Commit Graph

11224 Commits

Author SHA1 Message Date
Nate Chandler
f78c57daef [SILCombine] Rewrite try_apply(convert_function).
A partial revert of 428ab472ac.
2025-01-08 20:33:49 -08:00
Meghana Gupta
8397fc364c Merge pull request #78460 from meg-gupta/removeossa
Fix build option for Synchronization and Distributed
2025-01-08 15:20:07 -08:00
Michael Gottesman
2dbffa247b Merge pull request #78479 from gottesmm/pr-fadbda958eb1024880fd290cdb1b5b17ddc46b99
[rbi] Ensure that we infer isolation correctly for direct sending results
2025-01-08 14:56:18 -08:00
Meghana Gupta
0634babbe6 Merge pull request #78412 from meg-gupta/fixsilcombine
Fix SILCombine of existential applies
2025-01-08 12:12:36 -08:00
Erik Eckstein
67b8c08ef1 SILLinker: convert an assert to a compiler error message
Having a wrong linkage can happen if the user "re-defines" an existing function with a wrong linkage, e.g. using `@_cdecl`.
2025-01-08 11:00:27 +01:00
Daniil Kovalev
0ba886d409 [AutoDiff] Fix adjoint for move_value (#78286)
Since `move_value` is a destroying operation, the adjoint of `y = move_value x` should be `adj[x] += adj[y]; adj[y] = 0` instead of just `adj[x] += adj[y]`.
2025-01-08 00:42:54 -08:00
Michael Gottesman
c061ee72ec [rbi] Ensure that we infer isolation correctly for direct sending results.
I did the correct thing for indirect parameters, but did not do the correct
thing for direct parameters. This is now fixed with some tests to boot.

rdar://141631655
2025-01-07 14:33:39 -08:00
Meghana Gupta
ed0483b4ce Fix SILCombine of existential applies
Don't use previously found owned concrete values in ossa. They will consumed by
forwarding operations like init_existential_ref. Instead create an unconditional cast
of the opened existential to concrete type and use that to create a concrete apply.
2025-01-07 10:38:25 -08:00
Meghana Gupta
d55cb2ad6c Bailout of PredictableMemOpt utilities when in non-ossa
These utilities are called from MandatorPerformanceOptimizations which can run
on serialized non-ossa functions. Add a bailout to handle this case.
2025-01-07 01:19:09 -08:00
Daniil Kovalev
95f34ebaca [AutoDiff] Fix derivative for array literal with tuple_element_addr elts (#78355)
The `adjIndex` was not incremented due to missed `remapType`.

Fixes #54214
2025-01-06 16:11:54 -08:00
stzn
d429a90ebc [Diagnostics] A self argument implicitly passed as an inout parameter is diagnosed as used before initialized 2025-01-06 05:05:26 +09: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
Meghana Gupta
8494f68899 Remove complex bailouts and fix replacing open_existential_ref
This code was previously creating illegal unchecked_ref_cast
 with same source and destination.
2025-01-03 16:15:34 -08:00
Michael Gottesman
b74be1433a [concurrency] Fix a small bug in RBI that caused us to not recognize that an @MainActor SILIsolationInfo is from an @MainActor. 2025-01-02 13:18:55 -08:00
Michael Gottesman
5d4239af57 [concurrency] Add new isolation kind CallerIsolationInheriting.
Right now it is basically a version of nonisolated beyond a few simple cases
like constructors/destructors where we are pretty sure we want to not support
this.

This is part of my bringup strategy for changing nonisolated/unspecified to be
caller isolation inheriting.
2025-01-02 13:18:30 -08:00
eeckstein
f096787871 Merge pull request #78384 from eeckstein/enable-code-motion-in-ossa
Optimizer: enable SILCodeMotion in OSSA, but only for trivial values.
2025-01-02 20:36:29 +01:00
eeckstein
efe8aeb718 Merge pull request #78317 from eeckstein/pointer-to-address-simplification
Optimizer: re-implement the `pointer_to_address` SILCombine peephole optimizations in swift
2025-01-02 12:54:26 +01: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
Erik Eckstein
48b913af4b Optimizer: make the hasOwnershipOperandsOrResults utility available in OwnershipOptUtils 2025-01-02 10:42:01 +01:00
Meghana Gupta
ed2f43e67d Merge pull request #78354 from meg-gupta/enablesilcombine
Enable silcombine to propagate concrete type of existentials in ossa
2025-01-02 00:01:13 -08: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
95f199212d Merge pull request #78351 from eeckstein/fix-specializer
GenericSpecializer: fix an ownership verification failure when removing a partial_apply of a thunk
2025-01-02 08:40:52 +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
Meghana Gupta
5e1f9a37ef Enable silcombine to propagate concrete type of existentials in ossa 2024-12-23 08:34:13 -08:00
Meghana Gupta
571498289a [NFC] Print final ossa module when enabled 2024-12-23 08:31:31 -08:00
Erik Eckstein
e6f161c948 GenericSpecializer: fix an ownership verification failure when removing a partial_apply of a thunk
rdar://141490629
2024-12-23 09:45:21 +01:00
Erik Eckstein
9aff288be4 Optimizer: re-implement the pointer_to_address SILCombine peephole optimizations in swift
Which consists of
* removing redundant `address_to_pointer`-`pointer_to_address` pairs
* optimize `index_raw_pointer` of a manually computed stride to `index_addr`
* remove or increase the alignment based on a "assumeAlignment" builtin

This is a big code cleanup but also has some functional differences for the `address_to_pointer`-`pointer_to_address` pair removal:

* It's not done if the resulting SIL would result in a (detectable) use-after-dealloc_stack memory lifetime failure.
* It's not done if `copy_value`s must be inserted or borrow-scopes must be extended to comply with ownership rules (this was the task of the OwnershipRAUWHelper).

Inserting copies is bad anyway.
Extending borrow-scopes would only be required if the original lifetime of the pointer extends a borrow scope - which shouldn't happen in save code. Therefore this is a very rare case which is not worth handling.
2024-12-21 08:28:22 +01:00
Ben Barham
8111fe9343 Merge pull request #78262 from bnbarham/skip-non-wmo-diag
[Embedded] Do not produce `cannot_specialize_class` for live issues
2024-12-20 10:40:07 -08: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
Ben Barham
a2fda1d9f3 [Embedded] Do not produce cannot_specialize_class for live issues
SourceKit explicitly disables WMO, silence the diagnostic in this case
(but leave it enabled for explicit non-WMO builds otherwise).
2024-12-19 15:31:41 -08: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
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