00001
00009
00010
00011
00012
00013 #include <iostream>
00014 #include <string>
00015 #include <map>
00016 #include <cassert>
00017 #include <vector>
00018 class SgNode;
00019 namespace OmpSupport
00020 {
00021
00022
00023
00024
00025
00026 enum omp_construct_enum
00027 {
00028 e_unknown = 0,
00029
00030
00031 e_parallel,
00032 e_for,
00033 e_do,
00034 e_workshare,
00035 e_sections,
00036 e_section,
00037 e_single,
00038
00039 e_master,
00040 e_critical,
00041 e_barrier,
00042 e_atomic,
00043 e_flush,
00044
00045 e_threadprivate,
00046 e_parallel_for,
00047 e_parallel_do,
00048 e_parallel_sections,
00049 e_parallel_workshare,
00050 e_task,
00051 e_taskwait,
00052
00053
00054 e_ordered_directive,
00055
00056
00057 e_end_critical,
00058 e_end_do,
00059 e_end_master,
00060 e_end_ordered,
00061 e_end_parallel_do,
00062 e_end_parallel_sections,
00063 e_end_parallel_workshare,
00064 e_end_parallel,
00065 e_end_sections,
00066 e_end_single,
00067 e_end_task,
00068 e_end_workshare,
00069
00070
00071
00072 e_default,
00073 e_shared,
00074 e_private,
00075 e_firstprivate,
00076 e_lastprivate,
00077 e_copyin,
00078 e_copyprivate,
00079
00080
00081 e_if,
00082 e_num_threads,
00083 e_nowait,
00084 e_ordered_clause,
00085 e_reduction,
00086 e_schedule,
00087 e_collapse,
00088 e_untied,
00089
00090
00091
00092
00093
00094 e_default_none,
00095 e_default_shared,
00096
00097 e_default_private,
00098 e_default_firstprivate,
00099
00100
00101
00102
00103 e_reduction_plus,
00104 e_reduction_mul,
00105 e_reduction_minus,
00106
00107 e_reduction_bitand,
00108 e_reduction_bitor,
00109 e_reduction_bitxor,
00110 e_reduction_logand,
00111 e_reduction_logor,
00112
00113
00114 e_reduction_and,
00115 e_reduction_or,
00116 e_reduction_eqv,
00117 e_reduction_neqv,
00118
00119 e_reduction_max,
00120 e_reduction_min,
00121 e_reduction_iand,
00122 e_reduction_ior,
00123 e_reduction_ieor,
00124
00125
00126
00127 e_schedule_none,
00128 e_schedule_static,
00129 e_schedule_dynamic,
00130 e_schedule_guided,
00131 e_schedule_auto,
00132 e_schedule_runtime,
00133
00134
00135 e_not_omp
00136 };
00137
00138
00139
00140
00142
00143 std::string toString(omp_construct_enum omp_type);
00144
00146 bool isFortranEndDirective(omp_construct_enum omp_type);
00147
00149 bool isFortranBeginDirective(omp_construct_enum omp_type);
00150
00152 bool isDirective(omp_construct_enum omp_type);
00153
00155 bool isDirectiveWithBody(omp_construct_enum omp_type);
00156
00158 bool isClause(omp_construct_enum omp_type);
00159
00161 bool isReductionOperator(omp_construct_enum omp_type);
00162
00163 class OmpAttribute;
00165
00167 OmpAttribute* buildOmpAttribute(enum omp_construct_enum directive_type, SgNode* context_node, bool useDefined);
00168
00170 void addOmpAttribute(OmpAttribute* ompattribute, SgNode* node);
00171
00173 void removeOmpAttribute(OmpAttribute* ompattribute, SgNode* node);
00174
00176 bool isEquivalentOmpAttribute (OmpAttribute* a1, OmpAttribute* a2);
00177
00178 class OmpAttributeList;
00180 OmpAttributeList* getOmpAttributeList(SgNode* node);
00181
00183 OmpAttribute* getOmpAttribute(SgNode* node);
00184
00186 omp_construct_enum getOmpConstructEnum(SgPragmaDeclaration* decl);
00187
00189 omp_construct_enum getBeginOmpConstructEnum (omp_construct_enum end_enum);
00190
00192 omp_construct_enum getEndOmpConstructEnum (omp_construct_enum begin_enum);
00193
00195 void generatePragmaFromOmpAttribute(SgNode* sg_node);
00196
00197
00198
00200 std::string generateDiffTextFromOmpAttribute(SgNode* sg_node);
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220 class OmpAttributeList :public AstAttribute
00221 {
00222 public:
00223 std::vector<OmpAttribute*> ompAttriList;
00224
00225 std::string toOpenMPString();
00226
00227 void print();
00228 ~OmpAttributeList();
00229 };
00230
00231 class OmpAttribute
00232 {
00233 public:
00236 SgPragmaDeclaration* getPragmaDeclaration();
00237
00239 PreprocessingInfo* getPreprocessingInfo() {return pinfo;};
00240 void setPreprocessingInfo(PreprocessingInfo* info) { pinfo=info;};
00241
00243 SgNode* getNode(){return mNode;};
00244 void setNode(SgNode* n) { mNode= n;};
00246 void setOmpDirectiveType(omp_construct_enum omptype){ assert (isDirective(omptype)); omp_type = omptype;}
00247 omp_construct_enum getOmpDirectiveType() {return omp_type;}
00248
00251 void addClause(omp_construct_enum clause_type);
00253 bool hasClause(omp_construct_enum clause_type);
00254
00256 std::vector<omp_construct_enum> getClauses();
00257
00260 void addVariable(omp_construct_enum targetConstruct, const std::string& varString,SgInitializedName* sgvar=NULL);
00262 bool hasVariableList(omp_construct_enum);
00264 std::vector<std::pair<std::string,SgNode* > >
00265 getVariableList(omp_construct_enum);
00266
00268 std::vector<enum omp_construct_enum> get_clauses(const std::string& variable);
00269
00272 void addExpression(omp_construct_enum targetConstruct, const std::string& expString, SgExpression* sgexp=NULL);
00273
00275 std::pair<std::string, SgExpression*>
00276 getExpression(omp_construct_enum targetConstruct);
00277
00279
00280
00281
00282
00283
00284 void setReductionOperator(omp_construct_enum operatorx);
00286 std::vector<omp_construct_enum> getReductionOperators();
00288 bool hasReductionOperator(omp_construct_enum operatorx);
00289
00290
00291 void setDefaultValue(omp_construct_enum valuex);
00292 omp_construct_enum getDefaultValue();
00293
00294
00295 omp_construct_enum getScheduleKind();
00296 void setScheduleKind(omp_construct_enum kindx);
00297
00299 bool isInConstruct(const std::string & variable, enum omp_construct_enum);
00300
00302 void setCriticalName(const std::string & name);
00303 std::string getCriticalName() {return name;};
00304 bool isNamedCritical(){return hasName;};
00305
00307 void print();
00308
00310 bool get_isUserDefined() {return isUserDefined; }
00311
00313
00314 std::string toOpenMPString();
00315 friend OmpAttribute* buildOmpAttribute(omp_construct_enum directive_type, SgNode* node, bool userDefined);
00316
00317
00318 private:
00319
00320
00322 OmpAttribute()
00323 {
00324 mNode = NULL;
00325 omp_type = e_unknown;
00326 init();
00327 isUserDefined = true;
00328 }
00330 OmpAttribute(omp_construct_enum omptype, SgNode* mynode):
00331 mNode(mynode),omp_type(omptype){
00332
00333
00334 init();
00335 isUserDefined = true;
00336 if (mNode != NULL )
00337 {
00338 SgLocatedNode * lnode = isSgLocatedNode (mNode);
00339 ROSE_ASSERT (lnode != NULL);
00340
00341 }
00342
00343
00344
00345 }
00346
00348 SgNode* mNode;
00350 PreprocessingInfo* pinfo;
00351
00353 bool isUserDefined;
00354
00356 enum omp_construct_enum omp_type;
00357
00359
00360
00361
00362 std::vector<omp_construct_enum> clauses;
00363 std::map<omp_construct_enum,bool> clause_map;
00364
00365
00366
00367 std::vector<omp_construct_enum> reduction_operators;
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377 std::map<omp_construct_enum, std::vector<std::pair<std::string,SgNode* > > > variable_lists;
00378
00379 std::map<std::string, std::vector<omp_construct_enum> > var_clauses;
00380
00381
00382
00383 std::map<omp_construct_enum, std::pair<std::string, SgExpression*> > expressions;
00384
00385
00386
00387
00388 omp_construct_enum default_scope;
00389
00390
00391 omp_construct_enum schedule_kind;
00392
00393
00394
00395 bool hasName;
00396 std::string name;
00397
00398
00399
00400 bool isOrphaned;
00401
00402
00403 int wrapperCount;
00404
00405
00406 OmpAttribute * parent;
00407
00410 void init() ;
00411
00413
00414 std::string toOpenMPString(omp_construct_enum omp_type);
00415
00417 std::string toOpenMPString(std::vector<std::pair<std::string,SgNode* > >);
00418 };
00419
00420
00421
00422
00423 extern std::list<OmpAttribute* > omp_comment_list;
00424
00425
00426 }