2020-06-14 14:45:43 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "npcomp/Conversion/BasicpyToStd/Passes.h"
|
|
|
|
#include "npcomp/Conversion/BasicpyToStd/Patterns.h"
|
|
|
|
|
|
|
|
#include "../PassDetail.h"
|
|
|
|
#include "mlir/Dialect/Traits.h"
|
2020-10-30 06:25:55 +08:00
|
|
|
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
|
2020-06-14 14:45:43 +08:00
|
|
|
|
|
|
|
using namespace mlir;
|
|
|
|
using namespace mlir::NPCOMP;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class ConvertBasicpyToStd
|
|
|
|
: public ConvertBasicpyToStdBase<ConvertBasicpyToStd> {
|
|
|
|
public:
|
2021-01-22 03:48:41 +08:00
|
|
|
void runOnOperation() override {
|
2020-06-14 14:45:43 +08:00
|
|
|
FuncOp func = getOperation();
|
2020-10-30 06:25:55 +08:00
|
|
|
(void)applyPatternsAndFoldGreedily(func, getPatterns());
|
|
|
|
}
|
2020-06-14 14:45:43 +08:00
|
|
|
|
2020-10-30 06:25:55 +08:00
|
|
|
FrozenRewritePatternList getPatterns() {
|
|
|
|
auto *context = &getContext();
|
2020-06-14 14:45:43 +08:00
|
|
|
OwningRewritePatternList patterns;
|
|
|
|
populateBasicpyToStdPrimitiveOpPatterns(context, patterns);
|
2020-10-30 06:25:55 +08:00
|
|
|
return std::move(patterns);
|
2020-06-14 14:45:43 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
std::unique_ptr<OperationPass<FuncOp>>
|
|
|
|
mlir::NPCOMP::createConvertBasicpyToStdPass() {
|
|
|
|
return std::make_unique<ConvertBasicpyToStd>();
|
|
|
|
}
|