1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

MachineInstrBundle: Pass iterators to getBundle(Start|End); NFC

This is a function to go backwards in a block to find the first
instruction in a bundle, so iterator is a more natural choice for
parameter/return rather than a reference to a MachineInstruction.

llvm-svn: 285051
This commit is contained in:
Matthias Braun 2016-10-25 02:55:17 +00:00
parent 667b6a8f41
commit 456a8212fd
6 changed files with 29 additions and 26 deletions

View File

@ -460,7 +460,8 @@ public:
/// Create an MIBundleBuilder representing an existing instruction or bundle
/// that has MI as its head.
explicit MIBundleBuilder(MachineInstr *MI)
: MBB(*MI->getParent()), Begin(MI), End(getBundleEnd(*MI)) {}
: MBB(*MI->getParent()), Begin(MI),
End(getBundleEnd(MI->getIterator())) {}
/// Return a reference to the basic block containing this bundle.
MachineBasicBlock &getMBB() const { return MBB; }

View File

@ -41,34 +41,33 @@ MachineBasicBlock::instr_iterator finalizeBundle(MachineBasicBlock &MBB,
/// MachineFunction. Return true if any bundles are finalized.
bool finalizeBundles(MachineFunction &MF);
/// getBundleStart - Returns the first instruction in the bundle containing MI.
///
inline MachineInstr &getBundleStart(MachineInstr &MI) {
MachineBasicBlock::instr_iterator I(MI);
/// Returns an iterator to the first instruction in the bundle containing \p I.
inline MachineBasicBlock::instr_iterator getBundleStart(
MachineBasicBlock::instr_iterator I) {
while (I->isBundledWithPred())
--I;
return *I;
return I;
}
inline const MachineInstr &getBundleStart(const MachineInstr &MI) {
MachineBasicBlock::const_instr_iterator I(MI);
/// Returns an iterator to the first instruction in the bundle containing \p I.
inline MachineBasicBlock::const_instr_iterator getBundleStart(
MachineBasicBlock::const_instr_iterator I) {
while (I->isBundledWithPred())
--I;
return *I;
return I;
}
/// Return an iterator pointing beyond the bundle containing MI.
inline MachineBasicBlock::instr_iterator getBundleEnd(MachineInstr &MI) {
MachineBasicBlock::instr_iterator I(MI);
/// Returns an iterator pointing beyond the bundle containing \p I.
inline MachineBasicBlock::instr_iterator getBundleEnd(
MachineBasicBlock::instr_iterator I) {
while (I->isBundledWithSucc())
++I;
return ++I;
}
/// Return an iterator pointing beyond the bundle containing MI.
inline MachineBasicBlock::const_instr_iterator
getBundleEnd(const MachineInstr &MI) {
MachineBasicBlock::const_instr_iterator I(MI);
/// Returns an iterator pointing beyond the bundle containing \p I.
inline MachineBasicBlock::const_instr_iterator getBundleEnd(
MachineBasicBlock::const_instr_iterator I) {
while (I->isBundledWithSucc())
++I;
return ++I;
@ -115,7 +114,7 @@ protected:
///
explicit MachineOperandIteratorBase(MachineInstr &MI, bool WholeBundle) {
if (WholeBundle) {
InstrI = getBundleStart(MI).getIterator();
InstrI = getBundleStart(MI.getIterator());
InstrE = MI.getParent()->instr_end();
} else {
InstrI = InstrE = MI.getIterator();

View File

@ -898,10 +898,11 @@ public:
advance();
} while (Op && Op->getParent() == P);
} else if (ByBundle) {
MachineInstr &P = getBundleStart(*Op->getParent());
MachineBasicBlock::instr_iterator P =
getBundleStart(Op->getParent()->getIterator());
do {
advance();
} while (Op && &getBundleStart(*Op->getParent()) == &P);
} while (Op && getBundleStart(Op->getParent()->getIterator()) == P);
}
return *this;
@ -1000,10 +1001,11 @@ public:
advance();
} while (Op && Op->getParent() == P);
} else if (ByBundle) {
MachineInstr &P = getBundleStart(*Op->getParent());
MachineBasicBlock::instr_iterator P =
getBundleStart(Op->getParent()->getIterator());
do {
advance();
} while (Op && &getBundleStart(*Op->getParent()) == &P);
} while (Op && getBundleStart(Op->getParent()->getIterator()) == P);
}
return *this;
@ -1016,7 +1018,7 @@ public:
MachineInstr &operator*() const {
assert(Op && "Cannot dereference end iterator!");
if (ByBundle)
return getBundleStart(*Op->getParent());
return *getBundleStart(Op->getParent()->getIterator());
return *Op->getParent();
}

View File

@ -405,7 +405,8 @@ namespace llvm {
/// Returns the base index for the given instruction.
SlotIndex getInstructionIndex(const MachineInstr &MI) const {
// Instructions inside a bundle have the same number as the bundle itself.
Mi2IndexMap::const_iterator itr = mi2iMap.find(&getBundleStart(MI));
const MachineInstr &BundleStart = *getBundleStart(MI.getIterator());
Mi2IndexMap::const_iterator itr = mi2iMap.find(&BundleStart);
assert(itr != mi2iMap.end() && "Instruction not found in maps.");
return itr->second;
}

View File

@ -1222,7 +1222,7 @@ static void toggleBundleKillFlag(MachineInstr *MI, unsigned Reg,
// might set it on too many operands. We will clear as many flags as we
// can though.
MachineBasicBlock::instr_iterator Begin = MI->getIterator();
MachineBasicBlock::instr_iterator End = getBundleEnd(*MI);
MachineBasicBlock::instr_iterator End = getBundleEnd(Begin);
while (Begin != End) {
if (NewKillState) {
if ((--End)->addRegisterKilled(Reg, TRI, /* addIfNotFound= */ false))
@ -1344,7 +1344,7 @@ void ScheduleDAGInstrs::fixupKills(MachineBasicBlock *MBB) {
DEBUG({
if (MI.getOpcode() == TargetOpcode::BUNDLE) {
MachineBasicBlock::instr_iterator Begin = MI.getIterator();
MachineBasicBlock::instr_iterator End = getBundleEnd(MI);
MachineBasicBlock::instr_iterator End = getBundleEnd(Begin);
while (++Begin != End)
DEBUG(Begin->dump());
}

View File

@ -4239,7 +4239,7 @@ unsigned HexagonInstrInfo::nonDbgBundleSize(
assert(BundleHead->isBundle() && "Not a bundle header");
auto MII = BundleHead.getInstrIterator();
// Skip the bundle header.
return nonDbgMICount(++MII, getBundleEnd(*BundleHead));
return nonDbgMICount(++MII, getBundleEnd(BundleHead.getInstrIterator()));
}