comparison graal/com.oracle.max.graal.compiler/src/com/sun/c1x/lir/LIRBranch.java @ 2872:0341b6424579

Project renaming.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Wed, 08 Jun 2011 08:42:25 +0200
parents graal/GraalCompiler/src/com/sun/c1x/lir/LIRBranch.java@c379183d1c54
children
comparison
equal deleted inserted replaced
2871:d704eb526603 2872:0341b6424579
1 /*
2 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package com.sun.c1x.lir;
24
25 import com.oracle.max.asm.*;
26 import com.sun.c1x.ir.*;
27 import com.sun.cri.ci.*;
28
29 /**
30 * @author Marcelo Cintra
31 * @author Thomas Wuerthinger
32 *
33 */
34 public class LIRBranch extends LIRInstruction {
35
36 private Condition cond;
37 private CiKind kind;
38 private Label label;
39
40 /**
41 * The target block of this branch.
42 */
43 private LIRBlock block;
44
45 /**
46 * This is the unordered block for a float branch.
47 */
48 private LIRBlock unorderedBlock;
49
50
51 public LIRBranch(Condition cond, Label label) {
52 this(cond, label, null);
53 }
54
55 /**
56 * Creates a new LIRBranch instruction.
57 *
58 * @param cond the branch condition
59 * @param label target label
60 *
61 */
62 public LIRBranch(Condition cond, Label label, LIRDebugInfo info) {
63 super(LIROpcode.Branch, CiValue.IllegalValue, info, false);
64 this.cond = cond;
65 this.label = label;
66 }
67
68 /**
69 * Creates a new LIRBranch instruction.
70 *
71 * @param cond
72 * @param kind
73 * @param block
74 *
75 */
76 public LIRBranch(Condition cond, CiKind kind, LIRBlock block) {
77 super(LIROpcode.Branch, CiValue.IllegalValue, null, false);
78 this.cond = cond;
79 this.kind = kind;
80 this.label = block.label();
81 this.block = block;
82 this.unorderedBlock = null;
83 }
84
85 public LIRBranch(Condition cond, CiKind kind, LIRBlock block, LIRBlock ublock) {
86 super(LIROpcode.CondFloatBranch, CiValue.IllegalValue, null, false);
87 this.cond = cond;
88 this.kind = kind;
89 this.label = block.label();
90 this.block = block;
91 this.unorderedBlock = ublock;
92 }
93
94 /**
95 * @return the condition
96 */
97 public Condition cond() {
98 return cond;
99 }
100
101 public Label label() {
102 return label;
103 }
104
105 public LIRBlock block() {
106 return block;
107 }
108
109 public LIRBlock unorderedBlock() {
110 return unorderedBlock;
111 }
112
113 public void changeBlock(LIRBlock b) {
114 assert block != null : "must have old block";
115 assert block.label() == label() : "must be equal";
116
117 this.block = b;
118 this.label = b.label();
119 }
120
121 public void changeUblock(LIRBlock b) {
122 assert unorderedBlock != null : "must have old block";
123 this.unorderedBlock = b;
124 }
125
126 public void negateCondition() {
127 cond = cond.negate();
128 }
129
130 @Override
131 public void emitCode(LIRAssembler masm) {
132 masm.emitBranch(this);
133 }
134
135 @Override
136 public String operationString(OperandFormatter operandFmt) {
137 StringBuilder buf = new StringBuilder(cond().operator).append(' ');
138 if (block() != null) {
139 buf.append("[B").append(block.blockID()).append(']');
140 } else if (label().isBound()) {
141 buf.append("[label:0x").append(Integer.toHexString(label().position())).append(']');
142 } else {
143 buf.append("[label:??]");
144 }
145 if (unorderedBlock() != null) {
146 buf.append("unordered: [B").append(unorderedBlock().blockID()).append(']');
147 }
148 return buf.toString();
149 }
150
151 public void substitute(LIRBlock oldBlock, LIRBlock newBlock) {
152 if (block == oldBlock) {
153 block = newBlock;
154 LIRInstruction instr = newBlock.lir().instructionsList().get(0);
155 assert instr instanceof LIRLabel : "first instruction of block must be label";
156 label = ((LIRLabel) instr).label();
157 }
158 if (unorderedBlock == oldBlock) {
159 unorderedBlock = newBlock;
160 }
161 }
162 }