1 /* Copyright 2021 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_LITE_EXPERIMENTAL_TAC_COMMON_SUBGRAPH_H_ 17 #define TENSORFLOW_COMPILER_MLIR_LITE_EXPERIMENTAL_TAC_COMMON_SUBGRAPH_H_ 18 19 #include <string> 20 21 #include "llvm/ADT/StringRef.h" 22 #include "mlir/IR/Operation.h" // from @llvm-project 23 24 namespace mlir { 25 namespace TFL { 26 namespace tac { 27 28 // Interface name here is the "hook" between the CallOp and FuncOps. 29 // Take the following example: 30 // 31 // call @func_1_CPU {tac.interface_name = "func_1"} 32 // 33 // "func_1" is the interface name where "func_1_cpu" is the real implementation 34 // we can have multiple FuncOps like "func_1_cpu" and "func_1_gpu" and they 35 // both implement "func_1". 36 // 37 // The attribute on the FuncOp means what it actually implements while the 38 // attribute on the CallOp means what it actually looks for. 39 constexpr char kInterfaceNameAttr[] = "tac.interface_name"; 40 GetInterFaceName(Operation * op)41inline llvm::Optional<std::string> GetInterFaceName(Operation* op) { 42 auto name_attr = op->getAttrOfType<StringAttr>(kInterfaceNameAttr); 43 if (!name_attr) return llvm::None; 44 return name_attr.getValue().str(); 45 } 46 47 } // namespace tac 48 } // namespace TFL 49 } // namespace mlir 50 51 #endif // TENSORFLOW_COMPILER_MLIR_LITE_EXPERIMENTAL_TAC_COMMON_SUBGRAPH_H_ 52