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 boolean condition/control flow optimizations
23 * @author Matthias Braun, Christoph Mallon, Michael Beck
31 #include "../adt/array_t.h"
32 #include "iroptimize.h"
42 /** Describes a pair of relative conditions lo < hi, lo rel_lo x, hi rel_hi x */
43 typedef struct cond_pair {
44 ir_node *cmp_lo; /**< The lo compare node. */
45 ir_node *cmp_hi; /**< The hi compare node. */
46 ir_relation rel_lo; /**< The lo relation node. */
47 ir_relation rel_hi; /**< The hi relation node. */
48 ir_tarval *tv_lo; /**< The tarval of cmp_lo node. */
49 ir_tarval *tv_hi; /**< The tarval of cmp_hi node. */
50 ir_mode *lo_mode; /**< The mode of the cmp_lo operands. */
53 /** Environment for all walker in boolopt. */
55 int changed; /**< Set if the graph was changed. */
58 DEBUG_ONLY(static firm_dbg_module_t *dbg;)
61 * Check if tho given nodes, l and r, represent two compares with
62 * ... . If yes, return non-zero and fill the res struct.
64 static bool find_cond_pair(ir_node *const l, ir_node *const r, cond_pair *const res)
66 if (is_Cmp(l) && is_Cmp(r)) {
67 ir_node *const lol = get_Cmp_left(l);
68 ir_node *const lor = get_Cmp_right(l);
69 ir_node *const rol = get_Cmp_left(r);
70 ir_node *const ror = get_Cmp_right(r);
71 ir_relation const pnc_l = get_Cmp_relation(l);
72 ir_relation const pnc_r = get_Cmp_relation(r);
74 if (is_Const(lor) && is_Const_null(lor) &&
75 is_Const(ror) && is_Const_null(ror) &&
77 (pnc_l == ir_relation_less_greater || pnc_l == ir_relation_equal)) {
78 /* l == (lol !=|== NULL) && r == (rol !=|== NULL) */
83 res->tv_lo = get_Const_tarval(lor);
84 res->tv_hi = get_Const_tarval(ror);
85 res->lo_mode = get_irn_mode(lor);
90 if (lol == rol && lor != ror && is_Const(lor) && is_Const(ror)) {
91 /* l == (x CMP c_l), r == (x cmp c_r) */
92 ir_tarval *const tv_l = get_Const_tarval(lor);
93 ir_tarval *const tv_r = get_Const_tarval(ror);
94 ir_relation const rel = tarval_cmp(tv_l, tv_r);
96 res->lo_mode = get_irn_mode(lol);
98 if (rel == ir_relation_less) {
106 } else if (rel == ir_relation_greater) {
115 /* The constants shall be unequal but comparable.
116 * Local optimizations handle the equal case. */
126 * Handle (lo rel_lo x) AND (hi rel_hi x)
128 static ir_node *bool_and(cond_pair* const cpair, ir_node *dst_block)
130 ir_node *const cmp_lo = cpair->cmp_lo;
131 ir_node *const cmp_hi = cpair->cmp_hi;
132 ir_relation rel_lo = cpair->rel_lo;
133 ir_relation const rel_hi = cpair->rel_hi;
134 ir_tarval * tv_lo = cpair->tv_lo;
135 ir_tarval * tv_hi = cpair->tv_hi;
136 ir_mode * mode = cpair->lo_mode;
137 ir_graph * irg = get_irn_irg(cmp_lo);
139 if (rel_lo == ir_relation_equal && rel_hi == rel_lo &&
140 tarval_is_null(tv_lo) && tarval_is_null(tv_hi) &&
141 mode == get_tarval_mode(tv_hi)) {
142 /* p == NULL && q == NULL ==> (p&q) == NULL) */
143 ir_node *lol, *hil, *cmp, *c, *p;
145 if (mode_is_reference(mode)) {
146 mode = find_unsigned_mode(mode);
149 tv_lo = tarval_convert_to(tv_lo, mode);
150 if (tv_lo == tarval_bad)
153 if (mode_is_int(mode)) {
154 lol = get_Cmp_left(cmp_lo);
155 lol = new_r_Conv(dst_block, lol, mode);
156 hil = get_Cmp_left(cmp_hi);
157 hil = new_r_Conv(dst_block, hil, mode);
158 p = new_r_And(dst_block, lol, hil, mode);
159 c = new_r_Const(irg, tv_lo);
160 cmp = new_r_Cmp(dst_block, p, c, ir_relation_equal);
165 /* the following tests expect one common operand */
166 if (get_Cmp_left(cmp_lo) != get_Cmp_left(cmp_hi))
169 /* TODO: for now reject float modes */
170 if (! mode_is_int(mode))
173 /* Beware of NaN's, we can only check for (ordered) != here (which is Lg, not Ne) */
174 if ((rel_lo == ir_relation_less || rel_lo == ir_relation_less_equal || rel_lo == ir_relation_equal) &&
175 (rel_hi == ir_relation_equal || rel_hi == ir_relation_greater_equal || rel_hi == ir_relation_greater)) {
176 /* x <|<=|== lo && x ==|>=|> hi ==> false */
177 ir_node *const t = new_r_Const(irg, tarval_b_false);
179 } else if ((rel_lo == ir_relation_less || rel_lo == ir_relation_less_equal || rel_lo == ir_relation_equal) &&
180 (rel_hi == ir_relation_less || rel_hi == ir_relation_less_equal || rel_hi == ir_relation_less_greater)) {
181 /* x <|<=|== lo && x <|<=|!= hi ==> x <|<=|== lo */
183 } else if ((rel_lo == ir_relation_greater_equal || rel_lo == ir_relation_greater || rel_lo == ir_relation_less_greater) &&
184 (rel_hi == ir_relation_equal || rel_hi == ir_relation_greater_equal || rel_hi == ir_relation_greater)) {
185 /* x >=|>|!= lo && x ==|>=|> hi ==> x ==|>=|> hi */
187 } else if (tarval_is_one(tarval_sub(tv_hi, tv_lo, NULL))) { /* lo + 1 == hi */
188 if (rel_lo == ir_relation_greater_equal && rel_hi == ir_relation_less) {
189 /* x >= c && x < c + 1 ==> x == c */
190 ir_node *const p = new_r_Proj(cmp_lo, mode_b, ir_relation_equal);
192 } else if (rel_lo == ir_relation_greater) {
193 if (rel_hi == ir_relation_less_greater) {
194 /* x > c && x != c + 1 ==> x > c + 1 */
195 ir_node *const p = new_r_Proj(cmp_hi, mode_b, ir_relation_greater);
197 } else if (rel_hi == ir_relation_less) {
198 /* x > c && x < c + 1 ==> false */
199 ir_node *const t = new_r_Const(irg, tarval_b_false);
201 } else if (rel_hi == ir_relation_less_equal) {
202 /* x > c && x <= c + 1 ==> x != c + 1 */
203 ir_node *const p = new_r_Proj(cmp_hi, mode_b, ir_relation_equal);
206 } else if (rel_lo == ir_relation_less_greater && rel_hi == ir_relation_less) {
207 /* x != c && c < c + 1 ==> x < c */
208 ir_node *const p = new_r_Proj(cmp_lo, mode_b, ir_relation_less);
211 } else if ((rel_lo == ir_relation_greater || rel_lo == ir_relation_greater_equal) &&
212 (rel_hi == ir_relation_less || rel_lo == ir_relation_less_equal) &&
213 get_mode_arithmetic(mode) == irma_twos_complement) {
214 /* works for two-complements only */
215 /* x >|\= lo && x <|<= hi ==> (x - lo) <u|<=u (hi-lo) */
216 if (rel_lo == ir_relation_greater) {
217 /* must convert to >= */
218 ir_mode *mode = get_tarval_mode(tv_lo);
219 ir_tarval *n = tarval_add(tv_lo, get_mode_one(mode));
220 if (n != tarval_bad && tarval_cmp(n, tv_lo) == ir_relation_greater) {
223 rel_lo = ir_relation_greater_equal;
226 if (rel_lo == ir_relation_greater_equal) {
228 ir_node *const block = get_nodes_block(cmp_hi);
229 ir_node * x = get_Cmp_left(cmp_hi);
230 ir_mode * mode = get_irn_mode(x);
231 ir_node *sub, *cmp, *c, *subc;
233 if (mode_is_signed(mode)) {
234 /* convert to unsigned */
235 mode = find_unsigned_mode(mode);
238 x = new_r_Conv(block, x, mode);
239 tv_lo = tarval_convert_to(tv_lo, mode);
240 tv_hi = tarval_convert_to(tv_hi, mode);
241 if (tv_lo == tarval_bad || tv_hi == tarval_bad)
244 c = new_r_Const(irg, tv_lo);
245 sub = new_r_Sub(block, x, c, mode);
246 subc = new_r_Sub(block, new_r_Const(irg, tv_hi), c, mode);
247 cmp = new_r_Cmp(block, sub, subc, rel_hi);
255 * Handle (lo rel_lo x) OR (hi rel_hi x)
257 static ir_node *bool_or(cond_pair *const cpair, ir_node *dst_block)
259 ir_node *const cmp_lo = cpair->cmp_lo;
260 ir_node *const cmp_hi = cpair->cmp_hi;
261 ir_relation rel_lo = cpair->rel_lo;
262 ir_relation const rel_hi = cpair->rel_hi;
263 ir_tarval * tv_lo = cpair->tv_lo;
264 ir_tarval * tv_hi = cpair->tv_hi;
265 ir_mode * mode = cpair->lo_mode;
266 ir_graph * irg = get_irn_irg(cmp_lo);
268 if (rel_lo == ir_relation_less_greater && rel_hi == ir_relation_less_greater &&
269 tarval_is_null(tv_lo) && tarval_is_null(tv_hi) &&
270 mode == get_tarval_mode(tv_hi)) {
271 /* p != NULL || q != NULL ==> (p|q) != NULL) */
272 ir_node *lol, *hil, *cmp, *c, *p;
274 if (mode_is_reference(mode)) {
275 mode = find_unsigned_mode(mode);
278 tv_lo = tarval_convert_to(tv_lo, mode);
279 if (tv_lo == tarval_bad)
282 if (mode_is_int(mode)) {
283 lol = get_Cmp_left(cmp_lo);
284 lol = new_r_Conv(dst_block, lol, mode);
285 hil = get_Cmp_left(cmp_hi);
286 hil = new_r_Conv(dst_block, hil, mode);
287 p = new_r_Or(dst_block, lol, hil, mode);
288 c = new_r_Const(irg, tv_lo);
289 cmp = new_r_Cmp(dst_block, p, c, ir_relation_less_greater);
294 /* the following tests expect one common operand */
295 if (get_Cmp_left(cmp_lo) != get_Cmp_left(cmp_hi))
298 /* TODO: for now reject float modes */
299 if (! mode_is_int(mode))
302 /* Beware of NaN's, we can only check for (ordered) != here (which is Lg, not Ne) */
303 if ((rel_lo == ir_relation_greater_equal || rel_lo == ir_relation_greater || rel_lo == ir_relation_less_greater) &&
304 (rel_hi == ir_relation_less || rel_hi == ir_relation_less_equal || rel_hi == ir_relation_less_greater)) {
305 /* x >=|>|!= lo | x <|<=|!= hi ==> true */
306 ir_node *const t = new_r_Const(irg, tarval_b_true);
308 } else if ((rel_lo == ir_relation_less || rel_lo == ir_relation_less_equal || rel_lo == ir_relation_equal) &&
309 (rel_hi == ir_relation_less || rel_hi == ir_relation_less_equal || rel_hi == ir_relation_less_greater)) {
310 /* x <|<=|== lo || x <|<=|!= hi ==> x <|<=|!= hi */
312 } else if ((rel_lo == ir_relation_greater_equal || rel_lo == ir_relation_greater || rel_lo == ir_relation_less_greater) &&
313 (rel_hi == ir_relation_equal || rel_hi == ir_relation_greater_equal || rel_hi == ir_relation_greater)) {
314 /* x >=|>|!= lo || x ==|>=|> hi ==> x >=|>|!= lo */
316 } else if (tarval_is_one(tarval_sub(tv_hi, tv_lo, NULL))) { /* lo + 1 == hi */
317 if (rel_lo == ir_relation_less && rel_hi == ir_relation_greater_equal) {
318 /* x < c || x >= c + 1 ==> x != c */
319 ir_node *const p = new_r_Proj(cmp_lo, mode_b, ir_relation_less_greater);
321 } else if (rel_lo == ir_relation_less_equal) {
322 if (rel_hi == ir_relation_equal) {
323 /* x <= c || x == c + 1 ==> x <= c + 1 */
324 ir_node *const p = new_r_Proj(cmp_hi, mode_b, ir_relation_less_equal);
326 } else if (rel_hi == ir_relation_greater_equal) {
327 /* x <= c || x >= c + 1 ==> true */
328 ir_node *const t = new_r_Const(irg, tarval_b_true);
330 } else if (rel_hi == ir_relation_greater) {
331 /* x <= c || x > c + 1 ==> x != c + 1 */
332 ir_node *const p = new_r_Proj(cmp_hi, mode_b, ir_relation_less_greater);
335 } else if (rel_lo == ir_relation_equal && rel_hi == ir_relation_greater_equal) {
336 /* x == c || x >= c + 1 ==> x >= c */
337 ir_node *const p = new_r_Proj(cmp_lo, mode_b, ir_relation_greater_equal);
340 } else if ((rel_lo == ir_relation_less || rel_lo == ir_relation_less_equal) &&
341 (rel_hi == ir_relation_greater || rel_lo == ir_relation_greater_equal) &&
342 get_mode_arithmetic(mode) == irma_twos_complement) {
343 /* works for two-complements only */
344 /* x <|<= lo || x >|>= hi ==> (x - lo) >u|>=u (hi-lo) */
345 if (rel_lo == ir_relation_less_equal) {
346 /* must convert to < */
347 ir_mode *mode = get_tarval_mode(tv_lo);
348 ir_tarval *n = tarval_add(tv_lo, get_mode_one(mode));
349 if (n != tarval_bad && tarval_cmp(n, tv_lo) == ir_relation_greater) {
352 rel_lo = ir_relation_less;
355 if (rel_lo == ir_relation_less) {
357 ir_node *const block = get_nodes_block(cmp_hi);
358 ir_node * x = get_Cmp_left(cmp_hi);
359 ir_mode * mode = get_irn_mode(x);
360 ir_node *sub, *cmp, *c, *subc;
362 if (mode_is_signed(mode)) {
363 /* convert to unsigned */
364 mode = find_unsigned_mode(mode);
367 x = new_r_Conv(block, x, mode);
368 tv_lo = tarval_convert_to(tv_lo, mode);
369 tv_hi = tarval_convert_to(tv_hi, mode);
370 if (tv_lo == tarval_bad || tv_hi == tarval_bad)
373 c = new_r_Const(irg, tv_lo);
374 sub = new_r_Sub(block, x, c, mode);
375 subc = new_r_Sub(block, new_r_Const(irg, tv_hi), c, mode);
376 cmp = new_r_Cmp(block, sub, subc, rel_hi);
384 * Walker, tries to optimize Andb and Orb nodes.
386 static void bool_walk(ir_node *n, void *ctx)
388 bool_opt_env_t *env = (bool_opt_env_t*)ctx;
390 if (get_irn_mode(n) != mode_b)
394 ir_node *const l = get_And_left(n);
395 ir_node *const r = get_And_right(n);
396 ir_node * replacement;
398 if (!find_cond_pair(l, r, &cpair))
400 replacement = bool_and(&cpair, get_nodes_block(n));
402 exchange(n, replacement);
405 } else if (is_Or(n)) {
406 ir_node *const l = get_Or_left(n);
407 ir_node *const r = get_Or_right(n);
408 ir_node * replacement;
410 if (!find_cond_pair(l, r, &cpair))
412 replacement = bool_or(&cpair, get_nodes_block(n));
414 exchange(n, replacement);
421 * Walker, clear Block marker and Phi lists.
423 static void clear_block_infos(ir_node *node, void *env)
427 /* we visit blocks before any other nodes (from the block) */
431 /* clear the PHI list */
432 set_Block_phis(node, NULL);
433 set_Block_mark(node, 0);
437 * Walker: collect Phi nodes and mark
439 static void collect_phis(ir_node *node, void *env)
444 ir_node *block = get_nodes_block(node);
445 add_Block_phi(block, node);
449 /* Ignore control flow nodes, these will be removed. */
450 if (get_irn_pinned(node) == op_pin_state_pinned &&
451 !is_Block(node) && !is_cfop(node)) {
452 /* found a pinned non-cf node, mark its block */
453 ir_node *block = get_nodes_block(node);
454 set_Block_mark(block, 1);
459 * If node is a Jmp in a block containing no pinned instruction
460 * and having only one predecessor, skip the block and return its
461 * cf predecessor, else the node itself.
463 static ir_node *skip_empty_blocks(ir_node *node)
465 while (is_Jmp(node)) {
466 ir_node *block = get_nodes_block(node);
468 if (get_Block_n_cfgpreds(block) != 1)
471 if (get_Block_mark(block))
474 node = get_Block_cfgpred(block, 0);
480 * Check if two block inputs can be fused.
481 * This can be done, if block contains no Phi node that depends on
482 * different inputs idx_i and idx_j.
484 static int can_fuse_block_inputs(const ir_node *block, int idx_i, int idx_j)
488 for (phi = get_Block_phis(block); phi != NULL; phi = get_Phi_next(phi)) {
489 if (get_Phi_pred(phi, idx_i) != get_Phi_pred(phi, idx_j))
496 * Remove block input with given index.
498 static void remove_block_input(ir_node *block, int idx)
500 int i, j, n = get_Block_n_cfgpreds(block) - 1;
503 NEW_ARR_A(ir_node *, ins, n);
506 /* all Phis will be deleted */
509 for (phi = get_Block_phis(block); phi != NULL; phi = next_phi) {
510 next_phi = get_Phi_next(phi);
511 exchange(phi, get_Phi_pred(phi, idx ^ 1));
513 set_Block_phis(block, NULL);
515 for (phi = get_Block_phis(block); phi != NULL; phi = get_Phi_next(phi)) {
516 for (i = j = 0; i <= n; ++i) {
518 ins[j++] = get_Phi_pred(phi, i);
520 set_irn_in(phi, n, ins);
523 for (i = j = 0; i <= n; ++i) {
525 ins[j++] = get_Block_cfgpred(block, i);
527 set_irn_in(block, n, ins);
531 * Under the preposition that we have a chain of blocks from
532 * from_block to to_block, collapse them all into to_block.
534 static void move_nodes_to_block(ir_node *jmp, ir_node *to_block)
536 ir_node *new_jmp = NULL;
537 ir_node *block, *next_block;
539 for (block = get_nodes_block(jmp); block != to_block; block = next_block) {
540 new_jmp = get_Block_cfgpred(block, 0);
541 next_block = get_nodes_block(new_jmp);
542 exchange(block, to_block);
545 exchange(jmp, new_jmp);
551 * if we can find the following structure,
562 * try to convert it into a (x rel_lo c_lo) || (x rel_hi c_hi)
565 static void find_cf_and_or_walker(ir_node *block, void *ctx)
567 bool_opt_env_t *env = (bool_opt_env_t*)ctx;
571 /* because we modify the graph in regions we might not visited yet,
572 * Id nodes might arise here. Ignore them.
577 n_cfgpreds = get_Block_n_cfgpreds(block);
582 for (low_idx = 0; low_idx < n_cfgpreds; ++low_idx) {
583 ir_node *lower_block;
586 ir_node *cond_selector;
589 lower_cf = get_Block_cfgpred(block, low_idx);
590 lower_cf = skip_empty_blocks(lower_cf);
591 if (!is_Proj(lower_cf))
594 cond = get_Proj_pred(lower_cf);
598 lower_block = get_nodes_block(cond);
599 if (get_Block_n_cfgpreds(lower_block) != 1)
602 /* the block must not produce any side-effects */
603 if (get_Block_mark(lower_block))
606 cond_selector = get_Cond_selector(cond);
607 if (get_irn_mode(cond_selector) != mode_b)
610 lower_pred = get_Block_cfgpred_block(lower_block, 0);
612 for (up_idx = 0; up_idx < n_cfgpreds; ++up_idx) {
613 ir_node *upper_block;
616 ir_node *upper_cond_selector;
617 ir_node *replacement;
620 upper_cf = get_Block_cfgpred(block, up_idx);
621 upper_cf = skip_empty_blocks(upper_cf);
622 if (is_Bad(upper_cf))
624 upper_block = get_nodes_block(upper_cf);
625 if (upper_block != lower_pred)
627 if (!block_dominates(upper_block, block))
630 assert(is_Proj(upper_cf));
631 upper_cond = get_Proj_pred(upper_cf);
632 assert(is_Cond(upper_cond));
633 upper_cond_selector = get_Cond_selector(upper_cond);
634 if (get_irn_mode(upper_cond_selector) != mode_b)
637 /* we have found the structure */
638 /* check Phis: There must be NO Phi in block that
639 depends on the existence of low block */
640 if (!can_fuse_block_inputs(block, low_idx, up_idx))
643 /* all fine, try it */
644 if (!find_cond_pair(cond_selector, upper_cond_selector, &cpair))
647 /* normalize pncs: we need the true case to jump into the
648 * common block (ie. conjunctive normal form) */
649 if (get_Proj_proj(lower_cf) == pn_Cond_false) {
650 if (cpair.cmp_lo == cond_selector) {
651 ir_node *cmp = cpair.cmp_lo;
652 ir_node *block = get_nodes_block(cmp);
653 dbg_info *dbgi = get_irn_dbg_info(cmp);
654 cpair.rel_lo = get_negated_relation(cpair.rel_lo);
655 cpair.cmp_lo = new_rd_Cmp(dbgi, block,
656 get_Cmp_left(cmp), get_Cmp_right(cmp), cpair.rel_lo);
658 ir_node *cmp = cpair.cmp_hi;
659 ir_node *block = get_nodes_block(cmp);
660 dbg_info *dbgi = get_irn_dbg_info(cmp);
661 assert(cmp == cond_selector);
662 cpair.rel_hi = get_negated_relation(cpair.rel_hi);
663 cpair.cmp_hi = new_rd_Cmp(dbgi, block,
664 get_Cmp_left(cmp), get_Cmp_right(cmp), cpair.rel_hi);
667 if (get_Proj_proj(upper_cf) == pn_Cond_false) {
668 if (cpair.cmp_lo == upper_cond_selector) {
669 ir_node *cmp = cpair.cmp_lo;
670 ir_node *block = get_nodes_block(cmp);
671 dbg_info *dbgi = get_irn_dbg_info(cmp);
672 cpair.rel_lo = get_negated_relation(cpair.rel_lo);
673 cpair.cmp_lo = new_rd_Cmp(dbgi, block,
674 get_Cmp_left(cmp), get_Cmp_right(cmp), cpair.rel_lo);
676 ir_node *cmp = cpair.cmp_hi;
677 ir_node *block = get_nodes_block(cmp);
678 dbg_info *dbgi = get_irn_dbg_info(cmp);
679 assert(cmp == upper_cond_selector);
680 cpair.rel_hi = get_negated_relation(cpair.rel_hi);
681 cpair.cmp_hi = new_rd_Cmp(dbgi, block,
682 get_Cmp_left(cmp), get_Cmp_right(cmp), cpair.rel_hi);
686 /* can we optimize the case? */
687 replacement = bool_or(&cpair, upper_block);
688 if (replacement == NULL)
693 DB((dbg, LEVEL_1, "boolopt: %+F: fusing (ub %+F lb %+F)\n",
694 get_irn_irg(upper_block), upper_block, lower_block));
696 /* move all expressions on the path to lower/upper block */
697 move_nodes_to_block(get_Block_cfgpred(block, up_idx), upper_block);
698 move_nodes_to_block(get_Block_cfgpred(block, low_idx), lower_block);
700 /* move all nodes from lower block to upper block */
701 exchange(lower_block, upper_block);
703 remove_block_input(block, up_idx);
706 /* the optimizations expected the true case to jump */
707 if (get_Proj_proj(lower_cf) == pn_Cond_false) {
708 ir_node *block = get_nodes_block(replacement);
709 replacement = new_rd_Not(NULL, block, replacement, mode_b);
711 set_Cond_selector(cond, replacement);
718 void opt_bool(ir_graph *const irg)
722 /* register a debug mask */
723 FIRM_DBG_REGISTER(dbg, "firm.opt.bool");
727 /* optimize simple Andb and Orb cases */
728 irg_walk_graph(irg, NULL, bool_walk, &env);
730 /* now more complicated cases: find control flow And/Or and optimize. */
731 ir_reserve_resources(irg, IR_RESOURCE_BLOCK_MARK | IR_RESOURCE_PHI_LIST);
732 irg_walk_graph(irg, clear_block_infos, collect_phis, NULL);
733 irg_block_walk_graph(irg, NULL, find_cf_and_or_walker, &env);
734 ir_free_resources(irg, IR_RESOURCE_BLOCK_MARK | IR_RESOURCE_PHI_LIST);
736 confirm_irg_properties(irg,
737 env.changed ? IR_GRAPH_PROPERTIES_NONE : IR_GRAPH_PROPERTIES_ALL);
740 /* Creates an ir_graph pass for opt_bool. */
741 ir_graph_pass_t *opt_bool_pass(const char *name)
743 return def_graph_pass(name ? name : "opt_bool", opt_bool);