[flang] [clang] [lldb] [clang-tools-extra] [compiler-rt] [libcxx] [llvm] [libc] [RegAllocFast] Refactor dominates algorithm for large basic block (PR #72250)

Nikita Popov via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 22 09:38:45 PST 2023


================
@@ -62,6 +62,107 @@ static RegisterRegAlloc fastRegAlloc("fast", "fast register allocator",
 
 namespace {
 
+/// Assign ascending index for instructions in machine basic block. The index
+/// can be used to determine dominance between instructions in same MBB.
+class InstrPosIndexes {
+public:
+  void init(const MachineBasicBlock &MBB) {
+    CurMBB = &MBB;
+    Instr2PosIndex.clear();
+    uint64_t LastIndex = 0;
+    for (const MachineInstr &MI : MBB) {
+      LastIndex += InstrDist;
+      Instr2PosIndex[&MI] = LastIndex;
+    }
----------------
nikic wrote:

Can we do this lazily, on first query?

It looks like dominates() is actually only used in very rare situations (where a block branches back to itself), so populating this map is unnecessary for most blocks.



https://github.com/llvm/llvm-project/pull/72250


More information about the cfe-commits mailing list