1f8f909f8SDean Michael Berris //===- func-id-helper.h - XRay Function ID Conversion Helpers -------------===// 2f8f909f8SDean Michael Berris // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6f8f909f8SDean Michael Berris // 7f8f909f8SDean Michael Berris //===----------------------------------------------------------------------===// 8f8f909f8SDean Michael Berris // 9f8f909f8SDean Michael Berris // Defines helper tools dealing with XRay-generated function ids. 10f8f909f8SDean Michael Berris // 11f8f909f8SDean Michael Berris //===----------------------------------------------------------------------===// 12f8f909f8SDean Michael Berris #ifndef LLVM_TOOLS_LLVM_XRAY_FUNC_ID_HELPER_H 13f8f909f8SDean Michael Berris #define LLVM_TOOLS_LLVM_XRAY_FUNC_ID_HELPER_H 14f8f909f8SDean Michael Berris 1586ed8e58SMartin Pelikan #include "llvm/ADT/DenseMap.h" 16*db29f437Sserge-sans-paille #include "llvm/DebugInfo/Symbolize/SymbolizableModule.h" 17f8f909f8SDean Michael Berris #include "llvm/DebugInfo/Symbolize/Symbolize.h" 18f8f909f8SDean Michael Berris #include <unordered_map> 19f8f909f8SDean Michael Berris 20f8f909f8SDean Michael Berris namespace llvm { 21f8f909f8SDean Michael Berris namespace xray { 22f8f909f8SDean Michael Berris 23f8f909f8SDean Michael Berris // This class consolidates common operations related to Function IDs. 24f8f909f8SDean Michael Berris class FuncIdConversionHelper { 25f8f909f8SDean Michael Berris public: 26f8f909f8SDean Michael Berris using FunctionAddressMap = std::unordered_map<int32_t, uint64_t>; 27f8f909f8SDean Michael Berris 28f8f909f8SDean Michael Berris private: 29f8f909f8SDean Michael Berris std::string BinaryInstrMap; 30f8f909f8SDean Michael Berris symbolize::LLVMSymbolizer &Symbolizer; 31f8f909f8SDean Michael Berris const FunctionAddressMap &FunctionAddresses; 3286ed8e58SMartin Pelikan mutable llvm::DenseMap<int32_t, std::string> CachedNames; 33f8f909f8SDean Michael Berris 34f8f909f8SDean Michael Berris public: FuncIdConversionHelper(std::string BinaryInstrMap,symbolize::LLVMSymbolizer & Symbolizer,const FunctionAddressMap & FunctionAddresses)35f8f909f8SDean Michael Berris FuncIdConversionHelper(std::string BinaryInstrMap, 36f8f909f8SDean Michael Berris symbolize::LLVMSymbolizer &Symbolizer, 37f8f909f8SDean Michael Berris const FunctionAddressMap &FunctionAddresses) 38f8f909f8SDean Michael Berris : BinaryInstrMap(std::move(BinaryInstrMap)), Symbolizer(Symbolizer), 39f8f909f8SDean Michael Berris FunctionAddresses(FunctionAddresses) {} 40f8f909f8SDean Michael Berris 41f8f909f8SDean Michael Berris // Returns the symbol or a string representation of the function id. 42f8f909f8SDean Michael Berris std::string SymbolOrNumber(int32_t FuncId) const; 43f8f909f8SDean Michael Berris 44f8f909f8SDean Michael Berris // Returns the file and column from debug info for the given function id. 45f8f909f8SDean Michael Berris std::string FileLineAndColumn(int32_t FuncId) const; 46f8f909f8SDean Michael Berris }; 47f8f909f8SDean Michael Berris 48f8f909f8SDean Michael Berris } // namespace xray 49f8f909f8SDean Michael Berris } // namespace llvm 50f8f909f8SDean Michael Berris 51f8f909f8SDean Michael Berris #endif // LLVM_TOOLS_LLVM_XRAY_FUNC_ID_HELPER_H 52