This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Extend lazy computation of expensive preprocessor macros to FLOATN*
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Joseph Myers <joseph at codesourcery dot com>
- Cc: Richard Biener <rguenther at suse dot de>, Marek Polacek <polacek at redhat dot com>, gcc-patches at gcc dot gnu dot org
- Date: Sat, 27 Jan 2018 00:31:47 +0100
- Subject: Re: [PATCH] Extend lazy computation of expensive preprocessor macros to FLOATN*
- Authentication-results: sourceware.org; auth=none
- References: <20180126231100.GC2063@tucnak> <alpine.DEB.2.20.1801262317270.16084@digraph.polyomino.org.uk>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Fri, Jan 26, 2018 at 11:22:04PM +0000, Joseph Myers wrote:
> On Sat, 27 Jan 2018, Jakub Jelinek wrote:
> > Honza reported today on IRC that we spent (again) significant time
> > of empty file compilation computing preprocessor *_MAX/*_MIN etc. macros.
> > In 2010 I've added lazy computation for these, only when they are first used
> > except for -dD, but reserved just 12 entries for those, as only
> > FLT/DBL/LDBL prefixed macros (4 times for each kind) were needed at that
> > point. In 2016 for PR32187 Joseph has added a bunch of other kinds and
> > because there is no space in the array reserved for those, they are
> > evaluated right away, which is quite expensive.
> >
> > The following patch makes them lazy again.
> > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> Rather than hardcoding a number 36 I'd rather it used an explicit
> computation (with explanatory comment) such as 4 * (3 +
> NUM_FLOATN_NX_TYPES) (if that is indeed a safe value to use to guarantee
> covering all these types).
Works for me, this tests fine on a couple of tests, ok for trunk if it
passes bootstrap/regtest?
2018-01-27 Jakub Jelinek <jakub@redhat.com>
* c-cppbuiltin.c (c_cpp_builtins): Use ggc_strdup for the fp_suffix
argument.
(LAZY_HEX_FP_VALUES_CNT): Define.
(lazy_hex_fp_values): Allow up to LAZY_HEX_FP_VALUES_CNT lazy hex fp
values rather than just 12.
(builtin_define_with_hex_fp_value): Likewise.
* include/cpplib.h (enum cpp_builtin_type): Change BT_LAST_USER from
BT_FIRST_USER + 31 to BT_FIRST_USER + 63.
--- gcc/c-family/c-cppbuiltin.c.jj 2018-01-03 10:20:21.369538150 +0100
+++ gcc/c-family/c-cppbuiltin.c 2018-01-26 11:01:15.266648197 +0100
@@ -1124,8 +1124,8 @@ c_cpp_builtins (cpp_reader *pfile)
floatn_nx_types[i].extended ? "X" : "");
sprintf (csuffix, "F%d%s", floatn_nx_types[i].n,
floatn_nx_types[i].extended ? "x" : "");
- builtin_define_float_constants (prefix, csuffix, "%s", csuffix,
- FLOATN_NX_TYPE_NODE (i));
+ builtin_define_float_constants (prefix, ggc_strdup (csuffix), "%s",
+ csuffix, FLOATN_NX_TYPE_NODE (i));
}
/* For decfloat.h. */
@@ -1571,7 +1571,14 @@ struct GTY(()) lazy_hex_fp_value_struct
int digits;
const char *fp_suffix;
};
-static GTY(()) struct lazy_hex_fp_value_struct lazy_hex_fp_values[12];
+/* Number of the expensive to compute macros we should evaluate lazily.
+ Each builtin_define_float_constants invocation calls
+ builtin_define_with_hex_fp_value 4 times and builtin_define_float_constants
+ is called for FLT, DBL, LDBL and up to NUM_FLOATN_NX_TYPES times for
+ FLTNN*. */
+#define LAZY_HEX_FP_VALUES_CNT (4 * (3 + NUM_FLOATN_NX_TYPES))
+static GTY(()) struct lazy_hex_fp_value_struct
+ lazy_hex_fp_values[LAZY_HEX_FP_VALUES_CNT];
static GTY(()) int lazy_hex_fp_value_count;
static bool
@@ -1616,7 +1623,7 @@ builtin_define_with_hex_fp_value (const
char dec_str[64], buf[256], buf1[128], buf2[64];
/* This is very expensive, so if possible expand them lazily. */
- if (lazy_hex_fp_value_count < 12
+ if (lazy_hex_fp_value_count < LAZY_HEX_FP_VALUES_CNT
&& flag_dump_macros == 0
&& !cpp_get_options (parse_in)->traditional)
{
--- libcpp/include/cpplib.h.jj 2018-01-18 21:11:59.890207215 +0100
+++ libcpp/include/cpplib.h 2018-01-26 10:58:10.249699482 +0100
@@ -719,7 +719,7 @@ enum cpp_builtin_type
BT_COUNTER, /* `__COUNTER__' */
BT_HAS_ATTRIBUTE, /* `__has_attribute__(x)' */
BT_FIRST_USER, /* User defined builtin macros. */
- BT_LAST_USER = BT_FIRST_USER + 31
+ BT_LAST_USER = BT_FIRST_USER + 63
};
#define CPP_HASHNODE(HNODE) ((cpp_hashnode *) (HNODE))
Jakub