693e7a13a9e1268da782ad43bd579044c3822e77
[libfirm] / ir / be / beabihelper.h
1 /*
2  * Copyright (C) 1995-2008 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       Helper functions for handling ABI constraints in the code
23  *              selection phase.
24  * @author      Matthias Braun
25  * @version     $Id$
26  */
27 #ifndef FIRM_BE_BEABI_HELPER_H
28 #define FIRM_BE_BEABI_HELPER_H
29
30 #include "firm_types.h"
31 #include "be_types.h"
32 #include "bearch.h"
33
34 typedef struct beabi_helper_env_t beabi_helper_env_t;
35 typedef struct be_stackorder_t    be_stackorder_t;
36
37 /**
38  * Creates a helper object for the ABI constraint handling.
39  */
40 beabi_helper_env_t *be_abihelper_prepare(ir_graph *irg);
41
42 /**
43  * Terminates a helper object for the ABI constraint handling.
44  */
45 void be_abihelper_finish(beabi_helper_env_t *env);
46
47 /**
48  * Mark a registers value at the beginning of the function as significant.
49  * This is necessary for things like:
50  *  - Callee-Save registers (we need to restore that value at the end)
51  *  - Parameters passed in registers
52  *  - stack pointer, base pointer, ...
53  * It is possible to specify additional irn flags (useful to mark a value
54  * as ignore or produces_sp).
55  */
56 void be_prolog_add_reg(beabi_helper_env_t *env, const arch_register_t *reg,
57                        arch_register_req_type_t flags);
58
59 /**
60  * Creates a start node.
61  * Must be called after all prolog_add_reg calls
62  */
63 ir_node *be_prolog_create_start(beabi_helper_env_t *env, dbg_info *dbgi,
64                                 ir_node *block);
65
66 /**
67  * Get "value" of a register.
68  * This usually creates a Proj node for the start-node.
69  * Or returns the value set by a abi_helper_set_reg_value call
70  */
71 ir_node *be_prolog_get_reg_value(beabi_helper_env_t *env,
72                                  const arch_register_t *reg);
73
74 ir_node *be_prolog_get_memory(beabi_helper_env_t *env);
75
76 /**
77  * Set current register value.
78  */
79 void be_prolog_set_reg_value(beabi_helper_env_t *env,
80                              const arch_register_t *reg, ir_node *value);
81
82 void be_prolog_set_memory(beabi_helper_env_t *env, ir_node *value);
83
84 /**
85  * Set value of register at the end of the function. Necessary for:
86  *  - Callee-save registers
87  *  - Return values in registers
88  *  - stack pointer, base pointer
89  */
90 void be_epilog_add_reg(beabi_helper_env_t *env, const arch_register_t *reg,
91                        arch_register_req_type_t flags, ir_node *value);
92
93 void be_epilog_set_reg_value(beabi_helper_env_t *env,
94                              const arch_register_t *reg, ir_node *value);
95
96 ir_node *be_epilog_get_reg_value(beabi_helper_env_t *env,
97                              const arch_register_t *reg);
98
99 void be_epilog_set_memory(beabi_helper_env_t *env, ir_node *value);
100
101 ir_node *be_epilog_get_memory(beabi_helper_env_t *env);
102
103 void be_epilog_begin(beabi_helper_env_t *env);
104
105 /**
106  * Create return node and finishes epilog handling
107  */
108 ir_node *be_epilog_create_return(beabi_helper_env_t *env, dbg_info *dbgi,
109                                  ir_node *block);
110
111 /**
112  * Adds a X->Proj->Keep for each output value of X which has no Proj yet
113  */
114 void be_add_missing_keeps(ir_graph *irg);
115
116 /**
117  * Make sure all outputs of a node are used, add keeps otherwise
118  */
119 void be_add_missing_keeps_node(ir_node *node);
120
121 /**
122  * In the normal firm representation some nodes like pure calls, builtins
123  * have no memory inputs+outputs. However in the backend these sometimes have to
124  * access the stack to work and therefore suddenly need to be enqueued into the
125  * memory edge again.
126  * This API creates a possible order to enqueue them so we can be sure to create
127  * a legal dependency graph when transforming them.
128  */
129 be_stackorder_t *be_collect_stacknodes(ir_graph *irg);
130
131 /**
132  * return node that should produce the predecessor stack node in a block.
133  * returns NULL if there's no predecessor in the current block.
134  */
135 ir_node *be_get_stack_pred(const be_stackorder_t *env, const ir_node *node);
136
137 /**
138  * free memory associated with a stackorder structure
139  */
140 void be_free_stackorder(be_stackorder_t *env);
141
142 /**
143  * In case where a parameter is transmitted via register but someone takes its
144  * address a store to the frame which can be references is necessary.
145  * This function can be used as a preprocessing phase before transformation to
146  * do this. The assumption is that all parameter_entities which are passed
147  * through the stack are already moved to the arg_type and all remaining
148  * parameter_entities on the frame type need stores.
149  */
150 void be_add_parameter_entity_stores(ir_graph *irg);
151
152 #endif