@@ -24,7 +24,6 @@ namespace cir {
2424static BackendAction
2525getBackendActionFromOutputType (CIRGenAction::OutputType Action) {
2626 switch (Action) {
27- case CIRGenAction::OutputType::EmitCIR:
2827 case CIRGenAction::OutputType::EmitMLIR:
2928 assert (false &&
3029 " Unsupported output type for getBackendActionFromOutputType!" );
@@ -85,28 +84,28 @@ class CIRGenConsumer : public clang::ASTConsumer {
8584 Gen->HandleTranslationUnit (C);
8685 mlir::ModuleOp MlirModule = Gen->getModule ();
8786 mlir::MLIRContext &MlirCtx = Gen->getMLIRContext ();
87+
88+ auto emitMLIR = [&](mlir::Operation *MlirMod) {
89+ assert (MlirMod &&
90+ " MLIR module does not exist, but lowering did not fail?" );
91+ assert (OutputStream && " Missing output stream when emitting MLIR!" );
92+ // FIXME: we cannot roundtrip prettyForm=true right now.
93+ mlir::OpPrintingFlags Flags;
94+ Flags.enableDebugInfo (/* enable=*/ true , /* prettyForm=*/ false );
95+ MlirMod->print (*OutputStream, Flags);
96+ };
97+
8898 switch (Action) {
89- case CIRGenAction::OutputType::EmitCIR:
90- assert (CI.getFrontendOpts ().MLIRTargetDialect == frontend::MLIR_CIR);
9199 case CIRGenAction::OutputType::EmitMLIR: {
92100 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- }
101+ case frontend::MLIR_CORE:
102+ emitMLIR (lowerFromCIRToMLIR (MlirModule, MlirCtx));
99103 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.
105- mlir::OpPrintingFlags Flags;
106- Flags.enableDebugInfo (/* enable=*/ true , /* prettyForm=*/ false );
107- LoweredMlirModule->print (*OutputStream, Flags);
104+ case frontend::MLIR_CIR:
105+ emitMLIR (MlirModule);
108106 break ;
109107 }
108+ break ;
110109 }
111110 case CIRGenAction::OutputType::EmitLLVM:
112111 case CIRGenAction::OutputType::EmitBC:
@@ -140,8 +139,6 @@ getOutputStream(CompilerInstance &CI, StringRef InFile,
140139 switch (Action) {
141140 case CIRGenAction::OutputType::EmitAssembly:
142141 return CI.createDefaultOutputFile (false , InFile, " s" );
143- case CIRGenAction::OutputType::EmitCIR:
144- return CI.createDefaultOutputFile (false , InFile, " cir" );
145142 case CIRGenAction::OutputType::EmitMLIR:
146143 return CI.createDefaultOutputFile (false , InFile, " mlir" );
147144 case CIRGenAction::OutputType::EmitLLVM:
@@ -171,10 +168,6 @@ void EmitAssemblyAction::anchor() {}
171168EmitAssemblyAction::EmitAssemblyAction (mlir::MLIRContext *MLIRCtx)
172169 : CIRGenAction(OutputType::EmitAssembly, MLIRCtx) {}
173170
174- void EmitCIRAction::anchor () {}
175- EmitCIRAction::EmitCIRAction (mlir::MLIRContext *MLIRCtx)
176- : CIRGenAction(OutputType::EmitCIR, MLIRCtx) {}
177-
178171void EmitMLIRAction::anchor () {}
179172EmitMLIRAction::EmitMLIRAction (mlir::MLIRContext *MLIRCtx)
180173 : CIRGenAction(OutputType::EmitMLIR, MLIRCtx) {}
0 commit comments