From: Chris Lattner Date: Mon, 19 Oct 2009 07:10:59 +0000 (+0000) Subject: various cleanups. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=b2a33b46469a6d2c0e61122002079efb7d6d3f9c;p=oota-llvm.git various cleanups. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84471 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Metadata.h b/include/llvm/Metadata.h index 13b97b992ce..87c28b1ac55 100644 --- a/include/llvm/Metadata.h +++ b/include/llvm/Metadata.h @@ -47,12 +47,6 @@ protected: void resizeOperands(unsigned NumOps); 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: static inline bool classof(const MetadataBase *) { return true; } @@ -85,15 +79,17 @@ public: 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. /// - const char *begin() const { return Str.begin(); } + iterator begin() const { return Str.begin(); } /// 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: static inline bool classof(const MDString *) { return true; } @@ -133,7 +129,7 @@ class MDNode : public MetadataBase, public FoldingSetNode { SmallVector Node; protected: - explicit MDNode(LLVMContext &C, Value*const* Vals, unsigned NumVals); + explicit MDNode(LLVMContext &C, Value *const *Vals, unsigned NumVals); public: // Do not allocate any space for operands. void *operator new(size_t s) { @@ -141,7 +137,7 @@ public: } // Constructors and destructors. static MDNode *get(LLVMContext &Context, - Value* const* Vals, unsigned NumVals); + Value *const *Vals, unsigned NumVals); /// dropAllReferences - Remove all uses and clear node vector. void dropAllReferences(); @@ -151,7 +147,7 @@ public: /// getElement - Return specified element. Value *getElement(unsigned i) const { - assert (getNumElements() > i && "Invalid element number!"); + assert(getNumElements() > i && "Invalid element number!"); return Node[i]; } @@ -170,21 +166,10 @@ public: elem_iterator elem_begin() { return Node.begin(); } 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 /// duplicates 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: static inline bool classof(const MDNode *) { return true; } static bool classof(const Value *V) { @@ -229,7 +214,7 @@ class NamedMDNode : public MetadataBase, public ilist_node { typedef SmallVectorImpl::iterator elem_iterator; 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); public: // Do not allocate any space for operands. @@ -237,7 +222,7 @@ public: return User::operator new(s, 0); } static NamedMDNode *Create(LLVMContext &C, const Twine &N, - MetadataBase*const*MDs, + MetadataBase *const *MDs, unsigned NumMDs, Module *M = 0) { return new NamedMDNode(C, N, MDs, NumMDs, M); } @@ -261,7 +246,7 @@ public: /// getElement - Return specified element. MetadataBase *getElement(unsigned i) const { - assert (getNumElements() > i && "Invalid element number!"); + assert(getNumElements() > i && "Invalid element number!"); return Node[i]; } @@ -284,18 +269,6 @@ public: elem_iterator elem_begin() { return Node.begin(); } 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: static inline bool classof(const NamedMDNode *) { return true; } static bool classof(const Value *V) { diff --git a/lib/VMCore/Metadata.cpp b/lib/VMCore/Metadata.cpp index 110c5e38fac..0528e48259e 100644 --- a/lib/VMCore/Metadata.cpp +++ b/lib/VMCore/Metadata.cpp @@ -20,7 +20,7 @@ using namespace llvm; //===----------------------------------------------------------------------===// -//MetadataBase implementation +// MetadataBase implementation. // /// 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); } //===----------------------------------------------------------------------===// -//MDString implementation +// MDString implementation. // MDString *MDString::get(LLVMContext &Context, const StringRef &Str) { LLVMContextImpl *pImpl = Context.pImpl; @@ -56,16 +56,15 @@ MDString *MDString::get(LLVMContext &Context, const StringRef &Str) { StringMapEntry &Entry = pImpl->MDStringCache.GetOrCreateValue(Str); MDString *&S = Entry.getValue(); - if (!S) S = new MDString(Context, Entry.getKeyData(), - Entry.getKeyLength()); - - return S; + if (S) return S; + + return S = new MDString(Context, Entry.getKeyData(), Entry.getKeyLength()); } //===----------------------------------------------------------------------===// -//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) { NumOperands = 0; resizeOperands(NumVals); @@ -91,19 +90,20 @@ MDNode *MDNode::get(LLVMContext &Context, Value*const* Vals, unsigned NumVals) { 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(); + MDNode *N; + { + sys::SmartScopedReader Reader(pImpl->ConstantsLock); + N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint); + } + if (N) return N; + sys::SmartScopedWriter Writer(pImpl->ConstantsLock); + N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint); if (!N) { - sys::SmartScopedWriter 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); - } + // InsertPoint will have been set by the FindNodeOrInsertPos call. + N = new MDNode(Context, Vals, NumVals); + pImpl->MDNodeSet.InsertNode(N, InsertPoint); } return N; @@ -209,10 +209,10 @@ void MDNode::replaceElement(Value *From, Value *To) { } //===----------------------------------------------------------------------===// -//NamedMDNode implementation +// NamedMDNode implementation. // NamedMDNode::NamedMDNode(LLVMContext &C, const Twine &N, - MetadataBase*const* MDs, + MetadataBase *const *MDs, unsigned NumMDs, Module *ParentModule) : MetadataBase(Type::getMetadataTy(C), Value::NamedMDNodeVal), Parent(0) { setName(N); @@ -229,7 +229,7 @@ NamedMDNode::NamedMDNode(LLVMContext &C, const Twine &N, } NamedMDNode *NamedMDNode::Create(const NamedMDNode *NMD, Module *M) { - assert (NMD && "Invalid source NamedMDNode!"); + assert(NMD && "Invalid source NamedMDNode!"); SmallVector Elems; for (unsigned i = 0, e = NMD->getNumElements(); i != e; ++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. /// A metadata kind can be registered only once. unsigned MetadataContext::RegisterMDKind(const char *Name) { - assert (validName(Name) && "Invalid custome metadata name!"); + assert(validName(Name) && "Invalid custome metadata name!"); unsigned Count = MDHandlerNames.size(); assert(MDHandlerNames.find(Name) == MDHandlerNames.end() && "Already registered MDKind!"); @@ -292,7 +292,7 @@ bool MetadataContext::validName(const char *Name) { /// getMDKind - Return metadata kind. If the requested metadata kind /// is not registered then return 0. unsigned MetadataContext::getMDKind(const char *Name) { - assert (validName(Name) && "Invalid custome metadata name!"); + assert(validName(Name) && "Invalid custome metadata name!"); StringMap::iterator I = MDHandlerNames.find(Name); if (I == MDHandlerNames.end()) return 0; @@ -302,7 +302,7 @@ unsigned MetadataContext::getMDKind(const char *Name) { /// addMD - Attach the metadata of given kind with an Instruction. void MetadataContext::addMD(unsigned MDKind, MDNode *Node, Instruction *Inst) { - assert (Node && "Unable to add custome metadata"); + assert(Node && "Invalid null MDNode"); Inst->HasMetadata = true; MDStoreTy::iterator I = MetadataStore.find(Inst); if (I == MetadataStore.end()) { @@ -349,7 +349,7 @@ void MetadataContext::removeMD(unsigned Kind, Instruction *Inst) { void MetadataContext::removeMDs(const Instruction *Inst) { // Find Metadata handles for this instruction. 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; // 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 /// the same metadata to In2. void MetadataContext::copyMD(Instruction *In1, Instruction *In2) { - assert (In1 && In2 && "Invalid instruction!"); + assert(In1 && In2 && "Invalid instruction!"); MDStoreTy::iterator I = MetadataStore.find(In1); if (I == MetadataStore.end()) return; @@ -389,12 +389,13 @@ MDNode *MetadataContext::getMD(unsigned MDKind, const Instruction *Inst) { } /// 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); if (I == MetadataStore.end()) return NULL; - return &(I->second); + return &I->second; } /// getHandlerNames - Get handler names. This is used by bitcode @@ -408,7 +409,7 @@ const StringMap *MetadataContext::getHandlerNames() { void MetadataContext::ValueIsCloned(const Instruction *In1, Instruction *In2) { // Find Metadata handles for 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.