Commit Graph

25 Commits

Author SHA1 Message Date
Erik Eckstein
30c34894e0 Don't speculate initialization of globals with limited availability.
Fixes rdar://problem/20708979



Swift SVN r27965
2015-04-30 11:08:49 +00:00
Erik Eckstein
3549d46d3b Remove -enable-static-init option from GlobalOpts.
It is now done by default.



Swift SVN r27805
2015-04-27 17:07:45 +00:00
Erik Eckstein
3149910bc9 Improve the removal of redundant global-init calls in GlobalOpt.
Due to a small bug, redundant init-calls were only removed if the first call was inside a loop.
Now it should also work in cases without loops.
Related radar: rdar://problem/20433505



Swift SVN r27693
2015-04-24 13:59:06 +00:00
Erik Eckstein
cda450f8a2 Enable static initializer optimization by default.
Manman implemented this optimization a while ago, but it was not enabled by default.
<rdar://problem/18169093> Eliminate trivial global initializers by replacing them with sil_global constants.




Swift SVN r27685
2015-04-24 06:33:46 +00:00
Nadav Rotem
680c565af5 Refactor the code that checks if a function is marked with noopt semantics. NFC.
Swift SVN r27485
2015-04-20 17:27:31 +00:00
Nadav Rotem
926042ff81 Add @semantics("optimize.never") to disable optimizations of a specific function.
This commit adds a flag to disable optimizations on a specific functions. The
primary motivation of this patch is to allow the optimizer developers to reduce
testcasese by disabling optimizations of parts of the code without having to
recompile the compiler or inspect SIL. The annotations  "inline(never)"
and "optimize.none" can go a long way.

The second motivation for this patch is to allow our internal adopters to work
around compiler bugs.

rar://19745484

Usage:

@semantics("optimize.never")
public func miscompile() { ... }

Swift SVN r27475
2015-04-20 05:06:55 +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
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
Nadav Rotem
8d413c32a7 Invalidate the CallGraph after Global opt because we may be removing calls to global_initializer functions.
Swift SVN r25585
2015-02-27 01:54:31 +00:00
Mark Lacey
6170bbb0ed Minor code clean-up.
Primarily replacing getParent()->getParent() with getFunction().

Swift SVN r24596
2015-01-21 06:35:13 +00:00
Erik Eckstein
7573d42fe1 Fix checks for globalinit_* functions.
I missed this in my commit r22795: Mangle names of globalinit_{token,func} like other private entities.



Swift SVN r22839
2014-10-20 13:47:40 +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
Manman Ren
18042db194 [Global Opt] update SILGlobalOpt to use static initializer if possible.
This is off by default and is a modified version of r21996 (reverted in r22001).

Update SILGlobalOpt to remove "once" call from addressor and set the
InitializerF for SILGlboalVariable if legal.

For calls to addressor in non-cold block, we check the addressor to find out
the globalinit_func and the associated SILGlobalVariable. If legal, we set
InitializerF of SILGlobalVariable and remove "once" call from addressor.

The current rules for legality:
1> the addressor contains a single "once" call and it calls globalinit_func.
2> the globalinit_func is called by "once" from a single location.
   When we inline the addressor, the globalinit_func will be called by "once"
   from multiple locations. After we remove the "once" from the addressor, the
   inlined version will mistakely initialize the global variable again.
3> the globalinit_func is trivial as defined by
   SILGlobalVariable::canBeStaticInitializer().

Update IRGen to generate constant initializers for global variables with static
initializers (i.e non-null InitializerF).

Joe's suggestion on having the static initializer to return the result instead
of storing it is not implemented in this commit. But we do verify that a static
initializer has a single store to the global variable. The suggestion is tracked
in rdar://18382039.

Implement rdar://16621368, rdar://18169093.


Swift SVN r22083
2014-09-18 17:40:24 +00:00
Manman Ren
5311e7a98f [Global Opt] revert r21996.
r21996 tries to take advantage of LLVM global opt that eliminates global
initializers by using llvm.global_ctors. Revert it because we can't guarantee
that they will be optimized to constant initializers.

A modifed version will follow that uses constant initializers directly in IRGen.


Swift SVN r22001
2014-09-17 03:30:06 +00:00
Manman Ren
0351a2aa85 [Global Opt] update SILGlobalOpt to use static initializer if possible.
Update SILGlobalOpt to remove "once" call from addressor and set the
InitializerF for SILGlboalVariable if legal.

For calls to addressor in non-cold block, we check the addressor to find out
the globalinit_func and the associated SILGlobalVariable. If legal, we set
InitializerF of SILGlobalVariable and remove "once" call from addressor.

The current rules for legality:
1> the addressor contains a single "once" call
2> it calls globalinit_func
3> the globalinit_func is called by "once" from a single location
4> the globalinit_func is trivial

Update IRGen to emit llvm.global_ctors for global variables with static
initializers (i.e non-null InitializerF).

Performance --------
After:
Totals,54,67202,67202,67202,0,0 Onone
Totals,54,88948,88948,88948,0,0 O
Totals,54,71222,71222,71222,0,0 Ounchecked
Totals,54,66405,66405,66405,0,0 Onone
Totals,54,88759,88759,88759,0,0 O
Totals,54,71761,71761,71761,0,0 Ounchecked
Before:
Totals,55,68133,68133,68133,0,0 Onone
Totals,55,92458,92458,92458,0,0 O
Totals,55,72262,72262,72262,0,0 Ounchecked
Totals,55,69022,69022,69022,0,0 Onone
Totals,55,92178,92178,92178,0,0 O
Totals,55,72593,72593,72593,0,0 Ounchecked


Swift SVN r21996
2014-09-16 23:20:37 +00:00
Andrew Trick
a0a3f813b3 Remove temporary -enable-global-opt flag
Swift SVN r21260
2014-08-18 20:37:30 +00:00
Dmitri Hrybenko
26277fc41d Demangler: remove StringRef dependencies in the demangler interface and
PrettyStackTrace dependencies in the implementation


Swift SVN r20248
2014-07-21 12:46:58 +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
Andrew Trick
9d12bbd62e Added -enable-global-opt flag.
Swift SVN r19699
2014-07-08 21:43:15 +00:00
Andrew Trick
757348c3f7 Don't hoist SIL addressor calls out of cold blocks.
Swift SVN r19698
2014-07-08 21:43:15 +00:00
Andrew Trick
7f967015c8 Allow ColdBlockInfo to be used conveniently in a SIL module pass.
Swift SVN r19697
2014-07-08 21:43:14 +00:00
Andrew Trick
3ff33be164 SIL GlobalOpt pass: hoist init calls to the outer preheader.
This seems to consistently improve two benchmarks.
| key         |     tot0 |     tot1 |     tot2 |     opt0 |     opt1 |     opt2 |  delta | speedup |
| Ackermann   |  4036.00 |  4016.00 |  3941.00 |  3785.00 |  3843.00 |  3827.00 | 156.00 |    4.1% |
| LinkedList  |  1551.00 |  1606.00 |  1540.00 |  1523.00 |  1531.00 |  1516.00 |  24.00 |    1.6% |

Swift SVN r19571
2014-07-04 18:07:54 +00:00
Andrew Trick
e5d18b0c15 Convert the GlobalOpt pass into a proper SILModuleTransform.
Clear the entire state between runs just to be safe. This should have
no effect currently since it only runs once.

Swift SVN r19531
2014-07-03 21:35:08 +00:00
Andrew Trick
5dc505ab2e Reenable -global-opt after teaching it to avoid hoisting initializer calls unless they are inside loops.
<rdar://problem/16792521> Hoist globals initializers out of loops.

Long term, we should recognize hot/cold idioms for ObjC support and
provide an analysis that identifies cold branch targets. However,
identifying loops is trivial and self-contained so more appropriate
for WWDC.

I have not been able to reproduce the StringSort regression. However,
I compared Benchmark.swift with Release build before and after
enabling the pass with this patch and saw no regressions.

Swift SVN r17554
2014-05-06 18:10:29 +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