Commit Graph

800 Commits

Author SHA1 Message Date
Joe Groff
f24add3175 SIL: Give Unreachable instructions SILLocation info.
UnreachableInst's constructor didn't take a SILLocation. Oops. Fix that, and associate Unreachables emitted due to failed switch coverage with the switch. For missing-return Unreachables, there isn't yet readily available SILLocation info to attach to them, but Anna will fix that soon.

Swift SVN r6132
2013-07-10 21:54:37 +00:00
Joe Groff
4bbf608e8f SILGen: Implement variable bindings.
As clause matrix specialization exposes columns with variable bindings, bind all of the variables in each column to a new box for the variables in that column. (Since only one row out of the matrix ever ends up getting executed, we can share one box for the entire column.) Set up a scope hierarchy following that of the specialized clause matrices, and associate each case with the scope it needs to see all the variables of its fully-destructured pattern clause. Remove our ad-hoc hack for binding ExprPattern implicit variables, and bind them to the column's box too.

Swift SVN r6127
2013-07-10 19:09:58 +00:00
Adrian Prantl
de32b201d0 Debug Info: Add support for subprograms.
This means that single-stepping in lldb actually works now!

Swift SVN r5828
2013-06-27 00:46:30 +00:00
Adrian Prantl
5cf577282d Debug Info: Wire up more compile unit metadata and clean up the code a bit.
Swift SVN r5794
2013-06-25 00:19:32 +00:00
Adrian Prantl
05976c9612 Fix a typo that I would have caught with an asserts build..
Swift SVN r5773
2013-06-23 02:35:27 +00:00
Adrian Prantl
0f7533dc7e Debug Info! Add basic support for line tables, compilation units, files,
and lexical scopes, which can be enabled through the new -g option.
When -g is enabled, line tables and scopes compile all the way
down to DWARF.

Changes to SIL:
- In addition to a SILLocation, every instruction now also has a pointer
  to a SILDebugScope (its containing lexical scope).
- Added LexicalScope, which is to be used for all Scopes we want to show
  up in the debug info.

Swift SVN r5772
2013-06-23 00:09:17 +00:00
Joe Groff
f072c48e45 Refactor cast representation in AST and SIL, and implement 'is'.
Improve our representations of casts in the AST and SIL so that 'as!' and 'is' (and eventually 'as?') can share almost all of the same type-checking, SILGen, and IRGen code.

In the AST, we now represent 'as!' and 'is' as UnconditionalCheckedCastExpr and IsaExpr, respectively, with the semantic variations of cast (downcast, super-to-archetype, archetype-to-concrete, etc.) discriminated by an enum field. This keeps the user-visible syntactic and type behavior differences of the two forms cleanly separated for AST consumers.

At the SIL level, we transpose the representation so that the different cast semantics get their own instructions and the conditional/unconditional cast behavior is indicated by an enum, making it easy for IRGen to discriminate the different code paths for the different semantics. We also add an 'IsNonnull' instruction to cover the conditional-cast-result-to-boolean conversion common to all the forms of 'is'.

The upshot of all this is that 'x is T' now works for all the new archetype and existential cast forms supported by 'as!'.

Swift SVN r5737
2013-06-21 05:54:03 +00:00
Joe Groff
a56be726da SILGen: Set [volatile] attribute on ObjC method dispatches.
Tag ObjC dynamic method dispatch instructions so that future optimizers know they can't be devirtualized.

Swift SVN r5728
2013-06-20 22:17:34 +00:00
Joe Groff
665cbf56c1 IRGen: Implement conversions between class protocol types.
Implement existential upcasts from a class-bounded protocol type to a more general one.

Swift SVN r5673
2013-06-19 02:46:29 +00:00
Joe Groff
ff5f41b5f0 Archetypes with superclass bounds are class-bounded.
Treat archetypes with a superclass bound as class-bounded. Change SILGen and IRGen to use the new SuperToArchetypeRef and ArchetypeRefToSuper cast instructions, and drop the old SuperToArchetype and ArchetypeToSuper instructions, which are unneeded because any archetype with a superclass will be class-bounded.

Note that this patch doesn't implement representation optimization for archetypes with superclass bounds--they're still always represented with a worst-case UnknownRefCountedPtrTy.

Swift SVN r5629
2013-06-17 21:54:01 +00:00
Joe Groff
7420089303 SIL: Add instructions to represent generic dynamic casts.
Add Downcast{Archetype,Existential}{Addr,Ref} instructions to represent casting of archetypes and existentials to concrete types.

Swift SVN r5612
2013-06-17 01:23:55 +00:00
Joe Groff
e1b70c8def SILGen: Method calls on class-bound existentials.
Tweak things so that looking up methods and projecting 'this' from a class-bound existential works.

Swift SVN r5556
2013-06-10 01:50:32 +00:00
Joe Groff
2ce2d33a64 SIL: Add instructions for class-bound archetype/existential operations.
Add class-bound versions of archetype conversion and existential creation/projection/conversion instructions. Since class-bound generics aren't address-only these instruction variants don't need to indirect through addresses.

Swift SVN r5554
2013-06-09 18:12:43 +00:00
Joe Groff
b22fd22d57 SILGen: Handle Builtin.gep as a SIL builtin.
Add an index_raw_pointer instruction that acts like index_addr but for RawPointers, and use it to lower Builtin.gep into SIL instead of into IR.

Swift SVN r5479
2013-06-05 16:49:50 +00:00
Joe Groff
ed6b5ad497 SIL: Made index_addr index operand dynamic.
Instead of taking an integer constant index, index_addr now takes a value operand of builtin integer type, which makes more sense.

Swift SVN r5478
2013-06-05 16:49:41 +00:00
Joe Groff
0cb8adb46f SIL: Force all SILInstruction allocations through SILModule.
Delete the non-placement operator new/delete in the SILAllocated CRTP base so that the compiler saves us from accidentally allocating and leaking SILInstructions on the main heap instead of the owning SILModule's BPA.

Swift SVN r5468
2013-06-04 15:32:11 +00:00
Chris Lattner
5350849cbe Parser support for retain/release/retain_autoreleased.
Swift SVN r5357
2013-05-26 23:22:40 +00:00
Chris Lattner
22a14d7214 simplify the ctor for SILBuilder
Swift SVN r5333
2013-05-25 15:21:52 +00:00
Joe Groff
409655e037 SIL: Split tuple/struct field accessor insns.
Split ExtractInst and ElementAddrInst into separate Tuple and Struct versions, and have the Struct versions reference struct member VarDecls directly instead of integer indices.

Swift SVN r5215
2013-05-17 23:34:11 +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
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
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
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
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
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
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
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
442a51ef36 SIL: Fix Verifier.
The Verifier wasn't actually verifying function bodies, because I neglected to visit the actual basic blocks after checking the entry point arguments in verifySILFunction. This revealed a SILType identity issue where TypeConverter::getLoweredType and SILType::getEmptyTupleType returned non-identical SILTypes for the empty tuple type; fix that by removing SILType::getEmptyTupleType, moving TypeConverter into SILModule, and forcing all SILType creation through TypeConverter.

Swift SVN r4616
2013-04-05 22:19:14 +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
1beebda868 move Instruction/BasicBlock/BBArgument files to have SIL prefixes.
Swift SVN r4591
2013-04-03 18:43:54 +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
1f5bdda08f SIL: Add insns for archetype/protocol metatypes.
Archetype and protocol 'x.metatype' expressions eventually need to do a dynamic lookup, like 'x.metatype' for classes. These instructions represent that lookup.

Swift SVN r4534
2013-03-29 03:57:22 +00:00
Joe Groff
59d418de81 SIL: Add arguments to branch instructions.
BranchInst and CondBranchInst need to be able to pass arguments into the target BB. Add argument lists to the instructions.

Swift SVN r4485
2013-03-25 19:28:13 +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
ed6f218836 SIL: "Thicken" function refs when necessary.
Swift doesn't yet type-check function thinness, so variables, arguments, and return values are always thick. When we store, pass as argument, or return a function value that SIL tracks as thin, emit a new 'thin_to_thick_function' instruction to represent converting the type to the thick type and adding a null context pointer.

Swift SVN r4470
2013-03-21 23:44:01 +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
e07609c3e7 SIL: Add ClassMetatypeInst.
Represents getting the dynamic metatype from a class instance.

Swift SVN r4459
2013-03-20 23:27:18 +00:00
Joe Groff
9da0f893e5 SIL: Add address_to_pointer instruction.
Make converting a SIL address to a Builtin.RawPointer its own instruction separate from implicit_convert, which will let me get rid of a goofy edge case in IRGenSIL.

Swift SVN r4412
2013-03-18 03:14:24 +00:00
Joe Groff
b2c1a83433 SILGen: Uncurry function applications.
Reference and call uncurried function applications when appropriate to the call site, following the same logic implemented in CallEmission/CalleeSource in IRGen. Add ClassMethodInst and SuperMethodInst instructions to represent method and super dispatch. Change how closures and ClosureInst are represented in SIL so that closures are functions with an extra implicit uncurry level and so that ClosureInst applies the outer uncurries of an uncurried function type to give a curried type as a result. This breaks...pretty much everything else SIL-dependent; I'll clean it up next.

Swift SVN r4368
2013-03-14 01:27:54 +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
2ccfbdcf1a SIL: Add an UpcastExistentialInst.
Converting from a protocol type to a more general protocol type is different at the implementation level from converting a concrete type to a protocol type, since the witness tables and concrete value can be copied directly from the original existential container to the new without adding another indirection. This instruction represents that operation.

Swift SVN r3887
2013-01-28 20:02:52 +00:00
Joe Groff
8b1c38bfbd SIL: Add an 'upcast' instruction.
Upcasting isn't quite a no-op like the other implicit conversions because the underlying pointer type still needs to be bitcast. The additional semantic information will be useful for SIL consumers as well.

Swift SVN r3872
2013-01-26 00:49:47 +00:00
Joe Groff
b7c03623a8 SIL: Properly type closure constants and insns.
I was being lazy by not mangling the context arguments onto the types of closure SIL constants and then having ClosureInst pass the type of its callee through T -> T. Now closure functions get emitted with the right types, ClosureInst properly partially applies the type, and the SIL Verifier properly checks that the argument types all line up correctly.

Swift SVN r3815
2013-01-20 19:50:04 +00:00
Joe Groff
c2096a4bfe SIL: Include conformances in InitExistentialInst.
IRGen needs the conformances to be able to initialize an existential container.

Swift SVN r3786
2013-01-17 23:20:56 +00:00