From c02b38fe9af5149bae4d34bf66f66bbe7e00ad62 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Fri, 31 May 2013 20:22:38 +0200 Subject: [PATCH] Removed LLVM 3.0 compatibility code. There might be still some pieces left here and there, and there is certainly code that could be rewritten in a nicer way with the 3.0 requirement out of the picture. --- driver/main.cpp | 2 - driver/target.cpp | 16 --- driver/target.h | 3 - gen/llvmcompat.cpp | 169 ---------------------------- gen/llvmcompat.h | 21 ---- gen/llvmhelpers.cpp | 8 -- gen/optimizer.cpp | 6 - gen/optimizer.h | 4 - gen/passes/GarbageCollect2Stack.cpp | 5 +- gen/todebug.cpp | 14 +-- gen/tollvm.cpp | 12 +- 11 files changed, 6 insertions(+), 254 deletions(-) delete mode 100644 gen/llvmcompat.cpp diff --git a/driver/main.cpp b/driver/main.cpp index 3ac2aed707..c91b32f003 100644 --- a/driver/main.cpp +++ b/driver/main.cpp @@ -512,13 +512,11 @@ int main(int argc, char** argv) // FIXME: Detect O32/N32 variants (MIPS_{O32,N32}[_SoftFP,_HardFP]). VersionCondition::addPredefinedGlobalIdent("MIPS"); break; -#if LDC_LLVM_VER >= 301 case llvm::Triple::mips64: case llvm::Triple::mips64el: // FIXME: Detect N64 variants (MIPS64_N64[_SoftFP,_HardFP]). VersionCondition::addPredefinedGlobalIdent("MIPS64"); break; -#endif case llvm::Triple::sparc: // FIXME: Detect SPARC v8+ (SPARC_V8Plus). // FIXME: Detect soft float (SPARC_SoftFP/SPARC_HardFP). diff --git a/driver/target.cpp b/driver/target.cpp index 5c85bea0ed..4e4156aa72 100644 --- a/driver/target.cpp +++ b/driver/target.cpp @@ -13,7 +13,6 @@ //===----------------------------------------------------------------------===// #include "driver/target.h" -#include "gen/llvmcompat.h" #include "llvm/ADT/Triple.h" #include "llvm/MC/SubtargetFeature.h" #include "llvm/Support/Host.h" @@ -88,19 +87,11 @@ llvm::TargetMachine* createTargetMachine( std::string defaultTriple = llvm::sys::getDefaultTargetTriple(); if (sizeof(void*) == 4 && bitness == ExplicitBitness::M64) { -#if LDC_LLVM_VER >= 301 defaultTriple = llvm::Triple(defaultTriple).get64BitArchVariant().str(); -#else - defaultTriple = llvm::Triple__get64BitArchVariant(defaultTriple).str(); -#endif } else if (sizeof(void*) == 8 && bitness == ExplicitBitness::M32) { -#if LDC_LLVM_VER >= 301 defaultTriple = llvm::Triple(defaultTriple).get32BitArchVariant().str(); -#else - defaultTriple = llvm::Triple__get32BitArchVariant(defaultTriple).str(); -#endif } llvm::Triple triple; @@ -182,12 +173,6 @@ llvm::TargetMachine* createTargetMachine( relocModel = llvm::Reloc::PIC_; } -#if LDC_LLVM_VER == 300 - llvm::NoFramePointerElim = genDebugInfo; - - return theTarget->createTargetMachine(triple.str(), cpu, FeaturesStr, - relocModel, codeModel); -#else llvm::TargetOptions targetOptions; targetOptions.NoFramePointerElim = genDebugInfo; @@ -200,5 +185,4 @@ llvm::TargetMachine* createTargetMachine( codeModel, codeGenOptLevel ); -#endif } diff --git a/driver/target.h b/driver/target.h index 4eb4c63557..0b1b792693 100644 --- a/driver/target.h +++ b/driver/target.h @@ -16,9 +16,6 @@ #define LDC_DRIVER_TARGET_H #include "llvm/Support/CodeGen.h" -#if LDC_LLVM_VER == 300 -#include "llvm/Target/TargetMachine.h" // For llvm::CodeGenOpt::Level. -#endif #include #include diff --git a/gen/llvmcompat.cpp b/gen/llvmcompat.cpp deleted file mode 100644 index 17e0045c0f..0000000000 --- a/gen/llvmcompat.cpp +++ /dev/null @@ -1,169 +0,0 @@ -//===-- llvmcompat.cpp ----------------------------------------------------===// -// -// LDC – the LLVM D compiler -// -// This file is distributed under the BSD-style LDC license. See the LICENSE -// file for details. -// -//===----------------------------------------------------------------------===// - -#include "gen/llvmcompat.h" -#include "llvm/ADT/Triple.h" -#include "llvm/Config/llvm-config.h" -#if LDC_LLVM_VER >= 303 -#include "llvm/IR/DerivedTypes.h" -#include "llvm/IR/Function.h" -#include "llvm/IR/Module.h" -#include "llvm/IR/IRBuilder.h" -#else -#include "llvm/DerivedTypes.h" -#include "llvm/Function.h" -#include "llvm/Module.h" -#if LDC_LLVM_VER == 302 -#include "llvm/IRBuilder.h" -#else -#include "llvm/Support/IRBuilder.h" -#endif -#endif -#include - -#if LDC_LLVM_VER == 300 -using namespace llvm; - -std::string llvm::sys::getDefaultTargetTriple() { - return LLVM_HOSTTRIPLE; -} - -Triple llvm::Triple__get32BitArchVariant(const std::string& triple) { - Triple T(triple); - switch (T.getArch()) { - case Triple::UnknownArch: - case Triple::msp430: -#if LDC_LLVM_VER == 300 - case Triple::alpha: - case Triple::systemz: -#endif - T.setArch(Triple::UnknownArch); - break; - - case Triple::amdil: - case Triple::arm: - case Triple::cellspu: - case Triple::le32: - case Triple::mblaze: - case Triple::mips: - case Triple::mipsel: - case Triple::ppc: - case Triple::sparc: - case Triple::tce: - case Triple::thumb: - case Triple::x86: - case Triple::xcore: -#if LDC_LLVM_VER == 300 - case Triple::bfin: -#endif - // Already 32-bit. - break; - - case Triple::mips64: T.setArch(Triple::mips); break; - case Triple::mips64el: T.setArch(Triple::mipsel); break; - case Triple::ppc64: T.setArch(Triple::ppc); break; - case Triple::sparcv9: T.setArch(Triple::sparc); break; - case Triple::x86_64: T.setArch(Triple::x86); break; -#if LDC_LLVM_VER == 300 - case Triple::ptx64: T.setArch(Triple::ptx32); break; -#endif - } - return T; -} - -Triple llvm::Triple__get64BitArchVariant(const std::string& triple) { - Triple T(triple); - switch (T.getArch()) { - case Triple::UnknownArch: - case Triple::amdil: - case Triple::arm: - case Triple::cellspu: - case Triple::le32: - case Triple::mblaze: - case Triple::msp430: - case Triple::tce: - case Triple::thumb: - case Triple::xcore: -#if LDC_LLVM_VER == 300 - case Triple::bfin: -#endif - T.setArch(Triple::UnknownArch); - break; - -#if LDC_LLVM_VER == 300 - case Triple::alpha: - case Triple::systemz: -#endif - case Triple::mips64: - case Triple::mips64el: - case Triple::ppc64: - case Triple::sparcv9: - case Triple::x86_64: - // Already 64-bit. - break; - - case Triple::mips: T.setArch(Triple::mips64); break; - case Triple::mipsel: T.setArch(Triple::mips64el); break; - case Triple::ppc: T.setArch(Triple::ppc64); break; - case Triple::sparc: T.setArch(Triple::sparcv9); break; - case Triple::x86: T.setArch(Triple::x86_64); break; -#if LDC_LLVM_VER == 300 - case Triple::ptx32: T.setArch(Triple::ptx64); break; -#endif - } - return T; -} - -static void appendToGlobalArray(const char *Array, - Module &M, Function *F, int Priority) { - IRBuilder<> IRB(M.getContext()); - FunctionType *FnTy = FunctionType::get(IRB.getVoidTy(), false); - StructType *Ty = StructType::get( - IRB.getInt32Ty(), PointerType::getUnqual(FnTy), NULL); - - Constant *RuntimeCtorInit = ConstantStruct::get( - Ty, IRB.getInt32(Priority), F, NULL); - - // Get the current set of static global constructors and add the new ctor - // to the list. - SmallVector CurrentCtors; - if (GlobalVariable * GVCtor = M.getNamedGlobal(Array)) { - if (Constant *Init = GVCtor->getInitializer()) { - unsigned n = Init->getNumOperands(); - CurrentCtors.reserve(n + 1); - for (unsigned i = 0; i != n; ++i) - CurrentCtors.push_back(cast(Init->getOperand(i))); - } - GVCtor->eraseFromParent(); - } - - CurrentCtors.push_back(RuntimeCtorInit); - - // Create a new initializer. - ArrayType *AT = ArrayType::get(RuntimeCtorInit->getType(), - CurrentCtors.size()); - Constant *NewInit = ConstantArray::get(AT, CurrentCtors); - - // Create the new global variable and replace all uses of - // the old global variable with the new one. - (void)new GlobalVariable(M, NewInit->getType(), false, - GlobalValue::AppendingLinkage, NewInit, Array); -} - -void llvm::appendToGlobalCtors(Module &M, Function *F, int Priority) { - appendToGlobalArray("llvm.global_ctors", M, F, Priority); -} - -void llvm::appendToGlobalDtors(Module &M, Function *F, int Priority) { - appendToGlobalArray("llvm.global_dtors", M, F, Priority); -} - -#endif - - diff --git a/gen/llvmcompat.h b/gen/llvmcompat.h index b73d346abf..6435153b01 100644 --- a/gen/llvmcompat.h +++ b/gen/llvmcompat.h @@ -20,31 +20,10 @@ #ifndef LDC_LLVMCOMPAT_H #define LDC_LLVMCOMPAT_H -#include "llvm/ADT/Triple.h" -#include - #if !defined(LDC_LLVM_VER) #error "Please specify value for LDC_LLVM_VER." #endif -#if LDC_LLVM_VER == 300 -namespace llvm { - class Module; - class Function; - - namespace sys { - std::string getDefaultTargetTriple(); - } - - Triple Triple__get32BitArchVariant(const std::string&_this); - Triple Triple__get64BitArchVariant(const std::string& _this); - - // From Transforms/Utils/ModuleUtils - void appendToGlobalCtors(Module &M, Function *F, int Priority); - void appendToGlobalDtors(Module &M, Function *F, int Priority); -} -#endif - #if LDC_LLVM_VER >= 302 #define ADDRESS_SPACE 0 #define HAS_ATTRIBUTES(x) (x).hasAttributes() diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index c36d56415d..ff820bea8d 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -31,9 +31,7 @@ #include "ir/irmodule.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/Target/TargetMachine.h" -#if LDC_LLVM_VER >= 301 #include "llvm/Transforms/Utils/ModuleUtils.h" -#endif #include /****************************************************************************************/ @@ -1446,13 +1444,7 @@ LLConstant* DtoConstExpInit(Loc loc, Type* type, Expression* exp) assert(tv->basetype->ty == Tsarray); dinteger_t elemCount = static_cast(tv->basetype)->dim->toInteger(); - -#if LDC_LLVM_VER == 300 - std::vector Elts(elemCount, val); - return llvm::ConstantVector::get(Elts); -#else return llvm::ConstantVector::getSplat(elemCount, val); -#endif } error(loc, "LDC internal error: cannot yet convert default initializer %s of type %s to %s", diff --git a/gen/optimizer.cpp b/gen/optimizer.cpp index c2f1598dbf..86c6c5a59b 100644 --- a/gen/optimizer.cpp +++ b/gen/optimizer.cpp @@ -196,17 +196,11 @@ static void addOptimizationPasses(PassManagerBase &mpm, FunctionPassManager &fpm #endif // USE_METADATA } -#if LDC_LLVM_VER >= 301 // EP_OptimizerLast does not exist in LLVM 3.0, add it manually below. builder.addExtension(PassManagerBuilder::EP_OptimizerLast, addStripExternalsPass); -#endif builder.populateFunctionPassManager(fpm); builder.populateModulePassManager(mpm); - -#if LDC_LLVM_VER < 301 - addStripExternalsPass(builder, mpm); -#endif } ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/gen/optimizer.h b/gen/optimizer.h index 8f4950e13c..b5091e9eae 100644 --- a/gen/optimizer.h +++ b/gen/optimizer.h @@ -16,11 +16,7 @@ #define LDC_GEN_OPTIMIZER_H // For llvm::CodeGenOpt::Level -#if LDC_LLVM_VER == 300 -#include "llvm/Target/TargetMachine.h" -#else #include "llvm/Support/CodeGen.h" -#endif namespace llvm { class Module; } diff --git a/gen/passes/GarbageCollect2Stack.cpp b/gen/passes/GarbageCollect2Stack.cpp index 70e520a9f7..a65d89e24d 100644 --- a/gen/passes/GarbageCollect2Stack.cpp +++ b/gen/passes/GarbageCollect2Stack.cpp @@ -200,11 +200,8 @@ namespace { APInt Mask = APInt::getLowBitsSet(Bits, BitsLimit); Mask.flipAllBits(); APInt KnownZero(Bits, 0), KnownOne(Bits, 0); - #if LDC_LLVM_VER >= 301 ComputeMaskedBits(arrSize, KnownZero, KnownOne, &A.TD); - #else - ComputeMaskedBits(arrSize, Mask, KnownZero, KnownOne, &A.TD); - #endif + if ((KnownZero & Mask) != Mask) return false; } diff --git a/gen/todebug.cpp b/gen/todebug.cpp index 95223de612..b366896228 100644 --- a/gen/todebug.cpp +++ b/gen/todebug.cpp @@ -255,17 +255,13 @@ static llvm::DIType dwarfCompositeType(Type* type) // set diCompositeType to handle recursive types properly if (!ir->diCompositeType) { -#if LDC_LLVM_VER >= 301 unsigned tag = (t->ty == Tstruct) ? llvm::dwarf::DW_TAG_structure_type : llvm::dwarf::DW_TAG_class_type; - ir->diCompositeType = gIR->dibuilder.createForwardDecl(tag, name, + ir->diCompositeType = gIR->dibuilder.createForwardDecl(tag, name, #if LDC_LLVM_VER >= 302 llvm::DIDescriptor(file), #endif file, linnum); -#else - ir->diCompositeType = gIR->dibuilder.createTemporaryType(); -#endif } if (!ir->aggrdecl->isInterfaceDeclaration()) // plain interfaces don't have one @@ -542,9 +538,7 @@ llvm::DISubprogram DtoDwarfSubProgram(FuncDeclaration* fd) DIFnType, // type fd->protection == PROTprivate, // is local to unit gIR->dmodule == getDefinedModule(fd), // isdefinition -#if LDC_LLVM_VER >= 301 fd->loc.linnum, // FIXME: scope line -#endif 0, // Flags false, // isOptimized fd->ir.irFunc->func @@ -583,10 +577,8 @@ llvm::DISubprogram DtoDwarfSubProgramInternal(const char* prettyname, const char 0, // line no DIFnType, // return type. TODO: fill it up true, // is local to unit - true // isdefinition -#if LDC_LLVM_VER >= 301 - , 0 // FIXME: scope line -#endif + true, // isdefinition + 0 // FIXME: scope line ); } diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp index dbee41033f..9362888575 100644 --- a/gen/tollvm.cpp +++ b/gen/tollvm.cpp @@ -673,11 +673,7 @@ LLConstant* DtoConstFP(Type* t, longdouble value) LLConstant* DtoConstString(const char* str) { llvm::StringRef s(str ? str : ""); -#if LDC_LLVM_VER == 300 - LLConstant* init = LLConstantArray::get(gIR->context(), s, true); -#else LLConstant* init = llvm::ConstantDataArray::getString(gIR->context(), s, true); -#endif llvm::GlobalVariable* gvar = new llvm::GlobalVariable( *gIR->module, init->getType(), true, llvm::GlobalValue::InternalLinkage, init, ".str"); gvar->setUnnamedAddr(true); @@ -691,12 +687,8 @@ LLConstant* DtoConstString(const char* str) LLConstant* DtoConstStringPtr(const char* str, const char* section) { - llvm::StringRef s(str); -#if LDC_LLVM_VER == 300 - LLConstant* init = LLConstantArray::get(gIR->context(), s, true); -#else - LLConstant* init = llvm::ConstantDataArray::getString(gIR->context(), s, true); -#endif + llvm::StringRef s(str); + LLConstant* init = llvm::ConstantDataArray::getString(gIR->context(), s, true); llvm::GlobalVariable* gvar = new llvm::GlobalVariable( *gIR->module, init->getType(), true, llvm::GlobalValue::InternalLinkage, init, ".str"); if (section) gvar->setSection(section);