ROSE  0.11.96.11
ompSupport.h
1 #ifndef Omp_Support_h_INCLUDED
2 #define Omp_Support_h_INCLUDED
3 
11 //
12 // Liao 9/17, 2008
13 //
14 
15 #include <iostream>
16 #include <string>
17 #include <map>
18 #include <cassert>
19 #include <vector>
20 #include <deque>
21 class SgNode;
25 namespace OmpSupport
26 {
27  // OpenMP construct name list
28  //-------------------------------------------------------------------
29  // We put all directive and clause types into one enumerate type
30  // since some internal data structure(map) have to access
31  // both directives and clauses uniformly
32  enum omp_construct_enum
33  {
34  e_unknown = 0,
35 
36  // 16 directives as OpenMP 3.0
37  e_parallel,
38  e_for,
39  e_for_simd,
40  e_do,
41  e_workshare,
42  e_sections,
43  e_section,
44  e_single,
45 
46  e_master,
47  e_critical,
48  e_barrier,
49  e_atomic,
50  e_flush,
51 
52  // Liao, 1/15/2013, experimental implementation for the draft OpenMP Accelerator Model technical report
53  e_target,
54  e_target_declare,
55  e_target_data,
56  e_target_update,
57  e_map, // map clauses
58  e_device,
59  e_begin, // 10/29/2015, experimental begin/end directives for SPMD code blocks, without changing variable scopes
60  e_end,
61 
62  e_threadprivate,
63  e_parallel_for,
64  e_parallel_for_simd,
65  e_parallel_do,
66  e_parallel_sections,
67  e_parallel_workshare,
68  e_task,
69  e_taskwait,
70  // we have both ordered directive and ordered clause,
71  //so make the name explicit
72  e_ordered_directive,
73 
74  // Fortran only end directives
75  e_end_critical,
76  e_end_do,
77  e_end_master,
78  e_end_ordered,
79  e_end_parallel_do,
80  e_end_parallel_sections,
81  e_end_parallel_workshare,
82  e_end_parallel,
83  e_end_sections,
84  e_end_single,
85  e_end_task,
86  e_end_workshare,
87 
88  // 15 clauses for OpenMP 3.0
89  // 7 data-sharing attributes clauses
90  e_default, // the clause
91  e_shared,
92  e_private,
93  e_firstprivate,
94  e_lastprivate,
95  e_copyin,
96  e_copyprivate,
97  e_proc_bind,
98 
99  //8 misc clauses
100  e_if, // used with omp parallel or omp task
101  e_num_threads, // for omp parallel only
102  e_nowait,
103  e_ordered_clause,
104  e_reduction,
105  e_schedule,
106  e_collapse,
107  e_untied,
108  e_mergeable,
109  e_final,
110  e_priority,
111  e_atomic_clause,
112  e_inbranch,
113  e_notinbranch,
114 
115  e_depend, // OpenMP 4.0 task clauses
116 
117  // Simple values for some clauses
118 
119  //4 values for default clause
120  //C/C++ default values
121  e_default_none,
122  e_default_shared,
123  //Fortran default values
124  e_default_private,
125  e_default_firstprivate,
126 
127  // proc_bind(master|close|spread)
128  e_proc_bind_master,
129  e_proc_bind_close,
130  e_proc_bind_spread,
131 
132  e_atomic_read,
133  e_atomic_write,
134  e_atomic_update,
135  e_atomic_capture,
136 
137  // in_reduction operations
138  e_in_reduction_identifier_plus, //+
139  e_in_reduction_identifier_mul, //*
140  e_in_reduction_identifier_minus, // -
141  e_in_reduction_identifier_bitand, // &
142  e_in_reduction_identifier_bitor, // |
143  e_in_reduction_identifier_bitxor, // ^
144  e_in_reduction_identifier_logand, // &&
145  e_in_reduction_identifier_logor, // ||
146  e_in_reduction_identifier_and, // .and.
147  e_in_reduction_identifier_or, // .or.
148  e_in_reduction_identifier_eqv, // fortran .eqv.
149  e_in_reduction_identifier_neqv, // fortran .neqv.
150  e_in_reduction_identifier_max,
151  e_in_reduction_identifier_min,
152  e_in_reduction_identifier_iand,
153  e_in_reduction_identifier_ior,
154  e_in_reduction_identifier_ieor,
155 
156  // task_reduction operations
157  e_task_reduction_identifier_plus, //+
158  e_task_reduction_identifier_mul, //*
159  e_task_reduction_identifier_minus, // -
160  e_task_reduction_identifier_bitand, // &
161  e_task_reduction_identifier_bitor, // |
162  e_task_reduction_identifier_bitxor, // ^
163  e_task_reduction_identifier_logand, // &&
164  e_task_reduction_identifier_logor, // ||
165  e_task_reduction_identifier_and, // .and.
166  e_task_reduction_identifier_or, // .or.
167  e_task_reduction_identifier_eqv, // fortran .eqv.
168  e_task_reduction_identifier_neqv, // fortran .neqv.
169  e_task_reduction_identifier_max,
170  e_task_reduction_identifier_min,
171  e_task_reduction_identifier_iand,
172  e_task_reduction_identifier_ior,
173  e_task_reduction_identifier_ieor,
174 
175  // reduction operations
176  //8 operand for C/C++
177  // shared 3 common operators for both C and Fortran
178  e_reduction_plus, //+
179  e_reduction_mul, //*
180  e_reduction_minus, // -
181 
182  // C/C++ only
183  e_reduction_bitand, // &
184  e_reduction_bitor, // |
185  e_reduction_bitxor, // ^
186  e_reduction_logand, // &&
187  e_reduction_logor, // ||
188 
189  // Fortran operator
190  e_reduction_and, // .and.
191  e_reduction_or, // .or.
192  e_reduction_eqv, // fortran .eqv.
193  e_reduction_neqv, // fortran .neqv.
194 
195  // reduction intrinsic procedure name for Fortran
196  // min, max also for C
197  e_reduction_max,
198  e_reduction_min,
199 
200  e_reduction_iand,
201  e_reduction_ior,
202  e_reduction_ieor,
203 
204  // reduction modifiers in OpenMP 5.0
205  e_reduction_inscan,
206  e_reduction_task,
207  e_reduction_default,
208 
209  // lastprivate modifiers in OpenMP 5.0
210  e_lastprivate_conditional,
211 
212  // device modifiers in OpenMP 5.0
213  e_device_ancestor,
214  e_device_device_num,
215 
216  // linear modifiers in OpenMP 5.0
217  e_linear_ref,
218  e_linear_val,
219  e_linear_uval,
220 
221  // enum for all the user defined parameters
222  e_user_defined_parameter,
223 
224  //5 schedule policies for
225  //---------------------
226  e_schedule_none,
227  e_schedule_static,
228  e_schedule_dynamic,
229  e_schedule_guided,
230  e_schedule_auto,
231  e_schedule_runtime,
232 
233  // 4 device map variants
234  //----------------------
235  e_map_alloc,
236  e_map_to,
237  e_map_from,
238  e_map_tofrom,
239 
240  // experimental dist_data clause dist_data(dim1_policy, dim2_policy, dim3_policy)
241  // A policy can be block(n), cyclic(n), or duplicate
242  e_dist_data,
243  e_duplicate,
244  e_block,
245  e_cyclic,
246 
247  // experimental SIMD directive, phlin 8/5/2013
248  e_simd,
249  e_declare_simd,
250  e_safelen,
251  e_simdlen,
252  e_uniform,
253  e_aligned,
254  e_linear,
255 
256  // task dependence type
257  e_depend_in,
258  e_depend_out,
259  e_depend_inout,
260  e_depend_mutexinoutset,
261  e_depend_depobj,
262 
263  // task depend modifier
264  e_omp_depend_modifier_iterator,
265 
266  // OpenMP 5.0 clause
267  e_allocate,
268  e_allocate_default_mem_alloc,
269  e_allocate_large_cap_mem_alloc,
270  e_allocate_const_mem_alloc,
271  e_allocate_high_bw_mem_alloc,
272  e_allocate_low_lat_mem_alloc,
273  e_allocate_cgroup_mem_alloc,
274  e_allocate_pteam_mem_alloc,
275  e_allocate_thread_mem_alloc,
276 
277  // not an OpenMP construct
278  e_not_omp
279 
280  }; //end omp_construct_enum
281 
282  // A new variable to communicate the context of OpenMP parser
283  // what directive is being parsed right now.
284  // This is useful for rare case of parsing "declare simd"
285  extern omp_construct_enum cur_omp_directive;
286 
287  //-------------------------------------------------------------------
288  // some utility functions
289 
291  // Better using OmpSupport::toString() to avoid ambiguous
292  std::string toString(omp_construct_enum omp_type);
293 
295  bool isFortranEndDirective(omp_construct_enum omp_type);
296 
298  bool isFortranBeginDirective(omp_construct_enum omp_type);
299 
301  bool isDirective(omp_construct_enum omp_type);
302 
304  bool isDirectiveWithBody(omp_construct_enum omp_type);
305 
307  bool isClause(omp_construct_enum omp_type);
308 
310  bool isReductionOperator(omp_construct_enum omp_type);
311 
313  bool isDependenceType(omp_construct_enum omp_type);
314 
315  // We use objects of this class to store parameters of those clauses that take one or two additional
316  // parameters other than variable or expression list. E.g. reduction([reduction_modifier,]reduction_identifier:list).
317  // We call this kind of clause as ComplexClause, compared with other clauses which just take one parameter or a list
318  // of variable/expression.
320 
321  public:
322  omp_construct_enum clause_type;
323  omp_construct_enum first_parameter;
324  omp_construct_enum second_parameter;
325  omp_construct_enum third_parameter;
326  std::pair < std::string, SgExpression* > user_defined_parameter;
327  std::pair < std::string, SgExpression* > expression;
328  std::vector < std::pair < std::string, SgNode* > > variable_list;
329 
330  ComplexClause(omp_construct_enum first=e_unknown, omp_construct_enum second=e_unknown, omp_construct_enum third=e_unknown) : first_parameter(first), second_parameter(second), third_parameter(third) {};
331 
332  };
333 
334  // We reuse the list later on to build OpenMP AST for Fortran
335 } //end namespace OmpSupport
336 
337 #endif //Omp_Support_h_INCLUDED
338 
OmpSupport::ComplexClause
Definition: ompSupport.h:319
OmpSupport::isFortranBeginDirective
bool isFortranBeginDirective(omp_construct_enum omp_type)
Check if the construct is a Fortran directive which can (optionally) have a corresponding END directi...
OmpSupport::isDirective
bool isDirective(omp_construct_enum omp_type)
Check if an OpenMP construct is a directive.
OmpSupport::isFortranEndDirective
bool isFortranEndDirective(omp_construct_enum omp_type)
Check if the construct is a Fortran END ... directive.
OmpSupport::toString
std::string toString(omp_construct_enum omp_type)
Output omp_construct_enum to a string:
OmpSupport::isDirectiveWithBody
bool isDirectiveWithBody(omp_construct_enum omp_type)
Check if an OpenMP directive has a structured body.
SgNode
This class represents the base class for all IR nodes within Sage III.
Definition: Cxx_Grammar.h:6739
OmpSupport
Types and functions to support OpenMP.
Definition: ompAstConstruction.h:6
OmpSupport::isDependenceType
bool isDependenceType(omp_construct_enum omp_type)
Check if an OpenMP construct is a dependence type for omp task depend.
OmpSupport::isClause
bool isClause(omp_construct_enum omp_type)
Check if an OpenMP construct is a clause.
OmpSupport::isReductionOperator
bool isReductionOperator(omp_construct_enum omp_type)
Check if an OpenMP construct is a reduction operator.