@@ -24,7 +24,6 @@ namespace cir {
24
24
static BackendAction
25
25
getBackendActionFromOutputType (CIRGenAction::OutputType Action) {
26
26
switch (Action) {
27
- case CIRGenAction::OutputType::EmitCIR:
28
27
case CIRGenAction::OutputType::EmitMLIR:
29
28
assert (false &&
30
29
" Unsupported output type for getBackendActionFromOutputType!" );
@@ -85,28 +84,28 @@ class CIRGenConsumer : public clang::ASTConsumer {
85
84
Gen->HandleTranslationUnit (C);
86
85
mlir::ModuleOp MlirModule = Gen->getModule ();
87
86
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
+
88
98
switch (Action) {
89
- case CIRGenAction::OutputType::EmitCIR:
90
- assert (CI.getFrontendOpts ().MLIRTargetDialect == frontend::MLIR_CIR);
91
99
case CIRGenAction::OutputType::EmitMLIR: {
92
100
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));
99
103
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);
108
106
break ;
109
107
}
108
+ break ;
110
109
}
111
110
case CIRGenAction::OutputType::EmitLLVM:
112
111
case CIRGenAction::OutputType::EmitBC:
@@ -140,8 +139,6 @@ getOutputStream(CompilerInstance &CI, StringRef InFile,
140
139
switch (Action) {
141
140
case CIRGenAction::OutputType::EmitAssembly:
142
141
return CI.createDefaultOutputFile (false , InFile, " s" );
143
- case CIRGenAction::OutputType::EmitCIR:
144
- return CI.createDefaultOutputFile (false , InFile, " cir" );
145
142
case CIRGenAction::OutputType::EmitMLIR:
146
143
return CI.createDefaultOutputFile (false , InFile, " mlir" );
147
144
case CIRGenAction::OutputType::EmitLLVM:
@@ -171,10 +168,6 @@ void EmitAssemblyAction::anchor() {}
171
168
EmitAssemblyAction::EmitAssemblyAction (mlir::MLIRContext *MLIRCtx)
172
169
: CIRGenAction(OutputType::EmitAssembly, MLIRCtx) {}
173
170
174
- void EmitCIRAction::anchor () {}
175
- EmitCIRAction::EmitCIRAction (mlir::MLIRContext *MLIRCtx)
176
- : CIRGenAction(OutputType::EmitCIR, MLIRCtx) {}
177
-
178
171
void EmitMLIRAction::anchor () {}
179
172
EmitMLIRAction::EmitMLIRAction (mlir::MLIRContext *MLIRCtx)
180
173
: CIRGenAction(OutputType::EmitMLIR, MLIRCtx) {}
0 commit comments