[libcxx-commits] [llvm] [compiler-rt] [libcxx] [clang] [mlir] [clang-tools-extra] [RegAllocFast] Lazily initialize InstrPosIndexes for each MBB (PR #76275)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Dec 24 16:57:27 PST 2023
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.wen at 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?");
More information about the libcxx-commits
mailing list