Move default blocks into jump tables (#5756)

Move the default block off of the br_table instrution, and into the JumpTable that it references.
This commit is contained in:
Trevor Elliott
2023-02-10 08:53:30 -08:00
committed by GitHub
parent 49613be393
commit d99783fc91
21 changed files with 118 additions and 175 deletions

View File

@@ -2515,7 +2515,7 @@
;; `targets` contains the default target with the list of branch targets
;; concatenated.
(rule (lower_branch (br_table idx _ _) targets)
(rule (lower_branch (br_table idx _) targets)
(let ((jt_size u32 (targets_jt_size targets))
(_ InstOutput (side_effect
(emit_island (targets_jt_space targets))))

View File

@@ -361,11 +361,10 @@ mod test {
let mut pos = FuncCursor::new(&mut func);
pos.insert_block(bb0);
let mut jt_data = JumpTableData::new();
jt_data.push_entry(bb1);
jt_data.push_entry(bb2);
let jt = pos.func.create_jump_table(jt_data);
pos.ins().br_table(arg0, bb3, jt);
let jt = pos
.func
.create_jump_table(JumpTableData::new(bb3, vec![bb1, bb2]));
pos.ins().br_table(arg0, jt);
pos.insert_block(bb1);
let v1 = pos.ins().iconst(I32, 1);

View File

@@ -1942,7 +1942,7 @@
(extern constructor lower_br_table lower_br_table)
(rule
(lower_branch (br_table index _ _) targets)
(lower_branch (br_table index _) targets)
(lower_br_table index targets))
(decl load_ra () Reg)

View File

@@ -3725,7 +3725,7 @@
;; Jump table. `targets` contains the default target followed by the
;; list of branch targets per index value.
(rule (lower_branch (br_table val_idx _ _) targets)
(rule (lower_branch (br_table val_idx _) targets)
(let ((idx Reg (put_in_reg_zext64 val_idx))
;; Bounds-check the index and branch to default.
;; This is an internal branch that is not a terminator insn.

View File

@@ -2942,7 +2942,7 @@
;; Rules for `br_table` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(rule (lower_branch (br_table idx @ (value_type ty) _ _) (jump_table_targets default_target jt_targets))
(rule (lower_branch (br_table idx @ (value_type ty) _) (jump_table_targets default_target jt_targets))
(emit_side_effect (jmp_table_seq ty idx default_target jt_targets)))
;; Rules for `select_spectre_guard` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View File

@@ -408,11 +408,10 @@ mod test {
let mut pos = FuncCursor::new(&mut func);
pos.insert_block(bb0);
let mut jt_data = JumpTableData::new();
jt_data.push_entry(bb1);
jt_data.push_entry(bb2);
let jt = pos.func.create_jump_table(jt_data);
pos.ins().br_table(arg0, bb3, jt);
let jt = pos
.func
.create_jump_table(JumpTableData::new(bb3, vec![bb1, bb2]));
pos.ins().br_table(arg0, jt);
pos.insert_block(bb1);
let v1 = pos.ins().iconst(I32, 1);