Skip to content

Commit b3fad5b

Browse files
committed
PR review
1 parent 6517ab8 commit b3fad5b

2 files changed

Lines changed: 9 additions & 78 deletions

File tree

‎zjit/src/hir.rs‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2594,8 +2594,8 @@ impl Block {
25942594
self.insns.iter()
25952595
}
25962596

2597-
pub fn terminator(&self) -> &InsnId {
2598-
self.insns().last().unwrap()
2597+
pub fn terminator(&self) -> InsnId {
2598+
*self.insns().last().unwrap()
25992599
}
26002600
}
26012601

@@ -6606,7 +6606,7 @@ impl Function {
66066606
// Collect blocks that terminate with Jump or CondBranch instructions that pass at least one block param along.
66076607
let blocks_sending_params: Vec<BlockId> = blocks.iter().copied()
66086608
.filter(|&block_id|
6609-
self.resolve(*self.blocks[block_id].terminator()).insn(self).outgoing_edges().any(|edge| !edge.args.is_empty()))
6609+
self.resolve(self.blocks[block_id].terminator()).insn(self).outgoing_edges().any(|edge| !edge.args.is_empty()))
66106610
.collect();
66116611

66126612
// We only need to update blocks that have params. (Blocks without params cannot be improved)
@@ -6638,7 +6638,7 @@ impl Function {
66386638
for &block_id in &blocks_sending_params {
66396639
// Use the results of abstract interpretation to update the states
66406640
// Perform abstract interpretation
6641-
let edges = self.resolve(*self.blocks[block_id].terminator()).insn(self).outgoing_edges();
6641+
let edges = self.resolve(self.blocks[block_id].terminator()).insn(self).outgoing_edges();
66426642
for BranchEdge { target: target_block_id, args: params } in edges {
66436643
for (i, param) in params.iter().enumerate() {
66446644
let param = self.find_id(*param);
@@ -6689,7 +6689,7 @@ impl Function {
66896689

66906690
// Update the terminators (basic blocks can only branch at the terminator. This is where block params are passed)
66916691
for jump_block_id in &blocks_sending_params {
6692-
let edges = self.resolve(*self.blocks[*jump_block_id].terminator()).insn_mut(self).outgoing_edges_mut();
6692+
let edges = self.resolve(self.blocks[*jump_block_id].terminator()).insn_mut(self).outgoing_edges_mut();
66936693
for edge in edges {
66946694
if edge.target == *block_id {
66956695
prune_vec_by_indices(&mut edge.args, &trivial_indices);
@@ -6728,8 +6728,7 @@ impl Function {
67286728
loop {
67296729
for (rpo_index, &block_id) in rpo.iter().enumerate() {
67306730
let mut block_cache: HashMap<Key, InsnId> = HashMap::new();
6731-
// Populate the block cache with information from predecessors
6732-
// If all predecessors contain the same entry and value, add it to the map
6731+
// Set block_cache equal to the intersection of cached insns of all predecessors
67336732
match cfi.predecessors(block_id) {
67346733
[] => {},
67356734
[head] => {
@@ -6799,9 +6798,9 @@ impl Function {
67996798
continue
68006799
}
68016800
}
6802-
Entry::Vacant(_) => {
6801+
Entry::Vacant(entry) => {
68036802
// If the value has not been accessed, cache a copy to optimize future loads or stores.
6804-
block_cache.insert(key, insn_id);
6803+
entry.insert(insn_id);
68056804
}
68066805
}
68076806
insn_id
@@ -6829,7 +6828,7 @@ impl Function {
68296828
self.blocks[block_id].insns = new_insns;
68306829

68316830
// Check for back edges
6832-
for edge in self.resolve(*self.blocks[block_id].terminator()).insn(self).outgoing_edges() {
6831+
for edge in self.resolve(self.blocks[block_id].terminator()).insn(self).outgoing_edges() {
68336832
if rpo_order[edge.target] <= rpo_index {
68346833
has_back_edge |= true;
68356834
}

‎zjit/src/hir/tests.rs‎

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -6808,74 +6808,6 @@ pub(crate) mod hir_build_tests {
68086808
Return v39
68096809
");
68106810
}
6811-
6812-
#[test]
6813-
fn test_global_load_elimination() {
6814-
set_call_threshold(3);
6815-
eval(r#"
6816-
class TestObj
6817-
def initialize(value)
6818-
@value = value
6819-
end
6820-
6821-
def read(val)
6822-
even = val.even?
6823-
a = @value
6824-
even ? a : @value + 1
6825-
end
6826-
end
6827-
6828-
obj = TestObj.new(5)
6829-
obj.read(1)
6830-
obj.read(2)
6831-
"#);
6832-
6833-
assert_snapshot!(
6834-
hir_string_proc("TestObj.instance_method(:read)"),
6835-
@"
6836-
fn read@<compiled>:8:
6837-
bb1():
6838-
EntryPoint interpreter
6839-
v1:BasicObject = LoadSelf
6840-
v2:CPtr = LoadSP
6841-
v3:BasicObject = LoadField v2, :val@0x1000
6842-
v4:NilClass = Const Value(nil)
6843-
v5:NilClass = Const Value(nil)
6844-
Jump bb3(v1, v3, v4, v5)
6845-
bb2():
6846-
EntryPoint JIT(0)
6847-
v8:BasicObject = LoadArg :self@0
6848-
v9:BasicObject = LoadArg :val@1
6849-
v10:NilClass = Const Value(nil)
6850-
v11:NilClass = Const Value(nil)
6851-
Jump bb3(v8, v9, v10, v11)
6852-
bb3(v13:BasicObject, v14:BasicObject, v15:NilClass, v16:NilClass):
6853-
v21:BasicObject = Send v14, :even? # SendFallbackReason: Uncategorized(opt_send_without_block)
6854-
PatchPoint NoEPEscape(read)
6855-
v27:HeapBasicObject = GuardType v13, HeapBasicObject
6856-
v28:CShape = LoadField v27, :shape_id@0x1001
6857-
v29:CShape[0x1002] = GuardBitEquals v28, CShape(0x1002) recompile
6858-
v30:BasicObject = LoadField v27, :@value@0x1003
6859-
PatchPoint NoEPEscape(read)
6860-
v37:CBool = Test v21
6861-
v38:Falsy = RefineType v21, Falsy
6862-
CondBranch v37, bb5(), bb4(v13, v14, v38, v30)
6863-
bb5():
6864-
v40:Truthy = RefineType v21, Truthy
6865-
CheckInterrupts
6866-
Return v30
6867-
bb4(v46:BasicObject, v47:BasicObject, v48:Falsy, v49:BasicObject):
6868-
v52:HeapBasicObject = GuardType v46, HeapBasicObject
6869-
v53:CShape = LoadField v52, :shape_id@0x1001
6870-
v54:CShape[0x1002] = GuardBitEquals v53, CShape(0x1002) recompile
6871-
v55:BasicObject = LoadField v52, :@value@0x1003
6872-
v57:Fixnum[1] = Const Value(1)
6873-
v60:BasicObject = Send v55, :+, v57 # SendFallbackReason: Uncategorized(opt_plus)
6874-
CheckInterrupts
6875-
Return v60
6876-
"
6877-
);
6878-
}
68796811
}
68806812

68816813
/// Test successor and predecessor set computations.

0 commit comments

Comments
 (0)