hotspot/src/share/vm/opto/divnode.hpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2005 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
// Portions of code courtesy of Clifford Click
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
// Optimization - Graph Style
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
//------------------------------DivINode---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// Integer division
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// Note: this is division as defined by JVMS, i.e., MinInt/-1 == MinInt.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// On processors which don't naturally support this special case (e.g., x86),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// the matcher or runtime system must take care of this.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
class DivINode : public Node {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  DivINode( Node *c, Node *dividend, Node *divisor ) : Node(c, dividend, divisor ) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  virtual int Opcode() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  virtual Node *Identity( PhaseTransform *phase );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  virtual const Type *Value( PhaseTransform *phase ) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  virtual const Type *bottom_type() const { return TypeInt::INT; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  virtual uint ideal_reg() const { return Op_RegI; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
//------------------------------DivLNode---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
// Long division
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
class DivLNode : public Node {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  DivLNode( Node *c, Node *dividend, Node *divisor ) : Node(c, dividend, divisor ) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  virtual int Opcode() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  virtual Node *Identity( PhaseTransform *phase );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  virtual const Type *Value( PhaseTransform *phase ) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  virtual const Type *bottom_type() const { return TypeLong::LONG; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  virtual uint ideal_reg() const { return Op_RegL; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
//------------------------------DivFNode---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
// Float division
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
class DivFNode : public Node {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  DivFNode( Node *c, Node *dividend, Node *divisor ) : Node(c, dividend, divisor) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  virtual int Opcode() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  virtual Node *Identity( PhaseTransform *phase );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  virtual const Type *Value( PhaseTransform *phase ) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  virtual const Type *bottom_type() const { return Type::FLOAT; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  virtual uint ideal_reg() const { return Op_RegF; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
//------------------------------DivDNode---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
// Double division
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
class DivDNode : public Node {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  DivDNode( Node *c, Node *dividend, Node *divisor ) : Node(c,dividend, divisor) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  virtual int Opcode() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  virtual Node *Identity( PhaseTransform *phase );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  virtual const Type *Value( PhaseTransform *phase ) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  virtual const Type *bottom_type() const { return Type::DOUBLE; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  virtual uint ideal_reg() const { return Op_RegD; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
//------------------------------ModINode---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
// Integer modulus
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
class ModINode : public Node {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  ModINode( Node *c, Node *in1, Node *in2 ) : Node(c,in1, in2) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  virtual int Opcode() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  virtual const Type *Value( PhaseTransform *phase ) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  virtual const Type *bottom_type() const { return TypeInt::INT; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  virtual uint ideal_reg() const { return Op_RegI; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
//------------------------------ModLNode---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
// Long modulus
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
class ModLNode : public Node {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  ModLNode( Node *c, Node *in1, Node *in2 ) : Node(c,in1, in2) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  virtual int Opcode() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  virtual const Type *Value( PhaseTransform *phase ) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  virtual const Type *bottom_type() const { return TypeLong::LONG; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  virtual uint ideal_reg() const { return Op_RegL; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
//------------------------------ModFNode---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
// Float Modulus
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
class ModFNode : public Node {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  ModFNode( Node *c, Node *in1, Node *in2 ) : Node(c,in1, in2) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  virtual int Opcode() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  virtual const Type *Value( PhaseTransform *phase ) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  virtual const Type *bottom_type() const { return Type::FLOAT; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  virtual uint ideal_reg() const { return Op_RegF; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
//------------------------------ModDNode---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
// Double Modulus
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
class ModDNode : public Node {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  ModDNode( Node *c, Node *in1, Node *in2 ) : Node(c, in1, in2) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  virtual int Opcode() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  virtual const Type *Value( PhaseTransform *phase ) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  virtual const Type *bottom_type() const { return Type::DOUBLE; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  virtual uint ideal_reg() const { return Op_RegD; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
//------------------------------DivModNode---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
// Division with remainder result.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
class DivModNode : public MultiNode {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  DivModNode( Node *c, Node *dividend, Node *divisor );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    div_proj_num =  0,      // quotient
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    mod_proj_num =  1       // remainder
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  virtual int Opcode() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  virtual Node *Identity( PhaseTransform *phase ) { return this; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  virtual Node *Ideal(PhaseGVN *phase, bool can_reshape) { return NULL; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  virtual const Type *Value( PhaseTransform *phase ) const { return bottom_type(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  virtual uint hash() const { return Node::hash(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  virtual bool is_CFG() const  { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  virtual uint ideal_reg() const { return NotAMachineReg; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  ProjNode* div_proj() { return proj_out(div_proj_num); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  ProjNode* mod_proj() { return proj_out(mod_proj_num); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
//------------------------------DivModINode---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
// Integer division with remainder result.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
class DivModINode : public DivModNode {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  DivModINode( Node *c, Node *dividend, Node *divisor ) : DivModNode(c, dividend, divisor) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  virtual int Opcode() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  virtual const Type *bottom_type() const { return TypeTuple::INT_PAIR; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  virtual Node *match( const ProjNode *proj, const Matcher *m );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  // Make a divmod and associated projections from a div or mod.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  static DivModINode* make(Compile* C, Node* div_or_mod);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
//------------------------------DivModLNode---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
// Long division with remainder result.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
class DivModLNode : public DivModNode {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  DivModLNode( Node *c, Node *dividend, Node *divisor ) : DivModNode(c, dividend, divisor) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  virtual int Opcode() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  virtual const Type *bottom_type() const { return TypeTuple::LONG_PAIR; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  virtual Node *match( const ProjNode *proj, const Matcher *m );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  // Make a divmod and associated projections from a div or mod.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  static DivModLNode* make(Compile* C, Node* div_or_mod);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
};