diff --git a/dmd2/declaration.h b/dmd2/declaration.h index 418eb0043b..121cdd2fdb 100644 --- a/dmd2/declaration.h +++ b/dmd2/declaration.h @@ -19,7 +19,9 @@ #include #include #include -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 305 +#include "llvm/IR/DebugInfo.h" +#elif LDC_LLVM_VER >= 302 #include "llvm/DebugInfo.h" #else #include "llvm/Analysis/DebugInfo.h" diff --git a/driver/linker.cpp b/driver/linker.cpp index e533e30254..e6c22f6cb9 100644 --- a/driver/linker.cpp +++ b/driver/linker.cpp @@ -18,7 +18,11 @@ #include "gen/optimizer.h" #include "gen/programs.h" #include "llvm/ADT/Triple.h" +#if LDC_LLVM_VER >= 305 +#include "llvm/Linker/Linker.h" +#else #include "llvm/Linker.h" +#endif #include "llvm/Support/FileSystem.h" #include "llvm/Support/Program.h" #include "llvm/Support/Path.h" diff --git a/driver/main.cpp b/driver/main.cpp index 0d8869c64d..b8744889f8 100644 --- a/driver/main.cpp +++ b/driver/main.cpp @@ -32,7 +32,15 @@ #include "gen/optimizer.h" #include "gen/passes/Passes.h" #include "gen/runtime.h" +#if LDC_LLVM_VER >= 304 +#include "llvm/InitializePasses.h" +#endif +#include "llvm/LinkAllPasses.h" +#if LDC_LLVM_VER >= 305 +#include "llvm/Linker/Linker.h" +#else #include "llvm/Linker.h" +#endif #include "llvm/Support/Host.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/TargetRegistry.h" @@ -464,6 +472,29 @@ static void parseCommandLine(int argc, char **argv, Strings &sourceFiles, bool & } } +static void initializePasses() { +#if LDC_LLVM_VER >= 304 + using namespace llvm; + // Initialize passes + PassRegistry &Registry = *PassRegistry::getPassRegistry(); + initializeCore(Registry); + initializeDebugIRPass(Registry); + initializeScalarOpts(Registry); + initializeObjCARCOpts(Registry); + initializeVectorization(Registry); + initializeIPO(Registry); + initializeAnalysis(Registry); + initializeIPA(Registry); + initializeTransformUtils(Registry); + initializeInstCombine(Registry); + initializeInstrumentation(Registry); + initializeTarget(Registry); + // For codegen passes, only passes that do IR to IR transformation are + // supported. For now, just add CodeGenPrepare. + initializeCodeGenPreparePass(Registry); +#endif +} + /// Registers the predefined versions specific to the current target triple /// and other target specific options with VersionCondition. static void registerPredefinedTargetVersions() { @@ -748,6 +779,8 @@ int main(int argc, char **argv) llvm::InitializeAllAsmPrinters(); llvm::InitializeAllAsmParsers(); + initializePasses(); + bool helpOnly; Strings files; parseCommandLine(argc, argv, files, helpOnly); diff --git a/driver/toobj.cpp b/driver/toobj.cpp index 2c5a02c2a1..86d55f769f 100644 --- a/driver/toobj.cpp +++ b/driver/toobj.cpp @@ -60,7 +60,12 @@ static void codegenModule(llvm::TargetMachine &Target, llvm::Module& m, // Build up all of the passes that we want to do to the module. FunctionPassManager Passes(&m); -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 305 + if (const DataLayout *DL = Target.getDataLayout()) + Passes.add(new DataLayoutPass(*DL)); + else + Passes.add(new DataLayoutPass(&m)); +#elif LDC_LLVM_VER >= 302 if (const DataLayout *DL = Target.getDataLayout()) Passes.add(new DataLayout(*DL)); else @@ -136,7 +141,13 @@ void writeModule(llvm::Module* m, std::string filename) llvm::sys::path::replace_extension(bcpath, global.bc_ext); Logger::println("Writing LLVM bitcode to: %s\n", bcpath.c_str()); std::string errinfo; - llvm::raw_fd_ostream bos(bcpath.c_str(), errinfo, llvm::sys::fs::F_Binary); + llvm::raw_fd_ostream bos(bcpath.c_str(), errinfo, +#if LDC_LLVM_VER >= 305 + llvm::sys::fs::F_None +#else + llvm::sys::fs::F_Binary +#endif + ); if (bos.has_error()) { error(Loc(), "cannot write LLVM bitcode file '%s': %s", bcpath.c_str(), errinfo.c_str()); @@ -151,7 +162,13 @@ void writeModule(llvm::Module* m, std::string filename) llvm::sys::path::replace_extension(llpath, global.ll_ext); Logger::println("Writing LLVM asm to: %s\n", llpath.c_str()); std::string errinfo; - llvm::raw_fd_ostream aos(llpath.c_str(), errinfo); + llvm::raw_fd_ostream aos(llpath.c_str(), errinfo, +#if LDC_LLVM_VER >= 305 + llvm::sys::fs::F_None +#else + llvm::sys::fs::F_Binary +#endif + ); if (aos.has_error()) { error(Loc(), "cannot write LLVM asm file '%s': %s", llpath.c_str(), errinfo.c_str()); @@ -180,7 +197,13 @@ void writeModule(llvm::Module* m, std::string filename) Logger::println("Writing native asm to: %s\n", spath.c_str()); std::string err; { - llvm::raw_fd_ostream out(spath.c_str(), err); + llvm::raw_fd_ostream out(spath.c_str(), err, +#if LDC_LLVM_VER >= 305 + llvm::sys::fs::F_None +#else + llvm::sys::fs::F_Binary +#endif + ); if (err.empty()) { codegenModule(*gTargetMachine, *m, out, llvm::TargetMachine::CGFT_AssemblyFile); @@ -210,7 +233,13 @@ void writeModule(llvm::Module* m, std::string filename) Logger::println("Writing object file to: %s\n", objpath.c_str()); std::string err; { - llvm::raw_fd_ostream out(objpath.c_str(), err, llvm::sys::fs::F_Binary); + llvm::raw_fd_ostream out(objpath.c_str(), err, +#if LDC_LLVM_VER >= 305 + llvm::sys::fs::F_None +#else + llvm::sys::fs::F_Binary +#endif + ); if (err.empty()) { codegenModule(*gTargetMachine, *m, out, llvm::TargetMachine::CGFT_ObjectFile); diff --git a/gen/dibuilder.cpp b/gen/dibuilder.cpp index bfe8aa8b49..0e67322400 100644 --- a/gen/dibuilder.cpp +++ b/gen/dibuilder.cpp @@ -664,6 +664,9 @@ void ldc::DIBuilder::EmitBlockStart(Loc loc) CreateFile(loc), // file loc.linnum, // line 0 // column +#if LDC_LLVM_VER >= 305 + , 0 // DWARF path discriminator value +#endif ); IR->func()->diLexicalBlocks.push(block); EmitStopPoint(loc.linnum); diff --git a/gen/dibuilder.h b/gen/dibuilder.h index 5eb6faff7e..916cc09f01 100644 --- a/gen/dibuilder.h +++ b/gen/dibuilder.h @@ -14,8 +14,13 @@ #include "llvm/IR/Constants.h" #include "llvm/IR/Type.h" #include "llvm/IR/DataLayout.h" +#if LDC_LLVM_VER >= 305 +#include "llvm/IR/DebugInfo.h" +#include "llvm/IR/DIBuilder.h" +#else #include "llvm/DebugInfo.h" #include "llvm/DIBuilder.h" +#endif #else #if LDC_LLVM_VER == 302 #include "llvm/DataLayout.h" diff --git a/gen/functions.cpp b/gen/functions.cpp index 439ff296b5..6ca41014e1 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -29,13 +29,21 @@ #include "gen/pragma.h" #include "gen/runtime.h" #include "gen/tollvm.h" +#if LDC_LLVM_VER >= 305 +#include "llvm/Linker/Linker.h" +#else #include "llvm/Linker.h" +#endif #if LDC_LLVM_VER >= 303 #include "llvm/IR/Intrinsics.h" #else #include "llvm/Intrinsics.h" #endif +#if LDC_LLVM_VER >= 305 +#include "llvm/IR/CFG.h" +#else #include "llvm/Support/CFG.h" +#endif #include #if LDC_LLVM_VER == 302 diff --git a/gen/irstate.h b/gen/irstate.h index bd3a04f63f..b6598c0786 100644 --- a/gen/irstate.h +++ b/gen/irstate.h @@ -26,7 +26,11 @@ #include #include +#if LDC_LLVM_VER >= 305 +#include "llvm/IR/CallSite.h" +#else #include "llvm/Support/CallSite.h" +#endif namespace llvm { class LLVMContext; diff --git a/gen/llvm.h b/gen/llvm.h index 77cc2c86cf..288e6668bd 100644 --- a/gen/llvm.h +++ b/gen/llvm.h @@ -31,7 +31,11 @@ #include "llvm/IR/Attributes.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/IRBuilder.h" +#if LDC_LLVM_VER >= 305 +#include "llvm/IR/DebugInfo.h" +#else #include "llvm/DebugInfo.h" +#endif #else #include "llvm/Type.h" #include "llvm/DerivedTypes.h" @@ -57,7 +61,11 @@ #include "gen/llvmcompat.h" +#if LDC_LLVM_VER >= 305 +#include "llvm/IR/CallSite.h" +#else #include "llvm/Support/CallSite.h" +#endif using llvm::IRBuilder; diff --git a/gen/optimizer.cpp b/gen/optimizer.cpp index 888a5329df..a7514b155e 100644 --- a/gen/optimizer.cpp +++ b/gen/optimizer.cpp @@ -34,11 +34,16 @@ #include "llvm/Target/TargetLibraryInfo.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Support/CommandLine.h" +#if LDC_LLVM_VER >= 305 +#include "llvm/IR/LegacyPassNameParser.h" +#else #include "llvm/Support/PassNameParser.h" +#endif #include "llvm/Transforms/Instrumentation.h" #include "llvm/Transforms/IPO.h" #include "llvm/Transforms/IPO/PassManagerBuilder.h" +extern llvm::TargetMachine* gTargetMachine; using namespace llvm; // Allow the user to specify specific optimizations to run. @@ -306,14 +311,14 @@ static void addOptimizationPasses(PassManagerBase &mpm, FunctionPassManager &fpm ////////////////////////////////////////////////////////////////////////////////////////// // This function runs optimization passes based on command line arguments. // Returns true if any optimization passes were invoked. -bool ldc_optimize_module(llvm::Module* m) +bool ldc_optimize_module(llvm::Module *M) { // Create a PassManager to hold and optimize the collection of // per-module passes we are about to build. PassManager mpm; // Add an appropriate TargetLibraryInfo pass for the module's triple. - TargetLibraryInfo *tli = new TargetLibraryInfo(Triple(m->getTargetTriple())); + TargetLibraryInfo *tli = new TargetLibraryInfo(Triple(M->getTargetTriple())); // The -disable-simplify-libcalls flag actually disables all builtin optzns. if (disableSimplifyLibCalls) @@ -321,19 +326,31 @@ bool ldc_optimize_module(llvm::Module* m) mpm.add(tli); - // Add an appropriate TargetData instance for this module. -#if LDC_LLVM_VER >= 302 - mpm.add(new DataLayout(m)); + // Add an appropriate DataLayout instance for this module. +#if LDC_LLVM_VER >= 305 + const DataLayout *DL = M->getDataLayout(); + assert(DL && "DataLayout not set at module"); + mpm.add(new DataLayoutPass(*DL)); +#elif LDC_LLVM_VER >= 302 + mpm.add(new DataLayout(M)); #else - mpm.add(new TargetData(m)); + mpm.add(new TargetData(M)); +#endif + +#if LDC_LLVM_VER >= 305 + // Add internal analysis passes from the target machine. + gTargetMachine->addAnalysisPasses(mpm); #endif // Also set up a manager for the per-function passes. - FunctionPassManager fpm(m); -#if LDC_LLVM_VER >= 302 - fpm.add(new DataLayout(m)); + FunctionPassManager fpm(M); +#if LDC_LLVM_VER >= 305 + fpm.add(new DataLayoutPass(M)); + gTargetMachine->addAnalysisPasses(fpm); +#elif LDC_LLVM_VER >= 302 + fpm.add(new DataLayout(M)); #else - fpm.add(new TargetData(m)); + fpm.add(new TargetData(M)); #endif // If the -strip-debug command line option was specified, add it before @@ -372,15 +389,15 @@ bool ldc_optimize_module(llvm::Module* m) // Run per-function passes. fpm.doInitialization(); - for (llvm::Module::iterator F = m->begin(), E = m->end(); F != E; ++F) + for (llvm::Module::iterator F = M->begin(), E = M->end(); F != E; ++F) fpm.run(*F); fpm.doFinalization(); // Run per-module passes. - mpm.run(*m); + mpm.run(*M); // Verify the resulting module. - verifyModule(m); + verifyModule(M); // Report that we run some passes. return true; diff --git a/gen/passes/GarbageCollect2Stack.cpp b/gen/passes/GarbageCollect2Stack.cpp index 5c86700020..38a64fe7ed 100644 --- a/gen/passes/GarbageCollect2Stack.cpp +++ b/gen/passes/GarbageCollect2Stack.cpp @@ -38,7 +38,11 @@ #include "llvm/Target/TargetData.h" #endif #endif +#if LDC_LLVM_VER >= 305 +#include "llvm/IR/CallSite.h" +#else #include "llvm/Support/CallSite.h" +#endif #include "llvm/Support/CommandLine.h" #include "llvm/Analysis/CallGraph.h" #if LDC_LLVM_VER >= 305 @@ -74,7 +78,7 @@ SizeLimit("dgc2stack-size-limit", cl::init(1024), cl::Hidden, namespace { struct Analysis { - DataLayout& DL; + const DataLayout& DL; const Module& M; CallGraph* CG; CallGraphNode* CGNode; @@ -394,17 +398,14 @@ namespace { bool runOnFunction(Function &F); virtual void getAnalysisUsage(AnalysisUsage &AU) const { - AU.addRequired(); #if LDC_LLVM_VER >= 305 - AU.addRequired(); + AU.addRequired(); + AU.addRequired(); + AU.addPreserved(); #else - AU.addRequired(); -#endif - -#if LDC_LLVM_VER >= 305 - AU.addPreserved(); -#else - AU.addPreserved(); + AU.addRequired(); + AU.addRequired(); + AU.addPreserved(); #endif } }; @@ -462,19 +463,19 @@ static bool isSafeToStackAllocate(Instruction* Alloc, Value* V, DominatorTree& D bool GarbageCollect2Stack::runOnFunction(Function &F) { DEBUG(errs() << "\nRunning -dgc2stack on function " << F.getName() << '\n'); - DataLayout& DL = getAnalysis(); #if LDC_LLVM_VER >= 305 + DataLayoutPass *DLP = getAnalysisIfAvailable(); + assert(DLP && "required DataLayoutPass is null"); + const DataLayout &DL = DLP->getDataLayout(); DominatorTree &DT = getAnalysis().getDomTree(); + CallGraphWrapperPass *CGPass = getAnalysisIfAvailable(); + CallGraph *CG = CGPass ? &CGPass->getCallGraph() : 0; #else - DominatorTree& DT = getAnalysis(); + DataLayout &DL = getAnalysis(); + DominatorTree &DT = getAnalysis(); + CallGraph *CG = getAnalysisIfAvailable(); #endif -#if LDC_LLVM_VER >= 305 - CallGraphWrapperPass* CGPass = getAnalysisIfAvailable(); - CallGraph* CG = CGPass ? &CGPass->getCallGraph() : 0; -#else - CallGraph* CG = getAnalysisIfAvailable(); -#endif - CallGraphNode* CGNode = CG ? (*CG)[&F] : NULL; + CallGraphNode *CGNode = CG ? (*CG)[&F] : NULL; Analysis A = { DL, *M, CG, CGNode }; @@ -789,7 +790,11 @@ bool isSafeToStackAllocate(Instruction* Alloc, Value* V, DominatorTree& DT, for (Value::use_iterator UI = V->use_begin(), UE = V->use_end(); UI != UE; ++UI) { +#if LDC_LLVM_VER >= 305 + Use *U = &(*UI); +#else Use *U = &UI.getUse(); +#endif Visited.insert(U); Worklist.push_back(U); } @@ -865,7 +870,11 @@ bool isSafeToStackAllocate(Instruction* Alloc, Value* V, DominatorTree& DT, // The original value is not captured via this if the new value isn't. for (Instruction::use_iterator UI = I->use_begin(), UE = I->use_end(); UI != UE; ++UI) { +#if LDC_LLVM_VER >= 305 + Use *U = &(*UI); +#else Use *U = &UI.getUse(); +#endif if (Visited.insert(U)) Worklist.push_back(U); } diff --git a/gen/passes/SimplifyDRuntimeCalls.cpp b/gen/passes/SimplifyDRuntimeCalls.cpp index 07e241c210..16fa77d822 100644 --- a/gen/passes/SimplifyDRuntimeCalls.cpp +++ b/gen/passes/SimplifyDRuntimeCalls.cpp @@ -62,7 +62,7 @@ namespace { class LLVM_LIBRARY_VISIBILITY LibCallOptimization { protected: Function *Caller; - bool* Changed; + bool *Changed; const DataLayout *DL; AliasAnalysis *AA; LLVMContext *Context; @@ -85,11 +85,11 @@ namespace { /// delete CI. virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B)=0; - Value *OptimizeCall(CallInst *CI, bool& Changed, const DataLayout &DL, + Value *OptimizeCall(CallInst *CI, bool& Changed, const DataLayout *DL, AliasAnalysis& AA, IRBuilder<> &B) { Caller = CI->getParent()->getParent(); this->Changed = &Changed; - this->DL = &DL; + this->DL = DL; this->AA = &AA; if (CI->getCalledFunction()) Context = &CI->getCalledFunction()->getContext(); @@ -300,10 +300,14 @@ namespace { void InitOptimizations(); bool runOnFunction(Function &F); - bool runOnce(Function &F, const DataLayout& DL, AliasAnalysis& AA); + bool runOnce(Function &F, const DataLayout *DL, AliasAnalysis& AA); virtual void getAnalysisUsage(AnalysisUsage &AU) const { +#if LDC_LLVM_VER >= 305 + AU.addRequired(); +#else AU.addRequired(); +#endif AU.addRequired(); } }; @@ -353,7 +357,12 @@ bool SimplifyDRuntimeCalls::runOnFunction(Function &F) { if (Optimizations.empty()) InitOptimizations(); - const DataLayout &DL = getAnalysis(); +#if LDC_LLVM_VER >= 305 + DataLayoutPass *DLP = getAnalysisIfAvailable(); + const DataLayout *DL = DLP ? &DLP->getDataLayout() : 0; +#else + const DataLayout *DL = &getAnalysis(); +#endif AliasAnalysis &AA = getAnalysis(); // Iterate to catch opportunities opened up by other optimizations, @@ -371,7 +380,7 @@ bool SimplifyDRuntimeCalls::runOnFunction(Function &F) { return EverChanged; } -bool SimplifyDRuntimeCalls::runOnce(Function &F, const DataLayout& DL, AliasAnalysis& AA) { +bool SimplifyDRuntimeCalls::runOnce(Function &F, const DataLayout *DL, AliasAnalysis& AA) { IRBuilder<> Builder(F.getContext()); bool Changed = false; diff --git a/gen/statements.cpp b/gen/statements.cpp index a50bdf04ed..86e58ace90 100644 --- a/gen/statements.cpp +++ b/gen/statements.cpp @@ -24,7 +24,11 @@ #include "ir/irfunction.h" #include "ir/irlandingpad.h" #include "ir/irmodule.h" +#if LDC_LLVM_VER >= 305 +#include "llvm/IR/CFG.h" +#else #include "llvm/Support/CFG.h" +#endif #if LDC_LLVM_VER >= 303 #include "llvm/IR/InlineAsm.h" #else diff --git a/gen/toir.cpp b/gen/toir.cpp index fb9fb095b9..805d377f0e 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -1029,7 +1029,11 @@ DValue* CallExp::toElem(IRState* p) LLValue* ptr = exp1->toElem(p)->getRVal(); LLValue* cmp = exp2->toElem(p)->getRVal(); LLValue* val = exp3->toElem(p)->getRVal(); +#if LDC_LLVM_VER >= 305 + LLValue* ret = gIR->ir->CreateAtomicCmpXchg(ptr, cmp, val, llvm::AtomicOrdering(atomicOrdering), llvm::AtomicOrdering(atomicOrdering)); +#else LLValue* ret = gIR->ir->CreateAtomicCmpXchg(ptr, cmp, val, llvm::AtomicOrdering(atomicOrdering)); +#endif return new DImValue(exp3->type, ret); // atomicrmw instruction } else if (fndecl->llvmInternal == LLVMatomic_rmw) { diff --git a/ir/irtypeaggr.h b/ir/irtypeaggr.h index 1342cfe75b..4ee7bea889 100644 --- a/ir/irtypeaggr.h +++ b/ir/irtypeaggr.h @@ -12,7 +12,9 @@ #include "ir/irtype.h" #include "llvm/ADT/ArrayRef.h" -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 305 +#include "llvm/IR/DebugInfo.h" +#elif LDC_LLVM_VER >= 302 #include "llvm/DebugInfo.h" #else #include "llvm/Analysis/DebugInfo.h" diff --git a/runtime/druntime b/runtime/druntime index bcbc6a00fe..7b3ebf9bd6 160000 --- a/runtime/druntime +++ b/runtime/druntime @@ -1 +1 @@ -Subproject commit bcbc6a00fe639499a511597f1bc8d8bb40a9d39e +Subproject commit 7b3ebf9bd67a41bc757fce5484cf38a40568340e