36 #define DEBUG_TYPE "wasm-frame-info" 45 bool WebAssemblyFrameLowering::hasBP(
49 return RegInfo->needsStackRealignment(MF);
64 bool NeedsFixedReference = !hasBP(MF) || HasFixedSizedObjects;
93 bool WebAssemblyFrameLowering::needsSPWriteback(
107 const char *ES =
"__stack_pointer";
109 BuildMI(MBB, InsertStore, DL,
TII->get(WebAssembly::SET_GLOBAL_I32))
110 .addExternalSymbol(SPSymbol)
118 assert(!I->getOperand(0).getImm() && (
hasFP(MF) || hasBP(MF)) &&
119 "Call frame pseudos should only be used for dynamic stack adjustment");
121 if (I->getOpcode() ==
TII->getCallFrameDestroyOpcode() &&
134 "WebAssembly should not have callee-saved registers");
136 if (!needsSP(MF, MFI))
return;
142 auto InsertPt = MBB.
begin();
148 MRI.getTargetRegisterInfo()->getPointerRegClass(MF);
149 unsigned SPReg = WebAssembly::SP32;
151 SPReg =
MRI.createVirtualRegister(PtrRC);
153 const char *ES =
"__stack_pointer";
155 BuildMI(MBB, InsertPt, DL,
TII->get(WebAssembly::GET_GLOBAL_I32), SPReg)
156 .addExternalSymbol(SPSymbol);
158 bool HasBP = hasBP(MF);
161 unsigned BasePtr =
MRI.createVirtualRegister(PtrRC);
162 FI->setBasePointerVreg(BasePtr);
163 BuildMI(MBB, InsertPt, DL,
TII->get(WebAssembly::COPY), BasePtr)
168 unsigned OffsetReg =
MRI.createVirtualRegister(PtrRC);
169 BuildMI(MBB, InsertPt, DL,
TII->get(WebAssembly::CONST_I32), OffsetReg)
171 BuildMI(MBB, InsertPt, DL,
TII->get(WebAssembly::SUB_I32),
177 unsigned BitmaskReg =
MRI.createVirtualRegister(PtrRC);
180 "Alignment must be a power of 2");
181 BuildMI(MBB, InsertPt, DL,
TII->get(WebAssembly::CONST_I32), BitmaskReg)
182 .addImm((
int)~(Alignment - 1));
183 BuildMI(MBB, InsertPt, DL,
TII->get(WebAssembly::AND_I32),
185 .addReg(WebAssembly::SP32)
192 BuildMI(MBB, InsertPt, DL,
TII->get(WebAssembly::COPY),
194 .addReg(WebAssembly::SP32);
196 if (StackSize && needsSPWriteback(MF, MFI)) {
205 if (!needsSP(MF, MFI) || !needsSPWriteback(MF, MFI))
return;
211 if (InsertPt != MBB.
end())
212 DL = InsertPt->getDebugLoc();
220 SPReg = FI->getBasePointerVreg();
221 }
else if (StackSize) {
223 MRI.getTargetRegisterInfo()->getPointerRegClass(MF);
224 unsigned OffsetReg =
MRI.createVirtualRegister(PtrRC);
226 BuildMI(MBB, InsertPt, DL,
TII->get(WebAssembly::CONST_I32), OffsetReg)
230 SPReg =
MRI.createVirtualRegister(PtrRC);
231 BuildMI(MBB, InsertPt, DL,
TII->get(WebAssembly::ADD_I32), SPReg)
232 .addReg(
hasFP(MF) ? WebAssembly::FP32 : WebAssembly::SP32)
235 SPReg =
hasFP(MF) ? WebAssembly::FP32 : WebAssembly::SP32;
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
These methods insert prolog and epilog code into the function.
bool hasStackMap() const
This method may be called any time after instruction selection is complete to determine if there is a...
Compute iterated dominance frontiers using a linear time algorithm.
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
bool adjustsStack() const
Return true if this function adjusts the stack – e.g., when calling another function.
bool hasFP(const MachineFunction &MF) const override
Return true if the specified function should have a dedicated frame pointer register.
MachineBasicBlock::iterator eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator I) const override
This method is called during prolog/epilog code insertion to eliminate call frame setup and destroy p...
bool isFrameAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
const HexagonInstrInfo * TII
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
This file declares the WebAssembly-specific subclass of TargetMachine.
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
This file contains the declaration of the WebAssembly-specific utility functions. ...
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
unsigned const MachineRegisterInfo * MRI
std::size_t countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the least significant bit to the most stopping at the first 1...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
This file provides WebAssembly-specific target descriptions.
static void writeSPToMemory(unsigned SrcReg, MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator &InsertAddr, MachineBasicBlock::iterator &InsertStore, const DebugLoc &DL)
unsigned getMaxAlignment() const
Return the alignment in bytes that this function must be aligned to, which is greater than the defaul...
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const char * createExternalSymbolName(StringRef Name)
Allocate a string and populate it with the given external symbol name.
This file declares the WebAssembly-specific subclass of TargetSubtarget.
bool isArgument(const MachineInstr &MI)
This file contains the WebAssembly implementation of the TargetInstrInfo class.
const Function & getFunction() const
Return the LLVM function that this machine code represents.
This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...
This class implements WebAssembly-specific bits of TargetFrameLowering class.
static const size_t RedZoneSize
Size of the red zone for the user stack (leaf functions can use this much space below the stack point...
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
bool hasReservedCallFrame(const MachineFunction &MF) const override
Under normal circumstances, when a frame pointer is not required, we reserve argument space for call ...
This file declares WebAssembly-specific per-machine-function information.
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool hasPatchPoint() const
This method may be called any time after instruction selection is complete to determine if there is a...
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects...
bool hasCalls() const
Return true if the current function has any function calls.