Move ConstantStruct back to 2.5 API.
authorOwen Anderson <resistor@mac.com>
Mon, 27 Jul 2009 22:29:26 +0000 (22:29 +0000)
committerOwen Anderson <resistor@mac.com>
Mon, 27 Jul 2009 22:29:26 +0000 (22:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77266 91177308-0d34-0410-b5e6-96231b3b80d8

16 files changed:
include/llvm/Constants.h
include/llvm/LLVMContext.h
lib/Analysis/DebugInfo.cpp
lib/AsmParser/LLParser.cpp
lib/Bitcode/Reader/BitcodeReader.cpp
lib/CodeGen/ShadowStackGC.cpp
lib/Linker/LinkModules.cpp
lib/Transforms/IPO/GlobalOpt.cpp
lib/Transforms/Utils/ValueMapper.cpp
lib/VMCore/ConstantFold.cpp
lib/VMCore/Constants.cpp
lib/VMCore/Core.cpp
lib/VMCore/LLVMContext.cpp
lib/VMCore/LLVMContextImpl.cpp
lib/VMCore/LLVMContextImpl.h
tools/bugpoint/ExtractFunction.cpp

index f7b785aff3f7009a8f8088238a8f1bc77bbb5119..af7187d95fe13927eaf34d57dddacadd6c042047 100644 (file)
@@ -385,10 +385,15 @@ class ConstantStruct : public Constant {
   friend struct ConstantCreator<ConstantStruct, StructType,
                                     std::vector<Constant*> >;
   ConstantStruct(const ConstantStruct &);      // DO NOT IMPLEMENT
-  friend class LLVMContextImpl;
 protected:
   ConstantStruct(const StructType *T, const std::vector<Constant*> &Val);
 public:
+  // ConstantStruct accessors
+  static Constant* get(const StructType* T, const std::vector<Constant*>& V);
+  static Constant* get(const std::vector<Constant*>& V, bool Packed = false);
+  static Constant* get(Constant* const *Vals, unsigned NumVals,
+                       bool Packed = false);
+  
   /// Transparently provide more efficient getOperand methods.
   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
 
index 37f0cd1a44c75477dd99d50c1a6d18bc0bd6e560..8465e4d95a3ae576b3e09cb0340a5c5c3eea12dd 100644 (file)
@@ -57,6 +57,7 @@ class LLVMContext {
   
   friend class ConstantInt;
   friend class ConstantFP;
+  friend class ConstantStruct;
 public:
   LLVMContext();
   ~LLVMContext();
@@ -78,14 +79,6 @@ public:
   
   // ConstantPointerNull accessors
   ConstantPointerNull* getConstantPointerNull(const PointerType* T);
-  
-  // ConstantStruct accessors
-  Constant* getConstantStruct(const StructType* T,
-                              const std::vector<Constant*>& V);
-  Constant* getConstantStruct(const std::vector<Constant*>& V,
-                              bool Packed = false);
-  Constant* getConstantStruct(Constant* const *Vals, unsigned NumVals,
-                              bool Packed = false);
                               
   // ConstantAggregateZero accessors
   ConstantAggregateZero* getConstantAggregateZero(const Type* Ty);
@@ -233,14 +226,11 @@ public:
   void erase(MDNode *M);
   void erase(ConstantAggregateZero *Z);
   void erase(ConstantArray *Z);
-  void erase(ConstantStruct *S);
   void erase(ConstantVector *V);
   
   // RAUW helpers
   Constant *replaceUsesOfWithOnConstant(ConstantArray *CA,
                                              Value *From, Value *To, Use *U);
-  Constant *replaceUsesOfWithOnConstant(ConstantStruct *CS, Value *From,
-                                        Value *To, Use *U);
 };
 
 /// FOR BACKWARDS COMPATIBILITY - Returns a global context.
index 61c9a4af3e1521d04530f2e5e2dc821dbea5d736..47a561bc29c00a253e784cc0e711420f9dce96ed 100644 (file)
@@ -545,8 +545,7 @@ DISubrange DIFactory::GetOrCreateSubrange(int64_t Lo, int64_t Hi) {
     ConstantInt::get(Type::Int64Ty, Hi)
   };
   
-  Constant *Init = VMContext.getConstantStruct(Elts, 
-                                             sizeof(Elts)/sizeof(Elts[0]));
+  Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
 
   // If we already have this range, just return the uniqued version.
   DIDescriptor &Entry = SimpleConstantCache[Init];
@@ -587,8 +586,7 @@ DICompileUnit DIFactory::CreateCompileUnit(unsigned LangID,
     ConstantInt::get(Type::Int32Ty, RunTimeVer)
   };
   
-  Constant *Init = VMContext.getConstantStruct(Elts,
-                                             sizeof(Elts)/sizeof(Elts[0]));
+  Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
   
   M.addTypeName("llvm.dbg.compile_unit.type", Init->getType());
   GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
@@ -606,8 +604,7 @@ DIEnumerator DIFactory::CreateEnumerator(const std::string &Name, uint64_t Val){
     ConstantInt::get(Type::Int64Ty, Val)
   };
   
-  Constant *Init = VMContext.getConstantStruct(Elts,
-                                             sizeof(Elts)/sizeof(Elts[0]));
+  Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
   
   M.addTypeName("llvm.dbg.enumerator.type", Init->getType());
   GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
@@ -640,8 +637,7 @@ DIBasicType DIFactory::CreateBasicType(DIDescriptor Context,
     ConstantInt::get(Type::Int32Ty, Encoding)
   };
   
-  Constant *Init = VMContext.getConstantStruct(Elts,
-                                             sizeof(Elts)/sizeof(Elts[0]));
+  Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
   
   M.addTypeName("llvm.dbg.basictype.type", Init->getType());
   GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
@@ -676,8 +672,7 @@ DIDerivedType DIFactory::CreateDerivedType(unsigned Tag,
     getCastToEmpty(DerivedFrom)
   };
   
-  Constant *Init = VMContext.getConstantStruct(Elts,
-                                             sizeof(Elts)/sizeof(Elts[0]));
+  Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
   
   M.addTypeName("llvm.dbg.derivedtype.type", Init->getType());
   GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
@@ -716,8 +711,7 @@ DICompositeType DIFactory::CreateCompositeType(unsigned Tag,
     ConstantInt::get(Type::Int32Ty, RuntimeLang)
   };
   
-  Constant *Init = VMContext.getConstantStruct(Elts,
-                                             sizeof(Elts)/sizeof(Elts[0]));
+  Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
   
   M.addTypeName("llvm.dbg.composite.type", Init->getType());
   GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
@@ -754,8 +748,7 @@ DISubprogram DIFactory::CreateSubprogram(DIDescriptor Context,
     ConstantInt::get(Type::Int1Ty, isDefinition)
   };
   
-  Constant *Init = VMContext.getConstantStruct(Elts,
-                                             sizeof(Elts)/sizeof(Elts[0]));
+  Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
   
   M.addTypeName("llvm.dbg.subprogram.type", Init->getType());
   GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
@@ -788,8 +781,7 @@ DIFactory::CreateGlobalVariable(DIDescriptor Context, const std::string &Name,
     VMContext.getConstantExprBitCast(Val, EmptyStructPtr)
   };
   
-  Constant *Init = VMContext.getConstantStruct(Elts,
-                                             sizeof(Elts)/sizeof(Elts[0]));
+  Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
   
   M.addTypeName("llvm.dbg.global_variable.type", Init->getType());
   GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
@@ -814,8 +806,7 @@ DIVariable DIFactory::CreateVariable(unsigned Tag, DIDescriptor Context,
     getCastToEmpty(Type)
   };
   
-  Constant *Init = VMContext.getConstantStruct(Elts,
-                                             sizeof(Elts)/sizeof(Elts[0]));
+  Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
   
   M.addTypeName("llvm.dbg.variable.type", Init->getType());
   GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
@@ -834,8 +825,7 @@ DIBlock DIFactory::CreateBlock(DIDescriptor Context) {
     getCastToEmpty(Context)
   };
   
-  Constant *Init = VMContext.getConstantStruct(Elts,
-                                             sizeof(Elts)/sizeof(Elts[0]));
+  Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
   
   M.addTypeName("llvm.dbg.block.type", Init->getType());
   GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
index adcd79f40a30bf723a1f7c882bb38ae8e295ff97..6a4e5c1950b924f6453815132ed3700abcfaf772 100644 (file)
@@ -1737,7 +1737,7 @@ bool LLParser::ParseValID(ValID &ID) {
         ParseToken(lltok::rbrace, "expected end of struct constant"))
       return true;
     
-    ID.ConstantVal = Context.getConstantStruct(Elts.data(), Elts.size(), false);
+    ID.ConstantVal = ConstantStruct::get(Elts.data(), Elts.size(), false);
     ID.Kind = ValID::t_Constant;
     return false;
   }
@@ -1757,7 +1757,7 @@ bool LLParser::ParseValID(ValID &ID) {
     
     if (isPackedStruct) {
       ID.ConstantVal =
-        Context.getConstantStruct(Elts.data(), Elts.size(), true);
+        ConstantStruct::get(Elts.data(), Elts.size(), true);
       ID.Kind = ValID::t_Constant;
       return false;
     }
index e1cc1a3afba99b33ec663165d315e9a61d66c865..2c4aab1dfddc1264a2d624be3b36bf78f8f7e9f5 100644 (file)
@@ -291,7 +291,7 @@ void BitcodeReaderValueList::ResolveConstantForwardRefs() {
         NewC = Context.getConstantArray(UserCA->getType(), &NewOps[0],
                                         NewOps.size());
       } else if (ConstantStruct *UserCS = dyn_cast<ConstantStruct>(UserC)) {
-        NewC = Context.getConstantStruct(&NewOps[0], NewOps.size(),
+        NewC = ConstantStruct::get(&NewOps[0], NewOps.size(),
                                          UserCS->getType()->isPacked());
       } else if (isa<ConstantVector>(UserC)) {
         NewC = Context.getConstantVector(&NewOps[0], NewOps.size());
@@ -925,7 +925,7 @@ bool BitcodeReader::ParseConstants() {
         for (unsigned i = 0; i != Size; ++i)
           Elts.push_back(ValueList.getConstantFwdRef(Record[i],
                                                      STy->getElementType(i)));
-        V = Context.getConstantStruct(STy, Elts);
+        V = ConstantStruct::get(STy, Elts);
       } else if (const ArrayType *ATy = dyn_cast<ArrayType>(CurTy)) {
         const Type *EltTy = ATy->getElementType();
         for (unsigned i = 0; i != Size; ++i)
index e3281d249260975eb9bd1445d53d71256b0421bb..9d141e9c823b95cb18dc889035d379781dc7a4a3 100644 (file)
@@ -208,12 +208,12 @@ Constant *ShadowStackGC::GetFrameMap(Function &F) {
   };
 
   Constant *DescriptorElts[] = {
-    Context.getConstantStruct(BaseElts, 2),
+    ConstantStruct::get(BaseElts, 2),
     Context.getConstantArray(Context.getArrayType(VoidPtr, NumMeta),
                        Metadata.begin(), NumMeta)
   };
 
-  Constant *FrameMap = Context.getConstantStruct(DescriptorElts, 2);
+  Constant *FrameMap = ConstantStruct::get(DescriptorElts, 2);
 
   std::string TypeName("gc_map.");
   TypeName += utostr(NumMeta);
index 15fe2224e6691a9132370d9b1302946f4c71aaba..a2009ec4665e6419cb052399c9d151ce14655fc5 100644 (file)
@@ -376,7 +376,7 @@ static Value *RemapOperand(const Value *In,
         Operands[i] =cast<Constant>(RemapOperand(CPS->getOperand(i), ValueMap,
                                                  Context));
       Result =
-         Context.getConstantStruct(cast<StructType>(CPS->getType()), Operands);
+         ConstantStruct::get(cast<StructType>(CPS->getType()), Operands);
     } else if (isa<ConstantPointerNull>(CPV) || isa<UndefValue>(CPV)) {
       Result = const_cast<Constant*>(CPV);
     } else if (const ConstantVector *CP = dyn_cast<ConstantVector>(CPV)) {
index c7208bc892aec2a4cc9bcc058ca58995e59f30d4..2989e2827fcd31e1a57eb0526e2cfc3a686fe2cb 100644 (file)
@@ -1962,7 +1962,7 @@ static GlobalVariable *InstallGlobalCtors(GlobalVariable *GCL,
       CSVals[1] = Context.getNullValue(PFTy);
       CSVals[0] = ConstantInt::get(Type::Int32Ty, 2147483647);
     }
-    CAList.push_back(Context.getConstantStruct(CSVals));
+    CAList.push_back(ConstantStruct::get(CSVals));
   }
   
   // Create the array initializer.
@@ -2070,7 +2070,7 @@ static Constant *EvaluateStoreInto(Constant *Init, Constant *Val,
     Elts[Idx] = EvaluateStoreInto(Elts[Idx], Val, Addr, OpNo+1, Context);
     
     // Return the modified struct.
-    return Context.getConstantStruct(&Elts[0], Elts.size(), STy->isPacked());
+    return ConstantStruct::get(&Elts[0], Elts.size(), STy->isPacked());
   } else {
     ConstantInt *CI = cast<ConstantInt>(Addr->getOperand(OpNo));
     const ArrayType *ATy = cast<ArrayType>(Init->getType());
index a8f0f86ddf5757ff2df8532142692d18afca8294..643805a2f919072917453dcffbcf094112d784ef 100644 (file)
@@ -76,7 +76,7 @@ Value *llvm::MapValue(const Value *V, ValueMapTy &VM, LLVMContext &Context) {
           Values.push_back(cast<Constant>(MV));
           for (++i; i != e; ++i)
             Values.push_back(cast<Constant>(MapValue(*i, VM, Context)));
-          return VM[V] = Context.getConstantStruct(CS->getType(), Values);
+          return VM[V] = ConstantStruct::get(CS->getType(), Values);
         }
       }
       return VM[V] = C;
index 6546dc70d80cda290e958d9a99be18e3aa913241..61616f245ad56aacf347488eb8003e2606c837be 100644 (file)
@@ -519,7 +519,7 @@ Constant *llvm::ConstantFoldInsertValueInstruction(LLVMContext &Context,
       Ops[i] = const_cast<Constant*>(Op);
     }
     if (isa<StructType>(AggTy))
-      return Context.getConstantStruct(Ops);
+      return ConstantStruct::get(Ops);
     else
       return Context.getConstantArray(cast<ArrayType>(AggTy), Ops);
   }
@@ -548,7 +548,7 @@ Constant *llvm::ConstantFoldInsertValueInstruction(LLVMContext &Context,
       Ops[i] = const_cast<Constant*>(Op);
     }
     if (isa<StructType>(AggTy))
-      return Context.getConstantStruct(Ops);
+      return ConstantStruct::get(Ops);
     else
       return Context.getConstantArray(cast<ArrayType>(AggTy), Ops);
   }
@@ -565,7 +565,7 @@ Constant *llvm::ConstantFoldInsertValueInstruction(LLVMContext &Context,
     }
     Constant *C;
     if (isa<StructType>(Agg->getType()))
-      C = Context.getConstantStruct(Ops);
+      C = ConstantStruct::get(Ops);
     else
       C = Context.getConstantArray(cast<ArrayType>(Agg->getType()), Ops);
     return C;
index b2abdf3edc108cc396adb7487d7c1f1144485c5b..ecb62568a2e7d0ae95069f130fd040d4b1064ef6 100644 (file)
@@ -397,6 +397,33 @@ ConstantStruct::ConstantStruct(const StructType *T,
   }
 }
 
+// ConstantStruct accessors.
+Constant* ConstantStruct::get(const StructType* T,
+                              const std::vector<Constant*>& V) {
+  LLVMContextImpl* pImpl = T->getContext().pImpl;
+  
+  // Create a ConstantAggregateZero value if all elements are zeros...
+  for (unsigned i = 0, e = V.size(); i != e; ++i)
+    if (!V[i]->isNullValue())
+      // Implicitly locked.
+      return pImpl->StructConstants.getOrCreate(T, V);
+
+  return T->getContext().getConstantAggregateZero(T);
+}
+
+Constant* ConstantStruct::get(const std::vector<Constant*>& V, bool packed) {
+  std::vector<const Type*> StructEls;
+  StructEls.reserve(V.size());
+  for (unsigned i = 0, e = V.size(); i != e; ++i)
+    StructEls.push_back(V[i]->getType());
+  return get(StructType::get(StructEls, packed), V);
+}
+
+Constant* ConstantStruct::get(Constant* const *Vals, unsigned NumVals,
+                              bool Packed) {
+  // FIXME: make this the primary ctor method.
+  return get(std::vector<Constant*>(Vals, Vals+NumVals), Packed);
+}
 
 ConstantVector::ConstantVector(const VectorType *T,
                                const std::vector<Constant*> &V)
@@ -981,7 +1008,7 @@ namespace llvm {
 //
 void ConstantStruct::destroyConstant() {
   // Implicitly locked.
-  getType()->getContext().erase(this);
+  getType()->getContext().pImpl->StructConstants.remove(this);
   destroyConstantImpl();
 }
 
@@ -1897,11 +1924,74 @@ void ConstantArray::replaceUsesOfWithOnConstant(Value *From, Value *To,
   destroyConstant();
 }
 
+static std::vector<Constant*> getValType(ConstantStruct *CS) {
+  std::vector<Constant*> Elements;
+  Elements.reserve(CS->getNumOperands());
+  for (unsigned i = 0, e = CS->getNumOperands(); i != e; ++i)
+    Elements.push_back(cast<Constant>(CS->getOperand(i)));
+  return Elements;
+}
+
 void ConstantStruct::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);
+
+  unsigned OperandToUpdate = U-OperandList;
+  assert(getOperand(OperandToUpdate) == From && "ReplaceAllUsesWith broken!");
+
+  std::pair<LLVMContextImpl::StructConstantsTy::MapKey, Constant*> Lookup;
+  Lookup.first.first = getType();
+  Lookup.second = this;
+  std::vector<Constant*> &Values = Lookup.first.second;
+  Values.reserve(getNumOperands());  // Build replacement struct.
+  
+  
+  // Fill values with the modified operands of the constant struct.  Also, 
+  // compute whether this turns into an all-zeros struct.
+  bool isAllZeros = false;
+  if (!ToC->isNullValue()) {
+    for (Use *O = OperandList, *E = OperandList + getNumOperands(); O != E; ++O)
+      Values.push_back(cast<Constant>(O->get()));
+  } else {
+    isAllZeros = true;
+    for (Use *O = OperandList, *E = OperandList+getNumOperands(); O != E; ++O) {
+      Constant *Val = cast<Constant>(O->get());
+      Values.push_back(Val);
+      if (isAllZeros) isAllZeros = Val->isNullValue();
+    }
+  }
+  Values[OperandToUpdate] = ToC;
+  
+  LLVMContext &Context = getType()->getContext();
+  LLVMContextImpl *pImpl = Context.pImpl;
+  
+  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::StructConstantsTy::MapTy::iterator I =
+      pImpl->StructConstants.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 struct, inserting it, replaceallusesof'ing the
+      // old with the new, then deleting the old... just update the current one
+      // in place!
+      pImpl->StructConstants.MoveConstantToNewSlot(this, I);
+      
+      // Update to the new value.
+      setOperand(OperandToUpdate, ToC);
+      return;
+    }
+  }
+  
+  assert(Replacement != this && "I didn't contain From!");
   
   // Everyone using this now uses the replacement.
   uncheckedReplaceAllUsesWith(Replacement);
index 90f08c8e48222716771c7d157c91eefe9831182a..12f7c3223bcf457554c637eb82243081f8239653 100644 (file)
@@ -416,8 +416,7 @@ LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
 
 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
                              int Packed) {
-  return wrap(getGlobalContext().getConstantStruct(
-                                  unwrap<Constant>(ConstantVals, Count),
+  return wrap(ConstantStruct::get(unwrap<Constant>(ConstantVals, Count),
                                   Count, Packed != 0));
 }
 
index 722e29ee5dca0fce83805451207e4206ab531ad2..340ca9557a27e118e6119a28c038e225fbefed94 100644 (file)
@@ -98,29 +98,6 @@ ConstantPointerNull* LLVMContext::getConstantPointerNull(const PointerType* T) {
   return ConstantPointerNull::get(T);
 }
 
-
-// ConstantStruct accessors.
-Constant* LLVMContext::getConstantStruct(const StructType* T,
-                                         const std::vector<Constant*>& V) {
-  return pImpl->getConstantStruct(T, V);
-}
-
-Constant* LLVMContext::getConstantStruct(const std::vector<Constant*>& V,
-                                         bool packed) {
-  std::vector<const Type*> StructEls;
-  StructEls.reserve(V.size());
-  for (unsigned i = 0, e = V.size(); i != e; ++i)
-    StructEls.push_back(V[i]->getType());
-  return getConstantStruct(getStructType(StructEls, packed), V);
-}
-
-Constant* LLVMContext::getConstantStruct(Constant* const *Vals,
-                                         unsigned NumVals, bool Packed) {
-  // FIXME: make this the primary ctor method.
-  return getConstantStruct(std::vector<Constant*>(Vals, Vals+NumVals), Packed);
-}
-
-
 // ConstantAggregateZero accessors.
 ConstantAggregateZero* LLVMContext::getConstantAggregateZero(const Type* Ty) {
   return pImpl->getConstantAggregateZero(Ty);
@@ -552,10 +529,6 @@ void LLVMContext::erase(ConstantArray *C) {
   pImpl->erase(C);
 }
 
-void LLVMContext::erase(ConstantStruct *S) {
-  pImpl->erase(S);
-}
-
 void LLVMContext::erase(ConstantVector *V) {
   pImpl->erase(V);
 }
@@ -564,8 +537,3 @@ Constant *LLVMContext::replaceUsesOfWithOnConstant(ConstantArray *CA,
                                                Value *From, Value *To, Use *U) {
   return pImpl->replaceUsesOfWithOnConstant(CA, From, To, U);
 }
-
-Constant *LLVMContext::replaceUsesOfWithOnConstant(ConstantStruct *CS,
-                                               Value *From, Value *To, Use *U) {
-  return pImpl->replaceUsesOfWithOnConstant(CS, From, To, U);
-}
index 5315e23f8e352282189aa01388842c9a312c3348..858ed15d9b1515a461474f7be011ab2e05b3a373 100644 (file)
@@ -29,14 +29,6 @@ static std::vector<Constant*> getValType(ConstantArray *CA) {
   return Elements;
 }
 
-static std::vector<Constant*> getValType(ConstantStruct *CS) {
-  std::vector<Constant*> Elements;
-  Elements.reserve(CS->getNumOperands());
-  for (unsigned i = 0, e = CS->getNumOperands(); i != e; ++i)
-    Elements.push_back(cast<Constant>(CS->getOperand(i)));
-  return Elements;
-}
-
 static std::vector<Constant*> getValType(ConstantVector *CP) {
   std::vector<Constant*> Elements;
   Elements.reserve(CP->getNumOperands());
@@ -112,17 +104,6 @@ Constant *LLVMContextImpl::getConstantArray(const ArrayType *Ty,
   return Context.getConstantAggregateZero(Ty);
 }
 
-Constant *LLVMContextImpl::getConstantStruct(const StructType *Ty,
-                              const std::vector<Constant*> &V) {
-  // Create a ConstantAggregateZero value if all elements are zeros...
-  for (unsigned i = 0, e = V.size(); i != e; ++i)
-    if (!V[i]->isNullValue())
-      // Implicitly locked.
-      return StructConstants.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");
@@ -169,10 +150,6 @@ void LLVMContextImpl::erase(ConstantArray *C) {
   ArrayConstants.remove(C);
 }
 
-void LLVMContextImpl::erase(ConstantStruct *S) {
-  StructConstants.remove(S);
-}
-
 void LLVMContextImpl::erase(ConstantVector *V) {
   VectorConstants.remove(V);
 }
@@ -255,68 +232,4 @@ Constant *LLVMContextImpl::replaceUsesOfWithOnConstant(ConstantArray *CA,
   }
   
   return Replacement;
-}
-
-Constant *LLVMContextImpl::replaceUsesOfWithOnConstant(ConstantStruct *CS,
-                                               Value *From, Value *To, Use *U) {
-  assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!");
-  Constant *ToC = cast<Constant>(To);
-
-  unsigned OperandToUpdate = U - CS->OperandList;
-  assert(CS->getOperand(OperandToUpdate) == From &&
-         "ReplaceAllUsesWith broken!");
-
-  std::pair<StructConstantsTy::MapKey, Constant*> Lookup;
-  Lookup.first.first = CS->getType();
-  Lookup.second = CS;
-  std::vector<Constant*> &Values = Lookup.first.second;
-  Values.reserve(CS->getNumOperands());  // Build replacement struct.
-  
-  
-  // Fill values with the modified operands of the constant struct.  Also, 
-  // compute whether this turns into an all-zeros struct.
-  bool isAllZeros = false;
-  if (!ToC->isNullValue()) {
-    for (Use *O = CS->OperandList, *E = CS->OperandList + CS->getNumOperands(); 
-         O != E; ++O)
-      Values.push_back(cast<Constant>(O->get()));
-  } else {
-    isAllZeros = true;
-    for (Use *O = CS->OperandList, *E = CS->OperandList + CS->getNumOperands(); 
-         O != E; ++O) {
-      Constant *Val = cast<Constant>(O->get());
-      Values.push_back(Val);
-      if (isAllZeros) isAllZeros = Val->isNullValue();
-    }
-  }
-  Values[OperandToUpdate] = ToC;
-  
-  Constant *Replacement = 0;
-  if (isAllZeros) {
-    Replacement = Context.getConstantAggregateZero(CS->getType());
-  } else {
-    // Check to see if we have this array type already.
-    sys::SmartScopedWriter<true> Writer(ConstantsLock);
-    bool Exists;
-    StructConstantsTy::MapTy::iterator I =
-      StructConstants.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 struct, inserting it, replaceallusesof'ing the
-      // old with the new, then deleting the old... just update the current one
-      // in place!
-      StructConstants.MoveConstantToNewSlot(CS, I);
-      
-      // Update to the new value.
-      CS->setOperand(OperandToUpdate, ToC);
-      return 0;
-    }
-  }
-  
-  assert(Replacement != CS && "I didn't contain From!");
-  
-  return Replacement;
-}
+}
\ No newline at end of file
index a5ff8d5c54edeee80da84f04acf94defc74f9ce0..21fef39683d518df8cd3effc29e76d410f52a661 100644 (file)
@@ -102,7 +102,7 @@ struct ConvertConstantType<ConstantStruct, StructType> {
     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().getConstantStruct(NewTy, C);
+    Constant *New = ConstantStruct::get(NewTy, C);
     assert(New != OldC && "Didn't replace constant??");
 
     OldC->uncheckedReplaceAllUsesWith(New);
@@ -458,6 +458,7 @@ class LLVMContextImpl {
   
   friend class ConstantInt;
   friend class ConstantFP;
+  friend class ConstantStruct;
 public:
   LLVMContextImpl(LLVMContext &C);
   
@@ -470,9 +471,6 @@ public:
   Constant *getConstantArray(const ArrayType *Ty,
                              const std::vector<Constant*> &V);
   
-  Constant *getConstantStruct(const StructType *Ty, 
-                              const std::vector<Constant*> &V);
-  
   Constant *getConstantVector(const VectorType *Ty,
                               const std::vector<Constant*> &V);
   
@@ -494,15 +492,12 @@ public:
   void erase(MDNode *M);
   void erase(ConstantAggregateZero *Z);
   void erase(ConstantArray *C);
-  void erase(ConstantStruct *S);
   void erase(ConstantVector *V);
   
   // RAUW helpers
   
   Constant *replaceUsesOfWithOnConstant(ConstantArray *CA, Value *From,
                                              Value *To, Use *U);
-  Constant *replaceUsesOfWithOnConstant(ConstantStruct *CS, Value *From,
-                                        Value *To, Use *U);
 };
 
 }
index 41704f9dcab9f11a43cd76273168237921c8a3be..145942c886766fc546dcd7ff3eb225c02d7ab4d2 100644 (file)
@@ -187,7 +187,7 @@ static Constant *GetTorInit(std::vector<std::pair<Function*, int> > &TorList) {
     std::vector<Constant*> Elts;
     Elts.push_back(ConstantInt::get(Type::Int32Ty, TorList[i].second));
     Elts.push_back(TorList[i].first);
-    ArrayElts.push_back(Context.getConstantStruct(Elts));
+    ArrayElts.push_back(ConstantStruct::get(Elts));
   }
   return Context.getConstantArray(Context.getArrayType(ArrayElts[0]->getType(), 
                                            ArrayElts.size()),