[cfe-commits] r149916 - in /cfe/trunk/lib/CodeGen: CGObjCMac.cpp CodeGenModule.cpp CodeGenModule.h

Chris Lattner sabre at nondot.org
Mon Feb 6 14:16:35 PST 2012


Author: lattner
Date: Mon Feb  6 16:16:34 2012
New Revision: 149916

URL: http://llvm.org/viewvc/llvm-project?rev=149916&view=rev
Log:
use cheaper llvm APIs for various bits of IR generation.

Modified:
    cfe/trunk/lib/CodeGen/CGObjCMac.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.h

Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=149916&r1=149915&r2=149916&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Mon Feb  6 16:16:34 2012
@@ -3577,14 +3577,8 @@
   // 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 @@
     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 @@
 
   // 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 @@
 
   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::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 @@
   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 =

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=149916&r1=149915&r2=149916&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Feb  6 16:16:34 2012
@@ -383,12 +383,12 @@
                           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 @@
   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 @@
 
 /// 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 Str = E->getString().str();
   Str.resize(RealLen, '\0');
-
   return Str;
 }
 
@@ -2081,10 +2078,10 @@
   
   // 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 @@
   // 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());
   }

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=149916&r1=149915&r2=149916&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Mon Feb  6 16:16:34 2012
@@ -568,11 +568,6 @@
   /// 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);





More information about the cfe-commits mailing list