Commit Graph

9293 Commits

Author SHA1 Message Date
Joe Groff
b5c42d9876 SILGen: Consume address-only arguments in-place.
If an address-only argument doesn't need a box, we can just bind the address we were passed to the argument variable directly. We only need to destroy_addr the value when it goes out of scope.

Swift SVN r4929
2013-04-27 03:45:26 +00:00
John McCall
268eb42f46 Fix a bug with the SIL-generation of generic tuples.
Reviewed by Joe.

Swift SVN r4928
2013-04-26 23:47:45 +00:00
John McCall
5cd2af74ae Add a newline after the pretty stack trace for a SILFunction.
Swift SVN r4921
2013-04-26 18:48:35 +00:00
Joe Groff
54e101c517 SIL: Give BuiltinFunctionRef its own instruction.
We don't want to have to recover from a mangled name whether a function call is to an IRGen-lowered builtin, so add an instruction for referencing builtins.

Swift SVN r4919
2013-04-26 18:36:47 +00:00
Joe Groff
f3b6f9cb4f SILGen: Don't emit super_method for non-dynamic super calls.
We won't be able to easily lower super_method to a static call in IRGen when we pre-mangle symbols, so move the logic to determine whether a super call requires dynamic dispatch up to SILGen.

Swift SVN r4913
2013-04-25 22:32:04 +00:00
Joe Groff
0f0dd62d52 SILGen: Hook up emission of ZeroValueExprs.
Turn ZeroValueExprs that were created for implicit constructors into SIL BuiltinZeroInsts. Fixes <rdar://problem/13733107>.

Swift SVN r4912
2013-04-25 21:39:12 +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
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
Doug Gregor
a91941b635 Introduce assignments into the implicitly-defined default constructor body.
Add assignment statements into the implicitly-defined default
constructor body to initialize all of the members appropriately, e.g.,
by calling the default constructor. For builtin types and class types,
introduce ZeroValueInitExpr to produce a "zero" value.

ZeroValueInitExpr still needs a representation in SIL. Until then,
actual generation of this AST is suppressed.



Swift SVN r4895
2013-04-25 00:00:28 +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
36b02ac22b SILGen: Stub out implicit default ctor codegen.
Emit a zero-initialization for now, just so SILGen doesn't crash when it sees an implicit default ctor.

Swift SVN r4878
2013-04-24 16:02:37 +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
d764059b3e SILGen: Do 'emit into' optimization of calls.
Hand the SGFContext, with the current 'emit into' Initialization, down into the CallEmission machinery so that it can be used to emit indirect returns directly into their uninitialized destination buffers without an intermediate copy.

Swift SVN r4863
2013-04-22 23:56:28 +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
11109a9376 SILGen: Implement switch statements.
This should bring SILGen up to feature parity with the old backend. This implementation also now supports fallthrough.

Swift SVN r4858
2013-04-22 01:10:06 +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
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
Joe Groff
ce75e47139 SIL: Add instructions for RetainAutoreleased and AutoreleaseReturn.
Swift SVN r4821
2013-04-19 02:03:31 +00:00
Joe Groff
5be9883d82 SILGen: Be less cavalier with ownership near function applications.
Don't take for granted that function applications consume their arguments when emitting the object pointer argument of array injections or the function argument of applications. That's not going to be the case for ObjC methods.

Swift SVN r4812
2013-04-18 23:08:33 +00:00
Joe Groff
15b1b4eccb SILGen: Fix order of operations with ApplyExprs.
Evaluating all the arguments before uncurrying the function is wrong if the function can't be completely uncurried. Tweak CallEmission so it can work in Exprs instead of already-evaluated RValues and evaluate them in the right order relative to the function applications it emits. This also makes it easier to emit more accurate location info for each of the apply instructions.

Swift SVN r4811
2013-04-18 22:40:23 +00:00
Joe Groff
d0266e35c7 SILGen: Don't emit calls to objc super destructors
ObjC classes don't have a deallocating destructor, so we can't call up to it in a class derived from an ObjC class. Hack SILGen not to emit a call to the superclass destructor of a class inherited from an ObjC class. This is the wrong thing, but it looks like destructors don't get hooked up to ObjC dealloc methods anyway yet, so what the Swift destructor of an ObjC-derived class does is moot right now. This lets us remove the guards from IRGen that prevented ObjC destructors from being emitted.

Swift SVN r4784
2013-04-17 22:52:59 +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
Joe Groff
2aa41b72ed SILGen: Emit fixed-lifetime local vars to stack.
If capture analysis deems a local variable fixed-lifetime, we don't need to put it in a box and can instead locally stack-allocate and destroy it.

Swift SVN r4756
2013-04-16 22:06:43 +00:00
Joe Groff
ded5883eb4 SILGen: Fix infinite destructor loop.
Putting 'this' in a box causes 'this' to be released with the box at the end of the destructor and infinite-loop. Double-retain it to work around this. Gross.

Swift SVN r4752
2013-04-16 02:45:45 +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
2dea0de6f0 SILGen: Box 'this' in constructors and destructors
This is unfortunate (and wrong--this really shouldn't be capturable out of a ctor or dtor), but is needed for now in order for auto_closures over 'this' to work with SILGen's current naive handling of local variables and captures.

Swift SVN r4735
2013-04-14 21:41:04 +00:00
Joe Groff
88d5192a69 SILGen: Don't crash if FuncDecls lack bodies.
FuncDecls for builtins don't have bodies. Deal with this when determining function natural uncurry levels and captures for SILGen.

Swift SVN r4734
2013-04-14 19:45:02 +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
8ee0fb4e96 SILGen: Zero-initialize structs in constructors.
Otherwise we try to release junk pointers when we reassign class fields in the struct. Add an attribute to InitializeVarInst so that when dataflow analysis comes online, it knows that these InitializeVars need to be eliminated and can't be lowered to default constructor calls (since we're already in a constructor).

Swift SVN r4730
2013-04-13 20:45:18 +00:00
Joe Groff
700615e864 SIL: Don't leak byref(heap) into closure types.
It causes IRGen to do the wrong thing, and we want to kill byref(heap).

Swift SVN r4729
2013-04-13 20:45:15 +00:00
Joe Groff
7406986487 SILGen: Class constructors need to return modified self.
-[NSMutableArray init] modifies self, causing NSStringDemo to fail when sil-irgenned because SILGen didn't handle constructors changing 'this' correctly.

Swift SVN r4728
2013-04-13 19:21:10 +00:00
Joe Groff
4cdcdba22e SIL: Add BridgeToBlockInst.
And in SILGen, lower BridgeToBlockExprs to BridgeToBlockInsts.

Swift SVN r4723
2013-04-13 17:05:38 +00:00
Joe Groff
6786b66dcc SILGen: Emit unapplied DeclRefs at curry level 0.
And don't let ParenExprs or CoerceExprs screw up the uncurrying optimization.

Swift SVN r4721
2013-04-12 23:49:06 +00:00
Joe Groff
f6c72885a6 SILGen: Emit curried function calls.
Teach SILGen's CallEmission how to emit calls to an uncurry level above the natural uncurry level of the callee. Factor out a Callee object (like in IRGen) that encapsulates how to emit an abstract callee at any uncurry level. Currently only currying standalone non-generic functions works.

Swift SVN r4720
2013-04-12 23:10:48 +00:00
Joe Groff
887cb4f40f SIL: ThinToThickFunction can't alter uncurry level
Verify that ThinToThickFunction's operand and result types match uncurry level.

Swift SVN r4719
2013-04-12 23:10:46 +00:00
John McCall
5724427a40 Assert dominance in the verifier.
Swift SVN r4718
2013-04-12 22:33:03 +00:00
John McCall
dd4f26c6dc It does seem to make non-generic assumptions about the node
type, though;  I had to define a WriteAsOperand function and
add a front() method to SILFunction to get this to work.
Rip out my dominators implementation and replace it with
LLVM's.  I'd forgotten that LLVM's was actually generic.

Swift SVN r4717
2013-04-12 21:24:27 +00:00
Joe Groff
6e8ec92b4a SILGen: Emit curry thunks for standalone functions
For non-generic, non-property, non-instance-method curried functions, emit SIL thunks for all of the intermediate curry levels. The generic, property, and instance method cases need some additional SIL and irgen work to support, but aren't well supported by the current backend, so I'll leave them to be dealt with later. This causes the SliceUInt8 test to break down in IRGen; I'll fix that next.

Swift SVN r4715
2013-04-12 20:47:14 +00:00
Joe Groff
bc2abab6d1 SIL: Add SILValue::dumpInContext.
Dumps an instruction with its operands and users. Useful for debugging.

Swift SVN r4713
2013-04-12 16:36:25 +00:00
John McCall
3274de9c21 Add a simple dominance analysis based on Cooper, Harvey, and
Kennedy (2001).

This hasn't been tested yet.

Swift SVN r4712
2013-04-12 08:15:09 +00:00
John McCall
c6f42a03db Don't use assert directly in the SIL verifier; use a
different routine which tries to print some extra context
before triggering an assert.

For now, this is just the instruction and its basic block,
but I think a nicer output would be something like
    %0 = ...
    %1 = ...
->  %2 = ...
    %3 = ...
    br ...

Swift SVN r4711
2013-04-12 06:08:06 +00:00
John McCall
8dca52a2b0 Enhance the verifier to verify some basic properties of uses.
Also, refactor it to make it completely painless to introduce
new checks at arbitrary levels in the hierarchy.

Swift SVN r4710
2013-04-12 05:39:02 +00:00
Joe Groff
f59026e3fd SILGen: Fix double-free of exploded tuple elts.
Might be a good idea to kill the cleanup on the tuple rvalue when exploding it.

Swift SVN r4708
2013-04-12 03:12:53 +00:00
Joe Groff
65933e7eac SILGen: Add globals to module when we see VarDecls
Rather than when we initialize them while visiting the PatternBindingDecl. That's dumb.

Swift SVN r4706
2013-04-12 03:12:47 +00:00
John McCall
7e15f0a557 Make SIL-visiting not have a default implementation, make classof
take a const ValueBase* instead of a SILValue, implement SILArgument
cases for a few visitors and opt others out explicitly, and assert
that classes in the SIL value hierarchy override their superclass's
classof.

Swift SVN r4705
2013-04-12 01:39:52 +00:00
John McCall
f9226a8178 Add a getAllOperands() method to SILInstructions.
Required some renaming of the internal field-selector constants
to avoid inadvertent shadowing.

Swift SVN r4703
2013-04-12 00:54:53 +00:00
Joe Groff
bbb07912b1 SILGen: Emit all global variables as addresses.
For now, lazy-initializing global accessor functions aren't really a thing, so just emit all global variable references as global addresses.

Swift SVN r4701
2013-04-12 00:13:16 +00:00
Joe Groff
950ca1c929 SIL: Print type of string_literal insns.
string_literal can have a two-element tuple type (with any labels) or a Builtin.RawPointer type, so print the type of the string_literal when emitting SIL.

Swift SVN r4699
2013-04-12 00:00:48 +00:00