#include "irgwalk.h"
#include "irloop_t.h"
#include "irflag_t.h"
+#include "ircons.h"
+#include "typewalk.h"
static void clear_link(ir_node * node, void * env) {
set_irn_link(node, NULL);
}
}
+static void make_entity_to_description(type_or_ent *tore, void *env) {
+ if (get_kind(tore) == k_entity) {
+ entity *ent = (entity *)tore;
+ if ((is_method_type(get_entity_type(ent))) &&
+ (get_entity_peculiarity(ent) != peculiarity_description) &&
+ (get_entity_visibility(ent) != visibility_external_allocated) ) {
+ entity *impl = get_SymConst_entity(get_atomic_ent_value(ent));
+ if (get_entity_link(impl) != env) {
+ set_entity_peculiarity(ent, peculiarity_description);
+ //set_atomic_ent_value(ent, new_r_Const(get_const_code_irg(), get_irg_start_block(get_const_code_irg()),
+ // mode_P, get_tarval_null(mode_P)));
+ }
+ }
+ }
+}
/* garbage collect methods: mark and remove */
void gc_irgs(int n_keep, entity ** keep_arr) {
- void * MARK = &MARK;
+ void * MARK = &MARK; /* @@@ gefaehrlich!!! Aber wir markieren hoechstens zu viele ... */
int i;
if (!get_opt_dead_method_elimination()) return;
- /* mark */
+ /* Mark entities that are alive. */
if (n_keep > 0) {
entity ** marked = NEW_ARR_F(entity *, n_keep);
for (i = 0; i < n_keep; ++i) {
marked[i] = keep_arr[i];
set_entity_link(marked[i], MARK);
+ if (get_opt_dead_method_elimination_verbose() && get_firm_verbosity() > 2) {
+ printf("dead method elimination: method %s kept alive.\n", get_entity_ld_name(marked[i]));
+ }
}
for (i = 0; i < ARR_LEN(marked); ++i) {
/* check for extern methods, these don't have an IRG */
if (ent && get_entity_irg(ent) && get_entity_link(ent) != MARK) {
set_entity_link(ent, MARK);
ARR_APP1(entity *, marked, ent);
+ if (get_opt_dead_method_elimination_verbose() && get_firm_verbosity() > 2) {
+ printf("dead method elimination: method %s can be called from Call %ld: kept alive.\n",
+ get_entity_ld_name(ent), get_irn_node_nr(node));
+ }
}
}
}
}
/* clean */
+ type_walk(make_entity_to_description, NULL, MARK);
for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
ir_graph * irg = get_irp_irg(i);
entity * ent = get_irg_entity(irg);
if ((get_entity_visibility(ent) == visibility_local) && (get_entity_link(ent) != MARK)) {
remove_irp_irg(irg);
set_entity_peculiarity(ent, peculiarity_description);
- if (get_opt_dead_method_elimination_verbose()) {
+ if (get_opt_dead_method_elimination_verbose() && get_firm_verbosity() > 1) {
printf("dead method elimination: freeing method %s\n", get_entity_ld_name(ent));
}
}
};
static struct induct_var_info ivi;
+/** Counter for verbose information about optimization. */
+static int n_reduced_expressions;
/** Detect basic iteration variables.
*
return info;
}
+/* from irdump.c */
+const char *get_irg_dump_name(ir_graph *irg);
+
/**
* Reduce a node.
*
* @param *env Free environment pointer.
*
* The node for reduce mus be in a loop whit *phi and *add.The *phi node muss
- * have 2 predecessors a Const and a Add node. The predecessors of Add node muss * be *phi and a Const node. The nodes a, b, c muss be Const with dom_depth < * phi.
+ * have 2 predecessors a Const and a Add node. The predecessors of Add node muss
+ * be *phi and a Const node. The nodes a, b, c muss be Const with dom_depth <
+ * phi.
*/
-
void reduce_a_node(ir_node *strong, void *env) {
ir_node *phi, *l, *r, *c;
ir_op *op_strong;
if (get_Block_dom_depth(get_nodes_block(c)) >=
get_Block_dom_depth(get_nodes_block(phi))) return;
- if (get_opt_strength_red_verbosity() == 2) {
+ /* Some statistics and user information ... */
+ if (get_opt_strength_red_verbosity() && get_firm_verbosity() > 1) {
printf("Reducing node: "); DDMN(strong);
printf(" iter var is "); DDMN(ivi.op);
printf(" in graph "); DDMG(current_ir_graph);
}
+ n_reduced_expressions++;
ir_node *inc = NULL, *init = NULL, *new_phi, *in[2], *new_op = NULL, *block_init, *block_inc;
ir_node *init_block = get_nodes_block(ivi.init);
if (!get_optimize() || !get_opt_strength_red()) return;
+ n_reduced_expressions = 0;
+
/* -- Precompute some information -- */
/* Call algorithm that computes the backedges */
construct_cf_backedges(irg);
/* -- Search expressions that can be optimized -- */
irg_walk_graph(irg, NULL, reduce_a_node, NULL);
+
+
+ if (get_opt_strength_red_verbosity()) {
+ if (n_reduced_expressions > 0)
+ printf("reduced strength of %d expressions in graph %s.\n",
+ n_reduced_expressions, get_irg_dump_name(irg));
+ }
}