2 * Copyright (C) 1995-2011 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"
72 #include "irgraph_t.h"
79 #include "iropt_dbg.h"
83 #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 unsigned 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 */
116 unsigned uintVal;/**< for Builtin: the kind */
117 ir_node *block; /**< for Block: itself */
118 void *ptr; /**< generic pointer for hash/cmp */
123 * An entry in the list_map.
125 struct listmap_entry_t {
126 void *id; /**< The id. */
127 node_t *list; /**< The associated list for this id. */
128 listmap_entry_t *next; /**< Link to the next entry in the map. */
131 /** We must map id's to lists. */
132 typedef struct listmap_t {
133 set *map; /**< Map id's to listmap_entry_t's */
134 listmap_entry_t *values; /**< List of all values in the map. */
138 * A lattice element. Because we handle constants and symbolic constants different, we
139 * have to use this union.
150 ir_node *node; /**< The IR-node itself. */
151 list_head node_list; /**< Double-linked list of leader/follower entries. */
152 list_head cprop_list; /**< Double-linked partition.cprop list. */
153 partition_t *part; /**< points to the partition this node belongs to */
154 node_t *next; /**< Next node on local list (partition.touched, fallen). */
155 node_t *race_next; /**< Next node on race list. */
156 lattice_elem_t type; /**< The associated lattice element "type". */
157 int max_user_input; /**< Maximum input number of Def-Use edges. */
158 int next_edge; /**< Index of the next Def-Use edge to use. */
159 int n_followers; /**< Number of Follower in the outs set. */
160 unsigned on_touched:1; /**< Set, if this node is on the partition.touched set. */
161 unsigned on_cprop:1; /**< Set, if this node is on the partition.cprop list. */
162 unsigned on_fallen:1; /**< Set, if this node is on the fallen list. */
163 unsigned is_follower:1; /**< Set, if this node is a follower. */
164 unsigned flagged:2; /**< 2 Bits, set if this node was visited by race 1 or 2. */
168 * A partition containing congruent nodes.
171 list_head Leader; /**< The head of partition Leader node list. */
172 list_head Follower; /**< The head of partition Follower node list. */
173 list_head cprop; /**< The head of partition.cprop list. */
174 list_head cprop_X; /**< The head of partition.cprop (Cond nodes and its Projs) list. */
175 partition_t *wl_next; /**< Next entry in the work list if any. */
176 partition_t *touched_next; /**< Points to the next partition in the touched set. */
177 partition_t *cprop_next; /**< Points to the next partition in the cprop list. */
178 partition_t *split_next; /**< Points to the next partition in the list that must be split by split_by(). */
179 node_t *touched; /**< The partition.touched set of this partition. */
180 unsigned n_leader; /**< Number of entries in this partition.Leader. */
181 unsigned n_touched; /**< Number of entries in the partition.touched. */
182 int max_user_inputs; /**< Maximum number of user inputs of all entries. */
183 unsigned on_worklist:1; /**< Set, if this partition is in the work list. */
184 unsigned on_touched:1; /**< Set, if this partition is on the touched set. */
185 unsigned on_cprop:1; /**< Set, if this partition is on the cprop list. */
186 unsigned type_is_T_or_C:1;/**< Set, if all nodes in this partition have type Top or Constant. */
188 partition_t *dbg_next; /**< Link all partitions for debugging */
189 unsigned nr; /**< A unique number for (what-)mapping, >0. */
193 typedef struct environment_t {
194 struct obstack obst; /**< obstack to allocate data structures. */
195 partition_t *worklist; /**< The work list. */
196 partition_t *cprop; /**< The constant propagation list. */
197 partition_t *touched; /**< the touched set. */
198 partition_t *initial; /**< The initial partition. */
199 set *opcode2id_map; /**< The opcodeMode->id map. */
200 ir_node **kept_memory; /**< Array of memory nodes that must be kept. */
201 int end_idx; /**< -1 for local and 0 for global congruences. */
202 int lambda_input; /**< Captured argument for lambda_partition(). */
203 unsigned modified:1; /**< Set, if the graph was modified. */
204 unsigned unopt_cf:1; /**< If set, control flow is not optimized due to Unknown. */
205 /* options driving the optimization */
206 unsigned commutative:1; /**< Set, if commutation nodes should be handled specially. */
207 unsigned opt_unknown:1; /**< Set, if non-strict programs should be optimized. */
209 partition_t *dbg_list; /**< List of all partitions. */
213 /** Type of the what function. */
214 typedef void *(*what_func)(const node_t *node, environment_t *env);
216 #define get_irn_node(irn) ((node_t *)get_irn_link(irn))
217 #define set_irn_node(irn, node) set_irn_link(irn, node)
219 /* we do NOT use tarval_unreachable here, instead we use Top for this purpose */
220 #undef tarval_unreachable
221 #define tarval_unreachable tarval_top
224 /** The debug module handle. */
225 DEBUG_ONLY(static firm_dbg_module_t *dbg;)
227 /** The what reason. */
228 DEBUG_ONLY(static const char *what_reason;)
230 /** Next partition number. */
231 DEBUG_ONLY(static unsigned part_nr = 0);
233 /** The tarval returned by Unknown nodes: set to either tarval_bad OR tarval_top. */
234 static ir_tarval *tarval_UNKNOWN;
237 static node_t *identity(node_t *node);
239 #ifdef CHECK_PARTITIONS
243 static void check_partition(const partition_t *T)
248 list_for_each_entry(node_t, node, &T->Leader, node_list) {
249 assert(node->is_follower == 0);
250 assert(node->flagged == 0);
251 assert(node->part == T);
254 assert(n == T->n_leader);
256 list_for_each_entry(node_t, node, &T->Follower, node_list) {
257 assert(node->is_follower == 1);
258 assert(node->flagged == 0);
259 assert(node->part == T);
261 } /* check_partition */
264 * check that all leader nodes in the partition have the same opcode.
266 static void check_opcode(const partition_t *Z)
272 list_for_each_entry(node_t, node, &Z->Leader, node_list) {
273 ir_node *irn = node->node;
276 key.code = get_irn_opcode(irn);
277 key.mode = get_irn_mode(irn);
278 key.arity = get_irn_arity(irn);
282 switch (get_irn_opcode(irn)) {
284 key.u.proj = get_Proj_proj(irn);
287 key.u.ent = get_Sel_entity(irn);
290 key.u.intVal = get_Conv_strict(irn);
293 key.mode = get_Div_resmode(irn);
294 key.u.intVal = get_Div_no_remainder(irn);
297 key.mode = get_Mod_resmode(irn);
303 key.mode = get_Load_mode(irn);
306 key.u.intVal = get_Builtin_kind(irn);
313 assert((unsigned)key.code == get_irn_opcode(irn));
314 assert(key.arity == get_irn_arity(irn));
316 switch (get_irn_opcode(irn)) {
318 assert(key.mode == get_irn_mode(irn));
319 assert(key.u.proj == get_Proj_proj(irn));
322 assert(key.mode == get_irn_mode(irn));
323 assert(key.u.ent == get_Sel_entity(irn));
326 assert(key.mode == get_irn_mode(irn));
327 assert(key.u.intVal == get_Conv_strict(irn));
330 assert(key.mode == get_Div_resmode(irn));
331 assert(key.u.intVal == get_Div_no_remainder(irn));
334 assert(key.mode == get_Mod_resmode(irn));
337 assert(key.mode == get_irn_mode(irn));
338 assert(key.u.block == irn);
341 assert(key.mode == get_Load_mode(irn));
344 assert(key.mode == get_irn_mode(irn));
345 assert(key.u.intVal == (int) get_Builtin_kind(irn));
348 assert(key.mode == get_irn_mode(irn));
355 static void check_all_partitions(environment_t *env)
361 for (P = env->dbg_list; P != NULL; P = P->dbg_next) {
363 if (! P->type_is_T_or_C)
365 list_for_each_entry(node_t, node, &P->Follower, node_list) {
366 node_t *leader = identity(node);
368 assert(leader != node && leader->part == node->part);
379 static void do_check_list(const node_t *list, int ofs, const partition_t *Z)
384 #define NEXT(e) *((const node_t **)((char *)(e) + (ofs)))
385 for (e = list; e != NULL; e = NEXT(e)) {
386 assert(e->part == Z);
394 } /* ido_check_list */
397 * Check a local list.
399 static void check_list(const node_t *list, const partition_t *Z)
401 do_check_list(list, offsetof(node_t, next), Z);
405 #define check_partition(T)
406 #define check_list(list, Z)
407 #define check_all_partitions(env)
408 #endif /* CHECK_PARTITIONS */
411 static inline lattice_elem_t get_partition_type(const partition_t *X);
414 * Dump partition to output.
416 static void dump_partition(const char *msg, const partition_t *part)
420 lattice_elem_t type = get_partition_type(part);
422 DB((dbg, LEVEL_2, "%s part%u%s (%u, %+F) {\n ",
423 msg, part->nr, part->type_is_T_or_C ? "*" : "",
424 part->n_leader, type));
425 list_for_each_entry(node_t, node, &part->Leader, node_list) {
426 DB((dbg, LEVEL_2, "%s%+F", first ? "" : ", ", node->node));
429 if (! list_empty(&part->Follower)) {
430 DB((dbg, LEVEL_2, "\n---\n "));
432 list_for_each_entry(node_t, node, &part->Follower, node_list) {
433 DB((dbg, LEVEL_2, "%s%+F", first ? "" : ", ", node->node));
437 DB((dbg, LEVEL_2, "\n}\n"));
438 } /* dump_partition */
443 static void do_dump_list(const char *msg, const node_t *node, int ofs)
448 #define GET_LINK(p, ofs) *((const node_t **)((char *)(p) + (ofs)))
450 DB((dbg, LEVEL_3, "%s = {\n ", msg));
451 for (p = node; p != NULL; p = GET_LINK(p, ofs)) {
452 DB((dbg, LEVEL_3, "%s%+F", first ? "" : ", ", p->node));
455 DB((dbg, LEVEL_3, "\n}\n"));
463 static void dump_race_list(const char *msg, const node_t *list)
465 do_dump_list(msg, list, offsetof(node_t, race_next));
466 } /* dump_race_list */
469 * Dumps a local list.
471 static void dump_list(const char *msg, const node_t *list)
473 do_dump_list(msg, list, offsetof(node_t, next));
477 * Dump all partitions.
479 static void dump_all_partitions(const environment_t *env)
481 const partition_t *P;
483 DB((dbg, LEVEL_2, "All partitions\n===============\n"));
484 for (P = env->dbg_list; P != NULL; P = P->dbg_next)
485 dump_partition("", P);
486 } /* dump_all_partitions */
491 static void dump_split_list(const partition_t *list)
493 const partition_t *p;
495 DB((dbg, LEVEL_2, "Split by %s produced = {\n", what_reason));
496 for (p = list; p != NULL; p = p->split_next)
497 DB((dbg, LEVEL_2, "part%u, ", p->nr));
498 DB((dbg, LEVEL_2, "\n}\n"));
499 } /* dump_split_list */
502 * Dump partition and type for a node.
504 static int dump_partition_hook(FILE *F, ir_node *n, ir_node *local)
506 ir_node *irn = local != NULL ? local : n;
507 node_t *node = get_irn_node(irn);
509 ir_fprintf(F, "info2 : \"partition %u type %+F\"\n", node->part->nr, node->type);
511 } /* dump_partition_hook */
514 #define dump_partition(msg, part)
515 #define dump_race_list(msg, list)
516 #define dump_list(msg, list)
517 #define dump_all_partitions(env)
518 #define dump_split_list(list)
521 #if defined(VERIFY_MONOTONE) && defined (DEBUG_libfirm)
523 * Verify that a type transition is monotone
525 static void verify_type(const lattice_elem_t old_type, node_t *node)
527 if (old_type.tv == node->type.tv) {
531 if (old_type.tv == tarval_top) {
532 /* from Top down-to is always allowed */
535 if (node->type.tv == tarval_bottom || node->type.tv == tarval_reachable) {
539 panic("combo: wrong translation from %+F to %+F on node %+F", old_type, node->type, node->node);
543 #define verify_type(old_type, node)
547 * Compare two pointer values of a listmap.
549 static int listmap_cmp_ptr(const void *elt, const void *key, size_t size)
551 const listmap_entry_t *e1 = (listmap_entry_t*)elt;
552 const listmap_entry_t *e2 = (listmap_entry_t*)key;
555 return e1->id != e2->id;
556 } /* listmap_cmp_ptr */
559 * Initializes a listmap.
561 * @param map the listmap
563 static void listmap_init(listmap_t *map)
565 map->map = new_set(listmap_cmp_ptr, 16);
570 * Terminates a listmap.
572 * @param map the listmap
574 static void listmap_term(listmap_t *map)
580 * Return the associated listmap entry for a given id.
582 * @param map the listmap
583 * @param id the id to search for
585 * @return the associated listmap entry for the given id
587 static listmap_entry_t *listmap_find(listmap_t *map, void *id)
589 listmap_entry_t key, *entry;
594 entry = (listmap_entry_t*)set_insert(map->map, &key, sizeof(key), HASH_PTR(id));
596 if (entry->list == NULL) {
597 /* a new entry, put into the list */
598 entry->next = map->values;
605 * Calculate the hash value for an opcode map entry.
607 * @param entry an opcode map entry
609 * @return a hash value for the given opcode map entry
611 static unsigned opcode_hash(const opcode_key_t *entry)
613 return (unsigned)(PTR_TO_INT(entry->mode) * 9 + entry->code + entry->u.proj * 3 + HASH_PTR(entry->u.ptr) + entry->arity);
617 * Compare two entries in the opcode map.
619 static int cmp_opcode(const void *elt, const void *key, size_t size)
621 const opcode_key_t *o1 = (opcode_key_t*)elt;
622 const opcode_key_t *o2 = (opcode_key_t*)key;
625 return o1->code != o2->code || o1->mode != o2->mode ||
626 o1->arity != o2->arity ||
627 o1->u.proj != o2->u.proj ||
628 o1->u.intVal != o2->u.intVal || /* this already checks uIntVal */
629 o1->u.ptr != o2->u.ptr;
633 * Compare two Def-Use edges for input position.
635 static int cmp_def_use_edge(const void *a, const void *b)
637 const ir_def_use_edge *ea = (const ir_def_use_edge*)a;
638 const ir_def_use_edge *eb = (const ir_def_use_edge*)b;
640 /* no overrun, because range is [-1, MAXINT] */
641 return ea->pos - eb->pos;
642 } /* cmp_def_use_edge */
645 * We need the Def-Use edges sorted.
647 static void sort_irn_outs(node_t *node)
649 ir_node *irn = node->node;
650 int n_outs = get_irn_n_outs(irn);
653 qsort(&irn->out[1], n_outs, sizeof(irn->out[0]), cmp_def_use_edge);
655 node->max_user_input = irn->out[n_outs].pos;
656 } /* sort_irn_outs */
659 * Return the type of a node.
661 * @param irn an IR-node
663 * @return the associated type of this node
665 static inline lattice_elem_t get_node_type(const ir_node *irn)
667 return get_irn_node(irn)->type;
668 } /* get_node_type */
671 * Return the tarval of a node.
673 * @param irn an IR-node
675 * @return the associated type of this node
677 static inline ir_tarval *get_node_tarval(const ir_node *irn)
679 lattice_elem_t type = get_node_type(irn);
681 if (is_tarval(type.tv))
683 return tarval_bottom;
684 } /* get_node_type */
687 * Add a partition to the worklist.
689 static inline void add_to_worklist(partition_t *X, environment_t *env)
691 assert(X->on_worklist == 0);
692 DB((dbg, LEVEL_2, "Adding part%d to worklist\n", X->nr));
693 X->wl_next = env->worklist;
696 } /* add_to_worklist */
699 * Create a new empty partition.
701 * @param env the environment
703 * @return a newly allocated partition
705 static inline partition_t *new_partition(environment_t *env)
707 partition_t *part = OALLOC(&env->obst, partition_t);
709 INIT_LIST_HEAD(&part->Leader);
710 INIT_LIST_HEAD(&part->Follower);
711 INIT_LIST_HEAD(&part->cprop);
712 INIT_LIST_HEAD(&part->cprop_X);
713 part->wl_next = NULL;
714 part->touched_next = NULL;
715 part->cprop_next = NULL;
716 part->split_next = NULL;
717 part->touched = NULL;
720 part->max_user_inputs = 0;
721 part->on_worklist = 0;
722 part->on_touched = 0;
724 part->type_is_T_or_C = 0;
726 part->dbg_next = env->dbg_list;
727 env->dbg_list = part;
728 part->nr = part_nr++;
732 } /* new_partition */
735 * Get the first node from a partition.
737 static inline node_t *get_first_node(const partition_t *X)
739 return list_entry(X->Leader.next, node_t, node_list);
740 } /* get_first_node */
743 * Return the type of a partition (assuming partition is non-empty and
744 * all elements have the same type).
746 * @param X a partition
748 * @return the type of the first element of the partition
750 static inline lattice_elem_t get_partition_type(const partition_t *X)
752 const node_t *first = get_first_node(X);
754 } /* get_partition_type */
757 * Creates a partition node for the given IR-node and place it
758 * into the given partition.
760 * @param irn an IR-node
761 * @param part a partition to place the node in
762 * @param env the environment
764 * @return the created node
766 static node_t *create_partition_node(ir_node *irn, partition_t *part, environment_t *env)
768 /* create a partition node and place it in the partition */
769 node_t *node = OALLOC(&env->obst, node_t);
771 INIT_LIST_HEAD(&node->node_list);
772 INIT_LIST_HEAD(&node->cprop_list);
776 node->race_next = NULL;
777 node->type.tv = tarval_top;
778 node->max_user_input = 0;
780 node->n_followers = 0;
781 node->on_touched = 0;
784 node->is_follower = 0;
786 set_irn_node(irn, node);
788 list_add_tail(&node->node_list, &part->Leader);
792 } /* create_partition_node */
795 * Pre-Walker, initialize all Nodes' type to U or top and place
796 * all nodes into the TOP partition.
798 static void create_initial_partitions(ir_node *irn, void *ctx)
800 environment_t *env = (environment_t*)ctx;
801 partition_t *part = env->initial;
804 node = create_partition_node(irn, part, env);
806 if (node->max_user_input > part->max_user_inputs)
807 part->max_user_inputs = node->max_user_input;
810 set_Block_phis(irn, NULL);
812 } /* create_initial_partitions */
815 * Post-Walker, collect all Block-Phi lists, set Cond.
817 static void init_block_phis(ir_node *irn, void *ctx)
822 add_Block_phi(get_nodes_block(irn), irn);
824 } /* init_block_phis */
827 * Add a node to the entry.partition.touched set and
828 * node->partition to the touched set if not already there.
831 * @param env the environment
833 static inline void add_to_touched(node_t *y, environment_t *env)
835 if (y->on_touched == 0) {
836 partition_t *part = y->part;
838 y->next = part->touched;
843 if (part->on_touched == 0) {
844 part->touched_next = env->touched;
846 part->on_touched = 1;
849 check_list(part->touched, part);
851 } /* add_to_touched */
854 * Place a node on the cprop list.
857 * @param env the environment
859 static void add_to_cprop(node_t *y, environment_t *env)
863 /* Add y to y.partition.cprop. */
864 if (y->on_cprop == 0) {
865 partition_t *Y = y->part;
866 ir_node *irn = y->node;
868 /* place Conds and all its Projs on the cprop_X list */
869 if (is_Cond(skip_Proj(irn)))
870 list_add_tail(&y->cprop_list, &Y->cprop_X);
872 list_add_tail(&y->cprop_list, &Y->cprop);
875 DB((dbg, LEVEL_3, "Add %+F to part%u.cprop\n", y->node, Y->nr));
877 /* place its partition on the cprop list */
878 if (Y->on_cprop == 0) {
879 Y->cprop_next = env->cprop;
885 if (get_irn_mode(irn) == mode_T) {
886 /* mode_T nodes always produce tarval_bottom, so we must explicitly
887 add it's Proj's to get constant evaluation to work */
890 for (i = get_irn_n_outs(irn) - 1; i >= 0; --i) {
891 node_t *proj = get_irn_node(get_irn_out(irn, i));
893 add_to_cprop(proj, env);
895 } else if (is_Block(irn)) {
896 /* Due to the way we handle Phi's, we must place all Phis of a block on the list
897 * if someone placed the block. The Block is only placed if the reachability
898 * changes, and this must be re-evaluated in compute_Phi(). */
900 for (phi = get_Block_phis(irn); phi != NULL; phi = get_Phi_next(phi)) {
901 node_t *p = get_irn_node(phi);
902 add_to_cprop(p, env);
908 * Update the worklist: If Z is on worklist then add Z' to worklist.
909 * Else add the smaller of Z and Z' to worklist.
911 * @param Z the Z partition
912 * @param Z_prime the Z' partition, a previous part of Z
913 * @param env the environment
915 static void update_worklist(partition_t *Z, partition_t *Z_prime, environment_t *env)
917 if (Z->on_worklist || Z_prime->n_leader < Z->n_leader) {
918 add_to_worklist(Z_prime, env);
920 add_to_worklist(Z, env);
922 } /* update_worklist */
925 * Make all inputs to x no longer be F.def_use edges.
929 static void move_edges_to_leader(node_t *x)
931 ir_node *irn = x->node;
934 for (i = get_irn_arity(irn) - 1; i >= 0; --i) {
935 node_t *pred = get_irn_node(get_irn_n(irn, i));
940 n = get_irn_n_outs(p);
941 for (j = 1; j <= pred->n_followers; ++j) {
942 if (p->out[j].pos == i && p->out[j].use == irn) {
943 /* found a follower edge to x, move it to the Leader */
944 ir_def_use_edge edge = p->out[j];
946 /* remove this edge from the Follower set */
947 p->out[j] = p->out[pred->n_followers];
950 /* sort it into the leader set */
951 for (k = pred->n_followers + 2; k <= n; ++k) {
952 if (p->out[k].pos >= edge.pos)
954 p->out[k - 1] = p->out[k];
956 /* place the new edge here */
957 p->out[k - 1] = edge;
959 /* edge found and moved */
964 } /* move_edges_to_leader */
967 * Split a partition that has NO followers by a local list.
969 * @param Z partition to split
970 * @param g a (non-empty) node list
971 * @param env the environment
973 * @return a new partition containing the nodes of g
975 static partition_t *split_no_followers(partition_t *Z, node_t *g, environment_t *env)
977 partition_t *Z_prime;
982 dump_partition("Splitting ", Z);
983 dump_list("by list ", g);
987 /* Remove g from Z. */
988 for (node = g; node != NULL; node = node->next) {
989 assert(node->part == Z);
990 list_del(&node->node_list);
993 assert(n < Z->n_leader);
996 /* Move g to a new partition, Z'. */
997 Z_prime = new_partition(env);
999 for (node = g; node != NULL; node = node->next) {
1000 list_add_tail(&node->node_list, &Z_prime->Leader);
1001 node->part = Z_prime;
1002 if (node->max_user_input > max_input)
1003 max_input = node->max_user_input;
1005 Z_prime->max_user_inputs = max_input;
1006 Z_prime->n_leader = n;
1009 check_partition(Z_prime);
1011 /* for now, copy the type info tag, it will be adjusted in split_by(). */
1012 Z_prime->type_is_T_or_C = Z->type_is_T_or_C;
1014 update_worklist(Z, Z_prime, env);
1016 dump_partition("Now ", Z);
1017 dump_partition("Created new ", Z_prime);
1019 } /* split_no_followers */
1022 * Make the Follower -> Leader transition for a node.
1026 static void follower_to_leader(node_t *n)
1028 assert(n->is_follower == 1);
1030 DB((dbg, LEVEL_2, "%+F make the follower -> leader transition\n", n->node));
1032 move_edges_to_leader(n);
1033 list_del(&n->node_list);
1034 list_add_tail(&n->node_list, &n->part->Leader);
1035 ++n->part->n_leader;
1036 } /* follower_to_leader */
1039 * The environment for one race step.
1041 typedef struct step_env {
1042 node_t *initial; /**< The initial node list. */
1043 node_t *unwalked; /**< The unwalked node list. */
1044 node_t *walked; /**< The walked node list. */
1045 int index; /**< Next index of Follower use_def edge. */
1046 unsigned side; /**< side number. */
1050 * Return non-zero, if a input is a real follower
1052 * @param irn the node to check
1053 * @param input number of the input
1055 static int is_real_follower(const ir_node *irn, int input)
1059 switch (get_irn_opcode(irn)) {
1062 /* ignore the Confirm bound input */
1068 /* ignore the Mux sel input */
1073 /* dead inputs are not follower edges */
1074 ir_node *block = get_nodes_block(irn);
1075 node_t *pred = get_irn_node(get_Block_cfgpred(block, input));
1077 if (pred->type.tv == tarval_unreachable)
1087 /* only a Sub x,0 / Shift x,0 might be a follower */
1094 pred = get_irn_node(get_irn_n(irn, input));
1095 if (is_tarval(pred->type.tv) && tarval_is_null(pred->type.tv))
1099 pred = get_irn_node(get_irn_n(irn, input));
1100 if (is_tarval(pred->type.tv) && tarval_is_one(pred->type.tv))
1104 pred = get_irn_node(get_irn_n(irn, input));
1105 if (is_tarval(pred->type.tv) && tarval_is_all_one(pred->type.tv))
1109 assert(!"opcode not implemented yet");
1113 } /* is_real_follower */
1116 * Do one step in the race.
1118 static int step(step_env *env)
1122 if (env->initial != NULL) {
1123 /* Move node from initial to unwalked */
1125 env->initial = n->race_next;
1127 n->race_next = env->unwalked;
1133 while (env->unwalked != NULL) {
1134 /* let n be the first node in unwalked */
1136 while (env->index < n->n_followers) {
1137 const ir_def_use_edge *edge = &n->node->out[1 + env->index];
1139 /* let m be n.F.def_use[index] */
1140 node_t *m = get_irn_node(edge->use);
1142 assert(m->is_follower);
1144 * Some inputs, like the get_Confirm_bound are NOT
1145 * real followers, sort them out.
1147 if (! is_real_follower(m->node, edge->pos)) {
1153 /* only followers from our partition */
1154 if (m->part != n->part)
1157 if ((m->flagged & env->side) == 0) {
1158 m->flagged |= env->side;
1160 if (m->flagged != 3) {
1161 /* visited the first time */
1162 /* add m to unwalked not as first node (we might still need to
1163 check for more follower node */
1164 m->race_next = n->race_next;
1168 /* else already visited by the other side and on the other list */
1171 /* move n to walked */
1172 env->unwalked = n->race_next;
1173 n->race_next = env->walked;
1181 * Clear the flags from a list and check for
1182 * nodes that where touched from both sides.
1184 * @param list the list
1186 static int clear_flags(node_t *list)
1191 for (n = list; n != NULL; n = n->race_next) {
1192 if (n->flagged == 3) {
1193 /* we reach a follower from both sides, this will split congruent
1194 * inputs and make it a leader. */
1195 follower_to_leader(n);
1204 * Split a partition by a local list using the race.
1206 * @param pX pointer to the partition to split, might be changed!
1207 * @param gg a (non-empty) node list
1208 * @param env the environment
1210 * @return a new partition containing the nodes of gg
1212 static partition_t *split(partition_t **pX, node_t *gg, environment_t *env)
1214 partition_t *X = *pX;
1215 partition_t *X_prime;
1218 node_t *g, *h, *node, *t;
1219 int max_input, transitions, winner, shf;
1221 DEBUG_ONLY(static int run = 0;)
1223 DB((dbg, LEVEL_2, "Run %d ", run++));
1224 if (list_empty(&X->Follower)) {
1225 /* if the partition has NO follower, we can use the fast
1226 splitting algorithm. */
1227 return split_no_followers(X, gg, env);
1229 /* else do the race */
1231 dump_partition("Splitting ", X);
1232 dump_list("by list ", gg);
1234 INIT_LIST_HEAD(&tmp);
1236 /* Remove gg from X.Leader and put into g */
1238 for (node = gg; node != NULL; node = node->next) {
1239 assert(node->part == X);
1240 assert(node->is_follower == 0);
1242 list_del(&node->node_list);
1243 list_add_tail(&node->node_list, &tmp);
1244 node->race_next = g;
1249 list_for_each_entry(node_t, node, &X->Leader, node_list) {
1250 node->race_next = h;
1253 /* restore X.Leader */
1254 list_splice(&tmp, &X->Leader);
1256 senv[0].initial = g;
1257 senv[0].unwalked = NULL;
1258 senv[0].walked = NULL;
1262 senv[1].initial = h;
1263 senv[1].unwalked = NULL;
1264 senv[1].walked = NULL;
1269 * Some informations on the race that are not stated clearly in Click's
1271 * 1) A follower stays on the side that reach him first.
1272 * 2) If the other side reches a follower, if will be converted to
1273 * a leader. /This must be done after the race is over, else the
1274 * edges we are iterating on are renumbered./
1275 * 3) /New leader might end up on both sides./
1276 * 4) /If one side ends up with new Leaders, we must ensure that
1277 * they can split out by opcode, hence we have to put _every_
1278 * partition with new Leader nodes on the cprop list, as
1279 * opcode splitting is done by split_by() at the end of
1280 * constant propagation./
1283 if (step(&senv[0])) {
1287 if (step(&senv[1])) {
1292 assert(senv[winner].initial == NULL);
1293 assert(senv[winner].unwalked == NULL);
1295 /* clear flags from walked/unwalked */
1297 transitions = clear_flags(senv[0].unwalked) << shf;
1298 transitions |= clear_flags(senv[0].walked) << shf;
1300 transitions |= clear_flags(senv[1].unwalked) << shf;
1301 transitions |= clear_flags(senv[1].walked) << shf;
1303 dump_race_list("winner ", senv[winner].walked);
1305 /* Move walked_{winner} to a new partition, X'. */
1306 X_prime = new_partition(env);
1309 for (node = senv[winner].walked; node != NULL; node = node->race_next) {
1310 list_del(&node->node_list);
1311 node->part = X_prime;
1312 if (node->is_follower) {
1313 list_add_tail(&node->node_list, &X_prime->Follower);
1315 list_add_tail(&node->node_list, &X_prime->Leader);
1318 if (node->max_user_input > max_input)
1319 max_input = node->max_user_input;
1321 X_prime->n_leader = n;
1322 X_prime->max_user_inputs = max_input;
1323 X->n_leader -= X_prime->n_leader;
1325 /* for now, copy the type info tag, it will be adjusted in split_by(). */
1326 X_prime->type_is_T_or_C = X->type_is_T_or_C;
1329 * Even if a follower was not checked by both sides, it might have
1330 * loose its congruence, so we need to check this case for all follower.
1332 list_for_each_entry_safe(node_t, node, t, &X_prime->Follower, node_list) {
1333 if (identity(node) == node) {
1334 follower_to_leader(node);
1340 check_partition(X_prime);
1342 /* X' is the smaller part */
1343 add_to_worklist(X_prime, env);
1346 * If there where follower to leader transitions, ensure that the nodes
1347 * can be split out if necessary.
1349 if (transitions & 1) {
1350 /* place winner partition on the cprop list */
1351 if (X_prime->on_cprop == 0) {
1352 X_prime->cprop_next = env->cprop;
1353 env->cprop = X_prime;
1354 X_prime->on_cprop = 1;
1357 if (transitions & 2) {
1358 /* place other partition on the cprop list */
1359 if (X->on_cprop == 0) {
1360 X->cprop_next = env->cprop;
1366 dump_partition("Now ", X);
1367 dump_partition("Created new ", X_prime);
1369 /* we have to ensure that the partition containing g is returned */
1379 * Returns non-zero if the i'th input of a Phi node is live.
1381 * @param phi a Phi-node
1382 * @param i an input number
1384 * @return non-zero if the i'th input of the given Phi node is live
1386 static int is_live_input(ir_node *phi, int i)
1389 ir_node *block = get_nodes_block(phi);
1390 ir_node *pred = get_Block_cfgpred(block, i);
1391 lattice_elem_t type = get_node_type(pred);
1393 return type.tv != tarval_unreachable;
1395 /* else it's the control input, always live */
1397 } /* is_live_input */
1400 * Return non-zero if a type is a constant.
1402 static int is_constant_type(lattice_elem_t type)
1404 if (type.tv != tarval_bottom && type.tv != tarval_top)
1407 } /* is_constant_type */
1410 * Check whether a type is neither Top or a constant.
1411 * Note: U is handled like Top here, R is a constant.
1413 * @param type the type to check
1415 static int type_is_neither_top_nor_const(const lattice_elem_t type)
1417 if (is_tarval(type.tv)) {
1418 if (type.tv == tarval_top)
1420 if (tarval_is_constant(type.tv))
1427 } /* type_is_neither_top_nor_const */
1430 * Collect nodes to the touched list.
1432 * @param list the list which contains the nodes that must be evaluated
1433 * @param idx the index of the def_use edge to evaluate
1434 * @param env the environment
1436 static void collect_touched(list_head *list, int idx, environment_t *env)
1439 int end_idx = env->end_idx;
1441 list_for_each_entry(node_t, x, list, node_list) {
1445 /* leader edges start AFTER follower edges */
1446 x->next_edge = x->n_followers + 1;
1448 num_edges = get_irn_n_outs(x->node);
1450 /* for all edges in x.L.def_use_{idx} */
1451 while (x->next_edge <= num_edges) {
1452 const ir_def_use_edge *edge = &x->node->out[x->next_edge];
1455 /* check if we have necessary edges */
1456 if (edge->pos > idx)
1463 /* only non-commutative nodes */
1464 if (env->commutative &&
1465 (idx == 0 || idx == 1) && is_op_commutative(get_irn_op(succ)))
1468 /* ignore the "control input" for non-pinned nodes
1469 if we are running in GCSE mode */
1470 if (idx < end_idx && get_irn_pinned(succ) != op_pin_state_pinned)
1473 y = get_irn_node(succ);
1474 assert(get_irn_n(succ, idx) == x->node);
1476 /* ignore block edges touching followers */
1477 if (idx == -1 && y->is_follower)
1480 if (is_constant_type(y->type)) {
1481 unsigned code = get_irn_opcode(succ);
1482 if (code == iro_Sub || code == iro_Cmp)
1483 add_to_cprop(y, env);
1486 /* Partitions of constants should not be split simply because their Nodes have unequal
1487 functions or incongruent inputs. */
1488 if (type_is_neither_top_nor_const(y->type) &&
1489 (! is_Phi(y->node) || is_live_input(y->node, idx))) {
1490 add_to_touched(y, env);
1494 } /* collect_touched */
1497 * Collect commutative nodes to the touched list.
1499 * @param list the list which contains the nodes that must be evaluated
1500 * @param env the environment
1502 static void collect_commutative_touched(list_head *list, environment_t *env)
1506 list_for_each_entry(node_t, x, list, node_list) {
1509 num_edges = get_irn_n_outs(x->node);
1511 x->next_edge = x->n_followers + 1;
1513 /* for all edges in x.L.def_use_{idx} */
1514 while (x->next_edge <= num_edges) {
1515 const ir_def_use_edge *edge = &x->node->out[x->next_edge];
1518 /* check if we have necessary edges */
1528 /* only commutative nodes */
1529 if (!is_op_commutative(get_irn_op(succ)))
1532 y = get_irn_node(succ);
1533 if (is_constant_type(y->type)) {
1534 unsigned code = get_irn_opcode(succ);
1535 if (code == iro_Eor)
1536 add_to_cprop(y, env);
1539 /* Partitions of constants should not be split simply because their Nodes have unequal
1540 functions or incongruent inputs. */
1541 if (type_is_neither_top_nor_const(y->type)) {
1542 add_to_touched(y, env);
1546 } /* collect_commutative_touched */
1549 * Split the partitions if caused by the first entry on the worklist.
1551 * @param env the environment
1553 static void cause_splits(environment_t *env)
1555 partition_t *X, *Z, *N;
1558 /* remove the first partition from the worklist */
1560 env->worklist = X->wl_next;
1563 dump_partition("Cause_split: ", X);
1565 if (env->commutative) {
1566 /* handle commutative nodes first */
1568 /* empty the touched set: already done, just clear the list */
1569 env->touched = NULL;
1571 collect_commutative_touched(&X->Leader, env);
1572 collect_commutative_touched(&X->Follower, env);
1574 for (Z = env->touched; Z != NULL; Z = N) {
1576 node_t *touched = Z->touched;
1577 node_t *touched_aa = NULL;
1578 node_t *touched_ab = NULL;
1579 unsigned n_touched_aa = 0;
1580 unsigned n_touched_ab = 0;
1582 assert(Z->touched != NULL);
1584 /* beware, split might change Z */
1585 N = Z->touched_next;
1587 /* remove it from the touched set */
1590 /* Empty local Z.touched. */
1591 for (e = touched; e != NULL; e = n) {
1592 node_t *left = get_irn_node(get_irn_n(e->node, 0));
1593 node_t *right = get_irn_node(get_irn_n(e->node, 1));
1595 assert(e->is_follower == 0);
1600 * Note: op(a, a) is NOT congruent to op(a, b).
1601 * So, we must split the touched list.
1603 if (left->part == right->part) {
1604 e->next = touched_aa;
1608 e->next = touched_ab;
1613 assert(n_touched_aa + n_touched_ab == Z->n_touched);
1617 if (0 < n_touched_aa && n_touched_aa < Z->n_leader) {
1618 partition_t *Z_prime = Z;
1619 DB((dbg, LEVEL_2, "Split part%d by touched_aa\n", Z_prime->nr));
1620 split(&Z_prime, touched_aa, env);
1622 assert(n_touched_aa <= Z->n_leader);
1624 if (0 < n_touched_ab && n_touched_ab < Z->n_leader) {
1625 partition_t *Z_prime = Z;
1626 DB((dbg, LEVEL_2, "Split part%d by touched_ab\n", Z_prime->nr));
1627 split(&Z_prime, touched_ab, env);
1629 assert(n_touched_ab <= Z->n_leader);
1633 /* combine temporary leader and follower list */
1634 for (idx = -1; idx <= X->max_user_inputs; ++idx) {
1635 /* empty the touched set: already done, just clear the list */
1636 env->touched = NULL;
1638 collect_touched(&X->Leader, idx, env);
1639 collect_touched(&X->Follower, idx, env);
1641 for (Z = env->touched; Z != NULL; Z = N) {
1643 node_t *touched = Z->touched;
1644 unsigned n_touched = Z->n_touched;
1646 assert(Z->touched != NULL);
1648 /* beware, split might change Z */
1649 N = Z->touched_next;
1651 /* remove it from the touched set */
1654 /* Empty local Z.touched. */
1655 for (e = touched; e != NULL; e = e->next) {
1656 assert(e->is_follower == 0);
1662 if (0 < n_touched && n_touched < Z->n_leader) {
1663 DB((dbg, LEVEL_2, "Split part%d by touched\n", Z->nr));
1664 split(&Z, touched, env);
1666 assert(n_touched <= Z->n_leader);
1669 } /* cause_splits */
1672 * Implements split_by_what(): Split a partition by characteristics given
1673 * by the what function.
1675 * @param X the partition to split
1676 * @param What a function returning an Id for every node of the partition X
1677 * @param P a list to store the result partitions
1678 * @param env the environment
1682 static partition_t *split_by_what(partition_t *X, what_func What,
1683 partition_t **P, environment_t *env)
1687 listmap_entry_t *iter;
1690 /* Let map be an empty mapping from the range of What to (local) list of Nodes. */
1692 list_for_each_entry(node_t, x, &X->Leader, node_list) {
1693 void *id = What(x, env);
1694 listmap_entry_t *entry;
1697 /* input not allowed, ignore */
1700 /* Add x to map[What(x)]. */
1701 entry = listmap_find(&map, id);
1702 x->next = entry->list;
1705 /* Let P be a set of Partitions. */
1707 /* for all sets S except one in the range of map do */
1708 for (iter = map.values; iter != NULL; iter = iter->next) {
1709 if (iter->next == NULL) {
1710 /* this is the last entry, ignore */
1715 /* Add SPLIT( X, S ) to P. */
1716 DB((dbg, LEVEL_2, "Split part%d by WHAT = %s\n", X->nr, what_reason));
1717 R = split(&X, S, env);
1727 } /* split_by_what */
1729 /** lambda n.(n.type) */
1730 static void *lambda_type(const node_t *node, environment_t *env)
1733 return node->type.tv;
1736 /** lambda n.(n.opcode) */
1737 static void *lambda_opcode(const node_t *node, environment_t *env)
1739 opcode_key_t key, *entry;
1740 ir_node *irn = node->node;
1742 key.code = get_irn_opcode(irn);
1743 key.mode = get_irn_mode(irn);
1744 key.arity = get_irn_arity(irn);
1748 switch (get_irn_opcode(irn)) {
1750 key.u.proj = get_Proj_proj(irn);
1753 key.u.ent = get_Sel_entity(irn);
1756 key.u.intVal = get_Conv_strict(irn);
1759 key.u.intVal = get_Div_no_remainder(irn);
1763 * Some ugliness here: Two Blocks having the same
1764 * IJmp predecessor would be congruent, which of course is wrong.
1765 * We fix it by never letting blocks be congruent
1766 * which cannot be detected by combo either.
1771 key.mode = get_Load_mode(irn);
1774 key.u.intVal = get_Builtin_kind(irn);
1780 entry = (opcode_key_t*)set_insert(env->opcode2id_map, &key, sizeof(key), opcode_hash(&key));
1782 } /* lambda_opcode */
1784 /** lambda n.(n[i].partition) */
1785 static void *lambda_partition(const node_t *node, environment_t *env)
1787 ir_node *skipped = skip_Proj(node->node);
1790 int i = env->lambda_input;
1792 if (i >= get_irn_arity(node->node)) {
1794 * We are outside the allowed range: This can happen even
1795 * if we have split by opcode first: doing so might move Followers
1796 * to Leaders and those will have a different opcode!
1797 * Note that in this case the partition is on the cprop list and will be
1803 /* ignore the "control input" for non-pinned nodes
1804 if we are running in GCSE mode */
1805 if (i < env->end_idx && get_irn_pinned(skipped) != op_pin_state_pinned)
1808 pred = i == -1 ? get_irn_n(skipped, i) : get_irn_n(node->node, i);
1809 p = get_irn_node(pred);
1811 } /* lambda_partition */
1813 /** lambda n.(n[i].partition) for commutative nodes */
1814 static void *lambda_commutative_partition(const node_t *node, environment_t *env)
1816 ir_node *irn = node->node;
1817 ir_node *skipped = skip_Proj(irn);
1818 ir_node *pred, *left, *right;
1820 partition_t *pl, *pr;
1821 int i = env->lambda_input;
1823 if (i >= get_irn_arity(node->node)) {
1825 * We are outside the allowed range: This can happen even
1826 * if we have split by opcode first: doing so might move Followers
1827 * to Leaders and those will have a different opcode!
1828 * Note that in this case the partition is on the cprop list and will be
1834 /* ignore the "control input" for non-pinned nodes
1835 if we are running in GCSE mode */
1836 if (i < env->end_idx && get_irn_pinned(skipped) != op_pin_state_pinned)
1840 pred = get_irn_n(skipped, i);
1841 p = get_irn_node(pred);
1845 if (is_op_commutative(get_irn_op(irn))) {
1846 /* normalize partition order by returning the "smaller" on input 0,
1847 the "bigger" on input 1. */
1848 left = get_binop_left(irn);
1849 pl = get_irn_node(left)->part;
1850 right = get_binop_right(irn);
1851 pr = get_irn_node(right)->part;
1854 return pl < pr ? pl : pr;
1856 return pl > pr ? pl : pr;
1858 /* a not split out Follower */
1859 pred = get_irn_n(irn, i);
1860 p = get_irn_node(pred);
1864 } /* lambda_commutative_partition */
1867 * Returns true if a type is a constant (and NOT Top
1870 static int is_con(const lattice_elem_t type)
1872 /* be conservative */
1873 if (is_tarval(type.tv))
1874 return tarval_is_constant(type.tv);
1875 return is_entity(type.sym.entity_p);
1879 * Implements split_by().
1881 * @param X the partition to split
1882 * @param env the environment
1884 static void split_by(partition_t *X, environment_t *env)
1886 partition_t *I, *P = NULL;
1889 dump_partition("split_by", X);
1891 if (X->n_leader == 1) {
1892 /* we have only one leader, no need to split, just check it's type */
1893 node_t *x = get_first_node(X);
1894 X->type_is_T_or_C = x->type.tv == tarval_top || is_con(x->type);
1898 DEBUG_ONLY(what_reason = "lambda n.(n.type)";)
1899 P = split_by_what(X, lambda_type, &P, env);
1902 /* adjust the type tags, we have split partitions by type */
1903 for (I = P; I != NULL; I = I->split_next) {
1904 node_t *x = get_first_node(I);
1905 I->type_is_T_or_C = x->type.tv == tarval_top || is_con(x->type);
1912 if (Y->n_leader > 1) {
1913 /* we do not want split the TOP or constant partitions */
1914 if (! Y->type_is_T_or_C) {
1915 partition_t *Q = NULL;
1917 DEBUG_ONLY(what_reason = "lambda n.(n.opcode)";)
1918 Q = split_by_what(Y, lambda_opcode, &Q, env);
1925 if (Z->n_leader > 1) {
1926 const node_t *first = get_first_node(Z);
1927 int arity = get_irn_arity(first->node);
1929 what_func what = lambda_partition;
1930 DEBUG_ONLY(char buf[64];)
1932 if (env->commutative && is_op_commutative(get_irn_op(first->node)))
1933 what = lambda_commutative_partition;
1936 * BEWARE: during splitting by input 2 for instance we might
1937 * create new partitions which are different by input 1, so collect
1938 * them and split further.
1940 Z->split_next = NULL;
1943 for (input = arity - 1; input >= -1; --input) {
1945 partition_t *Z_prime = R;
1948 if (Z_prime->n_leader > 1) {
1949 env->lambda_input = input;
1950 DEBUG_ONLY(snprintf(buf, sizeof(buf), "lambda n.(n[%d].partition)", input);)
1951 DEBUG_ONLY(what_reason = buf;)
1952 S = split_by_what(Z_prime, what, &S, env);
1955 Z_prime->split_next = S;
1958 } while (R != NULL);
1963 } while (Q != NULL);
1966 } while (P != NULL);
1970 * (Re-)compute the type for a given node.
1972 * @param node the node
1974 static void default_compute(node_t *node)
1977 ir_node *irn = node->node;
1979 /* if any of the data inputs have type top, the result is type top */
1980 for (i = get_irn_arity(irn) - 1; i >= 0; --i) {
1981 ir_node *pred = get_irn_n(irn, i);
1982 node_t *p = get_irn_node(pred);
1984 if (p->type.tv == tarval_top) {
1985 node->type.tv = tarval_top;
1990 if (get_irn_mode(node->node) == mode_X)
1991 node->type.tv = tarval_reachable;
1993 node->type.tv = computed_value(irn);
1994 } /* default_compute */
1997 * (Re-)compute the type for a Block node.
1999 * @param node the node
2001 static void compute_Block(node_t *node)
2004 ir_node *block = node->node;
2006 if (block == get_irg_start_block(current_ir_graph) || has_Block_entity(block)) {
2007 /* start block and labelled blocks are always reachable */
2008 node->type.tv = tarval_reachable;
2012 for (i = get_Block_n_cfgpreds(block) - 1; i >= 0; --i) {
2013 node_t *pred = get_irn_node(get_Block_cfgpred(block, i));
2015 if (pred->type.tv == tarval_reachable) {
2016 /* A block is reachable, if at least of predecessor is reachable. */
2017 node->type.tv = tarval_reachable;
2021 node->type.tv = tarval_top;
2022 } /* compute_Block */
2025 * (Re-)compute the type for a Bad node.
2027 * @param node the node
2029 static void compute_Bad(node_t *node)
2031 /* Bad nodes ALWAYS compute Top */
2032 node->type.tv = tarval_top;
2036 * (Re-)compute the type for an Unknown node.
2038 * @param node the node
2040 static void compute_Unknown(node_t *node)
2042 /* While Unknown nodes should compute Top this is dangerous:
2043 * a Top input to a Cond would lead to BOTH control flows unreachable.
2044 * While this is correct in the given semantics, it would destroy the Firm
2047 * It would be safe to compute Top IF it can be assured, that only Cmp
2048 * nodes are inputs to Conds. We check that first.
2049 * This is the way Frontends typically build Firm, but some optimizations
2050 * (jump threading for instance) might replace them by Phib's...
2052 node->type.tv = tarval_UNKNOWN;
2053 } /* compute_Unknown */
2056 * (Re-)compute the type for a Jmp node.
2058 * @param node the node
2060 static void compute_Jmp(node_t *node)
2062 node_t *block = get_irn_node(get_nodes_block(node->node));
2064 node->type = block->type;
2068 * (Re-)compute the type for the Return node.
2070 * @param node the node
2072 static void compute_Return(node_t *node)
2074 /* The Return node is NOT dead if it is in a reachable block.
2075 * This is already checked in compute(). so we can return
2076 * Reachable here. */
2077 node->type.tv = tarval_reachable;
2078 } /* compute_Return */
2081 * (Re-)compute the type for the End node.
2083 * @param node the node
2085 static void compute_End(node_t *node)
2087 /* the End node is NOT dead of course */
2088 node->type.tv = tarval_reachable;
2092 * (Re-)compute the type for a Call.
2094 * @param node the node
2096 static void compute_Call(node_t *node)
2099 * A Call computes always bottom, even if it has Unknown
2102 node->type.tv = tarval_bottom;
2103 } /* compute_Call */
2106 * (Re-)compute the type for a SymConst node.
2108 * @param node the node
2110 static void compute_SymConst(node_t *node)
2112 ir_node *irn = node->node;
2113 node_t *block = get_irn_node(get_nodes_block(irn));
2115 if (block->type.tv == tarval_unreachable) {
2116 node->type.tv = tarval_top;
2119 switch (get_SymConst_kind(irn)) {
2120 case symconst_addr_ent:
2121 node->type.sym = get_SymConst_symbol(irn);
2124 node->type.tv = computed_value(irn);
2126 } /* compute_SymConst */
2129 * (Re-)compute the type for a Phi node.
2131 * @param node the node
2133 static void compute_Phi(node_t *node)
2136 ir_node *phi = node->node;
2137 lattice_elem_t type;
2139 /* if a Phi is in a unreachable block, its type is TOP */
2140 node_t *block = get_irn_node(get_nodes_block(phi));
2142 if (block->type.tv == tarval_unreachable) {
2143 node->type.tv = tarval_top;
2147 /* Phi implements the Meet operation */
2148 type.tv = tarval_top;
2149 for (i = get_Phi_n_preds(phi) - 1; i >= 0; --i) {
2150 node_t *pred = get_irn_node(get_Phi_pred(phi, i));
2151 node_t *pred_X = get_irn_node(get_Block_cfgpred(block->node, i));
2153 if (pred_X->type.tv == tarval_unreachable || pred->type.tv == tarval_top) {
2154 /* ignore TOP inputs: We must check here for unreachable blocks,
2155 because Firm constants live in the Start Block are NEVER Top.
2156 Else, a Phi (1,2) will produce Bottom, even if the 2 for instance
2157 comes from a unreachable input. */
2160 if (pred->type.tv == tarval_bottom) {
2161 node->type.tv = tarval_bottom;
2163 } else if (type.tv == tarval_top) {
2164 /* first constant found */
2166 } else if (type.tv != pred->type.tv) {
2167 /* different constants or tarval_bottom */
2168 node->type.tv = tarval_bottom;
2171 /* else nothing, constants are the same */
2177 * (Re-)compute the type for an Add. Special case: one nodes is a Zero Const.
2179 * @param node the node
2181 static void compute_Add(node_t *node)
2183 ir_node *sub = node->node;
2184 node_t *l = get_irn_node(get_Add_left(sub));
2185 node_t *r = get_irn_node(get_Add_right(sub));
2186 lattice_elem_t a = l->type;
2187 lattice_elem_t b = r->type;
2190 if (a.tv == tarval_top || b.tv == tarval_top) {
2191 node->type.tv = tarval_top;
2192 } else if (a.tv == tarval_bottom || b.tv == tarval_bottom) {
2193 node->type.tv = tarval_bottom;
2195 /* x + 0 = 0 + x = x, but beware of floating point +0 + -0, so we
2196 must call tarval_add() first to handle this case! */
2197 if (is_tarval(a.tv)) {
2198 if (is_tarval(b.tv)) {
2199 node->type.tv = tarval_add(a.tv, b.tv);
2202 mode = get_tarval_mode(a.tv);
2203 if (a.tv == get_mode_null(mode)) {
2207 } else if (is_tarval(b.tv)) {
2208 mode = get_tarval_mode(b.tv);
2209 if (b.tv == get_mode_null(mode)) {
2214 node->type.tv = tarval_bottom;
2219 * (Re-)compute the type for a Sub. Special case: both nodes are congruent.
2221 * @param node the node
2223 static void compute_Sub(node_t *node)
2225 ir_node *sub = node->node;
2226 node_t *l = get_irn_node(get_Sub_left(sub));
2227 node_t *r = get_irn_node(get_Sub_right(sub));
2228 lattice_elem_t a = l->type;
2229 lattice_elem_t b = r->type;
2232 if (a.tv == tarval_top || b.tv == tarval_top) {
2233 node->type.tv = tarval_top;
2234 } else if (is_con(a) && is_con(b)) {
2235 if (is_tarval(a.tv) && is_tarval(b.tv)) {
2236 node->type.tv = tarval_sub(a.tv, b.tv, get_irn_mode(sub));
2237 } else if (is_tarval(a.tv) && tarval_is_null(a.tv)) {
2239 } else if (is_tarval(b.tv) && tarval_is_null(b.tv)) {
2242 node->type.tv = tarval_bottom;
2244 } else if (r->part == l->part &&
2245 (!mode_is_float(get_irn_mode(l->node)))) {
2247 * BEWARE: a - a is NOT always 0 for floating Point values, as
2248 * NaN op NaN = NaN, so we must check this here.
2250 ir_mode *mode = get_irn_mode(sub);
2251 tv = get_mode_null(mode);
2253 /* if the node was ONCE evaluated by all constants, but now
2254 this breaks AND we get from the argument partitions a different
2255 result, switch to bottom.
2256 This happens because initially all nodes are in the same partition ... */
2257 if (node->type.tv != tv)
2261 node->type.tv = tarval_bottom;
2266 * (Re-)compute the type for an Eor. Special case: both nodes are congruent.
2268 * @param node the node
2270 static void compute_Eor(node_t *node)
2272 ir_node *eor = node->node;
2273 node_t *l = get_irn_node(get_Eor_left(eor));
2274 node_t *r = get_irn_node(get_Eor_right(eor));
2275 lattice_elem_t a = l->type;
2276 lattice_elem_t b = r->type;
2279 if (a.tv == tarval_top || b.tv == tarval_top) {
2280 node->type.tv = tarval_top;
2281 } else if (is_con(a) && is_con(b)) {
2282 if (is_tarval(a.tv) && is_tarval(b.tv)) {
2283 node->type.tv = tarval_eor(a.tv, b.tv);
2284 } else if (is_tarval(a.tv) && tarval_is_null(a.tv)) {
2286 } else if (is_tarval(b.tv) && tarval_is_null(b.tv)) {
2289 node->type.tv = tarval_bottom;
2291 } else if (r->part == l->part) {
2292 ir_mode *mode = get_irn_mode(eor);
2293 tv = get_mode_null(mode);
2295 /* if the node was ONCE evaluated by all constants, but now
2296 this breaks AND we get from the argument partitions a different
2297 result, switch to bottom.
2298 This happens because initially all nodes are in the same partition ... */
2299 if (node->type.tv != tv)
2303 node->type.tv = tarval_bottom;
2308 * (Re-)compute the type for Cmp.
2310 * @param node the node
2312 static void compute_Cmp(node_t *node)
2314 ir_node *cmp = node->node;
2315 node_t *l = get_irn_node(get_Cmp_left(cmp));
2316 node_t *r = get_irn_node(get_Cmp_right(cmp));
2317 lattice_elem_t a = l->type;
2318 lattice_elem_t b = r->type;
2319 ir_mode *mode = get_irn_mode(get_Cmp_left(cmp));
2321 if (a.tv == tarval_top || b.tv == tarval_top) {
2322 node->type.tv = tarval_top;
2323 } else if (r->part == l->part) {
2324 /* both nodes congruent, we can probably do something */
2325 if (mode_is_float(mode)) {
2326 /* beware of NaN's */
2327 node->type.tv = tarval_bottom;
2329 node->type.tv = tarval_b_true;
2331 } else if (is_con(a) && is_con(b)) {
2332 node->type.tv = tarval_b_true;
2334 node->type.tv = tarval_bottom;
2339 * (Re-)compute the type for a Proj(Cmp).
2341 * @param node the node
2342 * @param cond the predecessor Cmp node
2344 static void compute_Proj_Cmp(node_t *node, ir_node *cmp)
2346 ir_node *proj = node->node;
2347 node_t *l = get_irn_node(get_Cmp_left(cmp));
2348 node_t *r = get_irn_node(get_Cmp_right(cmp));
2349 lattice_elem_t a = l->type;
2350 lattice_elem_t b = r->type;
2351 pn_Cmp pnc = get_Proj_pn_cmp(proj);
2354 if (a.tv == tarval_top || b.tv == tarval_top) {
2355 node->type.tv = tarval_undefined;
2356 } else if (is_con(a) && is_con(b)) {
2357 default_compute(node);
2360 * BEWARE: a == a is NOT always True for floating Point values, as
2361 * NaN != NaN is defined, so we must check this here.
2362 * (while for some pnc we could still optimize we have to stay
2363 * consistent with compute_Cmp, so don't do anything for floats)
2365 } else if (r->part == l->part && !mode_is_float(get_irn_mode(l->node))) {
2366 tv = pnc & pn_Cmp_Eq ? tarval_b_true : tarval_b_false;
2368 /* if the node was ONCE evaluated by all constants, but now
2369 this breaks AND we get from the argument partitions a different
2370 result, switch to bottom.
2371 This happens because initially all nodes are in the same partition ... */
2372 if (node->type.tv != tv)
2376 node->type.tv = tarval_bottom;
2378 } /* compute_Proj_Cmp */
2381 * (Re-)compute the type for a Proj(Cond).
2383 * @param node the node
2384 * @param cond the predecessor Cond node
2386 static void compute_Proj_Cond(node_t *node, ir_node *cond)
2388 ir_node *proj = node->node;
2389 long pnc = get_Proj_proj(proj);
2390 ir_node *sel = get_Cond_selector(cond);
2391 node_t *selector = get_irn_node(sel);
2394 * Note: it is crucial for the monotony that the Proj(Cond)
2395 * are evaluates after all predecessors of the Cond selector are
2401 * Due to the fact that 0 is a const, the Cmp gets immediately
2402 * on the cprop list. It will be evaluated before x is evaluated,
2403 * might leaving x as Top. When later x is evaluated, the Cmp
2404 * might change its value.
2405 * BUT if the Cond is evaluated before this happens, Proj(Cond, FALSE)
2406 * gets R, and later changed to F if Cmp is evaluated to True!
2408 * We prevent this by putting Conds in an extra cprop_X queue, which
2409 * gets evaluated after the cprop queue is empty.
2411 * Note that this even happens with Click's original algorithm, if
2412 * Cmp(x, 0) is evaluated to True first and later changed to False
2413 * if x was Top first and later changed to a Const ...
2414 * It is unclear how Click solved that problem ...
2416 * However, in rare cases even this does not help, if a Top reaches
2417 * a compare through a Phi, than Proj(Cond) is evaluated changing
2418 * the type of the Phi to something other.
2419 * So, we take the last resort and bind the type to R once
2422 * (This might be even the way Click works around the whole problem).
2424 * Finally, we may miss some optimization possibilities due to this:
2429 * If Top reaches the if first, than we decide for != here.
2430 * If y later is evaluated to 0, we cannot revert this decision
2431 * and must live with both outputs enabled. If this happens,
2432 * we get an unresolved if (true) in the code ...
2434 * In Click's version where this decision is done at the Cmp,
2435 * the Cmp is NOT optimized away than (if y evaluated to 1
2436 * for instance) and we get a if (1 == 0) here ...
2438 * Both solutions are suboptimal.
2439 * At least, we could easily detect this problem and run
2440 * cf_opt() (or even combo) again :-(
2442 if (node->type.tv == tarval_reachable)
2445 if (get_irn_mode(sel) == mode_b) {
2447 if (pnc == pn_Cond_true) {
2448 if (selector->type.tv == tarval_b_false) {
2449 node->type.tv = tarval_unreachable;
2450 } else if (selector->type.tv == tarval_b_true) {
2451 node->type.tv = tarval_reachable;
2452 } else if (selector->type.tv == tarval_bottom) {
2453 node->type.tv = tarval_reachable;
2455 assert(selector->type.tv == tarval_top);
2456 if (tarval_UNKNOWN == tarval_top) {
2457 /* any condition based on Top is "!=" */
2458 node->type.tv = tarval_unreachable;
2460 node->type.tv = tarval_unreachable;
2464 assert(pnc == pn_Cond_false);
2466 if (selector->type.tv == tarval_b_false) {
2467 node->type.tv = tarval_reachable;
2468 } else if (selector->type.tv == tarval_b_true) {
2469 node->type.tv = tarval_unreachable;
2470 } else if (selector->type.tv == tarval_bottom) {
2471 node->type.tv = tarval_reachable;
2473 assert(selector->type.tv == tarval_top);
2474 if (tarval_UNKNOWN == tarval_top) {
2475 /* any condition based on Top is "!=" */
2476 node->type.tv = tarval_reachable;
2478 node->type.tv = tarval_unreachable;
2484 if (selector->type.tv == tarval_bottom) {
2485 node->type.tv = tarval_reachable;
2486 } else if (selector->type.tv == tarval_top) {
2487 if (tarval_UNKNOWN == tarval_top &&
2488 pnc == get_Cond_default_proj(cond)) {
2489 /* a switch based of Top is always "default" */
2490 node->type.tv = tarval_reachable;
2492 node->type.tv = tarval_unreachable;
2495 long value = get_tarval_long(selector->type.tv);
2496 if (pnc == get_Cond_default_proj(cond)) {
2497 /* default switch, have to check ALL other cases */
2500 for (i = get_irn_n_outs(cond) - 1; i >= 0; --i) {
2501 ir_node *succ = get_irn_out(cond, i);
2505 if (value == get_Proj_proj(succ)) {
2506 /* we found a match, will NOT take the default case */
2507 node->type.tv = tarval_unreachable;
2511 /* all cases checked, no match, will take default case */
2512 node->type.tv = tarval_reachable;
2515 node->type.tv = value == pnc ? tarval_reachable : tarval_unreachable;
2519 } /* compute_Proj_Cond */
2522 * (Re-)compute the type for a Proj-Node.
2524 * @param node the node
2526 static void compute_Proj(node_t *node)
2528 ir_node *proj = node->node;
2529 ir_mode *mode = get_irn_mode(proj);
2530 node_t *block = get_irn_node(get_nodes_block(skip_Proj(proj)));
2531 ir_node *pred = get_Proj_pred(proj);
2533 if (block->type.tv == tarval_unreachable) {
2534 /* a Proj in a unreachable Block stay Top */
2535 node->type.tv = tarval_top;
2538 if (get_irn_node(pred)->type.tv == tarval_top && !is_Cond(pred)) {
2539 /* if the predecessor is Top, its Proj follow */
2540 node->type.tv = tarval_top;
2544 if (mode == mode_M) {
2545 /* mode M is always bottom */
2546 node->type.tv = tarval_bottom;
2549 if (mode != mode_X) {
2551 compute_Proj_Cmp(node, pred);
2553 default_compute(node);
2556 /* handle mode_X nodes */
2558 switch (get_irn_opcode(pred)) {
2560 /* the Proj_X from the Start is always reachable.
2561 However this is already handled at the top. */
2562 node->type.tv = tarval_reachable;
2565 compute_Proj_Cond(node, pred);
2568 default_compute(node);
2570 } /* compute_Proj */
2573 * (Re-)compute the type for a Confirm.
2575 * @param node the node
2577 static void compute_Confirm(node_t *node)
2579 ir_node *confirm = node->node;
2580 node_t *pred = get_irn_node(get_Confirm_value(confirm));
2582 if (get_Confirm_cmp(confirm) == pn_Cmp_Eq) {
2583 node_t *bound = get_irn_node(get_Confirm_bound(confirm));
2585 if (is_con(bound->type)) {
2586 /* is equal to a constant */
2587 node->type = bound->type;
2591 /* a Confirm is a copy OR a Const */
2592 node->type = pred->type;
2593 } /* compute_Confirm */
2596 * (Re-)compute the type for a given node.
2598 * @param node the node
2600 static void compute(node_t *node)
2602 ir_node *irn = node->node;
2605 #ifndef VERIFY_MONOTONE
2607 * Once a node reaches bottom, the type cannot fall further
2608 * in the lattice and we can stop computation.
2609 * Do not take this exit if the monotony verifier is
2610 * enabled to catch errors.
2612 if (node->type.tv == tarval_bottom)
2616 if (!is_Block(irn)) {
2617 /* for pinned nodes, check its control input */
2618 if (get_irn_pinned(skip_Proj(irn)) == op_pin_state_pinned) {
2619 node_t *block = get_irn_node(get_nodes_block(irn));
2621 if (block->type.tv == tarval_unreachable) {
2622 node->type.tv = tarval_top;
2628 func = (compute_func)node->node->op->ops.generic;
2634 * Identity functions: Note that one might think that identity() is just a
2635 * synonym for equivalent_node(). While this is true, we cannot use it for the algorithm
2636 * here, because it expects that the identity node is one of the inputs, which is NOT
2637 * always true for equivalent_node() which can handle (and does sometimes) DAGs.
2638 * So, we have our own implementation, which copies some parts of equivalent_node()
2642 * Calculates the Identity for Phi nodes
2644 static node_t *identity_Phi(node_t *node)
2646 ir_node *phi = node->node;
2647 ir_node *block = get_nodes_block(phi);
2648 node_t *n_part = NULL;
2651 for (i = get_Phi_n_preds(phi) - 1; i >= 0; --i) {
2652 node_t *pred_X = get_irn_node(get_Block_cfgpred(block, i));
2654 if (pred_X->type.tv == tarval_reachable) {
2655 node_t *pred = get_irn_node(get_Phi_pred(phi, i));
2659 else if (n_part->part != pred->part) {
2660 /* incongruent inputs, not a follower */
2665 /* if n_part is NULL here, all inputs path are dead, the Phi computes
2666 * tarval_top, is in the TOP partition and should NOT being split! */
2667 assert(n_part != NULL);
2669 } /* identity_Phi */
2672 * Calculates the Identity for commutative 0 neutral nodes.
2674 static node_t *identity_comm_zero_binop(node_t *node)
2676 ir_node *op = node->node;
2677 node_t *a = get_irn_node(get_binop_left(op));
2678 node_t *b = get_irn_node(get_binop_right(op));
2679 ir_mode *mode = get_irn_mode(op);
2682 /* for FP these optimizations are only allowed if fp_strict_algebraic is disabled */
2683 if (mode_is_float(mode) && (get_irg_fp_model(current_ir_graph) & fp_strict_algebraic))
2686 /* node: no input should be tarval_top, else the binop would be also
2687 * Top and not being split. */
2688 zero = get_mode_null(mode);
2689 if (a->type.tv == zero)
2691 if (b->type.tv == zero)
2694 } /* identity_comm_zero_binop */
2697 * Calculates the Identity for Shift nodes.
2699 static node_t *identity_shift(node_t *node)
2701 ir_node *op = node->node;
2702 node_t *b = get_irn_node(get_binop_right(op));
2703 ir_mode *mode = get_irn_mode(b->node);
2706 /* node: no input should be tarval_top, else the binop would be also
2707 * Top and not being split. */
2708 zero = get_mode_null(mode);
2709 if (b->type.tv == zero)
2710 return get_irn_node(get_binop_left(op));
2712 } /* identity_shift */
2715 * Calculates the Identity for Mul nodes.
2717 static node_t *identity_Mul(node_t *node)
2719 ir_node *op = node->node;
2720 node_t *a = get_irn_node(get_Mul_left(op));
2721 node_t *b = get_irn_node(get_Mul_right(op));
2722 ir_mode *mode = get_irn_mode(op);
2725 /* for FP these optimizations are only allowed if fp_strict_algebraic is disabled */
2726 if (mode_is_float(mode) && (get_irg_fp_model(current_ir_graph) & fp_strict_algebraic))
2729 /* node: no input should be tarval_top, else the binop would be also
2730 * Top and not being split. */
2731 one = get_mode_one(mode);
2732 if (a->type.tv == one)
2734 if (b->type.tv == one)
2737 } /* identity_Mul */
2740 * Calculates the Identity for Sub nodes.
2742 static node_t *identity_Sub(node_t *node)
2744 ir_node *sub = node->node;
2745 node_t *b = get_irn_node(get_Sub_right(sub));
2746 ir_mode *mode = get_irn_mode(sub);
2748 /* for FP these optimizations are only allowed if fp_strict_algebraic is disabled */
2749 if (mode_is_float(mode) && (get_irg_fp_model(current_ir_graph) & fp_strict_algebraic))
2752 /* node: no input should be tarval_top, else the binop would be also
2753 * Top and not being split. */
2754 if (b->type.tv == get_mode_null(mode))
2755 return get_irn_node(get_Sub_left(sub));
2757 } /* identity_Sub */
2760 * Calculates the Identity for And nodes.
2762 static node_t *identity_And(node_t *node)
2764 ir_node *andnode = node->node;
2765 node_t *a = get_irn_node(get_And_left(andnode));
2766 node_t *b = get_irn_node(get_And_right(andnode));
2767 ir_tarval *neutral = get_mode_all_one(get_irn_mode(andnode));
2769 /* node: no input should be tarval_top, else the And would be also
2770 * Top and not being split. */
2771 if (a->type.tv == neutral)
2773 if (b->type.tv == neutral)
2776 } /* identity_And */
2779 * Calculates the Identity for Confirm nodes.
2781 static node_t *identity_Confirm(node_t *node)
2783 ir_node *confirm = node->node;
2785 /* a Confirm is always a Copy */
2786 return get_irn_node(get_Confirm_value(confirm));
2787 } /* identity_Confirm */
2790 * Calculates the Identity for Mux nodes.
2792 static node_t *identity_Mux(node_t *node)
2794 ir_node *mux = node->node;
2795 node_t *t = get_irn_node(get_Mux_true(mux));
2796 node_t *f = get_irn_node(get_Mux_false(mux));
2799 if (t->part == f->part)
2802 /* for now, the 1-input identity is not supported */
2804 sel = get_irn_node(get_Mux_sel(mux));
2806 /* Mux sel input is mode_b, so it is always a tarval */
2807 if (sel->type.tv == tarval_b_true)
2809 if (sel->type.tv == tarval_b_false)
2813 } /* identity_Mux */
2816 * Calculates the Identity for nodes.
2818 static node_t *identity(node_t *node)
2820 ir_node *irn = node->node;
2822 switch (get_irn_opcode(irn)) {
2824 return identity_Phi(node);
2826 return identity_Mul(node);
2830 return identity_comm_zero_binop(node);
2835 return identity_shift(node);
2837 return identity_And(node);
2839 return identity_Sub(node);
2841 return identity_Confirm(node);
2843 return identity_Mux(node);
2850 * Node follower is a (new) follower of leader, segregate Leader
2853 static void segregate_def_use_chain_1(const ir_node *follower, node_t *leader)
2855 ir_node *l = leader->node;
2856 int j, i, n = get_irn_n_outs(l);
2858 DB((dbg, LEVEL_2, "%+F is a follower of %+F\n", follower, leader->node));
2859 /* The leader edges must remain sorted, but follower edges can
2861 for (i = leader->n_followers + 1; i <= n; ++i) {
2862 if (l->out[i].use == follower) {
2863 ir_def_use_edge t = l->out[i];
2865 for (j = i - 1; j >= leader->n_followers + 1; --j)
2866 l->out[j + 1] = l->out[j];
2867 ++leader->n_followers;
2868 l->out[leader->n_followers] = t;
2872 } /* segregate_def_use_chain_1 */
2875 * Node follower is a (new) follower segregate its Leader
2878 * @param follower the follower IR node
2880 static void segregate_def_use_chain(const ir_node *follower)
2884 for (i = get_irn_arity(follower) - 1; i >= 0; --i) {
2885 node_t *pred = get_irn_node(get_irn_n(follower, i));
2887 segregate_def_use_chain_1(follower, pred);
2889 } /* segregate_def_use_chain */
2892 * Propagate constant evaluation.
2894 * @param env the environment
2896 static void propagate(environment_t *env)
2900 lattice_elem_t old_type;
2902 unsigned n_fallen, old_type_was_T_or_C;
2905 while (env->cprop != NULL) {
2906 void *oldopcode = NULL;
2908 /* remove the first partition X from cprop */
2911 env->cprop = X->cprop_next;
2913 old_type_was_T_or_C = X->type_is_T_or_C;
2915 DB((dbg, LEVEL_2, "Propagate type on part%d\n", X->nr));
2919 int cprop_empty = list_empty(&X->cprop);
2920 int cprop_X_empty = list_empty(&X->cprop_X);
2922 if (cprop_empty && cprop_X_empty) {
2923 /* both cprop lists are empty */
2927 /* remove the first Node x from X.cprop */
2929 /* Get a node from the cprop_X list only if
2930 * all data nodes are processed.
2931 * This ensures, that all inputs of the Cond
2932 * predecessor are processed if its type is still Top.
2934 x = list_entry(X->cprop_X.next, node_t, cprop_list);
2936 x = list_entry(X->cprop.next, node_t, cprop_list);
2939 //assert(x->part == X);
2940 list_del(&x->cprop_list);
2943 if (x->is_follower && identity(x) == x) {
2944 /* check the opcode first */
2945 if (oldopcode == NULL) {
2946 oldopcode = lambda_opcode(get_first_node(X), env);
2948 if (oldopcode != lambda_opcode(x, env)) {
2949 if (x->on_fallen == 0) {
2950 /* different opcode -> x falls out of this partition */
2955 DB((dbg, LEVEL_2, "Add node %+F to fallen\n", x->node));
2959 /* x will make the follower -> leader transition */
2960 follower_to_leader(x);
2963 /* compute a new type for x */
2965 DB((dbg, LEVEL_3, "computing type of %+F\n", x->node));
2967 if (x->type.tv != old_type.tv) {
2968 DB((dbg, LEVEL_2, "node %+F has changed type from %+F to %+F\n", x->node, old_type, x->type));
2969 verify_type(old_type, x);
2971 if (x->on_fallen == 0) {
2972 /* Add x to fallen. Nodes might fall from T -> const -> _|_, so check that they are
2973 not already on the list. */
2978 DB((dbg, LEVEL_2, "Add node %+F to fallen\n", x->node));
2980 for (i = get_irn_n_outs(x->node) - 1; i >= 0; --i) {
2981 ir_node *succ = get_irn_out(x->node, i);
2982 node_t *y = get_irn_node(succ);
2984 /* Add y to y.partition.cprop. */
2985 add_to_cprop(y, env);
2990 if (n_fallen > 0 && n_fallen != X->n_leader) {
2991 DB((dbg, LEVEL_2, "Splitting part%d by fallen\n", X->nr));
2992 Y = split(&X, fallen, env);
2994 * We have split out fallen node. The type of the result
2995 * partition is NOT set yet.
2997 Y->type_is_T_or_C = 0;
3001 /* remove the flags from the fallen list */
3002 for (x = fallen; x != NULL; x = x->next)
3005 if (old_type_was_T_or_C) {
3008 /* check if some nodes will make the leader -> follower transition */
3009 list_for_each_entry_safe(node_t, y, tmp, &Y->Leader, node_list) {
3010 if (y->type.tv != tarval_top && ! is_con(y->type)) {
3011 node_t *eq_node = identity(y);
3013 if (eq_node != y && eq_node->part == y->part) {
3014 DB((dbg, LEVEL_2, "Node %+F is a follower of %+F\n", y->node, eq_node->node));
3015 /* move to Follower */
3017 list_del(&y->node_list);
3018 list_add_tail(&y->node_list, &Y->Follower);
3021 segregate_def_use_chain(y->node);
3031 * Get the leader for a given node from its congruence class.
3033 * @param irn the node
3035 static ir_node *get_leader(node_t *node)
3037 partition_t *part = node->part;
3039 if (part->n_leader > 1 || node->is_follower) {
3040 if (node->is_follower) {
3041 DB((dbg, LEVEL_2, "Replacing follower %+F\n", node->node));
3044 DB((dbg, LEVEL_2, "Found congruence class for %+F\n", node->node));
3046 return get_first_node(part)->node;
3052 * Returns non-zero if a mode_T node has only one reachable output.
3054 static int only_one_reachable_proj(ir_node *n)
3058 for (i = get_irn_n_outs(n) - 1; i >= 0; --i) {
3059 ir_node *proj = get_irn_out(n, i);
3062 /* skip non-control flow Proj's */
3063 if (get_irn_mode(proj) != mode_X)
3066 node = get_irn_node(proj);
3067 if (node->type.tv == tarval_reachable) {
3073 } /* only_one_reachable_proj */
3076 * Return non-zero if the control flow predecessor node pred
3077 * is the only reachable control flow exit of its block.
3079 * @param pred the control flow exit
3080 * @param block the destination block
3082 static int can_exchange(ir_node *pred, ir_node *block)
3084 if (is_Start(pred) || has_Block_entity(block))
3086 else if (is_Jmp(pred))
3088 else if (get_irn_mode(pred) == mode_T) {
3089 /* if the predecessor block has more than one
3090 reachable outputs we cannot remove the block */
3091 return only_one_reachable_proj(pred);
3094 } /* can_exchange */
3097 * Block Post-Walker, apply the analysis results on control flow by
3098 * shortening Phi's and Block inputs.
3100 static void apply_cf(ir_node *block, void *ctx)
3102 environment_t *env = (environment_t*)ctx;
3103 node_t *node = get_irn_node(block);
3105 ir_node **ins, **in_X;
3106 ir_node *phi, *next;
3108 n = get_Block_n_cfgpreds(block);
3110 if (node->type.tv == tarval_unreachable) {
3113 for (i = n - 1; i >= 0; --i) {
3114 ir_node *pred = get_Block_cfgpred(block, i);
3116 if (! is_Bad(pred)) {
3117 node_t *pred_bl = get_irn_node(get_nodes_block(skip_Proj(pred)));
3119 if (pred_bl->flagged == 0) {
3120 pred_bl->flagged = 3;
3122 if (pred_bl->type.tv == tarval_reachable) {
3124 * We will remove an edge from block to its pred.
3125 * This might leave the pred block as an endless loop
3127 if (! is_backedge(block, i))
3128 keep_alive(pred_bl->node);
3134 /* the EndBlock is always reachable even if the analysis
3135 finds out the opposite :-) */
3136 if (block != get_irg_end_block(current_ir_graph)) {
3137 /* mark dead blocks */
3138 set_Block_dead(block);
3139 DB((dbg, LEVEL_1, "Removing dead %+F\n", block));
3141 /* the endblock is unreachable */
3142 set_irn_in(block, 0, NULL);
3148 /* only one predecessor combine */
3149 ir_node *pred = skip_Proj(get_Block_cfgpred(block, 0));
3151 if (can_exchange(pred, block)) {
3152 ir_node *new_block = get_nodes_block(pred);
3153 DB((dbg, LEVEL_1, "Fuse %+F with %+F\n", block, new_block));
3154 DBG_OPT_COMBO(block, new_block, FS_OPT_COMBO_CF);
3155 exchange(block, new_block);
3156 node->node = new_block;
3162 NEW_ARR_A(ir_node *, in_X, n);
3164 for (i = 0; i < n; ++i) {
3165 ir_node *pred = get_Block_cfgpred(block, i);
3166 node_t *node = get_irn_node(pred);
3168 if (node->type.tv == tarval_reachable) {
3171 DB((dbg, LEVEL_1, "Removing dead input %d from %+F (%+F)\n", i, block, pred));
3172 if (! is_Bad(pred)) {
3173 node_t *pred_bl = get_irn_node(get_nodes_block(skip_Proj(pred)));
3175 if (pred_bl->flagged == 0) {
3176 pred_bl->flagged = 3;
3178 if (pred_bl->type.tv == tarval_reachable) {
3180 * We will remove an edge from block to its pred.
3181 * This might leave the pred block as an endless loop
3183 if (! is_backedge(block, i))
3184 keep_alive(pred_bl->node);
3194 NEW_ARR_A(ir_node *, ins, n);
3195 for (phi = get_Block_phis(block); phi != NULL; phi = next) {
3196 node_t *node = get_irn_node(phi);
3198 next = get_Phi_next(phi);
3199 if (is_tarval(node->type.tv) && tarval_is_constant(node->type.tv)) {
3200 /* this Phi is replaced by a constant */
3201 ir_tarval *tv = node->type.tv;
3202 ir_node *c = new_r_Const(current_ir_graph, tv);
3204 set_irn_node(c, node);
3206 DB((dbg, LEVEL_1, "%+F is replaced by %+F\n", phi, c));
3207 DBG_OPT_COMBO(phi, c, FS_OPT_COMBO_CONST);
3212 for (i = 0; i < n; ++i) {
3213 node_t *pred = get_irn_node(get_Block_cfgpred(block, i));
3215 if (pred->type.tv == tarval_reachable) {
3216 ins[j++] = get_Phi_pred(phi, i);
3220 /* this Phi is replaced by a single predecessor */
3221 ir_node *s = ins[0];
3222 node_t *phi_node = get_irn_node(phi);
3225 DB((dbg, LEVEL_1, "%+F is replaced by %+F because of cf change\n", phi, s));
3226 DBG_OPT_COMBO(phi, s, FS_OPT_COMBO_FOLLOWER);
3231 set_irn_in(phi, j, ins);
3239 /* this Block has only one live predecessor */
3240 ir_node *pred = skip_Proj(in_X[0]);
3242 if (can_exchange(pred, block)) {
3243 ir_node *new_block = get_nodes_block(pred);
3244 DBG_OPT_COMBO(block, new_block, FS_OPT_COMBO_CF);
3245 exchange(block, new_block);
3246 node->node = new_block;
3251 set_irn_in(block, k, in_X);
3256 * Exchange a node by its leader.
3257 * Beware: in rare cases the mode might be wrong here, for instance
3258 * AddP(x, NULL) is a follower of x, but with different mode.
3261 static void exchange_leader(ir_node *irn, ir_node *leader)
3263 ir_mode *mode = get_irn_mode(irn);
3264 if (mode != get_irn_mode(leader)) {
3265 /* The conv is a no-op, so we are free to place it
3266 * either in the block of the leader OR in irn's block.
3267 * Probably placing it into leaders block might reduce
3268 * the number of Conv due to CSE. */
3269 ir_node *block = get_nodes_block(leader);
3270 dbg_info *dbg = get_irn_dbg_info(irn);
3271 ir_node *nlead = new_rd_Conv(dbg, block, leader, mode);
3273 if (nlead != leader) {
3274 /* Note: this newly create irn has no node info because
3275 * it is created after the analysis. However, this node
3276 * replaces the node irn and should not be visited again,
3277 * so set its visited count to the count of irn.
3278 * Otherwise we might visited this node more than once if
3279 * irn had more than one user.
3281 set_irn_node(nlead, NULL);
3282 set_irn_visited(nlead, get_irn_visited(irn));
3286 exchange(irn, leader);
3287 } /* exchange_leader */
3290 * Check, if all users of a mode_M node are dead. Use
3291 * the Def-Use edges for this purpose, as they still
3292 * reflect the situation.
3294 static int all_users_are_dead(const ir_node *irn)
3296 int i, n = get_irn_n_outs(irn);
3298 for (i = 1; i <= n; ++i) {
3299 const ir_node *succ = irn->out[i].use;
3300 const node_t *block = get_irn_node(get_nodes_block(succ));
3303 if (block->type.tv == tarval_unreachable) {
3304 /* block is unreachable */
3307 node = get_irn_node(succ);
3308 if (node->type.tv != tarval_top) {
3309 /* found a reachable user */
3313 /* all users are unreachable */
3315 } /* all_user_are_dead */
3318 * Walker: Find reachable mode_M nodes that have only
3319 * unreachable users. These nodes must be kept later.
3321 static void find_kept_memory(ir_node *irn, void *ctx)
3323 environment_t *env = (environment_t*)ctx;
3324 node_t *node, *block;
3326 if (get_irn_mode(irn) != mode_M)
3329 block = get_irn_node(get_nodes_block(irn));
3330 if (block->type.tv == tarval_unreachable)
3333 node = get_irn_node(irn);
3334 if (node->type.tv == tarval_top)
3337 /* ok, we found a live memory node. */
3338 if (all_users_are_dead(irn)) {
3339 DB((dbg, LEVEL_1, "%+F must be kept\n", irn));
3340 ARR_APP1(ir_node *, env->kept_memory, irn);
3342 } /* find_kept_memory */
3345 * Post-Walker, apply the analysis results;
3347 static void apply_result(ir_node *irn, void *ctx)
3349 environment_t *env = (environment_t*)ctx;
3350 node_t *node = get_irn_node(irn);
3352 if (is_Block(irn) || is_End(irn) || is_Bad(irn)) {
3353 /* blocks already handled, do not touch the End node */
3355 node_t *block = get_irn_node(get_nodes_block(irn));
3357 if (block->type.tv == tarval_unreachable) {
3358 ir_node *bad = get_irg_bad(current_ir_graph);
3360 /* here, bad might already have a node, but this can be safely ignored
3361 as long as bad has at least ONE valid node */
3362 set_irn_node(bad, node);
3364 DB((dbg, LEVEL_1, "%+F is unreachable\n", irn));
3367 } else if (node->type.tv == tarval_top) {
3368 ir_mode *mode = get_irn_mode(irn);
3370 if (mode == mode_M) {
3371 /* never kill a mode_M node */
3373 ir_node *pred = get_Proj_pred(irn);
3374 node_t *pnode = get_irn_node(pred);
3376 if (pnode->type.tv == tarval_top) {
3377 /* skip the predecessor */
3378 ir_node *mem = get_memop_mem(pred);
3380 DB((dbg, LEVEL_1, "%+F computes Top, replaced by %+F\n", irn, mem));
3385 /* leave other nodes, especially PhiM */
3386 } else if (mode == mode_T) {
3387 /* Do not kill mode_T nodes, kill their Projs */
3388 } else if (! is_Unknown(irn)) {
3389 /* don't kick away Unknown's, they might be still needed */
3390 ir_node *unk = new_r_Unknown(current_ir_graph, mode);
3392 /* control flow should already be handled at apply_cf() */
3393 assert(mode != mode_X);
3395 /* see comment above */
3396 set_irn_node(unk, node);
3398 DB((dbg, LEVEL_1, "%+F computes Top\n", irn));
3403 else if (get_irn_mode(irn) == mode_X) {
3406 ir_node *cond = get_Proj_pred(irn);
3408 if (is_Cond(cond)) {
3409 if (only_one_reachable_proj(cond)) {
3410 ir_node *jmp = new_r_Jmp(block->node);
3411 set_irn_node(jmp, node);
3413 DB((dbg, LEVEL_1, "%+F is replaced by %+F\n", irn, jmp));
3414 DBG_OPT_COMBO(irn, jmp, FS_OPT_COMBO_CF);
3418 node_t *sel = get_irn_node(get_Cond_selector(cond));
3419 ir_tarval *tv = sel->type.tv;
3421 if (is_tarval(tv) && tarval_is_constant(tv)) {
3422 /* The selector is a constant, but more
3423 * than one output is active: An unoptimized
3431 /* normal data node */
3432 if (is_tarval(node->type.tv) && tarval_is_constant(node->type.tv)) {
3433 ir_tarval *tv = node->type.tv;
3436 * Beware: never replace mode_T nodes by constants. Currently we must mark
3437 * mode_T nodes with constants, but do NOT replace them.
3439 if (! is_Const(irn) && get_irn_mode(irn) != mode_T) {
3440 /* can be replaced by a constant */
3441 ir_node *c = new_r_Const(current_ir_graph, tv);
3442 set_irn_node(c, node);
3444 DB((dbg, LEVEL_1, "%+F is replaced by %+F\n", irn, c));
3445 DBG_OPT_COMBO(irn, c, FS_OPT_COMBO_CONST);
3446 exchange_leader(irn, c);
3449 } else if (is_entity(node->type.sym.entity_p)) {
3450 if (! is_SymConst(irn)) {
3451 /* can be replaced by a SymConst */
3452 ir_node *symc = new_r_SymConst(current_ir_graph, get_irn_mode(irn), node->type.sym, symconst_addr_ent);
3453 set_irn_node(symc, node);
3456 DB((dbg, LEVEL_1, "%+F is replaced by %+F\n", irn, symc));
3457 DBG_OPT_COMBO(irn, symc, FS_OPT_COMBO_CONST);
3458 exchange_leader(irn, symc);
3461 } else if (is_Confirm(irn)) {
3462 /* Confirms are always follower, but do not kill them here */
3464 ir_node *leader = get_leader(node);
3466 if (leader != irn) {
3467 int non_strict_phi = 0;
3470 * Beware: Do not remove Phi(Unknown, ..., x, ..., Unknown)
3471 * as this might create non-strict programs.
3473 if (node->is_follower && is_Phi(irn) && !is_Unknown(leader)) {
3476 for (i = get_Phi_n_preds(irn) - 1; i >= 0; --i) {
3477 ir_node *pred = get_Phi_pred(irn, i);
3479 if (is_Unknown(pred)) {
3485 if (! non_strict_phi) {
3486 DB((dbg, LEVEL_1, "%+F from part%d is replaced by %+F\n", irn, node->part->nr, leader));
3487 if (node->is_follower)
3488 DBG_OPT_COMBO(irn, leader, FS_OPT_COMBO_FOLLOWER);
3490 DBG_OPT_COMBO(irn, leader, FS_OPT_COMBO_CONGRUENT);
3491 exchange_leader(irn, leader);
3498 } /* apply_result */
3501 * Fix the keep-alives by deleting unreachable ones.
3503 static void apply_end(ir_node *end, environment_t *env)
3505 int i, j, n = get_End_n_keepalives(end);
3506 ir_node **in = NULL;
3509 NEW_ARR_A(ir_node *, in, n);
3511 /* fix the keep alive */
3512 for (i = j = 0; i < n; i++) {
3513 ir_node *ka = get_End_keepalive(end, i);
3514 node_t *node = get_irn_node(ka);
3517 node = get_irn_node(get_nodes_block(ka));
3519 if (node->type.tv != tarval_unreachable && !is_Bad(ka))
3523 set_End_keepalives(end, j, in);
3528 #define SET(code) op_##code->ops.generic = (op_func)compute_##code
3531 * sets the generic functions to compute.
3533 static void set_compute_functions(void)
3537 /* set the default compute function */
3538 for (i = 0, n = get_irp_n_opcodes(); i < n; ++i) {
3539 ir_op *op = get_irp_opcode(i);
3540 op->ops.generic = (op_func)default_compute;
3543 /* set specific functions */
3559 } /* set_compute_functions */
3564 static void add_memory_keeps(ir_node **kept_memory, size_t len)
3566 ir_node *end = get_irg_end(current_ir_graph);
3571 ir_nodeset_init(&set);
3573 /* check, if those nodes are already kept */
3574 for (i = get_End_n_keepalives(end) - 1; i >= 0; --i)
3575 ir_nodeset_insert(&set, get_End_keepalive(end, i));
3577 for (idx = 0; idx < len; ++idx) {
3578 ir_node *ka = kept_memory[idx];
3580 if (! ir_nodeset_contains(&set, ka)) {
3581 add_End_keepalive(end, ka);
3584 ir_nodeset_destroy(&set);
3585 } /* add_memory_keeps */
3587 void combo(ir_graph *irg)
3590 ir_node *initial_bl;
3592 ir_graph *rem = current_ir_graph;
3595 current_ir_graph = irg;
3597 /* register a debug mask */
3598 FIRM_DBG_REGISTER(dbg, "firm.opt.combo");
3600 DB((dbg, LEVEL_1, "Doing COMBO for %+F\n", irg));
3602 obstack_init(&env.obst);
3603 env.worklist = NULL;
3607 #ifdef DEBUG_libfirm
3608 env.dbg_list = NULL;
3610 env.opcode2id_map = new_set(cmp_opcode, iro_Last * 4);
3611 env.kept_memory = NEW_ARR_F(ir_node *, 0);
3612 env.end_idx = get_opt_global_cse() ? 0 : -1;
3613 env.lambda_input = 0;
3616 /* options driving the optimization */
3617 env.commutative = 1;
3618 env.opt_unknown = 1;
3620 assure_irg_outs(irg);
3621 assure_cf_loop(irg);
3623 /* we have our own value_of function */
3624 set_value_of_func(get_node_tarval);
3626 set_compute_functions();
3627 DEBUG_ONLY(part_nr = 0);
3629 ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK | IR_RESOURCE_PHI_LIST);
3631 if (env.opt_unknown)
3632 tarval_UNKNOWN = tarval_top;
3634 tarval_UNKNOWN = tarval_bad;
3636 /* create the initial partition and place it on the work list */
3637 env.initial = new_partition(&env);
3638 add_to_worklist(env.initial, &env);
3639 irg_walk_graph(irg, create_initial_partitions, init_block_phis, &env);
3641 /* set the hook: from now, every node has a partition and a type */
3642 DEBUG_ONLY(set_dump_node_vcgattr_hook(dump_partition_hook));
3644 /* all nodes on the initial partition have type Top */
3645 env.initial->type_is_T_or_C = 1;
3647 /* Place the START Node's partition on cprop.
3648 Place the START Node on its local worklist. */
3649 initial_bl = get_irg_start_block(irg);
3650 start = get_irn_node(initial_bl);
3651 add_to_cprop(start, &env);
3655 if (env.worklist != NULL)
3657 } while (env.cprop != NULL || env.worklist != NULL);
3659 dump_all_partitions(&env);
3660 check_all_partitions(&env);
3663 dump_ir_block_graph(irg, "-partition");
3666 /* apply the result */
3668 /* check, which nodes must be kept */
3669 irg_walk_graph(irg, NULL, find_kept_memory, &env);
3671 /* kill unreachable control flow */
3672 irg_block_walk_graph(irg, NULL, apply_cf, &env);
3673 /* Kill keep-alives of dead blocks: this speeds up apply_result()
3674 * and fixes assertion because dead cf to dead blocks is NOT removed by
3676 apply_end(get_irg_end(irg), &env);
3677 irg_walk_graph(irg, NULL, apply_result, &env);
3679 len = ARR_LEN(env.kept_memory);
3681 add_memory_keeps(env.kept_memory, len);
3684 DB((dbg, LEVEL_1, "Unoptimized Control Flow left"));
3688 /* control flow might changed */
3689 set_irg_outs_inconsistent(irg);
3690 set_irg_extblk_inconsistent(irg);
3691 set_irg_doms_inconsistent(irg);
3692 set_irg_loopinfo_inconsistent(irg);
3693 set_irg_entity_usage_state(irg, ir_entity_usage_not_computed);
3696 ir_free_resources(irg, IR_RESOURCE_IRN_LINK | IR_RESOURCE_PHI_LIST);
3698 /* remove the partition hook */
3699 DEBUG_ONLY(set_dump_node_vcgattr_hook(NULL));
3701 DEL_ARR_F(env.kept_memory);
3702 del_set(env.opcode2id_map);
3703 obstack_free(&env.obst, NULL);
3705 /* restore value_of() default behavior */
3706 set_value_of_func(NULL);
3707 current_ir_graph = rem;
3710 /* Creates an ir_graph pass for combo. */
3711 ir_graph_pass_t *combo_pass(const char *name)
3713 return def_graph_pass(name ? name : "combo", combo);