ROSE  0.9.9.109
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 "OmpAttribute.h"
8 
16 namespace OmpSupport
17 {
18  // OpenMP version info.
19  extern bool enable_accelerator;
20 
21  // A flag to control if device data environment runtime functions are used to automatically manage data as much as possible.
22  // instead of generating explicit data allocation, copy, free functions.
23  extern bool useDDE /* = true */;
26 
27 
29  // TODO: patchUpDefaultVariables(SgFile* );
30 
31  int makeDataSharingExplicit( SgFile* );
32 
33  // last edited by Hongyi on 07/24/2012.
34 
36  // We support both Omni and GCC OpenMP runtime libraries
38  {
39  e_gomp,
40  e_omni,
41  e_last_rtl
42  };
43  extern unsigned int nCounter; // translation generated variable counter, used to avoid name collision
44 
45  extern omp_rtl_enum rtl_type;
46  typedef std::map<const SgVariableSymbol *, SgVariableSymbol *> VariableSymbolMap_t;
47 
48  void commandLineProcessing(std::vector<std::string> &argvList);
49 
51  void lower_omp(SgSourceFile*);
52 
53 
56 
59 
60  //Pei-Hung Insert accelerator init
61  void insertAcceleratorInit(SgSourceFile* );
62 
66  {
67  protected:
68  void visit(SgNode*);
69  }; //translationDriver
70 
72  void transOmpParallel(SgNode* node);
73 
75  void transOmpTargetParallel(SgNode* node);
76 
78  void transOmpSections(SgNode* node);
79 
81  void transOmpTask(SgNode* node);
82 
84  void transOmpLoop(SgNode* node);
85 
87  // The loop iteration count may exceed the max number of threads within a CUDA thread block.
88  // A loop scheduler is needed for real application.
89  void transOmpTargetLoop(SgNode* node);
90 
93 
95  //void transOmpDo(SgNode* node);
96 
98  void transOmpTarget(SgNode* node);
99 
101  void transOmpTargetData(SgNode* node);
102 
103 
105  void transOmpBarrier(SgNode* node);
106 
108  void transOmpFlush(SgNode* node);
109 
111  void transOmpTaskwait(SgNode* node);
112 
114  void transOmpThreadprivate(SgNode* node);
115 
117  void transOmpOrdered(SgNode* node);
119  void transOmpAtomic(SgNode* node);
121  void transOmpCritical(SgNode* node);
123  void transOmpMaster(SgNode* node);
125  void transOmpSingle(SgNode* node);
126 
128  // It calls the ROSE AST outliner internally.
129  SgFunctionDeclaration* generateOutlinedTask(SgNode* node, std::string& wrapper_name, std::set<SgVariableSymbol*>& syms);
130 
132  ROSE_DLL_API void transOmpVariables(SgStatement * ompStmt, SgBasicBlock* bb1, SgExpression* orig_loop_upper = NULL, bool withinAcceleratorModel= false);
133 
135  ROSE_DLL_API SgInitializedNamePtrList collectAllClauseVariables (SgOmpClauseBodyStatement * clause_stmt);
136 
138  ROSE_DLL_API SgInitializedNamePtrList collectClauseVariables (SgOmpClauseBodyStatement * clause_stmt, const VariantT& vt);
139 
141  ROSE_DLL_API SgInitializedNamePtrList collectClauseVariables (SgOmpClauseBodyStatement * clause_stmt, const VariantVector& vvt);
142 
144  ROSE_DLL_API SgExpression* getClauseExpression (SgOmpClauseBodyStatement * clause_stmt, const VariantVector& vvt);
145 
147  ROSE_DLL_API bool isInClauseVariableList(SgInitializedName* var, SgOmpClauseBodyStatement * clause_stmt, const VariantT& vt);
148 
150  ROSE_DLL_API bool isInClauseVariableList(SgInitializedName* var, SgOmpClauseBodyStatement * clause_stmt, const VariantVector& vvt);
151 
153  ROSE_DLL_API int replaceVariableReferences(SgNode* root, SgVariableSymbol* oldVar, SgVariableSymbol* newVar);
154 
156  ROSE_DLL_API int replaceVariableReferences(SgNode* root, VariableSymbolMap_t varRemap);
157  // I decided to reuse the existing Outliner work instead of coding a new one
158  //SgFunctionDeclaration* generateOutlinedFunction(SgNode* node);
159 
161  int replaceVariablesWithPointerDereference(SgNode* root, std::set<SgVariableSymbol*>& vars);
162 
164  ROSE_DLL_API void addClauseVariable(SgInitializedName* var, SgOmpClauseBodyStatement * clause_stmt, const VariantT& vt);
165 
167  ROSE_DLL_API SgOmpVariablesClause* buildOmpVariableClause(SgOmpClauseBodyStatement * clause_stmt, const VariantT& vt);
168 
170  ROSE_DLL_API int removeClause (SgOmpClauseBodyStatement * clause_stmt, const VariantT& vt);
171 
173  ROSE_DLL_API bool hasClause(SgOmpClauseBodyStatement* clause_stmt, const VariantT & vt);
174 
176  ROSE_DLL_API Rose_STL_Container<SgOmpClause*> getClause(SgOmpClauseBodyStatement* clause_stmt, const VariantT & vt);
177 
179  ROSE_DLL_API bool useStaticSchedule(SgOmpClauseBodyStatement* omp_loop);
180 
182  ROSE_DLL_API SgOmpClause::omp_reduction_operator_enum getReductionOperationType(SgInitializedName* init_name, SgOmpClauseBodyStatement* clause_stmt);
183 
185  ROSE_DLL_API SgExpression* createInitialValueExp(SgOmpClause::omp_reduction_operator_enum r_operator);
186 
188  ROSE_DLL_API std::string generateGOMPLoopStartFuncName (bool isOrdered, SgOmpClause::omp_schedule_kind_enum s_kind);
189 
191  ROSE_DLL_API std::string generateGOMPLoopNextFuncName (bool isOrdered, SgOmpClause::omp_schedule_kind_enum s_kind);
192 
194  ROSE_DLL_API std::string toString(SgOmpClause::omp_schedule_kind_enum s_kind);
195 
197  ROSE_DLL_API int patchUpPrivateVariables(SgFile*);
198 
200  ROSE_DLL_API int patchUpPrivateVariables(SgStatement* omp_loop);
201 
203  ROSE_DLL_API int patchUpFirstprivateVariables(SgFile*);
204 
206  std::set<SgInitializedName*> collectThreadprivateVariables();
207 
209  SgVariableDeclaration * buildAndInsertDeclarationForOmp(const std::string &name, SgType *type, SgInitializer *varInit, SgBasicBlock *orig_scope);
212 
214  ROSE_DLL_API bool isInClauseVariableList(SgOmpClause* cls, SgSymbol* var);
215 
217  ROSE_DLL_API bool isThreadprivate(SgSymbol* var);
218 
221  ROSE_DLL_API omp_construct_enum getDataSharingAttribute (SgSymbol* var, SgNode* anchor_node);
222 
224  ROSE_DLL_API omp_construct_enum getDataSharingAttribute (SgVarRefExp* varRef);
225 
227  void extractMapClauses(Rose_STL_Container<SgOmpClause*> map_clauses,
228  std::map<SgSymbol*, std::vector< std::pair <SgExpression*, SgExpression*> > > & array_dimensions,
229  std::map<SgSymbol*, std::vector< std::pair< SgOmpClause::omp_map_dist_data_enum, SgExpression * > > > & dist_data_policies,
230  SgOmpMapClause** map_alloc_clause, SgOmpMapClause** map_to_clause, SgOmpMapClause** map_from_clause, SgOmpMapClause** map_tofrom_clause);
232  void categorizeMapClauseVariables( const SgInitializedNamePtrList & all_vars, // all variables collected from map clauses
233  std::map<SgSymbol*, std::vector < std::pair <SgExpression*, SgExpression*> > >& array_dimensions, // array bounds info as input
234  std::set<SgSymbol*>& array_syms, // variable symbols which are array types (explicit or as a pointer)
235  std::set<SgSymbol*>& atom_syms); // variable symbols which are non-aggregate types: scalar, pointer, etc
236 } // end namespace OmpSupport
237 
238 #endif //OMP_LOWERING_H
ROSE_DLL_API int patchUpFirstprivateVariables(SgFile *)
Patch up firstprivate variables for omp task. The reason is that the specification 3...
This class represents the notion of an initializer for a variable declaration or expression in a func...
void transOmpMaster(SgNode *node)
Translate omp master.
This class represents a source file for a project (which may contian many source files and or directo...
Class for traversing the AST.
void transOmpBarrier(SgNode *node)
Translate omp barrier.
ROSE_DLL_API SgOmpClause::omp_reduction_operator_enum getReductionOperationType(SgInitializedName *init_name, SgOmpClauseBodyStatement *clause_stmt)
Return a reduction variable's reduction operation type.
This class represents the base class for all types.
ROSE_DLL_API SgInitializedNamePtrList collectAllClauseVariables(SgOmpClauseBodyStatement *clause_stmt)
Collect all variables from OpenMP clauses associated with an omp statement: private, reduction, etc.
void lower_omp(SgSourceFile *)
The top level interface to translate OpenMP directives.
ROSE_DLL_API SgInitializedNamePtrList collectClauseVariables(SgOmpClauseBodyStatement *clause_stmt, const VariantT &vt)
Collect variables from a particular type of OpenMP clauses associated with an omp statement: private...
std::set< SgInitializedName * > collectThreadprivateVariables()
Collect threadprivate variables within the current project, return a set to avoid duplicated elements...
void transOmpTask(SgNode *node)
Translate omp task.
int replaceVariablesWithPointerDereference(SgNode *root, std::set< SgVariableSymbol * > &vars)
Replace all variable references in a set by pointers to the variable.
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.
void transOmpThreadprivate(SgNode *node)
Translate omp threadprivate.
This class represents the notion of a declared variable.
This class represents the concept of a function declaration statement.
void transOmpLoop(SgNode *node)
Translate omp for or omp do loops.
void insertRTLinitAndCleanCode(SgSourceFile *)
Insert runtime init and terminate routines to main() entry.
void transOmpTargetLoop_RoundRobin(SgNode *node)
Translate omp for or omp do loops affected by the "omp target" directive, using a round robin-schedul...
ROSE_DLL_API bool isThreadprivate(SgSymbol *var)
Check if a variable is a threadprivate variable. It will search for all threadprivate directives to f...
void transOmpTargetParallel(SgNode *node)
Translate omp parallel under "omp target".
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, lastprivate, reduction, etc. bb1 is the translation generated code block in which the variable handling statements will be inserted. Original loop upper bound is needed for implementing lastprivate (check if it is the last iteration). withinAcceleratorModel means if we only translate private() variables, used to support accelerator model.
void transOmpAtomic(SgNode *node)
Translate omp atomic.
This class represents the notion of an expression. Expressions are derived from SgLocatedNodes, since similar to statement, expressions have a concrete location within the user's source code.
ROSE_DLL_API bool isInClauseVariableList(SgInitializedName *var, SgOmpClauseBodyStatement *clause_stmt, const VariantT &vt)
Check if a variable is in a variable list of a given clause type.
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...
This class represents the concept of a name within the compiler.
A driver to traverse AST trees and invoke individual translators for OpenMP constructs, (not in use) Postorder is preferred.
Definition: omp_lowering.h:65
ROSE_DLL_API int removeClause(SgOmpClauseBodyStatement *clause_stmt, const VariantT &vt)
Remove one or more clauses of type vt.
void transOmpTaskwait(SgNode *node)
Translate omp taskwait.
void transOmpTargetLoop(SgNode *node)
Translate omp for or omp do loops affected by the "omp target" directive, using naive 1-to-1 mapping ...
This class represents the base class for all IR nodes within Sage III.
Definition: Cxx_Grammar.h:8322
SgFunctionDeclaration * generateOutlinedTask(SgNode *node, std::string &wrapper_name, std::set< SgVariableSymbol * > &syms)
A helper function to generate implicit or explicit task for either omp parallel or omp task...
This class represents the concept of a variable name within the compiler (a shared container for the ...
omp_rtl_enum
The type of target runtime libraries (not yet in use)
Definition: omp_lowering.h:37
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...
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.
This class represents the concept of a block (not a basic block from control flow analysis)...
This class represents the notion of a statement.
void transOmpSingle(SgNode *node)
Translate omp single.
void transOmpCritical(SgNode *node)
Translate omp critical.
ROSE_DLL_API std::string generateGOMPLoopStartFuncName(bool isOrdered, SgOmpClause::omp_schedule_kind_enum s_kind)
Generate GOMP loop schedule start function's name.
void insertRTLHeaders(SgSourceFile *)
Insert #include "xxx.h", the interface of a runtime library to the compiler.
ROSE_DLL_API std::string generateGOMPLoopNextFuncName(bool isOrdered, SgOmpClause::omp_schedule_kind_enum s_kind)
Generate GOMP loop schedule next function's name.
ROSE_DLL_API bool hasClause(SgOmpClauseBodyStatement *clause_stmt, const VariantT &vt)
Check if an OpenMP statement has a clause of type vt.
void transOmpOrdered(SgNode *node)
Translate the ordered directive (not the ordered clause)
void transOmpFlush(SgNode *node)
Translate omp flush.
SgBasicBlock * getEnclosingRegionOrFuncDefinition(SgNode *)
Find an enclosing parallel region or function definition's body.
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 ...
This class represents the variable refernece in expressions.
Types and functions to support OpenMP.
int patchUpSharedVariables(SgFile *)
makeDataSharingExplicit() can call some of existing functions for some work in OmpSupport namespace b...
void transOmpTargetData(SgNode *node)
Translate "omp target data".
std::string toString(omp_construct_enum omp_type)
Output omp_construct_enum to a string:
void transOmpSections(SgNode *node)
Translate omp sections.
ROSE_DLL_API void addClauseVariable(SgInitializedName *var, SgOmpClauseBodyStatement *clause_stmt, const VariantT &vt)
Add a variable into a non-reduction clause of an OpenMP statement, create the clause transparently if...
ROSE_DLL_API Rose_STL_Container< SgOmpClause * > getClause(SgOmpClauseBodyStatement *clause_stmt, const VariantT &vt)
Get OpenMP clauses from an eligible OpenMP statement.
ROSE_DLL_API SgExpression * getClauseExpression(SgOmpClauseBodyStatement *clause_stmt, const VariantVector &vvt)
Collect expression from given types of OpenMP clauses associated with an omp statement: private...
void transOmpParallel(SgNode *node)
Translate omp parallel.
This class represents the concept of a C or C++ variable declaration.
void transOmpTarget(SgNode *node)
Translate Fortran omp do.
void visit(SgNode *)
this method is called at every traversed node.
ROSE_DLL_API bool useStaticSchedule(SgOmpClauseBodyStatement *omp_loop)
Check if an omp for/do loop use static schedule or not, including: default schedule, or schedule(static[,chunk_size])
ROSE_DLL_API SgOmpVariablesClause * buildOmpVariableClause(SgOmpClauseBodyStatement *clause_stmt, const VariantT &vt)
Build a non-reduction variable clause for a given OpenMP directive. It directly returns the clause if...
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...
ROSE_DLL_API SgExpression * createInitialValueExp(SgOmpClause::omp_reduction_operator_enum r_operator)
Create an initial value according to reduction operator type.