2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
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.
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.
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
22 * @brief Cliff Click's Combined Analysis/Optimization
23 * @author Michael Beck
26 * Note further 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/entity, nevertheless we call it type here for "maximum compatibility".
36 #include "iroptimize.h"
44 #include "irgraph_t.h"
59 /* define this to check that all type translations are monotone */
60 #define VERIFY_MONOTONE
62 /* define this to check the consistency of partitions */
63 #define CHECK_PARTITIONS
65 /* define this to disable followers (may be buggy) */
68 typedef struct node_t node_t;
69 typedef struct partition_t partition_t;
70 typedef struct opcode_key_t opcode_key_t;
71 typedef struct listmap_entry_t listmap_entry_t;
73 /** The type of the compute function. */
74 typedef void (*compute_func)(node_t *node);
80 ir_opcode code; /**< The Firm opcode. */
81 ir_mode *mode; /**< The mode of all nodes in the partition. */
82 int arity; /**< The arity of this opcode (needed for Phi etc. */
84 long proj; /**< For Proj nodes, its proj number */
85 ir_entity *ent; /**< For Sel Nodes, its entity */
90 * An entry in the list_map.
92 struct listmap_entry_t {
93 void *id; /**< The id. */
94 node_t *list; /**< The associated list for this id. */
95 listmap_entry_t *next; /**< Link to the next entry in the map. */
98 /** We must map id's to lists. */
99 typedef struct listmap_t {
100 set *map; /**< Map id's to listmap_entry_t's */
101 listmap_entry_t *values; /**< List of all values in the map. */
105 * A lattice element. Because we handle constants and symbolic constants different, we
106 * have to use this union.
117 ir_node *node; /**< The IR-node itself. */
118 list_head node_list; /**< Double-linked list of leader/follower entries. */
119 list_head cprop_list; /**< Double-linked partition.cprop list. */
120 partition_t *part; /**< points to the partition this node belongs to */
121 node_t *next; /**< Next node on local list (partition.touched, fallen). */
122 node_t *race_next; /**< Next node on race list. */
123 lattice_elem_t type; /**< The associated lattice element "type". */
124 int max_user_input; /**< Maximum input number of Def-Use edges. */
125 int next_edge; /**< Index of the next Def-Use edge to use. */
126 int n_followers; /**< Number of Follower in the outs set. */
127 unsigned on_touched:1; /**< Set, if this node is on the partition.touched set. */
128 unsigned on_cprop:1; /**< Set, if this node is on the partition.cprop list. */
129 unsigned on_fallen:1; /**< Set, if this node is on the fallen list. */
130 unsigned is_follower:1; /**< Set, if this node is a follower. */
131 unsigned by_all_const:1; /**< Set, if this node was once evaluated by all constants. */
132 unsigned flagged:2; /**< 2 Bits, set if this node was visited by race 1 or 2. */
136 * A partition containing congruent nodes.
139 list_head Leader; /**< The head of partition Leader node list. */
140 list_head Follower; /**< The head of partition Follower node list. */
141 list_head cprop; /**< The head of partition.cprop list. */
142 partition_t *wl_next; /**< Next entry in the work list if any. */
143 partition_t *touched_next; /**< Points to the next partition in the touched set. */
144 partition_t *cprop_next; /**< Points to the next partition in the cprop list. */
145 partition_t *split_next; /**< Points to the next partition in the list that must be split by split_by(). */
146 node_t *touched; /**< The partition.touched set of this partition. */
147 unsigned n_leader; /**< Number of entries in this partition.Leader. */
148 unsigned n_touched; /**< Number of entries in the partition.touched. */
149 int max_user_inputs; /**< Maximum number of user inputs of all entries. */
150 unsigned on_worklist:1; /**< Set, if this partition is in the work list. */
151 unsigned on_touched:1; /**< Set, if this partition is on the touched set. */
152 unsigned on_cprop:1; /**< Set, if this partition is on the cprop list. */
153 unsigned type_is_T_or_C:1;/**< Set, if all nodes in this partition have type Top or Constant. */
155 partition_t *dbg_next; /**< Link all partitions for debugging */
156 unsigned nr; /**< A unique number for (what-)mapping, >0. */
160 typedef struct environment_t {
161 struct obstack obst; /**< obstack to allocate data structures. */
162 partition_t *worklist; /**< The work list. */
163 partition_t *cprop; /**< The constant propagation list. */
164 partition_t *touched; /**< the touched set. */
165 partition_t *initial; /**< The initial partition. */
166 set *opcode2id_map; /**< The opcodeMode->id map. */
167 pmap *type2id_map; /**< The type->id map. */
168 int end_idx; /**< -1 for local and 0 for global congruences. */
169 int lambda_input; /**< Captured argument for lambda_partition(). */
170 int modified; /**< Set, if the graph was modified. */
172 partition_t *dbg_list; /**< List of all partitions. */
176 /** Type of the what function. */
177 typedef void *(*what_func)(const node_t *node, environment_t *env);
179 #define get_irn_node(follower) ((node_t *)get_irn_link(follower))
180 #define set_irn_node(follower, node) set_irn_link(follower, node)
182 /* we do NOT use tarval_unreachable here, instead we use Top for this purpose */
183 #undef tarval_unreachable
184 #define tarval_unreachable tarval_top
187 /** The debug module handle. */
188 DEBUG_ONLY(static firm_dbg_module_t *dbg;)
190 /** Next partition number. */
191 DEBUG_ONLY(static unsigned part_nr = 0);
194 static node_t *identity(node_t *node);
196 #ifdef CHECK_PARTITIONS
200 static void check_partition(const partition_t *T) {
204 list_for_each_entry(node_t, node, &T->Leader, node_list) {
205 assert(node->is_follower == 0);
206 assert(node->flagged == 0);
207 assert(node->part == T);
210 assert(n == T->n_leader);
212 list_for_each_entry(node_t, node, &T->Follower, node_list) {
213 assert(node->is_follower == 1);
214 assert(node->flagged == 0);
215 assert(node->part == T);
217 } /* check_partition */
222 static void do_check_list(const node_t *list, int ofs, const partition_t *Z) {
225 #define NEXT(e) *((const node_t **)((char *)(e) + (ofs)))
226 for (e = list; e != NULL; e = NEXT(e)) {
227 assert(e->part == Z);
230 } /* ido_check_list */
233 * Check a local list.
235 static void check_list(const node_t *list, const partition_t *Z) {
236 do_check_list(list, offsetof(node_t, next), Z);
240 #define check_partition(T)
241 #define check_list(list, Z)
242 #endif /* CHECK_PARTITIONS */
245 static INLINE lattice_elem_t get_partition_type(const partition_t *X);
248 * Dump partition to output.
250 static void dump_partition(const char *msg, const partition_t *part) {
253 lattice_elem_t type = get_partition_type(part);
255 DB((dbg, LEVEL_2, "%s part%u%s (%u, %+F) {\n ",
256 msg, part->nr, part->type_is_T_or_C ? "*" : "",
257 part->n_leader, type));
258 list_for_each_entry(node_t, node, &part->Leader, node_list) {
259 DB((dbg, LEVEL_2, "%s%+F", first ? "" : ", ", node->node));
262 if (! list_empty(&part->Follower)) {
263 DB((dbg, LEVEL_2, "\n---\n "));
265 list_for_each_entry(node_t, node, &part->Follower, node_list) {
266 DB((dbg, LEVEL_2, "%s%+F", first ? "" : ", ", node->node));
270 DB((dbg, LEVEL_2, "\n}\n"));
271 } /* dump_partition */
276 static void do_dump_list(const char *msg, const node_t *node, int ofs) {
280 #define GET_LINK(p, ofs) *((const node_t **)((char *)(p) + (ofs)))
282 DB((dbg, LEVEL_3, "%s = {\n ", msg));
283 for (p = node; p != NULL; p = GET_LINK(p, ofs)) {
284 DB((dbg, LEVEL_3, "%s%+F", first ? "" : ", ", p->node));
287 DB((dbg, LEVEL_3, "\n}\n"));
295 static void dump_race_list(const char *msg, const node_t *list) {
296 do_dump_list(msg, list, offsetof(node_t, race_next));
300 * Dumps a local list.
302 static void dump_list(const char *msg, const node_t *list) {
303 do_dump_list(msg, list, offsetof(node_t, next));
307 * Dump all partitions.
309 static void dump_all_partitions(const environment_t *env) {
310 const partition_t *P;
312 DB((dbg, LEVEL_2, "All partitions\n===============\n"));
313 for (P = env->dbg_list; P != NULL; P = P->dbg_next)
314 dump_partition("", P);
318 #define dump_partition(msg, part)
319 #define dump_race_list(msg, list)
320 #define dump_list(msg, list)
321 #define dump_all_partitions(env)
324 #if defined(VERIFY_MONOTONE) && defined (DEBUG_libfirm)
326 * Verify that a type transition is monotone
328 static void verify_type(const lattice_elem_t old_type, const lattice_elem_t new_type) {
329 if (old_type.tv == new_type.tv) {
333 if (old_type.tv == tarval_top) {
334 /* from Top down-to is always allowed */
337 if (old_type.tv == tarval_reachable) {
338 panic("verify_type(): wrong translation from %+F to %+F", old_type, new_type);
340 if (new_type.tv == tarval_bottom || new_type.tv == tarval_reachable) {
344 panic("verify_type(): wrong translation from %+F to %+F", old_type, new_type);
347 #define verify_type(old_type, new_type)
351 * Compare two pointer values of a listmap.
353 static int listmap_cmp_ptr(const void *elt, const void *key, size_t size) {
354 const listmap_entry_t *e1 = elt;
355 const listmap_entry_t *e2 = key;
358 return e1->id != e2->id;
359 } /* listmap_cmp_ptr */
362 * Initializes a listmap.
364 * @param map the listmap
366 static void listmap_init(listmap_t *map) {
367 map->map = new_set(listmap_cmp_ptr, 16);
372 * Terminates a listmap.
374 * @param map the listmap
376 static void listmap_term(listmap_t *map) {
381 * Return the associated listmap entry for a given id.
383 * @param map the listmap
384 * @param id the id to search for
386 * @return the asociated listmap entry for the given id
388 static listmap_entry_t *listmap_find(listmap_t *map, void *id) {
389 listmap_entry_t key, *entry;
394 entry = set_insert(map->map, &key, sizeof(key), HASH_PTR(id));
396 if (entry->list == NULL) {
397 /* a new entry, put into the list */
398 entry->next = map->values;
405 * Calculate the hash value for an opcode map entry.
407 * @param entry an opcode map entry
409 * @return a hash value for the given opcode map entry
411 static unsigned opcode_hash(const opcode_key_t *entry) {
412 return (entry->mode - (ir_mode *)0) * 9 + entry->code + entry->u.proj * 3 + HASH_PTR(entry->u.ent);
416 * Compare two entries in the opcode map.
418 static int cmp_opcode(const void *elt, const void *key, size_t size) {
419 const opcode_key_t *o1 = elt;
420 const opcode_key_t *o2 = key;
423 return o1->code != o2->code || o1->mode != o2->mode ||
424 o1->arity != o2->arity ||
425 o1->u.proj != o2->u.proj || o1->u.ent != o2->u.ent;
429 * Compare two Def-Use edges for input position.
431 static int cmp_def_use_edge(const void *a, const void *b) {
432 const ir_def_use_edge *ea = a;
433 const ir_def_use_edge *eb = b;
435 /* no overrun, because range is [-1, MAXINT] */
436 return ea->pos - eb->pos;
437 } /* cmp_def_use_edge */
440 * We need the Def-Use edges sorted.
442 static void sort_irn_outs(node_t *node) {
443 ir_node *irn = node->node;
444 int n_outs = get_irn_n_outs(irn);
447 qsort(&irn->out[1], n_outs, sizeof(irn->out[0]), cmp_def_use_edge);
449 node->max_user_input = irn->out[n_outs].pos;
450 } /* sort_irn_outs */
453 * Return the type of a node.
455 * @param irn an IR-node
457 * @return the associated type of this node
459 static INLINE lattice_elem_t get_node_type(const ir_node *irn) {
460 return get_irn_node(irn)->type;
461 } /* get_node_type */
464 * Return the tarval of a node.
466 * @param irn an IR-node
468 * @return the associated type of this node
470 static INLINE tarval *get_node_tarval(const ir_node *irn) {
471 lattice_elem_t type = get_node_type(irn);
473 if (is_tarval(type.tv))
475 return tarval_bottom;
476 } /* get_node_type */
479 * Add a partition to the worklist.
481 static INLINE void add_to_worklist(partition_t *X, environment_t *env) {
482 assert(X->on_worklist == 0);
483 X->wl_next = env->worklist;
486 } /* add_to_worklist */
489 * Create a new empty partition.
491 * @param env the environment
493 * @return a newly allocated partition
495 static INLINE partition_t *new_partition(environment_t *env) {
496 partition_t *part = obstack_alloc(&env->obst, sizeof(*part));
498 INIT_LIST_HEAD(&part->Leader);
499 INIT_LIST_HEAD(&part->Follower);
500 INIT_LIST_HEAD(&part->cprop);
501 part->wl_next = NULL;
502 part->touched_next = NULL;
503 part->cprop_next = NULL;
504 part->split_next = NULL;
505 part->touched = NULL;
508 part->max_user_inputs = 0;
509 part->on_worklist = 0;
510 part->on_touched = 0;
512 part->type_is_T_or_C = 0;
514 part->dbg_next = env->dbg_list;
515 env->dbg_list = part;
516 part->nr = part_nr++;
520 } /* new_partition */
523 * Get the first node from a partition.
525 static INLINE node_t *get_first_node(const partition_t *X) {
526 return list_entry(X->Leader.next, node_t, node_list);
527 } /* get_first_node */
530 * Return the type of a partition (assuming partition is non-empty and
531 * all elements have the same type).
533 * @param X a partition
535 * @return the type of the first element of the partition
537 static INLINE lattice_elem_t get_partition_type(const partition_t *X) {
538 const node_t *first = get_first_node(X);
540 } /* get_partition_type */
543 * Creates a partition node for the given IR-node and place it
544 * into the given partition.
546 * @param irn an IR-node
547 * @param part a partition to place the node in
548 * @param env the environment
550 * @return the created node
552 static node_t *create_partition_node(ir_node *irn, partition_t *part, environment_t *env) {
553 /* create a partition node and place it in the partition */
554 node_t *node = obstack_alloc(&env->obst, sizeof(*node));
556 INIT_LIST_HEAD(&node->node_list);
557 INIT_LIST_HEAD(&node->cprop_list);
561 node->race_next = NULL;
562 node->type.tv = tarval_top;
563 node->max_user_input = 0;
565 node->n_followers = 0;
566 node->on_touched = 0;
569 node->is_follower = 0;
570 node->by_all_const = 0;
572 set_irn_node(irn, node);
574 list_add_tail(&node->node_list, &part->Leader);
578 } /* create_partition_node */
581 * Pre-Walker, init all Block-Phi lists.
583 static void init_block_phis(ir_node *irn, void *env) {
587 set_Block_phis(irn, NULL);
589 } /* init_block_phis */
592 * Post-Walker, initialize all Nodes' type to U or top and place
593 * all nodes into the TOP partition.
595 static void create_initial_partitions(ir_node *irn, void *ctx) {
596 environment_t *env = ctx;
597 partition_t *part = env->initial;
600 node = create_partition_node(irn, part, env);
602 if (node->max_user_input > part->max_user_inputs)
603 part->max_user_inputs = node->max_user_input;
606 add_Block_phi(get_nodes_block(irn), irn);
608 } /* create_initial_partitions */
611 * Add a node to the entry.partition.touched set and
612 * node->partition to the touched set if not already there.
615 * @param env the environment
617 static INLINE void add_to_touched(node_t *y, environment_t *env) {
618 if (y->on_touched == 0) {
619 partition_t *part = y->part;
621 y->next = part->touched;
626 if (part->on_touched == 0) {
627 part->touched_next = env->touched;
629 part->on_touched = 1;
632 check_list(part->touched, part);
634 } /* add_to_touched */
637 * Place a node on the cprop list.
640 * @param env the environment
642 static void add_to_cprop(node_t *y, environment_t *env) {
643 /* Add y to y.partition.cprop. */
644 if (y->on_cprop == 0) {
645 partition_t *Y = y->part;
647 list_add_tail(&y->cprop_list, &Y->cprop);
650 DB((dbg, LEVEL_3, "Add %+F to part%u.cprop\n", y->node, Y->nr));
652 /* place its partition on the cprop list */
653 if (Y->on_cprop == 0) {
654 Y->cprop_next = env->cprop;
659 if (get_irn_mode(y->node) == mode_T) {
660 /* mode_T nodes always produce tarval_bottom, so we must explicitly
661 add it's Proj's to get constant evaluation to work */
664 for (i = get_irn_n_outs(y->node) - 1; i >= 0; --i) {
665 node_t *proj = get_irn_node(get_irn_out(y->node, i));
667 add_to_cprop(proj, env);
669 } else if (is_Block(y->node)) {
670 /* Due to the way we handle Phi's, we must place all Phis of a block on the list
671 * if someone placed the block. The Block is only placed if the reachability
672 * changes, and this must be re-evaluated in compute_Phi(). */
674 for (phi = get_Block_phis(y->node); phi != NULL; phi = get_Phi_next(phi)) {
675 node_t *p = get_irn_node(phi);
676 add_to_cprop(p, env);
682 * Update the worklist: If Z is on worklist then add Z' to worklist.
683 * Else add the smaller of Z and Z' to worklist.
685 * @param Z the Z partition
686 * @param Z_prime the Z' partition, a previous part of Z
687 * @param env the environment
689 static void update_worklist(partition_t *Z, partition_t *Z_prime, environment_t *env) {
690 if (Z->on_worklist || Z_prime->n_leader < Z->n_leader) {
691 add_to_worklist(Z_prime, env);
693 add_to_worklist(Z, env);
695 } /* update_worklist */
698 * Make all inputs to x no longer be F.def_use edges.
702 static void move_edges_to_leader(node_t *x) {
703 ir_node *irn = x->node;
706 for (i = get_irn_arity(irn) - 1; i >= 0; --i) {
707 node_t *pred = get_irn_node(get_irn_n(irn, i));
712 n = get_irn_n_outs(p);
713 for (j = 1; j <= pred->n_followers; ++j) {
714 if (p->out[j].pos == i && p->out[j].use == irn) {
715 /* found a follower edge to x, move it to the Leader */
716 ir_def_use_edge edge = p->out[j];
718 /* remove this edge from the Follower set */
719 p->out[j] = p->out[pred->n_followers];
722 /* sort it into the leader set */
723 for (k = pred->n_followers + 2; k <= n; ++k) {
724 if (p->out[k].pos >= edge.pos)
726 p->out[k - 1] = p->out[k];
728 /* place the new edge here */
729 p->out[k - 1] = edge;
731 /* edge found and moved */
736 } /* move_edges_to_leader */
739 * Split a partition that has NO followers by a local list.
741 * @param Z partition to split
742 * @param g a (non-empty) node list
743 * @param env the environment
745 * @return a new partition containing the nodes of g
747 static partition_t *split_no_followers(partition_t *Z, node_t *g, environment_t *env) {
748 partition_t *Z_prime;
753 dump_partition("Splitting ", Z);
754 dump_list("by list ", g);
758 /* Remove g from Z. */
759 for (node = g; node != NULL; node = node->next) {
760 assert(node->part == Z);
761 list_del(&node->node_list);
764 assert(n < Z->n_leader);
767 /* Move g to a new partition, Z'. */
768 Z_prime = new_partition(env);
770 for (node = g; node != NULL; node = node->next) {
771 list_add_tail(&node->node_list, &Z_prime->Leader);
772 node->part = Z_prime;
773 if (node->max_user_input > max_input)
774 max_input = node->max_user_input;
776 Z_prime->max_user_inputs = max_input;
777 Z_prime->n_leader = n;
780 check_partition(Z_prime);
782 /* for now, copy the type info tag, it will be adjusted in split_by(). */
783 Z_prime->type_is_T_or_C = Z->type_is_T_or_C;
785 update_worklist(Z, Z_prime, env);
787 dump_partition("Now ", Z);
788 dump_partition("Created new ", Z_prime);
790 } /* split_no_followers */
794 #define split(Z, g, env) split_no_followers(*(Z), g, env)
799 * Make the Follower -> Leader transition for a node.
803 static void follower_to_leader(node_t *n) {
804 assert(n->is_follower == 1);
806 DB((dbg, LEVEL_2, "%+F make the follower -> leader transition\n", n->node));
808 move_edges_to_leader(n);
809 list_del(&n->node_list);
810 list_add_tail(&n->node_list, &n->part->Leader);
812 } /* follower_to_leader */
815 * The environment for one race step.
817 typedef struct step_env {
818 node_t *initial; /**< The initial node list. */
819 node_t *unwalked; /**< The unwalked node list. */
820 node_t *walked; /**< The walked node list. */
821 int index; /**< Next index of Follower use_def edge. */
822 unsigned side; /**< side number. */
826 * Do one step in the race.
828 static int step(step_env *env) {
831 if (env->initial != NULL) {
832 /* Move node from initial to unwalked */
834 env->initial = n->race_next;
836 n->race_next = env->unwalked;
842 while (env->unwalked != NULL) {
843 /* let n be the first node in unwalked */
845 while (env->index < n->n_followers) {
846 /* let m be n.F.def_use[index] */
847 node_t *m = get_irn_node(n->node->out[1 + env->index].use);
849 assert(m->is_follower);
852 /* only followers from our partition */
853 if (m->part != n->part)
856 if ((m->flagged & env->side) == 0) {
857 m->flagged |= env->side;
859 if (m->flagged != 3) {
860 /* visited the first time */
861 /* add m to unwalked not as first node (we might still need to
862 check for more follower node */
863 m->race_next = n->race_next;
867 /* else already visited by the other side and on the other list */
870 /* move n to walked */
871 env->unwalked = n->race_next;
872 n->race_next = env->walked;
880 * Clear the flags from a list and check for
881 * nodes that where touched from both sides.
883 * @param list the list
885 * @return non-zero if a Follower -> Leader transition take place
887 static int clear_flags(node_t *list) {
891 for (n = list; n != NULL; n = n->race_next) {
892 if (n->flagged == 3) {
893 /* we reach a follower from both sides, this will split congruent
894 * inputs and make it a leader. */
895 follower_to_leader(n);
904 * Split a partition by a local list using the race.
906 * @param pX pointer to the partition to split, might be changed!
907 * @param gg a (non-empty) node list
908 * @param env the environment
910 * @return a new partition containing the nodes of gg
912 static partition_t *split(partition_t **pX, node_t *gg, environment_t *env) {
913 partition_t *X = *pX;
914 partition_t *X_prime;
916 step_env env1, env2, *winner;
917 node_t *g, *h, *node, *t;
918 int max_input, transitions;
920 DEBUG_ONLY(static int run = 0;)
922 DB((dbg, LEVEL_2, "Run %d ", run++));
923 if (list_empty(&X->Follower)) {
924 /* if the partition has NO follower, we can use the fast
925 splitting algorithm. */
926 return split_no_followers(X, gg, env);
928 /* else do the race */
930 dump_partition("Splitting ", X);
931 dump_list("by list ", gg);
933 INIT_LIST_HEAD(&tmp);
935 /* Remove gg from X.Leader and put into g */
937 for (node = gg; node != NULL; node = node->next) {
938 assert(node->part == X);
939 assert(node->is_follower == 0);
941 list_del(&node->node_list);
942 list_add_tail(&node->node_list, &tmp);
948 list_for_each_entry(node_t, node, &X->Leader, node_list) {
952 /* restore X.Leader */
953 list_splice(&tmp, &X->Leader);
956 env1.unwalked = NULL;
962 env2.unwalked = NULL;
977 assert(winner->initial == NULL);
978 assert(winner->unwalked == NULL);
980 /* clear flags from walked/unwalked */
981 transitions = clear_flags(env1.unwalked);
982 transitions |= clear_flags(env1.walked);
983 transitions |= clear_flags(env2.unwalked);
984 transitions |= clear_flags(env2.walked);
986 dump_race_list("winner ", winner->walked);
988 /* Move walked_{winner} to a new partition, X'. */
989 X_prime = new_partition(env);
992 for (node = winner->walked; node != NULL; node = node->race_next) {
993 list_del(&node->node_list);
994 node->part = X_prime;
995 if (node->is_follower) {
996 list_add_tail(&node->node_list, &X_prime->Follower);
998 list_add_tail(&node->node_list, &X_prime->Leader);
1001 if (node->max_user_input > max_input)
1002 max_input = node->max_user_input;
1004 X_prime->n_leader = n;
1005 X_prime->max_user_inputs = max_input;
1006 X->n_leader -= X_prime->n_leader;
1008 /* for now, copy the type info tag, it will be adjusted in split_by(). */
1009 X_prime->type_is_T_or_C = X->type_is_T_or_C;
1012 * Even if a follower was not checked by both sides, it might have
1013 * loose its congruence, so we need to check this case for all follower.
1015 list_for_each_entry_safe(node_t, node, t, &X_prime->Follower, node_list) {
1016 if (identity(node) == node) {
1017 follower_to_leader(node);
1023 check_partition(X_prime);
1025 /* X' is the smaller part */
1026 add_to_worklist(X_prime, env);
1028 if (transitions && X->on_worklist == 0) {
1030 * If there where transition from Follower to Leader,
1031 * these nodes must be split out from X_prime.
1032 * This is only possible if cause_split() will be called on X.
1034 add_to_worklist(X, env);
1037 dump_partition("Now ", X);
1038 dump_partition("Created new ", X_prime);
1040 /* we have to ensure that the partition containing g is returned */
1041 if (winner == &env2) {
1048 #endif /* NO_FOLLOWER */
1051 * Returns non-zero if the i'th input of a Phi node is live.
1053 * @param phi a Phi-node
1054 * @param i an input number
1056 * @return non-zero if the i'th input of the given Phi node is live
1058 static int is_live_input(ir_node *phi, int i) {
1060 ir_node *block = get_nodes_block(phi);
1061 ir_node *pred = get_Block_cfgpred(block, i);
1062 lattice_elem_t type = get_node_type(pred);
1064 return type.tv != tarval_unreachable;
1066 /* else it's the control input, always live */
1068 } /* is_live_input */
1071 * Return non-zero if a type is a constant.
1073 static int is_constant_type(lattice_elem_t type) {
1074 if (type.tv != tarval_bottom && type.tv != tarval_top)
1077 } /* is_constant_type */
1080 * Check whether a type is neither Top or a constant.
1081 * Note: U is handled like Top here, R is a constant.
1083 * @param type the type to check
1085 static int type_is_neither_top_nor_const(const lattice_elem_t type) {
1086 if (is_tarval(type.tv)) {
1087 if (type.tv == tarval_top)
1089 if (tarval_is_constant(type.tv))
1099 * Collect nodes to the touched list.
1101 * @param list the list which contains the nodes that must be evaluated
1102 * @param idx the index of the def_use edge to evaluate
1103 * @param env the environment
1105 static void collect_touched(list_head *list, int idx, environment_t *env) {
1107 int end_idx = env->end_idx;
1109 list_for_each_entry(node_t, x, list, node_list) {
1113 /* leader edges start AFTER follower edges */
1114 x->next_edge = x->n_followers + 1;
1116 num_edges = get_irn_n_outs(x->node);
1118 /* for all edges in x.L.def_use_{idx} */
1119 while (x->next_edge <= num_edges) {
1120 ir_def_use_edge *edge = &x->node->out[x->next_edge];
1123 /* check if we have necessary edges */
1124 if (edge->pos > idx)
1131 /* ignore the "control input" for non-pinned nodes
1132 if we are running in GCSE mode */
1133 if (idx < end_idx && get_irn_pinned(succ) != op_pin_state_pinned)
1136 y = get_irn_node(succ);
1137 assert(get_irn_n(succ, idx) == x->node);
1139 /* ignore block edges touching followers */
1140 if (idx == -1 && y->is_follower)
1143 if (is_constant_type(y->type)) {
1144 ir_opcode code = get_irn_opcode(succ);
1145 if (code == iro_Sub || code == iro_Cmp)
1146 add_to_cprop(y, env);
1149 /* Partitions of constants should not be split simply because their Nodes have unequal
1150 functions or incongruent inputs. */
1151 if (type_is_neither_top_nor_const(y->type) &&
1152 (! is_Phi(y->node) || is_live_input(y->node, idx))) {
1153 add_to_touched(y, env);
1157 } /* collect_touched */
1160 * Split the partitions if caused by the first entry on the worklist.
1162 * @param env the environment
1164 static void cause_splits(environment_t *env) {
1165 partition_t *X, *Z, *N;
1168 /* remove the first partition from the worklist */
1170 env->worklist = X->wl_next;
1173 dump_partition("Cause_split: ", X);
1175 /* combine temporary leader and follower list */
1176 for (idx = -1; idx <= X->max_user_inputs; ++idx) {
1177 /* empty the touched set: already done, just clear the list */
1178 env->touched = NULL;
1180 collect_touched(&X->Leader, idx, env);
1181 collect_touched(&X->Follower, idx, env);
1183 for (Z = env->touched; Z != NULL; Z = N) {
1185 node_t *touched = Z->touched;
1186 unsigned n_touched = Z->n_touched;
1188 assert(Z->touched != NULL);
1190 /* beware, split might change Z */
1191 N = Z->touched_next;
1193 /* remove it from the touched set */
1196 /* Empty local Z.touched. */
1197 for (e = touched; e != NULL; e = e->next) {
1198 assert(e->is_follower == 0);
1204 if (0 < n_touched && n_touched < Z->n_leader) {
1205 DB((dbg, LEVEL_2, "Split part%d by touched\n", Z->nr));
1206 split(&Z, touched, env);
1208 assert(n_touched <= Z->n_leader);
1211 } /* cause_splits */
1214 * Implements split_by_what(): Split a partition by characteristics given
1215 * by the what function.
1217 * @param X the partition to split
1218 * @param What a function returning an Id for every node of the partition X
1219 * @param P a list to store the result partitions
1220 * @param env the environment
1224 static partition_t *split_by_what(partition_t *X, what_func What,
1225 partition_t **P, environment_t *env) {
1228 listmap_entry_t *iter;
1231 /* Let map be an empty mapping from the range of What to (local) list of Nodes. */
1233 list_for_each_entry(node_t, x, &X->Leader, node_list) {
1234 void *id = What(x, env);
1235 listmap_entry_t *entry;
1238 /* input not allowed, ignore */
1241 /* Add x to map[What(x)]. */
1242 entry = listmap_find(&map, id);
1243 x->next = entry->list;
1246 /* Let P be a set of Partitions. */
1248 /* for all sets S except one in the range of map do */
1249 for (iter = map.values; iter != NULL; iter = iter->next) {
1250 if (iter->next == NULL) {
1251 /* this is the last entry, ignore */
1256 /* Add SPLIT( X, S ) to P. */
1257 DB((dbg, LEVEL_2, "Split part%d by what\n", X->nr));
1258 R = split(&X, S, env);
1268 } /* split_by_what */
1270 /** lambda n.(n.type) */
1271 static void *lambda_type(const node_t *node, environment_t *env) {
1273 return node->type.tv;
1276 /** lambda n.(n.opcode) */
1277 static void *lambda_opcode(const node_t *node, environment_t *env) {
1278 opcode_key_t key, *entry;
1279 ir_node *irn = node->node;
1281 key.code = get_irn_opcode(irn);
1282 key.mode = get_irn_mode(irn);
1283 key.arity = get_irn_arity(irn);
1287 switch (get_irn_opcode(irn)) {
1289 key.u.proj = get_Proj_proj(irn);
1292 key.u.ent = get_Sel_entity(irn);
1298 entry = set_insert(env->opcode2id_map, &key, sizeof(key), opcode_hash(&key));
1300 } /* lambda_opcode */
1302 /** lambda n.(n[i].partition) */
1303 static void *lambda_partition(const node_t *node, environment_t *env) {
1304 ir_node *skipped = skip_Proj(node->node);
1307 int i = env->lambda_input;
1309 if (i >= get_irn_arity(node->node)) {
1310 /* we are outside the allowed range */
1314 /* ignore the "control input" for non-pinned nodes
1315 if we are running in GCSE mode */
1316 if (i < env->end_idx && get_irn_pinned(skipped) != op_pin_state_pinned)
1319 pred = i == -1 ? get_irn_n(skipped, i) : get_irn_n(node->node, i);
1320 p = get_irn_node(pred);
1323 } /* lambda_partition */
1326 * Returns true if a type is a constant.
1328 static int is_con(const lattice_elem_t type) {
1329 /* be conservative */
1330 if (is_tarval(type.tv))
1331 return tarval_is_constant(type.tv);
1332 return is_entity(type.sym.entity_p);
1336 * Implements split_by().
1338 * @param X the partition to split
1339 * @param env the environment
1341 static void split_by(partition_t *X, environment_t *env) {
1342 partition_t *I, *P = NULL;
1345 dump_partition("split_by", X);
1347 if (X->n_leader == 1) {
1348 /* we have only one leader, no need to split, just check it's type */
1349 node_t *x = get_first_node(X);
1350 X->type_is_T_or_C = x->type.tv == tarval_top || is_con(x->type);
1354 DB((dbg, LEVEL_2, "WHAT = lambda n.(n.type) on part%d\n", X->nr));
1355 P = split_by_what(X, lambda_type, &P, env);
1357 /* adjust the type tags, we have split partitions by type */
1358 for (I = P; I != NULL; I = I->split_next) {
1359 node_t *x = get_first_node(I);
1360 I->type_is_T_or_C = x->type.tv == tarval_top || is_con(x->type);
1367 if (Y->n_leader > 1) {
1368 /* we do not want split the TOP or constant partitions */
1369 if (! Y->type_is_T_or_C) {
1370 partition_t *Q = NULL;
1372 DB((dbg, LEVEL_2, "WHAT = lambda n.(n.opcode) on part%d\n", Y->nr));
1373 Q = split_by_what(Y, lambda_opcode, &Q, env);
1379 if (Z->n_leader > 1) {
1380 const node_t *first = get_first_node(Z);
1381 int arity = get_irn_arity(first->node);
1385 * BEWARE: during splitting by input 2 for instance we might
1386 * create new partitions which are different by input 1, so collect
1387 * them and split further.
1389 Z->split_next = NULL;
1392 for (input = arity - 1; input >= -1; --input) {
1394 partition_t *Z_prime = R;
1397 if (Z_prime->n_leader > 1) {
1398 env->lambda_input = input;
1399 DB((dbg, LEVEL_2, "WHAT = lambda n.(n[%d].partition) on part%d\n", input, Z_prime->nr));
1400 S = split_by_what(Z_prime, lambda_partition, &S, env);
1402 Z_prime->split_next = S;
1405 } while (R != NULL);
1410 } while (Q != NULL);
1413 } while (P != NULL);
1417 * (Re-)compute the type for a given node.
1419 * @param node the node
1421 static void default_compute(node_t *node) {
1423 ir_node *irn = node->node;
1424 node_t *block = get_irn_node(get_nodes_block(irn));
1426 if (block->type.tv == tarval_unreachable) {
1427 node->type.tv = tarval_top;
1431 /* if any of the data inputs have type top, the result is type top */
1432 for (i = get_irn_arity(irn) - 1; i >= 0; --i) {
1433 ir_node *pred = get_irn_n(irn, i);
1434 node_t *p = get_irn_node(pred);
1436 if (p->type.tv == tarval_top) {
1437 node->type.tv = tarval_top;
1442 if (get_irn_mode(node->node) == mode_X)
1443 node->type.tv = tarval_reachable;
1445 node->type.tv = computed_value(irn);
1446 } /* default_compute */
1449 * (Re-)compute the type for a Block node.
1451 * @param node the node
1453 static void compute_Block(node_t *node) {
1455 ir_node *block = node->node;
1457 if (block == get_irg_start_block(current_ir_graph)) {
1458 /* start block is always reachable */
1459 node->type.tv = tarval_reachable;
1463 for (i = get_Block_n_cfgpreds(block) - 1; i >= 0; --i) {
1464 node_t *pred = get_irn_node(get_Block_cfgpred(block, i));
1466 if (pred->type.tv == tarval_reachable) {
1467 /* A block is reachable, if at least of predecessor is reachable. */
1468 node->type.tv = tarval_reachable;
1472 node->type.tv = tarval_top;
1473 } /* compute_Block */
1476 * (Re-)compute the type for a Bad node.
1478 * @param node the node
1480 static void compute_Bad(node_t *node) {
1481 /* Bad nodes ALWAYS compute Top */
1482 node->type.tv = tarval_top;
1486 * (Re-)compute the type for an Unknown node.
1488 * @param node the node
1490 static void compute_Unknown(node_t *node) {
1491 /* While Unknown nodes should compute Top this is dangerous:
1492 * a Top input to a Cond would lead to BOTH control flows unreachable.
1493 * While this is correct in the given semantics, it would destroy the Firm
1496 * It would be safe to compute Top IF it can be assured, that only Cmp
1497 * nodes are inputs to Conds. We check that first.
1498 * This is the way Frontends typically build Firm, but some optimizations
1499 * (cond_eval for instance) might replace them by Phib's...
1501 * For now, we compute bottom here.
1503 node->type.tv = tarval_bottom;
1504 } /* compute_Unknown */
1507 * (Re-)compute the type for a Jmp node.
1509 * @param node the node
1511 static void compute_Jmp(node_t *node) {
1512 node_t *block = get_irn_node(get_nodes_block(node->node));
1514 node->type = block->type;
1518 * (Re-)compute the type for the End node.
1520 * @param node the node
1522 static void compute_End(node_t *node) {
1523 /* the End node is NOT dead of course */
1524 node->type.tv = tarval_reachable;
1528 * (Re-)compute the type for a SymConst node.
1530 * @param node the node
1532 static void compute_SymConst(node_t *node) {
1533 ir_node *irn = node->node;
1534 node_t *block = get_irn_node(get_nodes_block(irn));
1536 if (block->type.tv == tarval_unreachable) {
1537 node->type.tv = tarval_top;
1540 switch (get_SymConst_kind(irn)) {
1541 case symconst_addr_ent:
1542 /* case symconst_addr_name: cannot handle this yet */
1543 node->type.sym = get_SymConst_symbol(irn);
1546 node->type.tv = computed_value(irn);
1548 } /* compute_SymConst */
1551 * (Re-)compute the type for a Phi node.
1553 * @param node the node
1555 static void compute_Phi(node_t *node) {
1557 ir_node *phi = node->node;
1558 lattice_elem_t type;
1560 /* if a Phi is in a unreachable block, its type is TOP */
1561 node_t *block = get_irn_node(get_nodes_block(phi));
1563 if (block->type.tv == tarval_unreachable) {
1564 node->type.tv = tarval_top;
1568 /* Phi implements the Meet operation */
1569 type.tv = tarval_top;
1570 for (i = get_Phi_n_preds(phi) - 1; i >= 0; --i) {
1571 node_t *pred = get_irn_node(get_Phi_pred(phi, i));
1572 node_t *pred_X = get_irn_node(get_Block_cfgpred(block->node, i));
1574 if (pred_X->type.tv == tarval_unreachable || pred->type.tv == tarval_top) {
1575 /* ignore TOP inputs: We must check here for unreachable blocks,
1576 because Firm constants live in the Start Block are NEVER Top.
1577 Else, a Phi (1,2) will produce Bottom, even if the 2 for instance
1578 comes from a unreachable input. */
1581 if (pred->type.tv == tarval_bottom) {
1582 node->type.tv = tarval_bottom;
1584 } else if (type.tv == tarval_top) {
1585 /* first constant found */
1587 } else if (type.tv != pred->type.tv) {
1588 /* different constants or tarval_bottom */
1589 node->type.tv = tarval_bottom;
1592 /* else nothing, constants are the same */
1598 * (Re-)compute the type for an Add. Special case: one nodes is a Zero Const.
1600 * @param node the node
1602 static void compute_Add(node_t *node) {
1603 ir_node *sub = node->node;
1604 node_t *l = get_irn_node(get_Add_left(sub));
1605 node_t *r = get_irn_node(get_Add_right(sub));
1606 lattice_elem_t a = l->type;
1607 lattice_elem_t b = r->type;
1610 if (a.tv == tarval_top || b.tv == tarval_top) {
1611 node->type.tv = tarval_top;
1612 } else if (a.tv == tarval_bottom || b.tv == tarval_bottom) {
1613 node->type.tv = tarval_bottom;
1615 /* x + 0 = 0 + x = x, but beware of floating point +0 + -0, so we
1616 must call tarval_add() first to handle this case! */
1617 if (is_tarval(a.tv)) {
1618 if (is_tarval(b.tv)) {
1619 node->type.tv = tarval_add(a.tv, b.tv);
1622 mode = get_tarval_mode(a.tv);
1623 if (a.tv == get_mode_null(mode)) {
1627 } else if (is_tarval(b.tv)) {
1628 mode = get_tarval_mode(b.tv);
1629 if (b.tv == get_mode_null(mode)) {
1634 node->type.tv = tarval_bottom;
1639 * (Re-)compute the type for a Sub. Special case: both nodes are congruent.
1641 * @param node the node
1643 static void compute_Sub(node_t *node) {
1644 ir_node *sub = node->node;
1645 node_t *l = get_irn_node(get_Sub_left(sub));
1646 node_t *r = get_irn_node(get_Sub_right(sub));
1647 lattice_elem_t a = l->type;
1648 lattice_elem_t b = r->type;
1651 if (a.tv == tarval_top || b.tv == tarval_top) {
1652 node->type.tv = tarval_top;
1653 } else if (is_con(a) && is_con(b)) {
1654 if (is_tarval(a.tv) && is_tarval(b.tv)) {
1655 node->type.tv = tarval_sub(a.tv, b.tv, get_irn_mode(sub));
1656 } else if (is_tarval(a.tv) && tarval_is_null(a.tv)) {
1658 } else if (is_tarval(b.tv) && tarval_is_null(b.tv)) {
1661 node->type.tv = tarval_bottom;
1663 node->by_all_const = 1;
1664 } else if (r->part == l->part &&
1665 (!mode_is_float(get_irn_mode(l->node)))) {
1667 * BEWARE: a - a is NOT always 0 for floating Point values, as
1668 * NaN op NaN = NaN, so we must check this here.
1670 ir_mode *mode = get_irn_mode(sub);
1671 tv = get_mode_null(mode);
1673 /* if the node was ONCE evaluated by all constants, but now
1674 this breakes AND we cat by partition a different result, switch to bottom.
1675 This happens because initially all nodes are in the same partition ... */
1676 if (node->by_all_const && node->type.tv != tv)
1680 node->type.tv = tarval_bottom;
1685 * (Re-)compute the type for Cmp.
1687 * @param node the node
1689 static void compute_Cmp(node_t *node) {
1690 ir_node *cmp = node->node;
1691 node_t *l = get_irn_node(get_Cmp_left(cmp));
1692 node_t *r = get_irn_node(get_Cmp_right(cmp));
1693 lattice_elem_t a = l->type;
1694 lattice_elem_t b = r->type;
1696 if (a.tv == tarval_top || b.tv == tarval_top) {
1697 node->type.tv = tarval_top;
1698 } else if (is_con(a) && is_con(b)) {
1699 /* both nodes are constants, we can probably do something */
1700 node->type.tv = tarval_b_true;
1701 } else if (r->part == l->part) {
1702 /* both nodes congruent, we can probably do something */
1703 node->type.tv = tarval_b_true;
1705 node->type.tv = tarval_bottom;
1707 } /* compute_Proj_Cmp */
1710 * (Re-)compute the type for a Proj(Cmp).
1712 * @param node the node
1713 * @param cond the predecessor Cmp node
1715 static void compute_Proj_Cmp(node_t *node, ir_node *cmp) {
1716 ir_node *proj = node->node;
1717 node_t *l = get_irn_node(get_Cmp_left(cmp));
1718 node_t *r = get_irn_node(get_Cmp_right(cmp));
1719 lattice_elem_t a = l->type;
1720 lattice_elem_t b = r->type;
1721 pn_Cmp pnc = get_Proj_proj(proj);
1724 if (a.tv == tarval_top || b.tv == tarval_top) {
1725 node->type.tv = tarval_top;
1726 } else if (is_con(a) && is_con(b)) {
1727 default_compute(node);
1728 node->by_all_const = 1;
1729 } else if (r->part == l->part &&
1730 (!mode_is_float(get_irn_mode(l->node)) || pnc == pn_Cmp_Lt || pnc == pn_Cmp_Gt)) {
1732 * BEWARE: a == a is NOT always True for floating Point values, as
1733 * NaN != NaN is defined, so we must check this here.
1735 tv = new_tarval_from_long(pnc & pn_Cmp_Eq, mode_b);
1737 /* if the node was ONCE evaluated by all constants, but now
1738 this breakes AND we cat by partition a different result, switch to bottom.
1739 This happens because initially all nodes are in the same partition ... */
1740 if (node->by_all_const && node->type.tv != tv)
1744 node->type.tv = tarval_bottom;
1746 } /* compute_Proj_Cmp */
1749 * (Re-)compute the type for a Proj(Cond).
1751 * @param node the node
1752 * @param cond the predecessor Cond node
1754 static void compute_Proj_Cond(node_t *node, ir_node *cond) {
1755 ir_node *proj = node->node;
1756 long pnc = get_Proj_proj(proj);
1757 ir_node *sel = get_Cond_selector(cond);
1758 node_t *selector = get_irn_node(sel);
1760 if (get_irn_mode(sel) == mode_b) {
1762 if (pnc == pn_Cond_true) {
1763 if (selector->type.tv == tarval_b_false) {
1764 node->type.tv = tarval_unreachable;
1765 } else if (selector->type.tv == tarval_b_true) {
1766 node->type.tv = tarval_reachable;
1767 } else if (selector->type.tv == tarval_bottom) {
1768 node->type.tv = tarval_reachable;
1770 assert(selector->type.tv == tarval_top);
1771 node->type.tv = tarval_unreachable;
1774 assert(pnc == pn_Cond_false);
1776 if (selector->type.tv == tarval_b_false) {
1777 node->type.tv = tarval_reachable;
1778 } else if (selector->type.tv == tarval_b_true) {
1779 node->type.tv = tarval_unreachable;
1780 } else if (selector->type.tv == tarval_bottom) {
1781 node->type.tv = tarval_reachable;
1783 assert(selector->type.tv == tarval_top);
1784 node->type.tv = tarval_unreachable;
1789 if (selector->type.tv == tarval_bottom) {
1790 node->type.tv = tarval_reachable;
1791 } else if (selector->type.tv == tarval_top) {
1792 node->type.tv = tarval_unreachable;
1794 long value = get_tarval_long(selector->type.tv);
1795 if (pnc == get_Cond_defaultProj(cond)) {
1796 /* default switch, have to check ALL other cases */
1799 for (i = get_irn_n_outs(cond) - 1; i >= 0; --i) {
1800 ir_node *succ = get_irn_out(cond, i);
1804 if (value == get_Proj_proj(succ)) {
1805 /* we found a match, will NOT take the default case */
1806 node->type.tv = tarval_unreachable;
1810 /* all cases checked, no match, will take default case */
1811 node->type.tv = tarval_reachable;
1814 node->type.tv = value == pnc ? tarval_reachable : tarval_unreachable;
1818 } /* compute_Proj_Cond */
1821 * (Re-)compute the type for a Proj-Node.
1823 * @param node the node
1825 static void compute_Proj(node_t *node) {
1826 ir_node *proj = node->node;
1827 ir_mode *mode = get_irn_mode(proj);
1828 node_t *block = get_irn_node(get_nodes_block(skip_Proj(proj)));
1829 ir_node *pred = get_Proj_pred(proj);
1831 if (block->type.tv == tarval_unreachable) {
1832 /* a Proj in a unreachable Block stay Top */
1833 node->type.tv = tarval_top;
1836 if (get_irn_node(pred)->type.tv == tarval_top) {
1837 /* if the predecessor is Top, its Proj follow */
1838 node->type.tv = tarval_top;
1842 if (mode == mode_M) {
1843 /* mode M is always bottom */
1844 node->type.tv = tarval_bottom;
1847 if (mode != mode_X) {
1849 compute_Proj_Cmp(node, pred);
1851 default_compute(node);
1854 /* handle mode_X nodes */
1856 switch (get_irn_opcode(pred)) {
1858 /* the Proj_X from the Start is always reachable.
1859 However this is already handled at the top. */
1860 node->type.tv = tarval_reachable;
1863 compute_Proj_Cond(node, pred);
1866 default_compute(node);
1868 } /* compute_Proj */
1871 * (Re-)compute the type for a Confirm.
1873 * @param node the node
1875 static void compute_Confirm(node_t *node) {
1876 ir_node *confirm = node->node;
1877 node_t *pred = get_irn_node(get_Confirm_value(confirm));
1879 if (get_Confirm_cmp(confirm) == pn_Cmp_Eq) {
1880 node_t *bound = get_irn_node(get_Confirm_bound(confirm));
1882 if (is_con(bound->type)) {
1883 /* is equal to a constant */
1884 node->type = bound->type;
1888 /* a Confirm is a copy OR a Const */
1889 node->type = pred->type;
1890 } /* compute_Confirm */
1893 * (Re-)compute the type for a Max.
1895 * @param node the node
1897 static void compute_Max(node_t *node) {
1898 ir_node *op = node->node;
1899 node_t *l = get_irn_node(get_binop_left(op));
1900 node_t *r = get_irn_node(get_binop_right(op));
1901 lattice_elem_t a = l->type;
1902 lattice_elem_t b = r->type;
1904 if (a.tv == tarval_top || b.tv == tarval_top) {
1905 node->type.tv = tarval_top;
1906 } else if (is_con(a) && is_con(b)) {
1907 /* both nodes are constants, we can probably do something */
1909 /* this case handles symconsts as well */
1912 ir_mode *mode = get_irn_mode(op);
1913 tarval *tv_min = get_mode_min(mode);
1917 else if (b.tv == tv_min)
1919 else if (is_tarval(a.tv) && is_tarval(b.tv)) {
1920 if (tarval_cmp(a.tv, b.tv) & pn_Cmp_Gt)
1921 node->type.tv = a.tv;
1923 node->type.tv = b.tv;
1925 node->type.tv = tarval_bad;
1928 } else if (r->part == l->part) {
1929 /* both nodes congruent, we can probably do something */
1932 node->type.tv = tarval_bottom;
1937 * (Re-)compute the type for a Min.
1939 * @param node the node
1941 static void compute_Min(node_t *node) {
1942 ir_node *op = node->node;
1943 node_t *l = get_irn_node(get_binop_left(op));
1944 node_t *r = get_irn_node(get_binop_right(op));
1945 lattice_elem_t a = l->type;
1946 lattice_elem_t b = r->type;
1948 if (a.tv == tarval_top || b.tv == tarval_top) {
1949 node->type.tv = tarval_top;
1950 } else if (is_con(a) && is_con(b)) {
1951 /* both nodes are constants, we can probably do something */
1953 /* this case handles symconsts as well */
1956 ir_mode *mode = get_irn_mode(op);
1957 tarval *tv_max = get_mode_max(mode);
1961 else if (b.tv == tv_max)
1963 else if (is_tarval(a.tv) && is_tarval(b.tv)) {
1964 if (tarval_cmp(a.tv, b.tv) & pn_Cmp_Gt)
1965 node->type.tv = a.tv;
1967 node->type.tv = b.tv;
1969 node->type.tv = tarval_bad;
1972 } else if (r->part == l->part) {
1973 /* both nodes congruent, we can probably do something */
1976 node->type.tv = tarval_bottom;
1981 * (Re-)compute the type for a given node.
1983 * @param node the node
1985 static void compute(node_t *node) {
1988 if (is_no_Block(node->node)) {
1989 node_t *block = get_irn_node(get_nodes_block(node->node));
1991 if (block->type.tv == tarval_unreachable) {
1992 node->type.tv = tarval_top;
1997 func = (compute_func)node->node->op->ops.generic;
2003 * Identity functions: Note that one might thing that identity() is just a
2004 * synonym for equivalent_node(). While this is true, we cannot use it for the algorithm
2005 * here, because it expects that the identity node is one of the inputs, which is NOT
2006 * always true for equivalent_node() which can handle (and does sometimes) DAGs.
2007 * So, we have our own implementation, which copies some parts of equivalent_node()
2011 * Calculates the Identity for Phi nodes
2013 static node_t *identity_Phi(node_t *node) {
2014 ir_node *phi = node->node;
2015 ir_node *block = get_nodes_block(phi);
2016 node_t *n_part = NULL;
2019 for (i = get_Phi_n_preds(phi) - 1; i >= 0; --i) {
2020 node_t *pred_X = get_irn_node(get_Block_cfgpred(block, i));
2022 if (pred_X->type.tv == tarval_reachable) {
2023 node_t *pred = get_irn_node(get_Phi_pred(phi, i));
2027 else if (n_part->part != pred->part) {
2028 /* incongruent inputs, not a follower */
2033 /* if n_part is NULL here, all inputs path are dead, the Phi computes
2034 * tarval_top, is in the TOP partition and should NOT being split! */
2035 assert(n_part != NULL);
2037 } /* identity_Phi */
2040 * Calculates the Identity for commutative 0 neutral nodes.
2042 static node_t *identity_comm_zero_binop(node_t *node) {
2043 ir_node *op = node->node;
2044 node_t *a = get_irn_node(get_binop_left(op));
2045 node_t *b = get_irn_node(get_binop_right(op));
2046 ir_mode *mode = get_irn_mode(op);
2049 /* for FP these optimizations are only allowed if fp_strict_algebraic is disabled */
2050 if (mode_is_float(mode) && (get_irg_fp_model(current_ir_graph) & fp_strict_algebraic))
2053 /* node: no input should be tarval_top, else the binop would be also
2054 * Top and not being split. */
2055 zero = get_mode_null(mode);
2056 if (a->type.tv == zero)
2058 if (b->type.tv == zero)
2061 } /* identity_comm_zero_binop */
2063 #define identity_Add identity_comm_zero_binop
2064 #define identity_Or identity_comm_zero_binop
2067 * Calculates the Identity for Mul nodes.
2069 static node_t *identity_Mul(node_t *node) {
2070 ir_node *op = node->node;
2071 node_t *a = get_irn_node(get_Mul_left(op));
2072 node_t *b = get_irn_node(get_Mul_right(op));
2073 ir_mode *mode = get_irn_mode(op);
2076 /* for FP these optimizations are only allowed if fp_strict_algebraic is disabled */
2077 if (mode_is_float(mode) && (get_irg_fp_model(current_ir_graph) & fp_strict_algebraic))
2080 /* node: no input should be tarval_top, else the binop would be also
2081 * Top and not being split. */
2082 one = get_mode_one(mode);
2083 if (a->type.tv == one)
2085 if (b->type.tv == one)
2088 } /* identity_Mul */
2091 * Calculates the Identity for Sub nodes.
2093 static node_t *identity_Sub(node_t *node) {
2094 ir_node *sub = node->node;
2095 node_t *b = get_irn_node(get_Sub_right(sub));
2096 ir_mode *mode = get_irn_mode(sub);
2098 /* for FP these optimizations are only allowed if fp_strict_algebraic is disabled */
2099 if (mode_is_float(mode) && (get_irg_fp_model(current_ir_graph) & fp_strict_algebraic))
2102 /* node: no input should be tarval_top, else the binop would be also
2103 * Top and not being split. */
2104 if (b->type.tv == get_mode_null(mode))
2105 return get_irn_node(get_Sub_left(sub));
2107 } /* identity_Mul */
2110 * Calculates the Identity for And nodes.
2112 static node_t *identity_And(node_t *node) {
2113 ir_node *and = node->node;
2114 node_t *a = get_irn_node(get_And_left(and));
2115 node_t *b = get_irn_node(get_And_right(and));
2116 tarval *neutral = get_mode_all_one(get_irn_mode(and));
2118 /* node: no input should be tarval_top, else the And would be also
2119 * Top and not being split. */
2120 if (a->type.tv == neutral)
2122 if (b->type.tv == neutral)
2125 } /* identity_And */
2128 * Calculates the Identity for Confirm nodes.
2130 static node_t *identity_Confirm(node_t *node) {
2131 ir_node *confirm = node->node;
2133 /* a Confirm is always a Copy */
2134 return get_irn_node(get_Confirm_value(confirm));
2135 } /* identity_Confirm */
2138 * Calculates the Identity for Mux nodes.
2140 static node_t *identity_Mux(node_t *node) {
2141 ir_node *mux = node->node;
2142 node_t *sel = get_irn_node(get_Mux_sel(mux));
2143 node_t *t = get_irn_node(get_Mux_true(mux));
2144 node_t *f = get_irn_node(get_Mux_false(mux));
2146 if (t->part == f->part)
2149 /* Mux sel input is mode_b, so it is always a tarval */
2150 if (sel->type.tv == tarval_b_true)
2152 if (sel->type.tv == tarval_b_false)
2155 } /* identity_Mux */
2158 * Calculates the Identity for Min nodes.
2160 static node_t *identity_Min(node_t *node) {
2161 ir_node *op = node->node;
2162 node_t *a = get_irn_node(get_binop_left(op));
2163 node_t *b = get_irn_node(get_binop_right(op));
2164 ir_mode *mode = get_irn_mode(op);
2167 if (a->part == b->part) {
2168 /* leader of multiple predecessors */
2172 /* works even with NaN */
2173 tv_max = get_mode_max(mode);
2174 if (a->type.tv == tv_max)
2176 if (b->type.tv == tv_max)
2179 } /* identity_Min */
2182 * Calculates the Identity for Max nodes.
2184 static node_t *identity_Max(node_t *node) {
2185 ir_node *op = node->node;
2186 node_t *a = get_irn_node(get_binop_left(op));
2187 node_t *b = get_irn_node(get_binop_right(op));
2188 ir_mode *mode = get_irn_mode(op);
2191 if (a->part == b->part) {
2192 /* leader of multiple predecessors */
2196 /* works even with NaN */
2197 tv_min = get_mode_min(mode);
2198 if (a->type.tv == tv_min)
2200 if (b->type.tv == tv_min)
2203 } /* identity_Max */
2206 * Calculates the Identity for nodes.
2208 static node_t *identity(node_t *node) {
2209 ir_node *irn = node->node;
2211 switch (get_irn_opcode(irn)) {
2213 return identity_Phi(node);
2215 return identity_Add(node);
2217 return identity_Mul(node);
2219 return identity_Or(node);
2221 return identity_And(node);
2223 return identity_Sub(node);
2225 return identity_Confirm(node);
2227 return identity_Mux(node);
2229 return identity_Min(node);
2231 return identity_Max(node);
2238 * Node follower is a (new) follower of leader, segregate Leader
2241 static void segregate_def_use_chain_1(const ir_node *follower, node_t *leader) {
2242 ir_node *l = leader->node;
2243 int j, i, n = get_irn_n_outs(l);
2245 DB((dbg, LEVEL_2, "%+F is a follower of %+F\n", follower, leader->node));
2246 /* The leader edges must remain sorted, but follower edges can
2248 for (i = leader->n_followers + 1; i <= n; ++i) {
2249 if (l->out[i].use == follower) {
2250 ir_def_use_edge t = l->out[i];
2252 for (j = i - 1; j >= leader->n_followers + 1; --j)
2253 l->out[j + 1] = l->out[j];
2254 ++leader->n_followers;
2255 l->out[leader->n_followers] = t;
2259 } /* segregate_def_use_chain_1 */
2262 * Node follower is a (new) follower of leader, segregate Leader
2263 * out edges. If follower is a n-congruent Input identity, all follower
2264 * inputs congruent to follower are also leader.
2266 * @param follower the follower IR node
2268 static void segregate_def_use_chain(const ir_node *follower) {
2271 for (i = get_irn_arity(follower) - 1; i >= 0; --i) {
2272 node_t *pred = get_irn_node(get_irn_n(follower, i));
2274 segregate_def_use_chain_1(follower, pred);
2276 } /* segregate_def_use_chain */
2279 * Propagate constant evaluation.
2281 * @param env the environment
2283 static void propagate(environment_t *env) {
2286 lattice_elem_t old_type;
2288 unsigned n_fallen, old_type_was_T_or_C;
2291 while (env->cprop != NULL) {
2292 void *oldopcode = NULL;
2294 /* remove the first partition X from cprop */
2297 env->cprop = X->cprop_next;
2299 old_type_was_T_or_C = X->type_is_T_or_C;
2301 DB((dbg, LEVEL_2, "Propagate type on part%d\n", X->nr));
2304 while (! list_empty(&X->cprop)) {
2305 /* remove the first Node x from X.cprop */
2306 x = list_entry(X->cprop.next, node_t, cprop_list);
2307 //assert(x->part == X);
2308 list_del(&x->cprop_list);
2311 if (x->is_follower && identity(x) == x) {
2312 /* check the opcode first */
2313 if (oldopcode == NULL) {
2314 oldopcode = lambda_opcode(get_first_node(X), env);
2316 if (oldopcode != lambda_opcode(x, env)) {
2317 if (x->on_fallen == 0) {
2318 /* different opcode -> x falls out of this partition */
2323 DB((dbg, LEVEL_2, "Add node %+F to fallen\n", x->node));
2327 /* x will make the follower -> leader transition */
2328 follower_to_leader(x);
2331 /* compute a new type for x */
2333 DB((dbg, LEVEL_3, "computing type of %+F\n", x->node));
2335 if (x->type.tv != old_type.tv) {
2336 verify_type(old_type, x->type);
2337 DB((dbg, LEVEL_2, "node %+F has changed type from %+F to %+F\n", x->node, old_type, x->type));
2339 if (x->on_fallen == 0) {
2340 /* Add x to fallen. Nodes might fall from T -> const -> _|_, so check that they are
2341 not already on the list. */
2346 DB((dbg, LEVEL_2, "Add node %+F to fallen\n", x->node));
2348 for (i = get_irn_n_outs(x->node) - 1; i >= 0; --i) {
2349 ir_node *succ = get_irn_out(x->node, i);
2350 node_t *y = get_irn_node(succ);
2352 /* Add y to y.partition.cprop. */
2353 add_to_cprop(y, env);
2358 if (n_fallen > 0 && n_fallen != X->n_leader) {
2359 DB((dbg, LEVEL_2, "Splitting part%d by fallen\n", X->nr));
2360 Y = split(&X, fallen, env);
2364 /* remove the flags from the fallen list */
2365 for (x = fallen; x != NULL; x = x->next)
2369 if (old_type_was_T_or_C) {
2372 if (Y->on_worklist == 0)
2373 add_to_worklist(Y, env);
2375 /* check if some nodes will make the leader -> follower transition */
2376 list_for_each_entry_safe(node_t, y, tmp, &Y->Leader, node_list) {
2377 if (!is_Phi(y->node) &&
2378 y->type.tv != tarval_top && ! is_con(y->type)) {
2379 node_t *eq_node = identity(y);
2381 if (eq_node != y && eq_node->part == y->part) {
2382 DB((dbg, LEVEL_2, "Node %+F is a follower of %+F\n", y->node, eq_node->node));
2383 /* move to Follower */
2385 list_del(&y->node_list);
2386 list_add_tail(&y->node_list, &Y->Follower);
2389 segregate_def_use_chain(y->node);
2400 * Get the leader for a given node from its congruence class.
2402 * @param irn the node
2404 static ir_node *get_leader(node_t *node) {
2405 partition_t *part = node->part;
2407 if (part->n_leader > 1 || node->is_follower) {
2408 if (node->is_follower)
2409 DB((dbg, LEVEL_2, "Replacing follower %+F\n", node->node));
2411 DB((dbg, LEVEL_2, "Found congruence class for %+F\n", node->node));
2413 return get_first_node(part)->node;
2419 * Return non-zero if the control flow predecessor node pred
2420 * is the only reachable control flow exit of its block.
2422 * @param pred the control flow exit
2424 static int can_exchange(ir_node *pred) {
2427 else if (is_Jmp(pred))
2429 else if (get_irn_mode(pred) == mode_T) {
2432 /* if the predecessor block has more than one
2433 reachable outputs we cannot remove the block */
2435 for (i = get_irn_n_outs(pred) - 1; i >= 0; --i) {
2436 ir_node *proj = get_irn_out(pred, i);
2439 /* skip non-control flow Proj's */
2440 if (get_irn_mode(proj) != mode_X)
2443 node = get_irn_node(proj);
2444 if (node->type.tv == tarval_reachable) {
2455 * Block Post-Walker, apply the analysis results on control flow by
2456 * shortening Phi's and Block inputs.
2458 static void apply_cf(ir_node *block, void *ctx) {
2459 environment_t *env = ctx;
2460 node_t *node = get_irn_node(block);
2462 ir_node **ins, **in_X;
2463 ir_node *phi, *next;
2465 if (block == get_irg_end_block(current_ir_graph) ||
2466 block == get_irg_start_block(current_ir_graph)) {
2467 /* the EndBlock is always reachable even if the analysis
2468 finds out the opposite :-) */
2471 if (node->type.tv == tarval_unreachable) {
2472 /* mark dead blocks */
2473 set_Block_dead(block);
2477 n = get_Block_n_cfgpreds(block);
2480 /* only one predecessor combine */
2481 ir_node *pred = skip_Proj(get_Block_cfgpred(block, 0));
2483 if (can_exchange(pred)) {
2484 exchange(block, get_nodes_block(pred));
2490 NEW_ARR_A(ir_node *, in_X, n);
2492 for (i = 0; i < n; ++i) {
2493 ir_node *pred = get_Block_cfgpred(block, i);
2494 node_t *node = get_irn_node(pred);
2496 if (node->type.tv == tarval_reachable) {
2503 NEW_ARR_A(ir_node *, ins, n);
2504 for (phi = get_Block_phis(block); phi != NULL; phi = next) {
2505 node_t *node = get_irn_node(phi);
2507 next = get_Phi_next(phi);
2508 if (is_tarval(node->type.tv) && tarval_is_constant(node->type.tv)) {
2509 /* this Phi is replaced by a constant */
2510 tarval *tv = node->type.tv;
2511 ir_node *c = new_r_Const(current_ir_graph, block, get_tarval_mode(tv), tv);
2513 set_irn_node(c, node);
2515 DB((dbg, LEVEL_1, "%+F is replaced by %+F\n", phi, c));
2520 for (i = 0; i < n; ++i) {
2521 node_t *pred = get_irn_node(get_Block_cfgpred(block, i));
2523 if (pred->type.tv == tarval_reachable) {
2524 ins[j++] = get_Phi_pred(phi, i);
2528 /* this Phi is replaced by a single predecessor */
2529 ir_node *s = ins[0];
2532 DB((dbg, LEVEL_1, "%+F is replaced by %+F because of cf change\n", phi, s));
2536 set_irn_in(phi, j, ins);
2543 /* this Block has only one live predecessor */
2544 ir_node *pred = skip_Proj(in_X[0]);
2546 if (can_exchange(pred)) {
2547 exchange(block, get_nodes_block(pred));
2551 set_irn_in(block, k, in_X);
2557 * Post-Walker, apply the analysis results;
2559 static void apply_result(ir_node *irn, void *ctx) {
2560 environment_t *env = ctx;
2561 node_t *node = get_irn_node(irn);
2563 if (is_Block(irn) || is_End(irn) || is_Bad(irn)) {
2564 /* blocks already handled, do not touch the End node */
2566 node_t *block = get_irn_node(get_nodes_block(irn));
2568 if (block->type.tv == tarval_unreachable) {
2569 ir_node *bad = get_irg_bad(current_ir_graph);
2571 /* here, bad might already have a node, but this can be safely ignored
2572 as long as bad has at least ONE valid node */
2573 set_irn_node(bad, node);
2575 DB((dbg, LEVEL_1, "%+F is unreachable\n", irn));
2579 else if (node->type.tv == tarval_unreachable) {
2580 ir_node *bad = get_irg_bad(current_ir_graph);
2582 /* see comment above */
2583 set_irn_node(bad, node);
2585 DB((dbg, LEVEL_1, "%+F is unreachable\n", irn));
2589 else if (get_irn_mode(irn) == mode_X) {
2592 ir_node *cond = get_Proj_pred(irn);
2594 if (is_Cond(cond)) {
2595 node_t *sel = get_irn_node(get_Cond_selector(cond));
2597 if (is_tarval(sel->type.tv) && tarval_is_constant(sel->type.tv)) {
2598 /* Cond selector is a constant, make a Jmp */
2599 ir_node *jmp = new_r_Jmp(current_ir_graph, block->node);
2600 set_irn_node(jmp, node);
2602 DB((dbg, LEVEL_1, "%+F is replaced by %+F\n", irn, jmp));
2609 /* normal data node */
2610 if (is_tarval(node->type.tv) && tarval_is_constant(node->type.tv)) {
2611 tarval *tv = node->type.tv;
2614 * Beware: never replace mode_T nodes by constants. Currently we must mark
2615 * mode_T nodes with constants, but do NOT replace them.
2617 if (! is_Const(irn) && get_irn_mode(irn) != mode_T) {
2618 /* can be replaced by a constant */
2619 ir_node *c = new_r_Const(current_ir_graph, block->node, get_tarval_mode(tv), tv);
2620 set_irn_node(c, node);
2622 DB((dbg, LEVEL_1, "%+F is replaced by %+F\n", irn, c));
2626 } else if (is_entity(node->type.sym.entity_p)) {
2627 if (! is_SymConst(irn)) {
2628 /* can be replaced by a Symconst */
2629 ir_node *symc = new_r_SymConst(current_ir_graph, block->node, get_irn_mode(irn), node->type.sym, symconst_addr_ent);
2630 set_irn_node(symc, node);
2633 DB((dbg, LEVEL_1, "%+F is replaced by %+F\n", irn, symc));
2634 exchange(irn, symc);
2637 } else if (is_Confirm(irn)) {
2638 /* Confirms are always follower, but do not kill them here */
2640 ir_node *leader = get_leader(node);
2642 if (leader != irn) {
2643 DB((dbg, LEVEL_1, "%+F from part%d is replaced by %+F\n", irn, node->part->nr, leader));
2644 exchange(irn, leader);
2650 } /* apply_result */
2653 * Fix the keep-alives by deleting unreachable ones.
2655 static void apply_end(ir_node *end, environment_t *env) {
2656 int i, j, n = get_End_n_keepalives(end);
2660 NEW_ARR_A(ir_node *, in, n);
2662 /* fix the keep alive */
2663 for (i = j = 0; i < n; i++) {
2664 ir_node *ka = get_End_keepalive(end, i);
2665 node_t *node = get_irn_node(ka);
2667 /* Use the flagged bits to mark already visited nodes.
2668 * This should not be ready but better safe than sorry. */
2669 if (node->flagged == 0) {
2673 node = get_irn_node(get_nodes_block(ka));
2675 if (node->type.tv != tarval_unreachable)
2680 set_End_keepalives(end, j, in);
2685 #define SET(code) op_##code->ops.generic = (op_func)compute_##code
2688 * sets the generic functions to compute.
2690 static void set_compute_functions(void) {
2693 /* set the default compute function */
2694 for (i = get_irp_n_opcodes() - 1; i >= 0; --i) {
2695 ir_op *op = get_irp_opcode(i);
2696 op->ops.generic = (op_func)default_compute;
2699 /* set specific functions */
2718 } /* set_compute_functions */
2720 static int dump_partition_hook(FILE *F, ir_node *n, ir_node *local) {
2721 ir_node *irn = local != NULL ? local : n;
2722 node_t *node = get_irn_node(irn);
2724 ir_fprintf(F, "info2 : \"partition %u type %+F\"\n", node->part->nr, node->type);
2728 void combo(ir_graph *irg) {
2730 ir_node *initial_bl;
2732 ir_graph *rem = current_ir_graph;
2734 current_ir_graph = irg;
2736 /* register a debug mask */
2737 FIRM_DBG_REGISTER(dbg, "firm.opt.combo");
2738 //firm_dbg_set_mask(dbg, SET_LEVEL_3);
2740 DB((dbg, LEVEL_1, "Doing COMBO for %+F\n", irg));
2742 obstack_init(&env.obst);
2743 env.worklist = NULL;
2747 #ifdef DEBUG_libfirm
2748 env.dbg_list = NULL;
2750 env.opcode2id_map = new_set(cmp_opcode, iro_Last * 4);
2751 env.type2id_map = pmap_create();
2752 env.end_idx = get_opt_global_cse() ? 0 : -1;
2753 env.lambda_input = 0;
2756 assure_irg_outs(irg);
2758 /* we have our own value_of function */
2759 set_value_of_func(get_node_tarval);
2761 set_compute_functions();
2762 DEBUG_ONLY(part_nr = 0);
2764 /* create the initial partition and place it on the work list */
2765 env.initial = new_partition(&env);
2766 add_to_worklist(env.initial, &env);
2767 irg_walk_graph(irg, init_block_phis, create_initial_partitions, &env);
2769 /* all nodes on the initial partition have type Top */
2770 env.initial->type_is_T_or_C = 1;
2772 /* Place the START Node's partition on cprop.
2773 Place the START Node on its local worklist. */
2774 initial_bl = get_irg_start_block(irg);
2775 start = get_irn_node(initial_bl);
2776 add_to_cprop(start, &env);
2780 if (env.worklist != NULL)
2782 } while (env.cprop != NULL || env.worklist != NULL);
2784 dump_all_partitions(&env);
2787 set_dump_node_vcgattr_hook(dump_partition_hook);
2788 dump_ir_block_graph(irg, "-partition");
2789 set_dump_node_vcgattr_hook(NULL);
2791 (void)dump_partition_hook;
2794 /* apply the result */
2795 irg_block_walk_graph(irg, NULL, apply_cf, &env);
2796 irg_walk_graph(irg, NULL, apply_result, &env);
2797 apply_end(get_irg_end(irg), &env);
2800 /* control flow might changed */
2801 set_irg_outs_inconsistent(irg);
2802 set_irg_extblk_inconsistent(irg);
2803 set_irg_doms_inconsistent(irg);
2804 set_irg_loopinfo_inconsistent(irg);
2807 pmap_destroy(env.type2id_map);
2808 del_set(env.opcode2id_map);
2809 obstack_free(&env.obst, NULL);
2811 /* restore value_of() default behavior */
2812 set_value_of_func(NULL);
2813 current_ir_graph = rem;