Commit Graph

21 Commits

Author SHA1 Message Date
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
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
Michael Gottesman
6ff318b9fa Remove dead code.
Swift SVN r22155
2014-09-21 03:25:27 +00:00
Michael Gottesman
77caabca83 Fix a bug in capture propagation and closure specializer where we were not checking if functions were external declarations.
Swift SVN r22149
2014-09-20 00:25:39 +00:00
Michael Gottesman
79890eeb1a [closure-spec] Do not specialize a closure into a callee passed the closure if the callee takes multiple closures.
The pass does not support this properly and given where we are in the schedule
it makes no sense to each the closure specializer how to do this at this time.

Swift SVN r22130
2014-09-19 14:50:53 +00:00
Michael Gottesman
10b5accfff [closure-spec] Teach closure specialization to not specialize closures with indirect return and re-enable it.
It is possible to teach the closure specializer to handle these cases but given
where we are in the schedule it makes no sense to try to teach the optimizer how
to handle it.

Keep in mind though that we *will* handle the case where the function being
passed the closure has out parameters. This means that generic functions like
reduce will still be able to be specialized if the closure being passed in does
not have generics in it at the AST level. This implies that we will not handle
specialized closures with indirect results either which is unfortunate.

Swift SVN r22126
2014-09-19 13:44:46 +00:00
Michael Gottesman
8d9e358ad4 [closure-spec] Use the signature of the closure's function_ref instead of the
arguments of the closure since if the closure is an external declaration, it
wont have a first BB.

Swift SVN r22114
2014-09-19 02:33:58 +00:00
Michael Gottesman
2e86b69325 [closure-spec] Refactor all logic determining if we should specialize into the gatherCallSites method.
This creates a nice separation in between the analysis and the dynamic part of
the specialization. Thus gatherCallSites only returns call sites that are legal
to specialize.

This makes it easier to track where all of the correctness checks are.

Swift SVN r22049
2014-09-17 22:57:54 +00:00
Michael Gottesman
9957b99a78 [closure-spec] Perform some small cleanups. NFC.
Swift SVN r22047
2014-09-17 22:53:13 +00:00
Michael Gottesman
59992e3e98 [closure-spec] Move closure specialization behind a flag so the test will pass.
Swift SVN r22046
2014-09-17 22:50:19 +00:00
Michael Gottesman
443881679a [closure-spec] Turn off the closure specializer for now. I found additional issues that need to be fixed and I do not want to block the submission while I am fixing them.
Swift SVN r22045
2014-09-17 22:28:03 +00:00
Michael Gottesman
296304b9aa [closure-spec] Teach closure specialization how to handle partial applies with one use.
Also refactor out the gathering of call sites into its own function.

rdar://18143825

Swift SVN r22008
2014-09-17 05:51:53 +00:00
Michael Gottesman
0090ab15d2 [closure-specializer] Use getFunctionCost from SILInliner to determine cost instead of using just the number of instructions.
There are many instructions which do not contribute to the actual size of a
function that getFunctionCost knows to ignore. Thus this is more accurate.

rdar://18143825

Swift SVN r22007
2014-09-17 05:25:12 +00:00
Michael Gottesman
24c138f29c Move SILLoopInfo into swiftSIL from swiftSILAnalysis so that we match the separation in between analysis and IR entities.
This follows the model of dominance info and allows me to create reachability
methods on SILBasicBlock without creating dependencies from swiftSIL to
swiftSILAnalysis.

Swift SVN r21866
2014-09-11 03:03:06 +00:00
Manman Ren
ded2ec05bc [Closure Specializer] fix rdar://18156518
We will specialize when the ApplyInst is on a FunctionRefInst.


Swift SVN r21686
2014-09-03 22:10:53 +00:00
Mark Lacey
9aa7ace51a Move the closure specializer over to using the new call graph.
Swift SVN r21568
2014-08-29 07:22:46 +00:00
Mark Lacey
e515c40af3 Small clean-up in closure specializer.
Swift SVN r21561
2014-08-29 02:58:10 +00:00
Mark Lacey
8d385d4506 Fix 80-column violation.
Swift SVN r21477
2014-08-27 05:56:29 +00:00
Erik Eckstein
99cc7603be Add an @inline(__always) function attribute.
This will let the performance inliner inline a function even if the costs are too high.
This attribute is only a hint to the inliner.
If the inliner has other good reasons not to inline a function,
it will ignore this attribute. For example if it is a recursive function (which is
currently not supported by the inliner).

Note that setting the inline threshold to 0 does disable performance inlining at all and in
this case also the @inline(__always) has no effect.



Swift SVN r21452
2014-08-26 00:56:34 +00:00
Manman Ren
24f14d944f [Closure Specializer] add it to pass manager.
PerfTests -----
Before
Totals,54,93821,93821,93821,0,0
Totals,54,86755,86755,86755,0,0

After
Totals,54,93610,93610,93610,0,0
Totals,54,85780,85780,85780,0,0

We may be able to tune BoostFactor for closure in PerformanceInliner.


Swift SVN r21312
2014-08-20 20:00:40 +00:00
Manman Ren
1f54d024a9 [Closure Specializer] check in a pass to specialize closure.
If we have function A calls function B with a closure C
func A {
  B(...) {
    // closure C
  }
}
and the inliner decides to not inline B into A, it may be beneficial to generate
a specialized version of B to have
func A {
  B_spec_with_C(..., arguments_to_closure_C)
}
 
SILCombine will optimize apply of partial_apply that are both in B_spec_with_C.
Then inliner can inline the closure to B_spec_with_C.

For profitability, we check the relative size of the callee B and the closure C.
We also check hotness of the callsite to B in A and callsites to the closure
inside B. For now, if closure is called inside a loop, we think it is
profitable.

I will add this to the pass manager in a follow-up patch.
rdar://16569736


Swift SVN r21216
2014-08-14 19:45:11 +00:00