Commit Graph

83 Commits

Author SHA1 Message Date
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
Andrew Trick
250bb973bb Add an array optimization pass that hoists make_mutable calls.
This gives us a 10x speedup on -Ofast memset, which was the original
goal. We're now within 2x of C, but the C code produces movdqu instead
of movups for twice the throughput:
<rdar://problem/17722727> Memset at -Ofast is 2x slower than C

-O3 results:
| benchmark     | baserun0 |  optrun0 |   delta | speedup |
| Memset        | 39885.00 | 33978.00 | 5907.00 |   17.4% |
| NBody         |   459.00 |   440.00 |   19.00 |    4.3% |
| QuickSort     |   456.00 |   439.00 |   17.00 |    3.9% |
| StringWalk    |   625.00 |   647.00 |   22.00 |   -3.4% |
| SmallPT       |   557.00 |   575.00 |   18.00 |   -3.1% |
| Phonebook     |  1804.00 |  1862.00 |   58.00 |   -3.1% |

Memset, NBody, and Quicksort are the ones we expected to improve.

We don't get much gain on O3 because retains/release and bounds checks
are still there.
<rdar://problem/17719220> QuickSort -O3 has retains/releases in the inner loop.

Given the Ofast results, I think the small degradations at O3 are noise.

-Ofast results:
| benchmark     | baserun0 |  optrun0 |   delta | speedup |
| Memset        |  5453.00 |   452.00 | 5001.00 | 1106.4% |
| NBody         |   772.00 |   437.00 |  335.00 |   76.7% |
| Walsh         |  1530.00 |  1096.00 |  434.00 |   39.6% |
| QuickSort     |   682.00 |   524.00 |  158.00 |   30.2% |
| Phonebook     |  1453.00 |  1561.00 |  108.00 |   -6.9% |
| Hash          |   993.00 |   958.00 |   35.00 |    3.7% |
| StringWalk    |   458.00 |   446.00 |   12.00 |    2.7% |
| StringBuilder |  1603.00 |  1568.00 |   35.00 |    2.2% |

Swift SVN r20145
2014-07-18 06:52:17 +00:00
Mark Lacey
e348535c3c Small clean-up - use hasArchetype() directly in the optimizer.
In a few places we were calling into a function that just returned
T->hasArchetype(). This just changes those places to test it directly.

Swift SVN r19427
2014-07-01 20:02:21 +00:00
Mark Lacey
c7d3c3cd01 Rename and move a function that checks for unbound generics.
In the short term this will also be used to determine if we can inline
generic functions.

Swift SVN r18972
2014-06-18 02:51:23 +00:00
Manman Ren
c2f32d7e24 [Inliner] revert r17101 since it causes a performance regression on MD5.
See rdar://16676020 for details.
r17101 tries to solve r16761933 by checking non-direct recursions in
the call graph. We are in discussion of solving it in a different way.

Todo: figure out why r17101 causes a preformance regression.


Swift SVN r17265
2014-05-02 19:00:36 +00:00
Nadav Rotem
e406e43060 Disable the inlining of non-direct recursions (where A->B->A).
Swift SVN r17101
2014-04-30 18:45:13 +00:00
Dmitri Hrybenko
77bf99656b Fix -Wdocumentation warnings
Swift SVN r16406
2014-04-16 07:52:19 +00:00
Michael Gottesman
78d7d2874e [constant-propagation] Remove from the delete list if we deleted them in recursivelyDeleteTriviallyDeadInstructions.
Also make the constant propagation test not dependent on the stdlib.

Swift SVN r16387
2014-04-16 01:19:26 +00:00
Michael Gottesman
f1899e185e Change hasUnboundGenericTypes to accept a CanType argument.
We are already only passing CanType arguments and really should only be dealing
with CanTypes at the SIL level.

Swift SVN r15699
2014-03-31 22:57:02 +00:00
Mark Lacey
66d779966b Move escape helper functions back to AllocBoxToStack.cpp.
These are only being used by that transform at this time, so it makes
sense to have them together.

Swift SVN r15606
2014-03-29 05:53:51 +00:00
Mark Lacey
22ed644333 More groundwork for further improvements to box-to-stack promotion.
Drill down into partial_apply to examine how the container pointer is
used within the partial_apply. If the uses are not unexpected, and do
not allow the container pointer to escape the partial_apply, then we'll
check how the partial_apply is used when passed into an apply by
drilling down one level into that apply (but no further). If the
partial_apply itself cannot escape the current function or any funtion
it is passed to, then we should be able to clone the partial_apply body
and rewrite it to remove the box container pointer (coming in a future
commit).

This is all effectively disabled now by passing false to the call to
canValueEscape in findUnexpectedBoxUse which disables drilling down into
the apply.

Swift SVN r15591
2014-03-28 23:42:54 +00:00
Nadav Rotem
eea8015957 fix a typo
Swift SVN r15457
2014-03-25 16:26:58 +00:00
Nadav Rotem
6359cf0a35 Refactor hasUnboundGenericTypes. NFC.
Swift SVN r15381
2014-03-23 06:49:54 +00:00
Mark Lacey
b6442dde4e Remove unused code in box-to-stack promotion.
r15322 reworked the logic for determining where the final releases are,
which means that we no longer need to collect the uses and releases as
we evaluate candidates for promotion.

Swift SVN r15333
2014-03-21 20:26:43 +00:00
Nadav Rotem
5752bff1a5 Refactor the code that checks if a box is captured and move it to Local.{h,cpp}. NFC.
Swift SVN r14924
2014-03-11 18:24:58 +00:00
Andrew Trick
04b2b5256b First implementation of <rdar://15922760> Deep devirtualization -
specialize on polymorphic arguments.

This can be enabled with: -sil-devirt-threshold 500.

It currently improves RC4 (when enabled) by 20%, but will be much more
important after Michael's load elimination with alias analysis lands.

This implementation is suitable for experimentation. Superficial code
reviews are also welcome. Although be warned that the design is overly
complex and I plan to rewrite it. I initially abandoned the idea of
incrementally specializing one function at a time, thinking that we
need to analyze full chains. However, I since realized after talking
to Nadav that the incremental approach can be made to work. A lot of
book-keeping will go away with that change.

TODO:

- Resolve protocol argument types. Currently we assume they can be
  reinitialized at applies, but I don't think they can unless they are
  @inouts.  This is an issue with the existing local devirtualizer
  that prevents it working across calls.

- Properly mangle the specialized methods. Find existing
  specializations by demangling rather than maintaining a map.

- Rewrite the logic for specializing chains for simplicity.

- Enable by default.

Swift SVN r13642
2014-02-07 19:10:27 +00:00
Nadav Rotem
93b5cac34e Remove the top-down call graph ABI and use the reverse bottom-up.
Swift SVN r13544
2014-02-06 01:52:14 +00:00
Nadav Rotem
59796c6921 Add topDownCallGraphOrder to utils/local.
Swift SVN r13491
2014-02-05 18:49:54 +00:00
Michael Gottesman
ebf12a9b9c Recommit r13291 with proper tests, etc.
Swift SVN r13304
2014-02-01 21:00:07 +00:00
Michael Gottesman
934e0756db Revert "[sil-code-motion] Read none builtins can not cause reads or writes. Don't let them disrupt load/store forwarding."
This reverts commit r13291. Had a thinko here.

Swift SVN r13303
2014-02-01 19:20:41 +00:00
Michael Gottesman
3fa7c641b1 [sil-code-motion] Read none builtins can not cause reads or writes. Don't let them disrupt load/store forwarding.
Swift SVN r13291
2014-02-01 05:51:19 +00:00
Michael Gottesman
e148a5f2a2 [sil-arc-opts] Expose isSideEffectFree in Local.h.
I am going to use it in the ARC optimizer for ascertaining whether or not
builtins cause side effects.

Swift SVN r12177
2014-01-11 00:58:42 +00:00
Nadav Rotem
4360ca00ff Rename function
Swift SVN r11668
2013-12-27 07:55:49 +00:00
Nadav Rotem
a9f9440544 Move the call-graph utility to Utils/Local
Swift SVN r11665
2013-12-27 04:54:56 +00:00
Nadav Rotem
d0c96e4eeb Implement a very very basic SIL Mem2Reg pass that promotes write-only and single-basicblock allocas.
This pass removes 1/4 of the allocas in the standard library.



Swift SVN r11189
2013-12-12 17:42:50 +00:00
Stephen Lin
d9340ccf86 MandatoryInlinning: Clean up arguments that end up being unused after inlining, such at metatype parameters to some standard library functions. Resolves <rdar://problem/15218643>.
Swift SVN r10431
2013-11-13 21:06:14 +00:00
Stephen Lin
8c1e44a7a7 Revert "Add helper function that will be necessary for recursively removing a group of instructions without dangling pointer issues."
This reverts commit 3d6ec9885426b668450578303e9fc55c4a399ffc. The new function signature is not needed after all, as far as I can currently tell.

Swift SVN r10393
2013-11-13 00:18:41 +00:00
Stephen Lin
60cf42b38a Add helper function that will be necessary for recursively removing a group of instructions without dangling pointer issues.
Swift SVN r10376
2013-11-12 19:07:57 +00:00
Chris Lattner
2e6aedd913 Define an entrypoint for an "instsimplify" analog, which only does
one trivial transform right now.  No clients yet.



Swift SVN r9856
2013-10-31 22:46:27 +00:00
Michael Gottesman
bdf7cbe178 [sil-combine] Initial SILCombine implementation.
This pass is a port of InstCombine from LLVM to SIL. Thus if you are familiar
with the code from InstCombine you will feel right at home.

Keep in mind that in order to help with review, this is just a skeleton with no
optimizations in it besides a simple DCE based off of isInstructionTriviallyDead
(which this patch exposes in Local.h like LLVM does) to ensure that trivial
testing of the pass can be accomplished since otherwise it would do nothing
implying that no tests could be written at all.

I additionally modified one test which no longer passed due to SILCombine
removing 1x unused metatype instruction from the standard library.

Swift SVN r9404
2013-10-16 03:10:14 +00:00
Anna Zaks
a19d7569cc Introduce Builtin.staticReport, which allows compiler diagnostic reporting.
- Introduces the Builtin
- If the first parameter evaluates to '1', the dataflow diagnostics pass produces a diagnostic.
- The Builtin gets cleaned up before IRGen, but not before SIL serialization.

This patch also removes the current, overflow warning and XFAILs one of the tests. The other test is switched to use Builtin.staticReport.

TODO:
 - Utilize the other parameters to the builtin - the Message and IsError flag.
 - Use this Builtin within the stdlib.

Swift SVN r8939
2013-10-05 00:12:23 +00:00
Michael Gottesman
22aef6c015 Change swift/SILPasses/Utils/Local.h to have a C++ mode declaration.
Swift SVN r8720
2013-09-27 05:23:59 +00:00
Anna Zaks
be6feaa82c [SIL] Fixup commit r7248.
I forgot to add in the new files!

Swift SVN r7251
2013-08-15 01:21:57 +00:00