fixed dead code
This commit is contained in:
@@ -139,6 +139,36 @@ void CStat::init(const char* path) {
|
||||
strcpy(spath, path);
|
||||
}
|
||||
|
||||
void CStat::init(CStatRead* stat_) {
|
||||
isjson = false;
|
||||
if (isinitialized) {
|
||||
err = true;
|
||||
return;
|
||||
}
|
||||
stat = stat_;
|
||||
int warn;
|
||||
if (stat->Valid(&warn) != TRUE) {
|
||||
err = true;
|
||||
return;
|
||||
}
|
||||
nproc = stat->QProc();
|
||||
if (nproc == 0) {
|
||||
err = true;
|
||||
return;
|
||||
}
|
||||
stat->VMSSize(p_heading);
|
||||
unsigned long n = stat->BeginTreeWalk();
|
||||
if (n != 0) inter_tree = new CStatInter(stat, n);
|
||||
proc_info = new struct CProcInfo[nproc];
|
||||
for (unsigned long i = 0; i < nproc; i++)
|
||||
stat->NameTimeProc(i, &proc_info[i].node_name, &proc_info[i].test_time);
|
||||
isinitialized = true;
|
||||
|
||||
//TODO: ?
|
||||
/*spath = new char[strlen(path) + 1];
|
||||
strcpy(spath, path);*/
|
||||
}
|
||||
|
||||
CStatInter * find_inter(short type, long expr, short nlev, CStatInter * cur) {
|
||||
while (cur != NULL) {
|
||||
if (cur->id.t == type && cur->id.nlev == nlev)
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#endif
|
||||
|
||||
#include "statprintf.h"
|
||||
#include "statlist.h"
|
||||
|
||||
using namespace std;
|
||||
/**
|
||||
@@ -83,6 +84,7 @@ static void printHelp()
|
||||
printf(" StartShdGrp|WaitShdGrp|ShdGrp|DistrGrp|ReDistrGrp|\n");
|
||||
printf(" MapPLGrp|DoPLGrp|ProgBlockGrp|IOGrp|RemAccessGrp|\n");
|
||||
printf(" UserDebGrp|StatistGrp|SystemGrp.\n");
|
||||
printf(" -j Dump to json format\n");
|
||||
}
|
||||
|
||||
#ifdef __SPF_BUILT_IN_PPPA
|
||||
@@ -112,7 +114,7 @@ int main(int argv, char **argc)
|
||||
#endif
|
||||
}
|
||||
|
||||
BOOL proc = TRUE, comp = TRUE, gen = TRUE;
|
||||
BOOL proc = TRUE, comp = TRUE, gen = TRUE, jsonDump = FALSE;
|
||||
BOOL dvmh_gpu = TRUE, dvmh_threads = FALSE, dvmh_threads_full = FALSE;
|
||||
int verbosity = VERBOSITY_LVL_CPU | VERBOSITY_LVL_GPU;
|
||||
char compr[3], mode[5];
|
||||
@@ -139,7 +141,7 @@ int main(int argv, char **argc)
|
||||
exit(1);
|
||||
#endif
|
||||
}
|
||||
if (argv == npar + 1) {
|
||||
if (argv == npar + 1 && argc[npar][1] != 'j') {
|
||||
printf("Parameter for %s not set\n", argc[npar]);
|
||||
#ifdef __SPF_BUILT_IN_PPPA
|
||||
return 1;
|
||||
@@ -335,7 +337,9 @@ int main(int argv, char **argc)
|
||||
else ++buf;
|
||||
} while (cond);
|
||||
}
|
||||
|
||||
break;
|
||||
case 'j':
|
||||
jsonDump = TRUE;
|
||||
break;
|
||||
default:
|
||||
printf("Incorrect parameter %s\n", argc[npar]);
|
||||
@@ -363,6 +367,27 @@ int main(int argv, char **argc)
|
||||
#endif
|
||||
}
|
||||
|
||||
if (jsonDump == TRUE)
|
||||
{
|
||||
CStat stat_json;
|
||||
stat_json.init(&stat);
|
||||
if (!stat_json.isinitialized)
|
||||
return 1;
|
||||
|
||||
json j;
|
||||
stat_json.to_json(j);
|
||||
std::string str = j.dump();
|
||||
|
||||
FILE* f = fopen(argc[nparout], "w");
|
||||
if (f == NULL)
|
||||
{
|
||||
printf("Can't open file %s\n", argc[nparout]);
|
||||
return 1;
|
||||
}
|
||||
fprintf(f, "%s\n", str.c_str());
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
// Возвращает количество процессоров, на которых считалась задача.
|
||||
unsigned long qproc = stat.QProc();
|
||||
|
||||
|
||||
@@ -86,6 +86,7 @@ public:
|
||||
CStat();
|
||||
CStat(json source);
|
||||
void init(const char* path);
|
||||
void init(CStatRead* stat);
|
||||
void clear();
|
||||
~CStat() ;
|
||||
CStatInter * inter_tree; //"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
@@ -351,6 +351,28 @@ public:
|
||||
{ }
|
||||
};
|
||||
|
||||
static bool hasCalls(SgExpression* ex)
|
||||
{
|
||||
if (ex)
|
||||
{
|
||||
if (ex->variant() == FUNC_CALL)
|
||||
return true;
|
||||
return hasCalls(ex->lhs()) || hasCalls(ex->rhs());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//TODO: add check for side effects for function calls
|
||||
static bool hasCalls(SgStatement* stat)
|
||||
{
|
||||
if (stat->variant() == FOR_NODE)
|
||||
{
|
||||
auto forSt = isSgForStmt(stat);
|
||||
return hasCalls(forSt->start()) || hasCalls(forSt->end()) || hasCalls(forSt->step());
|
||||
}
|
||||
else
|
||||
return hasCalls(stat->expr(0)) || hasCalls(stat->expr(1)) || hasCalls(stat->expr(2));
|
||||
}
|
||||
|
||||
int removeDeadCode(SgStatement* func,
|
||||
const map<string, vector<FuncInfo*>>& allFuncs,
|
||||
@@ -493,6 +515,19 @@ int removeDeadCode(SgStatement* func,
|
||||
for (auto& rem : remove)
|
||||
{
|
||||
__spf_print(PRINT_USELESS_STATEMENTS, "[Useless statement on line %d and file %s]\n", rem->lineNumber(), rem->fileName());
|
||||
|
||||
auto cp = rem->controlParent();
|
||||
if (cp->variant() == LOGIF_NODE)
|
||||
{
|
||||
if (hasCalls(cp))
|
||||
{
|
||||
((SgLogIfStmt*)cp)->convertLogicIf();
|
||||
rem->deleteStmt();
|
||||
}
|
||||
else
|
||||
cp->deleteStmt();
|
||||
}
|
||||
else
|
||||
rem->deleteStmt();
|
||||
}
|
||||
countOfTransform += remove.size();
|
||||
@@ -507,13 +542,20 @@ int removeDeadCode(SgStatement* func,
|
||||
if ((var == FOR_NODE || var == WHILE_NODE || var == SWITCH_NODE) &&
|
||||
st->lexNext()->variant() == CONTROL_END)
|
||||
{
|
||||
if (!hasCalls(st))
|
||||
remove.push_back(st);
|
||||
}
|
||||
else if (var == IF_NODE)
|
||||
{
|
||||
if (!hasCalls(st))
|
||||
{
|
||||
bool hasCalls_ = false;
|
||||
SgStatement* ifS = st;
|
||||
while (ifS->lexNext()->variant() == ELSEIF_NODE)
|
||||
{
|
||||
hasCalls_ |= hasCalls(ifS->lexNext());
|
||||
ifS = ifS->lexNext();
|
||||
}
|
||||
|
||||
SgStatement* lastNode = ifS->lastNodeOfStmt();
|
||||
ifS = ifS->lexNext();
|
||||
@@ -521,11 +563,12 @@ int removeDeadCode(SgStatement* func,
|
||||
while (ifS->variant() == CONTROL_END && ifS != lastNode)
|
||||
ifS = ifS->lexNext();
|
||||
|
||||
if (ifS == lastNode)
|
||||
if (ifS == lastNode && !hasCalls_)
|
||||
remove.push_back(st);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: SWITCH and other block statements
|
||||
//TODO: other block statements
|
||||
|
||||
if (var == CONTAINS_STMT)
|
||||
break;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#define VERSION_SPF "2318"
|
||||
#define VERSION_SPF "2319"
|
||||
|
||||
Reference in New Issue
Block a user