Skip to content

Commit

Permalink
allocate cut variables as temporaries when in non-allocating clause (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mthom committed Nov 28, 2023
1 parent b8ef367 commit de5de0c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
11 changes: 8 additions & 3 deletions src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,25 @@ pub(crate) trait Allocator {
&mut self,
var_num: usize,
lvl: Level,
cell: &'a Cell<VarReg>,
cell: &Cell<VarReg>,
term_loc: GenContext,
code: &mut CodeDeque,
r: RegType,
is_new_var: bool,
);

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

fn mark_var<'a, Target: CompilationTarget<'a>>(
&mut self,
var_num: usize,
lvl: Level,
cell: &'a Cell<VarReg>,
cell: &Cell<VarReg>,
context: GenContext,
code: &mut CodeDeque,
);
Expand Down
8 changes: 6 additions & 2 deletions src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -926,12 +926,16 @@ impl<'b> CodeGenerator<'b> {
match term {
&QueryTerm::GetLevel(var_num) => {
let code = branch_code_stack.code(code);
let r = self.marker.mark_cut_var(var_num, chunk_num);
let r = self
.marker
.mark_cut_var::<QueryInstruction>(var_num, term_loc, code);
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(var_num, chunk_num);
let r = self
.marker
.mark_cut_var::<FactInstruction>(var_num, term_loc, code);

code.push_back(if prev_b {
instr!("get_prev_level", r)
Expand Down
18 changes: 13 additions & 5 deletions src/debray_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ impl Allocator for DebrayAllocator {
&mut self,
var_num: usize,
lvl: Level,
cell: &'a Cell<VarReg>,
cell: &Cell<VarReg>,
term_loc: GenContext,
code: &mut CodeDeque,
) {
Expand Down Expand Up @@ -776,7 +776,7 @@ impl Allocator for DebrayAllocator {
&mut self,
var_num: usize,
lvl: Level,
cell: &'a Cell<VarReg>,
cell: &Cell<VarReg>,
term_loc: GenContext,
code: &mut CodeDeque,
r: RegType,
Expand Down Expand Up @@ -840,10 +840,18 @@ impl Allocator for DebrayAllocator {
self.in_use.insert(o);
}

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

0 comments on commit de5de0c

Please sign in to comment.