aboutsummaryrefslogtreecommitdiff
path: root/gcc/builtins.c
diff options
context:
space:
mode:
authorKaveh R. Ghazi <ghazi@caip.rutgers.edu>2003-05-08 13:45:38 +0000
committerKaveh Ghazi <ghazi@gcc.gnu.org>2003-05-08 13:45:38 +0000
commit7dc61d6cfb77ab9d3c59cc04d4bfb732bdb5f7d0 (patch)
tree5a03f0bcac76ac17d2d946ba52f8619024d49c7b /gcc/builtins.c
parent53415fa1a1f7b3c13dde3aa0a73f35ae4dcc335b (diff)
downloadgcc-7dc61d6cfb77ab9d3c59cc04d4bfb732bdb5f7d0.zip
gcc-7dc61d6cfb77ab9d3c59cc04d4bfb732bdb5f7d0.tar.gz
gcc-7dc61d6cfb77ab9d3c59cc04d4bfb732bdb5f7d0.tar.bz2
builtins.c (readonly_data_expr): New function.
gcc: * builtins.c (readonly_data_expr): New function. (expand_builtin_memmove): Optimize any rodata source, not just strings. testsuite gcc.c-torture/execute/string-opt-19.c: Add general rodata tests. (bcopy): Call memmove. From-SVN: r66597
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r--gcc/builtins.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c
index c309997..6745300 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -168,6 +168,7 @@ static tree fold_builtin_inf PARAMS ((tree, int));
static tree fold_builtin_nan PARAMS ((tree, tree, int));
static int validate_arglist PARAMS ((tree, ...));
static tree fold_trunc_transparent_mathfn PARAMS ((tree));
+static bool readonly_data_expr PARAMS ((tree));
/* Return the alignment in bits of EXP, a pointer valued expression.
But don't return more than MAX_ALIGN no matter what.
@@ -2423,10 +2424,16 @@ expand_builtin_memmove (arglist, target, mode)
if (src_align == 0)
return 0;
- /* If src is a string constant and strings are not writable,
- we can use normal memcpy. */
- if (!flag_writable_strings && c_getstr (src))
- return expand_builtin_memcpy (arglist, target, mode, 0);
+ /* If src is categorized for a readonly section we can use
+ normal memcpy. */
+ if (readonly_data_expr (src))
+ {
+ tree const fn = implicit_built_in_decls[BUILT_IN_MEMCPY];
+ if (!fn)
+ return 0;
+ return expand_expr (build_function_call_expr (fn, arglist),
+ target, mode, EXPAND_NORMAL);
+ }
/* Otherwise, call the normal function. */
return 0;
@@ -5449,3 +5456,16 @@ purge_builtin_constant_p ()
}
}
+/* Returns true is EXP represents data that would potentially reside
+ in a readonly section. */
+
+static bool
+readonly_data_expr (tree exp)
+{
+ STRIP_NOPS (exp);
+
+ if (TREE_CODE (exp) == ADDR_EXPR)
+ return decl_readonly_section (TREE_OPERAND (exp, 0), 0);
+ else
+ return false;
+}