Commit Graph

512 Commits

Author SHA1 Message Date
Joe Groff
1300efb8fb SIL: Represent float_literal values with bitwise representations.
This way we don't need to deal with the inaccuracy of decimal float literals. While we're here, modify the in-memory representation of IntegerLiteralInst and FloatLiteralInst to save the word array of the APInt instead of round-tripping through plain text.

Swift SVN r6676
2013-07-27 03:57:14 +00:00
Joe Groff
11ce744de1 SILPrinter: Comment sil decls and function_refs with demangled names.
Swift SVN r6658
2013-07-26 22:39:00 +00:00
Joe Groff
6b779cc642 SIL: Spell all non-SILFunction Swift decl references with '#'.
Reserve '@' as the SILFunction introducer, and use '#' when referencing Swift decls (like with SILConstants).

Swift SVN r6563
2013-07-24 22:10:52 +00:00
Joe Groff
398cbba5be Rename SILConstant to SILDeclRef.
"SILConstant" doesn't really describe its role in SIL anymore, which is to provide a reference to a Swift declaration in a SIL instruction, such as a method or nominal type field.

Swift SVN r6559
2013-07-24 21:21:31 +00:00
John McCall
e668ff914f Add parsing and IR-gen for weak_retain and weak_release.
Swift SVN r6492
2013-07-23 06:28:51 +00:00
Joe Groff
1984cf41e0 SIL: Rename SILFunction::getMangledName to SILFunction::getName.
Swift SVN r6430
2013-07-21 18:39:51 +00:00
Chris Lattner
496446ce64 Make all SIL objects that are print()-able, also raw_ostream insertable
with <<.  Use this to implement a DEBUG() dump in MemoryPromotion.cpp


Swift SVN r6412
2013-07-20 02:43:26 +00:00
Chris Lattner
d528b49fca make getElementType() methods on SIL allocation instructions return a SILType.
This points out that perhaps IRGen's HeapArrayInfo should traffic in SILTypes
instead of CanTypes.  I did the minimal update though.


Swift SVN r6405
2013-07-20 01:25:20 +00:00
Chris Lattner
cccf26b9b0 rename [de]alloc_var -> [de]alloc_stack in the printed and parsed sil syntax.
Swift SVN r6389
2013-07-19 21:18:20 +00:00
Chris Lattner
47dd7a4cf4 rename SIL internals for AllocVar and DeallocVar to [De]AllocStack.
No syntax change yet.


Swift SVN r6382
2013-07-19 19:38:29 +00:00
Manman Ren
457f27ccac SIL Parser: parse archetype_metatype, associated_metatype, class_metatype and
protocol_metatype.

Print type to enable parsing.


Swift SVN r6350
2013-07-18 18:49:04 +00:00
Joe Groff
8e56e45f22 SIL: Define a switch_oneof instruction.
This instruction encapsulates testing, branching, and destructuring a oneof, as in:

oneof Expr {
  case True
  case False
  case IntLiteral(Int)
  case StringLiteral(String)
}

sil @dispatch_expr : $(Expr) -> () {
entry(%expr : $Expr):
  switch_oneof %expr, \
    case #Expr.True!oneofelt : bb1, \
    case #Expr.False!oneofelt : bb2, \
    case #Expr.IntLiteral!oneofelt : bb3, \
    default bb4
bb1:
  ...
bb2:
  ...
bb3(%int : $Int):
  ...
bb4:
  ...
}

Swift SVN r6329
2013-07-17 16:55:29 +00:00
Manman Ren
ee8e504b79 SIL Parser: parse ref_element_addr.
Print type to enable parsing.


Swift SVN r6316
2013-07-17 01:06:28 +00:00
Manman Ren
04c146855f SIL Parser: parse tuple_element_addr and tuple_extract.
Print type to enable parsing.


Swift SVN r6312
2013-07-17 00:31:42 +00:00
Manman Ren
36dd7bfa84 SIL Parser: parse builtin_zero, struct, struct_element_addr, and struct_extract.
Print type for struct_extract and struct_element_addr to enable parsing.


Swift SVN r6308
2013-07-16 23:23:20 +00:00
Manman Ren
1d507f2e42 SIL Parser: parse copy_addr and upcast_existential.
Modify SILPrinter to print necessary types for parsing.
Format of copy_addr is changed from
  copy_addr Src [take]? to Dst [initialization]?
  to
  copy_addr [take]? Src to [initialization]? Dst : DstType
to put the attribute in front of the actual value.
It also makes parsing easier since '[' can start an array type.


Swift SVN r6268
2013-07-15 19:06:32 +00:00
Doug Gregor
a12d30d9b1 Emit entrypoints for the default argument generator functions.
In the resilience model for default arguments, the presence of a
default argument is API, but its specific value is not. Thus, the
actual default argument values can evolve over time. To implement
this, for each default argument, we emit a function that
takes no arguments and produces the default value for that
argument. The caller will then call that function to form the default
argument.

This commit emits these functions for each default argument, even
though they are not currently being called. This is part of
<rdar://problem/11561185>.

We'll probably want a different calling convention for these functions
that preserves all registers, since they will often end up being very
trivial functions. 




Swift SVN r6260
2013-07-15 17:34:22 +00:00
Chris Lattner
12872e5190 remove the allocation kind enum from alloc_var/dealloc_var/alloc_ref. There is
only one kind now: stack.  alloc_var is just for stack memory now.


Swift SVN r6256
2013-07-15 16:48:56 +00:00
Chris Lattner
5322275156 remove the 'heap' form of alloc_var. It is not used, and the imagined
possible use cases are far enough away that we shouldn't worry about them
now.


Swift SVN r6253
2013-07-15 16:33:09 +00:00
Chris Lattner
5c1320042c remove the "pseudo" class of alloc_var. It is not used.
Swift SVN r6252
2013-07-15 16:25:19 +00:00
Chris Lattner
ba4c64479c Have -emit-sil[gen] print a couple of import options. This is a hack (the right answer
is to print all referenced decls at the start of a .sil file), but it is a useful hack.



Swift SVN r6251
2013-07-15 15:49:29 +00:00
Manman Ren
61d547a2a1 SIL Parser: handle SIL functions with generic params and parse archetype_method.
Construct ArchetypeType from generic params; Construct a Scope for the SIL
function body so TypeAliasDecl for the generic params can be added to ScopeInfo.
Remove an extra '$' in SILPrinter when printing the lookup type for an
archetype_method.


Swift SVN r6219
2013-07-12 22:21:14 +00:00
Jordan Rose
e3999dde36 [serialization] Handle absent protocol conformances.
These still need to be serialized, because they are one-to-one with the
type's protocol list, but don't actually require any data. Found on
attempting to emit a module for the standard library.

Most of the churn here is moving Interleave.h to a more general STLExtras.h.

Swift SVN r6167
2013-07-11 18:38:50 +00:00
Manman Ren
a63c78b81a SIL Parser: parse protocol_method.
New format for SILConstant:
  '#' sil-dotted-path sil-constant-kind-and-uncurry-level?
  sil-dotted-path:
    identifier ('.' identifier)*
  sil-constant-kind-and-uncurry-level:
    '!' sil-constant-kind ('.' sil-constant-uncurry-level)? ('.objc')?
    '!' sil-constant-uncurry-level ('.objc')?
    '!objc'
  sil-constant-kind:
    'func' | 'getter' | 'setter' | 'allocator' | 'initializer' | 'oneofelt' \
    | 'destroyer' | 'globalaccessor'

Add helper function printFullContext in SILPrinter to generate the fully
qualified dotted path for a given DeclContext; Add parseSILConstant to
SILParser; Testing cases are updated to reflect the new format.


Swift SVN r6055
2013-07-08 18:24:15 +00:00
Chris Lattner
dc702b2be5 implement sil parser support for the rest of the unchecked conversion instructions.
Swift SVN r5942
2013-07-01 18:50:37 +00:00
Chris Lattner
77848dada1 Don't rely on overload resolution to find the right printing logic,
just make things explicit.  No functionality change.


Swift SVN r5932
2013-07-01 17:35:48 +00:00
Chris Lattner
6b4d262d24 silprint the type of the operand to checked conversions, improving parsability.
Swift SVN r5929
2013-07-01 17:18:50 +00:00
Chris Lattner
41591909d8 Change the syntax of SIL cast instructions to use the 'to' keyword.
This is better for uniformity with store and also is less of a punctuation
soup, making things easier to read.


Swift SVN r5928
2013-07-01 16:51:02 +00:00
Chris Lattner
6c4b37fd30 make class_method and protocol_method print the type of the object value being referenced,
a step towards parsability.


Swift SVN r5925
2013-07-01 16:31:39 +00:00
Chris Lattner
efaf4f6aee make the conversion instructions print the type of both the source and destination, so we can parse them.
Swift SVN r5918
2013-07-01 00:31:10 +00:00
Joe Groff
f072c48e45 Refactor cast representation in AST and SIL, and implement 'is'.
Improve our representations of casts in the AST and SIL so that 'as!' and 'is' (and eventually 'as?') can share almost all of the same type-checking, SILGen, and IRGen code.

In the AST, we now represent 'as!' and 'is' as UnconditionalCheckedCastExpr and IsaExpr, respectively, with the semantic variations of cast (downcast, super-to-archetype, archetype-to-concrete, etc.) discriminated by an enum field. This keeps the user-visible syntactic and type behavior differences of the two forms cleanly separated for AST consumers.

At the SIL level, we transpose the representation so that the different cast semantics get their own instructions and the conditional/unconditional cast behavior is indicated by an enum, making it easy for IRGen to discriminate the different code paths for the different semantics. We also add an 'IsNonnull' instruction to cover the conditional-cast-result-to-boolean conversion common to all the forms of 'is'.

The upshot of all this is that 'x is T' now works for all the new archetype and existential cast forms supported by 'as!'.

Swift SVN r5737
2013-06-21 05:54:03 +00:00
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