improved MERGE_ARRAYS
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include "merge_regions.h"
|
||||
#include "../DirectiveProcessing/directive_parser.h"
|
||||
|
||||
using std::map;
|
||||
using std::set;
|
||||
@@ -10,46 +11,6 @@ using std::pair;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
//TODO: need to create new clause!!
|
||||
static void parseMergeDirective(const char *comment,
|
||||
vector<pair<string, string>> &parsed_mapping)
|
||||
{
|
||||
while (comment)
|
||||
{
|
||||
auto *line_end = strchr(comment, '\n');
|
||||
|
||||
static const char prefix[] = "!!spf transform(merge_arrays(";
|
||||
static const auto compare_chars = sizeof(prefix) - 1;
|
||||
|
||||
if (strlen(comment) >= compare_chars)
|
||||
{
|
||||
std::string comment_cmp(comment, compare_chars);
|
||||
convertToLower(comment_cmp);
|
||||
|
||||
if (comment_cmp == prefix)
|
||||
{
|
||||
auto* pair_start = comment + compare_chars;
|
||||
auto* comma = strchr(pair_start, ',');
|
||||
if (comma)
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
comment = line_end;
|
||||
|
||||
if (comment)
|
||||
comment++;
|
||||
}
|
||||
}
|
||||
|
||||
static string getNonDefaultRegion(DIST::Array *a)
|
||||
{
|
||||
string result;
|
||||
@@ -217,7 +178,7 @@ static SgExpression* findExprWithVariant(SgExpression* exp, int variant)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SgType* GetArrayType(DIST::Array *array)
|
||||
static SgType* GetArrayType(DIST::Array *array)
|
||||
{
|
||||
if (!array)
|
||||
return NULL;
|
||||
@@ -242,11 +203,11 @@ SgType* GetArrayType(DIST::Array *array)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SgSymbol *insertDeclIfNeeded(const string &array_name,
|
||||
const string &common_block_name,
|
||||
DIST::Array *example_array,
|
||||
FuncInfo *dest,
|
||||
map<FuncInfo *, map<string, SgSymbol *>> &inserted_arrays)
|
||||
static SgSymbol *insertDeclIfNeeded(const string &array_name,
|
||||
const string &common_block_name,
|
||||
DIST::Array *example_array,
|
||||
FuncInfo *dest,
|
||||
map<FuncInfo *, map<string, SgSymbol *>> &inserted_arrays)
|
||||
{
|
||||
auto *type = GetArrayType(example_array);
|
||||
|
||||
@@ -462,17 +423,20 @@ void mergeRegions(vector<ParallelRegion *> ®ions, const map<string, vector<Fu
|
||||
|
||||
for (; curr_stmt && curr_stmt != stmt_end; curr_stmt = curr_stmt->lexNext())
|
||||
{
|
||||
if (curr_stmt->comments())
|
||||
auto attributes = getAttributes<SgStatement*, SgStatement*>(curr_stmt, set<int>{SPF_TRANSFORM_DIR});
|
||||
|
||||
for (auto& attr : attributes)
|
||||
{
|
||||
vector<pair<string, string>> parsed_mapping;
|
||||
parseMergeDirective(curr_stmt->comments(), parsed_mapping);
|
||||
pair<string, string> parsed_mapping = { "", "" };
|
||||
const auto empty = parsed_mapping;
|
||||
fillMergeArraysFromComment(new Statement(attr), parsed_mapping);
|
||||
|
||||
for (const auto &p : parsed_mapping)
|
||||
if (parsed_mapping != empty)
|
||||
{
|
||||
auto *found_array = getArrayFromDeclarated(curr_stmt, p.first);
|
||||
auto* found_array = getArrayFromDeclarated(curr_stmt, parsed_mapping.first);
|
||||
if (found_array)
|
||||
{
|
||||
arrays_to_merge[p.second].insert(found_array);
|
||||
arrays_to_merge[parsed_mapping.second].insert(found_array);
|
||||
array_alignment[found_array] = {};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user