Commit Graph

2295 Commits

Author SHA1 Message Date
Mark Lacey
8296a43356 It is not useful to link in the main inliner loop.
We never have anything but definitions in the call graph, so we can just
assert that.

Swift SVN r27311
2015-04-15 04:31:56 +00:00
Mark Lacey
02724cbb8f Minor renaming.
Replace CallSites with Applies.

Swift SVN r27308
2015-04-15 03:08:08 +00:00
Arnold Schwaighofer
48b6588bbb Teach DCE about ThrowInst and TryApplyInst
Part of rdar://20543286

Swift SVN r27302
2015-04-15 00:43:02 +00:00
Erik Eckstein
03d393ef5c Re-apply r27206: Convert all external function definitions to declarations when compiling with -Onone.
... with disabled test 1_stdlib/Bit.swift for ios.

Most likely the problem of 1_stdlib/Bit.swift (only on armv7) is just uncovered by this change.
Unfortunately I have no possibility to debug the problem on a device. Therefore I filed rdar://problem/20521110




Swift SVN r27274
2015-04-14 07:38:28 +00:00
Joe Groff
c0a2994564 AST: Start printing function types with @convention instead of old attributes.
And update tests to match.

Swift SVN r27262
2015-04-13 22:51:34 +00:00
Joe Groff
b03795e5f7 Add a '@convention(xxx)' attribute for specifying function conventions.
This is new attribute we're using to coalesce @thin, @objc_block, and @cc, and to extend to new uses like C function pointer types. Parse the new attribute, but preserve support for the old attributes, and print with the old attributes for now to separate out test changes. Migration fixits and test updates to come. I did take the opportunity here to kill off the '@cc(cdecl)' hack for AST-level function pointer types, which are now only spelt with @convention(c).

Swift SVN r27247
2015-04-13 04:27:02 +00:00
Michael Gottesman
75ea31dba9 Turn on +0 self by default.
The only caveat is that:

1. We do not properly recognize when we have a let binding and we
perform a guaranteed dynamic call. In such a case, we add an extra
retain, release pair around the call. In order to get that case I will
need to refactor some code in Callee. I want to make this change, but
not at the expense of getting the rest of this work in.

2. Some of the protocol witness thunks generated have unnecessary
retains or releases in a similar manner.

But this is a good first step.

I am going to send a large follow up email with all of the relevant results, so
I can let the bots chew on this a little bit.

rdar://19933044

Swift SVN r27241
2015-04-12 22:23:37 +00:00
Greg Parker
a42837bee2 Revert r27206.
This broke test 1_stdlib/Bit.swift on armv7.


Swift SVN r27236
2015-04-11 07:28:41 +00:00
Erik Eckstein
4e6efcb617 Fix a DEBUG log message in ExternalFunctionDefinitionsElimination.
Now the function name is printed before the function is deleted.



Swift SVN r27207
2015-04-10 11:27:48 +00:00
Erik Eckstein
c3b253d305 Convert all external function definitions to declarations when compiling with -Onone.
This avoids that an unoptimized imported function is linked instead the optimized version from the stdlib.
rdar://problem/20485253

It gives considerable performance improvmenets for some benchmarks with -Onone. E.g.
PopFrontUnsafePointer: +281%
ArrayOfPOD: +92%
StrComplexWalk: +91%
ArrayOfGenericPOD: +61%
Several others are within the range of +10% to +30%.

For the implementation I added runSILPassesForOnone() in Passes.cpp.
Here we can add other optimizations for -Onone in the future.



Swift SVN r27206
2015-04-10 09:53:17 +00:00
Erik Eckstein
9d28b2abca Don't convert shared_external function definitions to declarations in ExternalDefsToDecls.
This produced illegal SIL.
Also, just invalidate those functions which are converted.



Swift SVN r27205
2015-04-10 09:43:00 +00:00
Erik Eckstein
ab2dd51bb0 SIL passmanager: Add an option -sil-disable-pass for disabling passes by name.
Example: swiftc -O -Xllvm -sil-disable-pass="Performance Inliner" test.swift
All passes are disabled which contain the option argument string in their name.

This is useful for testing and debugging.



Swift SVN r27204
2015-04-10 09:39:30 +00:00
Roman Levenstein
d1698ba1cb Use a _bridgeable suffix for newly introduced fast bridging functions. NFC.
Dave explained that stdlib usually uses the suffix notation in such cases. This change follows his advice.

Swift SVN r27177
2015-04-09 20:59:42 +00:00
Roman Levenstein
39ad4c996b Fix a spelling error. Calleee -> Callee. NFC.
Swift SVN r27173
2015-04-09 18:16:04 +00:00
Roman Levenstein
cd08e967f9 [sil-devirtualizer] Better handling of methods that have their own generic parameters.
Fixed the logic in getSubstitutionsForSuperclass and renamed it into getSubstitutionsForCalleee to better reflect what it does.

rdar://20440616

Swift SVN r27166
2015-04-09 15:28:49 +00:00
Roman Levenstein
57c41a0e00 [sil-devirtualizer] If class contains archetypes, consider it unbound.
We should not try to devirtualize in such cases yet.

Swift SVN r27165
2015-04-09 15:28:48 +00:00
Roman Levenstein
90e5f932c7 Simplify the lookup of a compiler-known library function. NFC.
Swift SVN r27157
2015-04-09 02:35:27 +00:00
Roman Levenstein
7c5717d3ad Address Joe's comments on my r27102 commit. NFC.
Swift SVN r27154
2015-04-09 01:51:59 +00:00
Mark Lacey
ed66cfd544 Use a callback in the linker to notify clients of newly deserialized functions.
Previous attempts to update the callgraph explicitly after calls to
linkFunction() weren't completely effective because we can deserialize
deeply and introduce multiple new function bodies in the process.

This gets us a bit closer, but only adds new call graph nodes. It does
not currently add edges for everything that gets deserialized (and this
is not fatal, so it is a step forward).

Swift SVN r27120
2015-04-08 06:46:15 +00:00
Roman Levenstein
2dd38eee0e [sil-combine] Teach the optimizer how to optimize bridged casts.
If a conformance to _BridgedToObjectiveC is statically known, generate a more efficient code by using the newly introduced library functions for bridging casts.
This covers the casts resulting from SIL optimizations.

Tests are included. I tried to cover most typical casts from ObjC types into Swift types and vice versa and to check that we always generate something more efficient than a checked_cast or unconditional_checked_cast. But probably even more tests should be written or generated by means of gyb files to make sure that nothing important is missing.

The plan is to make the bridged casts SIL optimization a guaranteed optimization. Once it is done, there is no need to lower the bridged casts in a special way inside Sema, because they all can be handled by the optimizer in a uniform way. This would apply to bridging of Error types too.

With this change, no run-time conformance checks are performed at run-time if conformances are statically known at compile-time.
As a result, the performance of rdar://19081345 is improved by about 15%. In the past, conformance checks in this test took 50% of its execution time, then after some improvements 15% and now it is 0%, as it should be.

Swift SVN r27102
2015-04-07 22:53:57 +00:00
Mark Lacey
0c4249293a Update the call graph with newly linked-in functions.
We claim to maintain the call graph in these passes, so we really need
to add nodes for new functions we pull in.

Also, link in functions when building the call graph, and only allow
functions with bodies to be added to the call graph.

This makes the call graph more consistent.

At some point we need to revisit our linking story because we've got
code spread out over several phases now where it might make sense to do
a single up-front linking pass that potentially pulls in
never-referenced functions (e.g. pull in all foo() that could be reached
in a given class hierarchy up front, even if in reality only C.foo() is
ever called).

Swift SVN r27096
2015-04-07 22:29:52 +00:00
Joe Groff
ad0d20c07a Fold "AbstractCC" into SILFunctionType::Representation.
These aren't really orthogonal concerns--you'll never have a @thick @cc(objc_method), or an @objc_block @cc(witness_method)--and we have gross decision trees all over the codebase that try to hopscotch between the subset of combinations that make sense. Stop the madness by eliminating AbstractCC and folding its states into SILFunctionTypeRepresentation. This cleans up a ton of code across the compiler.

I couldn't quite eliminate AbstractCC's information from AST function types, since SIL type lowering transiently created AnyFunctionTypes with AbstractCCs set, even though these never occur at the source level. To accommodate type lowering, allow AnyFunctionType::ExtInfo to carry a SILFunctionTypeRepresentation, and arrange for the overlapping representations to share raw values.

In order to avoid disturbing test output, AST and SILFunctionTypes are still printed and parsed using the existing @thin/@thick/@objc_block and @cc() attributes, which is kind of gross, but lets me stage in the real source-breaking change separately.

Swift SVN r27095
2015-04-07 21:59:39 +00:00
Mark Lacey
cd6d1488e8 Use SmallVector consistently across the call graph.
Swift SVN r27073
2015-04-07 07:27:06 +00:00
Mark Lacey
37fc0c2622 Fix an issue with call graph maintainence in closure specializer.
The code was previously adding a call graph node for every apply we
rewrote, rather than only adding call graph nodes when we actually
create a new specialization.

This causes an assert in the stdlib build, but only with other local
changes I have.

Swift SVN r27062
2015-04-07 05:49:39 +00:00
Chris Lattner
fc0fb4e34b Reject let/else blocks when the 'else' falls through.
Swift SVN r27058
2015-04-07 03:54:00 +00:00
Mark Lacey
fd6ccb9b52 Bail from cost computation as soon as we know we'll return false.
Swift SVN r27034
2015-04-06 06:27:15 +00:00
Mark Lacey
d0233db99d Unindent and improve interface to helper function.
Swift SVN r27033
2015-04-06 06:27:14 +00:00
Mark Lacey
6c86c523a2 Move call graph maintenance logic out of main inlining logic.
Swift SVN r27032
2015-04-06 06:27:13 +00:00
Mark Lacey
fc4c83c984 Unindent a level.
Swift SVN r27031
2015-04-06 06:27:12 +00:00
Mark Lacey
18f7a5be7a Replace a condition with an assert.
This makes it easier to continue to simplify this code, and it should be
reasonable to maintain this invariant in the future.

Swift SVN r27030
2015-04-06 06:27:11 +00:00
Mark Lacey
bea04a3514 Delete FIXME for something that was fixed in r27024.
Swift SVN r27028
2015-04-06 04:25:09 +00:00
Mark Lacey
fea3321f59 Update the generic specializer to maintain the call graph.
Swift SVN r27024
2015-04-05 19:27:40 +00:00
Joe Groff
4821f594bb SIL: Separate SILFunctionType::Representation and ExtInfo from AST FunctionTypes.
The set of attributes that make sense at the AST level is increasingly divergent from those at the SIL level, so it doesn't really make sense for these to be the same. It'll also help prevent us from accidental unwanted propagation of attributes from the AST to SIL, which has caused bugs in the past. For staging purposes, start off with SILFunctionType's versions exactly the same as the FunctionType versions, which necessitates some ugly glue code but minimizes the potential disruption.

Swift SVN r27022
2015-04-05 17:04:55 +00:00
Mark Lacey
5adf76b4dd Missed one comment update.
Swift SVN r27019
2015-04-05 07:14:45 +00:00
Mark Lacey
8fad304e02 Fix a leak.
swift::clearBlockBody() in Local.cpp was popping instructions rather
than erasing them, resulting in leaking any instructions removed via
this function (which is reached via removeDeadBlock(), called throughout
SimplifyCFG).

Also tweak a couple comments and remove an assert that cannot fire.

Swift SVN r27018
2015-04-05 07:12:35 +00:00
Mark Lacey
95ed2af172 Update comment to reflect recent updates.
Swift SVN r27014
2015-04-05 05:07:17 +00:00
Mark Lacey
a57bfed2d1 Lock invalidations of the call graph during COWArrayOpt.
We already preserve the call graph, so we should not allow it to be
invalidated.

Swift SVN r27012
2015-04-05 04:53:47 +00:00
Mark Lacey
3572f1bc20 Maintain the call graph in the closure specializer.
Swift SVN r27009
2015-04-05 04:30:10 +00:00
Mark Lacey
bad8678f89 Add CallGraphEditor helper class and use it in the inliner.
Swift SVN r27008
2015-04-05 04:30:08 +00:00
Mark Lacey
217966eefd Maintain the call graph during inlining.
Swift SVN r26998
2015-04-05 02:27:58 +00:00
Mark Lacey
730ef41385 Make devirtualizer clients remove old applies.
This makes it feasible for clients to maintain the call graph.

Swift SVN r26997
2015-04-05 02:27:57 +00:00
Chris Lattner
95b7b4d5e4 rename CleanupLocation::getCleanupLocation -> CleanupLocation::get, NFC.
Swift SVN r26994
2015-04-04 22:56:01 +00:00
Michael Gottesman
faabb7ea8a [spec-devirt] Hoist releases right after the apply on self into the diamond.
rdar://20335275

Swift SVN r26985
2015-04-04 20:14:47 +00:00
Arnold Schwaighofer
c0fedecfd8 SimplifyCFG: Only recompute the dom tree on change
Swift SVN r26981
2015-04-04 15:42:47 +00:00
Arnold Schwaighofer
5bd9b4a6d6 SimplifyCFG: sprinkle some verification on top
Verify the dominator tree at strategic points to make sure we don't regress this in the future

Swift SVN r26980
2015-04-04 15:42:46 +00:00
Arnold Schwaighofer
ecd6ed9d3a SimplifyCFG: Fix dominatorBaseSimplify
Separate it into two phases: one that simplifies based on the domtree and one
that changes the CFG. Recompute the domtree in between.

Don't process unreachable blocks created by checked cast jump threading. The
dominator tree update in checked cast jump threading is buggy - recalclate the
dominator tree for now.

I measured no changes in performance and a +0.1-0.2% change in compile time of
'ninja -j1 swift-stdlib'.

rdar://20404463

Swift SVN r26979
2015-04-04 15:42:46 +00:00
Arnold Schwaighofer
e7e6e69c20 SimplifyCFG: Don't simplify an instruction without a use in propagateSwitchEnumCondition
Swift SVN r26978
2015-04-04 15:42:45 +00:00
Arnold Schwaighofer
e5e116b262 SimplifyCFG: simplifySwitchEnumToSelectEnum changes the CFG
Recompute (post)dominators.

Swift SVN r26977
2015-04-04 15:42:44 +00:00
Arnold Schwaighofer
d9e381f6e1 SimplifyCFG: Add a method to clear the worklist
To be used by a follow up commit.

Swift SVN r26976
2015-04-04 15:42:44 +00:00
Arnold Schwaighofer
4904072297 SimplifyCFG: propagateSwitchEnumCondition should not change the CFG
It is called from dominatorBasedSimplify which relies on a correct dominator
tree. Instead when we know the branch target of a switch_enum because of a
dominating switch_enum on the same operand change the dominated switch_enum to
use a enum instruction of the known enum case.

Disable some tests that now fail. They will be enabled again in follow up
commits.

Swift SVN r26975
2015-04-04 15:42:43 +00:00