Commit Graph

116 Commits

Author SHA1 Message Date
Stephen Lin
b0cdee2b9b Move SILBuilder::getTupleElementType and SILBuilder::getStructFieldType to SILBuilder.cpp
Swift SVN r8279
2013-09-16 18:19:14 +00:00
Adrian Prantl
83d7e9d69b silence warnings
Swift SVN r8231
2013-09-14 00:19:06 +00:00
Chris Lattner
7c8ae9352a Add a new "mark_function_escape" instruction that will be used to mark the
escape point of function definitions that "close" over global variables.



Swift SVN r8152
2013-09-12 18:31:00 +00:00
Doug Gregor
24f4706056 SIL: Introduce the dynamic_method_br instruction.
The dynamic_method_br instruction branches depending on whether a
particular object can accept a given message, as determined at
runtime. If the object can accept the message, it branches to the
first basic block, providing the uncurried method as the BB
argument. If the object cannot accept the message, it branches to the
second basic block. Either way, the result is packaged up into an
optional type and passed along to the continuation block, which
provides the optional result.

Note that this instruction is restricted to lookup of Objective-C
methods.

Documentation and IR generation (via -respondsToSelector) to
follow. Review greatly appreciated!



Swift SVN r8065
2013-09-09 23:46:10 +00:00
Michael Gottesman
c001e3e82b Added SILInstructionMemoryBehavior::MayRead/MayReadWrite and mayRead()/mayWrite() methods on SILInstruction.
Swift SVN r7963
2013-09-05 22:28:54 +00:00
Michael Gottesman
6988171ee6 As per my discussions with Anna, removed MayWriteAndHaveSideEffects.
The reason we decided to do this is that MayHaveSideEffects implies that a write
can occur, making MayWriteAndHaveSideEffects redundent.

Swift SVN r7943
2013-09-05 06:57:25 +00:00
Michael Gottesman
c86a54a438 Renamed SILBasicBlock::getInsts() => SILBasicBlock::getInstList() as discussed on the list.
Swift SVN r7776
2013-08-30 03:40:37 +00:00
Dmitri Hrybenko
69cfa73640 More 'this' -> 'self' replacements
Swift SVN r7657
2013-08-28 02:57:21 +00:00
Anna Zaks
440631f86a [SIL] Add the SILLocation hierarchy.
Now we should be ready to start using these.

Swift SVN r7632
2013-08-27 22:16:18 +00:00
Ted Kremenek
8f5b8ccb02 Rename "This" to "Self" and "this" to "self".
This was not likely an error-free change.  Where you see problems
please correct them.  This went through a fairly tedious audit
before committing, but comments might have been changed incorrectly,
not changed at all, etc.

Swift SVN r7631
2013-08-27 21:58:27 +00:00
Joe Groff
c74dc79610 SIL: Add instructions to implement address-only unions.
Because union layout may interleave tag bits with payload data, we need to be able to efficiently inject and remove tag bits from an address-only union in-place. To do this, we'll model address-only union initialization by projecting out the data address (union_data_addr) and storing to it, then overlaying the tag bits (inject_union_addr). To dispatch and project out the data, we'll use a destructive_switch_union_addr instruction that clears any tag bits in-place necessary to give a valid data address.

Swift SVN r7589
2013-08-26 20:50:31 +00:00
Chris Lattner
69d0afb658 rename [force_inlining] to [transparent].
Swift SVN r7448
2013-08-22 16:05:41 +00:00
Anna Zaks
21ce68188d [SIL] Add attributes to swift builtins, specifically, the readnone attribute.
Use the attribute when deciding if a call to a builtin can be eliminated as dead.

Swift SVN r7391
2013-08-21 00:02:25 +00:00
Anna Zaks
2f05d5c4df [SIL] Move GenFunc to use getBuiltinInfo and getIntrinsicInfo.
Make the functions support a wider range of builtins and store types to make
it possible.

This is an optimization - the cached ID will be used for builtin identification,
instead of retrieval of the string name and using it as the key.

Swift SVN r7390
2013-08-21 00:02:22 +00:00
Anna Zaks
3ac84f3878 [SIL] Add getIntrinsicID(FuncDecl*), which lazyly looks up the llvm::IntrinsicID for it.
The cache is stored in the SILModule.
Add getIntrinsicID() as a member of BuiltinFunctionRefInst.
Test by using the new method in the CCP pass.

Swift SVN r7311
2013-08-17 00:41:30 +00:00
Chris Lattner
9a68bc5cbf enhance SILBuilder to have some methods for extracting tuple/struct members
without having to specify the result type of the instruction (which is
determinable from the other operands).


Swift SVN r7299
2013-08-16 22:50:42 +00:00
Anna Zaks
ba57441908 [DCE] Rely on dropping operands instead of a hack (possible as of r7234).
This makes it possible to assert that a removed instruction has no uses.

Swift SVN r7244
2013-08-14 22:54:38 +00:00
Anna Zaks
359695acbd [SIL] Add dropAllReferences and a mutable version of getAllOperands
Swift SVN r7236
2013-08-14 22:01:57 +00:00
Stephen Lin
5fc7966675 Add [force_inline] to SIL apply instruction; kill FunctionInst abstract value type
Swift SVN r7163
2013-08-12 17:33:37 +00:00
Chris Lattner
b25af92552 change the StoreWeak "initialization" bit and accessors to follow the naming
convention of the CopyAddrInst methods.


Swift SVN r7161
2013-08-12 17:30:02 +00:00
Chris Lattner
c8f01a0bf3 Introduce a new SIL "assign" instruction to represent assignments in SIL when
SILGen doesn't know whether they are initializations or stores.


Swift SVN r7146
2013-08-12 14:24:52 +00:00
John McCall
14cb7001b3 Implement basic support for [weak].
Swift SVN r7041
2013-08-08 04:04:51 +00:00
John McCall
e9b913fb5b Remove LocalStorageType, make it a kind of SILType.
Swift SVN r6968
2013-08-07 00:22:26 +00:00
John McCall
b0084f7204 Prepare SILType for more than just isAddress.
Swift SVN r6946
2013-08-06 20:23:12 +00:00
John McCall
36aa6c2645 alloc_stack needs to return two values like alloc_box.
The current implementation of dealloc_stack in IR-gen is a
no-op, but that's very much wrong for types with non-trivial
local allocation requirements, e.g. archetypes.  So we need
to be able to do non-trivial code here.  However, that means
modeling both the buffer pointer and the allocated address
in SIL.

To make this more type-safe, introduce a SIL-specific
'[local_storage] T' type that represents the required
allocation for locally storing a T.  alloc_stack now returns
one of those in additon to a *T, and dealloc_stack expects
the former.

IR-gen still implements dealloc_stack as a no-op, but
that's now easy to fix.

Swift SVN r6937
2013-08-06 07:31:41 +00:00
John McCall
adfba641a8 Eliminate AllocInst, which does nothing for us.
Swift SVN r6936
2013-08-06 07:31:38 +00:00
Joe Groff
5a2128bc77 SIL: Model project_existential using an address.
Have project_existential return $*This instead of $Builtin.OpaquePointer, and have protocol_method do the same for methods of opaque protocols. This makes it easier for passes to reason about the semantics of the projected address, since it's restricted by the semantics of SIL addresses.

Swift SVN r6872
2013-08-03 01:48:15 +00:00
Joe Groff
a851072a25 SIL: Ensure all terminators are handled by TermInst::getSuccessors.
Create a separate TERMINATOR xmacro in SILNodes.def that only expands for terminators. Use it in TermInst::getSuccessors to automatically delegate to leaf terminator getSuccessors implementations without requiring additional maintenance work when new terminator instructions are added in the future.

Swift SVN r6869
2013-08-02 23:26:17 +00:00
John McCall
796e434f63 Make "isTake" and "isInitialization" flags type-safe.
Swift SVN r6860
2013-08-02 22:38:14 +00:00
Anna Zaks
29d2d8fb92 [SIL] Add memory behavior bit to SIL instruction definition.
As per code review discussion for r 6763.

The memory behavior enumeration is currently a subset of what it could be. Let’s add more kinds as needed.

Swift SVN r6830
2013-08-02 01:27:57 +00:00
John McCall
00a940ac1b Rename weak_retain to unowned_retain and change it to
require the correct [unowned] type as an argument.

Swift SVN r6825
2013-08-02 00:02:09 +00:00
Anna Zaks
2c529eb21a [SILParser] Parse basic block arguments in branch instructions
Added types when printing these args in the SIL printer.

As a side effect, I've removed the assertions that check
that we have the correct number of arguments in the Branch instruction
creation routines. The reason is that we do not have a complete block when
parsing and creating the branch instruction and it is possible to add
arguments to a basic block after creation. The assertion will be checked
by the SIL verifier.

Swift SVN r6818
2013-08-01 21:32:05 +00:00
Jordan Rose
674a03b085 Replace "oneof" with "union"...everywhere.
We haven't fully updated references to union cases, and enums still are not
their own thing yet, but "oneof" is gone. Long live "union"!

Swift SVN r6783
2013-07-31 21:33:33 +00:00
Anna Zaks
930b95cdb0 [SIL] Add SILInstruction::mayHaveSideEffects helper.
Swift SVN r6765
2013-07-30 23:08:37 +00:00
Joe Groff
26c00fd429 SIL: Add a switch_int instruction.
This will help represent cleanup blocks in the grown-up Clang way instead of the childish SILGen way, e.g.:

  retain %x
  retain %y
  ...
break_branch:
  %1 = int_literal 1 : $Builtin.Int64
  br cleanup(%1)
return_branch:
  %2 = int_literal 2 : $Builtin.Int64
  br cleanup(%2)
cleanup(%dest : $Builtin.Int64):
  release %z
  release %y
  switch %dest, case 1: break_dest, case 2: return_dest

Swift SVN r6753
2013-07-30 21:32:23 +00:00
Joe Groff
3c03a8cb21 SIL: Patch up float_literal bit handling.
Add a getBits() method to FloatLiteralInst so we don't need to round trip APInt -> APFloat -> APInt to print the bits in the printer. Use allocateLiteralInstWithBitSize instead of -WithTextSize to avoid wasting space.

Swift SVN r6680
2013-07-28 17:39:51 +00:00
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
Chris Lattner
c7373c563b add regular convenience methods to SIL IR objects for getting parent containers.
Add a getOperand(n) method to SILInstruction.


Swift SVN r6425
2013-07-21 06:12:29 +00:00
Chris Lattner
f8c8eb1037 add some helper methods for IR passes to use.
Swift SVN r6407
2013-07-20 01:36:46 +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
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
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
Anna Zaks
f6d1ec48f0 [SIL] Refactor SILLocation not to derive from PointerUnion3 but to include it as a member
As per Chris's suggestion (review of r6152), further refactored SILLocation not to derive from PointerUnion3 but to include it as a member.

In addition, added some template magic to make sure we don't have to chain dyn_casts, which I suspect will be/is happening a lot with SILLocation:
Ex:
-  if (auto E = Func.dyn_cast<Expr*>()) {
-    if (const FuncExpr *FE = dyn_cast<FuncExpr>(E))
-      return SILLocation(FE->getBody())
+  if (const FuncExpr *FE = Func.getAs<FuncExpr>())
+    return SILLocation(FE->getBody());

Swift SVN r6283
2013-07-16 01:50:29 +00:00
Dmitri Hrybenko
aa46064432 Pass a const ASTContext and const DeclContext whenever possible. This makes it
possible to use lookupVisibleDecls() with a const DeclContext.


Swift SVN r6274
2013-07-15 23:39:00 +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
Joe Groff
f24add3175 SIL: Give Unreachable instructions SILLocation info.
UnreachableInst's constructor didn't take a SILLocation. Oops. Fix that, and associate Unreachables emitted due to failed switch coverage with the switch. For missing-return Unreachables, there isn't yet readily available SILLocation info to attach to them, but Anna will fix that soon.

Swift SVN r6132
2013-07-10 21:54:37 +00:00
Joe Groff
5f9ff68d95 Revert r5949: "SIL: Null-terminate literal instruction string data."
The APFloat crash should be fixed in LLVM trunk, and we haven't seen the Interpreter crash in a while.

Swift SVN r6095
2013-07-09 20:49:52 +00:00
Joe Groff
0ac8c2b532 SIL: Null-terminate literal instruction string data.
Guard against StringRef-uncleanness in APFloat (e.g. rdar://14323230) and hopefully stop the intermittent buildbot failures in some Interpreter tests.

Swift SVN r5951
2013-07-01 21:48:31 +00:00
Joe Groff
665cbf56c1 IRGen: Implement conversions between class protocol types.
Implement existential upcasts from a class-bounded protocol type to a more general one.

Swift SVN r5673
2013-06-19 02:46:29 +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