comparison graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/WhileNode.java @ 13336:d4c6dd07be76

SL: added exemplary uses of new profiling utility BranchProfile to SL.
author Christian Humer <christian.humer@gmail.com>
date Sun, 15 Dec 2013 22:20:12 +0100
parents 5e3d1a68664e
children
comparison
equal deleted inserted replaced
13335:8531c47138dc 13336:d4c6dd07be76
21 * questions. 21 * questions.
22 */ 22 */
23 package com.oracle.truffle.sl.nodes; 23 package com.oracle.truffle.sl.nodes;
24 24
25 import com.oracle.truffle.api.frame.*; 25 import com.oracle.truffle.api.frame.*;
26 import com.oracle.truffle.api.utilities.*;
26 27
27 public class WhileNode extends StatementNode { 28 public class WhileNode extends StatementNode {
28 29
29 @Child private ConditionNode condition; 30 @Child private ConditionNode condition;
30 31
31 @Child private StatementNode body; 32 @Child private StatementNode body;
32 33
33 private final BreakException breakTarget; 34 private final BreakException breakTarget;
34 private final ContinueException continueTarget; 35 private final ContinueException continueTarget;
36
37 private final BranchProfile continueMismatch = new BranchProfile();
38 private final BranchProfile continueMatch = new BranchProfile();
39 private final BranchProfile breakMismatch = new BranchProfile();
40 private final BranchProfile breakMatch = new BranchProfile();
35 41
36 public WhileNode(ConditionNode condition, StatementNode body) { 42 public WhileNode(ConditionNode condition, StatementNode body) {
37 this.condition = adoptChild(condition); 43 this.condition = adoptChild(condition);
38 this.body = adoptChild(body); 44 this.body = adoptChild(body);
39 45
47 while (condition.executeCondition(frame)) { 53 while (condition.executeCondition(frame)) {
48 try { 54 try {
49 body.executeVoid(frame); 55 body.executeVoid(frame);
50 } catch (ContinueException ex) { 56 } catch (ContinueException ex) {
51 if (ex != continueTarget) { 57 if (ex != continueTarget) {
58 continueMismatch.enter();
52 throw ex; 59 throw ex;
53 } 60 }
61 continueMatch.enter();
54 // Fall through to next loop iteration. 62 // Fall through to next loop iteration.
55 } 63 }
56 } 64 }
57 } catch (BreakException ex) { 65 } catch (BreakException ex) {
58 if (ex != breakTarget) { 66 if (ex != breakTarget) {
67 breakMismatch.enter();
59 throw ex; 68 throw ex;
60 } 69 }
70 breakMatch.enter();
61 // Done executing this loop, exit method to execute statement following the loop. 71 // Done executing this loop, exit method to execute statement following the loop.
62 } 72 }
63 } 73 }
64 } 74 }