Commit Graph

512 Commits

Author SHA1 Message Date
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
340cc73e1e SIL: Track uncurry levels of SILConstants.
Pack the uncurry level onto SILConstant, and modify SILConstant constructors to determine the natural uncurry level of their referenced entity by default. While we're here, improve how SILConstant represents different kinds of constants by using a real enum for the kind. Type closure entry points by giving them an extra curry level for their context. The implementation of ApplyInst and ClosureInst hasn't been updated yet, so tests that lower closures to SIL are temporarily broken.

Swift SVN r4354
2013-03-11 23:17:35 +00:00
Joe Groff
4437c65178 SIL: Add uncurry level to SILType.
We want to port CallEmission to the SIL level to handle uncurrying, but IRGen needs to have the original signature of a function available to it so that it can maintain the correct calling convention for different ABIs independent of SIL. Instead of flattening curried function types in SIL and losing that information, add an uncurryLevel to SILType so it can represent the type of an entry point at a given uncurry level. Unfortunately, this makes SILType outgrow a single word, so the way Value unions SILType and SILTypeList folding sets needs to be tweaked too.

Swift SVN r4345
2013-03-09 00:53:14 +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
5852448152 IRGen: Generate SIL ctor and property decls.
Remove the filter that only irgenned SIL functions for FuncDecls so that we emit functions for all SIL decls, and disable the old paths for properties, constructors, and destructors when a SIL module is present. Unfortunately this breaks class constructors because SIL and IRGen don't agree on how initializing constructors should work. I need to sync with John to figure out how to fix that.

Swift SVN r3827
2013-01-22 02:45:27 +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
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
08399cf882 SILGen: Emit allocating/initializing class ctors.
Add a new SILConstant kind to refer to the initializer of a ConstructorDecl. Emit class constructors as separate allocating and initializing functions named SILConstant(CD) and SILConstant(CD, Initializer) so that derived classes will be able to invoke their superclass constructor.

Swift SVN r3686
2013-01-04 23:13:38 +00:00
Joe Groff
718126bd2e SILGen: Emit implicit destructors.
Add a new "kind" to SILConstant so that SIL can reference destructors without decls. Generate a destructor for classes even if they don't have an explicit destructor. If a class has a base class, call the base class destructor instead of dealloc_ref-ing the current instance.

Swift SVN r3665
2013-01-03 23:57:48 +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
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
aab2997273 SIL: Print SIL type when dumping Functions.
Swift SVN r3541
2012-12-19 01:30:25 +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
Dave Zarzycki
113faab6f6 Fix warning during RELEASE builds and fix -Wnewline-eof bugs
We really ought to enable: -Wnewline-eof

Swift SVN r3522
2012-12-17 17:59:52 +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
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
3e14d9782a SILGen: Specialize generic property accessors.
Generic accessors need to have a specialize instruction applied to them to get the concrete accessor before applying them.

Swift SVN r3492
2012-12-14 16:51:59 +00:00
Joe Groff
62e4e71ce8 SILGen: Implement CoerceExpr and DowncastExpr.
Use the new CoerceInst and DowncastInst instructions to handle Coerce and Downcast expressions.

Swift SVN r3491
2012-12-14 02:42:45 +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
4325479fc4 SIL: add print() and dump() methods to SILConstant
Expose the static printSILConstant function in SILPrinter.cpp as a method on SILConstant.

Swift SVN r3469
2012-12-13 01:26:34 +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
26344c7728 SILGen: Implement getting properties.
- Steal some bits from SILConstant::id to reference getter and setter definitions, and normalize SILConstant references to property FuncDecls to be SILConstant references to the ValueDecl getter/setter instead.
- In normal expression context, handle getting properties by calling the getter and materializing the return value. Setting lvalues is not implemented yet; that will require borrowing the LValue and GenLValue machinery from irgen to construct logical lvalue paths in assignment and byref contexts.

Swift SVN r3414
2012-12-07 23:24:15 +00:00
Joe Groff
6a67ad7e12 SIL: Add ElementAddrInst.
Derives the address of a member from the address of a fragile value type. SIL extract : SIL element_addr :: LLVM extractvalue : LLVM getelementptr. Also add SILVerifier checks for ExtractInst and ElementAddrInst that they deal only in values and addresses, respectively.

Swift SVN r3391
2012-12-07 00:37:29 +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
ba25bb79b3 SIL: Add a ClosureInst instruction type.
ClosureInst represents construction of a closure by partial application of a function reference.

Swift SVN r3359
2012-12-05 01:39:00 +00:00
Joe Groff
703bd9f355 SIL: Add bits to distinguish get/set in SILModule.
SIL needs a way to generate and reference getters and setters, which share a decl. Change SILModule to key its component Functions on a (ValueDecl, flags) pair rather than just on ValueDecl.

Swift SVN r3354
2012-12-04 21:42:35 +00:00
Joe Groff
814229fce7 SILGen: Generate top-level code.
Add a toplevel Function object to SILModule. When SILGenModule encounters TopLevelCodeDecls, pass their bodies on to SILGenFunction to emit SIL into the toplevel function

Swift SVN r3336
2012-12-03 20:38:14 +00:00
Joe Groff
ec1e1aedc4 SILModule: Use llvm::MapVector to store Functions.
(instead of slumming with a DenseMap/vector pair)
Re: r3322

Swift SVN r3331
2012-12-03 17:16:34 +00:00
Joe Groff
fdb8982f35 Add doc-comments to SIL Function and SILModule.
re: r3322

Swift SVN r3330
2012-12-03 17:16:32 +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
148609d596 SILGen: Allow global variable accesses.
If an lvalue DeclRefExpr doesn't have a local VarLocs entry in the current SILGen function, assume it's a global variable and generate a constant_ref to get at its address. Eventually there should be a SILGenModule with which we can check that the global access is valid. Either ConstantRef should be renamed or a new GlobalVarRef instruction should be added as well.

Swift SVN r3319
2012-11-30 20:21:37 +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
Chris Lattner
f59185141c Change integer_literal and friends to take a comma for consistency with other operations. Make a few more tweaks to the printer to match SIL.rst.
Swift SVN r3259
2012-11-27 18:48:30 +00:00
Chris Lattner
d734b4e989 change the SIL printer for a few instructions to follow SIL.rst
Swift SVN r3258
2012-11-27 18:40:58 +00:00
Chris Lattner
6d8d9daee8 rename DestroyInst -> DestroyAddr to conform to SIL.rst. The non-addr form of destroy will be added later.
Swift SVN r3257
2012-11-27 18:35:57 +00:00
Chris Lattner
9750e36943 rename Copy -> CopyAddr to follow SIL.rst
Swift SVN r3256
2012-11-27 18:34:40 +00:00
Chris Lattner
a9abb47cf0 rip out the 'is initialization' bit from StoreInst per SIL.rst. The AssignStmt
lowering code needs to emit the retain/release dance, but I'll leave that to
Joe :)


Swift SVN r3234
2012-11-17 01:56:57 +00:00
Chris Lattner
aad1b3c904 remove the 'take' flag from LoadInst
Swift SVN r3232
2012-11-17 01:47:55 +00:00
Chris Lattner
2ddc716bba rename TypeConversion to Convert to follow SIL.rst
Swift SVN r3231
2012-11-17 01:38:41 +00:00