Skip to content

Commit

Permalink
try to fix the build on older LLVM versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
emilio committed Mar 25, 2018
1 parent 4053e25 commit e155ecd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/librustc_llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1739,6 +1739,7 @@ extern "C" {
pub fn LLVMRustModuleCost(M: ModuleRef) -> u64;

pub fn LLVMRustThinLTOAvailable() -> bool;
pub fn LLVMRustPGOAvailable() -> bool;
pub fn LLVMRustWriteThinBitcodeToFile(PMR: PassManagerRef,
M: ModuleRef,
BC: *const c_char) -> bool;
Expand Down
7 changes: 7 additions & 0 deletions src/librustc_trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,13 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}
}

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 crate_hash = tcx.crate_hash(LOCAL_CRATE);
let link_meta = link::build_link_meta(crate_hash);

Expand Down
18 changes: 18 additions & 0 deletions src/rustllvm/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@

#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 @@ -435,6 +439,8 @@ extern "C" void LLVMRustConfigurePassManagerBuilder(
unwrap(PMBR)->SLPVectorize = SLPVectorize;
unwrap(PMBR)->OptLevel = fromRust(OptLevel);
unwrap(PMBR)->LoopVectorize = LoopVectorize;

#ifdef PGO_AVAILABLE
if (PGOGenPath) {
assert(!PGOUsePath);
unwrap(PMBR)->EnablePGOInstrGen = true;
Expand All @@ -444,6 +450,9 @@ 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 @@ -776,6 +785,15 @@ LLVMRustThinLTOAvailable() {
#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
Expand Down

0 comments on commit e155ecd

Please sign in to comment.