1
Fork 0

Make FixedCount partitioning handle case where codegen units have to be added.

This commit is contained in:
Michael Woerister 2016-05-06 17:00:59 -04:00
parent 0142336a2a
commit b89a5d1f7c

View file

@ -182,19 +182,7 @@ pub fn partition<'tcx, I>(tcx: &TyCtxt<'tcx>,
// easily determine which declarations need to be placed within each one.
let post_declarations = place_declarations(post_inlining, reference_map);
let mut final_partitioning = post_declarations.0;
if final_partitioning.len() == 0 {
// Some crates don't contain anything that will result in a translation
// item. We still want to have at least one (empty) codegen unit in that
// case.
final_partitioning.push(CodegenUnit {
name: token::intern_and_get_ident(&format!("{}.0", tcx.crate_name)[..]),
items: FnvHashMap()
});
}
final_partitioning
post_declarations.0
}
struct PreInliningPartitioning<'tcx> {
@ -268,10 +256,6 @@ fn place_root_translation_items<'tcx, I>(tcx: &TyCtxt<'tcx>,
fn merge_codegen_units<'tcx>(initial_partitioning: &mut PreInliningPartitioning<'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;
@ -290,7 +274,22 @@ fn merge_codegen_units<'tcx>(initial_partitioning: &mut PreInliningPartitioning<
}
for (index, cgu) in codegen_units.iter_mut().enumerate() {
cgu.name = token::intern_and_get_ident(&format!("{}.{}", crate_name, index)[..]);
cgu.name = numbered_codegen_unit_name(crate_name, index);
}
// If the initial partitioning contained less than target_cgu_count to begin
// with, we won't have enough codegen units here, so add a empty units until
// we reach the target count
while codegen_units.len() < target_cgu_count {
let index = codegen_units.len();
codegen_units.push(CodegenUnit {
name: numbered_codegen_unit_name(crate_name, index),
items: FnvHashMap()
});
}
fn numbered_codegen_unit_name(crate_name: &str, index: usize) -> InternedString {
token::intern_and_get_ident(&format!("{}.{}", crate_name, index)[..])
}
}