Commit Graph

2768 Commits

Author SHA1 Message Date
Meghana Gupta
4cf6f79938 Merge pull request #62714 from meg-gupta/fixassert
Create begin_borrow in OSSA only
2022-12-20 21:49:55 -08:00
Meghana Gupta
18fd845732 Create begin_borrow in OSSA only
Fixes rdar://103512260

Creating begin_borrow in non-ossa can raise asserts or reach unreachable in some utils.
2022-12-20 14:37:37 -08:00
Pavel Yaskevich
3fb69b3c3c [SIL] SILFunction: Add runtime accessible function attribute
This attribute indicates that the given SILFunction has to be
added to "accessible functions" section and could be looked up
at runtime using a special API.
2022-12-20 09:33:44 -08:00
Andrew Trick
02f7450759 At -Onone preserve debug info after splitting loads
Load splitting converts an aggregate load into a set of subobject
loads. This is required at -Onone for exclusivity diagnostics.

We cannot preserve the original debug information by redirecting debug
info to the memory address, because that might result in incorrect
debug values if the memory is reused.

Before this fix, we "conservatively" drop debug info in those
cases. This fix preserves full debug info by keeping the original
aggregate load intact alongside the new subobject loads. To avoid
exclusivity violations, it create a new unsafe access scope for the
old load.

Fixes LLDB missing variables in certain case #62241
2022-12-19 00:02:18 -08:00
Meghana Gupta
10d131d386 Merge pull request #62569 from meg-gupta/checkedcastjumpthreadingbug
Fix CheckedCastBrJumpThreading when we have dominating checked_cast_br on failure path only
2022-12-15 10:31:16 -08:00
Meghana Gupta
6ee4c17abe Merge pull request #62573 from meg-gupta/sbiverify
Update store_borrow checking in MemoryLifetimeVerifier and fix ForEachLoopUnroll and GenericCloner
2022-12-15 09:53:00 -08:00
Michael Gottesman
9e44011e4d [sil] Add a new attribute called @closureCaptured to SILFunctionArguments that are closure capture arguments.
I am adding this to make it easy to determine if a SILFunction that is not inout
aliasable is captured. This is useful when emitting certain types of
diagnostics like I need to emit with move only.
2022-12-14 15:16:43 -08:00
Meghana Gupta
7ad1a183f4 Fix store_borrow's end_borrows in GenericCloner when lifetime boundary cannot be found
Make sure end_borrows are inserted before dealloc_stack. Instead of inserting them at
function exits. Insert before dealloc_stack of destination.
2022-12-14 02:08:38 -08:00
Meghana Gupta
1c05e768b9 Fix OwnershipKind of block argument while creating a preheader 2022-12-13 21:24:07 -08:00
Meghana Gupta
5ab243ec6a Fix CheckedCastBrJumpThreading when we have dominating checked_cast_br on failure path only
In this case, we know the checked_cast_br will have a false outcome.
It is sufficient to transform checked_cast_br into a br and delete the success path.

Before this, we were trying to do an OSSA rauw the successarg which is incorrect.
2022-12-13 21:23:34 -08:00
swift-ci
6d0a3257a3 Merge pull request #62454 from meg-gupta/guaranteedforwardingphiverify
Update guaranteed forwarding phi apis and verification
2022-12-13 20:04:00 -08:00
Meghana Gupta
511739b494 Delete OperandOwnership::GuaranteedForwardingPhi
Use OperandOwnership::GuaranteedForwarding instead.
2022-12-13 12:51:31 -08:00
Nate Chandler
aaf6e97437 [ClosureLifetimeFixup] Shrink arg lifetimes.
Rather than inserting dealloc_stacks at the end of blocks in the
dominance frontier of the alloc_stack, walk backward in the block to the
last user (if any) and insert after that (or at the beginning of the
block if not).  If the transitive uses aren't understood, just insert at
the end of the blocks as before.
2022-12-13 11:46:54 -08:00
Nate Chandler
9ad44a5056 [ClosureLifetimeFixup] Dealloc args on frontier.
Previously, the dealloc_stacks created for the alloc_stacks used to pass
@in_guaranteed arguments to on_stack closures were created after the
users of the closure.  When SILGen created these alloc_stacks in the
same block as the users, this happened to work.  Now that
AddressLowering creates such alloc_stacks elsewhere, this approach
results in invalid SIL.

Here, the dealloc_stacks are instead at the end of each block in the
dominance frontier of the alloc_stack.
2022-12-13 11:46:47 -08:00
nate-chandler
32f9396db6 Merge pull request #62533 from nate-chandler/opaque-values/4/20221209
[ClosureLifetimeFixup] Cleanups get CleanupLocs.
2022-12-13 07:11:26 -08:00
Nate Chandler
9fbbab8045 [ClosureLifetimeFixup] Cleanups get CleanupLocs. 2022-12-12 13:39:56 -08:00
Andrew Trick
f9861ec9c0 Add APIs for terminator results that forward ownership.
Add TermInst::forwardedOperand.

Add SILArgument::forwardedTerminatorResultOperand. This API will be
moved into a proper TerminatorResult abstraction.

Remove getSingleTerminatorOperand, which could be misused because it's
not necessarilly forwarding ownership.

Remove the isTransformationTerminator API, which is not useful or well
defined.

Rewrite several instances of complex logic to handle block arguments
with the simple terminator result API. This defines away potential
bugs where we don't detect casts that perform implicit conversion.

Replace uses of the SILPhiArgument type and code that explicitly
handle block arguments. Control flow is irrelevant in these
situations. SILPhiArgument needs to be deleted ASAP. Instead, use
simple APIs like SILArgument::isTerminatorResult(). Eventually this
will be replaced by a TerminatorResult type.
2022-12-12 12:37:35 -08:00
Nate Chandler
8d8577e5b0 [SIL] Removed Indirect_In_Constant convention.
It is no different from @in.

Continue parse @in_constant in textual and serialized SIL, but just as
an alias for @in.
2022-12-09 21:54:00 -08:00
swift-ci
395064f311 Merge pull request #62286 from nate-chandler/opaque-values/5/20221118
[SILInliner] Borrow guaranteed yields.
2022-12-07 10:31:10 -08:00
Erik Eckstein
d86615830c SILCombine: handle begin_borrow in the partial_apply -> apply peephole optimization 2022-12-01 07:05:02 +01:00
Nate Chandler
182bd34427 [SILInliner] Borrow guaranteed yields.
When inlining a begin_apply, if one of the values is yielded by
guaranteed convention, if the yielded value is itself owned, borrow it
during inlining.

Doing so is necessary because users of the yielded value are expecting a
value with guaranteed ownership.  For example, it's valid to
store_borrow such a value but not an owned value.
2022-11-28 16:53:03 -08: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
Erik Eckstein
65367395a1 SimplifyCFG: fix an argument use-after-erase in CheckedCastBrJumpThreading
Need to check if a SILArgument, which was cached earlier is still alive before doing the actual transformation.

rdar://102108656
2022-11-11 07:58:51 +01:00
Erik Eckstein
0403a21d34 use the new side effects in the performance inliner 2022-11-09 08:06:19 +01:00
Nate Chandler
bfd865b6b6 [ApplySite] Renamed insertAfterApplication.
Now that it can be called on partial_apply instructions,
insertAfterFullEvaluation does not name what the function does.  One
could imagine a function which inserted after the applies of
(non-escaping) partial_applies.
2022-11-03 13:52:42 -07: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
809e67c879 Merge pull request #61776 from tshortli/break-cycle-extend-store-borrow 2022-10-27 19:49:37 -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
ed623d7b64 [NFC] Shortened SIL [init] flag.
Instead of writing out [initalization] for some instructions, use [init]
everywhere.
2022-10-27 10:38:54 -07:00
Andrew Trick
cdbc9170c5 Merge pull request #61648 from atrick/jump-thread
[NFC] OSSA jump-threading support
2022-10-24 21:23:13 -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
070632a195 [ShrinkBorrowScope] Added assertion.
Checked that a barrier terminator's successor isn't a merge point.
2022-10-24 08:46:47 -07:00
Nate Chandler
8bb465a7ef [Gardening] Fixed comment. 2022-10-24 08:32:56 -07:00
Andrew Trick
04aa16f97d OSSA: CheckedCastBrJumpThreading: support using RAUW utility.
Begin adding support for OSSA to checked-cast jump-threading based on
the new ownership utilities.

TODO:

Finish migrating to the new utilities in OwnershipOptUtils.

Ensure full unit test coverage.
2022-10-22 21:57:47 -07:00
Andrew Trick
d386d1ba05 Fix OSSA RAUW perform() to handle replaceAllUsesWith for terminators 2022-10-22 21:57:47 -07:00
nate-chandler
a0207916cb Merge pull request #61655 from nate-chandler/shrink_borrow_scope/dont_hoist_over_only_rewritten_copies
[ShrinkBorrowScope] Leave under rewritten copies.
2022-10-21 16:34:46 -07:00
Nate Chandler
a4d31a468b [ShrinkBorrowScope] Leave under rewritten copies.
When shrinking a borrow scope like

    %borrow = begin_borrow %value
    barrier
    %copy = copy_value %borrow
    end_borrow %borrow

the copy will be rewritten to be a copy of the borrowee:

    %borrow = begin_borrow %value
    barrier
    %copy = copy_value %value
                       ^^^^^^
    end_borrow %borrow

If, as here, shrinking next encounters a barrier, then the insertion
point will be that rewritten copy_value instruction.

In such a case, when rather than creating a new end_borrow there and
deleting the old, just reuse the old one.  The lifetime of the value
being copied will be canonicalized by CopyPropagation regardless.
2022-10-20 18:09:54 -07:00
Meghana Gupta
569b2aa36e Update castValueToABICompatibleType for @guaranteed forwarding phi support 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
4b85d0a9ca [DestroyHoisting] Barriers use callee analysis.
Pass a BasicCalleeAnalysis instance to isDeinitBarrier.  This enables
LexicalDestroyHoisting to hoist destroys over applies of functions which
are not deinit barriers.
2022-10-18 21:23:22 -07:00
Nate Chandler
f85074d1ba [ShrinkBorrowScope] Barriers use callee analysis.
Pass a BasicCalleeAnalysis instance to isDeinitBarrier.  This will allow
ShrinkBorrowScope to hoist end_borrows over applies of functions which
are not deinit barriers.
2022-10-18 21:23:22 -07:00
Nate Chandler
4476088ab5 [ComputeSideEffects] Track deinit-barrier-ness.
Functions "are deinit barriers" (more pedantically, applies of functions
are deinit barriers) if any of their instructions are deinit barriers.
During side-effect analysis, when walking a function's instructions for
other global effects, also check for the deinit-barrier effect.  If an
instruction is found to be a deinit barrier, mark the function's global
effects accordingly.

Add SILFunction::isDeinitBarrier to conveniently access the effects
computed during ComputeSideEffects.

Update the isBarrierApply predicate to iterate over the list of callees,
if complete, to check whether any is a deinit barrier.  If none is, then
the apply is not a deinit barrier.
2022-10-18 21:23:22 -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
Slava Pestov
36c01e80cc Merge pull request #61537 from hborla/variadic-generics-terminology
[AST] Use consistent variadic generics terminology.
2022-10-13 16:20:43 -04: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
Holly Borla
c4b946195e [AST] Replace the "type sequence" terminology with "parameter pack". 2022-10-10 16:28:13 -07:00
Holly Borla
9bb837a241 [AST] Rename SequenceArchetype to PackArchetype. 2022-10-10 16:25:26 -07:00