Files
archived-llvm/include/llvm/CodeGen/MachineInstrBundleIterator.h
Duncan P. N. Exon Smith fe912bf4b0 CodeGen: Make iterator-to-pointer conversion explicit, NFC
Remove the implicit conversion from MachineInstrBundleIterator to
MachineInstr*, leaving behind an explicit conversion.

I *think* this is the last ilist_iterator-related implicit conversion to
ilist_node subclass.  If I'm right, I can finally dig in and fix the UB
in ilist that these conversions were relying on.

Note that the implicit users of this conversion have already been
removed.  If you have out-of-tree code that doesn't update, you might be
able to buy some time by temporarily reverting this commit.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276902 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-27 18:45:18 +00:00

93 lines
2.9 KiB
C++

//===- llvm/CodeGen/MachineInstrBundleIterator.h ----------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Defines an iterator class that bundles MachineInstr.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CODEGEN_MACHINEINSTRBUNDLEITERATOR_H
#define LLVM_CODEGEN_MACHINEINSTRBUNDLEITERATOR_H
#include "llvm/ADT/ilist.h"
#include <iterator>
namespace llvm {
/// MachineBasicBlock iterator that automatically skips over MIs that are
/// inside bundles (i.e. walk top level MIs only).
template <typename Ty>
class MachineInstrBundleIterator
: public std::iterator<std::bidirectional_iterator_tag, Ty, ptrdiff_t> {
typedef ilist_iterator<Ty> instr_iterator;
instr_iterator MII;
public:
MachineInstrBundleIterator(instr_iterator MI) : MII(MI) {}
MachineInstrBundleIterator(Ty &MI) : MII(MI) {
assert(!MI.isBundledWithPred() && "It's not legal to initialize "
"MachineInstrBundleIterator with a "
"bundled MI");
}
MachineInstrBundleIterator(Ty *MI) : MII(MI) {
// FIXME: This conversion should be explicit.
assert((!MI || !MI->isBundledWithPred()) && "It's not legal to initialize "
"MachineInstrBundleIterator "
"with a bundled MI");
}
// Template allows conversion from const to nonconst.
template <class OtherTy>
MachineInstrBundleIterator(const MachineInstrBundleIterator<OtherTy> &I)
: MII(I.getInstrIterator()) {}
MachineInstrBundleIterator() : MII(nullptr) {}
Ty &operator*() const { return *MII; }
Ty *operator->() const { return &operator*(); }
// FIXME: This should be implemented as "return &operator*()" (or removed).
explicit operator Ty *() const { return MII.getNodePtrUnchecked(); }
bool operator==(const MachineInstrBundleIterator &X) const {
return MII == X.MII;
}
bool operator!=(const MachineInstrBundleIterator &X) const {
return !operator==(X);
}
// Increment and decrement operators...
MachineInstrBundleIterator &operator--() {
do
--MII;
while (MII->isBundledWithPred());
return *this;
}
MachineInstrBundleIterator &operator++() {
while (MII->isBundledWithSucc())
++MII;
++MII;
return *this;
}
MachineInstrBundleIterator operator--(int) {
MachineInstrBundleIterator Temp = *this;
--*this;
return Temp;
}
MachineInstrBundleIterator operator++(int) {
MachineInstrBundleIterator Temp = *this;
++*this;
return Temp;
}
instr_iterator getInstrIterator() const { return MII; }
};
} // end namespace llvm
#endif