Skip to content

Commit 3fdb0fd

Browse files
committed
[assembly-vision] Add function attribute '@_assemblyVision'
This is just a shortcut for @_semantics("optremark") to make it easier for people to remember how to enable assembly vision remarks. Now one can just type: ``` @_assemblyVision func foo() { ... } ``` and get all normal opt-remarks + assembly vision remarks.
1 parent 18670fc commit 3fdb0fd

File tree

6 files changed

+25
-1
lines changed

6 files changed

+25
-1
lines changed

include/swift/AST/Attr.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,11 @@ SIMPLE_DECL_ATTR(_distributedActorIndependent, DistributedActorIndependent,
672672
APIBreakingToAdd | APIBreakingToRemove,
673673
119)
674674

675+
SIMPLE_DECL_ATTR(_assemblyVision, EmitAssemblyVisionRemarks,
676+
OnFunc | UserInaccessible | NotSerialized |
677+
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
678+
120)
679+
675680
#undef TYPE_ATTR
676681
#undef DECL_ATTR_ALIAS
677682
#undef CONTEXTUAL_DECL_ATTR_ALIAS

lib/SIL/IR/SILFunctionBuilder.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "swift/SIL/SILFunctionBuilder.h"
14+
#include "swift/AST/AttrKind.h"
1415
#include "swift/AST/Availability.h"
1516
#include "swift/AST/Decl.h"
17+
#include "swift/AST/SemanticAttrs.h"
18+
1619
using namespace swift;
1720

1821
SILFunction *SILFunctionBuilder::getOrCreateFunction(
@@ -45,6 +48,13 @@ void SILFunctionBuilder::addFunctionAttributes(
4548
for (auto *A : Attrs.getAttributes<SemanticsAttr>())
4649
F->addSemanticsAttr(cast<SemanticsAttr>(A)->Value);
4750

51+
// If we are asked to emit assembly vision remarks for this function, mark the
52+
// function as force emitting all optremarks including assembly vision
53+
// remarks. This allows us to emit the assembly vision remarks without needing
54+
// to change any of the underlying optremark mechanisms.
55+
if (auto *A = Attrs.getAttribute(DAK_EmitAssemblyVisionRemarks))
56+
F->addSemanticsAttr(semantics::FORCE_EMIT_OPT_REMARK_PREFIX);
57+
4858
// Propagate @_specialize.
4959
for (auto *A : Attrs.getAttributes<SpecializeAttr>()) {
5060
auto *SA = cast<SpecializeAttr>(A);

lib/Sema/TypeCheckAttr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
9090
IGNORED_ATTR(RequiresStoredPropertyInits)
9191
IGNORED_ATTR(RestatedObjCConformance)
9292
IGNORED_ATTR(Semantics)
93+
IGNORED_ATTR(EmitAssemblyVisionRemarks)
9394
IGNORED_ATTR(ShowInInterface)
9495
IGNORED_ATTR(SILGenName)
9596
IGNORED_ATTR(StaticInitializeObjCMetadata)

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,6 +1480,7 @@ namespace {
14801480
UNINTERESTING_ATTR(Required)
14811481
UNINTERESTING_ATTR(Convenience)
14821482
UNINTERESTING_ATTR(Semantics)
1483+
UNINTERESTING_ATTR(EmitAssemblyVisionRemarks)
14831484
UNINTERESTING_ATTR(SetterAccess)
14841485
UNINTERESTING_ATTR(TypeEraser)
14851486
UNINTERESTING_ATTR(SPIAccessControl)

lib/Serialization/ModuleFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5656
/// describe what change you made. The content of this comment isn't important;
5757
/// it just ensures a conflict if two people change the module format.
5858
/// Don't worry about adhering to the 80-column limit for this line.
59-
const uint16_t SWIFTMODULE_VERSION_MINOR = 615; // isolated parameters
59+
const uint16_t SWIFTMODULE_VERSION_MINOR = 616; // @_assemblyVision
6060

6161
/// A standard hash seed used for all string hashes in a serialized module.
6262
///

test/SILOptimizer/assemblyvision_remark/semantics.swift renamed to test/SILOptimizer/assemblyvision_remark/attributes.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,10 @@ public func mix5() -> (Klass, Klass) {
8585
let x = getGlobal()
8686
return (x, Klass())
8787
}
88+
89+
@_assemblyVision
90+
public func mix4a() -> (Klass, Klass) {
91+
let x = getGlobal()
92+
return (x, Klass()) // expected-remark {{Pure call. Always profitable to inline "main.Klass.__allocating_init()"}}
93+
// expected-remark @-1 {{heap allocated ref of type 'Klass'}}
94+
}

0 commit comments

Comments
 (0)