beifg: Remove the unused function be_ifg_nodes_break().
[libfirm] / include / libfirm / be.h
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5
6 /**
7  * @file
8  * @brief       Generic backend types and interfaces.
9  * @author      Sebastian Hack
10  */
11 #ifndef FIRM_BE_MAIN_H
12 #define FIRM_BE_MAIN_H
13
14 #include <stdio.h>
15 #include "irarch.h"
16 #include "lowering.h"
17 #include "iroptimize.h"
18 #include "begin.h"
19
20 /**
21  * @defgroup be  Code Generation
22  *
23  * Code Generation (backend) produces machine-code.
24  * @{
25  */
26
27 /**
28  * flags categorizing assembler constraint specifications
29  */
30 typedef enum asm_constraint_flags_t {
31         ASM_CONSTRAINT_FLAG_NONE                  = 0, /**< no constraints */
32         /** input/output can be in a register */
33         ASM_CONSTRAINT_FLAG_SUPPORTS_REGISTER     = 1u << 0,
34         /** input/output can be read/written to/from a memory address */
35         ASM_CONSTRAINT_FLAG_SUPPORTS_MEMOP        = 1u << 1,
36         /** input can be encoded as an immediate number */
37         ASM_CONSTRAINT_FLAG_SUPPORTS_IMMEDIATE    = 1u << 2,
38         /** the constraint is not supported yet by libFirm */
39         ASM_CONSTRAINT_FLAG_NO_SUPPORT            = 1u << 3,
40         /** The input is also written to */
41         ASM_CONSTRAINT_FLAG_MODIFIER_WRITE        = 1u << 4,
42         /** the input is not written to */
43         ASM_CONSTRAINT_FLAG_MODIFIER_NO_WRITE     = 1u << 5,
44         /** the input is read */
45         ASM_CONSTRAINT_FLAG_MODIFIER_READ         = 1u << 6,
46         /** the input is not read */
47         ASM_CONSTRAINT_FLAG_MODIFIER_NO_READ      = 1u << 7,
48         /** the value is modified before all inputs to the asm block
49          * are handled. */
50         ASM_CONSTRAINT_FLAG_MODIFIER_EARLYCLOBBER = 1u << 8,
51         /** This operand and the following operand are commutative */
52         ASM_CONSTRAINT_FLAG_MODIFIER_COMMUTATIVE  = 1u << 9,
53         /** invalid constraint (due to parse error) */
54         ASM_CONSTRAINT_FLAG_INVALID               = 1u << 10
55 } asm_constraint_flags_t;
56 ENUM_BITSET(asm_constraint_flags_t)
57
58 /** Dwarf source language codes. */
59 typedef enum {
60         DW_LANG_C89 = 0x0001,
61         DW_LANG_C = 0x0002,
62         DW_LANG_Ada83 = 0x0003,
63         DW_LANG_C_plus_plus = 0x0004,
64         DW_LANG_Cobol74 = 0x0005,
65         DW_LANG_Cobol85 = 0x0006,
66         DW_LANG_Fortran77 = 0x0007,
67         DW_LANG_Fortran90 = 0x0008,
68         DW_LANG_Pascal83 = 0x0009,
69         DW_LANG_Modula2 = 0x000a,
70         DW_LANG_Java = 0x000b,
71         DW_LANG_C99 = 0x000c,
72         DW_LANG_Ada95 = 0x000d,
73         DW_LANG_Fortran95 = 0x000e,
74         DW_LANG_PLI = 0x000f,
75         DW_LANG_ObjC = 0x0010,
76         DW_LANG_ObjC_plus_plus = 0x0011,
77         DW_LANG_UPC = 0x0012,
78         DW_LANG_D = 0x0013,
79         DW_LANG_Python = 0x0014,
80         DW_LANG_Go = 0x0016,
81 } dwarf_source_language;
82
83 /**
84  * Build a Trampoline for the closure.
85  * @param block       the block where to build the trampoline
86  * @param mem         memory
87  * @param trampoline  address of a trampoline region
88  * @param env         address of the environment
89  * @param callee      address of the function to call
90  *
91  * @return modified memory
92  */
93 typedef ir_node *(create_trampoline_fkt)(ir_node *block, ir_node *mem, ir_node *trampoline, ir_node *env, ir_node *callee);
94
95 /**
96  * This structure contains parameters that should be
97  * propagated to the libFirm parameter set.
98  */
99 typedef struct backend_params {
100         /** If set, the backend supports inline assembly. */
101         unsigned support_inline_asm:1;
102         /** If set, the backend supports Rotl nodes */
103         unsigned support_rotl:1;
104         /** the backend uses big-endian byte ordering if set, else little endian */
105         unsigned byte_order_big_endian:1;
106         /** whether the architecure can natively handle modulo shift modes.
107          * If this is true, then you can assume that shifting in modes with
108          * module_shift==machine_size (if mode size is <= machine_size) is efficient
109          */
110         unsigned modulo_shift_efficient:1;
111         /** whether the architecure can natively handle modulo shift modes.
112          * If this is true, then you can assume that shifting without modulo shift
113          * is efficient
114          */
115         unsigned non_modulo_shift_efficient:1;
116
117         /** Settings for architecture dependent optimizations. */
118         const ir_settings_arch_dep_t *dep_param;
119
120         /** Backend settings for if-conversion. */
121         arch_allow_ifconv_func allow_ifconv;
122
123         /** size of machine word in bits. This is usually the size of the general
124          * purpose integer/address registers. */
125         unsigned machine_size;
126
127         /**
128          * some backends like x87 can only do arithmetic in a specific float
129          * mode (load/store are still done in the "normal" float/double modes).
130          */
131         ir_mode *mode_float_arithmetic;
132
133         /**
134          * type used for long long or NULL if none available.
135          */
136         ir_type *type_long_long;
137
138         /**
139          * type used for unsigned long long or NULL if none available
140          */
141         ir_type *type_unsigned_long_long;
142
143         /**
144          * type used for long double or NULL if none available.
145          */
146         ir_type *type_long_double;
147
148         /** Size of the trampoline code. */
149         unsigned trampoline_size;
150
151         /** Alignment of the trampoline code. */
152         unsigned trampoline_align;
153
154         /** If non-zero, build the trampoline. */
155         create_trampoline_fkt *build_trampoline;
156
157         /** Alignment of stack parameters */
158         unsigned stack_param_align;
159 } backend_params;
160
161 /**
162  * Parse one backend argument.
163  */
164 FIRM_API int be_parse_arg(const char *arg);
165
166 /**
167  * Returns 1 if the backend uses big-endian byte ordering
168  * and 0 for little-endian.
169  */
170 FIRM_API int be_is_big_endian(void);
171
172 /**
173  * Returns size of machine words. This is usually the size
174  * of the general purpose integer registers.
175  */
176 FIRM_API unsigned be_get_machine_size(void);
177
178 /**
179  * Returns supported float arithmetic mode or NULL if mode_D and mode_F
180  * are supported natively.
181  * Some backends like x87 can only do arithmetic in a specific float
182  * mode (load/store are still done in the "normal" float/double modes).
183  */
184 FIRM_API ir_mode *be_get_mode_float_arithmetic(void);
185
186 /** Returns type used for long long or NULL if none available. */
187 FIRM_API ir_type *be_get_type_long_long(void);
188
189 /** Returns type used for unsigned long long or NULL if none available. */
190 FIRM_API ir_type *be_get_type_unsigned_long_long(void);
191
192 /** Returns type used for long double or NULL if none available. */
193 FIRM_API ir_type *be_get_type_long_double(void);
194
195 /**
196  * Returns the backend configuration parameter.
197  *
198  * @return libFirm configuration parameters for the selected
199  *         backend
200  */
201 FIRM_API const backend_params *be_get_backend_param(void);
202
203 /**
204  * Lowers current program for the target architecture.
205  * This must be run once before using be_main. The idea here is that the backend
206  * can perform lowerings like doubleword-lowering, ABI adjustments or
207  * implementation of boolean values, if-conversion, with target specific
208  * settings.
209  * The resulting graph is still a "normal" firm-graph on which you can and
210  * should perform further architecture-neutral optimisations before be_main.
211  */
212 FIRM_API void be_lower_for_target(void);
213
214 /**
215  * Creates an ir_prog pass which performs lowerings necessary for the target
216  * architecture. (Calling backend_params->lower_for_target)
217  */
218 FIRM_API ir_prog_pass_t *lower_for_target_pass(const char *name);
219
220 /**
221  * Main interface to the frontend.
222  */
223 FIRM_API void be_main(FILE *output, const char *compilation_unit_name);
224
225 /**
226  * parse assembler constraint strings and returns flags (so the frontend knows
227  * which operands are inputs/outputs and whether memory is required)
228  */
229 FIRM_API asm_constraint_flags_t be_parse_asm_constraints(const char *constraints);
230
231 /**
232  * tests whether a string is a valid clobber in an ASM instruction
233  */
234 FIRM_API int be_is_valid_clobber(const char *clobber);
235
236 /**
237  * Sets source language for dwarf debug information.
238  */
239 FIRM_API void be_dwarf_set_source_language(dwarf_source_language language);
240
241 /**
242  * Sets working directory of the compiler (or directory where the compiler
243  * searched for sources) for dwarf debug information.
244  */
245 FIRM_API void be_dwarf_set_compilation_directory(const char *directory);
246
247 /** @} */
248
249 #include "end.h"
250
251 #endif