Skip to content

Commit

Permalink
Make FixedCount partitioning handle case where codegen units have to …
Browse files Browse the repository at this point in the history
…be added.
  • Loading branch information
michaelwoerister committed May 9, 2016
1 parent 0142336 commit b89a5d1
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions src/librustc_trans/partitioning.rs
Expand Up @@ -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> {
Expand Down Expand Up @@ -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;

Expand All @@ -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)[..])
}
}

Expand Down

0 comments on commit b89a5d1

Please sign in to comment.