- struct opt_pass *pass = *pass_list, *prev_pass = NULL;
- bool success = false;
-
- for ( ; pass; prev_pass = pass, pass = pass->next)
- {
- /* Check if the current pass is of the same type as the new pass and
- matches the name and the instance number of the reference pass. */
- if (pass->type == plugin_pass_info->pass->type
- && pass->name
- && !strcmp (pass->name, plugin_pass_info->reference_pass_name)
- && ((plugin_pass_info->ref_pass_instance_number == 0)
- || (plugin_pass_info->ref_pass_instance_number ==
- pass->static_pass_number)
- || (plugin_pass_info->ref_pass_instance_number == 1
- && pass->todo_flags_start & TODO_mark_first_instance)))
- {
- struct opt_pass *new_pass = plugin_pass_info->pass;
- struct pass_list_node *new_pass_node;
-
- /* The following code (if-statement) is adopted from next_pass_1. */
- if (new_pass->static_pass_number)
- {
- new_pass = XNEW (struct opt_pass);
- memcpy (new_pass, plugin_pass_info->pass, sizeof (*new_pass));
- new_pass->next = NULL;
-
- new_pass->todo_flags_start &= ~TODO_mark_first_instance;
-
- plugin_pass_info->pass->static_pass_number -= 1;
- new_pass->static_pass_number =
- -plugin_pass_info->pass->static_pass_number;
- }
- else
- {
- new_pass->todo_flags_start |= TODO_mark_first_instance;
- new_pass->static_pass_number = -1;
- }
-
- /* Insert the new pass instance based on the positioning op. */
- switch (plugin_pass_info->pos_op)
- {
- case PASS_POS_INSERT_AFTER:
- new_pass->next = pass->next;
- pass->next = new_pass;
- break;
- case PASS_POS_INSERT_BEFORE:
- new_pass->next = pass;
- if (prev_pass)
- prev_pass->next = new_pass;
- else
- *pass_list = new_pass;
- break;
- case PASS_POS_REPLACE:
- new_pass->next = pass->next;
- if (prev_pass)
- prev_pass->next = new_pass;
- else
- *pass_list = new_pass;
- new_pass->sub = pass->sub;
- new_pass->tv_id = pass->tv_id;
- pass = new_pass;
- break;
- default:
- error ("Invalid pass positioning operation");
- return false;
- }
-
- /* Save the newly added pass (instance) in the added_pass_nodes
- list so that we can register its dump file later. Note that
- we cannot register the dump file now because doing so will modify
- the static_pass_number of the opt_pass object and therefore
- mess up the dump file name of future instances. */
- new_pass_node = XCNEW (struct pass_list_node);
- new_pass_node->pass = new_pass;
- if (!added_pass_nodes)
- added_pass_nodes = new_pass_node;
- else
- prev_added_pass_node->next = new_pass_node;
- prev_added_pass_node = new_pass_node;
-
- success = true;
- }
-
- if (pass->sub && position_pass (plugin_pass_info, &pass->sub))
- success = true;
- }
-
- return success;