diff options
Diffstat (limited to 'gcc/gimple-fold.cc')
-rw-r--r-- | gcc/gimple-fold.cc | 82 |
1 files changed, 55 insertions, 27 deletions
diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc index 185f9db..729080a 100644 --- a/gcc/gimple-fold.cc +++ b/gcc/gimple-fold.cc @@ -191,16 +191,6 @@ can_refer_decl_in_current_unit_p (tree decl, tree from_decl) return !node || !node->inlined_to; } -/* Create a temporary for TYPE for a statement STMT. If the current function - is in SSA form, a SSA name is created. Otherwise a temporary register - is made. */ - -tree -create_tmp_reg_or_ssa_name (tree type, gimple *stmt) -{ - return make_ssa_name (type, stmt); -} - /* CVAL is value taken from DECL_INITIAL of variable. Try to transform it into acceptable form for is_gimple_min_invariant. FROM_DECL (if non-NULL) specify variable whose constructor contains CVAL. */ @@ -1038,8 +1028,7 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi, { new_stmt = gimple_build_assign (NULL_TREE, srcmem); srcmem - = create_tmp_reg_or_ssa_name (TREE_TYPE (srcmem), - new_stmt); + = make_ssa_name (TREE_TYPE (srcmem), new_stmt); gimple_assign_set_lhs (new_stmt, srcmem); gimple_set_vuse (new_stmt, gimple_vuse (stmt)); gimple_set_location (new_stmt, loc); @@ -1308,8 +1297,7 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi, if (! is_gimple_min_invariant (srcvar)) { new_stmt = gimple_build_assign (NULL_TREE, srcvar); - srcvar = create_tmp_reg_or_ssa_name (TREE_TYPE (srcvar), - new_stmt); + srcvar = make_ssa_name (TREE_TYPE (srcvar), new_stmt); gimple_assign_set_lhs (new_stmt, srcvar); gimple_set_vuse (new_stmt, gimple_vuse (stmt)); gimple_set_location (new_stmt, loc); @@ -2281,7 +2269,7 @@ gimple_fold_builtin_strchr (gimple_stmt_iterator *gsi, bool is_strrchr) gimple_seq stmts = NULL; gimple *new_stmt = gimple_build_call (strlen_fn, 1, str); gimple_set_location (new_stmt, loc); - len = create_tmp_reg_or_ssa_name (size_type_node); + len = make_ssa_name (size_type_node); gimple_call_set_lhs (new_stmt, len); gimple_seq_add_stmt_without_update (&stmts, new_stmt); @@ -2427,7 +2415,7 @@ gimple_fold_builtin_strcat (gimple_stmt_iterator *gsi, tree dst, tree src) gimple_seq stmts = NULL, stmts2; gimple *repl = gimple_build_call (strlen_fn, 1, dst); gimple_set_location (repl, loc); - newdst = create_tmp_reg_or_ssa_name (size_type_node); + newdst = make_ssa_name (size_type_node); gimple_call_set_lhs (repl, newdst); gimple_seq_add_stmt_without_update (&stmts, repl); @@ -2660,7 +2648,7 @@ gimple_load_first_char (location_t loc, tree str, gimple_seq *stmts) tree temp = fold_build2_loc (loc, MEM_REF, cst_uchar_node, str, off0); gassign *stmt = gimple_build_assign (NULL_TREE, temp); - var = create_tmp_reg_or_ssa_name (cst_uchar_node, stmt); + var = make_ssa_name (cst_uchar_node, stmt); gimple_assign_set_lhs (stmt, var); gimple_seq_add_stmt_without_update (stmts, stmt); @@ -2831,7 +2819,7 @@ gimple_fold_builtin_string_compare (gimple_stmt_iterator *gsi) if (lhs) { - tree c = create_tmp_reg_or_ssa_name (integer_type_node); + tree c = make_ssa_name (integer_type_node); stmt = gimple_build_assign (c, NOP_EXPR, var); gimple_seq_add_stmt_without_update (&stmts, stmt); @@ -2853,11 +2841,11 @@ gimple_fold_builtin_string_compare (gimple_stmt_iterator *gsi) if (lhs) { - tree c1 = create_tmp_reg_or_ssa_name (integer_type_node); + tree c1 = make_ssa_name (integer_type_node); gassign *convert1 = gimple_build_assign (c1, NOP_EXPR, temp1); gimple_seq_add_stmt_without_update (&stmts, convert1); - tree c2 = create_tmp_reg_or_ssa_name (integer_type_node); + tree c2 = make_ssa_name (integer_type_node); gassign *convert2 = gimple_build_assign (c2, NOP_EXPR, temp2); gimple_seq_add_stmt_without_update (&stmts, convert2); @@ -4097,6 +4085,40 @@ gimple_fold_builtin_omp_is_initial_device (gimple_stmt_iterator *gsi) return false; } +/* omp_get_initial_device was in OpenMP 5.0/5.1 explicitly and in + 5.0 implicitly the same as omp_get_num_devices; since 6.0 it is + unspecified whether -1 or omp_get_num_devices() is returned. For + better backward compatibility, use omp_get_num_devices() on the + host - and -1 on the device (where the result is unspecified). */ + +static bool +gimple_fold_builtin_omp_get_initial_device (gimple_stmt_iterator *gsi) +{ +#if ACCEL_COMPILER + replace_call_with_value (gsi, build_int_cst (integer_type_node, -1)); +#else + if (!ENABLE_OFFLOADING) + replace_call_with_value (gsi, integer_zero_node); + else + { + tree fn = builtin_decl_explicit (BUILT_IN_OMP_GET_NUM_DEVICES); + gcall *repl = gimple_build_call (fn, 0); + replace_call_with_call_and_fold (gsi, repl); + } +#endif + return true; +} + +static bool +gimple_fold_builtin_omp_get_num_devices (gimple_stmt_iterator *gsi) +{ + if (!ENABLE_OFFLOADING) + { + replace_call_with_value (gsi, integer_zero_node); + return true; + } + return false; +} /* Fold a call to __builtin_acc_on_device. */ @@ -5341,6 +5363,12 @@ gimple_fold_builtin (gimple_stmt_iterator *gsi) case BUILT_IN_OMP_IS_INITIAL_DEVICE: return gimple_fold_builtin_omp_is_initial_device (gsi); + case BUILT_IN_OMP_GET_INITIAL_DEVICE: + return gimple_fold_builtin_omp_get_initial_device (gsi); + + case BUILT_IN_OMP_GET_NUM_DEVICES: + return gimple_fold_builtin_omp_get_num_devices (gsi); + case BUILT_IN_REALLOC: return gimple_fold_builtin_realloc (gsi); @@ -10647,7 +10675,7 @@ gimple_build (gimple_stmt_iterator *gsi, gsi->bb ? follow_all_ssa_edges : gimple_build_valueize); if (!res) { - res = create_tmp_reg_or_ssa_name (type); + res = make_ssa_name (type); gimple *stmt; if (code == REALPART_EXPR || code == IMAGPART_EXPR @@ -10679,7 +10707,7 @@ gimple_build (gimple_stmt_iterator *gsi, gsi->bb ? follow_all_ssa_edges : gimple_build_valueize); if (!res) { - res = create_tmp_reg_or_ssa_name (type); + res = make_ssa_name (type); gimple *stmt = gimple_build_assign (res, code, op0, op1); gimple_set_location (stmt, loc); gimple_seq_add_stmt_without_update (&seq, stmt); @@ -10706,7 +10734,7 @@ gimple_build (gimple_stmt_iterator *gsi, gsi->bb ? follow_all_ssa_edges : gimple_build_valueize); if (!res) { - res = create_tmp_reg_or_ssa_name (type); + res = make_ssa_name (type); gimple *stmt; if (code == BIT_FIELD_REF) stmt = gimple_build_assign (res, code, @@ -10742,7 +10770,7 @@ gimple_build (gimple_stmt_iterator *gsi, } if (!VOID_TYPE_P (type)) { - res = create_tmp_reg_or_ssa_name (type); + res = make_ssa_name (type); gimple_call_set_lhs (stmt, res); } gimple_set_location (stmt, loc); @@ -10777,7 +10805,7 @@ gimple_build (gimple_stmt_iterator *gsi, } if (!VOID_TYPE_P (type)) { - res = create_tmp_reg_or_ssa_name (type); + res = make_ssa_name (type); gimple_call_set_lhs (stmt, res); } gimple_set_location (stmt, loc); @@ -10814,7 +10842,7 @@ gimple_build (gimple_stmt_iterator *gsi, } if (!VOID_TYPE_P (type)) { - res = create_tmp_reg_or_ssa_name (type); + res = make_ssa_name (type); gimple_call_set_lhs (stmt, res); } gimple_set_location (stmt, loc); @@ -10852,7 +10880,7 @@ gimple_build (gimple_stmt_iterator *gsi, } if (!VOID_TYPE_P (type)) { - res = create_tmp_reg_or_ssa_name (type); + res = make_ssa_name (type); gimple_call_set_lhs (stmt, res); } gimple_set_location (stmt, loc); |