MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / reuse_results

Function reuse_results

cranelift/codegen/src/ir/builder.rs:339–359  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

337
338 #[test]
339 fn reuse_results() {
340 let mut func = Function::new();
341 let block0 = func.dfg.make_block();
342 let arg0 = func.dfg.append_block_param(block0, I32);
343 let mut pos = FuncCursor::new(&mut func);
344 pos.insert_block(block0);
345
346 let v0 = pos.ins().iadd_imm(arg0, 17);
347 assert_eq!(pos.func.dfg.value_type(v0), I32);
348 let iadd = pos.prev_inst().unwrap();
349 assert_eq!(pos.func.dfg.value_def(v0), ValueDef::Result(iadd, 0));
350
351 // Detach v0 and reuse it for a different instruction.
352 pos.func.dfg.clear_results(iadd);
353 let v0b = pos.ins().with_result(v0).iconst(I32, 3);
354 assert_eq!(v0, v0b);
355 assert_eq!(pos.current_inst(), Some(iadd));
356 let iconst = pos.prev_inst().unwrap();
357 assert!(iadd != iconst);
358 assert_eq!(pos.func.dfg.value_def(v0), ValueDef::Result(iconst, 0));
359 }
360
361 #[test]
362 fn replace_with_imm_method() {

Callers

nothing calls this directly

Calls 9

make_blockMethod · 0.80
clear_resultsMethod · 0.80
with_resultMethod · 0.80
newFunction · 0.50
append_block_paramMethod · 0.45
insert_blockMethod · 0.45
insMethod · 0.45
unwrapMethod · 0.45
prev_instMethod · 0.45

Tested by

no test coverage detected