3 * File name: ir/ana/field_temperature.c
4 * Purpose: Compute an estimate of field temperature, i.e., field access heuristic.
5 * Author: Goetz Lindenmaier
9 * Copyright: (c) 2004 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
13 #include "field_temperature.h"
16 #include "irgraph_t.h"
23 /* *************************************************************************** */
24 /* initialize, global variables. */
25 /* *************************************************************************** */
27 /* A list of Load and Store operations that have no analyseable address. */
28 static ir_node **unrecognized_access = NULL;
30 static void add_unrecognized_access(ir_node *n) {
31 ARR_APP1(ir_node *, unrecognized_access, n);
34 /* *************************************************************************** */
35 /* Access routines for entities */
36 /* *************************************************************************** */
38 int get_entity_n_accesses(entity *ent) {
39 assert(ent && is_entity(ent));
41 if (!ent->accesses) { ent->accesses = NEW_ARR_F(ir_node *, 0); }
43 return ARR_LEN(ent->accesses);
46 ir_node *get_entity_access(entity *ent, int pos) {
47 assert(0 <= pos && pos < get_entity_n_accesses(ent));
49 return ent->accesses[pos];
52 void add_entity_access(entity *ent, ir_node *n) {
53 assert(ent && is_entity(ent));
54 assert(n && is_ir_node(n));
56 if (!ent->accesses) ent->accesses = NEW_ARR_F(ir_node *, 0);
58 ARR_APP1(ir_node *, ent->accesses, n);
61 void set_entity_access(entity *ent, int pos, ir_node *n) {
62 assert(0 <= pos && pos < get_entity_n_accesses(ent));
63 assert(n && is_ir_node(n));
65 ent->accesses[pos] = n;
69 /* *************************************************************************** */
70 /* Access routines for nodes */
71 /* *************************************************************************** */
73 /* *************************************************************************** */
74 /* Access routines for irnodes */
75 /* *************************************************************************** */
77 /* The entities that can be accessed by this Sel node. */
78 int get_Sel_n_accessed_entities(ir_node *sel) {
82 entity *get_Sel_accessed_entity(ir_node *sel, int pos) {
83 return get_Sel_entity(sel);
86 /* An addr node is a SymConst or a Sel. */
87 int get_addr_n_entities(ir_node *addr) {
90 switch (get_irn_opcode(addr)) {
92 /* Treat jack array sels? */
93 n_ents = get_Sel_n_accessed_entities(addr);
96 if (get_SymConst_kind(addr) == symconst_addr_ent) {
101 //assert(0 && "unexpected address expression");
108 /* An addr node is a SymConst or a Sel. */
109 entity *get_addr_entity(ir_node *addr, int pos) {
112 switch (get_irn_opcode(addr)) {
114 /* Treat jack array sels? */
115 assert (0 <= pos && pos < get_Sel_n_accessed_entities(addr));
116 ent = get_Sel_accessed_entity(addr, pos);
119 if (get_SymConst_kind(addr) == symconst_addr_ent) {
121 ent = get_SymConst_entity(addr);
132 int get_irn_loop_call_depth(ir_node *n) {
133 ir_graph *irg = get_irn_irg(n);
134 return get_irg_loop_depth(irg);
137 int get_irn_loop_depth(ir_node *n) {
138 get_loop_depth(get_irn_loop(get_nodes_block(n)));
141 int get_irn_recursion_depth(ir_node *n) {
142 ir_graph *irg = get_irn_irg(n);
143 return get_irg_recursion_depth(irg);
147 /* *************************************************************************** */
149 /* *************************************************************************** */
151 int get_weighted_loop_depth(ir_node *n) {
152 int loop_call_depth = get_irn_loop_call_depth(n);
153 int loop_depth = get_irn_loop_depth(n);
154 int recursion_depth = get_irn_recursion_depth(n);
156 return loop_call_depth + loop_depth + recursion_depth;
159 /* *************************************************************************** */
161 /* *************************************************************************** */
163 void init_field_temperature(void) {
164 assert(!unrecognized_access);
165 unrecognized_access = NEW_ARR_F(ir_node *, 0);
169 void chain_accesses(ir_node *n, void *env) {
174 addr = get_memop_ptr(n);
179 n_ents = get_addr_n_entities(addr);
180 for (i = 0; i < n_ents; ++i) {
181 entity *ent = get_addr_entity(addr, i);
183 add_entity_access(ent, n);
185 add_unrecognized_access(n);
190 /* compute the field temperature. */
191 void compute_field_temperature(void) {
193 int i, n_irgs = get_irp_n_irgs();
195 init_field_temperature();
197 for (i=0; i < n_irgs; i++) {
198 current_ir_graph = get_irp_irg(i);
199 irg_walk_graph(current_ir_graph, NULL, chain_accesses, NULL);
203 /* free occupied memory, reset */
204 void free_field_temperature(void) {
205 DEL_ARR_F(unrecognized_access);
206 unrecognized_access = NULL;
211 /* *************************************************************************** */
213 /* *************************************************************************** */
216 int is_jack_rts_class(type *t) {
217 ident *name = get_type_ident(t);
219 if (id_is_prefix(new_id_from_str("java/"), name)) return 1;
220 if (id_is_prefix(new_id_from_str("["), name)) return 1;
221 if (id_is_prefix(new_id_from_str("gnu/"), name)) return 1;
222 if (id_is_prefix(new_id_from_str("java/"), name)) return 1;