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