mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-18 11:24:01 +00:00
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
This commit is contained in:
@ -61,20 +61,11 @@ class LLVMContext {
|
|||||||
friend class ConstantArray;
|
friend class ConstantArray;
|
||||||
friend class ConstantVector;
|
friend class ConstantVector;
|
||||||
friend class ConstantAggregateZero;
|
friend class ConstantAggregateZero;
|
||||||
|
friend class MDNode;
|
||||||
|
friend class MDString;
|
||||||
public:
|
public:
|
||||||
LLVMContext();
|
LLVMContext();
|
||||||
~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.
|
/// FOR BACKWARDS COMPATIBILITY - Returns a global context.
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
class Constant;
|
class Constant;
|
||||||
|
class LLVMContext;
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// MetadataBase - A base class for MDNode, MDString and NamedMDNode.
|
// MetadataBase - A base class for MDNode, MDString and NamedMDNode.
|
||||||
@ -64,13 +65,14 @@ public:
|
|||||||
class MDString : public MetadataBase {
|
class MDString : public MetadataBase {
|
||||||
MDString(const MDString &); // DO NOT IMPLEMENT
|
MDString(const MDString &); // DO NOT IMPLEMENT
|
||||||
StringRef Str;
|
StringRef Str;
|
||||||
friend class LLVMContextImpl;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit MDString(const char *begin, unsigned l)
|
explicit MDString(const char *begin, unsigned l)
|
||||||
: MetadataBase(Type::MetadataTy, Value::MDStringVal), Str(begin, l) {}
|
: MetadataBase(Type::MetadataTy, Value::MDStringVal), Str(begin, l) {}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static MDString *get(LLVMContext &Context, const StringRef &Str);
|
||||||
|
|
||||||
StringRef getString() const { return Str; }
|
StringRef getString() const { return Str; }
|
||||||
|
|
||||||
unsigned length() const { return Str.size(); }
|
unsigned length() const { return Str.size(); }
|
||||||
@ -97,14 +99,15 @@ public:
|
|||||||
class MDNode : public MetadataBase, public FoldingSetNode {
|
class MDNode : public MetadataBase, public FoldingSetNode {
|
||||||
MDNode(const MDNode &); // DO NOT IMPLEMENT
|
MDNode(const MDNode &); // DO NOT IMPLEMENT
|
||||||
|
|
||||||
friend class LLVMContextImpl;
|
|
||||||
|
|
||||||
SmallVector<WeakVH, 4> Node;
|
SmallVector<WeakVH, 4> Node;
|
||||||
typedef SmallVectorImpl<WeakVH>::iterator elem_iterator;
|
typedef SmallVectorImpl<WeakVH>::iterator elem_iterator;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit MDNode(Value*const* Vals, unsigned NumVals);
|
explicit MDNode(Value*const* Vals, unsigned NumVals);
|
||||||
public:
|
public:
|
||||||
|
static MDNode *get(LLVMContext &Context,
|
||||||
|
Value* const* Vals, unsigned NumVals);
|
||||||
|
|
||||||
typedef SmallVectorImpl<WeakVH>::const_iterator const_elem_iterator;
|
typedef SmallVectorImpl<WeakVH>::const_iterator const_elem_iterator;
|
||||||
|
|
||||||
Value *getElement(unsigned i) const {
|
Value *getElement(unsigned i) const {
|
||||||
|
@ -374,7 +374,7 @@ bool LLParser::ParseNamedGlobal() {
|
|||||||
bool LLParser::ParseMDString(MetadataBase *&MDS) {
|
bool LLParser::ParseMDString(MetadataBase *&MDS) {
|
||||||
std::string Str;
|
std::string Str;
|
||||||
if (ParseStringConstant(Str)) return true;
|
if (ParseStringConstant(Str)) return true;
|
||||||
MDS = Context.getMDString(Str);
|
MDS = MDString::get(Context, Str);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -403,8 +403,8 @@ bool LLParser::ParseMDNode(MetadataBase *&Node) {
|
|||||||
// Create MDNode forward reference
|
// Create MDNode forward reference
|
||||||
SmallVector<Value *, 1> Elts;
|
SmallVector<Value *, 1> Elts;
|
||||||
std::string FwdRefName = "llvm.mdnode.fwdref." + utostr(MID);
|
std::string FwdRefName = "llvm.mdnode.fwdref." + utostr(MID);
|
||||||
Elts.push_back(Context.getMDString(FwdRefName));
|
Elts.push_back(MDString::get(Context, FwdRefName));
|
||||||
MDNode *FwdNode = Context.getMDNode(Elts.data(), Elts.size());
|
MDNode *FwdNode = MDNode::get(Context, Elts.data(), Elts.size());
|
||||||
ForwardRefMDNodes[MID] = std::make_pair(FwdNode, Lex.getLoc());
|
ForwardRefMDNodes[MID] = std::make_pair(FwdNode, Lex.getLoc());
|
||||||
Node = FwdNode;
|
Node = FwdNode;
|
||||||
return false;
|
return false;
|
||||||
@ -474,7 +474,7 @@ bool LLParser::ParseStandaloneMetadata() {
|
|||||||
|| ParseToken(lltok::rbrace, "expected end of metadata node"))
|
|| ParseToken(lltok::rbrace, "expected end of metadata node"))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
MDNode *Init = Context.getMDNode(Elts.data(), Elts.size());
|
MDNode *Init = MDNode::get(Context, Elts.data(), Elts.size());
|
||||||
MetadataCache[MetadataID] = Init;
|
MetadataCache[MetadataID] = Init;
|
||||||
std::map<unsigned, std::pair<MetadataBase *, LocTy> >::iterator
|
std::map<unsigned, std::pair<MetadataBase *, LocTy> >::iterator
|
||||||
FI = ForwardRefMDNodes.find(MetadataID);
|
FI = ForwardRefMDNodes.find(MetadataID);
|
||||||
@ -1729,7 +1729,7 @@ bool LLParser::ParseValID(ValID &ID) {
|
|||||||
ParseToken(lltok::rbrace, "expected end of metadata node"))
|
ParseToken(lltok::rbrace, "expected end of metadata node"))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
ID.MetadataVal = Context.getMDNode(Elts.data(), Elts.size());
|
ID.MetadataVal = MDNode::get(Context, Elts.data(), Elts.size());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -774,7 +774,7 @@ bool BitcodeReader::ParseMetadata() {
|
|||||||
else
|
else
|
||||||
Elts.push_back(NULL);
|
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++);
|
ValueList.AssignValue(V, NextValueNo++);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -784,7 +784,8 @@ bool BitcodeReader::ParseMetadata() {
|
|||||||
String.resize(MDStringLength);
|
String.resize(MDStringLength);
|
||||||
for (unsigned i = 0; i != MDStringLength; ++i)
|
for (unsigned i = 0; i != MDStringLength; ++i)
|
||||||
String[i] = Record[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++);
|
ValueList.AssignValue(V, NextValueNo++);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -31,21 +31,3 @@ LLVMContext& llvm::getGlobalContext() {
|
|||||||
|
|
||||||
LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl(*this)) { }
|
LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl(*this)) { }
|
||||||
LLVMContext::~LLVMContext() { delete pImpl; }
|
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) :
|
LLVMContextImpl::LLVMContextImpl(LLVMContext &C) :
|
||||||
Context(C), TheTrueVal(0), TheFalseVal(0) { }
|
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 ConstantArray;
|
||||||
friend class ConstantVector;
|
friend class ConstantVector;
|
||||||
friend class ConstantAggregateZero;
|
friend class ConstantAggregateZero;
|
||||||
|
friend class MDNode;
|
||||||
|
friend class MDString;
|
||||||
public:
|
public:
|
||||||
LLVMContextImpl(LLVMContext &C);
|
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/Metadata.h"
|
||||||
|
#include "llvm/LLVMContext.h"
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
#include "SymbolTableListTraitsImpl.h"
|
#include "SymbolTableListTraitsImpl.h"
|
||||||
using namespace llvm;
|
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 implementation
|
||||||
//
|
//
|
||||||
@ -30,6 +47,30 @@ void MDNode::Profile(FoldingSetNodeID &ID) const {
|
|||||||
ID.AddPointer(*I);
|
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
|
//NamedMDNode implementation
|
||||||
//
|
//
|
||||||
|
Reference in New Issue
Block a user