Commit Graph

325 Commits

Author SHA1 Message Date
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
Michael Gottesman
d808d6a7df [g-arc-opts] Extract out the definition of RCStateTransitionKind into a .def file.
This is apart of the work to change ARC so that all of the dataflow operations
are delegated to visitors which allow for behavior to be specialized depending
on the transformation kind. This will allow for users to add new behavior to the
ARC optimizer will minimally touching the actual dataflow.

Swift SVN r26777
2015-03-31 20:26:58 +00:00
Michael Gottesman
0edf7ef177 Fix indentation of various DEBUG(...) messages.
Swift SVN r26762
2015-03-31 16:44:38 +00:00
Erik Eckstein
160b8e07db SILPassManager: A new method to reduce the number of SIL pass runs.
It avoids that a pass runs a second time if didn't make any changes in the previous run and no other pass changed the function in between.
rdar://problem/20336764

In this change I also removed the CompleteFunctions analysis which is now obsolete.

Some measurements with swiftbench (-wmo, single threaded):
It reduces the number of pass runs by about 28%. Because only passes are skipped that don't do anything, the effect on compile time is not so dramatic.
The time spent in runSILOptimizationPasses is reduced by ~9% which gives a total compile time reduction of about 3%.




Swift SVN r26757
2015-03-31 14:19:51 +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
Michael Gottesman
9a215e078a [arc] Add support for performing a ARCUse query on a reverse range.
I am going to use this in a subsequent commit in SILCodeMotion.

Swift SVN r26670
2015-03-28 02:47:06 +00:00
John McCall
1ffb87bb1f Implement a 'throw' instruction in SIL.
Swift SVN r26668
2015-03-28 02:00:20 +00:00
Michael Gottesman
4ec67e9278 [arc] Teach ARC analysis how to determine uses of terminators rather than just bailing.
We were always treating terminators (even without arguments) as uses. This is
incorrect. With this patch we now say that a terminator can not use a ref count
pointer if all of the terminator's arguments conservatively can not alias the
pointer.

rdar://20335297

Swift SVN r26664
2015-03-28 01:38:29 +00:00
Michael Gottesman
74777a6c3a [remove-pin] Teach remove pin how to recognize a safe guaranteed array semantic call sequence.
Given a strong_pin for which we have not yet seen a strong_unpin, a safe
guaranteed call sequence is of the following form:

retain(x)
call f(@guaranteed x)
release(x)

where f is an array semantic call that we know does not touch globals and thus
are known to not change ref counts.

rdar://20305817

Swift SVN r26662
2015-03-28 00:43:47 +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
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
0ff07e9f29 Add a quick comment. NFC.
Swift SVN r26611
2015-03-26 23:05:34 +00:00
Michael Gottesman
84a444d542 [arc] Move duplicated code that uses ARCStateTransitions from {TopDown,BottomUp}RefCountState into RefCountState. NFC.
Swift SVN r26610
2015-03-26 23:02:44 +00:00
Michael Gottesman
e36661b8b5 [rc-id] Be conservative and remove the notion of ARCExitUser. This was too aggressive.
We can still ignore non-overlapping extract users.

Swift SVN r26609
2015-03-26 23:02:43 +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
Mark Lacey
dfccb5dca5 Add call graph support for an apply of a partial_apply.
We can sometimes determine exactly what we'll be calling by looking at
the callee of the partial_apply.

Nothing will directly make use of this yet, although it could perturb
the SCC ordering of the call graph.

Swift SVN r26586
2015-03-26 09:00:33 +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
Michael Gottesman
0688dbf607 [rcid] Teach RCIdentityAnalaysis::getRCUses() how to ignore certain uses that are inert from its perspective.
This includes:

1. Extract instructions which extracts a trivial part of an aggregate that has
one RCIdentity.
2. Instructions which take a pointer out of ARC's control by converting it to a
trivial type. This is safe to do since we can assume that the object that is
convered is alive when the conversion happens. So assuming that we can
conservatively find all RC users, we will have at least one RC user that
post dominates the use (since otherwise we would be touching a dangling
pointer). We leave it to the user of the pass to determine what is safe to do
with this information. Potentially in the future it might make sense to return
this information as well so that a user can use that information directly.

rdar://20305817

Swift SVN r26583
2015-03-26 07:19:41 +00:00
Roman Levenstein
f8a1aaff96 [sil-simplify] Add a peephole for XOR
Use the following equality: (x xor y) xor y == x.
With this in mind (a xor b) xor c can be replaced by:
 a - if b and c are the same
 b - if a and c are the same
 c - if a and b are the same

rdar://20280322

Swift SVN r26568
2015-03-26 00:37:08 +00:00
Michael Gottesman
254c784c94 [+0 self][pin removal] Teach pinremoval how to use RCIdentityAnalysis when removing pins.
Previously, we were being very conservative and were not trying to look through
any RCId uses. Now we understand how to look through RCIdentical instructions to
pair a pin and unpin. We also understand how to use the new getRCUses API on
RCIdentityAnalysis to get all uses of a value, looking through RCIdentical
instructions.

I also added some code to COWArrayOpts to teach it how to look through enum insts (which I needed).

Additionally I got stuck and added support for automatic indentation in Debug
statements. This is better than having to indent by hand every time.

There were no significant perf changes since this code was not being emitted by
the frontend. But without this +0 self causes COW to break.

rdar://20267677

Swift SVN r26529
2015-03-25 06:21:11 +00:00
Doug Gregor
7708c5a65e Start moving away from (Nominal)?TypeDecl::getProtocols().
Instead, use other entry points, particularly those that use the conformance lookup table.

Swift SVN r26412
2015-03-22 12:35:21 +00:00
Arnold Schwaighofer
63f4170a0e ArraySemantics: To facilitate make_unique hoisting add a array.owner call
After this change we can also hoist uniqueness checks for array of classes.

rdar://19955624

Swift SVN r26311
2015-03-19 19:32:16 +00:00
Joe Groff
fdde2a8e99 SIL: Add instructions for boxed existential operations.
Parsing and serialization for {Alloc,Open,Dealloc}ExistentialBox instructions to represent operations on ErrorType boxes.

Swift SVN r26145
2015-03-15 03:32:37 +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
Arnold Schwaighofer
513df867cf Revert "ArraySemantic: Add isMayRelease method"
This reverts commit r25925.

We cannot assume that these functions are not mayRelease because they call
Objective C functions which we must assume to be mayRelase.

Swift SVN r26107
2015-03-13 18:55:05 +00:00
Arnold Schwaighofer
7b9917bd21 Revert "ARCAnalysis: Teach it about array semantic calls that are not may-release"
This reverts commit r25926.

This is not a safe assumption to make. The array implementation does call
Objective C functions which must be assumed to be may-release.

Swift SVN r26106
2015-03-13 18:55:04 +00:00
Arnold Schwaighofer
af98fb95e2 Revert "ARCAnalysis: Teach ARC analysis about certain objective c methods that are not may-release"
This reverts commit r26082.

We cannot assume that NSArray count or objectAtIndex don't not have side effects
that are observed from Swift. We have to assume they could change an object that
is visible from Swift and therefore they are may-release.

Swift SVN r26099
2015-03-13 12:49:17 +00:00
Mark Lacey
dc7bb1a6f3 Add support for some editing of the call graph.
Specifically, addEdgesForApply() and removeEdgesForApply() allow for
clients to notify the call graph of apply instructions that are being
added or removed by the client. This allows us to avoid dangling
pointers in the maps kept in the call graph and avoid invalidating the
entire call graph at the end of passes that choose to maintain it.

Also, markCallerEdgesOfCalleesIncomplete() makes it possible to notify
all the callees of an apply that is being removed that we no longer have
complete information about all of the callers.

What this change specifically does not do is recompute the bottom-up
ordering of SCCs or functions in the call graph.

I have some incomplete updates to the inliner to use this functionality,
and it doesn't appear to be completely broken, but at this point I would
say this is experimental and could change once we have more clients
making use of it.

Swift SVN r26097
2015-03-13 08:03:15 +00:00
Mark Lacey
f6337d9688 Make call graph edge sets be SmallPtrSets rather than SmallVectors.
Re-apply r26072 with a fix to ensure that we get stable bottom-up
orderings in the call grpah.

Using SmallPtrSet here makes sense, and paves the way to more reasonable
code for editing the call graph by clients.

One unfortunate casualty of this is the ArrayRevView that was used by
one client.

Swift SVN r26093
2015-03-13 07:33:57 +00:00
Mark Lacey
89826f8d6b Remove a source of potential non-determinism in call graph construction.
Sort call graph nodes in the CalleeSet (which is a SmallPtrSet) by the
ordinal we've assigned before iterating over them.

The caller edge list will change to a SmallPtrSet soon as well, and
technically this won't be necessary at that point, but I will probably
leave the sorting in as it doesn't hurt anything and will ensure that if
we need to change data structures again we'll continue to be
deterministic.

Swift SVN r26091
2015-03-13 06:35:12 +00:00
Arnold Schwaighofer
a25b271c94 ARCAnalysis: Teach ARC analysis about certain objective c methods that are not may-release
This enables it to move retain about critical objective c method calls such as
objectAtIndex and count used by Array.

Improves DeltaBlue by 35% at -O.

radar://20147568

Swift SVN r26082
2015-03-13 02:19:54 +00:00
Arnold Schwaighofer
752c402dc2 DestructorAnalysis: Fix a spelling error
NFC.

Swift SVN r26081
2015-03-13 02:01:35 +00:00
Arnold Schwaighofer
a68f488e99 Revert "DestructorAnalysis: Don't rely on stable cannonical type pointers"
This reverts commit r26049.

Canonical types really should to be stable across the lifetime of one module.

Swift SVN r26080
2015-03-13 02:01:35 +00:00
Arnold Schwaighofer
07ef1bb68a DestructorAnalysis: Don't rely on stable cannonical type pointers
This should be NFC. Pointers to cannonical types should be stable accross
processing of a module.

Swift SVN r26049
2015-03-12 17:43:44 +00:00
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
e29b7ca52a ARCAnalysis: Teach it about array semantic calls that are not may-release
Read only array semantic functions such as "array.get_element" only have
balanced retain/release pairs in +0 self mode. Therefore, they are only a use of
the self pointer not a may-release or a guaranteed use. This means we can more
aggressively remove retain/release pairs accross such callees.

radar://20071261

Swift SVN r25926
2015-03-10 15:20:22 +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
Joe Groff
962a87f444 SIL: Rename address-only existential instructions to '{init,deinit,open}_existential_addr'.
For better consistency with other address-only instruction variants, and to open the door to new exciting existential representations (such as a refcounted boxed representation for ErrorType).

Swift SVN r25902
2015-03-09 23:55:31 +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
Mark Lacey
3c61e44b41 Support applies of witness_methods in call graph construction.
Swift SVN r25719
2015-03-03 21:06:42 +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