remove dependency of smt in IR
MODIFY
ir/state.cpp
ir/state.cpp
@@ -149,7 +149,7 @@ void State::addCondJump(const StateValue &cond, const BasicBlock &dst_true,
}
void State::addReturn(const StateValue &val) {
- return_val.add(StateValue(val), expr(domain.first));
+ return_val.add(val, domain.first);
return_domain |= domain.first;
return_undef_vars.insert(undef_vars.begin(), undef_vars.end());
return_undef_vars.insert(domain.second.begin(), domain.second.end());

MODIFY
smt/exprs.cpp
smt/exprs.cpp
// Distributed under the MIT license that can be found in the LICENSE file.
#include "smt/exprs.h"
-#include "ir/state_value.h"
#include "util/compiler.h"
using namespace std;
namespace smt {
-template <typename T>
-void DisjointExpr<T>::add(T &&val, expr &&domain) {
- if (domain.isFalse())
- return;
- if (domain.isTrue())
- vals.clear();
-
- auto [I, inserted] = vals.try_emplace(move(val), move(domain));
- if (!inserted)
- I->second |= move(domain);
-}
-
-template <typename T>
-T DisjointExpr<T>::operator()() const {
- T ret;
- bool first = true;
- for (auto &[val, domain] : vals) {
- if (domain.isTrue())
- return val;
-
- ret = first ? val : T::mkIf(domain, val, ret);
- first = false;
- }
- if (first)
- return default_val;
- return ret;
-}
-
-template class DisjointExpr<expr>;
-template class DisjointExpr<IR::StateValue>;
-
-
void FunctionExpr::add(expr &&key, expr &&val) {
ENSURE(fn.emplace(move(key), move(val)).second);
}
@@ -56,7 +23,7 @@ void FunctionExpr::del(const expr &key) {
expr FunctionExpr::operator()(expr &key) const {
DisjointExpr disj(default_val);
for (auto &[k, v] : fn) {
- disj.add(expr(v), k == key);
+ disj.add(v, k == key);
}
return disj();
}

MODIFY
smt/exprs.h
smt/exprs.h
#include "smt/expr.h"
#include <map>
#include <set>
+#include <utility>
namespace smt {
@@ -19,8 +20,29 @@ public:
DisjointExpr(const T &default_val) : default_val(default_val) {}
DisjointExpr(T &&default_val) : default_val(std::move(default_val)) {}
- void add(T &&val, expr &&domain);
- T operator()() const;
+ template <typename V, typename D>
+ void add(V &&val, D &&domain) {
+ if (domain.isFalse())
+ return;
+ if (domain.isTrue())
+ vals.clear();
+
+ auto [I, inserted] = vals.try_emplace(std::forward<V>(val),
+ std::forward<D>(domain));
+ if (!inserted)
+ I->second |= std::forward<D>(domain);
+ }
+
+ T operator()() const {
+ std::optional<T> ret;
+ for (auto &[val, domain] : vals) {
+ if (domain.isTrue())
+ return val;
+
+ ret = ret ? T::mkIf(domain, val, *ret) : val;
+ }
+ return ret.value_or(default_val);
+ }
};

remove dependency of smt in IR