Commit Graph

6634 Commits

Author SHA1 Message Date
Chris Lattner
e4ccec4cfc rename SILBAse.h -> SILAllocated.h and SILBase.cpp -> SILModule.cpp to
reflect their contents.


Swift SVN r5198
2013-05-17 04:25:49 +00:00
Chris Lattner
fa9adc72ed merge SILBase into SILModule, the only class that derives from it.
Swift SVN r5197
2013-05-17 04:22:00 +00:00
Chris Lattner
f018610708 some obsessive formatting changes, 80 column fixes, etc.
no functionality change.


Swift SVN r5196
2013-05-17 04:05:15 +00:00
Chris Lattner
611a3a97db Parse sil linkage types, and actually create the SILFunction parsed.
This gets us prototypes parsing and printing, though types aren't
correct at all yet.



Swift SVN r5192
2013-05-16 22:48:07 +00:00
Joe Groff
c4317411b6 IRGen: Use SILType in functions used for existential container insts.
Swift SVN r5191
2013-05-16 22:47:49 +00:00
Chris Lattner
4b8f53ef42 allow random clients to 'new' SILFunctions.
Swift SVN r5190
2013-05-16 22:36:22 +00:00
Chris Lattner
63e2a60585 rename Module:: and Function::getContext to ::getASTContext()
This matches SILType and is more explicit about which context
we're talking about.


Swift SVN r5185
2013-05-16 20:14:13 +00:00
Chris Lattner
21a3b9d246 remove two helper forwarding methods from SILFunction
one is dead, the other isn't helpful enough to persist.


Swift SVN r5184
2013-05-16 20:07:53 +00:00
Chris Lattner
3facf741fa move SILFunction implementation goop out into SILFunction.cpp
and make the SILFunction ctor public since SIL is an optimization
IR, not just a transient by product of IRGen. :)


Swift SVN r5183
2013-05-16 19:59:01 +00:00
Joe Groff
d5784307d2 SILGen: Emit objc_msgSend-able thunks in SIL.
Emit thunks for [objc] class methods and properties as SILFunctions, using SILGen's OwnershipConventions. This will help kill some redundant ownership code in IRGen, and will allow msgSend thunks to handle string and block bridging. IRGen doesn't actually codegen the thunks yet; that will require teaching IRGenSILFunction how to be AbstractCC-aware, so for now, we just reemit the thunks using the old IRGen code.

Swift SVN r5168
2013-05-14 01:22:12 +00:00
Joe Groff
d2e18f74c8 SIL: ArchetypeMethodInst doesn't need a value operand.
Archetype methods can be looked up from the local witness tables for the archetype independent of an object.

Swift SVN r5152
2013-05-10 22:26:22 +00:00
Joe Groff
667ef5d651 IRGen: Look up metatypes and class methods using SIL types.
Swift SVN r5150
2013-05-10 21:20:11 +00:00
Joe Groff
c012c2e1ce IRGen: Add 'Callee::forKnownFunction' for SIL types.
Swift SVN r5145
2013-05-10 18:18:12 +00:00
Jordan Rose
f6822e8c53 Fix -Wdocumentation issues.
No functionality change.

Swift SVN r5127
2013-05-09 21:40:33 +00:00
Joe Groff
e1c838962e Revert "Remove [objc_block] attribute from Swift type system."
Implementing SIL bridging is going to take more IRGen work than I anticipated.

Swift SVN r5113
2013-05-09 16:32:18 +00:00
Joe Groff
bcf510e30b SIL: Remove 'getPreLoweredType' from SILType.
We don't need this hole to bypass SIL TypeLowering anymore.

Swift SVN r5094
2013-05-08 18:26:38 +00:00
Joe Groff
38f13e56f5 Remove [objc_block] attribute from Swift type system.
We will handle Swift-function-to-ObjC-block bridging in SILGen as part of general Cocoa-to-Swift type bridging. Temporarily disable building swiftAppKit and tests that exercise block bridging until the new implementation lands.

Swift SVN r5090
2013-05-08 16:52:12 +00:00
Joe Groff
f79e939460 SIL: Sever load-bearing links to the AST.
Make IntegerLiteral, FloatLiteral, and StringLiteral own their own copies of their values so they don't depend on the AST. Remove the now-redundant IntegerValueInst, which only existed to be a non-AST-dependent variant of IntegerLiteral.

Swift SVN r5045
2013-05-06 03:08:58 +00:00
Chris Lattner
d2a8cffd9c remove an unneeded #include and some llvm:: qualifiers
Swift SVN r4966
2013-04-28 16:07:19 +00:00
Joe Groff
5b4519d12b Mangle operator fixity and tuple variadicity.
Tweak the mangling rules to fix some collisions I found:

- Mangle variadic tuples with a lowercase 't' to distinguish them from nonvariadic tuples with a slice as their final element.
- Mangle the fixity of operators using 'op' for prefix, 'oP' for postfix, and 'oi' for infix, so that operator declarations that differ only in fixity can coexist.

While we're here, 'Slice' seems worthy of a standard substitution, so mangle it to 'Sa'.

This fixes <rdar://problem/13757744> and <rdar://problem/13757750>.

Swift SVN r4965
2013-04-28 15:48:18 +00:00
Joe Groff
0566088bf2 Move name mangling into SIL.
Sever the last load-bearing link between SILFunction and SILConstant by naming SILFunctions with their mangled symbol names. Move the core of the mangler up to SIL, and teach SILGen how to use it to mangle a SILConstant.

Swift SVN r4964
2013-04-28 03:32:41 +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
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
ace9586c36 Reinstate the use of enable_if within SIL's UnaryInstructionBase using class templates rather than constexpr.
Swift SVN r4903
2013-04-25 03:28:14 +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
Doug Gregor
80cfdf7e39 Remove std::enable_if magic from UnaryInstructionBase. The current
production Clang can't handle it. 


Swift SVN r4866
2013-04-24 04:46:14 +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
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
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
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
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
4cdcdba22e SIL: Add BridgeToBlockInst.
And in SILGen, lower BridgeToBlockExprs to BridgeToBlockInsts.

Swift SVN r4723
2013-04-13 17:05:38 +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
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
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
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
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