| 1 |
/* ACLE support for Arm MVE |
| 2 |
Copyright (C) 2021-2025 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
This file is part of GCC. |
| 5 |
|
| 6 |
GCC is free software; you can redistribute it and/or modify it |
| 7 |
under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation; either version 3, or (at your option) |
| 9 |
any later version. |
| 10 |
|
| 11 |
GCC is distributed in the hope that it will be useful, but |
| 12 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
General Public License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License |
| 17 |
along with GCC; see the file COPYING3. If not see |
| 18 |
<http://www.gnu.org/licenses/>. */ |
| 19 |
|
| 20 |
#define IN_TARGET_CODE 1 |
| 21 |
|
| 22 |
#include "config.h" |
| 23 |
#include "system.h" |
| 24 |
#include "coretypes.h" |
| 25 |
#include "tm.h" |
| 26 |
#include "tree.h" |
| 27 |
#include "rtl.h" |
| 28 |
#include "tm_p.h" |
| 29 |
#include "memmodel.h" |
| 30 |
#include "insn-codes.h" |
| 31 |
#include "optabs.h" |
| 32 |
#include "recog.h" |
| 33 |
#include "expr.h" |
| 34 |
#include "basic-block.h" |
| 35 |
#include "function.h" |
| 36 |
#include "fold-const.h" |
| 37 |
#include "gimple.h" |
| 38 |
#include "gimple-iterator.h" |
| 39 |
#include "explow.h" |
| 40 |
#include "emit-rtl.h" |
| 41 |
#include "stor-layout.h" |
| 42 |
#include "langhooks.h" |
| 43 |
#include "stringpool.h" |
| 44 |
#include "attribs.h" |
| 45 |
#include "diagnostic.h" |
| 46 |
#include "arm-protos.h" |
| 47 |
#include "arm-builtins.h" |
| 48 |
#include "arm-mve-builtins.h" |
| 49 |
#include "arm-mve-builtins-base.h" |
| 50 |
#include "arm-mve-builtins-shapes.h" |
| 51 |
|
| 52 |
namespace arm_mve { |
| 53 |
|
| 54 |
/* Static information about each single-predicate or single-vector |
| 55 |
ACLE type. */ |
| 56 |
struct vector_type_info |
| 57 |
{ |
| 58 |
/* The name of the type as declared by arm_mve.h. */ |
| 59 |
const char *acle_name; |
| 60 |
|
| 61 |
/* Whether the type requires a floating point abi. */ |
| 62 |
const bool requires_float; |
| 63 |
}; |
| 64 |
|
| 65 |
/* Describes a function decl. */ |
| 66 |
class GTY(()) registered_function |
| 67 |
{ |
| 68 |
public: |
| 69 |
/* The ACLE function that the decl represents. */ |
| 70 |
function_instance instance GTY ((skip)); |
| 71 |
|
| 72 |
/* The decl itself. */ |
| 73 |
tree decl; |
| 74 |
|
| 75 |
/* Whether the function requires a floating point abi. */ |
| 76 |
bool requires_float; |
| 77 |
|
| 78 |
/* True if the decl represents an overloaded function that needs to be |
| 79 |
resolved by function_resolver. */ |
| 80 |
bool overloaded_p; |
| 81 |
}; |
| 82 |
|
| 83 |
/* Hash traits for registered_function. */ |
| 84 |
struct registered_function_hasher : nofree_ptr_hash <registered_function> |
| 85 |
{ |
| 86 |
typedef function_instance compare_type; |
| 87 |
|
| 88 |
static hashval_t hash (value_type); |
| 89 |
static bool equal (value_type, const compare_type &); |
| 90 |
}; |
| 91 |
|
| 92 |
/* Flag indicating whether the arm MVE types have been handled. */ |
| 93 |
static bool handle_arm_mve_types_p; |
| 94 |
|
| 95 |
/* Information about each single-predicate or single-vector type. */ |
| 96 |
static CONSTEXPR const vector_type_info vector_types[] = { |
| 97 |
#define DEF_MVE_TYPE(ACLE_NAME, SCALAR_TYPE) \ |
| 98 |
{ #ACLE_NAME, REQUIRES_FLOAT }, |
| 99 |
#include "arm-mve-builtins.def" |
| 100 |
}; |
| 101 |
|
| 102 |
/* The function name suffix associated with each predication type. */ |
| 103 |
static const char *const pred_suffixes[NUM_PREDS + 1] = { |
| 104 |
"", |
| 105 |
"_m", |
| 106 |
"_p", |
| 107 |
"_x", |
| 108 |
"_z", |
| 109 |
"" |
| 110 |
}; |
| 111 |
|
| 112 |
/* Static information about each mode_suffix_index. */ |
| 113 |
CONSTEXPR const mode_suffix_info mode_suffixes[] = { |
| 114 |
#define VECTOR_TYPE_none NUM_VECTOR_TYPES |
| 115 |
#define DEF_MVE_MODE(NAME, BASE, DISPLACEMENT, UNITS) \ |
| 116 |
{ "_" #NAME, VECTOR_TYPE_##BASE, VECTOR_TYPE_##DISPLACEMENT, UNITS_##UNITS }, |
| 117 |
#include "arm-mve-builtins.def" |
| 118 |
#undef VECTOR_TYPE_none |
| 119 |
{ "", NUM_VECTOR_TYPES, NUM_VECTOR_TYPES, UNITS_none } |
| 120 |
}; |
| 121 |
|
| 122 |
/* Static information about each type_suffix_index. */ |
| 123 |
CONSTEXPR const type_suffix_info type_suffixes[NUM_TYPE_SUFFIXES + 1] = { |
| 124 |
#define DEF_MVE_TYPE_SUFFIX(NAME, ACLE_TYPE, CLASS, BITS, MODE) \ |
| 125 |
{ "_" #NAME, \ |
| 126 |
VECTOR_TYPE_##ACLE_TYPE, \ |
| 127 |
TYPE_##CLASS, \ |
| 128 |
BITS, \ |
| 129 |
BITS / BITS_PER_UNIT, \ |
| 130 |
TYPE_##CLASS == TYPE_signed || TYPE_##CLASS == TYPE_unsigned, \ |
| 131 |
TYPE_##CLASS == TYPE_unsigned, \ |
| 132 |
TYPE_##CLASS == TYPE_float, \ |
| 133 |
TYPE_##CLASS == TYPE_poly, \ |
| 134 |
0, \ |
| 135 |
MODE }, |
| 136 |
#include "arm-mve-builtins.def" |
| 137 |
{ "", NUM_VECTOR_TYPES, TYPE_bool, 0, 0, false, false, false, false, |
| 138 |
0, VOIDmode } |
| 139 |
}; |
| 140 |
|
| 141 |
/* Define a TYPES_<combination> macro for each combination of type |
| 142 |
suffixes that an ACLE function can have, where <combination> is the |
| 143 |
name used in DEF_MVE_FUNCTION entries. |
| 144 |
|
| 145 |
Use S (T) for single type suffix T and D (T1, T2) for a pair of type |
| 146 |
suffixes T1 and T2. Use commas to separate the suffixes. |
| 147 |
|
| 148 |
Although the order shouldn't matter, the convention is to sort the |
| 149 |
suffixes lexicographically after dividing suffixes into a type |
| 150 |
class ("b", "f", etc.) and a numerical bit count. */ |
| 151 |
|
| 152 |
/* _f16. */ |
| 153 |
#define TYPES_float_16(S, D) S (f16) |
| 154 |
|
| 155 |
/* _f32. */ |
| 156 |
#define TYPES_float_32(S, D) S (f32) |
| 157 |
|
| 158 |
/* _f16 _f32. */ |
| 159 |
#define TYPES_all_float(S, D) \ |
| 160 |
S (f16), S (f32) |
| 161 |
|
| 162 |
/* _s8 _u8 . */ |
| 163 |
#define TYPES_integer_8(S, D) \ |
| 164 |
S (s8), S (u8) |
| 165 |
|
| 166 |
/* _s8 _s16 |
| 167 |
_u8 _u16. */ |
| 168 |
#define TYPES_integer_8_16(S, D) \ |
| 169 |
S (s8), S (s16), S (u8), S(u16) |
| 170 |
|
| 171 |
/* _s16 _s32 |
| 172 |
_u16 _u32. */ |
| 173 |
#define TYPES_integer_16_32(S, D) \ |
| 174 |
S (s16), S (s32), \ |
| 175 |
S (u16), S (u32) |
| 176 |
|
| 177 |
/* _s16 _s32. */ |
| 178 |
#define TYPES_signed_16_32(S, D) \ |
| 179 |
S (s16), S (s32) |
| 180 |
|
| 181 |
/* _s8 _s16 _s32. */ |
| 182 |
#define TYPES_all_signed(S, D) \ |
| 183 |
S (s8), S (s16), S (s32) |
| 184 |
|
| 185 |
/* _p8 _p16. */ |
| 186 |
#define TYPES_poly_8_16(S, D) \ |
| 187 |
S (p8), S (p16) |
| 188 |
|
| 189 |
/* _u8 _u16 _u32. */ |
| 190 |
#define TYPES_all_unsigned(S, D) \ |
| 191 |
S (u8), S (u16), S (u32) |
| 192 |
|
| 193 |
/* _s8 _s16 _s32 |
| 194 |
_u8 _u16 _u32. */ |
| 195 |
#define TYPES_all_integer(S, D) \ |
| 196 |
TYPES_all_signed (S, D), TYPES_all_unsigned (S, D) |
| 197 |
|
| 198 |
/* _s8 _s16 _s32 _s64 |
| 199 |
_u8 _u16 _u32 _u64. */ |
| 200 |
#define TYPES_all_integer_with_64(S, D) \ |
| 201 |
TYPES_all_signed (S, D), S (s64), TYPES_all_unsigned (S, D), S (u64) |
| 202 |
|
| 203 |
/* s32 _u32. */ |
| 204 |
#define TYPES_integer_32(S, D) \ |
| 205 |
S (s32), S (u32) |
| 206 |
|
| 207 |
/* s32 . */ |
| 208 |
#define TYPES_signed_32(S, D) \ |
| 209 |
S (s32) |
| 210 |
|
| 211 |
/* s64 _u64. */ |
| 212 |
#define TYPES_integer_64(S, D) \ |
| 213 |
S (s64), S (u64) |
| 214 |
|
| 215 |
/* All the type combinations allowed by vcvtq. */ |
| 216 |
#define TYPES_cvt(S, D) \ |
| 217 |
D (f16, s16), \ |
| 218 |
D (f16, u16), \ |
| 219 |
\ |
| 220 |
D (f32, s32), \ |
| 221 |
D (f32, u32), \ |
| 222 |
\ |
| 223 |
D (s16, f16), \ |
| 224 |
D (s32, f32), \ |
| 225 |
\ |
| 226 |
D (u16, f16), \ |
| 227 |
D (u32, f32) |
| 228 |
|
| 229 |
/* vcvt[bt]q_f16_f132. */ |
| 230 |
#define TYPES_cvt_f16_f32(S, D) \ |
| 231 |
D (f16, f32) |
| 232 |
|
| 233 |
/* vcvt[bt]q_f32_f16. */ |
| 234 |
#define TYPES_cvt_f32_f16(S, D) \ |
| 235 |
D (f32, f16) |
| 236 |
|
| 237 |
/* All the type combinations allowed by vcvtXq. */ |
| 238 |
#define TYPES_cvtx(S, D) \ |
| 239 |
D (s16, f16), \ |
| 240 |
D (s32, f32), \ |
| 241 |
\ |
| 242 |
D (u16, f16), \ |
| 243 |
D (u32, f32) |
| 244 |
|
| 245 |
#define TYPES_reinterpret_signed1(D, A) \ |
| 246 |
D (A, s8), D (A, s16), D (A, s32), D (A, s64) |
| 247 |
|
| 248 |
#define TYPES_reinterpret_unsigned1(D, A) \ |
| 249 |
D (A, u8), D (A, u16), D (A, u32), D (A, u64) |
| 250 |
|
| 251 |
#define TYPES_reinterpret_integer(S, D) \ |
| 252 |
TYPES_reinterpret_unsigned1 (D, s8), \ |
| 253 |
D (s8, s16), D (s8, s32), D (s8, s64), \ |
| 254 |
TYPES_reinterpret_unsigned1 (D, s16), \ |
| 255 |
D (s16, s8), D (s16, s32), D (s16, s64), \ |
| 256 |
TYPES_reinterpret_unsigned1 (D, s32), \ |
| 257 |
D (s32, s8), D (s32, s16), D (s32, s64), \ |
| 258 |
TYPES_reinterpret_unsigned1 (D, s64), \ |
| 259 |
D (s64, s8), D (s64, s16), D (s64, s32), \ |
| 260 |
TYPES_reinterpret_signed1 (D, u8), \ |
| 261 |
D (u8, u16), D (u8, u32), D (u8, u64), \ |
| 262 |
TYPES_reinterpret_signed1 (D, u16), \ |
| 263 |
D (u16, u8), D (u16, u32), D (u16, u64), \ |
| 264 |
TYPES_reinterpret_signed1 (D, u32), \ |
| 265 |
D (u32, u8), D (u32, u16), D (u32, u64), \ |
| 266 |
TYPES_reinterpret_signed1 (D, u64), \ |
| 267 |
D (u64, u8), D (u64, u16), D (u64, u32) |
| 268 |
|
| 269 |
/* { _s8 _s16 _s32 _s64 } x { _s8 _s16 _s32 _s64 } |
| 270 |
{ _u8 _u16 _u32 _u64 } { _u8 _u16 _u32 _u64 }. */ |
| 271 |
#define TYPES_reinterpret_integer1(D, A) \ |
| 272 |
TYPES_reinterpret_signed1 (D, A), \ |
| 273 |
TYPES_reinterpret_unsigned1 (D, A) |
| 274 |
|
| 275 |
#define TYPES_reinterpret_float1(D, A) \ |
| 276 |
D (A, f16), D (A, f32) |
| 277 |
|
| 278 |
#define TYPES_reinterpret_float(S, D) \ |
| 279 |
TYPES_reinterpret_float1 (D, s8), \ |
| 280 |
TYPES_reinterpret_float1 (D, s16), \ |
| 281 |
TYPES_reinterpret_float1 (D, s32), \ |
| 282 |
TYPES_reinterpret_float1 (D, s64), \ |
| 283 |
TYPES_reinterpret_float1 (D, u8), \ |
| 284 |
TYPES_reinterpret_float1 (D, u16), \ |
| 285 |
TYPES_reinterpret_float1 (D, u32), \ |
| 286 |
TYPES_reinterpret_float1 (D, u64), \ |
| 287 |
TYPES_reinterpret_integer1 (D, f16), \ |
| 288 |
TYPES_reinterpret_integer1 (D, f32), \ |
| 289 |
D (f16, f32), D (f32, f16) |
| 290 |
|
| 291 |
/* Describe a pair of type suffixes in which only the first is used. */ |
| 292 |
#define DEF_VECTOR_TYPE(X) { TYPE_SUFFIX_ ## X, NUM_TYPE_SUFFIXES } |
| 293 |
|
| 294 |
/* Describe a pair of type suffixes in which both are used. */ |
| 295 |
#define DEF_DOUBLE_TYPE(X, Y) { TYPE_SUFFIX_ ## X, TYPE_SUFFIX_ ## Y } |
| 296 |
|
| 297 |
/* Create an array that can be used in arm-mve-builtins.def to |
| 298 |
select the type suffixes in TYPES_<NAME>. */ |
| 299 |
#define DEF_MVE_TYPES_ARRAY(NAME) \ |
| 300 |
static const type_suffix_pair types_##NAME[] = { \ |
| 301 |
TYPES_##NAME (DEF_VECTOR_TYPE, DEF_DOUBLE_TYPE), \ |
| 302 |
{ NUM_TYPE_SUFFIXES, NUM_TYPE_SUFFIXES } \ |
| 303 |
} |
| 304 |
|
| 305 |
/* For functions that don't take any type suffixes. */ |
| 306 |
static const type_suffix_pair types_none[] = { |
| 307 |
{ NUM_TYPE_SUFFIXES, NUM_TYPE_SUFFIXES }, |
| 308 |
{ NUM_TYPE_SUFFIXES, NUM_TYPE_SUFFIXES } |
| 309 |
}; |
| 310 |
|
| 311 |
DEF_MVE_TYPES_ARRAY (all_integer); |
| 312 |
DEF_MVE_TYPES_ARRAY (all_integer_with_64); |
| 313 |
DEF_MVE_TYPES_ARRAY (float_16); |
| 314 |
DEF_MVE_TYPES_ARRAY (float_32); |
| 315 |
DEF_MVE_TYPES_ARRAY (all_float); |
| 316 |
DEF_MVE_TYPES_ARRAY (all_signed); |
| 317 |
DEF_MVE_TYPES_ARRAY (all_unsigned); |
| 318 |
DEF_MVE_TYPES_ARRAY (integer_8); |
| 319 |
DEF_MVE_TYPES_ARRAY (integer_8_16); |
| 320 |
DEF_MVE_TYPES_ARRAY (integer_16_32); |
| 321 |
DEF_MVE_TYPES_ARRAY (integer_32); |
| 322 |
DEF_MVE_TYPES_ARRAY (integer_64); |
| 323 |
DEF_MVE_TYPES_ARRAY (poly_8_16); |
| 324 |
DEF_MVE_TYPES_ARRAY (signed_16_32); |
| 325 |
DEF_MVE_TYPES_ARRAY (signed_32); |
| 326 |
DEF_MVE_TYPES_ARRAY (cvt); |
| 327 |
DEF_MVE_TYPES_ARRAY (cvt_f16_f32); |
| 328 |
DEF_MVE_TYPES_ARRAY (cvt_f32_f16); |
| 329 |
DEF_MVE_TYPES_ARRAY (cvtx); |
| 330 |
DEF_MVE_TYPES_ARRAY (reinterpret_integer); |
| 331 |
DEF_MVE_TYPES_ARRAY (reinterpret_float); |
| 332 |
|
| 333 |
/* Used by functions that have no governing predicate. */ |
| 334 |
static const predication_index preds_none[] = { PRED_none, NUM_PREDS }; |
| 335 |
|
| 336 |
/* Used by functions that have the m (merging) predicated form, and in |
| 337 |
addition have an unpredicated form. */ |
| 338 |
const predication_index preds_m_or_none[] = { |
| 339 |
PRED_m, PRED_none, NUM_PREDS |
| 340 |
}; |
| 341 |
|
| 342 |
/* Used by functions that have the mx (merging and "don't care" |
| 343 |
predicated forms, and in addition have an unpredicated form. */ |
| 344 |
static const predication_index preds_mx_or_none[] = { |
| 345 |
PRED_m, PRED_x, PRED_none, NUM_PREDS |
| 346 |
}; |
| 347 |
|
| 348 |
/* Used by functions that have the p predicated form, in addition to |
| 349 |
an unpredicated form. */ |
| 350 |
static const predication_index preds_p_or_none[] = { |
| 351 |
PRED_p, PRED_none, NUM_PREDS |
| 352 |
}; |
| 353 |
|
| 354 |
/* Used by functions that have the z predicated form, in addition to |
| 355 |
an unpredicated form. */ |
| 356 |
static const predication_index preds_z_or_none[] |
| 357 |
= {PRED_z, PRED_none, NUM_PREDS}; |
| 358 |
|
| 359 |
/* A list of all MVE ACLE functions. */ |
| 360 |
static CONSTEXPR const function_group_info function_groups[] = { |
| 361 |
#define DEF_MVE_FUNCTION(NAME, SHAPE, TYPES, PREDS) \ |
| 362 |
{ #NAME, &functions::NAME, &shapes::SHAPE, types_##TYPES, preds_##PREDS, \ |
| 363 |
REQUIRES_FLOAT }, |
| 364 |
#include "arm-mve-builtins.def" |
| 365 |
}; |
| 366 |
|
| 367 |
/* The scalar type associated with each vector type. */ |
| 368 |
extern GTY(()) tree scalar_types[NUM_VECTOR_TYPES]; |
| 369 |
tree scalar_types[NUM_VECTOR_TYPES]; |
| 370 |
|
| 371 |
/* The single-predicate and single-vector types, with their built-in |
| 372 |
"__simd128_..._t" name. Allow an index of NUM_VECTOR_TYPES, which always |
| 373 |
yields a null tree. */ |
| 374 |
static GTY(()) tree abi_vector_types[NUM_VECTOR_TYPES + 1]; |
| 375 |
|
| 376 |
/* Same, but with the arm_mve.h names. */ |
| 377 |
extern GTY(()) tree acle_vector_types[MAX_TUPLE_SIZE][NUM_VECTOR_TYPES + 1]; |
| 378 |
tree acle_vector_types[MAX_TUPLE_SIZE][NUM_VECTOR_TYPES + 1]; |
| 379 |
|
| 380 |
/* The list of all registered function decls, indexed by code. */ |
| 381 |
static GTY(()) vec<registered_function *, va_gc> *registered_functions; |
| 382 |
|
| 383 |
/* All registered function decls, hashed on the function_instance |
| 384 |
that they implement. This is used for looking up implementations of |
| 385 |
overloaded functions. */ |
| 386 |
static hash_table<registered_function_hasher> *function_table; |
| 387 |
|
| 388 |
/* True if we've already complained about attempts to use functions |
| 389 |
when the required extension is disabled. */ |
| 390 |
static bool reported_missing_float_p; |
| 391 |
|
| 392 |
/* Return the MVE abi type with element of type TYPE. */ |
| 393 |
static tree |
| 394 |
arm_mve_type_for_scalar_type (tree eltype) |
| 395 |
{ |
| 396 |
for (unsigned int i = 0; i < __TYPE_FINAL; ++i) |
| 397 |
if (arm_simd_types[i].eltype == eltype |
| 398 |
&& GET_MODE_SIZE (arm_simd_types[i].mode) == 16) |
| 399 |
return arm_simd_types[i].itype; |
| 400 |
|
| 401 |
gcc_unreachable (); |
| 402 |
} |
| 403 |
|
| 404 |
/* Register the built-in MVE ABI vector types, such as uint32x4_t. */ |
| 405 |
static void |
| 406 |
register_builtin_types () |
| 407 |
{ |
| 408 |
#define DEF_MVE_TYPE(ACLE_NAME, SCALAR_TYPE) \ |
| 409 |
scalar_types[VECTOR_TYPE_ ## ACLE_NAME] = SCALAR_TYPE; |
| 410 |
#include "arm-mve-builtins.def" |
| 411 |
for (unsigned int i = 0; i < NUM_VECTOR_TYPES; ++i) |
| 412 |
{ |
| 413 |
if (vector_types[i].requires_float && !TARGET_HAVE_MVE_FLOAT) |
| 414 |
continue; |
| 415 |
tree eltype = scalar_types[i]; |
| 416 |
tree vectype; |
| 417 |
if (eltype == boolean_type_node) |
| 418 |
{ |
| 419 |
vectype = get_typenode_from_name (UINT16_TYPE); |
| 420 |
gcc_assert (GET_MODE_SIZE (TYPE_MODE (vectype)) == 2); |
| 421 |
} |
| 422 |
else |
| 423 |
{ |
| 424 |
vectype = arm_mve_type_for_scalar_type (eltype); |
| 425 |
gcc_assert (VECTOR_MODE_P (TYPE_MODE (vectype)) |
| 426 |
&& GET_MODE_SIZE (TYPE_MODE (vectype)) == 16); |
| 427 |
} |
| 428 |
abi_vector_types[i] = vectype; |
| 429 |
} |
| 430 |
} |
| 431 |
|
| 432 |
/* Register vector type TYPE under its arm_mve.h name. */ |
| 433 |
static void |
| 434 |
register_vector_type (vector_type_index type) |
| 435 |
{ |
| 436 |
|
| 437 |
/* If the target does not have the mve.fp extension, but the type requires |
| 438 |
it, then it needs to be assigned a non-dummy type so that functions |
| 439 |
with those types in their signature can be registered. This allows for |
| 440 |
diagnostics about the missing extension, rather than about a missing |
| 441 |
function definition. */ |
| 442 |
if (vector_types[type].requires_float && !TARGET_HAVE_MVE_FLOAT) |
| 443 |
{ |
| 444 |
acle_vector_types[0][type] = void_type_node; |
| 445 |
return; |
| 446 |
} |
| 447 |
|
| 448 |
tree vectype = abi_vector_types[type]; |
| 449 |
tree id = get_identifier (vector_types[type].acle_name); |
| 450 |
tree decl = build_decl (input_location, TYPE_DECL, id, vectype); |
| 451 |
decl = lang_hooks.decls.pushdecl (decl); |
| 452 |
|
| 453 |
/* Record the new ACLE type if pushdecl succeeded without error. Use |
| 454 |
the ABI type otherwise, so that the type we record at least has the |
| 455 |
right form, even if it doesn't have the right name. This should give |
| 456 |
better error recovery behavior than installing error_mark_node or |
| 457 |
installing an incorrect type. */ |
| 458 |
if (decl |
| 459 |
&& TREE_CODE (decl) == TYPE_DECL |
| 460 |
&& TREE_TYPE (decl) != error_mark_node |
| 461 |
&& TYPE_MAIN_VARIANT (TREE_TYPE (decl)) == vectype) |
| 462 |
vectype = TREE_TYPE (decl); |
| 463 |
acle_vector_types[0][type] = vectype; |
| 464 |
} |
| 465 |
|
| 466 |
/* Register tuple types of element type TYPE under their arm_mve_types.h |
| 467 |
names. */ |
| 468 |
static void |
| 469 |
register_builtin_tuple_types (vector_type_index type) |
| 470 |
{ |
| 471 |
const vector_type_info* info = &vector_types[type]; |
| 472 |
|
| 473 |
/* If the target does not have the mve.fp extension, but the type requires |
| 474 |
it, then it needs to be assigned a non-dummy type so that functions |
| 475 |
with those types in their signature can be registered. This allows for |
| 476 |
diagnostics about the missing extension, rather than about a missing |
| 477 |
function definition. */ |
| 478 |
if (scalar_types[type] == boolean_type_node |
| 479 |
|| (info->requires_float && !TARGET_HAVE_MVE_FLOAT)) |
| 480 |
{ |
| 481 |
for (unsigned int num_vectors = 2; num_vectors <= 4; num_vectors += 2) |
| 482 |
acle_vector_types[num_vectors >> 1][type] = void_type_node; |
| 483 |
return; |
| 484 |
} |
| 485 |
|
| 486 |
const char *vector_type_name = info->acle_name; |
| 487 |
char buffer[sizeof ("float32x4x2_t")]; |
| 488 |
for (unsigned int num_vectors = 2; num_vectors <= 4; num_vectors += 2) |
| 489 |
{ |
| 490 |
snprintf (buffer, sizeof (buffer), "%.*sx%d_t", |
| 491 |
(int) strlen (vector_type_name) - 2, vector_type_name, |
| 492 |
num_vectors); |
| 493 |
|
| 494 |
tree vectype = acle_vector_types[0][type]; |
| 495 |
tree arrtype = build_array_type_nelts (vectype, num_vectors); |
| 496 |
gcc_assert (VECTOR_MODE_P (TYPE_MODE (arrtype)) |
| 497 |
&& TYPE_MODE_RAW (arrtype) == TYPE_MODE (arrtype) |
| 498 |
&& TYPE_ALIGN (arrtype) == 64); |
| 499 |
|
| 500 |
/* Build a structure type that contains a single field of type ARRTYPE. |
| 501 |
The field is called 'val', as mandated by ACLE. */ |
| 502 |
tree field = build_decl (input_location, FIELD_DECL, |
| 503 |
get_identifier ("val"), arrtype); |
| 504 |
tree tuple_type |
| 505 |
= lang_hooks.types.simulate_record_decl (input_location, |
| 506 |
buffer, |
| 507 |
make_array_slice (&field, 1)); |
| 508 |
gcc_assert (VECTOR_MODE_P (TYPE_MODE (tuple_type)) |
| 509 |
&& TYPE_MODE_RAW (tuple_type) == TYPE_MODE (tuple_type) |
| 510 |
&& TYPE_ALIGN (tuple_type) == 64); |
| 511 |
|
| 512 |
acle_vector_types[num_vectors >> 1][type] = tuple_type; |
| 513 |
} |
| 514 |
} |
| 515 |
|
| 516 |
/* Implement #pragma GCC arm "arm_mve_types.h". */ |
| 517 |
void |
| 518 |
handle_arm_mve_types_h () |
| 519 |
{ |
| 520 |
if (handle_arm_mve_types_p) |
| 521 |
{ |
| 522 |
error ("duplicate definition of %qs", "arm_mve_types.h"); |
| 523 |
return; |
| 524 |
} |
| 525 |
handle_arm_mve_types_p = true; |
| 526 |
if (!TARGET_HAVE_MVE) |
| 527 |
{ |
| 528 |
error ("this definition requires the MVE ISA extension"); |
| 529 |
return; |
| 530 |
} |
| 531 |
register_builtin_types (); |
| 532 |
for (unsigned int type_i = 0; type_i < NUM_VECTOR_TYPES; ++type_i) |
| 533 |
{ |
| 534 |
vector_type_index type = vector_type_index (type_i); |
| 535 |
register_vector_type (type); |
| 536 |
if (type_i != VECTOR_TYPE_mve_pred16_t) |
| 537 |
register_builtin_tuple_types (type); |
| 538 |
} |
| 539 |
} |
| 540 |
|
| 541 |
/* Implement #pragma GCC arm "arm_mve.h" <bool>. */ |
| 542 |
void |
| 543 |
handle_arm_mve_h (bool preserve_user_namespace) |
| 544 |
{ |
| 545 |
if (function_table) |
| 546 |
{ |
| 547 |
error ("duplicate definition of %qs", "arm_mve.h"); |
| 548 |
return; |
| 549 |
} |
| 550 |
|
| 551 |
if (!handle_arm_mve_types_p) |
| 552 |
{ |
| 553 |
error ("this definition requires MVE types, please include %qs", |
| 554 |
"arm_mve_types.h"); |
| 555 |
return; |
| 556 |
} |
| 557 |
|
| 558 |
/* Define MVE functions. */ |
| 559 |
function_table = new hash_table<registered_function_hasher> (1023); |
| 560 |
function_builder builder; |
| 561 |
for (unsigned int i = 0; i < ARRAY_SIZE (function_groups); ++i) |
| 562 |
builder.register_function_group (function_groups[i], |
| 563 |
preserve_user_namespace); |
| 564 |
} |
| 565 |
|
| 566 |
/* Return the function decl with MVE function subcode CODE, or error_mark_node |
| 567 |
if no such function exists. */ |
| 568 |
tree |
| 569 |
builtin_decl (unsigned int code) |
| 570 |
{ |
| 571 |
if (code >= vec_safe_length (registered_functions)) |
| 572 |
return error_mark_node; |
| 573 |
return (*registered_functions)[code]->decl; |
| 574 |
} |
| 575 |
|
| 576 |
/* Return true if CANDIDATE is equivalent to MODEL_TYPE for overloading |
| 577 |
purposes. */ |
| 578 |
static bool |
| 579 |
matches_type_p (const_tree model_type, const_tree candidate) |
| 580 |
{ |
| 581 |
if (VECTOR_TYPE_P (model_type)) |
| 582 |
{ |
| 583 |
if (!VECTOR_TYPE_P (candidate) |
| 584 |
|| maybe_ne (TYPE_VECTOR_SUBPARTS (model_type), |
| 585 |
TYPE_VECTOR_SUBPARTS (candidate)) |
| 586 |
|| TYPE_MODE (model_type) != TYPE_MODE (candidate)) |
| 587 |
return false; |
| 588 |
|
| 589 |
model_type = TREE_TYPE (model_type); |
| 590 |
candidate = TREE_TYPE (candidate); |
| 591 |
} |
| 592 |
return (candidate != error_mark_node |
| 593 |
&& TYPE_MAIN_VARIANT (model_type) == TYPE_MAIN_VARIANT (candidate)); |
| 594 |
} |
| 595 |
|
| 596 |
/* If TYPE is a valid MVE element type, return the corresponding type |
| 597 |
suffix, otherwise return NUM_TYPE_SUFFIXES. */ |
| 598 |
static type_suffix_index |
| 599 |
find_type_suffix_for_scalar_type (const_tree type) |
| 600 |
{ |
| 601 |
/* A linear search should be OK here, since the code isn't hot and |
| 602 |
the number of types is only small. */ |
| 603 |
for (unsigned int suffix_i = 0; suffix_i < NUM_TYPE_SUFFIXES; ++suffix_i) |
| 604 |
{ |
| 605 |
vector_type_index vector_i = type_suffixes[suffix_i].vector_type; |
| 606 |
if (matches_type_p (scalar_types[vector_i], type)) |
| 607 |
return type_suffix_index (suffix_i); |
| 608 |
} |
| 609 |
return NUM_TYPE_SUFFIXES; |
| 610 |
} |
| 611 |
|
| 612 |
/* Report an error against LOCATION that the user has tried to use |
| 613 |
a floating point function when the mve.fp extension is disabled. */ |
| 614 |
static void |
| 615 |
report_missing_float (location_t location, tree fndecl) |
| 616 |
{ |
| 617 |
/* Avoid reporting a slew of messages for a single oversight. */ |
| 618 |
if (reported_missing_float_p) |
| 619 |
return; |
| 620 |
|
| 621 |
error_at (location, "ACLE function %qD requires ISA extension %qs", |
| 622 |
fndecl, "mve.fp"); |
| 623 |
inform (location, "you can enable mve.fp by using the command-line" |
| 624 |
" option %<-march%>, or by using the %<target%>" |
| 625 |
" attribute or pragma"); |
| 626 |
reported_missing_float_p = true; |
| 627 |
} |
| 628 |
|
| 629 |
/* Report that LOCATION has a call to FNDECL in which argument ARGNO |
| 630 |
was not an integer constant expression. ARGNO counts from zero. */ |
| 631 |
static void |
| 632 |
report_non_ice (location_t location, tree fndecl, unsigned int argno) |
| 633 |
{ |
| 634 |
error_at (location, "argument %d of %qE must be an integer constant" |
| 635 |
" expression", argno + 1, fndecl); |
| 636 |
} |
| 637 |
|
| 638 |
/* Report that LOCATION has a call to FNDECL in which argument ARGNO has |
| 639 |
the value ACTUAL, whereas the function requires a value in the range |
| 640 |
[MIN, MAX]. ARGNO counts from zero. */ |
| 641 |
static void |
| 642 |
report_out_of_range (location_t location, tree fndecl, unsigned int argno, |
| 643 |
HOST_WIDE_INT actual, HOST_WIDE_INT min, |
| 644 |
HOST_WIDE_INT max) |
| 645 |
{ |
| 646 |
error_at (location, "passing %wd to argument %d of %qE, which expects" |
| 647 |
" a value in the range [%wd, %wd]", actual, argno + 1, fndecl, |
| 648 |
min, max); |
| 649 |
} |
| 650 |
|
| 651 |
/* Report that LOCATION has a call to FNDECL in which argument ARGNO has the |
| 652 |
value ACTUAL, whereas the function requires a value multiple of MULT in the |
| 653 |
range [MIN, MAX]. ARGNO counts from zero. */ |
| 654 |
static void |
| 655 |
report_out_of_range_multiple (location_t location, tree fndecl, |
| 656 |
unsigned int argno, |
| 657 |
HOST_WIDE_INT actual, HOST_WIDE_INT min, |
| 658 |
HOST_WIDE_INT max, HOST_WIDE_INT mult) |
| 659 |
{ |
| 660 |
error_at (location, "passing %wd to argument %d of %qE, which expects" |
| 661 |
" a value multiple of %wd in the range [%wd, %wd]", actual, |
| 662 |
argno + 1, fndecl, mult, min, max); |
| 663 |
} |
| 664 |
|
| 665 |
/* Report that LOCATION has a call to FNDECL in which argument ARGNO has |
| 666 |
the value ACTUAL, whereas the function requires a valid value of |
| 667 |
enum type ENUMTYPE. ARGNO counts from zero. */ |
| 668 |
static void |
| 669 |
report_not_enum (location_t location, tree fndecl, unsigned int argno, |
| 670 |
HOST_WIDE_INT actual, tree enumtype) |
| 671 |
{ |
| 672 |
error_at (location, "passing %wd to argument %d of %qE, which expects" |
| 673 |
" a valid %qT value", actual, argno + 1, fndecl, enumtype); |
| 674 |
} |
| 675 |
|
| 676 |
/* Report that LOCATION has a call to FNDECL in which argument ARGNO has |
| 677 |
the value ACTUAL, whereas the function requires one of VALUE0..3. |
| 678 |
ARGNO counts from zero. */ |
| 679 |
static void |
| 680 |
report_not_one_of (location_t location, tree fndecl, unsigned int argno, |
| 681 |
HOST_WIDE_INT actual, HOST_WIDE_INT value0, |
| 682 |
HOST_WIDE_INT value1, HOST_WIDE_INT value2, |
| 683 |
HOST_WIDE_INT value3) |
| 684 |
{ |
| 685 |
error_at (location, "passing %wd to argument %d of %qE, which expects" |
| 686 |
" %wd, %wd, %wd or %wd", actual, argno + 1, fndecl, value0, value1, |
| 687 |
value2, value3); |
| 688 |
} |
| 689 |
|
| 690 |
/* Checks that the mve.fp extension is enabled, given that REQUIRES_FLOAT |
| 691 |
indicates whether it is required or not for function FNDECL. |
| 692 |
Report an error against LOCATION if not. */ |
| 693 |
static bool |
| 694 |
check_requires_float (location_t location, tree fndecl, |
| 695 |
bool requires_float) |
| 696 |
{ |
| 697 |
if (requires_float && !TARGET_HAVE_MVE_FLOAT) |
| 698 |
{ |
| 699 |
report_missing_float (location, fndecl); |
| 700 |
return false; |
| 701 |
} |
| 702 |
|
| 703 |
return true; |
| 704 |
} |
| 705 |
|
| 706 |
/* Return a hash code for a function_instance. */ |
| 707 |
hashval_t |
| 708 |
function_instance::hash () const |
| 709 |
{ |
| 710 |
inchash::hash h; |
| 711 |
/* BASE uniquely determines BASE_NAME, so we don't need to hash both. */ |
| 712 |
h.add_ptr (base); |
| 713 |
h.add_ptr (shape); |
| 714 |
h.add_int (mode_suffix_id); |
| 715 |
h.add_int (type_suffix_ids[0]); |
| 716 |
h.add_int (type_suffix_ids[1]); |
| 717 |
h.add_int (pred); |
| 718 |
return h.end (); |
| 719 |
} |
| 720 |
|
| 721 |
/* Return a set of CP_* flags that describe what the function could do, |
| 722 |
taking the command-line flags into account. */ |
| 723 |
unsigned int |
| 724 |
function_instance::call_properties () const |
| 725 |
{ |
| 726 |
unsigned int flags = base->call_properties (*this); |
| 727 |
|
| 728 |
/* -fno-trapping-math means that we can assume any FP exceptions |
| 729 |
are not user-visible. */ |
| 730 |
if (!flag_trapping_math) |
| 731 |
flags &= ~CP_RAISE_FP_EXCEPTIONS; |
| 732 |
|
| 733 |
return flags; |
| 734 |
} |
| 735 |
|
| 736 |
/* Return true if calls to the function could read some form of |
| 737 |
global state. */ |
| 738 |
bool |
| 739 |
function_instance::reads_global_state_p () const |
| 740 |
{ |
| 741 |
unsigned int flags = call_properties (); |
| 742 |
|
| 743 |
/* Preserve any dependence on rounding mode, flush to zero mode, etc. |
| 744 |
There is currently no way of turning this off; in particular, |
| 745 |
-fno-rounding-math (which is the default) means that we should make |
| 746 |
the usual assumptions about rounding mode, which for intrinsics means |
| 747 |
acting as the instructions do. */ |
| 748 |
if (flags & CP_READ_FPCR) |
| 749 |
return true; |
| 750 |
|
| 751 |
return flags & CP_READ_MEMORY; |
| 752 |
} |
| 753 |
|
| 754 |
/* Return true if calls to the function could modify some form of |
| 755 |
global state. */ |
| 756 |
bool |
| 757 |
function_instance::modifies_global_state_p () const |
| 758 |
{ |
| 759 |
unsigned int flags = call_properties (); |
| 760 |
|
| 761 |
/* Preserve any exception state written back to the FPCR, |
| 762 |
unless -fno-trapping-math says this is unnecessary. */ |
| 763 |
if (flags & CP_RAISE_FP_EXCEPTIONS) |
| 764 |
return true; |
| 765 |
|
| 766 |
/* Handle direct modifications of global state. */ |
| 767 |
return flags & CP_WRITE_MEMORY; |
| 768 |
} |
| 769 |
|
| 770 |
/* Return true if calls to the function could raise a signal. */ |
| 771 |
bool |
| 772 |
function_instance::could_trap_p () const |
| 773 |
{ |
| 774 |
unsigned int flags = call_properties (); |
| 775 |
|
| 776 |
/* Handle functions that could raise SIGFPE. */ |
| 777 |
if (flags & CP_RAISE_FP_EXCEPTIONS) |
| 778 |
return true; |
| 779 |
|
| 780 |
/* Handle functions that could raise SIGBUS or SIGSEGV. */ |
| 781 |
if (flags & (CP_READ_MEMORY | CP_WRITE_MEMORY)) |
| 782 |
return true; |
| 783 |
|
| 784 |
return false; |
| 785 |
} |
| 786 |
|
| 787 |
/* Return true if the function has an implicit "inactive" argument. |
| 788 |
This is the case of most _m predicated functions, but not all. |
| 789 |
The list will be updated as needed. */ |
| 790 |
bool |
| 791 |
function_instance::has_inactive_argument () const |
| 792 |
{ |
| 793 |
if (pred != PRED_m) |
| 794 |
return false; |
| 795 |
|
| 796 |
if (mode_suffix_id == MODE_r |
| 797 |
|| (base == functions::vbicq && mode_suffix_id == MODE_n) |
| 798 |
|| base == functions::vcmlaq |
| 799 |
|| base == functions::vcmlaq_rot90 |
| 800 |
|| base == functions::vcmlaq_rot180 |
| 801 |
|| base == functions::vcmlaq_rot270 |
| 802 |
|| base == functions::vcmpeqq |
| 803 |
|| base == functions::vcmpneq |
| 804 |
|| base == functions::vcmpgeq |
| 805 |
|| base == functions::vcmpgtq |
| 806 |
|| base == functions::vcmpleq |
| 807 |
|| base == functions::vcmpltq |
| 808 |
|| base == functions::vcmpcsq |
| 809 |
|| base == functions::vcmphiq |
| 810 |
|| base == functions::vctp16q |
| 811 |
|| base == functions::vctp32q |
| 812 |
|| base == functions::vctp64q |
| 813 |
|| base == functions::vctp8q |
| 814 |
|| (base == functions::vcvtbq && type_suffix (0).element_bits == 16) |
| 815 |
|| (base == functions::vcvttq && type_suffix (0).element_bits == 16) |
| 816 |
|| base == functions::vfmaq |
| 817 |
|| base == functions::vfmasq |
| 818 |
|| base == functions::vfmsq |
| 819 |
|| base == functions::vmaxaq |
| 820 |
|| base == functions::vmaxnmaq |
| 821 |
|| base == functions::vminaq |
| 822 |
|| base == functions::vminnmaq |
| 823 |
|| base == functions::vmlaq |
| 824 |
|| base == functions::vmlasq |
| 825 |
|| base == functions::vmovnbq |
| 826 |
|| base == functions::vmovntq |
| 827 |
|| base == functions::vqmovnbq |
| 828 |
|| base == functions::vqmovntq |
| 829 |
|| base == functions::vqmovunbq |
| 830 |
|| base == functions::vqmovuntq |
| 831 |
|| (base == functions::vorrq && mode_suffix_id == MODE_n) |
| 832 |
|| base == functions::vqdmladhq |
| 833 |
|| base == functions::vqdmladhxq |
| 834 |
|| base == functions::vqdmlahq |
| 835 |
|| base == functions::vqdmlashq |
| 836 |
|| base == functions::vqdmlsdhq |
| 837 |
|| base == functions::vqdmlsdhxq |
| 838 |
|| base == functions::vqrdmladhq |
| 839 |
|| base == functions::vqrdmladhxq |
| 840 |
|| base == functions::vqrdmlahq |
| 841 |
|| base == functions::vqrdmlashq |
| 842 |
|| base == functions::vqrdmlsdhq |
| 843 |
|| base == functions::vqrdmlsdhxq |
| 844 |
|| (base == functions::vqrshlq && mode_suffix_id == MODE_n) |
| 845 |
|| base == functions::vqrshrnbq |
| 846 |
|| base == functions::vqrshrntq |
| 847 |
|| base == functions::vqrshrunbq |
| 848 |
|| base == functions::vqrshruntq |
| 849 |
|| base == functions::vqshrnbq |
| 850 |
|| base == functions::vqshrntq |
| 851 |
|| base == functions::vqshrunbq |
| 852 |
|| base == functions::vqshruntq |
| 853 |
|| (base == functions::vrshlq && mode_suffix_id == MODE_n) |
| 854 |
|| base == functions::vrshrnbq |
| 855 |
|| base == functions::vrshrntq |
| 856 |
|| base == functions::vshlcq |
| 857 |
|| base == functions::vshrnbq |
| 858 |
|| base == functions::vshrntq |
| 859 |
|| base == functions::vsliq |
| 860 |
|| base == functions::vsriq) |
| 861 |
return false; |
| 862 |
|
| 863 |
return true; |
| 864 |
} |
| 865 |
|
| 866 |
inline hashval_t |
| 867 |
registered_function_hasher::hash (value_type value) |
| 868 |
{ |
| 869 |
return value->instance.hash (); |
| 870 |
} |
| 871 |
|
| 872 |
inline bool |
| 873 |
registered_function_hasher::equal (value_type value, const compare_type &key) |
| 874 |
{ |
| 875 |
return value->instance == key; |
| 876 |
} |
| 877 |
|
| 878 |
function_builder::function_builder () |
| 879 |
{ |
| 880 |
m_overload_type = build_function_type (void_type_node, void_list_node); |
| 881 |
m_direct_overloads = lang_GNU_CXX (); |
| 882 |
gcc_obstack_init (&m_string_obstack); |
| 883 |
} |
| 884 |
|
| 885 |
function_builder::~function_builder () |
| 886 |
{ |
| 887 |
obstack_free (&m_string_obstack, NULL); |
| 888 |
} |
| 889 |
|
| 890 |
/* Add NAME to the end of the function name being built. */ |
| 891 |
void |
| 892 |
function_builder::append_name (const char *name) |
| 893 |
{ |
| 894 |
obstack_grow (&m_string_obstack, name, strlen (name)); |
| 895 |
} |
| 896 |
|
| 897 |
/* Zero-terminate and complete the function name being built. */ |
| 898 |
char * |
| 899 |
function_builder::finish_name () |
| 900 |
{ |
| 901 |
obstack_1grow (&m_string_obstack, 0); |
| 902 |
return (char *) obstack_finish (&m_string_obstack); |
| 903 |
} |
| 904 |
|
| 905 |
/* Return the overloaded or full function name for INSTANCE, with optional |
| 906 |
prefix; PRESERVE_USER_NAMESPACE selects the prefix, and OVERLOADED_P |
| 907 |
selects which the overloaded or full function name. Allocate the string on |
| 908 |
m_string_obstack; the caller must use obstack_free to free it after use. */ |
| 909 |
char * |
| 910 |
function_builder::get_name (const function_instance &instance, |
| 911 |
bool preserve_user_namespace, |
| 912 |
bool overloaded_p) |
| 913 |
{ |
| 914 |
if (preserve_user_namespace) |
| 915 |
append_name ("__arm_"); |
| 916 |
append_name (instance.base_name); |
| 917 |
|
| 918 |
if (instance.shape->mode_after_pred ()) |
| 919 |
append_name (pred_suffixes[instance.pred]); |
| 920 |
|
| 921 |
if (!overloaded_p |
| 922 |
|| instance.shape->explicit_mode_suffix_p (instance.pred, |
| 923 |
instance.mode_suffix_id)) |
| 924 |
append_name (instance.mode_suffix ().string); |
| 925 |
|
| 926 |
if (!instance.shape->mode_after_pred ()) |
| 927 |
append_name (pred_suffixes[instance.pred]); |
| 928 |
|
| 929 |
for (unsigned int i = 0; i < 2; ++i) |
| 930 |
if (!overloaded_p |
| 931 |
|| instance.shape->explicit_type_suffix_p (i, instance.pred, |
| 932 |
instance.mode_suffix_id, |
| 933 |
instance.type_suffix (i))) |
| 934 |
append_name (instance.type_suffix (i).string); |
| 935 |
return finish_name (); |
| 936 |
} |
| 937 |
|
| 938 |
/* Add attribute NAME to ATTRS. */ |
| 939 |
static tree |
| 940 |
add_attribute (const char *name, tree attrs) |
| 941 |
{ |
| 942 |
return tree_cons (get_identifier (name), NULL_TREE, attrs); |
| 943 |
} |
| 944 |
|
| 945 |
/* Return the appropriate function attributes for INSTANCE. */ |
| 946 |
tree |
| 947 |
function_builder::get_attributes (const function_instance &instance) |
| 948 |
{ |
| 949 |
tree attrs = NULL_TREE; |
| 950 |
|
| 951 |
if (!instance.modifies_global_state_p ()) |
| 952 |
{ |
| 953 |
if (instance.reads_global_state_p ()) |
| 954 |
attrs = add_attribute ("pure", attrs); |
| 955 |
else |
| 956 |
attrs = add_attribute ("const", attrs); |
| 957 |
} |
| 958 |
|
| 959 |
if (!flag_non_call_exceptions || !instance.could_trap_p ()) |
| 960 |
attrs = add_attribute ("nothrow", attrs); |
| 961 |
|
| 962 |
return add_attribute ("leaf", attrs); |
| 963 |
} |
| 964 |
|
| 965 |
/* Add a function called NAME with type FNTYPE and attributes ATTRS. |
| 966 |
INSTANCE describes what the function does and OVERLOADED_P indicates |
| 967 |
whether it is overloaded. REQUIRES_FLOAT indicates whether the function |
| 968 |
requires the mve.fp extension. */ |
| 969 |
registered_function & |
| 970 |
function_builder::add_function (const function_instance &instance, |
| 971 |
const char *name, tree fntype, tree attrs, |
| 972 |
bool requires_float, |
| 973 |
bool overloaded_p, |
| 974 |
bool placeholder_p) |
| 975 |
{ |
| 976 |
unsigned int code = vec_safe_length (registered_functions); |
| 977 |
code = (code << ARM_BUILTIN_SHIFT) | ARM_BUILTIN_MVE; |
| 978 |
|
| 979 |
/* We need to be able to generate placeholders to ensure that we have a |
| 980 |
consistent numbering scheme for function codes between the C and C++ |
| 981 |
frontends, so that everything ties up in LTO. |
| 982 |
|
| 983 |
Currently, tree-streamer-in.cc:unpack_ts_function_decl_value_fields |
| 984 |
validates that tree nodes returned by TARGET_BUILTIN_DECL are non-NULL and |
| 985 |
some node other than error_mark_node. This is a holdover from when builtin |
| 986 |
decls were streamed by code rather than by value. |
| 987 |
|
| 988 |
Ultimately, we should be able to remove this validation of BUILT_IN_MD |
| 989 |
nodes and remove the target hook. For now, however, we need to appease the |
| 990 |
validation and return a non-NULL, non-error_mark_node node, so we |
| 991 |
arbitrarily choose integer_zero_node. */ |
| 992 |
tree decl = placeholder_p |
| 993 |
? integer_zero_node |
| 994 |
: simulate_builtin_function_decl (input_location, name, fntype, |
| 995 |
code, NULL, attrs); |
| 996 |
registered_function &rfn = *ggc_alloc <registered_function> (); |
| 997 |
rfn.instance = instance; |
| 998 |
rfn.decl = decl; |
| 999 |
rfn.requires_float = requires_float; |
| 1000 |
rfn.overloaded_p = overloaded_p; |
| 1001 |
vec_safe_push (registered_functions, &rfn); |
| 1002 |
|
| 1003 |
return rfn; |
| 1004 |
} |
| 1005 |
|
| 1006 |
/* Add a built-in function for INSTANCE, with the argument types given |
| 1007 |
by ARGUMENT_TYPES and the return type given by RETURN_TYPE. |
| 1008 |
REQUIRES_FLOAT indicates whether the function requires the mve.fp extension, |
| 1009 |
and PRESERVE_USER_NAMESPACE indicates whether the function should also be |
| 1010 |
registered under its non-prefixed name. */ |
| 1011 |
void |
| 1012 |
function_builder::add_unique_function (const function_instance &instance, |
| 1013 |
tree return_type, |
| 1014 |
vec<tree> &argument_types, |
| 1015 |
bool preserve_user_namespace, |
| 1016 |
bool requires_float, |
| 1017 |
bool force_direct_overloads) |
| 1018 |
{ |
| 1019 |
/* Add the function under its full (unique) name with prefix. */ |
| 1020 |
char *name = get_name (instance, true, false); |
| 1021 |
tree fntype = build_function_type_array (return_type, |
| 1022 |
argument_types.length (), |
| 1023 |
argument_types.address ()); |
| 1024 |
tree attrs = get_attributes (instance); |
| 1025 |
registered_function &rfn = add_function (instance, name, fntype, attrs, |
| 1026 |
requires_float, false, false); |
| 1027 |
|
| 1028 |
/* Enter the function into the hash table. */ |
| 1029 |
hashval_t hash = instance.hash (); |
| 1030 |
registered_function **rfn_slot |
| 1031 |
= function_table->find_slot_with_hash (instance, hash, INSERT); |
| 1032 |
gcc_assert (!*rfn_slot); |
| 1033 |
*rfn_slot = &rfn; |
| 1034 |
|
| 1035 |
/* Also add the non-prefixed non-overloaded function, as placeholder |
| 1036 |
if the user namespace does not need to be preserved. */ |
| 1037 |
char *noprefix_name = get_name (instance, false, false); |
| 1038 |
attrs = get_attributes (instance); |
| 1039 |
add_function (instance, noprefix_name, fntype, attrs, requires_float, |
| 1040 |
false, preserve_user_namespace); |
| 1041 |
|
| 1042 |
/* Also add the function under its overloaded alias, if we want |
| 1043 |
a separate decl for each instance of an overloaded function. */ |
| 1044 |
char *overload_name = get_name (instance, true, true); |
| 1045 |
if (strcmp (name, overload_name) != 0) |
| 1046 |
{ |
| 1047 |
/* Attribute lists shouldn't be shared. */ |
| 1048 |
attrs = get_attributes (instance); |
| 1049 |
bool placeholder_p = !(m_direct_overloads || force_direct_overloads); |
| 1050 |
add_function (instance, overload_name, fntype, attrs, |
| 1051 |
requires_float, false, placeholder_p); |
| 1052 |
|
| 1053 |
/* Also add the non-prefixed overloaded function, as placeholder |
| 1054 |
if the user namespace does not need to be preserved. */ |
| 1055 |
char *noprefix_overload_name = get_name (instance, false, true); |
| 1056 |
attrs = get_attributes (instance); |
| 1057 |
add_function (instance, noprefix_overload_name, fntype, attrs, |
| 1058 |
requires_float, false, preserve_user_namespace || placeholder_p); |
| 1059 |
} |
| 1060 |
|
| 1061 |
obstack_free (&m_string_obstack, name); |
| 1062 |
} |
| 1063 |
|
| 1064 |
/* Add one function decl for INSTANCE, to be used with manual overload |
| 1065 |
resolution. REQUIRES_FLOAT indicates whether the function requires the |
| 1066 |
mve.fp extension. |
| 1067 |
|
| 1068 |
For simplicity, partition functions by instance and required extensions, |
| 1069 |
and check whether the required extensions are available as part of resolving |
| 1070 |
the function to the relevant unique function. */ |
| 1071 |
void |
| 1072 |
function_builder::add_overloaded_function (const function_instance &instance, |
| 1073 |
bool preserve_user_namespace, |
| 1074 |
bool requires_float) |
| 1075 |
{ |
| 1076 |
char *name = get_name (instance, true, true); |
| 1077 |
if (registered_function **map_value = m_overload_names.get (name)) |
| 1078 |
{ |
| 1079 |
gcc_assert ((*map_value)->instance == instance); |
| 1080 |
obstack_free (&m_string_obstack, name); |
| 1081 |
} |
| 1082 |
else |
| 1083 |
{ |
| 1084 |
registered_function &rfn |
| 1085 |
= add_function (instance, name, m_overload_type, NULL_TREE, |
| 1086 |
requires_float, true, m_direct_overloads); |
| 1087 |
m_overload_names.put (name, &rfn); |
| 1088 |
|
| 1089 |
/* Also add the non-prefixed function, as placeholder if the |
| 1090 |
user namespace does not need to be preserved. */ |
| 1091 |
char *noprefix_name = get_name (instance, false, true); |
| 1092 |
registered_function &noprefix_rfn |
| 1093 |
= add_function (instance, noprefix_name, m_overload_type, |
| 1094 |
NULL_TREE, requires_float, true, |
| 1095 |
preserve_user_namespace || m_direct_overloads); |
| 1096 |
m_overload_names.put (noprefix_name, &noprefix_rfn); |
| 1097 |
} |
| 1098 |
} |
| 1099 |
|
| 1100 |
/* If we are using manual overload resolution, add one function decl |
| 1101 |
for each overloaded function in GROUP. Take the function base name |
| 1102 |
from GROUP and the mode from MODE. */ |
| 1103 |
void |
| 1104 |
function_builder::add_overloaded_functions (const function_group_info &group, |
| 1105 |
mode_suffix_index mode, |
| 1106 |
bool preserve_user_namespace) |
| 1107 |
{ |
| 1108 |
for (unsigned int pi = 0; group.preds[pi] != NUM_PREDS; ++pi) |
| 1109 |
{ |
| 1110 |
unsigned int explicit_type0 |
| 1111 |
= (*group.shape)->explicit_type_suffix_p (0, group.preds[pi], mode, |
| 1112 |
type_suffixes[NUM_TYPE_SUFFIXES]); |
| 1113 |
unsigned int explicit_type1 |
| 1114 |
= (*group.shape)->explicit_type_suffix_p (1, group.preds[pi], mode, |
| 1115 |
type_suffixes[NUM_TYPE_SUFFIXES]); |
| 1116 |
|
| 1117 |
if ((*group.shape)->skip_overload_p (group.preds[pi], mode)) |
| 1118 |
continue; |
| 1119 |
|
| 1120 |
if (!explicit_type0 && !explicit_type1) |
| 1121 |
{ |
| 1122 |
/* Deal with the common case in which there is one overloaded |
| 1123 |
function for all type combinations. */ |
| 1124 |
function_instance instance (group.base_name, *group.base, |
| 1125 |
*group.shape, mode, types_none[0], |
| 1126 |
group.preds[pi]); |
| 1127 |
add_overloaded_function (instance, preserve_user_namespace, |
| 1128 |
group.requires_float); |
| 1129 |
} |
| 1130 |
else |
| 1131 |
for (unsigned int ti = 0; group.types[ti][0] != NUM_TYPE_SUFFIXES; |
| 1132 |
++ti) |
| 1133 |
{ |
| 1134 |
/* Stub out the types that are determined by overload |
| 1135 |
resolution. */ |
| 1136 |
type_suffix_pair types = { |
| 1137 |
explicit_type0 ? group.types[ti][0] : NUM_TYPE_SUFFIXES, |
| 1138 |
explicit_type1 ? group.types[ti][1] : NUM_TYPE_SUFFIXES |
| 1139 |
}; |
| 1140 |
function_instance instance (group.base_name, *group.base, |
| 1141 |
*group.shape, mode, types, |
| 1142 |
group.preds[pi]); |
| 1143 |
add_overloaded_function (instance, preserve_user_namespace, |
| 1144 |
group.requires_float); |
| 1145 |
} |
| 1146 |
} |
| 1147 |
} |
| 1148 |
|
| 1149 |
/* Register all the functions in GROUP. */ |
| 1150 |
void |
| 1151 |
function_builder::register_function_group (const function_group_info &group, |
| 1152 |
bool preserve_user_namespace) |
| 1153 |
{ |
| 1154 |
(*group.shape)->build (*this, group, preserve_user_namespace); |
| 1155 |
} |
| 1156 |
|
| 1157 |
function_call_info::function_call_info (location_t location_in, |
| 1158 |
const function_instance &instance_in, |
| 1159 |
tree fndecl_in) |
| 1160 |
: function_instance (instance_in), location (location_in), fndecl (fndecl_in) |
| 1161 |
{ |
| 1162 |
} |
| 1163 |
|
| 1164 |
function_resolver::function_resolver (location_t location, |
| 1165 |
const function_instance &instance, |
| 1166 |
tree fndecl, vec<tree, va_gc> &arglist) |
| 1167 |
: function_call_info (location, instance, fndecl), m_arglist (arglist) |
| 1168 |
{ |
| 1169 |
} |
| 1170 |
|
| 1171 |
/* Return the vector type associated with type suffix TYPE. */ |
| 1172 |
tree |
| 1173 |
function_resolver::get_vector_type (type_suffix_index type) |
| 1174 |
{ |
| 1175 |
return acle_vector_types[0][type_suffixes[type].vector_type]; |
| 1176 |
} |
| 1177 |
|
| 1178 |
/* Return the <stdint.h> name associated with TYPE. Using the <stdint.h> |
| 1179 |
name should be more user-friendly than the underlying canonical type, |
| 1180 |
since it makes the signedness and bitwidth explicit. */ |
| 1181 |
const char * |
| 1182 |
function_resolver::get_scalar_type_name (type_suffix_index type) |
| 1183 |
{ |
| 1184 |
return vector_types[type_suffixes[type].vector_type].acle_name + 2; |
| 1185 |
} |
| 1186 |
|
| 1187 |
/* Return the type of argument I, or error_mark_node if it isn't |
| 1188 |
well-formed. */ |
| 1189 |
tree |
| 1190 |
function_resolver::get_argument_type (unsigned int i) |
| 1191 |
{ |
| 1192 |
tree arg = m_arglist[i]; |
| 1193 |
return arg == error_mark_node ? arg : TREE_TYPE (arg); |
| 1194 |
} |
| 1195 |
|
| 1196 |
/* Return true if argument I is some form of scalar value. */ |
| 1197 |
bool |
| 1198 |
function_resolver::scalar_argument_p (unsigned int i) |
| 1199 |
{ |
| 1200 |
tree type = get_argument_type (i); |
| 1201 |
return (INTEGRAL_TYPE_P (type) |
| 1202 |
/* Allow pointer types, leaving the frontend to warn where |
| 1203 |
necessary. */ |
| 1204 |
|| POINTER_TYPE_P (type) |
| 1205 |
|| SCALAR_FLOAT_TYPE_P (type)); |
| 1206 |
} |
| 1207 |
|
| 1208 |
/* Report that the function has no form that takes type suffix TYPE. |
| 1209 |
Return error_mark_node. */ |
| 1210 |
tree |
| 1211 |
function_resolver::report_no_such_form (type_suffix_index type) |
| 1212 |
{ |
| 1213 |
error_at (location, "%qE has no form that takes %qT arguments", |
| 1214 |
fndecl, get_vector_type (type)); |
| 1215 |
return error_mark_node; |
| 1216 |
} |
| 1217 |
|
| 1218 |
/* Silently check whether there is an instance of the function with the |
| 1219 |
mode suffix given by MODE and the type suffixes given by TYPE0 and TYPE1. |
| 1220 |
Return its function decl if so, otherwise return null. */ |
| 1221 |
tree |
| 1222 |
function_resolver::lookup_form (mode_suffix_index mode, |
| 1223 |
type_suffix_index type0, |
| 1224 |
type_suffix_index type1) |
| 1225 |
{ |
| 1226 |
type_suffix_pair types = { type0, type1 }; |
| 1227 |
function_instance instance (base_name, base, shape, mode, types, pred); |
| 1228 |
registered_function *rfn |
| 1229 |
= function_table->find_with_hash (instance, instance.hash ()); |
| 1230 |
return rfn ? rfn->decl : NULL_TREE; |
| 1231 |
} |
| 1232 |
|
| 1233 |
/* Resolve the function to one with the mode suffix given by MODE and the |
| 1234 |
type suffixes given by TYPE0 and TYPE1. Return its function decl on |
| 1235 |
success, otherwise report an error and return error_mark_node. */ |
| 1236 |
tree |
| 1237 |
function_resolver::resolve_to (mode_suffix_index mode, |
| 1238 |
type_suffix_index type0, |
| 1239 |
type_suffix_index type1) |
| 1240 |
{ |
| 1241 |
tree res = lookup_form (mode, type0, type1); |
| 1242 |
if (!res) |
| 1243 |
{ |
| 1244 |
if (type1 == NUM_TYPE_SUFFIXES) |
| 1245 |
return report_no_such_form (type0); |
| 1246 |
if (type0 == type_suffix_ids[0]) |
| 1247 |
return report_no_such_form (type1); |
| 1248 |
/* To be filled in when we have other cases. */ |
| 1249 |
gcc_unreachable (); |
| 1250 |
} |
| 1251 |
return res; |
| 1252 |
} |
| 1253 |
|
| 1254 |
/* Require argument ARGNO to be a pointer to a scalar type that has a |
| 1255 |
corresponding type suffix. Return that type suffix on success, |
| 1256 |
otherwise report an error and return NUM_TYPE_SUFFIXES. */ |
| 1257 |
type_suffix_index |
| 1258 |
function_resolver::infer_pointer_type (unsigned int argno) |
| 1259 |
{ |
| 1260 |
tree actual = get_argument_type (argno); |
| 1261 |
if (actual == error_mark_node) |
| 1262 |
return NUM_TYPE_SUFFIXES; |
| 1263 |
|
| 1264 |
if (TREE_CODE (actual) != POINTER_TYPE) |
| 1265 |
{ |
| 1266 |
error_at (location, "passing %qT to argument %d of %qE, which" |
| 1267 |
" expects a pointer type", actual, argno + 1, fndecl); |
| 1268 |
return NUM_TYPE_SUFFIXES; |
| 1269 |
} |
| 1270 |
|
| 1271 |
tree target = TREE_TYPE (actual); |
| 1272 |
type_suffix_index type = find_type_suffix_for_scalar_type (target); |
| 1273 |
if (type == NUM_TYPE_SUFFIXES) |
| 1274 |
{ |
| 1275 |
error_at (location, "passing %qT to argument %d of %qE, but %qT is not" |
| 1276 |
" a valid MVE element type", actual, argno + 1, fndecl, |
| 1277 |
build_qualified_type (target, 0)); |
| 1278 |
return NUM_TYPE_SUFFIXES; |
| 1279 |
} |
| 1280 |
|
| 1281 |
return type; |
| 1282 |
} |
| 1283 |
|
| 1284 |
/* Require argument ARGNO to be a single vector or a tuple of NUM_VECTORS |
| 1285 |
vectors; NUM_VECTORS is 1 for the former. Return the associated type |
| 1286 |
suffix on success, using TYPE_SUFFIX_b for predicates. Report an error |
| 1287 |
and return NUM_TYPE_SUFFIXES on failure. */ |
| 1288 |
type_suffix_index |
| 1289 |
function_resolver::infer_vector_or_tuple_type (unsigned int argno, |
| 1290 |
unsigned int num_vectors) |
| 1291 |
{ |
| 1292 |
tree actual = get_argument_type (argno); |
| 1293 |
if (actual == error_mark_node) |
| 1294 |
return NUM_TYPE_SUFFIXES; |
| 1295 |
|
| 1296 |
/* A linear search should be OK here, since the code isn't hot and |
| 1297 |
the number of types is only small. */ |
| 1298 |
for (unsigned int size_i = 0; size_i < MAX_TUPLE_SIZE; ++size_i) |
| 1299 |
for (unsigned int suffix_i = 0; suffix_i < NUM_TYPE_SUFFIXES; ++suffix_i) |
| 1300 |
{ |
| 1301 |
vector_type_index type_i = type_suffixes[suffix_i].vector_type; |
| 1302 |
tree type = acle_vector_types[size_i][type_i]; |
| 1303 |
if (type && matches_type_p (type, actual)) |
| 1304 |
{ |
| 1305 |
if (size_i == (num_vectors >> 1)) |
| 1306 |
return type_suffix_index (suffix_i); |
| 1307 |
|
| 1308 |
if (num_vectors == 1) |
| 1309 |
error_at (location, "passing %qT to argument %d of %qE, which" |
| 1310 |
" expects a single MVE vector rather than a tuple", |
| 1311 |
actual, argno + 1, fndecl); |
| 1312 |
else if (size_i == 0 && type_i != VECTOR_TYPE_mve_pred16_t) |
| 1313 |
/* num_vectors is always != 1, so the singular isn't needed. */ |
| 1314 |
error_n (location, num_vectors, "%qT%d%qE%d", |
| 1315 |
"passing single vector %qT to argument %d" |
| 1316 |
" of %qE, which expects a tuple of %d vectors", |
| 1317 |
actual, argno + 1, fndecl, num_vectors); |
| 1318 |
else |
| 1319 |
/* num_vectors is always != 1, so the singular isn't needed. */ |
| 1320 |
error_n (location, num_vectors, "%qT%d%qE%d", |
| 1321 |
"passing %qT to argument %d of %qE, which" |
| 1322 |
" expects a tuple of %d vectors", actual, argno + 1, |
| 1323 |
fndecl, num_vectors); |
| 1324 |
return NUM_TYPE_SUFFIXES; |
| 1325 |
} |
| 1326 |
} |
| 1327 |
|
| 1328 |
if (num_vectors == 1) |
| 1329 |
error_at (location, "passing %qT to argument %d of %qE, which" |
| 1330 |
" expects an MVE vector type", actual, argno + 1, fndecl); |
| 1331 |
else |
| 1332 |
error_at (location, "passing %qT to argument %d of %qE, which" |
| 1333 |
" expects an MVE tuple type", actual, argno + 1, fndecl); |
| 1334 |
return NUM_TYPE_SUFFIXES; |
| 1335 |
} |
| 1336 |
|
| 1337 |
/* Require argument ARGNO to have some form of vector type. Return the |
| 1338 |
associated type suffix on success, using TYPE_SUFFIX_b for predicates. |
| 1339 |
Report an error and return NUM_TYPE_SUFFIXES on failure. */ |
| 1340 |
type_suffix_index |
| 1341 |
function_resolver::infer_vector_type (unsigned int argno) |
| 1342 |
{ |
| 1343 |
return infer_vector_or_tuple_type (argno, 1); |
| 1344 |
} |
| 1345 |
|
| 1346 |
/* If the function operates on tuples of vectors, require argument ARGNO to be |
| 1347 |
a tuple with the appropriate number of vectors, otherwise require it to be a |
| 1348 |
single vector. Return the associated type suffix on success. Report an |
| 1349 |
error and return NUM_TYPE_SUFFIXES on failure. */ |
| 1350 |
type_suffix_index |
| 1351 |
function_resolver::infer_tuple_type (unsigned int argno) |
| 1352 |
{ |
| 1353 |
return infer_vector_or_tuple_type (argno, vectors_per_tuple ()); |
| 1354 |
} |
| 1355 |
|
| 1356 |
/* Require argument ARGNO to be a vector or scalar argument. Return true |
| 1357 |
if it is, otherwise report an appropriate error. */ |
| 1358 |
bool |
| 1359 |
function_resolver::require_vector_or_scalar_type (unsigned int argno) |
| 1360 |
{ |
| 1361 |
tree actual = get_argument_type (argno); |
| 1362 |
if (actual == error_mark_node) |
| 1363 |
return false; |
| 1364 |
|
| 1365 |
if (!scalar_argument_p (argno) && !VECTOR_TYPE_P (actual)) |
| 1366 |
{ |
| 1367 |
error_at (location, "passing %qT to argument %d of %qE, which" |
| 1368 |
" expects a vector or scalar type", actual, argno + 1, fndecl); |
| 1369 |
return false; |
| 1370 |
} |
| 1371 |
|
| 1372 |
return true; |
| 1373 |
} |
| 1374 |
|
| 1375 |
/* Require argument ARGNO to have vector type TYPE, in cases where this |
| 1376 |
requirement holds for all uses of the function. Return true if the |
| 1377 |
argument has the right form, otherwise report an appropriate error. */ |
| 1378 |
bool |
| 1379 |
function_resolver::require_vector_type (unsigned int argno, |
| 1380 |
vector_type_index type) |
| 1381 |
{ |
| 1382 |
tree expected = acle_vector_types[0][type]; |
| 1383 |
tree actual = get_argument_type (argno); |
| 1384 |
if (actual == error_mark_node) |
| 1385 |
return false; |
| 1386 |
|
| 1387 |
if (!matches_type_p (expected, actual)) |
| 1388 |
{ |
| 1389 |
error_at (location, "passing %qT to argument %d of %qE, which" |
| 1390 |
" expects %qT", actual, argno + 1, fndecl, expected); |
| 1391 |
return false; |
| 1392 |
} |
| 1393 |
return true; |
| 1394 |
} |
| 1395 |
|
| 1396 |
/* Like require_vector_type, but TYPE is inferred from previous arguments |
| 1397 |
rather than being a fixed part of the function signature. This changes |
| 1398 |
the nature of the error messages. */ |
| 1399 |
bool |
| 1400 |
function_resolver::require_matching_vector_type (unsigned int argno, |
| 1401 |
type_suffix_index type) |
| 1402 |
{ |
| 1403 |
type_suffix_index new_type = infer_vector_type (argno); |
| 1404 |
if (new_type == NUM_TYPE_SUFFIXES) |
| 1405 |
return false; |
| 1406 |
|
| 1407 |
if (type != new_type) |
| 1408 |
{ |
| 1409 |
error_at (location, "passing %qT to argument %d of %qE, but" |
| 1410 |
" previous arguments had type %qT", |
| 1411 |
get_vector_type (new_type), argno + 1, fndecl, |
| 1412 |
get_vector_type (type)); |
| 1413 |
return false; |
| 1414 |
} |
| 1415 |
return true; |
| 1416 |
} |
| 1417 |
|
| 1418 |
/* Require argument ARGNO to be a vector type with the following properties: |
| 1419 |
|
| 1420 |
- the type class must be the same as FIRST_TYPE's if EXPECTED_TCLASS |
| 1421 |
is SAME_TYPE_CLASS, otherwise it must be EXPECTED_TCLASS itself. |
| 1422 |
|
| 1423 |
- the element size must be: |
| 1424 |
|
| 1425 |
- the same as FIRST_TYPE's if EXPECTED_BITS == SAME_SIZE |
| 1426 |
- half of FIRST_TYPE's if EXPECTED_BITS == HALF_SIZE |
| 1427 |
- a quarter of FIRST_TYPE's if EXPECTED_BITS == QUARTER_SIZE |
| 1428 |
- EXPECTED_BITS itself otherwise |
| 1429 |
|
| 1430 |
Return true if the argument has the required type, otherwise report |
| 1431 |
an appropriate error. |
| 1432 |
|
| 1433 |
FIRST_ARGNO is the first argument that is known to have type FIRST_TYPE. |
| 1434 |
Usually it comes before ARGNO, but sometimes it is more natural to resolve |
| 1435 |
arguments out of order. |
| 1436 |
|
| 1437 |
If the required properties depend on FIRST_TYPE then both FIRST_ARGNO and |
| 1438 |
ARGNO contribute to the resolution process. If the required properties |
| 1439 |
are fixed, only FIRST_ARGNO contributes to the resolution process. |
| 1440 |
|
| 1441 |
This function is a bit of a Swiss army knife. The complication comes |
| 1442 |
from trying to give good error messages when FIRST_ARGNO and ARGNO are |
| 1443 |
inconsistent, since either of them might be wrong. */ |
| 1444 |
bool function_resolver:: |
| 1445 |
require_derived_vector_type (unsigned int argno, |
| 1446 |
unsigned int first_argno, |
| 1447 |
type_suffix_index first_type, |
| 1448 |
type_class_index expected_tclass, |
| 1449 |
unsigned int expected_bits) |
| 1450 |
{ |
| 1451 |
/* If the type needs to match FIRST_ARGNO exactly, use the preferred |
| 1452 |
error message for that case. The VECTOR_TYPE_P test excludes tuple |
| 1453 |
types, which we handle below instead. */ |
| 1454 |
bool both_vectors_p = VECTOR_TYPE_P (get_argument_type (first_argno)); |
| 1455 |
if (both_vectors_p |
| 1456 |
&& expected_tclass == SAME_TYPE_CLASS |
| 1457 |
&& expected_bits == SAME_SIZE) |
| 1458 |
{ |
| 1459 |
/* There's no need to resolve this case out of order. */ |
| 1460 |
gcc_assert (argno > first_argno); |
| 1461 |
return require_matching_vector_type (argno, first_type); |
| 1462 |
} |
| 1463 |
|
| 1464 |
/* Use FIRST_TYPE to get the expected type class and element size. */ |
| 1465 |
type_class_index orig_expected_tclass = expected_tclass; |
| 1466 |
if (expected_tclass == NUM_TYPE_CLASSES) |
| 1467 |
expected_tclass = type_suffixes[first_type].tclass; |
| 1468 |
|
| 1469 |
unsigned int orig_expected_bits = expected_bits; |
| 1470 |
if (expected_bits == SAME_SIZE) |
| 1471 |
expected_bits = type_suffixes[first_type].element_bits; |
| 1472 |
else if (expected_bits == HALF_SIZE) |
| 1473 |
expected_bits = type_suffixes[first_type].element_bits / 2; |
| 1474 |
else if (expected_bits == QUARTER_SIZE) |
| 1475 |
expected_bits = type_suffixes[first_type].element_bits / 4; |
| 1476 |
|
| 1477 |
/* If the expected type doesn't depend on FIRST_TYPE at all, |
| 1478 |
just check for the fixed choice of vector type. */ |
| 1479 |
if (expected_tclass == orig_expected_tclass |
| 1480 |
&& expected_bits == orig_expected_bits) |
| 1481 |
{ |
| 1482 |
const type_suffix_info &expected_suffix |
| 1483 |
= type_suffixes[find_type_suffix (expected_tclass, expected_bits)]; |
| 1484 |
return require_vector_type (argno, expected_suffix.vector_type); |
| 1485 |
} |
| 1486 |
|
| 1487 |
/* Require the argument to be some form of MVE vector type, |
| 1488 |
without being specific about the type of vector we want. */ |
| 1489 |
type_suffix_index actual_type = infer_vector_type (argno); |
| 1490 |
if (actual_type == NUM_TYPE_SUFFIXES) |
| 1491 |
return false; |
| 1492 |
|
| 1493 |
/* Exit now if we got the right type. */ |
| 1494 |
bool tclass_ok_p = (type_suffixes[actual_type].tclass == expected_tclass); |
| 1495 |
bool size_ok_p = (type_suffixes[actual_type].element_bits == expected_bits); |
| 1496 |
if (tclass_ok_p && size_ok_p) |
| 1497 |
return true; |
| 1498 |
|
| 1499 |
/* First look for cases in which the actual type contravenes a fixed |
| 1500 |
size requirement, without having to refer to FIRST_TYPE. */ |
| 1501 |
if (!size_ok_p && expected_bits == orig_expected_bits) |
| 1502 |
{ |
| 1503 |
error_at (location, "passing %qT to argument %d of %qE, which" |
| 1504 |
" expects a vector of %d-bit elements", |
| 1505 |
get_vector_type (actual_type), argno + 1, fndecl, |
| 1506 |
expected_bits); |
| 1507 |
return false; |
| 1508 |
} |
| 1509 |
|
| 1510 |
/* Likewise for a fixed type class requirement. This is only ever |
| 1511 |
needed for signed and unsigned types, so don't create unnecessary |
| 1512 |
translation work for other type classes. */ |
| 1513 |
if (!tclass_ok_p && orig_expected_tclass == TYPE_signed) |
| 1514 |
{ |
| 1515 |
error_at (location, "passing %qT to argument %d of %qE, which" |
| 1516 |
" expects a vector of signed integers", |
| 1517 |
get_vector_type (actual_type), argno + 1, fndecl); |
| 1518 |
return false; |
| 1519 |
} |
| 1520 |
if (!tclass_ok_p && orig_expected_tclass == TYPE_unsigned) |
| 1521 |
{ |
| 1522 |
error_at (location, "passing %qT to argument %d of %qE, which" |
| 1523 |
" expects a vector of unsigned integers", |
| 1524 |
get_vector_type (actual_type), argno + 1, fndecl); |
| 1525 |
return false; |
| 1526 |
} |
| 1527 |
|
| 1528 |
/* Make sure that FIRST_TYPE itself is sensible before using it |
| 1529 |
as a basis for an error message. */ |
| 1530 |
if (resolve_to (mode_suffix_id, first_type) == error_mark_node) |
| 1531 |
return false; |
| 1532 |
|
| 1533 |
/* If the arguments have consistent type classes, but a link between |
| 1534 |
the sizes has been broken, try to describe the error in those terms. */ |
| 1535 |
if (both_vectors_p && tclass_ok_p && orig_expected_bits == SAME_SIZE) |
| 1536 |
{ |
| 1537 |
if (argno < first_argno) |
| 1538 |
{ |
| 1539 |
std::swap (argno, first_argno); |
| 1540 |
std::swap (actual_type, first_type); |
| 1541 |
} |
| 1542 |
error_at (location, "arguments %d and %d of %qE must have the" |
| 1543 |
" same element size, but the values passed here have type" |
| 1544 |
" %qT and %qT respectively", first_argno + 1, argno + 1, |
| 1545 |
fndecl, get_vector_type (first_type), |
| 1546 |
get_vector_type (actual_type)); |
| 1547 |
return false; |
| 1548 |
} |
| 1549 |
|
| 1550 |
/* Likewise in reverse: look for cases in which the sizes are consistent |
| 1551 |
but a link between the type classes has been broken. */ |
| 1552 |
if (both_vectors_p |
| 1553 |
&& size_ok_p |
| 1554 |
&& orig_expected_tclass == SAME_TYPE_CLASS |
| 1555 |
&& type_suffixes[first_type].integer_p |
| 1556 |
&& type_suffixes[actual_type].integer_p) |
| 1557 |
{ |
| 1558 |
if (argno < first_argno) |
| 1559 |
{ |
| 1560 |
std::swap (argno, first_argno); |
| 1561 |
std::swap (actual_type, first_type); |
| 1562 |
} |
| 1563 |
error_at (location, "arguments %d and %d of %qE must have the" |
| 1564 |
" same signedness, but the values passed here have type" |
| 1565 |
" %qT and %qT respectively", first_argno + 1, argno + 1, |
| 1566 |
fndecl, get_vector_type (first_type), |
| 1567 |
get_vector_type (actual_type)); |
| 1568 |
return false; |
| 1569 |
} |
| 1570 |
|
| 1571 |
/* The two arguments are wildly inconsistent. */ |
| 1572 |
type_suffix_index expected_type |
| 1573 |
= find_type_suffix (expected_tclass, expected_bits); |
| 1574 |
error_at (location, "passing %qT instead of the expected %qT to argument" |
| 1575 |
" %d of %qE, after passing %qT to argument %d", |
| 1576 |
get_vector_type (actual_type), get_vector_type (expected_type), |
| 1577 |
argno + 1, fndecl, get_argument_type (first_argno), |
| 1578 |
first_argno + 1); |
| 1579 |
return false; |
| 1580 |
} |
| 1581 |
|
| 1582 |
/* Require argument ARGNO to be a (possibly variable) scalar, expecting it |
| 1583 |
to have the following properties: |
| 1584 |
|
| 1585 |
- the type class must be the same as for type suffix 0 if EXPECTED_TCLASS |
| 1586 |
is SAME_TYPE_CLASS, otherwise it must be EXPECTED_TCLASS itself. |
| 1587 |
|
| 1588 |
- the element size must be the same as for type suffix 0 if EXPECTED_BITS |
| 1589 |
is SAME_TYPE_SIZE, otherwise it must be EXPECTED_BITS itself. |
| 1590 |
|
| 1591 |
Return true if the argument is valid, otherwise report an appropriate error. |
| 1592 |
|
| 1593 |
Note that we don't check whether the scalar type actually has the required |
| 1594 |
properties, since that's subject to implicit promotions and conversions. |
| 1595 |
Instead we just use the expected properties to tune the error message. */ |
| 1596 |
bool function_resolver:: |
| 1597 |
require_derived_scalar_type (unsigned int argno, |
| 1598 |
type_class_index expected_tclass, |
| 1599 |
unsigned int expected_bits) |
| 1600 |
{ |
| 1601 |
gcc_assert (expected_tclass == SAME_TYPE_CLASS |
| 1602 |
|| expected_tclass == TYPE_signed |
| 1603 |
|| expected_tclass == TYPE_unsigned); |
| 1604 |
|
| 1605 |
/* If the expected type doesn't depend on the type suffix at all, |
| 1606 |
just check for the fixed choice of scalar type. */ |
| 1607 |
if (expected_tclass != SAME_TYPE_CLASS && expected_bits != SAME_SIZE) |
| 1608 |
{ |
| 1609 |
type_suffix_index expected_type |
| 1610 |
= find_type_suffix (expected_tclass, expected_bits); |
| 1611 |
return require_scalar_type (argno, get_scalar_type_name (expected_type)); |
| 1612 |
} |
| 1613 |
|
| 1614 |
if (scalar_argument_p (argno)) |
| 1615 |
return true; |
| 1616 |
|
| 1617 |
if (expected_tclass == SAME_TYPE_CLASS) |
| 1618 |
/* It doesn't really matter whether the element is expected to be |
| 1619 |
the same size as type suffix 0. */ |
| 1620 |
error_at (location, "passing %qT to argument %d of %qE, which" |
| 1621 |
" expects a scalar element", get_argument_type (argno), |
| 1622 |
argno + 1, fndecl); |
| 1623 |
else |
| 1624 |
/* It doesn't seem useful to distinguish between signed and unsigned |
| 1625 |
scalars here. */ |
| 1626 |
error_at (location, "passing %qT to argument %d of %qE, which" |
| 1627 |
" expects a scalar integer", get_argument_type (argno), |
| 1628 |
argno + 1, fndecl); |
| 1629 |
return false; |
| 1630 |
} |
| 1631 |
|
| 1632 |
/* Require argument ARGNO to be suitable for an integer constant expression. |
| 1633 |
Return true if it is, otherwise report an appropriate error. |
| 1634 |
|
| 1635 |
function_checker checks whether the argument is actually constant and |
| 1636 |
has a suitable range. The reason for distinguishing immediate arguments |
| 1637 |
here is because it provides more consistent error messages than |
| 1638 |
require_scalar_type would. */ |
| 1639 |
bool |
| 1640 |
function_resolver::require_integer_immediate (unsigned int argno) |
| 1641 |
{ |
| 1642 |
if (!scalar_argument_p (argno)) |
| 1643 |
{ |
| 1644 |
report_non_ice (location, fndecl, argno); |
| 1645 |
return false; |
| 1646 |
} |
| 1647 |
return true; |
| 1648 |
} |
| 1649 |
|
| 1650 |
/* Require argument ARGNO to be a (possibly variable) scalar, using EXPECTED |
| 1651 |
as the name of its expected type. Return true if the argument has the |
| 1652 |
right form, otherwise report an appropriate error. */ |
| 1653 |
bool |
| 1654 |
function_resolver::require_scalar_type (unsigned int argno, |
| 1655 |
const char *expected) |
| 1656 |
{ |
| 1657 |
if (!scalar_argument_p (argno)) |
| 1658 |
{ |
| 1659 |
error_at (location, "passing %qT to argument %d of %qE, which" |
| 1660 |
" expects %qs", get_argument_type (argno), argno + 1, |
| 1661 |
fndecl, expected); |
| 1662 |
return false; |
| 1663 |
} |
| 1664 |
return true; |
| 1665 |
} |
| 1666 |
|
| 1667 |
/* Require argument ARGNO to be some form of pointer, without being specific |
| 1668 |
about its target type. Return true if the argument has the right form, |
| 1669 |
otherwise report an appropriate error. */ |
| 1670 |
bool |
| 1671 |
function_resolver::require_pointer_type (unsigned int argno) |
| 1672 |
{ |
| 1673 |
if (!scalar_argument_p (argno)) |
| 1674 |
{ |
| 1675 |
error_at (location, "passing %qT to argument %d of %qE, which" |
| 1676 |
" expects a scalar pointer", get_argument_type (argno), |
| 1677 |
argno + 1, fndecl); |
| 1678 |
return false; |
| 1679 |
} |
| 1680 |
return true; |
| 1681 |
} |
| 1682 |
|
| 1683 |
/* Require argument ARGNO to be a pointer to EXPECTED type. Return true on |
| 1684 |
success, otherwise report an error and return false. */ |
| 1685 |
bool |
| 1686 |
function_resolver::require_pointer_to_type (unsigned int argno, tree expected) |
| 1687 |
{ |
| 1688 |
tree actual = get_argument_type (argno); |
| 1689 |
if (TREE_CODE (actual) != POINTER_TYPE) |
| 1690 |
{ |
| 1691 |
error_at (location, "passing %qT to argument %d of %qE, which" |
| 1692 |
" expects a pointer type", actual, argno + 1, fndecl); |
| 1693 |
return false; |
| 1694 |
} |
| 1695 |
|
| 1696 |
tree target = TREE_TYPE (actual); |
| 1697 |
if (target != expected) |
| 1698 |
{ |
| 1699 |
error_at (location, "passing %qT to argument %d of %qE, which" |
| 1700 |
" expects a pointer to %qT", actual, argno + 1, fndecl, |
| 1701 |
expected); |
| 1702 |
return false; |
| 1703 |
} |
| 1704 |
|
| 1705 |
return true; |
| 1706 |
} |
| 1707 |
|
| 1708 |
/* Require the function to have exactly EXPECTED arguments. Return true |
| 1709 |
if it does, otherwise report an appropriate error. */ |
| 1710 |
bool |
| 1711 |
function_resolver::check_num_arguments (unsigned int expected) |
| 1712 |
{ |
| 1713 |
if (m_arglist.length () < expected) |
| 1714 |
error_at (location, "too few arguments to function %qE", fndecl); |
| 1715 |
else if (m_arglist.length () > expected) |
| 1716 |
error_at (location, "too many arguments to function %qE", fndecl); |
| 1717 |
return m_arglist.length () == expected; |
| 1718 |
} |
| 1719 |
|
| 1720 |
/* If the function is predicated, check that the last argument is a |
| 1721 |
suitable predicate. Also check that there are NOPS further |
| 1722 |
arguments before any predicate, but don't check what they are. |
| 1723 |
|
| 1724 |
Return true on success, otherwise report a suitable error. |
| 1725 |
When returning true: |
| 1726 |
|
| 1727 |
- set I to the number of the last unchecked argument. |
| 1728 |
- set NARGS to the total number of arguments. */ |
| 1729 |
bool |
| 1730 |
function_resolver::check_gp_argument (unsigned int nops, |
| 1731 |
unsigned int &i, unsigned int &nargs) |
| 1732 |
{ |
| 1733 |
i = nops - 1; |
| 1734 |
if (pred != PRED_none) |
| 1735 |
{ |
| 1736 |
switch (pred) |
| 1737 |
{ |
| 1738 |
case PRED_m: |
| 1739 |
/* Add first inactive argument if needed, and final predicate. */ |
| 1740 |
if (has_inactive_argument ()) |
| 1741 |
nargs = nops + 2; |
| 1742 |
else |
| 1743 |
nargs = nops + 1; |
| 1744 |
break; |
| 1745 |
|
| 1746 |
case PRED_p: |
| 1747 |
case PRED_x: |
| 1748 |
case PRED_z: |
| 1749 |
/* Add final predicate. */ |
| 1750 |
nargs = nops + 1; |
| 1751 |
break; |
| 1752 |
|
| 1753 |
default: |
| 1754 |
gcc_unreachable (); |
| 1755 |
} |
| 1756 |
|
| 1757 |
if (!check_num_arguments (nargs) |
| 1758 |
|| !require_vector_type (nargs - 1, VECTOR_TYPE_mve_pred16_t)) |
| 1759 |
return false; |
| 1760 |
|
| 1761 |
i = nargs - 2; |
| 1762 |
} |
| 1763 |
else |
| 1764 |
{ |
| 1765 |
nargs = nops; |
| 1766 |
if (!check_num_arguments (nargs)) |
| 1767 |
return false; |
| 1768 |
} |
| 1769 |
|
| 1770 |
return true; |
| 1771 |
} |
| 1772 |
|
| 1773 |
/* Finish resolving a function whose final argument can be a vector |
| 1774 |
or a scalar, with the function having an implicit "_n" suffix |
| 1775 |
in the latter case. This "_n" form might only exist for certain |
| 1776 |
type suffixes. |
| 1777 |
|
| 1778 |
ARGNO is the index of the final argument. The inferred type suffix |
| 1779 |
was obtained from argument FIRST_ARGNO, which has type FIRST_TYPE. |
| 1780 |
EXPECTED_TCLASS and EXPECTED_BITS describe the expected properties |
| 1781 |
of the final vector or scalar argument, in the same way as for |
| 1782 |
require_derived_vector_type. INFERRED_TYPE is the inferred type |
| 1783 |
suffix itself, or NUM_TYPE_SUFFIXES if it's the same as FIRST_TYPE. |
| 1784 |
|
| 1785 |
Return the function decl of the resolved function on success, |
| 1786 |
otherwise report a suitable error and return error_mark_node. */ |
| 1787 |
tree function_resolver:: |
| 1788 |
finish_opt_n_resolution (unsigned int argno, unsigned int first_argno, |
| 1789 |
type_suffix_index first_type, |
| 1790 |
type_class_index expected_tclass, |
| 1791 |
unsigned int expected_bits, |
| 1792 |
type_suffix_index inferred_type) |
| 1793 |
{ |
| 1794 |
if (inferred_type == NUM_TYPE_SUFFIXES) |
| 1795 |
inferred_type = first_type; |
| 1796 |
mode_suffix_index scalar_mode = MODE_n; |
| 1797 |
if (mode_suffix_id == MODE_r) |
| 1798 |
scalar_mode = MODE_r; |
| 1799 |
tree scalar_form = lookup_form (scalar_mode, inferred_type); |
| 1800 |
|
| 1801 |
/* Allow the final argument to be scalar, if an _n form exists. */ |
| 1802 |
if (scalar_argument_p (argno)) |
| 1803 |
{ |
| 1804 |
if (scalar_form) |
| 1805 |
return scalar_form; |
| 1806 |
|
| 1807 |
/* Check the vector form normally. If that succeeds, raise an |
| 1808 |
error about having no corresponding _n form. */ |
| 1809 |
tree res = resolve_to (mode_suffix_id, inferred_type); |
| 1810 |
if (res != error_mark_node) |
| 1811 |
error_at (location, "passing %qT to argument %d of %qE, but its" |
| 1812 |
" %qT form does not accept scalars", |
| 1813 |
get_argument_type (argno), argno + 1, fndecl, |
| 1814 |
get_vector_type (first_type)); |
| 1815 |
return error_mark_node; |
| 1816 |
} |
| 1817 |
|
| 1818 |
/* If an _n form does exist, provide a more accurate message than |
| 1819 |
require_derived_vector_type would for arguments that are neither |
| 1820 |
vectors nor scalars. */ |
| 1821 |
if (scalar_form && !require_vector_or_scalar_type (argno)) |
| 1822 |
return error_mark_node; |
| 1823 |
|
| 1824 |
/* Check for the correct vector type. */ |
| 1825 |
if (!require_derived_vector_type (argno, first_argno, first_type, |
| 1826 |
expected_tclass, expected_bits)) |
| 1827 |
return error_mark_node; |
| 1828 |
|
| 1829 |
return resolve_to (mode_suffix_id, inferred_type); |
| 1830 |
} |
| 1831 |
|
| 1832 |
/* Resolve a (possibly predicated) unary function. If the function uses |
| 1833 |
merge predication or if TREAT_AS_MERGE_P is true, there is an extra |
| 1834 |
vector argument before the governing predicate that specifies the |
| 1835 |
values of inactive elements. This argument has the following |
| 1836 |
properties: |
| 1837 |
|
| 1838 |
- the type class must be the same as for active elements if MERGE_TCLASS |
| 1839 |
is SAME_TYPE_CLASS, otherwise it must be MERGE_TCLASS itself. |
| 1840 |
|
| 1841 |
- the element size must be the same as for active elements if MERGE_BITS |
| 1842 |
is SAME_TYPE_SIZE, otherwise it must be MERGE_BITS itself. |
| 1843 |
|
| 1844 |
Return the function decl of the resolved function on success, |
| 1845 |
otherwise report a suitable error and return error_mark_node. */ |
| 1846 |
tree |
| 1847 |
function_resolver::resolve_unary (type_class_index merge_tclass, |
| 1848 |
unsigned int merge_bits, |
| 1849 |
bool treat_as_merge_p) |
| 1850 |
{ |
| 1851 |
type_suffix_index type; |
| 1852 |
if (pred == PRED_m || treat_as_merge_p) |
| 1853 |
{ |
| 1854 |
if (!check_num_arguments (3)) |
| 1855 |
return error_mark_node; |
| 1856 |
if (merge_tclass == SAME_TYPE_CLASS && merge_bits == SAME_SIZE) |
| 1857 |
{ |
| 1858 |
/* The inactive elements are the same as the active elements, |
| 1859 |
so we can use normal left-to-right resolution. */ |
| 1860 |
if ((type = infer_vector_type (0)) == NUM_TYPE_SUFFIXES |
| 1861 |
/* Predicates are the last argument. */ |
| 1862 |
|| !require_vector_type (2 , VECTOR_TYPE_mve_pred16_t) |
| 1863 |
|| !require_matching_vector_type (1 , type)) |
| 1864 |
return error_mark_node; |
| 1865 |
} |
| 1866 |
else |
| 1867 |
{ |
| 1868 |
/* The inactive element type is a function of the active one, |
| 1869 |
so resolve the active one first. */ |
| 1870 |
if (!require_vector_type (1, VECTOR_TYPE_mve_pred16_t) |
| 1871 |
|| (type = infer_vector_type (2)) == NUM_TYPE_SUFFIXES |
| 1872 |
|| !require_derived_vector_type (0, 2, type, merge_tclass, |
| 1873 |
merge_bits)) |
| 1874 |
return error_mark_node; |
| 1875 |
} |
| 1876 |
} |
| 1877 |
else |
| 1878 |
{ |
| 1879 |
/* We just need to check the predicate (if any) and the single |
| 1880 |
vector argument. */ |
| 1881 |
unsigned int i, nargs; |
| 1882 |
if (!check_gp_argument (1, i, nargs) |
| 1883 |
|| (type = infer_vector_type (i)) == NUM_TYPE_SUFFIXES) |
| 1884 |
return error_mark_node; |
| 1885 |
} |
| 1886 |
|
| 1887 |
/* Handle convert-like functions in which the first type suffix is |
| 1888 |
explicit. */ |
| 1889 |
if (type_suffix_ids[0] != NUM_TYPE_SUFFIXES) |
| 1890 |
return resolve_to (mode_suffix_id, type_suffix_ids[0], type); |
| 1891 |
|
| 1892 |
return resolve_to (mode_suffix_id, type); |
| 1893 |
} |
| 1894 |
|
| 1895 |
/* Resolve a (possibly predicated) unary function taking a scalar |
| 1896 |
argument (_n suffix). If the function uses merge predication, |
| 1897 |
there is an extra vector argument in the first position, and the |
| 1898 |
final governing predicate that specifies the values of inactive |
| 1899 |
elements. |
| 1900 |
|
| 1901 |
Return the function decl of the resolved function on success, |
| 1902 |
otherwise report a suitable error and return error_mark_node. */ |
| 1903 |
tree |
| 1904 |
function_resolver::resolve_unary_n () |
| 1905 |
{ |
| 1906 |
type_suffix_index type; |
| 1907 |
|
| 1908 |
/* Currently only support overrides for _m (vdupq). */ |
| 1909 |
if (pred != PRED_m) |
| 1910 |
return error_mark_node; |
| 1911 |
|
| 1912 |
if (pred == PRED_m) |
| 1913 |
{ |
| 1914 |
if (!check_num_arguments (3)) |
| 1915 |
return error_mark_node; |
| 1916 |
|
| 1917 |
/* The inactive elements are the same as the active elements, |
| 1918 |
so we can use normal left-to-right resolution. */ |
| 1919 |
if ((type = infer_vector_type (0)) == NUM_TYPE_SUFFIXES |
| 1920 |
/* Predicates are the last argument. */ |
| 1921 |
|| !require_vector_type (2 , VECTOR_TYPE_mve_pred16_t)) |
| 1922 |
return error_mark_node; |
| 1923 |
} |
| 1924 |
|
| 1925 |
/* Make sure the argument is scalar. */ |
| 1926 |
tree scalar_form = lookup_form (MODE_n, type); |
| 1927 |
|
| 1928 |
if (scalar_argument_p (1) && scalar_form) |
| 1929 |
return scalar_form; |
| 1930 |
|
| 1931 |
return error_mark_node; |
| 1932 |
} |
| 1933 |
|
| 1934 |
/* Resolve a (possibly predicated) function that takes NOPS like-typed |
| 1935 |
vector arguments followed by NIMM integer immediates. Return the |
| 1936 |
function decl of the resolved function on success, otherwise report |
| 1937 |
a suitable error and return error_mark_node. */ |
| 1938 |
tree |
| 1939 |
function_resolver::resolve_uniform (unsigned int nops, unsigned int nimm) |
| 1940 |
{ |
| 1941 |
unsigned int i, nargs; |
| 1942 |
type_suffix_index type; |
| 1943 |
if (!check_gp_argument (nops + nimm, i, nargs) |
| 1944 |
|| (type = infer_vector_type (0 )) == NUM_TYPE_SUFFIXES) |
| 1945 |
return error_mark_node; |
| 1946 |
|
| 1947 |
unsigned int last_arg = i + 1 - nimm; |
| 1948 |
for (i = 0; i < last_arg; i++) |
| 1949 |
if (!require_matching_vector_type (i, type)) |
| 1950 |
return error_mark_node; |
| 1951 |
|
| 1952 |
for (i = last_arg; i < nargs; ++i) |
| 1953 |
if (!require_integer_immediate (i)) |
| 1954 |
return error_mark_node; |
| 1955 |
|
| 1956 |
return resolve_to (mode_suffix_id, type); |
| 1957 |
} |
| 1958 |
|
| 1959 |
/* Resolve a (possibly predicated) function that offers a choice between |
| 1960 |
taking: |
| 1961 |
|
| 1962 |
- NOPS like-typed vector arguments or |
| 1963 |
- NOPS - 1 like-typed vector arguments followed by a scalar argument |
| 1964 |
|
| 1965 |
Return the function decl of the resolved function on success, |
| 1966 |
otherwise report a suitable error and return error_mark_node. */ |
| 1967 |
tree |
| 1968 |
function_resolver::resolve_uniform_opt_n (unsigned int nops) |
| 1969 |
{ |
| 1970 |
unsigned int i, nargs; |
| 1971 |
type_suffix_index type; |
| 1972 |
if (!check_gp_argument (nops, i, nargs) |
| 1973 |
/* Unary operators should use resolve_unary, so using i - 1 is |
| 1974 |
safe. */ |
| 1975 |
|| (type = infer_vector_type (i - 1)) == NUM_TYPE_SUFFIXES) |
| 1976 |
return error_mark_node; |
| 1977 |
|
| 1978 |
/* Skip last argument, may be scalar. */ |
| 1979 |
unsigned int last_arg = i; |
| 1980 |
for (i = 0; i < last_arg; i++) |
| 1981 |
if (!require_matching_vector_type (i, type)) |
| 1982 |
return error_mark_node; |
| 1983 |
|
| 1984 |
return finish_opt_n_resolution (last_arg, 0, type); |
| 1985 |
} |
| 1986 |
|
| 1987 |
/* If the call is erroneous, report an appropriate error and return |
| 1988 |
error_mark_node. Otherwise, if the function is overloaded, return |
| 1989 |
the decl of the non-overloaded function. Return NULL_TREE otherwise, |
| 1990 |
indicating that the call should be processed in the normal way. */ |
| 1991 |
tree |
| 1992 |
function_resolver::resolve () |
| 1993 |
{ |
| 1994 |
return shape->resolve (*this); |
| 1995 |
} |
| 1996 |
|
| 1997 |
function_checker::function_checker (location_t location, |
| 1998 |
const function_instance &instance, |
| 1999 |
tree fndecl, tree fntype, |
| 2000 |
unsigned int nargs, tree *args) |
| 2001 |
: function_call_info (location, instance, fndecl), |
| 2002 |
m_fntype (fntype), m_nargs (nargs), m_args (args) |
| 2003 |
{ |
| 2004 |
if (instance.has_inactive_argument ()) |
| 2005 |
m_base_arg = 1; |
| 2006 |
else |
| 2007 |
m_base_arg = 0; |
| 2008 |
} |
| 2009 |
|
| 2010 |
/* Return true if argument ARGNO exists. which it might not for |
| 2011 |
erroneous calls. It is safe to wave through checks if this |
| 2012 |
function returns false. */ |
| 2013 |
bool |
| 2014 |
function_checker::argument_exists_p (unsigned int argno) |
| 2015 |
{ |
| 2016 |
gcc_assert (argno < (unsigned int) type_num_arguments (m_fntype)); |
| 2017 |
return argno < m_nargs; |
| 2018 |
} |
| 2019 |
|
| 2020 |
/* Check that argument ARGNO is an integer constant expression and |
| 2021 |
store its value in VALUE_OUT if so. The caller should first |
| 2022 |
check that argument ARGNO exists. */ |
| 2023 |
bool |
| 2024 |
function_checker::require_immediate (unsigned int argno, |
| 2025 |
HOST_WIDE_INT &value_out) |
| 2026 |
{ |
| 2027 |
gcc_assert (argno < m_nargs); |
| 2028 |
tree arg = m_args[argno]; |
| 2029 |
|
| 2030 |
/* The type and range are unsigned, so read the argument as an |
| 2031 |
unsigned rather than signed HWI. */ |
| 2032 |
if (!tree_fits_uhwi_p (arg)) |
| 2033 |
{ |
| 2034 |
report_non_ice (location, fndecl, argno); |
| 2035 |
return false; |
| 2036 |
} |
| 2037 |
|
| 2038 |
/* ...but treat VALUE_OUT as signed for error reporting, since printing |
| 2039 |
-1 is more user-friendly than the maximum uint64_t value. */ |
| 2040 |
value_out = tree_to_uhwi (arg); |
| 2041 |
return true; |
| 2042 |
} |
| 2043 |
|
| 2044 |
/* Check that argument ARGNO is a signed integer constant expression and store |
| 2045 |
its value in VALUE_OUT if so. The caller should first check that argument |
| 2046 |
ARGNO exists. */ |
| 2047 |
bool |
| 2048 |
function_checker::require_signed_immediate (unsigned int argno, |
| 2049 |
HOST_WIDE_INT &value_out) |
| 2050 |
{ |
| 2051 |
gcc_assert (argno < m_nargs); |
| 2052 |
tree arg = m_args[argno]; |
| 2053 |
|
| 2054 |
if (!tree_fits_shwi_p (arg)) |
| 2055 |
{ |
| 2056 |
report_non_ice (location, fndecl, argno); |
| 2057 |
return false; |
| 2058 |
} |
| 2059 |
|
| 2060 |
value_out = tree_to_shwi (arg); |
| 2061 |
return true; |
| 2062 |
} |
| 2063 |
|
| 2064 |
/* Check that argument REL_ARGNO is an integer constant expression that has |
| 2065 |
a valid value for enumeration type TYPE. REL_ARGNO counts from the end |
| 2066 |
of the predication arguments. */ |
| 2067 |
bool |
| 2068 |
function_checker::require_immediate_enum (unsigned int rel_argno, tree type) |
| 2069 |
{ |
| 2070 |
unsigned int argno = m_base_arg + rel_argno; |
| 2071 |
if (!argument_exists_p (argno)) |
| 2072 |
return true; |
| 2073 |
|
| 2074 |
HOST_WIDE_INT actual; |
| 2075 |
if (!require_immediate (argno, actual)) |
| 2076 |
return false; |
| 2077 |
|
| 2078 |
for (tree entry = TYPE_VALUES (type); entry; entry = TREE_CHAIN (entry)) |
| 2079 |
{ |
| 2080 |
/* The value is an INTEGER_CST for C and a CONST_DECL wrapper |
| 2081 |
around an INTEGER_CST for C++. */ |
| 2082 |
tree value = TREE_VALUE (entry); |
| 2083 |
if (TREE_CODE (value) == CONST_DECL) |
| 2084 |
value = DECL_INITIAL (value); |
| 2085 |
if (wi::to_widest (value) == actual) |
| 2086 |
return true; |
| 2087 |
} |
| 2088 |
|
| 2089 |
report_not_enum (location, fndecl, argno, actual, type); |
| 2090 |
return false; |
| 2091 |
} |
| 2092 |
|
| 2093 |
/* Check that argument REL_ARGNO is an integer constant expression that |
| 2094 |
has one of the given values. */ |
| 2095 |
bool |
| 2096 |
function_checker::require_immediate_one_of (unsigned int rel_argno, |
| 2097 |
HOST_WIDE_INT value0, |
| 2098 |
HOST_WIDE_INT value1, |
| 2099 |
HOST_WIDE_INT value2, |
| 2100 |
HOST_WIDE_INT value3) |
| 2101 |
{ |
| 2102 |
unsigned int argno = m_base_arg + rel_argno; |
| 2103 |
if (!argument_exists_p (argno)) |
| 2104 |
return true; |
| 2105 |
|
| 2106 |
HOST_WIDE_INT actual; |
| 2107 |
if (!require_immediate (argno, actual)) |
| 2108 |
return false; |
| 2109 |
|
| 2110 |
if (actual != value0 |
| 2111 |
&& actual != value1 |
| 2112 |
&& actual != value2 |
| 2113 |
&& actual != value3) |
| 2114 |
{ |
| 2115 |
report_not_one_of (location, fndecl, argno, actual, |
| 2116 |
value0, value1, value2, value3); |
| 2117 |
return false; |
| 2118 |
} |
| 2119 |
|
| 2120 |
return true; |
| 2121 |
} |
| 2122 |
|
| 2123 |
/* Check that argument REL_ARGNO is an integer constant expression in the |
| 2124 |
range [MIN, MAX]. REL_ARGNO counts from the end of the predication |
| 2125 |
arguments. */ |
| 2126 |
bool |
| 2127 |
function_checker::require_immediate_range (unsigned int rel_argno, |
| 2128 |
HOST_WIDE_INT min, |
| 2129 |
HOST_WIDE_INT max) |
| 2130 |
{ |
| 2131 |
unsigned int argno = m_base_arg + rel_argno; |
| 2132 |
if (!argument_exists_p (argno)) |
| 2133 |
return true; |
| 2134 |
|
| 2135 |
/* Required because of the tree_to_uhwi -> HOST_WIDE_INT conversion |
| 2136 |
in require_immediate. */ |
| 2137 |
gcc_assert (min >= 0 && min <= max); |
| 2138 |
HOST_WIDE_INT actual; |
| 2139 |
if (!require_immediate (argno, actual)) |
| 2140 |
return false; |
| 2141 |
|
| 2142 |
if (!IN_RANGE (actual, min, max)) |
| 2143 |
{ |
| 2144 |
report_out_of_range (location, fndecl, argno, actual, min, max); |
| 2145 |
return false; |
| 2146 |
} |
| 2147 |
|
| 2148 |
return true; |
| 2149 |
} |
| 2150 |
|
| 2151 |
/* Check that argument REL_ARGNO is a signed integer constant expression in the |
| 2152 |
range [MIN, MAX]. Also check that REL_ARGNO is a multiple of MULT. */ |
| 2153 |
bool |
| 2154 |
function_checker::require_immediate_range_multiple (unsigned int rel_argno, |
| 2155 |
HOST_WIDE_INT min, |
| 2156 |
HOST_WIDE_INT max, |
| 2157 |
HOST_WIDE_INT mult) |
| 2158 |
{ |
| 2159 |
unsigned int argno = m_base_arg + rel_argno; |
| 2160 |
if (!argument_exists_p (argno)) |
| 2161 |
return true; |
| 2162 |
|
| 2163 |
HOST_WIDE_INT actual; |
| 2164 |
if (!require_signed_immediate (argno, actual)) |
| 2165 |
return false; |
| 2166 |
|
| 2167 |
if (!IN_RANGE (actual, min, max) |
| 2168 |
|| (actual % mult) != 0) |
| 2169 |
{ |
| 2170 |
report_out_of_range_multiple (location, fndecl, argno, actual, min, max, mult); |
| 2171 |
return false; |
| 2172 |
} |
| 2173 |
|
| 2174 |
return true; |
| 2175 |
} |
| 2176 |
|
| 2177 |
/* Perform semantic checks on the call. Return true if the call is valid, |
| 2178 |
otherwise report a suitable error. */ |
| 2179 |
bool |
| 2180 |
function_checker::check () |
| 2181 |
{ |
| 2182 |
function_args_iterator iter; |
| 2183 |
tree type; |
| 2184 |
unsigned int i = 0; |
| 2185 |
FOREACH_FUNCTION_ARGS (m_fntype, type, iter) |
| 2186 |
{ |
| 2187 |
if (type == void_type_node || i >= m_nargs) |
| 2188 |
break; |
| 2189 |
|
| 2190 |
if (i >= m_base_arg |
| 2191 |
&& TREE_CODE (type) == ENUMERAL_TYPE |
| 2192 |
&& !require_immediate_enum (i - m_base_arg, type)) |
| 2193 |
return false; |
| 2194 |
|
| 2195 |
i += 1; |
| 2196 |
} |
| 2197 |
|
| 2198 |
return shape->check (*this); |
| 2199 |
} |
| 2200 |
|
| 2201 |
gimple_folder::gimple_folder (const function_instance &instance, tree fndecl, |
| 2202 |
gcall *call_in) |
| 2203 |
: function_call_info (gimple_location (call_in), instance, fndecl), |
| 2204 |
call (call_in), lhs (gimple_call_lhs (call_in)) |
| 2205 |
{ |
| 2206 |
} |
| 2207 |
|
| 2208 |
/* Try to fold the call. Return the new statement on success and null |
| 2209 |
on failure. */ |
| 2210 |
gimple * |
| 2211 |
gimple_folder::fold () |
| 2212 |
{ |
| 2213 |
/* Don't fold anything when MVE is disabled; emit an error during |
| 2214 |
expansion instead. */ |
| 2215 |
if (!TARGET_HAVE_MVE) |
| 2216 |
return NULL; |
| 2217 |
|
| 2218 |
/* Punt if the function has a return type and no result location is |
| 2219 |
provided. The attributes should allow target-independent code to |
| 2220 |
remove the calls if appropriate. */ |
| 2221 |
if (!lhs && TREE_TYPE (gimple_call_fntype (call)) != void_type_node) |
| 2222 |
return NULL; |
| 2223 |
|
| 2224 |
return base->fold (*this); |
| 2225 |
} |
| 2226 |
|
| 2227 |
function_expander::function_expander (const function_instance &instance, |
| 2228 |
tree fndecl, tree call_expr_in, |
| 2229 |
rtx possible_target_in) |
| 2230 |
: function_call_info (EXPR_LOCATION (call_expr_in), instance, fndecl), |
| 2231 |
call_expr (call_expr_in), possible_target (possible_target_in) |
| 2232 |
{ |
| 2233 |
} |
| 2234 |
|
| 2235 |
/* Return the handler of direct optab OP for type suffix SUFFIX_I. */ |
| 2236 |
insn_code |
| 2237 |
function_expander::direct_optab_handler (optab op, unsigned int suffix_i) |
| 2238 |
{ |
| 2239 |
return ::direct_optab_handler (op, vector_mode (suffix_i)); |
| 2240 |
} |
| 2241 |
|
| 2242 |
/* Return the base address for a contiguous load or store |
| 2243 |
function. */ |
| 2244 |
rtx |
| 2245 |
function_expander::get_contiguous_base () |
| 2246 |
{ |
| 2247 |
return args[0]; |
| 2248 |
} |
| 2249 |
|
| 2250 |
/* For a function that does the equivalent of: |
| 2251 |
|
| 2252 |
OUTPUT = COND ? FN (INPUTS) : FALLBACK; |
| 2253 |
|
| 2254 |
return the value of FALLBACK. |
| 2255 |
|
| 2256 |
MODE is the mode of OUTPUT. |
| 2257 |
MERGE_ARGNO is the argument that provides FALLBACK for _m functions, |
| 2258 |
or DEFAULT_MERGE_ARGNO if we should apply the usual rules. |
| 2259 |
|
| 2260 |
ARGNO is the caller's index into args. If the returned value is |
| 2261 |
argument 0 (as for unary _m operations), increment ARGNO past the |
| 2262 |
returned argument. */ |
| 2263 |
rtx |
| 2264 |
function_expander::get_fallback_value (machine_mode mode, |
| 2265 |
unsigned int merge_argno, |
| 2266 |
unsigned int &argno) |
| 2267 |
{ |
| 2268 |
if (pred == PRED_z) |
| 2269 |
return CONST0_RTX (mode); |
| 2270 |
|
| 2271 |
gcc_assert (pred == PRED_m || pred == PRED_x); |
| 2272 |
|
| 2273 |
if (merge_argno == 0) |
| 2274 |
return args[argno++]; |
| 2275 |
|
| 2276 |
return args[merge_argno]; |
| 2277 |
} |
| 2278 |
|
| 2279 |
/* Return a REG rtx that can be used for the result of the function, |
| 2280 |
using the preferred target if suitable. */ |
| 2281 |
rtx |
| 2282 |
function_expander::get_reg_target () |
| 2283 |
{ |
| 2284 |
machine_mode target_mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (fndecl))); |
| 2285 |
if (!possible_target || GET_MODE (possible_target) != target_mode) |
| 2286 |
possible_target = gen_reg_rtx (target_mode); |
| 2287 |
return possible_target; |
| 2288 |
} |
| 2289 |
|
| 2290 |
/* Add an output operand to the instruction we're building, which has |
| 2291 |
code ICODE. Bind the output to the preferred target rtx if possible. */ |
| 2292 |
void |
| 2293 |
function_expander::add_output_operand (insn_code icode) |
| 2294 |
{ |
| 2295 |
unsigned int opno = m_ops.length (); |
| 2296 |
machine_mode mode = insn_data[icode].operand[opno].mode; |
| 2297 |
m_ops.safe_grow (opno + 1, true); |
| 2298 |
create_output_operand (&m_ops.last (), possible_target, mode); |
| 2299 |
} |
| 2300 |
|
| 2301 |
/* Add an input operand to the instruction we're building, which has |
| 2302 |
code ICODE. Calculate the value of the operand as follows: |
| 2303 |
|
| 2304 |
- If the operand is a predicate, coerce X to have the |
| 2305 |
mode that the instruction expects. |
| 2306 |
|
| 2307 |
- Otherwise use X directly. The expand machinery checks that X has |
| 2308 |
the right mode for the instruction. */ |
| 2309 |
void |
| 2310 |
function_expander::add_input_operand (insn_code icode, rtx x) |
| 2311 |
{ |
| 2312 |
unsigned int opno = m_ops.length (); |
| 2313 |
const insn_operand_data &operand = insn_data[icode].operand[opno]; |
| 2314 |
machine_mode mode = operand.mode; |
| 2315 |
if (mode == VOIDmode) |
| 2316 |
{ |
| 2317 |
/* The only allowable use of VOIDmode is the wildcard |
| 2318 |
arm_any_register_operand, which is used to avoid |
| 2319 |
combinatorial explosion in the reinterpret patterns. */ |
| 2320 |
gcc_assert (operand.predicate == arm_any_register_operand); |
| 2321 |
mode = GET_MODE (x); |
| 2322 |
} |
| 2323 |
else if (VALID_MVE_PRED_MODE (mode)) |
| 2324 |
{ |
| 2325 |
if (CONST_INT_P (x)) |
| 2326 |
{ |
| 2327 |
if (mode == V8BImode || mode == V4BImode) |
| 2328 |
{ |
| 2329 |
/* In V8BI or V4BI each element has 2 or 4 bits, if those bits |
| 2330 |
aren't all the same, gen_lowpart might ICE. Canonicalize all |
| 2331 |
the 2 or 4 bits to all ones if any of them is non-zero. V8BI |
| 2332 |
and V4BI multi-bit masks are interpreted byte-by-byte at |
| 2333 |
instruction level, but such constants should describe lanes, |
| 2334 |
rather than bytes. See the section on MVE intrinsics in the |
| 2335 |
Arm ACLE specification. */ |
| 2336 |
unsigned HOST_WIDE_INT xi = UINTVAL (x); |
| 2337 |
xi |= ((xi & 0x5555) << 1) | ((xi & 0xaaaa) >> 1); |
| 2338 |
if (mode == V4BImode) |
| 2339 |
xi |= ((xi & 0x3333) << 2) | ((xi & 0xcccc) >> 2); |
| 2340 |
if (xi != UINTVAL (x)) |
| 2341 |
warning_at (location, 0, "constant predicate argument %d" |
| 2342 |
" (%wx) does not map to %d lane numbers," |
| 2343 |
" converted to %wx", |
| 2344 |
opno, UINTVAL (x) & 0xffff, |
| 2345 |
mode == V8BImode ? 8 : 4, |
| 2346 |
xi & 0xffff); |
| 2347 |
|
| 2348 |
x = gen_int_mode (xi, HImode); |
| 2349 |
} |
| 2350 |
x = gen_lowpart (mode, x); |
| 2351 |
} |
| 2352 |
else |
| 2353 |
x = force_lowpart_subreg (mode, x, GET_MODE (x)); |
| 2354 |
} |
| 2355 |
|
| 2356 |
m_ops.safe_grow (m_ops.length () + 1, true); |
| 2357 |
create_input_operand (&m_ops.last (), x, mode); |
| 2358 |
} |
| 2359 |
|
| 2360 |
/* Add an integer operand with value X to the instruction. */ |
| 2361 |
void |
| 2362 |
function_expander::add_integer_operand (HOST_WIDE_INT x) |
| 2363 |
{ |
| 2364 |
m_ops.safe_grow (m_ops.length () + 1, true); |
| 2365 |
create_integer_operand (&m_ops.last (), x); |
| 2366 |
} |
| 2367 |
|
| 2368 |
/* Add a memory operand with mode MODE and address ADDR. */ |
| 2369 |
void |
| 2370 |
function_expander::add_mem_operand (machine_mode mode, rtx addr) |
| 2371 |
{ |
| 2372 |
gcc_assert (VECTOR_MODE_P (mode)); |
| 2373 |
rtx mem = gen_rtx_MEM (mode, memory_address (mode, addr)); |
| 2374 |
/* The memory is only guaranteed to be element-aligned. */ |
| 2375 |
set_mem_align (mem, GET_MODE_ALIGNMENT (GET_MODE_INNER (mode))); |
| 2376 |
add_fixed_operand (mem); |
| 2377 |
} |
| 2378 |
|
| 2379 |
/* Add an operand that must be X. The only way of legitimizing an |
| 2380 |
invalid X is to reload the address of a MEM. */ |
| 2381 |
void |
| 2382 |
function_expander::add_fixed_operand (rtx x) |
| 2383 |
{ |
| 2384 |
m_ops.safe_grow (m_ops.length () + 1, true); |
| 2385 |
create_fixed_operand (&m_ops.last (), x); |
| 2386 |
} |
| 2387 |
|
| 2388 |
/* Generate instruction ICODE, given that its operands have already |
| 2389 |
been added to M_OPS. Return the value of the first operand. */ |
| 2390 |
rtx |
| 2391 |
function_expander::generate_insn (insn_code icode) |
| 2392 |
{ |
| 2393 |
expand_insn (icode, m_ops.length (), m_ops.address ()); |
| 2394 |
return function_returns_void_p () ? const0_rtx : m_ops[0].value; |
| 2395 |
} |
| 2396 |
|
| 2397 |
/* Implement the call using instruction ICODE, with a 1:1 mapping between |
| 2398 |
arguments and input operands. */ |
| 2399 |
rtx |
| 2400 |
function_expander::use_exact_insn (insn_code icode) |
| 2401 |
{ |
| 2402 |
unsigned int nops = insn_data[icode].n_operands; |
| 2403 |
if (!function_returns_void_p ()) |
| 2404 |
{ |
| 2405 |
add_output_operand (icode); |
| 2406 |
nops -= 1; |
| 2407 |
} |
| 2408 |
for (unsigned int i = 0; i < nops; ++i) |
| 2409 |
add_input_operand (icode, args[i]); |
| 2410 |
return generate_insn (icode); |
| 2411 |
} |
| 2412 |
|
| 2413 |
/* Implement the call using instruction ICODE, which does not use a |
| 2414 |
predicate. */ |
| 2415 |
rtx |
| 2416 |
function_expander::use_unpred_insn (insn_code icode) |
| 2417 |
{ |
| 2418 |
gcc_assert (pred == PRED_none); |
| 2419 |
/* Discount the output operand. */ |
| 2420 |
unsigned int nops = insn_data[icode].n_operands - 1; |
| 2421 |
unsigned int i = 0; |
| 2422 |
|
| 2423 |
add_output_operand (icode); |
| 2424 |
for (; i < nops; ++i) |
| 2425 |
add_input_operand (icode, args[i]); |
| 2426 |
|
| 2427 |
return generate_insn (icode); |
| 2428 |
} |
| 2429 |
|
| 2430 |
/* Implement the call using instruction ICODE, which is a predicated |
| 2431 |
operation that returns arbitrary values for inactive lanes. */ |
| 2432 |
rtx |
| 2433 |
function_expander::use_pred_x_insn (insn_code icode) |
| 2434 |
{ |
| 2435 |
gcc_assert (pred == PRED_x); |
| 2436 |
unsigned int nops = args.length (); |
| 2437 |
|
| 2438 |
add_output_operand (icode); |
| 2439 |
/* Use first operand as arbitrary inactive input. */ |
| 2440 |
add_input_operand (icode, possible_target); |
| 2441 |
emit_clobber (possible_target); |
| 2442 |
/* Copy remaining arguments, including the final predicate. */ |
| 2443 |
for (unsigned int i = 0; i < nops; ++i) |
| 2444 |
add_input_operand (icode, args[i]); |
| 2445 |
|
| 2446 |
return generate_insn (icode); |
| 2447 |
} |
| 2448 |
|
| 2449 |
/* Implement the call using instruction ICODE, which does the equivalent of: |
| 2450 |
|
| 2451 |
OUTPUT = COND ? FN (INPUTS) : FALLBACK; |
| 2452 |
|
| 2453 |
The instruction operands are in the order above: OUTPUT, COND, INPUTS |
| 2454 |
and FALLBACK. MERGE_ARGNO is the argument that provides FALLBACK for _m |
| 2455 |
functions, or DEFAULT_MERGE_ARGNO if we should apply the usual rules. */ |
| 2456 |
rtx |
| 2457 |
function_expander::use_cond_insn (insn_code icode, unsigned int merge_argno) |
| 2458 |
{ |
| 2459 |
/* At present we never need to handle PRED_none, which would involve |
| 2460 |
creating a new predicate rather than using one supplied by the user. */ |
| 2461 |
gcc_assert (pred != PRED_none); |
| 2462 |
/* For MVE, we only handle PRED_m at present. */ |
| 2463 |
gcc_assert (pred == PRED_m); |
| 2464 |
|
| 2465 |
/* Discount the output, predicate and fallback value. */ |
| 2466 |
unsigned int nops = insn_data[icode].n_operands - 3; |
| 2467 |
machine_mode mode = insn_data[icode].operand[0].mode; |
| 2468 |
|
| 2469 |
unsigned int opno = 0; |
| 2470 |
rtx fallback_arg = NULL_RTX; |
| 2471 |
fallback_arg = get_fallback_value (mode, merge_argno, opno); |
| 2472 |
rtx pred_arg = args[nops + 1]; |
| 2473 |
|
| 2474 |
add_output_operand (icode); |
| 2475 |
add_input_operand (icode, fallback_arg); |
| 2476 |
for (unsigned int i = 0; i < nops; ++i) |
| 2477 |
add_input_operand (icode, args[opno + i]); |
| 2478 |
add_input_operand (icode, pred_arg); |
| 2479 |
return generate_insn (icode); |
| 2480 |
} |
| 2481 |
|
| 2482 |
/* Implement the call using instruction ICODE, which loads memory operand 1 |
| 2483 |
into register operand 0. */ |
| 2484 |
rtx |
| 2485 |
function_expander::use_contiguous_load_insn (insn_code icode) |
| 2486 |
{ |
| 2487 |
machine_mode mem_mode = memory_vector_mode (); |
| 2488 |
|
| 2489 |
add_output_operand (icode); |
| 2490 |
add_mem_operand (mem_mode, get_contiguous_base ()); |
| 2491 |
if (pred == PRED_z) |
| 2492 |
add_input_operand (icode, args[1]); |
| 2493 |
return generate_insn (icode); |
| 2494 |
} |
| 2495 |
|
| 2496 |
/* Implement the call using instruction ICODE, which stores register operand 1 |
| 2497 |
into memory operand 0. */ |
| 2498 |
rtx |
| 2499 |
function_expander::use_contiguous_store_insn (insn_code icode) |
| 2500 |
{ |
| 2501 |
machine_mode mem_mode = memory_vector_mode (); |
| 2502 |
|
| 2503 |
add_mem_operand (mem_mode, get_contiguous_base ()); |
| 2504 |
add_input_operand (icode, args[1]); |
| 2505 |
if (pred == PRED_p) |
| 2506 |
add_input_operand (icode, args[2]); |
| 2507 |
return generate_insn (icode); |
| 2508 |
} |
| 2509 |
|
| 2510 |
/* Implement the call using a normal unpredicated optab for PRED_none. |
| 2511 |
|
| 2512 |
<optab> corresponds to: |
| 2513 |
|
| 2514 |
- CODE_FOR_SINT for signed integers |
| 2515 |
- CODE_FOR_UINT for unsigned integers |
| 2516 |
- CODE_FOR_FP for floating-point values */ |
| 2517 |
rtx |
| 2518 |
function_expander::map_to_rtx_codes (rtx_code code_for_sint, |
| 2519 |
rtx_code code_for_uint, |
| 2520 |
rtx_code code_for_fp) |
| 2521 |
{ |
| 2522 |
gcc_assert (pred == PRED_none); |
| 2523 |
rtx_code code = type_suffix (0).integer_p ? |
| 2524 |
(type_suffix (0).unsigned_p ? code_for_uint : code_for_sint) |
| 2525 |
: code_for_fp; |
| 2526 |
insn_code icode = direct_optab_handler (code_to_optab (code), 0); |
| 2527 |
if (icode == CODE_FOR_nothing) |
| 2528 |
gcc_unreachable (); |
| 2529 |
|
| 2530 |
return use_unpred_insn (icode); |
| 2531 |
} |
| 2532 |
|
| 2533 |
/* Expand the call and return its lhs. */ |
| 2534 |
rtx |
| 2535 |
function_expander::expand () |
| 2536 |
{ |
| 2537 |
unsigned int nargs = call_expr_nargs (call_expr); |
| 2538 |
args.reserve (nargs); |
| 2539 |
for (unsigned int i = 0; i < nargs; ++i) |
| 2540 |
args.quick_push (expand_normal (CALL_EXPR_ARG (call_expr, i))); |
| 2541 |
|
| 2542 |
return base->expand (*this); |
| 2543 |
} |
| 2544 |
|
| 2545 |
/* If we're implementing manual overloading, check whether the MVE |
| 2546 |
function with subcode CODE is overloaded, and if so attempt to |
| 2547 |
determine the corresponding non-overloaded function. The call |
| 2548 |
occurs at location LOCATION and has the arguments given by ARGLIST. |
| 2549 |
|
| 2550 |
If the call is erroneous, report an appropriate error and return |
| 2551 |
error_mark_node. Otherwise, if the function is overloaded, return |
| 2552 |
the decl of the non-overloaded function. Return NULL_TREE otherwise, |
| 2553 |
indicating that the call should be processed in the normal way. */ |
| 2554 |
tree |
| 2555 |
resolve_overloaded_builtin (location_t location, unsigned int code, |
| 2556 |
vec<tree, va_gc> *arglist) |
| 2557 |
{ |
| 2558 |
if (code >= vec_safe_length (registered_functions)) |
| 2559 |
return NULL_TREE; |
| 2560 |
|
| 2561 |
registered_function &rfn = *(*registered_functions)[code]; |
| 2562 |
if (rfn.overloaded_p) |
| 2563 |
return function_resolver (location, rfn.instance, rfn.decl, |
| 2564 |
*arglist).resolve (); |
| 2565 |
return NULL_TREE; |
| 2566 |
} |
| 2567 |
|
| 2568 |
/* Perform any semantic checks needed for a call to the MVE function |
| 2569 |
with subcode CODE, such as testing for integer constant expressions. |
| 2570 |
The call occurs at location LOCATION and has NARGS arguments, |
| 2571 |
given by ARGS. FNDECL is the original function decl, before |
| 2572 |
overload resolution. |
| 2573 |
|
| 2574 |
Return true if the call is valid, otherwise report a suitable error. */ |
| 2575 |
bool |
| 2576 |
check_builtin_call (location_t location, vec<location_t>, unsigned int code, |
| 2577 |
tree fndecl, unsigned int nargs, tree *args) |
| 2578 |
{ |
| 2579 |
const registered_function &rfn = *(*registered_functions)[code]; |
| 2580 |
if (!check_requires_float (location, rfn.decl, rfn.requires_float)) |
| 2581 |
return false; |
| 2582 |
|
| 2583 |
return function_checker (location, rfn.instance, fndecl, |
| 2584 |
TREE_TYPE (rfn.decl), nargs, args).check (); |
| 2585 |
} |
| 2586 |
|
| 2587 |
/* Attempt to fold STMT, given that it's a call to the MVE function |
| 2588 |
with subcode CODE. Return the new statement on success and null |
| 2589 |
on failure. Insert any other new statements at GSI. */ |
| 2590 |
gimple * |
| 2591 |
gimple_fold_builtin (unsigned int code, gcall *stmt) |
| 2592 |
{ |
| 2593 |
registered_function &rfn = *(*registered_functions)[code]; |
| 2594 |
return gimple_folder (rfn.instance, rfn.decl, stmt).fold (); |
| 2595 |
} |
| 2596 |
|
| 2597 |
/* Expand a call to the MVE function with subcode CODE. EXP is the call |
| 2598 |
expression and TARGET is the preferred location for the result. |
| 2599 |
Return the value of the lhs. */ |
| 2600 |
rtx |
| 2601 |
expand_builtin (unsigned int code, tree exp, rtx target) |
| 2602 |
{ |
| 2603 |
registered_function &rfn = *(*registered_functions)[code]; |
| 2604 |
if (!check_requires_float (EXPR_LOCATION (exp), rfn.decl, |
| 2605 |
rfn.requires_float)) |
| 2606 |
return target; |
| 2607 |
return function_expander (rfn.instance, rfn.decl, exp, target).expand (); |
| 2608 |
} |
| 2609 |
|
| 2610 |
} /* end namespace arm_mve */ |
| 2611 |
|
| 2612 |
using namespace arm_mve; |
| 2613 |
|
| 2614 |
inline void |
| 2615 |
gt_ggc_mx (function_instance *) |
| 2616 |
{ |
| 2617 |
} |
| 2618 |
|
| 2619 |
inline void |
| 2620 |
gt_pch_nx (function_instance *) |
| 2621 |
{ |
| 2622 |
} |
| 2623 |
|
| 2624 |
inline void |
| 2625 |
gt_pch_nx (function_instance *, gt_pointer_operator, void *) |
| 2626 |
{ |
| 2627 |
} |
| 2628 |
|
| 2629 |
#include "gt-arm-mve-builtins.h" |