13#ifndef LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSUPPORT_H
14#define LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSUPPORT_H
30namespace logicalview {
38 std::tuple<LVStringRefs::size_type, LVStringRefs::size_type>;
42 static constexpr unsigned N_PROPS =
static_cast<unsigned>(T::LastEntry);
45 std::conditional_t<(N_PROPS > 32), std::bitset<N_PROPS>,
uint32_t> Bits{};
51 if constexpr (std::is_same_v<
decltype(Bits),
uint32_t>)
52 Bits |= 1 <<
static_cast<unsigned>(
Idx);
54 Bits.set(
static_cast<unsigned>(
Idx));
57 if constexpr (std::is_same_v<
decltype(Bits),
uint32_t>)
58 Bits &= ~(1 <<
static_cast<unsigned>(
Idx));
60 Bits.reset(
static_cast<unsigned>(
Idx));
63 if constexpr (std::is_same_v<
decltype(Bits),
uint32_t>)
64 return Bits & (1 <<
static_cast<unsigned>(
Idx));
66 return Bits[
static_cast<unsigned>(
Idx)];
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); }
80#define BOOL_BIT_1(FAMILY, ENUM, FIELD, F1) \
81 bool get##FIELD() const { return FAMILY.get(ENUM::FIELD); } \
83 FAMILY.set(ENUM::FIELD); \
86 void reset##FIELD() { FAMILY.reset(ENUM::FIELD); }
88#define BOOL_BIT_2(FAMILY, ENUM, FIELD, F1, F2) \
89 bool get##FIELD() const { return FAMILY.get(ENUM::FIELD); } \
91 FAMILY.set(ENUM::FIELD); \
95 void reset##FIELD() { FAMILY.reset(ENUM::FIELD); }
97#define BOOL_BIT_3(FAMILY, ENUM, FIELD, F1, F2, F3) \
98 bool get##FIELD() const { return FAMILY.get(ENUM::FIELD); } \
100 FAMILY.set(ENUM::FIELD); \
105 void reset##FIELD() { FAMILY.reset(ENUM::FIELD); }
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)
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)
124 bool Upper =
false) {
142template <
typename... Args>
145 std::stringstream Stream;
148 Stream << (
Size ?
" " :
"") << Item.str();
151 Stream << (
Size ?
" " :
"");
156template <
typename MapType,
typename KeyType,
typename ValueType>
158 (*Map)[Key].push_back(
Value);
162template <
typename FirstKeyType,
typename SecondKeyType,
typename ValueType>
164 static_assert(std::is_pointer<ValueType>::value,
165 "ValueType must be a pointer.");
166 using LVSecondMapType = std::map<SecondKeyType, ValueType>;
167 using LVFirstMapType =
168 std::map<FirstKeyType, std::unique_ptr<LVSecondMapType>>;
169 using LVAuxMapType = std::map<SecondKeyType, FirstKeyType>;
170 using LVValueTypes = std::vector<ValueType>;
171 LVFirstMapType FirstMap;
176 typename LVFirstMapType::iterator FirstIter = FirstMap.find(FirstKey);
177 if (FirstIter == FirstMap.end()) {
178 auto SecondMapSP = std::make_unique<LVSecondMapType>();
179 SecondMapSP->emplace(SecondKey,
Value);
180 FirstMap.emplace(FirstKey, std::move(SecondMapSP));
182 LVSecondMapType *SecondMap = FirstIter->second.get();
183 if (SecondMap->find(SecondKey) == SecondMap->end())
184 SecondMap->emplace(SecondKey,
Value);
187 typename LVAuxMapType::iterator AuxIter = AuxMap.find(SecondKey);
188 if (AuxIter == AuxMap.end()) {
189 AuxMap.emplace(SecondKey, FirstKey);
193 LVSecondMapType *
findMap(FirstKeyType FirstKey)
const {
194 typename LVFirstMapType::const_iterator FirstIter = FirstMap.find(FirstKey);
195 if (FirstIter == FirstMap.end())
198 return FirstIter->second.get();
202 LVSecondMapType *SecondMap =
findMap(FirstKey);
206 typename LVSecondMapType::const_iterator SecondIter =
207 SecondMap->find(SecondKey);
208 return (SecondIter != SecondMap->end()) ? SecondIter->second :
nullptr;
212 typename LVAuxMapType::const_iterator AuxIter = AuxMap.find(SecondKey);
213 if (AuxIter == AuxMap.end())
215 return find(AuxIter->second, SecondKey);
221 if (FirstMap.empty())
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);
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
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.
void add(FirstKeyType FirstKey, SecondKeyType SecondKey, ValueType Value)
LVValueTypes find() const
LVSecondMapType * findMap(FirstKeyType FirstKey) const
ValueType find(FirstKeyType FirstKey, SecondKeyType SecondKey) const
ValueType find(SecondKeyType SecondKey) const
A raw_ostream that writes to an std::string.
FormattedNumber hexValue(uint64_t N, unsigned Width=HEX_WIDTH, bool Upper=false)
std::string hexString(uint64_t Value, size_t Width=HEX_WIDTH)
std::string formattedNames(StringRef Name1, StringRef Name2)
std::vector< StringRef > LVStringRefs
LLVM_ABI LVStringPool & getStringPool()
std::tuple< StringRef, StringRef > LVLexicalComponent
std::string formattedKind(StringRef Kind)
uint16_t getCodeViewOperationCode(uint8_t Code)
void addItem(MapType *Map, KeyType Key, ValueType Value)
std::string hexSquareString(uint64_t Value)
LLVM_ABI LVStringRefs getAllLexicalComponents(StringRef Name)
LLVM_ABI std::string transformPath(StringRef Path)
LLVM_ABI LVLexicalComponent getInnerComponent(StringRef Name)
std::string formattedName(StringRef Name)
LLVM_ABI std::string flattenedFilePath(StringRef Path)
std::string formatAttributes(const StringRef First, Args... Others)
LLVM_ABI std::string getScopedName(const LVStringRefs &Components, StringRef BaseName={})
std::tuple< LVStringRefs::size_type, LVStringRefs::size_type > LVLexicalIndex
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.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.