Commit Graph

1069 Commits

Author SHA1 Message Date
Chris Lattner
5a3a99e78a remove a dead "CurConstant" ivar, simplify some code to make it fit in 80 columns.
Swift SVN r4744
2013-04-15 23:14:04 +00:00
Joe Groff
c217d69779 IRGen: Fix ArchetypeMethodInst for static funcs.
The argument to archetype_method can be a metatype, so allow that. While we're here, implement lowering for AssociatedMetatypeInst, and fix initial bringup of SIL-IRGen so that polymorphic arguments get emitted into the entry point BB instead of a random other BB.

Swift SVN r4741
2013-04-15 22:21:45 +00:00
Joe Groff
a90338bddb IRGen: Compile builtin calls from SIL.
When lowering SIL builtin ConstantRefs, just stash away the FuncDecl, and pass that decl on to a tweaked version of emitBuiltinCall when the constant is applied.

Swift SVN r4736
2013-04-15 21:04:36 +00:00
Joe Groff
9ff03ec06d SILGen: Stub out support for oneof elements.
Add a OneOfElement kind to SILConstant so we can at least reference Bool's element constructors.

Swift SVN r4733
2013-04-14 16:43:13 +00:00
Joe Groff
1fcf2237af SILGen: Emit global variable initializers.
Emit global initializers into the 'toplevel' function in a library TU, which IRGen will then wire up to a global constructor.

Swift SVN r4732
2013-04-14 15:31:35 +00:00
Joe Groff
69fb051811 IRGen: Lower SIL BridgeToBlockInst.
Swift SVN r4724
2013-04-13 17:22:48 +00:00
Joe Groff
eae9dd9214 IRGen: Fix PartialApply forwarder w/empty context.
Partial application forwarders don't take an ExtraData argument if the context layout is empty.

Swift SVN r4716
2013-04-12 21:04:49 +00:00
Joe Groff
88ada373c9 IRGen: Don't emit ConstantRefs to empty globals.
We don't emit empty global variables, so we shouldn't emit references to them either.

Swift SVN r4707
2013-04-12 03:12:51 +00:00
Joe Groff
01a1461e3b IRGen: Emit StringLiteralInst w/o size correctly.
If the StringLiteralInst type isn't a tuple, emit the literal string pointer without the size.

Swift SVN r4700
2013-04-12 00:00:50 +00:00
Joe Groff
9ff6e65af0 IRGen: Lower SIL ArchetypeMethodInst.
ArchetypeMethodInst, like ProtocolMethodInst, actually needs to be modeled as returning a thick function type, in order to represent the metadata parameter to the witness table function. With that change to SILGen, implement ArchetypeMethodInst IRGen.

Swift SVN r4688
2013-04-11 22:24:26 +00:00
Chris Lattner
7f13910498 revert r4673: respecializing SILConstant for ValueDecl instead of Decl.
On second thought, having SILConstant be able to point to a TLCD is going 
against the goal of making SILConstant be a "SILGen thing".  I'll find another
approach.


Swift SVN r4680
2013-04-11 17:41:36 +00:00
Chris Lattner
f4dfaed4cf generalize SILConstant to hold a Decl*, not just a ValueDecl*.
This is in preparation to allow SILConstant of TopLevelCodeDecl.



Swift SVN r4675
2013-04-11 00:46:36 +00:00
Joe Groff
873a0f0c9c IRGen: Fix assert when applying Specialize.
The callee can be AnyFunctionType, not just a concrete FunctionType.

Swift SVN r4673
2013-04-11 00:16:59 +00:00
Joe Groff
6582b406c4 IRGen: Fix reference invalidation bug in SIL SpecializedValue.
Don't capture references into DenseMaps, you dummy.

Swift SVN r4610
2013-04-05 18:03:42 +00:00
Joe Groff
bb1f516555 IRGen: Lower SIL SpecializeInsts.
Collect the substitutions from SpecializeInsts and use them when emitting an ApplyInst to pass archetype parameters and to reexplode arguments at the right abstraction level for the generic callee. Unfortunately, ArchetypeTypeInfo::allocate() is broken, so alloc_box $T for an archetype type T doesn't yet work.

Swift SVN r4597
2013-04-04 22:39:35 +00:00
Joe Groff
aeeda4ee12 Parser: Parse operator decls.
At the top level, if 'operator' is followed by 'infix', 'prefix', or 'postfix', consider it a contextual keyword, and parse an operator decl following it that looks like:

  operator {infix|postfix|prefix} <+> {
    attributes…
  }

Prefix and postfix operator decls currently admit no attributes. Infix operators have 'associativity {left|right|none}' and 'precedence <int>' attributes.

This patch implements parsing for operator declarations but does not yet attach the declared attributes to func decls for the operators.

Swift SVN r4596
2013-04-03 23:30:50 +00:00
Chris Lattner
a71bc3a78e rename Value -> SILValue, BasicBlock -> SILBasicBlock, BBArgument -> SILArgument.
Swift SVN r4594
2013-04-03 21:05:42 +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
3a9100f559 SIL: Clean up SILType interface for functions.
Function and compound types have a bunch of extra calling convention and uncurrying info stuffed into a "SILTypeInfo" object that until now had to be fetched through the SILModule. Change the representation of SILType to be a PointerUnion of CanType and SILTypeInfo*, and move the uncurry level onto the SILTypeInfo for functions, so that SILTypeInfo is available directly through the SILType and SILType can go back to being pointer-sized.

Swift SVN r4582
2013-04-03 02:33:29 +00:00
Joe Groff
c724d1f6a1 IRGen: Emit SIL class metatypes as Swift or ObjC.
Look at the uses of a SIL MetatypeInst to determine whether it is being used as a Swift metatype and/or ObjC class and emit the needed values. This avoids a costly trip wrapping and unwrapping ObjC Classes in a Swift metatype when they're just used to invoke class methods.

Swift SVN r4562
2013-04-01 22:10:12 +00:00
Joe Groff
0034475514 IRGen: Map SIL metatypes back to ObjC classes.
For ObjC class method calls, map a metatype value back to an objc Class before emitting the ObjC call. This is dumb because we already map the original Class to a Swift metatype when we map the metatype instruction, but it gets ObjC class method calls working. Now that SIL keeps use chains, we could be easily smarter about this.

Swift SVN r4558
2013-03-30 23:40:35 +00:00
Joe Groff
d6b30f71f0 IRGen: Fix SIL MetatypeInst lowering.
We were emitting the metatype of the metatype. Oops.

Swift SVN r4557
2013-03-30 22:48:18 +00:00
Joe Groff
02de4d8007 IRGen: Handle ownership conventions from SIL apply
Introduce cleanups onto arguments to SIL apply instructions, and let CallEmission consume the cleanups corresponding to the values consumed by the called function, so that releases will be emitted as needed to make a foreign call conform to Swift ownership conventions.

Swift SVN r4556
2013-03-30 22:48:16 +00:00
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