Commit Graph

177 Commits

Author SHA1 Message Date
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
Anna Zaks
2f05d5c4df [SIL] Move GenFunc to use getBuiltinInfo and getIntrinsicInfo.
Make the functions support a wider range of builtins and store types to make
it possible.

This is an optimization - the cached ID will be used for builtin identification,
instead of retrieval of the string name and using it as the key.

Swift SVN r7390
2013-08-21 00:02:22 +00:00
Anna Zaks
2870c53a54 [SIL] Cache Builtin Kind and type lookup in SILModule and speed up CCP
Swift SVN r7354
2013-08-20 01:31:48 +00:00
Anna Zaks
3ac84f3878 [SIL] Add getIntrinsicID(FuncDecl*), which lazyly looks up the llvm::IntrinsicID for it.
The cache is stored in the SILModule.
Add getIntrinsicID() as a member of BuiltinFunctionRefInst.
Test by using the new method in the CCP pass.

Swift SVN r7311
2013-08-17 00:41:30 +00:00
Dmitri Hrybenko
d0455ca1c6 Remove unneeded llvm:: qualifier for llvm::ArrayRef
Swift SVN r7093
2013-08-09 20:05:02 +00:00
Anna Zaks
aaa4b2c332 [SIL Printer] Add optional source location printing.
Added a -v(verbose) option to swift that will trigger verbose printing in SIL
Printer. SIL Printer will print the location info only in the verbose mode.

Here is the example of the format - only the line and colon are displayed for
brevity:

%24 = apply %13(%22) : $[cc(method), thin] ((), [byref] Bool) -> Builtin.Int1 // user: %26 line:46:10

(This will be used to test the validity of SILLocation info.)

Swift SVN r6991
2013-08-07 18:39:48 +00:00
John McCall
f46ffb3382 Shorten "TypeLoweringInfo" to "TypeLowering".
Swift SVN r6795
2013-08-01 01:28:34 +00:00
Joe Groff
ba774364f1 SIL: Have SILModules track their SILStage.
Modules can be in either 'Raw' or 'Canonical' form, with different invariants on each. We don't actually distinguish those invariants yet, but this patch adds the field to SILModule and adds a "sil_stage" declaration to SIL printer/parser syntax.

Swift SVN r6793
2013-08-01 00:58:31 +00:00
Joe Groff
398cbba5be Rename SILConstant to SILDeclRef.
"SILConstant" doesn't really describe its role in SIL anymore, which is to provide a reference to a Swift declaration in a SIL instruction, such as a method or nominal type field.

Swift SVN r6559
2013-07-24 21:21:31 +00:00
John McCall
4df7c9d33f Adjust the mechanics of type lowering to avoid double-caching.
Swift SVN r6531
2013-07-23 23:51:13 +00:00
Joe Groff
8ac1bda817 SIL: Move retain/release/destroy helpers onto SILBuilder.
Add a convenience SILModule::getTypeLoweringInfo forwarder, and move the emitRetainRValue and emitReleaseRValue helpers from SILGenFunction to SILBuilder so they're more readily available to non-SILGen passes. Add an emitDestroyAddress helper that emits nothing, destroy_addr, or load + release based on the value semantics of the referenced type.

Swift SVN r6431
2013-07-21 18:39:56 +00:00
Joe Groff
1984cf41e0 SIL: Rename SILFunction::getMangledName to SILFunction::getName.
Swift SVN r6430
2013-07-21 18:39:51 +00:00
Chris Lattner
099f0cf451 simplify the construction of SILFunctionTypeInfo, inlining some singly-called helper functions.
Swift SVN r6427
2013-07-21 15:42:25 +00:00
Chris Lattner
496446ce64 Make all SIL objects that are print()-able, also raw_ostream insertable
with <<.  Use this to implement a DEBUG() dump in MemoryPromotion.cpp


Swift SVN r6412
2013-07-20 02:43:26 +00:00
Anna Zaks
a984d9b24c Move the SIL diagnostic emission entrypoint from SILGen to the top level swift.cpp driver
This addresses Chris’s review of r6151.

Swift SVN r6290
2013-07-16 18:53:23 +00:00
Anna Zaks
2e4170e249 Add the first SIL-based waring - "missing return"
Add a warning on a missing return statement.
(This is not yet an error since we need to handle no-return functions.)

Swift SVN r6153
2013-07-11 17:12:12 +00:00
Chris Lattner
5c661f3c38 push global reference parsing forward a bit, diagnosing a type error.
Swift SVN r5811
2013-06-26 05:33:49 +00:00
Joe Groff
dbc314cdab Add a -use-malloc switch for memory debugging.
This flag makes ASTContext and SILModule's allocators go through malloc instead of using bump pointer allocators, so that GuardMalloc or similar tools can be used to look for memory bugs.

Swift SVN r5472
2013-06-04 20:35:01 +00:00
Joe Groff
12c5999b44 Strip out -no-nsstring-is-string flag and associated LangOptions bit.
Swift SVN r5383
2013-05-29 19:42:12 +00:00
Joe Groff
8693c5efaa SIL: Emit String-to-NSString conversions.
If -nsstring-is-string is enabled, lower Strings in cc(c) and cc(objc) function types to NSString, and when calling them, insert calls to StringToNSString/NSStringToString to perform the bridging conversion.

This isn't quite ready for prime-time yet, because we still need to emit the inverse bridging for ObjC method thunks, and I haven't tested the IRGen end of things yet.

Swift SVN r5355
2013-05-26 20:29:09 +00:00
Joe Groff
0dc5c66cd2 SIL: Move SILFunctionTypeInfo into a side table.
Generate and cache SILFunctionTypeInfo from Swift types on the fly, and simplify the SILType representation down to a CanType and isAddress bit.

Swift SVN r5298
2013-05-24 16:33:52 +00:00
Chris Lattner
af3f2d2a66 cache the (recursive) computation of SILType::isAddressOnly in SILModule
to avoid expensive cases in extreme situations.


Swift SVN r5220
2013-05-19 04:23:29 +00:00
Chris Lattner
fa9adc72ed merge SILBase into SILModule, the only class that derives from it.
Swift SVN r5197
2013-05-17 04:22:00 +00:00
Chris Lattner
63e2a60585 rename Module:: and Function::getContext to ::getASTContext()
This matches SILType and is more explicit about which context
we're talking about.


Swift SVN r5185
2013-05-16 20:14:13 +00:00
Joe Groff
bcb49ce450 SIL: Key functions directly without SILConstant.
Replace 'constant_ref' with 'function_ref', which references a SILFunction directly, and 'global_addr', which references a global variable VarDecl. Get rid of the SILConstant-to-SILFunction mapping in SILModule and replace it with an ilist of SILFunctions. Allow SILFunctions to be 'external' by not having any blocks in their body. 

For now, SILFunctions still carry around their SILConstant "name", because name mangling and IRGen still rely on access to the original decl in order to recover IRGen information, which unfortunately leaves IRGen's CodeRefs in a gross, awkward intermediate state. Lifting mangling, AbstractCC, and other linkage attributes to SIL should clear up this up.

Swift SVN r4865
2013-04-23 23:29:04 +00:00