Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

219 lines
9.3 KiB

  1. //===-- llvm/Target/TargetFrameLowering.h ---------------------------*- 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. // Interface to describe the layout of a stack frame on the target machine.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_TARGET_TARGETFRAMELOWERING_H
  14. #define LLVM_TARGET_TARGETFRAMELOWERING_H
  15. #include "llvm/CodeGen/MachineBasicBlock.h"
  16. #include <utility>
  17. #include <vector>
  18. namespace llvm {
  19. class CalleeSavedInfo;
  20. class MachineFunction;
  21. class RegScavenger;
  22. /// Information about stack frame layout on the target. It holds the direction
  23. /// of stack growth, the known stack alignment on entry to each function, and
  24. /// the offset to the locals area.
  25. ///
  26. /// The offset to the local area is the offset from the stack pointer on
  27. /// function entry to the first location where function data (local variables,
  28. /// spill locations) can be stored.
  29. class TargetFrameLowering {
  30. public:
  31. enum StackDirection {
  32. StackGrowsUp, // Adding to the stack increases the stack address
  33. StackGrowsDown // Adding to the stack decreases the stack address
  34. };
  35. // Maps a callee saved register to a stack slot with a fixed offset.
  36. struct SpillSlot {
  37. unsigned Reg;
  38. int Offset; // Offset relative to stack pointer on function entry.
  39. };
  40. private:
  41. StackDirection StackDir;
  42. unsigned StackAlignment;
  43. unsigned TransientStackAlignment;
  44. int LocalAreaOffset;
  45. bool StackRealignable;
  46. public:
  47. TargetFrameLowering(StackDirection D, unsigned StackAl, int LAO,
  48. unsigned TransAl = 1, bool StackReal = true)
  49. : StackDir(D), StackAlignment(StackAl), TransientStackAlignment(TransAl),
  50. LocalAreaOffset(LAO), StackRealignable(StackReal) {}
  51. virtual ~TargetFrameLowering();
  52. // These methods return information that describes the abstract stack layout
  53. // of the target machine.
  54. /// getStackGrowthDirection - Return the direction the stack grows
  55. ///
  56. StackDirection getStackGrowthDirection() const { return StackDir; }
  57. /// getStackAlignment - This method returns the number of bytes to which the
  58. /// stack pointer must be aligned on entry to a function. Typically, this
  59. /// is the largest alignment for any data object in the target.
  60. ///
  61. unsigned getStackAlignment() const { return StackAlignment; }
  62. /// getTransientStackAlignment - This method returns the number of bytes to
  63. /// which the stack pointer must be aligned at all times, even between
  64. /// calls.
  65. ///
  66. unsigned getTransientStackAlignment() const {
  67. return TransientStackAlignment;
  68. }
  69. /// isStackRealignable - This method returns whether the stack can be
  70. /// realigned.
  71. bool isStackRealignable() const {
  72. return StackRealignable;
  73. }
  74. /// getOffsetOfLocalArea - This method returns the offset of the local area
  75. /// from the stack pointer on entrance to a function.
  76. ///
  77. int getOffsetOfLocalArea() const { return LocalAreaOffset; }
  78. /// getCalleeSavedSpillSlots - This method returns a pointer to an array of
  79. /// pairs, that contains an entry for each callee saved register that must be
  80. /// spilled to a particular stack location if it is spilled.
  81. ///
  82. /// Each entry in this array contains a <register,offset> pair, indicating the
  83. /// fixed offset from the incoming stack pointer that each register should be
  84. /// spilled at. If a register is not listed here, the code generator is
  85. /// allowed to spill it anywhere it chooses.
  86. ///
  87. virtual const SpillSlot *
  88. getCalleeSavedSpillSlots(unsigned &NumEntries) const {
  89. NumEntries = 0;
  90. return 0;
  91. }
  92. /// targetHandlesStackFrameRounding - Returns true if the target is
  93. /// responsible for rounding up the stack frame (probably at emitPrologue
  94. /// time).
  95. virtual bool targetHandlesStackFrameRounding() const {
  96. return false;
  97. }
  98. /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
  99. /// the function.
  100. virtual void emitPrologue(MachineFunction &MF) const = 0;
  101. virtual void emitEpilogue(MachineFunction &MF,
  102. MachineBasicBlock &MBB) const = 0;
  103. /// Adjust the prologue to have the function use segmented stacks. This works
  104. /// by adding a check even before the "normal" function prologue.
  105. virtual void adjustForSegmentedStacks(MachineFunction &MF) const { }
  106. /// Adjust the prologue to add Erlang Run-Time System (ERTS) specific code in
  107. /// the assembly prologue to explicitly handle the stack.
  108. virtual void adjustForHiPEPrologue(MachineFunction &MF) const { }
  109. /// spillCalleeSavedRegisters - Issues instruction(s) to spill all callee
  110. /// saved registers and returns true if it isn't possible / profitable to do
  111. /// so by issuing a series of store instructions via
  112. /// storeRegToStackSlot(). Returns false otherwise.
  113. virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
  114. MachineBasicBlock::iterator MI,
  115. const std::vector<CalleeSavedInfo> &CSI,
  116. const TargetRegisterInfo *TRI) const {
  117. return false;
  118. }
  119. /// restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee
  120. /// saved registers and returns true if it isn't possible / profitable to do
  121. /// so by issuing a series of load instructions via loadRegToStackSlot().
  122. /// Returns false otherwise.
  123. virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
  124. MachineBasicBlock::iterator MI,
  125. const std::vector<CalleeSavedInfo> &CSI,
  126. const TargetRegisterInfo *TRI) const {
  127. return false;
  128. }
  129. /// hasFP - Return true if the specified function should have a dedicated
  130. /// frame pointer register. For most targets this is true only if the function
  131. /// has variable sized allocas or if frame pointer elimination is disabled.
  132. virtual bool hasFP(const MachineFunction &MF) const = 0;
  133. /// hasReservedCallFrame - Under normal circumstances, when a frame pointer is
  134. /// not required, we reserve argument space for call sites in the function
  135. /// immediately on entry to the current function. This eliminates the need for
  136. /// add/sub sp brackets around call sites. Returns true if the call frame is
  137. /// included as part of the stack frame.
  138. virtual bool hasReservedCallFrame(const MachineFunction &MF) const {
  139. return !hasFP(MF);
  140. }
  141. /// canSimplifyCallFramePseudos - When possible, it's best to simplify the
  142. /// call frame pseudo ops before doing frame index elimination. This is
  143. /// possible only when frame index references between the pseudos won't
  144. /// need adjusting for the call frame adjustments. Normally, that's true
  145. /// if the function has a reserved call frame or a frame pointer. Some
  146. /// targets (Thumb2, for example) may have more complicated criteria,
  147. /// however, and can override this behavior.
  148. virtual bool canSimplifyCallFramePseudos(const MachineFunction &MF) const {
  149. return hasReservedCallFrame(MF) || hasFP(MF);
  150. }
  151. /// getFrameIndexOffset - Returns the displacement from the frame register to
  152. /// the stack frame of the specified index.
  153. virtual int getFrameIndexOffset(const MachineFunction &MF, int FI) const;
  154. /// getFrameIndexReference - This method should return the base register
  155. /// and offset used to reference a frame index location. The offset is
  156. /// returned directly, and the base register is returned via FrameReg.
  157. virtual int getFrameIndexReference(const MachineFunction &MF, int FI,
  158. unsigned &FrameReg) const;
  159. /// processFunctionBeforeCalleeSavedScan - This method is called immediately
  160. /// before PrologEpilogInserter scans the physical registers used to determine
  161. /// what callee saved registers should be spilled. This method is optional.
  162. virtual void processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
  163. RegScavenger *RS = NULL) const {
  164. }
  165. /// processFunctionBeforeFrameFinalized - This method is called immediately
  166. /// before the specified function's frame layout (MF.getFrameInfo()) is
  167. /// finalized. Once the frame is finalized, MO_FrameIndex operands are
  168. /// replaced with direct constants. This method is optional.
  169. ///
  170. virtual void processFunctionBeforeFrameFinalized(MachineFunction &MF,
  171. RegScavenger *RS = NULL) const {
  172. }
  173. /// eliminateCallFramePseudoInstr - This method is called during prolog/epilog
  174. /// code insertion to eliminate call frame setup and destroy pseudo
  175. /// instructions (but only if the Target is using them). It is responsible
  176. /// for eliminating these instructions, replacing them with concrete
  177. /// instructions. This method need only be implemented if using call frame
  178. /// setup/destroy pseudo instructions.
  179. ///
  180. virtual void
  181. eliminateCallFramePseudoInstr(MachineFunction &MF,
  182. MachineBasicBlock &MBB,
  183. MachineBasicBlock::iterator MI) const {
  184. llvm_unreachable("Call Frame Pseudo Instructions do not exist on this "
  185. "target!");
  186. }
  187. };
  188. } // End llvm namespace
  189. #endif