Commit Graph

1084 Commits

Author SHA1 Message Date
Andrew Trick
c440cca939 Merge pull request #71570 from atrick/lifetime-inherit
LifetimeDependenceInsertion: do not emit inherited dependencies.
2024-02-12 23:02:14 -08:00
eeckstein
77cd7b5e87 Merge pull request #71554 from eeckstein/fix-escape-utils
EscapeUtils: fix escape result in case an address is stored
2024-02-13 07:13:51 +01:00
Andrew Trick
ecf2e36717 LifetimeDependenceDiagnostics: FIXME for @_unsafeNonEscapableResult
Reminder to add a builtin to reliably enforce this unsafe attribute.
2024-02-12 20:05:25 -08:00
Andrew Trick
1cdf9d56ac LifetimeDefUseWalker handles inherited dependencies.
This is needed when we don't insert mark_dependence.
2024-02-12 20:05:24 -08:00
Andrew Trick
ade2ed6ddb LifetimeDependenceInsertion: do not emit inherited dependencies.
These were always redundant. And there is no way to emit them
correctly for valid OSA when the original dependence scope is in the
caller.

NFC without:
-enable-experimental-feature NonescapableTypes
-enable-lifetime-dependence-diagnostics
2024-02-12 20:05:21 -08:00
Andrew Trick
2e7c29cdf5 Restrict findSingleInitializer @out arguments.
The client should handle @in/@inout arguments differently.
2024-02-12 20:03:38 -08:00
Andrew Trick
fcb8612c18 Format SingleInlineArray for use in lit tests. 2024-02-12 20:03:38 -08:00
Andrew Trick
c4eab6a54a Merge pull request #71266 from atrick/lifetime-insertion
Add the LifetimeDependenceInsertion pass.
2024-02-12 13:07:03 -08:00
nate-chandler
1713693703 Merge pull request #71558 from nate-chandler/test/20240212/1/troubleshoot-test-note
[Test] Added troubleshooting note.
2024-02-12 13:06:20 -08:00
Nate Chandler
f9ee089c04 [Test] Added troubleshooting note. 2024-02-12 10:23:13 -08:00
Andrew Trick
8c092911ef Add the LifetimeDependenceInsertion pass.
Insert mark_dependence [nonescaping] markers at every lifetime
introducer that produces a lifetime-dependent value.
2024-02-12 09:57:14 -08:00
Andrew Trick
274c47877f LifetimeDepenenceDiagnostics improvements
Better handling of @_unsafeNonescapableResult

Improve diagnostic clarity.
2024-02-12 09:57:14 -08:00
Andrew Trick
af39b0fb1f LifetimeDependenceUtils improvements
Improve noescape function handling. Use the mayEscape API.

Improve handling of @_unsafeNonescapableResult.

Improve handling of initialized scopes. Use findSingleInitializer.
2024-02-12 09:57:14 -08:00
Andrew Trick
ac457abab9 LifetimeDependenceUseDefWalker: track the owner of the value. 2024-02-12 09:57:14 -08:00
Andrew Trick
e9762432d5 Improve Operand.isAddressInitialization to handle indirect results. 2024-02-12 09:57:14 -08:00
Andrew Trick
b08f2dedf1 Add AccessBase.findSingleInitializer 2024-02-12 09:57:14 -08:00
Andrew Trick
63413916a1 LifetimeDependenceDiagnostics; handle @_unsafeNonescapableResult. 2024-02-12 09:57:14 -08: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
Andrew Trick
28b60e051d Bridge SILFunctionType LifetimeDependenceInfo 2024-02-12 09:57:14 -08:00
Andrew Trick
03bda631f1 AccessUtils: comment typo 2024-02-12 09:57:14 -08:00
Andrew Trick
15fef6868c BorrowUtils: add a comment 2024-02-12 09:57:14 -08:00
Andrew Trick
d0ac09493a Bridge MarkDependence.resolveToNonEscaping 2024-02-12 09:57:14 -08:00
Andrew Trick
f713587aa5 Fix OSSA support for mark_dependence [nonescaping]
Handle escapes to function results.
2024-02-12 09:57:14 -08:00
Andrew Trick
72fff912e7 SwiftCompilerSources: bridge Type.isEmpty 2024-02-12 09:57:14 -08:00
Andrew Trick
340bd26d23 SwiftCompilerSources: bridge isNoEscape and mayEscape. 2024-02-12 09:57:14 -08:00
Andrew Trick
ced850d092 SwiftCompilerSources: bridge GlobalVariable.varDecl 2024-02-12 09:57:14 -08:00
Andrew Trick
b1601a958b Fix ApplySite.originalParameter(of:). 2024-02-12 09:57:14 -08:00
Andrew Trick
79fe8bad30 SwiftCompilerSources: improve MarkDependenceInst. 2024-02-12 09:57:14 -08:00
Erik Eckstein
abd6ce0c9d EscapeUtils: fix escape result in case an address is stored
This unusual situation can happen if an address is converted to a raw pointer and that pointer is stored to a memory location.
In this case the walkers need to follow load instructions even if the visitor and current projection path don't say so.

Fixes a miscompile
rdar://122805546
2024-02-12 17:56:09 +01:00
Andrew Trick
da3f583492 Add mark_dependence [unresolved]
In preparation for inserting mark_dependence instructions for lifetime
dependencies early, immediately after SILGen. That will simplify the
implementation of borrowed arguments.

Marking them unresolved is needed to make OSSA verification
conservative until lifetime dependence diagnostics runs.
2024-02-08 22:53:16 -08:00
Erik Eckstein
38bfc03994 MandatoryPerformanceOptimizations: set the [perf_constraint] flag on functions with performance constraints 2024-02-05 12:38:53 +01:00
Erik Eckstein
86f23b089f SIL: add the [perf_constraint] flag in SILFunction
Specifies that the optimizer and IRGen must not add runtime calls which are not in the function originally.
This attribute is set for functions with performance constraints or functions which are called from functions with performance.
2024-02-05 12:26:30 +01:00
Erik Eckstein
6493872ec5 BooleanLiteralFolding: remove dead blocks
Remove all dead blocks which are a result of constant folding condition branches
2024-02-02 11:45:38 +01:00
Erik Eckstein
7fb4fc0f36 MandatoryPerformanceOptimizations: fix the linkage of function-signature-specialized functions
We need to keep the original linkage because it would be illegal to call a shared not-serialized function from a serialized function.

Also, rename the API to create the specialized function.
2024-02-02 07:27:38 +01:00
eeckstein
fb5228d453 Merge pull request #71267 from eeckstein/function-signature-opt
MandatoryPerformanceOptimizations: perform function signature optimization to remove metatype arguments
2024-02-01 07:53:36 +01:00
eeckstein
13201e03c3 Merge pull request #71275 from eeckstein/fix-object-outliner
ObjectOutliner: don't outline objects with tail allocations
2024-02-01 07:47:24 +01:00
Andrew Trick
3002513c4e [NFC] disable verbose lifetime diagnostics by default 2024-01-31 18:58:45 -08:00
Erik Eckstein
bd7db677ed MandatoryPerformanceOptimizations: perform function signature optimization to remove metatype arguments
Generic specialization already takes care of removing metatype arguments of generic functions.
But sometimes non-generic functions have metatype arguments which must be removed.
We need handle this case with a function signature optimization.

This enables, for example, to use `OptionSet` in embedded swift.

rdar://121206953
2024-01-31 17:16:18 +01:00
Erik Eckstein
80051feb4c MandatoryPerformanceOptimizations: trigger another iteration if dead allocations were removed 2024-01-31 17:16:18 +01: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
Erik Eckstein
250e2680aa SwiftCompilerSources: add some module-level APIs
* `Context.lookupFunction`
* `ModulePassContext.loadFunction`
* `ModulePassContext.createSpecializedFunctionDeclaration`
* `ModulePassContext.moveFunctionBody`
* `ModulePassContext.mangle(withDeadArguments:)`
2024-01-31 17:16:13 +01:00
Erik Eckstein
fa0be3c10f SwiftCompilerSources: bridge some SIL APIs
* `TryApplyInst.specializationInfo`
* `BasicBlock.addFunctionArgument`
* `Function.appendNewBlock`
2024-01-31 17:16:12 +01:00
Erik Eckstein
a98448b89a swift Builder: add a few instruction creation functions 2024-01-31 17:16:12 +01:00
Erik Eckstein
240fa6d937 SIL: make swift ParameterInfo convertible back to C++ SILParameterInfo 2024-01-31 17:16:12 +01:00
Erik Eckstein
7a62f15dae pass Context: verify that only the currently transformed function is modified 2024-01-31 17:16:12 +01:00
Erik Eckstein
eb626c2814 ObjectOutliner: don't outline objects with tail allocations
An object with tail allocated elements is in risk of being passed to malloc_size, which does not work for non-heap allocated objects.
Conservatively, disable objects with tail allocations.

rdar://121886093
2024-01-31 16:25:21 +01:00
Andrew Trick
ddceffaf3b LifetimeDependenceDiagnostics pass
Initial diagnostic pass to enforce ~Escapable types.
2024-01-30 11:45:55 -08:00
Andrew Trick
4f03241759 Bridge Argument.varDecl 2024-01-30 08:38:57 -08:00
Andrew Trick
25cff623ab Improve LifetimeDependenceUtils 2024-01-30 08:38:57 -08:00