-
Notifications
You must be signed in to change notification settings - Fork 156
[CIR] Add option to emit MLIR in LLVM dialect. #1316
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
Changes from 2 commits
3af1d49
d51b625
47de848
e3d820f
aec099c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3120,7 +3120,16 @@ def emit_cir_only : Flag<["-"], "emit-cir-only">, | |
def emit_cir_flat : Flag<["-"], "emit-cir-flat">, Visibility<[ClangOption, CC1Option]>, | ||
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">; | ||
HelpText<"Build ASTs and then lower through ClangIR to MLIR (standard dialects " | ||
"or the LLVM dialect), emit the .mlir file.">; | ||
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 " | ||
"`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 commentThe 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 |
||
NormalizedValuesScope<"FrontendOptions">, | ||
NormalizedValues<["MLIR_STD", "MLIR_LLVM", "MLIR_CIR"]>, | ||
MarshallingInfoEnum<FrontendOpts<"MLIRTargetDialect">, "MLIR_Default">; | ||
/// ClangIR-specific options - END | ||
|
||
def flto : Flag<["-"], "flto">, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
#include "clang/CIR/CIRToCIRPasses.h" | ||
#include "clang/CIR/Dialect/IR/CIRDialect.h" | ||
#include "clang/CIR/LowerToLLVM.h" | ||
#include "clang/CIR/LowerToMLIR.h" | ||
#include "clang/CIR/Passes.h" | ||
#include "clang/CodeGen/BackendUtil.h" | ||
#include "clang/CodeGen/ModuleBuilder.h" | ||
|
@@ -260,9 +261,7 @@ class CIRGenConsumer : public clang::ASTConsumer { | |
} | ||
} | ||
|
||
switch (action) { | ||
case CIRGenAction::OutputType::EmitCIR: | ||
case CIRGenAction::OutputType::EmitCIRFlat: | ||
auto emitCIR = [&]() { | ||
if (outputStream && mlirMod) { | ||
// FIXME: we cannot roundtrip prettyForm=true right now. | ||
mlir::OpPrintingFlags flags; | ||
|
@@ -271,14 +270,45 @@ class CIRGenConsumer : public clang::ASTConsumer { | |
flags.assumeVerified(); | ||
mlirMod->print(*outputStream, flags); | ||
} | ||
}; | ||
|
||
switch (action) { | ||
case CIRGenAction::OutputType::EmitCIR: | ||
case CIRGenAction::OutputType::EmitCIRFlat: | ||
emitCIR(); | ||
break; | ||
case CIRGenAction::OutputType::EmitMLIR: { | ||
auto loweredMlirModule = lowerFromCIRToMLIR(mlirMod, mlirCtx.get()); | ||
assert(outputStream && "Why are we here without an output stream?"); | ||
// FIXME: we cannot roundtrip prettyForm=true right now. | ||
mlir::OpPrintingFlags flags; | ||
flags.enableDebugInfo(/*enable=*/true, /*prettyForm=*/false); | ||
loweredMlirModule->print(*outputStream, flags); | ||
mlir::ModuleOp loweredMlirModule; | ||
switch (feOptions.MLIRTargetDialect) { | ||
bcardosolopes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
case clang::FrontendOptions::MLIR_Default: | ||
loweredMlirModule = | ||
feOptions.ClangIRDirectLowering | ||
? direct::lowerDirectlyFromCIRToLLVMDialect(mlirMod) | ||
: lowerFromCIRToMLIR(mlirMod, mlirCtx.get()); | ||
|
||
break; | ||
case clang::FrontendOptions::MLIR_STD: | ||
// Attempting to emit std with direct lowering is already checked by | ||
// Compiler Invocation | ||
loweredMlirModule = lowerFromCIRToMLIR(mlirMod, mlirCtx.get()); | ||
break; | ||
case clang::FrontendOptions::MLIR_LLVM: | ||
loweredMlirModule = | ||
feOptions.ClangIRDirectLowering | ||
? direct::lowerDirectlyFromCIRToLLVMDialect(mlirMod) | ||
: lowerFromCIRToMLIRToLLVMDialect(mlirMod, mlirCtx.get()); | ||
break; | ||
case clang::FrontendOptions::MLIR_CIR: | ||
emitCIR(); | ||
break; | ||
} | ||
if (loweredMlirModule) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if this if is not taken? |
||
assert(outputStream && "Why are we here without an output stream?"); | ||
// FIXME: we cannot roundtrip prettyForm=true right now. | ||
mlir::OpPrintingFlags flags; | ||
flags.enableDebugInfo(/*enable=*/true, /*prettyForm=*/false); | ||
loweredMlirModule->print(*outputStream, flags); | ||
} | ||
break; | ||
} | ||
case CIRGenAction::OutputType::EmitLLVM: | ||
|
Uh oh!
There was an error while loading. Please reload this page.