Skip to content

Reflect supporting only LLVM 3.7+ in the LLVM wrappers #34178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 1 addition & 27 deletions src/rustllvm/ArchiveWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
#include "rustllvm.h"

#include "llvm/Object/Archive.h"

#if LLVM_VERSION_MINOR >= 7
#include "llvm/Object/ArchiveWriter.h"
#endif

using namespace llvm;
using namespace llvm::object;
Expand All @@ -34,13 +31,7 @@ struct LLVMRustArchiveMember {
~LLVMRustArchiveMember() {}
};

#if LLVM_VERSION_MINOR >= 6
typedef OwningBinary<Archive> RustArchive;
#define GET_ARCHIVE(a) ((a)->getBinary())
#else
typedef Archive RustArchive;
#define GET_ARCHIVE(a) (a)
#endif

extern "C" void*
LLVMRustOpenArchive(char *path) {
Expand All @@ -52,7 +43,6 @@ LLVMRustOpenArchive(char *path) {
return nullptr;
}

#if LLVM_VERSION_MINOR >= 6
ErrorOr<std::unique_ptr<Archive>> archive_or =
Archive::create(buf_or.get()->getMemBufferRef());

Expand All @@ -63,14 +53,6 @@ LLVMRustOpenArchive(char *path) {

OwningBinary<Archive> *ret = new OwningBinary<Archive>(
std::move(archive_or.get()), std::move(buf_or.get()));
#else
std::error_code err;
Archive *ret = new Archive(std::move(buf_or.get()), err);
if (err) {
LLVMRustSetLastError(err.message().c_str());
return nullptr;
}
#endif

return ret;
}
Expand All @@ -87,7 +69,7 @@ struct RustArchiveIterator {

extern "C" RustArchiveIterator*
LLVMRustArchiveIteratorNew(RustArchive *ra) {
Archive *ar = GET_ARCHIVE(ra);
Archive *ar = ra->getBinary();
RustArchiveIterator *rai = new RustArchiveIterator();
rai->cur = ar->child_begin();
rai->end = ar->child_end();
Expand Down Expand Up @@ -137,16 +119,12 @@ LLVMRustArchiveChildName(const Archive::Child *child, size_t *size) {
extern "C" const char*
LLVMRustArchiveChildData(Archive::Child *child, size_t *size) {
StringRef buf;
#if LLVM_VERSION_MINOR >= 7
ErrorOr<StringRef> buf_or_err = child->getBuffer();
if (buf_or_err.getError()) {
LLVMRustSetLastError(buf_or_err.getError().message().c_str());
return NULL;
}
buf = buf_or_err.get();
#else
buf = child->getBuffer();
#endif
*size = buf.size();
return buf.data();
}
Expand All @@ -172,7 +150,6 @@ LLVMRustWriteArchive(char *Dst,
const LLVMRustArchiveMember **NewMembers,
bool WriteSymbtab,
Archive::Kind Kind) {
#if LLVM_VERSION_MINOR >= 7
std::vector<NewArchiveIterator> Members;

for (size_t i = 0; i < NumMembers; i++) {
Expand All @@ -196,8 +173,5 @@ LLVMRustWriteArchive(char *Dst,
if (!pair.second)
return 0;
LLVMRustSetLastError(pair.second.message().c_str());
#else
LLVMRustSetLastError("writing archives not supported with this LLVM version");
#endif
return -1;
}
5 changes: 0 additions & 5 deletions src/rustllvm/ExecutionEngineWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,8 @@ extern "C" LLVMExecutionEngineRef LLVMBuildExecutionEngine(LLVMModuleRef mod)
RustJITMemoryManager *mm = new RustJITMemoryManager;

ExecutionEngine *ee =
#if LLVM_VERSION_MINOR >= 6
EngineBuilder(std::unique_ptr<Module>(unwrap(mod)))
.setMCJITMemoryManager(std::unique_ptr<RustJITMemoryManager>(mm))
#else
EngineBuilder(unwrap(mod))
.setMCJITMemoryManager(mm)
#endif
.setEngineKind(EngineKind::JIT)
.setErrorStr(&error_str)
.setTargetOptions(options)
Expand Down
53 changes: 1 addition & 52 deletions src/rustllvm/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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);

Expand Down Expand Up @@ -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