public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-5016] ipa-cp: Templatize filtering of m_agg_values
@ 2023-10-30 17:38 Martin Jambor
0 siblings, 0 replies; only message in thread
From: Martin Jambor @ 2023-10-30 17:38 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:1437df40f12ade35fd1f1a3e4cbba4b4656cab0b
commit r14-5016-g1437df40f12ade35fd1f1a3e4cbba4b4656cab0b
Author: Martin Jambor <mjambor@suse.cz>
Date: Mon Oct 30 18:34:59 2023 +0100
ipa-cp: Templatize filtering of m_agg_values
PR 111157 points to another place where IPA-CP collected aggregate
compile-time constants need to be filtered, in addition to the one
place that already does this in ipa-sra. In order to re-use code,
this patch turns the common bit into a template.
The functionality is still covered by testcase gcc.dg/ipa/pr108959.c.
gcc/ChangeLog:
2023-09-13 Martin Jambor <mjambor@suse.cz>
PR ipa/111157
* ipa-prop.h (ipcp_transformation): New member function template
remove_argaggs_if.
* ipa-sra.cc (zap_useless_ipcp_results): Use remove_argaggs_if to
filter aggreagate constants.
Diff:
---
gcc/ipa-prop.h | 33 +++++++++++++++++++++++++++++++++
gcc/ipa-sra.cc | 33 ++++-----------------------------
2 files changed, 37 insertions(+), 29 deletions(-)
diff --git a/gcc/ipa-prop.h b/gcc/ipa-prop.h
index a7f34a8393b1..34b0d77b34bb 100644
--- a/gcc/ipa-prop.h
+++ b/gcc/ipa-prop.h
@@ -947,6 +947,39 @@ struct GTY(()) ipcp_transformation
void maybe_create_parm_idx_map (tree fndecl);
+ /* Remove all elements in m_agg_values on which PREDICATE returns true. */
+
+ template<typename pred_function>
+ void remove_argaggs_if (pred_function &&predicate)
+ {
+ unsigned ts_len = vec_safe_length (m_agg_values);
+ if (ts_len == 0)
+ return;
+
+ bool removed_item = false;
+ unsigned dst_index = 0;
+
+ for (unsigned i = 0; i < ts_len; i++)
+ {
+ ipa_argagg_value *v = &(*m_agg_values)[i];
+ if (!predicate (*v))
+ {
+ if (removed_item)
+ (*m_agg_values)[dst_index] = *v;
+ dst_index++;
+ }
+ else
+ removed_item = true;
+ }
+ if (dst_index == 0)
+ {
+ ggc_free (m_agg_values);
+ m_agg_values = NULL;
+ }
+ else if (removed_item)
+ m_agg_values->truncate (dst_index);
+ }
+
/* Known aggregate values. */
vec<ipa_argagg_value, va_gc> *m_agg_values;
/* Value range information. */
diff --git a/gcc/ipa-sra.cc b/gcc/ipa-sra.cc
index 495d7e67d6e2..6ffad335db44 100644
--- a/gcc/ipa-sra.cc
+++ b/gcc/ipa-sra.cc
@@ -4104,35 +4104,10 @@ mark_callers_calls_comdat_local (struct cgraph_node *node, void *)
static void
zap_useless_ipcp_results (const isra_func_summary *ifs, ipcp_transformation *ts)
{
- unsigned ts_len = vec_safe_length (ts->m_agg_values);
-
- if (ts_len == 0)
- return;
-
- bool removed_item = false;
- unsigned dst_index = 0;
-
- for (unsigned i = 0; i < ts_len; i++)
- {
- ipa_argagg_value *v = &(*ts->m_agg_values)[i];
- const isra_param_desc *desc = &(*ifs->m_parameters)[v->index];
-
- if (!desc->locally_unused)
- {
- if (removed_item)
- (*ts->m_agg_values)[dst_index] = *v;
- dst_index++;
- }
- else
- removed_item = true;
- }
- if (dst_index == 0)
- {
- ggc_free (ts->m_agg_values);
- ts->m_agg_values = NULL;
- }
- else if (removed_item)
- ts->m_agg_values->truncate (dst_index);
+ ts->remove_argaggs_if ([ifs](const ipa_argagg_value &v)
+ {
+ return (*ifs->m_parameters)[v.index].locally_unused;
+ });
bool useful_vr = false;
unsigned count = vec_safe_length (ts->m_vr);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-10-30 17:38 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-30 17:38 [gcc r14-5016] ipa-cp: Templatize filtering of m_agg_values Martin Jambor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).