-
Notifications
You must be signed in to change notification settings - Fork 12k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RegAllocFast] Refactor dominates algorithm for large basic block #72250
Conversation
The original brute force dominates algorithm is O(n) complexity so it is very slow for very large machine basic block which is very common with O0. This patch added InstrPosIndexes to assign index for each instruction and use it to determine dominance. The complexity is now O(1).
Hi, is there any more comment? I'd like to land this patch. |
for (auto I = Start; I != End; ++I) { | ||
LastIndex += Step; | ||
Instr2PosIndex[&*I] = LastIndex; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we know when new MI being inserted? I think we can simply assgin it a value if we do, e.g.,
MachineInstr *New = BuildMI(MBB, II, ...
uint64_t NewPos = Instr2PosIndex[&*II] - 1;
if (LLVM_UNLIKELY(NewPos & (InstrDist - 1) == 0)) ...
Instr2PosIndex[New] = NewPos;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This requires to carefully maintain this PosIndex for each insertion point. I think it's unfriendly for other users.
If we insert two instructions before same place, we need to be careful about the step to avoid duplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
for (const MachineInstr &MI : MBB) { | ||
LastIndex += InstrDist; | ||
Instr2PosIndex[&MI] = LastIndex; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for suggestion. See #76275
The original brute force dominates algorithm is O(n) complexity so it is
very slow for very large machine basic block which is very common with
O0. This patch added InstrPosIndexes to assign index for each
instruction and use it to determine dominance. The complexity is now
O(1).