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 */
23 package org.graalvm.compiler.phases.schedule;
24
25 import java.util.List;
26
27 import org.graalvm.compiler.core.common.cfg.BlockMap;
28 import org.graalvm.compiler.core.common.cfg.Loop;
29 import org.graalvm.compiler.debug.Debug;
30 import org.graalvm.compiler.graph.Node;
31 import org.graalvm.compiler.nodes.AbstractBeginNode;
32 import org.graalvm.compiler.nodes.AbstractMergeNode;
33 import org.graalvm.compiler.nodes.LoopBeginNode;
34 import org.graalvm.compiler.nodes.PhiNode;
35 import org.graalvm.compiler.nodes.cfg.Block;
36 import org.graalvm.compiler.nodes.cfg.HIRLoop;
37 import org.graalvm.compiler.nodes.memory.FloatingReadNode;
38 import org.graalvm.compiler.nodes.memory.MemoryCheckpoint;
39 import org.graalvm.compiler.nodes.memory.MemoryNode;
40 import org.graalvm.compiler.nodes.memory.MemoryPhiNode;
41 import org.graalvm.compiler.phases.graph.ReentrantBlockIterator;
42 import org.graalvm.compiler.phases.graph.ReentrantBlockIterator.BlockIteratorClosure;
43 import org.graalvm.util.Equivalence;
44 import org.graalvm.word.LocationIdentity;
45 import org.graalvm.util.EconomicSet;
46
47 public final class MemoryScheduleVerification extends BlockIteratorClosure<EconomicSet<FloatingReadNode>> {
48
49 private final BlockMap<List<Node>> blockToNodesMap;
50
51 public static boolean check(Block startBlock, BlockMap<List<Node>> blockToNodesMap) {
52 ReentrantBlockIterator.apply(new MemoryScheduleVerification(blockToNodesMap), startBlock);
53 return true;
54 }
55
56 private MemoryScheduleVerification(BlockMap<List<Node>> blockToNodesMap) {
57 this.blockToNodesMap = blockToNodesMap;
58 }
59
60 @Override
61 protected EconomicSet<FloatingReadNode> getInitialState() {
62 return EconomicSet.create(Equivalence.IDENTITY);
63 }
64
65 @Override
106 return currentState;
107 }
108
109 private static void addFloatingReadUsages(EconomicSet<FloatingReadNode> currentState, Node n) {
110 for (FloatingReadNode read : n.usages().filter(FloatingReadNode.class)) {
111 if (read.getLastLocationAccess() == n && read.getLocationIdentity().isMutable()) {
112 currentState.add(read);
113 }
114 }
115 }
116
117 private void processLocation(Node n, LocationIdentity location, EconomicSet<FloatingReadNode> currentState) {
118 assert n != null;
119 if (location.isImmutable()) {
120 return;
121 }
122
123 for (FloatingReadNode r : cloneState(currentState)) {
124 if (r.getLocationIdentity().overlaps(location)) {
125 // This read is killed by this location.
126 Debug.log(Debug.VERBOSE_LEVEL, "%s removing %s from state", n, r);
127 currentState.remove(r);
128 }
129 }
130 }
131
132 @Override
133 protected EconomicSet<FloatingReadNode> merge(Block merge, List<EconomicSet<FloatingReadNode>> states) {
134 EconomicSet<FloatingReadNode> result = states.get(0);
135 for (int i = 1; i < states.size(); ++i) {
136 result.retainAll(states.get(i));
137 }
138 return result;
139 }
140
141 @Override
142 protected EconomicSet<FloatingReadNode> cloneState(EconomicSet<FloatingReadNode> oldState) {
143 EconomicSet<FloatingReadNode> result = EconomicSet.create(Equivalence.IDENTITY);
144 if (oldState != null) {
145 result.addAll(oldState);
146 }
|
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 */
23 package org.graalvm.compiler.phases.schedule;
24
25 import java.util.List;
26
27 import org.graalvm.compiler.core.common.cfg.BlockMap;
28 import org.graalvm.compiler.core.common.cfg.Loop;
29 import org.graalvm.compiler.debug.DebugContext;
30 import org.graalvm.compiler.graph.Node;
31 import org.graalvm.compiler.nodes.AbstractBeginNode;
32 import org.graalvm.compiler.nodes.AbstractMergeNode;
33 import org.graalvm.compiler.nodes.LoopBeginNode;
34 import org.graalvm.compiler.nodes.PhiNode;
35 import org.graalvm.compiler.nodes.cfg.Block;
36 import org.graalvm.compiler.nodes.cfg.HIRLoop;
37 import org.graalvm.compiler.nodes.memory.FloatingReadNode;
38 import org.graalvm.compiler.nodes.memory.MemoryCheckpoint;
39 import org.graalvm.compiler.nodes.memory.MemoryNode;
40 import org.graalvm.compiler.nodes.memory.MemoryPhiNode;
41 import org.graalvm.compiler.phases.graph.ReentrantBlockIterator;
42 import org.graalvm.compiler.phases.graph.ReentrantBlockIterator.BlockIteratorClosure;
43 import org.graalvm.util.EconomicSet;
44 import org.graalvm.util.Equivalence;
45 import org.graalvm.word.LocationIdentity;
46
47 public final class MemoryScheduleVerification extends BlockIteratorClosure<EconomicSet<FloatingReadNode>> {
48
49 private final BlockMap<List<Node>> blockToNodesMap;
50
51 public static boolean check(Block startBlock, BlockMap<List<Node>> blockToNodesMap) {
52 ReentrantBlockIterator.apply(new MemoryScheduleVerification(blockToNodesMap), startBlock);
53 return true;
54 }
55
56 private MemoryScheduleVerification(BlockMap<List<Node>> blockToNodesMap) {
57 this.blockToNodesMap = blockToNodesMap;
58 }
59
60 @Override
61 protected EconomicSet<FloatingReadNode> getInitialState() {
62 return EconomicSet.create(Equivalence.IDENTITY);
63 }
64
65 @Override
106 return currentState;
107 }
108
109 private static void addFloatingReadUsages(EconomicSet<FloatingReadNode> currentState, Node n) {
110 for (FloatingReadNode read : n.usages().filter(FloatingReadNode.class)) {
111 if (read.getLastLocationAccess() == n && read.getLocationIdentity().isMutable()) {
112 currentState.add(read);
113 }
114 }
115 }
116
117 private void processLocation(Node n, LocationIdentity location, EconomicSet<FloatingReadNode> currentState) {
118 assert n != null;
119 if (location.isImmutable()) {
120 return;
121 }
122
123 for (FloatingReadNode r : cloneState(currentState)) {
124 if (r.getLocationIdentity().overlaps(location)) {
125 // This read is killed by this location.
126 r.getDebug().log(DebugContext.VERBOSE_LEVEL, "%s removing %s from state", n, r);
127 currentState.remove(r);
128 }
129 }
130 }
131
132 @Override
133 protected EconomicSet<FloatingReadNode> merge(Block merge, List<EconomicSet<FloatingReadNode>> states) {
134 EconomicSet<FloatingReadNode> result = states.get(0);
135 for (int i = 1; i < states.size(); ++i) {
136 result.retainAll(states.get(i));
137 }
138 return result;
139 }
140
141 @Override
142 protected EconomicSet<FloatingReadNode> cloneState(EconomicSet<FloatingReadNode> oldState) {
143 EconomicSet<FloatingReadNode> result = EconomicSet.create(Equivalence.IDENTITY);
144 if (oldState != null) {
145 result.addAll(oldState);
146 }
|