Skip to content

Commit 2994675

Browse files
Rollup merge of rust-lang#55349 - bjorn3:rustc_mir_collect_and_partition_mono_items, r=oli-obk
Move collect_and_partition_mono_items to rustc_mir Most of the logic of it is inside rustc_mir anyway. Also removes the single function crate rustc_metadata_utils. Based on rust-lang#55225
2 parents 0956690 + adafd0f commit 2994675

File tree

20 files changed

+280
-303
lines changed

20 files changed

+280
-303
lines changed

src/Cargo.lock

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,11 +2136,13 @@ dependencies = [
21362136
"flate2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
21372137
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
21382138
"rustc 0.0.0",
2139+
"rustc_allocator 0.0.0",
21392140
"rustc_data_structures 0.0.0",
21402141
"rustc_incremental 0.0.0",
2141-
"rustc_metadata_utils 0.0.0",
2142+
"rustc_metadata 0.0.0",
21422143
"rustc_mir 0.0.0",
21432144
"rustc_target 0.0.0",
2145+
"serialize 0.0.0",
21442146
"syntax 0.0.0",
21452147
"syntax_pos 0.0.0",
21462148
]
@@ -2283,23 +2285,13 @@ dependencies = [
22832285
"rustc 0.0.0",
22842286
"rustc_data_structures 0.0.0",
22852287
"rustc_errors 0.0.0",
2286-
"rustc_metadata_utils 0.0.0",
22872288
"rustc_target 0.0.0",
22882289
"serialize 0.0.0",
22892290
"syntax 0.0.0",
22902291
"syntax_ext 0.0.0",
22912292
"syntax_pos 0.0.0",
22922293
]
22932294

2294-
[[package]]
2295-
name = "rustc_metadata_utils"
2296-
version = "0.0.0"
2297-
dependencies = [
2298-
"rustc 0.0.0",
2299-
"syntax 0.0.0",
2300-
"syntax_pos 0.0.0",
2301-
]
2302-
23032295
[[package]]
23042296
name = "rustc_mir"
23052297
version = "0.0.0"

src/librustc_codegen_llvm/back/archive.rs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -52,28 +52,6 @@ enum Addition {
5252
},
5353
}
5454

55-
pub fn find_library(name: &str, search_paths: &[PathBuf], sess: &Session)
56-
-> PathBuf {
57-
// On Windows, static libraries sometimes show up as libfoo.a and other
58-
// times show up as foo.lib
59-
let oslibname = format!("{}{}{}",
60-
sess.target.target.options.staticlib_prefix,
61-
name,
62-
sess.target.target.options.staticlib_suffix);
63-
let unixlibname = format!("lib{}.a", name);
64-
65-
for path in search_paths {
66-
debug!("looking for {} inside {:?}", name, path);
67-
let test = path.join(&oslibname);
68-
if test.exists() { return test }
69-
if oslibname != unixlibname {
70-
let test = path.join(&unixlibname);
71-
if test.exists() { return test }
72-
}
73-
}
74-
sess.fatal(&format!("could not find native static library `{}`, \
75-
perhaps an -L flag is missing?", name));
76-
}
7755

7856
fn is_relevant_child(c: &Child) -> bool {
7957
match c.name() {
@@ -128,7 +106,7 @@ impl<'a> ArchiveBuilder<'a> {
128106
/// Adds all of the contents of a native library to this archive. This will
129107
/// search in the relevant locations for a library named `name`.
130108
pub fn add_native_library(&mut self, name: &str) {
131-
let location = find_library(name, &self.config.lib_search_paths,
109+
let location = ::rustc_codegen_utils::find_library(name, &self.config.lib_search_paths,
132110
self.config.sess);
133111
self.add_archive(&location, |_| false).unwrap_or_else(|e| {
134112
self.config.sess.fatal(&format!("failed to add native library {}: {}",

src/librustc_codegen_llvm/back/link.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ use back::wasm;
1212
use cc::windows_registry;
1313
use super::archive::{ArchiveBuilder, ArchiveConfig};
1414
use super::bytecode::RLIB_BYTECODE_EXTENSION;
15-
use super::linker::Linker;
16-
use super::command::Command;
1715
use super::rpath::RPathConfig;
1816
use super::rpath;
1917
use metadata::METADATA_FILENAME;
@@ -31,6 +29,8 @@ use rustc::hir::def_id::CrateNum;
3129
use tempfile::{Builder as TempFileBuilder, TempDir};
3230
use rustc_target::spec::{PanicStrategy, RelroLevel, LinkerFlavor};
3331
use rustc_data_structures::fx::FxHashSet;
32+
use rustc_codegen_utils::linker::Linker;
33+
use rustc_codegen_utils::command::Command;
3434
use context::get_reloc_model;
3535
use llvm;
3636

@@ -701,7 +701,8 @@ fn link_natively(sess: &Session,
701701
}
702702

703703
{
704-
let mut linker = codegen_results.linker_info.to_linker(cmd, &sess, flavor);
704+
let target_cpu = ::llvm_util::target_cpu(sess);
705+
let mut linker = codegen_results.linker_info.to_linker(cmd, &sess, flavor, target_cpu);
705706
link_args(&mut *linker, flavor, sess, crate_type, tmpdir,
706707
out_filename, codegen_results);
707708
cmd = linker.finalize();

src/librustc_codegen_llvm/back/lto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use back::bytecode::{DecodedBytecode, RLIB_BYTECODE_EXTENSION};
12-
use back::symbol_export;
1312
use back::write::{ModuleConfig, with_llvm_pmb, CodegenContext};
1413
use back::write::{self, DiagnosticHandlers, pre_lto_bitcode_filename};
1514
use errors::{FatalError, Handler};
@@ -24,6 +23,7 @@ use rustc::middle::exported_symbols::SymbolExportLevel;
2423
use rustc::session::config::{self, Lto};
2524
use rustc::util::common::time_ext;
2625
use rustc_data_structures::fx::FxHashMap;
26+
use rustc_codegen_utils::symbol_export;
2727
use time_graph::Timeline;
2828
use {ModuleCodegen, ModuleLlvm, ModuleKind};
2929

src/librustc_codegen_llvm/back/write.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ use attributes;
1212
use back::bytecode::{self, RLIB_BYTECODE_EXTENSION};
1313
use back::lto::{self, ModuleBuffer, ThinBuffer, SerializedModule};
1414
use back::link::{self, get_linker, remove};
15-
use back::command::Command;
16-
use back::linker::LinkerInfo;
17-
use back::symbol_export::ExportedSymbols;
1815
use base;
1916
use consts;
2017
use memmap;
@@ -38,6 +35,9 @@ use rustc::util::common::{time_ext, time_depth, set_time_depth, print_time_passe
3835
use rustc_fs_util::{path2cstr, link_or_copy};
3936
use rustc_data_structures::small_c_str::SmallCStr;
4037
use rustc_data_structures::svh::Svh;
38+
use rustc_codegen_utils::command::Command;
39+
use rustc_codegen_utils::linker::LinkerInfo;
40+
use rustc_codegen_utils::symbol_export::ExportedSymbols;
4141
use errors::{self, Handler, Level, DiagnosticBuilder, FatalError, DiagnosticId};
4242
use errors::emitter::{Emitter};
4343
use syntax::attr;

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,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;
@@ -962,128 +960,6 @@ fn assert_and_save_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
962960
|| rustc_incremental::save_dep_graph(tcx));
963961
}
964962

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

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

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

0 commit comments

Comments
 (0)