2 * Copyright (C) 1995-2008 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
27 * Optimize the frame type by removing unused type members.
31 #include "iroptimize.h"
32 #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) {
42 ir_type *frame_tp = get_irg_frame_type(irg);
43 ir_entity *ent, *list;
45 int i, n = get_class_n_members(frame_tp);
50 irp_reserve_resources(irp, IR_RESOURCE_ENTITY_LINK);
52 /* clear all entity links */
53 for (i = n - 1; i >= 0; --i) {
54 ent = get_class_member(frame_tp, i);
55 set_entity_link(ent, NULL);
59 frame = get_irg_frame(irg);
61 if (edges_activated(irg)) { /* use inplace edges */
62 const ir_edge_t *edge;
64 /* mark all used entities */
65 foreach_out_edge(frame, edge) {
66 sel = get_edge_src_irn(edge);
68 ent = get_Sel_entity(sel);
69 set_entity_link(ent, ent);
73 /* use traditionally out edges */
76 /* mark all used entities */
77 for (i = get_irn_n_outs(frame) - 1; i >= 0; --i) {
78 sel = get_irn_out(frame, i);
80 ent = get_Sel_entity(sel);
81 set_entity_link(ent, ent);
86 /* link unused ones */
88 for (i = n - 1; i >= 0; --i) {
89 ent = get_class_member(frame_tp, i);
90 if (get_entity_link(ent) == NULL) {
91 set_entity_link(ent, list);
97 /* delete list members */
98 for (ent = list; ent; ent = list) {
99 list = get_entity_link(ent);
100 remove_class_member(frame_tp, ent);
102 /* we changed the frame type, it's layout should be redefined */
103 set_type_state(frame_tp, layout_undefined);
105 irp_free_resources(irp, IR_RESOURCE_ENTITY_LINK);