-
Notifications
You must be signed in to change notification settings - Fork 14
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
[AIE2P] Refactor register bank selection #325
Conversation
e68a4c6
to
3f14d94
Compare
3f14d94
to
9ac5133
Compare
const MachineInstr &MI, const Register &AccReg) { | ||
static bool isUsedAsAccRegInIntrinsic(const MachineRegisterInfo &MRI, | ||
const MachineInstr &MI, | ||
const Register &AccReg) { | ||
switch (cast<GIntrinsic>(MI).getIntrinsicID()) { | ||
// All Intrinsics with accumlator destination operand |
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.
nit: accumulator + one more below
unsigned Op = MI.getOpcode(); | ||
switch (Op) { | ||
default: | ||
break; | ||
case TargetOpcode::G_INTRINSIC: | ||
case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS: | ||
return isAccIntrinsic(MRI, MI, RegOp); | ||
return isUsedAsAccRegInIntrinsic(MRI, MI, Reg); | ||
case TargetOpcode::COPY: { | ||
Register DstReg = MI.getOperand(0).getReg(); | ||
if (isAccReg(DstReg)) |
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.
What is the difference between isAccReg
and getRegBank(Reg) == AccRegBank
below?
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 understand, isAccReg
look for a register is a physical accumulator register and getRegBank(Reg) == AccRegBank
looks for AccRegBank
is assigned for a virtual register.
auto traceToActualReg = [&](Register &Reg) { | ||
for (auto &UseMI : MRI.use_nodbg_instructions(Reg)) { | ||
MachineInstr *ConvUseMI = &UseMI; | ||
auto TraceToActualReg = [&](Register &SkipReg) { |
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.
Could we pass by value and return the result?
isAccRegMapping = true; | ||
if (isUseFifoInsn(MRI, TRI, UseCandidate)) | ||
if (&AIE2P::FifoRegBank == PreferredRB) |
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.
nit: else if
?
9ac5133
to
f9b7212
Compare
const MachineRegisterInfo &MRI, | ||
const TargetRegisterInfo &TRI, | ||
Register FifoReg); | ||
typedef bool (*RegisterUsedAsSpecificBankFcnPtr)( |
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 this is too old for C++. We can use modern alternatives, like std::function
.
bool isUseFifoInsn(const MachineRegisterInfo &MRI, | ||
const TargetRegisterInfo &TRI, const Register FifoReg, | ||
unsigned Depth = 0) const; | ||
static bool isUsedAsAccRegInInstr(const MachineInstr &MI, |
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.
Static in .h files is unusual. I suggest to keep as is.
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.
The reason I changed to static is, non-static member functions are not allowed to pass. I can remove the declarations.
f9b7212
to
c5b401a
Compare
const RegisterBank *AIE2PRegisterBankInfo::getPreferredRegBankForVectorTy( | ||
const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI, | ||
Register Reg) const { | ||
auto RegTy = MRI.getType(Reg); |
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.
nit: use the real type here for both variables.
} | ||
} | ||
return false; | ||
if (registerBankCheckFunc(isUsedAsAccRegInInstr, MRI, TRI, Reg)) |
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.
Maybe we can use a more assertive name here, like registerBankLookAheadSearch
.
return &getRegBank(AIE2P::AccRegBankID); | ||
if (registerBankCheckFunc(isUsedAsFifoRegInInstr, MRI, TRI, Reg)) | ||
return &getRegBank(AIE2P::FifoRegBankID); | ||
return &getRegBank(AIE2P::VRegBankID); |
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 check against VRegBank? Or do we always check against Acc and Fifo? A feel dangerous just return VRegBank. We don't have a "Register holds vector type" precondition here.
3555c8c
to
8afe399
Compare
return &getRegBank(AIE2P::AccRegBankID); | ||
else if (registerBankLookAheadSearch(isUsedAsFifoRegInInstr, MRI, TRI, Reg)) | ||
return &getRegBank(AIE2P::FifoRegBankID); | ||
else if (RegSize > 64) |
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 is a very cheap check. Can we anticipate it? Like:
if (RegSize <= 256 && RegSize > 64)
return &getRegBank(AIE2P::VRegBankID)
@@ -841,7 +837,9 @@ AIE2PRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const { | |||
auto *RB = getRegBank(DstReg, MRI, TRI); | |||
if (RB == &AIE2P::AccRegBank) | |||
return AIEBaseRegisterBankInfo::getInstrMapping(MI); | |||
if (isUseAccInsn(MRI, TRI, DstReg)) { | |||
auto PreferredRegBank = getPreferredRegBankForVectorTy(MRI, TRI, DstReg); | |||
if (PreferredRegBank.has_value() && |
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.
nit: just if (PreferredRegBank && &AIE2P::AccRegBank == *PreferredRegBank
).
Below as well.
4e26531
to
54e9f3e
Compare
54e9f3e
to
d2ba106
Compare
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. Nice work!
No description provided.