@@ -261,17 +261,7 @@ class CIRGenConsumer : public clang::ASTConsumer {
261
261
}
262
262
}
263
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
-
272
- switch (action) {
273
- case CIRGenAction::OutputType::EmitCIR:
274
- case CIRGenAction::OutputType::EmitCIRFlat:
264
+ auto emitCIR = [&]() {
275
265
if (outputStream && mlirMod) {
276
266
// FIXME: we cannot roundtrip prettyForm=true right now.
277
267
mlir::OpPrintingFlags flags;
@@ -280,18 +270,45 @@ class CIRGenConsumer : public clang::ASTConsumer {
280
270
flags.assumeVerified ();
281
271
mlirMod->print (*outputStream, flags);
282
272
}
273
+ };
274
+
275
+ switch (action) {
276
+ case CIRGenAction::OutputType::EmitCIR:
277
+ case CIRGenAction::OutputType::EmitCIRFlat:
278
+ emitCIR ();
283
279
break ;
284
280
case CIRGenAction::OutputType::EmitMLIR: {
285
- auto loweredMlirModule = lowerFromCIRToMLIR (mlirMod, mlirCtx.get ());
286
- printMlirModule (loweredMlirModule);
287
- break ;
288
- }
289
- case CIRGenAction::OutputType::EmitMLIRLLVM: {
290
- auto loweredMlirModule =
291
- feOptions.ClangIRDirectLowering
292
- ? direct::lowerDirectlyFromCIRToLLVMDialect (mlirMod)
293
- : lowerFromCIRToMLIRToLLVMDialect (mlirMod);
294
- printMlirModule (loweredMlirModule);
281
+ mlir::ModuleOp loweredMlirModule;
282
+ switch (feOptions.MLIRTargetDialect ) {
283
+ case clang::FrontendOptions::MLIR_Default:
284
+ loweredMlirModule =
285
+ feOptions.ClangIRDirectLowering
286
+ ? direct::lowerDirectlyFromCIRToLLVMDialect (mlirMod)
287
+ : lowerFromCIRToMLIR (mlirMod, mlirCtx.get ());
288
+
289
+ break ;
290
+ case clang::FrontendOptions::MLIR_STD:
291
+ // Attempting to emit std with direct lowering is already checked by
292
+ // Compiler Invocation
293
+ loweredMlirModule = lowerFromCIRToMLIR (mlirMod, mlirCtx.get ());
294
+ break ;
295
+ case clang::FrontendOptions::MLIR_LLVM:
296
+ loweredMlirModule =
297
+ feOptions.ClangIRDirectLowering
298
+ ? direct::lowerDirectlyFromCIRToLLVMDialect (mlirMod)
299
+ : lowerFromCIRToMLIRToLLVMDialect (mlirMod, mlirCtx.get ());
300
+ break ;
301
+ case clang::FrontendOptions::MLIR_CIR:
302
+ emitCIR ();
303
+ break ;
304
+ }
305
+ if (loweredMlirModule) {
306
+ assert (outputStream && " Why are we here without an output stream?" );
307
+ // FIXME: we cannot roundtrip prettyForm=true right now.
308
+ mlir::OpPrintingFlags flags;
309
+ flags.enableDebugInfo (/* enable=*/ true , /* prettyForm=*/ false );
310
+ loweredMlirModule->print (*outputStream, flags);
311
+ }
295
312
break ;
296
313
}
297
314
case CIRGenAction::OutputType::EmitLLVM:
@@ -375,8 +392,6 @@ getOutputStream(CompilerInstance &ci, StringRef inFile,
375
392
return ci.createDefaultOutputFile (false , inFile, " cir" );
376
393
case CIRGenAction::OutputType::EmitMLIR:
377
394
return ci.createDefaultOutputFile (false , inFile, " mlir" );
378
- case CIRGenAction::OutputType::EmitMLIRLLVM:
379
- return ci.createDefaultOutputFile (false , inFile, " mlir" );
380
395
case CIRGenAction::OutputType::EmitLLVM:
381
396
return ci.createDefaultOutputFile (false , inFile, " ll" );
382
397
case CIRGenAction::OutputType::EmitBC:
@@ -487,10 +502,6 @@ void EmitMLIRAction::anchor() {}
487
502
EmitMLIRAction::EmitMLIRAction (mlir::MLIRContext *_MLIRContext)
488
503
: CIRGenAction(OutputType::EmitMLIR, _MLIRContext) {}
489
504
490
- void EmitMLIRLLVMAction::anchor () {}
491
- EmitMLIRLLVMAction::EmitMLIRLLVMAction (mlir::MLIRContext *_MLIRContext)
492
- : CIRGenAction(OutputType::EmitMLIRLLVM, _MLIRContext) {}
493
-
494
505
void EmitLLVMAction::anchor () {}
495
506
EmitLLVMAction::EmitLLVMAction (mlir::MLIRContext *_MLIRContext)
496
507
: CIRGenAction(OutputType::EmitLLVM, _MLIRContext) {}
0 commit comments