Reflect supporting only LLVM 3.7+ in the LLVM wrappers
This commit is contained in:
parent
0740a93cc2
commit
4f01329e0e
4 changed files with 4 additions and 222 deletions
|
@ -15,12 +15,8 @@
|
|||
#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/Target/TargetMachine.h"
|
||||
#include "llvm/Target/TargetSubtargetInfo.h"
|
||||
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
|
||||
|
@ -49,7 +45,7 @@ LLVMInitializePasses() {
|
|||
initializeVectorization(Registry);
|
||||
initializeIPO(Registry);
|
||||
initializeAnalysis(Registry);
|
||||
#if LLVM_VERSION_MINOR <= 7
|
||||
#if LLVM_VERSION_MINOR == 7
|
||||
initializeIPA(Registry);
|
||||
#endif
|
||||
initializeTransformUtils(Registry);
|
||||
|
@ -223,17 +219,8 @@ LLVMRustAddAnalysisPasses(LLVMTargetMachineRef TM,
|
|||
LLVMPassManagerRef PMR,
|
||||
LLVMModuleRef M) {
|
||||
PassManagerBase *PM = unwrap(PMR);
|
||||
#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
|
||||
|
@ -242,10 +229,8 @@ LLVMRustConfigurePassManagerBuilder(LLVMPassManagerBuilderRef PMB,
|
|||
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;
|
||||
|
@ -258,11 +243,7 @@ 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;
|
||||
|
@ -275,17 +256,10 @@ 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
|
||||
|
@ -323,25 +297,16 @@ LLVMRustWriteOutputFile(LLVMTargetMachineRef Target,
|
|||
PassManager *PM = unwrap<PassManager>(PMR);
|
||||
|
||||
std::string ErrorInfo;
|
||||
#if LLVM_VERSION_MINOR >= 6
|
||||
std::error_code EC;
|
||||
raw_fd_ostream OS(path, EC, sys::fs::F_None);
|
||||
if (EC)
|
||||
ErrorInfo = EC.message();
|
||||
#else
|
||||
raw_fd_ostream OS(path, ErrorInfo, sys::fs::F_None);
|
||||
#endif
|
||||
if (ErrorInfo != "") {
|
||||
LLVMRustSetLastError(ErrorInfo.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
#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 a pointer to our on-the-stack output
|
||||
|
@ -358,14 +323,10 @@ LLVMRustPrintModule(LLVMPassManagerRef PMR,
|
|||
PassManager *PM = unwrap<PassManager>(PMR);
|
||||
std::string ErrorInfo;
|
||||
|
||||
#if LLVM_VERSION_MINOR >= 6
|
||||
std::error_code EC;
|
||||
raw_fd_ostream OS(path, EC, sys::fs::F_None);
|
||||
if (EC)
|
||||
ErrorInfo = EC.message();
|
||||
#else
|
||||
raw_fd_ostream OS(path, ErrorInfo, sys::fs::F_None);
|
||||
#endif
|
||||
|
||||
formatted_raw_ostream FOS(OS);
|
||||
|
||||
|
@ -428,22 +389,10 @@ extern "C" void
|
|||
LLVMRustSetDataLayoutFromTargetMachine(LLVMModuleRef Module,
|
||||
LLVMTargetMachineRef TMR) {
|
||||
TargetMachine *Target = unwrap(TMR);
|
||||
#if LLVM_VERSION_MINOR >= 7
|
||||
unwrap(Module)->setDataLayout(Target->createDataLayout());
|
||||
#elif LLVM_VERSION_MINOR >= 6
|
||||
if (const DataLayout *DL = Target->getSubtargetImpl()->getDataLayout())
|
||||
unwrap(Module)->setDataLayout(DL);
|
||||
#else
|
||||
if (const DataLayout *DL = Target->getDataLayout())
|
||||
unwrap(Module)->setDataLayout(DL);
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" LLVMTargetDataRef
|
||||
LLVMRustGetModuleDataLayout(LLVMModuleRef M) {
|
||||
#if LLVM_VERSION_MINOR >= 7
|
||||
return wrap(&unwrap(M)->getDataLayout());
|
||||
#else
|
||||
return wrap(unwrap(M)->getDataLayout());
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue