3ed7ce57fc0cd9d06718ad8019774c6207120a03
[libfirm] / ir / be / arm / bearch_arm.c
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   The main arm backend driver file.
23  * @author  Matthias Braun, Oliver Richter, Tobias Gneist
24  * @version $Id$
25  */
26 #include "config.h"
27
28 #include "lc_opts.h"
29 #include "lc_opts_enum.h"
30
31 #include "pseudo_irg.h"
32 #include "irgwalk.h"
33 #include "irprog.h"
34 #include "irprintf.h"
35 #include "ircons.h"
36 #include "irgmod.h"
37 #include "irgopt.h"
38 #include "iroptimize.h"
39 #include "irdump.h"
40 #include "lowering.h"
41 #include "error.h"
42
43 #include "bitset.h"
44 #include "debug.h"
45 #include "array_t.h"
46 #include "irtools.h"
47
48 #include "../bearch.h"
49 #include "../benode.h"
50 #include "../belower.h"
51 #include "../besched.h"
52 #include "be.h"
53 #include "../bemachine.h"
54 #include "../beilpsched.h"
55 #include "../bemodule.h"
56 #include "../beirg.h"
57 #include "../bespillslots.h"
58 #include "../begnuas.h"
59 #include "../belistsched.h"
60 #include "../beflags.h"
61
62 #include "bearch_arm_t.h"
63
64 #include "arm_new_nodes.h"
65 #include "gen_arm_regalloc_if.h"
66 #include "arm_transform.h"
67 #include "arm_optimize.h"
68 #include "arm_emitter.h"
69 #include "arm_map_regs.h"
70
71 static arch_irn_class_t arm_classify(const ir_node *irn)
72 {
73         (void) irn;
74         /* TODO: we should mark reload/spill instructions and classify them here */
75         return 0;
76 }
77
78 static ir_entity *arm_get_frame_entity(const ir_node *irn)
79 {
80         const arm_attr_t *attr = get_arm_attr_const(irn);
81
82         if (is_arm_FrameAddr(irn)) {
83                 const arm_SymConst_attr_t *attr = get_irn_generic_attr_const(irn);
84                 return attr->entity;
85         }
86         if (attr->is_load_store) {
87                 const arm_load_store_attr_t *load_store_attr
88                         = get_arm_load_store_attr_const(irn);
89                 if (load_store_attr->is_frame_entity) {
90                         return load_store_attr->entity;
91                 }
92         }
93         return NULL;
94 }
95
96 /**
97  * This function is called by the generic backend to correct offsets for
98  * nodes accessing the stack.
99  */
100 static void arm_set_stack_bias(ir_node *irn, int bias)
101 {
102         if (is_arm_FrameAddr(irn)) {
103                 arm_SymConst_attr_t *attr = get_irn_generic_attr(irn);
104                 attr->fp_offset += bias;
105         } else {
106                 arm_load_store_attr_t *attr = get_arm_load_store_attr(irn);
107                 assert(attr->base.is_load_store);
108                 attr->offset += bias;
109         }
110 }
111
112 static int arm_get_sp_bias(const ir_node *irn)
113 {
114         /* We don't have any nodes changing the stack pointer.
115            We probably want to support post-/pre increment/decrement later */
116         (void) irn;
117         return 0;
118 }
119
120 /* fill register allocator interface */
121
122 static const arch_irn_ops_t arm_irn_ops = {
123         get_arm_in_req,
124         arm_classify,
125         arm_get_frame_entity,
126         arm_set_stack_bias,
127         arm_get_sp_bias,
128         NULL,    /* get_inverse             */
129         NULL,    /* get_op_estimated_cost   */
130         NULL,    /* possible_memory_operand */
131         NULL,    /* perform_memory_operand  */
132 };
133
134 /**
135  * Transforms the standard Firm graph into
136  * a ARM firm graph.
137  */
138 static void arm_prepare_graph(void *self)
139 {
140         arm_code_gen_t *cg = self;
141
142         /* transform nodes into assembler instructions */
143         arm_transform_graph(cg);
144
145         /* do local optimizations (mainly CSE) */
146         local_optimize_graph(cg->irg);
147
148         if (cg->dump)
149                 dump_ir_graph(cg->irg, "transformed");
150
151         /* do code placement, to optimize the position of constants */
152         place_code(cg->irg);
153
154         if (cg->dump)
155                 dump_ir_graph(cg->irg, "place");
156 }
157
158 /**
159  * Called immediately before emit phase.
160  */
161 static void arm_finish_irg(void *self)
162 {
163         arm_code_gen_t *cg = self;
164
165         /* do peephole optimizations and fix stack offsets */
166         arm_peephole_optimization(cg);
167 }
168
169 static ir_node *arm_flags_remat(ir_node *node, ir_node *after)
170 {
171         ir_node *block;
172         ir_node *copy;
173
174         if (is_Block(after)) {
175                 block = after;
176         } else {
177                 block = get_nodes_block(after);
178         }
179         copy = exact_copy(node);
180         set_nodes_block(copy, block);
181         sched_add_after(after, copy);
182         return copy;
183 }
184
185 static void arm_before_ra(void *self)
186 {
187         arm_code_gen_t *cg = self;
188
189         be_sched_fix_flags(cg->irg, &arm_reg_classes[CLASS_arm_flags],
190                            &arm_flags_remat);
191 }
192
193 static void transform_Reload(ir_node *node)
194 {
195         ir_node   *block  = get_nodes_block(node);
196         dbg_info  *dbgi   = get_irn_dbg_info(node);
197         ir_node   *ptr    = get_irn_n(node, be_pos_Reload_frame);
198         ir_node   *mem    = get_irn_n(node, be_pos_Reload_mem);
199         ir_mode   *mode   = get_irn_mode(node);
200         ir_entity *entity = be_get_frame_entity(node);
201         const arch_register_t *reg;
202         ir_node   *proj;
203         ir_node   *load;
204
205         ir_node  *sched_point = sched_prev(node);
206
207         load = new_bd_arm_Ldr(dbgi, block, ptr, mem, mode, entity, false, 0, true);
208         sched_add_after(sched_point, load);
209         sched_remove(node);
210
211         proj = new_rd_Proj(dbgi, load, mode, pn_arm_Ldr_res);
212
213         reg = arch_get_irn_register(node);
214         arch_set_irn_register(proj, reg);
215
216         exchange(node, proj);
217 }
218
219 static void transform_Spill(ir_node *node)
220 {
221         ir_node   *block  = get_nodes_block(node);
222         dbg_info  *dbgi   = get_irn_dbg_info(node);
223         ir_node   *ptr    = get_irn_n(node, be_pos_Spill_frame);
224         ir_node   *mem    = new_NoMem();
225         ir_node   *val    = get_irn_n(node, be_pos_Spill_val);
226         ir_mode   *mode   = get_irn_mode(val);
227         ir_entity *entity = be_get_frame_entity(node);
228         ir_node   *sched_point;
229         ir_node   *store;
230
231         sched_point = sched_prev(node);
232         store = new_bd_arm_Str(dbgi, block, ptr, val, mem, mode, entity, false, 0,
233                                true);
234
235         sched_remove(node);
236         sched_add_after(sched_point, store);
237
238         exchange(node, store);
239 }
240
241 static void arm_after_ra_walker(ir_node *block, void *data)
242 {
243         ir_node *node, *prev;
244         (void) data;
245
246         for (node = sched_last(block); !sched_is_begin(node); node = prev) {
247                 prev = sched_prev(node);
248
249                 if (be_is_Reload(node)) {
250                         transform_Reload(node);
251                 } else if (be_is_Spill(node)) {
252                         transform_Spill(node);
253                 }
254         }
255 }
256
257 static void arm_collect_frame_entity_nodes(ir_node *node, void *data)
258 {
259         be_fec_env_t  *env = data;
260         const ir_mode *mode;
261         int            align;
262         ir_entity     *entity;
263         const arm_load_store_attr_t *attr;
264
265         if (be_is_Reload(node) && be_get_frame_entity(node) == NULL) {
266                 mode  = get_irn_mode(node);
267                 align = get_mode_size_bytes(mode);
268                 be_node_needs_frame_entity(env, node, mode, align);
269                 return;
270         }
271
272         switch (get_arm_irn_opcode(node)) {
273         case iro_arm_Ldf:
274         case iro_arm_Ldr:
275                 break;
276         default:
277                 return;
278         }
279
280         attr   = get_arm_load_store_attr_const(node);
281         entity = attr->entity;
282         mode   = attr->load_store_mode;
283         align  = get_mode_size_bytes(mode);
284         if (entity != NULL)
285                 return;
286         if (!attr->is_frame_entity)
287                 return;
288         be_node_needs_frame_entity(env, node, mode, align);
289 }
290
291 static void arm_set_frame_entity(ir_node *node, ir_entity *entity)
292 {
293         if (is_be_node(node)) {
294                 be_node_set_frame_entity(node, entity);
295         } else {
296                 arm_load_store_attr_t *attr = get_arm_load_store_attr(node);
297                 attr->entity = entity;
298         }
299 }
300
301 static void arm_after_ra(void *self)
302 {
303         arm_code_gen_t *cg  = self;
304         ir_graph       *irg = cg->irg;
305
306         be_fec_env_t *fec_env = be_new_frame_entity_coalescer(irg);
307
308         irg_walk_graph(irg, NULL, arm_collect_frame_entity_nodes, fec_env);
309         be_assign_entities(fec_env, arm_set_frame_entity);
310         be_free_frame_entity_coalescer(fec_env);
311
312         irg_block_walk_graph(cg->irg, NULL, arm_after_ra_walker, NULL);
313 }
314
315 /**
316  * Emits the code, closes the output file and frees
317  * the code generator interface.
318  */
319 static void arm_emit_and_done(void *self)
320 {
321         arm_code_gen_t *cg = self;
322         ir_graph       *irg = cg->irg;
323
324         arm_gen_routine(cg, irg);
325
326         /* de-allocate code generator */
327         del_set(cg->reg_set);
328         free(self);
329 }
330
331 /* forward */
332 static void *arm_cg_init(ir_graph *irg);
333
334 static const arch_code_generator_if_t arm_code_gen_if = {
335         arm_cg_init,
336         NULL,               /* get_pic_base */
337         NULL,               /* before abi introduce */
338         arm_prepare_graph,
339         NULL,               /* spill */
340         arm_before_ra,      /* before register allocation hook */
341         arm_after_ra,
342         arm_finish_irg,
343         arm_emit_and_done,
344 };
345
346 /**
347  * Initializes the code generator.
348  */
349 static void *arm_cg_init(ir_graph *irg)
350 {
351         static ir_type *int_tp = NULL;
352         arm_isa_t      *isa = (arm_isa_t *) be_get_irg_arch_env(irg);
353         arm_code_gen_t *cg;
354
355         if (! int_tp) {
356                 /* create an integer type with machine size */
357                 int_tp = new_type_primitive(mode_Is);
358         }
359
360         cg = XMALLOC(arm_code_gen_t);
361         cg->impl         = &arm_code_gen_if;
362         cg->irg          = irg;
363         cg->reg_set      = new_set(arm_cmp_irn_reg_assoc, 1024);
364         cg->isa          = isa;
365         cg->int_tp       = int_tp;
366         cg->dump         = (be_get_irg_options(irg)->dump_flags & DUMP_BE) ? 1 : 0;
367
368         FIRM_DBG_REGISTER(cg->mod, "firm.be.arm.cg");
369
370         /* enter the current code generator */
371         isa->cg = cg;
372
373         return (arch_code_generator_t *)cg;
374 }
375
376
377 /**
378  * Maps all intrinsic calls that the backend support
379  * and map all instructions the backend did not support
380  * to runtime calls.
381  */
382 static void arm_handle_intrinsics(void)
383 {
384         ir_type *tp, *int_tp, *uint_tp;
385         i_record records[8];
386         int n_records = 0;
387
388         runtime_rt rt_iDiv, rt_uDiv, rt_iMod, rt_uMod;
389
390 #define ID(x) new_id_from_chars(x, sizeof(x)-1)
391
392         int_tp  = new_type_primitive(mode_Is);
393         uint_tp = new_type_primitive(mode_Iu);
394
395         /* ARM has neither a signed div instruction ... */
396         {
397                 i_instr_record *map_Div = &records[n_records++].i_instr;
398
399                 tp = new_type_method(2, 1);
400                 set_method_param_type(tp, 0, int_tp);
401                 set_method_param_type(tp, 1, int_tp);
402                 set_method_res_type(tp, 0, int_tp);
403
404                 rt_iDiv.ent             = new_entity(get_glob_type(), ID("__divsi3"), tp);
405                 set_entity_ld_ident(rt_iDiv.ent, ID("__divsi3"));
406                 rt_iDiv.mode            = mode_T;
407                 rt_iDiv.res_mode        = mode_Is;
408                 rt_iDiv.mem_proj_nr     = pn_Div_M;
409                 rt_iDiv.regular_proj_nr = pn_Div_X_regular;
410                 rt_iDiv.exc_proj_nr     = pn_Div_X_except;
411                 rt_iDiv.exc_mem_proj_nr = pn_Div_M;
412                 rt_iDiv.res_proj_nr     = pn_Div_res;
413
414                 add_entity_linkage(rt_iDiv.ent, IR_LINKAGE_CONSTANT);
415                 set_entity_visibility(rt_iDiv.ent, ir_visibility_external);
416
417                 map_Div->kind     = INTRINSIC_INSTR;
418                 map_Div->op       = op_Div;
419                 map_Div->i_mapper = (i_mapper_func)i_mapper_RuntimeCall;
420                 map_Div->ctx      = &rt_iDiv;
421         }
422         /* ... nor an unsigned div instruction ... */
423         {
424                 i_instr_record *map_Div = &records[n_records++].i_instr;
425
426                 tp = new_type_method(2, 1);
427                 set_method_param_type(tp, 0, uint_tp);
428                 set_method_param_type(tp, 1, uint_tp);
429                 set_method_res_type(tp, 0, uint_tp);
430
431                 rt_uDiv.ent             = new_entity(get_glob_type(), ID("__udivsi3"), tp);
432                 set_entity_ld_ident(rt_uDiv.ent, ID("__udivsi3"));
433                 rt_uDiv.mode            = mode_T;
434                 rt_uDiv.res_mode        = mode_Iu;
435                 rt_uDiv.mem_proj_nr     = pn_Div_M;
436                 rt_uDiv.regular_proj_nr = pn_Div_X_regular;
437                 rt_uDiv.exc_proj_nr     = pn_Div_X_except;
438                 rt_uDiv.exc_mem_proj_nr = pn_Div_M;
439                 rt_uDiv.res_proj_nr     = pn_Div_res;
440
441                 set_entity_visibility(rt_uDiv.ent, ir_visibility_external);
442
443                 map_Div->kind     = INTRINSIC_INSTR;
444                 map_Div->op       = op_Div;
445                 map_Div->i_mapper = (i_mapper_func)i_mapper_RuntimeCall;
446                 map_Div->ctx      = &rt_uDiv;
447         }
448         /* ... nor a signed mod instruction ... */
449         {
450                 i_instr_record *map_Mod = &records[n_records++].i_instr;
451
452                 tp = new_type_method(2, 1);
453                 set_method_param_type(tp, 0, int_tp);
454                 set_method_param_type(tp, 1, int_tp);
455                 set_method_res_type(tp, 0, int_tp);
456
457                 rt_iMod.ent             = new_entity(get_glob_type(), ID("__modsi3"), tp);
458                 set_entity_ld_ident(rt_iMod.ent, ID("__modsi3"));
459                 rt_iMod.mode            = mode_T;
460                 rt_iMod.res_mode        = mode_Is;
461                 rt_iMod.mem_proj_nr     = pn_Mod_M;
462                 rt_iMod.regular_proj_nr = pn_Mod_X_regular;
463                 rt_iMod.exc_proj_nr     = pn_Mod_X_except;
464                 rt_iMod.exc_mem_proj_nr = pn_Mod_M;
465                 rt_iMod.res_proj_nr     = pn_Mod_res;
466
467                 set_entity_visibility(rt_iMod.ent, ir_visibility_external);
468
469                 map_Mod->kind     = INTRINSIC_INSTR;
470                 map_Mod->op       = op_Mod;
471                 map_Mod->i_mapper = (i_mapper_func)i_mapper_RuntimeCall;
472                 map_Mod->ctx      = &rt_iMod;
473         }
474         /* ... nor an unsigned mod. */
475         {
476                 i_instr_record *map_Mod = &records[n_records++].i_instr;
477
478                 tp = new_type_method(2, 1);
479                 set_method_param_type(tp, 0, uint_tp);
480                 set_method_param_type(tp, 1, uint_tp);
481                 set_method_res_type(tp, 0, uint_tp);
482
483                 rt_uMod.ent             = new_entity(get_glob_type(), ID("__umodsi3"), tp);
484                 set_entity_ld_ident(rt_uMod.ent, ID("__umodsi3"));
485                 rt_uMod.mode            = mode_T;
486                 rt_uMod.res_mode        = mode_Iu;
487                 rt_uMod.mem_proj_nr     = pn_Mod_M;
488                 rt_uMod.regular_proj_nr = pn_Mod_X_regular;
489                 rt_uMod.exc_proj_nr     = pn_Mod_X_except;
490                 rt_uMod.exc_mem_proj_nr = pn_Mod_M;
491                 rt_uMod.res_proj_nr     = pn_Mod_res;
492
493                 set_entity_visibility(rt_uMod.ent, ir_visibility_external);
494
495                 map_Mod->kind     = INTRINSIC_INSTR;
496                 map_Mod->op       = op_Mod;
497                 map_Mod->i_mapper = (i_mapper_func)i_mapper_RuntimeCall;
498                 map_Mod->ctx      = &rt_uMod;
499         }
500
501         if (n_records > 0)
502                 lower_intrinsics(records, n_records, /*part_block_used=*/0);
503 }
504
505
506 static arm_isa_t arm_isa_template = {
507         {
508                 &arm_isa_if,           /* isa interface */
509                 &arm_gp_regs[REG_SP],  /* stack pointer */
510                 &arm_gp_regs[REG_R11], /* base pointer */
511                 &arm_reg_classes[CLASS_arm_gp],  /* static link pointer class */
512                 -1,                    /* stack direction */
513                 2,                     /* power of two stack alignment for calls, 2^2 == 4 */
514                 NULL,                  /* main environment */
515                 7,                     /* spill costs */
516                 5,                     /* reload costs */
517                 true,                  /* we do have custom abi handling */
518         },
519         0,                     /* use generic register names instead of SP, LR, PC */
520         ARM_FPU_ARCH_FPE,      /* FPU architecture */
521         NULL,                  /* current code generator */
522 };
523
524 /**
525  * Initializes the backend ISA and opens the output file.
526  */
527 static arch_env_t *arm_init(FILE *file_handle)
528 {
529         static int inited = 0;
530         arm_isa_t *isa;
531
532         if (inited)
533                 return NULL;
534
535         isa = XMALLOC(arm_isa_t);
536         memcpy(isa, &arm_isa_template, sizeof(*isa));
537
538         arm_register_init();
539
540         isa->cg  = NULL;
541         be_emit_init(file_handle);
542
543         arm_create_opcodes(&arm_irn_ops);
544         arm_handle_intrinsics();
545
546         be_gas_emit_types = false;
547
548         /* needed for the debug support */
549         be_gas_emit_switch_section(GAS_SECTION_TEXT);
550         be_emit_irprintf("%stext0:\n", be_gas_get_private_prefix());
551         be_emit_write_line();
552
553         inited = 1;
554         return &isa->arch_env;
555 }
556
557
558
559 /**
560  * Closes the output file and frees the ISA structure.
561  */
562 static void arm_done(void *self)
563 {
564         arm_isa_t *isa = self;
565
566         be_gas_emit_decls(isa->arch_env.main_env);
567
568         be_emit_exit();
569         free(self);
570 }
571
572
573 /**
574  * Report the number of register classes.
575  * If we don't have fp instructions, report only GP
576  * here to speed up register allocation (and makes dumps
577  * smaller and more readable).
578  */
579 static unsigned arm_get_n_reg_class(void)
580 {
581         return N_CLASSES;
582 }
583
584 /**
585  * Return the register class with requested index.
586  */
587 static const arch_register_class_t *arm_get_reg_class(unsigned i)
588 {
589         assert(i < N_CLASSES);
590         return &arm_reg_classes[i];
591 }
592
593 /**
594  * Get the register class which shall be used to store a value of a given mode.
595  * @param self The this pointer.
596  * @param mode The mode in question.
597  * @return A register class which can hold values of the given mode.
598  */
599 static const arch_register_class_t *arm_get_reg_class_for_mode(const ir_mode *mode)
600 {
601         if (mode_is_float(mode))
602                 return &arm_reg_classes[CLASS_arm_fpa];
603         else
604                 return &arm_reg_classes[CLASS_arm_gp];
605 }
606
607 static int arm_to_appear_in_schedule(void *block_env, const ir_node *irn)
608 {
609         (void) block_env;
610         if (!is_arm_irn(irn))
611                 return -1;
612
613         return 1;
614 }
615
616 /**
617  * Initializes the code generator interface.
618  */
619 static const arch_code_generator_if_t *arm_get_code_generator_if(void *self)
620 {
621         (void) self;
622         return &arm_code_gen_if;
623 }
624
625 list_sched_selector_t arm_sched_selector;
626
627 /**
628  * Returns the reg_pressure scheduler with to_appear_in_schedule() over\loaded
629  */
630 static const list_sched_selector_t *arm_get_list_sched_selector(const void *self, list_sched_selector_t *selector)
631 {
632         (void) self;
633         memcpy(&arm_sched_selector, selector, sizeof(arm_sched_selector));
634         /* arm_sched_selector.exectime              = arm_sched_exectime; */
635         arm_sched_selector.to_appear_in_schedule = arm_to_appear_in_schedule;
636         return &arm_sched_selector;
637
638 }
639
640 static const ilp_sched_selector_t *arm_get_ilp_sched_selector(const void *self)
641 {
642         (void) self;
643         return NULL;
644 }
645
646 /**
647  * Returns the necessary byte alignment for storing a register of given class.
648  */
649 static int arm_get_reg_class_alignment(const arch_register_class_t *cls)
650 {
651         (void) cls;
652         /* ARM is a 32 bit CPU, no need for other alignment */
653         return 4;
654 }
655
656 static const be_execution_unit_t ***arm_get_allowed_execution_units(const ir_node *irn)
657 {
658         (void) irn;
659         /* TODO */
660         panic("Unimplemented arm_get_allowed_execution_units()");
661 }
662
663 static const be_machine_t *arm_get_machine(const void *self)
664 {
665         (void) self;
666         /* TODO */
667         panic("Unimplemented arm_get_machine()");
668 }
669
670 /**
671  * Return irp irgs in the desired order.
672  */
673 static ir_graph **arm_get_irg_list(const void *self, ir_graph ***irg_list)
674 {
675         (void) self;
676         (void) irg_list;
677         return NULL;
678 }
679
680 /**
681  * Allows or disallows the creation of Psi nodes for the given Phi nodes.
682  * @return 1 if allowed, 0 otherwise
683  */
684 static int arm_is_mux_allowed(ir_node *sel, ir_node *mux_false,
685                               ir_node *mux_true)
686 {
687         (void) sel;
688         (void) mux_false;
689         (void) mux_true;
690
691         return 0;
692 }
693
694 static asm_constraint_flags_t arm_parse_asm_constraint(const char **c)
695 {
696         /* asm not supported */
697         (void) c;
698         return ASM_CONSTRAINT_FLAG_INVALID;
699 }
700
701 static int arm_is_valid_clobber(const char *clobber)
702 {
703         (void) clobber;
704         return 0;
705 }
706
707 /**
708  * Returns the libFirm configuration parameter for this backend.
709  */
710 static const backend_params *arm_get_libfirm_params(void)
711 {
712         static const ir_settings_if_conv_t ifconv = {
713                 4,                    /* maxdepth, doesn't matter for Psi-conversion */
714                 arm_is_mux_allowed   /* allows or disallows Mux creation for given selector */
715         };
716         static ir_settings_arch_dep_t ad = {
717                 1,    /* allow subs */
718                 1,        /* Muls are fast enough on ARM but ... */
719                 31,   /* ... one shift would be possible better */
720                 NULL, /* no evaluator function */
721                 0,    /* SMUL is needed, only in Arch M */
722                 0,    /* UMUL is needed, only in Arch M */
723                 32,   /* SMUL & UMUL available for 32 bit */
724         };
725         static backend_params p = {
726                 1,     /* need dword lowering */
727                 0,     /* don't support inline assembler yet */
728                 NULL,  /* will be set later */
729                 NULL,  /* but yet no creator function */
730                 NULL,  /* context for create_intrinsic_fkt */
731                 NULL,  /* ifconv_info will be set below */
732                 NULL,  /* float arithmetic mode (TODO) */
733                 0,     /* no trampoline support: size 0 */
734                 0,     /* no trampoline support: align 0 */
735                 NULL,  /* no trampoline support: no trampoline builder */
736                 4      /* alignment of stack parameter */
737         };
738
739         p.dep_param    = &ad;
740         p.if_conv_info = &ifconv;
741         return &p;
742 }
743
744 /* fpu set architectures. */
745 static const lc_opt_enum_int_items_t arm_fpu_items[] = {
746         { "softfloat", ARM_FPU_ARCH_SOFTFLOAT },
747         { "fpe",       ARM_FPU_ARCH_FPE },
748         { "fpa",       ARM_FPU_ARCH_FPA },
749         { "vfp1xd",    ARM_FPU_ARCH_VFP_V1xD },
750         { "vfp1",      ARM_FPU_ARCH_VFP_V1 },
751         { "vfp2",      ARM_FPU_ARCH_VFP_V2 },
752         { NULL,        0 }
753 };
754
755 static lc_opt_enum_int_var_t arch_fpu_var = {
756         &arm_isa_template.fpu_arch, arm_fpu_items
757 };
758
759 static const lc_opt_table_entry_t arm_options[] = {
760         LC_OPT_ENT_ENUM_INT("fpunit",    "select the floating point unit", &arch_fpu_var),
761         LC_OPT_ENT_BOOL("gen_reg_names", "use generic register names", &arm_isa_template.gen_reg_names),
762         LC_OPT_LAST
763 };
764
765 const arch_isa_if_t arm_isa_if = {
766         arm_init,
767         arm_done,
768         NULL,  /* handle_intrinsics */
769         arm_get_n_reg_class,
770         arm_get_reg_class,
771         arm_get_reg_class_for_mode,
772         NULL,
773         arm_get_code_generator_if,
774         arm_get_list_sched_selector,
775         arm_get_ilp_sched_selector,
776         arm_get_reg_class_alignment,
777         arm_get_libfirm_params,
778         arm_get_allowed_execution_units,
779         arm_get_machine,
780         arm_get_irg_list,
781         NULL,               /* mark remat */
782         arm_parse_asm_constraint,
783         arm_is_valid_clobber
784 };
785
786 BE_REGISTER_MODULE_CONSTRUCTOR(be_init_arch_arm);
787 void be_init_arch_arm(void)
788 {
789         lc_opt_entry_t *be_grp = lc_opt_get_grp(firm_opt_get_root(), "be");
790         lc_opt_entry_t *arm_grp = lc_opt_get_grp(be_grp, "arm");
791
792         lc_opt_add_table(arm_grp, arm_options);
793
794         be_register_isa_if("arm", &arm_isa_if);
795
796         arm_init_transform();
797         arm_init_emitter();
798 }