Fix Whitespace.
[oota-llvm.git] / include / llvm / Support / TypeBuilder.h
index 5ea7f9ebcf3cfde5954bc5958877fade7e2f31e1..ea63da00edcdb417dcd529a2aa27c26b993d7cc4 100644 (file)
@@ -50,15 +50,14 @@ namespace llvm {
 ///   namespace llvm {
 ///   template<bool xcompile> class TypeBuilder<MyType, xcompile> {
 ///   public:
-///     static const StructType *get() {
-///       // Using the static result variable ensures that the type is
-///       // only looked up once.
-///       static const StructType *const result = StructType::get(
-///         TypeBuilder<types::i<32>, xcompile>::get(),
-///         TypeBuilder<types::i<32>*, xcompile>::get(),
-///         TypeBuilder<types::i<8>*[], xcompile>::get(),
+///     static const StructType *get(LLVMContext &Context) {
+///       // If you cache this result, be sure to cache it separately
+///       // for each LLVMContext.
+///       return StructType::get(
+///         TypeBuilder<types::i<32>, xcompile>::get(Context),
+///         TypeBuilder<types::i<32>*, xcompile>::get(Context),
+///         TypeBuilder<types::i<8>*[], xcompile>::get(Context),
 ///         NULL);
-///       return result;
 ///     }
 ///
 ///     // You may find this a convenient place to put some constants
@@ -72,12 +71,9 @@ namespace llvm {
 ///   }
 ///   }  // namespace llvm
 ///
-/// Using the static result variable ensures that the type is only looked up
-/// once.
-///
 /// TypeBuilder cannot handle recursive types or types you only know at runtime.
 /// If you try to give it a recursive type, it will deadlock, infinitely
-/// recurse, or throw a recursive_init exception.
+/// recurse, or do something similarly undesirable.
 template<typename T, bool cross_compilable> class TypeBuilder {};
 
 // Types for use with cross-compilable TypeBuilders.  These correspond
@@ -92,6 +88,8 @@ class ieee_double {};
 class x86_fp80 {};
 class fp128 {};
 class ppc_fp128 {};
+// X86 MMX.
+class x86_mmx {};
 }  // namespace types
 
 // LLVM doesn't have const or volatile types.
@@ -106,9 +104,7 @@ template<typename T, bool cross> class TypeBuilder<const volatile T, cross>
 template<typename T, bool cross> class TypeBuilder<T*, cross> {
 public:
   static const PointerType *get(LLVMContext &Context) {
-    static const PointerType *const result =
-      Context.getPointerTypeUnqual(TypeBuilder<T,cross>::get(Context));
-    return result;
+    return PointerType::getUnqual(TypeBuilder<T,cross>::get(Context));
   }
 };
 
@@ -119,18 +115,14 @@ template<typename T, bool cross> class TypeBuilder<T&, cross> {};
 template<typename T, size_t N, bool cross> class TypeBuilder<T[N], cross> {
 public:
   static const ArrayType *get(LLVMContext &Context) {
-    static const ArrayType *const result =
-      Context.getArrayType(TypeBuilder<T, cross>::get(Context), N);
-    return result;
+    return ArrayType::get(TypeBuilder<T, cross>::get(Context), N);
   }
 };
 /// LLVM uses an array of length 0 to represent an unknown-length array.
 template<typename T, bool cross> class TypeBuilder<T[], cross> {
 public:
   static const ArrayType *get(LLVMContext &Context) {
-    static const ArrayType *const result =
-      Context.getArrayType(TypeBuilder<T, cross>::get(Context), 0);
-    return result;
+    return ArrayType::get(TypeBuilder<T, cross>::get(Context), 0);
   }
 };
 
@@ -160,9 +152,7 @@ public:
 template<> class TypeBuilder<T, false> { \
 public: \
   static const IntegerType *get(LLVMContext &Context) { \
-    static const IntegerType *const result = \
-      Context.getIntegerType(sizeof(T) * CHAR_BIT); \
-    return result; \
+    return IntegerType::get(Context, sizeof(T) * CHAR_BIT); \
   } \
 }; \
 template<> class TypeBuilder<T, true> { \
@@ -190,53 +180,56 @@ DEFINE_INTEGRAL_TYPEBUILDER(unsigned long long);
 template<uint32_t num_bits, bool cross>
 class TypeBuilder<types::i<num_bits>, cross> {
 public:
-  static const IntegerType *get(LLVMContext &Context) {
-    static const IntegerType *const result = Context.getIntegerType(num_bits);
-    return result;
+  static const IntegerType *get(LLVMContext &C) {
+    return IntegerType::get(C, num_bits);
   }
 };
 
 template<> class TypeBuilder<float, false> {
 public:
-  static const Type *get(LLVMContext&) {
-    return Type::FloatTy;
+  static const Type *get(LLVMContext& C) {
+    return Type::getFloatTy(C);
   }
 };
 template<> class TypeBuilder<float, true> {};
 
 template<> class TypeBuilder<double, false> {
 public:
-  static const Type *get(LLVMContext&) {
-    return Type::DoubleTy;
+  static const Type *get(LLVMContext& C) {
+    return Type::getDoubleTy(C);
   }
 };
 template<> class TypeBuilder<double, true> {};
 
 template<bool cross> class TypeBuilder<types::ieee_float, cross> {
 public:
-  static const Type *get(LLVMContext&) { return Type::FloatTy; }
+  static const Type *get(LLVMContext& C) { return Type::getFloatTy(C); }
 };
 template<bool cross> class TypeBuilder<types::ieee_double, cross> {
 public:
-  static const Type *get(LLVMContext&) { return Type::DoubleTy; }
+  static const Type *get(LLVMContext& C) { return Type::getDoubleTy(C); }
 };
 template<bool cross> class TypeBuilder<types::x86_fp80, cross> {
 public:
-  static const Type *get(LLVMContext&) { return Type::X86_FP80Ty; }
+  static const Type *get(LLVMContext& C) { return Type::getX86_FP80Ty(C); }
 };
 template<bool cross> class TypeBuilder<types::fp128, cross> {
 public:
-  static const Type *get(LLVMContext&) { return Type::FP128Ty; }
+  static const Type *get(LLVMContext& C) { return Type::getFP128Ty(C); }
 };
 template<bool cross> class TypeBuilder<types::ppc_fp128, cross> {
 public:
-  static const Type *get(LLVMContext&) { return Type::PPC_FP128Ty; }
+  static const Type *get(LLVMContext& C) { return Type::getPPC_FP128Ty(C); }
+};
+template<bool cross> class TypeBuilder<types::x86_mmx, cross> {
+public:
+  static const Type *get(LLVMContext& C) { return Type::getX86_MMXTy(C); }
 };
 
 template<bool cross> class TypeBuilder<void, cross> {
 public:
-  static const Type *get(LLVMContext&) {
-    return Type::VoidTy;
+  static const Type *get(LLVMContext &C) {
+    return Type::getVoidTy(C);
   }
 };
 
@@ -244,32 +237,26 @@ public:
 /// we special case it.
 template<> class TypeBuilder<void*, false>
   : public TypeBuilder<types::i<8>*, false> {};
+template<> class TypeBuilder<const void*, false>
+  : public TypeBuilder<types::i<8>*, false> {};
+template<> class TypeBuilder<volatile void*, false>
+  : public TypeBuilder<types::i<8>*, false> {};
+template<> class TypeBuilder<const volatile void*, false>
+  : public TypeBuilder<types::i<8>*, false> {};
 
 template<typename R, bool cross> class TypeBuilder<R(), cross> {
 public:
   static const FunctionType *get(LLVMContext &Context) {
-    static const FunctionType *const result = create(Context);
-    return result;
-  }
-
-private:
-  static const FunctionType *create(LLVMContext &Context) {
-    return Context.getFunctionType(TypeBuilder<R, cross>::get(Context), false);
+    return FunctionType::get(TypeBuilder<R, cross>::get(Context), false);
   }
 };
 template<typename R, typename A1, bool cross> class TypeBuilder<R(A1), cross> {
 public:
   static const FunctionType *get(LLVMContext &Context) {
-    static const FunctionType *const result = create(Context);
-    return result;
-  }
-
-private:
-  static const FunctionType *create(LLVMContext &Context) {
     std::vector<const Type*> params;
     params.reserve(1);
     params.push_back(TypeBuilder<A1, cross>::get(Context));
-    return Context.getFunctionType(TypeBuilder<R, cross>::get(Context),
+    return FunctionType::get(TypeBuilder<R, cross>::get(Context),
                              params, false);
   }
 };
@@ -277,17 +264,11 @@ template<typename R, typename A1, typename A2, bool cross>
 class TypeBuilder<R(A1, A2), cross> {
 public:
   static const FunctionType *get(LLVMContext &Context) {
-    static const FunctionType *const result = create(Context);
-    return result;
-  }
-
-private:
-  static const FunctionType *create(LLVMContext &Context) {
     std::vector<const Type*> params;
     params.reserve(2);
     params.push_back(TypeBuilder<A1, cross>::get(Context));
     params.push_back(TypeBuilder<A2, cross>::get(Context));
-    return Context.getFunctionType(TypeBuilder<R, cross>::get(Context),
+    return FunctionType::get(TypeBuilder<R, cross>::get(Context),
                              params, false);
   }
 };
@@ -295,18 +276,12 @@ template<typename R, typename A1, typename A2, typename A3, bool cross>
 class TypeBuilder<R(A1, A2, A3), cross> {
 public:
   static const FunctionType *get(LLVMContext &Context) {
-    static const FunctionType *const result = create(Context);
-    return result;
-  }
-
-private:
-  static const FunctionType *create(LLVMContext &Context) {
     std::vector<const Type*> params;
     params.reserve(3);
     params.push_back(TypeBuilder<A1, cross>::get(Context));
     params.push_back(TypeBuilder<A2, cross>::get(Context));
     params.push_back(TypeBuilder<A3, cross>::get(Context));
-    return Context.getFunctionType(TypeBuilder<R, cross>::get(Context),
+    return FunctionType::get(TypeBuilder<R, cross>::get(Context),
                              params, false);
   }
 };
@@ -316,19 +291,13 @@ template<typename R, typename A1, typename A2, typename A3, typename A4,
 class TypeBuilder<R(A1, A2, A3, A4), cross> {
 public:
   static const FunctionType *get(LLVMContext &Context) {
-    static const FunctionType *const result = create(Context);
-    return result;
-  }
-
-private:
-  static const FunctionType *create(LLVMContext &Context) {
     std::vector<const Type*> params;
     params.reserve(4);
     params.push_back(TypeBuilder<A1, cross>::get(Context));
     params.push_back(TypeBuilder<A2, cross>::get(Context));
     params.push_back(TypeBuilder<A3, cross>::get(Context));
     params.push_back(TypeBuilder<A4, cross>::get(Context));
-    return Context.getFunctionType(TypeBuilder<R, cross>::get(Context),
+    return FunctionType::get(TypeBuilder<R, cross>::get(Context),
                              params, false);
   }
 };
@@ -338,12 +307,6 @@ template<typename R, typename A1, typename A2, typename A3, typename A4,
 class TypeBuilder<R(A1, A2, A3, A4, A5), cross> {
 public:
   static const FunctionType *get(LLVMContext &Context) {
-    static const FunctionType *const result = create(Context);
-    return result;
-  }
-
-private:
-  static const FunctionType *create(LLVMContext &Context) {
     std::vector<const Type*> params;
     params.reserve(5);
     params.push_back(TypeBuilder<A1, cross>::get(Context));
@@ -351,7 +314,7 @@ private:
     params.push_back(TypeBuilder<A3, cross>::get(Context));
     params.push_back(TypeBuilder<A4, cross>::get(Context));
     params.push_back(TypeBuilder<A5, cross>::get(Context));
-    return Context.getFunctionType(TypeBuilder<R, cross>::get(Context),
+    return FunctionType::get(TypeBuilder<R, cross>::get(Context),
                              params, false);
   }
 };
@@ -359,47 +322,28 @@ private:
 template<typename R, bool cross> class TypeBuilder<R(...), cross> {
 public:
   static const FunctionType *get(LLVMContext &Context) {
-    static const FunctionType *const result = create(Context);
-    return result;
-  }
-
-private:
-  static const FunctionType *create(LLVMContext &Context) {
-    return Context.getFunctionType(TypeBuilder<R, cross>::get(Context), true);
+    return FunctionType::get(TypeBuilder<R, cross>::get(Context), true);
   }
 };
 template<typename R, typename A1, bool cross>
 class TypeBuilder<R(A1, ...), cross> {
 public:
   static const FunctionType *get(LLVMContext &Context) {
-    static const FunctionType *const result = create(Context);
-    return result;
-  }
-
-private:
-  static const FunctionType *create(LLVMContext &Context) {
     std::vector<const Type*> params;
     params.reserve(1);
     params.push_back(TypeBuilder<A1, cross>::get(Context));
-    return Context.getFunctionType(TypeBuilder<R, cross>::get(Context),
-                                   params, true);
+    return FunctionType::get(TypeBuilder<R, cross>::get(Context), params, true);
   }
 };
 template<typename R, typename A1, typename A2, bool cross>
 class TypeBuilder<R(A1, A2, ...), cross> {
 public:
   static const FunctionType *get(LLVMContext &Context) {
-    static const FunctionType *const result = create(Context);
-    return result;
-  }
-
-private:
-  static const FunctionType *create(LLVMContext &Context) {
     std::vector<const Type*> params;
     params.reserve(2);
     params.push_back(TypeBuilder<A1, cross>::get(Context));
     params.push_back(TypeBuilder<A2, cross>::get(Context));
-    return Context.getFunctionType(TypeBuilder<R, cross>::get(Context),
+    return FunctionType::get(TypeBuilder<R, cross>::get(Context),
                                    params, true);
   }
 };
@@ -407,18 +351,12 @@ template<typename R, typename A1, typename A2, typename A3, bool cross>
 class TypeBuilder<R(A1, A2, A3, ...), cross> {
 public:
   static const FunctionType *get(LLVMContext &Context) {
-    static const FunctionType *const result = create(Context);
-    return result;
-  }
-
-private:
-  static const FunctionType *create(LLVMContext &Context) {
     std::vector<const Type*> params;
     params.reserve(3);
     params.push_back(TypeBuilder<A1, cross>::get(Context));
     params.push_back(TypeBuilder<A2, cross>::get(Context));
     params.push_back(TypeBuilder<A3, cross>::get(Context));
-    return Context.getFunctionType(TypeBuilder<R, cross>::get(Context),
+    return FunctionType::get(TypeBuilder<R, cross>::get(Context),
                                    params, true);
   }
 };
@@ -428,19 +366,13 @@ template<typename R, typename A1, typename A2, typename A3, typename A4,
 class TypeBuilder<R(A1, A2, A3, A4, ...), cross> {
 public:
   static const FunctionType *get(LLVMContext &Context) {
-    static const FunctionType *const result = create(Context);
-    return result;
-  }
-
-private:
-  static const FunctionType *create(LLVMContext &Context) {
     std::vector<const Type*> params;
     params.reserve(4);
     params.push_back(TypeBuilder<A1, cross>::get(Context));
     params.push_back(TypeBuilder<A2, cross>::get(Context));
     params.push_back(TypeBuilder<A3, cross>::get(Context));
     params.push_back(TypeBuilder<A4, cross>::get(Context));
-    return Context.getFunctionType(TypeBuilder<R, cross>::get(Context),
+    return FunctionType::get(TypeBuilder<R, cross>::get(Context),
                              params, true);
   }
 };
@@ -450,12 +382,6 @@ template<typename R, typename A1, typename A2, typename A3, typename A4,
 class TypeBuilder<R(A1, A2, A3, A4, A5, ...), cross> {
 public:
   static const FunctionType *get(LLVMContext &Context) {
-    static const FunctionType *const result = create(Context);
-    return result;
-  }
-
-private:
-  static const FunctionType *create(LLVMContext &Context) {
     std::vector<const Type*> params;
     params.reserve(5);
     params.push_back(TypeBuilder<A1, cross>::get(Context));
@@ -463,7 +389,7 @@ private:
     params.push_back(TypeBuilder<A3, cross>::get(Context));
     params.push_back(TypeBuilder<A4, cross>::get(Context));
     params.push_back(TypeBuilder<A5, cross>::get(Context));
-    return Context.getFunctionType(TypeBuilder<R, cross>::get(Context),
+    return FunctionType::get(TypeBuilder<R, cross>::get(Context),
                                    params, true);
   }
 };