src/share/vm/c1/c1_Canonicalizer.cpp

Print this page




   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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "incls/_precompiled.incl"
  26 #include "incls/_c1_Canonicalizer.cpp.incl"
  27 
  28 
  29 static void do_print_value(Value* vp) {

  30   (*vp)->print_line();
  31 }

  32 
  33 void Canonicalizer::set_canonical(Value x) {
  34   assert(x != NULL, "value must exist");
  35   // Note: we can not currently substitute root nodes which show up in
  36   // the instruction stream (because the instruction list is embedded
  37   // in the instructions).
  38   if (canonical() != x) {
  39     if (PrintCanonicalization) {
  40       canonical()->input_values_do(do_print_value);

  41       canonical()->print_line();
  42       tty->print_cr("canonicalized to:");
  43       x->input_values_do(do_print_value);
  44       x->print_line();
  45       tty->cr();
  46     }
  47     assert(_canonical->type()->tag() == x->type()->tag(), "types must match");
  48     _canonical = x;
  49   }
  50 }
  51 
  52 
  53 void Canonicalizer::move_const_to_right(Op2* x) {
  54   if (x->x()->type()->is_constant() && x->is_commutative()) x->swap_operands();
  55 }
  56 
  57 
  58 void Canonicalizer::do_Op2(Op2* x) {
  59   if (x->x() == x->y()) {
  60     switch (x->op()) {
  61     case Bytecodes::_isub: set_constant(0); return;
  62     case Bytecodes::_lsub: set_constant(jlong_cast(0)); return;
  63     case Bytecodes::_iand: // fall through




   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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "incls/_precompiled.incl"
  26 #include "incls/_c1_Canonicalizer.cpp.incl"
  27 
  28 
  29 class PrintValueVisitor: public ValueVisitor {
  30   void visit(Value* vp) {
  31     (*vp)->print_line();
  32   }
  33 };
  34 
  35 void Canonicalizer::set_canonical(Value x) {
  36   assert(x != NULL, "value must exist");
  37   // Note: we can not currently substitute root nodes which show up in
  38   // the instruction stream (because the instruction list is embedded
  39   // in the instructions).
  40   if (canonical() != x) {
  41     if (PrintCanonicalization) {
  42       PrintValueVisitor do_print_value;
  43       canonical()->input_values_do(&do_print_value);
  44       canonical()->print_line();
  45       tty->print_cr("canonicalized to:");
  46       x->input_values_do(&do_print_value);
  47       x->print_line();
  48       tty->cr();
  49     }
  50     assert(_canonical->type()->tag() == x->type()->tag(), "types must match");
  51     _canonical = x;
  52   }
  53 }
  54 
  55 
  56 void Canonicalizer::move_const_to_right(Op2* x) {
  57   if (x->x()->type()->is_constant() && x->is_commutative()) x->swap_operands();
  58 }
  59 
  60 
  61 void Canonicalizer::do_Op2(Op2* x) {
  62   if (x->x() == x->y()) {
  63     switch (x->op()) {
  64     case Bytecodes::_isub: set_constant(0); return;
  65     case Bytecodes::_lsub: set_constant(jlong_cast(0)); return;
  66     case Bytecodes::_iand: // fall through