Index: llvm/trunk/include/llvm/CodeGen/MachineModuleInfoImpls.h =================================================================== --- llvm/trunk/include/llvm/CodeGen/MachineModuleInfoImpls.h +++ llvm/trunk/include/llvm/CodeGen/MachineModuleInfoImpls.h @@ -77,33 +77,6 @@ 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 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 &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 Index: llvm/trunk/lib/CodeGen/MachineModuleInfoImpls.cpp =================================================================== --- llvm/trunk/lib/CodeGen/MachineModuleInfoImpls.cpp +++ llvm/trunk/lib/CodeGen/MachineModuleInfoImpls.cpp @@ -23,7 +23,6 @@ // 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 PairTy; Index: llvm/trunk/lib/MC/WasmObjectWriter.cpp =================================================================== --- llvm/trunk/lib/MC/WasmObjectWriter.cpp +++ llvm/trunk/lib/MC/WasmObjectWriter.cpp @@ -406,6 +406,8 @@ } assert(!IsPCRel); + assert(SymA); + unsigned Type = getRelocType(Target, Fixup); WasmRelocationEntry Rec(FixupOffset, SymA, C, Type, &FixupSection); @@ -474,6 +476,7 @@ 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 @@ 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 @@ break; } default: - llvm_unreachable("unsupported relocation type"); + llvm_unreachable("invalid relocation type"); } } } Index: llvm/trunk/lib/Object/WasmObjectFile.cpp =================================================================== --- llvm/trunk/lib/Object/WasmObjectFile.cpp +++ llvm/trunk/lib/Object/WasmObjectFile.cpp @@ -325,6 +325,7 @@ 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 @@ Reloc.Addend = readVarint32(Ptr); break; default: - return make_error("Bad relocation type", + return make_error("Bad relocation type: " + + Twine(Reloc.Type), object_error::parse_failed); } Section->Relocations.push_back(Reloc); Index: llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCCodeEmitter.cpp =================================================================== --- llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCCodeEmitter.cpp +++ llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCCodeEmitter.cpp @@ -36,7 +36,6 @@ 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 @@ 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 @@ } 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 @@ 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"); } Index: llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h =================================================================== --- llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h +++ llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h @@ -35,8 +35,7 @@ Target &getTheWebAssemblyTarget32(); Target &getTheWebAssemblyTarget64(); -MCCodeEmitter *createWebAssemblyMCCodeEmitter(const MCInstrInfo &MCII, - MCContext &Ctx); +MCCodeEmitter *createWebAssemblyMCCodeEmitter(const MCInstrInfo &MCII); MCAsmBackend *createWebAssemblyAsmBackend(const Triple &TT); Index: llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.cpp =================================================================== --- llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.cpp +++ llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.cpp @@ -74,7 +74,7 @@ static MCCodeEmitter *createCodeEmitter(const MCInstrInfo &MCII, const MCRegisterInfo & /*MRI*/, MCContext &Ctx) { - return createWebAssemblyMCCodeEmitter(MCII, Ctx); + return createWebAssemblyMCCodeEmitter(MCII); } static MCAsmBackend *createAsmBackend(const Target & /*T*/, Index: llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp =================================================================== --- llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp +++ llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp @@ -68,6 +68,8 @@ 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; Index: llvm/trunk/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp =================================================================== --- llvm/trunk/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp +++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp @@ -96,13 +96,6 @@ MCConstantExpr::create(Size, OutContext)); } } - - if (!TM.getTargetTriple().isOSBinFormatELF()) { - MachineModuleInfoWasm &MMIW = MMI->getObjFileInfo(); - getTargetStreamer()->emitGlobal(MMIW.getGlobals()); - if (MMIW.hasStackPointerGlobal()) - getTargetStreamer()->emitStackPointer(MMIW.getStackPointerGlobal()); - } } void WebAssemblyAsmPrinter::EmitConstantPool() { Index: llvm/trunk/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp =================================================================== --- llvm/trunk/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp +++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp @@ -104,10 +104,10 @@ const DebugLoc &DL) { const auto *TII = MF.getSubtarget().getInstrInfo(); + const char *ES = "__stack_pointer"; + auto *SPSymbol = MF.createExternalSymbolName(ES); if (MF.getSubtarget() .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 @@ .addReg(SrcReg) .addMemOperand(MMO); } else { - MachineModuleInfoWasm &MMIW = - MF.getMMI().getObjFileInfo(); BuildMI(MBB, InsertStore, DL, TII->get(WebAssembly::SET_GLOBAL_I32)) - .addImm(MMIW.getStackPointerGlobal()) + .addExternalSymbol(SPSymbol) .addReg(SrcReg); } } @@ -171,10 +169,11 @@ unsigned SPReg = WebAssembly::SP32; if (StackSize) SPReg = MRI.createVirtualRegister(PtrRC); + + const char *ES = "__stack_pointer"; + auto *SPSymbol = MF.createExternalSymbolName(ES); if (MF.getSubtarget() .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 @@ .addReg(Zero) // addr .addMemOperand(LoadMMO); } else { - auto &MMIW = MF.getMMI().getObjFileInfo(); - 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); Index: llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp =================================================================== --- llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp +++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp @@ -170,28 +170,16 @@ if (MI.mayStore()) { Write = true; - const MachineFunction &MF = *MI.getParent()->getParent(); - if (MF.getSubtarget() - .getTargetTriple().isOSBinFormatELF()) { - // Check for stores to __stack_pointer. - for (auto MMO : MI.memoperands()) { - const MachinePointerInfo &MPI = MMO->getPointerInfo(); - if (MPI.V.is()) { - auto PSV = MPI.V.get(); - if (const ExternalSymbolPseudoSourceValue *EPSV = - dyn_cast(PSV)) - if (StringRef(EPSV->getSymbol()) == "__stack_pointer") - StackPointer = true; - } - } - } else { - // Check for sets of the stack pointer. - const MachineModuleInfoWasm &MMIW = - MF.getMMI().getObjFileInfo(); - 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()) { + auto PSV = MPI.V.get(); + if (const ExternalSymbolPseudoSourceValue *EPSV = + dyn_cast(PSV)) + if (StringRef(EPSV->getSymbol()) == "__stack_pointer") { + StackPointer = true; + } } } } else if (MI.hasOrderedMemoryRef()) { Index: llvm/trunk/test/CodeGen/WebAssembly/byval.ll =================================================================== --- llvm/trunk/test/CodeGen/WebAssembly/byval.ll +++ llvm/trunk/test/CodeGen/WebAssembly/byval.ll @@ -24,12 +24,12 @@ 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 @@ ; 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 @@ ; 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 @@ ; 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 @@ ; 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@FUNCTION, $[[SP]], ${{.+}}, $pop{{.+}} ; CHECK-NEXT: tee_local $push[[L9:.+]]=, $[[SP:.+]]=, $pop[[L11]]{{$}} Index: llvm/trunk/test/CodeGen/WebAssembly/reg-stackify.ll =================================================================== --- llvm/trunk/test/CodeGen/WebAssembly/reg-stackify.ll +++ llvm/trunk/test/CodeGen/WebAssembly/reg-stackify.ll @@ -448,7 +448,7 @@ ; CHECK-LABEL: stackpointer_dependency: ; CHECK: call {{.+}}, stackpointer_callee@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) { Index: llvm/trunk/test/CodeGen/WebAssembly/stack-alignment.ll =================================================================== --- llvm/trunk/test/CodeGen/WebAssembly/stack-alignment.ll +++ llvm/trunk/test/CodeGen/WebAssembly/stack-alignment.ll @@ -6,7 +6,7 @@ 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 @@ ; 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 @@ } ; 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 @@ ; CHECK: call somefunc@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 @@ } ; 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 @@ ; CHECK-NEXT: call somefunc@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 @@ } ; 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 @@ ; CHECK: call somefunc@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 @@ } ; 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 @@ ; CHECK-NEXT: call somefunc@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 @@ } ; 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 @@ ; CHECK-NEXT: call somefunc@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 Index: llvm/trunk/test/CodeGen/WebAssembly/userstack.ll =================================================================== --- llvm/trunk/test/CodeGen/WebAssembly/userstack.ll +++ llvm/trunk/test/CodeGen/WebAssembly/userstack.ll @@ -10,11 +10,11 @@ ; 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 @@ ; 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 @@ ; 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 @@ ; 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 @@ ; 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 @@ ; 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 @@ ; 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@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 @@ ; 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 @@ ; 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 @@ ; 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 @@ ; 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 @@ %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 @@ ; 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 @@ ; 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 @@ ; 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@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 @@ ; 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 Index: llvm/trunk/test/MC/WebAssembly/func-address.ll =================================================================== --- llvm/trunk/test/MC/WebAssembly/func-address.ll +++ llvm/trunk/test/MC/WebAssembly/func-address.ll @@ -25,11 +25,10 @@ ; 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 @@ ; CHECK: } ; CHECK: Relocation { ; CHECK: Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB (1) -; CHECK: Offset: 0x1A +; CHECK: Offset: 0x1E ; CHECK: Index: 0x0 ; CHECK: } ; CHECK: } Index: llvm/trunk/test/MC/WebAssembly/stack-ptr.ll =================================================================== --- llvm/trunk/test/MC/WebAssembly/stack-ptr.ll +++ llvm/trunk/test/MC/WebAssembly/stack-ptr.ll @@ -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