[llvm-commits] [llvm] r74584 - in /llvm/trunk: examples/ModuleMaker/ModuleMaker.cpp include/llvm/DerivedTypes.h include/llvm/Support/TypeBuilder.h lib/Analysis/DebugInfo.cpp lib/AsmParser/LLParser.cpp lib/Debugger/ProgramInfo.cpp lib/ExecutionEngine/JIT/JIT.cpp lib/Transforms/IPO/GlobalOpt.cpp lib/Transforms/IPO/RaiseAllocations.cpp lib/Transforms/Utils/LowerAllocations.cpp utils/TableGen/IntrinsicEmitter.cpp

Chris Lattner sabre at nondot.org
Tue Jun 30 21:13:33 PDT 2009


Author: lattner
Date: Tue Jun 30 23:13:31 2009
New Revision: 74584

URL: http://llvm.org/viewvc/llvm-project?rev=74584&view=rev
Log:
improve the APIs for creating struct and function types with no arguments/elements
to not have to create a temporary vector (in the API at least).  Patch by Jay Foad!

Modified:
    llvm/trunk/examples/ModuleMaker/ModuleMaker.cpp
    llvm/trunk/include/llvm/DerivedTypes.h
    llvm/trunk/include/llvm/Support/TypeBuilder.h
    llvm/trunk/lib/Analysis/DebugInfo.cpp
    llvm/trunk/lib/AsmParser/LLParser.cpp
    llvm/trunk/lib/Debugger/ProgramInfo.cpp
    llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp
    llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
    llvm/trunk/lib/Transforms/IPO/RaiseAllocations.cpp
    llvm/trunk/lib/Transforms/Utils/LowerAllocations.cpp
    llvm/trunk/utils/TableGen/IntrinsicEmitter.cpp

Modified: llvm/trunk/examples/ModuleMaker/ModuleMaker.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/ModuleMaker/ModuleMaker.cpp?rev=74584&r1=74583&r2=74584&view=diff

==============================================================================
--- llvm/trunk/examples/ModuleMaker/ModuleMaker.cpp (original)
+++ llvm/trunk/examples/ModuleMaker/ModuleMaker.cpp Tue Jun 30 23:13:31 2009
@@ -27,8 +27,7 @@
   Module *M = new Module("test");
 
   // Create the main function: first create the type 'int ()'
-  FunctionType *FT = FunctionType::get(Type::Int32Ty, std::vector<const Type*>(),
-                                       /*not vararg*/false);
+  FunctionType *FT = FunctionType::get(Type::Int32Ty, /*not vararg*/false);
 
   // By passing a module as the last parameter to the Function constructor,
   // it automatically gets appended to the Module.

Modified: llvm/trunk/include/llvm/DerivedTypes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DerivedTypes.h?rev=74584&r1=74583&r2=74584&view=diff

==============================================================================
--- llvm/trunk/include/llvm/DerivedTypes.h (original)
+++ llvm/trunk/include/llvm/DerivedTypes.h Tue Jun 30 23:13:31 2009
@@ -159,6 +159,15 @@
     bool isVarArg  ///< Whether this is a variable argument length function
   );
 
+  /// FunctionType::get - Create a FunctionType taking no parameters.
+  ///
+  static FunctionType *get(
+    const Type *Result, ///< The result type
+    bool isVarArg  ///< Whether this is a variable argument length function
+  ) {
+    return get(Result, std::vector<const Type *>(), isVarArg);
+  }
+
   /// isValidReturnType - Return true if the specified type is valid as a return
   /// type.
   static bool isValidReturnType(const Type *RetTy);
@@ -234,6 +243,12 @@
   static StructType *get(const std::vector<const Type*> &Params,
                          bool isPacked=false);
 
+  /// StructType::get - Create an empty structure type.
+  ///
+  static StructType *get(bool isPacked=false) {
+    return get(std::vector<const Type*>(), isPacked);
+  }
+
   /// StructType::get - This static method is a convenience method for
   /// creating structure types by specifying the elements as arguments.
   /// Note that this method always returns a non-packed struct.  To get

Modified: llvm/trunk/include/llvm/Support/TypeBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/TypeBuilder.h?rev=74584&r1=74583&r2=74584&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/TypeBuilder.h (original)
+++ llvm/trunk/include/llvm/Support/TypeBuilder.h Tue Jun 30 23:13:31 2009
@@ -253,8 +253,7 @@
 
 private:
   static const FunctionType *create() {
-    std::vector<const Type*> params;
-    return FunctionType::get(TypeBuilder<R, cross>::get(), params, false);
+    return FunctionType::get(TypeBuilder<R, cross>::get(), false);
   }
 };
 template<typename R, typename A1, bool cross> class TypeBuilder<R(A1), cross> {
@@ -360,8 +359,7 @@
 
 private:
   static const FunctionType *create() {
-    std::vector<const Type*> params;
-    return FunctionType::get(TypeBuilder<R, cross>::get(), params, true);
+    return FunctionType::get(TypeBuilder<R, cross>::get(), true);
   }
 };
 template<typename R, typename A1, bool cross>

Modified: llvm/trunk/lib/Analysis/DebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/DebugInfo.cpp?rev=74584&r1=74583&r2=74584&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/DebugInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/DebugInfo.cpp Tue Jun 30 23:13:31 2009
@@ -327,7 +327,7 @@
 DIFactory::DIFactory(Module &m)
   : M(m), StopPointFn(0), FuncStartFn(0), RegionStartFn(0), RegionEndFn(0),
     DeclareFn(0) {
-  EmptyStructPtr = PointerType::getUnqual(StructType::get(NULL, NULL));
+  EmptyStructPtr = PointerType::getUnqual(StructType::get());
 }
 
 /// getCastToEmpty - Return this descriptor as a Constant* with type '{}*'.

Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=74584&r1=74583&r2=74584&view=diff

==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Tue Jun 30 23:13:31 2009
@@ -1244,7 +1244,7 @@
   Lex.Lex(); // Consume the '{'
   
   if (EatIfPresent(lltok::rbrace)) {
-    Result = StructType::get(std::vector<const Type*>(), Packed);
+    Result = StructType::get(Packed);
     return false;
   }
 

Modified: llvm/trunk/lib/Debugger/ProgramInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Debugger/ProgramInfo.cpp?rev=74584&r1=74583&r2=74584&view=diff

==============================================================================
--- llvm/trunk/lib/Debugger/ProgramInfo.cpp (original)
+++ llvm/trunk/lib/Debugger/ProgramInfo.cpp Tue Jun 30 23:13:31 2009
@@ -271,8 +271,7 @@
   // should be on the use list of the llvm.dbg.translation_units global.
   //
   GlobalVariable *Units =
-    M->getGlobalVariable("llvm.dbg.translation_units",
-                         StructType::get(std::vector<const Type*>()));
+    M->getGlobalVariable("llvm.dbg.translation_units", StructType::get());
   if (Units == 0)
     throw "Program contains no debugging information!";
 
@@ -354,8 +353,7 @@
   // should be on the use list of the llvm.dbg.translation_units global.
   //
   GlobalVariable *Units =
-    M->getGlobalVariable("llvm.dbg.globals",
-                         StructType::get(std::vector<const Type*>()));
+    M->getGlobalVariable("llvm.dbg.globals", StructType::get());
   if (Units == 0)
     throw "Program contains no debugging information!";
 

Modified: llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp?rev=74584&r1=74583&r2=74584&view=diff

==============================================================================
--- llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp Tue Jun 30 23:13:31 2009
@@ -453,7 +453,7 @@
   // arguments.  Make this function and return.
 
   // First, create the function.
-  FunctionType *STy=FunctionType::get(RetTy, std::vector<const Type*>(), false);
+  FunctionType *STy=FunctionType::get(RetTy, false);
   Function *Stub = Function::Create(STy, Function::InternalLinkage, "",
                                     F->getParent());
 

Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=74584&r1=74583&r2=74584&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Tue Jun 30 23:13:31 2009
@@ -1928,8 +1928,7 @@
     if (Ctors[i]) {
       CSVals[1] = Ctors[i];
     } else {
-      const Type *FTy = FunctionType::get(Type::VoidTy,
-                                          std::vector<const Type*>(), false);
+      const Type *FTy = FunctionType::get(Type::VoidTy, false);
       const PointerType *PFTy = PointerType::getUnqual(FTy);
       CSVals[1] = Constant::getNullValue(PFTy);
       CSVals[0] = ConstantInt::get(Type::Int32Ty, 2147483647);

Modified: llvm/trunk/lib/Transforms/IPO/RaiseAllocations.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/RaiseAllocations.cpp?rev=74584&r1=74583&r2=74584&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/IPO/RaiseAllocations.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/RaiseAllocations.cpp Tue Jun 30 23:13:31 2009
@@ -92,8 +92,7 @@
         // i8*(...) * malloc
         // This handles the common declaration of: 'void *malloc();'
         const FunctionType *Malloc3Type = 
-          FunctionType::get(PointerType::getUnqual(Type::Int8Ty),
-                            std::vector<const Type*>(), true);
+          FunctionType::get(PointerType::getUnqual(Type::Int8Ty), true);
         if (TyWeHave != Malloc3Type)
           // Give up
           MallocFunc = 0;
@@ -113,14 +112,12 @@
       // Check to see if the prototype was forgotten, giving us 
       // void (...) * free
       // This handles the common forward declaration of: 'void free();'
-      const FunctionType* Free2Type = FunctionType::get(Type::VoidTy, 
-        std::vector<const Type*>(),true);
+      const FunctionType* Free2Type = FunctionType::get(Type::VoidTy, true);
 
       if (TyWeHave != Free2Type) {
         // One last try, check to see if we can find free as 
         // int (...)* free.  This handles the case where NOTHING was declared.
-        const FunctionType* Free3Type = FunctionType::get(Type::Int32Ty, 
-          std::vector<const Type*>(),true);
+        const FunctionType* Free3Type = FunctionType::get(Type::Int32Ty, true);
         
         if (TyWeHave != Free3Type) {
           // Give up.

Modified: llvm/trunk/lib/Transforms/Utils/LowerAllocations.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LowerAllocations.cpp?rev=74584&r1=74583&r2=74584&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Utils/LowerAllocations.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/LowerAllocations.cpp Tue Jun 30 23:13:31 2009
@@ -89,7 +89,7 @@
   const Type *BPTy = PointerType::getUnqual(Type::Int8Ty);
   // Prototype malloc as "char* malloc(...)", because we don't know in
   // doInitialization whether size_t is int or long.
-  FunctionType *FT = FunctionType::get(BPTy, std::vector<const Type*>(), true);
+  FunctionType *FT = FunctionType::get(BPTy, true);
   MallocFunc = M.getOrInsertFunction("malloc", FT);
   FreeFunc = M.getOrInsertFunction("free"  , Type::VoidTy, BPTy, (Type *)0);
   return true;

Modified: llvm/trunk/utils/TableGen/IntrinsicEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/IntrinsicEmitter.cpp?rev=74584&r1=74583&r2=74584&view=diff

==============================================================================
--- llvm/trunk/utils/TableGen/IntrinsicEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/IntrinsicEmitter.cpp Tue Jun 30 23:13:31 2009
@@ -146,7 +146,7 @@
     OS << "IntegerType::get(" << BitWidth << ")";
   } else if (VT == MVT::Other) {
     // MVT::OtherVT is used to mean the empty struct type here.
-    OS << "StructType::get(std::vector<const Type *>())";
+    OS << "StructType::get()";
   } else if (VT == MVT::f32) {
     OS << "Type::FloatTy";
   } else if (VT == MVT::f64) {





More information about the llvm-commits mailing list