42 enum Lowering { TouchAndSub, Sub, Probe };
51 Lowering getLowering(int64_t CurrentOffset, int64_t AllocaAmount);
61 unsigned SlotSize = 0;
62 int64_t StackProbeSize = 0;
63 bool NoStackArgProbe =
false;
71char X86DynAllocaExpander::ID = 0;
76 "X86 DynAlloca Expander",
false,
false)
79 return new X86DynAllocaExpander();
84 assert(
MI->getOpcode() == X86::DYN_ALLOCA_32 ||
85 MI->getOpcode() == X86::DYN_ALLOCA_64);
88 Register AmountReg =
MI->getOperand(0).getReg();
92 (Def->getOpcode() != X86::MOV32ri && Def->getOpcode() != X86::MOV64ri) ||
93 !Def->getOperand(1).isImm())
96 return Def->getOperand(1).getImm();
99X86DynAllocaExpander::Lowering
100X86DynAllocaExpander::getLowering(int64_t CurrentOffset,
101 int64_t AllocaAmount) {
103 if (AllocaAmount < 0 || AllocaAmount > StackProbeSize)
107 if (CurrentOffset + AllocaAmount <= StackProbeSize)
115 switch (
MI.getOpcode()) {
133 LoweringMap &Lowerings) {
141 OutOffset[&
MBB] = INT32_MAX;
157 if (
MI.getOpcode() == X86::DYN_ALLOCA_32 ||
158 MI.getOpcode() == X86::DYN_ALLOCA_64) {
177 }
else if (
MI.getOpcode() == X86::ADJCALLSTACKUP32 ||
178 MI.getOpcode() == X86::ADJCALLSTACKUP64) {
179 Offset -=
MI.getOperand(0).getImm();
180 }
else if (
MI.getOpcode() == X86::ADJCALLSTACKDOWN32 ||
181 MI.getOpcode() == X86::ADJCALLSTACKDOWN64) {
182 Offset +=
MI.getOperand(0).getImm();
183 }
else if (
MI.modifiesRegister(StackPtr,
TRI)) {
195 return X86::SUB64ri32;
206 MI->eraseFromParent();
212 bool Is64Bit = STI->is64Bit();
213 bool Is64BitAlloca =
MI->getOpcode() == X86::DYN_ALLOCA_64;
214 assert(SlotSize == 4 || SlotSize == 8);
216 std::optional<MachineFunction::DebugInstrOperandPair> InstrNum;
217 if (
unsigned Num =
MI->peekDebugInstrNum()) {
224 assert(Amount >= SlotSize);
227 unsigned RegA = Is64Bit ? X86::RAX : X86::EAX;
239 if (Amount == SlotSize) {
241 unsigned RegA = Is64Bit ? X86::RAX : X86::EAX;
252 if (!NoStackArgProbe) {
254 unsigned RegA = Is64BitAlloca ? X86::RAX : X86::EAX;
256 .
addReg(
MI->getOperand(0).getReg());
264 TII->get(Is64BitAlloca ? X86::SUB64rr : X86::SUB32rr), StackPtr)
266 .
addReg(
MI->getOperand(0).getReg());
271 Register AmountReg =
MI->getOperand(0).getReg();
272 MI->eraseFromParent();
275 if (
MRI->use_empty(AmountReg))
277 AmountDef->eraseFromParent();
286 TII = STI->getInstrInfo();
287 TRI = STI->getRegisterInfo();
289 SlotSize =
TRI->getSlotSize();
290 StackProbeSize = STI->getTargetLowering()->getStackProbeSize(MF);
295 LoweringMap Lowerings;
296 computeLowerings(MF, Lowerings);
297 for (
auto &
P : Lowerings)
298 lower(
P.first,
P.second);
unsigned const MachineRegisterInfo * MRI
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
const HexagonInstrInfo * TII
unsigned const TargetRegisterInfo * TRI
This file implements a map that provides insertion order iteration.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
pre isel intrinsic Pre ISel Intrinsic Lowering
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isPushPop(const MachineInstr &MI)
static int64_t getDynAllocaAmount(MachineInstr *MI, MachineRegisterInfo *MRI)
Return the allocation amount for a DynAlloca instruction, or -1 if unknown.
static unsigned getSubOpcode(bool Is64Bit)
FunctionPass class - This class is used to implement most global optimizations.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
iterator_range< pred_iterator > predecessors()
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
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.
Representation of each machine instruction.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
This class implements a map that also provides access to all stored values in a deterministic order.
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Wrapper class representing virtual and physical registers.
StringRef - Represent a constant reference to a string, i.e.
TargetInstrInfo - Interface to description of machine instruction set.
X86MachineFunctionInfo - This class is derived from MachineFunction and contains private X86 target-s...
bool hasDynAlloca() const
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ Undef
Value of the register doesn't matter.
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.
FunctionPass * createX86DynAllocaExpander()
Return a pass that expands DynAlloca pseudo-instructions.