From e144a2b3066ecad2a7c934b1cd437d2afad0018f Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Fri, 24 Aug 2018 11:17:16 +0000 Subject: cfg.h (struct control_flow_graph): Add edge_flags_allocated and bb_flags_allocated members. 2018-08-24 Richard Biener * cfg.h (struct control_flow_graph): Add edge_flags_allocated and bb_flags_allocated members. (auto_flag): New RAII class for allocating flags. (auto_edge_flag): New RAII class for allocating edge flags. (auto_bb_flag): New RAII class for allocating bb flags. * cfgloop.c (verify_loop_structure): Allocate temporary edge flag dynamically. * cfganal.c (dfs_enumerate_from): Remove use of visited sbitmap in favor of temporarily allocated BB flag. * hsa-brig.c: Re-order includes. * hsa-dump.c: Likewise. * hsa-regalloc.c: Likewise. * print-rtl.c: Likewise. * profile-count.c: Likewise. From-SVN: r263830 --- gcc/cfg.h | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'gcc/cfg.h') diff --git a/gcc/cfg.h b/gcc/cfg.h index 0953456..9fff135 100644 --- a/gcc/cfg.h +++ b/gcc/cfg.h @@ -74,6 +74,10 @@ struct GTY(()) control_flow_graph { /* Maximal count of BB in function. */ profile_count count_max; + + /* Dynamically allocated edge/bb flags. */ + int edge_flags_allocated; + int bb_flags_allocated; }; @@ -121,4 +125,60 @@ extern basic_block get_bb_copy (basic_block); void set_loop_copy (struct loop *, struct loop *); struct loop *get_loop_copy (struct loop *); +/* Generic RAII class to allocate a bit from storage of integer type T. + The allocated bit is accessible as mask with the single bit set + via the conversion operator to T. */ + +template +class auto_flag +{ +public: + /* static assert T is integer type of max HOST_WIDE_INT precision. */ + auto_flag (T *sptr) + { + m_sptr = sptr; + int free_bit = ffs_hwi (~*sptr); + /* If there are no unset bits... */ + if (free_bit == 0) + gcc_unreachable (); + m_flag = HOST_WIDE_INT_1U << (free_bit - 1); + /* ...or if T is signed and thus the complement is sign-extended, + check if we ran out of bits. We could spare us this bit + if we could use C++11 std::make_unsigned::type to pass + ~*sptr to ffs_hwi. */ + if (m_flag == 0) + gcc_unreachable (); + gcc_checking_assert ((*sptr & m_flag) == 0); + *sptr |= m_flag; + } + ~auto_flag () + { + gcc_checking_assert ((*m_sptr & m_flag) == m_flag); + *m_sptr &= ~m_flag; + } + operator T () const { return m_flag; } +private: + T *m_sptr; + T m_flag; +}; + +/* RAII class to allocate an edge flag for temporary use. You have + to clear the flag from all edges when you are finished using it. */ + +class auto_edge_flag : public auto_flag +{ +public: + auto_edge_flag (function *fun) + : auto_flag (&fun->cfg->edge_flags_allocated) {} +}; + +/* RAII class to allocate a bb flag for temporary use. You have + to clear the flag from all edges when you are finished using it. */ +class auto_bb_flag : public auto_flag +{ +public: + auto_bb_flag (function *fun) + : auto_flag (&fun->cfg->bb_flags_allocated) {} +}; + #endif /* GCC_CFG_H */ -- cgit v1.1