[IR] Make SwitchInst::CaseIt almost a normal iterator.
authorChandler Carruth <chandlerc@gmail.com>
Sun, 26 Mar 2017 02:49:23 +0000 (02:49 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Sun, 26 Mar 2017 02:49:23 +0000 (02:49 +0000)
commit0d256c0f5d246e884ec0320b703bb3a0606aefc5
tree75ea172e9d31514a2e2672ea6a1cd4f63e5d6d8e
parentbeeab45770e080e03fd60ddda6cdab6e5b7c3128
[IR] Make SwitchInst::CaseIt almost a normal iterator.

This moves it to the iterator facade utilities giving it full random
access semantics, etc. It can also now be used with standard algorithms
like std::all_of and std::any_of and range adaptors like llvm::reverse.

Also make the semantics of iterating match what every other iterator
uses and forbid decrementing past the begin iterator. This was used as
a hacky way to work around iterator invalidation. However, every
instance trying to do this failed to actually avoid touching invalid
iterators despite the clear documentation that the removed and all
subsequent iterators become invalid including the end iterator. So I've
added a return of the next iterator to removeCase and rewritten the
loops that were doing this to correctly follow the iterator pattern of
either incremneting or removing and assigning fresh values to the
iterator and the end.

In one case we were trying to go backwards to make this cleaner but it
doesn't actually work. I've made that code match the code we use
everywhere else to remove cases as we iterate. This changes the order of
cases in one test output and I moved that test to CHECK-DAG so it
wouldn't care -- the order isn't semantically meaningful anyways.

llvm-svn: 298791
llvm/include/llvm/IR/Instructions.h
llvm/lib/IR/Instructions.cpp
llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
llvm/lib/Transforms/Utils/Local.cpp
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/CorrelatedValuePropagation/basic.ll