Commit Graph

53 Commits

Author SHA1 Message Date
Michael Gottesman
3c217614b0 [g-arc-opts] Use RCStateTransitions when processing arguments as well.
Swift SVN r26914
2015-04-02 23:24:13 +00:00
Michael Gottesman
9b77fe1cb1 [g-arc-opts] Perform same refactoring for top down analysis as I performed for bottom up analysis in r26901.
Swift SVN r26906
2015-04-02 22:07:28 +00:00
Michael Gottesman
cc02b8debe [g-arc-opts] Refactor out bottomup dataflow instruction initialization into a new visitor class BottomUpDataflowRCStateVisitor.
This allows for the state transition kind caused by an instruction to change how
we process it. It also decouples this effect from the actual CFG visiting code.

This will give us the flexibility to teach the ARC optimizer in a clean way
about many more types of instructions.

Swift SVN r26901
2015-04-02 21:16:20 +00:00
Michael Gottesman
1b157d4138 [+0 self][arc] When checking if a cond_br touches reference counts, only perform AA on the operands passed to other blocks, not the integer that is being switched upon.
Perf Results:

RIGHT - Before (ms)
LEFT - After (ms)

TITLE               LEFT         RIGHT        RIGHT/LEFT
InsertionSort       103721.00    110326.00    1.06
NSXMLParser         27031.00     29763.00     1.10

rdar://20355793

Swift SVN r26784
2015-04-01 00:48:29 +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
9816e25dd1 [arc] Add RCStateTransition.
An RCStateTransition is (you guessed it) a transition in the state
of an RCIdentity. It abstracts operations such as:

1. The introduction of a new incremented RCID by an argument (and in
the future
an @owned return value).
2. Strong increment of an RC.
3. Strong decrement of an RC.

I will use this to move pin_removal into the ARC optimizer and will
open up the ARC optimizer to being able to match up unowned values in the
future. It additionally allows me to deduplicate code from
{TopDown,BottomUp}RefCountState into RefCountState, RCStateTransition.

Swift SVN r26608
2015-03-26 22:31:39 +00:00
Michael Gottesman
7d8a24a4ee [arc] Rename RefCountState::{get,has,}Value => RefCountState::{get,has,}RCRoot().
This clarifies the purpose of these field, methods.

Swift SVN r26607
2015-03-26 22:31:39 +00:00
Michael Gottesman
7eb49d6941 [arc] Move ARCBBState into its own file. This leaves just the actual sequence dataflow in GlobalARCSequenceDataflow, nothing else. NFC.
Swift SVN r26606
2015-03-26 22:31:38 +00:00
Michael Gottesman
9e692a5304 Fix format mistakes that snuck in (Sorry!).
Swift SVN r26605
2015-03-26 22:31:38 +00:00
Michael Gottesman
52ec89a4ad [arc] Refactor out all BBState management from the evaluator into an ARCBBStateInfo class in GlobalARCSequenceDataflow.cpp. NFC.
This lets me hide a bunch of state in GlobalARCSequenceDataflow.h.

Swift SVN r26588
2015-03-26 10:40:52 +00:00
Michael Gottesman
876ad89f30 [arc] Move RefCountState's implementation into its own file. NFC.
ALso renamed the header ReferenceCountState.h => RefCountState.h since it
matches the name of the class now.

Swift SVN r26587
2015-03-26 09:17:50 +00:00
Michael Gottesman
a134e3ffee Remove preallocated map. NFC.
This was an experiment that did not work out.

Swift SVN r26584
2015-03-26 08:46:50 +00:00
Chris Lattner
4f708c049b fix const correctness and standardize on names for the successor list of
TerminatorInsts.  Now you can walk over the successor list of a terminator
and actually modify the SILSuccessor directly, allowing better CFG
transformations.  NFC.




Swift SVN r26140
2015-03-14 17:52:27 +00:00
Michael Gottesman
3b5e703d68 [g-arc-opts] Teach the ARC Optimizer how to understand @guaranteed parameters directly.
Swift SVN r24602
2015-01-21 14:52:37 +00:00
Michael Gottesman
6ae6b83090 [g-arc-opts] Fix up stale comments. NFC.
Swift SVN r24577
2015-01-20 23:39:34 +00:00
Michael Gottesman
39817d5fd8 Remove arc namespace.
Swift SVN r24500
2015-01-19 00:10:48 +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
Michael Gottesman
7a2e1fb4d3 [arc-opts] After the arc optimizer converges, run another round of the ARC
optimizer freezing releases in the epilogue of functions that match to
SILArguments. This allows us to treat all such SILArguments throughout the
entire function as having a post dominating release.

<rdar://problem/18923030>

Swift SVN r23253
2014-11-11 23:37:09 +00:00
Michael Gottesman
f541019660 [codemotion] Extract out isARCInertTrapBB into ARCAnalysis from GARCOpts and teach SILCodeMotion to use it to not move retains into trap bbs.
This reduces the number of retains, releases in the stdlib by another 5% to
15167.

rdar://18328074

Swift SVN r21936
2014-09-13 03:15:29 +00:00
Michael Gottesman
1bfdd9e3bf [g-arc-opts] Teach the arc optimizer how to recognize more trap BBs in the stdlib.
This reduces the number of retain, release operations in the dylib from 38512 to
16041. That is a reduction of 60%. Most of the code paths affected by this were
in the cocoa part of the stdlib so when I measured the perf test suite I did not
see a huge boost in perf.

rdar://18327670

Swift SVN r21934
2014-09-13 01:42:24 +00:00
Michael Gottesman
4609513593 Remove SILValue::stripRCIdentityPreservingArgs and teach all uses of that method to use the new RCIdentityAnalysis.
Currently, the pass just calls a local version of that function. After OzU, I
will enable the full pass (which is currently disabled behind a flag).

Swift SVN r21894
2014-09-11 22:29:31 +00:00
Michael Gottesman
3624daaacd Change matchCondFail => matchNoSideEffectUnreachableBB and expand it to match any literals. This can be expanded over time.
Swift SVN r21358
2014-08-21 16:16:13 +00:00
Michael Gottesman
7c9b29a214 Remove stray APInt.
Swift SVN r21337
2014-08-21 03:46:27 +00:00
Arnold Schwaighofer
d32bda428f ARC: Ignore more failing blocks
Adds an ignore pattern for cond_fail unreachable blocks. These can happen
because of code that does a preconditionFailure on a branch.

 if cond {
   preconditionFailure("Must not happen")
 }

No performance impact measure on the perf test suite.

Swift SVN r21334
2014-08-21 03:32:10 +00:00
Michael Gottesman
56d51ca9f1 [g-arc-opts] Teach the ARC optimizer how to strip off ref count equivalent operations such as casts and ref count identity preserving typed geps.
Now that the ARC optimizer does not rely on stripCasts I also added
unchecked_trivial_bit_cast to stripCasts.

This and r21164 give the following speedups > 10%:

Ary      55.95%
MatMul   36.71%
Ary2     34.97%
Richard  32.08%
PrimeNum 15.87%

<rdar://problem/17456455>

Swift SVN r21240
2014-08-15 22:47:57 +00:00
Mark Lacey
ab3e8aac22 Make SILValue::stripCasts see through UncheckedRefBitCastInst.
The ARC optimizer had a wrapper that handled this, but other uses of
SILValue::stripCasts could benefit as well.

Swift SVN r21153
2014-08-12 19:00:45 +00:00
Michael Gottesman
764237d226 [g-arc-opts] Cleanup dataflow merging in the ARC optimizer so we do not prematurely clear values due to spurious merge failures.
Swift SVN r21113
2014-08-08 19:35:53 +00:00
Michael Gottesman
ad9097805d [g-arc-opts] Clear Partial when we clear and make sure we propagate partial into successors and predecessors if "Other" has the partial property.
This was noticed on inspection and I can't seem to come up with a good test case
for it. = /.

Swift SVN r20787
2014-07-30 23:20:26 +00:00
Michael Gottesman
564564d81a [g-arc-opts] Change RefCountState::getValue() to assert if Value is
NULL, add a method RefCountState::hasValue() for that query and update
logging to use hasValue() before calling getValue().

Swift SVN r20784
2014-07-30 22:47:40 +00:00
Michael Gottesman
5f98995c6c [g-arc-opts] Invert dependency in between RefCountState and its subclasses in clear() and call the subclass clear instead of the superclass clear.
Otherwise, we do not clear subclass specific state when we clear which can
potentially cause inconsistencies.

Swift SVN r20779
2014-07-30 21:47:31 +00:00
Pete Cooper
92500d331a Update some debug printing in ARC
Swift SVN r20058
2014-07-16 23:23:47 +00:00
Michael Gottesman
aa7f8f46d6 [g-arc-opts] Perform sanity check that we do not merge Argument paths with non-Argument tracking paths correctly.
This was a sanity check that I through in that makes sure that we do not
try to merge together an @owned argument we are tracking with an
instruction.

rdar://17634697



Swift SVN r19967
2014-07-15 01:55:19 +00:00
Joe Groff
45eec9a2e9 Remove 'interface' from the method names of SILFunctionType.
SILFunctionTypes are always interface types now. NFC.

Swift SVN r19952
2014-07-14 22:03:46 +00:00
Michael Gottesman
e998695670 [g-arc-opts] Refactor global arc opts to use the PostOrderAnalysis.
Swift SVN r19915
2014-07-14 01:32:27 +00:00
Michael Gottesman
0ac42332d0 Remove PreallocatedMap::operator[]. Change PreallocatedMap::find to return .end() if the map is not sorted in release builds.
I put in an assert for debug builds so we will be able to catch this.

Swift SVN r19908
2014-07-13 22:26:46 +00:00
Michael Gottesman
13f702852a [g-arc-opts] Skip unreachable BB that are predecessors of reachable BBs when merging predecessor state.
This will be cleaned up for sure at the LLVM level if we do not reach it
at the SIL level implying that this is safe.

<rdar://problem/17419974>

Swift SVN r19262
2014-06-26 22:18:49 +00:00
Manman Ren
dd974edb3e Update mismatching debug message.
Swift SVN r19095
2014-06-23 18:58:49 +00:00
Michael Gottesman
a0027162a6 Fix typo.
Swift SVN r19080
2014-06-22 19:19:44 +00:00
Michael Gottesman
067fee495b [g-arc-opts] Teach the global ARC optimizer to strip off unchecked_ref_bitcast_inst when determining pointer identity.
Swift SVN r19072
2014-06-22 02:43:26 +00:00
Michael Gottesman
2bf652fcb9 [g-arc-opts] Allow removing of increment, decrement pairs after seeing partial merges, ensuring that we still will not move them.
This enables us to handle significantly crazier control flow without
needing to worry about control dependency issues relating to different
groups of insertion points potentially not being control dependent which
can cause incorrect behavior in the optimizer.

Swift SVN r18861
2014-06-13 06:37:40 +00:00
Michael Gottesman
4b8a8efbef [g-arc-opts] Move all global arc optimizations under the same debug flag.
I wish we had the ability to specify a log grouping, so I could log all
of ARC opts or just a specific part of it. Sadly we don't have that now
so I am going to centralize them under the same flag.

Swift SVN r18820
2014-06-12 01:33:18 +00:00
Michael Gottesman
509bbe53be [g-arc-opts] Ignore trap BB during Sequence Dataflow.
These trap BBs are pattern matched very strictly, i.e. only BBs of the
following form are matched:

bbN:
  %_ = builtin_function_ref "int_trap"
  apply %_
  unreachable

Such BBs can be ignored safely for ARC purposes. This allows us to
handle -O3 code in the ARC optimizer significantly more effectively by
enabling us to handle many more types of check failures.

For instance we can now remove retains, releases in the following code:

bb0:
  strong_retain %0
  cond_br _, bb1, bb2

bb1:
  strong_release %0
  ...

bb2:
  %_ = builtin_function_ref "int_trap"
  apply %_
  unreachable

rdar://17212610

Swift SVN r18817
2014-06-12 00:43:11 +00:00
Michael Gottesman
59c89e56ce [g-arc-opts] Change Global ARC Sequence Dataflow to use PreallocatedMap.
This will speed up the optimizer by reducing the amount of allocations
we perform while running the optimizer.

Swift SVN r18762
2014-06-09 23:09:04 +00:00
Michael Gottesman
bf47d48831 [g-arc-opts] Hoist out F.size() and enable BB numbering only if asserts (i.e. logging) is enabled.
<rdar://problem/17181185>

Swift SVN r18725
2014-06-06 03:45:35 +00:00
Michael Gottesman
e9061373f7 [g-arc-opts] Remove old entry point to the sequence dataflow. Now this is run via the evaluator class.
Swift SVN r18723
2014-06-06 03:45:32 +00:00
Michael Gottesman
c2b2e52260 [g-arc-opts] Implement the merge functions to complete Stage 2 of global arc opts.
Also fixed a small bug related to how we handle arguments. We were not
clearing the state of the argument when we saw a potential decrement of
the argument.

<rdar://problem/17013194>

Swift SVN r18706
2014-06-05 04:35:14 +00:00
Michael Gottesman
44734294d6 [g-arc-opts] Add support for printing out LatticeState enum class elts.
Swift SVN r18699
2014-06-04 04:44:40 +00:00
Michael Gottesman
5b3e77e622 [g-arc-opts] Implement the traversal of the RPOT, POT, forgetting all tracked instructions at loop boundaries.
<rdar://problem/17013194>

Swift SVN r18692
2014-06-01 23:03:52 +00:00
Michael Gottesman
25803adbb4 [g-arc-opts] Refactor ARCBBState from GlobalARCSequenceDataflow.cpp -> *.h.
Swift SVN r18690
2014-06-01 22:22:24 +00:00
Michael Gottesman
483ba706be [g-arc-opts] Change ReferenceCountState to work on sets of instructions
instead of just individual instructions.

Swift SVN r18689
2014-06-01 22:22:23 +00:00