Commit Graph

629 Commits

Author SHA1 Message Date
Chris Lattner
a2a1b2af55 Clean up tuple and extract SILBuilder stuff:
- Introduce emitTupleExtract / emitStructExtract, which fold when their operand is a tuple/struct.
- Rename SILBuilder::createTupleExtractInst -> createTupleExtract, "Inst" isn't used as a suffix.
- Switch capture promotion and DI to use the new functions.

This trims 300 lines out of the stdlib.


Swift SVN r9897
2013-11-03 04:47:40 +00:00
Chris Lattner
03e7b756d0 teach simplify-cfg to merge blocks connected by an uncond branch, when
the dest has no other predecessors.  This fires 6926 times on the stdlib.


Swift SVN r9794
2013-10-30 16:48:59 +00:00
Chris Lattner
2127da6a91 Enhance the function_ref instruction to maintain a refcount on the
SILFunction that it references.  Use this in the mandatory inlining
pass to remove deserialized transparent functions, to clean up the
-emit-sil output of the compiler (and presumably speed up compile 
time).  This implements rdar://15272652



Swift SVN r9699
2013-10-27 22:00:54 +00:00
Joe Groff
00dcdf394f SIL: Introduce CondFailInst.
This instruction will conditionally trigger a runtime failure if its operand is true.

Swift SVN r9588
2013-10-22 15:53:04 +00:00
Chris Lattner
91c7cea310 Remove the SILModule& argument from a few methods in SILInstruction.h.
Instructions know which module they came from, so there is no need to
pass it in.



Swift SVN r9584
2013-10-22 11:06:50 +00:00
Joe Groff
61360ba7a4 SIL: Remove ConvertCCInst.
Swift SVN r9577
2013-10-22 03:16:27 +00:00
Chris Lattner
3b84c0fc05 use the standard idiom for defining a const and non-const version of a method.
Swift SVN r9526
2013-10-20 15:19:59 +00:00
Michael Gottesman
a2ee7a3d60 Make sure that the non-const version of getOperandForField calls the const version of said function instead of infinite looping.
Swift SVN r9524
2013-10-20 12:12:52 +00:00
Chris Lattner
589bd7362a simplify this, per Joe's advice.
Swift SVN r9316
2013-10-14 17:07:24 +00:00
Chris Lattner
8a6b5a29a2 add some helpers that return the struct/tuple associated with a
{struct|tuple}_element[_addr] instruction.



Swift SVN r9315
2013-10-14 17:01:22 +00:00
Dmitri Hrybenko
ae0826e34a Fix compilation issues with ToT Clang
Swift SVN r9313
2013-10-14 16:11:29 +00:00
Michael Gottesman
e90c93b344 [sil] Removed stale comment and replaced one instance of auto with the actual type for additional clarity.
Swift SVN r9228
2013-10-11 22:19:45 +00:00
Michael Gottesman
9de1dbf1ea [sil] Teach StructInsts how to return the operand for a given VarDecl.
This allows you to lookup the operand extracted from a struct by a
struct_extract in a SIL pass.

Swift SVN r9189
2013-10-11 02:53:10 +00:00
John McCall
b880e60100 Remove SILFunctionTypeInfo in favor of SILFunctionType.
We still don't actually use this as a type, however.

Swift SVN r9091
2013-10-09 20:55:55 +00:00
Adrian Prantl
37bb48afb0 Debug info: Create debug type info for box-allocated types by using their
Decl. This should allow us to emit debug info for boxed generic types.

rdar://problem/15180622

Swift SVN r9071
2013-10-09 18:25:18 +00:00
Stephen Lin
3f5c0dbf0e Update SILArgument::getModule(), SILBasicBlock::getModule() and SILInstruction::getModule() signatures to match SILFunction::getModule(), for consistency; standardize usage of SILFunction::getParent() to SILFunction::getModule().
Swift SVN r8932
2013-10-04 21:12:20 +00:00
Stephen Lin
a6108dbd48 Rename FunctionRefInst::getFunction() and BuiltinFunctionRefInst::getFunction() to FunctionRefInst::getReferencedFunction() and BuiltinFunctionRefInst::getReferencedFunction() to avoid shadowing SILInstruction::getFunction().
Swift SVN r8929
2013-10-04 20:26:41 +00:00
Joe Groff
82a18333ed SIL: Purge SpecializeInst.
Make ApplyInst and PartialApplyInst directly take substitutions for generic functions instead of trying to stage out substitutions separately. The legacy reasons for doing this are gone.

Swift SVN r8747
2013-09-28 00:15:45 +00:00
Joe Groff
a2672e9313 SIL: Turn conditional checked casts into a branch instruction.
Replace the existing suite of checked cast instructions with:

- unconditional_checked_cast, which performs an unconditional cast that aborts on failure (like the former downcast unconditional); and
- checked_cast_br, which performs a conditional pass and branches on whether the cast succeeds, passing the result to the true branch as an argument.

Both instructions take a CheckedCastKind that discriminates the different casting modes formerly discriminated by instruction type. This eliminates a source of null references in SIL and eliminates null SIL addresses completely.

Swift SVN r8696
2013-09-26 18:24:44 +00:00
Michael Gottesman
7bc9b9bfb8 Added SILInstruction::moveBefore to move an instruction before another instruction.
This is the same as llvm::Instruction::moveBefore.

Swift SVN r8689
2013-09-26 01:54:28 +00:00
Joe Groff
55bbf1f8bd Stale comment.
Swift SVN r8578
2013-09-24 00:17:59 +00:00
Joe Groff
014f270516 SIL: Have project_existential_ref project to a protocol Self archetype.
This mirrors the behavior of project_existential and simplifies some special cases in SILGen. It unfortunately makes dynamic_lookup sequences a bit noisier because of the need to explicitly cast the projection from DynamicLookup.Self to Builtin.ObjCPointer, but I think this modeling is more solid and will fit better with my planned redesign of archetype_method/protocol_method.

Swift SVN r8572
2013-09-23 21:57:12 +00:00
Joe Groff
9e54a69016 SIL: Allow RefToObjectPointer and ObjectPointerToRef to cast to/from Builtin.ObjCPointer.
Swift SVN r8558
2013-09-23 16:20:29 +00:00
Joe Groff
e109124186 Replace 'union' keyword with 'enum'.
This only touches the compiler and tests. Doc updates to follow.

Swift SVN r8478
2013-09-20 01:33:14 +00:00
Anna Zaks
1065caa2f4 [SIL] Store the BitWidth in the SwitchInstInst instead of computing it
getBitWidthForCase() is called from the destructor of the object and it
used to rely on Operand being around. However, dropAllReferences(), which
is run before instruction destruction makes the operand invalid at the
time of instruction death. (This results in a crash if we were to delete a
SwitchInstInt instruction.)

Swift SVN r8472
2013-09-19 23:41:03 +00:00
John McCall
7954960797 Add 'copy_value' and 'destroy_value' operations to destroy
entire aggregates at once.

This has three worth effects:
  - It significantly decreases the amount of SIL required
    for these operations.
  - It makes it far easier for IR-gen to choose efficient
    patterns of destruction, e.g. calling a single entrypoint
    or recognizing that it can just use the runtime 'release'
    entrypoints.
  - It makes it easier to recognize and optimize aggregate
    copy/destroy operations.
It does make SROA-like tasks a bit more challenging.  The
intent is to give TypeLowering a way to expand these into
their primitive behavior.

Swift SVN r8465
2013-09-19 22:14:55 +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
Chris Lattner
3c0c9a5da7 introduce a new mark_uninitialized SIL instruction which will be used by
definitive initialization of top-level code.


Swift SVN r8144
2013-09-12 04:30:48 +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
Doug Gregor
c5557a624c SIL: Introduce the 'dynamic_method' instruction for dynamic method dispatch.
The dynamic_method instruction handles method lookup on an existential
of type DynamicLookup based on the selector of an [objc] method of a
class or protocol. It is only introduced in the narrow case where we
are forcing a use of the method with '!', e.g.,

class X {
  func [objc] f() { println("Dynamic lookup") }
}

var x : DynamicLookup = X()
x.f!()



Swift SVN r8037
2013-09-09 16:12:50 +00:00
Doug Gregor
6e67e34b40 Rename DynamicMethodInst -> MethodInst.
Swift SVN r8031
2013-09-09 14:29:51 +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
Chris Lattner
fc04d57bd0 Rework the assign instruction in two major ways:
1. Change assign to follow SILGen's model for a semantic assignment,
   which (in the case of unowned pointers) doesn't require the left
   and right hand sides to be the same.
2. Change assign to consume/take the refcount from the LHS, following
   SILGen's design (which I completely misunderstood before).



Swift SVN r7787
2013-08-30 17:59:56 +00:00
Michael Gottesman
5679974328 Fixed comment typo.
Swift SVN r7777
2013-08-30 04:47:58 +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
Michael Gottesman
d41b871b3a At Joe's suggestion added the prefix strong to instructions Retain,Release,RetainAutoreleased,RetainUnowned to prevent confusion in between RetainUnowned and UnownedRetain.
This is was a very mechanical patch where I basically first renamed SILNodes.def
and then just kept fixing things until everything compiled, so even though it is
large patch I feel ok(ish) with committing it.

If anyone has any concerns/etc, please email me and I will revert in 1 second.

Swift SVN r7604
2013-08-26 23:32:16 +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
Joe Groff
fe1ad586e7 SIL: Add a 'union' instruction to construct unions.
The instruction represents constructing a loadable union given a case and the data for that case, which will let us emit union constructor functions in SIL instead of IRGen (rdar://problem/14773182).

Swift SVN r7558
2013-08-24 18:33:24 +00:00
Chris Lattner
d4a0c16baa revert my r7505 patch to 'assign'. It turns out that changing
assign in this way doesn't actually make things simpler, and the
former model for assign is simpler to work with.


Swift SVN r7537
2013-08-23 22:40:56 +00:00
Chris Lattner
f6a5c78df2 Per John's advice (a few weeks ago), rework the 'assign' instruction
to being a semantic assign.  The functional difference here is only
for unowned pointers, where now the conversion from strong to unowned 
is implicit in the assign.

The logic behind this is that 'assign' is really part of SILGen, that
is only moved later to make it easier to make it be flow sensitive.
Since it is part of SILGen and will be using some of the type lowering
functionality used by SILGen, we should play by its rules.

No functionality change.


Swift SVN r7507
2013-08-23 18:15:21 +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
5fb0985f85 [SIL] Fixup the copy and pasted comments.
Swift SVN r7346
2013-08-19 23:56:59 +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
Anna Zaks
359695acbd [SIL] Add dropAllReferences and a mutable version of getAllOperands
Swift SVN r7236
2013-08-14 22:01:57 +00:00
Anna Zaks
342dff1c80 [SIL CCP] Add the early constant propagation pass skeleton.
The pass folds a single operation: int_sadd_with_overflow and issues an
error on detectable overflow.

Swift SVN r7204
2013-08-13 17:36:35 +00:00