helper functions for doing custom abi construction in codeselection phase
[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
33 typedef struct beabi_helper_env_t beabi_helper_env_t;
34
35 beabi_helper_env_t *be_abihelper_prepare(ir_graph *irg);
36
37 void be_abihelper_finish(beabi_helper_env_t *env);
38
39 /**
40  * Mark a registers value at the beginning of the function as significant.
41  * This is necessary for things like:
42  *  - Callee-Save registers (we need to restore that value at the end)
43  *  - Parameters passed in registers
44  *  - stack pointer, base pointer, ...
45  * It is possible to specify additional irn flags (usefull to mark a value
46  * as ignore or produces_sp).
47  */
48 void be_prolog_add_reg(beabi_helper_env_t *env, const arch_register_t *reg,
49                        arch_irn_flags_t flags);
50
51 /**
52  * Creates a start node.
53  * Must be called after all prolog_add_reg calls
54  */
55 ir_node *be_prolog_create_start(beabi_helper_env_t *env, dbg_info *dbgi,
56                                 ir_node *block);
57
58 /**
59  * Creates a barrier node which lets all registers specified by prolog_add_reg
60  * pass through
61  */
62 ir_node *be_prolog_create_barrier(beabi_helper_env_t *env, ir_node *block);
63
64 /**
65  * Get "value" of a register.
66  * This usually creates a Proj node for the start-node or barrier-node.
67  * Or returns the value set by a abi_helper_set_reg_value call
68  */
69 ir_node *be_prolog_get_reg_value(beabi_helper_env_t *env,
70                                  const arch_register_t *reg);
71
72 ir_node *be_prolog_get_memory(beabi_helper_env_t *env);
73
74 /**
75  * Set current register value.
76  */
77 void be_prolog_set_reg_value(beabi_helper_env_t *env,
78                              const arch_register_t *reg, ir_node *value);
79
80 void be_prolog_set_memory(beabi_helper_env_t *env, ir_node *value);
81
82 /**
83  * Set value of register at the end of the function. Necessary for:
84  *  - Callee-save registers
85  *  - Return values in registers
86  *  - stack pointer, base pointer
87  */
88 void be_epilog_add_reg(beabi_helper_env_t *env, const arch_register_t *reg,
89                        arch_irn_flags_t flags, ir_node *value);
90
91 void be_epilog_set_reg_value(beabi_helper_env_t *env,
92                              const arch_register_t *reg, ir_node *value);
93
94 ir_node *be_epilog_get_reg_value(beabi_helper_env_t *env,
95                              const arch_register_t *reg);
96
97 void be_epilog_set_memory(beabi_helper_env_t *env, ir_node *value);
98
99 ir_node *be_epilog_get_memory(beabi_helper_env_t *env);
100
101 void be_epilog_begin(beabi_helper_env_t *env);
102
103 ir_node *be_epilog_create_barrier(beabi_helper_env_t *env, ir_node *block);
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 /**
113  * Adds a X->Proj->Keep for each output value of X which has no Proj yet
114  */
115 void be_add_missing_keeps(ir_graph *irg);
116
117 #endif