37 #define DEBUG_TYPE "wasm-frame-info" 49 return RegInfo->needsStackRealignment(MF);
64 bool NeedsFixedReference = !hasBP(MF) || HasFixedSizedObjects;
83 bool WebAssemblyFrameLowering::needsSPForLocalFrame(
102 bool WebAssemblyFrameLowering::needsSP(
const MachineFunction &MF)
const {
110 bool WebAssemblyFrameLowering::needsSPWriteback(
121 bool CanUseRedZone = MFI.getStackSize() <=
RedZoneSize && !MFI.hasCalls() &&
123 return needsSPForLocalFrame(MF) && !CanUseRedZone;
131 const char *ES =
"__stack_pointer";
133 BuildMI(MBB, InsertStore, DL,
TII->get(WebAssembly::GLOBAL_SET_I32))
142 assert(!I->getOperand(0).getImm() && (
hasFP(MF) || hasBP(MF)) &&
143 "Call frame pseudos should only be used for dynamic stack adjustment");
145 if (I->getOpcode() ==
TII->getCallFrameDestroyOpcode() &&
146 needsSPWriteback(MF)) {
157 assert(MFI.getCalleeSavedInfo().empty() &&
158 "WebAssembly should not have callee-saved registers");
162 uint64_t StackSize = MFI.getStackSize();
167 auto InsertPt = MBB.
begin();
173 MRI.getTargetRegisterInfo()->getPointerRegClass(MF);
174 unsigned SPReg = WebAssembly::SP32;
176 SPReg =
MRI.createVirtualRegister(PtrRC);
178 const char *ES =
"__stack_pointer";
180 BuildMI(MBB, InsertPt, DL,
TII->get(WebAssembly::GLOBAL_GET_I32), SPReg)
183 bool HasBP = hasBP(MF);
186 unsigned BasePtr =
MRI.createVirtualRegister(PtrRC);
187 FI->setBasePointerVreg(BasePtr);
188 BuildMI(MBB, InsertPt, DL,
TII->get(WebAssembly::COPY), BasePtr)
193 unsigned OffsetReg =
MRI.createVirtualRegister(PtrRC);
194 BuildMI(MBB, InsertPt, DL,
TII->get(WebAssembly::CONST_I32), OffsetReg)
196 BuildMI(MBB, InsertPt, DL,
TII->get(WebAssembly::SUB_I32),
202 unsigned BitmaskReg =
MRI.createVirtualRegister(PtrRC);
203 unsigned Alignment = MFI.getMaxAlignment();
205 "Alignment must be a power of 2");
206 BuildMI(MBB, InsertPt, DL,
TII->get(WebAssembly::CONST_I32), BitmaskReg)
207 .addImm((
int)~(Alignment - 1));
208 BuildMI(MBB, InsertPt, DL,
TII->get(WebAssembly::AND_I32),
210 .addReg(WebAssembly::SP32)
217 BuildMI(MBB, InsertPt, DL,
TII->get(WebAssembly::COPY), WebAssembly::FP32)
218 .addReg(WebAssembly::SP32);
220 if (StackSize && needsSPWriteback(MF)) {
228 if (!needsSP(MF) || !needsSPWriteback(MF))
235 if (InsertPt != MBB.
end())
236 DL = InsertPt->getDebugLoc();
243 SPReg = FI->getBasePointerVreg();
244 }
else if (StackSize) {
246 MRI.getTargetRegisterInfo()->getPointerRegClass(MF);
247 unsigned OffsetReg =
MRI.createVirtualRegister(PtrRC);
248 BuildMI(MBB, InsertPt, DL,
TII->get(WebAssembly::CONST_I32), OffsetReg)
252 SPReg =
MRI.createVirtualRegister(PtrRC);
253 BuildMI(MBB, InsertPt, DL,
TII->get(WebAssembly::ADD_I32), SPReg)
254 .addReg(
hasFP(MF) ? WebAssembly::FP32 : WebAssembly::SP32)
257 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...
This class represents lattice values for constants.
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 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 ...
bool needsPrologForEH(const MachineFunction &MF) const
This file declares the WebAssembly-specific subclass of TargetMachine.
bool hasPersonalityFn() const
Check whether this function has a personality function.
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
Windows Exception Handling.
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.
const MCAsmInfo * getMCAsmInfo() const
Return target specific asm information.
This file provides WebAssembly-specific target descriptions.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
void writeSPToGlobal(unsigned SrcReg, MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator &InsertStore, const DebugLoc &DL) const
Write SP back to __stack_pointer global.
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.
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.
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ExceptionHandling getExceptionHandlingType() const
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.