StatepointLowering.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //===-- StatepointLowering.h - SDAGBuilder's statepoint code -*- 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 file includes support code use by SelectionDAGBuilder when lowering a
  11. // statepoint sequence in SelectionDAG IR.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_LIB_CODEGEN_SELECTIONDAG_STATEPOINTLOWERING_H
  15. #define LLVM_LIB_CODEGEN_SELECTIONDAG_STATEPOINTLOWERING_H
  16. #include "llvm/ADT/DenseMap.h"
  17. #include "llvm/CodeGen/SelectionDAG.h"
  18. #include "llvm/CodeGen/SelectionDAGNodes.h"
  19. #include <vector>
  20. namespace llvm {
  21. class SelectionDAGBuilder;
  22. /// This class tracks both per-statepoint and per-selectiondag information.
  23. /// For each statepoint it tracks locations of it's gc valuess (incoming and
  24. /// relocated) and list of gcreloc calls scheduled for visiting (this is
  25. /// used for a debug mode consistency check only). The spill slot tracking
  26. /// works in concert with information in FunctionLoweringInfo.
  27. class StatepointLoweringState {
  28. public:
  29. StatepointLoweringState() : NextSlotToAllocate(0) {}
  30. /// Reset all state tracking for a newly encountered safepoint. Also
  31. /// performs some consistency checking.
  32. void startNewStatepoint(SelectionDAGBuilder &Builder);
  33. /// Clear the memory usage of this object. This is called from
  34. /// SelectionDAGBuilder::clear. We require this is never called in the
  35. /// midst of processing a statepoint sequence.
  36. void clear();
  37. /// Returns the spill location of a value incoming to the current
  38. /// statepoint. Will return SDValue() if this value hasn't been
  39. /// spilled. Otherwise, the value has already been spilled and no
  40. /// further action is required by the caller.
  41. SDValue getLocation(SDValue val) {
  42. if (!Locations.count(val))
  43. return SDValue();
  44. return Locations[val];
  45. }
  46. void setLocation(SDValue val, SDValue Location) {
  47. assert(!Locations.count(val) &&
  48. "Trying to allocate already allocated location");
  49. Locations[val] = Location;
  50. }
  51. /// Record the fact that we expect to encounter a given gc_relocate
  52. /// before the next statepoint. If we don't see it, we'll report
  53. /// an assertion.
  54. void scheduleRelocCall(const CallInst &RelocCall) {
  55. PendingGCRelocateCalls.push_back(&RelocCall);
  56. }
  57. /// Remove this gc_relocate from the list we're expecting to see
  58. /// before the next statepoint. If we weren't expecting to see
  59. /// it, we'll report an assertion.
  60. void relocCallVisited(const CallInst &RelocCall) {
  61. SmallVectorImpl<const CallInst *>::iterator itr =
  62. std::find(PendingGCRelocateCalls.begin(), PendingGCRelocateCalls.end(),
  63. &RelocCall);
  64. assert(itr != PendingGCRelocateCalls.end() &&
  65. "Visited unexpected gcrelocate call");
  66. PendingGCRelocateCalls.erase(itr);
  67. }
  68. // TODO: Should add consistency tracking to ensure we encounter
  69. // expected gc_result calls too.
  70. /// Get a stack slot we can use to store an value of type ValueType. This
  71. /// will hopefully be a recylced slot from another statepoint.
  72. SDValue allocateStackSlot(EVT ValueType, SelectionDAGBuilder &Builder);
  73. void reserveStackSlot(int Offset) {
  74. assert(Offset >= 0 && Offset < (int)AllocatedStackSlots.size() &&
  75. "out of bounds");
  76. assert(!AllocatedStackSlots[Offset] && "already reserved!");
  77. assert(NextSlotToAllocate <= (unsigned)Offset && "consistency!");
  78. AllocatedStackSlots[Offset] = true;
  79. }
  80. bool isStackSlotAllocated(int Offset) {
  81. assert(Offset >= 0 && Offset < (int)AllocatedStackSlots.size() &&
  82. "out of bounds");
  83. return AllocatedStackSlots[Offset];
  84. }
  85. private:
  86. /// Maps pre-relocation value (gc pointer directly incoming into statepoint)
  87. /// into it's location (currently only stack slots)
  88. DenseMap<SDValue, SDValue> Locations;
  89. /// A boolean indicator for each slot listed in the FunctionInfo as to
  90. /// whether it has been used in the current statepoint. Since we try to
  91. /// preserve stack slots across safepoints, there can be gaps in which
  92. /// slots have been allocated.
  93. SmallVector<bool, 50> AllocatedStackSlots;
  94. /// Points just beyond the last slot known to have been allocated
  95. unsigned NextSlotToAllocate;
  96. /// Keep track of pending gcrelocate calls for consistency check
  97. SmallVector<const CallInst *, 10> PendingGCRelocateCalls;
  98. };
  99. } // end namespace llvm
  100. #endif // LLVM_LIB_CODEGEN_SELECTIONDAG_STATEPOINTLOWERING_H