comparison graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/controlflow/SLIfNode.java @ 16829:e3724f25056a

SL: use the new IntegerConditionProfile in simple language.
author Christian Humer <christian.humer@gmail.com>
date Thu, 14 Aug 2014 13:11:47 +0200
parents abe7128ca473
children 226552569e34
comparison
equal deleted inserted replaced
16828:2834af86f398 16829:e3724f25056a
44 44
45 /** Statement (or {@link SLBlockNode block}) executed when the condition is false. */ 45 /** Statement (or {@link SLBlockNode block}) executed when the condition is false. */
46 @Child private SLStatementNode elsePartNode; 46 @Child private SLStatementNode elsePartNode;
47 47
48 /** 48 /**
49 * Profiling information, collected by the interpreter, capturing whether the then-branch was 49 * Profiling information, collected by the interpreter, capturing the profiling information of
50 * used (analogously for the {@link #elseTaken else-branch}). This allows the compiler to 50 * the condition. This allows the compiler to generate better code for conditions that are
51 * generate better code for conditions that are always true or always false. 51 * always true or always false. Additionally the {@link IntegerConditionProfile} implementation
52 * (as opposed to {@link BooleanConditionProfile} implementation) transmits the probability of
53 * the condition to be true to the compiler.
52 */ 54 */
53 private final BranchProfile thenTaken = new BranchProfile(); 55 private final ConditionProfile condition = new IntegerConditionProfile();
54 private final BranchProfile elseTaken = new BranchProfile();
55 56
56 public SLIfNode(SourceSection src, SLExpressionNode conditionNode, SLStatementNode thenPartNode, SLStatementNode elsePartNode) { 57 public SLIfNode(SourceSection src, SLExpressionNode conditionNode, SLStatementNode thenPartNode, SLStatementNode elsePartNode) {
57 super(src); 58 super(src);
58 this.conditionNode = conditionNode; 59 this.conditionNode = conditionNode;
59 this.thenPartNode = thenPartNode; 60 this.thenPartNode = thenPartNode;
60 this.elsePartNode = elsePartNode; 61 this.elsePartNode = elsePartNode;
61 } 62 }
62 63
63 @Override 64 @Override
64 public void executeVoid(VirtualFrame frame) { 65 public void executeVoid(VirtualFrame frame) {
65 if (evaluateCondition(frame)) { 66 /*
66 /* In the interpreter, record profiling information that the then-branch was used. */ 67 * In the interpreter, record profiling information that the condition was executed and with
67 thenTaken.enter(); 68 * which outcome.
69 */
70 if (condition.profile(evaluateCondition(frame))) {
68 /* Execute the then-branch. */ 71 /* Execute the then-branch. */
69 thenPartNode.executeVoid(frame); 72 thenPartNode.executeVoid(frame);
70 } else { 73 } else {
71 /* In the interpreter, record profiling information that the else-branch was used. */
72 elseTaken.enter();
73 /* Execute the else-branch (which is optional according to the SL syntax). */ 74 /* Execute the else-branch (which is optional according to the SL syntax). */
74 if (elsePartNode != null) { 75 if (elsePartNode != null) {
75 elsePartNode.executeVoid(frame); 76 elsePartNode.executeVoid(frame);
76 } 77 }
77 } 78 }