From bdcc06eb15ad86c5725176b8b2cd6ad28b6c3e20 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 26 Oct 2018 06:39:30 -0700 Subject: [PATCH] When lowering br_table to branches, delete the old jump tables. This prevents codegen from emitting unused readonly data. --- .../filetests/legalizer/br_table_cond.clif | 40 +++++++++++++++++++ lib/codegen/src/legalizer/mod.rs | 5 +++ 2 files changed, 45 insertions(+) create mode 100644 cranelift/filetests/legalizer/br_table_cond.clif diff --git a/cranelift/filetests/legalizer/br_table_cond.clif b/cranelift/filetests/legalizer/br_table_cond.clif new file mode 100644 index 0000000000..5b7beb3253 --- /dev/null +++ b/cranelift/filetests/legalizer/br_table_cond.clif @@ -0,0 +1,40 @@ +test legalizer +set probestack_enabled=false +set jump_tables_enabled=false +target x86_64 + +; Test that when jump_tables_enables is false, all jump tables are eliminated. + +function u0:0(i64 vmctx) baldrdash { + gv0 = vmctx + gv1 = iadd_imm.i64 gv0, 48 + jt0 = jump_table [ebb2, ebb2, ebb7] + jt1 = jump_table [ebb8, ebb8] + +ebb0(v0: i64): + jump ebb5 + +ebb5: + v1 = global_value.i64 gv1 + v2 = load.i64 v1 + trapnz v2, interrupt + v3 = iconst.i32 0 + br_table v3, ebb3, jt0 + +ebb7: + v4 = iconst.i32 0 + br_table v4, ebb3, jt1 + +ebb8: + jump ebb5 + +ebb3: + jump ebb2 + +ebb2: + jump ebb1 + +ebb1: + fallthrough_return +} +; not: jump_table diff --git a/lib/codegen/src/legalizer/mod.rs b/lib/codegen/src/legalizer/mod.rs index e52889c672..b552934289 100644 --- a/lib/codegen/src/legalizer/mod.rs +++ b/lib/codegen/src/legalizer/mod.rs @@ -110,6 +110,11 @@ pub fn legalize_function(func: &mut ir::Function, cfg: &mut ControlFlowGraph, is } } } + + // Now that we've lowered all br_tables, we don't need the jump tables anymore. + if !isa.flags().jump_tables_enabled() { + pos.func.jump_tables.clear(); + } } // Include legalization patterns that were generated by `gen_legalizer.py` from the `XForms` in