diff --git a/src/Transformations/MoveOperators/move_operators.cpp b/src/Transformations/MoveOperators/move_operators.cpp index 686cbd3..be51ce1 100644 --- a/src/Transformations/MoveOperators/move_operators.cpp +++ b/src/Transformations/MoveOperators/move_operators.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include #include #include @@ -192,6 +191,94 @@ static map> analyzeBasicBlockIntraDependencies(c return normalizeSageString(raw ? string(raw) : string()); }; + function canonicalExprKey; + canonicalExprKey = [&](SgExpression* expr) -> string + { + if (!expr) + return string(); + + const int v = expr->variant(); + + if (v == ADD_OP) + { + vector terms; + function flattenAdd = [&](SgExpression* e) + { + if (!e) + return; + if (e->variant() == ADD_OP) + { + flattenAdd(e->lhs()); + flattenAdd(e->rhs()); + } + else + terms.push_back(canonicalExprKey(e)); + }; + flattenAdd(expr); + sort(terms.begin(), terms.end()); + string joined; + for (size_t i = 0; i < terms.size(); ++i) + { + if (i) + joined += " + "; + joined += terms[i]; + } + return joined; + } + + if (v == MULT_OP) + { + vector factors; + function flattenMult = [&](SgExpression* e) + { + if (!e) + return; + if (e->variant() == MULT_OP) + { + flattenMult(e->lhs()); + flattenMult(e->rhs()); + } + else + factors.push_back(canonicalExprKey(e)); + }; + flattenMult(expr); + sort(factors.begin(), factors.end()); + string joined; + for (size_t i = 0; i < factors.size(); ++i) + { + if (i) + joined += " * "; + joined += factors[i]; + } + return joined; + } + + SgExpression *l = expr->lhs(); + SgExpression *r = expr->rhs(); + + if (l && r) + { + if (v == SUBT_OP || v == SUB_OP) + return canonicalExprKey(l) + string(" - ") + canonicalExprKey(r); + if (v == DIV_OP || v == INTEGER_DIV_OP) + return canonicalExprKey(l) + string(" / ") + canonicalExprKey(r); + if (v == EXP_OP) + return canonicalExprKey(l) + string(" ** ") + canonicalExprKey(r); + } + + if (l && !r) + { + if (v == MINUS_OP) + return string("-") + canonicalExprKey(l); + if (v == UNARY_ADD_OP) + return canonicalExprKey(l); + if (v == CAST_OP) + return canonicalExprKey(l); + } + + return sageExprToString(expr); + }; + auto arrayElementKey = [&](SgArrayRefExp* arrayRef) -> string { if (!arrayRef) @@ -212,7 +299,7 @@ static map> analyzeBasicBlockIntraDependencies(c { if (i) key += ", "; - key += sageExprToString(arrayRef->subscript(i)); + key += canonicalExprKey(arrayRef->subscript(i)); } key += ")";