44 enum Lowering { TouchAndSub, Sub, Probe };
53 Lowering getLowering(int64_t CurrentOffset, int64_t AllocaAmount);
63 unsigned SlotSize = 0;
64 int64_t StackProbeSize = 0;
65 bool NoStackArgProbe =
false;
71char X86DynAllocaExpander::ID = 0;
76 return new X86DynAllocaExpander();
81 assert(
MI->getOpcode() == X86::DYN_ALLOCA_32 ||
82 MI->getOpcode() == X86::DYN_ALLOCA_64);
85 Register AmountReg =
MI->getOperand(0).getReg();
89 (Def->getOpcode() != X86::MOV32ri && Def->getOpcode() != X86::MOV64ri) ||
90 !Def->getOperand(1).isImm())
93 return Def->getOperand(1).getImm();
96X86DynAllocaExpander::Lowering
97X86DynAllocaExpander::getLowering(int64_t CurrentOffset,
98 int64_t AllocaAmount) {
100 if (AllocaAmount < 0 || AllocaAmount > StackProbeSize)
104 if (CurrentOffset + AllocaAmount <= StackProbeSize)
112 switch (
MI.getOpcode()) {
130 LoweringMap &Lowerings) {
138 OutOffset[&
MBB] = INT32_MAX;
154 if (
MI.getOpcode() == X86::DYN_ALLOCA_32 ||
155 MI.getOpcode() == X86::DYN_ALLOCA_64) {
174 }
else if (
MI.getOpcode() == X86::ADJCALLSTACKUP32 ||
175 MI.getOpcode() == X86::ADJCALLSTACKUP64) {
176 Offset -=
MI.getOperand(0).getImm();
177 }
else if (
MI.getOpcode() == X86::ADJCALLSTACKDOWN32 ||
178 MI.getOpcode() == X86::ADJCALLSTACKDOWN64) {
179 Offset +=
MI.getOperand(0).getImm();
180 }
else if (
MI.modifiesRegister(StackPtr,
TRI)) {
192 return X86::SUB64ri32;
203 MI->eraseFromParent();
209 bool Is64Bit = STI->is64Bit();
210 bool Is64BitAlloca =
MI->getOpcode() == X86::DYN_ALLOCA_64;
211 assert(SlotSize == 4 || SlotSize == 8);
213 std::optional<MachineFunction::DebugInstrOperandPair> InstrNum;
214 if (
unsigned Num =
MI->peekDebugInstrNum()) {
221 assert(Amount >= SlotSize);
224 unsigned RegA = Is64Bit ? X86::RAX : X86::EAX;
236 if (Amount == SlotSize) {
238 unsigned RegA = Is64Bit ? X86::RAX : X86::EAX;
249 if (!NoStackArgProbe) {
251 unsigned RegA = Is64BitAlloca ? X86::RAX : X86::EAX;
253 .
addReg(
MI->getOperand(0).getReg());
261 TII->get(Is64BitAlloca ? X86::SUB64rr : X86::SUB32rr), StackPtr)
263 .
addReg(
MI->getOperand(0).getReg());
268 Register AmountReg =
MI->getOperand(0).getReg();
269 MI->eraseFromParent();
272 if (
MRI->use_empty(AmountReg))
274 AmountDef->eraseFromParent();
283 TII = STI->getInstrInfo();
284 TRI = STI->getRegisterInfo();
286 SlotSize =
TRI->getSlotSize();
287 StackProbeSize = STI->getTargetLowering()->getStackProbeSize(MF);
292 LoweringMap Lowerings;
293 computeLowerings(MF, Lowerings);
294 for (
auto &
P : Lowerings)
295 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.
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.