Skip to content

Commit 029cf2f

Browse files
committed
Move collect_and_partition_mono_items to rustc_mir
1 parent 18eeed5 commit 029cf2f

File tree

5 files changed

+165
-160
lines changed

5 files changed

+165
-160
lines changed

src/Cargo.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,11 +2135,13 @@ dependencies = [
21352135
"flate2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
21362136
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
21372137
"rustc 0.0.0",
2138+
"rustc_allocator 0.0.0",
21382139
"rustc_data_structures 0.0.0",
21392140
"rustc_incremental 0.0.0",
21402141
"rustc_metadata_utils 0.0.0",
21412142
"rustc_mir 0.0.0",
21422143
"rustc_target 0.0.0",
2144+
"serialize 0.0.0",
21432145
"syntax 0.0.0",
21442146
"syntax_pos 0.0.0",
21452147
]

src/librustc_codegen_llvm/base.rs

Lines changed: 4 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ use attributes;
5454
use builder::{Builder, MemFlags};
5555
use callee;
5656
use common::{C_bool, C_bytes_in_context, C_i32, C_usize};
57-
use rustc_mir::monomorphize::collector::{self, MonoItemCollectionMode};
5857
use rustc_mir::monomorphize::item::DefPathBasedNames;
5958
use common::{self, C_struct_in_context, C_array, val_ty};
6059
use consts;
@@ -64,20 +63,19 @@ use declare;
6463
use meth;
6564
use mir;
6665
use monomorphize::Instance;
67-
use monomorphize::partitioning::{self, PartitioningStrategy, CodegenUnit, CodegenUnitExt};
66+
use monomorphize::partitioning::{CodegenUnit, CodegenUnitExt};
6867
use rustc_codegen_utils::symbol_names_test;
6968
use time_graph;
70-
use mono_item::{MonoItem, BaseMonoItemExt, MonoItemExt};
69+
use mono_item::{MonoItem, MonoItemExt};
7170
use type_::Type;
7271
use type_of::LayoutLlvmExt;
73-
use rustc::util::nodemap::{FxHashMap, DefIdSet};
72+
use rustc::util::nodemap::FxHashMap;
7473
use CrateInfo;
7574
use rustc_data_structures::small_c_str::SmallCStr;
7675
use rustc_data_structures::sync::Lrc;
7776

7877
use std::any::Any;
7978
use std::ffi::CString;
80-
use std::sync::Arc;
8179
use std::time::{Instant, Duration};
8280
use std::i32;
8381
use std::cmp;
@@ -963,128 +961,6 @@ fn assert_and_save_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
963961
|| rustc_incremental::save_dep_graph(tcx));
964962
}
965963

966-
fn collect_and_partition_mono_items<'a, 'tcx>(
967-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
968-
cnum: CrateNum,
969-
) -> (Arc<DefIdSet>, Arc<Vec<Arc<CodegenUnit<'tcx>>>>)
970-
{
971-
assert_eq!(cnum, LOCAL_CRATE);
972-
973-
let collection_mode = match tcx.sess.opts.debugging_opts.print_mono_items {
974-
Some(ref s) => {
975-
let mode_string = s.to_lowercase();
976-
let mode_string = mode_string.trim();
977-
if mode_string == "eager" {
978-
MonoItemCollectionMode::Eager
979-
} else {
980-
if mode_string != "lazy" {
981-
let message = format!("Unknown codegen-item collection mode '{}'. \
982-
Falling back to 'lazy' mode.",
983-
mode_string);
984-
tcx.sess.warn(&message);
985-
}
986-
987-
MonoItemCollectionMode::Lazy
988-
}
989-
}
990-
None => {
991-
if tcx.sess.opts.cg.link_dead_code {
992-
MonoItemCollectionMode::Eager
993-
} else {
994-
MonoItemCollectionMode::Lazy
995-
}
996-
}
997-
};
998-
999-
let (items, inlining_map) =
1000-
time(tcx.sess, "monomorphization collection", || {
1001-
collector::collect_crate_mono_items(tcx, collection_mode)
1002-
});
1003-
1004-
tcx.sess.abort_if_errors();
1005-
1006-
::rustc_mir::monomorphize::assert_symbols_are_distinct(tcx, items.iter());
1007-
1008-
let strategy = if tcx.sess.opts.incremental.is_some() {
1009-
PartitioningStrategy::PerModule
1010-
} else {
1011-
PartitioningStrategy::FixedUnitCount(tcx.sess.codegen_units())
1012-
};
1013-
1014-
let codegen_units = time(tcx.sess, "codegen unit partitioning", || {
1015-
partitioning::partition(tcx,
1016-
items.iter().cloned(),
1017-
strategy,
1018-
&inlining_map)
1019-
.into_iter()
1020-
.map(Arc::new)
1021-
.collect::<Vec<_>>()
1022-
});
1023-
1024-
let mono_items: DefIdSet = items.iter().filter_map(|mono_item| {
1025-
match *mono_item {
1026-
MonoItem::Fn(ref instance) => Some(instance.def_id()),
1027-
MonoItem::Static(def_id) => Some(def_id),
1028-
_ => None,
1029-
}
1030-
}).collect();
1031-
1032-
if tcx.sess.opts.debugging_opts.print_mono_items.is_some() {
1033-
let mut item_to_cgus: FxHashMap<_, Vec<_>> = Default::default();
1034-
1035-
for cgu in &codegen_units {
1036-
for (&mono_item, &linkage) in cgu.items() {
1037-
item_to_cgus.entry(mono_item)
1038-
.or_default()
1039-
.push((cgu.name().clone(), linkage));
1040-
}
1041-
}
1042-
1043-
let mut item_keys: Vec<_> = items
1044-
.iter()
1045-
.map(|i| {
1046-
let mut output = i.to_string(tcx);
1047-
output.push_str(" @@");
1048-
let mut empty = Vec::new();
1049-
let cgus = item_to_cgus.get_mut(i).unwrap_or(&mut empty);
1050-
cgus.as_mut_slice().sort_by_key(|&(ref name, _)| name.clone());
1051-
cgus.dedup();
1052-
for &(ref cgu_name, (linkage, _)) in cgus.iter() {
1053-
output.push_str(" ");
1054-
output.push_str(&cgu_name.as_str());
1055-
1056-
let linkage_abbrev = match linkage {
1057-
Linkage::External => "External",
1058-
Linkage::AvailableExternally => "Available",
1059-
Linkage::LinkOnceAny => "OnceAny",
1060-
Linkage::LinkOnceODR => "OnceODR",
1061-
Linkage::WeakAny => "WeakAny",
1062-
Linkage::WeakODR => "WeakODR",
1063-
Linkage::Appending => "Appending",
1064-
Linkage::Internal => "Internal",
1065-
Linkage::Private => "Private",
1066-
Linkage::ExternalWeak => "ExternalWeak",
1067-
Linkage::Common => "Common",
1068-
};
1069-
1070-
output.push_str("[");
1071-
output.push_str(linkage_abbrev);
1072-
output.push_str("]");
1073-
}
1074-
output
1075-
})
1076-
.collect();
1077-
1078-
item_keys.sort();
1079-
1080-
for item in item_keys {
1081-
println!("MONO_ITEM {}", item);
1082-
}
1083-
}
1084-
1085-
(Arc::new(mono_items), Arc::new(codegen_units))
1086-
}
1087-
1088964
impl CrateInfo {
1089965
pub fn new(tcx: TyCtxt) -> CrateInfo {
1090966
let mut info = CrateInfo {
@@ -1174,12 +1050,6 @@ impl CrateInfo {
11741050
}
11751051
}
11761052

1177-
fn is_codegened_item(tcx: TyCtxt, id: DefId) -> bool {
1178-
let (all_mono_items, _) =
1179-
tcx.collect_and_partition_mono_items(LOCAL_CRATE);
1180-
all_mono_items.contains(&id)
1181-
}
1182-
11831053
fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11841054
cgu_name: InternedString)
11851055
-> Stats {
@@ -1270,24 +1140,7 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
12701140
}
12711141
}
12721142

1273-
pub fn provide(providers: &mut Providers) {
1274-
providers.collect_and_partition_mono_items =
1275-
collect_and_partition_mono_items;
1276-
1277-
providers.is_codegened_item = is_codegened_item;
1278-
1279-
providers.codegen_unit = |tcx, name| {
1280-
let (_, all) = tcx.collect_and_partition_mono_items(LOCAL_CRATE);
1281-
all.iter()
1282-
.find(|cgu| *cgu.name() == name)
1283-
.cloned()
1284-
.unwrap_or_else(|| panic!("failed to find cgu with name {:?}", name))
1285-
};
1286-
1287-
provide_extern(providers);
1288-
}
1289-
1290-
pub fn provide_extern(providers: &mut Providers) {
1143+
pub fn provide_both(providers: &mut Providers) {
12911144
providers.dllimport_foreign_items = |tcx, krate| {
12921145
let module_map = tcx.foreign_modules(krate);
12931146
let module_map = module_map.iter()

src/librustc_codegen_llvm/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,13 @@ impl CodegenBackend for LlvmCodegenBackend {
192192
fn provide(&self, providers: &mut ty::query::Providers) {
193193
rustc_codegen_utils::symbol_export::provide(providers);
194194
rustc_codegen_utils::symbol_names::provide(providers);
195-
base::provide(providers);
195+
base::provide_both(providers);
196196
attributes::provide(providers);
197197
}
198198

199199
fn provide_extern(&self, providers: &mut ty::query::Providers) {
200200
rustc_codegen_utils::symbol_export::provide_extern(providers);
201-
base::provide_extern(providers);
201+
base::provide_both(providers);
202202
attributes::provide_extern(providers);
203203
}
204204

src/librustc_mir/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ pub fn provide(providers: &mut Providers) {
9393
borrow_check::provide(providers);
9494
shim::provide(providers);
9595
transform::provide(providers);
96+
monomorphize::partitioning::provide(providers);
9697
providers.const_eval = const_eval::const_eval_provider;
9798
providers.check_match = hair::pattern::check_match;
9899
}

0 commit comments

Comments
 (0)