Commit Graph

2043 Commits

Author SHA1 Message Date
John McCall
6bf9ac858b Add instructions to allocate and deallocate packs.
Having added these, I'm not entirely sure we couldn't just use
alloc_stack and dealloc_stack.  Well, if we find ourselves adding
a lot of redundancy with those instructions (e.g. around DI), we
can always go back and rip these out.
2023-01-31 22:39:34 -05:00
John McCall
b4e1e52553 Merge pull request #63292 from rjmccall/lower-pack-types
Explicitly lower value pack and parameter expansion types in SIL
2023-01-29 13:16:08 -05:00
John McCall
d25a8aec8b Add explicit lowering for value packs and pack expansions.
- SILPackType carries whether the elements are stored directly
  in the pack, which we're not currently using in the lowering,
  but it's probably something we'll want in the final ABI.
  Having this also makes it clear that we're doing the right
  thing with substitution and element lowering.  I also toyed
  with making this a scalar type, which made it necessary in
  various places, although eventually I pulled back to the
  design where we always use packs as addresses.

- Pack boundaries are a core ABI concept, so the lowering has
  to wrap parameter pack expansions up as packs.  There are huge
  unimplemented holes here where the abstraction pattern will
  need to tell us how many elements to gather into the pack,
  but a naive approach is good enough to get things off the
  ground.

- Pack conventions are related to the existing parameter and
  result conventions, but they're different on enough grounds
  that they deserve to be separated.
2023-01-29 03:29:06 -05:00
Nate Chandler
4f845ccc52 [CanOSSALifetime] Option to shrink to scopes.
For most uses, some access scopes must be "respected"--if an extended
value's original lifetime originally extends beyond an access scope, its
canonicalized lifetime must not end _within_ such scopes (although
ending before them is fine).  Currently, to be conservative, the utility
applies this behavior to all access scopes.

For move-only values, however, lifetimes end at final consumes without
regard to access scopes.

Allow this behavior to be controlled by whether or not a
NonLocalAccessBlockAnalysis is provided to the utility in its
constructor.

rdar://104635319
2023-01-28 10:23:22 -08:00
nate-chandler
2fc7659ed7 Merge pull request #60670 from nate-chandler/lexical_lifetimes/owned_arguments
[SIL] Maintain owned argument lifetimes at inlining.
2023-01-26 18:30:24 -08:00
Andrew Trick
21f69d4741 Revert "At -Onone preserve debug info after splitting loads"
This reverts commit 02f7450759.

Fixes rdar://104667596 (incorrectly reports an error when resolving
initialization out of a switch)
2023-01-26 10:04:05 -08:00
swift-ci
281088eb73 Merge pull request #63204 from meg-gupta/ptrauthcodegenpr
Initial support for ptrauth qualified function pointers in C
2023-01-25 22:19:34 -08:00
Nate Chandler
10e86d6653 [CanonicalizeBorrowScope] Look through moves.
When encountering inside a borrow scope a non-lexical move_value or a
move_value [lexical] where the borrowed value is itself already lexical,
delete the move_value and regard its uses as uses of the moved-from
value.
2023-01-25 16:32:09 -08:00
Anthony Latsis
8eee0fff5e Merge pull request #62677 from valeriyvan/CanonicalizeOSSALifetime-enum 2023-01-26 02:30:45 +03:00
Meghana Gupta
ba052abec1 Add signed access enforcement to begin_access
This will be used for supporting imported c function pointers with custom __ptrauth qualifier.
2023-01-25 14:03:15 -08:00
Nate Chandler
794e33669e [ConstExpr] Look through move_value insts.
Just like begin_borrow and copy_value, move_value should be looked
through because the interpreter doesn't model the memory operation it
encodes.
2023-01-25 11:36:33 -08:00
Nate Chandler
69d1abe0c5 [SIL] Protect owned arg lifetimes at inlining.
Previously, `begin_borrow [lexical]` were created during SILGen for
@owned arguments.  Such borrows could be deleted if trivially dead,
which was the original reason why @owned arguments were considered
lexical and could not have their destroys hoisted.

Those borrows were however important during inlining because they would
maintain the lifetime of the owned argument.  Unless of course the
borrow scope was trivially dead.  In which case the owned argument's
lifetime would not be maintained.  And if the caller's value was
non-lexical, destroys of the value could be hoisted over deinit
barriers.

Here, during inlining, `move_value [lexical]`s are introduced during
inlining whever the caller's value is non-lexical.  This maintains the
lifetime of the owned argument even after inlining.
2023-01-25 11:36:33 -08:00
Nate Chandler
6e97889305 [SILInliner] Only add lexical borrows when needed.
If a guaranted function argument is lexical, its lifetime must be
mainted during inlining.  If the caller's value is already lexical,
no work is required to do the inlining.
2023-01-25 11:36:33 -08:00
Valeriy Van
735faf9f19 Fix looking odd logical expression mixing bool and enum 2023-01-25 17:04:12 +02:00
Andrew Trick
f5480ade92 Cleanup canonicalize OSSA reborrow handling and add tests 2023-01-24 22:15:12 -08:00
Ellie Shin
91f785441f Merge pull request #62652 from apple/es-pkg-acl
[NFC] Add 'package' access modifier to AccessLevel
2023-01-20 13:58:15 -08:00
John McCall
374c202b99 Add SIL instructions to generate pack indices 2023-01-19 23:57:22 -05:00
Ellie Shin
37af51dc4c Merge branch 'main' into es-pkg-acl 2023-01-19 16:18:17 -08:00
Ellie Shin
1c66d02f92 Add package access level to enum AccessLevel
Resolves rdar://104198440
2023-01-19 15:54:18 -08:00
Erik Eckstein
edce513580 SIL: simplify replaceBranchTarget
Instead of re-creating all kind of terminator instructions, just re-assign the terminator's successor.
2023-01-16 18:55:35 +01:00
Andrew Trick
599b1d1ae4 Handle guaranteed phis conservatively in a few more places. 2023-01-13 08:55:16 -08:00
John McCall
37baf9b2dc Add a SIL instruction to open a pack as an element archetype
IRGen not yet done.
2023-01-11 03:11:30 -05:00
Meghana Gupta
3660a1e6a9 Remove borrow scope adjustment for @guaranteed phi args 2023-01-06 23:50:07 -08:00
Erik Eckstein
8816034ab2 SILInliner: make SILInliner::Loc not an optional
It's not needed because it always has a value
2023-01-02 13:37:31 +01:00
Erik Eckstein
21b4004d69 Devirtualizer: don't de-virtualize witness calls to non-generic thunks which call a generic function.
If the callee is a non-generic thunk which calls a (not inlinable) generic function in the defining module,
it's more efficient to not devirtualize, but call the non-generic thunk - even though it's done through the witness table.
Example:
```
  protocol P {
    func f(x: [Int])   // not generic
  }
  struct S: P {
    func f(x: some RandomAccessCollection<Int>) { ... } // generic
  }
```

In the defining module, the generic conformance can be fully specialized (which is not possible in the client module, because it's not inlinable).

rdar://102623022
2022-12-21 08:52:53 +01:00
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