Mercurial > hg > graal-jvmci-8
comparison graal/GraalCompiler/src/com/sun/c1x/ir/Compare.java @ 2857:c6af2af32b3d
Merge.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Tue, 07 Jun 2011 15:59:08 +0200 |
parents | 3a4ad04d60a1 c6bdec623ef9 |
children |
comparison
equal
deleted
inserted
replaced
2856:3a4ad04d60a1 | 2857:c6af2af32b3d |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2011, 2011, Oracle and/or its affiliates. All rights reserved. | 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. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 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 | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
22 */ | 22 */ |
23 package com.sun.c1x.ir; | 23 package com.sun.c1x.ir; |
24 | 24 |
25 import com.oracle.graal.graph.*; | 25 import com.oracle.graal.graph.*; |
26 import com.sun.c1x.debug.*; | 26 import com.sun.c1x.debug.*; |
27 import com.sun.c1x.util.*; | 27 import com.sun.cri.bytecode.*; |
28 import com.sun.cri.ci.*; | 28 import com.sun.cri.ci.*; |
29 | 29 |
30 public final class Compare extends Value { | 30 /** |
31 * The {@code CompareOp} instruction represents comparisons such as equals, not equal, etc. | |
32 */ | |
33 public final class Compare extends Binary { | |
31 | 34 |
32 private static final int INPUT_COUNT = 2; | 35 private static final int INPUT_COUNT = 0; |
33 private static final int INPUT_X = 0; | |
34 private static final int INPUT_Y = 1; | |
35 | |
36 private static final int SUCCESSOR_COUNT = 0; | 36 private static final int SUCCESSOR_COUNT = 0; |
37 | 37 |
38 @Override | |
39 protected int inputCount() { | |
40 return super.inputCount() + INPUT_COUNT; | |
41 } | |
42 | |
43 @Override | |
44 protected int successorCount() { | |
45 return super.successorCount() + SUCCESSOR_COUNT; | |
46 } | |
47 | |
48 /** | 38 /** |
49 * The instruction that produces the first input to this comparison. | 39 * Creates a new compare operation. |
40 * @param opcode the bytecode opcode | |
41 * @param kind the result kind | |
42 * @param x the first input | |
43 * @param y the second input | |
50 */ | 44 */ |
51 public Value x() { | 45 public Compare(int opcode, CiKind kind, Value x, Value y, Graph graph) { |
52 return (Value) inputs().get(super.inputCount() + INPUT_X); | 46 super(kind, opcode, x, y, INPUT_COUNT, SUCCESSOR_COUNT, graph); |
53 } | |
54 | |
55 public Value setX(Value n) { | |
56 return (Value) inputs().set(super.inputCount() + INPUT_X, n); | |
57 } | |
58 | |
59 /** | |
60 * The instruction that produces the second input to this comparison. | |
61 */ | |
62 public Value y() { | |
63 return (Value) inputs().get(super.inputCount() + INPUT_Y); | |
64 } | |
65 | |
66 public Value setY(Value n) { | |
67 return (Value) inputs().set(super.inputCount() + INPUT_Y, n); | |
68 } | |
69 | |
70 Condition condition; | |
71 boolean unorderedIsTrue; | |
72 | |
73 /** | |
74 * Constructs a new If instruction. | |
75 * @param x the instruction producing the first input to the instruction | |
76 * @param condition the condition (comparison operation) | |
77 * @param y the instruction that produces the second input to this instruction | |
78 * @param graph | |
79 */ | |
80 public Compare(Value x, Condition condition, Value y, Graph graph) { | |
81 super(CiKind.Illegal, INPUT_COUNT, SUCCESSOR_COUNT, graph); | |
82 assert (x == null && y == null) || Util.archKindsEqual(x, y); | |
83 this.condition = condition; | |
84 setX(x); | |
85 setY(y); | |
86 } | |
87 | |
88 /** | |
89 * Gets the condition (comparison operation) for this instruction. | |
90 * @return the condition | |
91 */ | |
92 public Condition condition() { | |
93 return condition; | |
94 } | |
95 | |
96 /** | |
97 * Checks whether unordered inputs mean true or false. | |
98 * @return {@code true} if unordered inputs produce true | |
99 */ | |
100 public boolean unorderedIsTrue() { | |
101 return unorderedIsTrue; | |
102 } | |
103 | |
104 /** | |
105 * Swaps the operands to this if and reverses the condition (e.g. > goes to <=). | |
106 * @see Condition#mirror() | |
107 */ | |
108 public void swapOperands() { | |
109 condition = condition.mirror(); | |
110 Value t = x(); | |
111 setX(y()); | |
112 setY(t); | |
113 } | 47 } |
114 | 48 |
115 @Override | 49 @Override |
116 public void accept(ValueVisitor v) { | 50 public void accept(ValueVisitor v) { |
51 v.visitCompare(this); | |
117 } | 52 } |
118 | 53 |
119 @Override | 54 @Override |
120 public void print(LogStream out) { | 55 public void print(LogStream out) { |
121 out.print("comp "). | 56 out.print(x()). |
122 print(x()). | 57 print(' '). |
123 print(' '). | 58 print(Bytecodes.operator(opcode)). |
124 print(condition().operator). | 59 print(' '). |
125 print(' '). | 60 print(y()); |
126 print(y()); | |
127 } | |
128 | |
129 @Override | |
130 public String shortName() { | |
131 return "Comp " + condition.operator; | |
132 } | 61 } |
133 | 62 |
134 @Override | 63 @Override |
135 public Node copy(Graph into) { | 64 public Node copy(Graph into) { |
136 Compare x = new Compare(null, condition, null, into); | 65 Compare x = new Compare(opcode, kind, null, null, into); |
137 x.unorderedIsTrue = unorderedIsTrue; | |
138 x.setNonNull(isNonNull()); | |
139 return x; | 66 return x; |
140 } | 67 } |
141 } | 68 } |