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

regalloc: fail when some reg bool variables remain unallocated #313

Merged
merged 1 commit into from
Jan 4, 2023
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
([PR #311](https://github.com/jasmin-lang/jasmin/pull/311);
fixes [#309](https://github.com/jasmin-lang/jasmin/issues/309)).

- Register allocation fails when some `reg bool` variables remain unallocated
([PR #313](https://github.com/jasmin-lang/jasmin/pull/313);
fixes [#310](https://github.com/jasmin-lang/jasmin/issues/310)).

## Other changes

- Explicit if-then-else in flag combinations is no longer supported
Expand Down
13 changes: 12 additions & 1 deletion compiler/src/regalloc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,15 @@ let two_phase_coloring
A.set i y a
) schedule

let check_allocated
(vars: (int, var list) Hashtbl.t)
(a: A.allocation) : unit =
match Hashtbl.fold (fun i x m -> if A.mem i a then m else x @ m) vars [] with
| [] -> ()
| m ->
hierror_reg ~loc:Lnone "variables { %a } remain unallocated"
(pp_list "; " (Printer.pp_var ~debug:true)) m

let greedy_allocation
(vars: int Hv.t)
(nv: int) (cnf: conflicts)
Expand All @@ -720,6 +729,7 @@ let greedy_allocation
let scalars : (int, var list) Hashtbl.t = Hashtbl.create nv in
let extra_scalars : (int, var list) Hashtbl.t = Hashtbl.create nv in
let vectors : (int, var list) Hashtbl.t = Hashtbl.create nv in
let flags : (int, var list) Hashtbl.t = Hashtbl.create nv in
let push_var tbl i v =
match Hashtbl.find tbl i with
| old -> Hashtbl.replace tbl i (v :: old)
Expand All @@ -731,12 +741,13 @@ let greedy_allocation
if reg_kind v.v_kind = Normal then push_var scalars i v
else push_var extra_scalars i v
| Vector -> push_var vectors i v
| Flag
| Flag -> push_var flags i v
| Unknown _ -> ()
) vars;
two_phase_coloring Arch.allocatable_vars scalars cnf fr a;
two_phase_coloring Arch.extra_allocatable_vars extra_scalars cnf fr a;
two_phase_coloring Arch.xmm_allocatable_vars vectors cnf fr a;
check_allocated flags a;
()

let var_subst_of_allocation (vars: int Hv.t)
Expand Down
15 changes: 15 additions & 0 deletions compiler/tests/fail/register_allocation/bug_310.jazz
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export
fn test(reg u64 x y) -> reg u64 {
reg u64 r;
r = y;
reg bool valid;
if x > 56 {
valid = true;
} else {
valid = false;
}
if valid {
r = x;
}
return r;
}