aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #ifndef SHARE_VM_OPTO_MULNODE_HPP aoqi@0: #define SHARE_VM_OPTO_MULNODE_HPP aoqi@0: aoqi@0: #include "opto/node.hpp" aoqi@0: #include "opto/opcodes.hpp" aoqi@0: #include "opto/type.hpp" aoqi@0: aoqi@0: // Portions of code courtesy of Clifford Click aoqi@0: aoqi@0: class PhaseTransform; aoqi@0: aoqi@0: //------------------------------MulNode---------------------------------------- aoqi@0: // Classic MULTIPLY functionality. This covers all the usual 'multiply' aoqi@0: // behaviors for an algebraic ring. Multiply-integer, multiply-float, aoqi@0: // multiply-double, and binary-and are all inherited from this class. The aoqi@0: // various identity values are supplied by virtual functions. aoqi@0: class MulNode : public Node { aoqi@0: virtual uint hash() const; aoqi@0: public: aoqi@0: MulNode( Node *in1, Node *in2 ): Node(0,in1,in2) { aoqi@0: init_class_id(Class_Mul); aoqi@0: } aoqi@0: aoqi@0: // Handle algebraic identities here. If we have an identity, return the Node aoqi@0: // we are equivalent to. We look for "add of zero" as an identity. aoqi@0: virtual Node *Identity( PhaseTransform *phase ); aoqi@0: aoqi@0: // We also canonicalize the Node, moving constants to the right input, aoqi@0: // and flatten expressions (so that 1+x+2 becomes x+3). aoqi@0: virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); aoqi@0: aoqi@0: // Compute a new Type for this node. Basically we just do the pre-check, aoqi@0: // then call the virtual add() to set the type. aoqi@0: virtual const Type *Value( PhaseTransform *phase ) const; aoqi@0: aoqi@0: // Supplied function returns the product of the inputs. aoqi@0: // This also type-checks the inputs for sanity. Guaranteed never to aoqi@0: // be passed a TOP or BOTTOM type, these are filtered out by a pre-check. aoqi@0: // This call recognizes the multiplicative zero type. aoqi@0: virtual const Type *mul_ring( const Type *, const Type * ) const = 0; aoqi@0: aoqi@0: // Supplied function to return the multiplicative identity type aoqi@0: virtual const Type *mul_id() const = 0; aoqi@0: aoqi@0: // Supplied function to return the additive identity type aoqi@0: virtual const Type *add_id() const = 0; aoqi@0: aoqi@0: // Supplied function to return the additive opcode aoqi@0: virtual int add_opcode() const = 0; aoqi@0: aoqi@0: // Supplied function to return the multiplicative opcode aoqi@0: virtual int mul_opcode() const = 0; aoqi@0: aoqi@0: }; aoqi@0: aoqi@0: //------------------------------MulINode--------------------------------------- aoqi@0: // Multiply 2 integers aoqi@0: class MulINode : public MulNode { aoqi@0: public: aoqi@0: MulINode( Node *in1, Node *in2 ) : MulNode(in1,in2) {} aoqi@0: virtual int Opcode() const; aoqi@0: virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); aoqi@0: virtual const Type *mul_ring( const Type *, const Type * ) const; aoqi@0: const Type *mul_id() const { return TypeInt::ONE; } aoqi@0: const Type *add_id() const { return TypeInt::ZERO; } aoqi@0: int add_opcode() const { return Op_AddI; } aoqi@0: int mul_opcode() const { return Op_MulI; } aoqi@0: const Type *bottom_type() const { return TypeInt::INT; } aoqi@0: virtual uint ideal_reg() const { return Op_RegI; } aoqi@0: }; aoqi@0: aoqi@0: //------------------------------MulLNode--------------------------------------- aoqi@0: // Multiply 2 longs aoqi@0: class MulLNode : public MulNode { aoqi@0: public: aoqi@0: MulLNode( Node *in1, Node *in2 ) : MulNode(in1,in2) {} aoqi@0: virtual int Opcode() const; aoqi@0: virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); aoqi@0: virtual const Type *mul_ring( const Type *, const Type * ) const; aoqi@0: const Type *mul_id() const { return TypeLong::ONE; } aoqi@0: const Type *add_id() const { return TypeLong::ZERO; } aoqi@0: int add_opcode() const { return Op_AddL; } aoqi@0: int mul_opcode() const { return Op_MulL; } aoqi@0: const Type *bottom_type() const { return TypeLong::LONG; } aoqi@0: virtual uint ideal_reg() const { return Op_RegL; } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: //------------------------------MulFNode--------------------------------------- aoqi@0: // Multiply 2 floats aoqi@0: class MulFNode : public MulNode { aoqi@0: public: aoqi@0: MulFNode( Node *in1, Node *in2 ) : MulNode(in1,in2) {} aoqi@0: virtual int Opcode() const; aoqi@0: virtual const Type *mul_ring( const Type *, const Type * ) const; aoqi@0: const Type *mul_id() const { return TypeF::ONE; } aoqi@0: const Type *add_id() const { return TypeF::ZERO; } aoqi@0: int add_opcode() const { return Op_AddF; } aoqi@0: int mul_opcode() const { return Op_MulF; } aoqi@0: const Type *bottom_type() const { return Type::FLOAT; } aoqi@0: virtual uint ideal_reg() const { return Op_RegF; } aoqi@0: }; aoqi@0: aoqi@0: //------------------------------MulDNode--------------------------------------- aoqi@0: // Multiply 2 doubles aoqi@0: class MulDNode : public MulNode { aoqi@0: public: aoqi@0: MulDNode( Node *in1, Node *in2 ) : MulNode(in1,in2) {} aoqi@0: virtual int Opcode() const; aoqi@0: virtual const Type *mul_ring( const Type *, const Type * ) const; aoqi@0: const Type *mul_id() const { return TypeD::ONE; } aoqi@0: const Type *add_id() const { return TypeD::ZERO; } aoqi@0: int add_opcode() const { return Op_AddD; } aoqi@0: int mul_opcode() const { return Op_MulD; } aoqi@0: const Type *bottom_type() const { return Type::DOUBLE; } aoqi@0: virtual uint ideal_reg() const { return Op_RegD; } aoqi@0: }; aoqi@0: aoqi@0: //-------------------------------MulHiLNode------------------------------------ aoqi@0: // Upper 64 bits of a 64 bit by 64 bit multiply aoqi@0: class MulHiLNode : public Node { aoqi@0: public: aoqi@0: MulHiLNode( Node *in1, Node *in2 ) : Node(0,in1,in2) {} aoqi@0: virtual int Opcode() const; aoqi@0: virtual const Type *Value( PhaseTransform *phase ) const; aoqi@0: const Type *bottom_type() const { return TypeLong::LONG; } aoqi@0: virtual uint ideal_reg() const { return Op_RegL; } aoqi@0: }; aoqi@0: aoqi@0: //------------------------------AndINode--------------------------------------- aoqi@0: // Logically AND 2 integers. Included with the MUL nodes because it inherits aoqi@0: // all the behavior of multiplication on a ring. aoqi@0: class AndINode : public MulINode { aoqi@0: public: aoqi@0: AndINode( Node *in1, Node *in2 ) : MulINode(in1,in2) {} aoqi@0: virtual int Opcode() const; aoqi@0: virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); aoqi@0: virtual Node *Identity( PhaseTransform *phase ); aoqi@0: virtual const Type *mul_ring( const Type *, const Type * ) const; aoqi@0: const Type *mul_id() const { return TypeInt::MINUS_1; } aoqi@0: const Type *add_id() const { return TypeInt::ZERO; } aoqi@0: int add_opcode() const { return Op_OrI; } aoqi@0: int mul_opcode() const { return Op_AndI; } aoqi@0: virtual uint ideal_reg() const { return Op_RegI; } aoqi@0: }; aoqi@0: aoqi@0: //------------------------------AndINode--------------------------------------- aoqi@0: // Logically AND 2 longs. Included with the MUL nodes because it inherits aoqi@0: // all the behavior of multiplication on a ring. aoqi@0: class AndLNode : public MulLNode { aoqi@0: public: aoqi@0: AndLNode( Node *in1, Node *in2 ) : MulLNode(in1,in2) {} aoqi@0: virtual int Opcode() const; aoqi@0: virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); aoqi@0: virtual Node *Identity( PhaseTransform *phase ); aoqi@0: virtual const Type *mul_ring( const Type *, const Type * ) const; aoqi@0: const Type *mul_id() const { return TypeLong::MINUS_1; } aoqi@0: const Type *add_id() const { return TypeLong::ZERO; } aoqi@0: int add_opcode() const { return Op_OrL; } aoqi@0: int mul_opcode() const { return Op_AndL; } aoqi@0: virtual uint ideal_reg() const { return Op_RegL; } aoqi@0: }; aoqi@0: aoqi@0: //------------------------------LShiftINode------------------------------------ aoqi@0: // Logical shift left aoqi@0: class LShiftINode : public Node { aoqi@0: public: aoqi@0: LShiftINode( Node *in1, Node *in2 ) : Node(0,in1,in2) {} aoqi@0: virtual int Opcode() const; aoqi@0: virtual Node *Identity( PhaseTransform *phase ); aoqi@0: virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); aoqi@0: virtual const Type *Value( PhaseTransform *phase ) const; aoqi@0: const Type *bottom_type() const { return TypeInt::INT; } aoqi@0: virtual uint ideal_reg() const { return Op_RegI; } aoqi@0: }; aoqi@0: aoqi@0: //------------------------------LShiftLNode------------------------------------ aoqi@0: // Logical shift left aoqi@0: class LShiftLNode : public Node { aoqi@0: public: aoqi@0: LShiftLNode( Node *in1, Node *in2 ) : Node(0,in1,in2) {} aoqi@0: virtual int Opcode() const; aoqi@0: virtual Node *Identity( PhaseTransform *phase ); aoqi@0: virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); aoqi@0: virtual const Type *Value( PhaseTransform *phase ) const; aoqi@0: const Type *bottom_type() const { return TypeLong::LONG; } aoqi@0: virtual uint ideal_reg() const { return Op_RegL; } aoqi@0: }; aoqi@0: aoqi@0: //------------------------------RShiftINode------------------------------------ aoqi@0: // Signed shift right aoqi@0: class RShiftINode : public Node { aoqi@0: public: aoqi@0: RShiftINode( Node *in1, Node *in2 ) : Node(0,in1,in2) {} aoqi@0: virtual int Opcode() const; aoqi@0: virtual Node *Identity( PhaseTransform *phase ); aoqi@0: virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); aoqi@0: virtual const Type *Value( PhaseTransform *phase ) const; aoqi@0: const Type *bottom_type() const { return TypeInt::INT; } aoqi@0: virtual uint ideal_reg() const { return Op_RegI; } aoqi@0: }; aoqi@0: aoqi@0: //------------------------------RShiftLNode------------------------------------ aoqi@0: // Signed shift right aoqi@0: class RShiftLNode : public Node { aoqi@0: public: aoqi@0: RShiftLNode( Node *in1, Node *in2 ) : Node(0,in1,in2) {} aoqi@0: virtual int Opcode() const; aoqi@0: virtual Node *Identity( PhaseTransform *phase ); aoqi@0: virtual const Type *Value( PhaseTransform *phase ) const; aoqi@0: const Type *bottom_type() const { return TypeLong::LONG; } aoqi@0: virtual uint ideal_reg() const { return Op_RegL; } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: //------------------------------URShiftINode----------------------------------- aoqi@0: // Logical shift right aoqi@0: class URShiftINode : public Node { aoqi@0: public: aoqi@0: URShiftINode( Node *in1, Node *in2 ) : Node(0,in1,in2) {} aoqi@0: virtual int Opcode() const; aoqi@0: virtual Node *Identity( PhaseTransform *phase ); aoqi@0: virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); aoqi@0: virtual const Type *Value( PhaseTransform *phase ) const; aoqi@0: const Type *bottom_type() const { return TypeInt::INT; } aoqi@0: virtual uint ideal_reg() const { return Op_RegI; } aoqi@0: }; aoqi@0: aoqi@0: //------------------------------URShiftLNode----------------------------------- aoqi@0: // Logical shift right aoqi@0: class URShiftLNode : public Node { aoqi@0: public: aoqi@0: URShiftLNode( Node *in1, Node *in2 ) : Node(0,in1,in2) {} aoqi@0: virtual int Opcode() const; aoqi@0: virtual Node *Identity( PhaseTransform *phase ); aoqi@0: virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); aoqi@0: virtual const Type *Value( PhaseTransform *phase ) const; aoqi@0: const Type *bottom_type() const { return TypeLong::LONG; } aoqi@0: virtual uint ideal_reg() const { return Op_RegL; } aoqi@0: }; aoqi@0: aoqi@0: #endif // SHARE_VM_OPTO_MULNODE_HPP