| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#ifndef LLVM_CODEGEN_LIVEINTERVALUNION_H |
| 17 |
#define LLVM_CODEGEN_LIVEINTERVALUNION_H |
| 18 |
|
| 19 |
#include "llvm/ADT/IntervalMap.h" |
| 20 |
#include "llvm/ADT/SmallVector.h" |
| 21 |
#include "llvm/CodeGen/LiveInterval.h" |
| 22 |
#include "llvm/CodeGen/SlotIndexes.h" |
| 23 |
#include <cassert> |
| 24 |
#include <limits> |
| 25 |
|
| 26 |
namespace llvm { |
| 27 |
|
| 28 |
class raw_ostream; |
| 29 |
class TargetRegisterInfo; |
| 30 |
|
| 31 |
#ifndef NDEBUG |
| 32 |
|
| 33 |
template <unsigned Element> class SparseBitVector; |
| 34 |
|
| 35 |
using LiveVirtRegBitSet = SparseBitVector<128>; |
| 36 |
#endif |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
class LiveIntervalUnion { |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
using LiveSegments = IntervalMap<SlotIndex, LiveInterval*>; |
| 47 |
|
| 48 |
public: |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
using SegmentIter = LiveSegments::iterator; |
| 53 |
|
| 54 |
|
| 55 |
using ConstSegmentIter = LiveSegments::const_iterator; |
| 56 |
|
| 57 |
|
| 58 |
using Allocator = LiveSegments::Allocator; |
| 59 |
|
| 60 |
private: |
| 61 |
unsigned Tag = 0; |
| 62 |
LiveSegments Segments; |
| 63 |
|
| 64 |
public: |
| 65 |
explicit LiveIntervalUnion(Allocator &a) : Segments(a) {} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
SegmentIter begin() { return Segments.begin(); } |
| 70 |
SegmentIter end() { return Segments.end(); } |
| 71 |
SegmentIter find(SlotIndex x) { return Segments.find(x); } |
| 72 |
ConstSegmentIter begin() const { return Segments.begin(); } |
| 73 |
ConstSegmentIter end() const { return Segments.end(); } |
| 74 |
ConstSegmentIter find(SlotIndex x) const { return Segments.find(x); } |
| 75 |
|
| 76 |
bool empty() const { return Segments.empty(); } |
| 77 |
SlotIndex startIndex() const { return Segments.start(); } |
| 78 |
SlotIndex endIndex() const { return Segments.stop(); } |
| 79 |
|
| 80 |
|
| 81 |
using Map = LiveSegments; |
| 82 |
const Map &getMap() const { return Segments; } |
| 83 |
|
| 84 |
|
| 85 |
unsigned getTag() const { return Tag; } |
| 86 |
|
| 87 |
|
| 88 |
bool changedSince(unsigned tag) const { return tag != Tag; } |
| 89 |
|
| 90 |
|
| 91 |
void unify(LiveInterval &VirtReg, const LiveRange &Range); |
| 92 |
|
| 93 |
|
| 94 |
void extract(LiveInterval &VirtReg, const LiveRange &Range); |
| 95 |
|
| 96 |
|
| 97 |
void clear() { Segments.clear(); ++Tag; } |
| 98 |
|
| 99 |
|
| 100 |
void print(raw_ostream &OS, const TargetRegisterInfo *TRI) const; |
| 101 |
|
| 102 |
#ifndef NDEBUG |
| 103 |
|
| 104 |
void verify(LiveVirtRegBitSet& VisitedVRegs); |
| 105 |
#endif |
| 106 |
|
| 107 |
|
| 108 |
LiveInterval *getOneVReg() const; |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
class Query { |
| 113 |
const LiveIntervalUnion *LiveUnion = nullptr; |
| 114 |
const LiveRange *LR = nullptr; |
| 115 |
LiveRange::const_iterator LRI; |
| 116 |
ConstSegmentIter LiveUnionI; |
| 117 |
SmallVector<LiveInterval *, 4> InterferingVRegs; |
| 118 |
bool CheckedFirstInterference = false; |
| 119 |
bool SeenAllInterferences = false; |
| 120 |
unsigned Tag = 0; |
| 121 |
unsigned UserTag = 0; |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
unsigned collectInterferingVRegs(unsigned MaxInterferingRegs); |
| 126 |
|
| 127 |
|
| 128 |
bool isSeenInterference(LiveInterval *VirtReg) const; |
| 129 |
|
| 130 |
public: |
| 131 |
Query() = default; |
| 132 |
Query(const LiveRange &LR, const LiveIntervalUnion &LIU) |
| 133 |
: LiveUnion(&LIU), LR(&LR) {} |
| 134 |
Query(const Query &) = delete; |
| 135 |
Query &operator=(const Query &) = delete; |
| 136 |
|
| 137 |
void reset(unsigned NewUserTag, const LiveRange &NewLR, |
| 138 |
const LiveIntervalUnion &NewLiveUnion) { |
| 139 |
LiveUnion = &NewLiveUnion; |
| 140 |
LR = &NewLR; |
| 141 |
InterferingVRegs.clear(); |
| 142 |
CheckedFirstInterference = false; |
| 143 |
SeenAllInterferences = false; |
| 144 |
Tag = NewLiveUnion.getTag(); |
| 145 |
UserTag = NewUserTag; |
| 146 |
} |
| 147 |
|
| 148 |
void init(unsigned NewUserTag, const LiveRange &NewLR, |
| 149 |
const LiveIntervalUnion &NewLiveUnion) { |
| 150 |
if (UserTag == NewUserTag && LR == &NewLR && LiveUnion == &NewLiveUnion && |
| 151 |
!NewLiveUnion.changedSince(Tag)) { |
| 152 |
|
| 153 |
return; |
| 154 |
} |
| 155 |
reset(NewUserTag, NewLR, NewLiveUnion); |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
bool checkInterference() { return collectInterferingVRegs(1); } |
| 160 |
|
| 161 |
|
| 162 |
const SmallVectorImpl<LiveInterval *> &interferingVRegs( |
| 163 |
unsigned MaxInterferingRegs = std::numeric_limits<unsigned>::max()) { |
| 164 |
if (!SeenAllInterferences || MaxInterferingRegs < InterferingVRegs.size()) |
| 165 |
collectInterferingVRegs(MaxInterferingRegs); |
| 166 |
return InterferingVRegs; |
| 167 |
} |
| 168 |
}; |
| 169 |
|
| 170 |
|
| 171 |
class Array { |
| 172 |
unsigned Size = 0; |
| 173 |
LiveIntervalUnion *LIUs = nullptr; |
| 174 |
|
| 175 |
public: |
| 176 |
Array() = default; |
| 177 |
~Array() { clear(); } |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
void init(LiveIntervalUnion::Allocator&, unsigned Size); |
| 182 |
|
| 183 |
unsigned size() const { return Size; } |
| 184 |
|
| 185 |
void clear(); |
| 186 |
|
| 187 |
LiveIntervalUnion& operator[](unsigned idx) { |
| 188 |
assert(idx < Size && "idx out of bounds"); |
| 189 |
return LIUs[idx]; |
| 190 |
} |
| 191 |
|
| 192 |
const LiveIntervalUnion& operator[](unsigned Idx) const { |
| 193 |
assert(Idx < Size && "Idx out of bounds"); |
| 194 |
return LIUs[Idx]; |
| 195 |
} |
| 196 |
}; |
| 197 |
}; |
| 198 |
|
| 199 |
} |
| 200 |
|
| 201 |
#endif |