Commit Graph

66 Commits

Author SHA1 Message Date
Arnold Schwaighofer
b6f28bede1 ArraySemantics: Teach array semantics about getting the address of an array element
rdar://18517410

Swift SVN r22439
2014-10-01 21:08:22 +00:00
Erik Eckstein
c16c510167 Set SILLinkage according to visibility.
Now the SILLinkage for functions and global variables is according to the swift visibility (private, internal or public).

In addition, the fact whether a function or global variable is considered as fragile, is kept in a separate flag at SIL level.
Previously the linkage was used for this (e.g. no inlining of less visible functions to more visible functions). But it had no effect,
because everything was public anyway.

For now this isFragile-flag is set for public transparent functions and for everything if a module is compiled with -sil-serialize-all,
i.e. for the stdlib.

For details see <rdar://problem/18201785> Set SILLinkage correctly and better handling of fragile functions.

The benefits of this change are:
*) Enable to eliminate unused private and internal functions
*) It should be possible now to use private in the stdlib
*) The symbol linkage is as one would expect (previously almost all symbols were public).

More details:

Specializations from fragile functions (e.g. from the stdlib) now get linkonce_odr,default
linkage instead of linkonce_odr,hidden, i.e. they have public visibility.
The reason is: if such a function is called from another fragile function (in the same module),
then it has to be visible from a third module, in case the fragile caller is inlined but not
the specialized function.

I had to update lots of test files, because many CHECK-LABEL lines include the linkage, which has changed.

The -sil-serialize-all option is now handled at SILGen and not at the Serializer.
This means that test files in sil format which are compiled with -sil-serialize-all
must have the [fragile] attribute set for all functions and globals.

The -disable-access-control option doesn't help anymore if the accessed module is not compiled
with -sil-serialize-all, because the linker will complain about unresolved symbols.

A final note: I tried to consider all the implications of this change, but it's not a low-risk change.
If you have any comments, please let me know.



Swift SVN r22215
2014-09-23 12:33:18 +00:00
Arnold Schwaighofer
813d43415f ArraySemantics: Add wrapper utility for array semantics calls to Local.h
This encapsulates common operations on array semantic calls like identifying
them or hoisting/copying them.

Will be used by follow-up commits. NFC.

Swift SVN r21926
2014-09-12 21:05:22 +00:00
Mark Lacey
feae9cc517 Remove include of CallGraph.h since it is not needed.
Swift SVN r21392
2014-08-22 00:00:03 +00:00
Arnold Schwaighofer
88372515bd Add an isReadNone API for function refs and use it in CSE
This looks for @effects(readnone) on functions. A follow up commit will mark
_swift_isClassOrObjCExistential as readnone allowing us to CSE it.

rdar://17961249

Swift SVN r21285
2014-08-19 18:05:41 +00:00
Andrew Trick
bd299c9b16 Move getSpecializedLinkage into Local.cpp
Swift SVN r21247
2014-08-16 01:12:26 +00:00
Andrew Trick
b86c0dfe5f comment correction
Swift SVN r21246
2014-08-16 01:12:25 +00:00
Mark Lacey
d5a619bbad Small refactoring of call graph code.
This is a first step towards building a better call graph.

Swift SVN r21152
2014-08-12 18:20:21 +00:00
Manman Ren
1bace828d4 Move addArgumentToBranch to Local.h so we can use it in LoadStoreOpt. NFC.
Swift SVN r20726
2014-07-30 00:03:45 +00:00
Joe Groff
623aba1786 Encapsulate Substitution's state.
Expose Substitution's archetype, replacement, and conformances only through getters so we can actually assert invariants about them. To start, require  replacement types to be materializable in order to catch cases where the type-checker tries to bind type variables to lvalue or inout types, and require the conformance array to match the number of protocol conformances required by the archetype. This exposes some latent bugs in the test suite I've marked as failures for now:

- test/Constraints/overload.swift was quietly suffering from <rdar://problem/17507421>, but we didn't notice because we never tried to codegen it.
- test/SIL/Parser/array_roundtrip.swift doesn't correctly roundtrip substitutions, which I filed as <rdar://problem/17781140>.

Swift SVN r20418
2014-07-23 18:00:38 +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
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
Michael Gottesman
1c42e7c1a6 In recursivelyDeleteTriviallyDeadInstructions, call the callback before we mutate the state of the to be deleted instructions.
Previously in the aforementioned function, we drop the operands of the
instruction before we call the callback function.

This means that if, for instance, one was printing out that instruction,
the printer would blow up when it attempts to access the
instruction.

Swift SVN r20003
2014-07-16 04:37:49 +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
John McCall
c266b15293 Cache whether a type involves an archetype in the recursive
type properties.

Swift SVN r18773
2014-06-10 01:41:00 +00:00
Michael Gottesman
858d6a752c [sil-combine] Unused calls to global initializers are dead.
<rdar://problem/17207162>

Swift SVN r18733
2014-06-07 00:37:29 +00:00
Michael Gottesman
eeb9c4a0a3 Reapply r17654 since we are branched for WWDC.
This reverts commit r17875.

Swift SVN r18469
2014-05-20 22:10:03 +00:00
Michael Gottesman
5913edd829 [specializer] Always replace all results of a generic apply with the new specialized apply.
<rdar://problem/16938305>

Swift SVN r18205
2014-05-16 19:33:30 +00:00
Nadav Rotem
40abc887b4 Revert r17654 because of a regression in the phonebook benchmark.
See rdar://16876395.



Swift SVN r17875
2014-05-11 18:14:37 +00:00
Michael Gottesman
d26f235b22 [sil-combine] Eliminate unused unchecked_take_enum_addr_inst.
While they do "write" to memory in terms of invalidating enums, that is
not a required operation, so it is ok to remove it.

rdar://16752890

Swift SVN r17654
2014-05-08 00:02:35 +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
Michael Gottesman
8242060071 Fix formatting issue. NFC.
Swift SVN r16872
2014-04-26 06:50:58 +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
Mark Lacey
1452d24671 Small cleanup: Remove unnecessary calls to getDef(), mostly in dyn_cast<>(...).
Swift SVN r16235
2014-04-11 23:05:16 +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
Mark Lacey
059a8bafcf Update escape helpers with a few more cases.
No observable difference yet, but upcoming changes in the box-to-stack
promotion will require this change.

Swift SVN r15516
2014-03-26 19:28:03 +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
Mark Lacey
4ef321ac55 Future proof some code by replacing hard-coded operand numbers.
Swift SVN r15230
2014-03-19 08:59:44 +00:00
Mark Lacey
43ea4c722b Remove handling of address_to_pointer and pointer_to_address from useCaptured.
As of r15011 these are handled in canValueEscape. NFC.

Swift SVN r15229
2014-03-19 08:59:43 +00:00
Mark Lacey
a6a7dd76f3 In canValueEscape, add apply/partial_apply uses to Users.
Also treat @inout operands of partial_apply as escaping if the
partial_apply itself can escape.

Swift SVN r15228
2014-03-19 08:59:40 +00:00
Mark Lacey
41fc39d2f3 Correctly index into the parameters for partial_apply.
We need to adjust the index by the number of actual arguments used in
the partial apply.

There's no way to test this at this time as the only pass using this is
allocbox-to-stack, and that pass ends up bailing out due to the
ObjectPointer for the box also getting passed to the partial_apply.

No diffs compiling stdlib.

Swift SVN r15183
2014-03-18 05:32:04 +00:00
Mark Lacey
794da899bd A value used by pointer_to_address or address_to_pointer doesn't escape.
...unless of course the result of the instruction does.

Deletes another 20 alloc_box from the standard library (only 113 to go!).

Swift SVN r15011
2014-03-13 22:35:25 +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
4da216c7c7 Add a PassManager analysis that tracks changed/complete functions.
Don't print/verify unless something has changed.
Don't rerun function passes on functions that have not changed.

Swift SVN r13675
2014-02-08 08:20:44 +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
Joe Groff
71379f5bad SILGen: Explicitly mark uninitialized locals with mark_uninitialized, and have DI only consider mark_uninitialized storage.
Have SILGen mark all variables bound from pattern bindings without initializers (and *only* ones without initializers) with mark_uninitialized [var] pseudo instructions. On the DI end, *only* consider mark_uninitialized instructions for DI analysis. This has many benefits:

- DI doesn't waste time analyzing locals that are trivially initialized in the original source code.
- DI doesn't try to mangle canonical SIL that has been inlined from transparent functions, which may have been optimized into a form DI isn't written to understand.

While we're here, fix an issue with DCE where it would try to kill unused MarkUninitialized instructions. Although MarkUninitialized has no side effects, it still is semantically important to raw SIL, and can't be killed.

Chris did most of the work here; I just finished updating tests and fixing bugs.

Swift SVN r13247
2014-01-31 22:50:21 +00:00
Chris Lattner
2063e9b225 Enhance DCE to know that "condfail(false)" is dead.
Enhance constant propagation (a diagnostic pass) to invoke the DCE utility
when producing a condfail(false).

This fixes rdar://15729207.  Before we -emit-sil'd the testcase to:

sil @_TF1t1fFT_Si : $@thin () -> Int64 {
bb0:
  %0 = tuple ()
  %1 = integer_literal $Builtin.Int1, 0           // user: %2
  cond_fail %1 : $Builtin.Int1                    // id: %2
  %3 = integer_literal $Builtin.Int64, 8          // user: %5
  %4 = integer_literal $Builtin.Int1, 0           // user: %6
  %5 = struct $Int64 (%3 : $Builtin.Int64)        // user: %7
  cond_fail %4 : $Builtin.Int1                    // id: %6
  return %5 : $Int64                              // id: %7
}

and now we produce (if you ignore debug_value):

sil @_TF1t1fFT_Si : $@thin () -> Int64 {
bb0:
  %9 = integer_literal $Builtin.Int64, 8          // user: %10
  %10 = struct $Int64 (%9 : $Builtin.Int64)       // user: %11
  return %10 : $Int64                             // id: %11
}




Swift SVN r12490
2014-01-17 18:06:22 +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