ecf173cbed601dc97d99c6ed41975834435a838f
[libfirm] / ir / lower / lower_dw.h
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   doubleword lowering operations
23  * @author  Michael Beck, Matthias Braun
24  */
25 #ifndef FIRM_LOWER_LOWER_DW_H
26 #define FIRM_LOWER_LOWER_DW_H
27
28 /**
29  * Every double word node will be replaced,
30  * we need some store to hold the replacement:
31  */
32 typedef struct lower64_entry_t {
33         ir_node *low_word;    /**< the low word */
34         ir_node *high_word;   /**< the high word */
35 } lower64_entry_t;
36
37
38 /**
39  * A callback type for creating an intrinsic entity for a given opcode.
40  *
41  * @param method   the method type of the emulation function entity
42  * @param op       the emulated ir_op
43  * @param imode    the input mode of the emulated opcode
44  * @param omode    the output mode of the emulated opcode
45  * @param context  the context parameter
46  */
47 typedef ir_entity *(create_intrinsic_fkt)(ir_type *method, const ir_op *op,
48                                           const ir_mode *imode,
49                                           const ir_mode *omode, void *context);
50
51 /**
52  * The lowering parameter description.
53  */
54 typedef struct lwrdw_param_t {
55         unsigned              little_endian : 1; /**< if true should be lowered for little endian, else big endian */
56         unsigned              doubleword_size;   /**< bitsize of the doubleword mode */
57         create_intrinsic_fkt *create_intrinsic;  /**< callback that creates the intrinsic entity */
58         void                 *ctx;               /**< context parameter for the creator function */
59 } lwrdw_param_t;
60
61 /**
62  * Prepare the doubleword lowering algorithm. Creates an environment
63  * which can be used to register custom lowering functions
64  */
65 void ir_prepare_dw_lowering(const lwrdw_param_t *param);
66
67 /**
68  * Lower all doubleword operations in the program.
69  * Must be called after ir_prepare_dw_lowering()
70  */
71 void ir_lower_dw_ops(void);
72
73 typedef void (*lower_dw_func)(ir_node *node, ir_mode *mode);
74
75 /**
76  * register a custom lowering function.
77  * After lowering the custom function should call ir_set_dw_lowered()
78  */
79 void ir_register_dw_lower_function(ir_op *op, lower_dw_func func);
80
81 /**
82  * After lowering a node a custom doubleword lowering function has to call this.
83  * It registers 2 new values for the high and low part of the lowered value.
84  */
85 void ir_set_dw_lowered(ir_node *old, ir_node *new_low,
86                                 ir_node *new_high);
87
88 /**
89  * Query lowering results of a node. In a lowering callback you can use this
90  * on all predecessors of a node. The only exception are block and phi nodes.
91  * Their predecessors are not necessarily transformed yet.
92  */
93 lower64_entry_t *get_node_entry(ir_node *node);
94
95 static inline ir_node *get_lowered_low(ir_node *node)
96 {
97         return get_node_entry(node)->low_word;
98 }
99
100 static inline ir_node *get_lowered_high(ir_node *node)
101 {
102         return get_node_entry(node)->high_word;
103 }
104
105 /**
106  * Default implementation. Context is unused.
107  */
108 ir_entity *def_create_intrinsic_fkt(ir_type *method, const ir_op *op,
109                                     const ir_mode *imode, const ir_mode *omode,
110                                     void *context);
111
112 #endif