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 * This is a slightly enhanced version of Cliff Clicks combo algorithm
27 * - support for commutative nodes is added, Add(a,b) and Add(b,a) ARE congruent
28 * - supports all Firm direct (by a data edge) identities except Mux
29 * (Mux can be a 2-input or 1-input identity, only 2-input is implemented yet)
30 * - supports Confirm nodes (handle them like Copies but do NOT remove them)
31 * - let Cmp nodes calculate Top like all othe data nodes: this would let
32 * Mux nodes to calculate Unknown instead of taking the true result
33 * - let Cond(Top) always select FALSE/default: This is tricky. Nodes are only reavaluated
34 * IFF the predecessor changed its type. Because nodes are initialized with Top
35 * this never happens, let all Proj(Cond) be unreachable.
36 * We avoid this condition by the same way we work around Phi: whenever a Block
37 * node is placed on the list, place its Cond nodes (and because they are Tuple
38 * all its Proj-nodes either on the cprop list)
39 * Especially, this changes the meaning of Click's example:
54 * using Click's version while is silent with our.
55 * - support for global congruences is implemented but not tested yet
57 * Note further that we use the terminology from Click's work here, which is different
58 * in some cases from Firm terminology. Especially, Click's type is a
59 * Firm tarval/entity, nevertheless we call it type here for "maximum compatibility".
65 #include "iroptimize.h"
73 #include "irgraph_t.h"
80 #include "iropt_dbg.h"
84 #include "irnodeset.h"
91 /* define this to check that all type translations are monotone */
92 #define VERIFY_MONOTONE
94 /* define this to check the consistency of partitions */
95 #define CHECK_PARTITIONS
97 typedef struct node_t node_t;
98 typedef struct partition_t partition_t;
99 typedef struct opcode_key_t opcode_key_t;
100 typedef struct listmap_entry_t listmap_entry_t;
102 /** The type of the compute function. */
103 typedef void (*compute_func)(node_t *node);
108 struct opcode_key_t {
109 ir_opcode code; /**< The Firm opcode. */
110 ir_mode *mode; /**< The mode of all nodes in the partition. */
111 int arity; /**< The arity of this opcode (needed for Phi etc. */
113 long proj; /**< For Proj nodes, its proj number */
114 ir_entity *ent; /**< For Sel Nodes, its entity */
115 int intVal; /**< For Conv/Div Nodes: strict/remainderless */
120 * An entry in the list_map.
122 struct listmap_entry_t {
123 void *id; /**< The id. */
124 node_t *list; /**< The associated list for this id. */
125 listmap_entry_t *next; /**< Link to the next entry in the map. */
128 /** We must map id's to lists. */
129 typedef struct listmap_t {
130 set *map; /**< Map id's to listmap_entry_t's */
131 listmap_entry_t *values; /**< List of all values in the map. */
135 * A lattice element. Because we handle constants and symbolic constants different, we
136 * have to use this union.
147 ir_node *node; /**< The IR-node itself. */
148 list_head node_list; /**< Double-linked list of leader/follower entries. */
149 list_head cprop_list; /**< Double-linked partition.cprop list. */
150 partition_t *part; /**< points to the partition this node belongs to */
151 node_t *next; /**< Next node on local list (partition.touched, fallen). */
152 node_t *race_next; /**< Next node on race list. */
153 lattice_elem_t type; /**< The associated lattice element "type". */
154 int max_user_input; /**< Maximum input number of Def-Use edges. */
155 int next_edge; /**< Index of the next Def-Use edge to use. */
156 int n_followers; /**< Number of Follower in the outs set. */
157 unsigned on_touched:1; /**< Set, if this node is on the partition.touched set. */
158 unsigned on_cprop:1; /**< Set, if this node is on the partition.cprop list. */
159 unsigned on_fallen:1; /**< Set, if this node is on the fallen list. */
160 unsigned is_follower:1; /**< Set, if this node is a follower. */
161 unsigned flagged:2; /**< 2 Bits, set if this node was visited by race 1 or 2. */
165 * A partition containing congruent nodes.
168 list_head Leader; /**< The head of partition Leader node list. */
169 list_head Follower; /**< The head of partition Follower node list. */
170 list_head cprop; /**< The head of partition.cprop list. */
171 list_head cprop_X; /**< The head of partition.cprop (Cond nodes and its Projs) list. */
172 partition_t *wl_next; /**< Next entry in the work list if any. */
173 partition_t *touched_next; /**< Points to the next partition in the touched set. */
174 partition_t *cprop_next; /**< Points to the next partition in the cprop list. */
175 partition_t *split_next; /**< Points to the next partition in the list that must be split by split_by(). */
176 node_t *touched; /**< The partition.touched set of this partition. */
177 unsigned n_leader; /**< Number of entries in this partition.Leader. */
178 unsigned n_touched; /**< Number of entries in the partition.touched. */
179 int max_user_inputs; /**< Maximum number of user inputs of all entries. */
180 unsigned on_worklist:1; /**< Set, if this partition is in the work list. */
181 unsigned on_touched:1; /**< Set, if this partition is on the touched set. */
182 unsigned on_cprop:1; /**< Set, if this partition is on the cprop list. */
183 unsigned type_is_T_or_C:1;/**< Set, if all nodes in this partition have type Top or Constant. */
185 partition_t *dbg_next; /**< Link all partitions for debugging */
186 unsigned nr; /**< A unique number for (what-)mapping, >0. */
190 typedef struct environment_t {
191 struct obstack obst; /**< obstack to allocate data structures. */
192 partition_t *worklist; /**< The work list. */
193 partition_t *cprop; /**< The constant propagation list. */
194 partition_t *touched; /**< the touched set. */
195 partition_t *initial; /**< The initial partition. */
196 set *opcode2id_map; /**< The opcodeMode->id map. */
197 pmap *type2id_map; /**< The type->id map. */
198 ir_node **kept_memory; /**< Array of memory nodes that must be kept. */
199 int end_idx; /**< -1 for local and 0 for global congruences. */
200 int lambda_input; /**< Captured argument for lambda_partition(). */
201 unsigned modified:1; /**< Set, if the graph was modified. */
202 unsigned unopt_cf:1; /**< If set, control flow is not optimized due to Unknown. */
203 /* options driving the optimization */
204 unsigned commutative:1; /**< Set, if commutation nodes should be handled specially. */
205 unsigned opt_unknown:1; /**< Set, if non-strict programs should be optimized. */
207 partition_t *dbg_list; /**< List of all partitions. */
211 /** Type of the what function. */
212 typedef void *(*what_func)(const node_t *node, environment_t *env);
214 #define get_irn_node(irn) ((node_t *)get_irn_link(irn))
215 #define set_irn_node(irn, node) set_irn_link(irn, node)
217 /* we do NOT use tarval_unreachable here, instead we use Top for this purpose */
218 #undef tarval_unreachable
219 #define tarval_unreachable tarval_top
222 /** The debug module handle. */
223 DEBUG_ONLY(static firm_dbg_module_t *dbg;)
225 /** The what reason. */
226 DEBUG_ONLY(static const char *what_reason;)
228 /** Next partition number. */
229 DEBUG_ONLY(static unsigned part_nr = 0);
231 /** The tarval returned by Unknown nodes: set to either tarval_bad OR tarval_top. */
232 static tarval *tarval_UNKNOWN;
235 static node_t *identity(node_t *node);
237 #ifdef CHECK_PARTITIONS
241 static void check_partition(const partition_t *T) {
245 list_for_each_entry(node_t, node, &T->Leader, node_list) {
246 assert(node->is_follower == 0);
247 assert(node->flagged == 0);
248 assert(node->part == T);
251 assert(n == T->n_leader);
253 list_for_each_entry(node_t, node, &T->Follower, node_list) {
254 assert(node->is_follower == 1);
255 assert(node->flagged == 0);
256 assert(node->part == T);
258 } /* check_partition */
261 * check that all leader nodes in the partition have the same opcode.
263 static void check_opcode(const partition_t *Z) {
268 list_for_each_entry(node_t, node, &Z->Leader, node_list) {
269 ir_node *irn = node->node;
272 key.code = get_irn_opcode(irn);
273 key.mode = get_irn_mode(irn);
274 key.arity = get_irn_arity(irn);
278 switch (get_irn_opcode(irn)) {
280 key.u.proj = get_Proj_proj(irn);
283 key.u.ent = get_Sel_entity(irn);
286 key.u.intVal = get_Conv_strict(irn);
289 key.u.intVal = is_Div_remainderless(irn);
296 assert(key.code == get_irn_opcode(irn));
297 assert(key.mode == get_irn_mode(irn));
298 assert(key.arity == get_irn_arity(irn));
300 switch (get_irn_opcode(irn)) {
302 assert(key.u.proj == get_Proj_proj(irn));
305 assert(key.u.ent == get_Sel_entity(irn));
308 assert(key.u.intVal == get_Conv_strict(irn));
311 assert(key.u.intVal == is_Div_remainderless(irn));
320 static void check_all_partitions(environment_t *env) {
325 for (P = env->dbg_list; P != NULL; P = P->dbg_next) {
327 if (! P->type_is_T_or_C)
329 list_for_each_entry(node_t, node, &P->Follower, node_list) {
330 node_t *leader = identity(node);
332 assert(leader != node && leader->part == node->part);
341 static void do_check_list(const node_t *list, int ofs, const partition_t *Z) {
344 #define NEXT(e) *((const node_t **)((char *)(e) + (ofs)))
345 for (e = list; e != NULL; e = NEXT(e)) {
346 assert(e->part == Z);
349 } /* ido_check_list */
352 * Check a local list.
354 static void check_list(const node_t *list, const partition_t *Z) {
355 do_check_list(list, offsetof(node_t, next), Z);
359 #define check_partition(T)
360 #define check_list(list, Z)
361 #define check_all_partitions(env)
362 #endif /* CHECK_PARTITIONS */
365 static inline lattice_elem_t get_partition_type(const partition_t *X);
368 * Dump partition to output.
370 static void dump_partition(const char *msg, const partition_t *part) {
373 lattice_elem_t type = get_partition_type(part);
375 DB((dbg, LEVEL_2, "%s part%u%s (%u, %+F) {\n ",
376 msg, part->nr, part->type_is_T_or_C ? "*" : "",
377 part->n_leader, type));
378 list_for_each_entry(node_t, node, &part->Leader, node_list) {
379 DB((dbg, LEVEL_2, "%s%+F", first ? "" : ", ", node->node));
382 if (! list_empty(&part->Follower)) {
383 DB((dbg, LEVEL_2, "\n---\n "));
385 list_for_each_entry(node_t, node, &part->Follower, node_list) {
386 DB((dbg, LEVEL_2, "%s%+F", first ? "" : ", ", node->node));
390 DB((dbg, LEVEL_2, "\n}\n"));
391 } /* dump_partition */
396 static void do_dump_list(const char *msg, const node_t *node, int ofs) {
400 #define GET_LINK(p, ofs) *((const node_t **)((char *)(p) + (ofs)))
402 DB((dbg, LEVEL_3, "%s = {\n ", msg));
403 for (p = node; p != NULL; p = GET_LINK(p, ofs)) {
404 DB((dbg, LEVEL_3, "%s%+F", first ? "" : ", ", p->node));
407 DB((dbg, LEVEL_3, "\n}\n"));
415 static void dump_race_list(const char *msg, const node_t *list) {
416 do_dump_list(msg, list, offsetof(node_t, race_next));
417 } /* dump_race_list */
420 * Dumps a local list.
422 static void dump_list(const char *msg, const node_t *list) {
423 do_dump_list(msg, list, offsetof(node_t, next));
427 * Dump all partitions.
429 static void dump_all_partitions(const environment_t *env) {
430 const partition_t *P;
432 DB((dbg, LEVEL_2, "All partitions\n===============\n"));
433 for (P = env->dbg_list; P != NULL; P = P->dbg_next)
434 dump_partition("", P);
435 } /* dump_all_partitions */
440 static void dump_split_list(const partition_t *list) {
441 const partition_t *p;
443 DB((dbg, LEVEL_2, "Split by %s produced = {\n", what_reason));
444 for (p = list; p != NULL; p = p->split_next)
445 DB((dbg, LEVEL_2, "part%u, ", p->nr));
446 DB((dbg, LEVEL_2, "\n}\n"));
447 } /* dump_split_list */
450 * Dump partition and type for a node.
452 static int dump_partition_hook(FILE *F, ir_node *n, ir_node *local) {
453 ir_node *irn = local != NULL ? local : n;
454 node_t *node = get_irn_node(irn);
456 ir_fprintf(F, "info2 : \"partition %u type %+F\"\n", node->part->nr, node->type);
458 } /* dump_partition_hook */
461 #define dump_partition(msg, part)
462 #define dump_race_list(msg, list)
463 #define dump_list(msg, list)
464 #define dump_all_partitions(env)
465 #define dump_split_list(list)
468 #if defined(VERIFY_MONOTONE) && defined (DEBUG_libfirm)
470 * Verify that a type transition is monotone
472 static void verify_type(const lattice_elem_t old_type, node_t *node) {
473 if (old_type.tv == node->type.tv) {
477 if (old_type.tv == tarval_top) {
478 /* from Top down-to is always allowed */
481 if (node->type.tv == tarval_bottom || node->type.tv == tarval_reachable) {
485 panic("combo: wrong translation from %+F to %+F on node %+F", old_type, node->type, node->node);
489 #define verify_type(old_type, node)
493 * Compare two pointer values of a listmap.
495 static int listmap_cmp_ptr(const void *elt, const void *key, size_t size) {
496 const listmap_entry_t *e1 = elt;
497 const listmap_entry_t *e2 = key;
500 return e1->id != e2->id;
501 } /* listmap_cmp_ptr */
504 * Initializes a listmap.
506 * @param map the listmap
508 static void listmap_init(listmap_t *map) {
509 map->map = new_set(listmap_cmp_ptr, 16);
514 * Terminates a listmap.
516 * @param map the listmap
518 static void listmap_term(listmap_t *map) {
523 * Return the associated listmap entry for a given id.
525 * @param map the listmap
526 * @param id the id to search for
528 * @return the associated listmap entry for the given id
530 static listmap_entry_t *listmap_find(listmap_t *map, void *id) {
531 listmap_entry_t key, *entry;
536 entry = set_insert(map->map, &key, sizeof(key), HASH_PTR(id));
538 if (entry->list == NULL) {
539 /* a new entry, put into the list */
540 entry->next = map->values;
547 * Calculate the hash value for an opcode map entry.
549 * @param entry an opcode map entry
551 * @return a hash value for the given opcode map entry
553 static unsigned opcode_hash(const opcode_key_t *entry) {
554 return (entry->mode - (ir_mode *)0) * 9 + entry->code + entry->u.proj * 3 + HASH_PTR(entry->u.ent) + entry->arity;
558 * Compare two entries in the opcode map.
560 static int cmp_opcode(const void *elt, const void *key, size_t size) {
561 const opcode_key_t *o1 = elt;
562 const opcode_key_t *o2 = key;
565 return o1->code != o2->code || o1->mode != o2->mode ||
566 o1->arity != o2->arity ||
567 o1->u.proj != o2->u.proj || o1->u.ent != o2->u.ent ||
568 o1->u.intVal != o2->u.intVal;
572 * Compare two Def-Use edges for input position.
574 static int cmp_def_use_edge(const void *a, const void *b) {
575 const ir_def_use_edge *ea = a;
576 const ir_def_use_edge *eb = b;
578 /* no overrun, because range is [-1, MAXINT] */
579 return ea->pos - eb->pos;
580 } /* cmp_def_use_edge */
583 * We need the Def-Use edges sorted.
585 static void sort_irn_outs(node_t *node) {
586 ir_node *irn = node->node;
587 int n_outs = get_irn_n_outs(irn);
590 qsort(&irn->out[1], n_outs, sizeof(irn->out[0]), cmp_def_use_edge);
592 node->max_user_input = irn->out[n_outs].pos;
593 } /* sort_irn_outs */
596 * Return the type of a node.
598 * @param irn an IR-node
600 * @return the associated type of this node
602 static inline lattice_elem_t get_node_type(const ir_node *irn) {
603 return get_irn_node(irn)->type;
604 } /* get_node_type */
607 * Return the tarval of a node.
609 * @param irn an IR-node
611 * @return the associated type of this node
613 static inline tarval *get_node_tarval(const ir_node *irn) {
614 lattice_elem_t type = get_node_type(irn);
616 if (is_tarval(type.tv))
618 return tarval_bottom;
619 } /* get_node_type */
622 * Add a partition to the worklist.
624 static inline void add_to_worklist(partition_t *X, environment_t *env) {
625 assert(X->on_worklist == 0);
626 DB((dbg, LEVEL_2, "Adding part%d to worklist\n", X->nr));
627 X->wl_next = env->worklist;
630 } /* add_to_worklist */
633 * Create a new empty partition.
635 * @param env the environment
637 * @return a newly allocated partition
639 static inline partition_t *new_partition(environment_t *env) {
640 partition_t *part = obstack_alloc(&env->obst, sizeof(*part));
642 INIT_LIST_HEAD(&part->Leader);
643 INIT_LIST_HEAD(&part->Follower);
644 INIT_LIST_HEAD(&part->cprop);
645 INIT_LIST_HEAD(&part->cprop_X);
646 part->wl_next = NULL;
647 part->touched_next = NULL;
648 part->cprop_next = NULL;
649 part->split_next = NULL;
650 part->touched = NULL;
653 part->max_user_inputs = 0;
654 part->on_worklist = 0;
655 part->on_touched = 0;
657 part->type_is_T_or_C = 0;
659 part->dbg_next = env->dbg_list;
660 env->dbg_list = part;
661 part->nr = part_nr++;
665 } /* new_partition */
668 * Get the first node from a partition.
670 static inline node_t *get_first_node(const partition_t *X) {
671 return list_entry(X->Leader.next, node_t, node_list);
672 } /* get_first_node */
675 * Return the type of a partition (assuming partition is non-empty and
676 * all elements have the same type).
678 * @param X a partition
680 * @return the type of the first element of the partition
682 static inline lattice_elem_t get_partition_type(const partition_t *X) {
683 const node_t *first = get_first_node(X);
685 } /* get_partition_type */
688 * Creates a partition node for the given IR-node and place it
689 * into the given partition.
691 * @param irn an IR-node
692 * @param part a partition to place the node in
693 * @param env the environment
695 * @return the created node
697 static node_t *create_partition_node(ir_node *irn, partition_t *part, environment_t *env) {
698 /* create a partition node and place it in the partition */
699 node_t *node = obstack_alloc(&env->obst, sizeof(*node));
701 INIT_LIST_HEAD(&node->node_list);
702 INIT_LIST_HEAD(&node->cprop_list);
706 node->race_next = NULL;
707 node->type.tv = tarval_top;
708 node->max_user_input = 0;
710 node->n_followers = 0;
711 node->on_touched = 0;
714 node->is_follower = 0;
716 set_irn_node(irn, node);
718 list_add_tail(&node->node_list, &part->Leader);
722 } /* create_partition_node */
725 * Pre-Walker, initialize all Nodes' type to U or top and place
726 * all nodes into the TOP partition.
728 static void create_initial_partitions(ir_node *irn, void *ctx) {
729 environment_t *env = ctx;
730 partition_t *part = env->initial;
733 node = create_partition_node(irn, part, env);
735 if (node->max_user_input > part->max_user_inputs)
736 part->max_user_inputs = node->max_user_input;
739 set_Block_phis(irn, NULL);
741 } /* create_initial_partitions */
744 * Post-Walker, collect all Block-Phi lists, set Cond.
746 static void init_block_phis(ir_node *irn, void *ctx) {
750 add_Block_phi(get_nodes_block(irn), irn);
752 } /* init_block_phis */
755 * Add a node to the entry.partition.touched set and
756 * node->partition to the touched set if not already there.
759 * @param env the environment
761 static inline void add_to_touched(node_t *y, environment_t *env) {
762 if (y->on_touched == 0) {
763 partition_t *part = y->part;
765 y->next = part->touched;
770 if (part->on_touched == 0) {
771 part->touched_next = env->touched;
773 part->on_touched = 1;
776 check_list(part->touched, part);
778 } /* add_to_touched */
781 * Place a node on the cprop list.
784 * @param env the environment
786 static void add_to_cprop(node_t *y, environment_t *env) {
789 /* Add y to y.partition.cprop. */
790 if (y->on_cprop == 0) {
791 partition_t *Y = y->part;
792 ir_node *irn = y->node;
794 /* place Conds and all its Projs on the cprop_X list */
795 if (is_Cond(skip_Proj(irn)))
796 list_add_tail(&y->cprop_list, &Y->cprop_X);
798 list_add_tail(&y->cprop_list, &Y->cprop);
801 DB((dbg, LEVEL_3, "Add %+F to part%u.cprop\n", y->node, Y->nr));
803 /* place its partition on the cprop list */
804 if (Y->on_cprop == 0) {
805 Y->cprop_next = env->cprop;
811 if (get_irn_mode(irn) == mode_T) {
812 /* mode_T nodes always produce tarval_bottom, so we must explicitly
813 add it's Proj's to get constant evaluation to work */
816 for (i = get_irn_n_outs(irn) - 1; i >= 0; --i) {
817 node_t *proj = get_irn_node(get_irn_out(irn, i));
819 add_to_cprop(proj, env);
821 } else if (is_Block(irn)) {
822 /* Due to the way we handle Phi's, we must place all Phis of a block on the list
823 * if someone placed the block. The Block is only placed if the reachability
824 * changes, and this must be re-evaluated in compute_Phi(). */
826 for (phi = get_Block_phis(irn); phi != NULL; phi = get_Phi_next(phi)) {
827 node_t *p = get_irn_node(phi);
828 add_to_cprop(p, env);
834 * Update the worklist: If Z is on worklist then add Z' to worklist.
835 * Else add the smaller of Z and Z' to worklist.
837 * @param Z the Z partition
838 * @param Z_prime the Z' partition, a previous part of Z
839 * @param env the environment
841 static void update_worklist(partition_t *Z, partition_t *Z_prime, environment_t *env) {
842 if (Z->on_worklist || Z_prime->n_leader < Z->n_leader) {
843 add_to_worklist(Z_prime, env);
845 add_to_worklist(Z, env);
847 } /* update_worklist */
850 * Make all inputs to x no longer be F.def_use edges.
854 static void move_edges_to_leader(node_t *x) {
855 ir_node *irn = x->node;
858 for (i = get_irn_arity(irn) - 1; i >= 0; --i) {
859 node_t *pred = get_irn_node(get_irn_n(irn, i));
864 n = get_irn_n_outs(p);
865 for (j = 1; j <= pred->n_followers; ++j) {
866 if (p->out[j].pos == i && p->out[j].use == irn) {
867 /* found a follower edge to x, move it to the Leader */
868 ir_def_use_edge edge = p->out[j];
870 /* remove this edge from the Follower set */
871 p->out[j] = p->out[pred->n_followers];
874 /* sort it into the leader set */
875 for (k = pred->n_followers + 2; k <= n; ++k) {
876 if (p->out[k].pos >= edge.pos)
878 p->out[k - 1] = p->out[k];
880 /* place the new edge here */
881 p->out[k - 1] = edge;
883 /* edge found and moved */
888 } /* move_edges_to_leader */
891 * Split a partition that has NO followers by a local list.
893 * @param Z partition to split
894 * @param g a (non-empty) node list
895 * @param env the environment
897 * @return a new partition containing the nodes of g
899 static partition_t *split_no_followers(partition_t *Z, node_t *g, environment_t *env) {
900 partition_t *Z_prime;
905 dump_partition("Splitting ", Z);
906 dump_list("by list ", g);
910 /* Remove g from Z. */
911 for (node = g; node != NULL; node = node->next) {
912 assert(node->part == Z);
913 list_del(&node->node_list);
916 assert(n < Z->n_leader);
919 /* Move g to a new partition, Z'. */
920 Z_prime = new_partition(env);
922 for (node = g; node != NULL; node = node->next) {
923 list_add_tail(&node->node_list, &Z_prime->Leader);
924 node->part = Z_prime;
925 if (node->max_user_input > max_input)
926 max_input = node->max_user_input;
928 Z_prime->max_user_inputs = max_input;
929 Z_prime->n_leader = n;
932 check_partition(Z_prime);
934 /* for now, copy the type info tag, it will be adjusted in split_by(). */
935 Z_prime->type_is_T_or_C = Z->type_is_T_or_C;
937 update_worklist(Z, Z_prime, env);
939 dump_partition("Now ", Z);
940 dump_partition("Created new ", Z_prime);
942 } /* split_no_followers */
945 * Make the Follower -> Leader transition for a node.
949 static void follower_to_leader(node_t *n) {
950 assert(n->is_follower == 1);
952 DB((dbg, LEVEL_2, "%+F make the follower -> leader transition\n", n->node));
954 move_edges_to_leader(n);
955 list_del(&n->node_list);
956 list_add_tail(&n->node_list, &n->part->Leader);
958 } /* follower_to_leader */
961 * The environment for one race step.
963 typedef struct step_env {
964 node_t *initial; /**< The initial node list. */
965 node_t *unwalked; /**< The unwalked node list. */
966 node_t *walked; /**< The walked node list. */
967 int index; /**< Next index of Follower use_def edge. */
968 unsigned side; /**< side number. */
972 * Return non-zero, if a input is a real follower
974 * @param irn the node to check
975 * @param input number of the input
977 static int is_real_follower(const ir_node *irn, int input) {
980 switch (get_irn_opcode(irn)) {
983 /* ignore the Confirm bound input */
989 /* ignore the Mux sel input */
994 /* dead inputs are not follower edges */
995 ir_node *block = get_nodes_block(irn);
996 node_t *pred = get_irn_node(get_Block_cfgpred(block, input));
998 if (pred->type.tv == tarval_unreachable)
1008 /* only a Sub x,0 / Shift x,0 might be a follower */
1015 pred = get_irn_node(get_irn_n(irn, input));
1016 if (is_tarval(pred->type.tv) && tarval_is_null(pred->type.tv))
1020 pred = get_irn_node(get_irn_n(irn, input));
1021 if (is_tarval(pred->type.tv) && tarval_is_one(pred->type.tv))
1025 pred = get_irn_node(get_irn_n(irn, input));
1026 if (is_tarval(pred->type.tv) && tarval_is_all_one(pred->type.tv))
1031 /* all inputs are followers */
1034 assert(!"opcode not implemented yet");
1038 } /* is_real_follower */
1041 * Do one step in the race.
1043 static int step(step_env *env) {
1046 if (env->initial != NULL) {
1047 /* Move node from initial to unwalked */
1049 env->initial = n->race_next;
1051 n->race_next = env->unwalked;
1057 while (env->unwalked != NULL) {
1058 /* let n be the first node in unwalked */
1060 while (env->index < n->n_followers) {
1061 const ir_def_use_edge *edge = &n->node->out[1 + env->index];
1063 /* let m be n.F.def_use[index] */
1064 node_t *m = get_irn_node(edge->use);
1066 assert(m->is_follower);
1068 * Some inputs, like the get_Confirm_bound are NOT
1069 * real followers, sort them out.
1071 if (! is_real_follower(m->node, edge->pos)) {
1077 /* only followers from our partition */
1078 if (m->part != n->part)
1081 if ((m->flagged & env->side) == 0) {
1082 m->flagged |= env->side;
1084 if (m->flagged != 3) {
1085 /* visited the first time */
1086 /* add m to unwalked not as first node (we might still need to
1087 check for more follower node */
1088 m->race_next = n->race_next;
1092 /* else already visited by the other side and on the other list */
1095 /* move n to walked */
1096 env->unwalked = n->race_next;
1097 n->race_next = env->walked;
1105 * Clear the flags from a list and check for
1106 * nodes that where touched from both sides.
1108 * @param list the list
1110 static int clear_flags(node_t *list) {
1114 for (n = list; n != NULL; n = n->race_next) {
1115 if (n->flagged == 3) {
1116 /* we reach a follower from both sides, this will split congruent
1117 * inputs and make it a leader. */
1118 follower_to_leader(n);
1127 * Split a partition by a local list using the race.
1129 * @param pX pointer to the partition to split, might be changed!
1130 * @param gg a (non-empty) node list
1131 * @param env the environment
1133 * @return a new partition containing the nodes of gg
1135 static partition_t *split(partition_t **pX, node_t *gg, environment_t *env) {
1136 partition_t *X = *pX;
1137 partition_t *X_prime;
1140 node_t *g, *h, *node, *t;
1141 int max_input, transitions, winner, shf;
1143 DEBUG_ONLY(static int run = 0;)
1145 DB((dbg, LEVEL_2, "Run %d ", run++));
1146 if (list_empty(&X->Follower)) {
1147 /* if the partition has NO follower, we can use the fast
1148 splitting algorithm. */
1149 return split_no_followers(X, gg, env);
1151 /* else do the race */
1153 dump_partition("Splitting ", X);
1154 dump_list("by list ", gg);
1156 INIT_LIST_HEAD(&tmp);
1158 /* Remove gg from X.Leader and put into g */
1160 for (node = gg; node != NULL; node = node->next) {
1161 assert(node->part == X);
1162 assert(node->is_follower == 0);
1164 list_del(&node->node_list);
1165 list_add_tail(&node->node_list, &tmp);
1166 node->race_next = g;
1171 list_for_each_entry(node_t, node, &X->Leader, node_list) {
1172 node->race_next = h;
1175 /* restore X.Leader */
1176 list_splice(&tmp, &X->Leader);
1178 senv[0].initial = g;
1179 senv[0].unwalked = NULL;
1180 senv[0].walked = NULL;
1184 senv[1].initial = h;
1185 senv[1].unwalked = NULL;
1186 senv[1].walked = NULL;
1191 * Some informations on the race that are not stated clearly in Click's
1193 * 1) A follower stays on the side that reach him first.
1194 * 2) If the other side reches a follower, if will be converted to
1195 * a leader. /This must be done after the race is over, else the
1196 * edges we are iterating on are renumbered./
1197 * 3) /New leader might end up on both sides./
1198 * 4) /If one side ends up with new Leaders, we must ensure that
1199 * they can split out by opcode, hence we have to put _every_
1200 * partition with new Leader nodes on the cprop list, as
1201 * opcode splitting is done by split_by() at the end of
1202 * constant propagation./
1205 if (step(&senv[0])) {
1209 if (step(&senv[1])) {
1214 assert(senv[winner].initial == NULL);
1215 assert(senv[winner].unwalked == NULL);
1217 /* clear flags from walked/unwalked */
1219 transitions = clear_flags(senv[0].unwalked) << shf;
1220 transitions |= clear_flags(senv[0].walked) << shf;
1222 transitions |= clear_flags(senv[1].unwalked) << shf;
1223 transitions |= clear_flags(senv[1].walked) << shf;
1225 dump_race_list("winner ", senv[winner].walked);
1227 /* Move walked_{winner} to a new partition, X'. */
1228 X_prime = new_partition(env);
1231 for (node = senv[winner].walked; node != NULL; node = node->race_next) {
1232 list_del(&node->node_list);
1233 node->part = X_prime;
1234 if (node->is_follower) {
1235 list_add_tail(&node->node_list, &X_prime->Follower);
1237 list_add_tail(&node->node_list, &X_prime->Leader);
1240 if (node->max_user_input > max_input)
1241 max_input = node->max_user_input;
1243 X_prime->n_leader = n;
1244 X_prime->max_user_inputs = max_input;
1245 X->n_leader -= X_prime->n_leader;
1247 /* for now, copy the type info tag, it will be adjusted in split_by(). */
1248 X_prime->type_is_T_or_C = X->type_is_T_or_C;
1251 * Even if a follower was not checked by both sides, it might have
1252 * loose its congruence, so we need to check this case for all follower.
1254 list_for_each_entry_safe(node_t, node, t, &X_prime->Follower, node_list) {
1255 if (identity(node) == node) {
1256 follower_to_leader(node);
1262 check_partition(X_prime);
1264 /* X' is the smaller part */
1265 add_to_worklist(X_prime, env);
1268 * If there where follower to leader transitions, ensure that the nodes
1269 * can be split out if necessary.
1271 if (transitions & 1) {
1272 /* place winner partition on the cprop list */
1273 if (X_prime->on_cprop == 0) {
1274 X_prime->cprop_next = env->cprop;
1275 env->cprop = X_prime;
1276 X_prime->on_cprop = 1;
1279 if (transitions & 2) {
1280 /* place other partition on the cprop list */
1281 if (X->on_cprop == 0) {
1282 X->cprop_next = env->cprop;
1288 dump_partition("Now ", X);
1289 dump_partition("Created new ", X_prime);
1291 /* we have to ensure that the partition containing g is returned */
1301 * Returns non-zero if the i'th input of a Phi node is live.
1303 * @param phi a Phi-node
1304 * @param i an input number
1306 * @return non-zero if the i'th input of the given Phi node is live
1308 static int is_live_input(ir_node *phi, int i) {
1310 ir_node *block = get_nodes_block(phi);
1311 ir_node *pred = get_Block_cfgpred(block, i);
1312 lattice_elem_t type = get_node_type(pred);
1314 return type.tv != tarval_unreachable;
1316 /* else it's the control input, always live */
1318 } /* is_live_input */
1321 * Return non-zero if a type is a constant.
1323 static int is_constant_type(lattice_elem_t type) {
1324 if (type.tv != tarval_bottom && type.tv != tarval_top)
1327 } /* is_constant_type */
1330 * Check whether a type is neither Top or a constant.
1331 * Note: U is handled like Top here, R is a constant.
1333 * @param type the type to check
1335 static int type_is_neither_top_nor_const(const lattice_elem_t type) {
1336 if (is_tarval(type.tv)) {
1337 if (type.tv == tarval_top)
1339 if (tarval_is_constant(type.tv))
1346 } /* type_is_neither_top_nor_const */
1349 * Collect nodes to the touched list.
1351 * @param list the list which contains the nodes that must be evaluated
1352 * @param idx the index of the def_use edge to evaluate
1353 * @param env the environment
1355 static void collect_touched(list_head *list, int idx, environment_t *env) {
1357 int end_idx = env->end_idx;
1359 list_for_each_entry(node_t, x, list, node_list) {
1363 /* leader edges start AFTER follower edges */
1364 x->next_edge = x->n_followers + 1;
1366 num_edges = get_irn_n_outs(x->node);
1368 /* for all edges in x.L.def_use_{idx} */
1369 while (x->next_edge <= num_edges) {
1370 const ir_def_use_edge *edge = &x->node->out[x->next_edge];
1373 /* check if we have necessary edges */
1374 if (edge->pos > idx)
1381 /* only non-commutative nodes */
1382 if (env->commutative &&
1383 (idx == 0 || idx == 1) && is_op_commutative(get_irn_op(succ)))
1386 /* ignore the "control input" for non-pinned nodes
1387 if we are running in GCSE mode */
1388 if (idx < end_idx && get_irn_pinned(succ) != op_pin_state_pinned)
1391 y = get_irn_node(succ);
1392 assert(get_irn_n(succ, idx) == x->node);
1394 /* ignore block edges touching followers */
1395 if (idx == -1 && y->is_follower)
1398 if (is_constant_type(y->type)) {
1399 ir_opcode code = get_irn_opcode(succ);
1400 if (code == iro_Sub || code == iro_Cmp)
1401 add_to_cprop(y, env);
1404 /* Partitions of constants should not be split simply because their Nodes have unequal
1405 functions or incongruent inputs. */
1406 if (type_is_neither_top_nor_const(y->type) &&
1407 (! is_Phi(y->node) || is_live_input(y->node, idx))) {
1408 add_to_touched(y, env);
1412 } /* collect_touched */
1415 * Collect commutative nodes to the touched list.
1417 * @param X the partition of the list
1418 * @param list the list which contains the nodes that must be evaluated
1419 * @param env the environment
1421 static void collect_commutative_touched(partition_t *X, list_head *list, environment_t *env) {
1426 list_for_each_entry(node_t, x, list, node_list) {
1429 num_edges = get_irn_n_outs(x->node);
1431 x->next_edge = x->n_followers + 1;
1433 /* for all edges in x.L.def_use_{idx} */
1434 while (x->next_edge <= num_edges) {
1435 const ir_def_use_edge *edge = &x->node->out[x->next_edge];
1438 /* check if we have necessary edges */
1448 /* only commutative nodes */
1449 if (!is_op_commutative(get_irn_op(succ)))
1452 y = get_irn_node(succ);
1453 if (is_constant_type(y->type)) {
1454 ir_opcode code = get_irn_opcode(succ);
1455 if (code == iro_Eor)
1456 add_to_cprop(y, env);
1459 /* Partitions of constants should not be split simply because their Nodes have unequal
1460 functions or incongruent inputs. */
1461 if (type_is_neither_top_nor_const(y->type)) {
1462 int other_idx = edge->pos ^ 1;
1463 node_t *other = get_irn_node(get_irn_n(succ, other_idx));
1464 int equal = X == other->part;
1467 * Note: op(a, a) is NOT congruent to op(a, b).
1468 * So, either all touch nodes must have both inputs congruent,
1469 * or not. We decide this by the first occurred node.
1475 if (both_input == equal)
1476 add_to_touched(y, env);
1480 } /* collect_commutative_touched */
1483 * Split the partitions if caused by the first entry on the worklist.
1485 * @param env the environment
1487 static void cause_splits(environment_t *env) {
1488 partition_t *X, *Z, *N;
1491 /* remove the first partition from the worklist */
1493 env->worklist = X->wl_next;
1496 dump_partition("Cause_split: ", X);
1498 if (env->commutative) {
1499 /* handle commutative nodes first */
1501 /* empty the touched set: already done, just clear the list */
1502 env->touched = NULL;
1504 collect_commutative_touched(X, &X->Leader, env);
1505 collect_commutative_touched(X, &X->Follower, env);
1507 for (Z = env->touched; Z != NULL; Z = N) {
1509 node_t *touched = Z->touched;
1510 unsigned n_touched = Z->n_touched;
1512 assert(Z->touched != NULL);
1514 /* beware, split might change Z */
1515 N = Z->touched_next;
1517 /* remove it from the touched set */
1520 /* Empty local Z.touched. */
1521 for (e = touched; e != NULL; e = e->next) {
1522 assert(e->is_follower == 0);
1528 if (0 < n_touched && n_touched < Z->n_leader) {
1529 DB((dbg, LEVEL_2, "Split part%d by touched\n", Z->nr));
1530 split(&Z, touched, env);
1532 assert(n_touched <= Z->n_leader);
1536 /* combine temporary leader and follower list */
1537 for (idx = -1; idx <= X->max_user_inputs; ++idx) {
1538 /* empty the touched set: already done, just clear the list */
1539 env->touched = NULL;
1541 collect_touched(&X->Leader, idx, env);
1542 collect_touched(&X->Follower, idx, env);
1544 for (Z = env->touched; Z != NULL; Z = N) {
1546 node_t *touched = Z->touched;
1547 unsigned n_touched = Z->n_touched;
1549 assert(Z->touched != NULL);
1551 /* beware, split might change Z */
1552 N = Z->touched_next;
1554 /* remove it from the touched set */
1557 /* Empty local Z.touched. */
1558 for (e = touched; e != NULL; e = e->next) {
1559 assert(e->is_follower == 0);
1565 if (0 < n_touched && n_touched < Z->n_leader) {
1566 DB((dbg, LEVEL_2, "Split part%d by touched\n", Z->nr));
1567 split(&Z, touched, env);
1569 assert(n_touched <= Z->n_leader);
1572 } /* cause_splits */
1575 * Implements split_by_what(): Split a partition by characteristics given
1576 * by the what function.
1578 * @param X the partition to split
1579 * @param What a function returning an Id for every node of the partition X
1580 * @param P a list to store the result partitions
1581 * @param env the environment
1585 static partition_t *split_by_what(partition_t *X, what_func What,
1586 partition_t **P, environment_t *env) {
1589 listmap_entry_t *iter;
1592 /* Let map be an empty mapping from the range of What to (local) list of Nodes. */
1594 list_for_each_entry(node_t, x, &X->Leader, node_list) {
1595 void *id = What(x, env);
1596 listmap_entry_t *entry;
1599 /* input not allowed, ignore */
1602 /* Add x to map[What(x)]. */
1603 entry = listmap_find(&map, id);
1604 x->next = entry->list;
1607 /* Let P be a set of Partitions. */
1609 /* for all sets S except one in the range of map do */
1610 for (iter = map.values; iter != NULL; iter = iter->next) {
1611 if (iter->next == NULL) {
1612 /* this is the last entry, ignore */
1617 /* Add SPLIT( X, S ) to P. */
1618 DB((dbg, LEVEL_2, "Split part%d by WHAT = %s\n", X->nr, what_reason));
1619 R = split(&X, S, env);
1629 } /* split_by_what */
1631 /** lambda n.(n.type) */
1632 static void *lambda_type(const node_t *node, environment_t *env) {
1634 return node->type.tv;
1637 /** lambda n.(n.opcode) */
1638 static void *lambda_opcode(const node_t *node, environment_t *env) {
1639 opcode_key_t key, *entry;
1640 ir_node *irn = node->node;
1642 key.code = get_irn_opcode(irn);
1643 key.mode = get_irn_mode(irn);
1644 key.arity = get_irn_arity(irn);
1648 switch (get_irn_opcode(irn)) {
1650 key.u.proj = get_Proj_proj(irn);
1653 key.u.ent = get_Sel_entity(irn);
1656 key.u.intVal = get_Conv_strict(irn);
1659 key.u.intVal = is_Div_remainderless(irn);
1665 entry = set_insert(env->opcode2id_map, &key, sizeof(key), opcode_hash(&key));
1667 } /* lambda_opcode */
1669 /** lambda n.(n[i].partition) */
1670 static void *lambda_partition(const node_t *node, environment_t *env) {
1671 ir_node *skipped = skip_Proj(node->node);
1674 int i = env->lambda_input;
1676 if (i >= get_irn_arity(node->node)) {
1678 * We are outside the allowed range: This can happen even
1679 * if we have split by opcode first: doing so might move Followers
1680 * to Leaders and those will have a different opcode!
1681 * Note that in this case the partition is on the cprop list and will be
1687 /* ignore the "control input" for non-pinned nodes
1688 if we are running in GCSE mode */
1689 if (i < env->end_idx && get_irn_pinned(skipped) != op_pin_state_pinned)
1692 pred = i == -1 ? get_irn_n(skipped, i) : get_irn_n(node->node, i);
1693 p = get_irn_node(pred);
1696 } /* lambda_partition */
1698 /** lambda n.(n[i].partition) for commutative nodes */
1699 static void *lambda_commutative_partition(const node_t *node, environment_t *env) {
1700 ir_node *irn = node->node;
1701 ir_node *skipped = skip_Proj(irn);
1702 ir_node *pred, *left, *right;
1704 partition_t *pl, *pr;
1705 int i = env->lambda_input;
1707 if (i >= get_irn_arity(node->node)) {
1709 * We are outside the allowed range: This can happen even
1710 * if we have split by opcode first: doing so might move Followers
1711 * to Leaders and those will have a different opcode!
1712 * Note that in this case the partition is on the cprop list and will be
1718 /* ignore the "control input" for non-pinned nodes
1719 if we are running in GCSE mode */
1720 if (i < env->end_idx && get_irn_pinned(skipped) != op_pin_state_pinned)
1724 pred = get_irn_n(skipped, i);
1725 p = get_irn_node(pred);
1729 if (is_op_commutative(get_irn_op(irn))) {
1730 /* normalize partition order by returning the "smaller" on input 0,
1731 the "bigger" on input 1. */
1732 left = get_binop_left(irn);
1733 pl = get_irn_node(left)->part;
1734 right = get_binop_right(irn);
1735 pr = get_irn_node(right)->part;
1738 return pl < pr ? pl : pr;
1740 return pl > pr ? pl : pr;
1742 /* a not split out Follower */
1743 pred = get_irn_n(irn, i);
1744 p = get_irn_node(pred);
1748 } /* lambda_commutative_partition */
1751 * Returns true if a type is a constant (and NOT Top
1754 static int is_con(const lattice_elem_t type) {
1755 /* be conservative */
1756 if (is_tarval(type.tv))
1757 return tarval_is_constant(type.tv);
1758 return is_entity(type.sym.entity_p);
1762 * Implements split_by().
1764 * @param X the partition to split
1765 * @param env the environment
1767 static void split_by(partition_t *X, environment_t *env) {
1768 partition_t *I, *P = NULL;
1771 dump_partition("split_by", X);
1773 if (X->n_leader == 1) {
1774 /* we have only one leader, no need to split, just check it's type */
1775 node_t *x = get_first_node(X);
1776 X->type_is_T_or_C = x->type.tv == tarval_top || is_con(x->type);
1780 DEBUG_ONLY(what_reason = "lambda n.(n.type)";)
1781 P = split_by_what(X, lambda_type, &P, env);
1784 /* adjust the type tags, we have split partitions by type */
1785 for (I = P; I != NULL; I = I->split_next) {
1786 node_t *x = get_first_node(I);
1787 I->type_is_T_or_C = x->type.tv == tarval_top || is_con(x->type);
1794 if (Y->n_leader > 1) {
1795 /* we do not want split the TOP or constant partitions */
1796 if (! Y->type_is_T_or_C) {
1797 partition_t *Q = NULL;
1799 DEBUG_ONLY(what_reason = "lambda n.(n.opcode)";)
1800 Q = split_by_what(Y, lambda_opcode, &Q, env);
1807 if (Z->n_leader > 1) {
1808 const node_t *first = get_first_node(Z);
1809 int arity = get_irn_arity(first->node);
1811 what_func what = lambda_partition;
1812 DEBUG_ONLY(char buf[64];)
1814 if (env->commutative && is_op_commutative(get_irn_op(first->node)))
1815 what = lambda_commutative_partition;
1818 * BEWARE: during splitting by input 2 for instance we might
1819 * create new partitions which are different by input 1, so collect
1820 * them and split further.
1822 Z->split_next = NULL;
1825 for (input = arity - 1; input >= -1; --input) {
1827 partition_t *Z_prime = R;
1830 if (Z_prime->n_leader > 1) {
1831 env->lambda_input = input;
1832 DEBUG_ONLY(snprintf(buf, sizeof(buf), "lambda n.(n[%d].partition)", input);)
1833 DEBUG_ONLY(what_reason = buf;)
1834 S = split_by_what(Z_prime, what, &S, env);
1837 Z_prime->split_next = S;
1840 } while (R != NULL);
1845 } while (Q != NULL);
1848 } while (P != NULL);
1852 * (Re-)compute the type for a given node.
1854 * @param node the node
1856 static void default_compute(node_t *node) {
1858 ir_node *irn = node->node;
1860 /* if any of the data inputs have type top, the result is type top */
1861 for (i = get_irn_arity(irn) - 1; i >= 0; --i) {
1862 ir_node *pred = get_irn_n(irn, i);
1863 node_t *p = get_irn_node(pred);
1865 if (p->type.tv == tarval_top) {
1866 node->type.tv = tarval_top;
1871 if (get_irn_mode(node->node) == mode_X)
1872 node->type.tv = tarval_reachable;
1874 node->type.tv = computed_value(irn);
1875 } /* default_compute */
1878 * (Re-)compute the type for a Block node.
1880 * @param node the node
1882 static void compute_Block(node_t *node) {
1884 ir_node *block = node->node;
1886 if (block == get_irg_start_block(current_ir_graph)) {
1887 /* start block is always reachable */
1888 node->type.tv = tarval_reachable;
1892 for (i = get_Block_n_cfgpreds(block) - 1; i >= 0; --i) {
1893 node_t *pred = get_irn_node(get_Block_cfgpred(block, i));
1895 if (pred->type.tv == tarval_reachable) {
1896 /* A block is reachable, if at least of predecessor is reachable. */
1897 node->type.tv = tarval_reachable;
1901 node->type.tv = tarval_top;
1902 } /* compute_Block */
1905 * (Re-)compute the type for a Bad node.
1907 * @param node the node
1909 static void compute_Bad(node_t *node) {
1910 /* Bad nodes ALWAYS compute Top */
1911 node->type.tv = tarval_top;
1915 * (Re-)compute the type for an Unknown node.
1917 * @param node the node
1919 static void compute_Unknown(node_t *node) {
1920 /* While Unknown nodes should compute Top this is dangerous:
1921 * a Top input to a Cond would lead to BOTH control flows unreachable.
1922 * While this is correct in the given semantics, it would destroy the Firm
1925 * It would be safe to compute Top IF it can be assured, that only Cmp
1926 * nodes are inputs to Conds. We check that first.
1927 * This is the way Frontends typically build Firm, but some optimizations
1928 * (cond_eval for instance) might replace them by Phib's...
1930 node->type.tv = tarval_UNKNOWN;
1931 } /* compute_Unknown */
1934 * (Re-)compute the type for a Jmp node.
1936 * @param node the node
1938 static void compute_Jmp(node_t *node) {
1939 node_t *block = get_irn_node(get_nodes_block(node->node));
1941 node->type = block->type;
1945 * (Re-)compute the type for the Return node.
1947 * @param node the node
1949 static void compute_Return(node_t *node) {
1950 /* The Return node is NOT dead if it is in a reachable block.
1951 * This is already checked in compute(). so we can return
1952 * Reachable here. */
1953 node->type.tv = tarval_reachable;
1954 } /* compute_Return */
1957 * (Re-)compute the type for the End node.
1959 * @param node the node
1961 static void compute_End(node_t *node) {
1962 /* the End node is NOT dead of course */
1963 node->type.tv = tarval_reachable;
1967 * (Re-)compute the type for a Call.
1969 * @param node the node
1971 static void compute_Call(node_t *node) {
1973 * A Call computes always bottom, even if it has Unknown
1976 node->type.tv = tarval_bottom;
1977 } /* compute_Call */
1980 * (Re-)compute the type for a SymConst node.
1982 * @param node the node
1984 static void compute_SymConst(node_t *node) {
1985 ir_node *irn = node->node;
1986 node_t *block = get_irn_node(get_nodes_block(irn));
1988 if (block->type.tv == tarval_unreachable) {
1989 node->type.tv = tarval_top;
1992 switch (get_SymConst_kind(irn)) {
1993 case symconst_addr_ent:
1994 /* case symconst_addr_name: cannot handle this yet */
1995 node->type.sym = get_SymConst_symbol(irn);
1998 node->type.tv = computed_value(irn);
2000 } /* compute_SymConst */
2003 * (Re-)compute the type for a Phi node.
2005 * @param node the node
2007 static void compute_Phi(node_t *node) {
2009 ir_node *phi = node->node;
2010 lattice_elem_t type;
2012 /* if a Phi is in a unreachable block, its type is TOP */
2013 node_t *block = get_irn_node(get_nodes_block(phi));
2015 if (block->type.tv == tarval_unreachable) {
2016 node->type.tv = tarval_top;
2020 /* Phi implements the Meet operation */
2021 type.tv = tarval_top;
2022 for (i = get_Phi_n_preds(phi) - 1; i >= 0; --i) {
2023 node_t *pred = get_irn_node(get_Phi_pred(phi, i));
2024 node_t *pred_X = get_irn_node(get_Block_cfgpred(block->node, i));
2026 if (pred_X->type.tv == tarval_unreachable || pred->type.tv == tarval_top) {
2027 /* ignore TOP inputs: We must check here for unreachable blocks,
2028 because Firm constants live in the Start Block are NEVER Top.
2029 Else, a Phi (1,2) will produce Bottom, even if the 2 for instance
2030 comes from a unreachable input. */
2033 if (pred->type.tv == tarval_bottom) {
2034 node->type.tv = tarval_bottom;
2036 } else if (type.tv == tarval_top) {
2037 /* first constant found */
2039 } else if (type.tv != pred->type.tv) {
2040 /* different constants or tarval_bottom */
2041 node->type.tv = tarval_bottom;
2044 /* else nothing, constants are the same */
2050 * (Re-)compute the type for an Add. Special case: one nodes is a Zero Const.
2052 * @param node the node
2054 static void compute_Add(node_t *node) {
2055 ir_node *sub = node->node;
2056 node_t *l = get_irn_node(get_Add_left(sub));
2057 node_t *r = get_irn_node(get_Add_right(sub));
2058 lattice_elem_t a = l->type;
2059 lattice_elem_t b = r->type;
2062 if (a.tv == tarval_top || b.tv == tarval_top) {
2063 node->type.tv = tarval_top;
2064 } else if (a.tv == tarval_bottom || b.tv == tarval_bottom) {
2065 node->type.tv = tarval_bottom;
2067 /* x + 0 = 0 + x = x, but beware of floating point +0 + -0, so we
2068 must call tarval_add() first to handle this case! */
2069 if (is_tarval(a.tv)) {
2070 if (is_tarval(b.tv)) {
2071 node->type.tv = tarval_add(a.tv, b.tv);
2074 mode = get_tarval_mode(a.tv);
2075 if (a.tv == get_mode_null(mode)) {
2079 } else if (is_tarval(b.tv)) {
2080 mode = get_tarval_mode(b.tv);
2081 if (b.tv == get_mode_null(mode)) {
2086 node->type.tv = tarval_bottom;
2091 * (Re-)compute the type for a Sub. Special case: both nodes are congruent.
2093 * @param node the node
2095 static void compute_Sub(node_t *node) {
2096 ir_node *sub = node->node;
2097 node_t *l = get_irn_node(get_Sub_left(sub));
2098 node_t *r = get_irn_node(get_Sub_right(sub));
2099 lattice_elem_t a = l->type;
2100 lattice_elem_t b = r->type;
2103 if (a.tv == tarval_top || b.tv == tarval_top) {
2104 node->type.tv = tarval_top;
2105 } else if (is_con(a) && is_con(b)) {
2106 if (is_tarval(a.tv) && is_tarval(b.tv)) {
2107 node->type.tv = tarval_sub(a.tv, b.tv, get_irn_mode(sub));
2108 } else if (is_tarval(a.tv) && tarval_is_null(a.tv)) {
2110 } else if (is_tarval(b.tv) && tarval_is_null(b.tv)) {
2113 node->type.tv = tarval_bottom;
2115 } else if (r->part == l->part &&
2116 (!mode_is_float(get_irn_mode(l->node)))) {
2118 * BEWARE: a - a is NOT always 0 for floating Point values, as
2119 * NaN op NaN = NaN, so we must check this here.
2121 ir_mode *mode = get_irn_mode(sub);
2122 tv = get_mode_null(mode);
2124 /* if the node was ONCE evaluated by all constants, but now
2125 this breaks AND we get from the argument partitions a different
2126 result, switch to bottom.
2127 This happens because initially all nodes are in the same partition ... */
2128 if (node->type.tv != tv)
2132 node->type.tv = tarval_bottom;
2137 * (Re-)compute the type for an Eor. Special case: both nodes are congruent.
2139 * @param node the node
2141 static void compute_Eor(node_t *node) {
2142 ir_node *eor = node->node;
2143 node_t *l = get_irn_node(get_Eor_left(eor));
2144 node_t *r = get_irn_node(get_Eor_right(eor));
2145 lattice_elem_t a = l->type;
2146 lattice_elem_t b = r->type;
2149 if (a.tv == tarval_top || b.tv == tarval_top) {
2150 node->type.tv = tarval_top;
2151 } else if (is_con(a) && is_con(b)) {
2152 if (is_tarval(a.tv) && is_tarval(b.tv)) {
2153 node->type.tv = tarval_eor(a.tv, b.tv);
2154 } else if (is_tarval(a.tv) && tarval_is_null(a.tv)) {
2156 } else if (is_tarval(b.tv) && tarval_is_null(b.tv)) {
2159 node->type.tv = tarval_bottom;
2161 } else if (r->part == l->part) {
2162 ir_mode *mode = get_irn_mode(eor);
2163 tv = get_mode_null(mode);
2165 /* if the node was ONCE evaluated by all constants, but now
2166 this breaks AND we get from the argument partitions a different
2167 result, switch to bottom.
2168 This happens because initially all nodes are in the same partition ... */
2169 if (node->type.tv != tv)
2173 node->type.tv = tarval_bottom;
2178 * (Re-)compute the type for Cmp.
2180 * @param node the node
2182 static void compute_Cmp(node_t *node) {
2183 ir_node *cmp = node->node;
2184 node_t *l = get_irn_node(get_Cmp_left(cmp));
2185 node_t *r = get_irn_node(get_Cmp_right(cmp));
2186 lattice_elem_t a = l->type;
2187 lattice_elem_t b = r->type;
2189 if (a.tv == tarval_top || b.tv == tarval_top) {
2190 node->type.tv = tarval_top;
2191 } else if (r->part == l->part) {
2192 /* both nodes congruent, we can probably do something */
2193 node->type.tv = tarval_b_true;
2194 } else if (is_con(a) && is_con(b)) {
2195 /* both nodes are constants, we can probably do something */
2196 node->type.tv = tarval_b_true;
2198 node->type.tv = tarval_bottom;
2203 * (Re-)compute the type for a Proj(Cmp).
2205 * @param node the node
2206 * @param cond the predecessor Cmp node
2208 static void compute_Proj_Cmp(node_t *node, ir_node *cmp) {
2209 ir_node *proj = node->node;
2210 node_t *l = get_irn_node(get_Cmp_left(cmp));
2211 node_t *r = get_irn_node(get_Cmp_right(cmp));
2212 lattice_elem_t a = l->type;
2213 lattice_elem_t b = r->type;
2214 pn_Cmp pnc = get_Proj_proj(proj);
2217 if (a.tv == tarval_top || b.tv == tarval_top) {
2218 node->type.tv = tarval_undefined;
2219 } else if (is_con(a) && is_con(b)) {
2220 default_compute(node);
2221 } else if (r->part == l->part &&
2222 (!mode_is_float(get_irn_mode(l->node)) || pnc == pn_Cmp_Lt || pnc == pn_Cmp_Gt)) {
2224 * BEWARE: a == a is NOT always True for floating Point values, as
2225 * NaN != NaN is defined, so we must check this here.
2227 tv = pnc & pn_Cmp_Eq ? tarval_b_true: tarval_b_false;
2229 /* if the node was ONCE evaluated by all constants, but now
2230 this breaks AND we get from the argument partitions a different
2231 result, switch to bottom.
2232 This happens because initially all nodes are in the same partition ... */
2233 if (node->type.tv != tv)
2237 node->type.tv = tarval_bottom;
2239 } /* compute_Proj_Cmp */
2242 * (Re-)compute the type for a Proj(Cond).
2244 * @param node the node
2245 * @param cond the predecessor Cond node
2247 static void compute_Proj_Cond(node_t *node, ir_node *cond) {
2248 ir_node *proj = node->node;
2249 long pnc = get_Proj_proj(proj);
2250 ir_node *sel = get_Cond_selector(cond);
2251 node_t *selector = get_irn_node(sel);
2254 * Note: it is crucial for the monotony that the Proj(Cond)
2255 * are evaluates after all predecessors of the Cond selector are
2261 * Due to the fact that 0 is a const, the Cmp gets immediately
2262 * on the cprop list. It will be evaluated before x is evaluated,
2263 * might leaving x as Top. When later x is evaluated, the Cmp
2264 * might change its value.
2265 * BUT if the Cond is evaluated before this happens, Proj(Cond, FALSE)
2266 * gets R, and later changed to F if Cmp is evaluated to True!
2268 * We prevent this by putting Conds in an extra cprop_X queue, which
2269 * gets evaluated after the cprop queue is empty.
2271 * Note that this even happens with Click's original algorithm, if
2272 * Cmp(x, 0) is evaluated to True first and later changed to False
2273 * if x was Top first and later changed to a Const ...
2274 * It is unclear how Click solved that problem ...
2276 * However, in rare cases even this does not help, if a Top reaches
2277 * a compare through a Phi, than Proj(Cond) is evaluated changing
2278 * the type of the Phi to something other.
2279 * So, we take the last resort and bind the type to R once
2282 * (This might be even the way Click works around the whole problem).
2284 * Finally, we may miss some optimization possibilities due to this:
2289 * If Top reaches the if first, than we decide for != here.
2290 * If y later is evaluated to 0, we cannot revert this decision
2291 * and must live with both outputs enabled. If this happens,
2292 * we get an unresolved if (true) in the code ...
2294 * In Click's version where this decision is done at the Cmp,
2295 * the Cmp is NOT optimized away than (if y evaluated to 1
2296 * for instance) and we get a if (1 == 0) here ...
2298 * Both solutions are suboptimal.
2299 * At least, we could easily detect this problem and run
2300 * cf_opt() (or even combo) again :-(
2302 if (node->type.tv == tarval_reachable)
2305 if (get_irn_mode(sel) == mode_b) {
2307 if (pnc == pn_Cond_true) {
2308 if (selector->type.tv == tarval_b_false) {
2309 node->type.tv = tarval_unreachable;
2310 } else if (selector->type.tv == tarval_b_true) {
2311 node->type.tv = tarval_reachable;
2312 } else if (selector->type.tv == tarval_bottom) {
2313 node->type.tv = tarval_reachable;
2315 assert(selector->type.tv == tarval_top);
2316 if (tarval_UNKNOWN == tarval_top) {
2317 /* any condition based on Top is "!=" */
2318 node->type.tv = tarval_unreachable;
2320 node->type.tv = tarval_unreachable;
2324 assert(pnc == pn_Cond_false);
2326 if (selector->type.tv == tarval_b_false) {
2327 node->type.tv = tarval_reachable;
2328 } else if (selector->type.tv == tarval_b_true) {
2329 node->type.tv = tarval_unreachable;
2330 } else if (selector->type.tv == tarval_bottom) {
2331 node->type.tv = tarval_reachable;
2333 assert(selector->type.tv == tarval_top);
2334 if (tarval_UNKNOWN == tarval_top) {
2335 /* any condition based on Top is "!=" */
2336 node->type.tv = tarval_reachable;
2338 node->type.tv = tarval_unreachable;
2344 if (selector->type.tv == tarval_bottom) {
2345 node->type.tv = tarval_reachable;
2346 } else if (selector->type.tv == tarval_top) {
2347 if (tarval_UNKNOWN == tarval_top &&
2348 pnc == get_Cond_defaultProj(cond)) {
2349 /* a switch based of Top is always "default" */
2350 node->type.tv = tarval_reachable;
2352 node->type.tv = tarval_unreachable;
2355 long value = get_tarval_long(selector->type.tv);
2356 if (pnc == get_Cond_defaultProj(cond)) {
2357 /* default switch, have to check ALL other cases */
2360 for (i = get_irn_n_outs(cond) - 1; i >= 0; --i) {
2361 ir_node *succ = get_irn_out(cond, i);
2365 if (value == get_Proj_proj(succ)) {
2366 /* we found a match, will NOT take the default case */
2367 node->type.tv = tarval_unreachable;
2371 /* all cases checked, no match, will take default case */
2372 node->type.tv = tarval_reachable;
2375 node->type.tv = value == pnc ? tarval_reachable : tarval_unreachable;
2379 } /* compute_Proj_Cond */
2382 * (Re-)compute the type for a Proj-Node.
2384 * @param node the node
2386 static void compute_Proj(node_t *node) {
2387 ir_node *proj = node->node;
2388 ir_mode *mode = get_irn_mode(proj);
2389 node_t *block = get_irn_node(get_nodes_block(skip_Proj(proj)));
2390 ir_node *pred = get_Proj_pred(proj);
2392 if (block->type.tv == tarval_unreachable) {
2393 /* a Proj in a unreachable Block stay Top */
2394 node->type.tv = tarval_top;
2397 if (get_irn_node(pred)->type.tv == tarval_top && !is_Cond(pred)) {
2398 /* if the predecessor is Top, its Proj follow */
2399 node->type.tv = tarval_top;
2403 if (mode == mode_M) {
2404 /* mode M is always bottom */
2405 node->type.tv = tarval_bottom;
2408 if (mode != mode_X) {
2410 compute_Proj_Cmp(node, pred);
2412 default_compute(node);
2415 /* handle mode_X nodes */
2417 switch (get_irn_opcode(pred)) {
2419 /* the Proj_X from the Start is always reachable.
2420 However this is already handled at the top. */
2421 node->type.tv = tarval_reachable;
2424 compute_Proj_Cond(node, pred);
2427 default_compute(node);
2429 } /* compute_Proj */
2432 * (Re-)compute the type for a Confirm.
2434 * @param node the node
2436 static void compute_Confirm(node_t *node) {
2437 ir_node *confirm = node->node;
2438 node_t *pred = get_irn_node(get_Confirm_value(confirm));
2440 if (get_Confirm_cmp(confirm) == pn_Cmp_Eq) {
2441 node_t *bound = get_irn_node(get_Confirm_bound(confirm));
2443 if (is_con(bound->type)) {
2444 /* is equal to a constant */
2445 node->type = bound->type;
2449 /* a Confirm is a copy OR a Const */
2450 node->type = pred->type;
2451 } /* compute_Confirm */
2454 * (Re-)compute the type for a Max.
2456 * @param node the node
2458 static void compute_Max(node_t *node) {
2459 ir_node *op = node->node;
2460 node_t *l = get_irn_node(get_binop_left(op));
2461 node_t *r = get_irn_node(get_binop_right(op));
2462 lattice_elem_t a = l->type;
2463 lattice_elem_t b = r->type;
2465 if (a.tv == tarval_top || b.tv == tarval_top) {
2466 node->type.tv = tarval_top;
2467 } else if (is_con(a) && is_con(b)) {
2468 /* both nodes are constants, we can probably do something */
2470 /* this case handles SymConsts as well */
2473 ir_mode *mode = get_irn_mode(op);
2474 tarval *tv_min = get_mode_min(mode);
2478 else if (b.tv == tv_min)
2480 else if (is_tarval(a.tv) && is_tarval(b.tv)) {
2481 if (tarval_cmp(a.tv, b.tv) & pn_Cmp_Gt)
2482 node->type.tv = a.tv;
2484 node->type.tv = b.tv;
2486 node->type.tv = tarval_bad;
2489 } else if (r->part == l->part) {
2490 /* both nodes congruent, we can probably do something */
2493 node->type.tv = tarval_bottom;
2498 * (Re-)compute the type for a Min.
2500 * @param node the node
2502 static void compute_Min(node_t *node) {
2503 ir_node *op = node->node;
2504 node_t *l = get_irn_node(get_binop_left(op));
2505 node_t *r = get_irn_node(get_binop_right(op));
2506 lattice_elem_t a = l->type;
2507 lattice_elem_t b = r->type;
2509 if (a.tv == tarval_top || b.tv == tarval_top) {
2510 node->type.tv = tarval_top;
2511 } else if (is_con(a) && is_con(b)) {
2512 /* both nodes are constants, we can probably do something */
2514 /* this case handles SymConsts as well */
2517 ir_mode *mode = get_irn_mode(op);
2518 tarval *tv_max = get_mode_max(mode);
2522 else if (b.tv == tv_max)
2524 else if (is_tarval(a.tv) && is_tarval(b.tv)) {
2525 if (tarval_cmp(a.tv, b.tv) & pn_Cmp_Gt)
2526 node->type.tv = a.tv;
2528 node->type.tv = b.tv;
2530 node->type.tv = tarval_bad;
2533 } else if (r->part == l->part) {
2534 /* both nodes congruent, we can probably do something */
2537 node->type.tv = tarval_bottom;
2542 * (Re-)compute the type for a given node.
2544 * @param node the node
2546 static void compute(node_t *node) {
2547 ir_node *irn = node->node;
2550 #ifndef VERIFY_MONOTONE
2552 * Once a node reaches bottom, the type cannot fall further
2553 * in the lattice and we can stop computation.
2554 * Do not take this exit if the monotony verifier is
2555 * enabled to catch errors.
2557 if (node->type.tv == tarval_bottom)
2561 if (is_no_Block(irn)) {
2562 /* for pinned nodes, check its control input */
2563 if (get_irn_pinned(skip_Proj(irn)) == op_pin_state_pinned) {
2564 node_t *block = get_irn_node(get_nodes_block(irn));
2566 if (block->type.tv == tarval_unreachable) {
2567 node->type.tv = tarval_top;
2573 func = (compute_func)node->node->op->ops.generic;
2579 * Identity functions: Note that one might thing that identity() is just a
2580 * synonym for equivalent_node(). While this is true, we cannot use it for the algorithm
2581 * here, because it expects that the identity node is one of the inputs, which is NOT
2582 * always true for equivalent_node() which can handle (and does sometimes) DAGs.
2583 * So, we have our own implementation, which copies some parts of equivalent_node()
2587 * Calculates the Identity for Phi nodes
2589 static node_t *identity_Phi(node_t *node) {
2590 ir_node *phi = node->node;
2591 ir_node *block = get_nodes_block(phi);
2592 node_t *n_part = NULL;
2595 for (i = get_Phi_n_preds(phi) - 1; i >= 0; --i) {
2596 node_t *pred_X = get_irn_node(get_Block_cfgpred(block, i));
2598 if (pred_X->type.tv == tarval_reachable) {
2599 node_t *pred = get_irn_node(get_Phi_pred(phi, i));
2603 else if (n_part->part != pred->part) {
2604 /* incongruent inputs, not a follower */
2609 /* if n_part is NULL here, all inputs path are dead, the Phi computes
2610 * tarval_top, is in the TOP partition and should NOT being split! */
2611 assert(n_part != NULL);
2613 } /* identity_Phi */
2616 * Calculates the Identity for commutative 0 neutral nodes.
2618 static node_t *identity_comm_zero_binop(node_t *node) {
2619 ir_node *op = node->node;
2620 node_t *a = get_irn_node(get_binop_left(op));
2621 node_t *b = get_irn_node(get_binop_right(op));
2622 ir_mode *mode = get_irn_mode(op);
2625 /* for FP these optimizations are only allowed if fp_strict_algebraic is disabled */
2626 if (mode_is_float(mode) && (get_irg_fp_model(current_ir_graph) & fp_strict_algebraic))
2629 /* node: no input should be tarval_top, else the binop would be also
2630 * Top and not being split. */
2631 zero = get_mode_null(mode);
2632 if (a->type.tv == zero)
2634 if (b->type.tv == zero)
2637 } /* identity_comm_zero_binop */
2640 * Calculates the Identity for Shift nodes.
2642 static node_t *identity_shift(node_t *node) {
2643 ir_node *op = node->node;
2644 node_t *b = get_irn_node(get_binop_right(op));
2645 ir_mode *mode = get_irn_mode(b->node);
2648 /* node: no input should be tarval_top, else the binop would be also
2649 * Top and not being split. */
2650 zero = get_mode_null(mode);
2651 if (b->type.tv == zero)
2652 return get_irn_node(get_binop_left(op));
2654 } /* identity_shift */
2657 * Calculates the Identity for Mul nodes.
2659 static node_t *identity_Mul(node_t *node) {
2660 ir_node *op = node->node;
2661 node_t *a = get_irn_node(get_Mul_left(op));
2662 node_t *b = get_irn_node(get_Mul_right(op));
2663 ir_mode *mode = get_irn_mode(op);
2666 /* for FP these optimizations are only allowed if fp_strict_algebraic is disabled */
2667 if (mode_is_float(mode) && (get_irg_fp_model(current_ir_graph) & fp_strict_algebraic))
2670 /* node: no input should be tarval_top, else the binop would be also
2671 * Top and not being split. */
2672 one = get_mode_one(mode);
2673 if (a->type.tv == one)
2675 if (b->type.tv == one)
2678 } /* identity_Mul */
2681 * Calculates the Identity for Sub nodes.
2683 static node_t *identity_Sub(node_t *node) {
2684 ir_node *sub = node->node;
2685 node_t *b = get_irn_node(get_Sub_right(sub));
2686 ir_mode *mode = get_irn_mode(sub);
2688 /* for FP these optimizations are only allowed if fp_strict_algebraic is disabled */
2689 if (mode_is_float(mode) && (get_irg_fp_model(current_ir_graph) & fp_strict_algebraic))
2692 /* node: no input should be tarval_top, else the binop would be also
2693 * Top and not being split. */
2694 if (b->type.tv == get_mode_null(mode))
2695 return get_irn_node(get_Sub_left(sub));
2697 } /* identity_Sub */
2700 * Calculates the Identity for And nodes.
2702 static node_t *identity_And(node_t *node) {
2703 ir_node *and = node->node;
2704 node_t *a = get_irn_node(get_And_left(and));
2705 node_t *b = get_irn_node(get_And_right(and));
2706 tarval *neutral = get_mode_all_one(get_irn_mode(and));
2708 /* node: no input should be tarval_top, else the And would be also
2709 * Top and not being split. */
2710 if (a->type.tv == neutral)
2712 if (b->type.tv == neutral)
2715 } /* identity_And */
2718 * Calculates the Identity for Confirm nodes.
2720 static node_t *identity_Confirm(node_t *node) {
2721 ir_node *confirm = node->node;
2723 /* a Confirm is always a Copy */
2724 return get_irn_node(get_Confirm_value(confirm));
2725 } /* identity_Confirm */
2728 * Calculates the Identity for Mux nodes.
2730 static node_t *identity_Mux(node_t *node) {
2731 ir_node *mux = node->node;
2732 node_t *t = get_irn_node(get_Mux_true(mux));
2733 node_t *f = get_irn_node(get_Mux_false(mux));
2736 if (t->part == f->part)
2739 /* for now, the 1-input identity is not supported */
2741 sel = get_irn_node(get_Mux_sel(mux));
2743 /* Mux sel input is mode_b, so it is always a tarval */
2744 if (sel->type.tv == tarval_b_true)
2746 if (sel->type.tv == tarval_b_false)
2750 } /* identity_Mux */
2753 * Calculates the Identity for Min nodes.
2755 static node_t *identity_Min(node_t *node) {
2756 ir_node *op = node->node;
2757 node_t *a = get_irn_node(get_binop_left(op));
2758 node_t *b = get_irn_node(get_binop_right(op));
2759 ir_mode *mode = get_irn_mode(op);
2762 if (a->part == b->part) {
2763 /* leader of multiple predecessors */
2767 /* works even with NaN */
2768 tv_max = get_mode_max(mode);
2769 if (a->type.tv == tv_max)
2771 if (b->type.tv == tv_max)
2774 } /* identity_Min */
2777 * Calculates the Identity for Max nodes.
2779 static node_t *identity_Max(node_t *node) {
2780 ir_node *op = node->node;
2781 node_t *a = get_irn_node(get_binop_left(op));
2782 node_t *b = get_irn_node(get_binop_right(op));
2783 ir_mode *mode = get_irn_mode(op);
2786 if (a->part == b->part) {
2787 /* leader of multiple predecessors */
2791 /* works even with NaN */
2792 tv_min = get_mode_min(mode);
2793 if (a->type.tv == tv_min)
2795 if (b->type.tv == tv_min)
2798 } /* identity_Max */
2801 * Calculates the Identity for nodes.
2803 static node_t *identity(node_t *node) {
2804 ir_node *irn = node->node;
2806 switch (get_irn_opcode(irn)) {
2808 return identity_Phi(node);
2810 return identity_Mul(node);
2814 return identity_comm_zero_binop(node);
2819 return identity_shift(node);
2821 return identity_And(node);
2823 return identity_Sub(node);
2825 return identity_Confirm(node);
2827 return identity_Mux(node);
2829 return identity_Min(node);
2831 return identity_Max(node);
2838 * Node follower is a (new) follower of leader, segregate Leader
2841 static void segregate_def_use_chain_1(const ir_node *follower, node_t *leader) {
2842 ir_node *l = leader->node;
2843 int j, i, n = get_irn_n_outs(l);
2845 DB((dbg, LEVEL_2, "%+F is a follower of %+F\n", follower, leader->node));
2846 /* The leader edges must remain sorted, but follower edges can
2848 for (i = leader->n_followers + 1; i <= n; ++i) {
2849 if (l->out[i].use == follower) {
2850 ir_def_use_edge t = l->out[i];
2852 for (j = i - 1; j >= leader->n_followers + 1; --j)
2853 l->out[j + 1] = l->out[j];
2854 ++leader->n_followers;
2855 l->out[leader->n_followers] = t;
2859 } /* segregate_def_use_chain_1 */
2862 * Node follower is a (new) follower segregate its Leader
2865 * @param follower the follower IR node
2867 static void segregate_def_use_chain(const ir_node *follower) {
2870 for (i = get_irn_arity(follower) - 1; i >= 0; --i) {
2871 node_t *pred = get_irn_node(get_irn_n(follower, i));
2873 segregate_def_use_chain_1(follower, pred);
2875 } /* segregate_def_use_chain */
2878 * Propagate constant evaluation.
2880 * @param env the environment
2882 static void propagate(environment_t *env) {
2885 lattice_elem_t old_type;
2887 unsigned n_fallen, old_type_was_T_or_C;
2890 while (env->cprop != NULL) {
2891 void *oldopcode = NULL;
2893 /* remove the first partition X from cprop */
2896 env->cprop = X->cprop_next;
2898 old_type_was_T_or_C = X->type_is_T_or_C;
2900 DB((dbg, LEVEL_2, "Propagate type on part%d\n", X->nr));
2904 int cprop_empty = list_empty(&X->cprop);
2905 int cprop_X_empty = list_empty(&X->cprop_X);
2907 if (cprop_empty && cprop_X_empty) {
2908 /* both cprop lists are empty */
2912 /* remove the first Node x from X.cprop */
2914 /* Get a node from the cprop_X list only if
2915 * all data nodes are processed.
2916 * This ensures, that all inputs of the Cond
2917 * predecessor are processed if its type is still Top.
2919 x = list_entry(X->cprop_X.next, node_t, cprop_list);
2921 x = list_entry(X->cprop.next, node_t, cprop_list);
2924 //assert(x->part == X);
2925 list_del(&x->cprop_list);
2928 if (x->is_follower && identity(x) == x) {
2929 /* check the opcode first */
2930 if (oldopcode == NULL) {
2931 oldopcode = lambda_opcode(get_first_node(X), env);
2933 if (oldopcode != lambda_opcode(x, env)) {
2934 if (x->on_fallen == 0) {
2935 /* different opcode -> x falls out of this partition */
2940 DB((dbg, LEVEL_2, "Add node %+F to fallen\n", x->node));
2944 /* x will make the follower -> leader transition */
2945 follower_to_leader(x);
2948 /* compute a new type for x */
2950 DB((dbg, LEVEL_3, "computing type of %+F\n", x->node));
2952 if (x->type.tv != old_type.tv) {
2953 DB((dbg, LEVEL_2, "node %+F has changed type from %+F to %+F\n", x->node, old_type, x->type));
2954 verify_type(old_type, x);
2956 if (x->on_fallen == 0) {
2957 /* Add x to fallen. Nodes might fall from T -> const -> _|_, so check that they are
2958 not already on the list. */
2963 DB((dbg, LEVEL_2, "Add node %+F to fallen\n", x->node));
2965 for (i = get_irn_n_outs(x->node) - 1; i >= 0; --i) {
2966 ir_node *succ = get_irn_out(x->node, i);
2967 node_t *y = get_irn_node(succ);
2969 /* Add y to y.partition.cprop. */
2970 add_to_cprop(y, env);
2975 if (n_fallen > 0 && n_fallen != X->n_leader) {
2976 DB((dbg, LEVEL_2, "Splitting part%d by fallen\n", X->nr));
2977 Y = split(&X, fallen, env);
2979 * We have split out fallen node. The type of the result
2980 * partition is NOT set yet.
2982 Y->type_is_T_or_C = 0;
2986 /* remove the flags from the fallen list */
2987 for (x = fallen; x != NULL; x = x->next)
2990 if (old_type_was_T_or_C) {
2993 /* check if some nodes will make the leader -> follower transition */
2994 list_for_each_entry_safe(node_t, y, tmp, &Y->Leader, node_list) {
2995 if (y->type.tv != tarval_top && ! is_con(y->type)) {
2996 node_t *eq_node = identity(y);
2998 if (eq_node != y && eq_node->part == y->part) {
2999 DB((dbg, LEVEL_2, "Node %+F is a follower of %+F\n", y->node, eq_node->node));
3000 /* move to Follower */
3002 list_del(&y->node_list);
3003 list_add_tail(&y->node_list, &Y->Follower);
3006 segregate_def_use_chain(y->node);
3016 * Get the leader for a given node from its congruence class.
3018 * @param irn the node
3020 static ir_node *get_leader(node_t *node) {
3021 partition_t *part = node->part;
3023 if (part->n_leader > 1 || node->is_follower) {
3024 if (node->is_follower) {
3025 DB((dbg, LEVEL_2, "Replacing follower %+F\n", node->node));
3028 DB((dbg, LEVEL_2, "Found congruence class for %+F\n", node->node));
3030 return get_first_node(part)->node;
3036 * Returns non-zero if a mode_T node has only one reachable output.
3038 static int only_one_reachable_proj(ir_node *n) {
3041 for (i = get_irn_n_outs(n) - 1; i >= 0; --i) {
3042 ir_node *proj = get_irn_out(n, i);
3045 /* skip non-control flow Proj's */
3046 if (get_irn_mode(proj) != mode_X)
3049 node = get_irn_node(proj);
3050 if (node->type.tv == tarval_reachable) {
3056 } /* only_one_reachable_proj */
3059 * Return non-zero if the control flow predecessor node pred
3060 * is the only reachable control flow exit of its block.
3062 * @param pred the control flow exit
3064 static int can_exchange(ir_node *pred) {
3067 else if (is_Jmp(pred))
3069 else if (get_irn_mode(pred) == mode_T) {
3070 /* if the predecessor block has more than one
3071 reachable outputs we cannot remove the block */
3072 return only_one_reachable_proj(pred);
3075 } /* can_exchange */
3078 * Block Post-Walker, apply the analysis results on control flow by
3079 * shortening Phi's and Block inputs.
3081 static void apply_cf(ir_node *block, void *ctx) {
3082 environment_t *env = ctx;
3083 node_t *node = get_irn_node(block);
3085 ir_node **ins, **in_X;
3086 ir_node *phi, *next;
3088 n = get_Block_n_cfgpreds(block);
3090 if (node->type.tv == tarval_unreachable) {
3093 for (i = n - 1; i >= 0; --i) {
3094 ir_node *pred = get_Block_cfgpred(block, i);
3096 if (! is_Bad(pred)) {
3097 node_t *pred_bl = get_irn_node(get_nodes_block(skip_Proj(pred)));
3099 if (pred_bl->flagged == 0) {
3100 pred_bl->flagged = 3;
3102 if (pred_bl->type.tv == tarval_reachable) {
3104 * We will remove an edge from block to its pred.
3105 * This might leave the pred block as an endless loop
3107 if (! is_backedge(block, i))
3108 keep_alive(pred_bl->node);
3114 /* the EndBlock is always reachable even if the analysis
3115 finds out the opposite :-) */
3116 if (block != get_irg_end_block(current_ir_graph)) {
3117 /* mark dead blocks */
3118 set_Block_dead(block);
3119 DB((dbg, LEVEL_1, "Removing dead %+F\n", block));
3121 /* the endblock is unreachable */
3122 set_irn_in(block, 0, NULL);
3128 /* only one predecessor combine */
3129 ir_node *pred = skip_Proj(get_Block_cfgpred(block, 0));
3131 if (can_exchange(pred)) {
3132 ir_node *new_block = get_nodes_block(pred);
3133 DB((dbg, LEVEL_1, "Fuse %+F with %+F\n", block, new_block));
3134 DBG_OPT_COMBO(block, new_block, FS_OPT_COMBO_CF);
3135 exchange(block, new_block);
3136 node->node = new_block;
3142 NEW_ARR_A(ir_node *, in_X, n);
3144 for (i = 0; i < n; ++i) {
3145 ir_node *pred = get_Block_cfgpred(block, i);
3146 node_t *node = get_irn_node(pred);
3148 if (node->type.tv == tarval_reachable) {
3151 DB((dbg, LEVEL_1, "Removing dead input %d from %+F (%+F)\n", i, block, pred));
3152 if (! is_Bad(pred)) {
3153 node_t *pred_bl = get_irn_node(get_nodes_block(skip_Proj(pred)));
3155 if (pred_bl->flagged == 0) {
3156 pred_bl->flagged = 3;
3158 if (pred_bl->type.tv == tarval_reachable) {
3160 * We will remove an edge from block to its pred.
3161 * This might leave the pred block as an endless loop
3163 if (! is_backedge(block, i))
3164 keep_alive(pred_bl->node);
3174 NEW_ARR_A(ir_node *, ins, n);
3175 for (phi = get_Block_phis(block); phi != NULL; phi = next) {
3176 node_t *node = get_irn_node(phi);
3178 next = get_Phi_next(phi);
3179 if (is_tarval(node->type.tv) && tarval_is_constant(node->type.tv)) {
3180 /* this Phi is replaced by a constant */
3181 tarval *tv = node->type.tv;
3182 ir_node *c = new_Const(get_tarval_mode(tv), tv);
3184 set_irn_node(c, node);
3186 DB((dbg, LEVEL_1, "%+F is replaced by %+F\n", phi, c));
3187 DBG_OPT_COMBO(phi, c, FS_OPT_COMBO_CONST);
3192 for (i = 0; i < n; ++i) {
3193 node_t *pred = get_irn_node(get_Block_cfgpred(block, i));
3195 if (pred->type.tv == tarval_reachable) {
3196 ins[j++] = get_Phi_pred(phi, i);
3200 /* this Phi is replaced by a single predecessor */
3201 ir_node *s = ins[0];
3202 node_t *phi_node = get_irn_node(phi);
3205 DB((dbg, LEVEL_1, "%+F is replaced by %+F because of cf change\n", phi, s));
3206 DBG_OPT_COMBO(phi, s, FS_OPT_COMBO_FOLLOWER);
3211 set_irn_in(phi, j, ins);
3219 /* this Block has only one live predecessor */
3220 ir_node *pred = skip_Proj(in_X[0]);
3222 if (can_exchange(pred)) {
3223 ir_node *new_block = get_nodes_block(pred);
3224 DBG_OPT_COMBO(block, new_block, FS_OPT_COMBO_CF);
3225 exchange(block, new_block);
3226 node->node = new_block;
3231 set_irn_in(block, k, in_X);
3236 * Exchange a node by its leader.
3237 * Beware: in rare cases the mode might be wrong here, for instance
3238 * AddP(x, NULL) is a follower of x, but with different mode.
3241 static void exchange_leader(ir_node *irn, ir_node *leader) {
3242 ir_mode *mode = get_irn_mode(irn);
3243 if (mode != get_irn_mode(leader)) {
3244 /* The conv is a no-op, so we are free to place it
3245 * either in the block of the leader OR in irn's block.
3246 * Probably placing it into leaders block might reduce
3247 * the number of Conv due to CSE. */
3248 ir_node *block = get_nodes_block(leader);
3249 dbg_info *dbg = get_irn_dbg_info(irn);
3251 leader = new_rd_Conv(dbg, current_ir_graph, block, leader, mode);
3253 exchange(irn, leader);
3254 } /* exchange_leader */
3257 * Check, if all users of a mode_M node are dead. Use
3258 * the Def-Use edges for this purpose, as they still
3259 * reflect the situation.
3261 static int all_users_are_dead(const ir_node *irn) {
3262 int i, n = get_irn_n_outs(irn);
3264 for (i = 1; i <= n; ++i) {
3265 const ir_node *succ = irn->out[i].use;
3266 const node_t *block = get_irn_node(get_nodes_block(succ));
3269 if (block->type.tv == tarval_unreachable) {
3270 /* block is unreachable */
3273 node = get_irn_node(succ);
3274 if (node->type.tv != tarval_top) {
3275 /* found a reachable user */
3279 /* all users are unreachable */
3281 } /* all_user_are_dead */
3284 * Walker: Find reachable mode_M nodes that have only
3285 * unreachable users. These nodes must be kept later.
3287 static void find_kept_memory(ir_node *irn, void *ctx) {
3288 environment_t *env = ctx;
3289 node_t *node, *block;
3291 if (get_irn_mode(irn) != mode_M)
3294 block = get_irn_node(get_nodes_block(irn));
3295 if (block->type.tv == tarval_unreachable)
3298 node = get_irn_node(irn);
3299 if (node->type.tv == tarval_top)
3302 /* ok, we found a live memory node. */
3303 if (all_users_are_dead(irn)) {
3304 DB((dbg, LEVEL_1, "%+F must be kept\n", irn));
3305 ARR_APP1(ir_node *, env->kept_memory, irn);
3307 } /* find_kept_memory */
3310 * Post-Walker, apply the analysis results;
3312 static void apply_result(ir_node *irn, void *ctx) {
3313 environment_t *env = ctx;
3314 node_t *node = get_irn_node(irn);
3316 if (is_Block(irn) || is_End(irn) || is_Bad(irn)) {
3317 /* blocks already handled, do not touch the End node */
3319 node_t *block = get_irn_node(get_nodes_block(irn));
3321 if (block->type.tv == tarval_unreachable) {
3322 ir_node *bad = get_irg_bad(current_ir_graph);
3324 /* here, bad might already have a node, but this can be safely ignored
3325 as long as bad has at least ONE valid node */
3326 set_irn_node(bad, node);
3328 DB((dbg, LEVEL_1, "%+F is unreachable\n", irn));
3331 } else if (node->type.tv == tarval_top) {
3332 ir_mode *mode = get_irn_mode(irn);
3334 if (mode == mode_M) {
3335 /* never kill a mode_M node */
3337 ir_node *pred = get_Proj_pred(irn);
3338 node_t *pnode = get_irn_node(pred);
3340 if (pnode->type.tv == tarval_top) {
3341 /* skip the predecessor */
3342 ir_node *mem = get_memop_mem(pred);
3344 DB((dbg, LEVEL_1, "%+F computes Top, replaced by %+F\n", irn, mem));
3349 /* leave other nodes, especially PhiM */
3350 } else if (mode == mode_T) {
3351 /* Do not kill mode_T nodes, kill their Projs */
3352 } else if (! is_Unknown(irn)) {
3353 /* don't kick away Unknown's, they might be still needed */
3354 ir_node *unk = new_r_Unknown(current_ir_graph, mode);
3356 /* control flow should already be handled at apply_cf() */
3357 assert(mode != mode_X);
3359 /* see comment above */
3360 set_irn_node(unk, node);
3362 DB((dbg, LEVEL_1, "%+F computes Top\n", irn));
3367 else if (get_irn_mode(irn) == mode_X) {
3370 ir_node *cond = get_Proj_pred(irn);
3372 if (is_Cond(cond)) {
3373 if (only_one_reachable_proj(cond)) {
3374 ir_node *jmp = new_r_Jmp(current_ir_graph, block->node);
3375 set_irn_node(jmp, node);
3377 DB((dbg, LEVEL_1, "%+F is replaced by %+F\n", irn, jmp));
3378 DBG_OPT_COMBO(irn, jmp, FS_OPT_COMBO_CF);
3382 node_t *sel = get_irn_node(get_Cond_selector(cond));
3383 tarval *tv = sel->type.tv;
3385 if (is_tarval(tv) && tarval_is_constant(tv)) {
3386 /* The selector is a constant, but more
3387 * than one output is active: An unoptimized
3395 /* normal data node */
3396 if (is_tarval(node->type.tv) && tarval_is_constant(node->type.tv)) {
3397 tarval *tv = node->type.tv;
3400 * Beware: never replace mode_T nodes by constants. Currently we must mark
3401 * mode_T nodes with constants, but do NOT replace them.
3403 if (! is_Const(irn) && get_irn_mode(irn) != mode_T) {
3404 /* can be replaced by a constant */
3405 ir_node *c = new_Const(get_tarval_mode(tv), tv);
3406 set_irn_node(c, node);
3408 DB((dbg, LEVEL_1, "%+F is replaced by %+F\n", irn, c));
3409 DBG_OPT_COMBO(irn, c, FS_OPT_COMBO_CONST);
3410 exchange_leader(irn, c);
3413 } else if (is_entity(node->type.sym.entity_p)) {
3414 if (! is_SymConst(irn)) {
3415 /* can be replaced by a SymConst */
3416 ir_node *symc = new_r_SymConst(current_ir_graph, block->node, get_irn_mode(irn), node->type.sym, symconst_addr_ent);
3417 set_irn_node(symc, node);
3420 DB((dbg, LEVEL_1, "%+F is replaced by %+F\n", irn, symc));
3421 DBG_OPT_COMBO(irn, symc, FS_OPT_COMBO_CONST);
3422 exchange_leader(irn, symc);
3425 } else if (is_Confirm(irn)) {
3426 /* Confirms are always follower, but do not kill them here */
3428 ir_node *leader = get_leader(node);
3430 if (leader != irn) {
3431 int non_strict_phi = 0;
3434 * Beware: Do not remove Phi(Unknown, ..., x, ..., Unknown)
3435 * as this might create non-strict programs.
3437 if (node->is_follower && is_Phi(irn) && !is_Unknown(leader)) {
3440 for (i = get_Phi_n_preds(irn) - 1; i >= 0; --i) {
3441 ir_node *pred = get_Phi_pred(irn, i);
3443 if (is_Unknown(pred)) {
3449 if (! non_strict_phi) {
3450 DB((dbg, LEVEL_1, "%+F from part%d is replaced by %+F\n", irn, node->part->nr, leader));
3451 if (node->is_follower)
3452 DBG_OPT_COMBO(irn, leader, FS_OPT_COMBO_FOLLOWER);
3454 DBG_OPT_COMBO(irn, leader, FS_OPT_COMBO_CONGRUENT);
3455 exchange_leader(irn, leader);
3462 } /* apply_result */
3465 * Fix the keep-alives by deleting unreachable ones.
3467 static void apply_end(ir_node *end, environment_t *env) {
3468 int i, j, n = get_End_n_keepalives(end);
3472 NEW_ARR_A(ir_node *, in, n);
3474 /* fix the keep alive */
3475 for (i = j = 0; i < n; i++) {
3476 ir_node *ka = get_End_keepalive(end, i);
3477 node_t *node = get_irn_node(ka);
3480 node = get_irn_node(get_nodes_block(ka));
3482 if (node->type.tv != tarval_unreachable && !is_Bad(ka))
3486 set_End_keepalives(end, j, in);
3491 #define SET(code) op_##code->ops.generic = (op_func)compute_##code
3494 * sets the generic functions to compute.
3496 static void set_compute_functions(void) {
3499 /* set the default compute function */
3500 for (i = get_irp_n_opcodes() - 1; i >= 0; --i) {
3501 ir_op *op = get_irp_opcode(i);
3502 op->ops.generic = (op_func)default_compute;
3505 /* set specific functions */
3526 } /* set_compute_functions */
3531 static void add_memory_keeps(ir_node **kept_memory, int len) {
3532 ir_node *end = get_irg_end(current_ir_graph);
3536 ir_nodeset_init(&set);
3538 /* check, if those nodes are already kept */
3539 for (i = get_End_n_keepalives(end) - 1; i >= 0; --i)
3540 ir_nodeset_insert(&set, get_End_keepalive(end, i));
3542 for (i = len - 1; i >= 0; --i) {
3543 ir_node *ka = kept_memory[i];
3545 if (! ir_nodeset_contains(&set, ka)) {
3546 add_End_keepalive(end, ka);
3549 ir_nodeset_destroy(&set);
3550 } /* add_memory_keeps */
3552 void combo(ir_graph *irg) {
3554 ir_node *initial_bl;
3556 ir_graph *rem = current_ir_graph;
3559 current_ir_graph = irg;
3561 /* register a debug mask */
3562 FIRM_DBG_REGISTER(dbg, "firm.opt.combo");
3564 DB((dbg, LEVEL_1, "Doing COMBO for %+F\n", irg));
3566 obstack_init(&env.obst);
3567 env.worklist = NULL;
3571 #ifdef DEBUG_libfirm
3572 env.dbg_list = NULL;
3574 env.opcode2id_map = new_set(cmp_opcode, iro_Last * 4);
3575 env.type2id_map = pmap_create();
3576 env.kept_memory = NEW_ARR_F(ir_node *, 0);
3577 env.end_idx = get_opt_global_cse() ? 0 : -1;
3578 env.lambda_input = 0;
3581 /* options driving the optimization */
3582 env.commutative = 1;
3583 env.opt_unknown = 1;
3585 assure_irg_outs(irg);
3586 assure_cf_loop(irg);
3588 /* we have our own value_of function */
3589 set_value_of_func(get_node_tarval);
3591 set_compute_functions();
3592 DEBUG_ONLY(part_nr = 0);
3594 ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK | IR_RESOURCE_PHI_LIST);
3596 if (env.opt_unknown)
3597 tarval_UNKNOWN = tarval_top;
3599 tarval_UNKNOWN = tarval_bad;
3601 /* create the initial partition and place it on the work list */
3602 env.initial = new_partition(&env);
3603 add_to_worklist(env.initial, &env);
3604 irg_walk_graph(irg, create_initial_partitions, init_block_phis, &env);
3606 /* set the hook: from now, every node has a partition and a type */
3607 DEBUG_ONLY(set_dump_node_vcgattr_hook(dump_partition_hook));
3609 /* all nodes on the initial partition have type Top */
3610 env.initial->type_is_T_or_C = 1;
3612 /* Place the START Node's partition on cprop.
3613 Place the START Node on its local worklist. */
3614 initial_bl = get_irg_start_block(irg);
3615 start = get_irn_node(initial_bl);
3616 add_to_cprop(start, &env);
3620 if (env.worklist != NULL)
3622 } while (env.cprop != NULL || env.worklist != NULL);
3624 dump_all_partitions(&env);
3625 check_all_partitions(&env);
3628 dump_ir_block_graph(irg, "-partition");
3631 /* apply the result */
3633 /* check, which nodes must be kept */
3634 irg_walk_graph(irg, NULL, find_kept_memory, &env);
3636 /* kill unreachable control flow */
3637 irg_block_walk_graph(irg, NULL, apply_cf, &env);
3638 /* Kill keep-alives of dead blocks: this speeds up apply_result()
3639 * and fixes assertion because dead cf to dead blocks is NOT removed by
3641 apply_end(get_irg_end(irg), &env);
3642 irg_walk_graph(irg, NULL, apply_result, &env);
3644 len = ARR_LEN(env.kept_memory);
3646 add_memory_keeps(env.kept_memory, len);
3649 DB((dbg, LEVEL_1, "Unoptimized Control Flow left"));
3653 /* control flow might changed */
3654 set_irg_outs_inconsistent(irg);
3655 set_irg_extblk_inconsistent(irg);
3656 set_irg_doms_inconsistent(irg);
3657 set_irg_loopinfo_inconsistent(irg);
3660 ir_free_resources(irg, IR_RESOURCE_IRN_LINK | IR_RESOURCE_PHI_LIST);
3662 /* remove the partition hook */
3663 DEBUG_ONLY(set_dump_node_vcgattr_hook(NULL));
3665 DEL_ARR_F(env.kept_memory);
3666 pmap_destroy(env.type2id_map);
3667 del_set(env.opcode2id_map);
3668 obstack_free(&env.obst, NULL);
3670 /* restore value_of() default behavior */
3671 set_value_of_func(NULL);
3672 current_ir_graph = rem;