Commit Graph

9293 Commits

Author SHA1 Message Date
Joe Groff
46c4bd45e9 SILGen: Handle capture of local properties.
Add GetterSetter and Getter capture modes that capture the getter and/or setter closures when a local property is closed over.

Swift SVN r3418
2012-12-08 00:47:45 +00:00
Joe Groff
c16fa57e69 SILGen: Handle getting local properties.
Build closures for local getter and setter decls, and load the get closure when the property is referenced in a normal expression context.

Swift SVN r3417
2012-12-08 00:47:43 +00:00
Joe Groff
e0b9794941 Fix some comments.
Swift SVN r3415
2012-12-07 23:24:19 +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
dc43d34e39 SILGen: Support MemberRefExpr on loadable structs.
Have TypeConverter generate a field-to-index mapping for physical fields of loadable structs.
Use the resulting TypeInfo mapping to generate element_addrs for physical MemberRefExprs, borrowing the logic from TupleElementExpr.

Swift SVN r3406
2012-12-07 18:28:24 +00:00
Joe Groff
9ea984ca02 SILGen: Fix a bug in destructuring assignment.
The type of an Extract from the right-hand side is an rvalue type, not the lvalue type of the corresponding tuple assignment destination.

Swift SVN r3394
2012-12-07 01:29:43 +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
752da923e0 SILGen: Move Explosion.h to ManagedValue.h
Rename the header and remove the "Explosion" class from it since we didn't end up using it.

Swift SVN r3390
2012-12-07 00:37:28 +00:00
Joe Groff
0b825c421b SILGen: Treat global vars as accessor functions.
Instead of considering `constant_ref @var` to give the address of `var` directly, consider it to be a `() -> [byref] T` function that returns the address, presumably after running the initializer for the global if necessary. Generate a DeclRef to a global var as a constant_ref to get the function followed by an apply to get the address. Actually generating the global accessor is still to be implemented.

Swift SVN r3389
2012-12-07 00:37:26 +00:00
Joe Groff
370f3b1b94 SILGen: Prepare emitFunction to handle curries.
Change the signature of emitFunction to take just a decl (and leave it up to the implementation to create the SILConstant) because emitFunction may produce functions for multiple SILConstants from a single FuncExpr.

Swift SVN r3388
2012-12-07 00:37:25 +00:00
Joe Groff
26e63ab46b SILGen: Add doc comments to some SILGen* methods.
Swift SVN r3387
2012-12-07 00:37:24 +00:00
Joe Groff
ce47e97843 SILGen: Support ClosureExprs.
ClosureExprs mostly share the same logic as FuncExprs, but need a bit extra help to handle the implicit return from the body expression. Genericize some FuncExpr code to work with an arbitrary CapturingExpr or to accept body and param patterns separately so they can be passed the components of FuncExprs or ClosureExprs.

Swift SVN r3376
2012-12-06 01:05:21 +00:00
Joe Groff
9a0400293b SILGen: Generate anonymous FuncExprs.
Reuse the closure-building code from local FuncDecls to also produce closures for local anonymous FuncExprs.

Swift SVN r3373
2012-12-05 23:15:32 +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
061197217b SILGen: Implement capture of byref arguments.
Swift SVN r3364
2012-12-05 17:59:04 +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
909f8db12e SILGen: Emit local function decls.
Generate local functions with captured variables as arguments to the entry block. Still need to implement the closure construction sequence when local functions are referenced.

Swift SVN r3357
2012-12-05 00:18:25 +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
445193a8e7 SILGen: Style cleanup.
Fix some code style violations brought up by John.

Swift SVN r3346
2012-12-04 01:05:40 +00:00
Joe Groff
9c6343aee6 SILGen: Fix goof in DeclRefExpr codegen.
Swift SVN r3343
2012-12-04 00:36:17 +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
Joe Groff
a47932f143 SILGen: Kill currently-unused TypeConverter field.
Swift SVN r3321
2012-11-30 21:28:31 +00:00
Joe Groff
880d1202a4 SILGen: Rename 'SILGen' class to 'SILGenFunction'.
Differentiate it from the inevitable SILGenModule class.

Swift SVN r3320
2012-11-30 20:36:28 +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
Joe Groff
42039ec720 SILGen: Implement r/r of fragile aggregates.
Stick a ReferenceTypeElements array in the SIL TypeInfo that gives a path to every reference type within a fragile aggregate. Since this now makes TypeInfo nontrivial to compute, steal some of the TypeConverter infrastructure from IRGen to manage TypeInfos for the current SILGen context. Use the reference type elements to determine triviality and to generate retain/release sequences for nontrivial loadable types.

Swift SVN r3301
2012-11-30 01:21:05 +00:00
Dave Zarzycki
168177d90c Fix an unused variable warning under release builds
Swift SVN r3298
2012-11-29 21:51:20 +00:00
Joe Groff
cfa7a48aea SILGen: Prune now-unused memory management helpers
Argument lifetime is now handled adequately by ManagedValue, so the special-case emitRetainArgument/DestroyArgument helpers aren't needed.

Swift SVN r3297
2012-11-29 19:49:52 +00:00
Joe Groff
a97f5da427 SILGen: Use ManagedValue to manage temporaries.
Steal IRGen's ManagedValue abstraction to handle the generation and consumption of rvalues. ManagedValue is a (Value, Cleanup?) pair that supports "forward"-ing ownership of a value and disabling its cleanup, which allows temporary values to be generated, retained, and either consumed by an ownership-taking operation such as a function call or aggregate initialization or released if unused.

Swift SVN r3293
2012-11-29 19:29:47 +00:00
Joe Groff
5d399609f7 SILGen: Retain function arguments
Add an `emitApply` method to SILGen that retains arguments and then applies a function. Change B.createApply calls to use emitApply instead.

Swift SVN r3282
2012-11-28 18:07:30 +00:00
Joe Groff
9c013ef3e2 SIL: Avoid tupling one-argument function arguments
SILGenExpr has special case logic to avoid constructing a SIL tuple for function arguments, but this logic failed to cover single-argument functions, in which the argument AST goes through a ScalarToTupleExpr node rather than a TupleExpr node. This patch adds similar logic to the ScalarToTupleExpr case so that single function arguments don't go through a SIL tuple instruction.

Swift SVN r3281
2012-11-28 18:07:26 +00:00
Joe Groff
b79d71d1d1 SILGen: Emit cleanups for return statements.
Clean up arguments and temporaries after any return statement, not only when we fall off the end of the function.

Swift SVN r3273
2012-11-27 23:32:38 +00:00
Joe Groff
5a5c388d2b SILGen: Do the assignment dance
Use the emitCopy method from r3265 to generate an appropriate retain/load/store/release sequence for assignment statements.

Swift SVN r3272
2012-11-27 23:05:09 +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
Joe Groff
e4693666d4 SILGen: support void return statements
Generate '%1 = tuple (); return %1" for a void return statement instead of crashing.

Swift SVN r3266
2012-11-27 22:20:48 +00:00
Joe Groff
92ddeb8caf Steal IRGen TypeVisitor for SILGen.
Swift SVN r3265
2012-11-27 22:20:46 +00:00
Joe Groff
abc1724204 SILBuilder: use SILLocation in createR/R methods
Update createRetain, createRelease, etc. to use SILLocation instead of Expr * arguments to be in line with Chris's update in r3249.

Swift SVN r3263
2012-11-27 22:20:42 +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