Skip to content

[llc] Add -M for InstPrinter options #121078

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 2 commits into from
Apr 9, 2025

Conversation

MaskRay
Copy link
Member

@MaskRay MaskRay commented Dec 25, 2024

For many targets, llvm-objdump and llvm-mc
(https://reviews.llvm.org/D103004) support -M no-aliases (e.g.
RISCVInstPrinter::applyTargetSpecificCLOption).

This patch implements -M for llc.

While here, rename "DisassemblerOptions" in llvm-mc to the more
appropriate "InstPrinterOptions". For llvm-mc --assemble, there is no
disassembler involved.

Created using spr 1.3.5-bogner
Copy link
Contributor

@s-barannikov s-barannikov left a comment

Choose a reason for hiding this comment

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

The way it is currently implemented it only works when invoking llc directly.
It would be great if the option could be set by the compiler driver, which passes options in memory.
See

MCOptions.AsmVerbose = true;
for a few examples.

Some targets prefer to not print aliases by default; there should be a way of enabling this behavior.

@MaskRay
Copy link
Member Author

MaskRay commented Dec 25, 2024

The way it is currently implemented it only works when invoking llc directly. It would be great if the option could be set by the compiler driver, which passes options in memory. See

MCOptions.AsmVerbose = true;

for a few examples.
Some targets prefer to not print aliases by default; there should be a way of enabling this behavior.

Thanks for the quick response. This patch intends to port applyTargetSpecificCLOption to llc to be on par with llvm-mc and llvm-objdump.

You are right that Clang cc1as sets MCTargetOptions in a different place. If we want to add a clang -cc1 and -cc1as option, the clang file needs to be modified. That isn't my motivation, though. (Skimming through GCC's manpage I don't find a similar option. If we add an option, we have some freedom on the naming.)

@s-barannikov
Copy link
Contributor

I'm not against the current approach, it is just I'm not sure that this option would be as useful for llc without allowing it to be forwarded from the driver. llc is more a developer tool than an end-user tool. I doubt developers will want to pass this option to llc (what for?).

@MaskRay
Copy link
Member Author

MaskRay commented Dec 26, 2024

I'm not against the current approach, it is just I'm not sure that this option would be as useful for llc without allowing it to be forwarded from the driver. llc is more a developer tool than an end-user tool. I doubt developers will want to pass this option to llc (what for?).

For some reasons some RISC-V tests use a cl::opt option riscv-no-aliases. With this llc option, riscv-no-aliases/csky-no-aliases can be replaced with -M no-aliases, aligning with llvm-objdump. The usefulness is indeed low, just to unify similar features and avoid cl::opt.

Created using spr 1.3.5-bogner
@MaskRay
Copy link
Member Author

MaskRay commented Apr 8, 2025

Just realized that I haven't made the simplifications you requested :) Done. I think this is still useful, even just to remove riscv-no-aliases/csky-no-aliases and unify llc/llvm-mc/llvm-objdump

Copy link
Collaborator

@topperc topperc left a comment

Choose a reason for hiding this comment

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

LGTM

@MaskRay MaskRay merged commit 02b377d into main Apr 9, 2025
12 checks passed
@MaskRay MaskRay deleted the users/MaskRay/spr/llc-add-m-for-instprinter-options-1 branch April 9, 2025 02:34
MaskRay added a commit that referenced this pull request Apr 9, 2025
now that llc supports `-M no-aliases` (along with llvm-mc and llvm-objdump)
(#121078).

Pull Request: #134879
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Apr 9, 2025
For many targets, llvm-objdump and llvm-mc
(https://reviews.llvm.org/D103004) support -M no-aliases (e.g.
`RISCVInstPrinter::applyTargetSpecificCLOption`).

This patch implements -M for llc.

While here, rename "DisassemblerOptions" in llvm-mc to the more
appropriate "InstPrinterOptions". For llvm-mc --assemble, there is no
disassembler involved.

Pull Request: llvm/llvm-project#121078
@thurstond
Copy link
Contributor

Greetings from the borg! The HWASan buildbot is failing on the newly added llvm/test/tools/llc/instprinter-options.ll: https://lab.llvm.org/buildbot/#/builders/55/builds/9607

******************** TEST 'LLVM :: tools/llc/instprinter-options.ll' FAILED ********************
Exit Code: 1
Command Output (stderr):
--
not /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/llc -mtriple=x86_64 < /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/test/tools/llc/instprinter-options.ll -M invalid 2>&1 | /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/FileCheck /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/test/tools/llc/instprinter-options.ll --implicit-check-not=error: # RUN: at line 2
+ not /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/llc -mtriple=x86_64 -M invalid
+ /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/FileCheck /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/test/tools/llc/instprinter-options.ll --implicit-check-not=error:
command line:1:22: error: IMPLICIT-CHECK-NOT: excluded string found in input
-implicit-check-not='error:'
                     ^
<stdin>:3:1: note: found here
error: Aborted
^~~~~~
Input file: <stdin>
Check file: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/test/tools/llc/instprinter-options.ll
-dump-input=help explains the following input dump.
Input was:
<<<<<<
          1: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/llc: error: invalid InstPrinter option 'invalid' 
          2: libc++abi: Pure virtual function called! 
          3: error: Aborted 
not:imp1     !~~~~~          error: no match expected
>>>>>>

MaskRay added a commit that referenced this pull request Apr 11, 2025
... to clarify ownership, aligning with other parameters. Using
`std::unique_ptr` encourages users to manage `createMCInstPrinter` with
a unique_ptr instead of a raw pointer, reducing the risk of memory
leaks.

* llvm-mc: fix a leak and update llvm/test/tools/llvm-mc/disassembler-options.test
* #121078 copied the llvm-mc code to CodeGenTargetMachineImpl and made
  the same mistake. Fixed by 2b8cc65

Using unique_ptr requires #include MCInstPrinter.h in a few translation
units.

* Delete a createAsmStreamer overload I deprecated in 2024
* SystemZMCTargetDesc.cpp: rename to `createSystemZAsmStreamer` to fix
  an overload conflict.

Pull Request: #135128
var-const pushed a commit to ldionne/llvm-project that referenced this pull request Apr 17, 2025
For many targets, llvm-objdump and llvm-mc
(https://reviews.llvm.org/D103004) support -M no-aliases (e.g.
`RISCVInstPrinter::applyTargetSpecificCLOption`).

This patch implements -M for llc.

While here, rename "DisassemblerOptions" in llvm-mc to the more
appropriate "InstPrinterOptions". For llvm-mc --assemble, there is no
disassembler involved.

Pull Request: llvm#121078
var-const pushed a commit to ldionne/llvm-project that referenced this pull request Apr 17, 2025
now that llc supports `-M no-aliases` (along with llvm-mc and llvm-objdump)
(llvm#121078).

Pull Request: llvm#134879
var-const pushed a commit to ldionne/llvm-project that referenced this pull request Apr 17, 2025
... to clarify ownership, aligning with other parameters. Using
`std::unique_ptr` encourages users to manage `createMCInstPrinter` with
a unique_ptr instead of a raw pointer, reducing the risk of memory
leaks.

* llvm-mc: fix a leak and update llvm/test/tools/llvm-mc/disassembler-options.test
* llvm#121078 copied the llvm-mc code to CodeGenTargetMachineImpl and made
  the same mistake. Fixed by 2b8cc65

Using unique_ptr requires #include MCInstPrinter.h in a few translation
units.

* Delete a createAsmStreamer overload I deprecated in 2024
* SystemZMCTargetDesc.cpp: rename to `createSystemZAsmStreamer` to fix
  an overload conflict.

Pull Request: llvm#135128
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants