[llvm] [RegAllocFast] Refactor dominates algorithm for large basic block (PR #72250)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 14 22:28:04 PST 2023
================
@@ -62,6 +62,71 @@ 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;
+ }
+ }
+
+ /// Set \p Index to index of \p MI. If \p MI is new inserted, it try to assign
+ /// index without affecting existing instruction's index. Return true if all
+ /// instructions index has been reassigned.
+ bool getIndex(const MachineInstr &MI, uint64_t &Index) {
+ assert(MI.getParent() == CurMBB && "MI is not in CurMBB");
+ if (Instr2PosIndex.count(&MI)) {
+ Index = Instr2PosIndex[&MI];
+ return false;
+ }
+
+ unsigned Distance = 1;
+ MachineBasicBlock::const_iterator Start = MI.getIterator(),
+ End = std::next(Start);
+ while (Start != CurMBB->begin() &&
+ !Instr2PosIndex.count(&*std::prev(Start))) {
+ --Start;
----------------
arsenm wrote:
Debug instructions aren't quite assigned normally. They're tracked and fixed up after the block is processed if the register wasn't already assigned
https://github.com/llvm/llvm-project/pull/72250
More information about the llvm-commits
mailing list