Move types back to the 2.5 API.

llvm-svn: 77516
diff --git a/llvm/lib/VMCore/AutoUpgrade.cpp b/llvm/lib/VMCore/AutoUpgrade.cpp
index fc86e54..81d143a 100644
--- a/llvm/lib/VMCore/AutoUpgrade.cpp
+++ b/llvm/lib/VMCore/AutoUpgrade.cpp
@@ -27,8 +27,6 @@
 static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) {
   assert(F && "Illegal to upgrade a non-existent Function.");
 
-  LLVMContext &Context = F->getContext();
-
   // Get the Function's name.
   const std::string& Name = F->getName();
 
@@ -167,7 +165,7 @@
          Name.compare(13,4,"psrl", 4) == 0) && Name[17] != 'i') {
       
       const llvm::Type *VT =
-                        Context.getVectorType(Context.getIntegerType(64), 1);
+                        VectorType::get(IntegerType::get(64), 1);
       
       // We don't have to do anything if the parameter already has
       // the correct type.
@@ -268,7 +266,7 @@
       if (isLoadH || isLoadL) {
         Value *Op1 = Context.getUndef(Op0->getType());
         Value *Addr = new BitCastInst(CI->getOperand(2), 
-                                  Context.getPointerTypeUnqual(Type::DoubleTy),
+                                  PointerType::getUnqual(Type::DoubleTy),
                                       "upgraded.", CI);
         Value *Load = new LoadInst(Addr, "upgraded.", false, 8, CI);
         Value *Idx = ConstantInt::get(Type::Int32Ty, 0);
diff --git a/llvm/lib/VMCore/ConstantFold.cpp b/llvm/lib/VMCore/ConstantFold.cpp
index 440fb88..ab00160 100644
--- a/llvm/lib/VMCore/ConstantFold.cpp
+++ b/llvm/lib/VMCore/ConstantFold.cpp
@@ -1373,7 +1373,7 @@
                                                const Constant *C2) {
   const Type *ResultTy;
   if (const VectorType *VT = dyn_cast<VectorType>(C1->getType()))
-    ResultTy = Context.getVectorType(Type::Int1Ty, VT->getNumElements());
+    ResultTy = VectorType::get(Type::Int1Ty, VT->getNumElements());
   else
     ResultTy = Type::Int1Ty;
 
@@ -1677,7 +1677,7 @@
                                                        (Value **)Idxs,
                                                        (Value **)Idxs+NumIdx);
     assert(Ty != 0 && "Invalid indices for GEP!");
-    return Context.getUndef(Context.getPointerType(Ty, Ptr->getAddressSpace()));
+    return Context.getUndef(PointerType::get(Ty, Ptr->getAddressSpace()));
   }
 
   Constant *Idx0 = Idxs[0];
@@ -1695,7 +1695,7 @@
                                                          (Value**)Idxs+NumIdx);
       assert(Ty != 0 && "Invalid indices for GEP!");
       return  Context.getConstantPointerNull(
-                            Context.getPointerType(Ty,Ptr->getAddressSpace()));
+                            PointerType::get(Ty,Ptr->getAddressSpace()));
     }
   }
 
diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp
index 6746882..1ff596f 100644
--- a/llvm/lib/VMCore/Constants.cpp
+++ b/llvm/lib/VMCore/Constants.cpp
@@ -178,7 +178,7 @@
 // invariant which generates an assertion.
 ConstantInt *ConstantInt::get(LLVMContext &Context, const APInt& V) {
   // Get the corresponding integer type for the bit width of the value.
-  const IntegerType *ITy = Context.getIntegerType(V.getBitWidth());
+  const IntegerType *ITy = IntegerType::get(V.getBitWidth());
   // get an existing value or the insertion position
   DenseMapAPIntKeyInfo::KeyTy Key(V, ITy);
   
diff --git a/llvm/lib/VMCore/Core.cpp b/llvm/lib/VMCore/Core.cpp
index bf5a6a1..59aeb87 100644
--- a/llvm/lib/VMCore/Core.cpp
+++ b/llvm/lib/VMCore/Core.cpp
@@ -162,7 +162,7 @@
 LLVMTypeRef LLVMInt64Type(void) { return (LLVMTypeRef) Type::Int64Ty; }
 
 LLVMTypeRef LLVMIntType(unsigned NumBits) {
-  return wrap(getGlobalContext().getIntegerType(NumBits));
+  return wrap(IntegerType::get(NumBits));
 }
 
 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy) {
@@ -186,8 +186,7 @@
   for (LLVMTypeRef *I = ParamTypes, *E = ParamTypes + ParamCount; I != E; ++I)
     Tys.push_back(unwrap(*I));
   
-  return wrap(getGlobalContext().getFunctionType(unwrap(ReturnType), Tys,
-                                                 IsVarArg != 0));
+  return wrap(FunctionType::get(unwrap(ReturnType), Tys, IsVarArg != 0));
 }
 
 int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy) {
@@ -218,7 +217,7 @@
                    *E = ElementTypes + ElementCount; I != E; ++I)
     Tys.push_back(unwrap(*I));
   
-  return wrap(getGlobalContext().getStructType(Tys, Packed != 0));
+  return wrap(StructType::get(Tys, Packed != 0));
 }
 
 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy) {
@@ -239,18 +238,15 @@
 /*--.. Operations on array, pointer, and vector types (sequence types) .....--*/
 
 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount) {
-  return wrap(getGlobalContext().getArrayType(unwrap(ElementType), 
-                                               ElementCount));
+  return wrap(ArrayType::get(unwrap(ElementType), ElementCount));
 }
 
 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace) {
-  return wrap(getGlobalContext().getPointerType(unwrap(ElementType), 
-                                                 AddressSpace));
+  return wrap(PointerType::get(unwrap(ElementType), AddressSpace));
 }
 
 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount) {
-  return wrap(getGlobalContext().getVectorType(unwrap(ElementType), 
-                                                ElementCount));
+  return wrap(VectorType::get(unwrap(ElementType), ElementCount));
 }
 
 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty) {
@@ -275,7 +271,7 @@
 LLVMTypeRef LLVMLabelType(void) { return (LLVMTypeRef) Type::LabelTy; }
 
 LLVMTypeRef LLVMOpaqueType(void) {
-  return wrap(getGlobalContext().getOpaqueType());
+  return wrap(OpaqueType::get());
 }
 
 /*--.. Operations on type handles ..........................................--*/
@@ -408,8 +404,7 @@
 
 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
                             LLVMValueRef *ConstantVals, unsigned Length) {
-  return wrap(ConstantArray::get(
-                    getGlobalContext().getArrayType(unwrap(ElementTy), Length),
+  return wrap(ConstantArray::get(ArrayType::get(unwrap(ElementTy), Length),
                                  unwrap<Constant>(ConstantVals, Length),
                                  Length));
 }
diff --git a/llvm/lib/VMCore/Function.cpp b/llvm/lib/VMCore/Function.cpp
index cdf2dd0..9fc3000 100644
--- a/llvm/lib/VMCore/Function.cpp
+++ b/llvm/lib/VMCore/Function.cpp
@@ -346,7 +346,7 @@
 #include "llvm/Intrinsics.gen"
 #undef GET_INTRINSIC_GENERATOR
 
-  return Context.getFunctionType(ResultTy, ArgTys, IsVarArg); 
+  return FunctionType::get(ResultTy, ArgTys, IsVarArg); 
 }
 
 bool Intrinsic::isOverloaded(ID id) {
diff --git a/llvm/lib/VMCore/Globals.cpp b/llvm/lib/VMCore/Globals.cpp
index e01dedd..d18a201 100644
--- a/llvm/lib/VMCore/Globals.cpp
+++ b/llvm/lib/VMCore/Globals.cpp
@@ -98,7 +98,7 @@
                                bool constant, LinkageTypes Link,
                                Constant *InitVal, const Twine &Name,
                                bool ThreadLocal, unsigned AddressSpace)
-  : GlobalValue(Context.getPointerType(Ty, AddressSpace), 
+  : GlobalValue(PointerType::get(Ty, AddressSpace), 
                 Value::GlobalVariableVal,
                 OperandTraits<GlobalVariable>::op_begin(this),
                 InitVal != 0, Link, Name),
@@ -117,7 +117,7 @@
                                const Twine &Name,
                                GlobalVariable *Before, bool ThreadLocal,
                                unsigned AddressSpace)
-  : GlobalValue(M.getContext().getPointerType(Ty, AddressSpace), 
+  : GlobalValue(PointerType::get(Ty, AddressSpace), 
                 Value::GlobalVariableVal,
                 OperandTraits<GlobalVariable>::op_begin(this),
                 InitVal != 0, Link, Name),
diff --git a/llvm/lib/VMCore/Instructions.cpp b/llvm/lib/VMCore/Instructions.cpp
index 0b24241..08b4396 100644
--- a/llvm/lib/VMCore/Instructions.cpp
+++ b/llvm/lib/VMCore/Instructions.cpp
@@ -716,7 +716,7 @@
 AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy,
                                unsigned Align, const Twine &Name,
                                Instruction *InsertBefore)
-  : UnaryInstruction(Ty->getContext().getPointerTypeUnqual(Ty), iTy,
+  : UnaryInstruction(PointerType::getUnqual(Ty), iTy,
                      getAISize(Ty->getContext(), ArraySize), InsertBefore) {
   setAlignment(Align);
   assert(Ty != Type::VoidTy && "Cannot allocate void!");
@@ -726,7 +726,7 @@
 AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy,
                                unsigned Align, const Twine &Name,
                                BasicBlock *InsertAtEnd)
-  : UnaryInstruction(Ty->getContext().getPointerTypeUnqual(Ty), iTy,
+  : UnaryInstruction(PointerType::getUnqual(Ty), iTy,
                      getAISize(Ty->getContext(), ArraySize), InsertAtEnd) {
   setAlignment(Align);
   assert(Ty != Type::VoidTy && "Cannot allocate void!");
@@ -1046,7 +1046,7 @@
 
 GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx,
                                      const Twine &Name, Instruction *InBe)
-  : Instruction(Ptr->getType()->getContext().getPointerType(
+  : Instruction(PointerType::get(
       checkType(getIndexedType(Ptr->getType(),Idx)), retrieveAddrSpace(Ptr)),
                 GetElementPtr,
                 OperandTraits<GetElementPtrInst>::op_end(this) - 2,
@@ -1056,7 +1056,7 @@
 
 GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx,
                                      const Twine &Name, BasicBlock *IAE)
-  : Instruction(Ptr->getType()->getContext().getPointerType(
+  : Instruction(PointerType::get(
             checkType(getIndexedType(Ptr->getType(),Idx)),  
                 retrieveAddrSpace(Ptr)),
                 GetElementPtr,
@@ -1270,8 +1270,7 @@
 ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
                                      const Twine &Name,
                                      Instruction *InsertBefore)
-: Instruction(V1->getType()->getContext().getVectorType(
-                              cast<VectorType>(V1->getType())->getElementType(),
+: Instruction(VectorType::get(cast<VectorType>(V1->getType())->getElementType(),
                 cast<VectorType>(Mask->getType())->getNumElements()),
               ShuffleVector,
               OperandTraits<ShuffleVectorInst>::op_begin(this),
diff --git a/llvm/lib/VMCore/LLVMContext.cpp b/llvm/lib/VMCore/LLVMContext.cpp
index e38986e..8bd45b2 100644
--- a/llvm/lib/VMCore/LLVMContext.cpp
+++ b/llvm/lib/VMCore/LLVMContext.cpp
@@ -113,89 +113,6 @@
   return pImpl->getMDString(Str.data(), Str.size());
 }
 
-// FunctionType accessors
-FunctionType* LLVMContext::getFunctionType(const Type* Result, bool isVarArg) {
-  return FunctionType::get(Result, isVarArg);
-}
-
-FunctionType* LLVMContext::getFunctionType(const Type* Result,
-                                         const std::vector<const Type*>& Params,
-                                         bool isVarArg) {
-  return FunctionType::get(Result, Params, isVarArg);
-}
-                                
-// IntegerType accessors
-const IntegerType* LLVMContext::getIntegerType(unsigned NumBits) {
-  return IntegerType::get(NumBits);
-}
-  
-// OpaqueType accessors
-OpaqueType* LLVMContext::getOpaqueType() {
-  return OpaqueType::get();
-}
-
-// StructType accessors
-StructType* LLVMContext::getStructType(bool isPacked) {
-  return StructType::get(isPacked);
-}
-
-StructType* LLVMContext::getStructType(const std::vector<const Type*>& Params,
-                                       bool isPacked) {
-  return StructType::get(Params, isPacked);
-}
-
-StructType *LLVMContext::getStructType(const Type *type, ...) {
-  va_list ap;
-  std::vector<const llvm::Type*> StructFields;
-  va_start(ap, type);
-  while (type) {
-    StructFields.push_back(type);
-    type = va_arg(ap, llvm::Type*);
-  }
-  return StructType::get(StructFields);
-}
-
-// ArrayType accessors
-ArrayType* LLVMContext::getArrayType(const Type* ElementType,
-                                     uint64_t NumElements) {
-  return ArrayType::get(ElementType, NumElements);
-}
-  
-// PointerType accessors
-PointerType* LLVMContext::getPointerType(const Type* ElementType,
-                                         unsigned AddressSpace) {
-  return PointerType::get(ElementType, AddressSpace);
-}
-
-PointerType* LLVMContext::getPointerTypeUnqual(const Type* ElementType) {
-  return PointerType::getUnqual(ElementType);
-}
-  
-// VectorType accessors
-VectorType* LLVMContext::getVectorType(const Type* ElementType,
-                                       unsigned NumElements) {
-  return VectorType::get(ElementType, NumElements);
-}
-
-VectorType* LLVMContext::getVectorTypeInteger(const VectorType* VTy) {
-  return VectorType::getInteger(VTy);  
-}
-
-VectorType* LLVMContext::getVectorTypeExtendedElement(const VectorType* VTy) {
-  return VectorType::getExtendedElementVectorType(VTy);
-}
-
-VectorType* LLVMContext::getVectorTypeTruncatedElement(const VectorType* VTy) {
-  return VectorType::getTruncatedElementVectorType(VTy);
-}
-
-const Type* LLVMContext::makeCmpResultType(const Type* opnd_type) {
-  if (const VectorType* vt = dyn_cast<const VectorType>(opnd_type)) {
-    return getVectorType(Type::Int1Ty, vt->getNumElements());
-  }
-  return Type::Int1Ty;
-}
-
 void LLVMContext::erase(MDString *M) {
   pImpl->erase(M);
 }
diff --git a/llvm/lib/VMCore/Module.cpp b/llvm/lib/VMCore/Module.cpp
index 2ef16d0..87d4b05 100644
--- a/llvm/lib/VMCore/Module.cpp
+++ b/llvm/lib/VMCore/Module.cpp
@@ -153,8 +153,8 @@
 
   // If the function exists but has the wrong type, return a bitcast to the
   // right type.
-  if (F->getType() != Context.getPointerTypeUnqual(Ty))
-    return ConstantExpr::getBitCast(F, Context.getPointerTypeUnqual(Ty));
+  if (F->getType() != PointerType::getUnqual(Ty))
+    return ConstantExpr::getBitCast(F, PointerType::getUnqual(Ty));
   
   // Otherwise, we just found the existing function or a prototype.
   return F;  
@@ -203,7 +203,7 @@
 
   // Build the function type and chain to the other getOrInsertFunction...
   return getOrInsertFunction(Name,
-                             Context.getFunctionType(RetTy, ArgTys, false),
+                             FunctionType::get(RetTy, ArgTys, false),
                              AttributeList);
 }
 
@@ -221,7 +221,7 @@
 
   // Build the function type and chain to the other getOrInsertFunction...
   return getOrInsertFunction(Name, 
-                             Context.getFunctionType(RetTy, ArgTys, false),
+                             FunctionType::get(RetTy, ArgTys, false),
                              AttrListPtr::get((AttributeWithIndex *)0, 0));
 }
 
@@ -271,8 +271,8 @@
 
   // If the variable exists but has the wrong type, return a bitcast to the
   // right type.
-  if (GV->getType() != Context.getPointerTypeUnqual(Ty))
-    return ConstantExpr::getBitCast(GV, Context.getPointerTypeUnqual(Ty));
+  if (GV->getType() != PointerType::getUnqual(Ty))
+    return ConstantExpr::getBitCast(GV, PointerType::getUnqual(Ty));
   
   // Otherwise, we just found the existing function or a prototype.
   return GV;
diff --git a/llvm/lib/VMCore/ValueTypes.cpp b/llvm/lib/VMCore/ValueTypes.cpp
index 5badffc..2446596 100644
--- a/llvm/lib/VMCore/ValueTypes.cpp
+++ b/llvm/lib/VMCore/ValueTypes.cpp
@@ -21,16 +21,14 @@
 
 MVT MVT::getExtendedIntegerVT(unsigned BitWidth) {
   MVT VT;
-  VT.LLVMTy = getGlobalContext().getIntegerType(BitWidth);
+  VT.LLVMTy = IntegerType::get(BitWidth);
   assert(VT.isExtended() && "Type is not extended!");
   return VT;
 }
 
 MVT MVT::getExtendedVectorVT(MVT VT, unsigned NumElements) {
   MVT ResultVT;
-  ResultVT.LLVMTy = getGlobalContext().getVectorType(
-                                           VT.getTypeForMVT(getGlobalContext()), 
-                                                     NumElements);
+  ResultVT.LLVMTy = VectorType::get(VT.getTypeForMVT(), NumElements);
   assert(ResultVT.isExtended() && "Type is not extended!");
   return ResultVT;
 }
@@ -133,7 +131,7 @@
 /// getTypeForMVT - This method returns an LLVM type corresponding to the
 /// specified MVT.  For integer types, this returns an unsigned type.  Note
 /// that this will abort for types that cannot be represented.
-const Type *MVT::getTypeForMVT(LLVMContext &Context) const {
+const Type *MVT::getTypeForMVT() const {
   switch (V) {
   default:
     assert(isExtended() && "Type is not extended!");
@@ -144,32 +142,32 @@
   case MVT::i16:     return Type::Int16Ty;
   case MVT::i32:     return Type::Int32Ty;
   case MVT::i64:     return Type::Int64Ty;
-  case MVT::i128:    return Context.getIntegerType(128);
+  case MVT::i128:    return IntegerType::get(128);
   case MVT::f32:     return Type::FloatTy;
   case MVT::f64:     return Type::DoubleTy;
   case MVT::f80:     return Type::X86_FP80Ty;
   case MVT::f128:    return Type::FP128Ty;
   case MVT::ppcf128: return Type::PPC_FP128Ty;
-  case MVT::v2i8:    return Context.getVectorType(Type::Int8Ty, 2);
-  case MVT::v4i8:    return Context.getVectorType(Type::Int8Ty, 4);
-  case MVT::v8i8:    return Context.getVectorType(Type::Int8Ty, 8);
-  case MVT::v16i8:   return Context.getVectorType(Type::Int8Ty, 16);
-  case MVT::v32i8:   return Context.getVectorType(Type::Int8Ty, 32);
-  case MVT::v2i16:   return Context.getVectorType(Type::Int16Ty, 2);
-  case MVT::v4i16:   return Context.getVectorType(Type::Int16Ty, 4);
-  case MVT::v8i16:   return Context.getVectorType(Type::Int16Ty, 8);
-  case MVT::v16i16:  return Context.getVectorType(Type::Int16Ty, 16);
-  case MVT::v2i32:   return Context.getVectorType(Type::Int32Ty, 2);
-  case MVT::v4i32:   return Context.getVectorType(Type::Int32Ty, 4);
-  case MVT::v8i32:   return Context.getVectorType(Type::Int32Ty, 8);
-  case MVT::v1i64:   return Context.getVectorType(Type::Int64Ty, 1);
-  case MVT::v2i64:   return Context.getVectorType(Type::Int64Ty, 2);
-  case MVT::v4i64:   return Context.getVectorType(Type::Int64Ty, 4);
-  case MVT::v2f32:   return Context.getVectorType(Type::FloatTy, 2);
-  case MVT::v4f32:   return Context.getVectorType(Type::FloatTy, 4);
-  case MVT::v8f32:   return Context.getVectorType(Type::FloatTy, 8);
-  case MVT::v2f64:   return Context.getVectorType(Type::DoubleTy, 2);
-  case MVT::v4f64:   return Context.getVectorType(Type::DoubleTy, 4); 
+  case MVT::v2i8:    return VectorType::get(Type::Int8Ty, 2);
+  case MVT::v4i8:    return VectorType::get(Type::Int8Ty, 4);
+  case MVT::v8i8:    return VectorType::get(Type::Int8Ty, 8);
+  case MVT::v16i8:   return VectorType::get(Type::Int8Ty, 16);
+  case MVT::v32i8:   return VectorType::get(Type::Int8Ty, 32);
+  case MVT::v2i16:   return VectorType::get(Type::Int16Ty, 2);
+  case MVT::v4i16:   return VectorType::get(Type::Int16Ty, 4);
+  case MVT::v8i16:   return VectorType::get(Type::Int16Ty, 8);
+  case MVT::v16i16:  return VectorType::get(Type::Int16Ty, 16);
+  case MVT::v2i32:   return VectorType::get(Type::Int32Ty, 2);
+  case MVT::v4i32:   return VectorType::get(Type::Int32Ty, 4);
+  case MVT::v8i32:   return VectorType::get(Type::Int32Ty, 8);
+  case MVT::v1i64:   return VectorType::get(Type::Int64Ty, 1);
+  case MVT::v2i64:   return VectorType::get(Type::Int64Ty, 2);
+  case MVT::v4i64:   return VectorType::get(Type::Int64Ty, 4);
+  case MVT::v2f32:   return VectorType::get(Type::FloatTy, 2);
+  case MVT::v4f32:   return VectorType::get(Type::FloatTy, 4);
+  case MVT::v8f32:   return VectorType::get(Type::FloatTy, 8);
+  case MVT::v2f64:   return VectorType::get(Type::DoubleTy, 2);
+  case MVT::v4f64:   return VectorType::get(Type::DoubleTy, 4); 
  }
 }
 
diff --git a/llvm/lib/VMCore/Verifier.cpp b/llvm/lib/VMCore/Verifier.cpp
index 6d179d0..407a80b 100644
--- a/llvm/lib/VMCore/Verifier.cpp
+++ b/llvm/lib/VMCore/Verifier.cpp
@@ -1490,7 +1490,6 @@
 bool Verifier::PerformTypeCheck(Intrinsic::ID ID, Function *F, const Type *Ty,
                                 int VT, unsigned ArgNo, std::string &Suffix) {
   const FunctionType *FTy = F->getFunctionType();
-  LLVMContext &Context = FTy->getContext();
 
   unsigned NumElts = 0;
   const Type *EltTy = Ty;
@@ -1620,7 +1619,7 @@
                   "vector elements!", F);
       return false;
     }
-  } else if (MVT((MVT::SimpleValueType)VT).getTypeForMVT(Context) != EltTy) {
+  } else if (MVT((MVT::SimpleValueType)VT).getTypeForMVT() != EltTy) {
     CheckFailed(IntrinsicParam(ArgNo, NumRets) + " is wrong!", F);
     return false;
   } else if (EltTy != Ty) {