Move constant folds for maths functions to new file
The new routines operate on the built-in enum rather than on tree decls. The idea is to extend this to handle internal functions too, with a combined enum for both. The patch also moves fold_fma too, with the same prototype. The long-term plan is to replace FMA_EXPR with an internal function, for consistency with the way that things like SQRT will be handled. Tested on x86_64-linux-gnu, arm-linux-gnueabi and aarch64-linux-gnu. gcc/ * builtins.h (fold_fma): Move to fold-const-call.h. * builtins.c: Include fold-const-call.h. (mathfn_built_in_2): New function, split out from... (mathfn_built_in_1): ...here. (do_real_to_int_conversion, fold_const_builtin_pow) (fold_const_builtin_logb, fold_const_builtin_significand) (fold_const_builtin_load_exponent, do_mpfr_arg1, do_mpfr_arg2) (do_mpfr_arg3, do_mpfr_sincos, do_mpfr_bessel_n, do_mpc_arg1): Delete. (fold_builtin_sincos): Use fold_const_call to handle constants. (fold_builtin_1, fold_builtin_2, fold_builtin_3): Add explicit checks for ERROR_MARK. Use fold_const_call to handle constant folds for math functions. (fold_fma): Move to fold-const-call.c. * fold-const.c: Include fold-const-call.h. * Makefile.in (OBJS): Add fold-const-call.o. (PLUGIN_HEADERS): Add fold-const-call.h. * realmpfr.h (real_from_mpfr): Allow the format to be specified directly. * realmpfr.c (real_from_mpfr): Likewise. * fold-const-call.h, fold-const-call.c: New files. From-SVN: r229669
This commit is contained in:
parent
6aadd15a41
commit
5c1a2e639a
9 changed files with 1402 additions and 1025 deletions
|
@ -1,3 +1,26 @@
|
|||
2015-11-02 Richard Sandiford <richard.sandiford@arm.com>
|
||||
|
||||
* builtins.h (fold_fma): Move to fold-const-call.h.
|
||||
* builtins.c: Include fold-const-call.h.
|
||||
(mathfn_built_in_2): New function, split out from...
|
||||
(mathfn_built_in_1): ...here.
|
||||
(do_real_to_int_conversion, fold_const_builtin_pow)
|
||||
(fold_const_builtin_logb, fold_const_builtin_significand)
|
||||
(fold_const_builtin_load_exponent, do_mpfr_arg1, do_mpfr_arg2)
|
||||
(do_mpfr_arg3, do_mpfr_sincos, do_mpfr_bessel_n, do_mpc_arg1): Delete.
|
||||
(fold_builtin_sincos): Use fold_const_call to handle constants.
|
||||
(fold_builtin_1, fold_builtin_2, fold_builtin_3): Add explicit
|
||||
checks for ERROR_MARK. Use fold_const_call to handle constant
|
||||
folds for math functions.
|
||||
(fold_fma): Move to fold-const-call.c.
|
||||
* fold-const.c: Include fold-const-call.h.
|
||||
* Makefile.in (OBJS): Add fold-const-call.o.
|
||||
(PLUGIN_HEADERS): Add fold-const-call.h.
|
||||
* realmpfr.h (real_from_mpfr): Allow the format to be specified
|
||||
directly.
|
||||
* realmpfr.c (real_from_mpfr): Likewise.
|
||||
* fold-const-call.h, fold-const-call.c: New files.
|
||||
|
||||
2015-11-02 Julian Brown <julian@codesourcery.com>
|
||||
|
||||
* config/arm/neon-testgen.ml (emit_epilogue): Remove extraneous
|
||||
|
|
|
@ -1260,6 +1260,7 @@ OBJS = \
|
|||
final.o \
|
||||
fixed-value.o \
|
||||
fold-const.o \
|
||||
fold-const-call.o \
|
||||
function.o \
|
||||
fwprop.o \
|
||||
gcse.o \
|
||||
|
@ -3273,10 +3274,10 @@ PLUGIN_HEADERS = $(TREE_H) $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
|
|||
prefix.h tree-inline.h $(GIMPLE_PRETTY_PRINT_H) realmpfr.h \
|
||||
$(IPA_PROP_H) $(TARGET_H) $(RTL_H) $(TM_P_H) $(CFGLOOP_H) $(EMIT_RTL_H) \
|
||||
version.h stringpool.h gimplify.h gimple-iterator.h gimple-ssa.h \
|
||||
fold-const.h tree-cfg.h tree-into-ssa.h tree-ssanames.h print-tree.h \
|
||||
varasm.h context.h tree-phinodes.h stor-layout.h ssa-iterators.h \
|
||||
$(RESOURCE_H) tree-cfgcleanup.h attribs.h calls.h cfgexpand.h \
|
||||
diagnostic-color.h gcc-symtab.h gimple-builder.h gimple-low.h \
|
||||
fold-const.h fold-const-call.h tree-cfg.h tree-into-ssa.h tree-ssanames.h \
|
||||
print-tree.h varasm.h context.h tree-phinodes.h stor-layout.h \
|
||||
ssa-iterators.h $(RESOURCE_H) tree-cfgcleanup.h attribs.h calls.h \
|
||||
cfgexpand.h diagnostic-color.h gcc-symtab.h gimple-builder.h gimple-low.h \
|
||||
gimple-walk.h gimplify-me.h pass_manager.h print-rtl.h stmt.h \
|
||||
tree-dfa.h tree-hasher.h tree-nested.h tree-object-size.h tree-outof-ssa.h \
|
||||
tree-parloops.h tree-ssa-address.h tree-ssa-coalesce.h tree-ssa-dom.h \
|
||||
|
|
1085
gcc/builtins.c
1085
gcc/builtins.c
File diff suppressed because it is too large
Load diff
|
@ -73,7 +73,6 @@ extern rtx expand_builtin (tree, rtx, rtx, machine_mode, int);
|
|||
extern rtx expand_builtin_with_bounds (tree, rtx, rtx, machine_mode, int);
|
||||
extern enum built_in_function builtin_mathfn_code (const_tree);
|
||||
extern tree fold_builtin_expect (location_t, tree, tree, tree);
|
||||
extern tree fold_fma (location_t, tree, tree, tree, tree);
|
||||
extern bool avoid_folding_inline_builtin (tree);
|
||||
extern tree fold_call_expr (location_t, tree, bool);
|
||||
extern tree fold_builtin_call_array (location_t, tree, tree, int, tree *);
|
||||
|
|
1259
gcc/fold-const-call.c
Normal file
1259
gcc/fold-const-call.c
Normal file
File diff suppressed because it is too large
Load diff
28
gcc/fold-const-call.h
Normal file
28
gcc/fold-const-call.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
/* Fold calls to built-in and internal functions with constant arguments.
|
||||
Copyright (C) 2015 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GCC.
|
||||
|
||||
GCC is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 3, or (at your option) any later
|
||||
version.
|
||||
|
||||
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GCC; see the file COPYING3. If not see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef GCC_FOLD_CONST_CALL_H
|
||||
#define GCC_FOLD_CONST_CALL_H
|
||||
|
||||
tree fold_const_call (built_in_function, tree, tree);
|
||||
tree fold_const_call (built_in_function, tree, tree, tree);
|
||||
tree fold_const_call (built_in_function, tree, tree, tree, tree);
|
||||
tree fold_fma (location_t, tree, tree, tree, tree);
|
||||
|
||||
#endif
|
|
@ -57,6 +57,7 @@ along with GCC; see the file COPYING3. If not see
|
|||
#include "flags.h"
|
||||
#include "alias.h"
|
||||
#include "fold-const.h"
|
||||
#include "fold-const-call.h"
|
||||
#include "stor-layout.h"
|
||||
#include "calls.h"
|
||||
#include "tree-iterator.h"
|
||||
|
|
|
@ -54,11 +54,12 @@ mpfr_from_real (mpfr_ptr m, const REAL_VALUE_TYPE *r, mp_rnd_t rndmode)
|
|||
gcc_assert (ret == 0);
|
||||
}
|
||||
|
||||
/* Convert from MPFR to REAL_VALUE_TYPE, for a given type TYPE and rounding
|
||||
mode RNDMODE. TYPE is only relevant if M is a NaN. */
|
||||
/* Convert from MPFR to REAL_VALUE_TYPE, for a given format FORMAT and
|
||||
rounding mode RNDMODE. FORMAT is only relevant if M is a NaN. */
|
||||
|
||||
void
|
||||
real_from_mpfr (REAL_VALUE_TYPE *r, mpfr_srcptr m, tree type, mp_rnd_t rndmode)
|
||||
real_from_mpfr (REAL_VALUE_TYPE *r, mpfr_srcptr m, const real_format *format,
|
||||
mp_rnd_t rndmode)
|
||||
{
|
||||
/* We use a string as an intermediate type. */
|
||||
char buf[128], *rstr;
|
||||
|
@ -75,7 +76,7 @@ real_from_mpfr (REAL_VALUE_TYPE *r, mpfr_srcptr m, tree type, mp_rnd_t rndmode)
|
|||
|
||||
if (mpfr_nan_p (m))
|
||||
{
|
||||
real_nan (r, "", 1, TYPE_MODE (type));
|
||||
real_nan (r, "", 1, format);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -100,3 +101,13 @@ real_from_mpfr (REAL_VALUE_TYPE *r, mpfr_srcptr m, tree type, mp_rnd_t rndmode)
|
|||
real_from_string (r, buf);
|
||||
}
|
||||
|
||||
/* Convert from MPFR to REAL_VALUE_TYPE, for a given type TYPE and rounding
|
||||
mode RNDMODE. TYPE is only relevant if M is a NaN. */
|
||||
|
||||
void
|
||||
real_from_mpfr (REAL_VALUE_TYPE *r, mpfr_srcptr m, tree type, mp_rnd_t rndmode)
|
||||
{
|
||||
real_from_mpfr (r, m, type ? REAL_MODE_FORMAT (TYPE_MODE (type)) : NULL,
|
||||
rndmode);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
responsible for initializing and clearing the MPFR parameter. */
|
||||
|
||||
extern void real_from_mpfr (REAL_VALUE_TYPE *, mpfr_srcptr, tree, mp_rnd_t);
|
||||
extern void real_from_mpfr (REAL_VALUE_TYPE *, mpfr_srcptr,
|
||||
const real_format *, mp_rnd_t);
|
||||
extern void mpfr_from_real (mpfr_ptr, const REAL_VALUE_TYPE *, mp_rnd_t);
|
||||
|
||||
#endif /* ! GCC_REALGMP_H */
|
||||
|
|
Loading…
Add table
Reference in a new issue