1
Fork 0

rustc_llvm: rustc_trans: Thread the PGO config down to the pass manager builder.

Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
This commit is contained in:
Emilio Cobos Álvarez 2018-02-19 01:57:12 +01:00
parent 50a38725e1
commit 324ca7acd5
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
3 changed files with 46 additions and 7 deletions

View file

@ -1641,7 +1641,9 @@ extern "C" {
OptLevel: CodeGenOptLevel,
MergeFunctions: bool,
SLPVectorize: bool,
LoopVectorize: bool);
LoopVectorize: bool,
PGOGenPath: *const c_char,
PGOUsePath: *const c_char);
pub fn LLVMRustAddLibraryInfo(PM: PassManagerRef,
M: ModuleRef,
DisableSimplifyLibCalls: bool);

View file

@ -240,6 +240,9 @@ pub struct ModuleConfig {
/// Some(level) to optimize binary size, or None to not affect program size.
opt_size: Option<llvm::CodeGenOptSize>,
pgo_gen: Option<String>,
pgo_use: String,
// Flags indicating which outputs to produce.
emit_no_opt_bc: bool,
emit_bc: bool,
@ -274,6 +277,9 @@ impl ModuleConfig {
opt_level: None,
opt_size: None,
pgo_gen: None,
pgo_use: String::new(),
emit_no_opt_bc: false,
emit_bc: false,
emit_bc_compressed: false,
@ -932,6 +938,9 @@ pub fn start_async_translation(tcx: TyCtxt,
modules_config.passes.push("insert-gcov-profiling".to_owned())
}
modules_config.pgo_gen = sess.opts.cg.pgo_gen.clone();
modules_config.pgo_use = sess.opts.cg.pgo_use.clone();
modules_config.opt_level = Some(get_llvm_opt_level(sess.opts.optimize));
modules_config.opt_size = Some(get_llvm_opt_size(sess.opts.optimize));
@ -2046,6 +2055,8 @@ pub unsafe fn with_llvm_pmb(llmod: ModuleRef,
config: &ModuleConfig,
opt_level: llvm::CodeGenOptLevel,
f: &mut FnMut(llvm::PassManagerBuilderRef)) {
use std::ptr;
// Create the PassManagerBuilder for LLVM. We configure it with
// reasonable defaults and prepare it to actually populate the pass
// manager.
@ -2053,11 +2064,27 @@ pub unsafe fn with_llvm_pmb(llmod: ModuleRef,
let opt_size = config.opt_size.unwrap_or(llvm::CodeGenOptSizeNone);
let inline_threshold = config.inline_threshold;
llvm::LLVMRustConfigurePassManagerBuilder(builder,
opt_level,
config.merge_functions,
config.vectorize_slp,
config.vectorize_loop);
let pgo_gen_path = config.pgo_gen.as_ref().map(|s| {
let s = if s.is_empty() { "default_%m.profraw" } else { s };
CString::new(s.as_bytes()).unwrap()
});
let pgo_use_path = if config.pgo_use.is_empty() {
None
} else {
Some(CString::new(config.pgo_use.as_bytes()).unwrap())
};
llvm::LLVMRustConfigurePassManagerBuilder(
builder,
opt_level,
config.merge_functions,
config.vectorize_slp,
config.vectorize_loop,
pgo_gen_path.as_ref().map_or(ptr::null(), |s| s.as_ptr()),
pgo_use_path.as_ref().map_or(ptr::null(), |s| s.as_ptr()),
);
llvm::LLVMPassManagerBuilderSetSizeLevel(builder, opt_size as u32);
if opt_size != llvm::CodeGenOptSizeNone {

View file

@ -428,12 +428,22 @@ extern "C" void LLVMRustAddAnalysisPasses(LLVMTargetMachineRef TM,
extern "C" void LLVMRustConfigurePassManagerBuilder(
LLVMPassManagerBuilderRef PMBR, LLVMRustCodeGenOptLevel OptLevel,
bool MergeFunctions, bool SLPVectorize, bool LoopVectorize) {
bool MergeFunctions, bool SLPVectorize, bool LoopVectorize,
const char* PGOGenPath, const char* PGOUsePath) {
// Ignore mergefunc for now as enabling it causes crashes.
// unwrap(PMBR)->MergeFunctions = MergeFunctions;
unwrap(PMBR)->SLPVectorize = SLPVectorize;
unwrap(PMBR)->OptLevel = fromRust(OptLevel);
unwrap(PMBR)->LoopVectorize = LoopVectorize;
if (PGOGenPath) {
assert(!PGOUsePath);
unwrap(PMBR)->EnablePGOInstrGen = true;
unwrap(PMBR)->PGOInstrGen = PGOGenPath;
}
if (PGOUsePath) {
assert(!PGOGenPath);
unwrap(PMBR)->PGOInstrUse = PGOUsePath;
}
}
// Unfortunately, the LLVM C API doesn't provide a way to set the `LibraryInfo`