Skip to content

Commit d5ae511

Browse files
authored
Merge pull request swiftlang#39902 from eeckstein/performance-annotations
First prototype of Performance Annotations
2 parents 99eadd0 + 9f8b155 commit d5ae511

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2049
-386
lines changed

docs/ReferenceGuides/UnderscoredAttributes.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,3 +625,12 @@ for more details.
625625

626626
Marks a var decl as a variable that must be copied explicitly using the builtin
627627
function Builtin.copy.
628+
629+
## `@_noAllocation`, `@_noLocks`
630+
631+
These attributes are performance annotations. If a function is annotated with
632+
such an attribute, the compiler issues a diagnostic message if the function
633+
calls a runtime function which allocates memory or locks, respectively.
634+
The `@_noLocks` attribute implies `@_noAllocation` because a memory allocation
635+
also locks.
636+

docs/SIL.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,15 @@ Specifies for which types specialized code should be generated.
11071107
sil-function-attribute ::= '[clang "' identifier '"]'
11081108

11091109
The clang node owner.
1110+
::
1111+
1112+
sil-function-attribute ::= '[' performance-constraint ']'
1113+
performance-constraint :: 'no_locks'
1114+
performance-constraint :: 'no_allocation'
1115+
1116+
Specifies the performance constraints for the function, which defines which type
1117+
of runtime functions are allowed to be called from the function.
1118+
11101119

11111120
Basic Blocks
11121121
~~~~~~~~~~~~

include/swift/AST/Attr.def

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,16 @@ SIMPLE_DECL_ATTR(_noImplicitCopy, NoImplicitCopy,
679679
OnVar,
680680
122)
681681

682+
SIMPLE_DECL_ATTR(_noLocks, NoLocks,
683+
OnAbstractFunction | OnSubscript | UserInaccessible |
684+
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
685+
123)
686+
687+
SIMPLE_DECL_ATTR(_noAllocation, NoAllocation,
688+
OnAbstractFunction | OnSubscript | UserInaccessible |
689+
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
690+
124)
691+
682692
// If you're adding a new underscored attribute here, please document it in
683693
// docs/ReferenceGuides/UnderscoredAttributes.md.
684694

include/swift/AST/DiagnosticsSIL.def

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,34 @@ WARNING(warn_dead_weak_store,none,
311311
"weak reference will always be nil because the referenced object is "
312312
"deallocated here", ())
313313

314+
// performance diagnostics
315+
ERROR(performance_annotations_not_enabled,none,
316+
"use -experimental-performance-annotations to enable performance annotations", ())
317+
ERROR(performance_dynamic_casting,none,
318+
"dynamic casting can lock or allocate", ())
319+
ERROR(performance_metadata,none,
320+
"%0 can cause metadata allocation or locks", (StringRef))
321+
ERROR(performance_metadata_type,none,
322+
"Using type %0 can cause metadata allocation or locks", (Type))
323+
ERROR(performance_allocating,none,
324+
"%0 can cause an allocation", (StringRef))
325+
ERROR(performance_deallocating,none,
326+
"%0 can cause an deallocation", (StringRef))
327+
ERROR(performance_deallocating_type,none,
328+
"%0 a value of type %1 can cause a deallocation", (StringRef, Type))
329+
ERROR(performance_locking,none,
330+
"%0 can cause locking", (StringRef))
331+
ERROR(performance_arc,none,
332+
"this code performs reference counting operations which can cause locking", ())
333+
ERROR(performance_objectivec,none,
334+
"calls of Objective-C methods can have unpredictable performance", ())
335+
ERROR(performance_unknown_callees,none,
336+
"called function is not known at compile time and can have unpredictable performance", ())
337+
ERROR(performance_callee_unavailable,none,
338+
"called function is not availbale in this module and can have unpredictable performance", ())
339+
NOTE(performance_called_from,none,
340+
"called from here", ())
341+
314342
// 'transparent' diagnostics
315343
ERROR(circular_transparent,none,
316344
"inlining 'transparent' functions forms circular loop", ())

include/swift/AST/SILOptions.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ class SILOptions {
7878

7979
/// Controls whether cross module optimization is enabled.
8080
bool CrossModuleOptimization = false;
81-
81+
82+
/// Enables experimental performance annotations.
83+
bool EnablePerformanceAnnotations = false;
84+
8285
/// Controls whether or not paranoid verification checks are run.
8386
bool VerifyAll = false;
8487

include/swift/AST/SemanticAttrs.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,7 @@ SEMANTICS_ATTR(OBJC_FORBID_ASSOCIATED_OBJECTS, "objc.forbidAssociatedObjects")
115115

116116
SEMANTICS_ATTR(LIFETIMEMANAGEMENT_MOVE, "lifetimemanagement.move")
117117

118+
SEMANTICS_ATTR(NO_PERFORMANCE_ANALYSIS, "no_performance_analysis")
119+
118120
#undef SEMANTICS_ATTR
119121

include/swift/Option/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,10 @@ def CrossModuleOptimization : Flag<["-"], "cross-module-optimization">,
798798
Flags<[HelpHidden, FrontendOption]>,
799799
HelpText<"Perform cross-module optimization">;
800800

801+
def ExperimentalPerformanceAnnotations : Flag<["-"], "experimental-performance-annotations">,
802+
Flags<[HelpHidden, FrontendOption]>,
803+
HelpText<"Perform cross-module optimization">;
804+
801805
def RemoveRuntimeAsserts : Flag<["-"], "remove-runtime-asserts">,
802806
Flags<[FrontendOption]>,
803807
HelpText<"Remove runtime safety checks.">;

include/swift/Runtime/RuntimeFnWrappersGen.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#ifndef SWIFT_RUNTIME_RUNTIMEFNWRAPPERSGEN_H
1717
#define SWIFT_RUNTIME_RUNTIMEFNWRAPPERSGEN_H
1818

19+
#include "swift/SIL/RuntimeEffect.h"
1920
#include "llvm/IR/Module.h"
2021
#include "llvm/ADT/ArrayRef.h"
2122

0 commit comments

Comments
 (0)