Commit Graph

1057 Commits

Author SHA1 Message Date
nate-chandler
d5e8625db9 Merge pull request #62442 from nate-chandler/opaque-values/1/20221201
[AddressLowering] Handle indirectly yielded values used outside of coroutine range.
2022-12-09 07:00:16 -08:00
Nate Chandler
e1cb0b5522 [MemAccessUtils] Look thru nested for guar roots.
Previously, findGuaranteedReferenceRoots always stopped searching when
finding a begin_borrow, because it's not an ownership-forwarding
instruction.  Here, it is conditionally allowed to keep search through
the borrowee of that begin_borrow if it itself is guaranteed.
2022-12-08 18:29:14 -08:00
Michael Gottesman
d1d3c1262e Merge pull request #62464 from gottesmm/pr-6d0c4626f8ea10597ecc6b876f1bbfd6432cd4db
[move-addr] Move Field Sensitive Pruned Liveness into its own header/cpp impl.
2022-12-08 15:07:25 -08:00
Michael Gottesman
3f90afb901 [move-addr] Move Field Sensitive Pruned Liveness into its own header/cpp impl. 2022-12-08 10:29:48 -08:00
Nate Chandler
7430c6142f [SIL] Verified yielded addresses.
For yielded, nontrivial addresses, verify based on convention:
- guaranteed -> must be initialized at end_apply/abort_apply
- owned -> must be deinitialized at end_apply/abort_apply
- inout -> must be initialized at end_apply/abort_apply
2022-12-07 18:51:50 -08:00
Erik Eckstein
97d17a5451 Fix a crash in the mandatory inliner related to optimization remarks
Even if a function's type has a self parameter, it may be specialized and the function argument is actually not there anymore.

rdar://103065348
2022-12-07 13:51:32 +01:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Allan Shortlidge
0a24042cdd SIL: Introduce the has_symbol SIL instruction. 2022-11-16 16:07:26 -08:00
Allan Shortlidge
cfb5ad8836 Merge pull request #61779 from tshortli/break-cycle-loop-can-duplicate
SILOptimizer: Break circular dependency with SIL library by moving `canDuplicate()`
2022-10-27 22:43:47 -07:00
Allan Shortlidge
0921480486 SILOptimizer: Break circular dependency with SIL library by moving canDuplicate().
Fixes a cycle introduced by https://github.com/apple/swift/pull/61051.
2022-10-27 16:12:05 -07:00
Allan Shortlidge
4f8d33ffb5 SILOptimizer: Break circular dependency with SIL library by moving extendStoreBorrow(). 2022-10-27 15:29:37 -07:00
nate-chandler
9c17447158 Merge pull request #61654 from nate-chandler/shrink_borrow_scope/handle_barrier_merge_terminators
Removed deinit barrier workaround.
2022-10-24 14:40:21 -07:00
Nate Chandler
f98917b1fe Removed workaround for missing Swift sources.
Previously, to workaround an issue with ShrinkBorrowScope (where it
assumed a reasonable definition of isDeinitBarrier), a placeholder
version of the function was added.  It is now removed by moving the
implementation of a version of that predicate back to C++.
2022-10-24 08:47:18 -07:00
Egor Zhdan
a6372e955a Merge pull request #61618 from apple/egorzhdan/scs-reapply-enums
Revert "Revert "[cxx-interop][SwiftCompilerSources] Use C++ enums directly from Swift""
2022-10-20 15:46:17 +01:00
Erik Eckstein
173b698563 Swift SIL: add ApplySite.numIndirectResultArguments 2022-10-20 09:20:28 +02:00
Meghana Gupta
ebd7a90587 NFC: Remove unused code + reorg 2022-10-19 19:54:28 -07:00
Meghana Gupta
786eb94853 Support @guaranteed forwarding phis 2022-10-19 19:54:27 -07:00
Meghana Gupta
b1f719709b Rename ForwardingBorrow -> GuaranteedForwarding 2022-10-19 19:54:27 -07: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
Egor Zhdan
94ec683ba5 Revert "Revert "[cxx-interop][SwiftCompilerSources] Use C++ enums directly from Swift""
This reverts commit 69431f00
2022-10-18 18:55:57 +01:00
Nate Chandler
c2f354eefd [PrunedLiveness] Addressed boundary TODO.
With guaranteed phis, we'll be able to encounter cases where the last
users are BranchInsts which use but don't consume a value.  But even
without them, we can still test the API.
2022-10-17 16:50:04 -07:00
Nate Chandler
ca43d71769 [OpaqueValues] Fixed index of self argument.
Previously, SILFunction_getSelfArgumentIndex was directly using the
function type rather than interacting with the function convention.
Here, it is made to interact with the convention.
2022-10-14 17:11:01 -07:00
Andrew Trick
5270079265 Merge pull request #61558 from atrick/scoped-liveness
Handle scoped address in PrunedLiveness
2022-10-13 08:47:28 -07:00
Andrew Trick
6af0b6d818 Use ScopedAddressValue in PrunedLiveness
to handle scoped addresses properly
2022-10-12 12:32:15 -07:00
Nate Chandler
ab35362056 [SIL] Added new test_specification instruction.
The new instruction exists only to be used in tests.  The idea is to
specify tests that ought to be run "in the context" of the containing
function.
2022-10-11 17:15:13 -07:00
Andrew Trick
2c700be8eb Add a TODO in PrunedLivenessBoundary::visitInsertionPoints 2022-10-10 09:24:29 -07:00
swift-ci
4d561ee423 Merge pull request #61475 from atrick/liveness-cleanup
Liveness cleanup - preparation for OSSA liveness
2022-10-06 21:35:38 -07:00
Andrew Trick
715d3f7c31 Split PrunedLiveness::findBoundariesInBlock into fast paths
This allows dynamic dispatch into the fast paths. It's also easier to
understand the fast paths when written as separate loops.

This way, we can used MultiDefPrunedLiveness to compute ownership
liveness, but still benefit from the fact that the common case (owned
non-phi value) is much simpler and faster to compute.

This approach is necessary because we use stack-based data structures
within the liveness result, so we need to statically instantiate
something that can handle all cases.
2022-10-06 19:02:24 -07:00
Andrew Trick
eee184ae4e Delete isValueAddressOrTrivial
If we want a short-circuit test for address types, that should be done
within getOwnershipKind() itself.
2022-10-05 06:30:02 -07:00
Erik Eckstein
4a60ea809b Add some Swift SIL infrastructure
* In `ApplySite`: `argumentOperands` and `isCalleeOperand`
* In `ArgumentConvention`: `isIndirect`, `isIndirectIn` and `isGuaranteed`
* In `Function`: `isDefinition`, `numParameterArguments`, `numArguments`, `getArgumentConvention`, `effectAttribute`
* In `Type`: `isFunction` and `isCalleeConsumedFunction`
* In `Instruction`: `hasUnspecifiedSideEffects`
* New bridged instructions: `EndApplyInst` and `AbortApplyInst`
* `LoadInst.ownership`
* `BeginAccessInst.isStatic`
* make the `Allocation` protocol a `SingleValueInstruction` (instead of `AnyObject`)
2022-10-05 07:37:41 +02:00
Andrew Trick
755bce217d Remove complexity in findBoundariesInBlock
We can remove a ton of complexity by assuming that SSA uses never
occur before a def in the same block. This will hold true as long as
useless phis are only removed after all unreachable code is first
removed. Then we don't have the self-loop problem.

The SILVerifier already checks this invariant and I added an in-depth
comment in SimplifyCFG.
2022-10-04 13:27:48 -07:00
Andrew Trick
6861b318ca Make PrunedLiveness::computeSimple one-level transitive
Computing simple liveness is distinct from computing transitive
liveness. But for safety and consistency, always handle the first
level of liveness transitively. This way, computeSimple can be used on
guaranteed values that need OSSA lifetime fixup.

Simple liveness just means that *inner* borrow and address scopes are
assumed to be complete.

This utility is still only used conservatively because OSSA lifetime
completion is not yet enabled. But, in the future, computeSimple can
be used in the common case.
2022-10-04 13:27:48 -07:00
Andrew Trick
6346bf55c5 Rename areUsesWithinTransitiveScope to ...ExtendedScope
Start using consistent terminolfy in ownership utils.

A transitive use set follows transitive uses within an ownership
lifetime. It does not rely on complete inner scopes. An extended use
set is not necessarilly transitive but does look across
lifetime-ending uses: copies of owned values and/or reborrows of
guaranteed values. Whether lifetime extension refers to copies or
reborrow is context dependent.
2022-10-04 13:27:48 -07:00
Andrew Trick
619a638e34 ScopedAddressUtils - clarify the API used for transitive liveness.
Begin to distnguish logic that relies on complete OSSA lifetimes from
the logic that computes transitive uses.
2022-10-04 13:27:47 -07:00
Andrew Trick
da4f1b9a70 Add InnerBorrowKind and AddressUseKind to PrunedLiveness API
The API for computing simple liveness now returns a
SimpleLiveRangeSummary. Callers need to decide how to handle reborrows
and pointer escapes. If either condition exists then the resulting
liveness does not necessarily encapsulate the definition's ownership.

Fixes some number of latent bugs w.r.t. liveness clients.
2022-10-04 13:27:47 -07:00
Andrew Trick
4ef7f8590f Fix findTransitiveUsesForAddress to handle incomplete scopes
This fixes ScopedAddressValue::computeLiveness in unreachable code scenarios.
For example:

   %storeBorrow = store_borrow %_ to %adr
   %loadBorrow  = load_borrow %storeBorrow
   apply %f(%loadBorrow) : $@convention(thin) (...) -> Never

Now recursively process uses of load_borrow as if they are address
uses.

Ultimately, this would be more efficiently handled by a recursive
lifetime completion utility which would fixup the load_borrow scope
before computing the store_borrow liveness.

Fixes rdar://99874173: unreachable assert "No user in LiveWithin block"
2022-10-04 13:27:47 -07:00
Andrew Trick
464e353028 Fix ScopedAddressValue::computeLiveness.
Return the AddressUseKind.

Fixes a bug in extendStoreBorrow where it was looking at an
uninitialized liveness result whenever a pointer escape was present.
2022-10-04 13:27:47 -07:00
Andrew Trick
40e03ef782 Update passes to use SSAPrunedLiveness or MultiDefPrunedLiveness 2022-10-04 13:27:47 -07:00
Andrew Trick
ca503b54b7 Redesign PrunedLiveness APIs, introducing live ranges
First restore the basic PrunedLiveness abstraction to its original
intention. Move code outside of the basic abstraction that polutes the
abstraction and is fundamentally wrong from the perspective of the
liveness abstraction.

Most clients need to reason about live ranges, including the def
points, not just liveness based on use points. Add a PrunedLiveRange
layer of types that understand where the live range is
defined. Knowing where the live range is defined (the kill set) helps
reliably check that arbitrary points are within the boundary. This
way, the client doesn't need to be manage this on its own. We can also
support holes in the live range for non-SSA liveness. This makes it
safe and correct for the way liveness is now being used. This layer
safety handles:

- multiple defs
- instructions that are both uses and defs
- dead values
- unreachable code
- self-loops

So it's no longer the client's responsibility to check these things!

Add SSAPrunedLiveness and MultiDefPrunedLiveness to safely handle each
situation.

Split code that I can't figure out into
DiagnosticPrunedLiveness. Hopefully it will be deleted soon.
2022-10-04 13:27:44 -07:00
Andrew Trick
dab44e3e86 Fix LexicalDestroyHoisting: avoid optimizing when ownership escapes
Fix the utilities used by LexicalDestroyHoisting that finds all uses
to report a "PointerEscape". We can't rely on lifetime analysis when
such a use is present.
2022-09-30 15:20:52 -07:00
Dario Rexin
210c68d8aa [SILOptimizer] Add prespecialization for arbitray reference types (#58846)
* [SILOptimizer] Add prespecialization for arbitray reference types

* Fix benchmark Package.swift

* Move SimpleArray to utils

* Fix multiple indirect result case

* Remove leftover code from previous attempt

* Fix test after rebase

* Move code to compute type replacements to SpecializedFunction

* Fix ownership when OSSA is enabled

* Fixes after rebase

* Changes after rebasing

* Add feature flag for layout pre-specialization

* Fix pre_specialize-macos.swift

* Add compiler flag to benchmark build

* Fix benchmark SwiftPM flags
2022-09-22 16:29:01 -07:00
eeckstein
69431f00e8 Revert "[cxx-interop][SwiftCompilerSources] Use C++ enums directly from Swift" 2022-09-22 11:45:41 +02:00
Egor Zhdan
5f2a641513 [cxx-interop][SwiftCompilerSources] Use swift::SILWitnessTable::WitnessKind instead of `
SILWitnessTableEntryKind`

rdar://83361087
2022-09-20 12:03:48 +01:00
Egor Zhdan
3f1a30c52a [cxx-interop][SwiftCompilerSources] Use swift::SILAccessKind instead of BridgedAccessKind
rdar://83361087
2022-09-20 12:03:48 +01:00
Egor Zhdan
78cdf5eca6 [cxx-interop][SwiftCompilerSources] Use swift::BuiltinValueKind instead of BridgedBuiltinID
rdar://83361087
2022-09-20 12:03:48 +01:00
Andrew Trick
4b361d5bb6 Merge pull request #61145 from atrick/ossa-nonuse-liveness
Handle OperandOwnerhip::NonUse in PrunedLiveness::computeSSALiveness.
2022-09-16 09:35:08 -07:00
Michael Gottesman
c72ddcfb54 Merge pull request #61143 from gottesmm/pr-7e04f5d62651e78c425d1a21b829abaf5096b2b0
[move-only] Add support for trivial move only var/mutating self/inout.
2022-09-15 23:17:47 -07:00
Meghana Gupta
6c0c3dd1e1 Rename hasEscaped -> hasPointerEscape, and don't consider OperandOwnership::BitwiseEscape as a pointer escape 2022-09-15 16:40:39 -07:00
Meghana Gupta
804e3f0968 Merge pull request #61126 from meg-gupta/fixdce
Don't shrink escaped borrow scopes in DCE
2022-09-15 15:47:20 -07:00
Michael Gottesman
724449d579 [move-only] Add support for trivial move only var/mutating self/inout. 2022-09-15 13:55:03 -07:00