Skip to content

Commit

Permalink
allocate cut variables properly (#2183)
Browse files Browse the repository at this point in the history
  • Loading branch information
mthom committed Nov 28, 2023
1 parent de5de0c commit 5cb207d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
7 changes: 1 addition & 6 deletions src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@ pub(crate) trait Allocator {
is_new_var: bool,
);

fn mark_cut_var<'a, Target: CompilationTarget<'a>>(
&mut self,
var_num: usize,
term_loc: GenContext,
code: &mut CodeDeque,
) -> RegType;
fn mark_cut_var(&mut self, var_num: usize, chunk_num: usize) -> RegType;

fn mark_var<'a, Target: CompilationTarget<'a>>(
&mut self,
Expand Down
8 changes: 2 additions & 6 deletions src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -926,16 +926,12 @@ impl<'b> CodeGenerator<'b> {
match term {
&QueryTerm::GetLevel(var_num) => {
let code = branch_code_stack.code(code);
let r = self
.marker
.mark_cut_var::<QueryInstruction>(var_num, term_loc, code);
let r = self.marker.mark_cut_var(var_num, chunk_num);
code.push_back(instr!("get_level", r));
}
&QueryTerm::GetCutPoint { var_num, prev_b } => {
let code = branch_code_stack.code(code);
let r = self
.marker
.mark_cut_var::<FactInstruction>(var_num, term_loc, code);
let r = self.marker.mark_cut_var(var_num, chunk_num);

code.push_back(if prev_b {
instr!("get_prev_level", r)
Expand Down
25 changes: 15 additions & 10 deletions src/debray_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,18 +840,23 @@ impl Allocator for DebrayAllocator {
self.in_use.insert(o);
}

fn mark_cut_var<'a, Target: CompilationTarget<'a>>(
&mut self,
var_num: usize,
term_loc: GenContext,
code: &mut CodeDeque,
) -> RegType {
fn mark_cut_var(&mut self, var_num: usize, chunk_num: usize) -> RegType {
match self.get_binding(var_num) {
RegType::Perm(0) => RegType::Perm(self.alloc_perm_var(var_num, term_loc.chunk_num())),
RegType::Perm(0) => RegType::Perm(self.alloc_perm_var(var_num, chunk_num)),
RegType::Temp(0) => {
let cell = Cell::default();
self.mark_var::<Target>(var_num, Level::Shallow, &cell, term_loc, code);
cell.get().norm()
let t = self.alloc_reg_to_non_var();

match &mut self.var_data.records[var_num].allocation {
VarAlloc::Temp {
temp_reg, safety, ..
} => {
*temp_reg = t;
*safety = VarSafetyStatus::GloballyUnneeded;
}
_ => unreachable!(),
};

RegType::Temp(t)
}
r => r,
}
Expand Down

0 comments on commit 5cb207d

Please sign in to comment.