1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/opto/mulnode.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,266 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_OPTO_MULNODE_HPP 1.29 +#define SHARE_VM_OPTO_MULNODE_HPP 1.30 + 1.31 +#include "opto/node.hpp" 1.32 +#include "opto/opcodes.hpp" 1.33 +#include "opto/type.hpp" 1.34 + 1.35 +// Portions of code courtesy of Clifford Click 1.36 + 1.37 +class PhaseTransform; 1.38 + 1.39 +//------------------------------MulNode---------------------------------------- 1.40 +// Classic MULTIPLY functionality. This covers all the usual 'multiply' 1.41 +// behaviors for an algebraic ring. Multiply-integer, multiply-float, 1.42 +// multiply-double, and binary-and are all inherited from this class. The 1.43 +// various identity values are supplied by virtual functions. 1.44 +class MulNode : public Node { 1.45 + virtual uint hash() const; 1.46 +public: 1.47 + MulNode( Node *in1, Node *in2 ): Node(0,in1,in2) { 1.48 + init_class_id(Class_Mul); 1.49 + } 1.50 + 1.51 + // Handle algebraic identities here. If we have an identity, return the Node 1.52 + // we are equivalent to. We look for "add of zero" as an identity. 1.53 + virtual Node *Identity( PhaseTransform *phase ); 1.54 + 1.55 + // We also canonicalize the Node, moving constants to the right input, 1.56 + // and flatten expressions (so that 1+x+2 becomes x+3). 1.57 + virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 1.58 + 1.59 + // Compute a new Type for this node. Basically we just do the pre-check, 1.60 + // then call the virtual add() to set the type. 1.61 + virtual const Type *Value( PhaseTransform *phase ) const; 1.62 + 1.63 + // Supplied function returns the product of the inputs. 1.64 + // This also type-checks the inputs for sanity. Guaranteed never to 1.65 + // be passed a TOP or BOTTOM type, these are filtered out by a pre-check. 1.66 + // This call recognizes the multiplicative zero type. 1.67 + virtual const Type *mul_ring( const Type *, const Type * ) const = 0; 1.68 + 1.69 + // Supplied function to return the multiplicative identity type 1.70 + virtual const Type *mul_id() const = 0; 1.71 + 1.72 + // Supplied function to return the additive identity type 1.73 + virtual const Type *add_id() const = 0; 1.74 + 1.75 + // Supplied function to return the additive opcode 1.76 + virtual int add_opcode() const = 0; 1.77 + 1.78 + // Supplied function to return the multiplicative opcode 1.79 + virtual int mul_opcode() const = 0; 1.80 + 1.81 +}; 1.82 + 1.83 +//------------------------------MulINode--------------------------------------- 1.84 +// Multiply 2 integers 1.85 +class MulINode : public MulNode { 1.86 +public: 1.87 + MulINode( Node *in1, Node *in2 ) : MulNode(in1,in2) {} 1.88 + virtual int Opcode() const; 1.89 + virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 1.90 + virtual const Type *mul_ring( const Type *, const Type * ) const; 1.91 + const Type *mul_id() const { return TypeInt::ONE; } 1.92 + const Type *add_id() const { return TypeInt::ZERO; } 1.93 + int add_opcode() const { return Op_AddI; } 1.94 + int mul_opcode() const { return Op_MulI; } 1.95 + const Type *bottom_type() const { return TypeInt::INT; } 1.96 + virtual uint ideal_reg() const { return Op_RegI; } 1.97 +}; 1.98 + 1.99 +//------------------------------MulLNode--------------------------------------- 1.100 +// Multiply 2 longs 1.101 +class MulLNode : public MulNode { 1.102 +public: 1.103 + MulLNode( Node *in1, Node *in2 ) : MulNode(in1,in2) {} 1.104 + virtual int Opcode() const; 1.105 + virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 1.106 + virtual const Type *mul_ring( const Type *, const Type * ) const; 1.107 + const Type *mul_id() const { return TypeLong::ONE; } 1.108 + const Type *add_id() const { return TypeLong::ZERO; } 1.109 + int add_opcode() const { return Op_AddL; } 1.110 + int mul_opcode() const { return Op_MulL; } 1.111 + const Type *bottom_type() const { return TypeLong::LONG; } 1.112 + virtual uint ideal_reg() const { return Op_RegL; } 1.113 +}; 1.114 + 1.115 + 1.116 +//------------------------------MulFNode--------------------------------------- 1.117 +// Multiply 2 floats 1.118 +class MulFNode : public MulNode { 1.119 +public: 1.120 + MulFNode( Node *in1, Node *in2 ) : MulNode(in1,in2) {} 1.121 + virtual int Opcode() const; 1.122 + virtual const Type *mul_ring( const Type *, const Type * ) const; 1.123 + const Type *mul_id() const { return TypeF::ONE; } 1.124 + const Type *add_id() const { return TypeF::ZERO; } 1.125 + int add_opcode() const { return Op_AddF; } 1.126 + int mul_opcode() const { return Op_MulF; } 1.127 + const Type *bottom_type() const { return Type::FLOAT; } 1.128 + virtual uint ideal_reg() const { return Op_RegF; } 1.129 +}; 1.130 + 1.131 +//------------------------------MulDNode--------------------------------------- 1.132 +// Multiply 2 doubles 1.133 +class MulDNode : public MulNode { 1.134 +public: 1.135 + MulDNode( Node *in1, Node *in2 ) : MulNode(in1,in2) {} 1.136 + virtual int Opcode() const; 1.137 + virtual const Type *mul_ring( const Type *, const Type * ) const; 1.138 + const Type *mul_id() const { return TypeD::ONE; } 1.139 + const Type *add_id() const { return TypeD::ZERO; } 1.140 + int add_opcode() const { return Op_AddD; } 1.141 + int mul_opcode() const { return Op_MulD; } 1.142 + const Type *bottom_type() const { return Type::DOUBLE; } 1.143 + virtual uint ideal_reg() const { return Op_RegD; } 1.144 +}; 1.145 + 1.146 +//-------------------------------MulHiLNode------------------------------------ 1.147 +// Upper 64 bits of a 64 bit by 64 bit multiply 1.148 +class MulHiLNode : public Node { 1.149 +public: 1.150 + MulHiLNode( Node *in1, Node *in2 ) : Node(0,in1,in2) {} 1.151 + virtual int Opcode() const; 1.152 + virtual const Type *Value( PhaseTransform *phase ) const; 1.153 + const Type *bottom_type() const { return TypeLong::LONG; } 1.154 + virtual uint ideal_reg() const { return Op_RegL; } 1.155 +}; 1.156 + 1.157 +//------------------------------AndINode--------------------------------------- 1.158 +// Logically AND 2 integers. Included with the MUL nodes because it inherits 1.159 +// all the behavior of multiplication on a ring. 1.160 +class AndINode : public MulINode { 1.161 +public: 1.162 + AndINode( Node *in1, Node *in2 ) : MulINode(in1,in2) {} 1.163 + virtual int Opcode() const; 1.164 + virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 1.165 + virtual Node *Identity( PhaseTransform *phase ); 1.166 + virtual const Type *mul_ring( const Type *, const Type * ) const; 1.167 + const Type *mul_id() const { return TypeInt::MINUS_1; } 1.168 + const Type *add_id() const { return TypeInt::ZERO; } 1.169 + int add_opcode() const { return Op_OrI; } 1.170 + int mul_opcode() const { return Op_AndI; } 1.171 + virtual uint ideal_reg() const { return Op_RegI; } 1.172 +}; 1.173 + 1.174 +//------------------------------AndINode--------------------------------------- 1.175 +// Logically AND 2 longs. Included with the MUL nodes because it inherits 1.176 +// all the behavior of multiplication on a ring. 1.177 +class AndLNode : public MulLNode { 1.178 +public: 1.179 + AndLNode( Node *in1, Node *in2 ) : MulLNode(in1,in2) {} 1.180 + virtual int Opcode() const; 1.181 + virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 1.182 + virtual Node *Identity( PhaseTransform *phase ); 1.183 + virtual const Type *mul_ring( const Type *, const Type * ) const; 1.184 + const Type *mul_id() const { return TypeLong::MINUS_1; } 1.185 + const Type *add_id() const { return TypeLong::ZERO; } 1.186 + int add_opcode() const { return Op_OrL; } 1.187 + int mul_opcode() const { return Op_AndL; } 1.188 + virtual uint ideal_reg() const { return Op_RegL; } 1.189 +}; 1.190 + 1.191 +//------------------------------LShiftINode------------------------------------ 1.192 +// Logical shift left 1.193 +class LShiftINode : public Node { 1.194 +public: 1.195 + LShiftINode( Node *in1, Node *in2 ) : Node(0,in1,in2) {} 1.196 + virtual int Opcode() const; 1.197 + virtual Node *Identity( PhaseTransform *phase ); 1.198 + virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 1.199 + virtual const Type *Value( PhaseTransform *phase ) const; 1.200 + const Type *bottom_type() const { return TypeInt::INT; } 1.201 + virtual uint ideal_reg() const { return Op_RegI; } 1.202 +}; 1.203 + 1.204 +//------------------------------LShiftLNode------------------------------------ 1.205 +// Logical shift left 1.206 +class LShiftLNode : public Node { 1.207 +public: 1.208 + LShiftLNode( Node *in1, Node *in2 ) : Node(0,in1,in2) {} 1.209 + virtual int Opcode() const; 1.210 + virtual Node *Identity( PhaseTransform *phase ); 1.211 + virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 1.212 + virtual const Type *Value( PhaseTransform *phase ) const; 1.213 + const Type *bottom_type() const { return TypeLong::LONG; } 1.214 + virtual uint ideal_reg() const { return Op_RegL; } 1.215 +}; 1.216 + 1.217 +//------------------------------RShiftINode------------------------------------ 1.218 +// Signed shift right 1.219 +class RShiftINode : public Node { 1.220 +public: 1.221 + RShiftINode( Node *in1, Node *in2 ) : Node(0,in1,in2) {} 1.222 + virtual int Opcode() const; 1.223 + virtual Node *Identity( PhaseTransform *phase ); 1.224 + virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 1.225 + virtual const Type *Value( PhaseTransform *phase ) const; 1.226 + const Type *bottom_type() const { return TypeInt::INT; } 1.227 + virtual uint ideal_reg() const { return Op_RegI; } 1.228 +}; 1.229 + 1.230 +//------------------------------RShiftLNode------------------------------------ 1.231 +// Signed shift right 1.232 +class RShiftLNode : public Node { 1.233 +public: 1.234 + RShiftLNode( Node *in1, Node *in2 ) : Node(0,in1,in2) {} 1.235 + virtual int Opcode() const; 1.236 + virtual Node *Identity( PhaseTransform *phase ); 1.237 + virtual const Type *Value( PhaseTransform *phase ) const; 1.238 + const Type *bottom_type() const { return TypeLong::LONG; } 1.239 + virtual uint ideal_reg() const { return Op_RegL; } 1.240 +}; 1.241 + 1.242 + 1.243 +//------------------------------URShiftINode----------------------------------- 1.244 +// Logical shift right 1.245 +class URShiftINode : public Node { 1.246 +public: 1.247 + URShiftINode( Node *in1, Node *in2 ) : Node(0,in1,in2) {} 1.248 + virtual int Opcode() const; 1.249 + virtual Node *Identity( PhaseTransform *phase ); 1.250 + virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 1.251 + virtual const Type *Value( PhaseTransform *phase ) const; 1.252 + const Type *bottom_type() const { return TypeInt::INT; } 1.253 + virtual uint ideal_reg() const { return Op_RegI; } 1.254 +}; 1.255 + 1.256 +//------------------------------URShiftLNode----------------------------------- 1.257 +// Logical shift right 1.258 +class URShiftLNode : public Node { 1.259 +public: 1.260 + URShiftLNode( Node *in1, Node *in2 ) : Node(0,in1,in2) {} 1.261 + virtual int Opcode() const; 1.262 + virtual Node *Identity( PhaseTransform *phase ); 1.263 + virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 1.264 + virtual const Type *Value( PhaseTransform *phase ) const; 1.265 + const Type *bottom_type() const { return TypeLong::LONG; } 1.266 + virtual uint ideal_reg() const { return Op_RegL; } 1.267 +}; 1.268 + 1.269 +#endif // SHARE_VM_OPTO_MULNODE_HPP