JIT: Finally Optimizations
authorAndy Ayers <andya@microsoft.com>
Thu, 1 Dec 2016 02:16:17 +0000 (18:16 -0800)
committerAndy Ayers <andya@microsoft.com>
Wed, 11 Jan 2017 01:13:57 +0000 (17:13 -0800)
commit7fcd45710b6cec37f28848c819e1e2f37f80ccf0
tree446777d6bbc819d613a6bfb08854f954e30ba4c1
parent39617d79f2019a5837dffde95a6100db7990f6fd
JIT: Finally Optimizations

Adds two optimization for try-finallys: empty finally removal and
finally cloning.

Empty finally removal identifies trivially empty finally clauses and
removes the entire try-finally EH region. COde in the try is "promoted"
to be in the parent EH region (or method region). Empty finallys often
appear after inlining empty Dispose methods. Removing a try-finally with
an empty finally both reduces code size and improves code speed.

Finally cloning duplicates the code for the finally and 'inlines' it
along one of the normal exit paths from the try. This improves code
speed in the typical case where there is no exception raised while
the try is active. It generally increases code size slightly. However,
finallys are rare enough that the overall code size increase across
all methods is quite small. The jit will clone most finallys, provided
they are not too large, and are not contained in or contain other EH
constructs. If a try contains multiple exit paths only the final "fall
through" path will be optimized.

These optimizations are enabled for all target architectures. Finally
cloning is currently disabled for desktop CLR because more work is needed
to support thread abort.

More details on both optimizations can be found in the design document
added as part of this commit.

In debug builds, finally cloning can be selectively disabled or enabled
by setting COMPlus_JitEnableFinallyCloning to 0 or 1 respectively. This
config setting can thus be used override the default behavior (cloning
enabled for CoreCLR, disabled otherwise) for diagnostic or testing purposes.

Closes dotnet/coreclr#1505. Closes dotnet/coreclr#8065.

Commit migrated from https://github.com/dotnet/coreclr/commit/f2a2d9e1bd210b463fa929bab786e9b3529853f8
docs/coreclr/botr/clr-abi.md
docs/coreclr/design-docs/finally-optimizations.md [new file with mode: 0644]
src/coreclr/src/jit/block.cpp
src/coreclr/src/jit/block.h
src/coreclr/src/jit/compiler.h
src/coreclr/src/jit/compphases.h
src/coreclr/src/jit/flowgraph.cpp
src/coreclr/src/jit/jitconfigvalues.h
src/coreclr/src/jit/jiteh.cpp
src/coreclr/src/jit/jiteh.h
src/coreclr/src/jit/morph.cpp