Skip to content

Commit

Permalink
rustllvm: Remove conditional code for LLVM < 3.9
Browse files Browse the repository at this point in the history
We bumped the minimum LLVM to 3.9 in rust-lang#45326.  This just cleans up the
conditional code in the rustllvm C++ wrappers to assume at least 3.9.
  • Loading branch information
cuviper committed Dec 1, 2017
1 parent bb42071 commit 51342f1
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 148 deletions.
49 changes: 0 additions & 49 deletions src/rustllvm/ArchiveWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ struct RustArchiveMember {

RustArchiveMember()
: Filename(nullptr), Name(nullptr),
#if LLVM_VERSION_GE(3, 8)
Child(nullptr, nullptr, nullptr)
#else
Child(nullptr, nullptr)
#endif
{
}
~RustArchiveMember() {}
Expand All @@ -38,13 +34,9 @@ struct RustArchiveIterator {
bool First;
Archive::child_iterator Cur;
Archive::child_iterator End;
#if LLVM_VERSION_GE(3, 9)
Error Err;

RustArchiveIterator() : First(true), Err(Error::success()) {}
#else
RustArchiveIterator() : First(true) {}
#endif
};

enum class LLVMRustArchiveKind {
Expand Down Expand Up @@ -84,19 +76,11 @@ extern "C" LLVMRustArchiveRef LLVMRustOpenArchive(char *Path) {
return nullptr;
}

#if LLVM_VERSION_LE(3, 8)
ErrorOr<std::unique_ptr<Archive>> ArchiveOr =
#else
Expected<std::unique_ptr<Archive>> ArchiveOr =
#endif
Archive::create(BufOr.get()->getMemBufferRef());

if (!ArchiveOr) {
#if LLVM_VERSION_LE(3, 8)
LLVMRustSetLastError(ArchiveOr.getError().message().c_str());
#else
LLVMRustSetLastError(toString(ArchiveOr.takeError()).c_str());
#endif
return nullptr;
}

Expand All @@ -114,16 +98,12 @@ extern "C" LLVMRustArchiveIteratorRef
LLVMRustArchiveIteratorNew(LLVMRustArchiveRef RustArchive) {
Archive *Archive = RustArchive->getBinary();
RustArchiveIterator *RAI = new RustArchiveIterator();
#if LLVM_VERSION_LE(3, 8)
RAI->Cur = Archive->child_begin();
#else
RAI->Cur = Archive->child_begin(RAI->Err);
if (RAI->Err) {
LLVMRustSetLastError(toString(std::move(RAI->Err)).c_str());
delete RAI;
return nullptr;
}
#endif
RAI->End = Archive->child_end();
return RAI;
}
Expand All @@ -141,29 +121,18 @@ LLVMRustArchiveIteratorNext(LLVMRustArchiveIteratorRef RAI) {
// but instead advance it *before* fetching the child in all later calls.
if (!RAI->First) {
++RAI->Cur;
#if LLVM_VERSION_GE(3, 9)
if (RAI->Err) {
LLVMRustSetLastError(toString(std::move(RAI->Err)).c_str());
return nullptr;
}
#endif
} else {
RAI->First = false;
}

if (RAI->Cur == RAI->End)
return nullptr;

#if LLVM_VERSION_EQ(3, 8)
const ErrorOr<Archive::Child> *Cur = RAI->Cur.operator->();
if (!*Cur) {
LLVMRustSetLastError(Cur->getError().message().c_str());
return nullptr;
}
const Archive::Child &Child = Cur->get();
#else
const Archive::Child &Child = *RAI->Cur.operator->();
#endif
Archive::Child *Ret = new Archive::Child(Child);

return Ret;
Expand Down Expand Up @@ -239,18 +208,13 @@ LLVMRustWriteArchive(char *Dst, size_t NumMembers,
const LLVMRustArchiveMemberRef *NewMembers,
bool WriteSymbtab, LLVMRustArchiveKind RustKind) {

#if LLVM_VERSION_LE(3, 8)
std::vector<NewArchiveIterator> Members;
#else
std::vector<NewArchiveMember> Members;
#endif
auto Kind = fromRust(RustKind);

for (size_t I = 0; I < NumMembers; I++) {
auto Member = NewMembers[I];
assert(Member->Name);
if (Member->Filename) {
#if LLVM_VERSION_GE(3, 9)
Expected<NewArchiveMember> MOrErr =
NewArchiveMember::getFile(Member->Filename, true);
if (!MOrErr) {
Expand All @@ -261,30 +225,17 @@ LLVMRustWriteArchive(char *Dst, size_t NumMembers,
MOrErr->MemberName = sys::path::filename(MOrErr->MemberName);
#endif
Members.push_back(std::move(*MOrErr));
#elif LLVM_VERSION_EQ(3, 8)
Members.push_back(NewArchiveIterator(Member->Filename));
#else
Members.push_back(NewArchiveIterator(Member->Filename, Member->Name));
#endif
} else {
#if LLVM_VERSION_LE(3, 8)
Members.push_back(NewArchiveIterator(Member->Child, Member->Name));
#else
Expected<NewArchiveMember> MOrErr =
NewArchiveMember::getOldMember(Member->Child, true);
if (!MOrErr) {
LLVMRustSetLastError(toString(MOrErr.takeError()).c_str());
return LLVMRustResult::Failure;
}
Members.push_back(std::move(*MOrErr));
#endif
}
}
#if LLVM_VERSION_GE(3, 8)
auto Pair = writeArchive(Dst, Members, WriteSymbtab, Kind, true, false);
#else
auto Pair = writeArchive(Dst, Members, WriteSymbtab, Kind, true);
#endif
if (!Pair.second)
return LLVMRustResult::Success;
LLVMRustSetLastError(Pair.second.message().c_str());
Expand Down
21 changes: 0 additions & 21 deletions src/rustllvm/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ extern "C" void LLVMInitializePasses() {
initializeVectorization(Registry);
initializeIPO(Registry);
initializeAnalysis(Registry);
#if LLVM_VERSION_EQ(3, 7)
initializeIPA(Registry);
#endif
initializeTransformUtils(Registry);
initializeInstCombine(Registry);
initializeInstrumentation(Registry);
Expand Down Expand Up @@ -272,18 +269,10 @@ enum class LLVMRustRelocMode {
ROPIRWPI,
};

#if LLVM_VERSION_LE(3, 8)
static Reloc::Model fromRust(LLVMRustRelocMode RustReloc) {
#else
static Optional<Reloc::Model> fromRust(LLVMRustRelocMode RustReloc) {
#endif
switch (RustReloc) {
case LLVMRustRelocMode::Default:
#if LLVM_VERSION_LE(3, 8)
return Reloc::Default;
#else
return None;
#endif
case LLVMRustRelocMode::Static:
return Reloc::Static;
case LLVMRustRelocMode::PIC:
Expand Down Expand Up @@ -389,9 +378,6 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
}

TargetOptions Options;
#if LLVM_VERSION_LE(3, 8)
Options.PositionIndependentExecutable = PositionIndependentExecutable;
#endif

Options.FloatABIType = FloatABI::Default;
if (UseSoftFloat) {
Expand Down Expand Up @@ -719,10 +705,6 @@ extern "C" void LLVMRustRunRestrictionPass(LLVMModuleRef M, char **Symbols,
size_t Len) {
llvm::legacy::PassManager passes;

#if LLVM_VERSION_LE(3, 8)
ArrayRef<const char *> Ref(Symbols, Len);
passes.add(llvm::createInternalizePass(Ref));
#else
auto PreserveFunctions = [=](const GlobalValue &GV) {
for (size_t I = 0; I < Len; I++) {
if (GV.getName() == Symbols[I]) {
Expand All @@ -733,7 +715,6 @@ extern "C" void LLVMRustRunRestrictionPass(LLVMModuleRef M, char **Symbols,
};

passes.add(llvm::createInternalizePass(PreserveFunctions));
#endif

passes.run(*unwrap(M));
}
Expand Down Expand Up @@ -769,9 +750,7 @@ extern "C" LLVMTargetDataRef LLVMRustGetModuleDataLayout(LLVMModuleRef M) {
}

extern "C" void LLVMRustSetModulePIELevel(LLVMModuleRef M) {
#if LLVM_VERSION_GE(3, 9)
unwrap(M)->setPIELevel(PIELevel::Level::Large);
#endif
}

extern "C" bool
Expand Down
Loading

0 comments on commit 51342f1

Please sign in to comment.