Correct MustAnalysis.
This commit is contained in:
parent
c451a1eed0
commit
3429652f45
|
@ -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"
|
||||
],
|
||||
|
|
|
@ -231,8 +231,7 @@ struct CacheAnalysisPass : PassInfoMixin<CacheAnalysisPass> {
|
|||
}
|
||||
if(LoopUnrolling)
|
||||
AC.unrollLoops();
|
||||
AC.fillAbstractCache(EntryAddress);
|
||||
//AC.fillPath(EntryAddress);
|
||||
AC.runMustAnalysis(EntryAddress);
|
||||
if (DumpNodes)
|
||||
AC.dumpNodes();
|
||||
if (PrintEdgesPost)
|
||||
|
|
22
helper.sh
22
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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 << " ";
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue