Commit Graph

130 Commits

Author SHA1 Message Date
Joe Groff
45eec9a2e9 Remove 'interface' from the method names of SILFunctionType.
SILFunctionTypes are always interface types now. NFC.

Swift SVN r19952
2014-07-14 22:03:46 +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
Arnold Schwaighofer
b8283915cf Clarify that the issue is not in the devirtualizer
Swift SVN r19139
2014-06-24 20:33:00 +00:00
Arnold Schwaighofer
00e1e0c6cb Devirtualizer: work around partially implemented feature in the type system
We fail devirtualizing a specialized protocol method because the number (1) of
substitutions obtained from looking in the witness table does not match up with
the number (2) of substitutions expected by the function signature substitution
code.

As a workaround until the type code is fixed, check for this condition and bail.

rdar://17399536

Swift SVN r19137
2014-06-24 20:09:27 +00:00
Nadav Rotem
50b2d0e73d Rename early binding -> inline caches.
Swift SVN r19063
2014-06-21 05:06:37 +00:00
John McCall
385879beea Remove the CheckedCastKind from SIL dynamic casts.
It is straightforward and less redundant to recover this
information from the operand types.

Swift SVN r19056
2014-06-20 22:43:53 +00:00
Nadav Rotem
fdd774d380 Devirt: No need to sink/clone the class_method instruction.
Swift SVN r18949
2014-06-17 05:57:17 +00:00
Nadav Rotem
062124810e Do not try to devirtualize the call if the class instance is type-casted.
rdar://17333697.



Swift SVN r18948
2014-06-17 05:36:03 +00:00
Nadav Rotem
cf6fdb13a4 The correct devirtualization check needs to be isVolatile and not isForeign.
Swift SVN r18877
2014-06-13 19:15:00 +00:00
Nadav Rotem
79f901290a Early Binding: don't try to devirtualize objc classes.
Swift SVN r18869
2014-06-13 17:09:37 +00:00
Nadav Rotem
96f37fdd4d When performing specialization of virtual calls try to sink the retain into the diamond shaped CFG. This will ensure that the ARC optimizer will get a chance to remove the calling convention overhead after inlining.
Swift SVN r18864
2014-06-13 08:58:41 +00:00
Nadav Rotem
5d063f0061 Add an early binding pass for accelerating virtual method dispatch.
Dynamic languages are able to implement inline caches for virtual calls, but swift is statically compiled, so we have to guess the types at compile time. The early binding pass guesses that types at the bottom of the class hierarchy are not subclassed and emits direct calls to these passes. It converts class_method calls into the following code:

if (Instance is of time Foo) {
	Foo::ping()
} else {
	Instance->ping();
}

The check if an instance is of a specific type is inexpensive, it is simply a load+icmp sequence. 

Swift SVN r18860
2014-06-13 06:33:01 +00:00
Michael Gottesman
54ac7cb7bb [devirtualizer] Fix issues where the position of Self in arguments/substitutions were confused.
I added some helpers to ApplyInst that should hopefully linguistically eliminate
the issue by allowing users of the API to not need to remember that the self
substitution is first, but the self argument is last.

We should really just remove the dichotomy. But that is for after WWDC.

I also disabled devirtualization of inherited protocol conformances for
protocol_methods. This will be less likely to be used than specialized
protocol conformances protocol_method devirtualization (which is
currently).

<rdar://problem/16951124>

Swift SVN r18282
2014-05-17 23:15:55 +00:00
Michael Gottesman
eeea4caae0 [devirtualizer] Handle covariant return types correctly.
Also add a test to make sure we handle contravariant args correctly as
well (which we already do).

Swift SVN r17595
2014-05-07 01:19:37 +00:00
Michael Gottesman
bb8738ea91 [devirtualization] Fix up devirtualization of witness methods. Re-enable devirtualization of specialized witness methods.
Swift SVN r17585
2014-05-06 23:44:11 +00:00
Mark Lacey
baf731271b Remove unused header from devirtualizer.
Swift SVN r17580
2014-05-06 22:58:37 +00:00
Michael Gottesman
e76601b302 Fix 80+ violations. NFC.
Swift SVN r17570
2014-05-06 22:19:18 +00:00
Michael Gottesman
2a8068705e [devirtualization] Remove unneeded SILDevirtualization class and perform a bunch of cleanups. NFC.
Swift SVN r17569
2014-05-06 22:17:36 +00:00
Michael Gottesman
195e49e26f [devirtualization] Simplify how we iterate over functions in the module.
Swift SVN r17567
2014-05-06 22:08:31 +00:00
Michael Gottesman
45ca455c1c [devirtualization] Simplify/refactor optimizeClassMethod.
The only case which we were handling in the old code where the class
method was not dead was when we had an apply inst of the class method.

This commit simplifies all of the weird code therein by causing class
method optimization to go through the same optimization pathway as how
we optimize protocol methods and witness methods (i.e. we pattern match
on the apply and only replace the apply).

This makes the code much simpler and more readable.

Additionally while working on test cases I noticed that relying on
SILCombine to peephole convert_function creates phase ordering issues
since SILCombine does not cause additional optimizer iterations to run
implying that we can have a situation where we devirtualize, fail to
inline, then silcombine (which would allow us to optimize), but then
the pass manager does not go around another time. Thus I move that
operation into the devirtualizer itself since it is relatively simple to
do.

Also re-enable test/SILPasses/devirt_override.sil since we handle it
correctly now.

Swift SVN r17566
2014-05-06 22:08:31 +00:00
Michael Gottesman
ffe31fa64e [devirtualization] Verbose names => less verbose names.
Swift SVN r17565
2014-05-06 22:08:29 +00:00
Michael Gottesman
e79cd702c2 Reapply "Revert "[devirtualization] Re-enable devirtualization of pure inherited protocol conformances with a new refactored implementation and a better test.""
Now that the external vs linkonce_odr witness table issue has been
sorted out.

Swift SVN r17424
2014-05-05 04:21:25 +00:00
Michael Gottesman
e02b6074ae Revert "[devirtualization] Re-enable devirtualization of pure inherited protocol conformances with a new refactored implementation and a better test."
Revert "[devirtualization] Begin refactor devirtualization code into first simple cases and then the general case."

This reverts commit r17288.
This reverts commit r17287.

To unblock the submission.

Swift SVN r17310
2014-05-03 05:55:26 +00:00
Michael Gottesman
1f93ec5480 [devirtualization] Remove deep devirtualization code that we are not using for WWDC.
If we decide in the future to do this we can always revert this commit.

Swift SVN r17293
2014-05-03 00:33:46 +00:00
Michael Gottesman
29fd6880bf [devirtualization] Re-enable devirtualization of pure inherited protocol conformances with a new refactored implementation and a better test.
Swift SVN r17288
2014-05-02 23:21:41 +00:00
Michael Gottesman
843a59213b [devirtualization] Begin refactor devirtualization code into first simple cases and then the general case.
This in general should make the code far more readable and
understandable.

I am going to re-enable the inherited/specialized devirtualization in
subsequent commits.

Swift SVN r17287
2014-05-02 23:21:41 +00:00
Michael Gottesman
0f8733867b [deserialization] Change the return value of findFuncInWitnessTable to match the
ordering of SILWitnessTable, ArrayRef<Substitution> in lookUpWitnessTable.

Swift SVN r17266
2014-05-02 19:15:41 +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
Michael Gottesman
5dbfb3ab7f [devirtualization] Return the witness table when looking up SILFunctions from a witness table.
This is important since it enables one to analyze the type of the
conformance that the witness table implements which may be different
than the original type. This follows the precedent where we return the
Substitutions from the protocol conformance tree traversal.

Swift SVN r17220
2014-05-02 01:43:31 +00:00
Michael Gottesman
f92f212ec9 [devirtualization] Change optimizeApplyOfWitnessMethod to use SILModule::findFuncInWitnessTable.
Swift SVN r17135
2014-05-01 02:42:00 +00:00
Michael Gottesman
c9baa6d739 [devirtualization] Extract the method SILModule::lookUpSILFunctionFromVTable from optimizeClassMethodInst. NFC.
Swift SVN r17133
2014-05-01 02:08:57 +00:00
Michael Gottesman
e907b6515c [devirtualization] Refactor optimizeClassMethodInst so that the main while loop is smaller and we handle the success case outside of the for loop.
This IMHO makes the function much easier to read and understand.

Swift SVN r17131
2014-05-01 01:28:24 +00:00
Michael Gottesman
5449d6f673 [devirtualizer] Refactor findFuncInWitnessTable -> SILModule::findFuncInWitnessTable.
Swift SVN r17130
2014-05-01 01:06:06 +00:00
Michael Gottesman
9311c0c575 [devirtualization] Refactor the large method optimizeApplyInst into two smaller methods, optimizeApplyOfWitnessMethod and optimizeApplyOfProtocolMethod. NFC.
Swift SVN r17123
2014-04-30 23:53:17 +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
0c53a3505a [devirtualization] When making sure devirt types match up if the
conformance is specialized, the function we are attempting to substitute
will have a generic self type. Make sure to substitute in substitutions
from the origin type (if it has them) before attempting to perform the
comparison inbetween the self pointer on the target function of the
devirtualization from the alloc_ref of the self pointer on the CMI.

Swift SVN r16909
2014-04-27 02:47:47 +00:00
Michael Gottesman
e2cde3c7f4 [devirtualization] Properly substitute in types for upcast when handling
a specialized inherited conformance.

Swift SVN r16900
2014-04-27 00:06:46 +00:00
Michael Gottesman
e8f981ab6c [devirtualization] Teach the devirtualizer how to handle specialized protocol conformances.
Now we can devirtualize conformances like the following:

protocol P {
  func doSomething()
}

struct X { }

struct B<T> : P {
  func doSomething() { ... }
}

func whatShouldIDo(p : P) {
  p.doSomething()
}

var b = B<X>()
whatShouldIDo(b)

rdar://16638833

Swift SVN r16874
2014-04-26 06:51:00 +00:00
Manman Ren
9ba7def130 [Devirtualizer] trace across unchecked_ref_cast in findOrigin.
We will trace across unchecked_ref_cast to find the class origin in
devirtualizer. This enables us to devirtualize class_method where the
operand needs to go across unchecked_ref_cast to reach the origin.


Swift SVN r16857
2014-04-26 00:02:33 +00:00
Manman Ren
480b41c824 [SIL Vtable emission] use the least derived method in sil_vtable.
Given base class A and dervied class B, both with member functions f(),
to look for A.f in B's vtable, we should return SILFunction for B.f.

Before this commit, B's vtable will have entry for B.f, A's vtable will
have entry for A.f. When looking for A.f in B's vtable, it returns null.
And devirtualizer will look for A.f in A's vtable and resolve it to
SILFunction for A.f.

When replacing a class_method %1 : $A, #A.f!1 with a function ref to B.f,
we will have type checking issues for the apply instructions. So devirtualizer
will replace the argument of the apply instructions when necessary.

rdar://16681983


Swift SVN r16854
2014-04-25 23:42:12 +00:00
Michael Gottesman
0c0958b2e5 [devirtualization] Change devirtualization of protocol_method to use SILModule::lookUpWitnessTable instead of iterating over the witness tables itself.
This cleans up the code and also allows devirtualization to cause
deserialization of witness table declarations.

<rdar://problem/16646818>

Swift SVN r16741
2014-04-24 03:37:34 +00:00
Michael Gottesman
545054592f [devirtualization] Clean up debug statements in devirtualizer to be more readable.
Swift SVN r16738
2014-04-24 03:37:30 +00:00
Andrew Trick
f58ebbc251 Add a global_init attribute to SILFunction.
The implied semantics are:
- side-effects can occur any time before the first invocation.
- all calls to the same global_init function have the same side-effects.
- any operation that may observe the initializer's side-effects must be
  preceded by a call to the initializer.

This is currently true if the function is an addressor that was lazily
generated from a global variable access. Note that the initialization
function itself does not need this attribute. It is private and only
called within the addressor.

Swift SVN r16683
2014-04-23 01:09:47 +00:00
Michael Gottesman
83cf951609 [devirtualization] Teach devirtualization how to devirtualize inherited conformances.
Previously if we had an inherited conformance, we would not put in an
upcast from the subtype to the parent when we called the devirtualized
protocol method.

Swift SVN r16644
2014-04-22 04:45:08 +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
Adrian Prantl
47bf136af5 More assertion cleanups. Thanks, Joe!
Swift SVN r15842
2014-04-02 23:06:13 +00:00
Adrian Prantl
5385d4e7a7 Clean up a slightly wrong assertion.
<rdar://problem/16499612> assert building Foundation with SWIFT_ASSERTS=NO

Swift SVN r15840
2014-04-02 22:54:35 +00:00
Chris Lattner
afea47b621 rename "destroy_value" to "release_value", part of rdar://15889208.
Swift SVN r15777
2014-04-02 05:33:52 +00:00
John McCall
f1180f5e6d in order to work correctly for non-@objc protocols.
Language features like erasing concrete metatype
values are also left for the future.  Still, baby steps.

The singleton ordinary metatype for existential types
is still potentially useful; we allow it to be written
as P.Protocol.

I've been somewhat cavalier in making code accept
AnyMetatypeType instead of a more specific type, and
it's likely that a number of these places can and
should be more restrictive.
When T is an existential type, parse T.Type as an
ExistentialMetatypeType instead of a MetatypeType.

An existential metatype is the formal type
 \exists t:P . (t.Type)
whereas the ordinary metatype is the formal type
 (\exists t:P . t).Type
which is singleton.  Our inability to express that
difference was leading to an ever-increasing cascade
of hacks where information is shadily passed behind
the scenes in order to make various operations with
static members of protocols work correctly.

This patch takes the first step towards fixing that
by splitting out existential metatypes and giving
them a pointer representation.  Eventually, we will
need them to be able to carry protocol witness tables

Swift SVN r15716
2014-04-01 00:38:28 +00:00
Michael Gottesman
6946e86d0e [deserialization] Enable deserialization of VTables by default.
Swift SVN r15635
2014-03-29 21:58:55 +00:00