27#define DEBUG_TYPE "regalloc"
30const InterferenceCache::BlockInterference
31 InterferenceCache::Cursor::NoInterference;
42 if (PhysRegEntriesCount == TRI->
getNumRegs())
return;
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);
71 if (++RoundRobin == CacheEntries)
73 for (
unsigned i = 0; i != CacheEntries; ++i) {
75 if (Entries[E].hasRefs()) {
76 if (++E == CacheEntries)
80 Entries[E].reset(PhysReg, LIUArray, TRI, MF);
81 PhysRegEntries[PhysReg] = E;
96 RegUnits[i++].VirtTag = LIUArray[Unit].
getTag();
99void InterferenceCache::Entry::reset(
MCRegister physReg,
103 assert(!hasRefs() &&
"Cannot reset cache entry with references");
113 RegUnits.push_back(LIUArray[Unit]);
114 RegUnits.back().Fixed = &LIS->getRegUnit(Unit);
120 unsigned i = 0,
e = RegUnits.size();
124 if (LIUArray[Unit].changedSince(RegUnits[i].VirtTag))
131void InterferenceCache::Entry::update(
unsigned MBBNum) {
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);
154 BlockInterference *BI = &
Blocks[MBBNum];
162 for (RegUnitInfo &RUI : RegUnits) {
169 if (!BI->First.isValid() || StartI < BI->
First)
174 for (RegUnitInfo &RUI : RegUnits) {
182 if (!BI->First.isValid() || StartI < BI->
First)
187 RegMaskSlots = LIS->getRegMaskSlotsInBlock(MBBNum);
188 RegMaskBits = LIS->getRegMaskBitsInBlock(MBBNum);
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();
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;
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;
239 if (!BI->Last.isValid() || StopI > BI->Last)
247 for (
unsigned i = RegMaskSlots.
size();
248 i && RegMaskSlots[i-1].getDeadSlot() > Limit; --i)
252 BI->Last = RegMaskSlots[i-1].getDeadSlot();
DenseMap< Block *, BlockRelaxAux > Blocks
unsigned const TargetRegisterInfo * TRI
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
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.
This class represents the liveness of a register, stack slot, etc.
iterator advanceTo(iterator I, SlotIndex Pos)
advanceTo - Advance the specified iterator to point to the Segment containing the specified position,...
unsigned getNumRegs() const
Return the number of registers this target has (useful for sizing arrays holding per register informa...
Wrapper class representing physical registers. Should be passed by value.
constexpr unsigned id() const
MachineBasicBlock * getBlockNumbered(unsigned N) const
getBlockNumbered - MachineBasicBlocks are automatically numbered when they are inserted into the mach...
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
BasicBlockListType::const_iterator const_iterator
static bool clobbersPhysReg(const uint32_t *RegMask, MCRegister PhysReg)
clobbersPhysReg - Returns true if this RegMask clobbers PhysReg.
SlotIndex - An opaque wrapper around machine indexes.
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...
self_iterator getIterator()
#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)
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.