split irg and irp resources, add IRP_RESOURCE_TYPE_LINK
[libfirm] / include / libfirm / execution_frequency.h
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
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.
10  *
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.
14  *
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
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief    Compute an estimate of basic block executions.
23  * @author   Goetz Lindenmaier
24  * @date     5.11.2004
25  * @version  $Id$
26  * @brief
27  * We assume the start block of a procedure is executed once.  Based on this we
28  * compute the execution freqency of all blocks.
29  *
30  * The computation of the frequencies depends on the count of exception control
31  * flow computed during the interval analysis. The interval analysis again
32  * depends on stuff computed here.
33  */
34 #ifndef FIRM_ANA_EXECUTION_FREQUENCY_H
35 #define FIRM_ANA_EXECUTION_FREQUENCY_H
36
37 #include "firm_types.h"
38 #include "begin.h"
39
40 /* A proj from a Cond that goes to an exception handler. */
41 FIRM_API int is_fragile_Proj(ir_node *n);
42
43 /** Returns the number of times the block/region is executed according to
44  *  our estimate. Gives a number relative to the Start node of the procedure
45  *  the block is in, which is weighted with 1. */
46 FIRM_API double get_irn_exec_freq(ir_node *n);
47 FIRM_API double get_Block_exec_freq(ir_node *b);
48 FIRM_API double get_region_exec_freq(void *reg);
49
50 /** Compute the execution frequency for all blocks in the given
51  *  graph.
52  *
53  * @param irg                   The graph to be analyzed.
54  * @param default_loop_weight   The default number of executions of a loop.
55  * @param exception_probability The probability that a fragile operation causes an exception.
56  *
57  * Uses link field.
58  */
59 FIRM_API void compute_execution_frequency(ir_graph *irg, int default_loop_weight, double exception_probability);
60
61 /** Compute the execution frequency for all graphs.
62  *
63  * @param default_loop_weight   The default number of executions of a loop.
64  * @param exception_probability The probability that a fragile operation causes an exception.
65  *
66  */
67 FIRM_API void compute_execution_frequencies(int default_loop_weight, double exception_probability);
68
69 /** Free occupied memory, reset for all graphs. */
70 FIRM_API void free_execution_frequency(void);
71
72 /** State of execution frequencies for graphs and the whole program.
73  *
74  * The exec_freq_state in irp is consistent, if the state of all graphs is consistent.
75  * It is none, if the state of all graphs is none.  Else it is inconsistent. */
76 typedef enum {
77   exec_freq_none,             /**< Execution frequencies are not computed, no memory is
78                                    allocated, access fails. */
79   exec_freq_consistent,       /**< Execution frequency information is computed and correct. */
80   exec_freq_inconsistent      /**< Execution frequency is computed but the graph has been
81                                    changed since. */
82 } exec_freq_state;
83
84 FIRM_API exec_freq_state get_irg_exec_freq_state(ir_graph *irg);
85 FIRM_API void            set_irg_exec_freq_state(ir_graph *irg,
86                                                  exec_freq_state s);
87 /* Sets irg and irp exec freq state to inconsistent if it is set to consistent. */
88 FIRM_API void set_irg_exec_freq_state_inconsistent(ir_graph *irg);
89
90 FIRM_API exec_freq_state get_irp_exec_freq_state(void);
91 /* Sets irp and all irg exec freq states to inconsistent if it is set to consistent. */
92 FIRM_API void set_irp_exec_freq_state_inconsistent(void);
93
94 #include "end.h"
95
96 #endif