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