WIP : Add new pass - set-implisit-none
This commit is contained in:
@@ -187,6 +187,9 @@ set(TR_FUNC_PURE _src/Transformations/function_purifying.cpp
|
||||
_src/Transformations/function_purifying.h)
|
||||
set(TR_GV _src/Transformations/fix_common_blocks.cpp
|
||||
_src/Transformations/fix_common_blocks.h)
|
||||
set(TR_IMPLICIT_NONE _src/Transformations/set_implicit_none.cpp
|
||||
_src/Transformations/set_implicit_none.h)
|
||||
|
||||
set(TRANSFORMS
|
||||
${TR_CP}
|
||||
${TR_VECTOR}
|
||||
@@ -200,7 +203,8 @@ set(TRANSFORMS
|
||||
${TR_FUNC_PURE}
|
||||
${TR_LOOP_UNROLL}
|
||||
${TR_GV}
|
||||
${TR_PRIV_DEL})
|
||||
${TR_PRIV_DEL}
|
||||
${TR_IMPLICIT_NONE})
|
||||
|
||||
set(CFG _src/CFGraph/IR.cpp
|
||||
_src/CFGraph/IR.h
|
||||
@@ -419,6 +423,7 @@ source_group (Transformations\\PrivateArrayRemoving FILES ${TR_PRIV_DEL})
|
||||
source_group (Transformations\\VectorAssignToLoop FILES ${TR_VECTOR})
|
||||
source_group (Transformations\\RenameSymbols FILES ${RENAME_SYMBOLS})
|
||||
source_group (Transformations\\GlobalVariables FILES ${TR_GV})
|
||||
source_group (Transformations\\SetImplicitNone FILES ${TR_IMPLICIT_NONE})
|
||||
|
||||
|
||||
source_group (CreateIntervals FILES ${CREATE_INTER_T})
|
||||
|
||||
@@ -78,6 +78,7 @@
|
||||
#include "Transformations/function_purifying.h"
|
||||
#include "Transformations/private_removing.h"
|
||||
#include "Transformations/fix_common_blocks.h"
|
||||
#include "Transformations/set_implicit_none.h"
|
||||
|
||||
#include "RenameSymbols/rename_symbols.h"
|
||||
#include "ProjectParameters/projectParameters.h"
|
||||
@@ -2175,6 +2176,8 @@ 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) {
|
||||
map<string, vector<Messages>> localMessages;
|
||||
|
||||
@@ -2608,6 +2611,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 TEST_PASS:
|
||||
runAnalysis(*project, curr_regime, false);
|
||||
case SUBST_EXPR_RD_AND_UNPARSE:
|
||||
|
||||
@@ -168,6 +168,8 @@ enum passes {
|
||||
|
||||
FIX_COMMON_BLOCKS,
|
||||
|
||||
SET_IMPLICIT_NONE,
|
||||
|
||||
TEST_PASS,
|
||||
EMPTY_PASS
|
||||
};
|
||||
@@ -339,6 +341,7 @@ static void setPassValues()
|
||||
passNames[PRIVATE_ANALYSIS_IR] = "PRIVATE_ANALYSIS_IR";
|
||||
|
||||
passNames[FIX_COMMON_BLOCKS] = "FIX_COMMON_BLOCKS";
|
||||
passNames[SET_IMPLICIT_NONE] = "SET_IMPLICIT_NONE";
|
||||
|
||||
passNames[TEST_PASS] = "TEST_PASS";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "Utils/SgUtils.h"
|
||||
#include "set_implicit_none.h"
|
||||
|
||||
using std::vector;
|
||||
using std::map;
|
||||
using std::multimap;
|
||||
using std::set;
|
||||
using std::make_pair;
|
||||
using std::string;
|
||||
using std::to_string;
|
||||
|
||||
map<char, SgType*> implicit;
|
||||
set<SgSymbol*> vars;
|
||||
vector<SgSymbol*> toDecl;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
#include "Utils/SgUtils.h"
|
||||
|
||||
#include "string"
|
||||
#include "map"
|
||||
|
||||
void ImplicitCheck(SgProject* project);
|
||||
@@ -302,6 +302,8 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
|
||||
|
||||
Pass(CALL_GRAPH2) <= Pass(FIX_COMMON_BLOCKS);
|
||||
|
||||
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