This is the first step in constification (and/or C++ification)
of the cfghooks. Currently we compare variables to figure out
what the current IR type is. Rather let's move the ir_type
into the cfghooks.  This will help with constification due
to sel-sched overloading one of the hooks.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

        * cfghooks.cc (current_ir_type): Return cfghooks' ir field.
        * cfghooks.h (struct cfg_hooks): Add ir field.
        * cfgrtl.cc (rtl_cfg_hooks): Update for new ir field.
        (cfg_layout_rtl_cfg_hooks): Likewise.
        * tree-cfg.cc (gimple_cfg_hooks): Likewise.

Signed-off-by: Andrew Pinski <[email protected]>
---
 gcc/cfghooks.cc | 9 +--------
 gcc/cfghooks.h  | 1 +
 gcc/cfgrtl.cc   | 2 ++
 gcc/tree-cfg.cc | 1 +
 4 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/gcc/cfghooks.cc b/gcc/cfghooks.cc
index 6415d0fdec2..381d63c9398 100644
--- a/gcc/cfghooks.cc
+++ b/gcc/cfghooks.cc
@@ -86,14 +86,7 @@ set_cfg_hooks (struct cfg_hooks new_cfg_hooks)
 enum ir_type
 current_ir_type (void)
 {
-  if (cfg_hooks == &gimple_cfg_hooks)
-    return IR_GIMPLE;
-  else if (cfg_hooks == &rtl_cfg_hooks)
-    return IR_RTL_CFGRTL;
-  else if (cfg_hooks == &cfg_layout_rtl_cfg_hooks)
-    return IR_RTL_CFGLAYOUT;
-  else
-    gcc_unreachable ();
+  return cfg_hooks->ir;
 }
 
 /* Verify the CFG consistency.
diff --git a/gcc/cfghooks.h b/gcc/cfghooks.h
index bc7956be2a8..75857f6f90d 100644
--- a/gcc/cfghooks.h
+++ b/gcc/cfghooks.h
@@ -79,6 +79,7 @@ struct cfg_hooks
 {
   /* Name of the corresponding ir.  */
   const char *name;
+  enum ir_type ir;
 
   /* Debugging.  */
   bool (*verify_flow_info) (void);
diff --git a/gcc/cfgrtl.cc b/gcc/cfgrtl.cc
index 0e409140e71..5a0b09f801e 100644
--- a/gcc/cfgrtl.cc
+++ b/gcc/cfgrtl.cc
@@ -5386,6 +5386,7 @@ rtl_account_profile_record (basic_block bb, struct 
profile_record *record)
 /* Implementation of CFG manipulation for linearized RTL.  */
 struct cfg_hooks rtl_cfg_hooks = {
   "rtl",
+  IR_RTL_CFGRTL,
   rtl_verify_flow_info,
   rtl_dump_bb,
   rtl_dump_bb_for_graph,
@@ -5429,6 +5430,7 @@ struct cfg_hooks rtl_cfg_hooks = {
 
 struct cfg_hooks cfg_layout_rtl_cfg_hooks = {
   "cfglayout mode",
+  IR_RTL_CFGLAYOUT,
   rtl_verify_flow_info_1,
   rtl_dump_bb,
   rtl_dump_bb_for_graph,
diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc
index 3b95e0a68f1..56a5af86538 100644
--- a/gcc/tree-cfg.cc
+++ b/gcc/tree-cfg.cc
@@ -9361,6 +9361,7 @@ gimple_account_profile_record (basic_block bb,
 
 struct cfg_hooks gimple_cfg_hooks = {
   "gimple",
+  IR_GIMPLE,
   gimple_verify_flow_info,
   gimple_dump_bb,              /* dump_bb  */
   gimple_dump_bb_for_graph,    /* dump_bb_for_graph  */
-- 
2.43.0

Reply via email to