/* * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * 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. *
*/
//============================================================================= // If input is already higher or equal to cast type, then this is an identity.
Node* ConstraintCastNode::Identity(PhaseGVN* phase) {
Node* dom = dominating_cast(phase, phase); if (dom != NULL) { return dom;
} if (_dependency != RegularDependency) { returnthis;
} return phase->type(in(1))->higher_equal_speculative(_type) ? in(1) : this;
}
//------------------------------Value------------------------------------------ // Take 'join' of input and cast-up type const Type* ConstraintCastNode::Value(PhaseGVN* phase) const { if (in(0) && phase->type(in(0)) == Type::TOP) return Type::TOP; const Type* ft = phase->type(in(1))->filter_speculative(_type);
#ifdef ASSERT // Previous versions of this function had some special case logic, // which is no longer necessary. Make sure of the required effects. switch (Opcode()) { case Op_CastII:
{ const Type* t1 = phase->type(in(1)); if( t1 == Type::TOP ) assert(ft == Type::TOP, "special case #1"); const Type* rt = t1->join_speculative(_type); if (rt->empty()) assert(ft == Type::TOP, "special case #2"); break;
} case Op_CastPP: if (phase->type(in(1)) == TypePtr::NULL_PTR &&
_type->isa_ptr() && _type->is_ptr()->_ptr == TypePtr::NotNull)
assert(ft == Type::TOP, "special case #3"); break;
} #endif//ASSERT
return ft;
}
//------------------------------Ideal------------------------------------------ // Return a node which is more "ideal" than the current node. Strip out // control copies
Node *ConstraintCastNode::Ideal(PhaseGVN *phase, bool can_reshape) { return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
}
Node* ConstraintCastNode::make_cast(int opcode, Node* c, Node *n, const Type *t, DependencyType dependency) { switch(opcode) { case Op_CastII: {
Node* cast = new CastIINode(n, t, dependency);
cast->set_req(0, c); return cast;
} case Op_CastLL: {
Node* cast = new CastLLNode(n, t, dependency);
cast->set_req(0, c); return cast;
} case Op_CastPP: {
Node* cast = new CastPPNode(n, t, dependency);
cast->set_req(0, c); return cast;
} case Op_CastFF: {
Node* cast = new CastFFNode(n, t, dependency);
cast->set_req(0, c); return cast;
} case Op_CastDD: {
Node* cast = new CastDDNode(n, t, dependency);
cast->set_req(0, c); return cast;
} case Op_CastVV: {
Node* cast = new CastVVNode(n, t, dependency);
cast->set_req(0, c); return cast;
} case Op_CheckCastPP: returnnew CheckCastPPNode(c, n, t, dependency); default:
fatal("Bad opcode %d", opcode);
} return NULL;
}
Node* ConstraintCastNode::make(Node* c, Node *n, const Type *t, DependencyType dependency, BasicType bt) { switch(bt) { case T_INT: { return make_cast(Op_CastII, c, n, t, dependency);
} case T_LONG: { return make_cast(Op_CastLL, c, n, t, dependency);
} default:
fatal("Bad basic type %s", type2name(bt));
} return NULL;
}
TypeNode* ConstraintCastNode::dominating_cast(PhaseGVN* gvn, PhaseTransform* pt) const { if (_dependency == UnconditionalDependency) { return NULL;
}
Node* val = in(1);
Node* ctl = in(0); int opc = Opcode(); if (ctl == NULL) { return NULL;
} // Range check CastIIs may all end up under a single range check and // in that case only the narrower CastII would be kept by the code // below which would be incorrect. if (is_CastII() && as_CastII()->has_range_check()) { return NULL;
} if (type()->isa_rawptr() && (gvn->type_or_null(val) == NULL || gvn->type(val)->isa_oopptr())) { return NULL;
} for (DUIterator_Fast imax, i = val->fast_outs(imax); i < imax; i++) {
Node* u = val->fast_out(i); if (u != this &&
u->outcnt() > 0 &&
u->Opcode() == opc &&
u->in(0) != NULL &&
u->bottom_type()->higher_equal(type())) { if (pt->is_dominator(u->in(0), ctl)) { return u->as_Type();
} if (is_CheckCastPP() && u->in(1)->is_Proj() && u->in(1)->in(0)->is_Allocate() &&
u->in(0)->is_Proj() && u->in(0)->in(0)->is_Initialize() &&
u->in(1)->in(0)->as_Allocate()->initialization() == u->in(0)->in(0)) { // CheckCastPP following an allocation always dominates all // use of the allocation result return u->as_Type();
}
}
} return NULL;
}
const Type* CastIINode::Value(PhaseGVN* phase) const { const Type *res = ConstraintCastNode::Value(phase); if (res == Type::TOP) { return Type::TOP;
}
assert(res->isa_int(), "res must be int");
// Similar to ConvI2LNode::Value() for the same reasons // see if we can remove type assertion after loop opts // But here we have to pay extra attention: // Do not narrow the type of range check dependent CastIINodes to // avoid corruption of the graph if a CastII is replaced by TOP but // the corresponding range check is not removed. if (!_range_check_dependency) {
res = widen_type(phase, res, T_INT);
}
// Try to improve the type of the CastII if we recognize a CmpI/If // pattern. if (_dependency != RegularDependency) { if (in(0) != NULL && in(0)->in(0) != NULL && in(0)->in(0)->is_If()) {
assert(in(0)->is_IfFalse() || in(0)->is_IfTrue(), "should be If proj");
Node* proj = in(0); if (proj->in(0)->in(1)->is_Bool()) {
Node* b = proj->in(0)->in(1); if (b->in(1)->Opcode() == Op_CmpI) {
Node* cmp = b->in(1); if (cmp->in(1) == in(1) && phase->type(cmp->in(2))->isa_int()) { const TypeInt* in2_t = phase->type(cmp->in(2))->is_int(); const Type* t = TypeInt::INT;
BoolTest test = b->as_Bool()->_test; if (proj->is_IfFalse()) {
test = test.negate();
}
BoolTest::mask m = test._test;
jlong lo_long = min_jint;
jlong hi_long = max_jint; if (m == BoolTest::le || m == BoolTest::lt) {
hi_long = in2_t->_hi; if (m == BoolTest::lt) {
hi_long -= 1;
}
} elseif (m == BoolTest::ge || m == BoolTest::gt) {
lo_long = in2_t->_lo; if (m == BoolTest::gt) {
lo_long += 1;
}
} elseif (m == BoolTest::eq) {
lo_long = in2_t->_lo;
hi_long = in2_t->_hi;
} elseif (m == BoolTest::ne) { // can't do any better
} else {
stringStream ss;
test.dump_on(&ss);
fatal("unexpected comparison %s", ss.freeze());
} int lo_int = (int)lo_long; int hi_int = (int)hi_long;
if (lo_long != (jlong)lo_int) {
lo_int = min_jint;
} if (hi_long != (jlong)hi_int) {
hi_int = max_jint;
}
t = TypeInt::make(lo_int, hi_int, Type::WidenMax);
#ifndef PRODUCT void CastIINode::dump_spec(outputStream* st) const {
ConstraintCastNode::dump_spec(st); if (_range_check_dependency) {
st->print(" range check dependency");
}
} #endif
const Type* CastLLNode::Value(PhaseGVN* phase) const { const Type* res = ConstraintCastNode::Value(phase); if (res == Type::TOP) { return Type::TOP;
}
assert(res->isa_long(), "res must be long");
return widen_type(phase, res, T_LONG);
}
Node* CastLLNode::Ideal(PhaseGVN* phase, bool can_reshape) {
Node* progress = ConstraintCastNode::Ideal(phase, can_reshape); if (progress != NULL) { return progress;
} if (can_reshape && !phase->C->post_loop_opts_phase()) { // makes sure we run ::Value to potentially remove type assertion after loop opts
phase->C->record_for_post_loop_opts_igvn(this);
} // transform (CastLL (ConvI2L ..)) into (ConvI2L (CastII ..)) if the type of the CastLL is narrower than the type of // the ConvI2L.
Node* in1 = in(1); if (in1 != NULL && in1->Opcode() == Op_ConvI2L) { const Type* t = Value(phase); const Type* t_in = phase->type(in1); if (t != Type::TOP && t_in != Type::TOP) { const TypeLong* tl = t->is_long(); const TypeLong* t_in_l = t_in->is_long();
assert(tl->_lo >= t_in_l->_lo && tl->_hi <= t_in_l->_hi, "CastLL type should be narrower than or equal to the type of its input");
assert((tl != t_in_l) == (tl->_lo > t_in_l->_lo || tl->_hi < t_in_l->_hi), "if type differs then this nodes's type must be narrower"); if (tl != t_in_l) { const TypeInt* ti = TypeInt::make(checked_cast<jint>(tl->_lo), checked_cast<jint>(tl->_hi), tl->_widen);
Node* castii = phase->transform(new CastIINode(in(0), in1->in(1), ti));
Node* convi2l = in1->clone();
convi2l->set_req(1, castii); return convi2l;
}
}
} return optimize_integer_cast(phase, T_LONG);
}
//============================================================================= //------------------------------Identity--------------------------------------- // If input is already higher or equal to cast type, then this is an identity.
Node* CheckCastPPNode::Identity(PhaseGVN* phase) {
Node* dom = dominating_cast(phase, phase); if (dom != NULL) { return dom;
} if (_dependency != RegularDependency) { returnthis;
} const Type* t = phase->type(in(1)); if (EnableVectorReboxing && in(1)->Opcode() == Op_VectorBox) { if (t->higher_equal_speculative(phase->type(this))) { return in(1);
}
} elseif (t == phase->type(this)) { // Toned down to rescue meeting at a Phi 3 different oops all implementing // the same interface. return in(1);
} returnthis;
}
//------------------------------Value------------------------------------------ // Take 'join' of input and cast-up type, unless working with an Interface const Type* CheckCastPPNode::Value(PhaseGVN* phase) const { if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
const Type *inn = phase->type(in(1)); if( inn == Type::TOP ) return Type::TOP; // No information yet
// This is the code from TypePtr::xmeet() that prevents us from // having 2 ways to represent the same type. We have to replicate it // here because we don't go through meet/join. if (result->remove_speculative() == result->speculative()) {
result = result->remove_speculative();
}
// Same as above: because we don't go through meet/join, remove the // speculative type if we know we won't use it. return result->cleanup_speculative();
// JOIN NOT DONE HERE BECAUSE OF INTERFACE ISSUES. // FIX THIS (DO THE JOIN) WHEN UNION TYPES APPEAR!
// // Remove this code after overnight run indicates no performance // loss from not performing JOIN at CheckCastPPNode // // const TypeInstPtr *in_oop = in->isa_instptr(); // const TypeInstPtr *my_oop = _type->isa_instptr(); // // If either input is an 'interface', return destination type // assert (in_oop == NULL || in_oop->klass() != NULL, ""); // assert (my_oop == NULL || my_oop->klass() != NULL, ""); // if( (in_oop && in_oop->klass()->is_interface()) // ||(my_oop && my_oop->klass()->is_interface()) ) { // TypePtr::PTR in_ptr = in->isa_ptr() ? in->is_ptr()->_ptr : TypePtr::BotPTR; // // Preserve cast away nullness for interfaces // if( in_ptr == TypePtr::NotNull && my_oop && my_oop->_ptr == TypePtr::BotPTR ) { // return my_oop->cast_to_ptr_type(TypePtr::NotNull); // } // return _type; // } // // // Neither the input nor the destination type is an interface, // // // history: JOIN used to cause weird corner case bugs // // return (in == TypeOopPtr::NULL_PTR) ? in : _type; // // JOIN picks up NotNull in common instance-of/check-cast idioms, both oops. // // JOIN does not preserve NotNull in other cases, e.g. RawPtr vs InstPtr // const Type *join = in->join(_type); // // Check if join preserved NotNull'ness for pointers // if( join->isa_ptr() && _type->isa_ptr() ) { // TypePtr::PTR join_ptr = join->is_ptr()->_ptr; // TypePtr::PTR type_ptr = _type->is_ptr()->_ptr; // // If there isn't any NotNull'ness to preserve // // OR if join preserved NotNull'ness then return it // if( type_ptr == TypePtr::BotPTR || type_ptr == TypePtr::Null || // join_ptr == TypePtr::NotNull || join_ptr == TypePtr::Constant ) { // return join; // } // // ELSE return same old type as before // return _type; // } // // Not joining two pointers // return join;
}
Node *CastX2PNode::Ideal(PhaseGVN *phase, bool can_reshape) { // convert CastX2P(AddX(x, y)) to AddP(CastX2P(x), y) if y fits in an int int op = in(1)->Opcode();
Node* x;
Node* y; switch (op) { case Op_SubX:
x = in(1)->in(1); // Avoid ideal transformations ping-pong between this and AddP for raw pointers. if (phase->find_intptr_t_con(x, -1) == 0) break;
y = in(1)->in(2); if (fits_in_int(phase->type(y), true)) { return addP_of_X2P(phase, x, y, true);
} break; case Op_AddX:
x = in(1)->in(1);
y = in(1)->in(2); if (fits_in_int(phase->type(y))) { return addP_of_X2P(phase, x, y);
} if (fits_in_int(phase->type(x))) { return addP_of_X2P(phase, y, x);
} break;
} return NULL;
}
Node* ConstraintCastNode::optimize_integer_cast(PhaseGVN* phase, BasicType bt) {
PhaseIterGVN *igvn = phase->is_IterGVN(); const TypeInteger* this_type = this->type()->is_integer(bt);
Node* z = in(1); const TypeInteger* rx = NULL; const TypeInteger* ry = NULL; // Similar to ConvI2LNode::Ideal() for the same reasons if (Compile::push_thru_add(phase, z, this_type, rx, ry, bt, bt)) { if (igvn == NULL) { // Postpone this optimization to iterative GVN, where we can handle deep // AddI chains without an exponential number of recursive Ideal() calls.
phase->record_for_igvn(this); return NULL;
} int op = z->Opcode();
Node* x = z->in(1);
Node* y = z->in(2);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.