Skip to content

Commit

Permalink
fix(rtlib): persistend BB Id counter, minor type fixes, minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasrothenberger committed Nov 22, 2023
1 parent 37f8ea5 commit a810224
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
25 changes: 24 additions & 1 deletion DiscoPoP/DiscoPoP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ bool DiscoPoP::doInitialization(Module &M) {

// DPInstrumentationOmission
{
int bbDepCount = 0;
bbDepCount = 0;

initializeBBDepCounter();

errs() << "Initial dep count: " << to_string(bbDepCount) << "\n";

ReportBB = M.getOrInsertFunction(
"__dp_report_bb",
Expand Down Expand Up @@ -233,6 +237,15 @@ bool DiscoPoP::doFinalization(Module &M) {
}
}
}
// write the current count of BBs to a file to avoid duplicate BBids
outBBDepCounter = new std::ofstream();
outBBDepCounter->open(".discopop/profiler/DP_BBDepCounter.txt", std::ios_base::out);
if (outBBDepCounter && outBBDepCounter->is_open()) {
*outBBDepCounter << bbDepCount;
outBBDepCounter->flush();
outBBDepCounter->close();
}

// DPInstrumentationOmission end

return true;
Expand Down Expand Up @@ -893,6 +906,15 @@ void DiscoPoP::initializeCUIDCounter() {
}
}

void DiscoPoP::initializeBBDepCounter(){
std::string BBDepCounterFile = ".discopop/profiler/DP_BBDepCounter.txt";
if (dputil::fexists(BBDepCounterFile)) {
std::fstream inBBDepCounter(BBDepCounterFile, std::ios_base::in);;
inBBDepCounter >> bbDepCount;
inBBDepCounter.close();
}
}

bool DiscoPoP::isRecursive(Function &F, CallGraph &CG) {
auto callNode = CG[&F];
for (unsigned i = 0; i < callNode->size(); i++) {
Expand Down Expand Up @@ -2311,6 +2333,7 @@ bool DiscoPoP::runOnFunction(Function &F) {
if (isa<ReturnInst>(pair.first->getTerminator())) {
insertionPoint = insertionPoint->getPrevNonDebugInstruction();
}
errs() << "bbDepCount: " << bbDepCount << "\n";
auto CI = CallInst::Create(
ReportBB,
ConstantInt::get(Int32, bbDepCount),
Expand Down
4 changes: 3 additions & 1 deletion DiscoPoP/DiscoPoP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ namespace {
// CUGeneration

static unsigned int CUIDCounter;
static unsigned int bbDepCount;
static bool defaultIsGlobalVariableValue;
int32_t fileID;

Expand Down Expand Up @@ -217,6 +218,7 @@ namespace {
ofstream *outCUs;
ofstream *outOriginalVariables;
ofstream *outCUIDCounter;
ofstream *outBBDepCounter;
// Mohammad 23.12.2020
map <string, string> loopStartLines;

Expand Down Expand Up @@ -319,7 +321,6 @@ namespace {
// DPInstrumentation end

// DPInstrumentationOmission
int bbDepCount;
string bbDepString;
string fileName;
int32_t fid;
Expand Down Expand Up @@ -385,6 +386,7 @@ namespace {

// Output function
void initializeCUIDCounter();
void initializeBBDepCounter();

string xmlEscape(string data);

Expand Down
14 changes: 2 additions & 12 deletions rtlib/iFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ namespace __dp {
/******* Helper functions *******/

void addDep(depType type, LID curr, LID depOn, char *var, string AAvar) {
#ifdef DP_RTLIB_VERBOSE
cout << "enter addDep\n";
#endif
// hybrid analysis
if (depOn == 0 && type == WAW)
type = INIT;
Expand Down Expand Up @@ -210,9 +207,6 @@ namespace __dp {
}
cout << ", " << decodeLID(depOn) << "] into deps (" << myMap->size() << ")" << endl;
}
#ifdef DP_RTLIB_VERBOSE
cout << "exit addDep\n";
#endif
}

// hybrid analysis
Expand Down Expand Up @@ -1061,25 +1055,21 @@ namespace __dp {
return;
}

void __dp_report_bb(int32_t bbIndex) {
void __dp_report_bb(uint32_t bbIndex) {
#ifdef DP_PTHREAD_COMPATIBILITY_MODE
std::lock_guard<std::mutex> guard(pthread_compatibility_mutex);
#endif
#ifdef DP_RTLIB_VERBOSE
cout << "enter __dp_report_bb\n";
cout << "bbIndex: " << std::to_string(bbIndex) << "\n";
cout << "bbList: " << bbList << "\n";
for(auto elem: *bbList){
cout << "\t" << elem << "\n";
}
#endif
bbList->insert(bbIndex);
#ifdef DP_RTLIB_VERBOSE
cout << "exit __dp_report_bb\n";
#endif
}

void __dp_report_bb_pair(int32_t semaphore, int32_t bbIndex) {
void __dp_report_bb_pair(int32_t semaphore, uint32_t bbIndex) {
#ifdef DP_PTHREAD_COMPATIBILITY_MODE
std::lock_guard<std::mutex> guard(pthread_compatibility_mutex);
#endif
Expand Down
8 changes: 4 additions & 4 deletions rtlib/iFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ namespace __dp {
BGNFuncList;

// Hybrid analysis
typedef std::set <int32_t> ReportedBBSet;
typedef std::set <uint32_t> ReportedBBSet;
typedef std::set <std::string> ReportedBBPairSet;
// End HA
// 2) when two END func are identical
Expand Down Expand Up @@ -214,8 +214,8 @@ namespace __dp {
// End HA
#endif
// hybrid analysis
void __dp_report_bb(int32_t bbIndex);
void __dp_report_bb_pair(int32_t counter, int32_t bbIndex);
void __dp_report_bb(uint32_t bbIndex);
void __dp_report_bb_pair(int32_t counter, uint32_t bbIndex);
void __dp_add_bb_deps(char *depStringPtr);
// End HA
void __dp_finalize(LID lid);
Expand All @@ -225,4 +225,4 @@ namespace __dp {
void __dp_loop_entry(LID lid, int32_t loopID);
void __dp_loop_exit(LID lid, int32_t loopID);
}
} // namespace __dp
} // namespace __dp

0 comments on commit a810224

Please sign in to comment.