Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/rustc_codegen_cranelift/src/driver/aot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use rustc_errors::{DiagCtxt, DiagCtxtHandle};
use rustc_middle::dep_graph::WorkProduct;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::mono::{MonoItem, MonoItemData, Visibility};
use rustc_session::Session;
use rustc_session::config::{OptLevel, OutputFilenames, OutputType};
use rustc_session::{BorrowedIncrCompSession, Session};
use rustc_span::Symbol;

use crate::base::CodegenedFunction;
Expand Down Expand Up @@ -337,6 +337,7 @@ impl WriteBackendMethods for AotDriver {
fn run_thin_lto(
_cgcx: &CodegenContext,
_prof: &SelfProfilerRef,
_incr_comp_session: Option<&BorrowedIncrCompSession>,
_dcx: rustc_errors::DiagCtxtHandle<'_>,
_exported_symbols_for_lto: &[String],
_each_linked_rlib_for_lto: &[PathBuf],
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_gcc/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ fn fat_lto(
for module in modules {
match module {
FatLtoInput::InMemory(m) => in_memory.push(m),
FatLtoInput::Serialized { name, bitcode_path } => {
info!("pushing serialized module {:?}", name);
FatLtoInput::Serialized { wp, bitcode_path } => {
info!("pushing serialized module {:?}", wp.cgu_name);
serialized_modules.push((
SerializedModule::from_file(&bitcode_path),
CString::new(name).unwrap(),
CString::new(wp.cgu_name).unwrap(),
));
}
}
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_codegen_gcc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ use rustc_errors::{DiagCtxt, DiagCtxtHandle};
use rustc_middle::dep_graph::{WorkProduct, WorkProductMap};
use rustc_middle::ty::TyCtxt;
use rustc_session::config::{OptLevel, OutputFilenames};
use rustc_session::{CodegenBackendInit, EarlySession, IncrCompSession, Session};
use rustc_session::{
BorrowedIncrCompSession, CodegenBackendInit, EarlySession, IncrCompSession, Session,
};
use rustc_span::{Symbol, sym};
use rustc_target::spec::{RelocModel, TargetTuple};
use tempfile::TempDir;
Expand Down Expand Up @@ -404,6 +406,7 @@ impl WriteBackendMethods for GccCodegenBackend {
fn run_thin_lto(
_cgcx: &CodegenContext,
_prof: &SelfProfilerRef,
_incr_comp_session: Option<&BorrowedIncrCompSession>,
_dcx: DiagCtxtHandle<'_>,
// FIXME(bjorn3): Limit LTO exports to these symbols
_exported_symbols_for_lto: &[String],
Expand Down
44 changes: 31 additions & 13 deletions compiler/rustc_codegen_llvm/src/back/llvm_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ use rustc_metadata::EncodedMetadata;
use rustc_middle::dep_graph::{WorkProduct, WorkProductMap};
use rustc_middle::ty::TyCtxt;
use rustc_session::config::{OptLevel, OutputFilenames, PrintKind, PrintRequest};
use rustc_session::{CodegenBackendInit, EarlySession, IncrCompSession, Session};
use rustc_session::{
BorrowedIncrCompSession, CodegenBackendInit, EarlySession, IncrCompSession, Session,
};
use rustc_span::{Symbol, sym};
use rustc_target::spec::{RelocModel, TlsModel};

Expand Down Expand Up @@ -120,6 +122,7 @@ impl WriteBackendMethods for LlvmCodegenBackend {
fn run_thin_lto(
cgcx: &CodegenContext,
prof: &SelfProfilerRef,
incr_comp_session: Option<&BorrowedIncrCompSession>,
dcx: DiagCtxtHandle<'_>,
exported_symbols_for_lto: &[String],
each_linked_rlib_for_lto: &[PathBuf],
Expand All @@ -128,6 +131,7 @@ impl WriteBackendMethods for LlvmCodegenBackend {
back::lto::run_thin(
cgcx,
prof,
incr_comp_session,
dcx,
exported_symbols_for_lto,
each_linked_rlib_for_lto,
Expand Down Expand Up @@ -377,21 +381,35 @@ impl CodegenBackend for LlvmCodegenBackend {
});
}

(compiled_modules, work_products)
}
if sess.codegen_units().as_usize() == 1 && sess.opts.unstable_opts.time_llvm_passes {
let timings =
llvm::build_string(|s| unsafe { llvm::LLVMRustPrintPassTimings(s) }).unwrap();
print!("{timings}");
}

fn print_pass_timings(&self) {
let timings = llvm::build_string(|s| unsafe { llvm::LLVMRustPrintPassTimings(s) }).unwrap();
print!("{timings}");
}
if sess.print_llvm_stats() {
let stats =
llvm::build_string(|s| unsafe { llvm::LLVMRustPrintStatistics(s) }).unwrap();
print!("{stats}");
}

fn print_statistics(&self) {
let stats = llvm::build_string(|s| unsafe { llvm::LLVMRustPrintStatistics(s) }).unwrap();
print!("{stats}");
}
if let Some(out_path) = sess.print_llvm_stats_json() {
let llvm_stats_json =
llvm::build_string(|s| unsafe { llvm::LLVMRustPrintStatisticsJSON(s) }).unwrap();

if !llvm_stats_json.is_empty() {
if let Err(e) = std::fs::write(&out_path, llvm_stats_json) {
sess.dcx().err(format!("failed to write stats to {out_path}: {e}"));
}
} else {
sess.dcx().warn(format!(
"requested to print LLVM statistics to JSON file {out_path}, but the codegen backend \
did not provide any statistics",
));
Comment thread
bjorn3 marked this conversation as resolved.
}
}

fn print_statistics_json(&self) -> String {
llvm::build_string(|s| unsafe { llvm::LLVMRustPrintStatisticsJSON(s) }).unwrap()
(compiled_modules, work_products)
}

fn link(
Expand Down
29 changes: 14 additions & 15 deletions compiler/rustc_codegen_llvm/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use rustc_data_structures::memmap::Mmap;
use rustc_data_structures::profiling::SelfProfilerRef;
use rustc_errors::{DiagCtxt, DiagCtxtHandle};
use rustc_middle::dep_graph::WorkProduct;
use rustc_session::config;
use rustc_session::{BorrowedIncrCompSession, config};
use rustc_span::bug;
use rustc_structures::SanitizerSet;
use tracing::{debug, info};
Expand Down Expand Up @@ -184,6 +184,7 @@ pub(crate) fn run_fat(
pub(crate) fn run_thin(
cgcx: &CodegenContext,
prof: &SelfProfilerRef,
incr_comp_session: Option<&BorrowedIncrCompSession>,
dcx: DiagCtxtHandle<'_>,
exported_symbols_for_lto: &[String],
each_linked_rlib_for_lto: &[PathBuf],
Expand All @@ -199,7 +200,7 @@ pub(crate) fn run_thin(
is deferred to the linker"
);
}
thin_lto(cgcx, prof, dcx, modules, upstream_modules, &symbols_below_threshold)
thin_lto(prof, incr_comp_session, dcx, modules, upstream_modules, &symbols_below_threshold)
}

fn fat_lto(
Expand All @@ -225,11 +226,11 @@ fn fat_lto(
for module in modules {
match module {
FatLtoInput::InMemory(m) => in_memory.push(m),
FatLtoInput::Serialized { name, bitcode_path } => {
info!("pushing serialized module {:?}", name);
FatLtoInput::Serialized { wp, bitcode_path } => {
info!("pushing serialized module {:?}", wp.cgu_name);
serialized_modules.push((
SerializedModule::from_file(&bitcode_path),
CString::new(name).unwrap(),
CString::new(wp.cgu_name).unwrap(),
));
}
}
Expand Down Expand Up @@ -371,8 +372,8 @@ fn fat_lto(
/// all of the `LtoModuleCodegen` units returned below and destroyed once
/// they all go out of scope.
fn thin_lto(
cgcx: &CodegenContext,
prof: &SelfProfilerRef,
incr_comp_session: Option<&BorrowedIncrCompSession>,
dcx: DiagCtxtHandle<'_>,
modules: Vec<ThinLtoInput<LlvmCodegenBackend>>,
serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>,
Expand Down Expand Up @@ -463,13 +464,12 @@ fn thin_lto(

info!("thin LTO data created");

let new_key_map_path = cgcx
.new_incr_comp_session_dir
.as_ref()
.map(|dir| dir.join(THIN_LTO_KEYS_INCR_COMP_FILE_NAME));
let new_key_map_path = incr_comp_session.as_ref().map(|incr_comp_session| {
incr_comp_session.new_session_directory.join(THIN_LTO_KEYS_INCR_COMP_FILE_NAME)
});

let prev_key_map = if let Some(ref old_incr_comp_session_dir) =
cgcx.old_incr_comp_session_dir
let prev_key_map = if let Some(ref old_incr_comp_session_dir) = incr_comp_session
.and_then(|incr_comp_session| incr_comp_session.old_session_directory.as_deref())
{
let old_path = old_incr_comp_session_dir.join(THIN_LTO_KEYS_INCR_COMP_FILE_NAME);

Expand All @@ -481,7 +481,7 @@ fn thin_lto(
assert!(green_modules.is_empty());
None
};
let curr_key_map = if cgcx.new_incr_comp_session_dir.is_some() {
let curr_key_map = if incr_comp_session.is_some() {
ThinLTOKeysMap::from_thin_lto_modules(&data, &thin_modules, &module_names)
} else {
assert!(green_modules.is_empty());
Expand All @@ -506,8 +506,7 @@ fn thin_lto(
if let (Some(prev_key_map), true) =
(prev_key_map.as_ref(), green_modules.contains_key(module_name))
{
assert!(cgcx.old_incr_comp_session_dir.is_some());
assert!(cgcx.new_incr_comp_session_dir.is_some());
assert!(incr_comp_session.unwrap().old_session_directory.is_some());

// If a module exists in both the current and the previous session,
// and has the same LTO cache key in both sessions, then we can re-use it
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/assert_module_sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<'tcx> AssertModuleSource<'tcx> {

if !self.check_config(cfg) {
debug!("check_attr: config does not match, ignoring attr");
return;
continue;
}

let user_path = module.as_str();
Expand Down
Loading
Loading