diff options
Diffstat (limited to 'gcc/gimple-fold.cc')
-rw-r--r-- | gcc/gimple-fold.cc | 107 |
1 files changed, 66 insertions, 41 deletions
diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc index b74fb8b..c5c8e22 100644 --- a/gcc/gimple-fold.cc +++ b/gcc/gimple-fold.cc @@ -191,19 +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) -{ - if (gimple_in_ssa_p (cfun)) - return make_ssa_name (type, stmt); - else - return create_tmp_reg (type); -} - /* 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. */ @@ -1041,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); @@ -1311,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); @@ -2284,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); @@ -2430,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); @@ -2663,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); @@ -2834,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); @@ -2856,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); @@ -4100,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. */ @@ -5344,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); @@ -6020,7 +6045,7 @@ has_use_on_stmt (tree name, gimple *stmt) /* Add the lhs of each statement of SEQ to DCE_WORKLIST. */ -static void +void mark_lhs_in_seq_for_dce (bitmap dce_worklist, gimple_seq seq) { if (!dce_worklist) @@ -10092,19 +10117,21 @@ fold_const_aggregate_ref_1 (tree t, tree (*valueize) (tree)) base = get_ref_base_and_extent (t, &offset, &size, &max_size, &reverse); ctor = get_base_constructor (base, &offset, valueize); + /* We cannot determine ctor. */ + if (!ctor) + return NULL_TREE; /* Empty constructor. Always fold to 0. */ if (ctor == error_mark_node) return build_zero_cst (TREE_TYPE (t)); - /* We do not know precise address. */ + /* We do not know precise access. */ if (!known_size_p (max_size) || maybe_ne (max_size, size)) return NULL_TREE; - /* We cannot determine ctor. */ - if (!ctor) - return NULL_TREE; - /* Out of bound array access. Value is undefined, but don't fold. */ if (maybe_lt (offset, 0)) return NULL_TREE; + /* Access with reverse storage order. */ + if (reverse) + return NULL_TREE; tem = fold_ctor_reference (TREE_TYPE (t), ctor, offset, size, base); if (tem) @@ -10124,7 +10151,6 @@ fold_const_aggregate_ref_1 (tree t, tree (*valueize) (tree)) && offset.is_constant (&coffset) && (coffset % BITS_PER_UNIT != 0 || csize % BITS_PER_UNIT != 0) - && !reverse && BYTES_BIG_ENDIAN == WORDS_BIG_ENDIAN) { poly_int64 bitoffset; @@ -10251,13 +10277,12 @@ gimple_get_virt_method_for_vtable (HOST_WIDE_INT token, access_index = offset / BITS_PER_UNIT / elt_size; gcc_checking_assert (offset % (elt_size * BITS_PER_UNIT) == 0); - /* The C++ FE can now produce indexed fields, and we check if the indexes - match. */ + /* This code makes an assumption that there are no + indexed fileds produced by C++ FE, so we can directly index the array. */ if (access_index < CONSTRUCTOR_NELTS (init)) { fn = CONSTRUCTOR_ELT (init, access_index)->value; - tree idx = CONSTRUCTOR_ELT (init, access_index)->index; - gcc_checking_assert (!idx || tree_to_uhwi (idx) == access_index); + gcc_checking_assert (!CONSTRUCTOR_ELT (init, access_index)->index); STRIP_NOPS (fn); } else @@ -10650,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 @@ -10682,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); @@ -10709,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, @@ -10745,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); @@ -10780,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); @@ -10817,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); @@ -10855,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); |