Commit Graph

80 Commits

Author SHA1 Message Date
Andrew Trick
b670a6d9cc Merge pull request #81191 from atrick/var-walker-recursion
LifetimeDependenceDiagnostics: bug fixes and output clarity
2025-04-30 15:36:32 -07:00
Andrew Trick
25e9cbf3f1 [NFC] SwiftCompilerSource: bridge Function.accessorKindName 2025-04-29 22:09:42 -07:00
Erik Eckstein
ffc17322f9 SIL: bridge Function.isDeinitBarrier back from Swift to C++ SIL
This API already existed in Swift, but not in the C++ SIL.
2025-04-29 20:30:21 +02:00
Erik Eckstein
5a67af507e Swift SIL: add Function.isSpecialization 2025-04-18 06:58:39 +02:00
Erik Eckstein
67556cfbf4 SIL: add some Function APIs
* `var wasDeserializedCanonical`
* `var genericSignature`
* `func mapTypeIntoContext`
* `var forwardingSubstitutionMap`
2025-03-26 08:45:07 +01:00
Erik Eckstein
380ea889bc SIL: fix self-argument APIs in Function
`var selfArgument` should return an optional, i.e. nil if the function doesn't have a self argument.
2025-03-26 07:30:10 +01:00
Erik Eckstein
f8e013a21c Fix a compiler warning in SIL/Function.swift 2024-12-20 09:10:17 +01:00
Andrew Trick
7a11d5a3f1 SwiftCompilerSources: bridge Function.sourceFileKind. 2024-12-18 16:56:45 -08:00
Andrew Trick
98da813f02 [NFC] SwiftCompilerSources: add isConvertPointerToPointerArgument 2024-12-14 22:46:54 -08:00
Erik Eckstein
709dfc2d21 MandatoryPerformanceOptimization: don't let not-inlinable functions to be inlined
Also refactor canInline.

Fixes a compiler crash.
rdar://137544788
2024-10-15 12:19:50 +02:00
Erik Eckstein
10782cf42b SwiftCompilerSources: introduce the AST module
As the optimizer uses more and more AST stuff, it's now time to create an "AST" module.
Initially it defines following AST datastructures:
* declarations: `Decl` + derived classes
* `Conformance`
* `SubstitutionMap`
* `Type` and `CanonicalType`

Some of those were already defined in the SIL module and are now moved to the AST module.
This change also cleans up a few things:
* proper definition of `NominalTypeDecl`-related APIs in `SIL.Type`
* rename `ProtocolConformance` to `Conformance`
* use `AST.Type`/`AST.CanonicalType` instead of `BridgedASTType` in SIL and the Optimizer
2024-10-02 07:10:29 +02:00
Erik Eckstein
c96b196ffa SwiftCompilerSources: bridge SILLinkage
Make SILLInkage available in SIL as `SIL.Linkage`.
Also, rename the misleading Function and GlobalVariable ABI `isAvailableExternally` to `isDefinedExternally`
2024-08-22 08:56:27 +02:00
Erik Eckstein
c61733f985 SwiftCompilerSources: refactor Function.mayBindDynamicSelf
Instead of bridging the whole function, just bridge `hasDynamicSelfMetadata` and do the other work in swift.
2024-06-25 17:59:23 +02:00
Ellie Shin
41ee82a589 [SwiftCompilerSources] Remove warning: add unknown default case for bridged function serializedkind. 2024-06-13 14:42:13 -07:00
Ellie Shin
8b00478bc6 [SwiftCompilerSources] Remove unnecessary default case from SerializedKind funcs 2024-06-11 23:59:43 -07:00
Meghana Gupta
470fa2f365 Remove resultDependsOn/resultDependsOnSelf 2024-06-05 11:36:16 -07:00
Ellie Shin
c3ded85c4f Update SILBridgedFunction APIs.
Add isAnySerialized() and canBeInlinedIntoCaller(SerializedKind).
2024-05-29 15:54:36 -07:00
Kshitij
74166a4ab6 [Autodiff] Moves bridging code accesses in closure-spec opt behind APIs
Addresses some other surfacial feedback as well.
2024-05-13 15:37:30 -07:00
Kshitij
ab751d57ab [Autodiff] Adds logic to generate specialized functions in the closure-spec pass 2024-05-13 11:16:42 -07:00
Kshitij
003c9082cb [Autodiff] Adds SwiftCompilerSources changes in preparation for the Autodiff closure-spec optimization pass 2024-05-02 09:14:05 -07:00
Andrew Trick
8b24382494 SwiftCompilerSources: cleanup and extend ArgumentConventions
Provide APIs needed by lifetime dependence diagnostics, namely LifetimeDependenceConvention.

Reorganize the APIs so it's easy to find related functionality which
API is responsible for which functionality.

Remove the originalFunctionConvention complexity. It is no longer
needed for lifetime dependence inference, and generally should be
avoided in SIL.

Add some placeholder FIXMEs because this not a good PR in which to
change existing functionality.
2024-02-12 09:57:14 -08:00
Erik Eckstein
31f3102540 swift SIL: fix Function.isGeneric
It didn't work for functions in generic contexts, which don't add a generic parameter themselves
2024-01-31 17:16:18 +01:00
Erik Eckstein
3b239b25f3 swift SIL: add Function thunk APIs
* `var thunkKind`
* `set(thunkKind:)`
2024-01-31 17:16:13 +01:00
Andrew Trick
9770ce41a2 Improve the ArgumentConvention API 2024-01-30 08:38:57 -08:00
Andrew Trick
2128c21106 Migrate SwiftCompilerSources to FunctionConvention.
Layers:
- FunctionConvention: AST FunctionType: results, parameters
- ArgumentConventions: SIL function arguments
- ApplyOperandConventions: applied operands

The meaning of an integer index is determined by the collection
type. All the mapping between the various indices (results,
parameters, SIL argument, applied arguments) is restricted to the
collection type that owns that mapping. Remove the concept of a
"caller argument index".
2024-01-03 12:24:50 -08:00
Meghana Gupta
3c56a7a88e Bridge hasResultDependsOnSelf() 2023-12-29 02:06:15 -08:00
Andrew Trick
c1f0f06907 [SIL] Add FunctionConvention.swift
Bridge information about the AST function type that does not require a
SIL function body.

Support querying the function type's ResultInfo.
2023-12-18 09:43:18 -08:00
eeckstein
10ff55b2b3 Merge pull request #70155 from eeckstein/refactoring
MemoryLifetimeVerifier: use CalleeCache instead of AliasAnalysis
2023-12-04 08:53:59 +01:00
Erik Eckstein
0897d8a720 MemoryLifetimeVerifier: use CalleeCache instead of AliasAnalysis
To verify if a function may read from an indirect argument, don't use AliasAnalysis.
Instead use the CalleeCache to get the list of callees of an apply instruction.
Then use a simple call-back into the swift Function to check if a callee has any relevant memory effect set.

This avoids a dependency from SIL to the Optimizer.
It fixes a linker error when building some unit tests in debug.
2023-12-01 19:20:18 +01:00
zoecarver
69498e2f2e [opt] Add three new perf annotations: @_noRuntime, @_noExistential, and @_noObjCBridging. 2023-12-01 09:13:24 -07:00
Erik Eckstein
9bbee4411b SwiftCompilerSources: consider indirect error results in Function.numArguments 2023-11-27 08:51:12 +01:00
Hamish Knight
ce23252a3f [Basic] Improve some bridging APIs
Improve APIs for BridgedStringRef,
BridgedOwnedString, and BridgedSourceLoc.
2023-10-30 23:49:53 +00:00
Andrew Trick
ca7253a25c Add the @_unsafeNonEscapableResult function
This will allow NonEscapable types to be returned from a function.
2023-10-17 12:44:31 -07:00
Erik Eckstein
2dbd6cc56b SwiftCompilerSources: rework bridging
Introduce two modes of bridging:
* inline mode: this is basically how it worked so far. Using full C++ interop which allows bridging functions to be inlined.
* pure mode: bridging functions are not inlined but compiled in a cpp file. This allows to reduce the C++ interop requirements to a minimum. No std/llvm/swift headers are imported.

This change requires a major refactoring of bridging sources. The implementation of bridging functions go to two separate files: SILBridgingImpl.h and OptimizerBridgingImpl.h.
Depending on the mode, those files are either included in the corresponding header files (inline mode), or included in the c++ file (pure mode).

The mode can be selected with the BRIDGING_MODE cmake variable. By default it is set to the inline mode (= existing behavior). The pure mode is only selected in certain configurations to work around C++ interop issues:
* In debug builds, to workaround a problem with LLDB's `po` command (rdar://115770255).
* On windows to workaround a build problem.
2023-10-09 09:52:52 +02:00
Erik Eckstein
ad594f2713 Swift SIL: add some APIs
* `AssignInst`
* `Function.isDestructor`
* `MarkUninitializedInst.kind`
* `Type.isMoveOnly`
* `RefElementAddrInst.isImmutable` and `RefElementAddrInst.set(isImmutable:)`
* `BeginBorrowInst.endBorrows`
* `Context.hadError` and `Context.silStage`
2023-09-19 15:10:30 +02:00
zoecarver
48513f3c5b [embedded] Introduce isGenericFunction and addAllNonGenericFunctions. 2023-09-06 10:48:17 -07:00
John McCall
65e2e8c2fe Fix some SILArgument infrastructure for pack results.
Getting this right convinces the memory verifier to not complain
about untouched empty pack result arguments, which should be
innocuous.
2023-06-30 02:08:57 -04:00
Erik Eckstein
ee1c52bc77 Swift SIL: add some APIs 2023-05-22 15:34:26 +02:00
Erik Eckstein
b9169064c6 Swift SIL: add some APIs
* `Options.assertConfiguration`
* `Argument.isIndirectResult`
* in `Function`: `selfArgument`, `isTransparent`, `performanceConstraints` and `inlineStrategy`
* `BuiltinInst.substitutionMap`
* `SubstitutionMap.replacementTypes`
* `Type.canBeClass`
2023-05-11 08:11:44 +02:00
Erik Eckstein
e95c6425f2 Swift SIL: add some APIs for global variables 2023-05-08 21:23:36 +02:00
Erik Eckstein
7789b4063e Swift Bridging: remove BridgedMemoryBehavior and use swift.MemoryBehavior instead 2023-03-21 15:33:09 +01:00
Erik Eckstein
ae7770d911 Swift Bridging: use C++ instead of C bridging for BridgedFunction 2023-03-21 15:33:09 +01:00
Erik Eckstein
053a38d44b Swift SIL: mark SIL object classes as immortal
This avoids ARC operations on those objects which improves compile time.
2023-03-14 21:07:03 +01:00
Erik Eckstein
8d90dafb22 Swift SIL: add Function.reversedInstructions 2023-01-16 19:00:09 +01:00
Erik Eckstein
6c35258f83 Swift SIL: rename parent accessors to parentX, e.g. Instruction.parentBlock
It makes it easier to read
2023-01-16 15:11:34 +01:00
Erik Eckstein
d4d1620f28 Swift SIL: rework Instruction and BasicBlock lists to support deleting instructions during iteration
Replace the generic `List` with the (non-generic) `InstructionList` and `BasicBlockList`.
The `InstructionList` is now a bit different than the `BasicBlockList` because it supports that instructions are deleted while iterating over the list.
Also add a test pass which tests instruction modification while iteration.
2022-12-12 19:08:57 +01:00
Erik Eckstein
0ada6ec5bd SIL SideEffects: handle program termination point functions
We can ignore any memory writes in a program termination point, because it's not relevant for the caller.
But we need to consider memory reads, otherwise preceeding memory writes would be eliminated by dead-store-elimination in the caller.
E.g. String initialization for error strings which are printed by the program termination point.
Regarding ownership: a program termination point must not touch any reference counted objects.
2022-11-09 08:06:19 +01:00
Erik Eckstein
698196b1eb SILFunction: add getMemoryBehavior
This retrieves the side effect information from the function effects.
2022-10-20 09:20:28 +02:00
Nate Chandler
4476088ab5 [ComputeSideEffects] Track deinit-barrier-ness.
Functions "are deinit barriers" (more pedantically, applies of functions
are deinit barriers) if any of their instructions are deinit barriers.
During side-effect analysis, when walking a function's instructions for
other global effects, also check for the deinit-barrier effect.  If an
instruction is found to be a deinit barrier, mark the function's global
effects accordingly.

Add SILFunction::isDeinitBarrier to conveniently access the effects
computed during ComputeSideEffects.

Update the isBarrierApply predicate to iterate over the list of callees,
if complete, to check whether any is a deinit barrier.  If none is, then
the apply is not a deinit barrier.
2022-10-18 21:23:22 -07:00
Erik Eckstein
66f07fe3da Swift SIL: rework function effects and add function side-effects
So far, function effects only included escape effects.
This change adds side-effects (but they are not computed, yet).
It also involves refactoring of the existing escape effects.
Also the SIL effect syntax changed a bit. Details are in docs/SIL.rst
2022-10-05 07:38:11 +02:00