diff options
Diffstat (limited to 'src/rustllvm/PassWrapper.cpp')
| -rw-r--r-- | src/rustllvm/PassWrapper.cpp | 58 |
1 files changed, 51 insertions, 7 deletions
diff --git a/src/rustllvm/PassWrapper.cpp b/src/rustllvm/PassWrapper.cpp index a2ab8040198..2c0240eb8f9 100644 --- a/src/rustllvm/PassWrapper.cpp +++ b/src/rustllvm/PassWrapper.cpp @@ -15,12 +15,19 @@ #include "llvm/Support/CBindingWrapping.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Host.h" +#if LLVM_VERSION_MINOR >= 7 +#include "llvm/Analysis/TargetLibraryInfo.h" +#include "llvm/Analysis/TargetTransformInfo.h" +#else #include "llvm/Target/TargetLibraryInfo.h" +#endif #include "llvm/Transforms/IPO/PassManagerBuilder.h" + #include "llvm-c/Transforms/PassManagerBuilder.h" using namespace llvm; +using namespace llvm::legacy; extern cl::opt<bool> EnableARMEHABI; @@ -71,7 +78,6 @@ LLVMRustCreateTargetMachine(const char *triple, CodeGenOpt::Level OptLevel, bool EnableSegmentedStacks, bool UseSoftFloat, - bool NoFramePointerElim, bool PositionIndependentExecutable, bool FunctionSections, bool DataSections) { @@ -91,12 +97,12 @@ LLVMRustCreateTargetMachine(const char *triple, TargetOptions Options; Options.PositionIndependentExecutable = PositionIndependentExecutable; - Options.NoFramePointerElim = NoFramePointerElim; Options.FloatABIType = FloatABI::Default; - Options.UseSoftFloat = UseSoftFloat; if (UseSoftFloat) { Options.FloatABIType = FloatABI::Soft; } + Options.DataSections = DataSections; + Options.FunctionSections = FunctionSections; TargetMachine *TM = TheTarget->createTargetMachine(Trip.getTriple(), real_cpu, @@ -105,8 +111,6 @@ LLVMRustCreateTargetMachine(const char *triple, RM, CM, OptLevel); - TM->setDataSections(DataSections); - TM->setFunctionSections(FunctionSections); return wrap(TM); } @@ -123,12 +127,32 @@ LLVMRustAddAnalysisPasses(LLVMTargetMachineRef TM, LLVMPassManagerRef PMR, LLVMModuleRef M) { PassManagerBase *PM = unwrap(PMR); -#if LLVM_VERSION_MINOR >= 6 +#if LLVM_VERSION_MINOR >= 7 + PM->add(createTargetTransformInfoWrapperPass( + unwrap(TM)->getTargetIRAnalysis())); +#else +#if LLVM_VERSION_MINOR == 6 PM->add(new DataLayoutPass()); #else PM->add(new DataLayoutPass(unwrap(M))); #endif unwrap(TM)->addAnalysisPasses(*PM); +#endif +} + +extern "C" void +LLVMRustConfigurePassManagerBuilder(LLVMPassManagerBuilderRef PMB, + CodeGenOpt::Level OptLevel, + bool MergeFunctions, + bool SLPVectorize, + bool LoopVectorize) { +#if LLVM_VERSION_MINOR >= 6 + // Ignore mergefunc for now as enabling it causes crashes. + //unwrap(PMB)->MergeFunctions = MergeFunctions; +#endif + unwrap(PMB)->SLPVectorize = SLPVectorize; + unwrap(PMB)->OptLevel = OptLevel; + unwrap(PMB)->LoopVectorize = LoopVectorize; } // Unfortunately, the LLVM C API doesn't provide a way to set the `LibraryInfo` @@ -138,7 +162,11 @@ LLVMRustAddBuilderLibraryInfo(LLVMPassManagerBuilderRef PMB, LLVMModuleRef M, bool DisableSimplifyLibCalls) { Triple TargetTriple(unwrap(M)->getTargetTriple()); +#if LLVM_VERSION_MINOR >= 7 + TargetLibraryInfoImpl *TLI = new TargetLibraryInfoImpl(TargetTriple); +#else TargetLibraryInfo *TLI = new TargetLibraryInfo(TargetTriple); +#endif if (DisableSimplifyLibCalls) TLI->disableAllFunctions(); unwrap(PMB)->LibraryInfo = TLI; @@ -151,10 +179,17 @@ LLVMRustAddLibraryInfo(LLVMPassManagerRef PMB, LLVMModuleRef M, bool DisableSimplifyLibCalls) { Triple TargetTriple(unwrap(M)->getTargetTriple()); +#if LLVM_VERSION_MINOR >= 7 + TargetLibraryInfoImpl TLII(TargetTriple); + if (DisableSimplifyLibCalls) + TLII.disableAllFunctions(); + unwrap(PMB)->add(new TargetLibraryInfoWrapperPass(TLII)); +#else TargetLibraryInfo *TLI = new TargetLibraryInfo(TargetTriple); if (DisableSimplifyLibCalls) TLI->disableAllFunctions(); unwrap(PMB)->add(TLI); +#endif } // Unfortunately, the LLVM C API doesn't provide an easy way of iterating over @@ -204,10 +239,19 @@ LLVMRustWriteOutputFile(LLVMTargetMachineRef Target, LLVMRustSetLastError(ErrorInfo.c_str()); return false; } - formatted_raw_ostream FOS(OS); +#if LLVM_VERSION_MINOR >= 7 + unwrap(Target)->addPassesToEmitFile(*PM, OS, FileType, false); +#else + formatted_raw_ostream FOS(OS); unwrap(Target)->addPassesToEmitFile(*PM, FOS, FileType, false); +#endif PM->run(*unwrap(M)); + + // Apparently `addPassesToEmitFile` adds an pointer to our on-the-stack output + // stream (OS), so the only real safe place to delete this is here? Don't we + // wish this was written in Rust? + delete PM; return true; } |
