src/share/vm/opto/addnode.hpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/opto/addnode.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,252 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2010, 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_ADDNODE_HPP
    1.29 +#define SHARE_VM_OPTO_ADDNODE_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 +//------------------------------AddNode----------------------------------------
    1.40 +// Classic Add functionality.  This covers all the usual 'add' behaviors for
    1.41 +// an algebraic ring.  Add-integer, add-float, add-double, and binary-or are
    1.42 +// all inherited from this class.  The various identity values are supplied
    1.43 +// by virtual functions.
    1.44 +class AddNode : public Node {
    1.45 +  virtual uint hash() const;
    1.46 +public:
    1.47 +  AddNode( Node *in1, Node *in2 ) : Node(0,in1,in2) {
    1.48 +    init_class_id(Class_Add);
    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 +  // Check if this addition involves the additive identity
    1.64 +  virtual const Type *add_of_identity( const Type *t1, const Type *t2 ) const;
    1.65 +
    1.66 +  // Supplied function returns the sum of the inputs.
    1.67 +  // This also type-checks the inputs for sanity.  Guaranteed never to
    1.68 +  // be passed a TOP or BOTTOM type, these are filtered out by a pre-check.
    1.69 +  virtual const Type *add_ring( const Type *, const Type * ) const = 0;
    1.70 +
    1.71 +  // Supplied function to return the additive identity type
    1.72 +  virtual const Type *add_id() const = 0;
    1.73 +
    1.74 +};
    1.75 +
    1.76 +//------------------------------AddINode---------------------------------------
    1.77 +// Add 2 integers
    1.78 +class AddINode : public AddNode {
    1.79 +public:
    1.80 +  AddINode( Node *in1, Node *in2 ) : AddNode(in1,in2) {}
    1.81 +  virtual int Opcode() const;
    1.82 +  virtual const Type *add_ring( const Type *, const Type * ) const;
    1.83 +  virtual const Type *add_id() const { return TypeInt::ZERO; }
    1.84 +  virtual const Type *bottom_type() const { return TypeInt::INT; }
    1.85 +  virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
    1.86 +  virtual Node *Identity( PhaseTransform *phase );
    1.87 +  virtual uint ideal_reg() const { return Op_RegI; }
    1.88 +};
    1.89 +
    1.90 +//------------------------------AddLNode---------------------------------------
    1.91 +// Add 2 longs
    1.92 +class AddLNode : public AddNode {
    1.93 +public:
    1.94 +  AddLNode( Node *in1, Node *in2 ) : AddNode(in1,in2) {}
    1.95 +  virtual int Opcode() const;
    1.96 +  virtual const Type *add_ring( const Type *, const Type * ) const;
    1.97 +  virtual const Type *add_id() const { return TypeLong::ZERO; }
    1.98 +  virtual const Type *bottom_type() const { return TypeLong::LONG; }
    1.99 +  virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   1.100 +  virtual Node *Identity( PhaseTransform *phase );
   1.101 +  virtual uint ideal_reg() const { return Op_RegL; }
   1.102 +};
   1.103 +
   1.104 +//------------------------------AddFNode---------------------------------------
   1.105 +// Add 2 floats
   1.106 +class AddFNode : public AddNode {
   1.107 +public:
   1.108 +  AddFNode( Node *in1, Node *in2 ) : AddNode(in1,in2) {}
   1.109 +  virtual int Opcode() const;
   1.110 +  virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   1.111 +  virtual const Type *add_of_identity( const Type *t1, const Type *t2 ) const;
   1.112 +  virtual const Type *add_ring( const Type *, const Type * ) const;
   1.113 +  virtual const Type *add_id() const { return TypeF::ZERO; }
   1.114 +  virtual const Type *bottom_type() const { return Type::FLOAT; }
   1.115 +  virtual Node *Identity( PhaseTransform *phase ) { return this; }
   1.116 +  virtual uint ideal_reg() const { return Op_RegF; }
   1.117 +};
   1.118 +
   1.119 +//------------------------------AddDNode---------------------------------------
   1.120 +// Add 2 doubles
   1.121 +class AddDNode : public AddNode {
   1.122 +public:
   1.123 +  AddDNode( Node *in1, Node *in2 ) : AddNode(in1,in2) {}
   1.124 +  virtual int Opcode() const;
   1.125 +  virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   1.126 +  virtual const Type *add_of_identity( const Type *t1, const Type *t2 ) const;
   1.127 +  virtual const Type *add_ring( const Type *, const Type * ) const;
   1.128 +  virtual const Type *add_id() const { return TypeD::ZERO; }
   1.129 +  virtual const Type *bottom_type() const { return Type::DOUBLE; }
   1.130 +  virtual Node *Identity( PhaseTransform *phase ) { return this; }
   1.131 +  virtual uint ideal_reg() const { return Op_RegD; }
   1.132 +};
   1.133 +
   1.134 +//------------------------------AddPNode---------------------------------------
   1.135 +// Add pointer plus integer to get pointer.  NOT commutative, really.
   1.136 +// So not really an AddNode.  Lives here, because people associate it with
   1.137 +// an add.
   1.138 +class AddPNode : public Node {
   1.139 +public:
   1.140 +  enum { Control,               // When is it safe to do this add?
   1.141 +         Base,                  // Base oop, for GC purposes
   1.142 +         Address,               // Actually address, derived from base
   1.143 +         Offset } ;             // Offset added to address
   1.144 +  AddPNode( Node *base, Node *ptr, Node *off ) : Node(0,base,ptr,off) {
   1.145 +    init_class_id(Class_AddP);
   1.146 +  }
   1.147 +  virtual int Opcode() const;
   1.148 +  virtual Node *Identity( PhaseTransform *phase );
   1.149 +  virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   1.150 +  virtual const Type *Value( PhaseTransform *phase ) const;
   1.151 +  virtual const Type *bottom_type() const;
   1.152 +  virtual uint  ideal_reg() const { return Op_RegP; }
   1.153 +  Node         *base_node() { assert( req() > Base, "Missing base"); return in(Base); }
   1.154 +  static Node* Ideal_base_and_offset(Node* ptr, PhaseTransform* phase,
   1.155 +                                     // second return value:
   1.156 +                                     intptr_t& offset);
   1.157 +
   1.158 +  // Collect the AddP offset values into the elements array, giving up
   1.159 +  // if there are more than length.
   1.160 +  int unpack_offsets(Node* elements[], int length);
   1.161 +
   1.162 +  // Do not match base-ptr edge
   1.163 +  virtual uint match_edge(uint idx) const;
   1.164 +};
   1.165 +
   1.166 +//------------------------------OrINode----------------------------------------
   1.167 +// Logically OR 2 integers.  Included with the ADD nodes because it inherits
   1.168 +// all the behavior of addition on a ring.
   1.169 +class OrINode : public AddNode {
   1.170 +public:
   1.171 +  OrINode( Node *in1, Node *in2 ) : AddNode(in1,in2) {}
   1.172 +  virtual int Opcode() const;
   1.173 +  virtual const Type *add_ring( const Type *, const Type * ) const;
   1.174 +  virtual const Type *add_id() const { return TypeInt::ZERO; }
   1.175 +  virtual const Type *bottom_type() const { return TypeInt::INT; }
   1.176 +  virtual Node *Identity( PhaseTransform *phase );
   1.177 +  virtual uint ideal_reg() const { return Op_RegI; }
   1.178 +};
   1.179 +
   1.180 +//------------------------------OrLNode----------------------------------------
   1.181 +// Logically OR 2 longs.  Included with the ADD nodes because it inherits
   1.182 +// all the behavior of addition on a ring.
   1.183 +class OrLNode : public AddNode {
   1.184 +public:
   1.185 +  OrLNode( Node *in1, Node *in2 ) : AddNode(in1,in2) {}
   1.186 +  virtual int Opcode() const;
   1.187 +  virtual const Type *add_ring( const Type *, const Type * ) const;
   1.188 +  virtual const Type *add_id() const { return TypeLong::ZERO; }
   1.189 +  virtual const Type *bottom_type() const { return TypeLong::LONG; }
   1.190 +  virtual Node *Identity( PhaseTransform *phase );
   1.191 +  virtual uint ideal_reg() const { return Op_RegL; }
   1.192 +};
   1.193 +
   1.194 +//------------------------------XorINode---------------------------------------
   1.195 +// XOR'ing 2 integers
   1.196 +class XorINode : public AddNode {
   1.197 +public:
   1.198 +  XorINode( Node *in1, Node *in2 ) : AddNode(in1,in2) {}
   1.199 +  virtual int Opcode() const;
   1.200 +  virtual const Type *add_ring( const Type *, const Type * ) const;
   1.201 +  virtual const Type *add_id() const { return TypeInt::ZERO; }
   1.202 +  virtual const Type *bottom_type() const { return TypeInt::INT; }
   1.203 +  virtual uint ideal_reg() const { return Op_RegI; }
   1.204 +};
   1.205 +
   1.206 +//------------------------------XorINode---------------------------------------
   1.207 +// XOR'ing 2 longs
   1.208 +class XorLNode : public AddNode {
   1.209 +public:
   1.210 +  XorLNode( Node *in1, Node *in2 ) : AddNode(in1,in2) {}
   1.211 +  virtual int Opcode() const;
   1.212 +  virtual const Type *add_ring( const Type *, const Type * ) const;
   1.213 +  virtual const Type *add_id() const { return TypeLong::ZERO; }
   1.214 +  virtual const Type *bottom_type() const { return TypeLong::LONG; }
   1.215 +  virtual uint ideal_reg() const { return Op_RegL; }
   1.216 +};
   1.217 +
   1.218 +//------------------------------MaxNode----------------------------------------
   1.219 +// Max (or min) of 2 values.  Included with the ADD nodes because it inherits
   1.220 +// all the behavior of addition on a ring.  Only new thing is that we allow
   1.221 +// 2 equal inputs to be equal.
   1.222 +class MaxNode : public AddNode {
   1.223 +public:
   1.224 +  MaxNode( Node *in1, Node *in2 ) : AddNode(in1,in2) {}
   1.225 +  virtual int Opcode() const = 0;
   1.226 +};
   1.227 +
   1.228 +//------------------------------MaxINode---------------------------------------
   1.229 +// Maximum of 2 integers.  Included with the ADD nodes because it inherits
   1.230 +// all the behavior of addition on a ring.
   1.231 +class MaxINode : public MaxNode {
   1.232 +public:
   1.233 +  MaxINode( Node *in1, Node *in2 ) : MaxNode(in1,in2) {}
   1.234 +  virtual int Opcode() const;
   1.235 +  virtual const Type *add_ring( const Type *, const Type * ) const;
   1.236 +  virtual const Type *add_id() const { return TypeInt::make(min_jint); }
   1.237 +  virtual const Type *bottom_type() const { return TypeInt::INT; }
   1.238 +  virtual uint ideal_reg() const { return Op_RegI; }
   1.239 +};
   1.240 +
   1.241 +//------------------------------MinINode---------------------------------------
   1.242 +// MINimum of 2 integers.  Included with the ADD nodes because it inherits
   1.243 +// all the behavior of addition on a ring.
   1.244 +class MinINode : public MaxNode {
   1.245 +public:
   1.246 +  MinINode( Node *in1, Node *in2 ) : MaxNode(in1,in2) {}
   1.247 +  virtual int Opcode() const;
   1.248 +  virtual const Type *add_ring( const Type *, const Type * ) const;
   1.249 +  virtual const Type *add_id() const { return TypeInt::make(max_jint); }
   1.250 +  virtual const Type *bottom_type() const { return TypeInt::INT; }
   1.251 +  virtual uint ideal_reg() const { return Op_RegI; }
   1.252 +  virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   1.253 +};
   1.254 +
   1.255 +#endif // SHARE_VM_OPTO_ADDNODE_HPP

mercurial