switch to TrackingVH instead of WeakVH, since these can never

be RAUW'd and go to null.  This also gets us some sorely lacking
type safety.

llvm-svn: 92272
This commit is contained in:
Chris Lattner 2009-12-29 21:43:58 +00:00
parent c6b925c592
commit bfd6a6f096
2 changed files with 13 additions and 13 deletions

View File

@ -472,29 +472,30 @@ bool LLParser::ParseMDString(MetadataBase *&MDS) {
// MDNode:
// ::= '!' MDNodeNumber
// FIXME: Take an MDNode*&.
bool LLParser::ParseMDNode(MetadataBase *&Node) {
// !{ ..., !42, ... }
unsigned MID = 0;
if (ParseUInt32(MID)) return true;
if (ParseUInt32(MID)) return true;
// Check existing MDNode.
std::map<unsigned, WeakVH>::iterator I = MetadataCache.find(MID);
std::map<unsigned, TrackingVH<MDNode> >::iterator I = MetadataCache.find(MID);
if (I != MetadataCache.end()) {
Node = cast<MetadataBase>(I->second);
Node = I->second;
return false;
}
// Check known forward references.
std::map<unsigned, std::pair<WeakVH, LocTy> >::iterator
std::map<unsigned, std::pair<TrackingVH<MDNode>, LocTy> >::iterator
FI = ForwardRefMDNodes.find(MID);
if (FI != ForwardRefMDNodes.end()) {
Node = cast<MetadataBase>(FI->second.first);
Node = FI->second.first;
return false;
}
// Create MDNode forward reference
SmallVector<Value *, 1> Elts;
std::string FwdRefName = "llvm.mdnode.fwdref." + utostr(MID);
SmallVector<Value *, 1> Elts;
Elts.push_back(MDString::get(Context, FwdRefName));
MDNode *FwdNode = MDNode::get(Context, Elts.data(), Elts.size());
ForwardRefMDNodes[MID] = std::make_pair(FwdNode, Lex.getLoc());
@ -544,7 +545,7 @@ bool LLParser::ParseStandaloneMetadata() {
unsigned MetadataID = 0;
if (ParseUInt32(MetadataID))
return true;
if (MetadataCache.find(MetadataID) != MetadataCache.end())
if (MetadataCache.count(MetadataID))
return TokError("Metadata id is already used");
if (ParseToken(lltok::equal, "expected '=' here"))
return true;
@ -568,11 +569,10 @@ bool LLParser::ParseStandaloneMetadata() {
MDNode *Init = MDNode::get(Context, Elts.data(), Elts.size());
MetadataCache[MetadataID] = Init;
std::map<unsigned, std::pair<WeakVH, LocTy> >::iterator
std::map<unsigned, std::pair<TrackingVH<MDNode>, LocTy> >::iterator
FI = ForwardRefMDNodes.find(MetadataID);
if (FI != ForwardRefMDNodes.end()) {
MDNode *FwdNode = cast<MDNode>(FI->second.first);
FwdNode->replaceAllUsesWith(Init);
FI->second.first->replaceAllUsesWith(Init);
ForwardRefMDNodes.erase(FI);
}

View File

@ -17,8 +17,8 @@
#include "LLLexer.h"
#include "llvm/Module.h"
#include "llvm/Type.h"
#include <map>
#include "llvm/Support/ValueHandle.h"
#include <map>
namespace llvm {
class Module;
@ -80,8 +80,8 @@ namespace llvm {
std::map<unsigned, std::pair<PATypeHolder, LocTy> > ForwardRefTypeIDs;
std::vector<PATypeHolder> NumberedTypes;
/// MetadataCache - This map keeps track of parsed metadata constants.
std::map<unsigned, WeakVH> MetadataCache;
std::map<unsigned, std::pair<WeakVH, LocTy> > ForwardRefMDNodes;
std::map<unsigned, TrackingVH<MDNode> > MetadataCache;
std::map<unsigned, std::pair<TrackingVH<MDNode>, LocTy> > ForwardRefMDNodes;
SmallVector<std::pair<unsigned, MDNode *>, 2> MDsOnInst;
struct UpRefRecord {
/// Loc - This is the location of the upref.