Commit Graph

263 Commits

Author SHA1 Message Date
Andrew Trick
e400b66897 Cleanup replaceAllUsesAndErase, return an iterator, allow erase handlers.
This will make the forthcoming CanonicalizeInstruction interface more
clear.

This is generally the better approach to utilities that mutate the
instruction stream. It avoids the temptation to assume that only a
single instruction will be deleted or that only instructions before
the current iterator will be deleted. This often happens to work but
eventually fails in the presense of debug and end-of-scope
instructions.

A function returning an iterator has a more clear contract than one
accepting some iterator reference of unknown
providence. Unfortunately, it doesn't work at the lowest level of
utilities, such as recursivelyDeleteTriviallyDeadInstructions, where
we want to handle instruction batches.
2019-05-06 08:36:56 -07:00
Slava Pestov
16d5716e71 SIL: Use the best resilience expansion when lowering types
This is a large patch; I couldn't split it up further while still
keeping things working. There are four things being changed at
once here:

- Places that call SILType::isAddressOnly()/isLoadable() now call
  the SILFunction overload and not the SILModule one.

- SILFunction's overloads of getTypeLowering() and getLoweredType()
  now pass the function's resilience expansion down, instead of
  hardcoding ResilienceExpansion::Minimal.

- Various other places with '// FIXME: Expansion' now use a better
  resilience expansion.

- A few tests were updated to reflect SILGen's improved code
  generation, and some new tests are added to cover more code paths
  that previously were uncovered and only manifested themselves as
  standard library build failures while I was working on this change.
2019-04-26 22:47:59 -04:00
Andrew Trick
dfc2d47f3b Redo the data flow part of AccessEnforcementOpts.
Directly implement the data flow. Eliminate the extraneous work.
Remove cubic behavior. Do a single iteration of the data flow state at
each program point only performing the necessary set operations. At
unidentified access, clear the sets for simplicity and efficiency.

This cleanup results in significant functional changes:

- Allowing scopes to merge even if they are enclosed.

- Handling unidentified access conservatively.

Note that most of the added lines of code are comments.

Somehow this cleanup incidentally fixes:
<rdar://problem/48514339> swift compiler hangs building project

(I expected the subsequent loop summary cleanup to fix that problem.)
2019-03-18 12:42:53 -07:00
Andrew Trick
72a9190258 Expose AccessedStorageAnalysis as a utility.
The previous design was customized to perfoming IPO with
GenericSideEffectAnalysis. Expose the underlying logic as a utility so
that AccessEnforcementOpts can use it to summarize loops (in addition
to call sites).
2019-03-18 12:42:53 -07:00
Andrew Trick
bc884d4ba8 Merge pull request #20977 from rajbarik/raj-extend-existential2generic
Perform ExistentialSpecializer when SoleConformingType is known
2019-01-14 18:23:19 -08:00
Andrew Trick
5b424694c5 Reduce compile time for large strongly connected call graphs.
Improves SwiftSyntax release build speed by 4x.

Limit the size of the sets tracked by inter procedural
AccessedStorageAnalysis. There is a lot of leeway in this limit since
"normal" code doesn't come close to hitting it and SwiftSyntax compile
time isn't noticeably affected until 10x this limit.

This change also avoids reanalyzing function bodies once results have
bottomed out and avoids copying sets in the common case.

Fixes <rdar://problem/46905624> Release build time regression, a lot of time spent on AccessEnforcementOpts::run().

This is just a band aid. The fundamental problem is really:
<rdar://problem/47195282> Recomputing BottomUpIPAnalysis takes most of
the SwiftSyntax compile time.

SwiftSyntax compile time is still at least an order of magnitude
longer than it should be.
2019-01-10 16:31:08 -08:00
Raj Barik
0070730e5a Perform ExistentialSpecializer when SoleConformingType is known 2019-01-07 14:47:39 -08:00
Adrian Prantl
ff63eaea6f Remove \brief commands from doxygen comments.
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

      for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
2018-12-04 15:45:04 -08:00
Andrew Trick
5983aae176 Fix AccessEnforcementReleaseSinking. Check for illegal cases.
In the included, test case, the optimization was sinking
releases past is_escaping_closure.

Rewrite the isBarrier logic to be conservative and define the
mayCheckRefCount property in SIL/InstructionUtils. Properties that may
need to be updated when SIL changes belong there.

Note that it is particularly bad behavior if the presence of access
markers in the code cause miscompiles unrelated to access enforcement.

Fixes <rdar://problem/45846920> TestFoundation, TestProcess, closure
argument passed as @noescape to Objective-C has escaped.
2018-11-06 13:52:03 -08:00
Saleem Abdulrasool
813f712ad5 adjust declarations of DenseMapInfo for GCC
Remove the extra qualification and place explicitly in the LLVM
namespace.  This fixes some build issues with GCC 8.2.
2018-10-23 08:29:13 -07:00
Erik Eckstein
15b01ab792 SIL: Remove array.owner semantic function
Also remove the getOwner functions from ArraySlide.
These functions are not needed anymore with accessors.

rdar://problem/44184810
2018-10-15 09:44:52 -07:00
Graydon Hoare
cc16ddfd13 Revert "[SILOptimizer] Don't diagnose infinite recursion if a branch terminates (#19724)"
This reverts commit e94450e840.

rdar://45080912
2018-10-07 23:54:33 -07:00
Harlan
e94450e840 [SILOptimizer] Don't diagnose infinite recursion if a branch terminates (#19724)
This patch augments the infinite recursion checker to not warn if a
branch terminates, but still warns if a branch calls into something with
`@_semantics("arc.programtermination_point")`. This way, calling `fatalError`
doesn't disqualify you for the diagnostic, but calling `exit` does.

This also removes the warning workaround in the standard library, and
annotates the internal _assertionFailure functions as
`programtermination_point`s, so they get this treatment too.
2018-10-05 19:15:26 -07:00
Michael Gottesman
3cd1b7bedc [sil] Extract out ApplySite/FullApplySite into their own header.
I believe that these were in SILInstruction for historic reasons. This is a
separate API on top of SILInstruction so it makes sense to pull it out into its
own header.
2018-09-25 13:32:59 -07:00
Michael Gottesman
c62f31f5dc Inject llvm::SmallBitVector into namespace swift;
I also eliminated all llvm:: before SmallBitVector in the code base.
2018-09-21 09:49:25 -07:00
Jordan Rose
de7b8ff071 Replace 'delete's with std::unique_ptr throughout SILOptimizer 2018-09-18 09:44:01 -07:00
Saleem Abdulrasool
126b137011 Revert "Revert "SILOptimizer: make a conversion operation explicit""
This reverts commit ec11c213ca.  Change the
universal constructor to an explicit copy constructor to repair the Ubuntu 14.04
builds.
2018-09-17 11:45:42 -07:00
Ben Langmuir
ec11c213ca Revert "SILOptimizer: make a conversion operation explicit" 2018-09-17 09:07:38 -07:00
Saleem Abdulrasool
30e70cacb5 SILOptimizer: make a conversion operation explicit
Visual Studio objects to the existing construct with:

  swift/SILOptimizer/Analysis/ARCAnalysis.h(233): warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied
  swift/SILOptimizer/Analysis/ARCAnalysis.h(233): note: while calling the constructor 'llvm::Optional<llvm::ArrayRef<swift::SILInstruction *>>::Optiona(T &&)'
	with
	[
	  T=llvm::ArrayRef<swift::SILInstruction *>
	]
  llvm/ADT/Optional.h(143): note: see declaration of 'llvm::Optional<llvm::ArrayRef<swift::SILInstruction *>>::Optional'
2018-09-13 15:27:19 -07:00
Slava Pestov
42785bedbd Merge pull request #17373 from rajbarik/raj-cta
Concrete type propagation using ProtocolConformanceAnalysis
2018-08-22 15:19:39 -07:00
Raj Barik
d9a051ecdc Concrete type propagation using ProtocolConformanceAnalysis 2018-08-22 11:08:29 -07:00
Michael Gottesman
03afdc5291 [caller-analysis] Reimplement CallerAnalysis ontop of findLocalApplySites.
Now the caller analysis can tell callers if it was able to find /all/ callers of
a callee.

NOTE: This does not change FSO itself yet.

rdar://41146023
2018-08-21 19:34:03 -07:00
swift-ci
96e1edba51 Merge pull request #18767 from gottesmm/pr-0983614e249bfc12a55e18d548d5ea5de9cd00fa 2018-08-16 20:15:07 -07:00
Michael Gottesman
f093a8910d [analysis] Add a new form of verification SILAnalysis::verifyFull().
This is a verification routine that is only invoked in PassManager
destructors. I am going to use this to ensure that the
PassManagerVerifierAnalysis only runs at such points (even when sil-verify-all
is enabled) since it is too expensive to run otherwise.

NOTE: The default implementation of verifyFull in this commit is a no-op. I
wanted to have verify() be the default implementation of verifyFull(), but I do
not have more time to invest in this and it seems to catch /real/ bugs, albeit
bugs unrelated to pass manager notification verification. Instead I am going to
file an SR for someone to look at it since I need to move on from this work back
to semantic SIL. At least we will not have notification failure issues anymore
and thus a large correctness issue in the compiler has been fixed. Forward
progress!

rdar://42301529
2018-08-16 17:25:32 -07:00
Michael Gottesman
3c58cd56e1 [passmanager] Change the verifier analysis to use function names instead of SILFunction pointers for its internal state.
This enables us to have state independent of the liveness of the SILFunction's
that we are tracking.

I also changed the verifier to implement only verifyFull instead of verify to
ensure that when we run with sil-verify-all this only runs at the end of pass
manager pipelines.

rdar://42301529
2018-08-16 14:46:31 -07:00
Ben Cohen
428c580158 Fix unused variable warnings in release builds. (#18755) 2018-08-16 11:46:45 -06:00
Jordan Rose
793b335d0e [SIL] Clarify ownership in FunctionAnalysisBase w/ std::unique_ptr
I also thought I was fixing a performance issue by changing
invalidateFunction not to /insert/ new entries into the map, but
I guess those entries were present in practice. So this is just
a cleanup to make ownership easier.
2018-08-09 12:40:10 -07:00
Joe Shajrawi
2fb0dff321 LoopRegionAnalysis: fix a bug in the reverse_iterator
The reverse iterator initialization got the initializations of its rbegin() and rend() reversed (pun intended)
2018-07-25 14:46:59 -07:00
Michael Gottesman
4ba6a50563 [pass-manager] Add a new analysis PassManagerVerifierAnalysis that validates that the pass manager is sending new/delete messages appropriately to analyses.
The invariant is that this analysis should be able to stay in sync with the list
of functions stored in SILModule's function list. If any functions are
added/deleted then analyses can get out of sync with the state of the underlying
SILModule.

Some notes:

1. This is currently disabled by default since there are a bunch of
violations of this in the compiler. I am in the process of fixing violations.
Some examples: the linker and global opt.
2. This is a no-op in non-assert builds.
3. The full verification will only happen when -sil-verify-all is enabled.
Otherwise, we only check that when we delete a function, we had state for the
function.

rdar://42301529
2018-07-17 14:29:01 -07:00
Michael Gottesman
234fcc1771 [pass-manager] notifyDeleteFunction => notifyWillDeleteFunction.
This name makes it clear that the function has not yet been deleted and also
contrasts with the past tense used in the API notifyAddedOrModifiedFunction to
show that said function has already added/modified the function.
2018-07-16 14:11:06 -07:00
Michael Gottesman
190008418e [pass-manager] notifyAddFunction => notifyAddedOrModifiedFunction.
The name notifyAddFunction is actively harmful since the pass manager uses this
entrypoint to notify analyses of added *OR* modified functions. It is up to the
caller analysis to distinguish in between these cases.

I am not vouching for the design, just trying to make names match the
current behavior.
2018-07-16 13:10:28 -07:00
Michael Gottesman
87b847da0b [analysis] FunctionAnalysisBase's parameter SILAnalysisTy is actually a FunctionInfoTy.
I believe that this was just a typo from a long time ago. Calling this parameter
a SILAnalysisTy is actively misleading since as a result it seems to a naive
reading that one should be writing a recursive template:

```
class MyAnalysis : public FunctionAnalysisBase<MyAnalysis> { ... }
```

Instead of passing in the function info of the derived analysis, i.e.:

```
class MyAnalysisFunctionInfo { ... }
class MyAnalysis : public FunctionAnalysisBase<MyAnalysisFunctionInfo> { ... }
```

I also added some documentation to that affect onto FunctionAnalysisBase.
2018-07-15 12:21:10 -07:00
Michael Gottesman
56d100f493 [analysis] Standardize AnalysisKind by moving it out of SILAnalysis into its own "struct enum" in a non-nested scope.
Generally in the SIL/SILOptimizer libraries we have been putting kinds in the
swift namespace, not a nested scope in a type in swift (see ValueKind as an
example of this).
2018-07-15 11:00:33 -07:00
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
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
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
Michael Gottesman
07b1159be3 [gardening] Change some typedef => using. 2018-06-21 16:37:27 -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