[llvm-branch-commits] [llvm-branch] r134828 - /llvm/branches/type-system-rewrite/lib/VMCore/Module.cpp
Chris Lattner
sabre at nondot.org
Sat Jul 9 10:20:31 PDT 2011
Author: lattner
Date: Sat Jul 9 12:20:31 2011
New Revision: 134828
URL: http://llvm.org/viewvc/llvm-project?rev=134828&view=rev
Log:
fix a bug where we didn't enumerate struct types that were only referenced by MDNodes.
Modified:
llvm/branches/type-system-rewrite/lib/VMCore/Module.cpp
Modified: llvm/branches/type-system-rewrite/lib/VMCore/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/type-system-rewrite/lib/VMCore/Module.cpp?rev=134828&r1=134827&r2=134828&view=diff
==============================================================================
--- llvm/branches/type-system-rewrite/lib/VMCore/Module.cpp (original)
+++ llvm/branches/type-system-rewrite/lib/VMCore/Module.cpp Sat Jul 9 12:20:31 2011
@@ -460,6 +460,8 @@
incorporateValue(Aliasee);
}
+ SmallVector<std::pair<unsigned, MDNode*>, 4> MDForInst;
+
// Get types from functions.
for (Module::const_iterator FI = M.begin(), E = M.end(); FI != E; ++FI) {
incorporateType(FI->getType());
@@ -474,8 +476,21 @@
for (User::const_op_iterator OI = I.op_begin(), OE = I.op_end();
OI != OE; ++OI)
incorporateValue(*OI);
+
+ // Incorporate types hiding in metadata.
+ I.getAllMetadata(MDForInst);
+ for (unsigned i = 0, e = MDForInst.size(); i != e; ++i)
+ incorporateMDNode(MDForInst[i].second);
+ MDForInst.clear();
}
}
+
+ for (Module::const_named_metadata_iterator I = M.named_metadata_begin(),
+ E = M.named_metadata_end(); I != E; ++I) {
+ const NamedMDNode *NMD = I;
+ for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i)
+ incorporateMDNode(NMD->getOperand(i));
+ }
}
private:
@@ -499,6 +514,8 @@
/// walked in other ways. GlobalValues, basic blocks, instructions, and
/// inst operands are all explicitly enumerated.
void incorporateValue(const Value *V) {
+ if (const MDNode *M = dyn_cast<MDNode>(V))
+ return incorporateMDNode(M);
if (!isa<Constant>(V) || isa<GlobalValue>(V)) return;
// Already visited?
@@ -509,11 +526,23 @@
incorporateType(V->getType());
// Look in operands for types.
- const Constant *C = cast<Constant>(V);
- for (Constant::const_op_iterator I = C->op_begin(),
- E = C->op_end(); I != E;++I)
+ const User *U = cast<User>(V);
+ for (Constant::const_op_iterator I = U->op_begin(),
+ E = U->op_end(); I != E;++I)
incorporateValue(*I);
}
+
+ void incorporateMDNode(const MDNode *V) {
+
+ // Already visited?
+ if (!VisitedConstants.insert(V).second)
+ return;
+
+ // Look in operands for types.
+ for (unsigned i = 0, e = V->getNumOperands(); i != e; ++i)
+ if (Value *Op = V->getOperand(i))
+ incorporateValue(Op);
+ }
};
} // end anonymous namespace
More information about the llvm-branch-commits
mailing list