aboutsummaryrefslogtreecommitdiff
path: root/gcc/c/c-pragma-simd.c
blob: b47a656e8188395de267c59fcaa601b61dc16305 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* This file is part of the Intel(R) Cilk(TM) Plus support
   This file contains routines to handle Pragma SIMD expression
   handling routines in the C Compiler.
   Copyright (C) 2013  Free Software Foundation, Inc.
   Contributed by Balaji V. Iyer <balaji.v.iyer@intel.com>,
                  Intel Corporation.

   This file is part of GCC.

   GCC is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.

   GCC is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with GCC; see the file COPYING3.  If not see
   <http://www.gnu.org/licenses/>.  */

#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tree.h"
#include "diagnostic-core.h"
#include "cilk.h"

/* This function is passed in as a function pointer to walk_tree.  *TP is
   the current tree pointer, *WALK_SUBTREES is set to 0 by this function if
   recursing into TP's subtrees is unnecessary. *DATA is a bool variable that
   is set to false if an error has occured.  */

static tree
find_invalid_stmts (tree *tp, int *walk_subtrees, void *data)
{
  bool *valid = (bool *) data;
  location_t loc = EXPR_HAS_LOCATION (*tp) ? EXPR_LOCATION (*tp) :
    UNKNOWN_LOCATION;
  if (!tp || !*tp)
    return NULL_TREE;
  else if (TREE_CODE (*tp) == GOTO_EXPR)
    {
      error_at (loc, "goto/break/continue statments are not allowed inside "
		"loops marked with  #pragma simd");
      *valid = false;
      *walk_subtrees = 0;
    }
  else if (TREE_CODE (*tp) == CALL_EXPR)
    {
      tree fndecl = CALL_EXPR_FN (*tp);

      if (TREE_CODE (fndecl) == ADDR_EXPR)
	fndecl = TREE_OPERAND (fndecl, 0);
      if (TREE_CODE (fndecl) == FUNCTION_DECL)
	{
	  if (setjmp_call_p (fndecl))
	    {
	      error_at (loc, "setjmps are not allowed inside loops marked with"
			" #pragma simd");
	      *valid = false;
	      *walk_subtrees = 0;
	    }
	}
    }
  return NULL_TREE;
}  
  
/* Walks through all the subtrees of BODY using walk_tree to make sure invalid
   statements/expressions are not found inside BODY.  Returns false if any
   invalid statements are found.  */

bool
p_simd_valid_stmts_in_body_p (tree body)
{
  bool valid = true;
  walk_tree (&body, find_invalid_stmts, (void *) &valid, NULL);
  return valid;
}