testsuite: simplify target requirements for various Power9 testcases.
[official-gcc.git] / gcc / attr-fnspec.h
blobd38b84a969ee5316559ad70519bb4c69930c22f7
1 /* Handling of fnspec attribute specifiers
2 Copyright (C) 2008-2020 Free Software Foundation, Inc.
3 Contributed by Richard Guenther <rguenther@suse.de>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 /* Parse string of attribute "fn spec". This is an internal attribute
22 describing side effects of a function as follows:
24 character 0 specifies properties of return values as follows:
25 '1'...'4' specifies number of argument function returns (as in memset)
26 'm' specifies that returned value is noalias (as in malloc)
27 '.' specifies that nothing is known.
28 character 1 specifies additional function properties
29 ' ' specifies that nothing is known
31 character 2+2i specifies properties of argument number i as follows:
32 'x' or 'X' specifies that parameter is unused.
33 'r' or 'R' specifies that the memory pointed to by the parameter is only
34 read and does not escape
35 'w' or 'W' specifies that the memory pointed to by the parameter does not
36 escape
37 '.' specifies that nothing is known.
38 The uppercase letter in addition specifies that the memory pointed to
39 by the parameter is not dereferenced. For 'r' only read applies
40 transitively to pointers read from the pointed-to memory.
42 character 3+2i specifies additional properties of argument number i
43 as follows:
44 ' ' nothing is known
47 #ifndef ATTR_FNSPEC_H
48 #define ATTR_FNSPEC_H
50 class attr_fnspec
52 private:
53 /* fn spec attribute string. */
54 const char *str;
55 /* length of the fn spec string. */
56 const unsigned len;
57 /* Number of characters specifying return value. */
58 const unsigned int return_desc_size = 2;
59 /* Number of characters specifying size. */
60 const unsigned int arg_desc_size = 2;
62 /* Return start of specifier of arg i. */
63 unsigned int arg_idx (int i)
65 return return_desc_size + arg_desc_size * i;
68 public:
69 attr_fnspec (const char *str, unsigned len)
70 : str (str), len (len)
72 if (flag_checking)
73 verify ();
75 attr_fnspec (const_tree identifier)
76 : str (TREE_STRING_POINTER (identifier)),
77 len (TREE_STRING_LENGTH (identifier))
79 if (flag_checking)
80 verify ();
83 /* Return true if arg I is specified. */
84 bool
85 arg_specified_p (unsigned int i)
87 return len >= arg_idx (i + 1);
90 /* True if the argument is not dereferenced recursively, thus only
91 directly reachable memory is read or written. */
92 bool
93 arg_direct_p (unsigned int i)
95 unsigned int idx = arg_idx (i);
96 gcc_checking_assert (arg_specified_p (i));
97 return str[idx] == 'R' || str[idx] == 'W';
100 /* True if argument is used. */
101 bool
102 arg_used_p (unsigned int i)
104 unsigned int idx = arg_idx (i);
105 gcc_checking_assert (arg_specified_p (i));
106 return str[idx] != 'x' && str[idx] != 'X';
109 /* True if memory reached by the argument is readonly (not clobbered). */
110 bool
111 arg_readonly_p (unsigned int i)
113 unsigned int idx = arg_idx (i);
114 gcc_checking_assert (arg_specified_p (i));
115 return str[idx] == 'r' || str[idx] == 'R';
118 /* True if the argument does not escape. */
119 bool
120 arg_noescape_p (unsigned int i)
122 unsigned int idx = arg_idx (i);
123 gcc_checking_assert (arg_specified_p (i));
124 return str[idx] == 'w' || str[idx] == 'W'
125 || str[idx] == 'R' || str[idx] == 'r';
128 /* Return true if function returns value of its parameter. If ARG_NO is
129 non-NULL return initialize it to the argument returned. */
130 bool
131 returns_arg (unsigned int *arg_no)
133 if (str[0] >= '1' && str[0] <= '4')
135 if (arg_no)
136 *arg_no = str[0] - '1';
137 return true;
139 return false;
142 /* Nonzero if the return value does not alias with anything. Functions
143 with the malloc attribute have this set on their return value. */
144 bool
145 returns_noalias_p ()
147 return str[0] == 'm';
150 /* Check validity of the string. */
151 void verify ();
154 #endif /* ATTR_FNSPEC_H */