Skip to content

Commit

Permalink
forbid spilling arg
Browse files Browse the repository at this point in the history
  • Loading branch information
glyh committed Oct 23, 2024
1 parent 4f09408 commit eb44efb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
5 changes: 2 additions & 3 deletions src/js/clops2js.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,11 @@ pub fn JsEmitter::emit(self : JsEmitter) -> String {
output += line_start
// B. emit all functions
output += line_start + "const compiled_functions = ["

let line_start = "\n "
// 1. emit root
output += line_start + "function() { // root"
output += self.indent().indent().emit_cps(self.clops.root)
output += line_start + "},"

// 2. emit all functions
for label in self.lid2label {
let cur_fn = self.clops.fnblocks[label].unwrap()
Expand All @@ -197,7 +196,7 @@ pub fn JsEmitter::emit(self : JsEmitter) -> String {
let args_with_closure_emitted = args_with_closure.map(emit_var).join(", ")
output += line_start +
"function(\{args_with_closure_emitted}) { // \{label}"
// i. emit body
// ii. emit body
output += self.indent().indent().emit_cps(cur_fn.body)
output += line_start + "},"
}
Expand Down
6 changes: 5 additions & 1 deletion src/riscv/codegen.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ fn CodegenBlock::new(
let params = cfg.fn_args[name_var].unwrap()
for param in params {
let alloc_reg = allocation[param].unwrap()
dirtied.insert(alloc_reg)
if cfg.spilled.contains(param) {
@util.die("param \{param} of fn \{name_var} spilled")
} else {
dirtied.insert(alloc_reg)
}
}

// 3. collect spilled vars
Expand Down
12 changes: 10 additions & 2 deletions src/riscv/reg_allocation.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,22 @@ fn reg_allocate_on_fn(
vars_f, graph_f, alloc_fregs, allocation_f, simplify_stack_f,
)
if should_spill_i {
let vars_i_spillable = vars_i
.iter()
.filter(fn(var) { not(allocation_i.contains(var)) })
|> @hashset.from_iter()
let i_spilled = reg_spill_fn(
input, vars_i, simplify_stack_i, graph_i, fn_label,
input, vars_i_spillable, simplify_stack_i, graph_i, fn_label,
)
spilled_set.insert(i_spilled)
}
if should_spill_f {
let vars_f_spillable = vars_i
.iter()
.filter(fn(var) { not(allocation_f.contains(var)) })
|> @hashset.from_iter()
let f_spilled = reg_spill_fn(
input, vars_f, simplify_stack_f, graph_f, fn_label,
input, vars_f_spillable, simplify_stack_f, graph_f, fn_label,
)
spilled_set.insert(f_spilled)
}
Expand Down
6 changes: 3 additions & 3 deletions src/riscv/reg_spill.mbt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
fn reg_spill_fn(
cfg : @ssacfg.SsaCfg,
all_vars : @hashset.T[Var],
can_allocate : Array[Var],
all_vars_not_preallocated : @hashset.T[Var],
can_allocate : Array[Var], // vars that can be allocated but not yet
interference : InterferenceGraph,
fn_name : Var
) -> Var {
let spill_candidates = all_vars
let spill_candidates = all_vars_not_preallocated
.iter()
.filter(fn(var) { not(can_allocate.contains(var)) })
.collect()
Expand Down

0 comments on commit eb44efb

Please sign in to comment.