From 38f488e46292e38c776dd6ec3e3a0b8c57952fcb Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Sun, 15 Jul 2012 23:45:24 +0000 Subject: Move llvm/Support/TypeBuilder.h -> llvm/TypeBuilder.h. This completes the move of *Builder classes into the Core library. No uses of this builder in Clang or DragonEgg I could find. If there is a desire to have an IR-building-support library that contains all of these builders, that can be easily added, but currently it seems likely that these add no real overhead to VMCore. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160243 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/TypeBuilder.h | 399 --------------------- include/llvm/TypeBuilder.h | 399 +++++++++++++++++++++ lib/Analysis/PathNumbering.cpp | 2 +- lib/Transforms/Instrumentation/PathProfiling.cpp | 2 +- .../ExecutionEngine/JIT/JITEventListenerTest.cpp | 2 +- .../JIT/JITEventListenerTestCommon.h | 2 +- unittests/ExecutionEngine/JIT/JITTest.cpp | 2 +- unittests/Support/CMakeLists.txt | 1 - unittests/Support/TypeBuilderTest.cpp | 254 ------------- unittests/VMCore/CMakeLists.txt | 1 + unittests/VMCore/TypeBuilderTest.cpp | 254 +++++++++++++ 11 files changed, 659 insertions(+), 659 deletions(-) delete mode 100644 include/llvm/Support/TypeBuilder.h create mode 100644 include/llvm/TypeBuilder.h delete mode 100644 unittests/Support/TypeBuilderTest.cpp create mode 100644 unittests/VMCore/TypeBuilderTest.cpp diff --git a/include/llvm/Support/TypeBuilder.h b/include/llvm/Support/TypeBuilder.h deleted file mode 100644 index c756069..0000000 --- a/include/llvm/Support/TypeBuilder.h +++ /dev/null @@ -1,399 +0,0 @@ -//===---- llvm/Support/TypeBuilder.h - Builder for LLVM types ---*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file defines the TypeBuilder class, which is used as a convenient way to -// create LLVM types with a consistent and simplified interface. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_SUPPORT_TYPEBUILDER_H -#define LLVM_SUPPORT_TYPEBUILDER_H - -#include "llvm/DerivedTypes.h" -#include "llvm/LLVMContext.h" -#include - -namespace llvm { - -/// TypeBuilder - This provides a uniform API for looking up types -/// known at compile time. To support cross-compilation, we define a -/// series of tag types in the llvm::types namespace, like i, -/// ieee_float, ppc_fp128, etc. TypeBuilder allows T to be -/// any of these, a native C type (whose size may depend on the host -/// compiler), or a pointer, function, or struct type built out of -/// these. TypeBuilder removes native C types from this set -/// to guarantee that its result is suitable for cross-compilation. -/// We define the primitive types, pointer types, and functions up to -/// 5 arguments here, but to use this class with your own types, -/// you'll need to specialize it. For example, say you want to call a -/// function defined externally as: -/// -/// struct MyType { -/// int32 a; -/// int32 *b; -/// void *array[1]; // Intended as a flexible array. -/// }; -/// int8 AFunction(struct MyType *value); -/// -/// You'll want to use -/// Function::Create(TypeBuilder(MyType*), true>::get(), ...) -/// to declare the function, but when you first try this, your compiler will -/// complain that TypeBuilder::get() doesn't exist. To fix this, -/// write: -/// -/// namespace llvm { -/// template class TypeBuilder { -/// public: -/// static StructType *get(LLVMContext &Context) { -/// // If you cache this result, be sure to cache it separately -/// // for each LLVMContext. -/// return StructType::get( -/// TypeBuilder, xcompile>::get(Context), -/// TypeBuilder*, xcompile>::get(Context), -/// TypeBuilder*[], xcompile>::get(Context), -/// NULL); -/// } -/// -/// // You may find this a convenient place to put some constants -/// // to help with getelementptr. They don't have any effect on -/// // the operation of TypeBuilder. -/// enum Fields { -/// FIELD_A, -/// FIELD_B, -/// FIELD_ARRAY -/// }; -/// } -/// } // namespace llvm -/// -/// 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 do something similarly undesirable. -template class TypeBuilder {}; - -// Types for use with cross-compilable TypeBuilders. These correspond -// exactly with an LLVM-native type. -namespace types { -/// i corresponds to the LLVM IntegerType with N bits. -template class i {}; - -// The following classes represent the LLVM floating types. -class ieee_float {}; -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. -template class TypeBuilder - : public TypeBuilder {}; -template class TypeBuilder - : public TypeBuilder {}; -template class TypeBuilder - : public TypeBuilder {}; - -// Pointers -template class TypeBuilder { -public: - static PointerType *get(LLVMContext &Context) { - return PointerType::getUnqual(TypeBuilder::get(Context)); - } -}; - -/// There is no support for references -template class TypeBuilder {}; - -// Arrays -template class TypeBuilder { -public: - static ArrayType *get(LLVMContext &Context) { - return ArrayType::get(TypeBuilder::get(Context), N); - } -}; -/// LLVM uses an array of length 0 to represent an unknown-length array. -template class TypeBuilder { -public: - static ArrayType *get(LLVMContext &Context) { - return ArrayType::get(TypeBuilder::get(Context), 0); - } -}; - -// Define the C integral types only for TypeBuilder. -// -// C integral types do not have a defined size. It would be nice to use the -// stdint.h-defined typedefs that do have defined sizes, but we'd run into the -// following problem: -// -// On an ILP32 machine, stdint.h might define: -// -// typedef int int32_t; -// typedef long long int64_t; -// typedef long size_t; -// -// If we defined TypeBuilder and TypeBuilder, then any use of -// TypeBuilder would fail. We couldn't define TypeBuilder in -// addition to the defined-size types because we'd get duplicate definitions on -// platforms where stdint.h instead defines: -// -// typedef int int32_t; -// typedef long long int64_t; -// typedef int size_t; -// -// So we define all the primitive C types and nothing else. -#define DEFINE_INTEGRAL_TYPEBUILDER(T) \ -template<> class TypeBuilder { \ -public: \ - static IntegerType *get(LLVMContext &Context) { \ - return IntegerType::get(Context, sizeof(T) * CHAR_BIT); \ - } \ -}; \ -template<> class TypeBuilder { \ - /* We provide a definition here so users don't accidentally */ \ - /* define these types to work. */ \ -} -DEFINE_INTEGRAL_TYPEBUILDER(char); -DEFINE_INTEGRAL_TYPEBUILDER(signed char); -DEFINE_INTEGRAL_TYPEBUILDER(unsigned char); -DEFINE_INTEGRAL_TYPEBUILDER(short); -DEFINE_INTEGRAL_TYPEBUILDER(unsigned short); -DEFINE_INTEGRAL_TYPEBUILDER(int); -DEFINE_INTEGRAL_TYPEBUILDER(unsigned int); -DEFINE_INTEGRAL_TYPEBUILDER(long); -DEFINE_INTEGRAL_TYPEBUILDER(unsigned long); -#ifdef _MSC_VER -DEFINE_INTEGRAL_TYPEBUILDER(__int64); -DEFINE_INTEGRAL_TYPEBUILDER(unsigned __int64); -#else /* _MSC_VER */ -DEFINE_INTEGRAL_TYPEBUILDER(long long); -DEFINE_INTEGRAL_TYPEBUILDER(unsigned long long); -#endif /* _MSC_VER */ -#undef DEFINE_INTEGRAL_TYPEBUILDER - -template -class TypeBuilder, cross> { -public: - static IntegerType *get(LLVMContext &C) { - return IntegerType::get(C, num_bits); - } -}; - -template<> class TypeBuilder { -public: - static Type *get(LLVMContext& C) { - return Type::getFloatTy(C); - } -}; -template<> class TypeBuilder {}; - -template<> class TypeBuilder { -public: - static Type *get(LLVMContext& C) { - return Type::getDoubleTy(C); - } -}; -template<> class TypeBuilder {}; - -template class TypeBuilder { -public: - static Type *get(LLVMContext& C) { return Type::getFloatTy(C); } -}; -template class TypeBuilder { -public: - static Type *get(LLVMContext& C) { return Type::getDoubleTy(C); } -}; -template class TypeBuilder { -public: - static Type *get(LLVMContext& C) { return Type::getX86_FP80Ty(C); } -}; -template class TypeBuilder { -public: - static Type *get(LLVMContext& C) { return Type::getFP128Ty(C); } -}; -template class TypeBuilder { -public: - static Type *get(LLVMContext& C) { return Type::getPPC_FP128Ty(C); } -}; -template class TypeBuilder { -public: - static Type *get(LLVMContext& C) { return Type::getX86_MMXTy(C); } -}; - -template class TypeBuilder { -public: - static Type *get(LLVMContext &C) { - return Type::getVoidTy(C); - } -}; - -/// void* is disallowed in LLVM types, but it occurs often enough in C code that -/// we special case it. -template<> class TypeBuilder - : public TypeBuilder*, false> {}; -template<> class TypeBuilder - : public TypeBuilder*, false> {}; -template<> class TypeBuilder - : public TypeBuilder*, false> {}; -template<> class TypeBuilder - : public TypeBuilder*, false> {}; - -template class TypeBuilder { -public: - static FunctionType *get(LLVMContext &Context) { - return FunctionType::get(TypeBuilder::get(Context), false); - } -}; -template class TypeBuilder { -public: - static FunctionType *get(LLVMContext &Context) { - Type *params[] = { - TypeBuilder::get(Context), - }; - return FunctionType::get(TypeBuilder::get(Context), - params, false); - } -}; -template -class TypeBuilder { -public: - static FunctionType *get(LLVMContext &Context) { - Type *params[] = { - TypeBuilder::get(Context), - TypeBuilder::get(Context), - }; - return FunctionType::get(TypeBuilder::get(Context), - params, false); - } -}; -template -class TypeBuilder { -public: - static FunctionType *get(LLVMContext &Context) { - Type *params[] = { - TypeBuilder::get(Context), - TypeBuilder::get(Context), - TypeBuilder::get(Context), - }; - return FunctionType::get(TypeBuilder::get(Context), - params, false); - } -}; - -template -class TypeBuilder { -public: - static FunctionType *get(LLVMContext &Context) { - Type *params[] = { - TypeBuilder::get(Context), - TypeBuilder::get(Context), - TypeBuilder::get(Context), - TypeBuilder::get(Context), - }; - return FunctionType::get(TypeBuilder::get(Context), - params, false); - } -}; - -template -class TypeBuilder { -public: - static FunctionType *get(LLVMContext &Context) { - Type *params[] = { - TypeBuilder::get(Context), - TypeBuilder::get(Context), - TypeBuilder::get(Context), - TypeBuilder::get(Context), - TypeBuilder::get(Context), - }; - return FunctionType::get(TypeBuilder::get(Context), - params, false); - } -}; - -template class TypeBuilder { -public: - static FunctionType *get(LLVMContext &Context) { - return FunctionType::get(TypeBuilder::get(Context), true); - } -}; -template -class TypeBuilder { -public: - static FunctionType *get(LLVMContext &Context) { - Type *params[] = { - TypeBuilder::get(Context), - }; - return FunctionType::get(TypeBuilder::get(Context), params, true); - } -}; -template -class TypeBuilder { -public: - static FunctionType *get(LLVMContext &Context) { - Type *params[] = { - TypeBuilder::get(Context), - TypeBuilder::get(Context), - }; - return FunctionType::get(TypeBuilder::get(Context), - params, true); - } -}; -template -class TypeBuilder { -public: - static FunctionType *get(LLVMContext &Context) { - Type *params[] = { - TypeBuilder::get(Context), - TypeBuilder::get(Context), - TypeBuilder::get(Context), - }; - return FunctionType::get(TypeBuilder::get(Context), - params, true); - } -}; - -template -class TypeBuilder { -public: - static FunctionType *get(LLVMContext &Context) { - Type *params[] = { - TypeBuilder::get(Context), - TypeBuilder::get(Context), - TypeBuilder::get(Context), - TypeBuilder::get(Context), - }; - return FunctionType::get(TypeBuilder::get(Context), - params, true); - } -}; - -template -class TypeBuilder { -public: - static FunctionType *get(LLVMContext &Context) { - Type *params[] = { - TypeBuilder::get(Context), - TypeBuilder::get(Context), - TypeBuilder::get(Context), - TypeBuilder::get(Context), - TypeBuilder::get(Context), - }; - return FunctionType::get(TypeBuilder::get(Context), - params, true); - } -}; - -} // namespace llvm - -#endif diff --git a/include/llvm/TypeBuilder.h b/include/llvm/TypeBuilder.h new file mode 100644 index 0000000..0b56479 --- /dev/null +++ b/include/llvm/TypeBuilder.h @@ -0,0 +1,399 @@ +//===---- llvm/TypeBuilder.h - Builder for LLVM types -----------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines the TypeBuilder class, which is used as a convenient way to +// create LLVM types with a consistent and simplified interface. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_TYPEBUILDER_H +#define LLVM_TYPEBUILDER_H + +#include "llvm/DerivedTypes.h" +#include "llvm/LLVMContext.h" +#include + +namespace llvm { + +/// TypeBuilder - This provides a uniform API for looking up types +/// known at compile time. To support cross-compilation, we define a +/// series of tag types in the llvm::types namespace, like i, +/// ieee_float, ppc_fp128, etc. TypeBuilder allows T to be +/// any of these, a native C type (whose size may depend on the host +/// compiler), or a pointer, function, or struct type built out of +/// these. TypeBuilder removes native C types from this set +/// to guarantee that its result is suitable for cross-compilation. +/// We define the primitive types, pointer types, and functions up to +/// 5 arguments here, but to use this class with your own types, +/// you'll need to specialize it. For example, say you want to call a +/// function defined externally as: +/// +/// struct MyType { +/// int32 a; +/// int32 *b; +/// void *array[1]; // Intended as a flexible array. +/// }; +/// int8 AFunction(struct MyType *value); +/// +/// You'll want to use +/// Function::Create(TypeBuilder(MyType*), true>::get(), ...) +/// to declare the function, but when you first try this, your compiler will +/// complain that TypeBuilder::get() doesn't exist. To fix this, +/// write: +/// +/// namespace llvm { +/// template class TypeBuilder { +/// public: +/// static StructType *get(LLVMContext &Context) { +/// // If you cache this result, be sure to cache it separately +/// // for each LLVMContext. +/// return StructType::get( +/// TypeBuilder, xcompile>::get(Context), +/// TypeBuilder*, xcompile>::get(Context), +/// TypeBuilder*[], xcompile>::get(Context), +/// NULL); +/// } +/// +/// // You may find this a convenient place to put some constants +/// // to help with getelementptr. They don't have any effect on +/// // the operation of TypeBuilder. +/// enum Fields { +/// FIELD_A, +/// FIELD_B, +/// FIELD_ARRAY +/// }; +/// } +/// } // namespace llvm +/// +/// 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 do something similarly undesirable. +template class TypeBuilder {}; + +// Types for use with cross-compilable TypeBuilders. These correspond +// exactly with an LLVM-native type. +namespace types { +/// i corresponds to the LLVM IntegerType with N bits. +template class i {}; + +// The following classes represent the LLVM floating types. +class ieee_float {}; +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. +template class TypeBuilder + : public TypeBuilder {}; +template class TypeBuilder + : public TypeBuilder {}; +template class TypeBuilder + : public TypeBuilder {}; + +// Pointers +template class TypeBuilder { +public: + static PointerType *get(LLVMContext &Context) { + return PointerType::getUnqual(TypeBuilder::get(Context)); + } +}; + +/// There is no support for references +template class TypeBuilder {}; + +// Arrays +template class TypeBuilder { +public: + static ArrayType *get(LLVMContext &Context) { + return ArrayType::get(TypeBuilder::get(Context), N); + } +}; +/// LLVM uses an array of length 0 to represent an unknown-length array. +template class TypeBuilder { +public: + static ArrayType *get(LLVMContext &Context) { + return ArrayType::get(TypeBuilder::get(Context), 0); + } +}; + +// Define the C integral types only for TypeBuilder. +// +// C integral types do not have a defined size. It would be nice to use the +// stdint.h-defined typedefs that do have defined sizes, but we'd run into the +// following problem: +// +// On an ILP32 machine, stdint.h might define: +// +// typedef int int32_t; +// typedef long long int64_t; +// typedef long size_t; +// +// If we defined TypeBuilder and TypeBuilder, then any use of +// TypeBuilder would fail. We couldn't define TypeBuilder in +// addition to the defined-size types because we'd get duplicate definitions on +// platforms where stdint.h instead defines: +// +// typedef int int32_t; +// typedef long long int64_t; +// typedef int size_t; +// +// So we define all the primitive C types and nothing else. +#define DEFINE_INTEGRAL_TYPEBUILDER(T) \ +template<> class TypeBuilder { \ +public: \ + static IntegerType *get(LLVMContext &Context) { \ + return IntegerType::get(Context, sizeof(T) * CHAR_BIT); \ + } \ +}; \ +template<> class TypeBuilder { \ + /* We provide a definition here so users don't accidentally */ \ + /* define these types to work. */ \ +} +DEFINE_INTEGRAL_TYPEBUILDER(char); +DEFINE_INTEGRAL_TYPEBUILDER(signed char); +DEFINE_INTEGRAL_TYPEBUILDER(unsigned char); +DEFINE_INTEGRAL_TYPEBUILDER(short); +DEFINE_INTEGRAL_TYPEBUILDER(unsigned short); +DEFINE_INTEGRAL_TYPEBUILDER(int); +DEFINE_INTEGRAL_TYPEBUILDER(unsigned int); +DEFINE_INTEGRAL_TYPEBUILDER(long); +DEFINE_INTEGRAL_TYPEBUILDER(unsigned long); +#ifdef _MSC_VER +DEFINE_INTEGRAL_TYPEBUILDER(__int64); +DEFINE_INTEGRAL_TYPEBUILDER(unsigned __int64); +#else /* _MSC_VER */ +DEFINE_INTEGRAL_TYPEBUILDER(long long); +DEFINE_INTEGRAL_TYPEBUILDER(unsigned long long); +#endif /* _MSC_VER */ +#undef DEFINE_INTEGRAL_TYPEBUILDER + +template +class TypeBuilder, cross> { +public: + static IntegerType *get(LLVMContext &C) { + return IntegerType::get(C, num_bits); + } +}; + +template<> class TypeBuilder { +public: + static Type *get(LLVMContext& C) { + return Type::getFloatTy(C); + } +}; +template<> class TypeBuilder {}; + +template<> class TypeBuilder { +public: + static Type *get(LLVMContext& C) { + return Type::getDoubleTy(C); + } +}; +template<> class TypeBuilder {}; + +template class TypeBuilder { +public: + static Type *get(LLVMContext& C) { return Type::getFloatTy(C); } +}; +template class TypeBuilder { +public: + static Type *get(LLVMContext& C) { return Type::getDoubleTy(C); } +}; +template class TypeBuilder { +public: + static Type *get(LLVMContext& C) { return Type::getX86_FP80Ty(C); } +}; +template class TypeBuilder { +public: + static Type *get(LLVMContext& C) { return Type::getFP128Ty(C); } +}; +template class TypeBuilder { +public: + static Type *get(LLVMContext& C) { return Type::getPPC_FP128Ty(C); } +}; +template class TypeBuilder { +public: + static Type *get(LLVMContext& C) { return Type::getX86_MMXTy(C); } +}; + +template class TypeBuilder { +public: + static Type *get(LLVMContext &C) { + return Type::getVoidTy(C); + } +}; + +/// void* is disallowed in LLVM types, but it occurs often enough in C code that +/// we special case it. +template<> class TypeBuilder + : public TypeBuilder*, false> {}; +template<> class TypeBuilder + : public TypeBuilder*, false> {}; +template<> class TypeBuilder + : public TypeBuilder*, false> {}; +template<> class TypeBuilder + : public TypeBuilder*, false> {}; + +template class TypeBuilder { +public: + static FunctionType *get(LLVMContext &Context) { + return FunctionType::get(TypeBuilder::get(Context), false); + } +}; +template class TypeBuilder { +public: + static FunctionType *get(LLVMContext &Context) { + Type *params[] = { + TypeBuilder::get(Context), + }; + return FunctionType::get(TypeBuilder::get(Context), + params, false); + } +}; +template +class TypeBuilder { +public: + static FunctionType *get(LLVMContext &Context) { + Type *params[] = { + TypeBuilder::get(Context), + TypeBuilder::get(Context), + }; + return FunctionType::get(TypeBuilder::get(Context), + params, false); + } +}; +template +class TypeBuilder { +public: + static FunctionType *get(LLVMContext &Context) { + Type *params[] = { + TypeBuilder::get(Context), + TypeBuilder::get(Context), + TypeBuilder::get(Context), + }; + return FunctionType::get(TypeBuilder::get(Context), + params, false); + } +}; + +template +class TypeBuilder { +public: + static FunctionType *get(LLVMContext &Context) { + Type *params[] = { + TypeBuilder::get(Context), + TypeBuilder::get(Context), + TypeBuilder::get(Context), + TypeBuilder::get(Context), + }; + return FunctionType::get(TypeBuilder::get(Context), + params, false); + } +}; + +template +class TypeBuilder { +public: + static FunctionType *get(LLVMContext &Context) { + Type *params[] = { + TypeBuilder::get(Context), + TypeBuilder::get(Context), + TypeBuilder::get(Context), + TypeBuilder::get(Context), + TypeBuilder::get(Context), + }; + return FunctionType::get(TypeBuilder::get(Context), + params, false); + } +}; + +template class TypeBuilder { +public: + static FunctionType *get(LLVMContext &Context) { + return FunctionType::get(TypeBuilder::get(Context), true); + } +}; +template +class TypeBuilder { +public: + static FunctionType *get(LLVMContext &Context) { + Type *params[] = { + TypeBuilder::get(Context), + }; + return FunctionType::get(TypeBuilder::get(Context), params, true); + } +}; +template +class TypeBuilder { +public: + static FunctionType *get(LLVMContext &Context) { + Type *params[] = { + TypeBuilder::get(Context), + TypeBuilder::get(Context), + }; + return FunctionType::get(TypeBuilder::get(Context), + params, true); + } +}; +template +class TypeBuilder { +public: + static FunctionType *get(LLVMContext &Context) { + Type *params[] = { + TypeBuilder::get(Context), + TypeBuilder::get(Context), + TypeBuilder::get(Context), + }; + return FunctionType::get(TypeBuilder::get(Context), + params, true); + } +}; + +template +class TypeBuilder { +public: + static FunctionType *get(LLVMContext &Context) { + Type *params[] = { + TypeBuilder::get(Context), + TypeBuilder::get(Context), + TypeBuilder::get(Context), + TypeBuilder::get(Context), + }; + return FunctionType::get(TypeBuilder::get(Context), + params, true); + } +}; + +template +class TypeBuilder { +public: + static FunctionType *get(LLVMContext &Context) { + Type *params[] = { + TypeBuilder::get(Context), + TypeBuilder::get(Context), + TypeBuilder::get(Context), + TypeBuilder::get(Context), + TypeBuilder::get(Context), + }; + return FunctionType::get(TypeBuilder::get(Context), + params, true); + } +}; + +} // namespace llvm + +#endif diff --git a/lib/Analysis/PathNumbering.cpp b/lib/Analysis/PathNumbering.cpp index 80c5222..d4ad726 100644 --- a/lib/Analysis/PathNumbering.cpp +++ b/lib/Analysis/PathNumbering.cpp @@ -31,11 +31,11 @@ #include "llvm/Instructions.h" #include "llvm/Module.h" #include "llvm/Pass.h" +#include "llvm/TypeBuilder.h" #include "llvm/Support/CFG.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" -#include "llvm/Support/TypeBuilder.h" #include "llvm/Support/raw_ostream.h" #include diff --git a/lib/Transforms/Instrumentation/PathProfiling.cpp b/lib/Transforms/Instrumentation/PathProfiling.cpp index b214796..cc27146 100644 --- a/lib/Transforms/Instrumentation/PathProfiling.cpp +++ b/lib/Transforms/Instrumentation/PathProfiling.cpp @@ -55,11 +55,11 @@ #include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "llvm/Pass.h" +#include "llvm/TypeBuilder.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/CFG.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" -#include "llvm/Support/TypeBuilder.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "llvm/Transforms/Instrumentation.h" diff --git a/unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp b/unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp index f8d8830..333888a 100644 --- a/unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp +++ b/unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp @@ -12,10 +12,10 @@ #include "llvm/LLVMContext.h" #include "llvm/Instructions.h" #include "llvm/Module.h" +#include "llvm/TypeBuilder.h" #include "llvm/ADT/OwningPtr.h" #include "llvm/CodeGen/MachineCodeInfo.h" #include "llvm/ExecutionEngine/JIT.h" -#include "llvm/Support/TypeBuilder.h" #include "llvm/Support/TargetSelect.h" #include "gtest/gtest.h" #include diff --git a/unittests/ExecutionEngine/JIT/JITEventListenerTestCommon.h b/unittests/ExecutionEngine/JIT/JITEventListenerTestCommon.h index d669ecc..5f02b38 100644 --- a/unittests/ExecutionEngine/JIT/JITEventListenerTestCommon.h +++ b/unittests/ExecutionEngine/JIT/JITEventListenerTestCommon.h @@ -15,12 +15,12 @@ #include "llvm/IRBuilder.h" #include "llvm/Instructions.h" #include "llvm/Module.h" +#include "llvm/TypeBuilder.h" #include "llvm/CodeGen/MachineCodeInfo.h" #include "llvm/ExecutionEngine/JIT.h" #include "llvm/ExecutionEngine/JITEventListener.h" #include "llvm/Support/Dwarf.h" #include "llvm/Support/TargetSelect.h" -#include "llvm/Support/TypeBuilder.h" #include "llvm/Config/config.h" #include "gtest/gtest.h" diff --git a/unittests/ExecutionEngine/JIT/JITTest.cpp b/unittests/ExecutionEngine/JIT/JITTest.cpp index 8780aa5..0fde6fc 100644 --- a/unittests/ExecutionEngine/JIT/JITTest.cpp +++ b/unittests/ExecutionEngine/JIT/JITTest.cpp @@ -18,6 +18,7 @@ #include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "llvm/Type.h" +#include "llvm/TypeBuilder.h" #include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/Assembly/Parser.h" @@ -27,7 +28,6 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/TargetSelect.h" -#include "llvm/Support/TypeBuilder.h" #include "gtest/gtest.h" #include diff --git a/unittests/Support/CMakeLists.txt b/unittests/Support/CMakeLists.txt index 674da35..ad16e62 100644 --- a/unittests/Support/CMakeLists.txt +++ b/unittests/Support/CMakeLists.txt @@ -22,7 +22,6 @@ add_llvm_unittest(SupportTests RegexTest.cpp SwapByteOrderTest.cpp TimeValue.cpp - TypeBuilderTest.cpp ValueHandleTest.cpp YAMLParserTest.cpp ) diff --git a/unittests/Support/TypeBuilderTest.cpp b/unittests/Support/TypeBuilderTest.cpp deleted file mode 100644 index 1d32257..0000000 --- a/unittests/Support/TypeBuilderTest.cpp +++ /dev/null @@ -1,254 +0,0 @@ -//===- llvm/unittest/Support/TypeBuilderTest.cpp - TypeBuilder tests -----===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "llvm/Support/TypeBuilder.h" -#include "llvm/LLVMContext.h" -#include "llvm/ADT/ArrayRef.h" - -#include "gtest/gtest.h" - -using namespace llvm; - -namespace { - -TEST(TypeBuilderTest, Void) { - EXPECT_EQ(Type::getVoidTy(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(Type::getVoidTy(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); - // Special cases for C compatibility: - EXPECT_EQ(Type::getInt8PtrTy(getGlobalContext()), - (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt8PtrTy(getGlobalContext()), - (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt8PtrTy(getGlobalContext()), - (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt8PtrTy(getGlobalContext()), - (TypeBuilder::get( - getGlobalContext()))); -} - -TEST(TypeBuilderTest, HostIntegers) { - EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt16Ty(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt16Ty(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt64Ty(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt64Ty(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); - - EXPECT_EQ(IntegerType::get(getGlobalContext(), sizeof(size_t) * CHAR_BIT), - (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(IntegerType::get(getGlobalContext(), sizeof(ptrdiff_t) * CHAR_BIT), - (TypeBuilder::get(getGlobalContext()))); -} - -TEST(TypeBuilderTest, CrossCompilableIntegers) { - EXPECT_EQ(IntegerType::get(getGlobalContext(), 1), (TypeBuilder, true>::get(getGlobalContext()))); - EXPECT_EQ(IntegerType::get(getGlobalContext(), 1), (TypeBuilder, false>::get(getGlobalContext()))); - EXPECT_EQ(IntegerType::get(getGlobalContext(), 72), (TypeBuilder, true>::get(getGlobalContext()))); - EXPECT_EQ(IntegerType::get(getGlobalContext(), 72), (TypeBuilder, false>::get(getGlobalContext()))); -} - -TEST(TypeBuilderTest, Float) { - EXPECT_EQ(Type::getFloatTy(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(Type::getDoubleTy(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); - // long double isn't supported yet. - EXPECT_EQ(Type::getFloatTy(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(Type::getFloatTy(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(Type::getDoubleTy(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(Type::getDoubleTy(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(Type::getX86_FP80Ty(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(Type::getX86_FP80Ty(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(Type::getFP128Ty(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(Type::getFP128Ty(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(Type::getPPC_FP128Ty(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(Type::getPPC_FP128Ty(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); -} - -TEST(TypeBuilderTest, Derived) { - EXPECT_EQ(PointerType::getUnqual(Type::getInt8PtrTy(getGlobalContext())), - (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(ArrayType::get(Type::getInt8Ty(getGlobalContext()), 7), - (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(ArrayType::get(Type::getInt8Ty(getGlobalContext()), 0), - (TypeBuilder::get(getGlobalContext()))); - - EXPECT_EQ(PointerType::getUnqual(Type::getInt8PtrTy(getGlobalContext())), - (TypeBuilder**, false>::get(getGlobalContext()))); - EXPECT_EQ(ArrayType::get(Type::getInt8Ty(getGlobalContext()), 7), - (TypeBuilder[7], false>::get(getGlobalContext()))); - EXPECT_EQ(ArrayType::get(Type::getInt8Ty(getGlobalContext()), 0), - (TypeBuilder[], false>::get(getGlobalContext()))); - - EXPECT_EQ(PointerType::getUnqual(Type::getInt8PtrTy(getGlobalContext())), - (TypeBuilder**, true>::get(getGlobalContext()))); - EXPECT_EQ(ArrayType::get(Type::getInt8Ty(getGlobalContext()), 7), - (TypeBuilder[7], true>::get(getGlobalContext()))); - EXPECT_EQ(ArrayType::get(Type::getInt8Ty(getGlobalContext()), 0), - (TypeBuilder[], true>::get(getGlobalContext()))); - - - EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), - (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), - (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), - (TypeBuilder::get(getGlobalContext()))); - - EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), - (TypeBuilder, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), - (TypeBuilder, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), - (TypeBuilder, false>::get(getGlobalContext()))); - - EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), - (TypeBuilder, true>::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), - (TypeBuilder, true>::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), - (TypeBuilder, true>::get(getGlobalContext()))); - - EXPECT_EQ(Type::getInt8PtrTy(getGlobalContext()), - (TypeBuilder::get(getGlobalContext()))); -} - -TEST(TypeBuilderTest, Functions) { - std::vector params; - EXPECT_EQ(FunctionType::get(Type::getVoidTy(getGlobalContext()), params, false), - (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true), - (TypeBuilder::get(getGlobalContext()))); - params.push_back(TypeBuilder::get(getGlobalContext())); - EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, false), - (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true), - (TypeBuilder::get(getGlobalContext()))); - params.push_back(TypeBuilder::get(getGlobalContext())); - EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, false), - (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true), - (TypeBuilder::get(getGlobalContext()))); - params.push_back(TypeBuilder::get(getGlobalContext())); - EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, false), - (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true), - (TypeBuilder::get(getGlobalContext()))); - params.push_back(TypeBuilder::get(getGlobalContext())); - EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, false), - (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true), - (TypeBuilder::get(getGlobalContext()))); - params.push_back(TypeBuilder::get(getGlobalContext())); - EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, false), - (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true), - (TypeBuilder::get(getGlobalContext()))); -} - -TEST(TypeBuilderTest, Context) { - // We used to cache TypeBuilder results in static local variables. This - // produced the same type for different contexts, which of course broke - // things. - LLVMContext context1; - EXPECT_EQ(&context1, - &(TypeBuilder, true>::get(context1))->getContext()); - LLVMContext context2; - EXPECT_EQ(&context2, - &(TypeBuilder, true>::get(context2))->getContext()); -} - -struct MyType { - int a; - int *b; - void *array[1]; -}; - -struct MyPortableType { - int32_t a; - int32_t *b; - void *array[1]; -}; - -} // anonymous namespace - -namespace llvm { -template class TypeBuilder { -public: - static StructType *get(LLVMContext &Context) { - // Using the static result variable ensures that the type is - // only looked up once. - std::vector st; - st.push_back(TypeBuilder::get(Context)); - st.push_back(TypeBuilder::get(Context)); - st.push_back(TypeBuilder::get(Context)); - static StructType *const result = StructType::get(Context, st); - return result; - } - - // You may find this a convenient place to put some constants - // to help with getelementptr. They don't have any effect on - // the operation of TypeBuilder. - enum Fields { - FIELD_A, - FIELD_B, - FIELD_ARRAY - }; -}; - -template class TypeBuilder { -public: - static StructType *get(LLVMContext &Context) { - // Using the static result variable ensures that the type is - // only looked up once. - std::vector st; - st.push_back(TypeBuilder, cross>::get(Context)); - st.push_back(TypeBuilder*, cross>::get(Context)); - st.push_back(TypeBuilder*[], cross>::get(Context)); - static StructType *const result = StructType::get(Context, st); - return result; - } - - // You may find this a convenient place to put some constants - // to help with getelementptr. They don't have any effect on - // the operation of TypeBuilder. - enum Fields { - FIELD_A, - FIELD_B, - FIELD_ARRAY - }; -}; -} // namespace llvm -namespace { - -TEST(TypeBuilderTest, Extensions) { - EXPECT_EQ(PointerType::getUnqual(StructType::get( - TypeBuilder::get(getGlobalContext()), - TypeBuilder::get(getGlobalContext()), - TypeBuilder::get(getGlobalContext()), - (void*)0)), - (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(PointerType::getUnqual(StructType::get( - TypeBuilder, false>::get(getGlobalContext()), - TypeBuilder*, false>::get(getGlobalContext()), - TypeBuilder*[], false>::get(getGlobalContext()), - (void*)0)), - (TypeBuilder::get(getGlobalContext()))); - EXPECT_EQ(PointerType::getUnqual(StructType::get( - TypeBuilder, false>::get(getGlobalContext()), - TypeBuilder*, false>::get(getGlobalContext()), - TypeBuilder*[], false>::get(getGlobalContext()), - (void*)0)), - (TypeBuilder::get(getGlobalContext()))); -} - -} // anonymous namespace diff --git a/unittests/VMCore/CMakeLists.txt b/unittests/VMCore/CMakeLists.txt index 79ee22c..b902930 100644 --- a/unittests/VMCore/CMakeLists.txt +++ b/unittests/VMCore/CMakeLists.txt @@ -11,6 +11,7 @@ set(VMCoreSources MDBuilderTest.cpp MetadataTest.cpp PassManagerTest.cpp + TypeBuilderTest.cpp ValueMapTest.cpp VerifierTest.cpp ) diff --git a/unittests/VMCore/TypeBuilderTest.cpp b/unittests/VMCore/TypeBuilderTest.cpp new file mode 100644 index 0000000..a746b1f --- /dev/null +++ b/unittests/VMCore/TypeBuilderTest.cpp @@ -0,0 +1,254 @@ +//===- llvm/unittest/TypeBuilderTest.cpp - TypeBuilder tests --------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/TypeBuilder.h" +#include "llvm/LLVMContext.h" +#include "llvm/ADT/ArrayRef.h" + +#include "gtest/gtest.h" + +using namespace llvm; + +namespace { + +TEST(TypeBuilderTest, Void) { + EXPECT_EQ(Type::getVoidTy(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(Type::getVoidTy(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); + // Special cases for C compatibility: + EXPECT_EQ(Type::getInt8PtrTy(getGlobalContext()), + (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(Type::getInt8PtrTy(getGlobalContext()), + (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(Type::getInt8PtrTy(getGlobalContext()), + (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(Type::getInt8PtrTy(getGlobalContext()), + (TypeBuilder::get( + getGlobalContext()))); +} + +TEST(TypeBuilderTest, HostIntegers) { + EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(Type::getInt16Ty(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(Type::getInt16Ty(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(Type::getInt64Ty(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(Type::getInt64Ty(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); + + EXPECT_EQ(IntegerType::get(getGlobalContext(), sizeof(size_t) * CHAR_BIT), + (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(IntegerType::get(getGlobalContext(), sizeof(ptrdiff_t) * CHAR_BIT), + (TypeBuilder::get(getGlobalContext()))); +} + +TEST(TypeBuilderTest, CrossCompilableIntegers) { + EXPECT_EQ(IntegerType::get(getGlobalContext(), 1), (TypeBuilder, true>::get(getGlobalContext()))); + EXPECT_EQ(IntegerType::get(getGlobalContext(), 1), (TypeBuilder, false>::get(getGlobalContext()))); + EXPECT_EQ(IntegerType::get(getGlobalContext(), 72), (TypeBuilder, true>::get(getGlobalContext()))); + EXPECT_EQ(IntegerType::get(getGlobalContext(), 72), (TypeBuilder, false>::get(getGlobalContext()))); +} + +TEST(TypeBuilderTest, Float) { + EXPECT_EQ(Type::getFloatTy(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(Type::getDoubleTy(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); + // long double isn't supported yet. + EXPECT_EQ(Type::getFloatTy(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(Type::getFloatTy(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(Type::getDoubleTy(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(Type::getDoubleTy(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(Type::getX86_FP80Ty(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(Type::getX86_FP80Ty(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(Type::getFP128Ty(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(Type::getFP128Ty(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(Type::getPPC_FP128Ty(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(Type::getPPC_FP128Ty(getGlobalContext()), (TypeBuilder::get(getGlobalContext()))); +} + +TEST(TypeBuilderTest, Derived) { + EXPECT_EQ(PointerType::getUnqual(Type::getInt8PtrTy(getGlobalContext())), + (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(ArrayType::get(Type::getInt8Ty(getGlobalContext()), 7), + (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(ArrayType::get(Type::getInt8Ty(getGlobalContext()), 0), + (TypeBuilder::get(getGlobalContext()))); + + EXPECT_EQ(PointerType::getUnqual(Type::getInt8PtrTy(getGlobalContext())), + (TypeBuilder**, false>::get(getGlobalContext()))); + EXPECT_EQ(ArrayType::get(Type::getInt8Ty(getGlobalContext()), 7), + (TypeBuilder[7], false>::get(getGlobalContext()))); + EXPECT_EQ(ArrayType::get(Type::getInt8Ty(getGlobalContext()), 0), + (TypeBuilder[], false>::get(getGlobalContext()))); + + EXPECT_EQ(PointerType::getUnqual(Type::getInt8PtrTy(getGlobalContext())), + (TypeBuilder**, true>::get(getGlobalContext()))); + EXPECT_EQ(ArrayType::get(Type::getInt8Ty(getGlobalContext()), 7), + (TypeBuilder[7], true>::get(getGlobalContext()))); + EXPECT_EQ(ArrayType::get(Type::getInt8Ty(getGlobalContext()), 0), + (TypeBuilder[], true>::get(getGlobalContext()))); + + + EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), + (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), + (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), + (TypeBuilder::get(getGlobalContext()))); + + EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), + (TypeBuilder, false>::get(getGlobalContext()))); + EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), + (TypeBuilder, false>::get(getGlobalContext()))); + EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), + (TypeBuilder, false>::get(getGlobalContext()))); + + EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), + (TypeBuilder, true>::get(getGlobalContext()))); + EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), + (TypeBuilder, true>::get(getGlobalContext()))); + EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), + (TypeBuilder, true>::get(getGlobalContext()))); + + EXPECT_EQ(Type::getInt8PtrTy(getGlobalContext()), + (TypeBuilder::get(getGlobalContext()))); +} + +TEST(TypeBuilderTest, Functions) { + std::vector params; + EXPECT_EQ(FunctionType::get(Type::getVoidTy(getGlobalContext()), params, false), + (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true), + (TypeBuilder::get(getGlobalContext()))); + params.push_back(TypeBuilder::get(getGlobalContext())); + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, false), + (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true), + (TypeBuilder::get(getGlobalContext()))); + params.push_back(TypeBuilder::get(getGlobalContext())); + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, false), + (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true), + (TypeBuilder::get(getGlobalContext()))); + params.push_back(TypeBuilder::get(getGlobalContext())); + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, false), + (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true), + (TypeBuilder::get(getGlobalContext()))); + params.push_back(TypeBuilder::get(getGlobalContext())); + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, false), + (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true), + (TypeBuilder::get(getGlobalContext()))); + params.push_back(TypeBuilder::get(getGlobalContext())); + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, false), + (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true), + (TypeBuilder::get(getGlobalContext()))); +} + +TEST(TypeBuilderTest, Context) { + // We used to cache TypeBuilder results in static local variables. This + // produced the same type for different contexts, which of course broke + // things. + LLVMContext context1; + EXPECT_EQ(&context1, + &(TypeBuilder, true>::get(context1))->getContext()); + LLVMContext context2; + EXPECT_EQ(&context2, + &(TypeBuilder, true>::get(context2))->getContext()); +} + +struct MyType { + int a; + int *b; + void *array[1]; +}; + +struct MyPortableType { + int32_t a; + int32_t *b; + void *array[1]; +}; + +} // anonymous namespace + +namespace llvm { +template class TypeBuilder { +public: + static StructType *get(LLVMContext &Context) { + // Using the static result variable ensures that the type is + // only looked up once. + std::vector st; + st.push_back(TypeBuilder::get(Context)); + st.push_back(TypeBuilder::get(Context)); + st.push_back(TypeBuilder::get(Context)); + static StructType *const result = StructType::get(Context, st); + return result; + } + + // You may find this a convenient place to put some constants + // to help with getelementptr. They don't have any effect on + // the operation of TypeBuilder. + enum Fields { + FIELD_A, + FIELD_B, + FIELD_ARRAY + }; +}; + +template class TypeBuilder { +public: + static StructType *get(LLVMContext &Context) { + // Using the static result variable ensures that the type is + // only looked up once. + std::vector st; + st.push_back(TypeBuilder, cross>::get(Context)); + st.push_back(TypeBuilder*, cross>::get(Context)); + st.push_back(TypeBuilder*[], cross>::get(Context)); + static StructType *const result = StructType::get(Context, st); + return result; + } + + // You may find this a convenient place to put some constants + // to help with getelementptr. They don't have any effect on + // the operation of TypeBuilder. + enum Fields { + FIELD_A, + FIELD_B, + FIELD_ARRAY + }; +}; +} // namespace llvm +namespace { + +TEST(TypeBuilderTest, Extensions) { + EXPECT_EQ(PointerType::getUnqual(StructType::get( + TypeBuilder::get(getGlobalContext()), + TypeBuilder::get(getGlobalContext()), + TypeBuilder::get(getGlobalContext()), + (void*)0)), + (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(PointerType::getUnqual(StructType::get( + TypeBuilder, false>::get(getGlobalContext()), + TypeBuilder*, false>::get(getGlobalContext()), + TypeBuilder*[], false>::get(getGlobalContext()), + (void*)0)), + (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(PointerType::getUnqual(StructType::get( + TypeBuilder, false>::get(getGlobalContext()), + TypeBuilder*, false>::get(getGlobalContext()), + TypeBuilder*[], false>::get(getGlobalContext()), + (void*)0)), + (TypeBuilder::get(getGlobalContext()))); +} + +} // anonymous namespace -- cgit v1.1