Skip to content

Commit 68dabe4

Browse files
committed
[WIP]
1 parent c0b04ea commit 68dabe4

File tree

3 files changed

+55
-21
lines changed

3 files changed

+55
-21
lines changed

build_system/build_sysroot.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ fn build_clif_sysroot_for_triple(
216216
}
217217

218218
// Build sysroot
219-
let mut rustflags = vec!["-Zforce-unstable-if-unmarked".to_owned()];
219+
let mut rustflags =
220+
vec!["-Zforce-unstable-if-unmarked".to_owned(), "-Zincremental-verify-ich".to_owned()];
220221
if !panic_unwind_support {
221222
rustflags.push("-Cpanic=abort".to_owned());
222223
}

src/driver/aot.rs

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use crate::concurrency_limiter::{ConcurrencyLimiter, ConcurrencyLimiterToken};
3232
use crate::debuginfo::TypeDebugContext;
3333
use crate::global_asm::{GlobalAsmConfig, GlobalAsmContext};
3434
use crate::prelude::*;
35+
use crate::serializable_module::SerializableModule;
3536
use crate::unwind_module::UnwindModule;
3637

3738
fn disable_incr_cache() -> bool {
@@ -512,7 +513,7 @@ fn codegen_cgu_content(
512513
tcx: TyCtxt<'_>,
513514
module: &mut dyn Module,
514515
cgu_name: rustc_span::Symbol,
515-
) -> (Vec<CodegenedFunction>, String) {
516+
) -> (Vec<(SerializableModule, String)>, String) {
516517
let _timer = tcx.prof.generic_activity_with_arg("codegen cgu", cgu_name.as_str());
517518

518519
let cgu = tcx.codegen_unit(cgu_name);
@@ -543,16 +544,41 @@ fn codegen_cgu_content(
543544
);
544545
continue;
545546
}
547+
548+
/*let dep_node = mono_item.codegen_dep_node(tcx);
549+
let ((ser_module, global_asm), _) = tcx.dep_graph.with_task(
550+
dep_node,
551+
tcx,
552+
(cgu.name(), instance),
553+
|tcx, (cgu_name, instance)| {*/
554+
let mut ser_module = SerializableModule::new(crate::build_isa(tcx.sess, false));
546555
let codegened_function = crate::base::codegen_fn(
547556
tcx,
548557
cgu_name,
549558
//debug_context.as_mut(),
550559
//&mut type_dbg,
551560
Function::new(),
552-
module,
561+
&mut ser_module,
553562
instance,
554563
);
555-
codegened_functions.push(codegened_function);
564+
let mut cached_context = Context::new();
565+
let mut global_asm = String::new();
566+
crate::base::compile_fn(
567+
&tcx.prof,
568+
&tcx.output_filenames(()),
569+
crate::pretty_clif::should_write_ir(tcx.sess),
570+
&mut cached_context,
571+
&mut ser_module,
572+
//debug_context.as_mut(),
573+
&mut global_asm,
574+
codegened_function,
575+
);
576+
/*(ser_module, global_asm)
577+
},
578+
Some(rustc_middle::dep_graph::hash_result),
579+
);*/
580+
581+
codegened_functions.push((ser_module, global_asm));
556582
}
557583
MonoItem::Static(def_id) => {
558584
let data_id = crate::constant::codegen_static(tcx, module, def_id);
@@ -591,27 +617,16 @@ fn module_codegen(
591617

592618
let profiler = tcx.prof.clone();
593619
let invocation_temp = tcx.sess.invocation_temp.clone();
594-
let output_filenames = tcx.output_filenames(()).clone();
595-
let should_write_ir = crate::pretty_clif::should_write_ir(tcx.sess);
596620

597621
OngoingModuleCodegen::Async(std::thread::spawn(move || {
598622
profiler.clone().generic_activity_with_arg("compile functions", &*cgu_name).run(|| {
599623
cranelift_codegen::timing::set_thread_profiler(Box::new(super::MeasuremeProfiler(
600624
profiler.clone(),
601625
)));
602626

603-
let mut cached_context = Context::new();
604-
for codegened_func in codegened_functions {
605-
crate::base::compile_fn(
606-
&profiler,
607-
&output_filenames,
608-
should_write_ir,
609-
&mut cached_context,
610-
&mut module,
611-
//debug_context.as_mut(),
612-
&mut global_asm,
613-
codegened_func,
614-
);
627+
for (codegened_func, asm) in codegened_functions {
628+
codegened_func.apply_to(&mut module);
629+
global_asm.push_str(&asm);
615630
}
616631
});
617632

src/serializable_module.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::collections::BTreeMap;
2-
use std::sync::Arc;
2+
use std::sync::{Arc, OnceLock};
33

44
use cranelift_codegen::control::ControlPlane;
55
use cranelift_codegen::entity::SecondaryMap;
@@ -8,12 +8,14 @@ use cranelift_codegen::isa::TargetIsa;
88
use cranelift_module::{
99
DataId, ModuleDeclarations, ModuleError, ModuleReloc, ModuleRelocTarget, ModuleResult,
1010
};
11+
use rustc_data_structures::stable_hasher::HashStable;
1112

1213
use crate::prelude::*;
1314

1415
pub(super) struct SerializableModule {
1516
isa: Arc<dyn TargetIsa>,
1617
inner: SerializableModuleInner,
18+
serialized: OnceLock<Vec<u8>>,
1719
}
1820

1921
#[derive(Debug, serde::Serialize, serde::Deserialize)]
@@ -23,6 +25,17 @@ struct SerializableModuleInner {
2325
data_objects: BTreeMap<DataId, DataDescription>,
2426
}
2527

28+
impl<CTX> HashStable<CTX> for SerializableModule {
29+
fn hash_stable(
30+
&self,
31+
hcx: &mut CTX,
32+
hasher: &mut rustc_data_structures::stable_hasher::StableHasher,
33+
) {
34+
let ser = self.serialized.get_or_init(|| self.serialize());
35+
ser.hash_stable(hcx, hasher);
36+
}
37+
}
38+
2639
impl SerializableModule {
2740
pub(crate) fn new(isa: Arc<dyn TargetIsa>) -> Self {
2841
SerializableModule {
@@ -32,16 +45,21 @@ impl SerializableModule {
3245
functions: BTreeMap::new(),
3346
data_objects: BTreeMap::new(),
3447
},
48+
serialized: OnceLock::new(),
3549
}
3650
}
3751

38-
pub(crate) fn serialize(self) -> Vec<u8> {
52+
pub(crate) fn serialize(&self) -> Vec<u8> {
3953
postcard::to_stdvec(&self.inner).unwrap()
4054
}
4155

4256
pub(crate) fn deserialize(blob: &[u8], isa: Arc<dyn TargetIsa>) -> SerializableModule {
4357
// FIXME check isa compatibility
44-
SerializableModule { isa, inner: postcard::from_bytes(blob).unwrap() }
58+
SerializableModule {
59+
isa,
60+
inner: postcard::from_bytes(blob).unwrap(),
61+
serialized: OnceLock::new(),
62+
}
4563
}
4664

4765
pub(crate) fn apply_to(self, module: &mut dyn Module) {

0 commit comments

Comments
 (0)