diff options
author | Chris Lattner <sabre@nondot.org> | 2011-06-20 04:01:35 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2011-06-20 04:01:35 +0000 |
commit | c5cbb909e8a27deb8f1a2b6b7bf56a96051af81a (patch) | |
tree | 5a0169f89009c342c414e5a8ade283beb57c3b98 /lib/CodeGen | |
parent | 8cc2491239f0b9de35985a1650fffc05c1ca8242 (diff) |
Update to match mainline ConstantStruct::get API change. Also, use
ConvertType on InitListExprs as they are being converted. This is
needed for a forthcoming patch, and improves the IR generated anyway
(see additional type names in testcases).
This patch also converts a bunch of std::vector's in CGObjCMac to use
C arrays. There are a ton more that should be converted as well.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133413 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/CGBlocks.cpp | 8 | ||||
-rw-r--r-- | lib/CodeGen/CGExprConstant.cpp | 24 | ||||
-rw-r--r-- | lib/CodeGen/CGObjCGNU.cpp | 6 | ||||
-rw-r--r-- | lib/CodeGen/CGObjCMac.cpp | 64 | ||||
-rw-r--r-- | lib/CodeGen/CGRTTI.cpp | 4 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenModule.cpp | 4 | ||||
-rw-r--r-- | lib/CodeGen/ItaniumCXXABI.cpp | 9 |
7 files changed, 60 insertions, 59 deletions
diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp index 8fb6e3ed71..a0a8d667df 100644 --- a/lib/CodeGen/CGBlocks.cpp +++ b/lib/CodeGen/CGBlocks.cpp @@ -95,9 +95,7 @@ static llvm::Constant *buildBlockDescriptor(CodeGenModule &CGM, else elements.push_back(llvm::Constant::getNullValue(i8p)); - llvm::Constant *init = - llvm::ConstantStruct::get(CGM.getLLVMContext(), elements.data(), - elements.size(), false); + llvm::Constant *init = llvm::ConstantStruct::getAnon(elements); llvm::GlobalVariable *global = new llvm::GlobalVariable(CGM.getModule(), init->getType(), true, @@ -851,9 +849,7 @@ static llvm::Constant *buildGlobalBlock(CodeGenModule &CGM, // Descriptor fields[4] = buildBlockDescriptor(CGM, blockInfo); - llvm::Constant *init = - llvm::ConstantStruct::get(CGM.getLLVMContext(), fields, BlockHeaderSize, - /*packed*/ false); + llvm::Constant *init = llvm::ConstantStruct::getAnon(fields); llvm::GlobalVariable *literal = new llvm::GlobalVariable(CGM.getModule(), diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 75e566110c..5184f47537 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -433,9 +433,19 @@ llvm::Constant *ConstStructBuilder:: if (!Builder.Build(ILE)) return 0; + // Pick the type to use. If the type is layout identical to the ConvertType + // type then use it, otherwise use whatever the builder produced for us. + const llvm::StructType *STy = + llvm::ConstantStruct::getTypeForElements(CGM.getLLVMContext(), + Builder.Elements,Builder.Packed); + const llvm::Type *ILETy = CGM.getTypes().ConvertType(ILE->getType()); + if (const llvm::StructType *ILESTy = dyn_cast<llvm::StructType>(ILETy)) { + if (ILESTy->isLayoutIdentical(STy)) + STy = ILESTy; + } + llvm::Constant *Result = - llvm::ConstantStruct::get(CGM.getLLVMContext(), - Builder.Elements, Builder.Packed); + llvm::ConstantStruct::get(STy, Builder.Elements); assert(Builder.NextFieldOffsetInChars.RoundUpToAlignment( Builder.getAlignment(Result)) == @@ -988,7 +998,10 @@ llvm::Constant *CodeGenModule::EmitConstantExpr(const Expr *E, Result.Val.getComplexIntImag()); // FIXME: the target may want to specify that this is packed. - return llvm::ConstantStruct::get(VMContext, Complex, 2, false); + llvm::StructType *STy = llvm::StructType::get(Complex[0]->getType(), + Complex[1]->getType(), + NULL); + return llvm::ConstantStruct::get(STy, Complex); } case APValue::Float: return llvm::ConstantFP::get(VMContext, Result.Val.getFloat()); @@ -1001,7 +1014,10 @@ llvm::Constant *CodeGenModule::EmitConstantExpr(const Expr *E, Result.Val.getComplexFloatImag()); // FIXME: the target may want to specify that this is packed. - return llvm::ConstantStruct::get(VMContext, Complex, 2, false); + llvm::StructType *STy = llvm::StructType::get(Complex[0]->getType(), + Complex[1]->getType(), + NULL); + return llvm::ConstantStruct::get(STy, Complex); } case APValue::Vector: { llvm::SmallVector<llvm::Constant *, 4> Inits; diff --git a/lib/CodeGen/CGObjCGNU.cpp b/lib/CodeGen/CGObjCGNU.cpp index ce8123d016..6a711bff55 100644 --- a/lib/CodeGen/CGObjCGNU.cpp +++ b/lib/CodeGen/CGObjCGNU.cpp @@ -1573,7 +1573,7 @@ void CGObjCGNU::GenerateProtocol(const ObjCProtocolDecl *PD) { {llvm::ConstantInt::get(IntTy, Properties.size()), NULLPtr, PropertyArray}; llvm::Constant *PropertyListInit = - llvm::ConstantStruct::get(VMContext, PropertyListInitFields, 3, false); + llvm::ConstantStruct::getAnon(PropertyListInitFields); llvm::Constant *PropertyList = new llvm::GlobalVariable(TheModule, PropertyListInit->getType(), false, llvm::GlobalValue::InternalLinkage, PropertyListInit, ".objc_property_list"); @@ -1586,7 +1586,7 @@ void CGObjCGNU::GenerateProtocol(const ObjCProtocolDecl *PD) { OptionalPropertyArray }; llvm::Constant *OptionalPropertyListInit = - llvm::ConstantStruct::get(VMContext, OptionalPropertyListInitFields, 3, false); + llvm::ConstantStruct::getAnon(OptionalPropertyListInitFields); llvm::Constant *OptionalPropertyList = new llvm::GlobalVariable(TheModule, OptionalPropertyListInit->getType(), false, llvm::GlobalValue::InternalLinkage, OptionalPropertyListInit, @@ -1788,7 +1788,7 @@ llvm::Constant *CGObjCGNU::GeneratePropertyList(const ObjCImplementationDecl *OI {llvm::ConstantInt::get(IntTy, Properties.size()), NULLPtr, PropertyArray}; llvm::Constant *PropertyListInit = - llvm::ConstantStruct::get(VMContext, PropertyListInitFields, 3, false); + llvm::ConstantStruct::getAnon(PropertyListInitFields); return new llvm::GlobalVariable(TheModule, PropertyListInit->getType(), false, llvm::GlobalValue::InternalLinkage, PropertyListInit, ".objc_property_list"); diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index 0458e37518..721ab3e6ba 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -1880,7 +1880,7 @@ CGObjCMac::EmitProtocolList(llvm::Twine Name, // This list is null terminated. ProtocolRefs.push_back(llvm::Constant::getNullValue(ObjCTypes.ProtocolPtrTy)); - std::vector<llvm::Constant*> Values(3); + llvm::Constant *Values[3]; // This field is only used by the runtime. Values[0] = llvm::Constant::getNullValue(ObjCTypes.ProtocolListPtrTy); Values[1] = llvm::ConstantInt::get(ObjCTypes.LongTy, @@ -1890,7 +1890,7 @@ CGObjCMac::EmitProtocolList(llvm::Twine Name, ProtocolRefs.size()), ProtocolRefs); - llvm::Constant *Init = llvm::ConstantStruct::get(VMContext, Values, false); + llvm::Constant *Init = llvm::ConstantStruct::getAnon(Values); llvm::GlobalVariable *GV = CreateMetadataVar(Name, Init, "__OBJC,__cat_cls_meth,regular,no_dead_strip", 4, false); @@ -1964,13 +1964,13 @@ llvm::Constant *CGObjCCommonMac::EmitPropertyList(llvm::Twine Name, unsigned PropertySize = CGM.getTargetData().getTypeAllocSize(ObjCTypes.PropertyTy); - std::vector<llvm::Constant*> Values(3); + 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, Properties.size()); Values[2] = llvm::ConstantArray::get(AT, Properties); - llvm::Constant *Init = llvm::ConstantStruct::get(VMContext, Values, false); + llvm::Constant *Init = llvm::ConstantStruct::getAnon(Values); llvm::GlobalVariable *GV = CreateMetadataVar(Name, Init, @@ -2008,12 +2008,12 @@ llvm::Constant *CGObjCMac::EmitMethodDescList(llvm::Twine Name, if (Methods.empty()) return llvm::Constant::getNullValue(ObjCTypes.MethodDescriptionListPtrTy); - std::vector<llvm::Constant*> Values(2); + llvm::Constant *Values[2]; Values[0] = llvm::ConstantInt::get(ObjCTypes.IntTy, Methods.size()); llvm::ArrayType *AT = llvm::ArrayType::get(ObjCTypes.MethodDescriptionTy, Methods.size()); Values[1] = llvm::ConstantArray::get(AT, Methods); - llvm::Constant *Init = llvm::ConstantStruct::get(VMContext, Values, false); + llvm::Constant *Init = llvm::ConstantStruct::getAnon(Values); llvm::GlobalVariable *GV = CreateMetadataVar(Name, Init, Section, 4, true); return llvm::ConstantExpr::getBitCast(GV, @@ -2058,7 +2058,7 @@ void CGObjCMac::GenerateCategory(const ObjCCategoryImplDecl *OCD) { ClassMethods.push_back(GetMethodConstant(*i)); } - std::vector<llvm::Constant*> Values(7); + llvm::Constant *Values[7]; Values[0] = GetClassName(OCD->getIdentifier()); Values[1] = GetClassName(Interface->getIdentifier()); LazySymbols.insert(Interface->getIdentifier()); @@ -2180,7 +2180,7 @@ void CGObjCMac::GenerateClass(const ObjCImplementationDecl *ID) { } } - std::vector<llvm::Constant*> Values(12); + llvm::Constant *Values[12]; Values[ 0] = EmitMetaClass(ID, Protocols, ClassMethods); if (ObjCInterfaceDecl *Super = Interface->getSuperClass()) { // Record a reference to the super class. @@ -2239,7 +2239,7 @@ llvm::Constant *CGObjCMac::EmitMetaClass(const ObjCImplementationDecl *ID, if (ID->getClassInterface()->getVisibility() == HiddenVisibility) Flags |= eClassFlags_Hidden; - std::vector<llvm::Constant*> Values(12); + llvm::Constant *Values[12]; // The isa for the metaclass is the root of the hierarchy. const ObjCInterfaceDecl *Root = ID->getClassInterface(); while (const ObjCInterfaceDecl *Super = Root->getSuperClass()) @@ -2353,7 +2353,7 @@ CGObjCMac::EmitClassExtension(const ObjCImplementationDecl *ID) { uint64_t Size = CGM.getTargetData().getTypeAllocSize(ObjCTypes.ClassExtensionTy); - std::vector<llvm::Constant*> Values(3); + llvm::Constant *Values[3]; Values[0] = llvm::ConstantInt::get(ObjCTypes.IntTy, Size); Values[1] = BuildIvarLayout(ID, false); Values[2] = EmitPropertyList("\01l_OBJC_$_PROP_LIST_" + ID->getName(), @@ -2416,12 +2416,12 @@ llvm::Constant *CGObjCMac::EmitIvarList(const ObjCImplementationDecl *ID, if (Ivars.empty()) return llvm::Constant::getNullValue(ObjCTypes.IvarListPtrTy); - std::vector<llvm::Constant*> Values(2); + llvm::Constant *Values[2]; Values[0] = llvm::ConstantInt::get(ObjCTypes.IntTy, Ivars.size()); llvm::ArrayType *AT = llvm::ArrayType::get(ObjCTypes.IvarTy, Ivars.size()); Values[1] = llvm::ConstantArray::get(AT, Ivars); - llvm::Constant *Init = llvm::ConstantStruct::get(VMContext, Values, false); + llvm::Constant *Init = llvm::ConstantStruct::getAnon(Values); llvm::GlobalVariable *GV; if (ForClass) @@ -2473,17 +2473,16 @@ llvm::Constant *CGObjCMac::EmitMethodList(llvm::Twine Name, if (Methods.empty()) return llvm::Constant::getNullValue(ObjCTypes.MethodListPtrTy); - std::vector<llvm::Constant*> Values(3); + llvm::Constant *Values[3]; Values[0] = llvm::Constant::getNullValue(ObjCTypes.Int8PtrTy); Values[1] = llvm::ConstantInt::get(ObjCTypes.IntTy, Methods.size()); llvm::ArrayType *AT = llvm::ArrayType::get(ObjCTypes.MethodTy, Methods.size()); Values[2] = llvm::ConstantArray::get(AT, Methods); - llvm::Constant *Init = llvm::ConstantStruct::get(VMContext, Values, false); + llvm::Constant *Init = llvm::ConstantStruct::getAnon(Values); llvm::GlobalVariable *GV = CreateMetadataVar(Name, Init, Section, 4, true); - return llvm::ConstantExpr::getBitCast(GV, - ObjCTypes.MethodListPtrTy); + return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.MethodListPtrTy); } llvm::Function *CGObjCCommonMac::GenerateMethod(const ObjCMethodDecl *OMD, @@ -3444,7 +3443,7 @@ llvm::Constant *CGObjCMac::EmitModuleSymbols() { if (!NumClasses && !NumCategories) return llvm::Constant::getNullValue(ObjCTypes.SymtabPtrTy); - std::vector<llvm::Constant*> Values(5); + llvm::Constant *Values[5]; Values[0] = llvm::ConstantInt::get(ObjCTypes.LongTy, 0); Values[1] = llvm::Constant::getNullValue(ObjCTypes.SelectorPtrTy); Values[2] = llvm::ConstantInt::get(ObjCTypes.ShortTy, NumClasses); @@ -3466,7 +3465,7 @@ llvm::Constant *CGObjCMac::EmitModuleSymbols() { NumClasses + NumCategories), Symbols); - llvm::Constant *Init = llvm::ConstantStruct::get(VMContext, Values, false); + llvm::Constant *Init = llvm::ConstantStruct::getAnon(Values); llvm::GlobalVariable *GV = CreateMetadataVar("\01L_OBJC_SYMBOLS", Init, @@ -5180,7 +5179,7 @@ llvm::Constant *CGObjCNonFragileABIMac::EmitMethodList(llvm::Twine Name, if (Methods.empty()) return llvm::Constant::getNullValue(ObjCTypes.MethodListnfABIPtrTy); - std::vector<llvm::Constant*> Values(3); + llvm::Constant *Values[3]; // sizeof(struct _objc_method) unsigned Size = CGM.getTargetData().getTypeAllocSize(ObjCTypes.MethodTy); Values[0] = llvm::ConstantInt::get(ObjCTypes.IntTy, Size); @@ -5189,19 +5188,15 @@ llvm::Constant *CGObjCNonFragileABIMac::EmitMethodList(llvm::Twine Name, llvm::ArrayType *AT = llvm::ArrayType::get(ObjCTypes.MethodTy, Methods.size()); Values[2] = llvm::ConstantArray::get(AT, Methods); - llvm::Constant *Init = llvm::ConstantStruct::get(VMContext, Values, false); + llvm::Constant *Init = llvm::ConstantStruct::getAnon(Values); llvm::GlobalVariable *GV = new llvm::GlobalVariable(CGM.getModule(), Init->getType(), false, - llvm::GlobalValue::InternalLinkage, - Init, - Name); - GV->setAlignment( - CGM.getTargetData().getABITypeAlignment(Init->getType())); + llvm::GlobalValue::InternalLinkage, Init, Name); + GV->setAlignment(CGM.getTargetData().getABITypeAlignment(Init->getType())); GV->setSection(Section); CGM.AddUsedGlobal(GV); - return llvm::ConstantExpr::getBitCast(GV, - ObjCTypes.MethodListnfABIPtrTy); + return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.MethodListnfABIPtrTy); } /// ObjCIvarOffsetVariable - Returns the ivar offset variable for @@ -5304,14 +5299,15 @@ llvm::Constant *CGObjCNonFragileABIMac::EmitIvarList( // Return null for empty list. if (Ivars.empty()) return llvm::Constant::getNullValue(ObjCTypes.IvarListnfABIPtrTy); - std::vector<llvm::Constant*> Values(3); + + llvm::Constant *Values[3]; unsigned Size = CGM.getTargetData().getTypeAllocSize(ObjCTypes.IvarnfABITy); Values[0] = llvm::ConstantInt::get(ObjCTypes.IntTy, Size); Values[1] = llvm::ConstantInt::get(ObjCTypes.IntTy, Ivars.size()); llvm::ArrayType *AT = llvm::ArrayType::get(ObjCTypes.IvarnfABITy, Ivars.size()); Values[2] = llvm::ConstantArray::get(AT, Ivars); - llvm::Constant *Init = llvm::ConstantStruct::get(VMContext, Values, false); + llvm::Constant *Init = llvm::ConstantStruct::getAnon(Values); const char *Prefix = "\01l_OBJC_$_INSTANCE_VARIABLES_"; llvm::GlobalVariable *GV = new llvm::GlobalVariable(CGM.getModule(), Init->getType(), false, @@ -5497,7 +5493,7 @@ CGObjCNonFragileABIMac::EmitProtocolList(llvm::Twine Name, ProtocolRefs.push_back(llvm::Constant::getNullValue( ObjCTypes.ProtocolnfABIPtrTy)); - std::vector<llvm::Constant*> Values(2); + llvm::Constant *Values[2]; Values[0] = llvm::ConstantInt::get(ObjCTypes.LongTy, ProtocolRefs.size() - 1); Values[1] = @@ -5506,11 +5502,10 @@ CGObjCNonFragileABIMac::EmitProtocolList(llvm::Twine Name, ProtocolRefs.size()), ProtocolRefs); - llvm::Constant *Init = llvm::ConstantStruct::get(VMContext, Values, false); + llvm::Constant *Init = llvm::ConstantStruct::getAnon(Values); GV = new llvm::GlobalVariable(CGM.getModule(), Init->getType(), false, llvm::GlobalValue::InternalLinkage, - Init, - Name); + Init, Name); GV->setSection("__DATA, __objc_const"); GV->setAlignment( CGM.getTargetData().getABITypeAlignment(Init->getType())); @@ -5660,8 +5655,7 @@ CGObjCNonFragileABIMac::EmitVTableMessageSend(CodeGenFunction &CGF, if (!messageRef) { // Build the message ref structure. llvm::Constant *values[] = { fn, GetMethodVarName(selector) }; - llvm::Constant *init = - llvm::ConstantStruct::get(VMContext, values, 2, false); + llvm::Constant *init = llvm::ConstantStruct::getAnon(values); messageRef = new llvm::GlobalVariable(CGM.getModule(), init->getType(), /*constant*/ false, diff --git a/lib/CodeGen/CGRTTI.cpp b/lib/CodeGen/CGRTTI.cpp index c73b199e31..e564c70705 100644 --- a/lib/CodeGen/CGRTTI.cpp +++ b/lib/CodeGen/CGRTTI.cpp @@ -658,9 +658,7 @@ llvm::Constant *RTTIBuilder::BuildTypeInfo(QualType Ty, bool Force) { break; } - llvm::Constant *Init = - llvm::ConstantStruct::get(VMContext, &Fields[0], Fields.size(), - /*Packed=*/false); + llvm::Constant *Init = llvm::ConstantStruct::getAnon(Fields); llvm::GlobalVariable *GV = new llvm::GlobalVariable(CGM.getModule(), Init->getType(), diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index b9c829364f..57b4f7f2ae 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -353,7 +353,7 @@ void CodeGenModule::EmitCtorList(const CtorList &Fns, const char *GlobalName) { llvm::Type *CtorPFTy = llvm::PointerType::getUnqual(CtorFTy); // Get the type of a ctor entry, { i32, void ()* }. - llvm::StructType* CtorStructTy = + llvm::StructType *CtorStructTy = llvm::StructType::get(llvm::Type::getInt32Ty(VMContext), llvm::PointerType::getUnqual(CtorFTy), NULL); @@ -676,7 +676,7 @@ llvm::Constant *CodeGenModule::EmitAnnotateAttr(llvm::GlobalValue *GV, llvm::ConstantExpr::getBitCast(unitGV, SBP), llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), LineNo) }; - return llvm::ConstantStruct::get(VMContext, Fields, 4, false); + return llvm::ConstantStruct::getAnon(Fields); } bool CodeGenModule::MayDeferGeneration(const ValueDecl *Global) { diff --git a/lib/CodeGen/ItaniumCXXABI.cpp b/lib/CodeGen/ItaniumCXXABI.cpp index 77320c7c05..9edd793873 100644 --- a/lib/CodeGen/ItaniumCXXABI.cpp +++ b/lib/CodeGen/ItaniumCXXABI.cpp @@ -472,8 +472,7 @@ ItaniumCXXABI::EmitMemberPointerConversion(llvm::Constant *C, else Values[1] = llvm::ConstantExpr::getAdd(CS->getOperand(1), Offset); - return llvm::ConstantStruct::get(CGM.getLLVMContext(), Values, 2, - /*Packed=*/false); + return llvm::ConstantStruct::get(CS->getType(), Values); } @@ -488,8 +487,7 @@ ItaniumCXXABI::EmitNullMemberPointer(const MemberPointerType *MPT) { llvm::Constant *Zero = llvm::ConstantInt::get(ptrdiff_t, 0); llvm::Constant *Values[2] = { Zero, Zero }; - return llvm::ConstantStruct::get(CGM.getLLVMContext(), Values, 2, - /*Packed=*/false); + return llvm::ConstantStruct::getAnon(Values); } llvm::Constant * @@ -554,8 +552,7 @@ llvm::Constant *ItaniumCXXABI::EmitMemberPointer(const CXXMethodDecl *MD) { MemPtr[1] = llvm::ConstantInt::get(ptrdiff_t, 0); } - return llvm::ConstantStruct::get(CGM.getLLVMContext(), - MemPtr, 2, /*Packed=*/false); + return llvm::ConstantStruct::getAnon(MemPtr); } /// The comparison algorithm is pretty easy: the member pointers are |