Skip to content

Commit

Permalink
Pass TraceIterator to JIT compilers rather than Vec<TracedAOTBlock>.
Browse files Browse the repository at this point in the history
This allows the JIT compilers, if they so choose, to iterate over the
blocks. If a tracer chooses to process (e.g. decode) its trace in a
thread, this means that (some of) compilation and trace processing can
occur in parallel.

At the moment, this commit doesn't change anything meaningful inside
jitc_ykllvm or jitc_yk: both immediately `collect` the iterator into a
`Vec`. But the API is now flexible enough to allow something better in
the future.
  • Loading branch information
ltratt committed Feb 8, 2024
1 parent f3d7537 commit c8ea235
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions ykrt/src/compile/jitc_llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
compile::{CompilationError, CompiledTrace, Compiler},
location::HotLocation,
mt::{SideTraceInfo, MT},
trace::TracedAOTBlock,
trace::{TraceIterator, TracedAOTBlock},
};
use object::{Object, ObjectSection};
use parking_lot::Mutex;
Expand All @@ -32,10 +32,11 @@ impl Compiler for JITCLLVM {
fn compile(
&self,
mt: Arc<MT>,
irtrace: Vec<TracedAOTBlock>,
aottrace_iter: Box<dyn TraceIterator>,
sti: Option<SideTraceInfo>,
hl: Arc<Mutex<HotLocation>>,
) -> Result<CompiledTrace, CompilationError> {
let irtrace = aottrace_iter.collect::<Vec<_>>();
let (func_names, bbs, trace_len) = self.encode_trace(&irtrace);

let llvmbc = llvmbc_section();
Expand Down
5 changes: 3 additions & 2 deletions ykrt/src/compile/jitc_yk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
compile::{CompiledTrace, Compiler},
location::HotLocation,
mt::{SideTraceInfo, MT},
trace::TracedAOTBlock,
trace::TraceIterator,
};
use parking_lot::Mutex;
use std::{
Expand Down Expand Up @@ -60,7 +60,7 @@ impl Compiler for JITCYk {
fn compile(
&self,
_mt: Arc<MT>,
mtrace: Vec<TracedAOTBlock>,
aottrace_iter: Box<dyn TraceIterator>,
sti: Option<SideTraceInfo>,
_hl: Arc<Mutex<HotLocation>>,
) -> Result<CompiledTrace, CompilationError> {
Expand All @@ -77,6 +77,7 @@ impl Compiler for JITCYk {
eprintln!("--- End aot ---");
}

let mtrace = aottrace_iter.collect::<Vec<_>>();
let jit_mod = trace_builder::build(&aot_mod, &mtrace)?;

if PHASES_TO_PRINT.contains(&IRPhase::PreOpt) {
Expand Down
4 changes: 2 additions & 2 deletions ykrt/src/compile/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
location::HotLocation,
mt::{SideTraceInfo, MT},
trace::TracedAOTBlock,
trace::TraceIterator,
};
use libc::c_void;
use parking_lot::Mutex;
Expand Down Expand Up @@ -41,7 +41,7 @@ pub(crate) trait Compiler: Send + Sync {
fn compile(
&self,
mt: Arc<MT>,
irtrace: Vec<TracedAOTBlock>,
aottrace_iter: Box<dyn TraceIterator>,
sti: Option<SideTraceInfo>,
hl: Arc<Mutex<HotLocation>>,
) -> Result<CompiledTrace, CompilationError>;
Expand Down
3 changes: 1 addition & 2 deletions ykrt/src/mt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,6 @@ impl MT {
let mt = Arc::clone(self);
let do_compile = move || {
mt.stats.timing_state(TimingState::TraceMapping);
let irtrace = trace_iter.collect::<Vec<_>>();
debug_assert!(
sidetrace.is_none() || matches!(hl_arc.lock().kind, HotLocationKind::Compiled(_))
);
Expand All @@ -497,7 +496,7 @@ impl MT {
let guardid = sidetrace.as_ref().map(|x| x.0.guardid);
match compiler.compile(
Arc::clone(&mt),
irtrace,
trace_iter,
sidetrace.as_ref().map(|x| x.0),
Arc::clone(&hl_arc),
) {
Expand Down

0 comments on commit c8ea235

Please sign in to comment.