[llvm-commits] [llvm] r72210 - in /llvm/trunk: include/llvm/ADT/StringMap.h lib/Analysis/ConstantFolding.cpp lib/Analysis/DebugInfo.cpp lib/AsmParser/LLParser.cpp lib/CodeGen/SelectionDAG/LegalizeDAG.cpp lib/VMCore/Attributes.cpp lib/VMCore/ValueSymbolTable.cpp

Jay Foad jay.foad at gmail.com
Thu May 21 02:52:49 PDT 2009


Author: foad
Date: Thu May 21 04:52:38 2009
New Revision: 72210

URL: http://llvm.org/viewvc/llvm-project?rev=72210&view=rev
Log:
Use v.data() instead of &v[0] when SmallVector v might be empty.

Modified:
    llvm/trunk/include/llvm/ADT/StringMap.h
    llvm/trunk/lib/Analysis/ConstantFolding.cpp
    llvm/trunk/lib/Analysis/DebugInfo.cpp
    llvm/trunk/lib/AsmParser/LLParser.cpp
    llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
    llvm/trunk/lib/VMCore/Attributes.cpp
    llvm/trunk/lib/VMCore/ValueSymbolTable.cpp

Modified: llvm/trunk/include/llvm/ADT/StringMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringMap.h?rev=72210&r1=72209&r2=72210&view=diff

==============================================================================
--- llvm/trunk/include/llvm/ADT/StringMap.h (original)
+++ llvm/trunk/include/llvm/ADT/StringMap.h Thu May 21 04:52:38 2009
@@ -286,8 +286,7 @@
     return find(Key, Key + strlen(Key));
   }
   iterator find(const std::string &Key) {
-    const char* key_start = (Key.empty() ? NULL : &Key[0]);
-    return find(key_start, key_start + Key.size());
+    return find(Key.data(), Key.data() + Key.size());
   }
 
   const_iterator find(const char *KeyStart, const char *KeyEnd) const {
@@ -299,8 +298,7 @@
     return find(Key, Key + strlen(Key));
   }
   const_iterator find(const std::string &Key) const {
-    const char* key_start = (Key.empty() ? NULL : &Key[0]);
-    return find(key_start, key_start + Key.size());
+    return find(Key.data(), Key.data() + Key.size());
   }
 
    /// lookup - Return the entry for the specified key, or a default
@@ -328,8 +326,7 @@
     return GetOrCreateValue(Key, Key + strlen(Key)).getValue();
   }
   ValueTy& operator[](const std::string &Key) {
-    const char* key_start = (Key.empty() ? NULL : &Key[0]);
-    return GetOrCreateValue(key_start, key_start + Key.size()).getValue();
+    return GetOrCreateValue(Key.data(), Key.data() + Key.size()).getValue();
   }
 
   size_type count(const char *KeyStart, const char *KeyEnd) const {
@@ -339,8 +336,7 @@
     return count(Key, Key + strlen(Key));
   }
   size_type count(const std::string &Key) const {
-    const char* key_start = (Key.empty() ? NULL : &Key[0]);
-    return count(key_start, key_start + Key.size());
+    return count(Key.data(), Key.data() + Key.size());
   }
 
   /// insert - Insert the specified key/value pair into the map.  If the key

Modified: llvm/trunk/lib/Analysis/ConstantFolding.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ConstantFolding.cpp?rev=72210&r1=72209&r2=72210&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/ConstantFolding.cpp (original)
+++ llvm/trunk/lib/Analysis/ConstantFolding.cpp Thu May 21 04:52:38 2009
@@ -260,7 +260,7 @@
         }
       }
       
-      return ConstantVector::get(&Result[0], Result.size());
+      return ConstantVector::get(Result.data(), Result.size());
     }
   }
   
@@ -306,10 +306,10 @@
 
   if (const CmpInst *CI = dyn_cast<CmpInst>(I))
     return ConstantFoldCompareInstOperands(CI->getPredicate(),
-                                           &Ops[0], Ops.size(), TD);
+                                           Ops.data(), Ops.size(), TD);
   else
     return ConstantFoldInstOperands(I->getOpcode(), I->getType(),
-                                    &Ops[0], Ops.size(), TD);
+                                    Ops.data(), Ops.size(), TD);
 }
 
 /// ConstantFoldConstantExpression - Attempt to fold the constant expression
@@ -325,10 +325,10 @@
 
   if (CE->isCompare())
     return ConstantFoldCompareInstOperands(CE->getPredicate(),
-                                           &Ops[0], Ops.size(), TD);
+                                           Ops.data(), Ops.size(), TD);
   else 
     return ConstantFoldInstOperands(CE->getOpcode(), CE->getType(),
-                                    &Ops[0], Ops.size(), TD);
+                                    Ops.data(), Ops.size(), TD);
 }
 
 /// ConstantFoldInstOperands - Attempt to constant fold an instruction with the

Modified: llvm/trunk/lib/Analysis/DebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/DebugInfo.cpp?rev=72210&r1=72209&r2=72210&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/DebugInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/DebugInfo.cpp Thu May 21 04:52:38 2009
@@ -442,7 +442,7 @@
   
   Constant *Init = ConstantArray::get(ArrayType::get(EmptyStructPtr,
                                                      Elts.size()),
-                                      &Elts[0], Elts.size());
+                                      Elts.data(), Elts.size());
   // If we already have this array, just return the uniqued version.
   DIDescriptor &Entry = SimpleConstantCache[Init];
   if (!Entry.isNull()) return DIArray(Entry.getGV());

Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=72210&r1=72209&r2=72210&view=diff

==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Thu May 21 04:52:38 2009
@@ -1577,7 +1577,7 @@
           ParseToken(lltok::rbrace, "expected end of metadata node"))
         return true;
 
-      ID.ConstantVal = MDNode::get(&Elts[0], Elts.size());
+      ID.ConstantVal = MDNode::get(Elts.data(), Elts.size());
       return false;
     }
 
@@ -1617,7 +1617,7 @@
         ParseToken(lltok::rbrace, "expected end of struct constant"))
       return true;
     
-    ID.ConstantVal = ConstantStruct::get(&Elts[0], Elts.size(), false);
+    ID.ConstantVal = ConstantStruct::get(Elts.data(), Elts.size(), false);
     ID.Kind = ValID::t_Constant;
     return false;
   }
@@ -1636,7 +1636,7 @@
       return true;
     
     if (isPackedStruct) {
-      ID.ConstantVal = ConstantStruct::get(&Elts[0], Elts.size(), true);
+      ID.ConstantVal = ConstantStruct::get(Elts.data(), Elts.size(), true);
       ID.Kind = ValID::t_Constant;
       return false;
     }
@@ -1656,7 +1656,7 @@
                      "vector element #" + utostr(i) +
                     " is not of type '" + Elts[0]->getType()->getDescription());
     
-    ID.ConstantVal = ConstantVector::get(&Elts[0], Elts.size());
+    ID.ConstantVal = ConstantVector::get(Elts.data(), Elts.size());
     ID.Kind = ValID::t_Constant;
     return false;
   }
@@ -1690,7 +1690,7 @@
                      " is not of type '" +Elts[0]->getType()->getDescription());
     }
     
-    ID.ConstantVal = ConstantArray::get(ATy, &Elts[0], Elts.size());
+    ID.ConstantVal = ConstantArray::get(ATy, Elts.data(), Elts.size());
     ID.Kind = ValID::t_Constant;
     return false;
   }
@@ -1761,8 +1761,8 @@
     if (!ExtractValueInst::getIndexedType(Val->getType(), Indices.begin(),
                                           Indices.end()))
       return Error(ID.Loc, "invalid indices for extractvalue");
-    ID.ConstantVal = ConstantExpr::getExtractValue(Val,
-                                                   &Indices[0], Indices.size());
+    ID.ConstantVal =
+      ConstantExpr::getExtractValue(Val, Indices.data(), Indices.size());
     ID.Kind = ValID::t_Constant;
     return false;
   }
@@ -1782,8 +1782,8 @@
     if (!ExtractValueInst::getIndexedType(Val0->getType(), Indices.begin(),
                                           Indices.end()))
       return Error(ID.Loc, "invalid indices for insertvalue");
-    ID.ConstantVal = ConstantExpr::getInsertValue(Val0, Val1,
-                                                  &Indices[0], Indices.size());
+    ID.ConstantVal =
+      ConstantExpr::getInsertValue(Val0, Val1, Indices.data(), Indices.size());
     ID.Kind = ValID::t_Constant;
     return false;
   }

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp?rev=72210&r1=72209&r2=72210&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp Thu May 21 04:52:38 2009
@@ -1041,7 +1041,7 @@
       for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i)
         Ops.push_back(LegalizeOp(Node->getOperand(i)));
 
-      Result = DAG.UpdateNodeOperands(Result.getValue(0), &Ops[0], Ops.size());
+      Result = DAG.UpdateNodeOperands(Result.getValue(0), Ops.data(), Ops.size());
 
       for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i)
         AddLegalizedOperand(Op.getValue(i), Result.getValue(i));

Modified: llvm/trunk/lib/VMCore/Attributes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Attributes.cpp?rev=72210&r1=72209&r2=72210&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Attributes.cpp (original)
+++ llvm/trunk/lib/VMCore/Attributes.cpp Thu May 21 04:52:38 2009
@@ -108,7 +108,7 @@
   void DropRef() { if (--RefCount == 0) delete this; }
   
   void Profile(FoldingSetNodeID &ID) const {
-    Profile(ID, &Attrs[0], Attrs.size());
+    Profile(ID, Attrs.data(), Attrs.size());
   }
   static void Profile(FoldingSetNodeID &ID, const AttributeWithIndex *Attr,
                       unsigned NumAttrs) {
@@ -261,7 +261,7 @@
                        OldAttrList.begin()+i, OldAttrList.end());
   }
   
-  return get(&NewAttrList[0], NewAttrList.size());
+  return get(NewAttrList.data(), NewAttrList.size());
 }
 
 AttrListPtr AttrListPtr::removeAttr(unsigned Idx, Attributes Attrs) const {
@@ -296,7 +296,7 @@
   NewAttrList.insert(NewAttrList.end(), 
                      OldAttrList.begin()+i, OldAttrList.end());
   
-  return get(&NewAttrList[0], NewAttrList.size());
+  return get(NewAttrList.data(), NewAttrList.size());
 }
 
 void AttrListPtr::dump() const {

Modified: llvm/trunk/lib/VMCore/ValueSymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/ValueSymbolTable.cpp?rev=72210&r1=72209&r2=72210&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/ValueSymbolTable.cpp (original)
+++ llvm/trunk/lib/VMCore/ValueSymbolTable.cpp Thu May 21 04:52:38 2009
@@ -33,7 +33,7 @@
 // lookup a value - Returns null on failure...
 //
 Value *ValueSymbolTable::lookup(const std::string &Name) const {
-  const_iterator VI = vmap.find(&Name[0], &Name[Name.size()]);
+  const_iterator VI = vmap.find(Name.data(), Name.data() + Name.size());
   if (VI != vmap.end())                   // We found the symbol
     return VI->getValue();
   return 0;
@@ -70,8 +70,9 @@
     UniqueName.resize(BaseSize);
     UniqueName.append_uint_32(++LastUnique);
     // Try insert the vmap entry with this suffix.
-    ValueName &NewName = vmap.GetOrCreateValue(&UniqueName[0],
-                                               &UniqueName[UniqueName.size()]);
+    ValueName &NewName =
+      vmap.GetOrCreateValue(UniqueName.data(),
+                            UniqueName.data() + UniqueName.size());
     if (NewName.getValue() == 0) {
       // Newly inserted name.  Success!
       NewName.setValue(V);
@@ -111,8 +112,9 @@
     UniqueName.append_uint_32(++LastUnique);
     
     // Try insert the vmap entry with this suffix.
-    ValueName &NewName = vmap.GetOrCreateValue(&UniqueName[0],
-                                               &UniqueName[UniqueName.size()]);
+    ValueName &NewName =
+      vmap.GetOrCreateValue(UniqueName.data(),
+                            UniqueName.data() + UniqueName.size());
     if (NewName.getValue() == 0) {
       // Newly inserted name.  Success!
       NewName.setValue(V);





More information about the llvm-commits mailing list