aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorJakob Stoklund Olesen <stoklund@2pi.dk>2012-02-29 00:33:41 +0000
committerJakob Stoklund Olesen <stoklund@2pi.dk>2012-02-29 00:33:41 +0000
commit30e98a03a3c524026e2da2607e04bb655b0b6350 (patch)
tree918eb0da58d10019f3f26e1de5fb0eb955db2f8b /include
parentd1d721660edf3f4e76ea69fd5579f857b97a3150 (diff)
downloadexternal_llvm-30e98a03a3c524026e2da2607e04bb655b0b6350.zip
external_llvm-30e98a03a3c524026e2da2607e04bb655b0b6350.tar.gz
external_llvm-30e98a03a3c524026e2da2607e04bb655b0b6350.tar.bz2
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@151684 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/CodeGen/MachineBasicBlock.h67
-rw-r--r--include/llvm/CodeGen/MachineInstrBundle.h108
2 files changed, 108 insertions, 67 deletions
diff --git a/include/llvm/CodeGen/MachineBasicBlock.h b/include/llvm/CodeGen/MachineBasicBlock.h
index 1138f92..576ce94 100644
--- a/include/llvm/CodeGen/MachineBasicBlock.h
+++ b/include/llvm/CodeGen/MachineBasicBlock.h
@@ -699,73 +699,6 @@ template <> struct GraphTraits<Inverse<const MachineBasicBlock*> > {
}
};
-//===----------------------------------------------------------------------===//
-// 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
diff --git a/include/llvm/CodeGen/MachineInstrBundle.h b/include/llvm/CodeGen/MachineInstrBundle.h
index e6fcdad..f6525a8 100644
--- a/include/llvm/CodeGen/MachineInstrBundle.h
+++ b/include/llvm/CodeGen/MachineInstrBundle.h
@@ -41,6 +41,114 @@ MachineBasicBlock::instr_iterator finalizeBundle(MachineBasicBlock &MBB,
/// 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