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_TOOLS_KERNEL_GEN_TRANSFORMS_REWRITERS_H_ 17 #define TENSORFLOW_COMPILER_MLIR_TOOLS_KERNEL_GEN_TRANSFORMS_REWRITERS_H_ 18 19 #include "mlir/IR/MLIRContext.h" // from @llvm-project 20 21 namespace mlir { 22 namespace bufferization { 23 class BufferizeTypeConverter; 24 } 25 class ConversionTarget; 26 class LLVMTypeConverter; 27 class MLIRContext; 28 class RewritePatternSet; 29 class TypeConverter; 30 31 namespace kernel_gen { 32 namespace tf_framework { 33 34 /// Collects a set of patterns to convert from the TF Framework dialect to LLVM. 35 void PopulateTFFrameworkToLLVMConversionPatterns(LLVMTypeConverter *converter, 36 RewritePatternSet *patterns); 37 38 /// Collects a set of patterns to rewrite functions for use with TF framework 39 /// and also replace `alloc`, `dealloc` and `assert`. 40 void PopulateEmbedTFFrameworkPatterns(RewritePatternSet *patterns); 41 void PopulateEmbedTFFrameworkAssertPattern(RewritePatternSet *patterns); 42 43 } // namespace tf_framework 44 45 namespace transforms { 46 47 /// Collects a set of patterns that bufferize operations from the standard and 48 /// other dialects. 49 void populateExtraBufferizeDialects(DialectRegistry ®istry); 50 void populateExtraBufferizePatterns( 51 ConversionTarget &target, MLIRContext *context, 52 bufferization::BufferizeTypeConverter *converter, 53 RewritePatternSet *patterns); 54 55 /// Populate patterns to rewrite TF operations to TF framework JIT invocations. 56 void PopulateTFToJITInvocationPatterns( 57 MLIRContext *ctx, RewritePatternSet *patterns, 58 llvm::ArrayRef<int64_t> tile_sizes, llvm::ArrayRef<int64_t> unroll_factors, 59 int64_t max_supported_rank, bool enable_ftz, bool index_64bit, 60 bool cpu_codegen, bool jit_i64_indexed_for_large_tensors); 61 62 } // namespace transforms 63 } // namespace kernel_gen 64 } // namespace mlir 65 66 #endif // TENSORFLOW_COMPILER_MLIR_TOOLS_KERNEL_GEN_TRANSFORMS_REWRITERS_H_ 67