diff --git a/include/DataAccessHandler.hpp b/include/DataAccessHandler.hpp index b5c96f6..dbc3352 100644 --- a/include/DataAccessHandler.hpp +++ b/include/DataAccessHandler.hpp @@ -28,17 +28,17 @@ namespace spf_ie { * is difficult to work with for our purposes. */ struct ArrayAccess { - ArrayAccess(int64_t id, Expr *base, std::vector &indexes, bool isRead) - : id(id), base(base), indexes(indexes), isRead(isRead) {} + ArrayAccess(std::string arrayName, int64_t sourceId, std::vector &indexes, bool isRead) + : arrayName(arrayName), sourceId(sourceId), indexes(indexes), isRead(isRead) {} //! Get a string representation of the array access, like A(i,j). - //! \param[in] potentialSubaccesses Other array accesses which may be used as indexes in this one + //! \param[in] potentialSubaccesses Other array accesses here, which may be used as indexes in this one std::string toString(const std::vector &potentialSubaccesses) const; - //! ID of original AST array access expression - int64_t id; - //! Base array being accessed - Expr *base; + //! ID of original ArraySubscriptExpr node + int64_t sourceId; + //! Name of base (outermost) array being accessed + std::string arrayName; //! Indexes accessed in the array std::vector indexes; //! Whether this access is a read or not (a write) diff --git a/src/DataAccessHandler.cpp b/src/DataAccessHandler.cpp index f115dc6..92ba2d9 100644 --- a/src/DataAccessHandler.cpp +++ b/src/DataAccessHandler.cpp @@ -18,7 +18,7 @@ namespace spf_ie { std::string ArrayAccess::toString(const std::vector &potentialSubaccesses) const { std::ostringstream os; - os << DATA_SPACE_DELIMITER << Utils::stmtToString(this->base) << DATA_SPACE_DELIMITER; + os << DATA_SPACE_DELIMITER << this->arrayName << DATA_SPACE_DELIMITER; os << "("; bool first = true; for (const auto &it: this->indexes) { @@ -32,7 +32,7 @@ std::string ArrayAccess::toString(const std::vector &potentialSubac // there is another array access used as an index for this one bool foundSubaccess = false; for (const auto &it: potentialSubaccesses) { - if (it.id == asArrayAccess-> + if (it.sourceId == asArrayAccess-> getID(*Context) ) { foundSubaccess = true; @@ -78,7 +78,7 @@ void DataAccessHandler::addDataAccess(ArraySubscriptExpr *fullExpr, buildDataAccess(fullExpr, isRead, accesses); for (const auto &access: accesses) { - dataSpaces.emplace(Utils::stmtToString(access.base)); + dataSpaces.emplace(access.arrayName); arrayAccesses.push_back(access); } } @@ -95,7 +95,7 @@ void DataAccessHandler::buildDataAccess( } // construct ArrayAccess object - Expr *base = info.top(); + Expr *baseAccess = info.top(); info.pop(); std::vector indexes; while (!info.empty()) { @@ -109,7 +109,8 @@ void DataAccessHandler::buildDataAccess( info.pop(); } - existingAccesses.emplace_back(ArrayAccess(fullExpr->getID(*Context), base, indexes, isRead)); + existingAccesses + .emplace_back(ArrayAccess(Utils::stmtToString(baseAccess), fullExpr->getID(*Context), indexes, isRead)); } int DataAccessHandler::getArrayExprInfo(ArraySubscriptExpr *fullExpr, diff --git a/src/SPFComputationBuilder.cpp b/src/SPFComputationBuilder.cpp index 6a1d466..9c461b8 100644 --- a/src/SPFComputationBuilder.cpp +++ b/src/SPFComputationBuilder.cpp @@ -57,8 +57,7 @@ SPFComputationBuilder::buildComputationFromFunction(FunctionDecl *funcDecl) { std::vector> dataReads; std::vector> dataWrites; for (auto &it_accesses: stmtContext.dataAccesses.arrayAccesses) { - std::string dataSpaceAccessed = - Utils::stmtToString(it_accesses.base); + std::string dataSpaceAccessed = it_accesses.arrayName; // enforce loop invariance if (!it_accesses.isRead) { for (const auto &invariantGroup: stmtContext.invariants) { diff --git a/src/StmtContext.cpp b/src/StmtContext.cpp index c835b30..e676a60 100644 --- a/src/StmtContext.cpp +++ b/src/StmtContext.cpp @@ -147,7 +147,7 @@ void StmtContext::enterFor(ForStmt *forStmt) { } for (const auto &access: accesses) { newInvariants.push_back( - Utils::stmtToString(access.base)); + access.arrayName); } invariants.push_back(newInvariants); } else {