Don't use invalidated iterators in FlattenCFGPass
FlattenCFG may erase unnecessary blocks, which also invalidates iterators to those erased blocks.
Before this patch, iterativelyFlattenCFG could try to increment a BB iterator after that BB has been removed and crash.
This patch makes FlattenCFGPass use WeakVH to skip over erased blocks.
Reviewers: dblaikie, tstellar, davide, sanjoy, asbirlea, grosser
Reviewed By: asbirlea
Subscribers: hiraditya, llvm-commits
Differential Revision: https://reviews.llvm.org/D67672