Commit Graph

32 Commits

Author SHA1 Message Date
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
Nadav Rotem
baa1d1679a Teach some of the passes about the new PM.
Swift SVN r13494
2014-02-05 18:58:23 +00:00
Nadav Rotem
5310265dba Devirtualize archetype_method of polymorphic functions.
Patch by Joe.



Swift SVN r13007
2014-01-27 22:01:20 +00:00
Nadav Rotem
8fa61139ad Remove the old archetype_method devirtualization procedure and implement a new one.
The old devirtualization procedure did not take into account the substitution list in the apply inst.
The new optimization works on the apply instruction that uses the archetype_method instruction.
We do not handle polymorphic types because we don't modify the protocol conformance yet.



Swift SVN r12826
2014-01-23 00:29:44 +00:00
Nadav Rotem
91eff3655d Refactor the duplicated code for finding a static function in the witness table. NFC.
Swift SVN r12601
2014-01-20 18:46:21 +00:00
Nadav Rotem
42c966fc14 Devirtualize archetype_method instructions on non-generic lookup types.
For example, if ABC is not a generic type we can replace this instruction
with a function_ref instruction to a specific function:

archetype_method $ABC, #pingable.ping!1



Swift SVN r12571
2014-01-20 06:22:16 +00:00
Nadav Rotem
3d1d558aac Add debug prints.
Swift SVN r12224
2014-01-13 09:39:35 +00:00
Nadav Rotem
0271c34d77 Devirtualize: teach the class_method devirtualization type-search procedure to look into apply instructions.
In many cases these calls are constructors that were too big to be inlined.

We now devirtualize this code:

class ABC {
 init() { /* Don't inline */ }
 func member() { }
}

func foo() {
  var x = ABC()
  x.member()
}



Swift SVN r12223
2014-01-13 09:32:54 +00:00
Nadav Rotem
32f47906bd Refactor findClassTypeForOperand. NFC.
Swift SVN r12222
2014-01-13 07:56:48 +00:00
Nadav Rotem
970c387c34 Refactor devirt related optimizations from sil-combine into a new pass.
The reason is that I would like to add more sophisticated analysis and a
chache, which does not fit into sil-combine very well.



Swift SVN r12221
2014-01-13 07:34:25 +00:00