https://github.com/HaohaiWen updated https://github.com/llvm/llvm-project/pull/76275
>From 23882772e4dac82b45cac2b3ea4fba12415764f6 Mon Sep 17 00:00:00 2001 From: Haohai Wen <haohai....@intel.com> Date: Sat, 23 Dec 2023 09:55:37 +0800 Subject: [PATCH] [RegAllocFast] Lazily initialize InstrPosIndexes for each MBB Most basic block do not need to query dominates. Defer initialization of InstrPosIndexes to first query for each MBB. --- llvm/lib/CodeGen/RegAllocFast.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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?"); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits