0d606bd81d8c214811e11d2114809840b9e39505
[libfirm] / ir / lower / lower_intrinsics.c
1 /*
2  * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief   lowering of Calls of intrinsic functions
23  * @author  Michael Beck
24  * @version $Id$
25  */
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include "lowering.h"
32 #include "irop_t.h"
33 #include "irprog_t.h"
34 #include "irnode_t.h"
35 #include "irprog_t.h"
36 #include "irgwalk.h"
37 #include "ircons.h"
38 #include "irgmod.h"
39 #include "irgopt.h"
40 #include "trouts.h"
41 #include "pmap.h"
42 #include "xmalloc.h"
43
44 /** Walker environment */
45 typedef struct _walker_env {
46         pmap     *c_map;              /**< The intrinsic call map. */
47         unsigned nr_of_intrinsics;    /**< statistics */
48         i_instr_record **i_map;       /**< The intrinsic instruction map. */
49 } walker_env_t;
50
51 /**
52  * walker: call all mapper functions
53  */
54 static void call_mapper(ir_node *node, void *env) {
55         walker_env_t *wenv = env;
56         ir_op *op = get_irn_op(node);
57
58         if (op == op_Call) {
59                 ir_node *symconst;
60                 pmap_entry *p;
61                 const i_call_record *r;
62                 ir_entity *ent;
63
64                 symconst = get_Call_ptr(node);
65                 if (get_irn_op(symconst) != op_SymConst ||
66                         get_SymConst_kind(symconst) != symconst_addr_ent)
67                         return;
68
69                 ent = get_SymConst_entity(symconst);
70                 p   = pmap_find(wenv->c_map, ent);
71
72                 if (p) {
73                         r = p->value;
74                         wenv->nr_of_intrinsics += r->i_mapper(node, r->ctx) ? 1 : 0;
75                 }
76         } else {
77                 if (op->code < (unsigned) ARR_LEN(wenv->i_map)) {
78                         const i_instr_record *r = wenv->i_map[op->code];
79                         /* run all possible mapper */
80                         while (r) {
81                                 if (r->i_mapper(node, r->ctx)) {
82                                         ++wenv->nr_of_intrinsics;
83                                         break;
84                                 }
85                                 r = r->link;
86                         }
87                 }
88         }
89 }
90
91 /* Go through all graphs and map calls to intrinsic functions. */
92 unsigned lower_intrinsics(i_record *list, int length, int part_block_used) {
93         int            i, n_ops = get_irp_n_opcodes();
94         ir_graph       *irg;
95         pmap           *c_map = pmap_create_ex(length);
96         i_instr_record **i_map;
97         unsigned       nr_of_intrinsics = 0;
98         walker_env_t   wenv;
99
100         /* we use the ir_op generic pointers here */
101         NEW_ARR_A(const i_instr_record *, i_map, n_ops);
102         memset((void *)i_map, 0, sizeof(*i_map) * n_ops);
103
104         /* fill a map for faster search */
105         for (i = length - 1; i >= 0; --i) {
106                 if (list[i].i_call.kind == INTRINSIC_CALL) {
107                         pmap_insert(c_map, list[i].i_call.i_ent, (void *)&list[i].i_call);
108                 } else {
109                         ir_op *op = list[i].i_instr.op;
110                         assert(op->code < (unsigned) ARR_LEN(i_map));
111
112                         list[i].i_instr.link = i_map[op->code];
113                         i_map[op->code] = &list[i].i_instr;
114                 }
115         }
116
117         wenv.c_map = c_map;
118         wenv.i_map = i_map;
119
120         for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
121                 irg = get_irp_irg(i);
122
123                 if (part_block_used)
124                         collect_phiprojs(irg);
125
126                 wenv.nr_of_intrinsics = 0;
127                 irg_walk_graph(irg, NULL, call_mapper, &wenv);
128
129                 if (wenv.nr_of_intrinsics) {
130                         /* changes detected */
131                         set_irg_outs_inconsistent(irg);
132                         set_irg_callee_info_state(irg, irg_callee_info_inconsistent);
133
134                         /* exception control flow might have changed */
135                         set_irg_doms_inconsistent(irg);
136                         set_irg_extblk_inconsistent(irg);
137                         set_irg_loopinfo_inconsistent(irg);
138
139                         /* calls might be removed/added */
140                         set_trouts_inconsistent();
141
142                         /* optimize it, tuple might be created */
143                         local_optimize_graph(irg);
144
145                         nr_of_intrinsics += wenv.nr_of_intrinsics;
146                 }
147         }
148         pmap_destroy(c_map);
149
150         return nr_of_intrinsics;
151 }
152
153 /**
154  * Helper function, replace the call by the given node.
155  *
156  * @param irn      the result node
157  * @param call     the call to replace
158  * @param mem      the new mem result
159  * @param reg_jmp  new regular control flow, if NULL, a Jmp will be used
160  * @param exc_jmp  new exception control flow, if reg_jmp == NULL, a Bad will be used
161  */
162 static void replace_call(ir_node *irn, ir_node *call, ir_node *mem, ir_node *reg_jmp, ir_node *exc_jmp) {
163         if (reg_jmp == NULL) {
164                 ir_node *block = get_nodes_block(call);
165
166                 /* Beware: do we need here a protection against CSE? Better we do it. */
167                 int old_cse = get_opt_cse();
168                 set_opt_cse(0);
169                 reg_jmp = new_r_Jmp(current_ir_graph, block);
170                 set_opt_cse(old_cse);
171                 exc_jmp = new_Bad();
172         }
173         irn = new_Tuple(1, &irn);
174
175         turn_into_tuple(call, pn_Call_max);
176         set_Tuple_pred(call, pn_Call_M_regular, mem);
177         set_Tuple_pred(call, pn_Call_X_regular, reg_jmp);
178         set_Tuple_pred(call, pn_Call_X_except, exc_jmp);
179         set_Tuple_pred(call, pn_Call_T_result, irn);
180         set_Tuple_pred(call, pn_Call_M_except, mem);
181         set_Tuple_pred(call, pn_Call_P_value_res_base, new_Bad());
182 }
183
184 /* A mapper for the integer abs. */
185 int i_mapper_abs(ir_node *call, void *ctx) {
186         ir_node *mem   = get_Call_mem(call);
187         ir_node *block = get_nodes_block(call);
188         ir_node *op    = get_Call_param(call, 0);
189         ir_node *irn;
190         dbg_info *dbg  = get_irn_dbg_info(call);
191         (void) ctx;
192
193         irn = new_rd_Abs(dbg, current_ir_graph, block, op, get_irn_mode(op));
194         replace_call(irn, call, mem, NULL, NULL);
195         return 1;
196 }
197
198 /* A mapper for the alloca() function. */
199 int i_mapper_alloca(ir_node *call, void *ctx) {
200         ir_node *mem   = get_Call_mem(call);
201         ir_node *block = get_nodes_block(call);
202         ir_node *op    = get_Call_param(call, 0);
203         ir_node *irn, *exc, *no_exc;
204         dbg_info *dbg  = get_irn_dbg_info(call);
205         (void) ctx;
206
207         irn    = new_rd_Alloc(dbg, current_ir_graph, block, mem, op, firm_unknown_type, stack_alloc);
208         mem    = new_Proj(irn, mode_M, pn_Alloc_M);
209         no_exc = new_Proj(irn, mode_X, pn_Alloc_X_regular);
210         exc    = new_Proj(irn, mode_X, pn_Alloc_X_except);
211         irn    = new_Proj(irn, get_modeP_data(), pn_Alloc_res);
212
213         replace_call(irn, call, mem, no_exc, exc);
214         return 1;
215 }
216
217 /* A mapper for the floating point sqrt. */
218 int i_mapper_sqrt(ir_node *call, void *ctx) {
219         ir_node *mem;
220         tarval *tv;
221         ir_node *op = get_Call_param(call, 0);
222         (void) ctx;
223
224         if (!is_Const(op))
225                 return 0;
226
227         tv = get_Const_tarval(op);
228         if (! tarval_is_null(tv) && !tarval_is_one(tv))
229                 return 0;
230
231         mem = get_Call_mem(call);
232
233         /* sqrt(0) = 0, sqrt(1) = 1 */
234         replace_call(op, call, mem, NULL, NULL);
235         return 1;
236 }
237
238 /* A mapper for the floating point pow. */
239 int i_mapper_pow(ir_node *call, void *ctx) {
240         dbg_info *dbg;
241         ir_node *mem;
242         ir_node *left  = get_Call_param(call, 0);
243         ir_node *right = get_Call_param(call, 1);
244         ir_node *block = get_nodes_block(call);
245         ir_node *irn, *reg_jmp = NULL, *exc_jmp = NULL;
246         (void) ctx;
247
248         if (is_Const(left) && is_Const_one(left)) {
249                 /* pow (1.0, x) = 1.0 */
250                 irn = left;
251         } else if (is_Const(right)) {
252                 tarval *tv = get_Const_tarval(right);
253                 if (tarval_is_null(tv)) {
254                         /* pow(x, 0.0) = 1.0 */
255                         ir_mode *mode = get_tarval_mode(tv);
256                         irn = new_r_Const(current_ir_graph, block, mode, get_mode_one(mode));
257                 } else if (tarval_is_one(tv)) {
258                         /* pow(x, 1.0) = x */
259                         irn = left;
260                 } else if (tarval_is_minus_one(tv)) {
261                         /* pow(x, -1.0) = 1/x */
262                         irn = NULL;
263                 } else
264                         return 0;
265         } else {
266                 return 0;
267         }
268
269         mem = get_Call_mem(call);
270         dbg = get_irn_dbg_info(call);
271
272         if (irn == NULL) {
273                 ir_mode *mode = get_irn_mode(left);
274                 ir_node *quot;
275
276                 irn  = new_r_Const(current_ir_graph, block, mode, get_mode_one(mode));
277                 quot = new_rd_Quot(dbg, current_ir_graph, block, mem, irn, left, mode, op_pin_state_pinned);
278                 mem  = new_r_Proj(current_ir_graph, block, quot, mode_M, pn_Quot_M);
279                 irn  = new_r_Proj(current_ir_graph, block, quot, mode, pn_Quot_res);
280                 reg_jmp = new_r_Proj(current_ir_graph, block, quot, mode_X, pn_Quot_X_regular);
281                 exc_jmp = new_r_Proj(current_ir_graph, block, quot, mode_X, pn_Quot_X_except);
282         }
283         replace_call(irn, call, mem, reg_jmp, exc_jmp);
284         return 1;
285 }
286
287 /* A mapper for the floating point exp. */
288 int i_mapper_exp(ir_node *call, void *ctx) {
289         ir_node *val  = get_Call_param(call, 0);
290         (void) ctx;
291
292         if (is_Const(val) && is_Const_null(val)) {
293                 /* exp(0.0) = 1.0 */
294                 ir_node *block = get_nodes_block(call);
295                 ir_mode *mode  = get_irn_mode(val);
296                 ir_node *irn   = new_r_Const(current_ir_graph, block, mode, get_mode_one(mode));
297                 ir_node *mem   = get_Call_mem(call);
298                 replace_call(irn, call, mem, NULL, NULL);
299                 return 1;
300         }
301         return 0;
302 }
303
304 /* A mapper for the floating point log. */
305 int i_mapper_log(ir_node *call, void *ctx) {
306         ir_node *val  = get_Call_param(call, 0);
307         (void) ctx;
308
309         if (is_Const(val) && is_Const_one(val)) {
310                 /* log(1.0) = 0.0 */
311                 ir_node *block = get_nodes_block(call);
312                 ir_mode *mode  = get_irn_mode(val);
313                 ir_node *irn   = new_r_Const(current_ir_graph, block, mode, get_mode_null(mode));
314                 ir_node *mem   = get_Call_mem(call);
315                 replace_call(val, call, mem, NULL, NULL);
316                 return 1;
317         }
318         return 0;
319 }
320
321 /* A mapper for the floating point sin. */
322 int i_mapper_sin(ir_node *call, void *ctx) {
323         ir_node *val  = get_Call_param(call, 0);
324         (void) ctx;
325
326         if (is_Const(val) && is_Const_null(val)) {
327                 /* sin(0.0) = 0.0 */
328                 ir_node *mem = get_Call_mem(call);
329                 replace_call(val, call, mem, NULL, NULL);
330                 return 1;
331         }
332         return 0;
333 }
334
335 /* A mapper for the floating point cos. */
336 int i_mapper_cos(ir_node *call, void *ctx) {
337         ir_node *val  = get_Call_param(call, 0);
338         (void) ctx;
339
340         if (is_strictConv(val)) {
341                 ir_node *op = get_Conv_op(val);
342                 if (is_Minus(op)) {
343                         /* cos(-x) = cos(x) with strictConv */
344                         ir_node *block = get_nodes_block(call);
345                         ir_mode *mode  = get_irn_mode(val);
346                         dbg_info *dbg  = get_irn_dbg_info(val);
347
348                         op = get_Minus_op(op);
349                         val = new_rd_Conv(dbg, current_ir_graph, block, op, mode);
350                         if (is_Conv(val)) {
351                                 /* still a Conv ? */
352                                 set_Conv_strict(val, 1);
353                         }
354                         set_Call_param(call, 0, val);
355                 }
356         } else if (is_Minus(val)) {
357                 /* cos(-x) = cos(x) */
358                 val = get_Minus_op(val);
359                 set_Call_param(call, 0, val);
360         }
361
362         if (is_Const(val) && is_Const_null(val)) {
363                 /* cos(0.0) = 1.0 */
364                 ir_node *block = get_nodes_block(call);
365                 ir_mode *mode  = get_irn_mode(val);
366                 ir_node *irn   = new_r_Const(current_ir_graph, block, mode, get_mode_one(mode));
367                 ir_node *mem   = get_Call_mem(call);
368                 replace_call(irn, call, mem, NULL, NULL);
369                 return 1;
370         }
371         return 0;
372 }
373
374 /* A mapper for the floating point tan. */
375 int i_mapper_tan(ir_node *call, void *ctx) {
376         ir_node *val  = get_Call_param(call, 0);
377         (void) ctx;
378
379         if (is_Const(val) && is_Const_null(val)) {
380                 /* tan(0.0) = 0.0 */
381                 ir_node *mem = get_Call_mem(call);
382                 replace_call(val, call, mem, NULL, NULL);
383                 return 1;
384         }
385         return 0;
386 }
387
388 /* A mapper for the floating point asin. */
389 int i_mapper_asin(ir_node *call, void *ctx) {
390         ir_node *val  = get_Call_param(call, 0);
391         (void) ctx;
392
393         if (is_Const(val) && is_Const_null(val)) {
394                 /* asin(0.0) = 0.0 */
395                 ir_node *mem = get_Call_mem(call);
396                 replace_call(val, call, mem, NULL, NULL);
397                 return 1;
398         }
399         return 0;
400 }
401
402 /* A mapper for the floating point acos. */
403 int i_mapper_acos(ir_node *call, void *ctx) {
404         ir_node *val  = get_Call_param(call, 0);
405         (void) ctx;
406
407         if (is_Const(val) && is_Const_one(val)) {
408                 /* acos(1.0) = 0.0 */
409                 ir_node *block = get_nodes_block(call);
410                 ir_mode *mode  = get_irn_mode(val);
411                 ir_node *irn   = new_r_Const(current_ir_graph, block, mode, get_mode_null(mode));
412                 ir_node *mem   = get_Call_mem(call);
413                 replace_call(irn, call, mem, NULL, NULL);
414                 return 1;
415         }
416         return 0;
417 }
418
419 /* A mapper for the floating point atan. */
420 int i_mapper_atan(ir_node *call, void *ctx) {
421         ir_node *val  = get_Call_param(call, 0);
422         (void) ctx;
423
424         if (is_Const(val) && is_Const_null(val)) {
425                 /* atan(0.0) = 0.0 */
426                 ir_node *mem = get_Call_mem(call);
427                 replace_call(val, call, mem, NULL, NULL);
428                 return 1;
429         }
430         return 0;
431 }
432
433 /* A mapper for strcmp */
434 int i_mapper_strcmp(ir_node *call, void *ctx) {
435         ir_node *left  = get_Call_param(call, 0);
436         ir_node *right = get_Call_param(call, 1);
437         ir_node *irn;
438         (void) ctx;
439
440         if (left == right) {
441                 /* a strcmp(s, s) ==> 0 */
442                 ir_node   *mem     = get_Call_mem(call);
443                 ir_node   *adr     = get_Call_ptr(call);
444                 ir_entity *ent     = get_SymConst_entity(adr);
445                 ir_type   *call_tp = get_entity_type(ent);
446                 ir_type   *res_tp  = get_method_res_type(call_tp, 0);
447                 ir_mode   *mode    = get_type_mode(res_tp);
448                 ir_node   *block   = get_nodes_block(call);
449
450                 irn = new_r_Const(current_ir_graph, block, mode, get_mode_null(mode));
451                 replace_call(irn, call, mem, NULL, NULL);
452                 return 1;
453         }
454         return 0;
455 }
456
457 /* A mapper for strncmp */
458 int i_mapper_strncmp(ir_node *call, void *ctx) {
459         ir_node *left  = get_Call_param(call, 0);
460         ir_node *right = get_Call_param(call, 1);
461         ir_node *len   = get_Call_param(call, 2);
462         ir_node *irn;
463         (void) ctx;
464
465         if (left == right || (is_Const(len) && is_Const_null(len))) {
466                 /* a strncmp(s, s, len) ==> 0 OR
467                    a strncmp(a, b, 0) ==> 0 */
468                 ir_node   *mem     = get_Call_mem(call);
469                 ir_node   *adr     = get_Call_ptr(call);
470                 ir_entity *ent     = get_SymConst_entity(adr);
471                 ir_type   *call_tp = get_entity_type(ent);
472                 ir_type   *res_tp  = get_method_res_type(call_tp, 0);
473                 ir_mode   *mode    = get_type_mode(res_tp);
474                 ir_node   *block   = get_nodes_block(call);
475
476                 irn = new_r_Const(current_ir_graph, block, mode, get_mode_null(mode));
477                 replace_call(irn, call, mem, NULL, NULL);
478                 return 1;
479         }
480         return 0;
481 }
482
483 /* A mapper for memcpy */
484 int i_mapper_memcpy(ir_node *call, void *ctx) {
485         ir_node *len = get_Call_param(call, 2);
486         (void) ctx;
487
488         if (is_Const(len) && is_Const_null(len)) {
489                 /* a memcpy(d, s, 0) ==> d */
490                 ir_node *mem = get_Call_mem(call);
491                 ir_node *dst = get_Call_param(call, 0);
492
493                 replace_call(dst, call, mem, NULL, NULL);
494                 return 1;
495         }
496         return 0;
497 }
498
499 /* A mapper for memset */
500 int i_mapper_memset(ir_node *call, void *ctx) {
501         ir_node *len = get_Call_param(call, 2);
502         (void) ctx;
503
504         if (is_Const(len) && is_Const_null(len)) {
505                 /* a memset(d, C, 0) ==> d */
506                 ir_node *mem = get_Call_mem(call);
507                 ir_node *dst = get_Call_param(call, 0);
508
509                 replace_call(dst, call, mem, NULL, NULL);
510                 return 1;
511         }
512         return 0;
513 }
514
515 /**
516  * Returns the result mode of a node.
517  */
518 static ir_mode *get_irn_res_mode(ir_node *node) {
519         switch (get_irn_opcode(node)) {
520         case iro_Load:   return get_Load_mode(node);
521         case iro_Quot:   return get_Quot_resmode(node);
522         case iro_Div:    return get_Div_resmode(node);
523         case iro_Mod:    return get_Mod_resmode(node);
524         case iro_DivMod: return get_DivMod_resmode(node);
525         default: return NULL;
526         }
527 }
528
529 #define LMAX(a, b) ((a) > (b) ? (a) : (b))
530
531 /* A mapper for mapping unsupported instructions to runtime calls. */
532 int i_mapper_RuntimeCall(ir_node *node, runtime_rt *rt) {
533         int i, j, arity, first, n_param, n_res;
534         long n_proj;
535         ir_type *mtp;
536         ir_node *mem, *bl, *call, *addr, *res_proj;
537         ir_node **in;
538         ir_graph *irg;
539         symconst_symbol sym;
540         ir_mode *mode = get_irn_mode(node);
541
542         if (mode != rt->mode)
543                 return 0;
544         /* check if the result modes match */
545         if (mode == mode_T && rt->res_mode != NULL) {
546                 mode = get_irn_res_mode(node);
547                 if (mode != rt->res_mode)
548                         return 0;
549         }
550
551         arity = get_irn_arity(node);
552         if (arity <= 0)
553                 return 0;
554
555         mtp     = get_entity_type(rt->ent);
556         n_param = get_method_n_params(mtp);
557         irg     = current_ir_graph;
558
559         mem = get_irn_n(node, 0);
560         if (get_irn_mode(mem) != mode_M) {
561                 mem = new_r_NoMem(irg);
562                 first = 0;
563         } else
564                 first = 1;
565
566         /* check if the modes of the predecessors match the parameter modes */
567         if (arity - first != n_param)
568                 return 0;
569
570         for (i = first, j = 0; i < arity; ++i, ++j) {
571                 ir_type *param_tp = get_method_param_type(mtp, j);
572                 ir_node *pred = get_irn_n(node, i);
573
574                 if (get_type_mode(param_tp) != get_irn_mode(pred))
575                         return 0;
576         }
577
578         n_res = get_method_n_ress(mtp);
579
580         /* step 0: calculate the number of needed Proj's */
581         n_proj = 0;
582         n_proj = LMAX(n_proj, rt->mem_proj_nr + 1);
583         n_proj = LMAX(n_proj, rt->regular_proj_nr + 1);
584         n_proj = LMAX(n_proj, rt->exc_proj_nr + 1);
585         n_proj = LMAX(n_proj, rt->exc_mem_proj_nr + 1);
586         n_proj = LMAX(n_proj, rt->res_proj_nr + 1);
587
588         if (n_proj > 0) {
589                 if (rt->mode != mode_T) /* must be mode_T */
590                         return 0;
591         } else {
592                 if (n_res > 0)
593                         /* must match */
594                         if (get_type_mode(get_method_res_type(mtp, 0)) != rt->mode)
595                                 return 0;
596         }
597
598         /* ok, when we are here, the number of predecessors match as well as the parameter modes */
599         bl = get_nodes_block(node);
600
601         in = NULL;
602         if (n_param > 0) {
603                 NEW_ARR_A(ir_node *, in, n_param);
604                 for (i = 0; i < n_param; ++i)
605                         in[i] = get_irn_n(node, first + i);
606         }
607
608         /* step 1: create the call */
609         sym.entity_p = rt->ent;
610         addr = new_r_SymConst(irg, bl, sym, symconst_addr_ent);
611         call = new_rd_Call(get_irn_dbg_info(node), irg, bl, mem, addr, n_param, in, mtp);
612         set_irn_pinned(call, get_irn_pinned(node));
613
614         if (n_res > 0)
615                 res_proj = new_r_Proj(irg, bl, call, mode_T, pn_Call_T_result);
616         else
617                 res_proj = NULL;
618
619         if (n_proj > 0) {
620                 n_proj += n_res - 1;
621
622                 /* we are ready */
623                 turn_into_tuple(node, n_proj);
624
625                 for (i = 0; i < n_proj; ++i)
626                         set_Tuple_pred(node, i, new_r_Bad(irg));
627                 if (rt->mem_proj_nr >= 0)
628                         set_Tuple_pred(node, rt->mem_proj_nr, new_r_Proj(irg, bl, call, mode_M, pn_Call_M_regular));
629                 if (get_irn_op(mem) != op_NoMem) {
630                         /* Exceptions can only be handled with real memory */
631                         if (rt->regular_proj_nr >= 0)
632                                 set_Tuple_pred(node, rt->regular_proj_nr, new_r_Proj(irg, bl, call, mode_X, pn_Call_X_regular));
633                         if (rt->exc_proj_nr >= 0)
634                                 set_Tuple_pred(node, rt->exc_proj_nr, new_r_Proj(irg, bl, call, mode_X, pn_Call_X_except));
635                         if (rt->exc_mem_proj_nr >= 0)
636                                 set_Tuple_pred(node, rt->mem_proj_nr, new_r_Proj(irg, bl, call, mode_M, pn_Call_M_except));
637                 }
638
639                 if (rt->res_proj_nr >= 0)
640                         for (i = 0; i < n_res; ++i)
641                                 set_Tuple_pred(node, rt->res_proj_nr + i,
642                                 new_r_Proj(irg, bl, res_proj, get_type_mode(get_method_res_type(mtp, i)), i));
643                         return 1;
644         } else {
645                 /* only one return value supported */
646                 if (n_res > 0) {
647                         ir_mode *mode = get_type_mode(get_method_res_type(mtp, 0));
648
649                         res_proj = new_r_Proj(irg, bl, call, mode_T, pn_Call_T_result);
650                         res_proj = new_r_Proj(irg, bl, res_proj, mode, 0);
651
652                         exchange(node, res_proj);
653                         return 1;
654                 }
655         }
656         /* should not happen */
657         return 0;
658 }