Auto merge of #55593 - nikic:remove-llvm-4-checks, r=rkruppe
Remove checks for LLVM < 4.0 While we still have to support LLVM 4.0 for Emscripten, we can drop checks for LLVM >= 4.0 and < 4.0.
This commit is contained in:
commit
0117b42f66
@ -10,7 +10,7 @@
|
||||
|
||||
use attributes;
|
||||
use back::bytecode::{self, RLIB_BYTECODE_EXTENSION};
|
||||
use back::lto::{self, ModuleBuffer, ThinBuffer, SerializedModule};
|
||||
use back::lto::{self, ThinBuffer, SerializedModule};
|
||||
use back::link::{self, get_linker, remove};
|
||||
use base;
|
||||
use consts;
|
||||
@ -564,8 +564,8 @@ unsafe fn optimize(cgcx: &CodegenContext,
|
||||
// Some options cause LLVM bitcode to be emitted, which uses ThinLTOBuffers, so we need
|
||||
// to make sure we run LLVM's NameAnonGlobals pass when emitting bitcode; otherwise
|
||||
// we'll get errors in LLVM.
|
||||
let using_thin_buffers = llvm::LLVMRustThinLTOAvailable() && (config.emit_bc
|
||||
|| config.obj_is_bitcode || config.emit_bc_compressed || config.embed_bitcode);
|
||||
let using_thin_buffers = config.emit_bc || config.obj_is_bitcode
|
||||
|| config.emit_bc_compressed || config.embed_bitcode;
|
||||
let mut have_name_anon_globals_pass = false;
|
||||
if !config.no_prepopulate_passes {
|
||||
llvm::LLVMRustAddAnalysisPasses(tm, fpm, llmod);
|
||||
@ -729,15 +729,8 @@ unsafe fn codegen(cgcx: &CodegenContext,
|
||||
|
||||
|
||||
if write_bc || config.emit_bc_compressed || config.embed_bitcode {
|
||||
let thin;
|
||||
let old;
|
||||
let data = if llvm::LLVMRustThinLTOAvailable() {
|
||||
thin = ThinBuffer::new(llmod);
|
||||
thin.data()
|
||||
} else {
|
||||
old = ModuleBuffer::new(llmod);
|
||||
old.data()
|
||||
};
|
||||
let thin = ThinBuffer::new(llmod);
|
||||
let data = thin.data();
|
||||
timeline.record("make-bc");
|
||||
|
||||
if write_bc {
|
||||
@ -1385,12 +1378,8 @@ fn execute_optimize_work_item(cgcx: &CodegenContext,
|
||||
// builds we don't actually want to LTO the allocator modules if
|
||||
// it shows up. This is due to various linker shenanigans that
|
||||
// we'll encounter later.
|
||||
//
|
||||
// Additionally here's where we also factor in the current LLVM
|
||||
// version. If it doesn't support ThinLTO we skip this.
|
||||
Lto::ThinLocal => {
|
||||
module.kind != ModuleKind::Allocator &&
|
||||
unsafe { llvm::LLVMRustThinLTOAvailable() }
|
||||
module.kind != ModuleKind::Allocator
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -737,19 +737,6 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
{
|
||||
check_for_rustc_errors_attr(tcx);
|
||||
|
||||
if let Some(true) = tcx.sess.opts.debugging_opts.thinlto {
|
||||
if unsafe { !llvm::LLVMRustThinLTOAvailable() } {
|
||||
tcx.sess.fatal("this compiler's LLVM does not support ThinLTO");
|
||||
}
|
||||
}
|
||||
|
||||
if (tcx.sess.opts.debugging_opts.pgo_gen.is_some() ||
|
||||
!tcx.sess.opts.debugging_opts.pgo_use.is_empty()) &&
|
||||
unsafe { !llvm::LLVMRustPGOAvailable() }
|
||||
{
|
||||
tcx.sess.fatal("this compiler's LLVM does not support PGO");
|
||||
}
|
||||
|
||||
let cgu_name_builder = &mut CodegenUnitNameBuilder::new(tcx);
|
||||
|
||||
// Codegen the metadata.
|
||||
|
@ -1626,8 +1626,6 @@ extern "C" {
|
||||
pub fn LLVMRustModuleBufferFree(p: &'static mut ModuleBuffer);
|
||||
pub fn LLVMRustModuleCost(M: &Module) -> u64;
|
||||
|
||||
pub fn LLVMRustThinLTOAvailable() -> bool;
|
||||
pub fn LLVMRustPGOAvailable() -> bool;
|
||||
pub fn LLVMRustThinLTOBufferCreate(M: &Module) -> &'static mut ThinLTOBuffer;
|
||||
pub fn LLVMRustThinLTOBufferFree(M: &'static mut ThinLTOBuffer);
|
||||
pub fn LLVMRustThinLTOBufferPtr(M: &ThinLTOBuffer) -> *const c_char;
|
||||
|
@ -145,7 +145,6 @@ extern "C" void LLVMRustArchiveIteratorFree(LLVMRustArchiveIteratorRef RAI) {
|
||||
|
||||
extern "C" const char *
|
||||
LLVMRustArchiveChildName(LLVMRustArchiveChildConstRef Child, size_t *Size) {
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
Expected<StringRef> NameOrErr = Child->getName();
|
||||
if (!NameOrErr) {
|
||||
// rustc_codegen_llvm currently doesn't use this error string, but it might be
|
||||
@ -154,11 +153,6 @@ LLVMRustArchiveChildName(LLVMRustArchiveChildConstRef Child, size_t *Size) {
|
||||
LLVMRustSetLastError(toString(NameOrErr.takeError()).c_str());
|
||||
return nullptr;
|
||||
}
|
||||
#else
|
||||
ErrorOr<StringRef> NameOrErr = Child->getName();
|
||||
if (NameOrErr.getError())
|
||||
return nullptr;
|
||||
#endif
|
||||
StringRef Name = NameOrErr.get();
|
||||
*Size = Name.size();
|
||||
return Name.data();
|
||||
@ -167,19 +161,11 @@ LLVMRustArchiveChildName(LLVMRustArchiveChildConstRef Child, size_t *Size) {
|
||||
extern "C" const char *LLVMRustArchiveChildData(LLVMRustArchiveChildRef Child,
|
||||
size_t *Size) {
|
||||
StringRef Buf;
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
Expected<StringRef> BufOrErr = Child->getBuffer();
|
||||
if (!BufOrErr) {
|
||||
LLVMRustSetLastError(toString(BufOrErr.takeError()).c_str());
|
||||
return nullptr;
|
||||
}
|
||||
#else
|
||||
ErrorOr<StringRef> BufOrErr = Child->getBuffer();
|
||||
if (BufOrErr.getError()) {
|
||||
LLVMRustSetLastError(BufOrErr.getError().message().c_str());
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
Buf = BufOrErr.get();
|
||||
*Size = Buf.size();
|
||||
return Buf.data();
|
||||
|
@ -42,7 +42,6 @@ LLVMRustLinkerAdd(RustLinker *L, char *BC, size_t Len) {
|
||||
std::unique_ptr<MemoryBuffer> Buf =
|
||||
MemoryBuffer::getMemBufferCopy(StringRef(BC, Len));
|
||||
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
Expected<std::unique_ptr<Module>> SrcOrError =
|
||||
llvm::getLazyBitcodeModule(Buf->getMemBufferRef(), L->Ctx);
|
||||
if (!SrcOrError) {
|
||||
@ -51,20 +50,8 @@ LLVMRustLinkerAdd(RustLinker *L, char *BC, size_t Len) {
|
||||
}
|
||||
|
||||
auto Src = std::move(*SrcOrError);
|
||||
#else
|
||||
ErrorOr<std::unique_ptr<Module>> Src =
|
||||
llvm::getLazyBitcodeModule(std::move(Buf), L->Ctx);
|
||||
if (!Src) {
|
||||
LLVMRustSetLastError(Src.getError().message().c_str());
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
if (L->L.linkInModule(std::move(Src))) {
|
||||
#else
|
||||
if (L->L.linkInModule(std::move(Src.get()))) {
|
||||
#endif
|
||||
LLVMRustSetLastError("");
|
||||
return false;
|
||||
}
|
||||
|
@ -32,7 +32,6 @@
|
||||
#include "llvm/Target/TargetSubtargetInfo.h"
|
||||
#endif
|
||||
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
#include "llvm/Transforms/IPO/AlwaysInliner.h"
|
||||
#include "llvm/Transforms/IPO/FunctionImport.h"
|
||||
#include "llvm/Transforms/Utils/FunctionImportUtils.h"
|
||||
@ -40,14 +39,9 @@
|
||||
#if LLVM_VERSION_LE(4, 0)
|
||||
#include "llvm/Object/ModuleSummaryIndexObjectFile.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "llvm-c/Transforms/PassManagerBuilder.h"
|
||||
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
#define PGO_AVAILABLE
|
||||
#endif
|
||||
|
||||
using namespace llvm;
|
||||
using namespace llvm::legacy;
|
||||
|
||||
@ -121,12 +115,8 @@ bool LLVMRustPassManagerBuilderPopulateThinLTOPassManager(
|
||||
LLVMPassManagerBuilderRef PMBR,
|
||||
LLVMPassManagerRef PMR
|
||||
) {
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
unwrap(PMBR)->populateThinLTOPassManager(*unwrap(PMR));
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef LLVM_COMPONENT_X86
|
||||
@ -288,17 +278,12 @@ static Optional<Reloc::Model> fromRust(LLVMRustRelocMode RustReloc) {
|
||||
return Reloc::PIC_;
|
||||
case LLVMRustRelocMode::DynamicNoPic:
|
||||
return Reloc::DynamicNoPIC;
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
case LLVMRustRelocMode::ROPI:
|
||||
return Reloc::ROPI;
|
||||
case LLVMRustRelocMode::RWPI:
|
||||
return Reloc::RWPI;
|
||||
case LLVMRustRelocMode::ROPIRWPI:
|
||||
return Reloc::ROPI_RWPI;
|
||||
#else
|
||||
default:
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
report_fatal_error("Bad RelocModel.");
|
||||
}
|
||||
@ -450,11 +435,8 @@ extern "C" void LLVMRustConfigurePassManagerBuilder(
|
||||
unwrap(PMBR)->SLPVectorize = SLPVectorize;
|
||||
unwrap(PMBR)->OptLevel = fromRust(OptLevel);
|
||||
unwrap(PMBR)->LoopVectorize = LoopVectorize;
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
unwrap(PMBR)->PrepareForThinLTO = PrepareForThinLTO;
|
||||
#endif
|
||||
|
||||
#ifdef PGO_AVAILABLE
|
||||
if (PGOGenPath) {
|
||||
assert(!PGOUsePath);
|
||||
unwrap(PMBR)->EnablePGOInstrGen = true;
|
||||
@ -464,9 +446,6 @@ extern "C" void LLVMRustConfigurePassManagerBuilder(
|
||||
assert(!PGOGenPath);
|
||||
unwrap(PMBR)->PGOInstrUse = PGOUsePath;
|
||||
}
|
||||
#else
|
||||
assert(!PGOGenPath && !PGOUsePath && "Should've caught earlier");
|
||||
#endif
|
||||
}
|
||||
|
||||
// Unfortunately, the LLVM C API doesn't provide a way to set the `LibraryInfo`
|
||||
@ -716,7 +695,6 @@ extern "C" void LLVMRustPrintPasses() {
|
||||
LLVMInitializePasses();
|
||||
struct MyListener : PassRegistrationListener {
|
||||
void passEnumerate(const PassInfo *Info) {
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
StringRef PassArg = Info->getPassArgument();
|
||||
StringRef PassName = Info->getPassName();
|
||||
if (!PassArg.empty()) {
|
||||
@ -726,11 +704,6 @@ extern "C" void LLVMRustPrintPasses() {
|
||||
printf("%15.*s - %.*s\n", (int)PassArg.size(), PassArg.data(),
|
||||
(int)PassName.size(), PassName.data());
|
||||
}
|
||||
#else
|
||||
if (Info->getPassArgument() && *Info->getPassArgument()) {
|
||||
printf("%15s - %s\n", Info->getPassArgument(), Info->getPassName());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
} Listener;
|
||||
|
||||
@ -740,11 +713,7 @@ extern "C" void LLVMRustPrintPasses() {
|
||||
|
||||
extern "C" void LLVMRustAddAlwaysInlinePass(LLVMPassManagerBuilderRef PMBR,
|
||||
bool AddLifetimes) {
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
unwrap(PMBR)->Inliner = llvm::createAlwaysInlinerLegacyPass(AddLifetimes);
|
||||
#else
|
||||
unwrap(PMBR)->Inliner = createAlwaysInlinerPass(AddLifetimes);
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" void LLVMRustRunRestrictionPass(LLVMModuleRef M, char **Symbols,
|
||||
@ -795,26 +764,6 @@ extern "C" void LLVMRustSetModulePIELevel(LLVMModuleRef M) {
|
||||
unwrap(M)->setPIELevel(PIELevel::Level::Large);
|
||||
}
|
||||
|
||||
extern "C" bool
|
||||
LLVMRustThinLTOAvailable() {
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" bool
|
||||
LLVMRustPGOAvailable() {
|
||||
#ifdef PGO_AVAILABLE
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
|
||||
// Here you'll find an implementation of ThinLTO as used by the Rust compiler
|
||||
// right now. This ThinLTO support is only enabled on "recent ish" versions of
|
||||
// LLVM, and otherwise it's just blanket rejected from other compilers.
|
||||
@ -1276,94 +1225,3 @@ LLVMRustThinLTOPatchDICompileUnit(LLVMModuleRef Mod, DICompileUnit *Unit) {
|
||||
MD->clearOperands();
|
||||
MD->addOperand(Unit);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
struct LLVMRustThinLTOData {
|
||||
};
|
||||
|
||||
struct LLVMRustThinLTOModule {
|
||||
};
|
||||
|
||||
extern "C" LLVMRustThinLTOData*
|
||||
LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
|
||||
int num_modules,
|
||||
const char **preserved_symbols,
|
||||
int num_symbols) {
|
||||
report_fatal_error("ThinLTO not available");
|
||||
}
|
||||
|
||||
extern "C" bool
|
||||
LLVMRustPrepareThinLTORename(const LLVMRustThinLTOData *Data, LLVMModuleRef M) {
|
||||
report_fatal_error("ThinLTO not available");
|
||||
}
|
||||
|
||||
extern "C" bool
|
||||
LLVMRustPrepareThinLTOResolveWeak(const LLVMRustThinLTOData *Data, LLVMModuleRef M) {
|
||||
report_fatal_error("ThinLTO not available");
|
||||
}
|
||||
|
||||
extern "C" bool
|
||||
LLVMRustPrepareThinLTOInternalize(const LLVMRustThinLTOData *Data, LLVMModuleRef M) {
|
||||
report_fatal_error("ThinLTO not available");
|
||||
}
|
||||
|
||||
extern "C" bool
|
||||
LLVMRustPrepareThinLTOImport(const LLVMRustThinLTOData *Data, LLVMModuleRef M) {
|
||||
report_fatal_error("ThinLTO not available");
|
||||
}
|
||||
|
||||
extern "C" LLVMRustThinLTOModuleImports
|
||||
LLVMRustGetLLVMRustThinLTOModuleImports(const LLVMRustThinLTOData *Data) {
|
||||
report_fatal_error("ThinLTO not available");
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustFreeThinLTOData(LLVMRustThinLTOData *Data) {
|
||||
report_fatal_error("ThinLTO not available");
|
||||
}
|
||||
|
||||
struct LLVMRustThinLTOBuffer {
|
||||
};
|
||||
|
||||
extern "C" LLVMRustThinLTOBuffer*
|
||||
LLVMRustThinLTOBufferCreate(LLVMModuleRef M) {
|
||||
report_fatal_error("ThinLTO not available");
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustThinLTOBufferFree(LLVMRustThinLTOBuffer *Buffer) {
|
||||
report_fatal_error("ThinLTO not available");
|
||||
}
|
||||
|
||||
extern "C" const void*
|
||||
LLVMRustThinLTOBufferPtr(const LLVMRustThinLTOBuffer *Buffer) {
|
||||
report_fatal_error("ThinLTO not available");
|
||||
}
|
||||
|
||||
extern "C" size_t
|
||||
LLVMRustThinLTOBufferLen(const LLVMRustThinLTOBuffer *Buffer) {
|
||||
report_fatal_error("ThinLTO not available");
|
||||
}
|
||||
|
||||
extern "C" LLVMModuleRef
|
||||
LLVMRustParseBitcodeForThinLTO(LLVMContextRef Context,
|
||||
const char *data,
|
||||
size_t len,
|
||||
const char *identifier) {
|
||||
report_fatal_error("ThinLTO not available");
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustThinLTOGetDICompileUnit(LLVMModuleRef Mod,
|
||||
DICompileUnit **A,
|
||||
DICompileUnit **B) {
|
||||
report_fatal_error("ThinLTO not available");
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustThinLTOPatchDICompileUnit(LLVMModuleRef Mod) {
|
||||
report_fatal_error("ThinLTO not available");
|
||||
}
|
||||
|
||||
#endif // LLVM_VERSION_GE(4, 0)
|
||||
|
@ -907,10 +907,8 @@ LLVMRustDIBuilderCreateNameSpace(LLVMRustDIBuilderRef Builder,
|
||||
,
|
||||
unwrapDI<DIFile>(File), LineNo
|
||||
#endif
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
,
|
||||
false // ExportSymbols (only relevant for C++ anonymous namespaces)
|
||||
#endif
|
||||
));
|
||||
}
|
||||
|
||||
@ -1547,14 +1545,6 @@ LLVMRustBuildVectorReduceFMax(LLVMBuilderRef, LLVMValueRef, bool) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LLVM_VERSION_LT(4, 0)
|
||||
extern "C" LLVMValueRef
|
||||
LLVMBuildExactUDiv(LLVMBuilderRef B, LLVMValueRef LHS,
|
||||
LLVMValueRef RHS, const char *Name) {
|
||||
return wrap(unwrap(B)->CreateExactUDiv(unwrap(LHS), unwrap(RHS), Name));
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LLVM_VERSION_GE(6, 0)
|
||||
extern "C" LLVMValueRef
|
||||
LLVMRustBuildMinNum(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS) {
|
||||
|
@ -57,12 +57,8 @@
|
||||
|
||||
#include "llvm/IR/LegacyPassManager.h"
|
||||
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
#include "llvm/Bitcode/BitcodeReader.h"
|
||||
#include "llvm/Bitcode/BitcodeWriter.h"
|
||||
#else
|
||||
#include "llvm/Bitcode/ReaderWriter.h"
|
||||
#endif
|
||||
|
||||
#include "llvm/IR/DIBuilder.h"
|
||||
#include "llvm/IR/DebugInfo.h"
|
||||
|
Loading…
Reference in New Issue
Block a user