Commit Graph

1696 Commits

Author SHA1 Message Date
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
d0e0911ecf SIL: Add builtin_zero instruction.
To represent the zero value of builtin types.

Swift SVN r4907
2013-04-25 19:50:56 +00:00
John McCall
c3eae4ae04 Make it convenient to generate an undef address.
For most types, this is really only useful in the presence of
an unimplemented operation, but for empty types this does come
up quite reasonably.

Swift SVN r4897
2013-04-25 01:39:30 +00:00
Chris Lattner
ea36e8c7d2 remove loadUnmanaged, it is now identical to loadAsTake.
Swift SVN r4896
2013-04-25 00:44:30 +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
Joe Groff
b761bad088 SILGen: Lower some builtins to SIL.
The value semantics primitives load/move/assign/init/destroy lower trivially to SIL value semantics operators, and the bridge casting operations introduce r/r semantics that should be visible to the ARC optimizer, so move the lowering for these builtins up to SILGen. Add a BUILTIN_SIL_OPERATION metaprogramming macro to Builtins.def, and add a facility similar to IRGen's former SpecializedCallEmission so we can handle builtin call emissions as special cases.

This also sets up the framework for eventually reintroducing special-case handling of known functions like &&, ||, Bool.getLogicValue, Int.convertFromIntegerLiteral, etc. in SILGen.

Swift SVN r4862
2013-04-22 23:05:18 +00:00
Joe Groff
50b4b945bd IRGen: Emit objc super.ctor using msgSendSuper (again).
We weren't considering objc initializing constructors to be ObjC in SIL-IRGen. Oops.

Swift SVN r4861
2013-04-22 15:58:00 +00:00
Joe Groff
d50134d757 IRGen: Fix crash when returning protocol value.
The resultType of a function call from IRGen::CallEmission's point of view is still its Swift return type, which is different from the ApplyInst's result type when an apply instruction has an indirect return. Fix that, and un-XFAIL the parts of test/IRGen/protocols.swift that test witness table and witness method emission.

Swift SVN r4860
2013-04-22 15:42:33 +00:00
Joe Groff
e7f7df3027 Implement 'x is T' in SILGen.
Add an IsaInst to represent type tests, and implement SILGen for IsSubtypeExpr AST nodes. Get rid of SuperIsArchetypeExpr because it's not really necessary to have it different from IsaSubtype--the SIL and IR behavior is identical.

Swift SVN r4855
2013-04-21 20:33:54 +00:00
Joe Groff
f211c1d3d2 SIL: Factor out boilerplate from unary insns.
Create a UnaryInstructionBase that factors all the boilerplate out of all the unary instructions. It'll be easy to generalize to all fixed-arity instructions, but let's start simple. No functionality change.

Swift SVN r4854
2013-04-21 18:58:35 +00:00
Chris Lattner
2b6902b232 eliminate the "manage" operation on TypeInfo, which is now a (complicated!) noop.
Swift SVN r4850
2013-04-21 16:27:43 +00:00
Chris Lattner
85663f6df2 simplify Explosion by eliminating (now) copies of existing methods.
This removes addUnmanaged, ignoreAndDestroy, ignoreUnmanaged, claimUnmanagedNext,
claimUnmanaged, forwardNext, and forward


Swift SVN r4846
2013-04-21 06:29:50 +00:00
Chris Lattner
9ae0cf3bee inline Initialization::emitLocalAllocation into each of its callers and
eliminate the Initialization class and GenInit.h.  GenInit.cpp will stay
around, as it has some other random stuff in it.


Swift SVN r4845
2013-04-21 06:13:59 +00:00
Chris Lattner
d523932d85 remove InitializedObject.
Swift SVN r4844
2013-04-21 06:05:01 +00:00
Chris Lattner
0be7bbdddf remove ManagedValue.
Swift SVN r4843
2013-04-21 05:56:02 +00:00
Chris Lattner
510042f939 removed the registration logic from Initialization and Depth from Scope.
Swift SVN r4842
2013-04-21 05:39:35 +00:00
Chris Lattner
e8686c9560 remove Cleanups from IGF, simplify Initialization a bit.
Swift SVN r4841
2013-04-21 05:28:04 +00:00
Joe Groff
916ae36f7e Don't reemit globals from previous repl entries.
Oops. This should fix <rdar://problem/13694699>.

Swift SVN r4835
2013-04-20 23:50:36 +00:00
Joe Groff
e5068920bb SILGen: Handle ObjC ownership conventions of calls
Port IRGen's calculation of consumed arguments and return value semantics to SILGen, and use it to handle the ownership semantics of calls. Refactor the handling of properties and other clients of emitApply so they can properly hand ownership semantics down to it.

This should let all the moribund cleanup management code in IRGen die. Unfortunately Scope appears to be tied into scoped calculated metadata caching so it's not quite ready to die.

Swift SVN r4834
2013-04-20 23:13:42 +00:00
Chris Lattner
80565c63a0 fix an IRGen crash on multiple local decls. Noticed by inspection.
Swift SVN r4820
2013-04-19 00:13:17 +00:00
Chris Lattner
35edbcd29e prune some minor dead Stmt stuff.
Swift SVN r4818
2013-04-19 00:09:51 +00:00
Chris Lattner
abee79b26e remove some Expr stuff.
Swift SVN r4810
2013-04-18 22:32:37 +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
John McCall
8fe4246833 Hide StorageSize/Alignment behind accessors in preparation for moving
them to a subclass.

Swift SVN r4779
2013-04-17 21:55:41 +00:00
Joe Groff
b9bb84c58e SILGen: Emit implicit constructors.
Teach SILGen how to emit the implicit elementwise constructor for structs and the implicit default constructor for classes, and eliminate the now dead IRGen code for them. Add a StructInst SIL instruction to represent constructing a loadable struct value from elements, analogous to TupleInst for tuples.

Swift SVN r4778
2013-04-17 20:51:26 +00:00
Chris Lattner
7588b99869 add a pre-mangled name to the top level function, some more minor
style changes to fit in 80 columns etc.  No useful behavior change.



Swift SVN r4748
2013-04-16 00:44:57 +00:00
Joe Groff
7dde07cfd3 IRGen: Lower SIL ArchetypeToSuper (and v.v.).
Swift SVN r4747
2013-04-15 23:32:46 +00:00
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