Commit Graph

25 Commits

Author SHA1 Message Date
Andrew Trick
b80bd16eea [NFC] Add LifetimeDependenceUseDefWalker utility.
Refactor VariableIntroducerUseDefWalker into a general
LifetimeDependenceUseDefWalker for use with LifetimeDependenceScopeFixup.
2025-04-16 16:43:23 -07:00
Andrew Trick
28daec01a7 Add InstructionRange.overlapsWithPath() utility. 2025-04-16 16:43:23 -07:00
Andrew Trick
ccb26bcd89 LocalVariableUtils: add unit tests 2025-04-10 23:27:55 -07:00
Andrew Trick
c3de120ca5 LifetimeDependence: simplify and fix multiple bugs.
Functional changes:

Improved modeling of dependence on local variable scopes.

For nested modify->read accesses, only extend the read accesses.

Avoid making a read access dependent on an inout argument.
The following needs to be an error to prevent span storage from being modified:

  @lifetime(owner)
  foo(owner: inout Owner) -> Span {
    owner.span
  }

Improve usability of borrowing trivial values (UnsafePointer). Allow:

  let span = Span(buffer.baseAddress)

Ignore access scopes for trivial values.

Structural changes:

Delete the LifetimeDependenceUseDefWalker.

Encapsulate all logic for variable introducers within the LifetimeDependenceInsertion pass. Once mark_dependence instructions are inserted, no subsequent pass needs to think about the "root" of a dependence.

Fixes: rdar://142451725 (Escape analysis fails with mutations)
2025-02-10 09:11:22 -08:00
Andrew Trick
05c501a8f6 Add AddressOwnershipLiveRangeTest 2024-12-14 22:46:55 -08: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
Andrew Trick
b88566a36c Merge pull request #73621 from atrick/fix-access-mark-uninit
Allow AddressUseDefWalker to continue past MarkUninitializedInst
2024-05-22 18:18:51 -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
Andrew Trick
1ac4b4dd9d [SwiftCompilerSources] Add swift_get_access_base unit tests.
Add a unit test harness to SwiftCompilerSources to match the one in C++ since
both source bases have different implementations of the same utilities, and they
must be consistent for correctness.
2024-05-14 10:31:24 -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 Jain
01654fd323 Merge pull request #71775 from jkshtj/main
[Autodiff] Adds part of the Autodiff specific closure-specialization optimization pass
2024-05-10 08:51:01 -07:00
Nate Chandler
c84e196b16 [Test] Reenable SIL unit tests on windows.
Use `fflush(stdout)` from C++.

Issue 73252.
2024-05-06 12:20:16 -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
c4eab6a54a Merge pull request #71266 from atrick/lifetime-insertion
Add the LifetimeDependenceInsertion pass.
2024-02-12 13:07:03 -08:00
Nate Chandler
f9ee089c04 [Test] Added troubleshooting note. 2024-02-12 10:23:13 -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
2ef870a52b Add LifetimeDependence utilities 2024-01-22 23:57:03 -08:00
Andrew Trick
8a2ae0b23c BorrowIntroducer unit tests 2024-01-17 08:37:14 -08:00
Andrew Trick
12ea57919a Test.swift cleanup for usability 2023-10-10 13:39:59 -07:00
Nate Chandler
9ca6b9ac1f [Test] Print to stdout.
In the C++ sources it is slightly more convenient to dump to stderr than
to print to stdout, but it is rather more unsightly to print to stderr
from the Swift sources.  Switch to stdout.  Also allows the dump
functions to be marked debug only.
2023-10-10 08:19:44 -07:00
Nate Chandler
99576dc261 [SwiftCompilerSources] NFC: Renamed two helper fns 2023-10-09 07:40:18 -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
Nate Chandler
e65e6678e5 [Gardening] Updated comment.
Mention that running FunctionTests written in swift requires
swift-in-compiler and fixed the name of the register function.
2023-10-08 09:42:24 -07:00
Nate Chandler
ae1f950315 [SwiftCompilerSources] Moved Test into Optimizer.
And changed the type of the context argument to FunctionPassContext.
2023-10-07 21:23:13 -07:00