From 2a281178f70c38d796c8ec77e049f8139e1110fc Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Fri, 8 Jun 2018 14:10:02 +0200 Subject: [PATCH] Code refactoring for call_summary. 2018-06-08 Martin Liska * symbol-summary.h (release): Move definition out of class declaration. (symtab_removal): Likewise. (symtab_duplication): Likewise. From-SVN: r261308 --- gcc/ChangeLog | 7 +++ gcc/symbol-summary.h | 123 ++++++++++++++++++++++++------------------- 2 files changed, 77 insertions(+), 53 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b8f501be7f6..9a338f2643a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2018-06-08 Martin Liska + + * symbol-summary.h (release): Move definition out of class + declaration. + (symtab_removal): Likewise. + (symtab_duplication): Likewise. + 2018-06-08 Martin Liska * symbol-summary.h (function_summary): Move constructor diff --git a/gcc/symbol-summary.h b/gcc/symbol-summary.h index 13f8f04342a..a73472ef0ae 100644 --- a/gcc/symbol-summary.h +++ b/gcc/symbol-summary.h @@ -330,21 +330,7 @@ public: } /* Destruction method that can be called for GGT purpose. */ - void release () - { - if (m_released) - return; - - m_symtab->remove_edge_removal_hook (m_symtab_removal_hook); - m_symtab->remove_edge_duplication_hook (m_symtab_duplication_hook); - - /* Release all summaries. */ - typedef typename hash_map ::iterator map_iterator; - for (map_iterator it = m_map.begin (); it != m_map.end (); ++it) - release ((*it).second); - - m_released = true; - } + void release (); /* Traverses all summarys with a function F called with ARG as argument. */ @@ -369,16 +355,7 @@ public: } /* Release an item that is stored within map. */ - void release (T *item) - { - if (m_ggc) - { - item->~T (); - ggc_free (item); - } - else - delete item; - } + void release (T *item); /* Getter for summary callgraph edge pointer. */ T* get (cgraph_edge *edge) @@ -399,37 +376,11 @@ public: } /* Symbol removal hook that is registered to symbol table. */ - static void symtab_removal (cgraph_edge *edge, void *data) - { - call_summary *summary = (call_summary *) (data); - - int h_uid = summary->hashable_uid (edge); - T **v = summary->m_map.get (h_uid); - - if (v) - { - summary->remove (edge, *v); - summary->release (*v); - summary->m_map.remove (h_uid); - } - } + static void symtab_removal (cgraph_edge *edge, void *data); /* Symbol duplication hook that is registered to symbol table. */ static void symtab_duplication (cgraph_edge *edge1, cgraph_edge *edge2, - void *data) - { - call_summary *summary = (call_summary *) (data); - T **v = summary->m_map.get (summary->hashable_uid (edge1)); - - if (v) - { - /* This load is necessary, because we insert a new value! */ - T *data = *v; - T *duplicate = summary->allocate_new (); - summary->m_map.put (summary->hashable_uid (edge2), duplicate); - summary->duplicate (edge1, edge2, data, duplicate); - } - } + void *data); protected: /* Indication if we use ggc summary. */ @@ -473,6 +424,72 @@ private: gt_pointer_operator, void *); }; +template +void +call_summary::release () +{ + if (m_released) + return; + + m_symtab->remove_edge_removal_hook (m_symtab_removal_hook); + m_symtab->remove_edge_duplication_hook (m_symtab_duplication_hook); + + /* Release all summaries. */ + typedef typename hash_map ::iterator map_iterator; + for (map_iterator it = m_map.begin (); it != m_map.end (); ++it) + release ((*it).second); + + m_released = true; +} + +template +void +call_summary::release (T *item) +{ + if (m_ggc) + { + item->~T (); + ggc_free (item); + } + else + delete item; +} + +template +void +call_summary::symtab_removal (cgraph_edge *edge, void *data) +{ + call_summary *summary = (call_summary *) (data); + + int h_uid = summary->hashable_uid (edge); + T **v = summary->m_map.get (h_uid); + + if (v) + { + summary->remove (edge, *v); + summary->release (*v); + summary->m_map.remove (h_uid); + } +} + +template +void +call_summary::symtab_duplication (cgraph_edge *edge1, + cgraph_edge *edge2, void *data) +{ + call_summary *summary = (call_summary *) (data); + T **v = summary->m_map.get (summary->hashable_uid (edge1)); + + if (v) + { + /* This load is necessary, because we insert a new value! */ + T *data = *v; + T *duplicate = summary->allocate_new (); + summary->m_map.put (summary->hashable_uid (edge2), duplicate); + summary->duplicate (edge1, edge2, data, duplicate); + } +} + template void gt_ggc_mx(call_summary* const &summary) -- 2.30.2