- do not optimize away labeled blocks
[libfirm] / ir / opt / scalar_replace.c
1 /*
2  * Copyright (C) 1995-2008 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   Scalar replacement of compounds.
23  * @author  Beyhan Veliev, Michael Beck
24  * @version $Id$
25  */
26 #include "config.h"
27
28 #include <string.h>
29
30 #include "iroptimize.h"
31 #include "scalar_replace.h"
32 #include "irflag_t.h"
33 #include "irouts.h"
34 #include "set.h"
35 #include "pset.h"
36 #include "array.h"
37 #include "tv.h"
38 #include "ircons_t.h"
39 #include "hashptr.h"
40 #include "irgwalk.h"
41 #include "irgmod.h"
42 #include "irnode_t.h"
43 #include "irtools.h"
44 #include "xmalloc.h"
45 #include "debug.h"
46 #include "error.h"
47
48 #define SET_VNUM(node, vnum) set_irn_link(node, INT_TO_PTR(vnum))
49 #define GET_VNUM(node)       (unsigned)PTR_TO_INT(get_irn_link(node))
50
51 /**
52  * A path element entry: it is either an entity
53  * or a tarval, because we evaluate only constant array
54  * accesses like a.b.c[8].d
55  */
56 typedef union {
57         ir_entity *ent;
58         tarval *tv;
59 } path_elem_t;
60
61 /**
62  * An access path, used to assign value numbers
63  * to variables that will be scalar replaced.
64  */
65 typedef struct _path_t {
66         unsigned    vnum;      /**< The value number. */
67         unsigned    path_len;  /**< The length of the access path. */
68         path_elem_t path[1];   /**< The path. */
69 } path_t;
70
71 /** The size of a path in bytes. */
72 #define PATH_SIZE(p)  (sizeof(*(p)) + sizeof((p)->path[0]) * ((p)->path_len - 1))
73
74 typedef struct _scalars_t {
75         ir_entity *ent;              /**< A entity for scalar replacement. */
76         ir_type *ent_owner;          /**< The owner of this entity. */
77 } scalars_t;
78
79 DEBUG_ONLY(static firm_dbg_module_t *dbg;)
80
81 /**
82  * Compare two pathes.
83  *
84  * @return 0 if they are identically
85  */
86 static int path_cmp(const void *elt, const void *key, size_t size) {
87         const path_t *p1 = elt;
88         const path_t *p2 = key;
89         (void) size;
90
91         /* we can use memcmp here, because identical tarvals should have identical addresses */
92         return memcmp(p1->path, p2->path, p1->path_len * sizeof(p1->path[0]));
93 }
94
95 /**
96  * Compare two elements of the scalars_t set.
97  *
98  * @return 0 if they are identically
99  */
100 static int ent_cmp(const void *elt, const void *key, size_t size) {
101         const scalars_t *c1 = elt;
102         const scalars_t *c2 = key;
103         (void) size;
104
105         return c1->ent != c2->ent;
106 }
107
108 /**
109  * Calculate a hash value for a path.
110  */
111 static unsigned path_hash(const path_t *path) {
112         unsigned hash = 0;
113         unsigned i;
114
115         for (i = 0; i < path->path_len; ++i)
116                 hash ^= (unsigned)PTR_TO_INT(path->path[i].ent);
117
118         return hash >> 4;
119 }
120
121 /**
122  * Returns non-zero, if all indeces of a Sel node are constants.
123  *
124  * @param sel  the Sel node that will be checked
125  */
126 static int is_const_sel(ir_node *sel) {
127         int i, n = get_Sel_n_indexs(sel);
128
129         for (i = 0; i < n; ++i) {
130                 ir_node *idx = get_Sel_index(sel, i);
131
132                 if (!is_Const(idx))
133                         return 0;
134         }
135         return 1;
136 }
137
138 /**
139  * Check the mode of a Load/Store with the mode of the entity
140  * that is accessed.
141  * If the mode of the entity and the Load/Store mode do not match, we
142  * have the bad reinterpret case:
143  *
144  * int i;
145  * char b = *(char *)&i;
146  *
147  * We do NOT count this as one value and return address_taken
148  * in that case.
149  * However, we support an often used case. If the mode is two-complement
150  * we allow casts between signed/unsigned.
151  *
152  * @param mode     the mode of the Load/Store
153  * @param ent_mode the mode of the accessed entity
154  */
155 static int check_load_store_mode(ir_mode *mode, ir_mode *ent_mode) {
156         if (ent_mode != mode) {
157                 if (ent_mode == NULL ||
158                     get_mode_size_bits(ent_mode) != get_mode_size_bits(mode) ||
159                     get_mode_sort(ent_mode) != get_mode_sort(mode) ||
160                     get_mode_arithmetic(ent_mode) != irma_twos_complement ||
161                     get_mode_arithmetic(mode) != irma_twos_complement)
162                         return 0;
163         }
164         return 1;
165 }
166
167 /*
168  * Returns non-zero, if the address of an entity
169  * represented by a Sel node (or it's successor Sels) is taken.
170  */
171 int is_address_taken(ir_node *sel)
172 {
173         int       i, input_nr, k;
174         ir_mode   *emode, *mode;
175         ir_node   *value;
176         ir_entity *ent;
177
178         if (! is_const_sel(sel))
179                 return 1;
180
181         for (i = get_irn_n_outs(sel) - 1; i >= 0; --i) {
182                 ir_node *succ = get_irn_out(sel, i);
183
184                 switch (get_irn_opcode(succ)) {
185                 case iro_Load:
186                         /* do not remove volatile variables */
187                         if (get_Load_volatility(succ) == volatility_is_volatile)
188                                 return 1;
189                         /* check if this load is not a hidden conversion */
190                         mode = get_Load_mode(succ);
191                         ent = get_Sel_entity(sel);
192                         emode = get_type_mode(get_entity_type(ent));
193                         if (! check_load_store_mode(mode, emode))
194                                 return 1;
195                         break;
196
197                 case iro_Store:
198                         /* check that Sel is not the Store's value */
199                         value = get_Store_value(succ);
200                         if (value == sel)
201                                 return 1;
202                         /* do not remove volatile variables */
203                         if (get_Store_volatility(succ) == volatility_is_volatile)
204                                 return 1;
205                         /* check if this Store is not a hidden conversion */
206                         mode = get_irn_mode(value);
207                         ent = get_Sel_entity(sel);
208                         emode = get_type_mode(get_entity_type(ent));
209                         if (! check_load_store_mode(mode, emode))
210                                 return 1;
211                         break;
212
213                 case iro_Sel: {
214                         /* Check the Sel successor of Sel */
215                         int res = is_address_taken(succ);
216
217                         if (res)
218                                 return 1;
219                         break;
220                 }
221
222                 case iro_Call:
223                         /* The address of an entity is given as a parameter.
224                          * As long as we do not have analyses that can tell what
225                          * is done with parameters, think is taken.
226                          * One special case: If the Call type tells that it's a
227                          * value parameter, the address is NOT taken.
228                          */
229                         return 1;
230
231                 case iro_Id: {
232                         int res = is_address_taken(succ);
233                         if (res)
234                                 return 1;
235                         break;
236                 }
237
238                 case iro_Tuple:
239                         /* Non-optimized Tuple, happens in inlining */
240                         for (input_nr = get_Tuple_n_preds(succ) - 1; input_nr >= 0; --input_nr) {
241                                 ir_node *pred = get_Tuple_pred(succ, input_nr);
242
243                                 if (pred == sel) {
244                                         /* we found one input */
245                                         for (k = get_irn_n_outs(succ) - 1; k >= 0; --k) {
246                                                 ir_node *proj = get_irn_out(succ, k);
247
248                                                 if (is_Proj(proj) && get_Proj_proj(proj) == input_nr) {
249                                                         int res = is_address_taken(proj);
250                                                         if (res)
251                                                                 return 1;
252                                                 }
253                                         }
254                                 }
255                         }
256                         break;
257
258                 default:
259                         /* another op, the address is taken */
260                         return 1;
261                 }
262         }
263         return 0;
264 }
265
266 /**
267  * Link all leave Sels with the entity.
268  *
269  * @param ent  the entity that will be scalar replaced
270  * @param sel  a Sel node that selects some fields of this entity
271  */
272 static int link_all_leave_sels(ir_entity *ent, ir_node *sel) {
273         int i, is_leave = 1;
274
275         for (i = get_irn_n_outs(sel) - 1; i >= 0; --i) {
276                 ir_node *succ = get_irn_out(sel, i);
277
278                 if (is_Sel(succ)) {
279                         /* the current leave has further Sel's, no leave */
280                         is_leave = 0;
281                         link_all_leave_sels(ent, succ);
282                 } else if (is_Id(succ)) {
283                         is_leave &= link_all_leave_sels(ent, succ);
284                 }
285         }
286
287         if (is_leave) {
288                 /* beware of Id's */
289                 sel = skip_Id(sel);
290
291                 /* we know we are at a leave, because this function is only
292                  * called if the address is NOT taken, so sel's successor(s)
293                  * must be Loads or Stores
294                  */
295                 set_irn_link(sel, get_entity_link(ent));
296                 set_entity_link(ent, sel);
297         }
298         return is_leave;
299 }
300
301 /* we need a special address that serves as an address taken marker */
302 static char _x;
303 static void *ADDRESS_TAKEN = &_x;
304
305 /**
306  * Find possible scalar replacements.
307  *
308  * @param irg  an IR graph
309  *
310  * This function finds variables on the (members of the) frame type
311  * that can be scalar replaced, because their address is never taken.
312  * If such a variable is found, it's entity link will hold a list of all
313  * Sel nodes, that selects the atomic fields of this entity.
314  * Otherwise, the link will be ADDRESS_TAKEN or NULL.
315  *
316  * @return  non-zero if at least one entity could be replaced
317  *          potentially
318  */
319 static int find_possible_replacements(ir_graph *irg) {
320         ir_node *irg_frame;
321         ir_type *frame_tp;
322         int     i;
323         int     res = 0;
324
325         /*
326          * First, clear the link field of all interesting entities.
327          */
328         frame_tp = get_irg_frame_type(irg);
329         for (i = get_class_n_members(frame_tp) - 1; i >= 0; --i) {
330                 ir_entity *ent = get_class_member(frame_tp, i);
331                 set_entity_link(ent, NULL);
332         }
333
334         /*
335          * Check the ir_graph for Sel nodes. If the entity of Sel
336          * isn't a scalar replacement set the link of this entity
337          * equal ADDRESS_TAKEN.
338          */
339         irg_frame = get_irg_frame(irg);
340         for (i = get_irn_n_outs(irg_frame) - 1; i >= 0; --i) {
341                 ir_node *succ = get_irn_out(irg_frame, i);
342
343                 if (is_Sel(succ)) {
344                         ir_entity *ent = get_Sel_entity(succ);
345                         ir_type *ent_type;
346
347                         if (get_entity_link(ent) == ADDRESS_TAKEN)
348                                 continue;
349
350                         /*
351                          * Beware: in rare cases even entities on the frame might be
352                          * volatile. This might happen if the entity serves as a store
353                          * to a value that must survive a exception. Do not optimize
354                          * such entities away.
355                          */
356                         if (get_entity_volatility(ent) == volatility_is_volatile) {
357                                 set_entity_link(ent, ADDRESS_TAKEN);
358                                 continue;
359                         }
360
361                         ent_type = get_entity_type(ent);
362
363                         /* we can handle arrays, structs and atomic types yet */
364                         if (is_Array_type(ent_type) || is_Struct_type(ent_type) || is_atomic_type(ent_type)) {
365                                 if (is_address_taken(succ)) {
366                                          /* killing one */
367                                         if (get_entity_link(ent))
368                                                 --res;
369                                         set_entity_link(ent, ADDRESS_TAKEN);
370                                 } else {
371                                         /* possible found one */
372                                         if (get_entity_link(ent) == NULL)
373                                                 ++res;
374                                         link_all_leave_sels(ent, succ);
375                                 }
376                         }
377                 }
378         }
379
380         return res;
381 }
382
383 /**
384  * Return a path from the Sel node sel to it's root.
385  *
386  * @param sel  the Sel node
387  * @param len  the length of the path so far
388  */
389 static path_t *find_path(ir_node *sel, unsigned len) {
390         int pos, i, n;
391         path_t *res;
392         ir_node *pred = get_Sel_ptr(sel);
393
394         /* the current Sel node will add some path elements */
395         n    = get_Sel_n_indexs(sel);
396         len += n + 1;
397
398         if (! is_Sel(pred)) {
399                 /* we found the root */
400                 res = XMALLOCF(path_t, path, len);
401                 res->path_len = len;
402         } else
403                 res = find_path(pred, len);
404
405         pos = res->path_len - len;
406
407         res->path[pos++].ent = get_Sel_entity(sel);
408         for (i = 0; i < n; ++i) {
409                 ir_node *index = get_Sel_index(sel, i);
410
411                 res->path[pos++].tv = get_Const_tarval(index);
412         }
413         return res;
414 }
415
416
417 /**
418  * Allocate value numbers for the leaves
419  * in our found entities.
420  *
421  * @param sels  a set that will contain all Sels that have a value number
422  * @param ent   the entity that will be scalar replaced
423  * @param vnum  the first value number we can assign
424  * @param modes a flexible array, containing all the modes of
425  *              the value numbers.
426  *
427  * @return the next free value number
428  */
429 static unsigned allocate_value_numbers(pset *sels, ir_entity *ent, unsigned vnum, ir_mode ***modes)
430 {
431         ir_node *sel, *next;
432         path_t *key, *path;
433         set *pathes = new_set(path_cmp, 8);
434
435         DB((dbg, SET_LEVEL_3, "  Visiting Sel nodes of entity %+F\n", ent));
436         /* visit all Sel nodes in the chain of the entity */
437         for (sel = get_entity_link(ent); sel; sel = next) {
438                 next = get_irn_link(sel);
439
440                 /* we must mark this sel for later */
441                 pset_insert_ptr(sels, sel);
442
443                 key  = find_path(sel, 0);
444                 path = set_find(pathes, key, PATH_SIZE(key), path_hash(key));
445
446                 if (path) {
447                         SET_VNUM(sel, path->vnum);
448                         DB((dbg, SET_LEVEL_3, "  %+F represents value %u\n", sel, path->vnum));
449                 } else {
450                         key->vnum = vnum++;
451
452                         set_insert(pathes, key, PATH_SIZE(key), path_hash(key));
453
454                         SET_VNUM(sel, key->vnum);
455                         DB((dbg, SET_LEVEL_3, "  %+F represents value %u\n", sel, key->vnum));
456
457                         ARR_EXTO(ir_mode *, *modes, (int)((key->vnum + 15) & ~15));
458
459                         (*modes)[key->vnum] = get_type_mode(get_entity_type(get_Sel_entity(sel)));
460
461                         assert((*modes)[key->vnum] && "Value is not atomic");
462
463 #ifdef DEBUG_libfirm
464                         /* Debug output */
465                         {
466                                 unsigned i;
467                                 DB((dbg, SET_LEVEL_2, "  %s", get_entity_name(key->path[0].ent)));
468                                 for (i = 1; i < key->path_len; ++i) {
469                                         if (is_entity(key->path[i].ent))
470                                                 DB((dbg, SET_LEVEL_2, ".%s", get_entity_name(key->path[i].ent)));
471                                         else
472                                                 DB((dbg, SET_LEVEL_2, "[%ld]", get_tarval_long(key->path[i].tv)));
473                                 }
474                                 DB((dbg, SET_LEVEL_2, " = %u (%s)\n", PTR_TO_INT(get_irn_link(sel)), get_mode_name((*modes)[key->vnum])));
475                         }
476 #endif /* DEBUG_libfirm */
477                 }
478                 free(key);
479         }
480
481         del_set(pathes);
482         set_entity_link(ent, NULL);
483         return vnum;
484 }
485
486 /**
487  * A list entry for the fixing lists
488  */
489 typedef struct _list_entry_t {
490         ir_node  *node;   /**< the node that must be fixed */
491         unsigned vnum;    /**< the value number of this node */
492 } list_entry_t;
493
494 /**
495  * environment for memory walker
496  */
497 typedef struct _env_t {
498         int          nvals;       /**< number of values */
499         ir_mode      **modes;     /**< the modes of the values */
500         pset         *sels;       /**< A set of all Sel nodes that have a value number */
501 } env_t;
502
503 /**
504  * topological post-walker.
505  */
506 static void topologic_walker(ir_node *node, void *ctx) {
507         env_t        *env = ctx;
508         ir_node      *adr, *block, *mem, *val;
509         ir_mode      *mode;
510         unsigned     vnum;
511
512         if (is_Load(node)) {
513                 /* a load, check if we can resolve it */
514                 adr = get_Load_ptr(node);
515
516                 DB((dbg, SET_LEVEL_3, "  checking %+F for replacement ", node));
517                 if (! is_Sel(adr)) {
518                         DB((dbg, SET_LEVEL_3, "no Sel input (%+F)\n", adr));
519                         return;
520                 }
521
522                 if (! pset_find_ptr(env->sels, adr)) {
523                         DB((dbg, SET_LEVEL_3, "Sel %+F has no VNUM\n", adr));
524                         return;
525                 }
526
527                 /* ok, we have a Load that will be replaced */
528                 vnum = GET_VNUM(adr);
529                 assert(vnum < (unsigned)env->nvals);
530
531                 DB((dbg, SET_LEVEL_3, "replacing by value %u\n", vnum));
532
533                 block = get_nodes_block(node);
534                 set_cur_block(block);
535
536                 /* check, if we can replace this Load */
537                 val = get_value(vnum, env->modes[vnum]);
538
539                 /* Beware: A Load can contain a hidden conversion in Firm.
540                 This happens for instance in the following code:
541
542                  int i;
543                  unsigned j = *(unsigned *)&i;
544
545                 Handle this here. */
546                 mode = get_Load_mode(node);
547                 if (mode != get_irn_mode(val))
548                         val = new_d_Conv(get_irn_dbg_info(node), val, mode);
549
550                 mem = get_Load_mem(node);
551                 turn_into_tuple(node, pn_Load_max);
552                 set_Tuple_pred(node, pn_Load_M,         mem);
553                 set_Tuple_pred(node, pn_Load_res,       val);
554                 set_Tuple_pred(node, pn_Load_X_regular, new_Jmp());
555                 set_Tuple_pred(node, pn_Load_X_except,  new_Bad());
556         } else if (is_Store(node)) {
557                 DB((dbg, SET_LEVEL_3, "  checking %+F for replacement ", node));
558
559                 /* a Store always can be replaced */
560                 adr = get_Store_ptr(node);
561
562                 if (! is_Sel(adr)) {
563                         DB((dbg, SET_LEVEL_3, "no Sel input (%+F)\n", adr));
564                         return;
565                 }
566
567                 if (! pset_find_ptr(env->sels, adr)) {
568                         DB((dbg, SET_LEVEL_3, "Sel %+F has no VNUM\n", adr));
569                         return;
570                 }
571
572                 vnum = GET_VNUM(adr);
573                 assert(vnum < (unsigned)env->nvals);
574
575                 DB((dbg, SET_LEVEL_3, "replacing by value %u\n", vnum));
576
577                 block = get_nodes_block(node);
578                 set_cur_block(block);
579
580                 /* Beware: A Store can contain a hidden conversion in Firm. */
581                 val = get_Store_value(node);
582                 if (get_irn_mode(val) != env->modes[vnum])
583                         val = new_d_Conv(get_irn_dbg_info(node), val, env->modes[vnum]);
584
585                 set_value(vnum, val);
586
587                 mem = get_Store_mem(node);
588                 turn_into_tuple(node, pn_Store_max);
589                 set_Tuple_pred(node, pn_Store_M,         mem);
590                 set_Tuple_pred(node, pn_Store_X_regular, new_Jmp());
591                 set_Tuple_pred(node, pn_Store_X_except,  new_Bad());
592         }
593 }
594
595 /**
596  * Make scalar replacement.
597  *
598  * @param sels    A set containing all Sel nodes that have a value number
599  * @param nvals   The number of scalars.
600  * @param modes   A flexible array, containing all the modes of
601  *                the value numbers.
602  */
603 static void do_scalar_replacements(pset *sels, int nvals, ir_mode **modes) {
604         env_t env;
605
606         ssa_cons_start(current_ir_graph, nvals);
607
608         env.nvals     = nvals;
609         env.modes     = modes;
610         env.sels      = sels;
611
612         /*
613          * second step: walk over the graph blockwise in topological order
614          * and fill the array as much as possible.
615          */
616         DB((dbg, SET_LEVEL_3, "Substituting Loads and Stores in %+F\n", current_ir_graph));
617         irg_walk_blkwise_graph(current_ir_graph, NULL, topologic_walker, &env);
618
619         ssa_cons_finish(current_ir_graph);
620 }
621
622 /*
623  * Find possible scalar replacements
624  *
625  * @param irg  The current ir graph.
626  */
627 int scalar_replacement_opt(ir_graph *irg) {
628         unsigned  nvals;
629         int       i;
630         scalars_t key, *value;
631         ir_node   *irg_frame;
632         ir_mode   **modes;
633         set       *set_ent;
634         pset      *sels;
635         ir_type   *ent_type;
636         ir_graph  *rem;
637         int       res = 0;
638
639         if (! get_opt_scalar_replacement())
640                 return 0;
641
642         rem = current_ir_graph;
643         current_ir_graph = irg;
644
645         /* Call algorithm that computes the out edges */
646         assure_irg_outs(irg);
647
648         /* we use the link firld to store the VNUM */
649         ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK);
650         irp_reserve_resources(irp,  IR_RESOURCE_ENTITY_LINK);
651
652         /* Find possible scalar replacements */
653         if (find_possible_replacements(irg)) {
654                 DB((dbg, SET_LEVEL_1, "Scalar Replacement: %s\n", get_entity_name(get_irg_entity(irg))));
655
656                 /* Insert in set the scalar replacements. */
657                 irg_frame = get_irg_frame(irg);
658                 nvals = 0;
659                 modes = NEW_ARR_F(ir_mode *, 16);
660                 set_ent = new_set(ent_cmp, 8);
661                 sels    = pset_new_ptr(8);
662
663                 for (i = get_irn_n_outs(irg_frame) - 1; i >= 0; --i) {
664                         ir_node *succ = get_irn_out(irg_frame, i);
665
666                         if (is_Sel(succ)) {
667                                 ir_entity *ent = get_Sel_entity(succ);
668
669                                 if (get_entity_link(ent) == NULL || get_entity_link(ent) == ADDRESS_TAKEN)
670                                         continue;
671
672                                 ent_type = get_entity_type(ent);
673
674                                 key.ent       = ent;
675                                 key.ent_owner = get_entity_owner(ent);
676                                 set_insert(set_ent, &key, sizeof(key), HASH_PTR(key.ent));
677
678 #ifdef DEBUG_libfirm
679                                 if (is_Array_type(ent_type)) {
680                                         DB((dbg, SET_LEVEL_1, "  found array %s\n", get_entity_name(ent)));
681                                 } else if (is_Struct_type(ent_type)) {
682                                         DB((dbg, SET_LEVEL_1, "  found struct %s\n", get_entity_name(ent)));
683                                 } else if (is_atomic_type(ent_type))
684                                         DB((dbg, SET_LEVEL_1, "  found atomic value %s\n", get_entity_name(ent)));
685                                 else {
686                                         panic("Neither an array nor a struct or atomic value found in scalar replace");
687                                 }
688 #endif /* DEBUG_libfirm */
689
690                                 nvals = allocate_value_numbers(sels, ent, nvals, &modes);
691                         }
692                 }
693
694                 DB((dbg, SET_LEVEL_1, "  %u values will be needed\n", nvals));
695
696                 /* If scalars were found. */
697                 if (nvals > 0) {
698                         do_scalar_replacements(sels, nvals, modes);
699
700                         foreach_set(set_ent, value) {
701                                 remove_class_member(value->ent_owner, value->ent);
702                         }
703
704                         /*
705                          * We changed the graph, but did NOT introduce new blocks
706                          * neither changed control flow, cf-backedges should be still
707                          * consistent.
708                          */
709                         set_irg_outs_inconsistent(irg);
710                         set_irg_loopinfo_inconsistent(irg);
711
712                         res = 1;
713                 }
714                 del_pset(sels);
715                 del_set(set_ent);
716                 DEL_ARR_F(modes);
717         }
718
719         ir_free_resources(irg, IR_RESOURCE_IRN_LINK);
720         irp_free_resources(irp, IR_RESOURCE_ENTITY_LINK);
721
722         current_ir_graph = rem;
723         return res;
724 }
725
726 void firm_init_scalar_replace(void) {
727         FIRM_DBG_REGISTER(dbg, "firm.opt.scalar_replace");
728 }