Skip to content
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

Merged
merged 1 commit into from
Feb 13, 2025
Merged

Conversation

niwinanto
Copy link
Collaborator

No description provided.

@niwinanto niwinanto force-pushed the niwin.regbank.select branch from e68a4c6 to 3f14d94 Compare January 31, 2025 11:10
@niwinanto niwinanto force-pushed the niwin.regbank.select branch from 3f14d94 to 9ac5133 Compare February 5, 2025 11:16
@niwinanto niwinanto marked this pull request as ready for review February 5, 2025 11:22
@niwinanto niwinanto changed the title [WIP][AIE2P] Refactor register bank selection [AIE2P] Refactor register bank selection Feb 5, 2025
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
Copy link
Collaborator

@martien-de-jong martien-de-jong Feb 10, 2025

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))
Copy link
Collaborator

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?

Copy link
Collaborator Author

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) {
Copy link
Collaborator

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: else if?

const MachineRegisterInfo &MRI,
const TargetRegisterInfo &TRI,
Register FifoReg);
typedef bool (*RegisterUsedAsSpecificBankFcnPtr)(
Copy link
Collaborator

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,
Copy link
Collaborator

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.

Copy link
Collaborator Author

@niwinanto niwinanto Feb 13, 2025

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.

@niwinanto niwinanto force-pushed the niwin.regbank.select branch from f9b7212 to c5b401a Compare February 13, 2025 11:33
const RegisterBank *AIE2PRegisterBankInfo::getPreferredRegBankForVectorTy(
const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI,
Register Reg) const {
auto RegTy = MRI.getType(Reg);
Copy link
Collaborator

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))
Copy link
Collaborator

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);
Copy link
Collaborator

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.

@niwinanto niwinanto force-pushed the niwin.regbank.select branch 4 times, most recently from 3555c8c to 8afe399 Compare February 13, 2025 14:37
return &getRegBank(AIE2P::AccRegBankID);
else if (registerBankLookAheadSearch(isUsedAsFifoRegInInstr, MRI, TRI, Reg))
return &getRegBank(AIE2P::FifoRegBankID);
else if (RegSize > 64)
Copy link
Collaborator

@andcarminati andcarminati Feb 13, 2025

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() &&
Copy link
Collaborator

@andcarminati andcarminati Feb 13, 2025

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.

@niwinanto niwinanto force-pushed the niwin.regbank.select branch 2 times, most recently from 4e26531 to 54e9f3e Compare February 13, 2025 16:29
@niwinanto niwinanto force-pushed the niwin.regbank.select branch from 54e9f3e to d2ba106 Compare February 13, 2025 16:31
Copy link
Collaborator

@andcarminati andcarminati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Nice work!

@niwinanto niwinanto enabled auto-merge (rebase) February 13, 2025 16:40
@niwinanto niwinanto merged commit a0b3ab2 into aie-public Feb 13, 2025
8 checks passed
@SagarMaheshwari99 SagarMaheshwari99 deleted the niwin.regbank.select branch February 14, 2025 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants