diff options
Diffstat (limited to 'lib/CodeGen/CGObjCMac.cpp')
-rw-r--r-- | lib/CodeGen/CGObjCMac.cpp | 557 |
1 files changed, 290 insertions, 267 deletions
diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index 8f624f7ff8..70eb6a70e1 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -101,12 +101,13 @@ LValue CGObjCRuntime::EmitValueForIvarAtOffset(CodeGen::CodeGenFunction &CGF, unsigned CVRQualifiers, llvm::Value *Offset) { // Compute (type*) ( (char *) BaseValue + Offset) - llvm::Type *I8Ptr = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); + llvm::LLVMContext &VMContext = CGF.getLLVMContext(); + llvm::Type *I8Ptr = VMContext.getPointerTypeUnqual(llvm::Type::Int8Ty); QualType IvarTy = Ivar->getType(); const llvm::Type *LTy = CGF.CGM.getTypes().ConvertTypeForMem(IvarTy); llvm::Value *V = CGF.Builder.CreateBitCast(BaseValue, I8Ptr); V = CGF.Builder.CreateGEP(V, Offset, "add.ptr"); - V = CGF.Builder.CreateBitCast(V, llvm::PointerType::getUnqual(LTy)); + V = CGF.Builder.CreateBitCast(V, VMContext.getPointerTypeUnqual(LTy)); if (Ivar->isBitField()) { // We need to compute the bit offset for the bit-field, the offset @@ -139,6 +140,9 @@ namespace { // concatenation is lame. class ObjCCommonTypesHelper { +protected: + llvm::LLVMContext &VMContext; + private: llvm::Constant *getMessageSendFn() const { // id objc_msgSend (id, SEL, ...) @@ -146,7 +150,7 @@ private: Params.push_back(ObjectPtrTy); Params.push_back(SelectorPtrTy); return - CGM.CreateRuntimeFunction(llvm::FunctionType::get(ObjectPtrTy, + CGM.CreateRuntimeFunction(VMContext.getFunctionType(ObjectPtrTy, Params, true), "objc_msgSend"); } @@ -157,7 +161,7 @@ private: Params.push_back(ObjectPtrTy); Params.push_back(SelectorPtrTy); return - CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::VoidTy, + CGM.CreateRuntimeFunction(VMContext.getFunctionType(llvm::Type::VoidTy, Params, true), "objc_msgSend_stret"); @@ -170,7 +174,7 @@ private: Params.push_back(ObjectPtrTy); Params.push_back(SelectorPtrTy); return - CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::DoubleTy, + CGM.CreateRuntimeFunction(VMContext.getFunctionType(llvm::Type::DoubleTy, Params, true), "objc_msgSend_fpret"); @@ -183,7 +187,7 @@ private: std::vector<const llvm::Type*> Params; Params.push_back(SuperPtrTy); Params.push_back(SelectorPtrTy); - return CGM.CreateRuntimeFunction(llvm::FunctionType::get(ObjectPtrTy, + return CGM.CreateRuntimeFunction(VMContext.getFunctionType(ObjectPtrTy, Params, true), SuperName); } @@ -194,7 +198,7 @@ private: std::vector<const llvm::Type*> Params; Params.push_back(SuperPtrTy); Params.push_back(SelectorPtrTy); - return CGM.CreateRuntimeFunction(llvm::FunctionType::get(ObjectPtrTy, + return CGM.CreateRuntimeFunction(VMContext.getFunctionType(ObjectPtrTy, Params, true), SuperName); } @@ -206,7 +210,8 @@ private: Params.push_back(Int8PtrTy); Params.push_back(SuperPtrTy); Params.push_back(SelectorPtrTy); - return CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::VoidTy, + return CGM.CreateRuntimeFunction( + VMContext.getFunctionType(llvm::Type::VoidTy, Params, true), "objc_msgSendSuper_stret"); } @@ -218,7 +223,8 @@ private: Params.push_back(Int8PtrTy); Params.push_back(SuperPtrTy); Params.push_back(SelectorPtrTy); - return CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::VoidTy, + return CGM.CreateRuntimeFunction( + VMContext.getFunctionType(llvm::Type::VoidTy, Params, true), "objc_msgSendSuper2_stret"); } @@ -331,7 +337,8 @@ public: // id objc_read_weak (id *) std::vector<const llvm::Type*> Args; Args.push_back(ObjectPtrTy->getPointerTo()); - llvm::FunctionType *FTy = llvm::FunctionType::get(ObjectPtrTy, Args, false); + llvm::FunctionType *FTy = + VMContext.getFunctionType(ObjectPtrTy, Args, false); return CGM.CreateRuntimeFunction(FTy, "objc_read_weak"); } @@ -341,7 +348,7 @@ public: std::vector<const llvm::Type*> Args(1, ObjectPtrTy); Args.push_back(ObjectPtrTy->getPointerTo()); llvm::FunctionType *FTy = - llvm::FunctionType::get(ObjectPtrTy, Args, false); + VMContext.getFunctionType(ObjectPtrTy, Args, false); return CGM.CreateRuntimeFunction(FTy, "objc_assign_weak"); } @@ -350,7 +357,8 @@ public: // id objc_assign_global(id, id *) std::vector<const llvm::Type*> Args(1, ObjectPtrTy); Args.push_back(ObjectPtrTy->getPointerTo()); - llvm::FunctionType *FTy = llvm::FunctionType::get(ObjectPtrTy, Args, false); + llvm::FunctionType *FTy = + VMContext.getFunctionType(ObjectPtrTy, Args, false); return CGM.CreateRuntimeFunction(FTy, "objc_assign_global"); } @@ -359,7 +367,8 @@ public: // id objc_assign_ivar(id, id *) std::vector<const llvm::Type*> Args(1, ObjectPtrTy); Args.push_back(ObjectPtrTy->getPointerTo()); - llvm::FunctionType *FTy = llvm::FunctionType::get(ObjectPtrTy, Args, false); + llvm::FunctionType *FTy = + VMContext.getFunctionType(ObjectPtrTy, Args, false); return CGM.CreateRuntimeFunction(FTy, "objc_assign_ivar"); } @@ -369,7 +378,7 @@ public: std::vector<const llvm::Type*> Args(1, Int8PtrTy); Args.push_back(Int8PtrTy); Args.push_back(LongTy); - llvm::FunctionType *FTy = llvm::FunctionType::get(Int8PtrTy, Args, false); + llvm::FunctionType *FTy = VMContext.getFunctionType(Int8PtrTy, Args, false); return CGM.CreateRuntimeFunction(FTy, "objc_memmove_collectable"); } @@ -378,7 +387,8 @@ public: // id objc_assign_global(id, id *) std::vector<const llvm::Type*> Args(1, ObjectPtrTy); Args.push_back(ObjectPtrTy->getPointerTo()); - llvm::FunctionType *FTy = llvm::FunctionType::get(ObjectPtrTy, Args, false); + llvm::FunctionType *FTy = + VMContext.getFunctionType(ObjectPtrTy, Args, false); return CGM.CreateRuntimeFunction(FTy, "objc_assign_strongCast"); } @@ -387,7 +397,7 @@ public: // void objc_exception_throw(id) std::vector<const llvm::Type*> Args(1, ObjectPtrTy); llvm::FunctionType *FTy = - llvm::FunctionType::get(llvm::Type::VoidTy, Args, false); + VMContext.getFunctionType(llvm::Type::VoidTy, Args, false); return CGM.CreateRuntimeFunction(FTy, "objc_exception_throw"); } @@ -396,7 +406,7 @@ public: // void objc_sync_enter (id) std::vector<const llvm::Type*> Args(1, ObjectPtrTy); llvm::FunctionType *FTy = - llvm::FunctionType::get(llvm::Type::VoidTy, Args, false); + VMContext.getFunctionType(llvm::Type::VoidTy, Args, false); return CGM.CreateRuntimeFunction(FTy, "objc_sync_enter"); } @@ -405,7 +415,7 @@ public: // void objc_sync_exit (id) std::vector<const llvm::Type*> Args(1, ObjectPtrTy); llvm::FunctionType *FTy = - llvm::FunctionType::get(llvm::Type::VoidTy, Args, false); + VMContext.getFunctionType(llvm::Type::VoidTy, Args, false); return CGM.CreateRuntimeFunction(FTy, "objc_sync_exit"); } @@ -498,8 +508,9 @@ public: /// ExceptionTryEnterFn - LLVM objc_exception_try_enter function. llvm::Constant *getExceptionTryEnterFn() { std::vector<const llvm::Type*> Params; - Params.push_back(llvm::PointerType::getUnqual(ExceptionDataTy)); - return CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::VoidTy, + Params.push_back(VMContext.getPointerTypeUnqual(ExceptionDataTy)); + return CGM.CreateRuntimeFunction( + VMContext.getFunctionType(llvm::Type::VoidTy, Params, false), "objc_exception_try_enter"); } @@ -507,8 +518,9 @@ public: /// ExceptionTryExitFn - LLVM objc_exception_try_exit function. llvm::Constant *getExceptionTryExitFn() { std::vector<const llvm::Type*> Params; - Params.push_back(llvm::PointerType::getUnqual(ExceptionDataTy)); - return CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::VoidTy, + Params.push_back(VMContext.getPointerTypeUnqual(ExceptionDataTy)); + return CGM.CreateRuntimeFunction( + VMContext.getFunctionType(llvm::Type::VoidTy, Params, false), "objc_exception_try_exit"); } @@ -516,8 +528,8 @@ public: /// ExceptionExtractFn - LLVM objc_exception_extract function. llvm::Constant *getExceptionExtractFn() { std::vector<const llvm::Type*> Params; - Params.push_back(llvm::PointerType::getUnqual(ExceptionDataTy)); - return CGM.CreateRuntimeFunction(llvm::FunctionType::get(ObjectPtrTy, + Params.push_back(VMContext.getPointerTypeUnqual(ExceptionDataTy)); + return CGM.CreateRuntimeFunction(VMContext.getFunctionType(ObjectPtrTy, Params, false), "objc_exception_extract"); @@ -528,7 +540,8 @@ public: std::vector<const llvm::Type*> Params; Params.push_back(ClassPtrTy); Params.push_back(ObjectPtrTy); - return CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::Int32Ty, + return CGM.CreateRuntimeFunction( + VMContext.getFunctionType(llvm::Type::Int32Ty, Params, false), "objc_exception_match"); @@ -537,9 +550,9 @@ public: /// SetJmpFn - LLVM _setjmp function. llvm::Constant *getSetJmpFn() { std::vector<const llvm::Type*> Params; - Params.push_back(llvm::PointerType::getUnqual(llvm::Type::Int32Ty)); + Params.push_back(VMContext.getPointerTypeUnqual(llvm::Type::Int32Ty)); return - CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::Int32Ty, + CGM.CreateRuntimeFunction(VMContext.getFunctionType(llvm::Type::Int32Ty, Params, false), "_setjmp"); @@ -631,7 +644,7 @@ public: std::vector<const llvm::Type*> Params; Params.push_back(ObjectPtrTy); Params.push_back(MessageRefPtrTy); - return CGM.CreateRuntimeFunction(llvm::FunctionType::get(ObjectPtrTy, + return CGM.CreateRuntimeFunction(VMContext.getFunctionType(ObjectPtrTy, Params, true), "objc_msgSend_fixup"); } @@ -641,7 +654,7 @@ public: std::vector<const llvm::Type*> Params; Params.push_back(ObjectPtrTy); Params.push_back(MessageRefPtrTy); - return CGM.CreateRuntimeFunction(llvm::FunctionType::get(ObjectPtrTy, + return CGM.CreateRuntimeFunction(VMContext.getFunctionType(ObjectPtrTy, Params, true), "objc_msgSend_fpret_fixup"); } @@ -651,7 +664,7 @@ public: std::vector<const llvm::Type*> Params; Params.push_back(ObjectPtrTy); Params.push_back(MessageRefPtrTy); - return CGM.CreateRuntimeFunction(llvm::FunctionType::get(ObjectPtrTy, + return CGM.CreateRuntimeFunction(VMContext.getFunctionType(ObjectPtrTy, Params, true), "objc_msgSend_stret_fixup"); } @@ -661,7 +674,7 @@ public: std::vector<const llvm::Type*> Params; Params.push_back(ObjectPtrTy); Params.push_back(MessageRefPtrTy); - return CGM.CreateRuntimeFunction(llvm::FunctionType::get(ObjectPtrTy, + return CGM.CreateRuntimeFunction(VMContext.getFunctionType(ObjectPtrTy, Params, true), "objc_msgSendId_fixup"); } @@ -671,7 +684,7 @@ public: std::vector<const llvm::Type*> Params; Params.push_back(ObjectPtrTy); Params.push_back(MessageRefPtrTy); - return CGM.CreateRuntimeFunction(llvm::FunctionType::get(ObjectPtrTy, + return CGM.CreateRuntimeFunction(VMContext.getFunctionType(ObjectPtrTy, Params, true), "objc_msgSendId_stret_fixup"); } @@ -681,7 +694,7 @@ public: std::vector<const llvm::Type*> Params; Params.push_back(SuperPtrTy); Params.push_back(SuperMessageRefPtrTy); - return CGM.CreateRuntimeFunction(llvm::FunctionType::get(ObjectPtrTy, + return CGM.CreateRuntimeFunction(VMContext.getFunctionType(ObjectPtrTy, Params, true), "objc_msgSendSuper2_fixup"); } @@ -692,7 +705,7 @@ public: std::vector<const llvm::Type*> Params; Params.push_back(SuperPtrTy); Params.push_back(SuperMessageRefPtrTy); - return CGM.CreateRuntimeFunction(llvm::FunctionType::get(ObjectPtrTy, + return CGM.CreateRuntimeFunction(VMContext.getFunctionType(ObjectPtrTy, Params, true), "objc_msgSendSuper2_stret_fixup"); } @@ -703,22 +716,23 @@ public: /// exception personality function. llvm::Value *getEHPersonalityPtr() { llvm::Constant *Personality = - CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::Int32Ty, + CGM.CreateRuntimeFunction(VMContext.getFunctionType(llvm::Type::Int32Ty, true), "__objc_personality_v0"); - return llvm::ConstantExpr::getBitCast(Personality, Int8PtrTy); + return VMContext.getConstantExprBitCast(Personality, Int8PtrTy); } llvm::Constant *getUnwindResumeOrRethrowFn() { std::vector<const llvm::Type*> Params; Params.push_back(Int8PtrTy); - return CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::VoidTy, + return CGM.CreateRuntimeFunction( + VMContext.getFunctionType(llvm::Type::VoidTy, Params, false), "_Unwind_Resume_or_Rethrow"); } llvm::Constant *getObjCEndCatchFn() { - return CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::VoidTy, + return CGM.CreateRuntimeFunction(VMContext.getFunctionType(llvm::Type::VoidTy, false), "objc_end_catch"); @@ -727,7 +741,7 @@ public: llvm::Constant *getObjCBeginCatchFn() { std::vector<const llvm::Type*> Params; Params.push_back(Int8PtrTy); - return CGM.CreateRuntimeFunction(llvm::FunctionType::get(Int8PtrTy, + return CGM.CreateRuntimeFunction(VMContext.getFunctionType(Int8PtrTy, Params, false), "objc_begin_catch"); } @@ -1366,14 +1380,15 @@ public: /* *** Helper Functions *** */ /// getConstantGEP() - Help routine to construct simple GEPs. -static llvm::Constant *getConstantGEP(llvm::Constant *C, +static llvm::Constant *getConstantGEP(llvm::LLVMContext &VMContext, + llvm::Constant *C, unsigned idx0, unsigned idx1) { llvm::Value *Idxs[] = { - llvm::ConstantInt::get(llvm::Type::Int32Ty, idx0), - llvm::ConstantInt::get(llvm::Type::Int32Ty, idx1) + VMContext.getConstantInt(llvm::Type::Int32Ty, idx0), + VMContext.getConstantInt(llvm::Type::Int32Ty, idx1) }; - return llvm::ConstantExpr::getGetElementPtr(C, Idxs, 2); + return VMContext.getConstantExprGetElementPtr(C, Idxs, 2); } /// hasObjCExceptionAttribute - Return true if this class or any super @@ -1544,7 +1559,8 @@ CodeGen::RValue CGObjCCommonMac::EmitLegacyMessageSend( : ObjCTypes.getSendFn(IsSuper); } assert(Fn && "EmitLegacyMessageSend - unknown API"); - Fn = llvm::ConstantExpr::getBitCast(Fn, llvm::PointerType::getUnqual(FTy)); + Fn = VMContext.getConstantExprBitCast(Fn, + VMContext.getPointerTypeUnqual(FTy)); return CGF.EmitCall(FnInfo, Fn, ActualArgs); } @@ -1554,7 +1570,7 @@ llvm::Value *CGObjCMac::GenerateProtocolRef(CGBuilderTy &Builder, // resolved. Investigate. Its also wasteful to look this up over and over. LazySymbols.insert(&CGM.getContext().Idents.get("Protocol")); - return llvm::ConstantExpr::getBitCast(GetProtocolRef(PD), + return VMContext.getConstantExprBitCast(GetProtocolRef(PD), ObjCTypes.ExternalProtocolPtrTy); } @@ -1643,7 +1659,7 @@ llvm::Constant *CGObjCMac::GetOrEmitProtocol(const ObjCProtocolDecl *PD) { + PD->getNameAsString(), "__OBJC,__cat_cls_meth,regular,no_dead_strip", ClassMethods); - llvm::Constant *Init = llvm::ConstantStruct::get(ObjCTypes.ProtocolTy, + llvm::Constant *Init = VMContext.getConstantStruct(ObjCTypes.ProtocolTy, Values); if (Entry) { @@ -1703,7 +1719,7 @@ CGObjCMac::EmitProtocolExtension(const ObjCProtocolDecl *PD, uint64_t Size = CGM.getTargetData().getTypeAllocSize(ObjCTypes.ProtocolExtensionTy); std::vector<llvm::Constant*> Values(4); - Values[0] = llvm::ConstantInt::get(ObjCTypes.IntTy, Size); + Values[0] = VMContext.getConstantInt(ObjCTypes.IntTy, Size); Values[1] = EmitMethodDescList("\01L_OBJC_PROTOCOL_INSTANCE_METHODS_OPT_" + PD->getNameAsString(), @@ -1724,7 +1740,7 @@ CGObjCMac::EmitProtocolExtension(const ObjCProtocolDecl *PD, return VMContext.getNullValue(ObjCTypes.ProtocolExtensionPtrTy); llvm::Constant *Init = - llvm::ConstantStruct::get(ObjCTypes.ProtocolExtensionTy, Values); + VMContext.getConstantStruct(ObjCTypes.ProtocolExtensionTy, Values); // No special section, but goes in llvm.used return CreateMetadataVar("\01L_OBJC_PROTOCOLEXT_" + PD->getNameAsString(), @@ -1758,17 +1774,18 @@ CGObjCMac::EmitProtocolList(const std::string &Name, std::vector<llvm::Constant*> Values(3); // This field is only used by the runtime. Values[0] = VMContext.getNullValue(ObjCTypes.ProtocolListPtrTy); - Values[1] = llvm::ConstantInt::get(ObjCTypes.LongTy, ProtocolRefs.size() - 1); + Values[1] = VMContext.getConstantInt(ObjCTypes.LongTy, + ProtocolRefs.size() - 1); Values[2] = - llvm::ConstantArray::get(llvm::ArrayType::get(ObjCTypes.ProtocolPtrTy, + VMContext.getConstantArray(VMContext.getArrayType(ObjCTypes.ProtocolPtrTy, ProtocolRefs.size()), ProtocolRefs); - llvm::Constant *Init = llvm::ConstantStruct::get(Values); + llvm::Constant *Init = VMContext.getConstantStruct(Values); llvm::GlobalVariable *GV = CreateMetadataVar(Name, Init, "__OBJC,__cat_cls_meth,regular,no_dead_strip", 4, false); - return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.ProtocolListPtrTy); + return VMContext.getConstantExprBitCast(GV, ObjCTypes.ProtocolListPtrTy); } /* @@ -1793,7 +1810,7 @@ llvm::Constant *CGObjCCommonMac::EmitPropertyList(const std::string &Name, const ObjCPropertyDecl *PD = *I; Prop[0] = GetPropertyName(PD->getIdentifier()); Prop[1] = GetPropertyTypeString(PD, Container); - Properties.push_back(llvm::ConstantStruct::get(ObjCTypes.PropertyTy, + Properties.push_back(VMContext.getConstantStruct(ObjCTypes.PropertyTy, Prop)); } @@ -1804,12 +1821,12 @@ llvm::Constant *CGObjCCommonMac::EmitPropertyList(const std::string &Name, unsigned PropertySize = CGM.getTargetData().getTypeAllocSize(ObjCTypes.PropertyTy); std::vector<llvm::Constant*> Values(3); - Values[0] = llvm::ConstantInt::get(ObjCTypes.IntTy, PropertySize); - Values[1] = llvm::ConstantInt::get(ObjCTypes.IntTy, Properties.size()); - llvm::ArrayType *AT = llvm::ArrayType::get(ObjCTypes.PropertyTy, + Values[0] = VMContext.getConstantInt(ObjCTypes.IntTy, PropertySize); + Values[1] = VMContext.getConstantInt(ObjCTypes.IntTy, Properties.size()); + llvm::ArrayType *AT = VMContext.getArrayType(ObjCTypes.PropertyTy, Properties.size()); - Values[2] = llvm::ConstantArray::get(AT, Properties); - llvm::Constant *Init = llvm::ConstantStruct::get(Values); + Values[2] = VMContext.getConstantArray(AT, Properties); + llvm::Constant *Init = VMContext.getConstantStruct(Values); llvm::GlobalVariable *GV = CreateMetadataVar(Name, Init, @@ -1817,7 +1834,7 @@ llvm::Constant *CGObjCCommonMac::EmitPropertyList(const std::string &Name, "__OBJC,__property,regular,no_dead_strip", (ObjCABI == 2) ? 8 : 4, true); - return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.PropertyListPtrTy); + return VMContext.getConstantExprBitCast(GV, ObjCTypes.PropertyListPtrTy); } /* @@ -1829,10 +1846,11 @@ llvm::Constant *CGObjCCommonMac::EmitPropertyList(const std::string &Name, llvm::Constant * CGObjCMac::GetMethodDescriptionConstant(const ObjCMethodDecl *MD) { std::vector<llvm::Constant*> Desc(2); - Desc[0] = llvm::ConstantExpr::getBitCast(GetMethodVarName(MD->getSelector()), + Desc[0] = + VMContext.getConstantExprBitCast(GetMethodVarName(MD->getSelector()), ObjCTypes.SelectorPtrTy); Desc[1] = GetMethodVarType(MD); - return llvm::ConstantStruct::get(ObjCTypes.MethodDescriptionTy, + return VMContext.getConstantStruct(ObjCTypes.MethodDescriptionTy, Desc); } @@ -1844,14 +1862,14 @@ llvm::Constant *CGObjCMac::EmitMethodDescList(const std::string &Name, return VMContext.getNullValue(ObjCTypes.MethodDescriptionListPtrTy); std::vector<llvm::Constant*> Values(2); - Values[0] = llvm::ConstantInt::get(ObjCTypes.IntTy, Methods.size()); - llvm::ArrayType *AT = llvm::ArrayType::get(ObjCTypes.MethodDescriptionTy, + Values[0] = VMContext.getConstantInt(ObjCTypes.IntTy, Methods.size()); + llvm::ArrayType *AT = VMContext.getArrayType(ObjCTypes.MethodDescriptionTy, Methods.size()); - Values[1] = llvm::ConstantArray::get(AT, Methods); - llvm::Constant *Init = llvm::ConstantStruct::get(Values); + Values[1] = VMContext.getConstantArray(AT, Methods); + llvm::Constant *Init = VMContext.getConstantStruct(Values); llvm::GlobalVariable *GV = CreateMetadataVar(Name, Init, Section, 4, true); - return llvm::ConstantExpr::getBitCast(GV, + return VMContext.getConstantExprBitCast(GV, ObjCTypes.MethodDescriptionListPtrTy); } @@ -1912,7 +1930,7 @@ void CGObjCMac::GenerateCategory(const ObjCCategoryImplDecl *OCD) { } else { Values[4] = VMContext.getNullValue(ObjCTypes.ProtocolListPtrTy); } - Values[5] = llvm::ConstantInt::get(ObjCTypes.IntTy, Size); + Values[5] = VMContext.getConstantInt(ObjCTypes.IntTy, Size); // If there is no category @interface then there can be no properties. if (Category) { @@ -1922,7 +1940,7 @@ void CGObjCMac::GenerateCategory(const ObjCCategoryImplDecl *OCD) { Values[6] = VMContext.getNullValue(ObjCTypes.PropertyListPtrTy); } - llvm::Constant *Init = llvm::ConstantStruct::get(ObjCTypes.CategoryTy, + llvm::Constant *Init = VMContext.getConstantStruct(ObjCTypes.CategoryTy, Values); llvm::GlobalVariable *GV = @@ -2016,16 +2034,16 @@ void CGObjCMac::GenerateClass(const ObjCImplementationDecl *ID) { LazySymbols.insert(Super->getIdentifier()); Values[ 1] = - llvm::ConstantExpr::getBitCast(GetClassName(Super->getIdentifier()), + VMContext.getConstantExprBitCast(GetClassName(Super->getIdentifier()), ObjCTypes.ClassPtrTy); } else { Values[ 1] = VMContext.getNullValue(ObjCTypes.ClassPtrTy); } Values[ 2] = GetClassName(ID->getIdentifier()); // Version is always 0. - Values[ 3] = llvm::ConstantInt::get(ObjCTypes.LongTy, 0); - Values[ 4] = llvm::ConstantInt::get(ObjCTypes.LongTy, Flags); - Values[ 5] = llvm::ConstantInt::get(ObjCTypes.LongTy, Size); + Values[ 3] = VMContext.getConstantInt(ObjCTypes.LongTy, 0); + Values[ 4] = VMContext.getConstantInt(ObjCTypes.LongTy, Flags); + Values[ 5] = VMContext.getConstantInt(ObjCTypes.LongTy, Size); Values[ 6] = EmitIvarList(ID, false); Values[ 7] = EmitMethodList("\01L_OBJC_INSTANCE_METHODS_" + ID->getNameAsString(), @@ -2036,7 +2054,7 @@ void CGObjCMac::GenerateClass(const ObjCImplementationDecl *ID) { Values[ 9] = Protocols; Values[10] = BuildIvarLayout(ID, true); Values[11] = EmitClassExtension(ID); - llvm::Constant *Init = llvm::ConstantStruct::get(ObjCTypes.ClassTy, + llvm::Constant *Init = VMContext.getConstantStruct(ObjCTypes.ClassTy, Values); llvm::GlobalVariable *GV = @@ -2061,23 +2079,23 @@ llvm::Constant *CGObjCMac::EmitMetaClass(const ObjCImplementationDecl *ID, while (const ObjCInterfaceDecl *Super = Root->getSuperClass()) Root = Super; Values[ 0] = - llvm::ConstantExpr::getBitCast(GetClassName(Root->getIdentifier()), + VMContext.getConstantExprBitCast(GetClassName(Root->getIdentifier()), ObjCTypes.ClassPtrTy); // The super class for the metaclass is emitted as the name of the // super class. The runtime fixes this up to point to the // *metaclass* for the super class. if (ObjCInterfaceDecl *Super = ID->getClassInterface()->getSuperClass()) { Values[ 1] = - llvm::ConstantExpr::getBitCast(GetClassName(Super->getIdentifier()), + VMContext.getConstantExprBitCast(GetClassName(Super->getIdentifier()), ObjCTypes.ClassPtrTy); } else { Values[ 1] = VMContext.getNullValue(ObjCTypes.ClassPtrTy); } Values[ 2] = GetClassName(ID->getIdentifier()); // Version is always 0. - Values[ 3] = llvm::ConstantInt::get(ObjCTypes.LongTy, 0); - Values[ 4] = llvm::ConstantInt::get(ObjCTypes.LongTy, Flags); - Values[ 5] = llvm::ConstantInt::get(ObjCTypes.LongTy, Size); + Values[ 3] = VMContext.getConstantInt(ObjCTypes.LongTy, 0); + Values[ 4] = VMContext.getConstantInt(ObjCTypes.LongTy, Flags); + Values[ 5] = VMContext.getConstantInt(ObjCTypes.LongTy, Size); Values[ 6] = EmitIvarList(ID, true); Values[ 7] = EmitMethodList("\01L_OBJC_CLASS_METHODS_" + ID->getNameAsString(), @@ -2090,7 +2108,7 @@ llvm::Constant *CGObjCMac::EmitMetaClass(const ObjCImplementationDecl *ID, Values[10] = VMContext.getNullValue(ObjCTypes.Int8PtrTy); // The class extension is always unused for metaclasses. Values[11] = VMContext.getNullValue(ObjCTypes.ClassExtensionPtrTy); - llvm::Constant *Init = llvm::ConstantStruct::get(ObjCTypes.ClassTy, + llvm::Constant *Init = VMContext.getConstantStruct(ObjCTypes.ClassTy, Values); std::string Name("\01L_OBJC_METACLASS_"); @@ -2153,7 +2171,7 @@ CGObjCMac::EmitClassExtension(const ObjCImplementationDecl *ID) { CGM.getTargetData().getTypeAllocSize(ObjCTypes.ClassExtensionTy); std::vector<llvm::Constant*> Values(3); - Values[0] = llvm::ConstantInt::get(ObjCTypes.IntTy, Size); + Values[0] = VMContext.getConstantInt(ObjCTypes.IntTy, Size); Values[1] = BuildIvarLayout(ID, false); Values[2] = EmitPropertyList("\01l_OBJC_$_PROP_LIST_" + ID->getNameAsString(), ID, ID->getClassInterface(), ObjCTypes); @@ -2163,7 +2181,7 @@ CGObjCMac::EmitClassExtension(const ObjCImplementationDecl *ID) { return VMContext.getNullValue(ObjCTypes.ClassExtensionPtrTy); llvm::Constant *Init = - llvm::ConstantStruct::get(ObjCTypes.ClassExtensionTy, Values); + VMContext.getConstantStruct(ObjCTypes.ClassExtensionTy, Values); return CreateMetadataVar("\01L_OBJC_CLASSEXT_" + ID->getNameAsString(), Init, "__OBJC,__class_ext,regular,no_dead_strip", 4, true); @@ -2206,9 +2224,9 @@ llvm::Constant *CGObjCMac::EmitIvarList(const ObjCImplementationDecl *ID, continue; Ivar[0] = GetMethodVarName(IVD->getIdentifier()); Ivar[1] = GetMethodVarType(IVD); - Ivar[2] = llvm::ConstantInt::get(ObjCTypes.IntTy, + Ivar[2] = VMContext.getConstantInt(ObjCTypes.IntTy, ComputeIvarBaseOffset(CGM, OID, IVD)); - Ivars.push_back(llvm::ConstantStruct::get(ObjCTypes.IvarTy, Ivar)); + Ivars.push_back(VMContext.getConstantStruct(ObjCTypes.IvarTy, Ivar)); } // Return null for empty list. @@ -2216,11 +2234,11 @@ llvm::Constant *CGObjCMac::EmitIvarList(const ObjCImplementationDecl *ID, return VMContext.getNullValue(ObjCTypes.IvarListPtrTy); std::vector<llvm::Constant*> Values(2); - Values[0] = llvm::ConstantInt::get(ObjCTypes.IntTy, Ivars.size()); - llvm::ArrayType *AT = llvm::ArrayType::get(ObjCTypes.IvarTy, + Values[0] = VMContext.getConstantInt(ObjCTypes.IntTy, Ivars.size()); + llvm::ArrayType *AT = VMContext.getArrayType(ObjCTypes.IvarTy, Ivars.size()); - Values[1] = llvm::ConstantArray::get(AT, Ivars); - llvm::Constant *Init = llvm::ConstantStruct::get(Values); + Values[1] = VMContext.getConstantArray(AT, Ivars); + llvm::Constant *Init = VMContext.getConstantStruct(Values); llvm::GlobalVariable *GV; if (ForClass) @@ -2232,7 +2250,7 @@ llvm::Constant *CGObjCMac::EmitIvarList(const ObjCImplementationDecl *ID, + ID->getNameAsString(), Init, "__OBJC,__instance_vars,regular,no_dead_strip", 4, true); - return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.IvarListPtrTy); + return VMContext.getConstantExprBitCast(GV, ObjCTypes.IvarListPtrTy); } /* @@ -2260,11 +2278,11 @@ llvm::Constant *CGObjCMac::GetMethodConstant(const ObjCMethodDecl *MD) { std::vector<llvm::Constant*> Method(3); Method[0] = - llvm::ConstantExpr::getBitCast(GetMethodVarName(MD->getSelector()), + VMContext.getConstantExprBitCast(GetMethodVarName(MD->getSelector()), ObjCTypes.SelectorPtrTy); Method[1] = GetMethodVarType(MD); - Method[2] = llvm::ConstantExpr::getBitCast(Fn, ObjCTypes.Int8PtrTy); - return llvm::ConstantStruct::get(ObjCTypes.MethodTy, Method); + Method[2] = VMContext.getConstantExprBitCast(Fn, ObjCTypes.Int8PtrTy); + return VMContext.getConstantStruct(ObjCTypes.MethodTy, Method); } llvm::Constant *CGObjCMac::EmitMethodList(const std::string &Name, @@ -2276,14 +2294,14 @@ llvm::Constant *CGObjCMac::EmitMethodList(const std::string &Name, std::vector<llvm::Constant*> Values(3); Values[0] = VMContext.getNullValue(ObjCTypes.Int8PtrTy); - Values[1] = llvm::ConstantInt::get(ObjCTypes.IntTy, Methods.size()); - llvm::ArrayType *AT = llvm::ArrayType::get(ObjCTypes.MethodTy, + Values[1] = VMContext.getConstantInt(ObjCTypes.IntTy, Methods.size()); + llvm::ArrayType *AT = VMContext.getArrayType(ObjCTypes.MethodTy, Methods.size()); - Values[2] = llvm::ConstantArray::get(AT, Methods); - llvm::Constant *Init = llvm::ConstantStruct::get(Values); + Values[2] = VMContext.getConstantArray(AT, Methods); + llvm::Constant *Init = VMContext.getConstantStruct(Values); llvm::GlobalVariable *GV = CreateMetadataVar(Name, Init, Section, 4, true); - return llvm::ConstantExpr::getBitCast(GV, + return VMContext.getConstantExprBitCast(GV, ObjCTypes.MethodListPtrTy); } @@ -2468,7 +2486,7 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF, "_rethrow"); llvm::Value *CallTryExitPtr = CGF.CreateTempAlloca(llvm::Type::Int1Ty, "_call_try_exit"); - CGF.Builder.CreateStore(llvm::ConstantInt::getTrue(), CallTryExitPtr); + CGF.Builder.CreateStore(VMContext.getConstantIntTrue(), CallTryExitPtr); // Enter a new try block and call setjmp. CGF.Builder.CreateCall(ObjCTypes.getExceptionTryEnterFn(), ExceptionData); @@ -2501,7 +2519,7 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF, if (!isTry) { CGF.Builder.CreateStore(Caught, RethrowPtr); - CGF.Builder.CreateStore(llvm::ConstantInt::getFalse(), CallTryExitPtr); + CGF.Builder.CreateStore(VMContext.getConstantIntFalse(), CallTryExitPtr); CGF.EmitBranchThroughCleanup(FinallyRethrow); } else if (const ObjCAtCatchStmt* CatchStmt = @@ -2602,11 +2620,11 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF, CGF.Builder.CreateCall(ObjCTypes.getExceptionExtractFn(), ExceptionData), RethrowPtr); - CGF.Builder.CreateStore(llvm::ConstantInt::getFalse(), CallTryExitPtr); + CGF.Builder.CreateStore(VMContext.getConstantIntFalse(), CallTryExitPtr); CGF.EmitBranchThroughCleanup(FinallyRethrow); } else { CGF.Builder.CreateStore(Caught, RethrowPtr); - CGF.Builder.CreateStore(llvm::ConstantInt::getFalse(), CallTryExitPtr); + CGF.Builder.CreateStore(VMContext.getConstantIntFalse(), CallTryExitPtr); CGF.EmitBranchThroughCleanup(FinallyRethrow); } @@ -2777,7 +2795,7 @@ void CGObjCMac::EmitGCMemmoveCollectable(CodeGen::CodeGenFunction &CGF, unsigned long size) { SrcPtr = CGF.Builder.CreateBitCast(SrcPtr, ObjCTypes.Int8PtrTy); DestPtr = CGF.Builder.CreateBitCast(DestPtr, ObjCTypes.Int8PtrTy); - llvm::Value *N = llvm::ConstantInt::get(ObjCTypes.LongTy, size); + llvm::Value *N = VMContext.getConstantInt(ObjCTypes.LongTy, size); CGF.Builder.CreateCall3(ObjCTypes.GcMemmoveCollectableFn(), DestPtr, SrcPtr, N); return; @@ -2799,7 +2817,7 @@ llvm::Value *CGObjCMac::EmitIvarOffset(CodeGen::CodeGenFunction &CGF, const ObjCInterfaceDecl *Interface, const ObjCIvarDecl *Ivar) { uint64_t Offset = ComputeIvarBaseOffset(CGM, Interface, Ivar); - return llvm::ConstantInt::get( + return VMContext.getConstantInt( CGM.getTypes().ConvertType(CGM.getContext().LongTy), Offset); } @@ -2841,10 +2859,10 @@ void CGObjCMac::EmitImageInfo() { // Emitted as int[2]; llvm::Constant *values[2] = { - llvm::ConstantInt::get(llvm::Type::Int32Ty, version), - llvm::ConstantInt::get(llvm::Type::Int32Ty, flags) + VMContext.getConstantInt(llvm::Type::Int32Ty, version), + VMContext.getConstantInt(llvm::Type::Int32Ty, flags) }; - llvm::ArrayType *AT = llvm::ArrayType::get(llvm::Type::Int32Ty, 2); + llvm::ArrayType *AT = VMContext.getArrayType(llvm::Type::Int32Ty, 2); const char *Section; if (ObjCABI == 1) @@ -2853,7 +2871,7 @@ void CGObjCMac::EmitImageInfo() { Section = "__DATA, __objc_imageinfo, regular, no_dead_strip"; llvm::GlobalVariable *GV = CreateMetadataVar("\01L_OBJC_IMAGE_INFO", - llvm::ConstantArray::get(AT, values, 2), + VMContext.getConstantArray(AT, values, 2), Section, 0, true); @@ -2875,13 +2893,13 @@ void CGObjCMac::EmitModuleInfo() { uint64_t Size = CGM.getTargetData().getTypeAllocSize(ObjCTypes.ModuleTy); std::vector<llvm::Constant*> Values(4); - Values[0] = llvm::ConstantInt::get(ObjCTypes.LongTy, ModuleVersion); - Values[1] = llvm::ConstantInt::get(ObjCTypes.LongTy, Size); + Values[0] = VMContext.getConstantInt(ObjCTypes.LongTy, ModuleVersion); + Values[1] = VMContext.getConstantInt(ObjCTypes.LongTy, Size); // This used to be the filename, now it is unused. <rdr://4327263> Values[2] = GetClassName(&CGM.getContext().Idents.get("")); Values[3] = EmitModuleSymbols(); CreateMetadataVar("\01L_OBJC_MODULES", - llvm::ConstantStruct::get(ObjCTypes.ModuleTy, Values), + VMContext.getConstantStruct(ObjCTypes.ModuleTy, Values), "__OBJC,__module_info,regular,no_dead_strip", 4, true); } @@ -2895,34 +2913,34 @@ llvm::Constant *CGObjCMac::EmitModuleSymbols() { return VMContext.getNullValue(ObjCTypes.SymtabPtrTy); std::vector<llvm::Constant*> Values(5); - Values[0] = llvm::ConstantInt::get(ObjCTypes.LongTy, 0); + Values[0] = VMContext.getConstantInt(ObjCTypes.LongTy, 0); Values[1] = VMContext.getNullValue(ObjCTypes.SelectorPtrTy); - Values[2] = llvm::ConstantInt::get(ObjCTypes.ShortTy, NumClasses); - Values[3] = llvm::ConstantInt::get(ObjCTypes.ShortTy, NumCategories); + Values[2] = VMContext.getConstantInt(ObjCTypes.ShortTy, NumClasses); + Values[3] = VMContext.getConstantInt(ObjCTypes.ShortTy, NumCategories); // The runtime expects exactly the list of defined classes followed // by the list of defined categories, in a single array. std::vector<llvm::Constant*> Symbols(NumClasses + NumCategories); for (unsigned i=0; i<NumClasses; i++) - Symbols[i] = llvm::ConstantExpr::getBitCast(DefinedClasses[i], + Symbols[i] = VMContext.getConstantExprBitCast(DefinedClasses[i], ObjCTypes.Int8PtrTy); for (unsigned i=0; i<NumCategories; i++) Symbols[NumClasses + i] = - llvm::ConstantExpr::getBitCast(DefinedCategories[i], + VMContext.getConstantExprBitCast(DefinedCategories[i], ObjCTypes.Int8PtrTy); Values[4] = - llvm::ConstantArray::get(llvm::ArrayType::get(ObjCTypes.Int8PtrTy, + VMContext.getConstantArray(VMContext.getArrayType(ObjCTypes.Int8PtrTy, NumClasses + NumCategories), Symbols); - llvm::Constant *Init = llvm::ConstantStruct::get(Values); + llvm::Constant *Init = VMContext.getConstantStruct(Values); llvm::GlobalVariable *GV = CreateMetadataVar("\01L_OBJC_SYMBOLS", Init, "__OBJC,__symbols,regular,no_dead_strip", 4, true); - return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.SymtabPtrTy); + return VMContext.getConstantExprBitCast(GV, ObjCTypes.SymtabPtrTy); } llvm::Value *CGObjCMac::EmitClassRef(CGBuilderTy &Builder, @@ -2933,7 +2951,7 @@ llvm::Value *CGObjCMac::EmitClassRef(CGBuilderTy &Builder, if (!Entry) { llvm::Constant *Casted = - llvm::ConstantExpr::getBitCast(GetClassName(ID->getIdentifier()), + VMContext.getConstantExprBitCast(GetClassName(ID->getIdentifier()), ObjCTypes.ClassPtrTy); Entry = CreateMetadataVar("\01L_OBJC_CLASS_REFERENCES_", Casted, @@ -2949,7 +2967,7 @@ llvm::Value *CGObjCMac::EmitSelector(CGBuilderTy &Builder, Selector Sel) { if (!Entry) { llvm::Constant *Casted = - llvm::ConstantExpr::getBitCast(GetMethodVarName(Sel), + VMContext.getConstantExprBitCast(GetMethodVarName(Sel), ObjCTypes.SelectorPtrTy); Entry = CreateMetadataVar("\01L_OBJC_SELECTOR_REFERENCES_", Casted, @@ -2965,11 +2983,11 @@ llvm::Constant *CGObjCCommonMac::GetClassName(IdentifierInfo *Ident) { if (!Entry) Entry = CreateMetadataVar("\01L_OBJC_CLASS_NAME_", - llvm::ConstantArray::get(Ident->getName()), + VMContext.getConstantArray(Ident->getName()), "__TEXT,__cstring,cstring_literals", 1, true); - return getConstantGEP(Entry, 0, 0); + return getC |