@@ -213,34 +213,51 @@ impl FuncTranslator {
213
213
1
214
214
};
215
215
let mut is_first_alloca = true;
216
- let mut insert_alloca = |ty, name| -> Result<PointerValue, CompileError> {
217
- let alloca = err!(alloca_builder.build_alloca(ty, name));
216
+ let mut insert_alloca = |ty, name: String | -> Result<PointerValue, CompileError> {
217
+ let alloca = err!(alloca_builder.build_alloca(ty, & name));
218
218
if is_first_alloca {
219
219
alloca_builder.position_at(entry, &alloca.as_instruction_value().unwrap());
220
220
is_first_alloca = false;
221
221
}
222
222
Ok(alloca)
223
223
};
224
224
225
+ // Uncomment to print, at the start of the function, the function name.
226
+ // (poor man's debugger!)
227
+ //let func_name_str =
228
+ // err!(alloca_builder.build_global_string_ptr(&function_name, "function_name"));
229
+ //
230
+ //_ = alloca_builder.build_call(
231
+ // intrinsics.debug_str,
232
+ // &[
233
+ // func_name_str.as_pointer_value().into(),
234
+ // intrinsics
235
+ // .i32_ty
236
+ // .const_int(function_name.len() as _, false)
237
+ // .into(),
238
+ // ],
239
+ // "",
240
+ //);
241
+
225
242
for idx in 0..wasm_fn_type.params().len() {
226
243
let ty = wasm_fn_type.params()[idx];
227
244
let ty = type_to_llvm(&intrinsics, ty)?;
228
245
let value = func
229
246
.get_nth_param((idx as u32).checked_add(first_param).unwrap())
230
247
.unwrap();
231
- let alloca = insert_alloca(ty, "param" )?;
248
+ let alloca = insert_alloca(ty, format!("param_{idx}") )?;
232
249
err!(cache_builder.build_store(alloca, value));
233
250
params.push((ty, alloca));
234
251
}
235
252
236
253
let mut locals = vec![];
237
254
let num_locals = reader.read_local_count()?;
238
- for _ in 0..num_locals {
255
+ for idx in 0..num_locals {
239
256
let (count, ty) = reader.read_local_decl()?;
240
257
let ty = err!(wptype_to_type(ty));
241
258
let ty = type_to_llvm(&intrinsics, ty)?;
242
259
for _ in 0..count {
243
- let alloca = insert_alloca(ty, "local" )?;
260
+ let alloca = insert_alloca(ty, format!("local_{idx}") )?;
244
261
err!(cache_builder.build_store(alloca, ty.const_zero()));
245
262
locals.push((ty, alloca));
246
263
}
@@ -253,7 +270,7 @@ impl FuncTranslator {
253
270
254
271
if g0m0_is_enabled {
255
272
let value = self.abi.get_g0_ptr_param(&func);
256
- let g0 = insert_alloca(intrinsics.i32_ty.as_basic_type_enum(), "g0")?;
273
+ let g0 = insert_alloca(intrinsics.i32_ty.as_basic_type_enum(), "g0".to_string() )?;
257
274
err!(cache_builder.build_store(g0, value));
258
275
g0.set_name("g0");
259
276
let m0 = self.abi.get_m0_ptr_param(&func);
@@ -1257,13 +1274,16 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
1257
1274
let ptr_in_bounds = match ptr_in_bounds {
1258
1275
Some(ptr) => ptr,
1259
1276
None => {
1260
- let load_offset_end =
1261
- err!(builder.build_int_add(offset, value_size_v, ""));
1277
+ let load_offset_end = err!(builder.build_int_add(
1278
+ offset,
1279
+ value_size_v,
1280
+ "load_offset_end"
1281
+ ));
1262
1282
1263
1283
let current_length = err!(builder.build_load(
1264
1284
self.intrinsics.i32_ty,
1265
1285
ptr_to_current_length,
1266
- ""
1286
+ "current_length "
1267
1287
))
1268
1288
.into_int_value();
1269
1289
tbaa_label(
@@ -1275,14 +1295,14 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
1275
1295
let current_length = err!(builder.build_int_z_extend(
1276
1296
current_length,
1277
1297
intrinsics.i64_ty,
1278
- ""
1298
+ "current_length_zextd "
1279
1299
));
1280
1300
1281
1301
err!(builder.build_int_compare(
1282
1302
IntPredicate::ULE,
1283
1303
load_offset_end,
1284
1304
current_length,
1285
- "",
1305
+ "ptr_in_bounds ",
1286
1306
))
1287
1307
}
1288
1308
};
@@ -1327,7 +1347,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
1327
1347
builder.position_at_end(in_bounds_continue_block);
1328
1348
}
1329
1349
let ptr_to_base =
1330
- err!(builder.build_load(intrinsics.ptr_ty, ptr_to_base_ptr, ""))
1350
+ err!(builder.build_load(intrinsics.ptr_ty, ptr_to_base_ptr, "ptr_to_base "))
1331
1351
.into_pointer_value();
1332
1352
tbaa_label(
1333
1353
self.module,
@@ -1340,10 +1360,11 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
1340
1360
MemoryCache::Static { base_ptr } => base_ptr,
1341
1361
}
1342
1362
};
1343
- let value_ptr =
1344
- unsafe { err!(builder.build_gep(self.intrinsics.i8_ty, base_ptr, &[offset], "")) };
1363
+ let value_ptr = unsafe {
1364
+ err!(builder.build_gep(self.intrinsics.i8_ty, base_ptr, &[offset], "mem_value_ptr"))
1365
+ };
1345
1366
err_nt!(builder
1346
- .build_bit_cast(value_ptr, ptr_ty, "")
1367
+ .build_bit_cast(value_ptr, ptr_ty, "mem_value ")
1347
1368
.map(|v| v.into_pointer_value()))
1348
1369
}
1349
1370
@@ -1356,9 +1377,10 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
1356
1377
if align <= 1 {
1357
1378
return Ok(());
1358
1379
}
1359
- let value = err!(self
1360
- .builder
1361
- .build_ptr_to_int(ptr, self.intrinsics.i64_ty, ""));
1380
+ let value =
1381
+ err!(self
1382
+ .builder
1383
+ .build_ptr_to_int(ptr, self.intrinsics.i64_ty, "mischeck_value"));
1362
1384
let and = err!(self.builder.build_and(
1363
1385
value,
1364
1386
self.intrinsics.i64_ty.const_int((align - 1).into(), false),
@@ -1368,15 +1390,15 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
1368
1390
IntPredicate::EQ,
1369
1391
and,
1370
1392
self.intrinsics.i64_zero,
1371
- ""
1393
+ "is_aligned "
1372
1394
));
1373
1395
let aligned = err!(self.builder.build_call(
1374
1396
self.intrinsics.expect_i1,
1375
1397
&[
1376
1398
aligned.into(),
1377
1399
self.intrinsics.i1_ty.const_int(1, false).into(),
1378
1400
],
1379
- "",
1401
+ "is_aligned_expect ",
1380
1402
))
1381
1403
.try_as_basic_value()
1382
1404
.left()
@@ -2583,7 +2605,11 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
2583
2605
// Operate on self.locals.
2584
2606
Operator::LocalGet { local_index } => {
2585
2607
let (type_value, pointer_value) = self.locals[local_index as usize];
2586
- let v = err!(self.builder.build_load(type_value, pointer_value, ""));
2608
+ let v = err!(self.builder.build_load(
2609
+ type_value,
2610
+ pointer_value,
2611
+ &format!("local_{local_index}_get")
2612
+ ));
2587
2613
tbaa_label(
2588
2614
self.module,
2589
2615
self.intrinsics,
@@ -10022,10 +10048,11 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
10022
10048
4,
10023
10049
)?;
10024
10050
self.trap_if_misaligned(memarg, effective_address, 4)?;
10025
- let result =
10026
- err!(self
10027
- .builder
10028
- .build_load(self.intrinsics.i32_ty, effective_address, ""));
10051
+ let result = err!(self.builder.build_load(
10052
+ self.intrinsics.i32_ty,
10053
+ effective_address,
10054
+ "atomic_load"
10055
+ ));
10029
10056
let load = result.as_instruction_value().unwrap();
10030
10057
self.annotate_user_memaccess(memory_index, memarg, 4, load)?;
10031
10058
load.set_atomic_ordering(AtomicOrdering::SequentiallyConsistent)
0 commit comments