<commit_before>/*
 * Project:     libFIRM
 * File name:   ir/ir/irgmod.c
 * Purpose:     Support for ir graph modification.
 * Author:      <NAME>, <NAME>
 * Modified by: <NAME>
 * Created:
 * CVS-ID:      $Id$
 * Copyright:   (c) 1998-2003 Universitt Karlsruhe
 * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include "irvrfy.h"
#include "irflag_t.h"
#include "irgwalk.h"
#include "irnode_t.h"
#include "irgraph_t.h"
#include "irgmod.h"
#include "array.h"
#include "ircons.h"
#include "irhooks.h"
#include "iredges_t.h"
#include "irtools.h"

/* Turns a node into a "useless" Tuple.  The Tuple just forms a tuple
   from several inputs.
   This is useful if a node returning a tuple is removed, but the Projs
   extracting values from the tuple are not available. */
void
turn_into_tuple (ir_node *node, int arity)
{
  assert(node);
  set_irn_op(node, op_Tuple);
  if (get_irn_arity(node) == arity) {
    /* keep old array */
  } else {
    /* Allocate new array, don't free old in_array, it's on the obstack. */
    ir_node *block = get_nodes_block(node);
    edges_node_deleted(node, current_ir_graph);
    node->in = NEW_ARR_D(ir_node *, current_ir_graph->obst, arity+1);
    /* clear the new in array, else edge_notify tries to delete garbage */
    memset(node->in, 0, (arity+1) * sizeof(node->in[0]));
    set_nodes_block(node, block);
  }
}

/* Insert irnode `new' in place of irnode `old'
   Since `new' may be bigger than `old' replace `old'
   by an op_Id which is smaller than everything */
void
exchange (ir_node *old, ir_node *nw)
{
  hook_replace(old, nw);

  /*
   * If new outs are on, we can skip the id node creation and reroute
   * the edges from the old node to the new directly.
   */
  if (edges_activated(current_ir_graph)) {
    /* copy all dependencies from old to new */
    add_irn_deps(nw, old);

    edges_reroute(old, nw, current_ir_graph);
    edges_reroute_kind(old, nw, EDGE_KIND_DEP, current_ir_graph);
    edges_node_deleted(old, current_ir_graph);
    old->op = op_Bad;
  }<commit_msg>assert if someone tries to exchange a node with itself<commit_after>/*
 * Project:     libFIRM
 * File name:   ir/ir/irgmod.c
 * Purpose:     Support for ir graph modification.
 * Author:      <NAME>, <NAME>
 * Modified by: <NAME>
 * Created:
 * CVS-ID:      $Id$
 * Copyright:   (c) 1998-2003 Universitt Karlsruhe
 * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include "irvrfy.h"
#include "irflag_t.h"
#include "irgwalk.h"
#include "irnode_t.h"
#include "irgraph_t.h"
#include "irgmod.h"
#include "array.h"
#include "ircons.h"
#include "irhooks.h"
#include "iredges_t.h"
#include "irtools.h"

/* Turns a node into a "useless" Tuple.  The Tuple just forms a tuple
   from several inputs.
   This is useful if a node returning a tuple is removed, but the Projs
   extracting values from the tuple are not available. */
void
turn_into_tuple (ir_node *node, int arity)
{
  assert(node);
  set_irn_op(node, op_Tuple);
  if (get_irn_arity(node) == arity) {
    /* keep old array */
  } else {
    /* Allocate new array, don't free old in_array, it's on the obstack. */
    ir_node *block = get_nodes_block(node);
    edges_node_deleted(node, current_ir_graph);
    node->in = NEW_ARR_D(ir_node *, current_ir_graph->obst, arity+1);
    /* clear the new in array, else edge_notify tries to delete garbage */
    memset(node->in, 0, (arity+1) * sizeof(node->in[0]));
    set_nodes_block(node, block);
  }
}

/* Insert irnode `new' in place of irnode `old'
   Since `new' may be bigger than `old' replace `old'
   by an op_Id which is smaller than everything */
void
exchange (ir_node *old, ir_node *nw)
{
  assert(old != nw && "Exchanging node with itself is not allowed");
  hook_replace(old, nw);

  /*
   * If new outs are on, we can skip the id node creation and reroute
   * the edges from the old node to the new directly.
   */
  if (edges_activated(current_ir_graph)) {
    /* copy all dependencies from old to new */
    add_irn_deps(nw, old);

    edges_reroute(old, nw, current_ir_graph);
    edges_reroute_kind(old, nw, EDGE_KIND_DEP, current_ir_graph);
    edges_node_deleted(old, current_ir_graph);
    old->op = op_Bad;
  }
{'fraction_non_alphanumeric': 0.11886005560704356, 'fraction_numerical': 0.005560704355885079, 'mean_word_length': 3.5489989462592204, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6561219', 'n_tokens_mistral': 1589, 'n_tokens_neox': 1547, 'n_words': 484}