Skip to content

Commit 8da2bca

Browse files
committed
Auto merge of rust-lang#33171 - michaelwoerister:collector-drop-glue, r=nikomatsakis
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.
2 parents 115c6c8 + 0fc9f9a commit 8da2bca

20 files changed

+325
-144
lines changed

src/librustc_data_structures/bitvec.rs

+22-11
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ impl BitVector {
5252

5353
pub fn grow(&mut self, num_bits: usize) {
5454
let num_words = u64s(num_bits);
55-
let extra_words = self.data.len() - num_words;
56-
if extra_words > 0 {
57-
self.data.extend((0..extra_words).map(|_| 0));
55+
if self.data.len() < num_words {
56+
self.data.resize(num_words, 0)
5857
}
5958
}
6059

@@ -284,15 +283,27 @@ fn union_two_vecs() {
284283
#[test]
285284
fn grow() {
286285
let mut vec1 = BitVector::new(65);
287-
assert!(vec1.insert(3));
288-
assert!(!vec1.insert(3));
289-
assert!(vec1.insert(5));
290-
assert!(vec1.insert(64));
286+
for index in 0 .. 65 {
287+
assert!(vec1.insert(index));
288+
assert!(!vec1.insert(index));
289+
}
291290
vec1.grow(128);
292-
assert!(vec1.contains(3));
293-
assert!(vec1.contains(5));
294-
assert!(vec1.contains(64));
295-
assert!(!vec1.contains(126));
291+
292+
// Check if the bits set before growing are still set
293+
for index in 0 .. 65 {
294+
assert!(vec1.contains(index));
295+
}
296+
297+
// Check if the new bits are all un-set
298+
for index in 65 .. 128 {
299+
assert!(!vec1.contains(index));
300+
}
301+
302+
// Check that we can set all new bits without running out of bounds
303+
for index in 65 .. 128 {
304+
assert!(vec1.insert(index));
305+
assert!(!vec1.insert(index));
306+
}
296307
}
297308

298309
#[test]

src/librustc_llvm/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub enum Visibility {
9797
// DLLExportLinkage, GhostLinkage and LinkOnceODRAutoHideLinkage.
9898
// LinkerPrivateLinkage and LinkerPrivateWeakLinkage are not included either;
9999
// they've been removed in upstream LLVM commit r203866.
100-
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
100+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
101101
pub enum Linkage {
102102
ExternalLinkage = 0,
103103
AvailableExternallyLinkage = 1,

src/librustc_trans/base.rs

+24-14
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ use attributes;
5858
use build::*;
5959
use builder::{Builder, noname};
6060
use callee::{Callee, CallArgs, ArgExprs, ArgVals};
61-
use partitioning;
6261
use cleanup::{self, CleanupMethods, DropHint};
6362
use closure;
6463
use common::{Block, C_bool, C_bytes_in_context, C_i32, C_int, C_uint, C_integral};
@@ -83,6 +82,7 @@ use machine::{llalign_of_min, llsize_of, llsize_of_real};
8382
use meth;
8483
use mir;
8584
use monomorphize::{self, Instance};
85+
use partitioning::{self, PartitioningStrategy, InstantiationMode};
8686
use symbol_names_test;
8787
use tvec;
8888
use type_::Type;
@@ -2934,12 +2934,21 @@ fn collect_translation_items<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>) {
29342934
None => TransItemCollectionMode::Lazy
29352935
};
29362936

2937-
let (items, inlining_map) = time(time_passes, "translation item collection", || {
2937+
let (items, reference_map) = time(time_passes, "translation item collection", || {
29382938
collector::collect_crate_translation_items(&ccx, collection_mode)
29392939
});
29402940

2941+
let strategy = if ccx.sess().opts.debugging_opts.incremental.is_some() {
2942+
PartitioningStrategy::PerModule
2943+
} else {
2944+
PartitioningStrategy::FixedUnitCount(ccx.sess().opts.cg.codegen_units)
2945+
};
2946+
29412947
let codegen_units = time(time_passes, "codegen unit partitioning", || {
2942-
partitioning::partition(ccx.tcx(), items.iter().cloned(), &inlining_map)
2948+
partitioning::partition(ccx.tcx(),
2949+
items.iter().cloned(),
2950+
strategy,
2951+
&reference_map)
29432952
});
29442953

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

29692978
let linkage_abbrev = match linkage {
2970-
llvm::ExternalLinkage => "External",
2971-
llvm::AvailableExternallyLinkage => "Available",
2972-
llvm::LinkOnceAnyLinkage => "OnceAny",
2973-
llvm::LinkOnceODRLinkage => "OnceODR",
2974-
llvm::WeakAnyLinkage => "WeakAny",
2975-
llvm::WeakODRLinkage => "WeakODR",
2976-
llvm::AppendingLinkage => "Appending",
2977-
llvm::InternalLinkage => "Internal",
2978-
llvm::PrivateLinkage => "Private",
2979-
llvm::ExternalWeakLinkage => "ExternalWeak",
2980-
llvm::CommonLinkage => "Common",
2979+
InstantiationMode::Def(llvm::ExternalLinkage) => "External",
2980+
InstantiationMode::Def(llvm::AvailableExternallyLinkage) => "Available",
2981+
InstantiationMode::Def(llvm::LinkOnceAnyLinkage) => "OnceAny",
2982+
InstantiationMode::Def(llvm::LinkOnceODRLinkage) => "OnceODR",
2983+
InstantiationMode::Def(llvm::WeakAnyLinkage) => "WeakAny",
2984+
InstantiationMode::Def(llvm::WeakODRLinkage) => "WeakODR",
2985+
InstantiationMode::Def(llvm::AppendingLinkage) => "Appending",
2986+
InstantiationMode::Def(llvm::InternalLinkage) => "Internal",
2987+
InstantiationMode::Def(llvm::PrivateLinkage) => "Private",
2988+
InstantiationMode::Def(llvm::ExternalWeakLinkage) => "ExternalWeak",
2989+
InstantiationMode::Def(llvm::CommonLinkage) => "Common",
2990+
InstantiationMode::Decl => "Declaration",
29812991
};
29822992

29832993
output.push_str("[");

0 commit comments

Comments
 (0)