Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor tidy ups #1518

Merged
merged 2 commits into from
Dec 19, 2024
Merged
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
22 changes: 12 additions & 10 deletions ykrt/src/compile/jitc_yk/codegen/x64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,6 @@ struct Assemble<'a> {
/// The offset after the trace's prologue. This is the re-entry point when returning from
/// side-traces.
prologue_offset: AssemblyOffset,
/// Whether or not to skip processing [Param]s. We enable this once we've finished processing
/// the header, as we currently [Param]s in the trace body are only placeholders.
skip_params: bool,
}

impl<'a> Assemble<'a> {
Expand Down Expand Up @@ -269,7 +266,6 @@ impl<'a> Assemble<'a> {
used_insts,
ptradds,
prologue_offset: AssemblyOffset(0),
skip_params: false,
}))
}

Expand Down Expand Up @@ -469,6 +465,7 @@ impl<'a> Assemble<'a> {
fn cg_insts(&mut self) -> Result<(), CompilationError> {
let mut iter = self.m.iter_skipping_insts();
let mut next = iter.next();
let mut in_header = true;
while let Some((iidx, inst)) = next {
self.comment(self.asm.offset(), inst.display(iidx, self.m).to_string());
if !self.used_insts[usize::from(iidx)] {
Expand All @@ -485,7 +482,13 @@ impl<'a> Assemble<'a> {
}

jit_ir::Inst::BinOp(i) => self.cg_binop(iidx, i),
jit_ir::Inst::Param(i) => self.cg_param(iidx, i),
jit_ir::Inst::Param(i) => {
// Right now, `Param`s in the body contain dummy values, and shouldn't be
// processed.
if in_header {
self.cg_param(iidx, i);
}
}
jit_ir::Inst::Load(i) => self.cg_load(iidx, i),
jit_ir::Inst::PtrAdd(pa_inst) => self.cg_ptradd(iidx, pa_inst),
jit_ir::Inst::DynPtrAdd(i) => self.cg_dynptradd(iidx, i),
Expand Down Expand Up @@ -515,7 +518,10 @@ impl<'a> Assemble<'a> {
}
jit_ir::Inst::Guard(i) => self.cg_guard(iidx, i),
jit_ir::Inst::TraceHeaderStart => self.cg_header_start(),
jit_ir::Inst::TraceHeaderEnd => self.cg_header_end(),
jit_ir::Inst::TraceHeaderEnd => {
self.cg_header_end();
in_header = false;
}
jit_ir::Inst::TraceBodyStart => self.cg_body_start(),
jit_ir::Inst::TraceBodyEnd => self.cg_body_end(iidx),
jit_ir::Inst::SidetraceEnd => self.cg_sidetrace_end(iidx, self.m.root_jump_addr()),
Expand Down Expand Up @@ -1072,9 +1078,6 @@ impl<'a> Assemble<'a> {
/// Codegen a [jit_ir::ParamInst]. This only informs the register allocator about the
/// locations of live variables without generating any actual machine code.
fn cg_param(&mut self, iidx: jit_ir::InstIdx, inst: &jit_ir::ParamInst) {
if self.skip_params {
return;
}
let m = VarLocation::from_yksmp_location(self.m, iidx, self.m.param(inst.paramidx()));
debug_assert!(self.m.inst(iidx).def_byte_size(self.m) <= REG64_BYTESIZE);
match m {
Expand Down Expand Up @@ -1992,7 +1995,6 @@ impl<'a> Assemble<'a> {
e => panic!("{:?}", e),
}
}
self.skip_params = true;
}

fn cg_body_start(&mut self) {
Expand Down
26 changes: 13 additions & 13 deletions ykrt/src/compile/jitc_yk/opt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,18 @@ impl Opt {

fn opt(mut self) -> Result<Module, CompilationError> {
let base = self.m.insts_len();
// The instruction offset after all `loadti` instructions.
let is_sidetrace = matches!(self.m.inst(self.m.last_inst_idx()), Inst::SidetraceEnd);

// Disable loop peeling if there is no `header_end` and we are running tests.
#[cfg(test)]
let disable_peel = !matches!(self.m.inst(self.m.last_inst_idx()), Inst::TraceHeaderEnd);
let peel = match self.m.inst(self.m.last_inst_idx()) {
// If this is a sidetrace, we perform optimisations up to, but including, loop peeling.
Inst::SidetraceEnd => false,
Inst::TraceHeaderEnd => true,
#[cfg(test)]
// Not all tests create "fully valid" traces, in the sense that -- to keep things
// simple -- they don't end with `TraceHeaderEnd`. We don't want to peel such traces,
// but nor, in testing mode, do we consider them ill-formed.
_ => false,
#[cfg(not(test))]
_ => panic!(),
};

// Note that since we will apply loop peeling here, the list of instructions grows as this
// loop runs. Each instruction we process is (after optimisations were applied), duplicated
Expand All @@ -388,13 +394,7 @@ impl Opt {
// explicitly perform dead code elimination and this function can be made `#[cfg(test)]` only.
self.m.dead_code_elimination();

#[cfg(test)]
if disable_peel {
return Ok(self.m);
}

if is_sidetrace {
// Side-traces don't loop and thus cannot be peeled.
if !peel {
return Ok(self.m);
}

Expand Down
Loading