forked from nils.hoelscher/RTSA-lab01-CacheAnalysis
Correct MustAnalysis.
This commit is contained in:
parent
c451a1eed0
commit
3429652f45
|
@ -13,7 +13,7 @@
|
||||||
"-load-pass-plugin",
|
"-load-pass-plugin",
|
||||||
"${workspaceFolder}/build/libCacheAnalysisPass.so",
|
"${workspaceFolder}/build/libCacheAnalysisPass.so",
|
||||||
"-passes=lru-misses",
|
"-passes=lru-misses",
|
||||||
"${workspaceFolder}/test/fft1.ll",
|
"${workspaceFolder}/test/cnt.ll",
|
||||||
"-o",
|
"-o",
|
||||||
"/dev/null"
|
"/dev/null"
|
||||||
],
|
],
|
||||||
|
|
|
@ -231,8 +231,7 @@ struct CacheAnalysisPass : PassInfoMixin<CacheAnalysisPass> {
|
||||||
}
|
}
|
||||||
if(LoopUnrolling)
|
if(LoopUnrolling)
|
||||||
AC.unrollLoops();
|
AC.unrollLoops();
|
||||||
AC.fillAbstractCache(EntryAddress);
|
AC.runMustAnalysis(EntryAddress);
|
||||||
//AC.fillPath(EntryAddress);
|
|
||||||
if (DumpNodes)
|
if (DumpNodes)
|
||||||
AC.dumpNodes();
|
AC.dumpNodes();
|
||||||
if (PrintEdgesPost)
|
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
|
docker run -i -d -v "$(pwd)"/.:/root:rw --name RTSAlab01 rtsalab01cacheanalysis
|
||||||
;;
|
;;
|
||||||
evaluation | eval)
|
evaluation | eval)
|
||||||
run "fft1"
|
run "crc"
|
||||||
echo "==== Correct fft1 ===="
|
echo "==== Correct crc ===="
|
||||||
echo "MustHits: 21"
|
echo "MustHits: 90"
|
||||||
echo
|
echo
|
||||||
run "cnt"
|
run "cnt"
|
||||||
echo "==== Correct cnt ===="
|
echo "==== Correct cnt ===="
|
||||||
echo "MustHits: 4"
|
echo "MustHits: 28"
|
||||||
echo
|
echo
|
||||||
run "duff"
|
run "duff"
|
||||||
echo "==== Correct duff ===="
|
echo "==== Correct duff ===="
|
||||||
echo "MustHits: 3"
|
echo "MustHits: 78"
|
||||||
|
echo
|
||||||
|
run "fft1"
|
||||||
|
echo "==== Correct fft1 ===="
|
||||||
|
echo "MustHits: 74"
|
||||||
echo
|
echo
|
||||||
run "insertsort"
|
run "insertsort"
|
||||||
echo "==== Correct insertsort ===="
|
echo "==== Correct insertsort ===="
|
||||||
echo "MustHits: 2"
|
echo "MustHits: 61"
|
||||||
echo
|
echo
|
||||||
run "matmult"
|
run "matmult"
|
||||||
echo "==== Correct matmult ===="
|
echo "==== Correct matmult ===="
|
||||||
echo "MustHits: 9"
|
echo "MustHits: 34"
|
||||||
echo
|
|
||||||
run "crc"
|
|
||||||
echo "==== Correct crc ===="
|
|
||||||
echo "MustHits: 6"
|
|
||||||
echo
|
echo
|
||||||
;;
|
;;
|
||||||
a | all)
|
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
|
* @param NodeNr
|
||||||
*/
|
*/
|
||||||
void fillAbstractCache(unsigned int NodeNr) {
|
void runMustAnalysis(unsigned int NodeNr) {
|
||||||
// if(isLoopHead(NodeNr))
|
// Join and call until the state converges.
|
||||||
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)));
|
|
||||||
|
|
||||||
// Continue Joining until State converges
|
Nodes[NodeNr].Computed++;
|
||||||
if (!(Before == Nodes[SuccNr])) {
|
|
||||||
fillAbstractCache(NodeNr);
|
// 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 {
|
} else {
|
||||||
// Update and fill Succ
|
// Fill Successor with current State and its Address
|
||||||
Nodes[SuccNr].fill(Nodes[NodeNr], NodeNr);
|
Nodes[SuccNr].fill(Nodes[NodeNr], Address(Nodes[NodeNr].Addr));
|
||||||
fillAbstractCache(SuccNr);
|
// 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;
|
return;
|
||||||
|
@ -368,7 +374,7 @@ public: // everything is public, because IDGAF
|
||||||
auto Predecessor = Nodes[E.first];
|
auto Predecessor = Nodes[E.first];
|
||||||
for (unsigned int SuccessorAddr : E.second) {
|
for (unsigned int SuccessorAddr : E.second) {
|
||||||
// When successors Address is in predecessor, we have a Hit.
|
// 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;
|
return Hits;
|
||||||
|
@ -385,7 +391,7 @@ public: // everything is public, because IDGAF
|
||||||
auto Predecessor = Nodes[E.first];
|
auto Predecessor = Nodes[E.first];
|
||||||
for (unsigned int SuccessorAddr : E.second) {
|
for (unsigned int SuccessorAddr : E.second) {
|
||||||
// When successors Address is in predecessor, we have a Hit.
|
// 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;
|
return Misses;
|
||||||
|
|
|
@ -30,7 +30,8 @@ public: // everything is public, because IDGAF
|
||||||
unsigned int Addr;
|
unsigned int Addr;
|
||||||
unsigned int Unrolled;
|
unsigned int Unrolled;
|
||||||
|
|
||||||
bool Computed = false;
|
int Computed = 0;
|
||||||
|
bool Filled = false;
|
||||||
|
|
||||||
// Only entries below this comment are needed for the exercise.
|
// Only entries below this comment are needed for the exercise.
|
||||||
|
|
||||||
|
@ -164,6 +165,11 @@ public: // everything is public, because IDGAF
|
||||||
* @param Addr , Address
|
* @param Addr , Address
|
||||||
*/
|
*/
|
||||||
void update(Address Addr) {
|
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
|
// This loopages all entries by one. 3 <-2, 2<-1, 1<-0
|
||||||
for (int I = 3; I > 0; I--) {
|
for (int I = 3; I > 0; I--) {
|
||||||
Sets[Addr.Index].Associativity[I] = Sets[Addr.Index].Associativity[I - 1];
|
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};
|
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.
|
* @brief Fills the AbstractState PreState and updates with PreAddress.
|
||||||
*
|
*
|
||||||
|
@ -202,6 +187,7 @@ public: // everything is public, because IDGAF
|
||||||
* @param PreAddr Address of PreState
|
* @param PreAddr Address of PreState
|
||||||
*/
|
*/
|
||||||
void fill(AbstractState PreState, Address PreAddr) {
|
void fill(AbstractState PreState, Address PreAddr) {
|
||||||
|
bool Verbose = false;
|
||||||
// copy Pre State into this.
|
// copy Pre State into this.
|
||||||
for (auto S : PreState.Sets) {
|
for (auto S : PreState.Sets) {
|
||||||
unsigned int Index = S.first;
|
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
|
// update this with PreAddr
|
||||||
this->update(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() {
|
void dump() {
|
||||||
llvm::outs() << Addr << " {\n";
|
llvm::outs() << Addr << " {\n";
|
||||||
llvm::outs() << "Unrolled: " << Unrolled << "\n";
|
llvm::outs() << "Unrolled: " << Unrolled << "\n";
|
||||||
|
llvm::outs() << "Computed: " << Computed << "\n";
|
||||||
llvm::outs() << "Predecessors: ";
|
llvm::outs() << "Predecessors: ";
|
||||||
for (auto PreNr : Predecessors) {
|
for (auto PreNr : Predecessors) {
|
||||||
llvm::outs() << PreNr << " ";
|
llvm::outs() << PreNr << " ";
|
||||||
|
|
|
@ -145,29 +145,29 @@ case $1 in
|
||||||
docker run -i -d -v "$(pwd)"/.:/root:rw --name RTSAlab01 rtsalab01cacheanalysis
|
docker run -i -d -v "$(pwd)"/.:/root:rw --name RTSAlab01 rtsalab01cacheanalysis
|
||||||
;;
|
;;
|
||||||
evaluation | eval)
|
evaluation | eval)
|
||||||
run "fft1"
|
run "crc"
|
||||||
echo "==== Correct fft1 ===="
|
echo "==== Correct crc ===="
|
||||||
echo "MustHits: 21"
|
echo "MustHits: 90"
|
||||||
echo
|
echo
|
||||||
run "cnt"
|
run "cnt"
|
||||||
echo "==== Correct cnt ===="
|
echo "==== Correct cnt ===="
|
||||||
echo "MustHits: 4"
|
echo "MustHits: 28"
|
||||||
echo
|
echo
|
||||||
run "duff"
|
run "duff"
|
||||||
echo "==== Correct duff ===="
|
echo "==== Correct duff ===="
|
||||||
echo "MustHits: 3"
|
echo "MustHits: 78"
|
||||||
|
echo
|
||||||
|
run "fft1"
|
||||||
|
echo "==== Correct fft1 ===="
|
||||||
|
echo "MustHits: 74"
|
||||||
echo
|
echo
|
||||||
run "insertsort"
|
run "insertsort"
|
||||||
echo "==== Correct insertsort ===="
|
echo "==== Correct insertsort ===="
|
||||||
echo "MustHits: 2"
|
echo "MustHits: 61"
|
||||||
echo
|
echo
|
||||||
run "matmult"
|
run "matmult"
|
||||||
echo "==== Correct matmult ===="
|
echo "==== Correct matmult ===="
|
||||||
echo "MustHits: 9"
|
echo "MustHits: 34"
|
||||||
echo
|
|
||||||
run "crc"
|
|
||||||
echo "==== Correct crc ===="
|
|
||||||
echo "MustHits: 6"
|
|
||||||
echo
|
echo
|
||||||
;;
|
;;
|
||||||
a | all)
|
a | all)
|
||||||
|
|
Reference in New Issue