Skip to content
This repository was archived by the owner on Apr 23, 2021. It is now read-only.

Commit 1e94b99

Browse files
joker-ephtensorflower-gardener
authored andcommitted
Add missing lowering to CFG in mlir-cpu-runner + related cleanup
- the list of passes run by mlir-cpu-runner included -lower-affine and -lower-to-llvm but was missing -lower-to-cfg (because -lower-affine at some point used to lower straight to CFG); add -lower-to-cfg in between. IR with affine ops can now be run by mlir-cpu-runner. - update -lower-to-cfg to be consistent with other passes (create*Pass methods were changed to return unique ptrs, but -lower-to-cfg appears to have been missed). - mlir-cpu-runner was unable to parse custom form of affine op's - fix link options - drop unnecessary run options from test/mlir-cpu-runner/simple.mlir (none of the test cases had loops) - -convert-to-llvmir was changed to -lower-to-llvm at some point, but the create pass method name wasn't updated (this pass converts/lowers to LLVM dialect as opposed to LLVM IR). Fix this. (If we prefer "convert", the cmd-line options could be changed to "-convert-to-llvm/cfg" then.) Signed-off-by: Uday Bondhugula <[email protected]> Closes #115 PiperOrigin-RevId: 266666909
1 parent 5c0a0a5 commit 1e94b99

File tree

8 files changed

+27
-15
lines changed

8 files changed

+27
-15
lines changed

bindings/python/pybind.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ struct PythonMLIRModule {
197197
manager.addPass(mlir::createCanonicalizerPass());
198198
manager.addPass(mlir::createCSEPass());
199199
manager.addPass(mlir::createLowerAffinePass());
200-
manager.addPass(mlir::createConvertToLLVMIRPass());
200+
manager.addPass(mlir::createLowerToLLVMPass());
201201
if (failed(manager.run(*module))) {
202202
llvm::errs() << "conversion to the LLVM IR dialect failed\n";
203203
return;

include/mlir/Conversion/ControlFlowToCFG/ConvertControlFlowToCFG.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void populateLoopToStdConversionPatterns(OwningRewritePatternList &patterns,
3939
MLIRContext *ctx);
4040

4141
/// Creates a pass to convert loop.for, loop.if and loop.terminator ops to CFG.
42-
FunctionPassBase *createConvertToCFGPass();
42+
std::unique_ptr<FunctionPassBase> createLowerToCFGPass();
4343

4444
} // namespace mlir
4545

include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVMPass.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,23 @@ void populateStdToLLVMConversionPatterns(LLVMTypeConverter &converter,
5858
OwningRewritePatternList &patterns);
5959

6060
/// Creates a pass to convert the Standard dialect into the LLVMIR dialect.
61-
std::unique_ptr<ModulePassBase> createConvertToLLVMIRPass();
61+
std::unique_ptr<ModulePassBase> createLowerToLLVMPass();
6262

6363
/// Creates a pass to convert operations to the LLVMIR dialect. The conversion
6464
/// is defined by a list of patterns and a type converter that will be obtained
6565
/// during the pass using the provided callbacks.
6666
std::unique_ptr<ModulePassBase>
67-
createConvertToLLVMIRPass(LLVMPatternListFiller patternListFiller,
68-
LLVMTypeConverterMaker typeConverterMaker);
67+
createLowerToLLVMPass(LLVMPatternListFiller patternListFiller,
68+
LLVMTypeConverterMaker typeConverterMaker);
6969

7070
/// Creates a pass to convert operations to the LLVMIR dialect. The conversion
7171
/// is defined by a list of patterns obtained during the pass using the provided
7272
/// callback and an optional type conversion class, an instance is created
7373
/// during the pass.
7474
template <typename TypeConverter = LLVMTypeConverter>
7575
std::unique_ptr<ModulePassBase>
76-
createConvertToLLVMIRPass(LLVMPatternListFiller patternListFiller) {
77-
return createConvertToLLVMIRPass(patternListFiller, [](MLIRContext *context) {
76+
createLowerToLLVMPass(LLVMPatternListFiller patternListFiller) {
77+
return createLowerToLLVMPass(patternListFiller, [](MLIRContext *context) {
7878
return std::make_unique<TypeConverter>(context);
7979
});
8080
}

lib/Conversion/ControlFlowToCFG/ConvertControlFlowToCFG.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ void ControlFlowToCFGPass::runOnFunction() {
270270
signalPassFailure();
271271
}
272272

273-
FunctionPassBase *mlir::createConvertToCFGPass() {
274-
return new ControlFlowToCFGPass();
273+
std::unique_ptr<FunctionPassBase> mlir::createLowerToCFGPass() {
274+
return std::make_unique<ControlFlowToCFGPass>();
275275
}
276276

277277
static PassRegistration<ControlFlowToCFGPass>

lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,13 +1226,13 @@ struct LLVMLoweringPass : public ModulePass<LLVMLoweringPass> {
12261226
};
12271227
} // end namespace
12281228

1229-
std::unique_ptr<ModulePassBase> mlir::createConvertToLLVMIRPass() {
1229+
std::unique_ptr<ModulePassBase> mlir::createLowerToLLVMPass() {
12301230
return std::make_unique<LLVMLoweringPass>();
12311231
}
12321232

12331233
std::unique_ptr<ModulePassBase>
1234-
mlir::createConvertToLLVMIRPass(LLVMPatternListFiller patternListFiller,
1235-
LLVMTypeConverterMaker typeConverterMaker) {
1234+
mlir::createLowerToLLVMPass(LLVMPatternListFiller patternListFiller,
1235+
LLVMTypeConverterMaker typeConverterMaker) {
12361236
return std::make_unique<LLVMLoweringPass>(patternListFiller,
12371237
typeConverterMaker);
12381238
}

lib/Support/JitRunner.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "mlir/Support/JitRunner.h"
2727

28+
#include "mlir/Conversion/ControlFlowToCFG/ConvertControlFlowToCFG.h"
2829
#include "mlir/Conversion/StandardToLLVM/ConvertStandardToLLVMPass.h"
2930
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
3031
#include "mlir/ExecutionEngine/ExecutionEngine.h"
@@ -172,7 +173,8 @@ static LogicalResult convertAffineStandardToLLVMIR(ModuleOp module) {
172173
manager.addPass(mlir::createCanonicalizerPass());
173174
manager.addPass(mlir::createCSEPass());
174175
manager.addPass(mlir::createLowerAffinePass());
175-
manager.addPass(mlir::createConvertToLLVMIRPass());
176+
manager.addPass(mlir::createLowerToCFGPass());
177+
manager.addPass(mlir::createLowerToLLVMPass());
176178
return manager.run(module);
177179
}
178180

test/mlir-cpu-runner/simple.mlir

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// RUN: mlir-cpu-runner %s | FileCheck %s
22
// RUN: mlir-cpu-runner -e foo -init-value 1000 %s | FileCheck -check-prefix=NOMAIN %s
33
// RUN: mlir-cpu-runner %s -O3 | FileCheck %s
4-
// RUN: mlir-cpu-runner %s -O3 -loop-distribute -loop-vectorize | FileCheck %s
5-
// RUN: mlir-cpu-runner %s -loop-distribute -loop-vectorize | FileCheck %s
4+
// RUN: mlir-cpu-runner -e affine -init-value 2.0 %s | FileCheck -check-prefix=AFFINE %s
65

76
// RUN: cp %s %t
87
// RUN: mlir-cpu-runner %t -dump-object-file | FileCheck %t
@@ -40,3 +39,13 @@ func @foo(%a : memref<1x1xf32>) -> memref<1x1xf32> {
4039
}
4140
// NOMAIN: 2.234000e+03
4241
// NOMAIN-NEXT: 2.234000e+03
42+
43+
func @affine(%a : memref<32xf32>) -> memref<32xf32> {
44+
%cf1 = constant 42.0 : f32
45+
%N = dim %a, 0 : memref<32xf32>
46+
affine.for %i = 0 to %N {
47+
affine.store %cf1, %a[%i] : memref<32xf32>
48+
}
49+
return %a : memref<32xf32>
50+
}
51+
// AFFINE: 4.2{{0+}}e+01

tools/mlir-cpu-runner/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ add_llvm_executable(mlir-cpu-runner
33
)
44
llvm_update_compile_flags(mlir-cpu-runner)
55
whole_archive_link(mlir-cpu-runner
6+
MLIRAffineOps
67
MLIRLLVMIR
78
MLIRStandardOps
89
MLIRTargetLLVMIR

0 commit comments

Comments
 (0)