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