comparison graal/GraalCompiler/src/com/sun/c1x/ir/ArithmeticOp.java @ 2509:16b9a8b5ad39

Renamings Runtime=>GraalRuntime and Compiler=>GraalCompiler
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Wed, 27 Apr 2011 11:50:44 +0200
parents graal/Compiler/src/com/sun/c1x/ir/ArithmeticOp.java@9ec15d6914ca
children e1ba5a93e997
comparison
equal deleted inserted replaced
2508:fea94949e0a2 2509:16b9a8b5ad39
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.*;
26 import com.sun.c1x.debug.*;
27 import com.sun.c1x.value.*;
28 import com.sun.cri.bytecode.*;
29 import com.sun.cri.ci.*;
30
31 /**
32 * The {@code ArithmeticOp} class represents arithmetic operations such as addition, subtraction, etc.
33 *
34 * @author Ben L. Titzer
35 */
36 public final class ArithmeticOp extends Op2 {
37
38 private FrameState stateBefore;
39
40 /**
41 * Creates a new arithmetic operation.
42 * @param opcode the bytecode opcode
43 * @param kind the result kind of the operation
44 * @param x the first input instruction
45 * @param y the second input instruction
46 * @param isStrictFP indicates this operation has strict rounding semantics
47 * @param stateBefore the state for instructions that may trap
48 */
49 public ArithmeticOp(int opcode, CiKind kind, Value x, Value y, boolean isStrictFP, FrameState stateBefore) {
50 super(kind, opcode, x, y);
51 initFlag(Flag.IsStrictFP, isStrictFP);
52 if (stateBefore != null) {
53 // state before is only used in the case of a division or remainder,
54 // and isn't needed if the zero check is redundant
55 if (y.isConstant()) {
56 long divisor = y.asConstant().asLong();
57 if (divisor != 0) {
58 C1XMetrics.ZeroChecksRedundant++;
59 setFlag(Flag.NoZeroCheck);
60 } else {
61 this.stateBefore = stateBefore;
62 }
63 if (divisor != -1) {
64 C1XMetrics.DivideSpecialChecksRedundant++;
65 setFlag(Flag.NoDivSpecialCase);
66 }
67 } else {
68 this.stateBefore = stateBefore;
69 }
70 }
71 }
72
73 @Override
74 public FrameState stateBefore() {
75 return stateBefore;
76 }
77
78 /**
79 * Checks whether this instruction has strict fp semantics.
80 * @return {@code true} if this instruction has strict fp semantics
81 */
82 public boolean isStrictFP() {
83 return checkFlag(Flag.IsStrictFP);
84 }
85
86 /**
87 * Checks whether this instruction can cause a trap. For arithmetic operations,
88 * only division and remainder operations can cause traps.
89 * @return {@code true} if this instruction can cause a trap
90 */
91 @Override
92 public boolean canTrap() {
93 return stateBefore != null;
94 }
95
96 @Override
97 public void accept(ValueVisitor v) {
98 v.visitArithmeticOp(this);
99 }
100
101 public boolean isCommutative() {
102 return Bytecodes.isCommutative(opcode);
103 }
104
105 public boolean needsZeroCheck() {
106 return !checkFlag(Flag.NoZeroCheck);
107 }
108
109 public void eliminateZeroCheck() {
110 clearRuntimeCheck(Flag.NoZeroCheck);
111 }
112
113 @Override
114 public void print(LogStream out) {
115 out.print(x()).
116 print(' ').
117 print(Bytecodes.operator(opcode)).
118 print(' ').
119 print(y());
120 }
121 }