diff options
author | Wouter van Oortmerssen <aardappel@gmail.com> | 2020-06-15 15:31:10 -0700 |
---|---|---|
committer | Wouter van Oortmerssen <aardappel@gmail.com> | 2020-06-25 15:52:44 -0700 |
commit | b9a539c01084a572e406579c326a0da1e22e286f (patch) | |
tree | b07ec75715c53c5d7350e9562af1fc8e80bd5d29 /llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp | |
parent | 6e11ed52057ffc39941cb2de6d93cae522db4782 (diff) | |
download | llvm-b9a539c01084a572e406579c326a0da1e22e286f.zip llvm-b9a539c01084a572e406579c326a0da1e22e286f.tar.gz llvm-b9a539c01084a572e406579c326a0da1e22e286f.tar.bz2 |
[WebAssembly] Adding 64-bit versions of __stack_pointer and other globals
We have 6 globals, all of which except for __table_base are 64-bit under wasm64.
Differential Revision: https://reviews.llvm.org/D82130
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp')
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp | 107 |
1 files changed, 81 insertions, 26 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp index 30647fd..9566993 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp @@ -87,8 +87,8 @@ bool WebAssemblyFrameLowering::needsSPForLocalFrame( } // In function with EH pads, we need to make a copy of the value of -// __stack_pointer global in SP32 register, in order to use it when restoring -// __stack_pointer after an exception is caught. +// __stack_pointer global in SP32/64 register, in order to use it when +// restoring __stack_pointer after an exception is caught. bool WebAssemblyFrameLowering::needsPrologForEH( const MachineFunction &MF) const { auto EHType = MF.getTarget().getMCAsmInfo()->getExceptionHandlingType(); @@ -123,6 +123,57 @@ bool WebAssemblyFrameLowering::needsSPWriteback( return needsSPForLocalFrame(MF) && !CanUseRedZone; } +unsigned WebAssemblyFrameLowering::getSPReg(const MachineFunction &MF) { + return MF.getSubtarget<WebAssemblySubtarget>().hasAddr64() + ? WebAssembly::SP64 + : WebAssembly::SP32; +} + +unsigned WebAssemblyFrameLowering::getFPReg(const MachineFunction &MF) { + return MF.getSubtarget<WebAssemblySubtarget>().hasAddr64() + ? WebAssembly::FP64 + : WebAssembly::FP32; +} + +unsigned +WebAssemblyFrameLowering::getOpcConst(const MachineFunction &MF) { + return MF.getSubtarget<WebAssemblySubtarget>().hasAddr64() + ? WebAssembly::CONST_I64 + : WebAssembly::CONST_I32; +} + +unsigned WebAssemblyFrameLowering::getOpcAdd(const MachineFunction &MF) { + return MF.getSubtarget<WebAssemblySubtarget>().hasAddr64() + ? WebAssembly::ADD_I64 + : WebAssembly::ADD_I32; +} + +unsigned WebAssemblyFrameLowering::getOpcSub(const MachineFunction &MF) { + return MF.getSubtarget<WebAssemblySubtarget>().hasAddr64() + ? WebAssembly::SUB_I64 + : WebAssembly::SUB_I32; +} + +unsigned WebAssemblyFrameLowering::getOpcAnd(const MachineFunction &MF) { + return MF.getSubtarget<WebAssemblySubtarget>().hasAddr64() + ? WebAssembly::AND_I64 + : WebAssembly::AND_I32; +} + +unsigned +WebAssemblyFrameLowering::getOpcGlobGet(const MachineFunction &MF) { + return MF.getSubtarget<WebAssemblySubtarget>().hasAddr64() + ? WebAssembly::GLOBAL_GET_I64 + : WebAssembly::GLOBAL_GET_I32; +} + +unsigned +WebAssemblyFrameLowering::getOpcGlobSet(const MachineFunction &MF) { + return MF.getSubtarget<WebAssemblySubtarget>().hasAddr64() + ? WebAssembly::GLOBAL_SET_I64 + : WebAssembly::GLOBAL_SET_I32; +} + void WebAssemblyFrameLowering::writeSPToGlobal( unsigned SrcReg, MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator &InsertStore, const DebugLoc &DL) const { @@ -130,7 +181,8 @@ void WebAssemblyFrameLowering::writeSPToGlobal( const char *ES = "__stack_pointer"; auto *SPSymbol = MF.createExternalSymbolName(ES); - BuildMI(MBB, InsertStore, DL, TII->get(WebAssembly::GLOBAL_SET_I32)) + + BuildMI(MBB, InsertStore, DL, TII->get(getOpcGlobSet(MF))) .addExternalSymbol(SPSymbol) .addReg(SrcReg); } @@ -141,11 +193,12 @@ WebAssemblyFrameLowering::eliminateCallFramePseudoInstr( MachineBasicBlock::iterator I) const { assert(!I->getOperand(0).getImm() && (hasFP(MF) || hasBP(MF)) && "Call frame pseudos should only be used for dynamic stack adjustment"); - const auto *TII = MF.getSubtarget<WebAssemblySubtarget>().getInstrInfo(); + auto &ST = MF.getSubtarget<WebAssemblySubtarget>(); + const auto *TII = ST.getInstrInfo(); if (I->getOpcode() == TII->getCallFrameDestroyOpcode() && needsSPWriteback(MF)) { DebugLoc DL = I->getDebugLoc(); - writeSPToGlobal(WebAssembly::SP32, MF, MBB, I, DL); + writeSPToGlobal(getSPReg(MF), MF, MBB, I, DL); } return MBB.erase(I); } @@ -161,7 +214,8 @@ void WebAssemblyFrameLowering::emitPrologue(MachineFunction &MF, return; uint64_t StackSize = MFI.getStackSize(); - const auto *TII = MF.getSubtarget<WebAssemblySubtarget>().getInstrInfo(); + auto &ST = MF.getSubtarget<WebAssemblySubtarget>(); + const auto *TII = ST.getInstrInfo(); auto &MRI = MF.getRegInfo(); auto InsertPt = MBB.begin(); @@ -172,13 +226,13 @@ void WebAssemblyFrameLowering::emitPrologue(MachineFunction &MF, const TargetRegisterClass *PtrRC = MRI.getTargetRegisterInfo()->getPointerRegClass(MF); - unsigned SPReg = WebAssembly::SP32; + unsigned SPReg = getSPReg(MF); if (StackSize) SPReg = MRI.createVirtualRegister(PtrRC); const char *ES = "__stack_pointer"; auto *SPSymbol = MF.createExternalSymbolName(ES); - BuildMI(MBB, InsertPt, DL, TII->get(WebAssembly::GLOBAL_GET_I32), SPReg) + BuildMI(MBB, InsertPt, DL, TII->get(getOpcGlobGet(MF)), SPReg) .addExternalSymbol(SPSymbol); bool HasBP = hasBP(MF); @@ -192,32 +246,30 @@ void WebAssemblyFrameLowering::emitPrologue(MachineFunction &MF, if (StackSize) { // Subtract the frame size Register OffsetReg = MRI.createVirtualRegister(PtrRC); - BuildMI(MBB, InsertPt, DL, TII->get(WebAssembly::CONST_I32), OffsetReg) + BuildMI(MBB, InsertPt, DL, TII->get(getOpcConst(MF)), OffsetReg) .addImm(StackSize); - BuildMI(MBB, InsertPt, DL, TII->get(WebAssembly::SUB_I32), - WebAssembly::SP32) + BuildMI(MBB, InsertPt, DL, TII->get(getOpcSub(MF)), getSPReg(MF)) .addReg(SPReg) .addReg(OffsetReg); } if (HasBP) { Register BitmaskReg = MRI.createVirtualRegister(PtrRC); Align Alignment = MFI.getMaxAlign(); - BuildMI(MBB, InsertPt, DL, TII->get(WebAssembly::CONST_I32), BitmaskReg) - .addImm((int)~(Alignment.value() - 1)); - BuildMI(MBB, InsertPt, DL, TII->get(WebAssembly::AND_I32), - WebAssembly::SP32) - .addReg(WebAssembly::SP32) + BuildMI(MBB, InsertPt, DL, TII->get(getOpcConst(MF)), BitmaskReg) + .addImm((int64_t) ~(Alignment.value() - 1)); + BuildMI(MBB, InsertPt, DL, TII->get(getOpcAnd(MF)), getSPReg(MF)) + .addReg(getSPReg(MF)) .addReg(BitmaskReg); } if (hasFP(MF)) { // Unlike most conventional targets (where FP points to the saved FP), // FP points to the bottom of the fixed-size locals, so we can use positive // offsets in load/store instructions. - BuildMI(MBB, InsertPt, DL, TII->get(WebAssembly::COPY), WebAssembly::FP32) - .addReg(WebAssembly::SP32); + BuildMI(MBB, InsertPt, DL, TII->get(WebAssembly::COPY), getFPReg(MF)) + .addReg(getSPReg(MF)); } if (StackSize && needsSPWriteback(MF)) { - writeSPToGlobal(WebAssembly::SP32, MF, MBB, InsertPt, DL); + writeSPToGlobal(getSPReg(MF), MF, MBB, InsertPt, DL); } } @@ -226,7 +278,8 @@ void WebAssemblyFrameLowering::emitEpilogue(MachineFunction &MF, uint64_t StackSize = MF.getFrameInfo().getStackSize(); if (!needsSP(MF) || !needsSPWriteback(MF)) return; - const auto *TII = MF.getSubtarget<WebAssemblySubtarget>().getInstrInfo(); + auto &ST = MF.getSubtarget<WebAssemblySubtarget>(); + const auto *TII = ST.getInstrInfo(); auto &MRI = MF.getRegInfo(); auto InsertPt = MBB.getFirstTerminator(); DebugLoc DL; @@ -237,6 +290,7 @@ void WebAssemblyFrameLowering::emitEpilogue(MachineFunction &MF, // Restore the stack pointer. If we had fixed-size locals, add the offset // subtracted in the prolog. unsigned SPReg = 0; + unsigned SPFPReg = hasFP(MF) ? getFPReg(MF) : getSPReg(MF); if (hasBP(MF)) { auto FI = MF.getInfo<WebAssemblyFunctionInfo>(); SPReg = FI->getBasePointerVreg(); @@ -244,16 +298,17 @@ void WebAssemblyFrameLowering::emitEpilogue(MachineFunction &MF, const TargetRegisterClass *PtrRC = MRI.getTargetRegisterInfo()->getPointerRegClass(MF); Register OffsetReg = MRI.createVirtualRegister(PtrRC); - BuildMI(MBB, InsertPt, DL, TII->get(WebAssembly::CONST_I32), OffsetReg) + BuildMI(MBB, InsertPt, DL, TII->get(getOpcConst(MF)), OffsetReg) .addImm(StackSize); - // In the epilog we don't need to write the result back to the SP32 physreg - // because it won't be used again. We can use a stackified register instead. + // In the epilog we don't need to write the result back to the SP32/64 + // physreg because it won't be used again. We can use a stackified register + // instead. SPReg = MRI.createVirtualRegister(PtrRC); - BuildMI(MBB, InsertPt, DL, TII->get(WebAssembly::ADD_I32), SPReg) - .addReg(hasFP(MF) ? WebAssembly::FP32 : WebAssembly::SP32) + BuildMI(MBB, InsertPt, DL, TII->get(getOpcAdd(MF)), SPReg) + .addReg(SPFPReg) .addReg(OffsetReg); } else { - SPReg = hasFP(MF) ? WebAssembly::FP32 : WebAssembly::SP32; + SPReg = SPFPReg; } writeSPToGlobal(SPReg, MF, MBB, InsertPt, DL); |