diff options
author | Wilco Dijkstra <wdijkstr@arm.com> | 2016-10-05 12:31:05 +0000 |
---|---|---|
committer | Wilco Dijkstra <wilco@gcc.gnu.org> | 2016-10-05 12:31:05 +0000 |
commit | 71dea1dd60888030f3130f16933becdf597538ab (patch) | |
tree | 2e5b327406e5695e411f9f03cf0000a0eb1aafa8 /gcc/builtins.c | |
parent | 92805612f4e0cdd33e10282eaf2cc0369bca3293 (diff) | |
download | gcc-71dea1dd60888030f3130f16933becdf597538ab.zip gcc-71dea1dd60888030f3130f16933becdf597538ab.tar.gz gcc-71dea1dd60888030f3130f16933becdf597538ab.tar.bz2 |
Move all existing strchr and strrchr folding from builtins.c to gimple-fold.c.
gcc/
* builtins.c (fold_builtin_strchr): Remove function.
(fold_builtin_strrchr): Likewise.
(fold_builtin2): Remove strchr, index, strrchr, rindex cases.
* gimple-fold.c (target_char_cst_p): New function.
(gimple_fold_builtin_strchr) Add more foldings.
(gimple_fold_builtin): Add index, strrchr, rindex cases.
From-SVN: r240782
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r-- | gcc/builtins.c | 128 |
1 files changed, 0 insertions, 128 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c index 35cb109..facecd3 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -148,7 +148,6 @@ static tree rewrite_call_expr (location_t, tree, int, tree, int, ...); static bool validate_arg (const_tree, enum tree_code code); static rtx expand_builtin_fabs (tree, rtx, rtx); static rtx expand_builtin_signbit (tree, rtx); -static tree fold_builtin_strchr (location_t, tree, tree, tree); static tree fold_builtin_memchr (location_t, tree, tree, tree, tree); static tree fold_builtin_memcmp (location_t, tree, tree, tree); static tree fold_builtin_strcmp (location_t, tree, tree); @@ -168,7 +167,6 @@ static tree fold_builtin_varargs (location_t, tree, tree*, int); static tree fold_builtin_strpbrk (location_t, tree, tree, tree); static tree fold_builtin_strstr (location_t, tree, tree, tree); -static tree fold_builtin_strrchr (location_t, tree, tree, tree); static tree fold_builtin_strspn (location_t, tree, tree); static tree fold_builtin_strcspn (location_t, tree, tree); @@ -8395,14 +8393,6 @@ fold_builtin_2 (location_t loc, tree fndecl, tree arg0, tree arg1) case BUILT_IN_STRCSPN: return fold_builtin_strcspn (loc, arg0, arg1); - case BUILT_IN_STRCHR: - case BUILT_IN_INDEX: - return fold_builtin_strchr (loc, arg0, arg1, type); - - case BUILT_IN_STRRCHR: - case BUILT_IN_RINDEX: - return fold_builtin_strrchr (loc, arg0, arg1, type); - case BUILT_IN_STRCMP: return fold_builtin_strcmp (loc, arg0, arg1); @@ -8895,124 +8885,6 @@ fold_builtin_strstr (location_t loc, tree s1, tree s2, tree type) } } -/* Simplify a call to the strchr builtin. S1 and S2 are the arguments to - the call, and TYPE is its return type. - - Return NULL_TREE if no simplification was possible, otherwise return the - simplified form of the call as a tree. - - The simplified form may be a constant or other expression which - computes the same value, but in a more efficient manner (including - calls to other builtin functions). - - The call may contain arguments which need to be evaluated, but - which are not useful to determine the result of the call. In - this case we return a chain of COMPOUND_EXPRs. The LHS of each - COMPOUND_EXPR will be an argument which must be evaluated. - COMPOUND_EXPRs are chained through their RHS. The RHS of the last - COMPOUND_EXPR in the chain will contain the tree for the simplified - form of the builtin function call. */ - -static tree -fold_builtin_strchr (location_t loc, tree s1, tree s2, tree type) -{ - if (!validate_arg (s1, POINTER_TYPE) - || !validate_arg (s2, INTEGER_TYPE)) - return NULL_TREE; - else - { - const char *p1; - - if (TREE_CODE (s2) != INTEGER_CST) - return NULL_TREE; - - p1 = c_getstr (s1); - if (p1 != NULL) - { - char c; - const char *r; - tree tem; - - if (target_char_cast (s2, &c)) - return NULL_TREE; - - r = strchr (p1, c); - - if (r == NULL) - return build_int_cst (TREE_TYPE (s1), 0); - - /* Return an offset into the constant string argument. */ - tem = fold_build_pointer_plus_hwi_loc (loc, s1, r - p1); - return fold_convert_loc (loc, type, tem); - } - return NULL_TREE; - } -} - -/* Simplify a call to the strrchr builtin. S1 and S2 are the arguments to - the call, and TYPE is its return type. - - Return NULL_TREE if no simplification was possible, otherwise return the - simplified form of the call as a tree. - - The simplified form may be a constant or other expression which - computes the same value, but in a more efficient manner (including - calls to other builtin functions). - - The call may contain arguments which need to be evaluated, but - which are not useful to determine the result of the call. In - this case we return a chain of COMPOUND_EXPRs. The LHS of each - COMPOUND_EXPR will be an argument which must be evaluated. - COMPOUND_EXPRs are chained through their RHS. The RHS of the last - COMPOUND_EXPR in the chain will contain the tree for the simplified - form of the builtin function call. */ - -static tree -fold_builtin_strrchr (location_t loc, tree s1, tree s2, tree type) -{ - if (!validate_arg (s1, POINTER_TYPE) - || !validate_arg (s2, INTEGER_TYPE)) - return NULL_TREE; - else - { - tree fn; - const char *p1; - - if (TREE_CODE (s2) != INTEGER_CST) - return NULL_TREE; - - p1 = c_getstr (s1); - if (p1 != NULL) - { - char c; - const char *r; - tree tem; - - if (target_char_cast (s2, &c)) - return NULL_TREE; - - r = strrchr (p1, c); - - if (r == NULL) - return build_int_cst (TREE_TYPE (s1), 0); - - /* Return an offset into the constant string argument. */ - tem = fold_build_pointer_plus_hwi_loc (loc, s1, r - p1); - return fold_convert_loc (loc, type, tem); - } - - if (! integer_zerop (s2)) - return NULL_TREE; - - fn = builtin_decl_implicit (BUILT_IN_STRCHR); - if (!fn) - return NULL_TREE; - - /* Transform strrchr(s1, '\0') to strchr(s1, '\0'). */ - return build_call_expr_loc (loc, fn, 2, s1, s2); - } -} - /* Simplify a call to the strpbrk builtin. S1 and S2 are the arguments to the call, and TYPE is its return type. |