Skip to content

Commit 536b043

Browse files
authored
[RegAllocFast] Lazily initialize InstrPosIndexes for each MBB (#76275)
Most basic block do not need to query dominates. Defer initialization of InstrPosIndexes to first query for each MBB.
1 parent fd331ef commit 536b043

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

llvm/lib/CodeGen/RegAllocFast.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ namespace {
6666
/// can be used to determine dominance between instructions in same MBB.
6767
class InstrPosIndexes {
6868
public:
69+
void unsetInitialized() { IsInitialized = false; }
70+
6971
void init(const MachineBasicBlock &MBB) {
7072
CurMBB = &MBB;
7173
Instr2PosIndex.clear();
@@ -80,6 +82,13 @@ class InstrPosIndexes {
8082
/// index without affecting existing instruction's index. Return true if all
8183
/// instructions index has been reassigned.
8284
bool getIndex(const MachineInstr &MI, uint64_t &Index) {
85+
if (!IsInitialized) {
86+
init(*MI.getParent());
87+
IsInitialized = true;
88+
Index = Instr2PosIndex.at(&MI);
89+
return true;
90+
}
91+
8392
assert(MI.getParent() == CurMBB && "MI is not in CurMBB");
8493
auto It = Instr2PosIndex.find(&MI);
8594
if (It != Instr2PosIndex.end()) {
@@ -159,6 +168,7 @@ class InstrPosIndexes {
159168
}
160169

161170
private:
171+
bool IsInitialized = false;
162172
enum { InstrDist = 1024 };
163173
const MachineBasicBlock *CurMBB = nullptr;
164174
DenseMap<const MachineInstr *, uint64_t> Instr2PosIndex;
@@ -1665,7 +1675,7 @@ void RegAllocFast::allocateBasicBlock(MachineBasicBlock &MBB) {
16651675
this->MBB = &MBB;
16661676
LLVM_DEBUG(dbgs() << "\nAllocating " << MBB);
16671677

1668-
PosIndexes.init(MBB);
1678+
PosIndexes.unsetInitialized();
16691679
RegUnitStates.assign(TRI->getNumRegUnits(), regFree);
16701680
assert(LiveVirtRegs.empty() && "Mapping not cleared from last block?");
16711681

0 commit comments

Comments
 (0)