Commit Graph

2610 Commits

Author SHA1 Message Date
swift-ci
3561327bdb Merge remote-tracking branch 'origin/main' into rebranch 2023-08-08 21:33:48 -07:00
Meghana Gupta
1075f77822 Merge pull request #67521 from meg-gupta/migratedoe
Migrate DeadObjectElimination to OSSA
2023-08-08 21:27:06 -07:00
swift-ci
9742461a27 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-08 13:17:04 -07:00
Meghana Gupta
848466acbe Ensure no module transform is added in the function pipeline 2023-08-08 11:04:46 -07:00
Meghana Gupta
996fd8b978 Bail out from deleting a dead objection on seeing stores with lexical non-trivial source 2023-08-08 10:48:09 -07:00
Meghana Gupta
abdb9f0dba DeadObjectElimination: Handle allocating apply in ossa 2023-08-07 14:58:57 -07:00
Meghana Gupta
2831f2f528 Add findPointerEscape check on store source, before shortening its lifetime by inserting destroy at the store 2023-08-07 10:21:40 -07:00
Meghana Gupta
c3c78fa8f8 DeadObjectElimination: Handle alloc_ref in ossa 2023-08-07 10:21:40 -07:00
Meghana Gupta
f5c5c9e36b In non-ossa, ban non-trivial stores to alloc_ref's projections even the dtor is not inlined
There is no implementation to handle insertion of compensating releases of the non-trivial store's src for this case.
This never really happens, because destructor analysis is very limited and we end up banning alloc_ref with ref count instructions.
2023-08-07 10:21:40 -07:00
Meghana Gupta
768d98e1c4 Add a TODO in destructor analysis 2023-08-07 10:21:40 -07:00
Meghana Gupta
15e5364d25 DeadObjectElimination: Handle keypaths with non-trivial operands in OSSA 2023-08-07 10:21:40 -07:00
Meghana Gupta
41697b061c DeadObjectElimination: Handle non-trivial stores while processing alloc_stack 2023-08-07 10:21:40 -07:00
swift-ci
8308afaaf0 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-01 17:33:45 -07:00
Joe Groff
03eec7da2b Remove redundant SILType::isMoveOnlyNominalType (NFC)
and implement `SILType::isPureMoveOnly` in terms of `Type::isPureMoveOnly`.
2023-08-01 14:07:38 -07:00
swift-ci
7bef9fd31a Merge remote-tracking branch 'origin/main' into rebranch 2023-07-31 21:34:34 -07:00
Nate Chandler
4f16bb1a74 [Mem2Reg] Don't canonicalize undef.
They aren't the kind of values whose lifetimes are eligible for
canonicalization.

rdar://113121424
2023-07-31 16:20:37 -07:00
Nate Chandler
f276ebf37e [Mem2Reg] Only lifetime canonicalize in OSSA.
Bail both on collecting stores and canonicalizing values if the function
being optimized doesn't have ownership.
2023-07-31 16:16:28 -07:00
swift-ci
1c1be7d116 Merge remote-tracking branch 'origin/main' into rebranch 2023-07-28 15:36:57 -07:00
swift-ci
1cca22bafe Merge pull request #67526 from nate-chandler/mem2reg/canonicalize-values
[Mem2Reg] Canonicalize promoted lifetimes.
2023-07-28 15:30:59 -07:00
Nate Chandler
b563c4ea3d [Mem2Reg] Canonicalize new phis.
Mem2Reg introduces new OSSA values in the form of phis.  Take
responsibility for canonicalizing their lifetimes.
2023-07-28 13:21:13 -07:00
Nate Chandler
52ce100ef4 [Mem2Reg] Canonicalize stored values.
Stored values may now be canonicalizable, now that they have one less
consuming use.
2023-07-28 13:19:52 -07:00
swift-ci
1ead4ffed7 Merge remote-tracking branch 'origin/main' into rebranch 2023-07-28 10:57:58 -07:00
Nate Chandler
e5d87f75a8 [SIL] Add source formal type to checked_cast_br.
It is necessary for opaque values where for casts that will newly start
out as checked_cast_brs and be lowered to checked_cast_addr_brs, since
the latter has the source formal type, IRGen relies on being able to
access it, and there's no way in general to obtain the source formal
type from the source lowered type.
2023-07-27 15:04:15 -07:00
Nate Chandler
7fb9bcade8 [Mem2Reg] NFC: Lifted livePhiBlocks higher.
Move it all the way up into MemoryToRegisters::run in preparation for
using it to canonicalize new phis.
2023-07-26 21:27:35 -07:00
Nate Chandler
c9e0bb5a67 [Mem2Reg] NFC: Removed spurious typealias.
`BlockSetVector` is not much shorter than `BasicBlockSetVector`, and there's
no reason to tie the type to `StackAllocationPromoter`.
2023-07-26 21:27:35 -07:00
Nate Chandler
496761407c [Mem2Reg] NFC: Fixed comments.
Corrected the comments describing what the
`promoteSingleBlockAllocation` and `promoteMultiBlockAllocation`
functions do since they were no longer accurate.
2023-07-26 21:27:35 -07:00
Nate Chandler
e321fc4dc8 [Mem2Reg] NFC: Improved function name.
Previously there were the functions `promoteSingleAllocation` and
`removeSingleBlockAllocation`.  The distinction between these based on
the name alone is a bit subtle.  Shortened the name of
`promoteSingleAllocation` to `promoteAllocation`.
2023-07-26 21:27:35 -07:00
Evan Wilde
0f38040832 [NFC] Update more APIs for std::optional
`std::optional` doesn't have `hasValue` or `getPointer`. Using the
implicit decay to boolean, and grabbing the pointer to the element by
expanding the optional and grabbing the reference address.
2023-07-25 12:28:28 -07:00
Evan Wilde
fd156f2717 More APInt API updates
Updating more APInt and bit-manipulation API changes.
2023-07-25 12:28:27 -07:00
Evan Wilde
309aed4925 Add SmallSetVector replacement
llvm::SmallSetVector changed semantics
(https://reviews.llvm.org/D152497) resulting in build failures in Swift.
The old semantics allowed usage of types that did not have an
`operator==` because `SmallDenseSet` uses `DenseSetInfo<T>::isEqual` to
determine equality. The new implementation switched to using
`std::find`, which internally uses `operator==`. This type is used
pretty frequently with `swift::Type`, which intentionally deletes
`operator==` as it is not the canonical type and therefore cannot be
compared in normal circumstances.

This patch adds a new type-alias to the Swift namespace that provides
the old semantic behavior for `SmallSetVector`. I've also gone through
and replaced usages of `llvm::SmallSetVector` with the
`Swift::SmallSetVector` in places where we're storing a type that
doesn't implement or explicitly deletes `operator==`. The changes to
`llvm::SmallSetVector` should improve compile-time performance, so I
left the `llvm::SmallSetVector` where possible.
2023-07-25 12:28:27 -07:00
Erik Eckstein
4d20423e00 Optimizer: re-implement the RedundantLoadElimination pass in Swift
The new implementation has several benefits compared to the old C++ implementation:

* It is significantly simpler. It optimizes each load separately instead of all at once with bit-field based dataflow.
* It's using alias analysis more accurately which enables more loads to be optimized
* It avoids inserting additional copies in OSSA

The algorithm is a data flow analysis which starts at the original load and searches for preceding stores or loads by following the control flow in backward direction.
The preceding stores and loads provide the "available values" with which the original load can be replaced.
2023-07-21 07:19:56 +02:00
Evan Wilde
83b044f5fb Migrating LLVM API usage on main
This patch migrates the compiler off of the deprecated LLVM APIs where I
can.

 - APInt::getAllOnesValue -> APInt::getAllOnes
 - APInt::getNullValue -> APInt::getZero
 - APInt::isNullValue -> APInt::isZero
 - APInt::getMinSignedBits -> APInt::getSignificantBits
 - clang::Module::submodule_{begin,end} -> clang::Module::submodules
2023-07-13 11:22:35 -07:00
nate-chandler
f423115b71 Merge pull request #67218 from nate-chandler/rdar112078094
[AllocBoxToStack] Computing partial_apply frontier looks thru copies+moves.
2023-07-12 07:11:20 -07:00
Nate Chandler
6cf2bb4151 [AllocBoxToStack] PAI frontier looks thru moves.
When determining where to destroy a captured alloc_box, the frontier of
the capturing partial_apply is computed.  Previously, that computation
just used the uses of the partial_apply.  If the partial_apply were
moved and the original destroyed before the apply, however, the result
would be a miscompile where the destroy_addr/dealloc_stack for the
alloc_stack to which the alloc_box was promoted was destroyed before the
apply of the closure which used the address.
2023-07-11 16:27:47 -07:00
Nate Chandler
15ce42ae09 [AllocBoxToStack] PAI frontier looks thru copies.
When determining where to destroy a captured alloc_box, the frontier of
the capturing partial_apply is computed.  Previously, that computation
just used the uses of the partial_apply.  If the partial_apply were
copied and the original destroyed before the apply, however, the result
would be a miscompile where the destroy_addr/dealloc_stack for the
alloc_stack to which the alloc_box was promoted was destroyed before the
apply of the closure which used the address.
2023-07-11 16:27:27 -07:00
Joe Groff
3d5285be6f Arrange for closure bodies promoted by AllocBoxToStack to have their originals removed by MoveOnlyChecker.
This is an improvement of #67031 which avoids deleting the closure function
body during AllocBoxToStack, which still breaks pass invariants by modifying
functions other than the currently-analyzed function. As a function pass,
AllocBoxToStack also doesn't really know with certainty whether the original
closure function is unused after stack promotion or not. We still want to
eliminate the original when it may contain invalid SIL for move-only values
that rely on the escape analysis for correct semantics, so rather than mark the
original function to be *ignored* during move-only checking, mark it to be
*deleted* by move-only checking if the function is in fact unused at that
point.

If the marked function is still used, we let it pass through move-only
checking normally, which may cause redundant diagnostics but is the right
thing to do since code is still potentially using the closure with escaping
semantics. We should rearrange things to make this situation impossible in
the future.

rdar://110675352
2023-07-10 15:18:16 -07:00
Joe Groff
8d974212f1 Revert "AllocBoxToStack: Remove bodies of closure functions left unused after specialization."
This reverts commit bd5f0a7af0.
2023-07-10 12:43:21 -07:00
Erik Eckstein
baaf5565b0 Optimizer: reimplement DeadStoreElimination in swift
The old C++ pass didn't catch a few cases.
Also:
* The new pass is significantly simpler: it doesn't perform dataflow for _all_ memory locations at once using bitfields, but handles each store separately. (In both implementations there is a complexity limit in place to avoid quadratic complexity)
* The new pass works with OSSA
2023-07-05 21:33:25 +02:00
Nate Chandler
b9b286eff2 [Test] Ensourced simplify-cfg-try-jump-threading.
Moved the test next to the code it calls.
2023-07-04 11:52:13 -07:00
Nate Chandler
f1d61afdfb [Test] Ensourced simplify-cfg-simplify....
-term-with-identical-dest-blocks.  Moved the test next to the code it
calls.
2023-07-04 11:52:13 -07:00
Nate Chandler
736b1afb4d [Test] Ensourced simplify-cfg-simplify-switch....
-enum-unreachable-blocks.  Moved the test next to the code it calls.
2023-07-04 11:52:13 -07:00
Nate Chandler
d57b1e5fee [Test] Ensourced simplify-cfg-simplify-switch....
-enum-on-objc-class-optional.  Moved the test next to the code it calls.
2023-07-04 11:52:13 -07:00
Nate Chandler
49bc5a66d4 [Test] Ensourced simplify-cfg-simplify-switch....
-enum-block.  Moved the test next to the code it calls.
2023-07-04 11:52:13 -07:00
Nate Chandler
bf229c357e [Test] Ensourced simplify-cfg-canonicalize....
-switch-enum.  Moved the test next to the code it calls.
2023-07-04 11:52:13 -07:00
Nate Chandler
df02726e7b [Test] Ensourced simplify-cfg-simplify-block-args.
Moved the test next to the code it calls.
2023-07-04 11:52:13 -07:00
Nate Chandler
bc909e5b28 [Test] Ensourced simplify-cfg-simplify-argument.
Moved the test next to the code it calls.
2023-07-04 11:52:13 -07:00
Joe Groff
421c762862 Merge pull request #67031 from jckarter/allocbox-to-stack-remove-unused-original-bodies
AllocBoxToStack: Remove bodies of closure functions left unused after specialization.
2023-06-30 08:30:42 -07:00
Joe Groff
bd5f0a7af0 AllocBoxToStack: Remove bodies of closure functions left unused after specialization.
We can't remove the functions at this point in case they might have other function
passes enqueued to run on them, but we can at least remove the function contents
that are now unnecessary. We need to do this in cases when move-only types are
involved, since the semantics of the move checker rely on unescaped captures being
promoted before the pass runs, and we leave behind invalid SIL in the unpromoted code.
rdar://110675352
2023-06-29 13:45:07 -07:00
Meghana Gupta
c8001d86b1 Add a wrapper type SelectEnumOperation
SelectEnumInstBase will be templated in the next commit.
Instead of using templated SelectEnumInstBase everywhere, introduce
a new wrapper type SelectEnumOperation.
2023-06-28 14:29:10 -07:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00