/// 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; }
/// 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;
///
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();
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;
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;
MachineInstr &operator*() const {
assert(Op && "Cannot dereference end iterator!");
if (ByBundle)
- return getBundleStart(*Op->getParent());
+ return *getBundleStart(Op->getParent()->getIterator());
return *Op->getParent();
}
/// 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;
}
// 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))
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());
}
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()));
}