diff --git a/builtins.cpp b/builtins.cpp index 0193e8d3..6df7e6c6 100644 --- a/builtins.cpp +++ b/builtins.cpp @@ -48,6 +48,9 @@ #include #include #include +#if !defined(LLVM_3_0) && !defined(LLVM_3_1) + #include +#endif #include #include #include @@ -697,7 +700,11 @@ 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_0) || defined(LLVM_3_1) func->addFnAttr(llvm::Attribute::AlwaysInline); +#else + func->addFnAttr(llvm::Attributes::AlwaysInline); +#endif llvm::BasicBlock *bblock = llvm::BasicBlock::Create(*g->ctx, "entry", func, 0); llvm::ReturnInst::Create(*g->ctx, LLVMInt32(val), bblock); diff --git a/cbackend.cpp b/cbackend.cpp index b49e1d10..b433240e 100644 --- a/cbackend.cpp +++ b/cbackend.cpp @@ -61,7 +61,11 @@ #include "llvm/MC/MCRegisterInfo.h" #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/MC/MCSymbol.h" -#include "llvm/Target/TargetData.h" +#if defined(LLVM_3_0) || defined(LLVM_3_1) + #include "llvm/Target/TargetData.h" +#else + #include "llvm/DataLayout.h" +#endif #include "llvm/Support/CallSite.h" #include "llvm/Support/CFG.h" #include "llvm/Support/ErrorHandling.h" @@ -71,6 +75,7 @@ #include "llvm/Support/MathExtras.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/Host.h" +#include "llvm/Target/TargetMachine.h" #include "llvm/Config/config.h" #include @@ -84,9 +89,6 @@ #define snprintf _snprintf #endif -#include "llvm/Target/TargetMachine.h" -#include "llvm/Target/TargetData.h" - // FIXME: namespace { /// TypeFinder - Walk over a module, identifying all of the types that are @@ -229,7 +231,14 @@ namespace { const llvm::MCRegisterInfo *MRI; const llvm::MCObjectFileInfo *MOFI; llvm::MCContext *TCtx; +#if defined(LLVM_3_0) || defined(LLVM_3_1) const llvm::TargetData* TD; +#else + // FIXME: it's ugly to have the name be "TD" here, but it saves us + // lots of ifdefs in the below since the new DataLayout and the old + // TargetData have generally similar interfaces... + const llvm::DataLayout* TD; +#endif std::map FPConstantMap; #ifndef LLVM_3_0 @@ -569,12 +578,21 @@ void CWriter::printStructReturnPointerFunctionType(llvm::raw_ostream &Out, if (PrintedType) FunctionInnards << ", "; llvm::Type *ArgTy = *I; +#if defined(LLVM_3_0) || defined(LLVM_3_1) if (PAL.paramHasAttr(Idx, llvm::Attribute::ByVal)) { +#else + if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) { +#endif assert(ArgTy->isPointerTy()); ArgTy = llvm::cast(ArgTy)->getElementType(); } printType(FunctionInnards, ArgTy, - /*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt), ""); +#if defined(LLVM_3_0) || defined(LLVM_3_1) + /*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt), +#else + PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt), +#endif + ""); PrintedType = true; } if (FTy->isVarArg()) { @@ -586,7 +604,12 @@ void CWriter::printStructReturnPointerFunctionType(llvm::raw_ostream &Out, } FunctionInnards << ')'; printType(Out, RetTy, - /*isSigned=*/PAL.paramHasAttr(0, llvm::Attribute::SExt), FunctionInnards.str()); +#if defined(LLVM_3_0) || defined(LLVM_3_1) + /*isSigned=*/PAL.paramHasAttr(0, llvm::Attribute::SExt), +#else + PAL.getParamAttributes(0).hasAttribute(llvm::Attributes::SExt), +#endif + FunctionInnards.str()); } llvm::raw_ostream & @@ -696,14 +719,23 @@ 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_0) || defined(LLVM_3_1) if (PAL.paramHasAttr(Idx, llvm::Attribute::ByVal)) { +#else + if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) { +#endif assert(ArgTy->isPointerTy()); ArgTy = llvm::cast(ArgTy)->getElementType(); } if (I != FTy->param_begin()) FunctionInnards << ", "; printType(FunctionInnards, ArgTy, - /*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt), ""); +#if defined(LLVM_3_0) || defined(LLVM_3_1) + /*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt), +#else + PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt), +#endif + ""); ++Idx; } if (FTy->isVarArg()) { @@ -715,7 +747,12 @@ llvm::raw_ostream &CWriter::printType(llvm::raw_ostream &Out, llvm::Type *Ty, } FunctionInnards << ')'; printType(Out, FTy->getReturnType(), - /*isSigned=*/PAL.paramHasAttr(0, llvm::Attribute::SExt), FunctionInnards.str()); +#if defined(LLVM_3_0) || defined(LLVM_3_1) + /*isSigned=*/PAL.paramHasAttr(0, llvm::Attribute::SExt), +#else + PAL.getParamAttributes(0).hasAttribute(llvm::Attributes::SExt), +#endif + FunctionInnards.str()); return Out; } case llvm::Type::StructTyID: { @@ -1953,7 +1990,11 @@ void CWriter::writeOperandWithCast(llvm::Value* Operand, const llvm::ICmpInst &C // directives to cater to specific compilers as need be. // static void generateCompilerSpecificCode(llvm::formatted_raw_ostream& Out, +#if defined(LLVM_3_0) || defined(LLVM_3_1) const llvm::TargetData *TD) { +#else + const llvm::DataLayout *TD) { +#endif // We output GCC specific attributes to preserve 'linkonce'ness on globals. // If we aren't being compiled with GCC, just drop these attributes. Out << "#ifndef __GNUC__ /* Can only support \"linkonce\" vars with GCC */\n" @@ -2139,7 +2180,11 @@ bool CWriter::doInitialization(llvm::Module &M) { // Initialize TheModule = &M; +#if defined(LLVM_3_0) || defined(LLVM_3_1) TD = new llvm::TargetData(&M); +#else + TD = new llvm::DataLayout(&M); +#endif IL = new llvm::IntrinsicLowering(*TD); IL->AddPrototypes(M); @@ -2777,13 +2822,21 @@ void CWriter::printFunctionSignature(const llvm::Function *F, bool Prototype) { else ArgName = ""; llvm::Type *ArgTy = I->getType(); +#if defined(LLVM_3_0) || defined(LLVM_3_1) if (PAL.paramHasAttr(Idx, llvm::Attribute::ByVal)) { +#else + if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) { +#endif ArgTy = llvm::cast(ArgTy)->getElementType(); ByValParams.insert(I); } printType(FunctionInnards, ArgTy, - /*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt), - ArgName); +#if defined(LLVM_3_0) || defined(LLVM_3_1) + /*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt), +#else + PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt), +#endif + ArgName); PrintedArg = true; ++Idx; } @@ -2804,12 +2857,22 @@ void CWriter::printFunctionSignature(const llvm::Function *F, bool Prototype) { for (; I != E; ++I) { if (PrintedArg) FunctionInnards << ", "; llvm::Type *ArgTy = *I; +#if defined(LLVM_3_0) || defined(LLVM_3_1) if (PAL.paramHasAttr(Idx, llvm::Attribute::ByVal)) { +#else + if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) { +#endif assert(ArgTy->isPointerTy()); ArgTy = llvm::cast(ArgTy)->getElementType(); } printType(FunctionInnards, ArgTy, - /*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt)); +#if defined(LLVM_3_0) || defined(LLVM_3_1) + /*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt) +#else + PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt) + +#endif + ); PrintedArg = true; ++Idx; } @@ -2841,7 +2904,11 @@ 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_0) || defined(LLVM_3_1) /*isSigned=*/PAL.paramHasAttr(0, llvm::Attribute::SExt), +#else + PAL.getParamAttributes(0).hasAttribute(llvm::Attributes::SExt), +#endif FunctionInnards.str()); } @@ -3785,11 +3852,22 @@ void CWriter::visitCallInst(llvm::CallInst &I) { (*AI)->getType() != FTy->getParamType(ArgNo)) { Out << '('; printType(Out, FTy->getParamType(ArgNo), - /*isSigned=*/PAL.paramHasAttr(ArgNo+1, llvm::Attribute::SExt)); +#if defined(LLVM_3_0) || defined(LLVM_3_1) + /*isSigned=*/PAL.paramHasAttr(ArgNo+1, llvm::Attribute::SExt) +#else + PAL.getParamAttributes(ArgNo+1).hasAttribute(llvm::Attributes::SExt) +#endif + ); Out << ')'; } // Check if the argument is expected to be passed by value. - if (I.paramHasAttr(ArgNo+1, llvm::Attribute::ByVal)) + if (I.paramHasAttr(ArgNo+1, +#if defined(LLVM_3_0) || defined(LLVM_3_1) + llvm::Attribute::ByVal +#else + llvm::Attributes::ByVal +#endif + )) writeOperandDeref(*AI); else writeOperand(*AI); @@ -4394,8 +4472,13 @@ SmearCleanupPass::runOnBasicBlock(llvm::BasicBlock &bb) { matchType, NULL); smearFunc = llvm::dyn_cast(sf); assert(smearFunc != NULL); +#if defined(LLVM_3_0) || defined(LLVM_3_1) smearFunc->setDoesNotThrow(true); smearFunc->setDoesNotAccessMemory(true); +#else + smearFunc->setDoesNotThrow(); + smearFunc->setDoesNotAccessMemory(); +#endif } assert(smearFunc != NULL); @@ -4540,8 +4623,13 @@ AndCmpCleanupPass::runOnBasicBlock(llvm::BasicBlock &bb) { LLVMTypes::MaskType, NULL); andCmpFunc = llvm::dyn_cast(acf); Assert(andCmpFunc != NULL); +#if defined(LLVM_3_0) || defined(LLVM_3_1) andCmpFunc->setDoesNotThrow(true); andCmpFunc->setDoesNotAccessMemory(true); +#else + andCmpFunc->setDoesNotThrow(); + andCmpFunc->setDoesNotAccessMemory(); +#endif } // Set up the function call to the *_and_mask function; the @@ -4585,22 +4673,36 @@ public: notFunc = llvm::dyn_cast(m->getOrInsertFunction("__not", mt, mt, NULL)); assert(notFunc != NULL); +#if defined(LLVM_3_0) || defined(LLVM_3_1) notFunc->addFnAttr(llvm::Attribute::NoUnwind); notFunc->addFnAttr(llvm::Attribute::ReadNone); +#else + notFunc->addFnAttr(llvm::Attributes::NoUnwind); + notFunc->addFnAttr(llvm::Attributes::ReadNone); +#endif andNotFuncs[0] = llvm::dyn_cast(m->getOrInsertFunction("__and_not1", mt, mt, mt, NULL)); assert(andNotFuncs[0] != NULL); +#if defined(LLVM_3_0) || defined(LLVM_3_1) andNotFuncs[0]->addFnAttr(llvm::Attribute::NoUnwind); andNotFuncs[0]->addFnAttr(llvm::Attribute::ReadNone); - +#else + andNotFuncs[0]->addFnAttr(llvm::Attributes::NoUnwind); + andNotFuncs[0]->addFnAttr(llvm::Attributes::ReadNone); +#endif andNotFuncs[1] = llvm::dyn_cast(m->getOrInsertFunction("__and_not2", mt, mt, mt, NULL)); assert(andNotFuncs[1] != NULL); +#if defined(LLVM_3_0) || defined(LLVM_3_1) andNotFuncs[1]->addFnAttr(llvm::Attribute::NoUnwind); andNotFuncs[1]->addFnAttr(llvm::Attribute::ReadNone); +#else + andNotFuncs[1]->addFnAttr(llvm::Attributes::NoUnwind); + andNotFuncs[1]->addFnAttr(llvm::Attributes::ReadNone); +#endif } const char *getPassName() const { return "MaskOps Cleanup Pass"; } diff --git a/expr.cpp b/expr.cpp index 2f15f462..5d72a839 100644 --- a/expr.cpp +++ b/expr.cpp @@ -63,7 +63,6 @@ #include #include #include -#include #include #include diff --git a/func.cpp b/func.cpp index 8e072084..7f3eee21 100644 --- a/func.cpp +++ b/func.cpp @@ -59,7 +59,6 @@ #include #include #include -#include #include #include #include @@ -305,7 +304,7 @@ Function::emitCode(FunctionEmitContext *ctx, llvm::Function *function, #if defined(LLVM_3_0) || defined(LLVM_3_1) (function->hasFnAttr(llvm::Attribute::AlwaysInline) == false) #else - (function->getFnAttributes().hasAlwaysInlineAttr() == false) + (function->getFnAttributes().hasAttribute(llvm::Attributes::AlwaysInline) == false) #endif && costEstimate > CHECK_MASK_AT_FUNCTION_START_COST); @@ -443,7 +442,11 @@ Function::GenerateIR() { functionName += std::string("_") + g->target.GetISAString(); llvm::Function *appFunction = llvm::Function::Create(ftype, linkage, functionName.c_str(), m->module); +#if defined(LLVM_3_0) || defined(LLVM_3_1) appFunction->setDoesNotThrow(true); +#else + appFunction->setDoesNotThrow(); +#endif if (appFunction->getName() != functionName) { // this was a redefinition for which we already emitted an diff --git a/ispc.cpp b/ispc.cpp index 0aae5e90..e5a287e7 100644 --- a/ispc.cpp +++ b/ispc.cpp @@ -61,7 +61,11 @@ #include #include #include -#include +#if defined(LLVM_3_0) || defined(LLVM_3_1) + #include +#else + #include +#endif #include #include #include @@ -407,8 +411,14 @@ Target::GetTarget(const char *arch, const char *cpu, const char *isa, if (!error) { llvm::TargetMachine *targetMachine = t->GetTargetMachine(); +#if defined(LLVM_3_0) || defined(LLVM_3_1) const llvm::TargetData *targetData = targetMachine->getTargetData(); t->is32Bit = (targetData->getPointerSize() == 4); +#else + int addressSpace = 0; + const llvm::DataLayout *dataLayout = targetMachine->getDataLayout(); + t->is32Bit = (dataLayout->getPointerSize(addressSpace) == 4); +#endif Assert(t->vectorWidth <= ISPC_MAX_NVEC); } @@ -577,9 +587,16 @@ Target::SizeOf(llvm::Type *type, "sizeof_int", insertAtEnd); } +#if defined(LLVM_3_0) || defined(LLVM_3_1) const llvm::TargetData *td = GetTargetMachine()->getTargetData(); Assert(td != NULL); uint64_t bitSize = td->getTypeSizeInBits(type); +#else + const llvm::DataLayout *dl = GetTargetMachine()->getDataLayout(); + Assert(dl != NULL); + uint64_t bitSize = dl->getTypeSizeInBits(type); +#endif + Assert((bitSize % 8) == 0); uint64_t byteSize = bitSize / 8; if (is32Bit || g->opt.force32BitAddressing) @@ -610,15 +627,22 @@ Target::StructOffset(llvm::Type *type, int element, "offset_int", insertAtEnd); } - const llvm::TargetData *td = GetTargetMachine()->getTargetData(); - Assert(td != NULL); llvm::StructType *structType = llvm::dyn_cast(type); if (structType == NULL || structType->isSized() == false) { Assert(m->errorCount > 0); return NULL; } + +#if defined(LLVM_3_0) || defined(LLVM_3_1) + const llvm::TargetData *td = GetTargetMachine()->getTargetData(); + Assert(td != NULL); const llvm::StructLayout *sl = td->getStructLayout(structType); +#else + const llvm::DataLayout *dl = GetTargetMachine()->getDataLayout(); + Assert(dl != NULL); + const llvm::StructLayout *sl = dl->getStructLayout(structType); +#endif Assert(sl != NULL); uint64_t offset = sl->getElementOffset(element); diff --git a/module.cpp b/module.cpp index ce5ef4a5..d8975110 100644 --- a/module.cpp +++ b/module.cpp @@ -77,7 +77,12 @@ #include #include #include -#include +#if defined(LLVM_3_0) || defined(LLVM_3_1) + #include +#else + #include + #include +#endif #include #include #include @@ -751,14 +756,22 @@ Module::AddFunctionDeclaration(const std::string &name, module); // Set function attributes: we never throw exceptions - function->setDoesNotThrow(true); + function->setDoesNotThrow(); if (storageClass != SC_EXTERN_C && !g->generateDebuggingSymbols && isInline) +#if defined(LLVM_3_0) || defined(LLVM_3_1) function->addFnAttr(llvm::Attribute::AlwaysInline); +#else + function->addFnAttr(llvm::Attributes::AlwaysInline); +#endif if (functionType->isTask) // This also applies transitively to members I think? +#if defined(LLVM_3_0) || defined(LLVM_3_1) function->setDoesNotAlias(1, true); +#else + function->setDoesNotAlias(1); +#endif // Make sure that the return type isn't 'varying' or vector typed if // the function is 'export'ed. @@ -800,7 +813,12 @@ Module::AddFunctionDeclaration(const std::string &name, // NOTE: LLVM indexes function parameters starting from 1. // This is unintuitive. +#if defined(LLVM_3_0) || defined(LLVM_3_1) function->setDoesNotAlias(i+1, true); +#else + function->setDoesNotAlias(i+1); +#endif + #if 0 int align = 4 * RoundUpPow2(g->target.nativeVectorWidth); function->addAttribute(i+1, llvm::Attribute::constructAlignmentFromInt(align)); @@ -1022,16 +1040,27 @@ Module::writeObjectFileOrAssembly(llvm::TargetMachine *targetMachine, } llvm::PassManager pm; +#if defined(LLVM_3_0) || defined(LLVM_3_1) if (const llvm::TargetData *td = targetMachine->getTargetData()) pm.add(new llvm::TargetData(*td)); else pm.add(new llvm::TargetData(module)); +#else + if (const llvm::DataLayout *dl = targetMachine->getDataLayout()) + pm.add(new llvm::DataLayout(*dl)); + else + pm.add(new llvm::DataLayout(module)); +#endif llvm::formatted_raw_ostream fos(of->os()); + +#ifdef LLVM_3_0 llvm::CodeGenOpt::Level optLevel = (g->opt.level > 0) ? llvm::CodeGenOpt::Aggressive : llvm::CodeGenOpt::None; - if (targetMachine->addPassesToEmitFile(pm, fos, fileType, optLevel)) { +#else + if (targetMachine->addPassesToEmitFile(pm, fos, fileType)) { +#endif fprintf(stderr, "Fatal error adding passes to emit object file!"); exit(1); } diff --git a/opt.cpp b/opt.cpp index e2f38d8d..bb5ba955 100644 --- a/opt.cpp +++ b/opt.cpp @@ -64,7 +64,11 @@ #include #include #include -#include +#if defined(LLVM_3_0) || defined(LLVM_3_1) + #include +#else + #include +#endif #include #include #include @@ -403,7 +407,18 @@ Optimize(llvm::Module *module, int optLevel) { llvm::TargetLibraryInfo *targetLibraryInfo = new llvm::TargetLibraryInfo(llvm::Triple(module->getTargetTriple())); optPM.add(targetLibraryInfo); + +#if defined(LLVM_3_0) || defined(LLVM_3_1) optPM.add(new llvm::TargetData(module)); +#else + llvm::TargetMachine *targetMachine = g->target.GetTargetMachine(); + if (const llvm::DataLayout *dl = targetMachine->getDataLayout()) + optPM.add(new llvm::DataLayout(*dl)); + else + optPM.add(new llvm::DataLayout(module)); + optPM.add(new llvm::TargetTransformInfo(targetMachine->getScalarTargetTransformInfo(), + targetMachine->getVectorTargetTransformInfo())); +#endif optPM.add(llvm::createIndVarSimplifyPass()); diff --git a/type.cpp b/type.cpp index 942ff45c..ffc84252 100644 --- a/type.cpp +++ b/type.cpp @@ -816,7 +816,7 @@ EnumType::GetDIType(llvm::DIDescriptor scope) const { 32 /* align in bits */, elementArray #if !defined(LLVM_3_0) && !defined(LLVM_3_1) - , llvm::DIType(), 0 + , llvm::DIType() #endif );