Skip to content

Commit 483d4b9

Browse files
author
Nils Eliasson
committedFeb 14, 2022
8281505: Add CompileCommand PrintIdealPhase
Reviewed-by: kvn, thartmann, chagedorn
1 parent adbe066 commit 483d4b9

10 files changed

+377
-102
lines changed
 

‎src/hotspot/share/compiler/compileBroker.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -614,9 +614,8 @@ void register_jfr_phasetype_serializer(CompilerType compiler_type) {
614614
#ifdef COMPILER2
615615
} else if (compiler_type == compiler_c2) {
616616
assert(first_registration, "invariant"); // c2 must be registered first.
617-
GrowableArray<const char*>* c2_phase_names = new GrowableArray<const char*>(PHASE_NUM_TYPES);
618617
for (int i = 0; i < PHASE_NUM_TYPES; i++) {
619-
const char* phase_name = CompilerPhaseTypeHelper::to_string((CompilerPhaseType) i);
618+
const char* phase_name = CompilerPhaseTypeHelper::to_description((CompilerPhaseType) i);
620619
CompilerEvent::PhaseEvent::get_phase_id(phase_name, false, false, false);
621620
}
622621
first_registration = false;

‎src/hotspot/share/compiler/compilerDirectives.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "compiler/compilerOracle.hpp"
3131
#include "memory/allocation.inline.hpp"
3232
#include "memory/resourceArea.hpp"
33+
#include "opto/phasetype.hpp"
3334
#include "runtime/globals_extension.hpp"
3435

3536
CompilerDirectives::CompilerDirectives() : _next(NULL), _match(NULL), _ref_count(0) {
@@ -262,6 +263,7 @@ void DirectiveSet::init_control_intrinsic() {
262263

263264
DirectiveSet::DirectiveSet(CompilerDirectives* d) :_inlinematchers(NULL), _directive(d) {
264265
#define init_defaults_definition(name, type, dvalue, compiler) this->name##Option = dvalue;
266+
_ideal_phase_name_mask = 0;
265267
compilerdirectives_common_flags(init_defaults_definition)
266268
compilerdirectives_c2_flags(init_defaults_definition)
267269
compilerdirectives_c1_flags(init_defaults_definition)
@@ -381,6 +383,24 @@ DirectiveSet* DirectiveSet::compilecommand_compatibility_init(const methodHandle
381383
compilerdirectives_c2_flags(init_default_cc)
382384
compilerdirectives_c1_flags(init_default_cc)
383385

386+
// Parse PrintIdealPhaseName and create an efficient lookup mask
387+
#ifndef PRODUCT
388+
#ifdef COMPILER2
389+
if (!_modified[PrintIdealPhaseIndex]) {
390+
// Parse ccstr and create mask
391+
ccstrlist option;
392+
if (CompilerOracle::has_option_value(method, CompileCommand::PrintIdealPhase, option)) {
393+
uint64_t mask = 0;
394+
PhaseNameValidator validator(option, mask);
395+
if (validator.is_valid()) {
396+
assert(mask != 0, "Must be set");
397+
set.cloned()->_ideal_phase_name_mask = mask;
398+
}
399+
}
400+
}
401+
#endif
402+
#endif
403+
384404
// Canonicalize DisableIntrinsic to contain only ',' as a separator.
385405
ccstrlist option_value;
386406
bool need_reset = true; // if Control/DisableIntrinsic redefined, only need to reset control_words once

‎src/hotspot/share/compiler/compilerDirectives.hpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
NOT_PRODUCT(cflags(TraceOptoPipelining, bool, TraceOptoPipelining, TraceOptoPipelining)) \
6868
NOT_PRODUCT(cflags(TraceOptoOutput, bool, TraceOptoOutput, TraceOptoOutput)) \
6969
NOT_PRODUCT(cflags(PrintIdeal, bool, PrintIdeal, PrintIdeal)) \
70+
NOT_PRODUCT(cflags(PrintIdealPhase, ccstrlist, "", PrintIdealPhase)) \
7071
NOT_PRODUCT(cflags(PrintIdealLevel, uintx, PrintIdealLevel, PrintIdealLevel)) \
7172
cflags(TraceSpilling, bool, TraceSpilling, TraceSpilling) \
7273
cflags(Vectorize, bool, false, Vectorize) \
@@ -108,6 +109,7 @@ class DirectiveSet : public CHeapObj<mtCompiler> {
108109
InlineMatcher* _inlinematchers;
109110
CompilerDirectives* _directive;
110111
TriBoolArray<(size_t)vmIntrinsics::number_of_intrinsics(), int> _intrinsic_control_words;
112+
uint64_t _ideal_phase_name_mask;
111113

112114
public:
113115
DirectiveSet(CompilerDirectives* directive);
@@ -137,7 +139,6 @@ class DirectiveSet : public CHeapObj<mtCompiler> {
137139

138140
private:
139141
bool _modified[number_of_flags]; // Records what options where set by a directive
140-
141142
public:
142143
#define flag_store_definition(name, type, dvalue, cc_flag) type name##Option;
143144
compilerdirectives_common_flags(flag_store_definition)
@@ -150,6 +151,9 @@ class DirectiveSet : public CHeapObj<mtCompiler> {
150151
compilerdirectives_c2_flags(set_function_definition)
151152
compilerdirectives_c1_flags(set_function_definition)
152153

154+
void set_ideal_phase_mask(uint64_t mask) { _ideal_phase_name_mask = mask; };
155+
uint64_t ideal_phase_mask() { return _ideal_phase_name_mask; };
156+
153157
void print_intx(outputStream* st, ccstr n, intx v, bool mod) { if (mod) { st->print("%s:" INTX_FORMAT " ", n, v); } }
154158
void print_uintx(outputStream* st, ccstr n, intx v, bool mod) { if (mod) { st->print("%s:" UINTX_FORMAT " ", n, v); } }
155159
void print_bool(outputStream* st, ccstr n, bool v, bool mod) { if (mod) { st->print("%s:%s ", n, v ? "true" : "false"); } }

‎src/hotspot/share/compiler/compilerOracle.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "oops/klass.hpp"
3535
#include "oops/method.inline.hpp"
3636
#include "oops/symbol.hpp"
37+
#include "opto/phasetype.hpp"
3738
#include "runtime/globals_extension.hpp"
3839
#include "runtime/handles.inline.hpp"
3940
#include "runtime/jniHandles.hpp"
@@ -683,6 +684,21 @@ static void scan_value(enum OptionType type, char* line, int& total_bytes_read,
683684
jio_snprintf(errorbuf, buf_size, "Unrecognized intrinsic detected in %s: %s", option2name(option), validator.what());
684685
}
685686
}
687+
#ifndef PRODUCT
688+
else if (option == CompileCommand::PrintIdealPhase) {
689+
uint64_t mask = 0;
690+
PhaseNameValidator validator(value, mask);
691+
692+
if (!validator.is_valid()) {
693+
jio_snprintf(errorbuf, buf_size, "Unrecognized phase name in %s: %s", option2name(option), validator.what());
694+
}
695+
} else if (option == CompileCommand::TestOptionList) {
696+
// all values are ok
697+
}
698+
#endif
699+
else {
700+
assert(false, "Ccstrlist type option missing validator");
701+
}
686702

687703
register_command(matcher, option, (ccstr) value);
688704
return;

‎src/hotspot/share/compiler/compilerOracle.hpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ class methodHandle;
7979
option(TraceOptoPipelining, "TraceOptoPipelining", Bool) \
8080
option(TraceOptoOutput, "TraceOptoOutput", Bool) \
8181
option(TraceSpilling, "TraceSpilling", Bool) \
82-
option(PrintIdeal, "PrintIdeal", Bool) \
83-
option(PrintIdealLevel, "PrintIdealLevel", Uintx) \
84-
option(IGVPrintLevel, "IGVPrintLevel", Intx) \
82+
NOT_PRODUCT(option(PrintIdeal, "PrintIdeal", Bool)) \
83+
NOT_PRODUCT(option(PrintIdealLevel, "PrintIdealLevel", Uintx)) \
84+
NOT_PRODUCT(option(PrintIdealPhase, "PrintIdealPhase", Ccstrlist)) \
85+
NOT_PRODUCT(option(IGVPrintLevel, "IGVPrintLevel", Intx)) \
8586
option(Vectorize, "Vectorize", Bool) \
8687
option(VectorizeDebug, "VectorizeDebug", Uintx) \
8788
option(CloneMapDebug, "CloneMapDebug", Bool) \

‎src/hotspot/share/compiler/directivesParser.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "compiler/directivesParser.hpp"
2828
#include "memory/allocation.inline.hpp"
2929
#include "memory/resourceArea.hpp"
30+
#include "opto/phasetype.hpp"
3031
#include "runtime/os.hpp"
3132
#include <string.h>
3233

@@ -334,6 +335,15 @@ bool DirectivesParser::set_option_flag(JSON_TYPE t, JSON_VAL* v, const key* opti
334335
error(VALUE_ERROR, "Unrecognized intrinsic detected in DisableIntrinsic: %s", validator.what());
335336
return false;
336337
}
338+
} else if (strncmp(option_key->name, "PrintIdealPhase", 15) == 0) {
339+
uint64_t mask = 0;
340+
PhaseNameValidator validator(s, mask);
341+
342+
if (!validator.is_valid()) {
343+
error(VALUE_ERROR, "Unrecognized phase name detected in PrintIdealPhase: %s", validator.what());
344+
return false;
345+
}
346+
set->set_ideal_phase_mask(mask);
337347
}
338348
}
339349
break;

‎src/hotspot/share/opto/compile.cpp

+12-3
Original file line numberDiff line numberDiff line change
@@ -4833,7 +4833,7 @@ void Compile::print_method(CompilerPhaseType cpt, int level, Node* n) {
48334833
#ifndef PRODUCT
48344834
ResourceMark rm;
48354835
stringStream ss;
4836-
ss.print_raw(CompilerPhaseTypeHelper::to_string(cpt));
4836+
ss.print_raw(CompilerPhaseTypeHelper::to_name(cpt));
48374837
if (n != nullptr) {
48384838
ss.print(": %d %s ", n->_idx, NodeClassNames[n->Opcode()]);
48394839
}
@@ -4842,8 +4842,8 @@ void Compile::print_method(CompilerPhaseType cpt, int level, Node* n) {
48424842
if (should_print_igv(level)) {
48434843
_igv_printer->print_method(name, level);
48444844
}
4845-
if (should_print_ideal(level)) {
4846-
print_ideal_ir(name);
4845+
if (should_print_ideal(level) || should_print_phase(cpt)) {
4846+
print_ideal_ir(CompilerPhaseTypeHelper::to_name(cpt));
48474847
}
48484848
#endif
48494849
C->_latest_stage_start_counter.stamp();
@@ -4873,6 +4873,15 @@ void Compile::end_method() {
48734873
#endif
48744874
}
48754875

4876+
bool Compile::should_print_phase(CompilerPhaseType cpt) {
4877+
#ifndef PRODUCT
4878+
if ((_directive->ideal_phase_mask() & CompilerPhaseTypeHelper::to_bitmask(cpt)) != 0) {
4879+
return true;
4880+
}
4881+
#endif
4882+
return false;
4883+
}
4884+
48764885
bool Compile::should_print_igv(int level) {
48774886
#ifndef PRODUCT
48784887
if (PrintIdealGraphLevel < 0) { // disabled by the user

‎src/hotspot/share/opto/compile.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ class Compile : public Phase {
654654
void begin_method();
655655
void end_method();
656656
bool should_print_igv(int level);
657+
bool should_print_phase(CompilerPhaseType cpt);
657658

658659
void print_method(CompilerPhaseType cpt, int level, Node* n = nullptr);
659660

0 commit comments

Comments
 (0)