blob: a6da44f77aeab8edf10936267c84a7dcc8f43c9e [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===-- ValueEnumerator.cpp - Number values and types for bitcode writer --===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the ValueEnumerator class.
11//
12//===----------------------------------------------------------------------===//
13
14#include "ValueEnumerator.h"
15#include "llvm/Constants.h"
16#include "llvm/DerivedTypes.h"
17#include "llvm/Module.h"
18#include "llvm/TypeSymbolTable.h"
19#include "llvm/ValueSymbolTable.h"
Duncan Sandsf5588dc2007-11-27 13:23:08 +000020#include "llvm/Instructions.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000021#include <algorithm>
22using namespace llvm;
23
Dan Gohmane6b1ee62008-05-23 01:55:30 +000024static bool isSingleValueType(const std::pair<const llvm::Type*,
25 unsigned int> &P) {
26 return P.first->isSingleValueType();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000027}
28
29static bool isIntegerValue(const std::pair<const Value*, unsigned> &V) {
30 return isa<IntegerType>(V.first->getType());
31}
32
33static bool CompareByFrequency(const std::pair<const llvm::Type*,
34 unsigned int> &P1,
35 const std::pair<const llvm::Type*,
36 unsigned int> &P2) {
37 return P1.second > P2.second;
38}
39
40/// ValueEnumerator - Enumerate module-level information.
41ValueEnumerator::ValueEnumerator(const Module *M) {
Devang Pateladc37612009-09-18 19:26:43 +000042 InstructionCount = 0;
43
Dan Gohmanf17a25c2007-07-18 16:29:46 +000044 // Enumerate the global variables.
45 for (Module::const_global_iterator I = M->global_begin(),
46 E = M->global_end(); I != E; ++I)
47 EnumerateValue(I);
48
49 // Enumerate the functions.
Duncan Sandsf5588dc2007-11-27 13:23:08 +000050 for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000051 EnumerateValue(I);
Devang Pateld222f862008-09-25 21:00:45 +000052 EnumerateAttributes(cast<Function>(I)->getAttributes());
Duncan Sandsf5588dc2007-11-27 13:23:08 +000053 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +000054
55 // Enumerate the aliases.
56 for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
57 I != E; ++I)
58 EnumerateValue(I);
Daniel Dunbar3be44e62009-09-20 02:20:51 +000059
Dan Gohmanf17a25c2007-07-18 16:29:46 +000060 // Remember what is the cutoff between globalvalue's and other constants.
61 unsigned FirstConstant = Values.size();
Daniel Dunbar3be44e62009-09-20 02:20:51 +000062
Dan Gohmanf17a25c2007-07-18 16:29:46 +000063 // Enumerate the global variable initializers.
64 for (Module::const_global_iterator I = M->global_begin(),
65 E = M->global_end(); I != E; ++I)
66 if (I->hasInitializer())
67 EnumerateValue(I->getInitializer());
68
69 // Enumerate the aliasees.
70 for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
71 I != E; ++I)
72 EnumerateValue(I->getAliasee());
Daniel Dunbar3be44e62009-09-20 02:20:51 +000073
Dan Gohmanf17a25c2007-07-18 16:29:46 +000074 // Enumerate types used by the type symbol table.
75 EnumerateTypeSymbolTable(M->getTypeSymbolTable());
76
77 // Insert constants that are named at module level into the slot pool so that
78 // the module symbol table can refer to them...
79 EnumerateValueSymbolTable(M->getValueSymbolTable());
Daniel Dunbar3be44e62009-09-20 02:20:51 +000080
Dan Gohmanf17a25c2007-07-18 16:29:46 +000081 // Enumerate types used by function bodies and argument lists.
82 for (Module::const_iterator F = M->begin(), E = M->end(); F != E; ++F) {
Daniel Dunbar3be44e62009-09-20 02:20:51 +000083
Dan Gohmanf17a25c2007-07-18 16:29:46 +000084 for (Function::const_arg_iterator I = F->arg_begin(), E = F->arg_end();
85 I != E; ++I)
86 EnumerateType(I->getType());
Devang Pateladc37612009-09-18 19:26:43 +000087
Chris Lattnerdcf06572009-12-28 23:41:32 +000088 SmallVector<std::pair<unsigned, MDNode*>, 2> MDs;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000089 for (Function::const_iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
90 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E;++I){
Daniel Dunbar3be44e62009-09-20 02:20:51 +000091 for (User::const_op_iterator OI = I->op_begin(), E = I->op_end();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000092 OI != E; ++OI)
93 EnumerateOperandType(*OI);
94 EnumerateType(I->getType());
Duncan Sandsf5588dc2007-11-27 13:23:08 +000095 if (const CallInst *CI = dyn_cast<CallInst>(I))
Devang Pateld222f862008-09-25 21:00:45 +000096 EnumerateAttributes(CI->getAttributes());
Duncan Sandsf5588dc2007-11-27 13:23:08 +000097 else if (const InvokeInst *II = dyn_cast<InvokeInst>(I))
Devang Pateld222f862008-09-25 21:00:45 +000098 EnumerateAttributes(II->getAttributes());
Devang Pateladc37612009-09-18 19:26:43 +000099
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000100 // Enumerate metadata attached with this instruction.
Devang Patel0f6f8942009-10-22 18:55:16 +0000101 MDs.clear();
Chris Lattnerdcf06572009-12-28 23:41:32 +0000102 I->getAllMetadata(MDs);
103 for (unsigned i = 0, e = MDs.size(); i != e; ++i)
104 EnumerateMetadata(MDs[i].second);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000105 }
106 }
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000107
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000108 // Optimize constant ordering.
109 OptimizeConstants(FirstConstant, Values.size());
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000110
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000111 // Sort the type table by frequency so that most commonly used types are early
112 // in the table (have low bit-width).
113 std::stable_sort(Types.begin(), Types.end(), CompareByFrequency);
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000114
Dan Gohmane6b1ee62008-05-23 01:55:30 +0000115 // Partition the Type ID's so that the single-value types occur before the
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000116 // aggregate types. This allows the aggregate types to be dropped from the
117 // type table after parsing the global variable initializers.
Dan Gohmane6b1ee62008-05-23 01:55:30 +0000118 std::partition(Types.begin(), Types.end(), isSingleValueType);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000119
120 // Now that we rearranged the type table, rebuild TypeMap.
121 for (unsigned i = 0, e = Types.size(); i != e; ++i)
122 TypeMap[Types[i].first] = i+1;
123}
124
Devang Pateladc37612009-09-18 19:26:43 +0000125unsigned ValueEnumerator::getInstructionID(const Instruction *Inst) const {
126 InstructionMapType::const_iterator I = InstructionMap.find(Inst);
127 assert (I != InstructionMap.end() && "Instruction is not mapped!");
128 return I->second;
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000129}
Devang Pateladc37612009-09-18 19:26:43 +0000130
131void ValueEnumerator::setInstructionID(const Instruction *I) {
132 InstructionMap[I] = InstructionCount++;
133}
134
Devang Patelea27c232009-08-04 06:00:18 +0000135unsigned ValueEnumerator::getValueID(const Value *V) const {
136 if (isa<MetadataBase>(V)) {
137 ValueMapType::const_iterator I = MDValueMap.find(V);
138 assert(I != MDValueMap.end() && "Value not in slotcalculator!");
139 return I->second-1;
140 }
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000141
Devang Patelea27c232009-08-04 06:00:18 +0000142 ValueMapType::const_iterator I = ValueMap.find(V);
143 assert(I != ValueMap.end() && "Value not in slotcalculator!");
144 return I->second-1;
145}
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000146
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000147// Optimize constant ordering.
Dan Gohman089efff2008-05-13 00:00:25 +0000148namespace {
149 struct CstSortPredicate {
150 ValueEnumerator &VE;
151 explicit CstSortPredicate(ValueEnumerator &ve) : VE(ve) {}
152 bool operator()(const std::pair<const Value*, unsigned> &LHS,
153 const std::pair<const Value*, unsigned> &RHS) {
154 // Sort by plane.
155 if (LHS.first->getType() != RHS.first->getType())
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000156 return VE.getTypeID(LHS.first->getType()) <
Dan Gohman089efff2008-05-13 00:00:25 +0000157 VE.getTypeID(RHS.first->getType());
158 // Then by frequency.
159 return LHS.second > RHS.second;
160 }
161 };
162}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000163
164/// OptimizeConstants - Reorder constant pool for denser encoding.
165void ValueEnumerator::OptimizeConstants(unsigned CstStart, unsigned CstEnd) {
166 if (CstStart == CstEnd || CstStart+1 == CstEnd) return;
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000167
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000168 CstSortPredicate P(*this);
169 std::stable_sort(Values.begin()+CstStart, Values.begin()+CstEnd, P);
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000170
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000171 // Ensure that integer constants are at the start of the constant pool. This
172 // is important so that GEP structure indices come before gep constant exprs.
173 std::partition(Values.begin()+CstStart, Values.begin()+CstEnd,
174 isIntegerValue);
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000175
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000176 // Rebuild the modified portion of ValueMap.
177 for (; CstStart != CstEnd; ++CstStart)
178 ValueMap[Values[CstStart].first] = CstStart+1;
179}
180
181
182/// EnumerateTypeSymbolTable - Insert all of the types in the specified symbol
183/// table.
184void ValueEnumerator::EnumerateTypeSymbolTable(const TypeSymbolTable &TST) {
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000185 for (TypeSymbolTable::const_iterator TI = TST.begin(), TE = TST.end();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000186 TI != TE; ++TI)
187 EnumerateType(TI->second);
188}
189
190/// EnumerateValueSymbolTable - Insert all of the values in the specified symbol
191/// table into the values table.
192void ValueEnumerator::EnumerateValueSymbolTable(const ValueSymbolTable &VST) {
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000193 for (ValueSymbolTable::const_iterator VI = VST.begin(), VE = VST.end();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000194 VI != VE; ++VI)
195 EnumerateValue(VI->getValue());
196}
197
Devang Patelea27c232009-08-04 06:00:18 +0000198void ValueEnumerator::EnumerateMetadata(const MetadataBase *MD) {
199 // Check to see if it's already in!
200 unsigned &MDValueID = MDValueMap[MD];
201 if (MDValueID) {
202 // Increment use count.
203 MDValues[MDValueID-1].second++;
204 return;
205 }
206
207 // Enumerate the type of this value.
208 EnumerateType(MD->getType());
209
210 if (const MDNode *N = dyn_cast<MDNode>(MD)) {
211 MDValues.push_back(std::make_pair(MD, 1U));
212 MDValueMap[MD] = MDValues.size();
213 MDValueID = MDValues.size();
Devang Patel26c7b902009-10-21 21:25:09 +0000214 for (unsigned i = 0, e = N->getNumElements(); i != e; ++i) {
215 if (Value *V = N->getElement(i))
216 EnumerateValue(V);
Devang Patelea27c232009-08-04 06:00:18 +0000217 else
Owen Anderson35b47072009-08-13 21:58:54 +0000218 EnumerateType(Type::getVoidTy(MD->getContext()));
Devang Patelea27c232009-08-04 06:00:18 +0000219 }
220 return;
Chris Lattnerd5693a22009-10-28 05:24:40 +0000221 }
222
223 if (const NamedMDNode *N = dyn_cast<NamedMDNode>(MD)) {
Chris Lattner59a5a2e2009-12-28 07:57:01 +0000224 for (unsigned i = 0, e = N->getNumElements(); i != e; ++i)
225 EnumerateValue(N->getElement(i));
Devang Patelea27c232009-08-04 06:00:18 +0000226 MDValues.push_back(std::make_pair(MD, 1U));
227 MDValueMap[MD] = Values.size();
228 return;
229 }
230
231 // Add the value.
232 MDValues.push_back(std::make_pair(MD, 1U));
233 MDValueID = MDValues.size();
234}
235
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000236void ValueEnumerator::EnumerateValue(const Value *V) {
Owen Anderson35b47072009-08-13 21:58:54 +0000237 assert(V->getType() != Type::getVoidTy(V->getContext()) &&
238 "Can't insert void values!");
Devang Patelea27c232009-08-04 06:00:18 +0000239 if (const MetadataBase *MB = dyn_cast<MetadataBase>(V))
240 return EnumerateMetadata(MB);
241
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000242 // Check to see if it's already in!
243 unsigned &ValueID = ValueMap[V];
244 if (ValueID) {
245 // Increment use count.
246 Values[ValueID-1].second++;
247 return;
248 }
249
250 // Enumerate the type of this value.
251 EnumerateType(V->getType());
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000252
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000253 if (const Constant *C = dyn_cast<Constant>(V)) {
254 if (isa<GlobalValue>(C)) {
255 // Initializers for globals are handled explicitly elsewhere.
256 } else if (isa<ConstantArray>(C) && cast<ConstantArray>(C)->isString()) {
257 // Do not enumerate the initializers for an array of simple characters.
258 // The initializers just polute the value table, and we emit the strings
259 // specially.
260 } else if (C->getNumOperands()) {
261 // If a constant has operands, enumerate them. This makes sure that if a
262 // constant has uses (for example an array of const ints), that they are
263 // inserted also.
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000264
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000265 // We prefer to enumerate them with values before we enumerate the user
266 // itself. This makes it more likely that we can avoid forward references
267 // in the reader. We know that there can be no cycles in the constants
268 // graph that don't go through a global variable.
269 for (User::const_op_iterator I = C->op_begin(), E = C->op_end();
270 I != E; ++I)
Chris Lattner620cead2009-11-01 01:27:45 +0000271 if (!isa<BasicBlock>(*I)) // Don't enumerate BB operand to BlockAddress.
272 EnumerateValue(*I);
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000273
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000274 // Finally, add the value. Doing this could make the ValueID reference be
275 // dangling, don't reuse it.
276 Values.push_back(std::make_pair(V, 1U));
277 ValueMap[V] = Values.size();
278 return;
279 }
280 }
Devang Patel54199ef2009-07-23 01:07:34 +0000281
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000282 // Add the value.
283 Values.push_back(std::make_pair(V, 1U));
284 ValueID = Values.size();
285}
286
287
288void ValueEnumerator::EnumerateType(const Type *Ty) {
289 unsigned &TypeID = TypeMap[Ty];
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000290
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000291 if (TypeID) {
292 // If we've already seen this type, just increase its occurrence count.
293 Types[TypeID-1].second++;
294 return;
295 }
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000296
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000297 // First time we saw this type, add it.
298 Types.push_back(std::make_pair(Ty, 1U));
299 TypeID = Types.size();
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000300
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000301 // Enumerate subtypes.
302 for (Type::subtype_iterator I = Ty->subtype_begin(), E = Ty->subtype_end();
303 I != E; ++I)
304 EnumerateType(*I);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000305}
306
307// Enumerate the types for the specified value. If the value is a constant,
308// walk through it, enumerating the types of the constant.
309void ValueEnumerator::EnumerateOperandType(const Value *V) {
310 EnumerateType(V->getType());
311 if (const Constant *C = dyn_cast<Constant>(V)) {
312 // If this constant is already enumerated, ignore it, we know its type must
313 // be enumerated.
314 if (ValueMap.count(V)) return;
315
316 // This constant may have operands, make sure to enumerate the types in
317 // them.
Chris Lattnerd5693a22009-10-28 05:24:40 +0000318 for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i) {
319 const User *Op = C->getOperand(i);
320
321 // Don't enumerate basic blocks here, this happens as operands to
322 // blockaddress.
323 if (isa<BasicBlock>(Op)) continue;
324
325 EnumerateOperandType(cast<Constant>(Op));
326 }
Nick Lewycky117f4382009-05-10 20:57:05 +0000327
328 if (const MDNode *N = dyn_cast<MDNode>(V)) {
Chris Lattnerd5693a22009-10-28 05:24:40 +0000329 for (unsigned i = 0, e = N->getNumElements(); i != e; ++i)
330 if (Value *Elem = N->getElement(i))
Devang Patel0c0a6ca2009-07-22 17:43:22 +0000331 EnumerateOperandType(Elem);
Nick Lewycky117f4382009-05-10 20:57:05 +0000332 }
Devang Patel54199ef2009-07-23 01:07:34 +0000333 } else if (isa<MDString>(V) || isa<MDNode>(V))
Devang Patel0c0a6ca2009-07-22 17:43:22 +0000334 EnumerateValue(V);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000335}
336
Devang Pateld222f862008-09-25 21:00:45 +0000337void ValueEnumerator::EnumerateAttributes(const AttrListPtr &PAL) {
Chris Lattner1c8733e2008-03-12 17:45:29 +0000338 if (PAL.isEmpty()) return; // null is always 0.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000339 // Do a lookup.
Devang Pateld222f862008-09-25 21:00:45 +0000340 unsigned &Entry = AttributeMap[PAL.getRawPointer()];
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000341 if (Entry == 0) {
342 // Never saw this before, add it.
Devang Pateld222f862008-09-25 21:00:45 +0000343 Attributes.push_back(PAL);
344 Entry = Attributes.size();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000345 }
346}
347
348
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000349void ValueEnumerator::incorporateFunction(const Function &F) {
350 NumModuleValues = Values.size();
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000351
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000352 // Adding function arguments to the value table.
353 for(Function::const_arg_iterator I = F.arg_begin(), E = F.arg_end();
354 I != E; ++I)
355 EnumerateValue(I);
356
357 FirstFuncConstantID = Values.size();
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000358
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000359 // Add all function-level constants to the value table.
360 for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
361 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E; ++I)
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000362 for (User::const_op_iterator OI = I->op_begin(), E = I->op_end();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000363 OI != E; ++OI) {
364 if ((isa<Constant>(*OI) && !isa<GlobalValue>(*OI)) ||
365 isa<InlineAsm>(*OI))
366 EnumerateValue(*OI);
367 }
368 BasicBlocks.push_back(BB);
369 ValueMap[BB] = BasicBlocks.size();
370 }
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000371
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000372 // Optimize the constant layout.
373 OptimizeConstants(FirstFuncConstantID, Values.size());
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000374
Duncan Sandsf5588dc2007-11-27 13:23:08 +0000375 // Add the function's parameter attributes so they are available for use in
376 // the function's instruction.
Devang Pateld222f862008-09-25 21:00:45 +0000377 EnumerateAttributes(F.getAttributes());
Duncan Sandsf5588dc2007-11-27 13:23:08 +0000378
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000379 FirstInstID = Values.size();
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000380
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000381 // Add all of the instructions.
382 for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
383 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E; ++I) {
Owen Anderson35b47072009-08-13 21:58:54 +0000384 if (I->getType() != Type::getVoidTy(F.getContext()))
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000385 EnumerateValue(I);
386 }
387 }
388}
389
390void ValueEnumerator::purgeFunction() {
391 /// Remove purged values from the ValueMap.
392 for (unsigned i = NumModuleValues, e = Values.size(); i != e; ++i)
393 ValueMap.erase(Values[i].first);
394 for (unsigned i = 0, e = BasicBlocks.size(); i != e; ++i)
395 ValueMap.erase(BasicBlocks[i]);
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000396
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000397 Values.resize(NumModuleValues);
398 BasicBlocks.clear();
399}
Chris Lattnerd5693a22009-10-28 05:24:40 +0000400
401static void IncorporateFunctionInfoGlobalBBIDs(const Function *F,
402 DenseMap<const BasicBlock*, unsigned> &IDMap) {
403 unsigned Counter = 0;
404 for (Function::const_iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
405 IDMap[BB] = ++Counter;
406}
407
408/// getGlobalBasicBlockID - This returns the function-specific ID for the
409/// specified basic block. This is relatively expensive information, so it
410/// should only be used by rare constructs such as address-of-label.
411unsigned ValueEnumerator::getGlobalBasicBlockID(const BasicBlock *BB) const {
412 unsigned &Idx = GlobalBasicBlockIDs[BB];
413 if (Idx != 0)
Chris Lattner620cead2009-11-01 01:27:45 +0000414 return Idx-1;
Chris Lattnerd5693a22009-10-28 05:24:40 +0000415
416 IncorporateFunctionInfoGlobalBBIDs(BB->getParent(), GlobalBasicBlockIDs);
417 return getGlobalBasicBlockID(BB);
418}
419