MachineFrameInfo.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. //===-- CodeGen/MachineFrameInfo.h - Abstract Stack Frame Rep. --*- 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. // The file defines the MachineFrameInfo class.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_CODEGEN_MACHINEFRAMEINFO_H
  14. #define LLVM_CODEGEN_MACHINEFRAMEINFO_H
  15. #include "llvm/ADT/SmallVector.h"
  16. #include "llvm/Support/DataTypes.h"
  17. #include <cassert>
  18. #include <vector>
  19. namespace llvm {
  20. class raw_ostream;
  21. class DataLayout;
  22. class TargetRegisterClass;
  23. class Type;
  24. class MachineFunction;
  25. class MachineBasicBlock;
  26. class TargetFrameLowering;
  27. class TargetMachine;
  28. class BitVector;
  29. class Value;
  30. class AllocaInst;
  31. /// The CalleeSavedInfo class tracks the information need to locate where a
  32. /// callee saved register is in the current frame.
  33. class CalleeSavedInfo {
  34. unsigned Reg;
  35. int FrameIdx;
  36. public:
  37. explicit CalleeSavedInfo(unsigned R, int FI = 0)
  38. : Reg(R), FrameIdx(FI) {}
  39. // Accessors.
  40. unsigned getReg() const { return Reg; }
  41. int getFrameIdx() const { return FrameIdx; }
  42. void setFrameIdx(int FI) { FrameIdx = FI; }
  43. };
  44. /// The MachineFrameInfo class represents an abstract stack frame until
  45. /// prolog/epilog code is inserted. This class is key to allowing stack frame
  46. /// representation optimizations, such as frame pointer elimination. It also
  47. /// allows more mundane (but still important) optimizations, such as reordering
  48. /// of abstract objects on the stack frame.
  49. ///
  50. /// To support this, the class assigns unique integer identifiers to stack
  51. /// objects requested clients. These identifiers are negative integers for
  52. /// fixed stack objects (such as arguments passed on the stack) or nonnegative
  53. /// for objects that may be reordered. Instructions which refer to stack
  54. /// objects use a special MO_FrameIndex operand to represent these frame
  55. /// indexes.
  56. ///
  57. /// Because this class keeps track of all references to the stack frame, it
  58. /// knows when a variable sized object is allocated on the stack. This is the
  59. /// sole condition which prevents frame pointer elimination, which is an
  60. /// important optimization on register-poor architectures. Because original
  61. /// variable sized alloca's in the source program are the only source of
  62. /// variable sized stack objects, it is safe to decide whether there will be
  63. /// any variable sized objects before all stack objects are known (for
  64. /// example, register allocator spill code never needs variable sized
  65. /// objects).
  66. ///
  67. /// When prolog/epilog code emission is performed, the final stack frame is
  68. /// built and the machine instructions are modified to refer to the actual
  69. /// stack offsets of the object, eliminating all MO_FrameIndex operands from
  70. /// the program.
  71. ///
  72. /// @brief Abstract Stack Frame Information
  73. class MachineFrameInfo {
  74. // Represent a single object allocated on the stack.
  75. struct StackObject {
  76. // The offset of this object from the stack pointer on entry to
  77. // the function. This field has no meaning for a variable sized element.
  78. int64_t SPOffset;
  79. // The size of this object on the stack. 0 means a variable sized object,
  80. // ~0ULL means a dead object.
  81. uint64_t Size;
  82. // The required alignment of this stack slot.
  83. unsigned Alignment;
  84. // If true, the value of the stack object is set before
  85. // entering the function and is not modified inside the function. By
  86. // default, fixed objects are immutable unless marked otherwise.
  87. bool isImmutable;
  88. // If true the stack object is used as spill slot. It
  89. // cannot alias any other memory objects.
  90. bool isSpillSlot;
  91. /// If this stack object is originated from an Alloca instruction
  92. /// this value saves the original IR allocation. Can be NULL.
  93. const AllocaInst *Alloca;
  94. // If true, the object was mapped into the local frame
  95. // block and doesn't need additional handling for allocation beyond that.
  96. bool PreAllocated;
  97. // If true, an LLVM IR value might point to this object.
  98. // Normally, spill slots and fixed-offset objects don't alias IR-accessible
  99. // objects, but there are exceptions (on PowerPC, for example, some byval
  100. // arguments have ABI-prescribed offsets).
  101. bool isAliased;
  102. StackObject(uint64_t Sz, unsigned Al, int64_t SP, bool IM,
  103. bool isSS, const AllocaInst *Val, bool A)
  104. : SPOffset(SP), Size(Sz), Alignment(Al), isImmutable(IM),
  105. isSpillSlot(isSS), Alloca(Val), PreAllocated(false), isAliased(A) {}
  106. };
  107. /// The alignment of the stack.
  108. unsigned StackAlignment;
  109. /// Can the stack be realigned.
  110. bool StackRealignable;
  111. /// The list of stack objects allocated.
  112. std::vector<StackObject> Objects;
  113. /// This contains the number of fixed objects contained on
  114. /// the stack. Because fixed objects are stored at a negative index in the
  115. /// Objects list, this is also the index to the 0th object in the list.
  116. unsigned NumFixedObjects;
  117. /// This boolean keeps track of whether any variable
  118. /// sized objects have been allocated yet.
  119. bool HasVarSizedObjects;
  120. /// This boolean keeps track of whether there is a call
  121. /// to builtin \@llvm.frameaddress.
  122. bool FrameAddressTaken;
  123. /// This boolean keeps track of whether there is a call
  124. /// to builtin \@llvm.returnaddress.
  125. bool ReturnAddressTaken;
  126. /// This boolean keeps track of whether there is a call
  127. /// to builtin \@llvm.experimental.stackmap.
  128. bool HasStackMap;
  129. /// This boolean keeps track of whether there is a call
  130. /// to builtin \@llvm.experimental.patchpoint.
  131. bool HasPatchPoint;
  132. /// The prolog/epilog code inserter calculates the final stack
  133. /// offsets for all of the fixed size objects, updating the Objects list
  134. /// above. It then updates StackSize to contain the number of bytes that need
  135. /// to be allocated on entry to the function.
  136. uint64_t StackSize;
  137. /// The amount that a frame offset needs to be adjusted to
  138. /// have the actual offset from the stack/frame pointer. The exact usage of
  139. /// this is target-dependent, but it is typically used to adjust between
  140. /// SP-relative and FP-relative offsets. E.G., if objects are accessed via
  141. /// SP then OffsetAdjustment is zero; if FP is used, OffsetAdjustment is set
  142. /// to the distance between the initial SP and the value in FP. For many
  143. /// targets, this value is only used when generating debug info (via
  144. /// TargetRegisterInfo::getFrameIndexOffset); when generating code, the
  145. /// corresponding adjustments are performed directly.
  146. int OffsetAdjustment;
  147. /// The prolog/epilog code inserter may process objects that require greater
  148. /// alignment than the default alignment the target provides.
  149. /// To handle this, MaxAlignment is set to the maximum alignment
  150. /// needed by the objects on the current frame. If this is greater than the
  151. /// native alignment maintained by the compiler, dynamic alignment code will
  152. /// be needed.
  153. ///
  154. unsigned MaxAlignment;
  155. /// Set to true if this function adjusts the stack -- e.g.,
  156. /// when calling another function. This is only valid during and after
  157. /// prolog/epilog code insertion.
  158. bool AdjustsStack;
  159. /// Set to true if this function has any function calls.
  160. bool HasCalls;
  161. /// The frame index for the stack protector.
  162. int StackProtectorIdx;
  163. /// The frame index for the function context. Used for SjLj exceptions.
  164. int FunctionContextIdx;
  165. /// This contains the size of the largest call frame if the target uses frame
  166. /// setup/destroy pseudo instructions (as defined in the TargetFrameInfo
  167. /// class). This information is important for frame pointer elimination.
  168. /// If is only valid during and after prolog/epilog code insertion.
  169. unsigned MaxCallFrameSize;
  170. /// The prolog/epilog code inserter fills in this vector with each
  171. /// callee saved register saved in the frame. Beyond its use by the prolog/
  172. /// epilog code inserter, this data used for debug info and exception
  173. /// handling.
  174. std::vector<CalleeSavedInfo> CSInfo;
  175. /// Has CSInfo been set yet?
  176. bool CSIValid;
  177. /// References to frame indices which are mapped
  178. /// into the local frame allocation block. <FrameIdx, LocalOffset>
  179. SmallVector<std::pair<int, int64_t>, 32> LocalFrameObjects;
  180. /// Size of the pre-allocated local frame block.
  181. int64_t LocalFrameSize;
  182. /// Required alignment of the local object blob, which is the strictest
  183. /// alignment of any object in it.
  184. unsigned LocalFrameMaxAlign;
  185. /// Whether the local object blob needs to be allocated together. If not,
  186. /// PEI should ignore the isPreAllocated flags on the stack objects and
  187. /// just allocate them normally.
  188. bool UseLocalStackAllocationBlock;
  189. /// Whether the "realign-stack" option is on.
  190. bool RealignOption;
  191. /// True if the function dynamically adjusts the stack pointer through some
  192. /// opaque mechanism like inline assembly or Win32 EH.
  193. bool HasOpaqueSPAdjustment;
  194. /// True if the function contains a call to the llvm.vastart intrinsic.
  195. bool HasVAStart;
  196. /// True if this is a varargs function that contains a musttail call.
  197. bool HasMustTailInVarArgFunc;
  198. /// True if this function contains a tail call. If so immutable objects like
  199. /// function arguments are no longer so. A tail call *can* override fixed
  200. /// stack objects like arguments so we can't treat them as immutable.
  201. bool HasTailCall;
  202. /// Not null, if shrink-wrapping found a better place for the prologue.
  203. MachineBasicBlock *Save;
  204. /// Not null, if shrink-wrapping found a better place for the epilogue.
  205. MachineBasicBlock *Restore;
  206. public:
  207. explicit MachineFrameInfo(unsigned StackAlign, bool isStackRealign,
  208. bool RealignOpt)
  209. : StackAlignment(StackAlign), StackRealignable(isStackRealign),
  210. RealignOption(RealignOpt) {
  211. StackSize = NumFixedObjects = OffsetAdjustment = MaxAlignment = 0;
  212. HasVarSizedObjects = false;
  213. FrameAddressTaken = false;
  214. ReturnAddressTaken = false;
  215. HasStackMap = false;
  216. HasPatchPoint = false;
  217. AdjustsStack = false;
  218. HasCalls = false;
  219. StackProtectorIdx = -1;
  220. FunctionContextIdx = -1;
  221. MaxCallFrameSize = 0;
  222. CSIValid = false;
  223. LocalFrameSize = 0;
  224. LocalFrameMaxAlign = 0;
  225. UseLocalStackAllocationBlock = false;
  226. HasOpaqueSPAdjustment = false;
  227. HasVAStart = false;
  228. HasMustTailInVarArgFunc = false;
  229. Save = nullptr;
  230. Restore = nullptr;
  231. HasTailCall = false;
  232. }
  233. /// Return true if there are any stack objects in this function.
  234. bool hasStackObjects() const { return !Objects.empty(); }
  235. /// This method may be called any time after instruction
  236. /// selection is complete to determine if the stack frame for this function
  237. /// contains any variable sized objects.
  238. bool hasVarSizedObjects() const { return HasVarSizedObjects; }
  239. /// Return the index for the stack protector object.
  240. int getStackProtectorIndex() const { return StackProtectorIdx; }
  241. void setStackProtectorIndex(int I) { StackProtectorIdx = I; }
  242. /// Return the index for the function context object.
  243. /// This object is used for SjLj exceptions.
  244. int getFunctionContextIndex() const { return FunctionContextIdx; }
  245. void setFunctionContextIndex(int I) { FunctionContextIdx = I; }
  246. /// This method may be called any time after instruction
  247. /// selection is complete to determine if there is a call to
  248. /// \@llvm.frameaddress in this function.
  249. bool isFrameAddressTaken() const { return FrameAddressTaken; }
  250. void setFrameAddressIsTaken(bool T) { FrameAddressTaken = T; }
  251. /// This method may be called any time after
  252. /// instruction selection is complete to determine if there is a call to
  253. /// \@llvm.returnaddress in this function.
  254. bool isReturnAddressTaken() const { return ReturnAddressTaken; }
  255. void setReturnAddressIsTaken(bool s) { ReturnAddressTaken = s; }
  256. /// This method may be called any time after instruction
  257. /// selection is complete to determine if there is a call to builtin
  258. /// \@llvm.experimental.stackmap.
  259. bool hasStackMap() const { return HasStackMap; }
  260. void setHasStackMap(bool s = true) { HasStackMap = s; }
  261. /// This method may be called any time after instruction
  262. /// selection is complete to determine if there is a call to builtin
  263. /// \@llvm.experimental.patchpoint.
  264. bool hasPatchPoint() const { return HasPatchPoint; }
  265. void setHasPatchPoint(bool s = true) { HasPatchPoint = s; }
  266. /// Return the minimum frame object index.
  267. int getObjectIndexBegin() const { return -NumFixedObjects; }
  268. /// Return one past the maximum frame object index.
  269. int getObjectIndexEnd() const { return (int)Objects.size()-NumFixedObjects; }
  270. /// Return the number of fixed objects.
  271. unsigned getNumFixedObjects() const { return NumFixedObjects; }
  272. /// Return the number of objects.
  273. unsigned getNumObjects() const { return Objects.size(); }
  274. /// Map a frame index into the local object block
  275. void mapLocalFrameObject(int ObjectIndex, int64_t Offset) {
  276. LocalFrameObjects.push_back(std::pair<int, int64_t>(ObjectIndex, Offset));
  277. Objects[ObjectIndex + NumFixedObjects].PreAllocated = true;
  278. }
  279. /// Get the local offset mapping for a for an object.
  280. std::pair<int, int64_t> getLocalFrameObjectMap(int i) {
  281. assert (i >= 0 && (unsigned)i < LocalFrameObjects.size() &&
  282. "Invalid local object reference!");
  283. return LocalFrameObjects[i];
  284. }
  285. /// Return the number of objects allocated into the local object block.
  286. int64_t getLocalFrameObjectCount() { return LocalFrameObjects.size(); }
  287. /// Set the size of the local object blob.
  288. void setLocalFrameSize(int64_t sz) { LocalFrameSize = sz; }
  289. /// Get the size of the local object blob.
  290. int64_t getLocalFrameSize() const { return LocalFrameSize; }
  291. /// Required alignment of the local object blob,
  292. /// which is the strictest alignment of any object in it.
  293. void setLocalFrameMaxAlign(unsigned Align) { LocalFrameMaxAlign = Align; }
  294. /// Return the required alignment of the local object blob.
  295. unsigned getLocalFrameMaxAlign() const { return LocalFrameMaxAlign; }
  296. /// Get whether the local allocation blob should be allocated together or
  297. /// let PEI allocate the locals in it directly.
  298. bool getUseLocalStackAllocationBlock() {return UseLocalStackAllocationBlock;}
  299. /// setUseLocalStackAllocationBlock - Set whether the local allocation blob
  300. /// should be allocated together or let PEI allocate the locals in it
  301. /// directly.
  302. void setUseLocalStackAllocationBlock(bool v) {
  303. UseLocalStackAllocationBlock = v;
  304. }
  305. /// Return true if the object was pre-allocated into the local block.
  306. bool isObjectPreAllocated(int ObjectIdx) const {
  307. assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
  308. "Invalid Object Idx!");
  309. return Objects[ObjectIdx+NumFixedObjects].PreAllocated;
  310. }
  311. /// Return the size of the specified object.
  312. int64_t getObjectSize(int ObjectIdx) const {
  313. assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
  314. "Invalid Object Idx!");
  315. return Objects[ObjectIdx+NumFixedObjects].Size;
  316. }
  317. /// Change the size of the specified stack object.
  318. void setObjectSize(int ObjectIdx, int64_t Size) {
  319. assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
  320. "Invalid Object Idx!");
  321. Objects[ObjectIdx+NumFixedObjects].Size = Size;
  322. }
  323. /// Return the alignment of the specified stack object.
  324. unsigned getObjectAlignment(int ObjectIdx) const {
  325. assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
  326. "Invalid Object Idx!");
  327. return Objects[ObjectIdx+NumFixedObjects].Alignment;
  328. }
  329. /// setObjectAlignment - Change the alignment of the specified stack object.
  330. void setObjectAlignment(int ObjectIdx, unsigned Align) {
  331. assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
  332. "Invalid Object Idx!");
  333. Objects[ObjectIdx+NumFixedObjects].Alignment = Align;
  334. ensureMaxAlignment(Align);
  335. }
  336. /// Return the underlying Alloca of the specified
  337. /// stack object if it exists. Returns 0 if none exists.
  338. const AllocaInst* getObjectAllocation(int ObjectIdx) const {
  339. assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
  340. "Invalid Object Idx!");
  341. return Objects[ObjectIdx+NumFixedObjects].Alloca;
  342. }
  343. /// Return the assigned stack offset of the specified object
  344. /// from the incoming stack pointer.
  345. int64_t getObjectOffset(int ObjectIdx) const {
  346. assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
  347. "Invalid Object Idx!");
  348. assert(!isDeadObjectIndex(ObjectIdx) &&
  349. "Getting frame offset for a dead object?");
  350. return Objects[ObjectIdx+NumFixedObjects].SPOffset;
  351. }
  352. /// Set the stack frame offset of the specified object. The
  353. /// offset is relative to the stack pointer on entry to the function.
  354. void setObjectOffset(int ObjectIdx, int64_t SPOffset) {
  355. assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
  356. "Invalid Object Idx!");
  357. assert(!isDeadObjectIndex(ObjectIdx) &&
  358. "Setting frame offset for a dead object?");
  359. Objects[ObjectIdx+NumFixedObjects].SPOffset = SPOffset;
  360. }
  361. /// Return the number of bytes that must be allocated to hold
  362. /// all of the fixed size frame objects. This is only valid after
  363. /// Prolog/Epilog code insertion has finalized the stack frame layout.
  364. uint64_t getStackSize() const { return StackSize; }
  365. /// Set the size of the stack.
  366. void setStackSize(uint64_t Size) { StackSize = Size; }
  367. /// Estimate and return the size of the stack frame.
  368. unsigned estimateStackSize(const MachineFunction &MF) const;
  369. /// Return the correction for frame offsets.
  370. int getOffsetAdjustment() const { return OffsetAdjustment; }
  371. /// Set the correction for frame offsets.
  372. void setOffsetAdjustment(int Adj) { OffsetAdjustment = Adj; }
  373. /// Return the alignment in bytes that this function must be aligned to,
  374. /// which is greater than the default stack alignment provided by the target.
  375. unsigned getMaxAlignment() const { return MaxAlignment; }
  376. /// Make sure the function is at least Align bytes aligned.
  377. void ensureMaxAlignment(unsigned Align);
  378. /// Return true if this function adjusts the stack -- e.g.,
  379. /// when calling another function. This is only valid during and after
  380. /// prolog/epilog code insertion.
  381. bool adjustsStack() const { return AdjustsStack; }
  382. void setAdjustsStack(bool V) { AdjustsStack = V; }
  383. /// Return true if the current function has any function calls.
  384. bool hasCalls() const { return HasCalls; }
  385. void setHasCalls(bool V) { HasCalls = V; }
  386. /// Returns true if the function contains opaque dynamic stack adjustments.
  387. bool hasOpaqueSPAdjustment() const { return HasOpaqueSPAdjustment; }
  388. void setHasOpaqueSPAdjustment(bool B) { HasOpaqueSPAdjustment = B; }
  389. /// Returns true if the function calls the llvm.va_start intrinsic.
  390. bool hasVAStart() const { return HasVAStart; }
  391. void setHasVAStart(bool B) { HasVAStart = B; }
  392. /// Returns true if the function is variadic and contains a musttail call.
  393. bool hasMustTailInVarArgFunc() const { return HasMustTailInVarArgFunc; }
  394. void setHasMustTailInVarArgFunc(bool B) { HasMustTailInVarArgFunc = B; }
  395. /// Returns true if the function contains a tail call.
  396. bool hasTailCall() const { return HasTailCall; }
  397. void setHasTailCall() { HasTailCall = true; }
  398. /// Return the maximum size of a call frame that must be
  399. /// allocated for an outgoing function call. This is only available if
  400. /// CallFrameSetup/Destroy pseudo instructions are used by the target, and
  401. /// then only during or after prolog/epilog code insertion.
  402. ///
  403. unsigned getMaxCallFrameSize() const { return MaxCallFrameSize; }
  404. void setMaxCallFrameSize(unsigned S) { MaxCallFrameSize = S; }
  405. /// Create a new object at a fixed location on the stack.
  406. /// All fixed objects should be created before other objects are created for
  407. /// efficiency. By default, fixed objects are not pointed to by LLVM IR
  408. /// values. This returns an index with a negative value.
  409. int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool Immutable,
  410. bool isAliased = false);
  411. /// Create a spill slot at a fixed location on the stack.
  412. /// Returns an index with a negative value.
  413. int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset);
  414. /// Returns true if the specified index corresponds to a fixed stack object.
  415. bool isFixedObjectIndex(int ObjectIdx) const {
  416. return ObjectIdx < 0 && (ObjectIdx >= -(int)NumFixedObjects);
  417. }
  418. /// Returns true if the specified index corresponds
  419. /// to an object that might be pointed to by an LLVM IR value.
  420. bool isAliasedObjectIndex(int ObjectIdx) const {
  421. assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
  422. "Invalid Object Idx!");
  423. return Objects[ObjectIdx+NumFixedObjects].isAliased;
  424. }
  425. /// isImmutableObjectIndex - Returns true if the specified index corresponds
  426. /// to an immutable object.
  427. bool isImmutableObjectIndex(int ObjectIdx) const {
  428. // Tail calling functions can clobber their function arguments.
  429. if (HasTailCall)
  430. return false;
  431. assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
  432. "Invalid Object Idx!");
  433. return Objects[ObjectIdx+NumFixedObjects].isImmutable;
  434. }
  435. /// Returns true if the specified index corresponds to a spill slot.
  436. bool isSpillSlotObjectIndex(int ObjectIdx) const {
  437. assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
  438. "Invalid Object Idx!");
  439. return Objects[ObjectIdx+NumFixedObjects].isSpillSlot;
  440. }
  441. /// Returns true if the specified index corresponds to a dead object.
  442. bool isDeadObjectIndex(int ObjectIdx) const {
  443. assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
  444. "Invalid Object Idx!");
  445. return Objects[ObjectIdx+NumFixedObjects].Size == ~0ULL;
  446. }
  447. /// Returns true if the specified index corresponds to a variable sized
  448. /// object.
  449. bool isVariableSizedObjectIndex(int ObjectIdx) const {
  450. assert(unsigned(ObjectIdx + NumFixedObjects) < Objects.size() &&
  451. "Invalid Object Idx!");
  452. return Objects[ObjectIdx + NumFixedObjects].Size == 0;
  453. }
  454. /// Create a new statically sized stack object, returning
  455. /// a nonnegative identifier to represent it.
  456. int CreateStackObject(uint64_t Size, unsigned Alignment, bool isSS,
  457. const AllocaInst *Alloca = nullptr);
  458. /// Create a new statically sized stack object that represents a spill slot,
  459. /// returning a nonnegative identifier to represent it.
  460. int CreateSpillStackObject(uint64_t Size, unsigned Alignment);
  461. /// Remove or mark dead a statically sized stack object.
  462. void RemoveStackObject(int ObjectIdx) {
  463. // Mark it dead.
  464. Objects[ObjectIdx+NumFixedObjects].Size = ~0ULL;
  465. }
  466. /// Notify the MachineFrameInfo object that a variable sized object has been
  467. /// created. This must be created whenever a variable sized object is
  468. /// created, whether or not the index returned is actually used.
  469. int CreateVariableSizedObject(unsigned Alignment, const AllocaInst *Alloca);
  470. /// Returns a reference to call saved info vector for the current function.
  471. const std::vector<CalleeSavedInfo> &getCalleeSavedInfo() const {
  472. return CSInfo;
  473. }
  474. /// Used by prolog/epilog inserter to set the function's callee saved
  475. /// information.
  476. void setCalleeSavedInfo(const std::vector<CalleeSavedInfo> &CSI) {
  477. CSInfo = CSI;
  478. }
  479. /// Has the callee saved info been calculated yet?
  480. bool isCalleeSavedInfoValid() const { return CSIValid; }
  481. void setCalleeSavedInfoValid(bool v) { CSIValid = v; }
  482. MachineBasicBlock *getSavePoint() const { return Save; }
  483. void setSavePoint(MachineBasicBlock *NewSave) { Save = NewSave; }
  484. MachineBasicBlock *getRestorePoint() const { return Restore; }
  485. void setRestorePoint(MachineBasicBlock *NewRestore) { Restore = NewRestore; }
  486. /// Return a set of physical registers that are pristine.
  487. ///
  488. /// Pristine registers hold a value that is useless to the current function,
  489. /// but that must be preserved - they are callee saved registers that are not
  490. /// saved.
  491. ///
  492. /// Before the PrologueEpilogueInserter has placed the CSR spill code, this
  493. /// method always returns an empty set.
  494. BitVector getPristineRegs(const MachineFunction &MF) const;
  495. /// Used by the MachineFunction printer to print information about
  496. /// stack objects. Implemented in MachineFunction.cpp.
  497. void print(const MachineFunction &MF, raw_ostream &OS) const;
  498. /// dump - Print the function to stderr.
  499. void dump(const MachineFunction &MF) const;
  500. };
  501. } // End llvm namespace
  502. #endif