refactored
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
#include "leak_detector.h"
|
||||
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include "merge_regions.h"
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
using std::map;
|
||||
using std::set;
|
||||
using std::pair;
|
||||
using std::string;
|
||||
using std::unordered_map;
|
||||
using std::unordered_set;
|
||||
using std::vector;
|
||||
|
||||
//TODO: need to create new clause!!
|
||||
static void parseMergeDirective(const char *comment,
|
||||
vector<pair<string, string>> &parsed_mapping)
|
||||
{
|
||||
@@ -16,21 +18,27 @@ static void parseMergeDirective(const char *comment,
|
||||
{
|
||||
auto *line_end = strchr(comment, '\n');
|
||||
|
||||
static const char prefix[] = "!!SPF TRANSFORM(MERGE_ARRAYS(";
|
||||
static const char prefix[] = "!!spf transform(merge_arrays(";
|
||||
static const auto compare_chars = sizeof(prefix) - 1;
|
||||
|
||||
if (strncasecmp(comment, prefix, compare_chars) == 0)
|
||||
if (strlen(comment) >= compare_chars)
|
||||
{
|
||||
auto *pair_start = comment + compare_chars;
|
||||
auto *comma = strchr(pair_start, ',');
|
||||
if (comma)
|
||||
std::string comment_cmp(comment, compare_chars);
|
||||
convertToLower(comment_cmp);
|
||||
|
||||
if (comment_cmp == prefix)
|
||||
{
|
||||
auto *close_br = strchr(comma + 1, ')');
|
||||
if (close_br)
|
||||
auto* pair_start = comment + compare_chars;
|
||||
auto* comma = strchr(pair_start, ',');
|
||||
if (comma)
|
||||
{
|
||||
parsed_mapping.emplace_back(
|
||||
string(pair_start, comma - pair_start),
|
||||
string(comma + 1, close_br - comma - 1));
|
||||
auto* close_br = strchr(comma + 1, ')');
|
||||
if (close_br)
|
||||
{
|
||||
parsed_mapping.emplace_back(
|
||||
string(pair_start, comma - pair_start),
|
||||
string(comma + 1, close_br - comma - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,10 +86,10 @@ static bool hasSameSizes(DIST::Array *a, DIST::Array *b)
|
||||
}
|
||||
|
||||
static bool checkSimilarTemplates(vector<ParallelRegion *> ®ions,
|
||||
const unordered_map<string, string> &new_region_mapping)
|
||||
const map<string, string> &new_region_mapping)
|
||||
{
|
||||
// new region -> old regions
|
||||
unordered_map<string, unordered_set<string>> new_region_inverse_mapping;
|
||||
map<string, set<string>> new_region_inverse_mapping;
|
||||
for (const auto &p : new_region_mapping)
|
||||
new_region_inverse_mapping[p.second].insert(p.first);
|
||||
|
||||
@@ -126,8 +134,8 @@ static bool checkSimilarTemplates(vector<ParallelRegion *> ®ions,
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool hasSameAlignment(const std::unordered_set<const AlignRule *> &align_a,
|
||||
const std::unordered_set<const AlignRule *> &align_b)
|
||||
static bool hasSameAlignment(const std::set<const AlignRule *> &align_a,
|
||||
const std::set<const AlignRule *> &align_b)
|
||||
{
|
||||
if (align_a.size() != 1 || align_b.size() != 1)
|
||||
return false;
|
||||
@@ -238,7 +246,7 @@ SgSymbol *insertDeclIfNeeded(const string &array_name,
|
||||
const string &common_block_name,
|
||||
DIST::Array *example_array,
|
||||
FuncInfo *dest,
|
||||
unordered_map<FuncInfo *, unordered_map<string, SgSymbol *>> &inserted_arrays)
|
||||
map<FuncInfo *, map<string, SgSymbol *>> &inserted_arrays)
|
||||
{
|
||||
auto *type = GetArrayType(example_array);
|
||||
|
||||
@@ -278,7 +286,7 @@ SgSymbol *insertDeclIfNeeded(const string &array_name,
|
||||
|
||||
static pair<string, string> createNewArray(DIST::Array *example_array, const string &base_name,
|
||||
const map<string, vector<FuncInfo *>> &allFuncInfo,
|
||||
unordered_map<FuncInfo *, unordered_map<string, SgSymbol *>> &inserted_arrays)
|
||||
map<FuncInfo *, map<string, SgSymbol *>> &inserted_arrays)
|
||||
{
|
||||
auto common_block_name = base_name + "_merge_r";
|
||||
auto array_name = base_name;
|
||||
@@ -303,12 +311,12 @@ static pair<string, string> createNewArray(DIST::Array *example_array, const str
|
||||
}
|
||||
|
||||
static void replaceArrayRec(SgExpression *e,
|
||||
const unordered_set<string> &arrays_to_replace,
|
||||
const set<string> &arrays_to_replace,
|
||||
SgSymbol **func_symbol_hint,
|
||||
const pair<string, string> &replace_by,
|
||||
DIST::Array *example_array,
|
||||
FuncInfo *func,
|
||||
unordered_map<FuncInfo *, unordered_map<string, SgSymbol *>> &inserted_arrays)
|
||||
map<FuncInfo *, map<string, SgSymbol *>> &inserted_arrays)
|
||||
{
|
||||
if (!e)
|
||||
return;
|
||||
@@ -346,7 +354,7 @@ static void replaceArrayRec(SgExpression *e,
|
||||
inserted_arrays);
|
||||
}
|
||||
|
||||
static void replaceRegion(SgStatement* st, const unordered_map<string, string> &new_region_mapping)
|
||||
static void replaceRegion(SgStatement* st, const map<string, string> &new_region_mapping)
|
||||
{
|
||||
if (!st)
|
||||
return;
|
||||
@@ -430,8 +438,8 @@ void mergeRegions(vector<ParallelRegion *> ®ions, const map<string, vector<Fu
|
||||
// parse directives
|
||||
|
||||
// new array name -> current arrays
|
||||
unordered_map<string, unordered_set<DIST::Array *>> arrays_to_merge;
|
||||
unordered_map<DIST::Array *, unordered_set<const AlignRule *>> array_alignment;
|
||||
map<string, set<DIST::Array *>> arrays_to_merge;
|
||||
map<DIST::Array *, set<const AlignRule *>> array_alignment;
|
||||
|
||||
for (const auto &by_file : allFuncInfo)
|
||||
{
|
||||
@@ -489,10 +497,10 @@ void mergeRegions(vector<ParallelRegion *> ®ions, const map<string, vector<Fu
|
||||
}
|
||||
|
||||
// old region -> new region
|
||||
unordered_map<string, string> new_region_mapping;
|
||||
map<string, string> new_region_mapping;
|
||||
|
||||
// new array -> new region
|
||||
unordered_map<string, string> arrays_new_region_mapping;
|
||||
map<string, string> arrays_new_region_mapping;
|
||||
vector<string> created_region_names;
|
||||
|
||||
for (const auto &by_new_array : arrays_to_merge)
|
||||
@@ -529,7 +537,7 @@ void mergeRegions(vector<ParallelRegion *> ®ions, const map<string, vector<Fu
|
||||
if (!checkSimilarTemplates(regions, new_region_mapping))
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
unordered_map<FuncInfo *, unordered_map<string, SgSymbol *>> inserted_arrays;
|
||||
map<FuncInfo *, map<string, SgSymbol *>> inserted_arrays;
|
||||
|
||||
for (const auto &by_dest_array : arrays_to_merge)
|
||||
{
|
||||
@@ -571,7 +579,7 @@ void mergeRegions(vector<ParallelRegion *> ®ions, const map<string, vector<Fu
|
||||
|
||||
auto created_array_info = createNewArray(first_element, by_dest_array.first, allFuncInfo, inserted_arrays);
|
||||
|
||||
unordered_set<string> arrays_to_replace;
|
||||
set<string> arrays_to_replace;
|
||||
for (auto *array_to_merge : copy_arrays)
|
||||
arrays_to_replace.insert(array_to_merge->GetShortName());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user