PandA-2024.02
extract_omp_atomic.cpp
Go to the documentation of this file.
1 /*
2  *
3  * _/_/_/ _/_/ _/ _/ _/_/_/ _/_/
4  * _/ _/ _/ _/ _/_/ _/ _/ _/ _/ _/
5  * _/_/_/ _/_/_/_/ _/ _/_/ _/ _/ _/_/_/_/
6  * _/ _/ _/ _/ _/ _/ _/ _/ _/
7  * _/ _/ _/ _/ _/ _/_/_/ _/ _/
8  *
9  * ***********************************************
10  * PandA Project
11  * URL: http://panda.dei.polimi.it
12  * Politecnico di Milano - DEIB
13  * System Architectures Group
14  * ***********************************************
15  * Copyright (c) 2015-2024 Politecnico di Milano
16  *
17  * This file is part of the PandA framework.
18  *
19  * The PandA framework is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
41 #include "extract_omp_atomic.hpp"
43 
45 #include "Parameter.hpp"
46 
48 #include "application_manager.hpp"
49 #include "basic_block.hpp"
50 #include "function_behavior.hpp"
51 
53 #include "token_interface.hpp"
54 
56 #include "custom_set.hpp"
57 #include <utility>
58 
60 #include "ext_tree_node.hpp"
61 #include "tree_basic_block.hpp"
62 #include "tree_manager.hpp"
63 #include "tree_node.hpp"
64 #include "tree_reindex.hpp"
65 
67 #include "dbgPrintHelper.hpp"
68 #include "utility.hpp"
69 
70 ExtractOmpAtomic::ExtractOmpAtomic(const application_managerRef _AppM, unsigned int _function_id,
71  const DesignFlowManagerConstRef _design_flow_manager,
72  const ParameterConstRef _parameters)
73  : FunctionFrontendFlowStep(_AppM, _function_id, EXTRACT_OMP_ATOMIC, _design_flow_manager, _parameters)
74 {
75  debug_level = parameters->get_class_debug_level(GET_CLASS(*this), DEBUG_LEVEL_NONE);
76 }
77 
79 
82 {
83  const auto TM = AppM->get_tree_manager();
85  switch(relationship_type)
86  {
88  {
89  relationships.insert(std::make_pair(BASIC_BLOCKS_CFG_COMPUTATION, SAME_FUNCTION));
90  break;
91  }
93  {
94  break;
95  }
97  {
98  break;
99  }
100  default:
101  {
102  THROW_UNREACHABLE("");
103  }
104  }
105  return relationships;
106 }
107 
109 {
110  const auto TM = AppM->get_tree_manager();
112  (!parameters->IsParameter("print-dot-FF") || parameters->GetParameter<unsigned int>("print-dot-FF")))
113  {
114  WriteBBGraphDot("BB_Before_" + GetName() + ".dot");
115  PrintTreeManager(true);
116  }
117  bool changed = false;
118  const auto basic_block_graph = function_behavior->CGetBBGraph(FunctionBehavior::BB);
119  VertexIterator basic_block, basic_block_end;
120  for(boost::tie(basic_block, basic_block_end) = boost::vertices(*basic_block_graph); basic_block != basic_block_end;
121  basic_block++)
122  {
123  const auto block = basic_block_graph->CGetBBNodeInfo(*basic_block)->block;
124  tree_nodeRef gimple_to_be_removed;
125  for(const auto& stmt : block->CGetStmtList())
126  {
127  const auto* pn = GetPointer<gimple_pragma>(GET_NODE(stmt));
128  if(pn && pn->scope && GetPointer<omp_pragma>(GET_NODE(pn->scope)))
129  {
130  const auto oa = GetPointer<omp_atomic_pragma>(GET_NODE(pn->directive));
131  if(oa)
132  {
133  if(block->list_of_pred.size() == 1 && block->list_of_pred.front() == BB_ENTRY &&
134  stmt == block->CGetStmtList().front())
135  {
136  gimple_to_be_removed = stmt;
137  GetPointer<function_decl>(AppM->get_tree_manager()->get_tree_node_const(function_id))->omp_atomic =
138  true;
139  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Found Atomic Omp function");
140  changed = true;
141  }
142  else
143  {
144  THROW_ERROR("Omp atomic not supported");
145  }
146  }
147  }
148  }
149  if(gimple_to_be_removed)
150  {
151  block->RemoveStmt(gimple_to_be_removed, AppM);
152  }
153  }
155  (!parameters->IsParameter("print-dot-FF") || parameters->GetParameter<unsigned int>("print-dot-FF")))
156  {
157  WriteBBGraphDot("BB_After_" + GetName() + ".dot");
158  PrintTreeManager(false);
159  }
161 }
#define GET_NODE(t)
Macro used to hide implementation details when accessing a tree_node from another tree_node...
Definition: tree_node.hpp:343
#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;.
Basic block control flow graph.
File containing functions and utilities to support the printing of debug messagges.
const CustomUnorderedSet< std::pair< FrontendFlowStepType, FunctionRelationship > > ComputeFrontendRelationships(const DesignFlowStep::RelationshipType relationship_type) const override
Return the set of analyses in relationship with this design step.
#define DEBUG_LEVEL_PEDANTIC
very verbose debugging print is performed.
Step successfully executed.
#define GET_CLASS(obj)
Macro returning the actual type of an object.
Definition of the class representing a generic C application.
std::string GetName() const override
Return the name of this design step.
RelationshipType
The relationship type.
Source must be executed to satisfy target.
~ExtractOmpAtomic() override
Destructor.
A simple interface to token object of the raw files.
void PrintTreeManager(const bool before) const
Dump the tree manager.
Data structure describing a basic block at tree level.
#define THROW_UNREACHABLE(str_expr)
helper function used to specify that some points should never be reached
Definition: exceptions.hpp:292
void WriteBBGraphDot(const std::string &filename) const
Write the current version of statement list in dot format.
redefinition of set to manage ordered/unordered structures
Analysis step extracting openmp atomic.
#define BB_ENTRY
constant identifying the basic block node of type entry
boost::graph_traits< graph >::vertex_iterator VertexIterator
vertex_iterator definition.
Definition: graph.hpp:1307
Classes specification of the tree_node data structures.
const ParameterConstRef parameters
Set of input parameters.
DesignFlowStep_Status
The status of a step.
This file collects some utility functions and macros.
#define DEBUG_LEVEL_NONE
no debugging print is performed.
#define THROW_ERROR(str_expr)
helper function used to throw an error in a standard way
Definition: exceptions.hpp:263
This struct specifies the block node.
Definition: tree_node.hpp:1820
ExtractOmpAtomic(const application_managerRef _AppM, unsigned int function_id, const DesignFlowManagerConstRef design_flow_manager, const ParameterConstRef parameters)
Constructor.
DesignFlowStep_Status InternalExec() override
Restructures the unstructured code.
const unsigned int function_id
The index of the function to be analyzed.
const application_managerRef AppM
The application manager.
Class specification of the tree_reindex support class.
Class specification of the basic_block structure.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
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.
int debug_level
The debug level.
block(unsigned int i)
constructor
Definition: tree_node.hpp:1823
Class specification of the manager of the tree structures extracted from the raw file.
A brief description of the C++ Header File.
const FunctionBehaviorRef function_behavior
The function behavior of the function to be analyzed.

Generated on Mon Feb 12 2024 13:02:51 for PandA-2024.02 by doxygen 1.8.13