From 693ee07008e545c2a6f6f28aaa3c5b41575882c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20H=C3=B6lscher?= Date: Tue, 3 May 2022 14:04:21 +0200 Subject: [PATCH] Joining until state converges. Added Eval Again. --- .gitignore | 1 + CacheAnalysisPass/CacheAnalysisPass.cpp | 3 +- helper.sh | 27 +++------ include/AbstractCache.h | 53 ++++++++-------- include/AbstractState.h | 81 +++++++++++++++++++------ poolhelper.sh | 67 ++++++++------------ 6 files changed, 126 insertions(+), 106 deletions(-) diff --git a/.gitignore b/.gitignore index e2f0333..e275226 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,6 @@ build/ .gnupg .bash_history .cache/ +*.solution compile_commands.json llvm/ \ No newline at end of file diff --git a/CacheAnalysisPass/CacheAnalysisPass.cpp b/CacheAnalysisPass/CacheAnalysisPass.cpp index f0d85e3..ff6795b 100644 --- a/CacheAnalysisPass/CacheAnalysisPass.cpp +++ b/CacheAnalysisPass/CacheAnalysisPass.cpp @@ -232,6 +232,7 @@ struct CacheAnalysisPass : PassInfoMixin { if(LoopUnrolling) AC.unrollLoops(); AC.fillAbstractCache(EntryAddress); + //AC.fillPath(EntryAddress); if (DumpNodes) AC.dumpNodes(); if (PrintEdgesPost) @@ -239,7 +240,7 @@ struct CacheAnalysisPass : PassInfoMixin { if (DumpToDot) AC.dumpDotFile(); outs() << "MustHits: " << AC.collectHits() << "\n"; - outs() << "MayMisses: " << AC.collectMisses() << "\n"; + //outs() << "MayMisses: " << AC.collectMisses() << "\n"; return PreservedAnalyses::all(); } }; diff --git a/helper.sh b/helper.sh index ee575c6..7c36001 100755 --- a/helper.sh +++ b/helper.sh @@ -111,38 +111,29 @@ case $1 in docker run -i -d -v "$(pwd)"/.:/root:rw --name RTSAlab01 rtsalab01cacheanalysis ;; evaluation | eval) - echo "Currently not available!" - echo "But please continue to implement the must join," - echo "to the best of your abilities and check for updates!" run "fft1" echo "==== Correct fft1 ====" - echo "MustHits: 16" - echo "MayMisses: 280" + echo "MustHits: 21" echo run "cnt" echo "==== Correct cnt ====" - echo "MustHits: x" - echo "MayMisses: xx" - echo - run "crc" - echo "==== Correct crc ====" - echo "MustHits: x" - echo "MayMisses: xx" + echo "MustHits: 4" echo run "duff" echo "==== Correct duff ====" - echo "MustHits: x" - echo "MayMisses: xx" + echo "MustHits: 3" echo run "insertsort" echo "==== Correct insertsort ====" - echo "MustHits: x" - echo "MayMisses: xx" + echo "MustHits: 2" echo run "matmult" echo "==== Correct matmult ====" - echo "MustHits: x" - echo "MayMisses: x" + echo "MustHits: 9" + echo + run "crc" + echo "==== Correct crc ====" + echo "MustHits: 6" echo ;; a | all) diff --git a/include/AbstractCache.h b/include/AbstractCache.h index bc522c9..3040dd3 100644 --- a/include/AbstractCache.h +++ b/include/AbstractCache.h @@ -47,9 +47,9 @@ public: // everything is public, because IDGAF /** * @brief Add an Edge to the AbstractStateGraph - * - * @param Pre - * @param Suc + * + * @param Pre + * @param Suc */ void removeEdge(unsigned int Pre, unsigned int Suc) { Edges[Pre].remove(Suc); @@ -59,9 +59,9 @@ public: // everything is public, because IDGAF /** * @brief Add an Empty node @NodeAddr - * - * @param NodeAddr - * @return unsigned int + * + * @param NodeAddr + * @return unsigned int */ unsigned int addEmptyNode(unsigned int NodeAddr) { int I = Nodes.size(); @@ -71,11 +71,11 @@ public: // everything is public, because IDGAF /** * @brief Returns True if a path From -> To exists. - * - * @param From - * @param To - * @return true - * @return false + * + * @param From + * @param To + * @return true + * @return false */ bool findPath(unsigned int From, unsigned int To) { std::map Visited; @@ -97,9 +97,9 @@ public: // everything is public, because IDGAF /** * @brief Removes all Nested loops from the handed LoopBody - * - * @param LoopBodyIn - * @param OrigNodeToUnrolledNode + * + * @param LoopBodyIn + * @param OrigNodeToUnrolledNode */ void removeNestedLoops( std::list LoopBodyIn, @@ -338,11 +338,16 @@ public: // everything is public, because IDGAF Nodes[NodeNr].Computed = true; for (unsigned int SuccNr : Nodes[NodeNr].Successors) { Nodes[SuccNr]; + // first Run if (Nodes[SuccNr].Computed) { // Join don't call - // TODO fix Join - Nodes[SuccNr].mustJoin(Nodes[NodeNr]); // maybe fill - Nodes[SuccNr].mustJoin(AbstractState(NodeNr)); + AbstractState Before(Nodes[SuccNr]); + Nodes[SuccNr].mustJoin(AbstractState(NodeNr, Address(NodeNr))); + + // Continue Joining until State converges + if (!(Before == Nodes[SuccNr])) { + fillAbstractCache(NodeNr); + } } else { // Update and fill Succ Nodes[SuccNr].fill(Nodes[NodeNr], NodeNr); @@ -354,8 +359,8 @@ public: // everything is public, because IDGAF /** * @brief Return number of measured Hits - * - * @return unsigned int + * + * @return unsigned int */ unsigned int collectHits() { unsigned int Hits = 0; @@ -371,8 +376,8 @@ public: // everything is public, because IDGAF /** * @brief Return number of measured Misses - * - * @return unsigned int + * + * @return unsigned int */ unsigned int collectMisses() { unsigned int Misses = 0; @@ -388,7 +393,7 @@ public: // everything is public, because IDGAF /** * @brief Prints all Edges to Console - * + * */ void dumpEdges() { llvm::outs() << "Dumping Edges:\n"; @@ -409,7 +414,7 @@ public: // everything is public, because IDGAF /** * @brief Dumps the Graph to a out.dot file - * + * */ void dumpDotFile() { bool PrintOld = true; @@ -437,7 +442,7 @@ public: // everything is public, because IDGAF /** * @brief Prints all nodes to Console - * + * */ void dumpNodes() { for (auto const &E : Edges) { diff --git a/include/AbstractState.h b/include/AbstractState.h index 1b4da84..1d4fa21 100644 --- a/include/AbstractState.h +++ b/include/AbstractState.h @@ -1,6 +1,7 @@ #ifndef ABSSTATE_H #define ABSSTATE_H +#include #include #include #include @@ -71,6 +72,21 @@ public: // everything is public, because IDGAF } } + AbstractState(AbstractState const &Copy, Address Update) { + Addr = Copy.Addr; + Unrolled = Copy.Unrolled; + for (auto S : Copy.Sets) { + unsigned int SetNr = S.first; + for (auto E : S.second.Associativity) { + unsigned int Age = E.first; + for (auto B : E.second.Blocks) { + Sets[SetNr].Associativity[Age].Blocks.push_back(B); + } + } + } + this->update(Update); + } + AbstractState() {} AbstractState(unsigned int AddressIn) { @@ -89,6 +105,30 @@ public: // everything is public, because IDGAF void setUnrolled(unsigned int In) { Unrolled = In; } + bool operator==(AbstractState In) { + for (int Index; Index < 16; Index++) { + for (int Age; Age < 4; Age++) { + for (auto E1 : Sets[Index].Associativity[Age].Blocks) { + // find E1 in In States Set and Age. + if (std::find(In.Sets[Index].Associativity[Age].Blocks.begin(), + In.Sets[Index].Associativity[Age].Blocks.end(), + E1) == In.Sets[Index].Associativity[Age].Blocks.end()) { + return false; + } + } + for (auto E2 : In.Sets[Index].Associativity[Age].Blocks) { + // find E2 in This Set and Age. + if (std::find(Sets[Index].Associativity[Age].Blocks.begin(), + Sets[Index].Associativity[Age].Blocks.end(), + E2) == Sets[Index].Associativity[Age].Blocks.end()) { + return false; + } + } + } + } + return true; + } + /** * @brief Executes an Must LRU Join on the AbstractCacheState * @@ -127,31 +167,32 @@ public: // everything is public, because IDGAF // This loopages all entries by one. 3 <-2, 2<-1, 1<-0 for (int I = 3; I > 0; I--) { Sets[Addr.Index].Associativity[I] = Sets[Addr.Index].Associativity[I - 1]; + Sets[Addr.Index].Associativity[I].Blocks.remove(Addr.Tag); } // entry at age 0 is updated with current address. Sets[Addr.Index].Associativity[0].Blocks = {Addr.Tag}; } - /** - * @brief Updates the AbstractState with given AbstractState - * - * @param UpdateState, State that gets merged into State with Age+1. - */ - void update(AbstractState UpdateState) { - for (auto S : UpdateState.Sets) { - unsigned int Index = S.first; - for (auto E : S.second.Associativity) { - unsigned int Age = E.first; - // If updated age is greater 4 The Tag is no longer in Cache. - // Due to associativity of 4 per set. - if (Age >= 4) - break; - for (auto B : E.second.Blocks) { - Sets[Index].Associativity[Age].Blocks.push_back(B); - } - } - } - } + // /** + // * @brief Updates the AbstractState with given AbstractState + // * + // * @param UpdateState, State that gets merged into State with Age+1. + // */ + // void update(AbstractState UpdateState) { + // for (auto S : UpdateState.Sets) { + // unsigned int Index = S.first; + // for (auto E : S.second.Associativity) { + // unsigned int Age = E.first; + // // If updated age is greater 4 The Tag is no longer in Cache. + // // Due to associativity of 4 per set. + // if (Age >= 4) + // break; + // for (auto B : E.second.Blocks) { + // Sets[Index].Associativity[Age].Blocks.push_back(B); + // } + // } + // } + // } /** * @brief Fills the AbstractState PreState and updates with PreAddress. diff --git a/poolhelper.sh b/poolhelper.sh index 9918002..d20d2a3 100755 --- a/poolhelper.sh +++ b/poolhelper.sh @@ -145,49 +145,30 @@ case $1 in docker run -i -d -v "$(pwd)"/.:/root:rw --name RTSAlab01 rtsalab01cacheanalysis ;; evaluation | eval) - echo "Currently not available!" - echo "But please continue to implement the must join," - echo "to the best of your abilities and check for updates!" - # run "fft1" - # echo "==== Correct fft1 ====" - # echo "MustHits: 16" - # echo "MayMisses: 280" - # echo - # run "bsort100" - # echo "==== Correct bsort100 ====" - # echo "MustHits: 1" - # echo "MayMisses: 41" - # echo - # run "lms" - # echo "==== Correct lms ====" - # echo "MustHits: 5" - # echo "MayMisses: 288" - # echo - # run "minver" - # echo "==== Correct minver ====" - # echo "MustHits: 6" - # echo "MayMisses: 224" - # echo - # run "qsort-exam" - # echo "==== Correct qsort-exam ====" - # echo "MustHits: 2" - # echo "MayMisses: 152" - # echo - # run "recursion" - # echo "==== Correct recursion ====" - # echo "MustHits: 8" - # echo "MayMisses: 8" - # echo - # run "select" - # echo "==== Correct select ====" - # echo "MustHits: 4" - # echo "MayMisses: 108" - # echo - # run "whet" - # echo "==== Correct whet ====" - # echo "MustHits: 5" - # echo "MayMisses: 265" - # echo + run "fft1" + echo "==== Correct fft1 ====" + echo "MustHits: 21" + echo + run "cnt" + echo "==== Correct cnt ====" + echo "MustHits: 4" + echo + run "duff" + echo "==== Correct duff ====" + echo "MustHits: 3" + echo + run "insertsort" + echo "==== Correct insertsort ====" + echo "MustHits: 2" + echo + run "matmult" + echo "==== Correct matmult ====" + echo "MustHits: 9" + echo + run "crc" + echo "==== Correct crc ====" + echo "MustHits: 6" + echo ;; a | all) clean