[llvm-commits] [llvm] r77347 - in /llvm/trunk: examples/BrainF/ include/llvm/ include/llvm/Support/ lib/Analysis/ lib/AsmParser/ lib/Bitcode/Reader/ lib/CodeGen/ lib/CodeGen/SelectionDAG/ lib/Linker/ lib/Target/XCore/ lib/Transforms/IPO/ lib/Transforms/Scalar/ lib/Transforms/Utils/ lib/VMCore/ tools/bugpoint/

Owen Anderson resistor at mac.com
Tue Jul 28 11:32:18 PDT 2009


Author: resistor
Date: Tue Jul 28 13:32:17 2009
New Revision: 77347

URL: http://llvm.org/viewvc/llvm-project?rev=77347&view=rev
Log:
Change ConstantArray to 2.5 API.

Modified:
    llvm/trunk/examples/BrainF/BrainF.cpp
    llvm/trunk/include/llvm/Constants.h
    llvm/trunk/include/llvm/LLVMContext.h
    llvm/trunk/include/llvm/Support/IRBuilder.h
    llvm/trunk/lib/Analysis/DebugInfo.cpp
    llvm/trunk/lib/AsmParser/LLParser.cpp
    llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
    llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
    llvm/trunk/lib/CodeGen/ShadowStackGC.cpp
    llvm/trunk/lib/Linker/LinkModules.cpp
    llvm/trunk/lib/Target/XCore/XCoreTargetObjectFile.cpp
    llvm/trunk/lib/Transforms/IPO/ExtractGV.cpp
    llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
    llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp
    llvm/trunk/lib/Transforms/Utils/LowerInvoke.cpp
    llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp
    llvm/trunk/lib/VMCore/ConstantFold.cpp
    llvm/trunk/lib/VMCore/Constants.cpp
    llvm/trunk/lib/VMCore/Core.cpp
    llvm/trunk/lib/VMCore/LLVMContext.cpp
    llvm/trunk/lib/VMCore/LLVMContextImpl.cpp
    llvm/trunk/lib/VMCore/LLVMContextImpl.h
    llvm/trunk/tools/bugpoint/ExtractFunction.cpp
    llvm/trunk/tools/bugpoint/Miscompilation.cpp

Modified: llvm/trunk/examples/BrainF/BrainF.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/BrainF/BrainF.cpp?rev=77347&r1=77346&r2=77347&view=diff

==============================================================================
--- llvm/trunk/examples/BrainF/BrainF.cpp (original)
+++ llvm/trunk/examples/BrainF/BrainF.cpp Tue Jul 28 13:32:17 2009
@@ -125,7 +125,7 @@
   {
     //@aberrormsg = internal constant [%d x i8] c"\00"
     Constant *msg_0 =
-      C.getConstantArray("Error: The head has left the tape.", true);
+      ConstantArray::get("Error: The head has left the tape.", true);
 
     GlobalVariable *aberrormsg = new GlobalVariable(
       *module,

Modified: llvm/trunk/include/llvm/Constants.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Constants.h?rev=77347&r1=77346&r2=77347&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Constants.h (original)
+++ llvm/trunk/include/llvm/Constants.h Tue Jul 28 13:32:17 2009
@@ -327,10 +327,22 @@
   friend struct ConstantCreator<ConstantArray, ArrayType,
                                     std::vector<Constant*> >;
   ConstantArray(const ConstantArray &);      // DO NOT IMPLEMENT
-  friend class LLVMContextImpl;
 protected:
   ConstantArray(const ArrayType *T, const std::vector<Constant*> &Val);
 public:
+  // ConstantArray accessors
+  static Constant* get(const ArrayType* T, const std::vector<Constant*>& V);
+  static Constant* get(const ArrayType* T, Constant* const* Vals, 
+                       unsigned NumVals);
+                             
+  /// This method constructs a ConstantArray and initializes it with a text
+  /// string. The default behavior (AddNull==true) causes a null terminator to
+  /// be placed at the end of the array. This effectively increases the length
+  /// of the array by one (you've been warned).  However, in some situations 
+  /// this is not desired so if AddNull==false then the string is copied without
+  /// null termination.
+  static Constant* get(const StringRef &Initializer, bool AddNull = true);
+  
   /// Transparently provide more efficient getOperand methods.
   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
 

Modified: llvm/trunk/include/llvm/LLVMContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LLVMContext.h?rev=77347&r1=77346&r2=77347&view=diff

==============================================================================
--- llvm/trunk/include/llvm/LLVMContext.h (original)
+++ llvm/trunk/include/llvm/LLVMContext.h Tue Jul 28 13:32:17 2009
@@ -58,6 +58,7 @@
   friend class ConstantInt;
   friend class ConstantFP;
   friend class ConstantStruct;
+  friend class ConstantArray;
 public:
   LLVMContext();
   ~LLVMContext();
@@ -82,21 +83,6 @@
                               
   // ConstantAggregateZero accessors
   ConstantAggregateZero* getConstantAggregateZero(const Type* Ty);
-  
-  // ConstantArray accessors
-  Constant* getConstantArray(const ArrayType* T,
-                             const std::vector<Constant*>& V);
-  Constant* getConstantArray(const ArrayType* T, Constant* const* Vals,
-                             unsigned NumVals);
-                             
-  /// This method constructs a ConstantArray and initializes it with a text
-  /// string. The default behavior (AddNull==true) causes a null terminator to
-  /// be placed at the end of the array. This effectively increases the length
-  /// of the array by one (you've been warned).  However, in some situations 
-  /// this is not desired so if AddNull==false then the string is copied without
-  /// null termination.
-  Constant* getConstantArray(const StringRef &Initializer,
-                             bool AddNull = true);
                              
   // ConstantExpr accessors
   Constant* getConstantExpr(unsigned Opcode, Constant* C1, Constant* C2);
@@ -225,12 +211,7 @@
   void erase(MDString *M);
   void erase(MDNode *M);
   void erase(ConstantAggregateZero *Z);
-  void erase(ConstantArray *Z);
   void erase(ConstantVector *V);
-  
-  // RAUW helpers
-  Constant *replaceUsesOfWithOnConstant(ConstantArray *CA,
-                                             Value *From, Value *To, Use *U);
 };
 
 /// FOR BACKWARDS COMPATIBILITY - Returns a global context.

Modified: llvm/trunk/include/llvm/Support/IRBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/IRBuilder.h?rev=77347&r1=77346&r2=77347&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/IRBuilder.h (original)
+++ llvm/trunk/include/llvm/Support/IRBuilder.h Tue Jul 28 13:32:17 2009
@@ -413,7 +413,7 @@
     return CreateConstGEP2_32(Ptr, 0, Idx, Name);
   }
   Value *CreateGlobalString(const char *Str = "", const char *Name = "") {
-    Constant *StrConstant = Context.getConstantArray(Str, true);
+    Constant *StrConstant = ConstantArray::get(Str, true);
     Module &M = *BB->getParent()->getParent();
     GlobalVariable *gv = new GlobalVariable(M,
                                             StrConstant->getType(),

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

==============================================================================
--- llvm/trunk/lib/Analysis/DebugInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/DebugInfo.cpp Tue Jul 28 13:32:17 2009
@@ -499,7 +499,7 @@
     return Slot = VMContext.getConstantPointerNull(DestTy);
 
   // Construct string as an llvm constant.
-  Constant *ConstStr = VMContext.getConstantArray(String);
+  Constant *ConstStr = ConstantArray::get(String);
     
   // Otherwise create and return a new string global.
   GlobalVariable *StrGV = new GlobalVariable(M, ConstStr->getType(), true,
@@ -521,7 +521,7 @@
   for (unsigned i = 0; i != NumTys; ++i)
     Elts.push_back(getCastToEmpty(Tys[i]));
   
-  Constant *Init = VMContext.getConstantArray(VMContext.getArrayType(EmptyStructPtr,
+  Constant *Init = ConstantArray::get(VMContext.getArrayType(EmptyStructPtr,
                                                      Elts.size()),
                                       Elts.data(), Elts.size());
   // If we already have this array, just return the uniqued version.

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

==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Tue Jul 28 13:32:17 2009
@@ -1811,13 +1811,13 @@
                      " is not of type '" +Elts[0]->getType()->getDescription());
     }
     
-    ID.ConstantVal = Context.getConstantArray(ATy, Elts.data(), Elts.size());
+    ID.ConstantVal = ConstantArray::get(ATy, Elts.data(), Elts.size());
     ID.Kind = ValID::t_Constant;
     return false;
   }
   case lltok::kw_c:  // c "foo"
     Lex.Lex();
-    ID.ConstantVal = Context.getConstantArray(Lex.getStrVal(), false);
+    ID.ConstantVal = ConstantArray::get(Lex.getStrVal(), false);
     if (ParseToken(lltok::StringConstant, "expected string")) return true;
     ID.Kind = ValID::t_Constant;
     return false;

Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=77347&r1=77346&r2=77347&view=diff

==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Tue Jul 28 13:32:17 2009
@@ -288,7 +288,7 @@
       // Make the new constant.
       Constant *NewC;
       if (ConstantArray *UserCA = dyn_cast<ConstantArray>(UserC)) {
-        NewC = Context.getConstantArray(UserCA->getType(), &NewOps[0],
+        NewC = ConstantArray::get(UserCA->getType(), &NewOps[0],
                                         NewOps.size());
       } else if (ConstantStruct *UserCS = dyn_cast<ConstantStruct>(UserC)) {
         NewC = ConstantStruct::get(&NewOps[0], NewOps.size(),
@@ -930,7 +930,7 @@
         const Type *EltTy = ATy->getElementType();
         for (unsigned i = 0; i != Size; ++i)
           Elts.push_back(ValueList.getConstantFwdRef(Record[i], EltTy));
-        V = Context.getConstantArray(ATy, Elts);
+        V = ConstantArray::get(ATy, Elts);
       } else if (const VectorType *VTy = dyn_cast<VectorType>(CurTy)) {
         const Type *EltTy = VTy->getElementType();
         for (unsigned i = 0; i != Size; ++i)
@@ -952,7 +952,7 @@
       std::vector<Constant*> Elts;
       for (unsigned i = 0; i != Size; ++i)
         Elts.push_back(ConstantInt::get(EltTy, Record[i]));
-      V = Context.getConstantArray(ATy, Elts);
+      V = ConstantArray::get(ATy, Elts);
       break;
     }
     case bitc::CST_CODE_CSTRING: { // CSTRING: [values]
@@ -967,7 +967,7 @@
       for (unsigned i = 0; i != Size; ++i)
         Elts.push_back(ConstantInt::get(EltTy, Record[i]));
       Elts.push_back(Context.getNullValue(EltTy));
-      V = Context.getConstantArray(ATy, Elts);
+      V = ConstantArray::get(ATy, Elts);
       break;
     }
     case bitc::CST_CODE_CE_BINOP: {  // CE_BINOP: [opcode, opval, opval]

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

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Tue Jul 28 13:32:17 2009
@@ -5812,7 +5812,7 @@
         const TargetData &TD = *TLI.getTargetData();
         
         // Create a ConstantArray of the two constants.
-        Constant *CA = DAG.getContext()->getConstantArray(
+        Constant *CA = ConstantArray::get(
                           DAG.getContext()->getArrayType(FPTy, 2), Elts, 2);
         SDValue CPIdx = DAG.getConstantPool(CA, TLI.getPointerTy(),
                                             TD.getPrefTypeAlignment(FPTy));

Modified: llvm/trunk/lib/CodeGen/ShadowStackGC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ShadowStackGC.cpp?rev=77347&r1=77346&r2=77347&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/ShadowStackGC.cpp (original)
+++ llvm/trunk/lib/CodeGen/ShadowStackGC.cpp Tue Jul 28 13:32:17 2009
@@ -209,7 +209,7 @@
 
   Constant *DescriptorElts[] = {
     ConstantStruct::get(BaseElts, 2),
-    Context.getConstantArray(Context.getArrayType(VoidPtr, NumMeta),
+    ConstantArray::get(Context.getArrayType(VoidPtr, NumMeta),
                        Metadata.begin(), NumMeta)
   };
 

Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=77347&r1=77346&r2=77347&view=diff

==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Tue Jul 28 13:32:17 2009
@@ -369,7 +369,7 @@
         Operands[i] =cast<Constant>(RemapOperand(CPA->getOperand(i), ValueMap, 
                                                  Context));
       Result =
-          Context.getConstantArray(cast<ArrayType>(CPA->getType()), Operands);
+          ConstantArray::get(cast<ArrayType>(CPA->getType()), Operands);
     } else if (const ConstantStruct *CPS = dyn_cast<ConstantStruct>(CPV)) {
       std::vector<Constant*> Operands(CPS->getNumOperands());
       for (unsigned i = 0, e = CPS->getNumOperands(); i != e; ++i)
@@ -1186,7 +1186,7 @@
         for (unsigned i = 0, e = T2->getNumElements(); i != e; ++i)
           Inits.push_back(CV);
       }
-      NG->setInitializer(Context.getConstantArray(NewType, Inits));
+      NG->setInitializer(ConstantArray::get(NewType, Inits));
       Inits.clear();
 
       // Replace any uses of the two global variables with uses of the new

Modified: llvm/trunk/lib/Target/XCore/XCoreTargetObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/XCore/XCoreTargetObjectFile.cpp?rev=77347&r1=77346&r2=77347&view=diff

==============================================================================
--- llvm/trunk/lib/Target/XCore/XCoreTargetObjectFile.cpp (original)
+++ llvm/trunk/lib/Target/XCore/XCoreTargetObjectFile.cpp Tue Jul 28 13:32:17 2009
@@ -29,4 +29,4 @@
   else
     ReadOnlySection = getOrCreateSection("\t.cp.rodata", false,
                                          SectionKind::ReadOnly);
-}
\ No newline at end of file
+}

Modified: llvm/trunk/lib/Transforms/IPO/ExtractGV.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/ExtractGV.cpp?rev=77347&r1=77346&r2=77347&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/IPO/ExtractGV.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/ExtractGV.cpp Tue Jul 28 13:32:17 2009
@@ -110,7 +110,7 @@
           AUGs.push_back(Context.getConstantExprBitCast(*GI, SBP));
         }
         ArrayType *AT = Context.getArrayType(SBP, AUGs.size());
-        Constant *Init = Context.getConstantArray(AT, AUGs);
+        Constant *Init = ConstantArray::get(AT, AUGs);
         GlobalValue *gv = new GlobalVariable(M, AT, false, 
                                              GlobalValue::AppendingLinkage, 
                                              Init, "llvm.used");

Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=77347&r1=77346&r2=77347&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Tue Jul 28 13:32:17 2009
@@ -1968,7 +1968,7 @@
   // Create the array initializer.
   const Type *StructTy =
     cast<ArrayType>(GCL->getType()->getElementType())->getElementType();
-  Constant *CA = Context.getConstantArray(ArrayType::get(StructTy, 
+  Constant *CA = ConstantArray::get(ArrayType::get(StructTy, 
                                            CAList.size()), CAList);
   
   // If we didn't change the number of elements, don't create a new GV.
@@ -2094,7 +2094,7 @@
     assert(CI->getZExtValue() < ATy->getNumElements());
     Elts[CI->getZExtValue()] =
       EvaluateStoreInto(Elts[CI->getZExtValue()], Val, Addr, OpNo+1, Context);
-    return Context.getConstantArray(ATy, Elts);
+    return ConstantArray::get(ATy, Elts);
   }    
 }
 

Modified: llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp?rev=77347&r1=77346&r2=77347&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp Tue Jul 28 13:32:17 2009
@@ -1290,7 +1290,7 @@
       // Create a string literal with no \n on it.  We expect the constant merge
       // pass to be run after this pass, to merge duplicate strings.
       FormatStr.erase(FormatStr.end()-1);
-      Constant *C = Context->getConstantArray(FormatStr, true);
+      Constant *C = ConstantArray::get(FormatStr, true);
       C = new GlobalVariable(*Callee->getParent(), C->getType(), true,
                              GlobalVariable::InternalLinkage, C, "str");
       EmitPutS(C, B);

Modified: llvm/trunk/lib/Transforms/Utils/LowerInvoke.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LowerInvoke.cpp?rev=77347&r1=77346&r2=77347&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Utils/LowerInvoke.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/LowerInvoke.cpp Tue Jul 28 13:32:17 2009
@@ -183,7 +183,7 @@
     // The abort message for expensive EH support tells the user that the
     // program 'unwound' without an 'invoke' instruction.
     Constant *Msg =
-      Context.getConstantArray("ERROR: Exception thrown, but not caught!\n");
+      ConstantArray::get("ERROR: Exception thrown, but not caught!\n");
     AbortMessageLength = Msg->getNumOperands()-1;  // don't include \0
 
     GlobalVariable *MsgGV = new GlobalVariable(*M, Msg->getType(), true,
@@ -195,7 +195,7 @@
     // The abort message for cheap EH support tells the user that EH is not
     // enabled.
     Constant *Msg =
-      Context.getConstantArray("Exception handler needed, but not enabled."      
+      ConstantArray::get("Exception handler needed, but not enabled."      
                         "Recompile program with -enable-correct-eh-support.\n");
     AbortMessageLength = Msg->getNumOperands()-1;  // don't include \0
 

Modified: llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp?rev=77347&r1=77346&r2=77347&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp Tue Jul 28 13:32:17 2009
@@ -56,7 +56,7 @@
           Values.push_back(cast<Constant>(MV));
           for (++i; i != e; ++i)
             Values.push_back(cast<Constant>(MapValue(*i, VM, Context)));
-          return VM[V] = Context.getConstantArray(CA->getType(), Values);
+          return VM[V] = ConstantArray::get(CA->getType(), Values);
         }
       }
       return VM[V] = C;

Modified: llvm/trunk/lib/VMCore/ConstantFold.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/ConstantFold.cpp?rev=77347&r1=77346&r2=77347&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/ConstantFold.cpp (original)
+++ llvm/trunk/lib/VMCore/ConstantFold.cpp Tue Jul 28 13:32:17 2009
@@ -521,7 +521,7 @@
     if (isa<StructType>(AggTy))
       return ConstantStruct::get(Ops);
     else
-      return Context.getConstantArray(cast<ArrayType>(AggTy), Ops);
+      return ConstantArray::get(cast<ArrayType>(AggTy), Ops);
   }
   if (isa<ConstantAggregateZero>(Agg)) {
     // Insertion of constant into aggregate zero
@@ -550,7 +550,7 @@
     if (isa<StructType>(AggTy))
       return ConstantStruct::get(Ops);
     else
-      return Context.getConstantArray(cast<ArrayType>(AggTy), Ops);
+      return ConstantArray::get(cast<ArrayType>(AggTy), Ops);
   }
   if (isa<ConstantStruct>(Agg) || isa<ConstantArray>(Agg)) {
     // Insertion of constant into aggregate constant
@@ -567,7 +567,7 @@
     if (isa<StructType>(Agg->getType()))
       C = ConstantStruct::get(Ops);
     else
-      C = Context.getConstantArray(cast<ArrayType>(Agg->getType()), Ops);
+      C = ConstantArray::get(cast<ArrayType>(Agg->getType()), Ops);
     return C;
   }
 

Modified: llvm/trunk/lib/VMCore/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Constants.cpp?rev=77347&r1=77346&r2=77347&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Constants.cpp (original)
+++ llvm/trunk/lib/VMCore/Constants.cpp Tue Jul 28 13:32:17 2009
@@ -375,6 +375,54 @@
   }
 }
 
+Constant *ConstantArray::get(const ArrayType *Ty, 
+                             const std::vector<Constant*> &V) {
+  LLVMContextImpl *pImpl = Ty->getContext().pImpl;
+  // If this is an all-zero array, return a ConstantAggregateZero object
+  if (!V.empty()) {
+    Constant *C = V[0];
+    if (!C->isNullValue()) {
+      // Implicitly locked.
+      return pImpl->ArrayConstants.getOrCreate(Ty, V);
+    }
+    for (unsigned i = 1, e = V.size(); i != e; ++i)
+      if (V[i] != C) {
+        // Implicitly locked.
+        return pImpl->ArrayConstants.getOrCreate(Ty, V);
+      }
+  }
+  
+  return Ty->getContext().getConstantAggregateZero(Ty);
+}
+
+
+Constant* ConstantArray::get(const ArrayType* T, Constant* const* Vals,
+                             unsigned NumVals) {
+  // FIXME: make this the primary ctor method.
+  return get(T, std::vector<Constant*>(Vals, Vals+NumVals));
+}
+
+/// ConstantArray::get(const string&) - Return an array that is initialized to
+/// contain the specified string.  If length is zero then a null terminator is 
+/// added to the specified string so that it may be used in a natural way. 
+/// Otherwise, the length parameter specifies how much of the string to use 
+/// and it won't be null terminated.
+///
+Constant* ConstantArray::get(const StringRef &Str, bool AddNull) {
+  std::vector<Constant*> ElementVals;
+  for (unsigned i = 0; i < Str.size(); ++i)
+    ElementVals.push_back(ConstantInt::get(Type::Int8Ty, Str[i]));
+
+  // Add a null terminator to the string...
+  if (AddNull) {
+    ElementVals.push_back(ConstantInt::get(Type::Int8Ty, 0));
+  }
+
+  ArrayType *ATy = ArrayType::get(Type::Int8Ty, ElementVals.size());
+  return get(ATy, ElementVals);
+}
+
+
 
 ConstantStruct::ConstantStruct(const StructType *T,
                                const std::vector<Constant*> &V)
@@ -943,7 +991,7 @@
 ///
 void ConstantArray::destroyConstant() {
   // Implicitly locked.
-  getType()->getContext().erase(this);
+  getType()->getContext().pImpl->ArrayConstants.remove(this);
   destroyConstantImpl();
 }
 
@@ -1907,12 +1955,91 @@
 /// single invocation handles all 1000 uses.  Handling them one at a time would
 /// work, but would be really slow because it would have to unique each updated
 /// array instance.
+
+static std::vector<Constant*> getValType(ConstantArray *CA) {
+  std::vector<Constant*> Elements;
+  Elements.reserve(CA->getNumOperands());
+  for (unsigned i = 0, e = CA->getNumOperands(); i != e; ++i)
+    Elements.push_back(cast<Constant>(CA->getOperand(i)));
+  return Elements;
+}
+
+
 void ConstantArray::replaceUsesOfWithOnConstant(Value *From, Value *To,
                                                 Use *U) {
-  Constant *Replacement =
-    getType()->getContext().replaceUsesOfWithOnConstant(this, From, To, U);
- 
-  if (!Replacement) return;
+  assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!");
+  Constant *ToC = cast<Constant>(To);
+
+  LLVMContext &Context = getType()->getContext();
+  LLVMContextImpl *pImpl = Context.pImpl;
+
+  std::pair<LLVMContextImpl::ArrayConstantsTy::MapKey, Constant*> Lookup;
+  Lookup.first.first = getType();
+  Lookup.second = this;
+
+  std::vector<Constant*> &Values = Lookup.first.second;
+  Values.reserve(getNumOperands());  // Build replacement array.
+
+  // Fill values with the modified operands of the constant array.  Also, 
+  // compute whether this turns into an all-zeros array.
+  bool isAllZeros = false;
+  unsigned NumUpdated = 0;
+  if (!ToC->isNullValue()) {
+    for (Use *O = OperandList, *E = OperandList+getNumOperands(); O != E; ++O) {
+      Constant *Val = cast<Constant>(O->get());
+      if (Val == From) {
+        Val = ToC;
+        ++NumUpdated;
+      }
+      Values.push_back(Val);
+    }
+  } else {
+    isAllZeros = true;
+    for (Use *O = OperandList, *E = OperandList+getNumOperands();O != E; ++O) {
+      Constant *Val = cast<Constant>(O->get());
+      if (Val == From) {
+        Val = ToC;
+        ++NumUpdated;
+      }
+      Values.push_back(Val);
+      if (isAllZeros) isAllZeros = Val->isNullValue();
+    }
+  }
+  
+  Constant *Replacement = 0;
+  if (isAllZeros) {
+    Replacement = Context.getConstantAggregateZero(getType());
+  } else {
+    // Check to see if we have this array type already.
+    sys::SmartScopedWriter<true> Writer(pImpl->ConstantsLock);
+    bool Exists;
+    LLVMContextImpl::ArrayConstantsTy::MapTy::iterator I =
+      pImpl->ArrayConstants.InsertOrGetItem(Lookup, Exists);
+    
+    if (Exists) {
+      Replacement = I->second;
+    } else {
+      // Okay, the new shape doesn't exist in the system yet.  Instead of
+      // creating a new constant array, inserting it, replaceallusesof'ing the
+      // old with the new, then deleting the old... just update the current one
+      // in place!
+      pImpl->ArrayConstants.MoveConstantToNewSlot(this, I);
+      
+      // Update to the new value.  Optimize for the case when we have a single
+      // operand that we're changing, but handle bulk updates efficiently.
+      if (NumUpdated == 1) {
+        unsigned OperandToUpdate = U - OperandList;
+        assert(getOperand(OperandToUpdate) == From &&
+               "ReplaceAllUsesWith broken!");
+        setOperand(OperandToUpdate, ToC);
+      } else {
+        for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
+          if (getOperand(i) == From)
+            setOperand(i, ToC);
+      }
+      return;
+    }
+  }
  
   // Otherwise, I do need to replace this with an existing value.
   assert(Replacement != this && "I didn't contain From!");

Modified: llvm/trunk/lib/VMCore/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Core.cpp?rev=77347&r1=77346&r2=77347&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Core.cpp (original)
+++ llvm/trunk/lib/VMCore/Core.cpp Tue Jul 28 13:32:17 2009
@@ -402,13 +402,13 @@
                              int DontNullTerminate) {
   /* Inverted the sense of AddNull because ', 0)' is a
      better mnemonic for null termination than ', 1)'. */
-  return wrap(getGlobalContext().getConstantArray(std::string(Str, Length),
+  return wrap(ConstantArray::get(std::string(Str, Length),
                                  DontNullTerminate == 0));
 }
 
 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
                             LLVMValueRef *ConstantVals, unsigned Length) {
-  return wrap(getGlobalContext().getConstantArray(
+  return wrap(ConstantArray::get(
                     getGlobalContext().getArrayType(unwrap(ElementTy), Length),
                                  unwrap<Constant>(ConstantVals, Length),
                                  Length));

Modified: llvm/trunk/lib/VMCore/LLVMContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LLVMContext.cpp?rev=77347&r1=77346&r2=77347&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContext.cpp (original)
+++ llvm/trunk/lib/VMCore/LLVMContext.cpp Tue Jul 28 13:32:17 2009
@@ -103,42 +103,6 @@
   return pImpl->getConstantAggregateZero(Ty);
 }
 
-
-// ConstantArray accessors.
-Constant* LLVMContext::getConstantArray(const ArrayType* T,
-                                        const std::vector<Constant*>& V) {
-  return pImpl->getConstantArray(T, V);
-}
-
-Constant* LLVMContext::getConstantArray(const ArrayType* T,
-                                        Constant* const* Vals,
-                                        unsigned NumVals) {
-  // FIXME: make this the primary ctor method.
-  return getConstantArray(T, std::vector<Constant*>(Vals, Vals+NumVals));
-}
-
-/// ConstantArray::get(const string&) - Return an array that is initialized to
-/// contain the specified string.  If length is zero then a null terminator is 
-/// added to the specified string so that it may be used in a natural way. 
-/// Otherwise, the length parameter specifies how much of the string to use 
-/// and it won't be null terminated.
-///
-Constant* LLVMContext::getConstantArray(const StringRef &Str,
-                                        bool AddNull) {
-  std::vector<Constant*> ElementVals;
-  for (unsigned i = 0; i < Str.size(); ++i)
-    ElementVals.push_back(ConstantInt::get(Type::Int8Ty, Str[i]));
-
-  // Add a null terminator to the string...
-  if (AddNull) {
-    ElementVals.push_back(ConstantInt::get(Type::Int8Ty, 0));
-  }
-
-  ArrayType *ATy = getArrayType(Type::Int8Ty, ElementVals.size());
-  return getConstantArray(ATy, ElementVals);
-}
-
-
 // ConstantExpr accessors.
 Constant* LLVMContext::getConstantExpr(unsigned Opcode, Constant* C1,
                                        Constant* C2) {
@@ -525,15 +489,6 @@
   pImpl->erase(Z);
 }
 
-void LLVMContext::erase(ConstantArray *C) {
-  pImpl->erase(C);
-}
-
 void LLVMContext::erase(ConstantVector *V) {
   pImpl->erase(V);
 }
-
-Constant *LLVMContext::replaceUsesOfWithOnConstant(ConstantArray *CA,
-                                               Value *From, Value *To, Use *U) {
-  return pImpl->replaceUsesOfWithOnConstant(CA, From, To, U);
-}

Modified: llvm/trunk/lib/VMCore/LLVMContextImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LLVMContextImpl.cpp?rev=77347&r1=77346&r2=77347&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContextImpl.cpp (original)
+++ llvm/trunk/lib/VMCore/LLVMContextImpl.cpp Tue Jul 28 13:32:17 2009
@@ -21,14 +21,6 @@
 
 static char getValType(ConstantAggregateZero *CPZ) { return 0; }
 
-static std::vector<Constant*> getValType(ConstantArray *CA) {
-  std::vector<Constant*> Elements;
-  Elements.reserve(CA->getNumOperands());
-  for (unsigned i = 0, e = CA->getNumOperands(); i != e; ++i)
-    Elements.push_back(cast<Constant>(CA->getOperand(i)));
-  return Elements;
-}
-
 static std::vector<Constant*> getValType(ConstantVector *CP) {
   std::vector<Constant*> Elements;
   Elements.reserve(CP->getNumOperands());
@@ -85,25 +77,6 @@
   return AggZeroConstants.getOrCreate(Ty, 0);
 }
 
-Constant *LLVMContextImpl::getConstantArray(const ArrayType *Ty,
-                             const std::vector<Constant*> &V) {
-  // If this is an all-zero array, return a ConstantAggregateZero object
-  if (!V.empty()) {
-    Constant *C = V[0];
-    if (!C->isNullValue()) {
-      // Implicitly locked.
-      return ArrayConstants.getOrCreate(Ty, V);
-    }
-    for (unsigned i = 1, e = V.size(); i != e; ++i)
-      if (V[i] != C) {
-        // Implicitly locked.
-        return ArrayConstants.getOrCreate(Ty, V);
-      }
-  }
-  
-  return Context.getConstantAggregateZero(Ty);
-}
-
 Constant *LLVMContextImpl::getConstantVector(const VectorType *Ty,
                               const std::vector<Constant*> &V) {
   assert(!V.empty() && "Vectors can't be empty");
@@ -146,90 +119,6 @@
   AggZeroConstants.remove(Z);
 }
 
-void LLVMContextImpl::erase(ConstantArray *C) {
-  ArrayConstants.remove(C);
-}
-
 void LLVMContextImpl::erase(ConstantVector *V) {
   VectorConstants.remove(V);
 }
-
-// *** RAUW helpers ***
-
-Constant *LLVMContextImpl::replaceUsesOfWithOnConstant(ConstantArray *CA,
-                                               Value *From, Value *To, Use *U) {
-  assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!");
-  Constant *ToC = cast<Constant>(To);
-
-  std::pair<ArrayConstantsTy::MapKey, Constant*> Lookup;
-  Lookup.first.first = CA->getType();
-  Lookup.second = CA;
-
-  std::vector<Constant*> &Values = Lookup.first.second;
-  Values.reserve(CA->getNumOperands());  // Build replacement array.
-
-  // Fill values with the modified operands of the constant array.  Also, 
-  // compute whether this turns into an all-zeros array.
-  bool isAllZeros = false;
-  unsigned NumUpdated = 0;
-  if (!ToC->isNullValue()) {
-    for (Use *O = CA->OperandList, *E = CA->OperandList + CA->getNumOperands();
-         O != E; ++O) {
-      Constant *Val = cast<Constant>(O->get());
-      if (Val == From) {
-        Val = ToC;
-        ++NumUpdated;
-      }
-      Values.push_back(Val);
-    }
-  } else {
-    isAllZeros = true;
-    for (Use *O = CA->OperandList, *E = CA->OperandList + CA->getNumOperands();
-         O != E; ++O) {
-      Constant *Val = cast<Constant>(O->get());
-      if (Val == From) {
-        Val = ToC;
-        ++NumUpdated;
-      }
-      Values.push_back(Val);
-      if (isAllZeros) isAllZeros = Val->isNullValue();
-    }
-  }
-  
-  Constant *Replacement = 0;
-  if (isAllZeros) {
-    Replacement = Context.getConstantAggregateZero(CA->getType());
-  } else {
-    // Check to see if we have this array type already.
-    sys::SmartScopedWriter<true> Writer(ConstantsLock);
-    bool Exists;
-    ArrayConstantsTy::MapTy::iterator I =
-      ArrayConstants.InsertOrGetItem(Lookup, Exists);
-    
-    if (Exists) {
-      Replacement = I->second;
-    } else {
-      // Okay, the new shape doesn't exist in the system yet.  Instead of
-      // creating a new constant array, inserting it, replaceallusesof'ing the
-      // old with the new, then deleting the old... just update the current one
-      // in place!
-      ArrayConstants.MoveConstantToNewSlot(CA, I);
-      
-      // Update to the new value.  Optimize for the case when we have a single
-      // operand that we're changing, but handle bulk updates efficiently.
-      if (NumUpdated == 1) {
-        unsigned OperandToUpdate = U - CA->OperandList;
-        assert(CA->getOperand(OperandToUpdate) == From &&
-               "ReplaceAllUsesWith broken!");
-        CA->setOperand(OperandToUpdate, ToC);
-      } else {
-        for (unsigned i = 0, e = CA->getNumOperands(); i != e; ++i)
-          if (CA->getOperand(i) == From)
-            CA->setOperand(i, ToC);
-      }
-      return 0;
-    }
-  }
-  
-  return Replacement;
-}
\ No newline at end of file

Modified: llvm/trunk/lib/VMCore/LLVMContextImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LLVMContextImpl.h?rev=77347&r1=77346&r2=77347&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContextImpl.h (original)
+++ llvm/trunk/lib/VMCore/LLVMContextImpl.h Tue Jul 28 13:32:17 2009
@@ -88,7 +88,7 @@
     std::vector<Constant*> C;
     for (unsigned i = 0, e = OldC->getNumOperands(); i != e; ++i)
       C.push_back(cast<Constant>(OldC->getOperand(i)));
-    Constant *New = NewTy->getContext().getConstantArray(NewTy, C);
+    Constant *New = ConstantArray::get(NewTy, C);
     assert(New != OldC && "Didn't replace constant??");
     OldC->uncheckedReplaceAllUsesWith(New);
     OldC->destroyConstant();    // This constant is now dead, destroy it.
@@ -459,6 +459,7 @@
   friend class ConstantInt;
   friend class ConstantFP;
   friend class ConstantStruct;
+  friend class ConstantArray;
 public:
   LLVMContextImpl(LLVMContext &C);
   
@@ -468,9 +469,6 @@
   
   ConstantAggregateZero *getConstantAggregateZero(const Type *Ty);
   
-  Constant *getConstantArray(const ArrayType *Ty,
-                             const std::vector<Constant*> &V);
-  
   Constant *getConstantVector(const VectorType *Ty,
                               const std::vector<Constant*> &V);
   
@@ -491,13 +489,7 @@
   void erase(MDString *M);
   void erase(MDNode *M);
   void erase(ConstantAggregateZero *Z);
-  void erase(ConstantArray *C);
   void erase(ConstantVector *V);
-  
-  // RAUW helpers
-  
-  Constant *replaceUsesOfWithOnConstant(ConstantArray *CA, Value *From,
-                                             Value *To, Use *U);
 };
 
 }

Modified: llvm/trunk/tools/bugpoint/ExtractFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/ExtractFunction.cpp?rev=77347&r1=77346&r2=77347&view=diff

==============================================================================
--- llvm/trunk/tools/bugpoint/ExtractFunction.cpp (original)
+++ llvm/trunk/tools/bugpoint/ExtractFunction.cpp Tue Jul 28 13:32:17 2009
@@ -189,7 +189,7 @@
     Elts.push_back(TorList[i].first);
     ArrayElts.push_back(ConstantStruct::get(Elts));
   }
-  return Context.getConstantArray(Context.getArrayType(ArrayElts[0]->getType(), 
+  return ConstantArray::get(Context.getArrayType(ArrayElts[0]->getType(), 
                                            ArrayElts.size()),
                             ArrayElts);
 }

Modified: llvm/trunk/tools/bugpoint/Miscompilation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/Miscompilation.cpp?rev=77347&r1=77346&r2=77347&view=diff

==============================================================================
--- llvm/trunk/tools/bugpoint/Miscompilation.cpp (original)
+++ llvm/trunk/tools/bugpoint/Miscompilation.cpp Tue Jul 28 13:32:17 2009
@@ -709,7 +709,7 @@
       // Don't forward functions which are external in the test module too.
       if (TestFn && !TestFn->isDeclaration()) {
         // 1. Add a string constant with its name to the global file
-        Constant *InitArray = Context.getConstantArray(F->getName());
+        Constant *InitArray = ConstantArray::get(F->getName());
         GlobalVariable *funcName =
           new GlobalVariable(*Safe, InitArray->getType(), true /*isConstant*/,
                              GlobalValue::InternalLinkage, InitArray,





More information about the llvm-commits mailing list