src/share/vm/opto/subnode.hpp

Thu, 20 Mar 2008 15:11:44 -0700

author
kvn
date
Thu, 20 Mar 2008 15:11:44 -0700
changeset 509
2a9af0b9cb1c
parent 435
a61af66fc99e
child 548
ba764ed4b6f2
permissions
-rw-r--r--

6674600: (Escape Analysis) Optimize memory graph for instance's fields
Summary: EA gives opportunite to do more aggressive memory optimizations.
Reviewed-by: never, jrose

     1 /*
     2  * Copyright 1997-2006 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  *
    23  */
    25 // Portions of code courtesy of Clifford Click
    27 //------------------------------SUBNode----------------------------------------
    28 // Class SUBTRACTION functionality.  This covers all the usual 'subtract'
    29 // behaviors.  Subtract-integer, -float, -double, binary xor, compare-integer,
    30 // -float, and -double are all inherited from this class.  The compare
    31 // functions behave like subtract functions, except that all negative answers
    32 // are compressed into -1, and all positive answers compressed to 1.
    33 class SubNode : public Node {
    34 public:
    35   SubNode( Node *in1, Node *in2 ) : Node(0,in1,in2) {
    36     init_class_id(Class_Sub);
    37   }
    39   // Handle algebraic identities here.  If we have an identity, return the Node
    40   // we are equivalent to.  We look for "add of zero" as an identity.
    41   virtual Node *Identity( PhaseTransform *phase );
    43   // Compute a new Type for this node.  Basically we just do the pre-check,
    44   // then call the virtual add() to set the type.
    45   virtual const Type *Value( PhaseTransform *phase ) const;
    47   // Supplied function returns the subtractend of the inputs.
    48   // This also type-checks the inputs for sanity.  Guaranteed never to
    49   // be passed a TOP or BOTTOM type, these are filtered out by a pre-check.
    50   virtual const Type *sub( const Type *, const Type * ) const = 0;
    52   // Supplied function to return the additive identity type.
    53   // This is returned whenever the subtracts inputs are the same.
    54   virtual const Type *add_id() const = 0;
    56 };
    59 // NOTE: SubINode should be taken away and replaced by add and negate
    60 //------------------------------SubINode---------------------------------------
    61 // Subtract 2 integers
    62 class SubINode : public SubNode {
    63 public:
    64   SubINode( Node *in1, Node *in2 ) : SubNode(in1,in2) {}
    65   virtual int Opcode() const;
    66   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
    67   virtual const Type *sub( const Type *, const Type * ) const;
    68   const Type *add_id() const { return TypeInt::ZERO; }
    69   const Type *bottom_type() const { return TypeInt::INT; }
    70   virtual uint ideal_reg() const { return Op_RegI; }
    71 };
    73 //------------------------------SubLNode---------------------------------------
    74 // Subtract 2 integers
    75 class SubLNode : public SubNode {
    76 public:
    77   SubLNode( Node *in1, Node *in2 ) : SubNode(in1,in2) {}
    78   virtual int Opcode() const;
    79   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
    80   virtual const Type *sub( const Type *, const Type * ) const;
    81   const Type *add_id() const { return TypeLong::ZERO; }
    82   const Type *bottom_type() const { return TypeLong::LONG; }
    83   virtual uint ideal_reg() const { return Op_RegL; }
    84 };
    86 // NOTE: SubFPNode should be taken away and replaced by add and negate
    87 //------------------------------SubFPNode--------------------------------------
    88 // Subtract 2 floats or doubles
    89 class SubFPNode : public SubNode {
    90 protected:
    91   SubFPNode( Node *in1, Node *in2 ) : SubNode(in1,in2) {}
    92 public:
    93   const Type *Value( PhaseTransform *phase ) const;
    94 };
    96 // NOTE: SubFNode should be taken away and replaced by add and negate
    97 //------------------------------SubFNode---------------------------------------
    98 // Subtract 2 doubles
    99 class SubFNode : public SubFPNode {
   100 public:
   101   SubFNode( Node *in1, Node *in2 ) : SubFPNode(in1,in2) {}
   102   virtual int Opcode() const;
   103   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   104   virtual const Type *sub( const Type *, const Type * ) const;
   105   const Type   *add_id() const { return TypeF::ZERO; }
   106   const Type   *bottom_type() const { return Type::FLOAT; }
   107   virtual uint  ideal_reg() const { return Op_RegF; }
   108 };
   110 // NOTE: SubDNode should be taken away and replaced by add and negate
   111 //------------------------------SubDNode---------------------------------------
   112 // Subtract 2 doubles
   113 class SubDNode : public SubFPNode {
   114 public:
   115   SubDNode( Node *in1, Node *in2 ) : SubFPNode(in1,in2) {}
   116   virtual int Opcode() const;
   117   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   118   virtual const Type *sub( const Type *, const Type * ) const;
   119   const Type   *add_id() const { return TypeD::ZERO; }
   120   const Type   *bottom_type() const { return Type::DOUBLE; }
   121   virtual uint  ideal_reg() const { return Op_RegD; }
   122 };
   124 //------------------------------CmpNode---------------------------------------
   125 // Compare 2 values, returning condition codes (-1, 0 or 1).
   126 class CmpNode : public SubNode {
   127 public:
   128   CmpNode( Node *in1, Node *in2 ) : SubNode(in1,in2) {
   129     init_class_id(Class_Cmp);
   130   }
   131   virtual Node *Identity( PhaseTransform *phase );
   132   const Type *add_id() const { return TypeInt::ZERO; }
   133   const Type *bottom_type() const { return TypeInt::CC; }
   134   virtual uint ideal_reg() const { return Op_RegFlags; }
   135 };
   137 //------------------------------CmpINode---------------------------------------
   138 // Compare 2 signed values, returning condition codes (-1, 0 or 1).
   139 class CmpINode : public CmpNode {
   140 public:
   141   CmpINode( Node *in1, Node *in2 ) : CmpNode(in1,in2) {}
   142   virtual int Opcode() const;
   143   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   144   virtual const Type *sub( const Type *, const Type * ) const;
   145 };
   147 //------------------------------CmpUNode---------------------------------------
   148 // Compare 2 unsigned values (integer or pointer), returning condition codes (-1, 0 or 1).
   149 class CmpUNode : public CmpNode {
   150 public:
   151   CmpUNode( Node *in1, Node *in2 ) : CmpNode(in1,in2) {}
   152   virtual int Opcode() const;
   153   virtual const Type *sub( const Type *, const Type * ) const;
   154 };
   156 //------------------------------CmpPNode---------------------------------------
   157 // Compare 2 pointer values, returning condition codes (-1, 0 or 1).
   158 class CmpPNode : public CmpNode {
   159 public:
   160   CmpPNode( Node *in1, Node *in2 ) : CmpNode(in1,in2) {}
   161   virtual int Opcode() const;
   162   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   163   virtual const Type *sub( const Type *, const Type * ) const;
   164 };
   166 //------------------------------CmpLNode---------------------------------------
   167 // Compare 2 long values, returning condition codes (-1, 0 or 1).
   168 class CmpLNode : public CmpNode {
   169 public:
   170   CmpLNode( Node *in1, Node *in2 ) : CmpNode(in1,in2) {}
   171   virtual int    Opcode() const;
   172   virtual const Type *sub( const Type *, const Type * ) const;
   173 };
   175 //------------------------------CmpL3Node--------------------------------------
   176 // Compare 2 long values, returning integer value (-1, 0 or 1).
   177 class CmpL3Node : public CmpLNode {
   178 public:
   179   CmpL3Node( Node *in1, Node *in2 ) : CmpLNode(in1,in2) {
   180     // Since it is not consumed by Bools, it is not really a Cmp.
   181     init_class_id(Class_Sub);
   182   }
   183   virtual int    Opcode() const;
   184   virtual uint ideal_reg() const { return Op_RegI; }
   185 };
   187 //------------------------------CmpFNode---------------------------------------
   188 // Compare 2 float values, returning condition codes (-1, 0 or 1).
   189 // This implements the Java bytecode fcmpl, so unordered returns -1.
   190 // Operands may not commute.
   191 class CmpFNode : public CmpNode {
   192 public:
   193   CmpFNode( Node *in1, Node *in2 ) : CmpNode(in1,in2) {}
   194   virtual int Opcode() const;
   195   virtual const Type *sub( const Type *, const Type * ) const { ShouldNotReachHere(); return NULL; }
   196   const Type *Value( PhaseTransform *phase ) const;
   197 };
   199 //------------------------------CmpF3Node--------------------------------------
   200 // Compare 2 float values, returning integer value (-1, 0 or 1).
   201 // This implements the Java bytecode fcmpl, so unordered returns -1.
   202 // Operands may not commute.
   203 class CmpF3Node : public CmpFNode {
   204 public:
   205   CmpF3Node( Node *in1, Node *in2 ) : CmpFNode(in1,in2) {
   206     // Since it is not consumed by Bools, it is not really a Cmp.
   207     init_class_id(Class_Sub);
   208   }
   209   virtual int Opcode() const;
   210   // Since it is not consumed by Bools, it is not really a Cmp.
   211   virtual uint ideal_reg() const { return Op_RegI; }
   212 };
   215 //------------------------------CmpDNode---------------------------------------
   216 // Compare 2 double values, returning condition codes (-1, 0 or 1).
   217 // This implements the Java bytecode dcmpl, so unordered returns -1.
   218 // Operands may not commute.
   219 class CmpDNode : public CmpNode {
   220 public:
   221   CmpDNode( Node *in1, Node *in2 ) : CmpNode(in1,in2) {}
   222   virtual int Opcode() const;
   223   virtual const Type *sub( const Type *, const Type * ) const { ShouldNotReachHere(); return NULL; }
   224   const Type *Value( PhaseTransform *phase ) const;
   225   virtual Node  *Ideal(PhaseGVN *phase, bool can_reshape);
   226 };
   228 //------------------------------CmpD3Node--------------------------------------
   229 // Compare 2 double values, returning integer value (-1, 0 or 1).
   230 // This implements the Java bytecode dcmpl, so unordered returns -1.
   231 // Operands may not commute.
   232 class CmpD3Node : public CmpDNode {
   233 public:
   234   CmpD3Node( Node *in1, Node *in2 ) : CmpDNode(in1,in2) {
   235     // Since it is not consumed by Bools, it is not really a Cmp.
   236     init_class_id(Class_Sub);
   237   }
   238   virtual int Opcode() const;
   239   virtual uint ideal_reg() const { return Op_RegI; }
   240 };
   243 //------------------------------BoolTest---------------------------------------
   244 // Convert condition codes to a boolean test value (0 or -1).
   245 // We pick the values as 3 bits; the low order 2 bits we compare against the
   246 // condition codes, the high bit flips the sense of the result.
   247 struct BoolTest VALUE_OBJ_CLASS_SPEC {
   248   enum mask { eq = 0, ne = 4, le = 5, ge = 7, lt = 3, gt = 1, illegal = 8 };
   249   mask _test;
   250   BoolTest( mask btm ) : _test(btm) {}
   251   const Type *cc2logical( const Type *CC ) const;
   252   // Commute the test.  I use a small table lookup.  The table is created as
   253   // a simple char array where each element is the ASCII version of a 'mask'
   254   // enum from above.
   255   mask commute( ) const { return mask("038147858"[_test]-'0'); }
   256   mask negate( ) const { return mask(_test^4); }
   257   bool is_canonical( ) const { return (_test == BoolTest::ne || _test == BoolTest::lt || _test == BoolTest::le); }
   258 #ifndef PRODUCT
   259   void dump_on(outputStream *st) const;
   260 #endif
   261 };
   263 //------------------------------BoolNode---------------------------------------
   264 // A Node to convert a Condition Codes to a Logical result.
   265 class BoolNode : public Node {
   266   virtual uint hash() const;
   267   virtual uint cmp( const Node &n ) const;
   268   virtual uint size_of() const;
   269 public:
   270   const BoolTest _test;
   271   BoolNode( Node *cc, BoolTest::mask t): _test(t), Node(0,cc) {
   272     init_class_id(Class_Bool);
   273   }
   274   // Convert an arbitrary int value to a Bool or other suitable predicate.
   275   static Node* make_predicate(Node* test_value, PhaseGVN* phase);
   276   // Convert self back to an integer value.
   277   Node* as_int_value(PhaseGVN* phase);
   278   // Invert sense of self, returning new Bool.
   279   BoolNode* negate(PhaseGVN* phase);
   280   virtual int Opcode() const;
   281   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   282   virtual const Type *Value( PhaseTransform *phase ) const;
   283   virtual const Type *bottom_type() const { return TypeInt::BOOL; }
   284   uint match_edge(uint idx) const { return 0; }
   285   virtual uint ideal_reg() const { return Op_RegI; }
   287   bool is_counted_loop_exit_test();
   288 #ifndef PRODUCT
   289   virtual void dump_spec(outputStream *st) const;
   290 #endif
   291 };
   293 //------------------------------AbsNode----------------------------------------
   294 // Abstract class for absolute value.  Mostly used to get a handy wrapper
   295 // for finding this pattern in the graph.
   296 class AbsNode : public Node {
   297 public:
   298   AbsNode( Node *value ) : Node(0,value) {}
   299 };
   301 //------------------------------AbsINode---------------------------------------
   302 // Absolute value an integer.  Since a naive graph involves control flow, we
   303 // "match" it in the ideal world (so the control flow can be removed).
   304 class AbsINode : public AbsNode {
   305 public:
   306   AbsINode( Node *in1 ) : AbsNode(in1) {}
   307   virtual int Opcode() const;
   308   const Type *bottom_type() const { return TypeInt::INT; }
   309   virtual uint ideal_reg() const { return Op_RegI; }
   310 };
   312 //------------------------------AbsFNode---------------------------------------
   313 // Absolute value a float, a common float-point idiom with a cheap hardware
   314 // implemention on most chips.  Since a naive graph involves control flow, we
   315 // "match" it in the ideal world (so the control flow can be removed).
   316 class AbsFNode : public AbsNode {
   317 public:
   318   AbsFNode( Node *in1 ) : AbsNode(in1) {}
   319   virtual int Opcode() const;
   320   const Type *bottom_type() const { return Type::FLOAT; }
   321   virtual uint ideal_reg() const { return Op_RegF; }
   322 };
   324 //------------------------------AbsDNode---------------------------------------
   325 // Absolute value a double, a common float-point idiom with a cheap hardware
   326 // implemention on most chips.  Since a naive graph involves control flow, we
   327 // "match" it in the ideal world (so the control flow can be removed).
   328 class AbsDNode : public AbsNode {
   329 public:
   330   AbsDNode( Node *in1 ) : AbsNode(in1) {}
   331   virtual int Opcode() const;
   332   const Type *bottom_type() const { return Type::DOUBLE; }
   333   virtual uint ideal_reg() const { return Op_RegD; }
   334 };
   337 //------------------------------CmpLTMaskNode----------------------------------
   338 // If p < q, return -1 else return 0.  Nice for flow-free idioms.
   339 class CmpLTMaskNode : public Node {
   340 public:
   341   CmpLTMaskNode( Node *p, Node *q ) : Node(0, p, q) {}
   342   virtual int Opcode() const;
   343   const Type *bottom_type() const { return TypeInt::INT; }
   344   virtual uint ideal_reg() const { return Op_RegI; }
   345 };
   348 //------------------------------NegNode----------------------------------------
   349 class NegNode : public Node {
   350 public:
   351   NegNode( Node *in1 ) : Node(0,in1) {}
   352 };
   354 //------------------------------NegFNode---------------------------------------
   355 // Negate value a float.  Negating 0.0 returns -0.0, but subtracting from
   356 // zero returns +0.0 (per JVM spec on 'fneg' bytecode).  As subtraction
   357 // cannot be used to replace negation we have to implement negation as ideal
   358 // node; note that negation and addition can replace subtraction.
   359 class NegFNode : public NegNode {
   360 public:
   361   NegFNode( Node *in1 ) : NegNode(in1) {}
   362   virtual int Opcode() const;
   363   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   364   const Type *bottom_type() const { return Type::FLOAT; }
   365   virtual uint ideal_reg() const { return Op_RegF; }
   366 };
   368 //------------------------------NegDNode---------------------------------------
   369 // Negate value a double.  Negating 0.0 returns -0.0, but subtracting from
   370 // zero returns +0.0 (per JVM spec on 'dneg' bytecode).  As subtraction
   371 // cannot be used to replace negation we have to implement negation as ideal
   372 // node; note that negation and addition can replace subtraction.
   373 class NegDNode : public NegNode {
   374 public:
   375   NegDNode( Node *in1 ) : NegNode(in1) {}
   376   virtual int Opcode() const;
   377   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   378   const Type *bottom_type() const { return Type::DOUBLE; }
   379   virtual uint ideal_reg() const { return Op_RegD; }
   380 };
   382 //------------------------------CosDNode---------------------------------------
   383 // Cosinus of a double
   384 class CosDNode : public Node {
   385 public:
   386   CosDNode( Node *in1  ) : Node(0, in1) {}
   387   virtual int Opcode() const;
   388   const Type *bottom_type() const { return Type::DOUBLE; }
   389   virtual uint ideal_reg() const { return Op_RegD; }
   390   virtual const Type *Value( PhaseTransform *phase ) const;
   391 };
   393 //------------------------------CosDNode---------------------------------------
   394 // Sinus of a double
   395 class SinDNode : public Node {
   396 public:
   397   SinDNode( Node *in1  ) : Node(0, in1) {}
   398   virtual int Opcode() const;
   399   const Type *bottom_type() const { return Type::DOUBLE; }
   400   virtual uint ideal_reg() const { return Op_RegD; }
   401   virtual const Type *Value( PhaseTransform *phase ) const;
   402 };
   405 //------------------------------TanDNode---------------------------------------
   406 // tangens of a double
   407 class TanDNode : public Node {
   408 public:
   409   TanDNode(Node *in1  ) : Node(0, in1) {}
   410   virtual int Opcode() const;
   411   const Type *bottom_type() const { return Type::DOUBLE; }
   412   virtual uint ideal_reg() const { return Op_RegD; }
   413   virtual const Type *Value( PhaseTransform *phase ) const;
   414 };
   417 //------------------------------AtanDNode--------------------------------------
   418 // arcus tangens of a double
   419 class AtanDNode : public Node {
   420 public:
   421   AtanDNode(Node *c, Node *in1, Node *in2  ) : Node(c, in1, in2) {}
   422   virtual int Opcode() const;
   423   const Type *bottom_type() const { return Type::DOUBLE; }
   424   virtual uint ideal_reg() const { return Op_RegD; }
   425 };
   428 //------------------------------SqrtDNode--------------------------------------
   429 // square root a double
   430 class SqrtDNode : public Node {
   431 public:
   432   SqrtDNode(Node *c, Node *in1  ) : Node(c, in1) {}
   433   virtual int Opcode() const;
   434   const Type *bottom_type() const { return Type::DOUBLE; }
   435   virtual uint ideal_reg() const { return Op_RegD; }
   436   virtual const Type *Value( PhaseTransform *phase ) const;
   437 };
   439 //------------------------------ExpDNode---------------------------------------
   440 //  Exponentiate a double
   441 class ExpDNode : public Node {
   442 public:
   443   ExpDNode( Node *c, Node *in1 ) : Node(c, in1) {}
   444   virtual int Opcode() const;
   445   const Type *bottom_type() const { return Type::DOUBLE; }
   446   virtual uint ideal_reg() const { return Op_RegD; }
   447   virtual const Type *Value( PhaseTransform *phase ) const;
   448 };
   450 //------------------------------LogDNode---------------------------------------
   451 // Log_e of a double
   452 class LogDNode : public Node {
   453 public:
   454   LogDNode( Node *in1 ) : Node(0, in1) {}
   455   virtual int Opcode() const;
   456   const Type *bottom_type() const { return Type::DOUBLE; }
   457   virtual uint ideal_reg() const { return Op_RegD; }
   458   virtual const Type *Value( PhaseTransform *phase ) const;
   459 };
   461 //------------------------------Log10DNode---------------------------------------
   462 // Log_10 of a double
   463 class Log10DNode : public Node {
   464 public:
   465   Log10DNode( Node *in1 ) : Node(0, in1) {}
   466   virtual int Opcode() const;
   467   const Type *bottom_type() const { return Type::DOUBLE; }
   468   virtual uint ideal_reg() const { return Op_RegD; }
   469   virtual const Type *Value( PhaseTransform *phase ) const;
   470 };
   472 //------------------------------PowDNode---------------------------------------
   473 // Raise a double to a double power
   474 class PowDNode : public Node {
   475 public:
   476   PowDNode(Node *c, Node *in1, Node *in2  ) : Node(c, in1, in2) {}
   477   virtual int Opcode() const;
   478   const Type *bottom_type() const { return Type::DOUBLE; }
   479   virtual uint ideal_reg() const { return Op_RegD; }
   480   virtual const Type *Value( PhaseTransform *phase ) const;
   481 };
   483 //-------------------------------ReverseBytesINode--------------------------------
   484 // reverse bytes of an integer
   485 class ReverseBytesINode : public Node {
   486 public:
   487   ReverseBytesINode(Node *c, Node *in1) : Node(c, in1) {}
   488   virtual int Opcode() const;
   489   const Type *bottom_type() const { return TypeInt::INT; }
   490   virtual uint ideal_reg() const { return Op_RegI; }
   491 };
   493 //-------------------------------ReverseBytesLNode--------------------------------
   494 // reverse bytes of a long
   495 class ReverseBytesLNode : public Node {
   496 public:
   497   ReverseBytesLNode(Node *c, Node *in1) : Node(c, in1) {}
   498   virtual int Opcode() const;
   499   const Type *bottom_type() const { return TypeLong::LONG; }
   500   virtual uint ideal_reg() const { return Op_RegL; }
   501 };

mercurial