Commit Graph

69 Commits

Author SHA1 Message Date
Nadav Rotem
d78b376d07 [passes] Replace the old invalidation lattice with a new invalidation scheme.
The old invalidation lattice was incorrect because changes to control flow could cause changes to the
call graph, so we've decided to change the way passes invalidate analysis.  In the new scheme, the lattice
is replaced with a list of traits that passes preserve or invalidate. The current traits are Calls and Branches.
Now, passes report which traits they preserve, which is the opposite of the previous implementation where
passes needed to report what they invalidate.

Node: I tried to limit the changes in this commit to mechanical changes to ease the review. I will cleanup some
of the code in a following commit.

Swift SVN r26449
2015-03-23 21:18:58 +00:00
Joe Groff
7f886c924b SIL: Make 'isReferenceCounted' a bit on TypeLowering.
This allows types to be lowered as scalar reference-counted types without requiring them to have AST-level reference semantics. For now, put in a staging assertion to ensure isReferenceCounted == hasReferenceSemantics to make sure we set the bit properly everywhere.

Swift SVN r26238
2015-03-17 21:51:06 +00:00
Chris Lattner
4f708c049b fix const correctness and standardize on names for the successor list of
TerminatorInsts.  Now you can walk over the successor list of a terminator
and actually modify the SILSuccessor directly, allowing better CFG
transformations.  NFC.




Swift SVN r26140
2015-03-14 17:52:27 +00:00
Arnold Schwaighofer
951dc2875a Nuke isSideEffectFree
We can now compute the same result with Inst.mayHaveSideEffects(). NFC.

Swift SVN r25742
2015-03-04 05:03:44 +00:00
Michael Gottesman
6f8b468cb6 Change switches and selects to use NullablePtr<EnumElementDecl> instead of EnumElementDecl * when their API explicitly requires the user to check for nullptr. NFC.
This is just good to do and hopefully will help prevent people from forgetting
to check in the future by annotating the API explicitly as returning a
potentially nullptr.

Swift SVN r25364
2015-02-18 02:11:57 +00:00
Dmitri Hrybenko
61286f0260 Fix warnings produced by a newer version of Clang
Swift SVN r25257
2015-02-12 23:50:47 +00:00
Michael Gottesman
39817d5fd8 Remove arc namespace.
Swift SVN r24500
2015-01-19 00:10:48 +00:00
Adrian Prantl
c41b30299f Audit all SILPasses to ensure that new instructions are never created
without a valid SILDebugScope. An assertion in IRGenSIL prevents future
optimizations from regressing in this regard.
Introducing SILBuilderWithScope and SILBuilderwithPostprocess to ease the
transition.

This patch is large, but mostly mechanical.
<rdar://problem/18494573> Swift: Debugger is not stopping at the set breakpoint

Swift SVN r22978
2014-10-28 01:49:11 +00:00
Joe Groff
e3f9a2035c SIL: Move SILGen and passes over to use "builtin" instead of "apply (builtin_function_ref)".
Swift SVN r22785
2014-10-15 23:37:22 +00:00
Arnold Schwaighofer
e5084ae319 CodeMotion: Make release sinking more aggressive by looking through casts
Also, only hoist releases into switch regions late in the pipeline.

I made retain sinking more aggressive so that we can move more retains into (and
then hopefully out of) switch regions.

Hoisting releases up into switch regions blocks moving the retains out of the
switch region. To remove retain/releases we would have to iterate between
codemotion and global-arc-opts. Instead just don't move releases into switch
regions until late in the pipeline (the late iteration of the SSAPasses).

This fixes the remaining regressions from the array changes in RC4. And gives
some nice further gains.

-O results speedup(SU) = minbefore/minafter:

TEST``````````SMPL`MIN``MAX```MEAN``SD```MEDIAN`MIN``MAX``MEAN`SD```MEDIAN``SU
Forest````````10```4985`5456``5319``156``5376```4423`4914`4700`169``4789````1.12
ImageProc`````10```7852`7873``7858``6````7857```8260`8272`8264`3````8263````0.95
InsertionSort`10```6098`6109``6104``3````6104```6720`6736`6726`4````6727````0.90
PrimeNum``````10```9202`18296`12514`2690`12368``4098`7552`5953`1164`6319````2.24
Prims`````````10```2058`3486``2787``513``3025```1877`2429`2049`196``2007````1.09
QuickSort`````10```6101`6116``6107``5````6107```6380`6415`6396`11```6398````0.95
RC4```````````10```8639`8684``8655``14```8653```7821`7926`7876`32```7880````1.10
Richards``````10```2243`2254``2249``3````2250```1729`1740`1736`3````1738````1.29
StrToInt``````10```4298`4317``4309``6````4310```4090`4107`4097`6````4098````1.05
StringWalk````10```6478`6511``6486``10```6482```5784`5797`5790`4````5790````1.11
Walsh`````````10```5971`7374``6831``515``7103```4780`4803`4789`7````4788````1.24

InsertionSort: Looking at the profile of insertion sort the regression is not
due to increased retain/release traffic. In fact, it is hard to tell where
those 10% come from.

Quicksort: The quicksort function is identical and takes 95% of the time. Not
clear where the 5% are coming from. It is not extra retain/release traffic
AFAICT.

ImageProc: Same story as InsertionSort.

rdar://17653593

Swift SVN r22694
2014-10-12 22:57:20 +00:00
Joe Groff
9205bf64cf SIL: Remove enum_is_tag.
Swift SVN r22616
2014-10-09 05:03:43 +00:00
Joe Groff
c2fc9f58b8 SIL passes: Work with select_enum instead of enum_is_tag.
Simplify binary switches to select_enum instead of enum_is_tag, and make a first attempt at changing passes over to recognize limited forms of select_enum instead of enum_is_tag. There is one case in test/SILPasses/simplify_cfg.sil I wasn't able to figure out, and there are a lot more general passes we could define in terms of select_enum.

Swift SVN r22615
2014-10-09 03:49:31 +00:00
Michael Gottesman
f541019660 [codemotion] Extract out isARCInertTrapBB into ARCAnalysis from GARCOpts and teach SILCodeMotion to use it to not move retains into trap bbs.
This reduces the number of retains, releases in the stdlib by another 5% to
15167.

rdar://18328074

Swift SVN r21936
2014-09-13 03:15:29 +00:00
Michael Gottesman
4609513593 Remove SILValue::stripRCIdentityPreservingArgs and teach all uses of that method to use the new RCIdentityAnalysis.
Currently, the pass just calls a local version of that function. After OzU, I
will enable the full pass (which is currently disabled behind a flag).

Swift SVN r21894
2014-09-11 22:29:31 +00:00
Michael Gottesman
82ce64beac [code-motion] When merging states, blot values from EnumToEnumBBCaseListMap after we merge instead of clearing in the middle.
This ensures that if we fail to merge the state of one value, we do not
invalidate the enum to enum bb case list map for other values preventing us from
sinking retains out of switch regions.

rdar://18297445

Swift SVN r21860
2014-09-11 00:29:59 +00:00
Michael Gottesman
a539168ef7 Remove extraneous namespace specification. NFC.
Swift SVN r21859
2014-09-11 00:29:58 +00:00
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