3 * File name: ir/ir/ircgopt.c
4 * Purpose: Removal of unreachable methods.
5 * Author: Hubert Schmid
9 * Copyright: (c) 2002-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
14 * Entfernen von nicht erreichbaren (aufrufbaren) Methoden. Die Menge
15 * der nicht erreichbaren Methoden wird aus der Abschätzung der
16 * Aufrufrelation bestimmt.
30 static void clear_link(ir_node * node, void * env) {
31 set_irn_link(node, NULL);
35 /* Call-Operationen an die "link"-Liste von "call_head" anhängen. */
36 static void collect_call(ir_node * node, ir_node * head) {
37 if (get_irn_op(node) == op_Call) {
38 set_irn_link(node, get_irn_link(head));
39 set_irn_link(head, node);
45 /* garbage collect methods: mark and remove */
46 void gc_irgs(int n_keep, entity ** keep_arr) {
52 entity ** marked = NEW_ARR_F(entity *, n_keep);
53 for (i = 0; i < n_keep; ++i) {
54 marked[i] = keep_arr[i];
55 set_entity_link(marked[i], MARK);
57 for (i = 0; i < ARR_LEN(marked); ++i) {
58 /* check for extern methods, these don't have an IRG */
59 if (get_entity_visibility(marked[i]) != visibility_external_allocated) {
60 ir_graph * irg = get_entity_irg(marked[i]);
61 ir_node * node = get_irg_end(irg);
63 irg_walk_graph(irg, clear_link, (irg_walk_func *) collect_call, node);
65 for (node = get_irn_link(node); node; node = get_irn_link(node)) {
67 assert(get_irn_op(node) == op_Call);
68 for (i = get_Call_n_callees(node) - 1; i >= 0; --i) {
69 entity * ent = get_Call_callee(node, i);
70 if (ent && get_entity_irg(ent) && get_entity_link(ent) != MARK) {
71 set_entity_link(ent, MARK);
72 ARR_APP1(entity *, marked, ent);
82 for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
83 ir_graph * irg = get_irp_irg(i);
84 entity * ent = get_irg_ent(irg);
85 /* Removing any graph invalidates all interprocedural loop trees. */
86 if (get_irg_loopinfo_state(irg) == loopinfo_ip_consistent ||
87 get_irg_loopinfo_state(irg) == loopinfo_ip_inconsistent)
88 free_loop_information(irg);
89 if (get_entity_link(ent) != MARK) {
91 set_entity_peculiarity(ent, peculiarity_description);
93 set_entity_link(ent, NULL);