File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change 1+ // Test tco's -emit-final-mlir option.
2+
3+ // RUN: tco -emit-final-mlir %s 2>&1 | FileCheck %s
4+
5+ // Check that the FIR file is translated into the LLVM IR
6+ // MLIR dialect, but not into LLVM IR itself.
7+
8+ // CHECK-NOT: func.func
9+ // CHECK-LABEL: llvm.func @_QPfoo()
10+ // CHECK-NOT: fir.alloca
11+ // CHECK: %[[VAL_0:.*]] = llvm.mlir.constant(1 : i64) : i64
12+ // CHECK: %[[VAL_1:.*]] = llvm.alloca %[[VAL_0]] x i32 : (i64) -> !llvm.ptr
13+ // CHECK: llvm.return
14+ // CHECK-NOT: func.func
15+
16+ func.func @_QPfoo() {
17+ %1 = fir.alloca i32
18+ return
19+ }
Original file line number Diff line number Diff line change @@ -70,6 +70,11 @@ static cl::opt<bool> codeGenLLVM(
7070 cl::desc (" Run only CodeGen passes and translate FIR to LLVM IR" ),
7171 cl::init(false ));
7272
73+ static cl::opt<bool > emitFinalMLIR (
74+ " emit-final-mlir" ,
75+ cl::desc (" Only translate FIR to MLIR, do not lower to LLVM IR" ),
76+ cl::init(false ));
77+
7378#include " flang/Optimizer/Passes/CommandLineOpts.h"
7479#include " flang/Optimizer/Passes/Pipelines.h"
7580
@@ -149,13 +154,15 @@ compileFIR(const mlir::PassPipelineCLParser &passPipeline) {
149154 fir::registerDefaultInlinerPass (config);
150155 fir::createMLIRToLLVMPassPipeline (pm, config);
151156 }
152- fir::addLLVMDialectToLLVMPass (pm, out.os ());
157+ if (!emitFinalMLIR)
158+ fir::addLLVMDialectToLLVMPass (pm, out.os ());
153159 }
154160
155161 // run the pass manager
156162 if (mlir::succeeded (pm.run (*owningRef))) {
157163 // passes ran successfully, so keep the output
158- if ((emitFir || passPipeline.hasAnyOccurrences ()) && !codeGenLLVM)
164+ if ((emitFir || passPipeline.hasAnyOccurrences () || emitFinalMLIR) &&
165+ !codeGenLLVM)
159166 printModule (*owningRef, out.os ());
160167 out.keep ();
161168 return mlir::success ();
You can’t perform that action at this time.
0 commit comments