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 is_flagged:1; /**< Set, if this node was visited by the race. */
132 unsigned by_all_const:1; /**< Set, if this node was once evaluated by all constants. */
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->is_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->is_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;
571 node->is_flagged = 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. */
825 * Return non-zero, if a input is a real follower
827 * @param irn the node to check
828 * @param input number of the input
830 static int is_real_follower(const ir_node *irn, int input) {
831 if (input == 1 && is_Confirm(irn)) {
832 /* return the Confirm bound input */
835 if (input == 0 && is_Mux(irn)) {
836 /* ignore the Mux sel input */
842 * Do one step in the race.
844 static int step(step_env *env) {
847 if (env->initial != NULL) {
848 /* Move node from initial to unwalked */
850 env->initial = n->race_next;
852 n->race_next = env->unwalked;
858 while (env->unwalked != NULL) {
859 /* let n be the first node in unwalked */
861 while (env->index < n->n_followers) {
862 const ir_def_use_edge *edge = &n->node->out[1 + env->index];
864 /* let m be n.F.def_use[index] */
865 node_t *m = get_irn_node(edge->use);
867 assert(m->is_follower);
869 * Some inputs, like the get_Confirm_bound are NOT
870 * real followers, sort them out.
872 if (! is_real_follower(m->node, edge->pos)) {
878 /* only followers from our partition */
879 if (m->part != n->part)
882 if (m->is_flagged == 0) {
885 /* visited the first time */
886 /* add m to unwalked not as first node (we might still need to
887 check for more follower node */
888 m->race_next = n->race_next;
893 /* move n to walked */
894 env->unwalked = n->race_next;
895 n->race_next = env->walked;
903 * Clear the flags from a list and check for
904 * nodes that where touched from both sides.
906 * @param list the list
908 static void clear_flags(node_t *list) {
911 for (n = list; n != NULL; n = n->race_next)
916 * Split a partition by a local list using the race.
918 * @param pX pointer to the partition to split, might be changed!
919 * @param gg a (non-empty) node list
920 * @param env the environment
922 * @return a new partition containing the nodes of gg
924 static partition_t *split(partition_t **pX, node_t *gg, environment_t *env) {
925 partition_t *X = *pX;
926 partition_t *X_prime;
928 step_env env1, env2, *winner;
929 node_t *g, *h, *node, *t;
932 DEBUG_ONLY(static int run = 0;)
934 DB((dbg, LEVEL_2, "Run %d ", run++));
935 if (list_empty(&X->Follower)) {
936 /* if the partition has NO follower, we can use the fast
937 splitting algorithm. */
938 return split_no_followers(X, gg, env);
940 /* else do the race */
942 dump_partition("Splitting ", X);
943 dump_list("by list ", gg);
945 INIT_LIST_HEAD(&tmp);
947 /* Remove gg from X.Leader and put into g */
949 for (node = gg; node != NULL; node = node->next) {
950 assert(node->part == X);
951 assert(node->is_follower == 0);
953 list_del(&node->node_list);
954 list_add_tail(&node->node_list, &tmp);
960 list_for_each_entry(node_t, node, &X->Leader, node_list) {
964 /* restore X.Leader */
965 list_splice(&tmp, &X->Leader);
968 env1.unwalked = NULL;
973 env2.unwalked = NULL;
987 assert(winner->initial == NULL);
988 assert(winner->unwalked == NULL);
990 /* clear flags from walked/unwalked */
991 clear_flags(env1.unwalked);
992 clear_flags(env1.walked);
993 clear_flags(env2.unwalked);
994 clear_flags(env2.walked);
996 dump_race_list("winner ", winner->walked);
998 /* Move walked_{winner} to a new partition, X'. */
999 X_prime = new_partition(env);
1002 for (node = winner->walked; node != NULL; node = node->race_next) {
1003 list_del(&node->node_list);
1004 node->part = X_prime;
1005 if (node->is_follower) {
1006 list_add_tail(&node->node_list, &X_prime->Follower);
1008 list_add_tail(&node->node_list, &X_prime->Leader);
1011 if (node->max_user_input > max_input)
1012 max_input = node->max_user_input;
1014 X_prime->n_leader = n;
1015 X_prime->max_user_inputs = max_input;
1016 X->n_leader -= X_prime->n_leader;
1018 /* for now, copy the type info tag, it will be adjusted in split_by(). */
1019 X_prime->type_is_T_or_C = X->type_is_T_or_C;
1022 * Even if a follower was not checked by both sides, it might have
1023 * loose its congruence, so we need to check this case for all follower.
1025 list_for_each_entry_safe(node_t, node, t, &X_prime->Follower, node_list) {
1026 if (identity(node) == node)
1027 follower_to_leader(node);
1031 check_partition(X_prime);
1033 /* X' is the smaller part */
1034 add_to_worklist(X_prime, env);
1036 dump_partition("Now ", X);
1037 dump_partition("Created new ", X_prime);
1039 /* we have to ensure that the partition containing g is returned */
1040 if (winner == &env2) {
1047 #endif /* NO_FOLLOWER */
1050 * Returns non-zero if the i'th input of a Phi node is live.
1052 * @param phi a Phi-node
1053 * @param i an input number
1055 * @return non-zero if the i'th input of the given Phi node is live
1057 static int is_live_input(ir_node *phi, int i) {
1059 ir_node *block = get_nodes_block(phi);
1060 ir_node *pred = get_Block_cfgpred(block, i);
1061 lattice_elem_t type = get_node_type(pred);
1063 return type.tv != tarval_unreachable;
1065 /* else it's the control input, always live */
1067 } /* is_live_input */
1070 * Return non-zero if a type is a constant.
1072 static int is_constant_type(lattice_elem_t type) {
1073 if (type.tv != tarval_bottom && type.tv != tarval_top)
1076 } /* is_constant_type */
1079 * Check whether a type is neither Top or a constant.
1080 * Note: U is handled like Top here, R is a constant.
1082 * @param type the type to check
1084 static int type_is_neither_top_nor_const(const lattice_elem_t type) {
1085 if (is_tarval(type.tv)) {
1086 if (type.tv == tarval_top)
1088 if (tarval_is_constant(type.tv))
1098 * Collect nodes to the touched list.
1100 * @param list the list which contains the nodes that must be evaluated
1101 * @param idx the index of the def_use edge to evaluate
1102 * @param env the environment
1104 static void collect_touched(list_head *list, int idx, environment_t *env) {
1106 int end_idx = env->end_idx;
1108 list_for_each_entry(node_t, x, list, node_list) {
1112 /* leader edges start AFTER follower edges */
1113 x->next_edge = x->n_followers + 1;
1115 num_edges = get_irn_n_outs(x->node);
1117 /* for all edges in x.L.def_use_{idx} */
1118 while (x->next_edge <= num_edges) {
1119 const ir_def_use_edge *edge = &x->node->out[x->next_edge];
1122 /* check if we have necessary edges */
1123 if (edge->pos > idx)
1130 /* ignore the "control input" for non-pinned nodes
1131 if we are running in GCSE mode */
1132 if (idx < end_idx && get_irn_pinned(succ) != op_pin_state_pinned)
1135 y = get_irn_node(succ);
1136 assert(get_irn_n(succ, idx) == x->node);
1138 /* ignore block edges touching followers */
1139 if (idx == -1 && y->is_follower)
1142 if (is_constant_type(y->type)) {
1143 ir_opcode code = get_irn_opcode(succ);
1144 if (code == iro_Sub || code == iro_Cmp)
1145 add_to_cprop(y, env);
1148 /* Partitions of constants should not be split simply because their Nodes have unequal
1149 functions or incongruent inputs. */
1150 if (type_is_neither_top_nor_const(y->type) &&
1151 (! is_Phi(y->node) || is_live_input(y->node, idx))) {
1152 add_to_touched(y, env);
1156 } /* collect_touched */
1159 * Split the partitions if caused by the first entry on the worklist.
1161 * @param env the environment
1163 static void cause_splits(environment_t *env) {
1164 partition_t *X, *Z, *N;
1167 /* remove the first partition from the worklist */
1169 env->worklist = X->wl_next;
1172 dump_partition("Cause_split: ", X);
1174 /* combine temporary leader and follower list */
1175 for (idx = -1; idx <= X->max_user_inputs; ++idx) {
1176 /* empty the touched set: already done, just clear the list */
1177 env->touched = NULL;
1179 collect_touched(&X->Leader, idx, env);
1180 collect_touched(&X->Follower, idx, env);
1182 for (Z = env->touched; Z != NULL; Z = N) {
1184 node_t *touched = Z->touched;
1185 unsigned n_touched = Z->n_touched;
1187 assert(Z->touched != NULL);
1189 /* beware, split might change Z */
1190 N = Z->touched_next;
1192 /* remove it from the touched set */
1195 /* Empty local Z.touched. */
1196 for (e = touched; e != NULL; e = e->next) {
1197 assert(e->is_follower == 0);
1203 if (0 < n_touched && n_touched < Z->n_leader) {
1204 DB((dbg, LEVEL_2, "Split part%d by touched\n", Z->nr));
1205 split(&Z, touched, env);
1207 assert(n_touched <= Z->n_leader);
1210 } /* cause_splits */
1213 * Implements split_by_what(): Split a partition by characteristics given
1214 * by the what function.
1216 * @param X the partition to split
1217 * @param What a function returning an Id for every node of the partition X
1218 * @param P a list to store the result partitions
1219 * @param env the environment
1223 static partition_t *split_by_what(partition_t *X, what_func What,
1224 partition_t **P, environment_t *env) {
1227 listmap_entry_t *iter;
1230 /* Let map be an empty mapping from the range of What to (local) list of Nodes. */
1232 list_for_each_entry(node_t, x, &X->Leader, node_list) {
1233 void *id = What(x, env);
1234 listmap_entry_t *entry;
1237 /* input not allowed, ignore */
1240 /* Add x to map[What(x)]. */
1241 entry = listmap_find(&map, id);
1242 x->next = entry->list;
1245 /* Let P be a set of Partitions. */
1247 /* for all sets S except one in the range of map do */
1248 for (iter = map.values; iter != NULL; iter = iter->next) {
1249 if (iter->next == NULL) {
1250 /* this is the last entry, ignore */
1255 /* Add SPLIT( X, S ) to P. */
1256 DB((dbg, LEVEL_2, "Split part%d by what\n", X->nr));
1257 R = split(&X, S, env);
1267 } /* split_by_what */
1269 /** lambda n.(n.type) */
1270 static void *lambda_type(const node_t *node, environment_t *env) {
1272 return node->type.tv;
1275 /** lambda n.(n.opcode) */
1276 static void *lambda_opcode(const node_t *node, environment_t *env) {
1277 opcode_key_t key, *entry;
1278 ir_node *irn = node->node;
1280 key.code = get_irn_opcode(irn);
1281 key.mode = get_irn_mode(irn);
1282 key.arity = get_irn_arity(irn);
1286 switch (get_irn_opcode(irn)) {
1288 key.u.proj = get_Proj_proj(irn);
1291 key.u.ent = get_Sel_entity(irn);
1297 entry = set_insert(env->opcode2id_map, &key, sizeof(key), opcode_hash(&key));
1299 } /* lambda_opcode */
1301 /** lambda n.(n[i].partition) */
1302 static void *lambda_partition(const node_t *node, environment_t *env) {
1303 ir_node *skipped = skip_Proj(node->node);
1306 int i = env->lambda_input;
1308 if (i >= get_irn_arity(node->node)) {
1309 /* we are outside the allowed range */
1313 /* ignore the "control input" for non-pinned nodes
1314 if we are running in GCSE mode */
1315 if (i < env->end_idx && get_irn_pinned(skipped) != op_pin_state_pinned)
1318 pred = i == -1 ? get_irn_n(skipped, i) : get_irn_n(node->node, i);
1319 p = get_irn_node(pred);
1322 } /* lambda_partition */
1325 * Returns true if a type is a constant.
1327 static int is_con(const lattice_elem_t type) {
1328 /* be conservative */
1329 if (is_tarval(type.tv))
1330 return tarval_is_constant(type.tv);
1331 return is_entity(type.sym.entity_p);
1335 * Implements split_by().
1337 * @param X the partition to split
1338 * @param env the environment
1340 static void split_by(partition_t *X, environment_t *env) {
1341 partition_t *I, *P = NULL;
1344 dump_partition("split_by", X);
1346 if (X->n_leader == 1) {
1347 /* we have only one leader, no need to split, just check it's type */
1348 node_t *x = get_first_node(X);
1349 X->type_is_T_or_C = x->type.tv == tarval_top || is_con(x->type);
1353 DB((dbg, LEVEL_2, "WHAT = lambda n.(n.type) on part%d\n", X->nr));
1354 P = split_by_what(X, lambda_type, &P, env);
1356 /* adjust the type tags, we have split partitions by type */
1357 for (I = P; I != NULL; I = I->split_next) {
1358 node_t *x = get_first_node(I);
1359 I->type_is_T_or_C = x->type.tv == tarval_top || is_con(x->type);
1366 if (Y->n_leader > 1) {
1367 /* we do not want split the TOP or constant partitions */
1368 if (! Y->type_is_T_or_C) {
1369 partition_t *Q = NULL;
1371 DB((dbg, LEVEL_2, "WHAT = lambda n.(n.opcode) on part%d\n", Y->nr));
1372 Q = split_by_what(Y, lambda_opcode, &Q, env);
1378 if (Z->n_leader > 1) {
1379 const node_t *first = get_first_node(Z);
1380 int arity = get_irn_arity(first->node);
1384 * BEWARE: during splitting by input 2 for instance we might
1385 * create new partitions which are different by input 1, so collect
1386 * them and split further.
1388 Z->split_next = NULL;
1391 for (input = arity - 1; input >= -1; --input) {
1393 partition_t *Z_prime = R;
1396 if (Z_prime->n_leader > 1) {
1397 env->lambda_input = input;
1398 DB((dbg, LEVEL_2, "WHAT = lambda n.(n[%d].partition) on part%d\n", input, Z_prime->nr));
1399 S = split_by_what(Z_prime, lambda_partition, &S, env);
1401 Z_prime->split_next = S;
1404 } while (R != NULL);
1409 } while (Q != NULL);
1412 } while (P != NULL);
1416 * (Re-)compute the type for a given node.
1418 * @param node the node
1420 static void default_compute(node_t *node) {
1422 ir_node *irn = node->node;
1423 node_t *block = get_irn_node(get_nodes_block(irn));
1425 if (block->type.tv == tarval_unreachable) {
1426 node->type.tv = tarval_top;
1430 /* if any of the data inputs have type top, the result is type top */
1431 for (i = get_irn_arity(irn) - 1; i >= 0; --i) {
1432 ir_node *pred = get_irn_n(irn, i);
1433 node_t *p = get_irn_node(pred);
1435 if (p->type.tv == tarval_top) {
1436 node->type.tv = tarval_top;
1441 if (get_irn_mode(node->node) == mode_X)
1442 node->type.tv = tarval_reachable;
1444 node->type.tv = computed_value(irn);
1445 } /* default_compute */
1448 * (Re-)compute the type for a Block node.
1450 * @param node the node
1452 static void compute_Block(node_t *node) {
1454 ir_node *block = node->node;
1456 if (block == get_irg_start_block(current_ir_graph)) {
1457 /* start block is always reachable */
1458 node->type.tv = tarval_reachable;
1462 for (i = get_Block_n_cfgpreds(block) - 1; i >= 0; --i) {
1463 node_t *pred = get_irn_node(get_Block_cfgpred(block, i));
1465 if (pred->type.tv == tarval_reachable) {
1466 /* A block is reachable, if at least of predecessor is reachable. */
1467 node->type.tv = tarval_reachable;
1471 node->type.tv = tarval_top;
1472 } /* compute_Block */
1475 * (Re-)compute the type for a Bad node.
1477 * @param node the node
1479 static void compute_Bad(node_t *node) {
1480 /* Bad nodes ALWAYS compute Top */
1481 node->type.tv = tarval_top;
1485 * (Re-)compute the type for an Unknown node.
1487 * @param node the node
1489 static void compute_Unknown(node_t *node) {
1490 /* While Unknown nodes should compute Top this is dangerous:
1491 * a Top input to a Cond would lead to BOTH control flows unreachable.
1492 * While this is correct in the given semantics, it would destroy the Firm
1495 * It would be safe to compute Top IF it can be assured, that only Cmp
1496 * nodes are inputs to Conds. We check that first.
1497 * This is the way Frontends typically build Firm, but some optimizations
1498 * (cond_eval for instance) might replace them by Phib's...
1500 * For now, we compute bottom here.
1502 node->type.tv = tarval_bottom;
1503 } /* compute_Unknown */
1506 * (Re-)compute the type for a Jmp node.
1508 * @param node the node
1510 static void compute_Jmp(node_t *node) {
1511 node_t *block = get_irn_node(get_nodes_block(node->node));
1513 node->type = block->type;
1517 * (Re-)compute the type for the End node.
1519 * @param node the node
1521 static void compute_End(node_t *node) {
1522 /* the End node is NOT dead of course */
1523 node->type.tv = tarval_reachable;
1527 * (Re-)compute the type for a SymConst node.
1529 * @param node the node
1531 static void compute_SymConst(node_t *node) {
1532 ir_node *irn = node->node;
1533 node_t *block = get_irn_node(get_nodes_block(irn));
1535 if (block->type.tv == tarval_unreachable) {
1536 node->type.tv = tarval_top;
1539 switch (get_SymConst_kind(irn)) {
1540 case symconst_addr_ent:
1541 /* case symconst_addr_name: cannot handle this yet */
1542 node->type.sym = get_SymConst_symbol(irn);
1545 node->type.tv = computed_value(irn);
1547 } /* compute_SymConst */
1550 * (Re-)compute the type for a Phi node.
1552 * @param node the node
1554 static void compute_Phi(node_t *node) {
1556 ir_node *phi = node->node;
1557 lattice_elem_t type;
1559 /* if a Phi is in a unreachable block, its type is TOP */
1560 node_t *block = get_irn_node(get_nodes_block(phi));
1562 if (block->type.tv == tarval_unreachable) {
1563 node->type.tv = tarval_top;
1567 /* Phi implements the Meet operation */
1568 type.tv = tarval_top;
1569 for (i = get_Phi_n_preds(phi) - 1; i >= 0; --i) {
1570 node_t *pred = get_irn_node(get_Phi_pred(phi, i));
1571 node_t *pred_X = get_irn_node(get_Block_cfgpred(block->node, i));
1573 if (pred_X->type.tv == tarval_unreachable || pred->type.tv == tarval_top) {
1574 /* ignore TOP inputs: We must check here for unreachable blocks,
1575 because Firm constants live in the Start Block are NEVER Top.
1576 Else, a Phi (1,2) will produce Bottom, even if the 2 for instance
1577 comes from a unreachable input. */
1580 if (pred->type.tv == tarval_bottom) {
1581 node->type.tv = tarval_bottom;
1583 } else if (type.tv == tarval_top) {
1584 /* first constant found */
1586 } else if (type.tv != pred->type.tv) {
1587 /* different constants or tarval_bottom */
1588 node->type.tv = tarval_bottom;
1591 /* else nothing, constants are the same */
1597 * (Re-)compute the type for an Add. Special case: one nodes is a Zero Const.
1599 * @param node the node
1601 static void compute_Add(node_t *node) {
1602 ir_node *sub = node->node;
1603 node_t *l = get_irn_node(get_Add_left(sub));
1604 node_t *r = get_irn_node(get_Add_right(sub));
1605 lattice_elem_t a = l->type;
1606 lattice_elem_t b = r->type;
1609 if (a.tv == tarval_top || b.tv == tarval_top) {
1610 node->type.tv = tarval_top;
1611 } else if (a.tv == tarval_bottom || b.tv == tarval_bottom) {
1612 node->type.tv = tarval_bottom;
1614 /* x + 0 = 0 + x = x, but beware of floating point +0 + -0, so we
1615 must call tarval_add() first to handle this case! */
1616 if (is_tarval(a.tv)) {
1617 if (is_tarval(b.tv)) {
1618 node->type.tv = tarval_add(a.tv, b.tv);
1621 mode = get_tarval_mode(a.tv);
1622 if (a.tv == get_mode_null(mode)) {
1626 } else if (is_tarval(b.tv)) {
1627 mode = get_tarval_mode(b.tv);
1628 if (b.tv == get_mode_null(mode)) {
1633 node->type.tv = tarval_bottom;
1638 * (Re-)compute the type for a Sub. Special case: both nodes are congruent.
1640 * @param node the node
1642 static void compute_Sub(node_t *node) {
1643 ir_node *sub = node->node;
1644 node_t *l = get_irn_node(get_Sub_left(sub));
1645 node_t *r = get_irn_node(get_Sub_right(sub));
1646 lattice_elem_t a = l->type;
1647 lattice_elem_t b = r->type;
1650 if (a.tv == tarval_top || b.tv == tarval_top) {
1651 node->type.tv = tarval_top;
1652 } else if (is_con(a) && is_con(b)) {
1653 if (is_tarval(a.tv) && is_tarval(b.tv)) {
1654 node->type.tv = tarval_sub(a.tv, b.tv, get_irn_mode(sub));
1655 } else if (is_tarval(a.tv) && tarval_is_null(a.tv)) {
1657 } else if (is_tarval(b.tv) && tarval_is_null(b.tv)) {
1660 node->type.tv = tarval_bottom;
1662 node->by_all_const = 1;
1663 } else if (r->part == l->part &&
1664 (!mode_is_float(get_irn_mode(l->node)))) {
1666 * BEWARE: a - a is NOT always 0 for floating Point values, as
1667 * NaN op NaN = NaN, so we must check this here.
1669 ir_mode *mode = get_irn_mode(sub);
1670 tv = get_mode_null(mode);
1672 /* if the node was ONCE evaluated by all constants, but now
1673 this breakes AND we cat by partition a different result, switch to bottom.
1674 This happens because initially all nodes are in the same partition ... */
1675 if (node->by_all_const && node->type.tv != tv)
1679 node->type.tv = tarval_bottom;
1684 * (Re-)compute the type for Cmp.
1686 * @param node the node
1688 static void compute_Cmp(node_t *node) {
1689 ir_node *cmp = node->node;
1690 node_t *l = get_irn_node(get_Cmp_left(cmp));
1691 node_t *r = get_irn_node(get_Cmp_right(cmp));
1692 lattice_elem_t a = l->type;
1693 lattice_elem_t b = r->type;
1695 if (a.tv == tarval_top || b.tv == tarval_top) {
1696 node->type.tv = tarval_top;
1697 } else if (is_con(a) && is_con(b)) {
1698 /* both nodes are constants, we can probably do something */
1699 node->type.tv = tarval_b_true;
1700 } else if (r->part == l->part) {
1701 /* both nodes congruent, we can probably do something */
1702 node->type.tv = tarval_b_true;
1704 node->type.tv = tarval_bottom;
1706 } /* compute_Proj_Cmp */
1709 * (Re-)compute the type for a Proj(Cmp).
1711 * @param node the node
1712 * @param cond the predecessor Cmp node
1714 static void compute_Proj_Cmp(node_t *node, ir_node *cmp) {
1715 ir_node *proj = node->node;
1716 node_t *l = get_irn_node(get_Cmp_left(cmp));
1717 node_t *r = get_irn_node(get_Cmp_right(cmp));
1718 lattice_elem_t a = l->type;
1719 lattice_elem_t b = r->type;
1720 pn_Cmp pnc = get_Proj_proj(proj);
1723 if (a.tv == tarval_top || b.tv == tarval_top) {
1724 node->type.tv = tarval_top;
1725 } else if (is_con(a) && is_con(b)) {
1726 default_compute(node);
1727 node->by_all_const = 1;
1728 } else if (r->part == l->part &&
1729 (!mode_is_float(get_irn_mode(l->node)) || pnc == pn_Cmp_Lt || pnc == pn_Cmp_Gt)) {
1731 * BEWARE: a == a is NOT always True for floating Point values, as
1732 * NaN != NaN is defined, so we must check this here.
1734 tv = new_tarval_from_long(pnc & pn_Cmp_Eq, mode_b);
1736 /* if the node was ONCE evaluated by all constants, but now
1737 this breakes AND we cat by partition a different result, switch to bottom.
1738 This happens because initially all nodes are in the same partition ... */
1739 if (node->by_all_const && node->type.tv != tv)
1743 node->type.tv = tarval_bottom;
1745 } /* compute_Proj_Cmp */
1748 * (Re-)compute the type for a Proj(Cond).
1750 * @param node the node
1751 * @param cond the predecessor Cond node
1753 static void compute_Proj_Cond(node_t *node, ir_node *cond) {
1754 ir_node *proj = node->node;
1755 long pnc = get_Proj_proj(proj);
1756 ir_node *sel = get_Cond_selector(cond);
1757 node_t *selector = get_irn_node(sel);
1759 if (get_irn_mode(sel) == mode_b) {
1761 if (pnc == pn_Cond_true) {
1762 if (selector->type.tv == tarval_b_false) {
1763 node->type.tv = tarval_unreachable;
1764 } else if (selector->type.tv == tarval_b_true) {
1765 node->type.tv = tarval_reachable;
1766 } else if (selector->type.tv == tarval_bottom) {
1767 node->type.tv = tarval_reachable;
1769 assert(selector->type.tv == tarval_top);
1770 node->type.tv = tarval_unreachable;
1773 assert(pnc == pn_Cond_false);
1775 if (selector->type.tv == tarval_b_false) {
1776 node->type.tv = tarval_reachable;
1777 } else if (selector->type.tv == tarval_b_true) {
1778 node->type.tv = tarval_unreachable;
1779 } else if (selector->type.tv == tarval_bottom) {
1780 node->type.tv = tarval_reachable;
1782 assert(selector->type.tv == tarval_top);
1783 node->type.tv = tarval_unreachable;
1788 if (selector->type.tv == tarval_bottom) {
1789 node->type.tv = tarval_reachable;
1790 } else if (selector->type.tv == tarval_top) {
1791 node->type.tv = tarval_unreachable;
1793 long value = get_tarval_long(selector->type.tv);
1794 if (pnc == get_Cond_defaultProj(cond)) {
1795 /* default switch, have to check ALL other cases */
1798 for (i = get_irn_n_outs(cond) - 1; i >= 0; --i) {
1799 ir_node *succ = get_irn_out(cond, i);
1803 if (value == get_Proj_proj(succ)) {
1804 /* we found a match, will NOT take the default case */
1805 node->type.tv = tarval_unreachable;
1809 /* all cases checked, no match, will take default case */
1810 node->type.tv = tarval_reachable;
1813 node->type.tv = value == pnc ? tarval_reachable : tarval_unreachable;
1817 } /* compute_Proj_Cond */
1820 * (Re-)compute the type for a Proj-Node.
1822 * @param node the node
1824 static void compute_Proj(node_t *node) {
1825 ir_node *proj = node->node;
1826 ir_mode *mode = get_irn_mode(proj);
1827 node_t *block = get_irn_node(get_nodes_block(skip_Proj(proj)));
1828 ir_node *pred = get_Proj_pred(proj);
1830 if (block->type.tv == tarval_unreachable) {
1831 /* a Proj in a unreachable Block stay Top */
1832 node->type.tv = tarval_top;
1835 if (get_irn_node(pred)->type.tv == tarval_top) {
1836 /* if the predecessor is Top, its Proj follow */
1837 node->type.tv = tarval_top;
1841 if (mode == mode_M) {
1842 /* mode M is always bottom */
1843 node->type.tv = tarval_bottom;
1846 if (mode != mode_X) {
1848 compute_Proj_Cmp(node, pred);
1850 default_compute(node);
1853 /* handle mode_X nodes */
1855 switch (get_irn_opcode(pred)) {
1857 /* the Proj_X from the Start is always reachable.
1858 However this is already handled at the top. */
1859 node->type.tv = tarval_reachable;
1862 compute_Proj_Cond(node, pred);
1865 default_compute(node);
1867 } /* compute_Proj */
1870 * (Re-)compute the type for a Confirm.
1872 * @param node the node
1874 static void compute_Confirm(node_t *node) {
1875 ir_node *confirm = node->node;
1876 node_t *pred = get_irn_node(get_Confirm_value(confirm));
1878 if (get_Confirm_cmp(confirm) == pn_Cmp_Eq) {
1879 node_t *bound = get_irn_node(get_Confirm_bound(confirm));
1881 if (is_con(bound->type)) {
1882 /* is equal to a constant */
1883 node->type = bound->type;
1887 /* a Confirm is a copy OR a Const */
1888 node->type = pred->type;
1889 } /* compute_Confirm */
1892 * (Re-)compute the type for a Max.
1894 * @param node the node
1896 static void compute_Max(node_t *node) {
1897 ir_node *op = node->node;
1898 node_t *l = get_irn_node(get_binop_left(op));
1899 node_t *r = get_irn_node(get_binop_right(op));
1900 lattice_elem_t a = l->type;
1901 lattice_elem_t b = r->type;
1903 if (a.tv == tarval_top || b.tv == tarval_top) {
1904 node->type.tv = tarval_top;
1905 } else if (is_con(a) && is_con(b)) {
1906 /* both nodes are constants, we can probably do something */
1908 /* this case handles symconsts as well */
1911 ir_mode *mode = get_irn_mode(op);
1912 tarval *tv_min = get_mode_min(mode);
1916 else if (b.tv == tv_min)
1918 else if (is_tarval(a.tv) && is_tarval(b.tv)) {
1919 if (tarval_cmp(a.tv, b.tv) & pn_Cmp_Gt)
1920 node->type.tv = a.tv;
1922 node->type.tv = b.tv;
1924 node->type.tv = tarval_bad;
1927 } else if (r->part == l->part) {
1928 /* both nodes congruent, we can probably do something */
1931 node->type.tv = tarval_bottom;
1936 * (Re-)compute the type for a Min.
1938 * @param node the node
1940 static void compute_Min(node_t *node) {
1941 ir_node *op = node->node;
1942 node_t *l = get_irn_node(get_binop_left(op));
1943 node_t *r = get_irn_node(get_binop_right(op));
1944 lattice_elem_t a = l->type;
1945 lattice_elem_t b = r->type;
1947 if (a.tv == tarval_top || b.tv == tarval_top) {
1948 node->type.tv = tarval_top;
1949 } else if (is_con(a) && is_con(b)) {
1950 /* both nodes are constants, we can probably do something */
1952 /* this case handles symconsts as well */
1955 ir_mode *mode = get_irn_mode(op);
1956 tarval *tv_max = get_mode_max(mode);
1960 else if (b.tv == tv_max)
1962 else if (is_tarval(a.tv) && is_tarval(b.tv)) {
1963 if (tarval_cmp(a.tv, b.tv) & pn_Cmp_Gt)
1964 node->type.tv = a.tv;
1966 node->type.tv = b.tv;
1968 node->type.tv = tarval_bad;
1971 } else if (r->part == l->part) {
1972 /* both nodes congruent, we can probably do something */
1975 node->type.tv = tarval_bottom;
1980 * (Re-)compute the type for a given node.
1982 * @param node the node
1984 static void compute(node_t *node) {
1987 if (is_no_Block(node->node)) {
1988 node_t *block = get_irn_node(get_nodes_block(node->node));
1990 if (block->type.tv == tarval_unreachable) {
1991 node->type.tv = tarval_top;
1996 func = (compute_func)node->node->op->ops.generic;
2002 * Identity functions: Note that one might thing that identity() is just a
2003 * synonym for equivalent_node(). While this is true, we cannot use it for the algorithm
2004 * here, because it expects that the identity node is one of the inputs, which is NOT
2005 * always true for equivalent_node() which can handle (and does sometimes) DAGs.
2006 * So, we have our own implementation, which copies some parts of equivalent_node()
2010 * Calculates the Identity for Phi nodes
2012 static node_t *identity_Phi(node_t *node) {
2013 ir_node *phi = node->node;
2014 ir_node *block = get_nodes_block(phi);
2015 node_t *n_part = NULL;
2018 for (i = get_Phi_n_preds(phi) - 1; i >= 0; --i) {
2019 node_t *pred_X = get_irn_node(get_Block_cfgpred(block, i));
2021 if (pred_X->type.tv == tarval_reachable) {
2022 node_t *pred = get_irn_node(get_Phi_pred(phi, i));
2026 else if (n_part->part != pred->part) {
2027 /* incongruent inputs, not a follower */
2032 /* if n_part is NULL here, all inputs path are dead, the Phi computes
2033 * tarval_top, is in the TOP partition and should NOT being split! */
2034 assert(n_part != NULL);
2036 } /* identity_Phi */
2039 * Calculates the Identity for commutative 0 neutral nodes.
2041 static node_t *identity_comm_zero_binop(node_t *node) {
2042 ir_node *op = node->node;
2043 node_t *a = get_irn_node(get_binop_left(op));
2044 node_t *b = get_irn_node(get_binop_right(op));
2045 ir_mode *mode = get_irn_mode(op);
2048 /* for FP these optimizations are only allowed if fp_strict_algebraic is disabled */
2049 if (mode_is_float(mode) && (get_irg_fp_model(current_ir_graph) & fp_strict_algebraic))
2052 /* node: no input should be tarval_top, else the binop would be also
2053 * Top and not being split. */
2054 zero = get_mode_null(mode);
2055 if (a->type.tv == zero)
2057 if (b->type.tv == zero)
2060 } /* identity_comm_zero_binop */
2062 #define identity_Add identity_comm_zero_binop
2063 #define identity_Or identity_comm_zero_binop
2066 * Calculates the Identity for Mul nodes.
2068 static node_t *identity_Mul(node_t *node) {
2069 ir_node *op = node->node;
2070 node_t *a = get_irn_node(get_Mul_left(op));
2071 node_t *b = get_irn_node(get_Mul_right(op));
2072 ir_mode *mode = get_irn_mode(op);
2075 /* for FP these optimizations are only allowed if fp_strict_algebraic is disabled */
2076 if (mode_is_float(mode) && (get_irg_fp_model(current_ir_graph) & fp_strict_algebraic))
2079 /* node: no input should be tarval_top, else the binop would be also
2080 * Top and not being split. */
2081 one = get_mode_one(mode);
2082 if (a->type.tv == one)
2084 if (b->type.tv == one)
2087 } /* identity_Mul */
2090 * Calculates the Identity for Sub nodes.
2092 static node_t *identity_Sub(node_t *node) {
2093 ir_node *sub = node->node;
2094 node_t *b = get_irn_node(get_Sub_right(sub));
2095 ir_mode *mode = get_irn_mode(sub);
2097 /* for FP these optimizations are only allowed if fp_strict_algebraic is disabled */
2098 if (mode_is_float(mode) && (get_irg_fp_model(current_ir_graph) & fp_strict_algebraic))
2101 /* node: no input should be tarval_top, else the binop would be also
2102 * Top and not being split. */
2103 if (b->type.tv == get_mode_null(mode))
2104 return get_irn_node(get_Sub_left(sub));
2106 } /* identity_Mul */
2109 * Calculates the Identity for And nodes.
2111 static node_t *identity_And(node_t *node) {
2112 ir_node *and = node->node;
2113 node_t *a = get_irn_node(get_And_left(and));
2114 node_t *b = get_irn_node(get_And_right(and));
2115 tarval *neutral = get_mode_all_one(get_irn_mode(and));
2117 /* node: no input should be tarval_top, else the And would be also
2118 * Top and not being split. */
2119 if (a->type.tv == neutral)
2121 if (b->type.tv == neutral)
2124 } /* identity_And */
2127 * Calculates the Identity for Confirm nodes.
2129 static node_t *identity_Confirm(node_t *node) {
2130 ir_node *confirm = node->node;
2132 /* a Confirm is always a Copy */
2133 return get_irn_node(get_Confirm_value(confirm));
2134 } /* identity_Confirm */
2137 * Calculates the Identity for Mux nodes.
2139 static node_t *identity_Mux(node_t *node) {
2140 ir_node *mux = node->node;
2141 node_t *t = get_irn_node(get_Mux_true(mux));
2142 node_t *f = get_irn_node(get_Mux_false(mux));
2145 if (t->part == f->part)
2148 /* for now, the 1-input identity is not supported */
2150 sel = get_irn_node(get_Mux_sel(mux));
2152 /* Mux sel input is mode_b, so it is always a tarval */
2153 if (sel->type.tv == tarval_b_true)
2155 if (sel->type.tv == tarval_b_false)
2159 } /* identity_Mux */
2162 * Calculates the Identity for Min nodes.
2164 static node_t *identity_Min(node_t *node) {
2165 ir_node *op = node->node;
2166 node_t *a = get_irn_node(get_binop_left(op));
2167 node_t *b = get_irn_node(get_binop_right(op));
2168 ir_mode *mode = get_irn_mode(op);
2171 if (a->part == b->part) {
2172 /* leader of multiple predecessors */
2176 /* works even with NaN */
2177 tv_max = get_mode_max(mode);
2178 if (a->type.tv == tv_max)
2180 if (b->type.tv == tv_max)
2183 } /* identity_Min */
2186 * Calculates the Identity for Max nodes.
2188 static node_t *identity_Max(node_t *node) {
2189 ir_node *op = node->node;
2190 node_t *a = get_irn_node(get_binop_left(op));
2191 node_t *b = get_irn_node(get_binop_right(op));
2192 ir_mode *mode = get_irn_mode(op);
2195 if (a->part == b->part) {
2196 /* leader of multiple predecessors */
2200 /* works even with NaN */
2201 tv_min = get_mode_min(mode);
2202 if (a->type.tv == tv_min)
2204 if (b->type.tv == tv_min)
2207 } /* identity_Max */
2210 * Calculates the Identity for nodes.
2212 static node_t *identity(node_t *node) {
2213 ir_node *irn = node->node;
2215 switch (get_irn_opcode(irn)) {
2217 return identity_Phi(node);
2219 return identity_Add(node);
2221 return identity_Mul(node);
2223 return identity_Or(node);
2225 return identity_And(node);
2227 return identity_Sub(node);
2229 return identity_Confirm(node);
2231 return identity_Mux(node);
2233 return identity_Min(node);
2235 return identity_Max(node);
2242 * Node follower is a (new) follower of leader, segregate Leader
2245 static void segregate_def_use_chain_1(const ir_node *follower, node_t *leader) {
2246 ir_node *l = leader->node;
2247 int j, i, n = get_irn_n_outs(l);
2249 DB((dbg, LEVEL_2, "%+F is a follower of %+F\n", follower, leader->node));
2250 /* The leader edges must remain sorted, but follower edges can
2252 for (i = leader->n_followers + 1; i <= n; ++i) {
2253 if (l->out[i].use == follower) {
2254 ir_def_use_edge t = l->out[i];
2256 for (j = i - 1; j >= leader->n_followers + 1; --j)
2257 l->out[j + 1] = l->out[j];
2258 ++leader->n_followers;
2259 l->out[leader->n_followers] = t;
2263 } /* segregate_def_use_chain_1 */
2266 * Node follower is a (new) follower of leader, segregate Leader
2267 * out edges. If follower is a n-congruent Input identity, all follower
2268 * inputs congruent to follower are also leader.
2270 * @param follower the follower IR node
2272 static void segregate_def_use_chain(const ir_node *follower) {
2275 for (i = get_irn_arity(follower) - 1; i >= 0; --i) {
2276 node_t *pred = get_irn_node(get_irn_n(follower, i));
2278 segregate_def_use_chain_1(follower, pred);
2280 } /* segregate_def_use_chain */
2283 * Propagate constant evaluation.
2285 * @param env the environment
2287 static void propagate(environment_t *env) {
2290 lattice_elem_t old_type;
2292 unsigned n_fallen, old_type_was_T_or_C;
2295 while (env->cprop != NULL) {
2296 void *oldopcode = NULL;
2298 /* remove the first partition X from cprop */
2301 env->cprop = X->cprop_next;
2303 old_type_was_T_or_C = X->type_is_T_or_C;
2305 DB((dbg, LEVEL_2, "Propagate type on part%d\n", X->nr));
2308 while (! list_empty(&X->cprop)) {
2309 /* remove the first Node x from X.cprop */
2310 x = list_entry(X->cprop.next, node_t, cprop_list);
2311 //assert(x->part == X);
2312 list_del(&x->cprop_list);
2315 if (x->is_follower && identity(x) == x) {
2316 /* check the opcode first */
2317 if (oldopcode == NULL) {
2318 oldopcode = lambda_opcode(get_first_node(X), env);
2320 if (oldopcode != lambda_opcode(x, env)) {
2321 if (x->on_fallen == 0) {
2322 /* different opcode -> x falls out of this partition */
2327 DB((dbg, LEVEL_2, "Add node %+F to fallen\n", x->node));
2331 /* x will make the follower -> leader transition */
2332 follower_to_leader(x);
2335 /* compute a new type for x */
2337 DB((dbg, LEVEL_3, "computing type of %+F\n", x->node));
2339 if (x->type.tv != old_type.tv) {
2340 verify_type(old_type, x->type);
2341 DB((dbg, LEVEL_2, "node %+F has changed type from %+F to %+F\n", x->node, old_type, x->type));
2343 if (x->on_fallen == 0) {
2344 /* Add x to fallen. Nodes might fall from T -> const -> _|_, so check that they are
2345 not already on the list. */
2350 DB((dbg, LEVEL_2, "Add node %+F to fallen\n", x->node));
2352 for (i = get_irn_n_outs(x->node) - 1; i >= 0; --i) {
2353 ir_node *succ = get_irn_out(x->node, i);
2354 node_t *y = get_irn_node(succ);
2356 /* Add y to y.partition.cprop. */
2357 add_to_cprop(y, env);
2362 if (n_fallen > 0 && n_fallen != X->n_leader) {
2363 DB((dbg, LEVEL_2, "Splitting part%d by fallen\n", X->nr));
2364 Y = split(&X, fallen, env);
2368 /* remove the flags from the fallen list */
2369 for (x = fallen; x != NULL; x = x->next)
2373 if (old_type_was_T_or_C) {
2376 if (Y->on_worklist == 0)
2377 add_to_worklist(Y, env);
2379 /* check if some nodes will make the leader -> follower transition */
2380 list_for_each_entry_safe(node_t, y, tmp, &Y->Leader, node_list) {
2381 if (!is_Phi(y->node) &&
2382 y->type.tv != tarval_top && ! is_con(y->type)) {
2383 node_t *eq_node = identity(y);
2385 if (eq_node != y && eq_node->part == y->part) {
2386 DB((dbg, LEVEL_2, "Node %+F is a follower of %+F\n", y->node, eq_node->node));
2387 /* move to Follower */
2389 list_del(&y->node_list);
2390 list_add_tail(&y->node_list, &Y->Follower);
2393 segregate_def_use_chain(y->node);
2404 * Get the leader for a given node from its congruence class.
2406 * @param irn the node
2408 static ir_node *get_leader(node_t *node) {
2409 partition_t *part = node->part;
2411 if (part->n_leader > 1 || node->is_follower) {
2412 if (node->is_follower)
2413 DB((dbg, LEVEL_2, "Replacing follower %+F\n", node->node));
2415 DB((dbg, LEVEL_2, "Found congruence class for %+F\n", node->node));
2417 return get_first_node(part)->node;
2423 * Return non-zero if the control flow predecessor node pred
2424 * is the only reachable control flow exit of its block.
2426 * @param pred the control flow exit
2428 static int can_exchange(ir_node *pred) {
2431 else if (is_Jmp(pred))
2433 else if (get_irn_mode(pred) == mode_T) {
2436 /* if the predecessor block has more than one
2437 reachable outputs we cannot remove the block */
2439 for (i = get_irn_n_outs(pred) - 1; i >= 0; --i) {
2440 ir_node *proj = get_irn_out(pred, i);
2443 /* skip non-control flow Proj's */
2444 if (get_irn_mode(proj) != mode_X)
2447 node = get_irn_node(proj);
2448 if (node->type.tv == tarval_reachable) {
2459 * Block Post-Walker, apply the analysis results on control flow by
2460 * shortening Phi's and Block inputs.
2462 static void apply_cf(ir_node *block, void *ctx) {
2463 environment_t *env = ctx;
2464 node_t *node = get_irn_node(block);
2466 ir_node **ins, **in_X;
2467 ir_node *phi, *next;
2469 if (block == get_irg_end_block(current_ir_graph) ||
2470 block == get_irg_start_block(current_ir_graph)) {
2471 /* the EndBlock is always reachable even if the analysis
2472 finds out the opposite :-) */
2475 if (node->type.tv == tarval_unreachable) {
2476 /* mark dead blocks */
2477 set_Block_dead(block);
2481 n = get_Block_n_cfgpreds(block);
2484 /* only one predecessor combine */
2485 ir_node *pred = skip_Proj(get_Block_cfgpred(block, 0));
2487 if (can_exchange(pred)) {
2488 exchange(block, get_nodes_block(pred));
2494 NEW_ARR_A(ir_node *, in_X, n);
2496 for (i = 0; i < n; ++i) {
2497 ir_node *pred = get_Block_cfgpred(block, i);
2498 node_t *node = get_irn_node(pred);
2500 if (node->type.tv == tarval_reachable) {
2507 NEW_ARR_A(ir_node *, ins, n);
2508 for (phi = get_Block_phis(block); phi != NULL; phi = next) {
2509 node_t *node = get_irn_node(phi);
2511 next = get_Phi_next(phi);
2512 if (is_tarval(node->type.tv) && tarval_is_constant(node->type.tv)) {
2513 /* this Phi is replaced by a constant */
2514 tarval *tv = node->type.tv;
2515 ir_node *c = new_r_Const(current_ir_graph, block, get_tarval_mode(tv), tv);
2517 set_irn_node(c, node);
2519 DB((dbg, LEVEL_1, "%+F is replaced by %+F\n", phi, c));
2524 for (i = 0; i < n; ++i) {
2525 node_t *pred = get_irn_node(get_Block_cfgpred(block, i));
2527 if (pred->type.tv == tarval_reachable) {
2528 ins[j++] = get_Phi_pred(phi, i);
2532 /* this Phi is replaced by a single predecessor */
2533 ir_node *s = ins[0];
2536 DB((dbg, LEVEL_1, "%+F is replaced by %+F because of cf change\n", phi, s));
2540 set_irn_in(phi, j, ins);
2547 /* this Block has only one live predecessor */
2548 ir_node *pred = skip_Proj(in_X[0]);
2550 if (can_exchange(pred)) {
2551 exchange(block, get_nodes_block(pred));
2555 set_irn_in(block, k, in_X);
2561 * Post-Walker, apply the analysis results;
2563 static void apply_result(ir_node *irn, void *ctx) {
2564 environment_t *env = ctx;
2565 node_t *node = get_irn_node(irn);
2567 if (is_Block(irn) || is_End(irn) || is_Bad(irn)) {
2568 /* blocks already handled, do not touch the End node */
2570 node_t *block = get_irn_node(get_nodes_block(irn));
2572 if (block->type.tv == tarval_unreachable) {
2573 ir_node *bad = get_irg_bad(current_ir_graph);
2575 /* here, bad might already have a node, but this can be safely ignored
2576 as long as bad has at least ONE valid node */
2577 set_irn_node(bad, node);
2579 DB((dbg, LEVEL_1, "%+F is unreachable\n", irn));
2583 else if (node->type.tv == tarval_unreachable) {
2584 ir_node *bad = get_irg_bad(current_ir_graph);
2586 /* see comment above */
2587 set_irn_node(bad, node);
2589 DB((dbg, LEVEL_1, "%+F is unreachable\n", irn));
2593 else if (get_irn_mode(irn) == mode_X) {
2596 ir_node *cond = get_Proj_pred(irn);
2598 if (is_Cond(cond)) {
2599 node_t *sel = get_irn_node(get_Cond_selector(cond));
2601 if (is_tarval(sel->type.tv) && tarval_is_constant(sel->type.tv)) {
2602 /* Cond selector is a constant, make a Jmp */
2603 ir_node *jmp = new_r_Jmp(current_ir_graph, block->node);
2604 set_irn_node(jmp, node);
2606 DB((dbg, LEVEL_1, "%+F is replaced by %+F\n", irn, jmp));
2613 /* normal data node */
2614 if (is_tarval(node->type.tv) && tarval_is_constant(node->type.tv)) {
2615 tarval *tv = node->type.tv;
2618 * Beware: never replace mode_T nodes by constants. Currently we must mark
2619 * mode_T nodes with constants, but do NOT replace them.
2621 if (! is_Const(irn) && get_irn_mode(irn) != mode_T) {
2622 /* can be replaced by a constant */
2623 ir_node *c = new_r_Const(current_ir_graph, block->node, get_tarval_mode(tv), tv);
2624 set_irn_node(c, node);
2626 DB((dbg, LEVEL_1, "%+F is replaced by %+F\n", irn, c));
2630 } else if (is_entity(node->type.sym.entity_p)) {
2631 if (! is_SymConst(irn)) {
2632 /* can be replaced by a Symconst */
2633 ir_node *symc = new_r_SymConst(current_ir_graph, block->node, get_irn_mode(irn), node->type.sym, symconst_addr_ent);
2634 set_irn_node(symc, node);
2637 DB((dbg, LEVEL_1, "%+F is replaced by %+F\n", irn, symc));
2638 exchange(irn, symc);
2641 } else if (is_Confirm(irn)) {
2642 /* Confirms are always follower, but do not kill them here */
2644 ir_node *leader = get_leader(node);
2646 if (leader != irn) {
2647 DB((dbg, LEVEL_1, "%+F from part%d is replaced by %+F\n", irn, node->part->nr, leader));
2648 exchange(irn, leader);
2654 } /* apply_result */
2657 * Fix the keep-alives by deleting unreachable ones.
2659 static void apply_end(ir_node *end, environment_t *env) {
2660 int i, j, n = get_End_n_keepalives(end);
2664 NEW_ARR_A(ir_node *, in, n);
2666 /* fix the keep alive */
2667 for (i = j = 0; i < n; i++) {
2668 ir_node *ka = get_End_keepalive(end, i);
2669 node_t *node = get_irn_node(ka);
2671 /* Use the is_flagged bit to mark already visited nodes.
2672 * This should not be ready but better safe than sorry. */
2673 if (node->is_flagged == 0) {
2674 node->is_flagged = 1;
2677 node = get_irn_node(get_nodes_block(ka));
2679 if (node->type.tv != tarval_unreachable)
2684 set_End_keepalives(end, j, in);
2689 #define SET(code) op_##code->ops.generic = (op_func)compute_##code
2692 * sets the generic functions to compute.
2694 static void set_compute_functions(void) {
2697 /* set the default compute function */
2698 for (i = get_irp_n_opcodes() - 1; i >= 0; --i) {
2699 ir_op *op = get_irp_opcode(i);
2700 op->ops.generic = (op_func)default_compute;
2703 /* set specific functions */
2722 } /* set_compute_functions */
2724 static int dump_partition_hook(FILE *F, ir_node *n, ir_node *local) {
2725 ir_node *irn = local != NULL ? local : n;
2726 node_t *node = get_irn_node(irn);
2728 ir_fprintf(F, "info2 : \"partition %u type %+F\"\n", node->part->nr, node->type);
2732 void combo(ir_graph *irg) {
2734 ir_node *initial_bl;
2736 ir_graph *rem = current_ir_graph;
2738 current_ir_graph = irg;
2740 /* register a debug mask */
2741 FIRM_DBG_REGISTER(dbg, "firm.opt.combo");
2742 //firm_dbg_set_mask(dbg, SET_LEVEL_3);
2744 DB((dbg, LEVEL_1, "Doing COMBO for %+F\n", irg));
2746 obstack_init(&env.obst);
2747 env.worklist = NULL;
2751 #ifdef DEBUG_libfirm
2752 env.dbg_list = NULL;
2754 env.opcode2id_map = new_set(cmp_opcode, iro_Last * 4);
2755 env.type2id_map = pmap_create();
2756 env.end_idx = get_opt_global_cse() ? 0 : -1;
2757 env.lambda_input = 0;
2760 assure_irg_outs(irg);
2762 /* we have our own value_of function */
2763 set_value_of_func(get_node_tarval);
2765 set_compute_functions();
2766 DEBUG_ONLY(part_nr = 0);
2768 /* create the initial partition and place it on the work list */
2769 env.initial = new_partition(&env);
2770 add_to_worklist(env.initial, &env);
2771 irg_walk_graph(irg, init_block_phis, create_initial_partitions, &env);
2773 /* all nodes on the initial partition have type Top */
2774 env.initial->type_is_T_or_C = 1;
2776 /* Place the START Node's partition on cprop.
2777 Place the START Node on its local worklist. */
2778 initial_bl = get_irg_start_block(irg);
2779 start = get_irn_node(initial_bl);
2780 add_to_cprop(start, &env);
2784 if (env.worklist != NULL)
2786 } while (env.cprop != NULL || env.worklist != NULL);
2788 dump_all_partitions(&env);
2791 set_dump_node_vcgattr_hook(dump_partition_hook);
2792 dump_ir_block_graph(irg, "-partition");
2793 set_dump_node_vcgattr_hook(NULL);
2795 (void)dump_partition_hook;
2798 /* apply the result */
2799 irg_block_walk_graph(irg, NULL, apply_cf, &env);
2800 irg_walk_graph(irg, NULL, apply_result, &env);
2801 apply_end(get_irg_end(irg), &env);
2804 /* control flow might changed */
2805 set_irg_outs_inconsistent(irg);
2806 set_irg_extblk_inconsistent(irg);
2807 set_irg_doms_inconsistent(irg);
2808 set_irg_loopinfo_inconsistent(irg);
2811 pmap_destroy(env.type2id_map);
2812 del_set(env.opcode2id_map);
2813 obstack_free(&env.obst, NULL);
2815 /* restore value_of() default behavior */
2816 set_value_of_func(NULL);
2817 current_ir_graph = rem;