|
13 | 13 | #include "clang/CIR/LowerToLLVM.h"
|
14 | 14 | #include "clang/CodeGen/BackendUtil.h"
|
15 | 15 | #include "clang/Frontend/CompilerInstance.h"
|
| 16 | +#include "clang/Frontend/FrontendOptions.h" |
16 | 17 | #include "llvm/IR/Module.h"
|
17 | 18 |
|
18 | 19 | using namespace cir;
|
@@ -86,21 +87,26 @@ class CIRGenConsumer : public clang::ASTConsumer {
|
86 | 87 | mlir::MLIRContext &MlirCtx = Gen->getMLIRContext();
|
87 | 88 | switch (Action) {
|
88 | 89 | case CIRGenAction::OutputType::EmitCIR:
|
89 |
| - if (OutputStream && MlirModule) { |
| 90 | + assert(CI.getFrontendOpts().MLIRTargetDialect == frontend::MLIR_CIR); |
| 91 | + case CIRGenAction::OutputType::EmitMLIR: { |
| 92 | + switch (CI.getFrontendOpts().MLIRTargetDialect) { |
| 93 | + case frontend::MLIR_CIR: |
| 94 | + if (OutputStream && MlirModule) { |
| 95 | + mlir::OpPrintingFlags Flags; |
| 96 | + Flags.enableDebugInfo(/*enable=*/true, /*prettyForm=*/false); |
| 97 | + MlirModule->print(*OutputStream, Flags); |
| 98 | + } |
| 99 | + break; |
| 100 | + case frontend::MLIR_Core: |
| 101 | + mlir::ModuleOp LoweredMlirModule = |
| 102 | + lowerFromCIRToMLIR(MlirModule, MlirCtx); |
| 103 | + assert(OutputStream && "No output stream when lowering to MLIR!"); |
| 104 | + // FIXME: we cannot roundtrip prettyForm=true right now. |
90 | 105 | mlir::OpPrintingFlags Flags;
|
91 | 106 | Flags.enableDebugInfo(/*enable=*/true, /*prettyForm=*/false);
|
92 |
| - MlirModule->print(*OutputStream, Flags); |
| 107 | + LoweredMlirModule->print(*OutputStream, Flags); |
| 108 | + break; |
93 | 109 | }
|
94 |
| - break; |
95 |
| - case CIRGenAction::OutputType::EmitMLIR: { |
96 |
| - mlir::ModuleOp LoweredMlirModule = |
97 |
| - lowerFromCIRToMLIR(MlirModule, MlirCtx); |
98 |
| - assert(OutputStream && "No output stream when lowering to MLIR!"); |
99 |
| - // FIXME: we cannot roundtrip prettyForm=true right now. |
100 |
| - mlir::OpPrintingFlags Flags; |
101 |
| - Flags.enableDebugInfo(/*enable=*/true, /*prettyForm=*/false); |
102 |
| - LoweredMlirModule->print(*OutputStream, Flags); |
103 |
| - break; |
104 | 110 | }
|
105 | 111 | case CIRGenAction::OutputType::EmitLLVM:
|
106 | 112 | case CIRGenAction::OutputType::EmitBC:
|
|
0 commit comments