Skip to content

Commit 3845bbb

Browse files
committed
[Truffle] - Using CompilerDirectives.injectBranchProbability in the DoWhile nodes
1 parent d0d141a commit 3845bbb

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

core/src/main/java/org/jruby/truffle/nodes/control/DoWhileNode.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ public class DoWhileNode extends RubyNode {
3232
@Child protected BooleanCastNode condition;
3333
@Child protected RubyNode body;
3434

35+
@CompilerDirectives.CompilationFinal private int thenCount;
36+
@CompilerDirectives.CompilationFinal private int elseCount;
37+
38+
private final BranchProfile thenProfile = new BranchProfile();
39+
private final BranchProfile elseProfile = new BranchProfile();
40+
3541
private final BranchProfile breakProfile = new BranchProfile();
3642
private final BranchProfile nextProfile = new BranchProfile();
3743
private final BranchProfile redoProfile = new BranchProfile();
@@ -66,10 +72,17 @@ public Object execute(VirtualFrame frame) {
6672
redoProfile.enter();
6773
}
6874
}
69-
70-
if (condition.executeBoolean(frame)) {
75+
if (CompilerDirectives.injectBranchProbability((double) thenCount / (double) (thenCount + elseCount), condition.executeBoolean(frame))) {
76+
if (CompilerDirectives.inInterpreter()) {
77+
thenCount++;
78+
}
79+
thenProfile.enter();
7180
continue outer;
7281
} else {
82+
if (CompilerDirectives.inInterpreter()) {
83+
elseCount++;
84+
}
85+
elseProfile.enter();
7386
break outer;
7487
}
7588
}

0 commit comments

Comments
 (0)