1 /* Copyright 2022 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 // This file implements logic for translating mixed IR to buffer form. 17 18 #include <memory> 19 20 #include "mlir/Dialect/Arithmetic/IR/Arithmetic.h" // from @llvm-project 21 #include "mlir/Dialect/Bufferization/Transforms/Bufferize.h" // from @llvm-project 22 #include "mlir/Pass/PassManager.h" // from @llvm-project 23 #include "tensorflow/compiler/mlir/tools/kernel_gen/transforms/passes.h" 24 #include "tensorflow/compiler/mlir/tools/kernel_gen/transforms/rewriters.h" 25 #include "tensorflow/compiler/xla/mlir_hlo/include/mlir-hlo/Transforms/PassDetail.h" 26 #include "tensorflow/compiler/xla/mlir_hlo/include/mlir-hlo/Transforms/passes.h" 27 28 namespace mlir { 29 namespace kernel_gen { 30 namespace transforms { 31 namespace { 32 33 #define GEN_PASS_CLASSES 34 #include "tensorflow/compiler/mlir/tools/kernel_gen/transforms/kernel_gen_passes.h.inc" 35 36 struct KernelgenFinalBufferizePass 37 : public KernelgenFinalBufferizePassBase<KernelgenFinalBufferizePass> { 38 // Default alignment_ specified in passes.td 39 KernelgenFinalBufferizePass() = default; 40 runOnOperationmlir::kernel_gen::transforms::__anond73bfd8b0111::KernelgenFinalBufferizePass41 void runOnOperation() override { 42 mlir::PassManager pm(&getContext()); 43 pm.addPass(mlir::createFinalBufferizePass(/*alignment=*/64, 44 populateExtraBufferizeDialects, 45 populateExtraBufferizePatterns)); 46 (void)runPipeline(pm, getOperation()); 47 } 48 }; 49 50 } // namespace 51 CreateKernelgenFinalBufferizePass()52std::unique_ptr<OperationPass<ModuleOp>> CreateKernelgenFinalBufferizePass() { 53 return std::make_unique<KernelgenFinalBufferizePass>(); 54 } 55 56 } // namespace transforms 57 } // namespace kernel_gen 58 } // namespace mlir 59