Go to the documentation of this file.
39 #define DEBUG_TYPE "wasm-frame-info"
82 for (
EVT ValueVT : ValueVTs)
83 FuncInfo->
addLocal(ValueVT.getSimpleVT());
87 return static_cast<unsigned>(Local);
97 return RegInfo->hasStackRealignment(MF);
112 bool NeedsFixedReference = !hasBP(MF) || HasFixedSizedObjects;
131 bool WebAssemblyFrameLowering::needsSPForLocalFrame(
150 bool WebAssemblyFrameLowering::needsSP(
const MachineFunction &MF)
const {
158 bool WebAssemblyFrameLowering::needsSPWriteback(
169 bool CanUseRedZone = MFI.getStackSize() <=
RedZoneSize && !MFI.hasCalls() &&
171 return needsSPForLocalFrame(MF) && !CanUseRedZone;
189 ? WebAssembly::CONST_I64
190 : WebAssembly::CONST_I32;
195 ? WebAssembly::ADD_I64
196 : WebAssembly::ADD_I32;
201 ? WebAssembly::SUB_I64
202 : WebAssembly::SUB_I32;
207 ? WebAssembly::AND_I64
208 : WebAssembly::AND_I32;
214 ? WebAssembly::GLOBAL_GET_I64
215 : WebAssembly::GLOBAL_GET_I32;
221 ? WebAssembly::GLOBAL_SET_I64
222 : WebAssembly::GLOBAL_SET_I32;
230 const char *ES =
"__stack_pointer";
242 assert(!
I->getOperand(0).getImm() && (
hasFP(MF) || hasBP(MF)) &&
243 "Call frame pseudos should only be used for dynamic stack adjustment");
245 const auto *
TII =
ST.getInstrInfo();
246 if (
I->getOpcode() ==
TII->getCallFrameDestroyOpcode() &&
247 needsSPWriteback(MF)) {
258 assert(MFI.getCalleeSavedInfo().empty() &&
259 "WebAssembly should not have callee-saved registers");
263 uint64_t StackSize = MFI.getStackSize();
266 const auto *
TII =
ST.getInstrInfo();
270 while (InsertPt !=
MBB.
end() &&
281 const char *ES =
"__stack_pointer";
286 bool HasBP = hasBP(MF);
290 FI->setBasePointerVreg(BasePtr);
305 Align Alignment = MFI.getMaxAlign();
307 .
addImm((int64_t) ~(Alignment.value() - 1));
319 if (StackSize && needsSPWriteback(MF)) {
327 if (!needsSP(MF) || !needsSPWriteback(MF))
330 const auto *
TII =
ST.getInstrInfo();
335 if (InsertPt !=
MBB.
end())
336 DL = InsertPt->getDebugLoc();
345 }
else if (StackSize) {
static unsigned getOpcAdd(const MachineFunction &MF)
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
bool isArgument(unsigned Opc)
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
This is an optimization pass for GlobalISel generic memory operations.
static unsigned getSPReg(const MachineFunction &MF)
const std::vector< MVT > & getLocals() const
Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
bool isSupportedStackID(TargetStackID::Value ID) const override
static unsigned getOpcSub(const MachineFunction &MF)
PointerType * getType() const
Overload to return most specific pointer type.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
const TargetRegisterInfo * getTargetRegisterInfo() const
unsigned getAddressSpace() const
Return the address space of the Pointer type.
void setObjectSize(int ObjectIdx, int64_t Size)
Change the size of the specified stack object.
void writeSPToGlobal(unsigned SrcReg, MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator &InsertStore, const DebugLoc &DL) const
Write SP back to __stack_pointer global.
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...
void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty, SmallVectorImpl< EVT > &ValueVTs, SmallVectorImpl< uint64_t > *Offsets=nullptr, uint64_t StartingOffset=0)
ComputeValueVTs - Given an LLVM IR type, compute a sequence of EVTs that represent all the individual...
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
struct WasmFrameBase WasmLoc
union llvm::TargetFrameLowering::DwarfFrameBase::@227 Location
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
These methods insert prolog and epilog code into the function.
unsigned getBasePointerVreg() const
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
static unsigned getOpcConst(const MachineFunction &MF)
const HexagonInstrInfo * TII
@ Wasm
WebAssembly Exception Handling.
uint8_t getStackID(int ObjectIdx) const
bool hasPersonalityFn() const
Check whether this function has a personality function.
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
enum llvm::TargetFrameLowering::DwarfFrameBase::FrameBaseKind Kind
This struct is a compact representation of a valid (non-zero power of two) alignment.
const MachineInstrBuilder & addExternalSymbol(const char *FnName, unsigned TargetFlags=0) const
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
static unsigned getOpcGlobSet(const MachineFunction &MF)
virtual const TargetRegisterClass * getPointerRegClass(const MachineFunction &MF, unsigned Kind=0) const
Returns a TargetRegisterClass used for pointer values.
DwarfFrameBase getDwarfFrameBase(const MachineFunction &MF) const override
Return the frame base information to be encoded in the DWARF subprogram debug info.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
virtual bool isSupportedStackID(TargetStackID::Value ID) const
void setObjectOffset(int ObjectIdx, int64_t SPOffset)
Set the stack frame offset of the specified object.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
const MCAsmInfo * getMCAsmInfo() const
Return target specific asm information.
void setStackID(int ObjectIdx, uint8_t ID)
bool hasPatchPoint() const
This method may be called any time after instruction selection is complete to determine if there is a...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
static unsigned getOpcAnd(const MachineFunction &MF)
unsigned const MachineRegisterInfo * MRI
Wrapper class representing virtual and physical registers.
bool isFrameAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
bool hasCalls() const
Return true if the current function has any function calls.
bool hasReservedCallFrame(const MachineFunction &MF) const override
Under normal circumstances, when a frame pointer is not required, we reserve argument space for call ...
static unsigned getFPReg(const MachineFunction &MF)
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...
Function & getFunction()
Return the LLVM function that this machine code represents.
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
bool hasFP(const MachineFunction &MF) const override
Return true if the specified function should have a dedicated frame pointer register.
bool isFrameBaseVirtual() const
bool needsPrologForEH(const MachineFunction &MF) const
ExceptionHandling getExceptionHandlingType() const
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
bool isWasmVarAddressSpace(unsigned AS)
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
const std::vector< MVT > & getParams() const
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
static unsigned getOpcGlobGet(const MachineFunction &MF)
const char * createExternalSymbolName(StringRef Name)
Allocate a string and populate it with the given external symbol name.
bool hasStackMap() const
This method may be called any time after instruction selection is complete to determine if there is a...
an instruction to allocate memory on the stack
static Optional< unsigned > getLocalForStackObject(MachineFunction &MF, int FrameIndex)
unsigned getFrameBaseLocal() const
const AllocaInst * getObjectAllocation(int ObjectIdx) const
Return the underlying Alloca of the specified stack object if it exists.