removed debug setmask
[libfirm] / ir / lower / lower_calls.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/lower/lower_calls.h
4  * Purpose:     lowering of Calls with compound parameters
5  * Author:      Michael Beck
6  * Created:
7  * CVS-ID:      $Id$
8  * Copyright:   (c) 1998-2005 Universität Karlsruhe
9  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
10  */
11
12 /**
13  * @file lower_calls.h
14  *
15  * Lowering of Calls with compound return types.
16  *
17  * @author Michael Beck
18  */
19 #ifndef _LOWER_CALLS_H_
20 #define _LOWER_CALLS_H_
21
22 /**
23  * A type telling where to add hidden parameters.
24  */
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. */
29 } add_hidden;
30
31 /**
32  * Additional flags for the lowering.
33  */
34 enum lowering_flags {
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 */
40 };
41
42 /** Maximum number of registers that can be used to return compound values. */
43 #define MAX_REGISTER_RET_VAL 2
44
45 /**
46  * A struct containing all control parameters for
47  * lower_compound_ret_calls().
48  */
49 typedef struct {
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. */
53
54   /**
55    * A function returning a pointer type for a given type.
56    * If this pointer is NULL, a new pointer type is always created.
57    */
58   ir_type *(*find_pointer_type)(ir_type *e_type, ir_mode *mode, int alignment);
59
60   /**
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.
65    */
66   int (*ret_compound_in_regs)(ir_type *compound_tp, ir_mode **modes);
67 } lower_params_t;
68
69 /**
70  * Lower calls with compound parameter and return types.
71  * This function does the following transformations:
72  *
73  * If LF_COMPOUND_PARAM is set:
74  *
75  * - Copy compound parameters to a new location on the callers
76  *   stack and transmit the address of this new location
77  *
78  * If LF_COMPOUND_RETURN is set:
79  *
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.
83  *
84  * - Use of the hidden parameters in the function code.
85  *
86  * - Change all calls to functions with compound return
87  *   by providing space for the hidden parameter on the callers
88  *   stack.
89  *
90  * - Replace a possible block copy after the function call.
91  *
92  * General:
93  *
94  * - Changes the types of methods and calls to the lowered ones
95  *
96  * - lower all method types of existing entities
97  *
98  * In pseudo-code, the following transformation is done:
99  *
100    @code
101    struct x ret = func(a, b);
102    @endcode
103  *
104  * is translated into
105    @code
106    struct x ret;
107    func(&ret, a, b);
108    @endcode
109  *
110  * If the function returns only one possible result, the copy-on-return
111  * optimization is done, ie.
112    @code
113    struct x func(a) {
114      struct x ret;
115      ret.a = a;
116      return ret;
117    }
118    @endcode
119  *
120  * is transformed into
121  *
122    @code
123    void func(struct x *ret, a) {
124      ret->a = a;
125    }
126    @endcode
127  *
128  * @param params  A structure containing the control parameter for this
129  *                transformation.
130  *
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.
136  */
137 void lower_calls_with_compounds(const lower_params_t *params);
138
139 #endif /* _LOWER_CALLS_H_ */