[llvm] 536b043 - [RegAllocFast] Lazily initialize InstrPosIndexes for each MBB (#76275)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 24 17:42:35 PST 2023
Author: HaohaiWen
Date: 2023-12-25T09:42:31+08:00
New Revision: 536b043219e75976888bd77f6063b02ebb6ffdb9
URL: https://github.com/llvm/llvm-project/commit/536b043219e75976888bd77f6063b02ebb6ffdb9
DIFF: https://github.com/llvm/llvm-project/commit/536b043219e75976888bd77f6063b02ebb6ffdb9.diff
LOG: [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.
Added:
Modified:
llvm/lib/CodeGen/RegAllocFast.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/RegAllocFast.cpp b/llvm/lib/CodeGen/RegAllocFast.cpp
index d7edaa1d7ea47d..e81d4793013682 100644
--- a/llvm/lib/CodeGen/RegAllocFast.cpp
+++ b/llvm/lib/CodeGen/RegAllocFast.cpp
@@ -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();
@@ -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()) {
@@ -159,6 +168,7 @@ class InstrPosIndexes {
}
private:
+ bool IsInitialized = false;
enum { InstrDist = 1024 };
const MachineBasicBlock *CurMBB = nullptr;
DenseMap<const MachineInstr *, uint64_t> Instr2PosIndex;
@@ -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?");
More information about the llvm-commits
mailing list