10b57cec5SDimitry Andric //===- func-id-helper.h - XRay Function ID Conversion Helpers -------------===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric // 90b57cec5SDimitry Andric // Defines helper tools dealing with XRay-generated function ids. 100b57cec5SDimitry Andric // 110b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 120b57cec5SDimitry Andric #ifndef LLVM_TOOLS_LLVM_XRAY_FUNC_ID_HELPER_H 130b57cec5SDimitry Andric #define LLVM_TOOLS_LLVM_XRAY_FUNC_ID_HELPER_H 140b57cec5SDimitry Andric 150b57cec5SDimitry Andric #include "llvm/ADT/DenseMap.h" 16*81ad6265SDimitry Andric #include "llvm/DebugInfo/Symbolize/SymbolizableModule.h" 170b57cec5SDimitry Andric #include "llvm/DebugInfo/Symbolize/Symbolize.h" 180b57cec5SDimitry Andric #include <unordered_map> 190b57cec5SDimitry Andric 200b57cec5SDimitry Andric namespace llvm { 210b57cec5SDimitry Andric namespace xray { 220b57cec5SDimitry Andric 230b57cec5SDimitry Andric // This class consolidates common operations related to Function IDs. 240b57cec5SDimitry Andric class FuncIdConversionHelper { 250b57cec5SDimitry Andric public: 260b57cec5SDimitry Andric using FunctionAddressMap = std::unordered_map<int32_t, uint64_t>; 270b57cec5SDimitry Andric 280b57cec5SDimitry Andric private: 290b57cec5SDimitry Andric std::string BinaryInstrMap; 300b57cec5SDimitry Andric symbolize::LLVMSymbolizer &Symbolizer; 310b57cec5SDimitry Andric const FunctionAddressMap &FunctionAddresses; 320b57cec5SDimitry Andric mutable llvm::DenseMap<int32_t, std::string> CachedNames; 330b57cec5SDimitry Andric 340b57cec5SDimitry Andric public: FuncIdConversionHelper(std::string BinaryInstrMap,symbolize::LLVMSymbolizer & Symbolizer,const FunctionAddressMap & FunctionAddresses)350b57cec5SDimitry Andric FuncIdConversionHelper(std::string BinaryInstrMap, 360b57cec5SDimitry Andric symbolize::LLVMSymbolizer &Symbolizer, 370b57cec5SDimitry Andric const FunctionAddressMap &FunctionAddresses) 380b57cec5SDimitry Andric : BinaryInstrMap(std::move(BinaryInstrMap)), Symbolizer(Symbolizer), 390b57cec5SDimitry Andric FunctionAddresses(FunctionAddresses) {} 400b57cec5SDimitry Andric 410b57cec5SDimitry Andric // Returns the symbol or a string representation of the function id. 420b57cec5SDimitry Andric std::string SymbolOrNumber(int32_t FuncId) const; 430b57cec5SDimitry Andric 440b57cec5SDimitry Andric // Returns the file and column from debug info for the given function id. 450b57cec5SDimitry Andric std::string FileLineAndColumn(int32_t FuncId) const; 460b57cec5SDimitry Andric }; 470b57cec5SDimitry Andric 480b57cec5SDimitry Andric } // namespace xray 490b57cec5SDimitry Andric } // namespace llvm 500b57cec5SDimitry Andric 510b57cec5SDimitry Andric #endif // LLVM_TOOLS_LLVM_XRAY_FUNC_ID_HELPER_H 52