1 //===-- ValueEnumerator.cpp - Number values and types for bitcode writer --===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the ValueEnumerator class.
12 //===----------------------------------------------------------------------===//
14 #include "ValueEnumerator.h"
15 #include "llvm/ADT/STLExtras.h"
16 #include "llvm/ADT/SmallPtrSet.h"
17 #include "llvm/IR/Constants.h"
18 #include "llvm/IR/DerivedTypes.h"
19 #include "llvm/IR/Instructions.h"
20 #include "llvm/IR/Module.h"
21 #include "llvm/IR/UseListOrder.h"
22 #include "llvm/IR/ValueSymbolTable.h"
23 #include "llvm/Support/Debug.h"
24 #include "llvm/Support/raw_ostream.h"
29 typedef DenseMap<const Value *, std::pair<unsigned, bool>> OrderMap;
32 static void orderValue(const Value *V, OrderMap &OM) {
33 if (OM.lookup(V).first)
36 if (const Constant *C = dyn_cast<Constant>(V))
37 if (C->getNumOperands() && !isa<GlobalValue>(C))
38 for (const Value *Op : C->operands())
39 if (!isa<BasicBlock>(Op))
42 // Note: we cannot cache this lookup above, since inserting into the map
43 // changes the map's size, and thus affects the ID.
44 OM[V].first = OM.size() + 1;
47 static OrderMap orderModule(const Module *M) {
48 // This needs to match the order used by ValueEnumerator::ValueEnumerator()
49 // and ValueEnumerator::incorporateFunction().
52 for (const GlobalVariable &G : M->globals())
54 for (const Function &F : *M)
56 for (const GlobalAlias &A : M->aliases())
58 for (const GlobalVariable &G : M->globals())
59 if (G.hasInitializer())
60 orderValue(G.getInitializer(), OM);
61 for (const GlobalAlias &A : M->aliases())
62 orderValue(A.getAliasee(), OM);
63 for (const Function &F : *M)
64 if (F.hasPrefixData())
65 orderValue(F.getPrefixData(), OM);
67 for (const Function &F : *M) {
68 if (F.isDeclaration())
70 // Here we need to match the union of ValueEnumerator::incorporateFunction()
71 // and WriteFunction(). Basic blocks are implicitly declared before
72 // anything else (by declaring their size).
73 for (const BasicBlock &BB : F)
75 for (const Argument &A : F.args())
77 for (const BasicBlock &BB : F)
78 for (const Instruction &I : BB)
79 for (const Value *Op : I.operands())
80 if ((isa<Constant>(*Op) && !isa<GlobalValue>(*Op)) ||
83 for (const BasicBlock &BB : F)
84 for (const Instruction &I : BB)
90 static void predictValueUseListOrderImpl(const Value *V, const Function *F,
91 unsigned ID, const OrderMap &OM,
92 UseListOrderStack &Stack) {
93 // Predict use-list order for this one.
94 typedef std::pair<const Use *, unsigned> Entry;
95 SmallVector<Entry, 64> List;
96 for (const Use &U : V->uses())
97 // Check if this user will be serialized.
98 if (OM.lookup(U.getUser()).first)
99 List.push_back(std::make_pair(&U, List.size()));
102 // We may have lost some users.
105 std::sort(List.begin(), List.end(),
106 [&OM, ID](const Entry &L, const Entry &R) {
107 const Use *LU = L.first;
108 const Use *RU = R.first;
112 auto LID = OM.lookup(LU->getUser()).first;
113 auto RID = OM.lookup(RU->getUser()).first;
114 // If ID is 4, then expect: 7 6 5 1 2 3.
125 // LID and RID are equal, so we have different operands of the same user.
126 // Assume operands are added in order for all instructions.
127 if (LU->getOperandNo() < RU->getOperandNo())
133 List.begin(), List.end(),
134 [](const Entry &L, const Entry &R) { return L.second < R.second; }))
135 // Order is already correct.
138 // Store the shuffle.
139 UseListOrder O(V, F, List.size());
140 assert(List.size() == O.Shuffle.size() && "Wrong size");
141 for (size_t I = 0, E = List.size(); I != E; ++I)
142 O.Shuffle[I] = List[I].second;
143 Stack.emplace_back(std::move(O));
146 static void predictValueUseListOrder(const Value *V, const Function *F,
147 OrderMap &OM, UseListOrderStack &Stack) {
148 auto &IDPair = OM[V];
149 assert(IDPair.first && "Unmapped value");
151 // Already predicted.
154 // Do the actual prediction.
155 IDPair.second = true;
156 if (!V->use_empty() && std::next(V->use_begin()) != V->use_end())
157 predictValueUseListOrderImpl(V, F, IDPair.first, OM, Stack);
159 // Recursive descent into constants.
160 if (const Constant *C = dyn_cast<Constant>(V))
161 if (C->getNumOperands() && !isa<GlobalValue>(C))
162 for (const Value *Op : C->operands())
163 if (isa<Constant>(Op) && !isa<GlobalValue>(Op))
164 predictValueUseListOrder(Op, F, OM, Stack);
167 static UseListOrderStack predictUseListOrder(const Module *M) {
168 OrderMap OM = orderModule(M);
170 // Use-list orders need to be serialized after all the users have been added
171 // to a value, or else the shuffles will be incomplete. Store them per
172 // function in a stack.
174 // Aside from function order, the order of values doesn't matter much here.
175 UseListOrderStack Stack;
177 // We want to visit the functions backward now so we can list function-local
178 // constants in the last Function they're used in. Module-level constants
179 // have already been visited above.
180 for (auto I = M->rbegin(), E = M->rend(); I != E; ++I) {
181 const Function &F = *I;
182 if (F.isDeclaration())
184 for (const BasicBlock &BB : F)
185 predictValueUseListOrder(&BB, &F, OM, Stack);
186 for (const Argument &A : F.args())
187 predictValueUseListOrder(&A, &F, OM, Stack);
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 predictValueUseListOrder(Op, &F, OM, Stack);
194 for (const BasicBlock &BB : F)
195 for (const Instruction &I : BB)
196 predictValueUseListOrder(&I, &F, OM, Stack);
199 // Visit globals last, since the module-level use-list block will be seen
200 // before the function bodies are processed.
201 for (const GlobalVariable &G : M->globals())
202 predictValueUseListOrder(&G, nullptr, OM, Stack);
203 for (const Function &F : *M)
204 predictValueUseListOrder(&F, nullptr, OM, Stack);
205 for (const GlobalAlias &A : M->aliases())
206 predictValueUseListOrder(&A, nullptr, OM, Stack);
207 for (const GlobalVariable &G : M->globals())
208 if (G.hasInitializer())
209 predictValueUseListOrder(G.getInitializer(), nullptr, OM, Stack);
210 for (const GlobalAlias &A : M->aliases())
211 predictValueUseListOrder(A.getAliasee(), nullptr, OM, Stack);
212 for (const Function &F : *M)
213 if (F.hasPrefixData())
214 predictValueUseListOrder(F.getPrefixData(), nullptr, OM, Stack);
219 static bool isIntOrIntVectorValue(const std::pair<const Value*, unsigned> &V) {
220 return V.first->getType()->isIntOrIntVectorTy();
223 /// ValueEnumerator - Enumerate module-level information.
224 ValueEnumerator::ValueEnumerator(const Module *M) {
225 if (shouldPreserveBitcodeUseListOrder())
226 UseListOrders = predictUseListOrder(M);
228 // Enumerate the global variables.
229 for (Module::const_global_iterator I = M->global_begin(),
231 E = M->global_end(); I != E; ++I)
234 // Enumerate the functions.
235 for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) {
237 EnumerateAttributes(cast<Function>(I)->getAttributes());
240 // Enumerate the aliases.
241 for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
245 // Remember what is the cutoff between globalvalue's and other constants.
246 unsigned FirstConstant = Values.size();
248 // Enumerate the global variable initializers.
249 for (Module::const_global_iterator I = M->global_begin(),
250 E = M->global_end(); I != E; ++I)
251 if (I->hasInitializer())
252 EnumerateValue(I->getInitializer());
254 // Enumerate the aliasees.
255 for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
257 EnumerateValue(I->getAliasee());
259 // Enumerate the prefix data constants.
260 for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
261 if (I->hasPrefixData())
262 EnumerateValue(I->getPrefixData());
264 // Insert constants and metadata that are named at module level into the slot
265 // pool so that the module symbol table can refer to them...
266 EnumerateValueSymbolTable(M->getValueSymbolTable());
267 EnumerateNamedMetadata(M);
269 SmallVector<std::pair<unsigned, MDNode*>, 8> MDs;
271 // Enumerate types used by function bodies and argument lists.
272 for (const Function &F : *M) {
273 for (const Argument &A : F.args())
274 EnumerateType(A.getType());
276 for (const BasicBlock &BB : F)
277 for (const Instruction &I : BB) {
278 for (const Use &Op : I.operands()) {
279 if (MDNode *MD = dyn_cast<MDNode>(&Op))
280 if (MD->isFunctionLocal() && MD->getFunction())
281 // These will get enumerated during function-incorporation.
283 EnumerateOperandType(Op);
285 EnumerateType(I.getType());
286 if (const CallInst *CI = dyn_cast<CallInst>(&I))
287 EnumerateAttributes(CI->getAttributes());
288 else if (const InvokeInst *II = dyn_cast<InvokeInst>(&I))
289 EnumerateAttributes(II->getAttributes());
291 // Enumerate metadata attached with this instruction.
293 I.getAllMetadataOtherThanDebugLoc(MDs);
294 for (unsigned i = 0, e = MDs.size(); i != e; ++i)
295 EnumerateMetadata(MDs[i].second);
297 if (!I.getDebugLoc().isUnknown()) {
299 I.getDebugLoc().getScopeAndInlinedAt(Scope, IA, I.getContext());
300 if (Scope) EnumerateMetadata(Scope);
301 if (IA) EnumerateMetadata(IA);
306 // Optimize constant ordering.
307 OptimizeConstants(FirstConstant, Values.size());
310 unsigned ValueEnumerator::getInstructionID(const Instruction *Inst) const {
311 InstructionMapType::const_iterator I = InstructionMap.find(Inst);
312 assert(I != InstructionMap.end() && "Instruction is not mapped!");
316 unsigned ValueEnumerator::getComdatID(const Comdat *C) const {
317 unsigned ComdatID = Comdats.idFor(C);
318 assert(ComdatID && "Comdat not found!");
322 void ValueEnumerator::setInstructionID(const Instruction *I) {
323 InstructionMap[I] = InstructionCount++;
326 unsigned ValueEnumerator::getValueID(const Value *V) const {
327 if (isa<MDNode>(V) || isa<MDString>(V)) {
328 ValueMapType::const_iterator I = MDValueMap.find(V);
329 assert(I != MDValueMap.end() && "Value not in slotcalculator!");
333 ValueMapType::const_iterator I = ValueMap.find(V);
334 assert(I != ValueMap.end() && "Value not in slotcalculator!");
338 void ValueEnumerator::dump() const {
339 print(dbgs(), ValueMap, "Default");
341 print(dbgs(), MDValueMap, "MetaData");
345 void ValueEnumerator::print(raw_ostream &OS, const ValueMapType &Map,
346 const char *Name) const {
348 OS << "Map Name: " << Name << "\n";
349 OS << "Size: " << Map.size() << "\n";
350 for (ValueMapType::const_iterator I = Map.begin(),
351 E = Map.end(); I != E; ++I) {
353 const Value *V = I->first;
355 OS << "Value: " << V->getName();
357 OS << "Value: [null]\n";
360 OS << " Uses(" << std::distance(V->use_begin(),V->use_end()) << "):";
361 for (const Use &U : V->uses()) {
362 if (&U != &*V->use_begin())
365 OS << " " << U->getName();
374 /// OptimizeConstants - Reorder constant pool for denser encoding.
375 void ValueEnumerator::OptimizeConstants(unsigned CstStart, unsigned CstEnd) {
376 if (CstStart == CstEnd || CstStart+1 == CstEnd) return;
378 if (shouldPreserveBitcodeUseListOrder())
379 // Optimizing constants makes the use-list order difficult to predict.
380 // Disable it for now when trying to preserve the order.
383 std::stable_sort(Values.begin() + CstStart, Values.begin() + CstEnd,
384 [this](const std::pair<const Value *, unsigned> &LHS,
385 const std::pair<const Value *, unsigned> &RHS) {
387 if (LHS.first->getType() != RHS.first->getType())
388 return getTypeID(LHS.first->getType()) < getTypeID(RHS.first->getType());
389 // Then by frequency.
390 return LHS.second > RHS.second;
393 // Ensure that integer and vector of integer constants are at the start of the
394 // constant pool. This is important so that GEP structure indices come before
395 // gep constant exprs.
396 std::partition(Values.begin()+CstStart, Values.begin()+CstEnd,
397 isIntOrIntVectorValue);
399 // Rebuild the modified portion of ValueMap.
400 for (; CstStart != CstEnd; ++CstStart)
401 ValueMap[Values[CstStart].first] = CstStart+1;
405 /// EnumerateValueSymbolTable - Insert all of the values in the specified symbol
406 /// table into the values table.
407 void ValueEnumerator::EnumerateValueSymbolTable(const ValueSymbolTable &VST) {
408 for (ValueSymbolTable::const_iterator VI = VST.begin(), VE = VST.end();
410 EnumerateValue(VI->getValue());
413 /// EnumerateNamedMetadata - Insert all of the values referenced by
414 /// named metadata in the specified module.
415 void ValueEnumerator::EnumerateNamedMetadata(const Module *M) {
416 for (Module::const_named_metadata_iterator I = M->named_metadata_begin(),
417 E = M->named_metadata_end(); I != E; ++I)
418 EnumerateNamedMDNode(I);
421 void ValueEnumerator::EnumerateNamedMDNode(const NamedMDNode *MD) {
422 for (unsigned i = 0, e = MD->getNumOperands(); i != e; ++i)
423 EnumerateMetadata(MD->getOperand(i));
426 /// EnumerateMDNodeOperands - Enumerate all non-function-local values
427 /// and types referenced by the given MDNode.
428 void ValueEnumerator::EnumerateMDNodeOperands(const MDNode *N) {
429 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
430 if (Value *V = N->getOperand(i)) {
431 if (isa<MDNode>(V) || isa<MDString>(V))
432 EnumerateMetadata(V);
433 else if (!isa<Instruction>(V) && !isa<Argument>(V))
436 EnumerateType(Type::getVoidTy(N->getContext()));
440 void ValueEnumerator::EnumerateMetadata(const Value *MD) {
441 assert((isa<MDNode>(MD) || isa<MDString>(MD)) && "Invalid metadata kind");
443 // Enumerate the type of this value.
444 EnumerateType(MD->getType());
446 const MDNode *N = dyn_cast<MDNode>(MD);
448 // In the module-level pass, skip function-local nodes themselves, but
449 // do walk their operands.
450 if (N && N->isFunctionLocal() && N->getFunction()) {
451 EnumerateMDNodeOperands(N);
455 // Check to see if it's already in!
456 unsigned &MDValueID = MDValueMap[MD];
458 // Increment use count.
459 MDValues[MDValueID-1].second++;
462 MDValues.push_back(std::make_pair(MD, 1U));
463 MDValueID = MDValues.size();
465 // Enumerate all non-function-local operands.
467 EnumerateMDNodeOperands(N);
470 /// EnumerateFunctionLocalMetadataa - Incorporate function-local metadata
471 /// information reachable from the given MDNode.
472 void ValueEnumerator::EnumerateFunctionLocalMetadata(const MDNode *N) {
473 assert(N->isFunctionLocal() && N->getFunction() &&
474 "EnumerateFunctionLocalMetadata called on non-function-local mdnode!");
476 // Enumerate the type of this value.
477 EnumerateType(N->getType());
479 // Check to see if it's already in!
480 unsigned &MDValueID = MDValueMap[N];
482 // Increment use count.
483 MDValues[MDValueID-1].second++;
486 MDValues.push_back(std::make_pair(N, 1U));
487 MDValueID = MDValues.size();
489 // To incoroporate function-local information visit all function-local
490 // MDNodes and all function-local values they reference.
491 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
492 if (Value *V = N->getOperand(i)) {
493 if (MDNode *O = dyn_cast<MDNode>(V)) {
494 if (O->isFunctionLocal() && O->getFunction())
495 EnumerateFunctionLocalMetadata(O);
496 } else if (isa<Instruction>(V) || isa<Argument>(V))
500 // Also, collect all function-local MDNodes for easy access.
501 FunctionLocalMDs.push_back(N);
504 void ValueEnumerator::EnumerateValue(const Value *V) {
505 assert(!V->getType()->isVoidTy() && "Can't insert void values!");
506 assert(!isa<MDNode>(V) && !isa<MDString>(V) &&
507 "EnumerateValue doesn't handle Metadata!");
509 // Check to see if it's already in!
510 unsigned &ValueID = ValueMap[V];
512 // Increment use count.
513 Values[ValueID-1].second++;
517 if (auto *GO = dyn_cast<GlobalObject>(V))
518 if (const Comdat *C = GO->getComdat())
521 // Enumerate the type of this value.
522 EnumerateType(V->getType());
524 if (const Constant *C = dyn_cast<Constant>(V)) {
525 if (isa<GlobalValue>(C)) {
526 // Initializers for globals are handled explicitly elsewhere.
527 } else if (C->getNumOperands()) {
528 // If a constant has operands, enumerate them. This makes sure that if a
529 // constant has uses (for example an array of const ints), that they are
532 // We prefer to enumerate them with values before we enumerate the user
533 // itself. This makes it more likely that we can avoid forward references
534 // in the reader. We know that there can be no cycles in the constants
535 // graph that don't go through a global variable.
536 for (User::const_op_iterator I = C->op_begin(), E = C->op_end();
538 if (!isa<BasicBlock>(*I)) // Don't enumerate BB operand to BlockAddress.
541 // Finally, add the value. Doing this could make the ValueID reference be
542 // dangling, don't reuse it.
543 Values.push_back(std::make_pair(V, 1U));
544 ValueMap[V] = Values.size();
550 Values.push_back(std::make_pair(V, 1U));
551 ValueID = Values.size();
555 void ValueEnumerator::EnumerateType(Type *Ty) {
556 unsigned *TypeID = &TypeMap[Ty];
558 // We've already seen this type.
562 // If it is a non-anonymous struct, mark the type as being visited so that we
563 // don't recursively visit it. This is safe because we allow forward
564 // references of these in the bitcode reader.
565 if (StructType *STy = dyn_cast<StructType>(Ty))
566 if (!STy->isLiteral())
569 // Enumerate all of the subtypes before we enumerate this type. This ensures
570 // that the type will be enumerated in an order that can be directly built.
571 for (Type::subtype_iterator I = Ty->subtype_begin(), E = Ty->subtype_end();
575 // Refresh the TypeID pointer in case the table rehashed.
576 TypeID = &TypeMap[Ty];
578 // Check to see if we got the pointer another way. This can happen when
579 // enumerating recursive types that hit the base case deeper than they start.
581 // If this is actually a struct that we are treating as forward ref'able,
582 // then emit the definition now that all of its contents are available.
583 if (*TypeID && *TypeID != ~0U)
586 // Add this type now that its contents are all happily enumerated.
589 *TypeID = Types.size();
592 // Enumerate the types for the specified value. If the value is a constant,
593 // walk through it, enumerating the types of the constant.
594 void ValueEnumerator::EnumerateOperandType(const Value *V) {
595 EnumerateType(V->getType());
597 if (const Constant *C = dyn_cast<Constant>(V)) {
598 // If this constant is already enumerated, ignore it, we know its type must
600 if (ValueMap.count(V)) return;
602 // This constant may have operands, make sure to enumerate the types in
604 for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i) {
605 const Value *Op = C->getOperand(i);
607 // Don't enumerate basic blocks here, this happens as operands to
609 if (isa<BasicBlock>(Op)) continue;
611 EnumerateOperandType(Op);
614 if (const MDNode *N = dyn_cast<MDNode>(V)) {
615 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
616 if (Value *Elem = N->getOperand(i))
617 EnumerateOperandType(Elem);
619 } else if (isa<MDString>(V) || isa<MDNode>(V))
620 EnumerateMetadata(V);
623 void ValueEnumerator::EnumerateAttributes(AttributeSet PAL) {
624 if (PAL.isEmpty()) return; // null is always 0.
627 unsigned &Entry = AttributeMap[PAL];
629 // Never saw this before, add it.
630 Attribute.push_back(PAL);
631 Entry = Attribute.size();
634 // Do lookups for all attribute groups.
635 for (unsigned i = 0, e = PAL.getNumSlots(); i != e; ++i) {
636 AttributeSet AS = PAL.getSlotAttributes(i);
637 unsigned &Entry = AttributeGroupMap[AS];
639 AttributeGroups.push_back(AS);
640 Entry = AttributeGroups.size();
645 void ValueEnumerator::incorporateFunction(const Function &F) {
646 InstructionCount = 0;
647 NumModuleValues = Values.size();
648 NumModuleMDValues = MDValues.size();
650 // Adding function arguments to the value table.
651 for (Function::const_arg_iterator I = F.arg_begin(), E = F.arg_end();
655 FirstFuncConstantID = Values.size();
657 // Add all function-level constants to the value table.
658 for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
659 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E; ++I)
660 for (User::const_op_iterator OI = I->op_begin(), E = I->op_end();
662 if ((isa<Constant>(*OI) && !isa<GlobalValue>(*OI)) ||
666 BasicBlocks.push_back(BB);
667 ValueMap[BB] = BasicBlocks.size();
670 // Optimize the constant layout.
671 OptimizeConstants(FirstFuncConstantID, Values.size());
673 // Add the function's parameter attributes so they are available for use in
674 // the function's instruction.
675 EnumerateAttributes(F.getAttributes());
677 FirstInstID = Values.size();
679 SmallVector<MDNode *, 8> FnLocalMDVector;
680 // Add all of the instructions.
681 for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
682 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E; ++I) {
683 for (User::const_op_iterator OI = I->op_begin(), E = I->op_end();
685 if (MDNode *MD = dyn_cast<MDNode>(*OI))
686 if (MD->isFunctionLocal() && MD->getFunction())
687 // Enumerate metadata after the instructions they might refer to.
688 FnLocalMDVector.push_back(MD);
691 SmallVector<std::pair<unsigned, MDNode*>, 8> MDs;
692 I->getAllMetadataOtherThanDebugLoc(MDs);
693 for (unsigned i = 0, e = MDs.size(); i != e; ++i) {
694 MDNode *N = MDs[i].second;
695 if (N->isFunctionLocal() && N->getFunction())
696 FnLocalMDVector.push_back(N);
699 if (!I->getType()->isVoidTy())
704 // Add all of the function-local metadata.
705 for (unsigned i = 0, e = FnLocalMDVector.size(); i != e; ++i)
706 EnumerateFunctionLocalMetadata(FnLocalMDVector[i]);
709 void ValueEnumerator::purgeFunction() {
710 /// Remove purged values from the ValueMap.
711 for (unsigned i = NumModuleValues, e = Values.size(); i != e; ++i)
712 ValueMap.erase(Values[i].first);
713 for (unsigned i = NumModuleMDValues, e = MDValues.size(); i != e; ++i)
714 MDValueMap.erase(MDValues[i].first);
715 for (unsigned i = 0, e = BasicBlocks.size(); i != e; ++i)
716 ValueMap.erase(BasicBlocks[i]);
718 Values.resize(NumModuleValues);
719 MDValues.resize(NumModuleMDValues);
721 FunctionLocalMDs.clear();
724 static void IncorporateFunctionInfoGlobalBBIDs(const Function *F,
725 DenseMap<const BasicBlock*, unsigned> &IDMap) {
726 unsigned Counter = 0;
727 for (Function::const_iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
728 IDMap[BB] = ++Counter;
731 /// getGlobalBasicBlockID - This returns the function-specific ID for the
732 /// specified basic block. This is relatively expensive information, so it
733 /// should only be used by rare constructs such as address-of-label.
734 unsigned ValueEnumerator::getGlobalBasicBlockID(const BasicBlock *BB) const {
735 unsigned &Idx = GlobalBasicBlockIDs[BB];
739 IncorporateFunctionInfoGlobalBBIDs(BB->getParent(), GlobalBasicBlockIDs);
740 return getGlobalBasicBlockID(BB);