Commit Graph

763 Commits

Author SHA1 Message Date
Erik Eckstein
def3b6fab0 AccessUtils: recognize addressor calls of globals as a "global" access base
Makes e.g. alias analysis more precise in the early stage of the pass pipeline where addressor calls are not inlined, yet.
2024-08-05 17:12:46 +02:00
Erik Eckstein
ac3e2cb141 EscapeUtils: handle more use types for unchecked_addr_cast
Handle `apply` and `try_apply`.
Also, improve test cases
2024-08-05 17:02:07 +02:00
Erik Eckstein
8f839f0eab AliasAnalysis: use AccessBase.isLet instead of duplicating the code
A small refactoring. NFC
2024-08-05 17:02:07 +02:00
Erik Eckstein
345f9c1dfc AliasAnalysis: handle destroy_value [dead_end] in computeMemoryEffect
We don't have to take deinit effects into acount for a `destroy_value [dead_end]`.
Such destroys are lowered to no-ops and will not call any deinit.
2024-08-05 17:02:06 +02:00
Erik Eckstein
e3de408716 Simplification: remove builtin "destroyArray" with trivial element types 2024-08-01 13:38:39 +02:00
Andrew Trick
3e98d2e232 Fix an assert in LifetimeDependenceUtils to allow all valid cases. 2024-07-31 22:58:39 -07:00
Andrew Trick
11ba799cd4 LifetimeDependence: diagnose yield and store-to-yield. 2024-07-30 16:27:48 -07:00
Andrew Trick
c8fcb722a3 LifetimeDependenceInsertion for inout dependencies. 2024-07-30 15:57:57 -07:00
Andrew Trick
11640461ef Lifetime dependence: add inferrence for setters.
A nonescapable computed property should always depend on 'newValue'. We simply
infer that now. There's no way to explicitly spell the dependence.
2024-07-30 15:57:57 -07:00
Andrew Trick
ba9f12a80f LifetimeDependenceDiagnostics support for inout reassignment.
This relies on parameter dependence targets.

i.e. dependsOn in parameter position instead of result position.
2024-07-30 15:57:57 -07:00
Andrew Trick
058d22b2b6 Fix LifetimeDependenceScopeFixup for loops.
Handle situations in which the uses of the new scope are inside a loop so the
new range has no end instructions.
2024-07-30 15:57:56 -07:00
Andrew Trick
f3cf529b5d [SwiftCompilerSources] use debugLog in diagnostic passes 2024-07-30 15:57:56 -07:00
Andrew Trick
d065a3e576 Merge pull request #75562 from atrick/nfc-lifedep
[nfc] LifetimeDiagnostics cleanup
2024-07-30 09:03:24 -07:00
Andrew Trick
1113c757f0 Improve function convention printing. 2024-07-29 23:44:02 -07:00
Andrew Trick
20905b2f8e LifetimeDependenceDiagnostics comment. 2024-07-29 23:44:02 -07:00
Andrew Trick
b4cdbd276b LifetimeDependenceUtils comment typo. 2024-07-29 23:44:02 -07:00
Andrew Trick
f6d147855f AddressUtils comment 2024-07-29 23:44:02 -07:00
Andrew Trick
103c59b273 [SwiftCompilerSources] Add assert to Builder.init(after:)
This API is incorrect for terminators. Assert that it isn't used
incorrectly. Later, we should rename it.
2024-07-29 23:44:02 -07:00
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
f9b524b1cb AliasAnalysis: a complete overhaul of alias- and memory-behavior analysis
The main changes are:

*) Rewrite everything in swift. So far, parts of memory-behavior analysis were already implemented in swift. Now everything is done in swift and lives in `AliasAnalysis.swift`. This is a big code simplification.

*) Support many more instructions in the memory-behavior analysis - especially OSSA instructions, like `begin_borrow`, `end_borrow`, `store_borrow`, `load_borrow`. The computation of end_borrow effects is now much more precise. Also, partial_apply is now handled more precisely.

*) Simplify and reduce type-based alias analysis (TBAA). The complexity of the old TBAA comes from old days where the language and SIL didn't have strict aliasing and exclusivity rules (e.g. for inout arguments). Now TBAA is only needed for code using unsafe pointers. The new TBAA handles this - and not more. Note that TBAA for classes is already done in `AccessBase.isDistinct`.

*) Handle aliasing in `begin_access [modify]` scopes. We already supported truly immutable scopes like `begin_access [read]` or `ref_element_addr [immutable]`. For `begin_access [modify]` we know that there are no other reads or writes to the access-address within the scope.

*) Don't cache memory-behavior results. It turned out that the hit-miss rate was pretty bad (~ 1:7). The overhead of the cache lookup took as long as recomputing the memory behavior.
2024-07-29 17:33:46 +02:00
Erik Eckstein
cf99536d7f Optimizer Utilities: add InstructionWorklist.pushPredecessors(of: Instruction, ignoring:) 2024-07-29 17:33:45 +02:00
Erik Eckstein
6cfec91f69 EscapeInfo: handle store_borrow 2024-07-29 17:33:45 +02:00
Erik Eckstein
c6e3f51217 EscapeInfo: handle unchecked_addr_cast
It's dangerous to continue walking over an `unchecked_addr_cast` which casts between two different types.
We can only do this if the result is known to be the end of the walk, i.e. the cast result is not used in a relevant way.
2024-07-29 17:33:44 +02:00
Erik Eckstein
1440ae7b71 EscapeInfo: handle is_unique 2024-07-29 17:33:44 +02:00
Erik Eckstein
da5857d5ec EscapeInfo: improve handling of begin_applys which yield an address value
Instead of just aborting if a `begin_apply` gets an address argument, follow the yielded values and see if they actually escape
2024-07-29 17:33:44 +02:00
Erik Eckstein
4c49e0039b Verifier: in the swift verifier call the bridged C++ verificationFailure function in case of a failure
This brings all the nice verifier features to the swift verifier, like printing the surrounding instructions in case of a failure, etc.
2024-07-29 17:33:43 +02: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
Erik Eckstein
7512acfd31 SwiftCompilerSources: fix debug description of Set
Make each instruction to appear in a separate line
2024-07-29 17:33:43 +02:00
Erik Eckstein
f388361885 SimplifyBuiltin: fix a wrong constant folding of the is_same_metatype builtin for function types
We need to compare the not lowered types, because function types may differ in their original version but are equal in the lowered version, e.g.
```
  ((Int, Int) -> ())
  (((Int, Int)) -> ())
```

Fixes a miscompile
2024-07-29 17:33:42 +02:00
Erik Eckstein
04e0907ab0 SIL: rename Type.instanceTypeOfMetatype -> Type.loweredInstanceTypeOfMetatype
The same for SILType

It needs to be made clear that this is not the "original", but the lowered SIL type.

NFC
2024-07-29 17:33:36 +02:00
Andrew Trick
c32c238720 Fix LifetimeDependenceDiagnostics to handle invalid SIL types
Invalid types are not considered Escapable. This makes it difficult to make any
assumptions about nonescapable types.

Fixes rdar://132348528 (Fix LifetimeDependenceDiagnostics to handle invalid SIL types)
2024-07-23 16:03:32 -07:00
Andrew Trick
c41dc33c10 LocalVariableUtils: handle projections inside initializers.
These projections don't have access scopes, so the utility was treating them
like escapes.

Fixes: rdar://131499478 (Difficulties composing non-escapable types)
2024-07-12 19:58:14 -07:00
Andrew Trick
ad2e58ed43 Assert that mark_dependence operands are distinct.
Various downstream passes assume that the dependent value is not the same as the
base value.
2024-07-05 10:42:31 -07:00
Erik Eckstein
19dccf78ce MandatoryPerformanceOptimizations: don't crash with empty global-init-once functions
Instead ignore empty global-init-once functions

https://github.com/swiftlang/swift/issues/73487
rdar://130041582
2024-07-02 14:03:01 +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
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
Erik Eckstein
1f9588e5c6 MandatoryPerformanceOptimizations: prevent inlining of dynamic-self class methods
This fixes a compiler crash in embedded swift.

rdar://129241915
2024-06-24 15:01:02 +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
Erik Eckstein
715a765b6e Deinit-Devirtualization: fix a crash when trying to de-virtualize a non-copyable generic
rdar://129980818
2024-06-17 13:47:46 +02:00
Nate Chandler
81fa65772f [OwnershipLiveness] End at extend_lifetime.
When visiting consumes, also visit `extend_lifetime` instructions.
These instructions are not lifetime ending, but together with the
consumes, they enclose the users of a value.

Add a flag to LinearLiveness to control whether these instructions are
added so that the verifier can use verify that all such instructions
appear outside the linear lifetime boundary (not including them).
2024-06-05 16:28:28 -07:00
Ellie Shin
6216ec648f Merge pull request #73902 from apple/elsh/pkg-cmo-inline
[SIL][PackageCMO] Allow optimizing [serialized_for_pkg] functions
2024-06-04 11:39:19 -07:00
Emil Pedersen
531469f70e Merge pull request #73864 from Snowy1803/scs-builder-skip-meta
Skip meta instructions for Builder.init with automatic location
2024-05-30 09:50:48 -07:00
Ellie Shin
c3ded85c4f Update SILBridgedFunction APIs.
Add isAnySerialized() and canBeInlinedIntoCaller(SerializedKind).
2024-05-29 15:54:36 -07:00
Emil Pedersen
d39d838c2b Skip meta instructions for Builder.init with automatic location 2024-05-24 16:01:11 -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
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
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