Meghana Gupta
4561658799
Avoid creating unoptimizable copies in CSE
...
CSE uses OSSA rauw which creates copies and copies that are created to optimize
across borrow scopes are unoptimizable. This PR avoids this situation for now.
2025-02-19 11:20:43 -08:00
Erik Eckstein
5ef3b96da2
SimplifyCFG: remove all borrowed-from uses from arguments when merging blocks
...
So far we only considered the forwarding use. But there may be other uses.
Fixes a compiler crash.
rdar://145091197
2025-02-19 13:25:48 +01:00
Erik Eckstein
f0b7bdb382
TempLValueOpt: avoid creating invalid apply argument aliasing.
...
An indirect argument (except `@inout_aliasable`) must not alias with another indirect argument.
Now, if we would replace tempAddr with destAddr in
```
apply %f(%tempAddr, %destAddr) : (@in T) -> @out T
```
we would invalidate this rule.
This is even true if the called function does not read from destAddr.
Fixes a SIL verification error.
rdar://145090659
2025-02-19 10:33:18 +01:00
Meghana Gupta
cf22bced31
Merge pull request #79315 from meg-gupta/typevaluecse
...
Add CSE support for type_value instruction and add a few bounds check tests for InlineArray
2025-02-13 20:54:26 -08:00
Meghana Gupta
a31a603e49
Handle type_value instruction in CSE
2025-02-13 10:30:25 -08:00
Erik Eckstein
af5ac6d283
Re-instate the allocVector builtin
...
Although it's not used anymore we still have to support it to be able to read old Swift.interface files which still contain the builtin.
rdar://144781646
2025-02-13 17:55:27 +01:00
Erik Eckstein
6af5876f72
PerformanceInliner: add the @_semantics("optimize.sil.inline.aggressive") attribute to enable inlining into large functions.
...
This attribute overrides the limit of maximum number of basic blocks in the caller.
2025-02-13 07:40:24 +01:00
Erik Eckstein
3136218a64
PerformanceInliner: allow inlining of small functions even if the caller block limit is exceeded
...
This can fix performance problems in large functions.
rdar://141320229
2025-02-13 07:30:44 +01:00
Erik Eckstein
6407f9a0bd
remove the allocVector builtin
...
It's not needed anymore, because the "FixedArray" experimental feature is replaced by inline-arrays.
2025-02-12 10:51:14 +01:00
eeckstein
aa0833b0b3
Merge pull request #79110 from eeckstein/verify_mark_dependence
...
SIL: Fix memory behavior of mark_dependence
2025-02-11 06:39:43 +01:00
Erik Eckstein
d918b316c9
TempRValueOptimization: don't optimize copies to mark_dependence base values.
...
We want to keep the original lifetime of the base. If we would eliminate the base alloc_stack, we risk to insert a destroy_addr too early.
2025-02-10 17:57:47 +01:00
Arnold Schwaighofer
7a251af60c
AccessEnforcement: Fix analysis to include mayReleases as potentially
...
executing unknown code
This means we have to claw back some performance by recognizing harmless
releases.
Such as releases on types we known don't call a deinit with unknown
side-effects.
rdar://143497196
rdar://143141695
2025-02-07 15:10:13 -08:00
Anthony Latsis
a84dfc8387
[Gardening] Fix some set but not used variables
2025-01-30 21:34:38 +00:00
nate-chandler
8c63134570
Merge pull request #78682 from nate-chandler/rdar142636711_2
...
[TempRValueOpt] Invalidate insts when completing.
2025-01-27 12:53:57 -08:00
Meghana Gupta
01d4f11cf5
Fix condition forwarding for switch_enum with default in ossa
...
In ossa, switch_enum's destination accepts an argument. Fixup
condition forwarding to correctly forward the enum in this case.
Fixes rdar://143042093
2025-01-17 11:01:12 -08:00
Nate Chandler
8fb0fd2ba4
[TempRValueOpt] Invalidate insts when completing.
2025-01-16 08:18:30 -08:00
Nate Chandler
bf1e5dd308
[NFC] DestroyAddrHoisting: Add subpass bailouts.
2025-01-16 08:18:29 -08:00
Nate Chandler
dd5efc7c6b
[NFC] DestroyAddrHoisting: Extract transformation.
...
Separate the hoisting of destroys from the setup and cleanup.
Facilitates bailing after completing N subpasses.
2025-01-16 08:18:29 -08:00
Nate Chandler
6e2f09f225
[NFC] CopyPropagation: Add subpass bailouts.
...
Before each transformation is done, check whether to continue with the
next subpass.
2025-01-16 08:18:29 -08:00
Nate Chandler
8ace8b9ef9
[NFC] CopyPropagation: Extract transformation.
...
Separate the propagation of copies from the setup and cleanup.
Facilitates bailing after completing N subpasses.
2025-01-16 08:18:29 -08:00
Meghana Gupta
15733446ed
Merge pull request #78581 from meg-gupta/outlinerfix
...
Outliner: Do not outline if the BridgedArg value is not available at the BridgedCall
2025-01-13 04:15:20 -08:00
Meghana Gupta
abc37ce218
Remove copy added by outliner for guaranteed bridged value
...
This copy may remain unoptimized, avoid outlining this case.
2025-01-11 08:15:24 -08:00
Meghana Gupta
c56573e424
Outliner: Do not outline if the BridgedArg value is not available at the BridgedCall
...
Avoid outlining this scenario instead of creating a copy to make the value available
2025-01-11 07:40:35 -08:00
Erik Eckstein
b80a08ee6c
CodeMotion: check the ownership of arguments when sinking arguments
...
So far we only checked the ownership of incoming values.
But even if the incoming instruction has no ownership, the argument may have.
This can happen with enums which are constructed with a non-payload case:
%1 = enum $Optional<C>, #Optional.none!enumelt
br bb3(%1)
bb1(%3 : @owned $Optional<C>):
Fixes an ownership verification error:
rdar://142506300
2025-01-09 19:56:25 +01:00
Erik Eckstein
db96d63e9d
SimplifyCFG: correctly handle borrowed-from values when removing a redundant phi argument
...
Fixes a verifier crash
2025-01-09 19:56:25 +01:00
Allan Shortlidge
d0f63a0753
AST: Split Availability.h into multiple headers.
...
Put AvailabilityRange into its own header with very few dependencies so that it
can be included freely in other headers that need to use it as a complete type.
NFC.
2025-01-03 18:36:04 -08:00
Erik Eckstein
53d78abd01
Optimizer: enable SILCodeMotion in OSSA, but only for trivial values.
...
to-do: we should eventually remove code motion of retain and release instructions and implement them as semantic ARC optimizations in OSSA.
2025-01-02 11:01:39 +01:00
eeckstein
aa2cfd3ed1
Merge pull request #78361 from eeckstein/dead-obj-elimination
...
DeadObjectElimination: handle OSSA instructions when analyzing class destructors
2025-01-02 08:41:15 +01:00
eeckstein
1bdb51edc3
Merge pull request #78318 from eeckstein/fix-access-enforcement-opts
...
AccessEnforcementOpts: fix a SIL verifier error caused by a wrong bail-out condition
2025-01-02 08:31:28 +01:00
Erik Eckstein
41dd3dc453
DeadObjectElimination: handle OSSA instructions when analyzing class destructors
...
Handle typical patterns which are generated by SILGen.
2024-12-24 12:00:22 +01:00
Erik Eckstein
413c78e33a
AccessEnforcementOpts: fix a SIL verifier error caused by a wrong bail-out condition
...
In case of a bail-out on failed ownership extension the optimization didn't remove old instructions from previously merged access pairs.
2024-12-20 15:51:37 +01:00
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
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
363731686e
Allow SimplifyCFG::simplifyArgument on borrowed values
2024-12-17 15:03:11 -08: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
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
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
Meghana Gupta
d351623df0
Fix StringOptimization to handle load_borrow
...
rdar://140229560
2024-12-13 13:16:22 -08: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
984f9f6cd2
Remove unreachable blocks after inlining
2024-12-10 17:01:11 -08:00
Meghana Gupta
f7d1c59df5
Merge pull request #78053 from meg-gupta/fixdce
...
Fix DCE for ownership forwarding instructions
2024-12-09 09:56:30 -08:00
Meghana Gupta
daa9b161d0
Fix DCE for ownership forwarding instructions
...
DCE deletes ownership forwarding instructions when it doesn’t have useful users.
It inserts destroy_value/end_borrow for its operands to compensate their lifetimes.
DCE also deletes branches when its successor blocks does not have useful instructions.
It deletes blocks and creates a jump to the nearest post dominating block.
When DCE needs to delete a forwarding instruction in a dead block, it cannot just create
lifetime ends of its operands at its position. Use LifetimeCompletion utility in such cases.
rdar://140428721
2024-12-09 03:22:57 -08:00
Meghana Gupta
adf1eae287
Bring in DominanceInfo and DeadEndBlocks to DCE
2024-12-09 03:00:18 -08:00
Meghana Gupta
23498595bf
Remove incorrect assert in ConditionForwarding
...
ConditionForwarding is able to handle owned values and non-local guaranteed values.
Remove incorrect assertion about enum trivialiaty
Fixes rdar://140977875
2024-12-05 13:02:50 -08:00
Kuba Mracek
6f4ae28520
[ASTMangler] Pass ASTContext to all instantiations of ASTMangler
2024-12-02 15:01:04 -08:00