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