LLVM: include/llvm/DebugInfo/LogicalView/Core/LVSupport.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSUPPORT_H
14#define LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSUPPORT_H
15
23#include
24#include
25#include
26#include
27#include <type_traits>
28
29namespace llvm {
31
32
34
38 std::tuple<LVStringRefs::size_type, LVStringRefs::size_type>;
39
40
42 static constexpr unsigned N_PROPS = static_cast<unsigned>(T::LastEntry);
43
44
45 std::conditional_t<(N_PROPS > 32), std::bitset<N_PROPS>, uint32_t> Bits{};
46
47public:
49
51 if constexpr (std::is_same_v<decltype(Bits), uint32_t>)
52 Bits |= 1 << static_cast<unsigned>(Idx);
53 else
54 Bits.set(static_cast<unsigned>(Idx));
55 }
57 if constexpr (std::is_same_v<decltype(Bits), uint32_t>)
58 Bits &= ~(1 << static_cast<unsigned>(Idx));
59 else
60 Bits.reset(static_cast<unsigned>(Idx));
61 }
63 if constexpr (std::is_same_v<decltype(Bits), uint32_t>)
64 return Bits & (1 << static_cast<unsigned>(Idx));
65 else
66 return Bits[static_cast<unsigned>(Idx)];
67 }
68};
69
70
71
72
73
74
75#define BOOL_BIT(FAMILY, ENUM, FIELD) \
76 bool get##FIELD() const { return FAMILY.get(ENUM::FIELD); } \
77 void set##FIELD() { FAMILY.set(ENUM::FIELD); } \
78 void reset##FIELD() { FAMILY.reset(ENUM::FIELD); }
79
80#define BOOL_BIT_1(FAMILY, ENUM, FIELD, F1) \
81 bool get##FIELD() const { return FAMILY.get(ENUM::FIELD); } \
82 void set##FIELD() { \
83 FAMILY.set(ENUM::FIELD); \
84 set##F1(); \
85 } \
86 void reset##FIELD() { FAMILY.reset(ENUM::FIELD); }
87
88#define BOOL_BIT_2(FAMILY, ENUM, FIELD, F1, F2) \
89 bool get##FIELD() const { return FAMILY.get(ENUM::FIELD); } \
90 void set##FIELD() { \
91 FAMILY.set(ENUM::FIELD); \
92 set##F1(); \
93 set##F2(); \
94 } \
95 void reset##FIELD() { FAMILY.reset(ENUM::FIELD); }
96
97#define BOOL_BIT_3(FAMILY, ENUM, FIELD, F1, F2, F3) \
98 bool get##FIELD() const { return FAMILY.get(ENUM::FIELD); } \
99 void set##FIELD() { \
100 FAMILY.set(ENUM::FIELD); \
101 set##F1(); \
102 set##F2(); \
103 set##F3(); \
104 } \
105 void reset##FIELD() { FAMILY.reset(ENUM::FIELD); }
106
107
108#define PROPERTY(ENUM, FIELD) BOOL_BIT(Properties, ENUM, FIELD)
109#define PROPERTY_1(ENUM, FIELD, F1) BOOL_BIT_1(Properties, ENUM, FIELD, F1)
110#define PROPERTY_2(ENUM, FIELD, F1, F2) \
111 BOOL_BIT_2(Properties, ENUM, FIELD, F1, F2)
112#define PROPERTY_3(ENUM, FIELD, F1, F2, F3) \
113 BOOL_BIT_3(Properties, ENUM, FIELD, F1, F2, F3)
114
115
116#define KIND(ENUM, FIELD) BOOL_BIT(Kinds, ENUM, FIELD)
117#define KIND_1(ENUM, FIELD, F1) BOOL_BIT_1(Kinds, ENUM, FIELD, F1)
118#define KIND_2(ENUM, FIELD, F1, F2) BOOL_BIT_2(Kinds, ENUM, FIELD, F1, F2)
119#define KIND_3(ENUM, FIELD, F1, F2, F3) \
120 BOOL_BIT_3(Kinds, ENUM, FIELD, F1, F2, F3)
121
124 bool Upper = false) {
126}
127
128
135
136
140
141
142template <typename... Args>
144 const auto List = {First, Others...};
145 std::stringstream Stream;
146 size_t Size = 0;
148 Stream << (Size ? " " : "") << Item.str();
149 Size = Item.size();
150 }
151 Stream << (Size ? " " : "");
152 return Stream.str();
153}
154
155
156template <typename MapType, typename KeyType, typename ValueType>
160
161
162template <typename FirstKeyType, typename SecondKeyType, typename ValueType>
164 static_assert(std::is_pointer::value,
165 "ValueType must be a pointer.");
166 using LVSecondMapType = std::map<SecondKeyType, ValueType>;
167 using LVFirstMapType =
168 std::map<FirstKeyType, std::unique_ptr>;
169 using LVAuxMapType = std::map<SecondKeyType, FirstKeyType>;
170 using LVValueTypes = std::vector;
171 LVFirstMapType FirstMap;
172 LVAuxMapType AuxMap;
173
174public:
176 typename LVFirstMapType::iterator FirstIter = FirstMap.find(FirstKey);
177 if (FirstIter == FirstMap.end()) {
178 auto SecondMapSP = std::make_unique();
179 SecondMapSP->emplace(SecondKey, Value);
180 FirstMap.emplace(FirstKey, std::move(SecondMapSP));
181 } else {
182 LVSecondMapType *SecondMap = FirstIter->second.get();
183 if (SecondMap->find(SecondKey) == SecondMap->end())
184 SecondMap->emplace(SecondKey, Value);
185 }
186
187 typename LVAuxMapType::iterator AuxIter = AuxMap.find(SecondKey);
188 if (AuxIter == AuxMap.end()) {
189 AuxMap.emplace(SecondKey, FirstKey);
190 }
191 }
192
193 LVSecondMapType *findMap(FirstKeyType FirstKey) const {
194 typename LVFirstMapType::const_iterator FirstIter = FirstMap.find(FirstKey);
195 if (FirstIter == FirstMap.end())
196 return nullptr;
197
198 return FirstIter->second.get();
199 }
200
201 ValueType find(FirstKeyType FirstKey, SecondKeyType SecondKey) const {
202 LVSecondMapType *SecondMap = findMap(FirstKey);
203 if (!SecondMap)
204 return nullptr;
205
206 typename LVSecondMapType::const_iterator SecondIter =
207 SecondMap->find(SecondKey);
208 return (SecondIter != SecondMap->end()) ? SecondIter->second : nullptr;
209 }
210
212 typename LVAuxMapType::const_iterator AuxIter = AuxMap.find(SecondKey);
213 if (AuxIter == AuxMap.end())
214 return nullptr;
215 return find(AuxIter->second, SecondKey);
216 }
217
218
219 LVValueTypes find() const {
220 LVValueTypes Values;
221 if (FirstMap.empty())
222 return Values;
223 for (typename LVFirstMapType::const_reference FirstEntry : FirstMap) {
224 LVSecondMapType &SecondMap = *FirstEntry.second;
225 for (typename LVSecondMapType::const_reference SecondEntry : SecondMap)
226 Values.push_back(SecondEntry.second);
227 }
228 return Values;
229 }
230};
231
232
235
239
243
247
248
249
250
251
256
257
258
259
260
261
262
263
264
265
266
267
268
269
271
272}
273}
274
275#endif
This is a helper class used for format_hex() and format_decimal().
StringRef - Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
Definition LVSupport.h:163
void add(FirstKeyType FirstKey, SecondKeyType SecondKey, ValueType Value)
Definition LVSupport.h:175
LVValueTypes find() const
Definition LVSupport.h:219
LVSecondMapType * findMap(FirstKeyType FirstKey) const
Definition LVSupport.h:193
ValueType find(FirstKeyType FirstKey, SecondKeyType SecondKey) const
Definition LVSupport.h:201
ValueType find(SecondKeyType SecondKey) const
Definition LVSupport.h:211
void reset(T Idx)
Definition LVSupport.h:56
void set(T Idx)
Definition LVSupport.h:50
bool get(T Idx) const
Definition LVSupport.h:62
A raw_ostream that writes to an std::string.
const int HEX_WIDTH
Definition LVSupport.h:122
FormattedNumber hexValue(uint64_t N, unsigned Width=HEX_WIDTH, bool Upper=false)
Definition LVSupport.h:123
std::string hexString(uint64_t Value, size_t Width=HEX_WIDTH)
Definition LVSupport.h:129
std::string formattedNames(StringRef Name1, StringRef Name2)
Definition LVSupport.h:244
LLVM_ABI LVStringPool & getStringPool()
std::string formattedKind(StringRef Kind)
Definition LVSupport.h:236
uint16_t getCodeViewOperationCode(uint8_t Code)
Definition LVSupport.h:270
void addItem(MapType *Map, KeyType Key, ValueType Value)
Definition LVSupport.h:157
std::string hexSquareString(uint64_t Value)
Definition LVSupport.h:137
LLVM_ABI LVStringRefs getAllLexicalComponents(StringRef Name)
std::vector< StringRef > LVStringRefs
Definition LVSupport.h:35
LLVM_ABI std::string transformPath(StringRef Path)
LLVM_ABI LVLexicalComponent getInnerComponent(StringRef Name)
std::string formattedName(StringRef Name)
Definition LVSupport.h:240
std::tuple< StringRef, StringRef > LVLexicalComponent
Definition LVSupport.h:36
LLVM_ABI std::string flattenedFilePath(StringRef Path)
std::tuple< LVStringRefs::size_type, LVStringRefs::size_type > LVLexicalIndex
Definition LVSupport.h:37
std::string formatAttributes(const StringRef First, Args... Others)
Definition LVSupport.h:143
LLVM_ABI std::string getScopedName(const LVStringRefs &Components, StringRef BaseName={})
This is an optimization pass for GlobalISel generic memory operations.
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
PointerUnion< const Value *, const PseudoSourceValue * > ValueType