bdaabd3761ad1ae0fc25373ea454bf0a1db3eab1
[libfirm] / ir / be / ia32 / bearch_ia32_t.h
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5
6 /**
7  * @file
8  * @brief       This is the main ia32 firm backend driver.
9  * @author      Christian Wuerdig
10  */
11 #ifndef FIRM_BE_IA32_BEARCH_IA32_T_H
12 #define FIRM_BE_IA32_BEARCH_IA32_T_H
13
14 #include "config.h"
15 #include "pmap.h"
16 #include "debug.h"
17 #include "ia32_nodes_attr.h"
18 #include "set.h"
19 #include "pdeq.h"
20
21 #include "be.h"
22 #include "beemitter.h"
23 #include "beirg.h"
24 #include "gen_ia32_regalloc_if.h"
25
26 #ifdef NDEBUG
27 #define SET_IA32_ORIG_NODE(n, o)
28 #else  /* ! NDEBUG */
29 #define SET_IA32_ORIG_NODE(n, o) set_ia32_orig_node(n, o)
30 #endif /* NDEBUG */
31
32 typedef struct ia32_isa_t            ia32_isa_t;
33 typedef struct ia32_irn_ops_t        ia32_irn_ops_t;
34 typedef struct ia32_intrinsic_env_t  ia32_intrinsic_env_t;
35
36 typedef struct ia32_irg_data_t {
37         ir_node  **blk_sched;     /**< an array containing the scheduled blocks */
38         unsigned do_x87_sim:1;    /**< set to 1 if x87 simulation should be enforced */
39         unsigned dump:1;          /**< set to 1 if graphs should be dumped */
40         ir_node  *noreg_gp;       /**< unique NoReg_GP node */
41         ir_node  *noreg_fp;       /**< unique NoReg_FP node */
42         ir_node  *noreg_xmm;      /**< unique NoReg_XMM node */
43
44         ir_node  *fpu_trunc_mode; /**< truncate fpu mode */
45         ir_node  *get_eip;        /**< get eip node */
46 } ia32_irg_data_t;
47
48 /**
49  * IA32 ISA object
50  */
51 struct ia32_isa_t {
52         arch_env_t             base;     /**< must be derived from arch_env_t */
53         pmap                  *tv_ent;   /**< A map of entities that store const tarvals */
54         int                    fpu_arch; /**< FPU architecture */
55 };
56
57 /**
58  * A helper type collecting needed info for IA32 intrinsic lowering.
59  */
60 struct ia32_intrinsic_env_t {
61         ir_entity  *divdi3;  /**< entity for __divdi3 library call */
62         ir_entity  *moddi3;  /**< entity for __moddi3 library call */
63         ir_entity  *udivdi3; /**< entity for __udivdi3 library call */
64         ir_entity  *umoddi3; /**< entity for __umoddi3 library call */
65 };
66
67 typedef enum transformer_t {
68         TRANSFORMER_DEFAULT,
69 #ifdef FIRM_GRGEN_BE
70         TRANSFORMER_PBQP,
71         TRANSFORMER_RAND
72 #endif
73 } transformer_t;
74
75 #ifdef FIRM_GRGEN_BE
76 /** The selected transformer. */
77 extern transformer_t be_transformer;
78
79 #else
80 #define be_transformer TRANSFORMER_DEFAULT
81 #endif
82
83 /** The mode for the floating point control word. */
84 extern ir_mode *ia32_mode_fpcw;
85 /** extended floatingpoint mode */
86 extern ir_mode *ia32_mode_E;
87 extern ir_type *ia32_type_E;
88
89 static inline ia32_irg_data_t *ia32_get_irg_data(const ir_graph *irg)
90 {
91         return (ia32_irg_data_t*) be_birg_from_irg(irg)->isa_link;
92 }
93
94 static inline void ia32_request_x87_sim(ir_graph const *const irg)
95 {
96         ia32_irg_data_t *const d = ia32_get_irg_data(irg);
97         d->do_x87_sim = true;
98 }
99
100 /**
101  * Returns the unique per irg GP NoReg node.
102  */
103 ir_node *ia32_new_NoReg_gp(ir_graph *irg);
104 ir_node *ia32_new_NoReg_xmm(ir_graph *irg);
105 ir_node *ia32_new_NoReg_fp(ir_graph *irg);
106
107 /**
108  * Returns the unique per irg FPU truncation mode node.
109  */
110 ir_node *ia32_new_Fpu_truncate(ir_graph *irg);
111
112 /**
113  * Split instruction with source AM into Load and separate instruction.
114  * @return result of the Load
115  */
116 ir_node *ia32_turn_back_am(ir_node *node);
117
118 /**
119  * Maps all intrinsic calls that the backend support
120  * and map all instructions the backend did not support
121  * to runtime calls.
122  */
123 void ia32_handle_intrinsics(void);
124
125 /**
126  * Ia32 implementation.
127  *
128  * @param method   the method type of the emulation function entity
129  * @param op       the emulated ir_op
130  * @param imode    the input mode of the emulated opcode
131  * @param omode    the output mode of the emulated opcode
132  * @param context  the context parameter
133  */
134 ir_entity *ia32_create_intrinsic_fkt(ir_type *method, const ir_op *op,
135                                      const ir_mode *imode, const ir_mode *omode,
136                                      void *context);
137
138 /**
139  * Return the stack entity that contains the return address.
140  */
141 ir_entity *ia32_get_return_address_entity(ir_graph *irg);
142
143 /**
144  * Return the stack entity that contains the frame address.
145  */
146 ir_entity *ia32_get_frame_address_entity(ir_graph *irg);
147
148 #endif