Commit Graph

273 Commits

Author SHA1 Message Date
Joe Groff
9f4c417095 SIL: Forward-declare witness tables with correct linkage.
Fixes <rdar://problem/16997968>.

Swift SVN r19680
2014-07-08 05:30:35 +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
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
Manman Ren
b3e72be9d9 Remove unused deserialized SILFunctions.
The deserializer holds a reference to the deserialized SILFunction, which
prevents Dead Function Elimination from erasing them. 

We have a tradeoff on how often we should clean up the unused deserialized
SILFunctions. If we clean up at every optimization iteration, we may
end up deserializing the same SILFunction multiple times. For now, we clean
up only after we are done with the optimization iteration.

rdar://17046033


Swift SVN r18697
2014-06-04 00:30:34 +00:00
Mark Lacey
cd00cfbf8f Fix some build warnings.
DEBUG_TYPE should be defined before the inclusion of LLVM's Support/Debug.h.

Swift SVN r18640
2014-05-26 20:17:54 +00:00
Joe Groff
793fe06a34 SILGen: Emit an artificial toplevel for files with @UIApplicationMain classes.
If a source file contains the main class for its module, then implicitly emit a top_level_code that invokes UIApplicationMain with the name of the marked class.

Swift SVN r18088
2014-05-15 00:53:38 +00:00
Michael Gottesman
2c373a8cf4 [sil-module] Change DEBUG_TYPE to "sil-module" from "libsil"
I don't know why someone chose that name, but it makes no sense.

Swift SVN r17978
2014-05-12 23:59:50 +00:00
Michael Gottesman
e5191519e6 [linker] Link in closures references via function_refs during mandatory inlining.
Pattern matching on whether or not the function was applied is fragile
in the face of various possible compositions in between the function_ref
and the apply (i.e. thin_to_thick_function as an example).

Lets be conservative and just always deserialize references to closures
during mandatory inlining when referenced via a function_ref so we avoid
this problem if additional instructions like this are added.

Swift SVN r17977
2014-05-12 23:59:48 +00:00
Michael Gottesman
a7bb61265c [deserialization] Tighten up deserialization of witness tables.
We now enforce via an assert that each witness table is unique and that
every protocol conformance that is referenceable from SIL must have a
witness table matched to it.

Also, I taught the linker that it should deserialize witness tables for
InitExistentialRefInst instructions, something that was missed before.

Swift SVN r17283
2014-05-02 22:28:13 +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
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
c9baa6d739 [devirtualization] Extract the method SILModule::lookUpSILFunctionFromVTable from optimizeClassMethodInst. NFC.
Swift SVN r17133
2014-05-01 02:08:57 +00:00
Michael Gottesman
5449d6f673 [devirtualizer] Refactor findFuncInWitnessTable -> SILModule::findFuncInWitnessTable.
Swift SVN r17130
2014-05-01 01:06:06 +00:00
Michael Gottesman
14e0f3fef2 [deserialization] When deserializing init_existential_inst pull in all the relevant witness tables.
<rdar://problem/16646818>

Swift SVN r16742
2014-04-24 03:37:34 +00:00
Michael Gottesman
afa464f980 [deserialization] Do not allow SILModule to attempt to deserialize a witness table lazily while we are already deserializing.
When deserializing, the serialized sil loader attempts to first lookup
from its SILModule the witness table to attempt to grab a witness table
declaration. Before this patch if the SILModule could not find it, it
would attempt to deserialize it. In certain edge cases this would cause
us to attempt to deserialize a function definition which violates the
invariant that that should never happen.

This patch adds an argument to SILModule::lookUpWitnessTable that
enables you to turn off the lazy deserialization behavior. The default
argument gives the current behavior which should be used everywhere
except for the deserializer.

Swift SVN r16740
2014-04-24 03:37:33 +00:00
Chris Lattner
a3916614ef respond to mainline API changes in the Debug.h header, by defining the
DEBUG_TYPE macro in all .cpp files that use the DEBUG macro.  Hopefully
this will unbreak the build.


Swift SVN r16638
2014-04-22 02:54:55 +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
Michael Gottesman
0bc4f9c936 Call SILFunction destructor when we cleanup functions so that if the function contains a function_ref, the function referenced by the function_ref has its refcount properly decrement.
Otherwise a function_ref which was supposed to be deallocated would keep
functions alive.

rdar://16287331

Swift SVN r16192
2014-04-11 01:44:38 +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
4e73547a3e Change SerializedSILLoader::create to return a unique_ptr and use that everywhere so we don't leak SILLoaders.
Swift SVN r15700
2014-03-31 22:57:03 +00:00
Michael Gottesman
0d0c00ce15 [deserialization] Create the SILLoader for a SILModule lazily the first time deserialization occurs instead of when the SILModule is created.
This enables us to get around timing issues when we create a SILModule before we
have finished loading all Swift Modules.

This manifested itself in sil-opt where we were unable to deserialize from the
standard library when optimizing a separate *.sil file.

Swift SVN r15670
2014-03-31 08:40:35 +00:00
Michael Gottesman
6946e86d0e [deserialization] Enable deserialization of VTables by default.
Swift SVN r15635
2014-03-29 21:58:55 +00:00
Michael Gottesman
08cd417faf [deserialization] Rename addCalleeFunction() -> addFunctionToWorklist(). CalleeFunction is an inappropriate name since we are using this also for deserializing functions referenced by vtables and witness tables.
Swift SVN r15634
2014-03-29 21:58:52 +00:00
Michael Gottesman
a571cd83f9 [deserialization] Add ClassDecl -> VTable map to SILModule.
Swift SVN r15545
2014-03-27 03:52:00 +00:00
Michael Gottesman
fdaa10b94f [deserialization] Teach WitnessMethodInst how to deserialize SILFunctions referenced by a witness table.
I need to add in the non-lazy linking pass before I can properly test
this. But I did not want to leave this bug in the wild. Expect the test
in the next bit.

Swift SVN r15544
2014-03-27 01:51:07 +00:00
Michael Gottesman
406bc0c19a [deserialization] Change SILLinking to use SILModule for linking instead of performing the linking itself.
This approach will allow us to go back to doing lazy linking if we want
to in the future.

Swift SVN r15498
2014-03-26 08:47:01 +00:00
Michael Gottesman
f4bb049bfc [deserialization] Enable lazy deserialization of witness tables.
This patch adds in the necessary infrastructure for lazily deserializing
witness tables. This is done by following the same approach as the
deserialization/serialization of SILFunction.

Now if one calls SILModule::lookUpWitnessTable and the given witness table is a
definition, the SILModule will attempt to deserialize it from one of the other
modules.

Swift SVN r15403
2014-03-24 09:16:09 +00:00
Michael Gottesman
5b1e2d4025 This caching statement should not be necessary due to r15399.
Swift SVN r15401
2014-03-24 05:07:20 +00:00
Michael Gottesman
69af5467ce Add a witness table to the witness table lookup cache when we create it, not lazily as we perform a search.
This means that every witness table in a SILModule must be in the
protocol conformance -> witness table map. We still return nullptr if
there is no such witness table.

Swift SVN r15399
2014-03-24 04:38:49 +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
084d468236 [deserialization] Refactor SILModule::linkFunction into a SILVisitor pattern.
The if statement therein was just going to keep getting bigger and
bigger especially since I am going to add support for witness_method
among other things.

Swift SVN r15360
2014-03-22 02:06:38 +00:00
Michael Gottesman
11c03b0482 [deserialization] When linking functions, return failure if we get back a declaration.
We consider linking to only succeed if we actually convert a declaration
into a definition.

Swift SVN r15070
2014-03-14 20:36:17 +00:00
Chris Lattner
bca9000809 silence some fallthrough warnings.
Swift SVN r15033
2014-03-14 05:50:38 +00:00
Michael Gottesman
ea1d62e23a [deserialization] Verify functions when we deserialize them. This should help to catch deserialization issues.
Swift SVN r14876
2014-03-10 21:16:04 +00:00
Michael Gottesman
c52da10ee6 Fix typo where nullptr should be false.
Swift SVN r14835
2014-03-09 05:05:40 +00:00
Michael Gottesman
ba6ac196f6 Revert "[deserialization] Deserialize WitnessTables/VTables in SILModule, not in SILLinking."
This reverts commit r14623. I will recommit this when I reenable deserialization
of witness tables/vtables. This will enable the deserialization of SILFunctions
by default from the stdlib by avoiding the lack of external witness
tables/vtables.

Swift SVN r14786
2014-03-07 19:27:01 +00:00
Michael Gottesman
a50e4d54b8 Revert "[deserialization] Disable deserialization of vtables/witness tables for now."
This reverts commit r14750. I need to disable some tests.

Swift SVN r14751
2014-03-06 20:52:01 +00:00
Michael Gottesman
0b142c1f04 [deserialization] Disable deserialization of vtables/witness tables for now.
Some recent work done by John have unblocked deserialization of SILFunctions. We
still can not properly deserialize witness tables/vtables but enabling by
default deserialization of SILFunctions from the stdlib is a good first step
toward reaching our performance goals.

There will be forthcoming commits which removes Benchmarks.swift and all of the
infrastructure we have in place for compiling benchmarks in the standard
library.

Swift SVN r14750
2014-03-06 20:15:49 +00:00
Michael Gottesman
7f628360d9 [deserialization] Deserialize WitnessTables/VTables in SILModule, not in SILLinking.
Now we deserialize WitnessTables, VTables, and SILFunctions without
-sil-link-all passed in.

Swift SVN r14623
2014-03-03 23:49:42 +00:00
Michael Gottesman
29e1a53bbb [deserialization] Deserialize transparent functions lazily iff they will be used in mandatory inlining.
Swift SVN r14490
2014-02-28 01:05:01 +00:00
Michael Gottesman
a073096093 [deserialization] Begin move to lazy linking by putting a SerializedModuleLoader on SILModule.
Right now it is not wired up. That is coming in forthcoming commits. I am trying
to be very incremental about this.

This series of patches will fix an assertion triggered by us not deserializing
functions from vtables appropriately. Doing linking lazily fixes that issue and
does the "right thing".

The work is being done in consultation with John, Joe, and Jordan.

Swift SVN r14479
2014-02-27 21:30:54 +00:00
Michael Gottesman
ffa9b06042 Remove trailing whitespace. NFC.
Swift SVN r14478
2014-02-27 21:30:53 +00:00
Joe Groff
df356b475b SIL: Set the context generic params of reabstraction thunks less greedily.
Don't try to set the generic params of a reabstraction thunk until we've established it hasn't already been defined, fixing an issue where the same generic reabstraction pattern occurred in different contexts and we ended up clobbering the archetypes of a thunk that was already defined in terms of other archetypes.

Swift SVN r13964
2014-02-16 16:56:43 +00:00
Joe Groff
0c0d30d5eb SIL: Make ContextGenericParams a constructor parameter of SILFunction.
Edge SILFunction one step closer to independence from SILFunctionType context by taking the generic param list as a separate constructor parameter, and serializing those params alongside the function record. For now we still pass in the context params from the SILFunctionType in most cases, because the logic for finding the generic params tends to be entangled in type lowering, but this pushes the problem up a step.

Thanks Jordan for helping work out the serialization changes needed.

Compared to r13036, this version of the patch includes the decls_block RecordKind enumerators for the GENERIC_PARAM_LIST layouts in the sil_block RecordKind enumerator, as Jordan had suggested before. r13036 caused buildbot failures when building for iOS, but I am unable to reproduce those failures locally now.

Swift SVN r13485
2014-02-05 16:52:02 +00:00
Michael Gottesman
800ea37c34 Revert r13036 as per Joe's request.
Swift SVN r13063
2014-01-28 21:36:06 +00:00
Joe Groff
5d58f10e48 SIL: Make ContextGenericParams a constructor parameter of SILFunction.
Edge SILFunction one step closer to independence from SILFunctionType context by taking the generic param list as a separate constructor parameter, and serializing those params alongside the function record. For now we still pass in the context params from the SILFunctionType in most cases, because the logic for finding the generic params tends to be entangled in type lowering, but this pushes the problem up a step.

Thanks Jordan for helping work out the serialization changes needed.

Swift SVN r13036
2014-01-28 02:17:46 +00:00
Joe Groff
3b132bdcc7 SIL: SILModule::lookUpWitnessTable should always return a substitution list for generic conformances.
Even if the type is the DeclaredTypeInContext of the nominal, we still want the substitution list for generic specialization. Ideally the AST would always have a SpecializedProtocolConformance when we refer to a generic type instance, but our representation makes that difficult.

Swift SVN r12887
2014-01-23 23:45:32 +00:00
John McCall
5da6defa1f Clean up the linkage model and the computation of linkage.
In general, this forces SILGen and IRGen code that's grabbing
a declaration to state whether it's doing so to define it.

Change SIL serialization to serialize the linkage of functions
and global variables, which means also serializing declarations.

Change the deserializer to use this stored linkage, even when
only deserializing a declaration, and to call a callback to
inform the client that it has deserialized a new entity.

Take advantage of that callback in the linking pass to alter
the deserialized linkage as appropriate for the fact that we
imported the declaration.  This computation should really take
advantage of the relationship between modules, but currently
it does not.

Swift SVN r12090
2014-01-09 08:58:07 +00:00
John McCall
e507341c1b SILModule lookup: now with that magic O(1) flavor.
Swift SVN r11978
2014-01-07 01:21:10 +00:00
John McCall
bb63d2312b Hide the constructors of SILFunction/SILGlobalVariable
behind factory methods.

Swift SVN r11967
2014-01-07 00:22:15 +00:00