Commit Graph

631 Commits

Author SHA1 Message Date
Chris Lattner
8d53e68a68 switch function_ref/builtin_function_ref/global_addr to print their
referenced symbol with the name, followed by a colon, followed by the type
instead of the type first (following local value references).  For example,
instead of:

  %1 = function_ref $[thin] ((val : Builtin.Int128), Int64.metatype) -> Int64, @_TSi33_convertFromBuiltinIntegerLiteralfMSiFT3valBi128__Si // user: %4

we now get:
  %1 = function_ref @_TSi33_convertFromBuiltinIntegerLiteralfMSiFT3valBi128__Si : $[thin] ((val : Builtin.Int128), Int64.metatype) -> Int64 // user: %4




Swift SVN r5735
2013-06-21 04:54:01 +00:00
Joe Groff
ff5f41b5f0 Archetypes with superclass bounds are class-bounded.
Treat archetypes with a superclass bound as class-bounded. Change SILGen and IRGen to use the new SuperToArchetypeRef and ArchetypeRefToSuper cast instructions, and drop the old SuperToArchetype and ArchetypeToSuper instructions, which are unneeded because any archetype with a superclass will be class-bounded.

Note that this patch doesn't implement representation optimization for archetypes with superclass bounds--they're still always represented with a worst-case UnknownRefCountedPtrTy.

Swift SVN r5629
2013-06-17 21:54:01 +00:00
Joe Groff
7420089303 SIL: Add instructions to represent generic dynamic casts.
Add Downcast{Archetype,Existential}{Addr,Ref} instructions to represent casting of archetypes and existentials to concrete types.

Swift SVN r5612
2013-06-17 01:23:55 +00:00
Joe Groff
e1746bd24f SILGen: Use class-bound instructions to emit class-bound ErasureExprs.
Swift SVN r5555
2013-06-10 00:22:05 +00:00
Joe Groff
2ce2d33a64 SIL: Add instructions for class-bound archetype/existential operations.
Add class-bound versions of archetype conversion and existential creation/projection/conversion instructions. Since class-bound generics aren't address-only these instruction variants don't need to indirect through addresses.

Swift SVN r5554
2013-06-09 18:12:43 +00:00
Joe Groff
a9a2bff829 SIL: Print index_addr operands with types.
As required by the SIL parser.

Swift SVN r5481
2013-06-05 19:59:10 +00:00
Joe Groff
b22fd22d57 SILGen: Handle Builtin.gep as a SIL builtin.
Add an index_raw_pointer instruction that acts like index_addr but for RawPointers, and use it to lower Builtin.gep into SIL instead of into IR.

Swift SVN r5479
2013-06-05 16:49:50 +00:00
Joe Groff
ed6b5ad497 SIL: Made index_addr index operand dynamic.
Instead of taking an integer constant index, index_addr now takes a value operand of builtin integer type, which makes more sense.

Swift SVN r5478
2013-06-05 16:49:41 +00:00
Chris Lattner
07ea8a41b6 print function calls with the type of the callee at the end. Putting the
type of the callee at the end is unusual but makes it easier to read the
call.  We now get something like this, which makes it obvious what is the
callee value and what are the arguments:

 %6 = apply %4(%5) : $[thin] ((), Int64.metatype) -> Int64 

We may end up needing types for arguments as well, but lets try to get 
away without them.



Swift SVN r5358
2013-05-27 00:50:41 +00:00
Chris Lattner
e052f3ca41 change the sil printer to print the type of the destination
operand, producing something like:

	%2 = store %0 to %1 : $*Int64

Enhance the sil parser to be able to parse this.  We can now
round trip everything required to handle this function:

func foo(a : Int) -> Int {
  return a
}




Swift SVN r5354
2013-05-26 14:43:17 +00:00
Chris Lattner
c08a0e87a7 remove dead code.
Swift SVN r5349
2013-05-26 05:56:56 +00:00
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