Chris Lattner | fd57cec | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 1 | //===-- ValueEnumerator.cpp - Number values and types for bitcode writer --===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | fd57cec | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the ValueEnumerator class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "ValueEnumerator.h" |
Chris Lattner | ff7fc5d | 2007-05-06 00:35:24 +0000 | [diff] [blame] | 15 | #include "llvm/Constants.h" |
Chris Lattner | 50954f5 | 2007-05-03 22:46:43 +0000 | [diff] [blame] | 16 | #include "llvm/DerivedTypes.h" |
Devang Patel | 0a9f7b9 | 2009-07-28 21:49:47 +0000 | [diff] [blame] | 17 | #include "llvm/Metadata.h" |
Chris Lattner | fd57cec | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 18 | #include "llvm/Module.h" |
| 19 | #include "llvm/TypeSymbolTable.h" |
| 20 | #include "llvm/ValueSymbolTable.h" |
Duncan Sands | dc02467 | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 21 | #include "llvm/Instructions.h" |
Chris Lattner | 12f535b | 2007-05-04 05:05:48 +0000 | [diff] [blame] | 22 | #include <algorithm> |
Chris Lattner | fd57cec | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 23 | using namespace llvm; |
| 24 | |
Dan Gohman | e4977cf | 2008-05-23 01:55:30 +0000 | [diff] [blame] | 25 | static bool isSingleValueType(const std::pair<const llvm::Type*, |
| 26 | unsigned int> &P) { |
| 27 | return P.first->isSingleValueType(); |
Chris Lattner | 12f535b | 2007-05-04 05:05:48 +0000 | [diff] [blame] | 28 | } |
| 29 | |
Chris Lattner | 6da91d3 | 2007-05-04 05:21:47 +0000 | [diff] [blame] | 30 | static bool isIntegerValue(const std::pair<const Value*, unsigned> &V) { |
| 31 | return isa<IntegerType>(V.first->getType()); |
| 32 | } |
| 33 | |
Chris Lattner | 12f535b | 2007-05-04 05:05:48 +0000 | [diff] [blame] | 34 | static bool CompareByFrequency(const std::pair<const llvm::Type*, |
| 35 | unsigned int> &P1, |
| 36 | const std::pair<const llvm::Type*, |
| 37 | unsigned int> &P2) { |
| 38 | return P1.second > P2.second; |
| 39 | } |
| 40 | |
Chris Lattner | fd57cec | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 41 | /// ValueEnumerator - Enumerate module-level information. |
| 42 | ValueEnumerator::ValueEnumerator(const Module *M) { |
| 43 | // Enumerate the global variables. |
| 44 | for (Module::const_global_iterator I = M->global_begin(), |
| 45 | E = M->global_end(); I != E; ++I) |
| 46 | EnumerateValue(I); |
| 47 | |
| 48 | // Enumerate the functions. |
Duncan Sands | dc02467 | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 49 | for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) { |
Chris Lattner | fd57cec | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 50 | EnumerateValue(I); |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 51 | EnumerateAttributes(cast<Function>(I)->getAttributes()); |
Duncan Sands | dc02467 | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 52 | } |
Chris Lattner | fd57cec | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 53 | |
Chris Lattner | 07d98b4 | 2007-04-26 02:46:40 +0000 | [diff] [blame] | 54 | // Enumerate the aliases. |
| 55 | for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end(); |
| 56 | I != E; ++I) |
| 57 | EnumerateValue(I); |
| 58 | |
Chris Lattner | 6da91d3 | 2007-05-04 05:21:47 +0000 | [diff] [blame] | 59 | // Remember what is the cutoff between globalvalue's and other constants. |
| 60 | unsigned FirstConstant = Values.size(); |
| 61 | |
Chris Lattner | fd57cec | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 62 | // Enumerate the global variable initializers. |
| 63 | for (Module::const_global_iterator I = M->global_begin(), |
| 64 | E = M->global_end(); I != E; ++I) |
| 65 | if (I->hasInitializer()) |
| 66 | EnumerateValue(I->getInitializer()); |
| 67 | |
Chris Lattner | 07d98b4 | 2007-04-26 02:46:40 +0000 | [diff] [blame] | 68 | // Enumerate the aliasees. |
| 69 | for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end(); |
| 70 | I != E; ++I) |
| 71 | EnumerateValue(I->getAliasee()); |
| 72 | |
Chris Lattner | fd57cec | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 73 | // Enumerate types used by the type symbol table. |
| 74 | EnumerateTypeSymbolTable(M->getTypeSymbolTable()); |
| 75 | |
| 76 | // Insert constants that are named at module level into the slot pool so that |
| 77 | // the module symbol table can refer to them... |
| 78 | EnumerateValueSymbolTable(M->getValueSymbolTable()); |
| 79 | |
Chris Lattner | 8d35c79 | 2007-04-26 03:50:57 +0000 | [diff] [blame] | 80 | // Enumerate types used by function bodies and argument lists. |
Chris Lattner | fd57cec | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 81 | for (Module::const_iterator F = M->begin(), E = M->end(); F != E; ++F) { |
Chris Lattner | 8d35c79 | 2007-04-26 03:50:57 +0000 | [diff] [blame] | 82 | |
| 83 | for (Function::const_arg_iterator I = F->arg_begin(), E = F->arg_end(); |
| 84 | I != E; ++I) |
| 85 | EnumerateType(I->getType()); |
| 86 | |
Chris Lattner | fd57cec | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 87 | for (Function::const_iterator BB = F->begin(), E = F->end(); BB != E; ++BB) |
| 88 | for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E;++I){ |
| 89 | for (User::const_op_iterator OI = I->op_begin(), E = I->op_end(); |
| 90 | OI != E; ++OI) |
Chris Lattner | 33f1d5b | 2007-05-06 08:35:19 +0000 | [diff] [blame] | 91 | EnumerateOperandType(*OI); |
Chris Lattner | fd57cec | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 92 | EnumerateType(I->getType()); |
Duncan Sands | dc02467 | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 93 | if (const CallInst *CI = dyn_cast<CallInst>(I)) |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 94 | EnumerateAttributes(CI->getAttributes()); |
Duncan Sands | dc02467 | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 95 | else if (const InvokeInst *II = dyn_cast<InvokeInst>(I)) |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 96 | EnumerateAttributes(II->getAttributes()); |
Chris Lattner | fd57cec | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 97 | } |
| 98 | } |
Chris Lattner | 12f535b | 2007-05-04 05:05:48 +0000 | [diff] [blame] | 99 | |
Chris Lattner | 6da91d3 | 2007-05-04 05:21:47 +0000 | [diff] [blame] | 100 | // Optimize constant ordering. |
| 101 | OptimizeConstants(FirstConstant, Values.size()); |
| 102 | |
Chris Lattner | 12f535b | 2007-05-04 05:05:48 +0000 | [diff] [blame] | 103 | // Sort the type table by frequency so that most commonly used types are early |
| 104 | // in the table (have low bit-width). |
| 105 | std::stable_sort(Types.begin(), Types.end(), CompareByFrequency); |
Chris Lattner | fd57cec | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 106 | |
Dan Gohman | e4977cf | 2008-05-23 01:55:30 +0000 | [diff] [blame] | 107 | // Partition the Type ID's so that the single-value types occur before the |
Chris Lattner | 12f535b | 2007-05-04 05:05:48 +0000 | [diff] [blame] | 108 | // aggregate types. This allows the aggregate types to be dropped from the |
| 109 | // type table after parsing the global variable initializers. |
Dan Gohman | e4977cf | 2008-05-23 01:55:30 +0000 | [diff] [blame] | 110 | std::partition(Types.begin(), Types.end(), isSingleValueType); |
Chris Lattner | 12f535b | 2007-05-04 05:05:48 +0000 | [diff] [blame] | 111 | |
| 112 | // Now that we rearranged the type table, rebuild TypeMap. |
| 113 | for (unsigned i = 0, e = Types.size(); i != e; ++i) |
| 114 | TypeMap[Types[i].first] = i+1; |
Chris Lattner | fd57cec | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Chris Lattner | 6da91d3 | 2007-05-04 05:21:47 +0000 | [diff] [blame] | 117 | // Optimize constant ordering. |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 118 | namespace { |
| 119 | struct CstSortPredicate { |
| 120 | ValueEnumerator &VE; |
| 121 | explicit CstSortPredicate(ValueEnumerator &ve) : VE(ve) {} |
| 122 | bool operator()(const std::pair<const Value*, unsigned> &LHS, |
| 123 | const std::pair<const Value*, unsigned> &RHS) { |
| 124 | // Sort by plane. |
| 125 | if (LHS.first->getType() != RHS.first->getType()) |
| 126 | return VE.getTypeID(LHS.first->getType()) < |
| 127 | VE.getTypeID(RHS.first->getType()); |
| 128 | // Then by frequency. |
| 129 | return LHS.second > RHS.second; |
| 130 | } |
| 131 | }; |
| 132 | } |
Chris Lattner | 6da91d3 | 2007-05-04 05:21:47 +0000 | [diff] [blame] | 133 | |
| 134 | /// OptimizeConstants - Reorder constant pool for denser encoding. |
| 135 | void ValueEnumerator::OptimizeConstants(unsigned CstStart, unsigned CstEnd) { |
| 136 | if (CstStart == CstEnd || CstStart+1 == CstEnd) return; |
| 137 | |
| 138 | CstSortPredicate P(*this); |
| 139 | std::stable_sort(Values.begin()+CstStart, Values.begin()+CstEnd, P); |
| 140 | |
| 141 | // Ensure that integer constants are at the start of the constant pool. This |
| 142 | // is important so that GEP structure indices come before gep constant exprs. |
| 143 | std::partition(Values.begin()+CstStart, Values.begin()+CstEnd, |
| 144 | isIntegerValue); |
| 145 | |
| 146 | // Rebuild the modified portion of ValueMap. |
| 147 | for (; CstStart != CstEnd; ++CstStart) |
| 148 | ValueMap[Values[CstStart].first] = CstStart+1; |
| 149 | } |
| 150 | |
| 151 | |
Chris Lattner | fd57cec | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 152 | /// EnumerateTypeSymbolTable - Insert all of the types in the specified symbol |
| 153 | /// table. |
| 154 | void ValueEnumerator::EnumerateTypeSymbolTable(const TypeSymbolTable &TST) { |
| 155 | for (TypeSymbolTable::const_iterator TI = TST.begin(), TE = TST.end(); |
| 156 | TI != TE; ++TI) |
| 157 | EnumerateType(TI->second); |
| 158 | } |
| 159 | |
| 160 | /// EnumerateValueSymbolTable - Insert all of the values in the specified symbol |
| 161 | /// table into the values table. |
| 162 | void ValueEnumerator::EnumerateValueSymbolTable(const ValueSymbolTable &VST) { |
| 163 | for (ValueSymbolTable::const_iterator VI = VST.begin(), VE = VST.end(); |
| 164 | VI != VE; ++VI) |
| 165 | EnumerateValue(VI->getValue()); |
| 166 | } |
| 167 | |
| 168 | void ValueEnumerator::EnumerateValue(const Value *V) { |
| 169 | assert(V->getType() != Type::VoidTy && "Can't insert void values!"); |
| 170 | |
| 171 | // Check to see if it's already in! |
| 172 | unsigned &ValueID = ValueMap[V]; |
| 173 | if (ValueID) { |
| 174 | // Increment use count. |
| 175 | Values[ValueID-1].second++; |
| 176 | return; |
| 177 | } |
Chris Lattner | fd57cec | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 178 | |
Chris Lattner | 7a303d1 | 2007-05-06 01:00:28 +0000 | [diff] [blame] | 179 | // Enumerate the type of this value. |
| 180 | EnumerateType(V->getType()); |
| 181 | |
Chris Lattner | fd57cec | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 182 | if (const Constant *C = dyn_cast<Constant>(V)) { |
| 183 | if (isa<GlobalValue>(C)) { |
| 184 | // Initializers for globals are handled explicitly elsewhere. |
Chris Lattner | ff7fc5d | 2007-05-06 00:35:24 +0000 | [diff] [blame] | 185 | } else if (isa<ConstantArray>(C) && cast<ConstantArray>(C)->isString()) { |
| 186 | // Do not enumerate the initializers for an array of simple characters. |
| 187 | // The initializers just polute the value table, and we emit the strings |
| 188 | // specially. |
Chris Lattner | 7a303d1 | 2007-05-06 01:00:28 +0000 | [diff] [blame] | 189 | } else if (C->getNumOperands()) { |
| 190 | // If a constant has operands, enumerate them. This makes sure that if a |
| 191 | // constant has uses (for example an array of const ints), that they are |
| 192 | // inserted also. |
| 193 | |
| 194 | // We prefer to enumerate them with values before we enumerate the user |
| 195 | // itself. This makes it more likely that we can avoid forward references |
| 196 | // in the reader. We know that there can be no cycles in the constants |
| 197 | // graph that don't go through a global variable. |
Chris Lattner | fd57cec | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 198 | for (User::const_op_iterator I = C->op_begin(), E = C->op_end(); |
| 199 | I != E; ++I) |
| 200 | EnumerateValue(*I); |
Chris Lattner | 7a303d1 | 2007-05-06 01:00:28 +0000 | [diff] [blame] | 201 | |
| 202 | // Finally, add the value. Doing this could make the ValueID reference be |
| 203 | // dangling, don't reuse it. |
| 204 | Values.push_back(std::make_pair(V, 1U)); |
| 205 | ValueMap[V] = Values.size(); |
| 206 | return; |
Chris Lattner | fd57cec | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 207 | } |
| 208 | } |
Devang Patel | 104cf9e | 2009-07-23 01:07:34 +0000 | [diff] [blame] | 209 | |
| 210 | if (const MDNode *N = dyn_cast<MDNode>(V)) { |
| 211 | Values.push_back(std::make_pair(V, 1U)); |
| 212 | ValueMap[V] = Values.size(); |
| 213 | ValueID = Values.size(); |
| 214 | for (MDNode::const_elem_iterator I = N->elem_begin(), E = N->elem_end(); |
| 215 | I != E; ++I) { |
| 216 | if (*I) |
| 217 | EnumerateValue(*I); |
| 218 | else |
| 219 | EnumerateType(Type::VoidTy); |
| 220 | } |
| 221 | return; |
| 222 | } |
| 223 | |
Chris Lattner | 7a303d1 | 2007-05-06 01:00:28 +0000 | [diff] [blame] | 224 | // Add the value. |
| 225 | Values.push_back(std::make_pair(V, 1U)); |
| 226 | ValueID = Values.size(); |
Chris Lattner | fd57cec | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | |
| 230 | void ValueEnumerator::EnumerateType(const Type *Ty) { |
| 231 | unsigned &TypeID = TypeMap[Ty]; |
| 232 | |
| 233 | if (TypeID) { |
| 234 | // If we've already seen this type, just increase its occurrence count. |
| 235 | Types[TypeID-1].second++; |
| 236 | return; |
| 237 | } |
| 238 | |
| 239 | // First time we saw this type, add it. |
| 240 | Types.push_back(std::make_pair(Ty, 1U)); |
| 241 | TypeID = Types.size(); |
| 242 | |
| 243 | // Enumerate subtypes. |
| 244 | for (Type::subtype_iterator I = Ty->subtype_begin(), E = Ty->subtype_end(); |
| 245 | I != E; ++I) |
| 246 | EnumerateType(*I); |
| 247 | } |
| 248 | |
Chris Lattner | 33f1d5b | 2007-05-06 08:35:19 +0000 | [diff] [blame] | 249 | // Enumerate the types for the specified value. If the value is a constant, |
| 250 | // walk through it, enumerating the types of the constant. |
| 251 | void ValueEnumerator::EnumerateOperandType(const Value *V) { |
| 252 | EnumerateType(V->getType()); |
| 253 | if (const Constant *C = dyn_cast<Constant>(V)) { |
| 254 | // If this constant is already enumerated, ignore it, we know its type must |
| 255 | // be enumerated. |
| 256 | if (ValueMap.count(V)) return; |
| 257 | |
| 258 | // This constant may have operands, make sure to enumerate the types in |
| 259 | // them. |
| 260 | for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i) |
| 261 | EnumerateOperandType(C->getOperand(i)); |
Nick Lewycky | cb33799 | 2009-05-10 20:57:05 +0000 | [diff] [blame] | 262 | |
| 263 | if (const MDNode *N = dyn_cast<MDNode>(V)) { |
Devang Patel | e54abc9 | 2009-07-22 17:43:22 +0000 | [diff] [blame] | 264 | for (unsigned i = 0, e = N->getNumElements(); i != e; ++i) { |
| 265 | Value *Elem = N->getElement(i); |
| 266 | if (Elem) |
| 267 | EnumerateOperandType(Elem); |
| 268 | } |
Nick Lewycky | cb33799 | 2009-05-10 20:57:05 +0000 | [diff] [blame] | 269 | } |
Devang Patel | 104cf9e | 2009-07-23 01:07:34 +0000 | [diff] [blame] | 270 | } else if (isa<MDString>(V) || isa<MDNode>(V)) |
Devang Patel | e54abc9 | 2009-07-22 17:43:22 +0000 | [diff] [blame] | 271 | EnumerateValue(V); |
Chris Lattner | 33f1d5b | 2007-05-06 08:35:19 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 274 | void ValueEnumerator::EnumerateAttributes(const AttrListPtr &PAL) { |
Chris Lattner | 58d7491 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 275 | if (PAL.isEmpty()) return; // null is always 0. |
Chris Lattner | 50954f5 | 2007-05-03 22:46:43 +0000 | [diff] [blame] | 276 | // Do a lookup. |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 277 | unsigned &Entry = AttributeMap[PAL.getRawPointer()]; |
Chris Lattner | 50954f5 | 2007-05-03 22:46:43 +0000 | [diff] [blame] | 278 | if (Entry == 0) { |
| 279 | // Never saw this before, add it. |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 280 | Attributes.push_back(PAL); |
| 281 | Entry = Attributes.size(); |
Chris Lattner | 50954f5 | 2007-05-03 22:46:43 +0000 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | |
| 285 | |
Chris Lattner | 8d35c79 | 2007-04-26 03:50:57 +0000 | [diff] [blame] | 286 | void ValueEnumerator::incorporateFunction(const Function &F) { |
Chris Lattner | b9d0c2a | 2007-04-26 05:53:54 +0000 | [diff] [blame] | 287 | NumModuleValues = Values.size(); |
Chris Lattner | fd57cec | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 288 | |
Chris Lattner | 8d35c79 | 2007-04-26 03:50:57 +0000 | [diff] [blame] | 289 | // Adding function arguments to the value table. |
| 290 | for(Function::const_arg_iterator I = F.arg_begin(), E = F.arg_end(); |
Chris Lattner | fd57cec | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 291 | I != E; ++I) |
Chris Lattner | 8d35c79 | 2007-04-26 03:50:57 +0000 | [diff] [blame] | 292 | EnumerateValue(I); |
| 293 | |
Chris Lattner | b9d0c2a | 2007-04-26 05:53:54 +0000 | [diff] [blame] | 294 | FirstFuncConstantID = Values.size(); |
| 295 | |
Chris Lattner | 8d35c79 | 2007-04-26 03:50:57 +0000 | [diff] [blame] | 296 | // Add all function-level constants to the value table. |
| 297 | for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { |
| 298 | for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E; ++I) |
| 299 | for (User::const_op_iterator OI = I->op_begin(), E = I->op_end(); |
| 300 | OI != E; ++OI) { |
| 301 | if ((isa<Constant>(*OI) && !isa<GlobalValue>(*OI)) || |
| 302 | isa<InlineAsm>(*OI)) |
| 303 | EnumerateValue(*OI); |
| 304 | } |
Chris Lattner | c59c0af | 2007-04-26 04:42:16 +0000 | [diff] [blame] | 305 | BasicBlocks.push_back(BB); |
Chris Lattner | e825ed5 | 2007-05-03 22:18:21 +0000 | [diff] [blame] | 306 | ValueMap[BB] = BasicBlocks.size(); |
Chris Lattner | 8d35c79 | 2007-04-26 03:50:57 +0000 | [diff] [blame] | 307 | } |
Chris Lattner | fd57cec | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 308 | |
Chris Lattner | 6da91d3 | 2007-05-04 05:21:47 +0000 | [diff] [blame] | 309 | // Optimize the constant layout. |
| 310 | OptimizeConstants(FirstFuncConstantID, Values.size()); |
| 311 | |
Duncan Sands | dc02467 | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 312 | // Add the function's parameter attributes so they are available for use in |
| 313 | // the function's instruction. |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 314 | EnumerateAttributes(F.getAttributes()); |
Duncan Sands | dc02467 | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 315 | |
Chris Lattner | b9d0c2a | 2007-04-26 05:53:54 +0000 | [diff] [blame] | 316 | FirstInstID = Values.size(); |
| 317 | |
Chris Lattner | 8d35c79 | 2007-04-26 03:50:57 +0000 | [diff] [blame] | 318 | // Add all of the instructions. |
| 319 | for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { |
Chris Lattner | fd57cec | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 320 | for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E; ++I) { |
| 321 | if (I->getType() != Type::VoidTy) |
Chris Lattner | 8d35c79 | 2007-04-26 03:50:57 +0000 | [diff] [blame] | 322 | EnumerateValue(I); |
Chris Lattner | fd57cec | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 323 | } |
| 324 | } |
Chris Lattner | fd57cec | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 325 | } |
| 326 | |
Chris Lattner | 8d35c79 | 2007-04-26 03:50:57 +0000 | [diff] [blame] | 327 | void ValueEnumerator::purgeFunction() { |
| 328 | /// Remove purged values from the ValueMap. |
Chris Lattner | b9d0c2a | 2007-04-26 05:53:54 +0000 | [diff] [blame] | 329 | for (unsigned i = NumModuleValues, e = Values.size(); i != e; ++i) |
Chris Lattner | 8d35c79 | 2007-04-26 03:50:57 +0000 | [diff] [blame] | 330 | ValueMap.erase(Values[i].first); |
Chris Lattner | c59c0af | 2007-04-26 04:42:16 +0000 | [diff] [blame] | 331 | for (unsigned i = 0, e = BasicBlocks.size(); i != e; ++i) |
| 332 | ValueMap.erase(BasicBlocks[i]); |
| 333 | |
Chris Lattner | b9d0c2a | 2007-04-26 05:53:54 +0000 | [diff] [blame] | 334 | Values.resize(NumModuleValues); |
Chris Lattner | c59c0af | 2007-04-26 04:42:16 +0000 | [diff] [blame] | 335 | BasicBlocks.clear(); |
Chris Lattner | fd57cec | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 336 | } |
| 337 | |