Skip to content

Commit c314fc1

Browse files
authored
Merge pull request #84296 from rjmansfield/emit-verbose-asm
Add frontend option -verbose-asm to emit verbose assembly.
2 parents 0a72aa6 + 4cc2940 commit c314fc1

File tree

7 files changed

+32
-4
lines changed

7 files changed

+32
-4
lines changed

include/swift/AST/IRGenOptions.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,9 @@ class IRGenOptions {
627627
/// Set to true if we support AArch64TBI.
628628
bool HasAArch64TBI = false;
629629

630+
/// Generate verbose assembly output with comments.
631+
bool VerboseAsm = true;
632+
630633
IRGenOptions()
631634
: OutputKind(IRGenOutputKind::LLVMAssemblyAfterOptimization),
632635
Verify(true), VerifyEach(false), OptMode(OptimizationMode::NotSet),
@@ -676,7 +679,8 @@ class IRGenOptions {
676679
SanitizeCoverage(llvm::SanitizerCoverageOptions()),
677680
TypeInfoFilter(TypeInfoDumpFilter::All),
678681
PlatformCCallingConvention(llvm::CallingConv::C), UseCASBackend(false),
679-
CASObjMode(llvm::CASBackendMode::Native), HasAArch64TBI(false) {
682+
CASObjMode(llvm::CASBackendMode::Native), HasAArch64TBI(false),
683+
VerboseAsm(true) {
680684
DisableRoundTripDebugTypes = !CONDITIONAL_ASSERT_enabled();
681685
}
682686

include/swift/Option/FrontendOptions.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,12 @@ def disable_modules_validate_system_headers : Flag<["-"], "disable-modules-valid
703703
def emit_verbose_sil : Flag<["-"], "emit-verbose-sil">,
704704
HelpText<"Emit locations during SIL emission">;
705705

706+
def verbose_asm : Flag<["-"], "verbose-asm">,
707+
HelpText<"Generate verbose assembly output with comments">;
708+
709+
def no_verbose_asm : Flag<["-"], "no-verbose-asm">,
710+
HelpText<"Disable verbose assembly output (default is enabled)">;
711+
706712
def emit_pch : Flag<["-"], "emit-pch">,
707713
HelpText<"Emit PCH for imported Objective-C header file">, ModeOpt;
708714

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3523,6 +3523,9 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
35233523

35243524
Opts.FunctionSections = Args.hasArg(OPT_function_sections);
35253525

3526+
Opts.VerboseAsm = Args.hasFlag(OPT_verbose_asm, OPT_no_verbose_asm,
3527+
/*default*/ true);
3528+
35263529
if (Args.hasArg(OPT_autolink_force_load))
35273530
Opts.ForceLoadSymbolName = Args.getLastArgValue(OPT_module_link_name).str();
35283531

lib/IRGen/IRGen.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ swift::getIRTargetOptions(const IRGenOptions &Opts, ASTContext &Ctx) {
160160
// command-line flags.
161161
TargetOpts.EmulatedTLS = Clang->getCodeGenOpts().EmulatedTLS;
162162

163+
TargetOpts.MCOptions.AsmVerbose = Opts.VerboseAsm;
164+
163165
// WebAssembly doesn't support atomics yet, see
164166
// https://github.com/apple/swift/issues/54533 for more details.
165167
if (Clang->getTargetInfo().getTriple().isOSBinFormatWasm())

test/IRGen/verbose_asm.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %target-swift-frontend -emit-assembly %s | %FileCheck %s --check-prefix=VERBOSE
2+
// RUN: %target-swift-frontend -emit-assembly -verbose-asm %s | %FileCheck %s --check-prefix=VERBOSE
3+
// RUN: %target-swift-frontend -emit-assembly -no-verbose-asm %s | %FileCheck %s --check-prefix=NO-VERBOSE
4+
5+
// Test that verbose assembly is enabled by default and can be disabled
6+
7+
func simpleFunction() -> Int {
8+
return 42
9+
}
10+
11+
// VERBOSE: {{;|#}} -- {{Begin|End}} function
12+
// NO-VERBOSE-NOT: {{;|#}} -- {{Begin|End}} function

test/Misc/tbi.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
// respects this option and that we get the proper tbi behavior.
44

55
// RUN: %swiftc_driver -sdk "" -parse-sil -Xfrontend -disable-legacy-type-info -target arm64-apple-ios8.0 -target-cpu cyclone \
6-
// RUN: -O -S %s -parse-as-library -parse-stdlib -module-name Swift \
6+
// RUN: -O -S %s -parse-as-library -parse-stdlib -module-name Swift -Xfrontend -no-verbose-asm \
77
// RUN: | \
88
// RUN: %FileCheck --check-prefix=TBI %s
99

1010
// RUN: %swiftc_driver -sdk "" -parse-sil -Xfrontend -disable-legacy-type-info -target arm64-apple-ios7.0 -target-cpu cyclone \
11-
// RUN: -O -S %s -parse-as-library -parse-stdlib -module-name Swift \
11+
// RUN: -O -S %s -parse-as-library -parse-stdlib -module-name Swift -Xfrontend -no-verbose-asm \
1212
// RUN: | \
1313
// RUN: %FileCheck --check-prefix=NO_TBI %s
1414

test/stdlib/Span/BoundsCheckOptimization.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
// RUN: %target-swift-frontend -primary-file %s -O -emit-assembly | %FileCheck %s --check-prefix CHECK --check-prefix CHECK-%target-cpu
13+
// RUN: %target-swift-frontend -primary-file %s -O -emit-assembly -no-verbose-asm | \
14+
// RUN: %FileCheck %s --check-prefix CHECK --check-prefix CHECK-%target-cpu
1415
// REQUIRES: swift_stdlib_no_asserts
1516

1617
import Swift

0 commit comments

Comments
 (0)