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 #ifndef TENSORFLOW_COMPILER_MLIR_TOSA_TRANSFORMS_PASSES_H 17 #define TENSORFLOW_COMPILER_MLIR_TOSA_TRANSFORMS_PASSES_H 18 19 #include <memory> 20 #include <string> 21 #include <unordered_set> 22 23 #include "mlir/Dialect/Func/IR/FuncOps.h" // from @llvm-project 24 #include "mlir/Pass/Pass.h" // from @llvm-project 25 26 namespace mlir { 27 28 namespace quant { 29 class QuantizationDialect; 30 } 31 32 namespace quantfork { 33 class QuantizationForkDialect; 34 } 35 36 namespace TFL { 37 class TFLDialect; 38 } 39 40 namespace tosa { 41 class TosaDialect; 42 43 void populateLegalizeTFPatterns(MLIRContext* ctx, RewritePatternSet& patterns); 44 void populateLegalizeTFLPatterns(MLIRContext* ctx, RewritePatternSet& patterns); 45 46 std::unique_ptr<OperationPass<func::FuncOp>> createLegalizeTFPass(); 47 std::unique_ptr<OperationPass<func::FuncOp>> createFuseBiasTFPass(); 48 49 // `disabledPatterns` is a set of labels used to filter out input patterns with 50 // a debug label or debug name in this set. 51 // `enabledPatterns` is a set of labels used to filter out input patterns that 52 // do not have one of the labels in this set. 53 std::unique_ptr<OperationPass<func::FuncOp>> createLegalizeTFLPass( 54 ArrayRef<std::string> disabled_patterns = llvm::None, 55 ArrayRef<std::string> enabled_patterns = llvm::None); 56 57 std::unique_ptr<OperationPass<func::FuncOp>> createLegalizeTFTFLPass(); 58 std::unique_ptr<OperationPass<func::FuncOp>> createConvertTFLUint8Pass(); 59 std::unique_ptr<OperationPass<func::FuncOp>> createStripQuantTypesPass(); 60 std::unique_ptr<OperationPass<func::FuncOp>> createDequantizeTFLSoftmaxPass(); 61 62 #define GEN_PASS_REGISTRATION 63 #define GEN_PASS_CLASSES 64 65 #include "tensorflow/compiler/mlir/tosa/transforms/passes.h.inc" 66 67 } // namespace tosa 68 } // namespace mlir 69 70 #endif // TENSORFLOW_COMPILER_MLIR_TOSA_TRANSFORMS_PASSES_H 71