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.
This commit is contained in:
Trevor Elliott
2023-02-07 21:21:35 -08:00
committed by GitHub
parent 7bf89683e9
commit b0b3f67cb0
12 changed files with 25 additions and 24 deletions

View File

@@ -5,12 +5,11 @@ use crate::ir;
use crate::ir::builder::ReplaceBuilder;
use crate::ir::dynamic_type::{DynamicTypeData, DynamicTypes};
use crate::ir::instructions::{CallInfo, InstructionData};
use crate::ir::{types, ConstantData, ConstantPool, Immediate};
use crate::ir::{
Block, BlockCall, DynamicType, FuncRef, Inst, SigRef, Signature, Type, Value,
types, Block, BlockCall, ConstantData, ConstantPool, DynamicType, ExtFuncData, FuncRef,
Immediate, Inst, JumpTables, RelSourceLoc, SigRef, Signature, Type, Value,
ValueLabelAssignments, ValueList, ValueListPool,
};
use crate::ir::{ExtFuncData, RelSourceLoc};
use crate::packed_option::ReservedValue;
use crate::write::write_operands;
use core::fmt;
@@ -144,6 +143,9 @@ pub struct DataFlowGraph {
/// Stores large immediates that otherwise will not fit on InstructionData
pub immediates: PrimaryMap<Immediate, ConstantData>,
/// Jump tables used in this function.
pub jump_tables: JumpTables,
}
impl DataFlowGraph {
@@ -162,6 +164,7 @@ impl DataFlowGraph {
values_labels: None,
constants: ConstantPool::new(),
immediates: PrimaryMap::new(),
jump_tables: JumpTables::new(),
}
}
@@ -179,6 +182,7 @@ impl DataFlowGraph {
self.values_labels = None;
self.constants.clear();
self.immediates.clear();
self.jump_tables.clear();
}
/// Get the total number of instructions created in this function, whether they are currently

View File

@@ -7,7 +7,7 @@ use crate::entity::{PrimaryMap, SecondaryMap};
use crate::ir::{
self, Block, DataFlowGraph, DynamicStackSlot, DynamicStackSlotData, DynamicStackSlots,
DynamicType, ExtFuncData, FuncRef, GlobalValue, GlobalValueData, Inst, InstructionData,
JumpTable, JumpTableData, JumpTables, Layout, Opcode, SigRef, Signature, SourceLocs, StackSlot,
JumpTable, JumpTableData, Layout, Opcode, SigRef, Signature, SourceLocs, StackSlot,
StackSlotData, StackSlots, Table, TableData, Type,
};
use crate::isa::CallConv;
@@ -170,9 +170,6 @@ pub struct FunctionStencil {
/// Tables referenced.
pub tables: PrimaryMap<ir::Table, ir::TableData>,
/// Jump tables used in this function.
pub jump_tables: JumpTables,
/// Data flow graph containing the primary definition of all instructions, blocks and values.
pub dfg: DataFlowGraph,
@@ -200,7 +197,6 @@ impl FunctionStencil {
self.dynamic_stack_slots.clear();
self.global_values.clear();
self.tables.clear();
self.jump_tables.clear();
self.dfg.clear();
self.layout.clear();
self.srclocs.clear();
@@ -209,7 +205,7 @@ impl FunctionStencil {
/// Creates a jump table in the function, to be used by `br_table` instructions.
pub fn create_jump_table(&mut self, data: JumpTableData) -> JumpTable {
self.jump_tables.push(data)
self.dfg.jump_tables.push(data)
}
/// Creates a sized stack slot in the function, to be used by `stack_load`, `stack_store`
@@ -304,7 +300,7 @@ impl FunctionStencil {
destination: default_dest,
..
} => {
self.jump_tables[*table].iter_mut().for_each(|entry| {
self.dfg.jump_tables[*table].iter_mut().for_each(|entry| {
if *entry == old_dest {
*entry = new_dest;
}
@@ -433,7 +429,6 @@ impl Function {
dynamic_stack_slots: DynamicStackSlots::new(),
global_values: PrimaryMap::new(),
tables: PrimaryMap::new(),
jump_tables: PrimaryMap::new(),
dfg: DataFlowGraph::new(),
layout: Layout::new(),
srclocs: SecondaryMap::new(),