forked from OSchip/llvm-project
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:
parent
596760d9bb
commit
218b22f33b
|
@ -472,29 +472,30 @@ bool LLParser::ParseMDString(MetadataBase *&MDS) {
|
||||||
|
|
||||||
// MDNode:
|
// MDNode:
|
||||||
// ::= '!' MDNodeNumber
|
// ::= '!' MDNodeNumber
|
||||||
|
// FIXME: Take an MDNode*&.
|
||||||
bool LLParser::ParseMDNode(MetadataBase *&Node) {
|
bool LLParser::ParseMDNode(MetadataBase *&Node) {
|
||||||
// !{ ..., !42, ... }
|
// !{ ..., !42, ... }
|
||||||
unsigned MID = 0;
|
unsigned MID = 0;
|
||||||
if (ParseUInt32(MID)) return true;
|
if (ParseUInt32(MID)) return true;
|
||||||
|
|
||||||
// Check existing MDNode.
|
// 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()) {
|
if (I != MetadataCache.end()) {
|
||||||
Node = cast<MetadataBase>(I->second);
|
Node = I->second;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check known forward references.
|
// 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);
|
FI = ForwardRefMDNodes.find(MID);
|
||||||
if (FI != ForwardRefMDNodes.end()) {
|
if (FI != ForwardRefMDNodes.end()) {
|
||||||
Node = cast<MetadataBase>(FI->second.first);
|
Node = FI->second.first;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create MDNode forward reference
|
// Create MDNode forward reference
|
||||||
SmallVector<Value *, 1> Elts;
|
|
||||||
std::string FwdRefName = "llvm.mdnode.fwdref." + utostr(MID);
|
std::string FwdRefName = "llvm.mdnode.fwdref." + utostr(MID);
|
||||||
|
SmallVector<Value *, 1> Elts;
|
||||||
Elts.push_back(MDString::get(Context, FwdRefName));
|
Elts.push_back(MDString::get(Context, FwdRefName));
|
||||||
MDNode *FwdNode = MDNode::get(Context, Elts.data(), Elts.size());
|
MDNode *FwdNode = MDNode::get(Context, Elts.data(), Elts.size());
|
||||||
ForwardRefMDNodes[MID] = std::make_pair(FwdNode, Lex.getLoc());
|
ForwardRefMDNodes[MID] = std::make_pair(FwdNode, Lex.getLoc());
|
||||||
|
@ -544,7 +545,7 @@ bool LLParser::ParseStandaloneMetadata() {
|
||||||
unsigned MetadataID = 0;
|
unsigned MetadataID = 0;
|
||||||
if (ParseUInt32(MetadataID))
|
if (ParseUInt32(MetadataID))
|
||||||
return true;
|
return true;
|
||||||
if (MetadataCache.find(MetadataID) != MetadataCache.end())
|
if (MetadataCache.count(MetadataID))
|
||||||
return TokError("Metadata id is already used");
|
return TokError("Metadata id is already used");
|
||||||
if (ParseToken(lltok::equal, "expected '=' here"))
|
if (ParseToken(lltok::equal, "expected '=' here"))
|
||||||
return true;
|
return true;
|
||||||
|
@ -568,11 +569,10 @@ bool LLParser::ParseStandaloneMetadata() {
|
||||||
|
|
||||||
MDNode *Init = MDNode::get(Context, Elts.data(), Elts.size());
|
MDNode *Init = MDNode::get(Context, Elts.data(), Elts.size());
|
||||||
MetadataCache[MetadataID] = Init;
|
MetadataCache[MetadataID] = Init;
|
||||||
std::map<unsigned, std::pair<WeakVH, LocTy> >::iterator
|
std::map<unsigned, std::pair<TrackingVH<MDNode>, LocTy> >::iterator
|
||||||
FI = ForwardRefMDNodes.find(MetadataID);
|
FI = ForwardRefMDNodes.find(MetadataID);
|
||||||
if (FI != ForwardRefMDNodes.end()) {
|
if (FI != ForwardRefMDNodes.end()) {
|
||||||
MDNode *FwdNode = cast<MDNode>(FI->second.first);
|
FI->second.first->replaceAllUsesWith(Init);
|
||||||
FwdNode->replaceAllUsesWith(Init);
|
|
||||||
ForwardRefMDNodes.erase(FI);
|
ForwardRefMDNodes.erase(FI);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
#include "LLLexer.h"
|
#include "LLLexer.h"
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
#include "llvm/Type.h"
|
#include "llvm/Type.h"
|
||||||
#include <map>
|
|
||||||
#include "llvm/Support/ValueHandle.h"
|
#include "llvm/Support/ValueHandle.h"
|
||||||
|
#include <map>
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
class Module;
|
class Module;
|
||||||
|
@ -80,8 +80,8 @@ namespace llvm {
|
||||||
std::map<unsigned, std::pair<PATypeHolder, LocTy> > ForwardRefTypeIDs;
|
std::map<unsigned, std::pair<PATypeHolder, LocTy> > ForwardRefTypeIDs;
|
||||||
std::vector<PATypeHolder> NumberedTypes;
|
std::vector<PATypeHolder> NumberedTypes;
|
||||||
/// MetadataCache - This map keeps track of parsed metadata constants.
|
/// MetadataCache - This map keeps track of parsed metadata constants.
|
||||||
std::map<unsigned, WeakVH> MetadataCache;
|
std::map<unsigned, TrackingVH<MDNode> > MetadataCache;
|
||||||
std::map<unsigned, std::pair<WeakVH, LocTy> > ForwardRefMDNodes;
|
std::map<unsigned, std::pair<TrackingVH<MDNode>, LocTy> > ForwardRefMDNodes;
|
||||||
SmallVector<std::pair<unsigned, MDNode *>, 2> MDsOnInst;
|
SmallVector<std::pair<unsigned, MDNode *>, 2> MDsOnInst;
|
||||||
struct UpRefRecord {
|
struct UpRefRecord {
|
||||||
/// Loc - This is the location of the upref.
|
/// Loc - This is the location of the upref.
|
||||||
|
|
Loading…
Reference in New Issue