Commit Graph

167 Commits

Author SHA1 Message Date
Michael Gottesman
e5fcbc6d59 [func-sig-opts] Add get{Known,}CallerCallSites to the CallGraph.
This returns an ArrayRefView that allows one to iterate over the CallSites of a
functions callers in a clean way.

Swift SVN r21730
2014-09-04 23:34:35 +00:00
Roman Levenstein
933e4bff17 [sil-simplify] Peepholes for (trunc (s_to_u (zext x)))->x and (trunc (u_to_s (zext (lshr x 1) Word -> Int64)) Int64 -> Word) -> (lshr x 1).
Related to rdar://17433082 and rdar://17406327

Swift SVN r21700
2014-09-04 10:27:08 +00:00
Michael Gottesman
6d1fef172a Small LLVM style fixups. NFC.
Swift SVN r21617
2014-08-31 19:59:44 +00:00
Michael Gottesman
5561b3f538 Convert Nothing_t::Nothing => Nothing.
Swift SVN r21605
2014-08-30 03:11:55 +00:00
Mark Lacey
6a695f3099 Move DeadFunctionElimination to using the new call graph.
The old call graph remains, but the new call graph can obtained by
calling getCallGraph() on the analysis pass.

I'll move the few other passes that use the call graph over soon and
then rip out the old call graph.

No diffs in the stdlib.

Swift SVN r21565
2014-08-29 05:03:31 +00:00
Mark Lacey
dc625f7c19 Minor API change in call graph.
Swift SVN r21553
2014-08-29 00:32:17 +00:00
Mark Lacey
36365d79df In the new call graph, find the SCCs in bottom-up order.
With this change we generate the SCCs in the call graph (for the kinds
of calls we currently recognize) in bottom-up, which we can then
iterate over directly or in reverse for invocation- and
reverse-invocation-order traversal of the call graph.

(This still isn't hooked up - but will be after some dumping routines
and verification of the output).

Swift SVN r21552
2014-08-29 00:32:17 +00:00
Michael Gottesman
75d8e4d748 [sil-combine] Move isZeroValue out of SILCombine and into ValueTracking.
Swift SVN r21540
2014-08-28 21:27:53 +00:00
Michael Gottesman
b617d1b6d1 [arc] Change valueHasARC*InInstructionRange to return either the offending instruction or Nothing_t::None instead of a bool.
This enables us to both check if any instructions may use or decrement a value
in an instruction range and if we find such an instruction know the furthest
where we can move the retain or release.

Swift SVN r21522
2014-08-28 08:00:44 +00:00
Andrew Trick
292d9b3bb2 Fix SILCodeMotion: do not move retains across isUniquelyReferenced.
Sinking retains will simply make the unique check useless and eliminate
Array copies even when we need them.

Fix for:
<rdar://problem/18109082> ARC: make _isUniquelyReferenced a barrier to avoid lost copies

Swift SVN r21485
2014-08-27 18:28:36 +00:00
Mark Lacey
3494d6ab39 Track call graph roots with a SmallVector rather than DenseSet.
This will allow us to search in the order the roots are added which
should improve stability of our output. There is also an ordinal on each
node that we can use to choose order of traversing edges at a given call
site.

Swift SVN r21484
2014-08-27 16:59:50 +00:00
Mark Lacey
dee10cb164 Update the new call graph so that edges have sets of call graph nodes.
Previously we tracked a set of functions that could be called from a given
call site. Now we track a set of call graph nodes (each of which
represents a callable function). As a result we now create call graph
nodes for declarations rather than just definitions.

Swift SVN r21483
2014-08-27 15:54:34 +00:00
Mark Lacey
a3350db69c Add statistics to call graph construction.
Also stub out some of the cases we'll need to handle to build a more
complete call graph.

Swift SVN r21430
2014-08-23 05:48:54 +00:00
Mark Lacey
34a1050222 Add data structures for a new, more detailed, call graph.
This is not yet hooked up. I want to add a dumper and some tests, and
need to implement code to do invocation- and reverse-invocation-ordering
over the SCCs of the call graph before it can fully replace the existing
code.

This call graph has edges for each call site, so it's really a
multigraph. Each call site tracks the set of functions that can be
called from that point. Currently that set is always a singleton since
we only handle applies of direct function_refs (like the existing call
graph). In time it will be expanded to handle other types of function
application.

Swift SVN r21407
2014-08-22 07:46:53 +00:00
Mark Lacey
7b30e832e4 Move contents of CallGraph.h into CallGraphAnalysis.h.
Swift SVN r21393
2014-08-22 00:00:04 +00:00
Mark Lacey
f1f3025838 Add call graph edges based on direct calls.
We were adding call graph edges based on seeing a function_ref. Instead,
we'll only add them now based on a direct apply of a function_ref.

Also a minor refactoring to move the code that walks the blocks and
instructions of a function into its own method.

Swift SVN r21243
2014-08-15 23:29:37 +00:00
Arnold Schwaighofer
86d43be559 IndVars: Store the increment of an induction variable
Such that we don't need to repeat part of the analysis in ABCOpts.

No functionality change.

Swift SVN r21211
2014-08-14 18:18:38 +00:00
Mark Lacey
d5a619bbad Small refactoring of call graph code.
This is a first step towards building a better call graph.

Swift SVN r21152
2014-08-12 18:20:21 +00:00
Nadav Rotem
685bb84c15 Minor cleanup. NFC.
Swift SVN r20851
2014-07-31 21:22:17 +00:00
Nadav Rotem
1b980052b1 Cache the class hierarchy construction.
Before this commit we scanned the vtables every time we wanted to know who are the subclasses of a class. Now we scan the vtables just once.



Swift SVN r20847
2014-07-31 21:07:11 +00:00
Nadav Rotem
0cb8bf0ab8 Implement polymorphic inline caches.
Swift SVN r20740
2014-07-30 07:43:47 +00:00
Nadav Rotem
898bf23738 Move the CallGraphAnalysis to a new file.
Swift SVN r20714
2014-07-29 23:18:56 +00:00
Nadav Rotem
7faa5883df Add a basic Class Hierarchy Analysis. At this point it only lists classes that are inherited from in this module.
Swift SVN r20710
2014-07-29 23:01:01 +00:00
Arnold Schwaighofer
c50e396103 Add APIs to update preserved analysis information for dominance and loop info
Use it in loop rotation.

The pattern to update analysis information is:

  // The AnalysisInfo was preserved for this function.
  if (Changed) {
    // Preserve the analyis for this function by decoupling it from the analysis
    // cache.
    auto PreservedAnalysis = Analysis.preserveAnalysis(Function);

    // Invalidate analysis for this function.
    PM.invalidateAnalysis(Function, InvalidationKind::CFG);

    // Update the preserved analysis for this function.
    Analysis.updateAnalysis(F, std::move(PreservedAnalysis));
  }

Swift SVN r19918
2014-07-14 03:42:39 +00:00
Arnold Schwaighofer
12cb97d284 PassManager: Reset state and remove all currently owned transformations
In the current setup analysis information is not reused by new pass managers.
There is no point in having different pass managers. Instead, we can just remove
transformations, reset the internal state of the pass manager, and add new
transformation passes. Analysis information can be reused.

Reuse one pass manager in the pass pipeline so that we don't have to
unnecessarily recompute analysis information.

Swift SVN r19917
2014-07-14 03:42:39 +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
7d5751594d Add in a post order analysis that lazily recomputes post orders for functions when they are invalidated.
This ensures that if we have a bunch of passes in a row which modify the CFG, we
do not continually rebuild the post order, while at the same time preserving the
property of multiple passes which do not touch the CFG sharing the same post
order, reverse post order rather than recomputing them.

rdar://17654239

Swift SVN r19913
2014-07-14 01:32:24 +00:00
Michael Gottesman
8685173e21 [arc-analysis] Add two functions for applying canUseValue and canDecrementValue to a contiguous range of instructions in the same BB.
The two functions are:

1. valueHasARCUsesInInstructionRange.
2. valueHasARCDecrementsInInstructionRange.

They operate on the range [Start, End).

I am going to use them in enum simplification and sil code motion.

Swift SVN r19893
2014-07-13 06:32:44 +00:00
Mark Lacey
652bb85f55 Remove bogus assert and tighten up induction variable determination.
There was a (commented out) assert that the entry node to each SCC we
find would be a SILArgument. This is not always the case, so I removed
the assert and added a test case that demonstrates this.

I tightened up the IV recognition code a little bit as well.

Swift SVN r19885
2014-07-13 00:12:08 +00:00
Mark Lacey
021983017a Add a SIL SCC visitor and an induction variable analysis.
The induction variable analysis derives from the SCC visitor CRTP-style
and uses it to drive analysis to find the IVs of a function.

The current definition of induction variable is very weak, but enough to
use for very basic bounds-check elimination.

This is not quite ready for real use. There is an assert that I've
commented out that is firing but should not be, and that will require
some more investigation.

Swift SVN r19845
2014-07-11 02:48:03 +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
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
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
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
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
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
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
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
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
Michael Gottesman
32dee228f8 [sil-aa] Change TBAA to use type oracle instructions instead of the raw types of instructions.
The reason that this is important is that we *ARE* allowing the stdlib
to perform certain types of type punning for efficiency implying we need
to have a type oracle instruction to have safety.

A type oracle instruction is an instruction which implies undefined behavior
unless its operand/result is of a certain type (allowing us to ignore that
possibility).

In a following commit I am going to go over and fix any problems in the
actual TBAA implementation and give all the various checks tests.

rdar://16651852

Swift SVN r18090
2014-05-15 00:59:55 +00:00
Michael Gottesman
1f93ec5480 [devirtualization] Remove deep devirtualization code that we are not using for WWDC.
If we decide in the future to do this we can always revert this commit.

Swift SVN r17293
2014-05-03 00:33:46 +00:00
Manman Ren
c2f32d7e24 [Inliner] revert r17101 since it causes a performance regression on MD5.
See rdar://16676020 for details.
r17101 tries to solve r16761933 by checking non-direct recursions in
the call graph. We are in discussion of solving it in a different way.

Todo: figure out why r17101 causes a preformance regression.


Swift SVN r17265
2014-05-02 19:00:36 +00:00
Nadav Rotem
e406e43060 Disable the inlining of non-direct recursions (where A->B->A).
Swift SVN r17101
2014-04-30 18:45:13 +00:00
Michael Gottesman
8ffc0f10a3 [sil-aa] AA::may{Read,Write,ReadOrWrite}FromMemory do not care about ref counts. Add a flag to ignore ref counts during such a query.
This is due to MayHaveSideEffects encompassing ref count effects and a
myriad of other effects. If/when we separate the two concepts (which is
cleaner IMHO), the flag will no longer be necessary.

Swift SVN r16807
2014-04-25 06:37:02 +00:00
Michael Gottesman
b04b14e0fa Refactor isNonEscapingLocalObject/getUnderlying object into their own file ValueTracking.cpp.
This is because I need them in ARCAnalysis.cpp and from a modeling
perspective it is no longer just going to be used just in AA since they
are of larger functionality.

Swift SVN r16297
2014-04-14 04:44:53 +00:00
Nadav Rotem
1bfa103362 Add a basic TBAA rule.
Swift SVN r15358
2014-03-22 01:12:09 +00:00
Nadav Rotem
e620ed323c Additional negative logic changes. NFC.
Swift SVN r14743
2014-03-06 19:10:32 +00:00
Nadav Rotem
15ec637128 Reverse the negative logic. NFC.
Swift SVN r14742
2014-03-06 19:02:42 +00:00
Michael Gottesman
0044c1d379 [arc-opts] Teach cannotDecrementRefCount how to use alias information to prove
that an apply which may decrement ref counts can not decrement a value with
reference semantics if we can prove the value does not alias any of the applies
arguments.

Swift SVN r14120
2014-02-20 01:08:49 +00:00