Commit Graph

167 Commits

Author SHA1 Message Date
Arnold Schwaighofer
165bfb6f95 DestructorAnalysis: Fix for recursive types
We can't just recursively process types without caching. Instead mark a type as
safe before we recurse and reset this assumption if we proved otherwise on the
recursive traversal.

rdar://20132313

Swift SVN r26048
2015-03-12 17:14:25 +00:00
Arnold Schwaighofer
fab9212e45 ArraySemantic: Add isMayRelease method
Returns whether this array semantic call has a neutral effect on reference
counts.

Swift SVN r25925
2015-03-10 15:20:21 +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
Michael Gottesman
ef94fa0001 [callgraph] Change a bunch of llvm::SmallVectorImpl => ArrayRef. This hides the unnecessary information that the CallGraph internally uses SmallVectors.
Swift SVN r25838
2015-03-07 04:47:45 +00:00
Michael Gottesman
0aee8f9521 [callgraph] Centralize the calling of destructors in the CallGraph of CallGraphState.
Previously this was scattered in various places . Now we have a simple model that
all CallGraphEdges, CallGraphNodes, and CallGraphSCCs are owned by the CallGraph
since they are allocated by the CallGraph's BumpPtrAllocator.

This additionally fixes a problem where we were calling delete on SCC's owned by
the BumpPtrAllocator.

Swift SVN r25522
2015-02-25 00:41:14 +00:00
Michael Gottesman
114345b773 [callgraph] Add basic verification of the callgraph.
This is currently disabled by default since this verification trips on
ToT when I checked a few days ago.

The current checks that are performed are:

1. For every (SILFunction, CallGraphNode) pair FuncPair in the SILFunction to
   CallGraphNode map check that:
   a. FuncPair.first is a SILFunction in the current module.
   b. FuncPair.first is the SILFunction inside the CallGraphNode FuncPair.second.
   c. All CallGraphEdges mapped to FuncPair.second have ApplyInsts which are in
      the SILFunction FuncPair.first.

2. For every pair (ApplyInst, CallGraphEdge) ApplyPair in the Apply to
   CallGraphEdge map, check that:
   a. ApplyPair.second.getCallSite() == ApplyPair.first.
   b. ApplyPair.first->getFunction() is in the SILFunction to
      CallGraphNode map and the CallGraphEdge for ApplyPair is one of
      CallSiteEdges in the mapped to CallGraphNode.

<rdar://problem/19944399>

Swift SVN r25520
2015-02-24 23:55:21 +00:00
Michael Gottesman
cf27691098 [callgraph] Add a map from Apply -> CallGraphEdge.
This makes it easy to use the callgraph to determine what the Apply
actually calls instead of attempting to ascertain it in an adhoc
manner. This allows for the call graph analysis to be used as the one
point of truth for determing what an apply inst can call.

Swift SVN r25516
2015-02-24 22:49:47 +00:00
Michael Gottesman
28cde0e785 [callgraph] Use one bump ptr alloctor for all memory allocated in the callgraph.
I also did some small llvm style fixes.

Swift SVN r25515
2015-02-24 22:49:47 +00:00
Michael Gottesman
4a34f25c6b Add support for verifying analyses when -sil-verify-all is passed in.
Currently no passes implement this, but I am going to add support to the
callgraph. I just ran into a callgraph bug that this would have helped
to catch.

rdar://19930214

Swift SVN r25514
2015-02-24 22:49:46 +00:00
Mark Lacey
64af0798df Rename members and interfaces of the call graph for clarity.
Small clean-up to try to improve on the clarity of the call graph code.

I think this is an overall improvement although there is still some
clunky naming that could be improved in the future.

Swift SVN r25492
2015-02-24 00:08:19 +00:00
Mark Lacey
f92d70ec6c Use arena allocation in the call graph builder.
Shave a little more time off the call graph construction.

Thanks go to Erik for the suggestion.

Swift SVN r25439
2015-02-20 22:41:55 +00:00
Erik Eckstein
44fed755cc Use SmallPtrSet instead of DenseSet in CallGraphEdge
The memory allocation of DenseSet had a significant contribution to the compile time.
This change reduces the time of runSILOptimizationPasses by ~25% in a stdlib build => ~2s faster.



Swift SVN r25373
2015-02-18 18:01:21 +00:00
Michael Gottesman
4cb9eb72f4 [rc-id] Ensure that the reforming enum analysis properly handles no-payload incoming values.
One common problem in swift code is the "reforming enum problem". What
happens here is that we have some enum %0 : $Optional<T> and we break it
apart and reform it as a new enum as in the following:

   bb9:
     ...
     switch_enum %0 : $Optional<T>, #Optional.None: bb10,
                                    #Optional.Some: bb11

   bb10:
     %1 = enum $Optional<U>, #Optional.None
     br bb12(%1 : $Optional<U>)

   bb11:
     %2 = some_cast_to_u %0 : ...
     %3 = enum $Optional<U>, #Optional.Some, %2 : $U
     br bb12(%3 : $Optional<U>)

   bb12(%4 : $Optional<U>):
     retain_value %0 : $Optional<T> // id %5
     release_value %4 : $Optional<U> // id %6

We really would like to know that a retain on %4 is equivalent to a
retain on %0 so we can eliminate the retain, release pair. To be able to
do that safely, we need to know that along all paths %0 and %4 either:

1. Both refer to the same RCIdentity directly. An example of this is the
edge from bb11 -> bb12).
2. Both refer to the "null" RCIdentity (i.e. do not have a payload). An
example of this is the edge from bb10 -> bb12.

Only in such cases is it safe to match up %5, %6 and eliminate them. If
this is not true along all paths like in the following:

   bb9:
     ...
     cond_br %foo, bb10, bb11

   bb10:
     %1 = enum $Optional<U>, #Optional.None
     br bb12(%1 : $Optional<U>)

   bb11:
     %2 = some_cast_to_u %0 : ...
     %3 = enum $Optional<U>, #Optional.Some, %2 : $U
     br bb12(%3 : $Optional<U>)

   bb12(%4 : $Optional<U>):
     retain_value %0 : $Optional<T> // id %5
     release_value %4 : $Optional<U> // id %6

then we may have that %0 is always non-payloaded coming into bb12. Then
by matching up %0 and %4, if we go from bb9 -> bb11, we will lose a
retain.

Perf Changes:

TITLE..................OLD...........NEW...........NEW/OLD
LevenshteinDistance....1398195.00....1177397.00....0.84
Memset.................26541.00......23701.00......0.89
CaptureProp............5603.00.......5031.00.......0.90
ImageProc..............1281.00.......1196.00.......0.93
InsertionSort..........109828.00.....104129.00.....0.95
StringWalk.............6813.00.......7456.00.......1.09
Chars..................27182.00......30443.00......1.12

The StringWalk, Chars are both reproducible for me. When I turn back on parts of
the recursion (I took the recursion out to make this change more conservative),
the Chars regression goes away, but the StringWalk stays. I have not had a
chance to look at what is going on with StringWalk.

rdar://19724405

Swift SVN r25339
2015-02-17 01:30:19 +00:00
Doug Gregor
4977f7027c Stop using LLVM_DELETED_FUNCTION.
It's gone from LLVM now, and we always build as C++11.

Swift SVN r25313
2015-02-16 17:39:04 +00:00
Michael Gottesman
841aa449cf [cfg] Add a new analysis findAllNonFailureExitBBs.
Even though there is only one "return" from a SILFunction, there may be multiple
non-failure exits via no return functions. findAllNonFailureExitBBs

The verifier currently enforces that all no-return function applications must be
immediately followed by an unreachable. Thus to identify all such functions, we
must just visit all unreachables and visit the previous instruction of the
unreachable. If we don't have an apply in such case, then we must be in a
failure code path.

This code attempts to identify all ways of exiting a function in a non-failure
code path. Thus it places into the result vector the return from the BB and all
no-return function applications that it can not identify as a "failure"
function. The function ignores any paths that it identifies as failure paths.

Failure functions will be identified in the future via an @semantic tag but for
now we just check for functions with the appropriate "fatal error" suffix as we
do in the ARC optimizer.

I am going to use this in the closure specializer to insert releases for
"copied" closures that were originally passed in @guaranteed. Since the closure
was passed in originally @guaranteed there will be no matching -1 unless we
insert it ourselves.

Swift SVN r25051
2015-02-06 21:59:53 +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
Michael Gottesman
07acb16da8 [arc-analysis] Add a helper routine getFinalReleasesForValue that determines for a value a set of post-dominating live releases.
This is refactored code from AllocBoxToStack with some small forward
looking changes. The user passes in a ReleaseTracker object that via a
closure decides what users are acceptable. I am going to use this in
closure specialization to remove dead closures.

The main limitation currently is that the code:

1. Assumes that the user deals with any issues relating to whether or
not the value is local.
2. Only visits the direct users of the value instead of visiting the
users recursively. This is safe for my uses now since I will only accept
users that are retains or releases. These have no uses.

The reason why I am leaving in these limitations is I am trying to limit
the amount of changes to the code.

Swift SVN r25048
2015-02-06 21:59:51 +00:00
Michael Gottesman
a83b00b3c7 [value-tracking] Add an API to value tracking for determining dead closures.
I am going to use this in closure specialization to remove dead closures. We
should refactor the SILCombine dead closure removal to use this code path as
well.

Additionally, we should change the valueMayBeCaptured infrastructure to take a
struct like we do in LLVM so we can ignore casts and other things like that
additionally by injecting the logic to do so via the struct.

But that is for another day.

Swift SVN r25007
2015-02-05 19:11:35 +00:00
Andrew Trick
6f19952379 Fixup some comment grammar.
Swift SVN r24907
2015-02-02 23:19:29 +00:00
Mark Lacey
9afc924fdf Cast away constness in client, not in call graph code.
Swift SVN r24789
2015-01-28 05:57:08 +00:00
Mark Lacey
f8d9f73777 Refactor call graph to share common code for different kinds of applies.
Swift SVN r24764
2015-01-28 00:37:38 +00:00
Mark Lacey
9be5c4aa71 Minor update to call graph interface.
Provide only a single way to create a call graph edge, and make the
client explicitly inform us whether the callee set is complete.

Swift SVN r24763
2015-01-28 00:37:38 +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
38a0c69fc1 Rename some arc routines to use may instead of can as a prefix to match AliasAnalysis more closely.
Swift SVN r24509
2015-01-19 10:03:06 +00:00
Michael Gottesman
39817d5fd8 Remove arc namespace.
Swift SVN r24500
2015-01-19 00:10:48 +00:00
Arnold Schwaighofer
8d0ddb8a65 Analysis: InvalidationKind clarify comment
Swift SVN r24261
2015-01-08 03:11:17 +00:00
Michael Gottesman
3639691de2 Now that SmallMapVector is in llvm trunk... use it!
Swift SVN r24170
2015-01-04 22:50:11 +00:00
Michael Gottesman
2150ca257b Add a range type to PostOrderAnalysis for use with the post order and reverse post order ranges. This makes it cleaner if one needs to refer to the actual type returned by the post order and reverse post order calls.
Swift SVN r24165
2015-01-01 14:34:50 +00:00
Erik Eckstein
cf0030b587 Make isSlowPath() a public member of ColdBlockInfo.
Swift SVN r24108
2014-12-23 09:11:57 +00:00
Michael Gottesman
a4318845cc Add in a few comments. NFC.
Swift SVN r23717
2014-12-05 02:08:38 +00:00
Michael Gottesman
8eb9ad4591 Change file to fit LLVM coding standard. NFC.
Swift SVN r23716
2014-12-05 02:08:37 +00:00
Michael Gottesman
ebfcc123a3 [callgraph] Teach the callgraph how to determine for simple cases if we have a complete caller set.
We specifically only handle cases of functions that are not visible externally
and for whom all function_refs to the function only have apply inst users.

<rdar://problem/19137435>

Swift SVN r23714
2014-12-05 02:08:36 +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
Arnold Schwaighofer
06a0a23562 Add a destructor memory effect analysis
This adds an analysis to the compiler that identifies types that are may store
to memory on destruction.

It adds a compiler known protocol _DestructorSafeContainer that allows the
standard library to identify containers whose destructor's memory effects
depends strictly on the type parameters of the container.

Array<T> : _DestructorSafeContainer {} may not store to memory during
destruction if the bound T is a type that does not store to memory on
destruction.

This is needed to deduce that for example Array<Array<Int>> is does not store to
memory on destruction (e.g during a call to release).

rdar://18940376

Swift SVN r23242
2014-11-11 19:27:41 +00:00
Michael Gottesman
3d396f8b12 [arc-analysis] Refactor OwnedArgToEpilogueReleaseMatcher from FunctionSigOpts.
Given a function F, this utility class attempts to match up owned arguments with
releases in the epilogue of the function.

I am refactoring this from FunctionSigOpts so I can use it in the ARC optimizer.

<rdar://problem/18923030>

Swift SVN r23219
2014-11-11 00:42:30 +00:00
Michael Gottesman
7b34373bf4 [aa] Add PartialAlias. This currently is not returned by any routine or used anywhere.
rdar://18831605

Swift SVN r23059
2014-11-02 00:41:12 +00:00
Michael Gottesman
a014c65205 Expose canInstUseRefCountValues as swift::canNeverUseValues.
canInstUseRefCountValues should have always been named
canInstNotUseRefCountValues. I don't remember how it get renamed as such. Even
though it is a little weird to have a "canNever" in a function name, it makes
sense here to contrast it with canUseValue which returns if a specific user can
use a ptr in a way that requires the ptr to be alive. This in contrast says that
a user can never use a ptr in a manner where the ptr must be alive. I.e. this is
a universal quantifier.

Swift SVN r22961
2014-10-27 09:15:57 +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
Mark Lacey
445afdc031 Delete the old call graph code.
Swift SVN r22598
2014-10-08 07:47:32 +00:00
Roman Levenstein
5e91fd3a62 Extend ClassHierarchyAnalysis to provide information about indirect subclasses. This is used e.g. by the upcoming devirtualizer changes.
Swift SVN r22521
2014-10-04 09:49:47 +00:00
Jordan Rose
3fcdfd40e9 Remove the "swift/Basic/Optional.h" header.
llvm::Optional lives in "llvm/ADT/Optional.h". Like Clang, we can get
Optional in the 'swift' namespace by including "swift/Basic/LLVM.h".

We're now fully switched over to llvm::Optional!

Swift SVN r22477
2014-10-02 18:51:45 +00:00
Jordan Rose
042569a3be Optional: Replace uses of Nothing with None.
llvm::Optional (like Swift.Optional!) uses None as its placeholder value,
not Nothing.

Swift SVN r22476
2014-10-02 18:51:42 +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
04d9f968fd [rc-id] Make sure when stripping off arguments that the resulting stripped value dominates the argument.
This is important since to be more aggressive we are ignoring incoming values
that are no-payload enums since as far as we are concerned they do not matter
since retains, releases on those values are no-ops.

Swift SVN r21932
2014-09-12 22:21:06 +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
4647eb9601 Create RCIdentityAnalysis a cache for stripRCIdentityPreservingOps.
The cache is needed to ensure we do not run into compile time problems once we
start looking through Phi Nodes.

The analysis is currently disabled and just returns
SILValue::stripRCIdentityPreservingOps. I am going to thread it through the rest
of the passes that use that call. Then I am going to hide
stripRCIdentityPreservingArgs. Finally post OzU, I am going to enable the pass.

rdar://18300069

Swift SVN r21891
2014-09-11 21:51:29 +00:00
Roman Levenstein
a81a99776f Improve optimization of builtin operations that may overflow. Remove overflow checks if it can be proven that no overflow can happen.
Swift SVN r21874
2014-09-11 16:00:54 +00:00
Michael Gottesman
3275fc669d LLVM_DELETED_FUNCTION => = delete. NFC.
Swift SVN r21867
2014-09-11 05:41:12 +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
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