-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[MachinePipeliner] Use RegisterClassInfo::getRegPressureSetLimit
#119827
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
[MachinePipeliner] Use RegisterClassInfo::getRegPressureSetLimit
#119827
Conversation
// We assume fixed registers, such as stack pointer, are already in use. | ||
// Therefore subtracting the weight of the fixed registers from the limit of | ||
// each pressure set in advance. | ||
SmallDenseSet<Register, 8> FixedRegs; |
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.
Not sure what a fixed register is, but it seems to not be the same as reserved. Seems like another hook with bad defaults
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.
Yeah, it is a bad API. Fixed registers are not reserved register... Fixed register are registers defined in FixedRegisters
RegisterCategory by default...
The logic here seems to want to remove reserved registers @kasuga-fj.
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.
As I commented in #118787 (comment), I dared to replace it from RegisterClassInfo::getRegPressureSetLimit
before (in #87312). This is because there is a duplication between the reserved registers handled inside RegisterClassInfo::getRegPressureSetLimit
and the FixedRegs
calculated here, so the Limit >= Weight
assertion fails. If I remember correctly, in my case (AArch64), the $ffr
triggers it. What I'd like to do here is to ignore registers that have "specific rolls" (e.g., stack pointer) and those where TargetRegisterInfo::isFixedRegister
returns true looks appropriate in this case to me. Maybe I'm misunderstanding reserved and fixed registers, and there may be a better way to achieve what I want, but I'm not sure this change will work well.
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.
IMO isFixedRegister should be deleted. The intent seems to be isReserved || isConstantPhysREg
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 explanation! At least, after removing this part of code, the tests still pass? @kasuga-fj
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.
I ran tests and none of them failed. But that just means there are no correctness issues. This code is part of a heuristic decision, so performance degradation could happen in some cases (and I think the heuristics will be less accurate with this change).
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.
I think the heuristics will be less accurate with this change
I don't think so. These "fixed" registers are also "reserved" registers, and "reserved" registers contain runtime fixed registers like those are reserved via -ffixed-xx
options.
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.
These "fixed" registers are also "reserved" registers,
Previously (where RegisterClassInfo::getRegPressureSetLimit
was used here), #83437 caused the Limit >= Weight
assertion to fail. This patch marks the $ffr
register as reserved. I just tried to comment out the code that marks $ffr
as reserved and run MachinePipeliner, and found that FixedRegs
contains $ffr
. It looks to me like there are some gaps between "reserved" and "fixed". Or maybe I misunderstood something (I don't know much about the LLVM API for registers).
`RegisterClassInfo::getRegPressureSetLimit` is a wrapper of `TargetRegisterInfo::getRegPressureSetLimit` with some logics to adjust the limit by removing reserved registers. It seems that we shouldn't use `TargetRegisterInfo::getRegPressureSetLimit` directly, just like the comment "This limit must be adjusted dynamically for reserved registers" said. Thus we should use `RegisterClassInfo::getRegPressureSetLimit` and remove replicated code. Separate from llvm#118787
b0dd0ca
to
e0b49e0
Compare
@wangpc-pp Could you please check my comment #119827 (comment)? I don't have a strong opinion to reject this change, but I still suspect that there are some differences between "fixed" and "reserved" registers. To make the code consistent, I think we need to change the following function. llvm-project/llvm/lib/CodeGen/MachinePipeliner.cpp Lines 1287 to 1289 in 93743ee
|
Sorry, I was thinking that I may have solved your problem. bool AArch64GenRegisterInfo::
isFixedRegister(const MachineFunction &MF, MCRegister PhysReg) const {
return
AArch64::CCRRegClass.contains(PhysReg) ||
AArch64::FIXED_REGSRegClass.contains(PhysReg) ||
false;
} // Condition code regclass.
def CCR : RegisterClass<"AArch64", [i32], 32, (add NZCV)> {
let CopyCost = -1; // Don't allow copying of status registers.
// CCR is not allocatable.
let isAllocatable = 0;
}
def FIXED_REGS : RegisterClass<"AArch64", [i64], 64, (add FP, SP, VG, FFR)>;
def FixedRegisters : RegisterCategory<[CCR, FIXED_REGS]>; Reserved registers are: llvm-project/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp Lines 426 to 518 in 93743ee
So, all fixed registers are also reserved registers. I created #120694 to skip reserved registers, please have a look. :-) |
I see. Thanks, I thought a function like |
RegisterClassInfo::getRegPressureSetLimit
is a wrapper ofTargetRegisterInfo::getRegPressureSetLimit
with some logics toadjust the limit by removing reserved registers.
It seems that we shouldn't use
TargetRegisterInfo::getRegPressureSetLimit
directly, just like the comment "This limit must be adjusted
dynamically for reserved registers" said.
Thus we should use
RegisterClassInfo::getRegPressureSetLimit
andremove replicated code.
Separate from #118787