Commit Graph

51 Commits

Author SHA1 Message Date
Arnold Schwaighofer
9a7d57ac21 COWArrayOpt: Match retain/release that load an array address projection
Recovers the RC4 regression.

rdar://20654877

Swift SVN r27623
2015-04-23 02:08:16 +00:00
Arnold Schwaighofer
4dd60cbb17 COWArrayOpt: Document the usage of the MatchedReleases set.
Swift SVN r27615
2015-04-22 23:58:11 +00:00
Arnold Schwaighofer
77bb96c43c Fix a bug in the dominator update of the array property specializer
Found by running our pipeline with critical edge splitting on.

Swift SVN r27483
2015-04-20 16:53:17 +00:00
Mark Lacey
95ed2af172 Update comment to reflect recent updates.
Swift SVN r27014
2015-04-05 05:07:17 +00:00
Mark Lacey
a57bfed2d1 Lock invalidations of the call graph during COWArrayOpt.
We already preserve the call graph, so we should not allow it to be
invalidated.

Swift SVN r27012
2015-04-05 04:53:47 +00:00
Erik Eckstein
78a3572fa4 Rename NoDTC to NoTypeCheck. NFC.
Swift SVN r26973
2015-04-04 08:24:59 +00:00
Erik Eckstein
2f971c22cb re-apply r26871: stdlib: Do the Array fast-path check with a single array property call.
Changes compared to the original version:
I fixed the 2 bugs and added a test for the so far undetected missing range check bug.
To keep the SIL simple (4 basic blocks for arr[x]) I extracted the slow path for getElement into a
non-inlinable function.
On the other hand I inlined _typeCheck into the slow-path function.
This speeds up NSArray accesses because now only a single objectAtIndex is required for both
type checking and element retrieving.

Update on performance: DeltaBlue is now only 12% better (and not 25%). I suspect this is because
now Arnold's tail duplication cannot detect the ObjC call in the slow path.



Swift SVN r26935
2015-04-03 06:48:25 +00:00
Mark Lacey
23b6bd84f6 Do not build the call graph just to maintain it.
Before this commit, passes that were attempting to maintain the call
graph would actually build it if it wasn't already valid, just for the
sake of maintaining it.

Now we only maintain it if we already had a valid call graph built.

Swift SVN r26873
2015-04-02 17:16:01 +00:00
Ted Kremenek
69a12dfcb8 Revert "stdlib: Do the Array fast-path check with a single array property call."
This was causing test '1_stdlib/ArrayTraps.swift.gyb' to fail.

Swift SVN r26872
2015-04-02 14:47:19 +00:00
Erik Eckstein
834645a901 stdlib: Do the Array fast-path check with a single array property call.
Now that we can check isNative and NoDTC (no deffered type check needed) with a single bit-mask operation,
it makes sense to have a single array property call for it.
I replaced the the semantics call array.props.needsElementTypeCheck with array.props.isNativeNoDTC,
which is the combination of isNative && !needsElementTypeCheck. I kept array.props.isNative, which is not used for now,
but might be useful in the future, e.g. for array operations which don't care about type checks.

The optimized SIL for a class array access arr[i] now contains the minimum of 4 basic blocks.
PerfTests show +25% for DeltaBlue and some improvemements for -Onone.



Swift SVN r26871
2015-04-02 14:10:54 +00:00
Michael Gottesman
b122c0da47 [array-semantics] Teach array semantics to update the CallGraph when deleting instructions.
Swift SVN r26859
2015-04-02 05:01:09 +00:00
Michael Gottesman
2c1aed9b27 [cow] Teach uniqueness check hoisting how to ignore guaranteed calls to ArraySemantic functions.
We ignore calls to ArraySemantic functions when we hoist uniqueness checks. With
+0 self, this is disrupted by the release that now is in the caller instead of
the callee.

This patch fixes that problem by teaching COWArrayOpts about "guaranteed call
sequences". This is the following pattern:

retain(x)
... nothing that decrements reference counts ...
call f1(@guaranteed_self x)
... nothing that decrements or uses ref counts ...
call f2(@guaranteed_self x)
... nothing that decrements or uses ref counts ...
...
... nothing that decrements or uses ref counts ...
call f$(n-1)(@guaranteed_self x)
... nothing that decrements or uses ref counts ...
call fn(@guaranteed_self x)
... nothing that uses ref counts ...
release(x)

This pattern is created when there are a bunch of guaranteed calls together in a
row (which seems to happen at the "semantic" SIL level). We pattern match the
sequence and then verify that all of the calls are semantic calls. If the
verification succeeds, we can hoist the uniqueness check.

rdar://20340699

Swift SVN r26835
2015-04-01 23:30:03 +00:00
Michael Gottesman
6bd51ea51c Small style cleanups and convert query to use covered switch. NFC.
Swift SVN r26703
2015-03-29 20:29:07 +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
50803a7653 Create FunctionAnalysisBase to handle the boiler plate of caching and invalidating function specific analysis.
Swift SVN r26642
2015-03-27 20:54:22 +00:00
Nadav Rotem
f0fa502d56 Split the RCIdentityAnalysis analysis to allow per-function invalidation.
Before the change the RCIdentityAnalysis kept a single map that contained
the module's RC information. When function passes needed to invalidate the
analysis they had to clear the RC information for the entire module. The
problem was mitigated by the fact that we process one function at a time, and
we start processing a new function less frequently.

II adopted the DominanceAnalysis structure. We should probably implement
this functionality as CRTP.

Swift SVN r26636
2015-03-27 16:55:36 +00:00
Michael Gottesman
5c3b4a8dfe [cow] Teach uniqueness about mark_dependence on the array value.
We already did this for element accesses, this just extends it to handle array value.

This prevents a regression that is caused by my needing to insert an enum
so I can properly RAW a strong_pin operand onto the strong pin's users in a
subsequent patch to improve RemovePin for +0 self.

rdar://20267677

Swift SVN r26528
2015-03-25 06:21:10 +00:00
Michael Gottesman
a2233ebef4 [cow] Replaced some for () { if-else-if-else } code with common terminator statements with individual terminator. NFC.
Swift SVN r26527
2015-03-25 06:21:10 +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
2781e93d9f Port COW and LoopRotate to use the new locking-analysis API. NFC.
Swift SVN r26376
2015-03-20 22:53:09 +00:00
Arnold Schwaighofer
4aa6de5744 COWArrayOpt: A side-effect free instruction cannot mutate the array
This was blocking hoisting make_mutable with +0 Self enabled.

rdar://20071261

Swift SVN r26112
2015-03-13 21:31:31 +00:00
Arnold Schwaighofer
2106b44704 RegionCloner: Split edges from non cond_br terminators to exit blocks
When we clone the exiting block such edges become critical and we don't like
critical non cond_br edges (updating SSA needs to put arguments somewhere and
such).

radar://20114457

Swift SVN r25982
2015-03-11 17:25:16 +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
8038fd65a4 Revert "Revert "COWArrayOpt: Enable array.props hoisting""
Renable array property check hoisting. Third try.

This reverts commit r25751.

Swift SVN r25839
2015-03-07 05:07:32 +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
Michael Gottesman
d7d5dac460 Revert "COWArrayOpt: Enable array.props hoisting"
This reverts commit r25737. The pass was just turned on and is causing Asan to
trigger.

Swift SVN r25751
2015-03-04 08:17:44 +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
459fdb52ea Revert "Revert "COWArrayOpt: Enable array.props hoisting""
This reverts commit r25702 and reenabling array property hoisting.

Swift SVN r25737
2015-03-04 01:06:29 +00:00
Arnold Schwaighofer
a4c4f3aa2a COWArrayOpt: Split cond_br critical edges after cloning loops
Our cannonical form requires this.

Swift SVN r25736
2015-03-04 01:06:28 +00:00
Arnold Schwaighofer
7859522dbc COWArrayOpt: Only invalidate if we have changed the CFG
Swift SVN r25735
2015-03-04 01:06:28 +00:00
Arnold Schwaighofer
c52593fdce COWArrayOpt: No need to call SILAnalysis::invalidate twice
Invalidating the CFG will invalidate instructions.

Swift SVN r25734
2015-03-04 01:06:27 +00:00
Arnold Schwaighofer
411ba4e830 COWArrayOpt: Fix the array property specializer to recompute the loop tree after cloning
Cloning the loop is going to invalidate the loop tree. Be conservative and
recompute it.

No test case. I did not run into an error but also don't want to in the future.

Swift SVN r25733
2015-03-04 01:06:27 +00:00
Arnold Schwaighofer
c8180d6ee7 Revert "COWArrayOpt: Enable array.props hoisting"
This reverts commit r25699.

There is build bot breakage I believe due to this.

Swift SVN r25702
2015-03-03 02:43:50 +00:00
Arnold Schwaighofer
646e5e1f68 COWArrayOpt: Enable array.props hoisting
O speedup (before/after):
  ClassArrayGetter`7.4
  Rectangles```````1.9
  InsertionSort````0.9
  Chars````````````0.92

I looked at the Chars and InsertionSort regressions and did not see something
actionable. It looked like noise.

rdar://17955309

Swift SVN r25699
2015-03-03 00:46:00 +00:00
Arnold Schwaighofer
c087f218f9 COWArrayOpt: Hoist array projections to the preheader
In nested loops the projection operations to get to the array are only
conditionally executed (they reside in the preheader of the inner loop).
So LICM will not hoist them. Instead, recognize them and hoist them on demand.

rdar://19957962

Swift SVN r25620
2015-02-27 22:07:40 +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
Arnold Schwaighofer
71922a4daa COWArrayOpt: Handle cases where the array is not uniquely identified
We can still hoist in many cases if all operations in the loop are 'safe' wrt.
hoisting.

'Safe' array operations are

  * all array semantic functions (as long as one array type cannot contain
    another).
  * stores to array elements
  * any instruction that does not have side effects.
  * any retain must be matched by a release before we hit a make_unique.

rdar://19668784

Swift SVN r24960
2015-02-04 16:39:14 +00:00
Arnold Schwaighofer
0f4f6833c1 COWArrayOpt: Update for array addressor changes
A mark_dependence use of the buffer is safe.

Swift SVN r24445
2015-01-15 15:33:44 +00:00
Mark Lacey
4a74e94b40 Fix release build warnings about unused variables.
Swift SVN r23893
2014-12-12 20:05:30 +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
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
Ben Langmuir
e9e1666ab0 Update for upstream LLVM changes
* removal of StringMap's GetOrCreateValue
* SmallSet::insert now returns a pair like std::set

Swift SVN r23435
2014-11-19 16:49:30 +00:00
Arnold Schwaighofer
bb47ce9e00 COWArrayOpts: strong_release on the array is also harmless
Needed for the upcoming array implementation change.

rdar://18777237

Swift SVN r23075
2014-11-03 02:18:35 +00:00
Arnold Schwaighofer
e6c44a377b COWArrayOpt: We could (and are now) also use a strong retain on the array storage
Swift SVN r22998
2014-10-29 01:56:14 +00:00
Andrew Trick
2ca16462b2 NFC: Update COW Array pass name string
Swift SVN r21964
2014-09-16 01:56:41 +00:00
Arnold Schwaighofer
12b0e13459 COWArrayOpt: Use ArraySemanticsCall utility
NFC

Swift SVN r21929
2014-09-12 21:05:23 +00:00
Arnold Schwaighofer
6da1647e1f COWArrayOpt: Use ValueBase's getParentBB api
Swift SVN r21927
2014-09-12 21:05:22 +00:00
Michael Gottesman
24c138f29c Move SILLoopInfo into swiftSIL from swiftSILAnalysis so that we match the separation in between analysis and IR entities.
This follows the model of dominance info and allows me to create reachability
methods on SILBasicBlock without creating dependencies from swiftSIL to
swiftSILAnalysis.

Swift SVN r21866
2014-09-11 03:03:06 +00:00
Andrew Trick
bba2a37070 More COWArrayOpts cleanup.
Arnold noticed during review that ArrayUserSet was not properly
updated after previous rounds of cleanup.

This also removes some innefficiency by eliminating a few hash maps.

I want to make sure this is in good shape before reusing the analysis
for immutable array properties.

Swift SVN r21608
2014-08-30 09:20:07 +00:00
Andrew Trick
ed4d8e6b71 Cleanup COWArrayOpts.
Rewrite comments and refactor.

The refactored code now handles the latest SILCombine.

Swift SVN r21547
2014-08-28 22:42:15 +00:00