/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "precompiled.hpp"
#include "c1/c1_Canonicalizer.hpp"
#include "c1/c1_InstructionPrinter.hpp"
#include "c1/c1_ValueStack.hpp"
#include "ci/ciArray.hpp"
#include "runtime/sharedRuntime.hpp"
(*vp)->print_line();
}
};
// Note: we can not currently substitute root nodes which show up in
// the instruction stream (because the instruction list is embedded
// in the instructions).
if (canonical() != x) {
#ifndef PRODUCT
if (!x->has_printable_bci()) {
x->set_printable_bci(bci());
}
#endif
if (PrintCanonicalization) {
canonical()->print_line();
x->print_line();
}
_canonical = x;
}
}
}
if (x->x() == x->y()) {
switch (x->op()) {
}
}
// do constant folding for selected operations
case intTag:
switch (x->op()) {
if (b != 0) {
if (a == min_jint && b == -1) {
} else {
set_constant(a / b);
}
return;
}
break;
if (b != 0) {
if (a == min_jint && b == -1) {
set_constant(0);
} else {
set_constant(a % b);
}
return;
}
break;
}
}
break;
case longTag:
switch (x->op()) {
if (b != 0) {
return;
}
break;
if (b != 0) {
return;
}
break;
}
}
break;
// other cases not implemented (must be extremely careful with floats & doubles!)
}
}
// make sure constant is on the right side, if any
if (x->y()->type()->is_constant()) {
// do constant folding for selected operations
case intTag:
switch (x->op()) {
// Note: for div and rem, make sure that C semantics
// corresponds to Java semantics!
}
}
break;
case longTag:
switch (x->op()) {
// Note: for div and rem, make sure that C semantics
// corresponds to Java semantics!
}
}
break;
}
}
}
// checks if v is in the block that is currently processed by
// GraphBuilder. This is the only block that has not BlockEnd yet.
v = v->next();
max_distance--;
}
return v == NULL;
}
// If a value is going to be stored into a field or array some of
// the conversions emitted by javac are unneeded because the fields
// are packed to their natural size.
if (conv) {
}
// limit this optimization to current block
x->state_before(), x->needs_patching()));
return;
}
}
}
// do not use the Constant itself, but create a new Constant
// with same value Otherwise a Constant is live over multiple
// blocks without being registered in a state array.
}
} else {
// final static field
if (c->is_array()) {
}
}
}
}
}
// If a value is going to be stored into a field or array some of
// the conversions emitted by javac are unneeded because the fields
// are packed to their natural size.
if (conv) {
}
// limit this optimization to current block
return;
}
}
}
if (t->is_constant()) {
switch (t->tag()) {
default : ShouldNotReachHere();
}
}
}
if (t->is_constant()) {
switch (t->tag()) {
case longTag : if (t->as_LongConstant()->value() == (jlong)0) { set_constant(jlong_cast(0)); return; } break;
default : ShouldNotReachHere();
}
if (t2->is_constant()) {
switch (x->op()) {
}
switch (x->op()) {
}
}
}
}
if (t2->is_constant()) {
default : ShouldNotReachHere();
}
}
}
if (x->x() == x->y()) {
case longTag: set_constant(0); break;
case floatTag: {
if (fc) {
} else {
set_constant(0);
}
}
break;
}
case doubleTag: {
if (dc) {
} else {
set_constant(0);
}
}
break;
}
}
case longTag: {
set_constant(0);
set_constant(-1);
else
set_constant(1);
break;
}
case floatTag: {
set_constant(0);
set_constant(-1);
else
set_constant(1);
break;
}
case doubleTag: {
set_constant(0);
set_constant(-1);
else
set_constant(1);
break;
}
}
}
}
// Caution: do not use do_Op2(x) here for now since
// we map the condition to the op for now!
}
switch (x->id()) {
case vmIntrinsics::_floatToRawIntBits : {
if (c != NULL) {
JavaValue v;
v.set_jfloat(c->value());
set_constant(v.get_jint());
}
break;
}
case vmIntrinsics::_intBitsToFloat : {
if (c != NULL) {
JavaValue v;
set_constant(v.get_jfloat());
}
break;
}
case vmIntrinsics::_doubleToRawLongBits : {
if (c != NULL) {
JavaValue v;
v.set_jdouble(c->value());
set_constant(v.get_jlong());
}
break;
}
case vmIntrinsics::_longBitsToDouble : {
if (c != NULL) {
JavaValue v;
set_constant(v.get_jdouble());
}
break;
}
case vmIntrinsics::_isInstance : {
// ciInstance::java_mirror_type() returns non-NULL only for Java mirrors
if (t->is_klass()) {
// substitute cls.isInstance(obj) of a constant Class into
// an InstantOf instruction
set_canonical(i);
// and try to canonicalize even further
do_InstanceOf(i);
} else {
// cls.isInstance(obj) always returns false for primitive classes
set_constant(0);
}
}
break;
}
}
}
switch (x->op()) {
case Bytecodes::_i2b: set_constant((int)((x->value()->type()->as_IntConstant()->value() << 24) >> 24)); break;
case Bytecodes::_i2s: set_constant((int)((x->value()->type()->as_IntConstant()->value() << 16) >> 16)); break;
case Bytecodes::_i2c: set_constant((int)(x->value()->type()->as_IntConstant()->value() & ((1<<16)-1))); break;
case Bytecodes::_l2f: set_constant(SharedRuntime::l2f(x->value()->type()->as_LongConstant()->value())); break;
case Bytecodes::_l2d: set_constant(SharedRuntime::l2d(x->value()->type()->as_LongConstant()->value())); break;
case Bytecodes::_f2d: set_constant((double)(x->value()->type()->as_FloatConstant()->value())); break;
case Bytecodes::_f2i: set_constant(SharedRuntime::f2i(x->value()->type()->as_FloatConstant()->value())); break;
case Bytecodes::_f2l: set_constant(SharedRuntime::f2l(x->value()->type()->as_FloatConstant()->value())); break;
case Bytecodes::_d2f: set_constant((float)(x->value()->type()->as_DoubleConstant()->value())); break;
case Bytecodes::_d2i: set_constant(SharedRuntime::d2i(x->value()->type()->as_DoubleConstant()->value())); break;
case Bytecodes::_d2l: set_constant(SharedRuntime::d2l(x->value()->type()->as_DoubleConstant()->value())); break;
default:
}
}
if (lf) {
} else {
if (li) {
} else {
if (conv) {
}
}
}
}
switch (x->op()) {
}
} else {
switch (x->op()) {
}
// When casting a masked integer to a smaller signed type, if
// the mask doesn't include the sign bit the cast isn't needed.
set_canonical(x->value());
}
}
}
}
set_canonical(x->obj());
} else {
if (con) {
if (c && c->is_loaded()) {
}
}
}
}
}
return;
}
// checkcast of null returns null
}
}
}
return;
}
// instanceof null returns false
set_constant(0);
}
}
}
switch (cond) {
}
return false;
}
// An Instruction with multiple successors, x, is replaced by a Goto
// to a single successor, sux. Is a safepoint check needed = was the
// instruction being replaced a safepoint and the single remaining
// successor a back branch?
}
// move const to right
// simplify
if (l == r && !lt->is_float_kind()) {
// pattern: If (a cond a) => simplify to Goto
switch (x->cond()) {
}
// If is a safepoint then the debug information should come from the state_before of the If.
return;
}
if (x->x()->as_Constant() != NULL) {
// pattern: If (lc cond rc) => simplify to: Goto
x->sux_for(true),
x->sux_for(false));
// If is a safepoint then the debug information should come from the state_before of the If.
}
}
// pattern: If (l cond rc) => investigate further
if (l->as_CompareOp() != NULL) {
// pattern: If ((a cmp b) cond rc) => simplify to: If (x cond y) or: Goto
// Note: At this point all successors (lss_sux, eql_sux, gtr_sux, nan_sux) are
// equal to x->tsux() or x->fsux(). Furthermore, nan_sux equals either
// lss_sux or gtr_sux.
// all successors identical => simplify to: Goto
} else {
// two successors differ and two successors are the same => simplify to: If (x cmp y)
// determine new condition & successors
else { ShouldNotReachHere(); }
If* canon = new If(cmp->x(), cond, nan_sux == tsux, cmp->y(), tsux, fsux, cmp->state_before(), x->is_safepoint());
} else {
if (compilation()->profile_branches()) {
// TODO: If profiling, leave floating point comparisons unoptimized.
// We currently do not support profiling of the unordered case.
set_canonical(x);
return;
}
}
}
}
} else if (l->as_InstanceOf() != NULL) {
// NOTE: Code permanently disabled for now since it leaves the old InstanceOf
// instruction in the graph (it is pinned). Need to fix this at some point.
// It should also be left in the graph when generating a profiled method version or Goto
// has to know that it was an InstanceOf.
return;
// pattern: If ((obj instanceof klass) cond rc) => simplify to: IfInstanceOf or: Goto
// both successors identical and klass is loaded => simplify to: Goto
} else {
// successors differ => simplify to: IfInstanceOf
set_canonical(new IfInstanceOf(inst->klass(), inst->obj(), true, inst->state_before()->bci(), is_inst_sux, no_inst_sux));
}
}
} else {
}
}
}
}
} else if (x->number_of_sux() == 1) {
// NOTE: Code permanently disabled for now since the switch statement's
// tag expression may produce side-effects in which case it must
// be executed.
return;
// simplify to Goto
} else if (x->number_of_sux() == 2) {
// NOTE: Code permanently disabled for now since it produces two new nodes
// (Constant & If) and the Canonicalizer cannot return them correctly
// yet. For now we copied the corresponding code directly into the
// GraphBuilder (i.e., we should never reach here).
return;
// simplify to If
set_canonical(new If(x->tag(), If::eql, true, key, x->sux_at(0), x->default_sux(), x->state_before(), x->is_safepoint()));
}
}
for (int i = 0; i < x->length(); i++) {
if (v == x->key_at(i)) {
}
}
} else if (x->number_of_sux() == 1) {
// NOTE: Code permanently disabled for now since the switch statement's
// tag expression may produce side-effects in which case it must
// be executed.
return;
// simplify to Goto
} else if (x->number_of_sux() == 2) {
// NOTE: Code permanently disabled for now since it produces two new nodes
// (Constant & If) and the Canonicalizer cannot return them correctly
// yet. For now we copied the corresponding code directly into the
// GraphBuilder (i.e., we should never reach here).
return;
// simplify to If
set_canonical(new If(x->tag(), If::eql, true, key, x->sux_at(0), x->default_sux(), x->state_before(), x->is_safepoint()));
}
}
Instruction** index,
int* log2_scale,
*instr_to_unpin = NULL;
// Skip conversion ops
}
*instr_to_unpin = shift;
}
// Constant shift value?
// Well-known type and value?
*log2_scale = tmp_scale;
return true;
} else {
return false;
}
}
*instr_to_unpin = arith;
}
// Check for integer multiply
// See if either arg is a known constant
} else {
}
// Well-known type and value?
case 1: *log2_scale = 0; return true;
default: return false;
}
}
}
// Unknown instruction sequence; don't touch it
return false;
}
Instruction** base,
Instruction** index,
int* log2_scale) {
// Limit ourselves to addition for now
// Try to find shift or scale op
// pick base and index, setting scale at 1
*log2_scale = 0;
} else {
return false;
}
} else {
// doesn't match any expected sequences
return false;
}
// If the value is pinned then it will be always be computed so
// there's no profit to reshaping the expression.
}
int log2_scale;
x->set_log2_scale(log2_scale);
if (PrintUnsafeOptimization) {
}
}
}