Skip to content

Commit

Permalink
8319813: Remove upper limit on number of compiler phases in phasetype…
Browse files Browse the repository at this point in the history
….hpp

Reviewed-by: chagedorn, rcastanedalo, epeter
  • Loading branch information
dlunde authored and eme64 committed Nov 23, 2023
1 parent c49fb4f commit 8db7bad
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 25 deletions.
20 changes: 11 additions & 9 deletions src/hotspot/share/compiler/compilerDirectives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,11 @@ void DirectiveSet::init_control_intrinsic() {
}
}

DirectiveSet::DirectiveSet(CompilerDirectives* d) :_inlinematchers(nullptr), _directive(d) {
_ideal_phase_name_mask = 0;
DirectiveSet::DirectiveSet(CompilerDirectives* d) :
_inlinematchers(nullptr),
_directive(d),
_ideal_phase_name_set(PHASE_NUM_TYPES, mtCompiler)
{
#define init_defaults_definition(name, type, dvalue, compiler) this->name##Option = dvalue;
compilerdirectives_common_flags(init_defaults_definition)
compilerdirectives_c2_flags(init_defaults_definition)
Expand Down Expand Up @@ -427,18 +430,17 @@ DirectiveSet* DirectiveSet::compilecommand_compatibility_init(const methodHandle
compilerdirectives_c1_flags(init_default_cc)
#undef init_default_cc

// Parse PrintIdealPhaseName and create an efficient lookup mask
// Parse PrintIdealPhaseName and create a lookup set
#ifndef PRODUCT
#ifdef COMPILER2
if (!_modified[PrintIdealPhaseIndex]) {
// Parse ccstr and create mask
// Parse ccstr and create set
ccstrlist option;
if (CompilerOracle::has_option_value(method, CompileCommand::PrintIdealPhase, option)) {
uint64_t mask = 0;
PhaseNameValidator validator(option, mask);
PhaseNameValidator validator(option);
if (validator.is_valid()) {
assert(mask != 0, "Must be set");
set.cloned()->_ideal_phase_name_mask = mask;
assert(!validator.phase_name_set().is_empty(), "Phase name set must be non-empty");
set.cloned()->set_ideal_phase_name_set(validator.phase_name_set());
}
}
}
Expand Down Expand Up @@ -621,7 +623,7 @@ DirectiveSet* DirectiveSet::clone(DirectiveSet const* src) {
#undef copy_string_members_definition

set->_intrinsic_control_words = src->_intrinsic_control_words;
set->_ideal_phase_name_mask = src->_ideal_phase_name_mask;
set->set_ideal_phase_name_set(src->_ideal_phase_name_set);
return set;
}

Expand Down
12 changes: 9 additions & 3 deletions src/hotspot/share/compiler/compilerDirectives.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include "compiler/compiler_globals.hpp"
#include "compiler/methodMatcher.hpp"
#include "compiler/compilerOracle.hpp"
#include "opto/phasetype.hpp"
#include "utilities/bitMap.hpp"
#include "utilities/exceptions.hpp"
#include "utilities/tribool.hpp"

Expand Down Expand Up @@ -128,7 +130,7 @@ class DirectiveSet : public CHeapObj<mtCompiler> {
InlineMatcher* _inlinematchers;
CompilerDirectives* _directive;
TriBoolArray<(size_t)vmIntrinsics::number_of_intrinsics(), int> _intrinsic_control_words;
uint64_t _ideal_phase_name_mask;
CHeapBitMap _ideal_phase_name_set;

public:
DirectiveSet(CompilerDirectives* directive);
Expand Down Expand Up @@ -197,8 +199,12 @@ void set_##name(void* value) { \
compilerdirectives_c1_string_flags(set_string_function_definition)
#undef set_string_function_definition

void set_ideal_phase_mask(uint64_t mask) { _ideal_phase_name_mask = mask; };
uint64_t ideal_phase_mask() { return _ideal_phase_name_mask; };
void set_ideal_phase_name_set(const BitMap& set) {
_ideal_phase_name_set.set_from(set);
};
bool should_print_phase(const CompilerPhaseType cpt) const {
return _ideal_phase_name_set.at(cpt);
};

void print_intx(outputStream* st, ccstr n, intx v, bool mod) { if (mod) { st->print("%s:" INTX_FORMAT " ", n, v); } }
void print_uintx(outputStream* st, ccstr n, intx v, bool mod) { if (mod) { st->print("%s:" UINTX_FORMAT " ", n, v); } }
Expand Down
3 changes: 1 addition & 2 deletions src/hotspot/share/compiler/compilerOracle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,8 +777,7 @@ static void scan_value(enum OptionType type, char* line, int& total_bytes_read,
}
#ifndef PRODUCT
else if (option == CompileCommand::PrintIdealPhase) {
uint64_t mask = 0;
PhaseNameValidator validator(value, mask);
PhaseNameValidator validator(value);

if (!validator.is_valid()) {
jio_snprintf(errorbuf, buf_size, "Unrecognized phase name in %s: %s", option2name(option), validator.what());
Expand Down
5 changes: 2 additions & 3 deletions src/hotspot/share/compiler/directivesParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,11 @@ bool DirectivesParser::set_option_flag(JSON_TYPE t, JSON_VAL* v, const key* opti
error(VALUE_ERROR, "Unrecognized intrinsic detected in DisableIntrinsic: %s", validator.what());
}
} else if (strncmp(option_key->name, "PrintIdealPhase", 15) == 0) {
uint64_t mask = 0;
PhaseNameValidator validator(s, mask);
PhaseNameValidator validator(s);

valid = validator.is_valid();
if (valid) {
set->set_ideal_phase_mask(mask);
set->set_ideal_phase_name_set(validator.phase_name_set());
} else {
error(VALUE_ERROR, "Unrecognized phase name detected in PrintIdealPhase: %s", validator.what());
}
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/opto/compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5143,7 +5143,7 @@ void Compile::end_method() {

bool Compile::should_print_phase(CompilerPhaseType cpt) {
#ifndef PRODUCT
if ((_directive->ideal_phase_mask() & CompilerPhaseTypeHelper::to_bitmask(cpt)) != 0) {
if (_directive->should_print_phase(cpt)) {
return true;
}
#endif
Expand Down
23 changes: 16 additions & 7 deletions src/hotspot/share/opto/phasetype.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#ifndef SHARE_OPTO_PHASETYPE_HPP
#define SHARE_OPTO_PHASETYPE_HPP

#include "utilities/bitMap.inline.hpp"

#define COMPILER_PHASES(flags) \
flags(BEFORE_STRINGOPTS, "Before StringOpts") \
flags(AFTER_STRINGOPTS, "After StringOpts") \
Expand Down Expand Up @@ -100,9 +102,6 @@ class CompilerPhaseTypeHelper {
static const char* to_description(CompilerPhaseType cpt) {
return phase_descriptions[cpt];
}
static uint64_t to_bitmask(CompilerPhaseType cpt) {
return (UINT64_C(1) << cpt);
}
};

static CompilerPhaseType find_phase(const char* str) {
Expand Down Expand Up @@ -157,11 +156,16 @@ class PhaseNameIter {

class PhaseNameValidator {
private:
CHeapBitMap _phase_name_set;
bool _valid;
char* _bad;

public:
PhaseNameValidator(ccstrlist option, uint64_t& mask) : _valid(true), _bad(nullptr) {
PhaseNameValidator(ccstrlist option) :
_phase_name_set(PHASE_NUM_TYPES, mtCompiler),
_valid(true),
_bad(nullptr)
{
for (PhaseNameIter iter(option); *iter != nullptr && _valid; ++iter) {

CompilerPhaseType cpt = find_phase(*iter);
Expand All @@ -172,10 +176,10 @@ class PhaseNameValidator {
strncpy(_bad, *iter, len);
_valid = false;
} else if (PHASE_ALL == cpt) {
mask = ~(UINT64_C(0));
_phase_name_set.set_range(0, PHASE_NUM_TYPES);
} else {
assert(cpt < 64, "out of bounds");
mask |= CompilerPhaseTypeHelper::to_bitmask(cpt);
assert(cpt < PHASE_NUM_TYPES, "out of bounds");
_phase_name_set.set_bit(cpt);
}
}
}
Expand All @@ -186,6 +190,11 @@ class PhaseNameValidator {
}
}

const BitMap& phase_name_set() const {
assert(is_valid(), "Use of invalid phase name set");
return _phase_name_set;
}

bool is_valid() const {
return _valid;
}
Expand Down

0 comments on commit 8db7bad

Please sign in to comment.