Commit Graph

101 Commits

Author SHA1 Message Date
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
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
Michael Gottesman
7fbb22ef1e Revert "[sil-opt] When dumping a module, deterministically sort globals/functions/vtables/witness tables so that it is possible to diff modules."
This reverts commit r16267. Need to update tests.

Swift SVN r16269
2014-04-13 03:13:49 +00:00
Michael Gottesman
02ba8db0cf [sil-opt] When dumping a module, deterministically sort globals/functions/vtables/witness tables so that it is possible to diff modules.
Swift SVN r16267
2014-04-12 22:35:03 +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
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
a571cd83f9 [deserialization] Add ClassDecl -> VTable map to SILModule.
Swift SVN r15545
2014-03-27 03:52:00 +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
f807249aa8 [deserialization] Store the mangled name of a SILWitnessTable on the instance itself.
The importance of this is that we will be able to use this name during
SIL serialization/deserialization to lookup partially deserialized
witness tables.

I left IRGen's original code alone until I can discuss with Joe/John
combining the logic together.

Swift SVN r15400
2014-03-24 05:07:20 +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
Mark Lacey
2f4b982051 Remove TrivialTypeCache and AddrOnlyTypeCache from SILModule.
Now that we have better hashing in type lowering, these do not provide a
benefit.

Swift SVN r14878
2014-03-10 21:34:06 +00:00
Nadav Rotem
0985124291 Read the name of the function before deleting it.
I found this problem while fixing another bug.



Swift SVN r14532
2014-02-28 19:38:40 +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
137ca5f18f Remove trailing whitespace. NFC.
Swift SVN r14472
2014-02-27 20:54:10 +00:00
Nadav Rotem
bd83adcd7c Cache the isAddressOnly property since it is a major compile time win.
Swift SVN r14347
2014-02-25 18:42:09 +00:00
Nadav Rotem
bc6fcc4475 Cache the isTrivial property.
The check for isTrivial takes ~20% of the optimizer compile time (in debug
mode) and using a cache accelerates the compile time.



Swift SVN r14346
2014-02-25 18:15:45 +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
Doug Gregor
03edef185a Emit a -dealloc method for Swift classes whose root class is defined in Objective-C.
Teach SILGen to emit a -dealloc method that runs user code, destroys
instance variables, and then calls up to the superclass dealloc. Teach
IRGen to deal with Objective-C destructor methods and add -dealloc to
the instance method table.

There are a few things still wrong here: we're emitting both a Swift
destructor and -dealloc, even though only one of them should ever
actually be used. Additionally, instance variables shouldn't be
destroyed in -dealloc, but in .cxx_destruct, so they persist until the
last of the -dealloc methods is invoked.

Swift SVN r12115
2014-01-10 05:07:33 +00:00
Nadav Rotem
c391e8162e Refactor the code that erases sil functions into a new method, eraseFunction, and remember to clean the function table.
Swift SVN r11999
2014-01-07 18:18:10 +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
Joe Groff
8f47dc7383 SIL: Add a SILModule::lookUpWitnessTable method.
Looks up the SILWitnessTable for a ProtocolConformance.

Swift SVN r11576
2013-12-22 22:37:56 +00:00
Joe Groff
fd7b61ac71 SIL: Add a lookup cache StringMap to SILModule.
Because doing linear lookup all the time is dumb. NFC.

Swift SVN r11575
2013-12-22 22:37:55 +00:00
Adrian Prantl
c610ac94ef Add an IsBare attribute to SILFunction for functions that do not have an
AST.

Swift SVN r11236
2013-12-13 04:48:37 +00:00
Anna Zaks
e9870cd347 [SIL] Add helper - it's useful when printing SILInstructions.
Swift SVN r11196
2013-12-12 19:07:02 +00:00
Joe Groff
2a7de8f495 Introduce a SILWitnessTable class.
We will generate these in SILGen when we see a NormalProtocolConformance, to provide a mapping of method requirements to witnesses for types.

Swift SVN r10900
2013-12-06 01:32:36 +00:00
Jordan Rose
417b5d3982 Merge TranslationUnit into Module, and eliminate the term "translation unit".
This completes the FileUnit refactoring. A module consists of multiple
FileUnits, which provide decls from various file-like sources. I say
"file-like" because the Builtin module is implemented with a single
BuiltinUnit, and imported Clang modules are just a single FileUnit source
within a module.

Most modules, therefore, contain a single file unit; only the main module
will contain multiple source files (and eventually partial AST files).

The term "translation unit" has been scrubbed from the project. To refer
to the context of declarations outside of any other declarations, use
"top-level" or "module scope". To refer to a .swift file or its DeclContext,
use "source file". To refer to a single unit of compilation, use "module",
since the model is that an entire module will be compiled with a single
driver call. (It will still be possible to compile a single source file
through the direct-to-frontend interface, but only in the context of the
whole module.)

Swift SVN r10837
2013-12-05 01:51:15 +00:00
John McCall
007d3974d6 Use a proper mangling to try to share reabstraction thunks.
Swift SVN r10764
2013-12-03 23:23:52 +00:00
Chris Lattner
3b954ed44d strength reduce SILGenModule::getBuiltinInfo/getIntrinsicInfo to
take an identifier instead of a FuncDecl.


Swift SVN r10692
2013-11-30 00:57:46 +00:00
John McCall
20e58dcf93 Change the type of function values in SIL to SILFunctionType.
Perform major abstraction remappings in SILGen.  Introduce
thunking functions as necessary to map between abstraction
patterns.

Swift SVN r10562
2013-11-19 22:55:09 +00:00
Joe Groff
0cc9417fef SIL: Introduce a SILGlobalVariable concept.
This will let us control linkage and emit new variables independent of the AST in SILGen. In particular, for lazy global initialization, we need to emit a unique internal once predicate for every top-level pattern binding. Switching everything over is a bit much to reengineer all at once, so for now, it can coexist with the globals map that is already there.

Swift SVN r10509
2013-11-16 00:50:17 +00:00
Joe Groff
003709d51f SIL: Add a backreference from SILModule to its originating Swift Module.
Ideally this wouldn't be necessary, but the type substitution APIs required by generic specialization and SIL verification currently require a Module* pointer, and it's obnoxious to have to pass it down separately everywhere it's needed. Longer-term the reliance on Modules for type substitution might be able to go away.

Swift SVN r9866
2013-11-01 00:46:21 +00:00
Chris Lattner
ef93c81ffb Introduce a new SIL-level "undef" value, useful for SIL transformations.
IRGen support is missing, Joe volenteers to implement it.


Swift SVN r9776
2013-10-30 00:58:09 +00:00
Anna Zaks
7e47f5984a Fix a comment.
Swift SVN r9767
2013-10-29 22:27:27 +00:00
Chris Lattner
2127da6a91 Enhance the function_ref instruction to maintain a refcount on the
SILFunction that it references.  Use this in the mandatory inlining
pass to remove deserialized transparent functions, to clean up the
-emit-sil output of the compiler (and presumably speed up compile 
time).  This implements rdar://15272652



Swift SVN r9699
2013-10-27 22:00:54 +00:00
Sean Callanan
ac43e98dd2 Added SILExternalSource, a class that can be used
to interpose on the SIL linking process.  Under the
following conditions:

- a function is called by the current SILModule;
- that function is transparent and empty in the
  generated SIL;
- the SIL linker doesn't find a serialized
  version of it; and
- the external client (right now, LLDB) has a
  SILExternalSource installed in the SILModule;

the SIL linker will query the SILExternalSource
via lookupSILFunction.

This interface will be used by LLDB to provide
SIL accessors for a program's variables when they
are referred to by Swift expressions.


Swift SVN r9452
2013-10-17 18:04:24 +00:00
Jordan Rose
5ed38c0b72 Clarify SourceFile vs. TranslationUnit interfaces for SILGen and IRGen.
Once we have multiple SourceFiles in a TranslationUnit, it no longer makes
sense to say "only SILGen decls starting from element N" without specifying
which source file you mean.

Also, clarify ownership by having performSILGeneration return a unique_ptr
instead of just a bare pointer.

Swift SVN r9112
2013-10-09 23:44:43 +00:00
John McCall
b880e60100 Remove SILFunctionTypeInfo in favor of SILFunctionType.
We still don't actually use this as a type, however.

Swift SVN r9091
2013-10-09 20:55:55 +00:00
Joe Groff
aca3bd52ac SILGen: Build SILVTables while visiting classes.
When we walk a ClassDecl, generate its vtable, first pulling in decls from its ancestor classes, then overlaying overridden or new decls as we discover them.

Swift SVN r8947
2013-10-06 01:02:14 +00:00
Joe Groff
b4f85653e6 SIL: Introduce SILVTables.
These will provide a SIL-level representation of class_method dispatch, mapping from dynamically-dispatched SILDeclRefs to SILFunctions so that devirtualization passes will be able to promote a class_method for a statically-known type to a function_ref without going all the way back to the AST.

Swift SVN r8943
2013-10-05 21:58:58 +00:00
Joe Groff
82a18333ed SIL: Purge SpecializeInst.
Make ApplyInst and PartialApplyInst directly take substitutions for generic functions instead of trying to stage out substitutions separately. The legacy reasons for doing this are gone.

Swift SVN r8747
2013-09-28 00:15:45 +00:00
Anna Zaks
59175bdc08 [SIL] Remove TranslationUnit pointer from SILModule.
This reverts r8624 and compensates by passing the TU to the SILModule printer when needed.

This addresses concerns that Jordan and Sean had raised.

Swift SVN r8678
2013-09-25 23:52:04 +00:00
Anna Zaks
4c61550b20 [SIL] Use TranslationUnit instead of ASTContext when creating a SILModule.
TU contains Decls that will need to be serialized when we print the SILModule.

Swift SVN r8626
2013-09-25 17:08:40 +00:00