/*
- * Project: libFIRM
- * File name: ir/lower/lower_calls.c
- * Purpose: lowering of Calls with compound parameters
- * Author: Michael Beck
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 1998-2005 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
+ * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved.
+ *
+ * This file is part of libFirm.
+ *
+ * This file may be distributed and/or modified under the terms of the
+ * GNU General Public License version 2 as published by the Free Software
+ * Foundation and appearing in the file LICENSE.GPL included in the
+ * packaging of this file.
+ *
+ * Licensees holding valid libFirm Professional Edition licenses may use
+ * this file in accordance with the libFirm Commercial License.
+ * Agreement provided with the Software.
+ *
+ * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+ * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE.
+ */
+
+/**
+ * @file
+ * @brief Lowering of Calls with compound parameters and return types.
+ * @author Michael Beck
+ * @version $Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
-#ifdef HAVE_ALLOCA_H
-#include <alloca.h>
-#endif
-#ifdef HAVE_MALLOC_H
-#include <malloc.h>
-#endif
-
+#include "lowering.h"
#include "irprog_t.h"
#include "irnode_t.h"
#include "type_t.h"
#include "ircons.h"
#include "irgmod.h"
#include "irgwalk.h"
-#include "typewalk.h"
-#include "lower_calls.h"
-#include "return.h"
#include "irtools.h"
+#include "iroptimize.h"
#include "array.h"
#include "pmap.h"
+#include "xmalloc.h"
/** A type map for def_find_pointer_type. */
static pmap *type_map;
* might be ignored, we must put it in the list.
*/
(void)get_Call_entry(n, env);
+ break;
}
}
}
*/
static int is_compound_address(ir_type *ft, ir_node *adr)
{
- entity *ent;
+ ir_entity *ent;
if (! is_Sel(adr))
return 0;
/** A pair for the copy-return-optimization. */
typedef struct cr_pair {
- entity *ent; /**< the entity than can be removed from the frame */
+ ir_entity *ent; /**< the entity than can be removed from the frame */
ir_node *arg; /**< the argument that replaces the entities address */
} cr_pair;
int i;
if (is_Sel(n)) {
- entity *ent = get_Sel_entity(n);
+ ir_entity *ent = get_Sel_entity(n);
for (i = ARR_LEN(arr) - 1; i >= 0; --i) {
if (ent == arr[i].ent) {
*/
static ir_node *get_dummy_sel(ir_graph *irg, ir_node *block, ir_type *tp, wlk_env *env)
{
- ir_node *sel;
+ ir_entity *ent;
pmap_entry *e;
/* use a map the check if we already create such an entity */
e = pmap_find(env->dummy_map, tp);
if (e)
- sel = e->value;
+ ent = e->value;
else {
ir_type *ft = get_irg_frame_type(irg);
- entity *ent;
char buf[16];
snprintf(buf, sizeof(buf), "dummy.%u", env->dnr++);
ent = new_entity(ft, new_id_from_str(buf), tp);
- sel = new_r_simpleSel(
- irg,
- block,
- get_irg_no_mem(irg),
- get_irg_frame(irg),
- ent);
- pmap_insert(env->dummy_map, tp, sel);
+ pmap_insert(env->dummy_map, tp, ent);
if (get_type_state(ft) == layout_fixed) {
/* Fix the layout again */
assert(0 && "Fixed layout not implemented");
}
}
- return sel;
+ return new_r_simpleSel(
+ irg,
+ block,
+ get_irg_no_mem(irg),
+ get_irg_frame(irg),
+ ent);
}
/**
*/
static void add_hidden_param(ir_graph *irg, int n_com, ir_node **ins, cl_entry *entry, wlk_env *env)
{
- ir_node *p, *n, *src, *mem;
- entity *ent;
+ ir_node *p, *n, *src, *mem, *blk;
+ ir_entity *ent;
ir_type *owner;
int idx, n_args;
ins[idx] = get_CopyB_dst(p);
mem = get_CopyB_mem(p);
+ blk = get_nodes_block(p);
/* get rid of the CopyB */
turn_into_tuple(p, pn_CopyB_max);
set_Tuple_pred(p, pn_CopyB_M_regular, mem);
- set_Tuple_pred(p, pn_CopyB_M_except, get_irg_bad(irg));
- set_Tuple_pred(p, pn_CopyB_X_except, get_irg_bad(irg));
+ set_Tuple_pred(p, pn_CopyB_M_except, get_irg_bad(irg));
+ set_Tuple_pred(p, pn_CopyB_X_regular, new_r_Jmp(irg, blk));
+ set_Tuple_pred(p, pn_CopyB_X_except, get_irg_bad(irg));
++n_args;
}
*/
static void transform_irg(const lower_params_t *lp, ir_graph *irg)
{
- entity *ent = get_irg_entity(irg);
- ir_type *mtp, *lowered_mtp, *res_tp, *ft;
- int i, j, k, n_ress, n_ret_com, n_cr_opt;
+ ir_entity *ent = get_irg_entity(irg);
+ ir_type *mtp, *lowered_mtp, *tp, *ft;
+ int i, j, k, n_ress = 0, n_ret_com = 0, n_cr_opt;
ir_node **new_in, *ret, *endbl, *bl, *mem, *copy;
cr_pair *cr_opt;
wlk_env env;
assert(ent && "Cannot tranform graph without an entity");
assert(get_irg_phase_state(irg) == phase_high && "call lowering must be done in phase high");
- mtp = get_entity_type(ent);
+ mtp = get_entity_type(ent);
if (lp->flags & LF_COMPOUND_RETURN) {
/* calculate the number of compound returns */
n_ress = get_method_n_ress(mtp);
for (n_ret_com = i = 0; i < n_ress; ++i) {
- res_tp = get_method_res_type(mtp, i);
+ tp = get_method_res_type(mtp, i);
- if (is_compound_type(res_tp))
+ if (is_compound_type(tp))
++n_ret_com;
}
}
n_cr_opt = 0;
for (j = 1, i = k = 0; i < n_ress; ++i) {
ir_node *pred = get_Return_res(ret, i);
- res_tp = get_method_res_type(mtp, i);
+ tp = get_method_res_type(mtp, i);
- if (is_compound_type(res_tp)) {
+ if (is_compound_type(tp)) {
ir_node *arg = get_irg_args(irg);
arg = new_r_Proj(irg, get_nodes_block(arg), arg, mode_P_data, env.first_hidden + k);
++k;
mem,
arg,
pred,
- res_tp
+ tp
);
mem = new_r_Proj(irg, bl, copy, mode_M, pn_CopyB_M_regular);
}
/* fix method entities */
if (is_entity(tore)) {
- entity *ent = (entity *)tore;
+ ir_entity *ent = (ir_entity *)tore;
tp = get_entity_type(ent);
if (must_be_lowered(lp, tp)) {