- first working combo version (at least one example :-), no identities yet
[libfirm] / ir / opt / combo.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   Cliff Click's Combined Analysis/Optimization
23  * @author  Michael Beck
24  * @version $Id$
25  *
26  * Note that we use the terminology from Click's work here, which is different
27  * in some cases from Firm terminology.  Especially, Click's type is a
28  * Firm tarval, nevertheless we call it type here for "maximum compatibility".
29  */
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include <assert.h>
35
36 #include "iroptimize.h"
37 #include "irflag.h"
38 #include "ircons.h"
39 #include "list.h"
40 #include "array.h"
41 #include "set.h"
42 #include "pmap.h"
43 #include "obstack.h"
44 #include "irgraph_t.h"
45 #include "irnode_t.h"
46 #include "iropt_t.h"
47 #include "irgwalk.h"
48 #include "irop.h"
49 #include "irouts.h"
50 #include "irgmod.h"
51 #include "debug.h"
52
53 #include "tv_t.h"
54
55 #include "irprintf.h"
56 #include "irdump.h"
57
58 typedef struct node_t            node_t;
59 typedef struct partition_t       partition_t;
60 typedef struct opcode_key_t      opcode_key_t;
61 typedef struct opcode_entry_t    opcode_entry_t;
62 typedef struct listmap_entry_t   listmap_entry_t;
63
64 /** The type of the compute function. */
65 typedef void (*compute_func)(node_t *node);
66
67 /**
68  * An opcode map key.
69  */
70 struct opcode_key_t {
71         ir_opcode   code;   /**< The Firm opcode. */
72         ir_mode     *mode;  /**< The mode of all nodes in the partition. */
73 };
74
75 /**
76  * An entry in the opcode map.
77  */
78 struct opcode_entry_t {
79         opcode_key_t key;    /**< The key. */
80         partition_t  *part;  /**< The associated partition. */
81 };
82
83 /**
84  * An entry in the list_map.
85  */
86 struct listmap_entry_t {
87         void            *id;    /**< The id. */
88         node_t          *list;  /**< The associated list for this id. */
89         listmap_entry_t *next;  /**< Link to the next entry in the map. */
90 };
91
92 /** We must map id's to lists. */
93 typedef struct listmap_t {
94         set             *map;    /**< Map id's to listmap_entry_t's */
95         listmap_entry_t *values; /**< List of all values in the map. */
96 } listmap_t;
97
98 /**
99  * A lattice element. Because we handle constants and symbolic constants different, we
100  * have to use this union.
101  */
102 typedef union {
103         tarval          *tv;
104         symconst_symbol sym;
105 } lattice_elem_t;
106
107 /**
108  * A node.
109  */
110 struct node_t {
111         ir_node         *node;          /**< The IR-node itself. */
112         list_head       node_list;      /**< Double-linked list of entries. */
113         partition_t     *part;          /**< points to the partition this node belongs to */
114         node_t          *cprop_next;    /**< Next node on partition.cprop list. */
115         node_t          *next;          /**< Next node on local list (partition.touched, fallen). */
116         lattice_elem_t  type;           /**< The associated lattice element "type". */
117         int             max_user_input; /**< Maximum input number of Def-Use edges. */
118         int             next_edge;      /**< Index of the next Def-Use edge to use. */
119         unsigned        on_touched:1;   /**< Set, if this node is on the partition.touched set. */
120         unsigned        on_cprop:1;     /**< Set, if this node is on the partition.cprop list. */
121 };
122
123 /**
124  * A partition containing congruent nodes.
125  */
126 struct partition_t {
127         list_head         entries;         /**< The head of partition node list. */
128         node_t            *cprop;          /**< The partition.cprop list. */
129         partition_t       *wl_next;        /**< Next entry in the work list if any. */
130         partition_t       *touched_next;   /**< Points to the next partition in the touched set. */
131         partition_t       *cprop_next;     /**< Points to the next partition in the cprop list. */
132         node_t            *touched;        /**< The partition.touched set of this partition. */
133         unsigned          n_nodes;         /**< Number of entries in this partition. */
134         unsigned          n_touched;       /**< Number of entries in the partition.touched. */
135         int               max_arity;       /**< Maximum arity of all entries. */
136         int               max_user_inputs; /**< Maximum number of user inputs of all entries. */
137         unsigned          on_worklist:1;   /**< Set, if this partition is in the work list. */
138         unsigned          on_touched:1;    /**< Set, if this partition is on the touched set. */
139         unsigned          on_cprop:1;      /**< Set, if this partition is on the cprop list. */
140 #ifdef DEBUG_libfirm
141         partition_t       *dbg_next;       /**< Link all partitions for debugging */
142         unsigned          nr;              /**< A unique number for (what-)mapping, >0. */
143 #endif
144 };
145
146 typedef struct environment_t {
147         struct obstack  obst;           /**< obstack to allocate data structures. */
148         partition_t     *worklist;      /**< The work list. */
149         partition_t     *cprop;         /**< The constant propagation list. */
150         partition_t     *touched;       /**< the touched set. */
151         partition_t     *initial;       /**< The initial partition. */
152 #ifdef DEBUG_libfirm
153         partition_t     *dbg_list;      /**< List of all partitions. */
154 #endif
155         set             *opcode2id_map; /**< The opcodeMode->id map. */
156         pmap            *type2id_map;   /**< The type->id map. */
157         int             end_idx;        /**< -1 for local and 0 for global congruences. */
158         int             lambda_input;   /**< Captured argument for lambda_partition(). */
159 } environment_t;
160
161 /** Type of the what function. */
162 typedef void *(*what_func)(const node_t *node, environment_t *env);
163
164 #define get_irn_node(irn)         ((node_t *)get_irn_link(irn))
165 #define set_irn_node(irn, node)   set_irn_link(irn, node)
166
167 /** The debug module handle. */
168 DEBUG_ONLY(static firm_dbg_module_t *dbg;)
169
170 /** Next partition number. */
171 DEBUG_ONLY(static unsigned part_nr = 0);
172
173 #ifdef DEBUG_libfirm
174 static lattice_elem_t get_partition_type(const partition_t *X);
175
176 /**
177  * Dump partition to output.
178  */
179 static void dump_partition(const char *msg, const partition_t *part) {
180         const node_t   *node;
181         int            first = 1;
182         lattice_elem_t type = get_partition_type(part);
183
184         DB((dbg, LEVEL_2, "%s part%u (%u, %+F) {\n  ", msg, part->nr, part->n_nodes, type));
185         list_for_each_entry(node_t, node, &part->entries, node_list) {
186                 DB((dbg, LEVEL_2, "%s%+F", first ? "" : ", ", node->node));
187                 first = 0;
188         }
189         DB((dbg, LEVEL_2, "\n}\n"));
190 }
191
192 /**
193  * Dump all partitions.
194  */
195 static void dump_all_partitions(const environment_t *env) {
196         const partition_t *P;
197
198         DB((dbg, LEVEL_2, "All partitions\n===============\n"));
199         for (P = env->dbg_list; P != NULL; P = P->dbg_next)
200                 dump_partition("", P);
201 }
202
203 #else
204 #define dump_partition(msg, part)
205 #define dump_all_partitions(env)
206 #endif
207
208 /**
209  * Compare two pointer values of a listmap.
210  */
211 static int listmap_cmp_ptr(const void *elt, const void *key, size_t size) {
212         const listmap_entry_t *e1 = elt;
213         const listmap_entry_t *e2 = key;
214
215         return e1->id != e2->id;
216 }  /* listmap_cmp_ptr */
217
218 /**
219  * Initializes a listmap.
220  *
221  * @param map  the listmap
222  */
223 static void listmap_init(listmap_t *map) {
224         map->map    = new_set(listmap_cmp_ptr, 16);
225         map->values = NULL;
226 }  /* listmap_init */
227
228 /**
229  * Terminates a listmap.
230  *
231  * @param map  the listmap
232  */
233 static void listmap_term(listmap_t *map) {
234         del_set(map->map);
235 }  /* listmap_term */
236
237 /**
238  * Return the associated listmap entry for a given id.
239  *
240  * @param map  the listmap
241  * @param id   the id to search for
242  *
243  * @return the asociated listmap entry for the given id
244  */
245 static listmap_entry_t *listmap_find(listmap_t *map, void *id) {
246         listmap_entry_t key, *entry;
247
248         key.id   = id;
249         key.list = NULL;
250         key.next = NULL;
251         entry = set_insert(map->map, &key, sizeof(key), HASH_PTR(id));
252
253         if (entry->list == NULL) {
254                 /* a new entry, put into the list */
255                 entry->next = map->values;
256                 map->values = entry;
257         }
258         return entry;
259 }  /* listmap_find */
260
261 /**
262  * Calculate the hash value for an opcode map entry.
263  *
264  * @param entry  an opcode map entry
265  *
266  * @return a hash value for the given opcode map entry
267  */
268 static unsigned opcode_hash(const opcode_key_t *entry) {
269         return (entry->mode - (ir_mode *)0) * 9 + entry->code;
270 }  /* opcode_hash */
271
272 /**
273  * Compare two entries in the opcode map.
274  */
275 static int cmp_opcode(const void *elt, const void *key, size_t size) {
276         const opcode_key_t *o1 = elt;
277         const opcode_key_t *o2 = key;
278
279         return o1->code != o2->code || o1->mode != o2->mode;
280 }  /* cmp_opcode */
281
282 /**
283  * Compare two Def-Use edges for input position.
284  */
285 static int cmp_def_use_edge(const void *a, const void *b) {
286         const ir_def_use_edge *ea = a;
287         const ir_def_use_edge *eb = b;
288
289         /* no overrun, because range is [-1, MAXINT] */
290         return ea->pos - eb->pos;
291 }  /* cmp_def_use_edge */
292
293 /**
294  * We need the Def-Use edges sorted.
295  */
296 static void sort_irn_outs(node_t *node) {
297         ir_node *irn = node->node;
298         int n_outs = get_irn_n_outs(irn);
299
300         if (n_outs > 1) {
301                 qsort(&irn->out[1], n_outs, sizeof(irn->out[0]), cmp_def_use_edge);
302         }
303         node->max_user_input = irn->out[n_outs + 1].pos;
304 }  /* sort_irn_outs */
305
306 /**
307  * Return the type of a node.
308  *
309  * @param irn  an IR-node
310  *
311  * @return the associated type of this node
312  */
313 static INLINE lattice_elem_t get_node_type(const ir_node *irn) {
314         return get_irn_node(irn)->type;
315 }  /* get_node_type */
316
317 /**
318  * Return the tarval of a node.
319  *
320  * @param irn  an IR-node
321  *
322  * @return the associated type of this node
323  */
324 static INLINE tarval *get_node_tarval(const ir_node *irn) {
325         lattice_elem_t type = get_node_type(irn);
326
327         if (is_tarval(type.tv))
328                 return type.tv;
329         return tarval_bottom;
330 }  /* get_node_type */
331
332 /**
333  * Add a partition to the worklist.
334  */
335 static INLINE void add_to_worklist(partition_t *X, environment_t *env) {
336         assert(X->on_worklist == 0);
337         X->wl_next     = env->worklist;
338         X->on_worklist = 1;
339         env->worklist  = X;
340 }
341
342 /**
343  * Create a new empty partition.
344  *
345  * @param env   the environment
346  *
347  * @return a newly allocated partition
348  */
349 static INLINE partition_t *new_partition(environment_t *env) {
350         partition_t *part = obstack_alloc(&env->obst, sizeof(*part));
351
352         INIT_LIST_HEAD(&part->entries);
353         part->cprop           = NULL;
354         part->wl_next         = NULL;
355         part->touched_next    = NULL;
356         part->cprop_next      = NULL;
357         part->touched         = NULL;
358         part->n_nodes         = 0;
359         part->n_touched       = 0;
360         part->max_arity       = 0;
361         part->max_user_inputs = 0;
362         part->on_worklist     = 0;
363         part->on_touched      = 0;
364         part->on_cprop        = 0;
365 #ifdef DEBUG_libfirm
366         part->dbg_next        = env->dbg_list;
367         env->dbg_list         = part;
368         part->nr              = part_nr++;
369 #endif
370
371         return part;
372 }  /* new_partition */
373
374 /**
375  * Get the first node from a partition.
376  */
377 static INLINE node_t *get_first_node(const partition_t *X) {
378         return list_entry(X->entries.next, node_t, node_list);
379 }
380
381 /**
382  * Return the type of a partition (assuming partition is non-empty and
383  * all elements have the same type).
384  *
385  * @param X  a partition
386  *
387  * @return the type of the first element of the partition
388  */
389 static INLINE lattice_elem_t get_partition_type(const partition_t *X) {
390         const node_t *first = get_first_node(X);
391         return first->type;
392 }  /* get_partition_type */
393
394 /**
395  * Creates a partition node for the given IR-node and place it
396  * into the given partition.
397  *
398  * @param irn   an IR-node
399  * @param part  a partition to place the node in
400  * @param env   the environment
401  *
402  * @return the created node
403  */
404 static node_t *create_partition_node(ir_node *irn, partition_t *part, environment_t *env) {
405         /* create a partition node and place it in the partition */
406         node_t *node = obstack_alloc(&env->obst, sizeof(*node));
407         ir_mode *mode = get_irn_mode(irn);
408
409         INIT_LIST_HEAD(&node->node_list);
410         node->node           = irn;
411         node->part           = part;
412         node->cprop_next     = NULL;
413         node->next           = NULL;
414         node->type.tv        = mode == mode_X || mode == mode_BB ? tarval_bottom : tarval_unreachable;
415         node->max_user_input = 0;
416         node->next_edge      = 0;
417         node->on_touched     = 0;
418         node->on_cprop       = 0;
419         set_irn_node(irn, node);
420
421         list_add_tail(&node->node_list, &part->entries);
422         ++part->n_nodes;
423
424         DB((dbg, LEVEL_3, "Placing %+F in partition %u\n", irn, part->nr));
425
426         return node;
427 }  /* create_partition_node */
428
429 /**
430  * Walker, initialize all Nodes' type to U or top and place
431  * all nodes into the TOP partition.
432  */
433 static void create_initial_partitions(ir_node *irn, void *ctx) {
434         environment_t *env  = ctx;
435         partition_t   *part = env->initial;
436         node_t        *node;
437         int           arity;
438
439         node = create_partition_node(irn, part, env);
440         sort_irn_outs(node);
441         arity = get_irn_arity(irn);
442         if (arity > part->max_arity)
443                 part->max_arity = arity;
444         if (node->max_user_input > part->max_user_inputs)
445                 part->max_user_inputs = node->max_user_input;
446 }  /* create_initial_partitions */
447
448 /**
449  * Add a partition to the touched set if not already there.
450  *
451  * @param part  the partition
452  * @param env   the environment
453  */
454 static INLINE void add_to_touched(partition_t *part, environment_t *env) {
455         if (part->on_touched == 0) {
456                 part->touched_next = env->touched;
457                 env->touched       = part;
458                 part->on_touched   = 1;
459         }
460 }  /* add_to_touched */
461
462 /**
463  * Add a node to the entry.partition.touched set if not already there.
464  *
465  * @param y  a node
466  */
467 static INLINE void add_to_partition_touched(node_t *y) {
468         if (y->on_touched == 0) {
469                 partition_t *part = y->part;
470
471                 y->next       = part->touched;
472                 part->touched = y;
473                 y->on_touched = 1;
474                 ++part->n_touched;
475         }
476 }  /* add_to_partition_touched */
477
478 /**
479  * Update the worklist: If Z is on worklist then add Z' to worklist.
480  * Else add the smaller of Z and Z' to worklist.
481  *
482  * @param Z        the Z partition
483  * @param Z_prime  the Z' partition, a previous part of Z
484  * @param env      the environment
485  */
486 static void update_worklist(partition_t *Z, partition_t *Z_prime, environment_t *env) {
487         if (Z->on_worklist || Z_prime->n_nodes < Z->n_nodes) {
488                 add_to_worklist(Z_prime, env);
489         } else {
490                 add_to_worklist(Z, env);
491         }
492 }  /* update_worklist */
493
494 /**
495  * Split a partition by a local list.
496  *
497  * @param Z    the Z partition to split
498  * @param g    a (non-empty) node list
499  * @param env  the environment
500  *
501  * @return  a new partition containing the nodes of g
502  */
503 static partition_t *split(partition_t *Z, node_t *g, environment_t *env) {
504         partition_t *Z_prime;
505         node_t      *node;
506         unsigned    n = 0;
507         int         max_input, max_arity, arity;
508
509         dump_partition("Splitting ", Z);
510
511         assert(g != NULL);
512
513         /* Remove g from Z. */
514         for (node = g; node != NULL; node = node->next) {
515                 list_del(&node->node_list);
516                 ++n;
517         }
518         assert(n < Z->n_nodes);
519         Z->n_nodes -= n;
520
521         /* Move g to a new partition, Z\92. */
522         Z_prime = new_partition(env);
523         max_arity = max_input = 0;
524         for (node = g; node != NULL; node = node->next) {
525                 list_add(&node->node_list, &Z_prime->entries);
526                 node->part = Z_prime;
527                 arity = get_irn_arity(node->node);
528                 if (arity > max_arity)
529                         max_arity = arity;
530                 if (node->max_user_input > max_input)
531                         max_input = node->max_user_input;
532         }
533         Z_prime->max_arity       = max_arity;
534         Z_prime->max_user_inputs = max_input;
535         Z_prime->n_nodes         = n;
536
537         update_worklist(Z, Z_prime, env);
538
539         dump_partition("Now ", Z);
540         dump_partition("Created new ", Z_prime);
541         return Z_prime;
542 }  /* split */
543
544 /**
545  * Returns non-zero if the i'th input of a Phi node is live.
546  *
547  * @param phi  a Phi-node
548  * @param i    an input number
549  *
550  * @return non-zero if the i'th input of the given Phi node is live
551  */
552 static int is_live_input(ir_node *phi, int i) {
553         if (i >= 0) {
554                 ir_node        *block = get_nodes_block(phi);
555                 ir_node        *pred  = get_Block_cfgpred(block, i);
556                 lattice_elem_t type   = get_node_type(pred);
557
558                 return type.tv != tarval_unreachable;
559         }
560         /* else it's the control input, always live */
561         return 1;
562 }  /* is_live_input */
563
564 /**
565  * Return non-zero if a type is a constant.
566  */
567 static int is_constant_type(lattice_elem_t type) {
568         if (type.tv != tarval_bottom && type.tv != tarval_top)
569                 return 1;
570         return 0;
571 }  /* is_constant_type */
572
573 /**
574  * Place a node on the cprop list.
575  *
576  * @param y    the node
577  * @param env  the environment
578  */
579 static void add_node_to_cprop(node_t *y, environment_t *env) {
580         /* Add y to y.partition.cprop. */
581         if (y->on_cprop == 0) {
582                 partition_t *Y = y->part;
583
584                 y->cprop_next  = Y->cprop;
585                 Y->cprop = y;
586                 y->on_cprop    = 1;
587
588                 DB((dbg, LEVEL_3, "Add %+F to part%u.cprop\n", y->node, Y->nr));
589
590                 /* place its partition on the cprop list */
591                 if (Y->on_cprop == 0) {
592                         Y->cprop_next = env->cprop;
593                         env->cprop    = Y;
594                         Y->on_cprop   = 1;
595                 }
596         }
597         if (get_irn_mode(y->node) == mode_T) {
598                 /* mode_T nodes always produce tarval_bottom, so we must explicitly
599                    add it's Proj's to get constant evaluation to work */
600                 int i;
601
602                 for (i = get_irn_n_outs(y->node) - 1; i >= 0; --i) {
603                         node_t *proj = get_irn_node(get_irn_out(y->node, i));
604
605                         add_node_to_cprop(proj, env);
606                 }
607         }
608 }  /* add_node_to_cprop */
609
610 /**
611  * Split the partitions if caused by the first entry on the worklist.
612  *
613  * @param env  the environment
614  */
615 static void cause_splits(environment_t *env) {
616         partition_t *X, *Y, *Z;
617         node_t      *x, *y, *e;
618         int         i, end_idx;
619         ir_opcode   code;
620         ir_node     *succ;
621
622         /* remove the first partition from the worklist */
623         X = env->worklist;
624         env->worklist  = X->wl_next;
625         X->on_worklist = 0;
626
627         dump_partition("Cause_split: ", X);
628         end_idx = env->end_idx;
629         for (i = -1; i <= X->max_user_inputs; ++i) {
630                 /* empty the touched set: already done, just clear the list */
631                 env->touched = NULL;
632
633                 list_for_each_entry(node_t, x, &X->entries, node_list) {
634                         int num_edges;
635
636                         if (i == -1) {
637                                 x->next_edge = 1;
638                         }
639                         num_edges = get_irn_n_outs(x->node);
640
641                         while (x->next_edge <= num_edges) {
642                                 ir_def_use_edge *edge = &x->node->out[x->next_edge];
643
644                                 /* check if we have necessary edges */
645                                 if (edge->pos > i)
646                                         break;
647
648                                 ++x->next_edge;
649
650                                 succ = edge->use;
651
652                                 /* ignore the "control input" for non-pinned nodes
653                                    if we are running in GCSE mode */
654                                 if (i < end_idx && get_irn_pinned(succ) != op_pin_state_pinned)
655                                         continue;
656
657                                 y = get_irn_node(succ);
658                                 if (is_constant_type(y->type)) {
659                                         code = get_irn_opcode(succ);
660                                         if (code == iro_Sub || (code == iro_Proj && is_Cmp(get_Proj_pred(succ))))
661                                                 add_node_to_cprop(y, env);
662                                 }
663
664                                 /* Partitions of constants should not be split simply because their Nodes have unequal
665                                    functions or incongruent inputs. */
666                                 if (y->type.tv == tarval_bottom &&
667                                         (! is_Phi(x->node) || is_live_input(x->node, i))) {
668                                         Y = y->part;
669                                         add_to_touched(Y, env);
670                                         add_to_partition_touched(y);
671                                 }
672                         }
673                 }
674
675                 for (Z = env->touched; Z != NULL; Z = Z->touched_next) {
676                         /* remove it from the touched set */
677                         Z->on_touched = 0;
678
679                         if (Z->n_nodes != Z->n_touched) {
680                                 split(Z, Z->touched, env);
681                         }
682                         /* Empty local Z.touched. */
683                         for (e = Z->touched; e != NULL; e = e->next) {
684                                 e->on_touched = 0;
685                         }
686                         Z->touched   = NULL;
687                         Z->n_touched = 0;
688                 }
689         }
690 }  /* cause_splits */
691
692 /**
693  * Implements split_by_what(): Split a partition by characteristics given
694  * by the what function.
695  *
696  * @param X     the partition to split
697  * @param What  a function returning an Id for every node of the partition X
698  * @param P     an flexible array to store the result partitions or NULL
699  * @param env   the environment
700  *
701  * @return if P != NULL P will be filled with the resulting partitions and returned
702  */
703 static partition_t **split_by_what(partition_t *X, what_func What,
704                                                                   partition_t **P, environment_t *env) {
705         node_t          *x, *S;
706         listmap_t       map;
707         listmap_entry_t *iter;
708         partition_t     *R;
709
710         /* Let map be an empty mapping from the range of What to (local) list of Nodes. */
711         listmap_init(&map);
712         list_for_each_entry(node_t, x, &X->entries, node_list) {
713                 void            *id = What(x, env);
714                 listmap_entry_t *entry;
715
716                 if (id == NULL) {
717                         /* input not allowed, ignore */
718                         continue;
719                 }
720                 /* Add x to map[What(x)]. */
721                 entry = listmap_find(&map, id);
722                 x->next     = entry->list;
723                 entry->list = x;
724         }
725         /* Let P be a set of Partitions. */
726
727         /* for all sets S except one in the range of map do */
728         for (iter = map.values; iter != NULL; iter = iter->next) {
729                 if (iter->next == NULL) {
730                         /* this is the last entry, ignore */
731                         break;
732                 }
733                 S = iter->list;
734
735                 /* Add SPLIT( X, S ) to P. */
736                 R = split(X, S, env);
737                 if (P != NULL) {
738                         ARR_APP1(partition_t *, P, R);
739                 }
740         }
741         /* Add X to P. */
742         if (P != NULL) {
743                 ARR_APP1(partition_t *, P, X);
744         }
745
746         listmap_term(&map);
747         return P;
748 }  /* split_by_what */
749
750 /** lambda n.(n.type) */
751 static void *lambda_type(const node_t *node, environment_t *env) {
752         (void)env;
753         return node->type.tv;
754 }  /* lambda_type */
755
756 /** lambda n.(n.opcode) */
757 static void *lambda_opcode(const node_t *node, environment_t *env) {
758         opcode_key_t key, *entry;
759
760         key.code = get_irn_opcode(node->node);
761         key.mode = get_irn_mode(node->node);
762         entry = set_insert(env->opcode2id_map, &key, sizeof(key), opcode_hash(&key));
763         return entry;
764 }  /* lambda_opcode */
765
766 /** lambda n.(n[i].partition) */
767 static void *lambda_partition(const node_t *node, environment_t *env) {
768         ir_node *pred;
769         node_t  *p;
770         int     i = env->lambda_input;
771
772         if (i >= get_irn_arity(node->node)) {
773                 /* we are outside the allowed range */
774                 return NULL;
775         }
776
777         /* ignore the "control input" for non-pinned nodes
778            if we are running in GCSE mode */
779         if (i < env->end_idx && get_irn_pinned(node->node) != op_pin_state_pinned)
780                 return NULL;
781
782         pred = get_irn_n(node->node, i);
783         p    = get_irn_node(pred);
784
785         return p->part;
786 }  /* lambda_partition */
787
788 /**
789  * Checks whether a type is a constant.
790  */
791 static int is_type_constant(lattice_elem_t type) {
792         if (is_tarval(type.tv))
793                 return tarval_is_constant(type.tv);
794         /* else it is a symconst */
795         return 1;
796 }
797
798 /**
799  * Implements split_by().
800  *
801  * @param X    the partition to split
802  * @param env  the environment
803  */
804 static void split_by(partition_t *X, environment_t *env) {
805         partition_t **P = NEW_ARR_F(partition_t *, 0);
806         int         i, j, k;
807
808         P = split_by_what(X, lambda_type, P, env);
809         for (i = ARR_LEN(P) - 1; i >= 0; --i) {
810                 partition_t    *Y = P[i];
811
812                 if (Y->n_nodes > 1) {
813                         lattice_elem_t type = get_partition_type(Y);
814
815                         /* we do not want split the TOP, unreachable or constant partitions */
816                         if (type.tv != tarval_top && type.tv != tarval_unreachable && !is_type_constant(type)) {
817                                 partition_t **Q = NEW_ARR_F(partition_t *, 0);
818
819                                 Q = split_by_what(Y, lambda_opcode, Q, env);
820
821                                 for (j = ARR_LEN(Q) - 1; j >= 0; --j) {
822                                         partition_t *Z = Q[j];
823
824                                         for (k = Z->max_arity - 1; k >= -1; --k) {
825                                                 if (Z->n_nodes > 1) {
826                                                         env->lambda_input = k;
827                                                         split_by_what(Z, lambda_partition, NULL, env);
828                                                 }
829                                         }
830                                 }
831                                 DEL_ARR_F(Q);
832                         }
833                 }
834         }
835         DEL_ARR_F(P);
836 }  /* split_by */
837
838 /**
839  * (Re-)compute the type for a given node.
840  *
841  * @param node  the node
842  */
843 static void default_compute(node_t *node) {
844         int     i;
845         ir_node *irn = node->node;
846
847         if (get_irn_pinned(irn) == op_pin_state_pinned) {
848                 node_t *block = get_irn_node(get_nodes_block(irn));
849
850                 if (block->type.tv == tarval_unreachable) {
851                         node->type.tv = tarval_top;
852                         return;
853                 }
854         }
855
856         /* if any of the data inputs have type top, the result is type top */
857         for (i = get_irn_arity(irn) - 1; i >= 0; --i) {
858                 ir_node *pred = get_irn_n(irn, i);
859                 node_t  *p    = get_irn_node(pred);
860
861                 if (p->type.tv == tarval_top) {
862                         node->type.tv = tarval_top;
863                         return;
864                 }
865         }
866
867         node->type.tv = computed_value(irn);
868 }  /* default_compute */
869
870 /**
871  * (Re-)compute the type for a Block node.
872  *
873  * @param node  the node
874  */
875 static void compute_Block(node_t *node) {
876         int     i;
877         ir_node *block = node->node;
878
879         for (i = get_Block_n_cfgpreds(block) - 1; i >= 0; --i) {
880                 node_t *pred = get_irn_node(get_Block_cfgpred(block, i));
881
882                 if (pred->type.tv == tarval_reachable) {
883                         /* A block is reachable, if at least of predecessor is reachable. */
884                         node->type.tv = tarval_reachable;
885                         return;
886                 }
887         }
888         node->type.tv = tarval_unreachable;
889 }  /* compute_Block */
890
891 /**
892  * (Re-)compute the type for a Jmp node.
893  *
894  * @param node  the node
895  */
896 static void compute_Jmp(node_t *node) {
897         node_t *block = get_irn_node(get_nodes_block(node->node));
898
899         node->type = block->type;
900 }  /* compute_Jmp */
901
902 /**
903  * (Re-)compute the type for the End node.
904  *
905  * @param node  the node
906  */
907 static void compute_End(node_t *node) {
908         /* the End node is NOT dead of course */
909         node->type.tv = tarval_reachable;
910 }
911
912 /**
913  * (Re-)compute the type for a SymConst node.
914  *
915  * @param node  the node
916  */
917 static void compute_SymConst(node_t *node) {
918         ir_node *irn = node->node;
919         node_t  *block = get_irn_node(get_nodes_block(irn));
920
921         if (block->type.tv == tarval_unreachable) {
922                 node->type.tv = tarval_top;
923                 return;
924         }
925         switch (get_SymConst_kind(irn)) {
926         case symconst_addr_ent:
927         case symconst_addr_name:
928                 node->type.sym = get_SymConst_symbol(irn);
929                 break;
930         default:
931                 node->type.tv = computed_value(irn);
932         }
933 }  /* compute_SymConst */
934
935 /**
936  * (Re-)compute the type for a Phi node.
937  *
938  * @param node  the node
939  */
940 static void compute_Phi(node_t *node) {
941         int            i;
942         ir_node        *phi = node->node;
943         lattice_elem_t type;
944
945         /* if a Phi is in a unreachable block, its type is TOP */
946         node_t *block = get_irn_node(get_nodes_block(phi));
947
948         if (block->type.tv == tarval_unreachable) {
949                 node->type.tv = tarval_top;
950                 return;
951         }
952
953         /* Phi implements the Meet operation */
954         type.tv = tarval_top;
955         for (i = get_Phi_n_preds(phi) - 1; i >= 0; --i) {
956                 node_t *pred = get_irn_node(get_Phi_pred(phi, i));
957
958                 if (pred->type.tv == tarval_top) {
959                         /* ignore TOP inputs */
960                         continue;
961                 }
962                 if (pred->type.tv == tarval_bottom) {
963                         node->type.tv = tarval_bottom;
964                         return;
965                 } else if (type.tv == tarval_top) {
966                         /* first constant found */
967                         type = pred->type;
968                 } else if (type.tv != pred->type.tv) {
969                         /* different constants or tarval_bottom */
970                         node->type.tv = tarval_bottom;
971                         return;
972                 }
973                 /* else nothing, constants are the same */
974         }
975         node->type = type;
976 }  /* compute_Phi */
977
978 /**
979  * (Re-)compute the type for an Add. Special case: one nodes is a Zero Const.
980  *
981  * @param node  the node
982  */
983 static void compute_Add(node_t *node) {
984         ir_node        *sub = node->node;
985         node_t         *l   = get_irn_node(get_Add_left(sub));
986         node_t         *r   = get_irn_node(get_Add_right(sub));
987         lattice_elem_t a    = l->type;
988         lattice_elem_t b    = r->type;
989         node_t         *block = get_irn_node(get_nodes_block(sub));
990         ir_mode        *mode;
991
992         if (block->type.tv == tarval_unreachable) {
993                 node->type.tv = tarval_top;
994                 return;
995         }
996
997         if (a.tv == tarval_top || b.tv == tarval_top) {
998                 node->type.tv = tarval_top;
999         } else if (a.tv == tarval_bottom || b.tv == tarval_bottom) {
1000                 node->type.tv = tarval_bottom;
1001         } else {
1002                 /* x + 0 = 0 + x = x, but beware of floating point +0 + -0, so we
1003                    must call tarval_add() first to handle this case! */
1004                 if (is_tarval(a.tv)) {
1005                         if (is_tarval(b.tv)) {
1006                                 node->type.tv = tarval_add(a.tv, b.tv);
1007                                 return;
1008                         }
1009                         mode = get_tarval_mode(a.tv);
1010                         if (a.tv == get_mode_null(mode)) {
1011                                 node->type = b;
1012                                 return;
1013                         }
1014                 } else if (is_tarval(b.tv)) {
1015                         mode = get_tarval_mode(b.tv);
1016                         if (b.tv == get_mode_null(mode)) {
1017                                 node->type = a;
1018                                 return;
1019                         }
1020                 }
1021                 node->type.tv = tarval_bottom;
1022         }
1023 }  /* compute_Add */
1024
1025 /**
1026  * (Re-)compute the type for a Sub. Special case: both nodes are congruent.
1027  *
1028  * @param node  the node
1029  */
1030 static void compute_Sub(node_t *node) {
1031         ir_node        *sub = node->node;
1032         node_t         *l   = get_irn_node(get_Sub_left(sub));
1033         node_t         *r   = get_irn_node(get_Sub_right(sub));
1034         lattice_elem_t a    = l->type;
1035         lattice_elem_t b    = r->type;
1036         node_t         *block = get_irn_node(get_nodes_block(sub));
1037
1038         if (block->type.tv == tarval_unreachable) {
1039                 node->type.tv = tarval_top;
1040                 return;
1041         }
1042
1043         if (a.tv == tarval_top || b.tv == tarval_top) {
1044                 node->type.tv = tarval_top;
1045         } else if (r->part == l->part) {
1046                 ir_mode *mode = get_irn_mode(sub);
1047                 node->type.tv = get_mode_null(mode);
1048         } else if (a.tv == tarval_bottom || b.tv == tarval_bottom) {
1049                 node->type.tv = tarval_bottom;
1050         } else {
1051                 if (is_tarval(a.tv) && is_tarval(b.tv))
1052                         node->type.tv = tarval_sub(a.tv, b.tv);
1053                 else
1054                         node->type.tv = tarval_bottom;
1055         }
1056 }  /* compute_Sub */
1057
1058 /**
1059  * (Re-)compute the type for a Proj(Cmp).
1060  *
1061  * @param node  the node
1062  * @param cond  the predecessor Cmp node
1063  */
1064 static void compute_Proj_Cmp(node_t *node, ir_node *cmp) {
1065         ir_node        *proj = node->node;
1066         node_t         *l    = get_irn_node(get_Cmp_left(cmp));
1067         node_t         *r    = get_irn_node(get_Cmp_right(cmp));
1068         lattice_elem_t a     = l->type;
1069         lattice_elem_t b     = r->type;
1070         pn_Cmp         pnc   = get_Proj_proj(proj);
1071
1072         /*
1073          * BEWARE: a == a is NOT always True for floating Point values, as
1074          * NaN != NaN is defined, so we must check this here.
1075          */
1076         if (!mode_is_float(get_irn_mode(l->node)) || pnc == pn_Cmp_Lt ||  pnc == pn_Cmp_Gt) {
1077                 if (a.tv == tarval_top || b.tv == tarval_top) {
1078                         node->type.tv = tarval_top;
1079                 } else if (r->part == l->part) {
1080                         node->type.tv = new_tarval_from_long(pnc & pn_Cmp_Eq, mode_b);
1081                 } else if (a.tv == tarval_bottom || b.tv == tarval_bottom) {
1082                         node->type.tv = tarval_bottom;
1083                 } else {
1084                         default_compute(node);
1085                 }
1086         } else {
1087                 default_compute(node);
1088         }
1089 }  /* compute_Proj_Cmp */
1090
1091 /**
1092  * (Re-)compute the type for a Proj(Cond).
1093  *
1094  * @param node  the node
1095  * @param cond  the predecessor Cond node
1096  */
1097 static void compute_Proj_Cond(node_t *node, ir_node *cond) {
1098         ir_node *proj     = node->node;
1099         long    pnc       = get_Proj_proj(proj);
1100         ir_node *sel      = get_Cond_selector(cond);
1101         node_t  *selector = get_irn_node(sel);
1102
1103         if (get_irn_mode(sel) == mode_b) {
1104                 /* an IF */
1105                 if (pnc == pn_Cond_true) {
1106                         if (selector->type.tv == tarval_b_false) {
1107                                 node->type.tv = tarval_unreachable;
1108                         } else if (selector->type.tv == tarval_b_true) {
1109                                 node->type.tv = tarval_reachable;
1110                         } else if (selector->type.tv == tarval_bottom) {
1111                                 node->type.tv = tarval_reachable;
1112                         } else {
1113                                 assert(selector->type.tv == tarval_top);
1114                                 node->type.tv = tarval_unreachable;
1115                         }
1116                 } else {
1117                         assert(pnc == pn_Cond_false);
1118
1119                         if (selector->type.tv == tarval_b_false) {
1120                                 node->type.tv = tarval_reachable;
1121                         } else if (selector->type.tv == tarval_b_true) {
1122                                 node->type.tv = tarval_unreachable;
1123                         } else if (selector->type.tv == tarval_bottom) {
1124                                 node->type.tv = tarval_reachable;
1125                         } else {
1126                                 assert(selector->type.tv == tarval_top);
1127                                 node->type.tv = tarval_unreachable;
1128                         }
1129                 }
1130         } else {
1131                 /* an SWITCH */
1132                 if (selector->type.tv == tarval_bottom) {
1133                         node->type.tv = tarval_reachable;
1134                 } else if (selector->type.tv == tarval_top) {
1135                         node->type.tv = tarval_unreachable;
1136                 } else {
1137                         long value = get_tarval_long(selector->type.tv);
1138                         if (pnc == get_Cond_defaultProj(cond)) {
1139                                 /* default switch, have to check ALL other cases */
1140                                 int i;
1141
1142                                 for (i = get_irn_n_outs(cond) - 1; i >= 0; --i) {
1143                                         ir_node *succ = get_irn_out(cond, i);
1144
1145                                         if (succ == proj)
1146                                                 continue;
1147                                         if (value == get_Proj_proj(succ)) {
1148                                                 /* we found a match, will NOT take the default case */
1149                                                 node->type.tv = tarval_unreachable;
1150                                                 return;
1151                                         }
1152                                 }
1153                                 /* all cases checked, no match, will take default case */
1154                                 node->type.tv = tarval_reachable;
1155                         } else {
1156                                 /* normal case */
1157                                 node->type.tv = value == pnc ? tarval_reachable : tarval_unreachable;
1158                         }
1159                 }
1160         }
1161 }  /* compute_Proj_Cond */
1162
1163 /**
1164  * (Re-)compute the type for a Proj-Nodes.
1165  *
1166  * @param node  the node
1167  */
1168 static void compute_Proj(node_t *node) {
1169         ir_node *proj = node->node;
1170         ir_mode *mode = get_irn_mode(proj);
1171         ir_node *pred;
1172
1173         if (mode == mode_M) {
1174                 /* mode M is always bottom */
1175                 node->type.tv = tarval_bottom;
1176                 return;
1177         }
1178         if (mode != mode_X) {
1179                 ir_node *cmp = get_Proj_pred(proj);
1180                 if (is_Cmp(cmp))
1181                         compute_Proj_Cmp(node, cmp);
1182                 else
1183                         default_compute(node);
1184                 return;
1185         }
1186         /* handle mode_X nodes */
1187         pred = get_Proj_pred(proj);
1188
1189         switch (get_irn_opcode(pred)) {
1190         case iro_Start:
1191                 /* the Proj_X from the Start is always reachable */
1192                 node->type.tv = tarval_reachable;
1193                 break;
1194         case iro_Cond:
1195                 compute_Proj_Cond(node, pred);
1196                 break;
1197         default:
1198                 default_compute(node);
1199         }
1200 }  /* compute_Proj */
1201
1202 /**
1203  * (Re-)compute the type for a given node.
1204  *
1205  * @param node  the node
1206  */
1207 static void compute(node_t *node) {
1208         compute_func func = (compute_func)node->node->op->ops.generic;
1209
1210         if (func != NULL)
1211                 func(node);
1212 }  /* compute */
1213
1214 /**
1215  * Propagate constant evaluation.
1216  *
1217  * @param env  the environment
1218  */
1219 static void propagate(environment_t *env) {
1220         partition_t    *X, *Y;
1221         node_t         *x;
1222         lattice_elem_t old_type;
1223         node_t         *fallen;
1224         unsigned       n_fallen;
1225         int            i;
1226
1227         while (env->cprop != NULL) {
1228                 /* remove the first partition X from cprop but do not set the bit here */
1229                 X          = env->cprop;
1230                 env->cprop = X->cprop_next;
1231
1232                 fallen   = NULL;
1233                 n_fallen = 0;
1234                 do {
1235                         /* remove the first Node x from X.cprop but do NOT set the bit here */
1236                         x        = X->cprop;
1237                         X->cprop = x->cprop_next;
1238
1239                         /* compute a new type for x */
1240                         old_type = x->type;
1241                         DB((dbg, LEVEL_3, "computing type of %+F\n", x->node));
1242                         compute(x);
1243                         if (x->type.tv != old_type.tv) {
1244                                 DB((dbg, LEVEL_2, "node %+F has changed type from %+F to %+F\n", x->node, old_type, x->type));
1245                                 /* Add x to fallen. */
1246                                 x->next = fallen;
1247                                 fallen  = x;
1248                                 ++n_fallen;
1249
1250                                 for (i = get_irn_n_outs(x->node) - 1; i >= 0; --i) {
1251                                         ir_node *succ = get_irn_out(x->node, i);
1252                                         node_t  *y    = get_irn_node(succ);
1253
1254                                         /* Add y to y.partition.cprop. */
1255                                         add_node_to_cprop(y, env);
1256                                 }
1257                         }
1258                         /* now remove x from X.cprop: this ensures that a node is not placed on the list again
1259                            if is its user by itself (happens for Phi nodes and dead code) */
1260                         x->on_cprop = 0;
1261                 } while (X->cprop != NULL);
1262
1263                 /* now remove X from cprop, we have emptied it's local list */
1264                 X->on_cprop = 0;
1265
1266                 if (n_fallen > 0 && n_fallen != X->n_nodes) {
1267                         Y = split(X, fallen, env);
1268                 } else {
1269                         Y = X;
1270                 }
1271                 if (Y->n_nodes > 1)
1272                         split_by(Y, env);
1273         }
1274 }  /* propagate */
1275
1276 /**
1277  * Get the leader for a given node from its congruence class.
1278  *
1279  * @param irn  the node
1280  */
1281 static ir_node *get_leader(node_t *node) {
1282         partition_t *part = node->part;
1283
1284         if (part->n_nodes > 1) {
1285                 DB((dbg, LEVEL_2, "Found congruence class for %+F ", node->node));
1286
1287                 return get_first_node(part)->node;
1288         }
1289         return node->node;
1290 }
1291
1292 /**
1293  * Post-Walker, apply the analysis results;
1294  */
1295 static void apply_result(ir_node *irn, void *ctx) {
1296         environment_t *env = ctx;
1297         node_t        *node = get_irn_node(irn);
1298
1299         if (is_Block(irn)) {
1300                 if (node->type.tv == tarval_unreachable) {
1301                         set_Block_dead(irn);
1302                 }
1303         } else {
1304                 node_t *block = get_irn_node(get_nodes_block(irn));
1305
1306                 if (block->type.tv == tarval_unreachable) {
1307                         DB((dbg, LEVEL_1, "%+F is unreachable\n", irn));
1308                         exchange(irn, get_irg_bad(current_ir_graph));
1309                 }
1310                 else if (get_irn_mode(irn) == mode_X) {
1311                         if (node->type.tv == tarval_unreachable) {
1312                                 DB((dbg, LEVEL_1, "%+F is unreachable\n", irn));
1313                                 exchange(irn, get_irg_bad(current_ir_graph));
1314                         }
1315                         else if (is_Proj(irn)) {
1316                                 /* leave or Jmp */
1317                                 ir_node *cond = get_Proj_pred(irn);
1318
1319                                 if (is_Cond(cond)) {
1320                                         ir_node *sel = get_Cond_selector(cond);
1321
1322                                         if (is_Const(sel)) {
1323                                                 /* Cond selector was replaced by a constant, make a Jmp */
1324                                                 ir_node *jmp = new_r_Jmp(current_ir_graph, block->node);
1325
1326                                                 DB((dbg, LEVEL_1, "%+F is replaced by %+F\n", irn, jmp));
1327                                                 exchange(irn, jmp);
1328                                         }
1329                                 }
1330                         }
1331                 } else {
1332                         /* normal data node */
1333                         ir_node *leader = get_leader(node);
1334
1335                         if (leader != irn) {
1336                                 DB((dbg, LEVEL_1, "%+F is replaced by %+F\n", irn, leader));
1337                                 exchange(irn, leader);
1338                         }
1339                 }
1340         }
1341 }  /* static void apply_result(ir_node *irn, void *ctx) {
1342  */
1343
1344 #define SET(code) op_##code->ops.generic = (op_func)compute_##code
1345
1346 /**
1347  * sets the generic functions to compute.
1348  */
1349 static void set_compute_functions(void) {
1350         int i;
1351
1352         /* set the default compute function */
1353         for (i = get_irp_n_opcodes() - 1; i >= 0; --i) {
1354                 ir_op *op = get_irp_opcode(i);
1355                 op->ops.generic = (op_func)default_compute;
1356         }
1357
1358         /* set specific functions */
1359         SET(Block);
1360         SET(Jmp);
1361         SET(Phi);
1362         SET(Add);
1363         SET(Sub);
1364         SET(SymConst);
1365         SET(Proj);
1366         SET(End);
1367 }  /* set_compute_functions */
1368
1369 static int dump_partition_hook(FILE *F, ir_node *n, ir_node *local) {
1370         ir_node *irn = local != NULL ? local : n;
1371         node_t *node = get_irn_node(n);
1372
1373         ir_fprintf(F, "info2 : \"partition %u type %+F\"\n", node->part->nr, node->type);
1374         return 1;
1375 }
1376
1377 void combo(ir_graph *irg) {
1378         environment_t env;
1379         ir_node       *initial_X;
1380         node_t        *start;
1381         ir_graph      *rem = current_ir_graph;
1382
1383         current_ir_graph = irg;
1384
1385         /* register a debug mask */
1386         FIRM_DBG_REGISTER(dbg, "firm.opt.combo");
1387         firm_dbg_set_mask(dbg, SET_LEVEL_1);
1388
1389         DB((dbg, LEVEL_1, "Doing COMBO for %+F\n", irg));
1390
1391         obstack_init(&env.obst);
1392         env.worklist       = NULL;
1393         env.cprop          = NULL;
1394         env.touched        = NULL;
1395         env.initial        = NULL;
1396 #ifdef DEBUG_libfirm
1397         env.dbg_list       = NULL;
1398 #endif
1399         env.opcode2id_map  = new_set(cmp_opcode, iro_Last * 4);
1400         env.type2id_map    = pmap_create();
1401         env.end_idx        = get_opt_global_cse() ? 0 : -1;
1402         env.lambda_input   = 0;
1403
1404         assure_irg_outs(irg);
1405
1406         /* we have our own value_of function */
1407         set_value_of_func(get_node_tarval);
1408
1409         set_compute_functions();
1410
1411         /* create the initial partition and place it on the work list */
1412         env.initial = new_partition(&env);
1413         add_to_worklist(env.initial, &env);
1414         irg_walk_graph(irg, NULL, create_initial_partitions, &env);
1415
1416         /* Place the START Node's partition on cprop.
1417            Place the START Node on its local worklist. */
1418         initial_X = get_irg_initial_exec(irg);
1419         start     = get_irn_node(initial_X);
1420         add_node_to_cprop(start, &env);
1421
1422         do {
1423                 propagate(&env);
1424                 if (env.worklist != NULL)
1425                         cause_splits(&env);
1426         } while (env.cprop != NULL || env.worklist != NULL);
1427
1428         dump_all_partitions(&env);
1429
1430         set_dump_node_vcgattr_hook(dump_partition_hook);
1431         dump_ir_block_graph(irg, "-partition");
1432
1433
1434         /* apply the result */
1435         irg_walk_graph(irg, NULL, apply_result, &env);
1436
1437         pmap_destroy(env.type2id_map);
1438         del_set(env.opcode2id_map);
1439         obstack_free(&env.obst, NULL);
1440
1441         /* restore value_of() default behavior */
1442         set_value_of_func(NULL);
1443         current_ir_graph = rem;
1444 }  /* combo */