1 /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #include "mlir-hlo/Dialect/mhlo/IR/hlo_ops.h" 17 #include "mlir-hlo/Dialect/mhlo/transforms/PassDetail.h" 18 #include "mlir-hlo/Dialect/mhlo/transforms/passes.h" 19 #include "mlir-hlo/Dialect/mhlo/transforms/rewriters.h" 20 #include "mlir/Dialect/StandardOps/IR/Ops.h" 21 #include "mlir/IR/MLIRContext.h" 22 #include "mlir/IR/Operation.h" 23 #include "mlir/Pass/Pass.h" 24 #include "mlir/Transforms/DialectConversion.h" 25 #include "mlir/Transforms/GreedyPatternRewriteDriver.h" 26 27 namespace mlir { 28 namespace mhlo { 29 namespace { 30 class OptimizeMhloPass : public OptimizeMhloPassBase<OptimizeMhloPass> { 31 public: 32 /// Performs the lowering to MHLO dialect. 33 void runOnFunction() override; 34 }; 35 // Lowers the complex operations that can be represented using other operations. runOnFunction()36void OptimizeMhloPass::runOnFunction() { 37 // Add lowering patterns to the list. 38 OwningRewritePatternList patterns(&getContext()); 39 PopulateOptimizeMHLOPatterns(&getContext(), &patterns); 40 41 (void)applyPatternsAndFoldGreedily(getFunction(), std::move(patterns)); 42 } 43 } // end anonymous namespace 44 } // namespace mhlo 45 } // namespace mlir 46 createOptimizeMhloPass()47std::unique_ptr<mlir::FunctionPass> mlir::mhlo::createOptimizeMhloPass() { 48 return std::make_unique<mlir::mhlo::OptimizeMhloPass>(); 49 } 50