Skip to content

Commit

Permalink
Merge pull request #961 from ltratt/pass_traceiterator
Browse files Browse the repository at this point in the history
Pass `[AOT]TraceIterator` to compiler backends
  • Loading branch information
vext01 authored Feb 8, 2024
2 parents 8b6ccad + 1ea1014 commit 41f598f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 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::{AOTTraceIterator, 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 AOTTraceIterator>,
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::AOTTraceIterator,
};
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 AOTTraceIterator>,
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::AOTTraceIterator,
};
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 AOTTraceIterator>,
sti: Option<SideTraceInfo>,
hl: Arc<Mutex<HotLocation>>,
) -> Result<CompiledTrace, CompilationError>;
Expand Down
7 changes: 3 additions & 4 deletions ykrt/src/mt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::print_jit_state;
use crate::{
compile::{default_compiler, CompilationError, CompiledTrace, Compiler, GuardId},
location::{HotLocation, HotLocationKind, Location, TraceFailed},
trace::{default_tracer, TraceCollector, TraceIterator, Tracer},
trace::{default_tracer, AOTTraceIterator, TraceCollector, Tracer},
ykstats::{TimingState, YkStats},
};
use yktracec::promote;
Expand Down Expand Up @@ -476,15 +476,14 @@ impl MT {
/// in the `hl_arc`.
fn queue_compile_job(
self: &Arc<Self>,
trace_iter: Box<dyn TraceIterator>,
trace_iter: Box<dyn AOTTraceIterator>,
hl_arc: Arc<Mutex<HotLocation>>,
sidetrace: Option<(SideTraceInfo, Arc<CompiledTrace>)>,
) {
self.stats.trace_collected_ok();
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
6 changes: 3 additions & 3 deletions ykrt/src/trace/hwt/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Hardware tracing via hwtracer.
use super::{errors::InvalidTraceError, TraceCollector, TraceIterator, TracedAOTBlock};
use super::{errors::InvalidTraceError, AOTTraceIterator, TraceCollector, TracedAOTBlock};
use std::{error::Error, sync::Arc};

pub(crate) mod mapper;
Expand Down Expand Up @@ -33,7 +33,7 @@ struct HWTTraceCollector {
}

impl TraceCollector for HWTTraceCollector {
fn stop_collector(self: Box<Self>) -> Result<Box<dyn TraceIterator>, InvalidTraceError> {
fn stop_collector(self: Box<Self>) -> Result<Box<dyn AOTTraceIterator>, InvalidTraceError> {
let tr = self.thread_tracer.stop_collector().unwrap();
let mut mt = HWTMapper::new();
let mapped = mt
Expand All @@ -53,7 +53,7 @@ struct HWTTraceIterator {
trace: std::vec::IntoIter<TracedAOTBlock>,
}

impl TraceIterator for HWTTraceIterator {}
impl AOTTraceIterator for HWTTraceIterator {}

impl Iterator for HWTTraceIterator {
type Item = TracedAOTBlock;
Expand Down
4 changes: 2 additions & 2 deletions ykrt/src/trace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ pub(crate) fn default_tracer() -> Result<Arc<dyn Tracer>, Box<dyn Error>> {
pub(crate) trait TraceCollector {
/// Stop collecting a trace of the current thread and return an iterator which successively
/// produces the traced blocks.
fn stop_collector(self: Box<Self>) -> Result<Box<dyn TraceIterator>, InvalidTraceError>;
fn stop_collector(self: Box<Self>) -> Result<Box<dyn AOTTraceIterator>, InvalidTraceError>;
}

/// An iterator which takes an underlying raw trace and successively produces [TracedAOTBlock]s.
pub(crate) trait TraceIterator: Iterator<Item = TracedAOTBlock> + Send {}
pub(crate) trait AOTTraceIterator: Iterator<Item = TracedAOTBlock> + Send {}

/// An AOT LLVM IR block that has been traced at JIT time.
#[derive(Debug, Eq, PartialEq)]
Expand Down

0 comments on commit 41f598f

Please sign in to comment.