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