Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 2 additions & 7 deletions llvm/lib/CodeGen/RegAllocGreedy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,7 @@ bool RAGreedy::addSplitConstraints(InterferenceCache::Cursor Intf,
// Abort if the spill cannot be inserted at the MBB' start
if (((BC.Entry == SpillPlacement::MustSpill) ||
(BC.Entry == SpillPlacement::PrefSpill)) &&
SlotIndex::isEarlierInstr(BI.FirstInstr,
SA->getFirstSplitPoint(BC.Number)))
!SA->canSplitBeforeProlog(BC.Number))
return false;
}

Expand Down Expand Up @@ -829,11 +828,7 @@ bool RAGreedy::addThroughConstraints(InterferenceCache::Cursor Intf,
BCS[B].Number = Number;

// Abort if the spill cannot be inserted at the MBB' start
MachineBasicBlock *MBB = MF->getBlockNumbered(Number);
auto FirstNonDebugInstr = MBB->getFirstNonDebugInstr();
if (FirstNonDebugInstr != MBB->end() &&
SlotIndex::isEarlierInstr(LIS->getInstructionIndex(*FirstNonDebugInstr),
SA->getFirstSplitPoint(Number)))
if (!SA->canSplitBeforeProlog(Number))
return false;
// Interference for the live-in value.
if (Intf.first() <= Indexes->getMBBStartIdx(Number))
Expand Down
28 changes: 28 additions & 0 deletions llvm/lib/CodeGen/SplitKit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,34 @@ InsertPointAnalysis::getLastInsertPointIter(const LiveInterval &CurLI,
return LIS.getInstructionFromIndex(LIP);
}

bool InsertPointAnalysis::canSplitBeforeProlog(const LiveInterval &CurLI,
const MachineBasicBlock &MBB) {
const TargetInstrInfo *TII = MBB.getParent()->getSubtarget().getInstrInfo();

for (auto &MI : MBB) {
if (MI.isPHI() || MI.isPosition() || MI.isDebugInstr() ||
MI.isPseudoProbe())
continue;

if (!TII->isBasicBlockPrologue(MI))
return true;

for (auto &MO : MI.operands()) {
if (!MO.isReg() || !MO.isDef() || !MO.getReg().isVirtual())
continue;

const MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo();
const TargetRegisterInfo *TRI = MRI.getTargetRegisterInfo();
const TargetRegisterClass *RC = MRI.getRegClass(MO.getReg());
const TargetRegisterClass *CurRC = MRI.getRegClass(CurLI.reg());
if (TRI->getCommonSubClass(RC, CurRC))
return false;
}
}

return true;
}

//===----------------------------------------------------------------------===//
// Split Analysis
//===----------------------------------------------------------------------===//
Expand Down
8 changes: 8 additions & 0 deletions llvm/lib/CodeGen/SplitKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ class LLVM_LIBRARY_VISIBILITY InsertPointAnalysis {
return Res;
}

/// Return true if we can split \pCurLI before \pMBB's prolog.
bool canSplitBeforeProlog(const LiveInterval &CurLI,
const MachineBasicBlock &MBB);
};

/// SplitAnalysis - Analyze a LiveInterval, looking for live range splitting
Expand Down Expand Up @@ -247,6 +250,11 @@ class LLVM_LIBRARY_VISIBILITY SplitAnalysis {
SlotIndex getFirstSplitPoint(unsigned Num) {
return IPA.getFirstInsertPoint(*MF.getBlockNumbered(Num));
}

bool canSplitBeforeProlog(unsigned Num) {
MachineBasicBlock *BB = MF.getBlockNumbered(Num);
return IPA.canSplitBeforeProlog(*CurLI, *BB);
}
};

/// SplitEditor - Edit machine code and LiveIntervals for live range
Expand Down
Loading
Loading