Compare commits
9 Commits
master
...
1522dc7f27
| Author | SHA1 | Date | |
|---|---|---|---|
| 1522dc7f27 | |||
| bd52d5c6ec | |||
| 4ba2bb4c94 | |||
| 60544ea4d6 | |||
|
|
b40e969d02 | ||
| d062e52dd6 | |||
| 392ad97738 | |||
| c2c111586c | |||
| 172eedfef1 |
@@ -226,6 +226,8 @@ set(CFG _src/CFGraph/IR.cpp
|
|||||||
_src/CFGraph/live_variable_analysis.h
|
_src/CFGraph/live_variable_analysis.h
|
||||||
_src/CFGraph/private_variables_analysis.cpp
|
_src/CFGraph/private_variables_analysis.cpp
|
||||||
_src/CFGraph/private_variables_analysis.h
|
_src/CFGraph/private_variables_analysis.h
|
||||||
|
_src/CFGraph/IRSSAForm.cpp
|
||||||
|
_src/CFGraph/IRSSAForm.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set(DATA_FLOW
|
set(DATA_FLOW
|
||||||
|
|||||||
@@ -395,7 +395,7 @@ static SAPFOR::Argument* processExpression(SgExpression* ex, vector<IR_Block*>&
|
|||||||
if (ex)
|
if (ex)
|
||||||
{
|
{
|
||||||
const int var = ex->variant();
|
const int var = ex->variant();
|
||||||
if ((var == VAR_REF || var == CONST_REF || var == LABEL_REF) && !ex->lhs() && !ex->rhs()) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
if ((var == VAR_REF || var == CONST_REF || var == LABEL_REF) && !ex->lhs() && !ex->rhs()) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
{
|
{
|
||||||
if (var == CONST_REF)
|
if (var == CONST_REF)
|
||||||
{
|
{
|
||||||
@@ -1572,7 +1572,7 @@ vector<IR_Block*> buildIR(SgStatement* function, const FuncInfo* func, const vec
|
|||||||
else
|
else
|
||||||
findReturn(0, blocks.size(), blocks, blocks.back()->getNumber());
|
findReturn(0, blocks.size(), blocks, blocks.back()->getNumber());
|
||||||
|
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> GOTO <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> GOTO <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
for (int z = 0; z < blocks.size(); ++z)
|
for (int z = 0; z < blocks.size(); ++z)
|
||||||
{
|
{
|
||||||
auto op = blocks[z]->getInstruction()->getOperation();
|
auto op = blocks[z]->getInstruction()->getOperation();
|
||||||
@@ -1592,7 +1592,7 @@ vector<IR_Block*> buildIR(SgStatement* function, const FuncInfo* func, const vec
|
|||||||
|
|
||||||
blocks[z]->setJump(it->second);
|
blocks[z]->setJump(it->second);
|
||||||
|
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
arg->setValue(to_string(it->second->getNumber()));
|
arg->setValue(to_string(it->second->getNumber()));
|
||||||
arg->setType(CFG_ARG_TYPE::INSTR);
|
arg->setType(CFG_ARG_TYPE::INSTR);
|
||||||
}
|
}
|
||||||
@@ -1613,3 +1613,140 @@ vector<IR_Block*> buildIR(SgStatement* function, const FuncInfo* func, const vec
|
|||||||
|
|
||||||
return blocks;
|
return blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dfs(SAPFOR::BasicBlock* block, vector<int>& visit, vector<pair<SAPFOR::BasicBlock*, SAPFOR::BasicBlock*>>& startAndEnd, SAPFOR::BasicBlock* prev) {
|
||||||
|
if (visit[block->getNumber()] == 2) {
|
||||||
|
cout << "error";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (visit[block->getNumber()] == 1) {
|
||||||
|
visit[block->getNumber()] = 2;
|
||||||
|
startAndEnd.push_back(make_pair(prev, block));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
visit[block->getNumber()] = 1;
|
||||||
|
for (auto i : block->getNext()) {
|
||||||
|
dfs(i, visit, startAndEnd, block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void printBlock(SAPFOR::BasicBlock* block) {
|
||||||
|
cout << "block - " << block->getNumber() << endl;
|
||||||
|
cout << "next -";
|
||||||
|
for (auto i : block->getNext())
|
||||||
|
{
|
||||||
|
cout << " " << i->getNumber();
|
||||||
|
}
|
||||||
|
cout << endl << "prev -";
|
||||||
|
for (auto i : block->getPrev())
|
||||||
|
{
|
||||||
|
cout << " " << i->getNumber();
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
for (auto i : block->getInstructions())
|
||||||
|
{
|
||||||
|
cout << i->getNumber() << " " << i->getInstruction()->dump() << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void testIR(map<FuncInfo*, vector<SAPFOR::BasicBlock*>> fullIR) {
|
||||||
|
for (auto& i : fullIR)
|
||||||
|
{
|
||||||
|
for (auto j : i.second)
|
||||||
|
printBlock(j);
|
||||||
|
|
||||||
|
vector<IR_Block*> all;
|
||||||
|
for (auto j : i.second)
|
||||||
|
for (auto k : j->getInstructions())
|
||||||
|
all.push_back(k);
|
||||||
|
|
||||||
|
vector<int> visited(i.second.size(), 0);
|
||||||
|
vector<pair<SAPFOR::BasicBlock*, SAPFOR::BasicBlock*>> startAndEnd;
|
||||||
|
dfs(i.second[0], visited, startAndEnd, NULL);
|
||||||
|
|
||||||
|
|
||||||
|
vector<LoopGraph*> loops;
|
||||||
|
for (auto j : startAndEnd)
|
||||||
|
{
|
||||||
|
auto firstInstruction = j.second->getInstructions()[0]->getInstruction();
|
||||||
|
auto lastInstruction = j.first->getInstructions().back()->getInstruction();
|
||||||
|
Instruction* instructionAfterLoop;
|
||||||
|
for (auto a : fullIR)
|
||||||
|
for(auto b : a.second)
|
||||||
|
for (auto c : b->getInstructions())
|
||||||
|
if (c->getInstruction()->getNumber() == lastInstruction->getNumber() + 1)
|
||||||
|
{
|
||||||
|
instructionAfterLoop = c->getInstruction();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//auto instructionAfterLoop = getInstructionByNumber(all, lastInstruction->getNumber() + 1);
|
||||||
|
cout << "first - " << firstInstruction->getNumber() << " last - " << lastInstruction->getNumber() << " after - " << instructionAfterLoop->getNumber() << endl;
|
||||||
|
|
||||||
|
if (firstInstruction->getOperator()->variant() == FOR_NODE) {
|
||||||
|
SgForStmt* stmt = isSgForStmt(firstInstruction->getOperator());
|
||||||
|
|
||||||
|
auto tmpLoop = new LoopGraph();
|
||||||
|
tmpLoop->isFor = true;
|
||||||
|
tmpLoop->lineNum = firstInstruction->getOperator()->lineNumber();
|
||||||
|
tmpLoop->lineNumAfterLoop = instructionAfterLoop->getOperator()->lineNumber();
|
||||||
|
|
||||||
|
cout << "for" << endl << stmt->sunparse() << endl;
|
||||||
|
cout << "loop start line " << tmpLoop->lineNum << endl;
|
||||||
|
cout << "after loop line " << tmpLoop->lineNumAfterLoop << endl << endl;
|
||||||
|
loops.push_back(tmpLoop);
|
||||||
|
} else if (firstInstruction->getOperator()->variant() == WHILE_NODE) {
|
||||||
|
SgWhileStmt* stmt = isSgWhileStmt(firstInstruction->getOperator());
|
||||||
|
|
||||||
|
auto tmpLoop = new LoopGraph();
|
||||||
|
tmpLoop->lineNum = firstInstruction->getOperator()->lineNumber();
|
||||||
|
tmpLoop->lineNumAfterLoop = instructionAfterLoop->getOperator()->lineNumber();
|
||||||
|
|
||||||
|
if (stmt->conditional() == NULL)
|
||||||
|
{
|
||||||
|
//infinit loop
|
||||||
|
cout << "infinit loop " << endl << stmt->sunparse() << endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//while
|
||||||
|
cout << "while " << endl << stmt->sunparse();
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "loop start line " << tmpLoop->lineNum << endl;
|
||||||
|
cout << "after loop line " << tmpLoop->lineNumAfterLoop << endl << endl;
|
||||||
|
|
||||||
|
loops.push_back(tmpLoop);
|
||||||
|
} else if (firstInstruction->getOperator()->variant() == LOOP_NODE) {
|
||||||
|
cout << "not known loop" << endl << firstInstruction->getOperator()->sunparse() << endl;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cout << "goto loop - " << firstInstruction->getOperator()->sunparse() << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*for (auto j : i.second) {
|
||||||
|
cout << j->getNumber() << endl << "in" << endl;
|
||||||
|
for (auto k : j->getRD_In()) {
|
||||||
|
cout << k.first->getMemTypeStr() << " - ";
|
||||||
|
for (auto h : k.second) {
|
||||||
|
cout << h << " ";
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
cout << "out" << endl;
|
||||||
|
for (auto k : j->getRD_Out()) {
|
||||||
|
cout << k.first->getMemTypeStr() << " - ";
|
||||||
|
for (auto h : k.second) {
|
||||||
|
cout << h << " ";
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -344,3 +344,5 @@ SAPFOR::Instruction* getInstructionByNumber(const std::vector<SAPFOR::IR_Block*>
|
|||||||
std::pair<SAPFOR::Instruction*, SAPFOR::BasicBlock*> getInstructionAndBlockByNumber(const std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& CFGraph, int num);
|
std::pair<SAPFOR::Instruction*, SAPFOR::BasicBlock*> getInstructionAndBlockByNumber(const std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& CFGraph, int num);
|
||||||
std::pair<SAPFOR::Instruction*, SAPFOR::BasicBlock*> getInstructionAndBlockByStatement(const std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& CFGraph, SgStatement* stmt);
|
std::pair<SAPFOR::Instruction*, SAPFOR::BasicBlock*> getInstructionAndBlockByStatement(const std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& CFGraph, SgStatement* stmt);
|
||||||
int getParamIndex(SAPFOR::Argument* func_param, int max_index);
|
int getParamIndex(SAPFOR::Argument* func_param, int max_index);
|
||||||
|
|
||||||
|
void testIR(std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>> fullIR);
|
||||||
258
sapfor/experts/Sapfor_2017/_src/CFGraph/IRSSAForm.cpp
Normal file
258
sapfor/experts/Sapfor_2017/_src/CFGraph/IRSSAForm.cpp
Normal file
@@ -0,0 +1,258 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <vector>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
|
#include "../Utils/SgUtils.h"
|
||||||
|
#include "../Utils/CommonBlock.h"
|
||||||
|
#include "../GraphCall/graph_calls.h"
|
||||||
|
#include "../ExpressionTransform/expr_transform.h"
|
||||||
|
|
||||||
|
#include "dvm.h"
|
||||||
|
#include "IR.h"
|
||||||
|
#include "CFGraph.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace SAPFOR;
|
||||||
|
|
||||||
|
typedef SAPFOR::BasicBlock BBlock;
|
||||||
|
|
||||||
|
static void printBlock(BBlock* block) {
|
||||||
|
std::cout << "block - " << block->getNumber() << endl;
|
||||||
|
cout << "next -";
|
||||||
|
for (auto i : block->getNext())
|
||||||
|
{
|
||||||
|
cout << " " << i->getNumber();
|
||||||
|
}
|
||||||
|
/*cout << endl << "prev -";
|
||||||
|
for (auto i : block->getPrev())
|
||||||
|
{
|
||||||
|
cout << " " << i->getNumber();
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
for (auto i : block->getInstructions())
|
||||||
|
{
|
||||||
|
cout << i->getNumber() << " " << i->getInstruction()->dump() << endl;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
template <typename T>
|
||||||
|
static bool compareVectors(const std::vector<T>* vec1, const std::vector<T>* vec2) {
|
||||||
|
if (vec1 == vec2) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!vec1 || !vec2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<T> sortedVec1 = *vec1;
|
||||||
|
std::vector<T> sortedVec2 = *vec2;
|
||||||
|
|
||||||
|
std::sort(sortedVec1.begin(), sortedVec1.end());
|
||||||
|
std::sort(sortedVec2.begin(), sortedVec2.end());
|
||||||
|
|
||||||
|
return sortedVec1 == sortedVec2;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static std::vector<T>* getCommonElements(const std::vector<std::vector<T>>* vectors) {
|
||||||
|
if (!vectors || vectors->empty()) {
|
||||||
|
return new std::vector<T>(); // Return an empty vector if input is null or empty
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start with the first vector
|
||||||
|
std::vector<T>* commonElements = new std::vector<T>((*vectors)[0]);
|
||||||
|
|
||||||
|
for (size_t i = 1; i < vectors->size(); ++i) {
|
||||||
|
std::vector<T> tempCommon;
|
||||||
|
|
||||||
|
// Sort the current vector and common result for intersection
|
||||||
|
std::vector<T> sortedVec = (*vectors)[i];
|
||||||
|
std::sort(commonElements->begin(), commonElements->end());
|
||||||
|
std::sort(sortedVec.begin(), sortedVec.end());
|
||||||
|
|
||||||
|
// Find the intersection
|
||||||
|
std::set_intersection(
|
||||||
|
commonElements->begin(), commonElements->end(),
|
||||||
|
sortedVec.begin(), sortedVec.end(),
|
||||||
|
std::back_inserter(tempCommon)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Update common result
|
||||||
|
*commonElements = tempCommon;
|
||||||
|
|
||||||
|
// If no common elements left, break early
|
||||||
|
if (commonElements->empty()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return commonElements;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static map<BBlock*, vector<BBlock*>> findDominators(vector<BBlock*> blocks) {
|
||||||
|
map<BBlock*, vector<BBlock*>> result;
|
||||||
|
|
||||||
|
bool changed = true;
|
||||||
|
while (changed) {
|
||||||
|
changed = false;
|
||||||
|
|
||||||
|
for (auto currentBlock : blocks) {
|
||||||
|
auto pred = currentBlock->getPrev();
|
||||||
|
auto prevDominators = new vector<vector<BBlock*>>();
|
||||||
|
|
||||||
|
for (auto predBlock : pred)
|
||||||
|
prevDominators->push_back(result.find(predBlock) != result.end() ? result[predBlock] : blocks);
|
||||||
|
|
||||||
|
auto currentBlockResult = getCommonElements(prevDominators);
|
||||||
|
currentBlockResult->push_back(currentBlock);
|
||||||
|
|
||||||
|
if (result.find(currentBlock) == result.end() || !compareVectors(currentBlockResult, &result[currentBlock])) {
|
||||||
|
result[currentBlock] = *currentBlockResult;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void RenumberBlocks(BBlock* current, int* n, map<int, int>* res, set<BBlock*>* visited) {
|
||||||
|
if (visited->find(current) != visited->end()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
visited->insert(current);
|
||||||
|
|
||||||
|
std::vector<BBlock*> nextBlocks = current->getNext();
|
||||||
|
|
||||||
|
std::sort(nextBlocks.begin(), nextBlocks.end(), [](BBlock* a, BBlock* b) {
|
||||||
|
return a->getInstructions()[0]->getInstruction()->getOperator()->lineNumber() > b->getInstructions()[0]->getInstruction()->getOperator()->lineNumber();
|
||||||
|
});
|
||||||
|
|
||||||
|
for (auto i : nextBlocks) {
|
||||||
|
RenumberBlocks(i, n, res, visited);
|
||||||
|
}
|
||||||
|
|
||||||
|
(*res)[current->getNumber()] = *n;
|
||||||
|
*n -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static map<BBlock*, vector<BBlock*>> findDominatorBorders(vector<BBlock*>& blocks, map<BBlock*, BBlock*>& iDominators) {
|
||||||
|
map<BBlock*, vector<BBlock*>> result;
|
||||||
|
|
||||||
|
for (auto block : blocks) {
|
||||||
|
result[block] = *(new vector<BBlock*>());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto block : blocks) {
|
||||||
|
if (block->getPrev().size() > 1) {
|
||||||
|
for (auto prev : block->getPrev()) {
|
||||||
|
auto tmpBlock = prev;
|
||||||
|
|
||||||
|
while (tmpBlock != iDominators[block]) {
|
||||||
|
|
||||||
|
if (tmpBlock->getNumber() == 8 && block->getNumber() == 8) {
|
||||||
|
cout << "okjdwebnfklwedhfgklhwdgklvhvbklwdfhgvlhbwsdfgvlikbdflwkgb" << endl << prev->getNumber() << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
result[tmpBlock].push_back(block);
|
||||||
|
tmpBlock = iDominators[tmpBlock];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
map<FuncInfo*, vector<BBlock*>> buildIRSSAForm(map<FuncInfo*, vector<BBlock*>> fullIR) {
|
||||||
|
|
||||||
|
map<FuncInfo*, vector<BBlock*>> result;
|
||||||
|
|
||||||
|
for (auto item : fullIR) {
|
||||||
|
auto funcinfo = item.first;
|
||||||
|
auto funcIR = item.second;
|
||||||
|
|
||||||
|
auto funcResult = new vector<BBlock*>();
|
||||||
|
|
||||||
|
for (auto i : funcIR) {
|
||||||
|
printBlock(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto dominators = findDominators(funcIR);
|
||||||
|
|
||||||
|
cout << endl << endl << endl << "DOMINATORS" << endl << endl << endl;
|
||||||
|
|
||||||
|
for (auto i : dominators) {
|
||||||
|
cout << "block - " << i.first->getNumber() << endl;
|
||||||
|
for (auto j : i.second) {
|
||||||
|
cout << "dominators - " << j->getNumber() << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
map<int, int> numbers;
|
||||||
|
int n = funcIR.size() - 1;
|
||||||
|
RenumberBlocks(funcIR[0], &n, &numbers, new set<BBlock*>);
|
||||||
|
|
||||||
|
for (auto i : numbers) {
|
||||||
|
cout << i.first << " " << i.second << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
map<BBlock*, BBlock*> iDominators;
|
||||||
|
|
||||||
|
for (const auto& domPair : dominators) {
|
||||||
|
BBlock* block = domPair.first;
|
||||||
|
const std::vector<BBlock*>& domBlocks = domPair.second;
|
||||||
|
|
||||||
|
std::vector<int> domNumbers;
|
||||||
|
for (BBlock* domBlock : domBlocks) {
|
||||||
|
int number = numbers[domBlock->getNumber()];
|
||||||
|
domNumbers.push_back(number);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::sort(domNumbers.begin(), domNumbers.end());
|
||||||
|
|
||||||
|
if (domNumbers.size() < 2) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int secondLargestNumber = *(std::prev(domNumbers.end(), 2));
|
||||||
|
|
||||||
|
for (BBlock* domBlock : domBlocks) {
|
||||||
|
if (numbers[domBlock->getNumber()] == secondLargestNumber) {
|
||||||
|
iDominators[block] = domBlock;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto i : iDominators) {
|
||||||
|
cout << "block - " << i.first->getNumber() << endl;
|
||||||
|
cout << "Idominators - " << i.second->getNumber() << endl;
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto dominatorBorders = findDominatorBorders(funcIR, iDominators);
|
||||||
|
|
||||||
|
|
||||||
|
for (auto i : dominatorBorders) {
|
||||||
|
cout << "block - " << i.first->getNumber() << endl;
|
||||||
|
for (auto j : i.second) {
|
||||||
|
cout << "border - " << j->getNumber() << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
result[funcinfo] = *funcResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
6
sapfor/experts/Sapfor_2017/_src/CFGraph/IRSSAForm.h
Normal file
6
sapfor/experts/Sapfor_2017/_src/CFGraph/IRSSAForm.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CFGraph.h"
|
||||||
|
#include "IR.h"
|
||||||
|
|
||||||
|
std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>> buildIRSSAForm(std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>> fullIR);
|
||||||
@@ -1635,9 +1635,9 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> ®ions, map<tuple<int,
|
|||||||
string fName = file->functions(i)->symbol()->identifier();
|
string fName = file->functions(i)->symbol()->identifier();
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
if (file->functions(i)->variant() != MODULE_STMT)
|
if (file->functions(i)->variant() != MODULE_STMT)
|
||||||
sendMessage_2lvl(wstring(L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> '") + wstring(fName.begin(), fName.end()) + L"'");
|
sendMessage_2lvl(wstring(L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> '") + wstring(fName.begin(), fName.end()) + L"'");
|
||||||
else
|
else
|
||||||
sendMessage_2lvl(wstring(L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> '") + wstring(fName.begin(), fName.end()) + L"'");
|
sendMessage_2lvl(wstring(L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> '") + wstring(fName.begin(), fName.end()) + L"'");
|
||||||
#else
|
#else
|
||||||
if (file->functions(i)->variant() != MODULE_STMT)
|
if (file->functions(i)->variant() != MODULE_STMT)
|
||||||
sendMessage_2lvl(wstring(L"processing function '") + wstring(fName.begin(), fName.end()) + L"'");
|
sendMessage_2lvl(wstring(L"processing function '") + wstring(fName.begin(), fName.end()) + L"'");
|
||||||
@@ -2168,7 +2168,7 @@ void loopAnalyzer(SgFile *file, vector<ParallelRegion*> ®ions, map<tuple<int,
|
|||||||
{
|
{
|
||||||
string fName = file->functions(i)->symbol()->identifier();
|
string fName = file->functions(i)->symbol()->identifier();
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
sendMessage_2lvl(wstring(L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> ") + std::to_wstring(idx) + L"/" + std::to_wstring(convertedLoopInfo.size()));
|
sendMessage_2lvl(wstring(L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> ") + std::to_wstring(idx) + L"/" + std::to_wstring(convertedLoopInfo.size()));
|
||||||
#else
|
#else
|
||||||
sendMessage_2lvl(wstring(L"processing loop ") + std::to_wstring(idx) + L"/" + std::to_wstring(convertedLoopInfo.size()));
|
sendMessage_2lvl(wstring(L"processing loop ") + std::to_wstring(idx) + L"/" + std::to_wstring(convertedLoopInfo.size()));
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -92,6 +92,7 @@
|
|||||||
#include "CFGraph/IR.h"
|
#include "CFGraph/IR.h"
|
||||||
#include "CFGraph/RD_subst.h"
|
#include "CFGraph/RD_subst.h"
|
||||||
#include "CFGraph/CFGraph.h"
|
#include "CFGraph/CFGraph.h"
|
||||||
|
#include "CFGraph/IRSSAForm.h"
|
||||||
|
|
||||||
#include "CFGraph/live_variable_analysis.h"
|
#include "CFGraph/live_variable_analysis.h"
|
||||||
#include "CFGraph/private_variables_analysis.h"
|
#include "CFGraph/private_variables_analysis.h"
|
||||||
@@ -1003,6 +1004,10 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
|||||||
if(func->funcPointer->variant() != ENTRY_STAT)
|
if(func->funcPointer->variant() != ENTRY_STAT)
|
||||||
countOfTransform += removeDeadCode(func->funcPointer, allFuncInfo, commonBlocks);
|
countOfTransform += removeDeadCode(func->funcPointer, allFuncInfo, commonBlocks);
|
||||||
}
|
}
|
||||||
|
else if (curr_regime == EXPLORE_IR_LOOPS)
|
||||||
|
testIR(fullIR);
|
||||||
|
else if (curr_regime == BUILD_IR_SSA_FORM)
|
||||||
|
buildIRSSAForm(fullIR);
|
||||||
else if (curr_regime == TEST_PASS)
|
else if (curr_regime == TEST_PASS)
|
||||||
{
|
{
|
||||||
//test pass
|
//test pass
|
||||||
|
|||||||
@@ -181,6 +181,8 @@ enum passes {
|
|||||||
|
|
||||||
SET_IMPLICIT_NONE,
|
SET_IMPLICIT_NONE,
|
||||||
RENAME_INLCUDES,
|
RENAME_INLCUDES,
|
||||||
|
EXPLORE_IR_LOOPS,
|
||||||
|
BUILD_IR_SSA_FORM,
|
||||||
|
|
||||||
TEST_PASS,
|
TEST_PASS,
|
||||||
EMPTY_PASS
|
EMPTY_PASS
|
||||||
@@ -365,6 +367,8 @@ static void setPassValues()
|
|||||||
passNames[SET_IMPLICIT_NONE] = "SET_IMPLICIT_NONE";
|
passNames[SET_IMPLICIT_NONE] = "SET_IMPLICIT_NONE";
|
||||||
passNames[RENAME_INLCUDES] = "RENAME_INLCUDES";
|
passNames[RENAME_INLCUDES] = "RENAME_INLCUDES";
|
||||||
passNames[INSERT_NO_DISTR_FLAGS_FROM_GUI] = "INSERT_NO_DISTR_FLAGS_FROM_GUI";
|
passNames[INSERT_NO_DISTR_FLAGS_FROM_GUI] = "INSERT_NO_DISTR_FLAGS_FROM_GUI";
|
||||||
|
passNames[EXPLORE_IR_LOOPS] = "EXPLORE_IR_LOOPS";
|
||||||
|
passNames[BUILD_IR_SSA_FORM] = "BUILD_IR_SSA_FORM";
|
||||||
|
|
||||||
passNames[TEST_PASS] = "TEST_PASS";
|
passNames[TEST_PASS] = "TEST_PASS";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -314,6 +314,9 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
|
|||||||
|
|
||||||
list({ VERIFY_INCLUDES, CORRECT_VAR_DECL }) <= Pass(SET_IMPLICIT_NONE);
|
list({ VERIFY_INCLUDES, CORRECT_VAR_DECL }) <= Pass(SET_IMPLICIT_NONE);
|
||||||
|
|
||||||
|
list({ CALL_GRAPH, LOOP_GRAPH, CALL_GRAPH2 }) <= Pass(EXPLORE_IR_LOOPS);
|
||||||
|
list({ CALL_GRAPH, LOOP_GRAPH, CALL_GRAPH2 }) <= Pass(BUILD_IR_SSA_FORM);
|
||||||
|
|
||||||
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