Mercurial > hg > graal-compiler
annotate graal/com.oracle.graal.loop/src/com/oracle/graal/loop/CountedLoopInfo.java @ 22054:0e095e2c24e2
Rename com.oracle.jvmci to jdk.internal.jvmci
author | twisti |
---|---|
date | Mon, 22 Jun 2015 12:12:53 -0700 |
parents | ba3759462502 |
children | 660aa109e456 |
rev | line source |
---|---|
5610
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
1 /* |
21932
ba3759462502
Fix trip count of counted loops with stride > 1.
Roland Schatz <roland.schatz@oracle.com>
parents:
21556
diff
changeset
|
2 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. |
5610
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
4 * |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
8 * |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
13 * accompanied this code). |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
14 * |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
18 * |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
21 * questions. |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
22 */ |
6523
c8763a2deb0c
rename packages in graal.loop to match project name
Doug Simon <doug.simon@oracle.com>
parents:
6522
diff
changeset
|
23 package com.oracle.graal.loop; |
5610
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
24 |
19191
ef52cebd4030
Fold away obvious identities when building induction variable expressions
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18993
diff
changeset
|
25 import static com.oracle.graal.loop.MathUtil.*; |
22054 | 26 import jdk.internal.jvmci.code.*; |
27 import jdk.internal.jvmci.meta.*; | |
9446
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
28 |
15198
2c0cfbf454b5
Move LIRTypeTool and Stamp to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents:
15145
diff
changeset
|
29 import com.oracle.graal.compiler.common.type.*; |
7305
cd205ca515dd
Make integer division and remainder nodes fixed so that they can be lowered via snippets to do exception checks
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6523
diff
changeset
|
30 import com.oracle.graal.loop.InductionVariable.Direction; |
5610
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
31 import com.oracle.graal.nodes.*; |
9446
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
32 import com.oracle.graal.nodes.calc.*; |
9646
183d33c76419
Removed ValueNode.dependencies
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9644
diff
changeset
|
33 import com.oracle.graal.nodes.extended.*; |
5610
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
34 |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
35 public class CountedLoopInfo { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7305
diff
changeset
|
36 |
5610
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
37 private final LoopEx loop; |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
38 private InductionVariable iv; |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
39 private ValueNode end; |
5675
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5610
diff
changeset
|
40 private boolean oneOff; |
18993
480bd3b1adcd
Rename BeginNode => AbstractBeginNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18845
diff
changeset
|
41 private AbstractBeginNode body; |
5610
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
42 |
18993
480bd3b1adcd
Rename BeginNode => AbstractBeginNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18845
diff
changeset
|
43 CountedLoopInfo(LoopEx loop, InductionVariable iv, ValueNode end, boolean oneOff, AbstractBeginNode body) { |
5610
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
44 this.loop = loop; |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
45 this.iv = iv; |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
46 this.end = end; |
5675
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5610
diff
changeset
|
47 this.oneOff = oneOff; |
9446
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
48 this.body = body; |
5610
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
49 } |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
50 |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
51 public ValueNode maxTripCountNode() { |
9446
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
52 return maxTripCountNode(false); |
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
53 } |
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
54 |
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
55 public ValueNode maxTripCountNode(boolean assumePositive) { |
9602
19c5a07c7843
Introduce a graph() method that returns a StructuredGraph, to make many explicit casts unnecessary
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9569
diff
changeset
|
56 StructuredGraph graph = iv.valueNode().graph(); |
14024
34c07ef28bc9
Support integer arithmetic for arbitrary types.
Roland Schatz <roland.schatz@oracle.com>
parents:
13641
diff
changeset
|
57 Stamp stamp = iv.valueNode().stamp(); |
19191
ef52cebd4030
Fold away obvious identities when building induction variable expressions
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18993
diff
changeset
|
58 ValueNode range = sub(graph, end, iv.initNode()); |
21932
ba3759462502
Fix trip count of counted loops with stride > 1.
Roland Schatz <roland.schatz@oracle.com>
parents:
21556
diff
changeset
|
59 if (!iv.isConstantStride() || Math.abs(iv.constantStride()) != 1) { |
ba3759462502
Fix trip count of counted loops with stride > 1.
Roland Schatz <roland.schatz@oracle.com>
parents:
21556
diff
changeset
|
60 ValueNode stride = iv.strideNode(); |
ba3759462502
Fix trip count of counted loops with stride > 1.
Roland Schatz <roland.schatz@oracle.com>
parents:
21556
diff
changeset
|
61 if (!oneOff) { |
ba3759462502
Fix trip count of counted loops with stride > 1.
Roland Schatz <roland.schatz@oracle.com>
parents:
21556
diff
changeset
|
62 if (iv.direction() == Direction.Up) { |
ba3759462502
Fix trip count of counted loops with stride > 1.
Roland Schatz <roland.schatz@oracle.com>
parents:
21556
diff
changeset
|
63 stride = sub(graph, stride, ConstantNode.forIntegerStamp(stamp, 1, graph)); |
ba3759462502
Fix trip count of counted loops with stride > 1.
Roland Schatz <roland.schatz@oracle.com>
parents:
21556
diff
changeset
|
64 } else { |
ba3759462502
Fix trip count of counted loops with stride > 1.
Roland Schatz <roland.schatz@oracle.com>
parents:
21556
diff
changeset
|
65 assert iv.direction() == Direction.Down; |
ba3759462502
Fix trip count of counted loops with stride > 1.
Roland Schatz <roland.schatz@oracle.com>
parents:
21556
diff
changeset
|
66 stride = add(graph, stride, ConstantNode.forIntegerStamp(stamp, 1, graph)); |
ba3759462502
Fix trip count of counted loops with stride > 1.
Roland Schatz <roland.schatz@oracle.com>
parents:
21556
diff
changeset
|
67 } |
ba3759462502
Fix trip count of counted loops with stride > 1.
Roland Schatz <roland.schatz@oracle.com>
parents:
21556
diff
changeset
|
68 } |
ba3759462502
Fix trip count of counted loops with stride > 1.
Roland Schatz <roland.schatz@oracle.com>
parents:
21556
diff
changeset
|
69 range = add(graph, range, stride); |
ba3759462502
Fix trip count of counted loops with stride > 1.
Roland Schatz <roland.schatz@oracle.com>
parents:
21556
diff
changeset
|
70 } else if (oneOff) { |
9446
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
71 if (iv.direction() == Direction.Up) { |
19191
ef52cebd4030
Fold away obvious identities when building induction variable expressions
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18993
diff
changeset
|
72 range = add(graph, range, ConstantNode.forIntegerStamp(stamp, 1, graph)); |
9446
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
73 } else { |
19918
c278c8c727aa
More checks that InductionVariable.direction is valid
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19191
diff
changeset
|
74 assert iv.direction() == Direction.Down; |
19191
ef52cebd4030
Fold away obvious identities when building induction variable expressions
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18993
diff
changeset
|
75 range = sub(graph, range, ConstantNode.forIntegerStamp(stamp, 1, graph)); |
9446
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
76 } |
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
77 } |
19191
ef52cebd4030
Fold away obvious identities when building induction variable expressions
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18993
diff
changeset
|
78 ValueNode div = divBefore(graph, loop.entryPoint(), range, iv.strideNode()); |
9446
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
79 if (assumePositive) { |
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
80 return div; |
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
81 } |
19191
ef52cebd4030
Fold away obvious identities when building induction variable expressions
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18993
diff
changeset
|
82 ConstantNode zero = ConstantNode.forIntegerStamp(stamp, 0, graph); |
18845
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18490
diff
changeset
|
83 return graph.unique(new ConditionalNode(graph.unique(new IntegerLessThanNode(zero, div)), div, zero)); |
5610
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
84 } |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
85 |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
86 public boolean isConstantMaxTripCount() { |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
87 return end instanceof ConstantNode && iv.isConstantInit() && iv.isConstantStride(); |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
88 } |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
89 |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
90 public long constantMaxTripCount() { |
19918
c278c8c727aa
More checks that InductionVariable.direction is valid
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19191
diff
changeset
|
91 assert iv.direction() != null; |
5675
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5610
diff
changeset
|
92 long off = oneOff ? iv.direction() == Direction.Up ? 1 : -1 : 0; |
18187
9619ba4daf4c
Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents:
17419
diff
changeset
|
93 long max = (((ConstantNode) end).asJavaConstant().asLong() + off - iv.constantInit()) / iv.constantStride(); |
5675
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5610
diff
changeset
|
94 return Math.max(0, max); |
5610
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
95 } |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
96 |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
97 public boolean isExactTripCount() { |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
98 return loop.loopBegin().loopExits().count() == 1; |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
99 } |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
100 |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
101 public ValueNode exactTripCountNode() { |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
102 assert isExactTripCount(); |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
103 return maxTripCountNode(); |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
104 } |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
105 |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
106 public boolean isConstantExactTripCount() { |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
107 assert isExactTripCount(); |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
108 return isConstantMaxTripCount(); |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
109 } |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
110 |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
111 public long constantExactTripCount() { |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
112 assert isExactTripCount(); |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
113 return constantMaxTripCount(); |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
114 } |
5675
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5610
diff
changeset
|
115 |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5610
diff
changeset
|
116 @Override |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5610
diff
changeset
|
117 public String toString() { |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5610
diff
changeset
|
118 return "iv=" + iv + " until " + end + (oneOff ? iv.direction() == Direction.Up ? "+1" : "-1" : ""); |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5610
diff
changeset
|
119 } |
9446
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
120 |
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
121 public ValueNode getLimit() { |
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
122 return end; |
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
123 } |
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
124 |
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
125 public ValueNode getStart() { |
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
126 return iv.initNode(); |
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
127 } |
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
128 |
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
129 public boolean isLimitIncluded() { |
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
130 return oneOff; |
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
131 } |
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
132 |
18993
480bd3b1adcd
Rename BeginNode => AbstractBeginNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18845
diff
changeset
|
133 public AbstractBeginNode getBody() { |
9446
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
134 return body; |
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
135 } |
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
136 |
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
137 public Direction getDirection() { |
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
138 return iv.direction(); |
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
139 } |
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
140 |
11347
231c8a83cf41
Samll additions to Loops api, make IntegerExactArithmeticNodes iterable
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9646
diff
changeset
|
141 public InductionVariable getCounter() { |
231c8a83cf41
Samll additions to Loops api, make IntegerExactArithmeticNodes iterable
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9646
diff
changeset
|
142 return iv; |
231c8a83cf41
Samll additions to Loops api, make IntegerExactArithmeticNodes iterable
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9646
diff
changeset
|
143 } |
231c8a83cf41
Samll additions to Loops api, make IntegerExactArithmeticNodes iterable
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9646
diff
changeset
|
144 |
9646
183d33c76419
Removed ValueNode.dependencies
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9644
diff
changeset
|
145 public GuardingNode getOverFlowGuard() { |
9644
a230bfbd9497
Use specialized node inputs for loopbegin's overflow check and for value anchor's anchored values
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9602
diff
changeset
|
146 return loop.loopBegin().getOverflowGuard(); |
a230bfbd9497
Use specialized node inputs for loopbegin's overflow check and for value anchor's anchored values
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9602
diff
changeset
|
147 } |
a230bfbd9497
Use specialized node inputs for loopbegin's overflow check and for value anchor's anchored values
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9602
diff
changeset
|
148 |
9646
183d33c76419
Removed ValueNode.dependencies
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9644
diff
changeset
|
149 public GuardingNode createOverFlowGuard() { |
183d33c76419
Removed ValueNode.dependencies
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9644
diff
changeset
|
150 GuardingNode overflowGuard = getOverFlowGuard(); |
9644
a230bfbd9497
Use specialized node inputs for loopbegin's overflow check and for value anchor's anchored values
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9602
diff
changeset
|
151 if (overflowGuard != null) { |
a230bfbd9497
Use specialized node inputs for loopbegin's overflow check and for value anchor's anchored values
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9602
diff
changeset
|
152 return overflowGuard; |
a230bfbd9497
Use specialized node inputs for loopbegin's overflow check and for value anchor's anchored values
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9602
diff
changeset
|
153 } |
14024
34c07ef28bc9
Support integer arithmetic for arbitrary types.
Roland Schatz <roland.schatz@oracle.com>
parents:
13641
diff
changeset
|
154 IntegerStamp stamp = (IntegerStamp) iv.valueNode().stamp(); |
12655
2c4aa758ee18
made ConstantNodes external to a Graph (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents:
11839
diff
changeset
|
155 StructuredGraph graph = iv.valueNode().graph(); |
9644
a230bfbd9497
Use specialized node inputs for loopbegin's overflow check and for value anchor's anchored values
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9602
diff
changeset
|
156 CompareNode cond; // we use a negated guard with a < condition to achieve a >= |
14024
34c07ef28bc9
Support integer arithmetic for arbitrary types.
Roland Schatz <roland.schatz@oracle.com>
parents:
13641
diff
changeset
|
157 ConstantNode one = ConstantNode.forIntegerStamp(stamp, 1, graph); |
9644
a230bfbd9497
Use specialized node inputs for loopbegin's overflow check and for value anchor's anchored values
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9602
diff
changeset
|
158 if (iv.direction() == Direction.Up) { |
19191
ef52cebd4030
Fold away obvious identities when building induction variable expressions
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18993
diff
changeset
|
159 ValueNode v1 = sub(graph, ConstantNode.forIntegerStamp(stamp, CodeUtil.maxValue(stamp.getBits()), graph), sub(graph, iv.strideNode(), one)); |
9644
a230bfbd9497
Use specialized node inputs for loopbegin's overflow check and for value anchor's anchored values
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9602
diff
changeset
|
160 if (oneOff) { |
12655
2c4aa758ee18
made ConstantNodes external to a Graph (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents:
11839
diff
changeset
|
161 v1 = sub(graph, v1, one); |
9446
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
162 } |
18845
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18490
diff
changeset
|
163 cond = graph.unique(new IntegerLessThanNode(v1, end)); |
9644
a230bfbd9497
Use specialized node inputs for loopbegin's overflow check and for value anchor's anchored values
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9602
diff
changeset
|
164 } else { |
a230bfbd9497
Use specialized node inputs for loopbegin's overflow check and for value anchor's anchored values
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9602
diff
changeset
|
165 assert iv.direction() == Direction.Down; |
19191
ef52cebd4030
Fold away obvious identities when building induction variable expressions
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18993
diff
changeset
|
166 ValueNode v1 = add(graph, ConstantNode.forIntegerStamp(stamp, CodeUtil.minValue(stamp.getBits()), graph), sub(graph, one, iv.strideNode())); |
9644
a230bfbd9497
Use specialized node inputs for loopbegin's overflow check and for value anchor's anchored values
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9602
diff
changeset
|
167 if (oneOff) { |
12655
2c4aa758ee18
made ConstantNodes external to a Graph (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents:
11839
diff
changeset
|
168 v1 = add(graph, v1, one); |
9644
a230bfbd9497
Use specialized node inputs for loopbegin's overflow check and for value anchor's anchored values
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9602
diff
changeset
|
169 } |
18845
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18490
diff
changeset
|
170 cond = graph.unique(new IntegerLessThanNode(end, v1)); |
9446
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
171 } |
18993
480bd3b1adcd
Rename BeginNode => AbstractBeginNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18845
diff
changeset
|
172 overflowGuard = graph.unique(new GuardNode(cond, AbstractBeginNode.prevBegin(loop.entryPoint()), DeoptimizationReason.LoopLimitCheck, DeoptimizationAction.InvalidateRecompile, true, |
18490
ca81508f2a19
Generalize NULL handling to work on arbitrary pointers.
Roland Schatz <roland.schatz@oracle.com>
parents:
18187
diff
changeset
|
173 JavaConstant.NULL_POINTER)); // TODO gd: use speculation |
9644
a230bfbd9497
Use specialized node inputs for loopbegin's overflow check and for value anchor's anchored values
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9602
diff
changeset
|
174 loop.loopBegin().setOverflowGuard(overflowGuard); |
9446
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
175 return overflowGuard; |
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
176 } |
9450
ca34e36c53e8
Add loop safepoint elimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9446
diff
changeset
|
177 |
14024
34c07ef28bc9
Support integer arithmetic for arbitrary types.
Roland Schatz <roland.schatz@oracle.com>
parents:
13641
diff
changeset
|
178 public IntegerStamp getStamp() { |
34c07ef28bc9
Support integer arithmetic for arbitrary types.
Roland Schatz <roland.schatz@oracle.com>
parents:
13641
diff
changeset
|
179 return (IntegerStamp) iv.valueNode().stamp(); |
9450
ca34e36c53e8
Add loop safepoint elimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9446
diff
changeset
|
180 } |
5610
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
181 } |