mirror of
https://github.com/Z3Prover/z3
synced 2025-04-12 12:08:18 +00:00
make max_bv_sharing a simplifier
This commit is contained in:
parent
db74e23de1
commit
5af6e1a046
|
@ -6,6 +6,7 @@ z3_add_component(simplifiers
|
||||||
eliminate_predicates.cpp
|
eliminate_predicates.cpp
|
||||||
euf_completion.cpp
|
euf_completion.cpp
|
||||||
extract_eqs.cpp
|
extract_eqs.cpp
|
||||||
|
max_bv_sharing.cpp
|
||||||
model_reconstruction_trail.cpp
|
model_reconstruction_trail.cpp
|
||||||
propagate_values.cpp
|
propagate_values.cpp
|
||||||
solve_context_eqs.cpp
|
solve_context_eqs.cpp
|
||||||
|
|
|
@ -3,7 +3,7 @@ Copyright (c) 2011 Microsoft Corporation
|
||||||
|
|
||||||
Module Name:
|
Module Name:
|
||||||
|
|
||||||
max_bv_sharing_tactic.cpp
|
max_bv_sharing.cpp
|
||||||
|
|
||||||
Abstract:
|
Abstract:
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ Abstract:
|
||||||
This rewriter is particularly useful for reducing
|
This rewriter is particularly useful for reducing
|
||||||
the number of Adders and Multipliers before "bit-blasting".
|
the number of Adders and Multipliers before "bit-blasting".
|
||||||
|
|
||||||
Author:
|
Author
|
||||||
|
|
||||||
Leonardo de Moura (leonardo) 2011-12-29.
|
Leonardo de Moura (leonardo) 2011-12-29.
|
||||||
|
|
||||||
|
@ -23,9 +23,10 @@ Revision History:
|
||||||
#include "ast/bv_decl_plugin.h"
|
#include "ast/bv_decl_plugin.h"
|
||||||
#include "ast/rewriter/rewriter_def.h"
|
#include "ast/rewriter/rewriter_def.h"
|
||||||
#include "util/obj_pair_hashtable.h"
|
#include "util/obj_pair_hashtable.h"
|
||||||
|
#include "ast/simplifiers/dependent_expr_state.h"
|
||||||
#include "ast/ast_lt.h"
|
#include "ast/ast_lt.h"
|
||||||
|
|
||||||
class max_bv_sharing_tactic : public tactic {
|
class max_bv_sharing : public dependent_expr_simplifier {
|
||||||
|
|
||||||
struct rw_cfg : public default_rewriter_cfg {
|
struct rw_cfg : public default_rewriter_cfg {
|
||||||
typedef std::pair<expr *, expr *> expr_pair;
|
typedef std::pair<expr *, expr *> expr_pair;
|
||||||
|
@ -224,64 +225,22 @@ class max_bv_sharing_tactic : public tactic {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct imp {
|
rw m_rw;
|
||||||
rw m_rw;
|
unsigned m_num_steps = 0;
|
||||||
unsigned m_num_steps;
|
|
||||||
|
|
||||||
imp(ast_manager & m, params_ref const & p):
|
|
||||||
m_rw(m, p) {
|
|
||||||
}
|
|
||||||
|
|
||||||
ast_manager & m() const { return m_rw.m(); }
|
|
||||||
|
|
||||||
void operator()(goal_ref const & g,
|
|
||||||
goal_ref_buffer & result) {
|
|
||||||
tactic_report report("max-bv-sharing", *g);
|
|
||||||
bool produce_proofs = g->proofs_enabled();
|
|
||||||
|
|
||||||
expr_ref new_curr(m());
|
|
||||||
proof_ref new_pr(m());
|
|
||||||
unsigned size = g->size();
|
|
||||||
for (unsigned idx = 0; idx < size; idx++) {
|
|
||||||
if (g->inconsistent())
|
|
||||||
break;
|
|
||||||
expr * curr = g->form(idx);
|
|
||||||
m_rw(curr, new_curr, new_pr);
|
|
||||||
m_num_steps += m_rw.get_num_steps();
|
|
||||||
|
|
||||||
if (produce_proofs) {
|
|
||||||
proof * pr = g->pr(idx);
|
|
||||||
new_pr = m().mk_modus_ponens(pr, new_pr);
|
|
||||||
}
|
|
||||||
g->update(idx, new_curr, new_pr, g->dep(idx));
|
|
||||||
}
|
|
||||||
m_rw.cfg().cleanup();
|
|
||||||
g->inc_depth();
|
|
||||||
result.push_back(g.get());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
imp * m_imp;
|
|
||||||
params_ref m_params;
|
params_ref m_params;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
max_bv_sharing_tactic(ast_manager & m, params_ref const & p):
|
max_bv_sharing(ast_manager & m, params_ref const & p, dependent_expr_state& fmls):
|
||||||
m_params(p) {
|
dependent_expr_simplifier(m, fmls),
|
||||||
m_imp = alloc(imp, m, p);
|
m_params(p),
|
||||||
|
m_rw(m, p) {
|
||||||
}
|
}
|
||||||
|
|
||||||
tactic * translate(ast_manager & m) override {
|
|
||||||
return alloc(max_bv_sharing_tactic, m, m_params);
|
|
||||||
}
|
|
||||||
|
|
||||||
~max_bv_sharing_tactic() override {
|
|
||||||
dealloc(m_imp);
|
|
||||||
}
|
|
||||||
|
|
||||||
char const* name() const override { return "max_bv_sharing"; }
|
|
||||||
|
|
||||||
void updt_params(params_ref const & p) override {
|
void updt_params(params_ref const & p) override {
|
||||||
m_params.append(p);
|
m_params.append(p);
|
||||||
m_imp->m_rw.cfg().updt_params(m_params);
|
m_rw.cfg().updt_params(m_params);
|
||||||
}
|
}
|
||||||
|
|
||||||
void collect_param_descrs(param_descrs & r) override {
|
void collect_param_descrs(param_descrs & r) override {
|
||||||
|
@ -291,20 +250,21 @@ public:
|
||||||
"(default: 128) maximum number of arguments (per application) that will be considered by the greedy (quadratic) heuristic.");
|
"(default: 128) maximum number of arguments (per application) that will be considered by the greedy (quadratic) heuristic.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator()(goal_ref const & in,
|
void reduce() override {
|
||||||
goal_ref_buffer & result) override {
|
expr_ref new_curr(m);
|
||||||
(*m_imp)(in, result);
|
proof_ref new_pr(m);
|
||||||
}
|
for (unsigned idx = 0; idx < m_fmls.size() && !m_fmls.inconsistent(); idx++) {
|
||||||
|
auto [curr, d] = m_fmls[idx]();
|
||||||
void cleanup() override {
|
m_rw(curr, new_curr, new_pr);
|
||||||
ast_manager & m = m_imp->m();
|
// Proof reconstruction: new_pr = m.mk_modus_ponens(old_pr, new_pr);
|
||||||
params_ref p = std::move(m_params);
|
m_num_steps += m_rw.get_num_steps();
|
||||||
m_imp->~imp();
|
m_fmls.update(idx, dependent_expr(m, new_curr, d));
|
||||||
new (m_imp) imp(m, p);
|
}
|
||||||
|
m_rw.cfg().cleanup();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
tactic * mk_max_bv_sharing_tactic(ast_manager & m, params_ref const & p) {
|
dependent_expr_simplifier * mk_max_bv_sharing(ast_manager & m, params_ref const & p, dependent_expr_state& fmls) {
|
||||||
return clean(alloc(max_bv_sharing_tactic, m, p));
|
return alloc(max_bv_sharing, m, p, fmls);
|
||||||
}
|
}
|
||||||
|
|
25
src/ast/simplifiers/max_bv_sharing.h
Normal file
25
src/ast/simplifiers/max_bv_sharing.h
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
/*++
|
||||||
|
Copyright (c) 2022 Microsoft Corporation
|
||||||
|
|
||||||
|
Module Name:
|
||||||
|
|
||||||
|
max_bv_sharing.h
|
||||||
|
|
||||||
|
Abstract:
|
||||||
|
|
||||||
|
Rewriter for "maximing" the number of shared terms.
|
||||||
|
The idea is to rewrite AC terms to maximize sharing.
|
||||||
|
This rewriter is particularly useful for reducing
|
||||||
|
the number of Adders and Multipliers before "bit-blasting".
|
||||||
|
|
||||||
|
Author:
|
||||||
|
|
||||||
|
Leonardo de Moura (leonardo) 2011-12-29.
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ast/simplifiers/dependent_expr_state.h"
|
||||||
|
|
||||||
|
dependent_expr_simplifier * mk_max_bv_sharing(ast_manager & m, params_ref const & p, dependent_expr_state& fmls);
|
|
@ -11,7 +11,6 @@ z3_add_component(bv_tactics
|
||||||
bv_slice_tactic.cpp
|
bv_slice_tactic.cpp
|
||||||
dt2bv_tactic.cpp
|
dt2bv_tactic.cpp
|
||||||
elim_small_bv_tactic.cpp
|
elim_small_bv_tactic.cpp
|
||||||
max_bv_sharing_tactic.cpp
|
|
||||||
COMPONENT_DEPENDENCIES
|
COMPONENT_DEPENDENCIES
|
||||||
bit_blaster
|
bit_blaster
|
||||||
core_tactics
|
core_tactics
|
||||||
|
|
|
@ -21,11 +21,20 @@ Revision History:
|
||||||
--*/
|
--*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "util/params.h"
|
#include "ast/simplifiers/max_bv_sharing.h"
|
||||||
class ast_manager;
|
#include "tactic/dependent_expr_state_tactic.h"
|
||||||
class tactic;
|
|
||||||
|
class max_bv_sharing_tactic_factory : public dependent_expr_simplifier_factory {
|
||||||
|
public:
|
||||||
|
dependent_expr_simplifier* mk(ast_manager& m, params_ref const& p, dependent_expr_state& s) override {
|
||||||
|
return mk_max_bv_sharing(m, p, s);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline tactic* mk_max_bv_sharing_tactic(ast_manager& m, params_ref const& p = params_ref()) {
|
||||||
|
return alloc(dependent_expr_state_tactic, m, p, alloc(max_bv_sharing_tactic_factory), "max-bv-sharing");
|
||||||
|
}
|
||||||
|
|
||||||
tactic * mk_max_bv_sharing_tactic(ast_manager & m, params_ref const & p = params_ref());
|
|
||||||
/*
|
/*
|
||||||
ADD_TACTIC("max-bv-sharing", "use heuristics to maximize the sharing of bit-vector expressions such as adders and multipliers.", "mk_max_bv_sharing_tactic(m, p)")
|
ADD_TACTIC("max-bv-sharing", "use heuristics to maximize the sharing of bit-vector expressions such as adders and multipliers.", "mk_max_bv_sharing_tactic(m, p)")
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue