9f863253ff60dcd87deeb939ebd0d4a2db88b19d
[libfirm] / ir / lower / lower_mode_b.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       lower mode_b operations to something the backend can handle
23  * @author      Matthias Braun, Christoph Mallon
24  * @version     $Id$
25  *
26  * Most machines can't really manipulate mode_b values (which are usually
27  * modeled as cpu flags). So you often have to convert them into machine words
28  * with the values 0/1 and operate on them instead.
29  *
30  * After this pass the following holds:
31  *   - The only inputs with mode_b are for the Cond node and the Sel input of
32  *     a Mux node.
33  *   - The only nodes producing mode_b are: Proj(Cmp)
34  */
35 #ifndef FIRM_LOWER_MODE_B_H
36 #define FIRM_LOWER_MODE_B_H
37
38 #include "firm_types.h"
39
40 /**
41  * Function which creates a "set" instraction. A "set" instruction takes a
42  * condition value (a value with mode_b) as input and produces a value in a
43  * general purpose integer mode.
44  * Most architectures have special intrinsics for this. But if all else fails
45  * you can just produces the an if-like construct.
46  */
47 typedef ir_node* (*create_set_func)(ir_node *cond);
48
49 /**
50  * implementation of create_set_func which produces a cond with control
51  * flow
52  */
53 ir_node *ir_create_cond_set(ir_node *cond, ir_mode *dest_mode);
54
55 typedef struct lower_mode_b_config_t {
56         /* mode that is used to transport 0/1 values */
57         ir_mode *lowered_mode;
58         /* callback for creating set-like instructions */
59         create_set_func create_set;
60 } lower_mode_b_config_t;
61
62 /**
63  * Lowers mode_b operations to integer arithmetic. After the lowering the only
64  * operations with mode_b are the Projs of Cmps; the only nodes with mode_b
65  * inputs are Cond and Psi nodes.
66  *
67  * Example: Psi(a < 0, 1, 0) => a >> 31
68  *
69  * @param irg      the firm graph to lower
70  * @param config   configuration for mode_b lowerer
71  */
72 void ir_lower_mode_b(ir_graph *irg, const lower_mode_b_config_t *config);
73
74 #endif