Privatize the StructType table, which unfortunately involves routing contexts through...
authorOwen Anderson <resistor@mac.com>
Wed, 5 Aug 2009 23:16:16 +0000 (23:16 +0000)
committerOwen Anderson <resistor@mac.com>
Wed, 5 Aug 2009 23:16:16 +0000 (23:16 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78258 91177308-0d34-0410-b5e6-96231b3b80d8

18 files changed:
include/llvm/Constants.h
include/llvm/DerivedTypes.h
lib/Analysis/DebugInfo.cpp
lib/AsmParser/LLParser.cpp
lib/Bitcode/Reader/BitcodeReader.cpp
lib/CodeGen/ShadowStackGC.cpp
lib/Debugger/ProgramInfo.cpp
lib/Transforms/IPO/DeadArgumentElimination.cpp
lib/Transforms/IPO/GlobalOpt.cpp
lib/Transforms/Utils/CodeExtractor.cpp
lib/Transforms/Utils/LowerInvoke.cpp
lib/VMCore/ConstantFold.cpp
lib/VMCore/Constants.cpp
lib/VMCore/Core.cpp
lib/VMCore/LLVMContextImpl.h
lib/VMCore/Type.cpp
tools/bugpoint/ExtractFunction.cpp
utils/TableGen/IntrinsicEmitter.cpp

index 0785492335f4aa047add74263f9746c0ffe0e466..32eac7b4410970174d19cf6cfaf153e75d1c83a8 100644 (file)
@@ -407,8 +407,10 @@ protected:
 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,
+  static Constant* get(LLVMContext &Context, 
+                       const std::vector<Constant*>& V, bool Packed = false);
+  static Constant* get(LLVMContext &Context,
+                       Constant* const *Vals, unsigned NumVals,
                        bool Packed = false);
   
   /// Transparently provide more efficient getOperand methods.
index e2737bd3c7c60cd573c552ba8a6dff732b0cf7ce..b50ee5549f631cfd81836aa9e6b2c31ce51d4269 100644 (file)
@@ -31,6 +31,7 @@ class PointerValType;
 class VectorValType;
 class IntegerValType;
 class APInt;
+struct LLVMContext;
 
 class DerivedType : public Type {
   friend class Type;
@@ -240,20 +241,22 @@ public:
   /// StructType::get - This static method is the primary way to create a
   /// StructType.
   ///
-  static StructType *get(const std::vector<const Type*> &Params,
+  static StructType *get(LLVMContext &Context, 
+                         const std::vector<const Type*> &Params,
                          bool isPacked=false);
 
   /// StructType::get - Create an empty structure type.
   ///
-  static StructType *get(bool isPacked=false) {
-    return get(std::vector<const Type*>(), isPacked);
+  static StructType *get(LLVMContext &Context, bool isPacked=false) {
+    return get(Context, std::vector<const Type*>(), isPacked);
   }
 
   /// StructType::get - This static method is a convenience method for
   /// creating structure types by specifying the elements as arguments.
   /// Note that this method always returns a non-packed struct.  To get
   /// an empty struct, pass NULL, NULL.
-  static StructType *get(const Type *type, ...) END_WITH_NULL;
+  static StructType *get(LLVMContext &Context, 
+                         const Type *type, ...) END_WITH_NULL;
 
   /// isValidElementType - Return true if the specified type is valid as a
   /// element type.
index 1e2913477def4ae49e4c31154d544390344bf811..64fdfb8f85107aae3e79c5330190a120cc8ad222 100644 (file)
@@ -470,7 +470,7 @@ DIFactory::DIFactory(Module &m)
   : M(m), VMContext(M.getContext()), StopPointFn(0), FuncStartFn(0), 
     RegionStartFn(0), RegionEndFn(0),
     DeclareFn(0) {
-  EmptyStructPtr = PointerType::getUnqual(StructType::get());
+  EmptyStructPtr = PointerType::getUnqual(StructType::get(VMContext));
 }
 
 /// getCastToEmpty - Return this descriptor as a Constant* with type '{}*'.
@@ -546,7 +546,8 @@ DISubrange DIFactory::GetOrCreateSubrange(int64_t Lo, int64_t Hi) {
     ConstantInt::get(Type::Int64Ty, Hi)
   };
   
-  Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
+  Constant *Init = ConstantStruct::get(VMContext, Elts,
+                                       sizeof(Elts)/sizeof(Elts[0]));
 
   // If we already have this range, just return the uniqued version.
   DIDescriptor &Entry = SimpleConstantCache[Init];
@@ -587,7 +588,8 @@ DICompileUnit DIFactory::CreateCompileUnit(unsigned LangID,
     ConstantInt::get(Type::Int32Ty, RunTimeVer)
   };
   
-  Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
+  Constant *Init = ConstantStruct::get(VMContext, Elts,
+                                       sizeof(Elts)/sizeof(Elts[0]));
   
   M.addTypeName("llvm.dbg.compile_unit.type", Init->getType());
   GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
@@ -605,7 +607,8 @@ DIEnumerator DIFactory::CreateEnumerator(const std::string &Name, uint64_t Val){
     ConstantInt::get(Type::Int64Ty, Val)
   };
   
-  Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
+  Constant *Init = ConstantStruct::get(VMContext, Elts,
+                                       sizeof(Elts)/sizeof(Elts[0]));
   
   M.addTypeName("llvm.dbg.enumerator.type", Init->getType());
   GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
@@ -638,7 +641,8 @@ DIBasicType DIFactory::CreateBasicType(DIDescriptor Context,
     ConstantInt::get(Type::Int32Ty, Encoding)
   };
   
-  Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
+  Constant *Init = ConstantStruct::get(VMContext, Elts,
+                                       sizeof(Elts)/sizeof(Elts[0]));
   
   M.addTypeName("llvm.dbg.basictype.type", Init->getType());
   GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
@@ -673,7 +677,8 @@ DIDerivedType DIFactory::CreateDerivedType(unsigned Tag,
     getCastToEmpty(DerivedFrom)
   };
   
-  Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
+  Constant *Init = ConstantStruct::get(VMContext, Elts,
+                                       sizeof(Elts)/sizeof(Elts[0]));
   
   M.addTypeName("llvm.dbg.derivedtype.type", Init->getType());
   GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
@@ -712,7 +717,8 @@ DICompositeType DIFactory::CreateCompositeType(unsigned Tag,
     ConstantInt::get(Type::Int32Ty, RuntimeLang)
   };
   
-  Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
+  Constant *Init = ConstantStruct::get(VMContext, Elts,
+                                       sizeof(Elts)/sizeof(Elts[0]));
   
   M.addTypeName("llvm.dbg.composite.type", Init->getType());
   GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
@@ -749,7 +755,8 @@ DISubprogram DIFactory::CreateSubprogram(DIDescriptor Context,
     ConstantInt::get(Type::Int1Ty, isDefinition)
   };
   
-  Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
+  Constant *Init = ConstantStruct::get(VMContext, Elts,
+                                       sizeof(Elts)/sizeof(Elts[0]));
   
   M.addTypeName("llvm.dbg.subprogram.type", Init->getType());
   GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
@@ -782,7 +789,8 @@ DIFactory::CreateGlobalVariable(DIDescriptor Context, const std::string &Name,
     ConstantExpr::getBitCast(Val, EmptyStructPtr)
   };
   
-  Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
+  Constant *Init = ConstantStruct::get(VMContext, Elts,
+                                       sizeof(Elts)/sizeof(Elts[0]));
   
   M.addTypeName("llvm.dbg.global_variable.type", Init->getType());
   GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
@@ -807,7 +815,8 @@ DIVariable DIFactory::CreateVariable(unsigned Tag, DIDescriptor Context,
     getCastToEmpty(Type)
   };
   
-  Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
+  Constant *Init = ConstantStruct::get(VMContext, Elts,
+                                       sizeof(Elts)/sizeof(Elts[0]));
   
   M.addTypeName("llvm.dbg.variable.type", Init->getType());
   GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
@@ -826,7 +835,8 @@ DIBlock DIFactory::CreateBlock(DIDescriptor Context) {
     getCastToEmpty(Context)
   };
   
-  Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
+  Constant *Init = ConstantStruct::get(VMContext, Elts,
+                                       sizeof(Elts)/sizeof(Elts[0]));
   
   M.addTypeName("llvm.dbg.block.type", Init->getType());
   GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
index 0ba93b131a3828a2cab654e41cad2c10b0988fec..b5699ff361a67e7a7924ec999636e77f31581e37 100644 (file)
@@ -1381,7 +1381,7 @@ bool LLParser::ParseStructType(PATypeHolder &Result, bool Packed) {
   Lex.Lex(); // Consume the '{'
   
   if (EatIfPresent(lltok::rbrace)) {
-    Result = StructType::get(Packed);
+    Result = StructType::get(Context, Packed);
     return false;
   }
 
@@ -1413,7 +1413,7 @@ bool LLParser::ParseStructType(PATypeHolder &Result, bool Packed) {
   std::vector<const Type*> ParamsListTy;
   for (unsigned i = 0, e = ParamsList.size(); i != e; ++i)
     ParamsListTy.push_back(ParamsList[i].get());
-  Result = HandleUpRefs(StructType::get(ParamsListTy, Packed));
+  Result = HandleUpRefs(StructType::get(Context, ParamsListTy, Packed));
   return false;
 }
 
@@ -1772,7 +1772,8 @@ bool LLParser::ParseValID(ValID &ID) {
         ParseToken(lltok::rbrace, "expected end of struct constant"))
       return true;
     
-    ID.ConstantVal = ConstantStruct::get(Elts.data(), Elts.size(), false);
+    ID.ConstantVal = ConstantStruct::get(Context, Elts.data(),
+                                         Elts.size(), false);
     ID.Kind = ValID::t_Constant;
     return false;
   }
@@ -1792,7 +1793,7 @@ bool LLParser::ParseValID(ValID &ID) {
     
     if (isPackedStruct) {
       ID.ConstantVal =
-        ConstantStruct::get(Elts.data(), Elts.size(), true);
+        ConstantStruct::get(Context, Elts.data(), Elts.size(), true);
       ID.Kind = ValID::t_Constant;
       return false;
     }
index 4ad97b12d626fe2dfb0cedb690695a9e46b49f37..5f184ec58d1b3b199b28d24237827a4b7401f07b 100644 (file)
@@ -292,7 +292,7 @@ void BitcodeReaderValueList::ResolveConstantForwardRefs() {
         NewC = ConstantArray::get(UserCA->getType(), &NewOps[0],
                                         NewOps.size());
       } else if (ConstantStruct *UserCS = dyn_cast<ConstantStruct>(UserC)) {
-        NewC = ConstantStruct::get(&NewOps[0], NewOps.size(),
+        NewC = ConstantStruct::get(Context, &NewOps[0], NewOps.size(),
                                          UserCS->getType()->isPacked());
       } else if (isa<ConstantVector>(UserC)) {
         NewC = ConstantVector::get(&NewOps[0], NewOps.size());
@@ -580,7 +580,7 @@ bool BitcodeReader::ParseTypeTable() {
       std::vector<const Type*> EltTys;
       for (unsigned i = 1, e = Record.size(); i != e; ++i)
         EltTys.push_back(getTypeByID(Record[i], true));
-      ResultTy = StructType::get(EltTys, Record[0]);
+      ResultTy = StructType::get(Context, EltTys, Record[0]);
       break;
     }
     case bitc::TYPE_CODE_ARRAY:     // ARRAY: [numelts, eltty]
index 3aa86d04f83941986b609b2dd361355af57a8199..514629bff73c35e14d8f4608ffce5f11fea5b640 100644 (file)
@@ -206,12 +206,12 @@ Constant *ShadowStackGC::GetFrameMap(Function &F) {
   };
 
   Constant *DescriptorElts[] = {
-    ConstantStruct::get(BaseElts, 2),
+    ConstantStruct::get(F.getContext(), BaseElts, 2),
     ConstantArray::get(ArrayType::get(VoidPtr, NumMeta),
                        Metadata.begin(), NumMeta)
   };
 
-  Constant *FrameMap = ConstantStruct::get(DescriptorElts, 2);
+  Constant *FrameMap = ConstantStruct::get(F.getContext(), DescriptorElts, 2);
 
   std::string TypeName("gc_map.");
   TypeName += utostr(NumMeta);
@@ -245,7 +245,7 @@ const Type* ShadowStackGC::GetConcreteStackEntryType(Function &F) {
   EltTys.push_back(StackEntryTy);
   for (size_t I = 0; I != Roots.size(); I++)
     EltTys.push_back(Roots[I].second->getAllocatedType());
-  Type *Ty = StructType::get(EltTys);
+  Type *Ty = StructType::get(F.getContext(), EltTys);
 
   std::string TypeName("gc_stackentry.");
   TypeName += F.getName();
@@ -265,7 +265,7 @@ bool ShadowStackGC::initializeCustomLowering(Module &M) {
   std::vector<const Type*> EltTys;
   EltTys.push_back(Type::Int32Ty); // 32 bits is ok up to a 32GB stack frame. :)
   EltTys.push_back(Type::Int32Ty); // Specifies length of variable length array.
-  StructType *FrameMapTy = StructType::get(EltTys);
+  StructType *FrameMapTy = StructType::get(M.getContext(), EltTys);
   M.addTypeName("gc_map", FrameMapTy);
   PointerType *FrameMapPtrTy = PointerType::getUnqual(FrameMapTy);
 
@@ -279,7 +279,7 @@ bool ShadowStackGC::initializeCustomLowering(Module &M) {
   EltTys.clear();
   EltTys.push_back(PointerType::getUnqual(RecursiveTy));
   EltTys.push_back(FrameMapPtrTy);
-  PATypeHolder LinkTyH = StructType::get(EltTys);
+  PATypeHolder LinkTyH = StructType::get(M.getContext(), EltTys);
 
   RecursiveTy->refineAbstractTypeTo(LinkTyH.get());
   StackEntryTy = cast<StructType>(LinkTyH.get());
index e58b3d58e6d1ccc43723817319e6c3bd9f7bef29..6e584bdcc31195e5eee10609b7c1bf4c749aceb8 100644 (file)
@@ -271,7 +271,8 @@ ProgramInfo::getSourceFiles(bool RequiresCompleteMap) {
   // should be on the use list of the llvm.dbg.translation_units global.
   //
   GlobalVariable *Units =
-    M->getGlobalVariable("llvm.dbg.translation_units", StructType::get());
+    M->getGlobalVariable("llvm.dbg.translation_units", 
+                         StructType::get(M->getContext()));
   if (Units == 0)
     throw "Program contains no debugging information!";
 
@@ -353,7 +354,7 @@ ProgramInfo::getSourceFunctions(bool RequiresCompleteMap) {
   // should be on the use list of the llvm.dbg.translation_units global.
   //
   GlobalVariable *Units =
-    M->getGlobalVariable("llvm.dbg.globals", StructType::get());
+    M->getGlobalVariable("llvm.dbg.globals", StructType::get(M->getContext()));
   if (Units == 0)
     throw "Program contains no debugging information!";
 
index 47f5e65ccdbbfc26772da784494dee90234050d6..061211961818317f5590af2fa7e4c0552b8d8972 100644 (file)
@@ -638,7 +638,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
       // something and {} into void.
       // Make the new struct packed if we used to return a packed struct
       // already.
-      NRetTy = StructType::get(RetTypes, STy->isPacked());
+      NRetTy = StructType::get(STy->getContext(), RetTypes, STy->isPacked());
     else if (RetTypes.size() == 1)
       // One return type? Just a simple value then, but only if we didn't use to
       // return a struct with that simple value before.
index 35e3fe91f577036b6bc55ecc2169151ed22ca8a0..0048b097a8b1350d3e4b8dbd7cce9ca5f9c59084 100644 (file)
@@ -1961,7 +1961,7 @@ static GlobalVariable *InstallGlobalCtors(GlobalVariable *GCL,
       CSVals[1] = Constant::getNullValue(PFTy);
       CSVals[0] = ConstantInt::get(Type::Int32Ty, 2147483647);
     }
-    CAList.push_back(ConstantStruct::get(CSVals));
+    CAList.push_back(ConstantStruct::get(Context, CSVals));
   }
   
   // Create the array initializer.
@@ -2069,7 +2069,7 @@ static Constant *EvaluateStoreInto(Constant *Init, Constant *Val,
     Elts[Idx] = EvaluateStoreInto(Elts[Idx], Val, Addr, OpNo+1, Context);
     
     // Return the modified struct.
-    return ConstantStruct::get(&Elts[0], Elts.size(), STy->isPacked());
+    return ConstantStruct::get(Context, &Elts[0], Elts.size(), STy->isPacked());
   } else {
     ConstantInt *CI = cast<ConstantInt>(Addr->getOperand(OpNo));
     const ArrayType *ATy = cast<ArrayType>(Init->getType());
index 80da263df557c2461fa28c4d38140855f1019a20..d4f0c8095a11f7f1f15ef2cb2b6ee868ab567ee4 100644 (file)
@@ -275,7 +275,7 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
 
   if (AggregateArgs && (inputs.size() + outputs.size() > 0)) {
     PointerType *StructPtr =
-           PointerType::getUnqual(StructType::get(paramTy));
+           PointerType::getUnqual(StructType::get(M->getContext(), paramTy));
     paramTy.clear();
     paramTy.push_back(StructPtr);
   }
@@ -382,7 +382,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
       ArgTypes.push_back((*v)->getType());
 
     // Allocate a struct at the beginning of this function
-    Type *StructArgTy = StructType::get(ArgTypes);
+    Type *StructArgTy = StructType::get(newFunction->getContext(), ArgTypes);
     Struct =
       new AllocaInst(StructArgTy, 0, "structArg",
                      codeReplacer->getParent()->begin()->begin());
index 4eac467e076c5af8422454a179b54d48c560a76d..d16ceb42809ec8b7baa2d68688ee5cc0096174c6 100644 (file)
@@ -128,7 +128,7 @@ bool LowerInvoke::doInitialization(Module &M) {
       Elements.push_back(JmpBufTy);
       OpaqueType *OT = OpaqueType::get();
       Elements.push_back(PointerType::getUnqual(OT));
-      PATypeHolder JBLType(StructType::get(Elements));
+      PATypeHolder JBLType(StructType::get(M.getContext(), Elements));
       OT->refineAbstractTypeTo(JBLType.get());  // Complete the cycle.
       JBLinkTy = JBLType.get();
       M.addTypeName("llvm.sjljeh.jmpbufty", JBLinkTy);
index 081c7801400dac2e22d41658e4d880b010ef62d9..da9b6aa9784731844450de21ddda4c44f5245fd0 100644 (file)
@@ -519,7 +519,7 @@ Constant *llvm::ConstantFoldInsertValueInstruction(LLVMContext &Context,
       Ops[i] = const_cast<Constant*>(Op);
     }
     if (isa<StructType>(AggTy))
-      return ConstantStruct::get(Ops);
+      return ConstantStruct::get(Context, Ops);
     else
       return ConstantArray::get(cast<ArrayType>(AggTy), Ops);
   }
@@ -548,7 +548,7 @@ Constant *llvm::ConstantFoldInsertValueInstruction(LLVMContext &Context,
       Ops[i] = const_cast<Constant*>(Op);
     }
     if (isa<StructType>(AggTy))
-      return ConstantStruct::get(Ops);
+      return ConstantStruct::get(Context, Ops);
     else
       return ConstantArray::get(cast<ArrayType>(AggTy), Ops);
   }
@@ -565,7 +565,7 @@ Constant *llvm::ConstantFoldInsertValueInstruction(LLVMContext &Context,
     }
     Constant *C;
     if (isa<StructType>(Agg->getType()))
-      C = ConstantStruct::get(Ops);
+      C = ConstantStruct::get(Context, Ops);
     else
       C = ConstantArray::get(cast<ArrayType>(Agg->getType()), Ops);
     return C;
index d5f3eb972a74a32aa7a3a26b9a62714ed013ffae..161afe47e2ab5b6b57b422bed9a6fcc9a6f852ce 100644 (file)
@@ -532,18 +532,20 @@ Constant* ConstantStruct::get(const StructType* T,
   return ConstantAggregateZero::get(T);
 }
 
-Constant* ConstantStruct::get(const std::vector<Constant*>& V, bool packed) {
+Constant* ConstantStruct::get(LLVMContext &Context,
+                              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);
+  return get(StructType::get(Context, StructEls, packed), V);
 }
 
-Constant* ConstantStruct::get(Constant* const *Vals, unsigned NumVals,
+Constant* ConstantStruct::get(LLVMContext &Context,
+                              Constant* const *Vals, unsigned NumVals,
                               bool Packed) {
   // FIXME: make this the primary ctor method.
-  return get(std::vector<Constant*>(Vals, Vals+NumVals), Packed);
+  return get(Context, std::vector<Constant*>(Vals, Vals+NumVals), Packed);
 }
 
 ConstantVector::ConstantVector(const VectorType *T,
@@ -1355,7 +1357,8 @@ Constant* ConstantExpr::getSizeOf(const Type* Ty) {
 
 Constant* ConstantExpr::getAlignOf(const Type* Ty) {
   // alignof is implemented as: (i64) gep ({i8,Ty}*)null, 0, 1
-  const Type *AligningTy = StructType::get(Type::Int8Ty, Ty, NULL);
+  const Type *AligningTy = StructType::get(Ty->getContext(),
+                                           Type::Int8Ty, Ty, NULL);
   Constant *NullPtr = Constant::getNullValue(AligningTy->getPointerTo());
   Constant *Zero = ConstantInt::get(Type::Int32Ty, 0);
   Constant *One = ConstantInt::get(Type::Int32Ty, 1);
index 89983500b7b2b89ba56b44e17c7161e3c8e1e057..6cce6782eea8aa1837bfae0c856de15f9506ff2c 100644 (file)
@@ -217,7 +217,7 @@ LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes,
                    *E = ElementTypes + ElementCount; I != E; ++I)
     Tys.push_back(unwrap(*I));
   
-  return wrap(StructType::get(Tys, Packed != 0));
+  return wrap(StructType::get(getGlobalContext(), Tys, Packed != 0));
 }
 
 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy) {
@@ -411,7 +411,8 @@ LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
 
 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
                              int Packed) {
-  return wrap(ConstantStruct::get(unwrap<Constant>(ConstantVals, Count),
+  return wrap(ConstantStruct::get(getGlobalContext(),
+                                  unwrap<Constant>(ConstantVals, Count),
                                   Count, Packed != 0));
 }
 
index 3ce1234adfa5f309ae2547431dbedf7707ea9288..966f54b3e222d23876a83b3ed1a1cdf02bbf8410 100644 (file)
@@ -132,6 +132,7 @@ struct LLVMContextImpl {
   TypeMap<VectorValType, VectorType> VectorTypes;
   TypeMap<PointerValType, PointerType> PointerTypes;
   TypeMap<FunctionValType, FunctionType> FunctionTypes;
+  TypeMap<StructValType, StructType> StructTypes;
   
   LLVMContextImpl() : TheTrueVal(0), TheFalseVal(0) { }
 };
index 61549f8850c439e3357c61222d1b6643d4110cf8..ac55096ac8aa68beed78d646804131d208f4575b 100644 (file)
@@ -849,22 +849,23 @@ bool VectorType::isValidElementType(const Type *ElemTy) {
 // Struct Type Factory...
 //
 
-static ManagedStatic<TypeMap<StructValType, StructType> > StructTypes;
-
-StructType *StructType::get(const std::vector<const Type*> &ETypes, 
+StructType *StructType::get(LLVMContext &Context,
+                            const std::vector<const Type*> &ETypes, 
                             bool isPacked) {
   StructValType STV(ETypes, isPacked);
   StructType *ST = 0;
   
+  LLVMContextImpl *pImpl = Context.pImpl;
+  
   sys::SmartScopedLock<true> L(*TypeMapLock);
-  ST = StructTypes->get(STV);
+  ST = pImpl->StructTypes.get(STV);
     
   if (!ST) {
     // Value not found.  Derive a new type!
     ST = (StructType*) operator new(sizeof(StructType) +
                                     sizeof(PATypeHandle) * ETypes.size());
     new (ST) StructType(ETypes, isPacked);
-    StructTypes->add(STV, ST);
+    pImpl->StructTypes.add(STV, ST);
   }
 #ifdef DEBUG_MERGE_TYPES
   DOUT << "Derived new type: " << *ST << "\n";
@@ -872,7 +873,7 @@ StructType *StructType::get(const std::vector<const Type*> &ETypes,
   return ST;
 }
 
-StructType *StructType::get(const Type *type, ...) {
+StructType *StructType::get(LLVMContext &Context, const Type *type, ...) {
   va_list ap;
   std::vector<const llvm::Type*> StructFields;
   va_start(ap, type);
@@ -880,7 +881,7 @@ StructType *StructType::get(const Type *type, ...) {
     StructFields.push_back(type);
     type = va_arg(ap, llvm::Type*);
   }
-  return llvm::StructType::get(StructFields);
+  return llvm::StructType::get(Context, StructFields);
 }
 
 bool StructType::isValidElementType(const Type *ElemTy) {
@@ -1146,11 +1147,13 @@ void VectorType::typeBecameConcrete(const DerivedType *AbsTy) {
 //
 void StructType::refineAbstractType(const DerivedType *OldType,
                                     const Type *NewType) {
-  StructTypes->RefineAbstractType(this, OldType, NewType);
+  LLVMContextImpl *pImpl = OldType->getContext().pImpl;
+  pImpl->StructTypes.RefineAbstractType(this, OldType, NewType);
 }
 
 void StructType::typeBecameConcrete(const DerivedType *AbsTy) {
-  StructTypes->TypeBecameConcrete(this, AbsTy);
+  LLVMContextImpl *pImpl = AbsTy->getContext().pImpl;
+  pImpl->StructTypes.TypeBecameConcrete(this, AbsTy);
 }
 
 // refineAbstractType - Called when a contained type is found to be more
index f15fa9034563bb749481e46af7bd083808bf8849..684dde3538d8e5abe197589193cedfedfb4e1bc2 100644 (file)
@@ -186,7 +186,8 @@ 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(ConstantStruct::get(Elts));
+    ArrayElts.push_back(ConstantStruct::get(
+                                        TorList[i].first->getContext(), Elts));
   }
   return ConstantArray::get(ArrayType::get(ArrayElts[0]->getType(), 
                                            ArrayElts.size()),
index d1e9b03b8c76f56705c3094413fce8343e88d582..502aee64348ed5941f65d36a903b65f3a051d14a 100644 (file)
@@ -146,7 +146,7 @@ static void EmitTypeForValueType(raw_ostream &OS, MVT::SimpleValueType VT) {
     OS << "IntegerType::get(" << BitWidth << ")";
   } else if (VT == MVT::Other) {
     // MVT::OtherVT is used to mean the empty struct type here.
-    OS << "StructType::get()";
+    OS << "StructType::get(Context)";
   } else if (VT == MVT::f32) {
     OS << "Type::FloatTy";
   } else if (VT == MVT::f64) {
@@ -177,7 +177,7 @@ static void EmitTypeGenerate(raw_ostream &OS,
     return;
   }
 
-  OS << "StructType::get(";
+  OS << "StructType::get(Context, ";
 
   for (std::vector<Record*>::const_iterator
          I = ArgTypes.begin(), E = ArgTypes.end(); I != E; ++I) {