PATCH RFA: Better warnings for CONST_DOUBLE
Ian Lance Taylor
ian@airs.com
Thu Jul 28 16:52:00 GMT 2005
Richard Henderson <rth@redhat.com> writes:
> On Wed, Jul 27, 2005 at 05:09:09PM -0700, Ian Lance Taylor wrote:
> > +#define CONST_DOUBLE_REAL_VALUE(r) \
> > + ((struct real_value *)&XCNMWINT (r, 0, CONST_DOUBLE, VOIDmode))
>
> If we're going to change this, I think it makes sense to add a
> "struct real_value *" field to the union, so that we don't have
> to have the cast.
OK, here is the new patch.
I tried eliminating CONST_DOUBLE_FORMAT and just using "ww", and
special casing CONST_DOUBLE in rtx_size, but it ran into trouble with
various functions which use the rtx format and actually access the
real_value_format value as a sequence of HOST_WIDE_INT values. For
example, exp_equiv_p in cse.c. So changing CONST_DOUBLE_FORMAT would
require adding a special case for CONST_DOUBLE with non-VOIDmode in
all those functions. Or adding a new rtx_format code and updating
everything, which implies also introducing a new rtx_code to avoid the
ambiguity. I'm willing to pursue those approaches, but I think that
they are not appropriate for stage 3. So I'm proposing the appended
patch for now, which is a minimal change.
I tested this with a bootstrap and testsuite run on i686-pc-linux-gnu.
David Edelsohn pointed out that this patch might cause other targets
to break with --enable-checking, if they happen to use the
CONST_DOUBLE accessors incorrectly. Of course this would be a bug in
the target, but it would be better to fix those bugs before this patch
goes in, to avoid slowing down unrelated development.
I don't currently have access to any non-i386 targets. Would anybody
care to volunteer to test other targets? Geoff already volunteered to
test PowerPC Darwin.
Thanks.
OK for mainline pending any other test results?
:ADDPATCH middle-end:
Ian
2005-07-28 Ian Lance Taylor <ian@airs.com>
* rtl.h: Include "real.h".
(struct rtx_def): Add rv field to union.
(XCMWINT, XCNMWINT): Define.
(rtl_check_failed_code_mode): Declare.
(CONST_DOUBLE_LOW, CONST_DOUBLE_HIGH): Use XCWINT.
(CONST_DOUBLE_REAL_VALUE): Use XCNMWINT.
* rtl.c (rtl_check_failed_code_mode): New function.
* Makefile.in (RTL_BASE_H): Add real.h.
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.1530
diff -p -u -r1.1530 Makefile.in
--- Makefile.in 25 Jul 2005 23:04:33 -0000 1.1530
+++ Makefile.in 28 Jul 2005 16:33:19 -0000
@@ -716,7 +716,7 @@ HOSTHOOKS_DEF_H = hosthooks-def.h $(HOOK
LANGHOOKS_DEF_H = langhooks-def.h $(HOOKS_H)
TARGET_DEF_H = target-def.h $(HOOKS_H)
RTL_BASE_H = rtl.h rtl.def $(MACHMODE_H) reg-notes.def insn-notes.def \
- input.h statistics.h
+ input.h real.h statistics.h
RTL_H = $(RTL_BASE_H) genrtl.h
PARAMS_H = params.h params.def
TREE_H = tree.h tree.def $(MACHMODE_H) tree-check.h builtins.def \
Index: rtl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/rtl.c,v
retrieving revision 1.155
diff -p -u -r1.155 rtl.c
--- rtl.c 25 Jun 2005 02:00:58 -0000 1.155
+++ rtl.c 28 Jul 2005 16:33:24 -0000
@@ -515,6 +515,21 @@ rtl_check_failed_code2 (rtx r, enum rtx_
func, trim_filename (file), line);
}
+void
+rtl_check_failed_code_mode (rtx r, enum rtx_code code, enum machine_mode mode,
+ bool not_mode, const char *file, int line,
+ const char *func)
+{
+ internal_error ((not_mode
+ ? ("RTL check: expected code '%s' and not mode '%s', "
+ "have code '%s' and mode '%s' in %s, at %s:%d")
+ : ("RTL check: expected code '%s' and mode '%s', "
+ "have code '%s' and mode '%s' in %s, at %s:%d")),
+ GET_RTX_NAME (code), GET_MODE_NAME (mode),
+ GET_RTX_NAME (GET_CODE (r)), GET_MODE_NAME (GET_MODE (r)),
+ func, trim_filename (file), line);
+}
+
/* XXX Maybe print the vector? */
void
rtvec_check_failed_bounds (rtvec r, int n, const char *file, int line,
Index: rtl.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/rtl.h,v
retrieving revision 1.556
diff -p -u -r1.556 rtl.h
--- rtl.h 5 Jul 2005 16:20:14 -0000 1.556
+++ rtl.h 28 Jul 2005 16:33:24 -0000
@@ -25,6 +25,7 @@ Software Foundation, 51 Franklin Street,
#include "statistics.h"
#include "machmode.h"
#include "input.h"
+#include "real.h"
#undef FFS /* Some systems predefine this symbol; don't let it interfere. */
#undef FLOAT /* Likewise. */
@@ -249,6 +250,7 @@ struct rtx_def GTY((chain_next ("RTX_NEX
union u {
rtunion fld[1];
HOST_WIDE_INT hwint[1];
+ struct real_value rv;
} GTY ((special ("rtx_def"), desc ("GET_CODE (&%0)"))) u;
};
@@ -454,6 +456,20 @@ struct rtvec_def GTY(()) {
__FUNCTION__); \
&_rtx->u.hwint[N]; }))
+#define XCMWINT(RTX, N, C, M) __extension__ \
+(*({ rtx const _rtx = (RTX); \
+ if (GET_CODE (_rtx) != (C) || GET_MODE (_rtx) != (M)) \
+ rtl_check_failed_code_mode (_rtx, (C), (M), false, __FILE__, \
+ __LINE__, __FUNCTION__); \
+ &_rtx->u.hwint[N]; }))
+
+#define XCNMPRV(RTX, C, M) __extension__ \
+({ rtx const _rtx = (RTX); \
+ if (GET_CODE (_rtx) != (C) || GET_MODE (_rtx) == (M)) \
+ rtl_check_failed_code_mode (_rtx, (C), (M), true, __FILE__, \
+ __LINE__, __FUNCTION__); \
+ &_rtx->u.rv; })
+
extern void rtl_check_failed_bounds (rtx, int, const char *, int,
const char *)
ATTRIBUTE_NORETURN;
@@ -469,6 +485,9 @@ extern void rtl_check_failed_code1 (rtx,
extern void rtl_check_failed_code2 (rtx, enum rtx_code, enum rtx_code,
const char *, int, const char *)
ATTRIBUTE_NORETURN;
+extern void rtl_check_failed_code_mode (rtx, enum rtx_code, enum machine_mode,
+ bool, const char *, int, const char *)
+ ATTRIBUTE_NORETURN;
extern void rtvec_check_failed_bounds (rtvec, int, const char *, int,
const char *)
ATTRIBUTE_NORETURN;
@@ -482,6 +501,9 @@ extern void rtvec_check_failed_bounds (r
#define RTVEC_ELT(RTVEC, I) ((RTVEC)->elem[I])
#define XWINT(RTX, N) ((RTX)->u.hwint[N])
#define XCWINT(RTX, N, C) ((RTX)->u.hwint[N])
+#define XCMWINT(RTX, N, C, M) ((RTX)->u.hwint[N])
+#define XCNMWINT(RTX, N, C, M) ((RTX)->u.hwint[N])
+#define XCNMPRV(RTX, C, M) (&(RTX)->u.rv)
#endif
@@ -916,9 +938,9 @@ enum label_kind
low-order word and ..._HIGH the high-order.
For a float, there is a REAL_VALUE_TYPE structure, and
CONST_DOUBLE_REAL_VALUE(r) is a pointer to it. */
-#define CONST_DOUBLE_LOW(r) XCWINT (r, 0, CONST_DOUBLE)
-#define CONST_DOUBLE_HIGH(r) XCWINT (r, 1, CONST_DOUBLE)
-#define CONST_DOUBLE_REAL_VALUE(r) ((struct real_value *)&CONST_DOUBLE_LOW(r))
+#define CONST_DOUBLE_LOW(r) XCMWINT (r, 0, CONST_DOUBLE, VOIDmode)
+#define CONST_DOUBLE_HIGH(r) XCMWINT (r, 1, CONST_DOUBLE, VOIDmode)
+#define CONST_DOUBLE_REAL_VALUE(r) XCNMPRV (r, CONST_DOUBLE, VOIDmode)
/* For a CONST_VECTOR, return element #n. */
#define CONST_VECTOR_ELT(RTX, N) XCVECEXP (RTX, 0, N, CONST_VECTOR)
More information about the Gcc-patches
mailing list