-
Notifications
You must be signed in to change notification settings - Fork 128
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
[CIR] Add option to emit MLIR in LLVM dialect. #1316
base: main
Are you sure you want to change the base?
Conversation
6870e41
to
3af1d49
Compare
Instead of the current approach, I recommend using For the case where |
@@ -3121,6 +3121,8 @@ def emit_cir_flat : Flag<["-"], "emit-cir-flat">, Visibility<[ClangOption, CC1Op | |||
Group<Action_Group>, HelpText<"Similar to -emit-cir but also lowers structured CFG into basic blocks.">; | |||
def emit_mlir : Flag<["-"], "emit-mlir">, Visibility<[CC1Option]>, Group<Action_Group>, | |||
HelpText<"Build ASTs and then lower through ClangIR to MLIR, emit the .milr file">; | |||
def emit_mlir_llvm : Flag<["-"], "emit-mlir-llvm">, Visibility<[CC1Option]>, Group<Action_Group>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you add this flag, might be worth editing the one above to explain that that does to standard dialects instead.
I like @xlauko idea, couple things to add to the discussion:
|
5d29c0b
to
bc51bff
Compare
[CIR] Add option to emit MLIR in a selected dialect This PR adds `-emit-mlir=<std,llvm,cir>` option that emits MLIR in the specified dialect. The `-emit-mlir` option now emits the MLIR in the LLVM dialect when direct lowering to CIR is used (instead of producing an error).
bc51bff
to
d51b625
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for improving the PR, more comments inline. This still need tests (both driver test and a few simple IR output checks).
HelpText<"Build ASTs and then lower through ClangIR to the selected MLIR dialect, emit the .mlir file. " | ||
"Allowed values are `std` for MLIR standard dialects " | ||
"`llvm` for the LLVM dialect and `cir` for the ClangIR dialect.">, | ||
Values<"std,llvm,cir">, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's confusing to have CIR here, better remove it. Should be std or LLVM (we already have -emit-cir
and this PR is not unifying any of the existing handling either).
emitCIR(); | ||
break; | ||
} | ||
if (loweredMlirModule) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if this if is not taken?
flags.enableDebugInfo(/*enable=*/true, /*prettyForm=*/false); | ||
loweredMlirModule->print(*outputStream, flags); | ||
mlir::ModuleOp loweredMlirModule; | ||
switch (feOptions.MLIRTargetDialect) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After removing CIR support this can be simplified to not use a switch
To expand a bit on testing:
|
In the way I've done it |
I have updated the PR according to the comments. |
✅ With the latest revision this PR passed the C/C++ code formatter. |
b727be6
to
124bede
Compare
124bede
to
47de848
Compare
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-clangir-direct-lowering -emit-mlir=llvm %s -o - | FileCheck %s -check-prefix=LLVM | ||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-clangir-direct-lowering -emit-mlir=std %s -o - | FileCheck %s -check-prefix=STD | ||
|
||
// RUN: %clang -fclangir -Xclang -emit-mlir %s -o - -### 2>&1 | FileCheck %s -check-prefix=OPTS_NO_VALUE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates! Almost there, few more changes needed (sorry for not catching early):
- The version without the EQ should be driver only.
- cc1 only accepts the EQ version, requiring either llvm/std.
- We can ditch
MLIR_Default
by picking one of the EQ values at driver time.
def emit_mlir_EQ : Joined<["-"], "emit-mlir=">, Visibility<[CC1Option]>, Group<Action_Group>, | ||
HelpText<"Build ASTs and then lower through ClangIR to the selected MLIR dialect, emit the .mlir file. " | ||
"Allowed values are `std` for MLIR standard dialects and `llvm` for the LLVM dialect.">, | ||
Values<"std,llvm">, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can "cir" and "cir-flat" be added here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I asked to remove it but now in light of upstreaming discussion llvm/llvm-project#127835 (comment), we should probably converge to make upstreaming approach easier. @Jezurko sorry for the noise. We should add cir
and cir-flat
to match what is likely coming for Flang as part of that discussion. We should also rename std
to core
.
Andy, should we hold on this until you land to make your life easier or is it enough if @Jezurko applies the changes above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense to merge this first, then I can update my upstream patch to align with this and the wishes of the reviewers there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will update the list of values and update the action. No worries about the noise :)
@bcardosolopes what about the non-_EQ
situation? The current situation here in the incubator is that the -emit-mlir
alias to -emit-fir
is simply commented out and the CIR variant of -emit-mlir
is defined few lines later. Do we want to somehow resolve that in this PR (probably after discussion in the upstream PR)? Or just land the -emit-mlir=
option for now and resolve that separately?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have posted an update in llvm/llvm-project#127835 that uses the -emit-mlir=[cir|core]
option. I was referencing this PR when I implemented it, so it shouldn't be too far off. One difference is that I made the MLIR dialect a separate named enum.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added another small discussion point over there
This PR adds the flag
-emit-mlir-llvm
to allow emitting of MLIR in the LLVM dialect (cc @xlauko who asked me to do this).I'm not sure if the naming of the flag is the best and maybe someone will have a better idea.
Another solution would be to make the
-emit-mlir
flag have a value, that specifies the target dialect (CIR/MLIR std dialects/LLVM Dialect).