39#define DEBUG_TYPE "wasm-frame-info"
53std::optional<unsigned>
81 for (
EVT ValueVT : ValueVTs)
82 FuncInfo->
addLocal(ValueVT.getSimpleVT());
86 return static_cast<unsigned>(Local);
96 return RegInfo->hasStackRealignment(MF);
111 bool NeedsFixedReference = !hasBP(MF) || HasFixedSizedObjects;
130bool WebAssemblyFrameLowering::needsSPForLocalFrame(
136 bool HasExplicitSPUse =
140 return MFI.getStackSize() || MFI.adjustsStack() ||
hasFP(MF) ||
157bool WebAssemblyFrameLowering::needsSP(
const MachineFunction &MF)
const {
165bool WebAssemblyFrameLowering::needsSPWriteback(
176 bool CanUseRedZone = MFI.getStackSize() <=
RedZoneSize && !MFI.hasCalls() &&
178 return needsSPForLocalFrame(MF) && !CanUseRedZone;
196 ? WebAssembly::CONST_I64
197 : WebAssembly::CONST_I32;
202 ? WebAssembly::ADD_I64
203 : WebAssembly::ADD_I32;
208 ? WebAssembly::SUB_I64
209 : WebAssembly::SUB_I32;
214 ? WebAssembly::AND_I64
215 : WebAssembly::AND_I32;
221 ? WebAssembly::GLOBAL_GET_I64
222 : WebAssembly::GLOBAL_GET_I32;
228 ? WebAssembly::GLOBAL_SET_I64
229 : WebAssembly::GLOBAL_SET_I32;
237 const char *ES =
"__stack_pointer";
249 assert(!
I->getOperand(0).getImm() && (
hasFP(MF) || hasBP(MF)) &&
250 "Call frame pseudos should only be used for dynamic stack adjustment");
252 const auto *
TII = ST.getInstrInfo();
253 if (
I->getOpcode() ==
TII->getCallFrameDestroyOpcode() &&
254 needsSPWriteback(MF)) {
265 assert(MFI.getCalleeSavedInfo().empty() &&
266 "WebAssembly should not have callee-saved registers");
270 uint64_t StackSize = MFI.getStackSize();
273 const auto *
TII = ST.getInstrInfo();
277 while (InsertPt !=
MBB.
end() &&
283 MRI.getTargetRegisterInfo()->getPointerRegClass(MF);
286 SPReg =
MRI.createVirtualRegister(PtrRC);
288 const char *ES =
"__stack_pointer";
293 bool HasBP = hasBP(MF);
296 Register BasePtr =
MRI.createVirtualRegister(PtrRC);
297 FI->setBasePointerVreg(BasePtr);
303 Register OffsetReg =
MRI.createVirtualRegister(PtrRC);
311 Register BitmaskReg =
MRI.createVirtualRegister(PtrRC);
312 Align Alignment = MFI.getMaxAlign();
326 if (StackSize && needsSPWriteback(MF)) {
334 if (!needsSP(MF) || !needsSPWriteback(MF))
337 const auto *
TII = ST.getInstrInfo();
342 if (InsertPt !=
MBB.
end())
343 DL = InsertPt->getDebugLoc();
351 SPReg = FI->getBasePointerVreg();
352 }
else if (StackSize) {
354 MRI.getTargetRegisterInfo()->getPointerRegClass(MF);
355 Register OffsetReg =
MRI.createVirtualRegister(PtrRC);
361 SPReg =
MRI.createVirtualRegister(PtrRC);
385 Loc.
Kind = DwarfFrameBase::WasmFrameBase;
unsigned const MachineRegisterInfo * MRI
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
const HexagonInstrInfo * TII
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class implements WebAssembly-specific bits of TargetFrameLowering class.
This file contains the WebAssembly implementation of the TargetInstrInfo class.
This file provides WebAssembly-specific target descriptions.
This file declares WebAssembly-specific per-machine-function information.
This file declares the WebAssembly-specific subclass of TargetSubtarget.
This file declares the WebAssembly-specific subclass of TargetMachine.
This file contains the declaration of the WebAssembly-specific type parsing utility functions.
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end.
an instruction to allocate memory on the stack
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
unsigned getAddressSpace() const
Return the address space for the allocation.
bool hasPersonalityFn() const
Check whether this function has a personality function.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
ExceptionHandling getExceptionHandlingType() const
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
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 ...
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
const AllocaInst * getObjectAllocation(int ObjectIdx) const
Return the underlying Alloca of the specified stack object if it exists.
bool hasCalls() const
Return true if the current function has any function calls.
bool isFrameAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
void setObjectOffset(int ObjectIdx, int64_t SPOffset)
Set the stack frame offset of the specified object.
bool hasPatchPoint() const
This method may be called any time after instruction selection is complete to determine if there is a...
void setObjectSize(int ObjectIdx, int64_t Size)
Change the size of the specified stack object.
void setStackID(int ObjectIdx, uint8_t ID)
bool hasStackMap() const
This method may be called any time after instruction selection is complete to determine if there is a...
uint8_t getStackID(int ObjectIdx) const
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
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 char * createExternalSymbolName(StringRef Name)
Allocate a string and populate it with the given external symbol name.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
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
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const MachineInstrBuilder & addExternalSymbol(const char *FnName, unsigned TargetFlags=0) const
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
MachineOperand class - Representation of each machine instruction operand.
Wrapper class representing virtual and physical registers.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
virtual bool isSupportedStackID(TargetStackID::Value ID) const
const MCAsmInfo * getMCAsmInfo() const
Return target specific asm information.
static unsigned getOpcAdd(const MachineFunction &MF)
static unsigned getFPReg(const MachineFunction &MF)
bool needsPrologForEH(const MachineFunction &MF) const
static unsigned getOpcGlobSet(const MachineFunction &MF)
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 getOpcAnd(const MachineFunction &MF)
static unsigned getSPReg(const MachineFunction &MF)
static unsigned getOpcGlobGet(const MachineFunction &MF)
DwarfFrameBase getDwarfFrameBase(const MachineFunction &MF) const override
Return the frame base information to be encoded in the DWARF subprogram debug info.
bool isSupportedStackID(TargetStackID::Value ID) const override
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...
static unsigned getOpcConst(const MachineFunction &MF)
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
These methods insert prolog and epilog code into the function.
void writeSPToGlobal(unsigned SrcReg, MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator &InsertStore, const DebugLoc &DL) const
Write SP back to __stack_pointer global.
bool hasFP(const MachineFunction &MF) const override
Return true if the specified function should have a dedicated frame pointer register.
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
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...
static std::optional< unsigned > getLocalForStackObject(MachineFunction &MF, int FrameIndex)
static unsigned getOpcSub(const MachineFunction &MF)
This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...
unsigned getFrameBaseLocal() const
const std::vector< MVT > & getLocals() const
bool isFrameBaseVirtual() const
const std::vector< MVT > & getParams() const
bool isArgument(unsigned Opc)
bool isWasmVarAddressSpace(unsigned AS)
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
@ Wasm
WebAssembly Exception Handling.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty, SmallVectorImpl< EVT > &ValueVTs, SmallVectorImpl< EVT > *MemVTs, SmallVectorImpl< TypeSize > *Offsets=nullptr, TypeSize StartingOffset=TypeSize::getZero())
ComputeValueVTs - Given an LLVM IR type, compute a sequence of EVTs that represent all the individual...
This struct is a compact representation of a valid (non-zero power of two) alignment.
uint64_t value() const
This is a hole in the type system and should not be abused.
union llvm::TargetFrameLowering::DwarfFrameBase::@246 Location
enum llvm::TargetFrameLowering::DwarfFrameBase::FrameBaseKind Kind
struct WasmFrameBase WasmLoc