Commit Graph

2295 Commits

Author SHA1 Message Date
Erik Eckstein
cda450f8a2 Enable static initializer optimization by default.
Manman implemented this optimization a while ago, but it was not enabled by default.
<rdar://problem/18169093> Eliminate trivial global initializers by replacing them with sil_global constants.




Swift SVN r27685
2015-04-24 06:33:46 +00:00
Mark Lacey
9442ccb0a9 Do not disable mandatory passes when optimize.sil.never is specified.
Swift SVN r27667
2015-04-24 01:45:23 +00:00
Erik Eckstein
87e8fa4c8e SILCombine: Fixed missing strong_release for stores to an eliminated dead array.
rdar://problem/19460043



Swift SVN r27635
2015-04-23 13:52:35 +00:00
Arnold Schwaighofer
9a7d57ac21 COWArrayOpt: Match retain/release that load an array address projection
Recovers the RC4 regression.

rdar://20654877

Swift SVN r27623
2015-04-23 02:08:16 +00:00
Arnold Schwaighofer
4dd60cbb17 COWArrayOpt: Document the usage of the MatchedReleases set.
Swift SVN r27615
2015-04-22 23:58:11 +00:00
Roman Levenstein
212c6e3be2 [sil-devirtualizer] Improve devirtualization of generics classes with dependent types.
radar://20337006

Swift SVN r27608
2015-04-22 22:29:02 +00:00
Mark Lacey
014602d583 Reenable some devirtualization cases disabled in r26152.
In r26152 a crash was fixed that had been introduced by previous
improvements, but as a result of fixing the crash some cases where we
previously devirtualized were disabled with the intent that they would
be reenabled after further refactoring work was completed.

This commit restores that functionality and reenables the tests.

Swift SVN r27575
2015-04-22 08:24:33 +00:00
Mark Lacey
60311dab22 Coding style clean-ups.
Remove else after return, reduce indentation, etc.

Noticed while reviewing code that uses various SILValue::strip*Casts()
functions.

Swift SVN r27574
2015-04-22 08:24:10 +00:00
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
Roman Levenstein
61fd0abd51 [sil-combine] Fix a failure during compilation of Swiftz
rdar://20645583

Swift SVN r27555
2015-04-22 03:15:45 +00:00
Nadav Rotem
9eddbf670c CSE static class_method instructions.
Swift SVN r27539
2015-04-21 23:21:16 +00:00
Nadav Rotem
32211041d2 Rename @semantics -> @_semantics.
Swift SVN r27533
2015-04-21 17:10:06 +00:00
Chris Lattner
42b4a966b0 Introduce a new null_class SIL instruction for forming a null pointer
reference to something of class type.  This is required to model
RebindSelfInConstructorExpr correctly to DI, since in the class case, 
self.init and super.init *take* a value out of class box so that it 
can pass the +1 value without performing an extra retain.  Nothing
else in the compiler uninitializes a DI-controlled memory object
like this, so nothing else needs this.  DI really doesn't like something
going from initialized to uninitialized.

Yes, I feel super-gross about this and am really unhappy about it.  I
may end up reverting this if I can find an alternate solution to this
problem.



Swift SVN r27525
2015-04-21 05:56:55 +00:00
Chris Lattner
ea47d6ec8e remove dead code.
Swift SVN r27515
2015-04-21 03:37:39 +00:00
Roman Levenstein
77580edea5 Re-submit: Enable cast optimizations as a guaranteed optimization.
Fix a few places in diagnose unreachable, which were emitting false diagnostics after enabling this optimization.

This commit does not disable and remove the special-casing for bridging conversions in the CSApply yet. Let's wait a bit and see that everything works properly after my recent cast optimizations changes. If everything is OK, we can remove the code from CSApply.

This time it does not break the Alamofire external project (rdar://20579035).

rdar://20467603

Swift SVN r27513
2015-04-21 00:54:43 +00:00
Roman Levenstein
5bc45d000e [sil-combine] Peephole: inject_enum_addr (addr, val), switch_enum_addr (addr, val: bb1, ...) -> select_enum_addr, switch_value
rdar://20619835

Swift SVN r27492
2015-04-20 20:33:52 +00:00
Roman Levenstein
e488e5ec89 [simplify-cfg] Fold switch_value on a constant argument into an unconditional branch
rdar://20621777

Swift SVN r27491
2015-04-20 20:33:50 +00:00
Nadav Rotem
0f63546369 Rename the semantics tag name from never to sil.never. NFC.
Swift SVN r27486
2015-04-20 17:27:32 +00:00
Nadav Rotem
680c565af5 Refactor the code that checks if a function is marked with noopt semantics. NFC.
Swift SVN r27485
2015-04-20 17:27:31 +00:00
Arnold Schwaighofer
722fa41435 splitEdge: Fix dominator tree update
Swift SVN r27484
2015-04-20 16:53:17 +00:00
Arnold Schwaighofer
77bb96c43c Fix a bug in the dominator update of the array property specializer
Found by running our pipeline with critical edge splitting on.

Swift SVN r27483
2015-04-20 16:53:17 +00:00
Arnold Schwaighofer
7536fc59af SILCombine: Add missing debug scope
Swift SVN r27482
2015-04-20 16:53:16 +00:00
Erik Eckstein
af49ec17d2 Removed unused empty comment lines.
Swift SVN r27478
2015-04-20 07:24:43 +00:00
Mark Lacey
027c328deb The retain and release counts of a partial_apply may be unbalanced.
In hasOnlyRetainReleaseUsers() we both assert that the retain/release
are balanced, as well as do a normal check and bail.

The assert is overzealous since we can legitimately have cases where the
releases are removed due to being unreachable. In this case we should
just do the normal check and bail.

Fixes rdar://problem/20565974.

Swift SVN r27476
2015-04-20 05:11:29 +00:00
Nadav Rotem
926042ff81 Add @semantics("optimize.never") to disable optimizations of a specific function.
This commit adds a flag to disable optimizations on a specific functions. The
primary motivation of this patch is to allow the optimizer developers to reduce
testcasese by disabling optimizations of parts of the code without having to
recompile the compiler or inspect SIL. The annotations  "inline(never)"
and "optimize.none" can go a long way.

The second motivation for this patch is to allow our internal adopters to work
around compiler bugs.

rar://19745484

Usage:

@semantics("optimize.never")
public func miscompile() { ... }

Swift SVN r27475
2015-04-20 05:06:55 +00:00
Chris Lattner
3a58ca60fe improve the location information for the "all members must be initialized before 'return nil'
in a initializer" diagnostic by chasing dataflow information more aggressively.  We now generally
point at the problematic return instead of the init containing it.


Swift SVN r27474
2015-04-20 02:38:46 +00:00
Chris Lattner
17bfa99d89 fix <rdar://problem/20608881> DI miscompiles this testcase into a memory leak
When emiting logic for conditional destruction of a variable, we weren't considering
a delegated init as a store to the variable that needed to be tracked.  This caused us
to miscompile situations like this testcase where the self.init was conditional:

struct X {
  var c : C
  init() { c = C()}
  init?(a : Bool) {
    if a { self.init() }
    return nil
  }
}

This was exposed by other work, but needs to be fixed in any case.



Swift SVN r27471
2015-04-20 00:26:55 +00:00
Andrew Trick
4960d6ce88 Fix a comment type on canZapInstruction.
Swift SVN r27440
2015-04-17 21:15:35 +00:00
Erik Eckstein
665c1b8894 SimplifyCFG: fix wrong jump threading in case of block-args with multiple uses.
This fixes rdar://problem/20565538
(at least part of it).



Swift SVN r27432
2015-04-17 15:26:59 +00:00
Erik Eckstein
115090d6f7 Re-apply r27361: A new SIL pass for static analysis of array properties.
...with a fix for the compiler crash in external projects.
rdar://problem/20579035



Swift SVN r27427
2015-04-17 08:18:29 +00:00
Mark Lacey
0b423c1844 Revert "A new SIL pass for static analysis of array properties."
This reverts commit r27361. It may have broken some of the external
projects we test.

Swift SVN r27426
2015-04-17 06:19:59 +00:00
Mark Lacey
6b3c364738 Revert "Enable cast optimizations as a guaranteed optimization."
This reverts commit r27379. It may have broken some of the external
projects we test.

Swift SVN r27425
2015-04-17 06:19:57 +00:00
John McCall
9f38d8da50 Require a GenericSignature for dependent AbstractionPatterns.
We still don't actually handle these correctly, but at least
we have sensible information for them now.

Also, remember that we're working with canonical generic
signatures in more places.

Swift SVN r27388
2015-04-16 23:27:00 +00:00
Roman Levenstein
7675e614e3 Enable cast optimizations as a guaranteed optimization.
Fix a few places in diagnose unreachable, which were emitting false diagnostics after enabling this optimization.

This commit does not disable and remove the special-casing for bridging conversions in the CSApply yet. Let's wait a bit and see that everything works properly after my recent cast optimizations changes. If everything is OK, we can remove the code from CSApply.

Swift SVN r27379
2015-04-16 20:28:17 +00:00
Roman Levenstein
8152b80f4d Avoid inserting a new instruction twice during cast optimizations.
CastOptimizer handles insertion of new instructions during peepholes on its own. sil-combine should not try to insert them again.

Swift SVN r27378
2015-04-16 20:28:16 +00:00
Roman Levenstein
aa07bc3d90 Lower bridged casts always, when the outcome is not provably failing.
Even when we don't know for sure if a bridged cast would succeed, we still want to lower it to produce a more efficient code that does not performs conformance checks at run-time.

This is useful when performing casts optimizations as a guaranteed optimization.

Swift SVN r27377
2015-04-16 20:28:15 +00:00
Roman Levenstein
0f88c56b23 If a result of unconditional_checked_cast is not used, simply remove the cast.
This is useful when performing casts optimizations as a guaranteed optimization.

Swift SVN r27376
2015-04-16 20:28:15 +00:00
Roman Levenstein
12b1e88d3f Fix a bug in a peephole for checked_cast_addr_br.
It was producing a checked_cast_add_br, which took a metatype inst as it's argument, which is simply wrong, as it is not an address type. SILVerifier was complaining about it. Now we produce an equivalent peephole, but with a correct instruction sequence, which makes SILVerifier happy.

Swift SVN r27375
2015-04-16 20:28:12 +00:00
Roman Levenstein
7fe82963f0 Bail early on casts involving unbound generic types. It is too early to optimize them.
Swift SVN r27374
2015-04-16 20:28:11 +00:00
Roman Levenstein
a8cf05343f Don't try to optimize non-addr types in simplifyCheckedCastAddrBranchInst.
Sometimes, during intermediate optimization steps, the operands of produced checked_cast_addr_br instructions do not actually have address types.
Don't try to optimize further in such cases. Let the optimizer clean-up those instructions.

Swift SVN r27373
2015-04-16 20:28:10 +00:00
Roman Levenstein
782a4120a4 If kind of the instruction was changed by the optimizeCheckedCast*BranchInst, bail.
This avoids segfaults due to de-referencing of a nullptr.

Swift SVN r27372
2015-04-16 20:28:10 +00:00
Roman Levenstein
185e96ce8c Clean-up of retain/release insertion during bridged casts optimizations.
I noticed under Instruments that the bridged casts opts produced a code that was leaking in some cases. Therefore I took the change to re-visit the code and to clean-up the logic for insertion of retains and releases.

Swift SVN r27371
2015-04-16 20:28:09 +00:00
Roman Levenstein
0b6b907a0a Do not produce an intermediate cast between the same ObjC types as it will get eliminated anyways.
When casts optimizations were lowering bridged casts from ObjC to Swift, they were producing internally an intermediate cast from an ObjC type into the expected ObjC type of a bridged cast, before converting this expected ObjC type into a Swift type. In many cases, this resulted in a useless intermediate cast where both types were the same and such a cast would be eliminated afterwards. E.g.

unconditional_checked_cast A to B  // where A is ObjC type and B is a Swift type

was lowered into:

unconditional_checked_cast A to B. _ObjectiveCType // Often useless as A is equal to B. _ObjectiveCType already.
unconditional_checked_cast B._ObjectiveCType to B

This small inefficiency is fixed now. This problem was no observable from outside the optimization pass, it just required additional processing, therefore there is no test-case.

Swift SVN r27370
2015-04-16 20:28:07 +00:00
Erik Eckstein
6cfb3716bf A new SIL pass for static analysis of array properties.
The GlobalPropertyOpt pass performs a static analysis over the whole module.
If it can prove that an array property call (_getArrayPropertyIsNativeNoTypeCheck) always yiels true,
then it replaces the call with a literal-true.

The pass runs on the high-level SIL using the array semantics calls.
Currently it only handles the isNativeNoTypeCheck array property, but in future it might handle additinal properties
(therefore I chose this general name for it).

It gives +24% on DeltaBlue.




Swift SVN r27361
2015-04-16 17:28:14 +00:00
Erik Eckstein
0c5a97ebc5 SimplifyCFG: fix condition equivalence checking in checked-cast jump threading.
It was wrong in case two checked_cast_br have select_enum (with identical enum operands) as conditions.



Swift SVN r27356
2015-04-16 11:37:39 +00:00
Mark Lacey
3e1e90c31b Add a period at the end of a comment.
Swift SVN r27348
2015-04-16 05:19:53 +00:00
Nadav Rotem
e03d09dd79 Fix a bug in the SIL inliner that prevented the inlining of TryApply instructions.
The inliner sil-builder insertion point has to be before the Apply/TryApply inst,
because TryApply instructions are terminators.

Swift SVN r27332
2015-04-15 21:22:56 +00:00
Nadav Rotem
196ee35f2c Teach the Mandatory inliner to handle TryApply instructions.
Swift SVN r27331
2015-04-15 21:22:55 +00:00
Nadav Rotem
1891de29a4 Teach getCalleeFunction to work with FullApplySite, that wraps TryApply and Apply instructions. NFC.
Swift SVN r27329
2015-04-15 21:22:48 +00:00
Mark Lacey
f6ec796780 Integrate generic specialization into the inliner.
During inlining we'll now attempt to first devirtualize and specialize
within the function that we're going to inline into. If we're successful
devirtualizing and inlining, and we'll attempt to inline into the newly
exposed callees first, before inlining into the function we began with.

This does not remove any existing passes of devirtualization or
specialization yet, partially because we don't completely handle all
cases that they handle at this point (e.g. specializing partial
applies).

We do end up specializing deeper into the call graph with this approach
than we did prior to this commit.

I will have some follow-on changes that integrate things further,
allowing us to devirtualize in more cases after inlining into a given
function.

I will also add some directed tests in a future commit.

I tested the stdlib build and this made no difference in build
times. Perhaps after removing other existing phases we'll recapture some
build time.

I'm not seeing reproducible performance differences with this change,
which is not a big surprise at this point. This sets us up for being
able to improve the compilation pipeline in a future release.

Swift SVN r27327
2015-04-15 21:08:51 +00:00