annotate graal/com.oracle.graal.loop/src/com/oracle/graal/loop/LoopFragmentInside.java @ 9602:19c5a07c7843

Introduce a graph() method that returns a StructuredGraph, to make many explicit casts unnecessary
author Christian Wimmer <christian.wimmer@oracle.com>
date Tue, 07 May 2013 12:03:21 -0700
parents ae815a4c112a
children 6a1b7d28f2d4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5489
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
1 /*
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved.
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
4 *
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
7 * published by the Free Software Foundation.
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
8 *
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
13 * accompanied this code).
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
14 *
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
18 *
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
21 * questions.
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
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;
5489
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
24
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
25 import java.util.*;
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
26
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
27 import com.oracle.graal.graph.Graph.DuplicationReplacement;
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
28 import com.oracle.graal.graph.*;
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
29 import com.oracle.graal.graph.iterators.*;
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
30 import com.oracle.graal.nodes.*;
5678
2f714239cc68 Fix warning,
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5671
diff changeset
31 import com.oracle.graal.nodes.PhiNode.PhiType;
5671
a65b2a11bf34 Fix for peeling and VirtualStateNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5639
diff changeset
32 import com.oracle.graal.nodes.VirtualState.NodeClosure;
5489
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
33 import com.oracle.graal.nodes.util.*;
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
34
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6545
diff changeset
35 public class LoopFragmentInside extends LoopFragment {
5489
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
36
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6545
diff changeset
37 /**
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6545
diff changeset
38 * mergedInitializers. When an inside fragment's (loop)ends are merged to create a unique exit
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6545
diff changeset
39 * point, some phis must be created : they phis together all the back-values of the loop-phis
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6545
diff changeset
40 * These can then be used to update the loop-phis' forward edge value ('initializer') in the
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6545
diff changeset
41 * peeling case. In the unrolling case they will be used as the value that replace the loop-phis
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6545
diff changeset
42 * of the duplicated inside fragment
5489
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
43 */
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
44 private Map<PhiNode, ValueNode> mergedInitializers;
5741
c84c75339af1 Work on loop unswitching, things look ok, still disabled until FloatingRead preserves loop-closed form
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5717
diff changeset
45 private final DuplicationReplacement dataFixBefore = new DuplicationReplacement() {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6545
diff changeset
46
5489
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
47 @Override
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
48 public Node replacement(Node oriInput) {
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
49 if (!(oriInput instanceof ValueNode)) {
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
50 return oriInput;
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
51 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
52 return prim((ValueNode) oriInput);
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
53 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
54 };
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
55
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
56 public LoopFragmentInside(LoopEx loop) {
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
57 super(loop);
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
58 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
59
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
60 public LoopFragmentInside(LoopFragmentInside original) {
5741
c84c75339af1 Work on loop unswitching, things look ok, still disabled until FloatingRead preserves loop-closed form
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5717
diff changeset
61 super(null, original);
5489
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
62 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
63
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
64 @Override
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
65 public LoopFragmentInside duplicate() {
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
66 assert !isDuplicate();
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
67 return new LoopFragmentInside(this);
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
68 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
69
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
70 @Override
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
71 public LoopFragmentInside original() {
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
72 return (LoopFragmentInside) super.original();
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
73 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
74
5498
eb0d4946a1ea Fix compiler warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5489
diff changeset
75 @SuppressWarnings("unused")
5489
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
76 public void appendInside(LoopEx loop) {
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
77 // TODO (gd)
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
78 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
79
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
80 @Override
5741
c84c75339af1 Work on loop unswitching, things look ok, still disabled until FloatingRead preserves loop-closed form
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5717
diff changeset
81 public LoopEx loop() {
c84c75339af1 Work on loop unswitching, things look ok, still disabled until FloatingRead preserves loop-closed form
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5717
diff changeset
82 assert !this.isDuplicate();
c84c75339af1 Work on loop unswitching, things look ok, still disabled until FloatingRead preserves loop-closed form
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5717
diff changeset
83 return super.loop();
c84c75339af1 Work on loop unswitching, things look ok, still disabled until FloatingRead preserves loop-closed form
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5717
diff changeset
84 }
c84c75339af1 Work on loop unswitching, things look ok, still disabled until FloatingRead preserves loop-closed form
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5717
diff changeset
85
c84c75339af1 Work on loop unswitching, things look ok, still disabled until FloatingRead preserves loop-closed form
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5717
diff changeset
86 @Override
5489
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
87 public void insertBefore(LoopEx loop) {
5741
c84c75339af1 Work on loop unswitching, things look ok, still disabled until FloatingRead preserves loop-closed form
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5717
diff changeset
88 assert this.isDuplicate() && this.original().loop() == loop;
c84c75339af1 Work on loop unswitching, things look ok, still disabled until FloatingRead preserves loop-closed form
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5717
diff changeset
89
c84c75339af1 Work on loop unswitching, things look ok, still disabled until FloatingRead preserves loop-closed form
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5717
diff changeset
90 patchNodes(dataFixBefore);
5489
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
91
9436
ae815a4c112a Rename BeginNode => AbstractBeginNode and make abstract. Introduce concrete subclass BeginNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9434
diff changeset
92 AbstractBeginNode end = mergeEnds();
5489
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
93
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
94 original().patchPeeling(this);
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
95
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
96 mergeEarlyExits();
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
97
9436
ae815a4c112a Rename BeginNode => AbstractBeginNode and make abstract. Introduce concrete subclass BeginNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9434
diff changeset
98 AbstractBeginNode entry = getDuplicatedNode(loop.loopBegin());
5519
cedae73d9c2a Fix problem with jython and tmt
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489
diff changeset
99 FrameState state = entry.stateAfter();
cedae73d9c2a Fix problem with jython and tmt
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489
diff changeset
100 if (state != null) {
cedae73d9c2a Fix problem with jython and tmt
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489
diff changeset
101 entry.setStateAfter(null);
cedae73d9c2a Fix problem with jython and tmt
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489
diff changeset
102 GraphUtil.killWithUnusedFloatingInputs(state);
cedae73d9c2a Fix problem with jython and tmt
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489
diff changeset
103 }
5489
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
104 loop.entryPoint().replaceAtPredecessor(entry);
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
105 end.setNext(loop.entryPoint());
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
106 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
107
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
108 @Override
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
109 public NodeIterable<Node> nodes() {
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
110 if (nodes == null) {
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
111 LoopFragmentWhole whole = loop().whole();
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
112 whole.nodes(); // init nodes bitmap in whole
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
113 nodes = whole.nodes.copy();
5519
cedae73d9c2a Fix problem with jython and tmt
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489
diff changeset
114 // remove the phis
cedae73d9c2a Fix problem with jython and tmt
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489
diff changeset
115 for (PhiNode phi : loop().loopBegin().phis()) {
5489
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
116 nodes.clear(phi);
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
117 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
118 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
119 return nodes;
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
120 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
121
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
122 @Override
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
123 protected DuplicationReplacement getDuplicationReplacement() {
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
124 final LoopBeginNode loopBegin = loop().loopBegin();
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
125 final StructuredGraph graph = graph();
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
126 return new DuplicationReplacement() {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6545
diff changeset
127
5489
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
128 @Override
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
129 public Node replacement(Node original) {
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
130 if (original == loopBegin) {
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
131 return graph.add(new BeginNode());
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
132 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
133 if (original instanceof LoopExitNode && ((LoopExitNode) original).loopBegin() == loopBegin) {
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
134 return graph.add(new BeginNode());
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
135 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
136 if (original instanceof LoopEndNode && ((LoopEndNode) original).loopBegin() == loopBegin) {
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
137 return graph.add(new EndNode());
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
138 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
139 return original;
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
140 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
141 };
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
142 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
143
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
144 @Override
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
145 protected void finishDuplication() {
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
146 // TODO (gd) ?
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
147 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
148
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
149 private void patchPeeling(LoopFragmentInside peel) {
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
150 LoopBeginNode loopBegin = loop().loopBegin();
9602
19c5a07c7843 Introduce a graph() method that returns a StructuredGraph, to make many explicit casts unnecessary
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9436
diff changeset
151 StructuredGraph graph = loopBegin.graph();
5489
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
152 List<PhiNode> newPhis = new LinkedList<>();
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
153 for (PhiNode phi : loopBegin.phis().snapshot()) {
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
154 ValueNode first;
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
155 if (loopBegin.loopEnds().count() == 1) {
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
156 ValueNode b = phi.valueAt(loopBegin.loopEnds().first()); // back edge value
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
157 first = peel.prim(b); // corresponding value in the peel
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
158 } else {
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
159 first = peel.mergedInitializers.get(phi);
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
160 }
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6545
diff changeset
161 // create a new phi (we don't patch the old one since some usages of the old one may
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6545
diff changeset
162 // still be valid)
8551
0f6dd67470d9 location identity on PhiNodes and ProxyNodes
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
163 PhiNode newPhi = graph.add(phi.type() == PhiType.Value ? new PhiNode(phi.kind(), loopBegin) : new PhiNode(phi.type(), loopBegin, phi.getIdentity()));
5489
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
164 newPhi.addInput(first);
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
165 for (LoopEndNode end : loopBegin.orderedLoopEnds()) {
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
166 newPhi.addInput(phi.valueAt(end));
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
167 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
168 peel.putDuplicatedNode(phi, newPhi);
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
169 newPhis.add(newPhi);
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
170 for (Node usage : phi.usages().snapshot()) {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6545
diff changeset
171 if (peel.getDuplicatedNode(usage) != null) { // patch only usages that should use
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6545
diff changeset
172 // the new phi ie usages that were
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6545
diff changeset
173 // peeled
5489
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
174 usage.replaceFirstInput(phi, newPhi);
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
175 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
176 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
177 }
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6545
diff changeset
178 // check new phis to see if they have as input some old phis, replace those inputs with the
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6545
diff changeset
179 // new corresponding phis
5489
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
180 for (PhiNode phi : newPhis) {
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
181 for (int i = 0; i < phi.valueCount(); i++) {
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
182 ValueNode v = phi.valueAt(i);
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
183 if (loopBegin.isPhiAtMerge(v)) {
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
184 PhiNode newV = peel.getDuplicatedNode((PhiNode) v);
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
185 if (newV != null) {
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
186 phi.setValueAt(i, newV);
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
187 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
188 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
189 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
190 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
191 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
192
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
193 /**
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
194 * Gets the corresponding value in this fragment.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6545
diff changeset
195 *
5489
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
196 * @param b original value
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
197 * @return corresponding value in the peel
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
198 */
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
199 private ValueNode prim(ValueNode b) {
5741
c84c75339af1 Work on loop unswitching, things look ok, still disabled until FloatingRead preserves loop-closed form
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5717
diff changeset
200 assert isDuplicate();
c84c75339af1 Work on loop unswitching, things look ok, still disabled until FloatingRead preserves loop-closed form
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5717
diff changeset
201 LoopBeginNode loopBegin = original().loop().loopBegin();
5489
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
202 if (loopBegin.isPhiAtMerge(b)) {
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
203 PhiNode phi = (PhiNode) b;
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
204 return phi.valueAt(loopBegin.forwardEnd());
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
205 } else if (nodesReady) {
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
206 ValueNode v = getDuplicatedNode(b);
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
207 if (v == null) {
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
208 return b;
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
209 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
210 return v;
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
211 } else {
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
212 return b;
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
213 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
214 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
215
9436
ae815a4c112a Rename BeginNode => AbstractBeginNode and make abstract. Introduce concrete subclass BeginNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9434
diff changeset
216 private AbstractBeginNode mergeEnds() {
5741
c84c75339af1 Work on loop unswitching, things look ok, still disabled until FloatingRead preserves loop-closed form
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5717
diff changeset
217 assert isDuplicate();
9434
50f02c7d1cec Rename EndNode => AbstractEndNode and make abstract class. Introduce concrete EndNode subclass.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9234
diff changeset
218 List<AbstractEndNode> endsToMerge = new LinkedList<>();
50f02c7d1cec Rename EndNode => AbstractEndNode and make abstract class. Introduce concrete EndNode subclass.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9234
diff changeset
219 Map<AbstractEndNode, LoopEndNode> reverseEnds = new HashMap<>(); // map peel's exit to the
50f02c7d1cec Rename EndNode => AbstractEndNode and make abstract class. Introduce concrete EndNode subclass.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9234
diff changeset
220 // corresponding loop exits
5741
c84c75339af1 Work on loop unswitching, things look ok, still disabled until FloatingRead preserves loop-closed form
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5717
diff changeset
221 LoopBeginNode loopBegin = original().loop().loopBegin();
5489
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
222 for (LoopEndNode le : loopBegin.loopEnds()) {
9434
50f02c7d1cec Rename EndNode => AbstractEndNode and make abstract class. Introduce concrete EndNode subclass.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9234
diff changeset
223 AbstractEndNode duplicate = getDuplicatedNode(le);
5489
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
224 if (duplicate != null) {
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
225 endsToMerge.add(duplicate);
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
226 reverseEnds.put(duplicate, le);
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
227 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
228 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
229 mergedInitializers = new IdentityHashMap<>();
9436
ae815a4c112a Rename BeginNode => AbstractBeginNode and make abstract. Introduce concrete subclass BeginNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9434
diff changeset
230 AbstractBeginNode newExit;
5489
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
231 StructuredGraph graph = graph();
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
232 if (endsToMerge.size() == 1) {
9434
50f02c7d1cec Rename EndNode => AbstractEndNode and make abstract class. Introduce concrete EndNode subclass.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9234
diff changeset
233 AbstractEndNode end = endsToMerge.get(0);
5489
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
234 assert end.usages().count() == 0;
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
235 newExit = graph.add(new BeginNode());
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
236 end.replaceAtPredecessor(newExit);
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
237 end.safeDelete();
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
238 } else {
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
239 assert endsToMerge.size() > 1;
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
240 MergeNode newExitMerge = graph.add(new MergeNode());
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
241 newExit = newExitMerge;
5519
cedae73d9c2a Fix problem with jython and tmt
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489
diff changeset
242 FrameState state = loopBegin.stateAfter();
cedae73d9c2a Fix problem with jython and tmt
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489
diff changeset
243 FrameState duplicateState = null;
cedae73d9c2a Fix problem with jython and tmt
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489
diff changeset
244 if (state != null) {
5713
8c478272fb34 Cleanup and fixes in handling of VirtualStates around loop exits merging
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5678
diff changeset
245 duplicateState = state.duplicateWithVirtualState();
5519
cedae73d9c2a Fix problem with jython and tmt
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489
diff changeset
246 newExitMerge.setStateAfter(duplicateState);
cedae73d9c2a Fix problem with jython and tmt
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489
diff changeset
247 }
9434
50f02c7d1cec Rename EndNode => AbstractEndNode and make abstract class. Introduce concrete EndNode subclass.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9234
diff changeset
248 for (AbstractEndNode end : endsToMerge) {
5489
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
249 newExitMerge.addForwardEnd(end);
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
250 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
251
5671
a65b2a11bf34 Fix for peeling and VirtualStateNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5639
diff changeset
252 for (final PhiNode phi : loopBegin.phis().snapshot()) {
8551
0f6dd67470d9 location identity on PhiNodes and ProxyNodes
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
253 final PhiNode firstPhi = graph.add(phi.type() == PhiType.Value ? new PhiNode(phi.kind(), newExitMerge) : new PhiNode(phi.type(), newExitMerge, phi.getIdentity()));
9434
50f02c7d1cec Rename EndNode => AbstractEndNode and make abstract class. Introduce concrete EndNode subclass.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9234
diff changeset
254 for (AbstractEndNode end : newExitMerge.forwardEnds()) {
5489
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
255 LoopEndNode loopEnd = reverseEnds.get(end);
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
256 ValueNode prim = prim(phi.valueAt(loopEnd));
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
257 assert prim != null;
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
258 firstPhi.addInput(prim);
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
259 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
260 ValueNode initializer = firstPhi;
5519
cedae73d9c2a Fix problem with jython and tmt
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489
diff changeset
261 if (duplicateState != null) {
5671
a65b2a11bf34 Fix for peeling and VirtualStateNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5639
diff changeset
262 // fix the merge's state after
a65b2a11bf34 Fix for peeling and VirtualStateNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5639
diff changeset
263 duplicateState.applyToNonVirtual(new NodeClosure<ValueNode>() {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6545
diff changeset
264
5671
a65b2a11bf34 Fix for peeling and VirtualStateNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5639
diff changeset
265 @Override
a65b2a11bf34 Fix for peeling and VirtualStateNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5639
diff changeset
266 public void apply(Node from, ValueNode node) {
a65b2a11bf34 Fix for peeling and VirtualStateNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5639
diff changeset
267 if (node == phi) {
a65b2a11bf34 Fix for peeling and VirtualStateNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5639
diff changeset
268 from.replaceFirstInput(phi, firstPhi);
a65b2a11bf34 Fix for peeling and VirtualStateNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5639
diff changeset
269 }
a65b2a11bf34 Fix for peeling and VirtualStateNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5639
diff changeset
270 }
a65b2a11bf34 Fix for peeling and VirtualStateNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5639
diff changeset
271 });
5519
cedae73d9c2a Fix problem with jython and tmt
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489
diff changeset
272 }
5489
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
273 mergedInitializers.put(phi, initializer);
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
274 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
275 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
276 return newExit;
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
277 }
5d0d72b37f88 Switch to new loop transformation framework, use it for peeling and full unrolling for snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
278 }