various cleanups.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84471 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2009-10-19 07:10:59 +00:00
parent 12f031d005
commit b2a33b4646
2 changed files with 43 additions and 69 deletions

View File

@ -47,12 +47,6 @@ protected:
void resizeOperands(unsigned NumOps); void resizeOperands(unsigned NumOps);
public: public:
/// isNullValue - Return true if this is the value that would be returned by
/// getNullValue. This always returns false because getNullValue will never
/// produce metadata.
virtual bool isNullValue() const {
return false;
}
/// Methods for support type inquiry through isa, cast, and dyn_cast: /// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const MetadataBase *) { return true; } static inline bool classof(const MetadataBase *) { return true; }
@ -85,15 +79,17 @@ public:
StringRef getString() const { return Str; } StringRef getString() const { return Str; }
unsigned length() const { return Str.size(); } unsigned getLength() const { return Str.size(); }
typedef StringRef::iterator iterator;
/// begin() - Pointer to the first byte of the string. /// begin() - Pointer to the first byte of the string.
/// ///
const char *begin() const { return Str.begin(); } iterator begin() const { return Str.begin(); }
/// end() - Pointer to one byte past the end of the string. /// end() - Pointer to one byte past the end of the string.
/// ///
const char *end() const { return Str.end(); } iterator end() const { return Str.end(); }
/// Methods for support type inquiry through isa, cast, and dyn_cast: /// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const MDString *) { return true; } static inline bool classof(const MDString *) { return true; }
@ -133,7 +129,7 @@ class MDNode : public MetadataBase, public FoldingSetNode {
SmallVector<ElementVH, 4> Node; SmallVector<ElementVH, 4> Node;
protected: protected:
explicit MDNode(LLVMContext &C, Value*const* Vals, unsigned NumVals); explicit MDNode(LLVMContext &C, Value *const *Vals, unsigned NumVals);
public: public:
// Do not allocate any space for operands. // Do not allocate any space for operands.
void *operator new(size_t s) { void *operator new(size_t s) {
@ -141,7 +137,7 @@ public:
} }
// Constructors and destructors. // Constructors and destructors.
static MDNode *get(LLVMContext &Context, static MDNode *get(LLVMContext &Context,
Value* const* Vals, unsigned NumVals); Value *const *Vals, unsigned NumVals);
/// dropAllReferences - Remove all uses and clear node vector. /// dropAllReferences - Remove all uses and clear node vector.
void dropAllReferences(); void dropAllReferences();
@ -151,7 +147,7 @@ public:
/// getElement - Return specified element. /// getElement - Return specified element.
Value *getElement(unsigned i) const { Value *getElement(unsigned i) const {
assert (getNumElements() > i && "Invalid element number!"); assert(getNumElements() > i && "Invalid element number!");
return Node[i]; return Node[i];
} }
@ -170,21 +166,10 @@ public:
elem_iterator elem_begin() { return Node.begin(); } elem_iterator elem_begin() { return Node.begin(); }
elem_iterator elem_end() { return Node.end(); } elem_iterator elem_end() { return Node.end(); }
/// isNullValue - Return true if this is the value that would be returned by
/// getNullValue. This always returns false because getNullValue will never
/// produce metadata.
virtual bool isNullValue() const {
return false;
}
/// Profile - calculate a unique identifier for this MDNode to collapse /// Profile - calculate a unique identifier for this MDNode to collapse
/// duplicates /// duplicates
void Profile(FoldingSetNodeID &ID) const; void Profile(FoldingSetNodeID &ID) const;
virtual void replaceUsesOfWithOnConstant(Value *, Value *, Use *) {
llvm_unreachable("This should never be called because MDNodes have no ops");
}
/// Methods for support type inquiry through isa, cast, and dyn_cast: /// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const MDNode *) { return true; } static inline bool classof(const MDNode *) { return true; }
static bool classof(const Value *V) { static bool classof(const Value *V) {
@ -229,7 +214,7 @@ class NamedMDNode : public MetadataBase, public ilist_node<NamedMDNode> {
typedef SmallVectorImpl<WeakMetadataVH>::iterator elem_iterator; typedef SmallVectorImpl<WeakMetadataVH>::iterator elem_iterator;
protected: protected:
explicit NamedMDNode(LLVMContext &C, const Twine &N, MetadataBase*const* Vals, explicit NamedMDNode(LLVMContext &C, const Twine &N, MetadataBase*const *Vals,
unsigned NumVals, Module *M = 0); unsigned NumVals, Module *M = 0);
public: public:
// Do not allocate any space for operands. // Do not allocate any space for operands.
@ -237,7 +222,7 @@ public:
return User::operator new(s, 0); return User::operator new(s, 0);
} }
static NamedMDNode *Create(LLVMContext &C, const Twine &N, static NamedMDNode *Create(LLVMContext &C, const Twine &N,
MetadataBase*const*MDs, MetadataBase *const *MDs,
unsigned NumMDs, Module *M = 0) { unsigned NumMDs, Module *M = 0) {
return new NamedMDNode(C, N, MDs, NumMDs, M); return new NamedMDNode(C, N, MDs, NumMDs, M);
} }
@ -261,7 +246,7 @@ public:
/// getElement - Return specified element. /// getElement - Return specified element.
MetadataBase *getElement(unsigned i) const { MetadataBase *getElement(unsigned i) const {
assert (getNumElements() > i && "Invalid element number!"); assert(getNumElements() > i && "Invalid element number!");
return Node[i]; return Node[i];
} }
@ -284,18 +269,6 @@ public:
elem_iterator elem_begin() { return Node.begin(); } elem_iterator elem_begin() { return Node.begin(); }
elem_iterator elem_end() { return Node.end(); } elem_iterator elem_end() { return Node.end(); }
/// isNullValue - Return true if this is the value that would be returned by
/// getNullValue. This always returns false because getNullValue will never
/// produce metadata.
virtual bool isNullValue() const {
return false;
}
virtual void replaceUsesOfWithOnConstant(Value *, Value *, Use *) {
llvm_unreachable(
"This should never be called because NamedMDNodes have no ops");
}
/// Methods for support type inquiry through isa, cast, and dyn_cast: /// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const NamedMDNode *) { return true; } static inline bool classof(const NamedMDNode *) { return true; }
static bool classof(const Value *V) { static bool classof(const Value *V) {

View File

@ -20,7 +20,7 @@
using namespace llvm; using namespace llvm;
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
//MetadataBase implementation // MetadataBase implementation.
// //
/// resizeOperands - Metadata keeps track of other metadata uses using /// resizeOperands - Metadata keeps track of other metadata uses using
@ -48,7 +48,7 @@ void MetadataBase::resizeOperands(unsigned NumOps) {
if (OldOps) Use::zap(OldOps, OldOps + e, true); if (OldOps) Use::zap(OldOps, OldOps + e, true);
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
//MDString implementation // MDString implementation.
// //
MDString *MDString::get(LLVMContext &Context, const StringRef &Str) { MDString *MDString::get(LLVMContext &Context, const StringRef &Str) {
LLVMContextImpl *pImpl = Context.pImpl; LLVMContextImpl *pImpl = Context.pImpl;
@ -56,16 +56,15 @@ MDString *MDString::get(LLVMContext &Context, const StringRef &Str) {
StringMapEntry<MDString *> &Entry = StringMapEntry<MDString *> &Entry =
pImpl->MDStringCache.GetOrCreateValue(Str); pImpl->MDStringCache.GetOrCreateValue(Str);
MDString *&S = Entry.getValue(); MDString *&S = Entry.getValue();
if (!S) S = new MDString(Context, Entry.getKeyData(), if (S) return S;
Entry.getKeyLength());
return S = new MDString(Context, Entry.getKeyData(), Entry.getKeyLength());
return S;
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
//MDNode implementation // MDNode implementation.
// //
MDNode::MDNode(LLVMContext &C, Value*const* Vals, unsigned NumVals) MDNode::MDNode(LLVMContext &C, Value *const *Vals, unsigned NumVals)
: MetadataBase(Type::getMetadataTy(C), Value::MDNodeVal) { : MetadataBase(Type::getMetadataTy(C), Value::MDNodeVal) {
NumOperands = 0; NumOperands = 0;
resizeOperands(NumVals); resizeOperands(NumVals);
@ -91,19 +90,20 @@ MDNode *MDNode::get(LLVMContext &Context, Value*const* Vals, unsigned NumVals) {
for (unsigned i = 0; i != NumVals; ++i) for (unsigned i = 0; i != NumVals; ++i)
ID.AddPointer(Vals[i]); ID.AddPointer(Vals[i]);
pImpl->ConstantsLock.reader_acquire();
void *InsertPoint; void *InsertPoint;
MDNode *N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint); MDNode *N;
pImpl->ConstantsLock.reader_release(); {
sys::SmartScopedReader<true> Reader(pImpl->ConstantsLock);
if (!N) {
sys::SmartScopedWriter<true> Writer(pImpl->ConstantsLock);
N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint); N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
if (!N) { }
// InsertPoint will have been set by the FindNodeOrInsertPos call. if (N) return N;
N = new MDNode(Context, Vals, NumVals);
pImpl->MDNodeSet.InsertNode(N, InsertPoint); 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(Context, Vals, NumVals);
pImpl->MDNodeSet.InsertNode(N, InsertPoint);
} }
return N; return N;
@ -209,10 +209,10 @@ void MDNode::replaceElement(Value *From, Value *To) {
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
//NamedMDNode implementation // NamedMDNode implementation.
// //
NamedMDNode::NamedMDNode(LLVMContext &C, const Twine &N, NamedMDNode::NamedMDNode(LLVMContext &C, const Twine &N,
MetadataBase*const* MDs, MetadataBase *const *MDs,
unsigned NumMDs, Module *ParentModule) unsigned NumMDs, Module *ParentModule)
: MetadataBase(Type::getMetadataTy(C), Value::NamedMDNodeVal), Parent(0) { : MetadataBase(Type::getMetadataTy(C), Value::NamedMDNodeVal), Parent(0) {
setName(N); setName(N);
@ -229,7 +229,7 @@ NamedMDNode::NamedMDNode(LLVMContext &C, const Twine &N,
} }
NamedMDNode *NamedMDNode::Create(const NamedMDNode *NMD, Module *M) { NamedMDNode *NamedMDNode::Create(const NamedMDNode *NMD, Module *M) {
assert (NMD && "Invalid source NamedMDNode!"); assert(NMD && "Invalid source NamedMDNode!");
SmallVector<MetadataBase *, 4> Elems; SmallVector<MetadataBase *, 4> Elems;
for (unsigned i = 0, e = NMD->getNumElements(); i != e; ++i) for (unsigned i = 0, e = NMD->getNumElements(); i != e; ++i)
Elems.push_back(NMD->getElement(i)); Elems.push_back(NMD->getElement(i));
@ -254,13 +254,13 @@ NamedMDNode::~NamedMDNode() {
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
//Metadata implementation // MetadataContext implementation.
// //
/// RegisterMDKind - Register a new metadata kind and return its ID. /// RegisterMDKind - Register a new metadata kind and return its ID.
/// A metadata kind can be registered only once. /// A metadata kind can be registered only once.
unsigned MetadataContext::RegisterMDKind(const char *Name) { unsigned MetadataContext::RegisterMDKind(const char *Name) {
assert (validName(Name) && "Invalid custome metadata name!"); assert(validName(Name) && "Invalid custome metadata name!");
unsigned Count = MDHandlerNames.size(); unsigned Count = MDHandlerNames.size();
assert(MDHandlerNames.find(Name) == MDHandlerNames.end() assert(MDHandlerNames.find(Name) == MDHandlerNames.end()
&& "Already registered MDKind!"); && "Already registered MDKind!");
@ -292,7 +292,7 @@ bool MetadataContext::validName(const char *Name) {
/// getMDKind - Return metadata kind. If the requested metadata kind /// getMDKind - Return metadata kind. If the requested metadata kind
/// is not registered then return 0. /// is not registered then return 0.
unsigned MetadataContext::getMDKind(const char *Name) { unsigned MetadataContext::getMDKind(const char *Name) {
assert (validName(Name) && "Invalid custome metadata name!"); assert(validName(Name) && "Invalid custome metadata name!");
StringMap<unsigned>::iterator I = MDHandlerNames.find(Name); StringMap<unsigned>::iterator I = MDHandlerNames.find(Name);
if (I == MDHandlerNames.end()) if (I == MDHandlerNames.end())
return 0; return 0;
@ -302,7 +302,7 @@ unsigned MetadataContext::getMDKind(const char *Name) {
/// addMD - Attach the metadata of given kind with an Instruction. /// addMD - Attach the metadata of given kind with an Instruction.
void MetadataContext::addMD(unsigned MDKind, MDNode *Node, Instruction *Inst) { void MetadataContext::addMD(unsigned MDKind, MDNode *Node, Instruction *Inst) {
assert (Node && "Unable to add custome metadata"); assert(Node && "Invalid null MDNode");
Inst->HasMetadata = true; Inst->HasMetadata = true;
MDStoreTy::iterator I = MetadataStore.find(Inst); MDStoreTy::iterator I = MetadataStore.find(Inst);
if (I == MetadataStore.end()) { if (I == MetadataStore.end()) {
@ -349,7 +349,7 @@ void MetadataContext::removeMD(unsigned Kind, Instruction *Inst) {
void MetadataContext::removeMDs(const Instruction *Inst) { void MetadataContext::removeMDs(const Instruction *Inst) {
// Find Metadata handles for this instruction. // Find Metadata handles for this instruction.
MDStoreTy::iterator I = MetadataStore.find(Inst); MDStoreTy::iterator I = MetadataStore.find(Inst);
assert (I != MetadataStore.end() && "Invalid custom metadata info!"); assert(I != MetadataStore.end() && "Invalid custom metadata info!");
MDMapTy &Info = I->second; MDMapTy &Info = I->second;
// FIXME : Give all metadata handlers a chance to adjust. // FIXME : Give all metadata handlers a chance to adjust.
@ -362,7 +362,7 @@ void MetadataContext::removeMDs(const Instruction *Inst) {
/// copyMD - If metadata is attached with Instruction In1 then attach /// copyMD - If metadata is attached with Instruction In1 then attach
/// the same metadata to In2. /// the same metadata to In2.
void MetadataContext::copyMD(Instruction *In1, Instruction *In2) { void MetadataContext::copyMD(Instruction *In1, Instruction *In2) {
assert (In1 && In2 && "Invalid instruction!"); assert(In1 && In2 && "Invalid instruction!");
MDStoreTy::iterator I = MetadataStore.find(In1); MDStoreTy::iterator I = MetadataStore.find(In1);
if (I == MetadataStore.end()) if (I == MetadataStore.end())
return; return;
@ -389,12 +389,13 @@ MDNode *MetadataContext::getMD(unsigned MDKind, const Instruction *Inst) {
} }
/// getMDs - Get the metadata attached with an Instruction. /// getMDs - Get the metadata attached with an Instruction.
const MetadataContext::MDMapTy *MetadataContext::getMDs(const Instruction *Inst) { const MetadataContext::MDMapTy *
MetadataContext::getMDs(const Instruction *Inst) {
MDStoreTy::iterator I = MetadataStore.find(Inst); MDStoreTy::iterator I = MetadataStore.find(Inst);
if (I == MetadataStore.end()) if (I == MetadataStore.end())
return NULL; return NULL;
return &(I->second); return &I->second;
} }
/// getHandlerNames - Get handler names. This is used by bitcode /// getHandlerNames - Get handler names. This is used by bitcode
@ -408,7 +409,7 @@ const StringMap<unsigned> *MetadataContext::getHandlerNames() {
void MetadataContext::ValueIsCloned(const Instruction *In1, Instruction *In2) { void MetadataContext::ValueIsCloned(const Instruction *In1, Instruction *In2) {
// Find Metadata handles for In1. // Find Metadata handles for In1.
MDStoreTy::iterator I = MetadataStore.find(In1); MDStoreTy::iterator I = MetadataStore.find(In1);
assert (I != MetadataStore.end() && "Invalid custom metadata info!"); assert(I != MetadataStore.end() && "Invalid custom metadata info!");
// FIXME : Give all metadata handlers a chance to adjust. // FIXME : Give all metadata handlers a chance to adjust.