Skip to content

Commit

Permalink
CodeGen: Update LiveIntervalAnalysis API to use MachineInstr&, NFC
Browse files Browse the repository at this point in the history
These parameters aren't expected to be null, so take them by reference.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@262151 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
dexonsmith committed Feb 27, 2016
1 parent 1d75c8d commit 5144d35
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 45 deletions.
6 changes: 3 additions & 3 deletions include/llvm/CodeGen/LiveIntervalAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ extern cl::opt<bool> UseSegmentSetForPhysRegs;
// Calculate the spill weight to assign to a single instruction.
static float getSpillWeight(bool isDef, bool isUse,
const MachineBlockFrequencyInfo *MBFI,
const MachineInstr *Instr);
const MachineInstr &Instr);

LiveInterval &getInterval(unsigned Reg) {
if (hasInterval(Reg))
Expand Down Expand Up @@ -288,7 +288,7 @@ extern cl::opt<bool> UseSegmentSetForPhysRegs;
/// are not supported.
///
/// \param UpdateFlags Update live intervals for nonallocatable physregs.
void handleMove(MachineInstr* MI, bool UpdateFlags = false);
void handleMove(MachineInstr &MI, bool UpdateFlags = false);

/// moveIntoBundle - Update intervals for operands of MI so that they
/// begin/end on the SlotIndex for BundleStart.
Expand All @@ -298,7 +298,7 @@ extern cl::opt<bool> UseSegmentSetForPhysRegs;
/// Requires MI and BundleStart to have SlotIndexes, and assumes
/// existing liveness is accurate. BundleStart should be the first
/// instruction in the Bundle.
void handleMoveIntoBundle(MachineInstr* MI, MachineInstr* BundleStart,
void handleMoveIntoBundle(MachineInstr &MI, MachineInstr &BundleStart,
bool UpdateFlags = false);

/// repairIntervalsInRange - Update live intervals for instructions in a
Expand Down
3 changes: 1 addition & 2 deletions lib/CodeGen/CalcSpillWeights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ VirtRegAuxInfo::calculateSpillWeightAndHint(LiveInterval &li) {
// Calculate instr weight.
bool reads, writes;
std::tie(reads, writes) = mi->readsWritesVirtualRegister(li.reg);
weight = LiveIntervals::getSpillWeight(
writes, reads, &MBFI, mi);
weight = LiveIntervals::getSpillWeight(writes, reads, &MBFI, *mi);

// Give extra weight to what looks like a loop induction variable update.
if (writes && isExiting && LIS.isLiveOutOfMBB(li, mbb))
Expand Down
55 changes: 28 additions & 27 deletions lib/CodeGen/LiveIntervalAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,11 +841,10 @@ LiveIntervals::hasPHIKill(const LiveInterval &LI, const VNInfo *VNI) const {
return false;
}

float
LiveIntervals::getSpillWeight(bool isDef, bool isUse,
const MachineBlockFrequencyInfo *MBFI,
const MachineInstr *MI) {
BlockFrequency Freq = MBFI->getBlockFreq(MI->getParent());
float LiveIntervals::getSpillWeight(bool isDef, bool isUse,
const MachineBlockFrequencyInfo *MBFI,
const MachineInstr &MI) {
BlockFrequency Freq = MBFI->getBlockFreq(MI.getParent());
const float Scale = 1.0f / MBFI->getEntryFreq();
return (isDef + isUse) * (Freq.getFrequency() * Scale);
}
Expand Down Expand Up @@ -1391,26 +1390,26 @@ class LiveIntervals::HMEditor {
}
};

void LiveIntervals::handleMove(MachineInstr* MI, bool UpdateFlags) {
assert(!MI->isBundled() && "Can't handle bundled instructions yet.");
SlotIndex OldIndex = Indexes->getInstructionIndex(*MI);
Indexes->removeMachineInstrFromMaps(*MI);
SlotIndex NewIndex = Indexes->insertMachineInstrInMaps(*MI);
assert(getMBBStartIdx(MI->getParent()) <= OldIndex &&
OldIndex < getMBBEndIdx(MI->getParent()) &&
void LiveIntervals::handleMove(MachineInstr &MI, bool UpdateFlags) {
assert(!MI.isBundled() && "Can't handle bundled instructions yet.");
SlotIndex OldIndex = Indexes->getInstructionIndex(MI);
Indexes->removeMachineInstrFromMaps(MI);
SlotIndex NewIndex = Indexes->insertMachineInstrInMaps(MI);
assert(getMBBStartIdx(MI.getParent()) <= OldIndex &&
OldIndex < getMBBEndIdx(MI.getParent()) &&
"Cannot handle moves across basic block boundaries.");

HMEditor HME(*this, *MRI, *TRI, OldIndex, NewIndex, UpdateFlags);
HME.updateAllRanges(MI);
HME.updateAllRanges(&MI);
}

void LiveIntervals::handleMoveIntoBundle(MachineInstr* MI,
MachineInstr* BundleStart,
void LiveIntervals::handleMoveIntoBundle(MachineInstr &MI,
MachineInstr &BundleStart,
bool UpdateFlags) {
SlotIndex OldIndex = Indexes->getInstructionIndex(*MI);
SlotIndex NewIndex = Indexes->getInstructionIndex(*BundleStart);
SlotIndex OldIndex = Indexes->getInstructionIndex(MI);
SlotIndex NewIndex = Indexes->getInstructionIndex(BundleStart);
HMEditor HME(*this, *MRI, *TRI, OldIndex, NewIndex, UpdateFlags);
HME.updateAllRanges(MI);
HME.updateAllRanges(&MI);
}

void LiveIntervals::repairOldRegInRange(const MachineBasicBlock::iterator Begin,
Expand All @@ -1427,18 +1426,19 @@ void LiveIntervals::repairOldRegInRange(const MachineBasicBlock::iterator Begin,

for (MachineBasicBlock::iterator I = End; I != Begin;) {
--I;
MachineInstr *MI = I;
if (MI->isDebugValue())
MachineInstr &MI = *I;
if (MI.isDebugValue())
continue;

SlotIndex instrIdx = getInstructionIndex(*MI);
SlotIndex instrIdx = getInstructionIndex(MI);
bool isStartValid = getInstructionFromIndex(LII->start);
bool isEndValid = getInstructionFromIndex(LII->end);

// FIXME: This doesn't currently handle early-clobber or multiple removed
// defs inside of the region to repair.
for (MachineInstr::mop_iterator OI = MI->operands_begin(),
OE = MI->operands_end(); OI != OE; ++OI) {
for (MachineInstr::mop_iterator OI = MI.operands_begin(),
OE = MI.operands_end();
OI != OE; ++OI) {
const MachineOperand &MO = *OI;
if (!MO.isReg() || MO.getReg() != Reg)
continue;
Expand Down Expand Up @@ -1523,11 +1523,12 @@ LiveIntervals::repairIntervalsInRange(MachineBasicBlock *MBB,

for (MachineBasicBlock::iterator I = End; I != Begin;) {
--I;
MachineInstr *MI = I;
if (MI->isDebugValue())
MachineInstr &MI = *I;
if (MI.isDebugValue())
continue;
for (MachineInstr::const_mop_iterator MOI = MI->operands_begin(),
MOE = MI->operands_end(); MOI != MOE; ++MOI) {
for (MachineInstr::const_mop_iterator MOI = MI.operands_begin(),
MOE = MI.operands_end();
MOI != MOE; ++MOI) {
if (MOI->isReg() &&
TargetRegisterInfo::isVirtualRegister(MOI->getReg()) &&
!hasInterval(MOI->getReg())) {
Expand Down
2 changes: 1 addition & 1 deletion lib/CodeGen/MachineScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ void ScheduleDAGMI::moveInstruction(

// Update LiveIntervals
if (LIS)
LIS->handleMove(MI, /*UpdateFlags=*/true);
LIS->handleMove(*MI, /*UpdateFlags=*/true);

// Recede RegionBegin if an instruction moves above the first.
if (RegionBegin == InsertPos)
Expand Down
13 changes: 7 additions & 6 deletions lib/CodeGen/StackSlotColoring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ void StackSlotColoring::ScanForSpillSlotRefs(MachineFunction &MF) {
MachineBasicBlock *MBB = &*MBBI;
for (MachineBasicBlock::iterator MII = MBB->begin(), EE = MBB->end();
MII != EE; ++MII) {
MachineInstr *MI = &*MII;
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
MachineOperand &MO = MI->getOperand(i);
MachineInstr &MI = *MII;
for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
MachineOperand &MO = MI.getOperand(i);
if (!MO.isFI())
continue;
int FI = MO.getIndex();
Expand All @@ -156,11 +156,12 @@ void StackSlotColoring::ScanForSpillSlotRefs(MachineFunction &MF) {
if (!LS->hasInterval(FI))
continue;
LiveInterval &li = LS->getInterval(FI);
if (!MI->isDebugValue())
if (!MI.isDebugValue())
li.weight += LiveIntervals::getSpillWeight(false, true, MBFI, MI);
}
for (MachineInstr::mmo_iterator MMOI = MI->memoperands_begin(),
EE = MI->memoperands_end(); MMOI != EE; ++MMOI) {
for (MachineInstr::mmo_iterator MMOI = MI.memoperands_begin(),
EE = MI.memoperands_end();
MMOI != EE; ++MMOI) {
MachineMemOperand *MMO = *MMOI;
if (const FixedStackPseudoSourceValue *FSV =
dyn_cast_or_null<FixedStackPseudoSourceValue>(
Expand Down
8 changes: 4 additions & 4 deletions lib/CodeGen/TwoAddressInstructionPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ sink3AddrInstruction(MachineInstr *MI, unsigned SavedReg,
MBB->insert(KillPos, MI);

if (LIS)
LIS->handleMove(MI);
LIS->handleMove(*MI);

++Num3AddrSunk;
return true;
Expand Down Expand Up @@ -957,7 +957,7 @@ rescheduleMIBelowKill(MachineBasicBlock::iterator &mi,
MachineInstr *CopyMI = MBBI;
++MBBI;
MBB->splice(InsertPos, MBB, CopyMI);
LIS->handleMove(CopyMI);
LIS->handleMove(*CopyMI);
InsertPos = CopyMI;
}
End = std::next(MachineBasicBlock::iterator(MI));
Expand All @@ -969,7 +969,7 @@ rescheduleMIBelowKill(MachineBasicBlock::iterator &mi,

// Update live variables
if (LIS) {
LIS->handleMove(MI);
LIS->handleMove(*MI);
} else {
LV->removeVirtualRegisterKilled(Reg, KillMI);
LV->addVirtualRegisterKilled(Reg, MI);
Expand Down Expand Up @@ -1137,7 +1137,7 @@ rescheduleKillAboveMI(MachineBasicBlock::iterator &mi,

// Update live variables
if (LIS) {
LIS->handleMove(KillMI);
LIS->handleMove(*KillMI);
} else {
LV->removeVirtualRegisterKilled(Reg, KillMI);
LV->addVirtualRegisterKilled(Reg, MI);
Expand Down
4 changes: 2 additions & 2 deletions lib/Target/AMDGPU/SIMachineScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ void SIScheduleBlockCreator::scheduleInsideBlocks() {
// is the most cpu intensive operation of the scheduler.
// It would gain a lot if there was a way to recompute the
// LiveIntervals for the entire scheduling region.
DAG->getLIS()->handleMove(MI, /*UpdateFlags=*/true);
DAG->getLIS()->handleMove(*MI, /*UpdateFlags=*/true);
PosNew.push_back(CurrentTopFastSched);
}
}
Expand All @@ -1250,7 +1250,7 @@ void SIScheduleBlockCreator::scheduleInsideBlocks() {
DAG->getBB()->splice(POld, DAG->getBB(), PNew);

// Update LiveIntervals.
DAG->getLIS()->handleMove(POld, /*UpdateFlags=*/true);
DAG->getLIS()->handleMove(*POld, /*UpdateFlags=*/true);
}
}

Expand Down

0 comments on commit 5144d35

Please sign in to comment.