fixes for dead code removing pass
This commit is contained in:
@@ -29,6 +29,7 @@ public:
|
||||
virtual bool addIn(const DataType& data) = 0;
|
||||
virtual bool addOut(const DataType& data) = 0;
|
||||
|
||||
virtual bool updateState() { return false; }
|
||||
virtual bool forwardData(const DataType& data) = 0;
|
||||
|
||||
bool newerThan(const DataFlowAnalysisNode<DataType>* block) const { return out_cnt > block->in_cnt; }
|
||||
|
||||
@@ -27,6 +27,8 @@ template <class DataType>
|
||||
void DataFlowAnalysisNode<DataType>::doStep()
|
||||
{
|
||||
int in_max_cnt = CNT_NOTINIT, out_max_cnt = CNT_NOTINIT;
|
||||
|
||||
bool uniq_change = updateState();
|
||||
for (auto next : prev_blocks)
|
||||
{
|
||||
if (in_cnt < next->out_cnt)
|
||||
@@ -49,7 +51,7 @@ void DataFlowAnalysisNode<DataType>::doStep()
|
||||
}
|
||||
}
|
||||
|
||||
bool was_notinit = (out_cnt == CNT_NOTINIT);
|
||||
uniq_change |= (out_cnt == CNT_NOTINIT);
|
||||
|
||||
if (out_max_cnt != CNT_NOTINIT)
|
||||
out_cnt = out_max_cnt;
|
||||
@@ -58,7 +60,7 @@ void DataFlowAnalysisNode<DataType>::doStep()
|
||||
in_cnt = in_max_cnt;
|
||||
|
||||
// TODO: fix counter overflow
|
||||
if (was_notinit)
|
||||
if (uniq_change)
|
||||
{
|
||||
out_cnt++;
|
||||
in_cnt++;
|
||||
|
||||
@@ -39,7 +39,9 @@ static void updateUseDefForInstruction(SAPFOR::BasicBlock* block, SAPFOR::Instru
|
||||
{
|
||||
for (SAPFOR::Argument* r : res)
|
||||
{
|
||||
if (use.find(r) != use.end() || r->getMemType() != SAPFOR::CFG_MEM_TYPE::LOCAL_)
|
||||
if (use.find(r) != use.end() ||
|
||||
r->getMemType() != SAPFOR::CFG_MEM_TYPE::LOCAL_ ||
|
||||
r->getType() != SAPFOR::CFG_ARG_TYPE::VAR)
|
||||
{
|
||||
useful = true;
|
||||
break;
|
||||
@@ -88,7 +90,7 @@ static void updateUseDefForInstruction(SAPFOR::BasicBlock* block, SAPFOR::Instru
|
||||
use.insert(e);
|
||||
def.erase(e);
|
||||
}
|
||||
|
||||
|
||||
insertIfVar(args.begin(), args.end(), usedByThisBlock);
|
||||
}
|
||||
|
||||
@@ -207,11 +209,6 @@ public:
|
||||
bool addIn(const map<SAPFOR::Argument*, vector<SAPFOR::BasicBlock*>>& data) {
|
||||
bool inserted = getBlock()->addLiveOut(data);
|
||||
|
||||
if (!useful_block)
|
||||
inserted |= updateNextNotEmpty();
|
||||
|
||||
inserted |= updateJumpStatus();
|
||||
|
||||
return inserted;
|
||||
}
|
||||
|
||||
@@ -219,6 +216,21 @@ public:
|
||||
return getBlock()->addLiveIn(data);
|
||||
}
|
||||
|
||||
bool updateState() {
|
||||
if(getBlock()->getInstructions()[0]->getInstruction()->getOperator()->lineNumber() == 58)
|
||||
int b = 51;
|
||||
|
||||
bool updated = false;
|
||||
|
||||
if (!useful_block)
|
||||
updated |= updateNextNotEmpty();
|
||||
|
||||
updated |= updateJumpStatus();
|
||||
updated |= this->forwardData({ });
|
||||
|
||||
return updated;
|
||||
}
|
||||
|
||||
bool forwardData(const map<SAPFOR::Argument*, vector<SAPFOR::BasicBlock*>>& data) {
|
||||
bool inserted = false;
|
||||
SAPFOR::BasicBlock* bb= getBlock();
|
||||
@@ -298,13 +310,6 @@ public:
|
||||
{
|
||||
setBlock(block);
|
||||
useful.resize(block->getInstructions().size(), false);
|
||||
set<SAPFOR::Argument*> use, def;
|
||||
set<SAPFOR::Argument*> usedByThisBlock;
|
||||
|
||||
buildUseDef(getBlock(), use, def, this->formal_parameters, useful, usedByThisBlock, funcByName);
|
||||
|
||||
for (SAPFOR::Argument* arg : use)
|
||||
getBlock()->addLiveIn({ { arg, { getBlock() } } });
|
||||
}
|
||||
|
||||
const vector<bool>& getResult() { return useful; }
|
||||
|
||||
@@ -307,8 +307,8 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
|
||||
|
||||
Pass(REMOVE_OMP_DIRS) <= Pass(REMOVE_OMP_DIRS_TRANSFORM);
|
||||
|
||||
Pass(CALL_GRAPH2) <= Pass(REMOVE_DEAD_CODE);
|
||||
list({ REMOVE_DEAD_CODE, REVERT_SUBST_EXPR_RD, CONVERT_LOOP_TO_ASSIGN, RESTORE_LOOP_FROM_ASSIGN }) <= Pass(REMOVE_DEAD_CODE_AND_UNPARSE);
|
||||
list({ CALL_GRAPH2, REVERT_SUBST_EXPR_RD }) <= Pass(REMOVE_DEAD_CODE);
|
||||
list({ REMOVE_DEAD_CODE, CONVERT_LOOP_TO_ASSIGN, RESTORE_LOOP_FROM_ASSIGN }) <= Pass(REMOVE_DEAD_CODE_AND_UNPARSE);
|
||||
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user