diff --git a/builtins.cpp b/builtins.cpp index 65f31856..9cc36fc0 100644 --- a/builtins.cpp +++ b/builtins.cpp @@ -47,10 +47,10 @@ #include #include -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_3 #include #endif -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_3 #include #include #include @@ -66,7 +66,7 @@ #include #include #endif -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) // LLVM 3.5+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5 #include #else #include @@ -784,13 +784,13 @@ void AddBitcodeToModule(const unsigned char *bitcode, int length, llvm::Module *module, SymbolTable *symbolTable, bool warn) { llvm::StringRef sb = llvm::StringRef((char *)bitcode, length); -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_2 && ISPC_LLVM_VERSION < ISPC_LLVM_3_6 llvm::MemoryBuffer *bcBuf = llvm::MemoryBuffer::getMemBuffer(sb); #else // LLVM 3.6+ llvm::MemoryBufferRef bcBuf = llvm::MemoryBuffer::getMemBuffer(sb)->getMemBufferRef(); #endif -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) // LLVM 3.5+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5 llvm::ErrorOr ModuleOrErr = llvm::parseBitcodeFile(bcBuf, *g->ctx); if (std::error_code EC = ModuleOrErr.getError()) Error(SourcePos(), "Error parsing stdlib bitcode: %s", EC.message().c_str()); @@ -850,7 +850,7 @@ AddBitcodeToModule(const unsigned char *bitcode, int length, // architecture and investigate what happened. // Generally we allow library DataLayout to be subset of module // DataLayout or library DataLayout to be empty. -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) // LLVM 3.5+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5 if (!VerifyDataLayoutCompatibility(module->getDataLayoutStr(), bcModule->getDataLayoutStr()) && warn) { @@ -880,7 +880,7 @@ AddBitcodeToModule(const unsigned char *bitcode, int length, std::string(linkError); if (llvm::Linker::LinkModules(module, bcModule -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_2 && ISPC_LLVM_VERSION < ISPC_LLVM_3_6 , llvm::Linker::DestroySource, &linkError)) Error(SourcePos(), "Error linking stdlib bitcode: %s", linkError.c_str()); @@ -917,7 +917,7 @@ lDefineConstantInt(const char *name, int val, llvm::Module *module, symbolTable->AddVariable(sym); if (m->diBuilder != NULL) { -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_2 && ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIFile file; llvm::DIType diType = sym->type->GetDIType(file); Assert(diType.Verify()); @@ -932,7 +932,7 @@ lDefineConstantInt(const char *name, int val, llvm::Module *module, // have the DW_AT_artifical attribute. It's not clear if this // matters for anything though. -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_2 && ISPC_LLVM_VERSION < ISPC_LLVM_3_6 llvm::DIGlobalVariable var = m->diBuilder->createGlobalVariable( name, file, @@ -940,7 +940,7 @@ lDefineConstantInt(const char *name, int val, llvm::Module *module, diType, true /* static */, sym->storagePtr); -#elif defined(LLVM_3_6) +#elif ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /* i.e., 3.6 */ llvm::Constant *sym_const_storagePtr = llvm::dyn_cast(sym->storagePtr); Assert(sym_const_storagePtr); llvm::DIGlobalVariable var = m->diBuilder->createGlobalVariable( @@ -965,10 +965,10 @@ lDefineConstantInt(const char *name, int val, llvm::Module *module, true /* static */, sym_const_storagePtr); #endif -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_2 && ISPC_LLVM_VERSION < ISPC_LLVM_3_7 Assert(var.Verify()); #else // LLVM 3.7+ - //comming soon + //coming soon #endif } } @@ -984,7 +984,7 @@ lDefineConstantIntFunc(const char *name, int val, llvm::Module *module, llvm::Function *func = module->getFunction(name); Assert(func != NULL); // it should be declared already... -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_3 func->addFnAttr(llvm::Attributes::AlwaysInline); #else // LLVM 3.3+ func->addFnAttr(llvm::Attribute::AlwaysInline); @@ -1019,7 +1019,7 @@ lDefineProgramIndex(llvm::Module *module, SymbolTable *symbolTable) { symbolTable->AddVariable(sym); if (m->diBuilder != NULL) { -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_2 && ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIFile file; llvm::DIType diType = sym->type->GetDIType(file); Assert(diType.Verify()); @@ -1030,10 +1030,13 @@ lDefineProgramIndex(llvm::Module *module, SymbolTable *symbolTable) { llvm::DIType *diType = sym->type->GetDIType(file); // Assert(diType.Verify()); #endif -#if defined(LLVM_3_6)// LLVM 3.6+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_6 llvm::Constant *sym_const_storagePtr = llvm::dyn_cast(sym->storagePtr); Assert(sym_const_storagePtr); - llvm::DIGlobalVariable var = m->diBuilder->createGlobalVariable( +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 + llvm::DIGlobalVariable var = +#endif + m->diBuilder->createGlobalVariable( file, sym->name.c_str(), sym->name.c_str(), @@ -1042,7 +1045,7 @@ lDefineProgramIndex(llvm::Module *module, SymbolTable *symbolTable) { diType, false /* static */, sym_const_storagePtr); -#elif defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) +#elif ISPC_LLVM_VERSION >= ISPC_LLVM_3_2 /* && ISPC_LLVM_VERSION < ISPC_LLVM_3_6 */ llvm::DIGlobalVariable var = m->diBuilder->createGlobalVariable( sym->name.c_str(), file, @@ -1063,10 +1066,10 @@ lDefineProgramIndex(llvm::Module *module, SymbolTable *symbolTable) { false /* static */, sym_const_storagePtr); #endif -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_2 && ISPC_LLVM_VERSION < ISPC_LLVM_3_7 Assert(var.Verify()); #else // LLVM 3.7+ - //comming soon + //coming soon #endif } } diff --git a/cbackend.cpp b/cbackend.cpp index ad0ba32a..aa2385eb 100644 --- a/cbackend.cpp +++ b/cbackend.cpp @@ -32,7 +32,7 @@ #include "llvmutil.h" -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION == ISPC_LLVM_3_2 #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" #include "llvm/CallingConv.h" @@ -41,7 +41,7 @@ #include "llvm/Intrinsics.h" #include "llvm/IntrinsicInst.h" #include "llvm/InlineAsm.h" -#else +#else /* LLVM 3.3+ */ #include "llvm/IR/Constants.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/CallingConv.h" @@ -52,29 +52,29 @@ #include "llvm/IR/InlineAsm.h" #endif #include "llvm/Pass.h" -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /* <= 3.6 */ #include "llvm/PassManager.h" -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ #include "llvm/IR/LegacyPassManager.h" #endif -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION == ISPC_LLVM_3_2 #include "llvm/TypeFinder.h" -#else // LLVM_3_3 + +#else /* LLVM_3_3+ */ #include "llvm/IR/TypeFinder.h" #endif #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/STLExtras.h" -#if defined(LLVM_3_4) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_5 /* 3.2, 3.3, 3.4 */ #include "llvm/Support/InstIterator.h" -#else +#else /* 3.5+ */ #include "llvm/IR/InstIterator.h" #endif -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_6 #include "llvm/Analysis/FindUsedTypes.h" #endif #include "llvm/Analysis/LoopInfo.h" -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5 #include "llvm/IR/Verifier.h" #include #include "llvm/IR/CallSite.h" @@ -100,18 +100,18 @@ #include "llvm/MC/MCRegisterInfo.h" #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/MC/MCSymbol.h" -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_3 /* 3.2 */ #include "llvm/DataLayout.h" -#else // LLVM 3.3+ +#else /* LLVM 3.3+ */ #include "llvm/IR/DataLayout.h" #endif #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FormattedStream.h" -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_3 /* 3.2 */ #include "llvm/Support/InstVisitor.h" -#elif defined (LLVM_3_3) || defined (LLVM_3_4) +#elif ISPC_LLVM_VERSION < ISPC_LLVM_3_5 /* 3.3, 3.4 */ #include "llvm/InstVisitor.h" -#else // LLVM 3.5+ +#else /* LLVM 3.5+ */ #include "llvm/IR/InstVisitor.h" #endif #include "llvm/Support/MathExtras.h" @@ -119,7 +119,7 @@ #include "llvm/Support/Host.h" #include "llvm/Target/TargetMachine.h" -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_5 /* 3.2, 3.3, 3.4 */ #include "llvm/Config/config.h" #endif @@ -139,7 +139,7 @@ namespace constant_scanner { class constant_iterator : public std::iterator { - llvm::const_inst_iterator InstI; // Method instruction iterator + llvm::const_inst_iterator InstI; // Method instruction iterator unsigned OpIdx; // Operand index bool isAtConstant() const { @@ -206,7 +206,7 @@ namespace { // To avoid walking constant expressions multiple times and other IR // objects, we keep several helper maps. llvm::DenseSet VisitedConstants; -#if !defined (LLVM_3_2) && !defined (LLVM_3_3) && !defined (LLVM_3_4) && !defined (LLVM_3_5)// LLVN 3.6++ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_6 // LLVM 3.6+ llvm::DenseSet VisitedMDNodes; #endif llvm::DenseSet VisitedTypes; @@ -312,12 +312,12 @@ namespace { /// walked in other ways. GlobalValues, basic blocks, instructions, and /// inst operands are all explicitly enumerated. void incorporateValue(const llvm::Value *V) { -#if defined (LLVM_3_2) || defined (LLVM_3_3)|| defined (LLVM_3_4)|| defined (LLVM_3_5) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_6 // 3.2, 3.3, 3.4, 3.5 */ if (const llvm::MDNode *M = llvm::dyn_cast(V)) { incorporateMDNode(M); return; } -#else // LLVN 3.6++ +#else /* LLVN 3.6+ */ if (const llvm::MetadataAsValue *MV = llvm::dyn_cast(V)) { incorporateMDNode(MV->getMetadata()); return; @@ -339,7 +339,7 @@ namespace { incorporateValue(*I); } -#if defined (LLVM_3_2) || defined (LLVM_3_3)|| defined (LLVM_3_4)|| defined (LLVM_3_5) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_6 // 3.2, 3.3, 3.4, 3.5 */ void incorporateMDNode(const llvm::MDNode *V) { // Already visited? @@ -351,7 +351,7 @@ namespace { if (llvm::Value *Op = V->getOperand(i)) incorporateValue(Op); } -#else // LLVM 3.6+ +#else /* LLVM 3.6+ */ void incorporateMDNode(const llvm::Metadata *M) { // Already visited? @@ -397,7 +397,7 @@ namespace { public: CBEMCAsmInfo() { -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_5 /* 3.2, 3.3, 3.4 */ GlobalPrefix = ""; #endif PrivateGlobalPrefix = ""; @@ -449,9 +449,9 @@ namespace { OpaqueCounter(0), NextAnonValueNumber(0), includeName(incname ? incname : "generic_defs.h"), vectorWidth(vecwidth) { -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /* < 3.6 */ initializeLoopInfoPass(*llvm::PassRegistry::getPassRegistry()); -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ initializeLoopInfoWrapperPassPass(*llvm::PassRegistry::getPassRegistry()); #endif FPCounter = 0; @@ -461,9 +461,9 @@ namespace { virtual const char *getPassName() const { return "C backend"; } void getAnalysisUsage(llvm::AnalysisUsage &AU) const { -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /* < 3.6 */ AU.addRequired(); -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ AU.addRequired(); #endif AU.setPreservesAll(); @@ -477,9 +477,9 @@ namespace { if (F.hasAvailableExternallyLinkage()) return false; -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /* < 3.6 */ LI = &getAnalysis(); -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ LI = &getAnalysis().getLoopInfo(); #endif @@ -519,9 +519,9 @@ namespace { bool isSigned = false, const std::string &VariableName = "", bool IgnoreName = false, -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION == ISPC_LLVM_3_2 const llvm::AttrListPtr &PAL = llvm::AttrListPtr() -#else +#else /* LLVM 3.3+ */ const llvm::AttributeSet &PAL = llvm::AttributeSet() #endif ); @@ -530,9 +530,9 @@ namespace { const std::string &NameSoFar = ""); void printStructReturnPointerFunctionType(llvm::raw_ostream &Out, -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION == ISPC_LLVM_3_2 const llvm::AttrListPtr &PAL, -#else +#else /* LLVM 3.3+ */ const llvm::AttributeSet &PAL, #endif llvm::PointerType *Ty); @@ -610,7 +610,7 @@ namespace { if (llvm::isa(I) && llvm::isa(I.getType()) == false) return true; -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) // LLVM 3.5+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5 // 3.5+ // This instruction returns a struct on LLVM older than 3.4, and can not be inlined if (llvm::isa(I)) return false; @@ -628,7 +628,7 @@ namespace { // Must not be used in inline asm, extractelement, or shufflevector. if (I.hasOneUse()) { -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5 // 3.5+ const llvm::Instruction &User = llvm::cast(*I.user_back()); #else const llvm::Instruction &User = llvm::cast(*I.use_back()); @@ -640,7 +640,7 @@ namespace { } // Only inline instruction it if it's use is in the same BB as the inst. -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5 // 3.5+ return I.getParent() == llvm::cast(I.user_back())->getParent(); #else return I.getParent() == llvm::cast(I.use_back())->getParent(); @@ -776,9 +776,9 @@ 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 ISPC_LLVM_VERSION == ISPC_LLVM_3_2 const llvm::AttrListPtr &PAL, -#else +#else /* LLVM 3.3+ */ const llvm::AttributeSet &PAL, #endif llvm::PointerType *TheTy) { @@ -795,18 +795,18 @@ void CWriter::printStructReturnPointerFunctionType(llvm::raw_ostream &Out, if (PrintedType) FunctionInnards << ", "; llvm::Type *ArgTy = *I; -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION == ISPC_LLVM_3_2 if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) { -#else +#else /* LLVM 3.3+ */ 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 ISPC_LLVM_VERSION == ISPC_LLVM_3_2 PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt), -#else +#else /* LLVM 3.3+ */ PAL.getParamAttributes(Idx).hasAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::SExt), #endif ""); @@ -821,9 +821,9 @@ void CWriter::printStructReturnPointerFunctionType(llvm::raw_ostream &Out, } FunctionInnards << ')'; printType(Out, RetTy, -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION == ISPC_LLVM_3_2 PAL.getParamAttributes(0).hasAttribute(llvm::Attributes::SExt), -#else +#else /* LLVM 3.3+ */ PAL.getParamAttributes(0).hasAttribute(llvm::AttributeSet::ReturnIndex, llvm::Attribute::SExt), #endif FunctionInnards.str()); @@ -919,9 +919,9 @@ 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 ISPC_LLVM_VERSION == ISPC_LLVM_3_2 const llvm::AttrListPtr &PAL -#else +#else /* LLVM 3.3+ */ const llvm::AttributeSet &PAL #endif ) { @@ -941,9 +941,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 ISPC_LLVM_VERSION == ISPC_LLVM_3_2 if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) { -#else +#else /* LLVM 3.3+ */ if (PAL.getParamAttributes(Idx).hasAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::ByVal)) { #endif assert(ArgTy->isPointerTy()); @@ -952,9 +952,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 ISPC_LLVM_VERSION == ISPC_LLVM_3_2 PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt), -#else +#else /* LLVM 3.3+ */ PAL.getParamAttributes(Idx).hasAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::SExt), #endif ""); @@ -969,9 +969,9 @@ llvm::raw_ostream &CWriter::printType(llvm::raw_ostream &Out, llvm::Type *Ty, } FunctionInnards << ')'; printType(Out, FTy->getReturnType(), -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION == ISPC_LLVM_3_2 PAL.getParamAttributes(0).hasAttribute(llvm::Attributes::SExt), -#else +#else /* LLVM 3.3+ */ PAL.getParamAttributes(0).hasAttribute(llvm::AttributeSet::ReturnIndex, llvm::Attribute::SExt), #endif FunctionInnards.str()); @@ -1585,7 +1585,8 @@ void CWriter::printConstant(llvm::Constant *CPV, bool Static) { Out << CI->getZExtValue() << "ull"; else if (Ty->getPrimitiveSizeInBits() > 64) { Out << "\""; - const uint64_t *Ptr64 = CPV->getUniqueInteger().getRawData(); + //const uint64_t *Ptr64 = CPV->getUniqueInteger().getRawData(); + const uint64_t *Ptr64 = CI->getValue().getRawData(); for (int i = 0; i < Ty->getPrimitiveSizeInBits(); i++) { Out << ((Ptr64[i / (sizeof (uint64_t) * 8)] >> (i % (sizeof (uint64_t) * 8))) & 1); } @@ -1956,9 +1957,9 @@ std::string CWriter::GetValueName(const llvm::Value *Operand) { // Resolve potential alias. if (const llvm::GlobalAlias *GA = llvm::dyn_cast(Operand)) { -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5 /* LLVM 3.5+ */ if (const llvm::Value *V = GA->getAliasee()) -#else +#else /* <= LLVM 3.4 */ if (const llvm::Value *V = GA->resolveAliasedGlobal(false)) #endif Operand = V; @@ -2332,7 +2333,7 @@ static SpecialGlobalClass getGlobalVariableClass(const llvm::GlobalVariable *GV) // Otherwise, if it is other metadata, don't print it. This catches things // like debug information. -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5 /* LLVM 3.5+ */ // Here we compare char * if (!strcmp(GV->getSection(), "llvm.metadata")) #else @@ -2390,7 +2391,7 @@ bool CWriter::doInitialization(llvm::Module &M) { #endif TAsm = new CBEMCAsmInfo(); MRI = new llvm::MCRegisterInfo(); -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_4 /* LLVM 3.4+ */ TCtx = new llvm::MCContext(TAsm, MRI, NULL); #else TCtx = new llvm::MCContext(*TAsm, *MRI, NULL); @@ -2514,7 +2515,7 @@ bool CWriter::doInitialization(llvm::Module &M) { if (I->hasExternalLinkage() || I->hasExternalWeakLinkage() || I->hasCommonLinkage()) Out << "extern "; -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5 /* LLVM 3.5+ */ else if (I->hasDLLImportStorageClass()) #else else if (I->hasDLLImportLinkage()) @@ -2691,7 +2692,7 @@ bool CWriter::doInitialization(llvm::Module &M) { if (I->hasLocalLinkage()) Out << "static "; -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5 /* LLVM 3.5+ */ else if (I->hasDLLImportStorageClass()) Out << "__declspec(dllimport) "; else if (I->hasDLLExportStorageClass()) Out << "__declspec(dllexport) "; #else @@ -3040,7 +3041,7 @@ void CWriter::printContainedStructs(llvm::Type *Ty, if (llvm::StructType *ST = llvm::dyn_cast(Ty)) { // Check to see if we have already printed this struct. -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) && !defined(LLVM_3_5) // LLVM 3.6+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_6 /* LLVM 3.6+ */ if (!Printed.insert(Ty).second) return; #else if (!Printed.insert(Ty)) return; @@ -3051,7 +3052,7 @@ void CWriter::printContainedStructs(llvm::Type *Ty, Out << ";\n\n"; } if (llvm::ArrayType *AT = llvm::dyn_cast(Ty)) { -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) && !defined(LLVM_3_5) // LLVM 3.6+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_6 /* LLVM 3.6+ */ if (!Printed.insert(Ty).second) return; #else if (!Printed.insert(Ty)) return; @@ -3065,7 +3066,7 @@ void CWriter::printContainedStructs(llvm::Type *Ty, void CWriter::printContainedArrays(llvm::ArrayType *ATy, llvm::SmallPtrSet &Printed) { -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) && !defined(LLVM_3_5) // LLVM 3.6+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_6 /* LLVM 3.6+ */ if (!Printed.insert(ATy).second) return; #else @@ -3086,7 +3087,7 @@ void CWriter::printFunctionSignature(const llvm::Function *F, bool Prototype) { bool isStructReturn = F->hasStructRetAttr(); if (F->hasLocalLinkage()) Out << "static "; -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) // LLVM 3.5+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5 /* LLVM 3.5+ */ if (F->hasDLLImportStorageClass()) Out << "__declspec(dllimport) "; if (F->hasDLLExportStorageClass()) Out << "__declspec(dllexport) "; #else @@ -3109,9 +3110,9 @@ 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 ISPC_LLVM_VERSION == ISPC_LLVM_3_2 const llvm::AttrListPtr &PAL = F->getAttributes(); -#else +#else /* LLVM 3.3+ */ const llvm::AttributeSet &PAL = F->getAttributes(); #endif @@ -3143,18 +3144,18 @@ void CWriter::printFunctionSignature(const llvm::Function *F, bool Prototype) { else ArgName = ""; llvm::Type *ArgTy = I->getType(); -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION == ISPC_LLVM_3_2 if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) { -#else +#else /* LLVM 3.3+ */ 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 ISPC_LLVM_VERSION == ISPC_LLVM_3_2 PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt), -#else +#else /* LLVM 3.3+ */ PAL.getParamAttributes(Idx).hasAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::SExt), #endif ArgName); @@ -3178,18 +3179,18 @@ 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 ISPC_LLVM_VERSION == ISPC_LLVM_3_2 if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) { -#else +#else /* LLVM 3.3+ */ 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 ISPC_LLVM_VERSION == ISPC_LLVM_3_2 PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt) -#else +#else /* LLVM 3.3+ */ PAL.getParamAttributes(Idx).hasAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::SExt) #endif ); @@ -3224,9 +3225,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 ISPC_LLVM_VERSION == ISPC_LLVM_3_2 PAL.getParamAttributes(0).hasAttribute(llvm::Attributes::SExt), -#else +#else /* LLVM 3.3+ */ PAL.getParamAttributes(0).hasAttribute(llvm::AttributeSet::ReturnIndex, llvm::Attribute::SExt), #endif FunctionInnards.str()); @@ -3412,7 +3413,7 @@ void CWriter::visitSwitchInst(llvm::SwitchInst &SI) { printPHICopiesForSuccessor (SI.getParent(), Succ, 2); printBranchToBlock(SI.getParent(), Succ, 2); -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) // LLVM 3.5+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5 /* LLVM 3.5+ */ if (llvm::Function::iterator(Succ) == std::next(llvm::Function::iterator(SI.getParent()))) #else if (llvm::Function::iterator(Succ) == llvm::next(llvm::Function::iterator(SI.getParent()))) @@ -3437,7 +3438,7 @@ bool CWriter::isGotoCodeNecessary(llvm::BasicBlock *From, llvm::BasicBlock *To) /// FIXME: This should be reenabled, but loop reordering safe!! return true; -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) // LLVM 3.5+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5 /* LLVM 3.5+ */ if (std::next(llvm::Function::iterator(From)) != llvm::Function::iterator(To)) #else if (llvm::next(llvm::Function::iterator(From)) != llvm::Function::iterator(To)) @@ -4079,9 +4080,9 @@ void CWriter::lowerIntrinsics(llvm::Function &F) { const char *BuiltinName = ""; #define GET_GCC_BUILTIN_NAME #define Intrinsic llvm::Intrinsic -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION == ISPC_LLVM_3_2 #include "llvm/Intrinsics.gen" -#else +#else /* LLVM 3.3+ */ #include "llvm/IR/Intrinsics.gen" #endif #undef Intrinsic @@ -4092,7 +4093,7 @@ void CWriter::lowerIntrinsics(llvm::Function &F) { // All other intrinsic calls we must lower. llvm::Instruction *Before = 0; if (CI != &BB->front()) -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5 /* LLVM 3.5+ */ Before = std::prev(llvm::BasicBlock::iterator(CI)); #else Before = prior(llvm::BasicBlock::iterator(CI)); @@ -4148,9 +4149,9 @@ 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 ISPC_LLVM_VERSION == ISPC_LLVM_3_2 const llvm::AttrListPtr &PAL = I.getAttributes(); -#else +#else /* LLVM 3.3+ */ const llvm::AttributeSet &PAL = I.getAttributes(); #endif bool hasByVal = I.hasByValArgument(); @@ -4258,9 +4259,9 @@ void CWriter::visitCallInst(llvm::CallInst &I) { (*AI)->getType() != FTy->getParamType(ArgNo)) { Out << '('; printType(Out, FTy->getParamType(ArgNo), -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION == ISPC_LLVM_3_2 PAL.getParamAttributes(ArgNo+1).hasAttribute(llvm::Attributes::SExt) -#else +#else /* LLVM 3.3+ */ PAL.getParamAttributes(ArgNo+1).hasAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::SExt) #endif ); @@ -4268,9 +4269,9 @@ void CWriter::visitCallInst(llvm::CallInst &I) { } // Check if the argument is expected to be passed by value. if (I.paramHasAttr(ArgNo+1, -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION == ISPC_LLVM_3_2 llvm::Attributes::ByVal -#else +#else /* LLVM 3.3+ */ llvm::Attribute::ByVal #endif )) { @@ -4296,9 +4297,9 @@ 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 ISPC_LLVM_VERSION == ISPC_LLVM_3_2 #include "llvm/Intrinsics.gen" -#else +#else /* LLVM 3.3+ */ #include "llvm/IR/Intrinsics.gen" #endif #undef Intrinsic @@ -4817,7 +4818,7 @@ void CWriter::visitAtomicRMWInst(llvm::AtomicRMWInst &AI) { void CWriter::visitAtomicCmpXchgInst(llvm::AtomicCmpXchgInst &ACXI) { Out << "("; -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5 /* LLVM 3.5+ */ printType(Out, ACXI.getType(), false); Out << "::init("; // LLVM cmpxchg returns a struct, so we need make an assighment properly #endif @@ -4828,7 +4829,7 @@ void CWriter::visitAtomicCmpXchgInst(llvm::AtomicCmpXchgInst &ACXI) { Out << ", "; writeOperand(ACXI.getNewValOperand()); Out << ")"; -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5 /* LLVM 3.5+ */ Out << ", true /* There is no way to learn the value of this bit inside ISPC, so making it constant */)"; #endif Out << ")"; @@ -4932,7 +4933,11 @@ SmearCleanupPass::getShuffleSmearValue(llvm::Instruction* inst) const { // Check that the shuffle is a broadcast of the element of the first vector, // i.e. mask vector is vector with equal elements of expected size. if (!(mask && +#if ISPC_LLVM_VERSION == ISPC_LLVM_3_2 + (mask->isNullValue() || (shuffleInst->getMask()->getType()->isVectorTy() && llvm::dyn_cast(shuffleInst->getMask())->getSplatValue() != 0 ) ) && +#else (mask->isNullValue() || (shuffleInst->getMask()->getSplatValue() != 0))&& +#endif llvm::dyn_cast(mask->getType())->getNumElements() == vectorWidth)) { return NULL; } @@ -4973,8 +4978,14 @@ SmearCleanupPass::getShuffleSmearValue(llvm::Instruction* inst) const { return NULL; } llvm::Instruction *extractCall = - llvm::ExtractElementInst::Create(shuffleInst->getOperand(0), mask->getSplatValue(), - "__extract_element", inst); + llvm::ExtractElementInst::Create(shuffleInst->getOperand(0), +#if ISPC_LLVM_VERSION == ISPC_LLVM_3_2 + // mask is of VectorType + llvm::dyn_cast(mask)->getSplatValue(), +#else + mask->getSplatValue(), +#endif + "__extract_element", inst); return extractCall; } @@ -5150,10 +5161,10 @@ public: notFunc = llvm::dyn_cast(m->getOrInsertFunction("__not", mt, mt, NULL)); assert(notFunc != NULL); -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION == ISPC_LLVM_3_2 notFunc->addFnAttr(llvm::Attributes::NoUnwind); notFunc->addFnAttr(llvm::Attributes::ReadNone); -#else +#else /* LLVM 3.3+ */ notFunc->addFnAttr(llvm::Attribute::NoUnwind); notFunc->addFnAttr(llvm::Attribute::ReadNone); #endif @@ -5162,10 +5173,10 @@ public: llvm::dyn_cast(m->getOrInsertFunction("__and_not1", mt, mt, mt, NULL)); assert(andNotFuncs[0] != NULL); -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION == ISPC_LLVM_3_2 andNotFuncs[0]->addFnAttr(llvm::Attributes::NoUnwind); andNotFuncs[0]->addFnAttr(llvm::Attributes::ReadNone); -#else +#else /* LLVM 3.3+ */ andNotFuncs[0]->addFnAttr(llvm::Attribute::NoUnwind); andNotFuncs[0]->addFnAttr(llvm::Attribute::ReadNone); #endif @@ -5173,10 +5184,10 @@ public: llvm::dyn_cast(m->getOrInsertFunction("__and_not2", mt, mt, mt, NULL)); assert(andNotFuncs[1] != NULL); -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION == ISPC_LLVM_3_2 andNotFuncs[1]->addFnAttr(llvm::Attributes::NoUnwind); andNotFuncs[1]->addFnAttr(llvm::Attributes::ReadNone); -#else +#else /* LLVM 3.3+ */ andNotFuncs[1]->addFnAttr(llvm::Attribute::NoUnwind); andNotFuncs[1]->addFnAttr(llvm::Attribute::ReadNone); #endif @@ -5304,9 +5315,9 @@ bool WriteCXXFile(llvm::Module *module, const char *fn, int vectorWidth, const char *includeName) { -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /* 3.2, 3.3, 3.4, 3.5, 3.6 */ llvm::PassManager pm; -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ llvm::legacy::PassManager pm; #endif #if 0 @@ -5316,23 +5327,23 @@ 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 ISPC_LLVM_VERSION < ISPC_LLVM_3_4 /* 3.2, 3.3 */ int flags = 0; -#else +#else /* LLVM 3.4+ */ llvm::sys::fs::OpenFlags flags = llvm::sys::fs::F_None; #endif -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_6 /* 3.2, 3.3, 3.4, 3.5 */ std::string error; -#else // LLVM 3.6+ +#else /* LLVM 3.6+ */ std::error_code error; #endif llvm::tool_output_file *of = new llvm::tool_output_file(fn, error, flags); -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_6 /* 3.2, 3.3, 3.4, 3.5 */ if (error.size()) { -#else // LLVM 3.6+ +#else /* LLVM 3.6+ */ if (error) { #endif fprintf(stderr, "Error opening output file \"%s\".\n", fn); @@ -5350,7 +5361,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 ISPC_LLVM_VERSION == ISPC_LLVM_3_2 // This interface is depricated for 3.3+ pm.add(llvm::createGCInfoDeleter()); #endif diff --git a/ctx.cpp b/ctx.cpp index 082759b9..fdf80c56 100644 --- a/ctx.cpp +++ b/ctx.cpp @@ -46,7 +46,7 @@ #include "sym.h" #include #include -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION == ISPC_LLVM_3_2 #include #include #include @@ -337,25 +337,27 @@ FunctionEmitContext::FunctionEmitContext(Function *func, Symbol *funSym, /* If debugging is enabled, tell the debug information emission code about this new function */ -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /* 3.2, 3.3, 3.4, 3.5, 3.6 */ diFile = funcStartPos.GetDIFile(); AssertPos(currentPos, diFile.Verify()); -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ diFile = funcStartPos.GetDIFile(); #endif -#if defined(LLVM_3_2) || defined(LLVM_3_3) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_4 /* 3.2, 3.3 */ llvm::DIScope scope = llvm::DIScope(m->diBuilder->getCU()); -#elif defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#elif ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /* 3.4, 3.5, 3.6 */ llvm::DIScope scope = llvm::DIScope(m->diCompileUnit); -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ llvm::DIScope *scope = m->diCompileUnit; + //llvm::MDScope *scope = m->diCompileUnit; #endif -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /* 3.2, 3.3, 3.4, 3.5, 3.6 */ llvm::DIType diSubprogramType; AssertPos(currentPos, scope.Verify()); -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ llvm::DIType *diSubprogramType = NULL; + //llvm::MDType *diSubprogramType = NULL; #endif const FunctionType *functionType = function->GetType(); @@ -363,21 +365,22 @@ FunctionEmitContext::FunctionEmitContext(Function *func, Symbol *funSym, AssertPos(currentPos, m->errorCount > 0); else { diSubprogramType = functionType->GetDIType(scope); -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /* 3.2, 3.3, 3.4, 3.5, 3.6 */ AssertPos(currentPos, diSubprogramType.Verify()); -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ //comming soon #endif } -#if defined(LLVM_3_2) || defined(LLVM_3_3) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_4 /* 3.2, 3.3 */ llvm::DIType diSubprogramType_n = diSubprogramType; -#elif defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) + int flags = llvm::DIDescriptor::FlagPrototyped; +#elif ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /* 3.4, 3.5, 3.6 */ Assert(diSubprogramType.isCompositeType()); llvm::DICompositeType diSubprogramType_n = static_cast(diSubprogramType); int flags = llvm::DIDescriptor::FlagPrototyped; -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ Assert(llvm::isa(diSubprogramType)); llvm::DISubroutineType *diSubprogramType_n = llvm::cast(getDICompositeType(diSubprogramType)); @@ -392,7 +395,7 @@ FunctionEmitContext::FunctionEmitContext(Function *func, Symbol *funSym, bool isOptimized = (g->opt.level > 0); int firstLine = funcStartPos.first_line; -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /* 3.2, 3.3, 3.4, 3.5, 3.6 */ diSubprogram = m->diBuilder->createFunction(diFile /* scope */, funSym->name, mangledName, diFile, @@ -401,7 +404,7 @@ FunctionEmitContext::FunctionEmitContext(Function *func, Symbol *funSym, firstLine, flags, isOptimized, llvmFunction); AssertPos(currentPos, diSubprogram.Verify()); -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ diSubprogram = m->diBuilder->createFunction(diFile /* scope */, funSym->name, mangledName, diFile, @@ -1610,9 +1613,9 @@ lGetStringAsValue(llvm::BasicBlock *bblock, const char *s) { sConstant, var_name.c_str()); llvm::Value *indices[2] = { LLVMInt32(0), LLVMInt32(0) }; llvm::ArrayRef arrayRef(&indices[0], &indices[2]); -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /* 3.2, 3.3, 3.4, 3.5, 3.6 */ return llvm::GetElementPtrInst::Create(sPtr, arrayRef, "sptr", bblock); -#else // LLVM 3.7++ +#else /* LLVM 3.7+ */ return llvm::GetElementPtrInst::Create(PTYPE(sPtr), sPtr, arrayRef, "sptr", bblock); #endif @@ -1654,10 +1657,11 @@ FunctionEmitContext::GetDebugPos() const { void FunctionEmitContext::AddDebugPos(llvm::Value *value, const SourcePos *pos, -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /* 3.2, 3.3, 3.4, 3.5, 3.6 */ llvm::DIScope *scope) { -#else // LLVM 3.7++ +#else /* LLVM 3.7+ */ llvm::DIScope *scope) { + //llvm::MDScope *scope) { #endif llvm::Instruction *inst = llvm::dyn_cast(value); if (inst != NULL && m->diBuilder) { @@ -1668,9 +1672,9 @@ FunctionEmitContext::AddDebugPos(llvm::Value *value, const SourcePos *pos, // for those functions inst->setDebugLoc(llvm::DebugLoc::get(p.first_line, p.first_column, scope ? -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /* 3.2, 3.3, 3.4, 3.5, 3.6 */ *scope -#else // LLVM 3.7++ +#else /* LLVM 3.7+ */ scope #endif : GetDIScope())); @@ -1681,12 +1685,14 @@ FunctionEmitContext::AddDebugPos(llvm::Value *value, const SourcePos *pos, void FunctionEmitContext::StartScope() { if (m->diBuilder != NULL) { -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /* 3.2, 3.3, 3.4, 3.5, 3.6 */ llvm::DIScope parentScope; llvm::DILexicalBlock lexicalBlock; -#else // LLVM 3.7++ +#else /* LLVM 3.7+ */ llvm::DIScope *parentScope; llvm::DILexicalBlock *lexicalBlock; + //llvm::MDScope *parentScope; + //llvm::MDLexicalBlock *lexicalBlock; #endif if (debugScopes.size() > 0) parentScope = debugScopes.back(); @@ -1696,7 +1702,7 @@ FunctionEmitContext::StartScope() { lexicalBlock = m->diBuilder->createLexicalBlock(parentScope, diFile, currentPos.first_line, -#if defined(LLVM_3_5) +#if ISPC_LLVM_VERSION == ISPC_LLVM_3_5 // Revision 202736 in LLVM adds support of DWARF discriminator // to the last argument and revision 202737 in clang adds 0 // for the last argument by default. @@ -1706,11 +1712,12 @@ FunctionEmitContext::StartScope() { // as the last argument currentPos.first_column); #endif // LLVM 3.2, 3.3, 3.4 and 3.6+ -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /* 3.2, 3.3, 3.4, 3.5, 3.6 */ AssertPos(currentPos, lexicalBlock.Verify()); debugScopes.push_back(lexicalBlock); -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ debugScopes.push_back(llvm::cast(lexicalBlock)); + //debugScopes.push_back(llvm::cast(lexicalBlock)); #endif } } @@ -1725,10 +1732,11 @@ FunctionEmitContext::EndScope() { } -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /* 3.2, 3.3, 3.4, 3.5, 3.6 */ llvm::DIScope -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ llvm::DIScope* +//llvm::MDScope* #endif FunctionEmitContext::GetDIScope() const { AssertPos(currentPos, debugScopes.size() > 0); @@ -1741,15 +1749,18 @@ FunctionEmitContext::EmitVariableDebugInfo(Symbol *sym) { if (m->diBuilder == NULL) return; -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /* 3.2, 3.3, 3.4, 3.5, 3.6 */ llvm::DIScope scope = GetDIScope(); llvm::DIType diType = sym->type->GetDIType(scope); AssertPos(currentPos, diType.Verify()); llvm::DIVariable var = -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ llvm::DIScope *scope = GetDIScope(); llvm::DIType *diType = sym->type->GetDIType(scope); llvm::DILocalVariable *var = + //llvm::MDScope *scope = GetDIScope(); + //llvm::MDType *diType = sym->type->GetDIType(scope); + //llvm::MDLocalVariable *var = #endif m->diBuilder->createLocalVariable(llvm::dwarf::DW_TAG_auto_variable, scope, @@ -1758,16 +1769,16 @@ FunctionEmitContext::EmitVariableDebugInfo(Symbol *sym) { sym->pos.first_line, diType, true /* preserve through opts */); -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /* 3.2, 3.3, 3.4, 3.5, 3.6 */ AssertPos(currentPos, var.Verify()); llvm::Instruction *declareInst = m->diBuilder->insertDeclare(sym->storagePtr, var, - #if defined(LLVM_3_6) + #if ISPC_LLVM_VERSION == ISPC_LLVM_3_6 m->diBuilder->createExpression(), #endif bblock); AddDebugPos(declareInst, &sym->pos, &scope); -#else // LLVM 3.7++ +#else /* LLVM 3.7+ */ llvm::Instruction *declareInst = m->diBuilder->insertDeclare(sym->storagePtr, var, m->diBuilder->createExpression(), @@ -1785,15 +1796,18 @@ FunctionEmitContext::EmitFunctionParameterDebugInfo(Symbol *sym, int argNum) { return; int flags = 0; -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /* 3.2, 3.3, 3.4, 3.5, 3.6 */ llvm::DIScope scope = diSubprogram; llvm::DIType diType = sym->type->GetDIType(scope); AssertPos(currentPos, diType.Verify()); llvm::DIVariable var = -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ llvm::DIScope *scope = diSubprogram; llvm::DIType *diType = sym->type->GetDIType(scope); llvm::DILocalVariable *var = + //llvm::MDScope *scope = diSubprogram; + //llvm::MDType *diType = sym->type->GetDIType(scope); + //llvm::MDLocalVariable *var = #endif m->diBuilder->createLocalVariable(llvm::dwarf::DW_TAG_arg_variable, scope, @@ -1804,16 +1818,16 @@ FunctionEmitContext::EmitFunctionParameterDebugInfo(Symbol *sym, int argNum) { true /* preserve through opts */, flags, argNum + 1); -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /* 3.2, 3.3, 3.4, 3.5, 3.6 */ AssertPos(currentPos, var.Verify()); llvm::Instruction *declareInst = m->diBuilder->insertDeclare(sym->storagePtr, var, - #if defined(LLVM_3_6) + #if ISPC_LLVM_VERSION == ISPC_LLVM_3_6 m->diBuilder->createExpression(), #endif bblock); AddDebugPos(declareInst, &sym->pos, &scope); -#else // LLVM 3.7++ +#else /* LLVM 3.7+ */ llvm::Instruction *declareInst = m->diBuilder->insertDeclare(sym->storagePtr, var, m->diBuilder->createExpression(), @@ -2430,11 +2444,11 @@ FunctionEmitContext::GetElementPtrInst(llvm::Value *basePtr, llvm::Value *index, // uniform, so just emit the regular LLVM GEP instruction llvm::Value *ind[1] = { index }; llvm::ArrayRef arrayRef(&ind[0], &ind[1]); -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /* 3.2, 3.3, 3.4, 3.5, 3.6 */ llvm::Instruction *inst = llvm::GetElementPtrInst::Create(basePtr, arrayRef, name ? name : "gep", bblock); -#else // LLVM 3.7++ +#else /* LLVM 3.7+ */ llvm::Instruction *inst = llvm::GetElementPtrInst::Create(PTYPE(basePtr), basePtr, arrayRef, @@ -2497,11 +2511,11 @@ FunctionEmitContext::GetElementPtrInst(llvm::Value *basePtr, llvm::Value *index0 // uniform, so just emit the regular LLVM GEP instruction llvm::Value *indices[2] = { index0, index1 }; llvm::ArrayRef arrayRef(&indices[0], &indices[2]); -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /* 3.2, 3.3, 3.4, 3.5, 3.6 */ llvm::Instruction *inst = llvm::GetElementPtrInst::Create(basePtr, arrayRef, name ? name : "gep", bblock); -#else // LLVM 3.7++ +#else /* LLVM 3.7+ */ llvm::Instruction *inst = llvm::GetElementPtrInst::Create(PTYPE(basePtr), basePtr, arrayRef, @@ -2598,11 +2612,11 @@ FunctionEmitContext::AddElementOffset(llvm::Value *fullBasePtr, int elementNum, // If the pointer is uniform, we can use the regular LLVM GEP. llvm::Value *offsets[2] = { LLVMInt32(0), LLVMInt32(elementNum) }; llvm::ArrayRef arrayRef(&offsets[0], &offsets[2]); -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /* 3.2, 3.3, 3.4, 3.5, 3.6 */ resultPtr = llvm::GetElementPtrInst::Create(basePtr, arrayRef, name ? name : "struct_offset", bblock); -#else // LLVM 3.7++ +#else /* LLVM 3.7+ */ resultPtr = llvm::GetElementPtrInst::Create(PTYPE(basePtr), basePtr, arrayRef, name ? name : "struct_offset", bblock); @@ -2909,41 +2923,41 @@ FunctionEmitContext::addGSMetadata(llvm::Value *v, SourcePos pos) { llvm::Instruction *inst = llvm::dyn_cast(v); if (inst == NULL) return; -#if defined (LLVM_3_2) || defined (LLVM_3_3)|| defined (LLVM_3_4)|| defined (LLVM_3_5) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_6 /* 3.2, 3.3, 3.4, 3.5 */ llvm::Value *str = llvm::MDString::get(*g->ctx, pos.name); -#else // LLVN 3.6++ +#else /* LLVN 3.6+ */ llvm::MDString *str = llvm::MDString::get(*g->ctx, pos.name); #endif llvm::MDNode *md = llvm::MDNode::get(*g->ctx, str); inst->setMetadata("filename", md); -#if defined (LLVM_3_2) || defined (LLVM_3_3)|| defined (LLVM_3_4)|| defined (LLVM_3_5) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_6 /* 3.2, 3.3, 3.4, 3.5 */ llvm::Value *first_line = LLVMInt32(pos.first_line); -#else // LLVN 3.6++ +#else /* LLVN 3.6+ */ llvm::Metadata *first_line = llvm::ConstantAsMetadata::get(LLVMInt32(pos.first_line)); #endif md = llvm::MDNode::get(*g->ctx, first_line); inst->setMetadata("first_line", md); -#if defined (LLVM_3_2) || defined (LLVM_3_3)|| defined (LLVM_3_4)|| defined (LLVM_3_5) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_6 /* 3.2, 3.3, 3.4, 3.5 */ llvm::Value *first_column = LLVMInt32(pos.first_column); -#else // LLVN 3.6++ +#else /* LLVN 3.6+ */ llvm::Metadata *first_column = llvm::ConstantAsMetadata::get(LLVMInt32(pos.first_column)); #endif md = llvm::MDNode::get(*g->ctx, first_column); inst->setMetadata("first_column", md); -#if defined (LLVM_3_2) || defined (LLVM_3_3)|| defined (LLVM_3_4)|| defined (LLVM_3_5) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_6 /* 3.2, 3.3, 3.4, 3.5 */ llvm::Value *last_line = LLVMInt32(pos.last_line); -#else // LLVN 3.6++ +#else /* LLVN 3.6+ */ llvm::Metadata *last_line = llvm::ConstantAsMetadata::get(LLVMInt32(pos.last_line)); #endif md = llvm::MDNode::get(*g->ctx, last_line); inst->setMetadata("last_line", md); -#if defined (LLVM_3_2) || defined (LLVM_3_3)|| defined (LLVM_3_4)|| defined (LLVM_3_5) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_6 /* 3.2, 3.3, 3.4, 3.5 */ llvm::Value *last_column = LLVMInt32(pos.last_column); -#else // LLVN 3.6++ +#else /* LLVN 3.6+ */ llvm::Metadata *last_column = llvm::ConstantAsMetadata::get(LLVMInt32(pos.last_column)); #endif md = llvm::MDNode::get(*g->ctx, last_column); @@ -3577,7 +3591,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 ISPC_LLVM_VERSION >= ISPC_LLVM_3_3 // LLVM 3.3+ llvm::CallInst *cc = llvm::dyn_cast(ci); if (cc && cc->getCalledFunction() && diff --git a/ctx.h b/ctx.h index edc51ce4..7b2184ca 100644 --- a/ctx.h +++ b/ctx.h @@ -40,19 +40,19 @@ #include "ispc.h" #include -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_3 #include #include -#else +#else /* >= 3.3 */ #include #include #endif -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) // LLVM 3.5+ - #include - #include -#else +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_5 #include #include +#else /* >= 3.5 */ + #include + #include #endif struct CFInfo; @@ -352,10 +352,11 @@ public: Instructions stored using Value pointers; the code here returns silently if it's not actually given an instruction. */ void AddDebugPos(llvm::Value *instruction, const SourcePos *pos = NULL, -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIScope *scope = NULL); -#else // LLVM 3.7++ +#else /* LLVM 3.7+ */ llvm::DIScope *scope = NULL); + //llvm::MDScope *scope = NULL ); #endif /** Inform the debugging information generation code that a new scope @@ -368,7 +369,7 @@ public: /** Returns the llvm::DIScope corresponding to the current program scope. */ -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIScope GetDIScope() const; #else // LLVM 3.7++ llvm::DIScope *GetDIScope() const; @@ -683,7 +684,7 @@ private: emitted. */ std::vector controlFlowInfo; -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /** DIFile object corresponding to the source file where the current function was defined (used for debugging info). */ llvm::DIFile diFile; diff --git a/expr.cpp b/expr.cpp index e829f578..411628ab 100644 --- a/expr.cpp +++ b/expr.cpp @@ -56,7 +56,7 @@ #include #include #include -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION == ISPC_LLVM_3_2 #include #include #include @@ -74,7 +74,7 @@ #include #endif #include -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) // LLVM 3.5+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5 /* 3.5+ */ #include #else #include diff --git a/func.cpp b/func.cpp index 13aa09ee..9be935f4 100644 --- a/func.cpp +++ b/func.cpp @@ -46,7 +46,7 @@ #include "util.h" #include -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_3 /* 3.2 */ #ifdef ISPC_NVPTX_ENABLED #include #endif /* ISPC_NVPTX_ENABLED */ @@ -67,9 +67,9 @@ #include #include #endif -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /* < 3.6 */ #include "llvm/PassManager.h" -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ #include "llvm/IR/LegacyPassManager.h" #endif #include @@ -78,7 +78,7 @@ #include #include #include -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) // LLVM 3.5+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5 /* 3.5+ */ #include #include #include @@ -360,11 +360,19 @@ Function::emitCode(FunctionEmitContext *ctx, llvm::Function *function, { llvm::NamedMDNode* annotations = m->module->getOrInsertNamedMetadata("nvvm.annotations"); +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_6 /* 3.6+ */ + llvm::SmallVector av; + av.push_back(llvm::ValueAsMetadata::get(function)); + av.push_back(llvm::MDString::get(*g->ctx, "kernel")); + av.push_back(llvm::ConstantAsMetadata::get(LLVMInt32(1))); + annotations->addOperand(llvm::MDNode::get(*g->ctx, llvm::ArrayRef(av))); +#else llvm::SmallVector av; av.push_back(function); av.push_back(llvm::MDString::get(*g->ctx, "kernel")); av.push_back(LLVMInt32(1)); annotations->addOperand(llvm::MDNode::get(*g->ctx, av)); +#endif } #endif /* ISPC_NVPTX_ENABLED */ } @@ -384,9 +392,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 ISPC_LLVM_VERSION < ISPC_LLVM_3_3 /* 3.2 */ (function->getFnAttributes().hasAttribute(llvm::Attributes::AlwaysInline) == false) -#else // LLVM 3.3+ +#else /* LLVM 3.3+ */ (function->getAttributes().getFnAttributes().hasAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::AlwaysInline) == false) #endif && @@ -569,11 +577,21 @@ Function::GenerateIR() { { llvm::NamedMDNode* annotations = m->module->getOrInsertNamedMetadata("nvvm.annotations"); +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_6 /* 3.6+ */ + + llvm::SmallVector av; + av.push_back(llvm::ValueAsMetadata::get(function)); + av.push_back(llvm::MDString::get(*g->ctx, "kernel")); + av.push_back(llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(llvm::IntegerType::get(*g->ctx,32), 1))); + annotations->addOperand(llvm::MDNode::get(*g->ctx, llvm::ArrayRef(av))); +#else llvm::SmallVector av; - av.push_back(appFunction); + av.push_back(function); av.push_back(llvm::MDString::get(*g->ctx, "kernel")); av.push_back(llvm::ConstantInt::get(llvm::IntegerType::get(*g->ctx,32), 1)); - annotations->addOperand(llvm::MDNode::get(*g->ctx, av)); + annotations->addOperand(llvm::MDNode::get(*g->ctx, av)); +#endif + } #endif /* ISPC_NVPTX_ENABLED */ } diff --git a/ispc.cpp b/ispc.cpp index fd1459cc..6d5ff527 100644 --- a/ispc.cpp +++ b/ispc.cpp @@ -50,22 +50,22 @@ #include #include #endif -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION == ISPC_LLVM_3_2 #include #include #include -#else +#else /* 3.3+ */ #include #include #include #endif -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) && !defined(LLVM_3_5) // LLVM 3.6+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_6 // LLVM 3.6+ #include - #if !defined(LLVM_3_6) // LLVM 3.7+ + #if ISPC_LLVM_VERSION >= ISPC_LLVM_3_7 // LLVM 3.7+ #include #endif #endif -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) // LLVM 3.5+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5 // LLVM 3.5+ #include #include #else // LLVM 3.2, 3.3, 3.4 @@ -75,7 +75,7 @@ #include #include #include -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION == ISPC_LLVM_3_2 #include #else // LLVM 3.3+ #include @@ -233,17 +233,17 @@ typedef enum { // Haswell. Supports AVX 2. CPU_Haswell, -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) && !defined(LLVM_3_5) // LLVM 3.6+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_6 // LLVM 3.6+ // Broadwell. Supports AVX 2 + ADX/RDSEED/SMAP. CPU_Broadwell, #endif -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) && !defined(LLVM_3_5) && !defined(LLVM_3_6)// LLVM 3.7+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_7 // LLVM 3.7+ // KNL. Supports AVX512. CPU_KNL, #endif -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) // LLVM 3.4+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_4 // LLVM 3.4+ // Late Atom-like design. Supports SSE 4.2 + POPCNT/LZCNT. CPU_Silvermont, #endif @@ -302,7 +302,7 @@ public: names[CPU_Penryn].push_back("penryn"); -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) // LLVM 3.4+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_4 // LLVM 3.4+ names[CPU_Silvermont].push_back("slm"); names[CPU_Silvermont].push_back("silvermont"); #endif @@ -319,11 +319,11 @@ public: names[CPU_Haswell].push_back("core-avx2"); names[CPU_Haswell].push_back("haswell"); -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) && !defined(LLVM_3_5) // LLVM 3.6+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_6 // LLVM 3.6+ names[CPU_Broadwell].push_back("broadwell"); #endif -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) && !defined(LLVM_3_5) && !defined(LLVM_3_6)// LLVM 3.7+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_7 // LLVM 3.7+ names[CPU_KNL].push_back("knl"); #endif @@ -338,24 +338,24 @@ public: #endif -#if defined(LLVM_3_2) || defined(LLVM_3_3) // LLVM 3.4+ +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_4 // LLVM 3.2 or 3.3 #define CPU_Silvermont CPU_Nehalem -#else +#else /* LLVM 3.4+ */ compat[CPU_Silvermont] = Set(CPU_Generic, CPU_Bonnell, CPU_Penryn, CPU_Core2, CPU_Nehalem, CPU_Silvermont, CPU_None); #endif -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) && !defined(LLVM_3_5) && !defined(LLVM_3_6)// LLVM 3.7+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_7 // LLVM 3.7+ compat[CPU_KNL] = Set(CPU_KNL, CPU_Generic, CPU_Bonnell, CPU_Penryn, CPU_Core2, CPU_Nehalem, CPU_Silvermont, CPU_SandyBridge, CPU_IvyBridge, CPU_Haswell, CPU_Broadwell, CPU_None); #endif -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) // LLVM 3.6+ +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_6 // LLVM 3.2, 3.3, 3.4 or 3.5 #define CPU_Broadwell CPU_Haswell -#else +#else /* LLVM 3.6+ */ compat[CPU_Broadwell] = Set(CPU_Generic, CPU_Bonnell, CPU_Penryn, CPU_Core2, CPU_Nehalem, CPU_Silvermont, CPU_SandyBridge, CPU_IvyBridge, @@ -446,7 +446,7 @@ Target::Target(const char *arch, const char *cpu, const char *isa, bool pic, boo m_is32Bit(true), m_cpu(""), m_attributes(""), -#if !defined(LLVM_3_2) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_3 /* ! 3.2 */ m_tf_attributes(NULL), #endif m_nativeVectorWidth(-1), @@ -507,13 +507,13 @@ Target::Target(const char *arch, const char *cpu, const char *isa, bool pic, boo break; #endif -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) && !defined(LLVM_3_5) && !defined(LLVM_3_6)// LLVM 3.7+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_7 // LLVM 3.7+ case CPU_KNL: isa = "avx512knl-i32x16"; break; #endif -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) && !defined(LLVM_3_5) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_6 case CPU_Broadwell: #endif case CPU_Haswell: @@ -531,7 +531,7 @@ Target::Target(const char *arch, const char *cpu, const char *isa, bool pic, boo // Penryn is here because ISPC does not use SSE 4.2 case CPU_Penryn: case CPU_Nehalem: -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_4 case CPU_Silvermont: #endif isa = "sse4-i32x4"; @@ -569,7 +569,7 @@ Target::Target(const char *arch, const char *cpu, const char *isa, bool pic, boo // Make sure the target architecture is a known one; print an error // with the valid ones otherwise. -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) && !defined(LLVM_3_5) && !defined(LLVM_3_6) // 3.7 + +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_7 // LLVM 3.7+ for (llvm::TargetRegistry::iterator iter = llvm::TargetRegistry::targets().begin(); iter != llvm::TargetRegistry::targets().end(); ++iter) { #else @@ -584,7 +584,7 @@ Target::Target(const char *arch, const char *cpu, const char *isa, bool pic, boo if (this->m_target == NULL) { fprintf(stderr, "Invalid architecture \"%s\"\nOptions: ", arch); llvm::TargetRegistry::iterator iter; -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) && !defined(LLVM_3_5) && !defined(LLVM_3_6) // 3.7 + +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_7 // LLVM 3.7+ for (iter = llvm::TargetRegistry::targets().begin(); iter != llvm::TargetRegistry::targets().end(); ++iter) #else @@ -891,7 +891,7 @@ Target::Target(const char *arch, const char *cpu, const char *isa, bool pic, boo this->m_hasGather = true; CPUfromISA = CPU_Haswell; } -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) && !defined(LLVM_3_5) && !defined(LLVM_3_6)// LLVM 3.7+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_7 // LLVM 3.7+ else if (!strcasecmp(isa, "avx512knl-i32x16")) { this->m_isa = Target::KNL_AVX512; this->m_nativeVectorWidth = 16; @@ -1020,7 +1020,7 @@ Target::Target(const char *arch, const char *cpu, const char *isa, bool pic, boo #endif if (g->opt.disableFMA == false) options.AllowFPOpFusion = llvm::FPOpFusion::Fast; -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 #ifdef ISPC_IS_WINDOWS if (strcmp("x86", arch) == 0) { // Workaround for issue #503 (LLVM issue 14646). @@ -1034,18 +1034,17 @@ Target::Target(const char *arch, const char *cpu, const char *isa, bool pic, boo relocModel); Assert(m_targetMachine != NULL); -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 m_targetMachine->setAsmVerbosityDefault(true); -#else +#else /* LLVM 3.7+ */ m_targetMachine->Options.MCOptions.AsmVerbose = true; #endif // Initialize TargetData/DataLayout in 3 steps. // 1. Get default data layout first std::string dl_string; - -#if defined(LLVM_3_6) +#if ISPC_LLVM_VERSION == ISPC_LLVM_3_6 dl_string = m_targetMachine->getSubtargetImpl()->getDataLayout()->getStringRepresentation(); -#else // LLVM 3.5- and LLVM 3.7+ +#else // LLVM 3.5- or LLVM 3.7+ dl_string = m_targetMachine->getDataLayout()->getStringRepresentation(); #endif // 2. Adjust for generic @@ -1076,7 +1075,7 @@ Target::Target(const char *arch, const char *cpu, const char *isa, bool pic, boo this->m_is32Bit = (getDataLayout()->getPointerSize() == 4); -#if !defined(LLVM_3_2) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_3 // This is LLVM 3.3+ feature. // Initialize target-specific "target-feature" attribute. if (!m_attributes.empty()) { @@ -1135,11 +1134,11 @@ Target::SupportedTargets() { "avx1-i32x8, avx1-i32x16, avx1-i64x4, " "avx1.1-i32x8, avx1.1-i32x16, avx1.1-i64x4, " "avx2-i32x8, avx2-i32x16, avx2-i64x4, " -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) && !defined(LLVM_3_5) && !defined(LLVM_3_6)// LLVM 3.7+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_7 // LLVM 3.7+ "avx512knl-i32x16, " #endif "generic-x1, generic-x4, generic-x8, generic-x16, " - "generic-x32, generic-x64, *-generic-x16" + "generic-x32, generic-x64, *-generic-x16, " #ifdef ISPC_ARM_ENABLED ", neon-i8x16, neon-i16x8, neon-i32x4" #endif @@ -1208,7 +1207,7 @@ Target::ISAToString(ISA isa) { return "avx11"; case Target::AVX2: return "avx2"; -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) && !defined(LLVM_3_5) && !defined(LLVM_3_6)// LLVM 3.7+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_7 // LLVM 3.7+ case Target::KNL_AVX512: return "avx512knl-i32x16"; #endif @@ -1256,7 +1255,7 @@ Target::ISAToTargetString(ISA isa) { return "avx1.1-i32x8"; case Target::AVX2: return "avx2-i32x8"; -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) && !defined(LLVM_3_5) && !defined(LLVM_3_6)// LLVM 3.7+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_7 // LLVM 3.7+ case Target::KNL_AVX512: return "avx512knl-i32x16"; #endif @@ -1325,11 +1324,11 @@ Target::SizeOf(llvm::Type *type, llvm::PointerType *ptrType = llvm::PointerType::get(type, 0); llvm::Value *voidPtr = llvm::ConstantPointerNull::get(ptrType); llvm::ArrayRef arrayRef(&index[0], &index[1]); -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::Instruction *gep = llvm::GetElementPtrInst::Create(voidPtr, arrayRef, "sizeof_gep", insertAtEnd); -#else // LLVM 3.7++ +#else /* LLVM 3.7+ */ llvm::Instruction *gep = llvm::GetElementPtrInst::Create(PTYPE(voidPtr), voidPtr, arrayRef, "sizeof_gep", @@ -1363,11 +1362,11 @@ Target::StructOffset(llvm::Type *type, int element, llvm::PointerType *ptrType = llvm::PointerType::get(type, 0); llvm::Value *voidPtr = llvm::ConstantPointerNull::get(ptrType); llvm::ArrayRef arrayRef(&indices[0], &indices[2]); -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::Instruction *gep = llvm::GetElementPtrInst::Create(voidPtr, arrayRef, "offset_gep", insertAtEnd); -#else // LLVM 3.7++ +#else /* LLVM 3.7+ */ llvm::Instruction *gep = llvm::GetElementPtrInst::Create(PTYPE(voidPtr), voidPtr, arrayRef, "offset_gep", @@ -1399,7 +1398,7 @@ Target::StructOffset(llvm::Type *type, int element, } void Target::markFuncWithTargetAttr(llvm::Function* func) { -#if !defined(LLVM_3_2) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_3 if (m_tf_attributes) { func->addAttributes(llvm::AttributeSet::FunctionIndex, *m_tf_attributes); } @@ -1484,19 +1483,21 @@ SourcePos::SourcePos(const char *n, int fl, int fc, int ll, int lc) { } -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIFile -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ llvm::DIFile* +//llvm::MDFile* #endif SourcePos::GetDIFile() const { std::string directory, filename; GetDirectoryAndFileName(g->currentDirectory, name, &directory, &filename); -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIFile ret = m->diBuilder->createFile(filename, directory); Assert(ret.Verify()); -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ llvm::DIFile *ret = m->diBuilder->createFile(filename, directory); + //llvm::MDFile *ret = m->diBuilder->createFile(filename, directory); #endif return ret; } diff --git a/ispc.h b/ispc.h index 584c0242..31c0bd9d 100644 --- a/ispc.h +++ b/ispc.h @@ -38,9 +38,9 @@ #ifndef ISPC_H #define ISPC_H -#define ISPC_VERSION "1.8.3dev" +#include "ispc_version.h" -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) && !defined(LLVM_3_5) && !defined(LLVM_3_6) && !defined(LLVM_3_7) +#if ISPC_LLVM_VERSION < OLDEST_SUPPORTED_LLVM || ISPC_LLVM_VERSION > LATEST_SUPPORTED_LLVM #error "Only LLVM 3.2, 3.3, 3.4, 3.5, 3.6 and 3.7 development branch are supported" #endif @@ -86,7 +86,7 @@ namespace llvm { class TargetMachine; class Type; class Value; -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 class DIFile; class DIType; class DIDescriptor; @@ -144,7 +144,7 @@ struct SourcePos { /** Prints the filename and line/column range to standard output. */ void Print() const; -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /** Returns a LLVM DIFile object that represents the SourcePos's file */ llvm::DIFile GetDIFile() const; #else @@ -259,7 +259,7 @@ public: // Note the same name of method for 3.1 and 3.2+, this allows // to reduce number ifdefs on client side. - llvm::DataLayout *getDataLayout() const {return m_dataLayout;} + const llvm::DataLayout *getDataLayout() const {return m_dataLayout;} /** Reports if Target object has valid state. */ bool isValid() const {return m_valid;} @@ -344,7 +344,7 @@ private: /** Target-specific attribute string to pass along to the LLVM backend */ std::string m_attributes; -#if !defined(LLVM_3_2) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_3 /** 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/ispc_version.h b/ispc_version.h new file mode 100644 index 00000000..fe438e76 --- /dev/null +++ b/ispc_version.h @@ -0,0 +1,64 @@ +/* + Copyright (c) 2015, Intel Corporation + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of Intel Corporation nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/** @file ispc_version.h + @brief defines the ISPC version +*/ + +#ifndef ISPC_VERSION_H +#define ISPC_VERSION_H + +#define ISPC_VERSION "1.8.3dev" +#include "llvm/Config/llvm-config.h" + +#define ISPC_LLVM_VERSION ( LLVM_VERSION_MAJOR * 10000 + LLVM_VERSION_MINOR * 100 ) + +#define ISPC_LLVM_3_2 30200 +#define ISPC_LLVM_3_3 30300 +#define ISPC_LLVM_3_4 30400 +#define ISPC_LLVM_3_5 30500 +#define ISPC_LLVM_3_6 30600 +#define ISPC_LLVM_3_7 30700 + +#define OLDEST_SUPPORTED_LLVM ISPC_LLVM_3_2 +#define LATEST_SUPPORTED_LLVM ISPC_LLVM_3_7 + +#ifdef __ispc__xstr +#undef __ispc__xstr +#endif +#define __ispc__xstr(s) __ispc__str(s) +#define __ispc__str(s) #s + +#define ISPC_LLVM_VERSION_STRING __ispc__xstr(LLVM_VERSION_MAJOR) "." __ispc__xstr(LLVM_VERSION_MINOR) + +#endif // ISPC_VERSION_H diff --git a/llvmutil.cpp b/llvmutil.cpp index 3ec5ebef..9b2b3573 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 ISPC_LLVM_VERSION == ISPC_LLVM_3_2 #include #include #else diff --git a/llvmutil.h b/llvmutil.h index eb8ea49e..f65bf638 100644 --- a/llvmutil.h +++ b/llvmutil.h @@ -38,12 +38,13 @@ #ifndef ISPC_LLVMUTIL_H #define ISPC_LLVMUTIL_H 1 -#if defined(LLVM_3_2) +#include "ispc_version.h" +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_3 #include #include #include #include -#else +#else /* >= 3.3 */ #include #include #include diff --git a/main.cpp b/main.cpp index 60965317..7937dfcb 100644 --- a/main.cpp +++ b/main.cpp @@ -62,21 +62,7 @@ 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) - "3.2" -#elif defined(LLVM_3_3) - "3.3" -#elif defined(LLVM_3_4) - "3.4" -#elif defined(LLVM_3_5) - "3.5" -#elif defined(LLVM_3_6) - "3.6" -#elif defined(LLVM_3_7) - "3.7" -#else -#error "Unhandled LLVM version" -#endif + ISPC_LLVM_VERSION_STRING ); } @@ -173,7 +159,7 @@ devUsage(int ret) { printf(" [--yydebug]\t\t\t\tPrint debugging information during parsing\n"); printf(" [--debug-phase=]\t\tSet optimization phases to dump. --debug-phase=first,210:220,300,305,310:last\n"); -#if defined(LLVM_3_4) || defined(LLVM_3_5) // only 3.4 and 3.5 +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_2 && ISPC_LLVM_VERSION < ISPC_LLVM_3_6 /* 3.4, 3.5 */ printf(" [--debug-ir=]\t\tSet optimization phase to generate debugIR after it\n"); #endif printf(" [--off-phase=]\t\tSwitch off optimization phases. --off-phase=first,210:220,300,305,310:last\n"); @@ -570,7 +556,7 @@ int main(int Argc, char *Argv[]) { g->debug_stages = ParsingPhases(argv[i] + strlen("--debug-phase=")); } -#if defined(LLVM_3_4) || defined(LLVM_3_5) // only 3.4 and 3.5 +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_2 && ISPC_LLVM_VERSION < ISPC_LLVM_3_6 /* 3.4, 3.5 */ else if (strncmp(argv[i], "--debug-ir=", 11) == 0) { g->debugIR = ParsingPhaseName(argv[i] + strlen("--debug-ir=")); } diff --git a/module.cpp b/module.cpp index 28480488..a0412edf 100644 --- a/module.cpp +++ b/module.cpp @@ -66,8 +66,7 @@ #include #define strcasecmp stricmp #endif - -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION == ISPC_LLVM_3_2 #include #include #include @@ -85,16 +84,16 @@ #include #include #ifdef ISPC_NVPTX_ENABLED -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) // LLVM 3.5+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5 /* 3.5+ */ #include #else #include #endif #endif /* ISPC_NVPTX_ENABLED */ #endif -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 #include "llvm/PassManager.h" -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ #include "llvm/IR/LegacyPassManager.h" #endif #include @@ -103,14 +102,14 @@ #include #include #include -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION == ISPC_LLVM_3_2 #include #include #else // LLVM 3.3+ #include #include #endif -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) // LLVM 3.5+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5 #include #include #include @@ -170,9 +169,9 @@ static void lStripUnusedDebugInfo(llvm::Module *module) { if (g->generateDebuggingSymbols == false) return; -#if defined (LLVM_3_2) || defined (LLVM_3_3)|| defined (LLVM_3_4)|| defined (LLVM_3_5) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_6 /* <= 3.5 */ std::set SPall; -#else // LLVM 3.6++ +#else /* LLVM 3.6+ */ std::set SPall; #endif // OK, now we are to determine which functions actually survived the @@ -191,7 +190,7 @@ lStripUnusedDebugInfo(llvm::Module *module) { while (node) { // get the scope of the current instruction`s location // node becomes NULL if this was the original location -#if defined (LLVM_3_2) || defined (LLVM_3_3)|| defined (LLVM_3_4)|| defined (LLVM_3_5) || (LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /* <= 3.6 */ llvm::DILocation dloc(node); llvm::DIScope scope = dloc.getScope(); node = dloc.getOrigLocation(); @@ -206,9 +205,11 @@ lStripUnusedDebugInfo(llvm::Module *module) { else break; } if (scope.isSubprogram()) { -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ llvm::DILocation *dloc = llvm::cast(node); llvm::DIScope *scope = dloc->getScope(); + //llvm::MDLocation *dloc = llvm::cast(node); + //llvm::MDScope *scope = dloc->getScope(); node = dloc->getInlinedAt(); // now following a chain of nested scopes while (!0) { @@ -232,36 +233,38 @@ lStripUnusedDebugInfo(llvm::Module *module) { if (llvm::NamedMDNode *cuNodes = module->getNamedMetadata("llvm.dbg.cu")) { for (unsigned i = 0, ie = cuNodes->getNumOperands(); i != ie; ++i) { llvm::MDNode *cuNode = cuNodes->getOperand(i); -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DICompileUnit cu(cuNode); llvm::DIArray subprograms = cu.getSubprograms(); if (subprograms.getNumElements() == 0) { -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ llvm::DICompileUnit *cu = llvm::cast(cuNode); llvm::DISubprogramArray subprograms = cu->getSubprograms(); + //llvm::MDCompileUnit *cu = llvm::cast(cuNode); + //llvm::MDSubprogramArray subprograms = cu->getSubprograms(); if (subprograms.size() == 0) { #endif continue; } -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_6 std::set SPset; std::vector usedSubprograms; -#else // LLVM 3.6+ +#else /* LLVM 3.6+ */ std::set SPset; std::vector usedSubprograms; #endif // determine what functions of those extracted belong to the unit -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 for (unsigned j = 0, je = subprograms.getNumElements(); j != je; ++j) -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ for (unsigned j = 0, je = subprograms.size(); j != je; ++j) #endif -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_6 SPset.insert(subprograms->getOperand(j)); -#elif defined(LLVM_3_6) +#elif ISPC_LLVM_VERSION < ISPC_LLVM_3_7 SPset.insert(subprograms.getElement(j)); -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ SPset.insert(subprograms [j]); #endif @@ -271,9 +274,9 @@ lStripUnusedDebugInfo(llvm::Module *module) { Debug(SourcePos(), "%d / %d functions left in module with debug " "info.", (int)usedSubprograms.size(), -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 (int)subprograms.getNumElements()); -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ (int)subprograms.size()); #endif @@ -296,7 +299,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 ISPC_LLVM_VERSION < ISPC_LLVM_3_3 /* 3.2 */ llvm::MDNode *nodeSPMD = llvm::dyn_cast(cuNode->getOperand(12)); Assert(nodeSPMD != NULL); @@ -314,7 +317,7 @@ lStripUnusedDebugInfo(llvm::Module *module) { llvm::MDNode *replNode = llvm::MDNode::get(*g->ctx, llvm::ArrayRef(usedSubprogramsArray)); cuNode->replaceOperandWith(12, replNode); -#elif defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) +#elif ISPC_LLVM_VERSION < ISPC_LLVM_3_6 /* 3.3, 3.4, 3.5 */ llvm::MDNode *nodeSPMDArray = llvm::dyn_cast(cuNode->getOperand(9)); Assert(nodeSPMDArray != NULL); @@ -328,8 +331,7 @@ lStripUnusedDebugInfo(llvm::Module *module) { llvm::MDNode *replNode = m->diBuilder->getOrCreateArray(llvm::ArrayRef(usedSubprograms)); cuNode->replaceOperandWith(9, replNode); -#else // LLVM 3.6+ - #if defined(LLVM_3_6) +#elif ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /* 3.6 */ llvm::DIArray nodeSPs = cu.getSubprograms(); Assert(nodeSPs.getNumElements() == subprograms.getNumElements()); for (int i = 0; i < (int)nodeSPs.getNumElements(); ++i) @@ -340,8 +342,9 @@ lStripUnusedDebugInfo(llvm::Module *module) { llvm::MDNode *replNode = llvm::MDNode::get(module->getContext(), llvm::ArrayRef(usedSubprograms)); cu.replaceSubprograms(llvm::DIArray(replNode)); - #else // LLVM 3.7+ +#else /* LLVM 3.7+ */ llvm::DISubprogramArray nodeSPs = cu->getSubprograms(); + //llvm::MDSubprogramArray nodeSPs = cu->getSubprograms(); Assert(nodeSPs.size() == subprograms.size()); for (int i = 0; i < (int)nodeSPs.size(); ++i) Assert(nodeSPs [i] == subprograms [i]); @@ -350,7 +353,6 @@ lStripUnusedDebugInfo(llvm::Module *module) { // confidence... cu->replaceSubprograms(llvm::MDTuple::get(cu->getContext(), llvm::ArrayRef(usedSubprograms))); - #endif #endif } } @@ -418,7 +420,7 @@ Module::Module(const char *fn) { sprintf(producerString, "ispc version %s (built on %s)", ISPC_VERSION, __DATE__); #endif -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_4 /* 3.4+ */ diCompileUnit = #endif // LLVM_3_4+ diBuilder->createCompileUnit(llvm::dwarf::DW_LANG_C99, /* lang */ @@ -698,7 +700,7 @@ Module::AddGlobalVariable(const std::string &name, const Type *type, Expr *initE } if (diBuilder) { -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_6 /* 3.2, 3.3, 3.4, 3.5 */ llvm::DIFile file = pos.GetDIFile(); llvm::DIGlobalVariable var = diBuilder->createGlobalVariable( name, @@ -707,7 +709,7 @@ Module::AddGlobalVariable(const std::string &name, const Type *type, Expr *initE sym->type->GetDIType(file), (sym->storageClass == SC_STATIC), sym->storagePtr); -#elif defined(LLVM_3_6) +#elif ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /* 3.6 */ llvm::DIFile file = pos.GetDIFile(); llvm::Constant *sym_const_storagePtr = llvm::dyn_cast(sym->storagePtr); Assert(sym_const_storagePtr); @@ -720,8 +722,9 @@ Module::AddGlobalVariable(const std::string &name, const Type *type, Expr *initE sym->type->GetDIType(file), (sym->storageClass == SC_STATIC), sym_const_storagePtr); -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ llvm::DIFile *file = pos.GetDIFile(); + //llvm::MDFile *file = pos.GetDIFile(); llvm::Constant *sym_const_storagePtr = llvm::dyn_cast(sym->storagePtr); Assert(sym_const_storagePtr); diBuilder->createGlobalVariable( @@ -734,9 +737,9 @@ Module::AddGlobalVariable(const std::string &name, const Type *type, Expr *initE (sym->storageClass == SC_STATIC), sym_const_storagePtr); #endif -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 Assert(var.Verify()); -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ //comming soon #endif } @@ -1159,7 +1162,7 @@ Module::writeOutput(OutputType outputType, const char *outFileName, if (diBuilder && (outputType != Header) && (outputType != Deps)) lStripUnusedDebugInfo(module); -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) // LLVM 3.4+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_4 /* 3.4+ */ // In LLVM_3_4 after r195494 and r195504 revisions we should pass // "Debug Info Version" constant to the module. LLVM will ignore // our Debug Info metadata without it. @@ -1393,7 +1396,7 @@ Module::writeBitcode(llvm::Module *module, const char *outFileName) { std::string s; llvm::raw_string_ostream out(s); -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) // LLVM 3.5+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5 /* 3.5+ */ std::unique_ptr Annotator; #else llvm::OwningPtr Annotator; @@ -1406,7 +1409,7 @@ Module::writeBitcode(llvm::Module *module, const char *outFileName) { input.push_back(s); output = input; -#if !(defined(LLVM_3_1) || defined(LLVM_3_2)) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_3 /* 3.3+ */ /* do not fix attributed with LLVM 3.2, everything is fine there */ lFixAttributes(input,output); #endif @@ -1442,28 +1445,28 @@ 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 ISPC_LLVM_VERSION >= ISPC_LLVM_3_2 && ISPC_LLVM_VERSION < ISPC_LLVM_3_4 /* 3.2, 3.3 */ unsigned int flags = binary ? llvm::raw_fd_ostream::F_Binary : 0; -#elif defined(LLVM_3_4) +#elif ISPC_LLVM_VERSION < ISPC_LLVM_3_5 /* 3.4 */ llvm::sys::fs::OpenFlags flags = binary ? llvm::sys::fs::F_Binary : llvm::sys::fs::F_None; -#else +#else /* 3.5+ */ llvm::sys::fs::OpenFlags flags = binary ? llvm::sys::fs::F_None : llvm::sys::fs::F_Text; #endif -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_6 std::string error; -#else // LLVM 3.6+ +#else /* LLVM 3.6+ */ std::error_code error; #endif llvm::tool_output_file *of = new llvm::tool_output_file(outFileName, error, flags); -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_6 if (error.size()) { -#else // LLVM 3.6+ +#else /* LLVM 3.6+ */ if (error) { #endif @@ -1471,25 +1474,25 @@ Module::writeObjectFileOrAssembly(llvm::TargetMachine *targetMachine, return false; } -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::PassManager pm; -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ llvm::legacy::PassManager pm; #endif -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_2 && ISPC_LLVM_VERSION < ISPC_LLVM_3_5 /* 3.2, 3.3, 3.4 */ pm.add(new llvm::DataLayout(*g->target->getDataLayout())); -#elif defined(LLVM_3_5) +#elif ISPC_LLVM_VERSION < ISPC_LLVM_3_6 /* 3.5 */ pm.add(new llvm::DataLayoutPass(*g->target->getDataLayout())); -#elif defined(LLVM_3_6) +#elif ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /* 3.6 */ llvm::DataLayoutPass *dlp= new llvm::DataLayoutPass(); dlp->doInitialization(*module); pm.add(dlp); #endif // LLVM 3.7+ doesn't have DataLayoutPass anymore. { -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::formatted_raw_ostream fos(of->os()); -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ llvm::raw_fd_ostream &fos(of->os()); #endif if (targetMachine->addPassesToEmitFile(pm, fos, fileType)) { @@ -1578,7 +1581,7 @@ lEmitStructDecl(const StructType *st, std::vector *emittedSt char sSOA[48]; bool pack, needsAlign = false; llvm::Type *stype = st->LLVMType(g->ctx); - llvm::DataLayout *DL = g->target->getDataLayout(); + const llvm::DataLayout *DL = g->target->getDataLayout(); if (!(pack = llvm::dyn_cast(stype)->isPacked())) for (int i = 0; !needsAlign && (i < st->GetElementCount()); ++i) { @@ -2431,9 +2434,9 @@ Module::execPreprocessor(const char *infilename, llvm::raw_string_ostream *ostre inst.setDiagnostics(diagEngine); -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_5 /* 3.2, 3.3, 3.4 */ clang::TargetOptions &options = inst.getTargetOpts(); -#else // LLVM 3.5+ +#else /* LLVM 3.5+ */ const std::shared_ptr< clang::TargetOptions > &options = std::make_shared< clang::TargetOptions >(inst.getTargetOpts()); #endif @@ -2443,19 +2446,19 @@ Module::execPreprocessor(const char *infilename, llvm::raw_string_ostream *ostre triple.setTriple(llvm::sys::getDefaultTargetTriple()); } -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_5 /* 3.2, 3.3, 3.4 */ options.Triple = triple.getTriple(); -#else // LLVM 3.5+ +#else /* LLVM 3.5+ */ options->Triple = triple.getTriple(); #endif -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_3 /* 3.2 */ clang::TargetInfo *target = clang::TargetInfo::CreateTargetInfo(inst.getDiagnostics(), options); -#elif defined(LLVM_3_3) || defined(LLVM_3_4) +#elif ISPC_LLVM_VERSION < ISPC_LLVM_3_5 /* 3.3, 3.4 */ clang::TargetInfo *target = clang::TargetInfo::CreateTargetInfo(inst.getDiagnostics(), &options); -#else // LLVM 3.5+ +#else /* LLVM 3.5+ */ clang::TargetInfo *target = clang::TargetInfo::CreateTargetInfo(inst.getDiagnostics(), options); #endif @@ -2469,7 +2472,7 @@ Module::execPreprocessor(const char *infilename, llvm::raw_string_ostream *ostre // track the source file position by handling them ourselves. inst.getPreprocessorOutputOpts().ShowComments = 1; -#if !defined(LLVM_3_2) // LLVM 3.3+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_3 // LLVM 3.3+ inst.getPreprocessorOutputOpts().ShowCPP = 1; #endif @@ -2481,7 +2484,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 ISPC_LLVM_VERSION == ISPC_LLVM_3_2 true /* is user supplied */, #endif false /* not a framework */, @@ -2560,7 +2563,7 @@ Module::execPreprocessor(const char *infilename, llvm::raw_string_ostream *ostre inst.getLangOpts().LineComment = 1; -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) // LLVM 3.5+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5 /* 3.5+ */ inst.createPreprocessor(clang::TU_Complete); #else inst.createPreprocessor(); @@ -2905,9 +2908,9 @@ static void lEmitDispatchModule(llvm::Module *module, // Do some rudimentary cleanup of the final result and make sure that // the module is all ok. -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::PassManager optPM; -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ llvm::legacy::PassManager optPM; #endif optPM.add(llvm::createGlobalDCEPass()); diff --git a/module.h b/module.h index fb84122d..f6a82646 100644 --- a/module.h +++ b/module.h @@ -41,10 +41,9 @@ #include "ispc.h" #include "ast.h" -#if defined(LLVM_3_4) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_4 && ISPC_LLVM_VERSION < ISPC_LLVM_3_5 #include -#endif -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) // LLVM 3.5+ +#elif ISPC_LLVM_VERSION >= ISPC_LLVM_3_5 #include #endif @@ -161,10 +160,10 @@ public: /** The diBuilder manages generating debugging information */ llvm::DIBuilder *diBuilder; -#if defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_4 && ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DICompileUnit diCompileUnit; -#elif !defined(LLVM_3_2) && !defined(LLVM_3_3) // LLVM 3.7++ - llvm::DICompileUnit *diCompileUnit; +#elif ISPC_LLVM_VERSION >= ISPC_LLVM_3_7 + llvm::DICompileUnit* diCompileUnit; #endif // LLVM_3_4+ private: diff --git a/opt.cpp b/opt.cpp index ac9d2e2b..47918c78 100644 --- a/opt.cpp +++ b/opt.cpp @@ -48,7 +48,7 @@ #include #include -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_3 #include #include #include @@ -58,7 +58,7 @@ #ifdef ISPC_NVPTX_ENABLED #include #endif /* ISPC_NVPTX_ENABLED */ -#else +#else /* >= 3.3 */ #include #include #include @@ -69,30 +69,30 @@ #include #endif /* ISPC_NVPTX_ENABLED */ #endif -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) // LLVM 3.4+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_4 // LLVM 3.4+ #include #endif -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 #include "llvm/PassManager.h" -#else // LLVM 3.7+ +#else /* >= 3.7 */ #include "llvm/IR/LegacyPassManager.h" #endif #include -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) // LLVM 3.5+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5 // LLVM 3.5+ #include #include #include #include -#else +#else /* < 3.5 */ #include #include #include #include #endif #include -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 #include -#else // LLVM 3.7+ +#else /* >= 3.7 */ #include #endif #include @@ -101,9 +101,9 @@ #include #include #include -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_3 #include -#else // LLVM 3.3+ +#else /* LLVM 3.3+ */ #include #include #endif @@ -111,7 +111,7 @@ #include #include #include -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) && !defined(LLVM_3_5) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_6 #include #endif #ifdef ISPC_IS_LINUX @@ -238,33 +238,33 @@ lGetSourcePosFromMetadata(const llvm::Instruction *inst, SourcePos *pos) { llvm::MDString *str = llvm::dyn_cast(filename->getOperand(0)); Assert(str); llvm::ConstantInt *first_lnum = -#if defined (LLVM_3_2) || defined (LLVM_3_3)|| defined (LLVM_3_4)|| defined (LLVM_3_5) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_2 && ISPC_LLVM_VERSION < ISPC_LLVM_3_6 llvm::dyn_cast(first_line->getOperand(0)); -#else // LLVN 3.6++ +#else /* LLVN 3.6+ */ llvm::mdconst::extract(first_line->getOperand(0)); #endif Assert(first_lnum); llvm::ConstantInt *first_colnum = -#if defined (LLVM_3_2) || defined (LLVM_3_3)|| defined (LLVM_3_4)|| defined (LLVM_3_5) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_2 && ISPC_LLVM_VERSION < ISPC_LLVM_3_6 llvm::dyn_cast(first_column->getOperand(0)); -#else // LLVN 3.6++ +#else /* LLVN 3.6+ */ llvm::mdconst::extract(first_column->getOperand(0)); #endif Assert(first_column); llvm::ConstantInt *last_lnum = -#if defined (LLVM_3_2) || defined (LLVM_3_3)|| defined (LLVM_3_4)|| defined (LLVM_3_5) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_2 && ISPC_LLVM_VERSION < ISPC_LLVM_3_6 llvm::dyn_cast(last_line->getOperand(0)); -#else // LLVN 3.6++ +#else /* LLVN 3.6+ */ llvm::mdconst::extract(last_line->getOperand(0)); #endif Assert(last_lnum); llvm::ConstantInt *last_colnum = -#if defined (LLVM_3_2) || defined (LLVM_3_3)|| defined (LLVM_3_4)|| defined (LLVM_3_5) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_2 && ISPC_LLVM_VERSION < ISPC_LLVM_3_6 llvm::dyn_cast(last_column->getOperand(0)); -#else // LLVN 3.6++ +#else /* LLVN 3.6+ */ llvm::mdconst::extract(last_column->getOperand(0)); #endif Assert(last_column); @@ -330,10 +330,10 @@ lGEPInst(llvm::Value *ptr, llvm::Value *offset, const char *name, llvm::Instruction *insertBefore) { llvm::Value *index[1] = { offset }; llvm::ArrayRef arrayRef(&index[0], &index[1]); -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 return llvm::GetElementPtrInst::Create(ptr, arrayRef, name, insertBefore); -#else // LLVM 3.7++ +#else /* LLVM 3.7+ */ return llvm::GetElementPtrInst::Create(PTYPE(ptr), ptr, arrayRef, name, insertBefore); #endif @@ -466,15 +466,15 @@ public: DebugPassManager():number(0){} void add(llvm::Pass * P, int stage); bool run(llvm::Module& M) {return PM.run(M);} -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::PassManager& getPM() {return PM;} -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ llvm::legacy::PassManager& getPM() {return PM;} #endif private: -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::PassManager PM; -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ llvm::legacy::PassManager PM; #endif int number; @@ -500,7 +500,7 @@ DebugPassManager::add(llvm::Pass * P, int stage = -1) { PM.add(CreateDebugPass(buf)); } -#if defined(LLVM_3_4) || defined(LLVM_3_5) // only 3.4 and 3.5 +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_4 && ISPC_LLVM_VERSION < ISPC_LLVM_3_6 // only 3.4 and 3.5 if (g->debugIR == number) { // adding generating of LLVM IR debug after optimization char buf[100]; @@ -521,19 +521,19 @@ Optimize(llvm::Module *module, int optLevel) { DebugPassManager optPM; optPM.add(llvm::createVerifierPass(),0); -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::TargetLibraryInfo *targetLibraryInfo = new llvm::TargetLibraryInfo(llvm::Triple(module->getTargetTriple())); optPM.add(targetLibraryInfo); -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ optPM.add(new llvm::TargetLibraryInfoWrapperPass(llvm::Triple(module->getTargetTriple()))); #endif -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_2 && ISPC_LLVM_VERSION < ISPC_LLVM_3_5 optPM.add(new llvm::DataLayout(*g->target->getDataLayout())); -#elif defined(LLVM_3_5) +#elif ISPC_LLVM_VERSION < ISPC_LLVM_3_6 optPM.add(new llvm::DataLayoutPass(*g->target->getDataLayout())); -#elif defined(LLVM_3_6) +#elif ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DataLayoutPass *dlp= new llvm::DataLayoutPass(); dlp->doInitialization(*module); optPM.add(dlp); @@ -541,12 +541,12 @@ Optimize(llvm::Module *module, int optLevel) { llvm::TargetMachine *targetMachine = g->target->GetTargetMachine(); -#ifdef LLVM_3_2 +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_2 && ISPC_LLVM_VERSION < ISPC_LLVM_3_3 optPM.add(new llvm::TargetTransformInfo(targetMachine->getScalarTargetTransformInfo(), targetMachine->getVectorTargetTransformInfo())); -#elif defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) // LLVM 3.3 - 3.6 +#elif ISPC_LLVM_VERSION < ISPC_LLVM_3_7 targetMachine->addAnalysisPasses(optPM.getPM()); -#else // LLVM 3.7+ +#else /* LLVM 3.7+ */ optPM.getPM().add(createTargetTransformInfoWrapperPass(targetMachine->getTargetIRAnalysis())); #endif @@ -660,7 +660,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 ISPC_LLVM_VERSION >= ISPC_LLVM_3_2 && ISPC_LLVM_VERSION < ISPC_LLVM_3_4 // Starting from 3.4 this functionality was moved to // InstructionCombiningPass. See r184459 for details. optPM.add(llvm::createSimplifyLibCallsPass(), 240); @@ -810,7 +810,7 @@ Optimize(llvm::Module *module, int optLevel) { optPM.add(llvm::createCFGSimplificationPass()); optPM.add(llvm::createArgumentPromotionPass()); -#if defined(LLVM_3_1) || defined(LLVM_3_2) || defined(LLVM_3_3) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_2 && ISPC_LLVM_VERSION < ISPC_LLVM_3_4 // Starting from 3.4 this functionality was moved to // InstructionCombiningPass. See r184459 for details. optPM.add(llvm::createSimplifyLibCallsPass()); @@ -4924,7 +4924,7 @@ PeepholePass::PeepholePass() : BasicBlockPass(ID) { } -#if !defined(LLVM_3_2) +#if ISPC_LLVM_VERSION > ISPC_LLVM_3_2 using namespace llvm::PatternMatch; @@ -5258,7 +5258,7 @@ PeepholePass::runOnBasicBlock(llvm::BasicBlock &bb) { llvm::Instruction *inst = &*iter; llvm::Instruction *builtinCall = NULL; -#if !defined(LLVM_3_2) +#if ISPC_LLVM_VERSION > ISPC_LLVM_3_2 if (!builtinCall) builtinCall = lMatchAvgUpUInt8(inst); if (!builtinCall) @@ -5471,9 +5471,7 @@ llvm::Instruction* FixBooleanSelectPass::fixSelect(llvm::SelectInst* sel, llvm:: bool FixBooleanSelectPass::runOnFunction(llvm::Function &F) { bool modifiedAny = false; - - // LLVM 3.3 only -#if defined(LLVM_3_3) +#if ISPC_LLVM_VERSION == ISPC_LLVM_3_3 // LLVM 3.3 only // Don't optimize generic targets. if (g->target->getISA() == Target::GENERIC) { diff --git a/parse.yy b/parse.yy index daa41e54..703e12d1 100644 --- a/parse.yy +++ b/parse.yy @@ -83,7 +83,7 @@ struct ForeachDimension; #include "util.h" #include -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_3 #include #else #include diff --git a/stmt.cpp b/stmt.cpp index 586cb0fe..3b70c364 100644 --- a/stmt.cpp +++ b/stmt.cpp @@ -48,7 +48,7 @@ #include #include -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_3 #include #include #include @@ -190,7 +190,11 @@ static llvm::Value* lConvertToGenericPtr(FunctionEmitContext *ctx, llvm::Value * llvm::Function *func_warp_index = m->module->getFunction("__warp_index"); llvm::Value *warpId = ctx->CallInst(func_warp_index, NULL, std::vector(), "gep2gen_warp_index"); llvm::Value *offset = ctx->BinaryOperator(llvm::Instruction::Mul, warpId, LLVMInt32(numEl), "gep2gen_offset"); +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 value = llvm::GetElementPtrInst::Create(value, offset, "gep2gen_offset", ctx->GetCurrentBasicBlock()); +#else + value = llvm::GetElementPtrInst::Create(NULL, value, offset, "gep2gen_offset", ctx->GetCurrentBasicBlock()); +#endif } /* convert arrElTy* to elTy* */ @@ -1535,7 +1539,11 @@ lUpdateVaryingCounter(int dim, int nDims, FunctionEmitContext *ctx, ptr_arrayidx_indices.push_back(LLVMInt32(0)); ptr_arrayidx_indices.push_back(laneIdx); #if 1 +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::Instruction* ptr_arrayidx = llvm::GetElementPtrInst::Create(globalDelta, ptr_arrayidx_indices, "arrayidx", ctx->GetCurrentBasicBlock()); +#else + llvm::Instruction* ptr_arrayidx = llvm::GetElementPtrInst::Create(NULL, globalDelta, ptr_arrayidx_indices, "arrayidx", ctx->GetCurrentBasicBlock()); +#endif llvm::LoadInst* int8_39 = new llvm::LoadInst(ptr_arrayidx, "", false, ctx->GetCurrentBasicBlock()); llvm::Value * int32_39 = ctx->ZExtInst(int8_39, LLVMTypes::Int32Type); diff --git a/type.cpp b/type.cpp index 2f7b3546..6d48bca4 100644 --- a/type.cpp +++ b/type.cpp @@ -43,14 +43,14 @@ #include #include -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION == ISPC_LLVM_3_2 #include #include #else #include #include #endif -#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) // LLVM 3.5+ +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5 // LLVM 3.5+ #include #include #else @@ -79,12 +79,13 @@ lShouldPrintName(const std::string &name) { /** Utility routine to create a llvm array type of the given number of the given element type. */ -#if defined (LLVM_3_2) || defined (LLVM_3_3) || defined (LLVM_3_4) || defined (LLVM_3_5) || defined (LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 static llvm::DIType lCreateDIArray(llvm::DIType eltType, int count) { #else // LLVM 3.7++ static llvm::DIType *lCreateDIArray(llvm::DIType *eltType, int count) { #endif -#ifdef LLVM_3_2 + +#if ISPC_LLVM_VERSION == ISPC_LLVM_3_2 int lowerBound = 0, upperBound = count-1; if (count == 0) { @@ -94,11 +95,11 @@ static llvm::DIType *lCreateDIArray(llvm::DIType *eltType, int count) { } llvm::Value *sub = m->diBuilder->getOrCreateSubrange(lowerBound, upperBound); -#elif defined (LLVM_3_3)|| defined (LLVM_3_4) || defined (LLVM_3_5) +#elif ISPC_LLVM_VERSION < ISPC_LLVM_3_6 llvm::Value *sub = m->diBuilder->getOrCreateSubrange(0, count); #endif -#if defined (LLVM_3_2) || defined (LLVM_3_3) || defined (LLVM_3_4) || defined (LLVM_3_5) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_6 std::vector subs; #else // LLVM 3.6++ llvm::Metadata *sub = m->diBuilder->getOrCreateSubrange(0, count); @@ -106,7 +107,7 @@ static llvm::DIType *lCreateDIArray(llvm::DIType *eltType, int count) { #endif subs.push_back(sub); -#if defined (LLVM_3_2) || defined (LLVM_3_3) || defined (LLVM_3_4) || defined (LLVM_3_5) || defined (LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIArray subArray = m->diBuilder->getOrCreateArray(subs); uint64_t size = eltType.getSizeInBits() * count; uint64_t align = eltType.getAlignInBits(); @@ -525,7 +526,7 @@ AtomicType::LLVMType(llvm::LLVMContext *ctx) const { } -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIType AtomicType::GetDIType(llvm::DIDescriptor scope) const { #else //LLVM 3.7++ llvm::DIType *AtomicType::GetDIType(llvm::DIScope *scope) const { @@ -535,7 +536,7 @@ llvm::DIType *AtomicType::GetDIType(llvm::DIScope *scope) const { if (variability.type == Variability::Uniform) { switch (basicType) { case TYPE_VOID: -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 return llvm::DIType(); #else //LLVM 3.7++ return NULL; @@ -586,7 +587,7 @@ llvm::DIType *AtomicType::GetDIType(llvm::DIScope *scope) const { break; default: FATAL("unhandled basic type in AtomicType::GetDIType()"); -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 return llvm::DIType(); #else //LLVM 3.7++ return NULL; @@ -594,21 +595,23 @@ llvm::DIType *AtomicType::GetDIType(llvm::DIScope *scope) const { } } else if (variability == Variability::Varying) { -#ifdef LLVM_3_2 +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_3 llvm::Value *sub = m->diBuilder->getOrCreateSubrange(0, g->target->getVectorWidth()-1); -#elif defined (LLVM_3_3)|| defined (LLVM_3_4) || defined (LLVM_3_5) +#elif ISPC_LLVM_VERSION >= ISPC_VERSION_3_3 && ISPC_LLVM_VERSION < ISPC_LLVM_3_6 llvm::Value *sub = m->diBuilder->getOrCreateSubrange(0, g->target->getVectorWidth()); #else // LLVM 3.6++ llvm::Metadata *sub = m->diBuilder->getOrCreateSubrange(0, g->target->getVectorWidth()); #endif -#if defined (LLVM_3_3)|| defined (LLVM_3_4) || defined (LLVM_3_5) || defined (LLVM_3_6) +#if ISPC_LLVM_VERSION >= ISPC_VERSION_3_3 && ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIArray subArray = m->diBuilder->getOrCreateArray(sub); llvm::DIType unifType = GetAsUniformType()->GetDIType(scope); uint64_t size = unifType.getSizeInBits() * g->target->getVectorWidth(); uint64_t align = unifType.getAlignInBits() * g->target->getVectorWidth(); -#else // LLVM 3.7++ +#elif ISPC_LLVM_VERSION >= ISPC_VERSION_3_7 // LLVM 3.7+ llvm::DINodeArray subArray = m->diBuilder->getOrCreateArray(sub); llvm::DIType *unifType = GetAsUniformType()->GetDIType(scope); + //llvm::DebugNodeArray subArray = m->diBuilder->getOrCreateArray(sub); + //llvm::MDType *unifType = GetAsUniformType()->GetDIType(scope); uint64_t size = unifType->getSizeInBits() * g->target->getVectorWidth(); uint64_t align = unifType->getAlignInBits()* g->target->getVectorWidth(); #endif @@ -844,13 +847,13 @@ EnumType::LLVMType(llvm::LLVMContext *ctx) const { } -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIType EnumType::GetDIType(llvm::DIDescriptor scope) const { #else // LLVM 3.7++ llvm::DIType *EnumType::GetDIType(llvm::DIScope *scope) const { #endif -#if defined (LLVM_3_2) || defined (LLVM_3_3) || defined (LLVM_3_4) || defined (LLVM_3_5) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_6 std::vector enumeratorDescriptors; #else // LLVM 3.6++ std::vector enumeratorDescriptors; @@ -860,7 +863,7 @@ llvm::DIType *EnumType::GetDIType(llvm::DIScope *scope) const { Assert(enumerators[i]->constValue != NULL); int count = enumerators[i]->constValue->GetValues(&enumeratorValue); Assert(count == 1); -#if defined (LLVM_3_2) || defined (LLVM_3_3) || defined (LLVM_3_4) || defined (LLVM_3_5) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_6 llvm::Value *descriptor = #else // LLVM 3.6++ llvm::Metadata *descriptor = @@ -868,7 +871,7 @@ llvm::DIType *EnumType::GetDIType(llvm::DIScope *scope) const { m->diBuilder->createEnumerator(enumerators[i]->name, enumeratorValue); enumeratorDescriptors.push_back(descriptor); } -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIArray elementArray = m->diBuilder->getOrCreateArray(enumeratorDescriptors); llvm::DIFile diFile = pos.GetDIFile(); @@ -891,19 +894,20 @@ llvm::DIType *EnumType::GetDIType(llvm::DIScope *scope) const { case Variability::Uniform: return diType; case Variability::Varying: { -#ifdef LLVM_3_2 +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_3 llvm::Value *sub = m->diBuilder->getOrCreateSubrange(0, g->target->getVectorWidth()-1); -#elif defined (LLVM_3_3)|| defined (LLVM_3_4) || defined (LLVM_3_5) +#elif ISPC_LLVM_VERSION < ISPC_LLVM_3_6 llvm::Value *sub = m->diBuilder->getOrCreateSubrange(0, g->target->getVectorWidth()); #else // LLVM 3.6++ llvm::Metadata *sub = m->diBuilder->getOrCreateSubrange(0, g->target->getVectorWidth()); #endif -#if defined (LLVM_3_3)|| defined (LLVM_3_4) || defined (LLVM_3_5) || defined (LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIArray subArray = m->diBuilder->getOrCreateArray(sub); - uint64_t size = diType.getSizeInBits() * g->target->getVectorWidth(); + uint64_t size = diType.getSizeInBits() * g->target->getVectorWidth(); uint64_t align = diType.getAlignInBits() * g->target->getVectorWidth(); -#else // LLVM 3.7++ +#elif ISPC_LLVM_VERSION >= ISPC_LLVM_3_7 // LLVM 3.7++ llvm::DINodeArray subArray = m->diBuilder->getOrCreateArray(sub); + //llvm::DebugNodeArray subArray = m->diBuilder->getOrCreateArray(sub); uint64_t size = diType->getSizeInBits() * g->target->getVectorWidth(); uint64_t align = diType->getAlignInBits()* g->target->getVectorWidth(); #endif @@ -914,7 +918,7 @@ llvm::DIType *EnumType::GetDIType(llvm::DIScope *scope) const { } default: FATAL("Unexpected variability in EnumType::GetDIType()"); -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 return llvm::DIType(); #else //LLVM 3.7++ return NULL; @@ -1252,7 +1256,7 @@ PointerType::LLVMType(llvm::LLVMContext *ctx) const { } -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIType PointerType::GetDIType(llvm::DIDescriptor scope) const { if (baseType == NULL) { Assert(m->errorCount > 0); @@ -1275,7 +1279,7 @@ llvm::DIType *PointerType::GetDIType(llvm::DIScope *scope) const { ptrAlignBits); case Variability::Varying: { // emit them as an array of pointers -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIType eltType = #else //LLVM 3.7++ llvm::DIDerivedType *eltType = @@ -1289,7 +1293,7 @@ llvm::DIType *PointerType::GetDIType(llvm::DIScope *scope) const { } default: FATAL("Unexpected variability in PointerType::GetDIType()"); -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 return llvm::DIType(); #else //LLVM 3.7++ return NULL; @@ -1567,7 +1571,7 @@ ArrayType::TotalElementCount() const { } -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIType ArrayType::GetDIType(llvm::DIDescriptor scope) const { if (child == NULL) { Assert(m->errorCount > 0); @@ -1816,16 +1820,16 @@ VectorType::LLVMType(llvm::LLVMContext *ctx) const { } -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIType VectorType::GetDIType(llvm::DIDescriptor scope) const { llvm::DIType eltType = base->GetDIType(scope); #else //LLVM 3.7++ llvm::DIType *VectorType::GetDIType(llvm::DIScope *scope) const { llvm::DIType *eltType = base->GetDIType(scope); #endif -#ifdef LLVM_3_2 +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_3 llvm::Value *sub = m->diBuilder->getOrCreateSubrange(0, numElements-1); -#elif defined (LLVM_3_3)|| defined (LLVM_3_4) || defined (LLVM_3_5) +#elif ISPC_LLVM_VERSION < ISPC_LLVM_3_6 llvm::Value *sub = m->diBuilder->getOrCreateSubrange(0, numElements); #else // LLVM 3.6++ llvm::Metadata *sub = m->diBuilder->getOrCreateSubrange(0, numElements); @@ -1834,7 +1838,7 @@ llvm::DIType *VectorType::GetDIType(llvm::DIScope *scope) const { // vectors of varying types are already naturally aligned to the // machine's vector width, but arrays of uniform types need to be // explicitly aligned to the machines natural vector alignment. -#if defined (LLVM_3_3)|| defined (LLVM_3_4) || defined (LLVM_3_5) || defined (LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIArray subArray = m->diBuilder->getOrCreateArray(sub); uint64_t sizeBits = eltType.getSizeInBits() * numElements; uint64_t align = eltType.getAlignInBits(); @@ -1855,7 +1859,7 @@ llvm::DIType *VectorType::GetDIType(llvm::DIScope *scope) const { } else { FATAL("Unexpected variability in VectorType::GetDIType()"); -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 return llvm::DIType(); #else // LLVM 3.7++ return NULL; @@ -2259,13 +2263,13 @@ StructType::LLVMType(llvm::LLVMContext *ctx) const { } -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIType StructType::GetDIType(llvm::DIDescriptor scope) const { #else //LLVM 3.7++ llvm::DIType *StructType::GetDIType(llvm::DIScope *scope) const { #endif uint64_t currentSize = 0, align = 0; -#if defined (LLVM_3_2) || defined (LLVM_3_3) || defined (LLVM_3_4) || defined (LLVM_3_5) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_6 std::vector elementLLVMTypes; #else // LLVM 3.6++ std::vector elementLLVMTypes; @@ -2274,7 +2278,7 @@ llvm::DIType *StructType::GetDIType(llvm::DIScope *scope) const { // alignment and size, using that to figure out its offset w.r.t. the // start of the structure. for (unsigned int i = 0; i < elementTypes.size(); ++i) { -#if defined (LLVM_3_2) || defined (LLVM_3_3) || defined (LLVM_3_4) || defined (LLVM_3_5) || defined (LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIType eltType = GetElementType(i)->GetDIType(scope); uint64_t eltAlign = eltType.getAlignInBits(); uint64_t eltSize = eltType.getSizeInBits(); @@ -2296,7 +2300,7 @@ llvm::DIType *StructType::GetDIType(llvm::DIScope *scope) const { Assert((currentSize == 0) || (currentSize % eltAlign) == 0); int line = elementPositions[i].first_line; -#if defined (LLVM_3_2) || defined (LLVM_3_3) || defined (LLVM_3_4) || defined (LLVM_3_5) || defined (LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIFile diFile = elementPositions[i].GetDIFile(); llvm::DIType fieldType = #else // LLVM 3.7++ @@ -2316,7 +2320,7 @@ llvm::DIType *StructType::GetDIType(llvm::DIScope *scope) const { if (currentSize > 0 && (currentSize % align)) currentSize += align - (currentSize % align); -#if defined (LLVM_3_2) || defined (LLVM_3_3) || defined (LLVM_3_4) || defined (LLVM_3_5) || defined (LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIArray elements = m->diBuilder->getOrCreateArray(elementLLVMTypes); llvm::DIFile diFile = pos.GetDIFile(); #else // LLVM 3.7++ @@ -2331,9 +2335,9 @@ llvm::DIType *StructType::GetDIType(llvm::DIScope *scope) const { currentSize, // Size in bits align, // Alignment in bits 0, // Flags -#if defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_3 && ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIType(), // DerivedFrom -#elif !defined(LLVM_3_2) // LLVM 3.7++ +#elif ISPC_LLVM_VERSION >= ISPC_LLVM_3_7 // LLVM 3.7++ NULL, #endif elements); @@ -2564,7 +2568,7 @@ UndefinedStructType::LLVMType(llvm::LLVMContext *ctx) const { } -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIType UndefinedStructType::GetDIType(llvm::DIDescriptor scope) const { llvm::DIFile diFile = pos.GetDIFile(); llvm::DIArray elements; @@ -2581,9 +2585,9 @@ llvm::DIType *UndefinedStructType::GetDIType(llvm::DIScope *scope) const { 0, // Size 0, // Align 0, // Flags -#if defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION >= ISPC_LLVM_3_3 && ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIType(), // DerivedFrom -#elif !defined(LLVM_3_2) // LLVM 3.7++ +#elif ISPC_LLVM_VERSION >= ISPC_LLVM_3_7 // LLVM 3.7++ NULL, #endif elements); @@ -2838,7 +2842,7 @@ ReferenceType::LLVMType(llvm::LLVMContext *ctx) const { } -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIType ReferenceType::GetDIType(llvm::DIDescriptor scope) const { if (targetType == NULL) { Assert(m->errorCount > 0); @@ -3117,13 +3121,13 @@ FunctionType::LLVMType(llvm::LLVMContext *ctx) const { } -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIType FunctionType::GetDIType(llvm::DIDescriptor scope) const { #else //LLVM 3.7++ llvm::DIType *FunctionType::GetDIType(llvm::DIScope *scope) const { #endif -#if defined (LLVM_3_2) || defined (LLVM_3_3) || defined (LLVM_3_4) || defined (LLVM_3_5) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_6 std::vector retArgTypes; #else // LLVM 3.6++ std::vector retArgTypes; @@ -3133,22 +3137,22 @@ llvm::DIType *FunctionType::GetDIType(llvm::DIScope *scope) const { const Type *t = GetParameterType(i); if (t == NULL) -#if defined(LLVM_3_2) || defined(LLVM_3_3) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_4 return llvm::DIType(); -#elif defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#elif ISPC_LLVM_VERSION < ISPC_LLVM_3_7 return llvm::DICompositeType(); #else // LLVM 3.7++ return NULL; #endif retArgTypes.push_back(t->GetDIType(scope)); } -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_6 llvm::DIArray retArgTypesArray = m->diBuilder->getOrCreateArray(llvm::ArrayRef(retArgTypes)); llvm::DIType diType = // FIXME: DIFile m->diBuilder->createSubroutineType(llvm::DIFile(), retArgTypesArray); -#elif defined(LLVM_3_6) +#elif ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DITypeArray retArgTypesArray = m->diBuilder->getOrCreateTypeArray(retArgTypes); llvm::DIType diType = diff --git a/type.h b/type.h index 91b318bf..a8c70512 100644 --- a/type.h +++ b/type.h @@ -40,10 +40,10 @@ #include "ispc.h" #include "util.h" -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_3 #include #include -#else +#else /* >= 3.3 */ #include #include #endif @@ -222,7 +222,7 @@ public: /** Returns the LLVM type corresponding to this ispc type */ virtual llvm::Type *LLVMType(llvm::LLVMContext *ctx) const = 0; -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 /** Returns the DIType (LLVM's debugging information structure), corresponding to this type. */ virtual llvm::DIType GetDIType(llvm::DIDescriptor scope) const = 0; @@ -317,7 +317,7 @@ public: std::string GetCDeclaration(const std::string &name) const; llvm::Type *LLVMType(llvm::LLVMContext *ctx) const; -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIType GetDIType(llvm::DIDescriptor scope) const; #else // LLVM 3.7++ llvm::DIType *GetDIType(llvm::DIScope *scope) const; @@ -400,7 +400,7 @@ public: const std::string &GetEnumName() const { return name; } llvm::Type *LLVMType(llvm::LLVMContext *ctx) const; -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIType GetDIType(llvm::DIDescriptor scope) const; #else // LLVM 3.7++ llvm::DIType *GetDIType(llvm::DIScope *scope) const; @@ -485,7 +485,7 @@ public: std::string GetCDeclaration(const std::string &name) const; llvm::Type *LLVMType(llvm::LLVMContext *ctx) const; -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIType GetDIType(llvm::DIDescriptor scope) const; #else // LLVM 3.7++ llvm::DIType *GetDIType(llvm::DIScope *scope) const; @@ -591,7 +591,7 @@ public: std::string Mangle() const; std::string GetCDeclaration(const std::string &name) const; -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIType GetDIType(llvm::DIDescriptor scope) const; #else // LLVM 3.7++ llvm::DIType *GetDIType(llvm::DIScope *scope) const; @@ -663,7 +663,7 @@ public: std::string GetCDeclaration(const std::string &name) const; llvm::Type *LLVMType(llvm::LLVMContext *ctx) const; -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIType GetDIType(llvm::DIDescriptor scope) const; #else // LLVM 3.7++ llvm::DIType *GetDIType(llvm::DIScope *scope) const; @@ -718,7 +718,7 @@ public: std::string GetCDeclaration(const std::string &name) const; llvm::Type *LLVMType(llvm::LLVMContext *ctx) const; -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIType GetDIType(llvm::DIDescriptor scope) const; #else // LLVM 3.7++ llvm::DIType *GetDIType(llvm::DIScope *scope) const; @@ -810,7 +810,7 @@ public: std::string GetCDeclaration(const std::string &name) const; llvm::Type *LLVMType(llvm::LLVMContext *ctx) const; -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIType GetDIType(llvm::DIDescriptor scope) const; #else // LLVM 3.7++ llvm::DIType *GetDIType(llvm::DIScope *scope) const; @@ -857,7 +857,7 @@ public: std::string GetCDeclaration(const std::string &name) const; llvm::Type *LLVMType(llvm::LLVMContext *ctx) const; -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIType GetDIType(llvm::DIDescriptor scope) const; #else // LLVM 3.7++ llvm::DIType *GetDIType(llvm::DIScope *scope) const; @@ -915,7 +915,7 @@ public: std::string GetCDeclarationForDispatch(const std::string &fname) const; llvm::Type *LLVMType(llvm::LLVMContext *ctx) const; -#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_7 llvm::DIType GetDIType(llvm::DIDescriptor scope) const; #else // LLVM 3.7++ llvm::DIType *GetDIType(llvm::DIScope *scope) const; diff --git a/util.cpp b/util.cpp index ba4249c3..fd076ade 100644 --- a/util.cpp +++ b/util.cpp @@ -65,7 +65,7 @@ #include #include -#if defined(LLVM_3_2) +#if ISPC_LLVM_VERSION < ISPC_LLVM_3_3 #include #else // LLVM 3.3+ #include