Commit Graph

2053 Commits

Author SHA1 Message Date
Erik Eckstein
8223b3e210 MandatoryPerformanceOptimizations: fix some problems with inilning
* don't inline functions if it's not possible - by checking `SILInliner::canInlineApplySite`
* fix stack nesting after inlining a `begin_apply`
2023-08-10 15:01:47 +02:00
Becca Royal-Gordon
3eebc6dddb Merge branch 'main' into rebranch
# Conflicts:
#	lib/SILOptimizer/Differentiation/Common.cpp
2023-08-04 15:09:50 -07:00
Tony Allevato
b59f5c7c02 Merge pull request #67683 from allevato/c++20-tweaks
[Code Health] Improve eventual C++20 support.
2023-08-03 13:24:06 -04:00
swift-ci
be3a013d93 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-02 12:34:03 -07:00
Alejandro Alonso
62a986e9c3 Merge pull request #67643 from eltociear/patch-43
[SILOptimizer] Fix typo in KeyPathProjector.h
2023-08-02 12:19:23 -07:00
Tony Allevato
c71c1e193b Ensure types used as std::vector elements are complete.
These were never allowed, but with C++20 making more `vector` functions
`constexpr`, they would start causing build failures in that language
mode.
2023-08-02 15:03:48 -04:00
swift-ci
0c91f5124e Merge remote-tracking branch 'origin/main' into rebranch 2023-08-01 15:34:29 -07:00
Kuba (Brecka) Mracek
8510bdd7f0 Merge pull request #67587 from kubamracek/move-target-const-folding-to-swift-simplification
Move target const folding to swift simplification
2023-08-01 15:19:26 -07:00
Ikko Eltociear Ashimine
a4ab34475a [SILOptimizer] Fix typo in KeyPathProjector.h
addres -> address
2023-08-01 16:40:07 +09:00
Kuba Mracek
ae6129cf69 Cache the IRGenModule even between SIL passes 2023-07-31 11:57:28 -07:00
Kuba Mracek
5dac59ce71 Move TargetConstantFolding pass to the simplification passes in Swift, enable using MemoryLayout's .size, .stride, .alignment fields in forced-const global initializers 2023-07-31 10:54:07 -07:00
swift-ci
e24988e633 Merge remote-tracking branch 'origin/main' into rebranch 2023-07-28 09:44:12 -07:00
Joshua Turcotti
2eade1d1b5 Merge pull request #67511 from JTurcotti/tweaks
[SendNonSendable] Assorted Bugfixes and Tweaks
2023-07-28 09:24:36 -07:00
swift-ci
e1d21fe05c Merge remote-tracking branch 'origin/main' into rebranch 2023-07-27 16:56:57 -07:00
jturcotti
bb2f3c011e rename DeferredSendableChecking pass to SendNonSendable pass, handle more instructions such as try_apply and begin_apply, and fix bugs 2023-07-27 16:45:29 -07:00
Allan Shortlidge
f9a93a55d7 NFC: Fix duplicate definition of macro warnings.
Centralize the `SWIFT_{BEGIN/END}_NULLABILITY_ANNOTATIONS` definitions in a new
Nullability.h header to share.
2023-07-27 13:02:22 -07:00
Evan Wilde
5b40e5e50a Cast bitfields to unsigned int for optional return
Bit-fields don't convert to reference types automatically, so converting
them to unsigned int so that they can be returned in the
`std::optional`.
2023-07-25 12:28:28 -07:00
Evan Wilde
309aed4925 Add SmallSetVector replacement
llvm::SmallSetVector changed semantics
(https://reviews.llvm.org/D152497) resulting in build failures in Swift.
The old semantics allowed usage of types that did not have an
`operator==` because `SmallDenseSet` uses `DenseSetInfo<T>::isEqual` to
determine equality. The new implementation switched to using
`std::find`, which internally uses `operator==`. This type is used
pretty frequently with `swift::Type`, which intentionally deletes
`operator==` as it is not the canonical type and therefore cannot be
compared in normal circumstances.

This patch adds a new type-alias to the Swift namespace that provides
the old semantic behavior for `SmallSetVector`. I've also gone through
and replaced usages of `llvm::SmallSetVector` with the
`Swift::SmallSetVector` in places where we're storing a type that
doesn't implement or explicitly deletes `operator==`. The changes to
`llvm::SmallSetVector` should improve compile-time performance, so I
left the `llvm::SmallSetVector` where possible.
2023-07-25 12:28:27 -07:00
swift_jenkins
a087d570d2 Merge remote-tracking branch 'origin/main' into next 2023-07-21 05:02:46 -07:00
eeckstein
b9d0aa34e1 Merge pull request #67395 from eeckstein/redundant-load-elimination
Optimizer: re-implement the RedundantLoadElimination pass in Swift
2023-07-21 13:58:19 +02:00
swift_jenkins
37294fc25c Merge remote-tracking branch 'origin/main' into next 2023-07-21 01:24:40 -07:00
Erik Eckstein
5b3c34b9e7 fix a linking problem in swift-frontend
Sometimes when building the SwiftCompilerSources with a host compiler, linking fails with unresolved symbols for DenseMap and unique_ptr destroys.
This looks like a problem with C++ interop: the compiler thinks that destructors for some Analysis classes are materialized in the SwiftCompilerSources, but they are not.
Explicitly defining those destructors fixes the problem.
2023-07-21 08:01:31 +02:00
Erik Eckstein
29246fd80b AliasAnalysis: add complexity budget for the getMemEffectsFunction 2023-07-21 07:19:56 +02:00
Erik Eckstein
2384a0c6f4 Optimizer: remove the now unused LSLocation utilities 2023-07-21 07:19:56 +02:00
Erik Eckstein
4d20423e00 Optimizer: re-implement the RedundantLoadElimination pass in Swift
The new implementation has several benefits compared to the old C++ implementation:

* It is significantly simpler. It optimizes each load separately instead of all at once with bit-field based dataflow.
* It's using alias analysis more accurately which enables more loads to be optimized
* It avoids inserting additional copies in OSSA

The algorithm is a data flow analysis which starts at the original load and searches for preceding stores or loads by following the control flow in backward direction.
The preceding stores and loads provide the "available values" with which the original load can be replaced.
2023-07-21 07:19:56 +02:00
Erik Eckstein
ff913d2fa6 Swift Optimizer: add the FunctionPassContext.swiftArrayDecl API 2023-07-21 07:19:12 +02:00
Erik Eckstein
2e9de24e2a Swift Optimizer: add the SSAUpdater utility 2023-07-21 07:19:12 +02:00
swift_jenkins
5e19e456fc Merge remote-tracking branch 'origin/main' into next 2023-07-20 17:03:51 -07:00
jturcotti
853ef7cf3c fix bugs that present themselves when handling multiarg and varargs functions, including adding better debug dump methods 2023-07-20 14:01:08 -07:00
jturcotti
a83d7aa39c improve diagnostics about data races; highlight the individual expressions being sent and accessed as precisely as possible, and include information about specific non-sendable types and isolation crossings 2023-07-19 17:27:16 -07:00
swift_jenkins
b6f935ecaa Merge remote-tracking branch 'origin/main' into next 2023-07-19 09:44:39 -07:00
jturcotti
55e8f9f2ed improve debug output, finalize explicit constructor refactor, and begin improving diagnostic messages 2023-07-18 15:58:56 -07:00
jturcotti
3868f1dc27 perform refactor to use named types as elements and regions in partitions, and ensure that all SILValues are converted once to TrackableSILValues in the SendNonSendable analysis pass 2023-07-18 13:32:43 -07:00
Evan Wilde
26a974e772 [NFC] Headers headers headers!
Including headers that were being transitively included from LLVM
before. Also pointing them at the new locations for some of them.
2023-07-17 10:55:55 -07:00
jturcotti
34113c4c0f implement searching for a ConsumeReason instead of just diagnosing accesses to consumed values 2023-07-14 16:12:52 -07:00
jturcotti
1d130390be add more comprehensive cases to tests, and fix many bugs, relying on much more potent resolution of addresses 2023-07-14 09:28:27 -07:00
jturcotti
1a716d82cf replace use of internal "projections" tracking map with usage of memutils' AccessStorage utilities 2023-07-14 09:28:26 -07:00
Joshua Turcotti
e8111932d9 Merge pull request #67172 from JTurcotti/sil-pass
Add SIL Pass for flow-sensitive, region-based Sendable checking
2023-07-11 15:08:36 -07:00
jturcotti
e7a1747af2 Tweak, improve, and debug the PartitionAnalysis engine until a fairly comprehensive suite of simple tests passes (region_based_sendability.swift) 2023-07-11 11:12:38 -07:00
jturcotti
29bd728f4c Begin to fill in the SendNonSendable SIL pass using a PartitionAnalysis engine, works for some simple examples but needs to address address values in SIL. 2023-07-10 15:20:14 -07:00
jturcotti
aae9f43bda Write PartitionUtils.h, implementing common utilities for manipulating a partition data structure that will be used for flow-sensitive, region-based Sendable checking. 2023-07-10 15:20:14 -07:00
Andrew Trick
5bae8551ff Cleanup and document SIL memory behavior APIs.
This is code that I am fairly familiar with but it still took a day of
investigation to figure out how it is supposed to be used now in the
presence of bridging.

This primarily involved ruling out the possibity that the mid-level
Swift APIs could at some point call into the lower-level C++ APIs.

The biggest problem was that AliasAnalysis::getMemoryBehaviorOfInst()
was declared as a public interface, and it's name indicates that it
computes the memory behavior. But it is just a wrapper around a Swift
API and never actually calls into any of the C++ logic that is
responsible for computing memory behavior!
2023-07-07 20:54:31 -07:00
Erik Eckstein
baaf5565b0 Optimizer: reimplement DeadStoreElimination in swift
The old C++ pass didn't catch a few cases.
Also:
* The new pass is significantly simpler: it doesn't perform dataflow for _all_ memory locations at once using bitfields, but handles each store separately. (In both implementations there is a complexity limit in place to avoid quadratic complexity)
* The new pass works with OSSA
2023-07-05 21:33:25 +02:00
nate-chandler
d2c8ede38d Merge pull request #67069 from nate-chandler/test/20230629/2
[Test] Moved SIL function tests next to tested code.
2023-07-04 19:34:50 -07:00
Nate Chandler
df02726e7b [Test] Ensourced simplify-cfg-simplify-block-args.
Moved the test next to the code it calls.
2023-07-04 11:52:13 -07:00
Nate Chandler
e9ab3b4b53 [Test] Refactored SIL "unit" tests.
Renamed UnitTest to FunctionTest.

FunctionTests are now instantiated once as global objects--with their
names and the code they are to run--at which time they are stored by
name in a global registry.

Moved the types to the SIL library.

Together, these changes enable defining unit tests in the source file
containing the code to be tested.
2023-07-04 11:52:11 -07:00
Nate Chandler
4374b6b58f [Test] Moved test_spec parsing to SIL.
In preparation for moving unit test infrastructure there so that it can
be used anywhere the SIL library is used.
2023-07-04 11:51:36 -07:00
jturcotti
aa9f1a3584 add an experimental feature DeferSendableChecking to defer the sendable checking of some sites. For now, only diagnostics corresponding to non-sendable arguments passed to calls with unsatisfied isolation are deferred. A SIL pass SendNonSendable is added to emit the deferred diagnostics, and ApplyExpr is appropriately enriched to make that deferral possible. 2023-07-03 09:52:11 -07:00
Erik Eckstein
55c8c433c0 SILOptimizer: add the StripObjectHeader optimization pass
It sets the `[bare]` attribute for `alloc_ref` and `global_value` instructions if their header (reference count and metatype) is not used throughout the lifetime of the object.
2023-06-29 06:57:05 +02:00
Michael Gottesman
bd90e310e1 Merge pull request #66952 from gottesmm/pr-87fcc78991b465d8a15454dc76b66d6f347ddff0
[move-only] Emit an error if we /ever/ partially consume a noncopyable type.
2023-06-28 01:00:40 -07:00