Skip to content

Commit

Permalink
[WebAssembly] Print an extra local decl when the user stack pointer i…
Browse files Browse the repository at this point in the history
…s used

Differential Revision: http://reviews.llvm.org/D15546

llvm-svn: 255815
  • Loading branch information
dschuff committed Dec 16, 2015
1 parent ce7fc17 commit 45cd5a7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -181,6 +182,11 @@ void WebAssemblyAsmPrinter::EmitFunctionBodyStart() {
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);

Expand Down
5 changes: 5 additions & 0 deletions llvm/test/CodeGen/WebAssembly/userstack.ll
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ target datalayout = "e-p:32:32-i64:64-n32:64-S128"
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]])
Expand All @@ -23,6 +25,7 @@ define void @alloca32() {
}

; 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]])
Expand All @@ -43,6 +46,8 @@ define void @alloca3264() {
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]])
Expand Down

0 comments on commit 45cd5a7

Please sign in to comment.