Skip to content

Commit 4cc2940

Browse files
committed
Add frontend option -verbose-asm to emit verbose assembly.
This enables the option by default to aid readability with -emit-assembly.
1 parent 5e32563 commit 4cc2940

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
@@ -608,6 +608,9 @@ class IRGenOptions {
608608
/// Set to true if we support AArch64TBI.
609609
bool HasAArch64TBI = false;
610610

611+
/// Generate verbose assembly output with comments.
612+
bool VerboseAsm = true;
613+
611614
IRGenOptions()
612615
: OutputKind(IRGenOutputKind::LLVMAssemblyAfterOptimization),
613616
Verify(true), VerifyEach(false), OptMode(OptimizationMode::NotSet),
@@ -657,7 +660,8 @@ class IRGenOptions {
657660
SanitizeCoverage(llvm::SanitizerCoverageOptions()),
658661
TypeInfoFilter(TypeInfoDumpFilter::All),
659662
PlatformCCallingConvention(llvm::CallingConv::C), UseCASBackend(false),
660-
CASObjMode(llvm::CASBackendMode::Native), HasAArch64TBI(false) {
663+
CASObjMode(llvm::CASBackendMode::Native), HasAArch64TBI(false),
664+
VerboseAsm(true) {
661665
DisableRoundTripDebugTypes = !CONDITIONAL_ASSERT_enabled();
662666
}
663667

include/swift/Option/FrontendOptions.td

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

692+
def verbose_asm : Flag<["-"], "verbose-asm">,
693+
HelpText<"Generate verbose assembly output with comments">;
694+
695+
def no_verbose_asm : Flag<["-"], "no-verbose-asm">,
696+
HelpText<"Disable verbose assembly output (default is enabled)">;
697+
692698
def emit_pch : Flag<["-"], "emit-pch">,
693699
HelpText<"Emit PCH for imported Objective-C header file">, ModeOpt;
694700

lib/Frontend/CompilerInvocation.cpp

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

34983498
Opts.FunctionSections = Args.hasArg(OPT_function_sections);
34993499

3500+
Opts.VerboseAsm = Args.hasFlag(OPT_verbose_asm, OPT_no_verbose_asm,
3501+
/*default*/ true);
3502+
35003503
if (Args.hasArg(OPT_autolink_force_load))
35013504
Opts.ForceLoadSymbolName = Args.getLastArgValue(OPT_module_link_name).str();
35023505

lib/IRGen/IRGen.cpp

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

162+
TargetOpts.MCOptions.AsmVerbose = Opts.VerboseAsm;
163+
162164
// WebAssembly doesn't support atomics yet, see
163165
// https://github.com/apple/swift/issues/54533 for more details.
164166
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)