Commit Graph

9332 Commits

Author SHA1 Message Date
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
Joe Groff
03610fab6c SILGen: Emit DeclRefExprs using the expr type.
This gets the right type for generic-parameterized DeclRefExprs.

Swift SVN r4693
2013-04-11 23:20:32 +00:00
Joe Groff
6a516363cf SIL: Verify TupleInst elements.
The element types should match the corresponding field types of the result tuple type.

Swift SVN r4692
2013-04-11 23:20:30 +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
Joe Groff
a33ab2ee16 SIL: Verify DowncastInsts harder.
Doug found that the verifier would admit a DowncastInst that took an lvalue as the input, which is bogus. Refine the verifier rules for DowncastInst so it only admits class rvalues and destination types.

Swift SVN r4685
2013-04-11 21:40:11 +00:00
Joe Groff
44eaa29ff9 SILGen: Forward archetypes from alloc to init ctor
During type checking, fake up a "forwarding" substitution set for constructor decls that maps archetypes to themselves. This is goofy, but type-checking is the place that knows how to make ProtocolConformances, and I don't want to reinvent that. Use these forwarding substitutions in SILGen when emitting a generic allocating constructor so we can properly emit a call to the corresponding initializing constructor.

Swift SVN r4684
2013-04-11 21:40:09 +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
fd14aa423a SILGen: Consistently handle stores and assigns.
Factor out the logic for properly storing a loadable or address-only rvalue into ManagedValue::forwardInto and ManagedValue::assignInto, and use those methods everywhere instead of trying to cut corners and directly emit store instructions.

Swift SVN r4670
2013-04-10 23:48:00 +00:00
Joe Groff
7a0d879307 SILGen: Handle tuple explosions systematically.
Introduce an 'RValue' object in SILGen that behaves like a simplified version of IRGen's 'Explosion' object, holding a destructured tuple in a naturally destructured state. This cleans up a bunch of ad-hoc scattered code that destructured tuples in various places. Update SILGenFunction so that the expression visitors all pass around RValues, and update CallEmission to handle argument clauses as RValues instead of a pre-destructured string of arguments. Implement "emit into" optimization of TupleExpr and ScalarToTupleExpr, now that that's easy to do.

Swift SVN r4667
2013-04-10 23:00:18 +00:00
Joe Groff
bfd2f85b5c Parse 'fallthrough' statements.
Create a new FallthroughStmt, which transfers control from a 'case' or 'default' block to the next 'case' or 'default' block within a switch. Implement parsing and sema for FallthroughStmt, which syntactically consists of a single 'fallthrough' keyword. Sema verifies that 'fallthrough' actually appears inside a switch statement and that there is a following case or default block to pass control to.

SILGen/IRGen support forthcoming.

Swift SVN r4653
2013-04-10 17:30:42 +00:00
Joe Groff
9a98f9353d SILGen: Remove hack to convert toplevel code type.
All SILTypes now reliably convert through the same mechanism, so this hack isn't needed anymore.

Swift SVN r4628
2013-04-07 02:42:54 +00:00