[flang][tco] Add -emit-final-mlir flag (#146533)
Add a flag to tco for emitting the final MLIR, prior to lowering to LLVM IR. This is intended to produce output that can be passed directly to mlir-translate. --------- Signed-off-by: Kajetan Puchalski <kajetan.puchalski@arm.com>
This commit is contained in:
committed by
GitHub
parent
3cff3d882b
commit
69b69cbcb4
19
flang/test/Driver/tco-emit-final-mlir.fir
Normal file
19
flang/test/Driver/tco-emit-final-mlir.fir
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
// Test tco's -emit-final-mlir option.
|
||||||
|
|
||||||
|
// RUN: tco -emit-final-mlir %s 2>&1 | FileCheck %s
|
||||||
|
|
||||||
|
// Check that the FIR file is translated into the LLVM IR
|
||||||
|
// MLIR dialect, but not into LLVM IR itself.
|
||||||
|
|
||||||
|
// CHECK-NOT: func.func
|
||||||
|
// CHECK-LABEL: llvm.func @_QPfoo()
|
||||||
|
// CHECK-NOT: fir.alloca
|
||||||
|
// CHECK: %[[VAL_0:.*]] = llvm.mlir.constant(1 : i64) : i64
|
||||||
|
// CHECK: %[[VAL_1:.*]] = llvm.alloca %[[VAL_0]] x i32 : (i64) -> !llvm.ptr
|
||||||
|
// CHECK: llvm.return
|
||||||
|
// CHECK-NOT: func.func
|
||||||
|
|
||||||
|
func.func @_QPfoo() {
|
||||||
|
%1 = fir.alloca i32
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -70,6 +70,11 @@ static cl::opt<bool> codeGenLLVM(
|
|||||||
cl::desc("Run only CodeGen passes and translate FIR to LLVM IR"),
|
cl::desc("Run only CodeGen passes and translate FIR to LLVM IR"),
|
||||||
cl::init(false));
|
cl::init(false));
|
||||||
|
|
||||||
|
static cl::opt<bool> emitFinalMLIR(
|
||||||
|
"emit-final-mlir",
|
||||||
|
cl::desc("Only translate FIR to MLIR, do not lower to LLVM IR"),
|
||||||
|
cl::init(false));
|
||||||
|
|
||||||
#include "flang/Optimizer/Passes/CommandLineOpts.h"
|
#include "flang/Optimizer/Passes/CommandLineOpts.h"
|
||||||
#include "flang/Optimizer/Passes/Pipelines.h"
|
#include "flang/Optimizer/Passes/Pipelines.h"
|
||||||
|
|
||||||
@@ -149,13 +154,15 @@ compileFIR(const mlir::PassPipelineCLParser &passPipeline) {
|
|||||||
fir::registerDefaultInlinerPass(config);
|
fir::registerDefaultInlinerPass(config);
|
||||||
fir::createMLIRToLLVMPassPipeline(pm, config);
|
fir::createMLIRToLLVMPassPipeline(pm, config);
|
||||||
}
|
}
|
||||||
fir::addLLVMDialectToLLVMPass(pm, out.os());
|
if (!emitFinalMLIR)
|
||||||
|
fir::addLLVMDialectToLLVMPass(pm, out.os());
|
||||||
}
|
}
|
||||||
|
|
||||||
// run the pass manager
|
// run the pass manager
|
||||||
if (mlir::succeeded(pm.run(*owningRef))) {
|
if (mlir::succeeded(pm.run(*owningRef))) {
|
||||||
// passes ran successfully, so keep the output
|
// passes ran successfully, so keep the output
|
||||||
if ((emitFir || passPipeline.hasAnyOccurrences()) && !codeGenLLVM)
|
if ((emitFir || passPipeline.hasAnyOccurrences() || emitFinalMLIR) &&
|
||||||
|
!codeGenLLVM)
|
||||||
printModule(*owningRef, out.os());
|
printModule(*owningRef, out.os());
|
||||||
out.keep();
|
out.keep();
|
||||||
return mlir::success();
|
return mlir::success();
|
||||||
|
|||||||
Reference in New Issue
Block a user