From b5681b22937440dcb8007f4b125f3325d6341fe0 Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Thu, 22 Oct 2009 18:25:28 +0000 Subject: [PATCH] Using TrackingVH instead of WeakVH or WeakMetadataVH. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84884 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/MachineModuleInfo.h | 3 ++- include/llvm/Metadata.h | 28 +++++------------------- lib/Bitcode/Writer/BitcodeWriter.cpp | 12 +++++----- lib/Bitcode/Writer/ValueEnumerator.cpp | 3 +-- lib/VMCore/AsmWriter.cpp | 8 +++---- lib/VMCore/Metadata.cpp | 12 +++++----- 6 files changed, 22 insertions(+), 44 deletions(-) diff --git a/include/llvm/CodeGen/MachineModuleInfo.h b/include/llvm/CodeGen/MachineModuleInfo.h index 5878d67b939..1b924f28695 100644 --- a/include/llvm/CodeGen/MachineModuleInfo.h +++ b/include/llvm/CodeGen/MachineModuleInfo.h @@ -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, unsigned>, 4 > + VariableDbgInfoMapTy; VariableDbgInfoMapTy VariableDbgInfo; MachineModuleInfo(); diff --git a/include/llvm/Metadata.h b/include/llvm/Metadata.h index 93207b18cc7..63b9e5ae83b 100644 --- a/include/llvm/Metadata.h +++ b/include/llvm/Metadata.h @@ -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(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(const NamedMDNode &); // DO NOT IMPLEMENT Module *Parent; - SmallVector Node; - typedef SmallVectorImpl::iterator elem_iterator; + SmallVector, 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(M)); } - typedef SmallVectorImpl::const_iterator const_elem_iterator; + typedef SmallVectorImpl >::iterator elem_iterator; + typedef SmallVectorImpl >::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 MDPairTy; + typedef std::pair > MDPairTy; typedef SmallVector MDMapTy; typedef DenseMap MDStoreTy; friend class BitcodeReader; diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index 947b8958a12..c8cb59527d3 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -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(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) { diff --git a/lib/Bitcode/Writer/ValueEnumerator.cpp b/lib/Bitcode/Writer/ValueEnumerator.cpp index ca9fc776bf0..4257281a3aa 100644 --- a/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -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(MI->second)) - EnumerateMetadata(MDN); + EnumerateMetadata(MI->second); } } diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index e6ed81ede02..fb1b1ac41c2 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -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(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(MI->second)) - Out << ", !" << MDNames[MI->first] - << " !" << Machine.getMetadataSlot(MD); + Out << ", !" << MDNames[MI->first] + << " !" << Machine.getMetadataSlot(MI->second); } printInfoComment(I); } diff --git a/lib/VMCore/Metadata.cpp b/lib/VMCore/Metadata.cpp index 69b2c6f3f37..f4d60714f99 100644 --- a/lib/VMCore/Metadata.cpp +++ b/lib/VMCore/Metadata.cpp @@ -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(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(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(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(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