Commit Graph

73 Commits

Author SHA1 Message Date
Xin Tong
f1843d0a20 Wire up the new epilogue retain matcher with FSO
This should have identical behavior as the old epilogue retain matcher.

I do not see performance improvement.

The compilation time does not show up on Instrument either.
2016-08-29 22:12:43 -07:00
Erik Eckstein
959e19d7bc Add an optimization to eliminate a partial_apply if all applied arguments are dead in the applied function.
This consists of 3 parts:
1) Extend CallerAnalysis to also provide information if a function is partially applied
2) A new DeadArgSignatureOpt pass, similar to FunctionSignatureOpts, which just specializes for dead arguments of partially applied functions.
3) Let CapturePropagation eliminate such partial_apply instructions and replace them with a thin_to_thick conversion of the specialized functions.

This optimzation improves benchmarks where static struct or class functions are passed as a closure (e.g. -20% for SortStrings).
Such functions have a additional metatype parameter. We used to create a partial_apply in this case, which allocates a context, etc.
But this is not necessary as the metatype parameter is not used in most cases.

rdar://problem/27513085
2016-08-23 07:32:41 -07:00
Erik Eckstein
f86f0253d1 FunctionSignatureOpts: also specialize externally available functions.
Otherwise we are missing some important opportunities.
No code size degradation observed.
2016-08-23 07:32:41 -07:00
Erik Eckstein
a75a7f25f9 Re-instate: "SILPassManager: After a new function is pushed on the stack don't restart the pipeline on the old function."
This re-instates commit de9622654d

The problem of the infinite loop should be fixed by the previous fix in FunctionSignatureOpts.
In addition this new commit implements a safety check to void such cases, even if buggy optimizations try to keep pushing new functions onto the work list.
2016-08-19 14:04:49 -07:00
Greg Parker
19e0eb8537 Revert "SILPassManager: After a new function is pushed on the stack don't res…" 2016-08-18 14:48:12 -07:00
Erik Eckstein
de9622654d SILPassManager: After a new function is pushed on the stack don't restart the pipeline on the old function.
Instead the pipeline is continued on the old function. This happens when a pass pushes a new, e.g. specialized function, on the function stack.
There is no need to repeat passes which already did run on a function.
It saves a little of compile time and I didn't see any significant impact on code size or performance.
It also simplifies the pass manager.
2016-08-17 11:48:05 -07:00
Erik Eckstein
3581173a61 SIL: add the self-parameter to the list of type-dependent operands if an instruction uses the dynamic-self type.
This establishes a real def-use relation from the self-parameter to any instruction which uses the dynamic-self type.
This is an addition to what was already done for opened archetypes.
The biggest part of this commit is to rename "OpenedArchetypeOperands" to "TypeDependentOperands" as this name is now more appropriate.

Other than that the change includes:
*) type-dependent operands are now printed after a SIL instruction in a comment as "type-defs:" (for debugging)
*) FuncationSignatureOpts doesn't need to explicitly check if a function doesn't bind dynamic self to remove a dead self metadata argument
*) the check if a function binds dynamic self (used in the inliner) is much simpler now
*) also collect type-dependent operands for ApplyInstBase::SubstCalleeType and not only in the substitution list
*) with this SILInstruction::mayHaveOpenedArchetypeOperands (used in CSE) is not needed anymore and removed
*) add type dependent operands to dynamic_method instruction

Regarding the generated code it should be a NFC.
2016-08-12 16:55:27 -07:00
Slava Pestov
ddc51c5917 AST: Implement SE-0102, introducing new semantics for Never alongside @noreturn
No migrator support yet, and the code for @noreturn is still in
place.
2016-07-22 14:56:39 -07:00
Doug Gregor
823c24b355 [SE-0112] Rename ErrorProtocol to Error.
This is bullet (5) of the proposed solution in SE-0112, and the last
major piece to be implemented.
2016-07-12 10:53:52 -07:00
practicalswift
8df3859ce7 [gardening] Fix recently introduced typos. 2016-06-05 11:11:44 +02:00
practicalswift
d7c55418a3 [gardening] Remove unused identifier. 2016-06-01 14:08:51 +02:00
Xin Tong
c758848c92 Share a few createIncrement/createDecrement functions 2016-05-26 12:55:25 -07:00
Xin Tong
db9ee7c614 Fix a memory leak in FSO
Make sure the destructor of the SmallVector in ProjectionTreeNode gets
called when the BumpPtrAllocator is destroy'ed.
2016-05-25 15:08:18 -07:00
Xin Tong
fb3eb0b646 Simplify function signature optimzation.
Several functionalities have been added to FSO over time and the logic has become
muddled.

We were always looking at a static image of the SIL and try to reason about what kind of
function signature related optimizations we can do.

This can easily lead to muddled logic. e.g. we need to consider 2 different function
signature optimizations together instead of independently.

Split 1 single function to do all sorts of different analyses in FSO into several
small transformations, each of which does a specific job. After every analysis, we produce
a new function and eventually we collapse all intermediate thunks to in a single thunk.

With this change, it will be easier to implement function signature optimization as now
we can do them independently now.

Small modifications to the test cases.
2016-05-25 11:12:27 -07:00
Xin Tong
57e2bdb123 Revert "Simplify function signature optimization" 2016-04-25 16:33:17 -07:00
Xin Tong
633ca2e92b Simplify function signature optimzation.
Several functionalities have been added to FSO over time and the logic has become
muddled.

We were always looking at a static image of the SIL and try to reason about what kind of
function signature related optimizations we can do.

This can easily lead to muddled logic. e.g. we need to consider 2 different function
signature optimizations together instead of independently.

Split 1 single function to do all sorts of different analyses in FSO into several
small transformations, each of which does a specific job. After every analysis, we produce
a new function and eventually we collapse all intermediate thunks to in a single thunk.

With this change, it will be easier to implement function signature optimization as now
we can do them independently now.

Minimal modifications to the test cases.
2016-04-25 15:28:51 -07:00
Slava Pestov
2e52338d7c SIL: Rename long form of getOrCreateFunction() to createFunction(), NFC
This made call sites confusing to read because it doesn't actually
check if the function already exists.

Also fix some minor formatting issues. This came up while I was working
on a fix for a bug that turned out to not be a bug.
2016-04-21 17:58:10 -07:00
Xin Tong
d84de12943 Revert "Change FSO explosion heuristic"
This reverts commit fa09c6b71d.

Broke Linux build. And also PR "please benchmark" does not seem to catch it.
2016-04-14 11:05:00 -07:00
Xin Tong
fa09c6b71d Change FSO explosion heuristic
If we can not find the epilogue releases for all the fields with
reference sematics, but we found for some fields. Explode the argument.

I do not see a performance improvement with this change

rdar://25451364
2016-04-13 19:40:53 -07:00
Roman Levenstein
2e77b3990b Add [nonatomic] attribute to all SIL reference counting instructions. 2016-04-06 01:52:43 -07:00
Xin Tong
f95d9b3c92 Change FSO heuristic.
FSO functions that have high potential but does not have caller inside
current module.

The thunk can then be inlined into the module calling the function and
the function would get the benefit of FSO.

The heuristic for selecting such function is
1. Have no indirect caller. This would introduce a thunk.
2. Have potential to give better performance. i.e. function argument can
be O2G.

Regression
TEST                                                    | OLD_MIN | NEW_MIN | DELTA (%) | SPEEDUP
---                                                     | ---     | ---     | ---       | ---
BenchLangCallingCFunction                               | 184     | 211     | +14.7%    | **0.87x**
Calculator                                              | 55      | 59      | +7.3%     | **0.93x**
DeadArray                                               | 687     | 741     | +7.9%     | **0.93x**
MonteCarloPi                                            | 39275   | 41669   | +6.1%     | **0.94x**

Improvement
TEST                                                    | OLD_MIN | NEW_MIN | DELTA (%) | SPEEDUP
---                                                     | ---     | ---     | ---       | ---
LuhnAlgoLazy                                            | 2478    | 2327    | -6.1%     | **1.06x**
OpenClose                                               | 54      | 51      | -5.6%     | **1.06x**
SortLettersInPlace                                      | 1016    | 946     | -6.9%     | **1.07x**
ObjectiveCBridgeFromNSDictionaryAnyObjectToStringForced | 149993  | 139755  | -6.8%     | **1.07x**
Phonebook                                               | 9666    | 8992    | -7.0%     | **1.07x**
ObjectiveCBridgeFromNSDictionaryAnyObjectToString       | 222713  | 206538  | -7.3%     | **1.08x**
LuhnAlgoEager                                           | 2393    | 2226    | -7.0%     | **1.08x**
Dictionary                                              | 1307    | 1196    | -8.5%     | **1.09x**
JSONHelperDeserialize                                   | 3808    | 3492    | -8.3%     | **1.09x**
StdlibSort                                              | 7310    | 4084    | -44.1%    | **1.79x**

I see 0.15% increase in code size for Benchmark_O.

Thanks @gottesmm for suggesting this opportunity.

rdar://25345056
2016-03-29 23:04:36 -07:00
practicalswift
11a8b6c2ba [gardening] Daily cleanup: typos, header formatting. 2016-03-28 09:29:38 +02:00
Xin Tong
5907b8a3e2 Rename FunctionSignatureOptCloner to FunctionSignatureOpts
Eventually, we decided to do this

1. Have the function signature opts (used to be called the cloner to create
the optimized function.
2. Mark the thunk as always_inline
3. Rely on the inliner to inline the thunk to get the benefit of calling optimized
function directly.
2016-03-24 12:50:12 -07:00