Commit Graph

1696 Commits

Author SHA1 Message Date
Joe Groff
7e29184b77 IRGen: Map SIL rets to indirect returns.
If the IR calling convention for a type SIL considers loadable requires an indirect return, for example, for large structs, map the SIL direct return to an indirect return.

Swift SVN r4553
2013-03-30 18:46:50 +00:00
Joe Groff
0e4c0a568d IRGen: Start adding ObjC call support through SIL.
Represent class_method and super_method SIL values using an ObjCMethod variant of LoweredValue that holds the necessary information to emit an objc_msgSend* call when the value is apply-ed. You can't really use ObjC objects from SIL IRGen yet because SILGen doesn't yet visit external definitions from the Clang importer.

Swift SVN r4550
2013-03-30 00:06:41 +00:00
Joe Groff
aee590a4b0 IRGen: Enable C function calls from SIL.
Preserve the AbstractCC of a function symbol when emitting a SIL ConstantRefInst by adding a new StaticFunction variant to LoweredValue. This lets us avoid a bunch of bitcasting noise for static functions that aren't used as values, and will lets us emit C-to-Swift-ABI thunks on demand when C functions are used as values.

Swift SVN r4543
2013-03-29 19:47:46 +00:00
Joe Groff
b105e02534 IRGen: Lower SIL bb arguments to LLVM phi nodes.
Swift SVN r4493
2013-03-27 17:07:17 +00:00
Joe Groff
e8b66bce1d SIL: Rename implicit_convert to convert_function.
All the other implicit conversions have been given their own instructions, so specialize this ill-specified instruction to its one remaining use, for converting compatible function types.

Swift SVN r4482
2013-03-25 16:51:03 +00:00
Joe Groff
b3ae290685 IRGen: Codegen SIL 'extract' from rvalue struct.
Swift SVN r4481
2013-03-25 16:08:08 +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
Joe Groff
7934842505 SILGen: Handle globals in top-level code.
In top-level code, global variables are notionally local variables of the "main" function, but we give them global storage as an implementation detail. Add the ability to represent physical global variables to SILConstant, and emit top-level-code global variable initializers and references in terms of the physical address.

Swift SVN r4479
2013-03-22 21:58:33 +00:00
Joe Groff
fab787a585 IRGen: Linkage for anonymous SIL functions.
CapturingExprs get mapped to referenceable SILConstants by SILGen instead of getting emitted in-place as in IRGen, so they need LinkEntities and mangling. For now I just mangle them all to "closure", which matches what old IRGen does.

Swift SVN r4477
2013-03-22 19:09:28 +00:00
Joe Groff
98f58675d5 IRGen: Handle function values from SIL correctly.
As values, IRGen expects functions to be i8*, so bitcast function values to i8* and bitcast them back when they're actually called.

Swift SVN r4471
2013-03-21 23:44:03 +00:00
John McCall
1a8d624b6c Rename the SIL 'closure' instruction to 'partial_apply'.
Swift SVN r4468
2013-03-21 21:59:28 +00:00
Joe Groff
15d606b630 IRGen: Lower SIL class_method for native classes.
Turn class_method into a vtable lookup for Swift class and class metatype instances.

Swift SVN r4467
2013-03-21 20:50:37 +00:00
Joe Groff
aaa85831a3 IRGen: Lower SIL super_method for native classes.
ObjC classes will need a special code path to support super_method, but in the pure Swift case it's just a direct reference to the super implementation.

Swift SVN r4457
2013-03-20 21:22:24 +00:00
Joe Groff
c090f65a06 IRGen: Update lowering for SIL protocol_method.
Swift SVN r4456
2013-03-20 20:48:16 +00:00
Joe Groff
92c81b76c9 IRGen: Update lowering of SIL closure insts.
Swift SVN r4454
2013-03-20 16:16:39 +00:00
Joe Groff
6668cc7316 IRGen: Fix SIL constant_ref to destructor.
Destructor refs were getting bitcast to the wrong type.

Swift SVN r4453
2013-03-20 03:46:10 +00:00
Joe Groff
61077a641d IRGen: Lower SIL function args in right order.
Map the SIL entry point BB's args to LLVM function args in the inner-to-outer-uncurry order used by Swift's ABI.

Swift SVN r4452
2013-03-20 03:23:56 +00:00
Joe Groff
ac73865dd7 IRGen: Update lowering of SIL applications.
We no longer need the PartialCall hackery in IRGen to uncurry calls, because SILGen does it for us.

Swift SVN r4451
2013-03-20 00:02:49 +00:00
Joe Groff
340cc73e1e SIL: Track uncurry levels of SILConstants.
Pack the uncurry level onto SILConstant, and modify SILConstant constructors to determine the natural uncurry level of their referenced entity by default. While we're here, improve how SILConstant represents different kinds of constants by using a real enum for the kind. Type closure entry points by giving them an extra curry level for their context. The implementation of ApplyInst and ClosureInst hasn't been updated yet, so tests that lower closures to SIL are temporarily broken.

Swift SVN r4354
2013-03-11 23:17:35 +00:00
Joe Groff
0db00816cd SIL: Replace ZeroAddr/ZeroValue with InitializeVar
Rename 'ZeroAddr' to 'InitializeVar' and remove ZeroValue since only things with memory locations should ever be in a 'default-initialize' state. Add a ModuleInst so we don't need to use ZeroValue as a hack to represent ModuleExpr values.

Swift SVN r4319
2013-03-07 18:38:25 +00:00
Joe Groff
8da204e3a2 IRGenSIL: Improve Explosion handling.
Instead of embedding Explosions in IRGenSIL's LoweredValues and trying to use them directly, store an unmanaged vector of llvm::Value*s, and create Explosions as needed. This allows Explosion APIs to behave normally (consuming values out of the explosion) without potentially messing up SIL value-to-LLVM value mappings.

Swift SVN r4309
2013-03-06 22:11:13 +00:00
Joe Groff
23279d2b15 IRGen: Remove useless 'default'.
Swift SVN r3905
2013-01-30 17:37:14 +00:00
Joe Groff
4186e0e721 IRGen: Emit SIL UpcastExistentialInsts.
This covers the special case in classic IRGen for ErasureExprs from protocol to protocol type.

Swift SVN r3888
2013-01-28 20:02:54 +00:00
Joe Groff
7b0ef2344d IRGen: Bitcast dtor arguments to RefCountedPtr.
In the SIL for a destructor I emit a call to the base class destructor. Although destructors show up in SIL as their decl type T -> (), internally, they all share an LLVM function type void (%swift.refcounted). If an ApplyInst applies to a destructor, bitcast its argument.

Swift SVN r3875
2013-01-26 00:49:53 +00:00
Joe Groff
68658916df IRGen: Scrub cleanups from ApplyInst explosions.
It looks like CallEmission::emitToExplosion sets up cleanups on its outputs, and I didn't see an immediately apparent way to do so, so this is just a quick hack to scrub those cleanups so they don't interfere with SIL-IRGen.

Swift SVN r3874
2013-01-26 00:49:51 +00:00
Joe Groff
e822b95861 IRGen: Lowering for SIL UpcastInst.
Swift SVN r3873
2013-01-26 00:49:49 +00:00
Joe Groff
7a7e14a9c5 IRGen: Emit SIL destructors.
Emit the SIL destructor as a destroying destructor, then emit a deallocating destructor shim that calls into it and then returns the heap size. (The actual deallocation still happens in swift_release--I talked to John about that and I'll fix it later.) This gets the broken SIL/IRGen class tests passing again.

Swift SVN r3838
2013-01-22 23:36:37 +00:00
Joe Groff
5852448152 IRGen: Generate SIL ctor and property decls.
Remove the filter that only irgenned SIL functions for FuncDecls so that we emit functions for all SIL decls, and disable the old paths for properties, constructors, and destructors when a SIL module is present. Unfortunately this breaks class constructors because SIL and IRGen don't agree on how initializing constructors should work. I need to sync with John to figure out how to fix that.

Swift SVN r3827
2013-01-22 02:45:27 +00:00
Joe Groff
ae396e3905 IRGen: SIL AllocRefInst.
Implement AllocRefInst so that SIL-emitted constructors can be irgenned. Factor the code for allocating a class instance from GenClass's emitClassConstructor function.

Swift SVN r3826
2013-01-22 02:45:25 +00:00
Joe Groff
8c48a3afdd IRGen: Map SIL allocating/initializing ctors.
Now that John's implemented allocating and initializing constructors in irgen, map SIL's representation to irgen's.

Swift SVN r3823
2013-01-21 23:10:08 +00:00
Joe Groff
19d65fede5 IRGen: Visit all SIL Functions in a SILModule.
Make the SIL visitor path a bit less hacky by more cleanly separating the AST walk to find types to codegen from the SIL module walk to find functions to codegen. This way, local functions and other such entry points from SIL actually get generated, and the closures test works.

Swift SVN r3820
2013-01-21 20:17:05 +00:00
Joe Groff
c9d6a351f5 IRGen: SIL ClosureInsts (almost).
Implement lowering of SIL ClosureInsts by packing the partial arguments into a heap allocation and emitting a thunk to unpack them and apply the closure function, similar to curried entry points. The test doesn't work quite yet because nested FuncDecls don't get visited anymore. I need to replace my hacked SIL path with a proper walk of the SIL module to generate functions and the AST to generate types.

Swift SVN r3817
2013-01-20 19:50:10 +00:00
John McCall
3713b6a549 Add a framework for distinguishing between deallocating
and non-deallocating destructors and allocating/non-allocating
constructors.

Non-deallocating destructors might not play well with ObjC
classes;  we might have to limit them to pure-swift hierarchies.

No functionality change except that I decided to not force
destructors to have internal linkage unconditionally.

Swift SVN r3814
2013-01-20 19:40:12 +00:00
Joe Groff
5674cfd0b1 IRGen: SIL literals and zero initialization.
Pick up the remaining low-hanging fruit by implementing irgen for FloatLiteralInst, ZeroValueInst, and ZeroAddrInst.

Swift SVN r3801
2013-01-18 18:02:10 +00:00
Joe Groff
6c6d4dfbdf IRGen: Implement SIL protocol method calls.
Factor out the parts of GenProto's prepareExistentialMemberRefCall necessary to map to SIL's ProtocolMethodInst. Similar to ConstantRefInst, we map the ProtocolMethodInst to an incomplete CallEmission and emit the call when all curry levels have been applied.

Swift SVN r3794
2013-01-18 02:24:26 +00:00
Joe Groff
d2c91a2323 IRGen: SIL protocol type value support.
Factor out the witness table initialization and projection logic from GenProto so that IRGenSIL can use it to implement the ProjectExistential and InitExistential instructions. Also map the CopyAddr and DestroyAddr instructions to value witness table calls so that value semantics on protocol values (and other address-only values) work. The added test compiles but doesn't run yet because invoking methods on a protocol value still requires implementing the ProtocolMethod instruction.

Swift SVN r3787
2013-01-17 23:20:59 +00:00
Joe Groff
1459512901 IRGen: SIL tuple helper instructions.
Implement ElementAddrInst for lvalue tuples, and implement the AllocArray, IndexAddr, and IntegerValue insts used to lower variadic tuples. (Actually compiling code that uses variadic tuples still requires support for SpecializeInst and generic functions.)

Swift SVN r3781
2013-01-17 18:17:39 +00:00
Joe Groff
312e4872e9 IRGen: SIL class accessors.
Implement IRGen for RefElementAddr so that class accessors work. Add a loadUnmanaged method to TypeInfo classes so that we can populate Explosions without accruing unwanted cleanups.

Swift SVN r3779
2013-01-16 22:12:21 +00:00
Joe Groff
7e57041393 IRGen: SIL struct manipulation.
Implement ElementRefInst so that struct accessors work. Also extend SILConstant lowering to support constant_refs to constructors, destructors, and property accessors so that constructor and property accessor references work. (Constructors don't yet get visited by IRGenSIL, though.)

Swift SVN r3776
2013-01-16 19:04:08 +00:00
Joe Groff
30a5493250 IRGen: Lower SIL retain instruction.
Oops, I did release but not retain. Like 'release' it currently just does emitRetainCall without checking if the type in question requires ObjC or some other future kind of memory management.

Swift SVN r3770
2013-01-16 01:20:17 +00:00
Joe Groff
afa65ef3f4 IRGen: SIL function arguments and return values.
Lower arguments and value returns instead of assuming all functions are () -> ().

Swift SVN r3769
2013-01-16 01:20:15 +00:00
Joe Groff
8320df8b9d IRGen: SIL branching and variable allocation.
Implement SIL-to-IR lowering for allocation, deallocation, load, store, and branching instructions so that local variables and branching control flow can be used. Add a Fibonacci loop test to exercise the new instructions.

Swift SVN r3767
2013-01-15 22:32:49 +00:00
Dave Zarzycki
3b1aef5422 Fix an unused variable build warning
Swift SVN r3763
2013-01-14 22:40:23 +00:00
Dave Zarzycki
7c136717a5 Fix a build warning (missing newline at EOF)
Swift SVN r3762
2013-01-14 22:21:43 +00:00
Joe Groff
0970a18e7d IRGen: Compile the toplevel through SIL.
If IRGenModule has a SILModule, use its toplevel Function to emit the top-level code instead of re-walking TopLevelCodeDecls itself.

Swift SVN r3761
2013-01-14 18:33:08 +00:00
Joe Groff
9259c0d912 IRGen: Get "hello world" to compile through SIL.
Add a path through IRGenModule to optionally codegen FuncDecls using their corresponding SIL Functions when constructed with a SILModule. Jury-rig an IRGenSILFunction subclass of IRGenFunction that does the bare minimum necessary to compile "hello world" from SIL. There are some impedance mismatches between irgen and SIL that need to be smoothed out, particularly the AST-dependent way irgen currently handles function calls. Nonetheless, `swift -sil-i hello.swift` works!

Swift SVN r3759
2013-01-14 02:57:11 +00:00