9a31b42265ac62743953d91adefade770f5602b4
[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  * A struct containing all control parameters for
33  * lower_compound_ret_calls().
34  */
35 typedef struct {
36   int        def_ptr_alignment;   /**< Default alignment for data pointer. */
37   add_hidden hidden_params;       /**< Where to add hidden parameters. */
38
39   /**
40    * A function returning a pointer type for a given type.
41    * If this pointer is NULL, a new pointer type is always created.
42    */
43   ir_type *(*find_pointer_type)(ir_type *e_type, ir_mode *mode, int alignment);
44 } lower_params_t;
45
46 /**
47  * Lower calls with compound return types.
48  * This function does the following transformations:
49  *
50  * - Adds a new (hidden) pointer parameter for
51  *   any return compound type.
52  *
53  * - Use of the hidden parameters in the function code.
54  *
55  * - Change all calls to functions with compound return
56  *   by providing space for the hidden parameter on the callers
57  *   stack.
58  *
59  * - Replace a possible block copy after the function call.
60  *
61  * - Changes the types of methods and calls to the lowered ones
62  *
63  * - lower all method types of existing entities
64  *
65  * In pseudo-code, the following transformation is done:
66  *
67    @code
68    struct x ret = func(a, b);
69    @endcode
70  *
71  * is translated into
72    @code
73    struct x ret;
74    func(&ret, a, b);
75    @endcode
76  *
77  * If the function returns only one possible result, the copy-on-return
78  * optimization is done, ie.
79    @code
80    struct x func(a) {
81      struct x ret;
82      ret.a = a;
83      return ret;
84    }
85    @endcode
86  *
87  * is transformed into
88  *
89    @code
90    void func(struct x *ret, a) {
91      ret->a = a;
92    }
93    @endcode
94  *
95  * @param params  A structure containing the control parameter for this
96  *                transformation.
97  *
98  * During the transformation, pointer types must be created or reused.
99  * The caller can provide params->find_pointer_type for this task to
100  * reduce the number of created pointer types.
101  * If params->find_pointer_type is NULL, new pointer types
102  * are always created automatically.
103  */
104 void lower_compound_ret_calls(const lower_params_t *params);
105
106 #endif /* _LOWER_CALLS_H_ */