Skip to content

Commit 69e0698

Browse files
authored
Merge pull request #5480 from natasha-jeppu/clause-map
CBMC additional profiling info: Extend solver hardness to track clauses mapped to an instruction
2 parents 71a4d6d + 2cb743f commit 69e0698

File tree

4 files changed

+62
-4
lines changed

4 files changed

+62
-4
lines changed

regression/solver-hardness/solver-hardness-simple/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ main.c
55
^SIGNAL=0$
66
^\[main.assertion.\d+\] line \d+ assertion a \+ b \< 10: FAILURE$
77
^VERIFICATION FAILED$
8-
\"SAT_hardness\":\{(\"Clauses\":\d+|\"Variables\":\d+|\"Literals\":\d+),(\"Clauses\":\d+|\"Variables\":\d+|\"Literals\":\d+),(\"Clauses\":\d+|\"Variables\":\d+|\"Literals\":\d+)\}
8+
\"SAT_hardness\":\{(\"ClauseSet\":\[.*\]|\"Clauses\":\d+|\"Variables\":\d+|\"Literals\":\d+),(\"ClauseSet\":\[.*\]|\"Clauses\":\d+|\"Variables\":\d+|\"Literals\":\d+),(\"ClauseSet\":\[.*\]|\"Clauses\":\d+|\"Variables\":\d+|\"Literals\":\d+),(\"ClauseSet\":\[.*\]|\"Clauses\":\d+|\"Variables\":\d+|\"Literals\":\d+)\}
99
--
1010
^warning: ignoring

src/solvers/sat/satcheck_minisat2.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,22 @@ void satcheck_minisat2_baset<T>::lcnf(const bvt &bv)
140140

141141
solver->addClause_(c);
142142

143+
// To map clauses to lines of program code, track clause indices in the
144+
// dimacs cnf output. Dimacs output is generated after processing clauses
145+
// to remove duplicates and clauses that are trivially true. Here, a clause
146+
// is checked to see if it can be thus eliminated. If not, add the clause
147+
// index to list of clauses in solver_hardnesst::register_clause().
148+
static size_t cnf_clause_index = 0;
149+
bvt cnf;
150+
bool clause_removed = process_clause(bv, cnf);
151+
152+
if(!clause_removed)
153+
cnf_clause_index++;
154+
143155
with_solver_hardness(
144-
[&bv](solver_hardnesst &hardness) { hardness.register_clause(bv); });
156+
[&bv, &cnf, &clause_removed](solver_hardnesst &hardness) {
157+
hardness.register_clause(bv, cnf, cnf_clause_index, !clause_removed);
158+
});
145159
clause_counter++;
146160
}
147161
catch(const Minisat::OutOfMemoryException &)

src/solvers/solver_hardness.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ operator+=(const solver_hardnesst::sat_hardnesst &other)
2626
clauses += other.clauses;
2727
literals += other.literals;
2828
variables.insert(other.variables.begin(), other.variables.end());
29+
clause_set.insert(
30+
clause_set.end(), other.clause_set.begin(), other.clause_set.end());
2931
return *this;
3032
}
3133

@@ -87,14 +89,30 @@ void solver_hardnesst::register_assertion_ssas(
8789
current_hardness = {};
8890
}
8991

90-
void solver_hardnesst::register_clause(const bvt &bv)
92+
void solver_hardnesst::register_clause(
93+
const bvt &bv,
94+
const bvt &cnf,
95+
const size_t cnf_clause_index,
96+
bool register_cnf)
9197
{
9298
current_hardness.clauses++;
9399
current_hardness.literals += bv.size();
100+
94101
for(const auto &literal : bv)
95102
{
96103
current_hardness.variables.insert(literal.var_no());
97104
}
105+
106+
if(register_cnf)
107+
{
108+
#ifdef DEBUG
109+
std::cout << cnf_clause_index << ": ";
110+
for(const auto &literal : cnf)
111+
std::cout << literal.dimacs() << " ";
112+
std::cout << "0\n";
113+
#endif
114+
current_hardness.clause_set.push_back(cnf_clause_index);
115+
}
98116
}
99117

100118
void solver_hardnesst::set_outfile(const std::string &file_name)
@@ -151,6 +169,14 @@ void solver_hardnesst::produce_report()
151169
sat_hardness_json["Variables"] =
152170
json_numbert{std::to_string(hardness.variables.size())};
153171

172+
json_arrayt sat_hardness_clause_set_json;
173+
for(auto const &clause : hardness.clause_set)
174+
{
175+
sat_hardness_clause_set_json.push_back(
176+
json_numbert{std::to_string(clause)});
177+
}
178+
sat_hardness_json["ClauseSet"] = sat_hardness_clause_set_json;
179+
154180
hardness_stats_json["SAT_hardness"] = sat_hardness_json;
155181

156182
json_stream_array.push_back(hardness_stats_json);
@@ -183,6 +209,15 @@ void solver_hardnesst::produce_report()
183209
assertion_hardness_json["Variables"] = json_numbert{
184210
std::to_string(assertion_stats.sat_hardness.variables.size())};
185211

212+
json_arrayt assertion_sat_hardness_clause_set_json;
213+
for(auto const &clause : assertion_stats.sat_hardness.clause_set)
214+
{
215+
assertion_sat_hardness_clause_set_json.push_back(
216+
json_numbert{std::to_string(clause)});
217+
}
218+
assertion_hardness_json["ClauseSet"] =
219+
assertion_sat_hardness_clause_set_json;
220+
186221
assertion_stats_json["SAT_hardness"] = assertion_hardness_json;
187222

188223
json_stream_array.push_back(assertion_stats_json);

src/solvers/solver_hardness.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ struct solver_hardnesst
5050
size_t clauses = 0;
5151
size_t literals = 0;
5252
std::unordered_set<size_t> variables = {};
53+
std::vector<size_t> clause_set = {};
5354

5455
sat_hardnesst &operator+=(const sat_hardnesst &other);
5556
};
@@ -105,7 +106,15 @@ struct solver_hardnesst
105106
/// Called e.g. from the `satcheck_minisat2::lcnf`, this function adds the
106107
/// complexity statistics from the last SAT query to the `current_ssa_key`.
107108
/// \param bv: the clause (vector of literals)
108-
void register_clause(const bvt &bv);
109+
/// \param cnf: processed clause
110+
/// \param cnf_clause_index: index of clause in dimacs output
111+
/// \param register_cnf: negation of boolean variable tracking if the clause
112+
/// can be eliminated
113+
void register_clause(
114+
const bvt &bv,
115+
const bvt &cnf,
116+
const size_t cnf_clause_index,
117+
bool register_cnf);
109118

110119
void set_outfile(const std::string &file_name);
111120

0 commit comments

Comments
 (0)