Skip to content

Commit e155ecd

Browse files
committed
try to fix the build on older LLVM versions.
1 parent 4053e25 commit e155ecd

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

Diff for: src/librustc_llvm/ffi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1739,6 +1739,7 @@ extern "C" {
17391739
pub fn LLVMRustModuleCost(M: ModuleRef) -> u64;
17401740

17411741
pub fn LLVMRustThinLTOAvailable() -> bool;
1742+
pub fn LLVMRustPGOAvailable() -> bool;
17421743
pub fn LLVMRustWriteThinBitcodeToFile(PMR: PassManagerRef,
17431744
M: ModuleRef,
17441745
BC: *const c_char) -> bool;

Diff for: src/librustc_trans/base.rs

+7
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,13 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
708708
}
709709
}
710710

711+
if (tcx.sess.opts.debugging_opts.pgo_gen.is_some() ||
712+
!tcx.sess.opts.debugging_opts.pgo_use.is_empty()) &&
713+
unsafe { !llvm::LLVMRustPGOAvailable() }
714+
{
715+
tcx.sess.fatal("this compiler's LLVM does not support PGO");
716+
}
717+
711718
let crate_hash = tcx.crate_hash(LOCAL_CRATE);
712719
let link_meta = link::build_link_meta(crate_hash);
713720

Diff for: src/rustllvm/PassWrapper.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444

4545
#include "llvm-c/Transforms/PassManagerBuilder.h"
4646

47+
#if LLVM_VERSION_GE(4, 0)
48+
#define PGO_AVAILABLE
49+
#endif
50+
4751
using namespace llvm;
4852
using namespace llvm::legacy;
4953

@@ -435,6 +439,8 @@ extern "C" void LLVMRustConfigurePassManagerBuilder(
435439
unwrap(PMBR)->SLPVectorize = SLPVectorize;
436440
unwrap(PMBR)->OptLevel = fromRust(OptLevel);
437441
unwrap(PMBR)->LoopVectorize = LoopVectorize;
442+
443+
#ifdef PGO_AVAILABLE
438444
if (PGOGenPath) {
439445
assert(!PGOUsePath);
440446
unwrap(PMBR)->EnablePGOInstrGen = true;
@@ -444,6 +450,9 @@ extern "C" void LLVMRustConfigurePassManagerBuilder(
444450
assert(!PGOGenPath);
445451
unwrap(PMBR)->PGOInstrUse = PGOUsePath;
446452
}
453+
#else
454+
assert(!PGOGenPath && !PGOUsePath && "Should've caught earlier");
455+
#endif
447456
}
448457

449458
// Unfortunately, the LLVM C API doesn't provide a way to set the `LibraryInfo`
@@ -776,6 +785,15 @@ LLVMRustThinLTOAvailable() {
776785
#endif
777786
}
778787

788+
extern "C" bool
789+
LLVMRustPGOAvailable() {
790+
#ifdef PGO_AVAILABLE
791+
return true;
792+
#else
793+
return false;
794+
#endif
795+
}
796+
779797
#if LLVM_VERSION_GE(4, 0)
780798

781799
// Here you'll find an implementation of ThinLTO as used by the Rust compiler

0 commit comments

Comments
 (0)