Commit Graph

234 Commits

Author SHA1 Message Date
Roman Levenstein
97014172b7 [sil-combine] String literal concatenation optimization. Constant-fold concatenation of string literals known at compile-time.
Addresses rdar://17033696.

Swift SVN r21526
2014-08-28 11:33:21 +00:00
Erik Eckstein
2cd1c7df3a Add an isResilient check in SILType.
This is a wrapper for calling isResilient on nominal type decls.



Swift SVN r21449
2014-08-26 00:38:56 +00:00
Erik Eckstein
17c4a50766 Let the switch_enum instruction return a unqiue enum case for the default block, if possible.
This enables removal of more redundant switch_enum instructions, like

  switch_enum %0 : ..., default bb2
bb2:
  switch_enum %0 : ...




Swift SVN r21418
2014-08-22 18:51:56 +00:00
Michael Gottesman
9e55da4c92 [sink] Teach SILInstruction::isIdenticalTo how to handle retain_value. This is why we have not been sinking retain_value from predecessors.
I also cleaned up some code in InstructionIdentityComparer. We compare operands
before we hit the comparer, so we don't need to check operand equality there.

Swift SVN r21359
2014-08-21 16:16:13 +00:00
Michael Gottesman
96ef9814f5 Change CondBranchInst::getArgForDestBB() so that it returns SILValue() if the TrueBB and the False BB equal and so that it takes the SILArgument instead of the index.
Swift SVN r21335
2014-08-21 03:45:35 +00:00
Michael Gottesman
dec1bea98b Add support to SILArgument for finding the index of the SILArgument and a method on CondBranchInst to return the ith argument associated with a specific BB.
Together these allow you to find the specific cond_br argument that will be
passed to a BB by performing:

CBI->getArgForBB(BB, BBArg->getIndex())

Swift SVN r21326
2014-08-20 23:40:48 +00:00
Michael Gottesman
f0043de416 [cse] Add support for address_to_pointer and index_addr.
This reduces the number of optimizable retain, release pairs in a swap on Strings from 6 to 2:

func foo(inout T : [String]) {
  swap(&T[9], &T[1])
}

Swift SVN r21191
2014-08-14 01:45:34 +00:00
Pete Cooper
b14a2cf14d Implement all the missing conversion instructions in isIdenticalTo. These are in the same order as those listed in writeSILInstruction to make it easy to see which ones are simple conversion instructions
Swift SVN r19742
2014-07-09 20:59:22 +00:00
Pete Cooper
1aad2faaf5 Add RefToRawPointerInst to isIdenticalTo
Swift SVN r19737
2014-07-09 20:19:41 +00:00
Joe Groff
9f4c417095 SIL: Forward-declare witness tables with correct linkage.
Fixes <rdar://problem/16997968>.

Swift SVN r19680
2014-07-08 05:30:35 +00:00
Arnold Schwaighofer
7207b6ca0b TrivialCloner: Also clone the basic block for operands
In order to be able to clone branch instructions.

Swift SVN r19632
2014-07-07 21:05:22 +00:00
Nadav Rotem
0ad0c46a19 CSE: add support to the new bitcast instructions.
Swift SVN r19197
2014-06-26 00:10:17 +00:00
John McCall
f0e14f7e65 Carry the formal types of the arguments in the indirect-cast
instructions.

Swift SVN r18934
2014-06-16 17:35:43 +00:00
Adrian Prantl
17e3604b43 Make sure all non-inlining uses of SILCloner also clone the SILDebugScope
hierarchy. I still need to figure out a reliable way to write testcases
for this. For now it's ensured via an assertion in SILCloner::postprocess.

Swift SVN r18917
2014-06-15 20:50:49 +00:00
John McCall
f5749cc037 Track the consumption behavior of the new indirect-cast
instructions.

Swift SVN r18785
2014-06-10 22:27:56 +00:00
John McCall
0f0874bb4b Add variants of the checked-cast instructions that
put the result in a different place.

WIP: no IRGen support yet.

This will eventually be the required form when casting
to an address-only type; the existing instructions will
have only scalar outputs.

Swift SVN r18780
2014-06-10 07:43:22 +00:00
Michael Gottesman
eb9a804a75 [sil-cse] Teach CSE how to handle unchecked_enum_data.
Swift SVN r18694
2014-06-03 08:31:09 +00:00
Joe Groff
d6957d0328 Make existential-to-concrete metatype casts work.
This mostly falls out from the metatype cast infrastructure, but we need to generalize some Sema and SILGen code to accept AnyMetatypeType. Concrete-to-existential metatypes will need more runtime checking that isn't implemented, so raise a 'not implemented' error on those for now.

Swift SVN r17798
2014-05-09 20:57:55 +00:00
Michael Gottesman
a7bb61265c [deserialization] Tighten up deserialization of witness tables.
We now enforce via an assert that each witness table is unique and that
every protocol conformance that is referenceable from SIL must have a
witness table matched to it.

Also, I taught the linker that it should deserialize witness tables for
InitExistentialRefInst instructions, something that was missed before.

Swift SVN r17283
2014-05-02 22:28:13 +00:00
Joe Groff
51bde1485d Remove stray assertion.
The verifier will eventually check this (again).

Swift SVN r17128
2014-05-01 00:08:41 +00:00
Joe Groff
aeb607ad5b Fix latent SIL verification errors.
r15824 overrode SILVerifier::visitSILBasicBlock without calling up to the super definition, causing us to never actually verify any instructions for the past three weeks. Awesome. Patch up the latent bugs that have crept in, except for three devirtualizer tests that fail. This doesn't reenable the verifier because I don't want to cause crashes until all the regressions have been cleared up.

Swift SVN r17121
2014-04-30 22:33:46 +00:00
John McCall
8681963bcb A couple of long-overdue renames.
Builtin.ObjectPointer -> Builtin.NativeObject
Builtin.ObjCPointer -> Builtin.UnknownObject

Swift SVN r16634
2014-04-22 00:17:08 +00:00
Michael Gottesman
45b45b8b7a [cse] Teach CSE how to handle enum insts.
rdar://16560688

Swift SVN r16310
2014-04-14 11:05:41 +00:00
Michael Gottesman
0bc4f9c936 Call SILFunction destructor when we cleanup functions so that if the function contains a function_ref, the function referenced by the function_ref has its refcount properly decrement.
Otherwise a function_ref which was supposed to be deallocated would keep
functions alive.

rdar://16287331

Swift SVN r16192
2014-04-11 01:44:38 +00:00
John McCall
a7a4f67f1b Bump the reference count of a function as long as it's sitting
around in the deserializer's .
1,2d
1i
Bump the reference count of a SILFunction as long as it's sitting
around in the deserializer's cache.

If we deserialize a function, then delete it, then deserialize
another reference to it, we'll end up pointing to a deleted
function.  This was causing the bug where IRGen would assert
with "no order number for SIL function definition?"; I can't
seem to find a radar for that, though.

Also, deserialization test cases are hard to write and probably
inherently unstable.

Swift SVN r15908
2014-04-04 00:53:55 +00:00
Chris Lattner
afea47b621 rename "destroy_value" to "release_value", part of rdar://15889208.
Swift SVN r15777
2014-04-02 05:33:52 +00:00
Joe Groff
f6f3d6c324 SIL: StringLiteralInsts aren't identical if their encodings differ.
Fixes a problem where CSE would coalesce string_literals with the same text but different encodings when they happened to land in the same hash bucket.

Swift SVN r15603
2014-03-29 02:50:36 +00:00
Nadav Rotem
51087ea8b0 CSE cond_fail.
Swift SVN r15111
2014-03-16 04:27:07 +00:00
Nadav Rotem
6b6761fa08 CSE ApplyInst of BuiltIns with no side effects.
Swift SVN r15110
2014-03-16 03:52:18 +00:00
Nadav Rotem
9583261228 CSE two more instructions.
Swift SVN r15102
2014-03-15 07:25:26 +00:00
Doug Gregor
5d8bd84dfa Introduce the SIL instruction alloc_ref_dynamic.
alloc_ref_dynamic allocates an instance of a class type based on the
value in its metatype operand. Start emitting these instructions for
the allocating constructor of a complete object initializer (not yet
tested) and for the allocating constructor synthesized for an imported
Objective-C init method.

Still missing:
  - IRGen still does the same thing as alloc_ref right now. That
  change will follow.
  - There are devirtualization opportunities when we know the value of
  the metatype that would turn an alloc_ref_dynamic into an alloc_ref;
  I'm not planning to do this optimization.



Swift SVN r14560
2014-03-01 21:55:50 +00:00
Doug Gregor
2134072285 Split open_existential[_ref] out as their own instructions.
Riding off of project_existential[_ref] was convenient, but the
resuls are used quite differently. Note that open_existential[_ref]
still don't print/parse reasonably yet.



Swift SVN r13878
2014-02-13 23:42:23 +00:00
Michael Gottesman
2bf56c0dee Add in abstract SILInstruction AllocationInst so we can query if we have an Alloc{Stack,Box,Ref,Array} by just doing isa<AllocationInst>.
Swift SVN r13515
2014-02-05 23:02:58 +00:00
Chris Lattner
7532213f4a simplify the SIL string_literal instruction to only produce a single value,
which is the address of the string data.  Have SILGen compute and produce the
isASCII bit as an integer literal, and remove the logic from IRGen.

This overall approach is simpler and enables better SIL-level optimizations.


Swift SVN r13363
2014-02-03 19:10:37 +00:00
Nadav Rotem
56fea71716 Add more cases to the InstructionComperator. Also, return ‘false’ on unknown instructions instead of asserting.
Swift SVN r13091
2014-01-29 06:11:36 +00:00
Michael Gottesman
38871aed5e Add in abstract base class LiteralInst for literal instructions and modify all the literal SIL classes to inherit from it appropriately.
Swift SVN r12764
2014-01-22 19:23:11 +00:00
Nadav Rotem
1c9fbf5dac Teach CSE about ref_element_addr.
Swift SVN r12324
2014-01-15 07:45:44 +00:00
Chris Lattner
d82df1e073 make the SIL Printer print the var decl associated with a debug_value[_addr],
like this:
  debug_value %0 : $Int64  // let a               // id: %2



Swift SVN r12191
2014-01-11 01:40:15 +00:00
Chris Lattner
1c7803a1f9 Introduce new debug_value and debug_value_addr instructions to
give 'let' declarations debug info.  This is part of rdar://15785053.

IRGen is just stubbed out and nothing generates these yet (other than
the sil parser).


Swift SVN r12179
2014-01-11 01:07:36 +00:00
Doug Gregor
3f09a9891d Add an [objc] bit to the alloc_ref instruction to indicate when to use Objective-C's +allocWithZone:.
Swift SVN r12099
2014-01-09 21:35:55 +00:00
Joe Groff
8f6a58b998 SIL: Split address-only enum dispatch from destructive projection.
Split 'destructive_switch_enum_addr' into separate 'switch_enum_addr' and 'take_enum_data_addr' instructions. This should unblock some optimization work we would like to do with enums.

Swift SVN r12015
2014-01-07 22:58:21 +00:00
John McCall
12b1c9daf7 Add support for multiple encodings to the string_literal
SIL instruction.  Implement IR-gen support for same.  Fix
the parsing of SIL string literals to properly unescape them.

SIL-gen still emits UTF8 literals unconditionally.

Swift SVN r11904
2014-01-04 11:42:57 +00:00
Doug Gregor
1ee513e7e8 Use Builtin.Word for array lengths, string literal lengths, etc.
This eliminates a number of 64-bit integer/64-bit pointer assumptions
in the type checker and SILGen.


Swift SVN r11863
2014-01-03 18:53:01 +00:00
Nadav Rotem
20410a3b92 CondBranchInst: Save the number of true and false arguments.
The current implementation depends on the target basic block to record the number of argumens, but this is a bad idea because it makes it difficult to modify the argument list.



Swift SVN r11597
2013-12-23 06:23:02 +00:00
Michael Gottesman
045b9eb6f9 [cse] Add support for metatype.
With this commit CSE reduces the size of the standard library in SIL by 3840
lines.

Swift SVN r10913
2013-12-06 05:04:44 +00:00
Michael Gottesman
b3b50b0997 Refactor out the isIdenticalTo code into a visitor pattern.
This is inspired by Chris's SILVisitor suggestion for CSE.

Swift SVN r10911
2013-12-06 04:48:41 +00:00
Michael Gottesman
878cf0bb98 Rename SILInstructionMemoryBehavior => MemoryBehavior and move MemoryBehavior into SILInstruction.
Swift SVN r10770
2013-12-04 01:38:13 +00:00
Michael Gottesman
d8d1393611 Implement SILInstruction::isIdenticalTo for all literal types in preparation for CSE.
The code here is a simple checklist. It performs the following checks in order:

1. Quick check to see if the kind/number of operands/number of types match up.
2. Comparison all of the types/operands.
3. Finally use a switch to perform specialized per instruction comparisons on
state not represented in the instructions types/operands (i.e. vardecls,
structdecls, etc.).

Additionally the switch is setup so that instructions which have not been fully
implemented in the switch will cause an unreachable to be hit. Once all
instructions have isIdenticalTo implementations (implying the switch is
covered), I will remove the unreachable.

*NOTE* The primary use case for this now is CSE. In CSE we can control which
instructions we process so during the review process I am only going to process
literals for the sake of simplicity (and thus this patch contains only code for
checking literals).

Swift SVN r10743
2013-12-03 00:26:10 +00:00
Michael Gottesman
c2342df22e Removed trailing whitespace.
Swift SVN r10738
2013-12-02 22:52:01 +00:00
Chris Lattner
ad05efc481 Redesign the BuiltinFunctionRefInst to contain an Identifier instead of
a FuncDecl.  This makes it much more straight-forward for SIL passes to
introduce a new one - without doing name lookup in the builtin module!



Swift SVN r10694
2013-11-30 01:49:36 +00:00