[llvm] r253905 - [WebAssembly] Don't use set_local instructions explicitly.
Dan Gohman via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 23 11:30:43 PST 2015
Author: djg
Date: Mon Nov 23 13:30:43 2015
New Revision: 253905
URL: http://llvm.org/viewvc/llvm-project?rev=253905&view=rev
Log:
[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.
Modified:
llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.cpp
llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.td
llvm/trunk/test/CodeGen/WebAssembly/phi.ll
Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.cpp?rev=253905&r1=253904&r2=253905&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.cpp Mon Nov 23 13:30:43 2015
@@ -37,19 +37,19 @@ void WebAssemblyInstrInfo::copyPhysReg(M
const TargetRegisterClass *RC =
MBB.getParent()->getRegInfo().getRegClass(SrcReg);
- unsigned SetLocalOpcode;
+ unsigned CopyLocalOpcode;
if (RC == &WebAssembly::I32RegClass)
- SetLocalOpcode = WebAssembly::SET_LOCAL_I32;
+ CopyLocalOpcode = WebAssembly::COPY_LOCAL_I32;
else if (RC == &WebAssembly::I64RegClass)
- SetLocalOpcode = WebAssembly::SET_LOCAL_I64;
+ CopyLocalOpcode = WebAssembly::COPY_LOCAL_I64;
else if (RC == &WebAssembly::F32RegClass)
- SetLocalOpcode = WebAssembly::SET_LOCAL_F32;
+ CopyLocalOpcode = WebAssembly::COPY_LOCAL_F32;
else if (RC == &WebAssembly::F64RegClass)
- SetLocalOpcode = WebAssembly::SET_LOCAL_F64;
+ CopyLocalOpcode = WebAssembly::COPY_LOCAL_F64;
else
llvm_unreachable("Unexpected register class");
- BuildMI(MBB, I, DL, get(SetLocalOpcode), DestReg)
+ BuildMI(MBB, I, DL, get(CopyLocalOpcode), DestReg)
.addReg(SrcReg, KillSrc ? RegState::Kill : 0);
}
Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.td?rev=253905&r1=253904&r2=253905&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.td (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.td Mon Nov 23 13:30:43 2015
@@ -98,6 +98,14 @@ multiclass LOCAL<WebAssemblyRegClass vt>
// TODO: set_local returns its operand value
def SET_LOCAL_#vt : I<(outs), (ins i32imm:$regno, vt:$src), [],
"set_local\t$regno, $src">;
+
+ // COPY_LOCAL is not an actual instruction in wasm, but since we allow
+ // get_local and set_local to be implicit, we can have a COPY_LOCAL which
+ // is actually a no-op because all the work is done in the implied
+ // get_local and set_local.
+ let isAsCheapAsAMove = 1 in
+ def COPY_LOCAL_#vt : I<(outs vt:$res), (ins vt:$src), [],
+ "copy_local\t$res, $src">;
}
defm : LOCAL<I32>;
defm : LOCAL<I64>;
Modified: llvm/trunk/test/CodeGen/WebAssembly/phi.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/phi.ll?rev=253905&r1=253904&r2=253905&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/phi.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/phi.ll Mon Nov 23 13:30:43 2015
@@ -26,9 +26,9 @@ done:
; CHECK-LABEL: test1:
; CHECK: BB1_1:
-; CHECK: set_local $[[NUM0:[0-9]+]], $[[NUM1:[0-9]+]]{{$}}
-; CHECK: set_local $[[NUM1]], $[[NUM2:[0-9]+]]{{$}}
-; CHECK: set_local $[[NUM2]], $[[NUM0]]{{$}}
+; CHECK: copy_local $[[NUM0:[0-9]+]], $[[NUM1:[0-9]+]]{{$}}
+; CHECK: copy_local $[[NUM1]], $[[NUM2:[0-9]+]]{{$}}
+; CHECK: copy_local $[[NUM2]], $[[NUM0]]{{$}}
define i32 @test1(i32 %n) {
entry:
br label %loop
More information about the llvm-commits
mailing list