Commit Graph

248 Commits

Author SHA1 Message Date
Andrew Trick
22f01a956a [SwiftCompilerSources] add BridgedOStream and debugLog().
So we can trace optimizer passes using the same output stream as the
C++ passes and don't get garbled output.
2024-07-29 21:25:43 -07:00
Erik Eckstein
9eddb24c41 EscapeUtils: replace ...byWalkingDown APIs with an initialWalkingDirection parameter
It simplifies the EscapeUtils API
NFC
2024-07-29 17:33:43 +02:00
eeckstein
8455309dc2 Merge pull request #74766 from eeckstein/remove-stderr-reference
SwiftCompilerSources: remove references to C's stderr
2024-06-30 14:46:19 +02:00
Akira Hatanaka
42bc49d3fe Add a new parameter convention @in_cxx for non-trivial C++ classes that are passed indirectly and destructed by the caller (#73019)
This corresponds to the parameter-passing convention of the Itanium C++
ABI, in which the argument is passed indirectly and possibly modified,
but not destroyed, by the callee.

@in_cxx is handled the same way as @in in callers and @in_guaranteed in
callees. OwnershipModelEliminator emits the call to destroy_addr that is
needed to destroy the argument in the caller.

rdar://122707697
2024-06-27 09:44:04 -07:00
Erik Eckstein
638205e8c6 SwiftCompilerSources: remove references to C's stderr
Fixes a linux build error.
The `var standardError` was only used in one place for logging, which can be done with `log` anyway.
Instead of using such C library constructs directly we should bridge to higher level APIs. This is more platform independent.

https://github.com/swiftlang/swift/issues/73252
https://github.com/swiftlang/swift/issues/74701
2024-06-27 10:14:44 +02:00
Andrew Trick
279eb78d27 [windows] Temporarily guard lifetime dependence diagnostics
by -enable-experimental-feature NonescapableTypes
on the Windows platform

These passes do nothing unless the above feature flag is enabled, so
the only reason to run the pass is to exercise SwiftCompilerSources
and catch invalid SIL.

These passes rely on fundamental SwiftCompilerSources abstractions
which have not yet been tested outside of the passes. They don't yet
handle all SIL patterns, and SIL continues to evolve. We would like to
can these issues quickly as we hit them, but only if we have a way of
reproducing the failure. Currently, we don't have a way of reproducing
Windows-arm64 failures.

Workaround for:
rdar://128434000 ([nonescapable] [LifetimeDependenceInsertion]
Package resolution fails with arm64 Windows toolchain)
2024-06-20 16:51:21 -07:00
Kshitij Jain
64da348ee9 Merge pull request #73688 from jkshtj/main
[Autodiff] Adds logic to rewrite call-sites using functions specialized by the closure-spec optimization
2024-05-23 14:21:31 -07:00
Kshitij
487648a3aa [Autodiff] Fixes bugs in closure-spec opt that were causing "optimized" test failures on Linux builds 2024-05-22 22:24:31 -07:00
Kshitij
c288d95c1e [Autodiff] Separates out changes for using non-ossa instructions in the closure-spec optimization pass
The OSSA elimination pass has not yet been moved below all high level
function passes. Until that work has been completed the Autodiff
closure-spec optimization pass cannot solely support OSSA instructions.
2024-05-21 12:02:28 -07:00
Kshitij
12faf79911 [Autodiff] Adds logic to rewrite call-sites using functions specialized by the closure-spec optimization 2024-05-21 12:02:28 -07:00
Erik Eckstein
ccc691cc42 ObjectOutliner: try outline alloc_refs in multiple iterations to handle multi-dimensional arrays
This allows to completely statically allocate multi-dimensional global arrays, like
```
var x = [[1, 2], [3, 4], [5, 6]]
```
2024-05-17 17:03:07 +02:00
Erik Eckstein
af68435d90 Optimizer: support static initialization of global arrays
The buffer of global arrays could already be statically initialized.
The missing piece was the array itself, which is basically a reference to the array buffer.
For example:
```
var a = [1, 2, 3]
```
ends up in two statically initialized globals:
1. the array buffer, which contains the elements
2. the variable `a` which is a single reference (= pointer) of the array buffer

This optimization removes the need for lazy initialization of such variables.

rdar://127757554
2024-05-16 21:34:36 +02:00
Kshitij Jain
c37d31cc64 Merge pull request #73596 from jkshtj/specialize
[Autodiff] Adds logic to generate specialized functions in the closure-spec pass
2024-05-14 18:55:23 -07:00
nate-chandler
4cf63a9394 Merge pull request #73576 from nate-chandler/gardening/20240510/1
[Gardening] SIL: Spelling of live range.
2024-05-14 15:50:08 -07:00
Kshitij
ce2161ee43 [Autodiff] Fixes build issues on Linux 2024-05-13 19:25:18 -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
Erik Eckstein
4b2973a43c ComputeSideEffects: correctly handle escaping arguments
If an argument escapes in a called function, we don't know anything about the argument's side effects.
For example, it could escape to the return value and effects might occur in the caller.

Fixes a miscompile
https://github.com/apple/swift/issues/73477
rdar://127691335
2024-05-13 18:27:49 +02:00
Nate Chandler
7bfd7110cc [Gardening] SIL: "LifeRange" -> "LiveRange" 2024-05-10 15:56:35 -07:00
Nate Chandler
71368be8d4 [Gardening] SIL: "Liferange" -> "Liverange" 2024-05-10 15:54:09 -07:00
Nate Chandler
87e4c65e28 [Gardening] SIL: "liferange" -> "liverange" 2024-05-10 15:54:07 -07:00
Kshitij
c6330a7d3f Rev: Addressed feedback 2024-05-02 13:16:12 -07:00
Kshitij
fd609846ae Makes the swift-based closure-spec pass an experimental frontend feature 2024-05-02 09:14:05 -07:00
Kshitij
c8375c06ae [Autodiff] Adds part of the closure-specialization optimization pass
Changes in this CR add part of the, Swift based, Autodiff specific
closure specialization optimization pass. The pass does not modify any
code nor does it even exist in any of the optimization pipelines. The
rationale for pushing this partially complete optimization pass upstream
is to keep up with the breaking changes in the underlying Swift based
compiler infrastructure.
2024-05-02 09:14:05 -07:00
eeckstein
87a520ccb2 SwiftCompilerSources: exclude some low level file operations, which are not compilable on windows 2024-04-29 10:52:25 +02:00
Andrew Trick
fbae21ff21 LifetimeDependence: handle dependent values in throwing calls.
Fixes rdar://125564278 (~Escapable: crash in LifetimeDependenceInsertion)
2024-04-03 10:46:09 -07:00
Andrew Trick
f19d94ce3f Always-enable lifetime-depenence diagnostics.
-enable-experimental-feature NonescapableTypes now only controls syntax and some type inferrence features.
2024-03-27 13:57:11 -07:00
Andrew Trick
36b9ed4f9b Fix LifetimeDependenceDiagnostics to ignore closure captures
ClosureLifetimeFixup now emits mark_dependence [nonescaping]. Those should be
ignored by diagnostics. In the capture case, the dependence has already been
resolved, and may not match the SIL patterns that we expect for source-level
lifetime dependencies.

Fixes rdar://125375685 ([nonescapable] Fix lifetime-dependence diagnostics in the stdlib)
2024-03-27 13:54:27 -07:00
Andrew Trick
a0b2ae9c2c Add AccessBase.storeBorrow.
Don't treat StoreBorrow addresses as unknown bases. While they are never the base of a formal access, they are returned
as the AccessBase when querying the enclosing scope of an address.
2024-03-22 11:51:58 -07:00
Andrew Trick
08be9aebf2 LifetimeDependence cleanup logging 2024-03-22 11:51:58 -07:00
Andrew Trick
352724ea0d LifetimeDependenceScopeFixup logging 2024-03-18 17:45:33 -07:00
Erik Eckstein
c5c2688633 InitializeStaticGlobals: don't merge stores for structs with unreferencable storage
like C bitfields.

Fixes a compiler crash
rdar://122360051
2024-03-08 11:14:48 +01:00
Andrew Trick
8419cc599f Guard LifetimeDependenceScopeFixup under experimental NonescapableTypes
Out of paranoia, don't even try to run this path unless we see
-enable-experimental-feature NonescapableTypes.
2024-03-07 15:13:50 -08:00
Andrew Trick
df7326d790 Fix SILType::isEscapable for box types.
SILBoxTypes have their own generic signature and substitution
map. This means that every time we query isEscapable or mayEscape, we
need to extract the type of the box's field and perform type
substitution so that the AST query only sees types from the function's
generic environment.

Fixes rdar://124179106 (Assertion failed in SIL:
(!type->hasTypeParameter() && "caller forgot to mapTypeIntoContext!"))
2024-03-07 13:34:46 -08:00
Andrew Trick
3bee32639b LifetimeDependenceDefUseWalker: use LocalVariableReachableUses. 2024-03-05 18:08:16 -08:00
Andrew Trick
d01d74e20c LifetimeDependenceDiagnostics: find the correct variable introducer. 2024-03-05 17:08:13 -08:00
Andrew Trick
5c956f7437 Review feedback; only rewrite access scopes when necessary 2024-03-05 17:08:13 -08:00
Andrew Trick
7dea051bf6 Review feedback; Builder.createEndAccess() 2024-03-05 17:08:13 -08:00
Andrew Trick
d1a75e725c LifetimeDependenceScopeFixup: handle non-dominated dependent uses. 2024-03-05 17:08:13 -08:00
Andrew Trick
1122cc445f LifetimeDependenceScopeFixup: fix handling of returned dependence
Only rewrite the mark_dependence to depend on the function argument when the
dependent value is actually returned.

Also, find all uses even if an escaping use is seen.
2024-03-05 17:08:13 -08:00
Andrew Trick
8aa1d91a2c LifetimeDependence: clarify log headers 2024-03-05 17:08:13 -08:00
Michael Gottesman
11f0ff6e32 [sil] Ensure that all SILValues have a parent function by making it so that SILUndef is uniqued at the function instead of module level.
For years, optimizer engineers have been hitting a common bug caused by passes
assuming all SILValues have a parent function only to be surprised by SILUndef.
Generally we see SILUndef not that often so we see this come up later in
testing. This patch eliminates that problem by making SILUndef uniqued at the
function level instead of the module level. This ensures that it makes sense for
SILUndef to have a parent function, eliminating this possibility since we can
define an API to get its parent function.

rdar://123484595
2024-02-27 13:14:47 -08:00
Andrew Trick
56126e9db9 Fix LetPropertyLowering to correctly find mark_uninitialized uses. 2024-02-26 00:20:46 -08:00
Andrew Trick
a3cbc28078 SwiftCompilerSources: Add enum BeginAccess.AccessKind
So we can switch over it.
2024-02-25 10:22:06 -08:00
Meghana Gupta
12ac8042ab Handle YieldInst in LifetimeDependenceUtils 2024-02-19 15:28:04 -08:00
Andrew Trick
68037faa61 LifetimeDependenceScopeFixup: handle nested access
After extending access scopes, rewrite the mark_depenendence to be on
the outermost scope.
2024-02-13 22:22:28 -08:00
Andrew Trick
bc0f60afc9 LifetimeDependenceDiagnostics: cleanup. remove unused code. 2024-02-13 20:57:02 -08:00
Meghana Gupta
75bd5b08dd Add LifetimeDependenceScopeFixup pass 2024-02-13 16:52:01 -08: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
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