3 * File name: ir/lower/lower_calls.h
4 * Purpose: lowering of Calls with compound parameters
8 * Copyright: (c) 1998-2005 Universität Karlsruhe
9 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
15 * Lowering of Calls with compound return types.
17 * @author Michael Beck
19 #ifndef _LOWER_CALLS_H_
20 #define _LOWER_CALLS_H_
23 * A type telling where to add hidden parameters.
25 typedef enum add_hidden_params {
26 ADD_HIDDEN_ALWAYS_IN_FRONT = 0, /**< always add hidden parameters in front (default). */
27 ADD_HIDDEN_ALWAYS_LAST = 1, /**< always add hidden parameters last, did not work for variadic functions. */
28 ADD_HIDDEN_SMART = 2 /**< add hidden parameters last for non-variadic and first for variadic functions. */
32 * Additional flags for the lowering.
35 LF_NONE = 0, /**< no additional flags */
36 LF_COMPOUND_PARAM = 1, /**< lower calls with compound parameters */
37 LF_COMPOUND_RETURN = 2, /**< lower calls with compound returns */
38 LF_RETURN_HIDDEN = 4, /**< return the hidden address instead of void */
39 LF_SMALL_CMP_IN_REGS = 8 /**< return small compound values in registers */
42 /** Maximum number of registers that can be used to return compound values. */
43 #define MAX_REGISTER_RET_VAL 2
46 * A struct containing all control parameters for
47 * lower_compound_ret_calls().
50 int def_ptr_alignment; /**< Default alignment for data pointer. */
51 unsigned flags; /**< A bitmask of enum lowering_flags. */
52 add_hidden hidden_params; /**< Where to add hidden parameters. */
55 * A function returning a pointer type for a given type.
56 * If this pointer is NULL, a new pointer type is always created.
58 ir_type *(*find_pointer_type)(ir_type *e_type, ir_mode *mode, int alignment);
61 * If the LF_SMALL_CMP_IN_REGS flag is set, this function will be called
62 * to decide, whether a compound value should be returned in registers.
63 * This function must return the number of used registers and fill in the modes
64 * of the registers to use. Up to MAX_REGISTER_RET_VAL registers can be used.
66 int (*ret_compound_in_regs)(ir_type *compound_tp, ir_mode **modes);
70 * Lower calls with compound parameter and return types.
71 * This function does the following transformations:
73 * If LF_COMPOUND_PARAM is set:
75 * - Copy compound parameters to a new location on the callers
76 * stack and transmit the address of this new location
78 * If LF_COMPOUND_RETURN is set:
80 * - Adds a new (hidden) pointer parameter for
81 * any return compound type. The return type is replaced by void
82 * or if LOWERING_FLAGS_RETURN_HIDDEN is set by the address.
84 * - Use of the hidden parameters in the function code.
86 * - Change all calls to functions with compound return
87 * by providing space for the hidden parameter on the callers
90 * - Replace a possible block copy after the function call.
94 * - Changes the types of methods and calls to the lowered ones
96 * - lower all method types of existing entities
98 * In pseudo-code, the following transformation is done:
101 struct x ret = func(a, b);
110 * If the function returns only one possible result, the copy-on-return
111 * optimization is done, ie.
120 * is transformed into
123 void func(struct x *ret, a) {
128 * @param params A structure containing the control parameter for this
131 * During the transformation, pointer types must be created or reused.
132 * The caller can provide params->find_pointer_type for this task to
133 * reduce the number of created pointer types.
134 * If params->find_pointer_type is NULL, new pointer types
135 * are always created automatically.
137 void lower_calls_with_compounds(const lower_params_t *params);
139 #endif /* _LOWER_CALLS_H_ */