public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Aldy Hernandez <aldyh@redhat.com>
To: Jonathan Wakely <jwakely@redhat.com>
Cc: Jakub Jelinek <jakub@redhat.com>,
	 Andrew MacLeod via Gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: std:vec for classes with constructor?
Date: Fri, 7 Aug 2020 20:04:57 +0200	[thread overview]
Message-ID: <CAGm3qMU+g3FZRxDkCkDvNdLQpHgr3MEktz3f6omMSkYZHT8mHQ@mail.gmail.com> (raw)
In-Reply-To: <20200807091729.GO3400@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1412 bytes --]

Is the attached patch what y'all suggest?

The patch reverts the GCC vec<> usage in ipa-fnsummary.c and
implements the above suggestion.

Bootstraps, tests running...

If tests pass, is this OK?

Thanks.
Aldy

On Fri, Aug 7, 2020 at 11:17 AM Jonathan Wakely via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> On 07/08/20 10:55 +0200, Jakub Jelinek wrote:
> >On Fri, Aug 07, 2020 at 09:34:38AM +0100, Jonathan Wakely via Gcc-patches wrote:
> >> > Now that you say it, vec has a T[1] member so depending on T
> >> > there might be a side-effect as invoking its CTOR?  Or it might
> >> > even not compile if there is no default CTOR available...  Ick :/
> >>
> >> Right.
> >>
> >> Does the GTY stuff add members to the struct, or otherwise alter its
> >> layout?
> >
> >Or perhaps use offsetof on an alternate structure that should have the same
> >layout.
>
> Yes that's what I was going to suggest next.
>
> >So instead of
> >  typedef vec<T, A, vl_embed> vec_embedded;
> >  return offsetof (vec_embedded, m_vecdata) + alloc * sizeof (T);
> >use
> >  struct alignas (T) U { char data[sizeof (T)]; };
> >  typedef vec<U, A, vl_embed> vec_embedded;
>
> static_assert(sizeof(vec_embedded) == sizeof(vec), "");
> static_assert(alignof(vec_embedded) == alignof(vec), "");
>
> >  return offsetof (vec_embedded, m_vecdata) + alloc * sizeof (T);
> >where vec_embedded should have the same offset of m_vecdata as vec.
>

[-- Attachment #2: curr.patch --]
[-- Type: text/x-patch, Size: 3342 bytes --]

diff --git a/gcc/ipa-fnsummary.c b/gcc/ipa-fnsummary.c
index 49bab04524b..d853ed8f075 100644
--- a/gcc/ipa-fnsummary.c
+++ b/gcc/ipa-fnsummary.c
@@ -82,7 +82,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimplify.h"
 #include "stringpool.h"
 #include "attribs.h"
-#include <vector>
 #include "tree-into-ssa.h"
 
 /* Summaries.  */
@@ -331,7 +330,7 @@ static void
 evaluate_conditions_for_known_args (struct cgraph_node *node,
 				    bool inline_p,
 				    vec<tree> known_vals,
-				    const std::vector<value_range> &known_value_ranges,
+				    vec<value_range> known_value_ranges,
 				    vec<ipa_agg_value_set> known_aggs,
 				    clause_t *ret_clause,
 				    clause_t *ret_nonspec_clause)
@@ -446,7 +445,7 @@ evaluate_conditions_for_known_args (struct cgraph_node *node,
 	      continue;
 	    }
 	}
-      if (c->operand_num < (int) known_value_ranges.size ()
+      if (c->operand_num < (int) known_value_ranges.length ()
 	  && !c->agg_contents
 	  && !known_value_ranges[c->operand_num].undefined_p ()
 	  && !known_value_ranges[c->operand_num].varying_p ()
@@ -555,7 +554,7 @@ evaluate_properties_for_edge (struct cgraph_edge *e, bool inline_p,
 {
   struct cgraph_node *callee = e->callee->ultimate_alias_target ();
   class ipa_fn_summary *info = ipa_fn_summaries->get (callee);
-  std::vector<value_range> known_value_ranges (32);
+  auto_vec<value_range, 32> known_value_ranges;
   class ipa_edge_args *args;
 
   if (clause_ptr)
@@ -630,11 +629,11 @@ evaluate_properties_for_edge (struct cgraph_edge *e, bool inline_p,
 								   i));
 		    if (!vr.undefined_p () && !vr.varying_p ())
 		      {
-			if (!known_value_ranges.size ())
+			if (!known_value_ranges.length ())
 			  {
-			    known_value_ranges.resize (count);
+			    known_value_ranges.safe_grow (count);
 			    for (int i = 0; i < count; ++i)
-			      known_value_ranges[i].set_undefined ();
+			      new (&known_value_ranges[i]) value_range ();
 			  }
 			known_value_ranges[i] = vr;
 		      }
@@ -808,7 +807,7 @@ ipa_fn_summary_t::duplicate (cgraph_node *src,
 	}
       evaluate_conditions_for_known_args (dst, false,
 					  known_vals,
-					  std::vector<value_range> (),
+					  vNULL,
 					  vNULL,
 					  &possible_truths,
 					  /* We are going to specialize,
@@ -3692,8 +3691,7 @@ estimate_ipcp_clone_size_and_time (struct cgraph_node *node,
   clause_t clause, nonspec_clause;
 
   /* TODO: Also pass known value ranges.  */
-  evaluate_conditions_for_known_args (node, false, known_vals,
-				      std::vector<value_range> (),
+  evaluate_conditions_for_known_args (node, false, known_vals, vNULL,
 				      known_aggs, &clause, &nonspec_clause);
   ipa_call_context ctx (node, clause, nonspec_clause,
 		        known_vals, known_contexts,
diff --git a/gcc/vec.h b/gcc/vec.h
index 3ad99b83690..01d7736c520 100644
--- a/gcc/vec.h
+++ b/gcc/vec.h
@@ -1281,7 +1281,10 @@ template<typename T, typename A>
 inline size_t
 vec<T, A, vl_embed>::embedded_size (unsigned alloc)
 {
-  typedef vec<T, A, vl_embed> vec_embedded;
+  struct alignas (T) U { char data[sizeof (T)]; };
+  typedef vec<U, A, vl_embed> vec_embedded;
+  static_assert(sizeof(vec_embedded) == sizeof(vec), "");
+  static_assert(alignof(vec_embedded) == alignof(vec), "");
   return offsetof (vec_embedded, m_vecdata) + alloc * sizeof (T);
 }
 

  reply	other threads:[~2020-08-07 18:05 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-31 21:44 [patch] multi-range implementation for value_range (irange) Aldy Hernandez
2020-08-05 14:27 ` Gerald Pfeifer
2020-08-05 15:45   ` Aldy Hernandez
2020-08-05 22:43     ` Gerald Pfeifer
2020-08-06  4:00       ` Richard Sandiford
2020-08-10  3:42   ` Martin Liška
2020-08-10  7:44     ` Aldy Hernandez
2020-08-10 10:22       ` Gerald Pfeifer
2020-08-10 10:30         ` Martin Liška
2020-08-10 11:03         ` Aldy Hernandez
2020-08-05 15:09 ` std:vec for classes with constructor? (Was: Re: [patch] multi-range implementation for value_range (irange)) Martin Jambor
2020-08-05 15:41   ` Aldy Hernandez
2020-08-05 16:55     ` Richard Biener
2020-08-24 21:53     ` Jeff Law
2020-08-24 22:03       ` Andrew MacLeod
2020-08-05 16:54   ` Richard Biener
2020-08-06  1:07     ` Andrew MacLeod
2020-08-06  5:16       ` std:vec for classes with constructor? Richard Sandiford
2020-08-06 10:19         ` Jonathan Wakely
2020-08-06 10:31           ` Richard Biener
2020-08-06 10:48             ` Jonathan Wakely
2020-08-06 14:17               ` Aldy Hernandez
2020-08-06 14:35                 ` Richard Biener
2020-08-06 14:59                   ` Aldy Hernandez
2020-08-06 16:30                 ` Jonathan Wakely
2020-08-06 17:58                   ` Aldy Hernandez
2020-08-06 19:24                     ` Jonathan Wakely
2020-08-07  6:48                       ` Richard Biener
2020-08-07  7:57                         ` Jonathan Wakely
2020-08-07  8:22                           ` Richard Biener
2020-08-07  8:34                             ` Jonathan Wakely
2020-08-07  8:54                               ` Richard Biener
2020-08-07  8:55                               ` Jakub Jelinek
2020-08-07  9:17                                 ` Jonathan Wakely
2020-08-07 18:04                                   ` Aldy Hernandez [this message]
2020-08-07 18:33                                     ` Jakub Jelinek
2020-08-10 12:57                                       ` Aldy Hernandez
2020-08-10 13:05                                         ` Aldy Hernandez
2020-08-10 18:03                                           ` Jakub Jelinek
2020-08-10 13:51                                         ` Jakub Jelinek
2020-08-10 16:58                                           ` Richard Biener
2020-08-10 17:18                                             ` Jakub Jelinek
2020-08-13 11:38                                     ` r11-2663 causes static_assert failure (was: Re: std:vec for classes with constructor?) Tobias Burnus
2020-08-13 11:52                                       ` Jakub Jelinek
2020-08-13 12:06                                         ` r11-2663 causes static_assert failure Tobias Burnus
2020-08-13 12:25                                           ` Jakub Jelinek
2020-08-13 12:40                                             ` Jakub Jelinek
2020-08-13 12:46                                             ` Iain Sandoe
2020-08-13 12:55                                               ` Iain Sandoe
2020-08-13 13:04                                                 ` Jakub Jelinek
2020-08-13 13:00                                               ` Jakub Jelinek
2020-08-06  6:57       ` std:vec for classes with constructor? (Was: Re: [patch] multi-range implementation for value_range (irange)) Richard Biener
2020-08-06 10:23         ` Jonathan Wakely
2020-08-06 11:03         ` Aldy Hernandez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAGm3qMU+g3FZRxDkCkDvNdLQpHgr3MEktz3f6omMSkYZHT8mHQ@mail.gmail.com \
    --to=aldyh@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=jwakely@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).