Skip to content

Commit e88e793

Browse files
theoweidmannoraclechhagedorn
authored andcommitted
8343148: C2: Refactor uses of "PhaseValue::*con*() + PhaseIdealLoop::set_ctrl()" into separate method
Reviewed-by: kvn, chagedorn, thartmann
1 parent 1e9204f commit e88e793

8 files changed

+90
-90
lines changed

src/hotspot/share/gc/shenandoah/c2/shenandoahSupport.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ void ShenandoahBarrierC2Support::test_gc_state(Node*& ctrl, Node* raw_mem, Node*
887887
phase->register_new_node(gc_state_cmp, old_ctrl);
888888
phase->register_new_node(gc_state_bool, old_ctrl);
889889

890-
phase->set_ctrl(gc_state_offset, phase->C->root());
890+
phase->set_root_as_ctrl(gc_state_offset);
891891

892892
assert(is_gc_state_test(gc_state_iff, flags), "Should match the shape");
893893
}
@@ -945,7 +945,7 @@ void ShenandoahBarrierC2Support::test_in_cset(Node*& ctrl, Node*& not_cset_ctrl,
945945
phase->register_control(ctrl, loop, cset_iff);
946946
phase->register_control(not_cset_ctrl, loop, cset_iff);
947947

948-
phase->set_ctrl(cset_addr_ptr, phase->C->root());
948+
phase->set_root_as_ctrl(cset_addr_ptr);
949949

950950
phase->register_new_node(raw_val, old_ctrl);
951951
phase->register_new_node(cset_idx, old_ctrl);

src/hotspot/share/opto/loopPredicate.cpp

+5-10
Original file line numberDiff line numberDiff line change
@@ -766,17 +766,15 @@ BoolNode* PhaseIdealLoop::rc_predicate(Node* ctrl, const int scale, Node* offset
766766
if ((stride > 0 && (java_subtract(limit_lo, stride) < limit_lo)) ||
767767
(stride < 0 && (java_subtract(limit_hi, stride) > limit_hi))) {
768768
// No overflow possible
769-
ConINode* con_stride = _igvn.intcon(stride);
770-
set_ctrl(con_stride, C->root());
769+
ConINode* con_stride = intcon(stride);
771770
max_idx_expr = new SubINode(limit, con_stride);
772771
idx_type = TypeInt::make(limit_lo - stride, limit_hi - stride, limit_type->_widen);
773772
} else {
774773
// May overflow
775774
overflow = true;
776775
limit = new ConvI2LNode(limit);
777776
register_new_node(limit, ctrl);
778-
ConLNode* con_stride = _igvn.longcon(stride);
779-
set_ctrl(con_stride, C->root());
777+
ConLNode* con_stride = longcon(stride);
780778
max_idx_expr = new SubLNode(limit, con_stride);
781779
}
782780
register_new_node(max_idx_expr, ctrl);
@@ -793,8 +791,7 @@ BoolNode* PhaseIdealLoop::rc_predicate(Node* ctrl, const int scale, Node* offset
793791
}
794792

795793
if (scale != 1) {
796-
ConNode* con_scale = _igvn.intcon(scale);
797-
set_ctrl(con_scale, C->root());
794+
ConNode* con_scale = intcon(scale);
798795
if (TraceLoopPredicate) {
799796
predString->print("* %d ", scale);
800797
}
@@ -811,8 +808,7 @@ BoolNode* PhaseIdealLoop::rc_predicate(Node* ctrl, const int scale, Node* offset
811808
register_new_node(max_idx_expr, ctrl);
812809
}
813810
overflow = true;
814-
con_scale = _igvn.longcon(scale);
815-
set_ctrl(con_scale, C->root());
811+
con_scale = longcon(scale);
816812
max_idx_expr = new MulLNode(max_idx_expr, con_scale);
817813
} else {
818814
// No overflow possible
@@ -1342,8 +1338,7 @@ bool PhaseIdealLoop::loop_predication_impl(IdealLoopTree* loop) {
13421338
#endif
13431339
return false;
13441340
}
1345-
ConNode* zero = _igvn.intcon(0);
1346-
set_ctrl(zero, C->root());
1341+
ConNode* zero = intcon(0);
13471342

13481343
ResourceArea* area = Thread::current()->resource_area();
13491344
Invariance invar(area, loop);

src/hotspot/share/opto/loopTransform.cpp

+15-32
Original file line numberDiff line numberDiff line change
@@ -354,15 +354,11 @@ Node* IdealLoopTree::reassociate_add_sub_cmp(Node* n1, int inv1_idx, int inv2_id
354354
Node* inv1_c = phase->get_ctrl(inv1);
355355
Node* n_inv1;
356356
if (neg_inv1) {
357-
Node* zero;
358357
if (is_int) {
359-
zero = phase->_igvn.intcon(0);
360-
n_inv1 = new SubINode(zero, inv1);
358+
n_inv1 = new SubINode(phase->intcon(0), inv1);
361359
} else {
362-
zero = phase->_igvn.longcon(0L);
363-
n_inv1 = new SubLNode(zero, inv1);
360+
n_inv1 = new SubLNode(phase->longcon(0L), inv1);
364361
}
365-
phase->set_ctrl(zero, phase->C->root());
366362
phase->register_new_node(n_inv1, inv1_c);
367363
} else {
368364
n_inv1 = inv1;
@@ -1711,8 +1707,7 @@ void PhaseIdealLoop::update_main_loop_assertion_predicates(CountedLoopNode* main
17111707
// Compute the value of the loop induction variable at the end of the
17121708
// first iteration of the unrolled loop: init + new_stride_con - init_inc
17131709
int unrolled_stride_con = main_loop_head->stride_con() * 2;
1714-
Node* unrolled_stride = _igvn.intcon(unrolled_stride_con);
1715-
set_ctrl(unrolled_stride, C->root());
1710+
Node* unrolled_stride = intcon(unrolled_stride_con);
17161711

17171712
Node* loop_entry = main_loop_head->skip_strip_mined()->in(LoopNode::EntryControl);
17181713
PredicateIterator predicate_iterator(loop_entry);
@@ -1879,23 +1874,20 @@ void PhaseIdealLoop::do_unroll(IdealLoopTree *loop, Node_List &old_new, bool adj
18791874
if (limit->is_Con()) {
18801875
// The check in policy_unroll and the assert above guarantee
18811876
// no underflow if limit is constant.
1882-
new_limit = _igvn.intcon(limit->get_int() - stride_con);
1883-
set_ctrl(new_limit, C->root());
1877+
new_limit = intcon(limit->get_int() - stride_con);
18841878
} else {
18851879
// Limit is not constant. Int subtraction could lead to underflow.
18861880
// (1) Convert to long.
18871881
Node* limit_l = new ConvI2LNode(limit);
18881882
register_new_node_with_ctrl_of(limit_l, limit);
1889-
Node* stride_l = _igvn.longcon(stride_con);
1890-
set_ctrl(stride_l, C->root());
1883+
Node* stride_l = longcon(stride_con);
18911884

18921885
// (2) Subtract: compute in long, to prevent underflow.
18931886
Node* new_limit_l = new SubLNode(limit_l, stride_l);
18941887
register_new_node(new_limit_l, ctrl);
18951888

18961889
// (3) Clamp to int range, in case we had subtraction underflow.
1897-
Node* underflow_clamp_l = _igvn.longcon((stride_con > 0) ? min_jint : max_jint);
1898-
set_ctrl(underflow_clamp_l, C->root());
1890+
Node* underflow_clamp_l = longcon((stride_con > 0) ? min_jint : max_jint);
18991891
Node* new_limit_no_underflow_l = nullptr;
19001892
if (stride_con > 0) {
19011893
// limit = MaxL(limit - stride, min_jint)
@@ -1985,8 +1977,7 @@ void PhaseIdealLoop::do_unroll(IdealLoopTree *loop, Node_List &old_new, bool adj
19851977
// Kill the clone's backedge
19861978
Node *newcle = old_new[loop_end->_idx];
19871979
_igvn.hash_delete(newcle);
1988-
Node *one = _igvn.intcon(1);
1989-
set_ctrl(one, C->root());
1980+
Node* one = intcon(1);
19901981
newcle->set_req(1, one);
19911982
// Force clone into same loop body
19921983
uint max = loop->_body.size();
@@ -2122,8 +2113,7 @@ void PhaseIdealLoop::add_constraint(jlong stride_con, jlong scale_con, Node* off
21222113
// Only do this for the pre-loop, one less iteration of the main loop doesn't hurt.
21232114
bool round = ABS(scale_con) > 1;
21242115

2125-
Node* scale = _igvn.longcon(scale_con);
2126-
set_ctrl(scale, C->root());
2116+
Node* scale = longcon(scale_con);
21272117

21282118
if ((stride_con^scale_con) >= 0) { // Use XOR to avoid overflow
21292119
// Positive stride*scale: the affine function is increasing,
@@ -2162,8 +2152,7 @@ void PhaseIdealLoop::add_constraint(jlong stride_con, jlong scale_con, Node* off
21622152
// else /* scale > 0 and stride < 0 */
21632153
// I > (upper_limit-(offset+1))/scale
21642154
// )
2165-
Node* one = _igvn.longcon(1);
2166-
set_ctrl(one, C->root());
2155+
Node* one = longcon(1);
21672156
Node* plus_one = new AddLNode(offset, one);
21682157
register_new_node(plus_one, pre_ctrl);
21692158
*pre_limit = adjust_limit(!is_positive_stride, scale, plus_one, upper_limit, *pre_limit, pre_ctrl, round);
@@ -2368,8 +2357,7 @@ bool PhaseIdealLoop::is_scaled_iv_plus_offset(Node* exp, Node* iv, BasicType bt,
23682357
*p_scale = scale;
23692358
}
23702359
if (p_offset != nullptr) {
2371-
Node *zero = _igvn.zerocon(bt);
2372-
set_ctrl(zero, C->root());
2360+
Node* zero = zerocon(bt);
23732361
*p_offset = zero;
23742362
}
23752363
return true;
@@ -2420,8 +2408,7 @@ bool PhaseIdealLoop::is_scaled_iv_plus_offset(Node* exp, Node* iv, BasicType bt,
24202408
}
24212409
if (p_offset != nullptr) {
24222410
if (which == 1) { // must negate the extracted offset
2423-
Node *zero = _igvn.integercon(0, exp_bt);
2424-
set_ctrl(zero, C->root());
2411+
Node* zero = integercon(0, exp_bt);
24252412
Node *ctrl_off = get_ctrl(offset);
24262413
offset = SubNode::make(zero, offset, exp_bt);
24272414
register_new_node(offset, ctrl_off);
@@ -2540,13 +2527,10 @@ void PhaseIdealLoop::do_range_check(IdealLoopTree* loop) {
25402527

25412528
int stride_con = cl->stride_con();
25422529
bool abs_stride_is_one = stride_con == 1 || stride_con == -1;
2543-
Node* zero = _igvn.longcon(0);
2544-
Node* one = _igvn.longcon(1);
2530+
Node* zero = longcon(0);
2531+
Node* one = longcon(1);
25452532
// Use symmetrical int range [-max_jint,max_jint]
2546-
Node* mini = _igvn.longcon(-max_jint);
2547-
set_ctrl(zero, C->root());
2548-
set_ctrl(one, C->root());
2549-
set_ctrl(mini, C->root());
2533+
Node* mini = longcon(-max_jint);
25502534

25512535
Node* loop_entry = cl->skip_strip_mined()->in(LoopNode::EntryControl);
25522536
assert(loop_entry->is_Proj() && loop_entry->in(0)->is_If(), "if projection only");
@@ -2745,8 +2729,7 @@ void PhaseIdealLoop::do_range_check(IdealLoopTree* loop) {
27452729

27462730
// Kill the eliminated test
27472731
C->set_major_progress();
2748-
Node *kill_con = _igvn.intcon(1-flip);
2749-
set_ctrl(kill_con, C->root());
2732+
Node* kill_con = intcon(1-flip);
27502733
_igvn.replace_input_of(iff, 1, kill_con);
27512734
// Find surviving projection
27522735
assert(iff->is_If(), "");

src/hotspot/share/opto/loopnode.cpp

+44-27
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,7 @@ IdealLoopTree* PhaseIdealLoop::insert_outer_loop(IdealLoopTree* loop, LoopNode*
313313
IdealLoopTree* PhaseIdealLoop::create_outer_strip_mined_loop(BoolNode *test, Node *cmp, Node *init_control,
314314
IdealLoopTree* loop, float cl_prob, float le_fcnt,
315315
Node*& entry_control, Node*& iffalse) {
316-
Node* outer_test = _igvn.intcon(0);
317-
set_ctrl(outer_test, C->root());
316+
Node* outer_test = intcon(0);
318317
Node *orig = iffalse;
319318
iffalse = iffalse->clone();
320319
_igvn.register_new_node_with_optimizer(iffalse);
@@ -969,16 +968,14 @@ bool PhaseIdealLoop::create_loop_nest(IdealLoopTree* loop, Node_List &old_new) {
969968
inner_iters_actual_int = inner_iters_actual;
970969
}
971970

972-
Node* int_zero = _igvn.intcon(0);
973-
set_ctrl(int_zero, C->root());
971+
Node* int_zero = intcon(0);
974972
if (stride_con < 0) {
975973
inner_iters_actual_int = new SubINode(int_zero, inner_iters_actual_int);
976974
_igvn.register_new_node_with_optimizer(inner_iters_actual_int);
977975
}
978976

979977
// Clone the iv data nodes as an integer iv
980-
Node* int_stride = _igvn.intcon(stride_con);
981-
set_ctrl(int_stride, C->root());
978+
Node* int_stride = intcon(stride_con);
982979
Node* inner_phi = new PhiNode(x->in(0), TypeInt::INT);
983980
Node* inner_incr = new AddINode(inner_phi, int_stride);
984981
Node* inner_cmp = nullptr;
@@ -1273,14 +1270,10 @@ int PhaseIdealLoop::extract_long_range_checks(const IdealLoopTree* loop, jint st
12731270
void PhaseIdealLoop::transform_long_range_checks(int stride_con, const Node_List &range_checks, Node* outer_phi,
12741271
Node* inner_iters_actual_int, Node* inner_phi,
12751272
Node* iv_add, LoopNode* inner_head) {
1276-
Node* long_zero = _igvn.longcon(0);
1277-
set_ctrl(long_zero, C->root());
1278-
Node* int_zero = _igvn.intcon(0);
1279-
set_ctrl(int_zero, this->C->root());
1280-
Node* long_one = _igvn.longcon(1);
1281-
set_ctrl(long_one, this->C->root());
1282-
Node* int_stride = _igvn.intcon(checked_cast<int>(stride_con));
1283-
set_ctrl(int_stride, this->C->root());
1273+
Node* long_zero = longcon(0);
1274+
Node* int_zero = intcon(0);
1275+
Node* long_one = longcon(1);
1276+
Node* int_stride = intcon(checked_cast<int>(stride_con));
12841277

12851278
for (uint i = 0; i < range_checks.size(); i++) {
12861279
ProjNode* proj = range_checks.at(i)->as_Proj();
@@ -1302,8 +1295,7 @@ void PhaseIdealLoop::transform_long_range_checks(int stride_con, const Node_List
13021295
Node* entry_control = inner_head->in(LoopNode::EntryControl);
13031296

13041297
Node* R = range;
1305-
Node* K = _igvn.longcon(scale);
1306-
set_ctrl(K, this->C->root());
1298+
Node* K = longcon(scale);
13071299

13081300
Node* L = offset;
13091301

@@ -1334,8 +1326,7 @@ void PhaseIdealLoop::transform_long_range_checks(int stride_con, const Node_List
13341326
// So this transformation could cause spurious deoptimizations and failed range check elimination
13351327
// (but not incorrect execution) for unlikely corner cases with overflow.
13361328
// If this causes problems in practice, we could maybe direct execution to a post-loop, instead of deoptimizing.
1337-
Node* max_jint_plus_one_long = _igvn.longcon((jlong)max_jint + 1);
1338-
set_ctrl(max_jint_plus_one_long, C->root());
1329+
Node* max_jint_plus_one_long = longcon((jlong)max_jint + 1);
13391330
Node* max_range = new AddLNode(max_jint_plus_one_long, L);
13401331
register_new_node(max_range, entry_control);
13411332
R = MaxNode::unsigned_min(R, max_range, TypeLong::POS, _igvn);
@@ -1389,8 +1380,7 @@ void PhaseIdealLoop::transform_long_range_checks(int stride_con, const Node_List
13891380

13901381
// H_clamp = Q_max+1 < Q_min ? max_jlong : Q_max+1
13911382
// (Because Q_min and Q_max are close, the overflow check could also be encoded as Q_max+1 < 0 & Q_min >= 0.)
1392-
Node* max_jlong_long = _igvn.longcon(max_jlong);
1393-
set_ctrl(max_jlong_long, this->C->root());
1383+
Node* max_jlong_long = longcon(max_jlong);
13941384
Node* Q_max_cmp = new CmpLNode(Q_max_plus_one, Q_min);
13951385
register_new_node(Q_max_cmp, entry_control);
13961386
Node* Q_max_bool = new BoolNode(Q_max_cmp, BoolTest::lt);
@@ -1424,8 +1414,7 @@ void PhaseIdealLoop::transform_long_range_checks(int stride_con, const Node_List
14241414
// to: j*K + L_2 <u32 R_2
14251415
// that is:
14261416
// (j*K + Q_first) - L_clamp <u32 clamp(R, L_clamp, H_clamp) - L_clamp
1427-
K = _igvn.intcon(checked_cast<int>(scale));
1428-
set_ctrl(K, this->C->root());
1417+
K = intcon(checked_cast<int>(scale));
14291418
Node* scaled_iv = new MulINode(inner_phi, K);
14301419
register_new_node(scaled_iv, c);
14311420
Node* scaled_iv_plus_offset = new AddINode(scaled_iv, L_2);
@@ -3155,7 +3144,7 @@ void OuterStripMinedLoopNode::transform_to_counted_loop(PhaseIterGVN* igvn, Phas
31553144
// make counted loop exit test always fail
31563145
ConINode* zero = igvn->intcon(0);
31573146
if (iloop != nullptr) {
3158-
iloop->set_ctrl(zero, igvn->C->root());
3147+
iloop->set_root_as_ctrl(zero);
31593148
}
31603149
igvn->replace_input_of(cle, 1, zero);
31613150
// replace outer loop end with CountedLoopEndNode with formers' CLE's exit test
@@ -4067,8 +4056,7 @@ void PhaseIdealLoop::replace_parallel_iv(IdealLoopTree *loop) {
40674056
// variable differs from the trip counter by a loop-invariant
40684057
// amount, the difference between their respective initial values.
40694058
// It is scaled by the 'ratio_con'.
4070-
Node* ratio = _igvn.integercon(ratio_con, stride_con2_bt);
4071-
set_ctrl(ratio, C->root());
4059+
Node* ratio = integercon(ratio_con, stride_con2_bt);
40724060

40734061
Node* init_converted = insert_convert_node_if_needed(stride_con2_bt, init);
40744062
Node* phi_converted = insert_convert_node_if_needed(stride_con2_bt, phi);
@@ -4488,8 +4476,7 @@ void PhaseIdealLoop::eliminate_useless_template_assertion_predicates(Unique_Node
44884476
OpaqueTemplateAssertionPredicateNode* opaque_node =
44894477
C->template_assertion_predicate_opaq_node(i - 1)->as_OpaqueTemplateAssertionPredicate();
44904478
if (!useful_predicates.member(opaque_node)) { // not in the useful list
4491-
ConINode* one = _igvn.intcon(1);
4492-
set_ctrl(one, C->root());
4479+
ConINode* one = intcon(1);
44934480
_igvn.replace_node(opaque_node, one);
44944481
}
44954482
}
@@ -6870,6 +6857,36 @@ void PhaseIdealLoop::rpo(Node* start, Node_Stack &stk, VectorSet &visited, Node_
68706857
}
68716858
}
68726859

6860+
ConINode* PhaseIdealLoop::intcon(jint i) {
6861+
ConINode* node = _igvn.intcon(i);
6862+
set_root_as_ctrl(node);
6863+
return node;
6864+
}
6865+
6866+
ConLNode* PhaseIdealLoop::longcon(jlong i) {
6867+
ConLNode* node = _igvn.longcon(i);
6868+
set_root_as_ctrl(node);
6869+
return node;
6870+
}
6871+
6872+
ConNode* PhaseIdealLoop::makecon(const Type* t) {
6873+
ConNode* node = _igvn.makecon(t);
6874+
set_root_as_ctrl(node);
6875+
return node;
6876+
}
6877+
6878+
ConNode* PhaseIdealLoop::integercon(jlong l, BasicType bt) {
6879+
ConNode* node = _igvn.integercon(l, bt);
6880+
set_root_as_ctrl(node);
6881+
return node;
6882+
}
6883+
6884+
ConNode* PhaseIdealLoop::zerocon(BasicType bt) {
6885+
ConNode* node = _igvn.zerocon(bt);
6886+
set_root_as_ctrl(node);
6887+
return node;
6888+
}
6889+
68736890

68746891
//=============================================================================
68756892
//------------------------------LoopTreeIterator-------------------------------

src/hotspot/share/opto/loopnode.hpp

+14
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,10 @@ class PhaseIdealLoop : public PhaseTransform {
980980
assert( ctrl == find_non_split_ctrl(ctrl), "must set legal crtl" );
981981
_loop_or_ctrl.map(n->_idx, (Node*)((intptr_t)ctrl + 1));
982982
}
983+
void set_root_as_ctrl(Node* n) {
984+
assert(!has_node(n) || has_ctrl(n), "");
985+
_loop_or_ctrl.map(n->_idx, (Node*)((intptr_t)C->root() + 1));
986+
}
983987
// Set control and update loop membership
984988
void set_ctrl_and_loop(Node* n, Node* ctrl) {
985989
IdealLoopTree* old_loop = get_loop(get_ctrl(n));
@@ -1784,6 +1788,16 @@ class PhaseIdealLoop : public PhaseTransform {
17841788
void pin_array_access_nodes_dependent_on(Node* ctrl);
17851789

17861790
Node* ensure_node_and_inputs_are_above_pre_end(CountedLoopEndNode* pre_end, Node* node);
1791+
1792+
ConINode* intcon(jint i);
1793+
1794+
ConLNode* longcon(jlong i);
1795+
1796+
ConNode* makecon(const Type* t);
1797+
1798+
ConNode* integercon(jlong l, BasicType bt);
1799+
1800+
ConNode* zerocon(BasicType bt);
17871801
};
17881802

17891803

0 commit comments

Comments
 (0)