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