Commit Graph

39 Commits

Author SHA1 Message Date
Erik Eckstein
096f02b3ef SILOptimizer: rename ANALYSIS macro to SIL_ANALYSIS
Avoids a conflict with clang's `ANALYSIS` macro.

Fixes a macro redefinition warning.
2022-11-21 19:22:15 +01:00
Erik Eckstein
ecbcacdecf SIL Analysis: Rename InvalidationKind::FunctionData to InvalidationKind::Effects
This invalidation kind is used when a compute-effects pass changes function effects.
Also, let optimization passes which don't change effects only invalidate the `FunctionBody` and not `Everything`.
2022-10-20 09:20:28 +02:00
Erik Eckstein
beebd5a920 PassManager: add a invalidation kind for non-body function data
E.g. used if function effects are changed. This tells the passmanager that something changed, but no SIL-specific analysis have to be invalidated.
2022-08-24 17:54:46 +02:00
Erik Eckstein
4977850092 SIL: remove the notifyDeleteHandlers mechanism
It's not needed anymore with delayed instruction deletion.
It was used for two purposes:
1. For analysis, which cache instructions, to avoid dangling instruction pointers
2. For passes, which maintain worklists of instructions, to remove a deleted instructions from the worklist. This is now done by checking SILInstruction::isDeleted().
2021-05-26 21:57:54 +02:00
Varun Gandhi
fea589e470 [NFC] Remove redundant includes for llvm/ADT/DenseSet.h. 2020-05-31 13:07:45 -07:00
Varun Gandhi
96a332e865 [NFC] Remove redundant includes for llvm/ADT/SmallVector.h. 2020-05-31 13:07:45 -07:00
Varun Gandhi
2c7b4b119a [NFC] Remove redundant includes for llvm/ADT/Optional.h. 2020-05-31 13:05:48 -07:00
Varun Gandhi
ea92df04e1 [NFC] Remove redundant includes for <vector>. 2020-05-31 13:05:02 -07:00
Meghana Gupta
6c3857b6d6 Add forced precomputation and verification of analysis (#31251)
-sil-verify-all flag will verify analyses before and after a pass to
confirm correct invalidations. But if an analysis was never
constructed or invalidated as per current pass order,
it may never detect insufficient invalidations.

-sil-verify-force-analysis will force construct an analysis so that we
can better check for insufficient invalidations.
It is also terribly slow compared to -sil-verify-all.
2020-04-24 10:55:45 -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
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
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
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
b70c8b64a1 [sil-analysis] Add a new utility class for FunctionBaseInfo based analyses: LazyFunctionInfo.
Commonly when an analysis uses subanalyses, we eagerly create the sub function
info when constructing the main function info. This is not always necessary and
when the subanalyses do work in their constructor, can be actively harmful if
the parent analysis is never invoked.

This utility class solves this problem by being a very easy way to perform a
delayed call to the sub-analysis to get the sub-functioninfo combined with a
cache so that after the LazyFunctionInfo is used once, we do not reuse the
DenseMap in the sub-analysis unnecessarily.

An example of where this can happen is in EpilogueARCAnalysis in combination
with PostOrderFunctionInfo. PostOrderFunctionInfo eagerly creates a new post
order. So, if we were to eagerly create the PostOrderFunctionInfo (the
sub-functioninfo) when we created an EpilogueARCFunctionInfo, we would be
creating a post order even if we never actually invoke EpilogueARCFunctionInfo.
2017-08-11 18:18:39 -07:00
Michael Gottesman
eb4d94f10b [sil-analysis] Add FunctionAnalysisBase::{hasAnalysis,maybeGet}(SILFunction *F).
Today, if one wants to invalidate state relative to your own function analysis,
you have to use FunctionAnalysisBase::get() to get the analysis. The problem
here is that if the analysis does not exist yet, then you are actually creating
the analysis. This is an issue when one wants to perform an action on an
analysis only if the analysis has already been built. An example of such a
situation is when one is processing a delete notification. If one does not have
an analysis for a function, one should just do nothing.

I am going to use this to fix a delete notification problem in
EpilogueARCAnalysis.

rdar://33841629
2017-08-11 14:41:57 -07:00
Michael Gottesman
6b54531455 Move the include guard of Analysis.h /above/ the includes.
Otherwise, every time we include Analysis.h, we will try to include those other
files even if we have already included Analysis.h. This can increase compile
time.

rdar://33841629
2017-08-11 14:40:36 -07:00
Erik Eckstein
aa8eabfcf0 Fix a memory leak in SIL Analysis
rdar://problem/31282672
2017-03-30 15:07:10 -07:00
Erik Eckstein
a0079ba5be SIL optimizations: Implement the new API for analysis invalidation.
There are now separate functions for function addition and deletion instead of InvalidationKind::Function.
Also, there is a new function for witness/vtable invalidations.

rdar://problem/29311657
2017-03-14 13:00:54 -07:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Graydon Hoare
92440b0fcf [Compile Perf] Invalidate BasicCalleeAnalysis less, rdar://29279532 2016-11-17 12:56:39 -08:00
practicalswift
a0d494c143 [gardening] Fix recently introduced typos: "fucntion" → "function", "functio" → "function", "mergable" → "mergeable", "mistmatched" → "mismatched" 2016-03-20 10:34:32 +01:00
Xin Tong
1603b0f153 Handle dead functions in CallerAnalysis.
Add an invalidateAnalysisForDeadFunction API. This API calls the invalidateAnalysis
by default unless overriden by analysis pass themselves. This API passes the extra
information that this function is dead and going to be removed from the module.

CallerAnalysis overrides this API and only invalidate caller/callee relations but
does not push this into the recompute list.

We also considered the possibility of keeping a computed list, instead of recompute
list but that would introduce a O(n^2) complexity as every time we try to complete
the computed list, we need to walk over all the functions that currently exist in the
module to make sure the computed list is complete.

I feel eventually we can do a handleDeleteNotification for function deletion and we
wont need the API added in this change.
2016-03-17 09:55:12 -07:00
Xin Tong
0acc0a8464 Implement a Caller Analysis.
The analysis can tell all the callsites which calls a function in the module.

The analysis is computed and kept up-to-date lazily.

At the core of it, it keeps a list of functions that need to be recomputed for
the Caller/Callee relation to be precise and on every query, the analysis makes
sure to recompute them and clear the list before any query.

This is NFC right now. I am going to wire it up to function signature analysis
eventually.
2016-03-16 09:33:22 -07:00
practicalswift
1339b5403b Consistent use of header comment format.
Correct format:
//===--- Name of file - Description ----------------------------*- Lang -*-===//
2016-01-04 13:26:31 +01:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Dmitri Gribenko
15be903fe2 Merge pull request #500 from practicalswift/fix-typos-4
Fix typos (4 of 30)
2015-12-13 16:21:02 -08:00
practicalswift
c75ef42ed6 Fix typo: cacheing → caching 2015-12-14 00:11:19 +01:00
practicalswift
ffc8d90ebd Fix typo: anithing → anything 2015-12-13 23:56:41 +01:00
Andrew Trick
84450b4c43 Reorganize SILOptimizer directories for better discoverability.
(Headers first)

It has been generally agreed that we need to do this reorg, and now
seems like the perfect time. Some major pass reorganization is in the
works.

This does not have to be the final word on the matter. The consensus
among those working on the code is that it's much better than what we
had and a better starting point for future bike shedding.

Note that the previous organization was designed to allow separate
analysis and optimization libraries. It turns out this is an
artificial distinction and not an important goal.
2015-12-11 12:34:51 -08:00