Commit Graph

16 Commits

Author SHA1 Message Date
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
zoecarver
f6b1775f2c [nfc][opt] Add more stack traces and make them more specific. 2023-07-17 12:56:21 -07:00
zoecarver
a58cc2f0a5 [nfc][opts] Add a few pretty-stack traces to performance diagnostics.
It can be very hard to debug (from a compiler engineers perspective) why the perforamnce diagnostics aren't allowing a certain pattern. Usually this means adding a bunch of random SIL dumps to debug. With these stack traces, you can now just add `-Xllvm -swift-diagnostics-assert-on-error=1` and the stack dumps will do the rest.
2023-07-17 12:25:13 -07:00
Kuba Mracek
145f12f6a3 Allow using structs with trivial initializers in globals that require static initialization (e.g. @_section attribute)
Before this change, if a global variable is required to be statically initialized (e.g. due to @_section attribute), we don't allow its type to be a struct, only a scalar type works. This change improves on that by teaching MandatoryPerformanceOptimizations pass to inline struct initializer calls into initializer of globals, as long as they are simple enough so that we can be sure that we don't trigger recursive/infinite inlining.
2023-07-08 19:26:59 -07:00
Kuba (Brecka) Mracek
d427696bf9 Allow @_silgen_name to be used on globals and add a @_silgen_name(raw: ...) version that skips mangling (#66540)
Attribute @_silgen_name is today only allowed to be used on functions, this change allows usage on globals as well. The motivation for that is to be able to "forward declare" globals just like it's today possible to do with functions (for the cases where it's not practical or convenient to use a bridging header).

Separately, this change also adds a @_silgen_name(raw: ...) syntax, which simply avoids mangling the name (by using the \01 name prefix that LLVM uses). The motivation for that is to be able to reference the "magic Darwin linker symbols" that can be used to look up section bounds (in the current dylib/module) -- those symbols don't use the underscore prefix in their mangled names.
2023-06-29 08:37:51 -07: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
fe87b99e4d PerformanceDiagnostics: when checking closure values, look through convert_function 2023-06-15 21:42:01 +02:00
Kuba (Brecka) Mracek
2d5f33e2e3 Add @_used and @_section attributes for global variables and top-level functions (#65901)
* Add @_used and @_section attributes for global variables and top-level functions

This adds:
- @_used attribute that flags as a global variable or a top-level function as
  "do not dead-strip" via llvm.used, roughly the equivalent of
  __attribute__((used)) in C/C++.
- @_section("...") attribute that places a global variable or a top-level
  function into a section with that name, roughly the equivalent of
  __attribute__((section("..."))) in C/C++.
2023-05-26 14:02:32 -07:00
Erik Eckstein
85052a1489 deprecate the -experimental-performance-annotations option
Performance annotations can now be used without specifying this option
2023-05-11 08:03:19 +02:00
Erik Eckstein
8ea848a937 PerformanceDiagnostics: fix missing diagnostics 2023-05-11 08:03:19 +02:00
Joe Groff
69e4b95fb8 SIL: Model noescape partial_applys with ownership in OSSA.
Although nonescaping closures are representationally trivial pointers to their
on-stack context, it is useful to model them as borrowing their captures, which
allows for checking correct use of move-only values across the closure, and
lets us model the lifetime dependence between a closure and its captures without
an ad-hoc web of `mark_dependence` instructions.

During ownership elimination, We eliminate copy/destroy_value instructions and
end the partial_apply's lifetime with an explicit dealloc_stack as before,
for compatibility with existing IRGen and non-OSSA aware passes.
2023-02-16 21:43:53 -08: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
45c8c5f54d PerformanceDiagnostics: fix a crash when emitting a module
rdar://93439187
2022-05-27 19:03:55 +02: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
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