llvm.org GIT mirror llvm / c558dd3
[WebAssembly] Don't use set_local instructions explicitly. The current approach to using get_local and set_local is to use them implicitly, as register uses and defs. Introduce new copy instructions which are themselves no-ops except for the get_local and set_local that they imply, so that we use get_local and set_local consistently. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253905 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 4 years ago
3 changed file(s) with 17 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
3636 const TargetRegisterClass *RC =
3737 MBB.getParent()->getRegInfo().getRegClass(SrcReg);
3838
39 unsigned SetLocalOpcode;
39 unsigned CopyLocalOpcode;
4040 if (RC == &WebAssembly::I32RegClass)
41 SetLocalOpcode = WebAssembly::SET_LOCAL_I32;
41 CopyLocalOpcode = WebAssembly::COPY_LOCAL_I32;
4242 else if (RC == &WebAssembly::I64RegClass)
43 SetLocalOpcode = WebAssembly::SET_LOCAL_I64;
43 CopyLocalOpcode = WebAssembly::COPY_LOCAL_I64;
4444 else if (RC == &WebAssembly::F32RegClass)
45 SetLocalOpcode = WebAssembly::SET_LOCAL_F32;
45 CopyLocalOpcode = WebAssembly::COPY_LOCAL_F32;
4646 else if (RC == &WebAssembly::F64RegClass)
47 SetLocalOpcode = WebAssembly::SET_LOCAL_F64;
47 CopyLocalOpcode = WebAssembly::COPY_LOCAL_F64;
4848 else
4949 llvm_unreachable("Unexpected register class");
5050
51 BuildMI(MBB, I, DL, get(SetLocalOpcode), DestReg)
51 BuildMI(MBB, I, DL, get(CopyLocalOpcode), DestReg)
5252 .addReg(SrcReg, KillSrc ? RegState::Kill : 0);
5353 }
5454
9797 // TODO: set_local returns its operand value
9898 def SET_LOCAL_#vt : I<(outs), (ins i32imm:$regno, vt:$src), [],
9999 "set_local\t$regno, $src">;
100
101 // COPY_LOCAL is not an actual instruction in wasm, but since we allow
102 // get_local and set_local to be implicit, we can have a COPY_LOCAL which
103 // is actually a no-op because all the work is done in the implied
104 // get_local and set_local.
105 let isAsCheapAsAMove = 1 in
106 def COPY_LOCAL_#vt : I<(outs vt:$res), (ins vt:$src), [],
107 "copy_local\t$res, $src">;
100108 }
101109 defm : LOCAL;
102110 defm : LOCAL;
2525
2626 ; CHECK-LABEL: test1:
2727 ; CHECK: BB1_1:
28 ; CHECK: set_local $[[NUM0:[0-9]+]], $[[NUM1:[0-9]+]]{{$}}
29 ; CHECK: set_local $[[NUM1]], $[[NUM2:[0-9]+]]{{$}}
30 ; CHECK: set_local $[[NUM2]], $[[NUM0]]{{$}}
28 ; CHECK: copy_local $[[NUM0:[0-9]+]], $[[NUM1:[0-9]+]]{{$}}
29 ; CHECK: copy_local $[[NUM1]], $[[NUM2:[0-9]+]]{{$}}
30 ; CHECK: copy_local $[[NUM2]], $[[NUM0]]{{$}}
3131 define i32 @test1(i32 %n) {
3232 entry:
3333 br label %loop