2 * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief Optimize the frame type.
24 * @author Michael Beck
26 * Optimize the frame type by removing unused type members.
30 #include "iroptimize.h"
31 #include "irgraph_t.h"
38 * Optimize the frame type of an irg by removing
39 * never touched entities.
41 void opt_frame_irg(ir_graph *irg)
43 ir_type *frame_tp = get_irg_frame_type(irg);
44 ir_entity *ent, *list;
46 size_t i, n = get_class_n_members(frame_tp);
51 irp_reserve_resources(irp, IRP_RESOURCE_ENTITY_LINK);
53 /* clear all entity links */
55 ent = get_class_member(frame_tp, --i);
56 set_entity_link(ent, NULL);
60 frame = get_irg_frame(irg);
62 if (edges_activated(irg)) { /* use inplace edges */
63 const ir_edge_t *edge;
65 /* mark all used entities */
66 foreach_out_edge(frame, edge) {
67 sel = get_edge_src_irn(edge);
69 ent = get_Sel_entity(sel);
70 set_entity_link(ent, ent);
76 /* use traditionally out edges */
79 /* mark all used entities */
80 for (i = get_irn_n_outs(frame) - 1; i >= 0; --i) {
81 sel = get_irn_out(frame, i);
83 ent = get_Sel_entity(sel);
84 /* only entities on the frame */
85 if (get_entity_owner(ent) == frame_tp)
86 set_entity_link(ent, ent);
91 /* link unused ones */
94 ent = get_class_member(frame_tp, --i);
95 /* beware of inner functions: those are NOT unused */
96 if (get_entity_link(ent) == NULL && !is_method_entity(ent)) {
97 set_entity_link(ent, list);
103 /* delete list members */
104 for (ent = list; ent; ent = list) {
105 list = (ir_entity*)get_entity_link(ent);
108 /* we changed the frame type, its layout should be redefined */
109 set_type_state(frame_tp, layout_undefined);
111 irp_free_resources(irp, IRP_RESOURCE_ENTITY_LINK);
114 ir_graph_pass_t *opt_frame_irg_pass(const char *name)
116 return def_graph_pass(name ? name : "opt_frame_irg", opt_frame_irg);