9c78b7584225f08b8a2d423fd9f37fe218b42197
[libfirm] / ir / ana / cgana.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ana/cgana.h
4  * Purpose:     Intraprozedural analyses to estimate the call graph.
5  * Author:      Hubert Schmid
6  * Modified by:
7  * Created:     09.06.2002
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1999-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13 /**
14  * Intraprozedurale Analyse zur Abschätzung der Aufrulrelation. Es
15  * wird eine Menge von freien Methoden und anschließend die an den
16  * Call-Operationen aufrufbaren Methoden bestimmt.
17  *
18  */
19
20 #ifndef _CGANA_H_
21 #define _CGANA_H_
22
23 #include "entity.h"
24
25 /* Methoden sind "frei", wenn ihr Funktionszeiger (potentiell)
26  * "explizit" bekannt ist, d.h.:
27  *
28  * - die Methode ist von aussen sichtbar (external_visible).
29  *
30  * - ihr Funktionszeiger ist "frei", d.h. der Funktionszeiger wurde
31  *   nicht ausschliesslich an den entsprechenden Eingang eines
32  *   Call-Knotens weitergegeben, sondern z.B. in den Speicher
33  *   geschrieben, als Parameter uebergeben, ...
34  *
35  * Die main-Methode ist immer in der Menge enthalten.
36  *
37  * Die Links an den "ir_node"s werden geloescht. */
38
39 /** Analyses a rough estimation of the possible call graph.
40  *
41  *  Determines for each Call node the set of possibly called methods.
42  *  Stores the result in the field 'callees' of the Call node.  If the
43  *  address can not be analysed, e.g. because it is loaded from a
44  *  variable, the array contains NULL. @@@ the array should contain a
45  *  special entity 'unknown'. (See "set_Call_callee"). cgana returns
46  *  the set of 'free' methods, i.e., the methods that can be called
47  *  from external or via function pointers.  This datastructure must
48  *  be freed with 'free()' by the caller of cgana.
49  *
50  *  cgana sets the callee_info_state of each graph to consistent.
51  *
52  *  The algorithm implements roughly Static Class Hierarchy Analysis
53  *  as described in "Optimization of Object-Oriented Programs Using
54  *  Static Class Hierarchy Analysis" by Jeffrey Dean and David Grove
55  *  and Craig Chambers.
56  *
57  *  Performs some optimizations possible by the analysed information:
58  *    - Replace SymConst nodes by Const nodes if possible,
59  *    - Replace (Sel-method(Alloc)) by Const method,
60  *    - Replaces unreachable Sel nodes by Bad  (@@@ was genau meint unreachable?)
61  *    - Replaces Sel-method by Const if the Method is never overwritten */
62 /*  @@@ I assume this can not be called via JNI :-( -- how to obtain the array pointer? */
63 void cgana(int *len, entity ***free_methods, int whole);
64
65 /** Free callee information.
66  *
67  *  Sets callee_info_state of the graph passed to none.
68  */
69 void free_callee_info(ir_graph *irg);
70
71 /* Optimize the address expressions passed to call nodes.
72  * Performs only the optimizations done by cgana. */
73 /* @@@ move to irgopt ?! */
74 /* @@@ not fully implemented as buggy !!!  */
75 void opt_call_addrs(void);
76 #endif /* _CGANA_H_ */