Skip to content

Commit b0b3f67

Browse files
authored
Move jump tables to the DataFlowGraph (#5745)
Move the storage for jump tables off of FunctionStencil and onto DataFlowGraph. This change is in service of #5731, making it easier to access the jump table data in the context of helpers like inst_values.
1 parent 7bf8968 commit b0b3f67

File tree

12 files changed

+25
-24
lines changed

12 files changed

+25
-24
lines changed

cranelift/codegen/src/dominator_tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ impl DominatorTree {
367367
destination: dest,
368368
..
369369
} => {
370-
for succ in func.jump_tables[*jt].iter() {
370+
for succ in func.stencil.dfg.jump_tables[*jt].iter() {
371371
self.push_if_unseen(*succ);
372372
}
373373
self.push_if_unseen(*dest);

cranelift/codegen/src/flowgraph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl ControlFlowGraph {
137137
} => {
138138
self.add_edge(block, inst, *dest);
139139

140-
for dest in func.jump_tables[*jt].iter() {
140+
for dest in func.stencil.dfg.jump_tables[*jt].iter() {
141141
self.add_edge(block, inst, *dest);
142142
}
143143
}

cranelift/codegen/src/inst_predicates.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ pub(crate) fn visit_block_succs<F: FnMut(Inst, Block, bool)>(
199199
// so it is not part of the table.
200200
visit(inst, *dest, false);
201201

202-
for &dest in f.jump_tables[*table].as_slice() {
202+
for &dest in f.stencil.dfg.jump_tables[*table].as_slice() {
203203
visit(inst, dest, true);
204204
}
205205
}

cranelift/codegen/src/ir/dfg.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ use crate::ir;
55
use crate::ir::builder::ReplaceBuilder;
66
use crate::ir::dynamic_type::{DynamicTypeData, DynamicTypes};
77
use crate::ir::instructions::{CallInfo, InstructionData};
8-
use crate::ir::{types, ConstantData, ConstantPool, Immediate};
98
use crate::ir::{
10-
Block, BlockCall, DynamicType, FuncRef, Inst, SigRef, Signature, Type, Value,
9+
types, Block, BlockCall, ConstantData, ConstantPool, DynamicType, ExtFuncData, FuncRef,
10+
Immediate, Inst, JumpTables, RelSourceLoc, SigRef, Signature, Type, Value,
1111
ValueLabelAssignments, ValueList, ValueListPool,
1212
};
13-
use crate::ir::{ExtFuncData, RelSourceLoc};
1413
use crate::packed_option::ReservedValue;
1514
use crate::write::write_operands;
1615
use core::fmt;
@@ -144,6 +143,9 @@ pub struct DataFlowGraph {
144143

145144
/// Stores large immediates that otherwise will not fit on InstructionData
146145
pub immediates: PrimaryMap<Immediate, ConstantData>,
146+
147+
/// Jump tables used in this function.
148+
pub jump_tables: JumpTables,
147149
}
148150

149151
impl DataFlowGraph {
@@ -162,6 +164,7 @@ impl DataFlowGraph {
162164
values_labels: None,
163165
constants: ConstantPool::new(),
164166
immediates: PrimaryMap::new(),
167+
jump_tables: JumpTables::new(),
165168
}
166169
}
167170

@@ -179,6 +182,7 @@ impl DataFlowGraph {
179182
self.values_labels = None;
180183
self.constants.clear();
181184
self.immediates.clear();
185+
self.jump_tables.clear();
182186
}
183187

184188
/// Get the total number of instructions created in this function, whether they are currently

cranelift/codegen/src/ir/function.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::entity::{PrimaryMap, SecondaryMap};
77
use crate::ir::{
88
self, Block, DataFlowGraph, DynamicStackSlot, DynamicStackSlotData, DynamicStackSlots,
99
DynamicType, ExtFuncData, FuncRef, GlobalValue, GlobalValueData, Inst, InstructionData,
10-
JumpTable, JumpTableData, JumpTables, Layout, Opcode, SigRef, Signature, SourceLocs, StackSlot,
10+
JumpTable, JumpTableData, Layout, Opcode, SigRef, Signature, SourceLocs, StackSlot,
1111
StackSlotData, StackSlots, Table, TableData, Type,
1212
};
1313
use crate::isa::CallConv;
@@ -170,9 +170,6 @@ pub struct FunctionStencil {
170170
/// Tables referenced.
171171
pub tables: PrimaryMap<ir::Table, ir::TableData>,
172172

173-
/// Jump tables used in this function.
174-
pub jump_tables: JumpTables,
175-
176173
/// Data flow graph containing the primary definition of all instructions, blocks and values.
177174
pub dfg: DataFlowGraph,
178175

@@ -200,7 +197,6 @@ impl FunctionStencil {
200197
self.dynamic_stack_slots.clear();
201198
self.global_values.clear();
202199
self.tables.clear();
203-
self.jump_tables.clear();
204200
self.dfg.clear();
205201
self.layout.clear();
206202
self.srclocs.clear();
@@ -209,7 +205,7 @@ impl FunctionStencil {
209205

210206
/// Creates a jump table in the function, to be used by `br_table` instructions.
211207
pub fn create_jump_table(&mut self, data: JumpTableData) -> JumpTable {
212-
self.jump_tables.push(data)
208+
self.dfg.jump_tables.push(data)
213209
}
214210

215211
/// Creates a sized stack slot in the function, to be used by `stack_load`, `stack_store`
@@ -304,7 +300,7 @@ impl FunctionStencil {
304300
destination: default_dest,
305301
..
306302
} => {
307-
self.jump_tables[*table].iter_mut().for_each(|entry| {
303+
self.dfg.jump_tables[*table].iter_mut().for_each(|entry| {
308304
if *entry == old_dest {
309305
*entry = new_dest;
310306
}
@@ -433,7 +429,6 @@ impl Function {
433429
dynamic_stack_slots: DynamicStackSlots::new(),
434430
global_values: PrimaryMap::new(),
435431
tables: PrimaryMap::new(),
436-
jump_tables: PrimaryMap::new(),
437432
dfg: DataFlowGraph::new(),
438433
layout: Layout::new(),
439434
srclocs: SecondaryMap::new(),

cranelift/codegen/src/unreachable_code.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn eliminate_unreachable_code(
2121
) {
2222
let _tt = timing::unreachable_code();
2323
let mut pos = FuncCursor::new(func);
24-
let mut used_tables = EntitySet::with_capacity(pos.func.jump_tables.len());
24+
let mut used_tables = EntitySet::with_capacity(pos.func.stencil.dfg.jump_tables.len());
2525
while let Some(block) = pos.next_block() {
2626
if domtree.is_reachable(block) {
2727
let inst = pos.func.layout.last_inst(block).unwrap();
@@ -50,7 +50,7 @@ pub fn eliminate_unreachable_code(
5050
pos.func.layout.remove_block(block);
5151
}
5252

53-
for (table, jt_data) in func.jump_tables.iter_mut() {
53+
for (table, jt_data) in func.stencil.dfg.jump_tables.iter_mut() {
5454
if !used_tables.contains(table) {
5555
jt_data.clear();
5656
}

cranelift/codegen/src/verifier/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ impl<'a> Verifier<'a> {
447447
}
448448

449449
fn verify_jump_tables(&self, errors: &mut VerifierErrors) -> VerifierStepResult<()> {
450-
for (jt, jt_data) in &self.func.jump_tables {
450+
for (jt, jt_data) in &self.func.stencil.dfg.jump_tables {
451451
for &block in jt_data.iter() {
452452
self.verify_block(jt, block, errors)?;
453453
}
@@ -854,7 +854,7 @@ impl<'a> Verifier<'a> {
854854
j: JumpTable,
855855
errors: &mut VerifierErrors,
856856
) -> VerifierStepResult<()> {
857-
if !self.func.jump_tables.is_valid(j) {
857+
if !self.func.stencil.dfg.jump_tables.is_valid(j) {
858858
errors.nonfatal((
859859
inst,
860860
self.context(inst),
@@ -1344,7 +1344,7 @@ impl<'a> Verifier<'a> {
13441344
),
13451345
));
13461346
}
1347-
for block in self.func.jump_tables[*table].iter() {
1347+
for block in self.func.stencil.dfg.jump_tables[*table].iter() {
13481348
let arg_count = self.func.dfg.num_block_params(*block);
13491349
if arg_count != 0 {
13501350
return errors.nonfatal((

cranelift/codegen/src/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub trait FuncWriter {
8282
}
8383
}
8484

85-
for (jt, jt_data) in &func.jump_tables {
85+
for (jt, jt_data) in &func.stencil.dfg.jump_tables {
8686
any = true;
8787
self.write_entity_definition(w, func, jt.into(), jt_data)?;
8888
}

cranelift/frontend/src/frontend.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ impl<'short, 'long> InstBuilderBase<'short> for FuncInstBuilder<'short, 'long> {
139139
for dest_block in self
140140
.builder
141141
.func
142+
.stencil
143+
.dfg
142144
.jump_tables
143145
.get(*table)
144146
.expect("you are referencing an undeclared jump table")

cranelift/frontend/src/ssa.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ impl SSABuilder {
601601
let middle_block = dfg.blocks.add();
602602
func.stencil.layout.append_block(middle_block);
603603

604-
let table = &mut func.stencil.jump_tables[*jt];
604+
let table = &mut dfg.jump_tables[*jt];
605605
for block in table.iter_mut() {
606606
if *block == dest_block {
607607
*block = middle_block;

0 commit comments

Comments
 (0)