Modernization; no functional change intended. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r16-2767-gb963237a903f73.
gcc/ChangeLog: * dump-context.h: Convert "enum optinfo_item_kind" into "enum class kind" within class optinfo_item. * dumpfile.cc: Likewise. Use "auto" in a few places. Convert "enum optinfo_kind" to "enum class kind" within class optinfo. * opt-problem.cc: Likewise. * optinfo-emit-json.cc: Likewise. * optinfo.cc: Likewise. * optinfo.h: Likewise. --- gcc/dump-context.h | 10 +++---- gcc/dumpfile.cc | 57 +++++++++++++++++++++------------------- gcc/opt-problem.cc | 2 +- gcc/optinfo-emit-json.cc | 12 ++++----- gcc/optinfo.cc | 40 ++++++++++++++-------------- gcc/optinfo.h | 57 ++++++++++++++++++++-------------------- 6 files changed, 90 insertions(+), 88 deletions(-) diff --git a/gcc/dump-context.h b/gcc/dump-context.h index 9c52f03f0b7e..336cb2385bc8 100644 --- a/gcc/dump-context.h +++ b/gcc/dump-context.h @@ -267,7 +267,7 @@ extern void verify_dumped_text (const location &loc, void verify_item (const location &loc, const optinfo_item *item, - enum optinfo_item_kind expected_kind, + enum optinfo_item::kind expected_kind, location_t expected_location, const char *expected_text); @@ -275,7 +275,7 @@ verify_item (const location &loc, #define ASSERT_IS_TEXT(ITEM, EXPECTED_TEXT) \ SELFTEST_BEGIN_STMT \ - verify_item (SELFTEST_LOCATION, (ITEM), OPTINFO_ITEM_KIND_TEXT, \ + verify_item (SELFTEST_LOCATION, (ITEM), optinfo_item::kind::text, \ UNKNOWN_LOCATION, (EXPECTED_TEXT)); \ SELFTEST_END_STMT @@ -283,7 +283,7 @@ verify_item (const location &loc, #define ASSERT_IS_TREE(ITEM, EXPECTED_LOCATION, EXPECTED_TEXT) \ SELFTEST_BEGIN_STMT \ - verify_item (SELFTEST_LOCATION, (ITEM), OPTINFO_ITEM_KIND_TREE, \ + verify_item (SELFTEST_LOCATION, (ITEM), optinfo_item::kind::tree, \ (EXPECTED_LOCATION), (EXPECTED_TEXT)); \ SELFTEST_END_STMT @@ -291,7 +291,7 @@ verify_item (const location &loc, #define ASSERT_IS_GIMPLE(ITEM, EXPECTED_LOCATION, EXPECTED_TEXT) \ SELFTEST_BEGIN_STMT \ - verify_item (SELFTEST_LOCATION, (ITEM), OPTINFO_ITEM_KIND_GIMPLE, \ + verify_item (SELFTEST_LOCATION, (ITEM), optinfo_item::kind::gimple, \ (EXPECTED_LOCATION), (EXPECTED_TEXT)); \ SELFTEST_END_STMT @@ -299,7 +299,7 @@ verify_item (const location &loc, #define ASSERT_IS_SYMTAB_NODE(ITEM, EXPECTED_LOCATION, EXPECTED_TEXT) \ SELFTEST_BEGIN_STMT \ - verify_item (SELFTEST_LOCATION, (ITEM), OPTINFO_ITEM_KIND_SYMTAB_NODE, \ + verify_item (SELFTEST_LOCATION, (ITEM), optinfo_item::kind::symtab_node, \ (EXPECTED_LOCATION), (EXPECTED_TEXT)); \ SELFTEST_END_STMT diff --git a/gcc/dumpfile.cc b/gcc/dumpfile.cc index ebee8e5121fb..bca8b384c3f9 100644 --- a/gcc/dumpfile.cc +++ b/gcc/dumpfile.cc @@ -636,8 +636,8 @@ make_item_for_dump_gimple_stmt (gimple *stmt, int spc, dump_flags_t dump_flags) pp_gimple_stmt_1 (&pp, stmt, spc, dump_flags); pp_newline (&pp); - std::unique_ptr<optinfo_item> item - = std::make_unique<optinfo_item> (OPTINFO_ITEM_KIND_GIMPLE, + auto item + = std::make_unique<optinfo_item> (optinfo_item::kind::gimple, gimple_location (stmt), xstrdup (pp_formatted_text (&pp))); return item; @@ -684,8 +684,8 @@ make_item_for_dump_gimple_expr (gimple *stmt, int spc, dump_flags_t dump_flags) pp_needs_newline (&pp) = true; pp_gimple_stmt_1 (&pp, stmt, spc, dump_flags); - std::unique_ptr<optinfo_item> item - = std::make_unique<optinfo_item> (OPTINFO_ITEM_KIND_GIMPLE, + auto item + = std::make_unique<optinfo_item> (optinfo_item::kind::gimple, gimple_location (stmt), xstrdup (pp_formatted_text (&pp))); return item; @@ -738,8 +738,8 @@ make_item_for_dump_generic_expr (tree node, dump_flags_t dump_flags) if (EXPR_HAS_LOCATION (node)) loc = EXPR_LOCATION (node); - std::unique_ptr<optinfo_item> item - = std::make_unique<optinfo_item> (OPTINFO_ITEM_KIND_TREE, loc, + auto item + = std::make_unique<optinfo_item> (optinfo_item::kind::tree, loc, xstrdup (pp_formatted_text (&pp))); return item; } @@ -783,8 +783,8 @@ static std::unique_ptr<optinfo_item> make_item_for_dump_symtab_node (symtab_node *node) { location_t loc = DECL_SOURCE_LOCATION (node->decl); - std::unique_ptr<optinfo_item> item - = std::make_unique<optinfo_item> (OPTINFO_ITEM_KIND_SYMTAB_NODE, loc, + auto item + = std::make_unique<optinfo_item> (optinfo_item::kind::symtab_node, loc, xstrdup (node->dump_name ())); return item; } @@ -1011,8 +1011,9 @@ emit_any_pending_textual_chunks () return; char *formatted_text = xstrdup (pp_formatted_text (pp)); - std::unique_ptr<optinfo_item> item - = std::make_unique<optinfo_item> (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION, + auto item + = std::make_unique<optinfo_item> (optinfo_item::kind::text, + UNKNOWN_LOCATION, formatted_text); pp->emit_item (std::move (item), m_optinfo); @@ -1084,7 +1085,8 @@ make_item_for_dump_dec (const poly_int<N, C> &value) } auto item - = std::make_unique<optinfo_item> (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION, + = std::make_unique<optinfo_item> (optinfo_item::kind::text, + UNKNOWN_LOCATION, xstrdup (pp_formatted_text (&pp))); return item; } @@ -1162,8 +1164,9 @@ dump_context::begin_scope (const char *name, pretty_printer pp; pp_printf (&pp, "%s %s %s", "===", name, "==="); pp_newline (&pp); - std::unique_ptr<optinfo_item> item - = std::make_unique<optinfo_item> (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION, + auto item + = std::make_unique<optinfo_item> (optinfo_item::kind::text, + UNKNOWN_LOCATION, xstrdup (pp_formatted_text (&pp))); emit_item (*item.get (), MSG_NOTE); @@ -1172,7 +1175,7 @@ dump_context::begin_scope (const char *name, optinfo &info = begin_next_optinfo (dump_metadata_t (MSG_NOTE, impl_location), user_location); - info.m_kind = OPTINFO_KIND_SCOPE; + info.m_kind = optinfo::kind::scope; info.add_item (std::move (item)); end_any_optinfo (); } @@ -1221,7 +1224,7 @@ dump_context::begin_next_optinfo (const dump_metadata_t &metadata, end_any_optinfo (); gcc_assert (m_pending == NULL); dump_location_t loc (user_loc, metadata.get_impl_location ()); - m_pending = new optinfo (loc, OPTINFO_KIND_NOTE, current_pass); + m_pending = new optinfo (loc, optinfo::kind::note, current_pass); m_pending->handle_dump_file_kind (metadata.get_dump_flags ()); return *m_pending; } @@ -2265,7 +2268,7 @@ verify_dumped_text (const location &loc, void verify_item (const location &loc, const optinfo_item *item, - enum optinfo_item_kind expected_kind, + enum optinfo_item::kind expected_kind, location_t expected_location, const char *expected_text) { @@ -2324,7 +2327,7 @@ test_capture_of_dump_calls (const line_table_case &case_) { optinfo *info = tmp.get_pending_optinfo (); ASSERT_TRUE (info != NULL); - ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE); + ASSERT_EQ (info->get_kind (), optinfo::kind::note); ASSERT_EQ (info->num_items (), 1); ASSERT_IS_TEXT (info->get_item (0), "int: 42 str: foo"); ASSERT_IMPL_LOCATION_EQ (info->get_impl_location (), @@ -2345,7 +2348,7 @@ test_capture_of_dump_calls (const line_table_case &case_) { optinfo *info = tmp.get_pending_optinfo (); ASSERT_TRUE (info != NULL); - ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE); + ASSERT_EQ (info->get_kind (), optinfo::kind::note); ASSERT_EQ (info->num_items (), 2); ASSERT_IS_TEXT (info->get_item (0), "tree: "); ASSERT_IS_TREE (info->get_item (1), UNKNOWN_LOCATION, "0"); @@ -2367,7 +2370,7 @@ test_capture_of_dump_calls (const line_table_case &case_) { optinfo *info = tmp.get_pending_optinfo (); ASSERT_TRUE (info != NULL); - ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE); + ASSERT_EQ (info->get_kind (), optinfo::kind::note); ASSERT_EQ (info->num_items (), 2); ASSERT_IS_TEXT (info->get_item (0), "gimple: "); ASSERT_IS_GIMPLE (info->get_item (1), stmt_loc, "return;"); @@ -2389,7 +2392,7 @@ test_capture_of_dump_calls (const line_table_case &case_) { optinfo *info = tmp.get_pending_optinfo (); ASSERT_TRUE (info != NULL); - ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE); + ASSERT_EQ (info->get_kind (), optinfo::kind::note); ASSERT_EQ (info->num_items (), 2); ASSERT_IS_TEXT (info->get_item (0), "gimple: "); ASSERT_IS_GIMPLE (info->get_item (1), stmt_loc, "return;\n"); @@ -2411,7 +2414,7 @@ test_capture_of_dump_calls (const line_table_case &case_) { optinfo *info = tmp.get_pending_optinfo (); ASSERT_TRUE (info != NULL); - ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE); + ASSERT_EQ (info->get_kind (), optinfo::kind::note); ASSERT_EQ (info->num_items (), 2); ASSERT_IS_TEXT (info->get_item (0), "node: "); ASSERT_IS_SYMTAB_NODE (info->get_item (1), decl_loc, "test_decl/1"); @@ -2441,7 +2444,7 @@ test_capture_of_dump_calls (const line_table_case &case_) { optinfo *info = tmp.get_pending_optinfo (); ASSERT_TRUE (info != NULL); - ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE); + ASSERT_EQ (info->get_kind (), optinfo::kind::note); ASSERT_EQ (info->num_items (), 8); ASSERT_IS_TEXT (info->get_item (0), "before "); ASSERT_IS_TREE (info->get_item (1), UNKNOWN_LOCATION, "0"); @@ -2471,7 +2474,7 @@ test_capture_of_dump_calls (const line_table_case &case_) optinfo *info = tmp.get_pending_optinfo (); ASSERT_TRUE (info != NULL); ASSERT_EQ (info->get_location_t (), stmt_loc); - ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE); + ASSERT_EQ (info->get_kind (), optinfo::kind::note); ASSERT_EQ (info->num_items (), 2); ASSERT_IS_TEXT (info->get_item (0), "test of tree: "); ASSERT_IS_TREE (info->get_item (1), UNKNOWN_LOCATION, "0"); @@ -2494,7 +2497,7 @@ test_capture_of_dump_calls (const line_table_case &case_) optinfo *info = tmp.get_pending_optinfo (); ASSERT_TRUE (info != NULL); ASSERT_EQ (info->get_location_t (), stmt_loc); - ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE); + ASSERT_EQ (info->get_kind (), optinfo::kind::note); ASSERT_EQ (info->num_items (), 1); ASSERT_IS_TREE (info->get_item (0), UNKNOWN_LOCATION, "1"); ASSERT_IMPL_LOCATION_EQ (info->get_impl_location (), @@ -2598,7 +2601,7 @@ test_capture_of_dump_calls (const line_table_case &case_) { optinfo *info = tmp.get_pending_optinfo (); ASSERT_TRUE (info != NULL); - ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE); + ASSERT_EQ (info->get_kind (), optinfo::kind::note); ASSERT_EQ (info->num_items (), 1); ASSERT_IS_SYMTAB_NODE (info->get_item (0), decl_loc, "test_decl/1"); ASSERT_IMPL_LOCATION_EQ (info->get_impl_location (), @@ -2727,7 +2730,7 @@ test_capture_of_dump_calls (const line_table_case &case_) temp_dump_context tmp (true, true, MSG_ALL_KINDS); dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc, "test"); ASSERT_EQ (tmp.get_pending_optinfo ()->get_kind (), - OPTINFO_KIND_SUCCESS); + optinfo::kind::success); } /* MSG_MISSED_OPTIMIZATION. */ @@ -2735,7 +2738,7 @@ test_capture_of_dump_calls (const line_table_case &case_) temp_dump_context tmp (true, true, MSG_ALL_KINDS); dump_printf_loc (MSG_MISSED_OPTIMIZATION, loc, "test"); ASSERT_EQ (tmp.get_pending_optinfo ()->get_kind (), - OPTINFO_KIND_FAILURE); + optinfo::kind::failure); } } diff --git a/gcc/opt-problem.cc b/gcc/opt-problem.cc index 8324feb151af..e0c7601b2a25 100644 --- a/gcc/opt-problem.cc +++ b/gcc/opt-problem.cc @@ -42,7 +42,7 @@ along with GCC; see the file COPYING3. If not see opt_problem::opt_problem (const dump_location_t &loc, const char *fmt, va_list *ap) -: m_optinfo (loc, OPTINFO_KIND_FAILURE, current_pass) +: m_optinfo (loc, optinfo::kind::failure, current_pass) { /* We shouldn't be bothering to construct these objects if dumping isn't enabled. */ diff --git a/gcc/optinfo-emit-json.cc b/gcc/optinfo-emit-json.cc index 28c8a98db302..ae686a9e9db6 100644 --- a/gcc/optinfo-emit-json.cc +++ b/gcc/optinfo-emit-json.cc @@ -143,7 +143,7 @@ optrecord_json_writer::add_record (const optinfo *optinfo) add_record (obj); /* Potentially push the scope. */ - if (optinfo->get_kind () == OPTINFO_KIND_SCOPE) + if (optinfo->get_kind () == optinfo::kind::scope) { json::array *children = new json::array (); obj->set ("children", children); @@ -334,7 +334,7 @@ optrecord_json_writer::optinfo_to_json (const optinfo *optinfo) obj->set ("impl_location", impl_location_to_json (optinfo->get_impl_location ())); - const char *kind_str = optinfo_kind_to_string (optinfo->get_kind ()); + const char *kind_str = optinfo::kind_to_string (optinfo->get_kind ()); obj->set_string ("kind", kind_str); json::array *message = new json::array (); obj->set ("message", message); @@ -345,12 +345,12 @@ optrecord_json_writer::optinfo_to_json (const optinfo *optinfo) { default: gcc_unreachable (); - case OPTINFO_ITEM_KIND_TEXT: + case optinfo_item::kind::text: { message->append_string (item->get_text ()); } break; - case OPTINFO_ITEM_KIND_TREE: + case optinfo_item::kind::tree: { json::object *json_item = new json::object (); json_item->set_string ("expr", item->get_text ()); @@ -363,7 +363,7 @@ optrecord_json_writer::optinfo_to_json (const optinfo *optinfo) message->append (json_item); } break; - case OPTINFO_ITEM_KIND_GIMPLE: + case optinfo_item::kind::gimple: { json::object *json_item = new json::object (); json_item->set_string ("stmt", item->get_text ()); @@ -376,7 +376,7 @@ optrecord_json_writer::optinfo_to_json (const optinfo *optinfo) message->append (json_item); } break; - case OPTINFO_ITEM_KIND_SYMTAB_NODE: + case optinfo_item::kind::symtab_node: { json::object *json_item = new json::object (); json_item->set_string ("symtab_node", item->get_text ()); diff --git a/gcc/optinfo.cc b/gcc/optinfo.cc index 51e9fd615c62..dd5a55178665 100644 --- a/gcc/optinfo.cc +++ b/gcc/optinfo.cc @@ -36,9 +36,9 @@ along with GCC; see the file COPYING3. If not see /* optinfo_item's ctor. Takes ownership of TEXT. */ -optinfo_item::optinfo_item (enum optinfo_item_kind kind, location_t location, +optinfo_item::optinfo_item (enum kind kind_, location_t location, char *text) -: m_kind (kind), m_location (location), m_text (text) +: m_kind (kind_), m_location (location), m_text (text) { } @@ -52,19 +52,19 @@ optinfo_item::~optinfo_item () /* Get a string from KIND. */ const char * -optinfo_kind_to_string (enum optinfo_kind kind) +optinfo::kind_to_string (enum kind kind_) { - switch (kind) + switch (kind_) { default: gcc_unreachable (); - case OPTINFO_KIND_SUCCESS: + case kind::success: return "success"; - case OPTINFO_KIND_FAILURE: + case kind::failure: return "failure"; - case OPTINFO_KIND_NOTE: + case kind::note: return "note"; - case OPTINFO_KIND_SCOPE: + case kind::scope: return "scope"; } } @@ -91,19 +91,19 @@ optinfo::add_item (std::unique_ptr<optinfo_item> item) /* Get MSG_* flags corresponding to KIND. */ -static dump_flags_t -optinfo_kind_to_dump_flag (enum optinfo_kind kind) +dump_flags_t +optinfo::kind_to_dump_flag (enum kind kind_) { - switch (kind) + switch (kind_) { default: gcc_unreachable (); - case OPTINFO_KIND_SUCCESS: + case kind::success: return MSG_OPTIMIZED_LOCATIONS; - case OPTINFO_KIND_FAILURE: + case kind::failure: return MSG_MISSED_OPTIMIZATION; - case OPTINFO_KIND_NOTE: - case OPTINFO_KIND_SCOPE: + case kind::note: + case kind::scope: return MSG_NOTE; } } @@ -114,7 +114,7 @@ optinfo_kind_to_dump_flag (enum optinfo_kind kind) void optinfo::emit_for_opt_problem () const { - dump_flags_t dump_kind = optinfo_kind_to_dump_flag (get_kind ()); + dump_flags_t dump_kind = kind_to_dump_flag (get_kind ()); dump_kind |= MSG_PRIORITY_REEMITTED; /* Re-emit to "immediate" destinations, without creating a new optinfo. */ @@ -134,14 +134,14 @@ void optinfo::handle_dump_file_kind (dump_flags_t dump_kind) { /* Any optinfo for a "scope" should have been emitted separately. */ - gcc_assert (m_kind != OPTINFO_KIND_SCOPE); + gcc_assert (m_kind != kind::scope); if (dump_kind & MSG_OPTIMIZED_LOCATIONS) - m_kind = OPTINFO_KIND_SUCCESS; + m_kind = kind::success; else if (dump_kind & MSG_MISSED_OPTIMIZATION) - m_kind = OPTINFO_KIND_FAILURE; + m_kind = kind::failure; else if (dump_kind & MSG_NOTE) - m_kind = OPTINFO_KIND_NOTE; + m_kind = kind::note; } /* Return true if any of the active optinfo destinations make use diff --git a/gcc/optinfo.h b/gcc/optinfo.h index 1e0fb224adc2..ca9457f1b89a 100644 --- a/gcc/optinfo.h +++ b/gcc/optinfo.h @@ -74,18 +74,6 @@ class optinfo_item; extern bool optinfo_wants_inlining_info_p (); -/* The various kinds of optinfo. */ - -enum optinfo_kind -{ - OPTINFO_KIND_SUCCESS, - OPTINFO_KIND_FAILURE, - OPTINFO_KIND_NOTE, - OPTINFO_KIND_SCOPE -}; - -extern const char *optinfo_kind_to_string (enum optinfo_kind kind); - class dump_context; /* A bundle of information describing part of an optimization. */ @@ -95,10 +83,19 @@ class optinfo friend class dump_context; public: + /* The various kinds of optinfo. */ + enum class kind + { + success, + failure, + note, + scope + }; + optinfo (const dump_location_t &loc, - enum optinfo_kind kind, + enum kind kind_, opt_pass *pass) - : m_loc (loc), m_kind (kind), m_pass (pass), m_items () + : m_loc (loc), m_kind (kind_), m_pass (pass), m_items () {} ~optinfo (); @@ -111,7 +108,7 @@ class optinfo const dump_impl_location_t & get_impl_location () const { return m_loc.get_impl_location (); } - enum optinfo_kind get_kind () const { return m_kind; } + enum kind get_kind () const { return m_kind; } opt_pass *get_pass () const { return m_pass; } unsigned int num_items () const { return m_items.length (); } const optinfo_item *get_item (unsigned int i) const { return m_items[i]; } @@ -123,6 +120,9 @@ class optinfo void emit_for_opt_problem () const; + static const char *kind_to_string (enum kind k); + static dump_flags_t kind_to_dump_flag (enum kind k); + private: /* Pre-canned ways of manipulating the optinfo, for use by friend class dump_context. */ @@ -130,37 +130,36 @@ class optinfo private: dump_location_t m_loc; - enum optinfo_kind m_kind; + enum kind m_kind; opt_pass *m_pass; auto_vec <optinfo_item *> m_items; }; -/* An enum for discriminating between different kinds of optinfo_item. */ - -enum optinfo_item_kind -{ - OPTINFO_ITEM_KIND_TEXT, - OPTINFO_ITEM_KIND_TREE, - OPTINFO_ITEM_KIND_GIMPLE, - OPTINFO_ITEM_KIND_SYMTAB_NODE -}; - /* An item within an optinfo. */ class optinfo_item { public: - optinfo_item (enum optinfo_item_kind kind, location_t location, + /* An enum for discriminating between different kinds of optinfo_item. */ + enum class kind + { + text, + tree, + gimple, + symtab_node + }; + + optinfo_item (enum kind kind_, location_t location, char *text); ~optinfo_item (); - enum optinfo_item_kind get_kind () const { return m_kind; } + enum kind get_kind () const { return m_kind; } location_t get_location () const { return m_location; } const char *get_text () const { return m_text; } private: /* Metadata (e.g. for optimization records). */ - enum optinfo_item_kind m_kind; + enum kind m_kind; location_t m_location; /* The textual form of the item, owned by the item. */ -- 2.26.3