From 1276ea98440fc95bdb1388c27217c618cdac3cba Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Tue, 6 Aug 2013 17:00:35 -0700 Subject: [PATCH] Revert "Remove support for building with LLVM 3.1" This reverts commit d3c567503bf64ec9066c09cb8959c31d4aa1be0e. Conflicts: opt.cpp --- builtins.cpp | 2 + builtins/target-avx11-x2.ll | 4 +- builtins/target-avx11.ll | 4 +- builtins/target-avx2-x2.ll | 25 +++++++- builtins/target-avx2.ll | 25 +++++++- cbackend.cpp | 115 +++++++++++++++++++++++++++--------- ctx.cpp | 4 +- ctx.h | 11 +++- expr.cpp | 2 +- func.cpp | 10 +++- ispc.cpp | 68 +++++++++++++++++---- ispc.h | 18 +++++- llvmutil.cpp | 2 +- llvmutil.h | 2 +- main.cpp | 4 +- module.cpp | 47 ++++++++++++--- opt.cpp | 22 +++++-- stmt.cpp | 2 +- type.cpp | 26 +++++--- type.h | 2 +- util.cpp | 9 ++- 21 files changed, 320 insertions(+), 84 deletions(-) diff --git a/builtins.cpp b/builtins.cpp index d75db43e..82c45b02 100644 --- a/builtins.cpp +++ b/builtins.cpp @@ -49,6 +49,8 @@ #include #if defined(LLVM_3_2) #include +#endif +#if defined(LLVM_3_1) || defined(LLVM_3_2) #include #include #include diff --git a/builtins/target-avx11-x2.ll b/builtins/target-avx11-x2.ll index 2aee1e1c..1aa6345c 100644 --- a/builtins/target-avx11-x2.ll +++ b/builtins/target-avx11-x2.ll @@ -31,7 +31,9 @@ include(`target-avx-x2.ll') -rdrand_definition() +ifelse(LLVM_VERSION, `LLVM_3_0', `rdrand_decls()', + LLVM_VERSION, `LLVM_3_1', `rdrand_decls()', + `rdrand_definition()') ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; int min/max diff --git a/builtins/target-avx11.ll b/builtins/target-avx11.ll index 44593113..fea0a7c2 100644 --- a/builtins/target-avx11.ll +++ b/builtins/target-avx11.ll @@ -31,7 +31,9 @@ include(`target-avx.ll') -rdrand_definition() +ifelse(LLVM_VERSION, `LLVM_3_0', `rdrand_decls()', + LLVM_VERSION, `LLVM_3_1', `rdrand_decls()', + `rdrand_definition()') ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; int min/max diff --git a/builtins/target-avx2-x2.ll b/builtins/target-avx2-x2.ll index 19f1845d..053fd078 100644 --- a/builtins/target-avx2-x2.ll +++ b/builtins/target-avx2-x2.ll @@ -29,11 +29,15 @@ ;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -define(`HAVE_GATHER', `1') +ifelse(LLVM_VERSION, `LLVM_3_0', `', + LLVM_VERSION, `LLVM_3_1', `', + `define(`HAVE_GATHER', `1')') include(`target-avx-x2.ll') -rdrand_definition() +ifelse(LLVM_VERSION, `LLVM_3_0', `rdrand_decls()', + LLVM_VERSION, `LLVM_3_1', `rdrand_decls()', + `rdrand_definition()') ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; int min/max @@ -172,6 +176,21 @@ define(`assemble_4s', ` assemble_8s($1, $2, $2_1, $2_2) ') +ifelse(LLVM_VERSION, `LLVM_3_0', ` +gen_gather_factored(i8) +gen_gather_factored(i16) +gen_gather_factored(i32) +gen_gather_factored(float) +gen_gather_factored(i64) +gen_gather_factored(double)', +LLVM_VERSION, `LLVM_3_1', ` +gen_gather_factored(i8) +gen_gather_factored(i16) +gen_gather_factored(i32) +gen_gather_factored(float) +gen_gather_factored(i64) +gen_gather_factored(double)', ` + gen_gather(i8) gen_gather(i16) @@ -538,3 +557,5 @@ define <16 x double> @__gather64_double(<16 x i64> %ptrs, ret <16 x double> %v } + +') diff --git a/builtins/target-avx2.ll b/builtins/target-avx2.ll index d3410011..f4a0ee07 100644 --- a/builtins/target-avx2.ll +++ b/builtins/target-avx2.ll @@ -29,11 +29,15 @@ ;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -define(`HAVE_GATHER', `1') +ifelse(LLVM_VERSION, `LLVM_3_0', `', + LLVM_VERSION, `LLVM_3_1', `', + `define(`HAVE_GATHER', `1')') include(`target-avx.ll') -rdrand_definition() +ifelse(LLVM_VERSION, `LLVM_3_0', `rdrand_decls()', + LLVM_VERSION, `LLVM_3_1', `rdrand_decls()', + `rdrand_definition()') ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; int min/max @@ -119,6 +123,21 @@ define(`extract_4s', ` %$2_2 = shufflevector <8 x $1> %$2, <8 x $1> undef, <4 x i32> ') +ifelse(LLVM_VERSION, `LLVM_3_0', ` +gen_gather_factored(i8) +gen_gather_factored(i16) +gen_gather_factored(i32) +gen_gather_factored(float) +gen_gather_factored(i64) +gen_gather_factored(double)', +LLVM_VERSION, `LLVM_3_1', ` +gen_gather_factored(i8) +gen_gather_factored(i16) +gen_gather_factored(i32) +gen_gather_factored(float) +gen_gather_factored(i64) +gen_gather_factored(double)', ` + gen_gather(i8) gen_gather(i16) @@ -410,3 +429,5 @@ define <8 x double> @__gather64_double(<8 x i64> %ptrs, ret <8 x double> %v } + +') diff --git a/cbackend.cpp b/cbackend.cpp index d54f48fb..d23bcc20 100644 --- a/cbackend.cpp +++ b/cbackend.cpp @@ -29,7 +29,7 @@ #include "llvmutil.h" -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) || defined(LLVM_3_2) #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" #include "llvm/CallingConv.h" @@ -38,7 +38,6 @@ #include "llvm/Intrinsics.h" #include "llvm/IntrinsicInst.h" #include "llvm/InlineAsm.h" - #include "llvm/TypeFinder.h" #else #include "llvm/IR/Constants.h" #include "llvm/IR/DerivedTypes.h" @@ -48,10 +47,16 @@ #include "llvm/IR/Intrinsics.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/InlineAsm.h" - #include "llvm/IR/TypeFinder.h" #endif #include "llvm/Pass.h" #include "llvm/PassManager.h" +#if !defined(LLVM_3_1) + #if defined(LLVM_3_2) + #include "llvm/TypeFinder.h" + #else // LLVM_3_3 + + #include "llvm/IR/TypeFinder.h" + #endif +#endif // LLVM_3_2 + #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/STLExtras.h" @@ -71,7 +76,9 @@ #include "llvm/MC/MCRegisterInfo.h" #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/MC/MCSymbol.h" -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) + #include "llvm/Target/TargetData.h" +#elif defined(LLVM_3_2) #include "llvm/DataLayout.h" #else // LLVM 3.3+ #include "llvm/IR/DataLayout.h" @@ -81,7 +88,7 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FormattedStream.h" #include "llvm/Support/GetElementPtrTypeIterator.h" -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) || defined(LLVM_3_2) #include "llvm/Support/InstVisitor.h" #else // LLVM 3.3+ #include "llvm/InstVisitor.h" @@ -251,10 +258,14 @@ namespace { const llvm::MCRegisterInfo *MRI; const llvm::MCObjectFileInfo *MOFI; llvm::MCContext *TCtx; +#if defined(LLVM_3_1) + const llvm::TargetData* TD; +#else // FIXME: it's ugly to have the name be "TD" here, but it saves us // lots of ifdefs in the below since the new DataLayout and the old // TargetData have generally similar interfaces... const llvm::DataLayout* TD; +#endif std::map FPConstantMap; std::map VectorConstantMap; @@ -341,7 +352,7 @@ namespace { bool isSigned = false, const std::string &VariableName = "", bool IgnoreName = false, -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) || defined(LLVM_3_2) const llvm::AttrListPtr &PAL = llvm::AttrListPtr() #else const llvm::AttributeSet &PAL = llvm::AttributeSet() @@ -352,7 +363,7 @@ namespace { const std::string &NameSoFar = ""); void printStructReturnPointerFunctionType(llvm::raw_ostream &Out, -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) || defined(LLVM_3_2) const llvm::AttrListPtr &PAL, #else const llvm::AttributeSet &PAL, @@ -575,7 +586,7 @@ std::string CWriter::getArrayName(llvm::ArrayType *AT) { /// return type, except, instead of printing the type as void (*)(Struct*, ...) /// print it as "Struct (*)(...)", for struct return functions. void CWriter::printStructReturnPointerFunctionType(llvm::raw_ostream &Out, -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) || defined(LLVM_3_2) const llvm::AttrListPtr &PAL, #else const llvm::AttributeSet &PAL, @@ -594,16 +605,20 @@ void CWriter::printStructReturnPointerFunctionType(llvm::raw_ostream &Out, if (PrintedType) FunctionInnards << ", "; llvm::Type *ArgTy = *I; -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) + if (PAL.paramHasAttr(Idx, llvm::Attribute::ByVal)) { +#elif defined(LLVM_3_2) if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) { #else - if (PAL.getParamAttributes(Idx).hasAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::ByVal)) { + if (PAL.getParamAttributes(Idx).hasAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::ByVal)) { #endif assert(ArgTy->isPointerTy()); ArgTy = llvm::cast(ArgTy)->getElementType(); } printType(FunctionInnards, ArgTy, -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) + /*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt), +#elif defined(LLVM_3_2) PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt), #else PAL.getParamAttributes(Idx).hasAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::SExt), @@ -620,7 +635,9 @@ void CWriter::printStructReturnPointerFunctionType(llvm::raw_ostream &Out, } FunctionInnards << ')'; printType(Out, RetTy, -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) + /*isSigned=*/PAL.paramHasAttr(0, llvm::Attribute::SExt), +#elif defined(LLVM_3_2) PAL.getParamAttributes(0).hasAttribute(llvm::Attributes::SExt), #else PAL.getParamAttributes(0).hasAttribute(llvm::AttributeSet::ReturnIndex, llvm::Attribute::SExt), @@ -720,7 +737,7 @@ CWriter::printSimpleType(llvm::raw_ostream &Out, llvm::Type *Ty, bool isSigned, llvm::raw_ostream &CWriter::printType(llvm::raw_ostream &Out, llvm::Type *Ty, bool isSigned, const std::string &NameSoFar, bool IgnoreName, -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) || defined(LLVM_3_2) const llvm::AttrListPtr &PAL #else const llvm::AttributeSet &PAL @@ -742,7 +759,9 @@ llvm::raw_ostream &CWriter::printType(llvm::raw_ostream &Out, llvm::Type *Ty, for (llvm::FunctionType::param_iterator I = FTy->param_begin(), E = FTy->param_end(); I != E; ++I) { llvm::Type *ArgTy = *I; -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) + if (PAL.paramHasAttr(Idx, llvm::Attribute::ByVal)) { +#elif defined(LLVM_3_2) if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) { #else if (PAL.getParamAttributes(Idx).hasAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::ByVal)) { @@ -753,7 +772,9 @@ llvm::raw_ostream &CWriter::printType(llvm::raw_ostream &Out, llvm::Type *Ty, if (I != FTy->param_begin()) FunctionInnards << ", "; printType(FunctionInnards, ArgTy, -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) + /*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt), +#elif defined(LLVM_3_2) PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt), #else PAL.getParamAttributes(Idx).hasAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::SExt), @@ -770,7 +791,9 @@ llvm::raw_ostream &CWriter::printType(llvm::raw_ostream &Out, llvm::Type *Ty, } FunctionInnards << ')'; printType(Out, FTy->getReturnType(), -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) + /*isSigned=*/PAL.paramHasAttr(0, llvm::Attribute::SExt), +#elif defined(LLVM_3_2) PAL.getParamAttributes(0).hasAttribute(llvm::Attributes::SExt), #else PAL.getParamAttributes(0).hasAttribute(llvm::AttributeSet::ReturnIndex, llvm::Attribute::SExt), @@ -1949,7 +1972,11 @@ void CWriter::writeOperandWithCast(llvm::Value* Operand, const llvm::ICmpInst &C // directives to cater to specific compilers as need be. // static void generateCompilerSpecificCode(llvm::formatted_raw_ostream& Out, +#if defined(LLVM_3_1) + const llvm::TargetData *TD) { +#else const llvm::DataLayout *TD) { +#endif // We output GCC specific attributes to preserve 'linkonce'ness on globals. // If we aren't being compiled with GCC, just drop these attributes. Out << "#ifndef __GNUC__ /* Can only support \"linkonce\" vars with GCC */\n" @@ -2142,7 +2169,11 @@ bool CWriter::doInitialization(llvm::Module &M) { // Initialize TheModule = &M; +#if defined(LLVM_3_1) + TD = new llvm::TargetData(&M); +#else TD = new llvm::DataLayout(&M); +#endif IL = new llvm::IntrinsicLowering(*TD); IL->AddPrototypes(M); @@ -2625,11 +2656,15 @@ void CWriter::printModuleTypes() { // Get all of the struct types used in the module. std::vector StructTypes; +#if defined(LLVM_3_1) + TheModule->findUsedStructTypes(StructTypes); +#else llvm::TypeFinder typeFinder; typeFinder.run(*TheModule, false); for (llvm::TypeFinder::iterator iter = typeFinder.begin(); iter != typeFinder.end(); ++iter) StructTypes.push_back(*iter); +#endif // Get all of the array types used in the module std::vector ArrayTypes; @@ -2750,7 +2785,7 @@ void CWriter::printFunctionSignature(const llvm::Function *F, bool Prototype) { // Loop over the arguments, printing them... llvm::FunctionType *FT = llvm::cast(F->getFunctionType()); -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) || defined(LLVM_3_2) const llvm::AttrListPtr &PAL = F->getAttributes(); #else const llvm::AttributeSet &PAL = F->getAttributes(); @@ -2784,16 +2819,20 @@ void CWriter::printFunctionSignature(const llvm::Function *F, bool Prototype) { else ArgName = ""; llvm::Type *ArgTy = I->getType(); -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) + if (PAL.paramHasAttr(Idx, llvm::Attribute::ByVal)) { +#elif defined(LLVM_3_2) if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) { #else - if (PAL.getParamAttributes(Idx).hasAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::ByVal)) { + if (PAL.getParamAttributes(Idx).hasAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::ByVal)) { #endif ArgTy = llvm::cast(ArgTy)->getElementType(); ByValParams.insert(I); } printType(FunctionInnards, ArgTy, -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) + /*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt), +#elif defined(LLVM_3_2) PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt), #else PAL.getParamAttributes(Idx).hasAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::SExt), @@ -2819,7 +2858,9 @@ void CWriter::printFunctionSignature(const llvm::Function *F, bool Prototype) { for (; I != E; ++I) { if (PrintedArg) FunctionInnards << ", "; llvm::Type *ArgTy = *I; -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) + if (PAL.paramHasAttr(Idx, llvm::Attribute::ByVal)) { +#elif defined(LLVM_3_2) if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) { #else if (PAL.getParamAttributes(Idx).hasAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::ByVal)) { @@ -2828,7 +2869,9 @@ void CWriter::printFunctionSignature(const llvm::Function *F, bool Prototype) { ArgTy = llvm::cast(ArgTy)->getElementType(); } printType(FunctionInnards, ArgTy, -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) + /*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt) +#elif defined(LLVM_3_2) PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt) #else PAL.getParamAttributes(Idx).hasAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::SExt) @@ -2865,7 +2908,9 @@ void CWriter::printFunctionSignature(const llvm::Function *F, bool Prototype) { // Print out the return type and the signature built above. printType(Out, RetTy, -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) + /*isSigned=*/PAL.paramHasAttr(0, llvm::Attribute::SExt), +#elif defined(LLVM_3_2) PAL.getParamAttributes(0).hasAttribute(llvm::Attributes::SExt), #else PAL.getParamAttributes(0).hasAttribute(llvm::AttributeSet::ReturnIndex, llvm::Attribute::SExt), @@ -3667,7 +3712,7 @@ void CWriter::lowerIntrinsics(llvm::Function &F) { const char *BuiltinName = ""; #define GET_GCC_BUILTIN_NAME #define Intrinsic llvm::Intrinsic -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) || defined(LLVM_3_2) #include "llvm/Intrinsics.gen" #else #include "llvm/IR/Intrinsics.gen" @@ -3732,7 +3777,7 @@ void CWriter::visitCallInst(llvm::CallInst &I) { // If this is a call to a struct-return function, assign to the first // parameter instead of passing it to the call. -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) || defined(LLVM_3_2) const llvm::AttrListPtr &PAL = I.getAttributes(); #else const llvm::AttributeSet &PAL = I.getAttributes(); @@ -3820,7 +3865,9 @@ void CWriter::visitCallInst(llvm::CallInst &I) { (*AI)->getType() != FTy->getParamType(ArgNo)) { Out << '('; printType(Out, FTy->getParamType(ArgNo), -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) + /*isSigned=*/PAL.paramHasAttr(ArgNo+1, llvm::Attribute::SExt) +#elif defined(LLVM_3_2) PAL.getParamAttributes(ArgNo+1).hasAttribute(llvm::Attributes::SExt) #else PAL.getParamAttributes(ArgNo+1).hasAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::SExt) @@ -3858,7 +3905,7 @@ bool CWriter::visitBuiltinCall(llvm::CallInst &I, llvm::Intrinsic::ID ID, const char *BuiltinName = ""; #define GET_GCC_BUILTIN_NAME #define Intrinsic llvm::Intrinsic -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) || defined(LLVM_3_2) #include "llvm/Intrinsics.gen" #else #include "llvm/IR/Intrinsics.gen" @@ -4508,8 +4555,13 @@ SmearCleanupPass::runOnBasicBlock(llvm::BasicBlock &bb) { smearType, NULL); smearFunc = llvm::dyn_cast(sf); assert(smearFunc != NULL); +#if defined(LLVM_3_1) + smearFunc->setDoesNotThrow(true); + smearFunc->setDoesNotAccessMemory(true); +#else smearFunc->setDoesNotThrow(); smearFunc->setDoesNotAccessMemory(); +#endif } assert(smearFunc != NULL); @@ -4651,8 +4703,13 @@ AndCmpCleanupPass::runOnBasicBlock(llvm::BasicBlock &bb) { LLVMTypes::MaskType, NULL); andCmpFunc = llvm::dyn_cast(acf); Assert(andCmpFunc != NULL); +#if defined(LLVM_3_1) + andCmpFunc->setDoesNotThrow(true); + andCmpFunc->setDoesNotAccessMemory(true); +#else andCmpFunc->setDoesNotThrow(); andCmpFunc->setDoesNotAccessMemory(); +#endif } // Set up the function call to the *_and_mask function; the @@ -4857,7 +4914,7 @@ WriteCXXFile(llvm::Module *module, const char *fn, int vectorWidth, pm.add(new llvm::TargetData(module)); #endif -#if defined(LLVM_3_2) || defined(LLVM_3_3) +#if defined(LLVM_3_1) || defined(LLVM_3_2) || defined(LLVM_3_3) int flags = 0; #else llvm::sys::fs::OpenFlags flags = llvm::sys::fs::F_None; @@ -4882,7 +4939,7 @@ WriteCXXFile(llvm::Module *module, const char *fn, int vectorWidth, pm.add(llvm::createDeadCodeEliminationPass()); // clean up after smear pass //CO pm.add(llvm::createPrintModulePass(&fos)); pm.add(new CWriter(fos, includeName, vectorWidth)); -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) || defined(LLVM_3_2) // This interface is depricated for 3.3+ pm.add(llvm::createGCInfoDeleter()); #endif diff --git a/ctx.cpp b/ctx.cpp index 32ba0ad9..c50d22f9 100644 --- a/ctx.cpp +++ b/ctx.cpp @@ -46,7 +46,7 @@ #include "sym.h" #include #include -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) || defined(LLVM_3_2) #include #include #include @@ -3312,7 +3312,7 @@ FunctionEmitContext::CallInst(llvm::Value *func, const FunctionType *funcType, // alias analysis. // TODO: what other attributes needs to be copied? // TODO: do the same for varing path. -#if !defined (LLVM_3_2) // LLVM 3.3+ +#if !defined (LLVM_3_1) && !defined (LLVM_3_2) // LLVM 3.3+ llvm::CallInst *cc = llvm::dyn_cast(ci); if (cc && cc->getCalledFunction() && diff --git a/ctx.h b/ctx.h index 4b27e6e5..58f9aae3 100644 --- a/ctx.h +++ b/ctx.h @@ -40,15 +40,20 @@ #include "ispc.h" #include -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) || defined(LLVM_3_2) #include #include #else #include #include #endif -#include -#include +#if defined(LLVM_3_1) + #include + #include +#else + #include + #include +#endif struct CFInfo; diff --git a/expr.cpp b/expr.cpp index eb8c0951..856d363c 100644 --- a/expr.cpp +++ b/expr.cpp @@ -56,7 +56,7 @@ #include #include #include -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) || defined(LLVM_3_2) #include #include #include diff --git a/func.cpp b/func.cpp index 3097f86d..b975049b 100644 --- a/func.cpp +++ b/func.cpp @@ -46,7 +46,7 @@ #include "util.h" #include -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) || defined(LLVM_3_2) #include #include #include @@ -310,7 +310,9 @@ Function::emitCode(FunctionEmitContext *ctx, llvm::Function *function, // isn't worth the code bloat / overhead. bool checkMask = (type->isTask == true) || ( -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) + (function->hasFnAttr(llvm::Attribute::AlwaysInline) == false) +#elif defined(LLVM_3_2) (function->getFnAttributes().hasAttribute(llvm::Attributes::AlwaysInline) == false) #else // LLVM 3.3+ (function->getAttributes().getFnAttributes().hasAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::AlwaysInline) == false) @@ -451,7 +453,11 @@ Function::GenerateIR() { functionName += std::string("_") + g->target->GetISAString(); llvm::Function *appFunction = llvm::Function::Create(ftype, linkage, functionName.c_str(), m->module); +#if defined(LLVM_3_1) + appFunction->setDoesNotThrow(true); +#else appFunction->setDoesNotThrow(); +#endif g->target->markFuncWithTargetAttr(appFunction); diff --git a/ispc.cpp b/ispc.cpp index 03d1aaff..0f07895f 100644 --- a/ispc.cpp +++ b/ispc.cpp @@ -48,7 +48,7 @@ #include #include #endif -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) || defined(LLVM_3_2) #include #include #include @@ -57,12 +57,19 @@ #include #include #endif -#include -#include +#if defined(LLVM_3_1) + #include + #include +#else + #include + #include +#endif #include #include #include -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) + #include +#elif defined(LLVM_3_2) #include #else // LLVM 3.3+ #include @@ -138,20 +145,27 @@ static const char *supportedCPUs[] = { // cortex-a9 and a15. We should be able to handle any of them that also // have NEON support. "cortex-a9", "cortex-a15", - "atom", "penryn", "core2", "corei7", "corei7-avx", "core-avx-i", "core-avx2" + "atom", "penryn", "core2", "corei7", "corei7-avx" +#if !defined(LLVM_3_1) + , "core-avx-i", "core-avx2" +#endif // LLVM 3.2+ }; Target::Target(const char *arch, const char *cpu, const char *isa, bool pic) : m_target(NULL), m_targetMachine(NULL), +#if defined(LLVM_3_1) + m_targetData(NULL), +#else m_dataLayout(NULL), +#endif m_valid(false), m_isa(SSE2), m_arch(""), m_is32Bit(true), m_cpu(""), m_attributes(""), -#if !defined(LLVM_3_2) +#if !defined(LLVM_3_1) && !defined(LLVM_3_2) m_tf_attributes(NULL), #endif m_nativeVectorWidth(-1), @@ -393,7 +407,10 @@ Target::Target(const char *arch, const char *cpu, const char *isa, bool pic) : this->m_maskingIsFree = false; this->m_maskBitCount = 32; this->m_hasHalf = true; +#if !defined(LLVM_3_1) + // LLVM 3.2+ only this->m_hasRand = true; +#endif } else if (!strcasecmp(isa, "avx1.1-x2")) { this->m_isa = Target::AVX11; @@ -403,29 +420,46 @@ Target::Target(const char *arch, const char *cpu, const char *isa, bool pic) : this->m_maskingIsFree = false; this->m_maskBitCount = 32; this->m_hasHalf = true; +#if !defined(LLVM_3_1) + // LLVM 3.2+ only this->m_hasRand = true; +#endif } else if (!strcasecmp(isa, "avx2")) { this->m_isa = Target::AVX2; this->m_nativeVectorWidth = 8; this->m_vectorWidth = 8; - this->m_attributes = "+avx2,+popcnt,+cmov,+f16c,+rdrand,+fma"; + this->m_attributes = "+avx2,+popcnt,+cmov,+f16c,+rdrand" +#ifndef LLVM_3_1 + ",+fma" +#endif // !LLVM_3_1 + ; this->m_maskingIsFree = false; this->m_maskBitCount = 32; this->m_hasHalf = true; +#if !defined(LLVM_3_1) + // LLVM 3.2+ only this->m_hasRand = true; this->m_hasGather = true; +#endif } else if (!strcasecmp(isa, "avx2-x2")) { this->m_isa = Target::AVX2; this->m_nativeVectorWidth = 16; this->m_vectorWidth = 16; - this->m_attributes = "+avx2,+popcnt,+cmov,+f16c,+rdrand,+fma"; + this->m_attributes = "+avx2,+popcnt,+cmov,+f16c,+rdrand" +#ifndef LLVM_3_1 + ",+fma" +#endif // !LLVM_3_1 + ; this->m_maskingIsFree = false; this->m_maskBitCount = 32; this->m_hasHalf = true; +#if !defined(LLVM_3_1) + // LLVM 3.2+ only this->m_hasRand = true; this->m_hasGather = true; +#endif } else if (!strcasecmp(isa, "neon-8")) { this->m_isa = Target::NEON8; @@ -471,8 +505,10 @@ Target::Target(const char *arch, const char *cpu, const char *isa, bool pic) : if (m_isa == Target::NEON8 || m_isa == Target::NEON16 || m_isa == Target::NEON32) options.FloatABIType = llvm::FloatABI::Hard; +#if !defined(LLVM_3_1) if (g->opt.disableFMA == false) options.AllowFPOpFusion = llvm::FPOpFusion::Fast; +#endif // !LLVM_3_1 #ifdef ISPC_IS_WINDOWS if (strcmp("x86", arch) == 0) { @@ -490,8 +526,12 @@ Target::Target(const char *arch, const char *cpu, const char *isa, bool pic) : // Initialize TargetData/DataLayout in 3 steps. // 1. Get default data layout first - std::string dl_string = - m_targetMachine->getDataLayout()->getStringRepresentation(); + std::string dl_string; +#if defined(LLVM_3_1) + dl_string = m_targetMachine->getTargetData()->getStringRepresentation(); +#else + dl_string = m_targetMachine->getDataLayout()->getStringRepresentation(); +#endif // 2. Adjust for generic if (m_isa == Target::GENERIC) { @@ -506,7 +546,11 @@ Target::Target(const char *arch, const char *cpu, const char *isa, bool pic) : } // 3. Finally set member data +#if defined(LLVM_3_1) + m_targetData = new llvm::TargetData(dl_string); +#else m_dataLayout = new llvm::DataLayout(dl_string); +#endif // Set is32Bit // This indicates if we are compiling for 32 bit platform @@ -514,7 +558,7 @@ Target::Target(const char *arch, const char *cpu, const char *isa, bool pic) : // FIXME: all generic targets are handled as 64 bit, which is incorrect. this->m_is32Bit = (getDataLayout()->getPointerSize() == 4); -#if !defined(LLVM_3_2) +#if !defined(LLVM_3_1) && !defined(LLVM_3_2) // This is LLVM 3.3+ feature. // Initialize target-specific "target-feature" attribute. if (!m_attributes.empty()) { @@ -728,7 +772,7 @@ Target::StructOffset(llvm::Type *type, int element, } void Target::markFuncWithTargetAttr(llvm::Function* func) { -#if !defined(LLVM_3_2) +#if !defined(LLVM_3_1) && !defined(LLVM_3_2) if (m_tf_attributes) { func->addAttributes(llvm::AttributeSet::FunctionIndex, *m_tf_attributes); } diff --git a/ispc.h b/ispc.h index 8653553e..98fcd199 100644 --- a/ispc.h +++ b/ispc.h @@ -40,8 +40,8 @@ #define ISPC_VERSION "1.4.5dev" -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) -#error "Only LLVM 3.2, 3.3 and the 3.4 development branch are supported" +#if !defined(LLVM_3_1) && !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) +#error "Only LLVM 3.1, 3.2, 3.3 and the 3.4 development branch are supported" #endif #if defined(_WIN32) || defined(_WIN64) @@ -72,7 +72,11 @@ namespace llvm { class BasicBlock; class Constant; class ConstantValue; +#if defined(LLVM_3_1) + class TargetData; +#else class DataLayout; +#endif class DIBuilder; class DIDescriptor; class DIFile; @@ -222,7 +226,11 @@ public: // Note the same name of method for 3.1 and 3.2+, this allows // to reduce number ifdefs on client side. +#if defined(LLVM_3_1) + llvm::TargetData *getDataLayout() const {return m_targetData;} +#else llvm::DataLayout *getDataLayout() const {return m_dataLayout;} +#endif /** Reports if Target object has valid state. */ bool isValid() const {return m_valid;} @@ -270,7 +278,11 @@ private: */ llvm::TargetMachine *m_targetMachine; +#if defined(LLVM_3_1) + llvm::TargetData *m_targetData; +#else llvm::DataLayout *m_dataLayout; +#endif /** flag to report invalid state after construction (due to bad parameters passed to constructor). */ @@ -291,7 +303,7 @@ private: /** Target-specific attribute string to pass along to the LLVM backend */ std::string m_attributes; -#if !defined(LLVM_3_2) +#if !defined(LLVM_3_1) && !defined(LLVM_3_2) /** Target-specific LLVM attribute, which has to be attached to every function to ensure that it is generated for correct target architecture. This is requirement was introduced in LLVM 3.3 */ diff --git a/llvmutil.cpp b/llvmutil.cpp index 2f54a2fe..180c8676 100644 --- a/llvmutil.cpp +++ b/llvmutil.cpp @@ -38,7 +38,7 @@ #include "llvmutil.h" #include "ispc.h" #include "type.h" -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) || defined(LLVM_3_2) #include #include #else diff --git a/llvmutil.h b/llvmutil.h index d1803f32..d6c5ede0 100644 --- a/llvmutil.h +++ b/llvmutil.h @@ -38,7 +38,7 @@ #ifndef ISPC_LLVMUTIL_H #define ISPC_LLVMUTIL_H 1 -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) || defined(LLVM_3_2) #include #include #include diff --git a/main.cpp b/main.cpp index c21e7f88..8d7282f5 100644 --- a/main.cpp +++ b/main.cpp @@ -62,7 +62,9 @@ static void lPrintVersion() { printf("Intel(r) SPMD Program Compiler (ispc), %s (build %s @ %s, LLVM %s)\n", ISPC_VERSION, BUILD_VERSION, BUILD_DATE, -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) + "3.1" +#elif defined(LLVM_3_2) "3.2" #elif defined(LLVM_3_3) "3.3" diff --git a/module.cpp b/module.cpp index eba5eb3b..755a5dc4 100644 --- a/module.cpp +++ b/module.cpp @@ -64,7 +64,7 @@ #define strcasecmp stricmp #endif -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) || defined(LLVM_3_2) #include #include #include @@ -86,7 +86,9 @@ #include #include #include -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) + #include +#elif defined(LLVM_3_2) #include #include #else // LLVM 3.3+ @@ -200,7 +202,7 @@ lStripUnusedDebugInfo(llvm::Module *module) { // stuff and remove it later on. Removing it is useful, as it // reduces size of the binary significantly (manyfold for small // programs). -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) || defined(LLVM_3_2) llvm::MDNode *nodeSPMD = llvm::dyn_cast(cuNode->getOperand(12)); Assert(nodeSPMD != NULL); @@ -795,7 +797,11 @@ Module::AddFunctionDeclaration(const std::string &name, #endif if (functionType->isTask) // This also applies transitively to members I think? +#if defined(LLVM_3_1) + function->setDoesNotAlias(1, true); +#else // LLVM 3.2+ function->setDoesNotAlias(1); +#endif g->target->markFuncWithTargetAttr(function); @@ -844,7 +850,12 @@ Module::AddFunctionDeclaration(const std::string &name, // NOTE: LLVM indexes function parameters starting from 1. // This is unintuitive. +#if defined(LLVM_3_1) + function->setDoesNotAlias(i+1, true); +#else function->setDoesNotAlias(i+1); +#endif + #if 0 int align = 4 * RoundUpPow2(g->target->nativeVectorWidth); function->addAttribute(i+1, llvm::Attribute::constructAlignmentFromInt(align)); @@ -1056,7 +1067,7 @@ Module::writeObjectFileOrAssembly(llvm::TargetMachine *targetMachine, llvm::TargetMachine::CodeGenFileType fileType = (outputType == Object) ? llvm::TargetMachine::CGFT_ObjectFile : llvm::TargetMachine::CGFT_AssemblyFile; bool binary = (fileType == llvm::TargetMachine::CGFT_ObjectFile); -#if defined(LLVM_3_2) || defined(LLVM_3_3) +#if defined(LLVM_3_1) || defined(LLVM_3_2) || defined(LLVM_3_3) unsigned int flags = binary ? llvm::raw_fd_ostream::F_Binary : 0; #else llvm::sys::fs::OpenFlags flags = binary ? llvm::sys::fs::F_Binary : @@ -1071,7 +1082,11 @@ Module::writeObjectFileOrAssembly(llvm::TargetMachine *targetMachine, } llvm::PassManager pm; +#if defined(LLVM_3_1) + pm.add(new llvm::TargetData(*g->target->getDataLayout())); +#else pm.add(new llvm::DataLayout(*g->target->getDataLayout())); +#endif llvm::formatted_raw_ostream fos(of->os()); @@ -1785,12 +1800,22 @@ Module::execPreprocessor(const char *infilename, llvm::raw_string_ostream *ostre llvm::raw_fd_ostream stderrRaw(2, false); +#if defined(LLVM_3_1) + clang::TextDiagnosticPrinter *diagPrinter = + new clang::TextDiagnosticPrinter(stderrRaw, clang::DiagnosticOptions()); +#else clang::DiagnosticOptions *diagOptions = new clang::DiagnosticOptions(); clang::TextDiagnosticPrinter *diagPrinter = new clang::TextDiagnosticPrinter(stderrRaw, diagOptions); +#endif llvm::IntrusiveRefCntPtr diagIDs(new clang::DiagnosticIDs); +#if defined(LLVM_3_1) + clang::DiagnosticsEngine *diagEngine = + new clang::DiagnosticsEngine(diagIDs, diagPrinter); +#else clang::DiagnosticsEngine *diagEngine = new clang::DiagnosticsEngine(diagIDs, diagOptions, diagPrinter); +#endif inst.setDiagnostics(diagEngine); clang::TargetOptions &options = inst.getTargetOpts(); @@ -1800,7 +1825,7 @@ Module::execPreprocessor(const char *infilename, llvm::raw_string_ostream *ostre } options.Triple = triple.getTriple(); -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) || defined(LLVM_3_2) clang::TargetInfo *target = clang::TargetInfo::CreateTargetInfo(inst.getDiagnostics(), options); #else // LLVM 3.3+ @@ -1810,14 +1835,18 @@ Module::execPreprocessor(const char *infilename, llvm::raw_string_ostream *ostre inst.setTarget(target); inst.createSourceManager(inst.getFileManager()); +#if defined(LLVM_3_1) + inst.InitializeSourceManager(infilename); +#else clang::FrontendInputFile inputFile(infilename, clang::IK_None); inst.InitializeSourceManager(inputFile); +#endif // Don't remove comments in the preprocessor, so that we can accurately // track the source file position by handling them ourselves. inst.getPreprocessorOutputOpts().ShowComments = 1; -#if !defined(LLVM_3_2) // LLVM 3.3+ +#if !defined(LLVM_3_1) && !defined(LLVM_3_2) // LLVM 3.3+ inst.getPreprocessorOutputOpts().ShowCPP = 1; #endif @@ -1829,7 +1858,7 @@ Module::execPreprocessor(const char *infilename, llvm::raw_string_ostream *ostre headerOpts.Verbose = 1; for (int i = 0; i < (int)g->includePath.size(); ++i) { headerOpts.AddPath(g->includePath[i], clang::frontend::Angled, -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) || defined(LLVM_3_2) true /* is user supplied */, #endif false /* not a framework */, @@ -1884,7 +1913,11 @@ Module::execPreprocessor(const char *infilename, llvm::raw_string_ostream *ostre } } +#if defined(LLVM_3_1) + inst.getLangOpts().BCPLComment = 1; +#else inst.getLangOpts().LineComment = 1; +#endif inst.createPreprocessor(); diagPrinter->BeginSourceFile(inst.getLangOpts(), &inst.getPreprocessor()); diff --git a/opt.cpp b/opt.cpp index 8899c64d..077320d5 100644 --- a/opt.cpp +++ b/opt.cpp @@ -48,7 +48,7 @@ #include #include -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) || defined(LLVM_3_2) #include #include #include @@ -73,7 +73,9 @@ #include #include #include -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) + #include +#elif defined(LLVM_3_2) #include #else // LLVM 3.3+ #include @@ -83,8 +85,12 @@ #include #include #include -#include #include +#if defined(LLVM_3_1) + #include +#else + #include +#endif #include #ifdef ISPC_IS_LINUX #include @@ -411,14 +417,18 @@ Optimize(llvm::Module *module, int optLevel) { optPM.add(targetLibraryInfo); +#if defined(LLVM_3_1) + optPM.add(new llvm::TargetData(*g->target->getDataLayout())); +#else optPM.add(new llvm::DataLayout(*g->target->getDataLayout())); llvm::TargetMachine *targetMachine = g->target->GetTargetMachine(); -#ifdef LLVM_3_2 + #ifdef LLVM_3_2 optPM.add(new llvm::TargetTransformInfo(targetMachine->getScalarTargetTransformInfo(), targetMachine->getVectorTargetTransformInfo())); -#else // LLVM 3.3+ + #else // LLVM 3.3+ targetMachine->addAnalysisPasses(optPM); + #endif #endif optPM.add(llvm::createIndVarSimplifyPass()); @@ -500,7 +510,7 @@ Optimize(llvm::Module *module, int optLevel) { optPM.add(llvm::createCFGSimplificationPass()); optPM.add(llvm::createArgumentPromotionPass()); -#if defined(LLVM_3_2) || defined(LLVM_3_3) +#if defined(LLVM_3_1) || defined(LLVM_3_2) || defined(LLVM_3_3) // Starting from 3.4 this functionality was moved to // InstructionCombiningPass. See r184459 for details. optPM.add(llvm::createSimplifyLibCallsPass()); diff --git a/stmt.cpp b/stmt.cpp index 412b0dd9..4ec63d35 100644 --- a/stmt.cpp +++ b/stmt.cpp @@ -48,7 +48,7 @@ #include #include -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) || defined(LLVM_3_2) #include #include #include diff --git a/type.cpp b/type.cpp index 11a165f5..5fa1845b 100644 --- a/type.cpp +++ b/type.cpp @@ -43,15 +43,20 @@ #include #include -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) || defined(LLVM_3_2) #include #include #else #include #include #endif -#include -#include +#if defined(LLVM_3_1) + #include + #include +#else + #include + #include +#endif #include @@ -814,8 +819,11 @@ EnumType::GetDIType(llvm::DIDescriptor scope) const { m->diBuilder->createEnumerationType(scope, name, diFile, pos.first_line, 32 /* size in bits */, 32 /* align in bits */, - elementArray, - llvm::DIType()); + elementArray +#if !defined(LLVM_3_1) + , llvm::DIType() +#endif + ); switch (variability.type) { @@ -2131,7 +2139,7 @@ StructType::GetDIType(llvm::DIDescriptor scope) const { currentSize, // Size in bits align, // Alignment in bits 0, // Flags -#if !defined(LLVM_3_2) +#if !defined(LLVM_3_1) && !defined(LLVM_3_2) llvm::DIType(), // DerivedFrom #endif elements); @@ -2374,7 +2382,7 @@ UndefinedStructType::GetDIType(llvm::DIDescriptor scope) const { 0, // Size 0, // Align 0, // Flags -#if !defined(LLVM_3_2) +#if !defined(LLVM_3_1) && !defined(LLVM_3_2) llvm::DIType(), // DerivedFrom #endif elements); @@ -2637,8 +2645,12 @@ ReferenceType::GetDIType(llvm::DIDescriptor scope) const { } llvm::DIType diTargetType = targetType->GetDIType(scope); +#if defined(LLVM_3_1) + return m->diBuilder->createReferenceType(diTargetType); +#else return m->diBuilder->createReferenceType(llvm::dwarf::DW_TAG_reference_type, diTargetType); +#endif } diff --git a/type.h b/type.h index a6a52e10..880f8574 100644 --- a/type.h +++ b/type.h @@ -40,7 +40,7 @@ #include "ispc.h" #include "util.h" -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) || defined(LLVM_3_2) #include #include #else diff --git a/util.cpp b/util.cpp index 4be863bf..dbea9517 100644 --- a/util.cpp +++ b/util.cpp @@ -65,7 +65,9 @@ #include #include -#if defined(LLVM_3_2) +#if defined(LLVM_3_1) + #include +#elif defined(LLVM_3_2) #include #else // LLVM 3.3+ #include @@ -614,8 +616,13 @@ VerifyDataLayoutCompatibility(const std::string &module_dl, // which contradic: f80:128:128 followed by f80:32:32. This is a bug, but // correct thing to do is to interpret this exactly how LLVM would treat it, // so we create a DataLayout class and take its string representation. +#if defined(LLVM_3_1) + llvm::TargetData d1(module_dl); + llvm::TargetData d2(lib_dl); +#else // LLVM 3.2+ llvm::DataLayout d1(module_dl); llvm::DataLayout d2(lib_dl); +#endif std::string module_dl_canonic = d1.getStringRepresentation(); std::string lib_dl_canonic = d2.getStringRepresentation();