Commit Graph

77 Commits

Author SHA1 Message Date
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
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
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
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
John McCall
94514d7a22 Fix an annoying spate of build warnings about variadic macro
application.

Swift SVN r24046
2014-12-19 23:57:08 +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
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
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
664d718ac1 SimplifyCFG: Add a pass to split all critical edges
Swift SVN r22758
2014-10-15 17:07:03 +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
Andrew Trick
15f100f9f6 New SIL-Opt pass: CopyForwarding (disabled, NFC).
This should hugely improve performance in generic code. However, it
exposes a downstream issue with phi node generation.

e.g.
PHI node has multiple entries for the same basic block with different incoming values!
  %497 = phi i64 [ %177, %570 ], [ 0, %570 ], [ %494, %492 ], [ %493, %492 ]
label %492
  %494 = phi i64 [ %177, %547 ], [ %402, %491 ]
  %493 = phi i64 [ %558, %547 ], [ %489, %491 ]

Swift SVN r21965
2014-09-16 01:56:42 +00:00
Andrew Trick
da5a4411bf Rename ArrayOpts to COWArrayOpts.
It looks like we'll have a separate pass for different types of array
opts. There isn't much overlap between COW and ABC opts.

Swift SVN r21258
2014-08-18 18:44:01 +00:00
Andrew Trick
4ffa05c418 Add the CapturePropagation pass to specialize closures on constant arguments.
Fixes
<rdar://problem/16755460> Specialize functions that are partially applied to constant values

This seems to have little effect on our current benchmark suite except
for the one I wrote specifically for this optimization. We get 4x
speedup on calling reduce to sum a range.

Swift SVN r21248
2014-08-16 01:12:27 +00:00
Manman Ren
1f54d024a9 [Closure Specializer] check in a pass to specialize closure.
If we have function A calls function B with a closure C
func A {
  B(...) {
    // closure C
  }
}
and the inliner decides to not inline B into A, it may be beneficial to generate
a specialized version of B to have
func A {
  B_spec_with_C(..., arguments_to_closure_C)
}
 
SILCombine will optimize apply of partial_apply that are both in B_spec_with_C.
Then inliner can inline the closure to B_spec_with_C.

For profitability, we check the relative size of the callee B and the closure C.
We also check hotness of the callsite to B in A and callsites to the closure
inside B. For now, if closure is called inside a loop, we think it is
profitable.

I will add this to the pass manager in a follow-up patch.
rdar://16569736


Swift SVN r21216
2014-08-14 19:45:11 +00:00
Michael Gottesman
ec533fafa7 [load-store-opts] Enable global load store opts.
rdar://17680758



Swift SVN r20349
2014-07-22 23:43:44 +00:00
Arnold Schwaighofer
f6b0682988 Array bounds check optimization pass
Implements redundant bounds check elimination for basic blocks and along the
dominator tree of loops.

No induction variable based hoisting yet.

O3:
NBody          ,  473.00     ,  122.00    ,  294.2%
QuickSort      ,  477.00     ,  310.00    ,  53.9%
RC4            ,  1022.00    ,  736.00    ,  38.6%
Walsh          ,  1781.00    ,  1142.00   ,  55.5%

No effect on Ofast.

Disabled for now.

Swift SVN r20199
2014-07-19 01:18:50 +00:00
Andrew Trick
250bb973bb Add an array optimization pass that hoists make_mutable calls.
This gives us a 10x speedup on -Ofast memset, which was the original
goal. We're now within 2x of C, but the C code produces movdqu instead
of movups for twice the throughput:
<rdar://problem/17722727> Memset at -Ofast is 2x slower than C

-O3 results:
| benchmark     | baserun0 |  optrun0 |   delta | speedup |
| Memset        | 39885.00 | 33978.00 | 5907.00 |   17.4% |
| NBody         |   459.00 |   440.00 |   19.00 |    4.3% |
| QuickSort     |   456.00 |   439.00 |   17.00 |    3.9% |
| StringWalk    |   625.00 |   647.00 |   22.00 |   -3.4% |
| SmallPT       |   557.00 |   575.00 |   18.00 |   -3.1% |
| Phonebook     |  1804.00 |  1862.00 |   58.00 |   -3.1% |

Memset, NBody, and Quicksort are the ones we expected to improve.

We don't get much gain on O3 because retains/release and bounds checks
are still there.
<rdar://problem/17719220> QuickSort -O3 has retains/releases in the inner loop.

Given the Ofast results, I think the small degradations at O3 are noise.

-Ofast results:
| benchmark     | baserun0 |  optrun0 |   delta | speedup |
| Memset        |  5453.00 |   452.00 | 5001.00 | 1106.4% |
| NBody         |   772.00 |   437.00 |  335.00 |   76.7% |
| Walsh         |  1530.00 |  1096.00 |  434.00 |   39.6% |
| QuickSort     |   682.00 |   524.00 |  158.00 |   30.2% |
| Phonebook     |  1453.00 |  1561.00 |  108.00 |   -6.9% |
| Hash          |   993.00 |   958.00 |   35.00 |    3.7% |
| StringWalk    |   458.00 |   446.00 |   12.00 |    2.7% |
| StringBuilder |  1603.00 |  1568.00 |   35.00 |    2.2% |

Swift SVN r20145
2014-07-18 06:52:17 +00:00
Michael Gottesman
e5d7111db8 [load-store-opts] Change load store opts single BB pass to be a simple forward dataflow with an intersection merge operation.
This is not run by default unless one passes in the flag -Xllvm -enable-global-load-store-opts.

Also in order to make sure in the face of multi-bbs dead store elimination is
still correct, we use the post order dominator tree to determine if the dead
store is post dominated by the store that is causing it to be dead.

With this pass enabled, we see a 3.5% decrease in overall time in the precommit
bench and the following tests increase in speed by > 5%:

2Sum:          8.9%
Rectangles:    7.35%
Ackermann:     6.43%
StringBuilder: 6.16%
EditDistance:  5.71%
StringWalk:    5.58%

That means that 30% of our benchmarks increased in speed by > 5%. Many of the
other benchmarks increased in speed significantly but not as drmatically.

The only benchmark that regressed is SmallPt which I am looking into.

rdar://17680758

Swift SVN r20009
2014-07-16 06:01:37 +00:00
Mark Lacey
021983017a Add a SIL SCC visitor and an induction variable analysis.
The induction variable analysis derives from the SCC visitor CRTP-style
and uses it to drive analysis to find the IVs of a function.

The current definition of induction variable is very weak, but enough to
use for very basic bounds-check elimination.

This is not quite ready for real use. There is an assert that I've
commented out that is firing but should not be, and that will require
some more investigation.

Swift SVN r19845
2014-07-11 02:48:03 +00:00
Arnold Schwaighofer
51eb9269ab Add a SIL LICM pass
The main purpose of this pass is to hoist invariant loads out of loops. This
will enable llvm to vectorize loops with array accesses in Ofast once we hoist
the makeUnique functions.

Disabled for now.

rdar://17142604

Swift SVN r19713
2014-07-08 23:51:48 +00:00
Arnold Schwaighofer
5ad13207e5 Add a loop rotation pass
This is to support loop invariant code motion and bound check
hoisting.

Disabled for now.

Swift SVN r19635
2014-07-07 21:05:23 +00:00
Nadav Rotem
d2019d3e66 Add a an option to the inliner to ignore functions that are marked with the @semantics attribute so that we can perform high-level optimizations on them.
Swift SVN r19441
2014-07-01 23:45:26 +00:00
Michael Gottesman
90f578f047 Add a CFG Printer pass. This should make it easier to visualize SIL Code.
Swift SVN r19156
2014-06-25 10:14:29 +00:00
Nadav Rotem
50b2d0e73d Rename early binding -> inline caches.
Swift SVN r19063
2014-06-21 05:06:37 +00:00
Michael Gottesman
b3d7d3e60e [function-signature-opts] Commit initial function sig optimization pass that eliminates dead arguments.
The way this pass works is very similar to generic specialization except
that it turns the old function into a thunk that calls the newly created
function that has had the dead arguments removed.

This ensures that any place in the code where we were unable to see that
the old function was being called still works and also enables us to
cut down on code size increase due to code duplication since the
marshalling code for the thunk should be very small.

This is just the first part of a larger body of work that optimizes
function signatures. The plan is to include transforming loadable
pointer args to pass by value and to convert @owned arguments to
@gauranteed arguments.

<rdar://problem/17319928>

Swift SVN r18970
2014-06-18 02:36:05 +00:00
Nadav Rotem
5d063f0061 Add an early binding pass for accelerating virtual method dispatch.
Dynamic languages are able to implement inline caches for virtual calls, but swift is statically compiled, so we have to guess the types at compile time. The early binding pass guesses that types at the bottom of the class hierarchy are not subclassed and emits direct calls to these passes. It converts class_method calls into the following code:

if (Instance is of time Foo) {
	Foo::ping()
} else {
	Instance->ping();
}

The check if an instance is of a specific type is inexpensive, it is simply a load+icmp sequence. 

Swift SVN r18860
2014-06-13 06:33:01 +00:00
Arnold Schwaighofer
8c10907ce9 Add a LoopInfoPrinter pass.
This pass uses SILLoopAnalysis to display loop information.

Swift SVN r18719
2014-06-05 22:25:43 +00:00
Michael Gottesman
3ebbaaa091 [sil-enum-simplification] Add new pass enum simplification that propagates enum case information down the CFG. Currently it only simplifies ref count operations in the same basic block, but it could be pushed further.
Swift SVN r18698
2014-06-04 04:43:05 +00:00
Manman Ren
b3e72be9d9 Remove unused deserialized SILFunctions.
The deserializer holds a reference to the deserialized SILFunction, which
prevents Dead Function Elimination from erasing them. 

We have a tradeoff on how often we should clean up the unused deserialized
SILFunctions. If we clean up at every optimization iteration, we may
end up deserializing the same SILFunction multiple times. For now, we clean
up only after we are done with the optimization iteration.

rdar://17046033


Swift SVN r18697
2014-06-04 00:30:34 +00:00
Mark Lacey
8156008cd8 Add a dead code elimination optimization pass.
In a loop like this:
  var j = 2
  for var i = 0; i < 100; ++i {
    j += 3
  }
it will completely eliminate j.

It does not yet support rewriting conditional branches as unconditional
branches in the cases where only empty blocks are control dependent on
an edge. Once this support is added, it will also completely eliminate
the loop itself.

Swift SVN r18615
2014-05-24 07:02:18 +00:00
Mark Lacey
a9368d137b Update file contents for rename of DeadCodeElimination.
Now that the file is called DiagnoseUnreachable.cpp, update the contents
to match.

Swift SVN r18614
2014-05-24 07:02:17 +00:00
Michael Gottesman
24d98ce926 [global-arc-opts] Copy current single basic block ARCOpts -> GlobalARCOpts in preparation for beginning multiple basic block ARC work.
This will allow me to hide this work behind a flag when the time comes
so that other people's work is not disrupted.

rdar://16965332

Swift SVN r18437
2014-05-19 22:56:01 +00:00
Andrew Trick
ab129dfb39 Add -global-opt pass.
Currently, this pass simply hoists calls to addressor functions up to
the function entry point. This solves most of the perfomance problem.

Fixes <rdar://problem/16500879> Need to hoist @swift_once outside of loops.

Swift SVN r16684
2014-04-23 01:09:48 +00:00
Michael Gottesman
cffc3d372d [constant-propagation] Refactor constant propagation slightly to disable diagnostics so we can use it in the performance passes to help with branch simplification.
This commit also enables constant propagation in the performance
pipeline.

Since we are close to WWDC, this commit purposefully minimally touches
the pass (despite my hands wanted to refactor it so bad) just enough so
that we get the desired result with minimal in tree turmoil.

rdar://16604715

Swift SVN r16388
2014-04-16 01:49:16 +00:00
Michael Gottesman
0727628c8c [deserialization] Add in the linker pass.
Swift SVN r15671
2014-03-31 08:40:36 +00:00
Chris Lattner
8869767260 Implement the rest of rdar://16242700
Fix a phase ordering problem: SILGen of a noreturn function doesn't drop an unreachable after the function,
and doing so is problematic for various reasons (all expressions would have to handle their insertion point
vaporizing, and would have to emit unreachable code diagnostics).  Instead, run a simple pass that folds
noreturn calls and diagnoses unreachable code, and do it before DI.  This prevents DI from seeing false
paths, and rejecting what seems like invalid code.



Swift SVN r14711
2014-03-06 01:29:32 +00:00
Michael Gottesman
c25d6f8390 [mandatory-inlining] Use getOptions() instead of passing around options.
Swift SVN r14493
2014-02-28 01:51:53 +00:00
Michael Gottesman
29e1a53bbb [deserialization] Deserialize transparent functions lazily iff they will be used in mandatory inlining.
Swift SVN r14490
2014-02-28 01:05:01 +00:00
Nadav Rotem
d52cbc89dd Rename AllocRefElim -> DeadObjectElim. NFC.
Swift SVN r14179
2014-02-20 23:14:59 +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
Andrew Trick
47b936fbae Let passes get their options (current configuration) from the
PassManager.

I think this is much cleaner and more flexible. The various pass
builders have no business marshalling these things around, and they
shouldn't be bound to the pass C'tor. In the future we will be able
override and dynamically modify pass configuration this way.

Swift SVN r13626
2014-02-07 05:01:00 +00:00
Michael Gottesman
cd0e0b8c27 Rename AAEvaluator => AADumper as per request.
Swift SVN r13603
2014-02-06 23:19:35 +00:00
Nadav Rotem
591a42aae3 Rename a few more pass factory methods.
Swift SVN r13588
2014-02-06 17:52:18 +00:00
Nadav Rotem
7cfb83449e Rename the pass to AllocBoxToStack
Swift SVN r13586
2014-02-06 17:43:54 +00:00
Michael Gottesman
4c92002736 [sil-aa] Create utility pass AAEvaluator which just evaluates AA on all values in a function. This is so that tests can be written to test out the AA implementation.
Swift SVN r13578
2014-02-06 10:06:21 +00:00
Nadav Rotem
f8c7b54d28 Delete the unused performXXX() functions.
Swift SVN r13531
2014-02-06 00:57:28 +00:00