handle contains statement while removing dead code, fix getLive method
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include <set>
|
||||
#include <list>
|
||||
#include <unordered_map>
|
||||
#include <algorithm>
|
||||
|
||||
using std::string;
|
||||
using std::pair;
|
||||
@@ -138,7 +139,11 @@ namespace SAPFOR
|
||||
for (auto& by_pair : by_source)
|
||||
{
|
||||
auto& dest = res[by_pair.first];
|
||||
dest.insert(dest.end(), by_pair.second.begin(), by_pair.second.end());
|
||||
auto dest_copy = dest;
|
||||
|
||||
dest.resize(dest_copy.size() + by_pair.second.size());
|
||||
|
||||
set_union(dest_copy.begin(), dest_copy.end(), by_pair.second.begin(), by_pair.second.end(), dest.begin());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -503,12 +503,29 @@ void removeDeadCode(SgStatement* func,
|
||||
READ_STAT
|
||||
};
|
||||
|
||||
set<int> skip =
|
||||
{
|
||||
PROG_HEDR,
|
||||
PROC_HEDR,
|
||||
FUNC_HEDR
|
||||
};
|
||||
|
||||
vector<SgStatement*> remove;
|
||||
SgStatement* start = intervalDelStart ? intervalDelStart : func;
|
||||
SgStatement* end = intervalDelEnd ? intervalDelEnd : func->lastNodeOfStmt();
|
||||
|
||||
for (auto st = start; st != end; st = st->lexNext())
|
||||
auto st = start;
|
||||
if (skip.find(st->variant()) != skip.end())
|
||||
st = st->lexNext();
|
||||
|
||||
for (; st != end; st = st->lexNext())
|
||||
{
|
||||
if (skip.find(st->variant()) != skip.end())
|
||||
{
|
||||
st = st->lastNodeOfStmt();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (removable.find(st->variant()) != removable.end() && useful.find(st) == useful.end())
|
||||
{
|
||||
remove.push_back(st);
|
||||
@@ -526,9 +543,21 @@ void removeDeadCode(SgStatement* func,
|
||||
do
|
||||
{
|
||||
remove.clear();
|
||||
for (auto st = start; st != end; st = st->lexNext())
|
||||
|
||||
st = start;
|
||||
if (skip.find(st->variant()) != skip.end())
|
||||
st = st->lexNext();
|
||||
|
||||
for (; st != end; st = st->lexNext())
|
||||
{
|
||||
const int var = st->variant();
|
||||
|
||||
if (skip.find(var) != skip.end())
|
||||
{
|
||||
st = st->lastNodeOfStmt();
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((var == FOR_NODE || var == WHILE_NODE || var == SWITCH_NODE) &&
|
||||
st->lexNext()->variant() == CONTROL_END)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user