Commit Graph

1501 Commits

Author SHA1 Message Date
Erik Eckstein
f70177ca13 SIL: fix typo in comment in Function.swift 2025-06-20 08:15:03 +02:00
Erik Eckstein
fc8f264d56 SIL: add some instruction APIs
* some APIs for `MarkUnresolvedNonCopyableValueInst`
* `AllocBoxInst.hasDynamicLifetime`
2025-06-20 08:15:03 +02:00
Erik Eckstein
2259fe6972 SIL: add some instruction creation functions in Builder 2025-06-20 08:15:03 +02:00
Erik Eckstein
c19aa69940 SIL: implement Function.isSerialized and Function.isAnySerialized with serializedKind
No need for bridging functions
2025-06-20 08:15:02 +02:00
Erik Eckstein
c482b09878 SIL: let Builder.createAllocStack specify a debugVariable 2025-06-20 08:15:02 +02:00
Erik Eckstein
28dd6f7064 Optimizer: improve the SpecializationCloner
* add `cloneFunctionBody` without an `entryBlockArguments` argument
* remove the `swift::ClosureSpecializationCloner` from the bridging code and replace it with a more general `SpecializationCloner`
2025-06-20 08:15:02 +02:00
Erik Eckstein
7deec66ffe Optimizer: add two utilities in OptUtils.swift
* `MultipleValueInstruction.replace(with:)`
* `eraseIfDead(functions:)`
2025-06-20 08:15:01 +02:00
Erik Eckstein
9bd85c6723 SIL: add some Function APIs
* `isReferencedInModule`
* `shouldOptimize`
2025-06-20 08:15:01 +02:00
Erik Eckstein
d8e4e501f6 Optimizer: add some SIL modification APIs to Context
* `insertFunctionArgument`
* `BeginAccessInst.set(accessKind:)`
* `erase(function:)`
2025-06-20 08:15:01 +02:00
Erik Eckstein
de28cf04cc Optimizer: add Context. mangle(withBoxToStackPromotedArguments) 2025-06-20 08:15:01 +02:00
Erik Eckstein
bc7024edfe Optimizer: fix ModulePassContext.mangle(withDeadArguments:)
If mangled the wrong argument indices.
2025-06-20 08:15:00 +02:00
Erik Eckstein
5b9c206059 Optimizer: remove don't use locationOfNextNonMetaInstruction for getting Builder locations from instructions
This does not work in some situations.
2025-06-20 08:15:00 +02:00
Erik Eckstein
63cb683cb7 SIL: improve some Location APIs
* rename `var autoGenerated` -> `var asAutoGenerated`
* add `var asCleanup`
* add `func withScope`
2025-06-20 08:15:00 +02:00
Erik Eckstein
4212c611e5 Optimizer: add Context.createSpecializedFunctionDeclaration
Originally this was a "private" utility for the ClosureSpecialization pass.
Now, make it a general utility which can be used for all kind of function specializations.
2025-06-20 08:15:00 +02:00
Erik Eckstein
57e08affcb SIL: add ApplySite.calleeArgument(of operand: Operand, in callee: Function)
This is a safer API than using
```
  let argIdx = applySite.calleeArgumentIndex(of: op)
  let arg = callee.arguments[argIdx]
```
because there is no potential misuse of the index.
2025-06-20 08:14:59 +02:00
Erik Eckstein
f83fb1b14a Optimizer: add FunctionWorklist and CrossFunctionValueWorklist
Originally, `FunctionWorklist` was a private utility in MandatoryPerformanceOptimizations.
Moved this to `Worklist.swift` to make it generally available.
Also, simplify the `pop()` function which changes the popping order - therefore some test changes were necessary.
2025-06-20 08:14:59 +02:00
Erik Eckstein
40363d87c4 Optimizer: fix the InstructionRange utility for control flow graphs with unreachable blocks
`InstructionRange.contains` did yield a wrong result if the range ended in the begin-block and another instruction was inserted in an unreachable block.
2025-06-20 08:14:59 +02:00
Erik Eckstein
1f304e5609 SIL: improve APIs for Box types
* move `isBox` from `SIL.Type` to `TypeProperties` to make it also available for AST types
* add `BoxFieldsArray.isMutable(fieldIndex:)`
2025-06-20 08:14:59 +02:00
Erik Eckstein
094b246874 SIL: FunctionArgument.copyFlags needs a MutatingContext argument
SIL may only be modified through a MutatingContext. Otherwise analysis notifications may get lost.
2025-06-20 08:14:59 +02:00
Erik Eckstein
d025e9f7a5 SIL: add var Argument.decl: ValueDecl? 2025-06-20 08:14:58 +02:00
Anthony Latsis
722bc0f086 ASTBridging: Bridge swift::DiagID directly 2025-06-19 12:29:27 +01:00
Andrew Trick
5b5f370ce1 LifetimeDependenceScopeFixup: crash handling dead-end coroutine
When extending a coroutine, handle the end_borrow instruction used to end a
coroutine lifetime at a dead-end block.

Fixes rdar://153479358 (Compiler crash when force-unwrapping optional ~Copyable type)
2025-06-16 21:43:44 -07:00
Meghana Gupta
8396a6d8c0 Fix an inliner crash when inlining begin_apply with scoped lifetime dependence
LifetimeDependenceInsertion inserts mark_dependence on token result of a begin_apply
when it yields a lifetime dependent value. When such a begin_apply gets inlined,
the inliner can crash because of the remaining uses of the token result.

Fix this by inserting mark_dependence on parameter operands that are lifetime dependence sources
and deleting the mark_dependence on token results in the inliner.

Fixes rdar://151568816
2025-06-12 01:35:36 -07:00
eeckstein
2237d8615e Merge pull request #82142 from eeckstein/mandatory-perf-opt
MandatoryPerformanceOptimizations: some refactoring
2025-06-10 17:45:17 +02:00
Erik Eckstein
8d73f881e8 SIL: let getNominalFields return nil for a struct with unreferenceable storage
Like C bitfields.
Fixes a crash in the InitializeStaticGlobals pass in case a global having a C struct type with bitfield is initialized statically.
2025-06-10 10:55:40 +02:00
Erik Eckstein
f0b3ec05b4 MandatoryPerformanceOptimizations: some refactoring
NFC
2025-06-10 08:10:42 +02:00
eeckstein
a40a7be694 Merge pull request #82090 from valeriyvan/typos
Fix some typos in SwiftCompilerSources/Sources
2025-06-09 13:23:04 +02:00
Valeriy Van
761bee9d09 Fix typo in func replaceOpenedArchetypeInSubstituations -> replaceOpenedArchetypeInSubstitutions 2025-06-08 11:30:04 +03:00
Valeriy Van
dd2468cf58 Fix typo in local var 2025-06-08 11:27:30 +03:00
Valeriy Van
8a0c1db164 Fix typo in property allContainedAddresss -> allContainedAddresses 2025-06-08 11:26:01 +03:00
Valeriy Van
949c2bad67 Fix some typos in SwiftCompilerSources/Sources 2025-06-08 11:22:45 +03:00
Erik Eckstein
d6cbaf6ebd MandatoryPerformanceOptimizations: only set the [perf_constraint] flag for callees of performance constraint functions
It used to also set it for functions which are referenced from a global with a const/section attribute - even if not performance attribute was present in the whole module. This is unnecessary and can lead to worse code generation.

rdar://152665294
2025-06-06 20:08:16 +02:00
eeckstein
a33ff9879a Merge pull request #81969 from eeckstein/temp-lvalue-elimination
Optimizer: improve TempLValueOpt
2025-06-06 15:30:29 +02:00
eeckstein
98aeec6563 Merge pull request #82014 from eeckstein/address-walkers
SIL: handle `drop_deinit` in WalkUtils
2025-06-06 15:28:09 +02:00
Andrew Trick
227f8028e8 LifetimeDependenceScopeFixup: handle yielded value copies.
When extending an access scope over a coroutines, instead of simply
considering the lifetime of the coroutine scope, recurse through all
uses of yielded values. They may be copyable, non-Escapable values
that depend on the coroutine operand.

Fixes rdar://152693622 (Extend coroutines over copied yields)
2025-06-05 20:21:40 -07:00
Andrew Trick
95f7a12c98 [NFC] LifetimeDependence: fix internal debug output 2025-06-05 20:09:06 -07:00
Doug Gregor
67b55566fe Merge pull request #82005 from DougGregor/generalize-checked-cast-options
[SIL] Generalize CastingIsolatedConformances to CheckedCastInstOptions
2025-06-05 08:43:09 -07:00
Erik Eckstein
70ba193cd4 SIL: handle drop_deinit in WalkUtils
Also, handle some other missing instructions in the AddressDefUseWalker, which are visited in the AddressUseDefWalker.

This enables various other optimizations, like copy elimination, in the presence of `drop_deinit`.

rdar://152307747
2025-06-05 14:13:51 +02:00
Erik Eckstein
2b9b2d243c Optimizer: improve TempLValueOpt
* re-implement the pass in swift
* support alloc_stack liveranges which span over multiple basic blocks
* support `load`-`store` pairs, copying from the alloc_stack (in addition to `copy_addr`)

Those improvements help to reduce temporary stack allocations, especially for InlineArrays.

rdar://151606382
2025-06-05 06:45:18 +02:00
Erik Eckstein
6428a7b50c Optimizer: move protocol CopyLikeInstruction from TempRValueElimination to OptUtils, so that other passes can use it as well 2025-06-05 06:45:18 +02:00
Erik Eckstein
b4010e61a3 SIL: add a small utility Instruction.isUsing which checks if a value is in its operand list 2025-06-05 06:45:17 +02:00
Erik Eckstein
502c0eb7b0 Optimizer: add InstructionWorklist.pushSuccessors 2025-06-05 06:45:17 +02:00
Erik Eckstein
294a50ced8 SIL: allow inserting specific instruction classes into an InstructionSet
Instead, remove `Operand.users(ofType:)` which returned a sequence of `Instruction` - which was a kind of replacement for the missing `InstructionSet` API
2025-06-05 06:45:17 +02:00
Erik Eckstein
8b6a03b38b AliasAnalysis: compute more precise memory behavior for debug_value undef and the prepareInitialization and zeroInitializer builtins 2025-06-05 06:45:17 +02:00
Doug Gregor
bc4cf1236b [SIL] Generalize CastingIsolatedConformances to CheckedCastInstOptions
We are going to need to add more flags to the various checked cast
instructions. Generalize the CastingIsolatedConformances bit in all of
these SIL instructions to an "options" struct that's easier to extend.

Precursor to rdar://152335805.
2025-06-04 17:12:28 -07:00
Andrew Trick
c030b78c7d LifetimeDependenceDiagnostics: fix source loc for implicit variables
Diagnostics on an indirect result ($return_value) did not report a source
location.
2025-06-04 11:41:15 -07:00
Andrew Trick
1d09c06ab1 LifetimeDependenceDiagnostics: diagnose indirect closure results.
Add support for diagnosing calls to closures that return a generic
non-Escapable result.

Closures do not yet model lifetime dependencies. The diagnostics have
a special case for handling nonescaple result with no lifetime
dependence, but it previously only handled direct results. This fix handles
cases like the following:

    func callIndirectClosure<T>(f: () -> NE<T>) -> NE<T> {
      f()
    }

Fixes rdar://134318846 ([nonescapable] diagnose function types with nonescapable results)
2025-06-04 11:40:42 -07:00
eeckstein
4777f27114 Merge pull request #81897 from eeckstein/fix-mpo
MandatoryPerformanceOptimizations: make sure to handle de-serialized vtable methods
2025-06-02 20:06:32 +02:00
Pavel Yaskevich
e1e9f04398 Merge pull request #81863 from xedin/using-for-default-isolation-in-file-context
[AST/Sema] SE-0478:  Implement `using` declaration under an experimental flag
2025-06-02 09:56:29 -07:00
Erik Eckstein
cf55b9bede MandatoryPerformanceOptimizations: make sure to handle de-serialized vtable methods
When de-serializing a function and this function allocates a class, the methods of the de-serialized vtable must be handled, too.

Fixes an IRGen crash
rdar://152311945
2025-06-02 11:43:34 +02:00