for 2 and 3 argument calls. Committed.
Richard. 2014-08-18 Richard Biener <rguent...@suse.de> * gimple-fold.c (gimple_build): Add function call overloads with two and three arguments. * gimple-fold.h (gimple_build): Likewise. Index: gcc/gimple-fold.c =================================================================== --- gcc/gimple-fold.c (revision 214097) +++ gcc/gimple-fold.c (working copy) @@ -5156,11 +5224,12 @@ gimple_build (gimple_seq *seq, location_ return res; } -/* Build the expression CODE OP0 of type TYPE with location LOC, +/* Build the call FN (ARG0) with a result of type TYPE + (or no result if TYPE is void) with location LOC, simplifying it first if possible using VALUEIZE if not NULL. - OP0 is expected to be valueized already. Returns the built - expression value and appends statements possibly defining it - to SEQ. */ + ARG0 is expected to be valueized already. Returns the built + expression value (or NULL_TREE if TYPE is void) and appends + statements possibly defining it to SEQ. */ tree gimple_build (gimple_seq *seq, location_t loc, @@ -5170,13 +5239,79 @@ gimple_build (gimple_seq *seq, location_ tree res = gimple_simplify (fn, type, arg0, seq, valueize); if (!res) { - if (gimple_in_ssa_p (cfun)) - res = make_ssa_name (type, NULL); - else - res = create_tmp_reg (type, NULL); tree decl = builtin_decl_implicit (fn); gimple stmt = gimple_build_call (decl, 1, arg0); - gimple_call_set_lhs (stmt, res); + if (!VOID_TYPE_P (type)) + { + if (gimple_in_ssa_p (cfun)) + res = make_ssa_name (type, NULL); + else + res = create_tmp_reg (type, NULL); + gimple_call_set_lhs (stmt, res); + } + gimple_set_location (stmt, loc); + gimple_seq_add_stmt_without_update (seq, stmt); + } + return res; +} + +/* Build the call FN (ARG0, ARG1) with a result of type TYPE + (or no result if TYPE is void) with location LOC, + simplifying it first if possible using VALUEIZE if not NULL. + ARG0 is expected to be valueized already. Returns the built + expression value (or NULL_TREE if TYPE is void) and appends + statements possibly defining it to SEQ. */ + +tree +gimple_build (gimple_seq *seq, location_t loc, + enum built_in_function fn, tree type, tree arg0, tree arg1, + tree (*valueize)(tree)) +{ + tree res = gimple_simplify (fn, type, arg0, arg1, seq, valueize); + if (!res) + { + tree decl = builtin_decl_implicit (fn); + gimple stmt = gimple_build_call (decl, 2, arg0, arg1); + if (!VOID_TYPE_P (type)) + { + if (gimple_in_ssa_p (cfun)) + res = make_ssa_name (type, NULL); + else + res = create_tmp_reg (type, NULL); + gimple_call_set_lhs (stmt, res); + } + gimple_set_location (stmt, loc); + gimple_seq_add_stmt_without_update (seq, stmt); + } + return res; +} + +/* Build the call FN (ARG0, ARG1, ARG2) with a result of type TYPE + (or no result if TYPE is void) with location LOC, + simplifying it first if possible using VALUEIZE if not NULL. + ARG0 is expected to be valueized already. Returns the built + expression value (or NULL_TREE if TYPE is void) and appends + statements possibly defining it to SEQ. */ + +tree +gimple_build (gimple_seq *seq, location_t loc, + enum built_in_function fn, tree type, + tree arg0, tree arg1, tree arg2, + tree (*valueize)(tree)) +{ + tree res = gimple_simplify (fn, type, arg0, arg1, arg2, seq, valueize); + if (!res) + { + tree decl = builtin_decl_implicit (fn); + gimple stmt = gimple_build_call (decl, 3, arg0, arg1, arg2); + if (!VOID_TYPE_P (type)) + { + if (gimple_in_ssa_p (cfun)) + res = make_ssa_name (type, NULL); + else + res = create_tmp_reg (type, NULL); + gimple_call_set_lhs (stmt, res); + } gimple_set_location (stmt, loc); gimple_seq_add_stmt_without_update (seq, stmt); } Index: gcc/gimple-fold.h =================================================================== --- gcc/gimple-fold.h (revision 214097) +++ gcc/gimple-fold.h (working copy) @@ -85,7 +85,25 @@ gimple_build (gimple_seq *seq, { return gimple_build (seq, UNKNOWN_LOCATION, fn, type, arg0); } - +tree gimple_build (gimple_seq *, location_t, + enum built_in_function, tree, tree, tree, + tree (*valueize) (tree) = NULL); +inline tree +gimple_build (gimple_seq *seq, + enum built_in_function fn, tree type, tree arg0, tree arg1) +{ + return gimple_build (seq, UNKNOWN_LOCATION, fn, type, arg0, arg1); +} +tree gimple_build (gimple_seq *, location_t, + enum built_in_function, tree, tree, tree, tree, + tree (*valueize) (tree) = NULL); +inline tree +gimple_build (gimple_seq *seq, + enum built_in_function fn, tree type, + tree arg0, tree arg1, tree arg2) +{ + return gimple_build (seq, UNKNOWN_LOCATION, fn, type, arg0, arg1, arg2); +} /* ??? Forward from gimple-expr.h. */ extern bool useless_type_conversion_p (tree, tree);