Skip to content
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

How to pass clang options to be applied to generated object file? #2950

Closed
jinchenglee opened this issue Sep 23, 2024 · 10 comments
Closed

How to pass clang options to be applied to generated object file? #2950

jinchenglee opened this issue Sep 23, 2024 · 10 comments

Comments

@jinchenglee
Copy link

jinchenglee commented Sep 23, 2024

For example, I can compile my binary using clang -target riscv64-unknown-elf -fno-builtin-printf -fno-lto -O2 -c example.c -o example.o, how may I pass down the additional options through onnx-mlir? This might be a dumb question as I'm new to LLVM toolsets.

I tried $ onnx-mlir -mtriple=riscv64-unknown-elf -mllvm="-fno-builtin-printf -fno-lto -O2" --EmitObj ./nn.onnx:

[1/6] Mon Sep 23 15:21:19 2024 (0s) Importing ONNX Model to MLIR Module from "nn.onnx"
[2/6] Mon Sep 23 15:21:19 2024 (0s) Compiling and Optimizing MLIR Module
[3/6] Mon Sep 23 15:21:19 2024 (0s) Translating MLIR Module to LLVM and Generating LLVM Optimized Bitcode
opt: Unknown command line argument '-fno-builtin-printf -fno-lto -O2'.  Try: 'opt --help'
opt: Did you mean '--rotation-prepare-for-lto'?
opt -O0 --mtriple=riscv64-unknown-elf --code-model small -fno-builtin-printf -fno-lto -O2 -o ./nn.bc ./nn.unoptimized.bc
Error message:
Program path: ~/git_repo/llvm-project/build/bin/opt
Command execution failed.
@jinchenglee
Copy link
Author

Seems only a single option is allowed/supported.

$~/experimental/onnx-mlir-example$ onnx-mlir -mtriple=riscv64-unknown-elf -mllvm="--disable-simplify-libcalls -O2" --EmitObj ./nn.onnx
[1/6] Mon Sep 23 15:35:49 2024 (0s) Importing ONNX Model to MLIR Module from "nn.onnx"
[2/6] Mon Sep 23 15:35:49 2024 (0s) Compiling and Optimizing MLIR Module
[3/6] Mon Sep 23 15:35:49 2024 (0s) Translating MLIR Module to LLVM and Generating LLVM Optimized Bitcode
opt: Unknown command line argument '--disable-simplify-libcalls -O2'.  Try: 'opt --help'
opt: Did you mean '--disable-simplify-libcalls'?
opt -O0 --mtriple=riscv64-unknown-elf --code-model small --disable-simplify-libcalls -O2 -o ./nn.bc ./nn.unoptimized.bc
Error message:
Program path: ~/git_repo/llvm-project/build/bin/opt
Command execution failed.
$:~/experimental/onnx-mlir-example$ onnx-mlir -mtriple=riscv64-unknown-elf -mllvm="--disable-simplify-libcalls" --EmitObj ./nn.onnx
[1/6] Mon Sep 23 15:36:40 2024 (0s) Importing ONNX Model to MLIR Module from "nn.onnx"
[2/6] Mon Sep 23 15:36:40 2024 (0s) Compiling and Optimizing MLIR Module
[3/6] Mon Sep 23 15:36:40 2024 (0s) Translating MLIR Module to LLVM and Generating LLVM Optimized Bitcode
[4/6] Mon Sep 23 15:36:40 2024 (0s) Generating Object from LLVM Bitcode
[5/6] Mon Sep 23 15:36:40 2024 (0s) Compilation completed

@AlexandreEichenberger
Copy link
Collaborator

AlexandreEichenberger commented Sep 24, 2024

I have seen the system being fragile with multiple options in a string, not entirely sure why.
One workaround is to add support for multiple instances of -mllvm=<single option>.

Do you want me to add this feature?

@jinchenglee
Copy link
Author

I have seen the system being fragile with multiple options in a string, not entirely sure why. One workaround is to add support for multiple instances of -mllvm=<single option>.

Do you want me to add this feature?

That would be nice. Thanks.

@chentong319
Copy link
Collaborator

The reason is that strings have to be passed separately in the argv[][] for the command. There is another small issue for the example here: -O0 is created by default. If -O2 is passed the mllvm, I got error for "multiple -O#".
I am going create a PR to fix this issue of multiple options in mllvm.

@AlexandreEichenberger
Copy link
Collaborator

Thanks @chentong319

@chentong319
Copy link
Collaborator

@jinchenglee Which step do you intend to use these options, opt or llc? The current implementation has another issue is that the -mllvm is used in both opt and llc. But they may support different options. I need to introduce new options for onnx-mlir.

@jinchenglee
Copy link
Author

I'm just exploring and besides I'm pretty greenhorn about LLVM toolsets. It seems to me it would be better to separate them as the tools (llc and opt) are different from beginning?

@chentong319
Copy link
Collaborator

@jinchenglee There are three options in onnx-mlir to pass options to opt and/or llc

  1. mllvm: only one is used. passed to both opt and llc
  2. Xopt: multiple is allowed. passed to only opt
  3. Xllc: multiple is allowed. passed to only llc

I merged a new PR to handle the issue with mllvm. I added example of how to use Xopt and Xllc. Hope this PR2955 solved your issue.

@AlexandreEichenberger
Copy link
Collaborator

@jinchenglee can we close this issue?

@jinchenglee
Copy link
Author

@jinchenglee can we close this issue?

Sorry, I don't yet have time to try these yet. But for what this ticket is asking for, it's safe to close. If any issues, I or anyone can reopen it. Thanks.

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

No branches or pull requests

3 participants