forked from OSchip/llvm-project
Move the metadata constructors back to 2.5 syntax.
llvm-svn: 77733
This commit is contained in:
parent
0d5f37b81a
commit
0087fe6e5c
|
@ -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.
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -21,50 +21,3 @@ 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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -11,11 +11,28 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#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
|
||||
//
|
||||
|
@ -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
|
||||
//
|
||||
|
|
Loading…
Reference in New Issue