diff options
author | Owen Anderson <resistor@mac.com> | 2009-07-31 21:35:40 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2009-07-31 21:35:40 +0000 |
commit | 20be0583b5be721cb7065e7f4c4c4ad6a5e655e7 (patch) | |
tree | b7139544af240b94b3627101328ed7a81e3b9580 | |
parent | 7603480121a24dfd3e6f8343412c591a46bf8486 (diff) | |
download | external_llvm-20be0583b5be721cb7065e7f4c4c4ad6a5e655e7.zip external_llvm-20be0583b5be721cb7065e7f4c4c4ad6a5e655e7.tar.gz external_llvm-20be0583b5be721cb7065e7f4c4c4ad6a5e655e7.tar.bz2 |
Move the metadata constructors back to 2.5 syntax.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77733 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/LLVMContext.h | 13 | ||||
-rw-r--r-- | include/llvm/Metadata.h | 9 | ||||
-rw-r--r-- | lib/AsmParser/LLParser.cpp | 10 | ||||
-rw-r--r-- | lib/Bitcode/Reader/BitcodeReader.cpp | 5 | ||||
-rw-r--r-- | lib/VMCore/LLVMContext.cpp | 18 | ||||
-rw-r--r-- | lib/VMCore/LLVMContextImpl.cpp | 49 | ||||
-rw-r--r-- | lib/VMCore/LLVMContextImpl.h | 9 | ||||
-rw-r--r-- | lib/VMCore/Metadata.cpp | 41 |
8 files changed, 60 insertions, 94 deletions
diff --git a/include/llvm/LLVMContext.h b/include/llvm/LLVMContext.h index 9150e61..038ee35 100644 --- a/include/llvm/LLVMContext.h +++ b/include/llvm/LLVMContext.h @@ -61,20 +61,11 @@ class LLVMContext { friend class ConstantArray; friend class ConstantVector; friend class ConstantAggregateZero; + friend class MDNode; + friend class MDString; public: LLVMContext(); ~LLVMContext(); - - // MDNode accessors - MDNode* getMDNode(Value* const* Vals, unsigned NumVals); - - // MDString accessors - MDString* getMDString(const StringRef &Str); - - - // Methods for erasing constants - void erase(MDString *M); - void erase(MDNode *M); }; /// FOR BACKWARDS COMPATIBILITY - Returns a global context. diff --git a/include/llvm/Metadata.h b/include/llvm/Metadata.h index 7526919..95100c2 100644 --- a/include/llvm/Metadata.h +++ b/include/llvm/Metadata.h @@ -27,6 +27,7 @@ namespace llvm { class Constant; +class LLVMContext; //===----------------------------------------------------------------------===// // MetadataBase - A base class for MDNode, MDString and NamedMDNode. @@ -64,13 +65,14 @@ public: class MDString : public MetadataBase { MDString(const MDString &); // DO NOT IMPLEMENT StringRef Str; - friend class LLVMContextImpl; protected: explicit MDString(const char *begin, unsigned l) : MetadataBase(Type::MetadataTy, Value::MDStringVal), Str(begin, l) {} public: + static MDString *get(LLVMContext &Context, const StringRef &Str); + StringRef getString() const { return Str; } unsigned length() const { return Str.size(); } @@ -97,14 +99,15 @@ public: class MDNode : public MetadataBase, public FoldingSetNode { MDNode(const MDNode &); // DO NOT IMPLEMENT - friend class LLVMContextImpl; - SmallVector<WeakVH, 4> Node; typedef SmallVectorImpl<WeakVH>::iterator elem_iterator; protected: explicit MDNode(Value*const* Vals, unsigned NumVals); public: + static MDNode *get(LLVMContext &Context, + Value* const* Vals, unsigned NumVals); + typedef SmallVectorImpl<WeakVH>::const_iterator const_elem_iterator; Value *getElement(unsigned i) const { diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index ac35702..0ba93b1 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -374,7 +374,7 @@ bool LLParser::ParseNamedGlobal() { bool LLParser::ParseMDString(MetadataBase *&MDS) { std::string Str; if (ParseStringConstant(Str)) return true; - MDS = Context.getMDString(Str); + MDS = MDString::get(Context, Str); return false; } @@ -403,8 +403,8 @@ bool LLParser::ParseMDNode(MetadataBase *&Node) { // Create MDNode forward reference SmallVector<Value *, 1> Elts; std::string FwdRefName = "llvm.mdnode.fwdref." + utostr(MID); - Elts.push_back(Context.getMDString(FwdRefName)); - MDNode *FwdNode = Context.getMDNode(Elts.data(), Elts.size()); + Elts.push_back(MDString::get(Context, FwdRefName)); + MDNode *FwdNode = MDNode::get(Context, Elts.data(), Elts.size()); ForwardRefMDNodes[MID] = std::make_pair(FwdNode, Lex.getLoc()); Node = FwdNode; return false; @@ -474,7 +474,7 @@ bool LLParser::ParseStandaloneMetadata() { || ParseToken(lltok::rbrace, "expected end of metadata node")) return true; - MDNode *Init = Context.getMDNode(Elts.data(), Elts.size()); + MDNode *Init = MDNode::get(Context, Elts.data(), Elts.size()); MetadataCache[MetadataID] = Init; std::map<unsigned, std::pair<MetadataBase *, LocTy> >::iterator FI = ForwardRefMDNodes.find(MetadataID); @@ -1729,7 +1729,7 @@ bool LLParser::ParseValID(ValID &ID) { ParseToken(lltok::rbrace, "expected end of metadata node")) return true; - ID.MetadataVal = Context.getMDNode(Elts.data(), Elts.size()); + ID.MetadataVal = MDNode::get(Context, Elts.data(), Elts.size()); return false; } diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index 40920d8..81fdbd2 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -774,7 +774,7 @@ bool BitcodeReader::ParseMetadata() { else Elts.push_back(NULL); } - Value *V = Context.getMDNode(&Elts[0], Elts.size()); + Value *V = MDNode::get(Context, &Elts[0], Elts.size()); ValueList.AssignValue(V, NextValueNo++); break; } @@ -784,7 +784,8 @@ bool BitcodeReader::ParseMetadata() { String.resize(MDStringLength); for (unsigned i = 0; i != MDStringLength; ++i) String[i] = Record[i]; - Value *V = Context.getMDString(StringRef(String.data(), String.size())); + Value *V = MDString::get(Context, + StringRef(String.data(), String.size())); ValueList.AssignValue(V, NextValueNo++); break; } diff --git a/lib/VMCore/LLVMContext.cpp b/lib/VMCore/LLVMContext.cpp index 107905f..3cd7158 100644 --- a/lib/VMCore/LLVMContext.cpp +++ b/lib/VMCore/LLVMContext.cpp @@ -31,21 +31,3 @@ LLVMContext& llvm::getGlobalContext() { LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl(*this)) { } LLVMContext::~LLVMContext() { delete pImpl; } - -// MDNode accessors -MDNode* LLVMContext::getMDNode(Value* const* Vals, unsigned NumVals) { - return pImpl->getMDNode(Vals, NumVals); -} - -// MDString accessors -MDString* LLVMContext::getMDString(const StringRef &Str) { - return pImpl->getMDString(Str.data(), Str.size()); -} - -void LLVMContext::erase(MDString *M) { - pImpl->erase(M); -} - -void LLVMContext::erase(MDNode *M) { - pImpl->erase(M); -} diff --git a/lib/VMCore/LLVMContextImpl.cpp b/lib/VMCore/LLVMContextImpl.cpp index bba5861..b29868a 100644 --- a/lib/VMCore/LLVMContextImpl.cpp +++ b/lib/VMCore/LLVMContextImpl.cpp @@ -20,51 +20,4 @@ using namespace llvm; LLVMContextImpl::LLVMContextImpl(LLVMContext &C) : - Context(C), TheTrueVal(0), TheFalseVal(0) { } - -MDString *LLVMContextImpl::getMDString(const char *StrBegin, - unsigned StrLength) { - sys::SmartScopedWriter<true> Writer(ConstantsLock); - StringMapEntry<MDString *> &Entry = - MDStringCache.GetOrCreateValue(StringRef(StrBegin, StrLength)); - MDString *&S = Entry.getValue(); - if (!S) S = new MDString(Entry.getKeyData(), - Entry.getKeyLength()); - - return S; -} - -MDNode *LLVMContextImpl::getMDNode(Value*const* Vals, unsigned NumVals) { - FoldingSetNodeID ID; - for (unsigned i = 0; i != NumVals; ++i) - ID.AddPointer(Vals[i]); - - ConstantsLock.reader_acquire(); - void *InsertPoint; - MDNode *N = MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint); - ConstantsLock.reader_release(); - - if (!N) { - sys::SmartScopedWriter<true> Writer(ConstantsLock); - N = MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint); - if (!N) { - // InsertPoint will have been set by the FindNodeOrInsertPos call. - N = new MDNode(Vals, NumVals); - MDNodeSet.InsertNode(N, InsertPoint); - } - } - - return N; -} - -// *** erase methods *** - -void LLVMContextImpl::erase(MDString *M) { - sys::SmartScopedWriter<true> Writer(ConstantsLock); - MDStringCache.erase(MDStringCache.find(M->getString())); -} - -void LLVMContextImpl::erase(MDNode *M) { - sys::SmartScopedWriter<true> Writer(ConstantsLock); - MDNodeSet.RemoveNode(M); -} + Context(C), TheTrueVal(0), TheFalseVal(0) { }
\ No newline at end of file diff --git a/lib/VMCore/LLVMContextImpl.h b/lib/VMCore/LLVMContextImpl.h index b20b65d..7a29a84 100644 --- a/lib/VMCore/LLVMContextImpl.h +++ b/lib/VMCore/LLVMContextImpl.h @@ -462,15 +462,10 @@ class LLVMContextImpl { friend class ConstantArray; friend class ConstantVector; friend class ConstantAggregateZero; + friend class MDNode; + friend class MDString; public: LLVMContextImpl(LLVMContext &C); - - MDString *getMDString(const char *StrBegin, unsigned StrLength); - - MDNode *getMDNode(Value*const* Vals, unsigned NumVals); - - void erase(MDString *M); - void erase(MDNode *M); }; } diff --git a/lib/VMCore/Metadata.cpp b/lib/VMCore/Metadata.cpp index 48db0b4..bf0611f 100644 --- a/lib/VMCore/Metadata.cpp +++ b/lib/VMCore/Metadata.cpp @@ -11,12 +11,29 @@ // //===----------------------------------------------------------------------===// +#include "LLVMContextImpl.h" #include "llvm/Metadata.h" +#include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "SymbolTableListTraitsImpl.h" using namespace llvm; //===----------------------------------------------------------------------===// +//MDString implementation +// +MDString *MDString::get(LLVMContext &Context, const StringRef &Str) { + LLVMContextImpl *pImpl = Context.pImpl; + sys::SmartScopedWriter<true> Writer(pImpl->ConstantsLock); + StringMapEntry<MDString *> &Entry = + pImpl->MDStringCache.GetOrCreateValue(Str); + MDString *&S = Entry.getValue(); + if (!S) S = new MDString(Entry.getKeyData(), + Entry.getKeyLength()); + + return S; +} + +//===----------------------------------------------------------------------===// //MDNode implementation // MDNode::MDNode(Value*const* Vals, unsigned NumVals) @@ -30,6 +47,30 @@ void MDNode::Profile(FoldingSetNodeID &ID) const { ID.AddPointer(*I); } +MDNode *MDNode::get(LLVMContext &Context, Value*const* Vals, unsigned NumVals) { + LLVMContextImpl *pImpl = Context.pImpl; + FoldingSetNodeID ID; + for (unsigned i = 0; i != NumVals; ++i) + ID.AddPointer(Vals[i]); + + pImpl->ConstantsLock.reader_acquire(); + void *InsertPoint; + MDNode *N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint); + pImpl->ConstantsLock.reader_release(); + + if (!N) { + sys::SmartScopedWriter<true> Writer(pImpl->ConstantsLock); + N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint); + if (!N) { + // InsertPoint will have been set by the FindNodeOrInsertPos call. + N = new MDNode(Vals, NumVals); + pImpl->MDNodeSet.InsertNode(N, InsertPoint); + } + } + + return N; +} + //===----------------------------------------------------------------------===// //NamedMDNode implementation // |