comparison graal/Compiler/src/com/sun/c1x/ir/Op2.java @ 2507:9ec15d6914ca

Pull over of compiler from maxine repository.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Wed, 27 Apr 2011 11:43:22 +0200
parents
children
comparison
equal deleted inserted replaced
2506:4a3bf8a5bf41 2507:9ec15d6914ca
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.ir;
24
25 import com.sun.c1x.util.*;
26 import com.sun.cri.bytecode.*;
27 import com.sun.cri.ci.*;
28
29 /**
30 * The {@code Op2} class is the base of arithmetic and logic operations with two inputs.
31 *
32 * @author Ben L. Titzer
33 */
34 public abstract class Op2 extends Instruction {
35
36 /**
37 * The opcode of this instruction.
38 */
39 public final int opcode;
40
41 Value x;
42 Value y;
43
44 /**
45 * Creates a new Op2 instance.
46 * @param kind the result type of this instruction
47 * @param opcode the bytecode opcode
48 * @param x the first input instruction
49 * @param y the second input instruction
50 */
51 public Op2(CiKind kind, int opcode, Value x, Value y) {
52 super(kind);
53 this.opcode = opcode;
54 this.x = x;
55 this.y = y;
56 }
57
58 /**
59 * Gets the first input to this instruction.
60 * @return the first input to this instruction
61 */
62 public final Value x() {
63 return x;
64 }
65
66 /**
67 * Gets the second input to this instruction.
68 * @return the second input to this instruction
69 */
70 public final Value y() {
71 return y;
72 }
73
74 /**
75 * Swaps the operands of this instruction. This is only legal for commutative operations.
76 */
77 public void swapOperands() {
78 assert Bytecodes.isCommutative(opcode);
79 Value t = x;
80 x = y;
81 y = t;
82 }
83
84 /**
85 * Iterates over the inputs to this instruction.
86 * @param closure the closure to apply to each input value
87 */
88 @Override
89 public void inputValuesDo(ValueClosure closure) {
90 x = closure.apply(x);
91 y = closure.apply(y);
92 }
93
94 @Override
95 public int valueNumber() {
96 return Util.hash2(opcode, x, y);
97 }
98
99 @Override
100 public boolean valueEqual(Instruction i) {
101 if (i instanceof Op2) {
102 Op2 o = (Op2) i;
103 return opcode == o.opcode && x == o.x && y == o.y;
104 }
105 return false;
106 }
107 }