92
92
*/
93
93
public class ConvertDeoptimizeToGuardPhase extends PostRunCanonicalizationPhase <CoreProviders > implements RecursivePhase {
94
94
95
+ private final boolean considerCountedExits ;
96
+
95
97
public ConvertDeoptimizeToGuardPhase (CanonicalizerPhase canonicalizer ) {
98
+ this (canonicalizer , true );
99
+ }
100
+
101
+ public ConvertDeoptimizeToGuardPhase (CanonicalizerPhase canonicalizer , boolean considerCountedExits ) {
96
102
super (canonicalizer );
103
+ this .considerCountedExits = considerCountedExits ;
97
104
}
98
105
99
106
@ Override
@@ -116,20 +123,20 @@ protected void run(final StructuredGraph graph, final CoreProviders context) {
116
123
continue ;
117
124
}
118
125
try (DebugCloseable closable = d .withNodeSourcePosition ()) {
119
- propagateFixed (d , d , context , lazyLoops );
126
+ propagateFixed (d , d , context , lazyLoops , considerCountedExits );
120
127
}
121
128
}
122
129
if (context != null ) {
123
130
for (FixedGuardNode fixedGuard : graph .getNodes (FixedGuardNode .TYPE )) {
124
131
try (DebugCloseable closable = fixedGuard .withNodeSourcePosition ()) {
125
- trySplitFixedGuard (fixedGuard , context , lazyLoops );
132
+ trySplitFixedGuard (fixedGuard , context , lazyLoops , considerCountedExits );
126
133
}
127
134
}
128
135
}
129
136
new DeadCodeEliminationPhase (Optional ).apply (graph );
130
137
}
131
138
132
- private static void trySplitFixedGuard (FixedGuardNode fixedGuard , CoreProviders context , LazyValue <LoopsData > lazyLoops ) {
139
+ private static void trySplitFixedGuard (FixedGuardNode fixedGuard , CoreProviders context , LazyValue <LoopsData > lazyLoops , boolean considerCountedExits ) {
133
140
LogicNode condition = fixedGuard .condition ();
134
141
if (condition instanceof CompareNode ) {
135
142
CompareNode compare = (CompareNode ) condition ;
@@ -139,14 +146,14 @@ private static void trySplitFixedGuard(FixedGuardNode fixedGuard, CoreProviders
139
146
ValueNode y = compare .getY ();
140
147
ValuePhiNode yPhi = (y instanceof ValuePhiNode ) ? (ValuePhiNode ) y : null ;
141
148
if (y instanceof ConstantNode || yPhi != null ) {
142
- processFixedGuardAndPhis (fixedGuard , context , compare , x , xPhi , y , yPhi , lazyLoops );
149
+ processFixedGuardAndPhis (fixedGuard , context , compare , x , xPhi , y , yPhi , lazyLoops , considerCountedExits );
143
150
}
144
151
}
145
152
}
146
153
}
147
154
148
155
private static void processFixedGuardAndPhis (FixedGuardNode fixedGuard , CoreProviders context , CompareNode compare , ValueNode x , ValuePhiNode xPhi , ValueNode y , ValuePhiNode yPhi ,
149
- LazyValue <LoopsData > lazyLoops ) {
156
+ LazyValue <LoopsData > lazyLoops , boolean considerCountedExits ) {
150
157
AbstractBeginNode pred = AbstractBeginNode .prevBegin (fixedGuard );
151
158
if (pred instanceof AbstractMergeNode ) {
152
159
AbstractMergeNode merge = (AbstractMergeNode ) pred ;
@@ -157,13 +164,13 @@ private static void processFixedGuardAndPhis(FixedGuardNode fixedGuard, CoreProv
157
164
return ;
158
165
}
159
166
160
- processFixedGuardAndMerge (fixedGuard , context , compare , x , xPhi , y , yPhi , merge , lazyLoops );
167
+ processFixedGuardAndMerge (fixedGuard , context , compare , x , xPhi , y , yPhi , merge , lazyLoops , considerCountedExits );
161
168
}
162
169
}
163
170
164
171
@ SuppressWarnings ("try" )
165
172
private static void processFixedGuardAndMerge (FixedGuardNode fixedGuard , CoreProviders context , CompareNode compare , ValueNode x , ValuePhiNode xPhi , ValueNode y , ValuePhiNode yPhi ,
166
- AbstractMergeNode merge , LazyValue <LoopsData > lazyLoops ) {
173
+ AbstractMergeNode merge , LazyValue <LoopsData > lazyLoops , boolean considerCountedExits ) {
167
174
List <EndNode > mergePredecessors = merge .cfgPredecessors ().snapshot ();
168
175
for (AbstractEndNode mergePredecessor : mergePredecessors ) {
169
176
if (!mergePredecessor .isAlive ()) {
@@ -186,15 +193,15 @@ private static void processFixedGuardAndMerge(FixedGuardNode fixedGuard, CorePro
186
193
TriState compareResult = compare .condition ().foldCondition (compareStamp , xs , ys , context .getConstantReflection (), compare .unorderedIsTrue ());
187
194
if (compareResult .isKnown () && compareResult .toBoolean () == fixedGuard .isNegated ()) {
188
195
try (DebugCloseable position = fixedGuard .withNodeSourcePosition ()) {
189
- propagateFixed (mergePredecessor , fixedGuard , context , lazyLoops );
196
+ propagateFixed (mergePredecessor , fixedGuard , context , lazyLoops , considerCountedExits );
190
197
}
191
198
}
192
199
}
193
200
}
194
201
}
195
202
196
203
@ SuppressWarnings ("try" )
197
- public static void propagateFixed (FixedNode from , StaticDeoptimizingNode deopt , CoreProviders providers , LazyValue <LoopsData > lazyLoops ) {
204
+ public static void propagateFixed (FixedNode from , StaticDeoptimizingNode deopt , CoreProviders providers , LazyValue <LoopsData > lazyLoops , boolean considerCountedExits ) {
198
205
Node current = from ;
199
206
while (current != null ) {
200
207
if (GraalOptions .GuardPriorities .getValue (from .getOptions ()) && current instanceof FixedGuardNode ) {
@@ -209,16 +216,16 @@ public static void propagateFixed(FixedNode from, StaticDeoptimizingNode deopt,
209
216
FixedNode next = mergeNode .next ();
210
217
while (mergeNode .isAlive ()) {
211
218
AbstractEndNode end = mergeNode .forwardEnds ().first ();
212
- propagateFixed (end , deopt , providers , lazyLoops );
219
+ propagateFixed (end , deopt , providers , lazyLoops , considerCountedExits );
213
220
}
214
221
if (next .isAlive ()) {
215
- propagateFixed (next , deopt , providers , lazyLoops );
222
+ propagateFixed (next , deopt , providers , lazyLoops , considerCountedExits );
216
223
}
217
224
return ;
218
225
} else if (current .predecessor () instanceof IfNode ) {
219
226
AbstractBeginNode begin = (AbstractBeginNode ) current ;
220
227
IfNode ifNode = (IfNode ) current .predecessor ();
221
- if (isOsrLoopExit (begin ) || isCountedLoopExit (ifNode , lazyLoops )) {
228
+ if (isOsrLoopExit (begin ) || ( considerCountedExits && isCountedLoopExit (ifNode , lazyLoops ) )) {
222
229
moveAsDeoptAfter (begin , deopt );
223
230
} else {
224
231
if (begin instanceof LoopExitNode && ifNode .condition () instanceof IntegerEqualsNode ) {
0 commit comments