< prev index next >

src/share/vm/c1/c1_Instruction.cpp

Print this page


   1 /*
   2  * Copyright (c) 1999, 2016, Oracle and/or its affiliates. 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 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  *


 222 ciType* NewInstance::declared_type() const {
 223   return exact_type();
 224 }
 225 
 226 ciType* CheckCast::declared_type() const {
 227   return klass();
 228 }
 229 
 230 // Implementation of ArithmeticOp
 231 
 232 bool ArithmeticOp::is_commutative() const {
 233   switch (op()) {
 234     case Bytecodes::_iadd: // fall through
 235     case Bytecodes::_ladd: // fall through
 236     case Bytecodes::_fadd: // fall through
 237     case Bytecodes::_dadd: // fall through
 238     case Bytecodes::_imul: // fall through
 239     case Bytecodes::_lmul: // fall through
 240     case Bytecodes::_fmul: // fall through
 241     case Bytecodes::_dmul: return true;

 242   }
 243   return false;
 244 }
 245 
 246 
 247 bool ArithmeticOp::can_trap() const {
 248   switch (op()) {
 249     case Bytecodes::_idiv: // fall through
 250     case Bytecodes::_ldiv: // fall through
 251     case Bytecodes::_irem: // fall through
 252     case Bytecodes::_lrem: return true;

 253   }
 254   return false;
 255 }
 256 
 257 
 258 // Implementation of LogicOp
 259 
 260 bool LogicOp::is_commutative() const {
 261 #ifdef ASSERT
 262   switch (op()) {
 263     case Bytecodes::_iand: // fall through
 264     case Bytecodes::_land: // fall through
 265     case Bytecodes::_ior : // fall through
 266     case Bytecodes::_lor : // fall through
 267     case Bytecodes::_ixor: // fall through
 268     case Bytecodes::_lxor: break;
 269     default              : ShouldNotReachHere();
 270   }
 271 #endif
 272   // all LogicOps are commutative
 273   return true;
 274 }
 275 
 276 
 277 // Implementation of IfOp
 278 
 279 bool IfOp::is_commutative() const {
 280   return cond() == eql || cond() == neq;
 281 }
 282 
 283 
 284 // Implementation of StateSplit
 285 
 286 void StateSplit::substitute(BlockList& list, BlockBegin* old_block, BlockBegin* new_block) {
 287   NOT_PRODUCT(bool assigned = false;)
 288   for (int i = 0; i < list.length(); i++) {
 289     BlockBegin** b = list.adr_at(i);


 430         DoubleConstant* t2 = v->type()->as_DoubleConstant();
 431         return (t1 != NULL && t2 != NULL &&
 432                 jlong_cast(t1->value()) == jlong_cast(t2->value()));
 433       }
 434     case objectTag:
 435       {
 436         ObjectType* t1 =    type()->as_ObjectType();
 437         ObjectType* t2 = v->type()->as_ObjectType();
 438         return (t1 != NULL && t2 != NULL &&
 439                 t1->is_loaded() && t2->is_loaded() &&
 440                 t1->constant_value() == t2->constant_value());
 441       }
 442     case metaDataTag:
 443       {
 444         MetadataType* t1 =    type()->as_MetadataType();
 445         MetadataType* t2 = v->type()->as_MetadataType();
 446         return (t1 != NULL && t2 != NULL &&
 447                 t1->is_loaded() && t2->is_loaded() &&
 448                 t1->constant_value() == t2->constant_value());
 449       }
 450   }
 451   return false;

 452 }
 453 
 454 Constant::CompareResult Constant::compare(Instruction::Condition cond, Value right) const {
 455   Constant* rc = right->as_Constant();
 456   // other is not a constant
 457   if (rc == NULL) return not_comparable;
 458 
 459   ValueType* lt = type();
 460   ValueType* rt = rc->type();
 461   // different types
 462   if (lt->base() != rt->base()) return not_comparable;
 463   switch (lt->tag()) {
 464   case intTag: {
 465     int x = lt->as_IntConstant()->value();
 466     int y = rt->as_IntConstant()->value();
 467     switch (cond) {
 468     case If::eql: return x == y ? cond_true : cond_false;
 469     case If::neq: return x != y ? cond_true : cond_false;
 470     case If::lss: return x <  y ? cond_true : cond_false;
 471     case If::leq: return x <= y ? cond_true : cond_false;
 472     case If::gtr: return x >  y ? cond_true : cond_false;
 473     case If::geq: return x >= y ? cond_true : cond_false;

 474     }
 475     break;
 476   }
 477   case longTag: {
 478     jlong x = lt->as_LongConstant()->value();
 479     jlong y = rt->as_LongConstant()->value();
 480     switch (cond) {
 481     case If::eql: return x == y ? cond_true : cond_false;
 482     case If::neq: return x != y ? cond_true : cond_false;
 483     case If::lss: return x <  y ? cond_true : cond_false;
 484     case If::leq: return x <= y ? cond_true : cond_false;
 485     case If::gtr: return x >  y ? cond_true : cond_false;
 486     case If::geq: return x >= y ? cond_true : cond_false;

 487     }
 488     break;
 489   }
 490   case objectTag: {
 491     ciObject* xvalue = lt->as_ObjectType()->constant_value();
 492     ciObject* yvalue = rt->as_ObjectType()->constant_value();
 493     assert(xvalue != NULL && yvalue != NULL, "not constants");
 494     if (xvalue->is_loaded() && yvalue->is_loaded()) {
 495       switch (cond) {
 496       case If::eql: return xvalue == yvalue ? cond_true : cond_false;
 497       case If::neq: return xvalue != yvalue ? cond_true : cond_false;

 498       }
 499     }
 500     break;
 501   }
 502   case metaDataTag: {
 503     ciMetadata* xvalue = lt->as_MetadataType()->constant_value();
 504     ciMetadata* yvalue = rt->as_MetadataType()->constant_value();
 505     assert(xvalue != NULL && yvalue != NULL, "not constants");
 506     if (xvalue->is_loaded() && yvalue->is_loaded()) {
 507       switch (cond) {
 508       case If::eql: return xvalue == yvalue ? cond_true : cond_false;
 509       case If::neq: return xvalue != yvalue ? cond_true : cond_false;

 510       }
 511     }
 512     break;
 513   }


 514   }
 515   return not_comparable;
 516 }
 517 
 518 
 519 // Implementation of BlockBegin
 520 
 521 void BlockBegin::set_end(BlockEnd* end) {
 522   assert(end != NULL, "should not reset block end to NULL");
 523   if (end == _end) {
 524     return;
 525   }
 526   clear_end();
 527 
 528   // Set the new end
 529   _end = end;
 530 
 531   _successors.clear();
 532   // Now reset successors list based on BlockEnd
 533   for (int i = 0; i < end->number_of_sux(); i++) {


   1 /*
   2  * Copyright (c) 1999, 2017, Oracle and/or its affiliates. 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 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  *


 222 ciType* NewInstance::declared_type() const {
 223   return exact_type();
 224 }
 225 
 226 ciType* CheckCast::declared_type() const {
 227   return klass();
 228 }
 229 
 230 // Implementation of ArithmeticOp
 231 
 232 bool ArithmeticOp::is_commutative() const {
 233   switch (op()) {
 234     case Bytecodes::_iadd: // fall through
 235     case Bytecodes::_ladd: // fall through
 236     case Bytecodes::_fadd: // fall through
 237     case Bytecodes::_dadd: // fall through
 238     case Bytecodes::_imul: // fall through
 239     case Bytecodes::_lmul: // fall through
 240     case Bytecodes::_fmul: // fall through
 241     case Bytecodes::_dmul: return true;
 242     default              : return false;
 243   }

 244 }
 245 
 246 
 247 bool ArithmeticOp::can_trap() const {
 248   switch (op()) {
 249     case Bytecodes::_idiv: // fall through
 250     case Bytecodes::_ldiv: // fall through
 251     case Bytecodes::_irem: // fall through
 252     case Bytecodes::_lrem: return true;
 253     default              : return false;
 254   }

 255 }
 256 
 257 
 258 // Implementation of LogicOp
 259 
 260 bool LogicOp::is_commutative() const {
 261 #ifdef ASSERT
 262   switch (op()) {
 263     case Bytecodes::_iand: // fall through
 264     case Bytecodes::_land: // fall through
 265     case Bytecodes::_ior : // fall through
 266     case Bytecodes::_lor : // fall through
 267     case Bytecodes::_ixor: // fall through
 268     case Bytecodes::_lxor: break;
 269     default              : ShouldNotReachHere(); break;
 270   }
 271 #endif
 272   // all LogicOps are commutative
 273   return true;
 274 }
 275 
 276 
 277 // Implementation of IfOp
 278 
 279 bool IfOp::is_commutative() const {
 280   return cond() == eql || cond() == neq;
 281 }
 282 
 283 
 284 // Implementation of StateSplit
 285 
 286 void StateSplit::substitute(BlockList& list, BlockBegin* old_block, BlockBegin* new_block) {
 287   NOT_PRODUCT(bool assigned = false;)
 288   for (int i = 0; i < list.length(); i++) {
 289     BlockBegin** b = list.adr_at(i);


 430         DoubleConstant* t2 = v->type()->as_DoubleConstant();
 431         return (t1 != NULL && t2 != NULL &&
 432                 jlong_cast(t1->value()) == jlong_cast(t2->value()));
 433       }
 434     case objectTag:
 435       {
 436         ObjectType* t1 =    type()->as_ObjectType();
 437         ObjectType* t2 = v->type()->as_ObjectType();
 438         return (t1 != NULL && t2 != NULL &&
 439                 t1->is_loaded() && t2->is_loaded() &&
 440                 t1->constant_value() == t2->constant_value());
 441       }
 442     case metaDataTag:
 443       {
 444         MetadataType* t1 =    type()->as_MetadataType();
 445         MetadataType* t2 = v->type()->as_MetadataType();
 446         return (t1 != NULL && t2 != NULL &&
 447                 t1->is_loaded() && t2->is_loaded() &&
 448                 t1->constant_value() == t2->constant_value());
 449       }
 450     default:
 451       return false;
 452   }
 453 }
 454 
 455 Constant::CompareResult Constant::compare(Instruction::Condition cond, Value right) const {
 456   Constant* rc = right->as_Constant();
 457   // other is not a constant
 458   if (rc == NULL) return not_comparable;
 459 
 460   ValueType* lt = type();
 461   ValueType* rt = rc->type();
 462   // different types
 463   if (lt->base() != rt->base()) return not_comparable;
 464   switch (lt->tag()) {
 465   case intTag: {
 466     int x = lt->as_IntConstant()->value();
 467     int y = rt->as_IntConstant()->value();
 468     switch (cond) {
 469     case If::eql: return x == y ? cond_true : cond_false;
 470     case If::neq: return x != y ? cond_true : cond_false;
 471     case If::lss: return x <  y ? cond_true : cond_false;
 472     case If::leq: return x <= y ? cond_true : cond_false;
 473     case If::gtr: return x >  y ? cond_true : cond_false;
 474     case If::geq: return x >= y ? cond_true : cond_false;
 475     default     : break;
 476     }
 477     break;
 478   }
 479   case longTag: {
 480     jlong x = lt->as_LongConstant()->value();
 481     jlong y = rt->as_LongConstant()->value();
 482     switch (cond) {
 483     case If::eql: return x == y ? cond_true : cond_false;
 484     case If::neq: return x != y ? cond_true : cond_false;
 485     case If::lss: return x <  y ? cond_true : cond_false;
 486     case If::leq: return x <= y ? cond_true : cond_false;
 487     case If::gtr: return x >  y ? cond_true : cond_false;
 488     case If::geq: return x >= y ? cond_true : cond_false;
 489     default     : break;
 490     }
 491     break;
 492   }
 493   case objectTag: {
 494     ciObject* xvalue = lt->as_ObjectType()->constant_value();
 495     ciObject* yvalue = rt->as_ObjectType()->constant_value();
 496     assert(xvalue != NULL && yvalue != NULL, "not constants");
 497     if (xvalue->is_loaded() && yvalue->is_loaded()) {
 498       switch (cond) {
 499       case If::eql: return xvalue == yvalue ? cond_true : cond_false;
 500       case If::neq: return xvalue != yvalue ? cond_true : cond_false;
 501       default     : break;
 502       }
 503     }
 504     break;
 505   }
 506   case metaDataTag: {
 507     ciMetadata* xvalue = lt->as_MetadataType()->constant_value();
 508     ciMetadata* yvalue = rt->as_MetadataType()->constant_value();
 509     assert(xvalue != NULL && yvalue != NULL, "not constants");
 510     if (xvalue->is_loaded() && yvalue->is_loaded()) {
 511       switch (cond) {
 512       case If::eql: return xvalue == yvalue ? cond_true : cond_false;
 513       case If::neq: return xvalue != yvalue ? cond_true : cond_false;
 514       default     : break;
 515       }
 516     }
 517     break;
 518   }
 519   default:
 520     break;
 521   }
 522   return not_comparable;
 523 }
 524 
 525 
 526 // Implementation of BlockBegin
 527 
 528 void BlockBegin::set_end(BlockEnd* end) {
 529   assert(end != NULL, "should not reset block end to NULL");
 530   if (end == _end) {
 531     return;
 532   }
 533   clear_end();
 534 
 535   // Set the new end
 536   _end = end;
 537 
 538   _successors.clear();
 539   // Now reset successors list based on BlockEnd
 540   for (int i = 0; i < end->number_of_sux(); i++) {


< prev index next >