From 3429652f452081ce04b59b7e798c35bd118bf916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20H=C3=B6lscher?= Date: Fri, 6 May 2022 10:04:45 +0200 Subject: [PATCH] Correct MustAnalysis. --- .vscode/launch.json | 2 +- CacheAnalysisPass/CacheAnalysisPass.cpp | 3 +- helper.sh | 22 ++++++------ include/AbstractCache.h | 46 ++++++++++++++----------- include/AbstractState.h | 41 ++++++++++------------ poolhelper.sh | 22 ++++++------ 6 files changed, 69 insertions(+), 67 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index eb3a209..aa8dcd9 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -13,7 +13,7 @@ "-load-pass-plugin", "${workspaceFolder}/build/libCacheAnalysisPass.so", "-passes=lru-misses", - "${workspaceFolder}/test/fft1.ll", + "${workspaceFolder}/test/cnt.ll", "-o", "/dev/null" ], diff --git a/CacheAnalysisPass/CacheAnalysisPass.cpp b/CacheAnalysisPass/CacheAnalysisPass.cpp index d02b5dd..97c4d2a 100644 --- a/CacheAnalysisPass/CacheAnalysisPass.cpp +++ b/CacheAnalysisPass/CacheAnalysisPass.cpp @@ -231,8 +231,7 @@ struct CacheAnalysisPass : PassInfoMixin { } if(LoopUnrolling) AC.unrollLoops(); - AC.fillAbstractCache(EntryAddress); - //AC.fillPath(EntryAddress); + AC.runMustAnalysis(EntryAddress); if (DumpNodes) AC.dumpNodes(); if (PrintEdgesPost) diff --git a/helper.sh b/helper.sh index 7c36001..c4138d6 100755 --- a/helper.sh +++ b/helper.sh @@ -111,29 +111,29 @@ case $1 in docker run -i -d -v "$(pwd)"/.:/root:rw --name RTSAlab01 rtsalab01cacheanalysis ;; evaluation | eval) - run "fft1" - echo "==== Correct fft1 ====" - echo "MustHits: 21" + run "crc" + echo "==== Correct crc ====" + echo "MustHits: 90" echo run "cnt" echo "==== Correct cnt ====" - echo "MustHits: 4" + echo "MustHits: 28" echo run "duff" echo "==== Correct duff ====" - echo "MustHits: 3" + echo "MustHits: 78" + echo + run "fft1" + echo "==== Correct fft1 ====" + echo "MustHits: 74" echo run "insertsort" echo "==== Correct insertsort ====" - echo "MustHits: 2" + echo "MustHits: 61" echo run "matmult" echo "==== Correct matmult ====" - echo "MustHits: 9" - echo - run "crc" - echo "==== Correct crc ====" - echo "MustHits: 6" + echo "MustHits: 34" echo ;; a | all) diff --git a/include/AbstractCache.h b/include/AbstractCache.h index 3040dd3..b4cf544 100644 --- a/include/AbstractCache.h +++ b/include/AbstractCache.h @@ -329,29 +329,35 @@ public: // everything is public, because IDGAF } /** - * @brief Idea fill the graph with the node and perform loop unrolling. + * @brief Perform must analysis in the Graph * * @param NodeNr */ - void fillAbstractCache(unsigned int NodeNr) { - // if(isLoopHead(NodeNr)) - Nodes[NodeNr].Computed = true; - for (unsigned int SuccNr : Nodes[NodeNr].Successors) { - Nodes[SuccNr]; - // first Run - if (Nodes[SuccNr].Computed) { - // Join don't call - AbstractState Before(Nodes[SuccNr]); - Nodes[SuccNr].mustJoin(AbstractState(NodeNr, Address(NodeNr))); + void runMustAnalysis(unsigned int NodeNr) { + // Join and call until the state converges. - // Continue Joining until State converges - if (!(Before == Nodes[SuccNr])) { - fillAbstractCache(NodeNr); - } + Nodes[NodeNr].Computed++; + + // fill all Successors, if filled Already join. + for (unsigned int SuccNr : Nodes[NodeNr].Successors) { + if (Nodes[SuccNr].Filled) { + // Join Successor with current State and its Address + Nodes[SuccNr].mustJoin( + AbstractState(Nodes[NodeNr], Address(Nodes[NodeNr].Addr))); } else { - // Update and fill Succ - Nodes[SuccNr].fill(Nodes[NodeNr], NodeNr); - fillAbstractCache(SuccNr); + // Fill Successor with current State and its Address + Nodes[SuccNr].fill(Nodes[NodeNr], Address(Nodes[NodeNr].Addr)); + // first Fill, so set Filled + Nodes[SuccNr].Filled = true; + } + + // Continue Filling CFG on Successors. + for (unsigned int SuccNr : Nodes[NodeNr].Successors) { + // We can use this as we can safely assume a State has at most two successors. + // Due to branch instruction in llvmIR + if (Nodes[NodeNr].Computed > 2) + continue; + runMustAnalysis(SuccNr); } } return; @@ -368,7 +374,7 @@ public: // everything is public, because IDGAF auto Predecessor = Nodes[E.first]; for (unsigned int SuccessorAddr : E.second) { // When successors Address is in predecessor, we have a Hit. - Hits += Predecessor.isHit(Address(SuccessorAddr)) ? 1 : 0; + Hits += Predecessor.isHit(Address(Nodes[SuccessorAddr].Addr)) ? 1 : 0; } } return Hits; @@ -385,7 +391,7 @@ public: // everything is public, because IDGAF auto Predecessor = Nodes[E.first]; for (unsigned int SuccessorAddr : E.second) { // When successors Address is in predecessor, we have a Hit. - Misses += Predecessor.isHit(Address(SuccessorAddr)) ? 0 : 1; + Misses += Predecessor.isHit(Address(Nodes[SuccessorAddr].Addr)) ? 0 : 1; } } return Misses; diff --git a/include/AbstractState.h b/include/AbstractState.h index 1d4fa21..46149d6 100644 --- a/include/AbstractState.h +++ b/include/AbstractState.h @@ -30,7 +30,8 @@ public: // everything is public, because IDGAF unsigned int Addr; unsigned int Unrolled; - bool Computed = false; + int Computed = 0; + bool Filled = false; // Only entries below this comment are needed for the exercise. @@ -164,6 +165,11 @@ public: // everything is public, because IDGAF * @param Addr , Address */ void update(Address Addr) { + // If Updated Address is of Age 0 do nothing + if (std::find(Sets[Addr.Index].Associativity[0].Blocks.begin(), + Sets[Addr.Index].Associativity[0].Blocks.end(), + Addr.Tag) != Sets[Addr.Index].Associativity[0].Blocks.end()) + return; // 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]; @@ -173,27 +179,6 @@ public: // everything is public, because IDGAF 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 Fills the AbstractState PreState and updates with PreAddress. * @@ -202,6 +187,7 @@ public: // everything is public, because IDGAF * @param PreAddr Address of PreState */ void fill(AbstractState PreState, Address PreAddr) { + bool Verbose = false; // copy Pre State into this. for (auto S : PreState.Sets) { unsigned int Index = S.first; @@ -216,13 +202,24 @@ public: // everything is public, because IDGAF } } } + if (Verbose) { + llvm::outs() << "Before:\n"; + this->dump(); + } // update this with PreAddr this->update(PreAddr); + if (Verbose) { + llvm::outs() << "Update Tag: " << PreAddr.Tag << "\n"; + llvm::outs() << "Update Set: " << PreAddr.Index << "\n"; + llvm::outs() << "After:\n"; + this->dump(); + } } void dump() { llvm::outs() << Addr << " {\n"; llvm::outs() << "Unrolled: " << Unrolled << "\n"; + llvm::outs() << "Computed: " << Computed << "\n"; llvm::outs() << "Predecessors: "; for (auto PreNr : Predecessors) { llvm::outs() << PreNr << " "; diff --git a/poolhelper.sh b/poolhelper.sh index d20d2a3..1bd33f3 100755 --- a/poolhelper.sh +++ b/poolhelper.sh @@ -145,29 +145,29 @@ case $1 in docker run -i -d -v "$(pwd)"/.:/root:rw --name RTSAlab01 rtsalab01cacheanalysis ;; evaluation | eval) - run "fft1" - echo "==== Correct fft1 ====" - echo "MustHits: 21" + run "crc" + echo "==== Correct crc ====" + echo "MustHits: 90" echo run "cnt" echo "==== Correct cnt ====" - echo "MustHits: 4" + echo "MustHits: 28" echo run "duff" echo "==== Correct duff ====" - echo "MustHits: 3" + echo "MustHits: 78" + echo + run "fft1" + echo "==== Correct fft1 ====" + echo "MustHits: 74" echo run "insertsort" echo "==== Correct insertsort ====" - echo "MustHits: 2" + echo "MustHits: 61" echo run "matmult" echo "==== Correct matmult ====" - echo "MustHits: 9" - echo - run "crc" - echo "==== Correct crc ====" - echo "MustHits: 6" + echo "MustHits: 34" echo ;; a | all)