Mercurial > hg > CbC > CbC_gcc
comparison gcc/gimplify.c @ 70:b81903832de2
merge c-decl.c
author | Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 21 Aug 2011 09:24:16 +0900 |
parents | 1b10fe6932e1 |
children | ce75bd9117e4 |
comparison
equal
deleted
inserted
replaced
69:1b10fe6932e1 | 70:b81903832de2 |
---|---|
43 #include "target.h" | 43 #include "target.h" |
44 #include "pointer-set.h" | 44 #include "pointer-set.h" |
45 #include "splay-tree.h" | 45 #include "splay-tree.h" |
46 #include "vec.h" | 46 #include "vec.h" |
47 #include "gimple.h" | 47 #include "gimple.h" |
48 #ifndef noCbC | |
49 #include "cbc-tree.h" | |
50 #endif | |
51 | |
52 #include "tree-pass.h" | 48 #include "tree-pass.h" |
53 | 49 |
54 #include "langhooks-def.h" /* FIXME: for lhd_set_decl_assembler_name. */ | 50 #include "langhooks-def.h" /* FIXME: for lhd_set_decl_assembler_name. */ |
55 #include "expr.h" /* FIXME: for can_move_by_pieces | 51 #include "expr.h" /* FIXME: for can_move_by_pieces |
56 and STACK_CHECK_MAX_VAR_SIZE. */ | 52 and STACK_CHECK_MAX_VAR_SIZE. */ |
66 GOVD_REDUCTION = 64, | 62 GOVD_REDUCTION = 64, |
67 GOVD_LOCAL = 128, | 63 GOVD_LOCAL = 128, |
68 GOVD_DEBUG_PRIVATE = 256, | 64 GOVD_DEBUG_PRIVATE = 256, |
69 GOVD_PRIVATE_OUTER_REF = 512, | 65 GOVD_PRIVATE_OUTER_REF = 512, |
70 GOVD_DATA_SHARE_CLASS = (GOVD_SHARED | GOVD_PRIVATE | GOVD_FIRSTPRIVATE | 66 GOVD_DATA_SHARE_CLASS = (GOVD_SHARED | GOVD_PRIVATE | GOVD_FIRSTPRIVATE |
71 | GOVD_LASTPRIVATE | GOVD_REDUCTION | GOVD_LOCAL) | 67 | GOVD_LASTPRIVATE | GOVD_REDUCTION | GOVD_LOCAL) |
72 }; | 68 }; |
73 | 69 |
74 | 70 |
75 enum omp_region_type | 71 enum omp_region_type |
76 { | 72 { |
221 pop_gimplify_context (gimple body) | 217 pop_gimplify_context (gimple body) |
222 { | 218 { |
223 struct gimplify_ctx *c = gimplify_ctxp; | 219 struct gimplify_ctx *c = gimplify_ctxp; |
224 | 220 |
225 gcc_assert (c && (c->bind_expr_stack == NULL | 221 gcc_assert (c && (c->bind_expr_stack == NULL |
226 || VEC_empty (gimple, c->bind_expr_stack))); | 222 || VEC_empty (gimple, c->bind_expr_stack))); |
227 VEC_free (gimple, heap, c->bind_expr_stack); | 223 VEC_free (gimple, heap, c->bind_expr_stack); |
228 gimplify_ctxp = c->prev_context; | 224 gimplify_ctxp = c->prev_context; |
229 | 225 |
230 if (body) | 226 if (body) |
231 declare_vars (c->temps, body, false); | 227 declare_vars (c->temps, body, false); |
387 int i; | 383 int i; |
388 | 384 |
389 for (i = 2; i < 8 && len > i; i++) | 385 for (i = 2; i < 8 && len > i; i++) |
390 { | 386 { |
391 if (name[len - i] == '.') | 387 if (name[len - i] == '.') |
392 { | 388 { |
393 name[len - i] = '\0'; | 389 name[len - i] = '\0'; |
394 break; | 390 break; |
395 } | 391 } |
396 } | 392 } |
397 } | 393 } |
398 | 394 |
399 /* Create a new temporary name with PREFIX. Returns an identifier. */ | 395 /* Create a new temporary name with PREFIX. Returns an identifier. */ |
400 | 396 |
430 /* Make the type of the variable writable. */ | 426 /* Make the type of the variable writable. */ |
431 new_type = build_type_variant (type, 0, 0); | 427 new_type = build_type_variant (type, 0, 0); |
432 TYPE_ATTRIBUTES (new_type) = TYPE_ATTRIBUTES (type); | 428 TYPE_ATTRIBUTES (new_type) = TYPE_ATTRIBUTES (type); |
433 | 429 |
434 tmp_var = build_decl (input_location, | 430 tmp_var = build_decl (input_location, |
435 VAR_DECL, prefix ? create_tmp_var_name (prefix) : NULL, | 431 VAR_DECL, prefix ? create_tmp_var_name (prefix) : NULL, |
436 type); | 432 type); |
437 | 433 |
438 /* The variable was declared by the compiler. */ | 434 /* The variable was declared by the compiler. */ |
439 DECL_ARTIFICIAL (tmp_var) = 1; | 435 DECL_ARTIFICIAL (tmp_var) = 1; |
440 /* And we don't want debug info for it. */ | 436 /* And we don't want debug info for it. */ |
441 DECL_IGNORED_P (tmp_var) = 1; | 437 DECL_IGNORED_P (tmp_var) = 1; |
520 void **slot; | 516 void **slot; |
521 | 517 |
522 elt.val = val; | 518 elt.val = val; |
523 if (gimplify_ctxp->temp_htab == NULL) | 519 if (gimplify_ctxp->temp_htab == NULL) |
524 gimplify_ctxp->temp_htab | 520 gimplify_ctxp->temp_htab |
525 = htab_create (1000, gimple_tree_hash, gimple_tree_eq, free); | 521 = htab_create (1000, gimple_tree_hash, gimple_tree_eq, free); |
526 slot = htab_find_slot (gimplify_ctxp->temp_htab, (void *)&elt, INSERT); | 522 slot = htab_find_slot (gimplify_ctxp->temp_htab, (void *)&elt, INSERT); |
527 if (*slot == NULL) | 523 if (*slot == NULL) |
528 { | 524 { |
529 elt_p = XNEW (elt_t); | 525 elt_p = XNEW (elt_t); |
530 elt_p->val = val; | 526 elt_p->val = val; |
531 elt_p->temp = ret = create_tmp_from_val (val); | 527 elt_p->temp = ret = create_tmp_from_val (val); |
532 *slot = (void *) elt_p; | 528 *slot = (void *) elt_p; |
533 } | 529 } |
534 else | 530 else |
535 { | 531 { |
536 elt_p = (elt_t *) *slot; | 532 elt_p = (elt_t *) *slot; |
537 ret = elt_p->temp; | 533 ret = elt_p->temp; |
538 } | 534 } |
539 } | 535 } |
540 | 536 |
541 return ret; | 537 return ret; |
542 } | 538 } |
543 | 539 |
549 | 545 |
550 static bool | 546 static bool |
551 is_gimple_reg_rhs_or_call (tree t) | 547 is_gimple_reg_rhs_or_call (tree t) |
552 { | 548 { |
553 return (get_gimple_rhs_class (TREE_CODE (t)) != GIMPLE_INVALID_RHS | 549 return (get_gimple_rhs_class (TREE_CODE (t)) != GIMPLE_INVALID_RHS |
554 || TREE_CODE (t) == CALL_EXPR); | 550 || TREE_CODE (t) == CALL_EXPR); |
555 } | 551 } |
556 | 552 |
557 /* Return true if T is a valid memory RHS or a CALL_EXPR. Note that | 553 /* Return true if T is a valid memory RHS or a CALL_EXPR. Note that |
558 this predicate should only be used during gimplification. See the | 554 this predicate should only be used during gimplification. See the |
559 rationale for this in gimplify_modify_expr. */ | 555 rationale for this in gimplify_modify_expr. */ |
565 a renamed variable. */ | 561 a renamed variable. */ |
566 if (is_gimple_reg_type (TREE_TYPE (t))) | 562 if (is_gimple_reg_type (TREE_TYPE (t))) |
567 return is_gimple_val (t); | 563 return is_gimple_val (t); |
568 else | 564 else |
569 return (is_gimple_val (t) || is_gimple_lvalue (t) | 565 return (is_gimple_val (t) || is_gimple_lvalue (t) |
570 || TREE_CODE (t) == CALL_EXPR); | 566 || TREE_CODE (t) == CALL_EXPR); |
571 } | 567 } |
572 | 568 |
573 /* Helper for get_formal_tmp_var and get_initialized_tmp_var. */ | 569 /* Helper for get_formal_tmp_var and get_initialized_tmp_var. */ |
574 | 570 |
575 static tree | 571 static tree |
579 tree t, mod; | 575 tree t, mod; |
580 | 576 |
581 /* Notice that we explicitly allow VAL to be a CALL_EXPR so that we | 577 /* Notice that we explicitly allow VAL to be a CALL_EXPR so that we |
582 can create an INIT_EXPR and convert it into a GIMPLE_CALL below. */ | 578 can create an INIT_EXPR and convert it into a GIMPLE_CALL below. */ |
583 gimplify_expr (&val, pre_p, post_p, is_gimple_reg_rhs_or_call, | 579 gimplify_expr (&val, pre_p, post_p, is_gimple_reg_rhs_or_call, |
584 fb_rvalue); | 580 fb_rvalue); |
585 | 581 |
586 t = lookup_tmp_var (val, is_formal); | 582 t = lookup_tmp_var (val, is_formal); |
587 | 583 |
588 if (is_formal | 584 if (is_formal |
589 && (TREE_CODE (TREE_TYPE (t)) == COMPLEX_TYPE | 585 && (TREE_CODE (TREE_TYPE (t)) == COMPLEX_TYPE |
590 || TREE_CODE (TREE_TYPE (t)) == VECTOR_TYPE)) | 586 || TREE_CODE (TREE_TYPE (t)) == VECTOR_TYPE)) |
591 DECL_GIMPLE_REG_P (t) = 1; | 587 DECL_GIMPLE_REG_P (t) = 1; |
592 | 588 |
593 mod = build2 (INIT_EXPR, TREE_TYPE (t), t, unshare_expr (val)); | 589 mod = build2 (INIT_EXPR, TREE_TYPE (t), t, unshare_expr (val)); |
594 | 590 |
595 SET_EXPR_LOCATION (mod, EXPR_LOC_OR_HERE (val)); | 591 SET_EXPR_LOCATION (mod, EXPR_LOC_OR_HERE (val)); |
657 { | 653 { |
658 DECL_CHAIN (last) = gimple_bind_vars (scope); | 654 DECL_CHAIN (last) = gimple_bind_vars (scope); |
659 gimple_bind_set_vars (scope, temps); | 655 gimple_bind_set_vars (scope, temps); |
660 } | 656 } |
661 else | 657 else |
662 { | 658 { |
663 /* We need to attach the nodes both to the BIND_EXPR and to its | 659 /* We need to attach the nodes both to the BIND_EXPR and to its |
664 associated BLOCK for debugging purposes. The key point here | 660 associated BLOCK for debugging purposes. The key point here |
665 is that the BLOCK_VARS of the BIND_EXPR_BLOCK of a BIND_EXPR | 661 is that the BLOCK_VARS of the BIND_EXPR_BLOCK of a BIND_EXPR |
666 is a subchain of the BIND_EXPR_VARS of the BIND_EXPR. */ | 662 is a subchain of the BIND_EXPR_VARS of the BIND_EXPR. */ |
667 if (BLOCK_VARS (block)) | 663 if (BLOCK_VARS (block)) |
668 BLOCK_VARS (block) = chainon (BLOCK_VARS (block), temps); | 664 BLOCK_VARS (block) = chainon (BLOCK_VARS (block), temps); |
669 else | 665 else |
670 { | 666 { |
671 gimple_bind_set_vars (scope, | 667 gimple_bind_set_vars (scope, |
672 chainon (gimple_bind_vars (scope), temps)); | 668 chainon (gimple_bind_vars (scope), temps)); |
673 BLOCK_VARS (block) = temps; | 669 BLOCK_VARS (block) = temps; |
674 } | 670 } |
675 } | 671 } |
676 } | 672 } |
677 } | 673 } |
678 | 674 |
679 /* For VAR a VAR_DECL of variable size, try to find a constant upper bound | 675 /* For VAR a VAR_DECL of variable size, try to find a constant upper bound |
680 for the size and adjust DECL_SIZE/DECL_SIZE_UNIT accordingly. Abort if | 676 for the size and adjust DECL_SIZE/DECL_SIZE_UNIT accordingly. Abort if |
719 DECL_CHAIN (tmp) = gimplify_ctxp->temps; | 715 DECL_CHAIN (tmp) = gimplify_ctxp->temps; |
720 gimplify_ctxp->temps = tmp; | 716 gimplify_ctxp->temps = tmp; |
721 | 717 |
722 /* Mark temporaries local within the nearest enclosing parallel. */ | 718 /* Mark temporaries local within the nearest enclosing parallel. */ |
723 if (gimplify_omp_ctxp) | 719 if (gimplify_omp_ctxp) |
724 { | 720 { |
725 struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp; | 721 struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp; |
726 while (ctx && ctx->region_type == ORT_WORKSHARE) | 722 while (ctx && ctx->region_type == ORT_WORKSHARE) |
727 ctx = ctx->outer_context; | 723 ctx = ctx->outer_context; |
728 if (ctx) | 724 if (ctx) |
729 omp_add_variable (ctx, tmp, GOVD_LOCAL | GOVD_SEEN); | 725 omp_add_variable (ctx, tmp, GOVD_LOCAL | GOVD_SEEN); |
730 } | 726 } |
731 } | 727 } |
732 else if (cfun) | 728 else if (cfun) |
733 record_vars (tmp); | 729 record_vars (tmp); |
734 else | 730 else |
735 { | 731 { |
736 gimple_seq body_seq; | 732 gimple_seq body_seq; |
737 | 733 |
738 /* This case is for nested functions. We need to expose the locals | 734 /* This case is for nested functions. We need to expose the locals |
739 they create. */ | 735 they create. */ |
740 body_seq = gimple_body (current_function_decl); | 736 body_seq = gimple_body (current_function_decl); |
741 declare_vars (tmp, gimple_seq_first_stmt (body_seq), false); | 737 declare_vars (tmp, gimple_seq_first_stmt (body_seq), false); |
742 } | 738 } |
743 } | 739 } |
744 | 740 |
793 SEQ. If GSI is pointing to the end of the sequence, start with the | 789 SEQ. If GSI is pointing to the end of the sequence, start with the |
794 first statement in SEQ. */ | 790 first statement in SEQ. */ |
795 | 791 |
796 static void | 792 static void |
797 annotate_all_with_location_after (gimple_seq seq, gimple_stmt_iterator gsi, | 793 annotate_all_with_location_after (gimple_seq seq, gimple_stmt_iterator gsi, |
798 location_t location) | 794 location_t location) |
799 { | 795 { |
800 if (gsi_end_p (gsi)) | 796 if (gsi_end_p (gsi)) |
801 gsi = gsi_start (seq); | 797 gsi = gsi_start (seq); |
802 else | 798 else |
803 gsi_next (&gsi); | 799 gsi_next (&gsi); |
920 if (TREE_CODE_CLASS (code) == tcc_type | 916 if (TREE_CODE_CLASS (code) == tcc_type |
921 || TREE_CODE_CLASS (code) == tcc_declaration | 917 || TREE_CODE_CLASS (code) == tcc_declaration |
922 || TREE_CODE_CLASS (code) == tcc_constant) | 918 || TREE_CODE_CLASS (code) == tcc_constant) |
923 { | 919 { |
924 if (TREE_VISITED (t)) | 920 if (TREE_VISITED (t)) |
925 *walk_subtrees = 0; | 921 *walk_subtrees = 0; |
926 else | 922 else |
927 TREE_VISITED (t) = 1; | 923 TREE_VISITED (t) = 1; |
928 } | 924 } |
929 | 925 |
930 /* If this node has been visited already, unshare it and don't look | 926 /* If this node has been visited already, unshare it and don't look |
931 any deeper. */ | 927 any deeper. */ |
932 else if (TREE_VISITED (t)) | 928 else if (TREE_VISITED (t)) |
1036 if (type && !VOID_TYPE_P (type)) | 1032 if (type && !VOID_TYPE_P (type)) |
1037 { | 1033 { |
1038 tree *p; | 1034 tree *p; |
1039 | 1035 |
1040 /* Set p to point to the body of the wrapper. Loop until we find | 1036 /* Set p to point to the body of the wrapper. Loop until we find |
1041 something that isn't a wrapper. */ | 1037 something that isn't a wrapper. */ |
1042 for (p = &wrapper; p && *p; ) | 1038 for (p = &wrapper; p && *p; ) |
1043 { | 1039 { |
1044 switch (TREE_CODE (*p)) | 1040 switch (TREE_CODE (*p)) |
1045 { | 1041 { |
1046 case BIND_EXPR: | 1042 case BIND_EXPR: |
1047 TREE_SIDE_EFFECTS (*p) = 1; | 1043 TREE_SIDE_EFFECTS (*p) = 1; |
1048 TREE_TYPE (*p) = void_type_node; | 1044 TREE_TYPE (*p) = void_type_node; |
1049 /* For a BIND_EXPR, the body is operand 1. */ | 1045 /* For a BIND_EXPR, the body is operand 1. */ |
1050 p = &BIND_EXPR_BODY (*p); | 1046 p = &BIND_EXPR_BODY (*p); |
1051 break; | 1047 break; |
1052 | 1048 |
1053 case CLEANUP_POINT_EXPR: | 1049 case CLEANUP_POINT_EXPR: |
1054 case TRY_FINALLY_EXPR: | 1050 case TRY_FINALLY_EXPR: |
1055 case TRY_CATCH_EXPR: | 1051 case TRY_CATCH_EXPR: |
1056 TREE_SIDE_EFFECTS (*p) = 1; | 1052 TREE_SIDE_EFFECTS (*p) = 1; |
1057 TREE_TYPE (*p) = void_type_node; | 1053 TREE_TYPE (*p) = void_type_node; |
1058 p = &TREE_OPERAND (*p, 0); | 1054 p = &TREE_OPERAND (*p, 0); |
1059 break; | 1055 break; |
1060 | 1056 |
1061 case STATEMENT_LIST: | 1057 case STATEMENT_LIST: |
1062 { | 1058 { |
1063 tree_stmt_iterator i = tsi_last (*p); | 1059 tree_stmt_iterator i = tsi_last (*p); |
1064 TREE_SIDE_EFFECTS (*p) = 1; | 1060 TREE_SIDE_EFFECTS (*p) = 1; |
1065 TREE_TYPE (*p) = void_type_node; | 1061 TREE_TYPE (*p) = void_type_node; |
1066 p = tsi_end_p (i) ? NULL : tsi_stmt_ptr (i); | 1062 p = tsi_end_p (i) ? NULL : tsi_stmt_ptr (i); |
1067 } | 1063 } |
1068 break; | 1064 break; |
1069 | 1065 |
1070 case COMPOUND_EXPR: | 1066 case COMPOUND_EXPR: |
1071 /* Advance to the last statement. Set all container types to void. */ | 1067 /* Advance to the last statement. Set all container types to void. */ |
1072 for (; TREE_CODE (*p) == COMPOUND_EXPR; p = &TREE_OPERAND (*p, 1)) | 1068 for (; TREE_CODE (*p) == COMPOUND_EXPR; p = &TREE_OPERAND (*p, 1)) |
1073 { | 1069 { |
1074 TREE_SIDE_EFFECTS (*p) = 1; | 1070 TREE_SIDE_EFFECTS (*p) = 1; |
1075 TREE_TYPE (*p) = void_type_node; | 1071 TREE_TYPE (*p) = void_type_node; |
1076 } | 1072 } |
1077 break; | 1073 break; |
1078 | 1074 |
1079 default: | 1075 default: |
1080 goto out; | 1076 goto out; |
1081 } | 1077 } |
1082 } | 1078 } |
1083 | 1079 |
1084 out: | 1080 out: |
1085 if (p == NULL || IS_EMPTY_STMT (*p)) | 1081 if (p == NULL || IS_EMPTY_STMT (*p)) |
1086 temp = NULL_TREE; | 1082 temp = NULL_TREE; |
1087 else if (temp) | 1083 else if (temp) |
1088 { | 1084 { |
1089 /* The wrapper is on the RHS of an assignment that we're pushing | 1085 /* The wrapper is on the RHS of an assignment that we're pushing |
1090 down. */ | 1086 down. */ |
1091 gcc_assert (TREE_CODE (temp) == INIT_EXPR | 1087 gcc_assert (TREE_CODE (temp) == INIT_EXPR |
1092 || TREE_CODE (temp) == MODIFY_EXPR); | 1088 || TREE_CODE (temp) == MODIFY_EXPR); |
1093 TREE_OPERAND (temp, 1) = *p; | 1089 TREE_OPERAND (temp, 1) = *p; |
1094 *p = temp; | 1090 *p = temp; |
1095 } | 1091 } |
1096 else | 1092 else |
1097 { | 1093 { |
1098 temp = create_tmp_var (type, "retval"); | 1094 temp = create_tmp_var (type, "retval"); |
1099 *p = build2 (INIT_EXPR, type, temp, *p); | 1095 *p = build2 (INIT_EXPR, type, temp, *p); |
1100 } | 1096 } |
1101 | 1097 |
1102 return temp; | 1098 return temp; |
1103 } | 1099 } |
1104 | 1100 |
1105 return NULL_TREE; | 1101 return NULL_TREE; |
1116 *save = gimple_build_call (implicit_built_in_decls[BUILT_IN_STACK_SAVE], 0); | 1112 *save = gimple_build_call (implicit_built_in_decls[BUILT_IN_STACK_SAVE], 0); |
1117 tmp_var = create_tmp_var (ptr_type_node, "saved_stack"); | 1113 tmp_var = create_tmp_var (ptr_type_node, "saved_stack"); |
1118 gimple_call_set_lhs (*save, tmp_var); | 1114 gimple_call_set_lhs (*save, tmp_var); |
1119 | 1115 |
1120 *restore = gimple_build_call (implicit_built_in_decls[BUILT_IN_STACK_RESTORE], | 1116 *restore = gimple_build_call (implicit_built_in_decls[BUILT_IN_STACK_RESTORE], |
1121 1, tmp_var); | 1117 1, tmp_var); |
1122 } | 1118 } |
1123 | 1119 |
1124 /* Gimplify a BIND_EXPR. Just voidify and recurse. */ | 1120 /* Gimplify a BIND_EXPR. Just voidify and recurse. */ |
1125 | 1121 |
1126 static enum gimplify_status | 1122 static enum gimplify_status |
1136 | 1132 |
1137 /* Mark variables seen in this bind expr. */ | 1133 /* Mark variables seen in this bind expr. */ |
1138 for (t = BIND_EXPR_VARS (bind_expr); t ; t = DECL_CHAIN (t)) | 1134 for (t = BIND_EXPR_VARS (bind_expr); t ; t = DECL_CHAIN (t)) |
1139 { | 1135 { |
1140 if (TREE_CODE (t) == VAR_DECL) | 1136 if (TREE_CODE (t) == VAR_DECL) |
1141 { | 1137 { |
1142 struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp; | 1138 struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp; |
1143 | 1139 |
1144 /* Mark variable as local. */ | 1140 /* Mark variable as local. */ |
1145 if (ctx && !is_global_var (t) | 1141 if (ctx && !is_global_var (t) |
1146 && (! DECL_SEEN_IN_BIND_EXPR_P (t) | 1142 && (! DECL_SEEN_IN_BIND_EXPR_P (t) |
1147 || splay_tree_lookup (ctx->variables, | 1143 || splay_tree_lookup (ctx->variables, |
1148 (splay_tree_key) t) == NULL)) | 1144 (splay_tree_key) t) == NULL)) |
1149 omp_add_variable (gimplify_omp_ctxp, t, GOVD_LOCAL | GOVD_SEEN); | 1145 omp_add_variable (gimplify_omp_ctxp, t, GOVD_LOCAL | GOVD_SEEN); |
1150 | 1146 |
1151 DECL_SEEN_IN_BIND_EXPR_P (t) = 1; | 1147 DECL_SEEN_IN_BIND_EXPR_P (t) = 1; |
1152 | 1148 |
1153 if (DECL_HARD_REGISTER (t) && !is_global_var (t) && cfun) | 1149 if (DECL_HARD_REGISTER (t) && !is_global_var (t) && cfun) |
1154 cfun->has_local_explicit_reg_vars = true; | 1150 cfun->has_local_explicit_reg_vars = true; |
1155 } | 1151 } |
1156 | 1152 |
1157 /* Preliminarily mark non-addressed complex variables as eligible | 1153 /* Preliminarily mark non-addressed complex variables as eligible |
1158 for promotion to gimple registers. We'll transform their uses | 1154 for promotion to gimple registers. We'll transform their uses |
1159 as we find them. */ | 1155 as we find them. */ |
1160 if ((TREE_CODE (TREE_TYPE (t)) == COMPLEX_TYPE | 1156 if ((TREE_CODE (TREE_TYPE (t)) == COMPLEX_TYPE |
1180 { | 1176 { |
1181 gimple stack_save, stack_restore, gs; | 1177 gimple stack_save, stack_restore, gs; |
1182 gimple_seq cleanup, new_body; | 1178 gimple_seq cleanup, new_body; |
1183 | 1179 |
1184 /* Save stack on entry and restore it on exit. Add a try_finally | 1180 /* Save stack on entry and restore it on exit. Add a try_finally |
1185 block to achieve this. Note that mudflap depends on the | 1181 block to achieve this. Note that mudflap depends on the |
1186 format of the emitted code: see mx_register_decls(). */ | 1182 format of the emitted code: see mx_register_decls(). */ |
1187 build_stack_save_restore (&stack_save, &stack_restore); | 1183 build_stack_save_restore (&stack_save, &stack_restore); |
1188 | 1184 |
1189 cleanup = new_body = NULL; | 1185 cleanup = new_body = NULL; |
1190 gimplify_seq_add_stmt (&cleanup, stack_restore); | 1186 gimplify_seq_add_stmt (&cleanup, stack_restore); |
1191 gs = gimple_build_try (gimple_bind_body (gimple_bind), cleanup, | 1187 gs = gimple_build_try (gimple_bind_body (gimple_bind), cleanup, |
1192 GIMPLE_TRY_FINALLY); | 1188 GIMPLE_TRY_FINALLY); |
1193 | 1189 |
1194 gimplify_seq_add_stmt (&new_body, stack_save); | 1190 gimplify_seq_add_stmt (&new_body, stack_save); |
1195 gimplify_seq_add_stmt (&new_body, gs); | 1191 gimplify_seq_add_stmt (&new_body, gs); |
1196 gimple_bind_set_body (gimple_bind, new_body); | 1192 gimple_bind_set_body (gimple_bind, new_body); |
1197 } | 1193 } |
1236 gimple_set_no_warning (ret, TREE_NO_WARNING (stmt)); | 1232 gimple_set_no_warning (ret, TREE_NO_WARNING (stmt)); |
1237 gimplify_seq_add_stmt (pre_p, ret); | 1233 gimplify_seq_add_stmt (pre_p, ret); |
1238 return GS_ALL_DONE; | 1234 return GS_ALL_DONE; |
1239 } | 1235 } |
1240 | 1236 |
1241 if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (current_function_decl))) | 1237 if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (current_function_decl)))) |
1242 #ifndef noCbC | |
1243 || ( ret_expr | |
1244 && TREE_CODE(ret_expr)==CALL_EXPR | |
1245 && CbC_IS_CbC_GOTO(ret_expr) | |
1246 //&& !CbC_IS_CODE_SEGMENT(TREE_TYPE(current_function_decl))) | |
1247 && !(current_function_decl&&CbC_IS_CODE_SEGMENT(TREE_TYPE(current_function_decl)))) | |
1248 //&& !(current_function_decl&&CbC_IS_CODE_SEGMENT(current_function_decl))) | |
1249 #endif | |
1250 ) | |
1251 result_decl = NULL_TREE; | 1238 result_decl = NULL_TREE; |
1252 else | 1239 else |
1253 { | 1240 { |
1254 result_decl = TREE_OPERAND (ret_expr, 0); | 1241 result_decl = TREE_OPERAND (ret_expr, 0); |
1255 | 1242 |
1256 /* See through a return by reference. */ | 1243 /* See through a return by reference. */ |
1257 if (TREE_CODE (result_decl) == INDIRECT_REF) | 1244 if (TREE_CODE (result_decl) == INDIRECT_REF) |
1258 result_decl = TREE_OPERAND (result_decl, 0); | 1245 result_decl = TREE_OPERAND (result_decl, 0); |
1259 | 1246 |
1260 gcc_assert ((TREE_CODE (ret_expr) == MODIFY_EXPR | 1247 gcc_assert ((TREE_CODE (ret_expr) == MODIFY_EXPR |
1261 || TREE_CODE (ret_expr) == INIT_EXPR) | 1248 || TREE_CODE (ret_expr) == INIT_EXPR) |
1262 && TREE_CODE (result_decl) == RESULT_DECL); | 1249 && TREE_CODE (result_decl) == RESULT_DECL); |
1263 } | 1250 } |
1264 | 1251 |
1265 /* If aggregate_value_p is true, then we can return the bare RESULT_DECL. | 1252 /* If aggregate_value_p is true, then we can return the bare RESULT_DECL. |
1266 Recall that aggregate_value_p is FALSE for any aggregate type that is | 1253 Recall that aggregate_value_p is FALSE for any aggregate type that is |
1267 returned in registers. If we're returning values in registers, then | 1254 returned in registers. If we're returning values in registers, then |
1291 else | 1278 else |
1292 { | 1279 { |
1293 result = create_tmp_reg (TREE_TYPE (result_decl), NULL); | 1280 result = create_tmp_reg (TREE_TYPE (result_decl), NULL); |
1294 | 1281 |
1295 /* ??? With complex control flow (usually involving abnormal edges), | 1282 /* ??? With complex control flow (usually involving abnormal edges), |
1296 we can wind up warning about an uninitialized value for this. Due | 1283 we can wind up warning about an uninitialized value for this. Due |
1297 to how this variable is constructed and initialized, this is never | 1284 to how this variable is constructed and initialized, this is never |
1298 true. Give up and never warn. */ | 1285 true. Give up and never warn. */ |
1299 TREE_NO_WARNING (result) = 1; | 1286 TREE_NO_WARNING (result) = 1; |
1300 | 1287 |
1301 gimplify_ctxp->return_temp = result; | 1288 gimplify_ctxp->return_temp = result; |
1302 } | 1289 } |
1303 | 1290 |
1375 if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl)) | 1362 if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl)) |
1376 { | 1363 { |
1377 tree init = DECL_INITIAL (decl); | 1364 tree init = DECL_INITIAL (decl); |
1378 | 1365 |
1379 if (TREE_CODE (DECL_SIZE_UNIT (decl)) != INTEGER_CST | 1366 if (TREE_CODE (DECL_SIZE_UNIT (decl)) != INTEGER_CST |
1380 || (!TREE_STATIC (decl) | 1367 || (!TREE_STATIC (decl) |
1381 && flag_stack_check == GENERIC_STACK_CHECK | 1368 && flag_stack_check == GENERIC_STACK_CHECK |
1382 && compare_tree_int (DECL_SIZE_UNIT (decl), | 1369 && compare_tree_int (DECL_SIZE_UNIT (decl), |
1383 STACK_CHECK_MAX_VAR_SIZE) > 0)) | 1370 STACK_CHECK_MAX_VAR_SIZE) > 0)) |
1384 gimplify_vla_decl (decl, seq_p); | 1371 gimplify_vla_decl (decl, seq_p); |
1385 | 1372 |
1386 /* Some front ends do not explicitly declare all anonymous | 1373 /* Some front ends do not explicitly declare all anonymous |
1387 artificial variables. We compensate here by declaring the | 1374 artificial variables. We compensate here by declaring the |
1388 variables, though it would be better if the front ends would | 1375 variables, though it would be better if the front ends would |
1389 explicitly declare them. */ | 1376 explicitly declare them. */ |
1513 tree default_case = NULL_TREE; | 1500 tree default_case = NULL_TREE; |
1514 size_t i, len; | 1501 size_t i, len; |
1515 gimple gimple_switch; | 1502 gimple gimple_switch; |
1516 | 1503 |
1517 /* If someone can be bothered to fill in the labels, they can | 1504 /* If someone can be bothered to fill in the labels, they can |
1518 be bothered to null out the body too. */ | 1505 be bothered to null out the body too. */ |
1519 gcc_assert (!SWITCH_LABELS (switch_expr)); | 1506 gcc_assert (!SWITCH_LABELS (switch_expr)); |
1520 | 1507 |
1521 /* save old labels, get new ones from body, then restore the old | 1508 /* save old labels, get new ones from body, then restore the old |
1522 labels. Save all the things from the switch body to append after. */ | 1509 labels. Save all the things from the switch body to append after. */ |
1523 saved_labels = gimplify_ctxp->case_labels; | 1510 saved_labels = gimplify_ctxp->case_labels; |
1527 labels = gimplify_ctxp->case_labels; | 1514 labels = gimplify_ctxp->case_labels; |
1528 gimplify_ctxp->case_labels = saved_labels; | 1515 gimplify_ctxp->case_labels = saved_labels; |
1529 | 1516 |
1530 i = 0; | 1517 i = 0; |
1531 while (i < VEC_length (tree, labels)) | 1518 while (i < VEC_length (tree, labels)) |
1532 { | 1519 { |
1533 tree elt = VEC_index (tree, labels, i); | 1520 tree elt = VEC_index (tree, labels, i); |
1534 tree low = CASE_LOW (elt); | 1521 tree low = CASE_LOW (elt); |
1535 bool remove_element = FALSE; | 1522 bool remove_element = FALSE; |
1536 | 1523 |
1537 if (low) | 1524 if (low) |
1538 { | 1525 { |
1539 /* Discard empty ranges. */ | 1526 /* Discard empty ranges. */ |
1540 tree high = CASE_HIGH (elt); | 1527 tree high = CASE_HIGH (elt); |
1541 if (high && tree_int_cst_lt (high, low)) | 1528 if (high && tree_int_cst_lt (high, low)) |
1542 remove_element = TRUE; | 1529 remove_element = TRUE; |
1543 } | 1530 } |
1544 else | 1531 else |
1545 { | 1532 { |
1546 /* The default case must be the last label in the list. */ | 1533 /* The default case must be the last label in the list. */ |
1547 gcc_assert (!default_case); | 1534 gcc_assert (!default_case); |
1548 default_case = elt; | 1535 default_case = elt; |
1549 remove_element = TRUE; | 1536 remove_element = TRUE; |
1550 } | 1537 } |
1551 | 1538 |
1552 if (remove_element) | 1539 if (remove_element) |
1553 VEC_ordered_remove (tree, labels, i); | 1540 VEC_ordered_remove (tree, labels, i); |
1554 else | 1541 else |
1555 i++; | 1542 i++; |
1556 } | 1543 } |
1557 len = i; | 1544 len = i; |
1558 | 1545 |
1559 if (!VEC_empty (tree, labels)) | 1546 if (!VEC_empty (tree, labels)) |
1560 sort_case_labels (labels); | 1547 sort_case_labels (labels); |
1561 | 1548 |
1562 if (!default_case) | 1549 if (!default_case) |
1563 { | 1550 { |
1564 tree type = TREE_TYPE (switch_expr); | 1551 tree type = TREE_TYPE (switch_expr); |
1565 | 1552 |
1566 /* If the switch has no default label, add one, so that we jump | 1553 /* If the switch has no default label, add one, so that we jump |
1567 around the switch body. If the labels already cover the whole | 1554 around the switch body. If the labels already cover the whole |
1568 range of type, add the default label pointing to one of the | 1555 range of type, add the default label pointing to one of the |
1569 existing labels. */ | 1556 existing labels. */ |
1570 if (type == void_type_node) | 1557 if (type == void_type_node) |
1571 type = TREE_TYPE (SWITCH_COND (switch_expr)); | 1558 type = TREE_TYPE (SWITCH_COND (switch_expr)); |
1572 if (len | 1559 if (len |
1573 && INTEGRAL_TYPE_P (type) | 1560 && INTEGRAL_TYPE_P (type) |
1574 && TYPE_MIN_VALUE (type) | 1561 && TYPE_MIN_VALUE (type) |
1575 && TYPE_MAX_VALUE (type) | 1562 && TYPE_MAX_VALUE (type) |
1576 && tree_int_cst_equal (CASE_LOW (VEC_index (tree, labels, 0)), | 1563 && tree_int_cst_equal (CASE_LOW (VEC_index (tree, labels, 0)), |
1577 TYPE_MIN_VALUE (type))) | 1564 TYPE_MIN_VALUE (type))) |
1578 { | 1565 { |
1579 tree low, high = CASE_HIGH (VEC_index (tree, labels, len - 1)); | 1566 tree low, high = CASE_HIGH (VEC_index (tree, labels, len - 1)); |
1580 if (!high) | 1567 if (!high) |
1581 high = CASE_LOW (VEC_index (tree, labels, len - 1)); | 1568 high = CASE_LOW (VEC_index (tree, labels, len - 1)); |
1582 if (tree_int_cst_equal (high, TYPE_MAX_VALUE (type))) | 1569 if (tree_int_cst_equal (high, TYPE_MAX_VALUE (type))) |
1583 { | 1570 { |
1584 for (i = 1; i < len; i++) | 1571 for (i = 1; i < len; i++) |
1585 { | 1572 { |
1586 high = CASE_LOW (VEC_index (tree, labels, i)); | 1573 high = CASE_LOW (VEC_index (tree, labels, i)); |
1587 low = CASE_HIGH (VEC_index (tree, labels, i - 1)); | 1574 low = CASE_HIGH (VEC_index (tree, labels, i - 1)); |
1588 if (!low) | 1575 if (!low) |
1589 low = CASE_LOW (VEC_index (tree, labels, i - 1)); | 1576 low = CASE_LOW (VEC_index (tree, labels, i - 1)); |
1590 if ((TREE_INT_CST_LOW (low) + 1 | 1577 if ((TREE_INT_CST_LOW (low) + 1 |
1591 != TREE_INT_CST_LOW (high)) | 1578 != TREE_INT_CST_LOW (high)) |
1592 || (TREE_INT_CST_HIGH (low) | 1579 || (TREE_INT_CST_HIGH (low) |
1593 + (TREE_INT_CST_LOW (high) == 0) | 1580 + (TREE_INT_CST_LOW (high) == 0) |
1594 != TREE_INT_CST_HIGH (high))) | 1581 != TREE_INT_CST_HIGH (high))) |
1595 break; | 1582 break; |
1596 } | 1583 } |
1597 if (i == len) | 1584 if (i == len) |
1598 default_case = build3 (CASE_LABEL_EXPR, void_type_node, | 1585 default_case = build3 (CASE_LABEL_EXPR, void_type_node, |
1599 NULL_TREE, NULL_TREE, | 1586 NULL_TREE, NULL_TREE, |
1600 CASE_LABEL (VEC_index (tree, | 1587 CASE_LABEL (VEC_index (tree, |
1601 labels, 0))); | 1588 labels, 0))); |
1602 } | 1589 } |
1603 } | 1590 } |
1604 | 1591 |
1605 if (!default_case) | 1592 if (!default_case) |
1606 { | 1593 { |
1607 gimple new_default; | 1594 gimple new_default; |
1608 | 1595 |
1609 default_case | 1596 default_case |
1610 = build3 (CASE_LABEL_EXPR, void_type_node, | 1597 = build3 (CASE_LABEL_EXPR, void_type_node, |
1611 NULL_TREE, NULL_TREE, | 1598 NULL_TREE, NULL_TREE, |
1612 create_artificial_label (UNKNOWN_LOCATION)); | 1599 create_artificial_label (UNKNOWN_LOCATION)); |
1613 new_default = gimple_build_label (CASE_LABEL (default_case)); | 1600 new_default = gimple_build_label (CASE_LABEL (default_case)); |
1614 gimplify_seq_add_stmt (&switch_body_seq, new_default); | 1601 gimplify_seq_add_stmt (&switch_body_seq, new_default); |
1615 } | 1602 } |
1616 } | 1603 } |
1617 | 1604 |
1618 gimple_switch = gimple_build_switch_vec (SWITCH_COND (switch_expr), | 1605 gimple_switch = gimple_build_switch_vec (SWITCH_COND (switch_expr), |
1619 default_case, labels); | 1606 default_case, labels); |
1620 gimplify_seq_add_stmt (pre_p, gimple_switch); | 1607 gimplify_seq_add_stmt (pre_p, gimple_switch); |
1621 gimplify_seq_add_seq (pre_p, switch_body_seq); | 1608 gimplify_seq_add_seq (pre_p, switch_body_seq); |
1730 tree old_type = TREE_TYPE (expr); | 1717 tree old_type = TREE_TYPE (expr); |
1731 #endif | 1718 #endif |
1732 int type_quals; | 1719 int type_quals; |
1733 | 1720 |
1734 /* We need to preserve qualifiers and propagate them from | 1721 /* We need to preserve qualifiers and propagate them from |
1735 operand 0. */ | 1722 operand 0. */ |
1736 type_quals = TYPE_QUALS (type) | 1723 type_quals = TYPE_QUALS (type) |
1737 | TYPE_QUALS (TREE_TYPE (TREE_OPERAND (expr, 0))); | 1724 | TYPE_QUALS (TREE_TYPE (TREE_OPERAND (expr, 0))); |
1738 if (TYPE_QUALS (type) != type_quals) | 1725 if (TYPE_QUALS (type) != type_quals) |
1739 type = build_qualified_type (TYPE_MAIN_VARIANT (type), type_quals); | 1726 type = build_qualified_type (TYPE_MAIN_VARIANT (type), type_quals); |
1740 | 1727 |
1741 /* Set the type of the COMPONENT_REF to the underlying type. */ | 1728 /* Set the type of the COMPONENT_REF to the underlying type. */ |
1742 TREE_TYPE (expr) = type; | 1729 TREE_TYPE (expr) = type; |
1743 | 1730 |
1744 #ifdef ENABLE_TYPES_CHECKING | 1731 #ifdef ENABLE_TYPES_CHECKING |
1745 /* It is now a FE error, if the conversion from the canonical | 1732 /* It is now a FE error, if the conversion from the canonical |
1746 type to the original expression type is not useless. */ | 1733 type to the original expression type is not useless. */ |
1747 gcc_assert (useless_type_conversion_p (old_type, type)); | 1734 gcc_assert (useless_type_conversion_p (old_type, type)); |
1748 #endif | 1735 #endif |
1749 } | 1736 } |
1750 } | 1737 } |
1751 | 1738 |
1780 /* The pointer to element type shall be trivially convertible to | 1767 /* The pointer to element type shall be trivially convertible to |
1781 the expression pointer type. */ | 1768 the expression pointer type. */ |
1782 ddatype = TREE_TYPE (datype); | 1769 ddatype = TREE_TYPE (datype); |
1783 pddatype = build_pointer_type (ddatype); | 1770 pddatype = build_pointer_type (ddatype); |
1784 if (!useless_type_conversion_p (TYPE_MAIN_VARIANT (TREE_TYPE (expr)), | 1771 if (!useless_type_conversion_p (TYPE_MAIN_VARIANT (TREE_TYPE (expr)), |
1785 pddatype)) | 1772 pddatype)) |
1786 return; | 1773 return; |
1787 | 1774 |
1788 /* The lower bound and element sizes must be constant. */ | 1775 /* The lower bound and element sizes must be constant. */ |
1789 if (!TYPE_SIZE_UNIT (ddatype) | 1776 if (!TYPE_SIZE_UNIT (ddatype) |
1790 || TREE_CODE (TYPE_SIZE_UNIT (ddatype)) != INTEGER_CST | 1777 || TREE_CODE (TYPE_SIZE_UNIT (ddatype)) != INTEGER_CST |
1792 || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (datype))) != INTEGER_CST) | 1779 || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (datype))) != INTEGER_CST) |
1793 return; | 1780 return; |
1794 | 1781 |
1795 /* All checks succeeded. Build a new node to merge the cast. */ | 1782 /* All checks succeeded. Build a new node to merge the cast. */ |
1796 *expr_p = build4 (ARRAY_REF, ddatype, TREE_OPERAND (addr_expr, 0), | 1783 *expr_p = build4 (ARRAY_REF, ddatype, TREE_OPERAND (addr_expr, 0), |
1797 TYPE_MIN_VALUE (TYPE_DOMAIN (datype)), | 1784 TYPE_MIN_VALUE (TYPE_DOMAIN (datype)), |
1798 NULL_TREE, NULL_TREE); | 1785 NULL_TREE, NULL_TREE); |
1799 *expr_p = build1 (ADDR_EXPR, pddatype, *expr_p); | 1786 *expr_p = build1 (ADDR_EXPR, pddatype, *expr_p); |
1800 | 1787 |
1801 /* We can have stripped a required restrict qualifier above. */ | 1788 /* We can have stripped a required restrict qualifier above. */ |
1802 if (!useless_type_conversion_p (TREE_TYPE (expr), TREE_TYPE (*expr_p))) | 1789 if (!useless_type_conversion_p (TREE_TYPE (expr), TREE_TYPE (*expr_p))) |
1803 *expr_p = fold_convert (TREE_TYPE (expr), *expr_p); | 1790 *expr_p = fold_convert (TREE_TYPE (expr), *expr_p); |
1825 a need for statement. */ | 1812 a need for statement. */ |
1826 if (CONVERT_EXPR_P (*expr_p) | 1813 if (CONVERT_EXPR_P (*expr_p) |
1827 && POINTER_TYPE_P (TREE_TYPE (*expr_p)) | 1814 && POINTER_TYPE_P (TREE_TYPE (*expr_p)) |
1828 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (*expr_p, 0))) | 1815 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (*expr_p, 0))) |
1829 && (tem = maybe_fold_offset_to_address | 1816 && (tem = maybe_fold_offset_to_address |
1830 (EXPR_LOCATION (*expr_p), TREE_OPERAND (*expr_p, 0), | 1817 (EXPR_LOCATION (*expr_p), TREE_OPERAND (*expr_p, 0), |
1831 integer_zero_node, TREE_TYPE (*expr_p))) != NULL_TREE) | 1818 integer_zero_node, TREE_TYPE (*expr_p))) != NULL_TREE) |
1832 *expr_p = tem; | 1819 *expr_p = tem; |
1833 | 1820 |
1834 /* If we still have a conversion at the toplevel, | 1821 /* If we still have a conversion at the toplevel, |
1835 then canonicalize some constructs. */ | 1822 then canonicalize some constructs. */ |
1836 if (CONVERT_EXPR_P (*expr_p)) | 1823 if (CONVERT_EXPR_P (*expr_p)) |
1837 { | 1824 { |
1838 tree sub = TREE_OPERAND (*expr_p, 0); | 1825 tree sub = TREE_OPERAND (*expr_p, 0); |
1839 | 1826 |
1840 /* If a NOP conversion is changing the type of a COMPONENT_REF | 1827 /* If a NOP conversion is changing the type of a COMPONENT_REF |
1841 expression, then canonicalize its type now in order to expose more | 1828 expression, then canonicalize its type now in order to expose more |
1842 redundant conversions. */ | 1829 redundant conversions. */ |
1843 if (TREE_CODE (sub) == COMPONENT_REF) | 1830 if (TREE_CODE (sub) == COMPONENT_REF) |
1844 canonicalize_component_ref (&TREE_OPERAND (*expr_p, 0)); | 1831 canonicalize_component_ref (&TREE_OPERAND (*expr_p, 0)); |
1845 | 1832 |
1846 /* If a NOP conversion is changing a pointer to array of foo | 1833 /* If a NOP conversion is changing a pointer to array of foo |
1847 to a pointer to foo, embed that change in the ADDR_EXPR. */ | 1834 to a pointer to foo, embed that change in the ADDR_EXPR. */ |
1848 else if (TREE_CODE (sub) == ADDR_EXPR) | 1835 else if (TREE_CODE (sub) == ADDR_EXPR) |
1849 canonicalize_addr_expr (expr_p); | 1836 canonicalize_addr_expr (expr_p); |
1850 } | 1837 } |
1851 | 1838 |
1852 /* If we have a conversion to a non-register type force the | 1839 /* If we have a conversion to a non-register type force the |
1853 use of a VIEW_CONVERT_EXPR instead. */ | 1840 use of a VIEW_CONVERT_EXPR instead. */ |
1854 if (CONVERT_EXPR_P (*expr_p) && !is_gimple_reg_type (TREE_TYPE (*expr_p))) | 1841 if (CONVERT_EXPR_P (*expr_p) && !is_gimple_reg_type (TREE_TYPE (*expr_p))) |
1855 *expr_p = fold_build1_loc (loc, VIEW_CONVERT_EXPR, TREE_TYPE (*expr_p), | 1842 *expr_p = fold_build1_loc (loc, VIEW_CONVERT_EXPR, TREE_TYPE (*expr_p), |
1856 TREE_OPERAND (*expr_p, 0)); | 1843 TREE_OPERAND (*expr_p, 0)); |
1857 | 1844 |
1858 return GS_OK; | 1845 return GS_OK; |
1859 } | 1846 } |
1860 | 1847 |
1861 /* Nonlocal VLAs seen in the current function. */ | 1848 /* Nonlocal VLAs seen in the current function. */ |
1892 if (DECL_HAS_VALUE_EXPR_P (decl)) | 1879 if (DECL_HAS_VALUE_EXPR_P (decl)) |
1893 { | 1880 { |
1894 tree value_expr = DECL_VALUE_EXPR (decl); | 1881 tree value_expr = DECL_VALUE_EXPR (decl); |
1895 | 1882 |
1896 /* For referenced nonlocal VLAs add a decl for debugging purposes | 1883 /* For referenced nonlocal VLAs add a decl for debugging purposes |
1897 to the current function. */ | 1884 to the current function. */ |
1898 if (TREE_CODE (decl) == VAR_DECL | 1885 if (TREE_CODE (decl) == VAR_DECL |
1899 && TREE_CODE (DECL_SIZE_UNIT (decl)) != INTEGER_CST | 1886 && TREE_CODE (DECL_SIZE_UNIT (decl)) != INTEGER_CST |
1900 && nonlocal_vlas != NULL | 1887 && nonlocal_vlas != NULL |
1901 && TREE_CODE (value_expr) == INDIRECT_REF | 1888 && TREE_CODE (value_expr) == INDIRECT_REF |
1902 && TREE_CODE (TREE_OPERAND (value_expr, 0)) == VAR_DECL | 1889 && TREE_CODE (TREE_OPERAND (value_expr, 0)) == VAR_DECL |
1930 | 1917 |
1931 /* Gimplify the COMPONENT_REF, ARRAY_REF, REALPART_EXPR or IMAGPART_EXPR | 1918 /* Gimplify the COMPONENT_REF, ARRAY_REF, REALPART_EXPR or IMAGPART_EXPR |
1932 node *EXPR_P. | 1919 node *EXPR_P. |
1933 | 1920 |
1934 compound_lval | 1921 compound_lval |
1935 : min_lval '[' val ']' | 1922 : min_lval '[' val ']' |
1936 | min_lval '.' ID | 1923 | min_lval '.' ID |
1937 | compound_lval '[' val ']' | 1924 | compound_lval '[' val ']' |
1938 | compound_lval '.' ID | 1925 | compound_lval '.' ID |
1939 | 1926 |
1940 This is not part of the original SIMPLE definition, which separates | 1927 This is not part of the original SIMPLE definition, which separates |
1941 array and member references, but it seems reasonable to handle them | 1928 array and member references, but it seems reasonable to handle them |
1942 together. Also, this way we don't run into problems with union | 1929 together. Also, this way we don't run into problems with union |
1943 aliasing; gcc requires that for accesses through a union to alias, the | 1930 aliasing; gcc requires that for accesses through a union to alias, the |
1950 POST_P points to the sequence where side effects that must happen after | 1937 POST_P points to the sequence where side effects that must happen after |
1951 *EXPR_P should be stored. */ | 1938 *EXPR_P should be stored. */ |
1952 | 1939 |
1953 static enum gimplify_status | 1940 static enum gimplify_status |
1954 gimplify_compound_lval (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, | 1941 gimplify_compound_lval (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, |
1955 fallback_t fallback) | 1942 fallback_t fallback) |
1956 { | 1943 { |
1957 tree *p; | 1944 tree *p; |
1958 VEC(tree,heap) *stack; | 1945 VEC(tree,heap) *stack; |
1959 enum gimplify_status ret = GS_ALL_DONE, tret; | 1946 enum gimplify_status ret = GS_ALL_DONE, tret; |
1960 int i; | 1947 int i; |
1969 for (p = expr_p; ; p = &TREE_OPERAND (*p, 0)) | 1956 for (p = expr_p; ; p = &TREE_OPERAND (*p, 0)) |
1970 { | 1957 { |
1971 restart: | 1958 restart: |
1972 /* Fold INDIRECT_REFs now to turn them into ARRAY_REFs. */ | 1959 /* Fold INDIRECT_REFs now to turn them into ARRAY_REFs. */ |
1973 if (TREE_CODE (*p) == INDIRECT_REF) | 1960 if (TREE_CODE (*p) == INDIRECT_REF) |
1974 *p = fold_indirect_ref_loc (loc, *p); | 1961 *p = fold_indirect_ref_loc (loc, *p); |
1975 | 1962 |
1976 if (handled_component_p (*p)) | 1963 if (handled_component_p (*p)) |
1977 ; | 1964 ; |
1978 /* Expand DECL_VALUE_EXPR now. In some cases that may expose | 1965 /* Expand DECL_VALUE_EXPR now. In some cases that may expose |
1979 additional COMPONENT_REFs. */ | 1966 additional COMPONENT_REFs. */ |
1980 else if ((TREE_CODE (*p) == VAR_DECL || TREE_CODE (*p) == PARM_DECL) | 1967 else if ((TREE_CODE (*p) == VAR_DECL || TREE_CODE (*p) == PARM_DECL) |
1981 && gimplify_var_or_parm_decl (p) == GS_OK) | 1968 && gimplify_var_or_parm_decl (p) == GS_OK) |
1982 goto restart; | 1969 goto restart; |
1983 else | 1970 else |
1984 break; | 1971 break; |
1985 | 1972 |
1986 VEC_safe_push (tree, heap, stack, *p); | 1973 VEC_safe_push (tree, heap, stack, *p); |
1987 } | 1974 } |
1988 | 1975 |
1989 gcc_assert (VEC_length (tree, stack)); | 1976 gcc_assert (VEC_length (tree, stack)); |
2003 for (i = VEC_length (tree, stack) - 1; i >= 0; i--) | 1990 for (i = VEC_length (tree, stack) - 1; i >= 0; i--) |
2004 { | 1991 { |
2005 tree t = VEC_index (tree, stack, i); | 1992 tree t = VEC_index (tree, stack, i); |
2006 | 1993 |
2007 if (TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF) | 1994 if (TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF) |
2008 { | 1995 { |
2009 /* Gimplify the low bound and element type size and put them into | 1996 /* Gimplify the low bound and element type size and put them into |
2010 the ARRAY_REF. If these values are set, they have already been | 1997 the ARRAY_REF. If these values are set, they have already been |
2011 gimplified. */ | 1998 gimplified. */ |
2012 if (TREE_OPERAND (t, 2) == NULL_TREE) | 1999 if (TREE_OPERAND (t, 2) == NULL_TREE) |
2013 { | 2000 { |
2014 tree low = unshare_expr (array_ref_low_bound (t)); | 2001 tree low = unshare_expr (array_ref_low_bound (t)); |
2015 if (!is_gimple_min_invariant (low)) | 2002 if (!is_gimple_min_invariant (low)) |
2016 { | 2003 { |
2017 TREE_OPERAND (t, 2) = low; | 2004 TREE_OPERAND (t, 2) = low; |
2018 tret = gimplify_expr (&TREE_OPERAND (t, 2), pre_p, | 2005 tret = gimplify_expr (&TREE_OPERAND (t, 2), pre_p, |
2019 post_p, is_gimple_reg, | 2006 post_p, is_gimple_reg, |
2020 fb_rvalue); | 2007 fb_rvalue); |
2021 ret = MIN (ret, tret); | 2008 ret = MIN (ret, tret); |
2022 } | 2009 } |
2023 } | 2010 } |
2024 | 2011 |
2025 if (!TREE_OPERAND (t, 3)) | 2012 if (!TREE_OPERAND (t, 3)) |
2026 { | 2013 { |
2027 tree elmt_type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (t, 0))); | 2014 tree elmt_type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (t, 0))); |
2028 tree elmt_size = unshare_expr (array_ref_element_size (t)); | 2015 tree elmt_size = unshare_expr (array_ref_element_size (t)); |
2029 tree factor = size_int (TYPE_ALIGN_UNIT (elmt_type)); | 2016 tree factor = size_int (TYPE_ALIGN_UNIT (elmt_type)); |
2030 | 2017 |
2031 /* Divide the element size by the alignment of the element | 2018 /* Divide the element size by the alignment of the element |
2032 type (above). */ | 2019 type (above). */ |
2033 elmt_size = size_binop_loc (loc, EXACT_DIV_EXPR, elmt_size, factor); | 2020 elmt_size = size_binop_loc (loc, EXACT_DIV_EXPR, elmt_size, factor); |
2034 | 2021 |
2035 if (!is_gimple_min_invariant (elmt_size)) | 2022 if (!is_gimple_min_invariant (elmt_size)) |
2036 { | 2023 { |
2037 TREE_OPERAND (t, 3) = elmt_size; | 2024 TREE_OPERAND (t, 3) = elmt_size; |
2038 tret = gimplify_expr (&TREE_OPERAND (t, 3), pre_p, | 2025 tret = gimplify_expr (&TREE_OPERAND (t, 3), pre_p, |
2039 post_p, is_gimple_reg, | 2026 post_p, is_gimple_reg, |
2040 fb_rvalue); | 2027 fb_rvalue); |
2041 ret = MIN (ret, tret); | 2028 ret = MIN (ret, tret); |
2042 } | 2029 } |
2043 } | 2030 } |
2044 } | 2031 } |
2045 else if (TREE_CODE (t) == COMPONENT_REF) | 2032 else if (TREE_CODE (t) == COMPONENT_REF) |
2046 { | 2033 { |
2047 /* Set the field offset into T and gimplify it. */ | 2034 /* Set the field offset into T and gimplify it. */ |
2048 if (!TREE_OPERAND (t, 2)) | 2035 if (!TREE_OPERAND (t, 2)) |
2049 { | 2036 { |
2050 tree offset = unshare_expr (component_ref_field_offset (t)); | 2037 tree offset = unshare_expr (component_ref_field_offset (t)); |
2051 tree field = TREE_OPERAND (t, 1); | 2038 tree field = TREE_OPERAND (t, 1); |
2052 tree factor | 2039 tree factor |
2053 = size_int (DECL_OFFSET_ALIGN (field) / BITS_PER_UNIT); | 2040 = size_int (DECL_OFFSET_ALIGN (field) / BITS_PER_UNIT); |
2054 | 2041 |
2055 /* Divide the offset by its alignment. */ | 2042 /* Divide the offset by its alignment. */ |
2056 offset = size_binop_loc (loc, EXACT_DIV_EXPR, offset, factor); | 2043 offset = size_binop_loc (loc, EXACT_DIV_EXPR, offset, factor); |
2057 | 2044 |
2058 if (!is_gimple_min_invariant (offset)) | 2045 if (!is_gimple_min_invariant (offset)) |
2059 { | 2046 { |
2060 TREE_OPERAND (t, 2) = offset; | 2047 TREE_OPERAND (t, 2) = offset; |
2061 tret = gimplify_expr (&TREE_OPERAND (t, 2), pre_p, | 2048 tret = gimplify_expr (&TREE_OPERAND (t, 2), pre_p, |
2062 post_p, is_gimple_reg, | 2049 post_p, is_gimple_reg, |
2063 fb_rvalue); | 2050 fb_rvalue); |
2064 ret = MIN (ret, tret); | 2051 ret = MIN (ret, tret); |
2065 } | 2052 } |
2066 } | 2053 } |
2067 } | 2054 } |
2068 } | 2055 } |
2069 | 2056 |
2070 /* Step 2 is to gimplify the base expression. Make sure lvalue is set | 2057 /* Step 2 is to gimplify the base expression. Make sure lvalue is set |
2071 so as to match the min_lval predicate. Failure to do so may result | 2058 so as to match the min_lval predicate. Failure to do so may result |
2072 in the creation of large aggregate temporaries. */ | 2059 in the creation of large aggregate temporaries. */ |
2073 tret = gimplify_expr (p, pre_p, post_p, is_gimple_min_lval, | 2060 tret = gimplify_expr (p, pre_p, post_p, is_gimple_min_lval, |
2074 fallback | fb_lvalue); | 2061 fallback | fb_lvalue); |
2075 ret = MIN (ret, tret); | 2062 ret = MIN (ret, tret); |
2076 | 2063 |
2077 /* And finally, the indices and operands to BIT_FIELD_REF. During this | 2064 /* And finally, the indices and operands to BIT_FIELD_REF. During this |
2078 loop we also remove any useless conversions. */ | 2065 loop we also remove any useless conversions. */ |
2079 for (; VEC_length (tree, stack) > 0; ) | 2066 for (; VEC_length (tree, stack) > 0; ) |
2080 { | 2067 { |
2081 tree t = VEC_pop (tree, stack); | 2068 tree t = VEC_pop (tree, stack); |
2082 | 2069 |
2083 if (TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF) | 2070 if (TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF) |
2084 { | 2071 { |
2085 /* Gimplify the dimension. */ | 2072 /* Gimplify the dimension. */ |
2086 if (!is_gimple_min_invariant (TREE_OPERAND (t, 1))) | 2073 if (!is_gimple_min_invariant (TREE_OPERAND (t, 1))) |
2087 { | 2074 { |
2088 tret = gimplify_expr (&TREE_OPERAND (t, 1), pre_p, post_p, | 2075 tret = gimplify_expr (&TREE_OPERAND (t, 1), pre_p, post_p, |
2089 is_gimple_val, fb_rvalue); | 2076 is_gimple_val, fb_rvalue); |
2090 ret = MIN (ret, tret); | 2077 ret = MIN (ret, tret); |
2091 } | 2078 } |
2092 } | 2079 } |
2093 else if (TREE_CODE (t) == BIT_FIELD_REF) | 2080 else if (TREE_CODE (t) == BIT_FIELD_REF) |
2094 { | 2081 { |
2095 tret = gimplify_expr (&TREE_OPERAND (t, 1), pre_p, post_p, | 2082 tret = gimplify_expr (&TREE_OPERAND (t, 1), pre_p, post_p, |
2096 is_gimple_val, fb_rvalue); | 2083 is_gimple_val, fb_rvalue); |
2097 ret = MIN (ret, tret); | 2084 ret = MIN (ret, tret); |
2098 tret = gimplify_expr (&TREE_OPERAND (t, 2), pre_p, post_p, | 2085 tret = gimplify_expr (&TREE_OPERAND (t, 2), pre_p, post_p, |
2099 is_gimple_val, fb_rvalue); | 2086 is_gimple_val, fb_rvalue); |
2100 ret = MIN (ret, tret); | 2087 ret = MIN (ret, tret); |
2101 } | 2088 } |
2102 | 2089 |
2103 STRIP_USELESS_TYPE_CONVERSION (TREE_OPERAND (t, 0)); | 2090 STRIP_USELESS_TYPE_CONVERSION (TREE_OPERAND (t, 0)); |
2104 | 2091 |
2105 /* The innermost expression P may have originally had | 2092 /* The innermost expression P may have originally had |
2106 TREE_SIDE_EFFECTS set which would have caused all the outer | 2093 TREE_SIDE_EFFECTS set which would have caused all the outer |
2107 expressions in *EXPR_P leading to P to also have had | 2094 expressions in *EXPR_P leading to P to also have had |
2108 TREE_SIDE_EFFECTS set. */ | 2095 TREE_SIDE_EFFECTS set. */ |
2109 recalculate_side_effects (t); | 2096 recalculate_side_effects (t); |
2110 } | 2097 } |
2111 | 2098 |
2112 /* If the outermost expression is a COMPONENT_REF, canonicalize its type. */ | 2099 /* If the outermost expression is a COMPONENT_REF, canonicalize its type. */ |
2113 if ((fallback & fb_rvalue) && TREE_CODE (*expr_p) == COMPONENT_REF) | 2100 if ((fallback & fb_rvalue) && TREE_CODE (*expr_p) == COMPONENT_REF) |
2124 | 2111 |
2125 /* Gimplify the self modifying expression pointed to by EXPR_P | 2112 /* Gimplify the self modifying expression pointed to by EXPR_P |
2126 (++, --, +=, -=). | 2113 (++, --, +=, -=). |
2127 | 2114 |
2128 PRE_P points to the list where side effects that must happen before | 2115 PRE_P points to the list where side effects that must happen before |
2129 *EXPR_P should be stored. | 2116 *EXPR_P should be stored. |
2130 | 2117 |
2131 POST_P points to the list where side effects that must happen after | 2118 POST_P points to the list where side effects that must happen after |
2132 *EXPR_P should be stored. | 2119 *EXPR_P should be stored. |
2133 | 2120 |
2134 WANT_VALUE is nonzero iff we want to use the value of this expression | 2121 WANT_VALUE is nonzero iff we want to use the value of this expression |
2135 in another expression. */ | 2122 in another expression. */ |
2136 | 2123 |
2137 static enum gimplify_status | 2124 static enum gimplify_status |
2138 gimplify_self_mod_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, | 2125 gimplify_self_mod_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, |
2139 bool want_value) | 2126 bool want_value) |
2140 { | 2127 { |
2141 enum tree_code code; | 2128 enum tree_code code; |
2142 tree lhs, lvalue, rhs, t1; | 2129 tree lhs, lvalue, rhs, t1; |
2143 gimple_seq post = NULL, *orig_post_p = post_p; | 2130 gimple_seq post = NULL, *orig_post_p = post_p; |
2144 bool postfix; | 2131 bool postfix; |
2147 location_t loc = EXPR_LOCATION (*expr_p); | 2134 location_t loc = EXPR_LOCATION (*expr_p); |
2148 | 2135 |
2149 code = TREE_CODE (*expr_p); | 2136 code = TREE_CODE (*expr_p); |
2150 | 2137 |
2151 gcc_assert (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR | 2138 gcc_assert (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR |
2152 || code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR); | 2139 || code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR); |
2153 | 2140 |
2154 /* Prefix or postfix? */ | 2141 /* Prefix or postfix? */ |
2155 if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR) | 2142 if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR) |
2156 /* Faster to treat as prefix if result is not used. */ | 2143 /* Faster to treat as prefix if result is not used. */ |
2157 postfix = want_value; | 2144 postfix = want_value; |
2184 make sure to make lvalue a minimal lval, see | 2171 make sure to make lvalue a minimal lval, see |
2185 gcc.c-torture/execute/20040313-1.c for an example where this matters. */ | 2172 gcc.c-torture/execute/20040313-1.c for an example where this matters. */ |
2186 if (postfix) | 2173 if (postfix) |
2187 { | 2174 { |
2188 if (!is_gimple_min_lval (lvalue)) | 2175 if (!is_gimple_min_lval (lvalue)) |
2189 { | 2176 { |
2190 mark_addressable (lvalue); | 2177 mark_addressable (lvalue); |
2191 lvalue = build_fold_addr_expr_loc (input_location, lvalue); | 2178 lvalue = build_fold_addr_expr_loc (input_location, lvalue); |
2192 gimplify_expr (&lvalue, pre_p, post_p, is_gimple_val, fb_rvalue); | 2179 gimplify_expr (&lvalue, pre_p, post_p, is_gimple_val, fb_rvalue); |
2193 lvalue = build_fold_indirect_ref_loc (input_location, lvalue); | 2180 lvalue = build_fold_indirect_ref_loc (input_location, lvalue); |
2194 } | 2181 } |
2195 ret = gimplify_expr (&lhs, pre_p, post_p, is_gimple_val, fb_rvalue); | 2182 ret = gimplify_expr (&lhs, pre_p, post_p, is_gimple_val, fb_rvalue); |
2196 if (ret == GS_ERROR) | 2183 if (ret == GS_ERROR) |
2197 return ret; | 2184 return ret; |
2198 } | 2185 } |
2199 | 2186 |
2200 /* For POINTERs increment, use POINTER_PLUS_EXPR. */ | 2187 /* For POINTERs increment, use POINTER_PLUS_EXPR. */ |
2201 if (POINTER_TYPE_P (TREE_TYPE (lhs))) | 2188 if (POINTER_TYPE_P (TREE_TYPE (lhs))) |
2202 { | 2189 { |
2203 rhs = fold_convert_loc (loc, sizetype, rhs); | 2190 rhs = fold_convert_loc (loc, sizetype, rhs); |
2204 if (arith_code == MINUS_EXPR) | 2191 if (arith_code == MINUS_EXPR) |
2205 rhs = fold_build1_loc (loc, NEGATE_EXPR, TREE_TYPE (rhs), rhs); | 2192 rhs = fold_build1_loc (loc, NEGATE_EXPR, TREE_TYPE (rhs), rhs); |
2206 arith_code = POINTER_PLUS_EXPR; | 2193 arith_code = POINTER_PLUS_EXPR; |
2207 } | 2194 } |
2208 | 2195 |
2209 t1 = build2 (arith_code, TREE_TYPE (*expr_p), lhs, rhs); | 2196 t1 = build2 (arith_code, TREE_TYPE (*expr_p), lhs, rhs); |
2210 | 2197 |
2322 if (fndecl && DECL_BUILT_IN (fndecl)) | 2309 if (fndecl && DECL_BUILT_IN (fndecl)) |
2323 { | 2310 { |
2324 tree new_tree = fold_call_expr (input_location, *expr_p, !want_value); | 2311 tree new_tree = fold_call_expr (input_location, *expr_p, !want_value); |
2325 | 2312 |
2326 if (new_tree && new_tree != *expr_p) | 2313 if (new_tree && new_tree != *expr_p) |
2327 { | 2314 { |
2328 /* There was a transformation of this call which computes the | 2315 /* There was a transformation of this call which computes the |
2329 same value, but in a more efficient way. Return and try | 2316 same value, but in a more efficient way. Return and try |
2330 again. */ | 2317 again. */ |
2331 *expr_p = new_tree; | 2318 *expr_p = new_tree; |
2332 return GS_OK; | 2319 return GS_OK; |
2333 } | 2320 } |
2334 | 2321 |
2335 if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL | 2322 if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL |
2336 && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_VA_START) | 2323 && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_VA_START) |
2337 { | 2324 { |
2338 builtin_va_start_p = TRUE; | 2325 builtin_va_start_p = TRUE; |
2339 if (call_expr_nargs (*expr_p) < 2) | 2326 if (call_expr_nargs (*expr_p) < 2) |
2340 { | 2327 { |
2341 error ("too few arguments to function %<va_start%>"); | 2328 error ("too few arguments to function %<va_start%>"); |
2342 *expr_p = build_empty_stmt (EXPR_LOCATION (*expr_p)); | 2329 *expr_p = build_empty_stmt (EXPR_LOCATION (*expr_p)); |
2343 return GS_OK; | 2330 return GS_OK; |
2344 } | 2331 } |
2345 | 2332 |
2346 if (fold_builtin_next_arg (*expr_p, true)) | 2333 if (fold_builtin_next_arg (*expr_p, true)) |
2347 { | 2334 { |
2348 *expr_p = build_empty_stmt (EXPR_LOCATION (*expr_p)); | 2335 *expr_p = build_empty_stmt (EXPR_LOCATION (*expr_p)); |
2349 return GS_OK; | 2336 return GS_OK; |
2350 } | 2337 } |
2351 } | 2338 } |
2352 } | 2339 } |
2353 | 2340 |
2354 /* There is a sequence point before the call, so any side effects in | 2341 /* There is a sequence point before the call, so any side effects in |
2355 the calling expression must occur before the actual call. Force | 2342 the calling expression must occur before the actual call. Force |
2356 gimplify_expr to use an internal post queue. */ | 2343 gimplify_expr to use an internal post queue. */ |
2357 ret = gimplify_expr (&CALL_EXPR_FN (*expr_p), pre_p, NULL, | 2344 ret = gimplify_expr (&CALL_EXPR_FN (*expr_p), pre_p, NULL, |
2358 is_gimple_call_addr, fb_rvalue); | 2345 is_gimple_call_addr, fb_rvalue); |
2359 | 2346 |
2360 nargs = call_expr_nargs (*expr_p); | 2347 nargs = call_expr_nargs (*expr_p); |
2361 | 2348 |
2362 /* Get argument types for verification. */ | 2349 /* Get argument types for verification. */ |
2363 fndecl = get_callee_fndecl (*expr_p); | 2350 fndecl = get_callee_fndecl (*expr_p); |
2385 { | 2372 { |
2386 tree last_arg = CALL_EXPR_ARG (*expr_p, nargs - 1); | 2373 tree last_arg = CALL_EXPR_ARG (*expr_p, nargs - 1); |
2387 tree last_arg_fndecl = get_callee_fndecl (last_arg); | 2374 tree last_arg_fndecl = get_callee_fndecl (last_arg); |
2388 | 2375 |
2389 if (last_arg_fndecl | 2376 if (last_arg_fndecl |
2390 && TREE_CODE (last_arg_fndecl) == FUNCTION_DECL | 2377 && TREE_CODE (last_arg_fndecl) == FUNCTION_DECL |
2391 && DECL_BUILT_IN_CLASS (last_arg_fndecl) == BUILT_IN_NORMAL | 2378 && DECL_BUILT_IN_CLASS (last_arg_fndecl) == BUILT_IN_NORMAL |
2392 && DECL_FUNCTION_CODE (last_arg_fndecl) == BUILT_IN_VA_ARG_PACK) | 2379 && DECL_FUNCTION_CODE (last_arg_fndecl) == BUILT_IN_VA_ARG_PACK) |
2393 { | 2380 { |
2394 tree call = *expr_p; | 2381 tree call = *expr_p; |
2395 | 2382 |
2396 --nargs; | 2383 --nargs; |
2397 *expr_p = build_call_array_loc (loc, TREE_TYPE (call), | 2384 *expr_p = build_call_array_loc (loc, TREE_TYPE (call), |
2398 CALL_EXPR_FN (call), | 2385 CALL_EXPR_FN (call), |
2399 nargs, CALL_EXPR_ARGP (call)); | 2386 nargs, CALL_EXPR_ARGP (call)); |
2400 | 2387 |
2401 /* Copy all CALL_EXPR flags, location and block, except | 2388 /* Copy all CALL_EXPR flags, location and block, except |
2402 CALL_EXPR_VA_ARG_PACK flag. */ | 2389 CALL_EXPR_VA_ARG_PACK flag. */ |
2403 CALL_EXPR_STATIC_CHAIN (*expr_p) = CALL_EXPR_STATIC_CHAIN (call); | 2390 CALL_EXPR_STATIC_CHAIN (*expr_p) = CALL_EXPR_STATIC_CHAIN (call); |
2404 CALL_EXPR_TAILCALL (*expr_p) = CALL_EXPR_TAILCALL (call); | 2391 CALL_EXPR_TAILCALL (*expr_p) = CALL_EXPR_TAILCALL (call); |
2405 CALL_EXPR_RETURN_SLOT_OPT (*expr_p) | 2392 CALL_EXPR_RETURN_SLOT_OPT (*expr_p) |
2406 = CALL_EXPR_RETURN_SLOT_OPT (call); | 2393 = CALL_EXPR_RETURN_SLOT_OPT (call); |
2407 CALL_FROM_THUNK_P (*expr_p) = CALL_FROM_THUNK_P (call); | 2394 CALL_FROM_THUNK_P (*expr_p) = CALL_FROM_THUNK_P (call); |
2408 CALL_CANNOT_INLINE_P (*expr_p) = CALL_CANNOT_INLINE_P (call); | 2395 CALL_CANNOT_INLINE_P (*expr_p) = CALL_CANNOT_INLINE_P (call); |
2409 SET_EXPR_LOCATION (*expr_p, EXPR_LOCATION (call)); | 2396 SET_EXPR_LOCATION (*expr_p, EXPR_LOCATION (call)); |
2410 TREE_BLOCK (*expr_p) = TREE_BLOCK (call); | 2397 TREE_BLOCK (*expr_p) = TREE_BLOCK (call); |
2411 | 2398 |
2412 /* Set CALL_EXPR_VA_ARG_PACK. */ | 2399 /* Set CALL_EXPR_VA_ARG_PACK. */ |
2413 CALL_EXPR_VA_ARG_PACK (*expr_p) = 1; | 2400 CALL_EXPR_VA_ARG_PACK (*expr_p) = 1; |
2414 } | 2401 } |
2415 } | 2402 } |
2416 | 2403 |
2417 /* Finally, gimplify the function arguments. */ | 2404 /* Finally, gimplify the function arguments. */ |
2418 if (nargs > 0) | 2405 if (nargs > 0) |
2419 { | 2406 { |
2426 /* Avoid gimplifying the second argument to va_start, which needs to | 2413 /* Avoid gimplifying the second argument to va_start, which needs to |
2427 be the plain PARM_DECL. */ | 2414 be the plain PARM_DECL. */ |
2428 if ((i != 1) || !builtin_va_start_p) | 2415 if ((i != 1) || !builtin_va_start_p) |
2429 { | 2416 { |
2430 t = gimplify_arg (&CALL_EXPR_ARG (*expr_p, i), pre_p, | 2417 t = gimplify_arg (&CALL_EXPR_ARG (*expr_p, i), pre_p, |
2431 EXPR_LOCATION (*expr_p)); | 2418 EXPR_LOCATION (*expr_p)); |
2432 | 2419 |
2433 if (t == GS_ERROR) | 2420 if (t == GS_ERROR) |
2434 ret = GS_ERROR; | 2421 ret = GS_ERROR; |
2435 } | 2422 } |
2436 } | 2423 } |
2448 if (ret != GS_ERROR) | 2435 if (ret != GS_ERROR) |
2449 { | 2436 { |
2450 tree new_tree = fold_call_expr (input_location, *expr_p, !want_value); | 2437 tree new_tree = fold_call_expr (input_location, *expr_p, !want_value); |
2451 | 2438 |
2452 if (new_tree && new_tree != *expr_p) | 2439 if (new_tree && new_tree != *expr_p) |
2453 { | 2440 { |
2454 /* There was a transformation of this call which computes the | 2441 /* There was a transformation of this call which computes the |
2455 same value, but in a more efficient way. Return and try | 2442 same value, but in a more efficient way. Return and try |
2456 again. */ | 2443 again. */ |
2457 *expr_p = new_tree; | 2444 *expr_p = new_tree; |
2458 return GS_OK; | 2445 return GS_OK; |
2459 } | 2446 } |
2460 } | 2447 } |
2461 else | 2448 else |
2462 { | 2449 { |
2463 *expr_p = error_mark_node; | 2450 *expr_p = error_mark_node; |
2464 return GS_ERROR; | 2451 return GS_ERROR; |
2469 calls to "const" functions. */ | 2456 calls to "const" functions. */ |
2470 if (TREE_CODE (*expr_p) == CALL_EXPR) | 2457 if (TREE_CODE (*expr_p) == CALL_EXPR) |
2471 { | 2458 { |
2472 int flags = call_expr_flags (*expr_p); | 2459 int flags = call_expr_flags (*expr_p); |
2473 if (flags & (ECF_CONST | ECF_PURE) | 2460 if (flags & (ECF_CONST | ECF_PURE) |
2474 /* An infinite loop is considered a side effect. */ | 2461 /* An infinite loop is considered a side effect. */ |
2475 && !(flags & (ECF_LOOPING_CONST_OR_PURE))) | 2462 && !(flags & (ECF_LOOPING_CONST_OR_PURE))) |
2476 TREE_SIDE_EFFECTS (*expr_p) = 0; | 2463 TREE_SIDE_EFFECTS (*expr_p) = 0; |
2477 } | 2464 } |
2478 | 2465 |
2479 /* If the value is not needed by the caller, emit a new GIMPLE_CALL | 2466 /* If the value is not needed by the caller, emit a new GIMPLE_CALL |
2480 and clear *EXPR_P. Otherwise, leave *EXPR_P in its gimplified | 2467 and clear *EXPR_P. Otherwise, leave *EXPR_P in its gimplified |
2481 form and delegate the creation of a GIMPLE_CALL to | 2468 form and delegate the creation of a GIMPLE_CALL to |
2512 | 2499 |
2513 shortcut_cond_r should only be called by shortcut_cond_expr. */ | 2500 shortcut_cond_r should only be called by shortcut_cond_expr. */ |
2514 | 2501 |
2515 static tree | 2502 static tree |
2516 shortcut_cond_r (tree pred, tree *true_label_p, tree *false_label_p, | 2503 shortcut_cond_r (tree pred, tree *true_label_p, tree *false_label_p, |
2517 location_t locus) | 2504 location_t locus) |
2518 { | 2505 { |
2519 tree local_label = NULL_TREE; | 2506 tree local_label = NULL_TREE; |
2520 tree t, expr = NULL; | 2507 tree t, expr = NULL; |
2521 | 2508 |
2522 /* OK, it's not a simple case; we need to pull apart the COND_EXPR to | 2509 /* OK, it's not a simple case; we need to pull apart the COND_EXPR to |
2526 { | 2513 { |
2527 location_t new_locus; | 2514 location_t new_locus; |
2528 | 2515 |
2529 /* Turn if (a && b) into | 2516 /* Turn if (a && b) into |
2530 | 2517 |
2531 if (a); else goto no; | 2518 if (a); else goto no; |
2532 if (b) goto yes; else goto no; | 2519 if (b) goto yes; else goto no; |
2533 (no:) */ | 2520 (no:) */ |
2534 | 2521 |
2535 if (false_label_p == NULL) | 2522 if (false_label_p == NULL) |
2536 false_label_p = &local_label; | 2523 false_label_p = &local_label; |
2537 | 2524 |
2538 /* Keep the original source location on the first 'if'. */ | 2525 /* Keep the original source location on the first 'if'. */ |
2539 t = shortcut_cond_r (TREE_OPERAND (pred, 0), NULL, false_label_p, locus); | 2526 t = shortcut_cond_r (TREE_OPERAND (pred, 0), NULL, false_label_p, locus); |
2540 append_to_statement_list (t, &expr); | 2527 append_to_statement_list (t, &expr); |
2541 | 2528 |
2542 /* Set the source location of the && on the second 'if'. */ | 2529 /* Set the source location of the && on the second 'if'. */ |
2543 new_locus = EXPR_HAS_LOCATION (pred) ? EXPR_LOCATION (pred) : locus; | 2530 new_locus = EXPR_HAS_LOCATION (pred) ? EXPR_LOCATION (pred) : locus; |
2544 t = shortcut_cond_r (TREE_OPERAND (pred, 1), true_label_p, false_label_p, | 2531 t = shortcut_cond_r (TREE_OPERAND (pred, 1), true_label_p, false_label_p, |
2545 new_locus); | 2532 new_locus); |
2546 append_to_statement_list (t, &expr); | 2533 append_to_statement_list (t, &expr); |
2547 } | 2534 } |
2548 else if (TREE_CODE (pred) == TRUTH_ORIF_EXPR) | 2535 else if (TREE_CODE (pred) == TRUTH_ORIF_EXPR) |
2549 { | 2536 { |
2550 location_t new_locus; | 2537 location_t new_locus; |
2551 | 2538 |
2552 /* Turn if (a || b) into | 2539 /* Turn if (a || b) into |
2553 | 2540 |
2554 if (a) goto yes; | 2541 if (a) goto yes; |
2555 if (b) goto yes; else goto no; | 2542 if (b) goto yes; else goto no; |
2556 (yes:) */ | 2543 (yes:) */ |
2557 | 2544 |
2558 if (true_label_p == NULL) | 2545 if (true_label_p == NULL) |
2559 true_label_p = &local_label; | 2546 true_label_p = &local_label; |
2560 | 2547 |
2561 /* Keep the original source location on the first 'if'. */ | 2548 /* Keep the original source location on the first 'if'. */ |
2562 t = shortcut_cond_r (TREE_OPERAND (pred, 0), true_label_p, NULL, locus); | 2549 t = shortcut_cond_r (TREE_OPERAND (pred, 0), true_label_p, NULL, locus); |
2563 append_to_statement_list (t, &expr); | 2550 append_to_statement_list (t, &expr); |
2564 | 2551 |
2565 /* Set the source location of the || on the second 'if'. */ | 2552 /* Set the source location of the || on the second 'if'. */ |
2566 new_locus = EXPR_HAS_LOCATION (pred) ? EXPR_LOCATION (pred) : locus; | 2553 new_locus = EXPR_HAS_LOCATION (pred) ? EXPR_LOCATION (pred) : locus; |
2567 t = shortcut_cond_r (TREE_OPERAND (pred, 1), true_label_p, false_label_p, | 2554 t = shortcut_cond_r (TREE_OPERAND (pred, 1), true_label_p, false_label_p, |
2568 new_locus); | 2555 new_locus); |
2569 append_to_statement_list (t, &expr); | 2556 append_to_statement_list (t, &expr); |
2570 } | 2557 } |
2571 else if (TREE_CODE (pred) == COND_EXPR) | 2558 else if (TREE_CODE (pred) == COND_EXPR) |
2572 { | 2559 { |
2573 location_t new_locus; | 2560 location_t new_locus; |
2574 | 2561 |
2575 /* As long as we're messing with gotos, turn if (a ? b : c) into | 2562 /* As long as we're messing with gotos, turn if (a ? b : c) into |
2576 if (a) | 2563 if (a) |
2577 if (b) goto yes; else goto no; | 2564 if (b) goto yes; else goto no; |
2578 else | 2565 else |
2579 if (c) goto yes; else goto no; */ | 2566 if (c) goto yes; else goto no; */ |
2580 | 2567 |
2581 /* Keep the original source location on the first 'if'. Set the source | 2568 /* Keep the original source location on the first 'if'. Set the source |
2582 location of the ? on the second 'if'. */ | 2569 location of the ? on the second 'if'. */ |
2583 new_locus = EXPR_HAS_LOCATION (pred) ? EXPR_LOCATION (pred) : locus; | 2570 new_locus = EXPR_HAS_LOCATION (pred) ? EXPR_LOCATION (pred) : locus; |
2584 expr = build3 (COND_EXPR, void_type_node, TREE_OPERAND (pred, 0), | 2571 expr = build3 (COND_EXPR, void_type_node, TREE_OPERAND (pred, 0), |
2585 shortcut_cond_r (TREE_OPERAND (pred, 1), true_label_p, | 2572 shortcut_cond_r (TREE_OPERAND (pred, 1), true_label_p, |
2586 false_label_p, locus), | 2573 false_label_p, locus), |
2587 shortcut_cond_r (TREE_OPERAND (pred, 2), true_label_p, | 2574 shortcut_cond_r (TREE_OPERAND (pred, 2), true_label_p, |
2588 false_label_p, new_locus)); | 2575 false_label_p, new_locus)); |
2589 } | 2576 } |
2590 else | 2577 else |
2591 { | 2578 { |
2592 expr = build3 (COND_EXPR, void_type_node, pred, | 2579 expr = build3 (COND_EXPR, void_type_node, pred, |
2593 build_and_jump (true_label_p), | 2580 build_and_jump (true_label_p), |
2594 build_and_jump (false_label_p)); | 2581 build_and_jump (false_label_p)); |
2595 SET_EXPR_LOCATION (expr, locus); | 2582 SET_EXPR_LOCATION (expr, locus); |
2596 } | 2583 } |
2597 | 2584 |
2598 if (local_label) | 2585 if (local_label) |
2599 { | 2586 { |
2623 | 2610 |
2624 /* First do simple transformations. */ | 2611 /* First do simple transformations. */ |
2625 if (!else_se) | 2612 if (!else_se) |
2626 { | 2613 { |
2627 /* If there is no 'else', turn | 2614 /* If there is no 'else', turn |
2628 if (a && b) then c | 2615 if (a && b) then c |
2629 into | 2616 into |
2630 if (a) if (b) then c. */ | 2617 if (a) if (b) then c. */ |
2631 while (TREE_CODE (pred) == TRUTH_ANDIF_EXPR) | 2618 while (TREE_CODE (pred) == TRUTH_ANDIF_EXPR) |
2632 { | 2619 { |
2633 /* Keep the original source location on the first 'if'. */ | 2620 /* Keep the original source location on the first 'if'. */ |
2634 location_t locus = EXPR_LOC_OR_HERE (expr); | 2621 location_t locus = EXPR_LOC_OR_HERE (expr); |
2635 TREE_OPERAND (expr, 0) = TREE_OPERAND (pred, 1); | 2622 TREE_OPERAND (expr, 0) = TREE_OPERAND (pred, 1); |
2645 } | 2632 } |
2646 | 2633 |
2647 if (!then_se) | 2634 if (!then_se) |
2648 { | 2635 { |
2649 /* If there is no 'then', turn | 2636 /* If there is no 'then', turn |
2650 if (a || b); else d | 2637 if (a || b); else d |
2651 into | 2638 into |
2652 if (a); else if (b); else d. */ | 2639 if (a); else if (b); else d. */ |
2653 while (TREE_CODE (pred) == TRUTH_ORIF_EXPR) | 2640 while (TREE_CODE (pred) == TRUTH_ORIF_EXPR) |
2654 { | 2641 { |
2655 /* Keep the original source location on the first 'if'. */ | 2642 /* Keep the original source location on the first 'if'. */ |
2656 location_t locus = EXPR_LOC_OR_HERE (expr); | 2643 location_t locus = EXPR_LOC_OR_HERE (expr); |
2657 TREE_OPERAND (expr, 0) = TREE_OPERAND (pred, 1); | 2644 TREE_OPERAND (expr, 0) = TREE_OPERAND (pred, 1); |
2756 | 2743 |
2757 append_to_statement_list (then_, &expr); | 2744 append_to_statement_list (then_, &expr); |
2758 if (else_se) | 2745 if (else_se) |
2759 { | 2746 { |
2760 if (jump_over_else) | 2747 if (jump_over_else) |
2761 { | 2748 { |
2762 tree last = expr_last (expr); | 2749 tree last = expr_last (expr); |
2763 t = build_and_jump (&end_label); | 2750 t = build_and_jump (&end_label); |
2764 if (EXPR_HAS_LOCATION (last)) | 2751 if (EXPR_HAS_LOCATION (last)) |
2765 SET_EXPR_LOCATION (t, EXPR_LOCATION (last)); | 2752 SET_EXPR_LOCATION (t, EXPR_LOCATION (last)); |
2766 append_to_statement_list (t, &expr); | 2753 append_to_statement_list (t, &expr); |
2767 } | 2754 } |
2768 if (emit_false) | 2755 if (emit_false) |
2769 { | 2756 { |
2770 t = build1 (LABEL_EXPR, void_type_node, false_label); | 2757 t = build1 (LABEL_EXPR, void_type_node, false_label); |
2771 append_to_statement_list (t, &expr); | 2758 append_to_statement_list (t, &expr); |
2772 } | 2759 } |
2773 append_to_statement_list (else_, &expr); | 2760 append_to_statement_list (else_, &expr); |
2774 } | 2761 } |
2775 if (emit_end && end_label) | 2762 if (emit_end && end_label) |
2776 { | 2763 { |
2777 t = build1 (LABEL_EXPR, void_type_node, end_label); | 2764 t = build1 (LABEL_EXPR, void_type_node, end_label); |
2843 TREE_TYPE (expr) = boolean_type_node; | 2830 TREE_TYPE (expr) = boolean_type_node; |
2844 return expr; | 2831 return expr; |
2845 | 2832 |
2846 default: | 2833 default: |
2847 /* Other expressions that get here must have boolean values, but | 2834 /* Other expressions that get here must have boolean values, but |
2848 might need to be converted to the appropriate mode. */ | 2835 might need to be converted to the appropriate mode. */ |
2849 return fold_convert_loc (loc, boolean_type_node, expr); | 2836 return fold_convert_loc (loc, boolean_type_node, expr); |
2850 } | 2837 } |
2851 } | 2838 } |
2852 | 2839 |
2853 /* Given a conditional expression *EXPR_P without side effects, gimplify | 2840 /* Given a conditional expression *EXPR_P without side effects, gimplify |
2871 TREE_SET_CODE (cond, TRUTH_OR_EXPR); | 2858 TREE_SET_CODE (cond, TRUTH_OR_EXPR); |
2872 ret = gimplify_expr (&cond, pre_p, NULL, is_gimple_condexpr, fb_rvalue); | 2859 ret = gimplify_expr (&cond, pre_p, NULL, is_gimple_condexpr, fb_rvalue); |
2873 COND_EXPR_COND (*expr_p) = cond; | 2860 COND_EXPR_COND (*expr_p) = cond; |
2874 | 2861 |
2875 tret = gimplify_expr (&COND_EXPR_THEN (expr), pre_p, NULL, | 2862 tret = gimplify_expr (&COND_EXPR_THEN (expr), pre_p, NULL, |
2876 is_gimple_val, fb_rvalue); | 2863 is_gimple_val, fb_rvalue); |
2877 ret = MIN (ret, tret); | 2864 ret = MIN (ret, tret); |
2878 tret = gimplify_expr (&COND_EXPR_ELSE (expr), pre_p, NULL, | 2865 tret = gimplify_expr (&COND_EXPR_ELSE (expr), pre_p, NULL, |
2879 is_gimple_val, fb_rvalue); | 2866 is_gimple_val, fb_rvalue); |
2880 | 2867 |
2881 return MIN (ret, tret); | 2868 return MIN (ret, tret); |
2882 } | 2869 } |
2883 | 2870 |
2884 /* Returns true if evaluating EXPR could trap. | 2871 /* Returns true if evaluating EXPR could trap. |
2905 } | 2892 } |
2906 | 2893 |
2907 /* Convert the conditional expression pointed to by EXPR_P '(p) ? a : b;' | 2894 /* Convert the conditional expression pointed to by EXPR_P '(p) ? a : b;' |
2908 into | 2895 into |
2909 | 2896 |
2910 if (p) if (p) | 2897 if (p) if (p) |
2911 t1 = a; a; | 2898 t1 = a; a; |
2912 else or else | 2899 else or else |
2913 t1 = b; b; | 2900 t1 = b; b; |
2914 t1; | 2901 t1; |
2915 | 2902 |
2916 The second form is used when *EXPR_P is of type void. | 2903 The second form is used when *EXPR_P is of type void. |
2917 | 2904 |
2918 PRE_P points to the list where side effects that must happen before | 2905 PRE_P points to the list where side effects that must happen before |
3002 || TREE_CODE (TREE_OPERAND (expr, 0)) == TRUTH_ORIF_EXPR) | 2989 || TREE_CODE (TREE_OPERAND (expr, 0)) == TRUTH_ORIF_EXPR) |
3003 { | 2990 { |
3004 expr = shortcut_cond_expr (expr); | 2991 expr = shortcut_cond_expr (expr); |
3005 | 2992 |
3006 if (expr != *expr_p) | 2993 if (expr != *expr_p) |
3007 { | 2994 { |
3008 *expr_p = expr; | 2995 *expr_p = expr; |
3009 | 2996 |
3010 /* We can't rely on gimplify_expr to re-gimplify the expanded | 2997 /* We can't rely on gimplify_expr to re-gimplify the expanded |
3011 form properly, as cleanups might cause the target labels to be | 2998 form properly, as cleanups might cause the target labels to be |
3012 wrapped in a TRY_FINALLY_EXPR. To prevent that, we need to | 2999 wrapped in a TRY_FINALLY_EXPR. To prevent that, we need to |
3013 set up a conditional context. */ | 3000 set up a conditional context. */ |
3014 gimple_push_condition (); | 3001 gimple_push_condition (); |
3015 gimplify_stmt (expr_p, &seq); | 3002 gimplify_stmt (expr_p, &seq); |
3016 gimple_pop_condition (pre_p); | 3003 gimple_pop_condition (pre_p); |
3017 gimple_seq_add_seq (pre_p, seq); | 3004 gimple_seq_add_seq (pre_p, seq); |
3018 | 3005 |
3019 return GS_ALL_DONE; | 3006 return GS_ALL_DONE; |
3020 } | 3007 } |
3021 } | 3008 } |
3022 | 3009 |
3023 /* Now do the normal gimplification. */ | 3010 /* Now do the normal gimplification. */ |
3024 | 3011 |
3025 /* Gimplify condition. */ | 3012 /* Gimplify condition. */ |
3026 ret = gimplify_expr (&TREE_OPERAND (expr, 0), pre_p, NULL, is_gimple_condexpr, | 3013 ret = gimplify_expr (&TREE_OPERAND (expr, 0), pre_p, NULL, is_gimple_condexpr, |
3027 fb_rvalue); | 3014 fb_rvalue); |
3028 if (ret == GS_ERROR) | 3015 if (ret == GS_ERROR) |
3029 return GS_ERROR; | 3016 return GS_ERROR; |
3030 gcc_assert (TREE_OPERAND (expr, 0) != NULL_TREE); | 3017 gcc_assert (TREE_OPERAND (expr, 0) != NULL_TREE); |
3031 | 3018 |
3032 gimple_push_condition (); | 3019 gimple_push_condition (); |
3034 have_then_clause_p = have_else_clause_p = false; | 3021 have_then_clause_p = have_else_clause_p = false; |
3035 if (TREE_OPERAND (expr, 1) != NULL | 3022 if (TREE_OPERAND (expr, 1) != NULL |
3036 && TREE_CODE (TREE_OPERAND (expr, 1)) == GOTO_EXPR | 3023 && TREE_CODE (TREE_OPERAND (expr, 1)) == GOTO_EXPR |
3037 && TREE_CODE (GOTO_DESTINATION (TREE_OPERAND (expr, 1))) == LABEL_DECL | 3024 && TREE_CODE (GOTO_DESTINATION (TREE_OPERAND (expr, 1))) == LABEL_DECL |
3038 && (DECL_CONTEXT (GOTO_DESTINATION (TREE_OPERAND (expr, 1))) | 3025 && (DECL_CONTEXT (GOTO_DESTINATION (TREE_OPERAND (expr, 1))) |
3039 == current_function_decl) | 3026 == current_function_decl) |
3040 /* For -O0 avoid this optimization if the COND_EXPR and GOTO_EXPR | 3027 /* For -O0 avoid this optimization if the COND_EXPR and GOTO_EXPR |
3041 have different locations, otherwise we end up with incorrect | 3028 have different locations, otherwise we end up with incorrect |
3042 location information on the branches. */ | 3029 location information on the branches. */ |
3043 && (optimize | 3030 && (optimize |
3044 || !EXPR_HAS_LOCATION (expr) | 3031 || !EXPR_HAS_LOCATION (expr) |
3045 || !EXPR_HAS_LOCATION (TREE_OPERAND (expr, 1)) | 3032 || !EXPR_HAS_LOCATION (TREE_OPERAND (expr, 1)) |
3046 || EXPR_LOCATION (expr) == EXPR_LOCATION (TREE_OPERAND (expr, 1)))) | 3033 || EXPR_LOCATION (expr) == EXPR_LOCATION (TREE_OPERAND (expr, 1)))) |
3047 { | 3034 { |
3048 label_true = GOTO_DESTINATION (TREE_OPERAND (expr, 1)); | 3035 label_true = GOTO_DESTINATION (TREE_OPERAND (expr, 1)); |
3049 have_then_clause_p = true; | 3036 have_then_clause_p = true; |
3050 } | 3037 } |
3051 else | 3038 else |
3052 label_true = create_artificial_label (UNKNOWN_LOCATION); | 3039 label_true = create_artificial_label (UNKNOWN_LOCATION); |
3053 if (TREE_OPERAND (expr, 2) != NULL | 3040 if (TREE_OPERAND (expr, 2) != NULL |
3054 && TREE_CODE (TREE_OPERAND (expr, 2)) == GOTO_EXPR | 3041 && TREE_CODE (TREE_OPERAND (expr, 2)) == GOTO_EXPR |
3055 && TREE_CODE (GOTO_DESTINATION (TREE_OPERAND (expr, 2))) == LABEL_DECL | 3042 && TREE_CODE (GOTO_DESTINATION (TREE_OPERAND (expr, 2))) == LABEL_DECL |
3056 && (DECL_CONTEXT (GOTO_DESTINATION (TREE_OPERAND (expr, 2))) | 3043 && (DECL_CONTEXT (GOTO_DESTINATION (TREE_OPERAND (expr, 2))) |
3057 == current_function_decl) | 3044 == current_function_decl) |
3058 /* For -O0 avoid this optimization if the COND_EXPR and GOTO_EXPR | 3045 /* For -O0 avoid this optimization if the COND_EXPR and GOTO_EXPR |
3059 have different locations, otherwise we end up with incorrect | 3046 have different locations, otherwise we end up with incorrect |
3060 location information on the branches. */ | 3047 location information on the branches. */ |
3061 && (optimize | 3048 && (optimize |
3062 || !EXPR_HAS_LOCATION (expr) | 3049 || !EXPR_HAS_LOCATION (expr) |
3063 || !EXPR_HAS_LOCATION (TREE_OPERAND (expr, 2)) | 3050 || !EXPR_HAS_LOCATION (TREE_OPERAND (expr, 2)) |
3064 || EXPR_LOCATION (expr) == EXPR_LOCATION (TREE_OPERAND (expr, 2)))) | 3051 || EXPR_LOCATION (expr) == EXPR_LOCATION (TREE_OPERAND (expr, 2)))) |
3065 { | 3052 { |
3066 label_false = GOTO_DESTINATION (TREE_OPERAND (expr, 2)); | 3053 label_false = GOTO_DESTINATION (TREE_OPERAND (expr, 2)); |
3067 have_else_clause_p = true; | 3054 have_else_clause_p = true; |
3068 } | 3055 } |
3069 else | 3056 else |
3070 label_false = create_artificial_label (UNKNOWN_LOCATION); | 3057 label_false = create_artificial_label (UNKNOWN_LOCATION); |
3071 | 3058 |
3072 gimple_cond_get_ops_from_tree (COND_EXPR_COND (expr), &pred_code, &arm1, | 3059 gimple_cond_get_ops_from_tree (COND_EXPR_COND (expr), &pred_code, &arm1, |
3073 &arm2); | 3060 &arm2); |
3074 | 3061 |
3075 gimple_cond = gimple_build_cond (pred_code, arm1, arm2, label_true, | 3062 gimple_cond = gimple_build_cond (pred_code, arm1, arm2, label_true, |
3076 label_false); | 3063 label_false); |
3077 | 3064 |
3078 gimplify_seq_add_stmt (&seq, gimple_cond); | 3065 gimplify_seq_add_stmt (&seq, gimple_cond); |
3079 label_cont = NULL_TREE; | 3066 label_cont = NULL_TREE; |
3080 if (!have_then_clause_p) | 3067 if (!have_then_clause_p) |
3081 { | 3068 { |
3082 /* For if (...) {} else { code; } put label_true after | 3069 /* For if (...) {} else { code; } put label_true after |
3083 the else block. */ | 3070 the else block. */ |
3084 if (TREE_OPERAND (expr, 1) == NULL_TREE | 3071 if (TREE_OPERAND (expr, 1) == NULL_TREE |
3085 && !have_else_clause_p | 3072 && !have_else_clause_p |
3086 && TREE_OPERAND (expr, 2) != NULL_TREE) | 3073 && TREE_OPERAND (expr, 2) != NULL_TREE) |
3087 label_cont = label_true; | 3074 label_cont = label_true; |
3088 else | 3075 else |
3089 { | 3076 { |
3090 gimplify_seq_add_stmt (&seq, gimple_build_label (label_true)); | 3077 gimplify_seq_add_stmt (&seq, gimple_build_label (label_true)); |
3091 have_then_clause_p = gimplify_stmt (&TREE_OPERAND (expr, 1), &seq); | 3078 have_then_clause_p = gimplify_stmt (&TREE_OPERAND (expr, 1), &seq); |
3092 /* For if (...) { code; } else {} or | 3079 /* For if (...) { code; } else {} or |
3093 if (...) { code; } else goto label; or | 3080 if (...) { code; } else goto label; or |
3094 if (...) { code; return; } else { ... } | 3081 if (...) { code; return; } else { ... } |
3095 label_cont isn't needed. */ | 3082 label_cont isn't needed. */ |
3096 if (!have_else_clause_p | 3083 if (!have_else_clause_p |
3097 && TREE_OPERAND (expr, 2) != NULL_TREE | 3084 && TREE_OPERAND (expr, 2) != NULL_TREE |
3098 && gimple_seq_may_fallthru (seq)) | 3085 && gimple_seq_may_fallthru (seq)) |
3099 { | 3086 { |
3100 gimple g; | 3087 gimple g; |
3101 label_cont = create_artificial_label (UNKNOWN_LOCATION); | 3088 label_cont = create_artificial_label (UNKNOWN_LOCATION); |
3102 | 3089 |
3103 g = gimple_build_goto (label_cont); | 3090 g = gimple_build_goto (label_cont); |
3104 | 3091 |
3105 /* GIMPLE_COND's are very low level; they have embedded | 3092 /* GIMPLE_COND's are very low level; they have embedded |
3106 gotos. This particular embedded goto should not be marked | 3093 gotos. This particular embedded goto should not be marked |
3107 with the location of the original COND_EXPR, as it would | 3094 with the location of the original COND_EXPR, as it would |
3108 correspond to the COND_EXPR's condition, not the ELSE or the | 3095 correspond to the COND_EXPR's condition, not the ELSE or the |
3109 THEN arms. To avoid marking it with the wrong location, flag | 3096 THEN arms. To avoid marking it with the wrong location, flag |
3110 it as "no location". */ | 3097 it as "no location". */ |
3111 gimple_set_do_not_emit_location (g); | 3098 gimple_set_do_not_emit_location (g); |
3112 | 3099 |
3113 gimplify_seq_add_stmt (&seq, g); | 3100 gimplify_seq_add_stmt (&seq, g); |
3114 } | 3101 } |
3115 } | 3102 } |
3116 } | 3103 } |
3117 if (!have_else_clause_p) | 3104 if (!have_else_clause_p) |
3118 { | 3105 { |
3119 gimplify_seq_add_stmt (&seq, gimple_build_label (label_false)); | 3106 gimplify_seq_add_stmt (&seq, gimple_build_label (label_false)); |
3120 have_else_clause_p = gimplify_stmt (&TREE_OPERAND (expr, 2), &seq); | 3107 have_else_clause_p = gimplify_stmt (&TREE_OPERAND (expr, 2), &seq); |
3162 /* A subroutine of gimplify_modify_expr. Replace a MODIFY_EXPR with | 3149 /* A subroutine of gimplify_modify_expr. Replace a MODIFY_EXPR with |
3163 a call to __builtin_memcpy. */ | 3150 a call to __builtin_memcpy. */ |
3164 | 3151 |
3165 static enum gimplify_status | 3152 static enum gimplify_status |
3166 gimplify_modify_expr_to_memcpy (tree *expr_p, tree size, bool want_value, | 3153 gimplify_modify_expr_to_memcpy (tree *expr_p, tree size, bool want_value, |
3167 gimple_seq *seq_p) | 3154 gimple_seq *seq_p) |
3168 { | 3155 { |
3169 tree t, to, to_ptr, from, from_ptr; | 3156 tree t, to, to_ptr, from, from_ptr; |
3170 gimple gs; | 3157 gimple gs; |
3171 location_t loc = EXPR_LOCATION (*expr_p); | 3158 location_t loc = EXPR_LOCATION (*expr_p); |
3172 | 3159 |
3209 a call to __builtin_memset. In this case we know that the RHS is | 3196 a call to __builtin_memset. In this case we know that the RHS is |
3210 a CONSTRUCTOR with an empty element list. */ | 3197 a CONSTRUCTOR with an empty element list. */ |
3211 | 3198 |
3212 static enum gimplify_status | 3199 static enum gimplify_status |
3213 gimplify_modify_expr_to_memset (tree *expr_p, tree size, bool want_value, | 3200 gimplify_modify_expr_to_memset (tree *expr_p, tree size, bool want_value, |
3214 gimple_seq *seq_p) | 3201 gimple_seq *seq_p) |
3215 { | 3202 { |
3216 tree t, from, to, to_ptr; | 3203 tree t, from, to, to_ptr; |
3217 gimple gs; | 3204 gimple gs; |
3218 location_t loc = EXPR_LOCATION (*expr_p); | 3205 location_t loc = EXPR_LOCATION (*expr_p); |
3219 | 3206 |
3223 from = TREE_OPERAND (*expr_p, 1); | 3210 from = TREE_OPERAND (*expr_p, 1); |
3224 if (TREE_CODE (from) == WITH_SIZE_EXPR) | 3211 if (TREE_CODE (from) == WITH_SIZE_EXPR) |
3225 from = TREE_OPERAND (from, 0); | 3212 from = TREE_OPERAND (from, 0); |
3226 | 3213 |
3227 gcc_assert (TREE_CODE (from) == CONSTRUCTOR | 3214 gcc_assert (TREE_CODE (from) == CONSTRUCTOR |
3228 && VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (from))); | 3215 && VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (from))); |
3229 | 3216 |
3230 /* Now proceed. */ | 3217 /* Now proceed. */ |
3231 to = TREE_OPERAND (*expr_p, 0); | 3218 to = TREE_OPERAND (*expr_p, 0); |
3232 | 3219 |
3233 to_ptr = build_fold_addr_expr_loc (loc, to); | 3220 to_ptr = build_fold_addr_expr_loc (loc, to); |
3293 if (TREE_CODE (t) == CALL_EXPR) | 3280 if (TREE_CODE (t) == CALL_EXPR) |
3294 { | 3281 { |
3295 tree type, fntype = TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (t))); | 3282 tree type, fntype = TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (t))); |
3296 | 3283 |
3297 for (type = TYPE_ARG_TYPES (fntype); type; type = TREE_CHAIN (type)) | 3284 for (type = TYPE_ARG_TYPES (fntype); type; type = TREE_CHAIN (type)) |
3298 if (POINTER_TYPE_P (TREE_VALUE (type)) | 3285 if (POINTER_TYPE_P (TREE_VALUE (type)) |
3299 && (!data->lhs_base_decl || TREE_ADDRESSABLE (data->lhs_base_decl)) | 3286 && (!data->lhs_base_decl || TREE_ADDRESSABLE (data->lhs_base_decl)) |
3300 && alias_sets_conflict_p (data->lhs_alias_set, | 3287 && alias_sets_conflict_p (data->lhs_alias_set, |
3301 get_alias_set | 3288 get_alias_set |
3302 (TREE_TYPE (TREE_VALUE (type))))) | 3289 (TREE_TYPE (TREE_VALUE (type))))) |
3303 return t; | 3290 return t; |
3304 } | 3291 } |
3305 | 3292 |
3306 if (IS_TYPE_OR_DECL_P (t)) | 3293 if (IS_TYPE_OR_DECL_P (t)) |
3307 *walk_subtrees = 0; | 3294 *walk_subtrees = 0; |
3308 return NULL; | 3295 return NULL; |
3312 force values that overlap with the lhs (as described by *DATA) | 3299 force values that overlap with the lhs (as described by *DATA) |
3313 into temporaries. */ | 3300 into temporaries. */ |
3314 | 3301 |
3315 static void | 3302 static void |
3316 gimplify_init_ctor_preeval (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, | 3303 gimplify_init_ctor_preeval (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, |
3317 struct gimplify_init_ctor_preeval_data *data) | 3304 struct gimplify_init_ctor_preeval_data *data) |
3318 { | 3305 { |
3319 enum gimplify_status one; | 3306 enum gimplify_status one; |
3320 | 3307 |
3321 /* If the value is constant, then there's nothing to pre-evaluate. */ | 3308 /* If the value is constant, then there's nothing to pre-evaluate. */ |
3322 if (TREE_CONSTANT (*expr_p)) | 3309 if (TREE_CONSTANT (*expr_p)) |
3323 { | 3310 { |
3324 /* Ensure it does not have side effects, it might contain a reference to | 3311 /* Ensure it does not have side effects, it might contain a reference to |
3325 the object we're initializing. */ | 3312 the object we're initializing. */ |
3326 gcc_assert (!TREE_SIDE_EFFECTS (*expr_p)); | 3313 gcc_assert (!TREE_SIDE_EFFECTS (*expr_p)); |
3327 return; | 3314 return; |
3328 } | 3315 } |
3329 | 3316 |
3330 /* If the type has non-trivial constructors, we can't pre-evaluate. */ | 3317 /* If the type has non-trivial constructors, we can't pre-evaluate. */ |
3385 | 3372 |
3386 var = lower; | 3373 var = lower; |
3387 loop_entry: | 3374 loop_entry: |
3388 object[var] = value; | 3375 object[var] = value; |
3389 if (var == upper) | 3376 if (var == upper) |
3390 goto loop_exit; | 3377 goto loop_exit; |
3391 var = var + 1; | 3378 var = var + 1; |
3392 goto loop_entry; | 3379 goto loop_entry; |
3393 loop_exit: | 3380 loop_exit: |
3394 | 3381 |
3395 We increment var _after_ the loop exit check because we might otherwise | 3382 We increment var _after_ the loop exit check because we might otherwise |
3397 | 3384 |
3398 Note that we never have to deal with SAVE_EXPRs here, because this has | 3385 Note that we never have to deal with SAVE_EXPRs here, because this has |
3399 already been taken care of for us, in gimplify_init_ctor_preeval(). */ | 3386 already been taken care of for us, in gimplify_init_ctor_preeval(). */ |
3400 | 3387 |
3401 static void gimplify_init_ctor_eval (tree, VEC(constructor_elt,gc) *, | 3388 static void gimplify_init_ctor_eval (tree, VEC(constructor_elt,gc) *, |
3402 gimple_seq *, bool); | 3389 gimple_seq *, bool); |
3403 | 3390 |
3404 static void | 3391 static void |
3405 gimplify_init_ctor_eval_range (tree object, tree lower, tree upper, | 3392 gimplify_init_ctor_eval_range (tree object, tree lower, tree upper, |
3406 tree value, tree array_elt_type, | 3393 tree value, tree array_elt_type, |
3407 gimple_seq *pre_p, bool cleared) | 3394 gimple_seq *pre_p, bool cleared) |
3408 { | 3395 { |
3409 tree loop_entry_label, loop_exit_label, fall_thru_label; | 3396 tree loop_entry_label, loop_exit_label, fall_thru_label; |
3410 tree var, var_type, cref, tmp; | 3397 tree var, var_type, cref, tmp; |
3411 | 3398 |
3412 loop_entry_label = create_artificial_label (UNKNOWN_LOCATION); | 3399 loop_entry_label = create_artificial_label (UNKNOWN_LOCATION); |
3421 /* Add the loop entry label. */ | 3408 /* Add the loop entry label. */ |
3422 gimplify_seq_add_stmt (pre_p, gimple_build_label (loop_entry_label)); | 3409 gimplify_seq_add_stmt (pre_p, gimple_build_label (loop_entry_label)); |
3423 | 3410 |
3424 /* Build the reference. */ | 3411 /* Build the reference. */ |
3425 cref = build4 (ARRAY_REF, array_elt_type, unshare_expr (object), | 3412 cref = build4 (ARRAY_REF, array_elt_type, unshare_expr (object), |
3426 var, NULL_TREE, NULL_TREE); | 3413 var, NULL_TREE, NULL_TREE); |
3427 | 3414 |
3428 /* If we are a constructor, just call gimplify_init_ctor_eval to do | 3415 /* If we are a constructor, just call gimplify_init_ctor_eval to do |
3429 the store. Otherwise just assign value to the reference. */ | 3416 the store. Otherwise just assign value to the reference. */ |
3430 | 3417 |
3431 if (TREE_CODE (value) == CONSTRUCTOR) | 3418 if (TREE_CODE (value) == CONSTRUCTOR) |
3432 /* NB we might have to call ourself recursively through | 3419 /* NB we might have to call ourself recursively through |
3433 gimplify_init_ctor_eval if the value is a constructor. */ | 3420 gimplify_init_ctor_eval if the value is a constructor. */ |
3434 gimplify_init_ctor_eval (cref, CONSTRUCTOR_ELTS (value), | 3421 gimplify_init_ctor_eval (cref, CONSTRUCTOR_ELTS (value), |
3435 pre_p, cleared); | 3422 pre_p, cleared); |
3436 else | 3423 else |
3437 gimplify_seq_add_stmt (pre_p, gimple_build_assign (cref, value)); | 3424 gimplify_seq_add_stmt (pre_p, gimple_build_assign (cref, value)); |
3438 | 3425 |
3439 /* We exit the loop when the index var is equal to the upper bound. */ | 3426 /* We exit the loop when the index var is equal to the upper bound. */ |
3440 gimplify_seq_add_stmt (pre_p, | 3427 gimplify_seq_add_stmt (pre_p, |
3441 gimple_build_cond (EQ_EXPR, var, upper, | 3428 gimple_build_cond (EQ_EXPR, var, upper, |
3442 loop_exit_label, fall_thru_label)); | 3429 loop_exit_label, fall_thru_label)); |
3443 | 3430 |
3444 gimplify_seq_add_stmt (pre_p, gimple_build_label (fall_thru_label)); | 3431 gimplify_seq_add_stmt (pre_p, gimple_build_label (fall_thru_label)); |
3445 | 3432 |
3446 /* Otherwise, increment the index var... */ | 3433 /* Otherwise, increment the index var... */ |
3447 tmp = build2 (PLUS_EXPR, var_type, var, | 3434 tmp = build2 (PLUS_EXPR, var_type, var, |
3448 fold_convert (var_type, integer_one_node)); | 3435 fold_convert (var_type, integer_one_node)); |
3449 gimplify_seq_add_stmt (pre_p, gimple_build_assign (var, tmp)); | 3436 gimplify_seq_add_stmt (pre_p, gimple_build_assign (var, tmp)); |
3450 | 3437 |
3451 /* ...and jump back to the loop entry. */ | 3438 /* ...and jump back to the loop entry. */ |
3452 gimplify_seq_add_stmt (pre_p, gimple_build_goto (loop_entry_label)); | 3439 gimplify_seq_add_stmt (pre_p, gimple_build_goto (loop_entry_label)); |
3453 | 3440 |
3483 CONSTRUCTOR. CLEARED is true if the entire LHS object has been | 3470 CONSTRUCTOR. CLEARED is true if the entire LHS object has been |
3484 zeroed first. */ | 3471 zeroed first. */ |
3485 | 3472 |
3486 static void | 3473 static void |
3487 gimplify_init_ctor_eval (tree object, VEC(constructor_elt,gc) *elts, | 3474 gimplify_init_ctor_eval (tree object, VEC(constructor_elt,gc) *elts, |
3488 gimple_seq *pre_p, bool cleared) | 3475 gimple_seq *pre_p, bool cleared) |
3489 { | 3476 { |
3490 tree array_elt_type = NULL; | 3477 tree array_elt_type = NULL; |
3491 unsigned HOST_WIDE_INT ix; | 3478 unsigned HOST_WIDE_INT ix; |
3492 tree purpose, value; | 3479 tree purpose, value; |
3493 | 3480 |
3498 { | 3485 { |
3499 tree cref; | 3486 tree cref; |
3500 | 3487 |
3501 /* NULL values are created above for gimplification errors. */ | 3488 /* NULL values are created above for gimplification errors. */ |
3502 if (value == NULL) | 3489 if (value == NULL) |
3503 continue; | 3490 continue; |
3504 | 3491 |
3505 if (cleared && initializer_zerop (value)) | 3492 if (cleared && initializer_zerop (value)) |
3506 continue; | 3493 continue; |
3507 | 3494 |
3508 /* ??? Here's to hoping the front end fills in all of the indices, | 3495 /* ??? Here's to hoping the front end fills in all of the indices, |
3509 so we don't have to figure out what's missing ourselves. */ | 3496 so we don't have to figure out what's missing ourselves. */ |
3510 gcc_assert (purpose); | 3497 gcc_assert (purpose); |
3511 | 3498 |
3512 /* Skip zero-sized fields, unless value has side-effects. This can | 3499 /* Skip zero-sized fields, unless value has side-effects. This can |
3513 happen with calls to functions returning a zero-sized type, which | 3500 happen with calls to functions returning a zero-sized type, which |
3514 we shouldn't discard. As a number of downstream passes don't | 3501 we shouldn't discard. As a number of downstream passes don't |
3515 expect sets of zero-sized fields, we rely on the gimplification of | 3502 expect sets of zero-sized fields, we rely on the gimplification of |
3516 the MODIFY_EXPR we make below to drop the assignment statement. */ | 3503 the MODIFY_EXPR we make below to drop the assignment statement. */ |
3517 if (! TREE_SIDE_EFFECTS (value) && zero_sized_field_decl (purpose)) | 3504 if (! TREE_SIDE_EFFECTS (value) && zero_sized_field_decl (purpose)) |
3518 continue; | 3505 continue; |
3519 | 3506 |
3520 /* If we have a RANGE_EXPR, we have to build a loop to assign the | 3507 /* If we have a RANGE_EXPR, we have to build a loop to assign the |
3521 whole range. */ | 3508 whole range. */ |
3522 if (TREE_CODE (purpose) == RANGE_EXPR) | 3509 if (TREE_CODE (purpose) == RANGE_EXPR) |
3523 { | 3510 { |
3524 tree lower = TREE_OPERAND (purpose, 0); | 3511 tree lower = TREE_OPERAND (purpose, 0); |
3525 tree upper = TREE_OPERAND (purpose, 1); | 3512 tree upper = TREE_OPERAND (purpose, 1); |
3526 | 3513 |
3527 /* If the lower bound is equal to upper, just treat it as if | 3514 /* If the lower bound is equal to upper, just treat it as if |
3528 upper was the index. */ | 3515 upper was the index. */ |
3529 if (simple_cst_equal (lower, upper)) | 3516 if (simple_cst_equal (lower, upper)) |
3530 purpose = upper; | 3517 purpose = upper; |
3518 else | |
3519 { | |
3520 gimplify_init_ctor_eval_range (object, lower, upper, value, | |
3521 array_elt_type, pre_p, cleared); | |
3522 continue; | |
3523 } | |
3524 } | |
3525 | |
3526 if (array_elt_type) | |
3527 { | |
3528 /* Do not use bitsizetype for ARRAY_REF indices. */ | |
3529 if (TYPE_DOMAIN (TREE_TYPE (object))) | |
3530 purpose = fold_convert (TREE_TYPE (TYPE_DOMAIN (TREE_TYPE (object))), | |
3531 purpose); | |
3532 cref = build4 (ARRAY_REF, array_elt_type, unshare_expr (object), | |
3533 purpose, NULL_TREE, NULL_TREE); | |
3534 } | |
3531 else | 3535 else |
3532 { | 3536 { |
3533 gimplify_init_ctor_eval_range (object, lower, upper, value, | 3537 gcc_assert (TREE_CODE (purpose) == FIELD_DECL); |
3534 array_elt_type, pre_p, cleared); | 3538 cref = build3 (COMPONENT_REF, TREE_TYPE (purpose), |
3535 continue; | 3539 unshare_expr (object), purpose, NULL_TREE); |
3536 } | 3540 } |
3537 } | 3541 |
3538 | 3542 if (TREE_CODE (value) == CONSTRUCTOR |
3539 if (array_elt_type) | 3543 && TREE_CODE (TREE_TYPE (value)) != VECTOR_TYPE) |
3540 { | 3544 gimplify_init_ctor_eval (cref, CONSTRUCTOR_ELTS (value), |
3541 /* Do not use bitsizetype for ARRAY_REF indices. */ | 3545 pre_p, cleared); |
3542 if (TYPE_DOMAIN (TREE_TYPE (object))) | |
3543 purpose = fold_convert (TREE_TYPE (TYPE_DOMAIN (TREE_TYPE (object))), | |
3544 purpose); | |
3545 cref = build4 (ARRAY_REF, array_elt_type, unshare_expr (object), | |
3546 purpose, NULL_TREE, NULL_TREE); | |
3547 } | |
3548 else | 3546 else |
3549 { | 3547 { |
3550 gcc_assert (TREE_CODE (purpose) == FIELD_DECL); | 3548 tree init = build2 (INIT_EXPR, TREE_TYPE (cref), cref, value); |
3551 cref = build3 (COMPONENT_REF, TREE_TYPE (purpose), | 3549 gimplify_and_add (init, pre_p); |
3552 unshare_expr (object), purpose, NULL_TREE); | 3550 ggc_free (init); |
3553 } | 3551 } |
3554 | |
3555 if (TREE_CODE (value) == CONSTRUCTOR | |
3556 && TREE_CODE (TREE_TYPE (value)) != VECTOR_TYPE) | |
3557 gimplify_init_ctor_eval (cref, CONSTRUCTOR_ELTS (value), | |
3558 pre_p, cleared); | |
3559 else | |
3560 { | |
3561 tree init = build2 (INIT_EXPR, TREE_TYPE (cref), cref, value); | |
3562 gimplify_and_add (init, pre_p); | |
3563 ggc_free (init); | |
3564 } | |
3565 } | 3552 } |
3566 } | 3553 } |
3567 | 3554 |
3568 | 3555 |
3569 /* Returns the appropriate RHS predicate for this LHS. */ | 3556 /* Returns the appropriate RHS predicate for this LHS. */ |
3625 for (idx = 0; idx < num; idx++) | 3612 for (idx = 0; idx < num; idx++) |
3626 { | 3613 { |
3627 tree value = VEC_index (constructor_elt, elts, idx)->value; | 3614 tree value = VEC_index (constructor_elt, elts, idx)->value; |
3628 tree newval = value; | 3615 tree newval = value; |
3629 if (TREE_CODE (value) == CONSTRUCTOR) | 3616 if (TREE_CODE (value) == CONSTRUCTOR) |
3630 newval = optimize_compound_literals_in_ctor (value); | 3617 newval = optimize_compound_literals_in_ctor (value); |
3631 else if (TREE_CODE (value) == COMPOUND_LITERAL_EXPR) | 3618 else if (TREE_CODE (value) == COMPOUND_LITERAL_EXPR) |
3632 { | 3619 { |
3633 tree decl_s = COMPOUND_LITERAL_EXPR_DECL_EXPR (value); | 3620 tree decl_s = COMPOUND_LITERAL_EXPR_DECL_EXPR (value); |
3634 tree decl = DECL_EXPR_DECL (decl_s); | 3621 tree decl = DECL_EXPR_DECL (decl_s); |
3635 tree init = DECL_INITIAL (decl); | 3622 tree init = DECL_INITIAL (decl); |
3636 | 3623 |
3637 if (!TREE_ADDRESSABLE (value) | 3624 if (!TREE_ADDRESSABLE (value) |
3638 && !TREE_ADDRESSABLE (decl) | 3625 && !TREE_ADDRESSABLE (decl) |
3639 && init) | 3626 && init) |
3640 newval = optimize_compound_literals_in_ctor (init); | 3627 newval = optimize_compound_literals_in_ctor (init); |
3641 } | 3628 } |
3642 if (newval == value) | 3629 if (newval == value) |
3643 continue; | 3630 continue; |
3644 | 3631 |
3645 if (ctor == orig_ctor) | 3632 if (ctor == orig_ctor) |
3646 { | 3633 { |
3647 ctor = copy_node (orig_ctor); | 3634 ctor = copy_node (orig_ctor); |
3648 CONSTRUCTOR_ELTS (ctor) = VEC_copy (constructor_elt, gc, elts); | 3635 CONSTRUCTOR_ELTS (ctor) = VEC_copy (constructor_elt, gc, elts); |
3649 elts = CONSTRUCTOR_ELTS (ctor); | 3636 elts = CONSTRUCTOR_ELTS (ctor); |
3650 } | 3637 } |
3651 VEC_index (constructor_elt, elts, idx)->value = newval; | 3638 VEC_index (constructor_elt, elts, idx)->value = newval; |
3652 } | 3639 } |
3653 return ctor; | 3640 return ctor; |
3654 } | 3641 } |
3655 | 3642 |
3668 | 3655 |
3669 If NOTIFY_TEMP_CREATION is false, just do the gimplification. */ | 3656 If NOTIFY_TEMP_CREATION is false, just do the gimplification. */ |
3670 | 3657 |
3671 static enum gimplify_status | 3658 static enum gimplify_status |
3672 gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, | 3659 gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, |
3673 bool want_value, bool notify_temp_creation) | 3660 bool want_value, bool notify_temp_creation) |
3674 { | 3661 { |
3675 tree object, ctor, type; | 3662 tree object, ctor, type; |
3676 enum gimplify_status ret; | 3663 enum gimplify_status ret; |
3677 VEC(constructor_elt,gc) *elts; | 3664 VEC(constructor_elt,gc) *elts; |
3678 | 3665 |
3679 gcc_assert (TREE_CODE (TREE_OPERAND (*expr_p, 1)) == CONSTRUCTOR); | 3666 gcc_assert (TREE_CODE (TREE_OPERAND (*expr_p, 1)) == CONSTRUCTOR); |
3680 | 3667 |
3681 if (!notify_temp_creation) | 3668 if (!notify_temp_creation) |
3682 { | 3669 { |
3683 ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p, | 3670 ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p, |
3684 is_gimple_lvalue, fb_lvalue); | 3671 is_gimple_lvalue, fb_lvalue); |
3685 if (ret == GS_ERROR) | 3672 if (ret == GS_ERROR) |
3686 return ret; | 3673 return ret; |
3687 } | 3674 } |
3688 | 3675 |
3689 object = TREE_OPERAND (*expr_p, 0); | 3676 object = TREE_OPERAND (*expr_p, 0); |
3690 ctor = TREE_OPERAND (*expr_p, 1) = | 3677 ctor = TREE_OPERAND (*expr_p, 1) = |
3691 optimize_compound_literals_in_ctor (TREE_OPERAND (*expr_p, 1)); | 3678 optimize_compound_literals_in_ctor (TREE_OPERAND (*expr_p, 1)); |
3994 return GS_OK; | 3981 return GS_OK; |
3995 } | 3982 } |
3996 else | 3983 else |
3997 { | 3984 { |
3998 /* If we have gimplified both sides of the initializer but have | 3985 /* If we have gimplified both sides of the initializer but have |
3999 not emitted an assignment, do so now. */ | 3986 not emitted an assignment, do so now. */ |
4000 if (*expr_p) | 3987 if (*expr_p) |
4001 { | 3988 { |
4002 tree lhs = TREE_OPERAND (*expr_p, 0); | 3989 tree lhs = TREE_OPERAND (*expr_p, 0); |
4003 tree rhs = TREE_OPERAND (*expr_p, 1); | 3990 tree rhs = TREE_OPERAND (*expr_p, 1); |
4004 gimple init = gimple_build_assign (lhs, rhs); | 3991 gimple init = gimple_build_assign (lhs, rhs); |
4005 gimplify_seq_add_stmt (pre_p, init); | 3992 gimplify_seq_add_stmt (pre_p, init); |
4006 *expr_p = NULL; | 3993 *expr_p = NULL; |
4007 } | 3994 } |
4008 | 3995 |
4009 return GS_ALL_DONE; | 3996 return GS_ALL_DONE; |
4010 } | 3997 } |
4011 } | 3998 } |
4012 | 3999 |
4118 tree type_domain; | 4105 tree type_domain; |
4119 tree min_val = size_zero_node; | 4106 tree min_val = size_zero_node; |
4120 tree osub = sub; | 4107 tree osub = sub; |
4121 sub = gimple_fold_indirect_ref (sub); | 4108 sub = gimple_fold_indirect_ref (sub); |
4122 if (! sub) | 4109 if (! sub) |
4123 sub = build1 (INDIRECT_REF, TREE_TYPE (subtype), osub); | 4110 sub = build1 (INDIRECT_REF, TREE_TYPE (subtype), osub); |
4124 type_domain = TYPE_DOMAIN (TREE_TYPE (sub)); | 4111 type_domain = TYPE_DOMAIN (TREE_TYPE (sub)); |
4125 if (type_domain && TYPE_MIN_VALUE (type_domain)) | 4112 if (type_domain && TYPE_MIN_VALUE (type_domain)) |
4126 min_val = TYPE_MIN_VALUE (type_domain); | 4113 min_val = TYPE_MIN_VALUE (type_domain); |
4127 if (TREE_CODE (min_val) == INTEGER_CST) | 4114 if (TREE_CODE (min_val) == INTEGER_CST) |
4128 return build4 (ARRAY_REF, type, sub, min_val, NULL_TREE, NULL_TREE); | 4115 return build4 (ARRAY_REF, type, sub, min_val, NULL_TREE, NULL_TREE); |
4148 MODIFY_EXPRs based on the code of the RHS. We loop for as long as | 4135 MODIFY_EXPRs based on the code of the RHS. We loop for as long as |
4149 something changes. */ | 4136 something changes. */ |
4150 | 4137 |
4151 static enum gimplify_status | 4138 static enum gimplify_status |
4152 gimplify_modify_expr_rhs (tree *expr_p, tree *from_p, tree *to_p, | 4139 gimplify_modify_expr_rhs (tree *expr_p, tree *from_p, tree *to_p, |
4153 gimple_seq *pre_p, gimple_seq *post_p, | 4140 gimple_seq *pre_p, gimple_seq *post_p, |
4154 bool want_value) | 4141 bool want_value) |
4155 { | 4142 { |
4156 enum gimplify_status ret = GS_UNHANDLED; | 4143 enum gimplify_status ret = GS_UNHANDLED; |
4157 bool changed; | 4144 bool changed; |
4158 | 4145 |
4159 do | 4146 do |
4464 | 4451 |
4465 | 4452 |
4466 /* Gimplify the MODIFY_EXPR node pointed to by EXPR_P. | 4453 /* Gimplify the MODIFY_EXPR node pointed to by EXPR_P. |
4467 | 4454 |
4468 modify_expr | 4455 modify_expr |
4469 : varname '=' rhs | 4456 : varname '=' rhs |
4470 | '*' ID '=' rhs | 4457 | '*' ID '=' rhs |
4471 | 4458 |
4472 PRE_P points to the list where side effects that must happen before | 4459 PRE_P points to the list where side effects that must happen before |
4473 *EXPR_P should be stored. | 4460 *EXPR_P should be stored. |
4474 | 4461 |
4475 POST_P points to the list where side effects that must happen after | 4462 POST_P points to the list where side effects that must happen after |
4476 *EXPR_P should be stored. | 4463 *EXPR_P should be stored. |
4477 | 4464 |
4478 WANT_VALUE is nonzero iff we want to use the value of this expression | 4465 WANT_VALUE is nonzero iff we want to use the value of this expression |
4479 in another expression. */ | 4466 in another expression. */ |
4480 | 4467 |
4481 static enum gimplify_status | 4468 static enum gimplify_status |
4482 gimplify_modify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, | 4469 gimplify_modify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, |
4483 bool want_value) | 4470 bool want_value) |
4484 { | 4471 { |
4485 tree *from_p = &TREE_OPERAND (*expr_p, 1); | 4472 tree *from_p = &TREE_OPERAND (*expr_p, 1); |
4486 tree *to_p = &TREE_OPERAND (*expr_p, 0); | 4473 tree *to_p = &TREE_OPERAND (*expr_p, 0); |
4487 enum gimplify_status ret = GS_UNHANDLED; | 4474 enum gimplify_status ret = GS_UNHANDLED; |
4488 gimple assign; | 4475 gimple assign; |
4489 location_t loc = EXPR_LOCATION (*expr_p); | 4476 location_t loc = EXPR_LOCATION (*expr_p); |
4490 | 4477 |
4491 gcc_assert (TREE_CODE (*expr_p) == MODIFY_EXPR | 4478 gcc_assert (TREE_CODE (*expr_p) == MODIFY_EXPR |
4492 || TREE_CODE (*expr_p) == INIT_EXPR); | 4479 || TREE_CODE (*expr_p) == INIT_EXPR); |
4493 | 4480 |
4494 /* Insert pointer conversions required by the middle-end that are not | 4481 /* Insert pointer conversions required by the middle-end that are not |
4495 required by the frontend. This fixes middle-end type checking for | 4482 required by the frontend. This fixes middle-end type checking for |
4496 for example gcc.dg/redecl-6.c. */ | 4483 for example gcc.dg/redecl-6.c. */ |
4497 if (POINTER_TYPE_P (TREE_TYPE (*to_p))) | 4484 if (POINTER_TYPE_P (TREE_TYPE (*to_p))) |
4498 { | 4485 { |
4499 STRIP_USELESS_TYPE_CONVERSION (*from_p); | 4486 STRIP_USELESS_TYPE_CONVERSION (*from_p); |
4500 if (!useless_type_conversion_p (TREE_TYPE (*to_p), TREE_TYPE (*from_p))) | 4487 if (!useless_type_conversion_p (TREE_TYPE (*to_p), TREE_TYPE (*from_p))) |
4501 *from_p = fold_convert_loc (loc, TREE_TYPE (*to_p), *from_p); | 4488 *from_p = fold_convert_loc (loc, TREE_TYPE (*to_p), *from_p); |
4502 } | 4489 } |
4503 | 4490 |
4504 /* See if any simplifications can be done based on what the RHS is. */ | 4491 /* See if any simplifications can be done based on what the RHS is. */ |
4505 ret = gimplify_modify_expr_rhs (expr_p, from_p, to_p, pre_p, post_p, | 4492 ret = gimplify_modify_expr_rhs (expr_p, from_p, to_p, pre_p, post_p, |
4506 want_value); | 4493 want_value); |
4507 if (ret != GS_UNHANDLED) | 4494 if (ret != GS_UNHANDLED) |
4508 return ret; | 4495 return ret; |
4509 | 4496 |
4510 /* For zero sized types only gimplify the left hand side and right hand | 4497 /* For zero sized types only gimplify the left hand side and right hand |
4511 side as statements and throw away the assignment. Do this after | 4498 side as statements and throw away the assignment. Do this after |
4542 foo's LHS, we tell it that it should only gimplify until it | 4529 foo's LHS, we tell it that it should only gimplify until it |
4543 reaches the CALL_EXPR. On return from gimplify_expr, the newly | 4530 reaches the CALL_EXPR. On return from gimplify_expr, the newly |
4544 created GIMPLE_CALL <foo> will be the last statement in *PRE_P | 4531 created GIMPLE_CALL <foo> will be the last statement in *PRE_P |
4545 and all we need to do here is set 'a' to be its LHS. */ | 4532 and all we need to do here is set 'a' to be its LHS. */ |
4546 ret = gimplify_expr (from_p, pre_p, post_p, rhs_predicate_for (*to_p), | 4533 ret = gimplify_expr (from_p, pre_p, post_p, rhs_predicate_for (*to_p), |
4547 fb_rvalue); | 4534 fb_rvalue); |
4548 if (ret == GS_ERROR) | 4535 if (ret == GS_ERROR) |
4549 return ret; | 4536 return ret; |
4550 | 4537 |
4551 /* Now see if the above changed *from_p to something we handle specially. */ | 4538 /* Now see if the above changed *from_p to something we handle specially. */ |
4552 ret = gimplify_modify_expr_rhs (expr_p, from_p, to_p, pre_p, post_p, | 4539 ret = gimplify_modify_expr_rhs (expr_p, from_p, to_p, pre_p, post_p, |
4553 want_value); | 4540 want_value); |
4554 if (ret != GS_UNHANDLED) | 4541 if (ret != GS_UNHANDLED) |
4555 return ret; | 4542 return ret; |
4556 | 4543 |
4557 /* If we've got a variable sized assignment between two lvalues (i.e. does | 4544 /* If we've got a variable sized assignment between two lvalues (i.e. does |
4558 not involve a call), then we can make things a bit more straightforward | 4545 not involve a call), then we can make things a bit more straightforward |
4561 { | 4548 { |
4562 tree from = TREE_OPERAND (*from_p, 0); | 4549 tree from = TREE_OPERAND (*from_p, 0); |
4563 tree size = TREE_OPERAND (*from_p, 1); | 4550 tree size = TREE_OPERAND (*from_p, 1); |
4564 | 4551 |
4565 if (TREE_CODE (from) == CONSTRUCTOR) | 4552 if (TREE_CODE (from) == CONSTRUCTOR) |
4566 return gimplify_modify_expr_to_memset (expr_p, size, want_value, pre_p); | 4553 return gimplify_modify_expr_to_memset (expr_p, size, want_value, pre_p); |
4567 | 4554 |
4568 if (is_gimple_addressable (from)) | 4555 if (is_gimple_addressable (from)) |
4569 { | 4556 { |
4570 *from_p = from; | 4557 *from_p = from; |
4571 return gimplify_modify_expr_to_memcpy (expr_p, size, want_value, | 4558 return gimplify_modify_expr_to_memcpy (expr_p, size, want_value, |
4572 pre_p); | 4559 pre_p); |
4573 } | 4560 } |
4574 } | 4561 } |
4575 | 4562 |
4576 /* Transform partial stores to non-addressable complex variables into | 4563 /* Transform partial stores to non-addressable complex variables into |
4577 total stores. This allows us to use real instead of virtual operands | 4564 total stores. This allows us to use real instead of virtual operands |
4578 for these variables, which improves optimization. */ | 4565 for these variables, which improves optimization. */ |
4588 && DECL_IGNORED_P (*from_p) | 4575 && DECL_IGNORED_P (*from_p) |
4589 && DECL_P (*to_p) | 4576 && DECL_P (*to_p) |
4590 && !DECL_IGNORED_P (*to_p)) | 4577 && !DECL_IGNORED_P (*to_p)) |
4591 { | 4578 { |
4592 if (!DECL_NAME (*from_p) && DECL_NAME (*to_p)) | 4579 if (!DECL_NAME (*from_p) && DECL_NAME (*to_p)) |
4593 DECL_NAME (*from_p) | 4580 DECL_NAME (*from_p) |
4594 = create_tmp_var_name (IDENTIFIER_POINTER (DECL_NAME (*to_p))); | 4581 = create_tmp_var_name (IDENTIFIER_POINTER (DECL_NAME (*to_p))); |
4595 DECL_DEBUG_EXPR_IS_FROM (*from_p) = 1; | 4582 DECL_DEBUG_EXPR_IS_FROM (*from_p) = 1; |
4596 SET_DECL_DEBUG_EXPR (*from_p, *to_p); | 4583 SET_DECL_DEBUG_EXPR (*from_p, *to_p); |
4597 } | 4584 } |
4598 | 4585 |
4599 if (want_value && TREE_THIS_VOLATILE (*to_p)) | 4586 if (want_value && TREE_THIS_VOLATILE (*to_p)) |
4600 *from_p = get_initialized_tmp_var (*from_p, pre_p, post_p); | 4587 *from_p = get_initialized_tmp_var (*from_p, pre_p, post_p); |
4601 | 4588 |
4602 if (TREE_CODE (*from_p) == CALL_EXPR) | 4589 if (TREE_CODE (*from_p) == CALL_EXPR) |
4603 { | 4590 { |
4604 /* Since the RHS is a CALL_EXPR, we need to create a GIMPLE_CALL | 4591 /* Since the RHS is a CALL_EXPR, we need to create a GIMPLE_CALL |
4605 instead of a GIMPLE_ASSIGN. */ | 4592 instead of a GIMPLE_ASSIGN. */ |
4606 assign = gimple_build_call_from_tree (*from_p); | 4593 assign = gimple_build_call_from_tree (*from_p); |
4607 if (!gimple_call_noreturn_p (assign)) | 4594 if (!gimple_call_noreturn_p (assign)) |
4608 gimple_call_set_lhs (assign, *to_p); | 4595 gimple_call_set_lhs (assign, *to_p); |
4609 } | 4596 } |
4610 else | 4597 else |
4616 gimplify_seq_add_stmt (pre_p, assign); | 4603 gimplify_seq_add_stmt (pre_p, assign); |
4617 | 4604 |
4618 if (gimplify_ctxp->into_ssa && is_gimple_reg (*to_p)) | 4605 if (gimplify_ctxp->into_ssa && is_gimple_reg (*to_p)) |
4619 { | 4606 { |
4620 /* If we've somehow already got an SSA_NAME on the LHS, then | 4607 /* If we've somehow already got an SSA_NAME on the LHS, then |
4621 we've probably modified it twice. Not good. */ | 4608 we've probably modified it twice. Not good. */ |
4622 gcc_assert (TREE_CODE (*to_p) != SSA_NAME); | 4609 gcc_assert (TREE_CODE (*to_p) != SSA_NAME); |
4623 *to_p = make_ssa_name (*to_p, assign); | 4610 *to_p = make_ssa_name (*to_p, assign); |
4624 gimple_set_lhs (assign, *to_p); | 4611 gimple_set_lhs (assign, *to_p); |
4625 } | 4612 } |
4626 | 4613 |
4687 /* Gimplify TRUTH_ANDIF_EXPR and TRUTH_ORIF_EXPR expressions. EXPR_P | 4674 /* Gimplify TRUTH_ANDIF_EXPR and TRUTH_ORIF_EXPR expressions. EXPR_P |
4688 points to the expression to gimplify. | 4675 points to the expression to gimplify. |
4689 | 4676 |
4690 Expressions of the form 'a && b' are gimplified to: | 4677 Expressions of the form 'a && b' are gimplified to: |
4691 | 4678 |
4692 a && b ? true : false | 4679 a && b ? true : false |
4693 | 4680 |
4694 LOCUS is the source location to be put on the generated COND_EXPR. | 4681 LOCUS is the source location to be put on the generated COND_EXPR. |
4695 gimplify_cond_expr will do the rest. */ | 4682 gimplify_cond_expr will do the rest. */ |
4696 | 4683 |
4697 static enum gimplify_status | 4684 static enum gimplify_status |
4699 { | 4686 { |
4700 /* Preserve the original type of the expression. */ | 4687 /* Preserve the original type of the expression. */ |
4701 tree type = TREE_TYPE (*expr_p); | 4688 tree type = TREE_TYPE (*expr_p); |
4702 | 4689 |
4703 *expr_p = build3 (COND_EXPR, type, *expr_p, | 4690 *expr_p = build3 (COND_EXPR, type, *expr_p, |
4704 fold_convert_loc (locus, type, boolean_true_node), | 4691 fold_convert_loc (locus, type, boolean_true_node), |
4705 fold_convert_loc (locus, type, boolean_false_node)); | 4692 fold_convert_loc (locus, type, boolean_false_node)); |
4706 | 4693 |
4707 SET_EXPR_LOCATION (*expr_p, locus); | 4694 SET_EXPR_LOCATION (*expr_p, locus); |
4708 | 4695 |
4709 return GS_OK; | 4696 return GS_OK; |
4710 } | 4697 } |
4726 do | 4713 do |
4727 { | 4714 { |
4728 tree *sub_p = &TREE_OPERAND (t, 0); | 4715 tree *sub_p = &TREE_OPERAND (t, 0); |
4729 | 4716 |
4730 if (TREE_CODE (*sub_p) == COMPOUND_EXPR) | 4717 if (TREE_CODE (*sub_p) == COMPOUND_EXPR) |
4731 gimplify_compound_expr (sub_p, pre_p, false); | 4718 gimplify_compound_expr (sub_p, pre_p, false); |
4732 else | 4719 else |
4733 gimplify_stmt (sub_p, pre_p); | 4720 gimplify_stmt (sub_p, pre_p); |
4734 | 4721 |
4735 t = TREE_OPERAND (t, 1); | 4722 t = TREE_OPERAND (t, 1); |
4736 } | 4723 } |
4737 while (TREE_CODE (t) == COMPOUND_EXPR); | 4724 while (TREE_CODE (t) == COMPOUND_EXPR); |
4738 | 4725 |
4765 | 4752 |
4766 /* If the SAVE_EXPR has not been resolved, then evaluate it once. */ | 4753 /* If the SAVE_EXPR has not been resolved, then evaluate it once. */ |
4767 if (!SAVE_EXPR_RESOLVED_P (*expr_p)) | 4754 if (!SAVE_EXPR_RESOLVED_P (*expr_p)) |
4768 { | 4755 { |
4769 /* The operand may be a void-valued expression such as SAVE_EXPRs | 4756 /* The operand may be a void-valued expression such as SAVE_EXPRs |
4770 generated by the Java frontend for class initialization. It is | 4757 generated by the Java frontend for class initialization. It is |
4771 being executed only for its side-effects. */ | 4758 being executed only for its side-effects. */ |
4772 if (TREE_TYPE (val) == void_type_node) | 4759 if (TREE_TYPE (val) == void_type_node) |
4773 { | 4760 { |
4774 ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p, | 4761 ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p, |
4775 is_gimple_stmt, fb_none); | 4762 is_gimple_stmt, fb_none); |
4776 val = NULL; | 4763 val = NULL; |
4777 } | 4764 } |
4778 else | 4765 else |
4779 val = get_initialized_tmp_var (val, pre_p, post_p); | 4766 val = get_initialized_tmp_var (val, pre_p, post_p); |
4780 | 4767 |
4781 TREE_OPERAND (*expr_p, 0) = val; | 4768 TREE_OPERAND (*expr_p, 0) = val; |
4782 SAVE_EXPR_RESOLVED_P (*expr_p) = 1; | 4769 SAVE_EXPR_RESOLVED_P (*expr_p) = 1; |
4783 } | 4770 } |
4784 | 4771 |
4788 } | 4775 } |
4789 | 4776 |
4790 /* Re-write the ADDR_EXPR node pointed to by EXPR_P | 4777 /* Re-write the ADDR_EXPR node pointed to by EXPR_P |
4791 | 4778 |
4792 unary_expr | 4779 unary_expr |
4793 : ... | 4780 : ... |
4794 | '&' varname | 4781 | '&' varname |
4795 ... | 4782 ... |
4796 | 4783 |
4797 PRE_P points to the list where side effects that must happen before | 4784 PRE_P points to the list where side effects that must happen before |
4798 *EXPR_P should be stored. | 4785 *EXPR_P should be stored. |
4799 | 4786 |
4800 POST_P points to the list where side effects that must happen after | 4787 POST_P points to the list where side effects that must happen after |
4801 *EXPR_P should be stored. */ | 4788 *EXPR_P should be stored. */ |
4802 | 4789 |
4803 static enum gimplify_status | 4790 static enum gimplify_status |
4804 gimplify_addr_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p) | 4791 gimplify_addr_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p) |
4805 { | 4792 { |
4806 tree expr = *expr_p; | 4793 tree expr = *expr_p; |
4811 switch (TREE_CODE (op0)) | 4798 switch (TREE_CODE (op0)) |
4812 { | 4799 { |
4813 case INDIRECT_REF: | 4800 case INDIRECT_REF: |
4814 do_indirect_ref: | 4801 do_indirect_ref: |
4815 /* Check if we are dealing with an expression of the form '&*ptr'. | 4802 /* Check if we are dealing with an expression of the form '&*ptr'. |
4816 While the front end folds away '&*ptr' into 'ptr', these | 4803 While the front end folds away '&*ptr' into 'ptr', these |
4817 expressions may be generated internally by the compiler (e.g., | 4804 expressions may be generated internally by the compiler (e.g., |
4818 builtins like __builtin_va_end). */ | 4805 builtins like __builtin_va_end). */ |
4819 /* Caution: the silent array decomposition semantics we allow for | 4806 /* Caution: the silent array decomposition semantics we allow for |
4820 ADDR_EXPR means we can't always discard the pair. */ | 4807 ADDR_EXPR means we can't always discard the pair. */ |
4821 /* Gimplification of the ADDR_EXPR operand may drop | 4808 /* Gimplification of the ADDR_EXPR operand may drop |
4822 cv-qualification conversions, so make sure we add them if | 4809 cv-qualification conversions, so make sure we add them if |
4823 needed. */ | 4810 needed. */ |
4824 { | 4811 { |
4825 tree op00 = TREE_OPERAND (op0, 0); | 4812 tree op00 = TREE_OPERAND (op0, 0); |
4826 tree t_expr = TREE_TYPE (expr); | 4813 tree t_expr = TREE_TYPE (expr); |
4827 tree t_op00 = TREE_TYPE (op00); | 4814 tree t_op00 = TREE_TYPE (op00); |
4828 | 4815 |
4829 if (!useless_type_conversion_p (t_expr, t_op00)) | 4816 if (!useless_type_conversion_p (t_expr, t_op00)) |
4830 op00 = fold_convert_loc (loc, TREE_TYPE (expr), op00); | 4817 op00 = fold_convert_loc (loc, TREE_TYPE (expr), op00); |
4831 *expr_p = op00; | 4818 *expr_p = op00; |
4832 ret = GS_OK; | 4819 ret = GS_OK; |
4833 } | 4820 } |
4834 break; | 4821 break; |
4835 | 4822 |
4836 case VIEW_CONVERT_EXPR: | 4823 case VIEW_CONVERT_EXPR: |
4837 /* Take the address of our operand and then convert it to the type of | 4824 /* Take the address of our operand and then convert it to the type of |
4838 this ADDR_EXPR. | 4825 this ADDR_EXPR. |
4839 | 4826 |
4840 ??? The interactions of VIEW_CONVERT_EXPR and aliasing is not at | 4827 ??? The interactions of VIEW_CONVERT_EXPR and aliasing is not at |
4841 all clear. The impact of this transformation is even less clear. */ | 4828 all clear. The impact of this transformation is even less clear. */ |
4842 | 4829 |
4843 /* If the operand is a useless conversion, look through it. Doing so | 4830 /* If the operand is a useless conversion, look through it. Doing so |
4844 guarantees that the ADDR_EXPR and its operand will remain of the | 4831 guarantees that the ADDR_EXPR and its operand will remain of the |
4845 same type. */ | 4832 same type. */ |
4846 if (tree_ssa_useless_type_conversion (TREE_OPERAND (op0, 0))) | 4833 if (tree_ssa_useless_type_conversion (TREE_OPERAND (op0, 0))) |
4847 op0 = TREE_OPERAND (op0, 0); | 4834 op0 = TREE_OPERAND (op0, 0); |
4848 | 4835 |
4849 *expr_p = fold_convert_loc (loc, TREE_TYPE (expr), | 4836 *expr_p = fold_convert_loc (loc, TREE_TYPE (expr), |
4850 build_fold_addr_expr_loc (loc, | 4837 build_fold_addr_expr_loc (loc, |
4851 TREE_OPERAND (op0, 0))); | 4838 TREE_OPERAND (op0, 0))); |
4852 ret = GS_OK; | 4839 ret = GS_OK; |
4853 break; | 4840 break; |
4854 | 4841 |
4855 default: | 4842 default: |
4856 /* We use fb_either here because the C frontend sometimes takes | 4843 /* We use fb_either here because the C frontend sometimes takes |
4857 the address of a call that returns a struct; see | 4844 the address of a call that returns a struct; see |
4858 gcc.dg/c99-array-lval-1.c. The gimplifier will correctly make | 4845 gcc.dg/c99-array-lval-1.c. The gimplifier will correctly make |
4859 the implied temporary explicit. */ | 4846 the implied temporary explicit. */ |
4860 | 4847 |
4861 /* Make the operand addressable. */ | 4848 /* Make the operand addressable. */ |
4862 ret = gimplify_expr (&TREE_OPERAND (expr, 0), pre_p, post_p, | 4849 ret = gimplify_expr (&TREE_OPERAND (expr, 0), pre_p, post_p, |
4863 is_gimple_addressable, fb_either); | 4850 is_gimple_addressable, fb_either); |
4864 if (ret == GS_ERROR) | 4851 if (ret == GS_ERROR) |
4865 break; | 4852 break; |
4866 | 4853 |
4867 /* Then mark it. Beware that it may not be possible to do so directly | 4854 /* Then mark it. Beware that it may not be possible to do so directly |
4868 if a temporary has been created by the gimplification. */ | 4855 if a temporary has been created by the gimplification. */ |
4869 prepare_gimple_addressable (&TREE_OPERAND (expr, 0), pre_p); | 4856 prepare_gimple_addressable (&TREE_OPERAND (expr, 0), pre_p); |
4870 | 4857 |
4871 op0 = TREE_OPERAND (expr, 0); | 4858 op0 = TREE_OPERAND (expr, 0); |
4872 | 4859 |
4873 /* For various reasons, the gimplification of the expression | 4860 /* For various reasons, the gimplification of the expression |
4874 may have made a new INDIRECT_REF. */ | 4861 may have made a new INDIRECT_REF. */ |
4875 if (TREE_CODE (op0) == INDIRECT_REF) | 4862 if (TREE_CODE (op0) == INDIRECT_REF) |
4876 goto do_indirect_ref; | 4863 goto do_indirect_ref; |
4877 | 4864 |
4878 mark_addressable (TREE_OPERAND (expr, 0)); | 4865 mark_addressable (TREE_OPERAND (expr, 0)); |
4879 | 4866 |
4880 /* The FEs may end up building ADDR_EXPRs early on a decl with | 4867 /* The FEs may end up building ADDR_EXPRs early on a decl with |
4881 an incomplete type. Re-build ADDR_EXPRs in canonical form | 4868 an incomplete type. Re-build ADDR_EXPRs in canonical form |
4882 here. */ | 4869 here. */ |
4883 if (!types_compatible_p (TREE_TYPE (op0), TREE_TYPE (TREE_TYPE (expr)))) | 4870 if (!types_compatible_p (TREE_TYPE (op0), TREE_TYPE (TREE_TYPE (expr)))) |
4884 *expr_p = build_fold_addr_expr (op0); | 4871 *expr_p = build_fold_addr_expr (op0); |
4885 | 4872 |
4886 /* Make sure TREE_CONSTANT and TREE_SIDE_EFFECTS are set properly. */ | 4873 /* Make sure TREE_CONSTANT and TREE_SIDE_EFFECTS are set properly. */ |
4887 recompute_tree_invariant_for_addr_expr (*expr_p); | 4874 recompute_tree_invariant_for_addr_expr (*expr_p); |
4888 | 4875 |
4889 /* If we re-built the ADDR_EXPR add a conversion to the original type | 4876 /* If we re-built the ADDR_EXPR add a conversion to the original type |
4890 if required. */ | 4877 if required. */ |
4891 if (!useless_type_conversion_p (TREE_TYPE (expr), TREE_TYPE (*expr_p))) | 4878 if (!useless_type_conversion_p (TREE_TYPE (expr), TREE_TYPE (*expr_p))) |
4892 *expr_p = fold_convert (TREE_TYPE (expr), *expr_p); | 4879 *expr_p = fold_convert (TREE_TYPE (expr), *expr_p); |
4893 | 4880 |
4894 break; | 4881 break; |
4895 } | 4882 } |
4896 | 4883 |
4897 return ret; | 4884 return ret; |
4932 size_t constraint_len; | 4919 size_t constraint_len; |
4933 | 4920 |
4934 link_next = TREE_CHAIN (link); | 4921 link_next = TREE_CHAIN (link); |
4935 | 4922 |
4936 oconstraints[i] | 4923 oconstraints[i] |
4937 = constraint | 4924 = constraint |
4938 = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link))); | 4925 = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link))); |
4939 constraint_len = strlen (constraint); | 4926 constraint_len = strlen (constraint); |
4940 if (constraint_len == 0) | 4927 if (constraint_len == 0) |
4941 continue; | 4928 continue; |
4942 | 4929 |
4943 ok = parse_output_constraint (&constraint, i, 0, 0, | 4930 ok = parse_output_constraint (&constraint, i, 0, 0, |
4944 &allows_mem, &allows_reg, &is_inout); | 4931 &allows_mem, &allows_reg, &is_inout); |
4945 if (!ok) | 4932 if (!ok) |
4946 { | 4933 { |
4947 ret = GS_ERROR; | 4934 ret = GS_ERROR; |
4948 is_inout = false; | 4935 is_inout = false; |
4949 } | 4936 } |
4950 | 4937 |
4951 if (!allows_reg && allows_mem) | 4938 if (!allows_reg && allows_mem) |
4952 mark_addressable (TREE_VALUE (link)); | 4939 mark_addressable (TREE_VALUE (link)); |
4953 | 4940 |
4954 tret = gimplify_expr (&TREE_VALUE (link), pre_p, post_p, | 4941 tret = gimplify_expr (&TREE_VALUE (link), pre_p, post_p, |
4955 is_inout ? is_gimple_min_lval : is_gimple_lvalue, | 4942 is_inout ? is_gimple_min_lval : is_gimple_lvalue, |
4956 fb_lvalue | fb_mayfail); | 4943 fb_lvalue | fb_mayfail); |
4957 if (tret == GS_ERROR) | 4944 if (tret == GS_ERROR) |
4958 { | 4945 { |
4959 error ("invalid lvalue in asm output %d", i); | 4946 error ("invalid lvalue in asm output %d", i); |
4960 ret = tret; | 4947 ret = tret; |
4961 } | 4948 } |
4962 | 4949 |
4963 VEC_safe_push (tree, gc, outputs, link); | 4950 VEC_safe_push (tree, gc, outputs, link); |
4964 TREE_CHAIN (link) = NULL_TREE; | 4951 TREE_CHAIN (link) = NULL_TREE; |
4965 | 4952 |
4966 if (is_inout) | 4953 if (is_inout) |
4967 { | 4954 { |
4968 /* An input/output operand. To give the optimizers more | 4955 /* An input/output operand. To give the optimizers more |
4969 flexibility, split it into separate input and output | 4956 flexibility, split it into separate input and output |
4970 operands. */ | 4957 operands. */ |
4971 tree input; | 4958 tree input; |
4972 char buf[10]; | 4959 char buf[10]; |
4973 | 4960 |
4974 /* Turn the in/out constraint into an output constraint. */ | 4961 /* Turn the in/out constraint into an output constraint. */ |
4975 char *p = xstrdup (constraint); | 4962 char *p = xstrdup (constraint); |
4976 p[0] = '='; | 4963 p[0] = '='; |
4977 TREE_VALUE (TREE_PURPOSE (link)) = build_string (constraint_len, p); | 4964 TREE_VALUE (TREE_PURPOSE (link)) = build_string (constraint_len, p); |
4978 | 4965 |
4979 /* And add a matching input constraint. */ | 4966 /* And add a matching input constraint. */ |
4980 if (allows_reg) | 4967 if (allows_reg) |
4981 { | 4968 { |
4982 sprintf (buf, "%d", i); | 4969 sprintf (buf, "%d", i); |
4983 | 4970 |
4984 /* If there are multiple alternatives in the constraint, | 4971 /* If there are multiple alternatives in the constraint, |
4985 handle each of them individually. Those that allow register | 4972 handle each of them individually. Those that allow register |
4986 will be replaced with operand number, the others will stay | 4973 will be replaced with operand number, the others will stay |
4987 unchanged. */ | 4974 unchanged. */ |
4988 if (strchr (p, ',') != NULL) | 4975 if (strchr (p, ',') != NULL) |
4989 { | 4976 { |
4990 size_t len = 0, buflen = strlen (buf); | 4977 size_t len = 0, buflen = strlen (buf); |
4991 char *beg, *end, *str, *dst; | 4978 char *beg, *end, *str, *dst; |
4992 | 4979 |
4993 for (beg = p + 1;;) | 4980 for (beg = p + 1;;) |
4994 { | 4981 { |
4995 end = strchr (beg, ','); | 4982 end = strchr (beg, ','); |
4996 if (end == NULL) | 4983 if (end == NULL) |
4997 end = strchr (beg, '\0'); | 4984 end = strchr (beg, '\0'); |
4998 if ((size_t) (end - beg) < buflen) | 4985 if ((size_t) (end - beg) < buflen) |
4999 len += buflen + 1; | 4986 len += buflen + 1; |
5000 else | 4987 else |
5001 len += end - beg + 1; | 4988 len += end - beg + 1; |
5002 if (*end) | 4989 if (*end) |
5003 beg = end + 1; | 4990 beg = end + 1; |
5004 else | 4991 else |
5005 break; | 4992 break; |
5006 } | 4993 } |
5007 | 4994 |
5008 str = (char *) alloca (len); | 4995 str = (char *) alloca (len); |
5009 for (beg = p + 1, dst = str;;) | 4996 for (beg = p + 1, dst = str;;) |
5010 { | 4997 { |
5011 const char *tem; | 4998 const char *tem; |
5012 bool mem_p, reg_p, inout_p; | 4999 bool mem_p, reg_p, inout_p; |
5013 | 5000 |
5014 end = strchr (beg, ','); | 5001 end = strchr (beg, ','); |
5015 if (end) | 5002 if (end) |
5016 *end = '\0'; | 5003 *end = '\0'; |
5017 beg[-1] = '='; | 5004 beg[-1] = '='; |
5018 tem = beg - 1; | 5005 tem = beg - 1; |
5019 parse_output_constraint (&tem, i, 0, 0, | 5006 parse_output_constraint (&tem, i, 0, 0, |
5020 &mem_p, ®_p, &inout_p); | 5007 &mem_p, ®_p, &inout_p); |
5021 if (dst != str) | 5008 if (dst != str) |
5022 *dst++ = ','; | 5009 *dst++ = ','; |
5023 if (reg_p) | 5010 if (reg_p) |
5024 { | 5011 { |
5025 memcpy (dst, buf, buflen); | 5012 memcpy (dst, buf, buflen); |
5026 dst += buflen; | 5013 dst += buflen; |
5027 } | 5014 } |
5028 else | 5015 else |
5029 { | 5016 { |
5030 if (end) | 5017 if (end) |
5031 len = end - beg; | 5018 len = end - beg; |
5032 else | 5019 else |
5033 len = strlen (beg); | 5020 len = strlen (beg); |
5034 memcpy (dst, beg, len); | 5021 memcpy (dst, beg, len); |
5035 dst += len; | 5022 dst += len; |
5036 } | 5023 } |
5037 if (end) | 5024 if (end) |
5038 beg = end + 1; | 5025 beg = end + 1; |
5039 else | 5026 else |
5040 break; | 5027 break; |
5041 } | 5028 } |
5042 *dst = '\0'; | 5029 *dst = '\0'; |
5043 input = build_string (dst - str, str); | 5030 input = build_string (dst - str, str); |
5044 } | 5031 } |
5045 else | 5032 else |
5046 input = build_string (strlen (buf), buf); | 5033 input = build_string (strlen (buf), buf); |
5047 } | 5034 } |
5048 else | 5035 else |
5049 input = build_string (constraint_len - 1, constraint + 1); | 5036 input = build_string (constraint_len - 1, constraint + 1); |
5050 | 5037 |
5051 free (p); | 5038 free (p); |
5052 | 5039 |
5053 input = build_tree_list (build_tree_list (NULL_TREE, input), | 5040 input = build_tree_list (build_tree_list (NULL_TREE, input), |
5054 unshare_expr (TREE_VALUE (link))); | 5041 unshare_expr (TREE_VALUE (link))); |
5055 ASM_INPUTS (expr) = chainon (ASM_INPUTS (expr), input); | 5042 ASM_INPUTS (expr) = chainon (ASM_INPUTS (expr), input); |
5056 } | 5043 } |
5057 } | 5044 } |
5058 | 5045 |
5059 link_next = NULL_TREE; | 5046 link_next = NULL_TREE; |
5060 for (link = ASM_INPUTS (expr); link; ++i, link = link_next) | 5047 for (link = ASM_INPUTS (expr); link; ++i, link = link_next) |
5061 { | 5048 { |
5062 link_next = TREE_CHAIN (link); | 5049 link_next = TREE_CHAIN (link); |
5063 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link))); | 5050 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link))); |
5064 parse_input_constraint (&constraint, 0, 0, noutputs, 0, | 5051 parse_input_constraint (&constraint, 0, 0, noutputs, 0, |
5065 oconstraints, &allows_mem, &allows_reg); | 5052 oconstraints, &allows_mem, &allows_reg); |
5066 | 5053 |
5067 /* If we can't make copies, we can only accept memory. */ | 5054 /* If we can't make copies, we can only accept memory. */ |
5068 if (TREE_ADDRESSABLE (TREE_TYPE (TREE_VALUE (link)))) | 5055 if (TREE_ADDRESSABLE (TREE_TYPE (TREE_VALUE (link)))) |
5069 { | 5056 { |
5070 if (allows_mem) | 5057 if (allows_mem) |
5071 allows_reg = 0; | 5058 allows_reg = 0; |
5072 else | 5059 else |
5073 { | 5060 { |
5074 error ("impossible constraint in %<asm%>"); | 5061 error ("impossible constraint in %<asm%>"); |
5075 error ("non-memory input %d must stay in memory", i); | 5062 error ("non-memory input %d must stay in memory", i); |
5076 return GS_ERROR; | 5063 return GS_ERROR; |
5077 } | 5064 } |
5078 } | 5065 } |
5079 | 5066 |
5080 /* If the operand is a memory input, it should be an lvalue. */ | 5067 /* If the operand is a memory input, it should be an lvalue. */ |
5081 if (!allows_reg && allows_mem) | 5068 if (!allows_reg && allows_mem) |
5082 { | 5069 { |
5083 tree inputv = TREE_VALUE (link); | 5070 tree inputv = TREE_VALUE (link); |
5097 error ("memory input %d is not directly addressable", i); | 5084 error ("memory input %d is not directly addressable", i); |
5098 ret = tret; | 5085 ret = tret; |
5099 } | 5086 } |
5100 } | 5087 } |
5101 else | 5088 else |
5102 { | 5089 { |
5103 tret = gimplify_expr (&TREE_VALUE (link), pre_p, post_p, | 5090 tret = gimplify_expr (&TREE_VALUE (link), pre_p, post_p, |
5104 is_gimple_asm_val, fb_rvalue); | 5091 is_gimple_asm_val, fb_rvalue); |
5105 if (tret == GS_ERROR) | 5092 if (tret == GS_ERROR) |
5106 ret = tret; | 5093 ret = tret; |
5107 } | 5094 } |
5108 | 5095 |
5109 TREE_CHAIN (link) = NULL_TREE; | 5096 TREE_CHAIN (link) = NULL_TREE; |
5110 VEC_safe_push (tree, gc, inputs, link); | 5097 VEC_safe_push (tree, gc, inputs, link); |
5111 } | 5098 } |
5112 | 5099 |
5118 | 5105 |
5119 /* Do not add ASMs with errors to the gimple IL stream. */ | 5106 /* Do not add ASMs with errors to the gimple IL stream. */ |
5120 if (ret != GS_ERROR) | 5107 if (ret != GS_ERROR) |
5121 { | 5108 { |
5122 stmt = gimple_build_asm_vec (TREE_STRING_POINTER (ASM_STRING (expr)), | 5109 stmt = gimple_build_asm_vec (TREE_STRING_POINTER (ASM_STRING (expr)), |
5123 inputs, outputs, clobbers, labels); | 5110 inputs, outputs, clobbers, labels); |
5124 | 5111 |
5125 gimple_asm_set_volatile (stmt, ASM_VOLATILE_P (expr)); | 5112 gimple_asm_set_volatile (stmt, ASM_VOLATILE_P (expr)); |
5126 gimple_asm_set_input (stmt, ASM_INPUT_P (expr)); | 5113 gimple_asm_set_input (stmt, ASM_INPUT_P (expr)); |
5127 | 5114 |
5128 gimplify_seq_add_stmt (pre_p, stmt); | 5115 gimplify_seq_add_stmt (pre_p, stmt); |
5169 for (iter = gsi_start (body_sequence); !gsi_end_p (iter); ) | 5156 for (iter = gsi_start (body_sequence); !gsi_end_p (iter); ) |
5170 { | 5157 { |
5171 gimple wce = gsi_stmt (iter); | 5158 gimple wce = gsi_stmt (iter); |
5172 | 5159 |
5173 if (gimple_code (wce) == GIMPLE_WITH_CLEANUP_EXPR) | 5160 if (gimple_code (wce) == GIMPLE_WITH_CLEANUP_EXPR) |
5174 { | 5161 { |
5175 if (gsi_one_before_end_p (iter)) | 5162 if (gsi_one_before_end_p (iter)) |
5176 { | 5163 { |
5177 /* Note that gsi_insert_seq_before and gsi_remove do not | 5164 /* Note that gsi_insert_seq_before and gsi_remove do not |
5178 scan operands, unlike some other sequence mutators. */ | 5165 scan operands, unlike some other sequence mutators. */ |
5179 if (!gimple_wce_cleanup_eh_only (wce)) | 5166 if (!gimple_wce_cleanup_eh_only (wce)) |
5180 gsi_insert_seq_before_without_update (&iter, | 5167 gsi_insert_seq_before_without_update (&iter, |
5181 gimple_wce_cleanup (wce), | 5168 gimple_wce_cleanup (wce), |
5197 | 5184 |
5198 gtry = gimple_build_try (seq, gimple_wce_cleanup (wce), kind); | 5185 gtry = gimple_build_try (seq, gimple_wce_cleanup (wce), kind); |
5199 /* Do not use gsi_replace here, as it may scan operands. | 5186 /* Do not use gsi_replace here, as it may scan operands. |
5200 We want to do a simple structural modification only. */ | 5187 We want to do a simple structural modification only. */ |
5201 *gsi_stmt_ptr (&iter) = gtry; | 5188 *gsi_stmt_ptr (&iter) = gtry; |
5202 iter = gsi_start (seq); | 5189 iter = gsi_start (seq); |
5203 } | 5190 } |
5204 } | 5191 } |
5205 else | 5192 else |
5206 gsi_next (&iter); | 5193 gsi_next (&iter); |
5207 } | 5194 } |
5208 | 5195 |
5209 gimplify_seq_add_seq (pre_p, body_sequence); | 5196 gimplify_seq_add_seq (pre_p, body_sequence); |
5210 if (temp) | 5197 if (temp) |
5211 { | 5198 { |
5235 return; | 5222 return; |
5236 | 5223 |
5237 if (gimple_conditional_context ()) | 5224 if (gimple_conditional_context ()) |
5238 { | 5225 { |
5239 /* If we're in a conditional context, this is more complex. We only | 5226 /* If we're in a conditional context, this is more complex. We only |
5240 want to run the cleanup if we actually ran the initialization that | 5227 want to run the cleanup if we actually ran the initialization that |
5241 necessitates it, but we want to run it after the end of the | 5228 necessitates it, but we want to run it after the end of the |
5242 conditional context. So we wrap the try/finally around the | 5229 conditional context. So we wrap the try/finally around the |
5243 condition and use a flag to determine whether or not to actually | 5230 condition and use a flag to determine whether or not to actually |
5244 run the destructor. Thus | 5231 run the destructor. Thus |
5245 | 5232 |
5246 test ? f(A()) : 0 | 5233 test ? f(A()) : 0 |
5247 | 5234 |
5248 becomes (approximately) | 5235 becomes (approximately) |
5249 | 5236 |
5250 flag = 0; | 5237 flag = 0; |
5251 try { | 5238 try { |
5252 if (test) { A::A(temp); flag = 1; val = f(temp); } | 5239 if (test) { A::A(temp); flag = 1; val = f(temp); } |
5253 else { val = 0; } | 5240 else { val = 0; } |
5254 } finally { | 5241 } finally { |
5255 if (flag) A::~A(temp); | 5242 if (flag) A::~A(temp); |
5256 } | 5243 } |
5257 val | 5244 val |
5258 */ | 5245 */ |
5259 tree flag = create_tmp_var (boolean_type_node, "cleanup"); | 5246 tree flag = create_tmp_var (boolean_type_node, "cleanup"); |
5260 gimple ffalse = gimple_build_assign (flag, boolean_false_node); | 5247 gimple ffalse = gimple_build_assign (flag, boolean_false_node); |
5261 gimple ftrue = gimple_build_assign (flag, boolean_true_node); | 5248 gimple ftrue = gimple_build_assign (flag, boolean_true_node); |
5262 | 5249 |
5267 gimplify_seq_add_stmt (&gimplify_ctxp->conditional_cleanups, ffalse); | 5254 gimplify_seq_add_stmt (&gimplify_ctxp->conditional_cleanups, ffalse); |
5268 gimplify_seq_add_stmt (&gimplify_ctxp->conditional_cleanups, wce); | 5255 gimplify_seq_add_stmt (&gimplify_ctxp->conditional_cleanups, wce); |
5269 gimplify_seq_add_stmt (pre_p, ftrue); | 5256 gimplify_seq_add_stmt (pre_p, ftrue); |
5270 | 5257 |
5271 /* Because of this manipulation, and the EH edges that jump | 5258 /* Because of this manipulation, and the EH edges that jump |
5272 threading cannot redirect, the temporary (VAR) will appear | 5259 threading cannot redirect, the temporary (VAR) will appear |
5273 to be used uninitialized. Don't warn. */ | 5260 to be used uninitialized. Don't warn. */ |
5274 TREE_NO_WARNING (var) = 1; | 5261 TREE_NO_WARNING (var) = 1; |
5275 } | 5262 } |
5276 else | 5263 else |
5277 { | 5264 { |
5278 gimplify_stmt (&cleanup, &cleanup_stmts); | 5265 gimplify_stmt (&cleanup, &cleanup_stmts); |
5293 enum gimplify_status ret; | 5280 enum gimplify_status ret; |
5294 | 5281 |
5295 if (init) | 5282 if (init) |
5296 { | 5283 { |
5297 /* TARGET_EXPR temps aren't part of the enclosing block, so add it | 5284 /* TARGET_EXPR temps aren't part of the enclosing block, so add it |
5298 to the temps list. Handle also variable length TARGET_EXPRs. */ | 5285 to the temps list. Handle also variable length TARGET_EXPRs. */ |
5299 if (TREE_CODE (DECL_SIZE (temp)) != INTEGER_CST) | 5286 if (TREE_CODE (DECL_SIZE (temp)) != INTEGER_CST) |
5300 { | 5287 { |
5301 if (!TYPE_SIZES_GIMPLIFIED (TREE_TYPE (temp))) | 5288 if (!TYPE_SIZES_GIMPLIFIED (TREE_TYPE (temp))) |
5302 gimplify_type_sizes (TREE_TYPE (temp), pre_p); | 5289 gimplify_type_sizes (TREE_TYPE (temp), pre_p); |
5303 gimplify_vla_decl (temp, pre_p); | 5290 gimplify_vla_decl (temp, pre_p); |
5304 } | 5291 } |
5305 else | 5292 else |
5306 gimple_add_tmp_var (temp); | 5293 gimple_add_tmp_var (temp); |
5307 | 5294 |
5308 /* If TARGET_EXPR_INITIAL is void, then the mere evaluation of the | 5295 /* If TARGET_EXPR_INITIAL is void, then the mere evaluation of the |
5309 expression is supposed to initialize the slot. */ | 5296 expression is supposed to initialize the slot. */ |
5310 if (VOID_TYPE_P (TREE_TYPE (init))) | 5297 if (VOID_TYPE_P (TREE_TYPE (init))) |
5311 ret = gimplify_expr (&init, pre_p, post_p, is_gimple_stmt, fb_none); | 5298 ret = gimplify_expr (&init, pre_p, post_p, is_gimple_stmt, fb_none); |
5312 else | 5299 else |
5313 { | 5300 { |
5314 tree init_expr = build2 (INIT_EXPR, void_type_node, temp, init); | 5301 tree init_expr = build2 (INIT_EXPR, void_type_node, temp, init); |
5315 init = init_expr; | 5302 init = init_expr; |
5316 ret = gimplify_expr (&init, pre_p, post_p, is_gimple_stmt, fb_none); | 5303 ret = gimplify_expr (&init, pre_p, post_p, is_gimple_stmt, fb_none); |
5317 init = NULL; | 5304 init = NULL; |
5318 ggc_free (init_expr); | 5305 ggc_free (init_expr); |
5319 } | 5306 } |
5320 if (ret == GS_ERROR) | 5307 if (ret == GS_ERROR) |
5321 { | 5308 { |
5322 /* PR c++/28266 Make sure this is expanded only once. */ | 5309 /* PR c++/28266 Make sure this is expanded only once. */ |
5323 TARGET_EXPR_INITIAL (targ) = NULL_TREE; | 5310 TARGET_EXPR_INITIAL (targ) = NULL_TREE; |
5324 return GS_ERROR; | 5311 return GS_ERROR; |
5325 } | 5312 } |
5326 if (init) | 5313 if (init) |
5327 gimplify_and_add (init, pre_p); | 5314 gimplify_and_add (init, pre_p); |
5328 | 5315 |
5329 /* If needed, push the cleanup for the temp. */ | 5316 /* If needed, push the cleanup for the temp. */ |
5330 if (TARGET_EXPR_CLEANUP (targ)) | 5317 if (TARGET_EXPR_CLEANUP (targ)) |
5331 gimple_push_cleanup (temp, TARGET_EXPR_CLEANUP (targ), | 5318 gimple_push_cleanup (temp, TARGET_EXPR_CLEANUP (targ), |
5332 CLEANUP_EH_ONLY (targ), pre_p); | 5319 CLEANUP_EH_ONLY (targ), pre_p); |
5333 | 5320 |
5334 /* Only expand this once. */ | 5321 /* Only expand this once. */ |
5335 TREE_OPERAND (targ, 3) = init; | 5322 TREE_OPERAND (targ, 3) = init; |
5336 TARGET_EXPR_INITIAL (targ) = NULL_TREE; | 5323 TARGET_EXPR_INITIAL (targ) = NULL_TREE; |
5337 } | 5324 } |
5379 | 5366 |
5380 do | 5367 do |
5381 { | 5368 { |
5382 n = splay_tree_lookup (ctx->variables, (splay_tree_key)decl); | 5369 n = splay_tree_lookup (ctx->variables, (splay_tree_key)decl); |
5383 if (n != NULL) | 5370 if (n != NULL) |
5384 { | 5371 { |
5385 if (n->value & GOVD_SHARED) | 5372 if (n->value & GOVD_SHARED) |
5386 n->value = GOVD_FIRSTPRIVATE | (n->value & GOVD_SEEN); | 5373 n->value = GOVD_FIRSTPRIVATE | (n->value & GOVD_SEEN); |
5387 else | 5374 else |
5388 return; | 5375 return; |
5389 } | 5376 } |
5390 else if (ctx->region_type != ORT_WORKSHARE) | 5377 else if (ctx->region_type != ORT_WORKSHARE) |
5391 omp_add_variable (ctx, decl, GOVD_FIRSTPRIVATE); | 5378 omp_add_variable (ctx, decl, GOVD_FIRSTPRIVATE); |
5392 | 5379 |
5393 ctx = ctx->outer_context; | 5380 ctx = ctx->outer_context; |
5394 } | 5381 } |
5395 while (ctx); | 5382 while (ctx); |
5396 } | 5383 } |
5471 | 5458 |
5472 n = splay_tree_lookup (ctx->variables, (splay_tree_key)decl); | 5459 n = splay_tree_lookup (ctx->variables, (splay_tree_key)decl); |
5473 if (n != NULL) | 5460 if (n != NULL) |
5474 { | 5461 { |
5475 /* We shouldn't be re-adding the decl with the same data | 5462 /* We shouldn't be re-adding the decl with the same data |
5476 sharing class. */ | 5463 sharing class. */ |
5477 gcc_assert ((n->value & GOVD_DATA_SHARE_CLASS & flags) == 0); | 5464 gcc_assert ((n->value & GOVD_DATA_SHARE_CLASS & flags) == 0); |
5478 /* The only combination of data sharing classes we should see is | 5465 /* The only combination of data sharing classes we should see is |
5479 FIRSTPRIVATE and LASTPRIVATE. */ | 5466 FIRSTPRIVATE and LASTPRIVATE. */ |
5480 nflags = n->value | flags; | 5467 nflags = n->value | flags; |
5481 gcc_assert ((nflags & GOVD_DATA_SHARE_CLASS) | 5468 gcc_assert ((nflags & GOVD_DATA_SHARE_CLASS) |
5482 == (GOVD_FIRSTPRIVATE | GOVD_LASTPRIVATE)); | 5469 == (GOVD_FIRSTPRIVATE | GOVD_LASTPRIVATE)); |
5483 n->value = nflags; | 5470 n->value = nflags; |
5484 return; | 5471 return; |
5485 } | 5472 } |
5486 | 5473 |
5487 /* When adding a variable-sized variable, we have to handle all sorts | 5474 /* When adding a variable-sized variable, we have to handle all sorts |
5488 of additional bits of data: the pointer replacement variable, and | 5475 of additional bits of data: the pointer replacement variable, and |
5489 the parameters of the type. */ | 5476 the parameters of the type. */ |
5490 if (DECL_SIZE (decl) && TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST) | 5477 if (DECL_SIZE (decl) && TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST) |
5491 { | 5478 { |
5492 /* Add the pointer replacement variable as PRIVATE if the variable | 5479 /* Add the pointer replacement variable as PRIVATE if the variable |
5493 replacement is private, else FIRSTPRIVATE since we'll need the | 5480 replacement is private, else FIRSTPRIVATE since we'll need the |
5494 address of the original variable either for SHARED, or for the | 5481 address of the original variable either for SHARED, or for the |
5495 copy into or out of the context. */ | 5482 copy into or out of the context. */ |
5496 if (!(flags & GOVD_LOCAL)) | 5483 if (!(flags & GOVD_LOCAL)) |
5497 { | 5484 { |
5498 nflags = flags & GOVD_PRIVATE ? GOVD_PRIVATE : GOVD_FIRSTPRIVATE; | 5485 nflags = flags & GOVD_PRIVATE ? GOVD_PRIVATE : GOVD_FIRSTPRIVATE; |
5499 nflags |= flags & GOVD_SEEN; | 5486 nflags |= flags & GOVD_SEEN; |
5500 t = DECL_VALUE_EXPR (decl); | 5487 t = DECL_VALUE_EXPR (decl); |
5501 gcc_assert (TREE_CODE (t) == INDIRECT_REF); | 5488 gcc_assert (TREE_CODE (t) == INDIRECT_REF); |
5502 t = TREE_OPERAND (t, 0); | 5489 t = TREE_OPERAND (t, 0); |
5503 gcc_assert (DECL_P (t)); | 5490 gcc_assert (DECL_P (t)); |
5504 omp_add_variable (ctx, t, nflags); | 5491 omp_add_variable (ctx, t, nflags); |
5505 } | 5492 } |
5506 | 5493 |
5507 /* Add all of the variable and type parameters (which should have | 5494 /* Add all of the variable and type parameters (which should have |
5508 been gimplified to a formal temporary) as FIRSTPRIVATE. */ | 5495 been gimplified to a formal temporary) as FIRSTPRIVATE. */ |
5509 omp_firstprivatize_variable (ctx, DECL_SIZE_UNIT (decl)); | 5496 omp_firstprivatize_variable (ctx, DECL_SIZE_UNIT (decl)); |
5510 omp_firstprivatize_variable (ctx, DECL_SIZE (decl)); | 5497 omp_firstprivatize_variable (ctx, DECL_SIZE (decl)); |
5511 omp_firstprivatize_type_sizes (ctx, TREE_TYPE (decl)); | 5498 omp_firstprivatize_type_sizes (ctx, TREE_TYPE (decl)); |
5512 | 5499 |
5513 /* The variable-sized variable itself is never SHARED, only some form | 5500 /* The variable-sized variable itself is never SHARED, only some form |
5514 of PRIVATE. The sharing would take place via the pointer variable | 5501 of PRIVATE. The sharing would take place via the pointer variable |
5515 which we remapped above. */ | 5502 which we remapped above. */ |
5516 if (flags & GOVD_SHARED) | 5503 if (flags & GOVD_SHARED) |
5517 flags = GOVD_PRIVATE | GOVD_DEBUG_PRIVATE | 5504 flags = GOVD_PRIVATE | GOVD_DEBUG_PRIVATE |
5518 | (flags & (GOVD_SEEN | GOVD_EXPLICIT)); | 5505 | (flags & (GOVD_SEEN | GOVD_EXPLICIT)); |
5519 | 5506 |
5520 /* We're going to make use of the TYPE_SIZE_UNIT at least in the | 5507 /* We're going to make use of the TYPE_SIZE_UNIT at least in the |
5521 alloca statement we generate for the variable, so make sure it | 5508 alloca statement we generate for the variable, so make sure it |
5522 is available. This isn't automatically needed for the SHARED | 5509 is available. This isn't automatically needed for the SHARED |
5523 case, since we won't be allocating local storage then. | 5510 case, since we won't be allocating local storage then. |
5532 { | 5519 { |
5533 gcc_assert ((flags & GOVD_LOCAL) == 0); | 5520 gcc_assert ((flags & GOVD_LOCAL) == 0); |
5534 omp_firstprivatize_type_sizes (ctx, TREE_TYPE (decl)); | 5521 omp_firstprivatize_type_sizes (ctx, TREE_TYPE (decl)); |
5535 | 5522 |
5536 /* Similar to the direct variable sized case above, we'll need the | 5523 /* Similar to the direct variable sized case above, we'll need the |
5537 size of references being privatized. */ | 5524 size of references being privatized. */ |
5538 if ((flags & GOVD_SHARED) == 0) | 5525 if ((flags & GOVD_SHARED) == 0) |
5539 { | 5526 { |
5540 t = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl))); | 5527 t = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl))); |
5541 if (TREE_CODE (t) != INTEGER_CST) | 5528 if (TREE_CODE (t) != INTEGER_CST) |
5542 omp_notice_variable (ctx, t, true); | 5529 omp_notice_variable (ctx, t, true); |
5543 } | 5530 } |
5544 } | 5531 } |
5545 | 5532 |
5546 splay_tree_insert (ctx->variables, (splay_tree_key)decl, flags); | 5533 splay_tree_insert (ctx->variables, (splay_tree_key)decl, flags); |
5547 } | 5534 } |
5548 | 5535 |
5607 { | 5594 { |
5608 enum omp_clause_default_kind default_kind, kind; | 5595 enum omp_clause_default_kind default_kind, kind; |
5609 struct gimplify_omp_ctx *octx; | 5596 struct gimplify_omp_ctx *octx; |
5610 | 5597 |
5611 if (ctx->region_type == ORT_WORKSHARE) | 5598 if (ctx->region_type == ORT_WORKSHARE) |
5612 goto do_outer; | 5599 goto do_outer; |
5613 | 5600 |
5614 /* ??? Some compiler-generated variables (like SAVE_EXPRs) could be | 5601 /* ??? Some compiler-generated variables (like SAVE_EXPRs) could be |
5615 remapped firstprivate instead of shared. To some extent this is | 5602 remapped firstprivate instead of shared. To some extent this is |
5616 addressed in omp_firstprivatize_type_sizes, but not effectively. */ | 5603 addressed in omp_firstprivatize_type_sizes, but not effectively. */ |
5617 default_kind = ctx->default_kind; | 5604 default_kind = ctx->default_kind; |
5618 kind = lang_hooks.decls.omp_predetermined_sharing (decl); | 5605 kind = lang_hooks.decls.omp_predetermined_sharing (decl); |
5619 if (kind != OMP_CLAUSE_DEFAULT_UNSPECIFIED) | 5606 if (kind != OMP_CLAUSE_DEFAULT_UNSPECIFIED) |
5620 default_kind = kind; | 5607 default_kind = kind; |
5621 | 5608 |
5622 switch (default_kind) | 5609 switch (default_kind) |
5623 { | 5610 { |
5624 case OMP_CLAUSE_DEFAULT_NONE: | 5611 case OMP_CLAUSE_DEFAULT_NONE: |
5625 error ("%qE not specified in enclosing parallel", | 5612 error ("%qE not specified in enclosing parallel", |
5671 default: | 5658 default: |
5672 gcc_unreachable (); | 5659 gcc_unreachable (); |
5673 } | 5660 } |
5674 | 5661 |
5675 if ((flags & GOVD_PRIVATE) | 5662 if ((flags & GOVD_PRIVATE) |
5676 && lang_hooks.decls.omp_private_outer_ref (decl)) | 5663 && lang_hooks.decls.omp_private_outer_ref (decl)) |
5677 flags |= GOVD_PRIVATE_OUTER_REF; | 5664 flags |= GOVD_PRIVATE_OUTER_REF; |
5678 | 5665 |
5679 omp_add_variable (ctx, decl, flags); | 5666 omp_add_variable (ctx, decl, flags); |
5680 | 5667 |
5681 shared = (flags & GOVD_SHARED) != 0; | 5668 shared = (flags & GOVD_SHARED) != 0; |
5682 ret = lang_hooks.decls.omp_disregard_value_expr (decl, shared); | 5669 ret = lang_hooks.decls.omp_disregard_value_expr (decl, shared); |
5727 | 5714 |
5728 n = splay_tree_lookup (ctx->variables, (splay_tree_key)decl); | 5715 n = splay_tree_lookup (ctx->variables, (splay_tree_key)decl); |
5729 if (n != NULL) | 5716 if (n != NULL) |
5730 { | 5717 { |
5731 if (n->value & GOVD_SHARED) | 5718 if (n->value & GOVD_SHARED) |
5732 { | 5719 { |
5733 if (ctx == gimplify_omp_ctxp) | 5720 if (ctx == gimplify_omp_ctxp) |
5734 { | 5721 { |
5735 error ("iteration variable %qE should be private", | 5722 error ("iteration variable %qE should be private", |
5736 DECL_NAME (decl)); | 5723 DECL_NAME (decl)); |
5737 n->value = GOVD_PRIVATE; | 5724 n->value = GOVD_PRIVATE; |
5738 return true; | 5725 return true; |
5739 } | 5726 } |
5740 else | 5727 else |
5741 return false; | 5728 return false; |
5742 } | 5729 } |
5743 else if ((n->value & GOVD_EXPLICIT) != 0 | 5730 else if ((n->value & GOVD_EXPLICIT) != 0 |
5744 && (ctx == gimplify_omp_ctxp | 5731 && (ctx == gimplify_omp_ctxp |
5745 || (ctx->region_type == ORT_COMBINED_PARALLEL | 5732 || (ctx->region_type == ORT_COMBINED_PARALLEL |
5746 && gimplify_omp_ctxp->outer_context == ctx))) | 5733 && gimplify_omp_ctxp->outer_context == ctx))) |
5747 { | 5734 { |
5748 if ((n->value & GOVD_FIRSTPRIVATE) != 0) | 5735 if ((n->value & GOVD_FIRSTPRIVATE) != 0) |
5749 error ("iteration variable %qE should not be firstprivate", | 5736 error ("iteration variable %qE should not be firstprivate", |
5750 DECL_NAME (decl)); | 5737 DECL_NAME (decl)); |
5751 else if ((n->value & GOVD_REDUCTION) != 0) | 5738 else if ((n->value & GOVD_REDUCTION) != 0) |
5752 error ("iteration variable %qE should not be reduction", | 5739 error ("iteration variable %qE should not be reduction", |
5753 DECL_NAME (decl)); | 5740 DECL_NAME (decl)); |
5754 } | 5741 } |
5755 return (ctx == gimplify_omp_ctxp | 5742 return (ctx == gimplify_omp_ctxp |
5756 || (ctx->region_type == ORT_COMBINED_PARALLEL | 5743 || (ctx->region_type == ORT_COMBINED_PARALLEL |
5757 && gimplify_omp_ctxp->outer_context == ctx)); | 5744 && gimplify_omp_ctxp->outer_context == ctx)); |
5758 } | 5745 } |
5759 | 5746 |
5760 if (ctx->region_type != ORT_WORKSHARE) | 5747 if (ctx->region_type != ORT_WORKSHARE) |
5761 return false; | 5748 return false; |
5762 else if (ctx->outer_context) | 5749 else if (ctx->outer_context) |
5775 | 5762 |
5776 do | 5763 do |
5777 { | 5764 { |
5778 ctx = ctx->outer_context; | 5765 ctx = ctx->outer_context; |
5779 if (ctx == NULL) | 5766 if (ctx == NULL) |
5780 return !(is_global_var (decl) | 5767 return !(is_global_var (decl) |
5781 /* References might be private, but might be shared too. */ | 5768 /* References might be private, but might be shared too. */ |
5782 || lang_hooks.decls.omp_privatize_by_reference (decl)); | 5769 || lang_hooks.decls.omp_privatize_by_reference (decl)); |
5783 | 5770 |
5784 n = splay_tree_lookup (ctx->variables, (splay_tree_key) decl); | 5771 n = splay_tree_lookup (ctx->variables, (splay_tree_key) decl); |
5785 if (n != NULL) | 5772 if (n != NULL) |
5786 return (n->value & GOVD_SHARED) == 0; | 5773 return (n->value & GOVD_SHARED) == 0; |
5787 } | 5774 } |
5788 while (ctx->region_type == ORT_WORKSHARE); | 5775 while (ctx->region_type == ORT_WORKSHARE); |
5789 return false; | 5776 return false; |
5790 } | 5777 } |
5791 | 5778 |
5792 /* Scan the OpenMP clauses in *LIST_P, installing mappings into a new | 5779 /* Scan the OpenMP clauses in *LIST_P, installing mappings into a new |
5793 and previous omp contexts. */ | 5780 and previous omp contexts. */ |
5794 | 5781 |
5795 static void | 5782 static void |
5796 gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p, | 5783 gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p, |
5797 enum omp_region_type region_type) | 5784 enum omp_region_type region_type) |
5798 { | 5785 { |
5799 struct gimplify_omp_ctx *ctx, *outer_ctx; | 5786 struct gimplify_omp_ctx *ctx, *outer_ctx; |
5800 struct gimplify_ctx gctx; | 5787 struct gimplify_ctx gctx; |
5801 tree c; | 5788 tree c; |
5802 | 5789 |
5810 const char *check_non_private = NULL; | 5797 const char *check_non_private = NULL; |
5811 unsigned int flags; | 5798 unsigned int flags; |
5812 tree decl; | 5799 tree decl; |
5813 | 5800 |
5814 switch (OMP_CLAUSE_CODE (c)) | 5801 switch (OMP_CLAUSE_CODE (c)) |
5815 { | 5802 { |
5816 case OMP_CLAUSE_PRIVATE: | 5803 case OMP_CLAUSE_PRIVATE: |
5817 flags = GOVD_PRIVATE | GOVD_EXPLICIT; | 5804 flags = GOVD_PRIVATE | GOVD_EXPLICIT; |
5818 if (lang_hooks.decls.omp_private_outer_ref (OMP_CLAUSE_DECL (c))) | 5805 if (lang_hooks.decls.omp_private_outer_ref (OMP_CLAUSE_DECL (c))) |
5819 { | 5806 { |
5820 flags |= GOVD_PRIVATE_OUTER_REF; | 5807 flags |= GOVD_PRIVATE_OUTER_REF; |
5821 OMP_CLAUSE_PRIVATE_OUTER_REF (c) = 1; | 5808 OMP_CLAUSE_PRIVATE_OUTER_REF (c) = 1; |
5822 } | 5809 } |
5810 else | |
5811 notice_outer = false; | |
5812 goto do_add; | |
5813 case OMP_CLAUSE_SHARED: | |
5814 flags = GOVD_SHARED | GOVD_EXPLICIT; | |
5815 goto do_add; | |
5816 case OMP_CLAUSE_FIRSTPRIVATE: | |
5817 flags = GOVD_FIRSTPRIVATE | GOVD_EXPLICIT; | |
5818 check_non_private = "firstprivate"; | |
5819 goto do_add; | |
5820 case OMP_CLAUSE_LASTPRIVATE: | |
5821 flags = GOVD_LASTPRIVATE | GOVD_SEEN | GOVD_EXPLICIT; | |
5822 check_non_private = "lastprivate"; | |
5823 goto do_add; | |
5824 case OMP_CLAUSE_REDUCTION: | |
5825 flags = GOVD_REDUCTION | GOVD_SEEN | GOVD_EXPLICIT; | |
5826 check_non_private = "reduction"; | |
5827 goto do_add; | |
5828 | |
5829 do_add: | |
5830 decl = OMP_CLAUSE_DECL (c); | |
5831 if (decl == error_mark_node || TREE_TYPE (decl) == error_mark_node) | |
5832 { | |
5833 remove = true; | |
5834 break; | |
5835 } | |
5836 omp_add_variable (ctx, decl, flags); | |
5837 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION | |
5838 && OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)) | |
5839 { | |
5840 omp_add_variable (ctx, OMP_CLAUSE_REDUCTION_PLACEHOLDER (c), | |
5841 GOVD_LOCAL | GOVD_SEEN); | |
5842 gimplify_omp_ctxp = ctx; | |
5843 push_gimplify_context (&gctx); | |
5844 | |
5845 OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c) = gimple_seq_alloc (); | |
5846 OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c) = gimple_seq_alloc (); | |
5847 | |
5848 gimplify_and_add (OMP_CLAUSE_REDUCTION_INIT (c), | |
5849 &OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c)); | |
5850 pop_gimplify_context | |
5851 (gimple_seq_first_stmt (OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c))); | |
5852 push_gimplify_context (&gctx); | |
5853 gimplify_and_add (OMP_CLAUSE_REDUCTION_MERGE (c), | |
5854 &OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c)); | |
5855 pop_gimplify_context | |
5856 (gimple_seq_first_stmt (OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c))); | |
5857 OMP_CLAUSE_REDUCTION_INIT (c) = NULL_TREE; | |
5858 OMP_CLAUSE_REDUCTION_MERGE (c) = NULL_TREE; | |
5859 | |
5860 gimplify_omp_ctxp = outer_ctx; | |
5861 } | |
5862 else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE | |
5863 && OMP_CLAUSE_LASTPRIVATE_STMT (c)) | |
5864 { | |
5865 gimplify_omp_ctxp = ctx; | |
5866 push_gimplify_context (&gctx); | |
5867 if (TREE_CODE (OMP_CLAUSE_LASTPRIVATE_STMT (c)) != BIND_EXPR) | |
5868 { | |
5869 tree bind = build3 (BIND_EXPR, void_type_node, NULL, | |
5870 NULL, NULL); | |
5871 TREE_SIDE_EFFECTS (bind) = 1; | |
5872 BIND_EXPR_BODY (bind) = OMP_CLAUSE_LASTPRIVATE_STMT (c); | |
5873 OMP_CLAUSE_LASTPRIVATE_STMT (c) = bind; | |
5874 } | |
5875 gimplify_and_add (OMP_CLAUSE_LASTPRIVATE_STMT (c), | |
5876 &OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c)); | |
5877 pop_gimplify_context | |
5878 (gimple_seq_first_stmt (OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c))); | |
5879 OMP_CLAUSE_LASTPRIVATE_STMT (c) = NULL_TREE; | |
5880 | |
5881 gimplify_omp_ctxp = outer_ctx; | |
5882 } | |
5883 if (notice_outer) | |
5884 goto do_notice; | |
5885 break; | |
5886 | |
5887 case OMP_CLAUSE_COPYIN: | |
5888 case OMP_CLAUSE_COPYPRIVATE: | |
5889 decl = OMP_CLAUSE_DECL (c); | |
5890 if (decl == error_mark_node || TREE_TYPE (decl) == error_mark_node) | |
5891 { | |
5892 remove = true; | |
5893 break; | |
5894 } | |
5895 do_notice: | |
5896 if (outer_ctx) | |
5897 omp_notice_variable (outer_ctx, decl, true); | |
5898 if (check_non_private | |
5899 && region_type == ORT_WORKSHARE | |
5900 && omp_check_private (ctx, decl)) | |
5901 { | |
5902 error ("%s variable %qE is private in outer context", | |
5903 check_non_private, DECL_NAME (decl)); | |
5904 remove = true; | |
5905 } | |
5906 break; | |
5907 | |
5908 case OMP_CLAUSE_IF: | |
5909 OMP_CLAUSE_OPERAND (c, 0) | |
5910 = gimple_boolify (OMP_CLAUSE_OPERAND (c, 0)); | |
5911 /* Fall through. */ | |
5912 | |
5913 case OMP_CLAUSE_SCHEDULE: | |
5914 case OMP_CLAUSE_NUM_THREADS: | |
5915 if (gimplify_expr (&OMP_CLAUSE_OPERAND (c, 0), pre_p, NULL, | |
5916 is_gimple_val, fb_rvalue) == GS_ERROR) | |
5917 remove = true; | |
5918 break; | |
5919 | |
5920 case OMP_CLAUSE_NOWAIT: | |
5921 case OMP_CLAUSE_ORDERED: | |
5922 case OMP_CLAUSE_UNTIED: | |
5923 case OMP_CLAUSE_COLLAPSE: | |
5924 break; | |
5925 | |
5926 case OMP_CLAUSE_DEFAULT: | |
5927 ctx->default_kind = OMP_CLAUSE_DEFAULT_KIND (c); | |
5928 break; | |
5929 | |
5930 default: | |
5931 gcc_unreachable (); | |
5932 } | |
5933 | |
5934 if (remove) | |
5935 *list_p = OMP_CLAUSE_CHAIN (c); | |
5823 else | 5936 else |
5824 notice_outer = false; | 5937 list_p = &OMP_CLAUSE_CHAIN (c); |
5825 goto do_add; | |
5826 case OMP_CLAUSE_SHARED: | |
5827 flags = GOVD_SHARED | GOVD_EXPLICIT; | |
5828 goto do_add; | |
5829 case OMP_CLAUSE_FIRSTPRIVATE: | |
5830 flags = GOVD_FIRSTPRIVATE | GOVD_EXPLICIT; | |
5831 check_non_private = "firstprivate"; | |
5832 goto do_add; | |
5833 case OMP_CLAUSE_LASTPRIVATE: | |
5834 flags = GOVD_LASTPRIVATE | GOVD_SEEN | GOVD_EXPLICIT; | |
5835 check_non_private = "lastprivate"; | |
5836 goto do_add; | |
5837 case OMP_CLAUSE_REDUCTION: | |
5838 flags = GOVD_REDUCTION | GOVD_SEEN | GOVD_EXPLICIT; | |
5839 check_non_private = "reduction"; | |
5840 goto do_add; | |
5841 | |
5842 do_add: | |
5843 decl = OMP_CLAUSE_DECL (c); | |
5844 if (decl == error_mark_node || TREE_TYPE (decl) == error_mark_node) | |
5845 { | |
5846 remove = true; | |
5847 break; | |
5848 } | |
5849 omp_add_variable (ctx, decl, flags); | |
5850 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION | |
5851 && OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)) | |
5852 { | |
5853 omp_add_variable (ctx, OMP_CLAUSE_REDUCTION_PLACEHOLDER (c), | |
5854 GOVD_LOCAL | GOVD_SEEN); | |
5855 gimplify_omp_ctxp = ctx; | |
5856 push_gimplify_context (&gctx); | |
5857 | |
5858 OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c) = gimple_seq_alloc (); | |
5859 OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c) = gimple_seq_alloc (); | |
5860 | |
5861 gimplify_and_add (OMP_CLAUSE_REDUCTION_INIT (c), | |
5862 &OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c)); | |
5863 pop_gimplify_context | |
5864 (gimple_seq_first_stmt (OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c))); | |
5865 push_gimplify_context (&gctx); | |
5866 gimplify_and_add (OMP_CLAUSE_REDUCTION_MERGE (c), | |
5867 &OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c)); | |
5868 pop_gimplify_context | |
5869 (gimple_seq_first_stmt (OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c))); | |
5870 OMP_CLAUSE_REDUCTION_INIT (c) = NULL_TREE; | |
5871 OMP_CLAUSE_REDUCTION_MERGE (c) = NULL_TREE; | |
5872 | |
5873 gimplify_omp_ctxp = outer_ctx; | |
5874 } | |
5875 else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE | |
5876 && OMP_CLAUSE_LASTPRIVATE_STMT (c)) | |
5877 { | |
5878 gimplify_omp_ctxp = ctx; | |
5879 push_gimplify_context (&gctx); | |
5880 if (TREE_CODE (OMP_CLAUSE_LASTPRIVATE_STMT (c)) != BIND_EXPR) | |
5881 { | |
5882 tree bind = build3 (BIND_EXPR, void_type_node, NULL, | |
5883 NULL, NULL); | |
5884 TREE_SIDE_EFFECTS (bind) = 1; | |
5885 BIND_EXPR_BODY (bind) = OMP_CLAUSE_LASTPRIVATE_STMT (c); | |
5886 OMP_CLAUSE_LASTPRIVATE_STMT (c) = bind; | |
5887 } | |
5888 gimplify_and_add (OMP_CLAUSE_LASTPRIVATE_STMT (c), | |
5889 &OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c)); | |
5890 pop_gimplify_context | |
5891 (gimple_seq_first_stmt (OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c))); | |
5892 OMP_CLAUSE_LASTPRIVATE_STMT (c) = NULL_TREE; | |
5893 | |
5894 gimplify_omp_ctxp = outer_ctx; | |
5895 } | |
5896 if (notice_outer) | |
5897 goto do_notice; | |
5898 break; | |
5899 | |
5900 case OMP_CLAUSE_COPYIN: | |
5901 case OMP_CLAUSE_COPYPRIVATE: | |
5902 decl = OMP_CLAUSE_DECL (c); | |
5903 if (decl == error_mark_node || TREE_TYPE (decl) == error_mark_node) | |
5904 { | |
5905 remove = true; | |
5906 break; | |
5907 } | |
5908 do_notice: | |
5909 if (outer_ctx) | |
5910 omp_notice_variable (outer_ctx, decl, true); | |
5911 if (check_non_private | |
5912 && region_type == ORT_WORKSHARE | |
5913 && omp_check_private (ctx, decl)) | |
5914 { | |
5915 error ("%s variable %qE is private in outer context", | |
5916 check_non_private, DECL_NAME (decl)); | |
5917 remove = true; | |
5918 } | |
5919 break; | |
5920 | |
5921 case OMP_CLAUSE_IF: | |
5922 OMP_CLAUSE_OPERAND (c, 0) | |
5923 = gimple_boolify (OMP_CLAUSE_OPERAND (c, 0)); | |
5924 /* Fall through. */ | |
5925 | |
5926 case OMP_CLAUSE_SCHEDULE: | |
5927 case OMP_CLAUSE_NUM_THREADS: | |
5928 if (gimplify_expr (&OMP_CLAUSE_OPERAND (c, 0), pre_p, NULL, | |
5929 is_gimple_val, fb_rvalue) == GS_ERROR) | |
5930 remove = true; | |
5931 break; | |
5932 | |
5933 case OMP_CLAUSE_NOWAIT: | |
5934 case OMP_CLAUSE_ORDERED: | |
5935 case OMP_CLAUSE_UNTIED: | |
5936 case OMP_CLAUSE_COLLAPSE: | |
5937 break; | |
5938 | |
5939 case OMP_CLAUSE_DEFAULT: | |
5940 ctx->default_kind = OMP_CLAUSE_DEFAULT_KIND (c); | |
5941 break; | |
5942 | |
5943 default: | |
5944 gcc_unreachable (); | |
5945 } | |
5946 | |
5947 if (remove) | |
5948 *list_p = OMP_CLAUSE_CHAIN (c); | |
5949 else | |
5950 list_p = &OMP_CLAUSE_CHAIN (c); | |
5951 } | 5938 } |
5952 | 5939 |
5953 gimplify_omp_ctxp = ctx; | 5940 gimplify_omp_ctxp = ctx; |
5954 } | 5941 } |
5955 | 5942 |
5976 private_debug = true; | 5963 private_debug = true; |
5977 } | 5964 } |
5978 else | 5965 else |
5979 private_debug | 5966 private_debug |
5980 = lang_hooks.decls.omp_private_debug_clause (decl, | 5967 = lang_hooks.decls.omp_private_debug_clause (decl, |
5981 !!(flags & GOVD_SHARED)); | 5968 !!(flags & GOVD_SHARED)); |
5982 if (private_debug) | 5969 if (private_debug) |
5983 code = OMP_CLAUSE_PRIVATE; | 5970 code = OMP_CLAUSE_PRIVATE; |
5984 else if (flags & GOVD_SHARED) | 5971 else if (flags & GOVD_SHARED) |
5985 { | 5972 { |
5986 if (is_global_var (decl)) | 5973 if (is_global_var (decl)) |
5987 { | 5974 { |
5988 struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp->outer_context; | 5975 struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp->outer_context; |
5989 while (ctx != NULL) | 5976 while (ctx != NULL) |
5990 { | 5977 { |
5991 splay_tree_node on | 5978 splay_tree_node on |
5992 = splay_tree_lookup (ctx->variables, (splay_tree_key) decl); | 5979 = splay_tree_lookup (ctx->variables, (splay_tree_key) decl); |
5993 if (on && (on->value & (GOVD_FIRSTPRIVATE | GOVD_LASTPRIVATE | 5980 if (on && (on->value & (GOVD_FIRSTPRIVATE | GOVD_LASTPRIVATE |
5994 | GOVD_PRIVATE | GOVD_REDUCTION)) != 0) | 5981 | GOVD_PRIVATE | GOVD_REDUCTION)) != 0) |
5995 break; | 5982 break; |
5996 ctx = ctx->outer_context; | 5983 ctx = ctx->outer_context; |
5997 } | 5984 } |
5998 if (ctx == NULL) | 5985 if (ctx == NULL) |
5999 return 0; | 5986 return 0; |
6000 } | 5987 } |
6001 code = OMP_CLAUSE_SHARED; | 5988 code = OMP_CLAUSE_SHARED; |
6002 } | 5989 } |
6003 else if (flags & GOVD_PRIVATE) | 5990 else if (flags & GOVD_PRIVATE) |
6004 code = OMP_CLAUSE_PRIVATE; | 5991 code = OMP_CLAUSE_PRIVATE; |
6005 else if (flags & GOVD_FIRSTPRIVATE) | 5992 else if (flags & GOVD_FIRSTPRIVATE) |
6030 { | 6017 { |
6031 splay_tree_node n; | 6018 splay_tree_node n; |
6032 bool remove = false; | 6019 bool remove = false; |
6033 | 6020 |
6034 switch (OMP_CLAUSE_CODE (c)) | 6021 switch (OMP_CLAUSE_CODE (c)) |
6035 { | 6022 { |
6036 case OMP_CLAUSE_PRIVATE: | 6023 case OMP_CLAUSE_PRIVATE: |
6037 case OMP_CLAUSE_SHARED: | 6024 case OMP_CLAUSE_SHARED: |
6038 case OMP_CLAUSE_FIRSTPRIVATE: | 6025 case OMP_CLAUSE_FIRSTPRIVATE: |
6039 decl = OMP_CLAUSE_DECL (c); | 6026 decl = OMP_CLAUSE_DECL (c); |
6040 n = splay_tree_lookup (ctx->variables, (splay_tree_key) decl); | 6027 n = splay_tree_lookup (ctx->variables, (splay_tree_key) decl); |
6041 remove = !(n->value & GOVD_SEEN); | 6028 remove = !(n->value & GOVD_SEEN); |
6042 if (! remove) | 6029 if (! remove) |
6043 { | 6030 { |
6044 bool shared = OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED; | 6031 bool shared = OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED; |
6045 if ((n->value & GOVD_DEBUG_PRIVATE) | 6032 if ((n->value & GOVD_DEBUG_PRIVATE) |
6046 || lang_hooks.decls.omp_private_debug_clause (decl, shared)) | 6033 || lang_hooks.decls.omp_private_debug_clause (decl, shared)) |
6047 { | 6034 { |
6048 gcc_assert ((n->value & GOVD_DEBUG_PRIVATE) == 0 | 6035 gcc_assert ((n->value & GOVD_DEBUG_PRIVATE) == 0 |
6049 || ((n->value & GOVD_DATA_SHARE_CLASS) | 6036 || ((n->value & GOVD_DATA_SHARE_CLASS) |
6050 == GOVD_PRIVATE)); | 6037 == GOVD_PRIVATE)); |
6051 OMP_CLAUSE_SET_CODE (c, OMP_CLAUSE_PRIVATE); | 6038 OMP_CLAUSE_SET_CODE (c, OMP_CLAUSE_PRIVATE); |
6052 OMP_CLAUSE_PRIVATE_DEBUG (c) = 1; | 6039 OMP_CLAUSE_PRIVATE_DEBUG (c) = 1; |
6053 } | 6040 } |
6054 } | 6041 } |
6055 break; | 6042 break; |
6056 | 6043 |
6057 case OMP_CLAUSE_LASTPRIVATE: | 6044 case OMP_CLAUSE_LASTPRIVATE: |
6058 /* Make sure OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE is set to | 6045 /* Make sure OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE is set to |
6059 accurately reflect the presence of a FIRSTPRIVATE clause. */ | 6046 accurately reflect the presence of a FIRSTPRIVATE clause. */ |
6060 decl = OMP_CLAUSE_DECL (c); | 6047 decl = OMP_CLAUSE_DECL (c); |
6061 n = splay_tree_lookup (ctx->variables, (splay_tree_key) decl); | 6048 n = splay_tree_lookup (ctx->variables, (splay_tree_key) decl); |
6062 OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (c) | 6049 OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (c) |
6063 = (n->value & GOVD_FIRSTPRIVATE) != 0; | 6050 = (n->value & GOVD_FIRSTPRIVATE) != 0; |
6064 break; | 6051 break; |
6065 | 6052 |
6066 case OMP_CLAUSE_REDUCTION: | 6053 case OMP_CLAUSE_REDUCTION: |
6067 case OMP_CLAUSE_COPYIN: | 6054 case OMP_CLAUSE_COPYIN: |
6068 case OMP_CLAUSE_COPYPRIVATE: | 6055 case OMP_CLAUSE_COPYPRIVATE: |
6069 case OMP_CLAUSE_IF: | 6056 case OMP_CLAUSE_IF: |
6070 case OMP_CLAUSE_NUM_THREADS: | 6057 case OMP_CLAUSE_NUM_THREADS: |
6071 case OMP_CLAUSE_SCHEDULE: | 6058 case OMP_CLAUSE_SCHEDULE: |
6072 case OMP_CLAUSE_NOWAIT: | 6059 case OMP_CLAUSE_NOWAIT: |
6073 case OMP_CLAUSE_ORDERED: | 6060 case OMP_CLAUSE_ORDERED: |
6074 case OMP_CLAUSE_DEFAULT: | 6061 case OMP_CLAUSE_DEFAULT: |
6075 case OMP_CLAUSE_UNTIED: | 6062 case OMP_CLAUSE_UNTIED: |
6076 case OMP_CLAUSE_COLLAPSE: | 6063 case OMP_CLAUSE_COLLAPSE: |
6077 break; | 6064 break; |
6078 | 6065 |
6079 default: | 6066 default: |
6080 gcc_unreachable (); | 6067 gcc_unreachable (); |
6081 } | 6068 } |
6082 | 6069 |
6083 if (remove) | 6070 if (remove) |
6084 *list_p = OMP_CLAUSE_CHAIN (c); | 6071 *list_p = OMP_CLAUSE_CHAIN (c); |
6085 else | 6072 else |
6086 list_p = &OMP_CLAUSE_CHAIN (c); | 6073 list_p = &OMP_CLAUSE_CHAIN (c); |
6087 } | 6074 } |
6088 | 6075 |
6089 /* Add in any implicit data sharing. */ | 6076 /* Add in any implicit data sharing. */ |
6090 splay_tree_foreach (ctx->variables, gimplify_adjust_omp_clauses_1, list_p); | 6077 splay_tree_foreach (ctx->variables, gimplify_adjust_omp_clauses_1, list_p); |
6091 | 6078 |
6105 gimple g; | 6092 gimple g; |
6106 gimple_seq body = NULL; | 6093 gimple_seq body = NULL; |
6107 struct gimplify_ctx gctx; | 6094 struct gimplify_ctx gctx; |
6108 | 6095 |
6109 gimplify_scan_omp_clauses (&OMP_PARALLEL_CLAUSES (expr), pre_p, | 6096 gimplify_scan_omp_clauses (&OMP_PARALLEL_CLAUSES (expr), pre_p, |
6110 OMP_PARALLEL_COMBINED (expr) | 6097 OMP_PARALLEL_COMBINED (expr) |
6111 ? ORT_COMBINED_PARALLEL | 6098 ? ORT_COMBINED_PARALLEL |
6112 : ORT_PARALLEL); | 6099 : ORT_PARALLEL); |
6113 | 6100 |
6114 push_gimplify_context (&gctx); | 6101 push_gimplify_context (&gctx); |
6115 | 6102 |
6116 g = gimplify_and_return_first (OMP_PARALLEL_BODY (expr), &body); | 6103 g = gimplify_and_return_first (OMP_PARALLEL_BODY (expr), &body); |
6117 if (gimple_code (g) == GIMPLE_BIND) | 6104 if (gimple_code (g) == GIMPLE_BIND) |
6120 pop_gimplify_context (NULL); | 6107 pop_gimplify_context (NULL); |
6121 | 6108 |
6122 gimplify_adjust_omp_clauses (&OMP_PARALLEL_CLAUSES (expr)); | 6109 gimplify_adjust_omp_clauses (&OMP_PARALLEL_CLAUSES (expr)); |
6123 | 6110 |
6124 g = gimple_build_omp_parallel (body, | 6111 g = gimple_build_omp_parallel (body, |
6125 OMP_PARALLEL_CLAUSES (expr), | 6112 OMP_PARALLEL_CLAUSES (expr), |
6126 NULL_TREE, NULL_TREE); | 6113 NULL_TREE, NULL_TREE); |
6127 if (OMP_PARALLEL_COMBINED (expr)) | 6114 if (OMP_PARALLEL_COMBINED (expr)) |
6128 gimple_omp_set_subcode (g, GF_OMP_PARALLEL_COMBINED); | 6115 gimple_omp_set_subcode (g, GF_OMP_PARALLEL_COMBINED); |
6129 gimplify_seq_add_stmt (pre_p, g); | 6116 gimplify_seq_add_stmt (pre_p, g); |
6130 *expr_p = NULL_TREE; | 6117 *expr_p = NULL_TREE; |
6131 } | 6118 } |
6157 pop_gimplify_context (NULL); | 6144 pop_gimplify_context (NULL); |
6158 | 6145 |
6159 gimplify_adjust_omp_clauses (&OMP_TASK_CLAUSES (expr)); | 6146 gimplify_adjust_omp_clauses (&OMP_TASK_CLAUSES (expr)); |
6160 | 6147 |
6161 g = gimple_build_omp_task (body, | 6148 g = gimple_build_omp_task (body, |
6162 OMP_TASK_CLAUSES (expr), | 6149 OMP_TASK_CLAUSES (expr), |
6163 NULL_TREE, NULL_TREE, | 6150 NULL_TREE, NULL_TREE, |
6164 NULL_TREE, NULL_TREE, NULL_TREE); | 6151 NULL_TREE, NULL_TREE, NULL_TREE); |
6165 gimplify_seq_add_stmt (pre_p, g); | 6152 gimplify_seq_add_stmt (pre_p, g); |
6166 *expr_p = NULL_TREE; | 6153 *expr_p = NULL_TREE; |
6167 } | 6154 } |
6168 | 6155 |
6169 /* Gimplify the gross structure of an OMP_FOR statement. */ | 6156 /* Gimplify the gross structure of an OMP_FOR statement. */ |
6179 int i; | 6166 int i; |
6180 | 6167 |
6181 for_stmt = *expr_p; | 6168 for_stmt = *expr_p; |
6182 | 6169 |
6183 gimplify_scan_omp_clauses (&OMP_FOR_CLAUSES (for_stmt), pre_p, | 6170 gimplify_scan_omp_clauses (&OMP_FOR_CLAUSES (for_stmt), pre_p, |
6184 ORT_WORKSHARE); | 6171 ORT_WORKSHARE); |
6185 | 6172 |
6186 /* Handle OMP_FOR_INIT. */ | 6173 /* Handle OMP_FOR_INIT. */ |
6187 for_pre_body = NULL; | 6174 for_pre_body = NULL; |
6188 gimplify_and_add (OMP_FOR_PRE_BODY (for_stmt), &for_pre_body); | 6175 gimplify_and_add (OMP_FOR_PRE_BODY (for_stmt), &for_pre_body); |
6189 OMP_FOR_PRE_BODY (for_stmt) = NULL_TREE; | 6176 OMP_FOR_PRE_BODY (for_stmt) = NULL_TREE; |
6190 | 6177 |
6191 for_body = gimple_seq_alloc (); | 6178 for_body = gimple_seq_alloc (); |
6192 gcc_assert (TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)) | 6179 gcc_assert (TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)) |
6193 == TREE_VEC_LENGTH (OMP_FOR_COND (for_stmt))); | 6180 == TREE_VEC_LENGTH (OMP_FOR_COND (for_stmt))); |
6194 gcc_assert (TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)) | 6181 gcc_assert (TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)) |
6195 == TREE_VEC_LENGTH (OMP_FOR_INCR (for_stmt))); | 6182 == TREE_VEC_LENGTH (OMP_FOR_INCR (for_stmt))); |
6196 for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)); i++) | 6183 for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)); i++) |
6197 { | 6184 { |
6198 t = TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), i); | 6185 t = TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), i); |
6199 gcc_assert (TREE_CODE (t) == MODIFY_EXPR); | 6186 gcc_assert (TREE_CODE (t) == MODIFY_EXPR); |
6200 decl = TREE_OPERAND (t, 0); | 6187 decl = TREE_OPERAND (t, 0); |
6201 gcc_assert (DECL_P (decl)); | 6188 gcc_assert (DECL_P (decl)); |
6202 gcc_assert (INTEGRAL_TYPE_P (TREE_TYPE (decl)) | 6189 gcc_assert (INTEGRAL_TYPE_P (TREE_TYPE (decl)) |
6203 || POINTER_TYPE_P (TREE_TYPE (decl))); | 6190 || POINTER_TYPE_P (TREE_TYPE (decl))); |
6204 | 6191 |
6205 /* Make sure the iteration variable is private. */ | 6192 /* Make sure the iteration variable is private. */ |
6206 if (omp_is_private (gimplify_omp_ctxp, decl)) | 6193 if (omp_is_private (gimplify_omp_ctxp, decl)) |
6207 omp_notice_variable (gimplify_omp_ctxp, decl, true); | 6194 omp_notice_variable (gimplify_omp_ctxp, decl, true); |
6208 else | 6195 else |
6209 omp_add_variable (gimplify_omp_ctxp, decl, GOVD_PRIVATE | GOVD_SEEN); | 6196 omp_add_variable (gimplify_omp_ctxp, decl, GOVD_PRIVATE | GOVD_SEEN); |
6210 | 6197 |
6211 /* If DECL is not a gimple register, create a temporary variable to act | 6198 /* If DECL is not a gimple register, create a temporary variable to act |
6212 as an iteration counter. This is valid, since DECL cannot be | 6199 as an iteration counter. This is valid, since DECL cannot be |
6213 modified in the body of the loop. */ | 6200 modified in the body of the loop. */ |
6214 if (!is_gimple_reg (decl)) | 6201 if (!is_gimple_reg (decl)) |
6215 { | 6202 { |
6216 var = create_tmp_var (TREE_TYPE (decl), get_name (decl)); | 6203 var = create_tmp_var (TREE_TYPE (decl), get_name (decl)); |
6217 TREE_OPERAND (t, 0) = var; | 6204 TREE_OPERAND (t, 0) = var; |
6218 | 6205 |
6219 gimplify_seq_add_stmt (&for_body, gimple_build_assign (decl, var)); | 6206 gimplify_seq_add_stmt (&for_body, gimple_build_assign (decl, var)); |
6220 | 6207 |
6221 omp_add_variable (gimplify_omp_ctxp, var, GOVD_PRIVATE | GOVD_SEEN); | 6208 omp_add_variable (gimplify_omp_ctxp, var, GOVD_PRIVATE | GOVD_SEEN); |
6222 } | 6209 } |
6223 else | 6210 else |
6224 var = decl; | 6211 var = decl; |
6225 | 6212 |
6226 tret = gimplify_expr (&TREE_OPERAND (t, 1), &for_pre_body, NULL, | 6213 tret = gimplify_expr (&TREE_OPERAND (t, 1), &for_pre_body, NULL, |
6227 is_gimple_val, fb_rvalue); | 6214 is_gimple_val, fb_rvalue); |
6228 ret = MIN (ret, tret); | 6215 ret = MIN (ret, tret); |
6229 if (ret == GS_ERROR) | 6216 if (ret == GS_ERROR) |
6230 return ret; | 6217 return ret; |
6231 | 6218 |
6232 /* Handle OMP_FOR_COND. */ | 6219 /* Handle OMP_FOR_COND. */ |
6233 t = TREE_VEC_ELT (OMP_FOR_COND (for_stmt), i); | 6220 t = TREE_VEC_ELT (OMP_FOR_COND (for_stmt), i); |
6234 gcc_assert (COMPARISON_CLASS_P (t)); | 6221 gcc_assert (COMPARISON_CLASS_P (t)); |
6235 gcc_assert (TREE_OPERAND (t, 0) == decl); | 6222 gcc_assert (TREE_OPERAND (t, 0) == decl); |
6236 | 6223 |
6237 tret = gimplify_expr (&TREE_OPERAND (t, 1), &for_pre_body, NULL, | 6224 tret = gimplify_expr (&TREE_OPERAND (t, 1), &for_pre_body, NULL, |
6238 is_gimple_val, fb_rvalue); | 6225 is_gimple_val, fb_rvalue); |
6239 ret = MIN (ret, tret); | 6226 ret = MIN (ret, tret); |
6240 | 6227 |
6241 /* Handle OMP_FOR_INCR. */ | 6228 /* Handle OMP_FOR_INCR. */ |
6242 t = TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i); | 6229 t = TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i); |
6243 switch (TREE_CODE (t)) | 6230 switch (TREE_CODE (t)) |
6244 { | 6231 { |
6245 case PREINCREMENT_EXPR: | 6232 case PREINCREMENT_EXPR: |
6246 case POSTINCREMENT_EXPR: | 6233 case POSTINCREMENT_EXPR: |
6247 t = build_int_cst (TREE_TYPE (decl), 1); | 6234 t = build_int_cst (TREE_TYPE (decl), 1); |
6248 t = build2 (PLUS_EXPR, TREE_TYPE (decl), var, t); | 6235 t = build2 (PLUS_EXPR, TREE_TYPE (decl), var, t); |
6249 t = build2 (MODIFY_EXPR, TREE_TYPE (var), var, t); | 6236 t = build2 (MODIFY_EXPR, TREE_TYPE (var), var, t); |
6250 TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i) = t; | 6237 TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i) = t; |
6251 break; | 6238 break; |
6252 | 6239 |
6253 case PREDECREMENT_EXPR: | 6240 case PREDECREMENT_EXPR: |
6254 case POSTDECREMENT_EXPR: | 6241 case POSTDECREMENT_EXPR: |
6255 t = build_int_cst (TREE_TYPE (decl), -1); | 6242 t = build_int_cst (TREE_TYPE (decl), -1); |
6256 t = build2 (PLUS_EXPR, TREE_TYPE (decl), var, t); | 6243 t = build2 (PLUS_EXPR, TREE_TYPE (decl), var, t); |
6257 t = build2 (MODIFY_EXPR, TREE_TYPE (var), var, t); | 6244 t = build2 (MODIFY_EXPR, TREE_TYPE (var), var, t); |
6258 TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i) = t; | 6245 TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i) = t; |
6259 break; | 6246 break; |
6260 | 6247 |
6261 case MODIFY_EXPR: | 6248 case MODIFY_EXPR: |
6262 gcc_assert (TREE_OPERAND (t, 0) == decl); | 6249 gcc_assert (TREE_OPERAND (t, 0) == decl); |
6263 TREE_OPERAND (t, 0) = var; | 6250 TREE_OPERAND (t, 0) = var; |
6264 | 6251 |
6265 t = TREE_OPERAND (t, 1); | 6252 t = TREE_OPERAND (t, 1); |
6266 switch (TREE_CODE (t)) | 6253 switch (TREE_CODE (t)) |
6267 { | 6254 { |
6268 case PLUS_EXPR: | 6255 case PLUS_EXPR: |
6269 if (TREE_OPERAND (t, 1) == decl) | 6256 if (TREE_OPERAND (t, 1) == decl) |
6270 { | 6257 { |
6271 TREE_OPERAND (t, 1) = TREE_OPERAND (t, 0); | 6258 TREE_OPERAND (t, 1) = TREE_OPERAND (t, 0); |
6272 TREE_OPERAND (t, 0) = var; | 6259 TREE_OPERAND (t, 0) = var; |
6273 break; | 6260 break; |
6274 } | 6261 } |
6275 | 6262 |
6276 /* Fallthru. */ | 6263 /* Fallthru. */ |
6277 case MINUS_EXPR: | 6264 case MINUS_EXPR: |
6278 case POINTER_PLUS_EXPR: | 6265 case POINTER_PLUS_EXPR: |
6279 gcc_assert (TREE_OPERAND (t, 0) == decl); | 6266 gcc_assert (TREE_OPERAND (t, 0) == decl); |
6280 TREE_OPERAND (t, 0) = var; | 6267 TREE_OPERAND (t, 0) = var; |
6281 break; | 6268 break; |
6282 default: | 6269 default: |
6283 gcc_unreachable (); | 6270 gcc_unreachable (); |
6284 } | 6271 } |
6285 | 6272 |
6286 tret = gimplify_expr (&TREE_OPERAND (t, 1), &for_pre_body, NULL, | 6273 tret = gimplify_expr (&TREE_OPERAND (t, 1), &for_pre_body, NULL, |
6287 is_gimple_val, fb_rvalue); | 6274 is_gimple_val, fb_rvalue); |
6288 ret = MIN (ret, tret); | 6275 ret = MIN (ret, tret); |
6289 break; | 6276 break; |
6290 | 6277 |
6291 default: | 6278 default: |
6292 gcc_unreachable (); | 6279 gcc_unreachable (); |
6293 } | 6280 } |
6294 | 6281 |
6295 if (var != decl || TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)) > 1) | 6282 if (var != decl || TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)) > 1) |
6296 { | 6283 { |
6297 tree c; | 6284 tree c; |
6298 for (c = OMP_FOR_CLAUSES (for_stmt); c ; c = OMP_CLAUSE_CHAIN (c)) | 6285 for (c = OMP_FOR_CLAUSES (for_stmt); c ; c = OMP_CLAUSE_CHAIN (c)) |
6299 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE | 6286 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE |
6300 && OMP_CLAUSE_DECL (c) == decl | 6287 && OMP_CLAUSE_DECL (c) == decl |
6301 && OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c) == NULL) | 6288 && OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c) == NULL) |
6302 { | 6289 { |
6303 t = TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i); | 6290 t = TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i); |
6304 gcc_assert (TREE_CODE (t) == MODIFY_EXPR); | 6291 gcc_assert (TREE_CODE (t) == MODIFY_EXPR); |
6305 gcc_assert (TREE_OPERAND (t, 0) == var); | 6292 gcc_assert (TREE_OPERAND (t, 0) == var); |
6306 t = TREE_OPERAND (t, 1); | 6293 t = TREE_OPERAND (t, 1); |
6307 gcc_assert (TREE_CODE (t) == PLUS_EXPR | 6294 gcc_assert (TREE_CODE (t) == PLUS_EXPR |
6308 || TREE_CODE (t) == MINUS_EXPR | 6295 || TREE_CODE (t) == MINUS_EXPR |
6309 || TREE_CODE (t) == POINTER_PLUS_EXPR); | 6296 || TREE_CODE (t) == POINTER_PLUS_EXPR); |
6310 gcc_assert (TREE_OPERAND (t, 0) == var); | 6297 gcc_assert (TREE_OPERAND (t, 0) == var); |
6311 t = build2 (TREE_CODE (t), TREE_TYPE (decl), decl, | 6298 t = build2 (TREE_CODE (t), TREE_TYPE (decl), decl, |
6312 TREE_OPERAND (t, 1)); | 6299 TREE_OPERAND (t, 1)); |
6313 gimplify_assign (decl, t, | 6300 gimplify_assign (decl, t, |
6314 &OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c)); | 6301 &OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c)); |
6315 } | 6302 } |
6316 } | 6303 } |
6317 } | 6304 } |
6318 | 6305 |
6319 gimplify_and_add (OMP_FOR_BODY (for_stmt), &for_body); | 6306 gimplify_and_add (OMP_FOR_BODY (for_stmt), &for_body); |
6320 | 6307 |
6321 gimplify_adjust_omp_clauses (&OMP_FOR_CLAUSES (for_stmt)); | 6308 gimplify_adjust_omp_clauses (&OMP_FOR_CLAUSES (for_stmt)); |
6322 | 6309 |
6323 gfor = gimple_build_omp_for (for_body, OMP_FOR_CLAUSES (for_stmt), | 6310 gfor = gimple_build_omp_for (for_body, OMP_FOR_CLAUSES (for_stmt), |
6324 TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)), | 6311 TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)), |
6325 for_pre_body); | 6312 for_pre_body); |
6326 | 6313 |
6327 for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)); i++) | 6314 for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)); i++) |
6328 { | 6315 { |
6329 t = TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), i); | 6316 t = TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), i); |
6330 gimple_omp_for_set_index (gfor, i, TREE_OPERAND (t, 0)); | 6317 gimple_omp_for_set_index (gfor, i, TREE_OPERAND (t, 0)); |
6378 | 6365 |
6379 if (TREE_CODE (expr) == INDIRECT_REF) | 6366 if (TREE_CODE (expr) == INDIRECT_REF) |
6380 { | 6367 { |
6381 expr = TREE_OPERAND (expr, 0); | 6368 expr = TREE_OPERAND (expr, 0); |
6382 while (expr != addr | 6369 while (expr != addr |
6383 && (CONVERT_EXPR_P (expr) | 6370 && (CONVERT_EXPR_P (expr) |
6384 || TREE_CODE (expr) == NON_LVALUE_EXPR) | 6371 || TREE_CODE (expr) == NON_LVALUE_EXPR) |
6385 && TREE_CODE (expr) == TREE_CODE (addr) | 6372 && TREE_CODE (expr) == TREE_CODE (addr) |
6386 && types_compatible_p (TREE_TYPE (expr), TREE_TYPE (addr))) | 6373 && types_compatible_p (TREE_TYPE (expr), TREE_TYPE (addr))) |
6387 { | 6374 { |
6388 expr = TREE_OPERAND (expr, 0); | 6375 expr = TREE_OPERAND (expr, 0); |
6389 addr = TREE_OPERAND (addr, 0); | 6376 addr = TREE_OPERAND (addr, 0); |
6390 } | 6377 } |
6391 if (expr == addr) | 6378 if (expr == addr) |
6392 return true; | 6379 return true; |
6393 return (TREE_CODE (addr) == ADDR_EXPR | 6380 return (TREE_CODE (addr) == ADDR_EXPR |
6394 && TREE_CODE (expr) == ADDR_EXPR | 6381 && TREE_CODE (expr) == ADDR_EXPR |
6395 && TREE_OPERAND (addr, 0) == TREE_OPERAND (expr, 0)); | 6382 && TREE_OPERAND (addr, 0) == TREE_OPERAND (expr, 0)); |
6396 } | 6383 } |
6397 if (TREE_CODE (addr) == ADDR_EXPR && expr == TREE_OPERAND (addr, 0)) | 6384 if (TREE_CODE (addr) == ADDR_EXPR && expr == TREE_OPERAND (addr, 0)) |
6398 return true; | 6385 return true; |
6399 return false; | 6386 return false; |
6400 } | 6387 } |
6404 the lhs, evaluate it into a temporary. Return 1 if the lhs appeared as | 6391 the lhs, evaluate it into a temporary. Return 1 if the lhs appeared as |
6405 a subexpression, 0 if it did not, or -1 if an error was encountered. */ | 6392 a subexpression, 0 if it did not, or -1 if an error was encountered. */ |
6406 | 6393 |
6407 static int | 6394 static int |
6408 goa_stabilize_expr (tree *expr_p, gimple_seq *pre_p, tree lhs_addr, | 6395 goa_stabilize_expr (tree *expr_p, gimple_seq *pre_p, tree lhs_addr, |
6409 tree lhs_var) | 6396 tree lhs_var) |
6410 { | 6397 { |
6411 tree expr = *expr_p; | 6398 tree expr = *expr_p; |
6412 int saw_lhs; | 6399 int saw_lhs; |
6413 | 6400 |
6414 if (goa_lhs_expr_p (expr, lhs_addr)) | 6401 if (goa_lhs_expr_p (expr, lhs_addr)) |
6423 switch (TREE_CODE_CLASS (TREE_CODE (expr))) | 6410 switch (TREE_CODE_CLASS (TREE_CODE (expr))) |
6424 { | 6411 { |
6425 case tcc_binary: | 6412 case tcc_binary: |
6426 case tcc_comparison: | 6413 case tcc_comparison: |
6427 saw_lhs |= goa_stabilize_expr (&TREE_OPERAND (expr, 1), pre_p, lhs_addr, | 6414 saw_lhs |= goa_stabilize_expr (&TREE_OPERAND (expr, 1), pre_p, lhs_addr, |
6428 lhs_var); | 6415 lhs_var); |
6429 case tcc_unary: | 6416 case tcc_unary: |
6430 saw_lhs |= goa_stabilize_expr (&TREE_OPERAND (expr, 0), pre_p, lhs_addr, | 6417 saw_lhs |= goa_stabilize_expr (&TREE_OPERAND (expr, 0), pre_p, lhs_addr, |
6431 lhs_var); | 6418 lhs_var); |
6432 break; | 6419 break; |
6433 case tcc_expression: | 6420 case tcc_expression: |
6434 switch (TREE_CODE (expr)) | 6421 switch (TREE_CODE (expr)) |
6435 { | 6422 { |
6436 case TRUTH_ANDIF_EXPR: | 6423 case TRUTH_ANDIF_EXPR: |
6449 } | 6436 } |
6450 break; | 6437 break; |
6451 default: | 6438 default: |
6452 break; | 6439 break; |
6453 } | 6440 } |
6454 break; | |
6455 default: | |
6456 break; | |
6457 } | |
6458 | 6441 |
6459 if (saw_lhs == 0) | 6442 if (saw_lhs == 0) |
6460 { | 6443 { |
6461 enum gimplify_status gs; | 6444 enum gimplify_status gs; |
6462 gs = gimplify_expr (expr_p, pre_p, NULL, is_gimple_val, fb_rvalue); | 6445 gs = gimplify_expr (expr_p, pre_p, NULL, is_gimple_val, fb_rvalue); |
6463 if (gs != GS_ALL_DONE) | 6446 if (gs != GS_ALL_DONE) |
6464 saw_lhs = -1; | 6447 saw_lhs = -1; |
6465 } | 6448 } |
6466 | 6449 |
6467 return saw_lhs; | 6450 return saw_lhs; |
6468 } | 6451 } |
6469 | 6452 |
6535 side-effects of '--' must actually occur *after* the post | 6518 side-effects of '--' must actually occur *after* the post |
6536 side-effects of '++'. However, gimplification will first visit | 6519 side-effects of '++'. However, gimplification will first visit |
6537 the inner expression, so if a separate POST sequence was not | 6520 the inner expression, so if a separate POST sequence was not |
6538 used, the resulting sequence would be: | 6521 used, the resulting sequence would be: |
6539 | 6522 |
6540 1 t.1 = *p | 6523 1 t.1 = *p |
6541 2 p = p - 1 | 6524 2 p = p - 1 |
6542 3 t.2 = t.1 + 1 | 6525 3 t.2 = t.1 + 1 |
6543 4 *p = t.2 | 6526 4 *p = t.2 |
6544 | 6527 |
6545 However, the post-decrement operation in line #2 must not be | 6528 However, the post-decrement operation in line #2 must not be |
6546 evaluated until after the store to *p at line #4, so the | 6529 evaluated until after the store to *p at line #4, so the |
6547 correct sequence should be: | 6530 correct sequence should be: |
6548 | 6531 |
6549 1 t.1 = *p | 6532 1 t.1 = *p |
6550 2 t.2 = t.1 + 1 | 6533 2 t.2 = t.1 + 1 |
6551 3 *p = t.2 | 6534 3 *p = t.2 |
6552 4 p = p - 1 | 6535 4 p = p - 1 |
6553 | 6536 |
6554 So, by specifying a separate post queue, it is possible | 6537 So, by specifying a separate post queue, it is possible |
6555 to emit the post side-effects in the correct order. | 6538 to emit the post side-effects in the correct order. |
6556 If POST_P is NULL, an internal queue will be used. Before | 6539 If POST_P is NULL, an internal queue will be used. Before |
6557 returning to the caller, the sequence POST_P is appended to | 6540 returning to the caller, the sequence POST_P is appended to |
6576 function iterates until EXPR is completely gimplified or an error | 6559 function iterates until EXPR is completely gimplified or an error |
6577 occurs. */ | 6560 occurs. */ |
6578 | 6561 |
6579 enum gimplify_status | 6562 enum gimplify_status |
6580 gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, | 6563 gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, |
6581 bool (*gimple_test_f) (tree), fallback_t fallback) | 6564 bool (*gimple_test_f) (tree), fallback_t fallback) |
6582 { | 6565 { |
6583 tree tmp; | 6566 tree tmp; |
6584 gimple_seq internal_pre = NULL; | 6567 gimple_seq internal_pre = NULL; |
6585 gimple_seq internal_post = NULL; | 6568 gimple_seq internal_post = NULL; |
6586 tree save_expr; | 6569 tree save_expr; |
6610 || gimple_test_f == is_gimple_reg_rhs_or_call | 6593 || gimple_test_f == is_gimple_reg_rhs_or_call |
6611 || gimple_test_f == is_gimple_asm_val | 6594 || gimple_test_f == is_gimple_asm_val |
6612 || gimple_test_f == is_gimple_mem_ref_addr) | 6595 || gimple_test_f == is_gimple_mem_ref_addr) |
6613 gcc_assert (fallback & fb_rvalue); | 6596 gcc_assert (fallback & fb_rvalue); |
6614 else if (gimple_test_f == is_gimple_min_lval | 6597 else if (gimple_test_f == is_gimple_min_lval |
6615 || gimple_test_f == is_gimple_lvalue) | 6598 || gimple_test_f == is_gimple_lvalue) |
6616 gcc_assert (fallback & fb_lvalue); | 6599 gcc_assert (fallback & fb_lvalue); |
6617 else if (gimple_test_f == is_gimple_addressable) | 6600 else if (gimple_test_f == is_gimple_addressable) |
6618 gcc_assert (fallback & fb_either); | 6601 gcc_assert (fallback & fb_either); |
6619 else if (gimple_test_f == is_gimple_stmt) | 6602 else if (gimple_test_f == is_gimple_stmt) |
6620 gcc_assert (fallback == fb_none); | 6603 gcc_assert (fallback == fb_none); |
6621 else | 6604 else |
6622 { | 6605 { |
6623 /* We should have recognized the GIMPLE_TEST_F predicate to | 6606 /* We should have recognized the GIMPLE_TEST_F predicate to |
6624 know what kind of fallback to use in case a temporary is | 6607 know what kind of fallback to use in case a temporary is |
6625 needed to hold the value or address of *EXPR_P. */ | 6608 needed to hold the value or address of *EXPR_P. */ |
6626 gcc_unreachable (); | 6609 gcc_unreachable (); |
6627 } | 6610 } |
6628 | 6611 |
6629 /* We used to check the predicate here and return immediately if it | 6612 /* We used to check the predicate here and return immediately if it |
6630 succeeds. This is wrong; the design is for gimplification to be | 6613 succeeds. This is wrong; the design is for gimplification to be |
6655 /* Loop over the specific gimplifiers until the toplevel node | 6638 /* Loop over the specific gimplifiers until the toplevel node |
6656 remains the same. */ | 6639 remains the same. */ |
6657 do | 6640 do |
6658 { | 6641 { |
6659 /* Strip away as many useless type conversions as possible | 6642 /* Strip away as many useless type conversions as possible |
6660 at the toplevel. */ | 6643 at the toplevel. */ |
6661 STRIP_USELESS_TYPE_CONVERSION (*expr_p); | 6644 STRIP_USELESS_TYPE_CONVERSION (*expr_p); |
6662 | 6645 |
6663 /* Remember the expr. */ | 6646 /* Remember the expr. */ |
6664 save_expr = *expr_p; | 6647 save_expr = *expr_p; |
6665 | 6648 |
6666 /* Die, die, die, my darling. */ | 6649 /* Die, die, die, my darling. */ |
6667 if (save_expr == error_mark_node | 6650 if (save_expr == error_mark_node |
6668 || (TREE_TYPE (save_expr) | 6651 || (TREE_TYPE (save_expr) |
6669 && TREE_TYPE (save_expr) == error_mark_node)) | 6652 && TREE_TYPE (save_expr) == error_mark_node)) |
6670 { | 6653 { |
6671 ret = GS_ERROR; | 6654 ret = GS_ERROR; |
6672 break; | 6655 break; |
6673 } | 6656 } |
6674 | 6657 |
6675 /* Do any language-specific gimplification. */ | 6658 /* Do any language-specific gimplification. */ |
6676 ret = ((enum gimplify_status) | 6659 ret = ((enum gimplify_status) |
6677 lang_hooks.gimplify_expr (expr_p, pre_p, post_p)); | 6660 lang_hooks.gimplify_expr (expr_p, pre_p, post_p)); |
6678 if (ret == GS_OK) | 6661 if (ret == GS_OK) |
6679 { | 6662 { |
6680 if (*expr_p == NULL_TREE) | 6663 if (*expr_p == NULL_TREE) |
6681 break; | 6664 break; |
6682 if (*expr_p != save_expr) | 6665 if (*expr_p != save_expr) |
6683 continue; | 6666 continue; |
6684 } | 6667 } |
6685 else if (ret != GS_UNHANDLED) | 6668 else if (ret != GS_UNHANDLED) |
6686 break; | 6669 break; |
6687 | 6670 |
6688 /* Make sure that all the cases set 'ret' appropriately. */ | 6671 /* Make sure that all the cases set 'ret' appropriately. */ |
6689 ret = GS_UNHANDLED; | 6672 ret = GS_UNHANDLED; |
6690 switch (TREE_CODE (*expr_p)) | 6673 switch (TREE_CODE (*expr_p)) |
6691 { | 6674 { |
7322 /* If we encountered an error_mark somewhere nested inside, either | 7305 /* If we encountered an error_mark somewhere nested inside, either |
7323 stub out the statement or propagate the error back out. */ | 7306 stub out the statement or propagate the error back out. */ |
7324 if (ret == GS_ERROR) | 7307 if (ret == GS_ERROR) |
7325 { | 7308 { |
7326 if (is_statement) | 7309 if (is_statement) |
7327 *expr_p = NULL; | 7310 *expr_p = NULL; |
7328 goto out; | 7311 goto out; |
7329 } | 7312 } |
7330 | 7313 |
7331 /* This was only valid as a return value from the langhook, which | 7314 /* This was only valid as a return value from the langhook, which |
7332 we handled. Make sure it doesn't escape from any other context. */ | 7315 we handled. Make sure it doesn't escape from any other context. */ |
7333 gcc_assert (ret != GS_UNHANDLED); | 7316 gcc_assert (ret != GS_UNHANDLED); |
7334 | 7317 |
7335 if (fallback == fb_none && *expr_p && !is_gimple_stmt (*expr_p)) | 7318 if (fallback == fb_none && *expr_p && !is_gimple_stmt (*expr_p)) |
7336 { | 7319 { |
7337 /* We aren't looking for a value, and we don't have a valid | 7320 /* We aren't looking for a value, and we don't have a valid |
7338 statement. If it doesn't have side-effects, throw it away. */ | 7321 statement. If it doesn't have side-effects, throw it away. */ |
7339 if (!TREE_SIDE_EFFECTS (*expr_p)) | 7322 if (!TREE_SIDE_EFFECTS (*expr_p)) |
7340 *expr_p = NULL; | 7323 *expr_p = NULL; |
7341 else if (!TREE_THIS_VOLATILE (*expr_p)) | 7324 else if (!TREE_THIS_VOLATILE (*expr_p)) |
7342 { | 7325 { |
7343 /* This is probably a _REF that contains something nested that | 7326 /* This is probably a _REF that contains something nested that |
7344 has side effects. Recurse through the operands to find it. */ | 7327 has side effects. Recurse through the operands to find it. */ |
7345 enum tree_code code = TREE_CODE (*expr_p); | 7328 enum tree_code code = TREE_CODE (*expr_p); |
7346 | 7329 |
7347 switch (code) | 7330 switch (code) |
7348 { | 7331 { |
7349 case COMPONENT_REF: | 7332 case COMPONENT_REF: |
7350 case REALPART_EXPR: | 7333 case REALPART_EXPR: |
7351 case IMAGPART_EXPR: | 7334 case IMAGPART_EXPR: |
7352 case VIEW_CONVERT_EXPR: | 7335 case VIEW_CONVERT_EXPR: |
7353 gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p, | 7336 gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p, |
7354 gimple_test_f, fallback); | 7337 gimple_test_f, fallback); |
7355 break; | 7338 break; |
7356 | 7339 |
7357 case ARRAY_REF: | 7340 case ARRAY_REF: |
7358 case ARRAY_RANGE_REF: | 7341 case ARRAY_RANGE_REF: |
7359 gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p, | 7342 gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p, |
7360 gimple_test_f, fallback); | 7343 gimple_test_f, fallback); |
7361 gimplify_expr (&TREE_OPERAND (*expr_p, 1), pre_p, post_p, | 7344 gimplify_expr (&TREE_OPERAND (*expr_p, 1), pre_p, post_p, |
7362 gimple_test_f, fallback); | 7345 gimple_test_f, fallback); |
7363 break; | 7346 break; |
7364 | 7347 |
7365 default: | 7348 default: |
7366 /* Anything else with side-effects must be converted to | 7349 /* Anything else with side-effects must be converted to |
7367 a valid statement before we get here. */ | 7350 a valid statement before we get here. */ |
7368 gcc_unreachable (); | 7351 gcc_unreachable (); |
7369 } | 7352 } |
7370 | 7353 |
7371 *expr_p = NULL; | 7354 *expr_p = NULL; |
7372 } | 7355 } |
7373 else if (COMPLETE_TYPE_P (TREE_TYPE (*expr_p)) | 7356 else if (COMPLETE_TYPE_P (TREE_TYPE (*expr_p)) |
7374 && TYPE_MODE (TREE_TYPE (*expr_p)) != BLKmode) | 7357 && TYPE_MODE (TREE_TYPE (*expr_p)) != BLKmode) |
7375 { | 7358 { |
7376 /* Historically, the compiler has treated a bare reference | 7359 /* Historically, the compiler has treated a bare reference |
7377 to a non-BLKmode volatile lvalue as forcing a load. */ | 7360 to a non-BLKmode volatile lvalue as forcing a load. */ |
7378 tree type = TYPE_MAIN_VARIANT (TREE_TYPE (*expr_p)); | 7361 tree type = TYPE_MAIN_VARIANT (TREE_TYPE (*expr_p)); |
7379 | 7362 |
7380 /* Normally, we do not want to create a temporary for a | 7363 /* Normally, we do not want to create a temporary for a |
7381 TREE_ADDRESSABLE type because such a type should not be | 7364 TREE_ADDRESSABLE type because such a type should not be |
7382 copied by bitwise-assignment. However, we make an | 7365 copied by bitwise-assignment. However, we make an |
7383 exception here, as all we are doing here is ensuring that | 7366 exception here, as all we are doing here is ensuring that |
7384 we read the bytes that make up the type. We use | 7367 we read the bytes that make up the type. We use |
7385 create_tmp_var_raw because create_tmp_var will abort when | 7368 create_tmp_var_raw because create_tmp_var will abort when |
7386 given a TREE_ADDRESSABLE type. */ | 7369 given a TREE_ADDRESSABLE type. */ |
7387 tree tmp = create_tmp_var_raw (type, "vol"); | 7370 tree tmp = create_tmp_var_raw (type, "vol"); |
7388 gimple_add_tmp_var (tmp); | 7371 gimple_add_tmp_var (tmp); |
7389 gimplify_assign (tmp, *expr_p, pre_p); | 7372 gimplify_assign (tmp, *expr_p, pre_p); |
7390 *expr_p = NULL; | 7373 *expr_p = NULL; |
7391 } | 7374 } |
7392 else | 7375 else |
7393 /* We can't do anything useful with a volatile reference to | 7376 /* We can't do anything useful with a volatile reference to |
7394 an incomplete type, so just throw it away. Likewise for | 7377 an incomplete type, so just throw it away. Likewise for |
7395 a BLKmode type, since any implicit inner load should | 7378 a BLKmode type, since any implicit inner load should |
7396 already have been turned into an explicit one by the | 7379 already have been turned into an explicit one by the |
7397 gimplification process. */ | 7380 gimplification process. */ |
7398 *expr_p = NULL; | 7381 *expr_p = NULL; |
7399 } | 7382 } |
7400 | 7383 |
7401 /* If we are gimplifying at the statement level, we're done. Tack | 7384 /* If we are gimplifying at the statement level, we're done. Tack |
7402 everything together and return. */ | 7385 everything together and return. */ |
7403 if (fallback == fb_none || is_statement) | 7386 if (fallback == fb_none || is_statement) |
7405 /* Since *EXPR_P has been converted into a GIMPLE tuple, clear | 7388 /* Since *EXPR_P has been converted into a GIMPLE tuple, clear |
7406 it out for GC to reclaim it. */ | 7389 it out for GC to reclaim it. */ |
7407 *expr_p = NULL_TREE; | 7390 *expr_p = NULL_TREE; |
7408 | 7391 |
7409 if (!gimple_seq_empty_p (internal_pre) | 7392 if (!gimple_seq_empty_p (internal_pre) |
7410 || !gimple_seq_empty_p (internal_post)) | 7393 || !gimple_seq_empty_p (internal_post)) |
7411 { | 7394 { |
7412 gimplify_seq_add_seq (&internal_pre, internal_post); | 7395 gimplify_seq_add_seq (&internal_pre, internal_post); |
7413 gimplify_seq_add_seq (pre_p, internal_pre); | 7396 gimplify_seq_add_seq (pre_p, internal_pre); |
7414 } | 7397 } |
7415 | 7398 |
7416 /* The result of gimplifying *EXPR_P is going to be the last few | 7399 /* The result of gimplifying *EXPR_P is going to be the last few |
7417 statements in *PRE_P and *POST_P. Add location information | 7400 statements in *PRE_P and *POST_P. Add location information |
7418 to all the statements that were added by the gimplification | 7401 to all the statements that were added by the gimplification |
7419 helpers. */ | 7402 helpers. */ |
7420 if (!gimple_seq_empty_p (*pre_p)) | 7403 if (!gimple_seq_empty_p (*pre_p)) |
7421 annotate_all_with_location_after (*pre_p, pre_last_gsi, input_location); | 7404 annotate_all_with_location_after (*pre_p, pre_last_gsi, input_location); |
7422 | 7405 |
7423 if (!gimple_seq_empty_p (*post_p)) | 7406 if (!gimple_seq_empty_p (*post_p)) |
7424 annotate_all_with_location_after (*post_p, post_last_gsi, | 7407 annotate_all_with_location_after (*post_p, post_last_gsi, |
7425 input_location); | 7408 input_location); |
7426 | 7409 |
7427 goto out; | 7410 goto out; |
7428 } | 7411 } |
7429 | 7412 |
7430 #ifdef ENABLE_GIMPLE_CHECKING | 7413 #ifdef ENABLE_GIMPLE_CHECKING |
7431 if (*expr_p) | 7414 if (*expr_p) |
7432 { | 7415 { |
7433 enum tree_code code = TREE_CODE (*expr_p); | 7416 enum tree_code code = TREE_CODE (*expr_p); |
7434 /* These expressions should already be in gimple IR form. */ | 7417 /* These expressions should already be in gimple IR form. */ |
7435 gcc_assert (code != MODIFY_EXPR | 7418 gcc_assert (code != MODIFY_EXPR |
7436 && code != ASM_EXPR | 7419 && code != ASM_EXPR |
7437 && code != BIND_EXPR | 7420 && code != BIND_EXPR |
7438 && code != CATCH_EXPR | 7421 && code != CATCH_EXPR |
7439 && (code != COND_EXPR || gimplify_ctxp->allow_rhs_cond_expr) | 7422 && (code != COND_EXPR || gimplify_ctxp->allow_rhs_cond_expr) |
7440 && code != EH_FILTER_EXPR | 7423 && code != EH_FILTER_EXPR |
7441 && code != GOTO_EXPR | 7424 && code != GOTO_EXPR |
7442 && code != LABEL_EXPR | 7425 && code != LABEL_EXPR |
7443 && code != LOOP_EXPR | 7426 && code != LOOP_EXPR |
7444 && code != SWITCH_EXPR | 7427 && code != SWITCH_EXPR |
7445 && code != TRY_FINALLY_EXPR | 7428 && code != TRY_FINALLY_EXPR |
7446 && code != OMP_CRITICAL | 7429 && code != OMP_CRITICAL |
7447 && code != OMP_FOR | 7430 && code != OMP_FOR |
7448 && code != OMP_MASTER | 7431 && code != OMP_MASTER |
7449 && code != OMP_ORDERED | 7432 && code != OMP_ORDERED |
7450 && code != OMP_PARALLEL | 7433 && code != OMP_PARALLEL |
7451 && code != OMP_SECTIONS | 7434 && code != OMP_SECTIONS |
7452 && code != OMP_SECTION | 7435 && code != OMP_SECTION |
7453 && code != OMP_SINGLE); | 7436 && code != OMP_SINGLE); |
7454 } | 7437 } |
7455 #endif | 7438 #endif |
7456 | 7439 |
7457 /* Otherwise we're gimplifying a subexpression, so the resulting | 7440 /* Otherwise we're gimplifying a subexpression, so the resulting |
7458 value is interesting. If it's a valid operand that matches | 7441 value is interesting. If it's a valid operand that matches |
7472 if ((fallback & fb_lvalue) | 7455 if ((fallback & fb_lvalue) |
7473 && gimple_seq_empty_p (internal_post) | 7456 && gimple_seq_empty_p (internal_post) |
7474 && is_gimple_addressable (*expr_p)) | 7457 && is_gimple_addressable (*expr_p)) |
7475 { | 7458 { |
7476 /* An lvalue will do. Take the address of the expression, store it | 7459 /* An lvalue will do. Take the address of the expression, store it |
7477 in a temporary, and replace the expression with an INDIRECT_REF of | 7460 in a temporary, and replace the expression with an INDIRECT_REF of |
7478 that temporary. */ | 7461 that temporary. */ |
7479 tmp = build_fold_addr_expr_loc (input_location, *expr_p); | 7462 tmp = build_fold_addr_expr_loc (input_location, *expr_p); |
7480 gimplify_expr (&tmp, pre_p, post_p, is_gimple_reg, fb_rvalue); | 7463 gimplify_expr (&tmp, pre_p, post_p, is_gimple_reg, fb_rvalue); |
7481 *expr_p = build_simple_mem_ref (tmp); | 7464 *expr_p = build_simple_mem_ref (tmp); |
7482 } | 7465 } |
7483 else if ((fallback & fb_rvalue) && is_gimple_reg_rhs_or_call (*expr_p)) | 7466 else if ((fallback & fb_rvalue) && is_gimple_reg_rhs_or_call (*expr_p)) |
7484 { | 7467 { |
7485 /* An rvalue will do. Assign the gimplified expression into a | 7468 /* An rvalue will do. Assign the gimplified expression into a |
7486 new temporary TMP and replace the original expression with | 7469 new temporary TMP and replace the original expression with |
7487 TMP. First, make sure that the expression has a type so that | 7470 TMP. First, make sure that the expression has a type so that |
7488 it can be assigned into a temporary. */ | 7471 it can be assigned into a temporary. */ |
7489 gcc_assert (!VOID_TYPE_P (TREE_TYPE (*expr_p))); | 7472 gcc_assert (!VOID_TYPE_P (TREE_TYPE (*expr_p))); |
7490 | 7473 |
7491 if (!gimple_seq_empty_p (internal_post) || (fallback & fb_lvalue)) | 7474 if (!gimple_seq_empty_p (internal_post) || (fallback & fb_lvalue)) |
7492 /* The postqueue might change the value of the expression between | 7475 /* The postqueue might change the value of the expression between |
7493 the initialization and use of the temporary, so we can't use a | 7476 the initialization and use of the temporary, so we can't use a |
7494 formal temp. FIXME do we care? */ | 7477 formal temp. FIXME do we care? */ |
7495 { | 7478 { |
7496 *expr_p = get_initialized_tmp_var (*expr_p, pre_p, post_p); | 7479 *expr_p = get_initialized_tmp_var (*expr_p, pre_p, post_p); |
7497 if (TREE_CODE (TREE_TYPE (*expr_p)) == COMPLEX_TYPE | 7480 if (TREE_CODE (TREE_TYPE (*expr_p)) == COMPLEX_TYPE |
7498 || TREE_CODE (TREE_TYPE (*expr_p)) == VECTOR_TYPE) | 7481 || TREE_CODE (TREE_TYPE (*expr_p)) == VECTOR_TYPE) |
7499 DECL_GIMPLE_REG_P (*expr_p) = 1; | 7482 DECL_GIMPLE_REG_P (*expr_p) = 1; |
7500 } | 7483 } |
7501 else | 7484 else |
7502 *expr_p = get_formal_tmp_var (*expr_p, pre_p); | 7485 *expr_p = get_formal_tmp_var (*expr_p, pre_p); |
7503 } | 7486 } |
7504 else | 7487 else |
7505 { | 7488 { |
7506 #ifdef ENABLE_GIMPLE_CHECKING | 7489 #ifdef ENABLE_GIMPLE_CHECKING |
7507 if (!(fallback & fb_mayfail)) | 7490 if (!(fallback & fb_mayfail)) |
7508 { | 7491 { |
7509 fprintf (stderr, "gimplification failed:\n"); | 7492 fprintf (stderr, "gimplification failed:\n"); |
7510 print_generic_expr (stderr, *expr_p, 0); | 7493 print_generic_expr (stderr, *expr_p, 0); |
7511 debug_tree (*expr_p); | 7494 debug_tree (*expr_p); |
7512 internal_error ("gimplification failed"); | 7495 internal_error ("gimplification failed"); |
7513 } | 7496 } |
7514 #endif | 7497 #endif |
7515 gcc_assert (fallback & fb_mayfail); | 7498 gcc_assert (fallback & fb_mayfail); |
7516 | 7499 |
7517 /* If this is an asm statement, and the user asked for the | 7500 /* If this is an asm statement, and the user asked for the |
7518 impossible, don't die. Fail and let gimplify_asm_expr | 7501 impossible, don't die. Fail and let gimplify_asm_expr |
7519 issue an error. */ | 7502 issue an error. */ |
7520 ret = GS_ERROR; | 7503 ret = GS_ERROR; |
7521 goto out; | 7504 goto out; |
7522 } | 7505 } |
7523 | 7506 |
7524 /* Make sure the temporary matches our predicate. */ | 7507 /* Make sure the temporary matches our predicate. */ |
7564 case FIXED_POINT_TYPE: | 7547 case FIXED_POINT_TYPE: |
7565 gimplify_one_sizepos (&TYPE_MIN_VALUE (type), list_p); | 7548 gimplify_one_sizepos (&TYPE_MIN_VALUE (type), list_p); |
7566 gimplify_one_sizepos (&TYPE_MAX_VALUE (type), list_p); | 7549 gimplify_one_sizepos (&TYPE_MAX_VALUE (type), list_p); |
7567 | 7550 |
7568 for (t = TYPE_NEXT_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t)) | 7551 for (t = TYPE_NEXT_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t)) |
7569 { | 7552 { |
7570 TYPE_MIN_VALUE (t) = TYPE_MIN_VALUE (type); | 7553 TYPE_MIN_VALUE (t) = TYPE_MIN_VALUE (type); |
7571 TYPE_MAX_VALUE (t) = TYPE_MAX_VALUE (type); | 7554 TYPE_MAX_VALUE (t) = TYPE_MAX_VALUE (type); |
7572 } | 7555 } |
7573 break; | 7556 break; |
7574 | 7557 |
7575 case ARRAY_TYPE: | 7558 case ARRAY_TYPE: |
7576 /* These types may not have declarations, so handle them here. */ | 7559 /* These types may not have declarations, so handle them here. */ |
7577 gimplify_type_sizes (TREE_TYPE (type), list_p); | 7560 gimplify_type_sizes (TREE_TYPE (type), list_p); |
7607 } | 7590 } |
7608 break; | 7591 break; |
7609 | 7592 |
7610 case POINTER_TYPE: | 7593 case POINTER_TYPE: |
7611 case REFERENCE_TYPE: | 7594 case REFERENCE_TYPE: |
7612 /* We used to recurse on the pointed-to type here, which turned out to | 7595 /* We used to recurse on the pointed-to type here, which turned out to |
7613 be incorrect because its definition might refer to variables not | 7596 be incorrect because its definition might refer to variables not |
7614 yet initialized at this point if a forward declaration is involved. | 7597 yet initialized at this point if a forward declaration is involved. |
7615 | 7598 |
7616 It was actually useful for anonymous pointed-to types to ensure | 7599 It was actually useful for anonymous pointed-to types to ensure |
7617 that the sizes evaluation dominates every possible later use of the | 7600 that the sizes evaluation dominates every possible later use of the |
7618 values. Restricting to such types here would be safe since there | 7601 values. Restricting to such types here would be safe since there |
7619 is no possible forward declaration around, but would introduce an | 7602 is no possible forward declaration around, but would introduce an |
7620 undesirable middle-end semantic to anonymity. We then defer to | 7603 undesirable middle-end semantic to anonymity. We then defer to |
7621 front-ends the responsibility of ensuring that the sizes are | 7604 front-ends the responsibility of ensuring that the sizes are |
7622 evaluated both early and late enough, e.g. by attaching artificial | 7605 evaluated both early and late enough, e.g. by attaching artificial |
7623 type declarations to the tree. */ | 7606 type declarations to the tree. */ |
7624 break; | 7607 break; |
7625 | 7608 |
7626 default: | 7609 default: |
7627 break; | 7610 break; |
7628 } | 7611 } |
7847 { | 7830 { |
7848 /* Preliminarily mark non-addressed complex variables as eligible | 7831 /* Preliminarily mark non-addressed complex variables as eligible |
7849 for promotion to gimple registers. We'll transform their uses | 7832 for promotion to gimple registers. We'll transform their uses |
7850 as we find them. */ | 7833 as we find them. */ |
7851 if ((TREE_CODE (TREE_TYPE (parm)) == COMPLEX_TYPE | 7834 if ((TREE_CODE (TREE_TYPE (parm)) == COMPLEX_TYPE |
7852 || TREE_CODE (TREE_TYPE (parm)) == VECTOR_TYPE) | 7835 || TREE_CODE (TREE_TYPE (parm)) == VECTOR_TYPE) |
7853 && !TREE_THIS_VOLATILE (parm) | 7836 && !TREE_THIS_VOLATILE (parm) |
7854 && !needs_to_live_in_memory (parm)) | 7837 && !needs_to_live_in_memory (parm)) |
7855 DECL_GIMPLE_REG_P (parm) = 1; | 7838 DECL_GIMPLE_REG_P (parm) = 1; |
7856 } | 7839 } |
7857 | 7840 |
7946 | 7929 |
7947 switch (gimple_code (stmt)) | 7930 switch (gimple_code (stmt)) |
7948 { | 7931 { |
7949 case GIMPLE_COND: | 7932 case GIMPLE_COND: |
7950 gimplify_expr (gimple_cond_lhs_ptr (stmt), &pre, NULL, | 7933 gimplify_expr (gimple_cond_lhs_ptr (stmt), &pre, NULL, |
7951 is_gimple_val, fb_rvalue); | 7934 is_gimple_val, fb_rvalue); |
7952 gimplify_expr (gimple_cond_rhs_ptr (stmt), &pre, NULL, | 7935 gimplify_expr (gimple_cond_rhs_ptr (stmt), &pre, NULL, |
7953 is_gimple_val, fb_rvalue); | 7936 is_gimple_val, fb_rvalue); |
7954 break; | 7937 break; |
7955 case GIMPLE_SWITCH: | 7938 case GIMPLE_SWITCH: |
7956 gimplify_expr (gimple_switch_index_ptr (stmt), &pre, NULL, | 7939 gimplify_expr (gimple_switch_index_ptr (stmt), &pre, NULL, |
7957 is_gimple_val, fb_rvalue); | 7940 is_gimple_val, fb_rvalue); |
7958 break; | 7941 break; |
7959 case GIMPLE_OMP_ATOMIC_LOAD: | 7942 case GIMPLE_OMP_ATOMIC_LOAD: |
7960 gimplify_expr (gimple_omp_atomic_load_rhs_ptr (stmt), &pre, NULL, | 7943 gimplify_expr (gimple_omp_atomic_load_rhs_ptr (stmt), &pre, NULL, |
7961 is_gimple_val, fb_rvalue); | 7944 is_gimple_val, fb_rvalue); |
7962 break; | 7945 break; |
7963 case GIMPLE_ASM: | 7946 case GIMPLE_ASM: |
7964 { | 7947 { |
7965 size_t i, noutputs = gimple_asm_noutputs (stmt); | 7948 size_t i, noutputs = gimple_asm_noutputs (stmt); |
7966 const char *constraint, **oconstraints; | 7949 const char *constraint, **oconstraints; |
7967 bool allows_mem, allows_reg, is_inout; | 7950 bool allows_mem, allows_reg, is_inout; |
7968 | 7951 |
7969 oconstraints | 7952 oconstraints |
7970 = (const char **) alloca ((noutputs) * sizeof (const char *)); | 7953 = (const char **) alloca ((noutputs) * sizeof (const char *)); |
7971 for (i = 0; i < noutputs; i++) | 7954 for (i = 0; i < noutputs; i++) |
7972 { | 7955 { |
7973 tree op = gimple_asm_output_op (stmt, i); | 7956 tree op = gimple_asm_output_op (stmt, i); |
7974 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op))); | 7957 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op))); |
7975 oconstraints[i] = constraint; | 7958 oconstraints[i] = constraint; |
7976 parse_output_constraint (&constraint, i, 0, 0, &allows_mem, | 7959 parse_output_constraint (&constraint, i, 0, 0, &allows_mem, |
7977 &allows_reg, &is_inout); | 7960 &allows_reg, &is_inout); |
7978 gimplify_expr (&TREE_VALUE (op), &pre, NULL, | 7961 gimplify_expr (&TREE_VALUE (op), &pre, NULL, |
7979 is_inout ? is_gimple_min_lval : is_gimple_lvalue, | 7962 is_inout ? is_gimple_min_lval : is_gimple_lvalue, |
7980 fb_lvalue | fb_mayfail); | 7963 fb_lvalue | fb_mayfail); |
7981 } | 7964 } |
7982 for (i = 0; i < gimple_asm_ninputs (stmt); i++) | 7965 for (i = 0; i < gimple_asm_ninputs (stmt); i++) |
7983 { | 7966 { |
7984 tree op = gimple_asm_input_op (stmt, i); | 7967 tree op = gimple_asm_input_op (stmt, i); |
7985 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op))); | 7968 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op))); |
7986 parse_input_constraint (&constraint, 0, 0, noutputs, 0, | 7969 parse_input_constraint (&constraint, 0, 0, noutputs, 0, |
7987 oconstraints, &allows_mem, &allows_reg); | 7970 oconstraints, &allows_mem, &allows_reg); |
7988 if (TREE_ADDRESSABLE (TREE_TYPE (TREE_VALUE (op))) && allows_mem) | 7971 if (TREE_ADDRESSABLE (TREE_TYPE (TREE_VALUE (op))) && allows_mem) |
7989 allows_reg = 0; | 7972 allows_reg = 0; |
7990 if (!allows_reg && allows_mem) | 7973 if (!allows_reg && allows_mem) |
7991 gimplify_expr (&TREE_VALUE (op), &pre, NULL, | 7974 gimplify_expr (&TREE_VALUE (op), &pre, NULL, |
7992 is_gimple_lvalue, fb_lvalue | fb_mayfail); | 7975 is_gimple_lvalue, fb_lvalue | fb_mayfail); |
7993 else | 7976 else |
7994 gimplify_expr (&TREE_VALUE (op), &pre, NULL, | 7977 gimplify_expr (&TREE_VALUE (op), &pre, NULL, |
7995 is_gimple_asm_val, fb_rvalue); | 7978 is_gimple_asm_val, fb_rvalue); |
7996 } | 7979 } |
7997 } | 7980 } |
7998 break; | 7981 break; |
7999 default: | 7982 default: |
8000 /* NOTE: We start gimplifying operands from last to first to | 7983 /* NOTE: We start gimplifying operands from last to first to |
8001 make sure that side-effects on the RHS of calls, assignments | 7984 make sure that side-effects on the RHS of calls, assignments |
8002 and ASMs are executed before the LHS. The ordering is not | 7985 and ASMs are executed before the LHS. The ordering is not |
8003 important for other statements. */ | 7986 important for other statements. */ |
8004 num_ops = gimple_num_ops (stmt); | 7987 num_ops = gimple_num_ops (stmt); |
8005 orig_lhs = gimple_get_lhs (stmt); | 7988 orig_lhs = gimple_get_lhs (stmt); |
8006 for (i = num_ops; i > 0; i--) | 7989 for (i = num_ops; i > 0; i--) |
8007 { | 7990 { |
8008 tree op = gimple_op (stmt, i - 1); | 7991 tree op = gimple_op (stmt, i - 1); |
8009 if (op == NULL_TREE) | 7992 if (op == NULL_TREE) |
8010 continue; | 7993 continue; |
8011 if (i == 1 && (is_gimple_call (stmt) || is_gimple_assign (stmt))) | 7994 if (i == 1 && (is_gimple_call (stmt) || is_gimple_assign (stmt))) |
8012 gimplify_expr (&op, &pre, NULL, is_gimple_lvalue, fb_lvalue); | 7995 gimplify_expr (&op, &pre, NULL, is_gimple_lvalue, fb_lvalue); |
8013 else if (i == 2 | 7996 else if (i == 2 |
8014 && is_gimple_assign (stmt) | 7997 && is_gimple_assign (stmt) |
8015 && num_ops == 2 | 7998 && num_ops == 2 |
8016 && get_gimple_rhs_class (gimple_expr_code (stmt)) | 7999 && get_gimple_rhs_class (gimple_expr_code (stmt)) |
8017 == GIMPLE_SINGLE_RHS) | 8000 == GIMPLE_SINGLE_RHS) |
8018 gimplify_expr (&op, &pre, NULL, | 8001 gimplify_expr (&op, &pre, NULL, |
8019 rhs_predicate_for (gimple_assign_lhs (stmt)), | 8002 rhs_predicate_for (gimple_assign_lhs (stmt)), |
8020 fb_rvalue); | 8003 fb_rvalue); |
8021 else if (i == 2 && is_gimple_call (stmt)) | 8004 else if (i == 2 && is_gimple_call (stmt)) |
8022 { | 8005 { |
8023 if (TREE_CODE (op) == FUNCTION_DECL) | 8006 if (TREE_CODE (op) == FUNCTION_DECL) |
8024 continue; | 8007 continue; |
8025 gimplify_expr (&op, &pre, NULL, is_gimple_call_addr, fb_rvalue); | 8008 gimplify_expr (&op, &pre, NULL, is_gimple_call_addr, fb_rvalue); |
8026 } | 8009 } |
8027 else | 8010 else |
8028 gimplify_expr (&op, &pre, NULL, is_gimple_val, fb_rvalue); | 8011 gimplify_expr (&op, &pre, NULL, is_gimple_val, fb_rvalue); |
8029 gimple_set_op (stmt, i - 1, op); | 8012 gimple_set_op (stmt, i - 1, op); |
8030 } | 8013 } |
8031 | 8014 |
8032 lhs = gimple_get_lhs (stmt); | 8015 lhs = gimple_get_lhs (stmt); |
8033 /* If the LHS changed it in a way that requires a simple RHS, | 8016 /* If the LHS changed it in a way that requires a simple RHS, |
8034 create temporary. */ | 8017 create temporary. */ |
8035 if (lhs && !is_gimple_reg (lhs)) | 8018 if (lhs && !is_gimple_reg (lhs)) |
8036 { | 8019 { |
8037 bool need_temp = false; | 8020 bool need_temp = false; |
8038 | |
8039 | 8021 |
8040 if (is_gimple_assign (stmt) | 8022 if (is_gimple_assign (stmt) |
8041 && num_ops == 2 | 8023 && num_ops == 2 |
8042 && get_gimple_rhs_class (gimple_expr_code (stmt)) | 8024 && get_gimple_rhs_class (gimple_expr_code (stmt)) |
8043 == GIMPLE_SINGLE_RHS) | 8025 == GIMPLE_SINGLE_RHS) |
8101 add_referenced_var (t); | 8083 add_referenced_var (t); |
8102 | 8084 |
8103 if (!gimple_seq_empty_p (pre)) | 8085 if (!gimple_seq_empty_p (pre)) |
8104 { | 8086 { |
8105 if (gimple_in_ssa_p (cfun)) | 8087 if (gimple_in_ssa_p (cfun)) |
8106 { | 8088 { |
8107 gimple_stmt_iterator i; | 8089 gimple_stmt_iterator i; |
8108 | 8090 |
8109 for (i = gsi_start (pre); !gsi_end_p (i); gsi_next (&i)) | 8091 for (i = gsi_start (pre); !gsi_end_p (i); gsi_next (&i)) |
8110 mark_symbols_for_renaming (gsi_stmt (i)); | 8092 mark_symbols_for_renaming (gsi_stmt (i)); |
8111 } | 8093 } |
8112 gsi_insert_seq_before (gsi_p, pre, GSI_SAME_STMT); | 8094 gsi_insert_seq_before (gsi_p, pre, GSI_SAME_STMT); |
8113 } | 8095 } |
8114 if (post_stmt) | 8096 if (post_stmt) |
8115 gsi_insert_after (gsi_p, post_stmt, GSI_NEW_STMT); | 8097 gsi_insert_after (gsi_p, post_stmt, GSI_NEW_STMT); |
8116 | 8098 |
8223 the way GSI moves after insertion (GSI_SAME_STMT or GSI_CONTINUE_LINKING | 8205 the way GSI moves after insertion (GSI_SAME_STMT or GSI_CONTINUE_LINKING |
8224 are the usual values). */ | 8206 are the usual values). */ |
8225 | 8207 |
8226 tree | 8208 tree |
8227 force_gimple_operand_gsi (gimple_stmt_iterator *gsi, tree expr, | 8209 force_gimple_operand_gsi (gimple_stmt_iterator *gsi, tree expr, |
8228 bool simple_p, tree var, bool before, | 8210 bool simple_p, tree var, bool before, |
8229 enum gsi_iterator_update m) | 8211 enum gsi_iterator_update m) |
8230 { | 8212 { |
8231 return force_gimple_operand_gsi_1 (gsi, expr, | 8213 return force_gimple_operand_gsi_1 (gsi, expr, |
8232 simple_p | 8214 simple_p |
8233 ? is_gimple_val : is_gimple_reg_rhs, | 8215 ? is_gimple_val : is_gimple_reg_rhs, |
8234 var, before, m); | 8216 var, before, m); |