Lines Matching refs:sm

103 static void print_debug_tf(struct sm_state *sm, int istrue, int isfalse)  in print_debug_tf()  argument
109 printf("%s: %d: does not exist.\n", show_sm(sm), sm->line); in print_debug_tf()
111 printf("'%s = %s' from %d is true. %s[stree %d]\n", sm->name, show_state(sm->state), in print_debug_tf()
112 sm->line, sm->merged ? "[merged]" : "[leaf]", in print_debug_tf()
113 get_stree_id(sm->pool)); in print_debug_tf()
115 printf("'%s = %s' from %d is false. %s[stree %d]\n", sm->name, show_state(sm->state), in print_debug_tf()
116 sm->line, in print_debug_tf()
117 sm->merged ? "[merged]" : "[leaf]", in print_debug_tf()
118 get_stree_id(sm->pool)); in print_debug_tf()
120 printf("'%s = %s' from %d could be true or false. %s[stree %d]\n", sm->name, in print_debug_tf()
121 show_state(sm->state), sm->line, in print_debug_tf()
122 sm->merged ? "[merged]" : "[leaf]", in print_debug_tf()
123 get_stree_id(sm->pool)); in print_debug_tf()
139 static int create_fake_history(struct sm_state *sm, int comparison, struct range_list *rl) in create_fake_history() argument
147 if (is_merged(sm) || sm->left || sm->right) in create_fake_history()
151 if (!estate_rl(sm->state)) in create_fake_history()
154 orig_rl = cast_rl(rl_type(rl), estate_rl(sm->state)); in create_fake_history()
157 true_rl = rl_truncate_cast(estate_type(sm->state), true_rl); in create_fake_history()
158 false_rl = rl_truncate_cast(estate_type(sm->state), false_rl); in create_fake_history()
162 rl_equiv(estate_rl(sm->state), true_rl) || rl_equiv(estate_rl(sm->state), false_rl)) in create_fake_history()
178 sm->name, show_rl(rl), sm->state->name, show_comparison(comparison), show_rl(rl), in create_fake_history()
181 true_sm = clone_sm(sm); in create_fake_history()
182 false_sm = clone_sm(sm); in create_fake_history()
184 true_sm->state = clone_partial_estate(sm->state, true_rl); in create_fake_history()
187 false_sm->state = clone_partial_estate(sm->state, false_rl); in create_fake_history()
191 true_stree = clone_stree(sm->pool); in create_fake_history()
192 false_stree = clone_stree(sm->pool); in create_fake_history()
200 sm->merged = 1; in create_fake_history()
201 sm->left = true_sm; in create_fake_history()
202 sm->right = false_sm; in create_fake_history()
287 static void do_compare(struct sm_state *sm, int comparison, struct range_list *rl, in do_compare() argument
297 if (!sm->pool) in do_compare()
300 var_rl = cast_rl(rl_type(rl), estate_rl(sm->state)); in do_compare()
305 print_debug_tf(sm, istrue, isfalse); in do_compare()
308 if (sm->sym != gate_sm->sym || in do_compare()
309 strcmp(sm->name, gate_sm->name) != 0) { in do_compare()
314 if (mixed && !*mixed && !is_merged(sm) && !istrue && !isfalse) { in do_compare()
315 if (!create_fake_history(sm, comparison, rl)) in do_compare()
320 add_pool(true_stack, sm); in do_compare()
322 add_pool(false_stack, sm); in do_compare()
324 add_pool(maybe_stack, sm); in do_compare()
327 static int is_checked(struct state_list *checked, struct sm_state *sm) in is_checked() argument
332 if (tmp == sm) in is_checked()
346 static void __separate_pools(struct sm_state *sm, int comparison, struct range_list *rl, in __separate_pools() argument
357 if (!sm) in __separate_pools()
365 __func__, sm->state->name, show_comparison(comparison), show_rl(rl)); in __separate_pools()
375 if (is_checked(*checked, sm)) in __separate_pools()
377 add_ptr_list(checked, sm); in __separate_pools()
379 do_compare(sm, comparison, rl, true_stack, maybe_stack, false_stack, mixed, gate_sm); in __separate_pools()
381 …__separate_pools(sm->left, comparison, rl, true_stack, maybe_stack, false_stack, checked, mixed, g… in __separate_pools()
382 …__separate_pools(sm->right, comparison, rl, true_stack, maybe_stack, false_stack, checked, mixed, … in __separate_pools()
387 static void separate_pools(struct sm_state *sm, int comparison, struct range_list *rl, in separate_pools() argument
398 …__separate_pools(sm, comparison, rl, true_stack, &maybe_stack, false_stack, checked, mixed, sm, &s… in separate_pools()
401 struct sm_state *sm; in separate_pools() local
403 FOR_EACH_PTR(*true_stack, sm) { in separate_pools()
404 sm_msg("TRUE %s [stree %d]", show_sm(sm), get_stree_id(sm->pool)); in separate_pools()
405 } END_FOR_EACH_PTR(sm); in separate_pools()
407 FOR_EACH_PTR(maybe_stack, sm) { in separate_pools()
409 show_sm(sm), sm->merged ? "(merged) ": "", get_stree_id(sm->pool)); in separate_pools()
410 } END_FOR_EACH_PTR(sm); in separate_pools()
412 FOR_EACH_PTR(*false_stack, sm) { in separate_pools()
413 sm_msg("FALSE %s [stree %d]", show_sm(sm), get_stree_id(sm->pool)); in separate_pools()
414 } END_FOR_EACH_PTR(sm); in separate_pools()
429 static int sm_in_keep_leafs(struct sm_state *sm, const struct state_list *keep_gates) in sm_in_keep_leafs() argument
436 old = get_sm_state_stree(tmp->pool, sm->owner, sm->name, sm->sym); in sm_in_keep_leafs()
439 if (old == sm) in sm_in_keep_leafs()
468 static char *sm_state_info(struct sm_state *sm) in sm_state_info() argument
474 get_stree_id(sm->pool), sm->line); in sm_state_info()
477 n += snprintf(buf + n, sizeof(buf) - n, "%s ", show_sm(sm)); in sm_state_info()
481 sm->left ? sm->left->state->name : "<none>", in sm_state_info()
482 sm->left ? get_stree_id(sm->left->pool) : -1); in sm_state_info()
486 sm->right ? sm->right->state->name : "<none>", in sm_state_info()
487 sm->right ? get_stree_id(sm->right->pool) : -1); in sm_state_info()
499 struct sm_state *filter_pools(struct sm_state *sm, in filter_pools() argument
511 if (!sm) in filter_pools()
518 DIMPLIED("%s: implications taking too long: %s\n", __func__, sm_state_info(sm)); in filter_pools()
523 DIMPLIED("%s: recursed too far: %s\n", __func__, sm_state_info(sm)); in filter_pools()
528 if (pool_in_pools(sm->pool, remove_stack)) { in filter_pools()
529 DIMPLIED("%s: remove: %s\n", __func__, sm_state_info(sm)); in filter_pools()
534 if (!is_merged(sm) || pool_in_pools(sm->pool, keep_stack) || sm_in_keep_leafs(sm, keep_stack)) { in filter_pools()
535 DIMPLIED("%s: keep %s (%s, %s, %s): %s\n", __func__, sm->state->name, in filter_pools()
536 is_merged(sm) ? "merged" : "not merged", in filter_pools()
537 pool_in_pools(sm->pool, keep_stack) ? "not in keep pools" : "in keep pools", in filter_pools()
538 sm_in_keep_leafs(sm, keep_stack) ? "reachable keep leaf" : "no keep leaf", in filter_pools()
539 sm_state_info(sm)); in filter_pools()
540 return sm; in filter_pools()
543 left = filter_pools(sm->left, remove_stack, keep_stack, &removed, recurse_cnt, start, skip, bail); in filter_pools()
544 …right = filter_pools(sm->right, remove_stack, keep_stack, &removed, recurse_cnt, start, skip, bail… in filter_pools()
548 DIMPLIED("%s: kept all: %s\n", __func__, sm_state_info(sm)); in filter_pools()
549 return sm; in filter_pools()
553 DIMPLIED("%s: removed all: %s\n", __func__, sm_state_info(sm)); in filter_pools()
568 if (left->sym != sm->sym || strcmp(left->name, sm->name) != 0) { in filter_pools()
570 left->sym = sm->sym; in filter_pools()
571 left->name = sm->name; in filter_pools()
573 if (right->sym != sm->sym || strcmp(right->name, sm->name) != 0) { in filter_pools()
575 right->sym = sm->sym; in filter_pools()
576 right->name = sm->name; in filter_pools()
581 ret->pool = sm->pool; in filter_pools()
583 DIMPLIED("%s: partial: %s\n", __func__, sm_state_info(sm)); in filter_pools()
628 static void separate_and_filter(struct sm_state *sm, int comparison, struct range_list *rl, in separate_and_filter() argument
643 sm->name, sm->state->name, show_comparison(comparison), show_rl(rl)); in separate_and_filter()
645 if (!is_merged(sm)) { in separate_and_filter()
646 DIMPLIED("%d '%s' from line %d is not merged.\n", get_lineno(), sm->name, sm->line); in separate_and_filter()
650 separate_pools(sm, comparison, rl, &true_stack, &false_stack, NULL, mixed); in separate_and_filter()
653 *true_states = filter_stack(sm, pre_stree, false_stack, true_stack); in separate_and_filter()
655 *false_states = filter_stack(sm, pre_stree, true_stack, false_stack); in separate_and_filter()
699 struct sm_state *sm; in is_merged_expr() local
704 sm = get_sm_state_expr(SMATCH_EXTRA, expr); in is_merged_expr()
705 if (!sm) in is_merged_expr()
707 if (is_merged(sm)) in is_merged_expr()
734 struct sm_state *sm = NULL; in handle_comparison() local
746 sm = get_sm_state_expr(SMATCH_EXTRA, left); in handle_comparison()
749 sm = get_sm_state_expr(SMATCH_EXTRA, right); in handle_comparison()
754 if (!rl || !sm) in handle_comparison()
766 separate_and_filter(sm, comparison, rl, __get_cur_stree(), implied_true, implied_false, &mixed); in handle_comparison()
768 delete_gate_sm_equiv(implied_true, sm->name, sm->sym); in handle_comparison()
769 delete_gate_sm_equiv(implied_false, sm->name, sm->sym); in handle_comparison()
771 delete_gate_sm(implied_true, sm->name, sm->sym); in handle_comparison()
772 delete_gate_sm(implied_false, sm->name, sm->sym); in handle_comparison()
784 struct sm_state *sm; in handle_zero_comparison() local
801 sm = get_sm_state(SMATCH_EXTRA, name, sym); in handle_zero_comparison()
802 if (!sm || !sm->merged) in handle_zero_comparison()
805 …separate_and_filter(sm, SPECIAL_NOTEQUAL, tmp_range_list(estate_type(sm->state), 0), __get_cur_str… in handle_zero_comparison()
806 delete_gate_sm_equiv(implied_true, sm->name, sm->sym); in handle_zero_comparison()
807 delete_gate_sm_equiv(implied_false, sm->name, sm->sym); in handle_zero_comparison()
809 delete_gate_sm(implied_true, sm->name, sm->sym); in handle_zero_comparison()
810 delete_gate_sm(implied_false, sm->name, sm->sym); in handle_zero_comparison()
823 struct sm_state *sm, *true_sm, *false_sm; in handled_by_comparison_hook() local
828 sm = comparison_implication_hook(expr, &true_stack, &false_stack); in handled_by_comparison_hook()
829 if (!sm) in handled_by_comparison_hook()
834 *implied_true = filter_stack(sm, pre_stree, false_stack, true_stack); in handled_by_comparison_hook()
835 *implied_false = filter_stack(sm, pre_stree, true_stack, false_stack); in handled_by_comparison_hook()
837 true_sm = get_sm_state_stree(*implied_true, sm->owner, sm->name, sm->sym); in handled_by_comparison_hook()
838 false_sm = get_sm_state_stree(*implied_false, sm->owner, sm->name, sm->sym); in handled_by_comparison_hook()
840 delete_state_stree(implied_true, sm->owner, sm->name, sm->sym); in handled_by_comparison_hook()
842 delete_state_stree(implied_false, sm->owner, sm->name, sm->sym); in handled_by_comparison_hook()
874 struct sm_state *sm; in handled_by_parsed_conditions() local
876 sm = parsed_condition_implication_hook(expr, &true_stack, &false_stack); in handled_by_parsed_conditions()
877 if (!sm) in handled_by_parsed_conditions()
882 *implied_true = filter_stack(sm, pre_stree, false_stack, true_stack); in handled_by_parsed_conditions()
883 *implied_false = filter_stack(sm, pre_stree, true_stack, false_stack); in handled_by_parsed_conditions()
899 struct sm_state *sm; in handled_by_stored_conditions() local
901 sm = stored_condition_implication_hook(expr, &true_stack, &false_stack); in handled_by_stored_conditions()
902 if (!sm) in handled_by_stored_conditions()
907 *implied_true = filter_stack(sm, pre_stree, false_stack, true_stack); in handled_by_stored_conditions()
908 *implied_false = filter_stack(sm, pre_stree, true_stack, false_stack); in handled_by_stored_conditions()
926 struct sm_state *sm; in separate_implication_states() local
929 FOR_EACH_SM(*implied_true, sm) { in separate_implication_states()
930 if (sm->owner == owner) in separate_implication_states()
931 overwrite_sm_state_stree(&extra_saved_implied_true, sm); in separate_implication_states()
932 } END_FOR_EACH_SM(sm); in separate_implication_states()
933 FOR_EACH_SM(extra_saved_implied_true, sm) { in separate_implication_states()
934 delete_state_stree(implied_true, sm->owner, sm->name, sm->sym); in separate_implication_states()
935 } END_FOR_EACH_SM(sm); in separate_implication_states()
937 FOR_EACH_SM(*implied_false, sm) { in separate_implication_states()
938 if (sm->owner == owner) in separate_implication_states()
939 overwrite_sm_state_stree(&extra_saved_implied_false, sm); in separate_implication_states()
940 } END_FOR_EACH_SM(sm); in separate_implication_states()
941 FOR_EACH_SM(extra_saved_implied_false, sm) { in separate_implication_states()
942 delete_state_stree(implied_false, sm->owner, sm->name, sm->sym); in separate_implication_states()
943 } END_FOR_EACH_SM(sm); in separate_implication_states()
976 struct sm_state *sm; in set_implied_states() local
990 FOR_EACH_SM(saved_implied_true, sm) { in set_implied_states()
991 __set_true_false_sm(sm, NULL); in set_implied_states()
992 } END_FOR_EACH_SM(sm); in set_implied_states()
995 FOR_EACH_SM(saved_implied_false, sm) { in set_implied_states()
996 __set_true_false_sm(NULL, sm); in set_implied_states()
997 } END_FOR_EACH_SM(sm); in set_implied_states()
1016 struct sm_state *sm; in param_limit_implications() local
1046 sm = get_sm_state(SMATCH_EXTRA, name, sym); in param_limit_implications()
1047 if (!sm || !sm->merged) in param_limit_implications()
1055 orig = estate_rl(sm->state); in param_limit_implications()
1060 …separate_and_filter(sm, PARAM_LIMIT, limit, __get_cur_stree(), &implied_true, &implied_false, &mix… in param_limit_implications()
1096 struct sm_state *sm; in __implied_case_stree() local
1110 sm = get_sm_state_stree(*raw_stree, SMATCH_EXTRA, name, sym); in __implied_case_stree()
1111 if (sm) in __implied_case_stree()
1112 separate_and_filter(sm, SPECIAL_EQUAL, rl, *raw_stree, &true_states, &false_states, NULL); in __implied_case_stree()