ValueEnumerator.cpp revision 204642
1193323Sed//===-- ValueEnumerator.cpp - Number values and types for bitcode writer --===//
2193323Sed//
3193323Sed//                     The LLVM Compiler Infrastructure
4193323Sed//
5193323Sed// This file is distributed under the University of Illinois Open Source
6193323Sed// License. See LICENSE.TXT for details.
7193323Sed//
8193323Sed//===----------------------------------------------------------------------===//
9193323Sed//
10193323Sed// This file implements the ValueEnumerator class.
11193323Sed//
12193323Sed//===----------------------------------------------------------------------===//
13193323Sed
14193323Sed#include "ValueEnumerator.h"
15193323Sed#include "llvm/Constants.h"
16193323Sed#include "llvm/DerivedTypes.h"
17193323Sed#include "llvm/Module.h"
18193323Sed#include "llvm/TypeSymbolTable.h"
19193323Sed#include "llvm/ValueSymbolTable.h"
20193323Sed#include "llvm/Instructions.h"
21193323Sed#include <algorithm>
22193323Sedusing namespace llvm;
23193323Sed
24193323Sedstatic bool isSingleValueType(const std::pair<const llvm::Type*,
25193323Sed                              unsigned int> &P) {
26193323Sed  return P.first->isSingleValueType();
27193323Sed}
28193323Sed
29193323Sedstatic bool isIntegerValue(const std::pair<const Value*, unsigned> &V) {
30204642Srdivacky  return V.first->getType()->isIntegerTy();
31193323Sed}
32193323Sed
33193323Sedstatic bool CompareByFrequency(const std::pair<const llvm::Type*,
34193323Sed                               unsigned int> &P1,
35193323Sed                               const std::pair<const llvm::Type*,
36193323Sed                               unsigned int> &P2) {
37193323Sed  return P1.second > P2.second;
38193323Sed}
39193323Sed
40193323Sed/// ValueEnumerator - Enumerate module-level information.
41193323SedValueEnumerator::ValueEnumerator(const Module *M) {
42193323Sed  // Enumerate the global variables.
43193323Sed  for (Module::const_global_iterator I = M->global_begin(),
44193323Sed         E = M->global_end(); I != E; ++I)
45193323Sed    EnumerateValue(I);
46193323Sed
47193323Sed  // Enumerate the functions.
48193323Sed  for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) {
49193323Sed    EnumerateValue(I);
50193323Sed    EnumerateAttributes(cast<Function>(I)->getAttributes());
51193323Sed  }
52193323Sed
53193323Sed  // Enumerate the aliases.
54193323Sed  for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
55193323Sed       I != E; ++I)
56193323Sed    EnumerateValue(I);
57198090Srdivacky
58193323Sed  // Remember what is the cutoff between globalvalue's and other constants.
59193323Sed  unsigned FirstConstant = Values.size();
60198090Srdivacky
61193323Sed  // Enumerate the global variable initializers.
62193323Sed  for (Module::const_global_iterator I = M->global_begin(),
63193323Sed         E = M->global_end(); I != E; ++I)
64193323Sed    if (I->hasInitializer())
65193323Sed      EnumerateValue(I->getInitializer());
66193323Sed
67193323Sed  // Enumerate the aliasees.
68193323Sed  for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
69193323Sed       I != E; ++I)
70193323Sed    EnumerateValue(I->getAliasee());
71198090Srdivacky
72193323Sed  // Enumerate types used by the type symbol table.
73193323Sed  EnumerateTypeSymbolTable(M->getTypeSymbolTable());
74193323Sed
75202375Srdivacky  // Insert constants and metadata  that are named at module level into the slot
76202375Srdivacky  // pool so that the module symbol table can refer to them...
77193323Sed  EnumerateValueSymbolTable(M->getValueSymbolTable());
78202375Srdivacky  EnumerateMDSymbolTable(M->getMDSymbolTable());
79198090Srdivacky
80201360Srdivacky  SmallVector<std::pair<unsigned, MDNode*>, 8> MDs;
81201360Srdivacky
82193323Sed  // Enumerate types used by function bodies and argument lists.
83193323Sed  for (Module::const_iterator F = M->begin(), E = M->end(); F != E; ++F) {
84198090Srdivacky
85193323Sed    for (Function::const_arg_iterator I = F->arg_begin(), E = F->arg_end();
86193323Sed         I != E; ++I)
87193323Sed      EnumerateType(I->getType());
88198090Srdivacky
89193323Sed    for (Function::const_iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
90193323Sed      for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E;++I){
91198090Srdivacky        for (User::const_op_iterator OI = I->op_begin(), E = I->op_end();
92202375Srdivacky             OI != E; ++OI) {
93202375Srdivacky          if (MDNode *MD = dyn_cast<MDNode>(*OI))
94203954Srdivacky            if (MD->isFunctionLocal() && MD->getFunction())
95202375Srdivacky              // These will get enumerated during function-incorporation.
96202375Srdivacky              continue;
97193323Sed          EnumerateOperandType(*OI);
98202375Srdivacky        }
99193323Sed        EnumerateType(I->getType());
100193323Sed        if (const CallInst *CI = dyn_cast<CallInst>(I))
101193323Sed          EnumerateAttributes(CI->getAttributes());
102193323Sed        else if (const InvokeInst *II = dyn_cast<InvokeInst>(I))
103193323Sed          EnumerateAttributes(II->getAttributes());
104198090Srdivacky
105198090Srdivacky        // Enumerate metadata attached with this instruction.
106198396Srdivacky        MDs.clear();
107201360Srdivacky        I->getAllMetadata(MDs);
108201360Srdivacky        for (unsigned i = 0, e = MDs.size(); i != e; ++i)
109201360Srdivacky          EnumerateMetadata(MDs[i].second);
110193323Sed      }
111193323Sed  }
112198090Srdivacky
113193323Sed  // Optimize constant ordering.
114193323Sed  OptimizeConstants(FirstConstant, Values.size());
115198090Srdivacky
116193323Sed  // Sort the type table by frequency so that most commonly used types are early
117193323Sed  // in the table (have low bit-width).
118193323Sed  std::stable_sort(Types.begin(), Types.end(), CompareByFrequency);
119198090Srdivacky
120193323Sed  // Partition the Type ID's so that the single-value types occur before the
121193323Sed  // aggregate types.  This allows the aggregate types to be dropped from the
122193323Sed  // type table after parsing the global variable initializers.
123193323Sed  std::partition(Types.begin(), Types.end(), isSingleValueType);
124193323Sed
125193323Sed  // Now that we rearranged the type table, rebuild TypeMap.
126193323Sed  for (unsigned i = 0, e = Types.size(); i != e; ++i)
127193323Sed    TypeMap[Types[i].first] = i+1;
128193323Sed}
129193323Sed
130198090Srdivackyunsigned ValueEnumerator::getInstructionID(const Instruction *Inst) const {
131198090Srdivacky  InstructionMapType::const_iterator I = InstructionMap.find(Inst);
132198090Srdivacky  assert (I != InstructionMap.end() && "Instruction is not mapped!");
133198090Srdivacky    return I->second;
134198090Srdivacky}
135198090Srdivacky
136198090Srdivackyvoid ValueEnumerator::setInstructionID(const Instruction *I) {
137198090Srdivacky  InstructionMap[I] = InstructionCount++;
138198090Srdivacky}
139198090Srdivacky
140198090Srdivackyunsigned ValueEnumerator::getValueID(const Value *V) const {
141202878Srdivacky  if (isa<MDNode>(V) || isa<MDString>(V)) {
142198090Srdivacky    ValueMapType::const_iterator I = MDValueMap.find(V);
143198090Srdivacky    assert(I != MDValueMap.end() && "Value not in slotcalculator!");
144198090Srdivacky    return I->second-1;
145198090Srdivacky  }
146198090Srdivacky
147198090Srdivacky  ValueMapType::const_iterator I = ValueMap.find(V);
148198090Srdivacky  assert(I != ValueMap.end() && "Value not in slotcalculator!");
149198090Srdivacky  return I->second-1;
150198090Srdivacky}
151198090Srdivacky
152193323Sed// Optimize constant ordering.
153193323Sednamespace {
154193323Sed  struct CstSortPredicate {
155193323Sed    ValueEnumerator &VE;
156193323Sed    explicit CstSortPredicate(ValueEnumerator &ve) : VE(ve) {}
157193323Sed    bool operator()(const std::pair<const Value*, unsigned> &LHS,
158193323Sed                    const std::pair<const Value*, unsigned> &RHS) {
159193323Sed      // Sort by plane.
160193323Sed      if (LHS.first->getType() != RHS.first->getType())
161198090Srdivacky        return VE.getTypeID(LHS.first->getType()) <
162193323Sed               VE.getTypeID(RHS.first->getType());
163193323Sed      // Then by frequency.
164193323Sed      return LHS.second > RHS.second;
165193323Sed    }
166193323Sed  };
167193323Sed}
168193323Sed
169193323Sed/// OptimizeConstants - Reorder constant pool for denser encoding.
170193323Sedvoid ValueEnumerator::OptimizeConstants(unsigned CstStart, unsigned CstEnd) {
171193323Sed  if (CstStart == CstEnd || CstStart+1 == CstEnd) return;
172198090Srdivacky
173193323Sed  CstSortPredicate P(*this);
174193323Sed  std::stable_sort(Values.begin()+CstStart, Values.begin()+CstEnd, P);
175198090Srdivacky
176193323Sed  // Ensure that integer constants are at the start of the constant pool.  This
177193323Sed  // is important so that GEP structure indices come before gep constant exprs.
178193323Sed  std::partition(Values.begin()+CstStart, Values.begin()+CstEnd,
179193323Sed                 isIntegerValue);
180198090Srdivacky
181193323Sed  // Rebuild the modified portion of ValueMap.
182193323Sed  for (; CstStart != CstEnd; ++CstStart)
183193323Sed    ValueMap[Values[CstStart].first] = CstStart+1;
184193323Sed}
185193323Sed
186193323Sed
187193323Sed/// EnumerateTypeSymbolTable - Insert all of the types in the specified symbol
188193323Sed/// table.
189193323Sedvoid ValueEnumerator::EnumerateTypeSymbolTable(const TypeSymbolTable &TST) {
190198090Srdivacky  for (TypeSymbolTable::const_iterator TI = TST.begin(), TE = TST.end();
191193323Sed       TI != TE; ++TI)
192193323Sed    EnumerateType(TI->second);
193193323Sed}
194193323Sed
195193323Sed/// EnumerateValueSymbolTable - Insert all of the values in the specified symbol
196193323Sed/// table into the values table.
197193323Sedvoid ValueEnumerator::EnumerateValueSymbolTable(const ValueSymbolTable &VST) {
198198090Srdivacky  for (ValueSymbolTable::const_iterator VI = VST.begin(), VE = VST.end();
199193323Sed       VI != VE; ++VI)
200193323Sed    EnumerateValue(VI->getValue());
201193323Sed}
202193323Sed
203202375Srdivacky/// EnumerateMDSymbolTable - Insert all of the values in the specified metadata
204202375Srdivacky/// table.
205202375Srdivackyvoid ValueEnumerator::EnumerateMDSymbolTable(const MDSymbolTable &MST) {
206202375Srdivacky  for (MDSymbolTable::const_iterator MI = MST.begin(), ME = MST.end();
207202375Srdivacky       MI != ME; ++MI)
208202375Srdivacky    EnumerateValue(MI->getValue());
209202375Srdivacky}
210202375Srdivacky
211202375Srdivackyvoid ValueEnumerator::EnumerateNamedMDNode(const NamedMDNode *MD) {
212202375Srdivacky  // Check to see if it's already in!
213202375Srdivacky  unsigned &MDValueID = MDValueMap[MD];
214202375Srdivacky  if (MDValueID) {
215202375Srdivacky    // Increment use count.
216202375Srdivacky    MDValues[MDValueID-1].second++;
217202375Srdivacky    return;
218202375Srdivacky  }
219202375Srdivacky
220202375Srdivacky  // Enumerate the type of this value.
221202375Srdivacky  EnumerateType(MD->getType());
222202375Srdivacky
223202375Srdivacky  for (unsigned i = 0, e = MD->getNumOperands(); i != e; ++i)
224202375Srdivacky    if (MDNode *E = MD->getOperand(i))
225202375Srdivacky      EnumerateValue(E);
226202375Srdivacky  MDValues.push_back(std::make_pair(MD, 1U));
227202375Srdivacky  MDValueMap[MD] = Values.size();
228202375Srdivacky}
229202375Srdivacky
230202878Srdivackyvoid ValueEnumerator::EnumerateMetadata(const Value *MD) {
231202878Srdivacky  assert((isa<MDNode>(MD) || isa<MDString>(MD)) && "Invalid metadata kind");
232198090Srdivacky  // Check to see if it's already in!
233198090Srdivacky  unsigned &MDValueID = MDValueMap[MD];
234198090Srdivacky  if (MDValueID) {
235198090Srdivacky    // Increment use count.
236198090Srdivacky    MDValues[MDValueID-1].second++;
237198090Srdivacky    return;
238198090Srdivacky  }
239198090Srdivacky
240198090Srdivacky  // Enumerate the type of this value.
241198090Srdivacky  EnumerateType(MD->getType());
242198090Srdivacky
243198090Srdivacky  if (const MDNode *N = dyn_cast<MDNode>(MD)) {
244198090Srdivacky    MDValues.push_back(std::make_pair(MD, 1U));
245198090Srdivacky    MDValueMap[MD] = MDValues.size();
246198090Srdivacky    MDValueID = MDValues.size();
247202375Srdivacky    for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
248201360Srdivacky      if (Value *V = N->getOperand(i))
249198396Srdivacky        EnumerateValue(V);
250198090Srdivacky      else
251198090Srdivacky        EnumerateType(Type::getVoidTy(MD->getContext()));
252198090Srdivacky    }
253198090Srdivacky    return;
254198892Srdivacky  }
255198892Srdivacky
256198090Srdivacky  // Add the value.
257201360Srdivacky  assert(isa<MDString>(MD) && "Unknown metadata kind");
258198090Srdivacky  MDValues.push_back(std::make_pair(MD, 1U));
259198090Srdivacky  MDValueID = MDValues.size();
260198090Srdivacky}
261198090Srdivacky
262193323Sedvoid ValueEnumerator::EnumerateValue(const Value *V) {
263201360Srdivacky  assert(!V->getType()->isVoidTy() && "Can't insert void values!");
264202878Srdivacky  if (isa<MDNode>(V) || isa<MDString>(V))
265202878Srdivacky    return EnumerateMetadata(V);
266202375Srdivacky  else if (const NamedMDNode *NMD = dyn_cast<NamedMDNode>(V))
267202375Srdivacky    return EnumerateNamedMDNode(NMD);
268198090Srdivacky
269193323Sed  // Check to see if it's already in!
270193323Sed  unsigned &ValueID = ValueMap[V];
271193323Sed  if (ValueID) {
272193323Sed    // Increment use count.
273193323Sed    Values[ValueID-1].second++;
274193323Sed    return;
275193323Sed  }
276193323Sed
277193323Sed  // Enumerate the type of this value.
278193323Sed  EnumerateType(V->getType());
279198090Srdivacky
280193323Sed  if (const Constant *C = dyn_cast<Constant>(V)) {
281193323Sed    if (isa<GlobalValue>(C)) {
282193323Sed      // Initializers for globals are handled explicitly elsewhere.
283193323Sed    } else if (isa<ConstantArray>(C) && cast<ConstantArray>(C)->isString()) {
284193323Sed      // Do not enumerate the initializers for an array of simple characters.
285193323Sed      // The initializers just polute the value table, and we emit the strings
286193323Sed      // specially.
287193323Sed    } else if (C->getNumOperands()) {
288193323Sed      // If a constant has operands, enumerate them.  This makes sure that if a
289193323Sed      // constant has uses (for example an array of const ints), that they are
290193323Sed      // inserted also.
291198090Srdivacky
292193323Sed      // We prefer to enumerate them with values before we enumerate the user
293193323Sed      // itself.  This makes it more likely that we can avoid forward references
294193323Sed      // in the reader.  We know that there can be no cycles in the constants
295193323Sed      // graph that don't go through a global variable.
296193323Sed      for (User::const_op_iterator I = C->op_begin(), E = C->op_end();
297193323Sed           I != E; ++I)
298198892Srdivacky        if (!isa<BasicBlock>(*I)) // Don't enumerate BB operand to BlockAddress.
299198892Srdivacky          EnumerateValue(*I);
300198090Srdivacky
301193323Sed      // Finally, add the value.  Doing this could make the ValueID reference be
302193323Sed      // dangling, don't reuse it.
303193323Sed      Values.push_back(std::make_pair(V, 1U));
304193323Sed      ValueMap[V] = Values.size();
305193323Sed      return;
306193323Sed    }
307193323Sed  }
308198090Srdivacky
309193323Sed  // Add the value.
310193323Sed  Values.push_back(std::make_pair(V, 1U));
311193323Sed  ValueID = Values.size();
312193323Sed}
313193323Sed
314193323Sed
315193323Sedvoid ValueEnumerator::EnumerateType(const Type *Ty) {
316193323Sed  unsigned &TypeID = TypeMap[Ty];
317198090Srdivacky
318193323Sed  if (TypeID) {
319193323Sed    // If we've already seen this type, just increase its occurrence count.
320193323Sed    Types[TypeID-1].second++;
321193323Sed    return;
322193323Sed  }
323198090Srdivacky
324193323Sed  // First time we saw this type, add it.
325193323Sed  Types.push_back(std::make_pair(Ty, 1U));
326193323Sed  TypeID = Types.size();
327198090Srdivacky
328193323Sed  // Enumerate subtypes.
329193323Sed  for (Type::subtype_iterator I = Ty->subtype_begin(), E = Ty->subtype_end();
330193323Sed       I != E; ++I)
331193323Sed    EnumerateType(*I);
332193323Sed}
333193323Sed
334193323Sed// Enumerate the types for the specified value.  If the value is a constant,
335193323Sed// walk through it, enumerating the types of the constant.
336193323Sedvoid ValueEnumerator::EnumerateOperandType(const Value *V) {
337193323Sed  EnumerateType(V->getType());
338202375Srdivacky
339193323Sed  if (const Constant *C = dyn_cast<Constant>(V)) {
340193323Sed    // If this constant is already enumerated, ignore it, we know its type must
341193323Sed    // be enumerated.
342193323Sed    if (ValueMap.count(V)) return;
343193323Sed
344193323Sed    // This constant may have operands, make sure to enumerate the types in
345193323Sed    // them.
346198892Srdivacky    for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i) {
347198892Srdivacky      const User *Op = C->getOperand(i);
348198892Srdivacky
349198892Srdivacky      // Don't enumerate basic blocks here, this happens as operands to
350198892Srdivacky      // blockaddress.
351198892Srdivacky      if (isa<BasicBlock>(Op)) continue;
352198892Srdivacky
353198892Srdivacky      EnumerateOperandType(cast<Constant>(Op));
354198892Srdivacky    }
355193323Sed
356193323Sed    if (const MDNode *N = dyn_cast<MDNode>(V)) {
357201360Srdivacky      for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
358201360Srdivacky        if (Value *Elem = N->getOperand(i))
359198090Srdivacky          EnumerateOperandType(Elem);
360193323Sed    }
361198090Srdivacky  } else if (isa<MDString>(V) || isa<MDNode>(V))
362198090Srdivacky    EnumerateValue(V);
363193323Sed}
364193323Sed
365193323Sedvoid ValueEnumerator::EnumerateAttributes(const AttrListPtr &PAL) {
366193323Sed  if (PAL.isEmpty()) return;  // null is always 0.
367193323Sed  // Do a lookup.
368193323Sed  unsigned &Entry = AttributeMap[PAL.getRawPointer()];
369193323Sed  if (Entry == 0) {
370193323Sed    // Never saw this before, add it.
371193323Sed    Attributes.push_back(PAL);
372193323Sed    Entry = Attributes.size();
373193323Sed  }
374193323Sed}
375193323Sed
376193323Sed
377193323Sedvoid ValueEnumerator::incorporateFunction(const Function &F) {
378204642Srdivacky  InstructionCount = 0;
379193323Sed  NumModuleValues = Values.size();
380198090Srdivacky
381193323Sed  // Adding function arguments to the value table.
382193323Sed  for(Function::const_arg_iterator I = F.arg_begin(), E = F.arg_end();
383193323Sed      I != E; ++I)
384193323Sed    EnumerateValue(I);
385193323Sed
386193323Sed  FirstFuncConstantID = Values.size();
387198090Srdivacky
388193323Sed  // Add all function-level constants to the value table.
389193323Sed  for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
390193323Sed    for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E; ++I)
391198090Srdivacky      for (User::const_op_iterator OI = I->op_begin(), E = I->op_end();
392193323Sed           OI != E; ++OI) {
393193323Sed        if ((isa<Constant>(*OI) && !isa<GlobalValue>(*OI)) ||
394193323Sed            isa<InlineAsm>(*OI))
395193323Sed          EnumerateValue(*OI);
396193323Sed      }
397193323Sed    BasicBlocks.push_back(BB);
398193323Sed    ValueMap[BB] = BasicBlocks.size();
399193323Sed  }
400198090Srdivacky
401193323Sed  // Optimize the constant layout.
402193323Sed  OptimizeConstants(FirstFuncConstantID, Values.size());
403198090Srdivacky
404193323Sed  // Add the function's parameter attributes so they are available for use in
405193323Sed  // the function's instruction.
406193323Sed  EnumerateAttributes(F.getAttributes());
407193323Sed
408193323Sed  FirstInstID = Values.size();
409198090Srdivacky
410203954Srdivacky  SmallVector<MDNode *, 8> FunctionLocalMDs;
411193323Sed  // Add all of the instructions.
412193323Sed  for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
413193323Sed    for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E; ++I) {
414202375Srdivacky      for (User::const_op_iterator OI = I->op_begin(), E = I->op_end();
415202375Srdivacky           OI != E; ++OI) {
416202375Srdivacky        if (MDNode *MD = dyn_cast<MDNode>(*OI))
417203954Srdivacky          if (MD->isFunctionLocal() && MD->getFunction())
418203954Srdivacky            // Enumerate metadata after the instructions they might refer to.
419203954Srdivacky            FunctionLocalMDs.push_back(MD);
420202375Srdivacky      }
421202375Srdivacky      if (!I->getType()->isVoidTy())
422193323Sed        EnumerateValue(I);
423193323Sed    }
424193323Sed  }
425203954Srdivacky
426203954Srdivacky  // Add all of the function-local metadata.
427203954Srdivacky  for (unsigned i = 0, e = FunctionLocalMDs.size(); i != e; ++i)
428203954Srdivacky    EnumerateOperandType(FunctionLocalMDs[i]);
429193323Sed}
430193323Sed
431193323Sedvoid ValueEnumerator::purgeFunction() {
432193323Sed  /// Remove purged values from the ValueMap.
433193323Sed  for (unsigned i = NumModuleValues, e = Values.size(); i != e; ++i)
434193323Sed    ValueMap.erase(Values[i].first);
435193323Sed  for (unsigned i = 0, e = BasicBlocks.size(); i != e; ++i)
436193323Sed    ValueMap.erase(BasicBlocks[i]);
437198090Srdivacky
438193323Sed  Values.resize(NumModuleValues);
439193323Sed  BasicBlocks.clear();
440193323Sed}
441198892Srdivacky
442198892Srdivackystatic void IncorporateFunctionInfoGlobalBBIDs(const Function *F,
443198892Srdivacky                                 DenseMap<const BasicBlock*, unsigned> &IDMap) {
444198892Srdivacky  unsigned Counter = 0;
445198892Srdivacky  for (Function::const_iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
446198892Srdivacky    IDMap[BB] = ++Counter;
447198892Srdivacky}
448198892Srdivacky
449198892Srdivacky/// getGlobalBasicBlockID - This returns the function-specific ID for the
450198892Srdivacky/// specified basic block.  This is relatively expensive information, so it
451198892Srdivacky/// should only be used by rare constructs such as address-of-label.
452198892Srdivackyunsigned ValueEnumerator::getGlobalBasicBlockID(const BasicBlock *BB) const {
453198892Srdivacky  unsigned &Idx = GlobalBasicBlockIDs[BB];
454198892Srdivacky  if (Idx != 0)
455198892Srdivacky    return Idx-1;
456198892Srdivacky
457198892Srdivacky  IncorporateFunctionInfoGlobalBBIDs(BB->getParent(), GlobalBasicBlockIDs);
458198892Srdivacky  return getGlobalBasicBlockID(BB);
459198892Srdivacky}
460198892Srdivacky
461