func-id-helper.h 1.7 KB

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