Commit Graph

209 Commits

Author SHA1 Message Date
Mark Lacey
60261a74f0 Fix typo.
Swift SVN r21902
2014-09-12 07:51:12 +00:00
Manman Ren
3932a2439c [Devirtualizer] remove a hack that disables devirtualizing via specialized
conformance.

Revert r19137 and keep the testing case. Commit a fix that combines
substitutions from the specialized protocol conformance and substitutions from
the ApplyInst; then uses the full substitution list in substGenericArgs.

I had a small SIL testing case that runs "sil-opt -devirtualize", but due to
rdar://18120894, the testing case failed to work.

rdar://17440222

Performance -----
Before:
Totals,54,114129,114129,114129,0,0 (O)
Totals,54,81957,81957,81957,0,0 (Ounchecked)
Totals,54,83157,83157,83157,0,0 (run 2 of Ounchecked)

After:
Totals,54,109847,109847,109847,0,0 (O)
Totals,54,80301,80301,80301,0,0 (Ounchecked)


Swift SVN r21442
2014-08-25 18:33:26 +00:00
Manman Ren
31303ce50a NFC: remove unused codes.
Swift SVN r21439
2014-08-25 16:25:43 +00:00
Nadav Rotem
e858faf991 Rename method. NFC.
Swift SVN r21394
2014-08-22 00:19:56 +00:00
Mark Lacey
feae9cc517 Remove include of CallGraph.h since it is not needed.
Swift SVN r21392
2014-08-22 00:00:03 +00:00
Nadav Rotem
54458fb892 Enable access control based devirtualization.
Patch (mostly) by Jordan Rose.

rdar://17890078. 



Swift SVN r21139
2014-08-12 00:43:18 +00:00
Nadav Rotem
822f72c5d5 Revert "Devirtualize class methods based on access control."
There are still correctness problems when inlining across files.



Swift SVN r21032
2014-08-05 00:42:38 +00:00
Nadav Rotem
0499d24be2 Simplify the loop that finds the class member using getDeclaredTypeInContext. NFC.
Swift SVN r21031
2014-08-05 00:38:21 +00:00
Nadav Rotem
c66f460266 Devirtualize class methods based on access control.
Swift SVN r21030
2014-08-04 23:58:30 +00:00
Nadav Rotem
1fd257773d Refactor parts of the Devirtualizer. Rename methods and move the method
that seaches for point-of-construction for classes outside of the function that
does the devirtualization. Now we have a utility that devirtualizes a class
given a ClassDecl. NFC.



Swift SVN r20946
2014-08-02 05:33:16 +00:00
Nadav Rotem
5eebe943bc Fix a copy-and-paste mistake. Give the pass a real name. NFC.
Swift SVN r20945
2014-08-02 04:10:59 +00:00
Nadav Rotem
2ce50db8a8 When inserting an inline cache sink the class_method instruction next to its only use.
I did not observe and performance difference with this change.



Swift SVN r20914
2014-08-01 21:29:56 +00:00
Nadav Rotem
685bb84c15 Minor cleanup. NFC.
Swift SVN r20851
2014-07-31 21:22:17 +00:00
Nadav Rotem
1b980052b1 Cache the class hierarchy construction.
Before this commit we scanned the vtables every time we wanted to know who are the subclasses of a class. Now we scan the vtables just once.



Swift SVN r20847
2014-07-31 21:07:11 +00:00
Nadav Rotem
5d2627eff8 Document a function and cleanup debug message. NFC.
Swift SVN r20761
2014-07-30 16:30:40 +00:00
Nadav Rotem
4833d8351b PIC: Fix a bug in the cache size threshold and fix the docs. Thanks Greg.
Swift SVN r20746
2014-07-30 08:54:00 +00:00
Nadav Rotem
230547f71a PIC: when sinking the StrongRetain instruction use the bit-casted class reference.
This allows the ARC optimizer to remove the retain-release pair after inlining.



Swift SVN r20744
2014-07-30 08:44:13 +00:00
Nadav Rotem
0cb8bf0ab8 Implement polymorphic inline caches.
Swift SVN r20740
2014-07-30 07:43:47 +00:00
Nadav Rotem
d85414e90d Split the function into two smaller functions. NFC.
Swift SVN r20722
2014-07-29 23:40:36 +00:00
Nadav Rotem
0a248aa8b2 Rename method. NFC.
Swift SVN r20719
2014-07-29 23:25:33 +00:00
Nadav Rotem
e2f243b349 Add stats. NFC.
Swift SVN r20715
2014-07-29 23:20:08 +00:00
Nadav Rotem
4ccfdb6f89 Disable monomorphic inline caches for classes that are not at the bottom of the hierarchy. <2% improvments on DeltaBlue.
Swift SVN r20713
2014-07-29 23:07:22 +00:00
Nadav Rotem
cb1dc81308 Revert accidental commit.
Swift SVN r20711
2014-07-29 23:05:05 +00:00
Nadav Rotem
7faa5883df Add a basic Class Hierarchy Analysis. At this point it only lists classes that are inherited from in this module.
Swift SVN r20710
2014-07-29 23:01:01 +00:00
Michael Gottesman
02cb9bed86 [devirt] Disable devirt of inherited protocol conformances for Seed 5.
Devirtualization of inherited protocol conformances are not essential
for stdlib performance since in most cases the stdlib does not use class
types (in contrast to devirtualization of specialized protocol
conformances which /is/ essential). So for Seed 5 I am disabling this
for the reasons below:

We are not upcasting metatypes correctly and while debugging that I ran
into a case where in the protocol witness we had generic types as if
the protocol witness was potentially covariant in all arguments. This
caused the devirtualizer to subtitute in the witness type as
appropriate, but due to the covariant argument the devirtualizer did not
perform an upcast causing a verifier fail.

<rdar://problem/17823711>

Swift SVN r20612
2014-07-28 03:42:51 +00:00
Joe Groff
623aba1786 Encapsulate Substitution's state.
Expose Substitution's archetype, replacement, and conformances only through getters so we can actually assert invariants about them. To start, require  replacement types to be materializable in order to catch cases where the type-checker tries to bind type variables to lvalue or inout types, and require the conformance array to match the number of protocol conformances required by the archetype. This exposes some latent bugs in the test suite I've marked as failures for now:

- test/Constraints/overload.swift was quietly suffering from <rdar://problem/17507421>, but we didn't notice because we never tried to codegen it.
- test/SIL/Parser/array_roundtrip.swift doesn't correctly roundtrip substitutions, which I filed as <rdar://problem/17781140>.

Swift SVN r20418
2014-07-23 18:00:38 +00:00
Dmitri Hrybenko
d14f17beef Change 'getLogicValue()' into a property 'boolValue'; change
'getArrayBoundValue()' into a property 'arrayBoundValue'.

rdar://17156123


Swift SVN r20304
2014-07-22 12:08:10 +00:00
Dmitri Hrybenko
26277fc41d Demangler: remove StringRef dependencies in the demangler interface and
PrettyStackTrace dependencies in the implementation


Swift SVN r20248
2014-07-21 12:46:58 +00:00
Michael Gottesman
e8d4ec401b Fix some unused variable warnings during -DNDEBUG build due to variables only being used in asserts.
Swift SVN r19988
2014-07-15 22:12:51 +00:00
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