Commit Graph

6634 Commits

Author SHA1 Message Date
Joe Groff
d9db6d86e5 SIL: Make (Archetype|Protocol)Method with pre-formed types.
Deriving the instruction type of these nodes needs to go through SILGenModule so that their SILTypes have SILFunctionTypeInfo properly associated with them.

Swift SVN r3729
2013-01-10 03:45:42 +00:00
Joe Groff
2858bc4fde SIL: Replace '-dump-sil-verbose' hack with DEBUG()
Swift SVN r3728
2013-01-10 03:45:40 +00:00
Joe Groff
f390ee66b4 SIL: Fix bug in SILFunctionTypeInfo.
The SILFunctionTypeInfo constructor wasn't initializing the inputTypeCount. How it even seemed to work at all is a mystery.

Swift SVN r3727
2013-01-10 03:45:38 +00:00
Joe Groff
ac0713432b SILVisitor: Visit basic blocks and bb arguments.
Handle overridden visitFunction and visitBasicBlock methods, and in the default implementation of visitBasicBlock, recur into the block's arguments in addition to its instructions.

Swift SVN r3726
2013-01-10 03:45:36 +00:00
Dave Zarzycki
92d87def4c Build warning fix: missing newline at EOF
Swift SVN r3717
2013-01-09 18:04:23 +00:00
Joe Groff
cb03dbd3be SIL: Associate SILTypeInfo with the SILModule.
For some types, there is lowering info that is useful to IRGen, such as the SIL-level calling convention for functions or the element layout of aggregates, that can't fit in a SILType pointer but still should be associated with the module. Add a SILTypeInfo hierarchy, add a mapping of SILTypes to infos to SILModule, and rename the SILGen-specific TypeInfo to TypeLoweringInfo. Move the derived layout information for compound types from TypeLoweringInfo to SILTypeInfo so that IRGen will be able to use it.

Swift SVN r3712
2013-01-09 00:02:38 +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
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
661f6d8537 SIL: Destruct Instructions when they're erased.
Invoke the leaf destructor for the Instruction when it's eraseFromParent-ed, so that the SILSuccessors of BranchInsts get updated when branches are removed. This un-breaks the peepholing of breaks out of else blocks.

Swift SVN r3641
2013-01-02 18:53:40 +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
0d34838a79 SILGen: Handle address-only arguments and returns.
Use copy_addr to copy argument addresses into local boxes and to store to the return value address when working with address-only types. Add a bit to ManagedValue so that it knows when it's referencing an address-only value (as opposed to just an address) so it can require that forwarded address-only values be forwardInto-ed a memory location.

Swift SVN r3540
2012-12-19 01:30:23 +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
dc1af6ae11 SILGen: Implement address-only type lowering.
Add a getLoweredType() method to SILGen's TypeInfo and logic to convert function signatures and address-only types to their SIL-level representations. Drive a (currently weak) type wedge between lowered and unlowered types by making a SILType subclass of CanType. Make SILConstants take on their lowered function types. This breaks a bunch of SIL test cases, which I've temporarily XFAILed until proper address-only type support can propagate through the rest of SILGen.

Swift SVN r3528
2012-12-18 02:29:27 +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
9f7b89b1b2 Add a -dump-sil-verbose option.
Since I can't seem to help myself from committing my local debug dumps.

Swift SVN r3495
2012-12-14 18:44:51 +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
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
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
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
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
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
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
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
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
7b5e8c84cb SILGen: Gen VarDecls as locals for toplevel code.
If the TranslationUnit being silgenned is a Main or Repl unit, generate globals like locals. Generating toplevel functions as closures still needs to be done.

Swift SVN r3340
2012-12-04 00:04:38 +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
79c7e825f7 Don't <>-include llvm headers.
In response to Chris' feedback on r3322.

Swift SVN r3329
2012-12-03 17:16:29 +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