annotate graal/com.oracle.graal.loop/src/com/oracle/graal/loop/phases/LoopTransformLowPhase.java @ 7283:3964f3d4eb18

Extend loop unswicthing to Switch nodes (integer or type)
author Gilles Duboscq <duboscq@ssw.jku.at>
date Thu, 20 Dec 2012 12:06:58 +0100
parents b1ebd583be14
children 5e3d1a68664e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5675
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
1 /*
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved.
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
4 *
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
7 * published by the Free Software Foundation.
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
8 *
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
13 * accompanied this code).
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
14 *
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
18 *
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
21 * questions.
776366f3a41a A bit of work on counted loops
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.phases;
5675
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
24
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
25 import com.oracle.graal.debug.*;
7283
3964f3d4eb18 Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7257
diff changeset
26 import com.oracle.graal.graph.NodeClass.NodeClassIterator;
6523
c8763a2deb0c rename packages in graal.loop to match project name
Doug Simon <doug.simon@oracle.com>
parents: 6522
diff changeset
27 import com.oracle.graal.loop.*;
5675
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
28 import com.oracle.graal.nodes.*;
6525
2c913b643422 rename packages in graal.phases to match project name
Doug Simon <doug.simon@oracle.com>
parents: 6523
diff changeset
29 import com.oracle.graal.phases.*;
5675
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
30
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
31 public class LoopTransformLowPhase extends Phase {
5696
f592c22421e7 Look for LoopUnswitch opportunities (LoopUnswitch currently disabled)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5675
diff changeset
32 private static final DebugMetric UNSWITCHED = Debug.metric("Unswitched");
5675
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
33
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
34 @Override
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
35 protected void run(StructuredGraph graph) {
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
36 if (graph.hasLoops()) {
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
37 if (GraalOptions.ReassociateInvariants) {
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
38 final LoopsData dataReassociate = new LoopsData(graph);
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
39 Debug.scope("ReassociateInvariants", new Runnable() {
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
40 @Override
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
41 public void run() {
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
42 for (LoopEx loop : dataReassociate.loops()) {
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
43 loop.reassociateInvariants();
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
44 }
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
45 }
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
46 });
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
47 }
5696
f592c22421e7 Look for LoopUnswitch opportunities (LoopUnswitch currently disabled)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5675
diff changeset
48 if (GraalOptions.LoopUnswitch) {
f592c22421e7 Look for LoopUnswitch opportunities (LoopUnswitch currently disabled)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5675
diff changeset
49 boolean unswitched;
f592c22421e7 Look for LoopUnswitch opportunities (LoopUnswitch currently disabled)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5675
diff changeset
50 do {
f592c22421e7 Look for LoopUnswitch opportunities (LoopUnswitch currently disabled)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5675
diff changeset
51 unswitched = false;
f592c22421e7 Look for LoopUnswitch opportunities (LoopUnswitch currently disabled)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5675
diff changeset
52 final LoopsData dataUnswitch = new LoopsData(graph);
f592c22421e7 Look for LoopUnswitch opportunities (LoopUnswitch currently disabled)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5675
diff changeset
53 for (LoopEx loop : dataUnswitch.loops()) {
f592c22421e7 Look for LoopUnswitch opportunities (LoopUnswitch currently disabled)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5675
diff changeset
54 if (LoopPolicies.shouldTryUnswitch(loop)) {
7283
3964f3d4eb18 Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7257
diff changeset
55 ControlSplitNode controlSplit = LoopTransformations.findUnswitchable(loop);
3964f3d4eb18 Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7257
diff changeset
56 if (controlSplit != null && LoopPolicies.shouldUnswitch(loop, controlSplit)) {
3964f3d4eb18 Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7257
diff changeset
57 if (Debug.isLogEnabled()) {
3964f3d4eb18 Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7257
diff changeset
58 logUnswitch(loop, controlSplit);
3964f3d4eb18 Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7257
diff changeset
59 }
3964f3d4eb18 Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7257
diff changeset
60 LoopTransformations.unswitch(loop, controlSplit);
5696
f592c22421e7 Look for LoopUnswitch opportunities (LoopUnswitch currently disabled)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5675
diff changeset
61 UNSWITCHED.increment();
5741
c84c75339af1 Work on loop unswitching, things look ok, still disabled until FloatingRead preserves loop-closed form
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5732
diff changeset
62 Debug.dump(graph, "After unswitch %s", loop);
5696
f592c22421e7 Look for LoopUnswitch opportunities (LoopUnswitch currently disabled)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5675
diff changeset
63 unswitched = true;
f592c22421e7 Look for LoopUnswitch opportunities (LoopUnswitch currently disabled)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5675
diff changeset
64 break;
f592c22421e7 Look for LoopUnswitch opportunities (LoopUnswitch currently disabled)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5675
diff changeset
65 }
f592c22421e7 Look for LoopUnswitch opportunities (LoopUnswitch currently disabled)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5675
diff changeset
66 }
f592c22421e7 Look for LoopUnswitch opportunities (LoopUnswitch currently disabled)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5675
diff changeset
67 }
f592c22421e7 Look for LoopUnswitch opportunities (LoopUnswitch currently disabled)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5675
diff changeset
68 } while(unswitched);
f592c22421e7 Look for LoopUnswitch opportunities (LoopUnswitch currently disabled)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5675
diff changeset
69 }
5675
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
70 }
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
71 }
7283
3964f3d4eb18 Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7257
diff changeset
72
3964f3d4eb18 Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7257
diff changeset
73 private static void logUnswitch(LoopEx loop, ControlSplitNode controlSplit) {
3964f3d4eb18 Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7257
diff changeset
74 StringBuilder sb = new StringBuilder("Unswitching ");
3964f3d4eb18 Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7257
diff changeset
75 sb.append(loop).append(" at ").append(controlSplit).append(" [");
3964f3d4eb18 Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7257
diff changeset
76 NodeClassIterator it = controlSplit.successors().iterator();
3964f3d4eb18 Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7257
diff changeset
77 while (it.hasNext()) {
3964f3d4eb18 Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7257
diff changeset
78 sb.append(controlSplit.probability((BeginNode) it.next()));
3964f3d4eb18 Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7257
diff changeset
79 if (it.hasNext()) {
3964f3d4eb18 Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7257
diff changeset
80 sb.append(", ");
3964f3d4eb18 Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7257
diff changeset
81 }
3964f3d4eb18 Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7257
diff changeset
82 }
3964f3d4eb18 Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7257
diff changeset
83 sb.append("]");
3964f3d4eb18 Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7257
diff changeset
84 Debug.log(sb.toString());
3964f3d4eb18 Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7257
diff changeset
85 }
5675
776366f3a41a A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
86 }