2 * Copyright (C) 1995-2007 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 Operator Strength Reduction.
24 * @author Michael Beck
27 * Implementation of the Operator Strength Reduction algorithm
28 * by Keith D. Cooper, L. Taylor Simpson, Christopher A. Vick.
55 /** The debug handle. */
56 DEBUG_ONLY(static firm_dbg_module_t *dbg;)
60 ir_node *head; /**< the head of the list */
64 typedef struct node_entry {
65 unsigned DFSnum; /**< the DFS number of this node */
66 unsigned low; /**< the low number of this node */
67 ir_node *header; /**< the header of this node */
68 int in_stack; /**< flag, set if the node is on the stack */
69 ir_node *next; /**< link to the next node the the same scc */
70 scc *pscc; /**< the scc of this node */
71 unsigned POnum; /**< the post order number for blocks */
74 /** The environment. */
75 typedef struct iv_env {
76 struct obstack obst; /**< an obstack for allocations */
77 ir_node **stack; /**< the node stack */
78 int tos; /**< tos index */
79 unsigned nextDFSnum; /**< the current DFS number */
80 unsigned POnum; /**< current post order number */
81 set *quad_map; /**< a map from (op, iv, rc) to node */
82 set *lftr_edges; /**< the set of lftr edges */
83 unsigned replaced; /**< number of replaced ops */
84 unsigned lftr_replaced; /**< number of applied linear function test replacements */
85 unsigned flags; /**< additional flags */
86 /** Function called to process a SCC. */
87 void (*process_scc)(scc *pscc, struct iv_env *env);
91 * An entry in the (op, node, node) -> node map.
93 typedef struct quadruple_t {
94 ir_opcode code; /**< the opcode of the reduced operation */
95 ir_node *op1; /**< the first operand the reduced operation */
96 ir_node *op2; /**< the second operand of the reduced operation */
98 ir_node *res; /**< the reduced operation */
104 typedef struct LFTR_edge {
105 ir_node *src; /**< the source node */
106 ir_node *dst; /**< the destination node */
107 ir_opcode code; /**< the opcode that must be applied */
108 ir_node *rc; /**< the region const that must be applied */
112 static ir_node *reduce(ir_node *orig, ir_node *iv, ir_node *rc, iv_env *env);
115 * Compare two LFTR edges.
117 static int LFTR_cmp(const void *e1, const void *e2, size_t size) {
118 const LFTR_edge *l1 = e1;
119 const LFTR_edge *l2 = e2;
121 return l1->src != l2->src;
128 static LFTR_edge *LFTR_find(ir_node *src, iv_env *env) {
133 return set_find(env->lftr_edges, &key, sizeof(key), HASH_PTR(src));
140 static void LFTR_add(ir_node *src, ir_node *dst, ir_opcode code, ir_node *rc, iv_env *env) {
149 * There might be more than one edge here. This is rather bad
150 * because we currently store only one.
152 // assert(LFTR_find(src, env) == NULL);
153 set_insert(env->lftr_edges, &key, sizeof(key), HASH_PTR(src));
157 * Gets the node_entry of a node
159 static node_entry *get_irn_ne(ir_node *irn, iv_env *env) {
160 node_entry *e = get_irn_link(irn);
163 e = obstack_alloc(&env->obst, sizeof(*e));
164 memset(e, 0, sizeof(*e));
165 set_irn_link(irn, e);
171 * Check if irn is an IV.
173 * @param irn the node to check
174 * @param env the environment
176 * @returns the header if it is one, NULL else
178 static ir_node *is_iv(ir_node *irn, iv_env *env) {
179 return get_irn_ne(irn, env)->header;
183 * Check if irn is a region constant.
184 * The block or irn must strictly dominate the header block.
186 * @param irn the node to check
187 * @param header_block the header block of the induction variable
189 static int is_rc(ir_node *irn, ir_node *header_block) {
190 ir_node *block = get_nodes_block(irn);
192 return (block != header_block) && block_dominates(block, header_block);
196 * Set compare function for the quad set.
198 static int quad_cmp(const void *e1, const void *e2, size_t size) {
199 const quadruple_t *c1 = e1;
200 const quadruple_t *c2 = e2;
202 return c1->code != c2->code || c1->op1 != c2->op1 || c1->op2 != c2->op2;
206 * Check if an reduced operation was already calculated.
208 * @param code the opcode of the operation
209 * @param op1 the first operand of the operation
210 * @param op2 the second operand of the operation
211 * @param env the environment
213 * @return the already reduced node or NULL if this operation is not yet reduced
215 static ir_node *search(ir_opcode code, ir_node *op1, ir_node *op2, iv_env *env) {
216 quadruple_t key, *entry;
222 entry = set_find(env->quad_map, &key, sizeof(key),
223 (code * 9) ^ HASH_PTR(op1) ^HASH_PTR(op2));
230 * Add an reduced operation.
232 * @param code the opcode of the operation
233 * @param op1 the first operand of the operation
234 * @param op2 the second operand of the operation
235 * @param result the result of the reduced operation
236 * @param env the environment
238 static void add(ir_opcode code, ir_node *op1, ir_node *op2, ir_node *result, iv_env *env) {
246 set_insert(env->quad_map, &key, sizeof(key),
247 (code * 9) ^ HASH_PTR(op1) ^HASH_PTR(op2));
251 * Find a location where to place a bin-op whose operands are in
254 * @param block1 the block of the first operand
255 * @param block2 the block of the second operand
257 * Note that we know here that such a place must exists. Moreover, this means
258 * that either block1 dominates block2 or vice versa. So, just return
261 static ir_node *find_location(ir_node *block1, ir_node *block2) {
262 if (block_dominates(block1, block2))
264 assert(block_dominates(block2, block1));
269 * Create a node that executes an op1 code op1 operation.
271 * @param code the opcode to execute
272 * @param db debug info to add to the new node
273 * @param op1 the first operand
274 * @param op2 the second operand
275 * @param mode the mode of the new operation
277 * @return the newly created node
279 static ir_node *do_apply(ir_opcode code, dbg_info *db, ir_node *op1, ir_node *op2, ir_mode *mode) {
280 ir_graph *irg = current_ir_graph;
282 ir_node *block = find_location(get_nodes_block(op1), get_nodes_block(op2));
286 result = new_rd_Mul(db, irg, block, op1, op2, mode);
289 result = new_rd_Add(db, irg, block, op1, op2, mode);
292 result = new_rd_Sub(db, irg, block, op1, op2, mode);
302 * The Apply operation.
304 * @param orig the node that represent the original operation and determines
305 * the opcode, debug-info and mode of a newly created one
306 * @param op1 the first operand
307 * @param op2 the second operand
308 * @param env the environment
310 * @return the newly created node
312 static ir_node *apply(ir_node *orig, ir_node *op1, ir_node *op2, iv_env *env) {
313 ir_opcode code = get_irn_opcode(orig);
314 ir_node *result = search(code, op1, op2, env);
317 dbg_info *db = get_irn_dbg_info(orig);
318 ir_node *op1_header = get_irn_ne(op1, env)->header;
319 ir_node *op2_header = get_irn_ne(op2, env)->header;
321 if (op1_header != NULL && is_rc(op2, op1_header)) {
322 result = reduce(orig, op1, op2, env);
324 else if (op2_header != NULL && is_rc(op1, op2_header)) {
325 result = reduce(orig, op2, op1, env);
328 result = do_apply(code, db, op1, op2, get_irn_mode(orig));
329 get_irn_ne(result, env)->header = NULL; }
335 * The Reduce operation.
337 * @param orig the node that represent the original operation and determines
338 * the opcode, debug-info and mode of a newly created one
339 * @param iv the induction variable
340 * @param rc the region constant
341 * @param env the environment
343 * @return the reduced node
345 static ir_node *reduce(ir_node *orig, ir_node *iv, ir_node *rc, iv_env *env) {
346 ir_opcode code = get_irn_opcode(orig);
347 ir_node *result = search(code, iv, rc, env);
350 node_entry *e, *iv_e;
352 ir_mode *mode = get_irn_mode(orig);
354 result = exact_copy(iv);
356 /* Beware: we must always create a new nduction variable with the same mode
357 as the node we are replacing. Espicially this means the mode might be changed
358 from P to I and back. This is always possible, because we have only Phi, Add
360 set_irn_mode(result, mode);
361 add(code, iv, rc, result, env);
362 DB((dbg, LEVEL_3, " Created new %+F for %+F (%s %+F)\n", result, iv,
363 get_irn_opname(orig), rc));
365 iv_e = get_irn_ne(iv, env);
366 e = get_irn_ne(result, env);
367 e->header = iv_e->header;
369 /* create the LFTR edge */
370 LFTR_add(iv, result, code, rc, env);
372 n = get_irn_arity(result);
373 for (i = 0; i < n; ++i) {
374 ir_node *o = get_irn_n(result, i);
376 e = get_irn_ne(o, env);
377 if (e->header == iv_e->header)
378 o = reduce(orig, o, rc, env);
379 else if (is_Phi(result))
380 o = apply(orig, o, rc, env);
383 o = apply(orig, o, rc, env);
385 set_irn_n(result, i, o);
389 DB((dbg, LEVEL_3, " Already Created %+F for %+F (%s %+F)\n", result, iv,
390 get_irn_opname(orig), rc));
396 * The Replace operation.
398 * @param irn the node that will be replaced
399 * @param iv the induction variable
400 * @param rc the region constant
401 * @param env the environment
403 static int replace(ir_node *irn, ir_node *iv, ir_node *rc, iv_env *env) {
405 ir_loop *iv_loop = get_irn_loop(get_nodes_block(iv));
406 ir_loop *irn_loop = get_irn_loop(get_nodes_block(irn));
408 /* only replace nodes that are in the same (or deeper loops) */
409 if (get_loop_depth(irn_loop) >= get_loop_depth(iv_loop)) {
410 DB((dbg, LEVEL_2, " Replacing %+F\n", irn));
412 result = reduce(irn, iv, rc, env);
414 node_entry *e, *iv_e;
416 hook_strength_red(current_ir_graph, irn);
417 exchange(irn, result);
418 e = get_irn_ne(result, env);
419 iv_e = get_irn_ne(iv, env);
420 e->header = iv_e->header;
428 * Check if a node can be replaced (+, -, *).
430 * @param irn the node to check
431 * @param env the environment
433 * @return non-zero if irn should be Replace'd
435 static int check_replace(ir_node *irn, iv_env *env) {
436 ir_node *left, *right, *iv, *rc;
437 ir_op *op = get_irn_op(irn);
438 ir_opcode code = get_op_code(op);
447 left = get_binop_left(irn);
448 right = get_binop_right(irn);
450 liv = is_iv(left, env);
451 riv = is_iv(right, env);
452 if (liv && is_rc(right, liv)) {
453 iv = left; rc = right;
455 else if (riv && is_op_commutative(op) &&
457 iv = right; rc = left;
461 if (code == iro_Mul && env->flags & osr_flag_ignore_x86_shift) {
463 tarval *tv = get_Const_tarval(rc);
465 if (tarval_is_long(tv)) {
466 long value = get_tarval_long(tv);
468 if (value == 2 || value == 4 || value == 8) {
469 /* do not reduce multiplications by 2, 4, 8 */
476 return replace(irn, iv, rc, env);
486 * Check which SCC's are induction variables.
489 * @param env the environment
491 static void classify_iv(scc *pscc, iv_env *env) {
492 ir_node *irn, *next, *header = NULL;
493 node_entry *b, *h = NULL;
494 int j, only_phi, num_outside;
497 /* find the header block for this scc */
498 for (irn = pscc->head; irn; irn = next) {
499 node_entry *e = get_irn_link(irn);
500 ir_node *block = get_nodes_block(irn);
503 b = get_irn_ne(block, env);
506 if (h->POnum < b->POnum) {
517 /* check if this scc contains only Phi, Add or Sub nodes */
521 for (irn = pscc->head; irn; irn = next) {
522 node_entry *e = get_irn_ne(irn, env);
525 switch (get_irn_opcode(irn)) {
531 for (j = get_irn_arity(irn) - 1; j >= 0; --j) {
532 ir_node *pred = get_irn_n(irn, j);
533 node_entry *pe = get_irn_ne(pred, env);
535 if (pe->pscc != e->pscc) {
536 /* not in the same SCC, must be a region const */
537 if (! is_rc(pred, header)) {
538 /* not an induction variable */
544 } else if (out_rc != pred) {
551 /* not an induction variable */
555 /* found an induction variable */
556 DB((dbg, LEVEL_2, " Found an induction variable:\n "));
557 if (only_phi && num_outside == 1) {
558 /* a phi cycle with only one real predecessor can be collapsed */
559 DB((dbg, LEVEL_2, " Found an USELESS Phi cycle:\n "));
561 for (irn = pscc->head; irn; irn = next) {
562 node_entry *e = get_irn_ne(irn, env);
565 exchange(irn, out_rc);
571 /* set the header for every node in this scc */
572 for (irn = pscc->head; irn; irn = next) {
573 node_entry *e = get_irn_ne(irn, env);
576 DB((dbg, LEVEL_2, " %+F,", irn));
578 DB((dbg, LEVEL_2, "\n"));
582 for (irn = pscc->head; irn; irn = next) {
583 node_entry *e = get_irn_ne(irn, env);
586 if (! check_replace(irn, env))
592 * Process a SCC for the operator strength reduction.
594 * @param pscc the SCC
595 * @param env the environment
597 static void process_scc(scc *pscc, iv_env *env) {
598 ir_node *head = pscc->head;
599 node_entry *e = get_irn_link(head);
605 DB((dbg, LEVEL_4, " SCC at %p:\n ", pscc));
606 for (irn = pscc->head; irn; irn = next) {
607 node_entry *e = get_irn_link(irn);
611 DB((dbg, LEVEL_4, " %+F,", irn));
613 DB((dbg, LEVEL_4, "\n"));
617 if (e->next == NULL) {
618 /* this SCC has only a single member */
619 check_replace(head, env);
621 classify_iv(pscc, env);
626 * If an SCC is a Phi only cycle, remove it.
628 static void remove_phi_cycle(scc *pscc, iv_env *env) {
633 /* check if this scc contains only Phi, Add or Sub nodes */
635 for (irn = pscc->head; irn; irn = next) {
636 node_entry *e = get_irn_ne(irn, env);
642 for (j = get_irn_arity(irn) - 1; j >= 0; --j) {
643 ir_node *pred = get_irn_n(irn, j);
644 node_entry *pe = get_irn_ne(pred, env);
646 if (pe->pscc != e->pscc) {
647 /* not in the same SCC, must be the only input */
650 } else if (out_rc != pred) {
656 /* found a Phi cycle */
657 DB((dbg, LEVEL_2, " Found an USELESS Phi cycle:\n "));
659 for (irn = pscc->head; irn; irn = next) {
660 node_entry *e = get_irn_ne(irn, env);
663 exchange(irn, out_rc);
669 * Process a SCC for the Phi cycle removement.
671 * @param pscc the SCC
672 * @param env the environment
674 static void process_phi_only_scc(scc *pscc, iv_env *env) {
675 ir_node *head = pscc->head;
676 node_entry *e = get_irn_link(head);
682 DB((dbg, LEVEL_4, " SCC at %p:\n ", pscc));
683 for (irn = pscc->head; irn; irn = next) {
684 node_entry *e = get_irn_link(irn);
688 DB((dbg, LEVEL_4, " %+F,", irn));
690 DB((dbg, LEVEL_4, "\n"));
695 remove_phi_cycle(pscc, env);
700 * Push a node onto the stack.
702 * @param env the environment
703 * @param n the node to push
705 static void push(iv_env *env, ir_node *n) {
708 if (env->tos == ARR_LEN(env->stack)) {
709 int nlen = ARR_LEN(env->stack) * 2;
710 ARR_RESIZE(ir_node *, env->stack, nlen);
712 env->stack[env->tos++] = n;
713 e = get_irn_ne(n, env);
718 * pop a node from the stack
720 * @param env the environment
722 * @return The topmost node
724 static ir_node *pop(iv_env *env)
726 ir_node *n = env->stack[--env->tos];
727 node_entry *e = get_irn_ne(n, env);
734 * Do Tarjan's SCC algorithm and drive OSR.
736 * @param irn start at this node
737 * @param env the environment
739 static void dfs(ir_node *irn, iv_env *env)
742 node_entry *node = get_irn_ne(irn, env);
744 mark_irn_visited(irn);
746 /* do not put blocks into the scc */
748 n = get_irn_arity(irn);
749 for (i = 0; i < n; ++i) {
750 ir_node *pred = get_irn_n(irn, i);
752 if (irn_not_visited(pred))
757 ir_node *block = get_nodes_block(irn);
759 node->DFSnum = env->nextDFSnum++;
760 node->low = node->DFSnum;
763 /* handle the block */
764 if (irn_not_visited(block))
767 n = get_irn_arity(irn);
768 for (i = 0; i < n; ++i) {
769 ir_node *pred = get_irn_n(irn, i);
770 node_entry *o = get_irn_ne(pred, env);
772 if (irn_not_visited(pred)) {
774 node->low = MIN(node->low, o->low);
776 if (o->DFSnum < node->DFSnum && o->in_stack)
777 node->low = MIN(o->DFSnum, node->low);
779 if (node->low == node->DFSnum) {
780 scc *pscc = obstack_alloc(&env->obst, sizeof(*pscc));
788 e = get_irn_ne(x, env);
790 e->next = pscc->head;
794 env->process_scc(pscc, env);
800 * Do the DFS by starting at the End node of a graph.
802 * @param irg the graph to process
803 * @param env the environment
805 static void do_dfs(ir_graph *irg, iv_env *env) {
806 ir_graph *rem = current_ir_graph;
807 ir_node *end = get_irg_end(irg);
810 current_ir_graph = irg;
811 inc_irg_visited(irg);
813 /* visit all visible nodes */
816 /* visit the keep-alives */
817 n = get_End_n_keepalives(end);
818 for (i = 0; i < n; ++i) {
819 ir_node *ka = get_End_keepalive(end, i);
821 if (irn_not_visited(ka))
825 current_ir_graph = rem;
829 * Post-block-walker: assign the post-order number.
831 static void assign_po(ir_node *block, void *ctx) {
833 node_entry *e = get_irn_ne(block, env);
835 e->POnum = env->POnum++;
840 * Follows the LFTR edges and return the last node in the chain.
842 * @param irn the node that should be followed
843 * @param env the IV environment
846 * In the current implementation only the last edge is stored, so
847 * only one chain exists. That's why we might miss some opportunities.
849 static ir_node *followEdges(ir_node *irn, iv_env *env) {
851 LFTR_edge *e = LFTR_find(irn, env);
860 * Apply one LFTR edge operation.
861 * Return NULL if the transformation cannot be done safely without
864 * @param rc the IV node that should be translated
865 * @param e the LFTR edge
866 * @param env the IV environment
868 * @return the translated region constant or NULL
869 * if the translation was not possible
872 * In the current implementation only the last edge is stored, so
873 * only one chain exists. That's why we might miss some opportunities.
875 static ir_node *applyOneEdge(ir_node *rc, LFTR_edge *e, iv_env *env) {
876 if (env->flags & osr_flag_lftr_with_ov_check) {
877 tarval *tv_l, *tv_r, *tv;
878 tarval_int_overflow_mode_t ovmode;
880 /* overflow can only be decided for Consts */
881 if (! is_Const(e->rc)) {
882 DB((dbg, LEVEL_4, " = UNKNOWN (%+F)", e->rc));
886 tv_l = get_Const_tarval(rc);
887 tv_r = get_Const_tarval(e->rc);
889 ovmode = tarval_get_integer_overflow_mode();
890 tarval_set_integer_overflow_mode(TV_OVERFLOW_BAD);
894 tv = tarval_mul(tv_l, tv_r);
895 DB((dbg, LEVEL_4, " * %+F", tv_r));
898 tv = tarval_add(tv_l, tv_r);
899 DB((dbg, LEVEL_4, " + %+F", tv_r));
902 tv = tarval_sub(tv_l, tv_r);
903 DB((dbg, LEVEL_4, " - %+F", tv_r));
909 tarval_set_integer_overflow_mode(ovmode);
911 if (tv == tarval_bad) {
912 DB((dbg, LEVEL_4, " = OVERFLOW"));
915 return new_r_Const(current_ir_graph, get_irn_n(rc, -1), get_tarval_mode(tv), tv);
917 return do_apply(e->code, NULL, rc, e->rc, get_irn_mode(rc));
921 * Applies the operations represented by the LFTR edges to a
922 * region constant and returns the value.
923 * Return NULL if the transformation cannot be done safely without
926 * @param iv the IV node that starts the LFTR edge chain
927 * @param rc the region constant that should be translated
928 * @param env the IV environment
930 * @return the translated region constant or NULL
931 * if the translation was not possible
933 static ir_node *applyEdges(ir_node *iv, ir_node *rc, iv_env *env) {
936 if (env->flags & osr_flag_lftr_with_ov_check) {
937 /* overflow can only be decided for Consts */
938 if (! is_Const(rc)) {
939 DB((dbg, LEVEL_4, " = UNKNOWN (%+F)\n", rc));
942 DB((dbg, LEVEL_4, "%+F", get_Const_tarval(rc)));
945 for (irn = iv; rc;) {
946 LFTR_edge *e = LFTR_find(irn, env);
948 rc = applyOneEdge(rc, e, env);
954 DB((dbg, LEVEL_3, "\n"));
959 * Walker, finds Cmp(iv, rc) or Cmp(rc, iv)
960 * and tries to optimize them.
962 static void do_lftr(ir_node *cmp, void *ctx) {
964 ir_node *left, *right, *liv, *riv;
966 ir_node *nleft = NULL, *nright = NULL;
968 if (get_irn_op(cmp) != op_Cmp)
971 left = get_Cmp_left(cmp);
972 right = get_Cmp_right(cmp);
974 liv = is_iv(left, env);
975 riv = is_iv(right, env);
976 if (liv && is_rc(right, liv)) {
977 iv = left; rc = right;
979 nright = applyEdges(iv, rc, env);
980 if (nright && nright != rc) {
981 nleft = followEdges(iv, env);
984 else if (riv && is_rc(left, riv)) {
985 iv = right; rc = left;
987 nleft = applyEdges(iv, rc, env);
988 if (nleft && nleft != rc) {
989 nright = followEdges(iv, env);
993 if (nleft && nright) {
994 DB((dbg, LEVEL_2, " LFTR for %+F\n", cmp));
995 set_Cmp_left(cmp, nleft);
996 set_Cmp_right(cmp, nright);
997 ++env->lftr_replaced;
1002 * do linear function test replacement.
1004 * @param irg the graph that should be optimized
1005 * @param env the IV environment
1007 static void lftr(ir_graph *irg, iv_env *env) {
1008 irg_walk_graph(irg, NULL, do_lftr, env);
1013 * Pre-walker: set all node links to NULL and fix the
1014 * block of Proj nodes.
1016 static void clear_and_fix(ir_node *irn, void *env)
1018 set_irn_link(irn, NULL);
1021 ir_node *pred = get_Proj_pred(irn);
1022 set_irn_n(irn, -1, get_irn_n(pred, -1));
1026 /* Performs Operator Strength Reduction for the passed graph. */
1027 void opt_osr(ir_graph *irg, unsigned flags) {
1031 if (! get_opt_strength_red()) {
1032 /* only kill Phi cycles */
1033 remove_phi_cycles(irg);
1037 rem = current_ir_graph;
1038 current_ir_graph = irg;
1040 FIRM_DBG_REGISTER(dbg, "firm.opt.osr");
1042 DB((dbg, LEVEL_1, "Doing Operator Strength Reduction for %+F\n", irg));
1044 obstack_init(&env.obst);
1045 env.stack = NEW_ARR_F(ir_node *, 128);
1049 env.quad_map = new_set(quad_cmp, 64);
1050 env.lftr_edges = new_set(LFTR_cmp, 64);
1052 env.lftr_replaced = 0;
1054 env.process_scc = process_scc;
1056 /* Clear all links and move Proj nodes into the
1057 the same block as it's predecessors.
1058 This can improve the placement of new nodes.
1060 irg_walk_graph(irg, NULL, clear_and_fix, NULL);
1062 /* we need dominance */
1064 assure_irg_outs(irg);
1066 /* calculate the post order number for blocks. */
1067 irg_out_block_walk(get_irg_start_block(irg), NULL, assign_po, &env);
1069 /* calculate the SCC's and drive OSR. */
1073 /* try linear function test replacements */
1076 set_irg_outs_inconsistent(irg);
1077 DB((dbg, LEVEL_1, "Replacements: %u + %u (lftr)\n\n", env.replaced, env.lftr_replaced));
1080 del_set(env.lftr_edges);
1081 del_set(env.quad_map);
1082 DEL_ARR_F(env.stack);
1083 obstack_free(&env.obst, NULL);
1085 current_ir_graph = rem;
1088 /* Remove any Phi cycles with only one real input. */
1089 void remove_phi_cycles(ir_graph *irg) {
1093 rem = current_ir_graph;
1094 current_ir_graph = irg;
1096 FIRM_DBG_REGISTER(dbg, "firm.opt.remove_phi");
1098 DB((dbg, LEVEL_1, "Doing Phi cycle removement for %+F\n", irg));
1100 obstack_init(&env.obst);
1101 env.stack = NEW_ARR_F(ir_node *, 128);
1105 env.quad_map = NULL;
1106 env.lftr_edges = NULL;
1108 env.lftr_replaced = 0;
1110 env.process_scc = process_phi_only_scc;
1112 /* Clear all links and move Proj nodes into the
1113 the same block as it's predecessors.
1114 This can improve the placement of new nodes.
1116 irg_walk_graph(irg, NULL, clear_and_fix, NULL);
1118 /* we need dominance */
1119 assure_irg_outs(irg);
1121 /* calculate the post order number for blocks. */
1122 irg_out_block_walk(get_irg_start_block(irg), NULL, assign_po, &env);
1124 /* calculate the SCC's and drive OSR. */
1128 set_irg_outs_inconsistent(irg);
1129 DB((dbg, LEVEL_1, "remove_phi_cycles: %u Cycles removed\n\n", env.replaced));
1132 DEL_ARR_F(env.stack);
1133 obstack_free(&env.obst, NULL);
1135 current_ir_graph = rem;