Skip to content

Commit

Permalink
Adjust components stored in ArrayAccess #29
Browse files Browse the repository at this point in the history
  • Loading branch information
riftEmber committed Sep 19, 2021
1 parent ccdd1c1 commit 9b41b73
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
14 changes: 7 additions & 7 deletions include/DataAccessHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Expr *> &indexes, bool isRead)
: id(id), base(base), indexes(indexes), isRead(isRead) {}
ArrayAccess(std::string arrayName, int64_t sourceId, std::vector<Expr *> &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<ArrayAccess> &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<Expr *> indexes;
//! Whether this access is a read or not (a write)
Expand Down
11 changes: 6 additions & 5 deletions src/DataAccessHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace spf_ie {

std::string ArrayAccess::toString(const std::vector<ArrayAccess> &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) {
Expand All @@ -32,7 +32,7 @@ std::string ArrayAccess::toString(const std::vector<ArrayAccess> &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;
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -95,7 +95,7 @@ void DataAccessHandler::buildDataAccess(
}

// construct ArrayAccess object
Expr *base = info.top();
Expr *baseAccess = info.top();
info.pop();
std::vector<Expr *> indexes;
while (!info.empty()) {
Expand All @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions src/SPFComputationBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ SPFComputationBuilder::buildComputationFromFunction(FunctionDecl *funcDecl) {
std::vector<std::pair<std::string, std::string>> dataReads;
std::vector<std::pair<std::string, std::string>> 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) {
Expand Down
2 changes: 1 addition & 1 deletion src/StmtContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 9b41b73

Please sign in to comment.