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_XLA_SERVICE_CPU_MLIR_EMITTER_H_ 17 #define TENSORFLOW_COMPILER_XLA_SERVICE_CPU_MLIR_EMITTER_H_ 18 19 #include "llvm/IR/IRBuilder.h" 20 #include "llvm/IR/Value.h" 21 #include "mlir/Dialect/Func/IR/FuncOps.h" // from @llvm-project 22 #include "mlir/IR/Builders.h" // from @llvm-project 23 #include "mlir/IR/BuiltinOps.h" // from @llvm-project 24 #include "mlir/IR/MLIRContext.h" // from @llvm-project 25 #include "tensorflow/compiler/xla/shape.h" 26 #include "tensorflow/compiler/xla/status.h" 27 28 namespace xla { 29 namespace cpu { 30 31 // Create a new MLIR function with the name `func_name`, populate it with 32 // `emitter` and create a call, passing it the buffers defined by 33 // resultShape/resultPtr and operandShapes/operandPtrs. The function is added to 34 // the LLVM module at `b`s insertion point. 35 Status EmitMlirFuncAndCall( 36 mlir::MLIRContext *context, llvm::IRBuilder<> *b, const Shape &result_shape, 37 llvm::ArrayRef<Shape> operand_shapes, llvm::Value *result_ptr, 38 llvm::ArrayRef<llvm::Value *> operand_ptrs, llvm::StringRef func_name, 39 llvm::function_ref<void(mlir::OpBuilder *, mlir::func::FuncOp)> emitter); 40 41 } // namespace cpu 42 } // namespace xla 43 44 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_CPU_MLIR_EMITTER_H_ 45