Skip to content

Commit

Permalink
fix a bug in the reducer
Browse files Browse the repository at this point in the history
  • Loading branch information
Xuejun Yang committed Jul 22, 2011
1 parent bd4a83a commit 11305f8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
25 changes: 24 additions & 1 deletion src/Reducer.cpp
Expand Up @@ -524,7 +524,15 @@ Reducer::get_used_vars_and_funcs_and_labels(const FunctionInvocation* fi, vector
// replace the function call with a constant 0. In fact it's not evaluated
// anyway, so which constant we use doesn't matter
if (is_blk_deleted(call->get_func()->body)) {
map_reduced_invocations[fi] = new Constant(&fi->get_type(), "0");
if (call->get_type().is_aggregate()) {
// it's not a real constant, but we don't want to go through the trouble
// of creating an ExpressionVariable
string vname = add_artificial_globals(&call->get_type());
map_reduced_invocations[fi] = new Constant(&call->get_type(), vname);
}
else {
map_reduced_invocations[fi] = new Constant(&fi->get_type(), "0");
}
return;
}
// recursively find used vars and functions
Expand Down Expand Up @@ -988,13 +996,15 @@ Reducer::config_call_chain_shortcut(string cmd)
{
if (cmd == "poll") {
dump_monitored_var = true;
add_artificial_globals(get_int_type(), "global_call_id");
}
else {
vector<string> strs;
StringUtils::split_string(cmd, strs, ":");
assert(strs.size() == 2 || strs.size() == 3);
if (strs.size() == 2) {
dump_monitored_var = true;
add_artificial_globals(get_int_type(), "global_call_id");
monitored_func = find_function_by_name(strs[0]);
assert(monitored_func);
monitored_call_id = strs[1];
Expand Down Expand Up @@ -1163,6 +1173,19 @@ Reducer::config_var_init_reduction(string cmd)
map_reduced_var_inits[v] = strs[1];
}

string
Reducer::add_artificial_globals(const Type* t, string name)
{
static int cnt = 0;
ostringstream oss;
t->Output(oss);
if (name == "") {
name = "tmp_" + StringUtils::int2str(cnt++);
}
artificial_globals.push_back(oss.str() + " " + name);
return name;
}

const Variable*
Reducer::find_addressed_var(string addr)
{
Expand Down
4 changes: 4 additions & 0 deletions src/Reducer.h
Expand Up @@ -45,6 +45,7 @@ class Variable;
class Expression;
class ExpressionVariable;
class FactMgr;
class Type;
class FunctionInvocation;
class FunctionInvocationUser;
class FunctionInvocationBinary;
Expand Down Expand Up @@ -97,6 +98,8 @@ class Reducer
void delete_stms_after(const Statement* stm, bool include_parent_blks);
int reduce_stms_with_assigns(int id1, int id2, const string& assigns);

string add_artificial_globals(const Type* t, string name="");

// for outputing
void output_block_skeleton(const Block* blk, vector<const Block*>& work_blks, vector<const Function*>& work_funcs, std::ostream& out);
int output_expr(const Expression* e, std::ostream &out);
Expand Down Expand Up @@ -147,6 +150,7 @@ class Reducer
vector<const Function*> used_funcs;
vector<const Variable*> used_vars;
vector<string> used_labels;
vector<string> artificial_globals;
const Function* main;
string main_str;
bool configured;
Expand Down
16 changes: 2 additions & 14 deletions src/ReducerOutputMgr.cpp
Expand Up @@ -935,20 +935,8 @@ ReducerOutputMgr::OutputStructUnions(ostream& out)
void
ReducerOutputMgr::output_artificial_globals(ostream& out)
{
if (reducer->dump_monitored_var) {
//// hack for path shortcutting delta, move some local variables to global area for easy
//// recording of the program state
//if (CGOptions::monitored_call_id()) {
// vector<const Variable*> moved_vars;
// find_moved_local_vars(moved_vars);
// size_t i;
// for (i=0; i<moved_vars.size(); i++) {
// moved_vars[i]->OutputDef(out, 0);
// }
//}
// declare this variable as counter for subsequent function calls
out << "int global_call_id = 0; ";
outputln(out);
for (size_t i=0; i<reducer->artificial_globals.size(); i++) {
out << reducer->artificial_globals[i] << ";" << endl;
}
}

Expand Down

0 comments on commit 11305f8

Please sign in to comment.