26
26
#include " clang/CIR/CIRToCIRPasses.h"
27
27
#include " clang/CIR/Dialect/IR/CIRDialect.h"
28
28
#include " clang/CIR/LowerToLLVM.h"
29
+ #include " clang/CIR/LowerToMLIR.h"
29
30
#include " clang/CIR/Passes.h"
30
31
#include " clang/CodeGen/BackendUtil.h"
31
32
#include " clang/CodeGen/ModuleBuilder.h"
@@ -260,6 +261,14 @@ class CIRGenConsumer : public clang::ASTConsumer {
260
261
}
261
262
}
262
263
264
+ auto printMlirModule = [&](mlir::ModuleOp root) {
265
+ assert (outputStream && " Why are we here without an output stream?" );
266
+ // FIXME: we cannot roundtrip prettyForm=true right now.
267
+ mlir::OpPrintingFlags flags;
268
+ flags.enableDebugInfo (/* enable=*/ true , /* prettyForm=*/ false );
269
+ root->print (*outputStream, flags);
270
+ };
271
+
263
272
switch (action) {
264
273
case CIRGenAction::OutputType::EmitCIR:
265
274
case CIRGenAction::OutputType::EmitCIRFlat:
@@ -274,11 +283,17 @@ class CIRGenConsumer : public clang::ASTConsumer {
274
283
break ;
275
284
case CIRGenAction::OutputType::EmitMLIR: {
276
285
auto loweredMlirModule = lowerFromCIRToMLIR (mlirMod, mlirCtx.get ());
277
- assert (outputStream && " Why are we here without an output stream?" );
278
- // FIXME: we cannot roundtrip prettyForm=true right now.
279
- mlir::OpPrintingFlags flags;
280
- flags.enableDebugInfo (/* enable=*/ true , /* prettyForm=*/ false );
281
- loweredMlirModule->print (*outputStream, flags);
286
+ printMlirModule (loweredMlirModule);
287
+ break ;
288
+ }
289
+ case CIRGenAction::OutputType::EmitMLIRLLVM: {
290
+ bool disableDebugInfo =
291
+ codeGenOptions.getDebugInfo () == llvm::codegenoptions::NoDebugInfo;
292
+ auto loweredMlirModule =
293
+ feOptions.ClangIRDirectLowering
294
+ ? direct::lowerDirectlyFromCIRToLLVMDialect (mlirMod)
295
+ : lowerFromCIRToMLIRToLLVMDialect (mlirMod);
296
+ printMlirModule (loweredMlirModule);
282
297
break ;
283
298
}
284
299
case CIRGenAction::OutputType::EmitLLVM:
@@ -362,6 +377,8 @@ getOutputStream(CompilerInstance &ci, StringRef inFile,
362
377
return ci.createDefaultOutputFile (false , inFile, " cir" );
363
378
case CIRGenAction::OutputType::EmitMLIR:
364
379
return ci.createDefaultOutputFile (false , inFile, " mlir" );
380
+ case CIRGenAction::OutputType::EmitMLIRLLVM:
381
+ return ci.createDefaultOutputFile (false , inFile, " mlir" );
365
382
case CIRGenAction::OutputType::EmitLLVM:
366
383
return ci.createDefaultOutputFile (false , inFile, " ll" );
367
384
case CIRGenAction::OutputType::EmitBC:
@@ -472,6 +489,10 @@ void EmitMLIRAction::anchor() {}
472
489
EmitMLIRAction::EmitMLIRAction (mlir::MLIRContext *_MLIRContext)
473
490
: CIRGenAction(OutputType::EmitMLIR, _MLIRContext) {}
474
491
492
+ void EmitMLIRLLVMAction::anchor () {}
493
+ EmitMLIRLLVMAction::EmitMLIRLLVMAction (mlir::MLIRContext *_MLIRContext)
494
+ : CIRGenAction(OutputType::EmitMLIRLLVM, _MLIRContext) {}
495
+
475
496
void EmitLLVMAction::anchor () {}
476
497
EmitLLVMAction::EmitLLVMAction (mlir::MLIRContext *_MLIRContext)
477
498
: CIRGenAction(OutputType::EmitLLVM, _MLIRContext) {}
0 commit comments