Skip to content

Commit

Permalink
fix(profiler): rename addrIsFirstWrittenInScope -> addrIsOwnedByScope
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasrothenberger committed May 10, 2024
1 parent bab342e commit 8aff773
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 56 deletions.
16 changes: 8 additions & 8 deletions benchmark/scope/benchmark_scope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ static void benchmark_scope_manager_first_written(benchmark::State& state) {
}

if (first_written_address(addr, 1)) {
const auto b = manager.isFirstWrittenInScope(addr, true);
const auto b = manager.isOwnedByScope(addr, true);
}
}

Expand All @@ -262,7 +262,7 @@ static void benchmark_scope_manager_first_written(benchmark::State& state) {
}

if (first_written_address(addr, 2)) {
const auto b = manager.isFirstWrittenInScope(addr, true);
const auto b = manager.isOwnedByScope(addr, true);
}
}

Expand All @@ -278,7 +278,7 @@ static void benchmark_scope_manager_first_written(benchmark::State& state) {
}

if (first_written_address(addr, 3)) {
const auto b = manager.isFirstWrittenInScope(addr, true);
const auto b = manager.isOwnedByScope(addr, true);
}
}

Expand All @@ -297,7 +297,7 @@ static void benchmark_scope_manager_first_written(benchmark::State& state) {
}

if (first_written_address(addr, 4)) {
const auto b = manager.isFirstWrittenInScope(addr, true);
const auto b = manager.isOwnedByScope(addr, true);
}
}

Expand Down Expand Up @@ -600,7 +600,7 @@ static void benchmark_scope_manager_2_first_written(benchmark::State& state) {
}

if (first_written_address(addr, 1)) {
const auto b = manager.isFirstWrittenInScope(addr, true);
const auto b = manager.isOwnedByScope(addr, true);
}
}

Expand All @@ -616,7 +616,7 @@ static void benchmark_scope_manager_2_first_written(benchmark::State& state) {
}

if (first_written_address(addr, 2)) {
const auto b = manager.isFirstWrittenInScope(addr, true);
const auto b = manager.isOwnedByScope(addr, true);
}
}

Expand All @@ -632,7 +632,7 @@ static void benchmark_scope_manager_2_first_written(benchmark::State& state) {
}

if (first_written_address(addr, 3)) {
const auto b = manager.isFirstWrittenInScope(addr, true);
const auto b = manager.isOwnedByScope(addr, true);
}
}

Expand All @@ -651,7 +651,7 @@ static void benchmark_scope_manager_2_first_written(benchmark::State& state) {
}

if (first_written_address(addr, 4)) {
const auto b = manager.isFirstWrittenInScope(addr, true);
const auto b = manager.isOwnedByScope(addr, true);
}
}

Expand Down
4 changes: 2 additions & 2 deletions rtlib/functions/dp_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ void __dp_read(LID lid, ADDR addr, char *var) {
current.AAvar = getMemoryRegionIdFromAddr(var, addr);
current.addr = addr;
current.isStackAccess = is_stack_access;
current.addrIsFirstWrittenInScope =
scopeManager->isFirstWrittenInScope(addr, false);
current.addrIsOwnedByScope =
scopeManager->isOwnedByScope(addr, false);
current.positiveScopeChangeOccuredSinceLastAccess =
scopeManager->positiveScopeChangeOccuredSinceLastAccess(addr);

Expand Down
4 changes: 2 additions & 2 deletions rtlib/functions/dp_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ void __dp_write(LID lid, ADDR addr, char *var) {
current.AAvar = getMemoryRegionIdFromAddr(var, addr);
current.addr = addr;
current.isStackAccess = is_stack_access;
current.addrIsFirstWrittenInScope =
scopeManager->isFirstWrittenInScope(addr, true);
current.addrIsOwnedByScope =
scopeManager->isOwnedByScope(addr, true);
current.positiveScopeChangeOccuredSinceLastAccess =
scopeManager->positiveScopeChangeOccuredSinceLastAccess(addr);

Expand Down
8 changes: 4 additions & 4 deletions rtlib/iFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ void *analyzeDeps(void *arg) {
SMem->insertToRead(access.addr, access.lid);
addDep(RAW, access.lid, lastWrite, access.var, access.AAvar,
access.isStackAccess, access.addr,
access.addrIsFirstWrittenInScope,
access.addrIsOwnedByScope,
access.positiveScopeChangeOccuredSinceLastAccess);
}
} else {
Expand All @@ -857,23 +857,23 @@ void *analyzeDeps(void *arg) {
// INIT
addDep(INIT, access.lid, 0, access.var, access.AAvar,
access.isStackAccess, access.addr,
access.addrIsFirstWrittenInScope,
access.addrIsOwnedByScope,
access.positiveScopeChangeOccuredSinceLastAccess);
} else {
sigElement lastRead = SMem->testInRead(access.addr);
if (lastRead != 0) {
// WAR
addDep(WAR, access.lid, lastRead, access.var, access.AAvar,
access.isStackAccess, access.addr,
access.addrIsFirstWrittenInScope,
access.addrIsOwnedByScope,
access.positiveScopeChangeOccuredSinceLastAccess);
// Clear intermediate read ops
SMem->insertToRead(access.addr, 0);
} else {
// WAW
addDep(WAW, access.lid, lastWrite, access.var, access.AAvar,
access.isStackAccess, access.addr,
access.addrIsFirstWrittenInScope,
access.addrIsOwnedByScope,
access.positiveScopeChangeOccuredSinceLastAccess);
}
}
Expand Down
2 changes: 1 addition & 1 deletion rtlib/iFunctionsTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct AccessInfo {
std::string AAvar; // name of allocated variable -> "Anti Aliased Variable"
ADDR addr;
bool isStackAccess = false;
bool addrIsFirstWrittenInScope = false;
bool addrIsOwnedByScope = false;
bool positiveScopeChangeOccuredSinceLastAccess = false;
};

Expand Down
45 changes: 30 additions & 15 deletions rtlib/scope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ struct ScopeManager {
addrToLastAccessScopeID[address] = scopeStack.back().get_id();
}

bool isFirstWrittenInScope(ADDR addr, bool currentAccessIsWrite) {
bool isOwnedByScope(ADDR addr, bool currentAccessIsWrite) {
// currentAccessIsWrite is used in case no access to addr has been

// check for first_writes in previous scopes (i.e.: search for the "owner" of the stack variable)
Expand Down Expand Up @@ -221,26 +221,41 @@ struct ScopeManager2 {
addrToLastAccessScopeID[address] = current_scope.get_id();
}

bool isFirstWrittenInScope(ADDR addr, bool currentAccessIsWrite) const noexcept {
const auto& current_scope = getCurrentScope();

const auto& writes = current_scope.get_first_write();
const auto writes_iterator = writes.find(addr);
// const auto writes_iterator = std::find(writes.begin(), writes.end(), addr);

if (writes_iterator != writes.end()) {
bool isOwnedByScope(ADDR addr, bool currentAccessIsWrite) {
// currentAccessIsWrite is used in case no access to addr has been

// check for first_writes in previous scopes (i.e.: search for the "owner" of the stack variable)
int idx = 0;
for(auto scope: scopeStack){
if(scope.get_first_write().count(addr) > 0){
if(idx == scopeStack.size()-1){
return true;
}
else{
// scope variable "belongs" to a parent scope.
// Thus, it may not be considered a scope variable for the inner scope.
return false;
}
}
idx++;

}

// registered already
if (scopeStack.back().get_first_write().count(addr) > 0) {
return true;
}

const auto& reads = current_scope.get_first_read();
const auto reads_iterator = reads.find(addr);
// const auto reads_iterator = std::find(reads.begin(), reads.end(), addr);

if (reads_iterator != reads.end()) {
if (scopeStack.back().get_first_read().count(addr) > 0) {
return false;
}

return currentAccessIsWrite;
// no access to addr registered in the current scope
if (currentAccessIsWrite) {
return true;
}

return false;
}

bool positiveScopeChangeOccuredSinceLastAccess(const ADDR addr) noexcept {
Expand Down
48 changes: 24 additions & 24 deletions test/unit_tests/scope/test_scope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,18 +330,18 @@ TEST_F(ScopeManagerTest, testFirstWritten) {
manager.registerStackWrite(36, 5, "");
manager.registerStackRead(40, 6, "");

ASSERT_TRUE(manager.isFirstWrittenInScope(36, true));
ASSERT_TRUE(manager.isFirstWrittenInScope(12, true));
ASSERT_TRUE(manager.isFirstWrittenInScope(24, true));
ASSERT_TRUE(manager.isFirstWrittenInScope(1012, true));
ASSERT_TRUE(manager.isFirstWrittenInScope(1024, true));

ASSERT_FALSE(manager.isFirstWrittenInScope(32, true));
ASSERT_FALSE(manager.isFirstWrittenInScope(32, false));
ASSERT_FALSE(manager.isFirstWrittenInScope(40, true));
ASSERT_FALSE(manager.isFirstWrittenInScope(40, false));
ASSERT_FALSE(manager.isFirstWrittenInScope(1012, false));
ASSERT_FALSE(manager.isFirstWrittenInScope(1024, false));
ASSERT_TRUE(manager.isOwnedByScope(36, true));
ASSERT_TRUE(manager.isOwnedByScope(1012, true));
ASSERT_TRUE(manager.isOwnedByScope(1024, true));

ASSERT_FALSE(manager.isOwnedByScope(12, true));
ASSERT_FALSE(manager.isOwnedByScope(24, true));
ASSERT_FALSE(manager.isOwnedByScope(32, true));
ASSERT_FALSE(manager.isOwnedByScope(32, false));
ASSERT_FALSE(manager.isOwnedByScope(40, true));
ASSERT_FALSE(manager.isOwnedByScope(40, false));
ASSERT_FALSE(manager.isOwnedByScope(1012, false));
ASSERT_FALSE(manager.isOwnedByScope(1024, false));
}

TEST_F(ScopeManagerTest, testPositiveChange) {
Expand Down Expand Up @@ -731,18 +731,18 @@ TEST_F(ScopeManager2Test, testFirstWritten) {
manager.registerStackWrite(36, 5, "");
manager.registerStackRead(40, 6, "");

ASSERT_TRUE(manager.isFirstWrittenInScope(36, true));
ASSERT_TRUE(manager.isFirstWrittenInScope(12, true));
ASSERT_TRUE(manager.isFirstWrittenInScope(24, true));
ASSERT_TRUE(manager.isFirstWrittenInScope(1012, true));
ASSERT_TRUE(manager.isFirstWrittenInScope(1024, true));

ASSERT_FALSE(manager.isFirstWrittenInScope(32, true));
ASSERT_FALSE(manager.isFirstWrittenInScope(32, false));
ASSERT_FALSE(manager.isFirstWrittenInScope(40, true));
ASSERT_FALSE(manager.isFirstWrittenInScope(40, false));
ASSERT_FALSE(manager.isFirstWrittenInScope(1012, false));
ASSERT_FALSE(manager.isFirstWrittenInScope(1024, false));
ASSERT_TRUE(manager.isOwnedByScope(36, true));
ASSERT_TRUE(manager.isOwnedByScope(1012, true));
ASSERT_TRUE(manager.isOwnedByScope(1024, true));

ASSERT_FALSE(manager.isOwnedByScope(12, true));
ASSERT_FALSE(manager.isOwnedByScope(24, true));
ASSERT_FALSE(manager.isOwnedByScope(32, true));
ASSERT_FALSE(manager.isOwnedByScope(32, false));
ASSERT_FALSE(manager.isOwnedByScope(40, true));
ASSERT_FALSE(manager.isOwnedByScope(40, false));
ASSERT_FALSE(manager.isOwnedByScope(1012, false));
ASSERT_FALSE(manager.isOwnedByScope(1024, false));
}

TEST_F(ScopeManager2Test, testPositiveChange) {
Expand Down

0 comments on commit 8aff773

Please sign in to comment.