Skip to content

Commit

Permalink
Some optimizations
Browse files Browse the repository at this point in the history
* Only format global _comments when debug_assertions are enabled
* Only call build_value_labels_ranges in base.rs when debug_assertions are enabled

Benchmark #1: CHANNEL='pre' ../cargo.sh build
  Time (mean ± σ):     17.657 s ±  1.050 s    [User: 31.871 s, System: 3.014 s]
  Range (min … max):   16.907 s … 20.394 s    10 runs

Benchmark #2: ../cargo.sh build
  Time (mean ± σ):     16.640 s ±  0.255 s    [User: 30.238 s, System: 2.965 s]
  Range (min … max):   16.413 s … 17.186 s    10 runs

  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet PC without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.

Summary
  '../cargo.sh build' ran
    1.06 ± 0.07 times faster than 'CHANNEL='pre' ../cargo.sh build'
  • Loading branch information
bjorn3 committed Dec 16, 2019
1 parent c84ff85 commit b86eb2e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
26 changes: 14 additions & 12 deletions src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,22 @@ pub fn trans_fn<'clif, 'tcx, B: Backend + 'static>(
context.func = func;
cx.module.define_function(func_id, context).unwrap();

let value_ranges = context
.build_value_labels_ranges(cx.module.isa())
.expect("value location ranges");

// Write optimized function to file for debugging
#[cfg(debug_assertions)]
crate::pretty_clif::write_clif_file(
cx.tcx,
"opt",
instance,
&context.func,
&clif_comments,
Some(&value_ranges),
);
{
let value_ranges = context
.build_value_labels_ranges(cx.module.isa())
.expect("value location ranges");

crate::pretty_clif::write_clif_file(
cx.tcx,
"opt",
instance,
&context.func,
&clif_comments,
Some(&value_ranges),
);
}

// Define debuginfo for function
let isa = cx.module.isa();
Expand Down
12 changes: 9 additions & 3 deletions src/pretty_clif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ pub struct CommentWriter {

impl CommentWriter {
pub fn new<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> Self {
CommentWriter {
global_comments: vec![
let mut global_comments = if cfg!(debug_assertions) {
vec![
format!("symbol {}", tcx.symbol_name(instance).name.as_str()),
format!("instance {:?}", instance),
format!(
Expand All @@ -86,7 +86,13 @@ impl CommentWriter {
)
),
String::new(),
],
]
} else {
vec![]
};

CommentWriter {
global_comments,
entity_comments: HashMap::new(),
inst_comments: HashMap::new(),
}
Expand Down

0 comments on commit b86eb2e

Please sign in to comment.