ROSE  0.11.96.11
omp_lowering.h
1 #include "astQuery.h"
2 //#include "sage3basic.h"
3 
4 #ifndef OMP_LOWERING_H
5 #define OMP_LOWERING_H
6 
7 #include "ompSupport.h"
8 
16 extern std::vector<SgFunctionDeclaration* >* outlined_function_list;
17 extern std::vector<SgDeclarationStatement *>* outlined_struct_list;
18 namespace OmpSupport
19 {
20  //static std::vector<SgFunctionDeclaration* >* outlined_function_list = new std::vector<SgFunctionDeclaration *>();
21 
22  // OpenMP version info.
23  extern bool enable_accelerator;
24 
25  // A flag to control if device data environment runtime functions are used to automatically manage data as much as possible.
26  // instead of generating explicit data allocation, copy, free functions.
27  extern bool useDDE /* = true */;
30 
31 
33  // TODO: patchUpDefaultVariables(SgFile* );
34 
35  int makeDataSharingExplicit( SgFile* );
36 
37  // last edited by Hongyi on 07/24/2012.
38 
40  // We support both Omni and GCC OpenMP runtime libraries
42  {
43  e_gomp,
44  e_omni,
45  e_last_rtl
46  };
47  extern unsigned int nCounter; // translation generated variable counter, used to avoid name collision
48 
49  extern omp_rtl_enum rtl_type;
50  typedef std::map<const SgVariableSymbol *, SgVariableSymbol *> VariableSymbolMap_t;
51 
52  void commandLineProcessing(std::vector<std::string> &argvList);
53 
55  void lower_omp(SgSourceFile*);
56 
57  void analyze_omp(SgSourceFile*);
58 
61 
64 
65  //Pei-Hung Insert accelerator init
66  void insertAcceleratorInit(SgSourceFile* );
67 
71  {
72  protected:
73  void visit(SgNode*);
74  }; //translationDriver
75 
77  void transOmpParallel(SgNode* node);
78 
80  void transOmpTargetParallel(SgNode* node);
81 
83  void transOmpSections(SgNode* node);
84 
86  void transOmpTask(SgNode* node);
87 
89  void transUpirLoopParallel(SgNode* node);
90 
92  void transOmpLoop(SgNode* node);
93 
95  // The loop iteration count may exceed the max number of threads within a CUDA thread block.
96  // A loop scheduler is needed for real application.
97  void transOmpTargetLoop(SgNode* node);
98 
101 
103  //void transOmpDo(SgNode* node);
104 
106  void transOmpTarget(SgNode* node);
107 
109  void transOmpTargetData(SgNode* node);
110 
111 
113  void transOmpBarrier(SgNode* node);
114 
116  void transOmpFlush(SgNode* node);
117 
119  void transOmpTaskwait(SgNode* node);
120 
122  void transOmpThreadprivate(SgNode* node);
123 
125  void transOmpOrdered(SgNode* node);
127  void transOmpAtomic(SgNode* node);
129  void transOmpCritical(SgNode* node);
131  void transOmpMaster(SgNode* node);
133  void transOmpSingle(SgNode* node);
135  void transOmpMetadirective(SgNode* node);
136 
138  void transOmpSimd(SgNode *node);
139 
141  void transOmpUnroll(SgNode *node);
142 
144  void transOmpTile(SgNode *node);
145 
148  SgStatement *getUpirParent(SgStatement *node);
149  void setUpirRelationship(SgStatement *parent, SgStatement *child);
150  Rose_STL_Container<SgNode *> mergeSgNodeList(Rose_STL_Container<SgNode *> node_list1, Rose_STL_Container<SgNode *> node_list2);
151 
153  // It calls the ROSE AST outliner internally.
154  SgFunctionDeclaration* generateOutlinedTask(SgNode* node, std::string& wrapper_name,
155  std::set<const SgVariableSymbol*>& syms,
156  std::set<const SgVariableSymbol*>& pdSyms3,
157  bool use_task_param = false);
158 
160  ROSE_DLL_API void transOmpVariables(SgStatement * ompStmt, SgBasicBlock* bb1, SgExpression* orig_loop_upper = NULL, bool withinAcceleratorModel= false);
161 
163  ROSE_DLL_API SgInitializedNamePtrList collectAllClauseVariables (SgUpirFieldBodyStatement * clause_stmt);
164 
166  ROSE_DLL_API SgInitializedNamePtrList collectClauseVariables (SgUpirFieldBodyStatement * clause_stmt, const VariantT& vt);
167 
169  ROSE_DLL_API SgInitializedNamePtrList collectClauseVariables (SgUpirFieldBodyStatement * clause_stmt, const VariantVector& vvt);
170 
172  ROSE_DLL_API SgExpression* getClauseExpression (SgStatement * clause_stmt, const VariantVector& vvt);
173 
175  ROSE_DLL_API bool isInClauseVariableList(SgInitializedName* var, SgUpirFieldBodyStatement * clause_stmt, const VariantT& vt);
176 
178  ROSE_DLL_API bool isInClauseVariableList(SgInitializedName* var, SgUpirFieldBodyStatement * clause_stmt, const VariantVector& vvt);
179 
181  ROSE_DLL_API int replaceVariableReferences(SgNode* root, SgVariableSymbol* oldVar, SgVariableSymbol* newVar);
182 
184  ROSE_DLL_API int replaceVariableReferences(SgNode* root, VariableSymbolMap_t varRemap);
185  // I decided to reuse the existing Outliner work instead of coding a new one
186  //SgFunctionDeclaration* generateOutlinedFunction(SgNode* node);
187 
189  int replaceVariablesWithPointerDereference(SgNode* root, std::set<SgVariableSymbol*>& vars);
190 
192  ROSE_DLL_API void addClauseVariable(SgInitializedName* var, SgUpirFieldBodyStatement * clause_stmt, const VariantT& vt);
193  ROSE_DLL_API void addUpirDataVariable(SgUpirFieldBodyStatement* target, SgUpirDataItemField* data_item);
194 
196  ROSE_DLL_API SgOmpVariablesClause* buildOmpVariableClause(SgUpirFieldBodyStatement * clause_stmt, const VariantT& vt);
197 
199  ROSE_DLL_API int removeClause (SgStatement * clause_stmt, const VariantT& vt);
200 
202  ROSE_DLL_API bool hasClause(SgStatement* clause_stmt, const VariantT & vt);
203 
205  ROSE_DLL_API Rose_STL_Container<SgOmpClause*> getClause(SgStatement* clause_stmt, const VariantT & vt);
206 
208  ROSE_DLL_API bool useStaticSchedule(SgUpirFieldBodyStatement* omp_loop);
209 
211  ROSE_DLL_API SgOmpClause::omp_reduction_identifier_enum getReductionOperationType(SgInitializedName* init_name, SgUpirFieldBodyStatement* clause_stmt);
212 
214  ROSE_DLL_API SgExpression* createInitialValueExp(SgOmpClause::omp_reduction_identifier_enum r_operator);
215 
217  ROSE_DLL_API std::string generateGOMPLoopStartFuncName (bool isOrdered, SgOmpClause::omp_schedule_kind_enum s_kind);
218 
220  ROSE_DLL_API std::string generateGOMPLoopNextFuncName (bool isOrdered, SgOmpClause::omp_schedule_kind_enum s_kind);
221 
223  ROSE_DLL_API std::string toString(SgOmpClause::omp_schedule_kind_enum s_kind);
224 
226  ROSE_DLL_API int patchUpPrivateVariables(SgFile*);
227 
229  ROSE_DLL_API int patchUpPrivateVariables(SgStatement* omp_loop);
230 
232  ROSE_DLL_API int patchUpFirstprivateVariables(SgFile*);
233 
235  std::set<SgInitializedName*> collectThreadprivateVariables();
236 
238  SgVariableDeclaration * buildAndInsertDeclarationForOmp(const std::string &name, SgType *type, SgInitializer *varInit, SgBasicBlock *orig_scope);
241 
243  ROSE_DLL_API bool isInClauseVariableList(SgOmpClause* cls, SgSymbol* var);
244  ROSE_DLL_API bool isInUpirDataSharingList(SgOmpClause* data, SgSymbol* variable, SgOmpClause::upir_data_sharing_enum sharing_property);
245  ROSE_DLL_API bool isInUpirDataSharingList(SgUpirFieldBodyStatement* target, SgSymbol* variable, SgOmpClause::upir_data_sharing_enum sharing_property);
246  ROSE_DLL_API bool isInUpirDataSharingList(SgUpirFieldBodyStatement* target, SgSymbol* variable, std::set<SgOmpClause::upir_data_sharing_enum> sharing_property);
247  ROSE_DLL_API bool isInUpirDataList(SgUpirFieldBodyStatement* target, SgSymbol* variable);
248  ROSE_DLL_API SgUpirDataItemField* isInUpirDataList(SgOmpClause* target, SgSymbol* variable);
249 
251  ROSE_DLL_API bool isThreadprivate(SgSymbol* var);
252 
255  ROSE_DLL_API omp_construct_enum getDataSharingAttribute (SgSymbol* var, SgNode* anchor_node);
256 
258  ROSE_DLL_API omp_construct_enum getDataSharingAttribute (SgVarRefExp* varRef);
259 
261  ROSE_DLL_API bool isSharedAccess (SgVarRefExp* varRef);
262 
264  void extractMapClauses(Rose_STL_Container<SgOmpClause*> map_clauses,
265  std::map<SgSymbol*, std::vector< std::pair <SgExpression*, SgExpression*> > > & array_dimensions,
266  std::map<SgSymbol*, std::vector< std::pair< SgOmpClause::omp_map_dist_data_enum, SgExpression * > > > & dist_data_policies,
267  SgOmpMapClause** map_alloc_clause, SgOmpMapClause** map_to_clause, SgOmpMapClause** map_from_clause, SgOmpMapClause** map_tofrom_clause);
269  void categorizeMapClauseVariables( const SgInitializedNamePtrList & all_vars, // all variables collected from map clauses
270  std::map<SgSymbol*, std::vector < std::pair <SgExpression*, SgExpression*> > >& array_dimensions, // array bounds info as input
271  std::set<SgSymbol*>& array_syms, // variable symbols which are array types (explicit or as a pointer)
272  std::set<SgSymbol*>& atom_syms); // variable symbols which are non-aggregate types: scalar, pointer, etc
273 } // end namespace OmpSupport
274 
275 #endif //OMP_LOWERING_H
OmpSupport::translationDriver::visit
void visit(SgNode *)
this method is called at every traversed node.
OmpSupport::transOmpSimd
void transOmpSimd(SgNode *node)
Translate omp simd.
OmpSupport::generateGOMPLoopStartFuncName
ROSE_DLL_API std::string generateGOMPLoopStartFuncName(bool isOrdered, SgOmpClause::omp_schedule_kind_enum s_kind)
Generate GOMP loop schedule start function's name.
SgOmpMapClause
Definition: Cxx_Grammar.h:111837
OmpSupport::generateGOMPLoopNextFuncName
ROSE_DLL_API std::string generateGOMPLoopNextFuncName(bool isOrdered, SgOmpClause::omp_schedule_kind_enum s_kind)
Generate GOMP loop schedule next function's name.
SgOmpClause
Definition: Cxx_Grammar.h:79404
SgVariableSymbol
This class represents the concept of a variable name within the compiler (a shared container for the ...
Definition: Cxx_Grammar.h:321540
OmpSupport::getDataSharingAttribute
ROSE_DLL_API omp_construct_enum getDataSharingAttribute(SgSymbol *var, SgNode *anchor_node)
Return the data sharing attribute type of a variable, specified as a symbol and an anchor node (Must ...
OmpSupport::replaceVariableReferences
ROSE_DLL_API int replaceVariableReferences(SgNode *root, SgVariableSymbol *oldVar, SgVariableSymbol *newVar)
Replace references to oldVar within root with references to newVar, return the number of references r...
OmpSupport::transOmpMetadirective
void transOmpMetadirective(SgNode *node)
Translate omp metadirective.
OmpSupport::categorizeMapClauseVariables
void categorizeMapClauseVariables(const SgInitializedNamePtrList &all_vars, std::map< SgSymbol *, std::vector< std::pair< SgExpression *, SgExpression * > > > &array_dimensions, std::set< SgSymbol * > &array_syms, std::set< SgSymbol * > &atom_syms)
Categorize mapped variables.
OmpSupport::insertRTLHeaders
void insertRTLHeaders(SgSourceFile *)
Insert #include "xxx.h", the interface of a runtime library to the compiler.
SgUpirDataItemField
Definition: Cxx_Grammar.h:121270
OmpSupport::transOmpTargetData
void transOmpTargetData(SgNode *node)
Translate "omp target data".
SgOmpVariablesClause
Definition: Cxx_Grammar.h:104901
OmpSupport::transOmpFlush
void transOmpFlush(SgNode *node)
Translate omp flush.
OmpSupport::toString
std::string toString(omp_construct_enum omp_type)
Output omp_construct_enum to a string:
OmpSupport::hasClause
ROSE_DLL_API bool hasClause(SgStatement *clause_stmt, const VariantT &vt)
Check if an OpenMP statement has a clause of type vt.
SgVarRefExp
This class represents the variable refernece in expressions.
Definition: Cxx_Grammar.h:272706
OmpSupport::buildOmpVariableClause
ROSE_DLL_API SgOmpVariablesClause * buildOmpVariableClause(SgUpirFieldBodyStatement *clause_stmt, const VariantT &vt)
Build a non-reduction variable clause for a given OpenMP directive. It directly returns the clause if...
SgFile
This class represents a source file for a project (which may contian many source files and or directo...
Definition: Cxx_Grammar.h:21163
OmpSupport::removeClause
ROSE_DLL_API int removeClause(SgStatement *clause_stmt, const VariantT &vt)
Remove one or more clauses of type vt.
OmpSupport::transOmpCritical
void transOmpCritical(SgNode *node)
Translate omp critical.
SgType
This class represents the base class for all types.
Definition: Cxx_Grammar.h:43961
OmpSupport::isInClauseVariableList
ROSE_DLL_API bool isInClauseVariableList(SgInitializedName *var, SgUpirFieldBodyStatement *clause_stmt, const VariantT &vt)
Check if a variable is in a variable list of a given clause type.
OmpSupport::transOmpOrdered
void transOmpOrdered(SgNode *node)
Translate the ordered directive (not the ordered clause)
OmpSupport::getEnclosingRegionOrFuncDefinition
SgBasicBlock * getEnclosingRegionOrFuncDefinition(SgNode *)
Find an enclosing parallel region or function definition's body.
OmpSupport::transOmpSections
void transOmpSections(SgNode *node)
Translate omp sections.
SgBasicBlock
This class represents the concept of a block (not a basic block from control flow analysis).
Definition: Cxx_Grammar.h:124904
OmpSupport::transOmpUnroll
void transOmpUnroll(SgNode *node)
Translate omp unroll.
OmpSupport::transOmpParallel
void transOmpParallel(SgNode *node)
Translate omp parallel.
SgFunctionDeclaration
This class represents the concept of a function declaration statement.
Definition: Cxx_Grammar.h:155826
SgUpirFieldBodyStatement
Definition: Cxx_Grammar.h:195949
OmpSupport::addClauseVariable
ROSE_DLL_API void addClauseVariable(SgInitializedName *var, SgUpirFieldBodyStatement *clause_stmt, const VariantT &vt)
Add a variable into a non-reduction clause of an OpenMP statement, create the clause transparently if...
OmpSupport::buildAndInsertDeclarationForOmp
SgVariableDeclaration * buildAndInsertDeclarationForOmp(const std::string &name, SgType *type, SgInitializer *varInit, SgBasicBlock *orig_scope)
Special handling when trying to build and insert a variable declaration into a BB within Fortran Open...
OmpSupport::useStaticSchedule
ROSE_DLL_API bool useStaticSchedule(SgUpirFieldBodyStatement *omp_loop)
Check if an omp for/do loop use static schedule or not, including: default schedule,...
OmpSupport::createInitialValueExp
ROSE_DLL_API SgExpression * createInitialValueExp(SgOmpClause::omp_reduction_identifier_enum r_operator)
Create an initial value according to reduction operator type.
SgExpression
This class represents the notion of an expression. Expressions are derived from SgLocatedNodes,...
Definition: Cxx_Grammar.h:229045
OmpSupport::patchUpSharedVariables
int patchUpSharedVariables(SgFile *)
makeDataSharingExplicit() can call some of existing functions for some work in OmpSupport namespace b...
OmpSupport::transOmpTarget
void transOmpTarget(SgNode *node)
Translate Fortran omp do.
OmpSupport::transOmpBarrier
void transOmpBarrier(SgNode *node)
Translate omp barrier.
OmpSupport::isThreadprivate
ROSE_DLL_API bool isThreadprivate(SgSymbol *var)
Check if a variable is a threadprivate variable. It will search for all threadprivate directives to f...
AstSimpleProcessing
Class for traversing the AST.
Definition: AstSimpleProcessing.h:59
OmpSupport::patchUpFirstprivateVariables
ROSE_DLL_API int patchUpFirstprivateVariables(SgFile *)
Patch up firstprivate variables for omp task. The reason is that the specification 3....
OmpSupport::getReductionOperationType
ROSE_DLL_API SgOmpClause::omp_reduction_identifier_enum getReductionOperationType(SgInitializedName *init_name, SgUpirFieldBodyStatement *clause_stmt)
Return a reduction variable's reduction operation type.
SgNode
This class represents the base class for all IR nodes within Sage III.
Definition: Cxx_Grammar.h:6739
OmpSupport::transOmpLoop
void transOmpLoop(SgNode *node)
Translate omp for or omp do loops.
OmpSupport::transOmpMaster
void transOmpMaster(SgNode *node)
Translate omp master.
OmpSupport::patchUpPrivateVariables
ROSE_DLL_API int patchUpPrivateVariables(SgFile *)
Patch up private variables for omp for of entire file. The reason is that loop indices should be priv...
OmpSupport::lower_omp
void lower_omp(SgSourceFile *)
The top level interface to translate OpenMP directives.
SgInitializedName
This class represents the notion of a declared variable.
Definition: Cxx_Grammar.h:76851
variable
Definition: variables.h:40
OmpSupport
Types and functions to support OpenMP.
Definition: ompAstConstruction.h:6
OmpSupport::transOmpVariables
ROSE_DLL_API void transOmpVariables(SgStatement *ompStmt, SgBasicBlock *bb1, SgExpression *orig_loop_upper=NULL, bool withinAcceleratorModel=false)
Translate OpenMP variables associated with an OpenMP pragma, such as private, firstprivate,...
OmpSupport::transUpirLoopParallel
void transUpirLoopParallel(SgNode *node)
Translate UPIR parallel loops.
OmpSupport::translationDriver
A driver to traverse AST trees and invoke individual translators for OpenMP constructs,...
Definition: omp_lowering.h:70
OmpSupport::createUpirStatementTree
void createUpirStatementTree(SgSourceFile *file)
Analysis helpers.
SgSourceFile
Definition: Cxx_Grammar.h:22972
OmpSupport::insertRTLinitAndCleanCode
void insertRTLinitAndCleanCode(SgSourceFile *)
Insert runtime init and terminate routines to main() entry.
OmpSupport::generateOutlinedTask
SgFunctionDeclaration * generateOutlinedTask(SgNode *node, std::string &wrapper_name, std::set< const SgVariableSymbol * > &syms, std::set< const SgVariableSymbol * > &pdSyms3, bool use_task_param=false)
A helper function to generate implicit or explicit task for either omp parallel or omp task.
OmpSupport::transOmpTargetLoop
void transOmpTargetLoop(SgNode *node)
Translate omp for or omp do loops affected by the "omp target" directive, using naive 1-to-1 mapping ...
OmpSupport::transOmpThreadprivate
void transOmpThreadprivate(SgNode *node)
Translate omp threadprivate.
OmpSupport::isSharedAccess
ROSE_DLL_API bool isSharedAccess(SgVarRefExp *varRef)
Check if a variable access is a shared access , assuming it is already within an OpenMP region.
OmpSupport::extractMapClauses
void extractMapClauses(Rose_STL_Container< SgOmpClause * > map_clauses, std::map< SgSymbol *, std::vector< std::pair< SgExpression *, SgExpression * > > > &array_dimensions, std::map< SgSymbol *, std::vector< std::pair< SgOmpClause::omp_map_dist_data_enum, SgExpression * > > > &dist_data_policies, SgOmpMapClause **map_alloc_clause, SgOmpMapClause **map_to_clause, SgOmpMapClause **map_from_clause, SgOmpMapClause **map_tofrom_clause)
Extract map clause information.
SgVariableDeclaration
This class represents the concept of a C or C++ variable declaration.
Definition: Cxx_Grammar.h:138274
OmpSupport::transOmpTargetLoop_RoundRobin
void transOmpTargetLoop_RoundRobin(SgNode *node)
Translate omp for or omp do loops affected by the "omp target" directive, using a round robin-schedul...
OmpSupport::transOmpTaskwait
void transOmpTaskwait(SgNode *node)
Translate omp taskwait.
OmpSupport::transOmpAtomic
void transOmpAtomic(SgNode *node)
Translate omp atomic.
OmpSupport::transOmpSingle
void transOmpSingle(SgNode *node)
Translate omp single.
OmpSupport::getClauseExpression
ROSE_DLL_API SgExpression * getClauseExpression(SgStatement *clause_stmt, const VariantVector &vvt)
Collect expression from given types of OpenMP clauses associated with an omp statement: private,...
SgStatement
This class represents the notion of a statement.
Definition: Cxx_Grammar.h:122747
OmpSupport::collectAllClauseVariables
ROSE_DLL_API SgInitializedNamePtrList collectAllClauseVariables(SgUpirFieldBodyStatement *clause_stmt)
Collect all variables from OpenMP clauses associated with an omp statement: private,...
OmpSupport::collectClauseVariables
ROSE_DLL_API SgInitializedNamePtrList collectClauseVariables(SgUpirFieldBodyStatement *clause_stmt, const VariantT &vt)
Collect variables from a particular type of OpenMP clauses associated with an omp statement: private,...
OmpSupport::collectThreadprivateVariables
std::set< SgInitializedName * > collectThreadprivateVariables()
Collect threadprivate variables within the current project, return a set to avoid duplicated elements...
OmpSupport::transOmpTask
void transOmpTask(SgNode *node)
Translate omp task.
SgInitializer
This class represents the notion of an initializer for a variable declaration or expression in a func...
Definition: Cxx_Grammar.h:294701
OmpSupport::omp_rtl_enum
omp_rtl_enum
The type of target runtime libraries (not yet in use)
Definition: omp_lowering.h:41
OmpSupport::replaceVariablesWithPointerDereference
int replaceVariablesWithPointerDereference(SgNode *root, std::set< SgVariableSymbol * > &vars)
Replace all variable references in a set by pointers to the variable.
OmpSupport::transOmpTargetParallel
void transOmpTargetParallel(SgNode *node)
Translate omp parallel under "omp target".
SgSymbol
This class represents the concept of a name within the compiler.
Definition: Cxx_Grammar.h:321018
OmpSupport::transOmpTile
void transOmpTile(SgNode *node)
Translate omp tile.
OmpSupport::getClause
ROSE_DLL_API Rose_STL_Container< SgOmpClause * > getClause(SgStatement *clause_stmt, const VariantT &vt)
Get OpenMP clauses from an eligible OpenMP statement.