Skip to content

Commit d794597

Browse files
committedNov 1, 2018
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.
1 parent f6e9a6e commit d794597

File tree

8 files changed

+6
-215
lines changed

8 files changed

+6
-215
lines changed
 

‎src/librustc_codegen_llvm/back/write.rs

+6-17
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use attributes;
1212
use back::bytecode::{self, RLIB_BYTECODE_EXTENSION};
13-
use back::lto::{self, ModuleBuffer, ThinBuffer, SerializedModule};
13+
use back::lto::{self, ThinBuffer, SerializedModule};
1414
use back::link::{self, get_linker, remove};
1515
use back::command::Command;
1616
use back::linker::LinkerInfo;
@@ -564,8 +564,8 @@ unsafe fn optimize(cgcx: &CodegenContext,
564564
// Some options cause LLVM bitcode to be emitted, which uses ThinLTOBuffers, so we need
565565
// to make sure we run LLVM's NameAnonGlobals pass when emitting bitcode; otherwise
566566
// we'll get errors in LLVM.
567-
let using_thin_buffers = llvm::LLVMRustThinLTOAvailable() && (config.emit_bc
568-
|| config.obj_is_bitcode || config.emit_bc_compressed || config.embed_bitcode);
567+
let using_thin_buffers = config.emit_bc || config.obj_is_bitcode
568+
|| config.emit_bc_compressed || config.embed_bitcode;
569569
let mut have_name_anon_globals_pass = false;
570570
if !config.no_prepopulate_passes {
571571
llvm::LLVMRustAddAnalysisPasses(tm, fpm, llmod);
@@ -729,15 +729,8 @@ unsafe fn codegen(cgcx: &CodegenContext,
729729

730730

731731
if write_bc || config.emit_bc_compressed || config.embed_bitcode {
732-
let thin;
733-
let old;
734-
let data = if llvm::LLVMRustThinLTOAvailable() {
735-
thin = ThinBuffer::new(llmod);
736-
thin.data()
737-
} else {
738-
old = ModuleBuffer::new(llmod);
739-
old.data()
740-
};
732+
let thin = ThinBuffer::new(llmod);
733+
let data = thin.data();
741734
timeline.record("make-bc");
742735

743736
if write_bc {
@@ -1385,12 +1378,8 @@ fn execute_optimize_work_item(cgcx: &CodegenContext,
13851378
// builds we don't actually want to LTO the allocator modules if
13861379
// it shows up. This is due to various linker shenanigans that
13871380
// we'll encounter later.
1388-
//
1389-
// Additionally here's where we also factor in the current LLVM
1390-
// version. If it doesn't support ThinLTO we skip this.
13911381
Lto::ThinLocal => {
1392-
module.kind != ModuleKind::Allocator &&
1393-
unsafe { llvm::LLVMRustThinLTOAvailable() }
1382+
module.kind != ModuleKind::Allocator
13941383
}
13951384
};
13961385

‎src/librustc_codegen_llvm/base.rs

-13
Original file line numberDiff line numberDiff line change
@@ -738,19 +738,6 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
738738
{
739739
check_for_rustc_errors_attr(tcx);
740740

741-
if let Some(true) = tcx.sess.opts.debugging_opts.thinlto {
742-
if unsafe { !llvm::LLVMRustThinLTOAvailable() } {
743-
tcx.sess.fatal("this compiler's LLVM does not support ThinLTO");
744-
}
745-
}
746-
747-
if (tcx.sess.opts.debugging_opts.pgo_gen.is_some() ||
748-
!tcx.sess.opts.debugging_opts.pgo_use.is_empty()) &&
749-
unsafe { !llvm::LLVMRustPGOAvailable() }
750-
{
751-
tcx.sess.fatal("this compiler's LLVM does not support PGO");
752-
}
753-
754741
let cgu_name_builder = &mut CodegenUnitNameBuilder::new(tcx);
755742

756743
// Codegen the metadata.

‎src/librustc_codegen_llvm/llvm/ffi.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1626,8 +1626,6 @@ extern "C" {
16261626
pub fn LLVMRustModuleBufferFree(p: &'static mut ModuleBuffer);
16271627
pub fn LLVMRustModuleCost(M: &Module) -> u64;
16281628

1629-
pub fn LLVMRustThinLTOAvailable() -> bool;
1630-
pub fn LLVMRustPGOAvailable() -> bool;
16311629
pub fn LLVMRustThinLTOBufferCreate(M: &Module) -> &'static mut ThinLTOBuffer;
16321630
pub fn LLVMRustThinLTOBufferFree(M: &'static mut ThinLTOBuffer);
16331631
pub fn LLVMRustThinLTOBufferPtr(M: &ThinLTOBuffer) -> *const c_char;

‎src/rustllvm/ArchiveWrapper.cpp

-14
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ extern "C" void LLVMRustArchiveIteratorFree(LLVMRustArchiveIteratorRef RAI) {
145145

146146
extern "C" const char *
147147
LLVMRustArchiveChildName(LLVMRustArchiveChildConstRef Child, size_t *Size) {
148-
#if LLVM_VERSION_GE(4, 0)
149148
Expected<StringRef> NameOrErr = Child->getName();
150149
if (!NameOrErr) {
151150
// rustc_codegen_llvm currently doesn't use this error string, but it might be
@@ -154,11 +153,6 @@ LLVMRustArchiveChildName(LLVMRustArchiveChildConstRef Child, size_t *Size) {
154153
LLVMRustSetLastError(toString(NameOrErr.takeError()).c_str());
155154
return nullptr;
156155
}
157-
#else
158-
ErrorOr<StringRef> NameOrErr = Child->getName();
159-
if (NameOrErr.getError())
160-
return nullptr;
161-
#endif
162156
StringRef Name = NameOrErr.get();
163157
*Size = Name.size();
164158
return Name.data();
@@ -167,19 +161,11 @@ LLVMRustArchiveChildName(LLVMRustArchiveChildConstRef Child, size_t *Size) {
167161
extern "C" const char *LLVMRustArchiveChildData(LLVMRustArchiveChildRef Child,
168162
size_t *Size) {
169163
StringRef Buf;
170-
#if LLVM_VERSION_GE(4, 0)
171164
Expected<StringRef> BufOrErr = Child->getBuffer();
172165
if (!BufOrErr) {
173166
LLVMRustSetLastError(toString(BufOrErr.takeError()).c_str());
174167
return nullptr;
175168
}
176-
#else
177-
ErrorOr<StringRef> BufOrErr = Child->getBuffer();
178-
if (BufOrErr.getError()) {
179-
LLVMRustSetLastError(BufOrErr.getError().message().c_str());
180-
return nullptr;
181-
}
182-
#endif
183169
Buf = BufOrErr.get();
184170
*Size = Buf.size();
185171
return Buf.data();

‎src/rustllvm/Linker.cpp

-13
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ LLVMRustLinkerAdd(RustLinker *L, char *BC, size_t Len) {
4242
std::unique_ptr<MemoryBuffer> Buf =
4343
MemoryBuffer::getMemBufferCopy(StringRef(BC, Len));
4444

45-
#if LLVM_VERSION_GE(4, 0)
4645
Expected<std::unique_ptr<Module>> SrcOrError =
4746
llvm::getLazyBitcodeModule(Buf->getMemBufferRef(), L->Ctx);
4847
if (!SrcOrError) {
@@ -51,20 +50,8 @@ LLVMRustLinkerAdd(RustLinker *L, char *BC, size_t Len) {
5150
}
5251

5352
auto Src = std::move(*SrcOrError);
54-
#else
55-
ErrorOr<std::unique_ptr<Module>> Src =
56-
llvm::getLazyBitcodeModule(std::move(Buf), L->Ctx);
57-
if (!Src) {
58-
LLVMRustSetLastError(Src.getError().message().c_str());
59-
return false;
60-
}
61-
#endif
6253

63-
#if LLVM_VERSION_GE(4, 0)
6454
if (L->L.linkInModule(std::move(Src))) {
65-
#else
66-
if (L->L.linkInModule(std::move(Src.get()))) {
67-
#endif
6855
LLVMRustSetLastError("");
6956
return false;
7057
}

‎src/rustllvm/PassWrapper.cpp

-142
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,16 @@
3232
#include "llvm/Target/TargetSubtargetInfo.h"
3333
#endif
3434

35-
#if LLVM_VERSION_GE(4, 0)
3635
#include "llvm/Transforms/IPO/AlwaysInliner.h"
3736
#include "llvm/Transforms/IPO/FunctionImport.h"
3837
#include "llvm/Transforms/Utils/FunctionImportUtils.h"
3938
#include "llvm/LTO/LTO.h"
4039
#if LLVM_VERSION_LE(4, 0)
4140
#include "llvm/Object/ModuleSummaryIndexObjectFile.h"
4241
#endif
43-
#endif
4442

4543
#include "llvm-c/Transforms/PassManagerBuilder.h"
4644

47-
#if LLVM_VERSION_GE(4, 0)
48-
#define PGO_AVAILABLE
49-
#endif
50-
5145
using namespace llvm;
5246
using namespace llvm::legacy;
5347

@@ -121,12 +115,8 @@ bool LLVMRustPassManagerBuilderPopulateThinLTOPassManager(
121115
LLVMPassManagerBuilderRef PMBR,
122116
LLVMPassManagerRef PMR
123117
) {
124-
#if LLVM_VERSION_GE(4, 0)
125118
unwrap(PMBR)->populateThinLTOPassManager(*unwrap(PMR));
126119
return true;
127-
#else
128-
return false;
129-
#endif
130120
}
131121

132122
#ifdef LLVM_COMPONENT_X86
@@ -288,17 +278,12 @@ static Optional<Reloc::Model> fromRust(LLVMRustRelocMode RustReloc) {
288278
return Reloc::PIC_;
289279
case LLVMRustRelocMode::DynamicNoPic:
290280
return Reloc::DynamicNoPIC;
291-
#if LLVM_VERSION_GE(4, 0)
292281
case LLVMRustRelocMode::ROPI:
293282
return Reloc::ROPI;
294283
case LLVMRustRelocMode::RWPI:
295284
return Reloc::RWPI;
296285
case LLVMRustRelocMode::ROPIRWPI:
297286
return Reloc::ROPI_RWPI;
298-
#else
299-
default:
300-
break;
301-
#endif
302287
}
303288
report_fatal_error("Bad RelocModel.");
304289
}
@@ -450,11 +435,8 @@ extern "C" void LLVMRustConfigurePassManagerBuilder(
450435
unwrap(PMBR)->SLPVectorize = SLPVectorize;
451436
unwrap(PMBR)->OptLevel = fromRust(OptLevel);
452437
unwrap(PMBR)->LoopVectorize = LoopVectorize;
453-
#if LLVM_VERSION_GE(4, 0)
454438
unwrap(PMBR)->PrepareForThinLTO = PrepareForThinLTO;
455-
#endif
456439

457-
#ifdef PGO_AVAILABLE
458440
if (PGOGenPath) {
459441
assert(!PGOUsePath);
460442
unwrap(PMBR)->EnablePGOInstrGen = true;
@@ -464,9 +446,6 @@ extern "C" void LLVMRustConfigurePassManagerBuilder(
464446
assert(!PGOGenPath);
465447
unwrap(PMBR)->PGOInstrUse = PGOUsePath;
466448
}
467-
#else
468-
assert(!PGOGenPath && !PGOUsePath && "Should've caught earlier");
469-
#endif
470449
}
471450

472451
// Unfortunately, the LLVM C API doesn't provide a way to set the `LibraryInfo`
@@ -716,7 +695,6 @@ extern "C" void LLVMRustPrintPasses() {
716695
LLVMInitializePasses();
717696
struct MyListener : PassRegistrationListener {
718697
void passEnumerate(const PassInfo *Info) {
719-
#if LLVM_VERSION_GE(4, 0)
720698
StringRef PassArg = Info->getPassArgument();
721699
StringRef PassName = Info->getPassName();
722700
if (!PassArg.empty()) {
@@ -726,11 +704,6 @@ extern "C" void LLVMRustPrintPasses() {
726704
printf("%15.*s - %.*s\n", (int)PassArg.size(), PassArg.data(),
727705
(int)PassName.size(), PassName.data());
728706
}
729-
#else
730-
if (Info->getPassArgument() && *Info->getPassArgument()) {
731-
printf("%15s - %s\n", Info->getPassArgument(), Info->getPassName());
732-
}
733-
#endif
734707
}
735708
} Listener;
736709

@@ -740,11 +713,7 @@ extern "C" void LLVMRustPrintPasses() {
740713

741714
extern "C" void LLVMRustAddAlwaysInlinePass(LLVMPassManagerBuilderRef PMBR,
742715
bool AddLifetimes) {
743-
#if LLVM_VERSION_GE(4, 0)
744716
unwrap(PMBR)->Inliner = llvm::createAlwaysInlinerLegacyPass(AddLifetimes);
745-
#else
746-
unwrap(PMBR)->Inliner = createAlwaysInlinerPass(AddLifetimes);
747-
#endif
748717
}
749718

750719
extern "C" void LLVMRustRunRestrictionPass(LLVMModuleRef M, char **Symbols,
@@ -795,26 +764,6 @@ extern "C" void LLVMRustSetModulePIELevel(LLVMModuleRef M) {
795764
unwrap(M)->setPIELevel(PIELevel::Level::Large);
796765
}
797766

798-
extern "C" bool
799-
LLVMRustThinLTOAvailable() {
800-
#if LLVM_VERSION_GE(4, 0)
801-
return true;
802-
#else
803-
return false;
804-
#endif
805-
}
806-
807-
extern "C" bool
808-
LLVMRustPGOAvailable() {
809-
#ifdef PGO_AVAILABLE
810-
return true;
811-
#else
812-
return false;
813-
#endif
814-
}
815-
816-
#if LLVM_VERSION_GE(4, 0)
817-
818767
// Here you'll find an implementation of ThinLTO as used by the Rust compiler
819768
// right now. This ThinLTO support is only enabled on "recent ish" versions of
820769
// LLVM, and otherwise it's just blanket rejected from other compilers.
@@ -1276,94 +1225,3 @@ LLVMRustThinLTOPatchDICompileUnit(LLVMModuleRef Mod, DICompileUnit *Unit) {
12761225
MD->clearOperands();
12771226
MD->addOperand(Unit);
12781227
}
1279-
1280-
#else
1281-
1282-
struct LLVMRustThinLTOData {
1283-
};
1284-
1285-
struct LLVMRustThinLTOModule {
1286-
};
1287-
1288-
extern "C" LLVMRustThinLTOData*
1289-
LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
1290-
int num_modules,
1291-
const char **preserved_symbols,
1292-
int num_symbols) {
1293-
report_fatal_error("ThinLTO not available");
1294-
}
1295-
1296-
extern "C" bool
1297-
LLVMRustPrepareThinLTORename(const LLVMRustThinLTOData *Data, LLVMModuleRef M) {
1298-
report_fatal_error("ThinLTO not available");
1299-
}
1300-
1301-
extern "C" bool
1302-
LLVMRustPrepareThinLTOResolveWeak(const LLVMRustThinLTOData *Data, LLVMModuleRef M) {
1303-
report_fatal_error("ThinLTO not available");
1304-
}
1305-
1306-
extern "C" bool
1307-
LLVMRustPrepareThinLTOInternalize(const LLVMRustThinLTOData *Data, LLVMModuleRef M) {
1308-
report_fatal_error("ThinLTO not available");
1309-
}
1310-
1311-
extern "C" bool
1312-
LLVMRustPrepareThinLTOImport(const LLVMRustThinLTOData *Data, LLVMModuleRef M) {
1313-
report_fatal_error("ThinLTO not available");
1314-
}
1315-
1316-
extern "C" LLVMRustThinLTOModuleImports
1317-
LLVMRustGetLLVMRustThinLTOModuleImports(const LLVMRustThinLTOData *Data) {
1318-
report_fatal_error("ThinLTO not available");
1319-
}
1320-
1321-
extern "C" void
1322-
LLVMRustFreeThinLTOData(LLVMRustThinLTOData *Data) {
1323-
report_fatal_error("ThinLTO not available");
1324-
}
1325-
1326-
struct LLVMRustThinLTOBuffer {
1327-
};
1328-
1329-
extern "C" LLVMRustThinLTOBuffer*
1330-
LLVMRustThinLTOBufferCreate(LLVMModuleRef M) {
1331-
report_fatal_error("ThinLTO not available");
1332-
}
1333-
1334-
extern "C" void
1335-
LLVMRustThinLTOBufferFree(LLVMRustThinLTOBuffer *Buffer) {
1336-
report_fatal_error("ThinLTO not available");
1337-
}
1338-
1339-
extern "C" const void*
1340-
LLVMRustThinLTOBufferPtr(const LLVMRustThinLTOBuffer *Buffer) {
1341-
report_fatal_error("ThinLTO not available");
1342-
}
1343-
1344-
extern "C" size_t
1345-
LLVMRustThinLTOBufferLen(const LLVMRustThinLTOBuffer *Buffer) {
1346-
report_fatal_error("ThinLTO not available");
1347-
}
1348-
1349-
extern "C" LLVMModuleRef
1350-
LLVMRustParseBitcodeForThinLTO(LLVMContextRef Context,
1351-
const char *data,
1352-
size_t len,
1353-
const char *identifier) {
1354-
report_fatal_error("ThinLTO not available");
1355-
}
1356-
1357-
extern "C" void
1358-
LLVMRustThinLTOGetDICompileUnit(LLVMModuleRef Mod,
1359-
DICompileUnit **A,
1360-
DICompileUnit **B) {
1361-
report_fatal_error("ThinLTO not available");
1362-
}
1363-
1364-
extern "C" void
1365-
LLVMRustThinLTOPatchDICompileUnit(LLVMModuleRef Mod) {
1366-
report_fatal_error("ThinLTO not available");
1367-
}
1368-
1369-
#endif // LLVM_VERSION_GE(4, 0)

0 commit comments

Comments
 (0)
Please sign in to comment.