+ //
+ // Iterator to enumerate machine operands.
+ //
+ template<class MITy, class VTy>
+ class ValOpIterator : public forward_iterator<VTy, ptrdiff_t> {
+ unsigned i;
+ MITy MI;
+
+ void skipToNextVal() {
+ while (i < MI->getNumOperands() &&
+ !( (MI->getOperand(i).getType() == MachineOperand::MO_VirtualRegister ||
+ MI->getOperand(i).getType() == MachineOperand::MO_CCRegister)
+ && MI->getOperand(i).getVRegValue() != 0))
+ ++i;
+ }
+
+ inline ValOpIterator(MITy mi, unsigned I) : i(I), MI(mi) {
+ skipToNextVal();
+ }
+
+ public:
+ typedef ValOpIterator<MITy, VTy> _Self;
+
+ inline VTy operator*() const {
+ return MI->getOperand(i).getVRegValue();
+ }
+
+ const MachineOperand &getMachineOperand() const { return MI->getOperand(i);}
+ MachineOperand &getMachineOperand() { return MI->getOperand(i);}
+
+ inline VTy operator->() const { return operator*(); }
+
+ inline bool isUseOnly() const { return MI->getOperand(i).opIsUse(); }
+ inline bool isDefOnly() const { return MI->getOperand(i).opIsDefOnly(); }
+ inline bool isDefAndUse() const { return MI->getOperand(i).opIsDefAndUse();}
+
+ inline _Self& operator++() { i++; skipToNextVal(); return *this; }
+ inline _Self operator++(int) { _Self tmp = *this; ++*this; return tmp; }
+
+ inline bool operator==(const _Self &y) const {
+ return i == y.i;
+ }
+ inline bool operator!=(const _Self &y) const {
+ return !operator==(y);
+ }
+
+ static _Self begin(MITy MI) {
+ return _Self(MI, 0);
+ }
+ static _Self end(MITy MI) {
+ return _Self(MI, MI->getNumOperands());
+ }
+ };