localopt: simple associativity optimisation
[libfirm] / ir / common / firm.c
1 /*
2  * Copyright (C) 1995-2011 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     Central firm functionality.
23  * @author    Martin Trapp, Christian Schaefer, Goetz Lindenmaier
24  * @version   $Id$
25  */
26 #include "config.h"
27
28 #include "firm_revision.h"
29
30 #include <string.h>
31 #include <stdio.h>
32
33 #include "lc_opts.h"
34
35 #include "ident_t.h"
36 #include "firm.h"
37 #include "irflag_t.h"
38 #include "tv_t.h"
39 #include "tpop_t.h"
40 #include "irprog_t.h"
41 #include "irnode_t.h"
42 #include "irmode_t.h"
43 #include "ircons_t.h"
44 #include "irgraph_t.h"
45 #include "type_t.h"
46 #include "entity_t.h"
47 #include "firmstat.h"
48 #include "irarch.h"
49 #include "irhooks.h"
50 #include "iredges_t.h"
51 #include "irmemory_t.h"
52 #include "opt_init.h"
53 #include "debugger.h"
54 #include "be_t.h"
55 #include "irtools.h"
56
57 /* returns the firm root */
58 lc_opt_entry_t *firm_opt_get_root(void)
59 {
60         static lc_opt_entry_t *grp = NULL;
61         if (!grp)
62                 grp = lc_opt_get_grp(lc_opt_root_grp(), "firm");
63         return grp;
64 }
65
66 void ir_init(void)
67 {
68         /* for historical reasons be_init must be run first */
69         firm_be_init();
70
71         /* initialize firm flags */
72         firm_init_flags();
73         /* initialize all ident stuff */
74         init_ident();
75         /* Edges need hooks. */
76         init_edges();
77         /* create the type kinds. */
78         init_tpop();
79         /* create an obstack and put all tarvals in a pdeq */
80         init_tarval_1(0l, /* support_quad_precision */0);
81         /* Builds a basic program representation, so modes can be added. */
82         init_irprog_1();
83         /* initialize all modes an ir node can consist of */
84         init_mode();
85         /* initialize tarvals, and floating point arithmetic */
86         init_tarval_2();
87         /* init graph construction */
88         firm_init_irgraph();
89         /* kind of obstack initialization */
90         firm_init_mangle();
91         /* initialize all op codes an irnode can consist of */
92         init_op();
93         /* initialize reassociation */
94         firm_init_reassociation();
95         /* initialize function call optimization */
96         firm_init_funccalls();
97         /* initialize function inlining */
98         firm_init_inline();
99         /* initialize scalar replacement */
100         firm_init_scalar_replace();
101         /* Builds a construct allowing to access all information to be constructed
102            later. */
103         init_irprog_2();
104         /* Initialize the type module and construct some idents needed. */
105         ir_init_type();
106         /* initialize the entity module */
107         ir_init_entity();
108         /* class cast optimization */
109         firm_init_class_casts_opt();
110         /* memory disambiguation */
111         firm_init_memory_disambiguator();
112         firm_init_loop_opt();
113
114         /* Init architecture dependent optimizations. */
115         arch_dep_set_opts(arch_dep_none);
116
117         init_irnode();
118
119 #ifdef DEBUG_libfirm
120         /* integrated debugger extension */
121         firm_init_debugger();
122 #endif
123 }
124
125 void ir_finish(void)
126 {
127         size_t i;
128
129         /* must iterate backwards here */
130         for (i = get_irp_n_irgs(); i > 0;)
131                 free_ir_graph(get_irp_irg(--i));
132
133         free_type_entities(get_glob_type());
134         /* must iterate backwards here */
135         for (i = get_irp_n_types(); i > 0;)
136                 free_type_entities(get_irp_type(--i));
137
138         for (i = get_irp_n_types(); i > 0;)
139                 free_type(get_irp_type(--i));
140
141         free_ir_prog();
142
143         ir_finish_entity();
144         ir_finish_type();
145
146         finish_tarval();
147         finish_mode();
148         finish_tpop();
149         finish_ident();
150
151         firm_be_finish();
152 }
153
154 unsigned ir_get_version_major(void)
155 {
156         return libfirm_VERSION_MAJOR;
157 }
158
159 unsigned ir_get_version_minor(void)
160 {
161         return libfirm_VERSION_MINOR;
162 }
163
164 const char *ir_get_version_revision(void)
165 {
166 #ifdef libfirm_VERSION_REVISION
167         return libfirm_VERSION_REVISION;
168 #else
169         return "";
170 #endif
171 }
172
173 const char *ir_get_version_build(void)
174 {
175         return "";
176 }