moved LoopGraph to json
This commit is contained in:
@@ -76,7 +76,8 @@ set(UTILS src/Utils/AstWrapper.h
|
||||
src/Utils/utils.h
|
||||
src/Utils/version.h
|
||||
src/Utils/module_utils.h
|
||||
src/Utils/module_utils.cpp)
|
||||
src/Utils/module_utils.cpp
|
||||
src/Utils/json.hpp)
|
||||
|
||||
set(OMEGA src/SageAnalysisTool/OmegaForSage/add-assert.cpp
|
||||
src/SageAnalysisTool/OmegaForSage/affine.cpp
|
||||
|
||||
@@ -26,11 +26,11 @@
|
||||
|
||||
#include "../Utils/errors.h"
|
||||
#include "../Utils/AstWrapper.h"
|
||||
#include "../Utils/json.hpp"
|
||||
|
||||
#include "../DirectiveProcessing/directive_parser.h"
|
||||
#include "../DynamicAnalysis/gCov_parser_func.h"
|
||||
|
||||
#include "../GraphCall/graph_calls_func.h"
|
||||
#include "../Transformations/array_assign_to_loop.h"
|
||||
|
||||
using std::vector;
|
||||
@@ -40,6 +40,8 @@ using std::string;
|
||||
using std::wstring;
|
||||
using std::pair;
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
#define DEBUG 0
|
||||
static inline void insertLabels(SgExpression *lb, map<int, vector<int>> &gotoLabels, const int line)
|
||||
{
|
||||
@@ -918,7 +920,7 @@ void* LoopGraph::getRealStat(const char* file) const
|
||||
}
|
||||
|
||||
extern int PASSES_DONE[EMPTY_PASS];
|
||||
static void printToBuffer(const LoopGraph *currLoop, const int childSize, char buf[512])
|
||||
static int getLoopState(const LoopGraph* currLoop)
|
||||
{
|
||||
int loopState = 0; // 0 - unknown, 1 - good, 2 - bad
|
||||
if (PASSES_DONE[CREATE_TEMPLATE_LINKS] ||
|
||||
@@ -934,8 +936,14 @@ static void printToBuffer(const LoopGraph *currLoop, const int childSize, char b
|
||||
if (currLoop->hasLimitsToParallel())
|
||||
loopState = 2;
|
||||
}
|
||||
|
||||
return loopState;
|
||||
}
|
||||
|
||||
static void printToBuffer(const LoopGraph *currLoop, const int childSize, char buf[512])
|
||||
{
|
||||
sprintf(buf, "#%d#%d#%d#%d#%d#%d#%d#%d",
|
||||
currLoop->lineNum, currLoop->lineNumAfterLoop, currLoop->perfectLoop, currLoop->hasGoto, currLoop->hasPrints, childSize, loopState,
|
||||
currLoop->lineNum, currLoop->lineNumAfterLoop, currLoop->perfectLoop, currLoop->hasGoto, currLoop->hasPrints, childSize, getLoopState(currLoop),
|
||||
currLoop->hasNonRectangularBounds);
|
||||
}
|
||||
|
||||
@@ -979,6 +987,92 @@ void convertToString(const LoopGraph *currLoop, string &result)
|
||||
}
|
||||
}
|
||||
|
||||
json convertToJson(const LoopGraph* currLoop)
|
||||
{
|
||||
json loop;
|
||||
const auto& file = currLoop->fileName;
|
||||
if (currLoop && currLoop->lineNum > 0)
|
||||
{
|
||||
loop["file"] = file;
|
||||
loop["line"] = currLoop->lineNum;
|
||||
loop["lineNumAfterLoop"] = currLoop->lineNumAfterLoop;
|
||||
loop["perfectLoop"] = currLoop->perfectLoop;
|
||||
loop["loopState"] = getLoopState(currLoop);
|
||||
loop["hasNonRectangularBounds"] = (int)currLoop->hasNonRectangularBounds;
|
||||
|
||||
json calls = json::array();
|
||||
for (auto& [func, line] : currLoop->calls)
|
||||
{
|
||||
json call;
|
||||
call["line"] = line;
|
||||
call["funcName"] = func;
|
||||
call["canBeInlined"] = 0;
|
||||
call["parentLineOffset"] = 0;
|
||||
|
||||
calls.push_back(call);
|
||||
}
|
||||
loop["funcCalls"] = calls;
|
||||
|
||||
json e_gotos = json::array();
|
||||
for (auto& line : currLoop->linesOfExternalGoTo)
|
||||
e_gotos.push_back(line);
|
||||
loop["extGotos"] = e_gotos;
|
||||
|
||||
json i_gotos = json::array();
|
||||
for (auto& line : currLoop->linesOfInternalGoTo)
|
||||
i_gotos.push_back(line);
|
||||
loop["intGotos"] = i_gotos;
|
||||
|
||||
json ios = json::array();
|
||||
for (auto& line : currLoop->linesOfIO)
|
||||
ios.push_back(line);
|
||||
loop["ios"] = ios;
|
||||
|
||||
json stops = json::array();
|
||||
for (auto& line : currLoop->linesOfStop)
|
||||
stops.push_back(line);
|
||||
loop["stops"] = stops;
|
||||
|
||||
json children = json::array();
|
||||
for (const auto& ch : currLoop->children)
|
||||
{
|
||||
auto conv = convertToJson(ch);
|
||||
if (!conv.empty())
|
||||
children.push_back(conv);
|
||||
}
|
||||
loop["children"] = children;
|
||||
}
|
||||
return loop;
|
||||
}
|
||||
|
||||
json convertToJson(const map<string, vector<LoopGraph*>>& loopsByFileMap)
|
||||
{
|
||||
json loopsByFile = json::array();
|
||||
|
||||
for (auto& byFile : loopsByFileMap)
|
||||
{
|
||||
json loop;
|
||||
const string& file = byFile.first;
|
||||
|
||||
json loops_array = json::array();
|
||||
for (auto& loop : byFile.second)
|
||||
{
|
||||
auto conv = convertToJson(loop);
|
||||
if (!conv.empty())
|
||||
loops_array.push_back(conv);
|
||||
}
|
||||
|
||||
loop["file"] = file;
|
||||
loop["loops"] = loops_array;
|
||||
|
||||
loopsByFile.push_back(loop);
|
||||
}
|
||||
|
||||
json allLoops;
|
||||
allLoops["allLoops"] = loopsByFile;
|
||||
return allLoops;
|
||||
}
|
||||
|
||||
void createMapLoopGraph(const vector<LoopGraph*> &loops, map<int, LoopGraph*> &mapGraph)
|
||||
{
|
||||
for (auto &elem : loops)
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "graph_loops.h"
|
||||
#include "../Distribution/DvmhDirective.h"
|
||||
#include "Utils/json.hpp"
|
||||
|
||||
struct SpfInterval;
|
||||
|
||||
@@ -18,3 +20,5 @@ bool recSymbolFind(SgExpression *ex, const std::string &symb, const int var);
|
||||
void completeFillOfArrayUsageBetweenProc(const std::map<std::string, std::vector<LoopGraph*>>& loopGraph, const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo);
|
||||
bool detectMpiCalls(SgProject* proj, std::map<std::string, std::vector<Messages>>& SPF_messages);
|
||||
int calculateLoopIters(SgExpression* start, SgExpression* end, SgExpression* step, std::tuple<int, int, int>& result);
|
||||
|
||||
nlohmann::json convertToJson(const std::map<std::string, std::vector<LoopGraph*>>& loopsByFile);
|
||||
@@ -1561,6 +1561,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
||||
{
|
||||
if (keepFiles)
|
||||
printLoopGraph("_loopGraph.txt", loopGraph);
|
||||
//printf("%s\n", convertToJson(loopGraph).dump(2).c_str());
|
||||
}
|
||||
else if (curr_regime == FILL_COMMON_BLOCKS)
|
||||
{
|
||||
|
||||
22828
src/Utils/json.hpp
Normal file
22828
src/Utils/json.hpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#define VERSION_SPF "2401"
|
||||
#define VERSION_SPF "2402"
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include "../LoopAnalyzer/loop_analyzer.h"
|
||||
#include "../DirectiveProcessing/insert_directive.h"
|
||||
#include "../ProjectManipulation/PerfAnalyzer.h"
|
||||
#include "Utils/json.hpp"
|
||||
|
||||
#include "BuildGraph.h"
|
||||
|
||||
@@ -61,6 +62,7 @@ using std::pair;
|
||||
using std::tuple;
|
||||
using std::to_string;
|
||||
using std::make_pair;
|
||||
using json = nlohmann::json;
|
||||
|
||||
extern set<short*> allocated;
|
||||
extern set<int*> allocatedInt;
|
||||
@@ -510,26 +512,7 @@ int SPF_GetGraphLoops(void*& context, int winHandler, short *options, short *pro
|
||||
{
|
||||
runPassesForVisualizer(projName, { LOOP_GRAPH } );
|
||||
|
||||
string resVal = "";
|
||||
for (auto f = loopGraph.begin(); f != loopGraph.end(); ++f)
|
||||
{
|
||||
if (resVal != "")
|
||||
resVal += "|";
|
||||
|
||||
int realLoops = 0;
|
||||
for (int i = 0; i < f->second.size(); ++i)
|
||||
if (f->second[i]->lineNum > 0)
|
||||
realLoops++;
|
||||
|
||||
resVal += f->first + "|" + to_string(realLoops);
|
||||
for (int i = 0; i < f->second.size(); ++i)
|
||||
{
|
||||
string localRes = "";
|
||||
convertToString(f->second[i], localRes);
|
||||
resVal += localRes;
|
||||
}
|
||||
}
|
||||
|
||||
string resVal = convertToJson(loopGraph).dump();
|
||||
copyStringToShort(result, resVal);
|
||||
retSize = (int)resVal.size() + 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user