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";
116 BuildMI(MBB, InsertAddr, DL,
TII->get(WebAssembly::CONST_I32),
Zero)
121 BuildMI(MBB, InsertStore, DL,
TII->get(WebAssembly::STORE_I32))
128 BuildMI(MBB, InsertStore, DL,
TII->get(WebAssembly::SET_GLOBAL_I32))
129 .addExternalSymbol(SPSymbol)
138 assert(!I->getOperand(0).getImm() && (
hasFP(MF) || hasBP(MF)) &&
139 "Call frame pseudos should only be used for dynamic stack adjustment");
141 if (I->getOpcode() ==
TII->getCallFrameDestroyOpcode() &&
154 "WebAssembly should not have callee-saved registers");
156 if (!needsSP(MF, MFI))
return;
162 auto InsertPt = MBB.
begin();
168 MRI.getTargetRegisterInfo()->getPointerRegClass(MF);
169 unsigned SPReg = WebAssembly::SP32;
171 SPReg =
MRI.createVirtualRegister(PtrRC);
173 const char *ES =
"__stack_pointer";
177 unsigned Zero =
MRI.createVirtualRegister(PtrRC);
179 BuildMI(MBB, InsertPt, DL,
TII->get(WebAssembly::CONST_I32),
Zero)
185 BuildMI(MBB, InsertPt, DL,
TII->get(WebAssembly::LOAD_I32), SPReg)
191 BuildMI(MBB, InsertPt, DL,
TII->get(WebAssembly::GET_GLOBAL_I32), SPReg)
192 .addExternalSymbol(SPSymbol);
195 bool HasBP = hasBP(MF);
198 unsigned BasePtr =
MRI.createVirtualRegister(PtrRC);
199 FI->setBasePointerVreg(BasePtr);
200 BuildMI(MBB, InsertPt, DL,
TII->get(WebAssembly::COPY), BasePtr)
205 unsigned OffsetReg =
MRI.createVirtualRegister(PtrRC);
206 BuildMI(MBB, InsertPt, DL,
TII->get(WebAssembly::CONST_I32), OffsetReg)
208 BuildMI(MBB, InsertPt, DL,
TII->get(WebAssembly::SUB_I32),
214 unsigned BitmaskReg =
MRI.createVirtualRegister(PtrRC);
217 "Alignment must be a power of 2");
218 BuildMI(MBB, InsertPt, DL,
TII->get(WebAssembly::CONST_I32), BitmaskReg)
219 .addImm((
int)~(Alignment - 1));
220 BuildMI(MBB, InsertPt, DL,
TII->get(WebAssembly::AND_I32),
222 .addReg(WebAssembly::SP32)
229 BuildMI(MBB, InsertPt, DL,
TII->get(WebAssembly::COPY),
231 .addReg(WebAssembly::SP32);
233 if (StackSize && needsSPWriteback(MF, MFI)) {
242 if (!needsSP(MF, MFI) || !needsSPWriteback(MF, MFI))
return;
248 if (InsertPt != MBB.
end())
249 DL = InsertPt->getDebugLoc();
257 SPReg = FI->getBasePointerVreg();
258 }
else if (StackSize) {
260 MRI.getTargetRegisterInfo()->getPointerRegClass(MF);
261 unsigned OffsetReg =
MRI.createVirtualRegister(PtrRC);
263 BuildMI(MBB, InsertPt, DL,
TII->get(WebAssembly::CONST_I32), OffsetReg)
267 SPReg =
MRI.createVirtualRegister(PtrRC);
268 BuildMI(MBB, InsertPt, DL,
TII->get(WebAssembly::ADD_I32), SPReg)
269 .addReg(
hasFP(MF) ? WebAssembly::FP32 : WebAssembly::SP32)
272 SPReg =
hasFP(MF) ? WebAssembly::FP32 : WebAssembly::SP32;
const Triple & getTargetTriple() const
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
These methods insert prolog and epilog code into the function.
unsigned createVirtualRegister(const TargetRegisterClass *RegClass)
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
bool adjustsStack() const
Return true if this function adjusts the stack – e.g., when calling another function.
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
bool hasFP(const MachineFunction &MF) const override
Return true if the specified function should have a dedicated frame pointer register.
unsigned getMaxAlignment() const
Return the alignment in bytes that this function must be aligned to, which is greater than the defaul...
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects...
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...
A description of a memory reference used in the backend.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
const HexagonInstrInfo * TII
const TargetRegisterInfo * getTargetRegisterInfo() const
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
bool isFrameAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s, unsigned base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
This file declares the WebAssembly-specific subclass of TargetMachine.
PseudoSourceValueManager & getPSVManager() const
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.
bool hasStackMap() const
This method may be called any time after instruction selection is complete to determine if there is a...
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 PseudoSourceValue * getExternalSymbolCallEntry(const char *ES)
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)
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
This class contains a discriminated union of information about pointers in memory operands...
const char * createExternalSymbolName(StringRef Name)
Allocate a string and populate it with the given external symbol name.
The memory access writes data.
bool hasCalls() const
Return true if the current function has any function calls.
This file declares the WebAssembly-specific subclass of TargetSubtarget.
bool isArgument(const MachineInstr &MI)
This file contains the WebAssembly implementation of the TargetInstrInfo class.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
The memory access reads data.
This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...
bool hasPatchPoint() const
This method may be called any time after instruction selection is complete to determine if there is a...
This class implements WebAssembly-specific bits of TargetFrameLowering class.
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
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 MachineInstrBuilder & addExternalSymbol(const char *FnName, unsigned char TargetFlags=0) const
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
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.
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
virtual const TargetRegisterClass * getPointerRegClass(const MachineFunction &MF, unsigned Kind=0) const
Returns a TargetRegisterClass used for pointer values.