2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
8 * @brief Generic backend types and interfaces.
9 * @author Sebastian Hack
11 #ifndef FIRM_BE_MAIN_H
12 #define FIRM_BE_MAIN_H
17 #include "iroptimize.h"
21 * @defgroup be Code Generation
23 * Code Generation (backend) produces machine-code.
28 * flags categorizing assembler constraint specifications
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
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)
58 /** Dwarf source language codes. */
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,
72 DW_LANG_Ada95 = 0x000d,
73 DW_LANG_Fortran95 = 0x000e,
75 DW_LANG_ObjC = 0x0010,
76 DW_LANG_ObjC_plus_plus = 0x0011,
79 DW_LANG_Python = 0x0014,
81 } dwarf_source_language;
84 * Build a Trampoline for the closure.
85 * @param block the block where to build the trampoline
87 * @param trampoline address of a trampoline region
88 * @param env address of the environment
89 * @param callee address of the function to call
91 * @return modified memory
93 typedef ir_node *(create_trampoline_fkt)(ir_node *block, ir_node *mem, ir_node *trampoline, ir_node *env, ir_node *callee);
96 * This structure contains parameters that should be
97 * propagated to the libFirm parameter set.
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
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
115 unsigned non_modulo_shift_efficient:1;
117 /** Settings for architecture dependent optimizations. */
118 const ir_settings_arch_dep_t *dep_param;
120 /** Backend settings for if-conversion. */
121 arch_allow_ifconv_func allow_ifconv;
123 /** size of machine word in bits. This is usually the size of the general
124 * purpose integer/address registers. */
125 unsigned machine_size;
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).
131 ir_mode *mode_float_arithmetic;
134 * type used for long long or NULL if none available.
136 ir_type *type_long_long;
139 * type used for unsigned long long or NULL if none available
141 ir_type *type_unsigned_long_long;
144 * type used for long double or NULL if none available.
146 ir_type *type_long_double;
148 /** Size of the trampoline code. */
149 unsigned trampoline_size;
151 /** Alignment of the trampoline code. */
152 unsigned trampoline_align;
154 /** If non-zero, build the trampoline. */
155 create_trampoline_fkt *build_trampoline;
157 /** Alignment of stack parameters */
158 unsigned stack_param_align;
162 * Parse one backend argument.
164 FIRM_API int be_parse_arg(const char *arg);
167 * Returns 1 if the backend uses big-endian byte ordering
168 * and 0 for little-endian.
170 FIRM_API int be_is_big_endian(void);
173 * Returns size of machine words. This is usually the size
174 * of the general purpose integer registers.
176 FIRM_API unsigned be_get_machine_size(void);
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).
184 FIRM_API ir_mode *be_get_mode_float_arithmetic(void);
186 /** Returns type used for long long or NULL if none available. */
187 FIRM_API ir_type *be_get_type_long_long(void);
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);
192 /** Returns type used for long double or NULL if none available. */
193 FIRM_API ir_type *be_get_type_long_double(void);
196 * Returns the backend configuration parameter.
198 * @return libFirm configuration parameters for the selected
201 FIRM_API const backend_params *be_get_backend_param(void);
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
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.
212 FIRM_API void be_lower_for_target(void);
215 * Creates an ir_prog pass which performs lowerings necessary for the target
216 * architecture. (Calling backend_params->lower_for_target)
218 FIRM_API ir_prog_pass_t *lower_for_target_pass(const char *name);
221 * Main interface to the frontend.
223 FIRM_API void be_main(FILE *output, const char *compilation_unit_name);
226 * parse assembler constraint strings and returns flags (so the frontend knows
227 * which operands are inputs/outputs and whether memory is required)
229 FIRM_API asm_constraint_flags_t be_parse_asm_constraints(const char *constraints);
232 * tests whether a string is a valid clobber in an ASM instruction
234 FIRM_API int be_is_valid_clobber(const char *clobber);
237 * Sets source language for dwarf debug information.
239 FIRM_API void be_dwarf_set_source_language(dwarf_source_language language);
242 * Sets working directory of the compiler (or directory where the compiler
243 * searched for sources) for dwarf debug information.
245 FIRM_API void be_dwarf_set_compilation_directory(const char *directory);