From 0b2397132efe74ee11c1b371dd9033820c54240f Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 6 Feb 2012 22:16:34 +0000 Subject: [PATCH] use cheaper llvm APIs for various bits of IR generation. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149916 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGObjCMac.cpp | 26 +++++++++----------------- lib/CodeGen/CodeGenModule.cpp | 31 ++++++++++++++----------------- lib/CodeGen/CodeGenModule.h | 5 ----- 3 files changed, 23 insertions(+), 39 deletions(-) diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index 2ea7e92e8e..827055de4d 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/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 Symbols(NumClasses + NumCategories); + SmallVector Symbols(NumClasses + NumCategories); for (unsigned i=0; i Symbols(NumClasses); + SmallVector Symbols(NumClasses); for (unsigned i=0; i Ctors; + SmallVector Ctors; for (CtorList::const_iterator I = Fns.begin(), E = Fns.end(); I != E; ++I) { - std::vector 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 UsedArray; + SmallVector UsedArray; UsedArray.resize(LLVMUsed.size()); for (unsigned i = 0, e = LLVMUsed.size(); i != e; ++i) { UsedArray[i] = llvm::ConstantExpr::getBitCast(cast(&*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(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/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h index ca096c1019..fb22bebac8 100644 --- a/lib/CodeGen/CodeGenModule.h +++ b/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);