Skip to content

Commit a710fa9

Browse files
committed
Update block indexing
1 parent 38e8174 commit a710fa9

2 files changed

Lines changed: 11 additions & 17 deletions

File tree

zjit/src/hir.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5941,7 +5941,7 @@ impl Function {
59415941
}
59425942

59435943
fn block_terminator(fun: &Function, block_id: BlockId) -> InsnId {
5944-
*fun.blocks[block_id.0].insns().last().unwrap()
5944+
*fun.blocks[block_id.to_usize() as usize].insns().last().unwrap()
59455945
}
59465946

59475947
macro_rules! edges_of {
@@ -5956,12 +5956,12 @@ impl Function {
59565956

59575957
fn outgoing_edges(fun: &Function, block_id: BlockId) -> impl Iterator<Item = &BranchEdge> {
59585958
let insn_id = block_terminator(fun, block_id);
5959-
edges_of!(&fun.insns[insn_id.0])
5959+
edges_of!(&fun.insns[insn_id.to_usize()])
59605960
}
59615961

59625962
fn outgoing_edges_mut(fun: &mut Function, block_id: BlockId) -> impl Iterator<Item = &mut BranchEdge> {
59635963
let insn_id = block_terminator(fun, block_id);
5964-
edges_of!(&mut fun.insns[insn_id.0])
5964+
edges_of!(&mut fun.insns[insn_id.to_usize()])
59655965
}
59665966

59675967
// Instantiate the domain for abstract interpretation.
@@ -5979,7 +5979,7 @@ impl Function {
59795979
// We only need to update blocks that have params. (Blocks without params cannot be improved)
59805980
let blocks_receiving_params: Vec<BlockId> = blocks.into_iter()
59815981
.filter(|&block_id|
5982-
self.blocks[block_id.0].params().len() != 0)
5982+
self.blocks[block_id.to_usize()].params().len() != 0)
59835983
.collect();
59845984

59855985
// NOTE: It is possible that once some block_params are removed, there will be no params.
@@ -6005,10 +6005,10 @@ impl Function {
60056005
for (i, param) in params.iter().enumerate() {
60066006
let param = self.find_id(*param);
60076007
// If the param is the same as passed into the block, it is a self loop and provides no new predecessor information.
6008-
if param == self.find_id(self.blocks[block_id.0].params[i]) {
6008+
if param == self.find_id(self.blocks[block_id.to_usize()].params[i]) {
60096009
continue
60106010
}
6011-
param_values[block_id.0][i].update(param);
6011+
param_values[block_id.to_usize()][i].update(param);
60126012
}
60136013
}
60146014
}
@@ -6019,7 +6019,7 @@ impl Function {
60196019
// 2. Remove trivial params from the basic block definition
60206020
// 3. Remove trivial params from each CondBranch and Jump that targets the basic block that was just updated
60216021
for block_id in &blocks_receiving_params {
6022-
let block_preds = &param_values[block_id.0];
6022+
let block_preds = &param_values[block_id.to_usize()];
60236023
let trivial_indices: Vec<usize> = block_preds.iter().enumerate()
60246024
.filter_map(|(idx, state)|
60256025
matches!(state, ParamValue::One(_)).then_some(idx)
@@ -6028,13 +6028,13 @@ impl Function {
60286028
// Replace uses of the trivial params with the concretized value
60296029
for param_index in &trivial_indices {
60306030
if let ParamValue::One(insn_id) = block_preds[*param_index] {
6031-
self.make_equal_to(self.blocks[block_id.0].params[*param_index], insn_id);
6031+
self.make_equal_to(self.blocks[block_id.to_usize()].params[*param_index], insn_id);
60326032
changed = true;
60336033
}
60346034
}
60356035

60366036
// Update the block
6037-
prune_vec_by_indices(&mut self.blocks[block_id.0].params, &trivial_indices);
6037+
prune_vec_by_indices(&mut self.blocks[block_id.to_usize()].params, &trivial_indices);
60386038

60396039
// Update the terminators (basic blocks can only branch at the terminator. This is where block params are passed)
60406040
for jump_block_id in &blocks_sending_params {

zjit/src/hir/opt_tests.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21534,19 +21534,13 @@ mod hir_opt_tests {
2153421534
PatchPoint NoEPEscape(test)
2153521535
v44:CBool = Test v15
2153621536
v45:Falsy = RefineType v15, Falsy
21537-
CondBranch v44, bb5(), bb4(v13, v14, v45, v37)
21538-
v42:CBool = Test v15
21539-
v43:Falsy = RefineType v15, Falsy
21540-
CondBranch v42, bb5(), bb4()
21537+
CondBranch v44, bb5(), bb4()
2154121538
bb5():
2154221539
v47:Truthy = RefineType v15, Truthy
2154321540
CheckInterrupts
2154421541
Return v37
21545-
bb4(v54:BasicObject, v55:BasicObject, v56:Falsy, v57:BasicObject):
21546-
v61:NilClass = Const Value(nil)
21547-
Return v35
2154821542
bb4():
21549-
v59:NilClass = Const Value(nil)
21543+
v61:NilClass = Const Value(nil)
2155021544
CheckInterrupts
2155121545
Return v61
2155221546
");

0 commit comments

Comments
 (0)