Commit Graph

40 Commits

Author SHA1 Message Date
Anthony Latsis
17032b6eaf AST: Quote attributes more consistently in DiagnosticsSIL.def 2025-04-22 18:23:40 +01:00
Doug Gregor
c09bbf4c10 [Performance diagnostics] Enable checking of throw instructions
When performance diagnostics were introduced, typed throws didn't exist
so it was not generally possible to have throws anywhere without
triggering performance diagnostics. As a short term hack, we disabled
checking of `throw` instructions and the basic blocks that terminate
in a `throw`.

Now that typed throws is available and can be used to eliminate
allocations with error handling, remove all of the hacks. We'll now
diagnose attempts to throw or catch existential values (e.g., the `any
Error` used for untyped throws), but typed throws are fine.
2024-11-21 16:06:44 -08:00
Doug Gregor
eff9bacb1b Treat swift_willThrow(Typed) as not locking or performing allocation
Prior to throwing, Swift emits a call to `swift_willThrow(Typed)`,
which allows various diagnostic tools (such as debuggers and testing
libraries) to intercept errors at the point where they are initially
thrown.

Since `swift_willThrow(Typed)` can be hooked by arbitrary code at
runtime, there is no way for it to meet performance constraints like
@_noLocks or @_noAllocation. Therefore, in a function that has those
performance constraints specified, disable emission of the call to
`swift_willThrow(Typed)`.

Fixes rdar://140230684.
2024-11-21 10:18:57 -08:00
Daniel Rodríguez Troitiño
ba68faaed5 [test] Mark tests that use experimental/upcoming features as such
Find all the usages of `--enable-experimental-feature` or
`--enable-upcoming-feature` in the tests and replace some of the
`REQUIRES: asserts` to use `REQUIRES: swift-feature-Foo` instead, which
should correctly apply to depending on the asserts/noasserts mode of the
toolchain for each feature.

Remove some comments that talked about enabling asserts since they don't
apply anymore (but I might had miss some).

All this was done with an automated script, so some formatting weirdness
might happen, but I hope I fixed most of those.

There might be some tests that were `REQUIRES: asserts` that might run
in `noasserts` toolchains now. This will normally be because their
feature went from experimental to upcoming/base and the tests were not
updated.
2024-11-02 11:46:46 -07:00
Erik Eckstein
8b955d994e Fix a false performance error when using generic, but loadable types
For example: UnsafePointer<T>

rdar://135231581
2024-09-04 10:55:14 +02:00
Slava Pestov
322ce5a1ab SIL: Consistently drop substitution map when forming apply instructions
Fixes rdar://129298104.
2024-06-11 10:36:15 -04:00
Erik Eckstein
717880e844 PerformanceDiagnostics: avoid false meta-data alarms for non-loadable types
Non-loadable types don't necessarily need metadata, for example, structs with `@_rawLayout`

https://github.com/apple/swift/issues/73951
2024-06-10 18:25:08 +02:00
Erik Eckstein
fcc03b7046 SIL: fix runtime effects of initializing store
An initializing store is not a copy and therefore doesn't perform ref counting operations

Fixes a false performance error when using non-copyable types.
https://github.com/apple/swift/issues/73582
2024-05-14 09:29:42 +02:00
Erik Eckstein
20ca456601 SIL: fix runtime effect of copy_addr of trivial types
Fixes a false performance error
Reported in https://forums.swift.org/t/generic-type-nolocks-trouble/70667
2024-03-18 13:18:12 +01:00
Erik Eckstein
1a94f1ccb7 PerformanceDiagnostics: allow metatype arguments to _diagnoseUnexpectedEnumCaseValue
This is a fatal error function, used for imported C enums.

rdar://117520459
2023-12-14 12:51:01 +01:00
Erik Eckstein
11c74317a9 deinit-devirtualization: completely de-compose non-copyable destroys
Even if the destroyed value doesn't have a deinit.
This fixes a false alarm when a non-copyable value ends its lifetime in a function with performance annotations.

rdar://117002721
2023-12-13 20:03:02 +01:00
Erik Eckstein
3b514ff5fe tests: fix and re-enable the performance-annotations.swift test
The use of opaque return types requires `-disable-availability-checking`. Otherwise the test will fail when run for old targets.

rdar://119075334
2023-12-04 10:52:50 +01:00
Becca Royal-Gordon
d9d07e7b09 Merge pull request #70184 from beccadax/xfail-119075334
XFAIL SILOptimizer/performance-annotations.swift
2023-12-02 09:48:54 -08:00
Becca Royal-Gordon
93187836be XFAIL SILOptimizer/performance-annotations.swift
Blocking several bots:

https://ci.swift.org/job/oss-swift-package-macos/2456/
https://ci.swift.org/job/oss-swift_tools-R_stdlib-RD_test-simulator/4344/
https://ci.swift.org/job/oss-swift_tools-RA_stdlib-DA_test-device-non_executable/4949/
https://ci.swift.org/job/oss-swift_tools-RA_stdlib-RD_test-simulator/3362/

rdar://119075334
2023-12-02 09:47:15 -08:00
zoecarver
69498e2f2e [opt] Add three new perf annotations: @_noRuntime, @_noExistential, and @_noObjCBridging. 2023-12-01 09:13:24 -07:00
Erik Eckstein
c26134fbae PerformanceDiagnostics: correctly handle functions with multiple throws
This is a follow-up of https://github.com/apple/swift/pull/69300, which didn't handle function with multiple throws correctly.

rdar://117857767
2023-11-03 10:37:23 +01:00
Erik Eckstein
d27ca6a756 add a test to verify that precondition doesn't allocate in Onone builds 2023-10-27 10:47:07 +02:00
Erik Eckstein
1ec71a3568 PerformanceDiagnostics: exclude error handling from performance-checked code
This was changed in https://github.com/apple/swift/pull/69121. But it's a bit to early because we don't have typed throws, yet.

rdar://117219154
2023-10-20 10:33:48 +02:00
Erik Eckstein
e2a268ed70 PerformanceDiagnostics: fix handling of infinite loops and change error handling
* Don't exclude code which end up in an infinite loop. rdar://116705459
* Don't exclude error handling code (throw, catch). Errors are existentials and will always allocate. Once we have typed throws it will be possible to do error handling without allocations.
2023-10-11 12:02:51 +02:00
Erik Eckstein
1603035927 PerformanceDiagnostics: fix handling of nested closures
Need to handle `mark_dependence` instruction in the use-def walk for the closure value.

Fixes a false performance error.

rdar://114008787
2023-08-18 09:08:04 +02:00
Erik Eckstein
afc0f617e0 Optimizer: support statically initialized globals which contain pointers to other globals
For example:
```
  var p = Point(x: 10, y: 20)
  let o = UnsafePointer(&p)
```

Also support outlined arrays with pointers to other globals. For example:
```
var g1 = 1
var g2 = 2

func f() -> [UnsafePointer<Int>] {
  return [UnsafePointer(&g1), UnsafePointer(&g2)]
}
```
2023-08-10 20:50:36 +02:00
Erik Eckstein
64255651f5 MandatoryPerformanceOptimizations: refine the inlining decisions in global initializers
We inline a function (e.g. a struct initializer) into a global init function if the result is part of the initialized global.
Now, also handle functions with indirect return values. Such function can result from not-reabstracted generic specializations.
Handle cases where the result is stored into a temporary alloc_stack or directly stored to (a part) of the global variable.
2023-07-26 11:06:50 +02:00
Erik Eckstein
bfb5d21312 PerformanceDiagnostics: fix two small issues which result in false alarms
* Look through `begin_borrow` when analyzing closure values
* Treat non-escaping closures as trivial values when passed to a `partial_apply`

rdar://111046264
2023-06-21 12:46:39 +02:00
Erik Eckstein
7839b54b8a GenericSpecializer: drop metatype arguments in specialized functions
And replace them with explicit `metatype` instruction in the entry block.
This allows such metatype instructions to be deleted if they are dead.

This was already done for performance-annotated functions. But now do this for all functions.

It is essential that performance-annotated functions are specialized in the same way as other functions.
Because otherwise it can happen that the same specialization has different performance characteristics in different modules.
And it's up to the linker to select one of those ODR functions when linking.

Also, dropping metatype arguments is good for performance and code size in general.

This change also contains a few bug fixes for dropping metatype arguments.

rdar://110509780
2023-06-15 21:42:01 +02:00
Erik Eckstein
dfce8c2c05 Optimizer: replace the MandatoryGenericSpecializer with the MandatoryPerformanceOptimizations in the pipeline 2023-05-11 08:11:44 +02:00
Erik Eckstein
1e6511e7c0 Pass Pipeline: replace the old GlobalOpt with the new InitializeStaticGlobals and ReadOnlyGlobalVariablesPass passes. 2023-05-08 21:23:36 +02:00
Nate Chandler
90f7af22c9 [SILOpt] Run DestroyAddrHoisting in mandatory.
Run DestroyAddrHoisting in the pipeline where DestroyHoisting was
previously running.  Avoid extra ARC traffic that having no form of
destroy hoisting in the mandatory pipeline results in.

rdar://90495704
2023-04-04 11:11:34 -07:00
Erik Eckstein
fc30ac2431 Performance annotations: make UnsafeMutableRawBufferPointer.bindMemory allocation/lock free
Remove dead `metatype` instructions which only have `debug_value` uses.
We lose debug info for such type variables, but this is a compromise we need to accept to get allocation/lock free code.

rdar://103270882
2022-12-13 17:10:53 +01:00
Erik Eckstein
97d17a5451 Fix a crash in the mandatory inliner related to optimization remarks
Even if a function's type has a self parameter, it may be specialized and the function argument is actually not there anymore.

rdar://103065348
2022-12-07 13:51:32 +01:00
Erik Eckstein
d80d7ddcde MandatoryGenericSpecializer: add the partial_apply -> apply peephole optimization
In performance-annotated functions optimize the pattern where a partial_apply is immediately applied.
This remove the partial apply and thus avoids an allocation.

Fixes an unnecessary performance violation error.

rdar://95155145
2022-12-01 07:05:02 +01:00
Erik Eckstein
abfa0a34cc tests: add some performance diagnostics tests for integer operations 2022-07-07 08:35:04 +02:00
Erik Eckstein
f9130065f8 PerformanceDiagnostics: handle closures
Check if no-escaping closures meet the performance constraints.
Do this already when passing a closure to a function.

rdar://94729207
2022-07-07 08:35:04 +02:00
Erik Eckstein
481381b72e PerformanceDiagnostics: correctly handle initializers of global variables
So far, initializers of global variables were ignored.
The fix is to visit the called initializer of the builtin `once`.

rdar://94780620
2022-07-07 08:35:04 +02:00
Erik Eckstein
1cbea04103 run the TargetConstantFolding pass also at -Onone
This is important for performance diagnostics: it’s assumed that (non-generic) MemoryLayout constants do not need to create metadata at runtime. At Onone this is only guaranteed if the TargetConstantFolding pass runs.

rdar://94836837
2022-07-07 08:35:04 +02:00
Erik Eckstein
c3de7c1317 MandatoryGenericSpecializer: drop metatype arguments in specialized functions
And replace them with explicit `metatype` instruction in the entry block.
This allows such metatype instructions to be deleted if they are dead.

rdar://94388453
2022-07-07 08:34:54 +02:00
Erik Eckstein
4f64770b43 tests: re-enable performance-annotations.swift test
Just comment out the failing test (which needs rdar://90495704)
2022-07-07 08:34:53 +02:00
Nate Chandler
0ba00dbf66 [Test] Disabled a test temporarily.
rdar://90495704
2022-03-18 11:21:19 -07:00
Erik Eckstein
88219da06c PerformanceDiagnostics: don't issue a metatype diagnostics when using MemoryLayout
The metatype is not code-gend for the memory layout builtins.
Also fix the wrong help test for the -experimental-performance-annotations option.
2022-02-10 16:46:09 +01:00
Erik Eckstein
c578c937c8 SILOptimizer: run the GlobalOpt pass in the mandatory pipeline.
Replace the dynamic initialization of trivial globals with statically initialized globals, even in -Onone.
This is required to be able to use global variables in performance-annotated functions.
Also, it's a small performance improvement for -Onone.
2021-10-29 22:35:57 +02:00
Erik Eckstein
9f8b155c6c PerformanceDiagnostics: a pass to print errors for performance violations in annotated functions.
The PerformanceDiagnostics pass issues performance diagnostics for functions which are annotated with performance annotations, like @_noLocks, @_noAllocation.
This is done recursively for all functions which are called from performance-annotated functions.

rdar://83882635
2021-10-28 18:44:46 +02:00