[llvm] r305616 - [WebAssembly] Use __stack_pointer global when writing wasm binary

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 16 16:59:11 PDT 2017


Author: sbc
Date: Fri Jun 16 18:59:10 2017
New Revision: 305616

URL: http://llvm.org/viewvc/llvm-project?rev=305616&view=rev
Log:
[WebAssembly] Use __stack_pointer global when writing wasm binary

This ensures that symbolic relocations are generated for stack
pointer manipulations.

These relocations are of type R_WEBASSEMBLY_GLOBAL_INDEX_LEB.
This change also adds support for reading relocations of this
type in WasmObjectFile.cpp.

Since its a globally imported symbol this does mean that
the get_global/set_global instruction won't be valid until
the objects are linked that global used in no longer an
imported global.

Differential Revision: https://reviews.llvm.org/D34172

Added:
    llvm/trunk/test/MC/WebAssembly/stack-ptr.ll
Modified:
    llvm/trunk/include/llvm/CodeGen/MachineModuleInfoImpls.h
    llvm/trunk/lib/CodeGen/MachineModuleInfoImpls.cpp
    llvm/trunk/lib/MC/WasmObjectWriter.cpp
    llvm/trunk/lib/Object/WasmObjectFile.cpp
    llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCCodeEmitter.cpp
    llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.cpp
    llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h
    llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp
    llvm/trunk/test/CodeGen/WebAssembly/byval.ll
    llvm/trunk/test/CodeGen/WebAssembly/reg-stackify.ll
    llvm/trunk/test/CodeGen/WebAssembly/stack-alignment.ll
    llvm/trunk/test/CodeGen/WebAssembly/userstack.ll
    llvm/trunk/test/MC/WebAssembly/func-address.ll

Modified: llvm/trunk/include/llvm/CodeGen/MachineModuleInfoImpls.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineModuleInfoImpls.h?rev=305616&r1=305615&r2=305616&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineModuleInfoImpls.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineModuleInfoImpls.h Fri Jun 16 18:59:10 2017
@@ -77,33 +77,6 @@ public:
   SymbolListTy GetGVStubList() { return getSortedStubs(GVStubs); }
 };
 
-/// MachineModuleInfoWasm - This is a MachineModuleInfoImpl implementation
-/// for Wasm targets.
-class MachineModuleInfoWasm : public MachineModuleInfoImpl {
-  /// WebAssembly global variables defined by CodeGen.
-  std::vector<wasm::Global> Globals;
-
-  /// The WebAssembly global variable which is the stack pointer.
-  unsigned StackPointerGlobal;
-
-  virtual void anchor(); // Out of line virtual method.
-public:
-  MachineModuleInfoWasm(const MachineModuleInfo &)
-    : StackPointerGlobal(-1U) {}
-
-  void addGlobal(const wasm::Global &G) { Globals.push_back(G); }
-  const std::vector<wasm::Global> &getGlobals() const { return Globals; }
-
-  bool hasStackPointerGlobal() const {
-    return StackPointerGlobal != -1U;
-  }
-  unsigned getStackPointerGlobal() const {
-    assert(hasStackPointerGlobal() && "Stack ptr global hasn't been set");
-    return StackPointerGlobal;
-  }
-  void setStackPointerGlobal(unsigned Global) { StackPointerGlobal = Global; }
-};
-
 } // end namespace llvm
 
 #endif

Modified: llvm/trunk/lib/CodeGen/MachineModuleInfoImpls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineModuleInfoImpls.cpp?rev=305616&r1=305615&r2=305616&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineModuleInfoImpls.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineModuleInfoImpls.cpp Fri Jun 16 18:59:10 2017
@@ -23,7 +23,6 @@ using namespace llvm;
 // Out of line virtual method.
 void MachineModuleInfoMachO::anchor() {}
 void MachineModuleInfoELF::anchor() {}
-void MachineModuleInfoWasm::anchor() {}
 
 static int SortSymbolPair(const void *LHS, const void *RHS) {
   typedef std::pair<MCSymbol*, MachineModuleInfoImpl::StubValueTy> PairTy;

Modified: llvm/trunk/lib/MC/WasmObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WasmObjectWriter.cpp?rev=305616&r1=305615&r2=305616&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WasmObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WasmObjectWriter.cpp Fri Jun 16 18:59:10 2017
@@ -406,6 +406,8 @@ void WasmObjectWriter::recordRelocation(
   }
 
   assert(!IsPCRel);
+  assert(SymA);
+
   unsigned Type = getRelocType(Target, Fixup);
 
   WasmRelocationEntry Rec(FixupOffset, SymA, C, Type, &FixupSection);
@@ -474,6 +476,7 @@ uint32_t WasmObjectWriter::getRelocation
     assert(IndirectSymbolIndices.count(RelEntry.Symbol));
     return IndirectSymbolIndices[RelEntry.Symbol];
   case wasm::R_WEBASSEMBLY_FUNCTION_INDEX_LEB:
+  case wasm::R_WEBASSEMBLY_GLOBAL_INDEX_LEB:
   case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_LEB:
   case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_SLEB:
   case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_I32:
@@ -500,7 +503,8 @@ void WasmObjectWriter::applyRelocations(
     switch (RelEntry.Type) {
     case wasm::R_WEBASSEMBLY_TABLE_INDEX_SLEB:
     case wasm::R_WEBASSEMBLY_FUNCTION_INDEX_LEB:
-    case wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB: {
+    case wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB:
+    case wasm::R_WEBASSEMBLY_GLOBAL_INDEX_LEB: {
       uint32_t Index = getRelocationIndexValue(RelEntry);
       WritePatchableSLEB(Stream, Index, Offset);
       break;
@@ -526,7 +530,7 @@ void WasmObjectWriter::applyRelocations(
       break;
     }
     default:
-      llvm_unreachable("unsupported relocation type");
+      llvm_unreachable("invalid relocation type");
     }
   }
 }

Modified: llvm/trunk/lib/Object/WasmObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/WasmObjectFile.cpp?rev=305616&r1=305615&r2=305616&view=diff
==============================================================================
--- llvm/trunk/lib/Object/WasmObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/WasmObjectFile.cpp Fri Jun 16 18:59:10 2017
@@ -325,6 +325,7 @@ Error WasmObjectFile::parseRelocSection(
     case wasm::R_WEBASSEMBLY_TABLE_INDEX_SLEB:
     case wasm::R_WEBASSEMBLY_TABLE_INDEX_I32:
     case wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB:
+    case wasm::R_WEBASSEMBLY_GLOBAL_INDEX_LEB:
       break;
     case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_LEB:
     case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_SLEB:
@@ -332,7 +333,8 @@ Error WasmObjectFile::parseRelocSection(
       Reloc.Addend = readVarint32(Ptr);
       break;
     default:
-      return make_error<GenericBinaryError>("Bad relocation type",
+      return make_error<GenericBinaryError>("Bad relocation type: " +
+                                                Twine(Reloc.Type),
                                             object_error::parse_failed);
     }
     Section->Relocations.push_back(Reloc);

Modified: llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCCodeEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCCodeEmitter.cpp?rev=305616&r1=305615&r2=305616&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCCodeEmitter.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCCodeEmitter.cpp Fri Jun 16 18:59:10 2017
@@ -36,7 +36,6 @@ STATISTIC(MCNumFixups, "Number of MC fix
 namespace {
 class WebAssemblyMCCodeEmitter final : public MCCodeEmitter {
   const MCInstrInfo &MCII;
-  MCContext &Ctx;
 
   // Implementation generated by tablegen.
   uint64_t getBinaryCodeForInstr(const MCInst &MI,
@@ -48,14 +47,12 @@ class WebAssemblyMCCodeEmitter final : p
                          const MCSubtargetInfo &STI) const override;
 
 public:
-  WebAssemblyMCCodeEmitter(const MCInstrInfo &mcii, MCContext &ctx)
-      : MCII(mcii), Ctx(ctx) {}
+  WebAssemblyMCCodeEmitter(const MCInstrInfo &mcii) : MCII(mcii) {}
 };
 } // end anonymous namespace
 
-MCCodeEmitter *llvm::createWebAssemblyMCCodeEmitter(const MCInstrInfo &MCII,
-                                                    MCContext &Ctx) {
-  return new WebAssemblyMCCodeEmitter(MCII, Ctx);
+MCCodeEmitter *llvm::createWebAssemblyMCCodeEmitter(const MCInstrInfo &MCII) {
+  return new WebAssemblyMCCodeEmitter(MCII);
 }
 
 void WebAssemblyMCCodeEmitter::encodeInstruction(
@@ -89,11 +86,7 @@ void WebAssemblyMCCodeEmitter::encodeIns
         } else if (Info.OperandType == WebAssembly::OPERAND_I64IMM) {
           encodeSLEB128(int64_t(MO.getImm()), OS);
         } else if (Info.OperandType == WebAssembly::OPERAND_GLOBAL) {
-          Fixups.push_back(MCFixup::create(
-              OS.tell() - Start, MCConstantExpr::create(MO.getImm(), Ctx),
-              MCFixupKind(WebAssembly::fixup_code_global_index), MI.getLoc()));
-          ++MCNumFixups;
-          encodeULEB128(uint64_t(MO.getImm()), OS);
+          llvm_unreachable("wasm globals should only be accessed symbolicly");
         } else if (Info.OperandType == WebAssembly::OPERAND_SIGNATURE) {
           encodeSLEB128(int64_t(MO.getImm()), OS);
         } else {
@@ -135,6 +128,9 @@ void WebAssemblyMCCodeEmitter::encodeIns
                  Info.OperandType == WebAssembly::OPERAND_TYPEINDEX) {
         FixupKind = MCFixupKind(WebAssembly::fixup_code_uleb128_i32);
         PaddedSize = 5;
+      } else if (Info.OperandType == WebAssembly::OPERAND_GLOBAL) {
+        FixupKind = MCFixupKind(WebAssembly::fixup_code_global_index);
+        PaddedSize = 5;
       } else {
         llvm_unreachable("unexpected symbolic operand kind");
       }

Modified: llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.cpp?rev=305616&r1=305615&r2=305616&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.cpp Fri Jun 16 18:59:10 2017
@@ -74,7 +74,7 @@ static MCInstPrinter *createMCInstPrinte
 static MCCodeEmitter *createCodeEmitter(const MCInstrInfo &MCII,
                                         const MCRegisterInfo & /*MRI*/,
                                         MCContext &Ctx) {
-  return createWebAssemblyMCCodeEmitter(MCII, Ctx);
+  return createWebAssemblyMCCodeEmitter(MCII);
 }
 
 static MCAsmBackend *createAsmBackend(const Target & /*T*/,

Modified: llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h?rev=305616&r1=305615&r2=305616&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h (original)
+++ llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h Fri Jun 16 18:59:10 2017
@@ -35,8 +35,7 @@ class raw_pwrite_stream;
 Target &getTheWebAssemblyTarget32();
 Target &getTheWebAssemblyTarget64();
 
-MCCodeEmitter *createWebAssemblyMCCodeEmitter(const MCInstrInfo &MCII,
-                                              MCContext &Ctx);
+MCCodeEmitter *createWebAssemblyMCCodeEmitter(const MCInstrInfo &MCII);
 
 MCAsmBackend *createWebAssemblyAsmBackend(const Triple &TT);
 

Modified: llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp?rev=305616&r1=305615&r2=305616&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp Fri Jun 16 18:59:10 2017
@@ -68,6 +68,8 @@ WebAssemblyWasmObjectWriter::getRelocTyp
   bool IsFunction = IsFunctionExpr(Fixup.getValue());
 
   switch (unsigned(Fixup.getKind())) {
+  case WebAssembly::fixup_code_global_index:
+    return wasm::R_WEBASSEMBLY_GLOBAL_INDEX_LEB;
   case WebAssembly::fixup_code_sleb128_i32:
     if (IsFunction)
       return wasm::R_WEBASSEMBLY_TABLE_INDEX_SLEB;

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp?rev=305616&r1=305615&r2=305616&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp Fri Jun 16 18:59:10 2017
@@ -96,13 +96,6 @@ void WebAssemblyAsmPrinter::EmitEndOfAsm
                                MCConstantExpr::create(Size, OutContext));
     }
   }
-
-  if (!TM.getTargetTriple().isOSBinFormatELF()) {
-    MachineModuleInfoWasm &MMIW = MMI->getObjFileInfo<MachineModuleInfoWasm>();
-    getTargetStreamer()->emitGlobal(MMIW.getGlobals());
-    if (MMIW.hasStackPointerGlobal())
-      getTargetStreamer()->emitStackPointer(MMIW.getStackPointerGlobal());
-  }
 }
 
 void WebAssemblyAsmPrinter::EmitConstantPool() {

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp?rev=305616&r1=305615&r2=305616&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp Fri Jun 16 18:59:10 2017
@@ -104,10 +104,10 @@ static void writeSPToMemory(unsigned Src
                             const DebugLoc &DL) {
   const auto *TII = MF.getSubtarget<WebAssemblySubtarget>().getInstrInfo();
 
+  const char *ES = "__stack_pointer";
+  auto *SPSymbol = MF.createExternalSymbolName(ES);
   if (MF.getSubtarget<WebAssemblySubtarget>()
         .getTargetTriple().isOSBinFormatELF()) {
-    const char *ES = "__stack_pointer";
-    auto *SPSymbol = MF.createExternalSymbolName(ES);
     MachineRegisterInfo &MRI = MF.getRegInfo();
     const TargetRegisterClass *PtrRC =
         MRI.getTargetRegisterInfo()->getPointerRegClass(MF);
@@ -125,10 +125,8 @@ static void writeSPToMemory(unsigned Src
         .addReg(SrcReg)
         .addMemOperand(MMO);
   } else {
-    MachineModuleInfoWasm &MMIW =
-        MF.getMMI().getObjFileInfo<MachineModuleInfoWasm>();
     BuildMI(MBB, InsertStore, DL, TII->get(WebAssembly::SET_GLOBAL_I32))
-        .addImm(MMIW.getStackPointerGlobal())
+        .addExternalSymbol(SPSymbol)
         .addReg(SrcReg);
   }
 }
@@ -171,10 +169,11 @@ void WebAssemblyFrameLowering::emitProlo
   unsigned SPReg = WebAssembly::SP32;
   if (StackSize)
     SPReg = MRI.createVirtualRegister(PtrRC);
+
+  const char *ES = "__stack_pointer";
+  auto *SPSymbol = MF.createExternalSymbolName(ES);
   if (MF.getSubtarget<WebAssemblySubtarget>()
         .getTargetTriple().isOSBinFormatELF()) {
-    const char *ES = "__stack_pointer";
-    auto *SPSymbol = MF.createExternalSymbolName(ES);
     unsigned Zero = MRI.createVirtualRegister(PtrRC);
 
     BuildMI(MBB, InsertPt, DL, TII->get(WebAssembly::CONST_I32), Zero)
@@ -189,22 +188,8 @@ void WebAssemblyFrameLowering::emitProlo
         .addReg(Zero)    // addr
         .addMemOperand(LoadMMO);
   } else {
-    auto &MMIW = MF.getMMI().getObjFileInfo<MachineModuleInfoWasm>();
-    if (!MMIW.hasStackPointerGlobal()) {
-      MMIW.setStackPointerGlobal(MMIW.getGlobals().size());
-
-      // Create the stack-pointer global. For now, just use the
-      // Emscripten/Binaryen ABI names.
-      wasm::Global G;
-      G.Type = wasm::ValType::I32;
-      G.Mutable = true;
-      G.InitialValue = 0;
-      G.InitialModule = "env";
-      G.InitialName = "STACKTOP";
-      MMIW.addGlobal(G);
-    }
     BuildMI(MBB, InsertPt, DL, TII->get(WebAssembly::GET_GLOBAL_I32), SPReg)
-        .addImm(MMIW.getStackPointerGlobal());
+        .addExternalSymbol(SPSymbol);
   }
 
   bool HasBP = hasBP(MF);

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp?rev=305616&r1=305615&r2=305616&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp Fri Jun 16 18:59:10 2017
@@ -170,28 +170,16 @@ static void Query(const MachineInstr &MI
   if (MI.mayStore()) {
     Write = true;
 
-    const MachineFunction &MF = *MI.getParent()->getParent();
-    if (MF.getSubtarget<WebAssemblySubtarget>()
-          .getTargetTriple().isOSBinFormatELF()) {
-      // Check for stores to __stack_pointer.
-      for (auto MMO : MI.memoperands()) {
-        const MachinePointerInfo &MPI = MMO->getPointerInfo();
-        if (MPI.V.is<const PseudoSourceValue *>()) {
-          auto PSV = MPI.V.get<const PseudoSourceValue *>();
-          if (const ExternalSymbolPseudoSourceValue *EPSV =
-                  dyn_cast<ExternalSymbolPseudoSourceValue>(PSV))
-            if (StringRef(EPSV->getSymbol()) == "__stack_pointer")
-              StackPointer = true;
-        }
-      }
-    } else {
-      // Check for sets of the stack pointer.
-      const MachineModuleInfoWasm &MMIW =
-          MF.getMMI().getObjFileInfo<MachineModuleInfoWasm>();
-      if ((MI.getOpcode() == WebAssembly::SET_LOCAL_I32 ||
-           MI.getOpcode() == WebAssembly::SET_LOCAL_I64) &&
-          MI.getOperand(0).getImm() == MMIW.getStackPointerGlobal()) {
-        StackPointer = true;
+    // Check for stores to __stack_pointer.
+    for (auto MMO : MI.memoperands()) {
+      const MachinePointerInfo &MPI = MMO->getPointerInfo();
+      if (MPI.V.is<const PseudoSourceValue *>()) {
+        auto PSV = MPI.V.get<const PseudoSourceValue *>();
+        if (const ExternalSymbolPseudoSourceValue *EPSV =
+                dyn_cast<ExternalSymbolPseudoSourceValue>(PSV))
+          if (StringRef(EPSV->getSymbol()) == "__stack_pointer") {
+            StackPointer = true;
+          }
       }
     }
   } else if (MI.hasOrderedMemoryRef()) {

Modified: llvm/trunk/test/CodeGen/WebAssembly/byval.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/byval.ll?rev=305616&r1=305615&r2=305616&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/byval.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/byval.ll Fri Jun 16 18:59:10 2017
@@ -24,12 +24,12 @@ declare void @ext_byval_func_empty(%Empt
 define void @byval_arg(%SmallStruct* %ptr) {
  ; CHECK: .param i32
  ; Subtract 16 from SP (SP is 16-byte aligned)
- ; CHECK-NEXT: get_global $push[[L2:.+]]=, 0
+ ; CHECK-NEXT: get_global $push[[L2:.+]]=, __stack_pointer
  ; CHECK-NEXT: i32.const $push[[L3:.+]]=, 16
  ; CHECK-NEXT: i32.sub $push[[L11:.+]]=, $pop[[L2]], $pop[[L3]]
  ; Ensure SP is stored back before the call
  ; CHECK-NEXT: tee_local $push[[L10:.+]]=, $[[SP:.+]]=, $pop[[L11]]{{$}}
- ; CHECK-NEXT: set_global 0, $pop[[L10]]{{$}}
+ ; CHECK-NEXT: set_global __stack_pointer, $pop[[L10]]{{$}}
  ; Copy the SmallStruct argument to the stack (SP+12, original SP-4)
  ; CHECK-NEXT: i32.load $push[[L0:.+]]=, 0($0)
  ; CHECK-NEXT: i32.store 12($[[SP]]), $pop[[L0]]
@@ -41,7 +41,7 @@ define void @byval_arg(%SmallStruct* %pt
  ; Restore the stack
  ; CHECK-NEXT: i32.const $push[[L6:.+]]=, 16
  ; CHECK-NEXT: i32.add $push[[L8:.+]]=, $[[SP]], $pop[[L6]]
- ; CHECK-NEXT: set_global 0, $pop[[L8]]
+ ; CHECK-NEXT: set_global __stack_pointer, $pop[[L8]]
  ; CHECK-NEXT: return
  ret void
 }
@@ -53,7 +53,7 @@ define void @byval_arg_align8(%SmallStru
  ; CHECK: i32.const $push[[L1:.+]]=, 16
  ; CHECK-NEXT: i32.sub $push[[L11:.+]]=, {{.+}}, $pop[[L1]]
  ; CHECK-NEXT: tee_local $push[[L10:.+]]=, $[[SP:.+]]=, $pop[[L11]]{{$}}
- ; CHECK-NEXT: set_global 0, $pop[[L10]]{{$}}
+ ; CHECK-NEXT: set_global __stack_pointer, $pop[[L10]]{{$}}
  ; Copy the SmallStruct argument to the stack (SP+8, original SP-8)
  ; CHECK-NEXT: i32.load $push[[L0:.+]]=, 0($0){{$}}
  ; CHECK-NEXT: i32.store 8($[[SP]]), $pop[[L0]]{{$}}
@@ -72,7 +72,7 @@ define void @byval_arg_double(%AlignedSt
  ; CHECK: i32.const $push[[L1:.+]]=, 16
  ; CHECK-NEXT: i32.sub $push[[L14:.+]]=, {{.+}}, $pop[[L1]]
  ; CHECK-NEXT: tee_local $push[[L13:.+]]=, $[[SP:.+]]=, $pop[[L14]]
- ; CHECK-NEXT: set_global 0, $pop[[L13]]
+ ; CHECK-NEXT: set_global __stack_pointer, $pop[[L13]]
  ; Copy the AlignedStruct argument to the stack (SP+0, original SP-16)
  ; Just check the last load/store pair of the memcpy
  ; CHECK: i64.load $push[[L4:.+]]=, 0($0)
@@ -110,11 +110,11 @@ define void @byval_empty_callee(%EmptySt
 
 ; Call memcpy for "big" byvals.
 ; CHECK-LABEL: big_byval:
-; CHECK:      get_global $push[[L2:.+]]=, 0{{$}}
+; CHECK:      get_global $push[[L2:.+]]=, __stack_pointer{{$}}
 ; CHECK-NEXT: i32.const $push[[L3:.+]]=, 131072
 ; CHECK-NEXT: i32.sub $push[[L11:.+]]=, $pop[[L2]], $pop[[L3]]
 ; CHECK-NEXT: tee_local $push[[L10:.+]]=, $[[SP:.+]]=, $pop[[L11]]{{$}}
-; CHECK-NEXT: set_global 0, $pop[[L10]]{{$}}
+; CHECK-NEXT: set_global __stack_pointer, $pop[[L10]]{{$}}
 ; CHECK-NEXT: i32.const $push[[L0:.+]]=, 131072
 ; CHECK-NEXT: i32.call       $push[[L11:.+]]=, memcpy at FUNCTION, $[[SP]], ${{.+}}, $pop{{.+}}
 ; CHECK-NEXT: tee_local      $push[[L9:.+]]=, $[[SP:.+]]=, $pop[[L11]]{{$}}

Modified: llvm/trunk/test/CodeGen/WebAssembly/reg-stackify.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/reg-stackify.ll?rev=305616&r1=305615&r2=305616&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/reg-stackify.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/reg-stackify.ll Fri Jun 16 18:59:10 2017
@@ -448,7 +448,7 @@ bb10:
 
 ; CHECK-LABEL: stackpointer_dependency:
 ; CHECK:      call {{.+}}, stackpointer_callee at FUNCTION,
-; CHECK-NEXT: set_global 0,
+; CHECK-NEXT: set_global __stack_pointer,
 declare i32 @stackpointer_callee(i8* readnone, i8* readnone)
 declare i8* @llvm.frameaddress(i32)
 define i32 @stackpointer_dependency(i8* readnone) {

Modified: llvm/trunk/test/CodeGen/WebAssembly/stack-alignment.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/stack-alignment.ll?rev=305616&r1=305615&r2=305616&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/stack-alignment.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/stack-alignment.ll Fri Jun 16 18:59:10 2017
@@ -6,7 +6,7 @@ target triple = "wasm32-unknown-unknown-
 declare void @somefunc(i32*)
 
 ; CHECK-LABEL: underalign:
-; CHECK:      get_global $push[[L1:.+]]=, 0{{$}}
+; CHECK:      get_global $push[[L1:.+]]=, __stack_pointer{{$}}
 ; CHECK-NEXT: i32.const $push[[L2:.+]]=, 16
 ; CHECK-NEXT: i32.sub   $push[[L10:.+]]=, $pop[[L1]], $pop[[L2]]
 ; CHECK-NEXT: tee_local $push{{.+}}=, [[SP:.+]], $pop[[L10]]
@@ -17,7 +17,7 @@ declare void @somefunc(i32*)
 
 ; CHECK:      get_local $push[[M4:.+]]=, [[SP]]{{$}}
 ; CHECK:      i32.add   $push[[L5:.+]]=, $pop[[M4]], $pop{{.+}}
-; CHECK-NEXT: set_global 0, $pop[[L5]]
+; CHECK-NEXT: set_global __stack_pointer, $pop[[L5]]
 define void @underalign() {
 entry:
   %underaligned = alloca i32, align 8
@@ -26,7 +26,7 @@ entry:
 }
 
 ; CHECK-LABEL: overalign:
-; CHECK:      get_global $push[[L10:.+]]=, 0{{$}}
+; CHECK:      get_global $push[[L10:.+]]=, __stack_pointer{{$}}
 ; CHECK-NEXT: tee_local  $push[[L9:.+]]=, [[BP:.+]], $pop[[L10]]
 ; CHECK-NEXT: i32.const  $push[[L2:.+]]=, 32
 ; CHECK-NEXT: i32.sub    $push[[L8:.+]]=, $pop[[L9]], $pop[[L2]]
@@ -38,7 +38,7 @@ entry:
 ; CHECK:      call       somefunc at FUNCTION, $pop[[M5]]{{$}}
 
 ; CHECK:      get_local  $push[[M6:.+]]=, [[BP]]{{$}}
-; CHECK-NEXT: set_global 0, $pop[[M6]]
+; CHECK-NEXT: set_global __stack_pointer, $pop[[M6]]
 define void @overalign() {
 entry:
   %overaligned = alloca i32, align 32
@@ -47,7 +47,7 @@ entry:
 }
 
 ; CHECK-LABEL: over_and_normal_align:
-; CHECK:      get_global $push[[L14:.+]]=, 0{{$}}
+; CHECK:      get_global $push[[L14:.+]]=, __stack_pointer{{$}}
 ; CHECK-NEXT: tee_local  $push[[L13:.+]]=, [[BP:.+]], $pop[[L14]]
 ; CHECK:      i32.sub    $push[[L12:.+]]=, $pop[[L13]], $pop{{.+}}
 ; CHECK:      i32.and    $push[[L11:.+]]=, $pop[[L12]], $pop{{.+}}
@@ -61,7 +61,7 @@ entry:
 ; CHECK-NEXT: call       somefunc at FUNCTION, $pop[[L8]]
 
 ; CHECK:      get_local  $push[[L6:.+]]=, [[BP]]{{$}}
-; CHECK-NEXT: set_global 0, $pop[[L6]]
+; CHECK-NEXT: set_global __stack_pointer, $pop[[L6]]
 define void @over_and_normal_align() {
 entry:
   %over = alloca i32, align 32
@@ -72,7 +72,7 @@ entry:
 }
 
 ; CHECK-LABEL: dynamic_overalign:
-; CHECK:      get_global $push[[L18:.+]]=, 0{{$}}
+; CHECK:      get_global $push[[L18:.+]]=, __stack_pointer{{$}}
 ; CHECK-NEXT: tee_local  $push[[L17:.+]]=, [[SP:.+]], $pop[[L18]]
 ; CHECK-NEXT: set_local  [[BP:.+]], $pop[[L17]]
 ; CHECK:      tee_local  $push{{.+}}=, [[SP_2:.+]], $pop{{.+}}
@@ -81,7 +81,7 @@ entry:
 ; CHECK:      call       somefunc at FUNCTION, $pop[[M8]]
 
 ; CHECK:      get_local  $push[[M9:.+]]=, [[BP]]{{$}}
-; CHECK-NEXT: set_global 0, $pop[[M9]]
+; CHECK-NEXT: set_global __stack_pointer, $pop[[M9]]
 define void @dynamic_overalign(i32 %num) {
 entry:
   %dynamic = alloca i32, i32 %num, align 32
@@ -90,7 +90,7 @@ entry:
 }
 
 ; CHECK-LABEL: overalign_and_dynamic:
-; CHECK:      get_global $push[[L21:.+]]=, 0{{$}}
+; CHECK:      get_global $push[[L21:.+]]=, __stack_pointer{{$}}
 ; CHECK-NEXT: tee_local  $push[[L20:.+]]=, [[BP:.+]], $pop[[L21]]
 ; CHECK:      i32.sub    $push[[L19:.+]]=, $pop[[L20]], $pop{{.+}}
 ; CHECK:      i32.and    $push[[L18:.+]]=, $pop[[L19]], $pop{{.+}}
@@ -105,7 +105,7 @@ entry:
 ; CHECK-NEXT: call       somefunc at FUNCTION, $pop[[another]]
 
 ; CHECK:      get_local  $push[[M11:.+]]=, [[BP]]{{$}}
-; CHECK-NEXT: set_global 0, $pop[[M11]]
+; CHECK-NEXT: set_global __stack_pointer, $pop[[M11]]
 define void @overalign_and_dynamic(i32 %num) {
 entry:
   %over = alloca i32, align 32
@@ -116,7 +116,7 @@ entry:
 }
 
 ; CHECK-LABEL: overalign_static_and_dynamic:
-; CHECK:      get_global $push[[L26:.+]]=, 0{{$}}
+; CHECK:      get_global $push[[L26:.+]]=, __stack_pointer{{$}}
 ; CHECK-NEXT: tee_local  $push[[L25:.+]]=, [[BP:.+]], $pop[[L26]]
 ; CHECK:      i32.sub    $push[[L24:.+]]=, $pop[[L25]], $pop{{.+}}
 ; CHECK:      i32.and    $push[[L23:.+]]=, $pop[[L24]], $pop{{.+}}
@@ -136,7 +136,7 @@ entry:
 ; CHECK-NEXT: call       somefunc at FUNCTION, $pop[[static]]
 
 ; CHECK:      get_local  $push[[M14:.+]]=, [[BP]]{{$}}
-; CHECK-NEXT: set_global 0, $pop[[M14]]
+; CHECK-NEXT: set_global __stack_pointer, $pop[[M14]]
 define void @overalign_static_and_dynamic(i32 %num) {
 entry:
   %over = alloca i32, align 32

Modified: llvm/trunk/test/CodeGen/WebAssembly/userstack.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/userstack.ll?rev=305616&r1=305615&r2=305616&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/userstack.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/userstack.ll Fri Jun 16 18:59:10 2017
@@ -10,11 +10,11 @@ declare void @ext_func_i32(i32* %ptr)
 ; Check that there is an extra local for the stack pointer.
 ; CHECK: .local i32{{$}}
 define void @alloca32() noredzone {
- ; CHECK-NEXT: get_global $push[[L2:.+]]=, 0{{$}}
+ ; CHECK-NEXT: get_global $push[[L2:.+]]=, __stack_pointer{{$}}
  ; CHECK-NEXT: i32.const $push[[L3:.+]]=, 16
  ; CHECK-NEXT: i32.sub $push[[L9:.+]]=, $pop[[L2]], $pop[[L3]]
  ; CHECK-NEXT: tee_local $push[[L8:.+]]=, [[SP:.+]], $pop[[L9]]{{$}}
- ; CHECK-NEXT: set_global 0, $pop[[L8]]{{$}}
+ ; CHECK-NEXT: set_global __stack_pointer, $pop[[L8]]{{$}}
  %retval = alloca i32
  ; CHECK: get_local $push[[L4:.+]]=, [[SP]]{{$}}
  ; CHECK: i32.const $push[[L0:.+]]=, 0
@@ -23,14 +23,14 @@ define void @alloca32() noredzone {
  ; CHECK: get_local $push[[L6:.+]]=, [[SP]]{{$}}
  ; CHECK-NEXT: i32.const $push[[L5:.+]]=, 16
  ; CHECK-NEXT: i32.add $push[[L7:.+]]=, $pop[[L6]], $pop[[L5]]
- ; CHECK-NEXT: set_global 0, $pop[[L7]]
+ ; CHECK-NEXT: set_global __stack_pointer, $pop[[L7]]
  ret void
 }
 
 ; CHECK-LABEL: alloca3264:
 ; CHECK: .local i32{{$}}
 define void @alloca3264() {
- ; CHECK: get_global $push[[L3:.+]]=, 0{{$}}
+ ; CHECK: get_global $push[[L3:.+]]=, __stack_pointer{{$}}
  ; CHECK-NEXT: i32.const $push[[L4:.+]]=, 16
  ; CHECK-NEXT: i32.sub $push[[L6:.+]]=, $pop[[L3]], $pop[[L4]]
  ; CHECK-NEXT: tee_local $push[[L5:.+]]=, [[SP:.+]], $pop[[L6]]
@@ -50,11 +50,11 @@ define void @alloca3264() {
 ; CHECK-LABEL: allocarray:
 ; CHECK: .local i32{{$}}
 define void @allocarray() {
- ; CHECK-NEXT: get_global $push[[L4:.+]]=, 0{{$}}
+ ; CHECK-NEXT: get_global $push[[L4:.+]]=, __stack_pointer{{$}}
  ; CHECK-NEXT: i32.const $push[[L5:.+]]=, 144{{$}}
  ; CHECK-NEXT: i32.sub $push[[L12:.+]]=, $pop[[L4]], $pop[[L5]]
  ; CHECK-NEXT: tee_local $push[[L11:.+]]=, 0, $pop[[L12]]
- ; CHECK-NEXT: set_global 0, $pop[[L11]]
+ ; CHECK-NEXT: set_global __stack_pointer, $pop[[L11]]
  %r = alloca [33 x i32]
 
  ; CHECK:      i32.const $push{{.+}}=, 24
@@ -72,7 +72,7 @@ define void @allocarray() {
  ; CHECK-NEXT: get_local $push[[L2:.+]]=, [[SP]]{{$}}
  ; CHECK-NEXT: i32.const $push[[L7:.+]]=, 144
  ; CHECK-NEXT: i32.add $push[[L8:.+]]=, $pop[[L2]], $pop[[L7]]
- ; CHECK-NEXT: set_global 0, $pop[[L8]]
+ ; CHECK-NEXT: set_global __stack_pointer, $pop[[L8]]
  ret void
 }
 
@@ -81,7 +81,7 @@ define void @non_mem_use(i8** %addr) {
  ; CHECK: i32.const $push[[L2:.+]]=, 48
  ; CHECK-NEXT: i32.sub $push[[L12:.+]]=, {{.+}}, $pop[[L2]]
  ; CHECK-NEXT: tee_local $push[[L11:.+]]=, [[SP:.+]], $pop[[L12]]
- ; CHECK-NEXT: set_global 0, $pop[[L11]]
+ ; CHECK-NEXT: set_global __stack_pointer, $pop[[L11]]
  %buf = alloca [27 x i8], align 16
  %r = alloca i64
  %r2 = alloca i64
@@ -109,11 +109,11 @@ define void @non_mem_use(i8** %addr) {
 ; CHECK-LABEL: allocarray_inbounds:
 ; CHECK: .local i32{{$}}
 define void @allocarray_inbounds() {
- ; CHECK: get_global $push[[L3:.+]]=, 0{{$}}
+ ; CHECK: get_global $push[[L3:.+]]=, __stack_pointer{{$}}
  ; CHECK-NEXT: i32.const $push[[L4:.+]]=, 32{{$}}
  ; CHECK-NEXT: i32.sub $push[[L11:.+]]=, $pop[[L3]], $pop[[L4]]
  ; CHECK-NEXT: tee_local $push[[L10:.+]]=, [[SP:.+]], $pop[[L11]]
- ; CHECK-NEXT: set_global 0, $pop[[L10]]{{$}}
+ ; CHECK-NEXT: set_global __stack_pointer, $pop[[L10]]{{$}}
  %r = alloca [5 x i32]
  ; CHECK: i32.const $push[[L3:.+]]=, 1
  ; CHECK-DAG: i32.store 24(${{.+}}), $pop[[L3]]
@@ -127,29 +127,29 @@ define void @allocarray_inbounds() {
  ; CHECK: call ext_func
  ; CHECK: i32.const $push[[L5:.+]]=, 32{{$}}
  ; CHECK-NEXT: i32.add $push[[L7:.+]]=, ${{.+}}, $pop[[L5]]
- ; CHECK-NEXT: set_global 0, $pop[[L7]]
+ ; CHECK-NEXT: set_global __stack_pointer, $pop[[L7]]
  ret void
 }
 
 ; CHECK-LABEL: dynamic_alloca:
 define void @dynamic_alloca(i32 %alloc) {
- ; CHECK: get_global $push[[L13:.+]]=, 0{{$}}
+ ; CHECK: get_global $push[[L13:.+]]=, __stack_pointer{{$}}
  ; CHECK-NEXT: tee_local $push[[L12:.+]]=, [[SP:.+]], $pop[[L13]]{{$}}
  ; Target independent codegen bumps the stack pointer.
  ; CHECK: i32.sub
  ; Check that SP is written back to memory after decrement
- ; CHECK: set_global 0, 
+ ; CHECK: set_global __stack_pointer, 
  %r = alloca i32, i32 %alloc
  ; Target-independent codegen also calculates the store addr
  ; CHECK: call ext_func_i32 at FUNCTION
  call void @ext_func_i32(i32* %r)
- ; CHECK: set_global 0, $pop{{.+}}
+ ; CHECK: set_global __stack_pointer, $pop{{.+}}
  ret void
 }
 
 ; CHECK-LABEL: dynamic_alloca_redzone:
 define void @dynamic_alloca_redzone(i32 %alloc) {
- ; CHECK: get_global $push[[L13:.+]]=, 0{{$}}
+ ; CHECK: get_global $push[[L13:.+]]=, __stack_pointer{{$}}
  ; CHECK-NEXT: tee_local $push[[L12:.+]]=, [[SP:.+]], $pop[[L13]]{{$}}
  ; Target independent codegen bumps the stack pointer
  ; CHECK: i32.sub
@@ -166,11 +166,11 @@ define void @dynamic_alloca_redzone(i32
 ; CHECK-LABEL: dynamic_static_alloca:
 define void @dynamic_static_alloca(i32 %alloc) noredzone {
  ; Decrement SP in the prolog by the static amount and writeback to memory.
- ; CHECK: get_global $push[[L11:.+]]=, 0{{$}}
+ ; CHECK: get_global $push[[L11:.+]]=, __stack_pointer{{$}}
  ; CHECK-NEXT: i32.const $push[[L12:.+]]=, 16
  ; CHECK-NEXT: i32.sub $push[[L23:.+]]=, $pop[[L11]], $pop[[L12]]
  ; CHECK-NEXT: tee_local $push[[L22:.+]]=, [[SP:.+]], $pop[[L23]]
- ; CHECK-NEXT: set_global 0, $pop[[L22]]
+ ; CHECK-NEXT: set_global __stack_pointer, $pop[[L22]]
 
  ; Alloc and write to a static alloca
  ; CHECK: get_local $push[[L21:.+]]=, [[SP:.+]]
@@ -184,7 +184,7 @@ define void @dynamic_static_alloca(i32 %
  ; CHECK: i32.sub
  ; CHECK: tee_local $push[[L16:.+]]=, [[dynamic_local:.+]], $pop{{.+}}
  ; CHECK: tee_local $push[[L15:.+]]=, [[other:.+]], $pop[[L16]]{{$}}
- ; CHECK: set_global 0, $pop[[L15]]{{$}}
+ ; CHECK: set_global __stack_pointer, $pop[[L15]]{{$}}
  %dynamic = alloca i32, i32 %alloc
 
  ; Ensure we don't modify the frame pointer after assigning it.
@@ -226,7 +226,7 @@ define void @dynamic_static_alloca(i32 %
  ; CHECK: get_local $push[[L24:.+]]=, [[FP]]{{$}}
  ; CHECK: i32.const $push[[L18:.+]]=, 16
  ; CHECK-NEXT: i32.add $push[[L19:.+]]=, $pop[[L24]], $pop[[L18]]
- ; CHECK-NEXT: set_global 0, $pop[[L19]]
+ ; CHECK-NEXT: set_global __stack_pointer, $pop[[L19]]
  ret void
 }
 
@@ -235,7 +235,7 @@ declare void @llvm.stackrestore(i8*)
 
 ; CHECK-LABEL: llvm_stack_builtins:
 define void @llvm_stack_builtins(i32 %alloc) noredzone {
- ; CHECK: get_global $push[[L11:.+]]=, 0{{$}}
+ ; CHECK: get_global $push[[L11:.+]]=, __stack_pointer{{$}}
  ; CHECK-NEXT: tee_local $push[[L10:.+]]=, {{.+}}, $pop[[L11]]
  ; CHECK-NEXT: set_local [[STACK:.+]], $pop[[L10]]
  %stack = call i8* @llvm.stacksave()
@@ -245,7 +245,7 @@ define void @llvm_stack_builtins(i32 %al
  %dynamic = alloca i32, i32 %alloc
 
  ; CHECK: get_local $push[[L12:.+]]=, [[STACK]]
- ; CHECK-NEXT: set_global 0, $pop[[L12]]
+ ; CHECK-NEXT: set_global __stack_pointer, $pop[[L12]]
  call void @llvm.stackrestore(i8* %stack)
 
  ret void
@@ -256,7 +256,7 @@ define void @llvm_stack_builtins(i32 %al
 ; moved after the stack pointer was updated for the dynamic alloca.
 ; CHECK-LABEL: dynamic_alloca_nouse:
 define void @dynamic_alloca_nouse(i32 %alloc) noredzone {
- ; CHECK: get_global $push[[L11:.+]]=, 0{{$}}
+ ; CHECK: get_global $push[[L11:.+]]=, __stack_pointer{{$}}
  ; CHECK-NEXT: tee_local $push[[L10:.+]]=, {{.+}}, $pop[[L11]]
  ; CHECK-NEXT: set_local [[FP:.+]], $pop[[L10]]
  %dynamic = alloca i32, i32 %alloc
@@ -264,7 +264,7 @@ define void @dynamic_alloca_nouse(i32 %a
  ; CHECK-NOT: set_local [[FP]],
 
  ; CHECK: get_local $push[[L12:.+]]=, [[FP]]
- ; CHECK-NEXT: set_global 0, $pop[[L12]]
+ ; CHECK-NEXT: set_global __stack_pointer, $pop[[L12]]
  ret void
 }
 
@@ -295,11 +295,11 @@ declare i8* @llvm.frameaddress(i32)
 
 ; Test __builtin_frame_address(0).
 ; CHECK-LABEL: frameaddress_0:
-; CHECK: get_global $push[[L3:.+]]=, 0{{$}}
+; CHECK: get_global $push[[L3:.+]]=, __stack_pointer{{$}}
 ; CHECK-NEXT: tee_local $push[[L2:.+]]=, [[FP:.+]], $pop[[L3]]{{$}}
 ; CHECK-NEXT: call use_i8_star at FUNCTION, $pop[[L2]]
 ; CHECK-NEXT: get_local $push[[L5:.+]]=, [[FP]]
-; CHECK-NEXT: set_global 0, $pop[[L5]]
+; CHECK-NEXT: set_global __stack_pointer, $pop[[L5]]
 define void @frameaddress_0() {
   %t = call i8* @llvm.frameaddress(i32 0)
   call void @use_i8_star(i8* %t)
@@ -320,7 +320,7 @@ define void @frameaddress_1() {
 
 ; Test a stack address passed to an inline asm.
 ; CHECK-LABEL: inline_asm:
-; CHECK:       get_global {{.+}}, 0{{$}}
+; CHECK:       get_global {{.+}}, __stack_pointer{{$}}
 ; CHECK:       #APP
 ; CHECK-NEXT:  # %{{[0-9]+}}{{$}}
 ; CHECK-NEXT:  #NO_APP

Modified: llvm/trunk/test/MC/WebAssembly/func-address.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/WebAssembly/func-address.ll?rev=305616&r1=305615&r2=305616&view=diff
==============================================================================
--- llvm/trunk/test/MC/WebAssembly/func-address.ll (original)
+++ llvm/trunk/test/MC/WebAssembly/func-address.ll Fri Jun 16 18:59:10 2017
@@ -25,11 +25,10 @@ entry:
 ; CHECK:   Section {
 ; CHECK:     Type: ELEM (0x9)
 ; CHECK:     Size: 7
-; CHECK:     Offset: 165
 ; CHECK:   }
 
 ; CHECK: Relocations [
-; CHECK:   Section (9) CODE {
+; CHECK:   Section (8) CODE {
 ; CHECK:     Relocation {
 ; CHECK:       Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB (0)
 ; CHECK:       Offset: 0x4
@@ -42,7 +41,7 @@ entry:
 ; CHECK:     }
 ; CHECK:     Relocation {
 ; CHECK:       Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB (1)
-; CHECK:       Offset: 0x1A
+; CHECK:       Offset: 0x1E
 ; CHECK:       Index: 0x0
 ; CHECK:     }
 ; CHECK:   }

Added: llvm/trunk/test/MC/WebAssembly/stack-ptr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/WebAssembly/stack-ptr.ll?rev=305616&view=auto
==============================================================================
--- llvm/trunk/test/MC/WebAssembly/stack-ptr.ll (added)
+++ llvm/trunk/test/MC/WebAssembly/stack-ptr.ll Fri Jun 16 18:59:10 2017
@@ -0,0 +1,21 @@
+; RUN: llc -mtriple wasm32-unknown-unknown-wasm -filetype=obj %s -o - | obj2yaml | FileCheck %s
+
+; Function that uses explict stack, and should generate a reference to
+; __stack_pointer, along with the corresponding reloction entry.
+define hidden void @foo() #0 {
+entry:
+  alloca i32, align 4
+  ret void
+}
+
+; CHECK:  - Type:            IMPORT
+; CHECK:     Imports:
+; CHECK:       - Module:          env
+; CHECK:         Field:           __stack_pointer
+; CHECK:         Kind:            GLOBAL
+; CHECK:         GlobalType:      I32
+; CHECK:         GlobalMutable:   false
+; CHECK:   - Type:            CODE
+; CHECK:     Relocations:
+; CHECK:       - Type:            R_WEBASSEMBLY_GLOBAL_INDEX_LEB
+; CHECK:         Index:           0




More information about the llvm-commits mailing list