Commit Graph

2038 Commits

Author SHA1 Message Date
swift-ci
c911a4359f Merge pull request #17963 from gottesmm/pr-56b43cbc33e1c180f9a204470ac9c251f952788c 2018-07-15 10:32:37 -07:00
Michael Gottesman
42b26ed96f Merge pull request #17962 from gottesmm/pr-32867ca49fd7c7817ef633c1ab4042bac67051ba
[gardening] Add a missing const to a const method.
2018-07-15 09:59:24 -07:00
Michael Gottesman
7759b29a6d [gardening] Eliminate \ from macro that is < 80 lines. 2018-07-15 09:27:55 -07:00
Michael Gottesman
097e8778fc [gardening] Add a missing const to a const method. 2018-07-15 09:04:03 -07:00
Michael Gottesman
cfd177890c [gardening] Fixup a couple of doxygen comments. 2018-07-15 09:03:42 -07:00
swift-ci
ef0b91d1bc Merge pull request #17941 from gottesmm/pr-e25f39567ef78cb6f5e33ce2a73f85bc09dd55f2 2018-07-13 13:55:51 -07:00
Michael Gottesman
28d7f6a298 [caller-analysis] Eliminate NDEBUG that snuck in while I was rebasing this commit.
This broke the non-asserts bots... sorry!

rdar://42174943
2018-07-13 12:55:13 -07:00
Michael Gottesman
7167399984 [gardening] Standardize SILAnalysis.h to use consistent style.
Some parts were using the more modern style that we are using in the optimizer
that involves having ivars and local variables be camelCase instead of
CamelCase.
2018-07-13 12:51:00 -07:00
Michael Gottesman
54b3af6506 [gardening] LLVM style suggests not indenting large namespace blocks. 2018-07-13 12:51:00 -07:00
Michael Gottesman
979cb9c954 Merge pull request #17925 from gottesmm/pr-ee4013a4ba1a0f471cdc45bf15601a2c55002cdd
[caller-analysis] Change the dumping format to be a yaml format and u…
2018-07-13 08:38:09 -07:00
swift-ci
56f322f6f5 Merge pull request #17924 from gottesmm/pr-d6624e8a5116449b223f6e20308318db062511dd 2018-07-13 00:03:01 -07:00
Michael Gottesman
3051cd3f60 [caller-analysis] Change the dumping format to be a yaml format and update tests to use that format.
The current dumping format consists of 1 row of information per function. This
will become unweildy to write patterns for when I add additional state to
FunctionInfo.

Instead, this commit converts the dumping format of the caller analysis into a
multi line yaml format. This yaml format looks as follows:

  ---
  calleeName:      closure1
  hasCaller:       false
  minPartialAppliedArgs: 1
  partialAppliers:
    - partial_apply_one_arg
    - partial_apply_two_args1
  fullAppliers:
  ...

This can easily expand over time as we expand the queries that caller analysis
can answer.

As an additional advantage, there are definitely yaml parsers that can handle
multiple yaml documents in sequence in a stream. This means that by running via
sil-opt the caller-analysis-printer pass, one now will get a yaml description of
the caller analysis state, perfect and ready for analysis.
2018-07-12 22:43:23 -07:00
Michael Gottesman
dd1a201ed9 [caller-analysis] Improve memory usage of FunctionInfo structs by using small data structures instead of large.
This converts a DenseMap to a SmallMapVector and a SetVector to a
SmallSetVector. Both of these create large malloced data structures by
default. This really makes no sense when there are many functions that don't use
a partial apply or many applies.

Additionally, by changing the DenseMap to a MapVector container, this commit is
eliminating a potential source of non-determinism in the compiler since often
times we are iterating over the DenseMap to produce the results. Today all of
the usages of the DenseMap in this way are safe, but to defensively future proof
this analysis, it makes sense to use a MapVector here.
2018-07-12 22:35:09 -07:00
Slava Pestov
238928691d Merge pull request #17892 from slavapestov/unique-id-be-gone
SILOptimizer: Remove 'unique ID' from FSO mangling
2018-07-11 19:09:32 -07:00
Slava Pestov
f573b513c7 SILOptimizer: Remove unused ExistentialConformances field from ConcreteExistentialInfo 2018-07-11 15:31:38 -07:00
Slava Pestov
330be4a38e SILOptimizer: Remove 'unique ID' from FSO mangling 2018-07-11 15:29:45 -07:00
Slava Pestov
4bcf8f6320 Merge pull request #17361 from rajbarik/raj-globaladdr-refactor
Extend findInitExistential for cases when ApplySite argument is a global_addr
2018-07-11 14:18:07 -07:00
Adrian Prantl
fdad9076f2 Revert "Add debug info support for inlined and specialized generic variables."
There is an assertion failure building the source compatibility suite that
needs to be investigated.

This reverts commit 91f6f34119.
2018-07-07 13:01:01 -07:00
Adrian Prantl
91f6f34119 Add debug info support for inlined and specialized generic variables.
This patch adds SIL-level debug info support for variables whose
static type is rewritten by an optimizer transformation. When a
function is (generic-)specialized or inlined, the static types of
inlined variables my change as they are remapped into the generic
environment of the inlined call site. With this patch all inlined
SILDebugScopes that point to functions with a generic signature are
recursively rewritten to point to clones of the original function with
new unique mangled names. The new mangled names consist of the old
mangled names plus the new substituions, similar (or exactly,
respectively) to how generic specialization is handled.

On libSwiftCore.dylib (x86_64), this yields a 17% increase in unique
source vars and a ~24% increase in variables with a debug location.

rdar://problem/28859432
rdar://problem/34526036
2018-07-06 22:06:48 -07:00
Michael Gottesman
e1bb2ad0e5 [caller-analysis] Extract CallerAnalysis::FunctionInfo's definition out of line.
NFC. Just easier to read.
2018-07-04 01:06:01 -07:00
Andrew Trick
4f13dedc93 Add and enable an AccessEnforcementWMO pass.
Remove dynamic access checks for global variables and and class properties that
have been proven by earlier analysis never to conflict with nested access.

This only applies "-O -enforce-exclusivity=checked" builds. By default, it is
currently NFC.

These are the most important improvements:

RecursiveOwnedParameter                           -93.7%   **15.75x**
ReversedArray                                     -89.1%   **9.17x**
ReversedDictionary                                -81.0%   **5.28x**
ArrayInClass                                      -74.3%   **3.89x**
Ary3                                              -71.7%   **3.54x**
Random                                            -66.2%   **2.96x**
StringWalk                                        -63.5%   **2.74x**
LevenshteinDistance                               -55.4%   **2.24x**
Voronoi                                           -50.0%   **2.00x**
HashTest                                          -47.7%   **1.91x**
Richards                                          -46.7%   **1.88x**
NopDeinit                                         -44.8%   **1.81x**
Rectangles                                        -41.3%   **1.70x**
MultiFileTogether                                 -33.1%   **1.50x**
MultiFileSeparate                                 -32.8%   **1.49x**
SetIntersect_OfObjects                            -26.5%   **1.36x**
Ary2                                              -22.7%   **1.29x**
Prims                                             -21.9%   **1.28x**
PrimsSplit                                        -21.8%   **1.28x**
SetExclusiveOr_OfObjects                          -19.4%   **1.24x**
ObjectAllocation                                  -18.6%   **1.23x**
DropFirstAnySeqCRangeIterLazy                     -17.2%   **1.21x**
DropFirstAnySeqCRangeIter                         -17.2%   **1.21x**
Dictionary4OfObjects                              -16.5%   **1.20x**
SetUnion_OfObjects                                -15.3%   **1.18x**
DropWhileCountableRangeLazy                       -15.3%   **1.18x**
CharIndexing_[*]_Backwards                        -14.6%   **1.17x**
(all 17 variants of CharIndexing are -14%, 1.17x)
CharIteration_[*]_Backwards                       -14.3%   **1.17x**
(all 17 variants of CharIteration take 14%, 1.17x)
RGBHistogramOfObjects                             -14.2%   **1.17x**
DeltaBlue                                         -13.5%   **1.16x**
CharacterPropertiesPrecomputed                    -12.4%   **1.14x**
DictionarySwapOfObjects                           -9.9%    **1.11x**
ClassArrayGetter                                  -9.8%    **1.11x**
DictionaryGroupOfObjects                          -7.9%    **1.09x**
DictionaryRemoveOfObjects                         -7.2%    **1.08x**
Dictionary4OfObjectsLegacy                        -6.8%    **1.07x**
Havlak                                            -6.4%    **1.07x**
COWTree                                           -6.2%    **1.07x**
Radix2CooleyTukeyf                                -5.6%    **1.06x**
2018-06-29 17:56:56 -07:00
Andrew Trick
9d4b4c755c Rewrite SILCombiner::propagateConcreteTypeOfInitExistential. (#17315)
Fixes <rdar://40555427> [SR-7773]:
SILCombiner::propagateConcreteTypeOfInitExistential fails to full propagate type
substitutions.

Fixes <rdar://problem/40923849>
SILCombiner::propagateConcreteTypeOfInitExistential crashes on protocol
compositions.

This rewrite fixes several fundamental bugs in the SILCombiner optimization that
propagates concrete types. In particular, the pass needs to handle:

- Arguments of callee Self type in non-self position.
- Indirect and direct return values of Self type.
- Types that indirectly depend on Self within callee function signature.
- Protocol composition existentials.
- All of the above need to work for protocol extensions as well as witness methods.
- For protocol extensions, conformance lookup should be based on the existential's conformance list.

Additionally, the optimization should not depend on a SILFunction's DeclContext,
which is not serialized. (In fact, we should prevent SIL passes from using
DeclContext). Furthermore, the code needs to be expressed in a way that one can
reason about correctness and invariants.

The root cause of these bugs is that SIL passes are written based on untested
assumptions of Swift type system. A SIL pass needs to handle all verifiable SIL
input because passes need to be composable. Bail-out logic can be added to
simplify the design; however, _the bail-out logic itself cannot make any
assumptions about the language or type system_ that aren't clearly and
explicitly enforced in the SIL verifier. This is a common mistake and major
source of bugs.

I created as many unit tests as I reasonably could to prevent this code from
regressing. Creating enough unit tests to cover all corner cases that were
broken in the original code would be intractable. But the code has been
simplified such that many corner cases disappear.

This opens up some oportunity for generalizing the optimization and eliminating
special cases. However, I want this PR to be limited to fixing correctness
issues only. In the long term, it would be preferable to replace this
optimization entirely with a much more powerful general type propagation pass.
2018-06-26 19:33:31 -07:00
Michael Gottesman
07b1159be3 [gardening] Change some typedef => using. 2018-06-21 16:37:27 -07:00
Raj Barik
392469a336 Extend findInitExistential for cases with global_addr and ApplySite argument 2018-06-21 13:49:28 -07:00
swift-ci
ec732b09b1 Merge pull request #17367 from gottesmm/pr-54f11c8bd266d77cf730855fefc3d2a135669272 2018-06-20 12:26:04 -07:00
Michael Gottesman
00d95425be [erel-matcher] Do not throw away the list of releases if we do not have a joint post-dominating release set. Instead, use a flag.
I am tuning a new argument explosion heuristic to reduce code-size. One part of
the heuristic I am playing with is the part of the algorithm that attempts to
figure out if we could eliminate additonal arguments after performing
owned->guaranteed an additional release when we run FSO a second time. Today we
do this unconditionally. I am trying to do it in a more conservative way where
we only do it if we know that we aren't going to increase the number of
arguments too much.

rdar://41146023
2018-06-20 11:10:30 -07:00
Slava Pestov
e53ec62536 Merge pull request #17177 from rajbarik/raj-protoconfanal
ProtocolConformanceAnalysis
2018-06-19 14:37:01 -07:00
Raj Barik
c2aef11cff ProtocolConformanceAnalysis for a non-public protocol returns all the types (classes, structs, and enums) that conform to it. It is performed in the whole-module-compilation mode. 2018-06-18 13:38:24 -07:00
swift-ci
bd36ce12d3 Merge pull request #17234 from gottesmm/pr-0e0ac4897be5b6059f2959956c708dea2e027b88 2018-06-17 00:11:44 -07:00
Michael Gottesman
369b1f41c1 [epilogue-release-matcher] Pass DenseSet by reference instead of by value.
This is particularly egrigious since we are only /reading/ from the DenseSet. So
we are basically mallocing/copying a DenseSet just to read from it... I don't
think I need to say more.

rdar://41146023
2018-06-16 23:18:36 -07:00
Michael Gottesman
595a7dbc42 [epilogue-arc-analysis] Do not copy lists by value to read them. Use an ArrayRef instead.
I don't think I need to say more here.

rdar://41146023
2018-06-16 23:18:36 -07:00
Arnold Schwaighofer
73d3b37c94 Move RemoveUnreachable from SimplifyCFG into a utility function
The utility function will be used in a follow-up commit by a different
pass.

rdar://41139395
2018-06-15 13:52:17 -07:00
Michael Gottesman
f46de47e3f [gardening] Move private helper function decls after the public decls/fields. 2018-06-14 17:32:39 -07:00
Erik Little
863f3a19ff Rename @effects to @_effects
@effects is too low a level, and not meant for general usage outside
the standard library. Therefore it deserves to be underscored like
other such attributes.
2018-06-06 12:53:03 -04:00
Raj Barik
c277c90be6 Reorganizing the code to find init_existential; Move them to Existential.cpp/h in order for other passes such as ExistentialSpecializer to use it apart from SILCombiner 2018-06-04 11:07:12 -07:00
Michael Gottesman
7dbcdaa7a9 [simplify-cfg] The name for the pass does not have a - at the beginning.
I added a test that makes sure we can invoke this correctly. I found this when
trying to get the bug_reducer tests working again.
2018-06-03 17:51:03 -07:00
Andrew Trick
e29c2089a4 Rework AccessStorageAnalysis design. 2018-05-23 09:23:39 -07:00
Michael Gottesman
2872389826 [definite-init] Split raw SIL instruction lowering out of DI into its own pass run after DI.
I am doing this so I can start writing DI tests without this lowering occuring.
There never was a real reason for this code to be in DI beyond convenience. Now
it just makes writing tests more difficult. To prevent any test delta, I changed
all current DI tests to run this pass after DI.
2018-05-22 18:18:22 -07:00
Slava Pestov
ebb1198d57 AST: There's no longer any reason to pass SubstitutionMap by const reference
SubstitutionMaps are now just a trivial pointer-sized value, so
pass them by value instead.

I did have to move a couple of functors from Type.h to SubstitutionMap.h
to resolve some issues with forward declarations.
2018-05-19 00:45:36 -07:00
Andrew Trick
e1baf91ae1 Merge pull request #16595 from atrick/accessfold
[Exclusivity] Access Enforcement Folding Optimization
2018-05-15 13:27:52 -07:00
Andrew Trick
cb197d1e45 Enable AccessEnforcementOpts pass.
There are ~100 significant benchmark regressions (of ~350) with -O
-enforce-exclusivity=checked.

This optimization roughly cuts the overhead in half for almost all of those
regressions. These are the top 30 improvements with the optimization enabled.

XorShift....................................................2.83x
ReversedArray...............................................2.76x
RangeIterationSigned........................................2.67x
ExclusivityGlobal...........................................2.57x
Random......................................................2.44x
ReversedDictionary..........................................2.41x
GeekbenchGEMM...............................................2.35x
ArrayInClass................................................2.31x
StringWalk..................................................2.29x
Ary.........................................................2.25x
Ary3........................................................2.25x
Ary2........................................................2.21x
MultiFileTogether...........................................2.17x
MultiFileSeparate...........................................2.17x
RecursiveOwnedParameter.....................................2.14x
LevenshteinDistance.........................................2.04x
HashTest....................................................1.97x
Voronoi.....................................................1.94x
NopDeinit...................................................1.92x
Life........................................................1.89x
Richards....................................................1.84x
Rectangles..................................................1.74x
MatMul......................................................1.71x
LinkedList..................................................1.51x
GeekbenchFFT................................................1.47x
Xcbuild_OutputByteStreamPerfTests...........................1.39x
ObjectAllocation............................................1.33x
MapReduceLazyCollection.....................................1.30x
Prims.......................................................1.28x
CharIndexing_tweet_unicodeScalars_Backwards.................1.28x
2018-05-15 12:29:20 -07:00
Andrew Trick
495d5aecf6 [exclusivity] Add an access marker folding pass.
Use AccessedStorageAnalysis to find access markers with no nested conflicts.

This optimization analyzes the scope of each access to determine
whether it contains a potentially conflicting access. If not, then it
can be demoted to an instantaneous check, which still catches
conflicts on any enclosing outer scope.

This removes up to half of the runtime calls associated with
exclusivity checking.
2018-05-15 12:29:19 -07:00
swift-ci
3e3e0deaec Merge pull request #16634 from gottesmm/pr-61927cbaf34e5528bea75126c801563d0af1be0e 2018-05-15 11:06:17 -07:00
Michael Gottesman
d71d69821f [rcid] Add new method getRCUses() and reimplement getRCUsers() on top of it.
The actual algorithm used here has not changed at all so this is basically a NFC
commit. What this PR does is change the underlying algorithm to return the
operands that it computes internally rather than transforming the operand list
into the user list internally. This enables the callers of the optimization to
find the operand number related to the uses. This makes working with
instructions with multiple operands much easier since one does not need to mess
around with rederiving the operand number from the user instruction/SILValue
pair.

getRCUsers() works now by running getRCUses() internally and then maps the
operand list to the user list.

rdar://38196046
2018-05-15 10:22:23 -07:00
Raj Barik
e215abc3fa Add ExistentialToGeneric mangling and demangling code 2018-05-14 15:26:18 -07:00
Doug Gregor
8c770f956c [SILOptimizer] Remove dead swift::hasArchetypes(). 2018-05-11 17:37:26 -07:00
Doug Gregor
f2279520ed [SIL Optimizer] Eliminate some uses of SubstitutionList for debug output. 2018-05-11 13:18:06 -07:00
Doug Gregor
09446defef Eliminate yet more SubstitutionLists from SIL in search of a steady-state 2018-05-11 13:18:06 -07:00
Doug Gregor
4b5abbddbc [SIL] Teach *ApplyInst to traffic in SubstitutionMap.
Push SubstitutionMaps through most of SILGen and the SIL optimizers
that involve the various *ApplyInsts.
2018-05-11 13:18:06 -07:00
Doug Gregor
0107e93153 Merge pull request #16344 from DougGregor/sil-substitution-maps-redux
[SIL] Replace more SubstitutionLists with SubstitutionMap
2018-05-03 13:41:40 -07:00