[llvm] [gold] Add a new `-plugin-opt` to enable `MCTargetOptions::AsmVerbose` (PR #71606)

Min-Yih Hsu via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 7 15:52:17 PST 2023


https://github.com/mshockwave created https://github.com/llvm/llvm-project/pull/71606

Use `-plugin-opt=asm-verbose` to print comments into assembly output.

>From 331f085cec4ad2e3fc0473892b6089b0e3c1832c Mon Sep 17 00:00:00 2001
From: Min Hsu <min.hsu at sifive.com>
Date: Mon, 6 Nov 2023 11:10:45 -0800
Subject: [PATCH] [gold] Add a new `-plugin-opt` to enable
 `MCTargetOptions::AsmVerbose`

---
 llvm/test/tools/gold/X86/asm-verbose.ll | 15 +++++++++++++++
 llvm/tools/gold/gold-plugin.cpp         |  6 ++++++
 2 files changed, 21 insertions(+)
 create mode 100644 llvm/test/tools/gold/X86/asm-verbose.ll

diff --git a/llvm/test/tools/gold/X86/asm-verbose.ll b/llvm/test/tools/gold/X86/asm-verbose.ll
new file mode 100644
index 000000000000000..252d5b3a076d613
--- /dev/null
+++ b/llvm/test/tools/gold/X86/asm-verbose.ll
@@ -0,0 +1,15 @@
+; RUN: llvm-as -o %t.bc %s
+; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext -plugin-opt=emit-asm \
+; RUN:    -plugin-opt=asm-verbose \
+; RUN:    -m elf_x86_64 -r -o %t.s %t.bc
+; RUN: FileCheck --input-file=%t.s %s
+
+; Check if comments are emitted into assembly.
+; CHECK: -- End function
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define i32 @foo() {
+  ret i32 10
+}
diff --git a/llvm/tools/gold/gold-plugin.cpp b/llvm/tools/gold/gold-plugin.cpp
index d9e5983a4bacd63..bc4514990fa8f20 100644
--- a/llvm/tools/gold/gold-plugin.cpp
+++ b/llvm/tools/gold/gold-plugin.cpp
@@ -152,6 +152,7 @@ namespace options {
   static std::string extra_library_path;
   static std::string triple;
   static std::string mcpu;
+  static bool asm_verbose = false;
   // When the thinlto plugin option is specified, only read the function
   // the information from intermediate files and write a combined
   // global index for the ThinLTO backends.
@@ -308,6 +309,8 @@ namespace options {
       RemarksFormat = std::string(opt);
     } else if (opt.consume_front("stats-file=")) {
       stats_file = std::string(opt);
+    } else if (opt == "asm-verbose") {
+      asm_verbose = true;
     } else {
       // Save this option to pass to the code generator.
       // ParseCommandLineOptions() expects argv[0] to be program name. Lazily
@@ -950,6 +953,9 @@ static std::unique_ptr<LTO> createLTO(IndexWriteCallback OnIndexWrite,
   Conf.HasWholeProgramVisibility = options::whole_program_visibility;
 
   Conf.StatsFile = options::stats_file;
+
+  Conf.Options.MCOptions.AsmVerbose = options::asm_verbose;
+
   return std::make_unique<LTO>(std::move(Conf), Backend,
                                 options::ParallelCodeGenParallelismLevel);
 }



More information about the llvm-commits mailing list