00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "defs.h"
00025 #include "glob.h"
00026 #include "config.h"
00027 #include "wn.h"
00028 #include "wn_util.h"
00029
00030 #include "gnu_config.h"
00031 #include "system.h"
00032
00033 #include "srcpos.h"
00034 #include "tree.h"
00035
00036 #include "wfe_expr.h"
00037 #include "wfe_misc.h"
00038 #include "omp_types.h"
00039 #include "omp_directive.h"
00040 #include "wfe_omp_directives.h"
00041 #include "wfe_omp_check_stack.h"
00042
00043 #include <stdio.h>
00044 #include "errors.h"
00045 #include "const.h"
00046
00048
00049
00050
00051
00052
00053 tree
00054 chainon (tree op1, tree op2)
00055 {
00056
00057 if (op1)
00058 {
00059 register tree t1;
00060
00061 for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1));
00062
00063 TREE_CHAIN (t1) = op2;
00064 return op1;
00065 }
00066 else return op2;
00067 }
00068
00069
00070
00071
00072 void
00073 print_tree (FILE *file, tree node)
00074 {
00075 print_node_brief (file, "", node, 0);
00076
00077 fprintf (file, "\n");
00078 }
00079
00080
00081 void
00082 print_node_brief (FILE *file, const char *prefix, tree node, int indent)
00083 {
00084 char class1;
00085
00086 if (node == 0)
00087 return;
00088
00089 class1 = TREE_CODE_CLASS (TREE_CODE (node));
00090
00091
00092
00093 if (indent > 0)
00094 fprintf (file, " ");
00095 fprintf (file, "%s <%s ", prefix, tree_code_name[(int) TREE_CODE (node)]);
00096 fprintf (file, HOST_PTR_PRINTF, (char *) node);
00097
00098 if (class1 == 'd')
00099 {
00100 if (DECL_NAME (node))
00101 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
00102 }
00103 else if (class1 == 't')
00104 {
00105 if (TYPE_NAME (node))
00106 {
00107 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
00108 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
00109 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
00110 && DECL_NAME (TYPE_NAME (node)))
00111 fprintf (file, " %s",
00112 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
00113 }
00114 }
00115 if (TREE_CODE (node) == IDENTIFIER_NODE)
00116 fprintf (file, " %s", IDENTIFIER_POINTER (node));
00117
00118 fprintf (file, ">");
00119
00120 if (TREE_CODE (node) == TREE_LIST)
00121 {
00122 print_node_brief (file, "purpose", TREE_PURPOSE (node), indent + 4);
00123 print_node_brief (file, "value", TREE_VALUE (node), indent + 4);
00124 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
00125 }
00126 }
00127
00128
00129
00130
00131
00132 inline ST *
00133 Get_Pre_ST (tree name)
00134 {
00135 if (name!=NULL)
00136 return WN_st( WFE_Expand_Expr(name));
00137 else
00138 {
00139 SRCPOS srcpos = Get_Srcpos();
00140 WFE_CS_push(wfe_omp_master,SRCPOS_linenum(srcpos), SRCPOS_filenum(srcpos));
00141
00142 Fail_FmtAssertion("Undeclared variable name at line %d file %d \n",
00143 SRCPOS_linenum(srcpos), SRCPOS_filenum(srcpos));
00144 return NULL;
00145 }
00146 }
00147
00148 extern "C"{
00149
00150
00152
00153 void prepare_com_clause ( tree clause_tree, ST_list * * clause_st )
00154 {
00155 register tree t = NULL;
00156 ST *st = NULL;
00157 ST_list *stlist = NULL;
00158
00159 for (t = clause_tree; t; t = TREE_CHAIN (t))
00160 {
00161 st = Get_Pre_ST (TREE_VALUE(t));
00162 stlist = (struct ST_list *) malloc(sizeof(struct ST_list));
00163 stlist->st = st ;
00164 stlist->next = *clause_st;
00165 * clause_st = stlist;
00166 }
00167
00168 }
00169
00170 struct reduction_list
00171 {
00172 struct reduction node;
00173 struct reduction_list *next;
00174 };
00175
00176 void prepare_reduction_clause
00177 ( struct reduction_list *reduction_clause_list, WN_list * * reduction_clause_wn )
00178 {
00179 register tree t = NULL;
00180 ST *st = NULL;
00181 WN *wn = NULL;
00182 WN_list *wnlist = NULL;
00183
00184 while (reduction_clause_list)
00185 {
00186 OPERATOR op_code;
00187 switch(reduction_clause_list->node.reduction_op) {
00188 case REDUCTION_OPR_BAND:
00189 op_code = OPR_BAND;
00190 break;
00191 case REDUCTION_OPR_BIOR:
00192 op_code = OPR_BIOR;
00193 break;
00194 case REDUCTION_OPR_BXOR:
00195 op_code = OPR_BXOR;
00196 break;
00197 case REDUCTION_OPR_ADD:
00198 op_code = OPR_ADD;
00199 break;
00200 case REDUCTION_OPR_MPY:
00201 op_code = OPR_MPY;
00202 break;
00203 case REDUCTION_OPR_SUB:
00204 op_code = OPR_SUB;
00205 break;
00206 case REDUCTION_OPR_CAND:
00207 op_code = OPR_CAND;
00208 break;
00209 case REDUCTION_OPR_CIOR:
00210 op_code = OPR_CIOR;
00211 break;
00212 }
00213
00214 for (t=reduction_clause_list->node.var_list; t; t = TREE_CHAIN (t))
00215 {
00216 st = Get_Pre_ST (TREE_VALUE(t));
00217 wn = WN_CreatePragma(WN_PRAGMA_REDUCTION, st, 0, op_code);
00218 WN_set_pragma_omp(wn);
00219 wnlist = (struct WN_list *) malloc(sizeof(struct WN_list));
00220 wnlist->wn = wn;
00221 wnlist->next = *reduction_clause_wn;
00222 *reduction_clause_wn = wnlist;
00223
00224 }
00225
00226 reduction_clause_list= reduction_clause_list->next;
00227
00228 }
00229
00230 }
00231
00232
00234
00235 void
00236 check_parallel_directive( struct parallel_clause_list * clause_list )
00237 {
00238 struct parallel_clause_list *cl = NULL;
00239 int count_if = 0, count_num_threads = 0, count_default = 0;
00240
00241 for (cl = clause_list; cl != NULL; cl = cl->next)
00242 {
00243 if ( cl->type == p_if ) count_if++;
00244 if ( cl->type == p_num_threads ) count_num_threads++;
00245 if ( cl->type == p_default ) count_default++;
00246 }
00247
00248 if ( count_if > 1 || count_num_threads > 1 || count_default > 1)
00249 {
00250 if ( count_if > 1)
00251 {
00252 printf ("Too many IF clausees.\n");
00253 }
00254 if ( count_num_threads > 1)
00255 {
00256 printf ("Too many NUM_THREADS clausees.\n");
00257 }
00258 if ( count_default > 1)
00259 {
00260 printf ("Too many DEFAULT clausees.\n");
00261 }
00262
00263 SRCPOS srcpos = Get_Srcpos();
00264 Fail_FmtAssertion ("Invalid syntax in the #PRAGMA OMP PARALLEL directive at line: %d, file number: %d.!\n",
00265 SRCPOS_linenum(srcpos), SRCPOS_filenum(srcpos));
00266 }
00267 }
00268
00269 void
00270 expand_start_parallel (struct parallel_clause_list * clause_list)
00271 {
00272 struct Parallel_clause_wn_type * parallel_clause_wn;
00273
00274 tree if_clause_tree = NULL, num_threads_clause_tree = NULL;
00275 tree private_clause_tree = NULL, firstprivate_clause_tree = NULL;
00276 tree shared_clause_tree = NULL, copyin_clause_tree = NULL;
00277 struct reduction_list *reduction_clause_list = NULL;
00278 enum default_type default_clause_value = no_default;
00279
00280 WN *if_clause_wn = NULL, *num_threads_clause_wn =NULL ;
00281
00282 struct parallel_clause_list *cl = NULL;
00283 struct reduction_list *rl = NULL;
00284
00285 ST_list *private_clause_st = NULL;
00286 ST_list *firstprivate_clause_st = NULL;
00287 ST_list *shared_clause_st = NULL;
00288 ST_list *copyin_clause_st = NULL;
00289 WN_list *reduction_clause_wn = NULL;
00290
00291 check_parallel_directive(clause_list);
00292
00293 for (cl = clause_list; cl != NULL; cl = cl->next)
00294 {
00295 if ( cl->type == p_if ) {
00296 if_clause_tree = cl->node.expr_no_commas;
00297 break;
00298 };
00299 };
00300
00301
00302 for (cl = clause_list; cl != NULL; cl = cl->next)
00303 {
00304 if ( cl->type == p_num_threads ) {
00305 num_threads_clause_tree = cl->node.expr_no_commas;
00306 break;
00307 };
00308 };
00309
00310
00311 for (cl = clause_list; cl != NULL; cl = cl->next)
00312 {
00313 if ( cl->type == p_private ) {
00314 private_clause_tree = chainon (private_clause_tree, cl->node.var_list);
00315 };
00316 };
00317
00318
00319 for (cl = clause_list; cl != NULL; cl = cl->next)
00320 {
00321 if ( cl->type == p_firstprivate ) {
00322 firstprivate_clause_tree =
00323 chainon (firstprivate_clause_tree, cl->node.var_list);
00324 };
00325 };
00326
00327
00328 for (cl = clause_list; cl != NULL; cl = cl->next)
00329 {
00330 if ( cl->type == p_shared ) {
00331 shared_clause_tree = chainon (shared_clause_tree, cl->node.var_list);
00332 };
00333 };
00334
00335
00336 for (cl = clause_list; cl != NULL; cl = cl->next)
00337 {
00338 if ( cl->type == p_copyin ) {
00339 copyin_clause_tree = chainon (copyin_clause_tree, cl->node.var_list);
00340 };
00341 };
00342
00343
00344 for (cl = clause_list; cl != NULL; cl = cl->next)
00345 {
00346 if ( cl->type == p_reduction ) {
00347 rl = (struct reduction_list *) malloc(sizeof(struct reduction_list));
00348 rl->node = cl->node.reduction_node;
00349 rl->next = reduction_clause_list;
00350 reduction_clause_list = rl;
00351 };
00352 };
00353
00354
00355 for (cl = clause_list; cl != NULL; cl = cl->next)
00356 {
00357 if ( cl->type == p_default) {
00358 default_clause_value = cl->node.defaulttype;
00359 break;
00360 };
00361 };
00362
00363 if (if_clause_tree)
00364 {
00365 if_clause_wn = WFE_Expand_Expr (if_clause_tree);
00366 TYPE_ID type = WN_rtype (if_clause_wn);
00367 WN * val = (MTYPE_is_integral (type)) ? WN_Intconst (type, 0) :
00368 WN_Floatconst (type, 0);
00369 if_clause_wn = WN_NE (WN_rtype (if_clause_wn),
00370 val, if_clause_wn);
00371 }
00372
00373 if (num_threads_clause_tree)
00374 num_threads_clause_wn = WFE_Expand_Expr (num_threads_clause_tree);
00375
00376 prepare_com_clause ( private_clause_tree, &private_clause_st );
00377
00378 prepare_com_clause ( firstprivate_clause_tree, &firstprivate_clause_st );
00379
00380 prepare_com_clause ( shared_clause_tree, &shared_clause_st );
00381
00382 prepare_com_clause ( copyin_clause_tree, ©in_clause_st );
00383
00384 prepare_reduction_clause ( reduction_clause_list, &reduction_clause_wn );
00385
00386 parallel_clause_wn = (struct Parallel_clause_wn_type *) malloc(sizeof(Parallel_clause_wn_type));
00387
00388 parallel_clause_wn-> if_clause = if_clause_wn;
00389 parallel_clause_wn-> num_threads_clause = num_threads_clause_wn;
00390 parallel_clause_wn-> private_clause = private_clause_st;
00391 parallel_clause_wn-> firstprivate_clause = firstprivate_clause_st;
00392 parallel_clause_wn-> shared_clause = shared_clause_st;
00393 parallel_clause_wn-> copyin_clause = copyin_clause_st;
00394 parallel_clause_wn-> reduction_clause = reduction_clause_wn;
00395 parallel_clause_wn-> default_clause = default_clause_value;
00396
00397 WFE_expand_start_parallel (parallel_clause_wn);
00398
00399 free(parallel_clause_wn);
00400
00401 }
00402
00403 void
00404 expand_end_parallel ( )
00405 {
00406 WFE_expand_end_parallel ();
00407 }
00408
00409
00411
00412 void
00413 check_for_directive(struct for_clause_list * clause_list )
00414 {
00415 struct for_clause_list *cl = NULL;
00416 int count_schedule = 0, count_ordered = 0, count_nowait = 0;
00417
00418 for (cl = clause_list; cl != NULL; cl = cl->next)
00419 {
00420 if ( cl->type == f_schedule_1 || cl->type == f_schedule_2 ) count_schedule++;
00421 if ( cl->type == f_ordered ) count_ordered++;
00422 if ( cl->type == f_nowait ) count_nowait++;
00423 }
00424
00425 if ( count_schedule > 1 || count_ordered > 1 || count_nowait > 1)
00426 {
00427 if ( count_schedule > 1)
00428 {
00429 printf ("Too many SCHEDULE clausees.\n");
00430 }
00431 if ( count_ordered > 1)
00432 {
00433 printf ("Too many ORDERED clausees.\n");
00434 }
00435 if ( count_nowait > 1)
00436 {
00437 printf ("Too many NOWAIT clausees.\n");
00438 }
00439
00440
00441 SRCPOS srcpos = Get_Srcpos();
00442 Fail_FmtAssertion ("Invalid syntax in the #PRAGMA OMP FOR directive at line: %d, file number: %d.!\n",
00443 SRCPOS_linenum(srcpos), SRCPOS_filenum(srcpos));
00444 }
00445 }
00446
00447
00448 void
00449 expand_start_for (struct for_clause_list * clause_list)
00450 {
00451
00452 struct For_clause_wn_type * for_clause_wn;
00453
00454 tree private_clause_tree = NULL;
00455 tree firstprivate_clause_tree = NULL;
00456 tree lastprivate_clause_tree = NULL;
00457 struct reduction_list * reduction_clause_list = NULL;
00458 bool ordered_clause_value = false;
00459 enum schedule_kind_type schedule_1_clasue_value = SK_NONE;
00460 struct schedule_2 schedule_2_clause_value;
00461 schedule_2_clause_value.schedule_kind = SK_NONE;
00462 schedule_2_clause_value.chunk_size = NULL;
00463 bool nowait_clause_value = false;
00464
00465 register tree t = NULL;
00466 struct for_clause_list *cl = NULL;
00467 struct reduction_list *rl = NULL;
00468 ST *st = NULL;
00469 WN *wn = NULL;
00470
00471
00472 ST_list *private_clause_st = NULL;
00473 ST_list *firstprivate_clause_st = NULL;
00474 ST_list *lastprivate_clause_st = NULL;
00475 WN_list *reduction_clause_wn = NULL;
00476 struct schedule_2_wn schedule_2_clause_wn;
00477 schedule_2_clause_wn.schedule_2_kind = SK_NONE;
00478 schedule_2_clause_wn.chunk_size_wn = NULL;
00479
00480
00481 ST_list *stlist = NULL;
00482 WN_list *wnlist = NULL;
00483
00484 check_for_directive(clause_list);
00485
00486
00487 for (cl = clause_list; cl != NULL; cl = cl->next)
00488 {
00489 if ( cl->type == f_private ) {
00490 private_clause_tree = chainon (private_clause_tree, cl->node.var_list);
00491 };
00492 };
00493
00494
00495 for (cl = clause_list; cl != NULL; cl = cl->next)
00496 {
00497 if ( cl->type == f_firstprivate ) {
00498 firstprivate_clause_tree =
00499 chainon (firstprivate_clause_tree, cl->node.var_list);
00500 };
00501 };
00502
00503
00504 for (cl = clause_list; cl != NULL; cl = cl->next)
00505 {
00506 if ( cl->type == f_lastprivate ) {
00507 lastprivate_clause_tree =
00508 chainon (lastprivate_clause_tree, cl->node.var_list);
00509 };
00510 };
00511
00512
00513 for (cl = clause_list; cl != NULL; cl = cl->next)
00514 {
00515 if ( cl->type == f_reduction ) {
00516 rl = (struct reduction_list *) malloc(sizeof(struct reduction_list));
00517 rl->node = cl->node.reduction_node;
00518 rl->next = reduction_clause_list;
00519 reduction_clause_list = rl;
00520 };
00521 };
00522
00523
00524 for (cl = clause_list; cl != NULL; cl = cl->next)
00525 {
00526 if ( cl->type == f_ordered) {
00527 ordered_clause_value = true;
00528 break;
00529 };
00530 };
00531
00532
00533 for (cl = clause_list; cl != NULL; cl = cl->next)
00534 {
00535 if ( cl->type == f_schedule_1) {
00536 schedule_1_clasue_value = cl->node.schedule_kind;
00537 break;
00538 };
00539 };
00540
00541
00542 for (cl = clause_list; cl != NULL; cl = cl->next)
00543 {
00544 if ( cl->type == f_schedule_2) {
00545 schedule_2_clause_value.schedule_kind = cl->node.schedule_node.schedule_kind;
00546 schedule_2_clause_value.chunk_size = cl->node.schedule_node.chunk_size;
00547 break;
00548 };
00549 };
00550
00551
00552 for (cl = clause_list; cl != NULL; cl = cl->next)
00553 {
00554 if ( cl->type == f_nowait) {
00555 nowait_clause_value = true;
00556 break;
00557 };
00558 };
00559
00560 prepare_com_clause ( private_clause_tree, &private_clause_st );
00561
00562 prepare_com_clause ( firstprivate_clause_tree, &firstprivate_clause_st );
00563
00564 prepare_com_clause ( lastprivate_clause_tree, &lastprivate_clause_st );
00565
00566
00567 prepare_reduction_clause ( reduction_clause_list, &reduction_clause_wn );
00568
00569 if (schedule_2_clause_value.schedule_kind != SK_NONE)
00570 {
00571 schedule_2_clause_wn.schedule_2_kind =
00572 schedule_2_clause_value.schedule_kind;
00573
00574 WN *wn = WFE_Expand_Expr(schedule_2_clause_value.chunk_size);
00575
00576 schedule_2_clause_wn.chunk_size_wn = wn;
00577 }
00578
00579
00580 for_clause_wn = (struct For_clause_wn_type *) malloc(sizeof(For_clause_wn_type));
00581
00582 for_clause_wn-> private_clause = private_clause_st;
00583 for_clause_wn-> firstprivate_clause = firstprivate_clause_st;
00584 for_clause_wn-> lastprivate_clause = lastprivate_clause_st;
00585 for_clause_wn-> reduction_clause = reduction_clause_wn;
00586 for_clause_wn-> ordered_clause = ordered_clause_value;
00587 for_clause_wn-> schedule_1_clause = schedule_1_clasue_value;
00588 for_clause_wn-> schedule_2_clause = schedule_2_clause_wn;
00589 for_clause_wn-> nowait_clause = nowait_clause_value;
00590
00591 WFE_expand_start_for (for_clause_wn);
00592
00593 free(for_clause_wn);
00594
00595 }
00596
00597 void
00598 expand_end_for ( )
00599 {
00600 WFE_expand_end_for ();
00601 }
00602
00603
00605
00606
00607 void
00608 check_sections_directive( struct sections_clause_list * clause_list )
00609 {
00610 struct sections_clause_list *cl = NULL;
00611 int count_nowait = 0;
00612
00613 for (cl = clause_list; cl != NULL; cl = cl->next)
00614 {
00615 if ( cl->type == sections_nowait ) count_nowait++;
00616 }
00617
00618 if ( count_nowait > 1)
00619 {
00620 printf ("Too many NOWAIT clausees.\n");
00621
00622 SRCPOS srcpos = Get_Srcpos();
00623 Fail_FmtAssertion ("Invalid syntax in the #PRAGMA OMP SECTIONS directive at line: %d, file number: %d.!\n",
00624 SRCPOS_linenum(srcpos), SRCPOS_filenum(srcpos));
00625 }
00626 }
00627
00628 void
00629 expand_start_sections (struct sections_clause_list * clause_list)
00630 {
00631 struct Sections_clause_wn_type * sections_clause_wn = NULL;
00632
00633 tree private_clause_tree = NULL;
00634 tree firstprivate_clause_tree = NULL;
00635 tree lastprivate_clause_tree = NULL;
00636
00637 struct reduction_list * reduction_clause_list = NULL;
00638 bool nowait_clause_value = false;
00639
00640 register tree t = NULL;
00641 struct sections_clause_list *cl = NULL;
00642 struct reduction_list *rl = NULL;
00643 ST *st = NULL;
00644 WN *wn = NULL;
00645
00646
00647 ST_list *private_clause_st = NULL;
00648 ST_list *firstprivate_clause_st = NULL;
00649 ST_list *lastprivate_clause_st = NULL;
00650 WN_list *reduction_clause_wn = NULL;
00651
00652 ST_list *stlist = NULL;
00653 WN_list *wnlist = NULL;
00654
00655
00656 check_sections_directive(clause_list);
00657
00658
00659 for (cl = clause_list; cl != NULL; cl = cl->next)
00660 {
00661 if ( cl->type == sections_private ) {
00662 private_clause_tree = chainon (private_clause_tree, cl->node.var_list);
00663 };
00664 };
00665
00666
00667 for (cl = clause_list; cl != NULL; cl = cl->next)
00668 {
00669 if ( cl->type == sections_firstprivate ) {
00670 firstprivate_clause_tree =
00671 chainon (firstprivate_clause_tree, cl->node.var_list);
00672 };
00673 };
00674
00675
00676 for (cl = clause_list; cl != NULL; cl = cl->next)
00677 {
00678 if ( cl->type == sections_lastprivate ) {
00679 lastprivate_clause_tree =
00680 chainon (lastprivate_clause_tree, cl->node.var_list);
00681 };
00682 };
00683
00684
00685 for (cl = clause_list; cl != NULL; cl = cl->next)
00686 {
00687 if ( cl->type == sections_reduction ) {
00688 rl = (struct reduction_list *) malloc(sizeof(struct reduction_list));
00689 rl->node = cl->node.reduction_node;
00690 rl->next = reduction_clause_list;
00691 reduction_clause_list = rl;
00692 };
00693 };
00694
00695
00696 for (cl = clause_list; cl != NULL; cl = cl->next)
00697 {
00698 if ( cl->type == sections_nowait) {
00699 nowait_clause_value = true;
00700 break;
00701 };
00702 };
00703
00704 prepare_com_clause ( private_clause_tree, &private_clause_st );
00705
00706 prepare_com_clause ( firstprivate_clause_tree, &firstprivate_clause_st );
00707
00708 prepare_com_clause ( lastprivate_clause_tree, &lastprivate_clause_st );
00709
00710 prepare_reduction_clause ( reduction_clause_list, &reduction_clause_wn );
00711
00712
00713
00714 sections_clause_wn = (struct Sections_clause_wn_type *) malloc(sizeof(Sections_clause_wn_type));
00715
00716 sections_clause_wn-> private_clause = private_clause_st;
00717 sections_clause_wn-> firstprivate_clause = firstprivate_clause_st;
00718 sections_clause_wn-> lastprivate_clause = lastprivate_clause_st;
00719 sections_clause_wn-> reduction_clause = reduction_clause_wn;
00720 sections_clause_wn-> nowait_clause = nowait_clause_value;
00721
00722 WFE_expand_start_sections (sections_clause_wn);
00723
00724 free(sections_clause_wn);
00725
00726 }
00727
00728 void
00729 expand_end_sections ( )
00730 {
00731 WFE_expand_end_sections ();
00732 }
00733
00734
00736
00737
00738 void expand_start_section ( )
00739 {
00740 WFE_expand_start_section ();
00741 }
00742
00743 void expand_end_section ( )
00744 {
00745 WFE_expand_end_section ();
00746 }
00747
00749
00750 #ifdef TARG_SL2 //fork_joint
00751
00752 void
00753 expand_start_sl2_sections (bool is_minor_thread)
00754 {
00755 WFE_expand_start_sl2_sections (is_minor_thread);
00756 }
00757
00758 void
00759 expand_end_sl2_sections ( )
00760 {
00761 WFE_expand_end_sl2_sections ();
00762 }
00763
00764 void expand_start_sl2_section (bool is_minor_thread)
00765 {
00766 WFE_expand_start_sl2_section (is_minor_thread);
00767 }
00768
00769 void expand_end_sl2_section ( )
00770 {
00771 WFE_expand_end_sl2_section ();
00772 }
00773 #endif
00774
00775
00776 void
00777 check_single_directive( struct single_clause_list * clause_list )
00778 {
00779 struct single_clause_list *cl = NULL;
00780 int count_copyprivate = 0, count_nowait = 0;
00781
00782 for (cl = clause_list; cl != NULL; cl = cl->next)
00783 {
00784 if ( cl->type == single_copyprivate ) count_copyprivate++;
00785 if ( cl->type == single_nowait ) count_nowait++;
00786 }
00787
00788 if ( count_nowait > 1 || (count_copyprivate != 0 && count_nowait != 0) )
00789 {
00790 if ( count_copyprivate != 0 && count_nowait != 0 )
00791 {
00792 printf ("The copyprivate clause must not be used with the nowait clause.\n");
00793 }
00794 if ( count_nowait > 1)
00795 {
00796 printf ("Too many NOWAIT clausees.\n");
00797 }
00798
00799 SRCPOS srcpos = Get_Srcpos();
00800 Fail_FmtAssertion ("Invalid syntax in the #PRAGMA OMP SINGLE directive at line: %d, file number: %d.!\n",
00801 SRCPOS_linenum(srcpos), SRCPOS_filenum(srcpos));
00802 }
00803 }
00804
00805 void
00806 expand_start_single (struct single_clause_list * clause_list)
00807 {
00808 struct Single_clause_wn_type * single_clause_wn;
00809
00810 tree private_clause_tree = NULL;
00811 tree firstprivate_clause_tree = NULL;
00812 tree copyprivate_clause_tree = NULL;
00813 bool nowait_clause_value = false;
00814
00815 register tree t = NULL;
00816 struct single_clause_list *cl = NULL;
00817 ST *st = NULL;
00818 WN *wn = NULL;
00819
00820
00821 ST_list *private_clause_st = NULL;
00822 ST_list *firstprivate_clause_st = NULL;
00823 ST_list *copyprivate_clause_st = NULL;
00824
00825 ST_list *stlist = NULL;
00826 WN_list *wnlist = NULL;
00827
00828 check_single_directive(clause_list);
00829
00830
00831 for (cl = clause_list; cl != NULL; cl = cl->next)
00832 {
00833 if ( cl->type == single_private ) {
00834 private_clause_tree = chainon (private_clause_tree, cl->node.var_list);
00835 };
00836 };
00837
00838
00839 for (cl = clause_list; cl != NULL; cl = cl->next)
00840 {
00841 if ( cl->type == single_firstprivate ) {
00842 firstprivate_clause_tree =
00843 chainon (firstprivate_clause_tree, cl->node.var_list);
00844 };
00845 };
00846
00847
00848 for (cl = clause_list; cl != NULL; cl = cl->next)
00849 {
00850 if ( cl->type == single_copyprivate ) {
00851 copyprivate_clause_tree =
00852 chainon (copyprivate_clause_tree, cl->node.var_list);
00853 };
00854 };
00855
00856
00857 for (cl = clause_list; cl != NULL; cl = cl->next)
00858 {
00859 if ( cl->type == single_nowait) {
00860 nowait_clause_value = true;
00861 break;
00862 };
00863 };
00864
00865 prepare_com_clause ( private_clause_tree, &private_clause_st );
00866
00867 prepare_com_clause ( firstprivate_clause_tree, &firstprivate_clause_st );
00868
00869 prepare_com_clause ( copyprivate_clause_tree, ©private_clause_st );
00870
00871 single_clause_wn = (struct Single_clause_wn_type *) malloc(sizeof(Single_clause_wn_type));
00872
00873 single_clause_wn-> private_clause = private_clause_st;
00874 single_clause_wn-> firstprivate_clause = firstprivate_clause_st;
00875 single_clause_wn-> copyprivate_clause = copyprivate_clause_st;
00876 single_clause_wn-> nowait_clause = nowait_clause_value;
00877
00878 WFE_expand_start_single (single_clause_wn);
00879
00880 free(single_clause_wn);
00881
00882 }
00883
00884 void expand_end_single( )
00885 {
00886 WFE_expand_end_single ();
00887 }
00888
00889
00891
00892
00893 void
00894 check_parallel_for_directive( struct parallel_for_clause_list * clause_list )
00895 {
00896 struct parallel_for_clause_list *cl = NULL;
00897 int count_if = 0, count_num_threads = 0, count_default = 0;
00898 int count_schedule = 0, count_ordered = 0;
00899
00900 for (cl = clause_list; cl != NULL; cl = cl->next)
00901 {
00902 if ( cl->type == p_for_if ) count_if++;
00903 if ( cl->type == p_for_num_threads ) count_num_threads++;
00904 if ( cl->type == p_for_default ) count_default++;
00905 if ( cl->type == p_for_schedule_1 || cl->type == p_for_schedule_2 ) count_schedule++;
00906 if ( cl->type == p_for_ordered ) count_ordered++;
00907 }
00908
00909 if ( count_if > 1 || count_num_threads > 1 || count_default >1
00910 ||count_schedule > 1 || count_ordered > 1 )
00911 {
00912 if ( count_if > 1)
00913 {
00914 printf ("Too many IF clausees.\n");
00915 }
00916 if ( count_num_threads > 1)
00917 {
00918 printf ("Too many NUM_THREADS clausees.\n");
00919 }
00920 if ( count_default > 1)
00921 {
00922 printf ("Too many DEFAULT clausees.\n");
00923 }
00924 if ( count_schedule > 1)
00925 {
00926 printf ("Too many SCHEDULE clausees.\n");
00927 }
00928 if ( count_ordered > 1)
00929 {
00930 printf ("Too many ORDERED clausees.\n");
00931 }
00932
00933 SRCPOS srcpos = Get_Srcpos();
00934 Fail_FmtAssertion ("Invalid syntax in the #PRAGMA OMP PARALLEL FOR directive at line: %d, file number: %d.!\n",
00935 SRCPOS_linenum(srcpos), SRCPOS_filenum(srcpos));
00936 }
00937
00938 }
00939
00940
00941 void
00942 expand_start_parallel_for (struct parallel_for_clause_list * clause_list)
00943 {
00944 struct Parallel_for_clause_wn_type * parallel_for_clause_wn;
00945
00946 tree if_clause_tree = NULL, num_threads_clause_tree = NULL;
00947 tree private_clause_tree = NULL, firstprivate_clause_tree = NULL;
00948 tree shared_clause_tree = NULL, copyin_clause_tree = NULL;
00949 tree lastprivate_clause_tree = NULL;
00950 struct reduction_list *reduction_clause_list = NULL;
00951 enum default_type default_clause_value = no_default;
00952 bool ordered_clause_value = false;
00953 enum schedule_kind_type schedule_1_clasue_value = SK_NONE;
00954 struct schedule_2 schedule_2_clause_value;
00955 schedule_2_clause_value.schedule_kind = SK_NONE;
00956 schedule_2_clause_value.chunk_size = NULL;
00957
00958 WN *if_clause_wn = NULL, *num_threads_clause_wn =NULL ;
00959
00960 struct parallel_for_clause_list *cl = NULL;
00961 struct reduction_list *rl = NULL;
00962
00963 ST_list *private_clause_st = NULL;
00964 ST_list *firstprivate_clause_st = NULL;
00965 ST_list *shared_clause_st = NULL;
00966 ST_list *copyin_clause_st = NULL;
00967 WN_list *reduction_clause_wn = NULL;
00968 ST_list *lastprivate_clause_st = NULL;
00969 struct schedule_2_wn schedule_2_clause_wn;
00970 schedule_2_clause_wn.schedule_2_kind = SK_NONE;
00971 schedule_2_clause_wn.chunk_size_wn = NULL;
00972
00973 check_parallel_for_directive(clause_list);
00974
00975
00976 for (cl = clause_list; cl != NULL; cl = cl->next)
00977 {
00978 if ( cl->type == p_for_if ) {
00979 if_clause_tree = cl->node.expr_no_commas;
00980 break;
00981 };
00982 };
00983
00984
00985 for (cl = clause_list; cl != NULL; cl = cl->next)
00986 {
00987 if ( cl->type == p_for_num_threads ) {
00988 num_threads_clause_tree = cl->node.expr_no_commas;
00989 break;
00990 };
00991 };
00992
00993
00994 for (cl = clause_list; cl != NULL; cl = cl->next)
00995 {
00996 if ( cl->type == p_for_private ) {
00997 private_clause_tree = chainon (private_clause_tree, cl->node.var_list);
00998 };
00999 };
01000
01001
01002 for (cl = clause_list; cl != NULL; cl = cl->next)
01003 {
01004 if ( cl->type == p_for_firstprivate ) {
01005 firstprivate_clause_tree =
01006 chainon (firstprivate_clause_tree, cl->node.var_list);
01007 };
01008 };
01009
01010
01011 for (cl = clause_list; cl != NULL; cl = cl->next)
01012 {
01013 if ( cl->type == p_for_lastprivate ) {
01014 lastprivate_clause_tree =
01015 chainon (lastprivate_clause_tree, cl->node.var_list);
01016 };
01017 };
01018
01019
01020 for (cl = clause_list; cl != NULL; cl = cl->next)
01021 {
01022 if ( cl->type == p_for_shared ) {
01023 shared_clause_tree = chainon (shared_clause_tree, cl->node.var_list);
01024 };
01025 };
01026
01027
01028 for (cl = clause_list; cl != NULL; cl = cl->next)
01029 {
01030 if ( cl->type == p_for_copyin ) {
01031 copyin_clause_tree = chainon (copyin_clause_tree, cl->node.var_list);
01032 };
01033 };
01034
01035
01036 for (cl = clause_list; cl != NULL; cl = cl->next)
01037 {
01038 if ( cl->type == p_for_reduction ) {
01039 rl = (struct reduction_list *) malloc(sizeof(struct reduction_list));
01040 rl->node = cl->node.reduction_node;
01041 rl->next = reduction_clause_list;
01042 reduction_clause_list = rl;
01043 };
01044 };
01045
01046
01047 for (cl = clause_list; cl != NULL; cl = cl->next)
01048 {
01049 if ( cl->type == p_for_default) {
01050 default_clause_value = cl->node.defaulttype;
01051 break;
01052 };
01053 };
01054
01055
01056 for (cl = clause_list; cl != NULL; cl = cl->next)
01057 {
01058 if ( cl->type == p_for_ordered) {
01059 ordered_clause_value = true;
01060 break;
01061 };
01062 };
01063
01064
01065 for (cl = clause_list; cl != NULL; cl = cl->next)
01066 {
01067 if ( cl->type == p_for_schedule_1) {
01068 schedule_1_clasue_value = cl->node.schedule_kind;
01069 break;
01070 };
01071 };
01072
01073
01074 for (cl = clause_list; cl != NULL; cl = cl->next)
01075 {
01076 if ( cl->type == p_for_schedule_2) {
01077 schedule_2_clause_value.schedule_kind = cl->node.schedule_node.schedule_kind;
01078 schedule_2_clause_value.chunk_size = cl->node.schedule_node.chunk_size;
01079 break;
01080 };
01081 };
01082
01083 if (if_clause_tree)
01084 {
01085 if_clause_wn = WFE_Expand_Expr (if_clause_tree);
01086 TYPE_ID type = WN_rtype (if_clause_wn);
01087 WN * val = (MTYPE_is_integral (type)) ? WN_Intconst (type, 0) :
01088 WN_Floatconst (type, 0);
01089 if_clause_wn = WN_NE (WN_rtype (if_clause_wn),
01090 val, if_clause_wn);
01091 }
01092
01093 if (num_threads_clause_tree)
01094 num_threads_clause_wn = WFE_Expand_Expr (num_threads_clause_tree);
01095
01096 prepare_com_clause ( private_clause_tree, &private_clause_st );
01097
01098 prepare_com_clause ( firstprivate_clause_tree, &firstprivate_clause_st );
01099
01100 prepare_com_clause ( shared_clause_tree, &shared_clause_st );
01101
01102 prepare_com_clause ( copyin_clause_tree, ©in_clause_st );
01103
01104 prepare_reduction_clause ( reduction_clause_list, &reduction_clause_wn );
01105
01106 prepare_com_clause ( lastprivate_clause_tree, &lastprivate_clause_st );
01107
01108 if (schedule_2_clause_value.schedule_kind != SK_NONE)
01109 {
01110 schedule_2_clause_wn.schedule_2_kind =
01111 schedule_2_clause_value.schedule_kind;
01112 WN *wn = WFE_Expand_Expr(schedule_2_clause_value.chunk_size);
01113 schedule_2_clause_wn.chunk_size_wn = wn;
01114 }
01115
01116 parallel_for_clause_wn =
01117 (struct Parallel_for_clause_wn_type *) malloc(sizeof(Parallel_for_clause_wn_type));
01118
01119 parallel_for_clause_wn-> if_clause = if_clause_wn;
01120 parallel_for_clause_wn-> num_threads_clause = num_threads_clause_wn;
01121 parallel_for_clause_wn-> private_clause = private_clause_st;
01122 parallel_for_clause_wn-> firstprivate_clause = firstprivate_clause_st;
01123 parallel_for_clause_wn-> shared_clause = shared_clause_st;
01124 parallel_for_clause_wn-> copyin_clause = copyin_clause_st;
01125 parallel_for_clause_wn-> reduction_clause = reduction_clause_wn;
01126 parallel_for_clause_wn-> default_clause = default_clause_value;
01127 parallel_for_clause_wn-> lastprivate_clause = lastprivate_clause_st;
01128 parallel_for_clause_wn-> ordered_clause = ordered_clause_value;
01129 parallel_for_clause_wn-> schedule_1_clause = schedule_1_clasue_value;
01130 parallel_for_clause_wn-> schedule_2_clause = schedule_2_clause_wn;
01131
01132 WFE_expand_start_parallel_for (parallel_for_clause_wn);
01133
01134 free(parallel_for_clause_wn);
01135
01136 }
01137
01138 void
01139 expand_end_parallel_for ( )
01140 {
01141 WFE_expand_end_parallel_for ();
01142 }
01143
01144
01146
01147 void
01148 check_parallel_sections_directive( struct parallel_sections_clause_list * clause_list )
01149 {
01150 struct parallel_sections_clause_list *cl = NULL;
01151 int count_if = 0, count_num_threads = 0, count_default = 0;
01152
01153 for (cl = clause_list; cl != NULL; cl = cl->next)
01154 {
01155 if ( cl->type == p_sections_if ) count_if++;
01156 if ( cl->type == p_sections_num_threads ) count_num_threads++;
01157 if ( cl->type == p_sections_default ) count_default++;
01158 }
01159
01160 if ( count_if > 1 || count_num_threads > 1 || count_default > 1 )
01161 {
01162 if ( count_if > 1)
01163 {
01164 printf ("Too many IF clausees.\n");
01165 }
01166 if ( count_num_threads > 1)
01167 {
01168 printf ("Too many NUM_THREADS clausees.\n");
01169 }
01170 if ( count_default > 1)
01171 {
01172 printf ("Too many DEFAULT clausees.\n");
01173 }
01174
01175 SRCPOS srcpos = Get_Srcpos();
01176 Fail_FmtAssertion ("Invalid syntax in the #PRAGMA OMP PARALLEL SECTIONS directive at line: %d, file number: %d.!\n",
01177 SRCPOS_linenum(srcpos), SRCPOS_filenum(srcpos));
01178 }
01179
01180 }
01181
01182 void
01183 expand_start_parallel_sections( struct parallel_sections_clause_list * clause_list )
01184 {
01185 struct Parallel_sections_clause_wn_type * parallel_sections_clause_wn;
01186
01187 tree if_clause_tree = NULL, num_threads_clause_tree = NULL;
01188 tree private_clause_tree = NULL, firstprivate_clause_tree = NULL;
01189 tree shared_clause_tree = NULL, copyin_clause_tree = NULL;
01190 tree lastprivate_clause_tree = NULL;
01191 struct reduction_list *reduction_clause_list = NULL;
01192 enum default_type default_clause_value = no_default;
01193
01194 WN *if_clause_wn = NULL, *num_threads_clause_wn =NULL ;
01195
01196 struct parallel_sections_clause_list *cl = NULL;
01197 struct reduction_list *rl = NULL;
01198
01199 ST_list *private_clause_st = NULL;
01200 ST_list *firstprivate_clause_st = NULL;
01201 ST_list *lastprivate_clause_st = NULL;
01202 ST_list *shared_clause_st = NULL;
01203 ST_list *copyin_clause_st = NULL;
01204 WN_list *reduction_clause_wn = NULL;
01205
01206 check_parallel_sections_directive(clause_list);
01207
01208
01209 for (cl = clause_list; cl != NULL; cl = cl->next)
01210 {
01211 if ( cl->type == p_sections_if ) {
01212 if_clause_tree = cl->node.expr_no_commas;
01213 break;
01214 };
01215 };
01216
01217
01218 for (cl = clause_list; cl != NULL; cl = cl->next)
01219 {
01220 if ( cl->type == p_sections_num_threads ) {
01221 num_threads_clause_tree = cl->node.expr_no_commas;
01222 break;
01223 };
01224 };
01225
01226
01227 for (cl = clause_list; cl != NULL; cl = cl->next)
01228 {
01229 if ( cl->type == p_sections_private ) {
01230 private_clause_tree = chainon (private_clause_tree, cl->node.var_list);
01231 };
01232 };
01233
01234
01235 for (cl = clause_list; cl != NULL; cl = cl->next)
01236 {
01237 if ( cl->type == p_sections_firstprivate ) {
01238 firstprivate_clause_tree =
01239 chainon (firstprivate_clause_tree, cl->node.var_list);
01240 };
01241 };
01242
01243
01244 for (cl = clause_list; cl != NULL; cl = cl->next)
01245 {
01246 if ( cl->type == p_sections_lastprivate ) {
01247 lastprivate_clause_tree =
01248 chainon (lastprivate_clause_tree, cl->node.var_list);
01249 };
01250 };
01251
01252
01253 for (cl = clause_list; cl != NULL; cl = cl->next)
01254 {
01255 if ( cl->type == p_sections_shared ) {
01256 shared_clause_tree = chainon (shared_clause_tree, cl->node.var_list);
01257 };
01258 };
01259
01260
01261 for (cl = clause_list; cl != NULL; cl = cl->next)
01262 {
01263 if ( cl->type == p_sections_copyin ) {
01264 copyin_clause_tree = chainon (copyin_clause_tree, cl->node.var_list);
01265 };
01266 };
01267
01268
01269 for (cl = clause_list; cl != NULL; cl = cl->next)
01270 {
01271 if ( cl->type == p_sections_reduction ) {
01272 rl = (struct reduction_list *) malloc(sizeof(struct reduction_list));
01273 rl->node = cl->node.reduction_node;
01274 rl->next = reduction_clause_list;
01275 reduction_clause_list = rl;
01276 };
01277 };
01278
01279
01280 for (cl = clause_list; cl != NULL; cl = cl->next)
01281 {
01282 if ( cl->type == p_sections_default) {
01283 default_clause_value = cl->node.defaulttype;
01284 break;
01285 };
01286 };
01287
01288
01289 if (if_clause_tree)
01290 {
01291 if_clause_wn = WFE_Expand_Expr (if_clause_tree);
01292 TYPE_ID type = WN_rtype (if_clause_wn);
01293 WN * val = (MTYPE_is_integral (type)) ? WN_Intconst (type, 0) :
01294 WN_Floatconst (type, 0);
01295 if_clause_wn = WN_NE (WN_rtype (if_clause_wn),
01296 val, if_clause_wn);
01297 }
01298
01299 if (num_threads_clause_tree)
01300 num_threads_clause_wn = WFE_Expand_Expr (num_threads_clause_tree);
01301
01302 prepare_com_clause ( private_clause_tree, &private_clause_st );
01303
01304 prepare_com_clause ( firstprivate_clause_tree, &firstprivate_clause_st );
01305
01306 prepare_com_clause ( shared_clause_tree, &shared_clause_st );
01307
01308 prepare_com_clause ( copyin_clause_tree, ©in_clause_st );
01309
01310 prepare_reduction_clause ( reduction_clause_list, &reduction_clause_wn );
01311
01312 prepare_com_clause ( lastprivate_clause_tree, &lastprivate_clause_st );
01313
01314 parallel_sections_clause_wn =
01315 (struct Parallel_sections_clause_wn_type *) malloc(sizeof(Parallel_sections_clause_wn_type));
01316
01317 parallel_sections_clause_wn-> if_clause = if_clause_wn;
01318 parallel_sections_clause_wn-> num_threads_clause = num_threads_clause_wn;
01319 parallel_sections_clause_wn-> private_clause = private_clause_st;
01320 parallel_sections_clause_wn-> firstprivate_clause = firstprivate_clause_st;
01321 parallel_sections_clause_wn-> shared_clause = shared_clause_st;
01322 parallel_sections_clause_wn-> copyin_clause = copyin_clause_st;
01323 parallel_sections_clause_wn-> reduction_clause = reduction_clause_wn;
01324 parallel_sections_clause_wn-> default_clause = default_clause_value;
01325 parallel_sections_clause_wn-> lastprivate_clause = lastprivate_clause_st;
01326
01327 WFE_expand_start_parallel_sections (parallel_sections_clause_wn);
01328
01329 free(parallel_sections_clause_wn);
01330
01331 }
01332
01333 void
01334 expand_end_parallel_sections( )
01335 {
01336 WFE_expand_end_parallel_sections ();
01337 }
01338
01339
01341
01342
01343 void expand_start_master ( )
01344 {
01345 WFE_expand_start_master ();
01346 }
01347
01348 void expand_end_master ( )
01349 {
01350 WFE_expand_end_master ();
01351 }
01352
01353
01355
01356
01357 void expand_start_critical( tree region_phrase )
01358 {
01359 char *critical_name = NULL;
01360 ST *st = NULL;
01361 TCON tcon;
01362 TY_IDX ty;
01363
01364 if (region_phrase)
01365 {
01366 critical_name = IDENTIFIER_POINTER (region_phrase);
01367 tcon = Host_To_Targ_String ( MTYPE_STRING, critical_name, strlen(critical_name));
01368 st = Gen_String_Sym (&tcon, MTYPE_To_TY(MTYPE_STRING), FALSE );
01369 }
01370 if (Trace_Omp)
01371 printf("critical name is %s \n",critical_name);
01372 WFE_expand_start_critical ( st,critical_name );
01373 }
01374
01375 void expand_end_critical ( )
01376 {
01377 WFE_expand_end_critical ( );
01378 }
01379
01380
01382
01383
01384 void check_atomic_expression ( tree atomic_expression )
01385 {
01386 bool valid_for_expr = true;
01387 enum tree_code code, code1;
01388
01389 code = TREE_CODE (atomic_expression);
01390
01391 if (code != MODIFY_EXPR && code != PREDECREMENT_EXPR &&
01392 code != PREINCREMENT_EXPR && code != POSTDECREMENT_EXPR &&
01393 code != POSTINCREMENT_EXPR)
01394 {
01395 printf (" No such increment operation is permitted.\n");
01396 valid_for_expr = false;
01397 }
01398 else {
01399 code1 = TREE_CODE (TREE_OPERAND (atomic_expression, 1));
01400 if (code1 == NOP_EXPR)
01401 code1 = TREE_CODE (TREE_OPERAND (TREE_OPERAND (atomic_expression, 1), 0));
01402 if (code == MODIFY_EXPR && code1 != PLUS_EXPR &&
01403 code1 != MINUS_EXPR && code1 != MULT_EXPR &&
01404 code1 != RDIV_EXPR && code1 != BIT_AND_EXPR &&
01405 code1 != BIT_XOR_EXPR && code1 != BIT_IOR_EXPR &&
01406 code1 != LSHIFT_EXPR && code1 != RSHIFT_EXPR &&
01407 code1 != TRUNC_DIV_EXPR)
01408 {
01409 printf (" No such modifying operation is supported.\n");
01410 valid_for_expr = false;
01411 }
01412 }
01413
01414 if ( !valid_for_expr)
01415 {
01416 SRCPOS srcpos = Get_Srcpos();
01417 Fail_FmtAssertion ("Invalid atomic_expression in an ATOMIC directive! at line: %d, file number: %d.!\n",
01418 SRCPOS_linenum(srcpos), SRCPOS_filenum(srcpos));
01419 }
01420 }
01421
01422
01423 void expand_start_atomic ()
01424 {
01425 WFE_expand_start_atomic ();
01426 }
01427
01428 void expand_end_atomic ()
01429 {
01430 WFE_expand_end_atomic ();
01431 }
01432
01433
01435
01436
01437 void expand_start_ordered( )
01438 {
01439 WFE_expand_start_ordered ( );
01440 }
01441
01442 void expand_end_ordered ( )
01443 {
01444 WFE_expand_end_ordered ( );
01445 }
01446
01447
01449
01450
01451 void expand_barrier ()
01452 {
01453 WFE_expand_barrier ();
01454 }
01455
01456
01458
01459
01460 void expand_flush ( tree flush_variables)
01461 {
01462 register tree t = NULL;
01463 WN_list *flush_wn_list = NULL;
01464 WN_list *wnlist = NULL;
01465
01466 for (t = flush_variables; t; t = TREE_CHAIN (t))
01467 {
01468 WN *wn = WFE_Expand_Expr(TREE_VALUE(t));
01469 wnlist = (struct WN_list *) malloc(sizeof(struct WN_list));
01470 wnlist->wn = WN_CopyNode (wn) ;
01471 wnlist->next = flush_wn_list;
01472 flush_wn_list = wnlist;
01473 }
01474
01475 WFE_expand_flush (flush_wn_list);
01476
01477 }
01478
01479
01481
01482
01483 void expand_threadprivate ( tree threadprivate_variables)
01484 {
01485 register tree t = NULL;
01486 ST_list *threadprivate_st = NULL;
01487 ST_list *stlist = NULL;
01488 WN *wn;
01489 ST *st;
01490 for (t = threadprivate_variables; t; t = TREE_CHAIN (t))
01491 {
01492 st = Get_Pre_ST (TREE_VALUE(t));
01493 stlist = (struct ST_list *) malloc(sizeof(struct ST_list));
01494 stlist->st = st ;
01495 stlist->next = threadprivate_st;
01496 threadprivate_st = stlist;
01497 }
01498
01499 WFE_expand_threadprivate (threadprivate_st);
01500 }
01501
01502
01504
01505 int check_do_loop_for(tree init_expr, tree logical_expr, tree incr_expr)
01506 {
01507
01508 bool valid_for_expr = true;
01509 enum tree_code code, code1;
01510
01511 WN *index, *start, *end, *step;
01512
01513 WN *wn_tmp, * lcv , * incv;
01514
01515 TYPE_ID lcv_t;
01516
01517 code = TREE_CODE (init_expr);
01518
01519 if (code != MODIFY_EXPR)
01520 {
01521 valid_for_expr = false;
01522 }
01523 else
01524 {
01525 lcv = WFE_Expand_Expr (TREE_OPERAND (init_expr, 0));
01526 lcv_t = TY_mtype(ST_type(WN_st(lcv)));
01527
01528 if (lcv_t != MTYPE_I4 && lcv_t != MTYPE_I8 && lcv_t != MTYPE_I2
01529 && lcv_t != MTYPE_I1)
01530 {
01531 valid_for_expr = false;
01532 }
01533 }
01534
01535 code = TREE_CODE (logical_expr);
01536
01537 if (valid_for_expr && (code != LT_EXPR) && (code != LE_EXPR) && (code != GT_EXPR) && (code != GE_EXPR))
01538 {
01539 valid_for_expr = false;
01540 }
01541
01542
01543 code = TREE_CODE (incr_expr);
01544
01545 if (valid_for_expr && (code != MODIFY_EXPR) && (code != PREDECREMENT_EXPR) && (code != PREINCREMENT_EXPR)
01546 && (code != POSTDECREMENT_EXPR) && (code != POSTINCREMENT_EXPR))
01547 {
01548 valid_for_expr = false;
01549 }
01550 else {
01551 incv = WFE_Expand_Expr (TREE_OPERAND (incr_expr, 0));
01552 if (WN_st_idx(lcv)!=WN_st_idx(incv))
01553 {
01554 valid_for_expr = false;
01555 }
01556 else
01557 {
01558 code1 = TREE_CODE (TREE_OPERAND (incr_expr, 1));
01559 if ((code == MODIFY_EXPR) && (code1 != PLUS_EXPR) && (code1 != MINUS_EXPR))
01560 {
01561 valid_for_expr = false;
01562 }
01563
01564 }
01565 }
01566
01567 if (valid_for_expr)
01568 {
01569 return true;
01570 }
01571 else
01572 {
01573 return false;
01574 }
01575
01576
01577 }
01578 void expand_start_do_loop (tree init_expr, tree logical_expr, tree incr_expr, struct nesting * nest)
01579 {
01580 bool valid_for_expr = true;
01581 enum tree_code code, code1;
01582 tree temp;
01583
01584 WN *index, *start, *end, *step;
01585
01586 WN *wn_tmp, * lcv , * incv;
01587 WN *wn,*wn1;
01588 WN *tdecl;
01589 ST *tst;
01590 ST_IDX stlcv;
01591
01592 TYPE_ID lcv_t;
01593
01594 code = TREE_CODE (init_expr);
01595
01596
01597
01598 if (code != MODIFY_EXPR&&code!=VAR_DECL)
01599 {
01600 printf ("Invalid init_expr in a FOR statement! \n");
01601 valid_for_expr = false;
01602 WFE_Stmt_Push (WN_CreateBlock (), wfe_stmk_comma, Get_Srcpos());
01603 }
01604 else
01605 {
01606
01607 if(code==VAR_DECL)
01608 {
01609 tst=DECL_ST(init_expr);
01610 index = WN_CreateIdname(0,tst);
01611 WFE_Stmt_Push (WN_CreateBlock (), wfe_stmk_comma, Get_Srcpos());
01612
01613
01614 wn1 = WFE_Expand_Expr (DECL_INITIAL(init_expr));
01615 #ifdef TARG_SL
01616 wn_tmp = WFE_Lhs_Of_Modify_Expr(MODIFY_EXPR, init_expr, NULL, FALSE,
01617 #else
01618 wn_tmp = WFE_Lhs_Of_Modify_Expr(MODIFY_EXPR, init_expr, FALSE,
01619 #endif
01620 0, 0, 0, FALSE, wn1, 0, FALSE, FALSE);
01621
01622 wn_tmp = WFE_Stmt_Pop (wfe_stmk_comma);
01623 start = WN_COPY_Tree( WN_first( wn_tmp ));
01624 WN_DELETE_Tree( wn_tmp );
01625
01626 }
01627 else
01628 {
01629 lcv = WFE_Expand_Expr (TREE_OPERAND (init_expr, 0));
01630 lcv_t = TY_mtype(ST_type(WN_st(lcv)));
01631
01632 if (lcv_t != MTYPE_I4 && lcv_t != MTYPE_I8 && lcv_t != MTYPE_I2
01633 && lcv_t != MTYPE_I1)
01634 {
01635 printf ("Invalid induction variable type in init_expr in a FOR statement! \n");
01636 valid_for_expr = false;
01637 }
01638 else
01639 {
01640 index = WN_CreateIdname(0,WN_st_idx(lcv));
01641
01642 WFE_Stmt_Push (WN_CreateBlock (), wfe_stmk_comma, Get_Srcpos());
01643
01644
01645 wn_tmp = WFE_Expand_Expr (init_expr);
01646
01647
01648
01649
01650
01651
01652
01653
01654
01655
01656 wn_tmp = WFE_Stmt_Pop (wfe_stmk_comma);
01657 start = WN_COPY_Tree( WN_first( wn_tmp ));
01658 WN_DELETE_Tree( wn_tmp );
01659 }
01660 }
01661 }
01662 code = TREE_CODE (logical_expr);
01663 if (valid_for_expr && (code != LT_EXPR) && (code != LE_EXPR) && (code != GT_EXPR) && (code != GE_EXPR))
01664 {
01665 printf ("Invalid logical_expr in a FOR statement! \
01666 The logical operators can only be <=, <, > or >= \n");
01667 valid_for_expr = false;
01668 }
01669 else {
01670 end = WFE_Expand_Expr (logical_expr);
01671
01672 }
01673
01674 code = TREE_CODE (incr_expr);
01675
01676 if (valid_for_expr && (code != MODIFY_EXPR) && (code != PREDECREMENT_EXPR) && (code != PREINCREMENT_EXPR)
01677 && (code != POSTDECREMENT_EXPR) && (code != POSTINCREMENT_EXPR))
01678 {
01679 printf ("Invalid incr_expr in a FOR statement! \n");
01680 valid_for_expr = false;
01681 }
01682 else {
01683 incv = WFE_Expand_Expr (TREE_OPERAND (incr_expr, 0));
01684 if(TREE_CODE(init_expr)==VAR_DECL)
01685 stlcv=ST_st_idx(tst);
01686 else stlcv=WN_st_idx(lcv);
01687 if (stlcv!=WN_st_idx(incv))
01688 {
01689 printf ("Invalid incr_expr in a FOR statement! \
01690 No induction variable to be modified.\n");
01691 valid_for_expr = false;
01692 }
01693 else
01694 {
01695 code1 = TREE_CODE (TREE_OPERAND (incr_expr, 1));
01696 if ((code == MODIFY_EXPR) && (code1 != PLUS_EXPR) && (code1 != MINUS_EXPR))
01697 {
01698 printf ("Invalid incr_expr in a FOR statement! \
01699 No such increment operation is permitted.\n");
01700 valid_for_expr = false;
01701
01702 }
01703 else
01704 {
01705 WFE_Stmt_Push (WN_CreateBlock (), wfe_stmk_comma, Get_Srcpos());
01706 WFE_Expand_Expr (incr_expr, FALSE);
01707 wn_tmp = WFE_Stmt_Pop (wfe_stmk_comma);
01708 step = WN_COPY_Tree( WN_first( wn_tmp ));
01709 WN_DELETE_Tree( wn_tmp );
01710 }
01711 }
01712 }
01713 if (valid_for_expr)
01714 {
01715 WFE_expand_start_do_loop (index, start, end, step, nest);
01716 }
01717 else
01718 {
01719 SRCPOS srcpos = Get_Srcpos();
01720 Fail_FmtAssertion ("Invalid syntax in the FOR statement at line: %d, file number: %d.!\n",
01721 SRCPOS_linenum(srcpos), SRCPOS_filenum(srcpos));
01722 }
01723 }
01724
01725
01726 void expand_end_do_loop (struct nesting * nest)
01727 {
01728 WFE_expand_end_do_loop(nest);
01729 }
01730
01732
01733
01734 struct parallel_clause_list *
01735 chain_parallel_list_on (struct parallel_clause_list * pclause_list, struct parallel_clause_list * pclause)
01736 {
01737 struct parallel_clause_list *pcl;
01738 if (pclause_list)
01739 {
01740 for (pcl = pclause_list; pcl->next != NULL; pcl = pcl->next);
01741 pcl->next = pclause;
01742 return pclause_list;
01743 }
01744 else return pclause;
01745
01746 }
01747
01748
01749
01750
01751
01752
01753 extern bool seen_omp_paren;
01754
01755 struct parallel_clause_list *
01756 build_parallel_clause_list (tree t,
01757 parallel_clause_type p_type,
01758 default_type d_type,
01759 reduction_op_type red_op)
01760 {
01761
01762 seen_omp_paren = FALSE;
01763
01764 parallel_clause_list * result = (parallel_clause_list *) malloc (sizeof (parallel_clause_list));
01765
01766 result->type = p_type;
01767 result->next = NULL;
01768 switch (p_type)
01769 {
01770 case p_if:
01771 case p_num_threads:
01772 result->node.expr_no_commas = t;
01773 break;
01774 case p_private:
01775 case p_firstprivate:
01776 case p_shared:
01777 case p_copyin:
01778 result->node.var_list = t;
01779 break;
01780 case p_default:
01781 result->node.defaulttype = d_type;
01782 break;
01783 case p_reduction:
01784 result->node.reduction_node.reduction_op = red_op;
01785 result->node.reduction_node.var_list = t;
01786 break;
01787 default:
01788 Fail_FmtAssertion ("Unexpected parallel-clause-type");
01789 }
01790
01791 return result;
01792 }
01793
01795
01796
01797 struct for_clause_list *
01798 chain_for_list_on (struct for_clause_list * fclause_list, struct for_clause_list * fclause)
01799 {
01800 struct for_clause_list *fcl;
01801 if (fclause_list)
01802 {
01803 for (fcl = fclause_list; fcl->next != NULL; fcl = fcl->next);
01804 fcl->next = fclause;
01805 return fclause_list;
01806 }
01807 else return fclause;
01808 }
01809
01810 struct for_clause_list *
01811 build_for_clause_list (tree t, for_clause_type f_type, schedule_kind_type s_kind, reduction_op_type red_op)
01812 {
01813
01814 seen_omp_paren = FALSE;
01815
01816 for_clause_list * result = (for_clause_list *) malloc (sizeof (for_clause_list));
01817
01818 result->type = f_type;
01819 result->next = NULL;
01820
01821 switch (f_type)
01822 {
01823 case f_private:
01824 case f_firstprivate:
01825 case f_lastprivate:
01826 result->node.var_list = t;
01827 break;
01828 case f_schedule_1:
01829 result->node.schedule_kind = s_kind;
01830 break;
01831 case f_schedule_2:
01832 result->node.schedule_node.chunk_size = t;
01833 result->node.schedule_node.schedule_kind = s_kind;
01834 break;
01835 case f_reduction:
01836 result->node.reduction_node.var_list = t;
01837 result->node.reduction_node.reduction_op = red_op;
01838 break;
01839 case f_ordered:
01840 case f_nowait:
01841 result->node.ordered_nowait = 0;
01842 break;
01843 default:
01844 Fail_FmtAssertion ("Unexpected for-clause-type");
01845 }
01846 return result;
01847 }
01848
01850
01851 struct sections_clause_list *
01852 chain_sections_list_on (struct sections_clause_list * sclause_list,
01853 struct sections_clause_list * sclause)
01854 {
01855 struct sections_clause_list *scl;
01856 if (sclause_list)
01857 {
01858 for (scl = sclause_list; scl->next != NULL; scl = scl->next);
01859 scl->next = sclause;
01860 return sclause_list;
01861 }
01862 else return sclause;
01863 }
01864
01865 struct sections_clause_list *
01866 build_sections_clause_list (tree t, sections_clause_type s_type, reduction_op_type red_op)
01867 {
01868
01869 seen_omp_paren = FALSE;
01870
01871 sections_clause_list * result = (sections_clause_list *) malloc (sizeof (sections_clause_list));
01872
01873 result->type = s_type;
01874 result->next = NULL;
01875
01876 switch (s_type)
01877 {
01878 case sections_private:
01879 case sections_firstprivate:
01880 case sections_lastprivate:
01881 result->node.var_list = t;
01882 break;
01883 case sections_reduction:
01884 result->node.reduction_node.reduction_op = red_op;
01885 result->node.reduction_node.var_list = t;
01886 break;
01887 case sections_nowait:
01888 result->node.nowait = 0;
01889 break;
01890 default:
01891 Fail_FmtAssertion ("unexpected sections-clause-type");
01892 }
01893
01894 return result;
01895 }
01896
01898
01899
01900 struct single_clause_list *
01901 chain_single_list_on
01902 (struct single_clause_list * sclause_list, struct single_clause_list * sclause)
01903 {
01904 struct single_clause_list *scl;
01905 if (sclause_list)
01906 {
01907 for (scl = sclause_list; scl->next != NULL; scl = scl->next);
01908 scl->next = sclause;
01909 return sclause_list;
01910 }
01911 else return sclause;
01912 }
01913
01914 struct single_clause_list *
01915 build_single_clause_list (tree t, single_clause_type s_type)
01916 {
01917
01918 seen_omp_paren = FALSE;
01919
01920 struct single_clause_list * result = (single_clause_list *) malloc (sizeof (single_clause_list));
01921
01922 result->type = s_type;
01923 result->next = NULL;
01924
01925 switch (s_type)
01926 {
01927 case single_private:
01928 case single_firstprivate:
01929 case single_copyprivate:
01930 result->node.var_list = t;
01931 break;
01932 case single_nowait:
01933 result->node.nowait = 0;
01934 break;
01935 default:
01936 Fail_FmtAssertion ("Unexpected single-clause-type");
01937 }
01938
01939 return result;
01940 }
01941
01943
01944 struct parallel_for_clause_list *
01945 chain_parallel_for_list_on
01946 (struct parallel_for_clause_list * pfclause_list, struct parallel_for_clause_list * pfclause)
01947 {
01948 struct parallel_for_clause_list *pfcl;
01949 if (pfclause_list)
01950 {
01951 for (pfcl = pfclause_list; pfcl->next != NULL; pfcl = pfcl->next);
01952 pfcl->next = pfclause;
01953 return pfclause_list;
01954 }
01955 else return pfclause;
01956 }
01957
01958 struct parallel_for_clause_list *
01959 build_parallel_for_clause_list (tree t,
01960 parallel_for_clause_type p_type,
01961 default_type d_type,
01962 schedule_kind_type s_kind,
01963 reduction_op_type red_op)
01964 {
01965
01966 seen_omp_paren = FALSE;
01967
01968 struct parallel_for_clause_list * result = (parallel_for_clause_list *) malloc (sizeof (parallel_for_clause_list));
01969
01970 result->type = p_type;
01971 result->next = NULL;
01972
01973 switch (p_type)
01974 {
01975 case p_for_if:
01976 case p_for_num_threads:
01977 result->node.expr_no_commas = t;
01978 break;
01979 case p_for_copyprivate:
01980 case p_for_shared:
01981 case p_for_copyin:
01982 case p_for_private:
01983 case p_for_firstprivate:
01984 case p_for_lastprivate:
01985 result->node.var_list = t;
01986 break;
01987 case p_for_default:
01988 result->node.defaulttype = d_type;
01989 break;
01990 case p_for_schedule_1:
01991 result->node.schedule_kind = s_kind;
01992 break;
01993 case p_for_schedule_2:
01994 result->node.schedule_node.schedule_kind = s_kind;
01995 result->node.schedule_node.chunk_size = t;
01996 break;
01997 case p_for_reduction:
01998 result->node.reduction_node.reduction_op = red_op;
01999 result->node.reduction_node.var_list = t;
02000 break;
02001 case p_for_ordered:
02002 result->node.ordered = 0;
02003 break;
02004 default:
02005 Fail_FmtAssertion ("Unexpected parallel-for-clause-type");
02006 }
02007
02008 return result;
02009 }
02010
02012
02013
02014 struct parallel_sections_clause_list *
02015 chain_parallel_sections_list_on
02016 (struct parallel_sections_clause_list * psclause_list, struct parallel_sections_clause_list * psclause)
02017 {
02018 struct parallel_sections_clause_list *pscl;
02019 if (psclause_list)
02020 {
02021 for (pscl = psclause_list; pscl->next != NULL; pscl = pscl->next);
02022 pscl->next = psclause;
02023 return psclause_list;
02024 }
02025 else return psclause;
02026 }
02027
02028 struct parallel_sections_clause_list *
02029 build_parallel_sections_clause_list (tree t, parallel_sections_clause_type p_type, default_type d_type, reduction_op_type red_op)
02030 {
02031
02032 seen_omp_paren = FALSE;
02033
02034 parallel_sections_clause_list * result = (parallel_sections_clause_list *) malloc (sizeof (parallel_sections_clause_list));
02035
02036 result->type = p_type;
02037 result->next = NULL;
02038
02039 switch (p_type)
02040 {
02041 case p_sections_if:
02042 case p_sections_num_threads:
02043 result->node.expr_no_commas = t;
02044 break;
02045 case p_sections_private:
02046 case p_sections_copyprivate:
02047 case p_sections_firstprivate:
02048 case p_sections_lastprivate:
02049 case p_sections_shared:
02050 case p_sections_copyin:
02051 result->node.var_list = t;
02052 break;
02053 case p_sections_default:
02054 result->node.defaulttype = d_type;
02055 break;
02056 case p_sections_reduction:
02057 result->node.reduction_node.reduction_op = red_op;
02058 result->node.reduction_node.var_list = t;
02059 break;
02060 default:
02061 Fail_FmtAssertion ("Unexpected parallel-sections-clause-type");
02062 }
02063
02064 return result;
02065 }
02066
02067 }