void gimple_regimplify_operands (gimple stmt, gimple_stmt_iterator *gsi_p) { size_t i, num_ops; tree lhs; gimple_seq pre = NULL; gimple post_stmt = NULL; push_gimplify_context (gimple_in_ssa_p (cfun)); switch (gimple_code (stmt)) { case GIMPLE_COND: gimplify_expr (gimple_cond_lhs_ptr (stmt), &pre, NULL, is_gimple_val, fb_rvalue); gimplify_expr (gimple_cond_rhs_ptr (stmt), &pre, NULL, is_gimple_val, fb_rvalue); break; case GIMPLE_SWITCH: gimplify_expr (gimple_switch_index_ptr (stmt), &pre, NULL, is_gimple_val, fb_rvalue); break; case GIMPLE_OMP_ATOMIC_LOAD: gimplify_expr (gimple_omp_atomic_load_rhs_ptr (stmt), &pre, NULL, is_gimple_val, fb_rvalue); break; case GIMPLE_ASM: { size_t i, noutputs = gimple_asm_noutputs (stmt); const char *constraint, **oconstraints; bool allows_mem, allows_reg, is_inout; oconstraints = (const char **) alloca ((noutputs) * sizeof (const char *)); for (i = 0; i < noutputs; i++) { tree op = gimple_asm_output_op (stmt, i); constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op))); oconstraints[i] = constraint; parse_output_constraint (&constraint, i, 0, 0, &allows_mem, &allows_reg, &is_inout); gimplify_expr (&TREE_VALUE (op), &pre, NULL, is_inout ? is_gimple_min_lval : is_gimple_lvalue, fb_lvalue | fb_mayfail); } for (i = 0; i < gimple_asm_ninputs (stmt); i++) { tree op = gimple_asm_input_op (stmt, i); constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op))); parse_input_constraint (&constraint, 0, 0, noutputs, 0, oconstraints, &allows_mem, &allows_reg); if (TREE_ADDRESSABLE (TREE_TYPE (TREE_VALUE (op))) && allows_mem) allows_reg = 0; if (!allows_reg && allows_mem) gimplify_expr (&TREE_VALUE (op), &pre, NULL, is_gimple_lvalue, fb_lvalue | fb_mayfail); else gimplify_expr (&TREE_VALUE (op), &pre, NULL, is_gimple_asm_val, fb_rvalue); } } break; default: /* NOTE: We start gimplifying operands from last to first to make sure that side-effects on the RHS of calls, assignments and ASMs are executed before the LHS. The ordering is not important for other statements. */ num_ops = gimple_num_ops (stmt); for (i = num_ops; i > 0; i--) { tree op = gimple_op (stmt, i - 1); if (op == NULL_TREE) continue; if (i == 1 && (is_gimple_call (stmt) || is_gimple_assign (stmt))) gimplify_expr (&op, &pre, NULL, is_gimple_lvalue, fb_lvalue); else if (i == 2 && is_gimple_assign (stmt) && num_ops == 2 && get_gimple_rhs_class (gimple_expr_code (stmt)) == GIMPLE_SINGLE_RHS) gimplify_expr (&op, &pre, NULL, rhs_predicate_for (gimple_assign_lhs (stmt)), fb_rvalue); else if (i == 2 && is_gimple_call (stmt)) { if (TREE_CODE (op) == FUNCTION_DECL) continue; gimplify_expr (&op, &pre, NULL, is_gimple_call_addr, fb_rvalue); } else gimplify_expr (&op, &pre, NULL, is_gimple_val, fb_rvalue); gimple_set_op (stmt, i - 1, op); } lhs = gimple_get_lhs (stmt); /* If the LHS changed it in a way that requires a simple RHS, create temporary. */ if (lhs && !is_gimple_reg (lhs)) { bool need_temp = false; if (is_gimple_assign (stmt) && num_ops == 2 && get_gimple_rhs_class (gimple_expr_code (stmt)) == GIMPLE_SINGLE_RHS) gimplify_expr (gimple_assign_rhs1_ptr (stmt), &pre, NULL, rhs_predicate_for (gimple_assign_lhs (stmt)), fb_rvalue); else if (is_gimple_reg (lhs)) { if (is_gimple_reg_type (TREE_TYPE (lhs))) { if (is_gimple_call (stmt)) { i = gimple_call_flags (stmt); if ((i & ECF_LOOPING_CONST_OR_PURE) || !(i & (ECF_CONST | ECF_PURE))) need_temp = true; } if (stmt_can_throw_internal (stmt)) need_temp = true; } } else { if (is_gimple_reg_type (TREE_TYPE (lhs))) need_temp = true; else if (TYPE_MODE (TREE_TYPE (lhs)) != BLKmode) { if (is_gimple_call (stmt)) { tree fndecl = gimple_call_fndecl (stmt); if (!aggregate_value_p (TREE_TYPE (lhs), fndecl) && !(fndecl && DECL_RESULT (fndecl) && DECL_BY_REFERENCE (DECL_RESULT (fndecl)))) need_temp = true; } else need_temp = true; } } if (need_temp) { tree temp = create_tmp_reg (TREE_TYPE (lhs), NULL); if (gimple_in_ssa_p (cfun)) temp = make_ssa_name (temp, NULL); gimple_set_lhs (stmt, temp); post_stmt = gimple_build_assign (lhs, temp); } } break; } if (!gimple_seq_empty_p (pre)) gsi_insert_seq_before (gsi_p, pre, GSI_SAME_STMT); if (post_stmt) gsi_insert_after (gsi_p, post_stmt, GSI_NEW_STMT); pop_gimplify_context (NULL); }
tree walk_gimple_op (gimple *stmt, walk_tree_fn callback_op, struct walk_stmt_info *wi) { hash_set<tree> *pset = (wi) ? wi->pset : NULL; unsigned i; tree ret = NULL_TREE; switch (gimple_code (stmt)) { case GIMPLE_ASSIGN: /* Walk the RHS operands. If the LHS is of a non-renamable type or is a register variable, we may use a COMPONENT_REF on the RHS. */ if (wi) { tree lhs = gimple_assign_lhs (stmt); wi->val_only = (is_gimple_reg_type (TREE_TYPE (lhs)) && !is_gimple_reg (lhs)) || gimple_assign_rhs_class (stmt) != GIMPLE_SINGLE_RHS; } for (i = 1; i < gimple_num_ops (stmt); i++) { ret = walk_tree (gimple_op_ptr (stmt, i), callback_op, wi, pset); if (ret) return ret; } /* Walk the LHS. If the RHS is appropriate for a memory, we may use a COMPONENT_REF on the LHS. */ if (wi) { /* If the RHS is of a non-renamable type or is a register variable, we may use a COMPONENT_REF on the LHS. */ tree rhs1 = gimple_assign_rhs1 (stmt); wi->val_only = (is_gimple_reg_type (TREE_TYPE (rhs1)) && !is_gimple_reg (rhs1)) || gimple_assign_rhs_class (stmt) != GIMPLE_SINGLE_RHS; wi->is_lhs = true; } ret = walk_tree (gimple_op_ptr (stmt, 0), callback_op, wi, pset); if (ret) return ret; if (wi) { wi->val_only = true; wi->is_lhs = false; } break; case GIMPLE_CALL: if (wi) { wi->is_lhs = false; wi->val_only = true; } ret = walk_tree (gimple_call_chain_ptr (as_a <gcall *> (stmt)), callback_op, wi, pset); if (ret) return ret; ret = walk_tree (gimple_call_fn_ptr (stmt), callback_op, wi, pset); if (ret) return ret; for (i = 0; i < gimple_call_num_args (stmt); i++) { if (wi) wi->val_only = is_gimple_reg_type (TREE_TYPE (gimple_call_arg (stmt, i))); ret = walk_tree (gimple_call_arg_ptr (stmt, i), callback_op, wi, pset); if (ret) return ret; } if (gimple_call_lhs (stmt)) { if (wi) { wi->is_lhs = true; wi->val_only = is_gimple_reg_type (TREE_TYPE (gimple_call_lhs (stmt))); } ret = walk_tree (gimple_call_lhs_ptr (stmt), callback_op, wi, pset); if (ret) return ret; } if (wi) { wi->is_lhs = false; wi->val_only = true; } break; case GIMPLE_CATCH: ret = walk_tree (gimple_catch_types_ptr (as_a <gcatch *> (stmt)), callback_op, wi, pset); if (ret) return ret; break; case GIMPLE_EH_FILTER: ret = walk_tree (gimple_eh_filter_types_ptr (stmt), callback_op, wi, pset); if (ret) return ret; break; case GIMPLE_ASM: ret = walk_gimple_asm (as_a <gasm *> (stmt), callback_op, wi); if (ret) return ret; break; case GIMPLE_OMP_CONTINUE: { gomp_continue *cont_stmt = as_a <gomp_continue *> (stmt); ret = walk_tree (gimple_omp_continue_control_def_ptr (cont_stmt), callback_op, wi, pset); if (ret) return ret; ret = walk_tree (gimple_omp_continue_control_use_ptr (cont_stmt), callback_op, wi, pset); if (ret) return ret; } break; case GIMPLE_OMP_CRITICAL: { gomp_critical *omp_stmt = as_a <gomp_critical *> (stmt); ret = walk_tree (gimple_omp_critical_name_ptr (omp_stmt), callback_op, wi, pset); if (ret) return ret; ret = walk_tree (gimple_omp_critical_clauses_ptr (omp_stmt), callback_op, wi, pset); if (ret) return ret; } break; case GIMPLE_OMP_ORDERED: { gomp_ordered *omp_stmt = as_a <gomp_ordered *> (stmt); ret = walk_tree (gimple_omp_ordered_clauses_ptr (omp_stmt), callback_op, wi, pset); if (ret) return ret; } break; case GIMPLE_OMP_FOR: ret = walk_tree (gimple_omp_for_clauses_ptr (stmt), callback_op, wi, pset); if (ret) return ret; for (i = 0; i < gimple_omp_for_collapse (stmt); i++) { ret = walk_tree (gimple_omp_for_index_ptr (stmt, i), callback_op, wi, pset); if (ret) return ret; ret = walk_tree (gimple_omp_for_initial_ptr (stmt, i), callback_op, wi, pset); if (ret) return ret; ret = walk_tree (gimple_omp_for_final_ptr (stmt, i), callback_op, wi, pset); if (ret) return ret; ret = walk_tree (gimple_omp_for_incr_ptr (stmt, i), callback_op, wi, pset); if (ret) return ret; } break; case GIMPLE_OMP_PARALLEL: { gomp_parallel *omp_par_stmt = as_a <gomp_parallel *> (stmt); ret = walk_tree (gimple_omp_parallel_clauses_ptr (omp_par_stmt), callback_op, wi, pset); if (ret) return ret; ret = walk_tree (gimple_omp_parallel_child_fn_ptr (omp_par_stmt), callback_op, wi, pset); if (ret) return ret; ret = walk_tree (gimple_omp_parallel_data_arg_ptr (omp_par_stmt), callback_op, wi, pset); if (ret) return ret; } break; case GIMPLE_OMP_TASK: ret = walk_tree (gimple_omp_task_clauses_ptr (stmt), callback_op, wi, pset); if (ret) return ret; ret = walk_tree (gimple_omp_task_child_fn_ptr (stmt), callback_op, wi, pset); if (ret) return ret; ret = walk_tree (gimple_omp_task_data_arg_ptr (stmt), callback_op, wi, pset); if (ret) return ret; ret = walk_tree (gimple_omp_task_copy_fn_ptr (stmt), callback_op, wi, pset); if (ret) return ret; ret = walk_tree (gimple_omp_task_arg_size_ptr (stmt), callback_op, wi, pset); if (ret) return ret; ret = walk_tree (gimple_omp_task_arg_align_ptr (stmt), callback_op, wi, pset); if (ret) return ret; break; case GIMPLE_OMP_SECTIONS: ret = walk_tree (gimple_omp_sections_clauses_ptr (stmt), callback_op, wi, pset); if (ret) return ret; ret = walk_tree (gimple_omp_sections_control_ptr (stmt), callback_op, wi, pset); if (ret) return ret; break; case GIMPLE_OMP_SINGLE: ret = walk_tree (gimple_omp_single_clauses_ptr (stmt), callback_op, wi, pset); if (ret) return ret; break; case GIMPLE_OMP_TARGET: { gomp_target *omp_stmt = as_a <gomp_target *> (stmt); ret = walk_tree (gimple_omp_target_clauses_ptr (omp_stmt), callback_op, wi, pset); if (ret) return ret; ret = walk_tree (gimple_omp_target_child_fn_ptr (omp_stmt), callback_op, wi, pset); if (ret) return ret; ret = walk_tree (gimple_omp_target_data_arg_ptr (omp_stmt), callback_op, wi, pset); if (ret) return ret; } break; case GIMPLE_OMP_TEAMS: ret = walk_tree (gimple_omp_teams_clauses_ptr (stmt), callback_op, wi, pset); if (ret) return ret; break; case GIMPLE_OMP_ATOMIC_LOAD: { gomp_atomic_load *omp_stmt = as_a <gomp_atomic_load *> (stmt); ret = walk_tree (gimple_omp_atomic_load_lhs_ptr (omp_stmt), callback_op, wi, pset); if (ret) return ret; ret = walk_tree (gimple_omp_atomic_load_rhs_ptr (omp_stmt), callback_op, wi, pset); if (ret) return ret; } break; case GIMPLE_OMP_ATOMIC_STORE: { gomp_atomic_store *omp_stmt = as_a <gomp_atomic_store *> (stmt); ret = walk_tree (gimple_omp_atomic_store_val_ptr (omp_stmt), callback_op, wi, pset); if (ret) return ret; } break; case GIMPLE_TRANSACTION: ret = walk_tree (gimple_transaction_label_ptr ( as_a <gtransaction *> (stmt)), callback_op, wi, pset); if (ret) return ret; break; case GIMPLE_OMP_RETURN: ret = walk_tree (gimple_omp_return_lhs_ptr (stmt), callback_op, wi, pset); if (ret) return ret; break; /* Tuples that do not have operands. */ case GIMPLE_NOP: case GIMPLE_RESX: case GIMPLE_PREDICT: break; default: { enum gimple_statement_structure_enum gss; gss = gimple_statement_structure (stmt); if (gss == GSS_WITH_OPS || gss == GSS_WITH_MEM_OPS) for (i = 0; i < gimple_num_ops (stmt); i++) { ret = walk_tree (gimple_op_ptr (stmt, i), callback_op, wi, pset); if (ret) return ret; } } break; } return NULL_TREE; }