added new util module
[libfirm] / ir / be / ia32 / ia32_util.c
1 /**
2  * Contains implementation of some useful functions for ia32 backend.
3  * @author Christian Wuerdig
4  * $Id$
5  */
6
7 #include <assert.h>
8
9 #include "irnode.h"
10 #include "iredges.h"
11
12 #include "ia32_util.h"
13
14 /**
15  * Returns the first Proj with given mode connected to irn.
16  * @param irn  The irn
17  * @param First proj with mode == mode or NULL if none found
18  */
19 ir_node *ia32_get_proj_for_mode(const ir_node *irn, ir_mode *mode) {
20         const ir_edge_t *edge;
21         ir_node         *src;
22
23         assert(get_irn_mode(irn) == mode_T && "expected mode_T node");
24
25         foreach_out_edge(irn, edge) {
26                 src = get_edge_src_irn(edge);
27
28                 assert(is_Proj(src) && "Proj expected");
29
30                 if (get_irn_mode(src) == mode_M)
31                         return src;
32         }
33
34         return NULL;
35 }
36
37 /**
38  * Returns the first Proj with mode != mode_M connected to irn.
39  * @param irn  The irn
40  * @param First proj with mode != mode_M or NULL if none found
41  */
42 ir_node *ia32_get_res_proj(const ir_node *irn) {
43         const ir_edge_t *edge;
44         ir_node         *src;
45
46         assert(get_irn_mode(irn) == mode_T && "expected mode_T node");
47
48         foreach_out_edge(irn, edge) {
49                 src = get_edge_src_irn(edge);
50
51                 assert(is_Proj(src) && "Proj expected");
52
53                 if (get_irn_mode(src) != mode_M)
54                         return src;
55         }
56
57         return NULL;
58 }