LLVM 23.0.0git
DXILValueEnumerator.cpp
Go to the documentation of this file.
1//===- ValueEnumerator.cpp - Number values and types for bitcode writer ---===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the ValueEnumerator class.
10// Forked from lib/Bitcode/Writer
11//
12//===----------------------------------------------------------------------===//
13
14#include "DXILValueEnumerator.h"
17#include "llvm/Config/llvm-config.h"
18#include "llvm/IR/Argument.h"
19#include "llvm/IR/BasicBlock.h"
20#include "llvm/IR/Constant.h"
23#include "llvm/IR/Function.h"
24#include "llvm/IR/GlobalAlias.h"
25#include "llvm/IR/GlobalIFunc.h"
27#include "llvm/IR/GlobalValue.h"
29#include "llvm/IR/Instruction.h"
31#include "llvm/IR/Metadata.h"
32#include "llvm/IR/Module.h"
33#include "llvm/IR/Operator.h"
34#include "llvm/IR/Type.h"
36#include "llvm/IR/Use.h"
37#include "llvm/IR/User.h"
38#include "llvm/IR/Value.h"
42#include "llvm/Support/Debug.h"
45#include <algorithm>
46#include <cstddef>
47#include <iterator>
48#include <tuple>
49
50using namespace llvm;
51using namespace llvm::dxil;
52
53namespace {
54
55struct OrderMap {
56 DenseMap<const Value *, std::pair<unsigned, bool>> IDs;
57 unsigned LastGlobalConstantID = 0;
58 unsigned LastGlobalValueID = 0;
59
60 OrderMap() = default;
61
62 bool isGlobalConstant(unsigned ID) const {
63 return ID <= LastGlobalConstantID;
64 }
65
66 bool isGlobalValue(unsigned ID) const {
67 return ID <= LastGlobalValueID && !isGlobalConstant(ID);
68 }
69
70 unsigned size() const { return IDs.size(); }
71 std::pair<unsigned, bool> &operator[](const Value *V) { return IDs[V]; }
72
73 std::pair<unsigned, bool> lookup(const Value *V) const {
74 return IDs.lookup(V);
75 }
76
77 void index(const Value *V) {
78 // Explicitly sequence get-size and insert-value operations to avoid UB.
79 unsigned ID = IDs.size() + 1;
80 IDs[V].first = ID;
81 }
82};
83
84} // end anonymous namespace
85
86static void orderValue(const Value *V, OrderMap &OM) {
87 if (OM.lookup(V).first)
88 return;
89
90 if (const Constant *C = dyn_cast<Constant>(V)) {
91 if (C->getNumOperands() && !isa<GlobalValue>(C)) {
92 for (const Value *Op : C->operands())
94 orderValue(Op, OM);
95 if (auto *CE = dyn_cast<ConstantExpr>(C))
96 if (CE->getOpcode() == Instruction::ShuffleVector)
97 orderValue(CE->getShuffleMaskForBitcode(), OM);
98 }
99 }
100
101 // Note: we cannot cache this lookup above, since inserting into the map
102 // changes the map's size, and thus affects the other IDs.
103 OM.index(V);
104}
105
106static OrderMap orderModule(const Module &M, ValueEnumerator &VE) {
107 // This needs to match the order used by ValueEnumerator::ValueEnumerator()
108 // and ValueEnumerator::incorporateFunction().
109 OrderMap OM;
110
111 // In the reader, initializers of GlobalValues are set *after* all the
112 // globals have been read. Rather than awkwardly modeling this behaviour
113 // directly in predictValueUseListOrderImpl(), just assign IDs to
114 // initializers of GlobalValues before GlobalValues themselves to model this
115 // implicitly.
116 for (const GlobalVariable &G : M.globals())
117 if (G.hasInitializer())
118 if (!isa<GlobalValue>(G.getInitializer()))
119 orderValue(G.getInitializer(), OM);
120 for (const GlobalAlias &A : M.aliases())
121 if (!isa<GlobalValue>(A.getAliasee()))
122 orderValue(A.getAliasee(), OM);
123 for (const GlobalIFunc &I : M.ifuncs())
124 if (!isa<GlobalValue>(I.getResolver()))
125 orderValue(I.getResolver(), OM);
126 for (const Function &F : M) {
127 for (const Use &U : F.operands())
128 if (!isa<GlobalValue>(U.get()))
129 orderValue(U.get(), OM);
130 }
131
132 // As constants used in metadata operands are emitted as module-level
133 // constants, we must order them before other operands. Also, we must order
134 // these before global values, as these will be read before setting the
135 // global values' initializers. The latter matters for constants which have
136 // uses towards other constants that are used as initializers.
137 auto orderConstantValue = [&OM](const Value *V) {
138 if ((isa<Constant>(V) && !isa<GlobalValue>(V)) || isa<InlineAsm>(V))
139 orderValue(V, OM);
140 };
141 for (const Function &OrigF : M) {
142 const Function &F = VE.getDXILFunction(OrigF);
143 if (F.isDeclaration())
144 continue;
145 for (const BasicBlock &BB : F) {
146 for (const Instruction &OrigI : BB) {
147 const Instruction &I = VE.getDXILInstruction(OrigI);
148 for (const Value *V : I.operands()) {
149 if (const auto *MAV = dyn_cast<MetadataAsValue>(V)) {
150 if (const auto *VAM =
151 dyn_cast<ValueAsMetadata>(MAV->getMetadata())) {
152 orderConstantValue(VAM->getValue());
153 } else if (const auto *AL =
154 dyn_cast<DIArgList>(MAV->getMetadata())) {
155 for (const auto *VAM : AL->getArgs())
156 orderConstantValue(VAM->getValue());
157 }
158 }
159 }
160 }
161 }
162 }
163 OM.LastGlobalConstantID = OM.size();
164
165 // Initializers of GlobalValues are processed in
166 // BitcodeReader::ResolveGlobalAndAliasInits(). Match the order there rather
167 // than ValueEnumerator, and match the code in predictValueUseListOrderImpl()
168 // by giving IDs in reverse order.
169 //
170 // Since GlobalValues never reference each other directly (just through
171 // initializers), their relative IDs only matter for determining order of
172 // uses in their initializers.
173 for (const Function &OrigF : M) {
174 const Function &F = VE.getDXILFunction(OrigF);
175 orderValue(&F, OM);
176 }
177 for (const GlobalAlias &A : M.aliases())
178 orderValue(&A, OM);
179 for (const GlobalIFunc &I : M.ifuncs())
180 orderValue(&I, OM);
181 for (const GlobalVariable &G : M.globals())
182 orderValue(&G, OM);
183 OM.LastGlobalValueID = OM.size();
184
185 for (const Function &OrigF : M) {
186 const Function &F = VE.getDXILFunction(OrigF);
187 if (F.isDeclaration())
188 continue;
189 // Here we need to match the union of ValueEnumerator::incorporateFunction()
190 // and WriteFunction(). Basic blocks are implicitly declared before
191 // anything else (by declaring their size).
192 for (const BasicBlock &BB : F)
193 orderValue(&BB, OM);
194 for (const Argument &A : F.args())
195 orderValue(&A, OM);
196 for (const BasicBlock &BB : F)
197 for (const Instruction &OrigI : BB) {
198 const Instruction &I = VE.getDXILInstruction(OrigI);
199 for (const Value *Op : I.operands())
200 if ((isa<Constant>(*Op) && !isa<GlobalValue>(*Op)) ||
202 orderValue(Op, OM);
203 if (auto *SVI = dyn_cast<ShuffleVectorInst>(&I))
204 orderValue(SVI->getShuffleMaskForBitcode(), OM);
205 if (auto *SI = dyn_cast<SwitchInst>(&I)) {
206 for (const auto &Case : SI->cases())
207 orderValue(Case.getCaseValue(), OM);
208 }
209 }
210 for (const BasicBlock &BB : F) {
211 for (const Instruction &OrigI : BB) {
212 const Instruction &I = VE.getDXILInstruction(OrigI);
213 orderValue(&I, OM);
214 }
215 }
216 }
217 return OM;
218}
219
220static void predictValueUseListOrderImpl(const Value *V, const Function *F,
221 unsigned ID, const OrderMap &OM,
222 UseListOrderStack &Stack) {
223 // Predict use-list order for this one.
224 using Entry = std::pair<const Use *, unsigned>;
226 for (const Use &U : V->uses())
227 // Check if this user will be serialized.
228 if (OM.lookup(U.getUser()).first)
229 List.push_back(std::make_pair(&U, List.size()));
230
231 if (List.size() < 2)
232 // We may have lost some users.
233 return;
234
235 bool IsGlobalValue = OM.isGlobalValue(ID);
236 llvm::sort(List, [&](const Entry &L, const Entry &R) {
237 const Use *LU = L.first;
238 const Use *RU = R.first;
239 if (LU == RU)
240 return false;
241
242 auto LID = OM.lookup(LU->getUser()).first;
243 auto RID = OM.lookup(RU->getUser()).first;
244
245 // Global values are processed in reverse order.
246 //
247 // Moreover, initializers of GlobalValues are set *after* all the globals
248 // have been read (despite having earlier IDs). Rather than awkwardly
249 // modeling this behaviour here, orderModule() has assigned IDs to
250 // initializers of GlobalValues before GlobalValues themselves.
251 if (OM.isGlobalValue(LID) && OM.isGlobalValue(RID)) {
252 if (LID == RID)
253 return LU->getOperandNo() > RU->getOperandNo();
254 return LID < RID;
255 }
256
257 // If ID is 4, then expect: 7 6 5 1 2 3.
258 if (LID < RID) {
259 if (RID <= ID)
260 if (!IsGlobalValue) // GlobalValue uses don't get reversed.
261 return true;
262 return false;
263 }
264 if (RID < LID) {
265 if (LID <= ID)
266 if (!IsGlobalValue) // GlobalValue uses don't get reversed.
267 return false;
268 return true;
269 }
270
271 // LID and RID are equal, so we have different operands of the same user.
272 // Assume operands are added in order for all instructions.
273 if (LID <= ID)
274 if (!IsGlobalValue) // GlobalValue uses don't get reversed.
275 return LU->getOperandNo() < RU->getOperandNo();
276 return LU->getOperandNo() > RU->getOperandNo();
277 });
278
280 // Order is already correct.
281 return;
282
283 // Store the shuffle.
284 Stack.emplace_back(V, F, List.size());
285 assert(List.size() == Stack.back().Shuffle.size() && "Wrong size");
286 for (size_t I = 0, E = List.size(); I != E; ++I)
287 Stack.back().Shuffle[I] = List[I].second;
288}
289
290static void predictValueUseListOrder(const Value *V, const Function *F,
291 OrderMap &OM, UseListOrderStack &Stack) {
292 auto &IDPair = OM[V];
293 assert(IDPair.first && "Unmapped value");
294 if (IDPair.second)
295 // Already predicted.
296 return;
297
298 // Do the actual prediction.
299 IDPair.second = true;
300 if (!V->use_empty() && std::next(V->use_begin()) != V->use_end())
301 predictValueUseListOrderImpl(V, F, IDPair.first, OM, Stack);
302
303 // Recursive descent into constants.
304 if (const Constant *C = dyn_cast<Constant>(V)) {
305 if (C->getNumOperands()) { // Visit GlobalValues.
306 for (const Value *Op : C->operands())
307 if (isa<Constant>(Op)) // Visit GlobalValues.
308 predictValueUseListOrder(Op, F, OM, Stack);
309 if (auto *CE = dyn_cast<ConstantExpr>(C))
310 if (CE->getOpcode() == Instruction::ShuffleVector)
311 predictValueUseListOrder(CE->getShuffleMaskForBitcode(), F, OM,
312 Stack);
313 }
314 }
315}
316
318 OrderMap OM = orderModule(M, VE);
319
320 // Use-list orders need to be serialized after all the users have been added
321 // to a value, or else the shuffles will be incomplete. Store them per
322 // function in a stack.
323 //
324 // Aside from function order, the order of values doesn't matter much here.
325 UseListOrderStack Stack;
326
327 // We want to visit the functions backward now so we can list function-local
328 // constants in the last Function they're used in. Module-level constants
329 // have already been visited above.
330 for (const Function &F : llvm::reverse(M)) {
331 if (F.isDeclaration())
332 continue;
333 for (const BasicBlock &BB : F)
334 predictValueUseListOrder(&BB, &F, OM, Stack);
335 for (const Argument &A : F.args())
336 predictValueUseListOrder(&A, &F, OM, Stack);
337 for (const BasicBlock &BB : F)
338 for (const Instruction &OrigI : BB) {
339 const Instruction &I = VE.getDXILInstruction(OrigI);
340 for (const Value *Op : I.operands())
341 if (isa<Constant>(*Op) || isa<InlineAsm>(*Op)) // Visit GlobalValues.
342 predictValueUseListOrder(Op, &F, OM, Stack);
343 if (auto *SVI = dyn_cast<ShuffleVectorInst>(&I))
344 predictValueUseListOrder(SVI->getShuffleMaskForBitcode(), &F, OM,
345 Stack);
346 }
347 for (const BasicBlock &BB : F) {
348 for (const Instruction &OrigI : BB) {
349 const Instruction &I = VE.getDXILInstruction(OrigI);
350 predictValueUseListOrder(&I, &F, OM, Stack);
351 }
352 }
353 }
354
355 // Visit globals last, since the module-level use-list block will be seen
356 // before the function bodies are processed.
357 for (const GlobalVariable &G : M.globals())
358 predictValueUseListOrder(&G, nullptr, OM, Stack);
359 for (const Function &OrigF : M) {
360 const Function &F = VE.getDXILFunction(OrigF);
361 predictValueUseListOrder(&F, nullptr, OM, Stack);
362 }
363 for (const GlobalAlias &A : M.aliases())
364 predictValueUseListOrder(&A, nullptr, OM, Stack);
365 for (const GlobalIFunc &I : M.ifuncs())
366 predictValueUseListOrder(&I, nullptr, OM, Stack);
367 for (const GlobalVariable &G : M.globals())
368 if (G.hasInitializer())
369 predictValueUseListOrder(G.getInitializer(), nullptr, OM, Stack);
370 for (const GlobalAlias &A : M.aliases())
371 predictValueUseListOrder(A.getAliasee(), nullptr, OM, Stack);
372 for (const GlobalIFunc &I : M.ifuncs())
373 predictValueUseListOrder(I.getResolver(), nullptr, OM, Stack);
374 for (const Function &F : M) {
375 for (const Use &U : F.operands())
376 predictValueUseListOrder(U.get(), nullptr, OM, Stack);
377 }
378
379 return Stack;
380}
381
383 const DXILDebugInfoMap &DebugInfo)
384 : DebugInfo(DebugInfo) {
386
388
389 // Enumerate the global variables.
390 for (const GlobalVariable &GV : M.globals()) {
391 EnumerateValue(&GV);
392 EnumerateType(GV.getValueType());
393 }
394
395 // Enumerate the functions.
396 for (const Function &OrigF : M) {
397 const Function &F = getDXILFunction(OrigF);
398 EnumerateValue(&F);
399 EnumerateType(F.getFunctionType());
401 TypedPointerType::get(F.getFunctionType(), F.getAddressSpace()));
402 EnumerateAttributes(F.getAttributes());
403 }
404
405 // Enumerate the aliases.
406 for (const GlobalAlias &GA : M.aliases()) {
407 EnumerateValue(&GA);
408 EnumerateType(GA.getValueType());
409 }
410
411 // Enumerate the ifuncs.
412 for (const GlobalIFunc &GIF : M.ifuncs()) {
413 EnumerateValue(&GIF);
414 EnumerateType(GIF.getValueType());
415 }
416
417 // Enumerate the global variable initializers and attributes.
418 for (const GlobalVariable &GV : M.globals()) {
419 if (GV.hasInitializer())
420 EnumerateValue(GV.getInitializer());
422 TypedPointerType::get(GV.getValueType(), GV.getAddressSpace()));
423 if (GV.hasAttributes())
424 EnumerateAttributes(GV.getAttributesAsList(AttributeList::FunctionIndex));
425 }
426
427 // Enumerate the aliasees.
428 for (const GlobalAlias &GA : M.aliases())
429 EnumerateValue(GA.getAliasee());
430
431 // Enumerate the ifunc resolvers.
432 for (const GlobalIFunc &GIF : M.ifuncs())
433 EnumerateValue(GIF.getResolver());
434
435 // Enumerate any optional Function data.
436 for (const Function &F : M)
437 for (const Use &U : F.operands())
438 EnumerateValue(U.get());
439
440 // Enumerate the metadata type.
441 //
442 // TODO: Move this to ValueEnumerator::EnumerateOperandType() once bitcode
443 // only encodes the metadata type when it's used as a value.
444 EnumerateType(Type::getMetadataTy(M.getContext()));
445
446 // Insert constants and metadata that are named at module level into the slot
447 // pool so that the module symbol table can refer to them...
448 EnumerateValueSymbolTable(M.getValueSymbolTable());
449 EnumerateNamedMetadata(M);
450
452 for (const GlobalVariable &GV : M.globals()) {
453 MDs.clear();
454 GV.getAllMetadata(MDs);
455 for (const auto &I : MDs)
456 // FIXME: Pass GV to EnumerateMetadata and arrange for the bitcode writer
457 // to write metadata to the global variable's own metadata block
458 // (PR28134).
459 EnumerateMetadata(nullptr, I.second);
460 }
461
462 // Enumerate types used by function bodies and argument lists.
463 for (const Function &F : M) {
464 for (const Argument &A : F.args())
465 EnumerateType(A.getType());
466
467 // Enumerate metadata attached to this function.
468 MDs.clear();
469 F.getAllMetadata(MDs);
470 for (const auto &I : MDs)
471 EnumerateMetadata(F.isDeclaration() ? nullptr : &F, I.second);
472
473 for (const BasicBlock &BB : F)
474 for (const Instruction &OrigI : BB) {
475 const Instruction &I = getDXILInstruction(OrigI);
476 for (const Use &Op : I.operands()) {
477 auto *MD = dyn_cast<MetadataAsValue>(&Op);
478 if (!MD) {
479 EnumerateOperandType(Op);
480 continue;
481 }
482
483 // Local metadata is enumerated during function-incorporation, but
484 // any ConstantAsMetadata arguments in a DIArgList should be examined
485 // now.
486 if (isa<LocalAsMetadata>(MD->getMetadata()))
487 continue;
488 if (auto *AL = dyn_cast<DIArgList>(MD->getMetadata())) {
489 for (auto *VAM : AL->getArgs())
491 EnumerateMetadata(&F, VAM);
492 continue;
493 }
494
495 EnumerateMetadata(&F, MD->getMetadata());
496 }
497 if (auto *SVI = dyn_cast<ShuffleVectorInst>(&I))
498 EnumerateType(SVI->getShuffleMaskForBitcode()->getType());
499 if (auto *GEP = dyn_cast<GetElementPtrInst>(&I))
500 EnumerateType(GEP->getSourceElementType());
501 if (auto *AI = dyn_cast<AllocaInst>(&I))
502 EnumerateType(AI->getAllocatedType());
503 EnumerateType(I.getType());
504 if (const auto *Call = dyn_cast<CallBase>(&I)) {
505 EnumerateAttributes(Call->getAttributes());
506 EnumerateType(Call->getFunctionType());
507 }
508
509 // Enumerate metadata attached with this instruction.
510 MDs.clear();
511 I.getAllMetadataOtherThanDebugLoc(MDs);
512 for (unsigned i = 0, e = MDs.size(); i != e; ++i)
513 EnumerateMetadata(&F, MDs[i].second);
514
515 // Don't enumerate the location directly -- it has a special record
516 // type -- but enumerate its operands.
517 if (DILocation *L = I.getDebugLoc())
518 for (const Metadata *Op : L->operands())
519 EnumerateMetadata(&F, Op);
520 }
521 }
522
523 // Organize metadata ordering.
524 organizeMetadata();
525}
526
527unsigned ValueEnumerator::getInstructionID(const Instruction *Inst) const {
528 InstructionMapType::const_iterator I = InstructionMap.find(Inst);
529 assert(I != InstructionMap.end() && "Instruction is not mapped!");
530 return I->second;
531}
532
533unsigned ValueEnumerator::getComdatID(const Comdat *C) const {
534 unsigned ComdatID = Comdats.idFor(C);
535 assert(ComdatID && "Comdat not found!");
536 return ComdatID;
537}
538
540 InstructionMap[I] = InstructionCount++;
541}
542
543unsigned ValueEnumerator::getValueID(const Value *V) const {
544 if (auto *MD = dyn_cast<MetadataAsValue>(V))
545 return getMetadataID(MD->getMetadata());
546
547 ValueMapType::const_iterator I = ValueMap.find(V);
548 assert(I != ValueMap.end() && "Value not in slotcalculator!");
549 return I->second - 1;
550}
551
552#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
554 print(dbgs(), ValueMap, "Default");
555 dbgs() << '\n';
556 print(dbgs(), MetadataMap, "MetaData");
557 dbgs() << '\n';
558}
559#endif
560
561void ValueEnumerator::print(raw_ostream &OS, const ValueMapType &Map,
562 const char *Name) const {
563 OS << "Map Name: " << Name << "\n";
564 OS << "Size: " << Map.size() << "\n";
565 for (const auto &I : Map) {
566 const Value *V = I.first;
567 if (V->hasName())
568 OS << "Value: " << V->getName() << '\n';
569 else
570 OS << "Value: [null]\n";
571 V->print(OS);
572 OS << '\n';
573
574 if (V->hasUseList()) {
575 OS << " Uses(" << V->getNumUses() << "):";
576 for (const Use &U : V->uses()) {
577 if (&U != &*V->use_begin())
578 OS << ",";
579 if (U->hasName())
580 OS << " " << U->getName();
581 else
582 OS << " [null]";
583 }
584 OS << '\n';
585 }
586
587 OS << '\n';
588 }
589}
590
591void ValueEnumerator::print(raw_ostream &OS, const MetadataMapType &Map,
592 const char *Name) const {
593 OS << "Map Name: " << Name << "\n";
594 OS << "Size: " << Map.size() << "\n";
595 for (const auto &I : Map) {
596 const Metadata *MD = I.first;
597 OS << "Metadata: slot = " << I.second.ID << "\n";
598 OS << "Metadata: function = " << I.second.F << "\n";
599 MD->print(OS);
600 OS << "\n";
601 }
602}
603
604/// EnumerateValueSymbolTable - Insert all of the values in the specified symbol
605/// table into the values table.
606void ValueEnumerator::EnumerateValueSymbolTable(const ValueSymbolTable &VST) {
607 for (ValueSymbolTable::const_iterator VI = VST.begin(), VE = VST.end();
608 VI != VE; ++VI) {
609 const Value *V = VI->getValue();
610 EnumerateValue(&getDXILValue(*V));
611 }
612}
613
614/// Insert all of the values referenced by named metadata in the specified
615/// module.
616void ValueEnumerator::EnumerateNamedMetadata(const Module &M) {
617 for (const auto &I : M.named_metadata())
618 EnumerateNamedMDNode(&I);
619}
620
621void ValueEnumerator::EnumerateNamedMDNode(const NamedMDNode *MD) {
622 for (unsigned i = 0, e = MD->getNumOperands(); i != e; ++i)
623 EnumerateMetadata(nullptr, MD->getOperand(i));
624}
625
626unsigned ValueEnumerator::getMetadataFunctionID(const Function *F) const {
627 return F ? getValueID(F) + 1 : 0;
628}
629
630void ValueEnumerator::EnumerateMetadata(const Function *F, const Metadata *MD) {
631 EnumerateMetadata(getMetadataFunctionID(F), MD);
632}
633
634void ValueEnumerator::EnumerateFunctionLocalMetadata(
635 const Function &F, const LocalAsMetadata *Local) {
636 EnumerateFunctionLocalMetadata(getMetadataFunctionID(&F), Local);
637}
638
639void ValueEnumerator::EnumerateFunctionLocalListMetadata(
640 const Function &F, const DIArgList *ArgList) {
641 EnumerateFunctionLocalListMetadata(getMetadataFunctionID(&F), ArgList);
642}
643
644void ValueEnumerator::dropFunctionFromMetadata(
645 MetadataMapType::value_type &FirstMD) {
647 auto push = [&Worklist](MetadataMapType::value_type &MD) {
648 auto &Entry = MD.second;
649
650 // Nothing to do if this metadata isn't tagged.
651 if (!Entry.F)
652 return;
653
654 // Drop the function tag.
655 Entry.F = 0;
656
657 // If this is has an ID and is an MDNode, then its operands have entries as
658 // well. We need to drop the function from them too.
659 if (Entry.ID)
660 if (auto *N = dyn_cast<MDNode>(MD.first))
661 Worklist.push_back(N);
662 };
663 push(FirstMD);
664 while (!Worklist.empty())
665 for (const Metadata *Op : Worklist.pop_back_val()->operands()) {
666 if (!Op)
667 continue;
668 auto MD = MetadataMap.find(Op);
669 if (MD != MetadataMap.end())
670 push(*MD);
671 }
672}
673
674void ValueEnumerator::EnumerateMetadata(unsigned F, const Metadata *MD) {
675 MD = getDXILMetadata(MD);
676
677 // It's vital for reader efficiency that uniqued subgraphs are done in
678 // post-order; it's expensive when their operands have forward references.
679 // If a distinct node is referenced from a uniqued node, it'll be delayed
680 // until the uniqued subgraph has been completely traversed.
681 SmallVector<const MDNode *, 32> DelayedDistinctNodes;
682
683 // Start by enumerating MD, and then work through its transitive operands in
684 // post-order. This requires a depth-first search.
686 if (const MDNode *N = enumerateMetadataImpl(F, MD))
687 Worklist.push_back(std::make_pair(N, N->op_begin()));
688
689 while (!Worklist.empty()) {
690 const MDNode *N = Worklist.back().first;
691
692 // Enumerate operands until we hit a new node. We need to traverse these
693 // nodes' operands before visiting the rest of N's operands.
694 MDNode::op_iterator I = std::find_if(
695 Worklist.back().second, N->op_end(),
696 [&](const Metadata *MD) { return enumerateMetadataImpl(F, MD); });
697 if (I != N->op_end()) {
698 auto *Op = cast<MDNode>(getDXILMetadata(*I));
699 Worklist.back().second = ++I;
700
701 // Delay traversing Op if it's a distinct node and N is uniqued.
702 if (Op->isDistinct() && !N->isDistinct())
703 DelayedDistinctNodes.push_back(Op);
704 else
705 Worklist.push_back(std::make_pair(Op, Op->op_begin()));
706 continue;
707 }
708
709 if (const Metadata *ExtraMD = DebugInfo.MDExtra.lookup(N)) {
710 if (enumerateMetadataImpl(F, ExtraMD)) {
711 if (const auto *ExtraN = dyn_cast<MDNode>(ExtraMD)) {
712 Worklist.push_back(std::make_pair(ExtraN, ExtraN->op_begin()));
713 continue;
714 }
715 }
716 }
717
718 // All the operands have been visited. Now assign an ID.
719 Worklist.pop_back();
720 MDs.push_back(N);
721 MetadataMap[N].ID = MDs.size();
722
723 // Flush out any delayed distinct nodes; these are all the distinct nodes
724 // that are leaves in last uniqued subgraph.
725 if (Worklist.empty() || Worklist.back().first->isDistinct()) {
726 for (const MDNode *N : DelayedDistinctNodes)
727 Worklist.push_back(std::make_pair(N, N->op_begin()));
728 DelayedDistinctNodes.clear();
729 }
730 }
731}
732
733const MDNode *ValueEnumerator::enumerateMetadataImpl(unsigned F,
734 const Metadata *MD) {
735 MD = getDXILMetadata(MD);
736
737 if (!MD)
738 return nullptr;
739
740 assert(
742 "Invalid metadata kind");
743
744 auto Insertion = MetadataMap.insert(std::make_pair(MD, MDIndex(F)));
745 MDIndex &Entry = Insertion.first->second;
746 if (!Insertion.second) {
747 // Already mapped. If F doesn't match the function tag, drop it.
748 if (Entry.hasDifferentFunction(F))
749 dropFunctionFromMetadata(*Insertion.first);
750 return nullptr;
751 }
752
753 // Don't assign IDs to metadata nodes.
754 if (auto *N = dyn_cast<MDNode>(MD))
755 return N;
756
757 // Save the metadata.
758 MDs.push_back(MD);
759 Entry.ID = MDs.size();
760
761 // Enumerate the constant, if any.
762 if (auto *C = dyn_cast<ConstantAsMetadata>(MD))
763 EnumerateValue(C->getValue());
764
765 return nullptr;
766}
767
768/// EnumerateFunctionLocalMetadata - Incorporate function-local metadata
769/// information reachable from the metadata.
770void ValueEnumerator::EnumerateFunctionLocalMetadata(
771 unsigned F, const LocalAsMetadata *Local) {
772 assert(F && "Expected a function");
773
774 // Check to see if it's already in!
775 MDIndex &Index = MetadataMap[Local];
776 if (Index.ID) {
777 assert(Index.F == F && "Expected the same function");
778 return;
779 }
780
781 MDs.push_back(Local);
782 Index.F = F;
783 Index.ID = MDs.size();
784
785 EnumerateValue(Local->getValue());
786}
787
788/// EnumerateFunctionLocalListMetadata - Incorporate function-local metadata
789/// information reachable from the metadata.
790void ValueEnumerator::EnumerateFunctionLocalListMetadata(
791 unsigned F, const DIArgList *ArgList) {
792 assert(F && "Expected a function");
793
794 // Check to see if it's already in!
795 MDIndex &Index = MetadataMap[ArgList];
796 if (Index.ID) {
797 assert(Index.F == F && "Expected the same function");
798 return;
799 }
800
801 for (ValueAsMetadata *VAM : ArgList->getArgs()) {
802 if (isa<LocalAsMetadata>(VAM)) {
803 assert(MetadataMap.count(VAM) &&
804 "LocalAsMetadata should be enumerated before DIArgList");
805 assert(MetadataMap[VAM].F == F &&
806 "Expected LocalAsMetadata in the same function");
807 } else {
809 "Expected LocalAsMetadata or ConstantAsMetadata");
810 assert(ValueMap.count(VAM->getValue()) &&
811 "Constant should be enumerated beforeDIArgList");
812 EnumerateMetadata(F, VAM);
813 }
814 }
815
816 MDs.push_back(ArgList);
817 Index.F = F;
818 Index.ID = MDs.size();
819}
820
821static unsigned getMetadataTypeOrder(const Metadata *MD) {
822 // Strings are emitted in bulk and must come first.
823 if (isa<MDString>(MD))
824 return 0;
825
826 // ConstantAsMetadata doesn't reference anything. We may as well shuffle it
827 // to the front since we can detect it.
828 auto *N = dyn_cast<MDNode>(MD);
829 if (!N)
830 return 1;
831
832 // The reader is fast forward references for distinct node operands, but slow
833 // when uniqued operands are unresolved.
834 return N->isDistinct() ? 2 : 3;
835}
836
837void ValueEnumerator::organizeMetadata() {
838 assert(MetadataMap.size() == MDs.size() &&
839 "Metadata map and vector out of sync");
840
841 if (MDs.empty())
842 return;
843
844 // Copy out the index information from MetadataMap in order to choose a new
845 // order.
847 Order.reserve(MetadataMap.size());
848 for (const Metadata *MD : MDs)
849 Order.push_back(MetadataMap.lookup(MD));
850
851 // Partition:
852 // - by function, then
853 // - by isa<MDString>
854 // and then sort by the original/current ID. Since the IDs are guaranteed to
855 // be unique, the result of llvm::sort will be deterministic. There's no need
856 // for std::stable_sort.
857 llvm::sort(Order, [this](MDIndex LHS, MDIndex RHS) {
858 return std::make_tuple(LHS.F, getMetadataTypeOrder(LHS.get(MDs)), LHS.ID) <
859 std::make_tuple(RHS.F, getMetadataTypeOrder(RHS.get(MDs)), RHS.ID);
860 });
861
862 // Rebuild MDs, index the metadata ranges for each function in FunctionMDs,
863 // and fix up MetadataMap.
864 std::vector<const Metadata *> OldMDs;
865 MDs.swap(OldMDs);
866 MDs.reserve(OldMDs.size());
867 for (unsigned I = 0, E = Order.size(); I != E && !Order[I].F; ++I) {
868 auto *MD = Order[I].get(OldMDs);
869 MDs.push_back(MD);
870 MetadataMap[MD].ID = I + 1;
871 if (isa<MDString>(MD))
872 ++NumMDStrings;
873 }
874
875 // Return early if there's nothing for the functions.
876 if (MDs.size() == Order.size())
877 return;
878
879 // Build the function metadata ranges.
880 MDRange R;
881 FunctionMDs.reserve(OldMDs.size());
882 unsigned PrevF = 0;
883 for (unsigned I = MDs.size(), E = Order.size(), ID = MDs.size(); I != E;
884 ++I) {
885 unsigned F = Order[I].F;
886 if (!PrevF) {
887 PrevF = F;
888 } else if (PrevF != F) {
889 R.Last = FunctionMDs.size();
890 std::swap(R, FunctionMDInfo[PrevF]);
891 R.First = FunctionMDs.size();
892
893 ID = MDs.size();
894 PrevF = F;
895 }
896
897 auto *MD = Order[I].get(OldMDs);
898 FunctionMDs.push_back(MD);
899 MetadataMap[MD].ID = ++ID;
900 if (isa<MDString>(MD))
901 ++R.NumStrings;
902 }
903 R.Last = FunctionMDs.size();
904 FunctionMDInfo[PrevF] = R;
905}
906
908 return DebugInfo.getDXILFunction(F);
909}
910
911const Instruction &
913 return DebugInfo.getDXILInstruction(I);
914}
915
917 return DebugInfo.getDXILMetadata(M);
918}
919
921 if (auto *F = dyn_cast<Function>(&V))
922 return getDXILFunction(*F);
923 if (auto *I = dyn_cast<Instruction>(&V))
924 return getDXILInstruction(*I);
925 return V;
926}
927
928void ValueEnumerator::incorporateFunctionMetadata(const Function &F) {
929 NumModuleMDs = MDs.size();
930
931 auto R = FunctionMDInfo.lookup(getValueID(&F) + 1);
932 NumMDStrings = R.NumStrings;
933 MDs.insert(MDs.end(), FunctionMDs.begin() + R.First,
934 FunctionMDs.begin() + R.Last);
935}
936
937void ValueEnumerator::EnumerateValue(const Value *V) {
938 assert(!V->getType()->isVoidTy() && "Can't insert void values!");
939 assert(!isa<MetadataAsValue>(V) && "EnumerateValue doesn't handle Metadata!");
940 assert((V == &getDXILValue(*V)) && "Cannot enumerate replaced values!");
941
942 // Check to see if it's already in!
943 unsigned &ValueID = ValueMap[V];
944 if (ValueID) {
945 // Increment use count.
946 Values[ValueID - 1].second++;
947 return;
948 }
949
950 if (auto *GO = dyn_cast<GlobalObject>(V))
951 if (const Comdat *C = GO->getComdat())
952 Comdats.insert(C);
953
954 // Enumerate the type of this value.
955 EnumerateType(V->getType());
956
957 if (const Constant *C = dyn_cast<Constant>(V)) {
958 if (isa<GlobalValue>(C)) {
959 // Initializers for globals are handled explicitly elsewhere.
960 } else if (C->getNumOperands()) {
961 // If a constant has operands, enumerate them. This makes sure that if a
962 // constant has uses (for example an array of const ints), that they are
963 // inserted also.
964
965 // We prefer to enumerate them with values before we enumerate the user
966 // itself. This makes it more likely that we can avoid forward references
967 // in the reader. We know that there can be no cycles in the constants
968 // graph that don't go through a global variable.
969 for (User::const_op_iterator I = C->op_begin(), E = C->op_end(); I != E;
970 ++I)
971 if (!isa<BasicBlock>(*I)) // Don't enumerate BB operand to BlockAddress.
972 EnumerateValue(*I);
973 if (auto *CE = dyn_cast<ConstantExpr>(C)) {
974 if (CE->getOpcode() == Instruction::ShuffleVector)
975 EnumerateValue(CE->getShuffleMaskForBitcode());
976 if (auto *GEP = dyn_cast<GEPOperator>(CE))
977 EnumerateType(GEP->getSourceElementType());
978 }
979
980 // Finally, add the value. Doing this could make the ValueID reference be
981 // dangling, don't reuse it.
982 Values.push_back(std::make_pair(V, 1U));
983 ValueMap[V] = Values.size();
984 return;
985 }
986 }
987
988 // Add the value.
989 Values.push_back(std::make_pair(V, 1U));
990 ValueID = Values.size();
991}
992
994 unsigned *TypeID = &TypeMap[Ty];
995
996 // We've already seen this type.
997 if (*TypeID)
998 return;
999
1000 // If it is a non-anonymous struct, mark the type as being visited so that we
1001 // don't recursively visit it. This is safe because we allow forward
1002 // references of these in the bitcode reader.
1003 if (StructType *STy = dyn_cast<StructType>(Ty))
1004 if (!STy->isLiteral())
1005 *TypeID = ~0U;
1006
1007 // Enumerate all of the subtypes before we enumerate this type. This ensures
1008 // that the type will be enumerated in an order that can be directly built.
1009 for (Type *SubTy : Ty->subtypes())
1010 EnumerateType(SubTy);
1011
1012 // Refresh the TypeID pointer in case the table rehashed.
1013 TypeID = &TypeMap[Ty];
1014
1015 // Check to see if we got the pointer another way. This can happen when
1016 // enumerating recursive types that hit the base case deeper than they start.
1017 //
1018 // If this is actually a struct that we are treating as forward ref'able,
1019 // then emit the definition now that all of its contents are available.
1020 if (*TypeID && *TypeID != ~0U)
1021 return;
1022
1023 // Add this type now that its contents are all happily enumerated.
1024 Types.push_back(Ty);
1025
1026 *TypeID = Types.size();
1027}
1028
1029// Enumerate the types for the specified value. If the value is a constant,
1030// walk through it, enumerating the types of the constant.
1031void ValueEnumerator::EnumerateOperandType(const Value *V) {
1032 EnumerateType(V->getType());
1033
1034 assert(!isa<MetadataAsValue>(V) && "Unexpected metadata operand");
1035
1036 const Constant *C = dyn_cast<Constant>(V);
1037 if (!C)
1038 return;
1039
1040 // If this constant is already enumerated, ignore it, we know its type must
1041 // be enumerated.
1042 if (ValueMap.count(C))
1043 return;
1044
1045 // This constant may have operands, make sure to enumerate the types in
1046 // them.
1047 for (const Value *Op : C->operands()) {
1048 // Don't enumerate basic blocks here, this happens as operands to
1049 // blockaddress.
1050 if (isa<BasicBlock>(Op))
1051 continue;
1052
1053 EnumerateOperandType(Op);
1054 }
1055 if (auto *CE = dyn_cast<ConstantExpr>(C)) {
1056 if (CE->getOpcode() == Instruction::ShuffleVector)
1057 EnumerateOperandType(CE->getShuffleMaskForBitcode());
1058 if (CE->getOpcode() == Instruction::GetElementPtr)
1059 EnumerateType(cast<GEPOperator>(CE)->getSourceElementType());
1060 }
1061}
1062
1063void ValueEnumerator::EnumerateAttributes(AttributeList PAL) {
1064 if (PAL.isEmpty())
1065 return; // null is always 0.
1066
1067 // Do a lookup.
1068 unsigned &Entry = AttributeListMap[PAL];
1069 if (Entry == 0) {
1070 // Never saw this before, add it.
1071 AttributeLists.push_back(PAL);
1072 Entry = AttributeLists.size();
1073 }
1074
1075 // Do lookups for all attribute groups.
1076 for (unsigned i : PAL.indexes()) {
1077 AttributeSet AS = PAL.getAttributes(i);
1078 if (!AS.hasAttributes())
1079 continue;
1080 IndexAndAttrSet Pair = {i, AS};
1081 unsigned &Entry = AttributeGroupMap[Pair];
1082 if (Entry == 0) {
1083 AttributeGroups.push_back(Pair);
1084 Entry = AttributeGroups.size();
1085
1086 for (Attribute Attr : AS) {
1087 if (Attr.isTypeAttribute())
1088 EnumerateType(Attr.getValueAsType());
1089 }
1090 }
1091 }
1092}
1093
1094void ValueEnumerator::incorporateFunction(const Function &F) {
1095 InstructionCount = 0;
1096 NumModuleValues = Values.size();
1097
1098 // Add global metadata to the function block. This doesn't include
1099 // LocalAsMetadata.
1100 incorporateFunctionMetadata(F);
1101
1102 // Adding function arguments to the value table.
1103 for (const auto &I : F.args()) {
1104 EnumerateValue(&I);
1105 if (I.hasAttribute(Attribute::ByVal))
1106 EnumerateType(I.getParamByValType());
1107 else if (I.hasAttribute(Attribute::StructRet))
1108 EnumerateType(I.getParamStructRetType());
1109 else if (I.hasAttribute(Attribute::ByRef))
1110 EnumerateType(I.getParamByRefType());
1111 }
1112 FirstFuncConstantID = Values.size();
1113
1114 // Add all function-level constants to the value table.
1115 for (const BasicBlock &BB : F) {
1116 for (const Instruction &OrigI : BB) {
1117 const Instruction &I = getDXILInstruction(OrigI);
1118 for (const Use &OI : I.operands()) {
1119 if ((isa<Constant>(OI) && !isa<GlobalValue>(OI)) || isa<InlineAsm>(OI))
1120 EnumerateValue(OI);
1121 }
1122 if (auto *SVI = dyn_cast<ShuffleVectorInst>(&I))
1123 EnumerateValue(SVI->getShuffleMaskForBitcode());
1124 if (auto *SI = dyn_cast<SwitchInst>(&I)) {
1125 for (const auto &Case : SI->cases())
1126 EnumerateValue(Case.getCaseValue());
1127 }
1128 }
1129 BasicBlocks.push_back(&BB);
1130 ValueMap[&BB] = BasicBlocks.size();
1131 }
1132
1133 // Add the function's parameter attributes so they are available for use in
1134 // the function's instruction.
1135 EnumerateAttributes(F.getAttributes());
1136
1137 FirstInstID = Values.size();
1138
1139 SmallVector<LocalAsMetadata *, 8> FnLocalMDVector;
1140 SmallVector<DIArgList *, 8> ArgListMDVector;
1141 // Add all of the instructions.
1142 for (const BasicBlock &BB : F) {
1143 for (const Instruction &OrigI : BB) {
1144 const Instruction &I = getDXILInstruction(OrigI);
1145 for (const Use &OI : I.operands()) {
1146 if (auto *MD = dyn_cast<MetadataAsValue>(&OI)) {
1147 if (auto *Local = dyn_cast<LocalAsMetadata>(MD->getMetadata())) {
1148 // Enumerate metadata after the instructions they might refer to.
1149 FnLocalMDVector.push_back(Local);
1150 } else if (auto *ArgList = dyn_cast<DIArgList>(MD->getMetadata())) {
1151 ArgListMDVector.push_back(ArgList);
1152 for (ValueAsMetadata *VMD : ArgList->getArgs()) {
1153 if (auto *Local = dyn_cast<LocalAsMetadata>(VMD)) {
1154 // Enumerate metadata after the instructions they might refer
1155 // to.
1156 FnLocalMDVector.push_back(Local);
1157 }
1158 }
1159 }
1160 }
1161 }
1162
1163 if (!I.getType()->isVoidTy())
1164 EnumerateValue(&I);
1165 }
1166 }
1167
1168 // Add all of the function-local metadata.
1169 for (unsigned i = 0, e = FnLocalMDVector.size(); i != e; ++i) {
1170 // At this point, every local values have been incorporated, we shouldn't
1171 // have a metadata operand that references a value that hasn't been seen.
1172 assert(ValueMap.count(FnLocalMDVector[i]->getValue()) &&
1173 "Missing value for metadata operand");
1174 EnumerateFunctionLocalMetadata(F, FnLocalMDVector[i]);
1175 }
1176 // DIArgList entries must come after function-local metadata, as it is not
1177 // possible to forward-reference them.
1178 for (const DIArgList *ArgList : ArgListMDVector)
1179 EnumerateFunctionLocalListMetadata(F, ArgList);
1180}
1181
1183 /// Remove purged values from the ValueMap.
1184 for (unsigned i = NumModuleValues, e = Values.size(); i != e; ++i)
1185 ValueMap.erase(Values[i].first);
1186 for (unsigned i = NumModuleMDs, e = MDs.size(); i != e; ++i)
1187 MetadataMap.erase(MDs[i]);
1188 for (const BasicBlock *BB : BasicBlocks)
1189 ValueMap.erase(BB);
1190
1191 Values.resize(NumModuleValues);
1192 MDs.resize(NumModuleMDs);
1193 BasicBlocks.clear();
1194 NumMDStrings = 0;
1195}
1196
1199 unsigned Counter = 0;
1200 for (const BasicBlock &BB : *F)
1201 IDMap[&BB] = ++Counter;
1202}
1203
1204/// getGlobalBasicBlockID - This returns the function-specific ID for the
1205/// specified basic block. This is relatively expensive information, so it
1206/// should only be used by rare constructs such as address-of-label.
1207unsigned ValueEnumerator::getGlobalBasicBlockID(const BasicBlock *BB) const {
1208 unsigned &Idx = GlobalBasicBlockIDs[BB];
1209 if (Idx != 0)
1210 return Idx - 1;
1211
1212 IncorporateFunctionInfoGlobalBBIDs(BB->getParent(), GlobalBasicBlockIDs);
1213 return getGlobalBasicBlockID(BB);
1214}
1215
1217 return Log2_32_Ceil(getTypes().size() + 1);
1218}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MapVector< const Value *, unsigned > OrderMap
PrefixType
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:661
dxil translate DXIL Translate Metadata
static void predictValueUseListOrderImpl(const Value *V, const Function *F, unsigned ID, const OrderMap &OM, UseListOrderStack &Stack)
static void orderValue(const Value *V, OrderMap &OM)
static void predictValueUseListOrder(const Value *V, const Function *F, OrderMap &OM, UseListOrderStack &Stack)
static OrderMap orderModule(const Module &M, ValueEnumerator &VE)
UseListOrderStack predictUseListOrder(const Module &M, ValueEnumerator &VE)
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
Hexagon Common GEP
Module.h This file contains the declarations for the Module class.
This defines the Use class.
static bool lookup(const GsymReader &GR, GsymDataExtractor &Data, uint64_t &Offset, uint64_t BaseAddr, uint64_t Addr, SourceLocations &SrcLocs, llvm::Error &Err)
A Lookup helper functions.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
#define G(x, y, z)
Definition MD5.cpp:55
Machine Check Debug Module
This file contains the declarations for metadata subclasses.
Type::TypeID TypeID
This file defines the SmallVector class.
static unsigned getMetadataTypeOrder(const Metadata *MD)
static UseListOrderStack predictUseListOrder(const Module &M)
static void IncorporateFunctionInfoGlobalBBIDs(const Function *F, DenseMap< const BasicBlock *, unsigned > &IDMap)
Value * RHS
Value * LHS
This class represents an incoming formal argument to a Function.
Definition Argument.h:32
bool hasAttributes() const
Return true if attributes exists in this set.
Definition Attributes.h:477
LLVM Basic Block Representation.
Definition BasicBlock.h:62
const Function * getParent() const
Return the enclosing method, or null if none.
Definition BasicBlock.h:213
This is an important base class in LLVM.
Definition Constant.h:43
ArrayRef< ValueAsMetadata * > getArgs() const
ValueT lookup(const_arg_type_t< KeyT > Val) const
Return the entry for the specified key, or a default constructed value if no such entry exists.
Definition DenseMap.h:205
iterator find(const_arg_type_t< KeyT > Val)
Definition DenseMap.h:178
unsigned size() const
Definition DenseMap.h:114
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT, true > const_iterator
Definition DenseMap.h:79
iterator end()
Definition DenseMap.h:85
BucketT value_type
Definition DenseMap.h:76
const MDOperand * op_iterator
Definition Metadata.h:1431
unsigned & operator[](const const Value *&Key)
Definition MapVector.h:100
Root of the metadata hierarchy.
Definition Metadata.h:64
LLVM_ABI void print(raw_ostream &OS, const Module *M=nullptr, bool IsForDebug=false) const
Print.
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
LLVM_ABI MDNode * getOperand(unsigned i) const
LLVM_ABI unsigned getNumOperands() const
void reserve(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
static LLVM_ABI Type * getMetadataTy(LLVMContext &C)
Definition Type.cpp:288
ArrayRef< Type * > subtypes() const
Definition Type.h:381
static LLVM_ABI TypedPointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
unsigned insert(const T &Entry)
insert - Append entry to the vector if it doesn't already exist.
unsigned idFor(const T &Entry) const
idFor - return the ID for an existing entry.
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
const Use * const_op_iterator
Definition User.h:255
ValueEnumerator(const Module &M, bool ShouldPreserveUseListOrder)
See the file comment.
Definition ValueMap.h:84
ValueMap::const_iterator const_iterator
A const_iterator over a ValueMap.
iterator end()
Get an iterator to the end of the symbol table.
iterator begin()
Get an iterator that from the beginning of the symbol table.
LLVM Value Representation.
Definition Value.h:75
iterator_range< use_iterator > uses()
Definition Value.h:380
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...
const Value & getDXILValue(const Value &V) const
const Instruction & getDXILInstruction(const Instruction &I) const
void setInstructionID(const Instruction *I)
unsigned getComdatID(const Comdat *C) const
uint64_t computeBitsRequiredForTypeIndices() const
unsigned getMetadataID(const Metadata *MD) const
const TypeList & getTypes() const
const Function & getDXILFunction(const Function &F) const
const Metadata * getDXILMetadata(const Metadata *M) const
void print(raw_ostream &OS, const ValueMapType &Map, const char *Name) const
void incorporateFunction(const Function &F)
incorporateFunction/purgeFunction - If you'd like to deal with a function, use these two methods to g...
unsigned getInstructionID(const Instruction *I) const
unsigned getGlobalBasicBlockID(const BasicBlock *BB) const
getGlobalBasicBlockID - This returns the function-specific ID for the specified basic block.
CallInst * Call
@ Entry
Definition COFF.h:862
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
@ CE
Windows NT (Windows on ARM)
Definition MCAsmInfo.h:50
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition BasicBlock.h:73
This is an optimization pass for GlobalISel generic memory operations.
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
Definition MathExtras.h:344
FunctionAddr VTableAddr Value
Definition InstrProf.h:137
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.
Definition STLExtras.h:1668
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
auto reverse(ContainerTy &&C)
Definition STLExtras.h:407
void sort(IteratorTy Start, IteratorTy End)
Definition STLExtras.h:1635
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
bool is_sorted(R &&Range, Compare C)
Wrapper function around std::is_sorted to check if elements in a range R are sorted with respect to a...
Definition STLExtras.h:1969
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
std::vector< UseListOrder > UseListOrderStack
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition BitVector.h:876
#define N
Function object to check whether the second component of a container supported by std::get (like std:...
Definition STLExtras.h:1447