1
// Tencent is pleased to support the open source community by making ncnn available.
3
// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
5
// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6
// in compliance with the License. You may obtain a copy of the License at
8
// https://opensource.org/licenses/BSD-3-Clause
10
// Unless required by applicable law or agreed to in writing, software distributed
11
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
13
// specific language governing permissions and limitations under the License.
15
#include <mlir/IR/MLIRContext.h>
16
#include <mlir/IR/PatternMatch.h>
17
#include <mlir/Pass/Pass.h>
18
#include <mlir/Transforms/GreedyPatternRewriteDriver.h>
20
#include "tf_dialect.h"
21
#include "ncnn_dialect.h"
29
#include "ncnn_rewriter.inc"
31
class NCNNOptimizePass : public PassWrapper<NCNNOptimizePass, FunctionPass>
37
void NCNNOptimizePass::runOnFunction()
39
mlir::OwningRewritePatternList patterns;
40
mlir::ncnn::populateWithGenerated(&getContext(), patterns);
42
(void)mlir::applyPatternsAndFoldGreedily(getFunction(), std::move(patterns));
45
std::unique_ptr<OperationPass<FuncOp> > createNCNNOptimizePass()
47
return std::make_unique<NCNNOptimizePass>();
50
static PassRegistration<NCNNOptimizePass> pass("ncnn-optimize", "ncnn optimization");