[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
Fri Nov 10 11:07:59 PST 2023


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

>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 1/3] [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);
 }

>From b4b094e91552bbf7a427f3e721569889250fcaf3 Mon Sep 17 00:00:00 2001
From: Min-Yih Hsu <min.hsu at sifive.com>
Date: Fri, 10 Nov 2023 11:04:15 -0800
Subject: [PATCH 2/3] Enable AsmVerbose once we're using assembly output

---
 llvm/test/tools/gold/X86/asm-verbose.ll | 15 ---------------
 llvm/test/tools/gold/X86/emit-asm.ll    |  4 ++++
 llvm/tools/gold/gold-plugin.cpp         |  6 +-----
 3 files changed, 5 insertions(+), 20 deletions(-)
 delete 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
deleted file mode 100644
index 252d5b3a076d613..000000000000000
--- a/llvm/test/tools/gold/X86/asm-verbose.ll
+++ /dev/null
@@ -1,15 +0,0 @@
-; 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/test/tools/gold/X86/emit-asm.ll b/llvm/test/tools/gold/X86/emit-asm.ll
index 40ff71f6143e2a3..1c511dfa377c3eb 100644
--- a/llvm/test/tools/gold/X86/emit-asm.ll
+++ b/llvm/test/tools/gold/X86/emit-asm.ll
@@ -23,3 +23,7 @@ define void @f1() {
 define void @f2() {
   ret void
 }
+
+; Check if comments are emitted into assembly.
+; CHECK: -- End function
+
diff --git a/llvm/tools/gold/gold-plugin.cpp b/llvm/tools/gold/gold-plugin.cpp
index bc4514990fa8f20..2b935049320d346 100644
--- a/llvm/tools/gold/gold-plugin.cpp
+++ b/llvm/tools/gold/gold-plugin.cpp
@@ -152,7 +152,6 @@ 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.
@@ -309,8 +308,6 @@ 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
@@ -928,6 +925,7 @@ static std::unique_ptr<LTO> createLTO(IndexWriteCallback OnIndexWrite,
     break;
   case options::OT_ASM_ONLY:
     Conf.CGFileType = CodeGenFileType::AssemblyFile;
+    Conf.Options.MCOptions.AsmVerbose = true;
     break;
   }
 
@@ -954,8 +952,6 @@ static std::unique_ptr<LTO> createLTO(IndexWriteCallback OnIndexWrite,
 
   Conf.StatsFile = options::stats_file;
 
-  Conf.Options.MCOptions.AsmVerbose = options::asm_verbose;
-
   return std::make_unique<LTO>(std::move(Conf), Backend,
                                 options::ParallelCodeGenParallelismLevel);
 }

>From a27dd9077b66828d683322893b79a66718eb91ed Mon Sep 17 00:00:00 2001
From: Min-Yih Hsu <min.hsu at sifive.com>
Date: Fri, 10 Nov 2023 11:07:43 -0800
Subject: [PATCH 3/3] fixup! Enable AsmVerbose once we're using assembly output

---
 llvm/test/tools/gold/X86/emit-asm.ll | 1 -
 llvm/tools/gold/gold-plugin.cpp      | 1 -
 2 files changed, 2 deletions(-)

diff --git a/llvm/test/tools/gold/X86/emit-asm.ll b/llvm/test/tools/gold/X86/emit-asm.ll
index 1c511dfa377c3eb..4e76f45dcf2d60b 100644
--- a/llvm/test/tools/gold/X86/emit-asm.ll
+++ b/llvm/test/tools/gold/X86/emit-asm.ll
@@ -26,4 +26,3 @@ define void @f2() {
 
 ; Check if comments are emitted into assembly.
 ; CHECK: -- End function
-
diff --git a/llvm/tools/gold/gold-plugin.cpp b/llvm/tools/gold/gold-plugin.cpp
index 2b935049320d346..257832ab7671c45 100644
--- a/llvm/tools/gold/gold-plugin.cpp
+++ b/llvm/tools/gold/gold-plugin.cpp
@@ -951,7 +951,6 @@ static std::unique_ptr<LTO> createLTO(IndexWriteCallback OnIndexWrite,
   Conf.HasWholeProgramVisibility = options::whole_program_visibility;
 
   Conf.StatsFile = options::stats_file;
-
   return std::make_unique<LTO>(std::move(Conf), Backend,
                                 options::ParallelCodeGenParallelismLevel);
 }



More information about the llvm-commits mailing list