Commit Graph

150 Commits

Author SHA1 Message Date
Erik Eckstein
ebbecf5e5a Do not inline "availability.osversion" functions in mid-level inliner.
Because GlobalOpt must see this functions (rdar://problem/20708979)



Swift SVN r27964
2015-04-30 11:07:42 +00:00
Arnold Schwaighofer
3812583031 DominatorBasedJumpThreading: Resurrected
Teach dominator based simplifications to also thread dominated edges.

The code now handles cond_br and switch_enum terminators for both value based
simplifications (where the use is dominated) and jump threading edges (the edge
is dominated).

Update simplify_cfg.sil test cases for split edges.

This also handles the test case from rdar://20390647.

Swift SVN r27843
2015-04-27 23:44:57 +00:00
Erik Eckstein
115090d6f7 Re-apply r27361: A new SIL pass for static analysis of array properties.
...with a fix for the compiler crash in external projects.
rdar://problem/20579035



Swift SVN r27427
2015-04-17 08:18:29 +00:00
Mark Lacey
0b423c1844 Revert "A new SIL pass for static analysis of array properties."
This reverts commit r27361. It may have broken some of the external
projects we test.

Swift SVN r27426
2015-04-17 06:19:59 +00:00
Erik Eckstein
6cfb3716bf A new SIL pass for static analysis of array properties.
The GlobalPropertyOpt pass performs a static analysis over the whole module.
If it can prove that an array property call (_getArrayPropertyIsNativeNoTypeCheck) always yiels true,
then it replaces the call with a literal-true.

The pass runs on the high-level SIL using the array semantics calls.
Currently it only handles the isNativeNoTypeCheck array property, but in future it might handle additinal properties
(therefore I chose this general name for it).

It gives +24% on DeltaBlue.




Swift SVN r27361
2015-04-16 17:28:14 +00:00
Erik Eckstein
03d393ef5c Re-apply r27206: Convert all external function definitions to declarations when compiling with -Onone.
... with disabled test 1_stdlib/Bit.swift for ios.

Most likely the problem of 1_stdlib/Bit.swift (only on armv7) is just uncovered by this change.
Unfortunately I have no possibility to debug the problem on a device. Therefore I filed rdar://problem/20521110




Swift SVN r27274
2015-04-14 07:38:28 +00:00
Greg Parker
a42837bee2 Revert r27206.
This broke test 1_stdlib/Bit.swift on armv7.


Swift SVN r27236
2015-04-11 07:28:41 +00:00
Erik Eckstein
c3b253d305 Convert all external function definitions to declarations when compiling with -Onone.
This avoids that an unoptimized imported function is linked instead the optimized version from the stdlib.
rdar://problem/20485253

It gives considerable performance improvmenets for some benchmarks with -Onone. E.g.
PopFrontUnsafePointer: +281%
ArrayOfPOD: +92%
StrComplexWalk: +91%
ArrayOfGenericPOD: +61%
Several others are within the range of +10% to +30%.

For the implementation I added runSILPassesForOnone() in Passes.cpp.
Here we can add other optimizations for -Onone in the future.



Swift SVN r27206
2015-04-10 09:53:17 +00:00
Mark Lacey
af7a07b0f2 Remove the post-inliner runs of the devirtualization pass.
They have no effect. The pre-inliner run may be enabling some
specialization at this point. If it turns out that is not the case, I'll
remove those runs and delete the pass.

Swift SVN r26792
2015-04-01 02:11:00 +00:00
Erik Eckstein
f520ef894a Add the PassKind as a property in SILTransform.
To set the PassKind automatically, I needed to refactor some code of the pass manager and the pass definitions.
The main changes are:
1) SILPassManager now has an add-function for each pass: PM.add(createP()) -> PM.addP()
2) I removed the ARGS argument in Passes.def, which we didn't use anyway.



Swift SVN r26756
2015-03-31 14:08:19 +00:00
Nadav Rotem
83b194fb08 Remove some of the passes in the optimization pipeline.
I measured zero performance regressions on the test suite. I added an early
CSE pass because of a specific example in one of the tests where the inliner
brought in an integer literal that needed to be CSE-ed before inst-combine
could fold a comparison into a constant, and simplify-cfg get rid of that
constant.

Representing our literal values as instructions (e.g. integer_literal) forces
us to run CSE constantly. We also need to re-run InstCombine very frequently
because InstSimplifier is not allowed to create new instructions!

Swift SVN r26736
2015-03-30 23:04:29 +00:00
Michael Gottesman
99e0b6bb19 [codemotion] Instead of passing in whether we are late or early, create late early entry points.
I need this so I can write some tests for the late code motion pass in sil-opt.
Plus it follows the model in the inliner.

Swift SVN r26671
2015-03-28 02:47:07 +00:00
Michael Gottesman
a07e8c8fd2 Make the late code motion hoist releases.
Swift SVN r26663
2015-03-28 00:47:11 +00:00
Nadav Rotem
1e99e160e8 Remove some of the passes at the late stages of the optimization pipeline.
After many attempts I found that the change in this commit does not regress
the performance of the test suite. The passes that I added in this commit come
to replace the late 'SSAPasses' pipe. I am still not completely sure why there
is such a strong dependency between SimplifyCFG and InstCombine.

Swift SVN r26658
2015-03-28 00:20:38 +00:00
Nadav Rotem
240ff14db1 Split DominanceAnalysis into Dom and PDom using FunctionAnalysisBase.
This commit splits DominanceAnalysis into two analysis (Dom and PDom) that
can be cached and invalidates using the common FunctionAnalysisBase interface
independent of one another.

Swift SVN r26643
2015-03-27 20:54:28 +00:00
Erik Eckstein
9ef85c461b SimplifyCFG: Move optimization from CondFailOpt to SimplifyCFG and remove CondFailOpt pass.
I completely missed that one of the CondFailOpt optimization was already implemented in SimplifyCFG.
I move the other optimization also into SimplifyCFG because both share some code.



Swift SVN r26626
2015-03-27 14:07:14 +00:00
Erik Eckstein
9d8c98551c Add an optimization pass to optimize cond_fail instructions.
Summary: it tries to move cond_fail instruction to predecessor blocks, if benefitial.
For details see the comment in CondFailOpt.cpp.



Swift SVN r26592
2015-03-26 14:40:59 +00:00
Michael Gottesman
4874f0e159 Add options -sil-view-silgen-cfg and -sil-view-guaranteed-cfg.
These options run the SIL CFG printer after silgen and after the
guaranteed optimizations run respectively.

Swift SVN r26350
2015-03-20 07:34:49 +00:00
Nadav Rotem
cc37a28775 The lowering part of the optimization pipeline is non iterative so we can use the non-iterative API.
Swift SVN r26277
2015-03-18 20:49:59 +00:00
Nadav Rotem
bb4bdb5cc2 Reapply 26054. All of the tests pass again after the fix in r26060.
Swift SVN r26063
2015-03-12 20:54:07 +00:00
Nadav Rotem
7b836f9103 Revert 26054 because it broke the build (assertion failure in debug mode)
Swift SVN r26056
2015-03-12 19:59:27 +00:00
Nadav Rotem
773d8a4773 [overflow] Enable the pass the removes overflow checks by default.
We can now remove overflow checks by analyzing control flow. For example:

func foo(x : Int) {
  if x > 2 {
    x - 2 // overflow check removed
  }
}

We also remove overflow checks that are guarded by other (stronger) checks:

func bar(x : Int) {
  x + 1 // removed
  x + 5
  x + 2 // removed
}

With this change we are able to remove dozens of checks from the swift standard
library. However, only the only test in the test suite that becomes faster is
Fibonacci (1.3x).

Swift SVN r26054
2015-03-12 19:00:47 +00:00
Michael Gottesman
494305dcd1 Revert "Remove sil option flags that are no longer needed."
This reverts commit r25828. I forgot that some tests depend on these. Thanks
Andy!

Michael

Swift SVN r25832
2015-03-07 03:10:15 +00:00
Michael Gottesman
e40f01c9ed Remove sil option flags that are no longer needed.
Swift SVN r25828
2015-03-07 02:31:52 +00:00
Arnold Schwaighofer
1f399aa192 MergeCondFail: Combine cond_fail instructions in basic blocks
We can combine cond_fail instructions in basic blocks if there is no side-effect
or read in between them.

rdar://20006530

Swift SVN r25697
2015-03-03 00:45:56 +00:00
Nadav Rotem
663482ea93 Split the debugging feature to set the pass name inside the PassManager resetAndRemoveTransformations into a new function.
Swift SVN r25562
2015-02-26 21:01:46 +00:00
Arnold Schwaighofer
41360b0892 Run LICM in the early loop opt pipeline to expose more opportunities.
Swift SVN r24959
2015-02-04 16:39:13 +00:00
Erik Eckstein
758222e70f Run SilMem2Reg also after the last inliner.
This helps to clean up alloc_stack (+ related) instructions which are not necessary anymore
if a function with address-parameters is inlined.



Swift SVN r24916
2015-02-03 12:23:08 +00:00
Roman Levenstein
5831e7a5cc [sil-dead-function-elimination] Re-factoring of the external function definitions elimination pass.
Rename LateDeadFunctionElimination into ExternalFunctionDefinitionsElimination.
Move ExternalFunctionDefinitionsElimination  out of DeadFunctionElimination and make it a separate pass.
Move a common logic shared by  DeadFunctionElimination and ExternalFunctionDefinitionsElimination into a newly created base class.

Make ExternalFunctionDefinitionsElimination pass eliminate just those external functions which are only reachable via vtables and witness_tables, but leave directly reachable function definitions in place. This gives LLVM more chances to analyze directly reachable functions for side-effects and perform better optimizations based on this. Once we have a proper IPO support for Swift, we can eliminate all external function definitions, including directly reachable ones, as there will be other ways to get information about their side-effects.

Swift SVN r24546
2015-01-20 03:14:45 +00:00
Michael Gottesman
8c5b200239 [inst-count] Move InstCount into frontend_main wrapped in performSILInstCount so that we can gather statistics even if we don't run any SIL optimization passes.
Swift SVN r24490
2015-01-17 02:15:18 +00:00
Arnold Schwaighofer
ce9cb0bfac Add an instance of the RemovePin pass to the SSA pipeline
Swift SVN r24457
2015-01-15 22:44:38 +00:00
Arnold Schwaighofer
1e482be681 Add a pass to remove trivial pin/unpin pairs.
This pass removes pin/unpin pairs that are not interleaved by a may-release of
the pin's operand.

This will be needed when we turn on John's work on safe array accessors.

Swift SVN r24434
2015-01-15 00:48:59 +00:00
Roman Levenstein
9f49a1096a [sil-dead-function-elimination] Add a LateDeadFunctionElimination entry point to remove external definitions.
This pass is an extension of the dead function elimination, which additionally performs removal of external function definitions (i.e. function bodies) for a sake of improving the compile times by reducing the amount of code running through IRGen.  It is safe, because such functions are defined elsewhere and where required only for analysis and optimization purposes.

This pass is supposed to run very late in the pipeline, after any passes that may need to look at the function bodies, i.e. after devirtualization, inlining and all specialization passes.

Swift SVN r24417
2015-01-14 18:57:36 +00:00
Chris Lattner
ed09b7c7f1 reapply r24149, which moves mandatory inlining after DI and inout deshadowing,
fixing <rdar://problem/19268443> DI should reject this call to transparent function

with the other patch to infer @autoclosure arguments as @__noescape automatically in
the stdlib, there is no stdlib patch required at all.  




Swift SVN r24211
2015-01-06 06:29:30 +00:00
Dmitri Hrybenko
074692ad48 Revert "Reapply r23982, which moves mandatory inlining after DI and inout deshadowing."
This reverts commit r24142.

Even though the tests were broken by r24141, now that there are more
commits on top of it, reverting just r24141 does not fix tests.  I'm
reverting r24141, r24142 and r24143.

Swift SVN r24149
2014-12-24 07:23:08 +00:00
Chris Lattner
ce8b218aba Reapply r23982, which moves mandatory inlining after DI and inout deshadowing.
This fixes some serious DI problems where it would be broken with transparent
functions like ++.

Previously, this had to be reverted because we were relying on mandatory inlining
to inline closure-taking stdlib functions (like &&/||) before inout deshadowing
happened.  With mandatory inlining moved after inout deshadowing, we were getting
a lot of inout shadow temporaries around, which notably defeated important COW
optimizations by increasing refcounts in unpredictable ways.  

The new @__noescape attribute handles this for us now, because @__noescape closures
(like the autoclosure arguments to ||/&&) no longer block inout deshadowing.



Swift SVN r24142
2014-12-24 01:42:46 +00:00
Michael Gottesman
8175e8b709 Directly include ErrorOr.h and MemoryBuffer.h to make Passes.cpp resilient against potential forward declarations.
In the swift-602-branch, these are forward declared in one of the
headers included in this file yielded a compilation error. Rather than
just fixing the compilation failure on that branch, this commit makes
the entire file more redundent since who knows in the future these two
types may be forward declared again.

Swift SVN r24066
2014-12-21 23:14:20 +00:00
Michael Gottesman
1ae4002b6f Add the frontend flag '-external-pass-pipeline-filename'
This flag enables one to specify a json file that expresses a specific
pipeline in the following format:

[
  [
    "$PASS_MANAGER_ID",
    "run_n_times"|"run_to_fixed_point",
    $NUM_ITERATIONS,
    "$PASS1", "$PASS2", ...
  ],
  ...
]

This will make it easier to experiment with different pass pipelines by
allowing:

1. Automatic generation of pass pipelines without needing to recompile
   the compiler itself.
2. Simple scripting of pass pipelines via the json meta language.
3. Enabling the easy expression and reproducability of a specific
   pipeline ordering via radar.

In the next commit I will provide a python library for the generation of these
json files with a few types of pipeline generators already created.

Swift SVN r24055
2014-12-20 04:09:47 +00:00
Michael Gottesman
93b92a8f9f Add in Passes.def for metaprogramming with SILPassKinds.
This simplifies some code in SILOpt and SILPasses. The real reason to do it is
to use it to procedurally generate random pipelines.

Swift SVN r23996
2014-12-17 23:56:26 +00:00
Chris Lattner
4b957378e7 I'm seeing some test failures on stdlib test. Revert r23982 in case it is implicated.
Swift SVN r23986
2014-12-17 19:50:45 +00:00
Chris Lattner
244eda4cb6 fix <rdar://problem/19268443> DI should reject this call to transparent function
by moving Mandatory Inlining after DI.  Thanks to Mark for unblocking this!



Swift SVN r23982
2014-12-17 19:04:19 +00:00
Andrew Trick
6cc72ee21b Print SIL optimization stages. SIL debugging.
Swift SVN r23902
2014-12-12 23:57:03 +00:00
Andrew Trick
d435a43ee4 comment: EnableFuncSigOpts is now true.
Swift SVN r23900
2014-12-12 23:57:02 +00:00
Arnold Schwaighofer
83cf4f3405 Add a pass to specialize array code based on array semantic array.props calls
We know that a native swift array that does not need an element type check is
not going to change to an nsarray, or to an array that needs an element type
check. This allows us to specialize array code.

The array semantic calls 'array.props.isCocoa/needsElementTypeCheck' returns
said array properties for a read.

  func f(a : A[AClass]) {
     for i in 0..a.count {
       let b = a.props.isCocoa()
        .. += _getElement(a, i, b)
     }
  }

   ==>

  func f(a : A[AClass]) {
    let b2 = a.props.isCocoa()
    if (!b2) {
      for i in 0..a.count {
         .. += _getElement(a, i, false)
      }
    } else {
      for i in 0..a.count {
        let b = a.props.isCocoa
        .. += _getElement(a, i, b)
      }
    }
  }

The stdlib will be changed to use array.props calls in a future commit.

rdar://17955309

Swift SVN r23689
2014-12-04 19:24:40 +00:00
Michael Gottesman
123b8e6f61 Access SILOptions in SILPassManager via the SILModule now that we store the SILOptions in the SILPassManager.
Swift SVN r23651
2014-12-03 20:39:05 +00:00
Arnold Schwaighofer
06a0a23562 Add a destructor memory effect analysis
This adds an analysis to the compiler that identifies types that are may store
to memory on destruction.

It adds a compiler known protocol _DestructorSafeContainer that allows the
standard library to identify containers whose destructor's memory effects
depends strictly on the type parameters of the container.

Array<T> : _DestructorSafeContainer {} may not store to memory during
destruction if the bound T is a type that does not store to memory on
destruction.

This is needed to deduce that for example Array<Array<Int>> is does not store to
memory on destruction (e.g during a call to release).

rdar://18940376

Swift SVN r23242
2014-11-11 19:27:41 +00:00
Erik Eckstein
6b6581aa25 Invalidate the deserializer caches after each SIL linking pass.
This avoids that the deserializer(s) keep references to deserialized functions during the whole optimization passes
(especially dead function elimination).

I have seen no negative effect on compiletime. It seems to be a seldom event that a function is
deserialized twice because of not keeping the cache alive between linking passes.

I also simplified the final dead function elimination by just using the regular dead function elimination pass.




Swift SVN r22837
2014-10-20 11:57:27 +00:00
Arnold Schwaighofer
329fa51d3f Reapply "Verifier: Cannonical SIL should have split critical edges for non cond_br
terminators"

This is an assumption that the SSAUpdater makes. Verify that we preserve this
property.

With changes to the test cases, SIL documentation and add a critical edge (non
cond_br only) splitting pass to the mandatory pipeline.

This reapplies commit 22775.

Swift SVN r22803
2014-10-16 21:16:24 +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
Erik Eckstein
9a6699ac43 Enable inlining of functions with the global_init attribute.
Inlining of such functions should only be done after GlobalOpt otherwise
GlobalOpt will not hoist them out of loops.



Swift SVN r22283
2014-09-25 14:30:38 +00:00