From c8440dddb25dac3da5574f94ed267e9d2183c57e Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Tue, 25 Oct 2016 02:55:17 +0000 Subject: [PATCH] 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 --- llvm/include/llvm/CodeGen/MachineInstrBuilder.h | 3 ++- llvm/include/llvm/CodeGen/MachineInstrBundle.h | 31 ++++++++++++------------- llvm/include/llvm/CodeGen/MachineRegisterInfo.h | 12 ++++++---- llvm/include/llvm/CodeGen/SlotIndexes.h | 3 ++- llvm/lib/CodeGen/ScheduleDAGInstrs.cpp | 4 ++-- llvm/lib/Target/Hexagon/HexagonInstrInfo.cpp | 2 +- 6 files changed, 29 insertions(+), 26 deletions(-) diff --git a/llvm/include/llvm/CodeGen/MachineInstrBuilder.h b/llvm/include/llvm/CodeGen/MachineInstrBuilder.h index 66aebcf..3c8a362 100644 --- a/llvm/include/llvm/CodeGen/MachineInstrBuilder.h +++ b/llvm/include/llvm/CodeGen/MachineInstrBuilder.h @@ -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; } diff --git a/llvm/include/llvm/CodeGen/MachineInstrBundle.h b/llvm/include/llvm/CodeGen/MachineInstrBundle.h index c0033a5..995c700 100644 --- a/llvm/include/llvm/CodeGen/MachineInstrBundle.h +++ b/llvm/include/llvm/CodeGen/MachineInstrBundle.h @@ -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(); diff --git a/llvm/include/llvm/CodeGen/MachineRegisterInfo.h b/llvm/include/llvm/CodeGen/MachineRegisterInfo.h index 377bdeb..75e7250 100644 --- a/llvm/include/llvm/CodeGen/MachineRegisterInfo.h +++ b/llvm/include/llvm/CodeGen/MachineRegisterInfo.h @@ -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(); } diff --git a/llvm/include/llvm/CodeGen/SlotIndexes.h b/llvm/include/llvm/CodeGen/SlotIndexes.h index 984b5f3..2ac3b3d 100644 --- a/llvm/include/llvm/CodeGen/SlotIndexes.h +++ b/llvm/include/llvm/CodeGen/SlotIndexes.h @@ -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; } diff --git a/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp b/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp index ba9bf90..b968260 100644 --- a/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp +++ b/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp @@ -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()); } diff --git a/llvm/lib/Target/Hexagon/HexagonInstrInfo.cpp b/llvm/lib/Target/Hexagon/HexagonInstrInfo.cpp index 9704bd7..8b92df6 100644 --- a/llvm/lib/Target/Hexagon/HexagonInstrInfo.cpp +++ b/llvm/lib/Target/Hexagon/HexagonInstrInfo.cpp @@ -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())); } -- 2.7.4