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

Function sequence_of_blocks

cranelift/frontend/src/ssa.rs:722–848  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

720
721 #[test]
722 fn sequence_of_blocks() {
723 let mut func = Function::new();
724 let mut ssa = SSABuilder::default();
725 let block0 = func.dfg.make_block();
726 let block1 = func.dfg.make_block();
727 let block2 = func.dfg.make_block();
728 // Here is the pseudo-program we want to translate:
729 // block0:
730 // x = 1;
731 // y = 2;
732 // z = x + y;
733 // brif y, block1, block1;
734 // block1:
735 // z = x + z;
736 // jump block2;
737 // block2:
738 // y = x + y;
739 {
740 let mut cur = FuncCursor::new(&mut func);
741 cur.insert_block(block0);
742 cur.insert_block(block1);
743 cur.insert_block(block2);
744 }
745
746 // block0
747 ssa.declare_block(block0);
748 ssa.seal_block(block0, &mut func);
749 let x_var = Variable::new(0);
750 let x_ssa = {
751 let mut cur = FuncCursor::new(&mut func).at_bottom(block0);
752 cur.ins().iconst(I32, 1)
753 };
754 ssa.def_var(x_var, x_ssa, block0);
755 let y_var = Variable::new(1);
756 let y_ssa = {
757 let mut cur = FuncCursor::new(&mut func).at_bottom(block0);
758 cur.ins().iconst(I32, 2)
759 };
760 ssa.def_var(y_var, y_ssa, block0);
761 let z_var = Variable::new(2);
762 let x_use1 = ssa.use_var(&mut func, x_var, I32, block0).0;
763 let y_use1 = ssa.use_var(&mut func, y_var, I32, block0).0;
764 let z1_ssa = {
765 let mut cur = FuncCursor::new(&mut func).at_bottom(block0);
766 cur.ins().iadd(x_use1, y_use1)
767 };
768 ssa.def_var(z_var, z1_ssa, block0);
769 let y_use2 = ssa.use_var(&mut func, y_var, I32, block0).0;
770 let brif_block0_block2_block1: Inst = {
771 let mut cur = FuncCursor::new(&mut func).at_bottom(block0);
772 cur.ins().brif(y_use2, block2, &[], block1, &[])
773 };
774
775 assert_eq!(ssa.use_var(&mut func, x_var, I32, block0).0, x_ssa);
776 assert_eq!(ssa.use_var(&mut func, y_var, I32, block0).0, y_ssa);
777 assert_eq!(ssa.use_var(&mut func, z_var, I32, block0).0, z1_ssa);
778
779 // block1

Callers

nothing calls this directly

Calls 11

make_blockMethod · 0.80
declare_blockMethod · 0.80
at_bottomMethod · 0.80
jumpMethod · 0.80
newFunction · 0.50
insert_blockMethod · 0.45
seal_blockMethod · 0.45
insMethod · 0.45
def_varMethod · 0.45
use_varMethod · 0.45

Tested by

no test coverage detected