[llvm-commits] [llvm] r151684 - in /llvm/trunk: include/llvm/CodeGen/MachineBasicBlock.h include/llvm/CodeGen/MachineInstrBundle.h lib/CodeGen/MachineVerifier.cpp
Jakob Stoklund Olesen
stoklund at 2pi.dk
Tue Feb 28 16:33:41 PST 2012
Author: stoklund
Date: Tue Feb 28 18:33:41 2012
New Revision: 151684
URL: http://llvm.org/viewvc/llvm-project?rev=151684&view=rev
Log:
Move the operand iterator into MachineInstrBundle.h where it belongs.
Extract a base class and provide four specific sub-classes for iterating
over const/non-const bundles/instructions.
This eliminates the mystery bool constructor argument.
Modified:
llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h
llvm/trunk/include/llvm/CodeGen/MachineInstrBundle.h
llvm/trunk/lib/CodeGen/MachineVerifier.cpp
Modified: llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h?rev=151684&r1=151683&r2=151684&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h Tue Feb 28 18:33:41 2012
@@ -699,73 +699,6 @@
}
};
-//===----------------------------------------------------------------------===//
-// MachineOperand iterator
-//
-
-/// MachineOperands - Iterator that can visit all operands on a MachineInstr,
-/// or all operands on a bundle of MachineInstrs.
-///
-/// Intended use:
-///
-/// for (MIOperands MIO(MI, true); MIO.isValid(); ++MIO) {
-/// if (!MIO->isReg())
-/// continue;
-/// ...
-/// }
-///
-class MIOperands {
- MachineBasicBlock::instr_iterator InstrI, InstrE;
- MachineInstr::mop_iterator OpI, OpE;
-
- // If the operands on InstrI are exhausted, advance InstrI to the next
- // bundled instruction with operands.
- void advance() {
- while (OpI == OpE) {
- // Don't advance off the basic block, or into a new bundle.
- if (++InstrI == InstrE || !InstrI->isInsideBundle())
- break;
- OpI = InstrI->operands_begin();
- OpE = InstrI->operands_end();
- }
- }
-
-public:
- /// MIOperands - Create an iterator that visits all operands on MI, or all
- /// operands on every instruction in the bundle containing MI.
- ///
- /// @param MI The instruction to examine.
- /// @param WholeBundle When true, visit all operands on the entire bundle.
- ///
- explicit MIOperands(MachineInstr *MI, bool WholeBundle = false) {
- if (WholeBundle) {
- InstrI = MI->getBundleStart();
- InstrE = MI->getParent()->instr_end();
- } else {
- InstrI = InstrE = MI;
- ++InstrE;
- }
- OpI = InstrI->operands_begin();
- OpE = InstrI->operands_end();
- if (WholeBundle)
- advance();
- }
-
- /// isValid - Returns true until all the operands have been visited.
- bool isValid() const { return OpI != OpE; }
-
- /// Preincrement. Move to the next operand.
- MIOperands &operator++() {
- assert(isValid() && "Cannot advance MIOperands beyond the last operand");
- ++OpI;
- advance();
- return *this;
- }
-
- MachineOperand &operator* () const { return *OpI; }
- MachineOperand *operator->() const { return &*OpI; }
-};
-
} // End llvm namespace
#endif
Modified: llvm/trunk/include/llvm/CodeGen/MachineInstrBundle.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineInstrBundle.h?rev=151684&r1=151683&r2=151684&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineInstrBundle.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineInstrBundle.h Tue Feb 28 18:33:41 2012
@@ -41,6 +41,114 @@
/// MachineFunction. Return true if any bundles are finalized.
bool finalizeBundles(MachineFunction &MF);
+//===----------------------------------------------------------------------===//
+// MachineOperand iterator
+//
+
+/// MachineOperandIteratorBase - Iterator that can visit all operands on a
+/// MachineInstr, or all operands on a bundle of MachineInstrs. This class is
+/// not intended to be used directly, use one of the sub-classes instead.
+///
+/// Intended use:
+///
+/// for (MIBundleOperands MIO(MI); MIO.isValid(); ++MIO) {
+/// if (!MIO->isReg())
+/// continue;
+/// ...
+/// }
+///
+class MachineOperandIteratorBase {
+ MachineBasicBlock::instr_iterator InstrI, InstrE;
+ MachineInstr::mop_iterator OpI, OpE;
+
+ // If the operands on InstrI are exhausted, advance InstrI to the next
+ // bundled instruction with operands.
+ void advance() {
+ while (OpI == OpE) {
+ // Don't advance off the basic block, or into a new bundle.
+ if (++InstrI == InstrE || !InstrI->isInsideBundle())
+ break;
+ OpI = InstrI->operands_begin();
+ OpE = InstrI->operands_end();
+ }
+ }
+
+protected:
+ /// MachineOperandIteratorBase - Create an iterator that visits all operands
+ /// on MI, or all operands on every instruction in the bundle containing MI.
+ ///
+ /// @param MI The instruction to examine.
+ /// @param WholeBundle When true, visit all operands on the entire bundle.
+ ///
+ explicit MachineOperandIteratorBase(MachineInstr *MI, bool WholeBundle) {
+ if (WholeBundle) {
+ InstrI = MI->getBundleStart();
+ InstrE = MI->getParent()->instr_end();
+ } else {
+ InstrI = InstrE = MI;
+ ++InstrE;
+ }
+ OpI = InstrI->operands_begin();
+ OpE = InstrI->operands_end();
+ if (WholeBundle)
+ advance();
+ }
+
+ MachineOperand &deref() const { return *OpI; }
+
+public:
+ /// isValid - Returns true until all the operands have been visited.
+ bool isValid() const { return OpI != OpE; }
+
+ /// Preincrement. Move to the next operand.
+ void operator++() {
+ assert(isValid() && "Cannot advance MIOperands beyond the last operand");
+ ++OpI;
+ advance();
+ }
+
+};
+
+/// MIOperands - Iterate over operands of a single instruction.
+///
+class MIOperands : public MachineOperandIteratorBase {
+public:
+ MIOperands(MachineInstr *MI) : MachineOperandIteratorBase(MI, false) {}
+ MachineOperand &operator* () const { return deref(); }
+ MachineOperand *operator->() const { return &deref(); }
+};
+
+/// ConstMIOperands - Iterate over operands of a single const instruction.
+///
+class ConstMIOperands : public MachineOperandIteratorBase {
+public:
+ ConstMIOperands(const MachineInstr *MI)
+ : MachineOperandIteratorBase(const_cast<MachineInstr*>(MI), false) {}
+ const MachineOperand &operator* () const { return deref(); }
+ const MachineOperand *operator->() const { return &deref(); }
+};
+
+/// MIBundleOperands - Iterate over all operands in a bundle of machine
+/// instructions.
+///
+class MIBundleOperands : public MachineOperandIteratorBase {
+public:
+ MIBundleOperands(MachineInstr *MI) : MachineOperandIteratorBase(MI, true) {}
+ MachineOperand &operator* () const { return deref(); }
+ MachineOperand *operator->() const { return &deref(); }
+};
+
+/// ConstMIBundleOperands - Iterate over all operands in a const bundle of
+/// machine instructions.
+///
+class ConstMIBundleOperands : public MachineOperandIteratorBase {
+public:
+ ConstMIBundleOperands(const MachineInstr *MI)
+ : MachineOperandIteratorBase(const_cast<MachineInstr*>(MI), true) {}
+ const MachineOperand &operator* () const { return deref(); }
+ const MachineOperand *operator->() const { return &deref(); }
+};
+
} // End llvm namespace
#endif
Modified: llvm/trunk/lib/CodeGen/MachineVerifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineVerifier.cpp?rev=151684&r1=151683&r2=151684&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineVerifier.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineVerifier.cpp Tue Feb 28 18:33:41 2012
@@ -28,6 +28,7 @@
#include "llvm/CodeGen/LiveIntervalAnalysis.h"
#include "llvm/CodeGen/LiveVariables.h"
#include "llvm/CodeGen/LiveStackAnalysis.h"
+#include "llvm/CodeGen/MachineInstrBundle.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineMemOperand.h"
@@ -1104,7 +1105,7 @@
}
} else {
// Non-PHI def.
- MachineInstr *MI = LiveInts->getInstructionFromIndex(VNI->def);
+ const MachineInstr *MI = LiveInts->getInstructionFromIndex(VNI->def);
if (!MI) {
report("No instruction at def index", MF);
*OS << "Valno #" << VNI->id << " is defined at " << VNI->def
@@ -1114,7 +1115,7 @@
bool hasDef = false;
bool isEarlyClobber = false;
- for (MIOperands MOI(MI, true); MOI.isValid(); ++MOI) {
+ for (ConstMIBundleOperands MOI(MI); MOI.isValid(); ++MOI) {
if (!MOI->isReg() || !MOI->isDef())
continue;
if (TargetRegisterInfo::isVirtualRegister(LI.reg)) {
@@ -1197,7 +1198,7 @@
continue;
// The live segment is ending inside EndMBB
- MachineInstr *MI =
+ const MachineInstr *MI =
LiveInts->getInstructionFromIndex(I->end.getPrevSlot());
if (!MI) {
report("Live segment doesn't end at a valid instruction", EndMBB);
@@ -1242,7 +1243,7 @@
// use, or a dead flag on a def.
bool hasRead = false;
bool hasDeadDef = false;
- for (MIOperands MOI(MI, true); MOI.isValid(); ++MOI) {
+ for (ConstMIBundleOperands MOI(MI); MOI.isValid(); ++MOI) {
if (!MOI->isReg() || MOI->getReg() != LI.reg)
continue;
if (MOI->readsReg())
More information about the llvm-commits
mailing list