Commit Graph

9332 Commits

Author SHA1 Message Date
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
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
2c009210a4 rework a bunch of instructions to have a single constructor (and builder) form
that takes a generic SILLocation... instead of having duplicated constructors.


Swift SVN r3251
2012-11-27 01:28:23 +00:00
Joe Groff
a5157cac07 SILGen: generate alloc_box/release for PatternDecl
Update codegen for local variables and arguments to use the new alloc_box instruction to allocate retainable storage for the variables and to release the boxes when the variables go out of scope. Update tests to check for alloc_box and release sequences instead of alloc_var.

Swift SVN r3242
2012-11-26 17:48:37 +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
Joe Groff
39e1ba0e44 SIL: get IntLiteral/FloatLiteral values from AST
It would be better in the long term to copy the getText() from the AST into the instructions so they can stand independent of any AST node, but this is convenient for now.

Swift SVN r3233
2012-11-17 01:53:08 +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
Joe Groff
6d58ee281d SIL: rip out redundant CharacterLiteralInst
Swift SVN r3230
2012-11-17 01:32:16 +00:00
Chris Lattner
30c50c2c2d minor tweaks to SILPrint to follow SIL.rst, e.g. "store ... to".
Swift SVN r3229
2012-11-17 01:25:47 +00:00
Chris Lattner
8c0513f9cc rename index_lvalue instruction to index_addr to follow SIL.rst.
Swift SVN r3226
2012-11-17 01:22:19 +00:00