Commit Graph

11193 Commits

Author SHA1 Message Date
Nate Chandler
6d9ae19629 [DCE] Don't complete lifetimes of erased values.
DCE may enqueue a value for lifetime completion and later on erase the
instruction that defines that value.  When erasing an instruction, erase
each of its results from the collection of values to complete.

rdar://141560546
2024-12-19 15:16:32 -08:00
Nate Chandler
f75f12b681 [DCE] Add delete handler for phi erasure.
Set CallsChanged when appropriate and increment NumDeletedInsts.
2024-12-19 15:12:24 -08:00
Nate Chandler
00116edcfb [NFC] DCE: TermInsts increment NumDeletedInsts. 2024-12-19 15:12:24 -08:00
Nate Chandler
1851e712f8 [Gardening] DCE: Use bound variable in branch.
Rather than reusing the source of the dyn_cast.
2024-12-19 15:12:24 -08:00
Allan Shortlidge
17dfbf5053 AST: Adopt SemanticAvailableAttr for SpecializeAttr. 2024-12-19 08:40:00 -08:00
nate-chandler
419d87d630 Merge pull request #78105 from nate-chandler/rdar141197164
[SILGenCleanup] Complete lifetimes of defs backwards reachable from dead-end blocks.
2024-12-18 20:28:01 -08:00
Nate Chandler
c327c59460 [SGC] Complete deadend-reachable lifetimes.
For a function to have complete lifetimes, the lifetime of every def in
the function which is backwards-reachable from a dead-end block must be
completed.

Previously, every def in every block which appears in the post-order of
the function's blocks is completed.  This was not enough: defs in
"unreachable blocks" (i.e. those which aren't forwards-reachable from
the function entry) must be completed too, and such blocks do not appear
in the function's post-order.

Here, defs in unreachable blocks are be completed too.  Such defs must
also be completed in relative post-order.  To do this, roots for the
non-entry post-orders must be found.

rdar://141197164
2024-12-18 11:25:43 -08:00
Nate Chandler
7c4036e908 [NFC] SGC: Extract range completion.
In preparation for completing lifetimes in multiple ranges (namely
post-orders of subgraphs of the function), extract a complete-in-range
method.
2024-12-18 11:25:42 -08:00
Nate Chandler
62f2ffd794 [NFC] ReachableBlocks: Use StackList.
Replace a SmallVector.
2024-12-18 11:25:42 -08:00
Nate Chandler
f9b32a5c4d [NFC] CLF: Compute reachable blocks only.
Don't form a set of unreachable blocks, we only need to check whether
any given block is unreachable, which can be done via
`ReachableBlocks::isVisited`.
2024-12-18 11:25:42 -08:00
Nate Chandler
631fc4c39e [NFC] ReachableBlocks: Rename isReachable method.
It was previously `isVisited`.  And mark `visit` private, it needn't be
part of the interface for any current clients.
2024-12-18 11:25:42 -08:00
Nate Chandler
f8d782ed42 [NFC] ReachableBlocks: Extract compute method.
In preparation for adding more users.
2024-12-18 11:25:42 -08:00
Nate Chandler
e926d22b2d [NFC] SILGenCleanup: Added logging. 2024-12-18 11:25:42 -08:00
Nate Chandler
c53b1a5711 [Gardening] Detypo'd comment. 2024-12-18 11:25:41 -08:00
eeckstein
f1d66e3826 Merge pull request #78233 from eeckstein/ossa-simplify-alloc-stack
SILCombine: enable alloc_stack optimization for OSSA
2024-12-18 06:39:31 +01:00
eeckstein
d5bb068cb9 Merge pull request #78234 from eeckstein/no-use-prespecialized-in-embedded
Optimizer: don't run the UsePrespecialized pass in embedded mode
2024-12-18 06:39:12 +01:00
Meghana Gupta
aaaf5a4916 Merge pull request #78260 from meg-gupta/enableedgecase
Allow SimplifyCFG::simplifyArgument on borrowed values
2024-12-17 20:59:31 -08:00
Meghana Gupta
cda907e06d Merge pull request #78231 from meg-gupta/fixabc
Fix array bounds check optimization for ossa
2024-12-17 16:47:25 -08:00
Meghana Gupta
363731686e Allow SimplifyCFG::simplifyArgument on borrowed values 2024-12-17 15:03:11 -08:00
Meghana Gupta
2a5ddfbe2d Fix array bounds check optimization for ossa
While hoisting check_subscript call in ossa, isNativeTypeChecked call is also hoisted.
The array value used in the isNativeTypeChecked may not be available if it's lifetime
had ended before. Proactively set the array value of the isNativeTypeChecked call to
the array value in the check_subscript call.
2024-12-17 10:57:11 -08:00
Erik Eckstein
35af29aaa0 Optimizer: don't run the UsePrespecialized pass in embedded mode
There are not pre-specialized parts of the stdlib in embedded mode.

Fixes a compiler crash.
Unfortunately I con't have a test case for this.

https://github.com/swiftlang/swift/issues/78167
2024-12-17 11:36:21 +01:00
Erik Eckstein
69b16faa04 SILCombine: enable alloc_stack optimization for OSSA 2024-12-17 09:55:39 +01:00
Meghana Gupta
a62112bd1c Merge pull request #78200 from meg-gupta/fixdce
Look through borrowed from instructions before calling lifetime completion in DCE
2024-12-15 21:06:05 -08:00
Andrew Trick
1d1b260c8f Merge pull request #78199 from atrick/lifedep-cleanup
LifetimeDependence: minor diagnostic quality fixes and related utilities
2024-12-15 04:45:08 -08:00
Meghana Gupta
50bde829b4 Look through borrowed from instructions before calling lifetime completion
Lifetime completion will insert end_borrows only on borrow introducers.

Look through "borrowed from" instructions before calling it.

rdar://141490551
2024-12-15 01:53:19 -08:00
Meghana Gupta
3701f01de4 Mark ownership fixup instructions as live 2024-12-15 01:53:17 -08:00
Andrew Trick
b7f010570d Merge pull request #78197 from atrick/silcombine-markdep
Improve SILCombine mark_dependence: handle address dependence.
2024-12-14 23:37:55 -08:00
Andrew Trick
98da813f02 [NFC] SwiftCompilerSources: add isConvertPointerToPointerArgument 2024-12-14 22:46:54 -08:00
Andrew Trick
e56dbb4695 Improve SILCombine mark_dependence: handle address dependence. 2024-12-14 16:26:58 -08:00
Meghana Gupta
01da59f370 Merge pull request #78176 from meg-gupta/fixstropt
Fix StringOptimization to handle load_borrow
2024-12-13 19:15:46 -08:00
eeckstein
55009bf718 Merge pull request #78163 from eeckstein/improve-dead-object-elimination
Two optimization improvements to fix dead-object-elimination with OSSA
2024-12-13 22:56:24 +01:00
Meghana Gupta
d351623df0 Fix StringOptimization to handle load_borrow
rdar://140229560
2024-12-13 13:16:22 -08:00
Meghana Gupta
28e33af799 Merge pull request #78123 from meg-gupta/newflag
Add new flag -sil-ownership-verify-all
2024-12-13 10:00:41 -08:00
Erik Eckstein
bf496aa4f6 Optimizer: add simplification for fix_lifetime
Canonicalize a `fix_lifetime` from an address to a `load` + `fix_lifetime`:
```
   %1 = alloc_stack $T
   ...
   fix_lifetime %1
```
->
```
   %1 = alloc_stack $T
   ...
   %2 = load %1
   fix_lifetime %2
```

This transformation is done for `alloc_stack` and `store_borrow` (which always has an `alloc_stack` operand).
The benefit of this transformation is that it enables other optimizations, like mem2reg.

This peephole optimization was already done in SILCombine, but it didn't handle store_borrow.
A good opportunity to make an instruction simplification out of it.

This is part of fixing regressions when enabling OSSA modules:
rdar://140229560
2024-12-13 12:06:20 +01:00
Erik Eckstein
9781e99544 DeadObjectElimination: handle begin_borrow/end_borrow when deleting dead arrays
This is part of fixing regressions when enabling OSSA modules:
rdar://140229560
2024-12-13 10:49:01 +01:00
Meghana Gupta
8b1ecb8a71 Add new flag -sil-ownership-verify-all
This flag enables ownership verification after every transform.
2024-12-12 23:55:37 -08:00
Erik Eckstein
750d6ec81b CapturePropagation: handle keypaths which are upcast.
Deal with upcast instructions which cast keypath instructions before they are passed to a partial_apply.

rdar://141370412
2024-12-13 07:51:36 +01:00
eeckstein
0c860f8aba Merge pull request #78136 from eeckstein/fix-ssa-updater-2
LoopRotate: remove redundant phis after ssa-update
2024-12-12 20:59:02 +01:00
Usama Hameed
203f906364 Serialize/Deserialize source locations for instructions (#77281)
This commit adds support for serializing and deserializing source locations for instructions.
2024-12-12 16:15:44 +05:00
Erik Eckstein
8439d0bc46 LoopRotate: remove redundant phis after ssa-update
Fixes an ownership error
2024-12-12 09:22:20 +01:00
Erik Eckstein
6990a195a3 Optimizer: rename GuaranteedPhiUpdater -> PhiUpdater
Because it now has the replacePhisWithIncomingValues utility, which works for all kind of phis.
2024-12-12 09:09:11 +01:00
Erik Eckstein
09a5a4487a Optimizer: add a utility to replaces phis with the unique incoming values if all incoming values are the same
This is needed after running the SSAUpdater for an existing OSSA value, because the updater can
insert unnecessary phis in the middle of the original liverange which breaks up the original
liverange into smaller ones:

```
   %1 = def_of_owned_value
   %2 = begin_borrow %1
   ...
   br bb2(%1)
 bb2(%3 : @owned $T): // inserted by SSAUpdater
   ...
   end_borrow %2      // use after end-of-lifetime!
   destroy_value %3
```

It's not needed to run this utility if SSAUpdater is used to create a _new_ OSSA liverange.
2024-12-12 08:57:57 +01:00
Erik Eckstein
301ab4e112 LoopRotate: remove the replace-arg-with-struct peephole optimization
This does not belong to loop-rotate and does not work with OSSA.
This peephole is covered by other optimizations.
2024-12-12 08:35:48 +01:00
eeckstein
b7485467e9 Merge pull request #78054 from eeckstein/ossa-opt-improvements
Some OSSA related optimization improvements
2024-12-11 20:07:24 +01:00
Meghana Gupta
252a57a3fd Merge pull request #78096 from meg-gupta/removeunreachable
Remove unreachable blocks after inlining
2024-12-11 05:07:58 -08:00
Erik Eckstein
6b38f2aab4 Optimizer: simplify load_borrow
* Remove dead `load_borrow` instructions (replaces the old peephole optimization in SILCombine)
* If the `load_borrow` is followed by a `copy_value`, combine both into a `load [copy]`
2024-12-11 12:32:33 +01:00
Erik Eckstein
1bd74d1fc3 LICM: (limited) support for OSSA
The first step: allow hoisting instructions which only have trivial operands and results.
2024-12-11 12:32:33 +01:00
Erik Eckstein
074a99cc39 LoopRotate: don't rotate a loop if the new header is loop exiting as well
This doesn't give any performance benefit.
2024-12-11 12:32:33 +01:00
Erik Eckstein
8000802481 LoopRotate: handle copy_value and begin_borrow correctly 2024-12-11 12:32:32 +01:00
Erik Eckstein
7e8410ebc1 COWArrayOpt: handle load_borrow 2024-12-11 12:32:32 +01:00