2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
8 * @brief Helper functions for handling ABI constraints in the code
10 * @author Matthias Braun
12 #ifndef FIRM_BE_BEABI_HELPER_H
13 #define FIRM_BE_BEABI_HELPER_H
15 #include "firm_types.h"
19 typedef struct beabi_helper_env_t beabi_helper_env_t;
20 typedef struct be_stackorder_t be_stackorder_t;
23 * Creates a helper object for the ABI constraint handling.
25 beabi_helper_env_t *be_abihelper_prepare(ir_graph *irg);
28 * Terminates a helper object for the ABI constraint handling.
30 void be_abihelper_finish(beabi_helper_env_t *env);
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).
41 void be_prolog_add_reg(beabi_helper_env_t *env, const arch_register_t *reg,
42 arch_register_req_type_t flags);
45 * Creates a start node.
46 * Must be called after all prolog_add_reg calls
48 ir_node *be_prolog_create_start(beabi_helper_env_t *env, dbg_info *dbgi,
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
56 ir_node *be_prolog_get_reg_value(beabi_helper_env_t *env,
57 const arch_register_t *reg);
59 ir_node *be_prolog_get_memory(beabi_helper_env_t *env);
62 * Set current register value.
64 void be_prolog_set_reg_value(beabi_helper_env_t *env,
65 const arch_register_t *reg, ir_node *value);
67 void be_prolog_set_memory(beabi_helper_env_t *env, ir_node *value);
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
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);
78 void be_epilog_set_reg_value(beabi_helper_env_t *env,
79 const arch_register_t *reg, ir_node *value);
81 ir_node *be_epilog_get_reg_value(beabi_helper_env_t *env,
82 const arch_register_t *reg);
84 void be_epilog_set_memory(beabi_helper_env_t *env, ir_node *value);
86 ir_node *be_epilog_get_memory(beabi_helper_env_t *env);
88 void be_epilog_begin(beabi_helper_env_t *env);
91 * Create return node and finishes epilog handling
93 ir_node *be_epilog_create_return(beabi_helper_env_t *env, dbg_info *dbgi,
97 * Adds a X->Proj->Keep for each output value of X which has no Proj yet
99 void be_add_missing_keeps(ir_graph *irg);
102 * Make sure all outputs of a node are used, add keeps otherwise
104 void be_add_missing_keeps_node(ir_node *node);
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
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.
114 be_stackorder_t *be_collect_stacknodes(ir_graph *irg);
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.
120 ir_node *be_get_stack_pred(const be_stackorder_t *env, const ir_node *node);
123 * free memory associated with a stackorder structure
125 void be_free_stackorder(be_stackorder_t *env);
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.
135 void be_add_parameter_entity_stores(ir_graph *irg);