2 * Copyright (C) 1995-2007 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 Intraprozedural analyses to estimate the call graph.
23 * @author Hubert Schmid
28 * Interprocedural analysis to estimate the calling relation.
30 * This analysis computes all entities representing methods that
31 * can be called at a Call node. Further it computes a set of
32 * methods that are 'free', i.e., their adress is handled by
33 * the program directly, or they are visible external.
35 #ifndef FIRM_ANA_CGANA_H
36 #define FIRM_ANA_CGANA_H
38 #include "firm_types.h"
40 /* Methoden sind "frei", wenn ihr Funktionszeiger (potentiell)
41 * "explizit" bekannt ist, d.h.:
43 * - die Methode ist von aussen sichtbar (external_visible).
45 * - ihr Funktionszeiger ist "frei", d.h. der Funktionszeiger wurde
46 * nicht ausschliesslich an den entsprechenden Eingang eines
47 * Call-Knotens weitergegeben, sondern z.B. in den Speicher
48 * geschrieben, als Parameter uebergeben, ...
50 * Die main-Methode ist immer in der Menge enthalten.
52 * Die Links an den "ir_node"s werden geloescht.
55 /** Analyses a rough estimation of the possible call graph.
57 * Determines for each Call node the set of possibly called methods.
58 * Stores the result in the field 'callees' of the Call node. If the
59 * address can not be analysed, e.g. because it is loaded from a
60 * variable, the array contains the unknown_entity. (See
61 * "set_Call_callee"). cgana returns the set of 'free' methods, i.e.,
62 * the methods that can be called from external or via function
63 * pointers. This datastructure must be freed with 'free()' by the
66 * cgana sets the callee_info_state of each graph and the program to
69 * The algorithm implements roughly Static Class Hierarchy Analysis
70 * as described in "Optimization of Object-Oriented Programs Using
71 * Static Class Hierarchy Analysis" by Jeffrey Dean and David Grove
74 * Performs some optimizations possible by the analysed information:
75 * - Replace SymConst-name nodes by SymConst-entity nodes if possible.
76 * - Replace (Sel-method(Alloc)) by SymConst-entity.
77 * - Replaces Sel nodes by Bad if there is no implementation for the
79 * - Replaces Sel-method by SymConst-entity if the method is never overwritten.
80 * - Replaces Calls by Tuple containing Bads if callee array is empty
81 * (there is no implementation to call)
83 * Leaves Bad control predecessors in the graph!
85 void cgana(int *len, ir_entity ***free_methods);
87 /** Free callee information.
89 * Sets callee_info_state of the graph passed to none. Sets callee field
90 * in all call nodes to NULL. Else it happens that the field contains
91 * pointers to other than firm arrays.
93 void free_callee_info(ir_graph *irg);
94 void free_irp_callee_info(void);
96 /* Optimize the address expressions passed to call nodes.
97 * Performs only the optimizations done by cgana. */
98 void opt_call_addrs(void);