27#define DEBUG_TYPE "regalloc"
30const InterferenceCache::BlockInterference
31 InterferenceCache::Cursor::NoInterference;
42 if (PhysRegEntriesCount == TRI->getNumRegs())
return;
44 PhysRegEntriesCount = TRI->getNumRegs();
45 PhysRegEntries =
static_cast<unsigned char*
>(
46 safe_calloc(PhysRegEntriesCount,
sizeof(
unsigned char)));
58 for (Entry &E : Entries)
59 E.clear(mf, indexes, lis);
62InterferenceCache::Entry *InterferenceCache::get(
MCRegister PhysReg) {
63 unsigned char E = PhysRegEntries[PhysReg.
id()];
64 if (E <
CacheEntries && Entries[E].getPhysReg() == PhysReg) {
65 if (!Entries[E].valid(LIUArray,
TRI))
66 Entries[E].revalidate(LIUArray,
TRI);
75 if (Entries[
E].hasRefs()) {
80 Entries[
E].reset(PhysReg, LIUArray, TRI, MF);
81 PhysRegEntries[PhysReg.
id()] =
E;
93 PrevPos = SlotIndex();
96 RegUnits[i++].VirtTag = LIUArray[
Unit].
getTag();
99void InterferenceCache::Entry::reset(MCRegister physReg,
100 LiveIntervalUnion *LIUArray,
101 const TargetRegisterInfo *TRI,
102 const MachineFunction *MF) {
103 assert(!hasRefs() &&
"Cannot reset cache entry with references");
107 Blocks.resize(MF->getNumBlockIDs());
110 PrevPos = SlotIndex();
112 for (
MCRegUnit Unit : TRI->regunits(PhysReg)) {
113 RegUnits.push_back(LIUArray[Unit]);
114 RegUnits.back().Fixed = &LIS->getRegUnit(Unit);
118bool InterferenceCache::Entry::valid(LiveIntervalUnion *LIUArray,
119 const TargetRegisterInfo *TRI) {
120 unsigned i = 0,
e = RegUnits.size();
121 for (
MCRegUnit Unit : TRI->regunits(PhysReg)) {
124 if (LIUArray[Unit].changedSince(RegUnits[i].VirtTag))
131void InterferenceCache::Entry::update(
unsigned MBBNum) {
132 SlotIndex
Start, Stop;
133 std::tie(Start, Stop) = Indexes->getMBBRange(MBBNum);
136 if (PrevPos != Start) {
137 if (!PrevPos.isValid() || Start < PrevPos) {
138 for (RegUnitInfo &RUI : RegUnits) {
139 RUI.VirtI.find(Start);
140 RUI.FixedI = RUI.Fixed->find(Start);
143 for (RegUnitInfo &RUI : RegUnits) {
144 RUI.VirtI.advanceTo(Start);
145 if (RUI.FixedI != RUI.Fixed->end())
146 RUI.FixedI = RUI.Fixed->advanceTo(RUI.FixedI, Start);
153 MF->getBlockNumbered(MBBNum)->getIterator();
154 BlockInterference *BI = &Blocks[MBBNum];
159 BI->First = BI->Last = SlotIndex();
162 for (RegUnitInfo &RUI : RegUnits) {
166 SlotIndex StartI =
I.start();
169 if (!BI->First.isValid() || StartI < BI->
First)
174 for (RegUnitInfo &RUI : RegUnits) {
179 SlotIndex StartI =
I->start;
182 if (!BI->First.isValid() || StartI < BI->
First)
187 RegMaskSlots = LIS->getRegMaskSlotsInBlock(MBBNum);
188 RegMaskBits = LIS->getRegMaskBitsInBlock(MBBNum);
189 SlotIndex Limit = BI->First.isValid() ? BI->First : Stop;
190 for (
unsigned i = 0, e = RegMaskSlots.
size();
191 i != e && RegMaskSlots[i] < Limit; ++i)
194 BI->First = RegMaskSlots[i];
199 if (BI->First.isValid())
203 if (++MFI == MF->end())
205 MBBNum = MFI->getNumber();
206 BI = &Blocks[MBBNum];
209 std::tie(Start, Stop) = Indexes->getMBBRange(MBBNum);
213 for (RegUnitInfo &RUI : RegUnits) {
215 if (!
I.valid() ||
I.start() >= Stop)
218 bool Backup = !
I.valid() ||
I.start() >= Stop;
221 SlotIndex StopI =
I.stop();
222 if (!BI->Last.isValid() || StopI > BI->Last)
229 for (RegUnitInfo &RUI : RegUnits) {
232 if (
I == LR->
end() ||
I->start >= Stop)
235 bool Backup =
I == LR->
end() ||
I->start >= Stop;
238 SlotIndex StopI =
I->end;
239 if (!BI->Last.isValid() || StopI > BI->Last)
246 SlotIndex Limit = BI->Last.
isValid() ? BI->Last :
Start;
247 for (
unsigned i = RegMaskSlots.
size();
248 i && RegMaskSlots[i-1].getDeadSlot() > Limit; --i)
252 BI->Last = RegMaskSlots[i-1].getDeadSlot();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static cl::opt< unsigned > CacheEntries("cdsort-cache-entries", cl::ReallyHidden, cl::desc("The size of the cache"))
Register const TargetRegisterInfo * TRI
SI Optimize VGPR LiveRange
size_t size() const
size - Get the array size.
void init(MachineFunction *mf, LiveIntervalUnion *liuarray, SlotIndexes *indexes, LiveIntervals *lis, const TargetRegisterInfo *tri)
init - Prepare cache for a new function.
void reinitPhysRegEntries()
Union of live intervals that are strong candidates for coalescing into a single register (either phys...
LiveSegments::iterator SegmentIter
unsigned getTag() const
getTag - Return an opaque tag representing the current state of the union.
Segments::iterator iterator
Segments::const_iterator const_iterator
iterator advanceTo(iterator I, SlotIndex Pos)
advanceTo - Advance the specified iterator to point to the Segment containing the specified position,...
Wrapper class representing physical registers. Should be passed by value.
constexpr unsigned id() const
BasicBlockListType::const_iterator const_iterator
static bool clobbersPhysReg(const uint32_t *RegMask, MCRegister PhysReg)
clobbersPhysReg - Returns true if this RegMask clobbers PhysReg.
bool isValid() const
Returns true if this is a valid index.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ATTRIBUTE_RETURNS_NONNULL void * safe_calloc(size_t Count, size_t Sz)
unsigned MCRegUnit
Register units are used to compute register aliasing.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
ArrayRef(const T &OneElt) -> ArrayRef< T >