Skip to content

Commit b963237

Browse files
committed
optinfo: use enum class
Modernization; no functional change intended. 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. Signed-off-by: David Malcolm <[email protected]>
1 parent 7969e48 commit b963237

File tree

6 files changed

+90
-88
lines changed

6 files changed

+90
-88
lines changed

gcc/dump-context.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,39 +267,39 @@ extern void verify_dumped_text (const location &loc,
267267
void
268268
verify_item (const location &loc,
269269
const optinfo_item *item,
270-
enum optinfo_item_kind expected_kind,
270+
enum optinfo_item::kind expected_kind,
271271
location_t expected_location,
272272
const char *expected_text);
273273

274274
/* Verify that ITEM is a text item, with EXPECTED_TEXT. */
275275

276276
#define ASSERT_IS_TEXT(ITEM, EXPECTED_TEXT) \
277277
SELFTEST_BEGIN_STMT \
278-
verify_item (SELFTEST_LOCATION, (ITEM), OPTINFO_ITEM_KIND_TEXT, \
278+
verify_item (SELFTEST_LOCATION, (ITEM), optinfo_item::kind::text, \
279279
UNKNOWN_LOCATION, (EXPECTED_TEXT)); \
280280
SELFTEST_END_STMT
281281

282282
/* Verify that ITEM is a tree item, with the expected values. */
283283

284284
#define ASSERT_IS_TREE(ITEM, EXPECTED_LOCATION, EXPECTED_TEXT) \
285285
SELFTEST_BEGIN_STMT \
286-
verify_item (SELFTEST_LOCATION, (ITEM), OPTINFO_ITEM_KIND_TREE, \
286+
verify_item (SELFTEST_LOCATION, (ITEM), optinfo_item::kind::tree, \
287287
(EXPECTED_LOCATION), (EXPECTED_TEXT)); \
288288
SELFTEST_END_STMT
289289

290290
/* Verify that ITEM is a gimple item, with the expected values. */
291291

292292
#define ASSERT_IS_GIMPLE(ITEM, EXPECTED_LOCATION, EXPECTED_TEXT) \
293293
SELFTEST_BEGIN_STMT \
294-
verify_item (SELFTEST_LOCATION, (ITEM), OPTINFO_ITEM_KIND_GIMPLE, \
294+
verify_item (SELFTEST_LOCATION, (ITEM), optinfo_item::kind::gimple, \
295295
(EXPECTED_LOCATION), (EXPECTED_TEXT)); \
296296
SELFTEST_END_STMT
297297

298298
/* Verify that ITEM is a symtab node, with the expected values. */
299299

300300
#define ASSERT_IS_SYMTAB_NODE(ITEM, EXPECTED_LOCATION, EXPECTED_TEXT) \
301301
SELFTEST_BEGIN_STMT \
302-
verify_item (SELFTEST_LOCATION, (ITEM), OPTINFO_ITEM_KIND_SYMTAB_NODE, \
302+
verify_item (SELFTEST_LOCATION, (ITEM), optinfo_item::kind::symtab_node, \
303303
(EXPECTED_LOCATION), (EXPECTED_TEXT)); \
304304
SELFTEST_END_STMT
305305

gcc/dumpfile.cc

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,8 @@ make_item_for_dump_gimple_stmt (gimple *stmt, int spc, dump_flags_t dump_flags)
636636
pp_gimple_stmt_1 (&pp, stmt, spc, dump_flags);
637637
pp_newline (&pp);
638638

639-
std::unique_ptr<optinfo_item> item
640-
= std::make_unique<optinfo_item> (OPTINFO_ITEM_KIND_GIMPLE,
639+
auto item
640+
= std::make_unique<optinfo_item> (optinfo_item::kind::gimple,
641641
gimple_location (stmt),
642642
xstrdup (pp_formatted_text (&pp)));
643643
return item;
@@ -684,8 +684,8 @@ make_item_for_dump_gimple_expr (gimple *stmt, int spc, dump_flags_t dump_flags)
684684
pp_needs_newline (&pp) = true;
685685
pp_gimple_stmt_1 (&pp, stmt, spc, dump_flags);
686686

687-
std::unique_ptr<optinfo_item> item
688-
= std::make_unique<optinfo_item> (OPTINFO_ITEM_KIND_GIMPLE,
687+
auto item
688+
= std::make_unique<optinfo_item> (optinfo_item::kind::gimple,
689689
gimple_location (stmt),
690690
xstrdup (pp_formatted_text (&pp)));
691691
return item;
@@ -738,8 +738,8 @@ make_item_for_dump_generic_expr (tree node, dump_flags_t dump_flags)
738738
if (EXPR_HAS_LOCATION (node))
739739
loc = EXPR_LOCATION (node);
740740

741-
std::unique_ptr<optinfo_item> item
742-
= std::make_unique<optinfo_item> (OPTINFO_ITEM_KIND_TREE, loc,
741+
auto item
742+
= std::make_unique<optinfo_item> (optinfo_item::kind::tree, loc,
743743
xstrdup (pp_formatted_text (&pp)));
744744
return item;
745745
}
@@ -783,8 +783,8 @@ static std::unique_ptr<optinfo_item>
783783
make_item_for_dump_symtab_node (symtab_node *node)
784784
{
785785
location_t loc = DECL_SOURCE_LOCATION (node->decl);
786-
std::unique_ptr<optinfo_item> item
787-
= std::make_unique<optinfo_item> (OPTINFO_ITEM_KIND_SYMTAB_NODE, loc,
786+
auto item
787+
= std::make_unique<optinfo_item> (optinfo_item::kind::symtab_node, loc,
788788
xstrdup (node->dump_name ()));
789789
return item;
790790
}
@@ -1011,8 +1011,9 @@ emit_any_pending_textual_chunks ()
10111011
return;
10121012

10131013
char *formatted_text = xstrdup (pp_formatted_text (pp));
1014-
std::unique_ptr<optinfo_item> item
1015-
= std::make_unique<optinfo_item> (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION,
1014+
auto item
1015+
= std::make_unique<optinfo_item> (optinfo_item::kind::text,
1016+
UNKNOWN_LOCATION,
10161017
formatted_text);
10171018
pp->emit_item (std::move (item), m_optinfo);
10181019

@@ -1084,7 +1085,8 @@ make_item_for_dump_dec (const poly_int<N, C> &value)
10841085
}
10851086

10861087
auto item
1087-
= std::make_unique<optinfo_item> (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION,
1088+
= std::make_unique<optinfo_item> (optinfo_item::kind::text,
1089+
UNKNOWN_LOCATION,
10881090
xstrdup (pp_formatted_text (&pp)));
10891091
return item;
10901092
}
@@ -1162,8 +1164,9 @@ dump_context::begin_scope (const char *name,
11621164
pretty_printer pp;
11631165
pp_printf (&pp, "%s %s %s", "===", name, "===");
11641166
pp_newline (&pp);
1165-
std::unique_ptr<optinfo_item> item
1166-
= std::make_unique<optinfo_item> (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION,
1167+
auto item
1168+
= std::make_unique<optinfo_item> (optinfo_item::kind::text,
1169+
UNKNOWN_LOCATION,
11671170
xstrdup (pp_formatted_text (&pp)));
11681171
emit_item (*item.get (), MSG_NOTE);
11691172

@@ -1172,7 +1175,7 @@ dump_context::begin_scope (const char *name,
11721175
optinfo &info
11731176
= begin_next_optinfo (dump_metadata_t (MSG_NOTE, impl_location),
11741177
user_location);
1175-
info.m_kind = OPTINFO_KIND_SCOPE;
1178+
info.m_kind = optinfo::kind::scope;
11761179
info.add_item (std::move (item));
11771180
end_any_optinfo ();
11781181
}
@@ -1221,7 +1224,7 @@ dump_context::begin_next_optinfo (const dump_metadata_t &metadata,
12211224
end_any_optinfo ();
12221225
gcc_assert (m_pending == NULL);
12231226
dump_location_t loc (user_loc, metadata.get_impl_location ());
1224-
m_pending = new optinfo (loc, OPTINFO_KIND_NOTE, current_pass);
1227+
m_pending = new optinfo (loc, optinfo::kind::note, current_pass);
12251228
m_pending->handle_dump_file_kind (metadata.get_dump_flags ());
12261229
return *m_pending;
12271230
}
@@ -2265,7 +2268,7 @@ verify_dumped_text (const location &loc,
22652268
void
22662269
verify_item (const location &loc,
22672270
const optinfo_item *item,
2268-
enum optinfo_item_kind expected_kind,
2271+
enum optinfo_item::kind expected_kind,
22692272
location_t expected_location,
22702273
const char *expected_text)
22712274
{
@@ -2324,7 +2327,7 @@ test_capture_of_dump_calls (const line_table_case &case_)
23242327
{
23252328
optinfo *info = tmp.get_pending_optinfo ();
23262329
ASSERT_TRUE (info != NULL);
2327-
ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE);
2330+
ASSERT_EQ (info->get_kind (), optinfo::kind::note);
23282331
ASSERT_EQ (info->num_items (), 1);
23292332
ASSERT_IS_TEXT (info->get_item (0), "int: 42 str: foo");
23302333
ASSERT_IMPL_LOCATION_EQ (info->get_impl_location (),
@@ -2345,7 +2348,7 @@ test_capture_of_dump_calls (const line_table_case &case_)
23452348
{
23462349
optinfo *info = tmp.get_pending_optinfo ();
23472350
ASSERT_TRUE (info != NULL);
2348-
ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE);
2351+
ASSERT_EQ (info->get_kind (), optinfo::kind::note);
23492352
ASSERT_EQ (info->num_items (), 2);
23502353
ASSERT_IS_TEXT (info->get_item (0), "tree: ");
23512354
ASSERT_IS_TREE (info->get_item (1), UNKNOWN_LOCATION, "0");
@@ -2367,7 +2370,7 @@ test_capture_of_dump_calls (const line_table_case &case_)
23672370
{
23682371
optinfo *info = tmp.get_pending_optinfo ();
23692372
ASSERT_TRUE (info != NULL);
2370-
ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE);
2373+
ASSERT_EQ (info->get_kind (), optinfo::kind::note);
23712374
ASSERT_EQ (info->num_items (), 2);
23722375
ASSERT_IS_TEXT (info->get_item (0), "gimple: ");
23732376
ASSERT_IS_GIMPLE (info->get_item (1), stmt_loc, "return;");
@@ -2389,7 +2392,7 @@ test_capture_of_dump_calls (const line_table_case &case_)
23892392
{
23902393
optinfo *info = tmp.get_pending_optinfo ();
23912394
ASSERT_TRUE (info != NULL);
2392-
ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE);
2395+
ASSERT_EQ (info->get_kind (), optinfo::kind::note);
23932396
ASSERT_EQ (info->num_items (), 2);
23942397
ASSERT_IS_TEXT (info->get_item (0), "gimple: ");
23952398
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_)
24112414
{
24122415
optinfo *info = tmp.get_pending_optinfo ();
24132416
ASSERT_TRUE (info != NULL);
2414-
ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE);
2417+
ASSERT_EQ (info->get_kind (), optinfo::kind::note);
24152418
ASSERT_EQ (info->num_items (), 2);
24162419
ASSERT_IS_TEXT (info->get_item (0), "node: ");
24172420
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_)
24412444
{
24422445
optinfo *info = tmp.get_pending_optinfo ();
24432446
ASSERT_TRUE (info != NULL);
2444-
ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE);
2447+
ASSERT_EQ (info->get_kind (), optinfo::kind::note);
24452448
ASSERT_EQ (info->num_items (), 8);
24462449
ASSERT_IS_TEXT (info->get_item (0), "before ");
24472450
ASSERT_IS_TREE (info->get_item (1), UNKNOWN_LOCATION, "0");
@@ -2471,7 +2474,7 @@ test_capture_of_dump_calls (const line_table_case &case_)
24712474
optinfo *info = tmp.get_pending_optinfo ();
24722475
ASSERT_TRUE (info != NULL);
24732476
ASSERT_EQ (info->get_location_t (), stmt_loc);
2474-
ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE);
2477+
ASSERT_EQ (info->get_kind (), optinfo::kind::note);
24752478
ASSERT_EQ (info->num_items (), 2);
24762479
ASSERT_IS_TEXT (info->get_item (0), "test of tree: ");
24772480
ASSERT_IS_TREE (info->get_item (1), UNKNOWN_LOCATION, "0");
@@ -2494,7 +2497,7 @@ test_capture_of_dump_calls (const line_table_case &case_)
24942497
optinfo *info = tmp.get_pending_optinfo ();
24952498
ASSERT_TRUE (info != NULL);
24962499
ASSERT_EQ (info->get_location_t (), stmt_loc);
2497-
ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE);
2500+
ASSERT_EQ (info->get_kind (), optinfo::kind::note);
24982501
ASSERT_EQ (info->num_items (), 1);
24992502
ASSERT_IS_TREE (info->get_item (0), UNKNOWN_LOCATION, "1");
25002503
ASSERT_IMPL_LOCATION_EQ (info->get_impl_location (),
@@ -2598,7 +2601,7 @@ test_capture_of_dump_calls (const line_table_case &case_)
25982601
{
25992602
optinfo *info = tmp.get_pending_optinfo ();
26002603
ASSERT_TRUE (info != NULL);
2601-
ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE);
2604+
ASSERT_EQ (info->get_kind (), optinfo::kind::note);
26022605
ASSERT_EQ (info->num_items (), 1);
26032606
ASSERT_IS_SYMTAB_NODE (info->get_item (0), decl_loc, "test_decl/1");
26042607
ASSERT_IMPL_LOCATION_EQ (info->get_impl_location (),
@@ -2727,15 +2730,15 @@ test_capture_of_dump_calls (const line_table_case &case_)
27272730
temp_dump_context tmp (true, true, MSG_ALL_KINDS);
27282731
dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc, "test");
27292732
ASSERT_EQ (tmp.get_pending_optinfo ()->get_kind (),
2730-
OPTINFO_KIND_SUCCESS);
2733+
optinfo::kind::success);
27312734
}
27322735

27332736
/* MSG_MISSED_OPTIMIZATION. */
27342737
{
27352738
temp_dump_context tmp (true, true, MSG_ALL_KINDS);
27362739
dump_printf_loc (MSG_MISSED_OPTIMIZATION, loc, "test");
27372740
ASSERT_EQ (tmp.get_pending_optinfo ()->get_kind (),
2738-
OPTINFO_KIND_FAILURE);
2741+
optinfo::kind::failure);
27392742
}
27402743
}
27412744

gcc/opt-problem.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ along with GCC; see the file COPYING3. If not see
4242

4343
opt_problem::opt_problem (const dump_location_t &loc,
4444
const char *fmt, va_list *ap)
45-
: m_optinfo (loc, OPTINFO_KIND_FAILURE, current_pass)
45+
: m_optinfo (loc, optinfo::kind::failure, current_pass)
4646
{
4747
/* We shouldn't be bothering to construct these objects if
4848
dumping isn't enabled. */

gcc/optinfo-emit-json.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ optrecord_json_writer::add_record (const optinfo *optinfo)
143143
add_record (obj);
144144

145145
/* Potentially push the scope. */
146-
if (optinfo->get_kind () == OPTINFO_KIND_SCOPE)
146+
if (optinfo->get_kind () == optinfo::kind::scope)
147147
{
148148
json::array *children = new json::array ();
149149
obj->set ("children", children);
@@ -334,7 +334,7 @@ optrecord_json_writer::optinfo_to_json (const optinfo *optinfo)
334334
obj->set ("impl_location",
335335
impl_location_to_json (optinfo->get_impl_location ()));
336336

337-
const char *kind_str = optinfo_kind_to_string (optinfo->get_kind ());
337+
const char *kind_str = optinfo::kind_to_string (optinfo->get_kind ());
338338
obj->set_string ("kind", kind_str);
339339
json::array *message = new json::array ();
340340
obj->set ("message", message);
@@ -345,12 +345,12 @@ optrecord_json_writer::optinfo_to_json (const optinfo *optinfo)
345345
{
346346
default:
347347
gcc_unreachable ();
348-
case OPTINFO_ITEM_KIND_TEXT:
348+
case optinfo_item::kind::text:
349349
{
350350
message->append_string (item->get_text ());
351351
}
352352
break;
353-
case OPTINFO_ITEM_KIND_TREE:
353+
case optinfo_item::kind::tree:
354354
{
355355
json::object *json_item = new json::object ();
356356
json_item->set_string ("expr", item->get_text ());
@@ -363,7 +363,7 @@ optrecord_json_writer::optinfo_to_json (const optinfo *optinfo)
363363
message->append (json_item);
364364
}
365365
break;
366-
case OPTINFO_ITEM_KIND_GIMPLE:
366+
case optinfo_item::kind::gimple:
367367
{
368368
json::object *json_item = new json::object ();
369369
json_item->set_string ("stmt", item->get_text ());
@@ -376,7 +376,7 @@ optrecord_json_writer::optinfo_to_json (const optinfo *optinfo)
376376
message->append (json_item);
377377
}
378378
break;
379-
case OPTINFO_ITEM_KIND_SYMTAB_NODE:
379+
case optinfo_item::kind::symtab_node:
380380
{
381381
json::object *json_item = new json::object ();
382382
json_item->set_string ("symtab_node", item->get_text ());

0 commit comments

Comments
 (0)