Skip to content

Commit

Permalink
Auto merge of #33171 - michaelwoerister:collector-drop-glue, r=nikoma…
Browse files Browse the repository at this point in the history
…tsakis

Some preliminary work towards making trans "collector driven".

The `trans::collector` already collects all translation items and `trans::partitioning` distributes these translation items into codegen units. The changes in this PR provide the following extensions to this functionality:

1. Drop-glue is handled more accurately now, knowing about the difference between `DropGlueKind::Ty` and `DropGlueKind::TyContents`.
2. The partitioning module now supports the `FixedUnitCount` strategy which more or less corresponds to the partitioning one gets via supplying `-Ccodegen-units` today.
3. The partitioning scheme also takes care of assigned LLVM declarations to codegen units, not just definitions (declarations for external items not yet implemented).

It's debatable whether declarations should be handled by the partitioning scheme or whether they should just be emitted on demand.
  • Loading branch information
bors committed Apr 28, 2016
2 parents 115c6c8 + 0fc9f9a commit 8da2bca
Show file tree
Hide file tree
Showing 20 changed files with 325 additions and 144 deletions.
33 changes: 22 additions & 11 deletions src/librustc_data_structures/bitvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ impl BitVector {

pub fn grow(&mut self, num_bits: usize) {
let num_words = u64s(num_bits);
let extra_words = self.data.len() - num_words;
if extra_words > 0 {
self.data.extend((0..extra_words).map(|_| 0));
if self.data.len() < num_words {
self.data.resize(num_words, 0)
}
}

Expand Down Expand Up @@ -284,15 +283,27 @@ fn union_two_vecs() {
#[test]
fn grow() {
let mut vec1 = BitVector::new(65);
assert!(vec1.insert(3));
assert!(!vec1.insert(3));
assert!(vec1.insert(5));
assert!(vec1.insert(64));
for index in 0 .. 65 {
assert!(vec1.insert(index));
assert!(!vec1.insert(index));
}
vec1.grow(128);
assert!(vec1.contains(3));
assert!(vec1.contains(5));
assert!(vec1.contains(64));
assert!(!vec1.contains(126));

// Check if the bits set before growing are still set
for index in 0 .. 65 {
assert!(vec1.contains(index));
}

// Check if the new bits are all un-set
for index in 65 .. 128 {
assert!(!vec1.contains(index));
}

// Check that we can set all new bits without running out of bounds
for index in 65 .. 128 {
assert!(vec1.insert(index));
assert!(!vec1.insert(index));
}
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_llvm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub enum Visibility {
// DLLExportLinkage, GhostLinkage and LinkOnceODRAutoHideLinkage.
// LinkerPrivateLinkage and LinkerPrivateWeakLinkage are not included either;
// they've been removed in upstream LLVM commit r203866.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub enum Linkage {
ExternalLinkage = 0,
AvailableExternallyLinkage = 1,
Expand Down
38 changes: 24 additions & 14 deletions src/librustc_trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ use attributes;
use build::*;
use builder::{Builder, noname};
use callee::{Callee, CallArgs, ArgExprs, ArgVals};
use partitioning;
use cleanup::{self, CleanupMethods, DropHint};
use closure;
use common::{Block, C_bool, C_bytes_in_context, C_i32, C_int, C_uint, C_integral};
Expand All @@ -83,6 +82,7 @@ use machine::{llalign_of_min, llsize_of, llsize_of_real};
use meth;
use mir;
use monomorphize::{self, Instance};
use partitioning::{self, PartitioningStrategy, InstantiationMode};
use symbol_names_test;
use tvec;
use type_::Type;
Expand Down Expand Up @@ -2934,12 +2934,21 @@ fn collect_translation_items<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>) {
None => TransItemCollectionMode::Lazy
};

let (items, inlining_map) = time(time_passes, "translation item collection", || {
let (items, reference_map) = time(time_passes, "translation item collection", || {
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", || {
partitioning::partition(ccx.tcx(), items.iter().cloned(), &inlining_map)
partitioning::partition(ccx.tcx(),
items.iter().cloned(),
strategy,
&reference_map)
});

if ccx.sess().opts.debugging_opts.print_trans_items.is_some() {
Expand Down Expand Up @@ -2967,17 +2976,18 @@ fn collect_translation_items<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>) {
output.push_str(&cgu_name[..]);

let linkage_abbrev = match linkage {
llvm::ExternalLinkage => "External",
llvm::AvailableExternallyLinkage => "Available",
llvm::LinkOnceAnyLinkage => "OnceAny",
llvm::LinkOnceODRLinkage => "OnceODR",
llvm::WeakAnyLinkage => "WeakAny",
llvm::WeakODRLinkage => "WeakODR",
llvm::AppendingLinkage => "Appending",
llvm::InternalLinkage => "Internal",
llvm::PrivateLinkage => "Private",
llvm::ExternalWeakLinkage => "ExternalWeak",
llvm::CommonLinkage => "Common",
InstantiationMode::Def(llvm::ExternalLinkage) => "External",
InstantiationMode::Def(llvm::AvailableExternallyLinkage) => "Available",
InstantiationMode::Def(llvm::LinkOnceAnyLinkage) => "OnceAny",
InstantiationMode::Def(llvm::LinkOnceODRLinkage) => "OnceODR",
InstantiationMode::Def(llvm::WeakAnyLinkage) => "WeakAny",
InstantiationMode::Def(llvm::WeakODRLinkage) => "WeakODR",
InstantiationMode::Def(llvm::AppendingLinkage) => "Appending",
InstantiationMode::Def(llvm::InternalLinkage) => "Internal",
InstantiationMode::Def(llvm::PrivateLinkage) => "Private",
InstantiationMode::Def(llvm::ExternalWeakLinkage) => "ExternalWeak",
InstantiationMode::Def(llvm::CommonLinkage) => "Common",
InstantiationMode::Decl => "Declaration",
};

output.push_str("[");
Expand Down
Loading

0 comments on commit 8da2bca

Please sign in to comment.