Skip to content

Commit d46246b

Browse files
committed
Move collect_and_partition_mono_items to rustc_mir
1 parent 942864a commit d46246b

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
@@ -2141,11 +2141,13 @@ dependencies = [
21412141
"flate2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
21422142
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
21432143
"rustc 0.0.0",
2144+
"rustc_allocator 0.0.0",
21442145
"rustc_data_structures 0.0.0",
21452146
"rustc_incremental 0.0.0",
21462147
"rustc_metadata_utils 0.0.0",
21472148
"rustc_mir 0.0.0",
21482149
"rustc_target 0.0.0",
2150+
"serialize 0.0.0",
21492151
"syntax 0.0.0",
21502152
"syntax_pos 0.0.0",
21512153
]

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::{C_struct_in_context, C_array, val_ty};
6059
use consts;
@@ -64,13 +63,13 @@ 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;
@@ -80,7 +79,6 @@ use std::cmp;
8079
use std::ffi::CString;
8180
use std::i32;
8281
use std::ops::{Deref, DerefMut};
83-
use std::sync::Arc;
8482
use std::sync::mpsc;
8583
use std::time::{Instant, Duration};
8684
use syntax_pos::Span;
@@ -1011,128 +1009,6 @@ fn assert_and_save_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
10111009
|| rustc_incremental::save_dep_graph(tcx));
10121010
}
10131011

1014-
fn collect_and_partition_mono_items<'a, 'tcx>(
1015-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
1016-
cnum: CrateNum,
1017-
) -> (Arc<DefIdSet>, Arc<Vec<Arc<CodegenUnit<'tcx>>>>)
1018-
{
1019-
assert_eq!(cnum, LOCAL_CRATE);
1020-
1021-
let collection_mode = match tcx.sess.opts.debugging_opts.print_mono_items {
1022-
Some(ref s) => {
1023-
let mode_string = s.to_lowercase();
1024-
let mode_string = mode_string.trim();
1025-
if mode_string == "eager" {
1026-
MonoItemCollectionMode::Eager
1027-
} else {
1028-
if mode_string != "lazy" {
1029-
let message = format!("Unknown codegen-item collection mode '{}'. \
1030-
Falling back to 'lazy' mode.",
1031-
mode_string);
1032-
tcx.sess.warn(&message);
1033-
}
1034-
1035-
MonoItemCollectionMode::Lazy
1036-
}
1037-
}
1038-
None => {
1039-
if tcx.sess.opts.cg.link_dead_code {
1040-
MonoItemCollectionMode::Eager
1041-
} else {
1042-
MonoItemCollectionMode::Lazy
1043-
}
1044-
}
1045-
};
1046-
1047-
let (items, inlining_map) =
1048-
time(tcx.sess, "monomorphization collection", || {
1049-
collector::collect_crate_mono_items(tcx, collection_mode)
1050-
});
1051-
1052-
tcx.sess.abort_if_errors();
1053-
1054-
::rustc_mir::monomorphize::assert_symbols_are_distinct(tcx, items.iter());
1055-
1056-
let strategy = if tcx.sess.opts.incremental.is_some() {
1057-
PartitioningStrategy::PerModule
1058-
} else {
1059-
PartitioningStrategy::FixedUnitCount(tcx.sess.codegen_units())
1060-
};
1061-
1062-
let codegen_units = time(tcx.sess, "codegen unit partitioning", || {
1063-
partitioning::partition(tcx,
1064-
items.iter().cloned(),
1065-
strategy,
1066-
&inlining_map)
1067-
.into_iter()
1068-
.map(Arc::new)
1069-
.collect::<Vec<_>>()
1070-
});
1071-
1072-
let mono_items: DefIdSet = items.iter().filter_map(|mono_item| {
1073-
match *mono_item {
1074-
MonoItem::Fn(ref instance) => Some(instance.def_id()),
1075-
MonoItem::Static(def_id) => Some(def_id),
1076-
_ => None,
1077-
}
1078-
}).collect();
1079-
1080-
if tcx.sess.opts.debugging_opts.print_mono_items.is_some() {
1081-
let mut item_to_cgus: FxHashMap<_, Vec<_>> = Default::default();
1082-
1083-
for cgu in &codegen_units {
1084-
for (&mono_item, &linkage) in cgu.items() {
1085-
item_to_cgus.entry(mono_item)
1086-
.or_default()
1087-
.push((cgu.name().clone(), linkage));
1088-
}
1089-
}
1090-
1091-
let mut item_keys: Vec<_> = items
1092-
.iter()
1093-
.map(|i| {
1094-
let mut output = i.to_string(tcx);
1095-
output.push_str(" @@");
1096-
let mut empty = Vec::new();
1097-
let cgus = item_to_cgus.get_mut(i).unwrap_or(&mut empty);
1098-
cgus.as_mut_slice().sort_by_key(|&(ref name, _)| name.clone());
1099-
cgus.dedup();
1100-
for &(ref cgu_name, (linkage, _)) in cgus.iter() {
1101-
output.push_str(" ");
1102-
output.push_str(&cgu_name.as_str());
1103-
1104-
let linkage_abbrev = match linkage {
1105-
Linkage::External => "External",
1106-
Linkage::AvailableExternally => "Available",
1107-
Linkage::LinkOnceAny => "OnceAny",
1108-
Linkage::LinkOnceODR => "OnceODR",
1109-
Linkage::WeakAny => "WeakAny",
1110-
Linkage::WeakODR => "WeakODR",
1111-
Linkage::Appending => "Appending",
1112-
Linkage::Internal => "Internal",
1113-
Linkage::Private => "Private",
1114-
Linkage::ExternalWeak => "ExternalWeak",
1115-
Linkage::Common => "Common",
1116-
};
1117-
1118-
output.push_str("[");
1119-
output.push_str(linkage_abbrev);
1120-
output.push_str("]");
1121-
}
1122-
output
1123-
})
1124-
.collect();
1125-
1126-
item_keys.sort();
1127-
1128-
for item in item_keys {
1129-
println!("MONO_ITEM {}", item);
1130-
}
1131-
}
1132-
1133-
(Arc::new(mono_items), Arc::new(codegen_units))
1134-
}
1135-
11361012
impl CrateInfo {
11371013
pub fn new(tcx: TyCtxt) -> CrateInfo {
11381014
let mut info = CrateInfo {
@@ -1222,12 +1098,6 @@ impl CrateInfo {
12221098
}
12231099
}
12241100

1225-
fn is_codegened_item(tcx: TyCtxt, id: DefId) -> bool {
1226-
let (all_mono_items, _) =
1227-
tcx.collect_and_partition_mono_items(LOCAL_CRATE);
1228-
all_mono_items.contains(&id)
1229-
}
1230-
12311101
fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
12321102
cgu_name: InternedString)
12331103
-> Stats {
@@ -1318,24 +1188,7 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
13181188
}
13191189
}
13201190

1321-
pub fn provide(providers: &mut Providers) {
1322-
providers.collect_and_partition_mono_items =
1323-
collect_and_partition_mono_items;
1324-
1325-
providers.is_codegened_item = is_codegened_item;
1326-
1327-
providers.codegen_unit = |tcx, name| {
1328-
let (_, all) = tcx.collect_and_partition_mono_items(LOCAL_CRATE);
1329-
all.iter()
1330-
.find(|cgu| *cgu.name() == name)
1331-
.cloned()
1332-
.unwrap_or_else(|| panic!("failed to find cgu with name {:?}", name))
1333-
};
1334-
1335-
provide_extern(providers);
1336-
}
1337-
1338-
pub fn provide_extern(providers: &mut Providers) {
1191+
pub fn provide_both(providers: &mut Providers) {
13391192
providers.dllimport_foreign_items = |tcx, krate| {
13401193
let module_map = tcx.foreign_modules(krate);
13411194
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.const_eval_raw = const_eval::const_eval_raw_provider;
9899
providers.check_match = hair::pattern::check_match;

0 commit comments

Comments
 (0)