Using TrackingVH instead of WeakVH or WeakMetadataVH.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84884 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Devang Patel 2009-10-22 18:25:28 +00:00
parent d41fc65c56
commit b5681b2293
6 changed files with 22 additions and 44 deletions

View File

@ -150,7 +150,8 @@ class MachineModuleInfo : public ImmutablePass {
public:
static char ID; // Pass identification, replacement for typeid
typedef SmallVector< std::pair< WeakMetadataVH, unsigned>, 4 > VariableDbgInfoMapTy;
typedef SmallVector< std::pair<TrackingVH<MDNode>, unsigned>, 4 >
VariableDbgInfoMapTy;
VariableDbgInfoMapTy VariableDbgInfo;
MachineModuleInfo();

View File

@ -143,23 +143,6 @@ public:
}
};
//===----------------------------------------------------------------------===//
/// WeakMetadataVH - a weak value handle for metadata.
class WeakMetadataVH : public WeakVH {
public:
WeakMetadataVH() : WeakVH() {}
WeakMetadataVH(MetadataBase *M) : WeakVH(M) {}
WeakMetadataVH(const WeakMetadataVH &RHS) : WeakVH(RHS) {}
operator Value*() const {
llvm_unreachable("WeakMetadataVH only handles Metadata");
}
operator MetadataBase*() const {
return dyn_cast_or_null<MetadataBase>(getValPtr());
}
};
//===----------------------------------------------------------------------===//
/// NamedMDNode - a tuple of other metadata.
/// NamedMDNode is always named. All NamedMDNode element has a type of metadata.
@ -173,8 +156,7 @@ class NamedMDNode : public MetadataBase, public ilist_node<NamedMDNode> {
NamedMDNode(const NamedMDNode &); // DO NOT IMPLEMENT
Module *Parent;
SmallVector<WeakMetadataVH, 4> Node;
typedef SmallVectorImpl<WeakMetadataVH>::iterator elem_iterator;
SmallVector<TrackingVH<MetadataBase>, 4> Node;
void setParent(Module *M) { Parent = M; }
protected:
@ -216,10 +198,12 @@ public:
/// addElement - Add metadata element.
void addElement(MetadataBase *M) {
Node.push_back(WeakMetadataVH(M));
Node.push_back(TrackingVH<MetadataBase>(M));
}
typedef SmallVectorImpl<WeakMetadataVH>::const_iterator const_elem_iterator;
typedef SmallVectorImpl<TrackingVH<MetadataBase> >::iterator elem_iterator;
typedef SmallVectorImpl<TrackingVH<MetadataBase> >::const_iterator
const_elem_iterator;
bool elem_empty() const { return Node.empty(); }
const_elem_iterator elem_begin() const { return Node.begin(); }
const_elem_iterator elem_end() const { return Node.end(); }
@ -241,7 +225,7 @@ public:
/// is [a-zA-Z$._][a-zA-Z$._0-9]*
class MetadataContext {
public:
typedef std::pair<unsigned, WeakVH> MDPairTy;
typedef std::pair<unsigned, TrackingVH<MDNode> > MDPairTy;
typedef SmallVector<MDPairTy, 2> MDMapTy;
typedef DenseMap<const Instruction *, MDMapTy> MDStoreTy;
friend class BitcodeReader;

View File

@ -569,14 +569,12 @@ static void WriteMetadataAttachment(const Function &F,
bool RecordedInstruction = false;
for (MetadataContext::MDMapTy::const_iterator PI = P->begin(),
PE = P->end(); PI != PE; ++PI) {
if (MDNode *ND = dyn_cast_or_null<MDNode>(PI->second)) {
if (RecordedInstruction == false) {
Record.push_back(VE.getInstructionID(I));
RecordedInstruction = true;
}
Record.push_back(PI->first);
Record.push_back(VE.getValueID(ND));
if (RecordedInstruction == false) {
Record.push_back(VE.getInstructionID(I));
RecordedInstruction = true;
}
Record.push_back(PI->first);
Record.push_back(VE.getValueID(PI->second));
}
if (!Record.empty()) {
if (!StartedMetadataBlock) {

View File

@ -103,8 +103,7 @@ ValueEnumerator::ValueEnumerator(const Module *M) {
if (MDs)
for (MetadataContext::MDMapTy::const_iterator MI = MDs->begin(),
ME = MDs->end(); MI != ME; ++MI)
if (MDNode *MDN = dyn_cast_or_null<MDNode>(MI->second))
EnumerateMetadata(MDN);
EnumerateMetadata(MI->second);
}
}

View File

@ -700,8 +700,7 @@ void SlotTracker::processFunction() {
if (MDs)
for (MetadataContext::MDMapTy::const_iterator MI = MDs->begin(),
ME = MDs->end(); MI != ME; ++MI)
if (MDNode *MDN = dyn_cast_or_null<MDNode>(MI->second))
CreateMetadataSlot(MDN);
CreateMetadataSlot(MI->second);
}
}
@ -2039,9 +2038,8 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
if (MDMap)
for (MetadataContext::MDMapTy::const_iterator MI = MDMap->begin(),
ME = MDMap->end(); MI != ME; ++MI)
if (const MDNode *MD = dyn_cast_or_null<MDNode>(MI->second))
Out << ", !" << MDNames[MI->first]
<< " !" << Machine.getMetadataSlot(MD);
Out << ", !" << MDNames[MI->first]
<< " !" << Machine.getMetadataSlot(MI->second);
}
printInfoComment(I);
}

View File

@ -34,7 +34,7 @@ MDString *MDString::get(LLVMContext &Context, StringRef Str) {
if (S) return S;
return S =
new MDString(Context, StringRef(Entry.getKeyData(), Entry.getKeyLength()));
new MDString(Context, Entry.getKey());
}
//===----------------------------------------------------------------------===//
@ -151,7 +151,7 @@ NamedMDNode::NamedMDNode(LLVMContext &C, const Twine &N,
setName(N);
for (unsigned i = 0; i != NumMDs; ++i)
Node.push_back(WeakMetadataVH(MDs[i]));
Node.push_back(TrackingVH<MetadataBase>(MDs[i]));
if (ParentModule)
ParentModule->getNamedMDList().push_back(this);
@ -277,8 +277,7 @@ void MetadataContext::copyMD(Instruction *In1, Instruction *In2) {
return;
for (MDMapTy::iterator I = In1Info.begin(), E = In1Info.end(); I != E; ++I)
if (MDNode *MD = dyn_cast_or_null<MDNode>(I->second))
addMD(I->first, MD, In2);
addMD(I->first, I->second, In2);
}
/// getMD - Get the metadata of given kind attached to an Instruction.
@ -290,7 +289,7 @@ MDNode *MetadataContext::getMD(unsigned MDKind, const Instruction *Inst) {
for (MDMapTy::iterator I = Info.begin(), E = Info.end(); I != E; ++I)
if (I->first == MDKind)
return dyn_cast_or_null<MDNode>(I->second);
return I->second;
return NULL;
}
@ -326,8 +325,7 @@ void MetadataContext::ValueIsCloned(const Instruction *In1, Instruction *In2) {
MDMapTy &In1Info = I->second;
MDMapTy In2Info;
for (MDMapTy::iterator I = In1Info.begin(), E = In1Info.end(); I != E; ++I)
if (MDNode *MD = dyn_cast_or_null<MDNode>(I->second))
addMD(I->first, MD, In2);
addMD(I->first, I->second, In2);
}
/// ValueIsRAUWd - This handler is used when V1's all uses are replaced by