annotate gcc/c-family/c-omp.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents 561a7518be6b
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents: 68
diff changeset
1 /* This file contains routines to construct OpenACC and OpenMP constructs,
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 called from parsing in the C and C++ front ends.
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
111
kono
parents: 68
diff changeset
4 Copyright (C) 2005-2017 Free Software Foundation, Inc.
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 Contributed by Richard Henderson <rth@redhat.com>,
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 Diego Novillo <dnovillo@redhat.com>.
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 This file is part of GCC.
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 GCC is free software; you can redistribute it and/or modify it under
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 the terms of the GNU General Public License as published by the Free
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 Software Foundation; either version 3, or (at your option) any later
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 version.
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 for more details.
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 You should have received a copy of the GNU General Public License
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 along with GCC; see the file COPYING3. If not see
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 <http://www.gnu.org/licenses/>. */
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 #include "config.h"
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 #include "system.h"
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 #include "coretypes.h"
111
kono
parents: 68
diff changeset
27 #include "options.h"
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 #include "c-common.h"
111
kono
parents: 68
diff changeset
29 #include "gimple-expr.h"
kono
parents: 68
diff changeset
30 #include "c-pragma.h"
kono
parents: 68
diff changeset
31 #include "omp-general.h"
kono
parents: 68
diff changeset
32 #include "gomp-constants.h"
kono
parents: 68
diff changeset
33
kono
parents: 68
diff changeset
34
kono
parents: 68
diff changeset
35 /* Complete a #pragma oacc wait construct. LOC is the location of
kono
parents: 68
diff changeset
36 the #pragma. */
kono
parents: 68
diff changeset
37
kono
parents: 68
diff changeset
38 tree
kono
parents: 68
diff changeset
39 c_finish_oacc_wait (location_t loc, tree parms, tree clauses)
kono
parents: 68
diff changeset
40 {
kono
parents: 68
diff changeset
41 const int nparms = list_length (parms);
kono
parents: 68
diff changeset
42 tree stmt, t;
kono
parents: 68
diff changeset
43 vec<tree, va_gc> *args;
kono
parents: 68
diff changeset
44
kono
parents: 68
diff changeset
45 vec_alloc (args, nparms + 2);
kono
parents: 68
diff changeset
46 stmt = builtin_decl_explicit (BUILT_IN_GOACC_WAIT);
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47
111
kono
parents: 68
diff changeset
48 if (omp_find_clause (clauses, OMP_CLAUSE_ASYNC))
kono
parents: 68
diff changeset
49 t = OMP_CLAUSE_ASYNC_EXPR (clauses);
kono
parents: 68
diff changeset
50 else
kono
parents: 68
diff changeset
51 t = build_int_cst (integer_type_node, GOMP_ASYNC_SYNC);
kono
parents: 68
diff changeset
52
kono
parents: 68
diff changeset
53 args->quick_push (t);
kono
parents: 68
diff changeset
54 args->quick_push (build_int_cst (integer_type_node, nparms));
kono
parents: 68
diff changeset
55
kono
parents: 68
diff changeset
56 for (t = parms; t; t = TREE_CHAIN (t))
kono
parents: 68
diff changeset
57 {
kono
parents: 68
diff changeset
58 if (TREE_CODE (OMP_CLAUSE_WAIT_EXPR (t)) == INTEGER_CST)
kono
parents: 68
diff changeset
59 args->quick_push (build_int_cst (integer_type_node,
kono
parents: 68
diff changeset
60 TREE_INT_CST_LOW (OMP_CLAUSE_WAIT_EXPR (t))));
kono
parents: 68
diff changeset
61 else
kono
parents: 68
diff changeset
62 args->quick_push (OMP_CLAUSE_WAIT_EXPR (t));
kono
parents: 68
diff changeset
63 }
kono
parents: 68
diff changeset
64
kono
parents: 68
diff changeset
65 stmt = build_call_expr_loc_vec (loc, stmt, args);
kono
parents: 68
diff changeset
66
kono
parents: 68
diff changeset
67 vec_free (args);
kono
parents: 68
diff changeset
68
kono
parents: 68
diff changeset
69 return stmt;
kono
parents: 68
diff changeset
70 }
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 /* Complete a #pragma omp master construct. STMT is the structured-block
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 that follows the pragma. LOC is the l*/
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 tree
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 c_finish_omp_master (location_t loc, tree stmt)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 tree t = add_stmt (build1 (OMP_MASTER, void_type_node, stmt));
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 SET_EXPR_LOCATION (t, loc);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 return t;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82
111
kono
parents: 68
diff changeset
83 /* Complete a #pragma omp taskgroup construct. STMT is the structured-block
kono
parents: 68
diff changeset
84 that follows the pragma. LOC is the l*/
kono
parents: 68
diff changeset
85
kono
parents: 68
diff changeset
86 tree
kono
parents: 68
diff changeset
87 c_finish_omp_taskgroup (location_t loc, tree stmt)
kono
parents: 68
diff changeset
88 {
kono
parents: 68
diff changeset
89 tree t = add_stmt (build1 (OMP_TASKGROUP, void_type_node, stmt));
kono
parents: 68
diff changeset
90 SET_EXPR_LOCATION (t, loc);
kono
parents: 68
diff changeset
91 return t;
kono
parents: 68
diff changeset
92 }
kono
parents: 68
diff changeset
93
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 /* Complete a #pragma omp critical construct. STMT is the structured-block
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 that follows the pragma, NAME is the identifier in the pragma, or null
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 if it was omitted. LOC is the location of the #pragma. */
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 tree
111
kono
parents: 68
diff changeset
99 c_finish_omp_critical (location_t loc, tree body, tree name, tree clauses)
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 tree stmt = make_node (OMP_CRITICAL);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 TREE_TYPE (stmt) = void_type_node;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 OMP_CRITICAL_BODY (stmt) = body;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 OMP_CRITICAL_NAME (stmt) = name;
111
kono
parents: 68
diff changeset
105 OMP_CRITICAL_CLAUSES (stmt) = clauses;
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 SET_EXPR_LOCATION (stmt, loc);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 return add_stmt (stmt);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 /* Complete a #pragma omp ordered construct. STMT is the structured-block
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 that follows the pragma. LOC is the location of the #pragma. */
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 tree
111
kono
parents: 68
diff changeset
114 c_finish_omp_ordered (location_t loc, tree clauses, tree stmt)
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 {
111
kono
parents: 68
diff changeset
116 tree t = make_node (OMP_ORDERED);
kono
parents: 68
diff changeset
117 TREE_TYPE (t) = void_type_node;
kono
parents: 68
diff changeset
118 OMP_ORDERED_BODY (t) = stmt;
kono
parents: 68
diff changeset
119 if (!flag_openmp /* flag_openmp_simd */
kono
parents: 68
diff changeset
120 && (OMP_CLAUSE_CODE (clauses) != OMP_CLAUSE_SIMD
kono
parents: 68
diff changeset
121 || OMP_CLAUSE_CHAIN (clauses)))
kono
parents: 68
diff changeset
122 clauses = build_omp_clause (loc, OMP_CLAUSE_SIMD);
kono
parents: 68
diff changeset
123 OMP_ORDERED_CLAUSES (t) = clauses;
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 SET_EXPR_LOCATION (t, loc);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 return add_stmt (t);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
127
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
128
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 /* Complete a #pragma omp barrier construct. LOC is the location of
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 the #pragma. */
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 void
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 c_finish_omp_barrier (location_t loc)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 tree x;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136
111
kono
parents: 68
diff changeset
137 x = builtin_decl_explicit (BUILT_IN_GOMP_BARRIER);
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 x = build_call_expr_loc (loc, x, 0);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 add_stmt (x);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
141
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
142
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 /* Complete a #pragma omp taskwait construct. LOC is the location of the
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 pragma. */
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
145
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 void
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 c_finish_omp_taskwait (location_t loc)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 tree x;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
150
111
kono
parents: 68
diff changeset
151 x = builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT);
kono
parents: 68
diff changeset
152 x = build_call_expr_loc (loc, x, 0);
kono
parents: 68
diff changeset
153 add_stmt (x);
kono
parents: 68
diff changeset
154 }
kono
parents: 68
diff changeset
155
kono
parents: 68
diff changeset
156
kono
parents: 68
diff changeset
157 /* Complete a #pragma omp taskyield construct. LOC is the location of the
kono
parents: 68
diff changeset
158 pragma. */
kono
parents: 68
diff changeset
159
kono
parents: 68
diff changeset
160 void
kono
parents: 68
diff changeset
161 c_finish_omp_taskyield (location_t loc)
kono
parents: 68
diff changeset
162 {
kono
parents: 68
diff changeset
163 tree x;
kono
parents: 68
diff changeset
164
kono
parents: 68
diff changeset
165 x = builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD);
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 x = build_call_expr_loc (loc, x, 0);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 add_stmt (x);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
169
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
170
111
kono
parents: 68
diff changeset
171 /* Complete a #pragma omp atomic construct. For CODE OMP_ATOMIC
kono
parents: 68
diff changeset
172 the expression to be implemented atomically is LHS opcode= RHS.
kono
parents: 68
diff changeset
173 For OMP_ATOMIC_READ V = LHS, for OMP_ATOMIC_CAPTURE_{NEW,OLD} LHS
kono
parents: 68
diff changeset
174 opcode= RHS with the new or old content of LHS returned.
kono
parents: 68
diff changeset
175 LOC is the location of the atomic statement. The value returned
kono
parents: 68
diff changeset
176 is either error_mark_node (if the construct was erroneous) or an
kono
parents: 68
diff changeset
177 OMP_ATOMIC* node which should be added to the current statement
kono
parents: 68
diff changeset
178 tree with add_stmt. If TEST is set, avoid calling save_expr
kono
parents: 68
diff changeset
179 or create_tmp_var*. */
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
180
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 tree
111
kono
parents: 68
diff changeset
182 c_finish_omp_atomic (location_t loc, enum tree_code code,
kono
parents: 68
diff changeset
183 enum tree_code opcode, tree lhs, tree rhs,
kono
parents: 68
diff changeset
184 tree v, tree lhs1, tree rhs1, bool swapped, bool seq_cst,
kono
parents: 68
diff changeset
185 bool test)
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 {
111
kono
parents: 68
diff changeset
187 tree x, type, addr, pre = NULL_TREE;
kono
parents: 68
diff changeset
188 HOST_WIDE_INT bitpos = 0, bitsize = 0;
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
189
111
kono
parents: 68
diff changeset
190 if (lhs == error_mark_node || rhs == error_mark_node
kono
parents: 68
diff changeset
191 || v == error_mark_node || lhs1 == error_mark_node
kono
parents: 68
diff changeset
192 || rhs1 == error_mark_node)
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 return error_mark_node;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
194
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 /* ??? According to one reading of the OpenMP spec, complex type are
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 supported, but there are no atomic stores for any architecture.
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 But at least icc 9.0 doesn't support complex types here either.
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 And lets not even talk about vector types... */
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 type = TREE_TYPE (lhs);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 if (!INTEGRAL_TYPE_P (type)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 && !POINTER_TYPE_P (type)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 && !SCALAR_FLOAT_TYPE_P (type))
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 error_at (loc, "invalid expression type for %<#pragma omp atomic%>");
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 return error_mark_node;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 }
111
kono
parents: 68
diff changeset
207 if (TYPE_ATOMIC (type))
kono
parents: 68
diff changeset
208 {
kono
parents: 68
diff changeset
209 error_at (loc, "%<_Atomic%> expression in %<#pragma omp atomic%>");
kono
parents: 68
diff changeset
210 return error_mark_node;
kono
parents: 68
diff changeset
211 }
kono
parents: 68
diff changeset
212
kono
parents: 68
diff changeset
213 if (opcode == RDIV_EXPR)
kono
parents: 68
diff changeset
214 opcode = TRUNC_DIV_EXPR;
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
215
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
216 /* ??? Validate that rhs does not overlap lhs. */
111
kono
parents: 68
diff changeset
217 tree blhs = NULL;
kono
parents: 68
diff changeset
218 if (TREE_CODE (lhs) == COMPONENT_REF
kono
parents: 68
diff changeset
219 && TREE_CODE (TREE_OPERAND (lhs, 1)) == FIELD_DECL
kono
parents: 68
diff changeset
220 && DECL_C_BIT_FIELD (TREE_OPERAND (lhs, 1))
kono
parents: 68
diff changeset
221 && DECL_BIT_FIELD_REPRESENTATIVE (TREE_OPERAND (lhs, 1)))
kono
parents: 68
diff changeset
222 {
kono
parents: 68
diff changeset
223 tree field = TREE_OPERAND (lhs, 1);
kono
parents: 68
diff changeset
224 tree repr = DECL_BIT_FIELD_REPRESENTATIVE (field);
kono
parents: 68
diff changeset
225 if (tree_fits_uhwi_p (DECL_FIELD_OFFSET (field))
kono
parents: 68
diff changeset
226 && tree_fits_uhwi_p (DECL_FIELD_OFFSET (repr)))
kono
parents: 68
diff changeset
227 bitpos = (tree_to_uhwi (DECL_FIELD_OFFSET (field))
kono
parents: 68
diff changeset
228 - tree_to_uhwi (DECL_FIELD_OFFSET (repr))) * BITS_PER_UNIT;
kono
parents: 68
diff changeset
229 else
kono
parents: 68
diff changeset
230 bitpos = 0;
kono
parents: 68
diff changeset
231 bitpos += (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field))
kono
parents: 68
diff changeset
232 - tree_to_uhwi (DECL_FIELD_BIT_OFFSET (repr)));
kono
parents: 68
diff changeset
233 gcc_assert (tree_fits_shwi_p (DECL_SIZE (field)));
kono
parents: 68
diff changeset
234 bitsize = tree_to_shwi (DECL_SIZE (field));
kono
parents: 68
diff changeset
235 blhs = lhs;
kono
parents: 68
diff changeset
236 type = TREE_TYPE (repr);
kono
parents: 68
diff changeset
237 lhs = build3 (COMPONENT_REF, TREE_TYPE (repr), TREE_OPERAND (lhs, 0),
kono
parents: 68
diff changeset
238 repr, TREE_OPERAND (lhs, 2));
kono
parents: 68
diff changeset
239 }
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
240
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 /* Take and save the address of the lhs. From then on we'll reference it
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
242 via indirection. */
111
kono
parents: 68
diff changeset
243 addr = build_unary_op (loc, ADDR_EXPR, lhs, false);
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 if (addr == error_mark_node)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 return error_mark_node;
111
kono
parents: 68
diff changeset
246 if (!test)
kono
parents: 68
diff changeset
247 addr = save_expr (addr);
kono
parents: 68
diff changeset
248 if (!test
kono
parents: 68
diff changeset
249 && TREE_CODE (addr) != SAVE_EXPR
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 && (TREE_CODE (addr) != ADDR_EXPR
111
kono
parents: 68
diff changeset
251 || !VAR_P (TREE_OPERAND (addr, 0))))
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 /* Make sure LHS is simple enough so that goa_lhs_expr_p can recognize
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 it even after unsharing function body. */
111
kono
parents: 68
diff changeset
255 tree var = create_tmp_var_raw (TREE_TYPE (addr));
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
256 DECL_CONTEXT (var) = current_function_decl;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 addr = build4 (TARGET_EXPR, TREE_TYPE (addr), var, addr, NULL, NULL);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
258 }
111
kono
parents: 68
diff changeset
259 tree orig_lhs = lhs;
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
260 lhs = build_indirect_ref (loc, addr, RO_NULL);
111
kono
parents: 68
diff changeset
261 tree new_lhs = lhs;
kono
parents: 68
diff changeset
262
kono
parents: 68
diff changeset
263 if (code == OMP_ATOMIC_READ)
kono
parents: 68
diff changeset
264 {
kono
parents: 68
diff changeset
265 x = build1 (OMP_ATOMIC_READ, type, addr);
kono
parents: 68
diff changeset
266 SET_EXPR_LOCATION (x, loc);
kono
parents: 68
diff changeset
267 OMP_ATOMIC_SEQ_CST (x) = seq_cst;
kono
parents: 68
diff changeset
268 if (blhs)
kono
parents: 68
diff changeset
269 x = build3_loc (loc, BIT_FIELD_REF, TREE_TYPE (blhs), x,
kono
parents: 68
diff changeset
270 bitsize_int (bitsize), bitsize_int (bitpos));
kono
parents: 68
diff changeset
271 return build_modify_expr (loc, v, NULL_TREE, NOP_EXPR,
kono
parents: 68
diff changeset
272 loc, x, NULL_TREE);
kono
parents: 68
diff changeset
273 }
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
274
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
275 /* There are lots of warnings, errors, and conversions that need to happen
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 in the course of interpreting a statement. Use the normal mechanisms
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 to do this, and then take it apart again. */
111
kono
parents: 68
diff changeset
278 if (blhs)
kono
parents: 68
diff changeset
279 {
kono
parents: 68
diff changeset
280 lhs = build3_loc (loc, BIT_FIELD_REF, TREE_TYPE (blhs), lhs,
kono
parents: 68
diff changeset
281 bitsize_int (bitsize), bitsize_int (bitpos));
kono
parents: 68
diff changeset
282 if (swapped)
kono
parents: 68
diff changeset
283 rhs = build_binary_op (loc, opcode, rhs, lhs, true);
kono
parents: 68
diff changeset
284 else if (opcode != NOP_EXPR)
kono
parents: 68
diff changeset
285 rhs = build_binary_op (loc, opcode, lhs, rhs, true);
kono
parents: 68
diff changeset
286 opcode = NOP_EXPR;
kono
parents: 68
diff changeset
287 }
kono
parents: 68
diff changeset
288 else if (swapped)
kono
parents: 68
diff changeset
289 {
kono
parents: 68
diff changeset
290 rhs = build_binary_op (loc, opcode, rhs, lhs, true);
kono
parents: 68
diff changeset
291 opcode = NOP_EXPR;
kono
parents: 68
diff changeset
292 }
kono
parents: 68
diff changeset
293 bool save = in_late_binary_op;
kono
parents: 68
diff changeset
294 in_late_binary_op = true;
kono
parents: 68
diff changeset
295 x = build_modify_expr (loc, blhs ? blhs : lhs, NULL_TREE, opcode,
kono
parents: 68
diff changeset
296 loc, rhs, NULL_TREE);
kono
parents: 68
diff changeset
297 in_late_binary_op = save;
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 if (x == error_mark_node)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
299 return error_mark_node;
111
kono
parents: 68
diff changeset
300 if (TREE_CODE (x) == COMPOUND_EXPR)
kono
parents: 68
diff changeset
301 {
kono
parents: 68
diff changeset
302 pre = TREE_OPERAND (x, 0);
kono
parents: 68
diff changeset
303 gcc_assert (TREE_CODE (pre) == SAVE_EXPR);
kono
parents: 68
diff changeset
304 x = TREE_OPERAND (x, 1);
kono
parents: 68
diff changeset
305 }
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
306 gcc_assert (TREE_CODE (x) == MODIFY_EXPR);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 rhs = TREE_OPERAND (x, 1);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
308
111
kono
parents: 68
diff changeset
309 if (blhs)
kono
parents: 68
diff changeset
310 rhs = build3_loc (loc, BIT_INSERT_EXPR, type, new_lhs,
kono
parents: 68
diff changeset
311 rhs, bitsize_int (bitpos));
kono
parents: 68
diff changeset
312
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
313 /* Punt the actual generation of atomic operations to common code. */
111
kono
parents: 68
diff changeset
314 if (code == OMP_ATOMIC)
kono
parents: 68
diff changeset
315 type = void_type_node;
kono
parents: 68
diff changeset
316 x = build2 (code, type, addr, rhs);
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
317 SET_EXPR_LOCATION (x, loc);
111
kono
parents: 68
diff changeset
318 OMP_ATOMIC_SEQ_CST (x) = seq_cst;
kono
parents: 68
diff changeset
319
kono
parents: 68
diff changeset
320 /* Generally it is hard to prove lhs1 and lhs are the same memory
kono
parents: 68
diff changeset
321 location, just diagnose different variables. */
kono
parents: 68
diff changeset
322 if (rhs1
kono
parents: 68
diff changeset
323 && VAR_P (rhs1)
kono
parents: 68
diff changeset
324 && VAR_P (orig_lhs)
kono
parents: 68
diff changeset
325 && rhs1 != orig_lhs
kono
parents: 68
diff changeset
326 && !test)
kono
parents: 68
diff changeset
327 {
kono
parents: 68
diff changeset
328 if (code == OMP_ATOMIC)
kono
parents: 68
diff changeset
329 error_at (loc, "%<#pragma omp atomic update%> uses two different "
kono
parents: 68
diff changeset
330 "variables for memory");
kono
parents: 68
diff changeset
331 else
kono
parents: 68
diff changeset
332 error_at (loc, "%<#pragma omp atomic capture%> uses two different "
kono
parents: 68
diff changeset
333 "variables for memory");
kono
parents: 68
diff changeset
334 return error_mark_node;
kono
parents: 68
diff changeset
335 }
kono
parents: 68
diff changeset
336
kono
parents: 68
diff changeset
337 if (lhs1
kono
parents: 68
diff changeset
338 && lhs1 != orig_lhs
kono
parents: 68
diff changeset
339 && TREE_CODE (lhs1) == COMPONENT_REF
kono
parents: 68
diff changeset
340 && TREE_CODE (TREE_OPERAND (lhs1, 1)) == FIELD_DECL
kono
parents: 68
diff changeset
341 && DECL_C_BIT_FIELD (TREE_OPERAND (lhs1, 1))
kono
parents: 68
diff changeset
342 && DECL_BIT_FIELD_REPRESENTATIVE (TREE_OPERAND (lhs1, 1)))
kono
parents: 68
diff changeset
343 {
kono
parents: 68
diff changeset
344 tree field = TREE_OPERAND (lhs1, 1);
kono
parents: 68
diff changeset
345 tree repr = DECL_BIT_FIELD_REPRESENTATIVE (field);
kono
parents: 68
diff changeset
346 lhs1 = build3 (COMPONENT_REF, TREE_TYPE (repr), TREE_OPERAND (lhs1, 0),
kono
parents: 68
diff changeset
347 repr, TREE_OPERAND (lhs1, 2));
kono
parents: 68
diff changeset
348 }
kono
parents: 68
diff changeset
349 if (rhs1
kono
parents: 68
diff changeset
350 && rhs1 != orig_lhs
kono
parents: 68
diff changeset
351 && TREE_CODE (rhs1) == COMPONENT_REF
kono
parents: 68
diff changeset
352 && TREE_CODE (TREE_OPERAND (rhs1, 1)) == FIELD_DECL
kono
parents: 68
diff changeset
353 && DECL_C_BIT_FIELD (TREE_OPERAND (rhs1, 1))
kono
parents: 68
diff changeset
354 && DECL_BIT_FIELD_REPRESENTATIVE (TREE_OPERAND (rhs1, 1)))
kono
parents: 68
diff changeset
355 {
kono
parents: 68
diff changeset
356 tree field = TREE_OPERAND (rhs1, 1);
kono
parents: 68
diff changeset
357 tree repr = DECL_BIT_FIELD_REPRESENTATIVE (field);
kono
parents: 68
diff changeset
358 rhs1 = build3 (COMPONENT_REF, TREE_TYPE (repr), TREE_OPERAND (rhs1, 0),
kono
parents: 68
diff changeset
359 repr, TREE_OPERAND (rhs1, 2));
kono
parents: 68
diff changeset
360 }
kono
parents: 68
diff changeset
361
kono
parents: 68
diff changeset
362 if (code != OMP_ATOMIC)
kono
parents: 68
diff changeset
363 {
kono
parents: 68
diff changeset
364 /* Generally it is hard to prove lhs1 and lhs are the same memory
kono
parents: 68
diff changeset
365 location, just diagnose different variables. */
kono
parents: 68
diff changeset
366 if (lhs1 && VAR_P (lhs1) && VAR_P (orig_lhs))
kono
parents: 68
diff changeset
367 {
kono
parents: 68
diff changeset
368 if (lhs1 != orig_lhs && !test)
kono
parents: 68
diff changeset
369 {
kono
parents: 68
diff changeset
370 error_at (loc, "%<#pragma omp atomic capture%> uses two "
kono
parents: 68
diff changeset
371 "different variables for memory");
kono
parents: 68
diff changeset
372 return error_mark_node;
kono
parents: 68
diff changeset
373 }
kono
parents: 68
diff changeset
374 }
kono
parents: 68
diff changeset
375 if (blhs)
kono
parents: 68
diff changeset
376 x = build3_loc (loc, BIT_FIELD_REF, TREE_TYPE (blhs), x,
kono
parents: 68
diff changeset
377 bitsize_int (bitsize), bitsize_int (bitpos));
kono
parents: 68
diff changeset
378 x = build_modify_expr (loc, v, NULL_TREE, NOP_EXPR,
kono
parents: 68
diff changeset
379 loc, x, NULL_TREE);
kono
parents: 68
diff changeset
380 if (rhs1 && rhs1 != orig_lhs)
kono
parents: 68
diff changeset
381 {
kono
parents: 68
diff changeset
382 tree rhs1addr = build_unary_op (loc, ADDR_EXPR, rhs1, false);
kono
parents: 68
diff changeset
383 if (rhs1addr == error_mark_node)
kono
parents: 68
diff changeset
384 return error_mark_node;
kono
parents: 68
diff changeset
385 x = omit_one_operand_loc (loc, type, x, rhs1addr);
kono
parents: 68
diff changeset
386 }
kono
parents: 68
diff changeset
387 if (lhs1 && lhs1 != orig_lhs)
kono
parents: 68
diff changeset
388 {
kono
parents: 68
diff changeset
389 tree lhs1addr = build_unary_op (loc, ADDR_EXPR, lhs1, false);
kono
parents: 68
diff changeset
390 if (lhs1addr == error_mark_node)
kono
parents: 68
diff changeset
391 return error_mark_node;
kono
parents: 68
diff changeset
392 if (code == OMP_ATOMIC_CAPTURE_OLD)
kono
parents: 68
diff changeset
393 x = omit_one_operand_loc (loc, type, x, lhs1addr);
kono
parents: 68
diff changeset
394 else
kono
parents: 68
diff changeset
395 {
kono
parents: 68
diff changeset
396 if (!test)
kono
parents: 68
diff changeset
397 x = save_expr (x);
kono
parents: 68
diff changeset
398 x = omit_two_operands_loc (loc, type, x, x, lhs1addr);
kono
parents: 68
diff changeset
399 }
kono
parents: 68
diff changeset
400 }
kono
parents: 68
diff changeset
401 }
kono
parents: 68
diff changeset
402 else if (rhs1 && rhs1 != orig_lhs)
kono
parents: 68
diff changeset
403 {
kono
parents: 68
diff changeset
404 tree rhs1addr = build_unary_op (loc, ADDR_EXPR, rhs1, false);
kono
parents: 68
diff changeset
405 if (rhs1addr == error_mark_node)
kono
parents: 68
diff changeset
406 return error_mark_node;
kono
parents: 68
diff changeset
407 x = omit_one_operand_loc (loc, type, x, rhs1addr);
kono
parents: 68
diff changeset
408 }
kono
parents: 68
diff changeset
409
kono
parents: 68
diff changeset
410 if (pre)
kono
parents: 68
diff changeset
411 x = omit_one_operand_loc (loc, type, x, pre);
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
412 return x;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
413 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
414
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
415
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
416 /* Complete a #pragma omp flush construct. We don't do anything with
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
417 the variable list that the syntax allows. LOC is the location of
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
418 the #pragma. */
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
419
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
420 void
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
421 c_finish_omp_flush (location_t loc)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
422 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
423 tree x;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
424
111
kono
parents: 68
diff changeset
425 x = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE);
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
426 x = build_call_expr_loc (loc, x, 0);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
427 add_stmt (x);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
428 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
429
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
430
111
kono
parents: 68
diff changeset
431 /* Check and canonicalize OMP_FOR increment expression.
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
432 Helper function for c_finish_omp_for. */
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
433
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
434 static tree
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
435 check_omp_for_incr_expr (location_t loc, tree exp, tree decl)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
436 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
437 tree t;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
438
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
439 if (!INTEGRAL_TYPE_P (TREE_TYPE (exp))
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
440 || TYPE_PRECISION (TREE_TYPE (exp)) < TYPE_PRECISION (TREE_TYPE (decl)))
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
441 return error_mark_node;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
442
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
443 if (exp == decl)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
444 return build_int_cst (TREE_TYPE (exp), 0);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
445
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
446 switch (TREE_CODE (exp))
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
447 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
448 CASE_CONVERT:
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
449 t = check_omp_for_incr_expr (loc, TREE_OPERAND (exp, 0), decl);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
450 if (t != error_mark_node)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
451 return fold_convert_loc (loc, TREE_TYPE (exp), t);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
452 break;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
453 case MINUS_EXPR:
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
454 t = check_omp_for_incr_expr (loc, TREE_OPERAND (exp, 0), decl);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
455 if (t != error_mark_node)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
456 return fold_build2_loc (loc, MINUS_EXPR,
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
457 TREE_TYPE (exp), t, TREE_OPERAND (exp, 1));
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
458 break;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
459 case PLUS_EXPR:
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
460 t = check_omp_for_incr_expr (loc, TREE_OPERAND (exp, 0), decl);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
461 if (t != error_mark_node)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
462 return fold_build2_loc (loc, PLUS_EXPR,
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
463 TREE_TYPE (exp), t, TREE_OPERAND (exp, 1));
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
464 t = check_omp_for_incr_expr (loc, TREE_OPERAND (exp, 1), decl);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
465 if (t != error_mark_node)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
466 return fold_build2_loc (loc, PLUS_EXPR,
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
467 TREE_TYPE (exp), TREE_OPERAND (exp, 0), t);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
468 break;
111
kono
parents: 68
diff changeset
469 case COMPOUND_EXPR:
kono
parents: 68
diff changeset
470 {
kono
parents: 68
diff changeset
471 /* cp_build_modify_expr forces preevaluation of the RHS to make
kono
parents: 68
diff changeset
472 sure that it is evaluated before the lvalue-rvalue conversion
kono
parents: 68
diff changeset
473 is applied to the LHS. Reconstruct the original expression. */
kono
parents: 68
diff changeset
474 tree op0 = TREE_OPERAND (exp, 0);
kono
parents: 68
diff changeset
475 if (TREE_CODE (op0) == TARGET_EXPR
kono
parents: 68
diff changeset
476 && !VOID_TYPE_P (TREE_TYPE (op0)))
kono
parents: 68
diff changeset
477 {
kono
parents: 68
diff changeset
478 tree op1 = TREE_OPERAND (exp, 1);
kono
parents: 68
diff changeset
479 tree temp = TARGET_EXPR_SLOT (op0);
kono
parents: 68
diff changeset
480 if (BINARY_CLASS_P (op1)
kono
parents: 68
diff changeset
481 && TREE_OPERAND (op1, 1) == temp)
kono
parents: 68
diff changeset
482 {
kono
parents: 68
diff changeset
483 op1 = copy_node (op1);
kono
parents: 68
diff changeset
484 TREE_OPERAND (op1, 1) = TARGET_EXPR_INITIAL (op0);
kono
parents: 68
diff changeset
485 return check_omp_for_incr_expr (loc, op1, decl);
kono
parents: 68
diff changeset
486 }
kono
parents: 68
diff changeset
487 }
kono
parents: 68
diff changeset
488 break;
kono
parents: 68
diff changeset
489 }
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
490 default:
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
491 break;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
492 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
493
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
494 return error_mark_node;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
495 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
496
111
kono
parents: 68
diff changeset
497 /* If the OMP_FOR increment expression in INCR is of pointer type,
kono
parents: 68
diff changeset
498 canonicalize it into an expression handled by gimplify_omp_for()
kono
parents: 68
diff changeset
499 and return it. DECL is the iteration variable. */
kono
parents: 68
diff changeset
500
kono
parents: 68
diff changeset
501 static tree
kono
parents: 68
diff changeset
502 c_omp_for_incr_canonicalize_ptr (location_t loc, tree decl, tree incr)
kono
parents: 68
diff changeset
503 {
kono
parents: 68
diff changeset
504 if (POINTER_TYPE_P (TREE_TYPE (decl))
kono
parents: 68
diff changeset
505 && TREE_OPERAND (incr, 1))
kono
parents: 68
diff changeset
506 {
kono
parents: 68
diff changeset
507 tree t = fold_convert_loc (loc,
kono
parents: 68
diff changeset
508 sizetype, TREE_OPERAND (incr, 1));
kono
parents: 68
diff changeset
509
kono
parents: 68
diff changeset
510 if (TREE_CODE (incr) == POSTDECREMENT_EXPR
kono
parents: 68
diff changeset
511 || TREE_CODE (incr) == PREDECREMENT_EXPR)
kono
parents: 68
diff changeset
512 t = fold_build1_loc (loc, NEGATE_EXPR, sizetype, t);
kono
parents: 68
diff changeset
513 t = fold_build_pointer_plus (decl, t);
kono
parents: 68
diff changeset
514 incr = build2 (MODIFY_EXPR, void_type_node, decl, t);
kono
parents: 68
diff changeset
515 }
kono
parents: 68
diff changeset
516 return incr;
kono
parents: 68
diff changeset
517 }
kono
parents: 68
diff changeset
518
kono
parents: 68
diff changeset
519 /* Validate and generate OMP_FOR.
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
520 DECLV is a vector of iteration variables, for each collapsed loop.
111
kono
parents: 68
diff changeset
521
kono
parents: 68
diff changeset
522 ORIG_DECLV, if non-NULL, is a vector with the original iteration
kono
parents: 68
diff changeset
523 variables (prior to any transformations, by say, C++ iterators).
kono
parents: 68
diff changeset
524
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
525 INITV, CONDV and INCRV are vectors containing initialization
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
526 expressions, controlling predicates and increment expressions.
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
527 BODY is the body of the loop and PRE_BODY statements that go before
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
528 the loop. */
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
529
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
530 tree
111
kono
parents: 68
diff changeset
531 c_finish_omp_for (location_t locus, enum tree_code code, tree declv,
kono
parents: 68
diff changeset
532 tree orig_declv, tree initv, tree condv, tree incrv,
kono
parents: 68
diff changeset
533 tree body, tree pre_body)
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
534 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
535 location_t elocus;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
536 bool fail = false;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
537 int i;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
538
111
kono
parents: 68
diff changeset
539 if ((code == CILK_SIMD || code == CILK_FOR)
kono
parents: 68
diff changeset
540 && !c_check_cilk_loop (locus, TREE_VEC_ELT (declv, 0)))
kono
parents: 68
diff changeset
541 fail = true;
kono
parents: 68
diff changeset
542
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
543 gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (initv));
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
544 gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (condv));
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
545 gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (incrv));
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
546 for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
547 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
548 tree decl = TREE_VEC_ELT (declv, i);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
549 tree init = TREE_VEC_ELT (initv, i);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
550 tree cond = TREE_VEC_ELT (condv, i);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
551 tree incr = TREE_VEC_ELT (incrv, i);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
552
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
553 elocus = locus;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
554 if (EXPR_HAS_LOCATION (init))
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
555 elocus = EXPR_LOCATION (init);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
556
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
557 /* Validate the iteration variable. */
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
558 if (!INTEGRAL_TYPE_P (TREE_TYPE (decl))
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
559 && TREE_CODE (TREE_TYPE (decl)) != POINTER_TYPE)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
560 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
561 error_at (elocus, "invalid type for iteration variable %qE", decl);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
562 fail = true;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
563 }
111
kono
parents: 68
diff changeset
564 else if (TYPE_ATOMIC (TREE_TYPE (decl)))
kono
parents: 68
diff changeset
565 {
kono
parents: 68
diff changeset
566 error_at (elocus, "%<_Atomic%> iteration variable %qE", decl);
kono
parents: 68
diff changeset
567 fail = true;
kono
parents: 68
diff changeset
568 /* _Atomic iterator confuses stuff too much, so we risk ICE
kono
parents: 68
diff changeset
569 trying to diagnose it further. */
kono
parents: 68
diff changeset
570 continue;
kono
parents: 68
diff changeset
571 }
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
572
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
573 /* In the case of "for (int i = 0...)", init will be a decl. It should
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
574 have a DECL_INITIAL that we can turn into an assignment. */
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
575 if (init == decl)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
576 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
577 elocus = DECL_SOURCE_LOCATION (decl);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
578
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
579 init = DECL_INITIAL (decl);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
580 if (init == NULL)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
581 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
582 error_at (elocus, "%qE is not initialized", decl);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
583 init = integer_zero_node;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
584 fail = true;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
585 }
111
kono
parents: 68
diff changeset
586 DECL_INITIAL (decl) = NULL_TREE;
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
587
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
588 init = build_modify_expr (elocus, decl, NULL_TREE, NOP_EXPR,
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
589 /* FIXME diagnostics: This should
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
590 be the location of the INIT. */
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
591 elocus,
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
592 init,
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
593 NULL_TREE);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
594 }
111
kono
parents: 68
diff changeset
595 if (init != error_mark_node)
kono
parents: 68
diff changeset
596 {
kono
parents: 68
diff changeset
597 gcc_assert (TREE_CODE (init) == MODIFY_EXPR);
kono
parents: 68
diff changeset
598 gcc_assert (TREE_OPERAND (init, 0) == decl);
kono
parents: 68
diff changeset
599 }
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
600
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
601 if (cond == NULL_TREE)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
602 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
603 error_at (elocus, "missing controlling predicate");
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
604 fail = true;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
605 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
606 else
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
607 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
608 bool cond_ok = false;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
609
111
kono
parents: 68
diff changeset
610 /* E.g. C sizeof (vla) could add COMPOUND_EXPRs with
kono
parents: 68
diff changeset
611 evaluation of the vla VAR_DECL. We need to readd
kono
parents: 68
diff changeset
612 them to the non-decl operand. See PR45784. */
kono
parents: 68
diff changeset
613 while (TREE_CODE (cond) == COMPOUND_EXPR)
kono
parents: 68
diff changeset
614 cond = TREE_OPERAND (cond, 1);
kono
parents: 68
diff changeset
615
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
616 if (EXPR_HAS_LOCATION (cond))
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
617 elocus = EXPR_LOCATION (cond);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
618
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
619 if (TREE_CODE (cond) == LT_EXPR
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
620 || TREE_CODE (cond) == LE_EXPR
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
621 || TREE_CODE (cond) == GT_EXPR
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
622 || TREE_CODE (cond) == GE_EXPR
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
623 || TREE_CODE (cond) == NE_EXPR
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
624 || TREE_CODE (cond) == EQ_EXPR)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
625 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
626 tree op0 = TREE_OPERAND (cond, 0);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
627 tree op1 = TREE_OPERAND (cond, 1);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
628
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
629 /* 2.5.1. The comparison in the condition is computed in
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
630 the type of DECL, otherwise the behavior is undefined.
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
631
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
632 For example:
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
633 long n; int i;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
634 i < n;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
635
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
636 according to ISO will be evaluated as:
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
637 (long)i < n;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
638
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
639 We want to force:
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
640 i < (int)n; */
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
641 if (TREE_CODE (op0) == NOP_EXPR
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
642 && decl == TREE_OPERAND (op0, 0))
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
643 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
644 TREE_OPERAND (cond, 0) = TREE_OPERAND (op0, 0);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
645 TREE_OPERAND (cond, 1)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
646 = fold_build1_loc (elocus, NOP_EXPR, TREE_TYPE (decl),
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
647 TREE_OPERAND (cond, 1));
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
648 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
649 else if (TREE_CODE (op1) == NOP_EXPR
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
650 && decl == TREE_OPERAND (op1, 0))
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
651 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
652 TREE_OPERAND (cond, 1) = TREE_OPERAND (op1, 0);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
653 TREE_OPERAND (cond, 0)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
654 = fold_build1_loc (elocus, NOP_EXPR, TREE_TYPE (decl),
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
655 TREE_OPERAND (cond, 0));
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
656 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
657
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
658 if (decl == TREE_OPERAND (cond, 0))
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
659 cond_ok = true;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
660 else if (decl == TREE_OPERAND (cond, 1))
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
661 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
662 TREE_SET_CODE (cond,
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
663 swap_tree_comparison (TREE_CODE (cond)));
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
664 TREE_OPERAND (cond, 1) = TREE_OPERAND (cond, 0);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
665 TREE_OPERAND (cond, 0) = decl;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
666 cond_ok = true;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
667 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
668
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
669 if (TREE_CODE (cond) == NE_EXPR
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
670 || TREE_CODE (cond) == EQ_EXPR)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
671 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
672 if (!INTEGRAL_TYPE_P (TREE_TYPE (decl)))
111
kono
parents: 68
diff changeset
673 {
kono
parents: 68
diff changeset
674 if (code != CILK_SIMD && code != CILK_FOR)
kono
parents: 68
diff changeset
675 cond_ok = false;
kono
parents: 68
diff changeset
676 }
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
677 else if (operand_equal_p (TREE_OPERAND (cond, 1),
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
678 TYPE_MIN_VALUE (TREE_TYPE (decl)),
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
679 0))
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
680 TREE_SET_CODE (cond, TREE_CODE (cond) == NE_EXPR
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
681 ? GT_EXPR : LE_EXPR);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
682 else if (operand_equal_p (TREE_OPERAND (cond, 1),
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
683 TYPE_MAX_VALUE (TREE_TYPE (decl)),
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
684 0))
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
685 TREE_SET_CODE (cond, TREE_CODE (cond) == NE_EXPR
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
686 ? LT_EXPR : GE_EXPR);
111
kono
parents: 68
diff changeset
687 else if (code != CILK_SIMD && code != CILK_FOR)
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
688 cond_ok = false;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
689 }
111
kono
parents: 68
diff changeset
690
kono
parents: 68
diff changeset
691 if (cond_ok && TREE_VEC_ELT (condv, i) != cond)
kono
parents: 68
diff changeset
692 {
kono
parents: 68
diff changeset
693 tree ce = NULL_TREE, *pce = &ce;
kono
parents: 68
diff changeset
694 tree type = TREE_TYPE (TREE_OPERAND (cond, 1));
kono
parents: 68
diff changeset
695 for (tree c = TREE_VEC_ELT (condv, i); c != cond;
kono
parents: 68
diff changeset
696 c = TREE_OPERAND (c, 1))
kono
parents: 68
diff changeset
697 {
kono
parents: 68
diff changeset
698 *pce = build2 (COMPOUND_EXPR, type, TREE_OPERAND (c, 0),
kono
parents: 68
diff changeset
699 TREE_OPERAND (cond, 1));
kono
parents: 68
diff changeset
700 pce = &TREE_OPERAND (*pce, 1);
kono
parents: 68
diff changeset
701 }
kono
parents: 68
diff changeset
702 TREE_OPERAND (cond, 1) = ce;
kono
parents: 68
diff changeset
703 TREE_VEC_ELT (condv, i) = cond;
kono
parents: 68
diff changeset
704 }
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
705 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
706
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
707 if (!cond_ok)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
708 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
709 error_at (elocus, "invalid controlling predicate");
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
710 fail = true;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
711 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
712 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
713
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
714 if (incr == NULL_TREE)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
715 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
716 error_at (elocus, "missing increment expression");
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
717 fail = true;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
718 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
719 else
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
720 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
721 bool incr_ok = false;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
722
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
723 if (EXPR_HAS_LOCATION (incr))
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
724 elocus = EXPR_LOCATION (incr);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
725
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
726 /* Check all the valid increment expressions: v++, v--, ++v, --v,
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
727 v = v + incr, v = incr + v and v = v - incr. */
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
728 switch (TREE_CODE (incr))
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
729 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
730 case POSTINCREMENT_EXPR:
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
731 case PREINCREMENT_EXPR:
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
732 case POSTDECREMENT_EXPR:
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
733 case PREDECREMENT_EXPR:
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
734 if (TREE_OPERAND (incr, 0) != decl)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
735 break;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
736
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
737 incr_ok = true;
111
kono
parents: 68
diff changeset
738 incr = c_omp_for_incr_canonicalize_ptr (elocus, decl, incr);
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
739 break;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
740
111
kono
parents: 68
diff changeset
741 case COMPOUND_EXPR:
kono
parents: 68
diff changeset
742 if (TREE_CODE (TREE_OPERAND (incr, 0)) != SAVE_EXPR
kono
parents: 68
diff changeset
743 || TREE_CODE (TREE_OPERAND (incr, 1)) != MODIFY_EXPR)
kono
parents: 68
diff changeset
744 break;
kono
parents: 68
diff changeset
745 incr = TREE_OPERAND (incr, 1);
kono
parents: 68
diff changeset
746 /* FALLTHRU */
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
747 case MODIFY_EXPR:
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
748 if (TREE_OPERAND (incr, 0) != decl)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
749 break;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
750 if (TREE_OPERAND (incr, 1) == decl)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
751 break;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
752 if (TREE_CODE (TREE_OPERAND (incr, 1)) == PLUS_EXPR
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
753 && (TREE_OPERAND (TREE_OPERAND (incr, 1), 0) == decl
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
754 || TREE_OPERAND (TREE_OPERAND (incr, 1), 1) == decl))
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
755 incr_ok = true;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
756 else if ((TREE_CODE (TREE_OPERAND (incr, 1)) == MINUS_EXPR
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
757 || (TREE_CODE (TREE_OPERAND (incr, 1))
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
758 == POINTER_PLUS_EXPR))
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
759 && TREE_OPERAND (TREE_OPERAND (incr, 1), 0) == decl)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
760 incr_ok = true;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
761 else
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
762 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
763 tree t = check_omp_for_incr_expr (elocus,
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
764 TREE_OPERAND (incr, 1),
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
765 decl);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
766 if (t != error_mark_node)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
767 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
768 incr_ok = true;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
769 t = build2 (PLUS_EXPR, TREE_TYPE (decl), decl, t);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
770 incr = build2 (MODIFY_EXPR, void_type_node, decl, t);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
771 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
772 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
773 break;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
774
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
775 default:
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
776 break;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
777 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
778 if (!incr_ok)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
779 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
780 error_at (elocus, "invalid increment expression");
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
781 fail = true;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
782 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
783 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
784
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
785 TREE_VEC_ELT (initv, i) = init;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
786 TREE_VEC_ELT (incrv, i) = incr;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
787 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
788
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
789 if (fail)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
790 return NULL;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
791 else
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
792 {
111
kono
parents: 68
diff changeset
793 tree t = make_node (code);
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
794
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
795 TREE_TYPE (t) = void_type_node;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
796 OMP_FOR_INIT (t) = initv;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
797 OMP_FOR_COND (t) = condv;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
798 OMP_FOR_INCR (t) = incrv;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
799 OMP_FOR_BODY (t) = body;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
800 OMP_FOR_PRE_BODY (t) = pre_body;
111
kono
parents: 68
diff changeset
801 OMP_FOR_ORIG_DECLS (t) = orig_declv;
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
802
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
803 SET_EXPR_LOCATION (t, locus);
111
kono
parents: 68
diff changeset
804 return t;
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
805 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
806 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
807
111
kono
parents: 68
diff changeset
808 /* Type for passing data in between c_omp_check_loop_iv and
kono
parents: 68
diff changeset
809 c_omp_check_loop_iv_r. */
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
810
111
kono
parents: 68
diff changeset
811 struct c_omp_check_loop_iv_data
kono
parents: 68
diff changeset
812 {
kono
parents: 68
diff changeset
813 tree declv;
kono
parents: 68
diff changeset
814 bool fail;
kono
parents: 68
diff changeset
815 location_t stmt_loc;
kono
parents: 68
diff changeset
816 location_t expr_loc;
kono
parents: 68
diff changeset
817 int kind;
kono
parents: 68
diff changeset
818 walk_tree_lh lh;
kono
parents: 68
diff changeset
819 hash_set<tree> *ppset;
kono
parents: 68
diff changeset
820 };
kono
parents: 68
diff changeset
821
kono
parents: 68
diff changeset
822 /* Helper function called via walk_tree, to diagnose uses
kono
parents: 68
diff changeset
823 of associated loop IVs inside of lb, b and incr expressions
kono
parents: 68
diff changeset
824 of OpenMP loops. */
kono
parents: 68
diff changeset
825
kono
parents: 68
diff changeset
826 static tree
kono
parents: 68
diff changeset
827 c_omp_check_loop_iv_r (tree *tp, int *walk_subtrees, void *data)
kono
parents: 68
diff changeset
828 {
kono
parents: 68
diff changeset
829 struct c_omp_check_loop_iv_data *d
kono
parents: 68
diff changeset
830 = (struct c_omp_check_loop_iv_data *) data;
kono
parents: 68
diff changeset
831 if (DECL_P (*tp))
kono
parents: 68
diff changeset
832 {
kono
parents: 68
diff changeset
833 int i;
kono
parents: 68
diff changeset
834 for (i = 0; i < TREE_VEC_LENGTH (d->declv); i++)
kono
parents: 68
diff changeset
835 if (*tp == TREE_VEC_ELT (d->declv, i))
kono
parents: 68
diff changeset
836 {
kono
parents: 68
diff changeset
837 location_t loc = d->expr_loc;
kono
parents: 68
diff changeset
838 if (loc == UNKNOWN_LOCATION)
kono
parents: 68
diff changeset
839 loc = d->stmt_loc;
kono
parents: 68
diff changeset
840 switch (d->kind)
kono
parents: 68
diff changeset
841 {
kono
parents: 68
diff changeset
842 case 0:
kono
parents: 68
diff changeset
843 error_at (loc, "initializer expression refers to "
kono
parents: 68
diff changeset
844 "iteration variable %qD", *tp);
kono
parents: 68
diff changeset
845 break;
kono
parents: 68
diff changeset
846 case 1:
kono
parents: 68
diff changeset
847 error_at (loc, "condition expression refers to "
kono
parents: 68
diff changeset
848 "iteration variable %qD", *tp);
kono
parents: 68
diff changeset
849 break;
kono
parents: 68
diff changeset
850 case 2:
kono
parents: 68
diff changeset
851 error_at (loc, "increment expression refers to "
kono
parents: 68
diff changeset
852 "iteration variable %qD", *tp);
kono
parents: 68
diff changeset
853 break;
kono
parents: 68
diff changeset
854 }
kono
parents: 68
diff changeset
855 d->fail = true;
kono
parents: 68
diff changeset
856 }
kono
parents: 68
diff changeset
857 }
kono
parents: 68
diff changeset
858 /* Don't walk dtors added by C++ wrap_cleanups_r. */
kono
parents: 68
diff changeset
859 else if (TREE_CODE (*tp) == TRY_CATCH_EXPR
kono
parents: 68
diff changeset
860 && TRY_CATCH_IS_CLEANUP (*tp))
kono
parents: 68
diff changeset
861 {
kono
parents: 68
diff changeset
862 *walk_subtrees = 0;
kono
parents: 68
diff changeset
863 return walk_tree_1 (&TREE_OPERAND (*tp, 0), c_omp_check_loop_iv_r, data,
kono
parents: 68
diff changeset
864 d->ppset, d->lh);
kono
parents: 68
diff changeset
865 }
kono
parents: 68
diff changeset
866
kono
parents: 68
diff changeset
867 return NULL_TREE;
kono
parents: 68
diff changeset
868 }
kono
parents: 68
diff changeset
869
kono
parents: 68
diff changeset
870 /* Diagnose invalid references to loop iterators in lb, b and incr
kono
parents: 68
diff changeset
871 expressions. */
kono
parents: 68
diff changeset
872
kono
parents: 68
diff changeset
873 bool
kono
parents: 68
diff changeset
874 c_omp_check_loop_iv (tree stmt, tree declv, walk_tree_lh lh)
kono
parents: 68
diff changeset
875 {
kono
parents: 68
diff changeset
876 hash_set<tree> pset;
kono
parents: 68
diff changeset
877 struct c_omp_check_loop_iv_data data;
kono
parents: 68
diff changeset
878 int i;
kono
parents: 68
diff changeset
879
kono
parents: 68
diff changeset
880 data.declv = declv;
kono
parents: 68
diff changeset
881 data.fail = false;
kono
parents: 68
diff changeset
882 data.stmt_loc = EXPR_LOCATION (stmt);
kono
parents: 68
diff changeset
883 data.lh = lh;
kono
parents: 68
diff changeset
884 data.ppset = &pset;
kono
parents: 68
diff changeset
885 for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (stmt)); i++)
kono
parents: 68
diff changeset
886 {
kono
parents: 68
diff changeset
887 tree init = TREE_VEC_ELT (OMP_FOR_INIT (stmt), i);
kono
parents: 68
diff changeset
888 gcc_assert (TREE_CODE (init) == MODIFY_EXPR);
kono
parents: 68
diff changeset
889 tree decl = TREE_OPERAND (init, 0);
kono
parents: 68
diff changeset
890 tree cond = TREE_VEC_ELT (OMP_FOR_COND (stmt), i);
kono
parents: 68
diff changeset
891 gcc_assert (COMPARISON_CLASS_P (cond));
kono
parents: 68
diff changeset
892 gcc_assert (TREE_OPERAND (cond, 0) == decl);
kono
parents: 68
diff changeset
893 tree incr = TREE_VEC_ELT (OMP_FOR_INCR (stmt), i);
kono
parents: 68
diff changeset
894 data.expr_loc = EXPR_LOCATION (TREE_OPERAND (init, 1));
kono
parents: 68
diff changeset
895 data.kind = 0;
kono
parents: 68
diff changeset
896 walk_tree_1 (&TREE_OPERAND (init, 1),
kono
parents: 68
diff changeset
897 c_omp_check_loop_iv_r, &data, &pset, lh);
kono
parents: 68
diff changeset
898 /* Don't warn for C++ random access iterators here, the
kono
parents: 68
diff changeset
899 expression then involves the subtraction and always refers
kono
parents: 68
diff changeset
900 to the original value. The C++ FE needs to warn on those
kono
parents: 68
diff changeset
901 earlier. */
kono
parents: 68
diff changeset
902 if (decl == TREE_VEC_ELT (declv, i))
kono
parents: 68
diff changeset
903 {
kono
parents: 68
diff changeset
904 data.expr_loc = EXPR_LOCATION (cond);
kono
parents: 68
diff changeset
905 data.kind = 1;
kono
parents: 68
diff changeset
906 walk_tree_1 (&TREE_OPERAND (cond, 1),
kono
parents: 68
diff changeset
907 c_omp_check_loop_iv_r, &data, &pset, lh);
kono
parents: 68
diff changeset
908 }
kono
parents: 68
diff changeset
909 if (TREE_CODE (incr) == MODIFY_EXPR)
kono
parents: 68
diff changeset
910 {
kono
parents: 68
diff changeset
911 gcc_assert (TREE_OPERAND (incr, 0) == decl);
kono
parents: 68
diff changeset
912 incr = TREE_OPERAND (incr, 1);
kono
parents: 68
diff changeset
913 data.kind = 2;
kono
parents: 68
diff changeset
914 if (TREE_CODE (incr) == PLUS_EXPR
kono
parents: 68
diff changeset
915 && TREE_OPERAND (incr, 1) == decl)
kono
parents: 68
diff changeset
916 {
kono
parents: 68
diff changeset
917 data.expr_loc = EXPR_LOCATION (TREE_OPERAND (incr, 0));
kono
parents: 68
diff changeset
918 walk_tree_1 (&TREE_OPERAND (incr, 0),
kono
parents: 68
diff changeset
919 c_omp_check_loop_iv_r, &data, &pset, lh);
kono
parents: 68
diff changeset
920 }
kono
parents: 68
diff changeset
921 else
kono
parents: 68
diff changeset
922 {
kono
parents: 68
diff changeset
923 data.expr_loc = EXPR_LOCATION (TREE_OPERAND (incr, 1));
kono
parents: 68
diff changeset
924 walk_tree_1 (&TREE_OPERAND (incr, 1),
kono
parents: 68
diff changeset
925 c_omp_check_loop_iv_r, &data, &pset, lh);
kono
parents: 68
diff changeset
926 }
kono
parents: 68
diff changeset
927 }
kono
parents: 68
diff changeset
928 }
kono
parents: 68
diff changeset
929 return !data.fail;
kono
parents: 68
diff changeset
930 }
kono
parents: 68
diff changeset
931
kono
parents: 68
diff changeset
932 /* Similar, but allows to check the init or cond expressions individually. */
kono
parents: 68
diff changeset
933
kono
parents: 68
diff changeset
934 bool
kono
parents: 68
diff changeset
935 c_omp_check_loop_iv_exprs (location_t stmt_loc, tree declv, tree decl,
kono
parents: 68
diff changeset
936 tree init, tree cond, walk_tree_lh lh)
kono
parents: 68
diff changeset
937 {
kono
parents: 68
diff changeset
938 hash_set<tree> pset;
kono
parents: 68
diff changeset
939 struct c_omp_check_loop_iv_data data;
kono
parents: 68
diff changeset
940
kono
parents: 68
diff changeset
941 data.declv = declv;
kono
parents: 68
diff changeset
942 data.fail = false;
kono
parents: 68
diff changeset
943 data.stmt_loc = stmt_loc;
kono
parents: 68
diff changeset
944 data.lh = lh;
kono
parents: 68
diff changeset
945 data.ppset = &pset;
kono
parents: 68
diff changeset
946 if (init)
kono
parents: 68
diff changeset
947 {
kono
parents: 68
diff changeset
948 data.expr_loc = EXPR_LOCATION (init);
kono
parents: 68
diff changeset
949 data.kind = 0;
kono
parents: 68
diff changeset
950 walk_tree_1 (&init,
kono
parents: 68
diff changeset
951 c_omp_check_loop_iv_r, &data, &pset, lh);
kono
parents: 68
diff changeset
952 }
kono
parents: 68
diff changeset
953 if (cond)
kono
parents: 68
diff changeset
954 {
kono
parents: 68
diff changeset
955 gcc_assert (COMPARISON_CLASS_P (cond));
kono
parents: 68
diff changeset
956 data.expr_loc = EXPR_LOCATION (init);
kono
parents: 68
diff changeset
957 data.kind = 1;
kono
parents: 68
diff changeset
958 if (TREE_OPERAND (cond, 0) == decl)
kono
parents: 68
diff changeset
959 walk_tree_1 (&TREE_OPERAND (cond, 1),
kono
parents: 68
diff changeset
960 c_omp_check_loop_iv_r, &data, &pset, lh);
kono
parents: 68
diff changeset
961 else
kono
parents: 68
diff changeset
962 walk_tree_1 (&TREE_OPERAND (cond, 0),
kono
parents: 68
diff changeset
963 c_omp_check_loop_iv_r, &data, &pset, lh);
kono
parents: 68
diff changeset
964 }
kono
parents: 68
diff changeset
965 return !data.fail;
kono
parents: 68
diff changeset
966 }
kono
parents: 68
diff changeset
967
kono
parents: 68
diff changeset
968 /* This function splits clauses for OpenACC combined loop
kono
parents: 68
diff changeset
969 constructs. OpenACC combined loop constructs are:
kono
parents: 68
diff changeset
970 #pragma acc kernels loop
kono
parents: 68
diff changeset
971 #pragma acc parallel loop */
kono
parents: 68
diff changeset
972
kono
parents: 68
diff changeset
973 tree
kono
parents: 68
diff changeset
974 c_oacc_split_loop_clauses (tree clauses, tree *not_loop_clauses,
kono
parents: 68
diff changeset
975 bool is_parallel)
kono
parents: 68
diff changeset
976 {
kono
parents: 68
diff changeset
977 tree next, loop_clauses, nc;
kono
parents: 68
diff changeset
978
kono
parents: 68
diff changeset
979 loop_clauses = *not_loop_clauses = NULL_TREE;
kono
parents: 68
diff changeset
980 for (; clauses ; clauses = next)
kono
parents: 68
diff changeset
981 {
kono
parents: 68
diff changeset
982 next = OMP_CLAUSE_CHAIN (clauses);
kono
parents: 68
diff changeset
983
kono
parents: 68
diff changeset
984 switch (OMP_CLAUSE_CODE (clauses))
kono
parents: 68
diff changeset
985 {
kono
parents: 68
diff changeset
986 /* Loop clauses. */
kono
parents: 68
diff changeset
987 case OMP_CLAUSE_COLLAPSE:
kono
parents: 68
diff changeset
988 case OMP_CLAUSE_TILE:
kono
parents: 68
diff changeset
989 case OMP_CLAUSE_GANG:
kono
parents: 68
diff changeset
990 case OMP_CLAUSE_WORKER:
kono
parents: 68
diff changeset
991 case OMP_CLAUSE_VECTOR:
kono
parents: 68
diff changeset
992 case OMP_CLAUSE_AUTO:
kono
parents: 68
diff changeset
993 case OMP_CLAUSE_SEQ:
kono
parents: 68
diff changeset
994 case OMP_CLAUSE_INDEPENDENT:
kono
parents: 68
diff changeset
995 case OMP_CLAUSE_PRIVATE:
kono
parents: 68
diff changeset
996 OMP_CLAUSE_CHAIN (clauses) = loop_clauses;
kono
parents: 68
diff changeset
997 loop_clauses = clauses;
kono
parents: 68
diff changeset
998 break;
kono
parents: 68
diff changeset
999
kono
parents: 68
diff changeset
1000 /* Reductions must be duplicated on both constructs. */
kono
parents: 68
diff changeset
1001 case OMP_CLAUSE_REDUCTION:
kono
parents: 68
diff changeset
1002 if (is_parallel)
kono
parents: 68
diff changeset
1003 {
kono
parents: 68
diff changeset
1004 nc = build_omp_clause (OMP_CLAUSE_LOCATION (clauses),
kono
parents: 68
diff changeset
1005 OMP_CLAUSE_REDUCTION);
kono
parents: 68
diff changeset
1006 OMP_CLAUSE_DECL (nc) = OMP_CLAUSE_DECL (clauses);
kono
parents: 68
diff changeset
1007 OMP_CLAUSE_REDUCTION_CODE (nc)
kono
parents: 68
diff changeset
1008 = OMP_CLAUSE_REDUCTION_CODE (clauses);
kono
parents: 68
diff changeset
1009 OMP_CLAUSE_CHAIN (nc) = *not_loop_clauses;
kono
parents: 68
diff changeset
1010 *not_loop_clauses = nc;
kono
parents: 68
diff changeset
1011 }
kono
parents: 68
diff changeset
1012
kono
parents: 68
diff changeset
1013 OMP_CLAUSE_CHAIN (clauses) = loop_clauses;
kono
parents: 68
diff changeset
1014 loop_clauses = clauses;
kono
parents: 68
diff changeset
1015 break;
kono
parents: 68
diff changeset
1016
kono
parents: 68
diff changeset
1017 /* Parallel/kernels clauses. */
kono
parents: 68
diff changeset
1018 default:
kono
parents: 68
diff changeset
1019 OMP_CLAUSE_CHAIN (clauses) = *not_loop_clauses;
kono
parents: 68
diff changeset
1020 *not_loop_clauses = clauses;
kono
parents: 68
diff changeset
1021 break;
kono
parents: 68
diff changeset
1022 }
kono
parents: 68
diff changeset
1023 }
kono
parents: 68
diff changeset
1024
kono
parents: 68
diff changeset
1025 return loop_clauses;
kono
parents: 68
diff changeset
1026 }
kono
parents: 68
diff changeset
1027
kono
parents: 68
diff changeset
1028 /* This function attempts to split or duplicate clauses for OpenMP
kono
parents: 68
diff changeset
1029 combined/composite constructs. Right now there are 21 different
kono
parents: 68
diff changeset
1030 constructs. CODE is the innermost construct in the combined construct,
kono
parents: 68
diff changeset
1031 and MASK allows to determine which constructs are combined together,
kono
parents: 68
diff changeset
1032 as every construct has at least one clause that no other construct
kono
parents: 68
diff changeset
1033 has (except for OMP_SECTIONS, but that can be only combined with parallel).
kono
parents: 68
diff changeset
1034 OpenMP combined/composite constructs are:
kono
parents: 68
diff changeset
1035 #pragma omp distribute parallel for
kono
parents: 68
diff changeset
1036 #pragma omp distribute parallel for simd
kono
parents: 68
diff changeset
1037 #pragma omp distribute simd
kono
parents: 68
diff changeset
1038 #pragma omp for simd
kono
parents: 68
diff changeset
1039 #pragma omp parallel for
kono
parents: 68
diff changeset
1040 #pragma omp parallel for simd
kono
parents: 68
diff changeset
1041 #pragma omp parallel sections
kono
parents: 68
diff changeset
1042 #pragma omp target parallel
kono
parents: 68
diff changeset
1043 #pragma omp target parallel for
kono
parents: 68
diff changeset
1044 #pragma omp target parallel for simd
kono
parents: 68
diff changeset
1045 #pragma omp target teams
kono
parents: 68
diff changeset
1046 #pragma omp target teams distribute
kono
parents: 68
diff changeset
1047 #pragma omp target teams distribute parallel for
kono
parents: 68
diff changeset
1048 #pragma omp target teams distribute parallel for simd
kono
parents: 68
diff changeset
1049 #pragma omp target teams distribute simd
kono
parents: 68
diff changeset
1050 #pragma omp target simd
kono
parents: 68
diff changeset
1051 #pragma omp taskloop simd
kono
parents: 68
diff changeset
1052 #pragma omp teams distribute
kono
parents: 68
diff changeset
1053 #pragma omp teams distribute parallel for
kono
parents: 68
diff changeset
1054 #pragma omp teams distribute parallel for simd
kono
parents: 68
diff changeset
1055 #pragma omp teams distribute simd */
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1056
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1057 void
111
kono
parents: 68
diff changeset
1058 c_omp_split_clauses (location_t loc, enum tree_code code,
kono
parents: 68
diff changeset
1059 omp_clause_mask mask, tree clauses, tree *cclauses)
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1060 {
111
kono
parents: 68
diff changeset
1061 tree next, c;
kono
parents: 68
diff changeset
1062 enum c_omp_clause_split s;
kono
parents: 68
diff changeset
1063 int i;
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1064
111
kono
parents: 68
diff changeset
1065 for (i = 0; i < C_OMP_CLAUSE_SPLIT_COUNT; i++)
kono
parents: 68
diff changeset
1066 cclauses[i] = NULL;
kono
parents: 68
diff changeset
1067 /* Add implicit nowait clause on
kono
parents: 68
diff changeset
1068 #pragma omp parallel {for,for simd,sections}. */
kono
parents: 68
diff changeset
1069 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS)) != 0)
kono
parents: 68
diff changeset
1070 switch (code)
kono
parents: 68
diff changeset
1071 {
kono
parents: 68
diff changeset
1072 case OMP_FOR:
kono
parents: 68
diff changeset
1073 case OMP_SIMD:
kono
parents: 68
diff changeset
1074 cclauses[C_OMP_CLAUSE_SPLIT_FOR]
kono
parents: 68
diff changeset
1075 = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
kono
parents: 68
diff changeset
1076 break;
kono
parents: 68
diff changeset
1077 case OMP_SECTIONS:
kono
parents: 68
diff changeset
1078 cclauses[C_OMP_CLAUSE_SPLIT_SECTIONS]
kono
parents: 68
diff changeset
1079 = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
kono
parents: 68
diff changeset
1080 break;
kono
parents: 68
diff changeset
1081 default:
kono
parents: 68
diff changeset
1082 break;
kono
parents: 68
diff changeset
1083 }
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1084
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1085 for (; clauses ; clauses = next)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1086 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1087 next = OMP_CLAUSE_CHAIN (clauses);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1088
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1089 switch (OMP_CLAUSE_CODE (clauses))
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1090 {
111
kono
parents: 68
diff changeset
1091 /* First the clauses that are unique to some constructs. */
kono
parents: 68
diff changeset
1092 case OMP_CLAUSE_DEVICE:
kono
parents: 68
diff changeset
1093 case OMP_CLAUSE_MAP:
kono
parents: 68
diff changeset
1094 case OMP_CLAUSE_IS_DEVICE_PTR:
kono
parents: 68
diff changeset
1095 case OMP_CLAUSE_DEFAULTMAP:
kono
parents: 68
diff changeset
1096 case OMP_CLAUSE_DEPEND:
kono
parents: 68
diff changeset
1097 s = C_OMP_CLAUSE_SPLIT_TARGET;
kono
parents: 68
diff changeset
1098 break;
kono
parents: 68
diff changeset
1099 case OMP_CLAUSE_NUM_TEAMS:
kono
parents: 68
diff changeset
1100 case OMP_CLAUSE_THREAD_LIMIT:
kono
parents: 68
diff changeset
1101 s = C_OMP_CLAUSE_SPLIT_TEAMS;
kono
parents: 68
diff changeset
1102 break;
kono
parents: 68
diff changeset
1103 case OMP_CLAUSE_DIST_SCHEDULE:
kono
parents: 68
diff changeset
1104 s = C_OMP_CLAUSE_SPLIT_DISTRIBUTE;
kono
parents: 68
diff changeset
1105 break;
kono
parents: 68
diff changeset
1106 case OMP_CLAUSE_COPYIN:
kono
parents: 68
diff changeset
1107 case OMP_CLAUSE_NUM_THREADS:
kono
parents: 68
diff changeset
1108 case OMP_CLAUSE_PROC_BIND:
kono
parents: 68
diff changeset
1109 s = C_OMP_CLAUSE_SPLIT_PARALLEL;
kono
parents: 68
diff changeset
1110 break;
kono
parents: 68
diff changeset
1111 case OMP_CLAUSE_ORDERED:
kono
parents: 68
diff changeset
1112 s = C_OMP_CLAUSE_SPLIT_FOR;
kono
parents: 68
diff changeset
1113 break;
kono
parents: 68
diff changeset
1114 case OMP_CLAUSE_SCHEDULE:
kono
parents: 68
diff changeset
1115 s = C_OMP_CLAUSE_SPLIT_FOR;
kono
parents: 68
diff changeset
1116 if (code != OMP_SIMD)
kono
parents: 68
diff changeset
1117 OMP_CLAUSE_SCHEDULE_SIMD (clauses) = 0;
kono
parents: 68
diff changeset
1118 break;
kono
parents: 68
diff changeset
1119 case OMP_CLAUSE_SAFELEN:
kono
parents: 68
diff changeset
1120 case OMP_CLAUSE_SIMDLEN:
kono
parents: 68
diff changeset
1121 case OMP_CLAUSE_ALIGNED:
kono
parents: 68
diff changeset
1122 s = C_OMP_CLAUSE_SPLIT_SIMD;
kono
parents: 68
diff changeset
1123 break;
kono
parents: 68
diff changeset
1124 case OMP_CLAUSE_GRAINSIZE:
kono
parents: 68
diff changeset
1125 case OMP_CLAUSE_NUM_TASKS:
kono
parents: 68
diff changeset
1126 case OMP_CLAUSE_FINAL:
kono
parents: 68
diff changeset
1127 case OMP_CLAUSE_UNTIED:
kono
parents: 68
diff changeset
1128 case OMP_CLAUSE_MERGEABLE:
kono
parents: 68
diff changeset
1129 case OMP_CLAUSE_NOGROUP:
kono
parents: 68
diff changeset
1130 case OMP_CLAUSE_PRIORITY:
kono
parents: 68
diff changeset
1131 s = C_OMP_CLAUSE_SPLIT_TASKLOOP;
kono
parents: 68
diff changeset
1132 break;
kono
parents: 68
diff changeset
1133 /* Duplicate this to all of taskloop, distribute, for and simd. */
kono
parents: 68
diff changeset
1134 case OMP_CLAUSE_COLLAPSE:
kono
parents: 68
diff changeset
1135 if (code == OMP_SIMD)
kono
parents: 68
diff changeset
1136 {
kono
parents: 68
diff changeset
1137 if ((mask & ((OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE)
kono
parents: 68
diff changeset
1138 | (OMP_CLAUSE_MASK_1
kono
parents: 68
diff changeset
1139 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)
kono
parents: 68
diff changeset
1140 | (OMP_CLAUSE_MASK_1
kono
parents: 68
diff changeset
1141 << PRAGMA_OMP_CLAUSE_NOGROUP))) != 0)
kono
parents: 68
diff changeset
1142 {
kono
parents: 68
diff changeset
1143 c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses),
kono
parents: 68
diff changeset
1144 OMP_CLAUSE_COLLAPSE);
kono
parents: 68
diff changeset
1145 OMP_CLAUSE_COLLAPSE_EXPR (c)
kono
parents: 68
diff changeset
1146 = OMP_CLAUSE_COLLAPSE_EXPR (clauses);
kono
parents: 68
diff changeset
1147 OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_SIMD];
kono
parents: 68
diff changeset
1148 cclauses[C_OMP_CLAUSE_SPLIT_SIMD] = c;
kono
parents: 68
diff changeset
1149 }
kono
parents: 68
diff changeset
1150 else
kono
parents: 68
diff changeset
1151 {
kono
parents: 68
diff changeset
1152 /* This must be #pragma omp target simd */
kono
parents: 68
diff changeset
1153 s = C_OMP_CLAUSE_SPLIT_SIMD;
kono
parents: 68
diff changeset
1154 break;
kono
parents: 68
diff changeset
1155 }
kono
parents: 68
diff changeset
1156 }
kono
parents: 68
diff changeset
1157 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE)) != 0)
kono
parents: 68
diff changeset
1158 {
kono
parents: 68
diff changeset
1159 if ((mask & (OMP_CLAUSE_MASK_1
kono
parents: 68
diff changeset
1160 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) != 0)
kono
parents: 68
diff changeset
1161 {
kono
parents: 68
diff changeset
1162 c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses),
kono
parents: 68
diff changeset
1163 OMP_CLAUSE_COLLAPSE);
kono
parents: 68
diff changeset
1164 OMP_CLAUSE_COLLAPSE_EXPR (c)
kono
parents: 68
diff changeset
1165 = OMP_CLAUSE_COLLAPSE_EXPR (clauses);
kono
parents: 68
diff changeset
1166 OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
kono
parents: 68
diff changeset
1167 cclauses[C_OMP_CLAUSE_SPLIT_FOR] = c;
kono
parents: 68
diff changeset
1168 s = C_OMP_CLAUSE_SPLIT_DISTRIBUTE;
kono
parents: 68
diff changeset
1169 }
kono
parents: 68
diff changeset
1170 else
kono
parents: 68
diff changeset
1171 s = C_OMP_CLAUSE_SPLIT_FOR;
kono
parents: 68
diff changeset
1172 }
kono
parents: 68
diff changeset
1173 else if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP))
kono
parents: 68
diff changeset
1174 != 0)
kono
parents: 68
diff changeset
1175 s = C_OMP_CLAUSE_SPLIT_TASKLOOP;
kono
parents: 68
diff changeset
1176 else
kono
parents: 68
diff changeset
1177 s = C_OMP_CLAUSE_SPLIT_DISTRIBUTE;
kono
parents: 68
diff changeset
1178 break;
kono
parents: 68
diff changeset
1179 /* Private clause is supported on all constructs,
kono
parents: 68
diff changeset
1180 it is enough to put it on the innermost one. For
kono
parents: 68
diff changeset
1181 #pragma omp {for,sections} put it on parallel though,
kono
parents: 68
diff changeset
1182 as that's what we did for OpenMP 3.1. */
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1183 case OMP_CLAUSE_PRIVATE:
111
kono
parents: 68
diff changeset
1184 switch (code)
kono
parents: 68
diff changeset
1185 {
kono
parents: 68
diff changeset
1186 case OMP_SIMD: s = C_OMP_CLAUSE_SPLIT_SIMD; break;
kono
parents: 68
diff changeset
1187 case OMP_FOR: case OMP_SECTIONS:
kono
parents: 68
diff changeset
1188 case OMP_PARALLEL: s = C_OMP_CLAUSE_SPLIT_PARALLEL; break;
kono
parents: 68
diff changeset
1189 case OMP_DISTRIBUTE: s = C_OMP_CLAUSE_SPLIT_DISTRIBUTE; break;
kono
parents: 68
diff changeset
1190 case OMP_TEAMS: s = C_OMP_CLAUSE_SPLIT_TEAMS; break;
kono
parents: 68
diff changeset
1191 default: gcc_unreachable ();
kono
parents: 68
diff changeset
1192 }
kono
parents: 68
diff changeset
1193 break;
kono
parents: 68
diff changeset
1194 /* Firstprivate clause is supported on all constructs but
kono
parents: 68
diff changeset
1195 simd. Put it on the outermost of those and duplicate on teams
kono
parents: 68
diff changeset
1196 and parallel. */
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1197 case OMP_CLAUSE_FIRSTPRIVATE:
111
kono
parents: 68
diff changeset
1198 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP))
kono
parents: 68
diff changeset
1199 != 0)
kono
parents: 68
diff changeset
1200 {
kono
parents: 68
diff changeset
1201 if (code == OMP_SIMD
kono
parents: 68
diff changeset
1202 && (mask & ((OMP_CLAUSE_MASK_1
kono
parents: 68
diff changeset
1203 << PRAGMA_OMP_CLAUSE_NUM_THREADS)
kono
parents: 68
diff changeset
1204 | (OMP_CLAUSE_MASK_1
kono
parents: 68
diff changeset
1205 << PRAGMA_OMP_CLAUSE_NUM_TEAMS))) == 0)
kono
parents: 68
diff changeset
1206 {
kono
parents: 68
diff changeset
1207 /* This must be #pragma omp target simd. */
kono
parents: 68
diff changeset
1208 s = C_OMP_CLAUSE_SPLIT_TARGET;
kono
parents: 68
diff changeset
1209 break;
kono
parents: 68
diff changeset
1210 }
kono
parents: 68
diff changeset
1211 c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses),
kono
parents: 68
diff changeset
1212 OMP_CLAUSE_FIRSTPRIVATE);
kono
parents: 68
diff changeset
1213 OMP_CLAUSE_DECL (c) = OMP_CLAUSE_DECL (clauses);
kono
parents: 68
diff changeset
1214 OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_TARGET];
kono
parents: 68
diff changeset
1215 cclauses[C_OMP_CLAUSE_SPLIT_TARGET] = c;
kono
parents: 68
diff changeset
1216 }
kono
parents: 68
diff changeset
1217 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS))
kono
parents: 68
diff changeset
1218 != 0)
kono
parents: 68
diff changeset
1219 {
kono
parents: 68
diff changeset
1220 if ((mask & ((OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS)
kono
parents: 68
diff changeset
1221 | (OMP_CLAUSE_MASK_1
kono
parents: 68
diff changeset
1222 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE))) != 0)
kono
parents: 68
diff changeset
1223 {
kono
parents: 68
diff changeset
1224 c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses),
kono
parents: 68
diff changeset
1225 OMP_CLAUSE_FIRSTPRIVATE);
kono
parents: 68
diff changeset
1226 OMP_CLAUSE_DECL (c) = OMP_CLAUSE_DECL (clauses);
kono
parents: 68
diff changeset
1227 OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL];
kono
parents: 68
diff changeset
1228 cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL] = c;
kono
parents: 68
diff changeset
1229 if ((mask & (OMP_CLAUSE_MASK_1
kono
parents: 68
diff changeset
1230 << PRAGMA_OMP_CLAUSE_NUM_TEAMS)) != 0)
kono
parents: 68
diff changeset
1231 s = C_OMP_CLAUSE_SPLIT_TEAMS;
kono
parents: 68
diff changeset
1232 else
kono
parents: 68
diff changeset
1233 s = C_OMP_CLAUSE_SPLIT_DISTRIBUTE;
kono
parents: 68
diff changeset
1234 }
kono
parents: 68
diff changeset
1235 else
kono
parents: 68
diff changeset
1236 /* This must be
kono
parents: 68
diff changeset
1237 #pragma omp parallel{, for{, simd}, sections}
kono
parents: 68
diff changeset
1238 or
kono
parents: 68
diff changeset
1239 #pragma omp target parallel. */
kono
parents: 68
diff changeset
1240 s = C_OMP_CLAUSE_SPLIT_PARALLEL;
kono
parents: 68
diff changeset
1241 }
kono
parents: 68
diff changeset
1242 else if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS))
kono
parents: 68
diff changeset
1243 != 0)
kono
parents: 68
diff changeset
1244 {
kono
parents: 68
diff changeset
1245 /* This must be one of
kono
parents: 68
diff changeset
1246 #pragma omp {,target }teams distribute
kono
parents: 68
diff changeset
1247 #pragma omp target teams
kono
parents: 68
diff changeset
1248 #pragma omp {,target }teams distribute simd. */
kono
parents: 68
diff changeset
1249 gcc_assert (code == OMP_DISTRIBUTE
kono
parents: 68
diff changeset
1250 || code == OMP_TEAMS
kono
parents: 68
diff changeset
1251 || code == OMP_SIMD);
kono
parents: 68
diff changeset
1252 s = C_OMP_CLAUSE_SPLIT_TEAMS;
kono
parents: 68
diff changeset
1253 }
kono
parents: 68
diff changeset
1254 else if ((mask & (OMP_CLAUSE_MASK_1
kono
parents: 68
diff changeset
1255 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) != 0)
kono
parents: 68
diff changeset
1256 {
kono
parents: 68
diff changeset
1257 /* This must be #pragma omp distribute simd. */
kono
parents: 68
diff changeset
1258 gcc_assert (code == OMP_SIMD);
kono
parents: 68
diff changeset
1259 s = C_OMP_CLAUSE_SPLIT_DISTRIBUTE;
kono
parents: 68
diff changeset
1260 }
kono
parents: 68
diff changeset
1261 else if ((mask & (OMP_CLAUSE_MASK_1
kono
parents: 68
diff changeset
1262 << PRAGMA_OMP_CLAUSE_NOGROUP)) != 0)
kono
parents: 68
diff changeset
1263 {
kono
parents: 68
diff changeset
1264 /* This must be #pragma omp taskloop simd. */
kono
parents: 68
diff changeset
1265 gcc_assert (code == OMP_SIMD);
kono
parents: 68
diff changeset
1266 s = C_OMP_CLAUSE_SPLIT_TASKLOOP;
kono
parents: 68
diff changeset
1267 }
kono
parents: 68
diff changeset
1268 else
kono
parents: 68
diff changeset
1269 {
kono
parents: 68
diff changeset
1270 /* This must be #pragma omp for simd. */
kono
parents: 68
diff changeset
1271 gcc_assert (code == OMP_SIMD);
kono
parents: 68
diff changeset
1272 s = C_OMP_CLAUSE_SPLIT_FOR;
kono
parents: 68
diff changeset
1273 }
kono
parents: 68
diff changeset
1274 break;
kono
parents: 68
diff changeset
1275 /* Lastprivate is allowed on distribute, for, sections and simd. In
kono
parents: 68
diff changeset
1276 parallel {for{, simd},sections} we actually want to put it on
kono
parents: 68
diff changeset
1277 parallel rather than for or sections. */
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1278 case OMP_CLAUSE_LASTPRIVATE:
111
kono
parents: 68
diff changeset
1279 if (code == OMP_DISTRIBUTE)
kono
parents: 68
diff changeset
1280 {
kono
parents: 68
diff changeset
1281 s = C_OMP_CLAUSE_SPLIT_DISTRIBUTE;
kono
parents: 68
diff changeset
1282 break;
kono
parents: 68
diff changeset
1283 }
kono
parents: 68
diff changeset
1284 if ((mask & (OMP_CLAUSE_MASK_1
kono
parents: 68
diff changeset
1285 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) != 0)
kono
parents: 68
diff changeset
1286 {
kono
parents: 68
diff changeset
1287 c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses),
kono
parents: 68
diff changeset
1288 OMP_CLAUSE_LASTPRIVATE);
kono
parents: 68
diff changeset
1289 OMP_CLAUSE_DECL (c) = OMP_CLAUSE_DECL (clauses);
kono
parents: 68
diff changeset
1290 OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE];
kono
parents: 68
diff changeset
1291 cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE] = c;
kono
parents: 68
diff changeset
1292 }
kono
parents: 68
diff changeset
1293 if (code == OMP_FOR || code == OMP_SECTIONS)
kono
parents: 68
diff changeset
1294 {
kono
parents: 68
diff changeset
1295 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS))
kono
parents: 68
diff changeset
1296 != 0)
kono
parents: 68
diff changeset
1297 s = C_OMP_CLAUSE_SPLIT_PARALLEL;
kono
parents: 68
diff changeset
1298 else
kono
parents: 68
diff changeset
1299 s = C_OMP_CLAUSE_SPLIT_FOR;
kono
parents: 68
diff changeset
1300 break;
kono
parents: 68
diff changeset
1301 }
kono
parents: 68
diff changeset
1302 gcc_assert (code == OMP_SIMD);
kono
parents: 68
diff changeset
1303 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE)) != 0)
kono
parents: 68
diff changeset
1304 {
kono
parents: 68
diff changeset
1305 c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses),
kono
parents: 68
diff changeset
1306 OMP_CLAUSE_LASTPRIVATE);
kono
parents: 68
diff changeset
1307 OMP_CLAUSE_DECL (c) = OMP_CLAUSE_DECL (clauses);
kono
parents: 68
diff changeset
1308 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS))
kono
parents: 68
diff changeset
1309 != 0)
kono
parents: 68
diff changeset
1310 s = C_OMP_CLAUSE_SPLIT_PARALLEL;
kono
parents: 68
diff changeset
1311 else
kono
parents: 68
diff changeset
1312 s = C_OMP_CLAUSE_SPLIT_FOR;
kono
parents: 68
diff changeset
1313 OMP_CLAUSE_CHAIN (c) = cclauses[s];
kono
parents: 68
diff changeset
1314 cclauses[s] = c;
kono
parents: 68
diff changeset
1315 }
kono
parents: 68
diff changeset
1316 s = C_OMP_CLAUSE_SPLIT_SIMD;
kono
parents: 68
diff changeset
1317 break;
kono
parents: 68
diff changeset
1318 /* Shared and default clauses are allowed on parallel, teams and
kono
parents: 68
diff changeset
1319 taskloop. */
kono
parents: 68
diff changeset
1320 case OMP_CLAUSE_SHARED:
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1321 case OMP_CLAUSE_DEFAULT:
111
kono
parents: 68
diff changeset
1322 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP))
kono
parents: 68
diff changeset
1323 != 0)
kono
parents: 68
diff changeset
1324 {
kono
parents: 68
diff changeset
1325 s = C_OMP_CLAUSE_SPLIT_TASKLOOP;
kono
parents: 68
diff changeset
1326 break;
kono
parents: 68
diff changeset
1327 }
kono
parents: 68
diff changeset
1328 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS))
kono
parents: 68
diff changeset
1329 != 0)
kono
parents: 68
diff changeset
1330 {
kono
parents: 68
diff changeset
1331 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS))
kono
parents: 68
diff changeset
1332 == 0)
kono
parents: 68
diff changeset
1333 {
kono
parents: 68
diff changeset
1334 s = C_OMP_CLAUSE_SPLIT_TEAMS;
kono
parents: 68
diff changeset
1335 break;
kono
parents: 68
diff changeset
1336 }
kono
parents: 68
diff changeset
1337 c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses),
kono
parents: 68
diff changeset
1338 OMP_CLAUSE_CODE (clauses));
kono
parents: 68
diff changeset
1339 if (OMP_CLAUSE_CODE (clauses) == OMP_CLAUSE_SHARED)
kono
parents: 68
diff changeset
1340 OMP_CLAUSE_DECL (c) = OMP_CLAUSE_DECL (clauses);
kono
parents: 68
diff changeset
1341 else
kono
parents: 68
diff changeset
1342 OMP_CLAUSE_DEFAULT_KIND (c)
kono
parents: 68
diff changeset
1343 = OMP_CLAUSE_DEFAULT_KIND (clauses);
kono
parents: 68
diff changeset
1344 OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS];
kono
parents: 68
diff changeset
1345 cclauses[C_OMP_CLAUSE_SPLIT_TEAMS] = c;
kono
parents: 68
diff changeset
1346 }
kono
parents: 68
diff changeset
1347 s = C_OMP_CLAUSE_SPLIT_PARALLEL;
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1348 break;
111
kono
parents: 68
diff changeset
1349 /* Reduction is allowed on simd, for, parallel, sections and teams.
kono
parents: 68
diff changeset
1350 Duplicate it on all of them, but omit on for or sections if
kono
parents: 68
diff changeset
1351 parallel is present. */
kono
parents: 68
diff changeset
1352 case OMP_CLAUSE_REDUCTION:
kono
parents: 68
diff changeset
1353 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE)) != 0)
kono
parents: 68
diff changeset
1354 {
kono
parents: 68
diff changeset
1355 if (code == OMP_SIMD)
kono
parents: 68
diff changeset
1356 {
kono
parents: 68
diff changeset
1357 c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses),
kono
parents: 68
diff changeset
1358 OMP_CLAUSE_REDUCTION);
kono
parents: 68
diff changeset
1359 OMP_CLAUSE_DECL (c) = OMP_CLAUSE_DECL (clauses);
kono
parents: 68
diff changeset
1360 OMP_CLAUSE_REDUCTION_CODE (c)
kono
parents: 68
diff changeset
1361 = OMP_CLAUSE_REDUCTION_CODE (clauses);
kono
parents: 68
diff changeset
1362 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)
kono
parents: 68
diff changeset
1363 = OMP_CLAUSE_REDUCTION_PLACEHOLDER (clauses);
kono
parents: 68
diff changeset
1364 OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c)
kono
parents: 68
diff changeset
1365 = OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clauses);
kono
parents: 68
diff changeset
1366 OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_SIMD];
kono
parents: 68
diff changeset
1367 cclauses[C_OMP_CLAUSE_SPLIT_SIMD] = c;
kono
parents: 68
diff changeset
1368 }
kono
parents: 68
diff changeset
1369 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS))
kono
parents: 68
diff changeset
1370 != 0)
kono
parents: 68
diff changeset
1371 {
kono
parents: 68
diff changeset
1372 c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses),
kono
parents: 68
diff changeset
1373 OMP_CLAUSE_REDUCTION);
kono
parents: 68
diff changeset
1374 OMP_CLAUSE_DECL (c) = OMP_CLAUSE_DECL (clauses);
kono
parents: 68
diff changeset
1375 OMP_CLAUSE_REDUCTION_CODE (c)
kono
parents: 68
diff changeset
1376 = OMP_CLAUSE_REDUCTION_CODE (clauses);
kono
parents: 68
diff changeset
1377 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)
kono
parents: 68
diff changeset
1378 = OMP_CLAUSE_REDUCTION_PLACEHOLDER (clauses);
kono
parents: 68
diff changeset
1379 OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c)
kono
parents: 68
diff changeset
1380 = OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (clauses);
kono
parents: 68
diff changeset
1381 OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL];
kono
parents: 68
diff changeset
1382 cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL] = c;
kono
parents: 68
diff changeset
1383 s = C_OMP_CLAUSE_SPLIT_TEAMS;
kono
parents: 68
diff changeset
1384 }
kono
parents: 68
diff changeset
1385 else if ((mask & (OMP_CLAUSE_MASK_1
kono
parents: 68
diff changeset
1386 << PRAGMA_OMP_CLAUSE_NUM_THREADS)) != 0)
kono
parents: 68
diff changeset
1387 s = C_OMP_CLAUSE_SPLIT_PARALLEL;
kono
parents: 68
diff changeset
1388 else
kono
parents: 68
diff changeset
1389 s = C_OMP_CLAUSE_SPLIT_FOR;
kono
parents: 68
diff changeset
1390 }
kono
parents: 68
diff changeset
1391 else if (code == OMP_SECTIONS || code == OMP_PARALLEL)
kono
parents: 68
diff changeset
1392 s = C_OMP_CLAUSE_SPLIT_PARALLEL;
kono
parents: 68
diff changeset
1393 else if (code == OMP_SIMD)
kono
parents: 68
diff changeset
1394 s = C_OMP_CLAUSE_SPLIT_SIMD;
kono
parents: 68
diff changeset
1395 else
kono
parents: 68
diff changeset
1396 s = C_OMP_CLAUSE_SPLIT_TEAMS;
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1397 break;
111
kono
parents: 68
diff changeset
1398 case OMP_CLAUSE_IF:
kono
parents: 68
diff changeset
1399 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP))
kono
parents: 68
diff changeset
1400 != 0)
kono
parents: 68
diff changeset
1401 s = C_OMP_CLAUSE_SPLIT_TASKLOOP;
kono
parents: 68
diff changeset
1402 else if ((mask & (OMP_CLAUSE_MASK_1
kono
parents: 68
diff changeset
1403 << PRAGMA_OMP_CLAUSE_NUM_THREADS)) != 0)
kono
parents: 68
diff changeset
1404 {
kono
parents: 68
diff changeset
1405 if ((mask & (OMP_CLAUSE_MASK_1
kono
parents: 68
diff changeset
1406 << PRAGMA_OMP_CLAUSE_MAP)) != 0)
kono
parents: 68
diff changeset
1407 {
kono
parents: 68
diff changeset
1408 if (OMP_CLAUSE_IF_MODIFIER (clauses) == OMP_PARALLEL)
kono
parents: 68
diff changeset
1409 s = C_OMP_CLAUSE_SPLIT_PARALLEL;
kono
parents: 68
diff changeset
1410 else if (OMP_CLAUSE_IF_MODIFIER (clauses) == OMP_TARGET)
kono
parents: 68
diff changeset
1411 s = C_OMP_CLAUSE_SPLIT_TARGET;
kono
parents: 68
diff changeset
1412 else if (OMP_CLAUSE_IF_MODIFIER (clauses) == ERROR_MARK)
kono
parents: 68
diff changeset
1413 {
kono
parents: 68
diff changeset
1414 c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses),
kono
parents: 68
diff changeset
1415 OMP_CLAUSE_IF);
kono
parents: 68
diff changeset
1416 OMP_CLAUSE_IF_MODIFIER (c)
kono
parents: 68
diff changeset
1417 = OMP_CLAUSE_IF_MODIFIER (clauses);
kono
parents: 68
diff changeset
1418 OMP_CLAUSE_IF_EXPR (c) = OMP_CLAUSE_IF_EXPR (clauses);
kono
parents: 68
diff changeset
1419 OMP_CLAUSE_CHAIN (c)
kono
parents: 68
diff changeset
1420 = cclauses[C_OMP_CLAUSE_SPLIT_TARGET];
kono
parents: 68
diff changeset
1421 cclauses[C_OMP_CLAUSE_SPLIT_TARGET] = c;
kono
parents: 68
diff changeset
1422 s = C_OMP_CLAUSE_SPLIT_PARALLEL;
kono
parents: 68
diff changeset
1423 }
kono
parents: 68
diff changeset
1424 else
kono
parents: 68
diff changeset
1425 {
kono
parents: 68
diff changeset
1426 error_at (OMP_CLAUSE_LOCATION (clauses),
kono
parents: 68
diff changeset
1427 "expected %<parallel%> or %<target%> %<if%> "
kono
parents: 68
diff changeset
1428 "clause modifier");
kono
parents: 68
diff changeset
1429 continue;
kono
parents: 68
diff changeset
1430 }
kono
parents: 68
diff changeset
1431 }
kono
parents: 68
diff changeset
1432 else
kono
parents: 68
diff changeset
1433 s = C_OMP_CLAUSE_SPLIT_PARALLEL;
kono
parents: 68
diff changeset
1434 }
kono
parents: 68
diff changeset
1435 else
kono
parents: 68
diff changeset
1436 s = C_OMP_CLAUSE_SPLIT_TARGET;
kono
parents: 68
diff changeset
1437 break;
kono
parents: 68
diff changeset
1438 case OMP_CLAUSE_LINEAR:
kono
parents: 68
diff changeset
1439 /* Linear clause is allowed on simd and for. Put it on the
kono
parents: 68
diff changeset
1440 innermost construct. */
kono
parents: 68
diff changeset
1441 if (code == OMP_SIMD)
kono
parents: 68
diff changeset
1442 s = C_OMP_CLAUSE_SPLIT_SIMD;
kono
parents: 68
diff changeset
1443 else
kono
parents: 68
diff changeset
1444 s = C_OMP_CLAUSE_SPLIT_FOR;
kono
parents: 68
diff changeset
1445 break;
kono
parents: 68
diff changeset
1446 case OMP_CLAUSE_NOWAIT:
kono
parents: 68
diff changeset
1447 /* Nowait clause is allowed on target, for and sections, but
kono
parents: 68
diff changeset
1448 is not allowed on parallel for or parallel sections. Therefore,
kono
parents: 68
diff changeset
1449 put it on target construct if present, because that can only
kono
parents: 68
diff changeset
1450 be combined with parallel for{, simd} and not with for{, simd},
kono
parents: 68
diff changeset
1451 otherwise to the worksharing construct. */
kono
parents: 68
diff changeset
1452 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP))
kono
parents: 68
diff changeset
1453 != 0)
kono
parents: 68
diff changeset
1454 s = C_OMP_CLAUSE_SPLIT_TARGET;
kono
parents: 68
diff changeset
1455 else
kono
parents: 68
diff changeset
1456 s = C_OMP_CLAUSE_SPLIT_FOR;
kono
parents: 68
diff changeset
1457 break;
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1458 default:
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1459 gcc_unreachable ();
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1460 }
111
kono
parents: 68
diff changeset
1461 OMP_CLAUSE_CHAIN (clauses) = cclauses[s];
kono
parents: 68
diff changeset
1462 cclauses[s] = clauses;
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1463 }
111
kono
parents: 68
diff changeset
1464
kono
parents: 68
diff changeset
1465 if (!flag_checking)
kono
parents: 68
diff changeset
1466 return;
kono
parents: 68
diff changeset
1467
kono
parents: 68
diff changeset
1468 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)) == 0)
kono
parents: 68
diff changeset
1469 gcc_assert (cclauses[C_OMP_CLAUSE_SPLIT_TARGET] == NULL_TREE);
kono
parents: 68
diff changeset
1470 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS)) == 0)
kono
parents: 68
diff changeset
1471 gcc_assert (cclauses[C_OMP_CLAUSE_SPLIT_TEAMS] == NULL_TREE);
kono
parents: 68
diff changeset
1472 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) == 0)
kono
parents: 68
diff changeset
1473 gcc_assert (cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE] == NULL_TREE);
kono
parents: 68
diff changeset
1474 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS)) == 0)
kono
parents: 68
diff changeset
1475 gcc_assert (cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL] == NULL_TREE);
kono
parents: 68
diff changeset
1476 if ((mask & ((OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE)
kono
parents: 68
diff changeset
1477 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP))) == 0
kono
parents: 68
diff changeset
1478 && code != OMP_SECTIONS)
kono
parents: 68
diff changeset
1479 gcc_assert (cclauses[C_OMP_CLAUSE_SPLIT_FOR] == NULL_TREE);
kono
parents: 68
diff changeset
1480 if (code != OMP_SIMD)
kono
parents: 68
diff changeset
1481 gcc_assert (cclauses[C_OMP_CLAUSE_SPLIT_SIMD] == NULL_TREE);
kono
parents: 68
diff changeset
1482 }
kono
parents: 68
diff changeset
1483
kono
parents: 68
diff changeset
1484
kono
parents: 68
diff changeset
1485 /* qsort callback to compare #pragma omp declare simd clauses. */
kono
parents: 68
diff changeset
1486
kono
parents: 68
diff changeset
1487 static int
kono
parents: 68
diff changeset
1488 c_omp_declare_simd_clause_cmp (const void *p, const void *q)
kono
parents: 68
diff changeset
1489 {
kono
parents: 68
diff changeset
1490 tree a = *(const tree *) p;
kono
parents: 68
diff changeset
1491 tree b = *(const tree *) q;
kono
parents: 68
diff changeset
1492 if (OMP_CLAUSE_CODE (a) != OMP_CLAUSE_CODE (b))
kono
parents: 68
diff changeset
1493 {
kono
parents: 68
diff changeset
1494 if (OMP_CLAUSE_CODE (a) > OMP_CLAUSE_CODE (b))
kono
parents: 68
diff changeset
1495 return -1;
kono
parents: 68
diff changeset
1496 return 1;
kono
parents: 68
diff changeset
1497 }
kono
parents: 68
diff changeset
1498 if (OMP_CLAUSE_CODE (a) != OMP_CLAUSE_SIMDLEN
kono
parents: 68
diff changeset
1499 && OMP_CLAUSE_CODE (a) != OMP_CLAUSE_INBRANCH
kono
parents: 68
diff changeset
1500 && OMP_CLAUSE_CODE (a) != OMP_CLAUSE_NOTINBRANCH)
kono
parents: 68
diff changeset
1501 {
kono
parents: 68
diff changeset
1502 int c = tree_to_shwi (OMP_CLAUSE_DECL (a));
kono
parents: 68
diff changeset
1503 int d = tree_to_shwi (OMP_CLAUSE_DECL (b));
kono
parents: 68
diff changeset
1504 if (c < d)
kono
parents: 68
diff changeset
1505 return 1;
kono
parents: 68
diff changeset
1506 if (c > d)
kono
parents: 68
diff changeset
1507 return -1;
kono
parents: 68
diff changeset
1508 }
kono
parents: 68
diff changeset
1509 return 0;
kono
parents: 68
diff changeset
1510 }
kono
parents: 68
diff changeset
1511
kono
parents: 68
diff changeset
1512 /* Change PARM_DECLs in OMP_CLAUSE_DECL of #pragma omp declare simd
kono
parents: 68
diff changeset
1513 CLAUSES on FNDECL into argument indexes and sort them. */
kono
parents: 68
diff changeset
1514
kono
parents: 68
diff changeset
1515 tree
kono
parents: 68
diff changeset
1516 c_omp_declare_simd_clauses_to_numbers (tree parms, tree clauses)
kono
parents: 68
diff changeset
1517 {
kono
parents: 68
diff changeset
1518 tree c;
kono
parents: 68
diff changeset
1519 vec<tree> clvec = vNULL;
kono
parents: 68
diff changeset
1520
kono
parents: 68
diff changeset
1521 for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
kono
parents: 68
diff changeset
1522 {
kono
parents: 68
diff changeset
1523 if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SIMDLEN
kono
parents: 68
diff changeset
1524 && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_INBRANCH
kono
parents: 68
diff changeset
1525 && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_NOTINBRANCH)
kono
parents: 68
diff changeset
1526 {
kono
parents: 68
diff changeset
1527 tree decl = OMP_CLAUSE_DECL (c);
kono
parents: 68
diff changeset
1528 tree arg;
kono
parents: 68
diff changeset
1529 int idx;
kono
parents: 68
diff changeset
1530 for (arg = parms, idx = 0; arg;
kono
parents: 68
diff changeset
1531 arg = TREE_CHAIN (arg), idx++)
kono
parents: 68
diff changeset
1532 if (arg == decl)
kono
parents: 68
diff changeset
1533 break;
kono
parents: 68
diff changeset
1534 if (arg == NULL_TREE)
kono
parents: 68
diff changeset
1535 {
kono
parents: 68
diff changeset
1536 error_at (OMP_CLAUSE_LOCATION (c),
kono
parents: 68
diff changeset
1537 "%qD is not an function argument", decl);
kono
parents: 68
diff changeset
1538 continue;
kono
parents: 68
diff changeset
1539 }
kono
parents: 68
diff changeset
1540 OMP_CLAUSE_DECL (c) = build_int_cst (integer_type_node, idx);
kono
parents: 68
diff changeset
1541 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
kono
parents: 68
diff changeset
1542 && OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c))
kono
parents: 68
diff changeset
1543 {
kono
parents: 68
diff changeset
1544 decl = OMP_CLAUSE_LINEAR_STEP (c);
kono
parents: 68
diff changeset
1545 for (arg = parms, idx = 0; arg;
kono
parents: 68
diff changeset
1546 arg = TREE_CHAIN (arg), idx++)
kono
parents: 68
diff changeset
1547 if (arg == decl)
kono
parents: 68
diff changeset
1548 break;
kono
parents: 68
diff changeset
1549 if (arg == NULL_TREE)
kono
parents: 68
diff changeset
1550 {
kono
parents: 68
diff changeset
1551 error_at (OMP_CLAUSE_LOCATION (c),
kono
parents: 68
diff changeset
1552 "%qD is not an function argument", decl);
kono
parents: 68
diff changeset
1553 continue;
kono
parents: 68
diff changeset
1554 }
kono
parents: 68
diff changeset
1555 OMP_CLAUSE_LINEAR_STEP (c)
kono
parents: 68
diff changeset
1556 = build_int_cst (integer_type_node, idx);
kono
parents: 68
diff changeset
1557 }
kono
parents: 68
diff changeset
1558 }
kono
parents: 68
diff changeset
1559 clvec.safe_push (c);
kono
parents: 68
diff changeset
1560 }
kono
parents: 68
diff changeset
1561 if (!clvec.is_empty ())
kono
parents: 68
diff changeset
1562 {
kono
parents: 68
diff changeset
1563 unsigned int len = clvec.length (), i;
kono
parents: 68
diff changeset
1564 clvec.qsort (c_omp_declare_simd_clause_cmp);
kono
parents: 68
diff changeset
1565 clauses = clvec[0];
kono
parents: 68
diff changeset
1566 for (i = 0; i < len; i++)
kono
parents: 68
diff changeset
1567 OMP_CLAUSE_CHAIN (clvec[i]) = (i < len - 1) ? clvec[i + 1] : NULL_TREE;
kono
parents: 68
diff changeset
1568 }
kono
parents: 68
diff changeset
1569 else
kono
parents: 68
diff changeset
1570 clauses = NULL_TREE;
kono
parents: 68
diff changeset
1571 clvec.release ();
kono
parents: 68
diff changeset
1572 return clauses;
kono
parents: 68
diff changeset
1573 }
kono
parents: 68
diff changeset
1574
kono
parents: 68
diff changeset
1575 /* Change argument indexes in CLAUSES of FNDECL back to PARM_DECLs. */
kono
parents: 68
diff changeset
1576
kono
parents: 68
diff changeset
1577 void
kono
parents: 68
diff changeset
1578 c_omp_declare_simd_clauses_to_decls (tree fndecl, tree clauses)
kono
parents: 68
diff changeset
1579 {
kono
parents: 68
diff changeset
1580 tree c;
kono
parents: 68
diff changeset
1581
kono
parents: 68
diff changeset
1582 for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
kono
parents: 68
diff changeset
1583 if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SIMDLEN
kono
parents: 68
diff changeset
1584 && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_INBRANCH
kono
parents: 68
diff changeset
1585 && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_NOTINBRANCH)
kono
parents: 68
diff changeset
1586 {
kono
parents: 68
diff changeset
1587 int idx = tree_to_shwi (OMP_CLAUSE_DECL (c)), i;
kono
parents: 68
diff changeset
1588 tree arg;
kono
parents: 68
diff changeset
1589 for (arg = DECL_ARGUMENTS (fndecl), i = 0; arg;
kono
parents: 68
diff changeset
1590 arg = TREE_CHAIN (arg), i++)
kono
parents: 68
diff changeset
1591 if (i == idx)
kono
parents: 68
diff changeset
1592 break;
kono
parents: 68
diff changeset
1593 gcc_assert (arg);
kono
parents: 68
diff changeset
1594 OMP_CLAUSE_DECL (c) = arg;
kono
parents: 68
diff changeset
1595 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
kono
parents: 68
diff changeset
1596 && OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c))
kono
parents: 68
diff changeset
1597 {
kono
parents: 68
diff changeset
1598 idx = tree_to_shwi (OMP_CLAUSE_LINEAR_STEP (c));
kono
parents: 68
diff changeset
1599 for (arg = DECL_ARGUMENTS (fndecl), i = 0; arg;
kono
parents: 68
diff changeset
1600 arg = TREE_CHAIN (arg), i++)
kono
parents: 68
diff changeset
1601 if (i == idx)
kono
parents: 68
diff changeset
1602 break;
kono
parents: 68
diff changeset
1603 gcc_assert (arg);
kono
parents: 68
diff changeset
1604 OMP_CLAUSE_LINEAR_STEP (c) = arg;
kono
parents: 68
diff changeset
1605 }
kono
parents: 68
diff changeset
1606 }
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1607 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1608
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1609 /* True if OpenMP sharing attribute of DECL is predetermined. */
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1610
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1611 enum omp_clause_default_kind
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1612 c_omp_predetermined_sharing (tree decl)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1613 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1614 /* Variables with const-qualified type having no mutable member
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1615 are predetermined shared. */
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1616 if (TREE_READONLY (decl))
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1617 return OMP_CLAUSE_DEFAULT_SHARED;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1618
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1619 return OMP_CLAUSE_DEFAULT_UNSPECIFIED;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1620 }