Commit Graph

30 Commits

Author SHA1 Message Date
Mark Lacey
1859b476d4 Further integration of inlining, devirtualization, and specialization.
This updates the performance inliner to iterate on inlining in cases
where devirtualization or specialization after the first pass of
inlining expose new opportunities for inlining. Similarly, in some cases
inlining exposes new opportunities for devirtualization, e.g. when we
inline an initializer and can now see an alloc_ref that allows us to
devirtualize some class_methods.

The implementation currently has some inefficiencies which increase the
swift compilation time for the stdlib by around 3% (this is swift-time
only, no LLVM time, so overall time does not grow by this much).

Unfortunately the (unchanged) current implementation of the core
inlining trades off improved estimates of code growth for increased
compile time, and that plays a part in why compile time increases as
much as it does. Despite this, I have some ideas on how to win some of
that time back in future patches.

Performance differences are mixed, and this will likely require some
further inliner tuning to reduce or remove some of the losses seen here
at -O. I will open radars for the losses.

Wins:
DeltaBlue                        10.2%
EditDistance                     13.8%
SwiftStructuresInsertionSort     32.6%
SwiftStructuresStack             34.9%

Losses:
PopFrontArrayGeneric            -12.7%
PrimeNum                        -19.0%
RC4                             -30.7%
Sim2DArray                      -14.6%

There were a handful of wins and losses at Onone and Ounchecked as
well. I'll review the perf testing output and open radars accordingly.

The new test case shows an example of the power of the closer
integration here. We are able to completely devirtualize and inline a
series of class_method applies (10 deep in this case, but in theory
substantially deeper) in a single pass of the inliner, whereas before we
could only do a single level per pass of inlining & devirtualization.

Swift SVN r27561
2015-04-22 04:48:13 +00:00
Mark Lacey
2525fbf682 Allow clients of the SILInliner to specify a callback.
This callback is called on each newly generated instruction that results
from cloning the body of the callee. The intent is to use this to
collect a subset of newly generated instructions,
e.g. ApplyInst/TryApplyInst.

Swift SVN r26843
2015-04-02 02:29:13 +00:00
John McCall
6d8fff9c06 Parsing and basic structure of try_apply. Not yet properly
threaded into IRGen; tests to follow when that's done.

I made a preliminary effort to make the inliner do the
right thing with try_apply, but otherwise tried to avoid
touching the optimizer any more than was required by the
removal of ApplyInstBase.

Swift SVN r26747
2015-03-31 02:41:03 +00:00
Mark Lacey
4eb47f06c9 Remove unused helper function.
Swift SVN r26382
2015-03-21 02:06:14 +00:00
Erik Eckstein
b8ef26a3bd inliner: remove the obsolete CannotBeInlined cost value
Swift SVN r25427
2015-02-20 15:48:08 +00:00
Adrian Prantl
c41b30299f Audit all SILPasses to ensure that new instructions are never created
without a valid SILDebugScope. An assertion in IRGenSIL prevents future
optimizations from regressing in this regard.
Introducing SILBuilderWithScope and SILBuilderwithPostprocess to ease the
transition.

This patch is large, but mostly mechanical.
<rdar://problem/18494573> Swift: Debugger is not stopping at the set breakpoint

Swift SVN r22978
2014-10-28 01:49:11 +00:00
Arnold Schwaighofer
2af40aee89 Revert "Revert "SimplifyCFG: Don't count 'free' instructions during jump-threading""
Reinstantiate rr22712. Now that updating SSA form is more robust we should not
run into troubles anymore.

Original commit message:

"Use the inliner's heuristic to decide which instructions are 'free' (constants,
etc).

We were not jumpthreading a block because it had four instruction in it - two of
them integer_literals."

rdar://18594600

Swift SVN r22761
2014-10-15 17:07:06 +00:00
Arnold Schwaighofer
a536a67d12 Revert "SimplifyCFG: Don't count 'free' instructions during jump-threading"
This reverts commit r22712.

The swift-stdlib-release-asserts-noopt breaks because we can't build SSA form
:(.

Swift SVN r22716
2014-10-14 01:18:51 +00:00
Arnold Schwaighofer
1e06048408 SimplifyCFG: Don't count 'free' instructions during jump-threading
Use the inliner's heuristic to decide which instructions are 'free' (constants,
etc).

We were not jumpthreading a block because it had four instruction in it - two of
them integer_literals.

rdar://18594600

Swift SVN r22712
2014-10-13 22:47:43 +00:00
Adrian Prantl
a3b85b2600 Set the debug scope for transparently inlined instructions to the scope of
the inlined call site. Also fix a bunch of typos in the related testcase.

rdar://problem/17648201

Swift SVN r20861
2014-07-31 23:40:40 +00:00
Mark Lacey
a7556c89f9 Enable transparent inlining of some generic functions.
Fixes part of <rdar://problem/16196801>.

Inline generic functions, but only when:

- There are no unbound archetypes being substituted (due to various
  assumptions in TypeSubstCloner about having all concrete types).

- When no substitution is an existential (due to
  <rdar://problem/17431105>, <rdar://problem/17544901>, and
  <rdar://problem/17714025>).

This gets things limping along, but we really need to fix the above
limitations so that mandatory inlining never fails.

This doesn't enable inlining generics in the performance inliner. There
is no reason it shouldn't work as well, but there is no compelling
reason to do so now and it could have unintended effects on performance.

Some highlights from PreCommitBench -
O0:
            old (ms)   new (ms)  delta (ms)   speedup
ForLoops    1127.00     294.00      833.00     283.3%
LinkedList   828.00     165.00      663.00     401.8%
R17315246    982.00     288.00      694.00     241.0%
SmallPT     3018.00    1388.00     1630.00     117.4%
StringWalk  1276.00      89.00     1187.00    1333.7%
-- most others improve ~10% --

O3:
            old (ms)   new (ms)  delta (ms)   speedup
Ackermann   4138.00    3724.00      414.00      11.1%
Life          59.00      64.00        5.00      -7.8%
Phonebook   2103.00    1815.00      288.00      15.9%
R17315246    430.00     582.00      152.00     -26.1%
StringWalk  1173.00    1097.00       76.00       6.9%

Ofast:
            old (ms)   new (ms)  delta (ms)   speedup
Ackermann   3505.00    3715.00      210.00      -5.7%
Life          49.00      41.00        8.00      19.5%
Memset       684.00     554.00      130.00      23.5%
Phonebook   2166.00    1769.00      397.00      22.4%
StringWalk   829.00     790.00       39.00       4.9%

I've opened the following to track remaining issues that need to be
fixed before we can inline all transparent function applications:
<rdar://problem/17431105>
<rdar://problem/17544901>
<rdar://problem/17714025>
<rdar://problem/17768777>
<rdar://problem/17768931>
<rdar://problem/17769717>

Swift SVN r20378
2014-07-23 06:29:23 +00:00
Adrian Prantl
b1a7a7af1b Reference-count inlined functions to keep them alive until we emit debug
info for them and generally clean up the inline scope handling a bit.
Fix the debug scope handling for all clients of SILCloner, especially
the SIL-level spezializers and inliners.
This also adds a ton of additional assertions that will ensure that
future optimization passes won't mess with the debug info in a way that
could confuse the LLVM backend.

Swift SVN r18984
2014-06-18 22:34:10 +00:00
Adrian Prantl
17e3604b43 Make sure all non-inlining uses of SILCloner also clone the SILDebugScope
hierarchy. I still need to figure out a reliable way to write testcases
for this. For now it's ensured via an assertion in SILCloner::postprocess.

Swift SVN r18917
2014-06-15 20:50:49 +00:00
Mark Lacey
0707cf2573 Remove visitSILBasicBlock from SILInliner.
Instead, fall back on the version in SILCloner, which is identical
except the SILCLoner version properly remaps types when cloning generic
code.

Swift SVN r18905
2014-06-15 06:40:41 +00:00
Adrian Prantl
23bf30e732 Add a testcase for inline scopes and fix the locations emitted for
performance-inlined insrtructions.

Swift SVN r18849
2014-06-13 00:37:49 +00:00
Bob Wilson
2df66cf8c4 Implement inline scopes for the performance inliner.
Mandatory-inlined (aka transparent functions) are still treated as if they
had the location and scope of the call site. <rdar://problem/14845844>
Support inline scopes once we have an optimizing SIL-based inliner

Patch by Adrian Prantl.

Swift SVN r18835
2014-06-12 19:48:43 +00:00
Mark Lacey
1e87d7aab2 Minor clean-up of inliner code.
Don't pass substitutions as an argument since they are always going to
be from the apply we're passing in.

Swift SVN r18672
2014-05-30 20:24:48 +00:00
Mark Lacey
9cda4d5f69 Small clean-up of SILInliner.
The primary change is that it now takes an ApplyInst rather than an
iterator.

Swift SVN r16910
2014-04-27 03:38:22 +00:00
Andrew Trick
3dbaf8f499 Expose getFunctionCost() so it can be used by other SIL passes.
(devirtualization)

Swift SVN r13641
2014-02-07 19:10:25 +00:00
Chris Lattner
79cbdc5c32 Teach the performance inliner that debug_value[_addr] are free.
Teach the mandatory inliner to drop debug_value[_addr] instructions
when inlining.  Otherwise, we get debug_value's for all of the arguments
splattered all over the place.  We want transparent functions to be
effectively ((nodebug)) in C parlance.


Swift SVN r12404
2014-01-16 16:06:47 +00:00
Michael Gottesman
9de0af9d4a Change SILInliner to let the user specify the type of location (i.e. mandatory or not) that will be used by all the inlined instructions.
Swift SVN r11430
2013-12-18 19:06:23 +00:00
Stephen Lin
0871f8c3d8 SILCloner: change ValueRetTy to void, because it is unused and because an in-development subclass cannot always provide a valid return value of the current type
Swift SVN r8885
2013-10-03 18:36:05 +00:00
Stephen Lin
4ba5de9eff Refactor SILInliner, moving functionality to its base class so that it can be reused for other purposes (e.g. cloning functions, rather than inlining them). No functionality change.
Swift SVN r8851
2013-10-02 19:53:03 +00:00
Joe Groff
82a18333ed SIL: Purge SpecializeInst.
Make ApplyInst and PartialApplyInst directly take substitutions for generic functions instead of trying to stage out substitutions separately. The legacy reasons for doing this are gone.

Swift SVN r8747
2013-09-28 00:15:45 +00:00
Stephen Lin
4b6e14ba5d Clone DebugScope to new instruction when inlining, for Adrian (who will write tests for this)
Swift SVN r8614
2013-09-24 23:56:52 +00:00
Anna Zaks
e7e3c10fec [SIL] Add appropriate SILLocations to the inlined code.
The inlined locations should point to the call site.

Swift SVN r8108
2013-09-11 20:54:31 +00:00
Stephen Lin
62ad1cca30 Take out the hack in SILInliner that is no longer necessary now that [auto_closure] is handled specially in SILGen, and allow MandatoryInlining to see through basic indirection through alloc box instructions in order to inline calls to [auto_closure] arguments. Note that the logic here is conservative; any second store (beyond the initial store in the prologue) or any capture of the alloc box will preventing inlining.
Swift SVN r7912
2013-09-04 21:45:19 +00:00
Stephen Lin
75099b7435 Narrow the rule that ApplyInsts in transparently inlined functions get the [transparent] flag to only apply to ApplyInsts that directly call function arguments, which is enough to handle the intended use case of [auto_closure] arguments to [transparent] functions without virally enforcing inlining more than we want to (or should be, once the phase ordering and incomplete SSA-ification issues are resolved).
Swift SVN r7774
2013-08-30 01:38:00 +00:00
Stephen Lin
3828b616d8 Make transparent inlining apply transparency recursively to all calls and also see through applications of partial applications (in SSA form); this is intended to ensure that [auto_closure] arguments of [transparent] functions get inlined, although that's additionally blocked by (apparent?) incompleteness of SSA-ification passes currently and phase ordering issues.
After implementing this I realized that a lot of the logic currently in MandatoryInlining.cpp should be moved into the SILInliner so it can be reused in an optimizing inliner. I plan on doing that refactoring immediately but decided to go ahead and commit this since it's a working incremental step.

Swift SVN r7771
2013-08-30 00:25:24 +00:00
Stephen Lin
8d90466523 Reorganize SIL source tree: move lib/SIL/SILGen -> lib/SILGen, move lib/SIL/Passes -> lib/SILPasses, add lib/SILPasses/Utils
Swift SVN r7246
2013-08-14 23:47:29 +00:00