WIP : check all implicit stmts
This commit is contained in:
@@ -194,7 +194,7 @@ set(TR_IMPLICIT_NONE _src/Transformations/set_implicit_none.cpp
|
|||||||
_src/Transformations/set_implicit_none.h)
|
_src/Transformations/set_implicit_none.h)
|
||||||
|
|
||||||
set(TRANSFORMS
|
set(TRANSFORMS
|
||||||
${TR_CP}
|
${TR_CP}
|
||||||
${TR_VECTOR}
|
${TR_VECTOR}
|
||||||
${TR_ENDDO_LOOP}
|
${TR_ENDDO_LOOP}
|
||||||
${TR_LOOP_NEST}
|
${TR_LOOP_NEST}
|
||||||
@@ -207,7 +207,7 @@ set(TRANSFORMS
|
|||||||
${TR_LOOP_UNROLL}
|
${TR_LOOP_UNROLL}
|
||||||
${TR_GV}
|
${TR_GV}
|
||||||
${TR_PRIV_DEL}
|
${TR_PRIV_DEL}
|
||||||
${TR_CONV})
|
${TR_CONV}
|
||||||
${TR_PRIV_DEL}
|
${TR_PRIV_DEL}
|
||||||
${TR_IMPLICIT_NONE})
|
${TR_IMPLICIT_NONE})
|
||||||
|
|
||||||
|
|||||||
@@ -1162,6 +1162,8 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
|||||||
getMaxMinBlockDistribution(file, min_max_block);
|
getMaxMinBlockDistribution(file, min_max_block);
|
||||||
else if (curr_regime == CONVERT_TO_C)
|
else if (curr_regime == CONVERT_TO_C)
|
||||||
covertToC(file);
|
covertToC(file);
|
||||||
|
else if (curr_regime == SET_IMPLICIT_NONE)
|
||||||
|
ImplicitCheck(file);
|
||||||
else if (curr_regime == TEST_PASS)
|
else if (curr_regime == TEST_PASS)
|
||||||
{
|
{
|
||||||
//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);
|
runPrivateVariableAnalysis(loopGraph, fullIR, commonBlocks, SPF_messages);
|
||||||
else if (curr_regime == FIX_COMMON_BLOCKS)
|
else if (curr_regime == FIX_COMMON_BLOCKS)
|
||||||
fixCommonBlocks(allFuncInfo, commonBlocks, &project);
|
fixCommonBlocks(allFuncInfo, commonBlocks, &project);
|
||||||
else if (curr_regime == SET_IMPLICIT_NONE)
|
|
||||||
ImplicitCheck(&project);
|
|
||||||
else if (curr_regime == SELECT_ARRAY_DIM_CONF) {
|
else if (curr_regime == SELECT_ARRAY_DIM_CONF) {
|
||||||
SelectArrayConfForParallelization(&project, allFuncInfo, loopGraph, createdDirectives, SPF_messages, arrayLinksByFuncCalls, parallelRegions);
|
SelectArrayConfForParallelization(&project, allFuncInfo, loopGraph, createdDirectives, SPF_messages, arrayLinksByFuncCalls, parallelRegions);
|
||||||
removeRegionsWithoutDirs(createdDirectives, parallelRegions, allFuncInfo, SPF_messages);
|
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_SPLITTER:
|
||||||
case LOOPS_COMBINER:
|
case LOOPS_COMBINER:
|
||||||
case FIX_COMMON_BLOCKS:
|
case FIX_COMMON_BLOCKS:
|
||||||
case SET_IMPLICIT_NONE:
|
//case SET_IMPLICIT_NONE:
|
||||||
case TEST_PASS:
|
case TEST_PASS:
|
||||||
runAnalysis(*project, curr_regime, false);
|
runAnalysis(*project, curr_regime, false);
|
||||||
case SUBST_EXPR_RD_AND_UNPARSE:
|
case SUBST_EXPR_RD_AND_UNPARSE:
|
||||||
@@ -2624,7 +2624,10 @@ int main(int argc, char **argv)
|
|||||||
else if (string(curr_arg) == "-passN")
|
else if (string(curr_arg) == "-passN")
|
||||||
{
|
{
|
||||||
i++;
|
i++;
|
||||||
|
// test
|
||||||
|
|
||||||
curr_regime = getPassCode(argv[i]);
|
curr_regime = getPassCode(argv[i]);
|
||||||
|
curr_regime = 130;
|
||||||
printf("code for pass %s is %d\n", argv[i], curr_regime);
|
printf("code for pass %s is %d\n", argv[i], curr_regime);
|
||||||
}
|
}
|
||||||
else if (string(curr_arg) == "-passInfo")
|
else if (string(curr_arg) == "-passInfo")
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "Utils/SgUtils.h"
|
#include "Utils/SgUtils.h"
|
||||||
#include "set_implicit_none.h"
|
#include "set_implicit_none.h"
|
||||||
|
#include <LoopAnalyzer/loop_analyzer.h>
|
||||||
|
|
||||||
using std::vector;
|
using std::vector;
|
||||||
using std::map;
|
using std::map;
|
||||||
@@ -14,106 +15,120 @@ using std::make_pair;
|
|||||||
using std::string;
|
using std::string;
|
||||||
using std::to_string;
|
using std::to_string;
|
||||||
|
|
||||||
static map<char, SgType*> implicit;
|
map<char, SgType*> types;
|
||||||
static set<SgSymbol*> vars;
|
vector<SgSymbol*> varsWithoutDecl;
|
||||||
static vector<SgSymbol*> toDecl;
|
const char commonIntLetters[6] = {'i', 'j', 'k', 'm', 'n', 'l'};
|
||||||
|
|
||||||
static void InsertToMap(SgType* type, SgExpression* letters) {
|
void InitTypes();
|
||||||
|
void FillCommonTypes();
|
||||||
while (letters != NULL && letters->lhs() != NULL) {
|
void GetImplicitTypes(SgExpression* expr);
|
||||||
|
|
||||||
string letter;
|
|
||||||
|
|
||||||
switch (letters->lhs()->sunparse().size()) {
|
|
||||||
|
|
||||||
case 3:
|
|
||||||
letter = letters->lhs()->sunparse();
|
|
||||||
implicit[letter[1]] = type;
|
|
||||||
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
letter = letters->lhs()->sunparse();
|
|
||||||
|
|
||||||
for (char i = letter[1]; i <= letter[5]; i++) {
|
|
||||||
implicit[i] = type;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default :
|
|
||||||
//printf("IMPLICIT bad format (can bew only {letter : letter} or {letter})");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
|
|
||||||
letters = letters->rhs();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void InsertDefaultToMap() {
|
void ImplicitCheck(SgFile* file) {
|
||||||
SgType* intType = new SgType(T_INT);
|
|
||||||
|
|
||||||
SgType* realType = new SgType(T_FLOAT);
|
auto implicitNoneDeclaration = new SgStatement(IMPL_DECL);
|
||||||
|
auto hasImplicitNone = false;
|
||||||
|
|
||||||
for (char i = 'a'; i <= 'z'; i++) {
|
for (SgStatement* i = file->firstStatement(); i = i->lexNext(); i != NULL) {
|
||||||
implicit[i] = realType;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (char i = 'i'; i <= 'n'; i++) {
|
if (i->variant() == IMPL_DECL) {
|
||||||
implicit[i] = intType;
|
SgImplicitStmt* implicitSt = isSgImplicitStmt(i);
|
||||||
}
|
if (implicitSt) {
|
||||||
}
|
int numberOfTypes = implicitSt->numberOfImplicitTypes();
|
||||||
|
|
||||||
static void CheckVariables(SgStatement* function) {
|
if (numberOfTypes > 0) {
|
||||||
|
for (int j = 0; j < numberOfTypes; j++) {
|
||||||
|
SgType* type = implicitSt->implicitType(j);
|
||||||
|
SgExpression* letters = implicitSt->implicitRangeList(j);
|
||||||
|
|
||||||
for (int k = 0; k < function->numberOfChildrenList1(); k++) {
|
types['a'] = type;
|
||||||
SgStatement* state = function->childList1(k);
|
printf("%s\n", letters->unparse());
|
||||||
|
|
||||||
|
|
||||||
if (state->expr(0) && (state->expr(0)->variant() == VAR_REF || state->expr(0)->variant() == ARRAY_REF)) {
|
|
||||||
SgSymbol* symbol = state->expr(0)->symbol();
|
|
||||||
auto x = declaratedInStmt(symbol, NULL, false);
|
|
||||||
|
|
||||||
if (vars.find(symbol) == vars.end() && x == NULL) {
|
|
||||||
vars.insert(symbol);
|
|
||||||
|
|
||||||
char firstLetter = *symbol->identifier();
|
|
||||||
|
|
||||||
if (implicit.find(firstLetter) != implicit.end()) {
|
|
||||||
if (implicit[firstLetter]->variant() != symbol->type()->variant()) {
|
|
||||||
symbol->setType(implicit[firstLetter]);
|
|
||||||
|
|
||||||
if (symbol->declaredInStmt() == NULL) {
|
|
||||||
toDecl.push_back(symbol);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
toDecl.push_back(symbol);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//printf("Variable - ");
|
hasImplicitNone = true;
|
||||||
//printf(symbol->identifier());
|
|
||||||
//printf(" - not found in IMPLICIT\n");
|
|
||||||
throw;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
printf("%s\nvariant - %d\n\n", i->unparse(), i->variant());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
makeDeclaration(toDecl, function, NULL);
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ImplicitCheck(SgProject* project) {
|
/*
|
||||||
|
*
|
||||||
/*
|
*
|
||||||
printf("IMPLICIT\n");
|
auto x = implicitSt->numberOfImplicitTypes();
|
||||||
*/
|
printf("IMPLICIT\n%s", implicitSt->unparse());
|
||||||
|
printf("number - %d\n", x);
|
||||||
for (int i = 0; i < project->numberOfFiles(); i++) {
|
for (int j = 0; j < x; j++) {
|
||||||
SgFile file = project->file(i);
|
printf("%d - %s\n", j, implicitSt->implicitRangeList(j)->unparse());
|
||||||
int coutOfFunctions;
|
}
|
||||||
for (int j = 0; j < file.numberOfFunctions(); j++) {
|
printf("\n");
|
||||||
SgStatement* function = file.functions(j);
|
*
|
||||||
|
int coutOfFunctions;
|
||||||
|
for (int j = 0; j < file->numberOfFunctions(); j++) {
|
||||||
|
SgStatement* function = file->functions(j);
|
||||||
|
|
||||||
implicit.clear();
|
implicit.clear();
|
||||||
vars.clear();
|
vars.clear();
|
||||||
@@ -183,5 +198,89 @@ void ImplicitCheck(SgProject* project) {
|
|||||||
CheckVariables(function);
|
CheckVariables(function);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void InsertToMap(SgType* type, SgExpression* letters) {
|
||||||
|
|
||||||
|
while (letters != NULL && letters->lhs() != NULL) {
|
||||||
|
|
||||||
|
string letter;
|
||||||
|
|
||||||
|
switch (letters->lhs()->sunparse().size()) {
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
letter = letters->lhs()->sunparse();
|
||||||
|
implicit[letter[1]] = type;
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
letter = letters->lhs()->sunparse();
|
||||||
|
|
||||||
|
for (char i = letter[1]; i <= letter[5]; i++) {
|
||||||
|
implicit[i] = type;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
//printf("IMPLICIT bad format (can bew only {letter : letter} or {letter})");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
letters = letters->rhs();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void InsertDefaultToMap() {
|
||||||
|
SgType* intType = new SgType(T_INT);
|
||||||
|
|
||||||
|
SgType* realType = new SgType(T_FLOAT);
|
||||||
|
|
||||||
|
for (char i = 'a'; i <= 'z'; i++) {
|
||||||
|
implicit[i] = realType;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (char i = 'i'; i <= 'n'; i++) {
|
||||||
|
implicit[i] = intType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void CheckVariables(SgStatement* function) {
|
||||||
|
|
||||||
|
for (int k = 0; k < function->numberOfChildrenList1(); k++) {
|
||||||
|
SgStatement* state = function->childList1(k);
|
||||||
|
|
||||||
|
|
||||||
|
if (state->expr(0) && (state->expr(0)->variant() == VAR_REF || state->expr(0)->variant() == ARRAY_REF)) {
|
||||||
|
SgSymbol* symbol = state->expr(0)->symbol();
|
||||||
|
auto x = declaratedInStmt(symbol, NULL, false);
|
||||||
|
|
||||||
|
if (vars.find(symbol) == vars.end() && x == NULL) {
|
||||||
|
vars.insert(symbol);
|
||||||
|
|
||||||
|
char firstLetter = *symbol->identifier();
|
||||||
|
|
||||||
|
if (implicit.find(firstLetter) != implicit.end()) {
|
||||||
|
if (implicit[firstLetter]->variant() != symbol->type()->variant()) {
|
||||||
|
symbol->setType(implicit[firstLetter]);
|
||||||
|
|
||||||
|
if (symbol->declaredInStmt() == NULL) {
|
||||||
|
toDecl.push_back(symbol);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
toDecl.push_back(symbol);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//printf("Variable - ");
|
||||||
|
//printf(symbol->identifier());
|
||||||
|
//printf(" - not found in IMPLICIT\n");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
makeDeclaration(toDecl, function, NULL);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Utils/SgUtils.h"
|
#include "Utils/SgUtils.h"
|
||||||
|
|
||||||
#include "string"
|
#include <string>
|
||||||
#include "map"
|
#include <map>
|
||||||
|
|
||||||
void ImplicitCheck(SgProject* project);
|
void ImplicitCheck(SgFile* file);
|
||||||
@@ -306,8 +306,6 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
|
|||||||
|
|
||||||
Pass(REMOVE_OMP_DIRS) <= Pass(REMOVE_OMP_DIRS_TRANSFORM);
|
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,
|
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,
|
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,
|
REVERSE_CREATED_NESTED_LOOPS, PREDICT_SCHEME, CALCULATE_STATS_SCHEME, REVERT_SPF_DIRS, CLEAR_SPF_DIRS, TRANSFORM_SHADOW_IF_FULL,
|
||||||
|
|||||||
Reference in New Issue
Block a user