Commit Graph

1057 Commits

Author SHA1 Message Date
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
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
Meghana Gupta
b10563909c Update isGuaranteedForwarding api and delete isGuaranteedForwardingPhi api 2022-12-13 12:51:25 -08:00
eeckstein
cb6737269d Merge pull request #62480 from eeckstein/instruction-iteration
SIL: simplify deleting instructions while iterating over instructions.
2022-12-13 10:45:06 +01: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
Erik Eckstein
a8ba48e71d Swift SIL: add Instruction.isDeleted API 2022-12-12 19:08:57 +01:00
Erik Eckstein
9e0b86ddbd Swift SIL: add Builder.createUnreachable() 2022-12-12 19:08:57 +01: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