Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 6b9ee90

Browse files
committed
Reuse determine_cgu_reuse from cg_ssa in cg_clif
1 parent 317783a commit 6b9ee90

File tree

2 files changed

+2
-30
lines changed
  • compiler
    • rustc_codegen_cranelift/src/driver
    • rustc_codegen_ssa/src

2 files changed

+2
-30
lines changed

compiler/rustc_codegen_cranelift/src/driver/aot.rs

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::thread::JoinHandle;
88

99
use cranelift_object::{ObjectBuilder, ObjectModule};
1010
use rustc_codegen_ssa::back::metadata::create_compressed_metadata_file;
11+
use rustc_codegen_ssa::base::determine_cgu_reuse;
1112
use rustc_codegen_ssa::{CodegenResults, CompiledModule, CrateInfo, ModuleKind};
1213
use rustc_data_structures::profiling::SelfProfilerRef;
1314
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -489,32 +490,3 @@ pub(crate) fn run_aot(
489490
concurrency_limiter,
490491
})
491492
}
492-
493-
// Adapted from https://github.com/rust-lang/rust/blob/303d8aff6092709edd4dbd35b1c88e9aa40bf6d8/src/librustc_codegen_ssa/base.rs#L922-L953
494-
fn determine_cgu_reuse<'tcx>(tcx: TyCtxt<'tcx>, cgu: &CodegenUnit<'tcx>) -> CguReuse {
495-
if !tcx.dep_graph.is_fully_enabled() {
496-
return CguReuse::No;
497-
}
498-
499-
let work_product_id = &cgu.work_product_id();
500-
if tcx.dep_graph.previous_work_product(work_product_id).is_none() {
501-
// We don't have anything cached for this CGU. This can happen
502-
// if the CGU did not exist in the previous session.
503-
return CguReuse::No;
504-
}
505-
506-
// Try to mark the CGU as green. If it we can do so, it means that nothing
507-
// affecting the LLVM module has changed and we can re-use a cached version.
508-
// If we compile with any kind of LTO, this means we can re-use the bitcode
509-
// of the Pre-LTO stage (possibly also the Post-LTO version but we'll only
510-
// know that later). If we are not doing LTO, there is only one optimized
511-
// version of each module, so we re-use that.
512-
let dep_node = cgu.codegen_dep_node(tcx);
513-
assert!(
514-
!tcx.dep_graph.dep_node_exists(&dep_node),
515-
"CompileCodegenUnit dep-node for CGU `{}` already exists before marking.",
516-
cgu.name()
517-
);
518-
519-
if tcx.try_mark_green(&dep_node) { CguReuse::PostLto } else { CguReuse::No }
520-
}

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ pub fn provide(providers: &mut Providers) {
994994
};
995995
}
996996

997-
fn determine_cgu_reuse<'tcx>(tcx: TyCtxt<'tcx>, cgu: &CodegenUnit<'tcx>) -> CguReuse {
997+
pub fn determine_cgu_reuse<'tcx>(tcx: TyCtxt<'tcx>, cgu: &CodegenUnit<'tcx>) -> CguReuse {
998998
if !tcx.dep_graph.is_fully_enabled() {
999999
return CguReuse::No;
10001000
}

0 commit comments

Comments
 (0)