comparison gcc/omp-low.c @ 67:f6334be47118

update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 22 Mar 2011 17:18:12 +0900
parents b7f97abdc517
children 04ced10e8804
comparison
equal deleted inserted replaced
65:65488c3d617d 67:f6334be47118
30 #include "rtl.h" 30 #include "rtl.h"
31 #include "gimple.h" 31 #include "gimple.h"
32 #include "tree-iterator.h" 32 #include "tree-iterator.h"
33 #include "tree-inline.h" 33 #include "tree-inline.h"
34 #include "langhooks.h" 34 #include "langhooks.h"
35 #include "diagnostic.h" 35 #include "diagnostic-core.h"
36 #include "tree-flow.h" 36 #include "tree-flow.h"
37 #include "timevar.h" 37 #include "timevar.h"
38 #include "flags.h" 38 #include "flags.h"
39 #include "function.h" 39 #include "function.h"
40 #include "expr.h" 40 #include "expr.h"
41 #include "toplev.h"
42 #include "tree-pass.h" 41 #include "tree-pass.h"
43 #include "ggc.h" 42 #include "ggc.h"
44 #include "except.h" 43 #include "except.h"
45 #include "splay-tree.h" 44 #include "splay-tree.h"
46 #include "optabs.h" 45 #include "optabs.h"
553 552
554 /* Collect additional arguments needed to emit a combined 553 /* Collect additional arguments needed to emit a combined
555 parallel+workshare call. WS_STMT is the workshare directive being 554 parallel+workshare call. WS_STMT is the workshare directive being
556 expanded. */ 555 expanded. */
557 556
558 static tree 557 static VEC(tree,gc) *
559 get_ws_args_for (gimple ws_stmt) 558 get_ws_args_for (gimple ws_stmt)
560 { 559 {
561 tree t; 560 tree t;
562 location_t loc = gimple_location (ws_stmt); 561 location_t loc = gimple_location (ws_stmt);
562 VEC(tree,gc) *ws_args;
563 563
564 if (gimple_code (ws_stmt) == GIMPLE_OMP_FOR) 564 if (gimple_code (ws_stmt) == GIMPLE_OMP_FOR)
565 { 565 {
566 struct omp_for_data fd; 566 struct omp_for_data fd;
567 tree ws_args;
568 567
569 extract_omp_for_data (ws_stmt, &fd, NULL); 568 extract_omp_for_data (ws_stmt, &fd, NULL);
570 569
571 ws_args = NULL_TREE; 570 ws_args = VEC_alloc (tree, gc, 3 + (fd.chunk_size != 0));
571
572 t = fold_convert_loc (loc, long_integer_type_node, fd.loop.n1);
573 VEC_quick_push (tree, ws_args, t);
574
575 t = fold_convert_loc (loc, long_integer_type_node, fd.loop.n2);
576 VEC_quick_push (tree, ws_args, t);
577
578 t = fold_convert_loc (loc, long_integer_type_node, fd.loop.step);
579 VEC_quick_push (tree, ws_args, t);
580
572 if (fd.chunk_size) 581 if (fd.chunk_size)
573 { 582 {
574 t = fold_convert_loc (loc, long_integer_type_node, fd.chunk_size); 583 t = fold_convert_loc (loc, long_integer_type_node, fd.chunk_size);
575 ws_args = tree_cons (NULL, t, ws_args); 584 VEC_quick_push (tree, ws_args, t);
576 } 585 }
577
578 t = fold_convert_loc (loc, long_integer_type_node, fd.loop.step);
579 ws_args = tree_cons (NULL, t, ws_args);
580
581 t = fold_convert_loc (loc, long_integer_type_node, fd.loop.n2);
582 ws_args = tree_cons (NULL, t, ws_args);
583
584 t = fold_convert_loc (loc, long_integer_type_node, fd.loop.n1);
585 ws_args = tree_cons (NULL, t, ws_args);
586 586
587 return ws_args; 587 return ws_args;
588 } 588 }
589 else if (gimple_code (ws_stmt) == GIMPLE_OMP_SECTIONS) 589 else if (gimple_code (ws_stmt) == GIMPLE_OMP_SECTIONS)
590 { 590 {
591 /* Number of sections is equal to the number of edges from the 591 /* Number of sections is equal to the number of edges from the
592 GIMPLE_OMP_SECTIONS_SWITCH statement, except for the one to 592 GIMPLE_OMP_SECTIONS_SWITCH statement, except for the one to
593 the exit of the sections region. */ 593 the exit of the sections region. */
594 basic_block bb = single_succ (gimple_bb (ws_stmt)); 594 basic_block bb = single_succ (gimple_bb (ws_stmt));
595 t = build_int_cst (unsigned_type_node, EDGE_COUNT (bb->succs) - 1); 595 t = build_int_cst (unsigned_type_node, EDGE_COUNT (bb->succs) - 1);
596 t = tree_cons (NULL, t, NULL); 596 ws_args = VEC_alloc (tree, gc, 1);
597 return t; 597 VEC_quick_push (tree, ws_args, t);
598 return ws_args;
598 } 599 }
599 600
600 gcc_unreachable (); 601 gcc_unreachable ();
601 } 602 }
602 603
837 omp_copy_decl_2 (tree var, tree name, tree type, omp_context *ctx) 838 omp_copy_decl_2 (tree var, tree name, tree type, omp_context *ctx)
838 { 839 {
839 tree copy = copy_var_decl (var, name, type); 840 tree copy = copy_var_decl (var, name, type);
840 841
841 DECL_CONTEXT (copy) = current_function_decl; 842 DECL_CONTEXT (copy) = current_function_decl;
842 TREE_CHAIN (copy) = ctx->block_vars; 843 DECL_CHAIN (copy) = ctx->block_vars;
843 ctx->block_vars = copy; 844 ctx->block_vars = copy;
844 845
845 return copy; 846 return copy;
846 } 847 }
847 848
862 remap the field into the new record type. */ 863 remap the field into the new record type. */
863 x = maybe_lookup_field (field, ctx); 864 x = maybe_lookup_field (field, ctx);
864 if (x != NULL) 865 if (x != NULL)
865 field = x; 866 field = x;
866 867
867 x = build_fold_indirect_ref (ctx->receiver_decl); 868 x = build_simple_mem_ref (ctx->receiver_decl);
868 x = build3 (COMPONENT_REF, TREE_TYPE (field), x, field, NULL); 869 x = build3 (COMPONENT_REF, TREE_TYPE (field), x, field, NULL);
869 if (by_ref) 870 if (by_ref)
870 x = build_fold_indirect_ref (x); 871 x = build_simple_mem_ref (x);
871 872
872 return x; 873 return x;
873 } 874 }
874 875
875 /* Build tree nodes to access VAR in the scope outer to CTX. In the case 876 /* Build tree nodes to access VAR in the scope outer to CTX. In the case
885 x = var; 886 x = var;
886 else if (is_variable_sized (var)) 887 else if (is_variable_sized (var))
887 { 888 {
888 x = TREE_OPERAND (DECL_VALUE_EXPR (var), 0); 889 x = TREE_OPERAND (DECL_VALUE_EXPR (var), 0);
889 x = build_outer_var_ref (x, ctx); 890 x = build_outer_var_ref (x, ctx);
890 x = build_fold_indirect_ref (x); 891 x = build_simple_mem_ref (x);
891 } 892 }
892 else if (is_taskreg_ctx (ctx)) 893 else if (is_taskreg_ctx (ctx))
893 { 894 {
894 bool by_ref = use_pointer_for_field (var, NULL); 895 bool by_ref = use_pointer_for_field (var, NULL);
895 x = build_receiver_ref (var, by_ref, ctx); 896 x = build_receiver_ref (var, by_ref, ctx);
902 x = var; 903 x = var;
903 else 904 else
904 gcc_unreachable (); 905 gcc_unreachable ();
905 906
906 if (is_reference (var)) 907 if (is_reference (var))
907 x = build_fold_indirect_ref (x); 908 x = build_simple_mem_ref (x);
908 909
909 return x; 910 return x;
910 } 911 }
911 912
912 /* Build tree nodes to access the field for VAR on the sender side. */ 913 /* Build tree nodes to access the field for VAR on the sender side. */
1110 1111
1111 if (region->next) 1112 if (region->next)
1112 dump_omp_region (file, region->next, indent); 1113 dump_omp_region (file, region->next, indent);
1113 } 1114 }
1114 1115
1115 void 1116 DEBUG_FUNCTION void
1116 debug_omp_region (struct omp_region *region) 1117 debug_omp_region (struct omp_region *region)
1117 { 1118 {
1118 dump_omp_region (stderr, region, 0); 1119 dump_omp_region (stderr, region, 0);
1119 } 1120 }
1120 1121
1121 void 1122 DEBUG_FUNCTION void
1122 debug_all_omp_regions (void) 1123 debug_all_omp_regions (void)
1123 { 1124 {
1124 dump_omp_region (stderr, root_omp_region, 0); 1125 dump_omp_region (stderr, root_omp_region, 0);
1125 } 1126 }
1126 1127
1282 /* We hijacked DECL_ABSTRACT_ORIGIN earlier. We need to clear it before 1283 /* We hijacked DECL_ABSTRACT_ORIGIN earlier. We need to clear it before
1283 it produces corrupt debug information. */ 1284 it produces corrupt debug information. */
1284 if (ctx->record_type) 1285 if (ctx->record_type)
1285 { 1286 {
1286 tree t; 1287 tree t;
1287 for (t = TYPE_FIELDS (ctx->record_type); t ; t = TREE_CHAIN (t)) 1288 for (t = TYPE_FIELDS (ctx->record_type); t ; t = DECL_CHAIN (t))
1288 DECL_ABSTRACT_ORIGIN (t) = NULL; 1289 DECL_ABSTRACT_ORIGIN (t) = NULL;
1289 } 1290 }
1290 if (ctx->srecord_type) 1291 if (ctx->srecord_type)
1291 { 1292 {
1292 tree t; 1293 tree t;
1293 for (t = TYPE_FIELDS (ctx->srecord_type); t ; t = TREE_CHAIN (t)) 1294 for (t = TYPE_FIELDS (ctx->srecord_type); t ; t = DECL_CHAIN (t))
1294 DECL_ABSTRACT_ORIGIN (t) = NULL; 1295 DECL_ABSTRACT_ORIGIN (t) = NULL;
1295 } 1296 }
1296 1297
1297 if (is_task_ctx (ctx)) 1298 if (is_task_ctx (ctx))
1298 finalize_task_copyfn (ctx->stmt); 1299 finalize_task_copyfn (ctx->stmt);
1310 1311
1311 /* ??? It isn't sufficient to just call remap_type here, because 1312 /* ??? It isn't sufficient to just call remap_type here, because
1312 variably_modified_type_p doesn't work the way we expect for 1313 variably_modified_type_p doesn't work the way we expect for
1313 record types. Testing each field for whether it needs remapping 1314 record types. Testing each field for whether it needs remapping
1314 and creating a new record by hand works, however. */ 1315 and creating a new record by hand works, however. */
1315 for (f = TYPE_FIELDS (type); f ; f = TREE_CHAIN (f)) 1316 for (f = TYPE_FIELDS (type); f ; f = DECL_CHAIN (f))
1316 if (variably_modified_type_p (TREE_TYPE (f), ctx->cb.src_fn)) 1317 if (variably_modified_type_p (TREE_TYPE (f), ctx->cb.src_fn))
1317 break; 1318 break;
1318 if (f) 1319 if (f)
1319 { 1320 {
1320 tree name, new_fields = NULL; 1321 tree name, new_fields = NULL;
1323 name = DECL_NAME (TYPE_NAME (ctx->record_type)); 1324 name = DECL_NAME (TYPE_NAME (ctx->record_type));
1324 name = build_decl (DECL_SOURCE_LOCATION (ctx->receiver_decl), 1325 name = build_decl (DECL_SOURCE_LOCATION (ctx->receiver_decl),
1325 TYPE_DECL, name, type); 1326 TYPE_DECL, name, type);
1326 TYPE_NAME (type) = name; 1327 TYPE_NAME (type) = name;
1327 1328
1328 for (f = TYPE_FIELDS (ctx->record_type); f ; f = TREE_CHAIN (f)) 1329 for (f = TYPE_FIELDS (ctx->record_type); f ; f = DECL_CHAIN (f))
1329 { 1330 {
1330 tree new_f = copy_node (f); 1331 tree new_f = copy_node (f);
1331 DECL_CONTEXT (new_f) = type; 1332 DECL_CONTEXT (new_f) = type;
1332 TREE_TYPE (new_f) = remap_type (TREE_TYPE (f), &ctx->cb); 1333 TREE_TYPE (new_f) = remap_type (TREE_TYPE (f), &ctx->cb);
1333 TREE_CHAIN (new_f) = new_fields; 1334 DECL_CHAIN (new_f) = new_fields;
1334 walk_tree (&DECL_SIZE (new_f), copy_tree_body_r, &ctx->cb, NULL); 1335 walk_tree (&DECL_SIZE (new_f), copy_tree_body_r, &ctx->cb, NULL);
1335 walk_tree (&DECL_SIZE_UNIT (new_f), copy_tree_body_r, 1336 walk_tree (&DECL_SIZE_UNIT (new_f), copy_tree_body_r,
1336 &ctx->cb, NULL); 1337 &ctx->cb, NULL);
1337 walk_tree (&DECL_FIELD_OFFSET (new_f), copy_tree_body_r, 1338 walk_tree (&DECL_FIELD_OFFSET (new_f), copy_tree_body_r,
1338 &ctx->cb, NULL); 1339 &ctx->cb, NULL);
1529 static GTY(()) unsigned int tmp_ompfn_id_num; 1530 static GTY(()) unsigned int tmp_ompfn_id_num;
1530 1531
1531 static tree 1532 static tree
1532 create_omp_child_function_name (bool task_copy) 1533 create_omp_child_function_name (bool task_copy)
1533 { 1534 {
1534 tree name = DECL_ASSEMBLER_NAME (current_function_decl); 1535 return (clone_function_name (current_function_decl,
1535 size_t len = IDENTIFIER_LENGTH (name); 1536 task_copy ? "_omp_cpyfn" : "_omp_fn"));
1536 char *tmp_name, *prefix;
1537 const char *suffix;
1538
1539 suffix = task_copy ? "_omp_cpyfn" : "_omp_fn";
1540 prefix = XALLOCAVEC (char, len + strlen (suffix) + 1);
1541 memcpy (prefix, IDENTIFIER_POINTER (name), len);
1542 strcpy (prefix + len, suffix);
1543 #ifndef NO_DOT_IN_LABEL
1544 prefix[len] = '.';
1545 #elif !defined NO_DOLLAR_IN_LABEL
1546 prefix[len] = '$';
1547 #endif
1548 ASM_FORMAT_PRIVATE_NAME (tmp_name, prefix, tmp_ompfn_id_num++);
1549 return get_identifier (tmp_name);
1550 } 1537 }
1551 1538
1552 /* Build a decl for the omp child function. It'll not contain a body 1539 /* Build a decl for the omp child function. It'll not contain a body
1553 yet, just the bare decl. */ 1540 yet, just the bare decl. */
1554 1541
1573 gimple_omp_task_set_copy_fn (ctx->stmt, decl); 1560 gimple_omp_task_set_copy_fn (ctx->stmt, decl);
1574 1561
1575 TREE_STATIC (decl) = 1; 1562 TREE_STATIC (decl) = 1;
1576 TREE_USED (decl) = 1; 1563 TREE_USED (decl) = 1;
1577 DECL_ARTIFICIAL (decl) = 1; 1564 DECL_ARTIFICIAL (decl) = 1;
1565 DECL_NAMELESS (decl) = 1;
1578 DECL_IGNORED_P (decl) = 0; 1566 DECL_IGNORED_P (decl) = 0;
1579 TREE_PUBLIC (decl) = 0; 1567 TREE_PUBLIC (decl) = 0;
1580 DECL_UNINLINABLE (decl) = 1; 1568 DECL_UNINLINABLE (decl) = 1;
1581 DECL_EXTERNAL (decl) = 0; 1569 DECL_EXTERNAL (decl) = 0;
1582 DECL_CONTEXT (decl) = NULL_TREE; 1570 DECL_CONTEXT (decl) = NULL_TREE;
1590 DECL_RESULT (decl) = t; 1578 DECL_RESULT (decl) = t;
1591 1579
1592 t = build_decl (DECL_SOURCE_LOCATION (decl), 1580 t = build_decl (DECL_SOURCE_LOCATION (decl),
1593 PARM_DECL, get_identifier (".omp_data_i"), ptr_type_node); 1581 PARM_DECL, get_identifier (".omp_data_i"), ptr_type_node);
1594 DECL_ARTIFICIAL (t) = 1; 1582 DECL_ARTIFICIAL (t) = 1;
1583 DECL_NAMELESS (t) = 1;
1595 DECL_ARG_TYPE (t) = ptr_type_node; 1584 DECL_ARG_TYPE (t) = ptr_type_node;
1596 DECL_CONTEXT (t) = current_function_decl; 1585 DECL_CONTEXT (t) = current_function_decl;
1597 TREE_USED (t) = 1; 1586 TREE_USED (t) = 1;
1598 DECL_ARGUMENTS (decl) = t; 1587 DECL_ARGUMENTS (decl) = t;
1599 if (!task_copy) 1588 if (!task_copy)
1602 { 1591 {
1603 t = build_decl (DECL_SOURCE_LOCATION (decl), 1592 t = build_decl (DECL_SOURCE_LOCATION (decl),
1604 PARM_DECL, get_identifier (".omp_data_o"), 1593 PARM_DECL, get_identifier (".omp_data_o"),
1605 ptr_type_node); 1594 ptr_type_node);
1606 DECL_ARTIFICIAL (t) = 1; 1595 DECL_ARTIFICIAL (t) = 1;
1596 DECL_NAMELESS (t) = 1;
1607 DECL_ARG_TYPE (t) = ptr_type_node; 1597 DECL_ARG_TYPE (t) = ptr_type_node;
1608 DECL_CONTEXT (t) = current_function_decl; 1598 DECL_CONTEXT (t) = current_function_decl;
1609 TREE_USED (t) = 1; 1599 TREE_USED (t) = 1;
1610 TREE_ADDRESSABLE (t) = 1; 1600 TREE_ADDRESSABLE (t) = 1;
1611 TREE_CHAIN (t) = DECL_ARGUMENTS (decl); 1601 DECL_CHAIN (t) = DECL_ARGUMENTS (decl);
1612 DECL_ARGUMENTS (decl) = t; 1602 DECL_ARGUMENTS (decl) = t;
1613 } 1603 }
1614 1604
1615 /* Allocate memory for the function structure. The call to 1605 /* Allocate memory for the function structure. The call to
1616 allocate_struct_function clobbers CFUN, so we need to restore 1606 allocate_struct_function clobbers CFUN, so we need to restore
1648 ctx->default_kind = OMP_CLAUSE_DEFAULT_SHARED; 1638 ctx->default_kind = OMP_CLAUSE_DEFAULT_SHARED;
1649 ctx->record_type = lang_hooks.types.make_type (RECORD_TYPE); 1639 ctx->record_type = lang_hooks.types.make_type (RECORD_TYPE);
1650 name = create_tmp_var_name (".omp_data_s"); 1640 name = create_tmp_var_name (".omp_data_s");
1651 name = build_decl (gimple_location (stmt), 1641 name = build_decl (gimple_location (stmt),
1652 TYPE_DECL, name, ctx->record_type); 1642 TYPE_DECL, name, ctx->record_type);
1643 DECL_ARTIFICIAL (name) = 1;
1644 DECL_NAMELESS (name) = 1;
1653 TYPE_NAME (ctx->record_type) = name; 1645 TYPE_NAME (ctx->record_type) = name;
1654 create_omp_child_function (ctx, false); 1646 create_omp_child_function (ctx, false);
1655 gimple_omp_parallel_set_child_fn (stmt, ctx->cb.dst_fn); 1647 gimple_omp_parallel_set_child_fn (stmt, ctx->cb.dst_fn);
1656 1648
1657 scan_sharing_clauses (gimple_omp_parallel_clauses (stmt), ctx); 1649 scan_sharing_clauses (gimple_omp_parallel_clauses (stmt), ctx);
1691 ctx->default_kind = OMP_CLAUSE_DEFAULT_SHARED; 1683 ctx->default_kind = OMP_CLAUSE_DEFAULT_SHARED;
1692 ctx->record_type = lang_hooks.types.make_type (RECORD_TYPE); 1684 ctx->record_type = lang_hooks.types.make_type (RECORD_TYPE);
1693 name = create_tmp_var_name (".omp_data_s"); 1685 name = create_tmp_var_name (".omp_data_s");
1694 name = build_decl (gimple_location (stmt), 1686 name = build_decl (gimple_location (stmt),
1695 TYPE_DECL, name, ctx->record_type); 1687 TYPE_DECL, name, ctx->record_type);
1688 DECL_ARTIFICIAL (name) = 1;
1689 DECL_NAMELESS (name) = 1;
1696 TYPE_NAME (ctx->record_type) = name; 1690 TYPE_NAME (ctx->record_type) = name;
1697 create_omp_child_function (ctx, false); 1691 create_omp_child_function (ctx, false);
1698 gimple_omp_task_set_child_fn (stmt, ctx->cb.dst_fn); 1692 gimple_omp_task_set_child_fn (stmt, ctx->cb.dst_fn);
1699 1693
1700 scan_sharing_clauses (gimple_omp_task_clauses (stmt), ctx); 1694 scan_sharing_clauses (gimple_omp_task_clauses (stmt), ctx);
1702 if (ctx->srecord_type) 1696 if (ctx->srecord_type)
1703 { 1697 {
1704 name = create_tmp_var_name (".omp_data_a"); 1698 name = create_tmp_var_name (".omp_data_a");
1705 name = build_decl (gimple_location (stmt), 1699 name = build_decl (gimple_location (stmt),
1706 TYPE_DECL, name, ctx->srecord_type); 1700 TYPE_DECL, name, ctx->srecord_type);
1701 DECL_ARTIFICIAL (name) = 1;
1702 DECL_NAMELESS (name) = 1;
1707 TYPE_NAME (ctx->srecord_type) = name; 1703 TYPE_NAME (ctx->srecord_type) = name;
1708 create_omp_child_function (ctx, true); 1704 create_omp_child_function (ctx, true);
1709 } 1705 }
1710 1706
1711 scan_omp (gimple_omp_body (stmt), ctx); 1707 scan_omp (gimple_omp_body (stmt), ctx);
1731 *p = TREE_CHAIN (*p); 1727 *p = TREE_CHAIN (*p);
1732 TREE_CHAIN (*q) = NULL_TREE; 1728 TREE_CHAIN (*q) = NULL_TREE;
1733 q = &TREE_CHAIN (*q); 1729 q = &TREE_CHAIN (*q);
1734 } 1730 }
1735 else 1731 else
1736 p = &TREE_CHAIN (*p); 1732 p = &DECL_CHAIN (*p);
1737 *p = vla_fields; 1733 *p = vla_fields;
1738 layout_type (ctx->record_type); 1734 layout_type (ctx->record_type);
1739 fixup_child_record_type (ctx); 1735 fixup_child_record_type (ctx);
1740 if (ctx->srecord_type) 1736 if (ctx->srecord_type)
1741 layout_type (ctx->srecord_type); 1737 layout_type (ctx->srecord_type);
1928 *tp = remap_type (t, &ctx->cb); 1924 *tp = remap_type (t, &ctx->cb);
1929 else if (!DECL_P (t)) 1925 else if (!DECL_P (t))
1930 { 1926 {
1931 *walk_subtrees = 1; 1927 *walk_subtrees = 1;
1932 if (ctx) 1928 if (ctx)
1933 TREE_TYPE (t) = remap_type (TREE_TYPE (t), &ctx->cb); 1929 {
1930 tree tem = remap_type (TREE_TYPE (t), &ctx->cb);
1931 if (tem != TREE_TYPE (t))
1932 {
1933 if (TREE_CODE (t) == INTEGER_CST)
1934 *tp = build_int_cst_wide (tem,
1935 TREE_INT_CST_LOW (t),
1936 TREE_INT_CST_HIGH (t));
1937 else
1938 TREE_TYPE (t) = tem;
1939 }
1940 }
1934 } 1941 }
1935 break; 1942 break;
1936 } 1943 }
1937 1944
1938 return NULL_TREE; 1945 return NULL_TREE;
2008 { 2015 {
2009 tree var; 2016 tree var;
2010 2017
2011 *handled_ops_p = false; 2018 *handled_ops_p = false;
2012 if (ctx) 2019 if (ctx)
2013 for (var = gimple_bind_vars (stmt); var ; var = TREE_CHAIN (var)) 2020 for (var = gimple_bind_vars (stmt); var ; var = DECL_CHAIN (var))
2014 insert_decl_map (&ctx->cb, var, var); 2021 insert_decl_map (&ctx->cb, var, var);
2015 } 2022 }
2016 break; 2023 break;
2017 default: 2024 default:
2018 *handled_ops_p = false; 2025 *handled_ops_p = false;
2157 case BIT_XOR_EXPR: 2164 case BIT_XOR_EXPR:
2158 case TRUTH_OR_EXPR: 2165 case TRUTH_OR_EXPR:
2159 case TRUTH_ORIF_EXPR: 2166 case TRUTH_ORIF_EXPR:
2160 case TRUTH_XOR_EXPR: 2167 case TRUTH_XOR_EXPR:
2161 case NE_EXPR: 2168 case NE_EXPR:
2162 return fold_convert_loc (loc, type, integer_zero_node); 2169 return build_zero_cst (type);
2163 2170
2164 case MULT_EXPR: 2171 case MULT_EXPR:
2165 case TRUTH_AND_EXPR: 2172 case TRUTH_AND_EXPR:
2166 case TRUTH_ANDIF_EXPR: 2173 case TRUTH_ANDIF_EXPR:
2167 case EQ_EXPR: 2174 case EQ_EXPR:
2349 } 2356 }
2350 2357
2351 x = fold_convert_loc (clause_loc, TREE_TYPE (new_var), x); 2358 x = fold_convert_loc (clause_loc, TREE_TYPE (new_var), x);
2352 gimplify_assign (new_var, x, ilist); 2359 gimplify_assign (new_var, x, ilist);
2353 2360
2354 new_var = build_fold_indirect_ref_loc (clause_loc, new_var); 2361 new_var = build_simple_mem_ref_loc (clause_loc, new_var);
2355 } 2362 }
2356 else if (c_kind == OMP_CLAUSE_REDUCTION 2363 else if (c_kind == OMP_CLAUSE_REDUCTION
2357 && OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)) 2364 && OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
2358 { 2365 {
2359 if (pass == 0) 2366 if (pass == 0)
2567 } 2574 }
2568 OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c) = NULL; 2575 OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c) = NULL;
2569 2576
2570 x = build_outer_var_ref (var, ctx); 2577 x = build_outer_var_ref (var, ctx);
2571 if (is_reference (var)) 2578 if (is_reference (var))
2572 new_var = build_fold_indirect_ref_loc (clause_loc, new_var); 2579 new_var = build_simple_mem_ref_loc (clause_loc, new_var);
2573 x = lang_hooks.decls.omp_clause_assign_op (c, x, new_var); 2580 x = lang_hooks.decls.omp_clause_assign_op (c, x, new_var);
2574 gimplify_and_add (x, stmt_list); 2581 gimplify_and_add (x, stmt_list);
2575 } 2582 }
2576 c = OMP_CLAUSE_CHAIN (c); 2583 c = OMP_CLAUSE_CHAIN (c);
2577 if (c == NULL && !par_clauses) 2584 if (c == NULL && !par_clauses)
2634 continue; 2641 continue;
2635 2642
2636 var = OMP_CLAUSE_DECL (c); 2643 var = OMP_CLAUSE_DECL (c);
2637 new_var = lookup_decl (var, ctx); 2644 new_var = lookup_decl (var, ctx);
2638 if (is_reference (var)) 2645 if (is_reference (var))
2639 new_var = build_fold_indirect_ref_loc (clause_loc, new_var); 2646 new_var = build_simple_mem_ref_loc (clause_loc, new_var);
2640 ref = build_outer_var_ref (var, ctx); 2647 ref = build_outer_var_ref (var, ctx);
2641 code = OMP_CLAUSE_REDUCTION_CODE (c); 2648 code = OMP_CLAUSE_REDUCTION_CODE (c);
2642 2649
2643 /* reduction(-:var) sums up the partial results, so it acts 2650 /* reduction(-:var) sums up the partial results, so it acts
2644 identically to reduction(+:var). */ 2651 identically to reduction(+:var). */
2726 ref = build_fold_indirect_ref_loc (clause_loc, ref); 2733 ref = build_fold_indirect_ref_loc (clause_loc, ref);
2727 } 2734 }
2728 if (is_reference (var)) 2735 if (is_reference (var))
2729 { 2736 {
2730 ref = fold_convert_loc (clause_loc, TREE_TYPE (new_var), ref); 2737 ref = fold_convert_loc (clause_loc, TREE_TYPE (new_var), ref);
2731 ref = build_fold_indirect_ref_loc (clause_loc, ref); 2738 ref = build_simple_mem_ref_loc (clause_loc, ref);
2732 new_var = build_fold_indirect_ref_loc (clause_loc, new_var); 2739 new_var = build_simple_mem_ref_loc (clause_loc, new_var);
2733 } 2740 }
2734 x = lang_hooks.decls.omp_clause_assign_op (c, new_var, ref); 2741 x = lang_hooks.decls.omp_clause_assign_op (c, new_var, ref);
2735 gimplify_and_add (x, rlist); 2742 gimplify_and_add (x, rlist);
2736 } 2743 }
2737 } 2744 }
2837 2844
2838 if (ctx->record_type == NULL) 2845 if (ctx->record_type == NULL)
2839 return; 2846 return;
2840 2847
2841 record_type = ctx->srecord_type ? ctx->srecord_type : ctx->record_type; 2848 record_type = ctx->srecord_type ? ctx->srecord_type : ctx->record_type;
2842 for (f = TYPE_FIELDS (record_type); f ; f = TREE_CHAIN (f)) 2849 for (f = TYPE_FIELDS (record_type); f ; f = DECL_CHAIN (f))
2843 { 2850 {
2844 ovar = DECL_ABSTRACT_ORIGIN (f); 2851 ovar = DECL_ABSTRACT_ORIGIN (f);
2845 nvar = maybe_lookup_decl (ovar, ctx); 2852 nvar = maybe_lookup_decl (ovar, ctx);
2846 if (!nvar || !DECL_HAS_VALUE_EXPR_P (nvar)) 2853 if (!nvar || !DECL_HAS_VALUE_EXPR_P (nvar))
2847 continue; 2854 continue;
2900 construct, it contains the list of additional arguments needed by 2907 construct, it contains the list of additional arguments needed by
2901 the workshare construct. */ 2908 the workshare construct. */
2902 2909
2903 static void 2910 static void
2904 expand_parallel_call (struct omp_region *region, basic_block bb, 2911 expand_parallel_call (struct omp_region *region, basic_block bb,
2905 gimple entry_stmt, tree ws_args) 2912 gimple entry_stmt, VEC(tree,gc) *ws_args)
2906 { 2913 {
2907 tree t, t1, t2, val, cond, c, clauses; 2914 tree t, t1, t2, val, cond, c, clauses;
2908 gimple_stmt_iterator gsi; 2915 gimple_stmt_iterator gsi;
2909 gimple stmt; 2916 gimple stmt;
2910 int start_ix; 2917 int start_ix;
2911 location_t clause_loc; 2918 location_t clause_loc;
2919 VEC(tree,gc) *args;
2912 2920
2913 clauses = gimple_omp_parallel_clauses (entry_stmt); 2921 clauses = gimple_omp_parallel_clauses (entry_stmt);
2914 2922
2915 /* Determine what flavor of GOMP_parallel_start we will be 2923 /* Determine what flavor of GOMP_parallel_start we will be
2916 emitting. */ 2924 emitting. */
3037 t1 = null_pointer_node; 3045 t1 = null_pointer_node;
3038 else 3046 else
3039 t1 = build_fold_addr_expr (t); 3047 t1 = build_fold_addr_expr (t);
3040 t2 = build_fold_addr_expr (gimple_omp_parallel_child_fn (entry_stmt)); 3048 t2 = build_fold_addr_expr (gimple_omp_parallel_child_fn (entry_stmt));
3041 3049
3042 if (ws_args) 3050 args = VEC_alloc (tree, gc, 3 + VEC_length (tree, ws_args));
3043 { 3051 VEC_quick_push (tree, args, t2);
3044 tree args = tree_cons (NULL, t2, 3052 VEC_quick_push (tree, args, t1);
3045 tree_cons (NULL, t1, 3053 VEC_quick_push (tree, args, val);
3046 tree_cons (NULL, val, ws_args))); 3054 VEC_splice (tree, args, ws_args);
3047 t = build_function_call_expr (UNKNOWN_LOCATION, 3055
3048 built_in_decls[start_ix], args); 3056 t = build_call_expr_loc_vec (UNKNOWN_LOCATION,
3049 } 3057 built_in_decls[start_ix], args);
3050 else
3051 t = build_call_expr (built_in_decls[start_ix], 3, t2, t1, val);
3052 3058
3053 force_gimple_operand_gsi (&gsi, t, true, NULL_TREE, 3059 force_gimple_operand_gsi (&gsi, t, true, NULL_TREE,
3054 false, GSI_CONTINUE_LINKING); 3060 false, GSI_CONTINUE_LINKING);
3055 3061
3056 t = gimple_omp_parallel_data_arg (entry_stmt); 3062 t = gimple_omp_parallel_data_arg (entry_stmt);
3124 tree decl; 3130 tree decl;
3125 3131
3126 if (!flag_exceptions) 3132 if (!flag_exceptions)
3127 return body; 3133 return body;
3128 3134
3129 if (lang_protect_cleanup_actions) 3135 if (lang_hooks.eh_protect_cleanup_actions != NULL)
3130 decl = lang_protect_cleanup_actions (); 3136 decl = lang_hooks.eh_protect_cleanup_actions ();
3131 else 3137 else
3132 decl = built_in_decls[BUILT_IN_TRAP]; 3138 decl = built_in_decls[BUILT_IN_TRAP];
3133 3139
3134 g = gimple_build_eh_must_not_throw (decl); 3140 g = gimple_build_eh_must_not_throw (decl);
3135 g = gimple_build_try (body, gimple_seq_alloc_with_stmt (g), 3141 g = gimple_build_try (body, gimple_seq_alloc_with_stmt (g),
3139 } 3145 }
3140 3146
3141 /* Chain all the DECLs in LIST by their TREE_CHAIN fields. */ 3147 /* Chain all the DECLs in LIST by their TREE_CHAIN fields. */
3142 3148
3143 static tree 3149 static tree
3144 list2chain (tree list) 3150 vec2chain (VEC(tree,gc) *v)
3145 { 3151 {
3146 tree t; 3152 tree chain = NULL_TREE, t;
3147 3153 unsigned ix;
3148 for (t = list; t; t = TREE_CHAIN (t)) 3154
3149 { 3155 FOR_EACH_VEC_ELT_REVERSE (tree, v, ix, t)
3150 tree var = TREE_VALUE (t); 3156 {
3151 if (TREE_CHAIN (t)) 3157 DECL_CHAIN (t) = chain;
3152 TREE_CHAIN (var) = TREE_VALUE (TREE_CHAIN (t)); 3158 chain = t;
3153 else 3159 }
3154 TREE_CHAIN (var) = NULL_TREE; 3160
3155 } 3161 return chain;
3156
3157 return list ? TREE_VALUE (list) : NULL_TREE;
3158 } 3162 }
3159 3163
3160 3164
3161 /* Remove barriers in REGION->EXIT's block. Note that this is only 3165 /* Remove barriers in REGION->EXIT's block. Note that this is only
3162 valid for GIMPLE_OMP_PARALLEL regions. Since the end of a parallel region 3166 valid for GIMPLE_OMP_PARALLEL regions. Since the end of a parallel region
3211 of such a variable. */ 3215 of such a variable. */
3212 if (any_addressable_vars < 0) 3216 if (any_addressable_vars < 0)
3213 { 3217 {
3214 gimple parallel_stmt = last_stmt (region->entry); 3218 gimple parallel_stmt = last_stmt (region->entry);
3215 tree child_fun = gimple_omp_parallel_child_fn (parallel_stmt); 3219 tree child_fun = gimple_omp_parallel_child_fn (parallel_stmt);
3216 tree local_decls = DECL_STRUCT_FUNCTION (child_fun)->local_decls; 3220 tree local_decls, block, decl;
3217 tree block; 3221 unsigned ix;
3218 3222
3219 any_addressable_vars = 0; 3223 any_addressable_vars = 0;
3220 for (; local_decls; local_decls = TREE_CHAIN (local_decls)) 3224 FOR_EACH_LOCAL_DECL (DECL_STRUCT_FUNCTION (child_fun), ix, decl)
3221 if (TREE_ADDRESSABLE (TREE_VALUE (local_decls))) 3225 if (TREE_ADDRESSABLE (decl))
3222 { 3226 {
3223 any_addressable_vars = 1; 3227 any_addressable_vars = 1;
3224 break; 3228 break;
3225 } 3229 }
3226 for (block = gimple_block (stmt); 3230 for (block = gimple_block (stmt);
3229 && TREE_CODE (block) == BLOCK; 3233 && TREE_CODE (block) == BLOCK;
3230 block = BLOCK_SUPERCONTEXT (block)) 3234 block = BLOCK_SUPERCONTEXT (block))
3231 { 3235 {
3232 for (local_decls = BLOCK_VARS (block); 3236 for (local_decls = BLOCK_VARS (block);
3233 local_decls; 3237 local_decls;
3234 local_decls = TREE_CHAIN (local_decls)) 3238 local_decls = DECL_CHAIN (local_decls))
3235 if (TREE_ADDRESSABLE (local_decls)) 3239 if (TREE_ADDRESSABLE (local_decls))
3236 { 3240 {
3237 any_addressable_vars = 1; 3241 any_addressable_vars = 1;
3238 break; 3242 break;
3239 } 3243 }
3335 static void 3339 static void
3336 expand_omp_taskreg (struct omp_region *region) 3340 expand_omp_taskreg (struct omp_region *region)
3337 { 3341 {
3338 basic_block entry_bb, exit_bb, new_bb; 3342 basic_block entry_bb, exit_bb, new_bb;
3339 struct function *child_cfun; 3343 struct function *child_cfun;
3340 tree child_fn, block, t, ws_args, *tp; 3344 tree child_fn, block, t;
3341 tree save_current; 3345 tree save_current;
3342 gimple_stmt_iterator gsi; 3346 gimple_stmt_iterator gsi;
3343 gimple entry_stmt, stmt; 3347 gimple entry_stmt, stmt;
3344 edge e; 3348 edge e;
3349 VEC(tree,gc) *ws_args;
3345 3350
3346 entry_stmt = last_stmt (region->entry); 3351 entry_stmt = last_stmt (region->entry);
3347 child_fn = gimple_omp_taskreg_child_fn (entry_stmt); 3352 child_fn = gimple_omp_taskreg_child_fn (entry_stmt);
3348 child_cfun = DECL_STRUCT_FUNCTION (child_fn); 3353 child_cfun = DECL_STRUCT_FUNCTION (child_fn);
3349 /* If this function has been already instrumented, make sure 3354 /* If this function has been already instrumented, make sure
3354 exit_bb = region->exit; 3359 exit_bb = region->exit;
3355 3360
3356 if (is_combined_parallel (region)) 3361 if (is_combined_parallel (region))
3357 ws_args = region->ws_args; 3362 ws_args = region->ws_args;
3358 else 3363 else
3359 ws_args = NULL_TREE; 3364 ws_args = NULL;
3360 3365
3361 if (child_cfun->cfg) 3366 if (child_cfun->cfg)
3362 { 3367 {
3363 /* Due to inlining, it may happen that we have already outlined 3368 /* Due to inlining, it may happen that we have already outlined
3364 the region, in which case all we need to do is make the 3369 the region, in which case all we need to do is make the
3381 } 3386 }
3382 remove_edge_and_dominated_blocks (entry_succ_e); 3387 remove_edge_and_dominated_blocks (entry_succ_e);
3383 } 3388 }
3384 else 3389 else
3385 { 3390 {
3391 unsigned srcidx, dstidx, num;
3392
3386 /* If the parallel region needs data sent from the parent 3393 /* If the parallel region needs data sent from the parent
3387 function, then the very first statement (except possible 3394 function, then the very first statement (except possible
3388 tree profile counter updates) of the parallel body 3395 tree profile counter updates) of the parallel body
3389 is a copy assignment .OMP_DATA_I = &.OMP_DATA_O. Since 3396 is a copy assignment .OMP_DATA_I = &.OMP_DATA_O. Since
3390 &.OMP_DATA_O is passed as an argument to the child function, 3397 &.OMP_DATA_O is passed as an argument to the child function,
3458 } 3465 }
3459 } 3466 }
3460 3467
3461 /* Declare local variables needed in CHILD_CFUN. */ 3468 /* Declare local variables needed in CHILD_CFUN. */
3462 block = DECL_INITIAL (child_fn); 3469 block = DECL_INITIAL (child_fn);
3463 BLOCK_VARS (block) = list2chain (child_cfun->local_decls); 3470 BLOCK_VARS (block) = vec2chain (child_cfun->local_decls);
3464 /* The gimplifier could record temporaries in parallel/task block 3471 /* The gimplifier could record temporaries in parallel/task block
3465 rather than in containing function's local_decls chain, 3472 rather than in containing function's local_decls chain,
3466 which would mean cgraph missed finalizing them. Do it now. */ 3473 which would mean cgraph missed finalizing them. Do it now. */
3467 for (t = BLOCK_VARS (block); t; t = TREE_CHAIN (t)) 3474 for (t = BLOCK_VARS (block); t; t = DECL_CHAIN (t))
3468 if (TREE_CODE (t) == VAR_DECL 3475 if (TREE_CODE (t) == VAR_DECL
3469 && TREE_STATIC (t) 3476 && TREE_STATIC (t)
3470 && !DECL_EXTERNAL (t)) 3477 && !DECL_EXTERNAL (t))
3471 varpool_finalize_decl (t); 3478 varpool_finalize_decl (t);
3472 DECL_SAVED_TREE (child_fn) = NULL; 3479 DECL_SAVED_TREE (child_fn) = NULL;
3473 gimple_set_body (child_fn, bb_seq (single_succ (entry_bb))); 3480 gimple_set_body (child_fn, bb_seq (single_succ (entry_bb)));
3474 TREE_USED (block) = 1; 3481 TREE_USED (block) = 1;
3475 3482
3476 /* Reset DECL_CONTEXT on function arguments. */ 3483 /* Reset DECL_CONTEXT on function arguments. */
3477 for (t = DECL_ARGUMENTS (child_fn); t; t = TREE_CHAIN (t)) 3484 for (t = DECL_ARGUMENTS (child_fn); t; t = DECL_CHAIN (t))
3478 DECL_CONTEXT (t) = child_fn; 3485 DECL_CONTEXT (t) = child_fn;
3479 3486
3480 /* Split ENTRY_BB at GIMPLE_OMP_PARALLEL or GIMPLE_OMP_TASK, 3487 /* Split ENTRY_BB at GIMPLE_OMP_PARALLEL or GIMPLE_OMP_TASK,
3481 so that it can be moved to the child function. */ 3488 so that it can be moved to the child function. */
3482 gsi = gsi_last_bb (entry_bb); 3489 gsi = gsi_last_bb (entry_bb);
3516 new_bb = move_sese_region_to_fn (child_cfun, entry_bb, exit_bb, block); 3523 new_bb = move_sese_region_to_fn (child_cfun, entry_bb, exit_bb, block);
3517 if (exit_bb) 3524 if (exit_bb)
3518 single_succ_edge (new_bb)->flags = EDGE_FALLTHRU; 3525 single_succ_edge (new_bb)->flags = EDGE_FALLTHRU;
3519 3526
3520 /* Remove non-local VAR_DECLs from child_cfun->local_decls list. */ 3527 /* Remove non-local VAR_DECLs from child_cfun->local_decls list. */
3521 for (tp = &child_cfun->local_decls; *tp; ) 3528 num = VEC_length (tree, child_cfun->local_decls);
3522 if (DECL_CONTEXT (TREE_VALUE (*tp)) != cfun->decl) 3529 for (srcidx = 0, dstidx = 0; srcidx < num; srcidx++)
3523 tp = &TREE_CHAIN (*tp); 3530 {
3524 else 3531 t = VEC_index (tree, child_cfun->local_decls, srcidx);
3525 *tp = TREE_CHAIN (*tp); 3532 if (DECL_CONTEXT (t) == cfun->decl)
3533 continue;
3534 if (srcidx != dstidx)
3535 VEC_replace (tree, child_cfun->local_decls, dstidx, t);
3536 dstidx++;
3537 }
3538 if (dstidx != num)
3539 VEC_truncate (tree, child_cfun->local_decls, dstidx);
3526 3540
3527 /* Inform the callgraph about the new function. */ 3541 /* Inform the callgraph about the new function. */
3528 DECL_STRUCT_FUNCTION (child_fn)->curr_properties 3542 DECL_STRUCT_FUNCTION (child_fn)->curr_properties
3529 = cfun->curr_properties; 3543 = cfun->curr_properties;
3530 cgraph_add_new_function (child_fn, true); 3544 cgraph_add_new_function (child_fn, true);
4919 tree addr, tree loaded_val, 4933 tree addr, tree loaded_val,
4920 tree stored_val, int index) 4934 tree stored_val, int index)
4921 { 4935 {
4922 enum built_in_function base; 4936 enum built_in_function base;
4923 tree decl, itype, call; 4937 tree decl, itype, call;
4924 enum insn_code *optab; 4938 direct_optab optab;
4925 tree rhs; 4939 tree rhs;
4926 basic_block store_bb = single_succ (load_bb); 4940 basic_block store_bb = single_succ (load_bb);
4927 gimple_stmt_iterator gsi; 4941 gimple_stmt_iterator gsi;
4928 gimple stmt; 4942 gimple stmt;
4929 location_t loc; 4943 location_t loc;
4991 return false; 5005 return false;
4992 5006
4993 decl = built_in_decls[base + index + 1]; 5007 decl = built_in_decls[base + index + 1];
4994 itype = TREE_TYPE (TREE_TYPE (decl)); 5008 itype = TREE_TYPE (TREE_TYPE (decl));
4995 5009
4996 if (optab[TYPE_MODE (itype)] == CODE_FOR_nothing) 5010 if (direct_optab_handler (optab, TYPE_MODE (itype)) == CODE_FOR_nothing)
4997 return false; 5011 return false;
4998 5012
4999 gsi = gsi_last_bb (load_bb); 5013 gsi = gsi_last_bb (load_bb);
5000 gcc_assert (gimple_code (gsi_stmt (gsi)) == GIMPLE_OMP_ATOMIC_LOAD); 5014 gcc_assert (gimple_code (gsi_stmt (gsi)) == GIMPLE_OMP_ATOMIC_LOAD);
5001 call = build_call_expr_loc (loc, 5015 call = build_call_expr_loc (loc,
5043 5057
5044 cmpxchg = built_in_decls[BUILT_IN_VAL_COMPARE_AND_SWAP_N + index + 1]; 5058 cmpxchg = built_in_decls[BUILT_IN_VAL_COMPARE_AND_SWAP_N + index + 1];
5045 type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (addr))); 5059 type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (addr)));
5046 itype = TREE_TYPE (TREE_TYPE (cmpxchg)); 5060 itype = TREE_TYPE (TREE_TYPE (cmpxchg));
5047 5061
5048 if (sync_compare_and_swap[TYPE_MODE (itype)] == CODE_FOR_nothing) 5062 if (direct_optab_handler (sync_compare_and_swap_optab, TYPE_MODE (itype))
5063 == CODE_FOR_nothing)
5049 return false; 5064 return false;
5050 5065
5051 /* Load the initial value, replacing the GIMPLE_OMP_ATOMIC_LOAD. */ 5066 /* Load the initial value, replacing the GIMPLE_OMP_ATOMIC_LOAD. */
5052 si = gsi_last_bb (load_bb); 5067 si = gsi_last_bb (load_bb);
5053 gcc_assert (gimple_code (gsi_stmt (si)) == GIMPLE_OMP_ATOMIC_LOAD); 5068 gcc_assert (gimple_code (gsi_stmt (si)) == GIMPLE_OMP_ATOMIC_LOAD);
5079 { 5094 {
5080 iaddr = addr; 5095 iaddr = addr;
5081 loadedi = loaded_val; 5096 loadedi = loaded_val;
5082 } 5097 }
5083 5098
5084 initial = force_gimple_operand_gsi (&si, build_fold_indirect_ref (iaddr), 5099 initial
5085 true, NULL_TREE, true, GSI_SAME_STMT); 5100 = force_gimple_operand_gsi (&si,
5101 build2 (MEM_REF, TREE_TYPE (TREE_TYPE (iaddr)),
5102 iaddr,
5103 build_int_cst (TREE_TYPE (iaddr), 0)),
5104 true, NULL_TREE, true, GSI_SAME_STMT);
5086 5105
5087 /* Move the value to the LOADEDI temporary. */ 5106 /* Move the value to the LOADEDI temporary. */
5088 if (gimple_in_ssa_p (cfun)) 5107 if (gimple_in_ssa_p (cfun))
5089 { 5108 {
5090 gcc_assert (gimple_seq_empty_p (phi_nodes (loop_header))); 5109 gcc_assert (gimple_seq_empty_p (phi_nodes (loop_header)));
5221 5240
5222 si = gsi_last_bb (load_bb); 5241 si = gsi_last_bb (load_bb);
5223 gcc_assert (gimple_code (gsi_stmt (si)) == GIMPLE_OMP_ATOMIC_LOAD); 5242 gcc_assert (gimple_code (gsi_stmt (si)) == GIMPLE_OMP_ATOMIC_LOAD);
5224 5243
5225 t = built_in_decls[BUILT_IN_GOMP_ATOMIC_START]; 5244 t = built_in_decls[BUILT_IN_GOMP_ATOMIC_START];
5226 t = build_function_call_expr (UNKNOWN_LOCATION, t, 0); 5245 t = build_call_expr (t, 0);
5227 force_gimple_operand_gsi (&si, t, true, NULL_TREE, true, GSI_SAME_STMT); 5246 force_gimple_operand_gsi (&si, t, true, NULL_TREE, true, GSI_SAME_STMT);
5228 5247
5229 stmt = gimple_build_assign (loaded_val, build_fold_indirect_ref (addr)); 5248 stmt = gimple_build_assign (loaded_val, build_simple_mem_ref (addr));
5230 gsi_insert_before (&si, stmt, GSI_SAME_STMT); 5249 gsi_insert_before (&si, stmt, GSI_SAME_STMT);
5231 gsi_remove (&si, true); 5250 gsi_remove (&si, true);
5232 5251
5233 si = gsi_last_bb (store_bb); 5252 si = gsi_last_bb (store_bb);
5234 gcc_assert (gimple_code (gsi_stmt (si)) == GIMPLE_OMP_ATOMIC_STORE); 5253 gcc_assert (gimple_code (gsi_stmt (si)) == GIMPLE_OMP_ATOMIC_STORE);
5235 5254
5236 stmt = gimple_build_assign (build_fold_indirect_ref (unshare_expr (addr)), 5255 stmt = gimple_build_assign (build_simple_mem_ref (unshare_expr (addr)),
5237 stored_val); 5256 stored_val);
5238 gsi_insert_before (&si, stmt, GSI_SAME_STMT); 5257 gsi_insert_before (&si, stmt, GSI_SAME_STMT);
5239 5258
5240 t = built_in_decls[BUILT_IN_GOMP_ATOMIC_END]; 5259 t = built_in_decls[BUILT_IN_GOMP_ATOMIC_END];
5241 t = build_function_call_expr (UNKNOWN_LOCATION, t, 0); 5260 t = build_call_expr (t, 0);
5242 force_gimple_operand_gsi (&si, t, true, NULL_TREE, true, GSI_SAME_STMT); 5261 force_gimple_operand_gsi (&si, t, true, NULL_TREE, true, GSI_SAME_STMT);
5243 gsi_remove (&si, true); 5262 gsi_remove (&si, true);
5244 5263
5245 if (gimple_in_ssa_p (cfun)) 5264 if (gimple_in_ssa_p (cfun))
5246 update_ssa (TODO_update_ssa_no_phi); 5265 update_ssa (TODO_update_ssa_no_phi);
5510 /* OMP expansion -- the default pass, run before creation of SSA form. */ 5529 /* OMP expansion -- the default pass, run before creation of SSA form. */
5511 5530
5512 static bool 5531 static bool
5513 gate_expand_omp (void) 5532 gate_expand_omp (void)
5514 { 5533 {
5515 return (flag_openmp != 0 && errorcount == 0); 5534 return (flag_openmp != 0 && !seen_error ());
5516 } 5535 }
5517 5536
5518 struct gimple_opt_pass pass_expand_omp = 5537 struct gimple_opt_pass pass_expand_omp =
5519 { 5538 {
5520 { 5539 {
5899 tree decl; 5918 tree decl;
5900 splay_tree_node n; 5919 splay_tree_node n;
5901 5920
5902 if (!critical_name_mutexes) 5921 if (!critical_name_mutexes)
5903 critical_name_mutexes 5922 critical_name_mutexes
5904 = splay_tree_new_ggc (splay_tree_compare_pointers); 5923 = splay_tree_new_ggc (splay_tree_compare_pointers,
5924 ggc_alloc_splay_tree_tree_node_tree_node_splay_tree_s,
5925 ggc_alloc_splay_tree_tree_node_tree_node_splay_tree_node_s);
5905 5926
5906 n = splay_tree_lookup (critical_name_mutexes, (splay_tree_key) name); 5927 n = splay_tree_lookup (critical_name_mutexes, (splay_tree_key) name);
5907 if (n == NULL) 5928 if (n == NULL)
5908 { 5929 {
5909 char *new_str; 5930 char *new_str;
6206 gcc_assert (child_cfun->cfg == NULL); 6227 gcc_assert (child_cfun->cfg == NULL);
6207 child_cfun->dont_save_pending_sizes_p = 1; 6228 child_cfun->dont_save_pending_sizes_p = 1;
6208 DECL_SAVED_TREE (child_fn) = alloc_stmt_list (); 6229 DECL_SAVED_TREE (child_fn) = alloc_stmt_list ();
6209 6230
6210 /* Reset DECL_CONTEXT on function arguments. */ 6231 /* Reset DECL_CONTEXT on function arguments. */
6211 for (t = DECL_ARGUMENTS (child_fn); t; t = TREE_CHAIN (t)) 6232 for (t = DECL_ARGUMENTS (child_fn); t; t = DECL_CHAIN (t))
6212 DECL_CONTEXT (t) = child_fn; 6233 DECL_CONTEXT (t) = child_fn;
6213 6234
6214 /* Populate the function. */ 6235 /* Populate the function. */
6215 push_gimplify_context (&gctx); 6236 push_gimplify_context (&gctx);
6216 current_function_decl = child_fn; 6237 current_function_decl = child_fn;
6222 DECL_SOURCE_LOCATION (child_fn) = gimple_location (task_stmt); 6243 DECL_SOURCE_LOCATION (child_fn) = gimple_location (task_stmt);
6223 6244
6224 /* Remap src and dst argument types if needed. */ 6245 /* Remap src and dst argument types if needed. */
6225 record_type = ctx->record_type; 6246 record_type = ctx->record_type;
6226 srecord_type = ctx->srecord_type; 6247 srecord_type = ctx->srecord_type;
6227 for (f = TYPE_FIELDS (record_type); f ; f = TREE_CHAIN (f)) 6248 for (f = TYPE_FIELDS (record_type); f ; f = DECL_CHAIN (f))
6228 if (variably_modified_type_p (TREE_TYPE (f), ctx->cb.src_fn)) 6249 if (variably_modified_type_p (TREE_TYPE (f), ctx->cb.src_fn))
6229 { 6250 {
6230 record_needs_remap = true; 6251 record_needs_remap = true;
6231 break; 6252 break;
6232 } 6253 }
6233 for (f = TYPE_FIELDS (srecord_type); f ; f = TREE_CHAIN (f)) 6254 for (f = TYPE_FIELDS (srecord_type); f ; f = DECL_CHAIN (f))
6234 if (variably_modified_type_p (TREE_TYPE (f), ctx->cb.src_fn)) 6255 if (variably_modified_type_p (TREE_TYPE (f), ctx->cb.src_fn))
6235 { 6256 {
6236 srecord_needs_remap = true; 6257 srecord_needs_remap = true;
6237 break; 6258 break;
6238 } 6259 }
6261 6282
6262 push_cfun (child_cfun); 6283 push_cfun (child_cfun);
6263 6284
6264 arg = DECL_ARGUMENTS (child_fn); 6285 arg = DECL_ARGUMENTS (child_fn);
6265 TREE_TYPE (arg) = build_pointer_type (record_type); 6286 TREE_TYPE (arg) = build_pointer_type (record_type);
6266 sarg = TREE_CHAIN (arg); 6287 sarg = DECL_CHAIN (arg);
6267 TREE_TYPE (sarg) = build_pointer_type (srecord_type); 6288 TREE_TYPE (sarg) = build_pointer_type (srecord_type);
6268 6289
6269 /* First pass: initialize temporaries used in record_type and srecord_type 6290 /* First pass: initialize temporaries used in record_type and srecord_type
6270 sizes and field offsets. */ 6291 sizes and field offsets. */
6271 if (tcctx.cb.decl_map) 6292 if (tcctx.cb.decl_map)
6279 if (p == NULL) 6300 if (p == NULL)
6280 continue; 6301 continue;
6281 n = splay_tree_lookup (ctx->sfield_map, (splay_tree_key) decl); 6302 n = splay_tree_lookup (ctx->sfield_map, (splay_tree_key) decl);
6282 sf = (tree) n->value; 6303 sf = (tree) n->value;
6283 sf = *(tree *) pointer_map_contains (tcctx.cb.decl_map, sf); 6304 sf = *(tree *) pointer_map_contains (tcctx.cb.decl_map, sf);
6284 src = build_fold_indirect_ref_loc (loc, sarg); 6305 src = build_simple_mem_ref_loc (loc, sarg);
6285 src = build3 (COMPONENT_REF, TREE_TYPE (sf), src, sf, NULL); 6306 src = build3 (COMPONENT_REF, TREE_TYPE (sf), src, sf, NULL);
6286 t = build2 (MODIFY_EXPR, TREE_TYPE (*p), *p, src); 6307 t = build2 (MODIFY_EXPR, TREE_TYPE (*p), *p, src);
6287 append_to_statement_list (t, &list); 6308 append_to_statement_list (t, &list);
6288 } 6309 }
6289 6310
6302 f = *(tree *) pointer_map_contains (tcctx.cb.decl_map, f); 6323 f = *(tree *) pointer_map_contains (tcctx.cb.decl_map, f);
6303 n = splay_tree_lookup (ctx->sfield_map, (splay_tree_key) decl); 6324 n = splay_tree_lookup (ctx->sfield_map, (splay_tree_key) decl);
6304 sf = (tree) n->value; 6325 sf = (tree) n->value;
6305 if (tcctx.cb.decl_map) 6326 if (tcctx.cb.decl_map)
6306 sf = *(tree *) pointer_map_contains (tcctx.cb.decl_map, sf); 6327 sf = *(tree *) pointer_map_contains (tcctx.cb.decl_map, sf);
6307 src = build_fold_indirect_ref_loc (loc, sarg); 6328 src = build_simple_mem_ref_loc (loc, sarg);
6308 src = build3 (COMPONENT_REF, TREE_TYPE (sf), src, sf, NULL); 6329 src = build3 (COMPONENT_REF, TREE_TYPE (sf), src, sf, NULL);
6309 dst = build_fold_indirect_ref_loc (loc, arg); 6330 dst = build_simple_mem_ref_loc (loc, arg);
6310 dst = build3 (COMPONENT_REF, TREE_TYPE (f), dst, f, NULL); 6331 dst = build3 (COMPONENT_REF, TREE_TYPE (f), dst, f, NULL);
6311 t = build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src); 6332 t = build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src);
6312 append_to_statement_list (t, &list); 6333 append_to_statement_list (t, &list);
6313 break; 6334 break;
6314 case OMP_CLAUSE_FIRSTPRIVATE: 6335 case OMP_CLAUSE_FIRSTPRIVATE:
6325 if (n != NULL) 6346 if (n != NULL)
6326 { 6347 {
6327 sf = (tree) n->value; 6348 sf = (tree) n->value;
6328 if (tcctx.cb.decl_map) 6349 if (tcctx.cb.decl_map)
6329 sf = *(tree *) pointer_map_contains (tcctx.cb.decl_map, sf); 6350 sf = *(tree *) pointer_map_contains (tcctx.cb.decl_map, sf);
6330 src = build_fold_indirect_ref_loc (loc, sarg); 6351 src = build_simple_mem_ref_loc (loc, sarg);
6331 src = build3 (COMPONENT_REF, TREE_TYPE (sf), src, sf, NULL); 6352 src = build3 (COMPONENT_REF, TREE_TYPE (sf), src, sf, NULL);
6332 if (use_pointer_for_field (decl, NULL) || is_reference (decl)) 6353 if (use_pointer_for_field (decl, NULL) || is_reference (decl))
6333 src = build_fold_indirect_ref_loc (loc, src); 6354 src = build_simple_mem_ref_loc (loc, src);
6334 } 6355 }
6335 else 6356 else
6336 src = decl; 6357 src = decl;
6337 dst = build_fold_indirect_ref_loc (loc, arg); 6358 dst = build_simple_mem_ref_loc (loc, arg);
6338 dst = build3 (COMPONENT_REF, TREE_TYPE (f), dst, f, NULL); 6359 dst = build3 (COMPONENT_REF, TREE_TYPE (f), dst, f, NULL);
6339 t = lang_hooks.decls.omp_clause_copy_ctor (c, dst, src); 6360 t = lang_hooks.decls.omp_clause_copy_ctor (c, dst, src);
6340 append_to_statement_list (t, &list); 6361 append_to_statement_list (t, &list);
6341 break; 6362 break;
6342 case OMP_CLAUSE_PRIVATE: 6363 case OMP_CLAUSE_PRIVATE:
6351 if (n != NULL) 6372 if (n != NULL)
6352 { 6373 {
6353 sf = (tree) n->value; 6374 sf = (tree) n->value;
6354 if (tcctx.cb.decl_map) 6375 if (tcctx.cb.decl_map)
6355 sf = *(tree *) pointer_map_contains (tcctx.cb.decl_map, sf); 6376 sf = *(tree *) pointer_map_contains (tcctx.cb.decl_map, sf);
6356 src = build_fold_indirect_ref_loc (loc, sarg); 6377 src = build_simple_mem_ref_loc (loc, sarg);
6357 src = build3 (COMPONENT_REF, TREE_TYPE (sf), src, sf, NULL); 6378 src = build3 (COMPONENT_REF, TREE_TYPE (sf), src, sf, NULL);
6358 if (use_pointer_for_field (decl, NULL)) 6379 if (use_pointer_for_field (decl, NULL))
6359 src = build_fold_indirect_ref_loc (loc, src); 6380 src = build_simple_mem_ref_loc (loc, src);
6360 } 6381 }
6361 else 6382 else
6362 src = decl; 6383 src = decl;
6363 dst = build_fold_indirect_ref_loc (loc, arg); 6384 dst = build_simple_mem_ref_loc (loc, arg);
6364 dst = build3 (COMPONENT_REF, TREE_TYPE (f), dst, f, NULL); 6385 dst = build3 (COMPONENT_REF, TREE_TYPE (f), dst, f, NULL);
6365 t = build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src); 6386 t = build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src);
6366 append_to_statement_list (t, &list); 6387 append_to_statement_list (t, &list);
6367 break; 6388 break;
6368 default: 6389 default:
6390 gcc_assert (DECL_P (TREE_OPERAND (ind, 0))); 6411 gcc_assert (DECL_P (TREE_OPERAND (ind, 0)));
6391 n = splay_tree_lookup (ctx->sfield_map, 6412 n = splay_tree_lookup (ctx->sfield_map,
6392 (splay_tree_key) TREE_OPERAND (ind, 0)); 6413 (splay_tree_key) TREE_OPERAND (ind, 0));
6393 sf = (tree) n->value; 6414 sf = (tree) n->value;
6394 sf = *(tree *) pointer_map_contains (tcctx.cb.decl_map, sf); 6415 sf = *(tree *) pointer_map_contains (tcctx.cb.decl_map, sf);
6395 src = build_fold_indirect_ref_loc (loc, sarg); 6416 src = build_simple_mem_ref_loc (loc, sarg);
6396 src = build3 (COMPONENT_REF, TREE_TYPE (sf), src, sf, NULL); 6417 src = build3 (COMPONENT_REF, TREE_TYPE (sf), src, sf, NULL);
6397 src = build_fold_indirect_ref_loc (loc, src); 6418 src = build_simple_mem_ref_loc (loc, src);
6398 dst = build_fold_indirect_ref_loc (loc, arg); 6419 dst = build_simple_mem_ref_loc (loc, arg);
6399 dst = build3 (COMPONENT_REF, TREE_TYPE (f), dst, f, NULL); 6420 dst = build3 (COMPONENT_REF, TREE_TYPE (f), dst, f, NULL);
6400 t = lang_hooks.decls.omp_clause_copy_ctor (c, dst, src); 6421 t = lang_hooks.decls.omp_clause_copy_ctor (c, dst, src);
6401 append_to_statement_list (t, &list); 6422 append_to_statement_list (t, &list);
6402 n = splay_tree_lookup (ctx->field_map, 6423 n = splay_tree_lookup (ctx->field_map,
6403 (splay_tree_key) TREE_OPERAND (ind, 0)); 6424 (splay_tree_key) TREE_OPERAND (ind, 0));
6404 df = (tree) n->value; 6425 df = (tree) n->value;
6405 df = *(tree *) pointer_map_contains (tcctx.cb.decl_map, df); 6426 df = *(tree *) pointer_map_contains (tcctx.cb.decl_map, df);
6406 ptr = build_fold_indirect_ref_loc (loc, arg); 6427 ptr = build_simple_mem_ref_loc (loc, arg);
6407 ptr = build3 (COMPONENT_REF, TREE_TYPE (df), ptr, df, NULL); 6428 ptr = build3 (COMPONENT_REF, TREE_TYPE (df), ptr, df, NULL);
6408 t = build2 (MODIFY_EXPR, TREE_TYPE (ptr), ptr, 6429 t = build2 (MODIFY_EXPR, TREE_TYPE (ptr), ptr,
6409 build_fold_addr_expr_loc (loc, dst)); 6430 build_fold_addr_expr_loc (loc, dst));
6410 append_to_statement_list (t, &list); 6431 append_to_statement_list (t, &list);
6411 } 6432 }
6472 if (ctx->record_type) 6493 if (ctx->record_type)
6473 { 6494 {
6474 ctx->sender_decl 6495 ctx->sender_decl
6475 = create_tmp_var (ctx->srecord_type ? ctx->srecord_type 6496 = create_tmp_var (ctx->srecord_type ? ctx->srecord_type
6476 : ctx->record_type, ".omp_data_o"); 6497 : ctx->record_type, ".omp_data_o");
6498 DECL_NAMELESS (ctx->sender_decl) = 1;
6477 TREE_ADDRESSABLE (ctx->sender_decl) = 1; 6499 TREE_ADDRESSABLE (ctx->sender_decl) = 1;
6478 gimple_omp_taskreg_set_data_arg (stmt, ctx->sender_decl); 6500 gimple_omp_taskreg_set_data_arg (stmt, ctx->sender_decl);
6479 } 6501 }
6480 6502
6481 olist = NULL; 6503 olist = NULL;
6559 memset (&wi, '\0', sizeof (wi)); 6581 memset (&wi, '\0', sizeof (wi));
6560 6582
6561 /* If we have issued syntax errors, avoid doing any heavy lifting. 6583 /* If we have issued syntax errors, avoid doing any heavy lifting.
6562 Just replace the OpenMP directives with a NOP to avoid 6584 Just replace the OpenMP directives with a NOP to avoid
6563 confusing RTL expansion. */ 6585 confusing RTL expansion. */
6564 if (errorcount && is_gimple_omp (stmt)) 6586 if (seen_error () && is_gimple_omp (stmt))
6565 { 6587 {
6566 gsi_replace (gsi_p, gimple_build_nop (), true); 6588 gsi_replace (gsi_p, gimple_build_nop (), true);
6567 return; 6589 return;
6568 } 6590 }
6569 6591