annotate graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/LoweringPhase.java @ 2946:0d103e2a38e5

More work on lowering phase.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Thu, 09 Jun 2011 19:39:03 +0200
parents 41318fcb6b56
children e86e83c5adbc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2941
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
1 /*
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
4 *
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
7 * published by the Free Software Foundation.
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
8 *
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
13 * accompanied this code).
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
14 *
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
18 *
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
21 * questions.
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
22 */
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
23 package com.oracle.max.graal.compiler.phases;
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
24
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
25 import java.util.*;
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
26
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
27 import com.oracle.max.graal.compiler.*;
2945
41318fcb6b56 Added two algorithms for identifying Java-level blocks.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2943
diff changeset
28 import com.oracle.max.graal.compiler.debug.*;
2941
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
29 import com.oracle.max.graal.compiler.ir.*;
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
30 import com.oracle.max.graal.compiler.schedule.*;
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
31 import com.oracle.max.graal.graph.*;
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
32
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
33 public class LoweringPhase extends Phase {
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
34 @Override
2946
0d103e2a38e5 More work on lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
35 protected void run(final Graph graph) {
0d103e2a38e5 More work on lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
36 final IdentifyBlocksPhase s = new IdentifyBlocksPhase(false);
2945
41318fcb6b56 Added two algorithms for identifying Java-level blocks.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2943
diff changeset
37 s.apply(graph);
41318fcb6b56 Added two algorithms for identifying Java-level blocks.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2943
diff changeset
38
41318fcb6b56 Added two algorithms for identifying Java-level blocks.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2943
diff changeset
39 // for (Block b : s.getBlocks()) {
41318fcb6b56 Added two algorithms for identifying Java-level blocks.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2943
diff changeset
40 // TTY.println("Java block for block " + b.blockID() + " is " + b.javaBlock().blockID());
41318fcb6b56 Added two algorithms for identifying Java-level blocks.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2943
diff changeset
41 // }
41318fcb6b56 Added two algorithms for identifying Java-level blocks.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2943
diff changeset
42
41318fcb6b56 Added two algorithms for identifying Java-level blocks.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2943
diff changeset
43
2946
0d103e2a38e5 More work on lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
44 for (final Node n : graph.getNodes()) {
0d103e2a38e5 More work on lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
45 if (n instanceof FixedNode) {
0d103e2a38e5 More work on lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
46 LoweringOp op = n.lookup(LoweringOp.class);
0d103e2a38e5 More work on lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
47 if (op != null) {
0d103e2a38e5 More work on lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
48 op.lower(n, new LoweringTool() {
0d103e2a38e5 More work on lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
49 @Override
0d103e2a38e5 More work on lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
50 public Node createStructuredBlockAnchor() {
0d103e2a38e5 More work on lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
51 Block block = s.getNodeToBlock().get(n);
0d103e2a38e5 More work on lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
52 Block javaBlock = block.javaBlock();
0d103e2a38e5 More work on lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
53 Node first = javaBlock.firstNode();
0d103e2a38e5 More work on lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
54 if (!(first instanceof Anchor) && !(first instanceof Merge)) {
0d103e2a38e5 More work on lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
55 Anchor a = new Anchor(graph);
0d103e2a38e5 More work on lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
56 assert first.predecessors().size() == 1;
0d103e2a38e5 More work on lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
57 Node pred = first.predecessors().get(0);
0d103e2a38e5 More work on lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
58 int predIndex = first.predecessorsIndex().get(0);
0d103e2a38e5 More work on lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
59 a.successors().setAndClear(Instruction.SUCCESSOR_NEXT, pred, predIndex);
0d103e2a38e5 More work on lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
60 pred.successors().set(predIndex, a);
0d103e2a38e5 More work on lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
61 javaBlock.setFirstNode(a);
0d103e2a38e5 More work on lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
62 }
0d103e2a38e5 More work on lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
63 return javaBlock.firstNode();
0d103e2a38e5 More work on lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
64 }
0d103e2a38e5 More work on lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
65 });
0d103e2a38e5 More work on lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
66 }
2941
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
67 }
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
68
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
69 }
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
70 }
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
71
2946
0d103e2a38e5 More work on lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
72 public interface LoweringTool {
0d103e2a38e5 More work on lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
73 Node createStructuredBlockAnchor();
2941
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
74 }
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
75
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
76 public interface LoweringOp extends Op {
2946
0d103e2a38e5 More work on lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2945
diff changeset
77 void lower(Node n, LoweringTool tool);
2941
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
78 }
cd4176d590e7 Towards lowering phase.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
79 }