[IR] Reformulate LLVM's EH funclet IR
authorDavid Majnemer <david.majnemer@gmail.com>
Sat, 12 Dec 2015 05:38:55 +0000 (05:38 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Sat, 12 Dec 2015 05:38:55 +0000 (05:38 +0000)
commit8cec2f281696a19faee58cd0749a70fbcc0fa218
treea4bd9bcda2aa7ec03d0689b96e25840b0919c9b9
parentb73b3474ad5dac5bcf2e02836c51c169d71b6ada
[IR] Reformulate LLVM's EH funclet IR

While we have successfully implemented a funclet-oriented EH scheme on
top of LLVM IR, our scheme has some notable deficiencies:
- catchendpad and cleanupendpad are necessary in the current design
  but they are difficult to explain to others, even to seasoned LLVM
  experts.
- catchendpad and cleanupendpad are optimization barriers.  They cannot
  be split and force all potentially throwing call-sites to be invokes.
  This has a noticable effect on the quality of our code generation.
- catchpad, while similar in some aspects to invoke, is fairly awkward.
  It is unsplittable, starts a funclet, and has control flow to other
  funclets.
- The nesting relationship between funclets is currently a property of
  control flow edges.  Because of this, we are forced to carefully
  analyze the flow graph to see if there might potentially exist illegal
  nesting among funclets.  While we have logic to clone funclets when
  they are illegally nested, it would be nicer if we had a
  representation which forbade them upfront.

Let's clean this up a bit by doing the following:
- Instead, make catchpad more like cleanuppad and landingpad: no control
  flow, just a bunch of simple operands;  catchpad would be splittable.
- Introduce catchswitch, a control flow instruction designed to model
  the constraints of funclet oriented EH.
- Make funclet scoping explicit by having funclet instructions consume
  the token produced by the funclet which contains them.
- Remove catchendpad and cleanupendpad.  Their presence can be inferred
  implicitly using coloring information.

N.B.  The state numbering code for the CLR has been updated but the
veracity of it's output cannot be spoken for.  An expert should take a
look to make sure the results are reasonable.

Reviewers: rnk, JosephTremoulet, andrew.w.kaylor

Differential Revision: http://reviews.llvm.org/D15139

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255422 91177308-0d34-0410-b5e6-96231b3b80d8
109 files changed:
docs/ExceptionHandling.rst
docs/LangRef.rst
include/llvm-c/Core.h
include/llvm/Analysis/EHPersonalities.h
include/llvm/Bitcode/LLVMBitCodes.h
include/llvm/CodeGen/WinEHFuncInfo.h
include/llvm/IR/IRBuilder.h
include/llvm/IR/InstVisitor.h
include/llvm/IR/InstrTypes.h
include/llvm/IR/Instruction.def
include/llvm/IR/Instruction.h
include/llvm/IR/Instructions.h
include/llvm/Transforms/Utils/Local.h
lib/Analysis/CaptureTracking.cpp
lib/Analysis/EHPersonalities.cpp
lib/Analysis/InstructionSimplify.cpp
lib/Analysis/LoopInfo.cpp
lib/Analysis/ScalarEvolutionExpander.cpp
lib/Analysis/ValueTracking.cpp
lib/AsmParser/LLLexer.cpp
lib/AsmParser/LLParser.cpp
lib/AsmParser/LLParser.h
lib/AsmParser/LLToken.h
lib/Bitcode/Reader/BitcodeReader.cpp
lib/Bitcode/Writer/BitcodeWriter.cpp
lib/CodeGen/AsmPrinter/WinException.cpp
lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
lib/CodeGen/TargetLoweringBase.cpp
lib/CodeGen/WinEHPrepare.cpp
lib/IR/AsmWriter.cpp
lib/IR/Dominators.cpp
lib/IR/Instruction.cpp
lib/IR/Instructions.cpp
lib/IR/Verifier.cpp
lib/Target/X86/X86WinEHState.cpp
lib/Transforms/Instrumentation/MemorySanitizer.cpp
lib/Transforms/Scalar/Reassociate.cpp
lib/Transforms/Scalar/SCCP.cpp
lib/Transforms/Scalar/Sink.cpp
lib/Transforms/Utils/CodeExtractor.cpp
lib/Transforms/Utils/InlineFunction.cpp
lib/Transforms/Utils/LCSSA.cpp
lib/Transforms/Utils/Local.cpp
lib/Transforms/Utils/SimplifyCFG.cpp
test/Assembler/invalid-OperatorConstraint.ll [deleted file]
test/Bitcode/compatibility.ll
test/CodeGen/WinEH/wineh-cloning.ll
test/CodeGen/WinEH/wineh-coreclr.ll [deleted file]
test/CodeGen/WinEH/wineh-demotion.ll
test/CodeGen/WinEH/wineh-exceptionpointer.ll [deleted file]
test/CodeGen/WinEH/wineh-intrinsics.ll
test/CodeGen/WinEH/wineh-multi-parent-cloning.ll [deleted file]
test/CodeGen/WinEH/wineh-no-demotion.ll
test/CodeGen/WinEH/wineh-statenumbering-cleanups.ll
test/CodeGen/WinEH/wineh-statenumbering.ll
test/CodeGen/X86/branchfolding-catchpads.ll
test/CodeGen/X86/catchpad-realign-savexmm.ll
test/CodeGen/X86/catchpad-regmask.ll
test/CodeGen/X86/catchpad-weight.ll
test/CodeGen/X86/catchret-empty-fallthrough.ll
test/CodeGen/X86/catchret-fallthrough.ll
test/CodeGen/X86/cleanuppad-inalloca.ll
test/CodeGen/X86/cleanuppad-large-codemodel.ll
test/CodeGen/X86/cleanuppad-realign.ll
test/CodeGen/X86/funclet-layout.ll
test/CodeGen/X86/late-address-taken.ll
test/CodeGen/X86/seh-catch-all-win32.ll
test/CodeGen/X86/seh-catch-all.ll
test/CodeGen/X86/seh-catchpad.ll
test/CodeGen/X86/seh-except-finally.ll
test/CodeGen/X86/seh-exception-code.ll
test/CodeGen/X86/seh-finally.ll
test/CodeGen/X86/seh-safe-div-win32.ll
test/CodeGen/X86/seh-safe-div.ll
test/CodeGen/X86/seh-stack-realign.ll
test/CodeGen/X86/tail-dup-catchret.ll
test/CodeGen/X86/tail-merge-wineh.ll
test/CodeGen/X86/win-catchpad-csrs.ll
test/CodeGen/X86/win-catchpad-nested-cxx.ll [new file with mode: 0644]
test/CodeGen/X86/win-catchpad-nested.ll
test/CodeGen/X86/win-catchpad-varargs.ll
test/CodeGen/X86/win-catchpad.ll
test/CodeGen/X86/win-cleanuppad.ll
test/CodeGen/X86/win-funclet-cfi.ll
test/CodeGen/X86/win-mixed-ehpersonality.ll
test/CodeGen/X86/win32-eh-states.ll
test/CodeGen/X86/win32-eh.ll
test/CodeGen/X86/win32-seh-catchpad-realign.ll
test/CodeGen/X86/win32-seh-catchpad.ll
test/CodeGen/X86/win32-seh-cleanupendpad.ll [deleted file]
test/CodeGen/X86/win32-seh-nested-finally.ll [new file with mode: 0644]
test/CodeGen/X86/wineh-coreclr.ll [new file with mode: 0644]
test/CodeGen/X86/wineh-exceptionpointer.ll [new file with mode: 0644]
test/Feature/exception.ll
test/Transforms/CodeGenPrepare/catchpad-phi-cast.ll
test/Transforms/GVN/funclet.ll
test/Transforms/GVN/pre-load.ll
test/Transforms/Inline/PR25155.ll
test/Transforms/InstCombine/token.ll
test/Transforms/LoopStrengthReduce/funclet.ll
test/Transforms/LoopStrengthReduce/pr25541.ll
test/Transforms/LoopUnswitch/cleanuppad.ll [new file with mode: 0644]
test/Transforms/SimplifyCFG/empty-cleanuppad.ll
test/Transforms/SimplifyCFG/wineh-unreachable.ll
test/Transforms/Sink/catchswitch.ll [new file with mode: 0644]
test/Verifier/invalid-eh.ll [new file with mode: 0644]
tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp