func-id-helper.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. #include "llvm/ADT/DenseMap.h"
  15. #include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
  16. #include "llvm/DebugInfo/Symbolize/Symbolize.h"
  17. #include <unordered_map>
  18. namespace llvm {
  19. namespace xray {
  20. // This class consolidates common operations related to Function IDs.
  21. class FuncIdConversionHelper {
  22. public:
  23. using FunctionAddressMap = std::unordered_map<int32_t, uint64_t>;
  24. private:
  25. std::string BinaryInstrMap;
  26. symbolize::LLVMSymbolizer &Symbolizer;
  27. const FunctionAddressMap &FunctionAddresses;
  28. mutable llvm::DenseMap<int32_t, std::string> CachedNames;
  29. public:
  30. FuncIdConversionHelper(std::string BinaryInstrMap,
  31. symbolize::LLVMSymbolizer &Symbolizer,
  32. const FunctionAddressMap &FunctionAddresses)
  33. : BinaryInstrMap(std::move(BinaryInstrMap)), Symbolizer(Symbolizer),
  34. FunctionAddresses(FunctionAddresses) {}
  35. // Returns the symbol or a string representation of the function id.
  36. std::string SymbolOrNumber(int32_t FuncId) const;
  37. // Returns the file and column from debug info for the given function id.
  38. std::string FileLineAndColumn(int32_t FuncId) const;
  39. };
  40. } // namespace xray
  41. } // namespace llvm
  42. #endif // LLVM_TOOLS_LLVM_XRAY_FUNC_ID_HELPER_H