Commit Graph

175 Commits

Author SHA1 Message Date
Michael Gottesman
3f192f0c8d When using simplifyInstruction, RAUW SimplifedInst[0] with the returned SILValue instead of attempting to replace all operands.
The specific case of interest I ran into was:

  sil-extract(struct(string_literal[2]))

which using the old logic would fail since we would be trying to replace all
sil-extract arguments with string_literal arguments. The different result arity
would then hit an assertion.

Swift SVN r11607
2013-12-23 19:59:03 +00:00
Michael Gottesman
cda85f6d09 Canonicalize copy value of trivial types to no-ops+RAUW and reference types to strong_retain+RAUW.
<rdar://problem/15567540>

Swift SVN r11041
2013-12-09 22:21:00 +00:00
Michael Gottesman
07d7df4453 Canonicalize destroy value of trivial types to no-ops and reference types to strong_release.
<rdar://problem/15567540>

Swift SVN r11040
2013-12-09 22:20:58 +00:00
Michael Gottesman
b5b3820a22 [sil-combine] Change order of header includes so swift is before llvm to match other passes.
Swift SVN r10881
2013-12-05 20:02:22 +00:00
Michael Gottesman
4379283013 Remove inclusion of SILPasses/Passes.h into Subsystems.h and update all relevant files.
Swift SVN r10880
2013-12-05 19:58:21 +00:00
Michael Gottesman
4d4985ce16 [sil-combine] StructElementAddrInst has only one result. Use the special replaceInstUsesWith since it will be faster.
Swift SVN r10762
2013-12-03 22:42:56 +00:00
Michael Gottesman
1d03ec3421 [sil-combine] Set the insertion point of the builder after we have run the instruction through simplifyInstruction.
simplifyInstruction does not use the builder implying that if we successfully
simplify the instruction and continue, we will have initialized the builder for
nothing.

Swift SVN r10759
2013-12-03 22:24:49 +00:00
Michael Gottesman
08181f9f75 Refactor out all result replaceAllUsesWith from SILCombine into SILInstruction::replaceAllUsesWith.
Swift SVN r10758
2013-12-03 22:24:48 +00:00
Michael Gottesman
498a2a96bb [sil-combine] Add an overload of replaceInstUsesWith that handles replacing only one result with another result instead of all results.
Swift SVN r10756
2013-12-03 22:00:31 +00:00
Michael Gottesman
c210d23c93 [sil-combine] Change replaceInstUsesWith so that it replaces all results instead of just the 0 result.
I am preparing an additional patch after this that gives the user the option of
just replacing the ith result of the instruction with the jth result of the
value type. Only the users of the ith result of the instruction in that method
will be added to the worklist.

Swift SVN r10755
2013-12-03 22:00:30 +00:00
Michael Gottesman
7c2f5cb394 [sil-combine] Small cleanups.
Swift SVN r10660
2013-11-22 06:40:37 +00:00
Michael Gottesman
81ab6382b9 Add a template specialization to PatternMatch::match for SILValue to eliminate need for match(&*Value) to match.
I also updated the relevant code to use match(Value) instead of match(&*Value).

Swift SVN r10659
2013-11-22 06:37:13 +00:00
Michael Gottesman
b44fc94b96 [sil-combine] Small cleanup to the peephole from r10619 suggested by Chris.
Swift SVN r10631
2013-11-21 07:35:51 +00:00
Michael Gottesman
f47d8714b2 Reapply "[sil-combine] (struct_extract (load %x) #vardecl) -> (load (struct_element_addr %x #vardecl))"
This reapplies commit r10605 with the relevant fixes. The specific bug
had to do with the original code inserting the new
load/struct_element_addr at the struct_extract instead of at the load
instruction. As an example of this consider the following:

%y = (load %x)
(do_stuff)
(struct_extract %y #vardecl)

if (do_stuff) modifies the memory at %x that aliases what we would be
extracting from %y, then transforming the code to:

  (do_stuff)
  %y = (struct_element_addr %x #vardecl)
  (load %y)

would yield an incorrect value. This patch changes the transformation so that we
perform the following transformation instead:

  %y = (struct_element_addr %x #vardecl)
  (load %y)
  (do_stuff)

which will resolve the issue.

This peephole triggers 365 times in the stdlib.

Swift SVN r10619
2013-11-21 01:31:08 +00:00
Dave Abrahams
e05b4a416b Revert "[sil-combine] (struct_extract (load %x) #vardecl) -> (load (struct_element_addr %x #vardecl))"
This reverts r10605, which broke the stdlib/String.swift test

Swift SVN r10612
2013-11-20 23:47:46 +00:00
Michael Gottesman
4208d36cf0 [sil-combine] (struct_extract (load %x) #vardecl) -> (load (struct_element_addr %x #vardecl))
This peephole transforms struct_extract of a load into a load of a
struct_element_addr. This eliminates unnecessary creation of a non-trivial
non-reference counted types and additionally reduces the size of loads.
An example of this from RC4 is:

  %24 = struct_element_addr %1 : $*RC4, #State    // user: %25
  %25 = struct_element_addr %24 : $*Slice<UInt8>, #count // user: %26
  %26 = load %25 : $*Int64                        // user: %29
...
  %29 = struct_extract %26 : $Int64, #value       // user: %30
  %30 = apply %28(%29, %27) : $@thin (Builtin.Int64, Builtin.Int64) -> %Builtin.Int1 // user: %33

In this case there is no use of the load besides the struct_extract. This
becomes even more interesting when the type one is attempting to retrieve from
the non-trivial non-reference counted type is reference counted itself.

Swift SVN r10605
2013-11-20 20:44:10 +00:00
Michael Gottesman
adcae9a0d8 Remove trailing whitespace.
Swift SVN r10569
2013-11-19 23:48:59 +00:00
Chris Lattner
beab485db3 enhance the constant folding pass a bit to be smarter about folding
tuple-producing results (like those produced by folding overflow builtins).

Before the pass would just RAUW the apply_inst with a tuple_inst, but this
would leave around a bunch of tuple extracts.  Now we seek and destroy them.

This unblocks other transformations and allows the stdlib to shrink by another
1700 LOC.


Swift SVN r9900
2013-11-03 06:01:13 +00:00
Chris Lattner
fe34c28f12 teach silcombine to use the new InstSimplify functionality. Also
switch it to use an ArrayRef in one place.


Swift SVN r9898
2013-11-03 05:24:59 +00:00
Chris Lattner
968e89a3be improve the DEBUG output of inout-deshadow and allocbox-to-stack.
clean up a couple random things in silcombiner:
  - it shouldn't return "made any changes" out of the pass.
  - statistics should be spelled out more and don't end with periods.



Swift SVN r9755
2013-10-29 04:02:32 +00:00
Chris Lattner
c118613de3 Fix SILValue use_iterators to type the user as a SILInstruction, not just a ValueBase.
There are no values other than instructions that can use other values.  BBArguments are
defs, not uses.  This eliminates a bunch of casts in clients that use getUser().


Swift SVN r9701
2013-10-27 23:32:14 +00:00
Michael Gottesman
9625c08107 [sil-combine] Fix comments.
Swift SVN r9674
2013-10-25 17:42:49 +00:00
Michael Gottesman
a2d44397c8 [sil-combine] Add NumCombined statistic so we can count the total number of combines that occur.
Swift SVN r9525
2013-10-20 12:17:31 +00:00
Michael Gottesman
fe5f30e5a5 Change LLVM_DELETED_FUNCTION => = delete since we are using c++11 (sorry about that Joe).
Swift SVN r9405
2013-10-16 03:17:03 +00:00
Michael Gottesman
bdf7cbe178 [sil-combine] Initial SILCombine implementation.
This pass is a port of InstCombine from LLVM to SIL. Thus if you are familiar
with the code from InstCombine you will feel right at home.

Keep in mind that in order to help with review, this is just a skeleton with no
optimizations in it besides a simple DCE based off of isInstructionTriviallyDead
(which this patch exposes in Local.h like LLVM does) to ensure that trivial
testing of the pass can be accomplished since otherwise it would do nothing
implying that no tests could be written at all.

I additionally modified one test which no longer passed due to SILCombine
removing 1x unused metatype instruction from the standard library.

Swift SVN r9404
2013-10-16 03:10:14 +00:00