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); 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 &getPhysRegs() const { return PhysRegs; } }; } // end namespace llvm 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]])