Commit Graph

238 Commits

Author SHA1 Message Date
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
Dmitri Hrybenko
1eea220932 Use one module cache directory for all the lit tests to speed them up
Doing so is safe even though we have mock SDK.  The include paths for
modules with the same name in the real and mock SDKs are different, and
the module files will be distinct (because they will have a different
hash).

This reduces test runtime on OS X by 30% and brings it under a minute on
a 16-core machine.

This also uncovered some problems with some tests -- even when run for
iOS configurations, some tests would still run with macosx triple.  I
fixed the tests where I noticed this issue.

rdar://problem/19125022

Swift SVN r23683
2014-12-04 11:21:48 +00:00
Michael Gottesman
15bc4a634e Fix the build by initializing SILOptions earlier in sil-opt.
Swift SVN r23661
2014-12-03 22:38:41 +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
Michael Gottesman
85e2502f96 Pass in SILOptions to SILModule.
This should have been done a long time ago since SILOptions are options that
should be able to effect everything SIL related. In this case I just want to
pass in a flag on the SILModule to enable +0 self. By putting it on the
SILModule I can conveniently check it in SILFunctionType without exposing any
internal state from SILFunctionType.cpp.

Swift SVN r23647
2014-12-03 07:43:52 +00:00
Michael Gottesman
f85b695e5e [enum-simp] Now that enum simplification has been integrated into SILCodeMotion for a while, remove the old pass that is no longer in use.
Swift SVN r23588
2014-11-30 22:52:45 +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
Jordan Rose
0c94e535de [sil-opt] Add a -resource-dir option.
Swift SVN r22774
2014-10-15 21:36:21 +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
Andrew Trick
bef9edd5f4 Revamp the CopyForwarding pass, NRVO, various corner cases, unit tests (NFC).
This is still disabled as I haven't fixed the IRGen issue yet.

Swift SVN r22518
2014-10-04 01:23:11 +00:00
Manman Ren
c6d4cc05c6 [Printer] add sil-disable-ast-dump to disable dumping top AST decls.
This will be used for parsing sil generated from stdlib. We will ignore
the AST decls and instead import them from the module.

rdar://17979145


Swift SVN r22367
2014-09-29 22:04:15 +00:00
Michael Gottesman
04d9f968fd [rc-id] Make sure when stripping off arguments that the resulting stripped value dominates the argument.
This is important since to be more aggressive we are ignoring incoming values
that are no-payload enums since as far as we are concerned they do not matter
since retains, releases on those values are no-ops.

Swift SVN r21932
2014-09-12 22:21:06 +00:00
Michael Gottesman
4647eb9601 Create RCIdentityAnalysis a cache for stripRCIdentityPreservingOps.
The cache is needed to ensure we do not run into compile time problems once we
start looking through Phi Nodes.

The analysis is currently disabled and just returns
SILValue::stripRCIdentityPreservingOps. I am going to thread it through the rest
of the passes that use that call. Then I am going to hide
stripRCIdentityPreservingArgs. Finally post OzU, I am going to enable the pass.

rdar://18300069

Swift SVN r21891
2014-09-11 21:51:29 +00:00
Andrew Trick
9ce5894db1 Fix raw_fd_ostream calls for ToT constructor changes
Swift SVN r21447
2014-08-25 23:29:36 +00:00
Michael Gottesman
553365557f Remove old single basic block ARC optimization pass. It is bitrot now.
Swift SVN r21274
2014-08-19 06:03:13 +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
Nadav Rotem
7faa5883df Add a basic Class Hierarchy Analysis. At this point it only lists classes that are inherited from in this module.
Swift SVN r20710
2014-07-29 23:01:01 +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
Michael Gottesman
7d5751594d Add in a post order analysis that lazily recomputes post orders for functions when they are invalidated.
This ensures that if we have a bunch of passes in a row which modify the CFG, we
do not continually rebuild the post order, while at the same time preserving the
property of multiple passes which do not touch the CFG sharing the same post
order, reverse post order rather than recomputing them.

rdar://17654239

Swift SVN r19913
2014-07-14 01:32:24 +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
Pete Cooper
0d0defff9a Update which matches clang r212408, ie, using ErrorOr for file loading
Swift SVN r19607
2014-07-07 14:49:01 +00:00
Jordan Rose
d6f0a524b0 Fatal errors during -verify should always be treated as errors.
To disable this behavior, use the -show-diagnostics-after-fatal option.

Swift SVN r19483
2014-07-02 21:32:49 +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
Jordan Rose
1f6a6fa4ad [sil-opt] Always disable access control when running sil-opt.
Swift SVN r19352
2014-06-30 18:50:47 +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
Jordan Rose
2cac7e1c58 SIL tools always operate as -parse-stdlib, even when working with modules.
r18796 added a check that the standard library is always available when
not working in -parse-stdlib or SIL mode, but sil-opt and sil-extract have
no need to load the stdlib if the module file they're working on does not
depend on it. Treat these tools as if they are always in a -parse-stdlib mode.

This fixes the failure in witness_tables.sil, which is due to us pulling in
witness tables from all loaded modules.

Swift SVN r18807
2014-06-11 19:02:05 +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
3ba4ca1b31 Add support for printing SIL with SIL entities sorted by name behind the flag -sil-sort-by-output-names.
This significantly reduces the diff size when diffing the standard
library.

Swift SVN r18700
2014-06-04 05:22:52 +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
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
Mark Lacey
c5fd54a493 Add missing break to case.
Swift SVN r18587
2014-05-23 06:38:39 +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
Argyrios Kyrtzidis
796afac0af [Frontend] Rename CompilerInstance::performParse() -> performSema() to make it more clear that it is doing parsing + type checking.
Swift SVN r17597
2014-05-07 02:13:49 +00:00
Jordan Rose
f053c845a2 [sil-opt] Add -target option, and use it in SDK deserialization tests.
Swift SVN r17496
2014-05-05 23:45:41 +00:00
Michael Gottesman
1f93ec5480 [devirtualization] Remove deep devirtualization code that we are not using for WWDC.
If we decide in the future to do this we can always revert this commit.

Swift SVN r17293
2014-05-03 00:33:46 +00:00
Doug Gregor
3d3ff6811a Add a pile of missing #includes exposed by pruning includes in top-of-tree LLVM.
Swift SVN r17157
2014-05-01 14:26:34 +00:00
Michael Gottesman
662ac332dc [sil-opt] Teach silopt how to run predefined optimization groups diagnostics and performance.
Swift SVN r17010
2014-04-29 03:56:55 +00:00