Skip to content

Commit 6da200f

Browse files
Merge pull request #84009 from aschwaighofer/assembly_vision_all_the_things
Add a flag to annotate all functions with the `optremark` (`@_assemblyVision`) attribute
2 parents cb02d6b + df5a8cd commit 6da200f

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-1
lines changed

include/swift/AST/SILOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ class SILOptions {
327327
/// The format used for serializing remarks (default: YAML)
328328
llvm::remarks::Format OptRecordFormat = llvm::remarks::Format::YAML;
329329

330+
/// Whether to apply _assemblyVision to all functions.
331+
bool EnableGlobalAssemblyVision = false;
332+
330333
/// Are there any options that indicate that functions should not be preserved
331334
/// for the debugger?
332335
bool ShouldFunctionsBePreservedToDebugger = true;

include/swift/Option/FrontendOptions.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,12 @@ let Flags = [FrontendOption, NoDriverOption, HelpHidden, ModuleInterfaceOptionIg
318318
Joined<["-"], "formal-cxx-interoperability-mode=">,
319319
HelpText<"What version of C++ interoperability a textual interface was originally generated with">,
320320
MetaVarName<"<cxx-interop-version>|off">;
321+
def enable_assembly_vision_all
322+
: Flag<["-"], "enable-assembly-vision-all">,
323+
HelpText<"Enable assembly vision for all functions">;
324+
def disable_assembly_vision_all
325+
: Flag<["-"], "disable-assembly-vision-all">,
326+
HelpText<"Disable assembly vision for all functions">;
321327
}
322328

323329
// Flags that are saved into module interfaces

lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3075,6 +3075,10 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
30753075
Opts.OptRecordFormat = *formatOrErr;
30763076
}
30773077

3078+
Opts.EnableGlobalAssemblyVision = Args.hasFlag(
3079+
OPT_enable_assembly_vision_all, OPT_disable_assembly_vision_all,
3080+
Opts.EnableGlobalAssemblyVision);
3081+
30783082
if (const Arg *A = Args.getLastArg(OPT_save_optimization_record_passes))
30793083
Opts.OptRecordPasses = A->getValue();
30803084

lib/SIL/IR/SILFunctionBuilder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ void SILFunctionBuilder::addFunctionAttributes(
6161
// function as force emitting all optremarks including assembly vision
6262
// remarks. This allows us to emit the assembly vision remarks without needing
6363
// to change any of the underlying optremark mechanisms.
64-
if (Attrs.getAttribute(DeclAttrKind::EmitAssemblyVisionRemarks))
64+
if (Attrs.getAttribute(DeclAttrKind::EmitAssemblyVisionRemarks) ||
65+
M.getOptions().EnableGlobalAssemblyVision)
6566
F->addSemanticsAttr(semantics::FORCE_EMIT_OPT_REMARK_PREFIX);
6667

6768
// Propagate @_specialize.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %target-swift-frontend -enable-assembly-vision-all -emit-sil %s -Osize -o - -module-name main 2>&1 | %FileCheck %s
2+
// RUN: %target-swift-frontend -enable-assembly-vision-all -emit-sil %s -Osize -o - -module-name main 2>&1 | %FileCheck %s --check-prefix=REMARK
3+
4+
public class C {
5+
6+
// CHECK: sil [transparent] [_semantics "optremark"] @$s4main1CC1iSivg
7+
public var i: Int = 0
8+
9+
// CHECK: sil hidden [_semantics "optremark"] @$s4main1CCACycfc
10+
init() {
11+
print("\(i)")
12+
}
13+
14+
// CHECK: sil [_semantics "optremark"] @$s4main1CC6methodSiyF
15+
public func method() -> Int {
16+
// REMARK: 17:14: remark: begin exclusive access to value of type 'Int'
17+
return i
18+
// REMARK: 17:14: remark: end exclusive access to value of type 'Int'
19+
}
20+
21+
// CHECK: sil [_semantics "optremark"] @$s4main1CCfd
22+
}
23+
24+
// CHECK sil [_semantics "optremark"] @$s4main12freestandingAA1CCyF
25+
public func freestanding() -> C {
26+
return C()
27+
}

0 commit comments

Comments
 (0)