- // 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->getOperandType(i) == MachineOperand::MO_VirtualRegister ||
- MI->getOperandType(i) == 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 isDef() const { return MI->getOperand(i).opIsDef(); }
- 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());
- }
- };