Skip to content

Commit

Permalink
Auto merge of rust-lang#55593 - nikic:remove-llvm-4-checks, r=rkruppe
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Nov 5, 2018
2 parents 248745a + d794597 commit 0117b42
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 215 deletions.
23 changes: 6 additions & 17 deletions src/librustc_codegen_llvm/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
};

Expand Down
13 changes: 0 additions & 13 deletions src/librustc_codegen_llvm/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 0 additions & 2 deletions src/librustc_codegen_llvm/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 0 additions & 14 deletions src/rustllvm/ArchiveWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand All @@ -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();
Expand Down
13 changes: 0 additions & 13 deletions src/rustllvm/Linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down
142 changes: 0 additions & 142 deletions src/rustllvm/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,16 @@
#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"
#include "llvm/LTO/LTO.h"
#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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.");
}
Expand Down Expand Up @@ -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;
Expand All @@ -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`
Expand Down Expand Up @@ -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()) {
Expand All @@ -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;

Expand All @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Loading

0 comments on commit 0117b42

Please sign in to comment.