annotate graal/GraalCompiler/src/com/sun/c1x/ir/Instruction.java @ 2820:2b8ef0a06391

Clean up in the graph builder.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Mon, 30 May 2011 16:24:22 +0200
parents c3f64b66fc78
children 244921d7cf50
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
1 /*
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
2 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
4 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
7 * published by the Free Software Foundation.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
8 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
13 * accompanied this code).
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
14 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
18 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
21 * questions.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
22 */
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
23 package com.sun.c1x.ir;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
24
2756
bfcdda4fdd73 Removed the direct connection between BlockBegin and BlockEnd.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2716
diff changeset
25 import java.util.*;
bfcdda4fdd73 Removed the direct connection between BlockBegin and BlockEnd.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2716
diff changeset
26
2582
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
27 import com.oracle.graal.graph.*;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
28 import com.sun.c1x.*;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
29 import com.sun.c1x.value.*;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
30 import com.sun.cri.ci.*;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
31
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
32 /**
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
33 * Denotes an instruction node in the IR, which is a {@link Value} that
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
34 * can be added to a basic block (whereas other {@link Value} nodes such as {@link Phi} and
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
35 * {@link Local} cannot be added to basic blocks).
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
36 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
37 * Subclasses of instruction represent arithmetic and object operations,
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
38 * control flow operators, phi statements, method calls, the start of basic blocks, and
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
39 * the end of basic blocks.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
40 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
41 * Instruction nodes are chained together in a basic block through the embedded
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
42 * {@link Instruction#next} field. An Instruction may also have a list of {@link ExceptionHandler}s.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
43 */
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
44 public abstract class Instruction extends Value {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
45
2585
3e0e65161345 new node layout: Op2
Lukas Stadler <lukas.stadler@jku.at>
parents: 2584
diff changeset
46 private static final int INPUT_COUNT = 0;
2582
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
47
2585
3e0e65161345 new node layout: Op2
Lukas Stadler <lukas.stadler@jku.at>
parents: 2584
diff changeset
48 private static final int SUCCESSOR_COUNT = 1;
2799
e1dad0edd57a first part of loop reworking
Lukas Stadler <lukas.stadler@jku.at>
parents: 2793
diff changeset
49 public static final int SUCCESSOR_NEXT = 0;
2582
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
50
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
51 @Override
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
52 protected int inputCount() {
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
53 return super.inputCount() + INPUT_COUNT;
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
54 }
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
55
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
56 @Override
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
57 protected int successorCount() {
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
58 return super.successorCount() + SUCCESSOR_COUNT;
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
59 }
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
60
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
61 /**
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
62 * Links to next instruction in a basic block, to {@code null} if this instruction is the end of a basic block or to
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
63 * itself if not in a block.
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
64 */
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
65 public Instruction next() {
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
66 return (Instruction) successors().get(super.successorCount() + SUCCESSOR_NEXT);
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
67 }
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
68
2820
2b8ef0a06391 Clean up in the graph builder.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2805
diff changeset
69 public Node setNext(Instruction next) {
2582
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
70 return successors().set(super.successorCount() + SUCCESSOR_NEXT, next);
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
71 }
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
72
2799
e1dad0edd57a first part of loop reworking
Lukas Stadler <lukas.stadler@jku.at>
parents: 2793
diff changeset
73 public int nextIndex() {
e1dad0edd57a first part of loop reworking
Lukas Stadler <lukas.stadler@jku.at>
parents: 2793
diff changeset
74 return super.successorCount() + SUCCESSOR_NEXT;
e1dad0edd57a first part of loop reworking
Lukas Stadler <lukas.stadler@jku.at>
parents: 2793
diff changeset
75 }
e1dad0edd57a first part of loop reworking
Lukas Stadler <lukas.stadler@jku.at>
parents: 2793
diff changeset
76
2582
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
77
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
78 public static final int SYNCHRONIZATION_ENTRY_BCI = -1;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
79
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
80 /**
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
81 * Constructs a new instruction with the specified value type.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
82 * @param kind the value type for this instruction
2582
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
83 * @param inputCount
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
84 * @param successorCount
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
85 */
2582
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
86 public Instruction(CiKind kind, int inputCount, int successorCount, Graph graph) {
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
87 super(kind, inputCount + INPUT_COUNT, successorCount + SUCCESSOR_COUNT, graph);
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
88 C1XMetrics.HIRInstructions++;
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
89 }
768d77a1c7af new node layout: Instruction
Lukas Stadler <lukas.stadler@jku.at>
parents: 2541
diff changeset
90
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
91
2773
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2756
diff changeset
92 /**
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2756
diff changeset
93 * Gets the list of predecessors of this block.
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2756
diff changeset
94 * @return the predecessor list
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2756
diff changeset
95 */
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2756
diff changeset
96 @SuppressWarnings({ "unchecked", "rawtypes" })
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2756
diff changeset
97 public List<Instruction> blockPredecessors() {
2820
2b8ef0a06391 Clean up in the graph builder.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2805
diff changeset
98 return (List) Collections.unmodifiableList(predecessors());
2773
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2756
diff changeset
99 }
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2756
diff changeset
100
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2756
diff changeset
101 /**
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2756
diff changeset
102 * Get the number of predecessors.
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2756
diff changeset
103 * @return the number of predecessors
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2756
diff changeset
104 */
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2756
diff changeset
105 public int numberOfPreds() {
2820
2b8ef0a06391 Clean up in the graph builder.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2805
diff changeset
106 return predecessors().size();
2773
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2756
diff changeset
107 }
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2756
diff changeset
108
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2756
diff changeset
109 public Instruction predAt(int j) {
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2756
diff changeset
110 return (Instruction) predecessors().get(j);
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2756
diff changeset
111 }
27512ea6bbcb exception dispatch simplification:
Lukas Stadler <lukas.stadler@jku.at>
parents: 2756
diff changeset
112
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
113 /**
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
114 * Gets the state after the instruction, if it is recorded. Typically only
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
115 * instances of {@link BlockEnd} have a non-null state after.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
116 * @return the state after the instruction
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
117 */
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
118 public FrameState stateAfter() {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
119 return null;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
120 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
121 }