Add FixedUnitCount codegen unit partitioning strategy.
This commit is contained in:
parent
c61f22932d
commit
7f04d35cc6
12 changed files with 59 additions and 13 deletions
|
@ -58,7 +58,7 @@ use attributes;
|
||||||
use build::*;
|
use build::*;
|
||||||
use builder::{Builder, noname};
|
use builder::{Builder, noname};
|
||||||
use callee::{Callee, CallArgs, ArgExprs, ArgVals};
|
use callee::{Callee, CallArgs, ArgExprs, ArgVals};
|
||||||
use partitioning;
|
use partitioning::{self, PartitioningStrategy};
|
||||||
use cleanup::{self, CleanupMethods, DropHint};
|
use cleanup::{self, CleanupMethods, DropHint};
|
||||||
use closure;
|
use closure;
|
||||||
use common::{Block, C_bool, C_bytes_in_context, C_i32, C_int, C_uint, C_integral};
|
use common::{Block, C_bool, C_bytes_in_context, C_i32, C_int, C_uint, C_integral};
|
||||||
|
@ -2938,8 +2938,17 @@ fn collect_translation_items<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>) {
|
||||||
collector::collect_crate_translation_items(&ccx, collection_mode)
|
collector::collect_crate_translation_items(&ccx, collection_mode)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let strategy = if ccx.sess().opts.debugging_opts.incremental.is_some() {
|
||||||
|
PartitioningStrategy::PerModule
|
||||||
|
} else {
|
||||||
|
PartitioningStrategy::FixedUnitCount(ccx.sess().opts.cg.codegen_units)
|
||||||
|
};
|
||||||
|
|
||||||
let codegen_units = time(time_passes, "codegen unit partitioning", || {
|
let codegen_units = time(time_passes, "codegen unit partitioning", || {
|
||||||
partitioning::partition(ccx.tcx(), items.iter().cloned(), &inlining_map)
|
partitioning::partition(ccx.tcx(),
|
||||||
|
items.iter().cloned(),
|
||||||
|
strategy,
|
||||||
|
&inlining_map)
|
||||||
});
|
});
|
||||||
|
|
||||||
if ccx.sess().opts.debugging_opts.print_trans_items.is_some() {
|
if ccx.sess().opts.debugging_opts.print_trans_items.is_some() {
|
||||||
|
|
|
@ -132,11 +132,17 @@ pub struct CodegenUnit<'tcx> {
|
||||||
pub items: FnvHashMap<TransItem<'tcx>, llvm::Linkage>,
|
pub items: FnvHashMap<TransItem<'tcx>, llvm::Linkage>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum PartitioningStrategy {
|
||||||
|
PerModule,
|
||||||
|
FixedUnitCount(usize)
|
||||||
|
}
|
||||||
|
|
||||||
// Anything we can't find a proper codegen unit for goes into this.
|
// Anything we can't find a proper codegen unit for goes into this.
|
||||||
const FALLBACK_CODEGEN_UNIT: &'static str = "__rustc_fallback_codegen_unit";
|
const FALLBACK_CODEGEN_UNIT: &'static str = "__rustc_fallback_codegen_unit";
|
||||||
|
|
||||||
pub fn partition<'tcx, I>(tcx: &TyCtxt<'tcx>,
|
pub fn partition<'tcx, I>(tcx: &TyCtxt<'tcx>,
|
||||||
trans_items: I,
|
trans_items: I,
|
||||||
|
strategy: PartitioningStrategy,
|
||||||
inlining_map: &InliningMap<'tcx>)
|
inlining_map: &InliningMap<'tcx>)
|
||||||
-> Vec<CodegenUnit<'tcx>>
|
-> Vec<CodegenUnit<'tcx>>
|
||||||
where I: Iterator<Item = TransItem<'tcx>>
|
where I: Iterator<Item = TransItem<'tcx>>
|
||||||
|
@ -144,7 +150,11 @@ pub fn partition<'tcx, I>(tcx: &TyCtxt<'tcx>,
|
||||||
// In the first step, we place all regular translation items into their
|
// In the first step, we place all regular translation items into their
|
||||||
// respective 'home' codegen unit. Regular translation items are all
|
// respective 'home' codegen unit. Regular translation items are all
|
||||||
// functions and statics defined in the local crate.
|
// functions and statics defined in the local crate.
|
||||||
let initial_partitioning = place_root_translation_items(tcx, trans_items);
|
let mut initial_partitioning = place_root_translation_items(tcx, trans_items);
|
||||||
|
|
||||||
|
if let PartitioningStrategy::FixedUnitCount(count) = strategy {
|
||||||
|
merge_codegen_units(&mut initial_partitioning, count, &tcx.crate_name[..]);
|
||||||
|
}
|
||||||
|
|
||||||
// In the next step, we use the inlining map to determine which addtional
|
// In the next step, we use the inlining map to determine which addtional
|
||||||
// translation items have to go into each codegen unit. These additional
|
// translation items have to go into each codegen unit. These additional
|
||||||
|
@ -217,6 +227,33 @@ fn place_root_translation_items<'tcx, I>(tcx: &TyCtxt<'tcx>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn merge_codegen_units<'tcx>(initial_partitioning: &mut InitialPartitioning<'tcx>,
|
||||||
|
target_cgu_count: usize,
|
||||||
|
crate_name: &str) {
|
||||||
|
if target_cgu_count >= initial_partitioning.codegen_units.len() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert!(target_cgu_count >= 1);
|
||||||
|
let codegen_units = &mut initial_partitioning.codegen_units;
|
||||||
|
|
||||||
|
// Merge the two smallest codegen units until the target size is reached
|
||||||
|
while codegen_units.len() > target_cgu_count {
|
||||||
|
// Sort small cgus to the back
|
||||||
|
codegen_units.as_mut_slice().sort_by_key(|cgu| -(cgu.items.len() as i64));
|
||||||
|
let smallest = codegen_units.pop().unwrap();
|
||||||
|
let second_smallest = codegen_units.last_mut().unwrap();
|
||||||
|
|
||||||
|
for (k, v) in smallest.items.into_iter() {
|
||||||
|
second_smallest.items.insert(k, v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (index, cgu) in codegen_units.iter_mut().enumerate() {
|
||||||
|
cgu.name = token::intern_and_get_ident(&format!("{}.{}", crate_name, index)[..]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn place_inlined_translation_items<'tcx>(initial_partitioning: InitialPartitioning<'tcx>,
|
fn place_inlined_translation_items<'tcx>(initial_partitioning: InitialPartitioning<'tcx>,
|
||||||
inlining_map: &InliningMap<'tcx>)
|
inlining_map: &InliningMap<'tcx>)
|
||||||
-> Vec<CodegenUnit<'tcx>> {
|
-> Vec<CodegenUnit<'tcx>> {
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
// ignore-tidy-linelength
|
// ignore-tidy-linelength
|
||||||
// compile-flags:-Zprint-trans-items=lazy
|
// compile-flags:-Zprint-trans-items=lazy -Zincremental=""
|
||||||
|
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
#![crate_type="lib"]
|
#![crate_type="lib"]
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
// ignore-tidy-linelength
|
// ignore-tidy-linelength
|
||||||
// compile-flags:-Zprint-trans-items=eager
|
// compile-flags:-Zprint-trans-items=eager -Zincremental=""
|
||||||
|
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
#![crate_type="lib"]
|
#![crate_type="lib"]
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
// ignore-tidy-linelength
|
// ignore-tidy-linelength
|
||||||
// compile-flags:-Zprint-trans-items=lazy
|
// compile-flags:-Zprint-trans-items=lazy -Zincremental=""
|
||||||
|
|
||||||
#![crate_type="lib"]
|
#![crate_type="lib"]
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
// ignore-tidy-linelength
|
// ignore-tidy-linelength
|
||||||
// compile-flags:-Zprint-trans-items=lazy
|
// compile-flags:-Zprint-trans-items=lazy -Zincremental=""
|
||||||
|
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
#![crate_type="lib"]
|
#![crate_type="lib"]
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
// ignore-tidy-linelength
|
// ignore-tidy-linelength
|
||||||
// compile-flags:-Zprint-trans-items=eager
|
// compile-flags:-Zprint-trans-items=eager -Zincremental=""
|
||||||
|
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
#![crate_type="lib"]
|
#![crate_type="lib"]
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
// ignore-tidy-linelength
|
// ignore-tidy-linelength
|
||||||
// compile-flags:-Zprint-trans-items=lazy
|
// compile-flags:-Zprint-trans-items=lazy -Zincremental=""
|
||||||
|
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
#![crate_type="lib"]
|
#![crate_type="lib"]
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
// ignore-tidy-linelength
|
// ignore-tidy-linelength
|
||||||
// compile-flags:-Zprint-trans-items=lazy
|
// compile-flags:-Zprint-trans-items=lazy -Zincremental=""
|
||||||
|
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
#![crate_type="lib"]
|
#![crate_type="lib"]
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
// ignore-tidy-linelength
|
// ignore-tidy-linelength
|
||||||
// compile-flags:-Zprint-trans-items=lazy
|
// compile-flags:-Zprint-trans-items=lazy -Zincremental=""
|
||||||
|
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
// ignore-tidy-linelength
|
// ignore-tidy-linelength
|
||||||
// compile-flags:-Zprint-trans-items=eager
|
// compile-flags:-Zprint-trans-items=eager -Z incremental=""
|
||||||
|
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
#![crate_type="lib"]
|
#![crate_type="lib"]
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
// ignore-tidy-linelength
|
// ignore-tidy-linelength
|
||||||
// compile-flags:-Zprint-trans-items=lazy
|
// compile-flags:-Zprint-trans-items=lazy -Zincremental=""
|
||||||
|
|
||||||
#![crate_type="lib"]
|
#![crate_type="lib"]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue