WIP : check all implicit stmts

This commit is contained in:
2024-03-12 10:42:22 +03:00
parent 04f8f985c0
commit a5c31c60a7
5 changed files with 194 additions and 94 deletions

View File

@@ -207,7 +207,7 @@ set(TRANSFORMS
${TR_LOOP_UNROLL}
${TR_GV}
${TR_PRIV_DEL}
${TR_CONV})
${TR_CONV}
${TR_PRIV_DEL}
${TR_IMPLICIT_NONE})

View File

@@ -1162,6 +1162,8 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
getMaxMinBlockDistribution(file, min_max_block);
else if (curr_regime == CONVERT_TO_C)
covertToC(file);
else if (curr_regime == SET_IMPLICIT_NONE)
ImplicitCheck(file);
else if (curr_regime == TEST_PASS)
{
//test pass
@@ -2057,8 +2059,6 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
runPrivateVariableAnalysis(loopGraph, fullIR, commonBlocks, SPF_messages);
else if (curr_regime == FIX_COMMON_BLOCKS)
fixCommonBlocks(allFuncInfo, commonBlocks, &project);
else if (curr_regime == SET_IMPLICIT_NONE)
ImplicitCheck(&project);
else if (curr_regime == SELECT_ARRAY_DIM_CONF) {
SelectArrayConfForParallelization(&project, allFuncInfo, loopGraph, createdDirectives, SPF_messages, arrayLinksByFuncCalls, parallelRegions);
removeRegionsWithoutDirs(createdDirectives, parallelRegions, allFuncInfo, SPF_messages);
@@ -2522,7 +2522,7 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam
case LOOPS_SPLITTER:
case LOOPS_COMBINER:
case FIX_COMMON_BLOCKS:
case SET_IMPLICIT_NONE:
//case SET_IMPLICIT_NONE:
case TEST_PASS:
runAnalysis(*project, curr_regime, false);
case SUBST_EXPR_RD_AND_UNPARSE:
@@ -2624,7 +2624,10 @@ int main(int argc, char **argv)
else if (string(curr_arg) == "-passN")
{
i++;
// test
curr_regime = getPassCode(argv[i]);
curr_regime = 130;
printf("code for pass %s is %d\n", argv[i], curr_regime);
}
else if (string(curr_arg) == "-passInfo")

View File

@@ -5,6 +5,7 @@
#include "Utils/SgUtils.h"
#include "set_implicit_none.h"
#include <LoopAnalyzer/loop_analyzer.h>
using std::vector;
using std::map;
@@ -14,9 +15,190 @@ using std::make_pair;
using std::string;
using std::to_string;
static map<char, SgType*> implicit;
static set<SgSymbol*> vars;
static vector<SgSymbol*> toDecl;
map<char, SgType*> types;
vector<SgSymbol*> varsWithoutDecl;
const char commonIntLetters[6] = {'i', 'j', 'k', 'm', 'n', 'l'};
void InitTypes();
void FillCommonTypes();
void GetImplicitTypes(SgExpression* expr);
static inline string getContains(SgStatement* funcSt)
{
string containsName;
SgStatement* st_cp = funcSt->controlParent();
if (st_cp->variant() == PROC_HEDR || st_cp->variant() == PROG_HEDR || st_cp->variant() == FUNC_HEDR)
containsName = st_cp->symbol()->identifier() + std::string(".");
return containsName;
}
void ImplicitCheck(SgFile* file) {
auto implicitNoneDeclaration = new SgStatement(IMPL_DECL);
auto hasImplicitNone = false;
for (SgStatement* i = file->firstStatement(); i = i->lexNext(); i != NULL) {
if (i->variant() == IMPL_DECL) {
SgImplicitStmt* implicitSt = isSgImplicitStmt(i);
if (implicitSt) {
int numberOfTypes = implicitSt->numberOfImplicitTypes();
if (numberOfTypes > 0) {
for (int j = 0; j < numberOfTypes; j++) {
SgType* type = implicitSt->implicitType(j);
SgExpression* letters = implicitSt->implicitRangeList(j);
types['a'] = type;
printf("%s\n", letters->unparse());
}
}
else {
hasImplicitNone = true;
}
}
}
else {
printf("%s\nvariant - %d\n\n", i->unparse(), i->variant());
}
}
if (!hasImplicitNone) {
auto firstRealStatementOfFile = file->firstStatement()->lexNext()->lexNext();
firstRealStatementOfFile->insertStmtBefore(*implicitNoneDeclaration, *(firstRealStatementOfFile->controlParent()));
}
printf("%s", file->firstStatement()->lexNext()->unparse());
return;
}
void InitTypes() {
for (char i = 'a'; i <= 'z'; i++) {
types[i] = NULL;
}
}
void FillCommonTypes() {
for (char i: commonIntLetters) {
if (types[i] == NULL) {
types[i] = new SgType(T_INT);
}
}
for (auto i : types) {
if (i.second == NULL) {
types[i.first] = new SgType(T_FLOAT);
}
}
}
void GetImplicitTypes(SgExpression* expr) {
if (expr == NULL) {
return;
}
if (expr->variant() == IMPL_TYPE) {
auto letters = expr->operand(1);
auto type = expr->type();
printf("letters - %s\n", letters->unparse());
}
if (expr->lhs() != NULL) {
GetImplicitTypes(expr->lhs());
}
if (expr->rhs() != NULL) {
GetImplicitTypes(expr->rhs());
}
}
/*
*
*
auto x = implicitSt->numberOfImplicitTypes();
printf("IMPLICIT\n%s", implicitSt->unparse());
printf("number - %d\n", x);
for (int j = 0; j < x; j++) {
printf("%d - %s\n", j, implicitSt->implicitRangeList(j)->unparse());
}
printf("\n");
*
int coutOfFunctions;
for (int j = 0; j < file->numberOfFunctions(); j++) {
SgStatement* function = file->functions(j);
implicit.clear();
vars.clear();
toDecl.clear();
//fill implicit
for (int k = 0; k < function->numberOfChildrenList1(); k++) {
SgStatement* state = function->childList1(k);
if (state->variant() == IMPL_DECL) {
if (state->expr(0) == NULL) {
}
else {
SgExpression* expression = state->expr(0);
int n = 0;
SgExpression* one = expression;
while (one != NULL && one->lhs() != NULL) {
string what_type = one->lhs()->sunparse();
if (what_type.find("kind=") != std::string::npos) {
SgType* baseType = new SgType(one->lhs()->type()->variant());
SgType* type = new SgType(T_ARRAY, NULL, baseType);
SgExpression* letters = one->lhs()->operand(1);
InsertToMap(type, letters);
}
else {
SgType* type = new SgType(one->lhs()->type()->variant());
SgExpression* letters = one->lhs()->operand(1);
InsertToMap(type, letters);
}
one = one->rhs();
}
}
break;
}
if (state->variant() == CONTROL_END) {
SgStatement* state = new SgStatement(IMPL_DECL);
auto cp = function->childList1(0)->controlParent();
function->childList1(0)->insertStmtBefore(*state, *cp);
InsertDefaultToMap();
break;
}
}
CheckVariables(function);
}
static void InsertToMap(SgType* type, SgExpression* letters) {
@@ -101,87 +283,4 @@ static void CheckVariables(SgStatement* function) {
makeDeclaration(toDecl, function, NULL);
}
void ImplicitCheck(SgProject* project) {
/*
printf("IMPLICIT\n");
*/
for (int i = 0; i < project->numberOfFiles(); i++) {
SgFile file = project->file(i);
int coutOfFunctions;
for (int j = 0; j < file.numberOfFunctions(); j++) {
SgStatement* function = file.functions(j);
implicit.clear();
vars.clear();
toDecl.clear();
//fill implicit
for (int k = 0; k < function->numberOfChildrenList1(); k++) {
SgStatement* state = function->childList1(k);
if (state->variant() == IMPL_DECL) {
if (state->expr(0) == NULL) {
}
else {
SgExpression* expression = state->expr(0);
int n = 0;
SgExpression* one = expression;
while (one != NULL && one->lhs() != NULL) {
string what_type = one->lhs()->sunparse();
if (what_type.find("kind=") != std::string::npos) {
SgType* baseType = new SgType(one->lhs()->type()->variant());
SgType* type = new SgType(T_ARRAY, NULL, baseType);
SgExpression* letters = one->lhs()->operand(1);
InsertToMap(type, letters);
}
else {
SgType* type = new SgType(one->lhs()->type()->variant());
SgExpression* letters = one->lhs()->operand(1);
InsertToMap(type, letters);
}
one = one->rhs();
}
}
break;
}
if (state->variant() == CONTROL_END) {
SgStatement* state = new SgStatement(IMPL_DECL);
auto cp = function->childList1(0)->controlParent();
function->childList1(0)->insertStmtBefore(*state, *cp);
InsertDefaultToMap();
break;
}
}
CheckVariables(function);
}
}
}

View File

@@ -1,7 +1,7 @@
#pragma once
#include "Utils/SgUtils.h"
#include "string"
#include "map"
#include <string>
#include <map>
void ImplicitCheck(SgProject* project);
void ImplicitCheck(SgFile* file);

View File

@@ -306,8 +306,6 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
Pass(REMOVE_OMP_DIRS) <= Pass(REMOVE_OMP_DIRS_TRANSFORM);
Pass(CALL_GRAPH2) <= Pass(SET_IMPLICIT_NONE);
passesIgnoreStateDone.insert({ CREATE_PARALLEL_DIRS, INSERT_PARALLEL_DIRS, INSERT_SHADOW_DIRS, EXTRACT_PARALLEL_DIRS,
EXTRACT_SHADOW_DIRS, CREATE_REMOTES, UNPARSE_FILE, REMOVE_AND_CALC_SHADOW,
REVERSE_CREATED_NESTED_LOOPS, PREDICT_SCHEME, CALCULATE_STATS_SCHEME, REVERT_SPF_DIRS, CLEAR_SPF_DIRS, TRANSFORM_SHADOW_IF_FULL,