Skip to content

Commit 236e902

Browse files
committed
Refine trivial_params allocation
1 parent a710fa9 commit 236e902

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

zjit/src/hir.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5977,16 +5977,14 @@ impl Function {
59775977
.collect();
59785978

59795979
// We only need to update blocks that have params. (Blocks without params cannot be improved)
5980-
let blocks_receiving_params: Vec<BlockId> = blocks.into_iter()
5980+
let blocks_receiving_params: Vec<BlockId> = blocks.iter().copied()
59815981
.filter(|&block_id|
59825982
self.blocks[block_id.to_usize()].params().len() != 0)
59835983
.collect();
59845984

5985-
// NOTE: It is possible that once some block_params are removed, there will be no params.
5986-
// This means that predecessor_blocks or param_blocks could be pruned. This minor optimization can be added if desired.
5987-
// Importantly, we do not keep track of exactly which edges correspond to which blocks. While doing so
5988-
// would allow us to replace our "loop until fixpoint" with a "iterate through the worklist, only checking relevant edges",
5989-
// the construction of the mapping from predecessor edges to blocks seems expensive.
5985+
// Create a vec to represent trivial indices
5986+
let max_params = blocks.iter().copied().map(|id| self.blocks[id.to_usize()].params.len()).max().unwrap_or(0);
5987+
let mut trivial_indices: Vec<usize> = Vec::with_capacity(max_params);
59905988

59915989
let mut changed = true;
59925990

@@ -6020,10 +6018,12 @@ impl Function {
60206018
// 3. Remove trivial params from each CondBranch and Jump that targets the basic block that was just updated
60216019
for block_id in &blocks_receiving_params {
60226020
let block_preds = &param_values[block_id.to_usize()];
6023-
let trivial_indices: Vec<usize> = block_preds.iter().enumerate()
6024-
.filter_map(|(idx, state)|
6025-
matches!(state, ParamValue::One(_)).then_some(idx)
6026-
).collect();
6021+
trivial_indices.clear();
6022+
for (idx, state) in block_preds.iter().enumerate() {
6023+
if let ParamValue::One(_) = state {
6024+
trivial_indices.push(idx);
6025+
}
6026+
}
60276027

60286028
// Replace uses of the trivial params with the concretized value
60296029
for param_index in &trivial_indices {

0 commit comments

Comments
 (0)