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