[WebAssembly] Print an extra local decl when the user stack pointer is used
authorDerek Schuff <dschuff@google.com>
Wed, 16 Dec 2015 20:43:06 +0000 (20:43 +0000)
committerDerek Schuff <dschuff@google.com>
Wed, 16 Dec 2015 20:43:06 +0000 (20:43 +0000)
Differential Revision: http://reviews.llvm.org/D15546

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255815 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
test/CodeGen/WebAssembly/userstack.ll

index 079c864c7bc1c15e9a7bc5c8d238fad2829ea0af..e853b76d0dd43183a65e63e0fec732d3d62a9b79 100644 (file)
@@ -26,6 +26,7 @@
 #include "llvm/CodeGen/Analysis.h"
 #include "llvm/CodeGen/AsmPrinter.h"
 #include "llvm/CodeGen/MachineConstantPool.h"
 #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"
 #include "llvm/CodeGen/MachineInstr.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/MC/MCContext.h"
@@ -181,6 +182,11 @@ void WebAssemblyAsmPrinter::EmitFunctionBodyStart() {
     Local.addOperand(MCOperand::createImm(getRegType(VReg).SimpleTy));
     AnyWARegs = true;
   }
     Local.addOperand(MCOperand::createImm(getRegType(VReg).SimpleTy));
     AnyWARegs = true;
   }
+  if (MF->getFrameInfo()->getStackSize() > 0) {
+    // TODO: wasm64
+    Local.addOperand(MCOperand::createImm(MVT::i32));
+    AnyWARegs = true;
+  }
   if (AnyWARegs)
     EmitToStreamer(*OutStreamer, Local);
 
   if (AnyWARegs)
     EmitToStreamer(*OutStreamer, Local);
 
index 27ff1e192e63f20adf7340f8e01905f60f1d254e..855eaa00a4a768ea1256d83f0f7c0acc2436294b 100644 (file)
@@ -6,6 +6,8 @@ target datalayout = "e-p:32:32-i64:64-n32:64-S128"
 target triple = "wasm32-unknown-unknown"
 
 ; CHECK-LABEL: alloca32:
 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]])
 define void @alloca32() {
  ; CHECK: i32.const [[L1:.+]]=, __stack_pointer
  ; CHECK-NEXT: i32.load [[L1]]=, 0([[L1]])
@@ -23,6 +25,7 @@ define void @alloca32() {
 }
 
 ; CHECK-LABEL: alloca3264:
 }
 
 ; 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]])
 define void @alloca3264() {
  ; CHECK: i32.const [[L1:.+]]=, __stack_pointer
  ; CHECK-NEXT: i32.load [[L1]]=, 0([[L1]])
@@ -43,6 +46,8 @@ define void @alloca3264() {
  ret void
 }
 
  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]])
 define void @allocarray() {
  ; CHECK: i32.const [[L1:.+]]=, __stack_pointer
  ; CHECK-NEXT: i32.load [[L1]]=, 0([[L1]])