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