<commit_before>/*
 * Project:     libFIRM
 * File name:   ir/opt/opt_polymorphy
 * Purpose:     Optimize polymorphic Sel nodes.
 * Author:      <NAME>, <NAME>
 * Created:
 * CVS-ID:      $Id$
 * Copyright:   (c) 2005 Universitt Karlsruhe
 * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
 */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "irprog_t.h"
#include "entity_t.h"
#include "type_t.h"
#include "irop.h"
#include "irnode_t.h"
#include "ircons.h"

#include "iropt_dbg.h"
#include "irflag_t.h"

/**
 * Checks if a graph allocates new memory and returns the
 * type of the newly allocated entity.
 * Returns NULL if the graph did not represent an Allocation.
 *
 * The default implementation hecks for Alloc nodes only.
 */
ir_type *default_firm_get_Alloc(ir_node *n) {
  n = skip_Proj(n);
  if (get_irn_op(n) == op_Alloc) {
    return get_Alloc_type(n);
  }
  return NULL;
}

typedef ir_type *(*get_Alloc_func)(ir_node *n);

/** The get_Alloc function */
static get_Alloc_func firm_get_Alloc = default_firm_get_Alloc;

/** Set a new get_Alloc_func and returns the old one. */
get_Alloc_func firm_set_Alloc_func(get_Alloc_func newf) {
  get_Alloc_func old = firm_get_Alloc;
  firm_get_Alloc = newf;
  return old;
}

/** Return dynamic type of ptr.
 *
 * If we can deduct the dynamic type from the firm nodes
 * by a limited test we return the dynamic type.  Else
 * we return unknown_type.
 *
 * If we find a dynamic type this means that the pointer always points
 * to an object of this type during runtime.   We resolved polymorphy.
 */
static ir_type *get_dynamic_type(ir_node *ptr) {
  ir_type *tp;

  /* skip Cast and Confirm nodes */
  for (;;) {
    opcode code = get_irn_opcode(ptr);

    switch (code) {
    case iro_Cast:
      ptr = get_Cast_op(ptr);
      continue;
    case iro_Confirm:
      ptr = get_Confirm_value(ptr);
      continue;
    default:
      ;
    }
    break;
  }
  tp = (*firm_get_Alloc)(ptr);
  return tp ? tp : firm_unknown_type;
}

/**
 * Check, if a entity is final, i.e. is not anymore overridden.
 */
static is_final_ent(entity *ent) {
  if (get_entity_final(ent)) {
    /* not possible to override this entity. */
    return 1;
  }
  if (get_opt_closed_world() && get_entity_n_overwrittenby(ent) == 0) {
    /* we have a closed world, so simply check how often it was
       overridden. */
    return 1;
  }
  return 0;
}

/*
 * Transform Sel[method] to SymC[method] if possible.
 */
ir_node *transform_node_Sel(ir_node *node)<commit_msg>added missing function return type<commit_after>/*
 * Project:     libFIRM
 * File name:   ir/opt/opt_polymorphy
 * Purpose:     Optimize polymorphic Sel nodes.
 * Author:      <NAME>, <NAME>
 * Created:
 * CVS-ID:      $Id$
 * Copyright:   (c) 2005 Universitt Karlsruhe
 * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
 */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "irprog_t.h"
#include "entity_t.h"
#include "type_t.h"
#include "irop.h"
#include "irnode_t.h"
#include "ircons.h"

#include "iropt_dbg.h"
#include "irflag_t.h"

/**
 * Checks if a graph allocates new memory and returns the
 * type of the newly allocated entity.
 * Returns NULL if the graph did not represent an Allocation.
 *
 * The default implementation hecks for Alloc nodes only.
 */
ir_type *default_firm_get_Alloc(ir_node *n) {
  n = skip_Proj(n);
  if (get_irn_op(n) == op_Alloc) {
    return get_Alloc_type(n);
  }
  return NULL;
}

typedef ir_type *(*get_Alloc_func)(ir_node *n);

/** The get_Alloc function */
static get_Alloc_func firm_get_Alloc = default_firm_get_Alloc;

/** Set a new get_Alloc_func and returns the old one. */
get_Alloc_func firm_set_Alloc_func(get_Alloc_func newf) {
  get_Alloc_func old = firm_get_Alloc;
  firm_get_Alloc = newf;
  return old;
}

/** Return dynamic type of ptr.
 *
 * If we can deduct the dynamic type from the firm nodes
 * by a limited test we return the dynamic type.  Else
 * we return unknown_type.
 *
 * If we find a dynamic type this means that the pointer always points
 * to an object of this type during runtime.   We resolved polymorphy.
 */
static ir_type *get_dynamic_type(ir_node *ptr) {
  ir_type *tp;

  /* skip Cast and Confirm nodes */
  for (;;) {
    opcode code = get_irn_opcode(ptr);

    switch (code) {
    case iro_Cast:
      ptr = get_Cast_op(ptr);
      continue;
    case iro_Confirm:
      ptr = get_Confirm_value(ptr);
      continue;
    default:
      ;
    }
    break;
  }
  tp = (*firm_get_Alloc)(ptr);
  return tp ? tp : firm_unknown_type;
}

/**
 * Check, if a entity is final, i.e. is not anymore overridden.
 */
static int is_final_ent(entity *ent) {
  if (get_entity_final(ent)) {
    /* not possible to override this entity. */
    return 1;
  }
  if (get_opt_closed_world() && get_entity_n_overwrittenby(ent) == 0) {
    /* we have a closed world, so simply check how often it was
       overridden. */
    return 1;
  }
  return 0;
}

/*
 * Transform Sel[method] to SymC[method] if possible.
 */
ir_node *transform_node_Sel(ir_node *node)
{'fraction_non_alphanumeric': 0.10717816887482698, 'fraction_numerical': 0.0031639311844967374, 'mean_word_length': 3.3083475298126066, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '81852', 'n_tokens_mistral': 1822, 'n_tokens_neox': 1766, 'n_words': 546}