Commit Graph

89 Commits

Author SHA1 Message Date
John McCall
fe3a7b0f5e When determining whether we can specialize a generic function,
check whether any of the substitutions are dependent rather
than checking whether the function's substituted type is
dependent.

This can't currently come up for user functions because Swift
doesn't permit type arguments to be given explicitly; hence a
dependent type argument will necessarily appear somewhere in
the substituted signature.  However, it's still possible in
the basic SIL model, and Joe's fix to default argument
initializers was just an obvious example.

Swift SVN r18768
2014-06-10 00:46:32 +00:00
Michael Gottesman
39841c3889 [mangler][specializer] When mangling ExistentialMetatypes or Metatypes, mangle in the representation of the metatype.
rdar://16937175

Swift SVN r18219
2014-05-16 22:28:30 +00:00
Michael Gottesman
d866316e04 [specializer] Teach the specializer how to handle indentity {unconditional_checked_cast,checked_cast_br} super_to_archetype.
This is working under the assumption that every class is in a certain
sense its own super class (or we are allowing it to be so for these
casts).

Swift SVN r18020
2014-05-13 20:15:31 +00:00
Michael Gottesman
0f758c5fad [specializer] Teach the specializer how to handle identity existential->archetype casts.
From discussions with Joe I thought that we were not doing this cast. I
am looking into now if the same thing can happen with super_to_archetype
(i.e. identity cast) is supported.

rdar://16892732

Swift SVN r17988
2014-05-13 01:46:24 +00:00
Joe Pamer
1e5b9116d4 More array casting work:
- Continue adding support for checked downcasts of array types (rdar://problem/16535104)
- Fix non-bridged array conversions post-r17868
- Fix rdar://problem/16773693
- Add tests for NSArray coercions to and from Array<T>

Swift SVN r17957
2014-05-12 20:49:42 +00:00
Michael Gottesman
9b1f4b6517 [specializer] Do not replace generic calls in transparent functions to shared specialized functions.
This eliminates the possibility of references to shared functions
without bodies from being exposed by the mandatory inliner.

This does not affect performance in any manner since after mandatory
inlining, we can always specialize in the function that was just inlined
into.

rdar://16809311

Swift SVN r17803
2014-05-09 21:28:39 +00:00
Michael Gottesman
664c6a0637 Add FIXME to specializer to make it handle type aliases correctly by specializing all self derived types.
Swift SVN r17255
2014-05-02 17:26:30 +00:00
Doug Gregor
3d3ff6811a Add a pile of missing #includes exposed by pruning includes in top-of-tree LLVM.
Swift SVN r17157
2014-05-01 14:26:34 +00:00
Michael Gottesman
621f89d267 [specialization] Teach the specializer how to handle checked_cast_br correctly.
rdar://16490450.

Swift SVN r17013
2014-04-29 05:01:59 +00:00
Michael Gottesman
02bdf346bd [specialization] Teach the specializer how to create specialized
protocol conformances.

Without this we can not look up protocol conformances correctly after
specialization if the devirtualization applies to the relevant
specialized type.

Swift SVN r16873
2014-04-26 06:50:59 +00:00
Michael Gottesman
888f72cbbf [specializer] Teach the specializer how to specialize partial apply insts.
<rdar://problem/16696421>

Swift SVN r16871
2014-04-26 04:39:39 +00:00
Michael Gottesman
c9621406ba [specialization] It is incorrect to call getOpConformance on a conformance we already specialized "by hand".
Swift SVN r16766
2014-04-24 19:41:19 +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
40cbdc31b9 [specialization] Teach the specializer how to specialize existential->archetype and super->archetype unconditional_checked_casts.
<rdar://problem/16490450>

Swift SVN r16350
2014-04-15 01:05:08 +00:00
Michael Gottesman
e74f40e5bb [specialization] Teach the specializer how to specialize unconditional_checked_cast concrete_to_archetype and archetype_to_concrete.
I am handling checked_cast_branch in a later commit due to a SILGen
issue I am running into.

rdar://16490450

Swift SVN r16309
2014-04-14 09:52:18 +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
Nadav Rotem
ff5c3f0825 Fix an obvious typo that I found while debugging somethig else. createdFunc was set to false twice on both sides of the branch.
Swift SVN r16231
2014-04-11 21:57:04 +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
Michael Gottesman
c15862bc1a [specializer] Fix a bug I noticed on inspection. Converted the checked_cast_branch test to a .swift to get around parsing issues that will come up in the next bit of commits.
Swift SVN r15827
2014-04-02 20:46:57 +00:00
Michael Gottesman
2dcc1e7a8e Remove unnecessary Resolver argument from SILType::isSuperclassOf since SILTypes are only used after type checking.
Thanks Joe!

Swift SVN r15759
2014-04-01 22:55:43 +00:00
Michael Gottesman
1e9a6099a2 [specializer] Teach the specializer how to handle unconditional_checked_casts, checked_cast_branches that were originally archetype -> archetype but as a result of specialization are now a different sort of cast or a redundent cast.
I am preparing patches for the other cases, but I think this should unblock
DaveA.

rdar://16490450

Swift SVN r15757
2014-04-01 22:42:20 +00:00
Nadav Rotem
6359cf0a35 Refactor hasUnboundGenericTypes. NFC.
Swift SVN r15381
2014-03-23 06:49:54 +00:00
Michael Gottesman
3ad6f33202 Teach the generic specializer how to create SILWitnessTable declarations if a specialized conformance does not have a witness table.
This also teaches IRGen not to emit WitnessTable declarations. This
causes them to be left as unknown symbols in the resulting executable.

Swift SVN r15361
2014-03-22 05:05:47 +00:00
Michael Gottesman
fbfd9778d4 [deserialization] Teach generic specializer how to link functions.
Swift SVN r15095
2014-03-14 23:46:20 +00:00
Michael Gottesman
13b74af686 [specializer] Do not use the old instructions location when cloning. Instead use getOpLocation.
Swift SVN r15025
2014-03-14 04:35:30 +00:00
Joe Groff
a404b0cd49 Rework Substitution::subst not to depend on the meaningless 'Archetype' field of Substitutions.
Pass in the context generic parameters that correspond to the substitution vector in Substitution::subst. When we build the type substitution map, also collect the conformances from the substitutions into a map we can use to fill in those conformances in substituted substitutions where necessary, without relying on the '.Archetype' field.

Swift SVN r14964
2014-03-12 20:29:46 +00:00
Michael Gottesman
f1c9127a89 [serializer] Add some debug messages to the deserializer.
Swift SVN r14859
2014-03-10 01:17:18 +00:00
Michael Gottesman
3cc621b188 Remove trailing whitespace. NFC.
Swift SVN r14858
2014-03-10 01:17:17 +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
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
Joe Groff
7b28da3488 SIL: Always substitute SILFunctionTypes using their interface types.
Have SILType::subst and SILFunctionType::subst always visit the interface types of a SILFunctionType. Fix up some problems in the specializer this exposed by having it correctly apply interface type substitutions to the function type of a specialized function and contextualized substitutions to the body.

Swift SVN r13714
2014-02-09 20:23:07 +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
Nadav Rotem
3227f250cc Reindent the block.
Swift SVN r13648
2014-02-07 19:37:37 +00:00
Nadav Rotem
32d31122ff Generic specialize recursive calls.
With this change we are able to specialize generic recursive functions.
There are a few recursive generic functions in our String representation
and in qsort.

This patch accelerates all of the String benchmarks.



Swift SVN r13643
2014-02-07 19:17:30 +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
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
Nadav Rotem
e4cc6fc139 Rename Specializer.cpp to GenericSpecializer.cpp ;
We are about to start specializing calls in the devirtualizer so GenericSpecialzier is a more accurate name.


Swift SVN r13585
2014-02-06 17:41:05 +00:00