LLVM  3.7.0
X86FrameLowering.h
Go to the documentation of this file.
1 //===-- X86TargetFrameLowering.h - Define frame lowering for X86 -*- C++ -*-==//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This class implements X86-specific bits of TargetFrameLowering class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_LIB_TARGET_X86_X86FRAMELOWERING_H
15 #define LLVM_LIB_TARGET_X86_X86FRAMELOWERING_H
16 
18 
19 namespace llvm {
20 
21 class MachineInstrBuilder;
22 class MCCFIInstruction;
23 class X86Subtarget;
24 class X86RegisterInfo;
25 
27 public:
28  X86FrameLowering(const X86Subtarget &STI, unsigned StackAlignOverride);
29 
30  // Cached subtarget predicates.
31 
32  const X86Subtarget &STI;
35 
36  unsigned SlotSize;
37 
38  /// Is64Bit implies that x86_64 instructions are available.
39  bool Is64Bit;
40 
41  bool IsLP64;
42 
43  /// True if the 64-bit frame or stack pointer should be used. True for most
44  /// 64-bit targets with the exception of x32. If this is false, 32-bit
45  /// instruction operands should be used to manipulate StackPtr and FramePtr.
47 
48  unsigned StackPtr;
49 
50  /// Emit a call to the target's stack probe function. This is required for all
51  /// large stack allocations on Windows. The caller is required to materialize
52  /// the number of bytes to probe in RAX/EAX.
55 
58  DebugLoc DL) const;
59 
60  /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
61  /// the function.
62  void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
63  void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
64 
66  MachineBasicBlock &PrologueMBB) const override;
67 
69  MachineBasicBlock &PrologueMBB) const override;
70 
71  void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
72  RegScavenger *RS = nullptr) const override;
73 
74  bool
76  const TargetRegisterInfo *TRI,
77  std::vector<CalleeSavedInfo> &CSI) const override;
78 
81  const std::vector<CalleeSavedInfo> &CSI,
82  const TargetRegisterInfo *TRI) const override;
83 
86  const std::vector<CalleeSavedInfo> &CSI,
87  const TargetRegisterInfo *TRI) const override;
88 
89  bool hasFP(const MachineFunction &MF) const override;
90  bool hasReservedCallFrame(const MachineFunction &MF) const override;
91  bool canSimplifyCallFramePseudos(const MachineFunction &MF) const override;
92  bool needsFrameIndexResolution(const MachineFunction &MF) const override;
93 
94  int getFrameIndexOffset(const MachineFunction &MF, int FI) const override;
95  int getFrameIndexReference(const MachineFunction &MF, int FI,
96  unsigned &FrameReg) const override;
97 
98  int getFrameIndexOffsetFromSP(const MachineFunction &MF, int FI) const;
99  int getFrameIndexReferenceFromSP(const MachineFunction &MF, int FI,
100  unsigned &FrameReg) const override;
101 
103  MachineBasicBlock &MBB,
104  MachineBasicBlock::iterator MI) const override;
105 
106  /// Check the instruction before/after the passed instruction. If
107  /// it is an ADD/SUB/LEA instruction it is deleted argument and the
108  /// stack adjustment is returned as a positive value for ADD/LEA and
109  /// a negative for SUB.
111  bool doMergeWithPrevious) const;
112 
113  /// Emit a series of instructions to increment / decrement the stack
114  /// pointer by a constant value.
116  int64_t NumBytes, bool InEpilogue) const;
117 
118  /// Check that LEA can be used on SP in an epilogue sequence for \p MF.
119  bool canUseLEAForSPInEpilogue(const MachineFunction &MF) const;
120 
121  /// Check whether or not the given \p MBB can be used as a epilogue
122  /// for the target.
123  /// The epilogue will be inserted before the first terminator of that block.
124  /// This method is used by the shrink-wrapping pass to decide if
125  /// \p MBB will be correctly handled by the target.
126  bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override;
127 
128 private:
129  /// convertArgMovsToPushes - This method tries to convert a call sequence
130  /// that uses sub and mov instructions to put the argument onto the stack
131  /// into a series of pushes.
132  /// Returns true if the transformation succeeded, false if not.
133  bool convertArgMovsToPushes(MachineFunction &MF,
134  MachineBasicBlock &MBB,
136  uint64_t Amount) const;
137 
138  uint64_t calculateMaxStackAlign(const MachineFunction &MF) const;
139 
140  /// Wraps up getting a CFI index and building a MachineInstr for it.
141  void BuildCFI(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
142  DebugLoc DL, MCCFIInstruction CFIInst) const;
143 
144  /// Aligns the stack pointer by ANDing it with -MaxAlign.
145  void BuildStackAlignAND(MachineBasicBlock &MBB,
147  uint64_t MaxAlign) const;
148 
149  /// Adjusts the stack pointer using LEA, SUB, or ADD.
150  MachineInstrBuilder BuildStackAdjustment(MachineBasicBlock &MBB,
152  DebugLoc DL, int64_t Offset,
153  bool InEpilogue) const;
154 };
155 
156 } // End llvm namespace
157 
158 #endif
bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const std::vector< CalleeSavedInfo > &CSI, const TargetRegisterInfo *TRI) const override
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
A debug info location.
Definition: DebugLoc.h:34
X86FrameLowering(const X86Subtarget &STI, unsigned StackAlignOverride)
bool Uses64BitFramePtr
True if the 64-bit frame or stack pointer should be used.
void adjustForHiPEPrologue(MachineFunction &MF, MachineBasicBlock &PrologueMBB) const override
Erlang programs may need a special prologue to handle the stack size they might need at runtime...
bool hasFP(const MachineFunction &MF) const override
hasFP - Return true if the specified function should have a dedicated frame pointer register...
bool needsFrameIndexResolution(const MachineFunction &MF) const override
int getFrameIndexReferenceFromSP(const MachineFunction &MF, int FI, unsigned &FrameReg) const override
Same as above, except that the 'base register' will always be RSP, not RBP on x86.
bool Is64Bit
Is64Bit implies that x86_64 instructions are available.
TargetInstrInfo - Interface to description of machine instruction set.
bundle_iterator< MachineInstr, instr_iterator > iterator
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override
Check whether or not the given MBB can be used as a epilogue for the target.
void emitCalleeSavedFrameMoves(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, DebugLoc DL) const
int mergeSPUpdates(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, bool doMergeWithPrevious) const
Check the instruction before/after the passed instruction.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
void eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const override
eliminateCallFramePseudoInstr - This method is called during prolog/epilog code insertion to eliminat...
const X86Subtarget & STI
bool hasReservedCallFrame(const MachineFunction &MF) const override
hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required, we reserve argument space for call sites in the function immediately on entry to the current function.
Information about stack frame layout on the target.
bool canSimplifyCallFramePseudos(const MachineFunction &MF) const override
canSimplifyCallFramePseudos - If there is a reserved call frame, the call frame pseudos can be simpli...
const TargetInstrInfo & TII
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
bool canUseLEAForSPInEpilogue(const MachineFunction &MF) const
Check that LEA can be used on SP in an epilogue sequence for MF.
bool assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI) const override
assignCalleeSavedSpillSlots - Allows target to override spill slot assignment logic.
void adjustForSegmentedStacks(MachineFunction &MF, MachineBasicBlock &PrologueMBB) const override
Adjust the prologue to have the function use segmented stacks.
void emitStackProbeCall(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, DebugLoc DL) const
Emit a call to the target's stack probe function.
#define I(x, y, z)
Definition: MD5.cpp:54
int getFrameIndexOffsetFromSP(const MachineFunction &MF, int FI) const
const X86RegisterInfo * TRI
void emitSPUpdate(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, int64_t NumBytes, bool InEpilogue) const
Emit a series of instructions to increment / decrement the stack pointer by a constant value...
int getFrameIndexReference(const MachineFunction &MF, int FI, unsigned &FrameReg) const override
getFrameIndexReference - This method should return the base register and offset used to reference a f...
bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const std::vector< CalleeSavedInfo > &CSI, const TargetRegisterInfo *TRI) const override
spillCalleeSavedRegisters - Issues instruction(s) to spill all callee saved registers and returns tru...
int getFrameIndexOffset(const MachineFunction &MF, int FI) const override
getFrameIndexOffset - Returns the displacement from the frame register to the stack frame of the spec...