Commit Graph

175 Commits

Author SHA1 Message Date
Michael Gottesman
2749f9f1be [sil-combine] Refactor the SILCombine unchecked_addr_cast -> Typed GEP code to make it clearer what is going on. NFC.
Swift SVN r19126
2014-06-24 05:31:00 +00:00
Pete Cooper
7a2f007dee Peephole (condbr(xor(x, 1)), t, f) -> (cond_br(x), f, t). Includes a test case for PatternMatch behaving differently between SILValue and other matches on Apply arguments. <rdar://problem/17332412>
Swift SVN r19001
2014-06-19 15:59:59 +00:00
Michael Gottesman
735a23a0a3 [sil-combine] Rewrite unchecked_addr_cast to access layout compatible first element fields via typed GEPS.
A first element field of a nominal type is either the first element of a
struct or the first payload of an enum. We currently allow the stdlib to
rappel into struct heirarchies using reinterpretCast. This patch teaches
the optimizer how to rewrite such unchecked_addr_cast into
unchecked_enum_data_addr and struct_element_addr instructions. Then
Mem2Reg and Load Store Forwarding will remove the allocation generated
by such uses of reinterpret cast.

<rdar://problem/16703656>

Swift SVN r18977
2014-06-18 09:34:05 +00:00
Michael Gottesman
b97ce43f35 [sil-combine] Make sure when specializing a function to specialize its return type appropriately.
Swift SVN r18886
2014-06-14 03:58:13 +00:00
Michael Gottesman
90d1b06ef6 [sil-combine] Simplify (apply (partial_apply f)) -> (apply f) when the
partial apply is a partial apply of a generic function with a
non-generic substitution list.

rdar://17303157

Swift SVN r18885
2014-06-14 01:16:55 +00:00
Manman Ren
9a7cfe6a69 Optimize sub(ptrtoint(index_raw_pointer(v, x)), ptrtoint(v)) -> x.
Also Optimize sub(x - x) -> 0.


Swift SVN r18879
2014-06-13 22:15:16 +00:00
Manman Ren
7610c792d6 [SILCombine] optimize unconditional_checked_cast in -Ofast builds.
Reduce unconditional_checked_cast to unchecked_ref_cast or unchecked_addr_cast
when runtime checks are disabled.

rdar://16708688


Swift SVN r18601
2014-05-23 19:42:47 +00:00
Michael Gottesman
9755d8cbf9 [sil-combine] partial_apply without a substitution list or arguments is equivalent to a thin-to-thick function.
rdar://16860213

Swift SVN r18458
2014-05-20 19:15:26 +00:00
Michael Gottesman
0a206e2b87 [sil-combine] (strong_retain, strong_release (thin_to_thick_function)) is a no-op.
<rdar://problem/16860194>

Swift SVN r18446
2014-05-20 05:53:53 +00:00
Michael Gottesman
ed7c05e019 [sil-combine] Disable unchecked_take_enum_data_addr promotion to unchecked_enum_data when the enum type is address only.
An enum is address only if any of its cases are address only. The
mistake I made here was that I assumed if one of the enum's case
payloads was loadable then the enum was loadable.

<rdar://problem/16880697>

This change was approved by Nadav Rotem.

Swift SVN r18036
2014-05-13 22:55:09 +00:00
Michael Gottesman
d910d5197d [sil-combine] retain_value, release_value of an enum with payload where we can see the enum is equivalent to retain_value, release_value on the enum payload.
rdar://16703656

Swift SVN r17756
2014-05-09 02:04:18 +00:00
Michael Gottesman
c923ae25c4 [sil-combine] Eliminate dead thin_to_thick function.
Eliminate:

(strong_release (thin_to_thuck_function f))

rdar://16848107

Swift SVN r17663
2014-05-08 01:11:26 +00:00
Michael Gottesman
fd0a78b301 [sil-combine] Canonicalize index_raw_addr byte indexing operations => index_addr object size indexing operations.
This should eliminate pointless operations that get added to our inline
cost itinerary.

rdar://15567647
rdar://16762768
rdar://16832529

Swift SVN r17644
2014-05-07 22:01:30 +00:00
Michael Gottesman
083ac18f21 [inst-simplify] Eliminate identity unchecked_addr_cast, unchecked_ref_cast.
Swift SVN r17523
2014-05-06 02:06:55 +00:00
Michael Gottesman
4d751328bf [sil-combine] Canonicalize unchecked_addr_cast, unchecked_ref_cast of a subclass to a superclass into an upcast.
Swift SVN r17522
2014-05-06 02:06:54 +00:00
Michael Gottesman
b56c31dc5f [sil-combine] convert_function simplification.
convert_function works essentially as a bitcast on functions that
enables you to change address/ref type parameters. This commit enforces
that invariant in the verifier and teaches SILCombine how to simplify it
so we can use it in the devirtualizer.

Swift SVN r17516
2014-05-06 01:16:14 +00:00
Joe Groff
4229342571 Rename 'canBeObjCClass' to 'canBeClass' and have it return true for all classes.
This will enable the D[] <-> B[] conversions to work with all class types.

Swift SVN r17281
2014-05-02 22:04:43 +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
Michael Gottesman
1e1b32c665 [sil-combine] Refactor optimizeBuiltinCanBeObjCClass from InstSimplifer -> SILCombine since it creates instructions.
InstSimplify is meant to be more of an analysis pass which performs
simplifications that do not require instructions to be created or
eliminated.

Swift SVN r17120
2014-04-30 21:48:40 +00:00
Michael Gottesman
54ad7a32e6 [sil-combine] If we have a release_value, retain_value right next to each other
in the wrong order for the ARC optimizer due to multi-bb issues, peephole delete
them.

Swift SVN r17022
2014-04-29 05:52:07 +00:00
Michael Gottesman
4aa145d0cd [sil-combine] Promote unchecked_take_enum_data_addr -> load + unchecked_take_enum_data given a concrete type.
rdar://16703656

Swift SVN r17004
2014-04-29 00:46:50 +00:00
Michael Gottesman
83d364d4b0 [sil-combine] (unchecked_ref_cast (upcast x X->Y) Y->Z) -> (unchecked_ref_cast x X->Z)
Swift SVN r16906
2014-04-27 02:24:29 +00:00
Michael Gottesman
41d365e05b [sil-combine] (raw_pointer_to_ref (ref_to_raw_pointer x X->Y) Y->Z) -> (unchecked_ref_cast X->Z)
Swift SVN r16868
2014-04-26 02:08:20 +00:00
Michael Gottesman
7bd752421a [sil-combine] (unchecked-ref-cast (unchecked-ref-cast x X->Y) Y->Z) -> (unchecked-ref-cast X->Z)
Swift SVN r16867
2014-04-26 02:07:05 +00:00
Michael Gottesman
0f1985c1ba [sil-combine] (unchecked-addr-cast (unchecked-addr-cast x X->Y) Y->Z) -> (unchecked-addr-cast x X->Z)
Swift SVN r16866
2014-04-26 02:07:05 +00:00
Michael Gottesman
0f32b98ed4 [sil-combine] Teach SILCombine how to form unchecked_addr_casts.
It iss always safe to form unchecked_addr_casts from
address_to_pointer, pointer_to_address casts since it is undefined
behavior for that to occur and for the types to not be layout
compatible.

rdar://16703656

Swift SVN r16865
2014-04-26 02:06:54 +00:00
Joe Groff
68f942117a SIL: Squash 'ref_to_native_object' and 'native_object_to_ref' into one 'unchecked_ref_cast' insn.
An unsafe cast from a base to a derived class isn't really all that different from one from Builtin.NativeObject to an arbitrary class, so relax this pair of instructions to allow an arbitrary bitcast. This only combines the instructions; it doesn't attempt to simplify any codegen that was emitting round-trip casts before yet.

Swift SVN r16736
2014-04-24 03:10:53 +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
81ce0e8384 [sil-combine] Canonicalize (load (upcast-ptr %x)) -> (upcast-ref (load %x)). This helps devirtualization.
Swift SVN r16561
2014-04-19 01:19:31 +00:00
Michael Gottesman
487db561ca [sil_combine] Change payloaded enum promotion to be keyed off of InjectEnumAddrInst and more flexible so that the only condition is that the store and the inject_enum_addr are next to each other.
Sometimes loads sneak in between the init_enum_data_addr and the store.
This should not stop our optimization.

Swift SVN r16440
2014-04-17 04:29:03 +00:00
Michael Gottesman
5e0e6e79d0 [sil-combine] Canonicalize init_enum_data_addr+store+inject_enum_addr of a loadable enum with payload to a store of a loadable enum value.
We only do this in the simple case where all 3 instructions are right
next to each other. This is a very common pattern in the stdlib.

I XFAILED one test that is failing due to what is most likely an MCJit
issue and filed rdar://16643062

Swift SVN r16437
2014-04-17 03:41:34 +00:00
Michael Gottesman
27f6e2f568 [sil-combine] Canonicalize inject_enum_addr of a loadable enum without payload to a store of an enum value.
Swift SVN r16241
2014-04-12 00:29:57 +00:00
Mark Lacey
1452d24671 Small cleanup: Remove unnecessary calls to getDef(), mostly in dyn_cast<>(...).
Swift SVN r16235
2014-04-11 23:05:16 +00:00
Michael Gottesman
45c07489d2 Refactor Dead Function Elimination from SILCombine.cpp into its own file DeadFunctionElimination.cpp.
Swift SVN r16190
2014-04-11 01:10:28 +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
Chris Lattner
a0a65c0ea2 change the sil parser/printer to use retain_value instead of copy_value.
Swift SVN r15776
2014-04-02 05:22:41 +00:00
Chris Lattner
6540423613 rename CopyValueInst -> RetainValueInst. The .sil syntax
isn't changed yet.


Swift SVN r15775
2014-04-02 05:11:31 +00:00
Joe Groff
584009d27e SIL: Remove copy_value's result.
We won't have any types where copying has an effect on the bit pattern (except for blocks, which need special handling anyway), and copy_value having a result makes optimizations more complex, so remove it.

Swift SVN r15640
2014-03-30 03:40:45 +00:00
Nadav Rotem
5500bdae22 Add a command line flag for removing cond_fails in SIL.
Swift SVN r15432
2014-03-25 00:51:01 +00:00
Nadav Rotem
61f63769c7 Check that the store destination is the same as the switch addr.
Swift SVN r15068
2014-03-14 20:33:16 +00:00
Nadav Rotem
37fb7bfa38 Lower switch_enum_addr to switch_enum
Swift SVN r15065
2014-03-14 20:26:18 +00:00
Nadav Rotem
6c593f73af Remove init_existential of alloc_stack with no other usage by creating
a new allocation with the concrete type.



Swift SVN r15002
2014-03-13 20:28:57 +00:00
Nadav Rotem
631297d4d2 Reimplement the partial_apply+apply -> apply optimization.
This is a fix of r14842 that was reverted.



Swift SVN r14901
2014-03-11 00:39:06 +00:00
Nadav Rotem
3f61dad163 Fix a bug in the code that deletes partial_apply instructions.
The destroy_value needs to happen at the end of the partial_apply lifetime.
This is easy to do when there is only one user, strong_release, and less easy
to do when there are multiple retain/release users.



Swift SVN r14882
2014-03-10 22:48:46 +00:00
Nadav Rotem
9a37973a92 Revert -r14838. It is incorrect to remove partial_apply instructions because the partial_apply also guards the lifetime of the consumed arguments.
Swift SVN r14879
2014-03-10 22:07:47 +00:00
Greg Parker
847dd3428e Revert -r14842 which broke test/stdlib/NSStringAPI.swift.
Swift SVN r14844
2014-03-09 11:46:05 +00:00
Nadav Rotem
cc2162422b Combine apply(partial_apply()) into a single apply call.
We already inline closures inside the mandatory inliner but we miss cases
that are exposed due to other optimizations.



Swift SVN r14842
2014-03-09 08:16:59 +00:00
Nadav Rotem
c92f159a8f Allow the removal of partial_apply that is used by multiple retain/release instructions.
Swift SVN r14838
2014-03-09 07:05:08 +00:00
Michael Gottesman
541c6be44f Disable the cleaning up of dead functions by SILCombine if -sil-debug-serialization is passed in.
This will ease the writing of serialization test cases when
optimizations are enabled.

Swift SVN r14787
2014-03-07 19:27:02 +00:00
Chris Lattner
001c1890e5 put all the SIL*Transform classes in anonymous namespaces, there is
no need for their symbols to be exported out of their implementation
file.


Swift SVN r14714
2014-03-06 01:49:53 +00:00