typedef typename instr_iterator::const_pointer const_pointer;
typedef typename instr_iterator::const_reference const_reference;
+private:
+ typedef typename std::remove_const<value_type>::type nonconst_value_type;
+ typedef ilist_node<nonconst_value_type> node_type;
+ typedef ilist_iterator<nonconst_value_type> nonconst_instr_iterator;
+ typedef MachineInstrBundleIterator<nonconst_value_type> nonconst_iterator;
+
+public:
MachineInstrBundleIterator(instr_iterator MI) : MII(MI) {}
MachineInstrBundleIterator(reference MI) : MII(MI) {
}
instr_iterator getInstrIterator() const { return MII; }
+
+ nonconst_iterator getNonConstIterator() const {
+ if (auto *N = const_cast<node_type *>(MII.getNodePtr()))
+ return nonconst_iterator(nonconst_instr_iterator(*N));
+ return nonconst_iterator();
+ }
};
} // end namespace llvm
static MachineBasicBlock::iterator
priorNonDebug(MachineBasicBlock::iterator I,
MachineBasicBlock::const_iterator Beg) {
- return const_cast<MachineInstr*>(
- &*priorNonDebug(MachineBasicBlock::const_iterator(I), Beg));
+ return priorNonDebug(MachineBasicBlock::const_iterator(I), Beg)
+ .getNonConstIterator();
}
/// If this iterator is a debug value, increment until reaching the End or a
static MachineBasicBlock::iterator
nextIfDebug(MachineBasicBlock::iterator I,
MachineBasicBlock::const_iterator End) {
- // Cast the return value to nonconst MachineInstr, then cast to an
- // instr_iterator, which does not check for null, finally return a
- // bundle_iterator.
- return MachineBasicBlock::instr_iterator(
- const_cast<MachineInstr*>(
- &*nextIfDebug(MachineBasicBlock::const_iterator(I), End)));
+ return nextIfDebug(MachineBasicBlock::const_iterator(I), End)
+ .getNonConstIterator();
}
/// Instantiate a ScheduleDAGInstrs that will be owned by the caller.