Skip to content
Closed
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
6 changes: 6 additions & 0 deletions llvm/include/llvm/CodeGen/TargetInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2166,6 +2166,12 @@ class LLVM_ABI TargetInstrInfo : public MCInstrInfo {
return false;
}

/// Get the insertion point for a live range split copy at the beginning of
/// a basic block. This is used by the register allocator's live range
/// splitting logic.
virtual MachineBasicBlock::iterator
getExecAwareInsertPoint(MachineBasicBlock &MBB, Register Reg) const;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should use a generic name without any target-dependent register details in a common file.


/// Allows targets to use appropriate copy instruction while spilitting live
/// range of a register in register allocation.
virtual unsigned getLiveRangeSplitOpcode(Register Reg,
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/SplitKit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,8 @@ SlotIndex SplitEditor::leaveIntvAtTop(MachineBasicBlock &MBB) {

unsigned RegIdx = 0;
Register Reg = LIS.getInterval(Edit->get(RegIdx)).reg();
VNInfo *VNI = defFromParent(RegIdx, ParentVNI, Start, MBB,
MBB.SkipPHIsLabelsAndDebug(MBB.begin(), Reg));
MachineBasicBlock::iterator InsertPt = TII.getExecAwareInsertPoint(MBB, Reg);
VNInfo *VNI = defFromParent(RegIdx, ParentVNI, Start, MBB, InsertPt);
RegAssign.insert(Start, VNI->def, OpenIdx);
LLVM_DEBUG(dump());
return VNI->def;
Expand Down
6 changes: 6 additions & 0 deletions llvm/lib/CodeGen/TargetInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2222,3 +2222,9 @@ bool TargetInstrInfo::isGlobalMemoryObject(const MachineInstr *MI) const {
return MI->isCall() || MI->hasUnmodeledSideEffects() ||
(MI->hasOrderedMemoryRef() && !MI->isDereferenceableInvariantLoad());
}

MachineBasicBlock::iterator
TargetInstrInfo::getExecAwareInsertPoint(MachineBasicBlock &MBB,
Register Reg) const {
return MBB.SkipPHIsLabelsAndDebug(MBB.begin(), Reg);
}
38 changes: 38 additions & 0 deletions llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9903,6 +9903,44 @@ bool SIInstrInfo::isBasicBlockPrologue(const MachineInstr &MI,
MI.modifiesRegister(AMDGPU::EXEC, &RI)));
}

MachineBasicBlock::iterator
SIInstrInfo::getExecAwareInsertPoint(MachineBasicBlock &MBB,
Register Reg) const {
if (!Reg)
return MBB.SkipPHIsLabelsAndDebug(MBB.begin());

// Instructions using SGPRS are independent of exec mask: skip.
const MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo();
const TargetRegisterClass *RC = Reg.isPhysical() ? RI.getPhysRegBaseClass(Reg)
: MRI.getRegClassOrNull(Reg);
if (RC && RI.isSGPRClass(RC))
return MBB.SkipPHIsLabelsAndDebug(MBB.begin(), Reg);

// For VGPRs, find a safe insert point after exec has been restored.
// A standard basic block prologue pattern is:
// BB:
// <PHIs>
// <labels>
// <SGPR spills/restores>
// <scalar copies - live range splits for SGPRs>
// s_or_b32 exec_lo, exec_lo, s_saved

// Look for exec restore instruction: it could be after the first SGPR copy.
MachineBasicBlock::iterator I = MBB.SkipPHIsLabelsAndDebug(MBB.begin(), Reg);
MachineBasicBlock::iterator E = MBB.end();

for (MachineBasicBlock::iterator It = I; It != E; ++It) {
if (!It->isTerminator() && It->modifiesRegister(AMDGPU::EXEC, &RI))
return std::next(It);

if (It->mayLoadOrStore() && !isSGPRSpill(It->getOpcode()) &&
!isWWMRegSpillOpcode(It->getOpcode()))
break;
}

return I;
}

MachineInstrBuilder
SIInstrInfo::getAddNoCarry(MachineBasicBlock &MBB,
MachineBasicBlock::iterator I,
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/Target/AMDGPU/SIInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1579,6 +1579,9 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
bool isBasicBlockPrologue(const MachineInstr &MI,
Register Reg = Register()) const override;

MachineBasicBlock::iterator
getExecAwareInsertPoint(MachineBasicBlock &MBB, Register Reg) const override;

MachineInstr *createPHIDestinationCopy(MachineBasicBlock &MBB,
MachineBasicBlock::iterator InsPt,
const DebugLoc &DL, Register Src,
Expand Down