From 8cbfde6092332964224e8c371517de990f667675 Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Sun, 2 Dec 2012 14:29:24 -0800 Subject: [PATCH 1/2] Small fixes to build with LLVM top-of-tree (now numbered as version 3.3) --- cbackend.cpp | 6 +++++- ispc.cpp | 4 ++-- ispc.h | 4 ++-- main.cpp | 2 ++ 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cbackend.cpp b/cbackend.cpp index b433240e..f5fa85c7 100644 --- a/cbackend.cpp +++ b/cbackend.cpp @@ -71,7 +71,11 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FormattedStream.h" #include "llvm/Support/GetElementPtrTypeIterator.h" -#include "llvm/Support/InstVisitor.h" +#if defined(LLVM_3_3) + #include "llvm/InstVisitor.h" +#else + #include "llvm/Support/InstVisitor.h" +#endif #include "llvm/Support/MathExtras.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/Host.h" diff --git a/ispc.cpp b/ispc.cpp index e5a287e7..af066063 100644 --- a/ispc.cpp +++ b/ispc.cpp @@ -129,9 +129,9 @@ lGetSystemISA() { static const char *supportedCPUs[] = { "atom", "penryn", "core2", "corei7", "corei7-avx" -#ifdef LLVM_3_2 +#if defined(LLVM_3_2) || defined(LLVM_3_3) , "core-avx-i", "core-avx2" -#endif // LLVM_3_2 +#endif // LLVM_3_2 or LLVM_3_3 }; diff --git a/ispc.h b/ispc.h index 045916ab..40436d7c 100644 --- a/ispc.h +++ b/ispc.h @@ -40,8 +40,8 @@ #define ISPC_VERSION "1.3.1dev" -#if !defined(LLVM_3_0) && !defined(LLVM_3_1) && !defined(LLVM_3_2) -#error "Only LLVM 3.0, 3.1, and the 3.2 development branch are supported" +#if !defined(LLVM_3_0) && !defined(LLVM_3_1) && !defined(LLVM_3_2) && !defined(LLVM_3_3) +#error "Only LLVM 3.0, 3.1, 3.2, and the 3.3 development branch are supported" #endif #if defined(_WIN32) || defined(_WIN64) diff --git a/main.cpp b/main.cpp index 8076456f..70dfb5b6 100644 --- a/main.cpp +++ b/main.cpp @@ -68,6 +68,8 @@ lPrintVersion() { "3.1" #elif defined(LLVM_3_2) "3.2" +#elif defined(LLVM_3_3) + "3.3" #else #error "Unhandled LLVM version" #endif From 9892c8bf9a0755dbedb3b5691f50e1e827e0b831 Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Thu, 6 Dec 2012 11:39:22 -0500 Subject: [PATCH 2/2] Fix logic for ordering of struct declarations in generated header files. When a struct had an array of another struct type as a member, we weren't detecting that the struct type in the array needed to be declared before the enclosing struct type. Fixes issue #408. --- module.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/module.cpp b/module.cpp index be6796af..b99153b7 100644 --- a/module.cpp +++ b/module.cpp @@ -1075,6 +1075,23 @@ Module::writeObjectFileOrAssembly(llvm::TargetMachine *targetMachine, } +/** Given a pointer to an element of a structure, see if it is a struct + type or an array of a struct type. If so, return a pointer to the + underlying struct type. */ +static const StructType * +lGetElementStructType(const Type *t) { + const StructType *st = CastType(t); + if (st != NULL) + return st; + + const ArrayType *at = CastType(t); + if (at != NULL) + return lGetElementStructType(at->GetElementType()); + + return NULL; +} + + /** Emits a declaration for the given struct to the given file. This function first makes sure that declarations for any structs that are (recursively) members of this struct are emitted first. @@ -1092,7 +1109,7 @@ lEmitStructDecl(const StructType *st, std::vector *emittedSt // Otherwise first make sure any contained structs have been declared. for (int i = 0; i < st->GetElementCount(); ++i) { const StructType *elementStructType = - CastType(st->GetElementType(i)); + lGetElementStructType(st->GetElementType(i)); if (elementStructType != NULL) lEmitStructDecl(elementStructType, emittedStructs, file); }