* Makefile.in (C_COMMON_OBJS): Depend on c-cilkplus.o.
[official-gcc.git] / gcc / c-family / c-cilkplus.c
blob6fa979d652dd2e8be71bc39d3c680dc7997db596
1 /* This file contains routines to construct and validate Cilk Plus
2 constructs within the C and C++ front ends.
4 Copyright (C) 2013 Free Software Foundation, Inc.
5 Contributed by Aldy Hernandez <aldyh@redhat.com>.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it
10 under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
12 any later version.
14 GCC is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tree.h"
27 #include "c-common.h"
29 /* Validate the body of a _Cilk_for construct or a <#pragma simd> for
30 loop.
32 Returns true if there were no errors, false otherwise. */
34 bool
35 c_check_cilk_loop (location_t loc, tree decl)
37 if (TREE_THIS_VOLATILE (decl))
39 error_at (loc, "iteration variable cannot be volatile");
40 return false;
42 return true;
45 /* Validate and emit code for <#pragma simd> clauses. */
47 tree
48 c_finish_cilk_clauses (tree clauses)
50 for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
52 tree prev = clauses;
54 /* If a variable appears in a linear clause it cannot appear in
55 any other OMP clause. */
56 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR)
57 for (tree c2 = clauses; c2; c2 = OMP_CLAUSE_CHAIN (c2))
59 if (c == c2)
60 continue;
61 enum omp_clause_code code = OMP_CLAUSE_CODE (c2);
63 switch (code)
65 case OMP_CLAUSE_LINEAR:
66 case OMP_CLAUSE_PRIVATE:
67 case OMP_CLAUSE_FIRSTPRIVATE:
68 case OMP_CLAUSE_LASTPRIVATE:
69 case OMP_CLAUSE_REDUCTION:
70 break;
72 case OMP_CLAUSE_SAFELEN:
73 goto next;
75 default:
76 gcc_unreachable ();
79 if (OMP_CLAUSE_DECL (c) == OMP_CLAUSE_DECL (c2))
81 error_at (OMP_CLAUSE_LOCATION (c2),
82 "variable appears in more than one clause");
83 inform (OMP_CLAUSE_LOCATION (c),
84 "other clause defined here");
85 // Remove problematic clauses.
86 OMP_CLAUSE_CHAIN (prev) = OMP_CLAUSE_CHAIN (c2);
88 next:
89 prev = c2;
92 return clauses;