Skip to content

Commit

Permalink
8295166: IGV: dump graph at more locations
Browse files Browse the repository at this point in the history
Reviewed-by: thartmann, rcastanedalo, chagedorn
  • Loading branch information
dlunde authored and robcasloz committed Dec 8, 2023
1 parent 9e48b90 commit 701bc3b
Show file tree
Hide file tree
Showing 15 changed files with 173 additions and 62 deletions.
4 changes: 2 additions & 2 deletions src/hotspot/share/opto/c2_globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,10 @@
"Level of detail of the ideal graph printout. " \
"System-wide value, -1=printing is disabled, " \
"0=print nothing except IGVPrintLevel directives, " \
"5=all details printed. " \
"6=all details printed. " \
"Level of detail of printouts can be set on a per-method level " \
"as well by using CompileCommand=option.") \
range(-1, 5) \
range(-1, 6) \
\
notproduct(intx, PrintIdealGraphPort, 4444, \
"Ideal graph printer to network port") \
Expand Down
14 changes: 14 additions & 0 deletions src/hotspot/share/opto/compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,10 @@ void Compile::Init(bool aliasing) {
Copy::zero_to_bytes(_trap_hist, sizeof(_trap_hist));
set_decompile_count(0);

#ifndef PRODUCT
Copy::zero_to_bytes(_igv_phase_iter, sizeof(_igv_phase_iter));
#endif

set_do_freq_based_layout(_directive->BlockLayoutByFrequencyOption);
_loop_opts_cnt = LoopOptsCount;
set_do_inlining(Inline);
Expand Down Expand Up @@ -2397,6 +2401,7 @@ void Compile::Optimize() {
if (failing()) return;

// Conditional Constant Propagation;
print_method(PHASE_BEFORE_CCP1, 2);
PhaseCCP ccp( &igvn );
assert( true, "Break here to ccp.dump_nodes_and_types(_root,999,1)");
{
Expand Down Expand Up @@ -2972,6 +2977,8 @@ void Compile::Code_Gen() {
if (failing()) {
return;
}

print_method(PHASE_REGISTER_ALLOCATION, 2);
}

// Prior to register allocation we kept empty basic blocks in case the
Expand All @@ -2989,19 +2996,22 @@ void Compile::Code_Gen() {
cfg.fixup_flow();
cfg.remove_unreachable_blocks();
cfg.verify_dominator_tree();
print_method(PHASE_BLOCK_ORDERING, 3);
}

// Apply peephole optimizations
if( OptoPeephole ) {
TracePhase tp("peephole", &timers[_t_peephole]);
PhasePeephole peep( _regalloc, cfg);
peep.do_transform();
print_method(PHASE_PEEPHOLE, 3);
}

// Do late expand if CPU requires this.
if (Matcher::require_postalloc_expand) {
TracePhase tp("postalloc_expand", &timers[_t_postalloc_expand]);
cfg.postalloc_expand(_regalloc);
print_method(PHASE_POSTALLOC_EXPAND, 3);
}

// Convert Nodes to instruction bits in a buffer
Expand Down Expand Up @@ -5102,6 +5112,10 @@ void Compile::print_method(CompilerPhaseType cpt, int level, Node* n) {
ResourceMark rm;
stringStream ss;
ss.print_raw(CompilerPhaseTypeHelper::to_description(cpt));
int iter = ++_igv_phase_iter[cpt];
if (iter > 1) {
ss.print(" %d", iter);
}
if (n != nullptr) {
ss.print(": %d %s ", n->_idx, NodeClassNames[n->Opcode()]);
}
Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/share/opto/compile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ class Compile : public Phase {
bool _print_intrinsics; // True if we should print intrinsics for this compilation
#ifndef PRODUCT
uint _igv_idx; // Counter for IGV node identifiers
uint _igv_phase_iter[PHASE_NUM_TYPES]; // Counters for IGV phase iterations
bool _trace_opto_output;
bool _parsed_irreducible_loop; // True if ciTypeFlow detected irreducible loops during parsing
#endif
Expand Down Expand Up @@ -531,6 +532,7 @@ class Compile : public Phase {

#ifndef PRODUCT
IdealGraphPrinter* igv_printer() { return _igv_printer; }
void reset_igv_phase_iter(CompilerPhaseType cpt) { _igv_phase_iter[cpt] = 0; }
#endif

void log_late_inline(CallGenerator* cg);
Expand Down
7 changes: 7 additions & 0 deletions src/hotspot/share/opto/loopPredicate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,7 @@ bool PhaseIdealLoop::loop_predication_impl_helper(IdealLoopTree* loop, IfProjNod
}
BoolNode* bol = test->as_Bool();
if (invar.is_invariant(bol)) {
C->print_method(PHASE_BEFORE_LOOP_PREDICATION_IC, 4, iff);
// Invariant test
new_predicate_proj = create_new_if_for_predicate(parse_predicate_proj, nullptr,
reason,
Expand All @@ -1197,6 +1198,9 @@ bool PhaseIdealLoop::loop_predication_impl_helper(IdealLoopTree* loop, IfProjNod
IfNode* new_predicate_iff = new_predicate_proj->in(0)->as_If();
_igvn.hash_delete(new_predicate_iff);
new_predicate_iff->set_req(1, new_predicate_bol);

C->print_method(PHASE_AFTER_LOOP_PREDICATION_IC, 4, new_predicate_proj->in(0));

#ifndef PRODUCT
if (TraceLoopPredicate) {
tty->print("Predicate invariant if%s: %d ", negated ? " negated" : "", new_predicate_iff->_idx);
Expand All @@ -1207,6 +1211,7 @@ bool PhaseIdealLoop::loop_predication_impl_helper(IdealLoopTree* loop, IfProjNod
}
#endif
} else if (cl != nullptr && loop->is_range_check_if(if_success_proj, this, invar DEBUG_ONLY(COMMA parse_predicate_proj))) {
C->print_method(PHASE_BEFORE_LOOP_PREDICATION_RC, 4, iff);
// Range check for counted loops
assert(if_success_proj->is_IfTrue(), "trap must be on false projection for a range check");
const Node* cmp = bol->in(1)->as_Cmp();
Expand Down Expand Up @@ -1270,6 +1275,8 @@ bool PhaseIdealLoop::loop_predication_impl_helper(IdealLoopTree* loop, IfProjNod
new_predicate_proj = add_template_assertion_predicate(iff, loop, if_success_proj, parse_predicate_proj, upper_bound_proj, scale,
offset, init, limit, stride, rng, overflow, reason);

C->print_method(PHASE_AFTER_LOOP_PREDICATION_RC, 4, new_predicate_proj->in(0));

#ifndef PRODUCT
if (TraceLoopOpts && !TraceLoopPredicate) {
tty->print("Predicate RC ");
Expand Down
19 changes: 19 additions & 0 deletions src/hotspot/share/opto/loopTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,9 @@ void PhaseIdealLoop::do_peeling(IdealLoopTree *loop, Node_List &old_new) {
}
#endif
LoopNode* head = loop->_head->as_Loop();

C->print_method(PHASE_BEFORE_LOOP_PEELING, 4, head);

bool counted_loop = head->is_CountedLoop();
if (counted_loop) {
CountedLoopNode *cl = head->as_CountedLoop();
Expand Down Expand Up @@ -795,6 +798,8 @@ void PhaseIdealLoop::do_peeling(IdealLoopTree *loop, Node_List &old_new) {
peeled_dom_test_elim(loop,old_new);

loop->record_for_igvn();

C->print_method(PHASE_AFTER_LOOP_PEELING, 4, new_head);
}

//------------------------------policy_maximally_unroll------------------------
Expand Down Expand Up @@ -1629,6 +1634,8 @@ void PhaseIdealLoop::insert_pre_post_loops(IdealLoopTree *loop, Node_List &old_n
CountedLoopEndNode *main_end = main_head->loopexit();
assert(main_end->outcnt() == 2, "1 true, 1 false path only");

C->print_method(PHASE_BEFORE_PRE_MAIN_POST, 4, main_head);

Node *pre_header= main_head->in(LoopNode::EntryControl);
Node *init = main_head->init_trip();
Node *incr = main_end ->incr();
Expand Down Expand Up @@ -1825,6 +1832,8 @@ void PhaseIdealLoop::insert_pre_post_loops(IdealLoopTree *loop, Node_List &old_n
// finds some, but we _know_ they are all useless.
peeled_dom_test_elim(loop,old_new);
loop->record_for_igvn();

C->print_method(PHASE_AFTER_PRE_MAIN_POST, 4, main_head);
}

//------------------------------insert_vector_post_loop------------------------
Expand Down Expand Up @@ -2127,6 +2136,9 @@ void PhaseIdealLoop::do_unroll(IdealLoopTree *loop, Node_List &old_new, bool adj
assert(LoopUnrollLimit, "");
CountedLoopNode *loop_head = loop->_head->as_CountedLoop();
CountedLoopEndNode *loop_end = loop_head->loopexit();

C->print_method(PHASE_BEFORE_LOOP_UNROLLING, 4, loop_head);

#ifndef PRODUCT
if (PrintOpto && VerifyLoopOptimizations) {
tty->print("Unrolling ");
Expand Down Expand Up @@ -2374,6 +2386,8 @@ void PhaseIdealLoop::do_unroll(IdealLoopTree *loop, Node_List &old_new, bool adj
}
}
#endif

C->print_method(PHASE_AFTER_LOOP_UNROLLING, 4, clone_head);
}

//------------------------------do_maximally_unroll----------------------------
Expand Down Expand Up @@ -3003,6 +3017,8 @@ void PhaseIdealLoop::do_range_check(IdealLoopTree *loop, Node_List &old_new) {
// stride_con and scale_con can be negative which will flip about the
// sense of the test.

C->print_method(PHASE_BEFORE_RANGE_CHECK_ELIMINATION, 4, iff);

// Perform the limit computations in jlong to avoid overflow
jlong lscale_con = scale_con;
Node* int_offset = offset;
Expand Down Expand Up @@ -3103,6 +3119,9 @@ void PhaseIdealLoop::do_range_check(IdealLoopTree *loop, Node_List &old_new) {
--imax;
}
}

C->print_method(PHASE_AFTER_RANGE_CHECK_ELIMINATION, 4, cl);

} // End of is IF
}
if (loop_entry != cl->skip_strip_mined()->in(LoopNode::EntryControl)) {
Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/share/opto/loopUnswitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ void PhaseIdealLoop::do_unswitching(IdealLoopTree *loop, Node_List &old_new) {
}
#endif

C->print_method(PHASE_BEFORE_LOOP_UNSWITCHING, 4, head);

// Need to revert back to normal loop
if (head->is_CountedLoop() && !head->as_CountedLoop()->is_normal_loop()) {
head->as_CountedLoop()->set_normal_loop();
Expand Down Expand Up @@ -200,6 +202,8 @@ void PhaseIdealLoop::do_unswitching(IdealLoopTree *loop, Node_List &old_new) {
}
#endif

C->print_method(PHASE_AFTER_LOOP_UNSWITCHING, 4, head_clone);

C->set_major_progress();
}

Expand Down
11 changes: 11 additions & 0 deletions src/hotspot/share/opto/loopopts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,12 @@ void PhaseIdealLoop::split_if_with_blocks_post(Node *n) {
}

// Now split the IF
C->print_method(PHASE_BEFORE_SPLIT_IF, 4, iff);
if ((PrintOpto && VerifyLoopOptimizations) || TraceLoopOpts) {
tty->print_cr("Split-If");
}
do_split_if(iff);
C->print_method(PHASE_AFTER_SPLIT_IF, 4, iff);
return;
}

Expand Down Expand Up @@ -3625,6 +3630,9 @@ bool PhaseIdealLoop::partial_peel( IdealLoopTree *loop, Node_List &old_new ) {
}
}
#endif

C->print_method(PHASE_BEFORE_PARTIAL_PEELING, 4, head);

VectorSet peel;
VectorSet not_peel;
Node_List peel_list;
Expand Down Expand Up @@ -3919,6 +3927,9 @@ bool PhaseIdealLoop::partial_peel( IdealLoopTree *loop, Node_List &old_new ) {
}
}
#endif

C->print_method(PHASE_AFTER_PARTIAL_PEELING, 4, new_head_clone);

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/opto/parse2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2779,7 +2779,7 @@ void Parse::do_one_bytecode() {
}

#ifndef PRODUCT
constexpr int perBytecode = 5;
constexpr int perBytecode = 6;
if (C->should_print_igv(perBytecode)) {
IdealGraphPrinter* printer = C->igv_printer();
char buffer[256];
Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/share/opto/phaseX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ void PhaseIterGVN::verify_step(Node* n) {
void PhaseIterGVN::trace_PhaseIterGVN(Node* n, Node* nn, const Type* oldtype) {
const Type* newtype = type_or_null(n);
if (nn != n || oldtype != newtype) {
C->print_method(PHASE_AFTER_ITER_GVN_STEP, 4, n);
C->print_method(PHASE_AFTER_ITER_GVN_STEP, 5, n);
}
if (TraceIterativeGVN) {
uint wlsize = _worklist.size();
Expand Down Expand Up @@ -1025,6 +1025,7 @@ void PhaseIterGVN::trace_PhaseIterGVN_verbose(Node* n, int num_processed) {
void PhaseIterGVN::optimize() {
DEBUG_ONLY(uint num_processed = 0;)
NOT_PRODUCT(init_verifyPhaseIterGVN();)
NOT_PRODUCT(C->reset_igv_phase_iter(PHASE_AFTER_ITER_GVN_STEP);)
C->print_method(PHASE_BEFORE_ITER_GVN, 3);
if (StressIGVN) {
shuffle_worklist();
Expand Down
Loading

0 comments on commit 701bc3b

Please sign in to comment.