public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [RFC] -folding dumping for fold-const.cc
@ 2023-08-25 12:54 Richard Biener
  2023-08-25 13:37 ` Patrick Palka
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Biener @ 2023-08-25 12:54 UTC (permalink / raw)
  To: gcc-patches


The following adds the capability to have fold-const.cc matched
patterns visible in -folding dumps.  There's two choices,
a portable one replacing return stmts like

-       return fold_build1 (tcode, ctype, fold_convert (ctype, t1));
+       DRET (fold_build1 (tcode, ctype, fold_convert (ctype, t1)));

(carefully keeping total line length the same)

Or less portably by wrapping the return value:

-       return fold_build1 (tcode, ctype, fold_convert (ctype, t1));
+       return DUMP_FOLD (fold_build1 (tcode, ctype, fold_convert (ctype, 
t1)));

(requiring re-indenting)

+/* Similar to match.pd dumping support notes as part of -folding dumping
+   by wrapping return values in DUMP_FOLD (...).  */
+#if __GNUC__
+#define DUMP_FOLD(X) (__extension__ ({ \
+  auto x = (X); \
+  if (x && dump_file && (dump_flags & TDF_FOLDING)) \
+    fprintf (dump_file, "Applying fold-const.c:%d\n", __LINE__); \
+  x; \
+}))      
+#else                             
+#define DUMP_FOLD(X) (X)          
+#endif 

vs.

+/* Similar to match.pd dumping support notes as part of -folding dumping
+   by changing return statements to DRET (...).  */
+#define DRET(X) do { \
+  auto x = (X); \
+  if (x && dump_file && (dump_flags & TDF_FOLDING)) \
+    fprintf (dump_file, "Applying fold-const.c:%d\n", __LINE__); \
+  return x; \
+} while (0)

I personally prefer keeping 'return' visible and thus going the
non-portable way.  Any C++ folks know how to avoid re-evaluating
X portably in expression context?

Any other comments?

Thanks,
Richard.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [RFC] -folding dumping for fold-const.cc
  2023-08-25 12:54 [RFC] -folding dumping for fold-const.cc Richard Biener
@ 2023-08-25 13:37 ` Patrick Palka
  0 siblings, 0 replies; 2+ messages in thread
From: Patrick Palka @ 2023-08-25 13:37 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

On Fri, 25 Aug 2023, Richard Biener via Gcc-patches wrote:

> 
> The following adds the capability to have fold-const.cc matched
> patterns visible in -folding dumps.  There's two choices,
> a portable one replacing return stmts like
> 
> -       return fold_build1 (tcode, ctype, fold_convert (ctype, t1));
> +       DRET (fold_build1 (tcode, ctype, fold_convert (ctype, t1)));
> 
> (carefully keeping total line length the same)
> 
> Or less portably by wrapping the return value:
> 
> -       return fold_build1 (tcode, ctype, fold_convert (ctype, t1));
> +       return DUMP_FOLD (fold_build1 (tcode, ctype, fold_convert (ctype, 
> t1)));
> 
> (requiring re-indenting)
> 
> +/* Similar to match.pd dumping support notes as part of -folding dumping
> +   by wrapping return values in DUMP_FOLD (...).  */
> +#if __GNUC__
> +#define DUMP_FOLD(X) (__extension__ ({ \
> +  auto x = (X); \
> +  if (x && dump_file && (dump_flags & TDF_FOLDING)) \
> +    fprintf (dump_file, "Applying fold-const.c:%d\n", __LINE__); \
> +  x; \
> +}))      

Would using an ordinary function here work?

  static tree
  dump_fold (tree x, int line)
  {
    if (...)
      fprintf (dump_file, "Applying fold-const.c:%d\n", line);
    return x;
  }

  #define DUMP_FOLD(X) dump_fold ((X), __LINE__)

> +#else                             
> +#define DUMP_FOLD(X) (X)          
> +#endif 
> 
> vs.
> 
> +/* Similar to match.pd dumping support notes as part of -folding dumping
> +   by changing return statements to DRET (...).  */
> +#define DRET(X) do { \
> +  auto x = (X); \
> +  if (x && dump_file && (dump_flags & TDF_FOLDING)) \
> +    fprintf (dump_file, "Applying fold-const.c:%d\n", __LINE__); \
> +  return x; \
> +} while (0)
> 
> I personally prefer keeping 'return' visible and thus going the
> non-portable way.  Any C++ folks know how to avoid re-evaluating
> X portably in expression context?
> 
> Any other comments?
> 
> Thanks,
> Richard.
> 
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-08-25 13:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-25 12:54 [RFC] -folding dumping for fold-const.cc Richard Biener
2023-08-25 13:37 ` Patrick Palka

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).