Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 1 addition & 33 deletions llvm/lib/Target/AIE/AIEBaseRegisterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,12 @@
#include "Utils/AIELoopUtils.h"
#include "llvm/CodeGen/LiveIntervals.h"

namespace llvm {
static cl::opt<bool> EnableCoalescingForWideCopy(
"aie-enable-widen-copy-coalescing",
cl::desc("Enable register coalescing for widening Copy"), cl::init(false),
cl::Hidden);
using namespace llvm;

bool AIEBaseRegisterInfo::shouldCoalesce(
MachineInstr *MI, const TargetRegisterClass *SrcRC, unsigned SubReg,
const TargetRegisterClass *DstRC, unsigned DstSubReg,
const TargetRegisterClass *NewRC, LiveIntervals &LIS) const {
MachineBasicBlock *MBB = MI->getParent();
if (EnableCoalescingForWideCopy || AIELoopUtils::isSingleMBBLoop(MBB)) {
return TargetRegisterInfo::shouldCoalesce(MI, SrcRC, SubReg, DstRC,
DstSubReg, NewRC, LIS);
}
const unsigned SrcSize = getRegSizeInBits(*SrcRC);
const unsigned DstSize = getRegSizeInBits(*DstRC);
MachineFunction *MF = MI->getMF();
const AIEBaseInstrInfo *TII =
static_cast<const AIEBaseInstrInfo *>(MF->getSubtarget().getInstrInfo());
const unsigned BasicVectorSize = TII->getBasicVecRegSize();
// Should not coalesce if copying from bigger source.
if (SrcSize < DstSize &&
(SrcSize >= BasicVectorSize || DstSize >= BasicVectorSize)) {
LiveInterval &LI = LIS.getInterval(MI->getOperand(1).getReg());
const MachineInstr *FirstMI =
LI.empty() ? nullptr : LIS.getInstructionFromIndex(LI.beginIndex());
const MachineInstr *LastMI =
LI.empty() ? nullptr : LIS.getInstructionFromIndex(LI.endIndex());
// Coalescing inside the same basic block found beneficial. So, check that
// the LiveInterval is not just local to MBB.
if (!FirstMI || FirstMI->getParent() != MBB || !LastMI ||
LastMI->getParent() != MBB)
return false;
}

return TargetRegisterInfo::shouldCoalesce(MI, SrcRC, SubReg, DstRC, DstSubReg,
NewRC, LIS);
}

} // namespace llvm
38 changes: 38 additions & 0 deletions llvm/lib/Target/AIE/aie2p/AIE2PRegisterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "AIE2PRegisterBankInfo.h"
#include "AIE2PSubtarget.h"
#include "MCTargetDesc/aie2p/AIE2PMCTargetDesc.h"
#include "Utils/AIELoopUtils.h"
#include "llvm/CodeGen/LiveIntervals.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
Expand All @@ -34,6 +36,11 @@ using namespace llvm;

extern cl::opt<bool> SimplifyCRSRRegs;

cl::opt<bool> EnableCoalescingForWideCopy(
"aie-enable-widen-copy-coalescing",
cl::desc("Enable register coalescing for widening Copy"), cl::init(false),
cl::Hidden);

extern llvm::cl::opt<unsigned> ReservedGPRs;

AIE2PRegisterInfo::AIE2PRegisterInfo(unsigned HwMode)
Expand Down Expand Up @@ -603,3 +610,34 @@ bool AIE2PRegisterInfo::isFifoPhysReg(const Register Reg) const {
return Reg.isPhysical() && (AIE2P::FIFO512RegClass.contains(Reg) ||
AIE2P::FIFO1024RegClass.contains(Reg));
}

bool AIE2PRegisterInfo::shouldCoalesce(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe it is better to have this code only for AIE2P, as we are not planning to evaluate effects for AIE2 in this moment. Also, we should keep QoR results for AIE2 in a stable state.

MachineInstr *MI, const TargetRegisterClass *SrcRC, unsigned SubReg,
const TargetRegisterClass *DstRC, unsigned DstSubReg,
const TargetRegisterClass *NewRC, LiveIntervals &LIS) const {

const unsigned SrcSize = getRegSizeInBits(*SrcRC);
const unsigned DstSize = getRegSizeInBits(*DstRC);
MachineFunction *MF = MI->getMF();
const AIEBaseInstrInfo *TII =
static_cast<const AIEBaseInstrInfo *>(MF->getSubtarget().getInstrInfo());
const unsigned BasicVectorSize = TII->getBasicVecRegSize();
// Should not coalesce if copying from bigger source.
if (!EnableCoalescingForWideCopy && SrcSize < DstSize &&
(SrcSize >= BasicVectorSize || DstSize >= BasicVectorSize)) {
MachineBasicBlock *MBB = MI->getParent();
LiveInterval &LI = LIS.getInterval(MI->getOperand(1).getReg());
const MachineInstr *FirstMI =
LI.empty() ? nullptr : LIS.getInstructionFromIndex(LI.beginIndex());
const MachineInstr *LastMI =
LI.empty() ? nullptr : LIS.getInstructionFromIndex(LI.endIndex());
// Coalescing inside the same basic block found beneficial. So, check that
// the LiveInterval is not just local to MBB.
if (!FirstMI || FirstMI->getParent() != MBB || !LastMI ||
LastMI->getParent() != MBB)
return false;
}

return TargetRegisterInfo::shouldCoalesce(MI, SrcRC, SubReg, DstRC, DstSubReg,
NewRC, LIS);
}
5 changes: 5 additions & 0 deletions llvm/lib/Target/AIE/aie2p/AIE2PRegisterInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ struct AIE2PRegisterInfo : public AIE2PGenRegisterInfo {
bool isFifoPhysReg(const Register Reg) const override;

bool isSimplifiableReservedReg(MCRegister PhysReg) const override;

bool shouldCoalesce(MachineInstr *MI, const TargetRegisterClass *SrcRC,
unsigned SubReg, const TargetRegisterClass *DstRC,
unsigned DstSubReg, const TargetRegisterClass *NewRC,
LiveIntervals &LIS) const override;
};
} // namespace llvm

Expand Down
Loading