Commit Graph

2038 Commits

Author SHA1 Message Date
Michael Gottesman
157091d5c6 [ownership] Extract out from SILOwnershipVerifier the OperandOwnershipKindMapClassifier
NOTE: This is not the final form of how operand ownership restraints will be
represented. This patch is instead an incremental change that extracts out this
functionality from the ownership verifier as a pure refactor.

rdar://44667493
2018-10-01 22:14:41 -07:00
Erik Eckstein
643f98fdb3 SILOptimizer: fix non-deterministic behavior in RedundantLoadElimination and DeadStoreElimination.
Replace some DenseSets, which are used for iteration, with vectors.

SR-8844
rdar://problem/44762620
2018-10-01 15:32:37 -07:00
Michael Gottesman
d57a88af0d [gardening] Rename references to SILPHIArgument => SILPhiArgument. 2018-09-25 22:23:34 -07:00
Raj Barik
a4103126b3 Merge pull request #17366 from rajbarik/raj-existential2generic
ExistentialSpecializer Pass (without SILCombine/ConcreteType Propagation)
2018-09-25 21:32:46 -07:00
Raj Barik
89d31be7a5 ExistentialSpecializer Pass (without SILCombine/ConcreteType Propagation) 2018-09-25 14:52:00 -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
Davide Italiano
483d4be827 [Local] Update documentation to reflect reality. NFCI. 2018-09-24 15:40:10 -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
swift-ci
d516c93b32 Merge pull request #19300 from compnerd/explicit-implicit-conversion 2018-09-15 11:33:53 -07:00
Raj Barik
e034025f1f Merge pull request #19287 from rajbarik/raj-cp-allargs-2
Propagate concrete types for all arguments of an apply instruction
2018-09-14 10:19:10 -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
Raj Barik
3c5b13dd9e Propagate concrete types for all arguments of an apply instruction 2018-09-12 17:57:08 -07:00
Erik Eckstein
584ed9710f SILOptimizer: update bounds check and uniqueness check hoisting optimizations for using _modify in Array subscript.
The optimizations now handle the ref_tail_addr instructions for detecting element addresses
(in addition to the array semantics function _getElementAddress).
After _modify for Array subscript lands, we can get rid of _getElementAddress at all.
2018-09-06 16:58:06 -07:00
Andrew Trick
098759f070 CopyPropagation for SILValues with ownership.
This is a simple "utility" pass that canonicalizes SSA SILValues with
respect to copies and destroys. It is a self-contained, provably
complete pass that eliminates spurious copy_value instructions from
scalar SSA SILValues. It fundamentally depends on ownership SIL, but
otherwise can be run efficiently after any other pass. It separates
the pure problem of handling scalar SSA values from the more important
and complex problems:

- Promoting variables to SSA form (PredictableMemOps and Mem2Reg
  partially do this).

- Optimizing copies within "SIL borrow" scopes (another mandatory pass
  will be introduced to do this).

- Composing and decomposing aggregates (SROA handles some of this).

- Coalescing phis (A BlockArgumentOptimizer will be introduced as part
  of AddressLowering).

- Removing unnecessary retain/release when nothing within its scope
  may release the same object (ARC Code Motion does some of this).

Note that removing SSA copies was more obviously necessary before the
migration to +0 argument convention.
2018-09-04 13:12:36 -07:00
Andrew Trick
1e88e44ce8 Add critical edge verification and fix SIL passes.
SIL passes were violating the existing invariant on non-cond-br
critical edges in several places. I fixed the places that I could
find.  Wherever there was a post-pass to "clean up" critical edges, I
replaced it with a a call to verification that the critical edges
aren't broken in the first place.

We still need to eliminate critical edges entirely before enabling
ownership SIL.
2018-08-30 13:01:39 -07:00
Erik Eckstein
192431b830 SIL optimizer: remove the RemovePin optimization.
Not useful anymore after removing the pinning adressors
2018-08-23 12:47:56 -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
Michael Gottesman
a13c113b17 [caller-analysis] Add a new SIL utility primitive: findLocalApplySites.
This utility works by taking in a function_ref and then traverses the transitive
uses of the function_ref until it finds either a use it does not understand
"escape" or an "apply" instruction. It returns a result structure that contains
the final found applications and more importantly a bool telling the caller if
we found any "escaping" uses.

This is intended to be an inverse operation to ApplySite::getCalleeOrigin(). As
such it has a bunch of assertions in it that check that the two stay in sync.

rdar://41146023
2018-08-21 12:37:38 -07:00
John McCall
656aba19ea Rename "canInlineBeginApply" to just "canInline"; NFC. 2018-08-21 03:44:08 -04:00
John McCall
94b748a14c Update SIL devirtualization to handle begin_apply instructions.
In order to make this reasonable, I needed to shift responsibilities
around a little; the devirtualization operation is now responsible for
replacing uses of the original apply.  I wanted to remove the
phase-separation completely, but there was optimization-remark code
relying on the old apply site not having been deleted yet.

The begin_apply aspects of this aren't testable independently of
replacing materializeForSet because coroutines are currently never
called indirectly.
2018-08-19 19:50:13 -04:00
John McCall
512e55683e Make it easy to create a SILBasicBlock immediately before a target block.
Also, make "after" requests explicit in the API.
2018-08-18 12:36:36 -04:00
swift-ci
96e1edba51 Merge pull request #18767 from gottesmm/pr-0983614e249bfc12a55e18d548d5ea5de9cd00fa 2018-08-16 20:15:07 -07:00
swift-ci
f1f056cb4b Merge pull request #18765 from gottesmm/pr-c28068372a21dccd2c3076e1f666f346e90865e4 2018-08-16 18:20:55 -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
Michael Gottesman
9168d46015 [passmanager] Add the two last missing delete notifications.
With this change and some other changes that I am committing in parallel, the
stdlib and all of the overlays send all proper pass manager notifications.

rdar://42301529
2018-08-16 14:41:22 -07:00
Michael Gottesman
74ae66bacd Merge pull request #18725 from gottesmm/pr-1e9eaf3649841fc06185d9b353db89111ed4c380
[sil-pass-manager] Wire up pass manager to the new deserialization notification infrastructure.
2018-08-16 10:50:27 -07:00
Ben Cohen
428c580158 Fix unused variable warnings in release builds. (#18755) 2018-08-16 11:46:45 -06:00
Michael Gottesman
aa11068fd4 [sil-pass-manager] Wire up pass manager to the new deserialization notification infrastructure.
rdar://42301529
2018-08-15 16:28:50 -07:00
Raj Barik
971772d0a9 Merge pull request #18109 from rajbarik/raj-refactor
Extend SILCombiner code to handle existential self concrete type propagation using ProtocolConformanceAnalysis
2018-08-13 09:56:56 -07: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
Michael Gottesman
f35a2a3cf8 [sil-opt] Only notify the pass manager of newly added functions in SILOptFunctionBuilder.
To do so this commit does a few different things:

1. I changed SILOptFunctionBuilder to notify the pass manager's logging
functionality when new functions are added to the module and to notify analyses
as well. NOTE: This on purpose does not put the new function on the pass manager
worklist since we do not want to by mistake introduce a large amount of
re-optimizations. Such a thing should be explicit.

2. I eliminated SILModuleTransform::notifyAddFunction. This just performed the
operations from 1. Now that SILOptFunctionBuilder performs this operation for
us, it is not needed.

3. I changed SILFunctionTransform::notifyAddFunction to just add the function to
the passmanager worklist. It does not need to notify the pass manager's logging
or analyses that a new function was added to the module since
SILOptFunctionBuilder now performs that operation. Given its reduced
functionality, I changed the name to addFunctionToPassManagerWorklist(...). The
name is a little long/verbose, but this is a feature since one should think
before getting the pass manager to rerun transforms on a function. Also, giving
it a longer name calls out the operation in the code visually, giving this
operation more prominance when reading code. NOTE: I did the rename using
Xcode's refactoring functionality!

rdar://42301529
2018-08-06 18:27:24 -07:00
Michael Gottesman
f500f007f8 [sil] Add a template parameter to TypeSubstCloner so that subclasses can inject a SILFunctionBuilder composition class.
This works around a potential circular dependence issue where TypeSubstCloner
needs access to SILOptFunctionBuilder but is in libswiftSIL.

rdar://42301529
2018-08-06 13:40:25 -07:00
Michael Gottesman
b72304415d [passmanager] Change the optimizer to use SILOptFunctionBuilder.
I am going to add the code in a bit that does the notifications. I tried to pass
down the builder instead of the pass manager. I also tried not to change the
formatting.

rdar://42301529
2018-08-05 21:21:55 -07:00
Arnold Schwaighofer
f40a13a925 SILInliner: Disable inlining mulitple yields and don't create a temporary for yielded address values
Just use the yielded address from the callee directly. This also allows
handling yielded 'inout'/'out' values.
2018-08-02 14:57:03 -07:00
Raj Barik
484925c26f Extend SILCombiner code to handle existential self concrete type propagation using ProtocolConformanceAnalysis 2018-08-01 14:25:52 -07:00
Adrian Prantl
58475ef1ad 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-31 16:59:56 -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
fe97efcdbd [pass-manager] Missed one. notifyDeleteFunction => notifyWillDeleteFunction. 2018-07-17 10:00:27 -07:00
Michael Gottesman
cecf2f5345 [pass-manager] Analysis => Analyses.
This is a list of analyses, so using plural form makes more sense.
2018-07-16 17:42:11 -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