Commit Graph

1065 Commits

Author SHA1 Message Date
John McCall
7a89642341 Merge pull request #63488 from rjmccall/pack_element_getset
Add SIL instructions to get and set pack elements
2023-02-07 11:48:48 -05:00
Andrew Trick
4224d940ec Add visitInnerAdjacentPhis OSSA helper
This API is the inverse of visitEnclosingDefs when called on a phi.

This replaces the visitAdjacentReborrowsOfPhi algorithm with a small
loop that simply checks all the phis in the current block.

This should all be fairly efficient once SILArgument has a "reborrow"
flag.
2023-02-06 23:11:23 -08:00
John McCall
27142e42f6 Add SIL instructions to get and set pack elements 2023-02-07 01:10:15 -05:00
Andrew Trick
b893de6df2 Tweak findTransitiveUsesForAddress implementation
Record uses even when they escape a pointer. This is more consistent
and helps avoids corner cases involving dead address producers.
2023-02-06 18:25:15 -08:00
Andrew Trick
403c37a680 Tweak findTransitiveUsesForAddress implementation
Record uses even when they escape a pointer. This is more consistent
and helps avoids corner cases involving dead address producers.
2023-02-06 11:16:18 -08:00
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
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
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
Michael Gottesman
89176928ee Merge pull request #63213 from gottesmm/rdar103271138
[move-only] Implement borrow+struct_extract to restructure transform
2023-01-26 07:19:10 -08:00
Michael Gottesman
885eb21d37 [noimplicitcopy] Changes to borrow+gep -> destructure transform to support noimplicitcopy. 2023-01-25 14:55:52 -08:00
Nate Chandler
4422cdcc06 [OwnershipUtils] Match complex nested borrows.
Recognize lexical borrows as nested when their borrowee's guaranteed
reference roots are all lexical borrows.

Addresses the following regressions

Breadcrumbs.MutatedUTF16ToIdx.Mixed         188     882     +369.1%   **0.21x**
Breadcrumbs.MutatedIdxToUTF16.Mixed         230     926     +302.6%   **0.25x**

seen when enabling lexical lifetimes in the standard library.
2023-01-25 11:39:42 -08:00
Nate Chandler
9b185574d3 [Projection] Look through move_value insts. 2023-01-25 11:39:42 -08:00
Nate Chandler
3277d0e35b [InstUtils] Look through move as copy/cast inst.
Add move_value to the list of instructions through which
getSingleValueCopyOrCast looks.
2023-01-25 11:36:33 -08:00
Nate Chandler
329dd2c980 [InstUtils] Look through move as ownership inst.
Add move_value to the list of ownership instructions through which
lookThroughOwnershipInsts looks.
2023-01-25 11:36:33 -08:00
Andrew Trick
5d0fbaad5c Merge pull request #63210 from atrick/cleanup-prunedliveness
Cleanup PrunedLiveness interface.
2023-01-25 10:13:43 -08:00
Erik Eckstein
7d8bf37e5e change to the new llvm::Optional APIs
This is a follow-up of https://github.com/apple/swift/pull/62217
2023-01-25 09:18:36 +01:00
Andrew Trick
7990dda02b Cleanup PrunedLiveness interface.
In preparation for adding OwnershipLiveness.

Rename Simple LiveRangeSummary to LiveRangeSummary.

Add initializeDefNode helpers to avoid confusion about the argument
type.

Add defBegin/defEnd iterators in MultiDefPrunedLiveness.
2023-01-24 23:26:40 -08:00
Michael Gottesman
e15eab5020 [ownership] Change ForwardingOperand::visitForwardingValues to handle ForwardingOwned terminators that are function exiting correctly.
Previously, we would have just asserted when we passed the operand to
PhiOperand on the next line of the code.
2023-01-24 16:55:54 -08:00
Michael Gottesman
4ad2bc93ba [field-sensitive-pruned-liveness] Some small changes.
Specifically:

1. I added to the documentation at the top of the file that our representation
allows for partial init/reinit of structs/tuples from parts.

2. I renamed SubElementNumber to SubElementOffset. This I think fits the actual
use case better and makes it clearer what one is working with (the offset inside
a type of a subelement of the type).

3. I added some small helpers to TypeSubElementCount and SubElementOffset for
adding/subtracting from them.

4. I added the ability to iterate over just consuming/nonconsuming users in
FieldSensitivePrunedLiveness. Just a useful little helper.
2023-01-24 15:28:12 -08:00
John McCall
374c202b99 Add SIL instructions to generate pack indices 2023-01-19 23:57:22 -05:00
Michael Gottesman
ce39f365a8 [move-only] Fix a small thinko.
Specifically, I forgot that when asserts are disabled I made
FieldSensitivePrunedLivenessBoundary::getNumLastUsersAndDeadDefs() assert to
make sure that callers were sure to place it within a #ifndef block since it is
rather expensive and not actual used in the computation. Funnily, I forgot to
end.

rdar://104107922
2023-01-18 19:09:58 -08:00
Erik Eckstein
d96ef3bedd Swift SIL: add some APIs to Location
* `var description`
* `func ==`
* `func hasSameSourceLocation(as:)`
2023-01-16 19:00:09 +01:00
Erik Eckstein
3f457eb1d4 Swift SIL: add IntegerLiteralInst.value 2023-01-16 19:00:09 +01:00
Erik Eckstein
221a16ba17 Swift SIL: add more arguments to Builder.createApply
add the `isNonThrowing` and `isNonAsync` flags and the `specializationInfo`
2023-01-16 19:00:09 +01:00
Erik Eckstein
cf8c68c6c4 Swift SIL: add Type.hasArchetype 2023-01-16 19:00:09 +01:00
Erik Eckstein
230c93df30 SIL Optimizer: add some SIL modification APIs
* `MutatingContext.notifyInvalidatedStackNesting` and `MutatingContext.needFixStackNesting`
* `MutatingContext.tryDeleteDeadClosure`
* `MutatingContext.erase(block:)`
* `Undef.get`
* `BasicBlock.moveAllInstructions`
* `BasicBlock.eraseAllArguments`
* `BasicBlock.moveAllArguments`
* `TermInst.replaceBranchTarget`
2023-01-16 19:00:09 +01:00
Andrew Trick
7dc9405131 Add a visited set for PrunedLiveness guaranteed value. 2023-01-13 14:16:15 -08:00
Andrew Trick
599b1d1ae4 Handle guaranteed phis conservatively in a few more places. 2023-01-13 08:55:16 -08:00
swift-ci
c547f57b06 Merge pull request #62737 from valeriyvan/PrunedLiveness-null-derefence
Fix NULL pointer dereference
2023-01-12 03:53:22 -08:00
John McCall
9aeddd0b41 Merge pull request #62955 from rjmccall/open_pack_element
Add the open_pack_element instruction
2023-01-11 13:17:46 -05:00
swift-ci
93a0a6d905 Merge pull request #62914 from ktoso/wip-task-group-twotypes
[Concurrency] DiscardingTaskGroup (rev 3)
2023-01-11 01:37:33 -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
Michael Gottesman
0a05cd0c31 Merge pull request #62935 from gottesmm/pr-114a0082fe0f258851f6d645c8c5d5c72d5df2a1
[move-only-addr] Fix an assert and add some more tests.
2023-01-10 13:44:37 -08:00
Andrew Trick
208bb76ce3 Fix MultiDefPrunedLiveness; add boundaries for dead end blocks.
Make sure liveness reports a complete boundary even for OSSA lifetimes
that are incomplete. Definition blocks can be on the liveness boundary
in this case.
2023-01-09 23:01:37 -08:00
Michael Gottesman
65fd488ee6 [field-pruned-liveness] Enable an assert when computing boundaries with the correct condition. 2023-01-09 14:33:07 -08:00
Andrew Trick
07d4655fb7 Fix an assert in MultiDefPrunedLiveness
Fixes an assert that was meant for a narrow case and accidentally
applied too broadly.

This variation of the liveness utilities wasn't being exercised widely,
and is difficult to test with valid OSSA.
2023-01-09 13:46:58 -08:00
Michael Gottesman
1c459b6c5b [move-only-addr] Wire up the move only address checker to Field Sensitive Pruned Liveness Boundary.
This let me fix an issue around hoisting destroy_addr/store [assign] when
working in multi-block cfgs.

I also added some .sil tests.
2023-01-08 21:51:40 -08:00
swift-ci
0c6253ebd2 Merge pull request #61824 from meg-gupta/simplifycfgossapr1
Update some parts of SimplifyCFG for OSSA
2023-01-08 03:07:46 -08:00
Meghana Gupta
5d2967ca75 Fix SimplifyCFG::simplifySwitchEnumOnObjcClassOptional for OSSA 2023-01-08 00:15:17 -08:00
Michael Gottesman
5dceb82a76 [pruned-liveness] Change computeScalarUseBlockLiveness to internally sue the scalar version of markBlockLive 2023-01-07 14:40:04 -08:00
Michael Gottesman
82abf02883 [pruned-liveness] Change the internal machinery of updateForUse to use only scalar logic.
I did this by doing the following:

1. I renamed computeUseBlockLiveness to computeScalarUseBlockLiveness and
changed it to take a specific bit that it is testing for.

2. I changed the logic that already existed in this code path that worked scalar
by scalar to use scalar logic rather than call the broken multi-bit at a time
code path.

3. We took advantage of resultingFoundLiveness now only returning the requested
bits instead of all bits. This ensures that we do not run
computeScalarUseBlockLiveness for those unneeded dead bits resulting in liveness
being inappropriately propagated into predecessors.
2023-01-07 14:28:41 -08:00
Michael Gottesman
72c72968e8 [pruned-liveness] Make it so that PrunedLiveBlocks prints out all bits except just the first bit. 2023-01-07 14:14:59 -08:00
Konrad `ktoso` Malawski
f8b85015c1 prepare flags
wip on options

implement discardResults as a flag passed to grout init
2023-01-05 16:19:05 +09:00
Andrew Trick
0a9484597f Add findEnclosingDefs and findBorrowIntroducers utilities.
These APIs are essential for complete OSSA liveness analysis.  The
existing ad-hoc OSSA logic always misses some of the cases handled by
these new utilities. We need to start replacing that ad-hoc logic with
new utilities built on top of these APIs to define away potential
latent bugs.

Add FIXMEs to the inverse API: visitAdjacentBorrowsOfPhi. It should
probably be redesigned in terms of these new APIs.
2023-01-03 09:33:39 -08:00
Andrew Trick
c2ae7e0359 Add visitForwardedGuaranteedOperands utility.
Factors a mess of code in MemAccessUtils to handle forwarding
instruction types into a simpler utility. This utility is also needed
for ownership APIs, which need to be extended to handle these cases.
2023-01-03 09:33:39 -08:00
Valeriy Van
ad33e6a7f7 Fix NULL pointer dereference 2022-12-21 22:58:00 +02:00
Erik Eckstein
93dd07f5f2 replace llvm::NoneType::None -> None
This is needed for the rebranch.
2022-12-19 13:38:13 +01:00
Meghana Gupta
e2c53dd469 Merge pull request #62570 from meg-gupta/fixossaapi
[OSSA] Minor fixes to swift::findTransitiveUsesForAddress
2022-12-15 10:30:17 -08:00
Meghana Gupta
9360b7bfdb Record debug_value and end_borrow as leaf uses in swift::findTransitiveUsesForAddress
Otherwise the default is AddressUseKind::Unknown
2022-12-13 22:18:14 -08:00
Meghana Gupta
208298ed3e Fix findTransitiveUsesForAddress when foundUses vector is nullptr
The api should not behave differently when foundUses is nullptr.
The only difference should be in populating it.

No tests. Found by code inspection.
2022-12-13 22:18:08 -08:00