Skip to content

[CodeGen] Add target hook shouldReMaterializeTrivialRegDef #148429

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

Open
wants to merge 2 commits into
base: users/tomershafir/spr/main.codegen-add-target-hook-shouldrematerializetrivialregdef
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions llvm/include/llvm/CodeGen/TargetInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,23 @@ class LLVM_ABI TargetInstrInfo : public MCInstrInfo {
return true;
}

/// Returns true if CopyMI should be considered for register
/// definition rematerialization. Otherwise, returns false.
///
/// Rematerialization can replace a source register with its value
/// from its definition. Its applied in the register coalescer,
/// after instruction selection and before register allocation.
///
/// Subtargets can override this method to classify rematerialization
/// candidates. Note that this cannot be defined in tablegen because it
/// operates at a higher level.
virtual bool shouldReMaterializeTrivialRegDef(
const MachineFunction *MF, const MachineInstr &CopyMI,
const Register &DestReg, const Register &SrcReg,
const LiveIntervals *LIS) const {
return true;
}

/// Re-issue the specified 'original' instruction at the
/// specific location targeting a new destination register.
/// The register in Orig->getOperand(0).getReg() will be substituted by
Expand Down
11 changes: 11 additions & 0 deletions llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,14 @@ bool AArch64InstrInfo::isAsCheapAsAMove(const MachineInstr &MI) const {
}
}

bool AArch64InstrInfo::shouldReMaterializeTrivialRegDef(
const MachineFunction *MF, const MachineInstr &CopyMI,
const Register &DestReg, const Register &SrcReg,
const LiveIntervals *LIS) const {
return !Subtarget.canLowerToZeroCycleRegMove(CopyMI, DestReg, SrcReg) &&
!Subtarget.canLowerToZeroCycleRegZeroing(CopyMI, DestReg, SrcReg);
}

bool AArch64InstrInfo::isFalkorShiftExtFast(const MachineInstr &MI) {
switch (MI.getOpcode()) {
default:
Expand Down Expand Up @@ -5025,6 +5033,9 @@ void AArch64InstrInfo::copyGPRRegTuple(MachineBasicBlock &MBB,
}
}

/// NOTE: must maintain consistency with
/// `AArch64Subtarget::canLowerToZeroCycleRegMove` and
/// `AArch64Subtarget::canLowerToZeroCycleRegZeroing`.
void AArch64InstrInfo::copyPhysReg(MachineBasicBlock &MBB,
MachineBasicBlock::iterator I,
const DebugLoc &DL, Register DestReg,
Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/Target/AArch64/AArch64InstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ class AArch64InstrInfo final : public AArch64GenInstrInfo {

bool isAsCheapAsAMove(const MachineInstr &MI) const override;

bool shouldReMaterializeTrivialRegDef(
const MachineFunction *MF, const MachineInstr &CopyMI,
const Register &DestReg, const Register &SrcReg,
const LiveIntervals *LIS) const override;

bool isCoalescableExtInstr(const MachineInstr &MI, Register &SrcReg,
Register &DstReg, unsigned &SubIdx) const override;

Expand Down
Loading