diff options
author | rdivacky <rdivacky@FreeBSD.org> | 2009-10-14 17:57:32 +0000 |
---|---|---|
committer | rdivacky <rdivacky@FreeBSD.org> | 2009-10-14 17:57:32 +0000 |
commit | cd749a9c07f1de2fb8affde90537efa4bc3e7c54 (patch) | |
tree | b21f6de4e08b89bb7931806bab798fc2a5e3a686 /include/llvm/Support/TypeBuilder.h | |
parent | 72621d11de5b873f1695f391eb95f0b336c3d2d4 (diff) | |
download | FreeBSD-src-cd749a9c07f1de2fb8affde90537efa4bc3e7c54.zip FreeBSD-src-cd749a9c07f1de2fb8affde90537efa4bc3e7c54.tar.gz |
Update llvm to r84119.
Diffstat (limited to 'include/llvm/Support/TypeBuilder.h')
-rw-r--r-- | include/llvm/Support/TypeBuilder.h | 259 |
1 files changed, 92 insertions, 167 deletions
diff --git a/include/llvm/Support/TypeBuilder.h b/include/llvm/Support/TypeBuilder.h index b0ae516..fb22e3f 100644 --- a/include/llvm/Support/TypeBuilder.h +++ b/include/llvm/Support/TypeBuilder.h @@ -16,6 +16,7 @@ #define LLVM_SUPPORT_TYPEBUILDER_H #include "llvm/DerivedTypes.h" +#include "llvm/LLVMContext.h" #include <limits.h> namespace llvm { @@ -49,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 @@ -71,9 +71,6 @@ 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. @@ -104,10 +101,8 @@ template<typename T, bool cross> class TypeBuilder<const volatile T, cross> // Pointers template<typename T, bool cross> class TypeBuilder<T*, cross> { public: - static const PointerType *get() { - static const PointerType *const result = - PointerType::getUnqual(TypeBuilder<T,cross>::get()); - return result; + static const PointerType *get(LLVMContext &Context) { + return PointerType::getUnqual(TypeBuilder<T,cross>::get(Context)); } }; @@ -117,19 +112,15 @@ template<typename T, bool cross> class TypeBuilder<T&, cross> {}; // Arrays template<typename T, size_t N, bool cross> class TypeBuilder<T[N], cross> { public: - static const ArrayType *get() { - static const ArrayType *const result = - ArrayType::get(TypeBuilder<T, cross>::get(), N); - return result; + static const ArrayType *get(LLVMContext &Context) { + 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() { - static const ArrayType *const result = - ArrayType::get(TypeBuilder<T, cross>::get(), 0); - return result; + static const ArrayType *get(LLVMContext &Context) { + return ArrayType::get(TypeBuilder<T, cross>::get(Context), 0); } }; @@ -158,10 +149,8 @@ public: #define DEFINE_INTEGRAL_TYPEBUILDER(T) \ template<> class TypeBuilder<T, false> { \ public: \ - static const IntegerType *get() { \ - static const IntegerType *const result = \ - IntegerType::get(sizeof(T) * CHAR_BIT); \ - return result; \ + static const IntegerType *get(LLVMContext &Context) { \ + return IntegerType::get(Context, sizeof(T) * CHAR_BIT); \ } \ }; \ template<> class TypeBuilder<T, true> { \ @@ -189,53 +178,52 @@ 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() { - static const IntegerType *const result = IntegerType::get(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() { - 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() { - 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() { 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() { 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() { 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() { 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() { return Type::PPC_FP128Ty; } + static const Type *get(LLVMContext& C) { return Type::getPPC_FP128Ty(C); } }; template<bool cross> class TypeBuilder<void, cross> { public: - static const Type *get() { - return Type::VoidTy; + static const Type *get(LLVMContext &C) { + return Type::getVoidTy(C); } }; @@ -246,64 +234,43 @@ template<> class TypeBuilder<void*, false> template<typename R, bool cross> class TypeBuilder<R(), cross> { public: - static const FunctionType *get() { - static const FunctionType *const result = create(); - return result; - } - -private: - static const FunctionType *create() { - return FunctionType::get(TypeBuilder<R, cross>::get(), false); + static const FunctionType *get(LLVMContext &Context) { + 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() { - static const FunctionType *const result = create(); - return result; - } - -private: - static const FunctionType *create() { + static const FunctionType *get(LLVMContext &Context) { std::vector<const Type*> params; params.reserve(1); - params.push_back(TypeBuilder<A1, cross>::get()); - return FunctionType::get(TypeBuilder<R, cross>::get(), params, false); + params.push_back(TypeBuilder<A1, cross>::get(Context)); + return FunctionType::get(TypeBuilder<R, cross>::get(Context), + params, false); } }; template<typename R, typename A1, typename A2, bool cross> class TypeBuilder<R(A1, A2), cross> { public: - static const FunctionType *get() { - static const FunctionType *const result = create(); - return result; - } - -private: - static const FunctionType *create() { + static const FunctionType *get(LLVMContext &Context) { std::vector<const Type*> params; params.reserve(2); - params.push_back(TypeBuilder<A1, cross>::get()); - params.push_back(TypeBuilder<A2, cross>::get()); - return FunctionType::get(TypeBuilder<R, cross>::get(), params, false); + params.push_back(TypeBuilder<A1, cross>::get(Context)); + params.push_back(TypeBuilder<A2, cross>::get(Context)); + return FunctionType::get(TypeBuilder<R, cross>::get(Context), + params, false); } }; template<typename R, typename A1, typename A2, typename A3, bool cross> class TypeBuilder<R(A1, A2, A3), cross> { public: - static const FunctionType *get() { - static const FunctionType *const result = create(); - return result; - } - -private: - static const FunctionType *create() { + static const FunctionType *get(LLVMContext &Context) { std::vector<const Type*> params; params.reserve(3); - params.push_back(TypeBuilder<A1, cross>::get()); - params.push_back(TypeBuilder<A2, cross>::get()); - params.push_back(TypeBuilder<A3, cross>::get()); - return FunctionType::get(TypeBuilder<R, cross>::get(), params, false); + 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 FunctionType::get(TypeBuilder<R, cross>::get(Context), + params, false); } }; @@ -311,20 +278,15 @@ template<typename R, typename A1, typename A2, typename A3, typename A4, bool cross> class TypeBuilder<R(A1, A2, A3, A4), cross> { public: - static const FunctionType *get() { - static const FunctionType *const result = create(); - return result; - } - -private: - static const FunctionType *create() { + static const FunctionType *get(LLVMContext &Context) { std::vector<const Type*> params; params.reserve(4); - params.push_back(TypeBuilder<A1, cross>::get()); - params.push_back(TypeBuilder<A2, cross>::get()); - params.push_back(TypeBuilder<A3, cross>::get()); - params.push_back(TypeBuilder<A4, cross>::get()); - return FunctionType::get(TypeBuilder<R, cross>::get(), params, false); + 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 FunctionType::get(TypeBuilder<R, cross>::get(Context), + params, false); } }; @@ -332,85 +294,58 @@ template<typename R, typename A1, typename A2, typename A3, typename A4, typename A5, bool cross> class TypeBuilder<R(A1, A2, A3, A4, A5), cross> { public: - static const FunctionType *get() { - static const FunctionType *const result = create(); - return result; - } - -private: - static const FunctionType *create() { + static const FunctionType *get(LLVMContext &Context) { std::vector<const Type*> params; params.reserve(5); - params.push_back(TypeBuilder<A1, cross>::get()); - params.push_back(TypeBuilder<A2, cross>::get()); - params.push_back(TypeBuilder<A3, cross>::get()); - params.push_back(TypeBuilder<A4, cross>::get()); - params.push_back(TypeBuilder<A5, cross>::get()); - return FunctionType::get(TypeBuilder<R, cross>::get(), params, false); + 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)); + params.push_back(TypeBuilder<A5, cross>::get(Context)); + return FunctionType::get(TypeBuilder<R, cross>::get(Context), + params, false); } }; template<typename R, bool cross> class TypeBuilder<R(...), cross> { public: - static const FunctionType *get() { - static const FunctionType *const result = create(); - return result; - } - -private: - static const FunctionType *create() { - return FunctionType::get(TypeBuilder<R, cross>::get(), true); + static const FunctionType *get(LLVMContext &Context) { + 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() { - static const FunctionType *const result = create(); - return result; - } - -private: - static const FunctionType *create() { + static const FunctionType *get(LLVMContext &Context) { std::vector<const Type*> params; params.reserve(1); - params.push_back(TypeBuilder<A1, cross>::get()); - return FunctionType::get(TypeBuilder<R, cross>::get(), params, true); + params.push_back(TypeBuilder<A1, cross>::get(Context)); + 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() { - static const FunctionType *const result = create(); - return result; - } - -private: - static const FunctionType *create() { + static const FunctionType *get(LLVMContext &Context) { std::vector<const Type*> params; params.reserve(2); - params.push_back(TypeBuilder<A1, cross>::get()); - params.push_back(TypeBuilder<A2, cross>::get()); - return FunctionType::get(TypeBuilder<R, cross>::get(), params, true); + params.push_back(TypeBuilder<A1, cross>::get(Context)); + params.push_back(TypeBuilder<A2, cross>::get(Context)); + return FunctionType::get(TypeBuilder<R, cross>::get(Context), + params, true); } }; template<typename R, typename A1, typename A2, typename A3, bool cross> class TypeBuilder<R(A1, A2, A3, ...), cross> { public: - static const FunctionType *get() { - static const FunctionType *const result = create(); - return result; - } - -private: - static const FunctionType *create() { + static const FunctionType *get(LLVMContext &Context) { std::vector<const Type*> params; params.reserve(3); - params.push_back(TypeBuilder<A1, cross>::get()); - params.push_back(TypeBuilder<A2, cross>::get()); - params.push_back(TypeBuilder<A3, cross>::get()); - return FunctionType::get(TypeBuilder<R, cross>::get(), params, true); + 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 FunctionType::get(TypeBuilder<R, cross>::get(Context), + params, true); } }; @@ -418,20 +353,15 @@ template<typename R, typename A1, typename A2, typename A3, typename A4, bool cross> class TypeBuilder<R(A1, A2, A3, A4, ...), cross> { public: - static const FunctionType *get() { - static const FunctionType *const result = create(); - return result; - } - -private: - static const FunctionType *create() { + static const FunctionType *get(LLVMContext &Context) { std::vector<const Type*> params; params.reserve(4); - params.push_back(TypeBuilder<A1, cross>::get()); - params.push_back(TypeBuilder<A2, cross>::get()); - params.push_back(TypeBuilder<A3, cross>::get()); - params.push_back(TypeBuilder<A4, cross>::get()); - return FunctionType::get(TypeBuilder<R, cross>::get(), params, true); + 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 FunctionType::get(TypeBuilder<R, cross>::get(Context), + params, true); } }; @@ -439,21 +369,16 @@ template<typename R, typename A1, typename A2, typename A3, typename A4, typename A5, bool cross> class TypeBuilder<R(A1, A2, A3, A4, A5, ...), cross> { public: - static const FunctionType *get() { - static const FunctionType *const result = create(); - return result; - } - -private: - static const FunctionType *create() { + static const FunctionType *get(LLVMContext &Context) { std::vector<const Type*> params; params.reserve(5); - params.push_back(TypeBuilder<A1, cross>::get()); - params.push_back(TypeBuilder<A2, cross>::get()); - params.push_back(TypeBuilder<A3, cross>::get()); - params.push_back(TypeBuilder<A4, cross>::get()); - params.push_back(TypeBuilder<A5, cross>::get()); - return FunctionType::get(TypeBuilder<R, cross>::get(), params, true); + 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)); + params.push_back(TypeBuilder<A5, cross>::get(Context)); + return FunctionType::get(TypeBuilder<R, cross>::get(Context), + params, true); } }; |