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.getValueType());
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();
547 else
548 OS << "Value: [null]\n";
549 V->print(errs());
550 errs() << '\n';
551
552 OS << " Uses(" << V->getNumUses() << "):";
553 for (const Use &U : V->uses()) {
554 if (&U != &*V->use_begin())
555 OS << ",";
556 if (U->hasName())
557 OS << " " << U->getName();
558 else
559 OS << " [null]";
560 }
561 OS << "\n\n";
562 }
563}
564
565void ValueEnumerator::print(raw_ostream &OS, const MetadataMapType &Map,
566 const char *Name) const {
567 OS << "Map Name: " << Name << "\n";
568 OS << "Size: " << Map.size() << "\n";
569 for (const auto &I : Map) {
570 const Metadata *MD = I.first;
571 OS << "Metadata: slot = " << I.second.ID << "\n";
572 OS << "Metadata: function = " << I.second.F << "\n";
573 MD->print(OS);
574 OS << "\n";
575 }
576}
577
578/// EnumerateValueSymbolTable - Insert all of the values in the specified symbol
579/// table into the values table.
580void ValueEnumerator::EnumerateValueSymbolTable(const ValueSymbolTable &VST) {
581 for (ValueSymbolTable::const_iterator VI = VST.begin(), VE = VST.end();
582 VI != VE; ++VI)
583 EnumerateValue(VI->getValue());
584}
585
586/// Insert all of the values referenced by named metadata in the specified
587/// module.
588void ValueEnumerator::EnumerateNamedMetadata(const Module &M) {
589 for (const auto &I : M.named_metadata())
590 EnumerateNamedMDNode(&I);
591}
592
593void ValueEnumerator::EnumerateNamedMDNode(const NamedMDNode *MD) {
594 for (unsigned i = 0, e = MD->getNumOperands(); i != e; ++i)
595 EnumerateMetadata(nullptr, MD->getOperand(i));
596}
597
598unsigned ValueEnumerator::getMetadataFunctionID(const Function *F) const {
599 return F ? getValueID(F) + 1 : 0;
600}
601
602void ValueEnumerator::EnumerateMetadata(const Function *F, const Metadata *MD) {
603 EnumerateMetadata(getMetadataFunctionID(F), MD);
604}
605
606void ValueEnumerator::EnumerateFunctionLocalMetadata(
607 const Function &F, const LocalAsMetadata *Local) {
608 EnumerateFunctionLocalMetadata(getMetadataFunctionID(&F), Local);
609}
610
611void ValueEnumerator::EnumerateFunctionLocalListMetadata(
612 const Function &F, const DIArgList *ArgList) {
613 EnumerateFunctionLocalListMetadata(getMetadataFunctionID(&F), ArgList);
614}
615
616void ValueEnumerator::dropFunctionFromMetadata(
617 MetadataMapType::value_type &FirstMD) {
619 auto push = [&Worklist](MetadataMapType::value_type &MD) {
620 auto &Entry = MD.second;
621
622 // Nothing to do if this metadata isn't tagged.
623 if (!Entry.F)
624 return;
625
626 // Drop the function tag.
627 Entry.F = 0;
628
629 // If this is has an ID and is an MDNode, then its operands have entries as
630 // well. We need to drop the function from them too.
631 if (Entry.ID)
632 if (auto *N = dyn_cast<MDNode>(MD.first))
633 Worklist.push_back(N);
634 };
635 push(FirstMD);
636 while (!Worklist.empty())
637 for (const Metadata *Op : Worklist.pop_back_val()->operands()) {
638 if (!Op)
639 continue;
640 auto MD = MetadataMap.find(Op);
641 if (MD != MetadataMap.end())
642 push(*MD);
643 }
644}
645
646void ValueEnumerator::EnumerateMetadata(unsigned F, const Metadata *MD) {
647 // It's vital for reader efficiency that uniqued subgraphs are done in
648 // post-order; it's expensive when their operands have forward references.
649 // If a distinct node is referenced from a uniqued node, it'll be delayed
650 // until the uniqued subgraph has been completely traversed.
651 SmallVector<const MDNode *, 32> DelayedDistinctNodes;
652
653 // Start by enumerating MD, and then work through its transitive operands in
654 // post-order. This requires a depth-first search.
656 if (const MDNode *N = enumerateMetadataImpl(F, MD))
657 Worklist.push_back(std::make_pair(N, N->op_begin()));
658
659 while (!Worklist.empty()) {
660 const MDNode *N = Worklist.back().first;
661
662 // Enumerate operands until we hit a new node. We need to traverse these
663 // nodes' operands before visiting the rest of N's operands.
664 MDNode::op_iterator I = std::find_if(
665 Worklist.back().second, N->op_end(),
666 [&](const Metadata *MD) { return enumerateMetadataImpl(F, MD); });
667 if (I != N->op_end()) {
668 auto *Op = cast<MDNode>(*I);
669 Worklist.back().second = ++I;
670
671 // Delay traversing Op if it's a distinct node and N is uniqued.
672 if (Op->isDistinct() && !N->isDistinct())
673 DelayedDistinctNodes.push_back(Op);
674 else
675 Worklist.push_back(std::make_pair(Op, Op->op_begin()));
676 continue;
677 }
678
679 // All the operands have been visited. Now assign an ID.
680 Worklist.pop_back();
681 MDs.push_back(N);
682 MetadataMap[N].ID = MDs.size();
683
684 // Flush out any delayed distinct nodes; these are all the distinct nodes
685 // that are leaves in last uniqued subgraph.
686 if (Worklist.empty() || Worklist.back().first->isDistinct()) {
687 for (const MDNode *N : DelayedDistinctNodes)
688 Worklist.push_back(std::make_pair(N, N->op_begin()));
689 DelayedDistinctNodes.clear();
690 }
691 }
692}
693
694const MDNode *ValueEnumerator::enumerateMetadataImpl(unsigned F,
695 const Metadata *MD) {
696 if (!MD)
697 return nullptr;
698
699 assert(
701 "Invalid metadata kind");
702
703 auto Insertion = MetadataMap.insert(std::make_pair(MD, MDIndex(F)));
704 MDIndex &Entry = Insertion.first->second;
705 if (!Insertion.second) {
706 // Already mapped. If F doesn't match the function tag, drop it.
707 if (Entry.hasDifferentFunction(F))
708 dropFunctionFromMetadata(*Insertion.first);
709 return nullptr;
710 }
711
712 // Don't assign IDs to metadata nodes.
713 if (auto *N = dyn_cast<MDNode>(MD))
714 return N;
715
716 // Save the metadata.
717 MDs.push_back(MD);
718 Entry.ID = MDs.size();
719
720 // Enumerate the constant, if any.
721 if (auto *C = dyn_cast<ConstantAsMetadata>(MD))
722 EnumerateValue(C->getValue());
723
724 return nullptr;
725}
726
727/// EnumerateFunctionLocalMetadata - Incorporate function-local metadata
728/// information reachable from the metadata.
729void ValueEnumerator::EnumerateFunctionLocalMetadata(
730 unsigned F, const LocalAsMetadata *Local) {
731 assert(F && "Expected a function");
732
733 // Check to see if it's already in!
734 MDIndex &Index = MetadataMap[Local];
735 if (Index.ID) {
736 assert(Index.F == F && "Expected the same function");
737 return;
738 }
739
740 MDs.push_back(Local);
741 Index.F = F;
742 Index.ID = MDs.size();
743
744 EnumerateValue(Local->getValue());
745}
746
747/// EnumerateFunctionLocalListMetadata - Incorporate function-local metadata
748/// information reachable from the metadata.
749void ValueEnumerator::EnumerateFunctionLocalListMetadata(
750 unsigned F, const DIArgList *ArgList) {
751 assert(F && "Expected a function");
752
753 // Check to see if it's already in!
754 MDIndex &Index = MetadataMap[ArgList];
755 if (Index.ID) {
756 assert(Index.F == F && "Expected the same function");
757 return;
758 }
759
760 for (ValueAsMetadata *VAM : ArgList->getArgs()) {
761 if (isa<LocalAsMetadata>(VAM)) {
762 assert(MetadataMap.count(VAM) &&
763 "LocalAsMetadata should be enumerated before DIArgList");
764 assert(MetadataMap[VAM].F == F &&
765 "Expected LocalAsMetadata in the same function");
766 } else {
768 "Expected LocalAsMetadata or ConstantAsMetadata");
769 assert(ValueMap.count(VAM->getValue()) &&
770 "Constant should be enumerated beforeDIArgList");
771 EnumerateMetadata(F, VAM);
772 }
773 }
774
775 MDs.push_back(ArgList);
776 Index.F = F;
777 Index.ID = MDs.size();
778}
779
780static unsigned getMetadataTypeOrder(const Metadata *MD) {
781 // Strings are emitted in bulk and must come first.
782 if (isa<MDString>(MD))
783 return 0;
784
785 // ConstantAsMetadata doesn't reference anything. We may as well shuffle it
786 // to the front since we can detect it.
787 auto *N = dyn_cast<MDNode>(MD);
788 if (!N)
789 return 1;
790
791 // The reader is fast forward references for distinct node operands, but slow
792 // when uniqued operands are unresolved.
793 return N->isDistinct() ? 2 : 3;
794}
795
796void ValueEnumerator::organizeMetadata() {
797 assert(MetadataMap.size() == MDs.size() &&
798 "Metadata map and vector out of sync");
799
800 if (MDs.empty())
801 return;
802
803 // Copy out the index information from MetadataMap in order to choose a new
804 // order.
806 Order.reserve(MetadataMap.size());
807 for (const Metadata *MD : MDs)
808 Order.push_back(MetadataMap.lookup(MD));
809
810 // Partition:
811 // - by function, then
812 // - by isa<MDString>
813 // and then sort by the original/current ID. Since the IDs are guaranteed to
814 // be unique, the result of llvm::sort will be deterministic. There's no need
815 // for std::stable_sort.
816 llvm::sort(Order, [this](MDIndex LHS, MDIndex RHS) {
817 return std::make_tuple(LHS.F, getMetadataTypeOrder(LHS.get(MDs)), LHS.ID) <
818 std::make_tuple(RHS.F, getMetadataTypeOrder(RHS.get(MDs)), RHS.ID);
819 });
820
821 // Rebuild MDs, index the metadata ranges for each function in FunctionMDs,
822 // and fix up MetadataMap.
823 std::vector<const Metadata *> OldMDs;
824 MDs.swap(OldMDs);
825 MDs.reserve(OldMDs.size());
826 for (unsigned I = 0, E = Order.size(); I != E && !Order[I].F; ++I) {
827 auto *MD = Order[I].get(OldMDs);
828 MDs.push_back(MD);
829 MetadataMap[MD].ID = I + 1;
830 if (isa<MDString>(MD))
831 ++NumMDStrings;
832 }
833
834 // Return early if there's nothing for the functions.
835 if (MDs.size() == Order.size())
836 return;
837
838 // Build the function metadata ranges.
839 MDRange R;
840 FunctionMDs.reserve(OldMDs.size());
841 unsigned PrevF = 0;
842 for (unsigned I = MDs.size(), E = Order.size(), ID = MDs.size(); I != E;
843 ++I) {
844 unsigned F = Order[I].F;
845 if (!PrevF) {
846 PrevF = F;
847 } else if (PrevF != F) {
848 R.Last = FunctionMDs.size();
849 std::swap(R, FunctionMDInfo[PrevF]);
850 R.First = FunctionMDs.size();
851
852 ID = MDs.size();
853 PrevF = F;
854 }
855
856 auto *MD = Order[I].get(OldMDs);
857 FunctionMDs.push_back(MD);
858 MetadataMap[MD].ID = ++ID;
859 if (isa<MDString>(MD))
860 ++R.NumStrings;
861 }
862 R.Last = FunctionMDs.size();
863 FunctionMDInfo[PrevF] = R;
864}
865
866void ValueEnumerator::incorporateFunctionMetadata(const Function &F) {
867 NumModuleMDs = MDs.size();
868
869 auto R = FunctionMDInfo.lookup(getValueID(&F) + 1);
870 NumMDStrings = R.NumStrings;
871 MDs.insert(MDs.end(), FunctionMDs.begin() + R.First,
872 FunctionMDs.begin() + R.Last);
873}
874
875void ValueEnumerator::EnumerateValue(const Value *V) {
876 assert(!V->getType()->isVoidTy() && "Can't insert void values!");
877 assert(!isa<MetadataAsValue>(V) && "EnumerateValue doesn't handle Metadata!");
878
879 // Check to see if it's already in!
880 unsigned &ValueID = ValueMap[V];
881 if (ValueID) {
882 // Increment use count.
883 Values[ValueID - 1].second++;
884 return;
885 }
886
887 if (auto *GO = dyn_cast<GlobalObject>(V))
888 if (const Comdat *C = GO->getComdat())
889 Comdats.insert(C);
890
891 // Enumerate the type of this value.
892 EnumerateType(V->getType());
893
894 if (const Constant *C = dyn_cast<Constant>(V)) {
895 if (isa<GlobalValue>(C)) {
896 // Initializers for globals are handled explicitly elsewhere.
897 } else if (C->getNumOperands()) {
898 // If a constant has operands, enumerate them. This makes sure that if a
899 // constant has uses (for example an array of const ints), that they are
900 // inserted also.
901
902 // We prefer to enumerate them with values before we enumerate the user
903 // itself. This makes it more likely that we can avoid forward references
904 // in the reader. We know that there can be no cycles in the constants
905 // graph that don't go through a global variable.
906 for (User::const_op_iterator I = C->op_begin(), E = C->op_end(); I != E;
907 ++I)
908 if (!isa<BasicBlock>(*I)) // Don't enumerate BB operand to BlockAddress.
909 EnumerateValue(*I);
910 if (auto *CE = dyn_cast<ConstantExpr>(C)) {
911 if (CE->getOpcode() == Instruction::ShuffleVector)
912 EnumerateValue(CE->getShuffleMaskForBitcode());
913 if (auto *GEP = dyn_cast<GEPOperator>(CE))
914 EnumerateType(GEP->getSourceElementType());
915 }
916
917 // Finally, add the value. Doing this could make the ValueID reference be
918 // dangling, don't reuse it.
919 Values.push_back(std::make_pair(V, 1U));
920 ValueMap[V] = Values.size();
921 return;
922 }
923 }
924
925 // Add the value.
926 Values.push_back(std::make_pair(V, 1U));
927 ValueID = Values.size();
928}
929
930void ValueEnumerator::EnumerateType(Type *Ty) {
931 unsigned *TypeID = &TypeMap[Ty];
932
933 // We've already seen this type.
934 if (*TypeID)
935 return;
936
937 // If it is a non-anonymous struct, mark the type as being visited so that we
938 // don't recursively visit it. This is safe because we allow forward
939 // references of these in the bitcode reader.
940 if (StructType *STy = dyn_cast<StructType>(Ty))
941 if (!STy->isLiteral())
942 *TypeID = ~0U;
943
944 // Enumerate all of the subtypes before we enumerate this type. This ensures
945 // that the type will be enumerated in an order that can be directly built.
946 for (Type *SubTy : Ty->subtypes())
947 EnumerateType(SubTy);
948
949 // Refresh the TypeID pointer in case the table rehashed.
950 TypeID = &TypeMap[Ty];
951
952 // Check to see if we got the pointer another way. This can happen when
953 // enumerating recursive types that hit the base case deeper than they start.
954 //
955 // If this is actually a struct that we are treating as forward ref'able,
956 // then emit the definition now that all of its contents are available.
957 if (*TypeID && *TypeID != ~0U)
958 return;
959
960 // Add this type now that its contents are all happily enumerated.
961 Types.push_back(Ty);
962
963 *TypeID = Types.size();
964}
965
966// Enumerate the types for the specified value. If the value is a constant,
967// walk through it, enumerating the types of the constant.
968void ValueEnumerator::EnumerateOperandType(const Value *V) {
969 EnumerateType(V->getType());
970
971 assert(!isa<MetadataAsValue>(V) && "Unexpected metadata operand");
972
973 const Constant *C = dyn_cast<Constant>(V);
974 if (!C)
975 return;
976
977 // If this constant is already enumerated, ignore it, we know its type must
978 // be enumerated.
979 if (ValueMap.count(C))
980 return;
981
982 // This constant may have operands, make sure to enumerate the types in
983 // them.
984 for (const Value *Op : C->operands()) {
985 // Don't enumerate basic blocks here, this happens as operands to
986 // blockaddress.
987 if (isa<BasicBlock>(Op))
988 continue;
989
990 EnumerateOperandType(Op);
991 }
992 if (auto *CE = dyn_cast<ConstantExpr>(C)) {
993 if (CE->getOpcode() == Instruction::ShuffleVector)
994 EnumerateOperandType(CE->getShuffleMaskForBitcode());
995 if (CE->getOpcode() == Instruction::GetElementPtr)
996 EnumerateType(cast<GEPOperator>(CE)->getSourceElementType());
997 }
998}
999
1000void ValueEnumerator::EnumerateAttributes(AttributeList PAL) {
1001 if (PAL.isEmpty())
1002 return; // null is always 0.
1003
1004 // Do a lookup.
1005 unsigned &Entry = AttributeListMap[PAL];
1006 if (Entry == 0) {
1007 // Never saw this before, add it.
1008 AttributeLists.push_back(PAL);
1009 Entry = AttributeLists.size();
1010 }
1011
1012 // Do lookups for all attribute groups.
1013 for (unsigned i : PAL.indexes()) {
1014 AttributeSet AS = PAL.getAttributes(i);
1015 if (!AS.hasAttributes())
1016 continue;
1017 IndexAndAttrSet Pair = {i, AS};
1018 unsigned &Entry = AttributeGroupMap[Pair];
1019 if (Entry == 0) {
1020 AttributeGroups.push_back(Pair);
1021 Entry = AttributeGroups.size();
1022
1023 for (Attribute Attr : AS) {
1024 if (Attr.isTypeAttribute())
1025 EnumerateType(Attr.getValueAsType());
1026 }
1027 }
1028 }
1029}
1030
1032 InstructionCount = 0;
1033 NumModuleValues = Values.size();
1034
1035 // Add global metadata to the function block. This doesn't include
1036 // LocalAsMetadata.
1037 incorporateFunctionMetadata(F);
1038
1039 // Adding function arguments to the value table.
1040 for (const auto &I : F.args()) {
1041 EnumerateValue(&I);
1042 if (I.hasAttribute(Attribute::ByVal))
1043 EnumerateType(I.getParamByValType());
1044 else if (I.hasAttribute(Attribute::StructRet))
1045 EnumerateType(I.getParamStructRetType());
1046 else if (I.hasAttribute(Attribute::ByRef))
1047 EnumerateType(I.getParamByRefType());
1048 }
1049 FirstFuncConstantID = Values.size();
1050
1051 // Add all function-level constants to the value table.
1052 for (const BasicBlock &BB : F) {
1053 for (const Instruction &I : BB) {
1054 for (const Use &OI : I.operands()) {
1055 if ((isa<Constant>(OI) && !isa<GlobalValue>(OI)) || isa<InlineAsm>(OI))
1056 EnumerateValue(OI);
1057 }
1058 if (auto *SVI = dyn_cast<ShuffleVectorInst>(&I))
1059 EnumerateValue(SVI->getShuffleMaskForBitcode());
1060 if (auto *SI = dyn_cast<SwitchInst>(&I)) {
1061 for (const auto &Case : SI->cases())
1062 EnumerateValue(Case.getCaseValue());
1063 }
1064 }
1065 BasicBlocks.push_back(&BB);
1066 ValueMap[&BB] = BasicBlocks.size();
1067 }
1068
1069 // Add the function's parameter attributes so they are available for use in
1070 // the function's instruction.
1071 EnumerateAttributes(F.getAttributes());
1072
1073 FirstInstID = Values.size();
1074
1075 SmallVector<LocalAsMetadata *, 8> FnLocalMDVector;
1076 SmallVector<DIArgList *, 8> ArgListMDVector;
1077 // Add all of the instructions.
1078 for (const BasicBlock &BB : F) {
1079 for (const Instruction &I : BB) {
1080 for (const Use &OI : I.operands()) {
1081 if (auto *MD = dyn_cast<MetadataAsValue>(&OI)) {
1082 if (auto *Local = dyn_cast<LocalAsMetadata>(MD->getMetadata())) {
1083 // Enumerate metadata after the instructions they might refer to.
1084 FnLocalMDVector.push_back(Local);
1085 } else if (auto *ArgList = dyn_cast<DIArgList>(MD->getMetadata())) {
1086 ArgListMDVector.push_back(ArgList);
1087 for (ValueAsMetadata *VMD : ArgList->getArgs()) {
1088 if (auto *Local = dyn_cast<LocalAsMetadata>(VMD)) {
1089 // Enumerate metadata after the instructions they might refer
1090 // to.
1091 FnLocalMDVector.push_back(Local);
1092 }
1093 }
1094 }
1095 }
1096 }
1097
1098 if (!I.getType()->isVoidTy())
1099 EnumerateValue(&I);
1100 }
1101 }
1102
1103 // Add all of the function-local metadata.
1104 for (unsigned i = 0, e = FnLocalMDVector.size(); i != e; ++i) {
1105 // At this point, every local values have been incorporated, we shouldn't
1106 // have a metadata operand that references a value that hasn't been seen.
1107 assert(ValueMap.count(FnLocalMDVector[i]->getValue()) &&
1108 "Missing value for metadata operand");
1109 EnumerateFunctionLocalMetadata(F, FnLocalMDVector[i]);
1110 }
1111 // DIArgList entries must come after function-local metadata, as it is not
1112 // possible to forward-reference them.
1113 for (const DIArgList *ArgList : ArgListMDVector)
1114 EnumerateFunctionLocalListMetadata(F, ArgList);
1115}
1116
1118 /// Remove purged values from the ValueMap.
1119 for (unsigned i = NumModuleValues, e = Values.size(); i != e; ++i)
1120 ValueMap.erase(Values[i].first);
1121 for (unsigned i = NumModuleMDs, e = MDs.size(); i != e; ++i)
1122 MetadataMap.erase(MDs[i]);
1123 for (const BasicBlock *BB : BasicBlocks)
1124 ValueMap.erase(BB);
1125
1126 Values.resize(NumModuleValues);
1127 MDs.resize(NumModuleMDs);
1128 BasicBlocks.clear();
1129 NumMDStrings = 0;
1130}
1131
1134 unsigned Counter = 0;
1135 for (const BasicBlock &BB : *F)
1136 IDMap[&BB] = ++Counter;
1137}
1138
1139/// getGlobalBasicBlockID - This returns the function-specific ID for the
1140/// specified basic block. This is relatively expensive information, so it
1141/// should only be used by rare constructs such as address-of-label.
1142unsigned ValueEnumerator::getGlobalBasicBlockID(const BasicBlock *BB) const {
1143 unsigned &Idx = GlobalBasicBlockIDs[BB];
1144 if (Idx != 0)
1145 return Idx - 1;
1146
1147 IncorporateFunctionInfoGlobalBBIDs(BB->getParent(), GlobalBasicBlockIDs);
1148 return getGlobalBasicBlockID(BB);
1149}
1150
1152 return Log2_32_Ceil(getTypes().size() + 1);
1153}
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:638
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, 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 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: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
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: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
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:45
static LLVM_ABI Type * getMetadataTy(LLVMContext &C)
Definition Type.cpp:286
ArrayRef< Type * > subtypes() const
Definition Type.h:365
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:281
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.
Definition Types.h:26
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:1968
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
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