[llvm-commits] [llvm] r84471 - in /llvm/trunk: include/llvm/Metadata.h lib/VMCore/Metadata.cpp

Chris Lattner sabre at nondot.org
Mon Oct 19 00:11:00 PDT 2009


Author: lattner
Date: Mon Oct 19 02:10:59 2009
New Revision: 84471

URL: http://llvm.org/viewvc/llvm-project?rev=84471&view=rev
Log:
various cleanups.

Modified:
    llvm/trunk/include/llvm/Metadata.h
    llvm/trunk/lib/VMCore/Metadata.cpp

Modified: llvm/trunk/include/llvm/Metadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Metadata.h?rev=84471&r1=84470&r2=84471&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Metadata.h (original)
+++ llvm/trunk/include/llvm/Metadata.h Mon Oct 19 02:10:59 2009
@@ -47,12 +47,6 @@
 
   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 @@
   
   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 @@
   SmallVector<ElementVH, 4> 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 @@
   }
   // 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 @@
   
   /// 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 @@
   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 @@
   typedef SmallVectorImpl<WeakMetadataVH>::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 @@
     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 @@
 
   /// 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 @@
   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) {

Modified: llvm/trunk/lib/VMCore/Metadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Metadata.cpp?rev=84471&r1=84470&r2=84471&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Metadata.cpp (original)
+++ llvm/trunk/lib/VMCore/Metadata.cpp Mon Oct 19 02:10:59 2009
@@ -20,7 +20,7 @@
 using namespace llvm;
 
 //===----------------------------------------------------------------------===//
-//MetadataBase implementation
+// MetadataBase implementation.
 //
 
 /// resizeOperands - Metadata keeps track of other metadata uses using 
@@ -48,7 +48,7 @@
   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 @@
   StringMapEntry<MDString *> &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 @@
   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<true> Reader(pImpl->ConstantsLock);
+    N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
+  }  
+  if (N) return N;
   
+  sys::SmartScopedWriter<true> Writer(pImpl->ConstantsLock);
+  N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
   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(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 @@
 }
 
 //===----------------------------------------------------------------------===//
-//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::Create(const NamedMDNode *NMD, Module *M) {
-  assert (NMD && "Invalid source NamedMDNode!");
+  assert(NMD && "Invalid source NamedMDNode!");
   SmallVector<MetadataBase *, 4> Elems;
   for (unsigned i = 0, e = NMD->getNumElements(); i != e; ++i)
     Elems.push_back(NMD->getElement(i));
@@ -254,13 +254,13 @@
 }
 
 //===----------------------------------------------------------------------===//
-//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 @@
 /// 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<unsigned>::iterator I = MDHandlerNames.find(Name);
   if (I == MDHandlerNames.end())
     return 0;
@@ -302,7 +302,7 @@
 
 /// 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::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 @@
 /// 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 @@
 }
 
 /// 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 @@
 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.
 





More information about the llvm-commits mailing list