LLVM  4.0.0
StatepointLowering.h
Go to the documentation of this file.
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 
15 #ifndef LLVM_LIB_CODEGEN_SELECTIONDAG_STATEPOINTLOWERING_H
16 #define LLVM_LIB_CODEGEN_SELECTIONDAG_STATEPOINTLOWERING_H
17 
18 #include "llvm/ADT/DenseMap.h"
22 
23 namespace llvm {
24 class SelectionDAGBuilder;
25 
26 /// This class tracks both per-statepoint and per-selectiondag information.
27 /// For each statepoint it tracks locations of it's gc valuess (incoming and
28 /// relocated) and list of gcreloc calls scheduled for visiting (this is
29 /// used for a debug mode consistency check only). The spill slot tracking
30 /// works in concert with information in FunctionLoweringInfo.
32 public:
33  StatepointLoweringState() : NextSlotToAllocate(0) {}
34 
35  /// Reset all state tracking for a newly encountered safepoint. Also
36  /// performs some consistency checking.
38 
39  /// Clear the memory usage of this object. This is called from
40  /// SelectionDAGBuilder::clear. We require this is never called in the
41  /// midst of processing a statepoint sequence.
42  void clear();
43 
44  /// Returns the spill location of a value incoming to the current
45  /// statepoint. Will return SDValue() if this value hasn't been
46  /// spilled. Otherwise, the value has already been spilled and no
47  /// further action is required by the caller.
49  auto I = Locations.find(Val);
50  if (I == Locations.end())
51  return SDValue();
52  return I->second;
53  }
54 
55  void setLocation(SDValue Val, SDValue Location) {
56  assert(!Locations.count(Val) &&
57  "Trying to allocate already allocated location");
58  Locations[Val] = Location;
59  }
60 
61  /// Record the fact that we expect to encounter a given gc_relocate
62  /// before the next statepoint. If we don't see it, we'll report
63  /// an assertion.
64  void scheduleRelocCall(const CallInst &RelocCall) {
65  PendingGCRelocateCalls.push_back(&RelocCall);
66  }
67 
68  /// Remove this gc_relocate from the list we're expecting to see
69  /// before the next statepoint. If we weren't expecting to see
70  /// it, we'll report an assertion.
71  void relocCallVisited(const CallInst &RelocCall) {
72  auto I = find(PendingGCRelocateCalls, &RelocCall);
73  assert(I != PendingGCRelocateCalls.end() &&
74  "Visited unexpected gcrelocate call");
75  PendingGCRelocateCalls.erase(I);
76  }
77 
78  // TODO: Should add consistency tracking to ensure we encounter
79  // expected gc_result calls too.
80 
81  /// Get a stack slot we can use to store an value of type ValueType. This
82  /// will hopefully be a recylced slot from another statepoint.
84 
86  assert(Offset >= 0 && Offset < (int)AllocatedStackSlots.size() &&
87  "out of bounds");
88  assert(!AllocatedStackSlots.test(Offset) && "already reserved!");
89  assert(NextSlotToAllocate <= (unsigned)Offset && "consistency!");
90  AllocatedStackSlots.set(Offset);
91  }
92 
94  assert(Offset >= 0 && Offset < (int)AllocatedStackSlots.size() &&
95  "out of bounds");
96  return AllocatedStackSlots.test(Offset);
97  }
98 
99 private:
100  /// Maps pre-relocation value (gc pointer directly incoming into statepoint)
101  /// into it's location (currently only stack slots)
102  DenseMap<SDValue, SDValue> Locations;
103 
104  /// A boolean indicator for each slot listed in the FunctionInfo as to
105  /// whether it has been used in the current statepoint. Since we try to
106  /// preserve stack slots across safepoints, there can be gaps in which
107  /// slots have been allocated.
108  SmallBitVector AllocatedStackSlots;
109 
110  /// Points just beyond the last slot known to have been allocated
111  unsigned NextSlotToAllocate;
112 
113  /// Keep track of pending gcrelocate calls for consistency check
114  SmallVector<const CallInst *, 10> PendingGCRelocateCalls;
115 };
116 } // end namespace llvm
117 
118 #endif // LLVM_LIB_CODEGEN_SELECTIONDAG_STATEPOINTLOWERING_H
This is a 'bitvector' (really, a variable-sized bit array), optimized for the case when the array is ...
SelectionDAGBuilder - This is the common target-independent lowering implementation that is parameter...
This class represents a function call, abstracting a target machine's calling convention.
SDValue getLocation(SDValue Val)
Returns the spill location of a value incoming to the current statepoint.
SDValue allocateStackSlot(EVT ValueType, SelectionDAGBuilder &Builder)
Get a stack slot we can use to store an value of type ValueType.
uint32_t Offset
void clear()
Clear the memory usage of this object.
This class tracks both per-statepoint and per-selectiondag information.
EVT - Extended Value Type.
Definition: ValueTypes.h:31
void setLocation(SDValue Val, SDValue Location)
SmallBitVector & set()
auto find(R &&Range, const T &Val) -> decltype(std::begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:757
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:843
size_t size() const
Returns the number of bits in this bitvector.
bool test(unsigned Idx) const
#define I(x, y, z)
Definition: MD5.cpp:54
void startNewStatepoint(SelectionDAGBuilder &Builder)
Reset all state tracking for a newly encountered safepoint.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void scheduleRelocCall(const CallInst &RelocCall)
Record the fact that we expect to encounter a given gc_relocate before the next statepoint.
void relocCallVisited(const CallInst &RelocCall)
Remove this gc_relocate from the list we're expecting to see before the next statepoint.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...