Commit Graph

59 Commits

Author SHA1 Message Date
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
Dmitri Hrybenko
4156c938d7 Fix -Wdocumentation warning about @cc not being a valid command name
Swift SVN r15556
2014-03-27 10:08:44 +00:00
Michael Gottesman
3bca84f50b [devirtualization] Refactor optimizeClassMethod to use SILModule::lookUpVTable. Also refactor the method a bit.
Swift SVN r15547
2014-03-27 03:52:01 +00:00
John McCall
e3e040581c Add another missing include for SWIFT_FALLTHROUGH.
Swift SVN r15038
2014-03-14 05:59:45 +00:00
Ted Kremenek
c87ac8167a Use SWIFT_FALLTHROUGH instead of [[clang::fallthrough]].
Swift SVN r15028
2014-03-14 05:15:05 +00:00
Ted Kremenek
39a368f0ec Add [[clang::fallthrough]] in obvious cases to satisfy -Wimplicit-fallthrough.
Swift SVN r15018
2014-03-14 00:34:25 +00:00
Chris Lattner
001c1890e5 put all the SIL*Transform classes in anonymous namespaces, there is
no need for their symbols to be exported out of their implementation
file.


Swift SVN r14714
2014-03-06 01:49:53 +00:00
Doug Gregor
5d8bd84dfa Introduce the SIL instruction alloc_ref_dynamic.
alloc_ref_dynamic allocates an instance of a class type based on the
value in its metatype operand. Start emitting these instructions for
the allocating constructor of a complete object initializer (not yet
tested) and for the allocating constructor synthesized for an imported
Objective-C init method.

Still missing:
  - IRGen still does the same thing as alloc_ref right now. That
  change will follow.
  - There are devirtualization opportunities when we know the value of
  the metatype that would turn an alloc_ref_dynamic into an alloc_ref;
  I'm not planning to do this optimization.



Swift SVN r14560
2014-03-01 21:55:50 +00:00
Joe Groff
88b6efcc43 Rename ArchetypeMethodInst -> WitnessMethodInst more thoroughly.
Swift SVN r14501
2014-02-28 06:41:18 +00:00
Joe Groff
59d2a169f6 SIL: Rename 'archetype_method' to 'witness_method'.
It has been generalized to get a witness out of an arbitrary protocol conformance, not just for archetypes.

Swift SVN r14497
2014-02-28 05:09:11 +00:00
Doug Gregor
2134072285 Split open_existential[_ref] out as their own instructions.
Riding off of project_existential[_ref] was convenient, but the
resuls are used quite differently. Note that open_existential[_ref]
still don't print/parse reasonably yet.



Swift SVN r13878
2014-02-13 23:42:23 +00:00
Joe Groff
404f555221 Devirtualizer: Zap all Self-derived substitutions when devirtualizing an ArchetypeMethodInst.
Including Self in AllArchetypes introduced substitutions for Self's associated types as a side effect, which caused devirtualized witness calls to hold on to stale substitutions that were quietly ignored.

Swift SVN r13713
2014-02-09 20:23:03 +00:00
Andrew Trick
0825258b80 SIL transforms should only invalidate when things change.
-sil-print-all shows a nice readable evolution now.

Oh yeah, and we don't unnecessarilly rerun passes.

Swift SVN r13677
2014-02-08 08:20:45 +00:00
Andrew Trick
731000b4cd Added -sil-print-all and -sil-verify-all options.
Swift SVN r13662
2014-02-07 23:07:11 +00:00
Andrew Trick
04b2b5256b First implementation of <rdar://15922760> Deep devirtualization -
specialize on polymorphic arguments.

This can be enabled with: -sil-devirt-threshold 500.

It currently improves RC4 (when enabled) by 20%, but will be much more
important after Michael's load elimination with alias analysis lands.

This implementation is suitable for experimentation. Superficial code
reviews are also welcome. Although be warned that the design is overly
complex and I plan to rewrite it. I initially abandoned the idea of
incrementally specializing one function at a time, thinking that we
need to analyze full chains. However, I since realized after talking
to Nadav that the incremental approach can be made to work. A lot of
book-keeping will go away with that change.

TODO:

- Resolve protocol argument types. Currently we assume they can be
  reinitialized at applies, but I don't think they can unless they are
  @inouts.  This is an issue with the existing local devirtualizer
  that prevents it working across calls.

- Properly mangle the specialized methods. Find existing
  specializations by demangling rather than maintaining a map.

- Rewrite the logic for specializing chains for simplicity.

- Enable by default.

Swift SVN r13642
2014-02-07 19:10:27 +00:00
Andrew Trick
611173ae4b Factor out a findOrigin helper to peek past casts and returned args.
Swift SVN r13640
2014-02-07 19:10:25 +00:00
Nadav Rotem
27a1a63134 Remove unneeded empty virtual destructors.
Swift SVN r13599
2014-02-06 22:24:33 +00:00
Nadav Rotem
1ef0d157ca PassManager: Inject the function/module into the Transformation.
Now the pass does not need to know about the pass manager. We also don't have
runOnFunction or runOnModule anymore because the trnasformation knows
which module it is processing. The Pass itself knows how to invalidate the
analysis, based on the injected pass manager that is internal to the
transformation.

Now our DCE transformation looks like this:

class DCE : public SILModuleTransform {
  void run() {
    performSILDeadCodeElimination(getModule());
    invalidateAnalysis(SILAnalysis::InvalidationKind::All);
  }
};





Swift SVN r13598
2014-02-06 22:11:21 +00:00
Chris Lattner
827acad533 Various inout improvements:
- purge @inout from comments in the compiler except for places talking about
   the SIL argument convention.
 - change diagnostics to not refer to @inout
 - Change the astprinter to print InoutType without the @, so it doesn't show
   up in diagnostics or in closure argument types in code completion.
 - Implement type parsing support for the new inout syntax (before we just 
   handled patterns).
 - Switch the last couple of uses in the stdlib (in types) to inout.
 - Various testcase updates (more to come).



Swift SVN r13564
2014-02-06 06:22:27 +00:00
Nadav Rotem
99b075c32a Rename SILFunctionTrans -> SILFunctionTransform
Swift SVN r13536
2014-02-06 01:32:10 +00:00
Nadav Rotem
f8c7b54d28 Delete the unused performXXX() functions.
Swift SVN r13531
2014-02-06 00:57:28 +00:00
Michael Gottesman
631f9326ab [PM] Change enum => enum class everywhere in the PM code. Additionally fix some typos.
Swift SVN r13507
2014-02-05 21:25:15 +00:00