Commit Graph

325 Commits

Author SHA1 Message Date
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
Arnold Schwaighofer
d77b8216ae SILLoopInfo: Add a verification method
Fix some comment styles while we are there.

This commit needs a recent version of puzzle/master llvm because I need to make
to const expose the basic block map in the LoopInfo class.

Swift SVN r19630
2014-07-07 21:05:21 +00:00
Andrew Trick
8122715df7 Teach the ColdBlocks SIL analysis to recognize the branch hint semantic model.
We're temporarily using @semantics until we have mandatory inlining of branch hints.

We now have @noinline, which helps a lot, but:
- @noinline and "cold/slow" are not the same thing.

- Some functions may need to be inlined into hot paths, but that
  doesn't mean we should also inline them into cold paths.

- It is easier to find cold blocks than to look for blocks that
  contain calls to @noinline functions. And that doesn't necessarilly
  mean the blocks are cold anyway.

Swift SVN r19455
2014-07-02 06:35:09 +00:00
Andrew Trick
53cbc3e858 Add a ColdBlockInfo analysis based on DominanceAnalysis.
This will be used by PerformanceInliner, GlobalOpt, and other passes in the future.

Swift SVN r19454
2014-07-02 06:35:09 +00:00
Michael Gottesman
7e37d3fcec [g-arc-opts] Ensure that if top down we are moving and bottom up we are eliminating (or vis-a-versa), we do nothing.
<rdar://problem/17420922>

Swift SVN r19310
2014-06-27 22:27:38 +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
Michael Gottesman
3fd80b868e [g-arc-opts] Add in a comment to a method. NFC.
Swift SVN r19261
2014-06-26 22:18:48 +00:00
Michael Gottesman
98649dada2 [global-arc-opts] It is not expected, but just in case we get more than INT_MAX BB, bail gracefully.
Swift SVN r19260
2014-06-26 22:18:44 +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
2f1a00abd3 [g-arc-opts] Now that there are actual cases where we can match up retain_value, strong_retain with release_value strong_release, enable that code path.
Previously this was an impossibility so I put in code to check for user error in
case it came up. Now that we have layout compatible reference casts, it makes
sense to add this capability to the optimizer.

Swift SVN r19073
2014-06-22 02:54:59 +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
Joe Groff
d9d451cea5 SIL: Add unchecked_{trivial,ref}_bit_cast instructions.
These instructions do a bitcast operation without stack traffic (at the SIL level). unchecked_trivial_bit_cast represents a conversion from a potentially nontrivial type to a trivial type, such as from a class reference to Int. unchecked_ref_bit_cast represents a conversion between types for which retain_value and release_value has equivalent effects when applied on the input or output values.

Swift SVN r19053
2014-06-20 22:02:38 +00:00
Michael Gottesman
6593eec533 [g-arc-opts] Implement release post-dominated by use optimization.
Currently in the ARC optimizer, we perform the double release
algorithm. The logic behind the double release algorithm is that given
the following situation:

retain(x)
call(x)
call(x)
release(x)
release(x)

The fact that we have two releases in a row on x implies that before the
first release, we know statically that the reference count of x must be
>= 2 implying we can remove the retain, release pair safely.

This optimization was tempered by the restriction that the two releases
could not have a use in between them.

While thinking about this algorithm, I realized that the key thing about
this optimization is *NOT* that I have two releases in a row. The
interesting part of the optimization is that I know the reference count
of x must be >= 2 before the first release. To ascertain that, we do not
care about having another release, all that we care about is that there
is an operation after the first release that requires x to be
alive. Since x must be alive after the first release, we know that that
release can not be the last release.

This yields a much stronger optimization since it implies that if we see
a release that is post dominated by a second release, we always know
that the first release is known safe. Thus the optimization sequence
looks like the following:

retain(x)
call(x)
call(x)
release(x)
...
use(x)

The current implementation of this algorithm is very simple and just
changes the optimizer by saying that two nested decrements causes the
first decrement to be known safe as long as there is not a retain on the
same pointer in between the two decrements. The reason why this is
important is that if we remove the second release in the ARC optimizer
then that decrement (since it is removed) can not be considered the
local use that allows us to conclude that the first is known safe.

<rdar://problem/17372698> ARC: Implement the stronger release algorithm

Swift SVN r19033
2014-06-20 05:01:03 +00:00
Manman Ren
357640494a [global-arc] treat isUniquelyReferenced as known to not decrement ref count.
This removes a pair of retain|release from MD5.hash().
rdar://17360691


Swift SVN r19024
2014-06-20 01:20:17 +00:00
Michael Gottesman
7ca1bbb3e1 [value-tracking] Teach valueMayBeCaptured that enums are only captured if their operands are captured.
Since the enum instruction is already a "transitive escape instruction",
we can just run the query on the enum's operand and value may be
captured will also make sure that the enum does not escape either.

Swift SVN r18893
2014-06-14 05:42:32 +00:00
Michael Gottesman
fd8f3b197f Add more informative DEBUG messages to valueMayBeCaptured and fix a little bit of formatting in ARCAnalysis.h. NFC.
Swift SVN r18892
2014-06-14 05:42:32 +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
Joe Groff
1f1c00cf9e SIL: Add instructions to convert metatypes to object references.
Add objc_metatype_to_object and objc_existential_metatype_to_object to convert metatypes to AnyObject, and objc_protocol to get a reference to an @objc protocol descriptor as a Protocol class instance.

Swift SVN r18824
2014-06-12 05:34:03 +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
John McCall
0f0874bb4b Add variants of the checked-cast instructions that
put the result in a different place.

WIP: no IRGen support yet.

This will eventually be the required form when casting
to an address-only type; the existing instructions will
have only scalar outputs.

Swift SVN r18780
2014-06-10 07:43:22 +00:00
John McCall
c266b15293 Cache whether a type involves an archetype in the recursive
type properties.

Swift SVN r18773
2014-06-10 01:41:00 +00:00
Michael Gottesman
c8ac91e4c7 Remove trailing whitespace that snuck in. NFC.
Swift SVN r18763
2014-06-09 23:31:35 +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
125c206d3b Move BlotMapVector -> include/swift/Basic/BlotMapVector so it can be used in SILAnalysis and SILPasses. NFC.
Swift SVN r18736
2014-06-07 22:20:26 +00:00
Michael Gottesman
a4a96fcc9f Make sure we emit SILLoop::dump even with asserts off. Just conditionally compile out its body.
Swift SVN r18732
2014-06-06 23:23:26 +00:00
Michael Gottesman
4b9af9c876 [g-arc-opts] Only perform alias queries to determine potential decrements and uses if we are a point in the dataflow lattice where such determinations can cause us to change lattice state.
With this and the previous commit, BST goes to < 10 seconds from not completing
in a reasonable amount of time.

<rdar://problem/17181185>

Swift SVN r18726
2014-06-06 03:45:36 +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
a12fb013f7 [g-arc-opts] Create a context object for the matching set computation which stores an evaluator and both state maps. This allows us to not need to recompute the reverse post order over and over again for a single function.
<rdar://problem/17181185>

Swift SVN r18724
2014-06-06 03:45:34 +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
Arnold Schwaighofer
a14aa42ce1 SILLoopInfo: Implement SIL loop info analysis using LLVM's LoopInfo
Swift SVN r18718
2014-06-05 22:25:42 +00:00
Michael Gottesman
649886b142 [g-arc-opts] Add a comment to clarify the purpose of BBToPostOrderID.
This map is just for debugging purposes to give BBs an id # that is easy to
track in the debug output.

Swift SVN r18714
2014-06-05 22:20:43 +00:00
Michael Gottesman
6db91f76c9 [g-arc-opts] swift_keepAlive does not decrement reference counts.
Swift SVN r18708
2014-06-05 05:14:17 +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
5def9ae5dc [local-arc-analysis] Teach ARC analysis about more instructions that only use pointers via users. These uses will be caught by the dataflow.
Swift SVN r18695
2014-06-03 08:58:29 +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
Michael Gottesman
208fa3658f [g-arc-opts] enum struct => enum class. NFC.
Swift SVN r18655
2014-05-28 21:05:02 +00:00
Michael Gottesman
3a07bdbcf7 [g-arc-opts] Remove #if 0 section I forgot to remove.
Swift SVN r18584
2014-05-23 03:50:54 +00:00
Michael Gottesman
ee0d677ce4 [g-arc-opts] Remove isInterestingInstruction. Its not useful or interesting.
Swift SVN r18583
2014-05-23 02:31:49 +00:00
Michael Gottesman
445c474ed0 [g-arc-opts] Wired up the Release->RetainState (TDMap), Retain->ReleaseState (BUMap) dataflow into the pair matcher analysis which matches up sets of retains, releases.
This completes the implementation of the bottom up decrement data flow
data analysis.

<rdar://problem/16965332>

Swift SVN r18580
2014-05-23 01:34:13 +00:00
Michael Gottesman
80f8b1a4ea [g-arc-opts] Extract out the dataflow from GlobalARCPairingAnalysis =>
GlobalARCSequenceDataflow. Add in the code to implement the bottom up
dataflow, but don't wire it up. Pass in the refactored top down dataflow
to the old pairing pass so we still give correct results.

The next step is to change the pairing analysis to use both the bottom
up and top down dataflow passes.

rdar://16965332

Swift SVN r18551
2014-05-22 02:17:28 +00:00
Michael Gottesman
6ddce0ad4b [g-arc-opts] Missing file from r18542.
Swift SVN r18544
2014-05-22 01:00:34 +00:00
Michael Gottesman
592c2bb265 [g-arc-opts] Move the ARC pairing and dataflow analysis into their own analysis file.
Now the actual GlobalARCOpts pass itself is complete. The rest of the
work is improving the analysis.

rdar://16965332

Swift SVN r18542
2014-05-22 00:58:34 +00:00
Michael Gottesman
fc91eb68fa [sil-aa] Remove type classifier methods from SILType.
Swift SVN r18165
2014-05-16 03:04:17 +00:00
Michael Gottesman
2c84a0ac82 [sil-aa] Typed Based TBAA with all the necessary fixes.
This commit fixes a bunch of problems I found in TBAA. Some fun
examples:

1. We were not handling protocols correctly.
2. We were not handling enums correctly.
3. We were not handling builtins correctly all the time.
...
And much more.

I also added a fairly exhaustive test.

Additionally I checked the benchmarks and did not see any regressions.

rdar://16651852

Swift SVN r18148
2014-05-16 00:21:41 +00:00