diff --git a/benchmark/scope/benchmark_scope.cpp b/benchmark/scope/benchmark_scope.cpp index 4c927a8a4..ad34c9b4e 100644 --- a/benchmark/scope/benchmark_scope.cpp +++ b/benchmark/scope/benchmark_scope.cpp @@ -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); } } @@ -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); } } @@ -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); } } @@ -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); } } @@ -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); } } @@ -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); } } @@ -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); } } @@ -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); } } diff --git a/rtlib/functions/dp_read.cpp b/rtlib/functions/dp_read.cpp index 012b6b081..e31b06355 100644 --- a/rtlib/functions/dp_read.cpp +++ b/rtlib/functions/dp_read.cpp @@ -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); diff --git a/rtlib/functions/dp_write.cpp b/rtlib/functions/dp_write.cpp index 7c0f9eb26..f79276ba4 100644 --- a/rtlib/functions/dp_write.cpp +++ b/rtlib/functions/dp_write.cpp @@ -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); diff --git a/rtlib/iFunctions.cpp b/rtlib/iFunctions.cpp index 6c6d21d2e..27a8c153d 100644 --- a/rtlib/iFunctions.cpp +++ b/rtlib/iFunctions.cpp @@ -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 { @@ -857,7 +857,7 @@ 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); @@ -865,7 +865,7 @@ void *analyzeDeps(void *arg) { // 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); @@ -873,7 +873,7 @@ void *analyzeDeps(void *arg) { // WAW addDep(WAW, access.lid, lastWrite, access.var, access.AAvar, access.isStackAccess, access.addr, - access.addrIsFirstWrittenInScope, + access.addrIsOwnedByScope, access.positiveScopeChangeOccuredSinceLastAccess); } } diff --git a/rtlib/iFunctionsTypes.hpp b/rtlib/iFunctionsTypes.hpp index 592afbcd1..0f09a1687 100644 --- a/rtlib/iFunctionsTypes.hpp +++ b/rtlib/iFunctionsTypes.hpp @@ -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; }; diff --git a/rtlib/scope.hpp b/rtlib/scope.hpp index 5f846a479..e2628a02b 100644 --- a/rtlib/scope.hpp +++ b/rtlib/scope.hpp @@ -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) @@ -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 { diff --git a/test/unit_tests/scope/test_scope.cpp b/test/unit_tests/scope/test_scope.cpp index f61671b26..6f8808d7d 100644 --- a/test/unit_tests/scope/test_scope.cpp +++ b/test/unit_tests/scope/test_scope.cpp @@ -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) { @@ -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) {