Commit Graph

417 Commits

Author SHA1 Message Date
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
Joe Groff
521b9376eb SIL: Make RefElement take VarDecl instead of index
This is inconsistent with ElementAddr and Extract, but allows all the hairy logic of accessing class fields in IRGen to stand without a bunch of pointless refactoring.

Swift SVN r3778
2013-01-16 22:12:17 +00:00
Joe Groff
740e7d93eb SIL: Use SILLocation in SILBuilder methods.
Update some laggards in SILBuilder that still were demanding Expr*s of some form rather than SILLocations.

Swift SVN r3733
2013-01-10 21:59:20 +00:00
Joe Groff
49521d60e5 SIL: Rename instructions.
ExistentialMethod -> ProtocolMethod for better specificity.
[De]AllocExistential -> [De]InitExistential because it doesn't necessarily allocate anything.

Swift SVN r3710
2013-01-08 17:14:45 +00:00
Joe Groff
05adc65d14 SIL: Add AllocRefInst.
Represents a raw allocation of a reference type instance. This lets us implement constructors for reference types.

Swift SVN r3661
2013-01-03 20:12:32 +00:00
Joe Groff
7b2c1a31e5 SILGen: A first pass at generating destructors.
Generate explicit destructors by emitting their bodies then emitting release sequences for the class's members. Eventually we'll need to also emit implicit destructors for classes without explicit destructors and to chain a call to the base class destructor, which will require adding a new linkable entity flag onto SILConstant for destructors, similar to getter/setters.

Swift SVN r3655
2013-01-03 04:24:43 +00:00
Joe Groff
e7fc1d0bba SIL: Add SuperToArchetypeInst.
Add an instruction to represent super-to-archetype downcasts. Since archetypes are address-only, it needs to take a reference to the destination archetype as a parameter.

Swift SVN r3643
2013-01-02 21:00:37 +00:00
Joe Groff
1892f51a05 SIL: Add AssociatedMetatypeInst.
Represents getting an associated type metatype from a generic metatype.

Swift SVN r3588
2012-12-22 01:10:46 +00:00
Joe Groff
21dcefd4f1 SIL: Add DeallocRefInst.
Needed to represent deallocating an uninitialized box.

Swift SVN r3573
2012-12-21 02:37:17 +00:00
Joe Groff
c2f9b197ad SIL: Add DeallocExistentialInst.
Needed to represent deinitializing a partially-initialized existential in which the value witness table has been populated by alloc_existential but the value has not been initialized yet.

Swift SVN r3565
2012-12-20 20:18:54 +00:00
Joe Groff
7d8f04ac45 SIL: Make SILType independent of Type.
Move SILType to its own header, and make it its own container type consisting of a Type with an "isAddress" bit for representing address types. Move the "isAddressOnly" information from SILGen's TypeInfo onto SILType as a second bit, because address-only-ness is extremely useful for verification outside of SILGen. Instead of mangling function types during type lowering, rely on the fact that SILType is no longer a Type to force us to mangle argument and return types when we see them. (We may eventually need SILFunctionType and SILTupleType things to represent lowered SIL function and tuple types containing addresses, but for now we can lower function and tuple components as needed.)

Swift SVN r3551
2012-12-19 21:51:39 +00:00
Joe Groff
6ad32a20c4 SIL: Use SILType and lower types where needed.
Change over SIL Values and Instructions to work in terms of SILTypes, and update SILGen to lower types where needed. Add LValueType logic to SILType lowering to get rid of those annoying lvalue qualifiers so we can ignore RequalifyExprs. Tighten up the XFAILs in the SIL tests and disable the checks that currently crash.

Swift SVN r3538
2012-12-18 23:53:39 +00:00
Joe Groff
601f1d3c4d SIL: Move SILModule::getConstantType to TypeInfo.
Determining constant types requires help from SILGen because of address-only types, and the type of a constant after SILGen should always be readily available from the ConstantRefInst. Initialize SIL Function objects with their lowered type as well so that it's available to IRGen and SIL passes.

Swift SVN r3526
2012-12-17 20:27:46 +00:00
Joe Groff
90b3f319c7 SILGen: implement ArchetypeToSuperExpr.
Add an ArchetypeToSuperInst to represent archetype-to-base-constraint-type conversions. Use it to emit ArchetypeToSuperExprs.

Swift SVN r3521
2012-12-17 17:52:27 +00:00
Joe Groff
03dd05ca07 SIL: Add ProjectExistential and AllocExistential.
ProjectExistential derives the value pointer from an existential, and AllocExistential initializes an existential's witness tables and allocates its value. Tweak SILGen's handling of ExistentialMemberRefExprs to emit a project_existential between querying the method and applying it.

Swift SVN r3508
2012-12-15 02:15:54 +00:00
Joe Groff
6d77ef4041 SIL: Add ExistentialMethodInst.
Like ArchetypeMethodInst for existential types. Factor out a common WitnessTableMethodInst for both insns.

Swift SVN r3506
2012-12-15 02:15:51 +00:00
Joe Groff
6b7405e602 SILGen: Fix associated types in archetype methods.
Pass down the AST type from the ArchetypeMemberRefExpr, which has the right locally-bound archetypes, rather than derive the method type from the decl.

Swift SVN r3504
2012-12-15 00:11:29 +00:00
Joe Groff
5d405e5ecd SIL: Add ArchetypeMethodInst.
Add an instruction to get a method implementation from an archetype's protocol witness table.

Swift SVN r3502
2012-12-14 23:56:32 +00:00
Joe Groff
9474a81f0b SIL: Generalize MetatypeInst.
Allow MetatypeInst to be constructed with any expr of metatype type, not just MetatypeExpr nodes.

Swift SVN r3496
2012-12-14 18:44:53 +00:00
Joe Groff
b335710fd2 SIL: Add CoerceInst and DowncastInst insns.
Add instructions to represent type coercion and downcast conversion operations. Factor out a common ConversionInst base class for Convert and these instructions, and rename ConvertInst to ImplicitConvertInst to distinguish it from these new explicit conversion instructions.

Swift SVN r3490
2012-12-14 02:13:21 +00:00
Joe Groff
7142b34161 SIL: Make SpecializeInst own its Substitutions.
Have SpecializeInst own its Substitution array so that a SpecializeInst can be instantiated independently of a backing SpecializeExpr in the AST.

Swift SVN r3483
2012-12-13 22:08:45 +00:00
Joe Groff
d3d617ca70 SILGen: Implement getting subscripts.
Subscripts are just another kind of property. Refactor some logic from ApplyExpr codegen to visit index arguments consistently with apply arguments. Also move the logic for determining SIL constant types onto SILModule because it's too hairy to calculate on the fly.

Swift SVN r3452
2012-12-12 20:23:56 +00:00
Joe Groff
13bb47d070 SIL: Add RefElementAddrInst instruction.
Like ElementAddrInst for reference type instances. Takes an rvalue reference type and gives the address of an element in the instance.

Swift SVN r3444
2012-12-12 01:04:30 +00:00
Joe Groff
0f3414480e SILBuilder: r/r of constant_ref is a no-op.
Retaining or releasing a constant_ref can be trivially elided in SILBuilder.

Swift SVN r3440
2012-12-11 18:23:08 +00:00
Joe Groff
374aff6632 SILGen: Use ElementAddr for lvalue TupleElements.
If the operand of a TupleElementExpr is an lvalue, derive the address of the element from the operand rather than try to extract a value from it as the code was doing before.

Swift SVN r3392
2012-12-07 00:37:31 +00:00
Joe Groff
a593076d09 SIL: Introduce a SILConstant type.
We need something more general than ValueDecl to be able to talk about anonymous functions, curried entry points, etc. as SIL constants. SILConstant is a (ValueDecl | CapturingExpr) union with an additional index for discriminating multiple instances or entry points derived from the same AST entity. Update ConstantInst and SILModule's function table to be keyed by SILConstant rather than ValueDecl.

Swift SVN r3372
2012-12-05 22:40:38 +00:00
Joe Groff
45c980ce85 SILGen: Capture local constants by value.
Local constants (such as local FuncDecls) are never modifiable so can be captured by value. Give the local constant value to the closure when visiting a local FuncDecl, and in the function body, register the corresponding closure context argument as a local constant for that context.

Swift SVN r3369
2012-12-05 19:41:27 +00:00
Joe Groff
b045361d9d SILGen: Generate closure for FuncDecl once.
Associate the closure object for a local FuncDecl with the FuncDecl rather than with the DeclRefExpr. Move the closure creation code into SILGenFunction::visitFuncDecl, and add a LocalConstants map to SILGenFunction to store closures generated from local decls. Add a constructor to ConstantRefInst to allow it to be associated directly with ValueDecls in addition to DeclRefExprs.

Swift SVN r3368
2012-12-05 18:47:40 +00:00
Joe Groff
11c48c2ac4 SILGen: Generate closures for local FuncDecls.
Swift SVN r3360
2012-12-05 01:55:53 +00:00
Joe Groff
1c21b9f304 SIL: Introduce a SILModule object.
Create a SILModule type, and lift ownership of TU-global things like the bump allocator and type list uniquing from Function to SILModule. Move the ad-hoc SIL dumping logic out of main() into SILModule and into a new SILGenModule class.

Swift SVN r3324
2012-12-01 01:29:59 +00:00
Joe Groff
583ad139b6 SILGen: Remove AllocTmp, add AllocVar stack attr
Remove the AllocTmp instruction and represent MaterializeExpr allocations using 'alloc_var stack'/'dealloc_var stack' instructions. Rename Dealloc to DeallocVar, and add an AllocKind attribute to AllocVar and DeallocVar. Update MaterializeExpr SILGen to generate an AllocVar with a DeallocVar cleanup instead of AllocTmp. Tweak SILPrinter's presentation of AllocVar and DeallocVar to be in line with what SIL.rst claims.

Swift SVN r3311
2012-11-30 18:45:57 +00:00
Joe Groff
3d273367f4 SIL: rename TupleElementInst -> ExtractInst
Now that it's being used on both tuples and structs, the current name doesn't make much sense. SIL.rst specifies a unified set of extract/insert/gep instructions that operate on either tuples or nominal fragile structs.

Swift SVN r3303
2012-11-30 01:49:57 +00:00
Joe Groff
f8a2de9d61 Sync up with today's earlier SIL insn changes.
Swift SVN r3268
2012-11-27 22:44:44 +00:00
Joe Groff
253e953a98 SIL: Release arguments and retain stores to boxes.
Build some infrastructure for handling retain/release/copy/destroy of values. Use this to retain values when storing them into boxes and to clean up reference type arguments on function exit. Right now this just stupidly assumes "value type is trivial, reference type is retained/released", but it eventually needs to handle address-only types using the indirect copy_addr/destroy_addr instructions and to handle loadable value types with reference members by retaining the proper members. Passing arguments to function calls, reassignment, and cleanup of full expression temporaries all still need implementation.

Swift SVN r3267
2012-11-27 22:20:49 +00:00