Commit Graph

6634 Commits

Author SHA1 Message Date
Chris Lattner
f4dfaed4cf generalize SILConstant to hold a Decl*, not just a ValueDecl*.
This is in preparation to allow SILConstant of TopLevelCodeDecl.



Swift SVN r4675
2013-04-11 00:46:36 +00:00
Joe Groff
7a0d879307 SILGen: Handle tuple explosions systematically.
Introduce an 'RValue' object in SILGen that behaves like a simplified version of IRGen's 'Explosion' object, holding a destructured tuple in a naturally destructured state. This cleans up a bunch of ad-hoc scattered code that destructured tuples in various places. Update SILGenFunction so that the expression visitors all pass around RValues, and update CallEmission to handle argument clauses as RValues instead of a pre-destructured string of arguments. Implement "emit into" optimization of TupleExpr and ScalarToTupleExpr, now that that's easy to do.

Swift SVN r4667
2013-04-10 23:00:18 +00:00
Joe Groff
6df319ab8e Update PointerIntPairs to use enum class members.
LLVM r179073 fixed PointerIntPair to work with an enum class as the IntType member, so we can kill some boilerplate in a few type implementations that were explicitly casting to unsigned to work around PointerIntPair's limitations.

Swift SVN r4652
2013-04-10 15:30:41 +00:00
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
965242a833 rename SILBBArgument.h -> SILArgument.h to match the class name.
I'm done with renaming for now, boy do my fingers hurt.


Swift SVN r4595
2013-04-03 21:08:38 +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
fe23727891 rename Value.h -> SILValue.h, missed it in the last pass.
Swift SVN r4592
2013-04-03 18:47:32 +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
Chris Lattner
05dcf38c1c move SIL/Function.h to SILFunction.h in preparation to renaming the class.
Swift SVN r4589
2013-04-03 18:27:54 +00:00
Joe Groff
8caf747853 Put alignas(N) on classes with strict alignment.
We use three tag bits on Expr*, Stmt*, Decl*, TypeBase* and SILTypeInfo*, and four on DeclContext*, so set the alignment of the pointed-to types formally with alignas(N) instead of relying on operator new passing down the right alignment to the allocator. Get rid of the informal T::Alignment members of these classes and pass alignof(T) to their allocators. Fix the 'operator new' of DeclContext subclasses so that we can actually use the four tag bits PointerLikeTypeTraits<DeclContext*> claims are available.

Swift SVN r4587
2013-04-03 17:27:05 +00:00
Chris Lattner
05fbef4a86 give SIL Function a mangled name field, which is currently unused.
Swift SVN r4586
2013-04-03 16:49:10 +00:00
Chris Lattner
85c7c494ae Wire up the most trivial support for sil parsing, which allows us to write
a (trivial, empty) sil parser testcase.  The parser is still not SIL aware
though.


Swift SVN r4585
2013-04-03 05:57:42 +00:00
Joe Groff
4923acce2b Use C++11 alignof(T) instead of llvm::AlignOf<T>.
Swift SVN r4583
2013-04-03 02:41:29 +00:00
Joe Groff
3a9100f559 SIL: Clean up SILType interface for functions.
Function and compound types have a bunch of extra calling convention and uncurrying info stuffed into a "SILTypeInfo" object that until now had to be fetched through the SILModule. Change the representation of SILType to be a PointerUnion of CanType and SILTypeInfo*, and move the uncurry level onto the SILTypeInfo for functions, so that SILTypeInfo is available directly through the SILType and SILType can go back to being pointer-sized.

Swift SVN r4582
2013-04-03 02:33:29 +00:00
Joe Groff
83d4b6dda4 SIL: Separate TypeLowering from SILGen.
Other SIL producers (like the parser) will probably need to be able to lower Swift Types to SILTypes, so make TypeLowering.h a public SIL header instead of an implementation detail of SILGen.

Swift SVN r4577
2013-04-02 21:50:28 +00:00
Joe Groff
d2a985ded5 SIL: Fix use chains better.
Bring back most of John's old code and just keep the fix to update the first use pointer in the value.

Swift SVN r4564
2013-04-01 22:46:40 +00:00
Joe Groff
c724d1f6a1 IRGen: Emit SIL class metatypes as Swift or ObjC.
Look at the uses of a SIL MetatypeInst to determine whether it is being used as a Swift metatype and/or ObjC class and emit the needed values. This avoids a costly trip wrapping and unwrapping ObjC Classes in a Swift metatype when they're just used to invoke class methods.

Swift SVN r4562
2013-04-01 22:10:12 +00:00
Joe Groff
79b36f7744 SIL: Fix use chains.
The FirstUse of values was never getting updated, so use chains were always empty.

Swift SVN r4561
2013-04-01 22:10:10 +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
1a8b35d383 REPL: Support -sil-irgen.
Add a 'startElem' option to SILModule::constructSIL so that it can be used with REPL input.

Swift SVN r4519
2013-03-28 18:38:29 +00:00
Joe Groff
b105e02534 IRGen: Lower SIL bb arguments to LLVM phi nodes.
Swift SVN r4493
2013-03-27 17:07:17 +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
08d06e850d IRGen: Emit top-level globals from SIL.
Set up IRGen to emit SIL code that uses top-level-code global variables. Add -sil-i to a bunch of Interpreter tests that use global variables.

Swift SVN r4480
2013-03-22 23:34:38 +00:00
Joe Groff
7934842505 SILGen: Handle globals in top-level code.
In top-level code, global variables are notionally local variables of the "main" function, but we give them global storage as an implementation detail. Add the ability to represent physical global variables to SILConstant, and emit top-level-code global variable initializers and references in terms of the physical address.

Swift SVN r4479
2013-03-22 21:58:33 +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
15d606b630 IRGen: Lower SIL class_method for native classes.
Turn class_method into a vtable lookup for Swift class and class metatype instances.

Swift SVN r4467
2013-03-21 20:50:37 +00:00
John McCall
3c7df2d9d9 Waste time during SIL-generation keeping a lot of information
that we're not even using.

Oh, and initialize the existential operand of a
DeinitExistentialInst.

Swift SVN r4464
2013-03-21 05:29:19 +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
61077a641d IRGen: Lower SIL function args in right order.
Map the SIL entry point BB's args to LLVM function args in the inner-to-outer-uncurry order used by Swift's ABI.

Swift SVN r4452
2013-03-20 03:23:56 +00:00
Joe Groff
ac73865dd7 IRGen: Update lowering of SIL applications.
We no longer need the PartialCall hackery in IRGen to uncurry calls, because SILGen does it for us.

Swift SVN r4451
2013-03-20 00:02:49 +00:00
Joe Groff
98fd61559a SIL: Keep SIL argument counts for each curry level
Track the argument offset for each curry level of an uncurried function so that IRGen can map SIL arguments to LLVM arguments in the correct order for the underlying calling convention.

Swift SVN r4449
2013-03-19 16:28:43 +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
7a7e14a9c5 IRGen: Emit SIL destructors.
Emit the SIL destructor as a destroying destructor, then emit a deallocating destructor shim that calls into it and then returns the heap size. (The actual deallocation still happens in swift_release--I talked to John about that and I'll fix it later.) This gets the broken SIL/IRGen class tests passing again.

Swift SVN r3838
2013-01-22 23:36:37 +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
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
0422897a47 Expose %swift.opaque as a builtin type.
Archetypes and projected existentials have the type %swift.opaque* and not i8*, so I need a corresponding SIL type to be able to model the ProjectExistential operation. We might also end up needing the builtin type for other low-level things down the line.

Swift SVN r3793
2013-01-18 02:24:23 +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
8320df8b9d IRGen: SIL branching and variable allocation.
Implement SIL-to-IR lowering for allocation, deallocation, load, store, and branching instructions so that local variables and branching control flow can be used. Add a Fibonacci loop test to exercise the new instructions.

Swift SVN r3767
2013-01-15 22:32:49 +00:00
Joe Groff
4239b2edf0 SIL: Make Value::operator bool() explicit.
Implicit conversions to integer are bad news.

Swift SVN r3758
2013-01-14 02:57:08 +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