[llvm-commits] [llvm] r77733 - in /llvm/trunk: include/llvm/LLVMContext.h include/llvm/Metadata.h lib/AsmParser/LLParser.cpp lib/Bitcode/Reader/BitcodeReader.cpp lib/VMCore/LLVMContext.cpp lib/VMCore/LLVMContextImpl.cpp lib/VMCore/LLVMContextImpl.h lib/VMCore/Metadata.cpp
Owen Anderson
resistor at mac.com
Fri Jul 31 14:35:41 PDT 2009
Author: resistor
Date: Fri Jul 31 16:35:40 2009
New Revision: 77733
URL: http://llvm.org/viewvc/llvm-project?rev=77733&view=rev
Log:
Move the metadata constructors back to 2.5 syntax.
Modified:
llvm/trunk/include/llvm/LLVMContext.h
llvm/trunk/include/llvm/Metadata.h
llvm/trunk/lib/AsmParser/LLParser.cpp
llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/trunk/lib/VMCore/LLVMContext.cpp
llvm/trunk/lib/VMCore/LLVMContextImpl.cpp
llvm/trunk/lib/VMCore/LLVMContextImpl.h
llvm/trunk/lib/VMCore/Metadata.cpp
Modified: llvm/trunk/include/llvm/LLVMContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LLVMContext.h?rev=77733&r1=77732&r2=77733&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LLVMContext.h (original)
+++ llvm/trunk/include/llvm/LLVMContext.h Fri Jul 31 16:35:40 2009
@@ -61,20 +61,11 @@
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.
Modified: llvm/trunk/include/llvm/Metadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Metadata.h?rev=77733&r1=77732&r2=77733&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Metadata.h (original)
+++ llvm/trunk/include/llvm/Metadata.h Fri Jul 31 16:35:40 2009
@@ -27,6 +27,7 @@
namespace llvm {
class Constant;
+class LLVMContext;
//===----------------------------------------------------------------------===//
// MetadataBase - A base class for MDNode, MDString and NamedMDNode.
@@ -64,13 +65,14 @@
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 @@
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 {
Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=77733&r1=77732&r2=77733&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Fri Jul 31 16:35:40 2009
@@ -374,7 +374,7 @@
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 @@
// 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 @@
|| 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 @@
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;
}
Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=77733&r1=77732&r2=77733&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Fri Jul 31 16:35:40 2009
@@ -774,7 +774,7 @@
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 @@
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;
}
Modified: llvm/trunk/lib/VMCore/LLVMContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LLVMContext.cpp?rev=77733&r1=77732&r2=77733&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContext.cpp (original)
+++ llvm/trunk/lib/VMCore/LLVMContext.cpp Fri Jul 31 16:35:40 2009
@@ -31,21 +31,3 @@
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);
-}
Modified: llvm/trunk/lib/VMCore/LLVMContextImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LLVMContextImpl.cpp?rev=77733&r1=77732&r2=77733&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContextImpl.cpp (original)
+++ llvm/trunk/lib/VMCore/LLVMContextImpl.cpp Fri Jul 31 16:35:40 2009
@@ -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
Modified: llvm/trunk/lib/VMCore/LLVMContextImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LLVMContextImpl.h?rev=77733&r1=77732&r2=77733&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContextImpl.h (original)
+++ llvm/trunk/lib/VMCore/LLVMContextImpl.h Fri Jul 31 16:35:40 2009
@@ -462,15 +462,10 @@
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);
};
}
Modified: llvm/trunk/lib/VMCore/Metadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Metadata.cpp?rev=77733&r1=77732&r2=77733&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Metadata.cpp (original)
+++ llvm/trunk/lib/VMCore/Metadata.cpp Fri Jul 31 16:35:40 2009
@@ -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 @@
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
//
More information about the llvm-commits
mailing list