<commit_before>/*
 * Project:     libFIRM
 * File name:   ir/ana/field_temperature.c
 * Purpose:     Compute an estimate of field temperature, i.e., field access heuristic.
 * Author:      <NAME>
 * Modified by:
 * Created:     21.7.2004
 * CVS-ID:      $Id$
 * Copyright:   (c) 2004 Universitt Karlsruhe
 * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
 */

#include <math.h>

#include "field_temperature.h"

#include "trouts.h"
#include "execution_frequency.h"

#include "irnode_t.h"
#include "irgraph_t.h"
#include "irprog_t.h"
#include "entity_t.h"
#include "irgwalk.h"

#include "array.h"

/* *************************************************************************** */
/* initialize, global variables.                                               */
/* *************************************************************************** */

/* *************************************************************************** */
/*   Access routines for irnodes                                               */
/* *************************************************************************** */

/* The entities that can be accessed by this Sel node. */
int get_Sel_n_accessed_entities(ir_node *sel) {
  return 1;
}

entity *get_Sel_accessed_entity(ir_node *sel, int pos) {
  return get_Sel_entity(sel);
}

/* *************************************************************************** */
/* The heuristic                                                               */
/* *************************************************************************** */

int get_irn_loop_call_depth(ir_node *n) {
  ir_graph *irg = get_irn_irg(n);
  return get_irg_loop_depth(irg);
}

int get_irn_loop_depth(ir_node *n) {
  ir_loop *l = get_irn_loop(get_nodes_block(n));
  if (l)
    return get_loop_depth(l);
  else
    return 0;
}

int get_irn_recursion_depth(ir_node *n) {
  ir_graph *irg = get_irn_irg(n);
  return get_irg_recursion_depth(irg);
}


/**   @@@ the second version of the heuristic. */
int get_weighted_loop_depth(ir_node *n) {
  int loop_call_depth = get_irn_loop_call_depth(n);
  int loop_depth      = get_irn_loop_depth(n);
  int recursion_depth = get_irn_recursion_depth(n);

  return loop_call_depth + loop_depth + recursion_depth;
}


/* *************************************************************************** */
/* The 2. heuristic                                                            */
/* *************************************************************************** */

static int default_recursion_weight = 5;

/* The final evaluation of a node.  In this function we can
   adapt the heuristic.  Combine execution freqency with
   recursion depth.
   @@@ the second version of the heuristic. */
double get_irn_final_cost(ir_node *n) {
  double cost_loop   = get_irn_exec_freq(n);
  double cost_method = get_irg_method_execution_frequency(get_irn_irg(n));
  int    rec_depth   = get_irn_recursion_depth(n);
  double cost_rec    = 0;
  if (rec_depth) cost_rec = pow(default_recursion_weight, rec_depth);
  return cost_loop*(cost_method + cost_rec);
}

double get_type_estimated_n_instances(type *tp) {
  int i, n_allocs = get_type_n_allocs(tp);
  double n_instances = 0;
  for (i = 0; i < n_allocs; ++i) {
    ir_node *alloc = get_type_alloc(tp, i);
    n_instances += get_irn_final_cost(alloc);
  }
  return n_instances;
}

double get_type_estimated_mem_consumption_bytes(type *tp) {
  assert(0);
  return 0.0;
}
<commit_msg>typo fixed<commit_after>/*
 * Project:     libFIRM
 * File name:   ir/ana/field_temperature.c
 * Purpose:     Compute an estimate of field temperature, i.e., field access heuristic.
 * Author:      <NAME>
 * Modified by:
 * Created:     21.7.2004
 * CVS-ID:      $Id$
 * Copyright:   (c) 2004 <NAME>
 * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
 */

#include <math.h>

#include "field_temperature.h"

#include "trouts.h"
#include "execution_frequency.h"

#include "irnode_t.h"
#include "irgraph_t.h"
#include "irprog_t.h"
#include "entity_t.h"
#include "irgwalk.h"

#include "array.h"

/* *************************************************************************** */
/* initialize, global variables.                                               */
/* *************************************************************************** */

/* *************************************************************************** */
/*   Access routines for irnodes                                               */
/* *************************************************************************** */

/* The entities that can be accessed by this Sel node. */
int get_Sel_n_accessed_entities(ir_node *sel) {
  return 1;
}

entity *get_Sel_accessed_entity(ir_node *sel, int pos) {
  return get_Sel_entity(sel);
}

/* *************************************************************************** */
/* The heuristic                                                               */
/* *************************************************************************** */

int get_irn_loop_call_depth(ir_node *n) {
  ir_graph *irg = get_irn_irg(n);
  return get_irg_loop_depth(irg);
}

int get_irn_loop_depth(ir_node *n) {
  ir_loop *l = get_irn_loop(get_nodes_block(n));
  if (l)
    return get_loop_depth(l);
  else
    return 0;
}

int get_irn_recursion_depth(ir_node *n) {
  ir_graph *irg = get_irn_irg(n);
  return get_irg_recursion_depth(irg);
}


/**   @@@ the second version of the heuristic. */
int get_weighted_loop_depth(ir_node *n) {
  int loop_call_depth = get_irn_loop_call_depth(n);
  int loop_depth      = get_irn_loop_depth(n);
  int recursion_depth = get_irn_recursion_depth(n);

  return loop_call_depth + loop_depth + recursion_depth;
}


/* *************************************************************************** */
/* The 2. heuristic                                                            */
/* *************************************************************************** */

static int default_recursion_weight = 5;

/* The final evaluation of a node.  In this function we can
   adapt the heuristic.  Combine execution frequency with
   recursion depth.
   @@@ the second version of the heuristic. */
double get_irn_final_cost(ir_node *n) {
  double cost_loop   = get_irn_exec_freq(n);
  double cost_method = get_irg_method_execution_frequency(get_irn_irg(n));
  int    rec_depth   = get_irn_recursion_depth(n);
  double cost_rec    = 0;
  if (rec_depth) cost_rec = pow(default_recursion_weight, rec_depth);
  return cost_loop*(cost_method + cost_rec);
}

double get_type_estimated_n_instances(type *tp) {
  int i, n_allocs = get_type_n_allocs(tp);
  double n_instances = 0;
  for (i = 0; i < n_allocs; ++i) {
    ir_node *alloc = get_type_alloc(tp, i);
    n_instances += get_irn_final_cost(alloc);
  }
  return n_instances;
}

double get_type_estimated_mem_consumption_bytes(type *tp) {
  assert(0);
  return 0.0;
}

{'fraction_non_alphanumeric': 0.2665121668597914, 'fraction_numerical': 0.00608342989571263, 'mean_word_length': 3.563780568407138, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2729898', 'n_tokens_mistral': 2240, 'n_tokens_neox': 2069, 'n_words': 456}