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 #ifndef TENSORFLOW_COMPILER_MLIR_TOOLS_KERNEL_GEN_TRANSFORMS_UTILS_H_ 17 #define TENSORFLOW_COMPILER_MLIR_TOOLS_KERNEL_GEN_TRANSFORMS_UTILS_H_ 18 19 #include <string> 20 21 #include "mlir/IR/BuiltinOps.h" // from @llvm-project 22 #include "mlir/IR/BuiltinTypes.h" // from @llvm-project 23 24 namespace mlir { 25 namespace kernel_gen { 26 namespace transforms { 27 28 // Attempts to find function symbol in the module, adds it if not found. 29 FlatSymbolRefAttr GetOrInsertLLVMFunction(StringRef func_name, Type func_type, 30 Operation* op, OpBuilder* b); 31 32 // Attemts to find a global string constant in the module, adds it if not found. 33 Value CreateOrFindGlobalStringConstant(Location loc, StringRef global_name, 34 StringRef content, OpBuilder* builder); 35 36 // Generates a global name with the format "base_hash(content)". 37 std::string GetGlobalName(StringRef base, StringRef content); 38 39 } // namespace transforms 40 } // namespace kernel_gen 41 } // namespace mlir 42 43 #endif // TENSORFLOW_COMPILER_MLIR_TOOLS_KERNEL_GEN_TRANSFORMS_UTILS_H_ 44