Skip to content

[gold] Enable MCTargetOptions::AsmVerbose along with emit-asm #71606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 10, 2023

Conversation

mshockwave
Copy link
Member

@mshockwave mshockwave commented Nov 7, 2023

Print comments into assembly output if we're using emit-asm.

@mshockwave mshockwave requested a review from MaskRay November 7, 2023 23:52
@llvmbot llvmbot added the LTO Link time optimization (regular/full LTO or ThinLTO) label Nov 7, 2023
@llvmbot
Copy link
Member

llvmbot commented Nov 7, 2023

@llvm/pr-subscribers-lto

Author: Min-Yih Hsu (mshockwave)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/71606.diff

2 Files Affected:

  • (added) llvm/test/tools/gold/X86/asm-verbose.ll (+15)
  • (modified) llvm/tools/gold/gold-plugin.cpp (+6)
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);
 }

Copy link
Contributor

@teresajohnson teresajohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that lld enables this unconditionally:

c.Options.MCOptions.AsmVerbose = true;

How about just make it unconditionally true to be consistent and avoid adding another plugin option?

@teresajohnson
Copy link
Contributor

I see that lld enables this unconditionally:

c.Options.MCOptions.AsmVerbose = true;

How about just make it unconditionally true to be consistent and avoid adding another plugin option?

In which case you can just modify https://github.com/llvm/llvm-project/blob/26ab444e88fc8fdd554e5a9381a68b7b5e63b6fd/llvm/test/tools/gold/X86/emit-asm.ll slightly to check that the comments are emitted.

@mshockwave
Copy link
Member Author

I see that lld enables this unconditionally:

c.Options.MCOptions.AsmVerbose = true;

How about just make it unconditionally true to be consistent and avoid adding another plugin option?

In which case you can just modify https://github.com/llvm/llvm-project/blob/26ab444e88fc8fdd554e5a9381a68b7b5e63b6fd/llvm/test/tools/gold/X86/emit-asm.ll slightly to check that the comments are emitted.

Yes I think this is a good idea. I've updated the PR.

@mshockwave mshockwave changed the title [gold] Add a new -plugin-opt to enable MCTargetOptions::AsmVerbose [gold] Enable MCTargetOptions::AsmVerbose along with emit-asm Nov 10, 2023
@mshockwave mshockwave merged commit 9e13d64 into llvm:main Nov 10, 2023
@mshockwave mshockwave deleted the patch/lto-backend-asm-verbose branch November 10, 2023 20:11
zahiraam pushed a commit to zahiraam/llvm-project that referenced this pull request Nov 20, 2023
…vm#71606)

Print comments into assembly output if we're using `emit-asm`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LTO Link time optimization (regular/full LTO or ThinLTO)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants