Mercurial > hg > truffle
annotate graal/com.oracle.graal.loop/src/com/oracle/graal/loop/InductionVariable.java @ 19190:18c2fd3d7fc7
Cleanup InductionVariable declarations a bit
author | Tom Rodriguez <tom.rodriguez@oracle.com> |
---|---|
date | Mon, 09 Feb 2015 15:52:17 -0800 |
parents | 627f255ee298 |
children | 93c50cefb9e8 |
rev | line source |
---|---|
5610
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
1 /* |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. |
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 |
15193
96bb07a5d667
Spit up and move GraalInternalError.
Josef Eisl <josef.eisl@jku.at>
parents:
14908
diff
changeset
|
25 import com.oracle.graal.compiler.common.*; |
15198
2c0cfbf454b5
Move LIRTypeTool and Stamp to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents:
15193
diff
changeset
|
26 import com.oracle.graal.compiler.common.type.*; |
5610
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
27 import com.oracle.graal.nodes.*; |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
28 |
11263
acf09b065eba
Calculate exit value of counted loop induction variables.
Roland Schatz <roland.schatz@oracle.com>
parents:
9446
diff
changeset
|
29 /** |
acf09b065eba
Calculate exit value of counted loop induction variables.
Roland Schatz <roland.schatz@oracle.com>
parents:
9446
diff
changeset
|
30 * This class describes a value node that is an induction variable in a counted loop. |
acf09b065eba
Calculate exit value of counted loop induction variables.
Roland Schatz <roland.schatz@oracle.com>
parents:
9446
diff
changeset
|
31 */ |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6523
diff
changeset
|
32 public abstract class InductionVariable { |
5610
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
33 |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
34 public enum Direction { |
14908
8db6e76cb658
Formatter: Keep one enum constant per line
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
14000
diff
changeset
|
35 Up, |
8db6e76cb658
Formatter: Keep one enum constant per line
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
14000
diff
changeset
|
36 Down; |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6523
diff
changeset
|
37 |
5610
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
38 public Direction opposite() { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6523
diff
changeset
|
39 switch (this) { |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6523
diff
changeset
|
40 case Up: |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6523
diff
changeset
|
41 return Down; |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6523
diff
changeset
|
42 case Down: |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6523
diff
changeset
|
43 return Up; |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6523
diff
changeset
|
44 default: |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6523
diff
changeset
|
45 throw GraalInternalError.shouldNotReachHere(); |
5610
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
46 } |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
47 } |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
48 } |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
49 |
12655
2c4aa758ee18
made ConstantNodes external to a Graph (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents:
11263
diff
changeset
|
50 public abstract StructuredGraph graph(); |
2c4aa758ee18
made ConstantNodes external to a Graph (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents:
11263
diff
changeset
|
51 |
5610
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
52 protected final LoopEx loop; |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
53 |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
54 public InductionVariable(LoopEx loop) { |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
55 this.loop = loop; |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
56 } |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
57 |
9446
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
58 public LoopEx getLoop() { |
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
59 return loop; |
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
60 } |
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
61 |
5610
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
62 public abstract Direction direction(); |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
63 |
11263
acf09b065eba
Calculate exit value of counted loop induction variables.
Roland Schatz <roland.schatz@oracle.com>
parents:
9446
diff
changeset
|
64 /** |
16194
7fb828b4c32b
made LoopsData clients clean up dead nodes created during loop analysis
Doug Simon <doug.simon@oracle.com>
parents:
15198
diff
changeset
|
65 * Returns the value node that is described by this induction variable. |
11263
acf09b065eba
Calculate exit value of counted loop induction variables.
Roland Schatz <roland.schatz@oracle.com>
parents:
9446
diff
changeset
|
66 */ |
5610
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
67 public abstract ValueNode valueNode(); |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
68 |
11263
acf09b065eba
Calculate exit value of counted loop induction variables.
Roland Schatz <roland.schatz@oracle.com>
parents:
9446
diff
changeset
|
69 /** |
acf09b065eba
Calculate exit value of counted loop induction variables.
Roland Schatz <roland.schatz@oracle.com>
parents:
9446
diff
changeset
|
70 * Returns the node that gives the initial value of this induction variable. |
acf09b065eba
Calculate exit value of counted loop induction variables.
Roland Schatz <roland.schatz@oracle.com>
parents:
9446
diff
changeset
|
71 */ |
5610
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
72 public abstract ValueNode initNode(); |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6523
diff
changeset
|
73 |
11263
acf09b065eba
Calculate exit value of counted loop induction variables.
Roland Schatz <roland.schatz@oracle.com>
parents:
9446
diff
changeset
|
74 /** |
acf09b065eba
Calculate exit value of counted loop induction variables.
Roland Schatz <roland.schatz@oracle.com>
parents:
9446
diff
changeset
|
75 * Returns the stride of the induction variable. The stride is the value that is added to the |
acf09b065eba
Calculate exit value of counted loop induction variables.
Roland Schatz <roland.schatz@oracle.com>
parents:
9446
diff
changeset
|
76 * induction variable at each iteration. |
acf09b065eba
Calculate exit value of counted loop induction variables.
Roland Schatz <roland.schatz@oracle.com>
parents:
9446
diff
changeset
|
77 */ |
5610
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
78 public abstract ValueNode strideNode(); |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
79 |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
80 public abstract boolean isConstantInit(); |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6523
diff
changeset
|
81 |
5610
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
82 public abstract boolean isConstantStride(); |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
83 |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
84 public abstract long constantInit(); |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6523
diff
changeset
|
85 |
5610
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
86 public abstract long constantStride(); |
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
87 |
11263
acf09b065eba
Calculate exit value of counted loop induction variables.
Roland Schatz <roland.schatz@oracle.com>
parents:
9446
diff
changeset
|
88 /** |
acf09b065eba
Calculate exit value of counted loop induction variables.
Roland Schatz <roland.schatz@oracle.com>
parents:
9446
diff
changeset
|
89 * Returns the extremum value of the induction variable. The extremum value is the value of the |
19190
18c2fd3d7fc7
Cleanup InductionVariable declarations a bit
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16341
diff
changeset
|
90 * induction variable in the loop body of the last iteration, only taking into account the main |
18c2fd3d7fc7
Cleanup InductionVariable declarations a bit
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16341
diff
changeset
|
91 * loop limit test. It's possible for the loop to exit before this value if |
18c2fd3d7fc7
Cleanup InductionVariable declarations a bit
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
16341
diff
changeset
|
92 * {@link CountedLoopInfo#isExactTripCount()} returns false for the containing loop. |
11263
acf09b065eba
Calculate exit value of counted loop induction variables.
Roland Schatz <roland.schatz@oracle.com>
parents:
9446
diff
changeset
|
93 */ |
9446
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
94 public ValueNode extremumNode() { |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12655
diff
changeset
|
95 return extremumNode(false, valueNode().stamp()); |
9446
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
96 } |
27733a62ba72
Fixes and improvements for induction variables
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
97 |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
12655
diff
changeset
|
98 public abstract ValueNode extremumNode(boolean assumePositiveTripCount, Stamp stamp); |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6523
diff
changeset
|
99 |
5610
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
100 public abstract boolean isConstantExtremum(); |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6523
diff
changeset
|
101 |
5610
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
102 public abstract long constantExtremum(); |
11263
acf09b065eba
Calculate exit value of counted loop induction variables.
Roland Schatz <roland.schatz@oracle.com>
parents:
9446
diff
changeset
|
103 |
acf09b065eba
Calculate exit value of counted loop induction variables.
Roland Schatz <roland.schatz@oracle.com>
parents:
9446
diff
changeset
|
104 /** |
acf09b065eba
Calculate exit value of counted loop induction variables.
Roland Schatz <roland.schatz@oracle.com>
parents:
9446
diff
changeset
|
105 * Returns the exit value of the induction variable. The exit value is the value of the |
acf09b065eba
Calculate exit value of counted loop induction variables.
Roland Schatz <roland.schatz@oracle.com>
parents:
9446
diff
changeset
|
106 * induction variable at the loop exit. |
acf09b065eba
Calculate exit value of counted loop induction variables.
Roland Schatz <roland.schatz@oracle.com>
parents:
9446
diff
changeset
|
107 */ |
acf09b065eba
Calculate exit value of counted loop induction variables.
Roland Schatz <roland.schatz@oracle.com>
parents:
9446
diff
changeset
|
108 public abstract ValueNode exitValueNode(); |
16194
7fb828b4c32b
made LoopsData clients clean up dead nodes created during loop analysis
Doug Simon <doug.simon@oracle.com>
parents:
15198
diff
changeset
|
109 |
7fb828b4c32b
made LoopsData clients clean up dead nodes created during loop analysis
Doug Simon <doug.simon@oracle.com>
parents:
15198
diff
changeset
|
110 /** |
7fb828b4c32b
made LoopsData clients clean up dead nodes created during loop analysis
Doug Simon <doug.simon@oracle.com>
parents:
15198
diff
changeset
|
111 * Deletes any nodes created within the scope of this object that have no usages. |
7fb828b4c32b
made LoopsData clients clean up dead nodes created during loop analysis
Doug Simon <doug.simon@oracle.com>
parents:
15198
diff
changeset
|
112 */ |
16341
627f255ee298
made InductionVariable.deleteUnusedNodes() abstract
Doug Simon <doug.simon@oracle.com>
parents:
16194
diff
changeset
|
113 public abstract void deleteUnusedNodes(); |
5610
9f3250602d69
Preliminary counted loop detection
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
114 } |