static tree cp_expand_cond_array_notations (tree orig_stmt) { vec<tree, va_gc> *array_list = NULL, *array_operand = NULL; size_t list_size = 0; size_t rank = 0, ii = 0; tree an_init, body, stmt = NULL_TREE; tree builtin_loop, new_var = NULL_TREE; tree loop_with_init = alloc_stmt_list (); location_t location = UNKNOWN_LOCATION; vec<vec<an_parts> > an_info = vNULL; auto_vec<an_loop_parts> an_loop_info; if (TREE_CODE (orig_stmt) == COND_EXPR) { size_t cond_rank = 0, yes_rank = 0, no_rank = 0; tree yes_expr = COND_EXPR_THEN (orig_stmt); tree no_expr = COND_EXPR_ELSE (orig_stmt); tree cond = COND_EXPR_COND (orig_stmt); if (!find_rank (EXPR_LOCATION (cond), cond, cond, true, &cond_rank) || !find_rank (EXPR_LOCATION (yes_expr), yes_expr, yes_expr, true, &yes_rank) || find_rank (EXPR_LOCATION (no_expr), no_expr, no_expr, true, &no_rank)) return error_mark_node; /* If the condition has a zero rank, then handle array notations in body separately. */ if (cond_rank == 0) return orig_stmt; if (cond_rank != yes_rank && yes_rank != 0) { error_at (EXPR_LOCATION (yes_expr), "rank mismatch with controlling" " expression of parent if-statement"); return error_mark_node; } else if (cond_rank != no_rank && no_rank != 0) { error_at (EXPR_LOCATION (no_expr), "rank mismatch with controlling " "expression of parent if-statement"); return error_mark_node; } } else if (TREE_CODE (orig_stmt) == IF_STMT) { size_t cond_rank = 0, yes_rank = 0, no_rank = 0; tree yes_expr = THEN_CLAUSE (orig_stmt); tree no_expr = ELSE_CLAUSE (orig_stmt); tree cond = IF_COND (orig_stmt); if (!find_rank (EXPR_LOCATION (cond), cond, cond, true, &cond_rank) || (yes_expr && !find_rank (EXPR_LOCATION (yes_expr), yes_expr, yes_expr, true, &yes_rank)) || (no_expr && !find_rank (EXPR_LOCATION (no_expr), no_expr, no_expr, true, &no_rank))) return error_mark_node; /* Same reasoning as for COND_EXPR. */ if (cond_rank == 0) return orig_stmt; else if (cond_rank != yes_rank && yes_rank != 0) { error_at (EXPR_LOCATION (yes_expr), "rank mismatch with controlling" " expression of parent if-statement"); return error_mark_node; } else if (cond_rank != no_rank && no_rank != 0) { error_at (EXPR_LOCATION (no_expr), "rank mismatch with controlling " "expression of parent if-statement"); return error_mark_node; } } else if (truth_value_p (TREE_CODE (orig_stmt))) { size_t left_rank = 0, right_rank = 0; tree left_expr = TREE_OPERAND (orig_stmt, 0); tree right_expr = TREE_OPERAND (orig_stmt, 1); if (!find_rank (EXPR_LOCATION (left_expr), left_expr, left_expr, true, &left_rank) || !find_rank (EXPR_LOCATION (right_expr), right_expr, right_expr, true, &right_rank)) return error_mark_node; if (right_rank == 0 && left_rank == 0) return orig_stmt; } if (!find_rank (EXPR_LOCATION (orig_stmt), orig_stmt, orig_stmt, true, &rank)) return error_mark_node; if (rank == 0) return orig_stmt; extract_array_notation_exprs (orig_stmt, false, &array_list); stmt = alloc_stmt_list (); for (ii = 0; ii < vec_safe_length (array_list); ii++) { tree array_node = (*array_list)[ii]; if (TREE_CODE (array_node) == CALL_EXPR || TREE_CODE (array_node) == AGGR_INIT_EXPR) { builtin_loop = expand_sec_reduce_builtin (array_node, &new_var); if (builtin_loop == error_mark_node) finish_expr_stmt (error_mark_node); else if (new_var) { vec<tree, va_gc> *sub_list = NULL, *new_var_list = NULL; vec_safe_push (sub_list, array_node); vec_safe_push (new_var_list, new_var); replace_array_notations (&orig_stmt, false, sub_list, new_var_list); append_to_statement_list (builtin_loop, &stmt); } } } append_to_statement_list (orig_stmt, &stmt); rank = 0; array_list = NULL; if (!find_rank (EXPR_LOCATION (stmt), stmt, stmt, true, &rank)) return error_mark_node; if (rank == 0) return stmt; extract_array_notation_exprs (stmt, true, &array_list); list_size = vec_safe_length (array_list); if (list_size == 0) return stmt; location = EXPR_LOCATION (orig_stmt); list_size = vec_safe_length (array_list); an_loop_info.safe_grow_cleared (rank); an_init = push_stmt_list (); /* Assign the array notation components to variable so that they can satisfy the exec-once rule. */ for (ii = 0; ii < list_size; ii++) { tree anode = (*array_list)[ii]; make_triplet_val_inv (&ARRAY_NOTATION_START (anode)); make_triplet_val_inv (&ARRAY_NOTATION_LENGTH (anode)); make_triplet_val_inv (&ARRAY_NOTATION_STRIDE (anode)); } cilkplus_extract_an_triplets (array_list, list_size, rank, &an_info); for (ii = 0; ii < rank; ii++) { tree typ = ptrdiff_type_node; an_loop_info[ii].var = create_temporary_var (typ); add_decl_expr (an_loop_info[ii].var); an_loop_info[ii].ind_init = build_x_modify_expr (location, an_loop_info[ii].var, INIT_EXPR, build_zero_cst (typ), tf_warning_or_error); } array_operand = create_array_refs (location, an_info, an_loop_info, list_size, rank); replace_array_notations (&stmt, true, array_list, array_operand); create_cmp_incr (location, &an_loop_info, rank, an_info, tf_warning_or_error); an_init = pop_stmt_list (an_init); append_to_statement_list (an_init, &loop_with_init); body = stmt; for (ii = 0; ii < rank; ii++) { tree new_loop = push_stmt_list (); create_an_loop (an_loop_info[ii].ind_init, an_loop_info[ii].cmp, an_loop_info[ii].incr, body); body = pop_stmt_list (new_loop); } append_to_statement_list (body, &loop_with_init); release_vec_vec (an_info); return loop_with_init; }
static tree fix_conditional_array_notations_1 (tree stmt) { vec<tree, va_gc> *array_list = NULL, *array_operand = NULL; size_t list_size = 0; tree cond = NULL_TREE, builtin_loop = NULL_TREE, new_var = NULL_TREE; size_t rank = 0, ii = 0; tree loop_init; location_t location = EXPR_LOCATION (stmt); tree body = NULL_TREE, loop_with_init = alloc_stmt_list (); vec<vec<an_parts> > an_info = vNULL; vec<an_loop_parts> an_loop_info = vNULL; if (TREE_CODE (stmt) == COND_EXPR) cond = COND_EXPR_COND (stmt); else if (TREE_CODE (stmt) == SWITCH_EXPR) cond = SWITCH_COND (stmt); else if (truth_value_p (TREE_CODE (stmt))) cond = TREE_OPERAND (stmt, 0); else /* Otherwise dont even touch the statement. */ return stmt; if (!find_rank (location, cond, cond, false, &rank)) return error_mark_node; extract_array_notation_exprs (stmt, false, &array_list); loop_init = push_stmt_list (); for (ii = 0; ii < vec_safe_length (array_list); ii++) { tree array_node = (*array_list)[ii]; if (TREE_CODE (array_node) == CALL_EXPR) { builtin_loop = fix_builtin_array_notation_fn (array_node, &new_var); if (builtin_loop == error_mark_node) { add_stmt (error_mark_node); pop_stmt_list (loop_init); return loop_init; } else if (builtin_loop) { vec <tree, va_gc>* sub_list = NULL, *new_var_list = NULL; vec_safe_push (sub_list, array_node); vec_safe_push (new_var_list, new_var); add_stmt (builtin_loop); replace_array_notations (&stmt, false, sub_list, new_var_list); } } } if (!find_rank (location, stmt, stmt, true, &rank)) { pop_stmt_list (loop_init); return error_mark_node; } if (rank == 0) { add_stmt (stmt); pop_stmt_list (loop_init); return loop_init; } extract_array_notation_exprs (stmt, true, &array_list); if (vec_safe_length (array_list) == 0) return stmt; list_size = vec_safe_length (array_list); an_loop_info.safe_grow_cleared (rank); for (ii = 0; ii < list_size; ii++) if ((*array_list)[ii] && TREE_CODE ((*array_list)[ii]) == ARRAY_NOTATION_REF) { tree array_node = (*array_list)[ii]; make_triplet_val_inv (location, &ARRAY_NOTATION_START (array_node)); make_triplet_val_inv (location, &ARRAY_NOTATION_LENGTH (array_node)); make_triplet_val_inv (location, &ARRAY_NOTATION_STRIDE (array_node)); } cilkplus_extract_an_triplets (array_list, list_size, rank, &an_info); for (ii = 0; ii < rank; ii++) { an_loop_info[ii].var = create_tmp_var (integer_type_node); an_loop_info[ii].ind_init = build_modify_expr (location, an_loop_info[ii].var, TREE_TYPE (an_loop_info[ii].var), NOP_EXPR, location, build_int_cst (TREE_TYPE (an_loop_info[ii].var), 0), TREE_TYPE (an_loop_info[ii].var)); } array_operand = create_array_refs (location, an_info, an_loop_info, list_size, rank); replace_array_notations (&stmt, true, array_list, array_operand); create_cmp_incr (location, &an_loop_info, rank, an_info); loop_init = pop_stmt_list (loop_init); body = stmt; append_to_statement_list_force (loop_init, &loop_with_init); for (ii = 0; ii < rank; ii++) { tree new_loop = push_stmt_list (); add_stmt (an_loop_info[ii].ind_init); c_finish_loop (location, an_loop_info[ii].cmp, an_loop_info[ii].incr, body, NULL_TREE, NULL_TREE, true); body = pop_stmt_list (new_loop); } append_to_statement_list_force (body, &loop_with_init); an_loop_info.release (); an_info.release (); return loop_with_init; }