Skip to content

Commit 860aefc

Browse files
committed
rerun backward synthesis after unate_def with dependency-aware predefined vars
1 parent a616cfb commit 860aefc

File tree

3 files changed

+47
-6
lines changed

3 files changed

+47
-6
lines changed

src/arjun.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,6 @@ class SimplifiedCNF {
12481248
}
12491249
}
12501250
void set_after_backward_round_synth() {
1251-
assert(!after_backward_round_synth && "Should only be set once");
12521251
after_backward_round_synth = true;
12531252
}
12541253
const auto& get_orig_to_new_var() const {

src/backward.cpp

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,23 @@ void Minimize::backward_round_synth(SimplifiedCNF& cnf, const Arjun::ManthanConf
415415
vector<char> unknown_set(orig_num_vars, 0);
416416
vector<uint32_t> unknown;
417417
auto [input, to_define, backward_defined] = cnf.get_var_types(conf.verb | verbose_debug_enabled, "start backward_round_synth");
418+
const auto new_to_orig_var = cnf.get_new_to_orig_var();
419+
map<uint32_t, set<uint32_t>> dep_cache;
420+
map<uint32_t, set<uint32_t>> backward_depends_on_orig;
418421
set<uint32_t> pretend_input;
419422
if (to_define.empty()) {
420423
verb_print(1, "[backw-synth] No variables to define, returning original CNF");
421424
return;
422425
}
423-
assert(backward_defined.empty());
426+
if (!backward_defined.empty()) {
427+
verb_print(1, "[backw-synth] Rerun mode: respecting pre-defined backward vars: "
428+
<< backward_defined.size());
429+
for (const auto& b_new : backward_defined) {
430+
assert(new_to_orig_var.count(b_new));
431+
const uint32_t b_orig = new_to_orig_var.at(b_new).var();
432+
backward_depends_on_orig[b_new] = cnf.get_dependent_vars_recursive(b_orig, dep_cache);
433+
}
434+
}
424435

425436
add_all_indics_except(input);
426437
for(const auto& v: input) {
@@ -439,9 +450,8 @@ void Minimize::backward_round_synth(SimplifiedCNF& cnf, const Arjun::ManthanConf
439450
interp.fill_picolsat(orig_num_vars);
440451
interp.fill_var_to_indic(var_to_indic);
441452

442-
for(uint32_t x = 0; x < orig_num_vars; x++) {
443-
pretend_input.insert(x); // we pretend that all vars are input vars
444-
if (input.count(x)) continue;
453+
for(uint32_t x = 0; x < orig_num_vars; x++) pretend_input.insert(x); // we pretend that all vars are input vars
454+
for(const auto& x: to_define) {
445455
unknown.push_back(x);
446456
unknown_set[x] = 1;
447457
}
@@ -489,14 +499,24 @@ void Minimize::backward_round_synth(SimplifiedCNF& cnf, const Arjun::ManthanConf
489499
}
490500
assert(test_var < orig_num_vars);
491501
assert(!input.count(test_var));
502+
assert(!backward_defined.count(test_var));
492503
assert(unknown_set[test_var]);
493504
unknown_set[test_var] = 0;
494505
pretend_input.erase(test_var);
495506
verb_print(3, "Testing: " << test_var+1);
496507

497508
//Assumption filling
498509
assert(test_var != var_Undef);
499-
fill_assumptions_backward(assumptions, unknown, unknown_set, pretend_input, input);
510+
set<uint32_t> ignore_assumps = input;
511+
if (!backward_defined.empty()) {
512+
assert(new_to_orig_var.count(test_var));
513+
const uint32_t test_orig = new_to_orig_var.at(test_var).var();
514+
for (const auto& b_new : backward_defined) {
515+
const auto& deps = backward_depends_on_orig.at(b_new);
516+
if (deps.count(test_orig)) ignore_assumps.insert(b_new);
517+
}
518+
}
519+
fill_assumptions_backward(assumptions, unknown, unknown_set, pretend_input, ignore_assumps);
500520
assumptions.push_back(Lit(test_var, false));
501521
assumptions.push_back(Lit(test_var + orig_num_vars, true));
502522
solver->set_no_confl_needed();
@@ -556,6 +576,7 @@ void Minimize::backward_round_synth(SimplifiedCNF& cnf, const Arjun::ManthanConf
556576
const auto& aig = interp.get_defs()[v];
557577
if (aig == nullptr) continue;
558578
assert(input.count(v) == 0);
579+
assert(backward_defined.count(v) == 0);
559580
}
560581
cnf.map_aigs_to_orig(interp.get_defs(), orig_num_vars);
561582
cnf.set_after_backward_round_synth();

src/main.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ int do_synth_bve = true;
8383
int do_pre_backbone = 0;
8484
int manthan_rep_mult = 4;
8585
int manthan_strategy = 0;
86+
constexpr uint32_t unate_def_backward_rerun_threshold = 8;
8687

8788
int synthesis = false;
8889
int do_unate = false;
@@ -386,8 +387,28 @@ void do_synthesis() {
386387
}
387388

388389
if (!candidate_all_specified && do_unate_def && !cnf.synth_done()) {
390+
uint32_t unate_def_newly_defined = 0;
391+
auto [input_before_unate_def, to_define_before_unate_def, backward_before_unate_def] =
392+
cnf.get_var_types(0 | verbose_debug_enabled, "pre_unate_def_count");
389393
arjun->standalone_unate_def(cnf);
390394
if (!conf.debug_synth.empty()) cnf.write_aig_defs_to_file(conf.debug_synth + "-unsat_unate_def.aig");
395+
auto [input_after_unate_def, to_define_after_unate_def, backward_after_unate_def] =
396+
cnf.get_var_types(0 | verbose_debug_enabled, "post_unate_def_count");
397+
(void)input_after_unate_def;
398+
(void)backward_after_unate_def;
399+
if (to_define_before_unate_def.size() >= to_define_after_unate_def.size()) {
400+
unate_def_newly_defined += to_define_before_unate_def.size() - to_define_after_unate_def.size();
401+
}
402+
403+
if (do_minim_indep && !cnf.synth_done()
404+
&& unate_def_newly_defined >= unate_def_backward_rerun_threshold) {
405+
cout << "c o [synth] unate_def defined " << unate_def_newly_defined
406+
<< " vars (threshold " << unate_def_backward_rerun_threshold
407+
<< "), rerunning backward synthesis" << endl;
408+
arjun->standalone_backward_round_synth(cnf, mconf);
409+
if (!conf.debug_synth.empty()) cnf.write_aig_defs_to_file(conf.debug_synth + "-minim_idep_synt-post_unate_def.aig");
410+
cnf.simplify_aigs(conf.verb);
411+
}
391412
}
392413

393414
auto mconf_orig = mconf;

0 commit comments

Comments
 (0)