43972
|
1 |
/*
|
57537
|
2 |
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
|
43972
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
50858
|
23 |
|
|
24 |
|
43972
|
25 |
package org.graalvm.compiler.loop;
|
|
26 |
|
48861
|
27 |
import java.util.Collection;
|
|
28 |
import java.util.LinkedList;
|
|
29 |
import java.util.Queue;
|
|
30 |
|
49873
|
31 |
import jdk.internal.vm.compiler.collections.EconomicMap;
|
|
32 |
import jdk.internal.vm.compiler.collections.EconomicSet;
|
|
33 |
import jdk.internal.vm.compiler.collections.Equivalence;
|
43972
|
34 |
import org.graalvm.compiler.core.common.calc.Condition;
|
|
35 |
import org.graalvm.compiler.core.common.cfg.Loop;
|
|
36 |
import org.graalvm.compiler.core.common.type.IntegerStamp;
|
46640
|
37 |
import org.graalvm.compiler.debug.DebugContext;
|
43972
|
38 |
import org.graalvm.compiler.debug.GraalError;
|
46762
|
39 |
import org.graalvm.compiler.graph.Graph;
|
43972
|
40 |
import org.graalvm.compiler.graph.Node;
|
|
41 |
import org.graalvm.compiler.graph.NodeBitMap;
|
|
42 |
import org.graalvm.compiler.graph.iterators.NodePredicate;
|
|
43 |
import org.graalvm.compiler.loop.InductionVariable.Direction;
|
|
44 |
import org.graalvm.compiler.nodes.AbstractBeginNode;
|
|
45 |
import org.graalvm.compiler.nodes.AbstractEndNode;
|
|
46 |
import org.graalvm.compiler.nodes.ConstantNode;
|
|
47 |
import org.graalvm.compiler.nodes.FixedGuardNode;
|
|
48 |
import org.graalvm.compiler.nodes.FixedNode;
|
|
49 |
import org.graalvm.compiler.nodes.FixedWithNextNode;
|
|
50 |
import org.graalvm.compiler.nodes.FrameState;
|
|
51 |
import org.graalvm.compiler.nodes.FullInfopointNode;
|
|
52 |
import org.graalvm.compiler.nodes.IfNode;
|
|
53 |
import org.graalvm.compiler.nodes.LogicNode;
|
|
54 |
import org.graalvm.compiler.nodes.LoopBeginNode;
|
48190
|
55 |
import org.graalvm.compiler.nodes.NodeView;
|
43972
|
56 |
import org.graalvm.compiler.nodes.PhiNode;
|
|
57 |
import org.graalvm.compiler.nodes.PiNode;
|
|
58 |
import org.graalvm.compiler.nodes.StructuredGraph;
|
|
59 |
import org.graalvm.compiler.nodes.ValueNode;
|
|
60 |
import org.graalvm.compiler.nodes.ValuePhiNode;
|
|
61 |
import org.graalvm.compiler.nodes.calc.AddNode;
|
|
62 |
import org.graalvm.compiler.nodes.calc.BinaryArithmeticNode;
|
|
63 |
import org.graalvm.compiler.nodes.calc.CompareNode;
|
|
64 |
import org.graalvm.compiler.nodes.calc.LeftShiftNode;
|
|
65 |
import org.graalvm.compiler.nodes.calc.MulNode;
|
|
66 |
import org.graalvm.compiler.nodes.calc.NegateNode;
|
|
67 |
import org.graalvm.compiler.nodes.calc.SignExtendNode;
|
|
68 |
import org.graalvm.compiler.nodes.calc.SubNode;
|
|
69 |
import org.graalvm.compiler.nodes.calc.ZeroExtendNode;
|
|
70 |
import org.graalvm.compiler.nodes.cfg.Block;
|
|
71 |
import org.graalvm.compiler.nodes.cfg.ControlFlowGraph;
|
46344
|
72 |
import org.graalvm.compiler.nodes.debug.ControlFlowAnchored;
|
43972
|
73 |
import org.graalvm.compiler.nodes.extended.ValueAnchorNode;
|
|
74 |
import org.graalvm.compiler.nodes.util.GraphUtil;
|
|
75 |
|
|
76 |
public class LoopEx {
|
|
77 |
private final Loop<Block> loop;
|
|
78 |
private LoopFragmentInside inside;
|
|
79 |
private LoopFragmentWhole whole;
|
|
80 |
private CountedLoopInfo counted;
|
|
81 |
private LoopsData data;
|
46344
|
82 |
private EconomicMap<Node, InductionVariable> ivs;
|
54084
|
83 |
private boolean countedLoopChecked;
|
43972
|
84 |
|
|
85 |
LoopEx(Loop<Block> loop, LoopsData data) {
|
|
86 |
this.loop = loop;
|
|
87 |
this.data = data;
|
|
88 |
}
|
|
89 |
|
|
90 |
public Loop<Block> loop() {
|
|
91 |
return loop;
|
|
92 |
}
|
|
93 |
|
|
94 |
public LoopFragmentInside inside() {
|
|
95 |
if (inside == null) {
|
|
96 |
inside = new LoopFragmentInside(this);
|
|
97 |
}
|
|
98 |
return inside;
|
|
99 |
}
|
|
100 |
|
|
101 |
public LoopFragmentWhole whole() {
|
|
102 |
if (whole == null) {
|
|
103 |
whole = new LoopFragmentWhole(this);
|
|
104 |
}
|
|
105 |
return whole;
|
|
106 |
}
|
|
107 |
|
|
108 |
public void invalidateFragments() {
|
|
109 |
inside = null;
|
|
110 |
whole = null;
|
|
111 |
}
|
|
112 |
|
|
113 |
@SuppressWarnings("unused")
|
|
114 |
public LoopFragmentInsideFrom insideFrom(FixedNode point) {
|
|
115 |
// TODO (gd)
|
|
116 |
return null;
|
|
117 |
}
|
|
118 |
|
|
119 |
@SuppressWarnings("unused")
|
|
120 |
public LoopFragmentInsideBefore insideBefore(FixedNode point) {
|
|
121 |
// TODO (gd)
|
|
122 |
return null;
|
|
123 |
}
|
|
124 |
|
|
125 |
public boolean isOutsideLoop(Node n) {
|
|
126 |
return !whole().contains(n);
|
|
127 |
}
|
|
128 |
|
|
129 |
public LoopBeginNode loopBegin() {
|
|
130 |
return (LoopBeginNode) loop().getHeader().getBeginNode();
|
|
131 |
}
|
|
132 |
|
|
133 |
public FixedNode predecessor() {
|
|
134 |
return (FixedNode) loopBegin().forwardEnd().predecessor();
|
|
135 |
}
|
|
136 |
|
|
137 |
public FixedNode entryPoint() {
|
|
138 |
return loopBegin().forwardEnd();
|
|
139 |
}
|
|
140 |
|
|
141 |
public boolean isCounted() {
|
54084
|
142 |
assert countedLoopChecked;
|
43972
|
143 |
return counted != null;
|
|
144 |
}
|
|
145 |
|
|
146 |
public CountedLoopInfo counted() {
|
54084
|
147 |
assert countedLoopChecked;
|
43972
|
148 |
return counted;
|
|
149 |
}
|
|
150 |
|
|
151 |
public LoopEx parent() {
|
|
152 |
if (loop.getParent() == null) {
|
|
153 |
return null;
|
|
154 |
}
|
|
155 |
return data.loop(loop.getParent());
|
|
156 |
}
|
|
157 |
|
|
158 |
public int size() {
|
|
159 |
return whole().nodes().count();
|
|
160 |
}
|
|
161 |
|
|
162 |
@Override
|
|
163 |
public String toString() {
|
54601
|
164 |
return (countedLoopChecked && isCounted() ? "CountedLoop [" + counted() + "] " : "Loop ") + "(depth=" + loop().getDepth() + ") " + loopBegin();
|
43972
|
165 |
}
|
|
166 |
|
|
167 |
private class InvariantPredicate implements NodePredicate {
|
|
168 |
|
46762
|
169 |
private final Graph.Mark mark;
|
|
170 |
|
|
171 |
InvariantPredicate() {
|
|
172 |
this.mark = loopBegin().graph().getMark();
|
|
173 |
}
|
|
174 |
|
43972
|
175 |
@Override
|
|
176 |
public boolean apply(Node n) {
|
46762
|
177 |
if (loopBegin().graph().isNew(mark, n)) {
|
|
178 |
// Newly created nodes are unknown.
|
|
179 |
return false;
|
|
180 |
}
|
43972
|
181 |
return isOutsideLoop(n);
|
|
182 |
}
|
|
183 |
}
|
|
184 |
|
46762
|
185 |
public boolean reassociateInvariants() {
|
|
186 |
int count = 0;
|
|
187 |
StructuredGraph graph = loopBegin().graph();
|
43972
|
188 |
InvariantPredicate invariant = new InvariantPredicate();
|
|
189 |
for (BinaryArithmeticNode<?> binary : whole().nodes().filter(BinaryArithmeticNode.class)) {
|
|
190 |
if (!binary.isAssociative()) {
|
|
191 |
continue;
|
|
192 |
}
|
48190
|
193 |
ValueNode result = BinaryArithmeticNode.reassociate(binary, invariant, binary.getX(), binary.getY(), NodeView.DEFAULT);
|
43972
|
194 |
if (result != binary) {
|
46762
|
195 |
if (!result.isAlive()) {
|
|
196 |
assert !result.isDeleted();
|
|
197 |
result = graph.addOrUniqueWithInputs(result);
|
|
198 |
}
|
46640
|
199 |
DebugContext debug = graph.getDebug();
|
|
200 |
if (debug.isLogEnabled()) {
|
|
201 |
debug.log("%s : Reassociated %s into %s", graph.method().format("%H::%n"), binary, result);
|
43972
|
202 |
}
|
|
203 |
binary.replaceAtUsages(result);
|
|
204 |
GraphUtil.killWithUnusedFloatingInputs(binary);
|
46762
|
205 |
count++;
|
43972
|
206 |
}
|
|
207 |
}
|
46762
|
208 |
return count != 0;
|
43972
|
209 |
}
|
|
210 |
|
58299
|
211 |
@SuppressWarnings("fallthrough")
|
43972
|
212 |
public boolean detectCounted() {
|
54084
|
213 |
if (countedLoopChecked) {
|
|
214 |
return isCounted();
|
|
215 |
}
|
|
216 |
countedLoopChecked = true;
|
43972
|
217 |
LoopBeginNode loopBegin = loopBegin();
|
|
218 |
FixedNode next = loopBegin.next();
|
|
219 |
while (next instanceof FixedGuardNode || next instanceof ValueAnchorNode || next instanceof FullInfopointNode) {
|
|
220 |
next = ((FixedWithNextNode) next).next();
|
|
221 |
}
|
|
222 |
if (next instanceof IfNode) {
|
|
223 |
IfNode ifNode = (IfNode) next;
|
|
224 |
boolean negated = false;
|
54084
|
225 |
if (!isCfgLoopExit(ifNode.falseSuccessor())) {
|
|
226 |
if (!isCfgLoopExit(ifNode.trueSuccessor())) {
|
43972
|
227 |
return false;
|
|
228 |
}
|
|
229 |
negated = true;
|
|
230 |
}
|
|
231 |
LogicNode ifTest = ifNode.condition();
|
58299
|
232 |
if (!(ifTest instanceof CompareNode)) {
|
43972
|
233 |
return false;
|
|
234 |
}
|
58299
|
235 |
CompareNode compare = (CompareNode) ifTest;
|
43972
|
236 |
Condition condition = null;
|
|
237 |
InductionVariable iv = null;
|
|
238 |
ValueNode limit = null;
|
58299
|
239 |
if (isOutsideLoop(compare.getX())) {
|
|
240 |
iv = getInductionVariables().get(compare.getY());
|
43972
|
241 |
if (iv != null) {
|
58299
|
242 |
condition = compare.condition().asCondition().mirror();
|
|
243 |
limit = compare.getX();
|
43972
|
244 |
}
|
58299
|
245 |
} else if (isOutsideLoop(compare.getY())) {
|
|
246 |
iv = getInductionVariables().get(compare.getX());
|
43972
|
247 |
if (iv != null) {
|
58299
|
248 |
condition = compare.condition().asCondition();
|
|
249 |
limit = compare.getY();
|
43972
|
250 |
}
|
|
251 |
}
|
|
252 |
if (condition == null) {
|
|
253 |
return false;
|
|
254 |
}
|
|
255 |
if (negated) {
|
|
256 |
condition = condition.negate();
|
|
257 |
}
|
|
258 |
boolean oneOff = false;
|
58299
|
259 |
boolean unsigned = false;
|
43972
|
260 |
switch (condition) {
|
|
261 |
case EQ:
|
58299
|
262 |
if (iv.initNode() == limit) {
|
|
263 |
// allow "single iteration" case
|
|
264 |
oneOff = true;
|
|
265 |
} else {
|
43972
|
266 |
return false;
|
|
267 |
}
|
58299
|
268 |
break;
|
|
269 |
case NE: {
|
48190
|
270 |
IntegerStamp initStamp = (IntegerStamp) iv.initNode().stamp(NodeView.DEFAULT);
|
|
271 |
IntegerStamp limitStamp = (IntegerStamp) limit.stamp(NodeView.DEFAULT);
|
58299
|
272 |
IntegerStamp counterStamp = (IntegerStamp) iv.valueNode().stamp(NodeView.DEFAULT);
|
43972
|
273 |
if (iv.direction() == Direction.Up) {
|
58299
|
274 |
if (limitStamp.asConstant() != null && limitStamp.asConstant().asLong() == counterStamp.upperBound()) {
|
|
275 |
// signed: i < MAX_INT
|
|
276 |
} else if (limitStamp.asConstant() != null && limitStamp.asConstant().asLong() == counterStamp.unsignedUpperBound()) {
|
|
277 |
unsigned = true;
|
|
278 |
} else if (!iv.isConstantStride() || Math.abs(iv.constantStride()) != 1 || initStamp.upperBound() > limitStamp.lowerBound()) {
|
43972
|
279 |
return false;
|
|
280 |
}
|
|
281 |
} else if (iv.direction() == Direction.Down) {
|
58299
|
282 |
if (limitStamp.asConstant() != null && limitStamp.asConstant().asLong() == counterStamp.lowerBound()) {
|
|
283 |
// signed: MIN_INT > i
|
|
284 |
} else if (limitStamp.asConstant() != null && limitStamp.asConstant().asLong() == counterStamp.unsignedLowerBound()) {
|
|
285 |
unsigned = true;
|
|
286 |
} else if (!iv.isConstantStride() || Math.abs(iv.constantStride()) != 1 || initStamp.lowerBound() < limitStamp.upperBound()) {
|
43972
|
287 |
return false;
|
|
288 |
}
|
|
289 |
} else {
|
|
290 |
return false;
|
|
291 |
}
|
|
292 |
break;
|
|
293 |
}
|
58299
|
294 |
case BE:
|
|
295 |
unsigned = true; // fall through
|
43972
|
296 |
case LE:
|
|
297 |
oneOff = true;
|
|
298 |
if (iv.direction() != Direction.Up) {
|
|
299 |
return false;
|
|
300 |
}
|
|
301 |
break;
|
58299
|
302 |
case BT:
|
|
303 |
unsigned = true; // fall through
|
43972
|
304 |
case LT:
|
|
305 |
if (iv.direction() != Direction.Up) {
|
|
306 |
return false;
|
|
307 |
}
|
|
308 |
break;
|
58299
|
309 |
case AE:
|
|
310 |
unsigned = true; // fall through
|
43972
|
311 |
case GE:
|
|
312 |
oneOff = true;
|
|
313 |
if (iv.direction() != Direction.Down) {
|
|
314 |
return false;
|
|
315 |
}
|
|
316 |
break;
|
58299
|
317 |
case AT:
|
|
318 |
unsigned = true; // fall through
|
43972
|
319 |
case GT:
|
|
320 |
if (iv.direction() != Direction.Down) {
|
|
321 |
return false;
|
|
322 |
}
|
|
323 |
break;
|
|
324 |
default:
|
54084
|
325 |
throw GraalError.shouldNotReachHere(condition.toString());
|
43972
|
326 |
}
|
58299
|
327 |
counted = new CountedLoopInfo(this, iv, ifNode, limit, oneOff, negated ? ifNode.falseSuccessor() : ifNode.trueSuccessor(), unsigned);
|
43972
|
328 |
return true;
|
|
329 |
}
|
|
330 |
return false;
|
|
331 |
}
|
|
332 |
|
54084
|
333 |
private boolean isCfgLoopExit(AbstractBeginNode begin) {
|
|
334 |
Block block = data.getCFG().blockFor(begin);
|
|
335 |
return loop.getDepth() > block.getLoopDepth() || loop.isNaturalExit(block);
|
|
336 |
}
|
|
337 |
|
43972
|
338 |
public LoopsData loopsData() {
|
|
339 |
return data;
|
|
340 |
}
|
|
341 |
|
|
342 |
public void nodesInLoopBranch(NodeBitMap branchNodes, AbstractBeginNode branch) {
|
46393
|
343 |
EconomicSet<AbstractBeginNode> blocks = EconomicSet.create();
|
46640
|
344 |
Collection<AbstractBeginNode> exits = new LinkedList<>();
|
43972
|
345 |
Queue<Block> work = new LinkedList<>();
|
|
346 |
ControlFlowGraph cfg = loopsData().getCFG();
|
|
347 |
work.add(cfg.blockFor(branch));
|
|
348 |
while (!work.isEmpty()) {
|
|
349 |
Block b = work.remove();
|
54084
|
350 |
if (loop().isLoopExit(b)) {
|
46393
|
351 |
assert !exits.contains(b.getBeginNode());
|
46640
|
352 |
exits.add(b.getBeginNode());
|
46393
|
353 |
} else if (blocks.add(b.getBeginNode())) {
|
46344
|
354 |
Block d = b.getDominatedSibling();
|
|
355 |
while (d != null) {
|
43972
|
356 |
if (loop.getBlocks().contains(d)) {
|
|
357 |
work.add(d);
|
|
358 |
}
|
46344
|
359 |
d = d.getDominatedSibling();
|
43972
|
360 |
}
|
|
361 |
}
|
|
362 |
}
|
57537
|
363 |
LoopFragment.computeNodes(branchNodes, branch.graph(), this, blocks, exits);
|
43972
|
364 |
}
|
|
365 |
|
46344
|
366 |
public EconomicMap<Node, InductionVariable> getInductionVariables() {
|
43972
|
367 |
if (ivs == null) {
|
|
368 |
ivs = findInductionVariables(this);
|
|
369 |
}
|
|
370 |
return ivs;
|
|
371 |
}
|
|
372 |
|
|
373 |
/**
|
|
374 |
* Collect all the basic induction variables for the loop and the find any induction variables
|
|
375 |
* which are derived from the basic ones.
|
|
376 |
*
|
|
377 |
* @param loop
|
|
378 |
* @return a map from node to induction variable
|
|
379 |
*/
|
46344
|
380 |
private static EconomicMap<Node, InductionVariable> findInductionVariables(LoopEx loop) {
|
|
381 |
EconomicMap<Node, InductionVariable> ivs = EconomicMap.create(Equivalence.IDENTITY);
|
43972
|
382 |
|
|
383 |
Queue<InductionVariable> scanQueue = new LinkedList<>();
|
|
384 |
LoopBeginNode loopBegin = loop.loopBegin();
|
|
385 |
AbstractEndNode forwardEnd = loopBegin.forwardEnd();
|
46344
|
386 |
for (PhiNode phi : loopBegin.valuePhis()) {
|
|
387 |
ValueNode backValue = phi.singleBackValueOrThis();
|
|
388 |
if (backValue == phi) {
|
43972
|
389 |
continue;
|
|
390 |
}
|
|
391 |
ValueNode stride = addSub(loop, backValue, phi);
|
|
392 |
if (stride != null) {
|
|
393 |
BasicInductionVariable biv = new BasicInductionVariable(loop, (ValuePhiNode) phi, phi.valueAt(forwardEnd), stride, (BinaryArithmeticNode<?>) backValue);
|
|
394 |
ivs.put(phi, biv);
|
|
395 |
scanQueue.add(biv);
|
|
396 |
}
|
|
397 |
}
|
|
398 |
|
|
399 |
while (!scanQueue.isEmpty()) {
|
|
400 |
InductionVariable baseIv = scanQueue.remove();
|
|
401 |
ValueNode baseIvNode = baseIv.valueNode();
|
|
402 |
for (ValueNode op : baseIvNode.usages().filter(ValueNode.class)) {
|
|
403 |
if (loop.isOutsideLoop(op)) {
|
|
404 |
continue;
|
|
405 |
}
|
55509
|
406 |
if (op.hasExactlyOneUsage() && op.usages().first() == baseIvNode) {
|
43972
|
407 |
/*
|
|
408 |
* This is just the base induction variable increment with no other uses so
|
|
409 |
* don't bother reporting it.
|
|
410 |
*/
|
|
411 |
continue;
|
|
412 |
}
|
|
413 |
InductionVariable iv = null;
|
|
414 |
ValueNode offset = addSub(loop, op, baseIvNode);
|
|
415 |
ValueNode scale;
|
|
416 |
if (offset != null) {
|
|
417 |
iv = new DerivedOffsetInductionVariable(loop, baseIv, offset, (BinaryArithmeticNode<?>) op);
|
|
418 |
} else if (op instanceof NegateNode) {
|
|
419 |
iv = new DerivedScaledInductionVariable(loop, baseIv, (NegateNode) op);
|
|
420 |
} else if ((scale = mul(loop, op, baseIvNode)) != null) {
|
|
421 |
iv = new DerivedScaledInductionVariable(loop, baseIv, scale, op);
|
|
422 |
} else {
|
|
423 |
boolean isValidConvert = op instanceof PiNode || op instanceof SignExtendNode;
|
|
424 |
if (!isValidConvert && op instanceof ZeroExtendNode) {
|
48861
|
425 |
ZeroExtendNode zeroExtendNode = (ZeroExtendNode) op;
|
|
426 |
isValidConvert = zeroExtendNode.isInputAlwaysPositive() || ((IntegerStamp) zeroExtendNode.stamp(NodeView.DEFAULT)).isPositive();
|
43972
|
427 |
}
|
|
428 |
|
|
429 |
if (isValidConvert) {
|
48190
|
430 |
iv = new DerivedConvertedInductionVariable(loop, baseIv, op.stamp(NodeView.DEFAULT), op);
|
43972
|
431 |
}
|
|
432 |
}
|
|
433 |
|
|
434 |
if (iv != null) {
|
|
435 |
ivs.put(op, iv);
|
|
436 |
scanQueue.offer(iv);
|
|
437 |
}
|
|
438 |
}
|
|
439 |
}
|
46344
|
440 |
return ivs;
|
43972
|
441 |
}
|
|
442 |
|
|
443 |
private static ValueNode addSub(LoopEx loop, ValueNode op, ValueNode base) {
|
48190
|
444 |
if (op.stamp(NodeView.DEFAULT) instanceof IntegerStamp && (op instanceof AddNode || op instanceof SubNode)) {
|
43972
|
445 |
BinaryArithmeticNode<?> aritOp = (BinaryArithmeticNode<?>) op;
|
|
446 |
if (aritOp.getX() == base && loop.isOutsideLoop(aritOp.getY())) {
|
|
447 |
return aritOp.getY();
|
|
448 |
} else if (aritOp.getY() == base && loop.isOutsideLoop(aritOp.getX())) {
|
|
449 |
return aritOp.getX();
|
|
450 |
}
|
|
451 |
}
|
|
452 |
return null;
|
|
453 |
}
|
|
454 |
|
|
455 |
private static ValueNode mul(LoopEx loop, ValueNode op, ValueNode base) {
|
|
456 |
if (op instanceof MulNode) {
|
|
457 |
MulNode mul = (MulNode) op;
|
|
458 |
if (mul.getX() == base && loop.isOutsideLoop(mul.getY())) {
|
|
459 |
return mul.getY();
|
|
460 |
} else if (mul.getY() == base && loop.isOutsideLoop(mul.getX())) {
|
|
461 |
return mul.getX();
|
|
462 |
}
|
|
463 |
}
|
|
464 |
if (op instanceof LeftShiftNode) {
|
|
465 |
LeftShiftNode shift = (LeftShiftNode) op;
|
|
466 |
if (shift.getX() == base && shift.getY().isConstant()) {
|
48190
|
467 |
return ConstantNode.forIntegerStamp(base.stamp(NodeView.DEFAULT), 1 << shift.getY().asJavaConstant().asInt(), base.graph());
|
43972
|
468 |
}
|
|
469 |
}
|
|
470 |
return null;
|
|
471 |
}
|
|
472 |
|
|
473 |
/**
|
|
474 |
* Deletes any nodes created within the scope of this object that have no usages.
|
|
475 |
*/
|
|
476 |
public void deleteUnusedNodes() {
|
|
477 |
if (ivs != null) {
|
46344
|
478 |
for (InductionVariable iv : ivs.getValues()) {
|
43972
|
479 |
iv.deleteUnusedNodes();
|
|
480 |
}
|
|
481 |
}
|
|
482 |
}
|
|
483 |
|
|
484 |
/**
|
|
485 |
* @return true if all nodes in the loop can be duplicated.
|
|
486 |
*/
|
|
487 |
public boolean canDuplicateLoop() {
|
|
488 |
for (Node node : inside().nodes()) {
|
46344
|
489 |
if (node instanceof ControlFlowAnchored) {
|
43972
|
490 |
return false;
|
|
491 |
}
|
|
492 |
if (node instanceof FrameState) {
|
|
493 |
FrameState frameState = (FrameState) node;
|
54084
|
494 |
if (frameState.isExceptionHandlingBCI()) {
|
43972
|
495 |
return false;
|
|
496 |
}
|
|
497 |
}
|
|
498 |
}
|
|
499 |
return true;
|
|
500 |
}
|
|
501 |
}
|