diff options
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r-- | clang/lib/CodeGen/CGObjCMac.cpp | 26 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 31 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.h | 5 |
3 files changed, 23 insertions, 39 deletions
diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp index 2ea7e92e8e5..827055de4d2 100644 --- a/clang/lib/CodeGen/CGObjCMac.cpp +++ b/clang/lib/CodeGen/CGObjCMac.cpp @@ -3577,14 +3577,8 @@ void CGObjCCommonMac::EmitImageInfo() { // We never allow @synthesize of a superclass property. flags |= eImageInfo_CorrectedSynthesize; - llvm::Type *Int32Ty = llvm::Type::getInt32Ty(VMContext); - // Emitted as int[2]; - llvm::Constant *values[2] = { - llvm::ConstantInt::get(Int32Ty, version), - llvm::ConstantInt::get(Int32Ty, flags) - }; - llvm::ArrayType *AT = llvm::ArrayType::get(Int32Ty, 2); + uint32_t Values[2] = { version, flags }; const char *Section; if (ObjCABI == 1) @@ -3593,10 +3587,8 @@ void CGObjCCommonMac::EmitImageInfo() { Section = "__DATA, __objc_imageinfo, regular, no_dead_strip"; llvm::GlobalVariable *GV = CreateMetadataVar("\01L_OBJC_IMAGE_INFO", - llvm::ConstantArray::get(AT, values), - Section, - 0, - true); + llvm::ConstantDataArray::get(VMContext, Values), + Section, 0, true); GV->setConstant(true); } @@ -3643,7 +3635,7 @@ llvm::Constant *CGObjCMac::EmitModuleSymbols() { // 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); + SmallVector<llvm::Constant*, 8> Symbols(NumClasses + NumCategories); for (unsigned i=0; i<NumClasses; i++) Symbols[i] = llvm::ConstantExpr::getBitCast(DefinedClasses[i], ObjCTypes.Int8PtrTy); @@ -3654,7 +3646,7 @@ llvm::Constant *CGObjCMac::EmitModuleSymbols() { Values[4] = llvm::ConstantArray::get(llvm::ArrayType::get(ObjCTypes.Int8PtrTy, - NumClasses + NumCategories), + Symbols.size()), Symbols); llvm::Constant *Init = llvm::ConstantStruct::getAnon(Values); @@ -4131,7 +4123,7 @@ llvm::Constant *CGObjCCommonMac::BuildIvarLayout( llvm::Constant *CGObjCCommonMac::GetMethodVarName(Selector Sel) { llvm::GlobalVariable *&Entry = MethodVarNames[Sel]; - // FIXME: Avoid std::string copying. + // FIXME: Avoid std::string in "Sel.getAsString()" if (!Entry) Entry = CreateMetadataVar("\01L_OBJC_METH_VAR_NAME_", llvm::ConstantDataArray::getString(VMContext, Sel.getAsString()), @@ -4754,13 +4746,13 @@ void CGObjCNonFragileABIMac::AddModuleClassList(const if (!NumClasses) return; - std::vector<llvm::Constant*> Symbols(NumClasses); + SmallVector<llvm::Constant*, 8> Symbols(NumClasses); for (unsigned i=0; i<NumClasses; i++) Symbols[i] = llvm::ConstantExpr::getBitCast(Container[i], ObjCTypes.Int8PtrTy); - llvm::Constant* Init = + llvm::Constant *Init = llvm::ConstantArray::get(llvm::ArrayType::get(ObjCTypes.Int8PtrTy, - NumClasses), + Symbols.size()), Symbols); llvm::GlobalVariable *GV = diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index af6381b1cfa..5cc4f395e48 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -383,12 +383,12 @@ void CodeGenModule::EmitCtorList(const CtorList &Fns, const char *GlobalName) { llvm::PointerType::getUnqual(CtorFTy), NULL); // Construct the constructor and destructor arrays. - std::vector<llvm::Constant*> Ctors; + SmallVector<llvm::Constant*, 8> Ctors; for (CtorList::const_iterator I = Fns.begin(), E = Fns.end(); I != E; ++I) { - std::vector<llvm::Constant*> S; - S.push_back(llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), - I->second, false)); - S.push_back(llvm::ConstantExpr::getBitCast(I->first, CtorPFTy)); + llvm::Constant *S[] = { + llvm::ConstantInt::get(Int32Ty, I->second, false), + llvm::ConstantExpr::getBitCast(I->first, CtorPFTy) + }; Ctors.push_back(llvm::ConstantStruct::get(CtorStructTy, S)); } @@ -612,20 +612,18 @@ void CodeGenModule::EmitLLVMUsed() { if (LLVMUsed.empty()) return; - llvm::Type *i8PTy = llvm::Type::getInt8PtrTy(VMContext); - // Convert LLVMUsed to what ConstantArray needs. - std::vector<llvm::Constant*> UsedArray; + SmallVector<llvm::Constant*, 8> UsedArray; UsedArray.resize(LLVMUsed.size()); for (unsigned i = 0, e = LLVMUsed.size(); i != e; ++i) { UsedArray[i] = llvm::ConstantExpr::getBitCast(cast<llvm::Constant>(&*LLVMUsed[i]), - i8PTy); + Int8PtrTy); } if (UsedArray.empty()) return; - llvm::ArrayType *ATy = llvm::ArrayType::get(i8PTy, UsedArray.size()); + llvm::ArrayType *ATy = llvm::ArrayType::get(Int8PtrTy, UsedArray.size()); llvm::GlobalVariable *GV = new llvm::GlobalVariable(getModule(), ATy, false, @@ -2058,10 +2056,10 @@ QualType CodeGenModule::getObjCFastEnumerationStateType() { /// GetStringForStringLiteral - Return the appropriate bytes for a /// string literal, properly padded to match the literal type. -std::string CodeGenModule::GetStringForStringLiteral(const StringLiteral *E) { +static std::string GetStringForStringLiteral(const StringLiteral *E, + const ASTContext &Context) { assert((E->isAscii() || E->isUTF8()) && "Use GetConstantArrayFromStringLiteral for wide strings"); - const ASTContext &Context = getContext(); const ConstantArrayType *CAT = Context.getAsConstantArrayType(E->getType()); assert(CAT && "String isn't pointer or array!"); @@ -2071,7 +2069,6 @@ std::string CodeGenModule::GetStringForStringLiteral(const StringLiteral *E) { std::string Str = E->getString().str(); Str.resize(RealLen, '\0'); - return Str; } @@ -2081,10 +2078,10 @@ CodeGenModule::GetConstantArrayFromStringLiteral(const StringLiteral *E) { // Don't emit it as the address of the string, emit the string data itself // as an inline array. - if (E->getCharByteWidth()==1) { + if (E->getCharByteWidth() == 1) return llvm::ConstantDataArray::getString(VMContext, - GetStringForStringLiteral(E), false); - } + GetStringForStringLiteral(E, getContext()), + false); llvm::ArrayType *AType = cast<llvm::ArrayType>(getTypes().ConvertType(E->getType())); @@ -2114,7 +2111,7 @@ CodeGenModule::GetAddrOfConstantStringFromLiteral(const StringLiteral *S) { // FIXME: We shouldn't need to bitcast the constant in the wide string case. CharUnits Align = getContext().getTypeAlignInChars(S->getType()); if (S->isAscii() || S->isUTF8()) { - return GetAddrOfConstantString(GetStringForStringLiteral(S), + return GetAddrOfConstantString(GetStringForStringLiteral(S, getContext()), /* GlobalName */ 0, Align.getQuantity()); } diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index ca096c1019f..fb22bebac87 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -568,11 +568,6 @@ public: /// requires no captures. llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE, const char *); - /// GetStringForStringLiteral - Return the appropriate bytes for a string - /// literal, properly padded to match the literal type. If only the address of - /// a constant is needed consider using GetAddrOfConstantStringLiteral. - std::string GetStringForStringLiteral(const StringLiteral *E); - /// GetAddrOfConstantCFString - Return a pointer to a constant CFString object /// for the given string. llvm::Constant *GetAddrOfConstantCFString(const StringLiteral *Literal); |