Commit Graph

35 Commits

Author SHA1 Message Date
Egor Zhdan
b3c13e445e Merge pull request #74094 from swiftlang/egorzhdan/scs-inline-dtor
[cxx-interop][SwiftCompilerSources] Remove a workaround
2024-09-03 12:37:35 +01:00
Erik Eckstein
f9b524b1cb AliasAnalysis: a complete overhaul of alias- and memory-behavior analysis
The main changes are:

*) Rewrite everything in swift. So far, parts of memory-behavior analysis were already implemented in swift. Now everything is done in swift and lives in `AliasAnalysis.swift`. This is a big code simplification.

*) Support many more instructions in the memory-behavior analysis - especially OSSA instructions, like `begin_borrow`, `end_borrow`, `store_borrow`, `load_borrow`. The computation of end_borrow effects is now much more precise. Also, partial_apply is now handled more precisely.

*) Simplify and reduce type-based alias analysis (TBAA). The complexity of the old TBAA comes from old days where the language and SIL didn't have strict aliasing and exclusivity rules (e.g. for inout arguments). Now TBAA is only needed for code using unsafe pointers. The new TBAA handles this - and not more. Note that TBAA for classes is already done in `AccessBase.isDistinct`.

*) Handle aliasing in `begin_access [modify]` scopes. We already supported truly immutable scopes like `begin_access [read]` or `ref_element_addr [immutable]`. For `begin_access [modify]` we know that there are no other reads or writes to the access-address within the scope.

*) Don't cache memory-behavior results. It turned out that the hit-miss rate was pretty bad (~ 1:7). The overhead of the cache lookup took as long as recomputing the memory behavior.
2024-07-29 17:33:46 +02:00
Egor Zhdan
2d255e7129 [cxx-interop][SwiftCompilerSources] Remove a workaround
The definition of `~BasicCalleeAnalysis` can now be inlined.

rdar://127152872 / resolves https://github.com/apple/swift/issues/64502
2024-06-03 14:04:30 +01:00
Erik Eckstein
0897d8a720 MemoryLifetimeVerifier: use CalleeCache instead of AliasAnalysis
To verify if a function may read from an indirect argument, don't use AliasAnalysis.
Instead use the CalleeCache to get the list of callees of an apply instruction.
Then use a simple call-back into the swift Function to check if a callee has any relevant memory effect set.

This avoids a dependency from SIL to the Optimizer.
It fixes a linker error when building some unit tests in debug.
2023-12-01 19:20:18 +01:00
Erik Eckstein
e80fedc52a move CalleeCache from SILOptimizer to SIL
Extract the CalleeCache from BasicCalleeAnalysis so that it can be used in SIL without BasicCalleeAnalysis
2023-12-01 19:20:18 +01:00
Erik Eckstein
da3f126322 CalleeAnalysis: no need to provide the PassManager to the getMemBehaviorFn
A NFC simplification
2023-05-03 14:33:45 +02:00
Erik Eckstein
67299b4471 SIL bridging: work around an unresolved symbol linker error
Works around  problem https://github.com/apple/swift/issues/64502
2023-03-21 15:33:09 +01:00
Erik Eckstein
010efc1ca6 Swift Bridging: use C++ instead of C bridging for the optimizer 2023-03-21 15:33:09 +01:00
Erik Eckstein
8c05024ea6 SIL: move the SILInstruction::MemoryBehavior enum out of SILInstruction into the swift namespace 2023-03-21 15:33:09 +01:00
Erik Eckstein
7db7065740 swift side effects: add CalleeAnalysis.getSideEffects(of: apply) 2022-10-20 09:20:28 +02:00
Nate Chandler
7ea336367d [NFC] Port isDeinitBarrier to Swift.
Added new C++-to-Swift callback for isDeinitBarrier.

And pass it CalleeAnalysis so it can depend on function effects.  For
now, the argument is ignored.  And, all callers just pass nullptr.

Promoted to API the mayAccessPointer component predicate of
isDeinitBarrier which needs to remain in C++.  That predicate will also
depends on function effects.  For that reason, it too is now passed a
BasicCalleeAnalysis and is moved into SILOptimizer.

Also, added more conservative versions of isDeinitBarrier and
maySynchronize which will never consider side-effects.
2022-10-18 21:23:22 -07:00
Erik Eckstein
d8bf949582 BasicCalleeAnalysis: improve finding the actual called deinits of a destroy/release instruction
* C++: add a function `getDestructors(SILType type, bool isExactType)’: if the type is a final class or `isExactType` is true, then return the one and only destructor of that class.
* swift: add `getDestructor(ofExactType type: Type)` and `getIncompleteCallees`
* swift: remove `getDestructor` from the PassContext. The API of the `calleeAnalysis` can be used instead.
2022-04-05 20:33:23 +02:00
Erik Eckstein
e096b2f14a BasicCalleeAnalysis: make the callee list datastructure more efficient
This avoids copying a SmallVector in case of multiple callees in the list.
Instead, just reference the callee list in the cache.
2021-07-01 17:16:47 +02:00
swift-ci
0b41d02a4d Merge remote-tracking branch 'origin/master' into master-next 2019-10-31 20:49:50 -07:00
Brent Royal-Gordon
99faa033fc [NFC] Standardize dump() methods in frontend
By convention, most structs and classes in the Swift compiler include a `dump()` method which prints debugging information. This method is meant to be called only from the debugger, but this means they’re often unused and may be eliminated from optimized binaries. On the other hand, some parts of the compiler call `dump()` methods directly despite them being intended as a pure debugging aid. clang supports attributes which can be used to avoid these problems, but they’re used very inconsistently across the compiler.

This commit adds `SWIFT_DEBUG_DUMP` and `SWIFT_DEBUG_DUMPER(<name>(<params>))` macros to declare `dump()` methods with the appropriate set of attributes and adopts this macro throughout the frontend. It does not pervasively adopt this macro in SILGen, SILOptimizer, or IRGen; these components use `dump()` methods in a different way where they’re frequently called from debugging code. Nor does it adopt it in runtime components like swiftRuntime and swiftReflection, because I’m a bit worried about size.

Despite the large number of files and lines affected, this change is NFC.
2019-10-31 18:37:42 -07:00
Xi Ge
64c0680686 Merge remote-tracking branch 'apple/master' into master-next 2019-10-28 10:19:36 -07:00
Erik Eckstein
d88edadb60 BasicCalleeAnalysis: fix computation of class method callees if an overridden function has a different ABI
In such a case the overridden function gets a new separate vtable entry.
With this change, the computation of class method callees only uses the information in sil_vtables (instead of ClassDecl members).

Fixes a compiler crash in various optimization passes.
rdar://problem/56146633
2019-10-22 11:27:21 +02:00
Erik Eckstein
baa94f21c2 BasicCalleeAnalysis: add dump() functions for debugging 2019-10-22 11:27:21 +02:00
Jonas Devlieghere
b4d268e9e1 Migrate llvm::make_unique to std::make_unique
Now that we've moved to C++14, we no longer need the llvm::make_unique
implementation from STLExtras.h. This patch is a mechanical replacement
of (hopefully) all the llvm::make_unique instances in the swift repo.
2019-08-15 11:32:39 -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
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
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
Michael Gottesman
07b1159be3 [gardening] Change some typedef => using. 2018-06-21 16:37:27 -07:00
Erik Eckstein
0e068ea15c Add some comments and remove dead while-loop.
Thanks @atrick for reviewing!
2017-03-14 13:00:55 -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
Erik Eckstein
8284688ab1 BasicCalleeAnalysis: fix the handling of allocator class methods.
It can result in a runtime crash.
This comes up when using required initializers.

fixes rdar://problem/29398625
2017-01-04 14:39:10 -08: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
Roman Levenstein
4433ad9c3c [sil-optimizer] Teach analysis passes that some instructions besides apply may result in a function call.
For example, strong_release may call a destructor. This information will be used e.g. by the escape analysis.
As destructors are potential calles now, FunctionOrder analysis will make sure that they will be scheduled for optimizations before their callers.
2016-09-15 22:10:25 -07:00
Mark Lacey
f47cd8afd0 Fix leak in BasicCalleeAnalysis.
Each time we delete the pass manager, we delete the analyses it
holds. In this analysis we were holding onto memory that wasn't getting
released when the analysis was deleted.

Fixes rdar://problem/26245872.
2016-06-23 07:49:06 -07:00
Mark Lacey
921dededad Use a bump pointer allocator in the callee set creation.
Shaves about 19% of the time from the construction of these sets. The
SmallVector size was chosen to minimize the number of dynamic
allocations we end up doing while building the stdlib. This should be a
reasonable size for most projects, too. It's a bit wasteful in space,
but the total amount of allocated space here is pretty small to begin
with.
2016-05-11 17:07:27 -07:00
practicalswift
f91525a10f Consistent placement of "-*- [language] -*-===//" in header. 2016-01-04 09:46:20 +01:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00: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