ADT: Remove all ilist_iterator => pointer casts, NFC
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Fri, 12 Aug 2016 05:05:36 +0000 (05:05 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Fri, 12 Aug 2016 05:05:36 +0000 (05:05 +0000)
commitf197b1f78f854d8513ef617b8cfc61860f7b4b84
treeb1b5d31d642e9a8597137799be8a9aebd6f9954e
parent91a02f5beef6b8ba2ae9e79b04259e6c3573fb73
ADT: Remove all ilist_iterator => pointer casts, NFC

Remove all ilist_iterator to pointer casts.  There were two reasons for
casts:

  - Checking for an uninitialized (i.e., null) iterator.  I added
    MachineInstrBundleIterator::isValid() to check for that case.

  - Comparing an iterator against the underlying pointer value while
    avoiding converting the pointer value to an iterator.  This is
    occasionally necessary in MachineInstrBundleIterator, since there is
    an assertion in the constructors that the underlying MachineInstr is
    not bundled (but we don't care about that if we're just checking for
    pointer equality).

To support the latter case, I rewrote the == and != operators for
ilist_iterator and MachineInstrBundleIterator.

  - The implicit constructors now use enable_if to exclude
    const-iterator => non-const-iterator conversions from overload
    resolution (previously it was a compiler error on instantiation, now
    it's SFINAE).

  - The == and != operators are now global (friends), and are not
    templated.

  - MachineInstrBundleIterator has overloads to compare against both
    const_pointer and const_reference.  This avoids the implicit
    conversions to MachineInstrBundleIterator that assert, instead just
    checking the address (and I added unit tests to confirm this).

Notably, the only remaining uses of ilist_iterator::getNodePtrUnchecked
are in ilist.h, and no code outside of ilist*.h directly relies on this
UB end-iterator-to-pointer conversion anymore.  It's still needed for
ilist_*sentinel_traits, but I'll clean that up soon.

llvm-svn: 278478
llvm/include/llvm/ADT/ilist.h
llvm/include/llvm/CodeGen/MachineInstrBundleIterator.h
llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
llvm/lib/Target/AMDGPU/AMDILCFGStructurizer.cpp
llvm/lib/Target/AMDGPU/R600InstrInfo.cpp
llvm/lib/Target/Hexagon/HexagonCopyToCombine.cpp
llvm/lib/Target/Mips/MipsConstantIslandPass.cpp
llvm/unittests/CodeGen/CMakeLists.txt
llvm/unittests/CodeGen/MachineInstrBundleIteratorTest.cpp [new file with mode: 0644]