LLVM: lib/Target/DirectX/DXILWriter/DXILValueEnumerator.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef LLVM_DXILWRITER_VALUEENUMERATOR_H
15#define LLVM_DXILWRITER_VALUEENUMERATOR_H
16
22#include
23#include
24#include
25#include
26
27namespace llvm {
28
43
44namespace dxil {
45
47public:
49
50
51 using ValueList = std::vector<std::pair<const Value *, unsigned>>;
52
53
54
56
58
59private:
61 TypeMapType TypeMap;
63
65 ValueMapType ValueMap;
67
69 ComdatSetType Comdats;
70
71 std::vector<const Metadata *> MDs;
72 std::vector<const Metadata *> FunctionMDs;
73
74
75 struct MDIndex {
76 unsigned F = 0;
77 unsigned ID = 0;
78
79 MDIndex() = default;
80 explicit MDIndex(unsigned F) : F(F) {}
81
82
83 bool hasDifferentFunction(unsigned NewF) const { return F && F != NewF; }
84
85
87 assert(ID && "Expected non-zero ID");
88 assert(ID <= MDs.size() && "Expected valid ID");
89 return MDs[ID - 1];
90 }
91 };
92
94 MetadataMapType MetadataMap;
95
96
97 struct MDRange {
98 unsigned First = 0;
99 unsigned Last = 0;
100
101
102 unsigned NumStrings = 0;
103
104 MDRange() = default;
106 };
107 SmallDenseMap<unsigned, MDRange, 1> FunctionMDInfo;
108
109 using AttributeGroupMapType = DenseMap<IndexAndAttrSet, unsigned>;
110 AttributeGroupMapType AttributeGroupMap;
111 std::vector AttributeGroups;
112
113 using AttributeListMapType = DenseMap<AttributeList, unsigned>;
114 AttributeListMapType AttributeListMap;
115 std::vector AttributeLists;
116
117
118
119 mutable DenseMap<const BasicBlock *, unsigned> GlobalBasicBlockIDs;
120
121 using InstructionMapType = DenseMap<const Instruction *, unsigned>;
122 InstructionMapType InstructionMap;
123 unsigned InstructionCount;
124
125
126
127 std::vector<const BasicBlock *> BasicBlocks;
128
129
130
131 unsigned NumModuleValues;
132
133
134
135 unsigned NumModuleMDs = 0;
136 unsigned NumMDStrings = 0;
137
138 unsigned FirstFuncConstantID;
139 unsigned FirstInstID;
140
141public:
145
147 void print(raw_ostream &OS, const ValueMapType &Map, const char *Name) const;
149 const char *Name) const;
150
152
155 assert(ID != 0 && "Metadata not in slotcalculator!");
156 return ID - 1;
157 }
158
160 return MetadataMap.lookup(MD).ID;
161 }
162
163 unsigned numMDs() const { return MDs.size(); }
164
167 assert(I != TypeMap.end() && "Type not in ValueEnumerator!");
168 return I->second - 1;
169 }
170
173
175 if (PAL.isEmpty())
176 return 0;
178 assert(I != AttributeListMap.end() && "Attribute not in ValueEnumerator!");
179 return I->second;
180 }
181
183 if (!Group.second.hasAttributes())
184 return 0;
186 assert(I != AttributeGroupMap.end() && "Attribute not in ValueEnumerator!");
187 return I->second;
188 }
189
190
191
193 Start = FirstFuncConstantID;
194 End = FirstInstID;
195 }
196
198
199
200 bool hasMDs() const { return NumModuleMDs < MDs.size(); }
201
202
204 return ArrayRef(MDs).slice(NumModuleMDs, NumMDStrings);
205 }
206
207
209 return ArrayRef(MDs).slice(NumModuleMDs).slice(NumMDStrings);
210 }
211
213
215 return BasicBlocks;
216 }
217
219 return AttributeLists;
220 }
221
223 return AttributeGroups;
224 }
225
226 const ComdatSetType &getComdats() const { return Comdats; }
228
229
230
231
233
234
235
237
240
242
243private:
244
245
246
247
248
249 void organizeMetadata();
250
251
253
254
255
256
257
258 void incorporateFunctionMetadata(const Function &F);
259
260
261
262
263
264
265
266
267 const MDNode *enumerateMetadataImpl(unsigned F, const Metadata *MD);
268
269 unsigned getMetadataFunctionID(const Function *F) const;
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
287 void EnumerateMetadata(unsigned F, const Metadata *MD);
288
289
290 void EnumerateFunctionLocalMetadata(const Function &F,
293 void EnumerateFunctionLocalListMetadata(const Function &F,
295 void EnumerateFunctionLocalListMetadata(unsigned F, const DIArgList *Arglist);
296 void EnumerateNamedMDNode(const NamedMDNode *NMD);
297 void EnumerateValue(const Value *V);
298 void EnumerateOperandType(const Value *V);
299 void EnumerateAttributes(AttributeList PAL);
300
302 void EnumerateNamedMetadata(const Module &M);
303};
304
305}
306}
307
308#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file contains the simple types necessary to represent the attributes associated with functions a...
This file defines the DenseMap class.
Machine Check Debug Module
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
LLVM Basic Block Representation.
List of ValueAsMetadata, to be used as an argument to a dbg.value intrinsic.
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT, true > const_iterator
A Module instance is used to store all the information related to an LLVM module.
The instances of the Type class are immutable: once they are created, they are never changed.
UniqueVector - This class produces a sequential ID number (base 1) for each unique entry that is adde...
This class provides a symbol table of name/value pairs.
LLVM Value Representation.
ArrayRef< const Metadata * > getNonMDStrings() const
Get the non-MDString metadata for this block.
Definition DXILValueEnumerator.h:208
unsigned getValueID(const Value *V) const
std::pair< unsigned, AttributeSet > IndexAndAttrSet
Attribute groups as encoded in bitcode are almost AttributeSets, but they include the AttributeList i...
Definition DXILValueEnumerator.h:55
void setInstructionID(const Instruction *I)
void EnumerateType(Type *T)
unsigned getMetadataOrNullID(const Metadata *MD) const
Definition DXILValueEnumerator.h:159
ValueEnumerator(const Module &M, Type *PrefixType)
const std::vector< IndexAndAttrSet > & getAttributeGroups() const
Definition DXILValueEnumerator.h:222
unsigned getComdatID(const Comdat *C) const
std::vector< std::pair< const Value *, unsigned > > ValueList
Definition DXILValueEnumerator.h:51
ArrayRef< const Metadata * > getMDStrings() const
Get the MDString metadata for this block.
Definition DXILValueEnumerator.h:203
bool hasMDs() const
Check whether the current block has any metadata to emit.
Definition DXILValueEnumerator.h:200
uint64_t computeBitsRequiredForTypeIndices() const
const ComdatSetType & getComdats() const
Definition DXILValueEnumerator.h:226
unsigned getAttributeListID(AttributeList PAL) const
Definition DXILValueEnumerator.h:174
unsigned getMetadataID(const Metadata *MD) const
Definition DXILValueEnumerator.h:153
ValueEnumerator & operator=(const ValueEnumerator &)=delete
void print(raw_ostream &OS, const MetadataMapType &Map, const char *Name) const
const TypeList & getTypes() const
Definition DXILValueEnumerator.h:212
const std::vector< AttributeList > & getAttributeLists() const
Definition DXILValueEnumerator.h:218
void print(raw_ostream &OS, const ValueMapType &Map, const char *Name) const
std::vector< Type * > TypeList
Definition DXILValueEnumerator.h:48
void incorporateFunction(const Function &F)
incorporateFunction/purgeFunction - If you'd like to deal with a function, use these two methods to g...
unsigned getTypeID(Type *T) const
Definition DXILValueEnumerator.h:165
unsigned getInstructionID(const Instruction *I) const
const ValueList & getValues() const
Definition DXILValueEnumerator.h:197
ValueEnumerator(const ValueEnumerator &)=delete
unsigned getGlobalBasicBlockID(const BasicBlock *BB) const
getGlobalBasicBlockID - This returns the function-specific ID for the specified basic block.
UseListOrderStack UseListOrders
Definition DXILValueEnumerator.h:57
void getFunctionConstantRange(unsigned &Start, unsigned &End) const
getFunctionConstantRange - Return the range of values that corresponds to function-local constants.
Definition DXILValueEnumerator.h:192
const std::vector< const BasicBlock * > & getBasicBlocks() const
Definition DXILValueEnumerator.h:214
unsigned getAttributeGroupID(IndexAndAttrSet Group) const
Definition DXILValueEnumerator.h:182
unsigned numMDs() const
Definition DXILValueEnumerator.h:163
This class implements an extremely fast bulk output stream that can only output to a stream.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
std::vector< UseListOrder > UseListOrderStack
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
ArrayRef(const T &OneElt) -> ArrayRef< T >