Skip to content

Commit e9b7810

Browse files
committed
Support new PWMap implementation in evaluator
1 parent 3a31f32 commit e9b7810

8 files changed

Lines changed: 70 additions & 23 deletions

File tree

eval/eval_exec.cpp

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,19 @@ void printHeader(Util::prog_opts::variables_map vm)
6464
// Evaluation Executor ---------------------------------------------------------
6565
////////////////////////////////////////////////////////////////////////////////
6666

67-
EvalExecutor::EvalExecutor() : set_impl_(0)
67+
EvalExecutor::EvalExecutor() : scc_impl_(1)
6868
{
6969
config_.add_options()
7070
("set_impl,s", Util::prog_opts::value(&set_impl_),
7171
" Desired set implementation:"
7272
"\n - 0 for unordered sets (default option)"
7373
"\n - 1 for ordered sets"
7474
"\n - 2 for unidimensional ordered dense sets")
75+
("pw_impl,p", Util::prog_opts::value(&pw_impl_),
76+
" Desired PWMap implementation:"
77+
"\n - 0 for unordered PWMaps (default option)"
78+
"\n - 1 for ordered PWMaps"
79+
"\n - 2 for domain ordered PWMaps")
7580
("scc_impl", Util::prog_opts::value(&scc_impl_),
7681
"Desired SCC algorithm implementation:"
7782
"\n - 0 for V1 of minimum reachable SCC (default option)"
@@ -82,11 +87,32 @@ EvalExecutor::EvalExecutor() : set_impl_(0)
8287
visible_.add(generic_).add(config_);
8388
}
8489

85-
EvalUserInput EvalExecutor::gatherUserInput()
90+
EvalUserInput EvalExecutor::chooseImplementation()
8691
{
8792
EvalUserInput result;
8893

89-
result.set_set_impl(set_impl_);
94+
AutomImplVisitor autom_impl_visitor;
95+
std::streambuf* old_cout_buffer = std::cout.rdbuf();
96+
std::cout.rdbuf(nullptr);
97+
EvalUserInput autom_impl = autom_impl_visitor.visit(Parser::parseFile(
98+
*input_file_));
99+
std::cout.rdbuf(old_cout_buffer);
100+
101+
result.set_set_impl(autom_impl.set_impl());
102+
result.set_pw_impl(autom_impl.pw_impl());
103+
104+
if (set_impl_) {
105+
if (set_impl_ > autom_impl.set_impl())
106+
Util::ERROR("Incompatible set implementation for the SBG input\n");
107+
108+
result.set_set_impl(set_impl_);
109+
}
110+
if (pw_impl_) {
111+
if (pw_impl_ > autom_impl.pw_impl())
112+
Util::ERROR("Incompatible PW implementation for the SBG input\n");
113+
114+
result.set_pw_impl(pw_impl_);
115+
}
90116
result.set_scc_impl(scc_impl_);
91117

92118
return result;
@@ -131,13 +157,7 @@ void EvalExecutor::execute(int arg_count, char* args[])
131157
// Input SBG program file handling -------------------------------------------
132158

133159
if (input_file_) {
134-
AutomImplVisitor autom_impl;
135-
std::streambuf* old_cout_buffer = std::cout.rdbuf();
136-
std::cout.rdbuf(nullptr);
137-
autom_impl.visit(Parser::parseFile(*input_file_));
138-
std::cout.rdbuf(old_cout_buffer);
139-
140-
EvalUserInput input = gatherUserInput();
160+
EvalUserInput input = chooseImplementation();
141161
InputTranslator input_translator;
142162
input_translator.translate(input);
143163
ProgramIO eval_result = parseEvalFile(*input_file_);

eval/eval_exec.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ class EvalExecutor : public Util::UserInputHandler {
3838
void execute(int arg_count, char* args[]) override;
3939

4040
private:
41-
EvalUserInput gatherUserInput();
41+
EvalUserInput chooseImplementation();
4242

4343
boost::optional<int> set_impl_;
44+
boost::optional<int> pw_impl_;
4445
boost::optional<int> scc_impl_;
4546
};
4647

eval/input_translator.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,23 @@ InputTranslator::InputTranslator() {}
3030
void InputTranslator::translate(EvalUserInput& input)
3131
{
3232
EvalUserInput::MaybeInt s = input.set_impl();
33-
if (s) {
33+
EvalUserInput::MaybeInt pw = input.pw_impl();
34+
if (pw && s) {
35+
if (*pw == 2 && *s == 0) {
36+
Util::ERROR("Domain ordered PWMap should be used with an ordered set"
37+
" implementation\n");
38+
}
39+
else {
40+
setSetFactory(*s);
41+
setPWFactory(*pw);
42+
}
43+
}
44+
else if (s) {
3445
setSetFactory(*s);
3546
}
47+
else if (pw) {
48+
setPWFactory(*pw);
49+
}
3650

3751
EvalUserInput::MaybeInt scc = input.scc_impl();
3852
if (scc) {

eval/user_impl_map.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ UserImplMap::StructImplMap pwMap()
6767
UserImplMap::StructImplMap pw_mapping;
6868
pw_mapping[0] = []() { return std::make_unique<LIB::UnordPWMapFact>(); };
6969
pw_mapping[1] = []() { return std::make_unique<LIB::OrdPWMapFact>(); };
70+
pw_mapping[2] = []() { return std::make_unique<LIB::DomOrdPWMapFact>(); };
7071
pw_mapping.freeze();
7172
return pw_mapping;
7273
}

eval/visitors/autom_impl_visitor.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace Eval {
3333

3434
AutomImplVisitor::AutomImplVisitor() {}
3535

36-
void AutomImplVisitor::visit(AST::SBGProgram p) const
36+
EvalUserInput AutomImplVisitor::visit(AST::SBGProgram p) const
3737
{
3838
// Statement inspection ------------------------------------------------------
3939

@@ -55,17 +55,23 @@ void AutomImplVisitor::visit(AST::SBGProgram p) const
5555
// Set Implementation --------------------------------------------------------
5656

5757
int auto_set_impl = 2;
58-
if (dims < 2) {
59-
SetImplExprVisitor set_impl_visit(stm_eval.eval_ctx().venv());
60-
for (AST::Expr expr : p.exprs()) {
61-
int ith_set_impl = boost::apply_visitor(set_impl_visit, expr);
62-
auto_set_impl = std::min(auto_set_impl, ith_set_impl);
63-
}
58+
SetImplExprVisitor set_impl_visit(stm_eval.eval_ctx().venv());
59+
for (AST::Expr expr : p.exprs()) {
60+
int ith_set_impl = boost::apply_visitor(set_impl_visit, expr);
61+
auto_set_impl = std::min(auto_set_impl, ith_set_impl);
6462
}
6563

66-
setSetFactory(auto_set_impl);
64+
EvalUserInput result;
65+
result.set_set_impl(auto_set_impl);
6766

68-
return;
67+
// PW Implementation ---------------------------------------------------------
68+
69+
result.set_pw_impl(1);
70+
if (auto_set_impl > 0) {
71+
result.set_pw_impl(2);
72+
}
73+
74+
return result;
6975
}
7076

7177
} // namespace Eval

eval/visitors/autom_impl_visitor.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <boost/variant.hpp>
3232

3333
#include "ast/sbg_program.hpp"
34+
#include "eval/user_input.hpp"
3435

3536
namespace SBG {
3637

@@ -40,7 +41,7 @@ class AutomImplVisitor {
4041
public:
4142
AutomImplVisitor();
4243

43-
void visit(AST::SBGProgram p) const;
44+
EvalUserInput visit(AST::SBGProgram p) const;
4445
};
4546

4647
} // namespace Eval

eval/visitors/set_impl_visitor.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ int SetImplExprVisitor::operator()(AST::Interval v) const
7070
int SetImplExprVisitor::operator()(AST::MultiDimInter v) const
7171
{
7272
int impl = 2;
73+
74+
if (v.intervals().size() > 1)
75+
return 1;
76+
7377
for (const AST::Expr &e : v.intervals())
7478
impl = std::min(impl, boost::apply_visitor(*this, e));
7579

test/rl2.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Emap: <<{[1:1:E1]} -> |0*x+1|, {[E1+1:1:E2]} -> |0*x+2|, {[E2+1:1:E3], [E3+1:1:E
8383
|, {[E6+1:1:E7]} -> |0*x+6|, {[E7+1:1:E8]} -> |0*x+7|, {[E8+1:1:E9]} -> |0*x+8
8484
|, {[E9+1:1:E10]} -> |0*x+9|>>;
8585

86-
matchSCCTS(
86+
matchSCC(
8787
V: {[1:1:F1], [F1+1:1:F2], [F2+1:1:F3], [F3+1:1:F4], [F4+1:1:F5]
8888
, [F5+1:1:U1], [U1+1:1:U2], [U2+1:1:U3]}
8989
Vmap: <<{[1:1:F1]} -> |0*x+1|, {[F1+1:1:F2]} -> |0*x+2|, {[F2+1:1:F3]} -> |0*x+3

0 commit comments

Comments
 (0)