Commit Graph

83 Commits

Author SHA1 Message Date
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
Arnold Schwaighofer
c366d18249 Add an use iterator to iterate over a set of uses of a value while ignoring
expect intrinsics.

The view presented is that of all uses of the value looking through
builitin expect users at their uses.

Swift SVN r27840
2015-04-27 23:44:55 +00:00
Michael Gottesman
d494735329 Teach capture promotion how to handle all types of partial apply arguments. We technically don't need it now but it would be technical debt to leave it unfixed.
rdar://19552593

Swift SVN r27798
2015-04-27 01:59:46 +00:00
Michael Gottesman
eed6317da2 Add a callback struct to tryDeleteDeadClosure() that clients can use to be notified of instruction insertion and deletion.
rdar://19552593

Swift SVN r27749
2015-04-26 05:11:54 +00:00
Arnold Schwaighofer
e4e1254383 Reapply "SimplifyCFG: Fix a bug in the jump threading code"
This reverts commit r27739 reapplying r27722.

The test (validation/stdlib/Hashing.swift) that failed is expected to sometimes
fails.

Original message

"SimplifyCFG: Fix a bug in the jump threading code

When jump threading a block we used to propagate phi values directly into the
threaded block - instead of leaving in a copy. Because of this the SSA updater
would propagate the value feeding the copy from the next iteration.
Now when jump threading the destination block into the edge we leave in the phi
(copy) such that the SSA updater picks up value of the right iteration.

rdar://20617338"

Swift SVN r27741
2015-04-26 01:28:10 +00:00
Arnold Schwaighofer
50355e99dc Revert "SimplifyCFG: Fix a bug in the jump threading code"
This reverts commit r27722.

Broken bot.

Swift SVN r27738
2015-04-26 00:24:34 +00:00
Arnold Schwaighofer
9921573073 SimplifyCFG: Fix a bug in the jump threading code
When jump threading a block we used to propagate phi values directly into the
threaded block - instead of leaving in a copy. Because of this the SSA updater
would propagate the value feeding the copy from the next iteration.
Now when jump threading the destination block into the edge we leave in the phi
(copy) such that the SSA updater picks up value of the right iteration.

rdar://20617338

Swift SVN r27722
2015-04-25 22:42:29 +00:00
Mark Lacey
1859b476d4 Further integration of inlining, devirtualization, and specialization.
This updates the performance inliner to iterate on inlining in cases
where devirtualization or specialization after the first pass of
inlining expose new opportunities for inlining. Similarly, in some cases
inlining exposes new opportunities for devirtualization, e.g. when we
inline an initializer and can now see an alloc_ref that allows us to
devirtualize some class_methods.

The implementation currently has some inefficiencies which increase the
swift compilation time for the stdlib by around 3% (this is swift-time
only, no LLVM time, so overall time does not grow by this much).

Unfortunately the (unchanged) current implementation of the core
inlining trades off improved estimates of code growth for increased
compile time, and that plays a part in why compile time increases as
much as it does. Despite this, I have some ideas on how to win some of
that time back in future patches.

Performance differences are mixed, and this will likely require some
further inliner tuning to reduce or remove some of the losses seen here
at -O. I will open radars for the losses.

Wins:
DeltaBlue                        10.2%
EditDistance                     13.8%
SwiftStructuresInsertionSort     32.6%
SwiftStructuresStack             34.9%

Losses:
PopFrontArrayGeneric            -12.7%
PrimeNum                        -19.0%
RC4                             -30.7%
Sim2DArray                      -14.6%

There were a handful of wins and losses at Onone and Ounchecked as
well. I'll review the perf testing output and open radars accordingly.

The new test case shows an example of the power of the closer
integration here. We are able to completely devirtualize and inline a
series of class_method applies (10 deep in this case, but in theory
substantially deeper) in a single pass of the inliner, whereas before we
could only do a single level per pass of inlining & devirtualization.

Swift SVN r27561
2015-04-22 04:48:13 +00:00
Erik Eckstein
0c5a97ebc5 SimplifyCFG: fix condition equivalence checking in checked-cast jump threading.
It was wrong in case two checked_cast_br have select_enum (with identical enum operands) as conditions.



Swift SVN r27356
2015-04-16 11:37:39 +00:00
Roman Levenstein
2dd38eee0e [sil-combine] Teach the optimizer how to optimize bridged casts.
If a conformance to _BridgedToObjectiveC is statically known, generate a more efficient code by using the newly introduced library functions for bridging casts.
This covers the casts resulting from SIL optimizations.

Tests are included. I tried to cover most typical casts from ObjC types into Swift types and vice versa and to check that we always generate something more efficient than a checked_cast or unconditional_checked_cast. But probably even more tests should be written or generated by means of gyb files to make sure that nothing important is missing.

The plan is to make the bridged casts SIL optimization a guaranteed optimization. Once it is done, there is no need to lower the bridged casts in a special way inside Sema, because they all can be handled by the optimizer in a uniform way. This would apply to bridging of Error types too.

With this change, no run-time conformance checks are performed at run-time if conformances are statically known at compile-time.
As a result, the performance of rdar://19081345 is improved by about 15%. In the past, conformance checks in this test took 50% of its execution time, then after some improvements 15% and now it is 0%, as it should be.

Swift SVN r27102
2015-04-07 22:53:57 +00:00
Mark Lacey
fea3321f59 Update the generic specializer to maintain the call graph.
Swift SVN r27024
2015-04-05 19:27:40 +00:00
Mark Lacey
730ef41385 Make devirtualizer clients remove old applies.
This makes it feasible for clients to maintain the call graph.

Swift SVN r26997
2015-04-05 02:27:57 +00:00
Mark Lacey
fe3c827c6a Unindent namespace.
If someone has conflicting changes, please feel free to revert this,
commit your changes, and then do the same unindenting of the resulting
file as a separate step.

Swift SVN r26819
2015-04-01 19:17:00 +00:00
Mark Lacey
1b75112151 Fix typos.
Swift SVN r26789
2015-04-01 02:10:54 +00:00
John McCall
6d8fff9c06 Parsing and basic structure of try_apply. Not yet properly
threaded into IRGen; tests to follow when that's done.

I made a preliminary effort to make the inliner do the
right thing with try_apply, but otherwise tried to avoid
touching the optimizer any more than was required by the
removal of ApplyInstBase.

Swift SVN r26747
2015-03-31 02:41:03 +00:00
Roman Levenstein
9b0cb402fc [sil-simplify-cfg] Move the implementation of CheckedCastBrJumpThreading into its own file. NFC.
This is a part of our attempts to clean-up the SimplifyCFG, which got just too huge to work with.

Swift SVN r26660
2015-03-28 00:42:08 +00:00
Roman Levenstein
7011a5f4b4 [generic-specializer] Add support for specializing generic partial_apply instructions.
Use existing machinery of the generic specializer to produce generic specializations of closures referenced by partial_apply instructions. Thanks to the newly introduced ApplyInstBase class, the required changes in the generic specializer are very minimal.

rdar://19290942

Swift SVN r26582
2015-03-26 06:41:30 +00:00
Roman Levenstein
51ad2d964d Move the logic for type casts optimizations into one place.
This is mostly a re-factoring. It creates a new helper class CastOptimizer which contains all the logic for performing type casts optimizations. This logic is a copy of the current logic from sil-combine and simplify-cfg. Those passes will become clients of this new helper class.

Swift SVN r26122
2015-03-14 02:23:05 +00:00
Arnold Schwaighofer
aa24e126e4 ArraySemantic: Move to its own file in SILAnalysis
I want to use it in ARCAnalysis.

Swift SVN r25924
2015-03-10 15:20:20 +00:00
Arnold Schwaighofer
06f7c40c32 ArraySemanticsCall: Handle @guaranteed parameters
Also improve checking of parameter requirements.

This is needed for our move to +0 self.

radar://20039357

Swift SVN r25798
2015-03-06 03:20:47 +00:00
Arnold Schwaighofer
f7c01f2061 Nuke isReadNone function
We can now compute the same result with Inst.mayReadOrWriteMemory(). NFC.

Swift SVN r25743
2015-03-04 05:03:45 +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
Arnold Schwaighofer
14ddfe1427 Add an API to ArraySemantic call to get the self argument as an operand.
Swift SVN r25619
2015-02-27 22:07:39 +00:00
Luqman Aden
e1c60464d3 Fold getCmpFunction function into helper method on SILBuilder.
Swift SVN r25416
2015-02-20 04:08:08 +00:00
Luqman Aden
858d8d99df SILCombine: Add cmp_*_T . (zext U->T x, zext U->T y) => cmp_*_T (x, y)
peephole for unsigned/equality comparisons.

Fixes <rdar://problem/19759124>

Swift SVN r25404
2015-02-20 00:39:33 +00:00
Michael Gottesman
669cdc537c Create an entrypoint tryToConcatenateStrings and hide the class StringConcatenationOptimizer in Local.cpp.
In every instance, we were just creating the StringConcatenationOptimizer and
then invoking optimize on it. This is a cleaner solution since the details of
how we perform the string concatenation are hidden in Local.cpp instead of being
in a header.

NFC.

Swift SVN r25341
2015-02-17 01:59:13 +00:00
Mark Lacey
03cca73418 Fix naming convention.
Swift SVN r25179
2015-02-11 10:27:19 +00:00
Mark Lacey
c804c50c4d Add a simple utility for determining the lifetime of a value.
This refactors some code out of AllocBoxToStack that computes the
lifetime of a value in the strictess sense, limiting the lifetime to
that value and not anything derived from that value (whether by casting,
projection, etc.).

In the short term this will be used to fix a very rarely hit
optimization in AllocBoxToStack.

Longer term I will replace the other similar code in AllocBoxToStack to
use this instead.

Swift SVN r25176
2015-02-11 10:17:03 +00:00
Michael Gottesman
436f022867 [local] Add tryDeleteDeadClosures.
This utility attempts to delete dead closures with a set of
post-dominating releases using the infrastructure from
getFinalReleasesForValue.

It currently only will eliminate closures that only have retain, release
uses and a final post-dominating release set.

The reason why we need the final post-dominating release set is so that
we can release any captured variables at the points where we would have
deallocated the release. This is b/c captured variables are passed in at
+1 to partial apply.

Swift SVN r25050
2015-02-06 21:59:52 +00:00
Arnold Schwaighofer
283a6bee39 Fix users of ArraySemantics::getSelf to correctly handle Array.init
Array.init does not have a self argument (it returns the newly created array
@owned). Passes using the ArraySemantic::getSelf() interface must handle it
specially.

rdar://19724033

Swift SVN r25013
2015-02-05 19:31:23 +00:00
Adrian Prantl
95eec5a155 Fix Test for: DCE is dropping debug intrinsics, Was: DebugInfo/closure-multivalue test is failing
In order to not completely loose testcoverage while rdar://problem/18709125
is under investiagtion, add a special flag for enabling debug value
liveness.

Patch by Michael Gottesman!

<rdar://problem/19267059>

Swift SVN r24416
2015-01-14 18:37:39 +00:00
Erik Eckstein
31dd17a49f Add array.uninitialized semantics to ArrayCallKind, ArraySemanticsCall and the docs.
For completeness. NFC.



Swift SVN r23955
2014-12-16 13:28:18 +00:00
Arnold Schwaighofer
2f949056d6 SIL utils: Rename array.props.isCocoa to array.props.isNative
The upcoming stdlib patch will also be modified.

NFC

rdar://17955309

Swift SVN r23813
2014-12-09 21:58:16 +00:00
Mark Lacey
9d6e7cddc8 Reapply r23673, which was reverted in r23679.
It had exposed a problem with the MemBehavior on a couple SIL
instructions which resulted in code motion moving a retain across an
instruction that can release (fixed in r23722).

From the original commit message:

    Remove restriction on substituting existentials during mandatory inlining.

    Issues around this have now been resolved, so we should now support
    anything that Sema lets through.

    Fixes rdar://problem/17769717.

Swift SVN r23729
2014-12-05 05:47:42 +00:00
Arnold Schwaighofer
404ce8c599 ArraySemantics: Add support for the upcoming array.props semantic calls
"array.props.isCocoa/needsElementTypeCheck" semantic calls will mark calls that
return array properties: isCocoa and needsElementTypeCheck. We know that said
states can only transfer in certain directions (a native swift array that does
not need an element type check stays in this state) enabling us to version loops
based on the state of said array array properties.

rdar://17955309

Swift SVN r23688
2014-12-04 19:24:39 +00:00
Mark Lacey
2cb14c32fe Revert "Remove restriction on substituting existentials during mandatory inlining."
This reverts commit r23673.

It looks like this broke the DollarChain benchmark so I am backing it
out while I investigate.

Swift SVN r23679
2014-12-04 05:40:49 +00:00
Mark Lacey
f3b82c7bfd Remove restriction on substituting existentials during mandatory inlining.
Issues around this have now been resolved, so we should now support
anything that Sema lets through.

Fixes rdar://problem/17769717.

Swift SVN r23673
2014-12-04 01:12:42 +00:00
Roman Levenstein
f8c3dda827 [sil-combine] Move the StringConcatenationOptimizer class into Local.h/.cpp. NFC.
This is done because this class is to be used by sil-combine and constant constant-propagation.

Swift SVN r23654
2014-12-03 21:46:27 +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
Michael Gottesman
269c372d97 [func-sig-opts] Extract out utility method removeDeadBlocks() from simplifyCFG so I canuse it in FunctionSignatureOpts.
I also extracted out an additional method clearBlockBody() from the body
of removeDeadBlocks() since I need that functionality exposed in
Function Signature Opts.

Swift SVN r22560
2014-10-07 00:53:58 +00:00
Arnold Schwaighofer
c1eefb1dad Reapply "stdlib: Remove dead semantic Array._setElement function
Also remove helper functions."

With fixes.

Swift SVN r22479
2014-10-02 20:26:32 +00:00
Arnold Schwaighofer
2bd116c20b Revert "stdlib: Remove dead semantic Array._setElement function"
This reverts r22468. Because it breaks the build.

Swift SVN r22469
2014-10-02 18:46:24 +00:00
Arnold Schwaighofer
cfd4a0902d stdlib: Remove dead semantic Array._setElement function
Also remove helper functions.

Swift SVN r22468
2014-10-02 18:44:31 +00:00
Arnold Schwaighofer
b6f28bede1 ArraySemantics: Teach array semantics about getting the address of an array element
rdar://18517410

Swift SVN r22439
2014-10-01 21:08:22 +00:00
Arnold Schwaighofer
813d43415f ArraySemantics: Add wrapper utility for array semantics calls to Local.h
This encapsulates common operations on array semantic calls like identifying
them or hoisting/copying them.

Will be used by follow-up commits. NFC.

Swift SVN r21926
2014-09-12 21:05:22 +00:00
Michael Gottesman
6e485700c6 Move SimplifyInstruction into SILAnalysis since it is an analysis.
This will hopefully make it clearer as we onboard people that
SimplifyInstruction should not add instructions to the IR by making it clearer
that it is an analysis, not a pass.

Swift SVN r21752
2014-09-05 22:56:26 +00:00
Arnold Schwaighofer
88372515bd Add an isReadNone API for function refs and use it in CSE
This looks for @effects(readnone) on functions. A follow up commit will mark
_swift_isClassOrObjCExistential as readnone allowing us to CSE it.

rdar://17961249

Swift SVN r21285
2014-08-19 18:05:41 +00:00
Andrew Trick
bd299c9b16 Move getSpecializedLinkage into Local.cpp
Swift SVN r21247
2014-08-16 01:12:26 +00:00
Mark Lacey
d5a619bbad Small refactoring of call graph code.
This is a first step towards building a better call graph.

Swift SVN r21152
2014-08-12 18:20:21 +00:00
Manman Ren
1bace828d4 Move addArgumentToBranch to Local.h so we can use it in LoadStoreOpt. NFC.
Swift SVN r20726
2014-07-30 00:03:45 +00:00