rustllvm: Remove conditional code for LLVM < 3.9

We bumped the minimum LLVM to 3.9 in #45326.  This just cleans up the
conditional code in the rustllvm C++ wrappers to assume at least 3.9.
This commit is contained in:
Josh Stone 2017-11-30 17:28:28 -08:00
parent bb42071f63
commit 51342f1fd7
4 changed files with 1 additions and 148 deletions

View File

@ -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() {}
@ -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 {
@ -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;
}
@ -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;
}
@ -141,12 +121,10 @@ 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;
}
@ -154,16 +132,7 @@ LLVMRustArchiveIteratorNext(LLVMRustArchiveIteratorRef RAI) {
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;
@ -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) {
@ -261,15 +225,7 @@ 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) {
@ -277,14 +233,9 @@ LLVMRustWriteArchive(char *Dst, size_t NumMembers,
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());

View File

@ -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);
@ -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:
@ -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) {
@ -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]) {
@ -733,7 +715,6 @@ extern "C" void LLVMRustRunRestrictionPass(LLVMModuleRef M, char **Symbols,
};
passes.add(llvm::createInternalizePass(PreserveFunctions));
#endif
passes.run(*unwrap(M));
}
@ -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

View File

@ -609,9 +609,6 @@ LLVMRustDIBuilderCreateSubroutineType(LLVMRustDIBuilderRef Builder,
LLVMMetadataRef File,
LLVMMetadataRef ParameterTypes) {
return wrap(Builder->createSubroutineType(
#if LLVM_VERSION_EQ(3, 7)
unwrapDI<DIFile>(File),
#endif
DITypeRefArray(unwrap<MDTuple>(ParameterTypes))));
}
@ -621,7 +618,6 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateFunction(
LLVMMetadataRef Ty, bool IsLocalToUnit, bool IsDefinition,
unsigned ScopeLine, LLVMRustDIFlags Flags, bool IsOptimized,
LLVMValueRef Fn, LLVMMetadataRef TParam, LLVMMetadataRef Decl) {
#if LLVM_VERSION_GE(3, 8)
DITemplateParameterArray TParams =
DITemplateParameterArray(unwrap<MDTuple>(TParam));
DISubprogram *Sub = Builder->createFunction(
@ -631,13 +627,6 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateFunction(
unwrapDIPtr<DISubprogram>(Decl));
unwrap<Function>(Fn)->setSubprogram(Sub);
return wrap(Sub);
#else
return wrap(Builder->createFunction(
unwrapDI<DIScope>(Scope), Name, LinkageName, unwrapDI<DIFile>(File),
LineNo, unwrapDI<DISubroutineType>(Ty), IsLocalToUnit, IsDefinition,
ScopeLine, fromRust(Flags), IsOptimized, unwrap<Function>(Fn),
unwrapDIPtr<MDNode>(TParam), unwrapDIPtr<MDNode>(Decl)));
#endif
}
extern "C" LLVMMetadataRef
@ -741,7 +730,6 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateVariable(
const char *Name, LLVMMetadataRef File, unsigned LineNo,
LLVMMetadataRef Ty, bool AlwaysPreserve, LLVMRustDIFlags Flags,
unsigned ArgNo, uint32_t AlignInBits) {
#if LLVM_VERSION_GE(3, 8)
if (Tag == 0x100) { // DW_TAG_auto_variable
return wrap(Builder->createAutoVariable(
unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), LineNo,
@ -756,11 +744,6 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateVariable(
unwrapDI<DIDescriptor>(Scope), Name, ArgNo, unwrapDI<DIFile>(File),
LineNo, unwrapDI<DIType>(Ty), AlwaysPreserve, fromRust(Flags)));
}
#else
return wrap(Builder->createLocalVariable(
Tag, unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), LineNo,
unwrapDI<DIType>(Ty), AlwaysPreserve, fromRust(Flags), ArgNo));
#endif
}
extern "C" LLVMMetadataRef
@ -935,11 +918,8 @@ extern "C" bool LLVMRustLinkInExternalBitcode(LLVMModuleRef DstRef, char *BC,
DiagnosticPrinterRawOStream DP(Stream);
#if LLVM_VERSION_GE(4, 0)
if (Linker::linkModules(*Dst, std::move(Src))) {
#elif LLVM_VERSION_GE(3, 8)
if (Linker::linkModules(*Dst, std::move(Src.get()))) {
#else
if (Linker::LinkModules(Dst, Src->get(),
[&](const DiagnosticInfo &DI) { DI.print(DP); })) {
if (Linker::linkModules(*Dst, std::move(Src.get()))) {
#endif
LLVMRustSetLastError(Err.c_str());
return false;
@ -1086,20 +1066,14 @@ static LLVMRustDiagnosticKind toRust(DiagnosticKind Kind) {
return LLVMRustDiagnosticKind::OptimizationRemarkMissed;
case DK_OptimizationRemarkAnalysis:
return LLVMRustDiagnosticKind::OptimizationRemarkAnalysis;
#if LLVM_VERSION_GE(3, 8)
case DK_OptimizationRemarkAnalysisFPCommute:
return LLVMRustDiagnosticKind::OptimizationRemarkAnalysisFPCommute;
case DK_OptimizationRemarkAnalysisAliasing:
return LLVMRustDiagnosticKind::OptimizationRemarkAnalysisAliasing;
#endif
default:
#if LLVM_VERSION_GE(3, 9)
return (Kind >= DK_FirstRemark && Kind <= DK_LastRemark)
? LLVMRustDiagnosticKind::OptimizationRemarkOther
: LLVMRustDiagnosticKind::Other;
#else
return LLVMRustDiagnosticKind::Other;
#endif
}
}
@ -1144,10 +1118,8 @@ extern "C" LLVMTypeKind LLVMRustGetTypeKind(LLVMTypeRef Ty) {
return LLVMVectorTypeKind;
case Type::X86_MMXTyID:
return LLVMX86_MMXTypeKind;
#if LLVM_VERSION_GE(3, 8)
case Type::TokenTyID:
return LLVMTokenTypeKind;
#endif
}
report_fatal_error("Unhandled TypeID.");
}
@ -1184,7 +1156,6 @@ extern "C" LLVMValueRef LLVMRustBuildCleanupPad(LLVMBuilderRef B,
unsigned ArgCount,
LLVMValueRef *LLArgs,
const char *Name) {
#if LLVM_VERSION_GE(3, 8)
Value **Args = unwrap(LLArgs);
if (ParentPad == nullptr) {
Type *Ty = Type::getTokenTy(unwrap(B)->getContext());
@ -1192,43 +1163,28 @@ extern "C" LLVMValueRef LLVMRustBuildCleanupPad(LLVMBuilderRef B,
}
return wrap(unwrap(B)->CreateCleanupPad(
unwrap(ParentPad), ArrayRef<Value *>(Args, ArgCount), Name));
#else
return nullptr;
#endif
}
extern "C" LLVMValueRef LLVMRustBuildCleanupRet(LLVMBuilderRef B,
LLVMValueRef CleanupPad,
LLVMBasicBlockRef UnwindBB) {
#if LLVM_VERSION_GE(3, 8)
CleanupPadInst *Inst = cast<CleanupPadInst>(unwrap(CleanupPad));
return wrap(unwrap(B)->CreateCleanupRet(Inst, unwrap(UnwindBB)));
#else
return nullptr;
#endif
}
extern "C" LLVMValueRef
LLVMRustBuildCatchPad(LLVMBuilderRef B, LLVMValueRef ParentPad,
unsigned ArgCount, LLVMValueRef *LLArgs, const char *Name) {
#if LLVM_VERSION_GE(3, 8)
Value **Args = unwrap(LLArgs);
return wrap(unwrap(B)->CreateCatchPad(
unwrap(ParentPad), ArrayRef<Value *>(Args, ArgCount), Name));
#else
return nullptr;
#endif
}
extern "C" LLVMValueRef LLVMRustBuildCatchRet(LLVMBuilderRef B,
LLVMValueRef Pad,
LLVMBasicBlockRef BB) {
#if LLVM_VERSION_GE(3, 8)
return wrap(unwrap(B)->CreateCatchRet(cast<CatchPadInst>(unwrap(Pad)),
unwrap(BB)));
#else
return nullptr;
#endif
}
extern "C" LLVMValueRef LLVMRustBuildCatchSwitch(LLVMBuilderRef B,
@ -1236,27 +1192,20 @@ extern "C" LLVMValueRef LLVMRustBuildCatchSwitch(LLVMBuilderRef B,
LLVMBasicBlockRef BB,
unsigned NumHandlers,
const char *Name) {
#if LLVM_VERSION_GE(3, 8)
if (ParentPad == nullptr) {
Type *Ty = Type::getTokenTy(unwrap(B)->getContext());
ParentPad = wrap(Constant::getNullValue(Ty));
}
return wrap(unwrap(B)->CreateCatchSwitch(unwrap(ParentPad), unwrap(BB),
NumHandlers, Name));
#else
return nullptr;
#endif
}
extern "C" void LLVMRustAddHandler(LLVMValueRef CatchSwitchRef,
LLVMBasicBlockRef Handler) {
#if LLVM_VERSION_GE(3, 8)
Value *CatchSwitch = unwrap(CatchSwitchRef);
cast<CatchSwitchInst>(CatchSwitch)->addHandler(unwrap(Handler));
#endif
}
#if LLVM_VERSION_GE(3, 8)
extern "C" OperandBundleDef *LLVMRustBuildOperandBundleDef(const char *Name,
LLVMValueRef *Inputs,
unsigned NumInputs) {
@ -1288,28 +1237,6 @@ LLVMRustBuildInvoke(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args,
makeArrayRef(unwrap(Args), NumArgs),
Bundles, Name));
}
#else
extern "C" void *LLVMRustBuildOperandBundleDef(const char *Name,
LLVMValueRef *Inputs,
unsigned NumInputs) {
return nullptr;
}
extern "C" void LLVMRustFreeOperandBundleDef(void *Bundle) {}
extern "C" LLVMValueRef LLVMRustBuildCall(LLVMBuilderRef B, LLVMValueRef Fn,
LLVMValueRef *Args, unsigned NumArgs,
void *Bundle, const char *Name) {
return LLVMBuildCall(B, Fn, Args, NumArgs, Name);
}
extern "C" LLVMValueRef
LLVMRustBuildInvoke(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args,
unsigned NumArgs, LLVMBasicBlockRef Then,
LLVMBasicBlockRef Catch, void *Bundle, const char *Name) {
return LLVMBuildInvoke(B, Fn, Args, NumArgs, Then, Catch, Name);
}
#endif
extern "C" void LLVMRustPositionBuilderAtStart(LLVMBuilderRef B,
LLVMBasicBlockRef BB) {

View File

@ -57,11 +57,7 @@
#define LLVM_VERSION_LT(major, minor) (!LLVM_VERSION_GE((major), (minor)))
#if LLVM_VERSION_GE(3, 7)
#include "llvm/IR/LegacyPassManager.h"
#else
#include "llvm/PassManager.h"
#endif
#if LLVM_VERSION_GE(4, 0)
#include "llvm/Bitcode/BitcodeReader.h"