[PATCH] D15546: [WebAssembly] Print an extra local decl when the user stack pointer is used
Derek Schuff via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 15 17:24:42 PST 2015
dschuff updated this revision to Diff 42946.
dschuff added a comment.
- Iterate over phys regs instead
http://reviews.llvm.org/D15546
Files:
lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h
test/CodeGen/WebAssembly/userstack.ll
Index: test/CodeGen/WebAssembly/userstack.ll
===================================================================
--- test/CodeGen/WebAssembly/userstack.ll
+++ test/CodeGen/WebAssembly/userstack.ll
@@ -6,6 +6,8 @@
target triple = "wasm32-unknown-unknown"
; CHECK-LABEL: alloca32:
+; Check that there is an extra local for the stack pointer.
+; CHECK: .local i32, i32, i32, i32{{$}}
define void @alloca32() {
; CHECK: i32.const [[L1:.+]]=, __stack_pointer
; CHECK-NEXT: i32.load [[L1]]=, 0([[L1]])
@@ -23,6 +25,7 @@
}
; CHECK-LABEL: alloca3264:
+; CHECK: .local i32, i32, i32, i32{{$}}
define void @alloca3264() {
; CHECK: i32.const [[L1:.+]]=, __stack_pointer
; CHECK-NEXT: i32.load [[L1]]=, 0([[L1]])
@@ -43,6 +46,8 @@
ret void
}
+; CHECK-LABEL: allocarray:
+; CHECK: .local i32, i32, i32, i32, i32, i32{{$}}
define void @allocarray() {
; CHECK: i32.const [[L1:.+]]=, __stack_pointer
; CHECK-NEXT: i32.load [[L1]]=, 0([[L1]])
Index: lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h
===================================================================
--- lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h
+++ lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h
@@ -89,6 +89,7 @@
assert(WAReg < -1U);
PhysRegs[PReg] = WAReg;
}
+ const std::vector<unsigned> &getPhysRegs() const { return PhysRegs; }
};
} // end namespace llvm
Index: lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
===================================================================
--- lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
+++ lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
@@ -26,6 +26,7 @@
#include "llvm/CodeGen/Analysis.h"
#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/CodeGen/MachineConstantPool.h"
+#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/MC/MCContext.h"
@@ -90,7 +91,10 @@
//===----------------------------------------------------------------------===//
MVT WebAssemblyAsmPrinter::getRegType(unsigned RegNo) const {
- const TargetRegisterClass *TRC = MRI->getRegClass(RegNo);
+ const TargetRegisterClass *TRC =
+ TargetRegisterInfo::isVirtualRegister(RegNo) ?
+ MRI->getRegClass(RegNo) :
+ MRI->getTargetRegisterInfo()->getMinimalPhysRegClass(RegNo);
for (MVT T : {MVT::i32, MVT::i64, MVT::f32, MVT::f64})
if (TRC->hasType(T))
return T;
@@ -181,6 +185,13 @@
Local.addOperand(MCOperand::createImm(getRegType(VReg).SimpleTy));
AnyWARegs = true;
}
+ auto &PhysRegs = MFI->getPhysRegs();
+ for (unsigned PReg = 0; PReg < PhysRegs.size(); ++PReg) {
+ if (PhysRegs[PReg] == -1U)
+ continue;
+ Local.addOperand(MCOperand::createImm(getRegType(PReg).SimpleTy));
+ AnyWARegs = true;
+ }
if (AnyWARegs)
EmitToStreamer(*OutStreamer, Local);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15546.42946.patch
Type: text/x-patch
Size: 2857 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151216/ba2eed7c/attachment.bin>
More information about the llvm-commits
mailing list