-
Notifications
You must be signed in to change notification settings - Fork 113
/
Copy pathbinary_address_branch.h
77 lines (67 loc) · 2.43 KB
/
binary_address_branch.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef AUTOFDO_BINARY_ADDRESS_BRANCH_H_
#define AUTOFDO_BINARY_ADDRESS_BRANCH_H_
#include <cstdint>
#include <tuple>
#include <utility>
#include "third_party/abseil/absl/strings/str_format.h"
namespace devtools_crosstool_autofdo {
// `BinaryAddressBranch` represents a taken branch with endpoints specified as
// addresses in a program binary.
struct BinaryAddressBranch {
uint64_t from, to;
template <typename H>
friend H AbslHashValue(H h, const BinaryAddressBranch &b) {
return H::combine(std::move(h), b.from, b.to);
}
bool operator==(const BinaryAddressBranch &b) const {
return from == b.from && to == b.to;
}
bool operator<(const BinaryAddressBranch &b) const {
return std::forward_as_tuple(from, to) <
std::forward_as_tuple(b.from, b.to);
}
template <typename Sink>
friend void AbslStringify(Sink &sink, const BinaryAddressBranch &b) {
absl::Format(&sink, "0x%016x->0x%016x", b.from, b.to);
}
};
// `BinaryAddressNotTakenBranch` represents a not-taken branch with address
// specified as a binary address.
struct BinaryAddressNotTakenBranch {
uint64_t address;
template <typename H>
friend H AbslHashValue(H h, const BinaryAddressNotTakenBranch &b) {
return H::combine(std::move(h), b.address);
}
bool operator==(const BinaryAddressNotTakenBranch &b) const {
return address == b.address;
}
bool operator<(const BinaryAddressNotTakenBranch &b) const {
return address < b.address;
}
template <typename Sink>
friend void AbslStringify(Sink &sink, const BinaryAddressNotTakenBranch &b) {
absl::Format(&sink, "0x%016x", b.address);
}
};
// `BinaryAddressFallthrough` represents an address range of
// sequentially-executed instruction with endpoints specified as addresses in a
// program binary.
struct BinaryAddressFallthrough {
uint64_t from, to;
template <typename H>
friend H AbslHashValue(H h, const BinaryAddressFallthrough &f) {
return H::combine(std::move(h), f.from, f.to);
}
bool operator==(const BinaryAddressFallthrough &f) const {
return from == f.from && to == f.to;
}
template <typename Sink>
friend void AbslStringify(Sink &sink, const BinaryAddressFallthrough &f) {
absl::Format(&sink, "0x%016x->0x%016x", f.from, f.to);
}
};
// The sentinel value for an invalid binary address.
inline constexpr uint64_t kInvalidBinaryAddress = static_cast<uint64_t>(-1);
} // namespace devtools_crosstool_autofdo
#endif // AUTOFDO_BINARY_ADDRESS_BRANCH_H_