44 #include "config_HAVE_FROM_PRAGMA_BUILT.hpp" 46 #include "config_NPROFILE.hpp" 97 #include <boost/algorithm/string.hpp> 98 #include <boost/graph/depth_first_search.hpp> 99 #include <boost/graph/reverse_graph.hpp> 103 "atomic",
"barrier",
"critical",
"declare simd",
"for",
"parallel for",
"parallel sections",
104 "parallel",
"sections",
"section",
"simd",
"target",
"task",
111 TM(_application_manager->get_tree_manager()),
113 debug_level(_param->get_class_debug_level(
GET_CLASS(*this)))
115 if(
param->isOption(OPT_blackbox))
118 for(
const auto& black_box_function : black_box_functions)
121 "Function \"" + black_box_function +
"\" is a blackbox");
150 return std::list<std::string>();
168 for(
const auto& pragma : pragmas)
170 std::match_results<std::string::const_iterator> what;
172 if(pragma.find(
"#pragma omp declare simd") == 0)
177 THROW_ERROR(
"Unsupported function definition pragma associated with function " + function_name +
": " + pragma);
184 for(k = Pragmas.begin(); k != k_end; ++
k)
192 unsigned int scope =
TM->new_tree_node_id();
193 std::map<TreeVocabularyTokenTypes_TokenEnum, std::string> tree_node_schema;
194 TM->create_tree_node(scope, issue_pragma_K, tree_node_schema);
196 unsigned int directive =
TM->new_tree_node_id();
197 TM->create_tree_node(directive, blackbox_pragma_K, tree_node_schema);
199 std::map<TreeVocabularyTokenTypes_TokenEnum, std::string> schema;
206 unsigned int final_id =
TM->new_tree_node_id();
207 TM->create_tree_node(final_id, gimple_pragma_K, schema);
216 std::map<TreeVocabularyTokenTypes_TokenEnum, std::string> simd_tree_node_schema, omp_pragma_tree_node_schema,
218 unsigned int scope_id =
TM->new_tree_node_id();
219 TM->create_tree_node(scope_id, omp_pragma_K, omp_pragma_tree_node_schema);
221 unsigned int simd_id =
TM->new_tree_node_id();
222 TM->create_tree_node(simd_id, omp_simd_pragma_K, simd_tree_node_schema);
223 auto* osp = GetPointer<omp_simd_pragma>(
TM->get_tree_node_const(simd_id));
224 if(line !=
"#pragma omp declare simd")
226 osp->clauses =
ExtractClauses(line.substr(line.find(
"#pragma omp declare simd ")));
236 unsigned int pragma_id =
TM->new_tree_node_id();
237 TM->create_tree_node(pragma_id, gimple_pragma_K, tree_node_schema);
245 if(!clauses_list.size())
250 std::string trimmed_clauses = clauses_list;
251 bool inside_parentheses =
false;
255 if(trimmed_clauses[
index - 1] ==
')')
257 inside_parentheses =
true;
259 else if(trimmed_clauses[
index - 1] ==
'(')
261 inside_parentheses =
false;
269 trimmed_clauses.erase(
index - 1, 1);
272 else if(trimmed_clauses[
index - 1] ==
' ' && inside_parentheses)
274 trimmed_clauses.erase(
index - 1, 1);
278 std::vector<std::string> splitted =
SplitString(trimmed_clauses,
" \t\n");
280 for(
const auto& clause : splitted)
282 if(clause.find(
'(') != std::string::npos)
284 const std::string
key = clause.substr(0, clause.find(
'('));
285 const std::string
value = clause.substr(clause.find(
'(') + 1, clause.size() - clause.find(
'(') - 2);
291 clauses_map[clause] =
"";
310 const vertex bb_operation_vertex)
const 313 vertex current = bb_operation_vertex;
315 "-->Looking for an openmp associated with loop " +
316 std::to_string(bb_cfg->
CGetBBNodeInfo(bb_operation_vertex)->block->number));
317 while(boost::in_degree(current, *bb_cfg) == 1)
320 for(
const auto& stmt : info->block->CGetStmtList())
322 if(
GET_NODE(stmt)->get_kind() == gimple_pragma_K)
324 auto* pn = GetPointer<gimple_pragma>(
GET_NODE(stmt));
325 if(pn->scope && GetPointer<omp_pragma>(
GET_NODE(pn->scope)))
327 auto* fp = GetPointer<omp_for_pragma>(
GET_NODE(pn->directive));
336 boost::tie(ei, ei_end) = boost::in_edges(current, *bb_cfg);
337 current = boost::source(*ei, *bb_cfg);
347 vertex current = bb_operation_vertex;
349 "-->Looking for an openmp associated with loop " +
350 std::to_string(bb_cfg->CGetBBNodeInfo(bb_operation_vertex)->block->number));
351 while(boost::in_degree(current, *bb_cfg) == 1)
353 const auto info = bb_cfg->CGetBBNodeInfo(current);
355 for(
const auto& stmt : info->block->CGetStmtList())
358 if(
GET_NODE(stmt)->get_kind() == gimple_pragma_K)
360 const auto pn = GetPointerS<gimple_pragma>(
GET_NODE(stmt));
361 if(pn->scope && GetPointer<omp_pragma>(
GET_NODE(pn->scope)))
363 const auto fp = GetPointer<omp_for_pragma>(
GET_NODE(pn->directive));
366 info->block->RemoveStmt(stmt, AppM);
368 FB->GetLoops()->GetLoop(bb_cfg->CGetBBNodeInfo(bb_operation_vertex)->block->number)->loop_type |=
378 boost::tie(ei, ei_end) = boost::in_edges(current, *bb_cfg);
379 current = boost::source(*ei, *bb_cfg);
388 const auto current_loop_id = bb_cfg->CGetBBNodeInfo(bb_operation_vertex)->loop_id;
390 "-->Looking for an openmp simd associated with loop " +
391 std::to_string(bb_cfg->CGetBBNodeInfo(bb_operation_vertex)->block->number));
392 if(boost::in_degree(bb_operation_vertex, *bb_cfg) != 1)
398 boost::tie(ei, ei_end) = boost::in_edges(bb_operation_vertex, *bb_cfg);
399 vertex current = boost::source(*ei, *bb_cfg);
400 while(boost::in_degree(current, *bb_cfg) == 1)
402 const auto info = bb_cfg->GetBBNodeInfo(current);
404 for(
const auto& stmt : info->block->CGetStmtList())
406 if(
GET_NODE(stmt)->get_kind() == gimple_pragma_K)
408 const auto pn = GetPointerS<gimple_pragma>(
GET_NODE(stmt));
409 if(pn->scope && GetPointer<omp_pragma>(
GET_NODE(pn->scope)))
411 const auto sp = GetPointer<omp_simd_pragma>(
GET_NODE(pn->directive));
414 info->block->RemoveStmt(stmt, AppM);
418 const auto ssa_vdef = GetPointerS<ssa_name>(
GET_NODE(pn->vdef));
419 const auto vdef_uses = ssa_vdef->CGetUseStmts();
420 for(
const auto& stmt_uses : vdef_uses)
422 const auto gn = GetPointerS<gimple_node>(
GET_NODE(stmt_uses.first));
425 ssa_vdef->RemoveUse(stmt_uses.first);
426 gn->memuse =
nullptr;
428 if(gn->vuses.erase(pn->vdef))
430 ssa_vdef->RemoveUse(stmt_uses.first);
432 if(gn->vovers.erase(pn->vdef))
434 ssa_vdef->RemoveUse(stmt_uses.first);
440 FB->GetLoops()->GetLoop(bb_cfg->CGetBBNodeInfo(bb_operation_vertex)->block->number)->loop_type |=
449 boost::tie(ei, ei_end) = boost::in_edges(current, *bb_cfg);
450 current = boost::source(*ei, *bb_cfg);
451 if(boost::out_degree(current, *bb_cfg) != 1 || bb_cfg->CGetBBNodeInfo(current)->loop_id != current_loop_id)
471 return omp_pragma_type;
#define GET_NODE(t)
Macro used to hide implementation details when accessing a tree_node from another tree_node...
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
#define INDENT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
static const std::string omp_directive_keywords[OMP_UNKNOWN]
The list of omp directive keywords.
CustomOrderedSet< std::string > BlackBoxFunctions
Basic block control flow graph.
File containing functions and utilities to support the printing of debug messagges.
const std::list< std::string > GetFunctionDefinitionPragmas(const std::string &function_name) const
Return the pragmas associated with a function definition.
#define PRINT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
#define GET_CLASS(obj)
Macro returning the actual type of an object.
CustomUnorderedSet< std::string > getFunctionCallPragmas(const std::string &Name) const
Definition of the class representing a generic C application.
const std::vector< std::string > SplitString(const std::string &input, const std::string &separators)
Function which splits a string into tokens.
std::map< std::string, std::list< std::string > > function_definition_pragmas
Function defintion pragmas.
std::map< unsigned int, std::string > GenericPragmas
void addFunctionCallPragmas(const std::string &Name, const CustomUnorderedSet< std::string > &Pragmas)
const FunctionBehaviorConstRef CGetFunctionBehavior(unsigned int index) const
Returns the data-structure associated with the given identifier.
bool checkCompliant() const
Check if the data-structure information are compliant with the pragma reference manual.
Class specification of the graph structures.
CustomUnorderedMapUnstable< std::string, std::string > ExtractClauses(const std::string &clauses_list) const
Extract clauses associated with a pragma.
boost::graph_traits< graph >::in_edge_iterator InEdgeIterator
in_edge_iterator definition.
exceptions managed by PandA
A simple interface to token object of the raw files.
#define GET_INDEX_NODE(t)
Macro used to hide implementation details when accessing a tree_node from another tree_node...
absl::flat_hash_map< T, U, Hash, Eq, Alloc > CustomUnorderedMapUnstable
Data structure describing a basic block at tree level.
redefinition of map to manage ordered/unordered structures
constant strings used in pragma identification
#define TOK(token)
Macro used to convert a token symbol into a treeVocabularyTokenTypes.
Include a set of utilities used to manage CPU time measures.
unsigned int addBlackBoxPragma(const std::string &function_name, unsigned int function_id)
#define STR(s)
Macro which performs a lexical_cast to a string.
void line(int x1, int y1, int x2, int y2, unsigned int color)
Auxiliary methods for manipulating string.
void AddFunctionDefinitionPragmas(const std::string &name, const CustomUnorderedSet< std::string > &pragmas)
Add a set of definition pragmas to a function.
virtual ~pragma_manager()
Destructor.
std::map< std::string, CustomUnorderedSet< std::string > > FunctionCallPragmas
static const uint32_t k[]
Manager for pragma annotations.
std::string getGenericPragma(unsigned int number) const
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Classes specification of the tree_node data structures.
OmpPragmaType
The possible openmp pragmas Note that sections has to go before section but after parallel sections o...
#define THROW_ERROR(str_expr)
helper function used to throw an error in a standard way
bool CheckOmpFor(const application_managerConstRef app_man, const unsigned int function_index, const vertex bb_operation_vertex) const
Check if a omp for pragma is associated with the loop.
This file collects some utility functions.
void CheckAddOmpFor(const unsigned int function_index, const vertex bb_operation_vertex, const application_managerRef AppM)
Check if a omp for pragma is associated with the loop; if yes, add the gimple_for.
Parsing pragma from C sources.
pragma_manager(const application_managerRef application_manager, const ParameterConstRef param)
Constructor.
int debug_level
The debug level.
Class specification of the tree_reindex support class.
bool isBlackBox(const std::string &name) const
FunctionBehaviorRef GetFunctionBehavior(unsigned int index)
Returns the data structure associated with the given identifier.
Class specification of the basic_block structure.
const BBNodeInfoConstRef CGetBBNodeInfo(const vertex node) const
Return the info associated with a basic block.
Data structures used in operations graph.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
const BBGraphConstRef CGetBBGraph(FunctionBehavior::bb_graph_type gt=FunctionBehavior::BB) const
This method returns the basic block graphs.
interface of loops finding algorithm
unsigned int AddOmpSimdPragma(const std::string &line, unsigned int function_id) const
Create a simd openmp pragma starting from the line containing it.
Classes specification of the tree_node data structures not present in the gcc.
this class is used to manage the command-line or XML options.
void setGenericPragma(unsigned int number, const std::string &line)
#define DOALL_LOOP
parallelizable for loop
#define PRINT_OUT_MEX(profLevel, curprofLevel, mex)
#define OUTPUT_LEVEL_VERBOSE
verbose debugging print is performed.
const ParameterConstRef param
Set of input parameters.
static OmpPragmaType GetOmpPragmaType(const std::string &directive)
Returns the identifier corresponding to an openmp directive.
Class specification of the manager of the tree structures extracted from the raw file.
A brief description of the C++ Header File.
void CheckAddOmpSimd(const unsigned int function_index, const vertex bb_operation_vertex, const application_managerRef AppM)
Check if a omp simd pragma is associated with the loop; if yes, add information to the loop...
#define DEBUG_LEVEL_MINIMUM
minimum debugging print is performed.
#define THROW_ASSERT(cond, str_expr)
helper function used to check an assert and if needed to throw an error in a standard way ...