annotate tools/llvm-xray/func-id-helper.h @ 148:63bd29f05246

merged
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 14 Aug 2019 19:46:37 +0900
parents c2174574ed3a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
1 //===- func-id-helper.h - XRay Function ID Conversion Helpers -------------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
2 //
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
6 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
8 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
9 // Defines helper tools dealing with XRay-generated function ids.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
10 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
11 //===----------------------------------------------------------------------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
12 #ifndef LLVM_TOOLS_LLVM_XRAY_FUNC_ID_HELPER_H
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
13 #define LLVM_TOOLS_LLVM_XRAY_FUNC_ID_HELPER_H
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
14
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
15 #include "llvm/ADT/DenseMap.h"
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
16 #include "llvm/DebugInfo/Symbolize/Symbolize.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
17 #include <unordered_map>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
18
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
19 namespace llvm {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
20 namespace xray {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
21
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
22 // This class consolidates common operations related to Function IDs.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
23 class FuncIdConversionHelper {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
24 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
25 using FunctionAddressMap = std::unordered_map<int32_t, uint64_t>;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
26
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
27 private:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
28 std::string BinaryInstrMap;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
29 symbolize::LLVMSymbolizer &Symbolizer;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
30 const FunctionAddressMap &FunctionAddresses;
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
31 mutable llvm::DenseMap<int32_t, std::string> CachedNames;
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
32
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
33 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
34 FuncIdConversionHelper(std::string BinaryInstrMap,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
35 symbolize::LLVMSymbolizer &Symbolizer,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
36 const FunctionAddressMap &FunctionAddresses)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
37 : BinaryInstrMap(std::move(BinaryInstrMap)), Symbolizer(Symbolizer),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
38 FunctionAddresses(FunctionAddresses) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
39
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
40 // Returns the symbol or a string representation of the function id.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
41 std::string SymbolOrNumber(int32_t FuncId) const;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
42
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
43 // Returns the file and column from debug info for the given function id.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
44 std::string FileLineAndColumn(int32_t FuncId) const;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
45 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
46
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
47 } // namespace xray
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
48 } // namespace llvm
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
49
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
50 #endif // LLVM_TOOLS_LLVM_XRAY_FUNC_ID_HELPER_H