Commit Graph

925 Commits

Author SHA1 Message Date
Mark Lacey
dffef5d02b Revert "Handle indirect returns in @objc methods properly."
This reverts r11184, which broke some builds due to a missing library.

Swift SVN r11186
2013-12-12 09:11:39 +00:00
Mark Lacey
973ece4dc9 Handle indirect returns in @objc methods properly.
Use CodeGenABITypes to determine which return values should be indirect
in @objc methods.

Swift SVN r11184
2013-12-12 07:22:12 +00:00
John McCall
4bba9b38f8 Make several new interfaces traffic in AbstractionPatterns.
Swift SVN r10621
2013-11-21 02:19: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
15dc4967aa IRGen: Lower SILGlobalVariables.
Add support for emitting IR for SILGlobalVariables and SILGlobalAddrInst.

Swift SVN r10543
2013-11-18 17:40:45 +00:00
Joe Groff
ab65140a2e Add a 'Builtin.once' builtin.
This lowers to a call to a to-be-written swift_once runtime function and will be used for lazy global initialization. Having this be a builtin seemed appropriate to me given that:

- references to it will be implicitly emitted by SILGen for global initializers.
- there are restrictions on its correct use that are currently impossible to express in the language outside of the stdlib.

Swift SVN r10508
2013-11-16 00:50:12 +00:00
Joe Groff
19457c12ea Give Builtin.Word an abstract size.
Instead of hardcoding Builtin.Word to be an alias for Builtin.Int64, make it its own type of abstract pointer width.

- Change BuiltinIntegerType's width representation to accommodate abstract widths.

- In the AST and in SIL, store values of the types as the greatest supported size for the abstract width (64 bits for a pointer).

- Add some type safety to the ([sz]ext|trunc)(OrBitCast)? builtins that they're used appropriately given the upper and lower bounds of the abstract sizes they're working with.

- Now that Builtin.Word is a distinct type, give it its own mangling.

- In IRGen, lower pointer-sized BuiltinIntegerType appropriately for the target, and truncate lowered SIL values if necessary.

Fixes <rdar://problem/15367913>.

Swift SVN r10467
2013-11-14 19:56:26 +00:00
John McCall
93dfaa6bf4 Make everything getting a TypeInfo declare whether it's
working with a SIL-lowered or SIL-unlowered type.

Swift SVN r10067
2013-11-09 01:41:16 +00:00
Joe Groff
554abf2d7a IRGen/Runtime: Expose extra inhabitants of class types.
Start using null-page values as extra inhabitants when laying out single-payload enums that contain class pointers as their payload type. Don't use inhabitants that set the lowest bit, to avoid trampling potential ObjC tagged pointer representations. This means that 'T?' for class type T now has a null pointer representation. Enums with multiple empty cases, as well as nested enums like 'T??', should now have optimal representations for class type T as well.

Note that we don't yet expose extra inhabitants for aggregates that contain heap object references, such as structs with class fields, Swift function types, or class-bounded existentials (even when the existential has no witness tables).

Swift SVN r10061
2013-11-09 00:43:40 +00:00
Chris Lattner
68af974227 Remove 'axle' related code and build machinery. It turns out that we
will not be pursuing this project in the immediate future.



Swift SVN r9901
2013-11-03 16:04:27 +00:00
Joe Groff
bbddf41693 IRGen: Instantiate existential metadata through the runtime.
When we need a reference to protocol or protocol composition type metadata, ask for it through the runtime, instead of referencing statically-emitted protocol metadata.

Swift SVN r9871
2013-11-01 17:13:49 +00:00
Joe Groff
a0c4486808 IRGen: Emit protocol descriptors.
Produce protocol descriptors when we see a protocol definition in the current module. If the protocol is @objc, go through the existing path for generating full Protocol* metadata for objc objects; otherwise, emit our layout-compatible but strong-external-linkage Swift protocol descriptor record.

Swift SVN r9867
2013-11-01 04:28:43 +00:00
Jordan Rose
4a90ab0a4f [IRGen] Separate out SourceFile-specific processing from whole-module stuff.
We're going to want to emit multiple SourceFiles and one SILModule in one
IRGenModule.

Swift SVN r9670
2013-10-25 17:30:39 +00:00
Joe Groff
b8c75769b3 IRGen: Emit nominal type descriptors in struct and enum metadata.
Build a nominal type descriptor when we emit the metadata or generic metadata pattern for a nominal type, and put a reference into the formerly null slot in the struct or enum metadata. We need to make a place for them in class metadata; that'll come next.

Swift SVN r9492
2013-10-18 21:04:58 +00:00
Joe Groff
d2de66b18b IRGen: Include formal protocol conformances in ObjC class and protocol data.
So that Swift-defined classes actually do the right thing when -conformsToProtocol:-ed by dynamic protocol casts. Partially addresses <rdar://problem/15247517>, but we still need to dynamically emit runtime calls to register the conformance when compiling extensions in the JIT.

Swift SVN r9471
2013-10-17 22:51:04 +00:00
Joe Groff
f164a88615 IRGen: Emit ObjC protocol records for protocols used in casts.
Greg indicated that objc_getProtocol only works if somebody actually reifies a protocol_t record for the protocol with the runtime, so we need to emit our own protocol_t for every Protocol* value we do a checked cast with. Hijack the ClassDataBuilder to also build protocol_t records.

Swift SVN r9420
2013-10-16 21:50:56 +00:00
Jordan Rose
49cd5b1680 Use SourceFile in IRGen.
The only real change here is that module-wide IR (autolinking and ObjC
runtime flags) have been pushed up from emitTranslationUnit (now
emitSourceFile) to its only caller, performIRGeneration.

Swift SVN r9075
2013-10-09 18:38:24 +00:00
Pete Cooper
f9c6bf0630 Initial framework for generating Axle metadata. This currently only supports the function level metadata. Argument and result metadata to come later
Swift SVN r9061
2013-10-09 16:54:28 +00:00
Joe Groff
e109124186 Replace 'union' keyword with 'enum'.
This only touches the compiler and tests. Doc updates to follow.

Swift SVN r8478
2013-09-20 01:33:14 +00:00
Dmitri Hrybenko
f2cc4cb303 Rename CapturingExpr -> AbstractClosureExpr
Swift SVN r8299
2013-09-16 21:58:44 +00:00
Joe Groff
82f1ea85c0 IRGen: Kill dead methods from GenericMetadataBuilderBase.
Swift SVN r7894
2013-09-04 02:24:52 +00:00
Joe Groff
c3d1f0d661 IRGen: Sketch out a SwiftTargetInfo class with fun facts about pointers.
Start out with pointer spare bits, heap object alignment, null page size, and ObjC reserved bits, and provide static values for X86-64 and for a worst-case generic platform.

Swift SVN r7833
2013-08-31 17:01:02 +00:00
John McCall
eaa6228124 getFragileTypeInfo -> getTypeInfo
I didn't end up going the same way with fragility that I
thought I would at start, and this method name has become a
legacy.

Swift SVN r7340
2013-08-19 23:01:44 +00:00
Joe Groff
8baa585bab IRGen: Add FixedTypeInfo methods for extra inhabitants/spare bits.
Dynamic forms of these methods will ultimately move to the fully general TypeInfo class, but for now I'm focusing on getting fixed-layout unions working. Set up methods on FixedTypeInfo for getting the fixed count of extra inhabitants and the spare bit mask for a type. Have the default implementation of extra inhabitants count use the spare bits. For now, only actually set spare bits for types with IR-level single scalar non-power-of-two integer representation (e.g., i1, or i21).

Swift SVN r7289
2013-08-16 20:56:28 +00:00
Joe Groff
a94489473c IRGen: Add ValueWitness enumerators for union layout and access.
These value witness table entries will be conditionally available for types that support specialized union representation through extra inhabitants and/or spare bits and for union value witnesses:

- storeExtraInhabitant, to store an extra inhabitant representation;
- getExtraInhabitantIndex, to recognize an extra inhabitant representation;
- getUnionTag, to get a union's discriminator; and
- inplaceProjectUnionData, to extract the value in place from a union.

This just sets up the enumerators and related IR types and mangling; nothing emits these witnesses yet.

Swift SVN r7234
2013-08-14 21:01:21 +00:00
Dmitri Hrybenko
de59d8dcd4 Remove unneeded llvm:: qualifier for llvm::StringRef and llvm::SmallVector
Swift SVN r7089
2013-08-09 18:41:46 +00:00
Jordan Rose
674a03b085 Replace "oneof" with "union"...everywhere.
We haven't fully updated references to union cases, and enums still are not
their own thing yet, but "oneof" is gone. Long live "union"!

Swift SVN r6783
2013-07-31 21:33:33 +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
7b86817b3c Basic value structure for [weak] and [unowned] references.
Add a bunch of new entrypoints and give them terrible
implementations.

Swift SVN r6322
2013-07-17 09:20:20 +00:00
John McCall
075539b0f5 Generate runtime functions from an xmacro database.
Swift SVN r6266
2013-07-15 18:33:45 +00:00
Adrian Prantl
0f7533dc7e Debug Info! Add basic support for line tables, compilation units, files,
and lexical scopes, which can be enabled through the new -g option.
When -g is enabled, line tables and scopes compile all the way
down to DWARF.

Changes to SIL:
- In addition to a SILLocation, every instruction now also has a pointer
  to a SILDebugScope (its containing lexical scope).
- Added LexicalScope, which is to be used for all Scopes we want to show
  up in the debug info.

Swift SVN r5772
2013-06-23 00:09:17 +00:00
Joe Groff
470cb9eae0 IRGen: Implement opaque archetype/existential casts.
Use the new swift_dynamicCastIndirect runtime functions to implement casts from opaque archetype and existential types to concrete types.

Swift SVN r5684
2013-06-19 18:56:14 +00:00
Joe Groff
4ff8cd27dd IRGen: Abstract out an "unknown refcounted" concept.
In the implementation of class-bounded archetypes and existentials, instead of referring to ObjC pointer types and retain/release operations directly, use an 'UnknownRefCountedPtrTy' and 'emitUnknownRetain/Release' functions.

Swift SVN r5619
2013-06-17 18:31:49 +00:00
Joe Groff
285031cc8c IRGen: Use SILTypes for utility functions used by conversion insns.
Push SILTypes down into the helper functions used to emit SuperToArchetype, Downcast, and BridgeToBlock instructions.

Swift SVN r5189
2013-05-16 22:31:46 +00:00
Joe Groff
223d0251bd IRGen: Add getFragileTypeInfo and getFunctionType for SIL types.
Add overloads of getFragileTypeInfo and getFunctionType that take a SILType instead of a Swift CanType, and use them where it's easy to do so. Right now they just forward to the CanType versions, but we'll want to do SILType-specific type conversion soon. Clean up some IRGenSILFunction interfaces now that SILFunction carries most of the information IRGen needs intrinsically. No functionality change.

Swift SVN r5141
2013-05-10 16:28:25 +00:00
Chris Lattner
ca0091a445 add a few "optimized" runtime entrypoints for swift_getTupleTypeMetadata
that handle the 2/3 element cases specially.  These are not actually
optimized at the moment (they just call into swift_getTupleTypeMetadata)
but this could be done at some point.

This is a win for a couple reasons: this reduces the amount of code generated
inline and it allows swift_getTupleTypeMetadata2/3 to be marked readnone,
enabling CSE.  As a driveby, optimize metadata refs of zero element tuples
to directly use _TMdT_, eliminating a branch from swift_getTupleTypeMetadata.



Swift SVN r5070
2013-05-06 23:19:31 +00:00
Joe Groff
2be26b31a5 Make the deallocating destructor actually deallocate.
Emit the deallocObject runtime call inside the deallocating destructor for a heap object, instead of inside swift_release. This will allow for heap objects with known size to directly call fast deallocator entry points and potentially custom deallocators in the future.

Swift SVN r5027
2013-05-02 20:37:12 +00:00
Joe Groff
08b6f87524 Add 'typeof' to value witness tables.
To be able to get the dynamic type of a generic value, the 'typeof' operation needs to be part of the value witness for the type. Add 'typeof' to the value witness table layout, and in the runtime, provide standard typeof witnesses for static, Swift class, and ObjC class values.

Swift SVN r5013
2013-05-01 18:49:25 +00:00
Joe Groff
0566088bf2 Move name mangling into SIL.
Sever the last load-bearing link between SILFunction and SILConstant by naming SILFunctions with their mangled symbol names. Move the core of the mangler up to SIL, and teach SILGen how to use it to mangle a SILConstant.

Swift SVN r4964
2013-04-28 03:32:41 +00:00
John McCall
1fec73a8d2 Untested support for tuples with generically-sized elements.
Swift SVN r4926
2013-04-26 21:33:24 +00:00
Joe Groff
ac1a7b3d0a IRGen: Walk local decls independent of SILFunctions
Find function bodies and emit their local type decls using the AST instead of relying on SILConstants to point the way back to the function bodies.

Swift SVN r4916
2013-04-26 00:32:22 +00:00
Joe Groff
8bdccdd418 IRGen: Clear up dtor special cases in SIL-IRGen.
Change the destroying destructor entry point ABI to take 'this' as the appropriate type instead of as %swift.refcounted. Emit the deallocating destructor in IRGen when we see the ClassDecl, not when we see the SILFunction for the destructor. This frees us from having to worry about whether a SILFunction came from a destructor decl. We won't be able to reconstruct that once SILFunctions are pre-mangled.

While we're here, repaint some bikesheds so it's clearer that SIL and SILGen work with the destroying destructor.

Swift SVN r4908
2013-04-25 19:50:58 +00:00
Joe Groff
ee9ca634a5 SIL: Add linkage and calling conv to SILFunctions.
Move AbstractCC into SILType and make it an attribute of SILTypes for functions. Add a ConvertCCInst to represent calling convention conversions. Give SILFunctions a linkage attribute. Add logic to SILGen to calculate these attributes for SILConstants based on their attached decls.

IRGen doesn't use these new attributes yet. I'll hook that up when I move mangling over.

Swift SVN r4886
2013-04-24 18:09:44 +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
Chris Lattner
e3d6a489af remove the Cleanup subclasses.
Swift SVN r4839
2013-04-21 05:06:52 +00:00
John McCall
38b34b7307 Pass #1 at localizing assumptions about fixed layout and
handling non-fixed layouts.

This uncovered a bug where we weren't rounding up the header
size to the element alignment when allocating an array of archetypes.

Writing up a detailed test case for *that* revealed that we were
never initializing the length field of heap arrays.  Fixing that
caused a bunch of tests to crash trying to release stuff.  So...
I've left this in a workaround state right now because I have to
catch a plane.

Swift SVN r4804
2013-04-18 07:58:21 +00:00
Chris Lattner
22321ffe7f next pass deleting now-dead code. Default ctors are keeping a bunch of
stuff alive (tracked by rdar://13670607)


Swift SVN r4763
2013-04-17 04:01:37 +00:00
Joe Groff
14355a8134 Runtime: Add swift_allocBox.
Add a runtime function that, given a generic type metadata pointer, allocates a heap object capable of containing a value of that type. This is a first-pass implementation that always does the worst case thing of stuffing the type metadata into the box with the value and using its value witness table to size, align, and destroy the box. Use swift_allocBox to implement ArchetypeTypeInfo::allocate correctly for heap object allocations. This means SIL's alloc_box $T now works for archetypes, and a simple generics test now (almost) compiles through SIL!

Swift SVN r4599
2013-04-05 01:34:28 +00:00
Chris Lattner
65cd2b2d25 rename swift::Function to swift::SILFunction to be more explicit.
Swift SVN r4590
2013-04-03 18:36:15 +00:00
Joe Groff
08d06e850d IRGen: Emit top-level globals from SIL.
Set up IRGen to emit SIL code that uses top-level-code global variables. Add -sil-i to a bunch of Interpreter tests that use global variables.

Swift SVN r4480
2013-03-22 23:34:38 +00:00