LLVM: include/llvm/ProfileData/FunctionId.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef LLVM_PROFILEDATA_FUNCTIONID_H
16#define LLVM_PROFILEDATA_FUNCTIONID_H
17
23#include
24
25namespace llvm {
27
28
29
30
31
32
33
34
35
37
38 const char *Data = nullptr;
39
40
41
42 uint64_t LengthOrHashCode = 0;
43
44
45
46
47
48 static int compareMemory(const char *Lhs, const char *Rhs, uint64_t Length) {
49 if (Lhs == Rhs)
50 return 0;
51 if (!Lhs)
52 return -1;
53 if (!Rhs)
54 return 1;
55 return ::memcmp(Lhs, Rhs, (size_t)Length);
56 }
57
58public:
60
61
63 : Data(Str.data()), LengthOrHashCode(Str.size()) {
64 }
65
66
68 : LengthOrHashCode(HashCode) {
69 assert(HashCode != 0);
70 }
71
72
73
74
75
77 return LengthOrHashCode == Other.LengthOrHashCode &&
78 compareMemory(Data, Other.Data, LengthOrHashCode) == 0;
79 }
80
81
82
83
84
86 auto Res = compareMemory(
87 Data, Other.Data, std::min(LengthOrHashCode, Other.LengthOrHashCode));
88 if (Res != 0)
89 return Res;
90 if (LengthOrHashCode == Other.LengthOrHashCode)
91 return 0;
92 return LengthOrHashCode < Other.LengthOrHashCode ? -1 : 1;
93 }
94
95
96
98 if (Data)
99 return std::string(Data, LengthOrHashCode);
100 if (LengthOrHashCode != 0)
101 return std::to_string(LengthOrHashCode);
102 return std::string();
103 }
104
105
106
107
109 if (Data)
110 return StringRef(Data, LengthOrHashCode);
111 assert(LengthOrHashCode == 0 &&
112 "Cannot convert MD5 FunctionId to StringRef");
114 }
115
117
118
119
120
121
122
124 if (Data)
126 return LengthOrHashCode;
127 }
128
129 bool empty() const { return LengthOrHashCode == 0; }
130
131
133};
134
137}
138
140 return .equals(RHS);
141}
142
144 return LHS.compare(RHS) < 0;
145}
146
148 return LHS.compare(RHS) <= 0;
149}
150
152 return LHS.compare(RHS) > 0;
153}
154
156 return LHS.compare(RHS) >= 0;
157}
158
160 if (Obj.Data)
161 return OS << StringRef(Obj.Data, Obj.LengthOrHashCode);
162 if (Obj.LengthOrHashCode != 0)
163 return OS << Obj.LengthOrHashCode;
164 return OS;
165}
166
168 return Obj.getHashCode();
169}
170
172 return Obj.getHashCode();
173}
174
175}
176
177
178
198
199}
200
201namespace std {
202
203
204
205template <> struct hash<llvm::sampleprof::FunctionId> {
209};
210
211}
212
213#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines DenseMapInfo traits for DenseMap.
StringRef - Represent a constant reference to a string, i.e.
This class implements an extremely fast bulk output stream that can only output to a stream.
This class represents a function that is read from a sample profile.
Definition FunctionId.h:36
FunctionId(StringRef Str)
Constructor from a StringRef.
Definition FunctionId.h:62
StringRef stringRef() const
Convert to StringRef.
Definition FunctionId.h:108
FunctionId(uint64_t HashCode)
Constructor from a hash code.
Definition FunctionId.h:67
uint64_t getHashCode() const
Get hash code of this object.
Definition FunctionId.h:123
bool isStringRef() const
Check if this object represents a StringRef, or a hash code.
Definition FunctionId.h:132
friend raw_ostream & operator<<(raw_ostream &OS, const FunctionId &Obj)
Definition FunctionId.h:159
int compare(const FunctionId &Other) const
Total order comparison.
Definition FunctionId.h:85
bool empty() const
Definition FunctionId.h:129
bool equals(const FunctionId &Other) const
Check for equality.
Definition FunctionId.h:76
std::string str() const
Convert to a string, usually for output purpose.
Definition FunctionId.h:97
Definition FunctionId.h:26
bool operator>(const FunctionId &LHS, const FunctionId &RHS)
Definition FunctionId.h:151
bool operator<=(const FunctionId &LHS, const FunctionId &RHS)
Definition FunctionId.h:147
bool operator<(const FunctionId &LHS, const FunctionId &RHS)
Definition FunctionId.h:143
bool operator!=(const FunctionId &LHS, const FunctionId &RHS)
Definition FunctionId.h:139
bool operator>=(const FunctionId &LHS, const FunctionId &RHS)
Definition FunctionId.h:155
uint64_t MD5Hash(const FunctionId &Obj)
Definition FunctionId.h:167
raw_ostream & operator<<(raw_ostream &OS, const FunctionId &Obj)
Definition FunctionId.h:159
uint64_t hash_value(const FunctionId &Obj)
Definition FunctionId.h:171
bool operator==(const FunctionId &LHS, const FunctionId &RHS)
Definition FunctionId.h:135
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Implement std::hash so that hash_code can be used in STL containers.
static sampleprof::FunctionId getEmptyKey()
Definition FunctionId.h:181
static sampleprof::FunctionId getTombstoneKey()
Definition FunctionId.h:185
static bool isEqual(const sampleprof::FunctionId &LHS, const sampleprof::FunctionId &RHS)
Definition FunctionId.h:193
static unsigned getHashValue(const sampleprof::FunctionId &Val)
Definition FunctionId.h:189
An information struct used to provide DenseMap with the various necessary components for a given valu...
size_t operator()(const llvm::sampleprof::FunctionId &Val) const
Definition FunctionId.h:206