Make krnl-to-llvm patterns reusable (#272)

* Make krnl-to-llvm patterns reusable

* Change include paths

* Change include paths
This commit is contained in:
Tung D. Le 2020-08-20 00:58:04 +09:00 committed by GitHub
parent fe6dc5bd81
commit 13e8070708
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 17 deletions

View File

@ -10,7 +10,6 @@
#include "mlir/Conversion/AffineToStandard/AffineToStandard.h"
#include "mlir/Conversion/SCFToStandard/SCFToStandard.h"
#include "mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h"
#include "mlir/Conversion/StandardToLLVM/ConvertStandardToLLVMPass.h"
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
@ -22,6 +21,7 @@
#include "onnx/onnx_pb.h"
#include "llvm/ADT/Sequence.h"
#include "src/Conversion/KrnlToLLVM/KrnlToLLVM.hpp"
#include "src/Conversion/ONNXToKrnl/ONNXToKrnlCommon.hpp"
#include "src/Dialect/Krnl/KrnlOps.hpp"
#include "src/Pass/Passes.hpp"
@ -852,18 +852,31 @@ private:
};
} // end namespace
void mlir::populateAffineAndKrnlToLLVMConversion(
OwningRewritePatternList &patterns, MLIRContext *ctx,
LLVMTypeConverter &typeConverter) {
populateAffineToStdConversionPatterns(patterns, ctx);
populateLoopToStdConversionPatterns(patterns, ctx);
populateStdToLLVMConversionPatterns(typeConverter, patterns);
patterns.insert<KrnlGlobalOpLowering, KrnlPackedConstOpLowering>(
ctx, typeConverter);
patterns.insert<KrnlGetRefOpLowering>(ctx, typeConverter);
patterns.insert<KrnlMemcpyOpLowering, KrnlEntryPointOpLowering>(ctx);
}
//===----------------------------------------------------------------------===//
// KRNL + Stadard + Affine dialects lowering to LLVM.
// KRNL + Standard + Affine dialects lowering to LLVM.
//===----------------------------------------------------------------------===//
namespace {
struct ConvertKrlnToLLVMPass
: public PassWrapper<ConvertKrlnToLLVMPass, OperationPass<ModuleOp>> {
struct ConvertKrnlToLLVMPass
: public PassWrapper<ConvertKrnlToLLVMPass, OperationPass<ModuleOp>> {
void runOnOperation() final;
};
} // end anonymous namespace
void ConvertKrlnToLLVMPass::runOnOperation() {
void ConvertKrnlToLLVMPass::runOnOperation() {
// Define the target for this lowering i.e. the LLVM dialect.
ConversionTarget target(getContext());
target.addLegalDialect<LLVM::LLVMDialect>();
@ -877,17 +890,7 @@ void ConvertKrlnToLLVMPass::runOnOperation() {
// We have a combination of `krnl`, `affine`, and `std` operations. We
// lower in stages until all the code is in the LLVM dialect.
OwningRewritePatternList patterns;
populateAffineToStdConversionPatterns(patterns, &getContext());
populateLoopToStdConversionPatterns(patterns, &getContext());
populateStdToLLVMConversionPatterns(typeConverter, patterns);
patterns.insert<KrnlGlobalOpLowering, KrnlPackedConstOpLowering>(
&getContext(), typeConverter);
patterns.insert<KrnlGetRefOpLowering>(&getContext(), typeConverter);
// Lower from the `krnl` dialect i.e. the Reshape operation.
patterns.insert<KrnlMemcpyOpLowering, KrnlEntryPointOpLowering>(
&getContext());
populateAffineAndKrnlToLLVMConversion(patterns, &getContext(), typeConverter);
// We want to completely lower to LLVM, so we use a `FullConversion`. This
// ensures that only legal operations will remain after the conversion.
@ -898,5 +901,5 @@ void ConvertKrlnToLLVMPass::runOnOperation() {
/// Create the pass for lowering `Krnl`, `Affine` and `Std` dialects to LLVM.
std::unique_ptr<mlir::Pass> mlir::createConvertKrnlToLLVMPass() {
return std::make_unique<ConvertKrlnToLLVMPass>();
return std::make_unique<ConvertKrnlToLLVMPass>();
}

View File

@ -0,0 +1,27 @@
//===------ KrnlToLLVM.hpp - Lowering from KRNL+Affine+Std to LLVM -------===//
//
// Copyright 2019-2020 The IBM Research Authors.
//
// =============================================================================
//
//
//
//===----------------------------------------------------------------------===//
#ifndef KRNL_TO_LLVM_H
#define KRNL_TO_LLVM_H
#include "mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h"
namespace mlir {
class MLIRContext;
class LLVMTypeConverter;
class OwningRewritePatternList;
void populateAffineAndKrnlToLLVMConversion(OwningRewritePatternList &patterns,
MLIRContext *ctx, LLVMTypeConverter &typeConverter);
} // namespace mlir
#endif // KRNL_TO_LLVM_H