43 enum Lowering { TouchAndSub, Sub, Probe };
52 Lowering getLowering(int64_t CurrentOffset, int64_t AllocaAmount);
62 unsigned SlotSize = 0;
63 int64_t StackProbeSize = 0;
64 bool NoStackArgProbe =
false;
66 StringRef getPassName()
const override {
return "X86 WinAlloca Expander"; }
75 return new X86WinAllocaExpander();
95 X86WinAllocaExpander::Lowering
96 X86WinAllocaExpander::getLowering(int64_t CurrentOffset,
97 int64_t AllocaAmount) {
99 if (AllocaAmount < 0 || AllocaAmount > StackProbeSize)
103 if (CurrentOffset + AllocaAmount <= StackProbeSize)
131 LoweringMap &Lowerings) {
139 OutOffset[&MBB] = INT32_MAX;
151 Offset =
std::max(Offset, OutOffset[Pred]);
152 if (Offset == -1) Offset = INT32_MAX;
155 if (
MI.getOpcode() == X86::WIN_ALLOCA_32 ||
156 MI.getOpcode() == X86::WIN_ALLOCA_64) {
159 Lowering L = getLowering(Offset, Amount);
175 }
else if (
MI.getOpcode() == X86::ADJCALLSTACKUP32 ||
176 MI.getOpcode() == X86::ADJCALLSTACKUP64) {
177 Offset -=
MI.getOperand(0).getImm();
178 }
else if (
MI.getOpcode() == X86::ADJCALLSTACKDOWN32 ||
179 MI.getOpcode() == X86::ADJCALLSTACKDOWN64) {
180 Offset +=
MI.getOperand(0).getImm();
181 }
else if (
MI.modifiesRegister(StackPtr,
TRI)) {
193 return isInt<8>(Amount) ? X86::SUB64ri8 : X86::SUB64ri32;
194 return isInt<8>(Amount) ? X86::SUB32ri8 : X86::SUB32ri;
210 bool Is64Bit = STI->is64Bit();
211 bool Is64BitAlloca = MI->
getOpcode() == X86::WIN_ALLOCA_64;
212 assert(SlotSize == 4 || SlotSize == 8);
216 assert(Amount >= SlotSize);
219 unsigned RegA = Is64Bit ? X86::RAX :
X86::EAX;
220 BuildMI(*MBB, I, DL,
TII->get(Is64Bit ? X86::PUSH64r : X86::PUSH32r))
231 if (Amount == SlotSize) {
233 unsigned RegA = Is64Bit ? X86::RAX :
X86::EAX;
234 BuildMI(*MBB, I, DL,
TII->get(Is64Bit ? X86::PUSH64r : X86::PUSH32r))
245 if (!NoStackArgProbe) {
247 unsigned RegA = Is64BitAlloca ? X86::RAX :
X86::EAX;
248 BuildMI(*MBB, MI, DL,
TII->get(TargetOpcode::COPY), RegA)
252 STI->getFrameLowering()->emitStackProbe(*MBB->
getParent(), *MBB,
MI, DL,
257 TII->get(Is64BitAlloca ? X86::SUB64rr : X86::SUB32rr), StackPtr)
268 if (
MRI->use_empty(AmountReg))
270 AmountDef->eraseFromParent();
279 TII = STI->getInstrInfo();
280 TRI = STI->getRegisterInfo();
281 StackPtr =
TRI->getStackRegister();
282 SlotSize =
TRI->getSlotSize();
284 StackProbeSize = 4096;
295 LoweringMap Lowerings;
296 computeLowerings(MF, Lowerings);
297 for (
auto &
P : Lowerings)
298 lower(
P.first,
P.second);
This class represents lattice values for constants.
bool hasWinAlloca() const
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
constexpr bool isInt< 8 >(int64_t x)
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
This class implements a map that also provides access to all stored values in a deterministic order...
unsigned const TargetRegisterInfo * TRI
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
X86MachineFunctionInfo - This class is derived from MachineFunction and contains private X86 target-s...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
static int64_t getWinAllocaAmount(MachineInstr *MI, MachineRegisterInfo *MRI)
Return the allocation amount for a WinAlloca instruction, or -1 if unknown.
TargetInstrInfo - Interface to description of machine instruction set.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
unsigned const MachineRegisterInfo * MRI
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
FunctionPass class - This class is used to implement most global optimizations.
iterator_range< pred_iterator > predecessors()
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Align max(MaybeAlign Lhs, Align Rhs)
MachineInstr * getUniqueVRegDef(unsigned Reg) const
getUniqueVRegDef - Return the unique machine instr that defines the specified virtual register or nul...
const Function & getFunction() const
Return the LLVM function that this machine code represents.
const MachineBasicBlock * getParent() const
FunctionPass * createX86WinAllocaExpander()
Return a pass that expands WinAlloca pseudo-instructions.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
StringRef getValueAsString() const
Return the attribute's value as a string.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
rpo Deduce function attributes in RPO
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
static unsigned getSubOpcode(bool Is64Bit, int64_t Amount)
StringRef - Represent a constant reference to a string, i.e.
static bool isPushPop(const MachineInstr &MI)
Register getReg() const
getReg - Returns the register number.
const MachineOperand & getOperand(unsigned i) const
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Wrapper class representing virtual and physical registers.