Commit Graph

53 Commits

Author SHA1 Message Date
Michael Gottesman
75cebe5b85 [sil-code-motion] Teach SILCodeMotion how to sink retains out of switch regions.
I also added the enum simplification tests to sil code motion since this change
to sil code motion causes the output from the two passes to diverge on that test
.sil file.

rdar://18027730

Swift SVN r21558
2014-08-29 01:13:26 +00:00
Michael Gottesman
f629a7ffe4 [sil-code-motion] Now that valueHas*InInstructionRange returns the barrier instruction, merge tryToMoveRefCountInstDownInBB into tryToSinkRefCountInst.
Swift SVN r21524
2014-08-28 10:17:14 +00:00
Michael Gottesman
5285b9f811 [codemotion] Refactor loop into std::none_of.
Swift SVN r21521
2014-08-28 08:00:44 +00:00
Michael Gottesman
9b68a2e205 [sil-code-motion] Combine together SILCodeMotion and Enum Simplification.
The reason why this is being done is that this eliminates phase ordering issues
between these two sinking passes. Specifically, a retain should be able to move
through multiple iterated switch regions if there are no intervening
instructions that may decrement its ref count. With the passes separate, sil
code motion would move the retain into the switch region until the end of the
switch region. Then it could not move it out of the switch region. Then enum
simplification would move it out of the switch region but would move it no
further. Thus the retain would need to wait for the ARC Optimizer or
SILCodeMotion to move the retain to the next switch. Then enum simplification
could process it again. Thus given the number of times that we iterate, given
enough switches the optimizer would be unable to push the retains.

Now that this has been done, after we move the retain out of the switch region,
we can keep sinking it to the next switch region, move the retain into there,
etc. That work will be done in a later radar.

Given where we are in the schedule I am not going to remove the old enum
simplification pass or combine together the two passes more than crudely so that
(hopefully) cherry-picking will be easier if necessary. I will perform more
indepth combination later.

<rdar://problem/18033238>

Swift SVN r21502
2014-08-28 00:51:51 +00:00
Andrew Trick
292d9b3bb2 Fix SILCodeMotion: do not move retains across isUniquelyReferenced.
Sinking retains will simply make the unique check useless and eliminate
Array copies even when we need them.

Fix for:
<rdar://problem/18109082> ARC: make _isUniquelyReferenced a barrier to avoid lost copies

Swift SVN r21485
2014-08-27 18:28:36 +00:00
Pete Cooper
8322876162 Sink retains down in the current BB if they cannot be sunk to a successor.
We currently only sink retains to successor BBs.

However, if a retain can't be moved to a successor, we may still want to move it as late in the current BB as
possible.  For example, we want retains after called to _swift_isUniquelyReferenced and not before it.

Here are performance numbers for -O.  Note that i'm about to commit improvements to enum_is_tag which fixes the
regressions here.

Ackermann``````,``````````1413.00```,`````````````````1566.00```,``````````153.00``,`````````````````-9.8%
ArrayLiteral```,``````````834.00````,`````````````````859.00````,``````````25.00```,`````````````````-2.9%
Ary````````````,``````````1110.00```,`````````````````1121.00```,``````````11.00```,`````````````````-1.0%
Ary2```````````,``````````1092.00```,`````````````````1105.00```,``````````13.00```,`````````````````-1.2%
Ary3```````````,``````````1164.00```,`````````````````1193.00```,``````````29.00```,`````````````````-2.4%
DeltaBlue``````,``````````2195.00```,`````````````````2204.00```,``````````9.00````,`````````````````-0.4%
Dictionary`````,``````````502.00````,`````````````````512.00````,``````````10.00```,`````````````````-2.0%
Dictionary2````,``````````884.00````,`````````````````895.00````,``````````11.00```,`````````````````-1.2%
Dictionary3````,``````````859.00````,`````````````````870.00````,``````````11.00```,`````````````````-1.3%
EditDistance```,``````````1344.00```,`````````````````1344.00```,``````````0.00````,`````````````````0.0%
Fibonacci``````,``````````1382.00```,`````````````````1309.00```,``````````73.00```,`````````````````5.6%
ForLoops```````,``````````1318.00```,`````````````````1324.00```,``````````6.00````,`````````````````-0.5%
Forest`````````,``````````757.00````,`````````````````775.00````,``````````18.00```,`````````````````-2.3%
GlobalClass````,``````````1617.00```,`````````````````1620.00```,``````````3.00````,`````````````````-0.2%
Hash```````````,``````````660.00````,`````````````````718.00````,``````````58.00```,`````````````````-8.1%
HeapSort```````,``````````1256.00```,`````````````````1292.00```,``````````36.00```,`````````````````-2.8%
Histogram``````,``````````313.00````,`````````````````296.00````,``````````17.00```,`````````````````5.7%
InsertionSort``,``````````1223.00```,`````````````````1351.00```,``````````128.00``,`````````````````-9.5%
Life```````````,``````````69.00`````,`````````````````70.00`````,``````````1.00````,`````````````````-1.4%
LinkedList`````,``````````1516.00```,`````````````````1529.00```,``````````13.00```,`````````````````-0.9%
MatMul`````````,``````````224.00````,`````````````````239.00````,``````````15.00```,`````````````````-6.3%
Memset`````````,``````````43.00`````,`````````````````43.00`````,``````````0.00````,`````````````````0.0%
MonteCarloE````,``````````905.00````,`````````````````900.00````,``````````5.00````,`````````````````0.6%
MonteCarloPi```,``````````643.00````,`````````````````654.00````,``````````11.00```,`````````````````-1.7%
NBody``````````,``````````42.00`````,`````````````````41.00`````,``````````1.00````,`````````````````2.4%
NestedLoop`````,``````````931.00````,`````````````````876.00````,``````````55.00```,`````````````````6.3%
NopDeinit``````,``````````1119.00```,`````````````````1117.00```,``````````2.00````,`````````````````0.2%
Phonebook``````,``````````1424.00```,`````````````````1395.00```,``````````29.00```,`````````````````2.1%
PrimeNum```````,``````````214.00````,`````````````````219.00````,``````````5.00````,`````````````````-2.3%
Prims``````````,``````````1182.00```,`````````````````1198.00```,``````````16.00```,`````````````````-1.3%
QuickSort``````,``````````1196.00```,`````````````````1166.00```,``````````30.00```,`````````````````2.6%
R17315246``````,``````````798.00````,`````````````````798.00````,``````````0.00````,`````````````````0.0%
RC4````````````,``````````25.00`````,`````````````````25.00`````,``````````0.00````,`````````````````0.0%
RIPEMD`````````,``````````724.00````,`````````````````746.00````,``````````22.00```,`````````````````-2.9%
Random`````````,``````````960.00````,`````````````````963.00````,``````````3.00````,`````````````````-0.3%
Rectangles`````,``````````836.00````,`````````````````849.00````,``````````13.00```,`````````````````-1.5%
Richards```````,``````````220.00````,`````````````````225.00````,``````````5.00````,`````````````````-2.2%
SelectionSort``,``````````931.00````,`````````````````932.00````,``````````1.00````,`````````````````-0.1%
SmallPT````````,``````````1014.00```,`````````````````1039.00```,``````````25.00```,`````````````````-2.4%
StdlibSort`````,``````````1617.00```,`````````````````1602.00```,``````````15.00```,`````````````````0.9%
StrCat`````````,``````````1061.00```,`````````````````1121.00```,``````````60.00```,`````````````````-5.4%
StrSplitter````,``````````1607.00```,`````````````````1533.00```,``````````74.00```,`````````````````4.8%
StrToInt```````,``````````616.00````,`````````````````612.00````,``````````4.00````,`````````````````0.7%
StringBuilder``,``````````701.00````,`````````````````682.00````,``````````19.00```,`````````````````2.8%
StringWalk`````,``````````1165.00```,`````````````````1182.00```,``````````17.00```,`````````````````-1.4%
Totals`````````,``````````42392.00``,`````````````````42778.00``,``````````386.00``,`````````````````-0.9%
TwoSum`````````,``````````581.00````,`````````````````564.00````,``````````17.00```,`````````````````3.0%
Walsh``````````,``````````105.00````,`````````````````104.00````,``````````1.00````,`````````````````1.0%

Swift SVN r21133
2014-08-11 17:48:37 +00:00
Michael Gottesman
a992d9b74e [codemotion] Check for decrements between retain,cond_br not retain,enum_is_tag
<rdar://problem/17912494>

Swift SVN r21131
2014-08-11 07:54:01 +00:00
Pete Cooper
509dfb6247 valueHasARCDecrementsInInstructionRange needs iterators to be in the same BB
Swift SVN r20938
2014-08-02 01:17:50 +00:00
Pete Cooper
c5fe89ddc8 Teach codemotion about enum_is_tag so that it can move retains. This is exactly the same logic switch_enum currently has
Swift SVN r20881
2014-08-01 03:37:47 +00:00
Michael Gottesman
f650c85af2 [codemotion] Do not move retains over switch_enum if the switch_enum has a default case.
<rdar://problem/17823618>

Swift SVN r20608
2014-07-27 19:38:47 +00:00
Pete Cooper
99d8ce9240 Sink struct instructions when all predecessors differ by only a single operand
Swift SVN r20360
2014-07-23 02:53:41 +00:00
Michael Gottesman
9b4ee301fd [sil-code-motion] Use valueHasARCDecrementsInInstructionRange.
Swift SVN r19894
2014-07-13 06:32:45 +00:00
Manman Ren
16aa8a0a05 [CodeMotion] handle retain_value as well.
Follow up to r19283.


Swift SVN r19298
2014-06-27 17:54:35 +00:00
Manman Ren
c749d8e4a0 [CodeMotion] sink retains down so we can pair up retains with releases.
This enables us to pair up retains with releases on the fast path with inline
cache. The run time of rdar://17327077 is down to 0.07s from 0.7s.

We should be able to simplify the code for sinking retains down switch_enum,
now we have the enum simplification.

Thanks Michael for the review.


Swift SVN r19283
2014-06-27 00:53:37 +00:00
Michael Gottesman
b127cf5c4c [codemotion] Teach SILCodeMotion how to use the ARC infrastructure to be more aggressive in sinking retain insts over switch_enums.
This commit reuses utility methods from the ARC optimizer to know if an
instruction can decrement the ref count of a retain_value's operand. If
we can conservatively ascertain that it can not, we can ignore the
instruction for the purposes of determining if we can move the
retain_value into the switch region.

<rdar://problem/17225910>

Swift SVN r18894
2014-06-14 05:42:33 +00:00
Michael Gottesman
72ea293ed8 [sil-code-motion] When sinking retain_value, release_value over switch_enum, allow for there to be a dealloc_stack intervening.
This is safe to do since the switch_enum can not be on the dealloc_stack.

Swift SVN r18709
2014-06-05 05:55:46 +00:00
Michael Gottesman
ba182e6679 [sil-code-motion] Teach SILCodeMotion how to push retain_value, release_value on enums over switch_enums onto the enum payloads.
rdar://17107213

Swift SVN r18696
2014-06-03 09:38:10 +00:00
Nadav Rotem
b62e2e2288 Sink identical block arguments from predecessors into the destination block.
Swift SVN r18684
2014-05-31 00:25:10 +00:00
Mark Lacey
cb9e8e88cf Remove include of unused header.
Swift SVN r16506
2014-04-18 07:19:29 +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
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
Michael Gottesman
8cff098f1e Split SILCodeMotion into two passes, LoadStoreOpts and SILCodeMotion.
LoadStoreOpts removes duplicate loads, forwards stores to loads, and eliminates
dead stores.

Swift SVN r13789
2014-02-11 23:36:51 +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
Michael Gottesman
655f0be796 [sil-code-motion] Change debug assert into a proper assert.
Swift SVN r13690
2014-02-09 01:41:41 +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
Michael Gottesman
c9f7bba46d [sil-code-motion] Refactor out load invalidation into its own method so that we can use it both for stores and generic instructions that write to memory.
Swift SVN r13652
2014-02-07 21:38:43 +00:00
Michael Gottesman
1905d85aab [sil-code-motion] Teach SIL code motion how to forward a load of an aggregate type + struct_extracts for a load of a gep + load of field of aggregate type.
Swift SVN r13651
2014-02-07 21:38:43 +00:00
Michael Gottesman
fb512b48f4 [sil-code-motion] Teach SIL Code Motion that dealloc_stack does not disrupt reads/writes.
Swift SVN r13650
2014-02-07 21:38:41 +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
fda4a88be5 Teach the codemotion pass not to invalidate the analysis if no change was made.
Swift SVN r13590
2014-02-06 18:06:57 +00:00
Michael Gottesman
3b43e09bae Change getAnalysis<T> to be asserting and provide a new entry point getAnalysisOrNull<T>. Remove all of the unneeded asserts in the various passes.
Swift SVN r13576
2014-02-06 10:06:18 +00:00
Michael Gottesman
80f1451534 [sil-code-motion] Put in assert to make sure we always get a non-null alias analysis. The only way this can happen is if someone is careless and does not add the alias analysis to the pass manager.
Swift SVN r13551
2014-02-06 02:31:43 +00:00
Michael Gottesman
098fda670f [sil-aa] Change SIL AliasAnalysis into an Analysis.
Swift SVN r13550
2014-02-06 02:29:41 +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
7461dbd70a Now that we have a PM, separate passes from analyses by creating a separate library swiftSILAnalysis and a separate folder/etc.
Swift SVN r13511
2014-02-05 22:17:50 +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
473927a1ed [sil-codemotion] Added debug statements to promoteMemoryOperationsInBlock().
Swift SVN r13460
2014-02-05 00:30:35 +00:00
Michael Gottesman
e066574abe [sil-codemotion] After seeing a store only invalidate loads that we can not prove it does not write to.
Swift SVN r13458
2014-02-05 00:27:00 +00:00
Michael Gottesman
f1e247e399 [sil-aa] Convert AliasAnalysis::alias(SILInstruction *, SILValue) -> AliasAnalysis::getMemoryBehavior(SILInstruction *, SILValue).
AliasAnalysis::getMemoryBehavior() returns a SILInstruction::MemoryBehavior
object that specifies the memory behavior of the SILInstruction with respect to
the SILValue. This name fits better the intention behind the aforementioned
poorly named alias instruction.

This is analogous to memdep in LLVM, except using the enum values from
SILInstruction::MemoryBehavior since we already have them.

Currently it always returns the most conservative answer, MayHaveSideEffects for
everything.

The patch also updates SILCodeMotion in light of these changes.

Swift SVN r13457
2014-02-05 00:26:59 +00:00
Michael Gottesman
1d1de86f37 [sil-code-motion] If we find an Inst that can not be proven to not alias a load, only invalidate that load instead of all of the loads.
Swift SVN r13382
2014-02-03 23:05:03 +00:00
Michael Gottesman
8789bd3b51 Small cleanup. NFC.
Swift SVN r13329
2014-02-03 02:34:01 +00:00
Michael Gottesman
bbdfb8bcad [sil-code-motion] Teach SILCodeMotion how to use the AliasAnalysis infrastructure.
Swift SVN r13328
2014-02-03 02:34:00 +00:00
Michael Gottesman
33a8cc36a2 [codemotion] CondFail does not cause us to read/write memory in a manner that we care about.
Swift SVN r13323
2014-02-03 00:11:14 +00:00
Michael Gottesman
ebf12a9b9c Recommit r13291 with proper tests, etc.
Swift SVN r13304
2014-02-01 21:00:07 +00:00
Michael Gottesman
934e0756db Revert "[sil-code-motion] Read none builtins can not cause reads or writes. Don't let them disrupt load/store forwarding."
This reverts commit r13291. Had a thinko here.

Swift SVN r13303
2014-02-01 19:20:41 +00:00
Michael Gottesman
3fa7c641b1 [sil-code-motion] Read none builtins can not cause reads or writes. Don't let them disrupt load/store forwarding.
Swift SVN r13291
2014-02-01 05:51:19 +00:00