Commit Graph

75 Commits

Author SHA1 Message Date
Nadav Rotem
d78b376d07 [passes] Replace the old invalidation lattice with a new invalidation scheme.
The old invalidation lattice was incorrect because changes to control flow could cause changes to the
call graph, so we've decided to change the way passes invalidate analysis.  In the new scheme, the lattice
is replaced with a list of traits that passes preserve or invalidate. The current traits are Calls and Branches.
Now, passes report which traits they preserve, which is the opposite of the previous implementation where
passes needed to report what they invalidate.

Node: I tried to limit the changes in this commit to mechanical changes to ease the review. I will cleanup some
of the code in a following commit.

Swift SVN r26449
2015-03-23 21:18:58 +00:00
Nadav Rotem
285e2e88e1 Change the specialization API to allow specialization of individual calls
and specialization using a call tree.

Swift SVN r25573
2015-02-27 00:32:03 +00:00
Nadav Rotem
690cc050f0 Refactor the generic specialization API. NFC.
Swift SVN r25572
2015-02-27 00:32:01 +00:00
Nadav Rotem
932790b4e9 Refactor the generic specialize into two parts: a utility and a pass.
Swift SVN r25570
2015-02-27 00:31:59 +00:00
Nadav Rotem
f730a306a1 remove a debug flag
Swift SVN r25569
2015-02-27 00:31:59 +00:00
Nadav Rotem
5588b65905 Add API for inspecting a single call. NFC.
Swift SVN r25568
2015-02-27 00:31:51 +00:00
Dmitri Hrybenko
61286f0260 Fix warnings produced by a newer version of Clang
Swift SVN r25257
2015-02-12 23:50:47 +00:00
Erik Eckstein
9dfd349faf Add a new Thunk-flag in SILFunction which specifies that a function is a thunk.
This will have an effect on inlining into thunks.
Currently this flag is set for witness thunks and thunks from function signature optimization.
No change in code generation, yet.



Swift SVN r24998
2015-02-05 16:45:05 +00:00
Michael Gottesman
897325b096 Codebase Gardening. NFC.
1. Eliminate unused variable warnings.
2. Change field names to match capitalization of the rest of the field names in the file.
3. Change method names to match rest of the file.
4. Change get,set method for a field to match the field type.

Swift SVN r24501
2015-01-19 00:34:07 +00:00
Erik Eckstein
14af3a57e8 Enable elimination of dead methods which are in classes of higher visibility.
The underlying problem is that e.g. even if a method is private but its class is public, the method can be referenced from another module - from the vtable of a derived class.
So far we handled this by setting the SILLinkage of such methods according to the visibility of the class. But this prevented dead method elimination.
Now I set the SILLinkage according to the visibility of the method. This enables dead method elimination, but it requires the following:
1) Still set the linkage in llvm so that it can be referenced from outside.
2) If the method is dead and eliminated, create a stub for it (which calls swift_reportMissingMethod).



Swift SVN r23889
2014-12-12 17:35:40 +00:00
Michael Gottesman
4d48d2aaae [mangle] Add initial code for SIL specializations manglings and refactor Generic Specialization mangling code to there from the pass itself.
This is apart of creating the infrastructure for creating special manglings for
all of the passes that we specialize. The main motiviations for this
infrastructure is:

1. Create an easy method with examples on how to create these manglings.
2. Support multiple specializations. This is important once we allow for partial
specialization and can already occur if we perform function signature
optimizations on specialized functions.

The overall scheme is as follows:

_TTS<MANGLINGINFO>__<FUNCNAME>

Thus if we specialize twice, the first specialization will just be treated as
the function name for the second specialization.

<MANGLINGINFO> is defined as:

_<SPECIALIZATIONKINDID>_<SPECIALIZATIONUNIQUEINFO>

Where specialization kind is an enum that specifies the specific sort of
specialization we are performing and specialization unique info is enough
information to ensure that the identity of the function is appropriately
preserved.

Swift SVN r23801
2014-12-09 02:53:05 +00:00
Michael Gottesman
1afc987739 Refactor the SILArgument API on SILBasicBlock so we can insert bb arguments anywhere in the argument list. Also clean up the API names so that they all match.
Swift SVN r23543
2014-11-22 00:24:40 +00:00
Andrew Trick
40c27c85ab Added -enable-specializer flag.
Swift SVN r22860
2014-10-21 16:48:07 +00:00
Mark Lacey
3007f6597b Move the generic specializer to using the new call graph.
Resolves <rdar://problem/18186065>.

Swift SVN r22596
2014-10-08 06:25:57 +00:00
Mark Lacey
7284f31d4e Make output order of specialization less fragile.
Change the function insert policy to insert specializations before the
function we are specializing rather than at the end of the module in
order to make the -emit-sil output a little less dependent on the actual
order we specialize in.

Swift SVN r22595
2014-10-08 05:01:16 +00:00
Mark Lacey
9d43ae474a Fix 80-column violations in generic specializer.
Swift SVN r22593
2014-10-08 03:21:13 +00:00
Erik Eckstein
c16c510167 Set SILLinkage according to visibility.
Now the SILLinkage for functions and global variables is according to the swift visibility (private, internal or public).

In addition, the fact whether a function or global variable is considered as fragile, is kept in a separate flag at SIL level.
Previously the linkage was used for this (e.g. no inlining of less visible functions to more visible functions). But it had no effect,
because everything was public anyway.

For now this isFragile-flag is set for public transparent functions and for everything if a module is compiled with -sil-serialize-all,
i.e. for the stdlib.

For details see <rdar://problem/18201785> Set SILLinkage correctly and better handling of fragile functions.

The benefits of this change are:
*) Enable to eliminate unused private and internal functions
*) It should be possible now to use private in the stdlib
*) The symbol linkage is as one would expect (previously almost all symbols were public).

More details:

Specializations from fragile functions (e.g. from the stdlib) now get linkonce_odr,default
linkage instead of linkonce_odr,hidden, i.e. they have public visibility.
The reason is: if such a function is called from another fragile function (in the same module),
then it has to be visible from a third module, in case the fragile caller is inlined but not
the specialized function.

I had to update lots of test files, because many CHECK-LABEL lines include the linkage, which has changed.

The -sil-serialize-all option is now handled at SILGen and not at the Serializer.
This means that test files in sil format which are compiled with -sil-serialize-all
must have the [fragile] attribute set for all functions and globals.

The -disable-access-control option doesn't help anymore if the accessed module is not compiled
with -sil-serialize-all, because the linker will complain about unresolved symbols.

A final note: I tried to consider all the implications of this change, but it's not a low-risk change.
If you have any comments, please let me know.



Swift SVN r22215
2014-09-23 12:33:18 +00:00
Erik Eckstein
99cc7603be Add an @inline(__always) function attribute.
This will let the performance inliner inline a function even if the costs are too high.
This attribute is only a hint to the inliner.
If the inliner has other good reasons not to inline a function,
it will ignore this attribute. For example if it is a recursive function (which is
currently not supported by the inliner).

Note that setting the inline threshold to 0 does disable performance inlining at all and in
this case also the @inline(__always) has no effect.



Swift SVN r21452
2014-08-26 00:56:34 +00:00
Nadav Rotem
8dd52d63cd Add the @effects(readonly/readnone/readwrite) attribute.
Swift SVN r21070
2014-08-06 18:48:20 +00:00
Nadav Rotem
898bf23738 Move the CallGraphAnalysis to a new file.
Swift SVN r20714
2014-07-29 23:18:56 +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
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
Manman Ren
ae9f2e25ae [@semantics] add SemanticsAttr to SILFunction.
Enable SIL parsing and SIL serialization of semantics.

We add one more field to SILFunctionLayout for semantics. We should refactor
handling of attributes at SIL level, right now they are in SILFunction as bool
or std::string and in SIL serializer as a 1-bit field or an ID field.

rdar://17525564


Swift SVN r19434
2014-07-01 22:49:46 +00:00
Manman Ren
7667b829bb [noinline attribute] add noinline attribute.
Propagate it to SILFunction and use it in PerformanceInliner. We also serialize
and parse the attribute.

rdar://15882816


Swift SVN r19150
2014-06-24 23:07:45 +00:00
Adrian Prantl
b1a7a7af1b Reference-count inlined functions to keep them alive until we emit debug
info for them and generally clean up the inline scope handling a bit.
Fix the debug scope handling for all clients of SILCloner, especially
the SIL-level spezializers and inliners.
This also adds a ton of additional assertions that will ensure that
future optimization passes won't mess with the debug info in a way that
could confuse the LLVM backend.

Swift SVN r18984
2014-06-18 22:34:10 +00:00
Mark Lacey
c7d3c3cd01 Rename and move a function that checks for unbound generics.
In the short term this will also be used to determine if we can inline
generic functions.

Swift SVN r18972
2014-06-18 02:51:23 +00:00
Mark Lacey
0850bcc4d7 Make TypeSubstCloner take a substitution list directly.
Rather than calling getSubstitutions() in various places on the apply
that we are cloning the body of, pass the substitution list in
directly when creating the cloner.

This is not interesting for the generic specializer, but is important in
mandatory inlining when we go to inline an apply of a partial apply,
where we need to use the full list of substitutions for both.

Swift SVN r18951
2014-06-17 08:28:56 +00:00
Mark Lacey
904d73b71e Remove unused parameters to TypeSubstCloner ctor.
These are used by a helper in the generic specializer, but not
need for the cloner class itself.

Swift SVN r18848
2014-06-12 23:50:19 +00:00
Mark Lacey
70fdc6d9ed Make SpecializingCloner inherit from TypeSubstCloner.
This is mostly cleanup in TypeSubstCloner to make it possible to use
in the CRTP.

Swift SVN r18847
2014-06-12 23:50:19 +00:00
Michael Gottesman
d306d62d08 Remove unused anonymous namespace.
Swift SVN r18843
2014-06-12 22:36:08 +00:00
Bob Wilson
2df66cf8c4 Implement inline scopes for the performance inliner.
Mandatory-inlined (aka transparent functions) are still treated as if they
had the location and scope of the call site. <rdar://problem/14845844>
Support inline scopes once we have an optimizing SIL-based inliner

Patch by Adrian Prantl.

Swift SVN r18835
2014-06-12 19:48:43 +00:00
Mark Lacey
87e94268a6 Move TypeSubstCloner into its own file.
This will allow it to be used both by the generic specializer as well as
the inliner.

Swift SVN r18812
2014-06-11 23:23:01 +00:00
Mark Lacey
dcdcde8c10 Rename TypeSubCloner to TypeSubstCloner.
Swift SVN r18811
2014-06-11 23:22:57 +00:00
Mark Lacey
5d8323ceeb Move initCloned from TypeSubCloner to SpecializingCloner
Swift SVN r18802
2014-06-11 08:19:31 +00:00
Mark Lacey
dcf7d5cc3a Start refactoring type substitution cloning for use in inliner.
Add a new SpecializingCloner that will contain the
generic-specialization-specific functionality needed by that pass. This
inherits from TypeSubCloner, which I will move into a separate file in a
future commit after further refactoring.

Swift SVN r18791
2014-06-10 23:32:46 +00:00
Mark Lacey
b9ac148bc9 Small renaming of a couple members.
Swift SVN r18782
2014-06-10 19:15:30 +00:00
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