Skip to content

[RegAllocFast] Lazily initialize InstrPosIndexes for each MBB #76275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion llvm/lib/CodeGen/RegAllocFast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ namespace {
/// can be used to determine dominance between instructions in same MBB.
class InstrPosIndexes {
public:
void unsetInitialized() { IsInitialized = false; }

void init(const MachineBasicBlock &MBB) {
CurMBB = &MBB;
Instr2PosIndex.clear();
Expand All @@ -80,6 +82,13 @@ class InstrPosIndexes {
/// index without affecting existing instruction's index. Return true if all
/// instructions index has been reassigned.
bool getIndex(const MachineInstr &MI, uint64_t &Index) {
if (!IsInitialized) {
init(*MI.getParent());
IsInitialized = true;
Index = Instr2PosIndex.at(&MI);
return true;
}

assert(MI.getParent() == CurMBB && "MI is not in CurMBB");
auto It = Instr2PosIndex.find(&MI);
if (It != Instr2PosIndex.end()) {
Expand Down Expand Up @@ -159,6 +168,7 @@ class InstrPosIndexes {
}

private:
bool IsInitialized = false;
enum { InstrDist = 1024 };
const MachineBasicBlock *CurMBB = nullptr;
DenseMap<const MachineInstr *, uint64_t> Instr2PosIndex;
Expand Down Expand Up @@ -1665,7 +1675,7 @@ void RegAllocFast::allocateBasicBlock(MachineBasicBlock &MBB) {
this->MBB = &MBB;
LLVM_DEBUG(dbgs() << "\nAllocating " << MBB);

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

Expand Down