task-create-implicit-pass #30
@@ -194,7 +194,7 @@ set(TR_IMPLICIT_NONE _src/Transformations/set_implicit_none.cpp
|
||||
_src/Transformations/set_implicit_none.h)
|
||||
|
||||
set(TRANSFORMS
|
||||
${TR_CP}
|
||||
${TR_CP}
|
||||
${TR_VECTOR}
|
||||
${TR_ENDDO_LOOP}
|
||||
${TR_LOOP_NEST}
|
||||
@@ -207,7 +207,7 @@ set(TRANSFORMS
|
||||
${TR_LOOP_UNROLL}
|
||||
${TR_GV}
|
||||
${TR_PRIV_DEL}
|
||||
${TR_CONV})
|
||||
${TR_CONV}
|
||||
${TR_PRIV_DEL}
|
||||
${TR_IMPLICIT_NONE})
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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,106 +15,120 @@ 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'};
|
||||
|
||||
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();
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
static void InsertDefaultToMap() {
|
||||
SgType* intType = new SgType(T_INT);
|
||||
void ImplicitCheck(SgFile* file) {
|
||||
|
||||
SgType* realType = new SgType(T_FLOAT);
|
||||
auto implicitNoneDeclaration = new SgStatement(IMPL_DECL);
|
||||
auto hasImplicitNone = false;
|
||||
|
||||
for (char i = 'a'; i <= 'z'; i++) {
|
||||
implicit[i] = realType;
|
||||
}
|
||||
for (SgStatement* i = file->firstStatement(); i = i->lexNext(); i != NULL) {
|
||||
|
||||
for (char i = 'i'; i <= 'n'; i++) {
|
||||
implicit[i] = intType;
|
||||
}
|
||||
}
|
||||
if (i->variant() == IMPL_DECL) {
|
||||
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++) {
|
||||
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);
|
||||
types['a'] = type;
|
||||
printf("%s\n", letters->unparse());
|
||||
}
|
||||
}
|
||||
else {
|
||||
//printf("Variable - ");
|
||||
//printf(symbol->identifier());
|
||||
//printf(" - not found in IMPLICIT\n");
|
||||
throw;
|
||||
hasImplicitNone = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
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");
|
||||
*/
|
||||
|
||||
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);
|
||||
/*
|
||||
*
|
||||
*
|
||||
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();
|
||||
@@ -124,7 +139,7 @@ void ImplicitCheck(SgProject* project) {
|
||||
for (int k = 0; k < function->numberOfChildrenList1(); k++) {
|
||||
SgStatement* state = function->childList1(k);
|
||||
|
||||
|
||||
|
||||
|
||||
if (state->variant() == IMPL_DECL) {
|
||||
|
||||
@@ -162,11 +177,11 @@ void ImplicitCheck(SgProject* project) {
|
||||
one = one->rhs();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (state->variant() == CONTROL_END) {
|
||||
|
||||
SgStatement* state = new SgStatement(IMPL_DECL);
|
||||
@@ -183,5 +198,89 @@ void ImplicitCheck(SgProject* project) {
|
||||
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
|
||||
#include "Utils/SgUtils.h"
|
||||
|
||||
#include "string"
|
||||
#include "map"
|
||||
#include <string>
|
||||
#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(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,
|
||||
|
||||
Reference in New Issue
Block a user