comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/SpecializationGroup.java @ 12401:85dcc7f59c34

Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
author Christian Humer <christian.humer@gmail.com>
date Mon, 14 Oct 2013 15:44:18 +0200
parents d6a5ab791b0d
children 25ecb47a6d0e
comparison
equal deleted inserted replaced
12400:28e7396dca1d 12401:85dcc7f59c34
88 } 88 }
89 } 89 }
90 return null; 90 return null;
91 } 91 }
92 92
93 public List<GuardData> getElseConnectableGuards() { 93 public List<GuardData> findElseConnectableGuards(boolean minimumStateCheck) {
94 if (minimumStateCheck) {
95 /*
96 * TODO investigate further if we really cannot else connect guards if minimum state is
97 * required
98 */
99 return Collections.emptyList();
100 }
94 if (!getTypeGuards().isEmpty() || !getAssumptions().isEmpty()) { 101 if (!getTypeGuards().isEmpty() || !getAssumptions().isEmpty()) {
95 return Collections.emptyList(); 102 return Collections.emptyList();
96 } 103 }
97 104
98 if (getGuards().isEmpty()) { 105 if (getGuards().isEmpty()) {
99 return Collections.emptyList(); 106 return Collections.emptyList();
100 } 107 }
101 108
102 List<GuardData> elseConnectableGuards = new ArrayList<>(); 109 List<GuardData> elseConnectableGuards = new ArrayList<>();
103 int guardIndex = 0; 110 int guardIndex = 0;
104 while (guardIndex < getGuards().size() && findNegatedGuardInPrevious(getGuards().get(guardIndex)) != null) { 111 while (guardIndex < getGuards().size() && findNegatedGuardInPrevious(getGuards().get(guardIndex), minimumStateCheck) != null) {
105 elseConnectableGuards.add(getGuards().get(guardIndex)); 112 elseConnectableGuards.add(getGuards().get(guardIndex));
106 guardIndex++; 113 guardIndex++;
107 } 114 }
108 115
109 return elseConnectableGuards; 116 return elseConnectableGuards;
110 } 117 }
111 118
112 private GuardData findNegatedGuardInPrevious(GuardData guard) { 119 private GuardData findNegatedGuardInPrevious(GuardData guard, boolean minimumStateCheck) {
113 SpecializationGroup previous = this.getPreviousGroup(); 120 SpecializationGroup previous = this.getPreviousGroup();
114 if (previous == null) { 121 if (previous == null) {
115 return null; 122 return null;
116 } 123 }
117 List<GuardData> elseConnectedGuards = previous.getElseConnectableGuards(); 124 List<GuardData> elseConnectedGuards = previous.findElseConnectableGuards(minimumStateCheck);
118 125
119 if (previous == null || previous.getGuards().size() != elseConnectedGuards.size() + 1) { 126 if (previous == null || previous.getGuards().size() != elseConnectedGuards.size() + 1) {
120 return null; 127 return null;
121 } 128 }
122 129
130 /* Guard is else branch can be connected in previous specialization. */
123 if (elseConnectedGuards.contains(guard)) { 131 if (elseConnectedGuards.contains(guard)) {
124 return guard; 132 return guard;
125 } 133 }
126 134
127 GuardData previousGuard = previous.getGuards().get(elseConnectedGuards.size()); 135 GuardData previousGuard = previous.getGuards().get(elseConnectedGuards.size());
339 return null; 347 return null;
340 } 348 }
341 return parent.children.get(index - 1); 349 return parent.children.get(index - 1);
342 } 350 }
343 351
352 public int getUncheckedSpecializationIndex() {
353 int groupMaxIndex = getMaxSpecializationIndex();
354
355 int genericIndex = node.getSpecializations().indexOf(node.getGenericSpecialization());
356 if (groupMaxIndex >= genericIndex) {
357 // no minimum state check for an generic index
358 groupMaxIndex = -1;
359 }
360
361 if (groupMaxIndex > -1) {
362 // no minimum state check if already checked by parent group
363 int parentMaxIndex = -1;
364 if (getParent() != null) {
365 parentMaxIndex = getParent().getMaxSpecializationIndex();
366 }
367 if (groupMaxIndex == parentMaxIndex) {
368 groupMaxIndex = -1;
369 }
370 }
371 return groupMaxIndex;
372 }
373
344 public int getMaxSpecializationIndex() { 374 public int getMaxSpecializationIndex() {
345 if (specialization != null) { 375 if (specialization != null) {
346 return specialization.getNode().getSpecializations().indexOf(specialization); 376 return specialization.getNode().getSpecializations().indexOf(specialization);
347 } else { 377 } else {
348 int max = Integer.MIN_VALUE; 378 int max = Integer.MIN_VALUE;