This patch is a re-incarnation of https://reviews.llvm.org/D10740 (which seems to be abandoned now). This adds support for TSan C++ exception handling, where we need to add extra calls to __tsan_func_exit when a function is exitted via exception mechanisms. Otherwise the shadow stack gets corrupted (leaked). There is an existing implementation that finds all possible function exit points, and adds extra EH cleanup blocks where needed.
I moved the implementation of EscapeEnumerator to a header file, but note that I made one change, which is the addition of the II->setDebugLoc(CI->getDebugLoc()); line. This makes sure we don't lose debug information.
The state machine is superfluous, it only has two real states: 1 (running) and 2 (done). The state 0 logic could be handled in the constructor by setting StateBB and StateE. Mind killing the switch and this comment, assuming we don't implement the code size optimization I described below?