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