Commit Graph

175 Commits

Author SHA1 Message Date
Chris Lattner
dfc39abd3e teach silcombine to merge upcast instructions that feed each other, now that
sema is emitting each step of a conversion independently.  Also, as a driveby,
fix an optimizer crash in the "(ref_to_raw_pointer (ref_to_object_pointer x)) 
to (ref_to_raw_pointer x)" peephole when the ref_to_object_pointer had other
uses (noticed by inspection).



Swift SVN r14603
2014-03-03 18:52:05 +00:00
Nadav Rotem
a4693bf143 Fix an analysis invalidation problem. rdar://16192731.
We need to run the entire pass manager pipe to expose this bug. I did not want
to include a big SIL file because it would be more code that we will need to
update if we change SIL.



Swift SVN r14531
2014-02-28 19:37:37 +00:00
Michael Gottesman
3ba6b7c663 [sil-combine] Make output of (extract (load)) -> (load (element_addr)) deterministic by not using pointer address as a sorting criteria for vardecls.
Instead for vardecls, we use the index of the field in the structdecl itself as
a stable ordering of vardecls.

I validated that the indeterminism was gone by running the failing test 1000
times in a row. Doug and I were hitting the indeterminism with well less than
100 iterations before, so I feel the number of iterations is sufficient.

Swift SVN r13859
2014-02-13 04:57:54 +00:00
Michael Gottesman
3a1d46d145 [sil-code-motion] Refactor out the address projection path computation from findExtractPathBetweenValues to a new function findAddressProjectionPathBetweenValues and wire up the old method to use the results of the refactored method.
This is in preparation for using the refactored functionality in Alias
Analysis's address projection disambiguation code.

Swift SVN r13765
2014-02-11 00:09:15 +00:00
Michael Gottesman
5b3423308d Refactor out the class Projection class into its own header swift/SIL/Projection.h.
This class allows you to deal with tuple and nominal projections in a way that
is agnostic of either of them.

Expect some incoming utilities based off of this for dealing with what I call
'aggregate type trees'.

Swift SVN r13735
2014-02-10 05:07:36 +00:00
Andrew Trick
731000b4cd Added -sil-print-all and -sil-verify-all options.
Swift SVN r13662
2014-02-07 23:07:11 +00:00
Nadav Rotem
27a1a63134 Remove unneeded empty virtual destructors.
Swift SVN r13599
2014-02-06 22:24:33 +00:00
Nadav Rotem
1ef0d157ca PassManager: Inject the function/module into the Transformation.
Now the pass does not need to know about the pass manager. We also don't have
runOnFunction or runOnModule anymore because the trnasformation knows
which module it is processing. The Pass itself knows how to invalidate the
analysis, based on the injected pass manager that is internal to the
transformation.

Now our DCE transformation looks like this:

class DCE : public SILModuleTransform {
  void run() {
    performSILDeadCodeElimination(getModule());
    invalidateAnalysis(SILAnalysis::InvalidationKind::All);
  }
};





Swift SVN r13598
2014-02-06 22:11:21 +00:00
Nadav Rotem
cd7f72f6ca Teach SILCombine not to invalidate all the analysis if no change was made.
Swift SVN r13584
2014-02-06 17:38:00 +00:00
Nadav Rotem
d6802340fe Change the CallGraph Analysis API and add cacheing and invalidation methods.
Swift SVN r13554
2014-02-06 04:24:51 +00:00
Nadav Rotem
99b075c32a Rename SILFunctionTrans -> SILFunctionTransform
Swift SVN r13536
2014-02-06 01:32:10 +00:00
Nadav Rotem
f8c7b54d28 Delete the unused performXXX() functions.
Swift SVN r13531
2014-02-06 00:57:28 +00:00
Michael Gottesman
310fa94887 Fix typo. createDeadFunctionEmim => createDeadFunctionElimination.
Swift SVN r13508
2014-02-05 21:33:22 +00:00
Michael Gottesman
631f9326ab [PM] Change enum => enum class everywhere in the PM code. Additionally fix some typos.
Swift SVN r13507
2014-02-05 21:25:15 +00:00
Nadav Rotem
baa1d1679a Teach some of the passes about the new PM.
Swift SVN r13494
2014-02-05 18:58:23 +00:00
Michael Gottesman
34f264f0e5 [sil-combine] Fix assertion failure in partial apply closure cleanup where we
were attempting to create destroy values for arguments that were not apart of
the partial apply itself in the case where the partial apply had more than 1
argument left uncurried.

Swift SVN r13448
2014-02-04 22:38:37 +00:00
Michael Gottesman
34b64eba9c [sil-combine] Remove old struct_extract/tuple_extract of load canonicalizations since they are inferior to the new load processing version.
Swift SVN r13325
2014-02-03 00:11:16 +00:00
Michael Gottesman
1350988cad [sil-combine] (projection (load)) -> (load (gep)), done right this time.
This patch canonicalizes projections of load to loads of gep so that passes like
the ARC optimizer and the load/store optimization in SILCodeMotion have a
canonical pattern to look for. As an example, often times in the stdlib one
will see something like this:

(retain (struct_extract (load)))

and,

(release (load (struct_element_addr)))

It does not matter which one we pick, just that we pick one.

Swift SVN r13324
2014-02-03 00:11:16 +00:00
Michael Gottesman
9b0e57f8f3 [sil-combine] Small cleanups. NFC.
Swift SVN r13117
2014-01-29 21:11:35 +00:00
Michael Gottesman
945d094631 [sil-combine] Move ref_to_raw_pointer consumption of other pointers to SILCombine from SILInstruction.
I am unhappy about this but otherwise since we are just "consuming" the other
pointers, we do not properly get the other points on the SILCombine worklist
since SimplifyInstruction does not have a manner of communicating that.

I kept around the method stub in SimplifyInstruction.cpp since in the next
commit I am going to put a round trip optimization for ref_to_raw_pointer
there.

Swift SVN r12835
2014-01-23 01:19:33 +00:00
Michael Gottesman
efaf21b8ee [sil-combine] Add in a small peephole to handle a strong_release right before a strong_retain on the same pointer.
The case this is optimization is:

strong_release %0
strong_retain %0

This case occurs due to the strong_release's matching retain being in a
different basic block from the increment/decrement and the same for the
strong_retain.

At some point way in the future, when we get a true global ARC optimizer, this
will no longer be necessary.

But until that point, there is no reason why we can not remove such a pair.

Swift SVN r12655
2014-01-21 20:48:07 +00:00
Nadav Rotem
d472fe0b18 partial_apply does not take ownership of @in arguments,
but it does take ownership of @owned values.



Swift SVN r12651
2014-01-21 19:49:24 +00:00
Michael Gottesman
816c2a1398 [sil-combine] Do not transform (struct_extract (load)) -> (load (struct_element_addr)) when the load has multiple uses.
Do the same for the tuple_extract optimization.

After turning this off I am starting to see a bunch of code like this:

  %69 = load %1#1 : $*Array<T>                    // users: %77, %70                                                                                           
  %70 = struct_extract %69 : $Array<T>, #owner    // user: %73                                                                                                 
  %71 = struct_element_addr %1#1 : $*Array<T>, #owner // user: %72                                                                                             
  %72 = load %71 : $*Builtin.ObjectPointer        // user: %74                                                                                                 
  strong_retain %70 : $Builtin.ObjectPointer      // id: %73                                                                                                   
  strong_release %72 : $Builtin.ObjectPointer     // id: %74 
  dealloc_stack %1#0 : $*@local_storage Array<T>  // id: %75                                                                                                   
  strong_release %2 : $Builtin.ObjectPointer      // id: %76                                                                                                   
  return %69 : $Array<T>                          // id: %77 

Which confuses the ARC optimizer (notice the struct_extract vs
struct_element_addr).

I imagine we will want to canonicalize this case in a different way (maybe an
inverse peephole that would turn in this case the struct_element_addr + load ->
load + struct_extract?).

Swift SVN r12305
2014-01-15 01:00:02 +00:00
Nadav Rotem
100fd9207a Erasing an instruction does not remove it from the worklist.
We crash when we try to debug print the module. 

Swift SVN r12295
2014-01-14 22:07:02 +00:00
Nadav Rotem
f4efc85195 A small cleanup.
Swift SVN r12294
2014-01-14 21:54:33 +00:00
Michael Gottesman
e1773d8a0e [sil-combine] Eliminate (cond_fail 0)
I have seen this a few times in the stdlib in methods like:

_TFCSs21DictionaryBufferOwnercUSs8Hashable___fMGS_Q_Q0__FT15minimumCapacitySi_GS_Q_Q0__

Swift SVN r12273
2014-01-14 03:31:33 +00:00
Nadav Rotem
970c387c34 Refactor devirt related optimizations from sil-combine into a new pass.
The reason is that I would like to add more sophisticated analysis and a
chache, which does not fit into sil-combine very well.



Swift SVN r12221
2014-01-13 07:34:25 +00:00
Nadav Rotem
68da9ff5cd Replace the partial apply of "@in" captured arguments with strong_release.
The partial apply takes ownership of @in arguments so we need to deal with the +1 refcounts coming in.




Swift SVN r12215
2014-01-12 08:24:16 +00:00
Nadav Rotem
313c28f46b Remove unused closures.
Our debugTraps still capture values in a closure even when we comment them out. Adding this pattern
that removes unused partial_apply instructions removes all of these debugTraps.

This accelerates our RC4 benchmark by 4.5X (we are now only 180x the speed of CPP).



Swift SVN r12202
2014-01-11 07:27:44 +00:00
Michael Gottesman
973e6fcdf6 Revert "[sil-combine] Eliminate copy_value, destroy_value that are applied to the same value and are next to each other."
This reverts commit r12074. I am going to do this optimization in the basic ARC
optimizer.

Swift SVN r12114
2014-01-10 04:24:00 +00:00
John McCall
5da6defa1f Clean up the linkage model and the computation of linkage.
In general, this forces SILGen and IRGen code that's grabbing
a declaration to state whether it's doing so to define it.

Change SIL serialization to serialize the linkage of functions
and global variables, which means also serializing declarations.

Change the deserializer to use this stored linkage, even when
only deserializing a declaration, and to call a callback to
inform the client that it has deserialized a new entity.

Take advantage of that callback in the linking pass to alter
the deserialized linkage as appropriate for the fact that we
imported the declaration.  This computation should really take
advantage of the relationship between modules, but currently
it does not.

Swift SVN r12090
2014-01-09 08:58:07 +00:00
Michael Gottesman
6ee06ffc3f Fix typo.
Swift SVN r12078
2014-01-09 00:21:34 +00:00
Michael Gottesman
d9561b2018 [sil-combine] (tuple_extract (load %x) 0) -> (load (tuple_extract_addr %x 0))
We already have this peephole in for struct_extract. The optimization reduces
the size of loads.

Swift SVN r12076
2014-01-09 00:17:27 +00:00
Michael Gottesman
67296288fc [sil-combine] Eliminate copy_value, destroy_value that are applied to the same value and are next to each other.
This occurs frequently in the standard library (especially with enums) and there
is no reason not to eliminate it in SILCombine if we can since we will be
eliminating it earlier (potentially opening up more optimizations).

Swift SVN r12074
2014-01-08 23:46:48 +00:00
Nadav Rotem
c391e8162e Refactor the code that erases sil functions into a new method, eraseFunction, and remember to clean the function table.
Swift SVN r11999
2014-01-07 18:18:10 +00:00
Michael Gottesman
8cf8a216b5 Some code I am working on leaked into the previous commit due to my failure at git shenanigans.
Swift SVN r11915
2014-01-05 07:58:08 +00:00
Michael Gottesman
8f8ed7666b [SIL.rst] Fix mark_uninitialize formatting so that a code block is created.
Swift SVN r11914
2014-01-05 07:55:10 +00:00
Michael Gottesman
57d824b1e3 Fix whitespace.
Swift SVN r11913
2014-01-05 07:55:09 +00:00
Nadav Rotem
18b826e6cf When we devirtualize apply instructions that access protocols we look for the
init_existential instruction. However, in some cases the protocol is initialized
using copy_addr. This patch adds support for analyzing the copy_addr in search
for the init_existential instruction. The same rules must apply: both
instructions must not be captured, etc.

With this change we devirtualize 287 calls in stdlib. We are left with only 26 project_existential instructions in stdlib.
I don't have a testcase outside the stdlib right now.



Swift SVN r11897
2014-01-04 09:36:10 +00:00
Nadav Rotem
f73b4ad625 Devirtual ApplyInst + project_existential.
This optimization devirtualizes a very common pattern:

%0 = alloc ... $aProtocol
%1 = init_existential %0#1 : $*aProtocol, $*Foo  <-- Foo is the static type!
%4 = project_existential %0#1
%5 = protocol_method %0#1 : $*aProtocol, #aProtocol.aMethod!1 :
%8 = apply %5( .. args ... , %4) :

rdar://15466450.



Swift SVN r11893
2014-01-04 07:28:54 +00:00
Nadav Rotem
55948dcac0 Devirtualize even more.
1. When optimizing the class_method in search of a static type we now skip downcasts and upcasts.
2. Metatype are also considered static classes.
3. Search the entire class hierarchy.



Swift SVN r11842
2014-01-03 01:08:20 +00:00
Nadav Rotem
d455565d21 top_level_code is intrinsically alive so don't remove it.
Swift SVN r11741
2013-12-30 08:39:33 +00:00
Nadav Rotem
c15f16ee91 cleanup
Swift SVN r11737
2013-12-30 07:48:43 +00:00
Nadav Rotem
6fabe7e456 Devirtualize very simple class_method and alloc_ref pairs.
Swift SVN r11693
2013-12-28 09:22:16 +00:00
Nadav Rotem
9cd580bf9c We can’t print the debug message before we insert the instruction into the function.
Swift SVN r11692
2013-12-28 09:02:08 +00:00
Nadav Rotem
5c160916d7 Sink another expensive optimization.
Swift SVN r11672
2013-12-27 08:15:46 +00:00
Nadav Rotem
2f1e2a22e3 The call to 'isTrivial' is expensive. Make this optimization last.
Swift SVN r11671
2013-12-27 08:11:47 +00:00
Nadav Rotem
821ef81e12 Remove internal functions that are not called by any functions in the module.
Swift SVN r11669
2013-12-27 07:56:53 +00:00
Michael Gottesman
471c496066 [sil-combine] Teach silcombine to simplify {copy,destroy_value} of an enum with no-payload or a payload of trivial type since such an operation is a no-op.
*NOTE* We also RAUW copy_values appropriately.

rdar://15568314

Swift SVN r11664
2013-12-27 00:39:37 +00:00
Nadav Rotem
1870710d84 a minor cleanup
Swift SVN r11627
2013-12-24 22:24:00 +00:00