llvm.org GIT mirror llvm / ab9cd10
Enumerate function-local metadata (and its types and operands) only during function-incorporation, global metadata continues to be enumerated during creation of ValueEnumerator git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93338 91177308-0d34-0410-b5e6-96231b3b80d8 Victor Hernandez 10 years ago
2 changed file(s) with 35 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
9191 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E;++I){
9292 for (User::const_op_iterator OI = I->op_begin(), E = I->op_end();
9393 OI != E; ++OI)
94 EnumerateOperandType(*OI);
94 EnumerateOperandType(*OI, true);
9595 EnumerateType(I->getType());
9696 if (const CallInst *CI = dyn_cast(I))
9797 EnumerateAttributes(CI->getAttributes());
102102 MDs.clear();
103103 I->getAllMetadata(MDs);
104104 for (unsigned i = 0, e = MDs.size(); i != e; ++i)
105 EnumerateMetadata(MDs[i].second);
105 EnumerateMetadata(MDs[i].second, true);
106106 }
107107 }
108108
223223 MDValueMap[MD] = Values.size();
224224 }
225225
226 void ValueEnumerator::EnumerateMetadata(const MetadataBase *MD) {
226 void ValueEnumerator::EnumerateMetadata(const MetadataBase *MD, bool isGlobal) {
227227 // Check to see if it's already in!
228228 unsigned &MDValueID = MDValueMap[MD];
229229 if (MDValueID) {
236236 EnumerateType(MD->getType());
237237
238238 if (const MDNode *N = dyn_cast(MD)) {
239 MDValues.push_back(std::make_pair(MD, 1U));
240 MDValueMap[MD] = MDValues.size();
241 MDValueID = MDValues.size();
242 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
243 if (Value *V = N->getOperand(i))
244 EnumerateValue(V);
245 else
246 EnumerateType(Type::getVoidTy(MD->getContext()));
239 if ((isGlobal && !N->isFunctionLocal()) ||
240 (!isGlobal && N->isFunctionLocal())) {
241 MDValues.push_back(std::make_pair(MD, 1U));
242 MDValueMap[MD] = MDValues.size();
243 MDValueID = MDValues.size();
244 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
245 if (Value *V = N->getOperand(i))
246 EnumerateValue(V);
247 else
248 EnumerateType(Type::getVoidTy(MD->getContext()));
249 }
250 return;
247251 }
248252 return;
249253 }
254258 MDValueID = MDValues.size();
255259 }
256260
257 void ValueEnumerator::EnumerateValue(const Value *V) {
261 void ValueEnumerator::EnumerateValue(const Value *V, bool isGlobal) {
258262 assert(!V->getType()->isVoidTy() && "Can't insert void values!");
259263 if (const MetadataBase *MB = dyn_cast(V))
260 return EnumerateMetadata(MB);
264 return EnumerateMetadata(MB, isGlobal);
261265 else if (const NamedMDNode *NMD = dyn_cast(V))
262266 return EnumerateNamedMDNode(NMD);
263267
291295 for (User::const_op_iterator I = C->op_begin(), E = C->op_end();
292296 I != E; ++I)
293297 if (!isa(*I)) // Don't enumerate BB operand to BlockAddress.
294 EnumerateValue(*I);
298 EnumerateValue(*I, isGlobal);
295299
296300 // Finally, add the value. Doing this could make the ValueID reference be
297301 // dangling, don't reuse it.
328332
329333 // Enumerate the types for the specified value. If the value is a constant,
330334 // walk through it, enumerating the types of the constant.
331 void ValueEnumerator::EnumerateOperandType(const Value *V) {
335 void ValueEnumerator::EnumerateOperandType(const Value *V, bool isGlobal) {
332336 EnumerateType(V->getType());
337
338 // During function-incorporation, only enumerate metadata operands.
339 if (!isGlobal)
340 if (const MetadataBase *MB = dyn_cast(V))
341 return EnumerateMetadata(MB, isGlobal);
342
333343 if (const Constant *C = dyn_cast(V)) {
334344 // If this constant is already enumerated, ignore it, we know its type must
335345 // be enumerated.
344354 // blockaddress.
345355 if (isa(Op)) continue;
346356
347 EnumerateOperandType(cast(Op));
357 EnumerateOperandType(cast(Op), isGlobal);
348358 }
349359
350360 if (const MDNode *N = dyn_cast(V)) {
351361 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
352362 if (Value *Elem = N->getOperand(i))
353 EnumerateOperandType(Elem);
363 EnumerateOperandType(Elem, isGlobal);
354364 }
355365 } else if (isa(V) || isa(V))
356366 EnumerateValue(V);
403413 // Add all of the instructions.
404414 for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
405415 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E; ++I) {
416 for (User::const_op_iterator OI = I->op_begin(), E = I->op_end();
417 OI != E; ++OI) {
418 EnumerateOperandType(*OI, false);
419 }
406420 if (!I->getType()->isVoidTy())
407421 EnumerateValue(I);
408422 }
104104
105105 const ValueList &getValues() const { return Values; }
106106 const ValueList &getMDValues() const { return MDValues; }
107 ValueList getMDValues() { return MDValues; }
107108 const TypeList &getTypes() const { return Types; }
108109 const std::vector &getBasicBlocks() const {
109110 return BasicBlocks;
126127 private:
127128 void OptimizeConstants(unsigned CstStart, unsigned CstEnd);
128129
129 void EnumerateMetadata(const MetadataBase *MD);
130 void EnumerateMetadata(const MetadataBase *MD, bool isGlobal);
130131 void EnumerateNamedMDNode(const NamedMDNode *NMD);
131 void EnumerateValue(const Value *V);
132 void EnumerateValue(const Value *V, bool isGlobal = true);
132133 void EnumerateType(const Type *T);
133 void EnumerateOperandType(const Value *V);
134 void EnumerateOperandType(const Value *V, bool isGlobal);
134135 void EnumerateAttributes(const AttrListPtr &PAL);
135136
136137 void EnumerateTypeSymbolTable(const TypeSymbolTable &ST);