Commit Graph

770 Commits

Author SHA1 Message Date
Chris Lattner
a34f4efa13 parse integer_literal. Parse and print tuple instructions with named
elements in a way that we can not lose information.


Swift SVN r5348
2013-05-26 01:09:46 +00:00
Chris Lattner
7383d09a36 add a new SILType::getAsString() method, to be used in diagnostics when
printing SILTypes.  Bias the values in ValueToIDMap in SILPrinter so that
uses of invalid operands will print as %-1.



Swift SVN r5342
2013-05-25 18:40:47 +00:00
Joe Groff
0dc5c66cd2 SIL: Move SILFunctionTypeInfo into a side table.
Generate and cache SILFunctionTypeInfo from Swift types on the fly, and simplify the SILType representation down to a CanType and isAddress bit.

Swift SVN r5298
2013-05-24 16:33:52 +00:00
Joe Groff
5e2779b51e SIL: Uncurry function types within the Swift type system.
Remove uncurry level as a property of SILType/SILFunctionTypeInfo. During SIL type lowering, map a (Type, UncurryLevel) pair to a Swift CanType with the uncurried arguments as a Swift tuple. For example, T -> (U, V) -> W at uncurry level 1 becomes ((U, V), T) -> W--in reverse order to match the low-level calling convention. Update SILGen and IRGen all over the place for this representation change.

SILFunctionTypeInfo is still used in the SILType representation, but it's no longer load-bearing. Everything remaining in it can be derived from a Swift type.

This is an ABI break. Be sure to rebuild clean!

Swift SVN r5296
2013-05-24 01:51:07 +00:00
Chris Lattner
55fe34063f optimize this to use std::next
Swift SVN r5271
2013-05-22 19:59:11 +00:00
Chris Lattner
a1f43692e8 switch a bunch of instructions (e.g. load) to print types for their operand.
These are the instructions that don't require testsuite updates :-)


Swift SVN r5270
2013-05-22 18:07:48 +00:00
Chris Lattner
02f02fca0f [overpedantic] Get plurality right in the # users comment, printing:
%0 = tuple ()                                   // user: %1
  %1 = return %0 : $()

instead of "users".



Swift SVN r5268
2013-05-22 17:58:44 +00:00
Chris Lattner
aacbf8f560 print the type of the operand to return and autorelease_return,
print the element types of struct.

The empty function now prints as:

sil @_T1t5emptyFT_T_ : $[thin] () -> () {
bb0:
  %0 = tuple ()
  %1 = tuple ()                                   // users: %2
  %2 = return %1 : $()
}



Swift SVN r5267
2013-05-22 17:49:03 +00:00
Chris Lattner
1bdf645d4b code cleanup:
- use interleave a bit more
 - Inline printAsOperand() away.
 - Introduce a "getIDAndType" method that prints both ID and type in the standard form.


Swift SVN r5266
2013-05-22 17:44:48 +00:00
Chris Lattner
de0ab0474e change tuple instructions to print as "tuple (%0 : $Int, %1 : $Float)"
so they can be parsed.  Drop the comman in struct instructions so they
print as "struct $foostruct (%0, %1, %2)"



Swift SVN r5265
2013-05-22 17:33:12 +00:00
Chris Lattner
d2de474371 Add a public raw_stream inserter for SILType. Change SILType printing
to always prefix a printed SILType with a $.  Update SILPrinter to use
this instead of manually adding $ everywhere.

The only behavioral change of this is that BB arguments now have a $ on
their type.


Swift SVN r5263
2013-05-22 17:14:05 +00:00
Chris Lattner
0c294501d6 add a "container" version of interleave, use it in SILPrinter a bit more.
No behavior change.


Swift SVN r5262
2013-05-22 16:52:51 +00:00
Joe Groff
12c7d01708 SIL: Write a function for uncurrying function types within the Swift type system.
Add a TypeConverter::uncurryFunctionType method for making an uncurried AnyFunctionType given a nested AnyFunctionType and an uncurry level. Without actually wiring it into anything yet, spot-check that it does the right thing by hacking SILPrinter to print the uncurried types of SILFunctions in a comment before the sil decl.

Swift SVN r5260
2013-05-22 03:14:13 +00:00
Chris Lattner
ed2c094728 change the SIL printer to print return statements without parens around their operand.
Swift SVN r5258
2013-05-22 00:35:34 +00:00
Joe Groff
a4ce448280 Move cc attribute from SILType to AnyFunctionType.
We decided we're going to want to surface fine-grained representational control of functions to the user, so move AbstractCC and the calling convention attributes into the Swift type system. Like the [thin] attribute, we don't set this in the type-checker or importer at all yet, and let SILGen set the attribute where it wants it for now.

Swift SVN r5222
2013-05-20 17:55:51 +00:00
Joe Groff
409655e037 SIL: Split tuple/struct field accessor insns.
Split ExtractInst and ElementAddrInst into separate Tuple and Struct versions, and have the Struct versions reference struct member VarDecls directly instead of integer indices.

Swift SVN r5215
2013-05-17 23:34:11 +00:00
Chris Lattner
087d4c8430 Implement the parsing logic for SIL types (the SILType specific attributes).
All of it is still dropped on the floor.


Swift SVN r5195
2013-05-17 01:02:02 +00:00
Chris Lattner
babc1ea148 change printing of SILType to make it more regular and parsable. As usual,
the hard part is updating the testsuite.


Swift SVN r5194
2013-05-17 00:26:27 +00:00
Joe Groff
c4317411b6 IRGen: Use SILType in functions used for existential container insts.
Swift SVN r5191
2013-05-16 22:47:49 +00:00
Chris Lattner
63e2a60585 rename Module:: and Function::getContext to ::getASTContext()
This matches SILType and is more explicit about which context
we're talking about.


Swift SVN r5185
2013-05-16 20:14:13 +00:00
Chris Lattner
2e7a6c015a switch the specialize instruction to print its substitution list after
a comma, and restore testcases to check the list.


Swift SVN r5182
2013-05-16 19:48:42 +00:00
Chris Lattner
1f2eb7e77b switch the SIL printer to use // as its comment character instead of using ;
Swift SVN r5178
2013-05-16 18:44:16 +00:00
Joe Groff
d5784307d2 SILGen: Emit objc_msgSend-able thunks in SIL.
Emit thunks for [objc] class methods and properties as SILFunctions, using SILGen's OwnershipConventions. This will help kill some redundant ownership code in IRGen, and will allow msgSend thunks to handle string and block bridging. IRGen doesn't actually codegen the thunks yet; that will require teaching IRGenSILFunction how to be AbstractCC-aware, so for now, we just reemit the thunks using the old IRGen code.

Swift SVN r5168
2013-05-14 01:22:12 +00:00
Joe Groff
d2e18f74c8 SIL: ArchetypeMethodInst doesn't need a value operand.
Archetype methods can be looked up from the local witness tables for the archetype independent of an object.

Swift SVN r5152
2013-05-10 22:26:22 +00:00
Joe Groff
f5eaf12011 SIL: Print function types with SIL representation.
SIL mangles function types enough that the Swift function type is unhelpful and potentially misleading, especially if we start bridging types in SILGen.

Swift SVN r5135
2013-05-09 22:59:37 +00:00
Joe Groff
f79e939460 SIL: Sever load-bearing links to the AST.
Make IntegerLiteral, FloatLiteral, and StringLiteral own their own copies of their values so they don't depend on the AST. Remove the now-redundant IntegerValueInst, which only existed to be a non-AST-dependent variant of IntegerLiteral.

Swift SVN r5045
2013-05-06 03:08:58 +00:00
Joe Groff
0566088bf2 Move name mangling into SIL.
Sever the last load-bearing link between SILFunction and SILConstant by naming SILFunctions with their mangled symbol names. Move the core of the mangler up to SIL, and teach SILGen how to use it to mangle a SILConstant.

Swift SVN r4964
2013-04-28 03:32:41 +00:00
John McCall
5cd2af74ae Add a newline after the pretty stack trace for a SILFunction.
Swift SVN r4921
2013-04-26 18:48:35 +00:00
Joe Groff
54e101c517 SIL: Give BuiltinFunctionRef its own instruction.
We don't want to have to recover from a mangled name whether a function call is to an IRGen-lowered builtin, so add an instruction for referencing builtins.

Swift SVN r4919
2013-04-26 18:36:47 +00:00
Joe Groff
d0e0911ecf SIL: Add builtin_zero instruction.
To represent the zero value of builtin types.

Swift SVN r4907
2013-04-25 19:50:56 +00:00
Joe Groff
ee9ca634a5 SIL: Add linkage and calling conv to SILFunctions.
Move AbstractCC into SILType and make it an attribute of SILTypes for functions. Add a ConvertCCInst to represent calling convention conversions. Give SILFunctions a linkage attribute. Add logic to SILGen to calculate these attributes for SILConstants based on their attached decls.

IRGen doesn't use these new attributes yet. I'll hook that up when I move mangling over.

Swift SVN r4886
2013-04-24 18:09:44 +00:00
Joe Groff
bcb49ce450 SIL: Key functions directly without SILConstant.
Replace 'constant_ref' with 'function_ref', which references a SILFunction directly, and 'global_addr', which references a global variable VarDecl. Get rid of the SILConstant-to-SILFunction mapping in SILModule and replace it with an ilist of SILFunctions. Allow SILFunctions to be 'external' by not having any blocks in their body. 

For now, SILFunctions still carry around their SILConstant "name", because name mangling and IRGen still rely on access to the original decl in order to recover IRGen information, which unfortunately leaves IRGen's CodeRefs in a gross, awkward intermediate state. Lifting mangling, AbstractCC, and other linkage attributes to SIL should clear up this up.

Swift SVN r4865
2013-04-23 23:29:04 +00:00
Joe Groff
b761bad088 SILGen: Lower some builtins to SIL.
The value semantics primitives load/move/assign/init/destroy lower trivially to SIL value semantics operators, and the bridge casting operations introduce r/r semantics that should be visible to the ARC optimizer, so move the lowering for these builtins up to SILGen. Add a BUILTIN_SIL_OPERATION metaprogramming macro to Builtins.def, and add a facility similar to IRGen's former SpecializedCallEmission so we can handle builtin call emissions as special cases.

This also sets up the framework for eventually reintroducing special-case handling of known functions like &&, ||, Bool.getLogicValue, Int.convertFromIntegerLiteral, etc. in SILGen.

Swift SVN r4862
2013-04-22 23:05:18 +00:00
Joe Groff
e7f7df3027 Implement 'x is T' in SILGen.
Add an IsaInst to represent type tests, and implement SILGen for IsSubtypeExpr AST nodes. Get rid of SuperIsArchetypeExpr because it's not really necessary to have it different from IsaSubtype--the SIL and IR behavior is identical.

Swift SVN r4855
2013-04-21 20:33:54 +00:00
Joe Groff
f211c1d3d2 SIL: Factor out boilerplate from unary insns.
Create a UnaryInstructionBase that factors all the boilerplate out of all the unary instructions. It'll be easy to generalize to all fixed-arity instructions, but let's start simple. No functionality change.

Swift SVN r4854
2013-04-21 18:58:35 +00:00
Joe Groff
ce75e47139 SIL: Add instructions for RetainAutoreleased and AutoreleaseReturn.
Swift SVN r4821
2013-04-19 02:03:31 +00:00
Joe Groff
b9bb84c58e SILGen: Emit implicit constructors.
Teach SILGen how to emit the implicit elementwise constructor for structs and the implicit default constructor for classes, and eliminate the now dead IRGen code for them. Add a StructInst SIL instruction to represent constructing a loadable struct value from elements, analogous to TupleInst for tuples.

Swift SVN r4778
2013-04-17 20:51:26 +00:00
Joe Groff
9ff03ec06d SILGen: Stub out support for oneof elements.
Add a OneOfElement kind to SILConstant so we can at least reference Bool's element constructors.

Swift SVN r4733
2013-04-14 16:43:13 +00:00
Joe Groff
8ee0fb4e96 SILGen: Zero-initialize structs in constructors.
Otherwise we try to release junk pointers when we reassign class fields in the struct. Add an attribute to InitializeVarInst so that when dataflow analysis comes online, it knows that these InitializeVars need to be eliminated and can't be lowered to default constructor calls (since we're already in a constructor).

Swift SVN r4730
2013-04-13 20:45:18 +00:00
Joe Groff
4cdcdba22e SIL: Add BridgeToBlockInst.
And in SILGen, lower BridgeToBlockExprs to BridgeToBlockInsts.

Swift SVN r4723
2013-04-13 17:05:38 +00:00
John McCall
dd4f26c6dc It does seem to make non-generic assumptions about the node
type, though;  I had to define a WriteAsOperand function and
add a front() method to SILFunction to get this to work.
Rip out my dominators implementation and replace it with
LLVM's.  I'd forgotten that LLVM's was actually generic.

Swift SVN r4717
2013-04-12 21:24:27 +00:00
Joe Groff
bc2abab6d1 SIL: Add SILValue::dumpInContext.
Dumps an instruction with its operands and users. Useful for debugging.

Swift SVN r4713
2013-04-12 16:36:25 +00:00
John McCall
7e15f0a557 Make SIL-visiting not have a default implementation, make classof
take a const ValueBase* instead of a SILValue, implement SILArgument
cases for a few visitors and opt others out explicitly, and assert
that classes in the SIL value hierarchy override their superclass's
classof.

Swift SVN r4705
2013-04-12 01:39:52 +00:00
Joe Groff
950ca1c929 SIL: Print type of string_literal insns.
string_literal can have a two-element tuple type (with any labels) or a Builtin.RawPointer type, so print the type of the string_literal when emitting SIL.

Swift SVN r4699
2013-04-12 00:00:48 +00:00
Chris Lattner
7f13910498 revert r4673: respecializing SILConstant for ValueDecl instead of Decl.
On second thought, having SILConstant be able to point to a TLCD is going 
against the goal of making SILConstant be a "SILGen thing".  I'll find another
approach.


Swift SVN r4680
2013-04-11 17:41:36 +00:00
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
Chris Lattner
a71bc3a78e rename Value -> SILValue, BasicBlock -> SILBasicBlock, BBArgument -> SILArgument.
Swift SVN r4594
2013-04-03 21:05:42 +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
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
Chris Lattner
b96818f7d7 Line up all comments (predecessors, users) in column 50 instead of being so tab ragged.
Print sil function bodies as "sil" declarations, not func_decl.
Print an @ before the sil declaration name for consistency with uses.



Swift SVN r4568
2013-04-01 23:10:18 +00:00