| 1 |
/* Subroutines used for code generation on IA-32. |
| 2 |
Copyright (C) 1988-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 |
| 7 |
it 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, |
| 12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
GNU 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 INCLUDE_STRING |
| 21 |
#define IN_TARGET_CODE 1 |
| 22 |
|
| 23 |
#include "config.h" |
| 24 |
#include "system.h" |
| 25 |
#include "coretypes.h" |
| 26 |
#include "backend.h" |
| 27 |
#include "rtl.h" |
| 28 |
#include "tree.h" |
| 29 |
#include "memmodel.h" |
| 30 |
#include "gimple.h" |
| 31 |
#include "cfghooks.h" |
| 32 |
#include "cfgloop.h" |
| 33 |
#include "df.h" |
| 34 |
#include "tm_p.h" |
| 35 |
#include "stringpool.h" |
| 36 |
#include "expmed.h" |
| 37 |
#include "optabs.h" |
| 38 |
#include "regs.h" |
| 39 |
#include "emit-rtl.h" |
| 40 |
#include "recog.h" |
| 41 |
#include "cgraph.h" |
| 42 |
#include "diagnostic.h" |
| 43 |
#include "cfgbuild.h" |
| 44 |
#include "alias.h" |
| 45 |
#include "fold-const.h" |
| 46 |
#include "attribs.h" |
| 47 |
#include "calls.h" |
| 48 |
#include "stor-layout.h" |
| 49 |
#include "varasm.h" |
| 50 |
#include "output.h" |
| 51 |
#include "insn-attr.h" |
| 52 |
#include "flags.h" |
| 53 |
#include "except.h" |
| 54 |
#include "explow.h" |
| 55 |
#include "expr.h" |
| 56 |
#include "cfgrtl.h" |
| 57 |
#include "common/common-target.h" |
| 58 |
#include "langhooks.h" |
| 59 |
#include "reload.h" |
| 60 |
#include "gimplify.h" |
| 61 |
#include "dwarf2.h" |
| 62 |
#include "tm-constrs.h" |
| 63 |
#include "cselib.h" |
| 64 |
#include "sched-int.h" |
| 65 |
#include "opts.h" |
| 66 |
#include "tree-pass.h" |
| 67 |
#include "context.h" |
| 68 |
#include "pass_manager.h" |
| 69 |
#include "target-globals.h" |
| 70 |
#include "gimple-iterator.h" |
| 71 |
#include "gimple-fold.h" |
| 72 |
#include "tree-vectorizer.h" |
| 73 |
#include "shrink-wrap.h" |
| 74 |
#include "builtins.h" |
| 75 |
#include "rtl-iter.h" |
| 76 |
#include "tree-iterator.h" |
| 77 |
#include "dbgcnt.h" |
| 78 |
#include "case-cfn-macros.h" |
| 79 |
#include "dojump.h" |
| 80 |
#include "fold-const-call.h" |
| 81 |
#include "tree-vrp.h" |
| 82 |
#include "tree-ssanames.h" |
| 83 |
#include "selftest.h" |
| 84 |
#include "selftest-rtl.h" |
| 85 |
#include "print-rtl.h" |
| 86 |
#include "intl.h" |
| 87 |
#include "ifcvt.h" |
| 88 |
#include "symbol-summary.h" |
| 89 |
#include "sreal.h" |
| 90 |
#include "ipa-cp.h" |
| 91 |
#include "ipa-prop.h" |
| 92 |
#include "ipa-fnsummary.h" |
| 93 |
#include "wide-int-bitmask.h" |
| 94 |
#include "tree-vector-builder.h" |
| 95 |
#include "debug.h" |
| 96 |
#include "dwarf2out.h" |
| 97 |
#include "i386-options.h" |
| 98 |
#include "i386-builtins.h" |
| 99 |
#include "i386-expand.h" |
| 100 |
#include "i386-features.h" |
| 101 |
#include "function-abi.h" |
| 102 |
#include "rtl-error.h" |
| 103 |
|
| 104 |
/* This file should be included last. */ |
| 105 |
#include "target-def.h" |
| 106 |
|
| 107 |
static void ix86_print_operand_address_as (FILE *, rtx, addr_space_t, bool); |
| 108 |
static void ix86_emit_restore_reg_using_pop (rtx, bool = false); |
| 109 |
|
| 110 |
|
| 111 |
#ifndef CHECK_STACK_LIMIT |
| 112 |
#define CHECK_STACK_LIMIT (-1) |
| 113 |
#endif |
| 114 |
|
| 115 |
/* Return index of given mode in mult and division cost tables. */ |
| 116 |
#define MODE_INDEX(mode) \ |
| 117 |
((mode) == QImode ? 0 \ |
| 118 |
: (mode) == HImode ? 1 \ |
| 119 |
: (mode) == SImode ? 2 \ |
| 120 |
: (mode) == DImode ? 3 \ |
| 121 |
: 4) |
| 122 |
|
| 123 |
|
| 124 |
/* Set by -mtune. */ |
| 125 |
const struct processor_costs *ix86_tune_cost = NULL; |
| 126 |
|
| 127 |
/* Set by -mtune or -Os. */ |
| 128 |
const struct processor_costs *ix86_cost = NULL; |
| 129 |
|
| 130 |
/* In case the average insn count for single function invocation is |
| 131 |
lower than this constant, emit fast (but longer) prologue and |
| 132 |
epilogue code. */ |
| 133 |
#define FAST_PROLOGUE_INSN_COUNT 20 |
| 134 |
|
| 135 |
/* Names for 8 (low), 8 (high), and 16-bit registers, respectively. */ |
| 136 |
static const char *const qi_reg_name[] = QI_REGISTER_NAMES; |
| 137 |
static const char *const qi_high_reg_name[] = QI_HIGH_REGISTER_NAMES; |
| 138 |
static const char *const hi_reg_name[] = HI_REGISTER_NAMES; |
| 139 |
|
| 140 |
/* Array of the smallest class containing reg number REGNO, indexed by |
| 141 |
REGNO. Used by REGNO_REG_CLASS in i386.h. */ |
| 142 |
|
| 143 |
enum reg_class const regclass_map[FIRST_PSEUDO_REGISTER] = |
| 144 |
{ |
| 145 |
/* ax, dx, cx, bx */ |
| 146 |
AREG, DREG, CREG, BREG, |
| 147 |
/* si, di, bp, sp */ |
| 148 |
SIREG, DIREG, NON_Q_REGS, NON_Q_REGS, |
| 149 |
/* FP registers */ |
| 150 |
FP_TOP_REG, FP_SECOND_REG, FLOAT_REGS, FLOAT_REGS, |
| 151 |
FLOAT_REGS, FLOAT_REGS, FLOAT_REGS, FLOAT_REGS, |
| 152 |
/* arg pointer, flags, fpsr, frame */ |
| 153 |
NON_Q_REGS, NO_REGS, NO_REGS, NON_Q_REGS, |
| 154 |
/* SSE registers */ |
| 155 |
SSE_FIRST_REG, SSE_REGS, SSE_REGS, SSE_REGS, |
| 156 |
SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, |
| 157 |
/* MMX registers */ |
| 158 |
MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS, |
| 159 |
MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS, |
| 160 |
/* REX registers */ |
| 161 |
GENERAL_REGS, GENERAL_REGS, GENERAL_REGS, GENERAL_REGS, |
| 162 |
GENERAL_REGS, GENERAL_REGS, GENERAL_REGS, GENERAL_REGS, |
| 163 |
/* SSE REX registers */ |
| 164 |
SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, |
| 165 |
SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, |
| 166 |
/* AVX-512 SSE registers */ |
| 167 |
ALL_SSE_REGS, ALL_SSE_REGS, ALL_SSE_REGS, ALL_SSE_REGS, |
| 168 |
ALL_SSE_REGS, ALL_SSE_REGS, ALL_SSE_REGS, ALL_SSE_REGS, |
| 169 |
ALL_SSE_REGS, ALL_SSE_REGS, ALL_SSE_REGS, ALL_SSE_REGS, |
| 170 |
ALL_SSE_REGS, ALL_SSE_REGS, ALL_SSE_REGS, ALL_SSE_REGS, |
| 171 |
/* Mask registers. */ |
| 172 |
ALL_MASK_REGS, MASK_REGS, MASK_REGS, MASK_REGS, |
| 173 |
MASK_REGS, MASK_REGS, MASK_REGS, MASK_REGS, |
| 174 |
/* REX2 registers */ |
| 175 |
GENERAL_REGS, GENERAL_REGS, GENERAL_REGS, GENERAL_REGS, |
| 176 |
GENERAL_REGS, GENERAL_REGS, GENERAL_REGS, GENERAL_REGS, |
| 177 |
GENERAL_REGS, GENERAL_REGS, GENERAL_REGS, GENERAL_REGS, |
| 178 |
GENERAL_REGS, GENERAL_REGS, GENERAL_REGS, GENERAL_REGS, |
| 179 |
}; |
| 180 |
|
| 181 |
/* The "default" register map used in 32bit mode. */ |
| 182 |
|
| 183 |
unsigned int const debugger_register_map[FIRST_PSEUDO_REGISTER] = |
| 184 |
{ |
| 185 |
/* general regs */ |
| 186 |
0, 2, 1, 3, 6, 7, 4, 5, |
| 187 |
/* fp regs */ |
| 188 |
12, 13, 14, 15, 16, 17, 18, 19, |
| 189 |
/* arg, flags, fpsr, frame */ |
| 190 |
IGNORED_DWARF_REGNUM, IGNORED_DWARF_REGNUM, |
| 191 |
IGNORED_DWARF_REGNUM, IGNORED_DWARF_REGNUM, |
| 192 |
/* SSE */ |
| 193 |
21, 22, 23, 24, 25, 26, 27, 28, |
| 194 |
/* MMX */ |
| 195 |
29, 30, 31, 32, 33, 34, 35, 36, |
| 196 |
/* extended integer registers */ |
| 197 |
INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, |
| 198 |
INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, |
| 199 |
/* extended sse registers */ |
| 200 |
INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, |
| 201 |
INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, |
| 202 |
/* AVX-512 registers 16-23 */ |
| 203 |
INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, |
| 204 |
INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, |
| 205 |
/* AVX-512 registers 24-31 */ |
| 206 |
INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, |
| 207 |
INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, |
| 208 |
/* Mask registers */ |
| 209 |
93, 94, 95, 96, 97, 98, 99, 100 |
| 210 |
}; |
| 211 |
|
| 212 |
/* The "default" register map used in 64bit mode. */ |
| 213 |
|
| 214 |
unsigned int const debugger64_register_map[FIRST_PSEUDO_REGISTER] = |
| 215 |
{ |
| 216 |
/* general regs */ |
| 217 |
0, 1, 2, 3, 4, 5, 6, 7, |
| 218 |
/* fp regs */ |
| 219 |
33, 34, 35, 36, 37, 38, 39, 40, |
| 220 |
/* arg, flags, fpsr, frame */ |
| 221 |
IGNORED_DWARF_REGNUM, IGNORED_DWARF_REGNUM, |
| 222 |
IGNORED_DWARF_REGNUM, IGNORED_DWARF_REGNUM, |
| 223 |
/* SSE */ |
| 224 |
17, 18, 19, 20, 21, 22, 23, 24, |
| 225 |
/* MMX */ |
| 226 |
41, 42, 43, 44, 45, 46, 47, 48, |
| 227 |
/* extended integer registers */ |
| 228 |
8, 9, 10, 11, 12, 13, 14, 15, |
| 229 |
/* extended SSE registers */ |
| 230 |
25, 26, 27, 28, 29, 30, 31, 32, |
| 231 |
/* AVX-512 registers 16-23 */ |
| 232 |
67, 68, 69, 70, 71, 72, 73, 74, |
| 233 |
/* AVX-512 registers 24-31 */ |
| 234 |
75, 76, 77, 78, 79, 80, 81, 82, |
| 235 |
/* Mask registers */ |
| 236 |
118, 119, 120, 121, 122, 123, 124, 125, |
| 237 |
/* rex2 extend interger registers */ |
| 238 |
130, 131, 132, 133, 134, 135, 136, 137, |
| 239 |
138, 139, 140, 141, 142, 143, 144, 145 |
| 240 |
}; |
| 241 |
|
| 242 |
/* Define the register numbers to be used in Dwarf debugging information. |
| 243 |
The SVR4 reference port C compiler uses the following register numbers |
| 244 |
in its Dwarf output code: |
| 245 |
0 for %eax (gcc regno = 0) |
| 246 |
1 for %ecx (gcc regno = 2) |
| 247 |
2 for %edx (gcc regno = 1) |
| 248 |
3 for %ebx (gcc regno = 3) |
| 249 |
4 for %esp (gcc regno = 7) |
| 250 |
5 for %ebp (gcc regno = 6) |
| 251 |
6 for %esi (gcc regno = 4) |
| 252 |
7 for %edi (gcc regno = 5) |
| 253 |
The following three DWARF register numbers are never generated by |
| 254 |
the SVR4 C compiler or by the GNU compilers, but SDB on x86/svr4 |
| 255 |
believed these numbers have these meanings. |
| 256 |
8 for %eip (no gcc equivalent) |
| 257 |
9 for %eflags (gcc regno = 17) |
| 258 |
10 for %trapno (no gcc equivalent) |
| 259 |
It is not at all clear how we should number the FP stack registers |
| 260 |
for the x86 architecture. If the version of SDB on x86/svr4 were |
| 261 |
a bit less brain dead with respect to floating-point then we would |
| 262 |
have a precedent to follow with respect to DWARF register numbers |
| 263 |
for x86 FP registers, but the SDB on x86/svr4 was so completely |
| 264 |
broken with respect to FP registers that it is hardly worth thinking |
| 265 |
of it as something to strive for compatibility with. |
| 266 |
The version of x86/svr4 SDB I had does (partially) |
| 267 |
seem to believe that DWARF register number 11 is associated with |
| 268 |
the x86 register %st(0), but that's about all. Higher DWARF |
| 269 |
register numbers don't seem to be associated with anything in |
| 270 |
particular, and even for DWARF regno 11, SDB only seemed to under- |
| 271 |
stand that it should say that a variable lives in %st(0) (when |
| 272 |
asked via an `=' command) if we said it was in DWARF regno 11, |
| 273 |
but SDB still printed garbage when asked for the value of the |
| 274 |
variable in question (via a `/' command). |
| 275 |
(Also note that the labels SDB printed for various FP stack regs |
| 276 |
when doing an `x' command were all wrong.) |
| 277 |
Note that these problems generally don't affect the native SVR4 |
| 278 |
C compiler because it doesn't allow the use of -O with -g and |
| 279 |
because when it is *not* optimizing, it allocates a memory |
| 280 |
location for each floating-point variable, and the memory |
| 281 |
location is what gets described in the DWARF AT_location |
| 282 |
attribute for the variable in question. |
| 283 |
Regardless of the severe mental illness of the x86/svr4 SDB, we |
| 284 |
do something sensible here and we use the following DWARF |
| 285 |
register numbers. Note that these are all stack-top-relative |
| 286 |
numbers. |
| 287 |
11 for %st(0) (gcc regno = 8) |
| 288 |
12 for %st(1) (gcc regno = 9) |
| 289 |
13 for %st(2) (gcc regno = 10) |
| 290 |
14 for %st(3) (gcc regno = 11) |
| 291 |
15 for %st(4) (gcc regno = 12) |
| 292 |
16 for %st(5) (gcc regno = 13) |
| 293 |
17 for %st(6) (gcc regno = 14) |
| 294 |
18 for %st(7) (gcc regno = 15) |
| 295 |
*/ |
| 296 |
unsigned int const svr4_debugger_register_map[FIRST_PSEUDO_REGISTER] = |
| 297 |
{ |
| 298 |
/* general regs */ |
| 299 |
0, 2, 1, 3, 6, 7, 5, 4, |
| 300 |
/* fp regs */ |
| 301 |
11, 12, 13, 14, 15, 16, 17, 18, |
| 302 |
/* arg, flags, fpsr, frame */ |
| 303 |
IGNORED_DWARF_REGNUM, 9, |
| 304 |
IGNORED_DWARF_REGNUM, IGNORED_DWARF_REGNUM, |
| 305 |
/* SSE registers */ |
| 306 |
21, 22, 23, 24, 25, 26, 27, 28, |
| 307 |
/* MMX registers */ |
| 308 |
29, 30, 31, 32, 33, 34, 35, 36, |
| 309 |
/* extended integer registers */ |
| 310 |
INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, |
| 311 |
INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, |
| 312 |
/* extended sse registers */ |
| 313 |
INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, |
| 314 |
INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, |
| 315 |
/* AVX-512 registers 16-23 */ |
| 316 |
INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, |
| 317 |
INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, |
| 318 |
/* AVX-512 registers 24-31 */ |
| 319 |
INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, |
| 320 |
INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, |
| 321 |
/* Mask registers */ |
| 322 |
93, 94, 95, 96, 97, 98, 99, 100 |
| 323 |
}; |
| 324 |
|
| 325 |
/* Define parameter passing and return registers. */ |
| 326 |
|
| 327 |
static int const x86_64_int_parameter_registers[6] = |
| 328 |
{ |
| 329 |
DI_REG, SI_REG, DX_REG, CX_REG, R8_REG, R9_REG |
| 330 |
}; |
| 331 |
|
| 332 |
static int const x86_64_ms_abi_int_parameter_registers[4] = |
| 333 |
{ |
| 334 |
CX_REG, DX_REG, R8_REG, R9_REG |
| 335 |
}; |
| 336 |
|
| 337 |
static int const x86_64_int_return_registers[4] = |
| 338 |
{ |
| 339 |
AX_REG, DX_REG, DI_REG, SI_REG |
| 340 |
}; |
| 341 |
|
| 342 |
/* Define the structure for the machine field in struct function. */ |
| 343 |
|
| 344 |
struct GTY(()) stack_local_entry { |
| 345 |
unsigned short mode; |
| 346 |
unsigned short n; |
| 347 |
rtx rtl; |
| 348 |
struct stack_local_entry *next; |
| 349 |
}; |
| 350 |
|
| 351 |
/* Which cpu are we scheduling for. */ |
| 352 |
enum attr_cpu ix86_schedule; |
| 353 |
|
| 354 |
/* Which cpu are we optimizing for. */ |
| 355 |
enum processor_type ix86_tune; |
| 356 |
|
| 357 |
/* Which instruction set architecture to use. */ |
| 358 |
enum processor_type ix86_arch; |
| 359 |
|
| 360 |
/* True if processor has SSE prefetch instruction. */ |
| 361 |
unsigned char ix86_prefetch_sse; |
| 362 |
|
| 363 |
/* Preferred alignment for stack boundary in bits. */ |
| 364 |
unsigned int ix86_preferred_stack_boundary; |
| 365 |
|
| 366 |
/* Alignment for incoming stack boundary in bits specified at |
| 367 |
command line. */ |
| 368 |
unsigned int ix86_user_incoming_stack_boundary; |
| 369 |
|
| 370 |
/* Default alignment for incoming stack boundary in bits. */ |
| 371 |
unsigned int ix86_default_incoming_stack_boundary; |
| 372 |
|
| 373 |
/* Alignment for incoming stack boundary in bits. */ |
| 374 |
unsigned int ix86_incoming_stack_boundary; |
| 375 |
|
| 376 |
/* True if there is no direct access to extern symbols. */ |
| 377 |
bool ix86_has_no_direct_extern_access; |
| 378 |
|
| 379 |
/* Calling abi specific va_list type nodes. */ |
| 380 |
tree sysv_va_list_type_node; |
| 381 |
tree ms_va_list_type_node; |
| 382 |
|
| 383 |
/* Prefix built by ASM_GENERATE_INTERNAL_LABEL. */ |
| 384 |
char internal_label_prefix[16]; |
| 385 |
int internal_label_prefix_len; |
| 386 |
|
| 387 |
/* Fence to use after loop using movnt. */ |
| 388 |
tree x86_mfence; |
| 389 |
|
| 390 |
/* Register class used for passing given 64bit part of the argument. |
| 391 |
These represent classes as documented by the PS ABI, with the exception |
| 392 |
of SSESF, SSEDF classes, that are basically SSE class, just gcc will |
| 393 |
use SF or DFmode move instead of DImode to avoid reformatting penalties. |
| 394 |
|
| 395 |
Similarly we play games with INTEGERSI_CLASS to use cheaper SImode moves |
| 396 |
whenever possible (upper half does contain padding). */ |
| 397 |
enum x86_64_reg_class |
| 398 |
{ |
| 399 |
X86_64_NO_CLASS, |
| 400 |
X86_64_INTEGER_CLASS, |
| 401 |
X86_64_INTEGERSI_CLASS, |
| 402 |
X86_64_SSE_CLASS, |
| 403 |
X86_64_SSEHF_CLASS, |
| 404 |
X86_64_SSESF_CLASS, |
| 405 |
X86_64_SSEDF_CLASS, |
| 406 |
X86_64_SSEUP_CLASS, |
| 407 |
X86_64_X87_CLASS, |
| 408 |
X86_64_X87UP_CLASS, |
| 409 |
X86_64_COMPLEX_X87_CLASS, |
| 410 |
X86_64_MEMORY_CLASS |
| 411 |
}; |
| 412 |
|
| 413 |
#define MAX_CLASSES 8 |
| 414 |
|
| 415 |
/* Table of constants used by fldpi, fldln2, etc.... */ |
| 416 |
static REAL_VALUE_TYPE ext_80387_constants_table [5]; |
| 417 |
static bool ext_80387_constants_init; |
| 418 |
|
| 419 |
|
| 420 |
static rtx ix86_function_value (const_tree, const_tree, bool); |
| 421 |
static bool ix86_function_value_regno_p (const unsigned int); |
| 422 |
static unsigned int ix86_function_arg_boundary (machine_mode, |
| 423 |
const_tree); |
| 424 |
static rtx ix86_static_chain (const_tree, bool); |
| 425 |
static int ix86_function_regparm (const_tree, const_tree); |
| 426 |
static void ix86_compute_frame_layout (void); |
| 427 |
static tree ix86_canonical_va_list_type (tree); |
| 428 |
static unsigned int split_stack_prologue_scratch_regno (void); |
| 429 |
static bool i386_asm_output_addr_const_extra (FILE *, rtx); |
| 430 |
|
| 431 |
static bool ix86_can_inline_p (tree, tree); |
| 432 |
static unsigned int ix86_minimum_incoming_stack_boundary (bool); |
| 433 |
|
| 434 |
typedef enum ix86_flags_cc |
| 435 |
{ |
| 436 |
X86_CCO = 0, X86_CCNO, X86_CCB, X86_CCNB, |
| 437 |
X86_CCE, X86_CCNE, X86_CCBE, X86_CCNBE, |
| 438 |
X86_CCS, X86_CCNS, X86_CCP, X86_CCNP, |
| 439 |
X86_CCL, X86_CCNL, X86_CCLE, X86_CCNLE |
| 440 |
} ix86_cc; |
| 441 |
|
| 442 |
static const char *ix86_ccmp_dfv_mapping[] = |
| 443 |
{ |
| 444 |
"{dfv=of}", "{dfv=}", "{dfv=cf}", "{dfv=}", |
| 445 |
"{dfv=zf}", "{dfv=}", "{dfv=cf, zf}", "{dfv=}", |
| 446 |
"{dfv=sf}", "{dfv=}", "{dfv=cf}", "{dfv=}", |
| 447 |
"{dfv=sf}", "{dfv=sf, of}", "{dfv=sf, of, zf}", "{dfv=sf, of}" |
| 448 |
}; |
| 449 |
|
| 450 |
|
| 451 |
/* Whether -mtune= or -march= were specified */ |
| 452 |
int ix86_tune_defaulted; |
| 453 |
int ix86_arch_specified; |
| 454 |
|
| 455 |
/* Return true if a red-zone is in use. We can't use red-zone when |
| 456 |
there are local indirect jumps, like "indirect_jump" or "tablejump", |
| 457 |
which jumps to another place in the function, since "call" in the |
| 458 |
indirect thunk pushes the return address onto stack, destroying |
| 459 |
red-zone. |
| 460 |
|
| 461 |
NB: Don't use red-zone for functions with no_caller_saved_registers |
| 462 |
and 32 GPRs since 128-byte red-zone is too small for 31 GPRs. |
| 463 |
|
| 464 |
TODO: If we can reserve the first 2 WORDs, for PUSH and, another |
| 465 |
for CALL, in red-zone, we can allow local indirect jumps with |
| 466 |
indirect thunk. */ |
| 467 |
|
| 468 |
bool |
| 469 |
ix86_using_red_zone (void) |
| 470 |
{ |
| 471 |
return (TARGET_RED_ZONE |
| 472 |
&& !TARGET_64BIT_MS_ABI |
| 473 |
&& (!TARGET_APX_EGPR |
| 474 |
|| (cfun->machine->call_saved_registers |
| 475 |
!= TYPE_NO_CALLER_SAVED_REGISTERS)) |
| 476 |
&& (!cfun->machine->has_local_indirect_jump |
| 477 |
|| cfun->machine->indirect_branch_type == indirect_branch_keep)); |
| 478 |
} |
| 479 |
|
| 480 |
/* Return true, if profiling code should be emitted before |
| 481 |
prologue. Otherwise it returns false. |
| 482 |
Note: For x86 with "hotfix" it is sorried. */ |
| 483 |
static bool |
| 484 |
ix86_profile_before_prologue (void) |
| 485 |
{ |
| 486 |
return flag_fentry != 0; |
| 487 |
} |
| 488 |
|
| 489 |
/* Update register usage after having seen the compiler flags. */ |
| 490 |
|
| 491 |
static void |
| 492 |
ix86_conditional_register_usage (void) |
| 493 |
{ |
| 494 |
int i, c_mask; |
| 495 |
|
| 496 |
/* If there are no caller-saved registers, preserve all registers. |
| 497 |
except fixed_regs and registers used for function return value |
| 498 |
since aggregate_value_p checks call_used_regs[regno] on return |
| 499 |
value. */ |
| 500 |
if (cfun |
| 501 |
&& (cfun->machine->call_saved_registers |
| 502 |
== TYPE_NO_CALLER_SAVED_REGISTERS)) |
| 503 |
for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) |
| 504 |
if (!fixed_regs[i] && !ix86_function_value_regno_p (i)) |
| 505 |
call_used_regs[i] = 0; |
| 506 |
|
| 507 |
/* For 32-bit targets, disable the REX registers. */ |
| 508 |
if (! TARGET_64BIT) |
| 509 |
{ |
| 510 |
for (i = FIRST_REX_INT_REG; i <= LAST_REX_INT_REG; i++) |
| 511 |
CLEAR_HARD_REG_BIT (accessible_reg_set, i); |
| 512 |
for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++) |
| 513 |
CLEAR_HARD_REG_BIT (accessible_reg_set, i); |
| 514 |
for (i = FIRST_EXT_REX_SSE_REG; i <= LAST_EXT_REX_SSE_REG; i++) |
| 515 |
CLEAR_HARD_REG_BIT (accessible_reg_set, i); |
| 516 |
} |
| 517 |
|
| 518 |
/* See the definition of CALL_USED_REGISTERS in i386.h. */ |
| 519 |
c_mask = CALL_USED_REGISTERS_MASK (TARGET_64BIT_MS_ABI); |
| 520 |
|
| 521 |
CLEAR_HARD_REG_SET (reg_class_contents[(int)CLOBBERED_REGS]); |
| 522 |
|
| 523 |
for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) |
| 524 |
{ |
| 525 |
/* Set/reset conditionally defined registers from |
| 526 |
CALL_USED_REGISTERS initializer. */ |
| 527 |
if (call_used_regs[i] > 1) |
| 528 |
call_used_regs[i] = !!(call_used_regs[i] & c_mask); |
| 529 |
|
| 530 |
/* Calculate registers of CLOBBERED_REGS register set |
| 531 |
as call used registers from GENERAL_REGS register set. */ |
| 532 |
if (TEST_HARD_REG_BIT (reg_class_contents[(int)GENERAL_REGS], i) |
| 533 |
&& call_used_regs[i]) |
| 534 |
SET_HARD_REG_BIT (reg_class_contents[(int)CLOBBERED_REGS], i); |
| 535 |
} |
| 536 |
|
| 537 |
/* If MMX is disabled, disable the registers. */ |
| 538 |
if (! TARGET_MMX) |
| 539 |
accessible_reg_set &= ~reg_class_contents[MMX_REGS]; |
| 540 |
|
| 541 |
/* If SSE is disabled, disable the registers. */ |
| 542 |
if (! TARGET_SSE) |
| 543 |
accessible_reg_set &= ~reg_class_contents[ALL_SSE_REGS]; |
| 544 |
|
| 545 |
/* If the FPU is disabled, disable the registers. */ |
| 546 |
if (! (TARGET_80387 || TARGET_FLOAT_RETURNS_IN_80387)) |
| 547 |
accessible_reg_set &= ~reg_class_contents[FLOAT_REGS]; |
| 548 |
|
| 549 |
/* If AVX512F is disabled, disable the registers. */ |
| 550 |
if (! TARGET_AVX512F) |
| 551 |
{ |
| 552 |
for (i = FIRST_EXT_REX_SSE_REG; i <= LAST_EXT_REX_SSE_REG; i++) |
| 553 |
CLEAR_HARD_REG_BIT (accessible_reg_set, i); |
| 554 |
|
| 555 |
accessible_reg_set &= ~reg_class_contents[ALL_MASK_REGS]; |
| 556 |
} |
| 557 |
|
| 558 |
/* If APX is disabled, disable the registers. */ |
| 559 |
if (! (TARGET_APX_EGPR && TARGET_64BIT)) |
| 560 |
{ |
| 561 |
for (i = FIRST_REX2_INT_REG; i <= LAST_REX2_INT_REG; i++) |
| 562 |
CLEAR_HARD_REG_BIT (accessible_reg_set, i); |
| 563 |
} |
| 564 |
} |
| 565 |
|
| 566 |
/* Canonicalize a comparison from one we don't have to one we do have. */ |
| 567 |
|
| 568 |
static void |
| 569 |
ix86_canonicalize_comparison (int *code, rtx *op0, rtx *op1, |
| 570 |
bool op0_preserve_value) |
| 571 |
{ |
| 572 |
/* The order of operands in x87 ficom compare is forced by combine in |
| 573 |
simplify_comparison () function. Float operator is treated as RTX_OBJ |
| 574 |
with a precedence over other operators and is always put in the first |
| 575 |
place. Swap condition and operands to match ficom instruction. */ |
| 576 |
if (!op0_preserve_value |
| 577 |
&& GET_CODE (*op0) == FLOAT && MEM_P (XEXP (*op0, 0)) && REG_P (*op1)) |
| 578 |
{ |
| 579 |
enum rtx_code scode = swap_condition ((enum rtx_code) *code); |
| 580 |
|
| 581 |
/* We are called only for compares that are split to SAHF instruction. |
| 582 |
Ensure that we have setcc/jcc insn for the swapped condition. */ |
| 583 |
if (ix86_fp_compare_code_to_integer (scode) != UNKNOWN) |
| 584 |
{ |
| 585 |
std::swap (*op0, *op1); |
| 586 |
*code = (int) scode; |
| 587 |
return; |
| 588 |
} |
| 589 |
} |
| 590 |
|
| 591 |
/* Swap operands of GTU comparison to canonicalize |
| 592 |
addcarry/subborrow comparison. */ |
| 593 |
if (!op0_preserve_value |
| 594 |
&& *code == GTU |
| 595 |
&& GET_CODE (*op0) == PLUS |
| 596 |
&& ix86_carry_flag_operator (XEXP (*op0, 0), VOIDmode) |
| 597 |
&& GET_CODE (XEXP (*op0, 1)) == ZERO_EXTEND |
| 598 |
&& GET_CODE (*op1) == ZERO_EXTEND) |
| 599 |
{ |
| 600 |
std::swap (*op0, *op1); |
| 601 |
*code = (int) swap_condition ((enum rtx_code) *code); |
| 602 |
return; |
| 603 |
} |
| 604 |
} |
| 605 |
|
| 606 |
/* Hook to determine if one function can safely inline another. */ |
| 607 |
|
| 608 |
static bool |
| 609 |
ix86_can_inline_p (tree caller, tree callee) |
| 610 |
{ |
| 611 |
tree caller_tree = DECL_FUNCTION_SPECIFIC_TARGET (caller); |
| 612 |
tree callee_tree = DECL_FUNCTION_SPECIFIC_TARGET (callee); |
| 613 |
|
| 614 |
/* Changes of those flags can be tolerated for always inlines. Lets hope |
| 615 |
user knows what he is doing. */ |
| 616 |
unsigned HOST_WIDE_INT always_inline_safe_mask |
| 617 |
= (MASK_USE_8BIT_IDIV | MASK_ACCUMULATE_OUTGOING_ARGS |
| 618 |
| MASK_NO_ALIGN_STRINGOPS | MASK_AVX256_SPLIT_UNALIGNED_LOAD |
| 619 |
| MASK_AVX256_SPLIT_UNALIGNED_STORE | MASK_CLD |
| 620 |
| MASK_NO_FANCY_MATH_387 | MASK_IEEE_FP | MASK_INLINE_ALL_STRINGOPS |
| 621 |
| MASK_INLINE_STRINGOPS_DYNAMICALLY | MASK_RECIP | MASK_STACK_PROBE |
| 622 |
| MASK_STV | MASK_TLS_DIRECT_SEG_REFS | MASK_VZEROUPPER |
| 623 |
| MASK_NO_PUSH_ARGS | MASK_OMIT_LEAF_FRAME_POINTER); |
| 624 |
|
| 625 |
|
| 626 |
if (!callee_tree) |
| 627 |
callee_tree = target_option_default_node; |
| 628 |
if (!caller_tree) |
| 629 |
caller_tree = target_option_default_node; |
| 630 |
if (callee_tree == caller_tree) |
| 631 |
return true; |
| 632 |
|
| 633 |
struct cl_target_option *caller_opts = TREE_TARGET_OPTION (caller_tree); |
| 634 |
struct cl_target_option *callee_opts = TREE_TARGET_OPTION (callee_tree); |
| 635 |
bool ret = false; |
| 636 |
bool always_inline |
| 637 |
= (DECL_DISREGARD_INLINE_LIMITS (callee) |
| 638 |
&& lookup_attribute ("always_inline", |
| 639 |
DECL_ATTRIBUTES (callee))); |
| 640 |
|
| 641 |
/* If callee only uses GPRs, ignore MASK_80387. */ |
| 642 |
if (TARGET_GENERAL_REGS_ONLY_P (callee_opts->x_ix86_target_flags)) |
| 643 |
always_inline_safe_mask |= MASK_80387; |
| 644 |
|
| 645 |
cgraph_node *callee_node = cgraph_node::get (callee); |
| 646 |
/* Callee's isa options should be a subset of the caller's, i.e. a SSE4 |
| 647 |
function can inline a SSE2 function but a SSE2 function can't inline |
| 648 |
a SSE4 function. */ |
| 649 |
if (((caller_opts->x_ix86_isa_flags & callee_opts->x_ix86_isa_flags) |
| 650 |
!= callee_opts->x_ix86_isa_flags) |
| 651 |
|| ((caller_opts->x_ix86_isa_flags2 & callee_opts->x_ix86_isa_flags2) |
| 652 |
!= callee_opts->x_ix86_isa_flags2)) |
| 653 |
ret = false; |
| 654 |
|
| 655 |
/* See if we have the same non-isa options. */ |
| 656 |
else if ((!always_inline |
| 657 |
&& caller_opts->x_target_flags != callee_opts->x_target_flags) |
| 658 |
|| (caller_opts->x_target_flags & ~always_inline_safe_mask) |
| 659 |
!= (callee_opts->x_target_flags & ~always_inline_safe_mask)) |
| 660 |
ret = false; |
| 661 |
|
| 662 |
else if (caller_opts->x_ix86_fpmath != callee_opts->x_ix86_fpmath |
| 663 |
/* If the calle doesn't use FP expressions differences in |
| 664 |
ix86_fpmath can be ignored. We are called from FEs |
| 665 |
for multi-versioning call optimization, so beware of |
| 666 |
ipa_fn_summaries not available. */ |
| 667 |
&& (! ipa_fn_summaries |
| 668 |
|| ipa_fn_summaries->get (callee_node) == NULL |
| 669 |
|| ipa_fn_summaries->get (callee_node)->fp_expressions)) |
| 670 |
ret = false; |
| 671 |
|
| 672 |
/* At this point we cannot identify whether arch or tune setting |
| 673 |
comes from target attribute or not. So the most conservative way |
| 674 |
is to allow the callee that uses default arch and tune string to |
| 675 |
be inlined. */ |
| 676 |
else if (!strcmp (callee_opts->x_ix86_arch_string, "x86-64") |
| 677 |
&& !strcmp (callee_opts->x_ix86_tune_string, "generic")) |
| 678 |
ret = true; |
| 679 |
|
| 680 |
/* See if arch, tune, etc. are the same. As previous ISA flags already |
| 681 |
checks if callee's ISA is subset of caller's, do not block |
| 682 |
always_inline attribute for callee even it has different arch. */ |
| 683 |
else if (!always_inline && caller_opts->arch != callee_opts->arch) |
| 684 |
ret = false; |
| 685 |
|
| 686 |
else if (!always_inline && caller_opts->tune != callee_opts->tune) |
| 687 |
ret = false; |
| 688 |
|
| 689 |
else if (!always_inline |
| 690 |
&& caller_opts->branch_cost != callee_opts->branch_cost) |
| 691 |
ret = false; |
| 692 |
|
| 693 |
else |
| 694 |
ret = true; |
| 695 |
|
| 696 |
return ret; |
| 697 |
} |
| 698 |
|
| 699 |
/* Return true if this goes in large data/bss. */ |
| 700 |
|
| 701 |
static bool |
| 702 |
ix86_in_large_data_p (tree exp) |
| 703 |
{ |
| 704 |
if (ix86_cmodel != CM_MEDIUM && ix86_cmodel != CM_MEDIUM_PIC |
| 705 |
&& ix86_cmodel != CM_LARGE && ix86_cmodel != CM_LARGE_PIC) |
| 706 |
return false; |
| 707 |
|
| 708 |
if (exp == NULL_TREE) |
| 709 |
return false; |
| 710 |
|
| 711 |
/* Functions are never large data. */ |
| 712 |
if (TREE_CODE (exp) == FUNCTION_DECL) |
| 713 |
return false; |
| 714 |
|
| 715 |
/* Automatic variables are never large data. */ |
| 716 |
if (VAR_P (exp) && !is_global_var (exp)) |
| 717 |
return false; |
| 718 |
|
| 719 |
if (VAR_P (exp) && DECL_SECTION_NAME (exp)) |
| 720 |
{ |
| 721 |
const char *section = DECL_SECTION_NAME (exp); |
| 722 |
if (strcmp (section, ".ldata") == 0 |
| 723 |
|| strcmp (section, ".lbss") == 0) |
| 724 |
return true; |
| 725 |
return false; |
| 726 |
} |
| 727 |
else |
| 728 |
{ |
| 729 |
HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp)); |
| 730 |
|
| 731 |
/* If this is an incomplete type with size 0, then we can't put it |
| 732 |
in data because it might be too big when completed. Also, |
| 733 |
int_size_in_bytes returns -1 if size can vary or is larger than |
| 734 |
an integer in which case also it is safer to assume that it goes in |
| 735 |
large data. */ |
| 736 |
if (size <= 0 || size > ix86_section_threshold) |
| 737 |
return true; |
| 738 |
} |
| 739 |
|
| 740 |
return false; |
| 741 |
} |
| 742 |
|
| 743 |
/* i386-specific section flag to mark large sections. */ |
| 744 |
#define SECTION_LARGE SECTION_MACH_DEP |
| 745 |
|
| 746 |
/* Switch to the appropriate section for output of DECL. |
| 747 |
DECL is either a `VAR_DECL' node or a constant of some sort. |
| 748 |
RELOC indicates whether forming the initial value of DECL requires |
| 749 |
link-time relocations. */ |
| 750 |
|
| 751 |
ATTRIBUTE_UNUSED static section * |
| 752 |
x86_64_elf_select_section (tree decl, int reloc, |
| 753 |
unsigned HOST_WIDE_INT align) |
| 754 |
{ |
| 755 |
if (ix86_in_large_data_p (decl)) |
| 756 |
{ |
| 757 |
const char *sname = NULL; |
| 758 |
unsigned int flags = SECTION_WRITE | SECTION_LARGE; |
| 759 |
switch (categorize_decl_for_section (decl, reloc)) |
| 760 |
{ |
| 761 |
case SECCAT_DATA: |
| 762 |
sname = ".ldata"; |
| 763 |
break; |
| 764 |
case SECCAT_DATA_REL: |
| 765 |
sname = ".ldata.rel"; |
| 766 |
break; |
| 767 |
case SECCAT_DATA_REL_LOCAL: |
| 768 |
sname = ".ldata.rel.local"; |
| 769 |
break; |
| 770 |
case SECCAT_DATA_REL_RO: |
| 771 |
sname = ".ldata.rel.ro"; |
| 772 |
break; |
| 773 |
case SECCAT_DATA_REL_RO_LOCAL: |
| 774 |
sname = ".ldata.rel.ro.local"; |
| 775 |
break; |
| 776 |
case SECCAT_BSS: |
| 777 |
sname = ".lbss"; |
| 778 |
flags |= SECTION_BSS; |
| 779 |
break; |
| 780 |
case SECCAT_RODATA: |
| 781 |
case SECCAT_RODATA_MERGE_STR: |
| 782 |
case SECCAT_RODATA_MERGE_STR_INIT: |
| 783 |
case SECCAT_RODATA_MERGE_CONST: |
| 784 |
sname = ".lrodata"; |
| 785 |
flags &= ~SECTION_WRITE; |
| 786 |
break; |
| 787 |
case SECCAT_SRODATA: |
| 788 |
case SECCAT_SDATA: |
| 789 |
case SECCAT_SBSS: |
| 790 |
gcc_unreachable (); |
| 791 |
case SECCAT_TEXT: |
| 792 |
case SECCAT_TDATA: |
| 793 |
case SECCAT_TBSS: |
| 794 |
/* We don't split these for medium model. Place them into |
| 795 |
default sections and hope for best. */ |
| 796 |
break; |
| 797 |
} |
| 798 |
if (sname) |
| 799 |
{ |
| 800 |
/* We might get called with string constants, but get_named_section |
| 801 |
doesn't like them as they are not DECLs. Also, we need to set |
| 802 |
flags in that case. */ |
| 803 |
if (!DECL_P (decl)) |
| 804 |
return get_section (sname, flags, NULL); |
| 805 |
return get_named_section (decl, sname, reloc); |
| 806 |
} |
| 807 |
} |
| 808 |
return default_elf_select_section (decl, reloc, align); |
| 809 |
} |
| 810 |
|
| 811 |
/* Select a set of attributes for section NAME based on the properties |
| 812 |
of DECL and whether or not RELOC indicates that DECL's initializer |
| 813 |
might contain runtime relocations. */ |
| 814 |
|
| 815 |
static unsigned int ATTRIBUTE_UNUSED |
| 816 |
x86_64_elf_section_type_flags (tree decl, const char *name, int reloc) |
| 817 |
{ |
| 818 |
unsigned int flags = default_section_type_flags (decl, name, reloc); |
| 819 |
|
| 820 |
if (ix86_in_large_data_p (decl)) |
| 821 |
flags |= SECTION_LARGE; |
| 822 |
|
| 823 |
if (decl == NULL_TREE |
| 824 |
&& (strcmp (name, ".ldata.rel.ro") == 0 |
| 825 |
|| strcmp (name, ".ldata.rel.ro.local") == 0)) |
| 826 |
flags |= SECTION_RELRO; |
| 827 |
|
| 828 |
if (strcmp (name, ".lbss") == 0 |
| 829 |
|| startswith (name, ".lbss.") |
| 830 |
|| startswith (name, ".gnu.linkonce.lb.")) |
| 831 |
flags |= SECTION_BSS; |
| 832 |
|
| 833 |
return flags; |
| 834 |
} |
| 835 |
|
| 836 |
/* Build up a unique section name, expressed as a |
| 837 |
STRING_CST node, and assign it to DECL_SECTION_NAME (decl). |
| 838 |
RELOC indicates whether the initial value of EXP requires |
| 839 |
link-time relocations. */ |
| 840 |
|
| 841 |
static void ATTRIBUTE_UNUSED |
| 842 |
x86_64_elf_unique_section (tree decl, int reloc) |
| 843 |
{ |
| 844 |
if (ix86_in_large_data_p (decl)) |
| 845 |
{ |
| 846 |
const char *prefix = NULL; |
| 847 |
/* We only need to use .gnu.linkonce if we don't have COMDAT groups. */ |
| 848 |
bool one_only = DECL_COMDAT_GROUP (decl) && !HAVE_COMDAT_GROUP; |
| 849 |
|
| 850 |
switch (categorize_decl_for_section (decl, reloc)) |
| 851 |
{ |
| 852 |
case SECCAT_DATA: |
| 853 |
case SECCAT_DATA_REL: |
| 854 |
case SECCAT_DATA_REL_LOCAL: |
| 855 |
case SECCAT_DATA_REL_RO: |
| 856 |
case SECCAT_DATA_REL_RO_LOCAL: |
| 857 |
prefix = one_only ? ".ld" : ".ldata"; |
| 858 |
break; |
| 859 |
case SECCAT_BSS: |
| 860 |
prefix = one_only ? ".lb" : ".lbss"; |
| 861 |
break; |
| 862 |
case SECCAT_RODATA: |
| 863 |
case SECCAT_RODATA_MERGE_STR: |
| 864 |
case SECCAT_RODATA_MERGE_STR_INIT: |
| 865 |
case SECCAT_RODATA_MERGE_CONST: |
| 866 |
prefix = one_only ? ".lr" : ".lrodata"; |
| 867 |
break; |
| 868 |
case SECCAT_SRODATA: |
| 869 |
case SECCAT_SDATA: |
| 870 |
case SECCAT_SBSS: |
| 871 |
gcc_unreachable (); |
| 872 |
case SECCAT_TEXT: |
| 873 |
case SECCAT_TDATA: |
| 874 |
case SECCAT_TBSS: |
| 875 |
/* We don't split these for medium model. Place them into |
| 876 |
default sections and hope for best. */ |
| 877 |
break; |
| 878 |
} |
| 879 |
if (prefix) |
| 880 |
{ |
| 881 |
const char *name, *linkonce; |
| 882 |
char *string; |
| 883 |
|
| 884 |
name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); |
| 885 |
name = targetm.strip_name_encoding (name); |
| 886 |
|
| 887 |
/* If we're using one_only, then there needs to be a .gnu.linkonce |
| 888 |
prefix to the section name. */ |
| 889 |
linkonce = one_only ? ".gnu.linkonce" : ""; |
| 890 |
|
| 891 |
string = ACONCAT ((linkonce, prefix, ".", name, NULL)); |
| 892 |
|
| 893 |
set_decl_section_name (decl, string); |
| 894 |
return; |
| 895 |
} |
| 896 |
} |
| 897 |
default_unique_section (decl, reloc); |
| 898 |
} |
| 899 |
|
| 900 |
#ifdef COMMON_ASM_OP |
| 901 |
|
| 902 |
#ifndef LARGECOMM_SECTION_ASM_OP |
| 903 |
#define LARGECOMM_SECTION_ASM_OP "\t.largecomm\t" |
| 904 |
#endif |
| 905 |
|
| 906 |
/* This says how to output assembler code to declare an |
| 907 |
uninitialized external linkage data object. |
| 908 |
|
| 909 |
For medium model x86-64 we need to use LARGECOMM_SECTION_ASM_OP opcode for |
| 910 |
large objects. */ |
| 911 |
void |
| 912 |
x86_elf_aligned_decl_common (FILE *file, tree decl, |
| 913 |
const char *name, unsigned HOST_WIDE_INT size, |
| 914 |
unsigned align) |
| 915 |
{ |
| 916 |
if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC |
| 917 |
|| ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC) |
| 918 |
&& size > (unsigned int)ix86_section_threshold) |
| 919 |
{ |
| 920 |
switch_to_section (get_named_section (decl, ".lbss", 0)); |
| 921 |
fputs (LARGECOMM_SECTION_ASM_OP, file); |
| 922 |
} |
| 923 |
else |
| 924 |
fputs (COMMON_ASM_OP, file); |
| 925 |
assemble_name (file, name); |
| 926 |
fprintf (file, "," HOST_WIDE_INT_PRINT_UNSIGNED ",%u\n", |
| 927 |
size, align / BITS_PER_UNIT); |
| 928 |
} |
| 929 |
#endif |
| 930 |
|
| 931 |
/* Utility function for targets to use in implementing |
| 932 |
ASM_OUTPUT_ALIGNED_BSS. */ |
| 933 |
|
| 934 |
void |
| 935 |
x86_output_aligned_bss (FILE *file, tree decl, const char *name, |
| 936 |
unsigned HOST_WIDE_INT size, unsigned align) |
| 937 |
{ |
| 938 |
if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC |
| 939 |
|| ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC) |
| 940 |
&& size > (unsigned int)ix86_section_threshold) |
| 941 |
switch_to_section (get_named_section (decl, ".lbss", 0)); |
| 942 |
else |
| 943 |
switch_to_section (bss_section); |
| 944 |
ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT)); |
| 945 |
#ifdef ASM_DECLARE_OBJECT_NAME |
| 946 |
last_assemble_variable_decl = decl; |
| 947 |
ASM_DECLARE_OBJECT_NAME (file, name, decl); |
| 948 |
#else |
| 949 |
/* Standard thing is just output label for the object. */ |
| 950 |
ASM_OUTPUT_LABEL (file, name); |
| 951 |
#endif /* ASM_DECLARE_OBJECT_NAME */ |
| 952 |
ASM_OUTPUT_SKIP (file, size ? size : 1); |
| 953 |
} |
| 954 |
|
| 955 |
/* Decide whether we must probe the stack before any space allocation |
| 956 |
on this target. It's essentially TARGET_STACK_PROBE except when |
| 957 |
-fstack-check causes the stack to be already probed differently. */ |
| 958 |
|
| 959 |
bool |
| 960 |
ix86_target_stack_probe (void) |
| 961 |
{ |
| 962 |
/* Do not probe the stack twice if static stack checking is enabled. */ |
| 963 |
if (flag_stack_check == STATIC_BUILTIN_STACK_CHECK) |
| 964 |
return false; |
| 965 |
|
| 966 |
return TARGET_STACK_PROBE; |
| 967 |
} |
| 968 |
|
| 969 |
/* Decide whether we can make a sibling call to a function. DECL is the |
| 970 |
declaration of the function being targeted by the call and EXP is the |
| 971 |
CALL_EXPR representing the call. */ |
| 972 |
|
| 973 |
static bool |
| 974 |
ix86_function_ok_for_sibcall (tree decl, tree exp) |
| 975 |
{ |
| 976 |
tree type, decl_or_type; |
| 977 |
rtx a, b; |
| 978 |
bool bind_global = decl && !targetm.binds_local_p (decl); |
| 979 |
|
| 980 |
if (ix86_function_naked (current_function_decl)) |
| 981 |
return false; |
| 982 |
|
| 983 |
/* Sibling call isn't OK if there are no caller-saved registers |
| 984 |
since all registers must be preserved before return. */ |
| 985 |
if (cfun->machine->call_saved_registers |
| 986 |
== TYPE_NO_CALLER_SAVED_REGISTERS) |
| 987 |
return false; |
| 988 |
|
| 989 |
/* If we are generating position-independent code, we cannot sibcall |
| 990 |
optimize direct calls to global functions, as the PLT requires |
| 991 |
%ebx be live. (Darwin does not have a PLT.) */ |
| 992 |
if (!TARGET_MACHO |
| 993 |
&& !TARGET_64BIT |
| 994 |
&& flag_pic |
| 995 |
&& flag_plt |
| 996 |
&& bind_global) |
| 997 |
return false; |
| 998 |
|
| 999 |
/* If we need to align the outgoing stack, then sibcalling would |
| 1000 |
unalign the stack, which may break the called function. */ |
| 1001 |
if (ix86_minimum_incoming_stack_boundary (true) |
| 1002 |
< PREFERRED_STACK_BOUNDARY) |
| 1003 |
return false; |
| 1004 |
|
| 1005 |
if (decl) |
| 1006 |
{ |
| 1007 |
decl_or_type = decl; |
| 1008 |
type = TREE_TYPE (decl); |
| 1009 |
} |
| 1010 |
else |
| 1011 |
{ |
| 1012 |
/* We're looking at the CALL_EXPR, we need the type of the function. */ |
| 1013 |
type = CALL_EXPR_FN (exp); /* pointer expression */ |
| 1014 |
type = TREE_TYPE (type); /* pointer type */ |
| 1015 |
type = TREE_TYPE (type); /* function type */ |
| 1016 |
decl_or_type = type; |
| 1017 |
} |
| 1018 |
|
| 1019 |
/* Sibling call isn't OK if callee has no callee-saved registers |
| 1020 |
and the calling function has callee-saved registers. */ |
| 1021 |
if (cfun->machine->call_saved_registers != TYPE_NO_CALLEE_SAVED_REGISTERS |
| 1022 |
&& (cfun->machine->call_saved_registers |
| 1023 |
!= TYPE_NO_CALLEE_SAVED_REGISTERS_EXCEPT_BP) |
| 1024 |
&& lookup_attribute ("no_callee_saved_registers", |
| 1025 |
TYPE_ATTRIBUTES (type))) |
| 1026 |
return false; |
| 1027 |
|
| 1028 |
/* If outgoing reg parm stack space changes, we cannot do sibcall. */ |
| 1029 |
if ((OUTGOING_REG_PARM_STACK_SPACE (type) |
| 1030 |
!= OUTGOING_REG_PARM_STACK_SPACE (TREE_TYPE (current_function_decl))) |
| 1031 |
|| (REG_PARM_STACK_SPACE (decl_or_type) |
| 1032 |
!= REG_PARM_STACK_SPACE (current_function_decl))) |
| 1033 |
{ |
| 1034 |
maybe_complain_about_tail_call (exp, |
| 1035 |
"inconsistent size of stack space" |
| 1036 |
" allocated for arguments which are" |
| 1037 |
" passed in registers"); |
| 1038 |
return false; |
| 1039 |
} |
| 1040 |
|
| 1041 |
/* Check that the return value locations are the same. Like |
| 1042 |
if we are returning floats on the 80387 register stack, we cannot |
| 1043 |
make a sibcall from a function that doesn't return a float to a |
| 1044 |
function that does or, conversely, from a function that does return |
| 1045 |
a float to a function that doesn't; the necessary stack adjustment |
| 1046 |
would not be executed. This is also the place we notice |
| 1047 |
differences in the return value ABI. Note that it is ok for one |
| 1048 |
of the functions to have void return type as long as the return |
| 1049 |
value of the other is passed in a register. */ |
| 1050 |
a = ix86_function_value (TREE_TYPE (exp), decl_or_type, false); |
| 1051 |
b = ix86_function_value (TREE_TYPE (DECL_RESULT (cfun->decl)), |
| 1052 |
cfun->decl, false); |
| 1053 |
if (STACK_REG_P (a) || STACK_REG_P (b)) |
| 1054 |
{ |
| 1055 |
if (!rtx_equal_p (a, b)) |
| 1056 |
return false; |
| 1057 |
} |
| 1058 |
else if (VOID_TYPE_P (TREE_TYPE (DECL_RESULT (cfun->decl)))) |
| 1059 |
; |
| 1060 |
else if (!rtx_equal_p (a, b)) |
| 1061 |
return false; |
| 1062 |
|
| 1063 |
if (TARGET_64BIT) |
| 1064 |
{ |
| 1065 |
/* The SYSV ABI has more call-clobbered registers; |
| 1066 |
disallow sibcalls from MS to SYSV. */ |
| 1067 |
if (cfun->machine->call_abi == MS_ABI |
| 1068 |
&& ix86_function_type_abi (type) == SYSV_ABI) |
| 1069 |
return false; |
| 1070 |
} |
| 1071 |
else |
| 1072 |
{ |
| 1073 |
/* If this call is indirect, we'll need to be able to use a |
| 1074 |
call-clobbered register for the address of the target function. |
| 1075 |
Make sure that all such registers are not used for passing |
| 1076 |
parameters. Note that DLLIMPORT functions and call to global |
| 1077 |
function via GOT slot are indirect. */ |
| 1078 |
if (!decl |
| 1079 |
|| (bind_global && flag_pic && !flag_plt) |
| 1080 |
|| (TARGET_DLLIMPORT_DECL_ATTRIBUTES && DECL_DLLIMPORT_P (decl)) |
| 1081 |
|| flag_force_indirect_call) |
| 1082 |
{ |
| 1083 |
/* Check if regparm >= 3 since arg_reg_available is set to |
| 1084 |
false if regparm == 0. If regparm is 1 or 2, there is |
| 1085 |
always a call-clobbered register available. |
| 1086 |
|
| 1087 |
??? The symbol indirect call doesn't need a call-clobbered |
| 1088 |
register. But we don't know if this is a symbol indirect |
| 1089 |
call or not here. */ |
| 1090 |
if (ix86_function_regparm (type, decl) >= 3 |
| 1091 |
&& !cfun->machine->arg_reg_available) |
| 1092 |
return false; |
| 1093 |
} |
| 1094 |
} |
| 1095 |
|
| 1096 |
if (decl && ix86_use_pseudo_pic_reg ()) |
| 1097 |
{ |
| 1098 |
/* When PIC register is used, it must be restored after ifunc |
| 1099 |
function returns. */ |
| 1100 |
cgraph_node *node = cgraph_node::get (decl); |
| 1101 |
if (node && node->ifunc_resolver) |
| 1102 |
return false; |
| 1103 |
} |
| 1104 |
|
| 1105 |
/* Disable sibcall if callee has indirect_return attribute and |
| 1106 |
caller doesn't since callee will return to the caller's caller |
| 1107 |
via an indirect jump. */ |
| 1108 |
if (((flag_cf_protection & (CF_RETURN | CF_BRANCH)) |
| 1109 |
== (CF_RETURN | CF_BRANCH)) |
| 1110 |
&& lookup_attribute ("indirect_return", TYPE_ATTRIBUTES (type)) |
| 1111 |
&& !lookup_attribute ("indirect_return", |
| 1112 |
TYPE_ATTRIBUTES (TREE_TYPE (cfun->decl)))) |
| 1113 |
return false; |
| 1114 |
|
| 1115 |
/* Otherwise okay. That also includes certain types of indirect calls. */ |
| 1116 |
return true; |
| 1117 |
} |
| 1118 |
|
| 1119 |
/* This function determines from TYPE the calling-convention. */ |
| 1120 |
|
| 1121 |
unsigned int |
| 1122 |
ix86_get_callcvt (const_tree type) |
| 1123 |
{ |
| 1124 |
unsigned int ret = 0; |
| 1125 |
bool is_stdarg; |
| 1126 |
tree attrs; |
| 1127 |
|
| 1128 |
if (TARGET_64BIT) |
| 1129 |
return IX86_CALLCVT_CDECL; |
| 1130 |
|
| 1131 |
attrs = TYPE_ATTRIBUTES (type); |
| 1132 |
if (attrs != NULL_TREE) |
| 1133 |
{ |
| 1134 |
if (lookup_attribute ("cdecl", attrs)) |
| 1135 |
ret |= IX86_CALLCVT_CDECL; |
| 1136 |
else if (lookup_attribute ("stdcall", attrs)) |
| 1137 |
ret |= IX86_CALLCVT_STDCALL; |
| 1138 |
else if (lookup_attribute ("fastcall", attrs)) |
| 1139 |
ret |= IX86_CALLCVT_FASTCALL; |
| 1140 |
else if (lookup_attribute ("thiscall", attrs)) |
| 1141 |
ret |= IX86_CALLCVT_THISCALL; |
| 1142 |
|
| 1143 |
/* Regparam isn't allowed for thiscall and fastcall. */ |
| 1144 |
if ((ret & (IX86_CALLCVT_THISCALL | IX86_CALLCVT_FASTCALL)) == 0) |
| 1145 |
{ |
| 1146 |
if (lookup_attribute ("regparm", attrs)) |
| 1147 |
ret |= IX86_CALLCVT_REGPARM; |
| 1148 |
if (lookup_attribute ("sseregparm", attrs)) |
| 1149 |
ret |= IX86_CALLCVT_SSEREGPARM; |
| 1150 |
} |
| 1151 |
|
| 1152 |
if (IX86_BASE_CALLCVT(ret) != 0) |
| 1153 |
return ret; |
| 1154 |
} |
| 1155 |
|
| 1156 |
is_stdarg = stdarg_p (type); |
| 1157 |
if (TARGET_RTD && !is_stdarg) |
| 1158 |
return IX86_CALLCVT_STDCALL | ret; |
| 1159 |
|
| 1160 |
if (ret != 0 |
| 1161 |
|| is_stdarg |
| 1162 |
|| TREE_CODE (type) != METHOD_TYPE |
| 1163 |
|| ix86_function_type_abi (type) != MS_ABI) |
| 1164 |
return IX86_CALLCVT_CDECL | ret; |
| 1165 |
|
| 1166 |
return IX86_CALLCVT_THISCALL; |
| 1167 |
} |
| 1168 |
|
| 1169 |
/* Return 0 if the attributes for two types are incompatible, 1 if they |
| 1170 |
are compatible, and 2 if they are nearly compatible (which causes a |
| 1171 |
warning to be generated). */ |
| 1172 |
|
| 1173 |
static int |
| 1174 |
ix86_comp_type_attributes (const_tree type1, const_tree type2) |
| 1175 |
{ |
| 1176 |
unsigned int ccvt1, ccvt2; |
| 1177 |
|
| 1178 |
if (TREE_CODE (type1) != FUNCTION_TYPE |
| 1179 |
&& TREE_CODE (type1) != METHOD_TYPE) |
| 1180 |
return 1; |
| 1181 |
|
| 1182 |
ccvt1 = ix86_get_callcvt (type1); |
| 1183 |
ccvt2 = ix86_get_callcvt (type2); |
| 1184 |
if (ccvt1 != ccvt2) |
| 1185 |
return 0; |
| 1186 |
if (ix86_function_regparm (type1, NULL) |
| 1187 |
!= ix86_function_regparm (type2, NULL)) |
| 1188 |
return 0; |
| 1189 |
|
| 1190 |
if (lookup_attribute ("no_callee_saved_registers", |
| 1191 |
TYPE_ATTRIBUTES (type1)) |
| 1192 |
!= lookup_attribute ("no_callee_saved_registers", |
| 1193 |
TYPE_ATTRIBUTES (type2))) |
| 1194 |
return 0; |
| 1195 |
|
| 1196 |
return 1; |
| 1197 |
} |
| 1198 |
|
| 1199 |
/* Return the regparm value for a function with the indicated TYPE and DECL. |
| 1200 |
DECL may be NULL when calling function indirectly |
| 1201 |
or considering a libcall. */ |
| 1202 |
|
| 1203 |
static int |
| 1204 |
ix86_function_regparm (const_tree type, const_tree decl) |
| 1205 |
{ |
| 1206 |
tree attr; |
| 1207 |
int regparm; |
| 1208 |
unsigned int ccvt; |
| 1209 |
|
| 1210 |
if (TARGET_64BIT) |
| 1211 |
return (ix86_function_type_abi (type) == SYSV_ABI |
| 1212 |
? X86_64_REGPARM_MAX : X86_64_MS_REGPARM_MAX); |
| 1213 |
ccvt = ix86_get_callcvt (type); |
| 1214 |
regparm = ix86_regparm; |
| 1215 |
|
| 1216 |
if ((ccvt & IX86_CALLCVT_REGPARM) != 0) |
| 1217 |
{ |
| 1218 |
attr = lookup_attribute ("regparm", TYPE_ATTRIBUTES (type)); |
| 1219 |
if (attr) |
| 1220 |
{ |
| 1221 |
regparm = TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr))); |
| 1222 |
return regparm; |
| 1223 |
} |
| 1224 |
} |
| 1225 |
else if ((ccvt & IX86_CALLCVT_FASTCALL) != 0) |
| 1226 |
return 2; |
| 1227 |
else if ((ccvt & IX86_CALLCVT_THISCALL) != 0) |
| 1228 |
return 1; |
| 1229 |
|
| 1230 |
/* Use register calling convention for local functions when possible. */ |
| 1231 |
if (decl |
| 1232 |
&& TREE_CODE (decl) == FUNCTION_DECL) |
| 1233 |
{ |
| 1234 |
cgraph_node *target = cgraph_node::get (decl); |
| 1235 |
if (target) |
| 1236 |
target = target->function_symbol (); |
| 1237 |
|
| 1238 |
/* Caller and callee must agree on the calling convention, so |
| 1239 |
checking here just optimize means that with |
| 1240 |
__attribute__((optimize (...))) caller could use regparm convention |
| 1241 |
and callee not, or vice versa. Instead look at whether the callee |
| 1242 |
is optimized or not. */ |
| 1243 |
if (target && opt_for_fn (target->decl, optimize) |
| 1244 |
&& !(profile_flag && !flag_fentry)) |
| 1245 |
{ |
| 1246 |
if (target->local && target->can_change_signature) |
| 1247 |
{ |
| 1248 |
int local_regparm, globals = 0, regno; |
| 1249 |
|
| 1250 |
/* Make sure no regparm register is taken by a |
| 1251 |
fixed register variable. */ |
| 1252 |
for (local_regparm = 0; local_regparm < REGPARM_MAX; |
| 1253 |
local_regparm++) |
| 1254 |
if (fixed_regs[local_regparm]) |
| 1255 |
break; |
| 1256 |
|
| 1257 |
/* We don't want to use regparm(3) for nested functions as |
| 1258 |
these use a static chain pointer in the third argument. */ |
| 1259 |
if (local_regparm == 3 && DECL_STATIC_CHAIN (target->decl)) |
| 1260 |
local_regparm = 2; |
| 1261 |
|
| 1262 |
/* Save a register for the split stack. */ |
| 1263 |
if (flag_split_stack) |
| 1264 |
{ |
| 1265 |
if (local_regparm == 3) |
| 1266 |
local_regparm = 2; |
| 1267 |
else if (local_regparm == 2 |
| 1268 |
&& DECL_STATIC_CHAIN (target->decl)) |
| 1269 |
local_regparm = 1; |
| 1270 |
} |
| 1271 |
|
| 1272 |
/* Each fixed register usage increases register pressure, |
| 1273 |
so less registers should be used for argument passing. |
| 1274 |
This functionality can be overriden by an explicit |
| 1275 |
regparm value. */ |
| 1276 |
for (regno = AX_REG; regno <= DI_REG; regno++) |
| 1277 |
if (fixed_regs[regno]) |
| 1278 |
globals++; |
| 1279 |
|
| 1280 |
local_regparm |
| 1281 |
= globals < local_regparm ? local_regparm - globals : 0; |
| 1282 |
|
| 1283 |
if (local_regparm > regparm) |
| 1284 |
regparm = local_regparm; |
| 1285 |
} |
| 1286 |
} |
| 1287 |
} |
| 1288 |
|
| 1289 |
return regparm; |
| 1290 |
} |
| 1291 |
|
| 1292 |
/* Return 1 or 2, if we can pass up to SSE_REGPARM_MAX SFmode (1) and |
| 1293 |
DFmode (2) arguments in SSE registers for a function with the |
| 1294 |
indicated TYPE and DECL. DECL may be NULL when calling function |
| 1295 |
indirectly or considering a libcall. Return -1 if any FP parameter |
| 1296 |
should be rejected by error. This is used in siutation we imply SSE |
| 1297 |
calling convetion but the function is called from another function with |
| 1298 |
SSE disabled. Otherwise return 0. */ |
| 1299 |
|
| 1300 |
static int |
| 1301 |
ix86_function_sseregparm (const_tree type, const_tree decl, bool warn) |
| 1302 |
{ |
| 1303 |
gcc_assert (!TARGET_64BIT); |
| 1304 |
|
| 1305 |
/* Use SSE registers to pass SFmode and DFmode arguments if requested |
| 1306 |
by the sseregparm attribute. */ |
| 1307 |
if (TARGET_SSEREGPARM |
| 1308 |
|| (type && lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type)))) |
| 1309 |
{ |
| 1310 |
if (!TARGET_SSE) |
| 1311 |
{ |
| 1312 |
if (warn) |
| 1313 |
{ |
| 1314 |
if (decl) |
| 1315 |
error ("calling %qD with attribute sseregparm without " |
| 1316 |
"SSE/SSE2 enabled", decl); |
| 1317 |
else |
| 1318 |
error ("calling %qT with attribute sseregparm without " |
| 1319 |
"SSE/SSE2 enabled", type); |
| 1320 |
} |
| 1321 |
return 0; |
| 1322 |
} |
| 1323 |
|
| 1324 |
return 2; |
| 1325 |
} |
| 1326 |
|
| 1327 |
if (!decl) |
| 1328 |
return 0; |
| 1329 |
|
| 1330 |
cgraph_node *target = cgraph_node::get (decl); |
| 1331 |
if (target) |
| 1332 |
target = target->function_symbol (); |
| 1333 |
|
| 1334 |
/* For local functions, pass up to SSE_REGPARM_MAX SFmode |
| 1335 |
(and DFmode for SSE2) arguments in SSE registers. */ |
| 1336 |
if (target |
| 1337 |
/* TARGET_SSE_MATH */ |
| 1338 |
&& (target_opts_for_fn (target->decl)->x_ix86_fpmath & FPMATH_SSE) |
| 1339 |
&& opt_for_fn (target->decl, optimize) |
| 1340 |
&& !(profile_flag && !flag_fentry)) |
| 1341 |
{ |
| 1342 |
if (target->local && target->can_change_signature) |
| 1343 |
{ |
| 1344 |
/* Refuse to produce wrong code when local function with SSE enabled |
| 1345 |
is called from SSE disabled function. |
| 1346 |
FIXME: We need a way to detect these cases cross-ltrans partition |
| 1347 |
and avoid using SSE calling conventions on local functions called |
| 1348 |
from function with SSE disabled. For now at least delay the |
| 1349 |
warning until we know we are going to produce wrong code. |
| 1350 |
See PR66047 */ |
| 1351 |
if (!TARGET_SSE && warn) |
| 1352 |
return -1; |
| 1353 |
return TARGET_SSE2_P (target_opts_for_fn (target->decl) |
| 1354 |
->x_ix86_isa_flags) ? 2 : 1; |
| 1355 |
} |
| 1356 |
} |
| 1357 |
|
| 1358 |
return 0; |
| 1359 |
} |
| 1360 |
|
| 1361 |
/* Return true if EAX is live at the start of the function. Used by |
| 1362 |
ix86_expand_prologue to determine if we need special help before |
| 1363 |
calling allocate_stack_worker. */ |
| 1364 |
|
| 1365 |
static bool |
| 1366 |
ix86_eax_live_at_start_p (void) |
| 1367 |
{ |
| 1368 |
/* Cheat. Don't bother working forward from ix86_function_regparm |
| 1369 |
to the function type to whether an actual argument is located in |
| 1370 |
eax. Instead just look at cfg info, which is still close enough |
| 1371 |
to correct at this point. This gives false positives for broken |
| 1372 |
functions that might use uninitialized data that happens to be |
| 1373 |
allocated in eax, but who cares? */ |
| 1374 |
return REGNO_REG_SET_P (df_get_live_out (ENTRY_BLOCK_PTR_FOR_FN (cfun)), 0); |
| 1375 |
} |
| 1376 |
|
| 1377 |
static bool |
| 1378 |
ix86_keep_aggregate_return_pointer (tree fntype) |
| 1379 |
{ |
| 1380 |
tree attr; |
| 1381 |
|
| 1382 |
if (!TARGET_64BIT) |
| 1383 |
{ |
| 1384 |
attr = lookup_attribute ("callee_pop_aggregate_return", |
| 1385 |
TYPE_ATTRIBUTES (fntype)); |
| 1386 |
if (attr) |
| 1387 |
return (TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr))) == 0); |
| 1388 |
|
| 1389 |
/* For 32-bit MS-ABI the default is to keep aggregate |
| 1390 |
return pointer. */ |
| 1391 |
if (ix86_function_type_abi (fntype) == MS_ABI) |
| 1392 |
return true; |
| 1393 |
} |
| 1394 |
return KEEP_AGGREGATE_RETURN_POINTER != 0; |
| 1395 |
} |
| 1396 |
|
| 1397 |
/* Value is the number of bytes of arguments automatically |
| 1398 |
popped when returning from a subroutine call. |
| 1399 |
FUNDECL is the declaration node of the function (as a tree), |
| 1400 |
FUNTYPE is the data type of the function (as a tree), |
| 1401 |
or for a library call it is an identifier node for the subroutine name. |
| 1402 |
SIZE is the number of bytes of arguments passed on the stack. |
| 1403 |
|
| 1404 |
On the 80386, the RTD insn may be used to pop them if the number |
| 1405 |
of args is fixed, but if the number is variable then the caller |
| 1406 |
must pop them all. RTD can't be used for library calls now |
| 1407 |
because the library is compiled with the Unix compiler. |
| 1408 |
Use of RTD is a selectable option, since it is incompatible with |
| 1409 |
standard Unix calling sequences. If the option is not selected, |
| 1410 |
the caller must always pop the args. |
| 1411 |
|
| 1412 |
The attribute stdcall is equivalent to RTD on a per module basis. */ |
| 1413 |
|
| 1414 |
static poly_int64 |
| 1415 |
ix86_return_pops_args (tree fundecl, tree funtype, poly_int64 size) |
| 1416 |
{ |
| 1417 |
unsigned int ccvt; |
| 1418 |
|
| 1419 |
/* None of the 64-bit ABIs pop arguments. */ |
| 1420 |
if (TARGET_64BIT) |
| 1421 |
return 0; |
| 1422 |
|
| 1423 |
ccvt = ix86_get_callcvt (funtype); |
| 1424 |
|
| 1425 |
if ((ccvt & (IX86_CALLCVT_STDCALL | IX86_CALLCVT_FASTCALL |
| 1426 |
| IX86_CALLCVT_THISCALL)) != 0 |
| 1427 |
&& ! stdarg_p (funtype)) |
| 1428 |
return size; |
| 1429 |
|
| 1430 |
/* Lose any fake structure return argument if it is passed on the stack. */ |
| 1431 |
if (aggregate_value_p (TREE_TYPE (funtype), fundecl) |
| 1432 |
&& !ix86_keep_aggregate_return_pointer (funtype)) |
| 1433 |
{ |
| 1434 |
int nregs = ix86_function_regparm (funtype, fundecl); |
| 1435 |
if (nregs == 0) |
| 1436 |
return GET_MODE_SIZE (Pmode); |
| 1437 |
} |
| 1438 |
|
| 1439 |
return 0; |
| 1440 |
} |
| 1441 |
|
| 1442 |
/* Implement the TARGET_LEGITIMATE_COMBINED_INSN hook. */ |
| 1443 |
|
| 1444 |
static bool |
| 1445 |
ix86_legitimate_combined_insn (rtx_insn *insn) |
| 1446 |
{ |
| 1447 |
int i; |
| 1448 |
|
| 1449 |
/* Check operand constraints in case hard registers were propagated |
| 1450 |
into insn pattern. This check prevents combine pass from |
| 1451 |
generating insn patterns with invalid hard register operands. |
| 1452 |
These invalid insns can eventually confuse reload to error out |
| 1453 |
with a spill failure. See also PRs 46829 and 46843. */ |
| 1454 |
|
| 1455 |
gcc_assert (INSN_CODE (insn) >= 0); |
| 1456 |
|
| 1457 |
extract_insn (insn); |
| 1458 |
preprocess_constraints (insn); |
| 1459 |
|
| 1460 |
int n_operands = recog_data.n_operands; |
| 1461 |
int n_alternatives = recog_data.n_alternatives; |
| 1462 |
for (i = 0; i < n_operands; i++) |
| 1463 |
{ |
| 1464 |
rtx op = recog_data.operand[i]; |
| 1465 |
machine_mode mode = GET_MODE (op); |
| 1466 |
const operand_alternative *op_alt; |
| 1467 |
int offset = 0; |
| 1468 |
bool win; |
| 1469 |
int j; |
| 1470 |
|
| 1471 |
/* A unary operator may be accepted by the predicate, but it |
| 1472 |
is irrelevant for matching constraints. */ |
| 1473 |
if (UNARY_P (op)) |
| 1474 |
op = XEXP (op, 0); |
| 1475 |
|
| 1476 |
if (SUBREG_P (op)) |
| 1477 |
{ |
| 1478 |
if (REG_P (SUBREG_REG (op)) |
| 1479 |
&& REGNO (SUBREG_REG (op)) < FIRST_PSEUDO_REGISTER) |
| 1480 |
offset = subreg_regno_offset (REGNO (SUBREG_REG (op)), |
| 1481 |
GET_MODE (SUBREG_REG (op)), |
| 1482 |
SUBREG_BYTE (op), |
| 1483 |
GET_MODE (op)); |
| 1484 |
op = SUBREG_REG (op); |
| 1485 |
} |
| 1486 |
|
| 1487 |
if (!(REG_P (op) && HARD_REGISTER_P (op))) |
| 1488 |
continue; |
| 1489 |
|
| 1490 |
op_alt = recog_op_alt; |
| 1491 |
|
| 1492 |
/* Operand has no constraints, anything is OK. */ |
| 1493 |
win = !n_alternatives; |
| 1494 |
|
| 1495 |
alternative_mask preferred = get_preferred_alternatives (insn); |
| 1496 |
for (j = 0; j < n_alternatives; j++, op_alt += n_operands) |
| 1497 |
{ |
| 1498 |
if (!TEST_BIT (preferred, j)) |
| 1499 |
continue; |
| 1500 |
if (op_alt[i].anything_ok |
| 1501 |
|| (op_alt[i].matches != -1 |
| 1502 |
&& operands_match_p |
| 1503 |
(recog_data.operand[i], |
| 1504 |
recog_data.operand[op_alt[i].matches])) |
| 1505 |
|| reg_fits_class_p (op, op_alt[i].cl, offset, mode)) |
| 1506 |
{ |
| 1507 |
win = true; |
| 1508 |
break; |
| 1509 |
} |
| 1510 |
} |
| 1511 |
|
| 1512 |
if (!win) |
| 1513 |
return false; |
| 1514 |
} |
| 1515 |
|
| 1516 |
return true; |
| 1517 |
} |
| 1518 |
|
| 1519 |
/* Implement the TARGET_ASAN_SHADOW_OFFSET hook. */ |
| 1520 |
|
| 1521 |
static unsigned HOST_WIDE_INT |
| 1522 |
ix86_asan_shadow_offset (void) |
| 1523 |
{ |
| 1524 |
return SUBTARGET_SHADOW_OFFSET; |
| 1525 |
} |
| 1526 |
|
| 1527 |
/* Argument support functions. */ |
| 1528 |
|
| 1529 |
/* Return true when register may be used to pass function parameters. */ |
| 1530 |
bool |
| 1531 |
ix86_function_arg_regno_p (int regno) |
| 1532 |
{ |
| 1533 |
int i; |
| 1534 |
enum calling_abi call_abi; |
| 1535 |
const int *parm_regs; |
| 1536 |
|
| 1537 |
if (TARGET_SSE && SSE_REGNO_P (regno) |
| 1538 |
&& regno < FIRST_SSE_REG + SSE_REGPARM_MAX) |
| 1539 |
return true; |
| 1540 |
|
| 1541 |
if (!TARGET_64BIT) |
| 1542 |
return (regno < REGPARM_MAX |
| 1543 |
|| (TARGET_MMX && MMX_REGNO_P (regno) |
| 1544 |
&& regno < FIRST_MMX_REG + MMX_REGPARM_MAX)); |
| 1545 |
|
| 1546 |
/* TODO: The function should depend on current function ABI but |
| 1547 |
builtins.cc would need updating then. Therefore we use the |
| 1548 |
default ABI. */ |
| 1549 |
call_abi = ix86_cfun_abi (); |
| 1550 |
|
| 1551 |
/* RAX is used as hidden argument to va_arg functions. */ |
| 1552 |
if (call_abi == SYSV_ABI && regno == AX_REG) |
| 1553 |
return true; |
| 1554 |
|
| 1555 |
if (call_abi == MS_ABI) |
| 1556 |
parm_regs = x86_64_ms_abi_int_parameter_registers; |
| 1557 |
else |
| 1558 |
parm_regs = x86_64_int_parameter_registers; |
| 1559 |
|
| 1560 |
for (i = 0; i < (call_abi == MS_ABI |
| 1561 |
? X86_64_MS_REGPARM_MAX : X86_64_REGPARM_MAX); i++) |
| 1562 |
if (regno == parm_regs[i]) |
| 1563 |
return true; |
| 1564 |
return false; |
| 1565 |
} |
| 1566 |
|
| 1567 |
/* Return if we do not know how to pass ARG solely in registers. */ |
| 1568 |
|
| 1569 |
static bool |
| 1570 |
ix86_must_pass_in_stack (const function_arg_info &arg) |
| 1571 |
{ |
| 1572 |
if (must_pass_in_stack_var_size_or_pad (arg)) |
| 1573 |
return true; |
| 1574 |
|
| 1575 |
/* For 32-bit, we want TImode aggregates to go on the stack. But watch out! |
| 1576 |
The layout_type routine is crafty and tries to trick us into passing |
| 1577 |
currently unsupported vector types on the stack by using TImode. */ |
| 1578 |
return (!TARGET_64BIT && arg.mode == TImode |
| 1579 |
&& arg.type && TREE_CODE (arg.type) != VECTOR_TYPE); |
| 1580 |
} |
| 1581 |
|
| 1582 |
/* It returns the size, in bytes, of the area reserved for arguments passed |
| 1583 |
in registers for the function represented by fndecl dependent to the used |
| 1584 |
abi format. */ |
| 1585 |
int |
| 1586 |
ix86_reg_parm_stack_space (const_tree fndecl) |
| 1587 |
{ |
| 1588 |
enum calling_abi call_abi = SYSV_ABI; |
| 1589 |
if (fndecl != NULL_TREE && TREE_CODE (fndecl) == FUNCTION_DECL) |
| 1590 |
call_abi = ix86_function_abi (fndecl); |
| 1591 |
else |
| 1592 |
call_abi = ix86_function_type_abi (fndecl); |
| 1593 |
if (TARGET_64BIT && call_abi == MS_ABI) |
| 1594 |
return 32; |
| 1595 |
return 0; |
| 1596 |
} |
| 1597 |
|
| 1598 |
/* We add this as a workaround in order to use libc_has_function |
| 1599 |
hook in i386.md. */ |
| 1600 |
bool |
| 1601 |
ix86_libc_has_function (enum function_class fn_class) |
| 1602 |
{ |
| 1603 |
return targetm.libc_has_function (fn_class, NULL_TREE); |
| 1604 |
} |
| 1605 |
|
| 1606 |
/* Returns value SYSV_ABI, MS_ABI dependent on fntype, |
| 1607 |
specifying the call abi used. */ |
| 1608 |
enum calling_abi |
| 1609 |
ix86_function_type_abi (const_tree fntype) |
| 1610 |
{ |
| 1611 |
enum calling_abi abi = ix86_abi; |
| 1612 |
|
| 1613 |
if (fntype == NULL_TREE || TYPE_ATTRIBUTES (fntype) == NULL_TREE) |
| 1614 |
return abi; |
| 1615 |
|
| 1616 |
if (abi == SYSV_ABI |
| 1617 |
&& lookup_attribute ("ms_abi", TYPE_ATTRIBUTES (fntype))) |
| 1618 |
{ |
| 1619 |
static int warned; |
| 1620 |
if (TARGET_X32 && !warned) |
| 1621 |
{ |
| 1622 |
error ("X32 does not support %<ms_abi%> attribute"); |
| 1623 |
warned = 1; |
| 1624 |
} |
| 1625 |
|
| 1626 |
abi = MS_ABI; |
| 1627 |
} |
| 1628 |
else if (abi == MS_ABI |
| 1629 |
&& lookup_attribute ("sysv_abi", TYPE_ATTRIBUTES (fntype))) |
| 1630 |
abi = SYSV_ABI; |
| 1631 |
|
| 1632 |
return abi; |
| 1633 |
} |
| 1634 |
|
| 1635 |
enum calling_abi |
| 1636 |
ix86_function_abi (const_tree fndecl) |
| 1637 |
{ |
| 1638 |
return fndecl ? ix86_function_type_abi (TREE_TYPE (fndecl)) : ix86_abi; |
| 1639 |
} |
| 1640 |
|
| 1641 |
/* Returns value SYSV_ABI, MS_ABI dependent on cfun, |
| 1642 |
specifying the call abi used. */ |
| 1643 |
enum calling_abi |
| 1644 |
ix86_cfun_abi (void) |
| 1645 |
{ |
| 1646 |
return cfun ? cfun->machine->call_abi : ix86_abi; |
| 1647 |
} |
| 1648 |
|
| 1649 |
bool |
| 1650 |
ix86_function_ms_hook_prologue (const_tree fn) |
| 1651 |
{ |
| 1652 |
if (fn && lookup_attribute ("ms_hook_prologue", DECL_ATTRIBUTES (fn))) |
| 1653 |
{ |
| 1654 |
if (decl_function_context (fn) != NULL_TREE) |
| 1655 |
error_at (DECL_SOURCE_LOCATION (fn), |
| 1656 |
"%<ms_hook_prologue%> attribute is not compatible " |
| 1657 |
"with nested function"); |
| 1658 |
else |
| 1659 |
return true; |
| 1660 |
} |
| 1661 |
return false; |
| 1662 |
} |
| 1663 |
|
| 1664 |
bool |
| 1665 |
ix86_function_naked (const_tree fn) |
| 1666 |
{ |
| 1667 |
if (fn && lookup_attribute ("naked", DECL_ATTRIBUTES (fn))) |
| 1668 |
return true; |
| 1669 |
|
| 1670 |
return false; |
| 1671 |
} |
| 1672 |
|
| 1673 |
/* Write the extra assembler code needed to declare a function properly. */ |
| 1674 |
|
| 1675 |
void |
| 1676 |
ix86_asm_output_function_label (FILE *out_file, const char *fname, |
| 1677 |
tree decl) |
| 1678 |
{ |
| 1679 |
bool is_ms_hook = ix86_function_ms_hook_prologue (decl); |
| 1680 |
|
| 1681 |
if (cfun) |
| 1682 |
cfun->machine->function_label_emitted = true; |
| 1683 |
|
| 1684 |
if (is_ms_hook) |
| 1685 |
{ |
| 1686 |
int i, filler_count = (TARGET_64BIT ? 32 : 16); |
| 1687 |
unsigned int filler_cc = 0xcccccccc; |
| 1688 |
|
| 1689 |
for (i = 0; i < filler_count; i += 4) |
| 1690 |
fprintf (out_file, ASM_LONG " %#x\n", filler_cc); |
| 1691 |
} |
| 1692 |
|
| 1693 |
#ifdef SUBTARGET_ASM_UNWIND_INIT |
| 1694 |
SUBTARGET_ASM_UNWIND_INIT (out_file); |
| 1695 |
#endif |
| 1696 |
|
| 1697 |
assemble_function_label_raw (out_file, fname); |
| 1698 |
|
| 1699 |
/* Output magic byte marker, if hot-patch attribute is set. */ |
| 1700 |
if (is_ms_hook) |
| 1701 |
{ |
| 1702 |
if (TARGET_64BIT) |
| 1703 |
{ |
| 1704 |
/* leaq [%rsp + 0], %rsp */ |
| 1705 |
fputs (ASM_BYTE "0x48, 0x8d, 0xa4, 0x24, 0x00, 0x00, 0x00, 0x00\n", |
| 1706 |
out_file); |
| 1707 |
} |
| 1708 |
else |
| 1709 |
{ |
| 1710 |
/* movl.s %edi, %edi |
| 1711 |
push %ebp |
| 1712 |
movl.s %esp, %ebp */ |
| 1713 |
fputs (ASM_BYTE "0x8b, 0xff, 0x55, 0x8b, 0xec\n", out_file); |
| 1714 |
} |
| 1715 |
} |
| 1716 |
} |
| 1717 |
|
| 1718 |
/* Implementation of call abi switching target hook. Specific to FNDECL |
| 1719 |
the specific call register sets are set. See also |
| 1720 |
ix86_conditional_register_usage for more details. */ |
| 1721 |
void |
| 1722 |
ix86_call_abi_override (const_tree fndecl) |
| 1723 |
{ |
| 1724 |
cfun->machine->call_abi = ix86_function_abi (fndecl); |
| 1725 |
} |
| 1726 |
|
| 1727 |
/* Return 1 if pseudo register should be created and used to hold |
| 1728 |
GOT address for PIC code. */ |
| 1729 |
bool |
| 1730 |
ix86_use_pseudo_pic_reg (void) |
| 1731 |
{ |
| 1732 |
if ((TARGET_64BIT |
| 1733 |
&& (ix86_cmodel == CM_SMALL_PIC |
| 1734 |
|| TARGET_PECOFF)) |
| 1735 |
|| !flag_pic) |
| 1736 |
return false; |
| 1737 |
return true; |
| 1738 |
} |
| 1739 |
|
| 1740 |
/* Initialize large model PIC register. */ |
| 1741 |
|
| 1742 |
static void |
| 1743 |
ix86_init_large_pic_reg (unsigned int tmp_regno) |
| 1744 |
{ |
| 1745 |
rtx_code_label *label; |
| 1746 |
rtx tmp_reg; |
| 1747 |
|
| 1748 |
gcc_assert (Pmode == DImode); |
| 1749 |
label = gen_label_rtx (); |
| 1750 |
emit_label (label); |
| 1751 |
LABEL_PRESERVE_P (label) = 1; |
| 1752 |
tmp_reg = gen_rtx_REG (Pmode, tmp_regno); |
| 1753 |
gcc_assert (REGNO (pic_offset_table_rtx) != tmp_regno); |
| 1754 |
emit_insn (gen_set_rip_rex64 (pic_offset_table_rtx, |
| 1755 |
label)); |
| 1756 |
emit_insn (gen_set_got_offset_rex64 (tmp_reg, label)); |
| 1757 |
emit_insn (gen_add2_insn (pic_offset_table_rtx, tmp_reg)); |
| 1758 |
const char *name = LABEL_NAME (label); |
| 1759 |
PUT_CODE (label, NOTE); |
| 1760 |
NOTE_KIND (label) = NOTE_INSN_DELETED_LABEL; |
| 1761 |
NOTE_DELETED_LABEL_NAME (label) = name; |
| 1762 |
} |
| 1763 |
|
| 1764 |
/* Create and initialize PIC register if required. */ |
| 1765 |
static void |
| 1766 |
ix86_init_pic_reg (void) |
| 1767 |
{ |
| 1768 |
edge entry_edge; |
| 1769 |
rtx_insn *seq; |
| 1770 |
|
| 1771 |
if (!ix86_use_pseudo_pic_reg ()) |
| 1772 |
return; |
| 1773 |
|
| 1774 |
start_sequence (); |
| 1775 |
|
| 1776 |
if (TARGET_64BIT) |
| 1777 |
{ |
| 1778 |
if (ix86_cmodel == CM_LARGE_PIC) |
| 1779 |
ix86_init_large_pic_reg (R11_REG); |
| 1780 |
else |
| 1781 |
emit_insn (gen_set_got_rex64 (pic_offset_table_rtx)); |
| 1782 |
} |
| 1783 |
else |
| 1784 |
{ |
| 1785 |
/* If there is future mcount call in the function it is more profitable |
| 1786 |
to emit SET_GOT into ABI defined REAL_PIC_OFFSET_TABLE_REGNUM. */ |
| 1787 |
rtx reg = crtl->profile |
| 1788 |
? gen_rtx_REG (Pmode, REAL_PIC_OFFSET_TABLE_REGNUM) |
| 1789 |
: pic_offset_table_rtx; |
| 1790 |
rtx_insn *insn = emit_insn (gen_set_got (reg)); |
| 1791 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 1792 |
if (crtl->profile) |
| 1793 |
emit_move_insn (pic_offset_table_rtx, reg); |
| 1794 |
add_reg_note (insn, REG_CFA_FLUSH_QUEUE, NULL_RTX); |
| 1795 |
} |
| 1796 |
|
| 1797 |
seq = get_insns (); |
| 1798 |
end_sequence (); |
| 1799 |
|
| 1800 |
entry_edge = single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun)); |
| 1801 |
insert_insn_on_edge (seq, entry_edge); |
| 1802 |
commit_one_edge_insertion (entry_edge); |
| 1803 |
} |
| 1804 |
|
| 1805 |
/* Initialize a variable CUM of type CUMULATIVE_ARGS |
| 1806 |
for a call to a function whose data type is FNTYPE. |
| 1807 |
For a library call, FNTYPE is 0. */ |
| 1808 |
|
| 1809 |
void |
| 1810 |
init_cumulative_args (CUMULATIVE_ARGS *cum, /* Argument info to initialize */ |
| 1811 |
tree fntype, /* tree ptr for function decl */ |
| 1812 |
rtx libname, /* SYMBOL_REF of library name or 0 */ |
| 1813 |
tree fndecl, |
| 1814 |
int caller) |
| 1815 |
{ |
| 1816 |
struct cgraph_node *local_info_node = NULL; |
| 1817 |
struct cgraph_node *target = NULL; |
| 1818 |
|
| 1819 |
/* Set silent_p to false to raise an error for invalid calls when |
| 1820 |
expanding function body. */ |
| 1821 |
cfun->machine->silent_p = false; |
| 1822 |
|
| 1823 |
memset (cum, 0, sizeof (*cum)); |
| 1824 |
|
| 1825 |
if (fndecl) |
| 1826 |
{ |
| 1827 |
target = cgraph_node::get (fndecl); |
| 1828 |
if (target) |
| 1829 |
{ |
| 1830 |
target = target->function_symbol (); |
| 1831 |
local_info_node = cgraph_node::local_info_node (target->decl); |
| 1832 |
cum->call_abi = ix86_function_abi (target->decl); |
| 1833 |
} |
| 1834 |
else |
| 1835 |
cum->call_abi = ix86_function_abi (fndecl); |
| 1836 |
} |
| 1837 |
else |
| 1838 |
cum->call_abi = ix86_function_type_abi (fntype); |
| 1839 |
|
| 1840 |
cum->caller = caller; |
| 1841 |
|
| 1842 |
/* Set up the number of registers to use for passing arguments. */ |
| 1843 |
cum->nregs = ix86_regparm; |
| 1844 |
if (TARGET_64BIT) |
| 1845 |
{ |
| 1846 |
cum->nregs = (cum->call_abi == SYSV_ABI |
| 1847 |
? X86_64_REGPARM_MAX |
| 1848 |
: X86_64_MS_REGPARM_MAX); |
| 1849 |
} |
| 1850 |
if (TARGET_SSE) |
| 1851 |
{ |
| 1852 |
cum->sse_nregs = SSE_REGPARM_MAX; |
| 1853 |
if (TARGET_64BIT) |
| 1854 |
{ |
| 1855 |
cum->sse_nregs = (cum->call_abi == SYSV_ABI |
| 1856 |
? X86_64_SSE_REGPARM_MAX |
| 1857 |
: X86_64_MS_SSE_REGPARM_MAX); |
| 1858 |
} |
| 1859 |
} |
| 1860 |
if (TARGET_MMX) |
| 1861 |
cum->mmx_nregs = MMX_REGPARM_MAX; |
| 1862 |
cum->warn_avx512f = true; |
| 1863 |
cum->warn_avx = true; |
| 1864 |
cum->warn_sse = true; |
| 1865 |
cum->warn_mmx = true; |
| 1866 |
|
| 1867 |
/* Because type might mismatch in between caller and callee, we need to |
| 1868 |
use actual type of function for local calls. |
| 1869 |
FIXME: cgraph_analyze can be told to actually record if function uses |
| 1870 |
va_start so for local functions maybe_vaarg can be made aggressive |
| 1871 |
helping K&R code. |
| 1872 |
FIXME: once typesytem is fixed, we won't need this code anymore. */ |
| 1873 |
if (local_info_node && local_info_node->local |
| 1874 |
&& local_info_node->can_change_signature) |
| 1875 |
fntype = TREE_TYPE (target->decl); |
| 1876 |
cum->stdarg = stdarg_p (fntype); |
| 1877 |
cum->maybe_vaarg = (fntype |
| 1878 |
? (!prototype_p (fntype) || stdarg_p (fntype)) |
| 1879 |
: !libname); |
| 1880 |
|
| 1881 |
cum->decl = fndecl; |
| 1882 |
|
| 1883 |
cum->warn_empty = !warn_abi || cum->stdarg; |
| 1884 |
if (!cum->warn_empty && fntype) |
| 1885 |
{ |
| 1886 |
function_args_iterator iter; |
| 1887 |
tree argtype; |
| 1888 |
bool seen_empty_type = false; |
| 1889 |
FOREACH_FUNCTION_ARGS (fntype, argtype, iter) |
| 1890 |
{ |
| 1891 |
if (argtype == error_mark_node || VOID_TYPE_P (argtype)) |
| 1892 |
break; |
| 1893 |
if (TYPE_EMPTY_P (argtype)) |
| 1894 |
seen_empty_type = true; |
| 1895 |
else if (seen_empty_type) |
| 1896 |
{ |
| 1897 |
cum->warn_empty = true; |
| 1898 |
break; |
| 1899 |
} |
| 1900 |
} |
| 1901 |
} |
| 1902 |
|
| 1903 |
if (!TARGET_64BIT) |
| 1904 |
{ |
| 1905 |
/* If there are variable arguments, then we won't pass anything |
| 1906 |
in registers in 32-bit mode. */ |
| 1907 |
if (stdarg_p (fntype)) |
| 1908 |
{ |
| 1909 |
cum->nregs = 0; |
| 1910 |
/* Since in 32-bit, variable arguments are always passed on |
| 1911 |
stack, there is scratch register available for indirect |
| 1912 |
sibcall. */ |
| 1913 |
cfun->machine->arg_reg_available = true; |
| 1914 |
cum->sse_nregs = 0; |
| 1915 |
cum->mmx_nregs = 0; |
| 1916 |
cum->warn_avx512f = false; |
| 1917 |
cum->warn_avx = false; |
| 1918 |
cum->warn_sse = false; |
| 1919 |
cum->warn_mmx = false; |
| 1920 |
return; |
| 1921 |
} |
| 1922 |
|
| 1923 |
/* Use ecx and edx registers if function has fastcall attribute, |
| 1924 |
else look for regparm information. */ |
| 1925 |
if (fntype) |
| 1926 |
{ |
| 1927 |
unsigned int ccvt = ix86_get_callcvt (fntype); |
| 1928 |
if ((ccvt & IX86_CALLCVT_THISCALL) != 0) |
| 1929 |
{ |
| 1930 |
cum->nregs = 1; |
| 1931 |
cum->fastcall = 1; /* Same first register as in fastcall. */ |
| 1932 |
} |
| 1933 |
else if ((ccvt & IX86_CALLCVT_FASTCALL) != 0) |
| 1934 |
{ |
| 1935 |
cum->nregs = 2; |
| 1936 |
cum->fastcall = 1; |
| 1937 |
} |
| 1938 |
else |
| 1939 |
cum->nregs = ix86_function_regparm (fntype, fndecl); |
| 1940 |
} |
| 1941 |
|
| 1942 |
/* Set up the number of SSE registers used for passing SFmode |
| 1943 |
and DFmode arguments. Warn for mismatching ABI. */ |
| 1944 |
cum->float_in_sse = ix86_function_sseregparm (fntype, fndecl, true); |
| 1945 |
} |
| 1946 |
|
| 1947 |
cfun->machine->arg_reg_available = (cum->nregs > 0); |
| 1948 |
} |
| 1949 |
|
| 1950 |
/* Return the "natural" mode for TYPE. In most cases, this is just TYPE_MODE. |
| 1951 |
But in the case of vector types, it is some vector mode. |
| 1952 |
|
| 1953 |
When we have only some of our vector isa extensions enabled, then there |
| 1954 |
are some modes for which vector_mode_supported_p is false. For these |
| 1955 |
modes, the generic vector support in gcc will choose some non-vector mode |
| 1956 |
in order to implement the type. By computing the natural mode, we'll |
| 1957 |
select the proper ABI location for the operand and not depend on whatever |
| 1958 |
the middle-end decides to do with these vector types. |
| 1959 |
|
| 1960 |
The midde-end can't deal with the vector types > 16 bytes. In this |
| 1961 |
case, we return the original mode and warn ABI change if CUM isn't |
| 1962 |
NULL. |
| 1963 |
|
| 1964 |
If INT_RETURN is true, warn ABI change if the vector mode isn't |
| 1965 |
available for function return value. */ |
| 1966 |
|
| 1967 |
static machine_mode |
| 1968 |
type_natural_mode (const_tree type, const CUMULATIVE_ARGS *cum, |
| 1969 |
bool in_return) |
| 1970 |
{ |
| 1971 |
machine_mode mode = TYPE_MODE (type); |
| 1972 |
|
| 1973 |
if (VECTOR_TYPE_P (type) && !VECTOR_MODE_P (mode)) |
| 1974 |
{ |
| 1975 |
HOST_WIDE_INT size = int_size_in_bytes (type); |
| 1976 |
if ((size == 8 || size == 16 || size == 32 || size == 64) |
| 1977 |
/* ??? Generic code allows us to create width 1 vectors. Ignore. */ |
| 1978 |
&& TYPE_VECTOR_SUBPARTS (type) > 1) |
| 1979 |
{ |
| 1980 |
machine_mode innermode = TYPE_MODE (TREE_TYPE (type)); |
| 1981 |
|
| 1982 |
/* There are no XFmode vector modes ... */ |
| 1983 |
if (innermode == XFmode) |
| 1984 |
return mode; |
| 1985 |
|
| 1986 |
/* ... and no decimal float vector modes. */ |
| 1987 |
if (DECIMAL_FLOAT_MODE_P (innermode)) |
| 1988 |
return mode; |
| 1989 |
|
| 1990 |
if (SCALAR_FLOAT_TYPE_P (TREE_TYPE (type))) |
| 1991 |
mode = MIN_MODE_VECTOR_FLOAT; |
| 1992 |
else |
| 1993 |
mode = MIN_MODE_VECTOR_INT; |
| 1994 |
|
| 1995 |
/* Get the mode which has this inner mode and number of units. */ |
| 1996 |
FOR_EACH_MODE_FROM (mode, mode) |
| 1997 |
if (GET_MODE_NUNITS (mode) == TYPE_VECTOR_SUBPARTS (type) |
| 1998 |
&& GET_MODE_INNER (mode) == innermode) |
| 1999 |
{ |
| 2000 |
if (size == 64 && (!TARGET_AVX512F || !TARGET_EVEX512) |
| 2001 |
&& !TARGET_IAMCU) |
| 2002 |
{ |
| 2003 |
static bool warnedavx512f; |
| 2004 |
static bool warnedavx512f_ret; |
| 2005 |
|
| 2006 |
if (cum && cum->warn_avx512f && !warnedavx512f) |
| 2007 |
{ |
| 2008 |
if (warning (OPT_Wpsabi, "AVX512F vector argument " |
| 2009 |
"without AVX512F enabled changes the ABI")) |
| 2010 |
warnedavx512f = true; |
| 2011 |
} |
| 2012 |
else if (in_return && !warnedavx512f_ret) |
| 2013 |
{ |
| 2014 |
if (warning (OPT_Wpsabi, "AVX512F vector return " |
| 2015 |
"without AVX512F enabled changes the ABI")) |
| 2016 |
warnedavx512f_ret = true; |
| 2017 |
} |
| 2018 |
|
| 2019 |
return TYPE_MODE (type); |
| 2020 |
} |
| 2021 |
else if (size == 32 && !TARGET_AVX && !TARGET_IAMCU) |
| 2022 |
{ |
| 2023 |
static bool warnedavx; |
| 2024 |
static bool warnedavx_ret; |
| 2025 |
|
| 2026 |
if (cum && cum->warn_avx && !warnedavx) |
| 2027 |
{ |
| 2028 |
if (warning (OPT_Wpsabi, "AVX vector argument " |
| 2029 |
"without AVX enabled changes the ABI")) |
| 2030 |
warnedavx = true; |
| 2031 |
} |
| 2032 |
else if (in_return && !warnedavx_ret) |
| 2033 |
{ |
| 2034 |
if (warning (OPT_Wpsabi, "AVX vector return " |
| 2035 |
"without AVX enabled changes the ABI")) |
| 2036 |
warnedavx_ret = true; |
| 2037 |
} |
| 2038 |
|
| 2039 |
return TYPE_MODE (type); |
| 2040 |
} |
| 2041 |
else if (((size == 8 && TARGET_64BIT) || size == 16) |
| 2042 |
&& !TARGET_SSE |
| 2043 |
&& !TARGET_IAMCU) |
| 2044 |
{ |
| 2045 |
static bool warnedsse; |
| 2046 |
static bool warnedsse_ret; |
| 2047 |
|
| 2048 |
if (cum && cum->warn_sse && !warnedsse) |
| 2049 |
{ |
| 2050 |
if (warning (OPT_Wpsabi, "SSE vector argument " |
| 2051 |
"without SSE enabled changes the ABI")) |
| 2052 |
warnedsse = true; |
| 2053 |
} |
| 2054 |
else if (!TARGET_64BIT && in_return && !warnedsse_ret) |
| 2055 |
{ |
| 2056 |
if (warning (OPT_Wpsabi, "SSE vector return " |
| 2057 |
"without SSE enabled changes the ABI")) |
| 2058 |
warnedsse_ret = true; |
| 2059 |
} |
| 2060 |
} |
| 2061 |
else if ((size == 8 && !TARGET_64BIT) |
| 2062 |
&& (!cfun |
| 2063 |
|| cfun->machine->func_type == TYPE_NORMAL) |
| 2064 |
&& !TARGET_MMX |
| 2065 |
&& !TARGET_IAMCU) |
| 2066 |
{ |
| 2067 |
static bool warnedmmx; |
| 2068 |
static bool warnedmmx_ret; |
| 2069 |
|
| 2070 |
if (cum && cum->warn_mmx && !warnedmmx) |
| 2071 |
{ |
| 2072 |
if (warning (OPT_Wpsabi, "MMX vector argument " |
| 2073 |
"without MMX enabled changes the ABI")) |
| 2074 |
warnedmmx = true; |
| 2075 |
} |
| 2076 |
else if (in_return && !warnedmmx_ret) |
| 2077 |
{ |
| 2078 |
if (warning (OPT_Wpsabi, "MMX vector return " |
| 2079 |
"without MMX enabled changes the ABI")) |
| 2080 |
warnedmmx_ret = true; |
| 2081 |
} |
| 2082 |
} |
| 2083 |
return mode; |
| 2084 |
} |
| 2085 |
|
| 2086 |
gcc_unreachable (); |
| 2087 |
} |
| 2088 |
} |
| 2089 |
|
| 2090 |
return mode; |
| 2091 |
} |
| 2092 |
|
| 2093 |
/* We want to pass a value in REGNO whose "natural" mode is MODE. However, |
| 2094 |
this may not agree with the mode that the type system has chosen for the |
| 2095 |
register, which is ORIG_MODE. If ORIG_MODE is not BLKmode, then we can |
| 2096 |
go ahead and use it. Otherwise we have to build a PARALLEL instead. */ |
| 2097 |
|
| 2098 |
static rtx |
| 2099 |
gen_reg_or_parallel (machine_mode mode, machine_mode orig_mode, |
| 2100 |
unsigned int regno) |
| 2101 |
{ |
| 2102 |
rtx tmp; |
| 2103 |
|
| 2104 |
if (orig_mode != BLKmode) |
| 2105 |
tmp = gen_rtx_REG (orig_mode, regno); |
| 2106 |
else |
| 2107 |
{ |
| 2108 |
tmp = gen_rtx_REG (mode, regno); |
| 2109 |
tmp = gen_rtx_EXPR_LIST (VOIDmode, tmp, const0_rtx); |
| 2110 |
tmp = gen_rtx_PARALLEL (orig_mode, gen_rtvec (1, tmp)); |
| 2111 |
} |
| 2112 |
|
| 2113 |
return tmp; |
| 2114 |
} |
| 2115 |
|
| 2116 |
/* x86-64 register passing implementation. See x86-64 ABI for details. Goal |
| 2117 |
of this code is to classify each 8bytes of incoming argument by the register |
| 2118 |
class and assign registers accordingly. */ |
| 2119 |
|
| 2120 |
/* Return the union class of CLASS1 and CLASS2. |
| 2121 |
See the x86-64 PS ABI for details. */ |
| 2122 |
|
| 2123 |
static enum x86_64_reg_class |
| 2124 |
merge_classes (enum x86_64_reg_class class1, enum x86_64_reg_class class2) |
| 2125 |
{ |
| 2126 |
/* Rule #1: If both classes are equal, this is the resulting class. */ |
| 2127 |
if (class1 == class2) |
| 2128 |
return class1; |
| 2129 |
|
| 2130 |
/* Rule #2: If one of the classes is NO_CLASS, the resulting class is |
| 2131 |
the other class. */ |
| 2132 |
if (class1 == X86_64_NO_CLASS) |
| 2133 |
return class2; |
| 2134 |
if (class2 == X86_64_NO_CLASS) |
| 2135 |
return class1; |
| 2136 |
|
| 2137 |
/* Rule #3: If one of the classes is MEMORY, the result is MEMORY. */ |
| 2138 |
if (class1 == X86_64_MEMORY_CLASS || class2 == X86_64_MEMORY_CLASS) |
| 2139 |
return X86_64_MEMORY_CLASS; |
| 2140 |
|
| 2141 |
/* Rule #4: If one of the classes is INTEGER, the result is INTEGER. */ |
| 2142 |
if ((class1 == X86_64_INTEGERSI_CLASS |
| 2143 |
&& (class2 == X86_64_SSESF_CLASS || class2 == X86_64_SSEHF_CLASS)) |
| 2144 |
|| (class2 == X86_64_INTEGERSI_CLASS |
| 2145 |
&& (class1 == X86_64_SSESF_CLASS || class1 == X86_64_SSEHF_CLASS))) |
| 2146 |
return X86_64_INTEGERSI_CLASS; |
| 2147 |
if (class1 == X86_64_INTEGER_CLASS || class1 == X86_64_INTEGERSI_CLASS |
| 2148 |
|| class2 == X86_64_INTEGER_CLASS || class2 == X86_64_INTEGERSI_CLASS) |
| 2149 |
return X86_64_INTEGER_CLASS; |
| 2150 |
|
| 2151 |
/* Rule #5: If one of the classes is X87, X87UP, or COMPLEX_X87 class, |
| 2152 |
MEMORY is used. */ |
| 2153 |
if (class1 == X86_64_X87_CLASS |
| 2154 |
|| class1 == X86_64_X87UP_CLASS |
| 2155 |
|| class1 == X86_64_COMPLEX_X87_CLASS |
| 2156 |
|| class2 == X86_64_X87_CLASS |
| 2157 |
|| class2 == X86_64_X87UP_CLASS |
| 2158 |
|| class2 == X86_64_COMPLEX_X87_CLASS) |
| 2159 |
return X86_64_MEMORY_CLASS; |
| 2160 |
|
| 2161 |
/* Rule #6: Otherwise class SSE is used. */ |
| 2162 |
return X86_64_SSE_CLASS; |
| 2163 |
} |
| 2164 |
|
| 2165 |
/* Classify the argument of type TYPE and mode MODE. |
| 2166 |
CLASSES will be filled by the register class used to pass each word |
| 2167 |
of the operand. The number of words is returned. In case the parameter |
| 2168 |
should be passed in memory, 0 is returned. As a special case for zero |
| 2169 |
sized containers, classes[0] will be NO_CLASS and 1 is returned. |
| 2170 |
|
| 2171 |
BIT_OFFSET is used internally for handling records and specifies offset |
| 2172 |
of the offset in bits modulo 512 to avoid overflow cases. |
| 2173 |
|
| 2174 |
See the x86-64 PS ABI for details. |
| 2175 |
*/ |
| 2176 |
|
| 2177 |
static int |
| 2178 |
classify_argument (machine_mode mode, const_tree type, |
| 2179 |
enum x86_64_reg_class classes[MAX_CLASSES], int bit_offset, |
| 2180 |
int &zero_width_bitfields) |
| 2181 |
{ |
| 2182 |
HOST_WIDE_INT bytes |
| 2183 |
= mode == BLKmode ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode); |
| 2184 |
int words = CEIL (bytes + (bit_offset % 64) / 8, UNITS_PER_WORD); |
| 2185 |
|
| 2186 |
/* Variable sized entities are always passed/returned in memory. */ |
| 2187 |
if (bytes < 0) |
| 2188 |
return 0; |
| 2189 |
|
| 2190 |
if (mode != VOIDmode) |
| 2191 |
{ |
| 2192 |
/* The value of "named" doesn't matter. */ |
| 2193 |
function_arg_info arg (const_cast<tree> (type), mode, /*named=*/true); |
| 2194 |
if (targetm.calls.must_pass_in_stack (arg)) |
| 2195 |
return 0; |
| 2196 |
} |
| 2197 |
|
| 2198 |
if (type && (AGGREGATE_TYPE_P (type) |
| 2199 |
|| (TREE_CODE (type) == BITINT_TYPE && words > 1))) |
| 2200 |
{ |
| 2201 |
int i; |
| 2202 |
tree field; |
| 2203 |
enum x86_64_reg_class subclasses[MAX_CLASSES]; |
| 2204 |
|
| 2205 |
/* On x86-64 we pass structures larger than 64 bytes on the stack. */ |
| 2206 |
if (bytes > 64) |
| 2207 |
return 0; |
| 2208 |
|
| 2209 |
for (i = 0; i < words; i++) |
| 2210 |
classes[i] = X86_64_NO_CLASS; |
| 2211 |
|
| 2212 |
/* Zero sized arrays or structures are NO_CLASS. We return 0 to |
| 2213 |
signalize memory class, so handle it as special case. */ |
| 2214 |
if (!words) |
| 2215 |
{ |
| 2216 |
classes[0] = X86_64_NO_CLASS; |
| 2217 |
return 1; |
| 2218 |
} |
| 2219 |
|
| 2220 |
/* Classify each field of record and merge classes. */ |
| 2221 |
switch (TREE_CODE (type)) |
| 2222 |
{ |
| 2223 |
case RECORD_TYPE: |
| 2224 |
/* And now merge the fields of structure. */ |
| 2225 |
for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) |
| 2226 |
{ |
| 2227 |
if (TREE_CODE (field) == FIELD_DECL) |
| 2228 |
{ |
| 2229 |
int num; |
| 2230 |
|
| 2231 |
if (TREE_TYPE (field) == error_mark_node) |
| 2232 |
continue; |
| 2233 |
|
| 2234 |
/* Bitfields are always classified as integer. Handle them |
| 2235 |
early, since later code would consider them to be |
| 2236 |
misaligned integers. */ |
| 2237 |
if (DECL_BIT_FIELD (field)) |
| 2238 |
{ |
| 2239 |
if (integer_zerop (DECL_SIZE (field))) |
| 2240 |
{ |
| 2241 |
if (DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD (field)) |
| 2242 |
continue; |
| 2243 |
if (zero_width_bitfields != 2) |
| 2244 |
{ |
| 2245 |
zero_width_bitfields = 1; |
| 2246 |
continue; |
| 2247 |
} |
| 2248 |
} |
| 2249 |
for (i = (int_bit_position (field) |
| 2250 |
+ (bit_offset % 64)) / 8 / 8; |
| 2251 |
i < ((int_bit_position (field) + (bit_offset % 64)) |
| 2252 |
+ tree_to_shwi (DECL_SIZE (field)) |
| 2253 |
+ 63) / 8 / 8; i++) |
| 2254 |
classes[i] |
| 2255 |
= merge_classes (X86_64_INTEGER_CLASS, classes[i]); |
| 2256 |
} |
| 2257 |
else |
| 2258 |
{ |
| 2259 |
int pos; |
| 2260 |
|
| 2261 |
type = TREE_TYPE (field); |
| 2262 |
|
| 2263 |
/* Flexible array member is ignored. */ |
| 2264 |
if (TYPE_MODE (type) == BLKmode |
| 2265 |
&& TREE_CODE (type) == ARRAY_TYPE |
| 2266 |
&& TYPE_SIZE (type) == NULL_TREE |
| 2267 |
&& TYPE_DOMAIN (type) != NULL_TREE |
| 2268 |
&& (TYPE_MAX_VALUE (TYPE_DOMAIN (type)) |
| 2269 |
== NULL_TREE)) |
| 2270 |
{ |
| 2271 |
static bool warned; |
| 2272 |
|
| 2273 |
if (!warned && warn_psabi) |
| 2274 |
{ |
| 2275 |
warned = true; |
| 2276 |
inform (input_location, |
| 2277 |
"the ABI of passing struct with" |
| 2278 |
" a flexible array member has" |
| 2279 |
" changed in GCC 4.4"); |
| 2280 |
} |
| 2281 |
continue; |
| 2282 |
} |
| 2283 |
num = classify_argument (TYPE_MODE (type), type, |
| 2284 |
subclasses, |
| 2285 |
(int_bit_position (field) |
| 2286 |
+ bit_offset) % 512, |
| 2287 |
zero_width_bitfields); |
| 2288 |
if (!num) |
| 2289 |
return 0; |
| 2290 |
pos = (int_bit_position (field) |
| 2291 |
+ (bit_offset % 64)) / 8 / 8; |
| 2292 |
for (i = 0; i < num && (i + pos) < words; i++) |
| 2293 |
classes[i + pos] |
| 2294 |
= merge_classes (subclasses[i], classes[i + pos]); |
| 2295 |
} |
| 2296 |
} |
| 2297 |
} |
| 2298 |
break; |
| 2299 |
|
| 2300 |
case ARRAY_TYPE: |
| 2301 |
/* Arrays are handled as small records. */ |
| 2302 |
{ |
| 2303 |
int num; |
| 2304 |
num = classify_argument (TYPE_MODE (TREE_TYPE (type)), |
| 2305 |
TREE_TYPE (type), subclasses, bit_offset, |
| 2306 |
zero_width_bitfields); |
| 2307 |
if (!num) |
| 2308 |
return 0; |
| 2309 |
|
| 2310 |
/* The partial classes are now full classes. */ |
| 2311 |
if (subclasses[0] == X86_64_SSESF_CLASS && bytes != 4) |
| 2312 |
subclasses[0] = X86_64_SSE_CLASS; |
| 2313 |
if (subclasses[0] == X86_64_SSEHF_CLASS && bytes != 2) |
| 2314 |
subclasses[0] = X86_64_SSE_CLASS; |
| 2315 |
if (subclasses[0] == X86_64_INTEGERSI_CLASS |
| 2316 |
&& !((bit_offset % 64) == 0 && bytes == 4)) |
| 2317 |
subclasses[0] = X86_64_INTEGER_CLASS; |
| 2318 |
|
| 2319 |
for (i = 0; i < words; i++) |
| 2320 |
classes[i] = subclasses[i % num]; |
| 2321 |
|
| 2322 |
break; |
| 2323 |
} |
| 2324 |
case UNION_TYPE: |
| 2325 |
case QUAL_UNION_TYPE: |
| 2326 |
/* Unions are similar to RECORD_TYPE but offset is always 0. |
| 2327 |
*/ |
| 2328 |
for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) |
| 2329 |
{ |
| 2330 |
if (TREE_CODE (field) == FIELD_DECL) |
| 2331 |
{ |
| 2332 |
int num; |
| 2333 |
|
| 2334 |
if (TREE_TYPE (field) == error_mark_node) |
| 2335 |
continue; |
| 2336 |
|
| 2337 |
num = classify_argument (TYPE_MODE (TREE_TYPE (field)), |
| 2338 |
TREE_TYPE (field), subclasses, |
| 2339 |
bit_offset, zero_width_bitfields); |
| 2340 |
if (!num) |
| 2341 |
return 0; |
| 2342 |
for (i = 0; i < num && i < words; i++) |
| 2343 |
classes[i] = merge_classes (subclasses[i], classes[i]); |
| 2344 |
} |
| 2345 |
} |
| 2346 |
break; |
| 2347 |
|
| 2348 |
case BITINT_TYPE: |
| 2349 |
/* _BitInt(N) for N > 64 is passed as structure containing |
| 2350 |
(N + 63) / 64 64-bit elements. */ |
| 2351 |
if (words > 2) |
| 2352 |
return 0; |
| 2353 |
classes[0] = classes[1] = X86_64_INTEGER_CLASS; |
| 2354 |
return 2; |
| 2355 |
|
| 2356 |
default: |
| 2357 |
gcc_unreachable (); |
| 2358 |
} |
| 2359 |
|
| 2360 |
if (words > 2) |
| 2361 |
{ |
| 2362 |
/* When size > 16 bytes, if the first one isn't |
| 2363 |
X86_64_SSE_CLASS or any other ones aren't |
| 2364 |
X86_64_SSEUP_CLASS, everything should be passed in |
| 2365 |
memory. */ |
| 2366 |
if (classes[0] != X86_64_SSE_CLASS) |
| 2367 |
return 0; |
| 2368 |
|
| 2369 |
for (i = 1; i < words; i++) |
| 2370 |
if (classes[i] != X86_64_SSEUP_CLASS) |
| 2371 |
return 0; |
| 2372 |
} |
| 2373 |
|
| 2374 |
/* Final merger cleanup. */ |
| 2375 |
for (i = 0; i < words; i++) |
| 2376 |
{ |
| 2377 |
/* If one class is MEMORY, everything should be passed in |
| 2378 |
memory. */ |
| 2379 |
if (classes[i] == X86_64_MEMORY_CLASS) |
| 2380 |
return 0; |
| 2381 |
|
| 2382 |
/* The X86_64_SSEUP_CLASS should be always preceded by |
| 2383 |
X86_64_SSE_CLASS or X86_64_SSEUP_CLASS. */ |
| 2384 |
if (classes[i] == X86_64_SSEUP_CLASS |
| 2385 |
&& classes[i - 1] != X86_64_SSE_CLASS |
| 2386 |
&& classes[i - 1] != X86_64_SSEUP_CLASS) |
| 2387 |
{ |
| 2388 |
/* The first one should never be X86_64_SSEUP_CLASS. */ |
| 2389 |
gcc_assert (i != 0); |
| 2390 |
classes[i] = X86_64_SSE_CLASS; |
| 2391 |
} |
| 2392 |
|
| 2393 |
/* If X86_64_X87UP_CLASS isn't preceded by X86_64_X87_CLASS, |
| 2394 |
everything should be passed in memory. */ |
| 2395 |
if (classes[i] == X86_64_X87UP_CLASS |
| 2396 |
&& (classes[i - 1] != X86_64_X87_CLASS)) |
| 2397 |
{ |
| 2398 |
static bool warned; |
| 2399 |
|
| 2400 |
/* The first one should never be X86_64_X87UP_CLASS. */ |
| 2401 |
gcc_assert (i != 0); |
| 2402 |
if (!warned && warn_psabi) |
| 2403 |
{ |
| 2404 |
warned = true; |
| 2405 |
inform (input_location, |
| 2406 |
"the ABI of passing union with %<long double%>" |
| 2407 |
" has changed in GCC 4.4"); |
| 2408 |
} |
| 2409 |
return 0; |
| 2410 |
} |
| 2411 |
} |
| 2412 |
return words; |
| 2413 |
} |
| 2414 |
|
| 2415 |
/* Compute alignment needed. We align all types to natural boundaries with |
| 2416 |
exception of XFmode that is aligned to 64bits. */ |
| 2417 |
if (mode != VOIDmode && mode != BLKmode) |
| 2418 |
{ |
| 2419 |
int mode_alignment = GET_MODE_BITSIZE (mode); |
| 2420 |
|
| 2421 |
if (mode == XFmode) |
| 2422 |
mode_alignment = 128; |
| 2423 |
else if (mode == XCmode) |
| 2424 |
mode_alignment = 256; |
| 2425 |
if (COMPLEX_MODE_P (mode)) |
| 2426 |
mode_alignment /= 2; |
| 2427 |
/* Misaligned fields are always returned in memory. */ |
| 2428 |
if (bit_offset % mode_alignment) |
| 2429 |
return 0; |
| 2430 |
} |
| 2431 |
|
| 2432 |
/* for V1xx modes, just use the base mode */ |
| 2433 |
if (VECTOR_MODE_P (mode) && mode != V1DImode && mode != V1TImode |
| 2434 |
&& GET_MODE_UNIT_SIZE (mode) == bytes) |
| 2435 |
mode = GET_MODE_INNER (mode); |
| 2436 |
|
| 2437 |
/* Classification of atomic types. */ |
| 2438 |
switch (mode) |
| 2439 |
{ |
| 2440 |
case E_SDmode: |
| 2441 |
case E_DDmode: |
| 2442 |
classes[0] = X86_64_SSE_CLASS; |
| 2443 |
return 1; |
| 2444 |
case E_TDmode: |
| 2445 |
classes[0] = X86_64_SSE_CLASS; |
| 2446 |
classes[1] = X86_64_SSEUP_CLASS; |
| 2447 |
return 2; |
| 2448 |
case E_DImode: |
| 2449 |
case E_SImode: |
| 2450 |
case E_HImode: |
| 2451 |
case E_QImode: |
| 2452 |
case E_CSImode: |
| 2453 |
case E_CHImode: |
| 2454 |
case E_CQImode: |
| 2455 |
{ |
| 2456 |
int size = bit_offset + (int) GET_MODE_BITSIZE (mode); |
| 2457 |
|
| 2458 |
/* Analyze last 128 bits only. */ |
| 2459 |
size = (size - 1) & 0x7f; |
| 2460 |
|
| 2461 |
if (size < 32) |
| 2462 |
{ |
| 2463 |
classes[0] = X86_64_INTEGERSI_CLASS; |
| 2464 |
return 1; |
| 2465 |
} |
| 2466 |
else if (size < 64) |
| 2467 |
{ |
| 2468 |
classes[0] = X86_64_INTEGER_CLASS; |
| 2469 |
return 1; |
| 2470 |
} |
| 2471 |
else if (size < 64+32) |
| 2472 |
{ |
| 2473 |
classes[0] = X86_64_INTEGER_CLASS; |
| 2474 |
classes[1] = X86_64_INTEGERSI_CLASS; |
| 2475 |
return 2; |
| 2476 |
} |
| 2477 |
else if (size < 64+64) |
| 2478 |
{ |
| 2479 |
classes[0] = classes[1] = X86_64_INTEGER_CLASS; |
| 2480 |
return 2; |
| 2481 |
} |
| 2482 |
else |
| 2483 |
gcc_unreachable (); |
| 2484 |
} |
| 2485 |
case E_CDImode: |
| 2486 |
case E_TImode: |
| 2487 |
classes[0] = classes[1] = X86_64_INTEGER_CLASS; |
| 2488 |
return 2; |
| 2489 |
case E_COImode: |
| 2490 |
case E_OImode: |
| 2491 |
/* OImode shouldn't be used directly. */ |
| 2492 |
gcc_unreachable (); |
| 2493 |
case E_CTImode: |
| 2494 |
return 0; |
| 2495 |
case E_HFmode: |
| 2496 |
case E_BFmode: |
| 2497 |
if (!(bit_offset % 64)) |
| 2498 |
classes[0] = X86_64_SSEHF_CLASS; |
| 2499 |
else |
| 2500 |
classes[0] = X86_64_SSE_CLASS; |
| 2501 |
return 1; |
| 2502 |
case E_SFmode: |
| 2503 |
if (!(bit_offset % 64)) |
| 2504 |
classes[0] = X86_64_SSESF_CLASS; |
| 2505 |
else |
| 2506 |
classes[0] = X86_64_SSE_CLASS; |
| 2507 |
return 1; |
| 2508 |
case E_DFmode: |
| 2509 |
classes[0] = X86_64_SSEDF_CLASS; |
| 2510 |
return 1; |
| 2511 |
case E_XFmode: |
| 2512 |
classes[0] = X86_64_X87_CLASS; |
| 2513 |
classes[1] = X86_64_X87UP_CLASS; |
| 2514 |
return 2; |
| 2515 |
case E_TFmode: |
| 2516 |
classes[0] = X86_64_SSE_CLASS; |
| 2517 |
classes[1] = X86_64_SSEUP_CLASS; |
| 2518 |
return 2; |
| 2519 |
case E_HCmode: |
| 2520 |
case E_BCmode: |
| 2521 |
classes[0] = X86_64_SSE_CLASS; |
| 2522 |
if (!(bit_offset % 64)) |
| 2523 |
return 1; |
| 2524 |
else |
| 2525 |
{ |
| 2526 |
classes[1] = X86_64_SSEHF_CLASS; |
| 2527 |
return 2; |
| 2528 |
} |
| 2529 |
case E_SCmode: |
| 2530 |
classes[0] = X86_64_SSE_CLASS; |
| 2531 |
if (!(bit_offset % 64)) |
| 2532 |
return 1; |
| 2533 |
else |
| 2534 |
{ |
| 2535 |
static bool warned; |
| 2536 |
|
| 2537 |
if (!warned && warn_psabi) |
| 2538 |
{ |
| 2539 |
warned = true; |
| 2540 |
inform (input_location, |
| 2541 |
"the ABI of passing structure with %<complex float%>" |
| 2542 |
" member has changed in GCC 4.4"); |
| 2543 |
} |
| 2544 |
classes[1] = X86_64_SSESF_CLASS; |
| 2545 |
return 2; |
| 2546 |
} |
| 2547 |
case E_DCmode: |
| 2548 |
classes[0] = X86_64_SSEDF_CLASS; |
| 2549 |
classes[1] = X86_64_SSEDF_CLASS; |
| 2550 |
return 2; |
| 2551 |
case E_XCmode: |
| 2552 |
classes[0] = X86_64_COMPLEX_X87_CLASS; |
| 2553 |
return 1; |
| 2554 |
case E_TCmode: |
| 2555 |
/* This modes is larger than 16 bytes. */ |
| 2556 |
return 0; |
| 2557 |
case E_V8SFmode: |
| 2558 |
case E_V8SImode: |
| 2559 |
case E_V32QImode: |
| 2560 |
case E_V16HFmode: |
| 2561 |
case E_V16BFmode: |
| 2562 |
case E_V16HImode: |
| 2563 |
case E_V4DFmode: |
| 2564 |
case E_V4DImode: |
| 2565 |
classes[0] = X86_64_SSE_CLASS; |
| 2566 |
classes[1] = X86_64_SSEUP_CLASS; |
| 2567 |
classes[2] = X86_64_SSEUP_CLASS; |
| 2568 |
classes[3] = X86_64_SSEUP_CLASS; |
| 2569 |
return 4; |
| 2570 |
case E_V8DFmode: |
| 2571 |
case E_V16SFmode: |
| 2572 |
case E_V32HFmode: |
| 2573 |
case E_V32BFmode: |
| 2574 |
case E_V8DImode: |
| 2575 |
case E_V16SImode: |
| 2576 |
case E_V32HImode: |
| 2577 |
case E_V64QImode: |
| 2578 |
classes[0] = X86_64_SSE_CLASS; |
| 2579 |
classes[1] = X86_64_SSEUP_CLASS; |
| 2580 |
classes[2] = X86_64_SSEUP_CLASS; |
| 2581 |
classes[3] = X86_64_SSEUP_CLASS; |
| 2582 |
classes[4] = X86_64_SSEUP_CLASS; |
| 2583 |
classes[5] = X86_64_SSEUP_CLASS; |
| 2584 |
classes[6] = X86_64_SSEUP_CLASS; |
| 2585 |
classes[7] = X86_64_SSEUP_CLASS; |
| 2586 |
return 8; |
| 2587 |
case E_V4SFmode: |
| 2588 |
case E_V4SImode: |
| 2589 |
case E_V16QImode: |
| 2590 |
case E_V8HImode: |
| 2591 |
case E_V8HFmode: |
| 2592 |
case E_V8BFmode: |
| 2593 |
case E_V2DFmode: |
| 2594 |
case E_V2DImode: |
| 2595 |
classes[0] = X86_64_SSE_CLASS; |
| 2596 |
classes[1] = X86_64_SSEUP_CLASS; |
| 2597 |
return 2; |
| 2598 |
case E_V1TImode: |
| 2599 |
case E_V1DImode: |
| 2600 |
case E_V2SFmode: |
| 2601 |
case E_V2SImode: |
| 2602 |
case E_V4HImode: |
| 2603 |
case E_V4HFmode: |
| 2604 |
case E_V4BFmode: |
| 2605 |
case E_V2HFmode: |
| 2606 |
case E_V2BFmode: |
| 2607 |
case E_V8QImode: |
| 2608 |
classes[0] = X86_64_SSE_CLASS; |
| 2609 |
return 1; |
| 2610 |
case E_BLKmode: |
| 2611 |
case E_VOIDmode: |
| 2612 |
return 0; |
| 2613 |
default: |
| 2614 |
gcc_assert (VECTOR_MODE_P (mode)); |
| 2615 |
|
| 2616 |
if (bytes > 16) |
| 2617 |
return 0; |
| 2618 |
|
| 2619 |
gcc_assert (GET_MODE_CLASS (GET_MODE_INNER (mode)) == MODE_INT); |
| 2620 |
|
| 2621 |
if (bit_offset + GET_MODE_BITSIZE (mode) <= 32) |
| 2622 |
classes[0] = X86_64_INTEGERSI_CLASS; |
| 2623 |
else |
| 2624 |
classes[0] = X86_64_INTEGER_CLASS; |
| 2625 |
classes[1] = X86_64_INTEGER_CLASS; |
| 2626 |
return 1 + (bytes > 8); |
| 2627 |
} |
| 2628 |
} |
| 2629 |
|
| 2630 |
/* Wrapper around classify_argument with the extra zero_width_bitfields |
| 2631 |
argument, to diagnose GCC 12.1 ABI differences for C. */ |
| 2632 |
|
| 2633 |
static int |
| 2634 |
classify_argument (machine_mode mode, const_tree type, |
| 2635 |
enum x86_64_reg_class classes[MAX_CLASSES], int bit_offset) |
| 2636 |
{ |
| 2637 |
int zero_width_bitfields = 0; |
| 2638 |
static bool warned = false; |
| 2639 |
int n = classify_argument (mode, type, classes, bit_offset, |
| 2640 |
zero_width_bitfields); |
| 2641 |
if (!zero_width_bitfields || warned || !warn_psabi) |
| 2642 |
return n; |
| 2643 |
enum x86_64_reg_class alt_classes[MAX_CLASSES]; |
| 2644 |
zero_width_bitfields = 2; |
| 2645 |
if (classify_argument (mode, type, alt_classes, bit_offset, |
| 2646 |
zero_width_bitfields) != n) |
| 2647 |
zero_width_bitfields = 3; |
| 2648 |
else |
| 2649 |
for (int i = 0; i < n; i++) |
| 2650 |
if (classes[i] != alt_classes[i]) |
| 2651 |
{ |
| 2652 |
zero_width_bitfields = 3; |
| 2653 |
break; |
| 2654 |
} |
| 2655 |
if (zero_width_bitfields == 3) |
| 2656 |
{ |
| 2657 |
warned = true; |
| 2658 |
const char *url |
| 2659 |
= CHANGES_ROOT_URL "gcc-12/changes.html#zero_width_bitfields"; |
| 2660 |
|
| 2661 |
inform (input_location, |
| 2662 |
"the ABI of passing C structures with zero-width bit-fields" |
| 2663 |
" has changed in GCC %{12.1%}", url); |
| 2664 |
} |
| 2665 |
return n; |
| 2666 |
} |
| 2667 |
|
| 2668 |
/* Examine the argument and return set number of register required in each |
| 2669 |
class. Return true iff parameter should be passed in memory. */ |
| 2670 |
|
| 2671 |
static bool |
| 2672 |
examine_argument (machine_mode mode, const_tree type, int in_return, |
| 2673 |
int *int_nregs, int *sse_nregs) |
| 2674 |
{ |
| 2675 |
enum x86_64_reg_class regclass[MAX_CLASSES]; |
| 2676 |
int n = classify_argument (mode, type, regclass, 0); |
| 2677 |
|
| 2678 |
*int_nregs = 0; |
| 2679 |
*sse_nregs = 0; |
| 2680 |
|
| 2681 |
if (!n) |
| 2682 |
return true; |
| 2683 |
for (n--; n >= 0; n--) |
| 2684 |
switch (regclass[n]) |
| 2685 |
{ |
| 2686 |
case X86_64_INTEGER_CLASS: |
| 2687 |
case X86_64_INTEGERSI_CLASS: |
| 2688 |
(*int_nregs)++; |
| 2689 |
break; |
| 2690 |
case X86_64_SSE_CLASS: |
| 2691 |
case X86_64_SSEHF_CLASS: |
| 2692 |
case X86_64_SSESF_CLASS: |
| 2693 |
case X86_64_SSEDF_CLASS: |
| 2694 |
(*sse_nregs)++; |
| 2695 |
break; |
| 2696 |
case X86_64_NO_CLASS: |
| 2697 |
case X86_64_SSEUP_CLASS: |
| 2698 |
break; |
| 2699 |
case X86_64_X87_CLASS: |
| 2700 |
case X86_64_X87UP_CLASS: |
| 2701 |
case X86_64_COMPLEX_X87_CLASS: |
| 2702 |
if (!in_return) |
| 2703 |
return true; |
| 2704 |
break; |
| 2705 |
case X86_64_MEMORY_CLASS: |
| 2706 |
gcc_unreachable (); |
| 2707 |
} |
| 2708 |
|
| 2709 |
return false; |
| 2710 |
} |
| 2711 |
|
| 2712 |
/* Construct container for the argument used by GCC interface. See |
| 2713 |
FUNCTION_ARG for the detailed description. */ |
| 2714 |
|
| 2715 |
static rtx |
| 2716 |
construct_container (machine_mode mode, machine_mode orig_mode, |
| 2717 |
const_tree type, int in_return, int nintregs, int nsseregs, |
| 2718 |
const int *intreg, int sse_regno) |
| 2719 |
{ |
| 2720 |
/* The following variables hold the static issued_error state. */ |
| 2721 |
static bool issued_sse_arg_error; |
| 2722 |
static bool issued_sse_ret_error; |
| 2723 |
static bool issued_x87_ret_error; |
| 2724 |
|
| 2725 |
machine_mode tmpmode; |
| 2726 |
int bytes |
| 2727 |
= mode == BLKmode ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode); |
| 2728 |
enum x86_64_reg_class regclass[MAX_CLASSES]; |
| 2729 |
int n; |
| 2730 |
int i; |
| 2731 |
int nexps = 0; |
| 2732 |
int needed_sseregs, needed_intregs; |
| 2733 |
rtx exp[MAX_CLASSES]; |
| 2734 |
rtx ret; |
| 2735 |
|
| 2736 |
n = classify_argument (mode, type, regclass, 0); |
| 2737 |
if (!n) |
| 2738 |
return NULL; |
| 2739 |
if (examine_argument (mode, type, in_return, &needed_intregs, |
| 2740 |
&needed_sseregs)) |
| 2741 |
return NULL; |
| 2742 |
if (needed_intregs > nintregs || needed_sseregs > nsseregs) |
| 2743 |
return NULL; |
| 2744 |
|
| 2745 |
/* We allowed the user to turn off SSE for kernel mode. Don't crash if |
| 2746 |
some less clueful developer tries to use floating-point anyway. */ |
| 2747 |
if (needed_sseregs |
| 2748 |
&& (!TARGET_SSE || (VALID_SSE2_TYPE_MODE (mode) && !TARGET_SSE2))) |
| 2749 |
{ |
| 2750 |
/* Return early if we shouldn't raise an error for invalid |
| 2751 |
calls. */ |
| 2752 |
if (cfun != NULL && cfun->machine->silent_p) |
| 2753 |
return NULL; |
| 2754 |
if (in_return) |
| 2755 |
{ |
| 2756 |
if (!issued_sse_ret_error) |
| 2757 |
{ |
| 2758 |
if (VALID_SSE2_TYPE_MODE (mode)) |
| 2759 |
error ("SSE register return with SSE2 disabled"); |
| 2760 |
else |
| 2761 |
error ("SSE register return with SSE disabled"); |
| 2762 |
issued_sse_ret_error = true; |
| 2763 |
} |
| 2764 |
} |
| 2765 |
else if (!issued_sse_arg_error) |
| 2766 |
{ |
| 2767 |
if (VALID_SSE2_TYPE_MODE (mode)) |
| 2768 |
error ("SSE register argument with SSE2 disabled"); |
| 2769 |
else |
| 2770 |
error ("SSE register argument with SSE disabled"); |
| 2771 |
issued_sse_arg_error = true; |
| 2772 |
} |
| 2773 |
return NULL; |
| 2774 |
} |
| 2775 |
|
| 2776 |
/* Likewise, error if the ABI requires us to return values in the |
| 2777 |
x87 registers and the user specified -mno-80387. */ |
| 2778 |
if (!TARGET_FLOAT_RETURNS_IN_80387 && in_return) |
| 2779 |
for (i = 0; i < n; i++) |
| 2780 |
if (regclass[i] == X86_64_X87_CLASS |
| 2781 |
|| regclass[i] == X86_64_X87UP_CLASS |
| 2782 |
|| regclass[i] == X86_64_COMPLEX_X87_CLASS) |
| 2783 |
{ |
| 2784 |
/* Return early if we shouldn't raise an error for invalid |
| 2785 |
calls. */ |
| 2786 |
if (cfun != NULL && cfun->machine->silent_p) |
| 2787 |
return NULL; |
| 2788 |
if (!issued_x87_ret_error) |
| 2789 |
{ |
| 2790 |
error ("x87 register return with x87 disabled"); |
| 2791 |
issued_x87_ret_error = true; |
| 2792 |
} |
| 2793 |
return NULL; |
| 2794 |
} |
| 2795 |
|
| 2796 |
/* First construct simple cases. Avoid SCmode, since we want to use |
| 2797 |
single register to pass this type. */ |
| 2798 |
if (n == 1 && mode != SCmode && mode != HCmode) |
| 2799 |
switch (regclass[0]) |
| 2800 |
{ |
| 2801 |
case X86_64_INTEGER_CLASS: |
| 2802 |
case X86_64_INTEGERSI_CLASS: |
| 2803 |
return gen_rtx_REG (mode, intreg[0]); |
| 2804 |
case X86_64_SSE_CLASS: |
| 2805 |
case X86_64_SSEHF_CLASS: |
| 2806 |
case X86_64_SSESF_CLASS: |
| 2807 |
case X86_64_SSEDF_CLASS: |
| 2808 |
if (mode != BLKmode) |
| 2809 |
return gen_reg_or_parallel (mode, orig_mode, |
| 2810 |
GET_SSE_REGNO (sse_regno)); |
| 2811 |
break; |
| 2812 |
case X86_64_X87_CLASS: |
| 2813 |
case X86_64_COMPLEX_X87_CLASS: |
| 2814 |
return gen_rtx_REG (mode, FIRST_STACK_REG); |
| 2815 |
case X86_64_NO_CLASS: |
| 2816 |
/* Zero sized array, struct or class. */ |
| 2817 |
return NULL; |
| 2818 |
default: |
| 2819 |
gcc_unreachable (); |
| 2820 |
} |
| 2821 |
if (n == 2 |
| 2822 |
&& regclass[0] == X86_64_SSE_CLASS |
| 2823 |
&& regclass[1] == X86_64_SSEUP_CLASS |
| 2824 |
&& mode != BLKmode) |
| 2825 |
return gen_reg_or_parallel (mode, orig_mode, |
| 2826 |
GET_SSE_REGNO (sse_regno)); |
| 2827 |
if (n == 4 |
| 2828 |
&& regclass[0] == X86_64_SSE_CLASS |
| 2829 |
&& regclass[1] == X86_64_SSEUP_CLASS |
| 2830 |
&& regclass[2] == X86_64_SSEUP_CLASS |
| 2831 |
&& regclass[3] == X86_64_SSEUP_CLASS |
| 2832 |
&& mode != BLKmode) |
| 2833 |
return gen_reg_or_parallel (mode, orig_mode, |
| 2834 |
GET_SSE_REGNO (sse_regno)); |
| 2835 |
if (n == 8 |
| 2836 |
&& regclass[0] == X86_64_SSE_CLASS |
| 2837 |
&& regclass[1] == X86_64_SSEUP_CLASS |
| 2838 |
&& regclass[2] == X86_64_SSEUP_CLASS |
| 2839 |
&& regclass[3] == X86_64_SSEUP_CLASS |
| 2840 |
&& regclass[4] == X86_64_SSEUP_CLASS |
| 2841 |
&& regclass[5] == X86_64_SSEUP_CLASS |
| 2842 |
&& regclass[6] == X86_64_SSEUP_CLASS |
| 2843 |
&& regclass[7] == X86_64_SSEUP_CLASS |
| 2844 |
&& mode != BLKmode) |
| 2845 |
return gen_reg_or_parallel (mode, orig_mode, |
| 2846 |
GET_SSE_REGNO (sse_regno)); |
| 2847 |
if (n == 2 |
| 2848 |
&& regclass[0] == X86_64_X87_CLASS |
| 2849 |
&& regclass[1] == X86_64_X87UP_CLASS) |
| 2850 |
return gen_rtx_REG (XFmode, FIRST_STACK_REG); |
| 2851 |
|
| 2852 |
if (n == 2 |
| 2853 |
&& regclass[0] == X86_64_INTEGER_CLASS |
| 2854 |
&& regclass[1] == X86_64_INTEGER_CLASS |
| 2855 |
&& (mode == CDImode || mode == TImode || mode == BLKmode) |
| 2856 |
&& intreg[0] + 1 == intreg[1]) |
| 2857 |
{ |
| 2858 |
if (mode == BLKmode) |
| 2859 |
{ |
| 2860 |
/* Use TImode for BLKmode values in 2 integer registers. */ |
| 2861 |
exp[0] = gen_rtx_EXPR_LIST (VOIDmode, |
| 2862 |
gen_rtx_REG (TImode, intreg[0]), |
| 2863 |
GEN_INT (0)); |
| 2864 |
ret = gen_rtx_PARALLEL (mode, rtvec_alloc (1)); |
| 2865 |
XVECEXP (ret, 0, 0) = exp[0]; |
| 2866 |
return ret; |
| 2867 |
} |
| 2868 |
else |
| 2869 |
return gen_rtx_REG (mode, intreg[0]); |
| 2870 |
} |
| 2871 |
|
| 2872 |
/* Otherwise figure out the entries of the PARALLEL. */ |
| 2873 |
for (i = 0; i < n; i++) |
| 2874 |
{ |
| 2875 |
int pos; |
| 2876 |
|
| 2877 |
switch (regclass[i]) |
| 2878 |
{ |
| 2879 |
case X86_64_NO_CLASS: |
| 2880 |
break; |
| 2881 |
case X86_64_INTEGER_CLASS: |
| 2882 |
case X86_64_INTEGERSI_CLASS: |
| 2883 |
/* Merge TImodes on aligned occasions here too. */ |
| 2884 |
if (i * 8 + 8 > bytes) |
| 2885 |
{ |
| 2886 |
unsigned int tmpbits = (bytes - i * 8) * BITS_PER_UNIT; |
| 2887 |
if (!int_mode_for_size (tmpbits, 0).exists (&tmpmode)) |
| 2888 |
/* We've requested 24 bytes we |
| 2889 |
don't have mode for. Use DImode. */ |
| 2890 |
tmpmode = DImode; |
| 2891 |
} |
| 2892 |
else if (regclass[i] == X86_64_INTEGERSI_CLASS) |
| 2893 |
tmpmode = SImode; |
| 2894 |
else |
| 2895 |
tmpmode = DImode; |
| 2896 |
exp [nexps++] |
| 2897 |
= gen_rtx_EXPR_LIST (VOIDmode, |
| 2898 |
gen_rtx_REG (tmpmode, *intreg), |
| 2899 |
GEN_INT (i*8)); |
| 2900 |
intreg++; |
| 2901 |
break; |
| 2902 |
case X86_64_SSEHF_CLASS: |
| 2903 |
tmpmode = (mode == BFmode ? BFmode : HFmode); |
| 2904 |
exp [nexps++] |
| 2905 |
= gen_rtx_EXPR_LIST (VOIDmode, |
| 2906 |
gen_rtx_REG (tmpmode, |
| 2907 |
GET_SSE_REGNO (sse_regno)), |
| 2908 |
GEN_INT (i*8)); |
| 2909 |
sse_regno++; |
| 2910 |
break; |
| 2911 |
case X86_64_SSESF_CLASS: |
| 2912 |
exp [nexps++] |
| 2913 |
= gen_rtx_EXPR_LIST (VOIDmode, |
| 2914 |
gen_rtx_REG (SFmode, |
| 2915 |
GET_SSE_REGNO (sse_regno)), |
| 2916 |
GEN_INT (i*8)); |
| 2917 |
sse_regno++; |
| 2918 |
break; |
| 2919 |
case X86_64_SSEDF_CLASS: |
| 2920 |
exp [nexps++] |
| 2921 |
= gen_rtx_EXPR_LIST (VOIDmode, |
| 2922 |
gen_rtx_REG (DFmode, |
| 2923 |
GET_SSE_REGNO (sse_regno)), |
| 2924 |
GEN_INT (i*8)); |
| 2925 |
sse_regno++; |
| 2926 |
break; |
| 2927 |
case X86_64_SSE_CLASS: |
| 2928 |
pos = i; |
| 2929 |
switch (n) |
| 2930 |
{ |
| 2931 |
case 1: |
| 2932 |
tmpmode = DImode; |
| 2933 |
break; |
| 2934 |
case 2: |
| 2935 |
if (i == 0 && regclass[1] == X86_64_SSEUP_CLASS) |
| 2936 |
{ |
| 2937 |
tmpmode = TImode; |
| 2938 |
i++; |
| 2939 |
} |
| 2940 |
else |
| 2941 |
tmpmode = DImode; |
| 2942 |
break; |
| 2943 |
case 4: |
| 2944 |
gcc_assert (i == 0 |
| 2945 |
&& regclass[1] == X86_64_SSEUP_CLASS |
| 2946 |
&& regclass[2] == X86_64_SSEUP_CLASS |
| 2947 |
&& regclass[3] == X86_64_SSEUP_CLASS); |
| 2948 |
tmpmode = OImode; |
| 2949 |
i += 3; |
| 2950 |
break; |
| 2951 |
case 8: |
| 2952 |
gcc_assert (i == 0 |
| 2953 |
&& regclass[1] == X86_64_SSEUP_CLASS |
| 2954 |
&& regclass[2] == X86_64_SSEUP_CLASS |
| 2955 |
&& regclass[3] == X86_64_SSEUP_CLASS |
| 2956 |
&& regclass[4] == X86_64_SSEUP_CLASS |
| 2957 |
&& regclass[5] == X86_64_SSEUP_CLASS |
| 2958 |
&& regclass[6] == X86_64_SSEUP_CLASS |
| 2959 |
&& regclass[7] == X86_64_SSEUP_CLASS); |
| 2960 |
tmpmode = XImode; |
| 2961 |
i += 7; |
| 2962 |
break; |
| 2963 |
default: |
| 2964 |
gcc_unreachable (); |
| 2965 |
} |
| 2966 |
exp [nexps++] |
| 2967 |
= gen_rtx_EXPR_LIST (VOIDmode, |
| 2968 |
gen_rtx_REG (tmpmode, |
| 2969 |
GET_SSE_REGNO (sse_regno)), |
| 2970 |
GEN_INT (pos*8)); |
| 2971 |
sse_regno++; |
| 2972 |
break; |
| 2973 |
default: |
| 2974 |
gcc_unreachable (); |
| 2975 |
} |
| 2976 |
} |
| 2977 |
|
| 2978 |
/* Empty aligned struct, union or class. */ |
| 2979 |
if (nexps == 0) |
| 2980 |
return NULL; |
| 2981 |
|
| 2982 |
ret = gen_rtx_PARALLEL (mode, rtvec_alloc (nexps)); |
| 2983 |
for (i = 0; i < nexps; i++) |
| 2984 |
XVECEXP (ret, 0, i) = exp [i]; |
| 2985 |
return ret; |
| 2986 |
} |
| 2987 |
|
| 2988 |
/* Update the data in CUM to advance over an argument of mode MODE |
| 2989 |
and data type TYPE. (TYPE is null for libcalls where that information |
| 2990 |
may not be available.) |
| 2991 |
|
| 2992 |
Return a number of integer regsiters advanced over. */ |
| 2993 |
|
| 2994 |
static int |
| 2995 |
function_arg_advance_32 (CUMULATIVE_ARGS *cum, machine_mode mode, |
| 2996 |
const_tree type, HOST_WIDE_INT bytes, |
| 2997 |
HOST_WIDE_INT words) |
| 2998 |
{ |
| 2999 |
int res = 0; |
| 3000 |
bool error_p = false; |
| 3001 |
|
| 3002 |
if (TARGET_IAMCU) |
| 3003 |
{ |
| 3004 |
/* Intel MCU psABI passes scalars and aggregates no larger than 8 |
| 3005 |
bytes in registers. */ |
| 3006 |
if (!VECTOR_MODE_P (mode) && bytes <= 8) |
| 3007 |
goto pass_in_reg; |
| 3008 |
return res; |
| 3009 |
} |
| 3010 |
|
| 3011 |
switch (mode) |
| 3012 |
{ |
| 3013 |
default: |
| 3014 |
break; |
| 3015 |
|
| 3016 |
case E_BLKmode: |
| 3017 |
if (bytes < 0) |
| 3018 |
break; |
| 3019 |
/* FALLTHRU */ |
| 3020 |
|
| 3021 |
case E_DImode: |
| 3022 |
case E_SImode: |
| 3023 |
case E_HImode: |
| 3024 |
case E_QImode: |
| 3025 |
pass_in_reg: |
| 3026 |
cum->words += words; |
| 3027 |
cum->nregs -= words; |
| 3028 |
cum->regno += words; |
| 3029 |
if (cum->nregs >= 0) |
| 3030 |
res = words; |
| 3031 |
if (cum->nregs <= 0) |
| 3032 |
{ |
| 3033 |
cum->nregs = 0; |
| 3034 |
cfun->machine->arg_reg_available = false; |
| 3035 |
cum->regno = 0; |
| 3036 |
} |
| 3037 |
break; |
| 3038 |
|
| 3039 |
case E_OImode: |
| 3040 |
/* OImode shouldn't be used directly. */ |
| 3041 |
gcc_unreachable (); |
| 3042 |
|
| 3043 |
case E_DFmode: |
| 3044 |
if (cum->float_in_sse == -1) |
| 3045 |
error_p = true; |
| 3046 |
if (cum->float_in_sse < 2) |
| 3047 |
break; |
| 3048 |
/* FALLTHRU */ |
| 3049 |
case E_SFmode: |
| 3050 |
if (cum->float_in_sse == -1) |
| 3051 |
error_p = true; |
| 3052 |
if (cum->float_in_sse < 1) |
| 3053 |
break; |
| 3054 |
/* FALLTHRU */ |
| 3055 |
|
| 3056 |
case E_V16HFmode: |
| 3057 |
case E_V16BFmode: |
| 3058 |
case E_V8SFmode: |
| 3059 |
case E_V8SImode: |
| 3060 |
case E_V64QImode: |
| 3061 |
case E_V32HImode: |
| 3062 |
case E_V16SImode: |
| 3063 |
case E_V8DImode: |
| 3064 |
case E_V32HFmode: |
| 3065 |
case E_V32BFmode: |
| 3066 |
case E_V16SFmode: |
| 3067 |
case E_V8DFmode: |
| 3068 |
case E_V32QImode: |
| 3069 |
case E_V16HImode: |
| 3070 |
case E_V4DFmode: |
| 3071 |
case E_V4DImode: |
| 3072 |
case E_TImode: |
| 3073 |
case E_V16QImode: |
| 3074 |
case E_V8HImode: |
| 3075 |
case E_V4SImode: |
| 3076 |
case E_V2DImode: |
| 3077 |
case E_V8HFmode: |
| 3078 |
case E_V8BFmode: |
| 3079 |
case E_V4SFmode: |
| 3080 |
case E_V2DFmode: |
| 3081 |
if (!type || !AGGREGATE_TYPE_P (type)) |
| 3082 |
{ |
| 3083 |
cum->sse_words += words; |
| 3084 |
cum->sse_nregs -= 1; |
| 3085 |
cum->sse_regno += 1; |
| 3086 |
if (cum->sse_nregs <= 0) |
| 3087 |
{ |
| 3088 |
cum->sse_nregs = 0; |
| 3089 |
cum->sse_regno = 0; |
| 3090 |
} |
| 3091 |
} |
| 3092 |
break; |
| 3093 |
|
| 3094 |
case E_V8QImode: |
| 3095 |
case E_V4HImode: |
| 3096 |
case E_V4HFmode: |
| 3097 |
case E_V4BFmode: |
| 3098 |
case E_V2SImode: |
| 3099 |
case E_V2SFmode: |
| 3100 |
case E_V1TImode: |
| 3101 |
case E_V1DImode: |
| 3102 |
if (!type || !AGGREGATE_TYPE_P (type)) |
| 3103 |
{ |
| 3104 |
cum->mmx_words += words; |
| 3105 |
cum->mmx_nregs -= 1; |
| 3106 |
cum->mmx_regno += 1; |
| 3107 |
if (cum->mmx_nregs <= 0) |
| 3108 |
{ |
| 3109 |
cum->mmx_nregs = 0; |
| 3110 |
cum->mmx_regno = 0; |
| 3111 |
} |
| 3112 |
} |
| 3113 |
break; |
| 3114 |
} |
| 3115 |
if (error_p) |
| 3116 |
{ |
| 3117 |
cum->float_in_sse = 0; |
| 3118 |
error ("calling %qD with SSE calling convention without " |
| 3119 |
"SSE/SSE2 enabled", cum->decl); |
| 3120 |
sorry ("this is a GCC bug that can be worked around by adding " |
| 3121 |
"attribute used to function called"); |
| 3122 |
} |
| 3123 |
|
| 3124 |
return res; |
| 3125 |
} |
| 3126 |
|
| 3127 |
static int |
| 3128 |
function_arg_advance_64 (CUMULATIVE_ARGS *cum, machine_mode mode, |
| 3129 |
const_tree type, HOST_WIDE_INT words, bool named) |
| 3130 |
{ |
| 3131 |
int int_nregs, sse_nregs; |
| 3132 |
|
| 3133 |
/* Unnamed 512 and 256bit vector mode parameters are passed on stack. */ |
| 3134 |
if (!named && (VALID_AVX512F_REG_MODE (mode) |
| 3135 |
|| VALID_AVX256_REG_MODE (mode))) |
| 3136 |
return 0; |
| 3137 |
|
| 3138 |
if (!examine_argument (mode, type, 0, &int_nregs, &sse_nregs) |
| 3139 |
&& sse_nregs <= cum->sse_nregs && int_nregs <= cum->nregs) |
| 3140 |
{ |
| 3141 |
cum->nregs -= int_nregs; |
| 3142 |
cum->sse_nregs -= sse_nregs; |
| 3143 |
cum->regno += int_nregs; |
| 3144 |
cum->sse_regno += sse_nregs; |
| 3145 |
return int_nregs; |
| 3146 |
} |
| 3147 |
else |
| 3148 |
{ |
| 3149 |
int align = ix86_function_arg_boundary (mode, type) / BITS_PER_WORD; |
| 3150 |
cum->words = ROUND_UP (cum->words, align); |
| 3151 |
cum->words += words; |
| 3152 |
return 0; |
| 3153 |
} |
| 3154 |
} |
| 3155 |
|
| 3156 |
static int |
| 3157 |
function_arg_advance_ms_64 (CUMULATIVE_ARGS *cum, HOST_WIDE_INT bytes, |
| 3158 |
HOST_WIDE_INT words) |
| 3159 |
{ |
| 3160 |
/* Otherwise, this should be passed indirect. */ |
| 3161 |
gcc_assert (bytes == 1 || bytes == 2 || bytes == 4 || bytes == 8); |
| 3162 |
|
| 3163 |
cum->words += words; |
| 3164 |
if (cum->nregs > 0) |
| 3165 |
{ |
| 3166 |
cum->nregs -= 1; |
| 3167 |
cum->regno += 1; |
| 3168 |
return 1; |
| 3169 |
} |
| 3170 |
return 0; |
| 3171 |
} |
| 3172 |
|
| 3173 |
/* Update the data in CUM to advance over argument ARG. */ |
| 3174 |
|
| 3175 |
static void |
| 3176 |
ix86_function_arg_advance (cumulative_args_t cum_v, |
| 3177 |
const function_arg_info &arg) |
| 3178 |
{ |
| 3179 |
CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v); |
| 3180 |
machine_mode mode = arg.mode; |
| 3181 |
HOST_WIDE_INT bytes, words; |
| 3182 |
int nregs; |
| 3183 |
|
| 3184 |
/* The argument of interrupt handler is a special case and is |
| 3185 |
handled in ix86_function_arg. */ |
| 3186 |
if (!cum->caller && cfun->machine->func_type != TYPE_NORMAL) |
| 3187 |
return; |
| 3188 |
|
| 3189 |
bytes = arg.promoted_size_in_bytes (); |
| 3190 |
words = CEIL (bytes, UNITS_PER_WORD); |
| 3191 |
|
| 3192 |
if (arg.type) |
| 3193 |
mode = type_natural_mode (arg.type, NULL, false); |
| 3194 |
|
| 3195 |
if (TARGET_64BIT) |
| 3196 |
{ |
| 3197 |
enum calling_abi call_abi = cum ? cum->call_abi : ix86_abi; |
| 3198 |
|
| 3199 |
if (call_abi == MS_ABI) |
| 3200 |
nregs = function_arg_advance_ms_64 (cum, bytes, words); |
| 3201 |
else |
| 3202 |
nregs = function_arg_advance_64 (cum, mode, arg.type, words, |
| 3203 |
arg.named); |
| 3204 |
} |
| 3205 |
else |
| 3206 |
nregs = function_arg_advance_32 (cum, mode, arg.type, bytes, words); |
| 3207 |
|
| 3208 |
if (!nregs) |
| 3209 |
{ |
| 3210 |
/* Track if there are outgoing arguments on stack. */ |
| 3211 |
if (cum->caller) |
| 3212 |
cfun->machine->outgoing_args_on_stack = true; |
| 3213 |
} |
| 3214 |
} |
| 3215 |
|
| 3216 |
/* Define where to put the arguments to a function. |
| 3217 |
Value is zero to push the argument on the stack, |
| 3218 |
or a hard register in which to store the argument. |
| 3219 |
|
| 3220 |
MODE is the argument's machine mode. |
| 3221 |
TYPE is the data type of the argument (as a tree). |
| 3222 |
This is null for libcalls where that information may |
| 3223 |
not be available. |
| 3224 |
CUM is a variable of type CUMULATIVE_ARGS which gives info about |
| 3225 |
the preceding args and about the function being called. |
| 3226 |
NAMED is nonzero if this argument is a named parameter |
| 3227 |
(otherwise it is an extra parameter matching an ellipsis). */ |
| 3228 |
|
| 3229 |
static rtx |
| 3230 |
function_arg_32 (CUMULATIVE_ARGS *cum, machine_mode mode, |
| 3231 |
machine_mode orig_mode, const_tree type, |
| 3232 |
HOST_WIDE_INT bytes, HOST_WIDE_INT words) |
| 3233 |
{ |
| 3234 |
bool error_p = false; |
| 3235 |
|
| 3236 |
/* Avoid the AL settings for the Unix64 ABI. */ |
| 3237 |
if (mode == VOIDmode) |
| 3238 |
return constm1_rtx; |
| 3239 |
|
| 3240 |
if (TARGET_IAMCU) |
| 3241 |
{ |
| 3242 |
/* Intel MCU psABI passes scalars and aggregates no larger than 8 |
| 3243 |
bytes in registers. */ |
| 3244 |
if (!VECTOR_MODE_P (mode) && bytes <= 8) |
| 3245 |
goto pass_in_reg; |
| 3246 |
return NULL_RTX; |
| 3247 |
} |
| 3248 |
|
| 3249 |
switch (mode) |
| 3250 |
{ |
| 3251 |
default: |
| 3252 |
break; |
| 3253 |
|
| 3254 |
case E_BLKmode: |
| 3255 |
if (bytes < 0) |
| 3256 |
break; |
| 3257 |
/* FALLTHRU */ |
| 3258 |
case E_DImode: |
| 3259 |
case E_SImode: |
| 3260 |
case E_HImode: |
| 3261 |
case E_QImode: |
| 3262 |
pass_in_reg: |
| 3263 |
if (words <= cum->nregs) |
| 3264 |
{ |
| 3265 |
int regno = cum->regno; |
| 3266 |
|
| 3267 |
/* Fastcall allocates the first two DWORD (SImode) or |
| 3268 |
smaller arguments to ECX and EDX if it isn't an |
| 3269 |
aggregate type . */ |
| 3270 |
if (cum->fastcall) |
| 3271 |
{ |
| 3272 |
if (mode == BLKmode |
| 3273 |
|| mode == DImode |
| 3274 |
|| (type && AGGREGATE_TYPE_P (type))) |
| 3275 |
break; |
| 3276 |
|
| 3277 |
/* ECX not EAX is the first allocated register. */ |
| 3278 |
if (regno == AX_REG) |
| 3279 |
regno = CX_REG; |
| 3280 |
} |
| 3281 |
return gen_rtx_REG (mode, regno); |
| 3282 |
} |
| 3283 |
break; |
| 3284 |
|
| 3285 |
case E_DFmode: |
| 3286 |
if (cum->float_in_sse == -1) |
| 3287 |
error_p = true; |
| 3288 |
if (cum->float_in_sse < 2) |
| 3289 |
break; |
| 3290 |
/* FALLTHRU */ |
| 3291 |
case E_SFmode: |
| 3292 |
if (cum->float_in_sse == -1) |
| 3293 |
error_p = true; |
| 3294 |
if (cum->float_in_sse < 1) |
| 3295 |
break; |
| 3296 |
/* FALLTHRU */ |
| 3297 |
case E_TImode: |
| 3298 |
/* In 32bit, we pass TImode in xmm registers. */ |
| 3299 |
case E_V16QImode: |
| 3300 |
case E_V8HImode: |
| 3301 |
case E_V4SImode: |
| 3302 |
case E_V2DImode: |
| 3303 |
case E_V8HFmode: |
| 3304 |
case E_V8BFmode: |
| 3305 |
case E_V4SFmode: |
| 3306 |
case E_V2DFmode: |
| 3307 |
if (!type || !AGGREGATE_TYPE_P (type)) |
| 3308 |
{ |
| 3309 |
if (cum->sse_nregs) |
| 3310 |
return gen_reg_or_parallel (mode, orig_mode, |
| 3311 |
cum->sse_regno + FIRST_SSE_REG); |
| 3312 |
} |
| 3313 |
break; |
| 3314 |
|
| 3315 |
case E_OImode: |
| 3316 |
case E_XImode: |
| 3317 |
/* OImode and XImode shouldn't be used directly. */ |
| 3318 |
gcc_unreachable (); |
| 3319 |
|
| 3320 |
case E_V64QImode: |
| 3321 |
case E_V32HImode: |
| 3322 |
case E_V16SImode: |
| 3323 |
case E_V8DImode: |
| 3324 |
case E_V32HFmode: |
| 3325 |
case E_V32BFmode: |
| 3326 |
case E_V16SFmode: |
| 3327 |
case E_V8DFmode: |
| 3328 |
case E_V16HFmode: |
| 3329 |
case E_V16BFmode: |
| 3330 |
case E_V8SFmode: |
| 3331 |
case E_V8SImode: |
| 3332 |
case E_V32QImode: |
| 3333 |
case E_V16HImode: |
| 3334 |
case E_V4DFmode: |
| 3335 |
case E_V4DImode: |
| 3336 |
if (!type || !AGGREGATE_TYPE_P (type)) |
| 3337 |
{ |
| 3338 |
if (cum->sse_nregs) |
| 3339 |
return gen_reg_or_parallel (mode, orig_mode, |
| 3340 |
cum->sse_regno + FIRST_SSE_REG); |
| 3341 |
} |
| 3342 |
break; |
| 3343 |
|
| 3344 |
case E_V8QImode: |
| 3345 |
case E_V4HImode: |
| 3346 |
case E_V4HFmode: |
| 3347 |
case E_V4BFmode: |
| 3348 |
case E_V2SImode: |
| 3349 |
case E_V2SFmode: |
| 3350 |
case E_V1TImode: |
| 3351 |
case E_V1DImode: |
| 3352 |
if (!type || !AGGREGATE_TYPE_P (type)) |
| 3353 |
{ |
| 3354 |
if (cum->mmx_nregs) |
| 3355 |
return gen_reg_or_parallel (mode, orig_mode, |
| 3356 |
cum->mmx_regno + FIRST_MMX_REG); |
| 3357 |
} |
| 3358 |
break; |
| 3359 |
} |
| 3360 |
if (error_p) |
| 3361 |
{ |
| 3362 |
cum->float_in_sse = 0; |
| 3363 |
error ("calling %qD with SSE calling convention without " |
| 3364 |
"SSE/SSE2 enabled", cum->decl); |
| 3365 |
sorry ("this is a GCC bug that can be worked around by adding " |
| 3366 |
"attribute used to function called"); |
| 3367 |
} |
| 3368 |
|
| 3369 |
return NULL_RTX; |
| 3370 |
} |
| 3371 |
|
| 3372 |
static rtx |
| 3373 |
function_arg_64 (const CUMULATIVE_ARGS *cum, machine_mode mode, |
| 3374 |
machine_mode orig_mode, const_tree type, bool named) |
| 3375 |
{ |
| 3376 |
/* Handle a hidden AL argument containing number of registers |
| 3377 |
for varargs x86-64 functions. */ |
| 3378 |
if (mode == VOIDmode) |
| 3379 |
return GEN_INT (cum->maybe_vaarg |
| 3380 |
? (cum->sse_nregs < 0 |
| 3381 |
? X86_64_SSE_REGPARM_MAX |
| 3382 |
: cum->sse_regno) |
| 3383 |
: -1); |
| 3384 |
|
| 3385 |
switch (mode) |
| 3386 |
{ |
| 3387 |
default: |
| 3388 |
break; |
| 3389 |
|
| 3390 |
case E_V16HFmode: |
| 3391 |
case E_V16BFmode: |
| 3392 |
case E_V8SFmode: |
| 3393 |
case E_V8SImode: |
| 3394 |
case E_V32QImode: |
| 3395 |
case E_V16HImode: |
| 3396 |
case E_V4DFmode: |
| 3397 |
case E_V4DImode: |
| 3398 |
case E_V32HFmode: |
| 3399 |
case E_V32BFmode: |
| 3400 |
case E_V16SFmode: |
| 3401 |
case E_V16SImode: |
| 3402 |
case E_V64QImode: |
| 3403 |
case E_V32HImode: |
| 3404 |
case E_V8DFmode: |
| 3405 |
case E_V8DImode: |
| 3406 |
/* Unnamed 256 and 512bit vector mode parameters are passed on stack. */ |
| 3407 |
if (!named) |
| 3408 |
return NULL; |
| 3409 |
break; |
| 3410 |
} |
| 3411 |
|
| 3412 |
return construct_container (mode, orig_mode, type, 0, cum->nregs, |
| 3413 |
cum->sse_nregs, |
| 3414 |
&x86_64_int_parameter_registers [cum->regno], |
| 3415 |
cum->sse_regno); |
| 3416 |
} |
| 3417 |
|
| 3418 |
static rtx |
| 3419 |
function_arg_ms_64 (const CUMULATIVE_ARGS *cum, machine_mode mode, |
| 3420 |
machine_mode orig_mode, bool named, const_tree type, |
| 3421 |
HOST_WIDE_INT bytes) |
| 3422 |
{ |
| 3423 |
unsigned int regno; |
| 3424 |
|
| 3425 |
/* We need to add clobber for MS_ABI->SYSV ABI calls in expand_call. |
| 3426 |
We use value of -2 to specify that current function call is MSABI. */ |
| 3427 |
if (mode == VOIDmode) |
| 3428 |
return GEN_INT (-2); |
| 3429 |
|
| 3430 |
/* If we've run out of registers, it goes on the stack. */ |
| 3431 |
if (cum->nregs == 0) |
| 3432 |
return NULL_RTX; |
| 3433 |
|
| 3434 |
regno = x86_64_ms_abi_int_parameter_registers[cum->regno]; |
| 3435 |
|
| 3436 |
/* Only floating point modes are passed in anything but integer regs. */ |
| 3437 |
if (TARGET_SSE && (mode == SFmode || mode == DFmode)) |
| 3438 |
{ |
| 3439 |
if (named) |
| 3440 |
{ |
| 3441 |
if (type == NULL_TREE || !AGGREGATE_TYPE_P (type)) |
| 3442 |
regno = cum->regno + FIRST_SSE_REG; |
| 3443 |
} |
| 3444 |
else |
| 3445 |
{ |
| 3446 |
rtx t1, t2; |
| 3447 |
|
| 3448 |
/* Unnamed floating parameters are passed in both the |
| 3449 |
SSE and integer registers. */ |
| 3450 |
t1 = gen_rtx_REG (mode, cum->regno + FIRST_SSE_REG); |
| 3451 |
t2 = gen_rtx_REG (mode, regno); |
| 3452 |
t1 = gen_rtx_EXPR_LIST (VOIDmode, t1, const0_rtx); |
| 3453 |
t2 = gen_rtx_EXPR_LIST (VOIDmode, t2, const0_rtx); |
| 3454 |
return gen_rtx_PARALLEL (mode, gen_rtvec (2, t1, t2)); |
| 3455 |
} |
| 3456 |
} |
| 3457 |
/* Handle aggregated types passed in register. */ |
| 3458 |
if (orig_mode == BLKmode) |
| 3459 |
{ |
| 3460 |
if (bytes > 0 && bytes <= 8) |
| 3461 |
mode = (bytes > 4 ? DImode : SImode); |
| 3462 |
if (mode == BLKmode) |
| 3463 |
mode = DImode; |
| 3464 |
} |
| 3465 |
|
| 3466 |
return gen_reg_or_parallel (mode, orig_mode, regno); |
| 3467 |
} |
| 3468 |
|
| 3469 |
/* Return where to put the arguments to a function. |
| 3470 |
Return zero to push the argument on the stack, or a hard register in which to store the argument. |
| 3471 |
|
| 3472 |
ARG describes the argument while CUM gives information about the |
| 3473 |
preceding args and about the function being called. */ |
| 3474 |
|
| 3475 |
static rtx |
| 3476 |
ix86_function_arg (cumulative_args_t cum_v, const function_arg_info &arg) |
| 3477 |
{ |
| 3478 |
CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v); |
| 3479 |
machine_mode mode = arg.mode; |
| 3480 |
HOST_WIDE_INT bytes, words; |
| 3481 |
rtx reg; |
| 3482 |
|
| 3483 |
if (!cum->caller && cfun->machine->func_type != TYPE_NORMAL) |
| 3484 |
{ |
| 3485 |
gcc_assert (arg.type != NULL_TREE); |
| 3486 |
if (POINTER_TYPE_P (arg.type)) |
| 3487 |
{ |
| 3488 |
/* This is the pointer argument. */ |
| 3489 |
gcc_assert (TYPE_MODE (arg.type) == ptr_mode); |
| 3490 |
/* It is at -WORD(AP) in the current frame in interrupt and |
| 3491 |
exception handlers. */ |
| 3492 |
reg = plus_constant (Pmode, arg_pointer_rtx, -UNITS_PER_WORD); |
| 3493 |
} |
| 3494 |
else |
| 3495 |
{ |
| 3496 |
gcc_assert (cfun->machine->func_type == TYPE_EXCEPTION |
| 3497 |
&& TREE_CODE (arg.type) == INTEGER_TYPE |
| 3498 |
&& TYPE_MODE (arg.type) == word_mode); |
| 3499 |
/* The error code is the word-mode integer argument at |
| 3500 |
-2 * WORD(AP) in the current frame of the exception |
| 3501 |
handler. */ |
| 3502 |
reg = gen_rtx_MEM (word_mode, |
| 3503 |
plus_constant (Pmode, |
| 3504 |
arg_pointer_rtx, |
| 3505 |
-2 * UNITS_PER_WORD)); |
| 3506 |
} |
| 3507 |
return reg; |
| 3508 |
} |
| 3509 |
|
| 3510 |
bytes = arg.promoted_size_in_bytes (); |
| 3511 |
words = CEIL (bytes, UNITS_PER_WORD); |
| 3512 |
|
| 3513 |
/* To simplify the code below, represent vector types with a vector mode |
| 3514 |
even if MMX/SSE are not active. */ |
| 3515 |
if (arg.type && VECTOR_TYPE_P (arg.type)) |
| 3516 |
mode = type_natural_mode (arg.type, cum, false); |
| 3517 |
|
| 3518 |
if (TARGET_64BIT) |
| 3519 |
{ |
| 3520 |
enum calling_abi call_abi = cum ? cum->call_abi : ix86_abi; |
| 3521 |
|
| 3522 |
if (call_abi == MS_ABI) |
| 3523 |
reg = function_arg_ms_64 (cum, mode, arg.mode, arg.named, |
| 3524 |
arg.type, bytes); |
| 3525 |
else |
| 3526 |
reg = function_arg_64 (cum, mode, arg.mode, arg.type, arg.named); |
| 3527 |
} |
| 3528 |
else |
| 3529 |
reg = function_arg_32 (cum, mode, arg.mode, arg.type, bytes, words); |
| 3530 |
|
| 3531 |
/* Track if there are outgoing arguments on stack. */ |
| 3532 |
if (reg == NULL_RTX && cum->caller) |
| 3533 |
cfun->machine->outgoing_args_on_stack = true; |
| 3534 |
|
| 3535 |
return reg; |
| 3536 |
} |
| 3537 |
|
| 3538 |
/* A C expression that indicates when an argument must be passed by |
| 3539 |
reference. If nonzero for an argument, a copy of that argument is |
| 3540 |
made in memory and a pointer to the argument is passed instead of |
| 3541 |
the argument itself. The pointer is passed in whatever way is |
| 3542 |
appropriate for passing a pointer to that type. */ |
| 3543 |
|
| 3544 |
static bool |
| 3545 |
ix86_pass_by_reference (cumulative_args_t cum_v, const function_arg_info &arg) |
| 3546 |
{ |
| 3547 |
CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v); |
| 3548 |
|
| 3549 |
if (TARGET_64BIT) |
| 3550 |
{ |
| 3551 |
enum calling_abi call_abi = cum ? cum->call_abi : ix86_abi; |
| 3552 |
|
| 3553 |
/* See Windows x64 Software Convention. */ |
| 3554 |
if (call_abi == MS_ABI) |
| 3555 |
{ |
| 3556 |
HOST_WIDE_INT msize = GET_MODE_SIZE (arg.mode); |
| 3557 |
|
| 3558 |
if (tree type = arg.type) |
| 3559 |
{ |
| 3560 |
/* Arrays are passed by reference. */ |
| 3561 |
if (TREE_CODE (type) == ARRAY_TYPE) |
| 3562 |
return true; |
| 3563 |
|
| 3564 |
if (RECORD_OR_UNION_TYPE_P (type)) |
| 3565 |
{ |
| 3566 |
/* Structs/unions of sizes other than 8, 16, 32, or 64 bits |
| 3567 |
are passed by reference. */ |
| 3568 |
msize = int_size_in_bytes (type); |
| 3569 |
} |
| 3570 |
} |
| 3571 |
|
| 3572 |
/* __m128 is passed by reference. */ |
| 3573 |
return msize != 1 && msize != 2 && msize != 4 && msize != 8; |
| 3574 |
} |
| 3575 |
else if (arg.type && int_size_in_bytes (arg.type) == -1) |
| 3576 |
return true; |
| 3577 |
} |
| 3578 |
|
| 3579 |
return false; |
| 3580 |
} |
| 3581 |
|
| 3582 |
/* Return true when TYPE should be 128bit aligned for 32bit argument |
| 3583 |
passing ABI. XXX: This function is obsolete and is only used for |
| 3584 |
checking psABI compatibility with previous versions of GCC. */ |
| 3585 |
|
| 3586 |
static bool |
| 3587 |
ix86_compat_aligned_value_p (const_tree type) |
| 3588 |
{ |
| 3589 |
machine_mode mode = TYPE_MODE (type); |
| 3590 |
if (((TARGET_SSE && SSE_REG_MODE_P (mode)) |
| 3591 |
|| mode == TDmode |
| 3592 |
|| mode == TFmode |
| 3593 |
|| mode == TCmode) |
| 3594 |
&& (!TYPE_USER_ALIGN (type) || TYPE_ALIGN (type) > 128)) |
| 3595 |
return true; |
| 3596 |
if (TYPE_ALIGN (type) < 128) |
| 3597 |
return false; |
| 3598 |
|
| 3599 |
if (AGGREGATE_TYPE_P (type)) |
| 3600 |
{ |
| 3601 |
/* Walk the aggregates recursively. */ |
| 3602 |
switch (TREE_CODE (type)) |
| 3603 |
{ |
| 3604 |
case RECORD_TYPE: |
| 3605 |
case UNION_TYPE: |
| 3606 |
case QUAL_UNION_TYPE: |
| 3607 |
{ |
| 3608 |
tree field; |
| 3609 |
|
| 3610 |
/* Walk all the structure fields. */ |
| 3611 |
for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) |
| 3612 |
{ |
| 3613 |
if (TREE_CODE (field) == FIELD_DECL |
| 3614 |
&& ix86_compat_aligned_value_p (TREE_TYPE (field))) |
| 3615 |
return true; |
| 3616 |
} |
| 3617 |
break; |
| 3618 |
} |
| 3619 |
|
| 3620 |
case ARRAY_TYPE: |
| 3621 |
/* Just for use if some languages passes arrays by value. */ |
| 3622 |
if (ix86_compat_aligned_value_p (TREE_TYPE (type))) |
| 3623 |
return true; |
| 3624 |
break; |
| 3625 |
|
| 3626 |
default: |
| 3627 |
gcc_unreachable (); |
| 3628 |
} |
| 3629 |
} |
| 3630 |
return false; |
| 3631 |
} |
| 3632 |
|
| 3633 |
/* Return the alignment boundary for MODE and TYPE with alignment ALIGN. |
| 3634 |
XXX: This function is obsolete and is only used for checking psABI |
| 3635 |
compatibility with previous versions of GCC. */ |
| 3636 |
|
| 3637 |
static unsigned int |
| 3638 |
ix86_compat_function_arg_boundary (machine_mode mode, |
| 3639 |
const_tree type, unsigned int align) |
| 3640 |
{ |
| 3641 |
/* In 32bit, only _Decimal128 and __float128 are aligned to their |
| 3642 |
natural boundaries. */ |
| 3643 |
if (!TARGET_64BIT && mode != TDmode && mode != TFmode) |
| 3644 |
{ |
| 3645 |
/* i386 ABI defines all arguments to be 4 byte aligned. We have to |
| 3646 |
make an exception for SSE modes since these require 128bit |
| 3647 |
alignment. |
| 3648 |
|
| 3649 |
The handling here differs from field_alignment. ICC aligns MMX |
| 3650 |
arguments to 4 byte boundaries, while structure fields are aligned |
| 3651 |
to 8 byte boundaries. */ |
| 3652 |
if (!type) |
| 3653 |
{ |
| 3654 |
if (!(TARGET_SSE && SSE_REG_MODE_P (mode))) |
| 3655 |
align = PARM_BOUNDARY; |
| 3656 |
} |
| 3657 |
else |
| 3658 |
{ |
| 3659 |
if (!ix86_compat_aligned_value_p (type)) |
| 3660 |
align = PARM_BOUNDARY; |
| 3661 |
} |
| 3662 |
} |
| 3663 |
if (align > BIGGEST_ALIGNMENT) |
| 3664 |
align = BIGGEST_ALIGNMENT; |
| 3665 |
return align; |
| 3666 |
} |
| 3667 |
|
| 3668 |
/* Return true when TYPE should be 128bit aligned for 32bit argument |
| 3669 |
passing ABI. */ |
| 3670 |
|
| 3671 |
static bool |
| 3672 |
ix86_contains_aligned_value_p (const_tree type) |
| 3673 |
{ |
| 3674 |
machine_mode mode = TYPE_MODE (type); |
| 3675 |
|
| 3676 |
if (mode == XFmode || mode == XCmode) |
| 3677 |
return false; |
| 3678 |
|
| 3679 |
if (TYPE_ALIGN (type) < 128) |
| 3680 |
return false; |
| 3681 |
|
| 3682 |
if (AGGREGATE_TYPE_P (type)) |
| 3683 |
{ |
| 3684 |
/* Walk the aggregates recursively. */ |
| 3685 |
switch (TREE_CODE (type)) |
| 3686 |
{ |
| 3687 |
case RECORD_TYPE: |
| 3688 |
case UNION_TYPE: |
| 3689 |
case QUAL_UNION_TYPE: |
| 3690 |
{ |
| 3691 |
tree field; |
| 3692 |
|
| 3693 |
/* Walk all the structure fields. */ |
| 3694 |
for (field = TYPE_FIELDS (type); |
| 3695 |
field; |
| 3696 |
field = DECL_CHAIN (field)) |
| 3697 |
{ |
| 3698 |
if (TREE_CODE (field) == FIELD_DECL |
| 3699 |
&& ix86_contains_aligned_value_p (TREE_TYPE (field))) |
| 3700 |
return true; |
| 3701 |
} |
| 3702 |
break; |
| 3703 |
} |
| 3704 |
|
| 3705 |
case ARRAY_TYPE: |
| 3706 |
/* Just for use if some languages passes arrays by value. */ |
| 3707 |
if (ix86_contains_aligned_value_p (TREE_TYPE (type))) |
| 3708 |
return true; |
| 3709 |
break; |
| 3710 |
|
| 3711 |
default: |
| 3712 |
gcc_unreachable (); |
| 3713 |
} |
| 3714 |
} |
| 3715 |
else |
| 3716 |
return TYPE_ALIGN (type) >= 128; |
| 3717 |
|
| 3718 |
return false; |
| 3719 |
} |
| 3720 |
|
| 3721 |
/* Gives the alignment boundary, in bits, of an argument with the |
| 3722 |
specified mode and type. */ |
| 3723 |
|
| 3724 |
static unsigned int |
| 3725 |
ix86_function_arg_boundary (machine_mode mode, const_tree type) |
| 3726 |
{ |
| 3727 |
unsigned int align; |
| 3728 |
if (type) |
| 3729 |
{ |
| 3730 |
/* Since the main variant type is used for call, we convert it to |
| 3731 |
the main variant type. */ |
| 3732 |
type = TYPE_MAIN_VARIANT (type); |
| 3733 |
align = TYPE_ALIGN (type); |
| 3734 |
if (TYPE_EMPTY_P (type)) |
| 3735 |
return PARM_BOUNDARY; |
| 3736 |
} |
| 3737 |
else |
| 3738 |
align = GET_MODE_ALIGNMENT (mode); |
| 3739 |
if (align < PARM_BOUNDARY) |
| 3740 |
align = PARM_BOUNDARY; |
| 3741 |
else |
| 3742 |
{ |
| 3743 |
static bool warned; |
| 3744 |
unsigned int saved_align = align; |
| 3745 |
|
| 3746 |
if (!TARGET_64BIT) |
| 3747 |
{ |
| 3748 |
/* i386 ABI defines XFmode arguments to be 4 byte aligned. */ |
| 3749 |
if (!type) |
| 3750 |
{ |
| 3751 |
if (mode == XFmode || mode == XCmode) |
| 3752 |
align = PARM_BOUNDARY; |
| 3753 |
} |
| 3754 |
else if (!ix86_contains_aligned_value_p (type)) |
| 3755 |
align = PARM_BOUNDARY; |
| 3756 |
|
| 3757 |
if (align < 128) |
| 3758 |
align = PARM_BOUNDARY; |
| 3759 |
} |
| 3760 |
|
| 3761 |
if (warn_psabi |
| 3762 |
&& !warned |
| 3763 |
&& align != ix86_compat_function_arg_boundary (mode, type, |
| 3764 |
saved_align)) |
| 3765 |
{ |
| 3766 |
warned = true; |
| 3767 |
inform (input_location, |
| 3768 |
"the ABI for passing parameters with %d-byte" |
| 3769 |
" alignment has changed in GCC 4.6", |
| 3770 |
align / BITS_PER_UNIT); |
| 3771 |
} |
| 3772 |
} |
| 3773 |
|
| 3774 |
return align; |
| 3775 |
} |
| 3776 |
|
| 3777 |
/* Return true if N is a possible register number of function value. */ |
| 3778 |
|
| 3779 |
static bool |
| 3780 |
ix86_function_value_regno_p (const unsigned int regno) |
| 3781 |
{ |
| 3782 |
switch (regno) |
| 3783 |
{ |
| 3784 |
case AX_REG: |
| 3785 |
return true; |
| 3786 |
case DX_REG: |
| 3787 |
return (!TARGET_64BIT || ix86_cfun_abi () != MS_ABI); |
| 3788 |
case DI_REG: |
| 3789 |
case SI_REG: |
| 3790 |
return TARGET_64BIT && ix86_cfun_abi () != MS_ABI; |
| 3791 |
|
| 3792 |
/* Complex values are returned in %st(0)/%st(1) pair. */ |
| 3793 |
case ST0_REG: |
| 3794 |
case ST1_REG: |
| 3795 |
/* TODO: The function should depend on current function ABI but |
| 3796 |
builtins.cc would need updating then. Therefore we use the |
| 3797 |
default ABI. */ |
| 3798 |
if (TARGET_64BIT && ix86_cfun_abi () == MS_ABI) |
| 3799 |
return false; |
| 3800 |
return TARGET_FLOAT_RETURNS_IN_80387; |
| 3801 |
|
| 3802 |
/* Complex values are returned in %xmm0/%xmm1 pair. */ |
| 3803 |
case XMM0_REG: |
| 3804 |
case XMM1_REG: |
| 3805 |
return TARGET_SSE; |
| 3806 |
|
| 3807 |
case MM0_REG: |
| 3808 |
if (TARGET_MACHO || TARGET_64BIT) |
| 3809 |
return false; |
| 3810 |
return TARGET_MMX; |
| 3811 |
} |
| 3812 |
|
| 3813 |
return false; |
| 3814 |
} |
| 3815 |
|
| 3816 |
/* Check whether the register REGNO should be zeroed on X86. |
| 3817 |
When ALL_SSE_ZEROED is true, all SSE registers have been zeroed |
| 3818 |
together, no need to zero it again. |
| 3819 |
When NEED_ZERO_MMX is true, MMX registers should be cleared. */ |
| 3820 |
|
| 3821 |
static bool |
| 3822 |
zero_call_used_regno_p (const unsigned int regno, |
| 3823 |
bool all_sse_zeroed, |
| 3824 |
bool need_zero_mmx) |
| 3825 |
{ |
| 3826 |
return GENERAL_REGNO_P (regno) |
| 3827 |
|| (!all_sse_zeroed && SSE_REGNO_P (regno)) |
| 3828 |
|| MASK_REGNO_P (regno) |
| 3829 |
|| (need_zero_mmx && MMX_REGNO_P (regno)); |
| 3830 |
} |
| 3831 |
|
| 3832 |
/* Return the machine_mode that is used to zero register REGNO. */ |
| 3833 |
|
| 3834 |
static machine_mode |
| 3835 |
zero_call_used_regno_mode (const unsigned int regno) |
| 3836 |
{ |
| 3837 |
/* NB: We only need to zero the lower 32 bits for integer registers |
| 3838 |
and the lower 128 bits for vector registers since destination are |
| 3839 |
zero-extended to the full register width. */ |
| 3840 |
if (GENERAL_REGNO_P (regno)) |
| 3841 |
return SImode; |
| 3842 |
else if (SSE_REGNO_P (regno)) |
| 3843 |
return V4SFmode; |
| 3844 |
else if (MASK_REGNO_P (regno)) |
| 3845 |
return HImode; |
| 3846 |
else if (MMX_REGNO_P (regno)) |
| 3847 |
return V2SImode; |
| 3848 |
else |
| 3849 |
gcc_unreachable (); |
| 3850 |
} |
| 3851 |
|
| 3852 |
/* Generate a rtx to zero all vector registers together if possible, |
| 3853 |
otherwise, return NULL. */ |
| 3854 |
|
| 3855 |
static rtx |
| 3856 |
zero_all_vector_registers (HARD_REG_SET need_zeroed_hardregs) |
| 3857 |
{ |
| 3858 |
if (!TARGET_AVX) |
| 3859 |
return NULL; |
| 3860 |
|
| 3861 |
for (unsigned int regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) |
| 3862 |
if ((LEGACY_SSE_REGNO_P (regno) |
| 3863 |
|| (TARGET_64BIT |
| 3864 |
&& (REX_SSE_REGNO_P (regno) |
| 3865 |
|| (TARGET_AVX512F && EXT_REX_SSE_REGNO_P (regno))))) |
| 3866 |
&& !TEST_HARD_REG_BIT (need_zeroed_hardregs, regno)) |
| 3867 |
return NULL; |
| 3868 |
|
| 3869 |
return gen_avx_vzeroall (); |
| 3870 |
} |
| 3871 |
|
| 3872 |
/* Generate insns to zero all st registers together. |
| 3873 |
Return true when zeroing instructions are generated. |
| 3874 |
Assume the number of st registers that are zeroed is num_of_st, |
| 3875 |
we will emit the following sequence to zero them together: |
| 3876 |
fldz; \ |
| 3877 |
fldz; \ |
| 3878 |
... |
| 3879 |
fldz; \ |
| 3880 |
fstp %%st(0); \ |
| 3881 |
fstp %%st(0); \ |
| 3882 |
... |
| 3883 |
fstp %%st(0); |
| 3884 |
i.e., num_of_st fldz followed by num_of_st fstp to clear the stack |
| 3885 |
mark stack slots empty. |
| 3886 |
|
| 3887 |
How to compute the num_of_st: |
| 3888 |
There is no direct mapping from stack registers to hard register |
| 3889 |
numbers. If one stack register needs to be cleared, we don't know |
| 3890 |
where in the stack the value remains. So, if any stack register |
| 3891 |
needs to be cleared, the whole stack should be cleared. However, |
| 3892 |
x87 stack registers that hold the return value should be excluded. |
| 3893 |
x87 returns in the top (two for complex values) register, so |
| 3894 |
num_of_st should be 7/6 when x87 returns, otherwise it will be 8. |
| 3895 |
return the value of num_of_st. */ |
| 3896 |
|
| 3897 |
|
| 3898 |
static int |
| 3899 |
zero_all_st_registers (HARD_REG_SET need_zeroed_hardregs) |
| 3900 |
{ |
| 3901 |
|
| 3902 |
/* If the FPU is disabled, no need to zero all st registers. */ |
| 3903 |
if (! (TARGET_80387 || TARGET_FLOAT_RETURNS_IN_80387)) |
| 3904 |
return 0; |
| 3905 |
|
| 3906 |
unsigned int num_of_st = 0; |
| 3907 |
for (unsigned int regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) |
| 3908 |
if ((STACK_REGNO_P (regno) || MMX_REGNO_P (regno)) |
| 3909 |
&& TEST_HARD_REG_BIT (need_zeroed_hardregs, regno)) |
| 3910 |
{ |
| 3911 |
num_of_st++; |
| 3912 |
break; |
| 3913 |
} |
| 3914 |
|
| 3915 |
if (num_of_st == 0) |
| 3916 |
return 0; |
| 3917 |
|
| 3918 |
bool return_with_x87 = false; |
| 3919 |
return_with_x87 = (crtl->return_rtx |
| 3920 |
&& (STACK_REG_P (crtl->return_rtx))); |
| 3921 |
|
| 3922 |
bool complex_return = false; |
| 3923 |
complex_return = (crtl->return_rtx |
| 3924 |
&& COMPLEX_MODE_P (GET_MODE (crtl->return_rtx))); |
| 3925 |
|
| 3926 |
if (return_with_x87) |
| 3927 |
if (complex_return) |
| 3928 |
num_of_st = 6; |
| 3929 |
else |
| 3930 |
num_of_st = 7; |
| 3931 |
else |
| 3932 |
num_of_st = 8; |
| 3933 |
|
| 3934 |
rtx st_reg = gen_rtx_REG (XFmode, FIRST_STACK_REG); |
| 3935 |
for (unsigned int i = 0; i < num_of_st; i++) |
| 3936 |
emit_insn (gen_rtx_SET (st_reg, CONST0_RTX (XFmode))); |
| 3937 |
|
| 3938 |
for (unsigned int i = 0; i < num_of_st; i++) |
| 3939 |
{ |
| 3940 |
rtx insn; |
| 3941 |
insn = emit_insn (gen_rtx_SET (st_reg, st_reg)); |
| 3942 |
add_reg_note (insn, REG_DEAD, st_reg); |
| 3943 |
} |
| 3944 |
return num_of_st; |
| 3945 |
} |
| 3946 |
|
| 3947 |
|
| 3948 |
/* When the routine exit in MMX mode, if any ST register needs |
| 3949 |
to be zeroed, we should clear all MMX registers except the |
| 3950 |
RET_MMX_REGNO that holds the return value. */ |
| 3951 |
static bool |
| 3952 |
zero_all_mm_registers (HARD_REG_SET need_zeroed_hardregs, |
| 3953 |
unsigned int ret_mmx_regno) |
| 3954 |
{ |
| 3955 |
bool need_zero_all_mm = false; |
| 3956 |
for (unsigned int regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) |
| 3957 |
if (STACK_REGNO_P (regno) |
| 3958 |
&& TEST_HARD_REG_BIT (need_zeroed_hardregs, regno)) |
| 3959 |
{ |
| 3960 |
need_zero_all_mm = true; |
| 3961 |
break; |
| 3962 |
} |
| 3963 |
|
| 3964 |
if (!need_zero_all_mm) |
| 3965 |
return false; |
| 3966 |
|
| 3967 |
machine_mode mode = V2SImode; |
| 3968 |
for (unsigned int regno = FIRST_MMX_REG; regno <= LAST_MMX_REG; regno++) |
| 3969 |
if (regno != ret_mmx_regno) |
| 3970 |
{ |
| 3971 |
rtx reg = gen_rtx_REG (mode, regno); |
| 3972 |
emit_insn (gen_rtx_SET (reg, CONST0_RTX (mode))); |
| 3973 |
} |
| 3974 |
return true; |
| 3975 |
} |
| 3976 |
|
| 3977 |
/* TARGET_ZERO_CALL_USED_REGS. */ |
| 3978 |
/* Generate a sequence of instructions that zero registers specified by |
| 3979 |
NEED_ZEROED_HARDREGS. Return the ZEROED_HARDREGS that are actually |
| 3980 |
zeroed. */ |
| 3981 |
static HARD_REG_SET |
| 3982 |
ix86_zero_call_used_regs (HARD_REG_SET need_zeroed_hardregs) |
| 3983 |
{ |
| 3984 |
HARD_REG_SET zeroed_hardregs; |
| 3985 |
bool all_sse_zeroed = false; |
| 3986 |
int all_st_zeroed_num = 0; |
| 3987 |
bool all_mm_zeroed = false; |
| 3988 |
|
| 3989 |
CLEAR_HARD_REG_SET (zeroed_hardregs); |
| 3990 |
|
| 3991 |
/* first, let's see whether we can zero all vector registers together. */ |
| 3992 |
rtx zero_all_vec_insn = zero_all_vector_registers (need_zeroed_hardregs); |
| 3993 |
if (zero_all_vec_insn) |
| 3994 |
{ |
| 3995 |
emit_insn (zero_all_vec_insn); |
| 3996 |
all_sse_zeroed = true; |
| 3997 |
if (TARGET_64BIT && TARGET_AVX512F) |
| 3998 |
{ |
| 3999 |
rtx zero = CONST0_RTX (V4SFmode); |
| 4000 |
for (unsigned int regno = XMM16_REG; |
| 4001 |
regno <= XMM31_REG; |
| 4002 |
regno++) |
| 4003 |
{ |
| 4004 |
rtx reg = gen_rtx_REG (V4SFmode, regno); |
| 4005 |
emit_move_insn (reg, zero); |
| 4006 |
} |
| 4007 |
} |
| 4008 |
} |
| 4009 |
|
| 4010 |
/* mm/st registers are shared registers set, we should follow the following |
| 4011 |
rules to clear them: |
| 4012 |
MMX exit mode x87 exit mode |
| 4013 |
-------------|----------------------|--------------- |
| 4014 |
uses x87 reg | clear all MMX | clear all x87 |
| 4015 |
uses MMX reg | clear individual MMX | clear all x87 |
| 4016 |
x87 + MMX | clear all MMX | clear all x87 |
| 4017 |
|
| 4018 |
first, we should decide which mode (MMX mode or x87 mode) the function |
| 4019 |
exit with. */ |
| 4020 |
|
| 4021 |
bool exit_with_mmx_mode = (crtl->return_rtx |
| 4022 |
&& (MMX_REG_P (crtl->return_rtx))); |
| 4023 |
|
| 4024 |
if (!exit_with_mmx_mode) |
| 4025 |
/* x87 exit mode, we should zero all st registers together. */ |
| 4026 |
{ |
| 4027 |
all_st_zeroed_num = zero_all_st_registers (need_zeroed_hardregs); |
| 4028 |
|
| 4029 |
if (all_st_zeroed_num > 0) |
| 4030 |
for (unsigned int regno = FIRST_STACK_REG; regno <= LAST_STACK_REG; regno++) |
| 4031 |
/* x87 stack registers that hold the return value should be excluded. |
| 4032 |
x87 returns in the top (two for complex values) register. */ |
| 4033 |
if (all_st_zeroed_num == 8 |
| 4034 |
|| !((all_st_zeroed_num >= 6 && regno == REGNO (crtl->return_rtx)) |
| 4035 |
|| (all_st_zeroed_num == 6 |
| 4036 |
&& (regno == (REGNO (crtl->return_rtx) + 1))))) |
| 4037 |
SET_HARD_REG_BIT (zeroed_hardregs, regno); |
| 4038 |
} |
| 4039 |
else |
| 4040 |
/* MMX exit mode, check whether we can zero all mm registers. */ |
| 4041 |
{ |
| 4042 |
unsigned int exit_mmx_regno = REGNO (crtl->return_rtx); |
| 4043 |
all_mm_zeroed = zero_all_mm_registers (need_zeroed_hardregs, |
| 4044 |
exit_mmx_regno); |
| 4045 |
if (all_mm_zeroed) |
| 4046 |
for (unsigned int regno = FIRST_MMX_REG; regno <= LAST_MMX_REG; regno++) |
| 4047 |
if (regno != exit_mmx_regno) |
| 4048 |
SET_HARD_REG_BIT (zeroed_hardregs, regno); |
| 4049 |
} |
| 4050 |
|
| 4051 |
/* Now, generate instructions to zero all the other registers. */ |
| 4052 |
|
| 4053 |
for (unsigned int regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) |
| 4054 |
{ |
| 4055 |
if (!TEST_HARD_REG_BIT (need_zeroed_hardregs, regno)) |
| 4056 |
continue; |
| 4057 |
if (!zero_call_used_regno_p (regno, all_sse_zeroed, |
| 4058 |
exit_with_mmx_mode && !all_mm_zeroed)) |
| 4059 |
continue; |
| 4060 |
|
| 4061 |
SET_HARD_REG_BIT (zeroed_hardregs, regno); |
| 4062 |
|
| 4063 |
machine_mode mode = zero_call_used_regno_mode (regno); |
| 4064 |
|
| 4065 |
rtx reg = gen_rtx_REG (mode, regno); |
| 4066 |
rtx tmp = gen_rtx_SET (reg, CONST0_RTX (mode)); |
| 4067 |
|
| 4068 |
switch (mode) |
| 4069 |
{ |
| 4070 |
case E_SImode: |
| 4071 |
if (!TARGET_USE_MOV0 || optimize_insn_for_size_p ()) |
| 4072 |
{ |
| 4073 |
rtx clob = gen_rtx_CLOBBER (VOIDmode, |
| 4074 |
gen_rtx_REG (CCmode, |
| 4075 |
FLAGS_REG)); |
| 4076 |
tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, |
| 4077 |
tmp, |
| 4078 |
clob)); |
| 4079 |
} |
| 4080 |
/* FALLTHRU. */ |
| 4081 |
|
| 4082 |
case E_V4SFmode: |
| 4083 |
case E_HImode: |
| 4084 |
case E_V2SImode: |
| 4085 |
emit_insn (tmp); |
| 4086 |
break; |
| 4087 |
|
| 4088 |
default: |
| 4089 |
gcc_unreachable (); |
| 4090 |
} |
| 4091 |
} |
| 4092 |
return zeroed_hardregs; |
| 4093 |
} |
| 4094 |
|
| 4095 |
/* Define how to find the value returned by a function. |
| 4096 |
VALTYPE is the data type of the value (as a tree). |
| 4097 |
If the precise function being called is known, FUNC is its FUNCTION_DECL; |
| 4098 |
otherwise, FUNC is 0. */ |
| 4099 |
|
| 4100 |
static rtx |
| 4101 |
function_value_32 (machine_mode orig_mode, machine_mode mode, |
| 4102 |
const_tree fntype, const_tree fn) |
| 4103 |
{ |
| 4104 |
unsigned int regno; |
| 4105 |
|
| 4106 |
/* 8-byte vector modes in %mm0. See ix86_return_in_memory for where |
| 4107 |
we normally prevent this case when mmx is not available. However |
| 4108 |
some ABIs may require the result to be returned like DImode. */ |
| 4109 |
if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 8) |
| 4110 |
regno = FIRST_MMX_REG; |
| 4111 |
|
| 4112 |
/* 16-byte vector modes in %xmm0. See ix86_return_in_memory for where |
| 4113 |
we prevent this case when sse is not available. However some ABIs |
| 4114 |
may require the result to be returned like integer TImode. */ |
| 4115 |
else if (mode == TImode |
| 4116 |
|| (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 16)) |
| 4117 |
regno = FIRST_SSE_REG; |
| 4118 |
|
| 4119 |
/* 32-byte vector modes in %ymm0. */ |
| 4120 |
else if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 32) |
| 4121 |
regno = FIRST_SSE_REG; |
| 4122 |
|
| 4123 |
/* 64-byte vector modes in %zmm0. */ |
| 4124 |
else if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 64) |
| 4125 |
regno = FIRST_SSE_REG; |
| 4126 |
|
| 4127 |
/* Floating point return values in %st(0) (unless -mno-fp-ret-in-387). */ |
| 4128 |
else if (X87_FLOAT_MODE_P (mode) && TARGET_FLOAT_RETURNS_IN_80387) |
| 4129 |
regno = FIRST_FLOAT_REG; |
| 4130 |
else |
| 4131 |
/* Most things go in %eax. */ |
| 4132 |
regno = AX_REG; |
| 4133 |
|
| 4134 |
/* Return __bf16/ _Float16/_Complex _Foat16 by sse register. */ |
| 4135 |
if (mode == HFmode || mode == BFmode) |
| 4136 |
{ |
| 4137 |
if (!TARGET_SSE2) |
| 4138 |
{ |
| 4139 |
error ("SSE register return with SSE2 disabled"); |
| 4140 |
regno = AX_REG; |
| 4141 |
} |
| 4142 |
else |
| 4143 |
regno = FIRST_SSE_REG; |
| 4144 |
} |
| 4145 |
|
| 4146 |
if (mode == HCmode) |
| 4147 |
{ |
| 4148 |
if (!TARGET_SSE2) |
| 4149 |
error ("SSE register return with SSE2 disabled"); |
| 4150 |
|
| 4151 |
rtx ret = gen_rtx_PARALLEL (mode, rtvec_alloc(1)); |
| 4152 |
XVECEXP (ret, 0, 0) |
| 4153 |
= gen_rtx_EXPR_LIST (VOIDmode, |
| 4154 |
gen_rtx_REG (SImode, |
| 4155 |
TARGET_SSE2 ? FIRST_SSE_REG : AX_REG), |
| 4156 |
GEN_INT (0)); |
| 4157 |
return ret; |
| 4158 |
} |
| 4159 |
|
| 4160 |
/* Override FP return register with %xmm0 for local functions when |
| 4161 |
SSE math is enabled or for functions with sseregparm attribute. */ |
| 4162 |
if ((fn || fntype) && (mode == SFmode || mode == DFmode)) |
| 4163 |
{ |
| 4164 |
int sse_level = ix86_function_sseregparm (fntype, fn, false); |
| 4165 |
if (sse_level == -1) |
| 4166 |
{ |
| 4167 |
error ("calling %qD with SSE calling convention without " |
| 4168 |
"SSE/SSE2 enabled", fn); |
| 4169 |
sorry ("this is a GCC bug that can be worked around by adding " |
| 4170 |
"attribute used to function called"); |
| 4171 |
} |
| 4172 |
else if ((sse_level >= 1 && mode == SFmode) |
| 4173 |
|| (sse_level == 2 && mode == DFmode)) |
| 4174 |
regno = FIRST_SSE_REG; |
| 4175 |
} |
| 4176 |
|
| 4177 |
/* OImode shouldn't be used directly. */ |
| 4178 |
gcc_assert (mode != OImode); |
| 4179 |
|
| 4180 |
return gen_rtx_REG (orig_mode, regno); |
| 4181 |
} |
| 4182 |
|
| 4183 |
static rtx |
| 4184 |
function_value_64 (machine_mode orig_mode, machine_mode mode, |
| 4185 |
const_tree valtype) |
| 4186 |
{ |
| 4187 |
rtx ret; |
| 4188 |
|
| 4189 |
/* Handle libcalls, which don't provide a type node. */ |
| 4190 |
if (valtype == NULL) |
| 4191 |
{ |
| 4192 |
unsigned int regno; |
| 4193 |
|
| 4194 |
switch (mode) |
| 4195 |
{ |
| 4196 |
case E_BFmode: |
| 4197 |
case E_HFmode: |
| 4198 |
case E_HCmode: |
| 4199 |
case E_SFmode: |
| 4200 |
case E_SCmode: |
| 4201 |
case E_DFmode: |
| 4202 |
case E_DCmode: |
| 4203 |
case E_TFmode: |
| 4204 |
case E_SDmode: |
| 4205 |
case E_DDmode: |
| 4206 |
case E_TDmode: |
| 4207 |
regno = FIRST_SSE_REG; |
| 4208 |
break; |
| 4209 |
case E_XFmode: |
| 4210 |
case E_XCmode: |
| 4211 |
regno = FIRST_FLOAT_REG; |
| 4212 |
break; |
| 4213 |
case E_TCmode: |
| 4214 |
return NULL; |
| 4215 |
default: |
| 4216 |
regno = AX_REG; |
| 4217 |
} |
| 4218 |
|
| 4219 |
return gen_rtx_REG (mode, regno); |
| 4220 |
} |
| 4221 |
else if (POINTER_TYPE_P (valtype)) |
| 4222 |
{ |
| 4223 |
/* Pointers are always returned in word_mode. */ |
| 4224 |
mode = word_mode; |
| 4225 |
} |
| 4226 |
|
| 4227 |
ret = construct_container (mode, orig_mode, valtype, 1, |
| 4228 |
X86_64_REGPARM_MAX, X86_64_SSE_REGPARM_MAX, |
| 4229 |
x86_64_int_return_registers, 0); |
| 4230 |
|
| 4231 |
/* For zero sized structures, construct_container returns NULL, but we |
| 4232 |
need to keep rest of compiler happy by returning meaningful value. */ |
| 4233 |
if (!ret) |
| 4234 |
ret = gen_rtx_REG (orig_mode, AX_REG); |
| 4235 |
|
| 4236 |
return ret; |
| 4237 |
} |
| 4238 |
|
| 4239 |
static rtx |
| 4240 |
function_value_ms_32 (machine_mode orig_mode, machine_mode mode, |
| 4241 |
const_tree fntype, const_tree fn, const_tree valtype) |
| 4242 |
{ |
| 4243 |
unsigned int regno; |
| 4244 |
|
| 4245 |
/* Floating point return values in %st(0) |
| 4246 |
(unless -mno-fp-ret-in-387 or aggregate type of up to 8 bytes). */ |
| 4247 |
if (X87_FLOAT_MODE_P (mode) && TARGET_FLOAT_RETURNS_IN_80387 |
| 4248 |
&& (GET_MODE_SIZE (mode) > 8 |
| 4249 |
|| valtype == NULL_TREE || !AGGREGATE_TYPE_P (valtype))) |
| 4250 |
{ |
| 4251 |
regno = FIRST_FLOAT_REG; |
| 4252 |
return gen_rtx_REG (orig_mode, regno); |
| 4253 |
} |
| 4254 |
else |
| 4255 |
return function_value_32(orig_mode, mode, fntype,fn); |
| 4256 |
} |
| 4257 |
|
| 4258 |
static rtx |
| 4259 |
function_value_ms_64 (machine_mode orig_mode, machine_mode mode, |
| 4260 |
const_tree valtype) |
| 4261 |
{ |
| 4262 |
unsigned int regno = AX_REG; |
| 4263 |
|
| 4264 |
if (TARGET_SSE) |
| 4265 |
{ |
| 4266 |
switch (GET_MODE_SIZE (mode)) |
| 4267 |
{ |
| 4268 |
case 16: |
| 4269 |
if (valtype != NULL_TREE |
| 4270 |
&& !VECTOR_INTEGER_TYPE_P (valtype) |
| 4271 |
&& !VECTOR_INTEGER_TYPE_P (valtype) |
| 4272 |
&& !INTEGRAL_TYPE_P (valtype) |
| 4273 |
&& !VECTOR_FLOAT_TYPE_P (valtype)) |
| 4274 |
break; |
| 4275 |
if ((SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode)) |
| 4276 |
&& !COMPLEX_MODE_P (mode)) |
| 4277 |
regno = FIRST_SSE_REG; |
| 4278 |
break; |
| 4279 |
case 8: |
| 4280 |
case 4: |
| 4281 |
if (valtype != NULL_TREE && AGGREGATE_TYPE_P (valtype)) |
| 4282 |
break; |
| 4283 |
if (mode == SFmode || mode == DFmode) |
| 4284 |
regno = FIRST_SSE_REG; |
| 4285 |
break; |
| 4286 |
default: |
| 4287 |
break; |
| 4288 |
} |
| 4289 |
} |
| 4290 |
return gen_rtx_REG (orig_mode, regno); |
| 4291 |
} |
| 4292 |
|
| 4293 |
static rtx |
| 4294 |
ix86_function_value_1 (const_tree valtype, const_tree fntype_or_decl, |
| 4295 |
machine_mode orig_mode, machine_mode mode) |
| 4296 |
{ |
| 4297 |
const_tree fn, fntype; |
| 4298 |
|
| 4299 |
fn = NULL_TREE; |
| 4300 |
if (fntype_or_decl && DECL_P (fntype_or_decl)) |
| 4301 |
fn = fntype_or_decl; |
| 4302 |
fntype = fn ? TREE_TYPE (fn) : fntype_or_decl; |
| 4303 |
|
| 4304 |
if (ix86_function_type_abi (fntype) == MS_ABI) |
| 4305 |
{ |
| 4306 |
if (TARGET_64BIT) |
| 4307 |
return function_value_ms_64 (orig_mode, mode, valtype); |
| 4308 |
else |
| 4309 |
return function_value_ms_32 (orig_mode, mode, fntype, fn, valtype); |
| 4310 |
} |
| 4311 |
else if (TARGET_64BIT) |
| 4312 |
return function_value_64 (orig_mode, mode, valtype); |
| 4313 |
else |
| 4314 |
return function_value_32 (orig_mode, mode, fntype, fn); |
| 4315 |
} |
| 4316 |
|
| 4317 |
static rtx |
| 4318 |
ix86_function_value (const_tree valtype, const_tree fntype_or_decl, bool) |
| 4319 |
{ |
| 4320 |
machine_mode mode, orig_mode; |
| 4321 |
|
| 4322 |
orig_mode = TYPE_MODE (valtype); |
| 4323 |
mode = type_natural_mode (valtype, NULL, true); |
| 4324 |
return ix86_function_value_1 (valtype, fntype_or_decl, orig_mode, mode); |
| 4325 |
} |
| 4326 |
|
| 4327 |
/* Pointer function arguments and return values are promoted to |
| 4328 |
word_mode for normal functions. */ |
| 4329 |
|
| 4330 |
static machine_mode |
| 4331 |
ix86_promote_function_mode (const_tree type, machine_mode mode, |
| 4332 |
int *punsignedp, const_tree fntype, |
| 4333 |
int for_return) |
| 4334 |
{ |
| 4335 |
if (cfun->machine->func_type == TYPE_NORMAL |
| 4336 |
&& type != NULL_TREE |
| 4337 |
&& POINTER_TYPE_P (type)) |
| 4338 |
{ |
| 4339 |
*punsignedp = POINTERS_EXTEND_UNSIGNED; |
| 4340 |
return word_mode; |
| 4341 |
} |
| 4342 |
return default_promote_function_mode (type, mode, punsignedp, fntype, |
| 4343 |
for_return); |
| 4344 |
} |
| 4345 |
|
| 4346 |
/* Return true if a structure, union or array with MODE containing FIELD |
| 4347 |
should be accessed using BLKmode. */ |
| 4348 |
|
| 4349 |
static bool |
| 4350 |
ix86_member_type_forces_blk (const_tree field, machine_mode mode) |
| 4351 |
{ |
| 4352 |
/* Union with XFmode must be in BLKmode. */ |
| 4353 |
return (mode == XFmode |
| 4354 |
&& (TREE_CODE (DECL_FIELD_CONTEXT (field)) == UNION_TYPE |
| 4355 |
|| TREE_CODE (DECL_FIELD_CONTEXT (field)) == QUAL_UNION_TYPE)); |
| 4356 |
} |
| 4357 |
|
| 4358 |
rtx |
| 4359 |
ix86_libcall_value (machine_mode mode) |
| 4360 |
{ |
| 4361 |
return ix86_function_value_1 (NULL, NULL, mode, mode); |
| 4362 |
} |
| 4363 |
|
| 4364 |
/* Return true iff type is returned in memory. */ |
| 4365 |
|
| 4366 |
static bool |
| 4367 |
ix86_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED) |
| 4368 |
{ |
| 4369 |
const machine_mode mode = type_natural_mode (type, NULL, true); |
| 4370 |
HOST_WIDE_INT size; |
| 4371 |
|
| 4372 |
if (TARGET_64BIT) |
| 4373 |
{ |
| 4374 |
if (ix86_function_type_abi (fntype) == MS_ABI) |
| 4375 |
{ |
| 4376 |
size = int_size_in_bytes (type); |
| 4377 |
|
| 4378 |
/* __m128 is returned in xmm0. */ |
| 4379 |
if ((!type || VECTOR_INTEGER_TYPE_P (type) |
| 4380 |
|| INTEGRAL_TYPE_P (type) |
| 4381 |
|| VECTOR_FLOAT_TYPE_P (type)) |
| 4382 |
&& (SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode)) |
| 4383 |
&& !COMPLEX_MODE_P (mode) |
| 4384 |
&& (GET_MODE_SIZE (mode) == 16 || size == 16)) |
| 4385 |
return false; |
| 4386 |
|
| 4387 |
/* Otherwise, the size must be exactly in [1248]. */ |
| 4388 |
return size != 1 && size != 2 && size != 4 && size != 8; |
| 4389 |
} |
| 4390 |
else |
| 4391 |
{ |
| 4392 |
int needed_intregs, needed_sseregs; |
| 4393 |
|
| 4394 |
return examine_argument (mode, type, 1, |
| 4395 |
&needed_intregs, &needed_sseregs); |
| 4396 |
} |
| 4397 |
} |
| 4398 |
else |
| 4399 |
{ |
| 4400 |
size = int_size_in_bytes (type); |
| 4401 |
|
| 4402 |
/* Intel MCU psABI returns scalars and aggregates no larger than 8 |
| 4403 |
bytes in registers. */ |
| 4404 |
if (TARGET_IAMCU) |
| 4405 |
return VECTOR_MODE_P (mode) || size < 0 || size > 8; |
| 4406 |
|
| 4407 |
if (mode == BLKmode) |
| 4408 |
return true; |
| 4409 |
|
| 4410 |
if (MS_AGGREGATE_RETURN && AGGREGATE_TYPE_P (type) && size <= 8) |
| 4411 |
return false; |
| 4412 |
|
| 4413 |
if (VECTOR_MODE_P (mode) || mode == TImode) |
| 4414 |
{ |
| 4415 |
/* User-created vectors small enough to fit in EAX. */ |
| 4416 |
if (size < 8) |
| 4417 |
return false; |
| 4418 |
|
| 4419 |
/* Unless ABI prescibes otherwise, |
| 4420 |
MMX/3dNow values are returned in MM0 if available. */ |
| 4421 |
|
| 4422 |
if (size == 8) |
| 4423 |
return TARGET_VECT8_RETURNS || !TARGET_MMX; |
| 4424 |
|
| 4425 |
/* SSE values are returned in XMM0 if available. */ |
| 4426 |
if (size == 16) |
| 4427 |
return !TARGET_SSE; |
| 4428 |
|
| 4429 |
/* AVX values are returned in YMM0 if available. */ |
| 4430 |
if (size == 32) |
| 4431 |
return !TARGET_AVX; |
| 4432 |
|
| 4433 |
/* AVX512F values are returned in ZMM0 if available. */ |
| 4434 |
if (size == 64) |
| 4435 |
return !TARGET_AVX512F || !TARGET_EVEX512; |
| 4436 |
} |
| 4437 |
|
| 4438 |
if (mode == XFmode) |
| 4439 |
return false; |
| 4440 |
|
| 4441 |
if (size > 12) |
| 4442 |
return true; |
| 4443 |
|
| 4444 |
/* OImode shouldn't be used directly. */ |
| 4445 |
gcc_assert (mode != OImode); |
| 4446 |
|
| 4447 |
return false; |
| 4448 |
} |
| 4449 |
} |
| 4450 |
|
| 4451 |
/* Implement TARGET_PUSH_ARGUMENT. */ |
| 4452 |
|
| 4453 |
static bool |
| 4454 |
ix86_push_argument (unsigned int npush) |
| 4455 |
{ |
| 4456 |
/* If SSE2 is available, use vector move to put large argument onto |
| 4457 |
stack. NB: In 32-bit mode, use 8-byte vector move. */ |
| 4458 |
return ((!TARGET_SSE2 || npush < (TARGET_64BIT ? 16 : 8)) |
| 4459 |
&& TARGET_PUSH_ARGS |
| 4460 |
&& !ACCUMULATE_OUTGOING_ARGS); |
| 4461 |
} |
| 4462 |
|
| 4463 |
|
| 4464 |
/* Create the va_list data type. */ |
| 4465 |
|
| 4466 |
static tree |
| 4467 |
ix86_build_builtin_va_list_64 (void) |
| 4468 |
{ |
| 4469 |
tree f_gpr, f_fpr, f_ovf, f_sav, record, type_decl; |
| 4470 |
|
| 4471 |
record = lang_hooks.types.make_type (RECORD_TYPE); |
| 4472 |
type_decl = build_decl (BUILTINS_LOCATION, |
| 4473 |
TYPE_DECL, get_identifier ("__va_list_tag"), record); |
| 4474 |
|
| 4475 |
f_gpr = build_decl (BUILTINS_LOCATION, |
| 4476 |
FIELD_DECL, get_identifier ("gp_offset"), |
| 4477 |
unsigned_type_node); |
| 4478 |
f_fpr = build_decl (BUILTINS_LOCATION, |
| 4479 |
FIELD_DECL, get_identifier ("fp_offset"), |
| 4480 |
unsigned_type_node); |
| 4481 |
f_ovf = build_decl (BUILTINS_LOCATION, |
| 4482 |
FIELD_DECL, get_identifier ("overflow_arg_area"), |
| 4483 |
ptr_type_node); |
| 4484 |
f_sav = build_decl (BUILTINS_LOCATION, |
| 4485 |
FIELD_DECL, get_identifier ("reg_save_area"), |
| 4486 |
ptr_type_node); |
| 4487 |
|
| 4488 |
va_list_gpr_counter_field = f_gpr; |
| 4489 |
va_list_fpr_counter_field = f_fpr; |
| 4490 |
|
| 4491 |
DECL_FIELD_CONTEXT (f_gpr) = record; |
| 4492 |
DECL_FIELD_CONTEXT (f_fpr) = record; |
| 4493 |
DECL_FIELD_CONTEXT (f_ovf) = record; |
| 4494 |
DECL_FIELD_CONTEXT (f_sav) = record; |
| 4495 |
|
| 4496 |
TYPE_STUB_DECL (record) = type_decl; |
| 4497 |
TYPE_NAME (record) = type_decl; |
| 4498 |
TYPE_FIELDS (record) = f_gpr; |
| 4499 |
DECL_CHAIN (f_gpr) = f_fpr; |
| 4500 |
DECL_CHAIN (f_fpr) = f_ovf; |
| 4501 |
DECL_CHAIN (f_ovf) = f_sav; |
| 4502 |
|
| 4503 |
layout_type (record); |
| 4504 |
|
| 4505 |
TYPE_ATTRIBUTES (record) = tree_cons (get_identifier ("sysv_abi va_list"), |
| 4506 |
NULL_TREE, TYPE_ATTRIBUTES (record)); |
| 4507 |
|
| 4508 |
/* The correct type is an array type of one element. */ |
| 4509 |
return build_array_type (record, build_index_type (size_zero_node)); |
| 4510 |
} |
| 4511 |
|
| 4512 |
/* Setup the builtin va_list data type and for 64-bit the additional |
| 4513 |
calling convention specific va_list data types. */ |
| 4514 |
|
| 4515 |
static tree |
| 4516 |
ix86_build_builtin_va_list (void) |
| 4517 |
{ |
| 4518 |
if (TARGET_64BIT) |
| 4519 |
{ |
| 4520 |
/* Initialize ABI specific va_list builtin types. |
| 4521 |
|
| 4522 |
In lto1, we can encounter two va_list types: |
| 4523 |
- one as a result of the type-merge across TUs, and |
| 4524 |
- the one constructed here. |
| 4525 |
These two types will not have the same TYPE_MAIN_VARIANT, and therefore |
| 4526 |
a type identity check in canonical_va_list_type based on |
| 4527 |
TYPE_MAIN_VARIANT (which we used to have) will not work. |
| 4528 |
Instead, we tag each va_list_type_node with its unique attribute, and |
| 4529 |
look for the attribute in the type identity check in |
| 4530 |
canonical_va_list_type. |
| 4531 |
|
| 4532 |
Tagging sysv_va_list_type_node directly with the attribute is |
| 4533 |
problematic since it's a array of one record, which will degrade into a |
| 4534 |
pointer to record when used as parameter (see build_va_arg comments for |
| 4535 |
an example), dropping the attribute in the process. So we tag the |
| 4536 |
record instead. */ |
| 4537 |
|
| 4538 |
/* For SYSV_ABI we use an array of one record. */ |
| 4539 |
sysv_va_list_type_node = ix86_build_builtin_va_list_64 (); |
| 4540 |
|
| 4541 |
/* For MS_ABI we use plain pointer to argument area. */ |
| 4542 |
tree char_ptr_type = build_pointer_type (char_type_node); |
| 4543 |
tree attr = tree_cons (get_identifier ("ms_abi va_list"), NULL_TREE, |
| 4544 |
TYPE_ATTRIBUTES (char_ptr_type)); |
| 4545 |
ms_va_list_type_node = build_type_attribute_variant (char_ptr_type, attr); |
| 4546 |
|
| 4547 |
return ((ix86_abi == MS_ABI) |
| 4548 |
? ms_va_list_type_node |
| 4549 |
: sysv_va_list_type_node); |
| 4550 |
} |
| 4551 |
else |
| 4552 |
{ |
| 4553 |
/* For i386 we use plain pointer to argument area. */ |
| 4554 |
return build_pointer_type (char_type_node); |
| 4555 |
} |
| 4556 |
} |
| 4557 |
|
| 4558 |
/* Worker function for TARGET_SETUP_INCOMING_VARARGS. */ |
| 4559 |
|
| 4560 |
static void |
| 4561 |
setup_incoming_varargs_64 (CUMULATIVE_ARGS *cum) |
| 4562 |
{ |
| 4563 |
rtx save_area, mem; |
| 4564 |
alias_set_type set; |
| 4565 |
int i, max; |
| 4566 |
|
| 4567 |
/* GPR size of varargs save area. */ |
| 4568 |
if (cfun->va_list_gpr_size) |
| 4569 |
ix86_varargs_gpr_size = X86_64_REGPARM_MAX * UNITS_PER_WORD; |
| 4570 |
else |
| 4571 |
ix86_varargs_gpr_size = 0; |
| 4572 |
|
| 4573 |
/* FPR size of varargs save area. We don't need it if we don't pass |
| 4574 |
anything in SSE registers. */ |
| 4575 |
if (TARGET_SSE && cfun->va_list_fpr_size) |
| 4576 |
ix86_varargs_fpr_size = X86_64_SSE_REGPARM_MAX * 16; |
| 4577 |
else |
| 4578 |
ix86_varargs_fpr_size = 0; |
| 4579 |
|
| 4580 |
if (! ix86_varargs_gpr_size && ! ix86_varargs_fpr_size) |
| 4581 |
return; |
| 4582 |
|
| 4583 |
save_area = frame_pointer_rtx; |
| 4584 |
set = get_varargs_alias_set (); |
| 4585 |
|
| 4586 |
max = cum->regno + cfun->va_list_gpr_size / UNITS_PER_WORD; |
| 4587 |
if (max > X86_64_REGPARM_MAX) |
| 4588 |
max = X86_64_REGPARM_MAX; |
| 4589 |
|
| 4590 |
for (i = cum->regno; i < max; i++) |
| 4591 |
{ |
| 4592 |
mem = gen_rtx_MEM (word_mode, |
| 4593 |
plus_constant (Pmode, save_area, i * UNITS_PER_WORD)); |
| 4594 |
MEM_NOTRAP_P (mem) = 1; |
| 4595 |
set_mem_alias_set (mem, set); |
| 4596 |
emit_move_insn (mem, |
| 4597 |
gen_rtx_REG (word_mode, |
| 4598 |
x86_64_int_parameter_registers[i])); |
| 4599 |
} |
| 4600 |
|
| 4601 |
if (ix86_varargs_fpr_size) |
| 4602 |
{ |
| 4603 |
machine_mode smode; |
| 4604 |
rtx_code_label *label; |
| 4605 |
rtx test; |
| 4606 |
|
| 4607 |
/* Now emit code to save SSE registers. The AX parameter contains number |
| 4608 |
of SSE parameter registers used to call this function, though all we |
| 4609 |
actually check here is the zero/non-zero status. */ |
| 4610 |
|
| 4611 |
label = gen_label_rtx (); |
| 4612 |
test = gen_rtx_EQ (VOIDmode, gen_rtx_REG (QImode, AX_REG), const0_rtx); |
| 4613 |
emit_jump_insn (gen_cbranchqi4 (test, XEXP (test, 0), XEXP (test, 1), |
| 4614 |
label)); |
| 4615 |
|
| 4616 |
/* ??? If !TARGET_SSE_TYPELESS_STORES, would we perform better if |
| 4617 |
we used movdqa (i.e. TImode) instead? Perhaps even better would |
| 4618 |
be if we could determine the real mode of the data, via a hook |
| 4619 |
into pass_stdarg. Ignore all that for now. */ |
| 4620 |
smode = V4SFmode; |
| 4621 |
if (crtl->stack_alignment_needed < GET_MODE_ALIGNMENT (smode)) |
| 4622 |
crtl->stack_alignment_needed = GET_MODE_ALIGNMENT (smode); |
| 4623 |
|
| 4624 |
max = cum->sse_regno + cfun->va_list_fpr_size / 16; |
| 4625 |
if (max > X86_64_SSE_REGPARM_MAX) |
| 4626 |
max = X86_64_SSE_REGPARM_MAX; |
| 4627 |
|
| 4628 |
for (i = cum->sse_regno; i < max; ++i) |
| 4629 |
{ |
| 4630 |
mem = plus_constant (Pmode, save_area, |
| 4631 |
i * 16 + ix86_varargs_gpr_size); |
| 4632 |
mem = gen_rtx_MEM (smode, mem); |
| 4633 |
MEM_NOTRAP_P (mem) = 1; |
| 4634 |
set_mem_alias_set (mem, set); |
| 4635 |
set_mem_align (mem, GET_MODE_ALIGNMENT (smode)); |
| 4636 |
|
| 4637 |
emit_move_insn (mem, gen_rtx_REG (smode, GET_SSE_REGNO (i))); |
| 4638 |
} |
| 4639 |
|
| 4640 |
emit_label (label); |
| 4641 |
} |
| 4642 |
} |
| 4643 |
|
| 4644 |
static void |
| 4645 |
setup_incoming_varargs_ms_64 (CUMULATIVE_ARGS *cum) |
| 4646 |
{ |
| 4647 |
alias_set_type set = get_varargs_alias_set (); |
| 4648 |
int i; |
| 4649 |
|
| 4650 |
/* Reset to zero, as there might be a sysv vaarg used |
| 4651 |
before. */ |
| 4652 |
ix86_varargs_gpr_size = 0; |
| 4653 |
ix86_varargs_fpr_size = 0; |
| 4654 |
|
| 4655 |
for (i = cum->regno; i < X86_64_MS_REGPARM_MAX; i++) |
| 4656 |
{ |
| 4657 |
rtx reg, mem; |
| 4658 |
|
| 4659 |
mem = gen_rtx_MEM (Pmode, |
| 4660 |
plus_constant (Pmode, virtual_incoming_args_rtx, |
| 4661 |
i * UNITS_PER_WORD)); |
| 4662 |
MEM_NOTRAP_P (mem) = 1; |
| 4663 |
set_mem_alias_set (mem, set); |
| 4664 |
|
| 4665 |
reg = gen_rtx_REG (Pmode, x86_64_ms_abi_int_parameter_registers[i]); |
| 4666 |
emit_move_insn (mem, reg); |
| 4667 |
} |
| 4668 |
} |
| 4669 |
|
| 4670 |
static void |
| 4671 |
ix86_setup_incoming_varargs (cumulative_args_t cum_v, |
| 4672 |
const function_arg_info &arg, |
| 4673 |
int *, int no_rtl) |
| 4674 |
{ |
| 4675 |
CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v); |
| 4676 |
CUMULATIVE_ARGS next_cum; |
| 4677 |
tree fntype; |
| 4678 |
|
| 4679 |
/* This argument doesn't appear to be used anymore. Which is good, |
| 4680 |
because the old code here didn't suppress rtl generation. */ |
| 4681 |
gcc_assert (!no_rtl); |
| 4682 |
|
| 4683 |
if (!TARGET_64BIT) |
| 4684 |
return; |
| 4685 |
|
| 4686 |
fntype = TREE_TYPE (current_function_decl); |
| 4687 |
|
| 4688 |
/* For varargs, we do not want to skip the dummy va_dcl argument. |
| 4689 |
For stdargs, we do want to skip the last named argument. */ |
| 4690 |
next_cum = *cum; |
| 4691 |
if ((!TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (current_function_decl)) |
| 4692 |
|| arg.type != NULL_TREE) |
| 4693 |
&& stdarg_p (fntype)) |
| 4694 |
ix86_function_arg_advance (pack_cumulative_args (&next_cum), arg); |
| 4695 |
|
| 4696 |
if (cum->call_abi == MS_ABI) |
| 4697 |
setup_incoming_varargs_ms_64 (&next_cum); |
| 4698 |
else |
| 4699 |
setup_incoming_varargs_64 (&next_cum); |
| 4700 |
} |
| 4701 |
|
| 4702 |
/* Checks if TYPE is of kind va_list char *. */ |
| 4703 |
|
| 4704 |
static bool |
| 4705 |
is_va_list_char_pointer (tree type) |
| 4706 |
{ |
| 4707 |
tree canonic; |
| 4708 |
|
| 4709 |
/* For 32-bit it is always true. */ |
| 4710 |
if (!TARGET_64BIT) |
| 4711 |
return true; |
| 4712 |
canonic = ix86_canonical_va_list_type (type); |
| 4713 |
return (canonic == ms_va_list_type_node |
| 4714 |
|| (ix86_abi == MS_ABI && canonic == va_list_type_node)); |
| 4715 |
} |
| 4716 |
|
| 4717 |
/* Implement va_start. */ |
| 4718 |
|
| 4719 |
static void |
| 4720 |
ix86_va_start (tree valist, rtx nextarg) |
| 4721 |
{ |
| 4722 |
HOST_WIDE_INT words, n_gpr, n_fpr; |
| 4723 |
tree f_gpr, f_fpr, f_ovf, f_sav; |
| 4724 |
tree gpr, fpr, ovf, sav, t; |
| 4725 |
tree type; |
| 4726 |
rtx ovf_rtx; |
| 4727 |
|
| 4728 |
if (flag_split_stack |
| 4729 |
&& cfun->machine->split_stack_varargs_pointer == NULL_RTX) |
| 4730 |
{ |
| 4731 |
unsigned int scratch_regno; |
| 4732 |
|
| 4733 |
/* When we are splitting the stack, we can't refer to the stack |
| 4734 |
arguments using internal_arg_pointer, because they may be on |
| 4735 |
the old stack. The split stack prologue will arrange to |
| 4736 |
leave a pointer to the old stack arguments in a scratch |
| 4737 |
register, which we here copy to a pseudo-register. The split |
| 4738 |
stack prologue can't set the pseudo-register directly because |
| 4739 |
it (the prologue) runs before any registers have been saved. */ |
| 4740 |
|
| 4741 |
scratch_regno = split_stack_prologue_scratch_regno (); |
| 4742 |
if (scratch_regno != INVALID_REGNUM) |
| 4743 |
{ |
| 4744 |
rtx reg; |
| 4745 |
rtx_insn *seq; |
| 4746 |
|
| 4747 |
reg = gen_reg_rtx (Pmode); |
| 4748 |
cfun->machine->split_stack_varargs_pointer = reg; |
| 4749 |
|
| 4750 |
start_sequence (); |
| 4751 |
emit_move_insn (reg, gen_rtx_REG (Pmode, scratch_regno)); |
| 4752 |
seq = get_insns (); |
| 4753 |
end_sequence (); |
| 4754 |
|
| 4755 |
push_topmost_sequence (); |
| 4756 |
emit_insn_after (seq, entry_of_function ()); |
| 4757 |
pop_topmost_sequence (); |
| 4758 |
} |
| 4759 |
} |
| 4760 |
|
| 4761 |
/* Only 64bit target needs something special. */ |
| 4762 |
if (is_va_list_char_pointer (TREE_TYPE (valist))) |
| 4763 |
{ |
| 4764 |
if (cfun->machine->split_stack_varargs_pointer == NULL_RTX) |
| 4765 |
std_expand_builtin_va_start (valist, nextarg); |
| 4766 |
else |
| 4767 |
{ |
| 4768 |
rtx va_r, next; |
| 4769 |
|
| 4770 |
va_r = expand_expr (valist, NULL_RTX, VOIDmode, EXPAND_WRITE); |
| 4771 |
next = expand_binop (ptr_mode, add_optab, |
| 4772 |
cfun->machine->split_stack_varargs_pointer, |
| 4773 |
crtl->args.arg_offset_rtx, |
| 4774 |
NULL_RTX, 0, OPTAB_LIB_WIDEN); |
| 4775 |
convert_move (va_r, next, 0); |
| 4776 |
} |
| 4777 |
return; |
| 4778 |
} |
| 4779 |
|
| 4780 |
f_gpr = TYPE_FIELDS (TREE_TYPE (sysv_va_list_type_node)); |
| 4781 |
f_fpr = DECL_CHAIN (f_gpr); |
| 4782 |
f_ovf = DECL_CHAIN (f_fpr); |
| 4783 |
f_sav = DECL_CHAIN (f_ovf); |
| 4784 |
|
| 4785 |
valist = build_simple_mem_ref (valist); |
| 4786 |
TREE_TYPE (valist) = TREE_TYPE (sysv_va_list_type_node); |
| 4787 |
/* The following should be folded into the MEM_REF offset. */ |
| 4788 |
gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr), unshare_expr (valist), |
| 4789 |
f_gpr, NULL_TREE); |
| 4790 |
fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), unshare_expr (valist), |
| 4791 |
f_fpr, NULL_TREE); |
| 4792 |
ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), unshare_expr (valist), |
| 4793 |
f_ovf, NULL_TREE); |
| 4794 |
sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), unshare_expr (valist), |
| 4795 |
f_sav, NULL_TREE); |
| 4796 |
|
| 4797 |
/* Count number of gp and fp argument registers used. */ |
| 4798 |
words = crtl->args.info.words; |
| 4799 |
n_gpr = crtl->args.info.regno; |
| 4800 |
n_fpr = crtl->args.info.sse_regno; |
| 4801 |
|
| 4802 |
if (cfun->va_list_gpr_size) |
| 4803 |
{ |
| 4804 |
type = TREE_TYPE (gpr); |
| 4805 |
t = build2 (MODIFY_EXPR, type, |
| 4806 |
gpr, build_int_cst (type, n_gpr * 8)); |
| 4807 |
TREE_SIDE_EFFECTS (t) = 1; |
| 4808 |
expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); |
| 4809 |
} |
| 4810 |
|
| 4811 |
if (TARGET_SSE && cfun->va_list_fpr_size) |
| 4812 |
{ |
| 4813 |
type = TREE_TYPE (fpr); |
| 4814 |
t = build2 (MODIFY_EXPR, type, fpr, |
| 4815 |
build_int_cst (type, n_fpr * 16 + 8*X86_64_REGPARM_MAX)); |
| 4816 |
TREE_SIDE_EFFECTS (t) = 1; |
| 4817 |
expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); |
| 4818 |
} |
| 4819 |
|
| 4820 |
/* Find the overflow area. */ |
| 4821 |
type = TREE_TYPE (ovf); |
| 4822 |
if (cfun->machine->split_stack_varargs_pointer == NULL_RTX) |
| 4823 |
ovf_rtx = crtl->args.internal_arg_pointer; |
| 4824 |
else |
| 4825 |
ovf_rtx = cfun->machine->split_stack_varargs_pointer; |
| 4826 |
t = make_tree (type, ovf_rtx); |
| 4827 |
if (words != 0) |
| 4828 |
t = fold_build_pointer_plus_hwi (t, words * UNITS_PER_WORD); |
| 4829 |
|
| 4830 |
t = build2 (MODIFY_EXPR, type, ovf, t); |
| 4831 |
TREE_SIDE_EFFECTS (t) = 1; |
| 4832 |
expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); |
| 4833 |
|
| 4834 |
if (ix86_varargs_gpr_size || ix86_varargs_fpr_size) |
| 4835 |
{ |
| 4836 |
/* Find the register save area. |
| 4837 |
Prologue of the function save it right above stack frame. */ |
| 4838 |
type = TREE_TYPE (sav); |
| 4839 |
t = make_tree (type, frame_pointer_rtx); |
| 4840 |
if (!ix86_varargs_gpr_size) |
| 4841 |
t = fold_build_pointer_plus_hwi (t, -8 * X86_64_REGPARM_MAX); |
| 4842 |
|
| 4843 |
t = build2 (MODIFY_EXPR, type, sav, t); |
| 4844 |
TREE_SIDE_EFFECTS (t) = 1; |
| 4845 |
expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); |
| 4846 |
} |
| 4847 |
} |
| 4848 |
|
| 4849 |
/* Implement va_arg. */ |
| 4850 |
|
| 4851 |
static tree |
| 4852 |
ix86_gimplify_va_arg (tree valist, tree type, gimple_seq *pre_p, |
| 4853 |
gimple_seq *post_p) |
| 4854 |
{ |
| 4855 |
static const int intreg[6] = { 0, 1, 2, 3, 4, 5 }; |
| 4856 |
tree f_gpr, f_fpr, f_ovf, f_sav; |
| 4857 |
tree gpr, fpr, ovf, sav, t; |
| 4858 |
int size, rsize; |
| 4859 |
tree lab_false, lab_over = NULL_TREE; |
| 4860 |
tree addr, t2; |
| 4861 |
rtx container; |
| 4862 |
int indirect_p = 0; |
| 4863 |
tree ptrtype; |
| 4864 |
machine_mode nat_mode; |
| 4865 |
unsigned int arg_boundary; |
| 4866 |
unsigned int type_align; |
| 4867 |
|
| 4868 |
/* Only 64bit target needs something special. */ |
| 4869 |
if (is_va_list_char_pointer (TREE_TYPE (valist))) |
| 4870 |
return std_gimplify_va_arg_expr (valist, type, pre_p, post_p); |
| 4871 |
|
| 4872 |
f_gpr = TYPE_FIELDS (TREE_TYPE (sysv_va_list_type_node)); |
| 4873 |
f_fpr = DECL_CHAIN (f_gpr); |
| 4874 |
f_ovf = DECL_CHAIN (f_fpr); |
| 4875 |
f_sav = DECL_CHAIN (f_ovf); |
| 4876 |
|
| 4877 |
gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr), |
| 4878 |
valist, f_gpr, NULL_TREE); |
| 4879 |
|
| 4880 |
fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE); |
| 4881 |
ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE); |
| 4882 |
sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE); |
| 4883 |
|
| 4884 |
indirect_p = pass_va_arg_by_reference (type); |
| 4885 |
if (indirect_p) |
| 4886 |
type = build_pointer_type (type); |
| 4887 |
size = arg_int_size_in_bytes (type); |
| 4888 |
rsize = CEIL (size, UNITS_PER_WORD); |
| 4889 |
|
| 4890 |
nat_mode = type_natural_mode (type, NULL, false); |
| 4891 |
switch (nat_mode) |
| 4892 |
{ |
| 4893 |
case E_V16HFmode: |
| 4894 |
case E_V16BFmode: |
| 4895 |
case E_V8SFmode: |
| 4896 |
case E_V8SImode: |
| 4897 |
case E_V32QImode: |
| 4898 |
case E_V16HImode: |
| 4899 |
case E_V4DFmode: |
| 4900 |
case E_V4DImode: |
| 4901 |
case E_V32HFmode: |
| 4902 |
case E_V32BFmode: |
| 4903 |
case E_V16SFmode: |
| 4904 |
case E_V16SImode: |
| 4905 |
case E_V64QImode: |
| 4906 |
case E_V32HImode: |
| 4907 |
case E_V8DFmode: |
| 4908 |
case E_V8DImode: |
| 4909 |
/* Unnamed 256 and 512bit vector mode parameters are passed on stack. */ |
| 4910 |
if (!TARGET_64BIT_MS_ABI) |
| 4911 |
{ |
| 4912 |
container = NULL; |
| 4913 |
break; |
| 4914 |
} |
| 4915 |
/* FALLTHRU */ |
| 4916 |
|
| 4917 |
default: |
| 4918 |
container = construct_container (nat_mode, TYPE_MODE (type), |
| 4919 |
type, 0, X86_64_REGPARM_MAX, |
| 4920 |
X86_64_SSE_REGPARM_MAX, intreg, |
| 4921 |
0); |
| 4922 |
break; |
| 4923 |
} |
| 4924 |
|
| 4925 |
/* Pull the value out of the saved registers. */ |
| 4926 |
|
| 4927 |
addr = create_tmp_var (ptr_type_node, "addr"); |
| 4928 |
type_align = TYPE_ALIGN (type); |
| 4929 |
|
| 4930 |
if (container) |
| 4931 |
{ |
| 4932 |
int needed_intregs, needed_sseregs; |
| 4933 |
bool need_temp; |
| 4934 |
tree int_addr, sse_addr; |
| 4935 |
|
| 4936 |
lab_false = create_artificial_label (UNKNOWN_LOCATION); |
| 4937 |
lab_over = create_artificial_label (UNKNOWN_LOCATION); |
| 4938 |
|
| 4939 |
examine_argument (nat_mode, type, 0, &needed_intregs, &needed_sseregs); |
| 4940 |
|
| 4941 |
bool container_in_reg = false; |
| 4942 |
if (REG_P (container)) |
| 4943 |
container_in_reg = true; |
| 4944 |
else if (GET_CODE (container) == PARALLEL |
| 4945 |
&& GET_MODE (container) == BLKmode |
| 4946 |
&& XVECLEN (container, 0) == 1) |
| 4947 |
{ |
| 4948 |
/* Check if it is a PARALLEL BLKmode container of an EXPR_LIST |
| 4949 |
expression in a TImode register. In this case, temp isn't |
| 4950 |
needed. Otherwise, the TImode variable will be put in the |
| 4951 |
GPR save area which guarantees only 8-byte alignment. */ |
| 4952 |
rtx x = XVECEXP (container, 0, 0); |
| 4953 |
if (GET_CODE (x) == EXPR_LIST |
| 4954 |
&& REG_P (XEXP (x, 0)) |
| 4955 |
&& XEXP (x, 1) == const0_rtx) |
| 4956 |
container_in_reg = true; |
| 4957 |
} |
| 4958 |
|
| 4959 |
need_temp = (!container_in_reg |
| 4960 |
&& ((needed_intregs && TYPE_ALIGN (type) > 64) |
| 4961 |
|| TYPE_ALIGN (type) > 128)); |
| 4962 |
|
| 4963 |
/* In case we are passing structure, verify that it is consecutive block |
| 4964 |
on the register save area. If not we need to do moves. */ |
| 4965 |
if (!need_temp && !container_in_reg) |
| 4966 |
{ |
| 4967 |
/* Verify that all registers are strictly consecutive */ |
| 4968 |
if (SSE_REGNO_P (REGNO (XEXP (XVECEXP (container, 0, 0), 0)))) |
| 4969 |
{ |
| 4970 |
int i; |
| 4971 |
|
| 4972 |
for (i = 0; i < XVECLEN (container, 0) && !need_temp; i++) |
| 4973 |
{ |
| 4974 |
rtx slot = XVECEXP (container, 0, i); |
| 4975 |
if (REGNO (XEXP (slot, 0)) != FIRST_SSE_REG + (unsigned int) i |
| 4976 |
|| INTVAL (XEXP (slot, 1)) != i * 16) |
| 4977 |
need_temp = true; |
| 4978 |
} |
| 4979 |
} |
| 4980 |
else |
| 4981 |
{ |
| 4982 |
int i; |
| 4983 |
|
| 4984 |
for (i = 0; i < XVECLEN (container, 0) && !need_temp; i++) |
| 4985 |
{ |
| 4986 |
rtx slot = XVECEXP (container, 0, i); |
| 4987 |
if (REGNO (XEXP (slot, 0)) != (unsigned int) i |
| 4988 |
|| INTVAL (XEXP (slot, 1)) != i * 8) |
| 4989 |
need_temp = true; |
| 4990 |
} |
| 4991 |
} |
| 4992 |
} |
| 4993 |
if (!need_temp) |
| 4994 |
{ |
| 4995 |
int_addr = addr; |
| 4996 |
sse_addr = addr; |
| 4997 |
} |
| 4998 |
else |
| 4999 |
{ |
| 5000 |
int_addr = create_tmp_var (ptr_type_node, "int_addr"); |
| 5001 |
sse_addr = create_tmp_var (ptr_type_node, "sse_addr"); |
| 5002 |
} |
| 5003 |
|
| 5004 |
/* First ensure that we fit completely in registers. */ |
| 5005 |
if (needed_intregs) |
| 5006 |
{ |
| 5007 |
t = build_int_cst (TREE_TYPE (gpr), |
| 5008 |
(X86_64_REGPARM_MAX - needed_intregs + 1) * 8); |
| 5009 |
t = build2 (GE_EXPR, boolean_type_node, gpr, t); |
| 5010 |
t2 = build1 (GOTO_EXPR, void_type_node, lab_false); |
| 5011 |
t = build3 (COND_EXPR, void_type_node, t, t2, NULL_TREE); |
| 5012 |
gimplify_and_add (t, pre_p); |
| 5013 |
} |
| 5014 |
if (needed_sseregs) |
| 5015 |
{ |
| 5016 |
t = build_int_cst (TREE_TYPE (fpr), |
| 5017 |
(X86_64_SSE_REGPARM_MAX - needed_sseregs + 1) * 16 |
| 5018 |
+ X86_64_REGPARM_MAX * 8); |
| 5019 |
t = build2 (GE_EXPR, boolean_type_node, fpr, t); |
| 5020 |
t2 = build1 (GOTO_EXPR, void_type_node, lab_false); |
| 5021 |
t = build3 (COND_EXPR, void_type_node, t, t2, NULL_TREE); |
| 5022 |
gimplify_and_add (t, pre_p); |
| 5023 |
} |
| 5024 |
|
| 5025 |
/* Compute index to start of area used for integer regs. */ |
| 5026 |
if (needed_intregs) |
| 5027 |
{ |
| 5028 |
/* int_addr = gpr + sav; */ |
| 5029 |
t = fold_build_pointer_plus (sav, gpr); |
| 5030 |
gimplify_assign (int_addr, t, pre_p); |
| 5031 |
} |
| 5032 |
if (needed_sseregs) |
| 5033 |
{ |
| 5034 |
/* sse_addr = fpr + sav; */ |
| 5035 |
t = fold_build_pointer_plus (sav, fpr); |
| 5036 |
gimplify_assign (sse_addr, t, pre_p); |
| 5037 |
} |
| 5038 |
if (need_temp) |
| 5039 |
{ |
| 5040 |
int i, prev_size = 0; |
| 5041 |
tree temp = create_tmp_var (type, "va_arg_tmp"); |
| 5042 |
TREE_ADDRESSABLE (temp) = 1; |
| 5043 |
|
| 5044 |
/* addr = &temp; */ |
| 5045 |
t = build1 (ADDR_EXPR, build_pointer_type (type), temp); |
| 5046 |
gimplify_assign (addr, t, pre_p); |
| 5047 |
|
| 5048 |
for (i = 0; i < XVECLEN (container, 0); i++) |
| 5049 |
{ |
| 5050 |
rtx slot = XVECEXP (container, 0, i); |
| 5051 |
rtx reg = XEXP (slot, 0); |
| 5052 |
machine_mode mode = GET_MODE (reg); |
| 5053 |
tree piece_type; |
| 5054 |
tree addr_type; |
| 5055 |
tree daddr_type; |
| 5056 |
tree src_addr, src; |
| 5057 |
int src_offset; |
| 5058 |
tree dest_addr, dest; |
| 5059 |
int cur_size = GET_MODE_SIZE (mode); |
| 5060 |
|
| 5061 |
gcc_assert (prev_size <= INTVAL (XEXP (slot, 1))); |
| 5062 |
prev_size = INTVAL (XEXP (slot, 1)); |
| 5063 |
if (prev_size + cur_size > size) |
| 5064 |
{ |
| 5065 |
cur_size = size - prev_size; |
| 5066 |
unsigned int nbits = cur_size * BITS_PER_UNIT; |
| 5067 |
if (!int_mode_for_size (nbits, 1).exists (&mode)) |
| 5068 |
mode = QImode; |
| 5069 |
} |
| 5070 |
piece_type = lang_hooks.types.type_for_mode (mode, 1); |
| 5071 |
if (mode == GET_MODE (reg)) |
| 5072 |
addr_type = build_pointer_type (piece_type); |
| 5073 |
else |
| 5074 |
addr_type = build_pointer_type_for_mode (piece_type, ptr_mode, |
| 5075 |
true); |
| 5076 |
daddr_type = build_pointer_type_for_mode (piece_type, ptr_mode, |
| 5077 |
true); |
| 5078 |
|
| 5079 |
if (SSE_REGNO_P (REGNO (reg))) |
| 5080 |
{ |
| 5081 |
src_addr = sse_addr; |
| 5082 |
src_offset = (REGNO (reg) - FIRST_SSE_REG) * 16; |
| 5083 |
} |
| 5084 |
else |
| 5085 |
{ |
| 5086 |
src_addr = int_addr; |
| 5087 |
src_offset = REGNO (reg) * 8; |
| 5088 |
} |
| 5089 |
src_addr = fold_convert (addr_type, src_addr); |
| 5090 |
src_addr = fold_build_pointer_plus_hwi (src_addr, src_offset); |
| 5091 |
|
| 5092 |
dest_addr = fold_convert (daddr_type, addr); |
| 5093 |
dest_addr = fold_build_pointer_plus_hwi (dest_addr, prev_size); |
| 5094 |
if (cur_size == GET_MODE_SIZE (mode)) |
| 5095 |
{ |
| 5096 |
src = build_va_arg_indirect_ref (src_addr); |
| 5097 |
dest = build_va_arg_indirect_ref (dest_addr); |
| 5098 |
|
| 5099 |
gimplify_assign (dest, src, pre_p); |
| 5100 |
} |
| 5101 |
else |
| 5102 |
{ |
| 5103 |
tree copy |
| 5104 |
= build_call_expr (builtin_decl_implicit (BUILT_IN_MEMCPY), |
| 5105 |
3, dest_addr, src_addr, |
| 5106 |
size_int (cur_size)); |
| 5107 |
gimplify_and_add (copy, pre_p); |
| 5108 |
} |
| 5109 |
prev_size += cur_size; |
| 5110 |
} |
| 5111 |
} |
| 5112 |
|
| 5113 |
if (needed_intregs) |
| 5114 |
{ |
| 5115 |
t = build2 (PLUS_EXPR, TREE_TYPE (gpr), gpr, |
| 5116 |
build_int_cst (TREE_TYPE (gpr), needed_intregs * 8)); |
| 5117 |
gimplify_assign (gpr, t, pre_p); |
| 5118 |
/* The GPR save area guarantees only 8-byte alignment. */ |
| 5119 |
if (!need_temp) |
| 5120 |
type_align = MIN (type_align, 64); |
| 5121 |
} |
| 5122 |
|
| 5123 |
if (needed_sseregs) |
| 5124 |
{ |
| 5125 |
t = build2 (PLUS_EXPR, TREE_TYPE (fpr), fpr, |
| 5126 |
build_int_cst (TREE_TYPE (fpr), needed_sseregs * 16)); |
| 5127 |
gimplify_assign (unshare_expr (fpr), t, pre_p); |
| 5128 |
} |
| 5129 |
|
| 5130 |
gimple_seq_add_stmt (pre_p, gimple_build_goto (lab_over)); |
| 5131 |
|
| 5132 |
gimple_seq_add_stmt (pre_p, gimple_build_label (lab_false)); |
| 5133 |
} |
| 5134 |
|
| 5135 |
/* ... otherwise out of the overflow area. */ |
| 5136 |
|
| 5137 |
/* When we align parameter on stack for caller, if the parameter |
| 5138 |
alignment is beyond MAX_SUPPORTED_STACK_ALIGNMENT, it will be |
| 5139 |
aligned at MAX_SUPPORTED_STACK_ALIGNMENT. We will match callee |
| 5140 |
here with caller. */ |
| 5141 |
arg_boundary = ix86_function_arg_boundary (VOIDmode, type); |
| 5142 |
if ((unsigned int) arg_boundary > MAX_SUPPORTED_STACK_ALIGNMENT) |
| 5143 |
arg_boundary = MAX_SUPPORTED_STACK_ALIGNMENT; |
| 5144 |
|
| 5145 |
/* Care for on-stack alignment if needed. */ |
| 5146 |
if (arg_boundary <= 64 || size == 0) |
| 5147 |
t = ovf; |
| 5148 |
else |
| 5149 |
{ |
| 5150 |
HOST_WIDE_INT align = arg_boundary / 8; |
| 5151 |
t = fold_build_pointer_plus_hwi (ovf, align - 1); |
| 5152 |
t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t, |
| 5153 |
build_int_cst (TREE_TYPE (t), -align)); |
| 5154 |
} |
| 5155 |
|
| 5156 |
gimplify_expr (&t, pre_p, NULL, is_gimple_val, fb_rvalue); |
| 5157 |
gimplify_assign (addr, t, pre_p); |
| 5158 |
|
| 5159 |
t = fold_build_pointer_plus_hwi (t, rsize * UNITS_PER_WORD); |
| 5160 |
gimplify_assign (unshare_expr (ovf), t, pre_p); |
| 5161 |
|
| 5162 |
if (container) |
| 5163 |
gimple_seq_add_stmt (pre_p, gimple_build_label (lab_over)); |
| 5164 |
|
| 5165 |
type = build_aligned_type (type, type_align); |
| 5166 |
ptrtype = build_pointer_type_for_mode (type, ptr_mode, true); |
| 5167 |
addr = fold_convert (ptrtype, addr); |
| 5168 |
|
| 5169 |
if (indirect_p) |
| 5170 |
addr = build_va_arg_indirect_ref (addr); |
| 5171 |
return build_va_arg_indirect_ref (addr); |
| 5172 |
} |
| 5173 |
|
| 5174 |
/* Return true if OPNUM's MEM should be matched |
| 5175 |
in movabs* patterns. */ |
| 5176 |
|
| 5177 |
bool |
| 5178 |
ix86_check_movabs (rtx insn, int opnum) |
| 5179 |
{ |
| 5180 |
rtx set, mem; |
| 5181 |
|
| 5182 |
set = PATTERN (insn); |
| 5183 |
if (GET_CODE (set) == PARALLEL) |
| 5184 |
set = XVECEXP (set, 0, 0); |
| 5185 |
gcc_assert (GET_CODE (set) == SET); |
| 5186 |
mem = XEXP (set, opnum); |
| 5187 |
while (SUBREG_P (mem)) |
| 5188 |
mem = SUBREG_REG (mem); |
| 5189 |
gcc_assert (MEM_P (mem)); |
| 5190 |
return volatile_ok || !MEM_VOLATILE_P (mem); |
| 5191 |
} |
| 5192 |
|
| 5193 |
/* Return false if INSN contains a MEM with a non-default address space. */ |
| 5194 |
bool |
| 5195 |
ix86_check_no_addr_space (rtx insn) |
| 5196 |
{ |
| 5197 |
subrtx_var_iterator::array_type array; |
| 5198 |
FOR_EACH_SUBRTX_VAR (iter, array, PATTERN (insn), ALL) |
| 5199 |
{ |
| 5200 |
rtx x = *iter; |
| 5201 |
if (MEM_P (x) && !ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (x))) |
| 5202 |
return false; |
| 5203 |
} |
| 5204 |
return true; |
| 5205 |
} |
| 5206 |
|
| 5207 |
/* Initialize the table of extra 80387 mathematical constants. */ |
| 5208 |
|
| 5209 |
static void |
| 5210 |
init_ext_80387_constants (void) |
| 5211 |
{ |
| 5212 |
static const char * cst[5] = |
| 5213 |
{ |
| 5214 |
"0.3010299956639811952256464283594894482", /* 0: fldlg2 */ |
| 5215 |
"0.6931471805599453094286904741849753009", /* 1: fldln2 */ |
| 5216 |
"1.4426950408889634073876517827983434472", /* 2: fldl2e */ |
| 5217 |
"3.3219280948873623478083405569094566090", /* 3: fldl2t */ |
| 5218 |
"3.1415926535897932385128089594061862044", /* 4: fldpi */ |
| 5219 |
}; |
| 5220 |
int i; |
| 5221 |
|
| 5222 |
for (i = 0; i < 5; i++) |
| 5223 |
{ |
| 5224 |
real_from_string (&ext_80387_constants_table[i], cst[i]); |
| 5225 |
/* Ensure each constant is rounded to XFmode precision. */ |
| 5226 |
real_convert (&ext_80387_constants_table[i], |
| 5227 |
XFmode, &ext_80387_constants_table[i]); |
| 5228 |
} |
| 5229 |
|
| 5230 |
ext_80387_constants_init = 1; |
| 5231 |
} |
| 5232 |
|
| 5233 |
/* Return non-zero if the constant is something that |
| 5234 |
can be loaded with a special instruction. */ |
| 5235 |
|
| 5236 |
int |
| 5237 |
standard_80387_constant_p (rtx x) |
| 5238 |
{ |
| 5239 |
machine_mode mode = GET_MODE (x); |
| 5240 |
|
| 5241 |
const REAL_VALUE_TYPE *r; |
| 5242 |
|
| 5243 |
if (!(CONST_DOUBLE_P (x) && X87_FLOAT_MODE_P (mode))) |
| 5244 |
return -1; |
| 5245 |
|
| 5246 |
if (x == CONST0_RTX (mode)) |
| 5247 |
return 1; |
| 5248 |
if (x == CONST1_RTX (mode)) |
| 5249 |
return 2; |
| 5250 |
|
| 5251 |
r = CONST_DOUBLE_REAL_VALUE (x); |
| 5252 |
|
| 5253 |
/* For XFmode constants, try to find a special 80387 instruction when |
| 5254 |
optimizing for size or on those CPUs that benefit from them. */ |
| 5255 |
if (mode == XFmode |
| 5256 |
&& (optimize_function_for_size_p (cfun) || TARGET_EXT_80387_CONSTANTS) |
| 5257 |
&& !flag_rounding_math) |
| 5258 |
{ |
| 5259 |
int i; |
| 5260 |
|
| 5261 |
if (! ext_80387_constants_init) |
| 5262 |
init_ext_80387_constants (); |
| 5263 |
|
| 5264 |
for (i = 0; i < 5; i++) |
| 5265 |
if (real_identical (r, &ext_80387_constants_table[i])) |
| 5266 |
return i + 3; |
| 5267 |
} |
| 5268 |
|
| 5269 |
/* Load of the constant -0.0 or -1.0 will be split as |
| 5270 |
fldz;fchs or fld1;fchs sequence. */ |
| 5271 |
if (real_isnegzero (r)) |
| 5272 |
return 8; |
| 5273 |
if (real_identical (r, &dconstm1)) |
| 5274 |
return 9; |
| 5275 |
|
| 5276 |
return 0; |
| 5277 |
} |
| 5278 |
|
| 5279 |
/* Return the opcode of the special instruction to be used to load |
| 5280 |
the constant X. */ |
| 5281 |
|
| 5282 |
const char * |
| 5283 |
standard_80387_constant_opcode (rtx x) |
| 5284 |
{ |
| 5285 |
switch (standard_80387_constant_p (x)) |
| 5286 |
{ |
| 5287 |
case 1: |
| 5288 |
return "fldz"; |
| 5289 |
case 2: |
| 5290 |
return "fld1"; |
| 5291 |
case 3: |
| 5292 |
return "fldlg2"; |
| 5293 |
case 4: |
| 5294 |
return "fldln2"; |
| 5295 |
case 5: |
| 5296 |
return "fldl2e"; |
| 5297 |
case 6: |
| 5298 |
return "fldl2t"; |
| 5299 |
case 7: |
| 5300 |
return "fldpi"; |
| 5301 |
case 8: |
| 5302 |
case 9: |
| 5303 |
return "#"; |
| 5304 |
default: |
| 5305 |
gcc_unreachable (); |
| 5306 |
} |
| 5307 |
} |
| 5308 |
|
| 5309 |
/* Return the CONST_DOUBLE representing the 80387 constant that is |
| 5310 |
loaded by the specified special instruction. The argument IDX |
| 5311 |
matches the return value from standard_80387_constant_p. */ |
| 5312 |
|
| 5313 |
rtx |
| 5314 |
standard_80387_constant_rtx (int idx) |
| 5315 |
{ |
| 5316 |
int i; |
| 5317 |
|
| 5318 |
if (! ext_80387_constants_init) |
| 5319 |
init_ext_80387_constants (); |
| 5320 |
|
| 5321 |
switch (idx) |
| 5322 |
{ |
| 5323 |
case 3: |
| 5324 |
case 4: |
| 5325 |
case 5: |
| 5326 |
case 6: |
| 5327 |
case 7: |
| 5328 |
i = idx - 3; |
| 5329 |
break; |
| 5330 |
|
| 5331 |
default: |
| 5332 |
gcc_unreachable (); |
| 5333 |
} |
| 5334 |
|
| 5335 |
return const_double_from_real_value (ext_80387_constants_table[i], |
| 5336 |
XFmode); |
| 5337 |
} |
| 5338 |
|
| 5339 |
/* Return 1 if X is all bits 0, 2 if X is all bits 1 |
| 5340 |
and 3 if X is all bits 1 with zero extend |
| 5341 |
in supported SSE/AVX vector mode. */ |
| 5342 |
|
| 5343 |
int |
| 5344 |
standard_sse_constant_p (rtx x, machine_mode pred_mode) |
| 5345 |
{ |
| 5346 |
machine_mode mode; |
| 5347 |
|
| 5348 |
if (!TARGET_SSE) |
| 5349 |
return 0; |
| 5350 |
|
| 5351 |
mode = GET_MODE (x); |
| 5352 |
|
| 5353 |
if (x == const0_rtx || const0_operand (x, mode)) |
| 5354 |
return 1; |
| 5355 |
|
| 5356 |
if (x == constm1_rtx |
| 5357 |
|| vector_all_ones_operand (x, mode) |
| 5358 |
|| ((GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT |
| 5359 |
|| GET_MODE_CLASS (pred_mode) == MODE_VECTOR_FLOAT) |
| 5360 |
&& float_vector_all_ones_operand (x, mode))) |
| 5361 |
{ |
| 5362 |
/* VOIDmode integer constant, get mode from the predicate. */ |
| 5363 |
if (mode == VOIDmode) |
| 5364 |
mode = pred_mode; |
| 5365 |
|
| 5366 |
switch (GET_MODE_SIZE (mode)) |
| 5367 |
{ |
| 5368 |
case 64: |
| 5369 |
if (TARGET_AVX512F && TARGET_EVEX512) |
| 5370 |
return 2; |
| 5371 |
break; |
| 5372 |
case 32: |
| 5373 |
if (TARGET_AVX2) |
| 5374 |
return 2; |
| 5375 |
break; |
| 5376 |
case 16: |
| 5377 |
if (TARGET_SSE2) |
| 5378 |
return 2; |
| 5379 |
break; |
| 5380 |
case 0: |
| 5381 |
/* VOIDmode */ |
| 5382 |
gcc_unreachable (); |
| 5383 |
default: |
| 5384 |
break; |
| 5385 |
} |
| 5386 |
} |
| 5387 |
|
| 5388 |
if (vector_all_ones_zero_extend_half_operand (x, mode) |
| 5389 |
|| vector_all_ones_zero_extend_quarter_operand (x, mode)) |
| 5390 |
return 3; |
| 5391 |
|
| 5392 |
return 0; |
| 5393 |
} |
| 5394 |
|
| 5395 |
/* Return the opcode of the special instruction to be used to load |
| 5396 |
the constant operands[1] into operands[0]. */ |
| 5397 |
|
| 5398 |
const char * |
| 5399 |
standard_sse_constant_opcode (rtx_insn *insn, rtx *operands) |
| 5400 |
{ |
| 5401 |
machine_mode mode; |
| 5402 |
rtx x = operands[1]; |
| 5403 |
|
| 5404 |
gcc_assert (TARGET_SSE); |
| 5405 |
|
| 5406 |
mode = GET_MODE (x); |
| 5407 |
|
| 5408 |
if (x == const0_rtx || const0_operand (x, mode)) |
| 5409 |
{ |
| 5410 |
switch (get_attr_mode (insn)) |
| 5411 |
{ |
| 5412 |
case MODE_TI: |
| 5413 |
if (!EXT_REX_SSE_REG_P (operands[0])) |
| 5414 |
return "%vpxor\t%0, %d0"; |
| 5415 |
/* FALLTHRU */ |
| 5416 |
case MODE_XI: |
| 5417 |
case MODE_OI: |
| 5418 |
if (EXT_REX_SSE_REG_P (operands[0])) |
| 5419 |
{ |
| 5420 |
if (TARGET_AVX512VL) |
| 5421 |
return "vpxord\t%x0, %x0, %x0"; |
| 5422 |
else if (TARGET_EVEX512) |
| 5423 |
return "vpxord\t%g0, %g0, %g0"; |
| 5424 |
else |
| 5425 |
gcc_unreachable (); |
| 5426 |
} |
| 5427 |
return "vpxor\t%x0, %x0, %x0"; |
| 5428 |
|
| 5429 |
case MODE_V2DF: |
| 5430 |
if (!EXT_REX_SSE_REG_P (operands[0])) |
| 5431 |
return "%vxorpd\t%0, %d0"; |
| 5432 |
/* FALLTHRU */ |
| 5433 |
case MODE_V8DF: |
| 5434 |
case MODE_V4DF: |
| 5435 |
if (EXT_REX_SSE_REG_P (operands[0])) |
| 5436 |
{ |
| 5437 |
if (TARGET_AVX512DQ) |
| 5438 |
{ |
| 5439 |
if (TARGET_AVX512VL) |
| 5440 |
return "vxorpd\t%x0, %x0, %x0"; |
| 5441 |
else if (TARGET_EVEX512) |
| 5442 |
return "vxorpd\t%g0, %g0, %g0"; |
| 5443 |
else |
| 5444 |
gcc_unreachable (); |
| 5445 |
} |
| 5446 |
else |
| 5447 |
{ |
| 5448 |
if (TARGET_AVX512VL) |
| 5449 |
return "vpxorq\t%x0, %x0, %x0"; |
| 5450 |
else if (TARGET_EVEX512) |
| 5451 |
return "vpxorq\t%g0, %g0, %g0"; |
| 5452 |
else |
| 5453 |
gcc_unreachable (); |
| 5454 |
} |
| 5455 |
} |
| 5456 |
return "vxorpd\t%x0, %x0, %x0"; |
| 5457 |
|
| 5458 |
case MODE_V4SF: |
| 5459 |
if (!EXT_REX_SSE_REG_P (operands[0])) |
| 5460 |
return "%vxorps\t%0, %d0"; |
| 5461 |
/* FALLTHRU */ |
| 5462 |
case MODE_V16SF: |
| 5463 |
case MODE_V8SF: |
| 5464 |
if (EXT_REX_SSE_REG_P (operands[0])) |
| 5465 |
{ |
| 5466 |
if (TARGET_AVX512DQ) |
| 5467 |
{ |
| 5468 |
if (TARGET_AVX512VL) |
| 5469 |
return "vxorps\t%x0, %x0, %x0"; |
| 5470 |
else if (TARGET_EVEX512) |
| 5471 |
return "vxorps\t%g0, %g0, %g0"; |
| 5472 |
else |
| 5473 |
gcc_unreachable (); |
| 5474 |
} |
| 5475 |
else |
| 5476 |
{ |
| 5477 |
if (TARGET_AVX512VL) |
| 5478 |
return "vpxord\t%x0, %x0, %x0"; |
| 5479 |
else if (TARGET_EVEX512) |
| 5480 |
return "vpxord\t%g0, %g0, %g0"; |
| 5481 |
else |
| 5482 |
gcc_unreachable (); |
| 5483 |
} |
| 5484 |
} |
| 5485 |
return "vxorps\t%x0, %x0, %x0"; |
| 5486 |
|
| 5487 |
default: |
| 5488 |
gcc_unreachable (); |
| 5489 |
} |
| 5490 |
} |
| 5491 |
else if (x == constm1_rtx |
| 5492 |
|| vector_all_ones_operand (x, mode) |
| 5493 |
|| (GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT |
| 5494 |
&& float_vector_all_ones_operand (x, mode))) |
| 5495 |
{ |
| 5496 |
enum attr_mode insn_mode = get_attr_mode (insn); |
| 5497 |
|
| 5498 |
switch (insn_mode) |
| 5499 |
{ |
| 5500 |
case MODE_XI: |
| 5501 |
case MODE_V8DF: |
| 5502 |
case MODE_V16SF: |
| 5503 |
gcc_assert (TARGET_AVX512F && TARGET_EVEX512); |
| 5504 |
return "vpternlogd\t{$0xFF, %g0, %g0, %g0|%g0, %g0, %g0, 0xFF}"; |
| 5505 |
|
| 5506 |
case MODE_OI: |
| 5507 |
case MODE_V4DF: |
| 5508 |
case MODE_V8SF: |
| 5509 |
gcc_assert (TARGET_AVX2); |
| 5510 |
/* FALLTHRU */ |
| 5511 |
case MODE_TI: |
| 5512 |
case MODE_V2DF: |
| 5513 |
case MODE_V4SF: |
| 5514 |
gcc_assert (TARGET_SSE2); |
| 5515 |
if (EXT_REX_SSE_REG_P (operands[0])) |
| 5516 |
{ |
| 5517 |
if (TARGET_AVX512VL) |
| 5518 |
return "vpternlogd\t{$0xFF, %0, %0, %0|%0, %0, %0, 0xFF}"; |
| 5519 |
else if (TARGET_EVEX512) |
| 5520 |
return "vpternlogd\t{$0xFF, %g0, %g0, %g0|%g0, %g0, %g0, 0xFF}"; |
| 5521 |
else |
| 5522 |
gcc_unreachable (); |
| 5523 |
} |
| 5524 |
return (TARGET_AVX |
| 5525 |
? "vpcmpeqd\t%0, %0, %0" |
| 5526 |
: "pcmpeqd\t%0, %0"); |
| 5527 |
|
| 5528 |
default: |
| 5529 |
gcc_unreachable (); |
| 5530 |
} |
| 5531 |
} |
| 5532 |
else if (vector_all_ones_zero_extend_half_operand (x, mode)) |
| 5533 |
{ |
| 5534 |
if (GET_MODE_SIZE (mode) == 64) |
| 5535 |
{ |
| 5536 |
gcc_assert (TARGET_AVX512F && TARGET_EVEX512); |
| 5537 |
return "vpcmpeqd\t%t0, %t0, %t0"; |
| 5538 |
} |
| 5539 |
else if (GET_MODE_SIZE (mode) == 32) |
| 5540 |
{ |
| 5541 |
gcc_assert (TARGET_AVX); |
| 5542 |
return "vpcmpeqd\t%x0, %x0, %x0"; |
| 5543 |
} |
| 5544 |
gcc_unreachable (); |
| 5545 |
} |
| 5546 |
else if (vector_all_ones_zero_extend_quarter_operand (x, mode)) |
| 5547 |
{ |
| 5548 |
gcc_assert (TARGET_AVX512F && TARGET_EVEX512); |
| 5549 |
return "vpcmpeqd\t%x0, %x0, %x0"; |
| 5550 |
} |
| 5551 |
|
| 5552 |
gcc_unreachable (); |
| 5553 |
} |
| 5554 |
|
| 5555 |
/* Returns true if INSN can be transformed from a memory load |
| 5556 |
to a supported FP constant load. */ |
| 5557 |
|
| 5558 |
bool |
| 5559 |
ix86_standard_x87sse_constant_load_p (const rtx_insn *insn, rtx dst) |
| 5560 |
{ |
| 5561 |
rtx src = find_constant_src (insn); |
| 5562 |
|
| 5563 |
gcc_assert (REG_P (dst)); |
| 5564 |
|
| 5565 |
if (src == NULL |
| 5566 |
|| (SSE_REGNO_P (REGNO (dst)) |
| 5567 |
&& standard_sse_constant_p (src, GET_MODE (dst)) != 1) |
| 5568 |
|| (!TARGET_AVX512VL |
| 5569 |
&& EXT_REX_SSE_REGNO_P (REGNO (dst)) |
| 5570 |
&& standard_sse_constant_p (src, GET_MODE (dst)) == 1) |
| 5571 |
|| (STACK_REGNO_P (REGNO (dst)) |
| 5572 |
&& standard_80387_constant_p (src) < 1)) |
| 5573 |
return false; |
| 5574 |
|
| 5575 |
return true; |
| 5576 |
} |
| 5577 |
|
| 5578 |
/* Predicate for pre-reload splitters with associated instructions, |
| 5579 |
which can match any time before the split1 pass (usually combine), |
| 5580 |
then are unconditionally split in that pass and should not be |
| 5581 |
matched again afterwards. */ |
| 5582 |
|
| 5583 |
bool |
| 5584 |
ix86_pre_reload_split (void) |
| 5585 |
{ |
| 5586 |
return (can_create_pseudo_p () |
| 5587 |
&& !(cfun->curr_properties & PROP_rtl_split_insns)); |
| 5588 |
} |
| 5589 |
|
| 5590 |
/* Return the opcode of the TYPE_SSEMOV instruction. To move from |
| 5591 |
or to xmm16-xmm31/ymm16-ymm31 registers, we either require |
| 5592 |
TARGET_AVX512VL or it is a register to register move which can |
| 5593 |
be done with zmm register move. */ |
| 5594 |
|
| 5595 |
static const char * |
| 5596 |
ix86_get_ssemov (rtx *operands, unsigned size, |
| 5597 |
enum attr_mode insn_mode, machine_mode mode) |
| 5598 |
{ |
| 5599 |
char buf[128]; |
| 5600 |
bool misaligned_p = (misaligned_operand (operands[0], mode) |
| 5601 |
|| misaligned_operand (operands[1], mode)); |
| 5602 |
bool evex_reg_p = (size == 64 |
| 5603 |
|| EXT_REX_SSE_REG_P (operands[0]) |
| 5604 |
|| EXT_REX_SSE_REG_P (operands[1])); |
| 5605 |
|
| 5606 |
bool egpr_p = (TARGET_APX_EGPR |
| 5607 |
&& (x86_extended_rex2reg_mentioned_p (operands[0]) |
| 5608 |
|| x86_extended_rex2reg_mentioned_p (operands[1]))); |
| 5609 |
bool egpr_vl = egpr_p && TARGET_AVX512VL; |
| 5610 |
|
| 5611 |
machine_mode scalar_mode; |
| 5612 |
|
| 5613 |
const char *opcode = NULL; |
| 5614 |
enum |
| 5615 |
{ |
| 5616 |
opcode_int, |
| 5617 |
opcode_float, |
| 5618 |
opcode_double |
| 5619 |
} type = opcode_int; |
| 5620 |
|
| 5621 |
switch (insn_mode) |
| 5622 |
{ |
| 5623 |
case MODE_V16SF: |
| 5624 |
case MODE_V8SF: |
| 5625 |
case MODE_V4SF: |
| 5626 |
scalar_mode = E_SFmode; |
| 5627 |
type = opcode_float; |
| 5628 |
break; |
| 5629 |
case MODE_V8DF: |
| 5630 |
case MODE_V4DF: |
| 5631 |
case MODE_V2DF: |
| 5632 |
scalar_mode = E_DFmode; |
| 5633 |
type = opcode_double; |
| 5634 |
break; |
| 5635 |
case MODE_XI: |
| 5636 |
case MODE_OI: |
| 5637 |
case MODE_TI: |
| 5638 |
scalar_mode = GET_MODE_INNER (mode); |
| 5639 |
break; |
| 5640 |
default: |
| 5641 |
gcc_unreachable (); |
| 5642 |
} |
| 5643 |
|
| 5644 |
/* NB: To move xmm16-xmm31/ymm16-ymm31 registers without AVX512VL, |
| 5645 |
we can only use zmm register move without memory operand. */ |
| 5646 |
if (evex_reg_p |
| 5647 |
&& !TARGET_AVX512VL |
| 5648 |
&& GET_MODE_SIZE (mode) < 64) |
| 5649 |
{ |
| 5650 |
/* NB: Even though ix86_hard_regno_mode_ok doesn't allow |
| 5651 |
xmm16-xmm31 nor ymm16-ymm31 in 128/256 bit modes when |
| 5652 |
AVX512VL is disabled, LRA can still generate reg to |
| 5653 |
reg moves with xmm16-xmm31 and ymm16-ymm31 in 128/256 bit |
| 5654 |
modes. */ |
| 5655 |
if (memory_operand (operands[0], mode) |
| 5656 |
|| memory_operand (operands[1], mode)) |
| 5657 |
gcc_unreachable (); |
| 5658 |
size = 64; |
| 5659 |
/* We need TARGET_EVEX512 to move into zmm register. */ |
| 5660 |
gcc_assert (TARGET_EVEX512); |
| 5661 |
switch (type) |
| 5662 |
{ |
| 5663 |
case opcode_int: |
| 5664 |
if (scalar_mode == E_HFmode || scalar_mode == E_BFmode) |
| 5665 |
opcode = (misaligned_p |
| 5666 |
? (TARGET_AVX512BW ? "vmovdqu16" : "vmovdqu64") |
| 5667 |
: "vmovdqa64"); |
| 5668 |
else |
| 5669 |
opcode = misaligned_p ? "vmovdqu32" : "vmovdqa32"; |
| 5670 |
break; |
| 5671 |
case opcode_float: |
| 5672 |
opcode = misaligned_p ? "vmovups" : "vmovaps"; |
| 5673 |
break; |
| 5674 |
case opcode_double: |
| 5675 |
opcode = misaligned_p ? "vmovupd" : "vmovapd"; |
| 5676 |
break; |
| 5677 |
} |
| 5678 |
} |
| 5679 |
else if (SCALAR_FLOAT_MODE_P (scalar_mode)) |
| 5680 |
{ |
| 5681 |
switch (scalar_mode) |
| 5682 |
{ |
| 5683 |
case E_HFmode: |
| 5684 |
case E_BFmode: |
| 5685 |
if (evex_reg_p || egpr_vl) |
| 5686 |
opcode = (misaligned_p |
| 5687 |
? (TARGET_AVX512BW |
| 5688 |
? "vmovdqu16" |
| 5689 |
: "vmovdqu64") |
| 5690 |
: "vmovdqa64"); |
| 5691 |
else if (egpr_p) |
| 5692 |
opcode = (misaligned_p |
| 5693 |
? (TARGET_AVX512BW |
| 5694 |
? "vmovdqu16" |
| 5695 |
: "%vmovups") |
| 5696 |
: "%vmovaps"); |
| 5697 |
else |
| 5698 |
opcode = (misaligned_p |
| 5699 |
? (TARGET_AVX512BW |
| 5700 |
? "vmovdqu16" |
| 5701 |
: "%vmovdqu") |
| 5702 |
: "%vmovdqa"); |
| 5703 |
break; |
| 5704 |
case E_SFmode: |
| 5705 |
opcode = misaligned_p ? "%vmovups" : "%vmovaps"; |
| 5706 |
break; |
| 5707 |
case E_DFmode: |
| 5708 |
opcode = misaligned_p ? "%vmovupd" : "%vmovapd"; |
| 5709 |
break; |
| 5710 |
case E_TFmode: |
| 5711 |
if (evex_reg_p || egpr_vl) |
| 5712 |
opcode = misaligned_p ? "vmovdqu64" : "vmovdqa64"; |
| 5713 |
else if (egpr_p) |
| 5714 |
opcode = misaligned_p ? "%vmovups" : "%vmovaps"; |
| 5715 |
else |
| 5716 |
opcode = misaligned_p ? "%vmovdqu" : "%vmovdqa"; |
| 5717 |
break; |
| 5718 |
default: |
| 5719 |
gcc_unreachable (); |
| 5720 |
} |
| 5721 |
} |
| 5722 |
else if (SCALAR_INT_MODE_P (scalar_mode)) |
| 5723 |
{ |
| 5724 |
switch (scalar_mode) |
| 5725 |
{ |
| 5726 |
case E_QImode: |
| 5727 |
if (evex_reg_p || egpr_vl) |
| 5728 |
opcode = (misaligned_p |
| 5729 |
? (TARGET_AVX512BW |
| 5730 |
? "vmovdqu8" |
| 5731 |
: "vmovdqu64") |
| 5732 |
: "vmovdqa64"); |
| 5733 |
else if (egpr_p) |
| 5734 |
opcode = (misaligned_p |
| 5735 |
? (TARGET_AVX512BW |
| 5736 |
? "vmovdqu8" |
| 5737 |
: "%vmovups") |
| 5738 |
: "%vmovaps"); |
| 5739 |
else |
| 5740 |
opcode = (misaligned_p |
| 5741 |
? (TARGET_AVX512BW |
| 5742 |
? "vmovdqu8" |
| 5743 |
: "%vmovdqu") |
| 5744 |
: "%vmovdqa"); |
| 5745 |
break; |
| 5746 |
case E_HImode: |
| 5747 |
if (evex_reg_p || egpr_vl) |
| 5748 |
opcode = (misaligned_p |
| 5749 |
? (TARGET_AVX512BW |
| 5750 |
? "vmovdqu16" |
| 5751 |
: "vmovdqu64") |
| 5752 |
: "vmovdqa64"); |
| 5753 |
else if (egpr_p) |
| 5754 |
opcode = (misaligned_p |
| 5755 |
? (TARGET_AVX512BW |
| 5756 |
? "vmovdqu16" |
| 5757 |
: "%vmovups") |
| 5758 |
: "%vmovaps"); |
| 5759 |
else |
| 5760 |
opcode = (misaligned_p |
| 5761 |
? (TARGET_AVX512BW |
| 5762 |
? "vmovdqu16" |
| 5763 |
: "%vmovdqu") |
| 5764 |
: "%vmovdqa"); |
| 5765 |
break; |
| 5766 |
case E_SImode: |
| 5767 |
if (evex_reg_p || egpr_vl) |
| 5768 |
opcode = misaligned_p ? "vmovdqu32" : "vmovdqa32"; |
| 5769 |
else if (egpr_p) |
| 5770 |
opcode = misaligned_p ? "%vmovups" : "%vmovaps"; |
| 5771 |
else |
| 5772 |
opcode = misaligned_p ? "%vmovdqu" : "%vmovdqa"; |
| 5773 |
break; |
| 5774 |
case E_DImode: |
| 5775 |
case E_TImode: |
| 5776 |
case E_OImode: |
| 5777 |
if (evex_reg_p || egpr_vl) |
| 5778 |
opcode = misaligned_p ? "vmovdqu64" : "vmovdqa64"; |
| 5779 |
else if (egpr_p) |
| 5780 |
opcode = misaligned_p ? "%vmovups" : "%vmovaps"; |
| 5781 |
else |
| 5782 |
opcode = misaligned_p ? "%vmovdqu" : "%vmovdqa"; |
| 5783 |
break; |
| 5784 |
case E_XImode: |
| 5785 |
opcode = misaligned_p ? "vmovdqu64" : "vmovdqa64"; |
| 5786 |
break; |
| 5787 |
default: |
| 5788 |
gcc_unreachable (); |
| 5789 |
} |
| 5790 |
} |
| 5791 |
else |
| 5792 |
gcc_unreachable (); |
| 5793 |
|
| 5794 |
switch (size) |
| 5795 |
{ |
| 5796 |
case 64: |
| 5797 |
snprintf (buf, sizeof (buf), "%s\t{%%g1, %%g0|%%g0, %%g1}", |
| 5798 |
opcode); |
| 5799 |
break; |
| 5800 |
case 32: |
| 5801 |
snprintf (buf, sizeof (buf), "%s\t{%%t1, %%t0|%%t0, %%t1}", |
| 5802 |
opcode); |
| 5803 |
break; |
| 5804 |
case 16: |
| 5805 |
snprintf (buf, sizeof (buf), "%s\t{%%x1, %%x0|%%x0, %%x1}", |
| 5806 |
opcode); |
| 5807 |
break; |
| 5808 |
default: |
| 5809 |
gcc_unreachable (); |
| 5810 |
} |
| 5811 |
output_asm_insn (buf, operands); |
| 5812 |
return ""; |
| 5813 |
} |
| 5814 |
|
| 5815 |
/* Return the template of the TYPE_SSEMOV instruction to move |
| 5816 |
operands[1] into operands[0]. */ |
| 5817 |
|
| 5818 |
const char * |
| 5819 |
ix86_output_ssemov (rtx_insn *insn, rtx *operands) |
| 5820 |
{ |
| 5821 |
machine_mode mode = GET_MODE (operands[0]); |
| 5822 |
if (get_attr_type (insn) != TYPE_SSEMOV |
| 5823 |
|| mode != GET_MODE (operands[1])) |
| 5824 |
gcc_unreachable (); |
| 5825 |
|
| 5826 |
enum attr_mode insn_mode = get_attr_mode (insn); |
| 5827 |
|
| 5828 |
switch (insn_mode) |
| 5829 |
{ |
| 5830 |
case MODE_XI: |
| 5831 |
case MODE_V8DF: |
| 5832 |
case MODE_V16SF: |
| 5833 |
return ix86_get_ssemov (operands, 64, insn_mode, mode); |
| 5834 |
|
| 5835 |
case MODE_OI: |
| 5836 |
case MODE_V4DF: |
| 5837 |
case MODE_V8SF: |
| 5838 |
return ix86_get_ssemov (operands, 32, insn_mode, mode); |
| 5839 |
|
| 5840 |
case MODE_TI: |
| 5841 |
case MODE_V2DF: |
| 5842 |
case MODE_V4SF: |
| 5843 |
return ix86_get_ssemov (operands, 16, insn_mode, mode); |
| 5844 |
|
| 5845 |
case MODE_DI: |
| 5846 |
/* Handle broken assemblers that require movd instead of movq. */ |
| 5847 |
if (GENERAL_REG_P (operands[0])) |
| 5848 |
{ |
| 5849 |
if (HAVE_AS_IX86_INTERUNIT_MOVQ) |
| 5850 |
return "%vmovq\t{%1, %q0|%q0, %1}"; |
| 5851 |
else |
| 5852 |
return "%vmovd\t{%1, %q0|%q0, %1}"; |
| 5853 |
} |
| 5854 |
else if (GENERAL_REG_P (operands[1])) |
| 5855 |
{ |
| 5856 |
if (HAVE_AS_IX86_INTERUNIT_MOVQ) |
| 5857 |
return "%vmovq\t{%q1, %0|%0, %q1}"; |
| 5858 |
else |
| 5859 |
return "%vmovd\t{%q1, %0|%0, %q1}"; |
| 5860 |
} |
| 5861 |
else |
| 5862 |
return "%vmovq\t{%1, %0|%0, %1}"; |
| 5863 |
|
| 5864 |
case MODE_SI: |
| 5865 |
if (GENERAL_REG_P (operands[0])) |
| 5866 |
return "%vmovd\t{%1, %k0|%k0, %1}"; |
| 5867 |
else if (GENERAL_REG_P (operands[1])) |
| 5868 |
return "%vmovd\t{%k1, %0|%0, %k1}"; |
| 5869 |
else |
| 5870 |
return "%vmovd\t{%1, %0|%0, %1}"; |
| 5871 |
|
| 5872 |
case MODE_HI: |
| 5873 |
if (GENERAL_REG_P (operands[0])) |
| 5874 |
return "vmovw\t{%1, %k0|%k0, %1}"; |
| 5875 |
else if (GENERAL_REG_P (operands[1])) |
| 5876 |
return "vmovw\t{%k1, %0|%0, %k1}"; |
| 5877 |
else |
| 5878 |
return "vmovw\t{%1, %0|%0, %1}"; |
| 5879 |
|
| 5880 |
case MODE_DF: |
| 5881 |
if (TARGET_AVX && REG_P (operands[0]) && REG_P (operands[1])) |
| 5882 |
return "vmovsd\t{%d1, %0|%0, %d1}"; |
| 5883 |
else |
| 5884 |
return "%vmovsd\t{%1, %0|%0, %1}"; |
| 5885 |
|
| 5886 |
case MODE_SF: |
| 5887 |
if (TARGET_AVX && REG_P (operands[0]) && REG_P (operands[1])) |
| 5888 |
return "vmovss\t{%d1, %0|%0, %d1}"; |
| 5889 |
else |
| 5890 |
return "%vmovss\t{%1, %0|%0, %1}"; |
| 5891 |
|
| 5892 |
case MODE_HF: |
| 5893 |
case MODE_BF: |
| 5894 |
if (REG_P (operands[0]) && REG_P (operands[1])) |
| 5895 |
return "vmovsh\t{%d1, %0|%0, %d1}"; |
| 5896 |
else |
| 5897 |
return "vmovsh\t{%1, %0|%0, %1}"; |
| 5898 |
|
| 5899 |
case MODE_V1DF: |
| 5900 |
gcc_assert (!TARGET_AVX); |
| 5901 |
return "movlpd\t{%1, %0|%0, %1}"; |
| 5902 |
|
| 5903 |
case MODE_V2SF: |
| 5904 |
if (TARGET_AVX && REG_P (operands[0])) |
| 5905 |
return "vmovlps\t{%1, %d0|%d0, %1}"; |
| 5906 |
else |
| 5907 |
return "%vmovlps\t{%1, %0|%0, %1}"; |
| 5908 |
|
| 5909 |
default: |
| 5910 |
gcc_unreachable (); |
| 5911 |
} |
| 5912 |
} |
| 5913 |
|
| 5914 |
/* Returns true if OP contains a symbol reference */ |
| 5915 |
|
| 5916 |
bool |
| 5917 |
symbolic_reference_mentioned_p (rtx op) |
| 5918 |
{ |
| 5919 |
const char *fmt; |
| 5920 |
int i; |
| 5921 |
|
| 5922 |
if (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF) |
| 5923 |
return true; |
| 5924 |
|
| 5925 |
fmt = GET_RTX_FORMAT (GET_CODE (op)); |
| 5926 |
for (i = GET_RTX_LENGTH (GET_CODE (op)) - 1; i >= 0; i--) |
| 5927 |
{ |
| 5928 |
if (fmt[i] == 'E') |
| 5929 |
{ |
| 5930 |
int j; |
| 5931 |
|
| 5932 |
for (j = XVECLEN (op, i) - 1; j >= 0; j--) |
| 5933 |
if (symbolic_reference_mentioned_p (XVECEXP (op, i, j))) |
| 5934 |
return true; |
| 5935 |
} |
| 5936 |
|
| 5937 |
else if (fmt[i] == 'e' && symbolic_reference_mentioned_p (XEXP (op, i))) |
| 5938 |
return true; |
| 5939 |
} |
| 5940 |
|
| 5941 |
return false; |
| 5942 |
} |
| 5943 |
|
| 5944 |
/* Return true if it is appropriate to emit `ret' instructions in the |
| 5945 |
body of a function. Do this only if the epilogue is simple, needing a |
| 5946 |
couple of insns. Prior to reloading, we can't tell how many registers |
| 5947 |
must be saved, so return false then. Return false if there is no frame |
| 5948 |
marker to de-allocate. */ |
| 5949 |
|
| 5950 |
bool |
| 5951 |
ix86_can_use_return_insn_p (void) |
| 5952 |
{ |
| 5953 |
if (ix86_function_ms_hook_prologue (current_function_decl)) |
| 5954 |
return false; |
| 5955 |
|
| 5956 |
if (ix86_function_naked (current_function_decl)) |
| 5957 |
return false; |
| 5958 |
|
| 5959 |
/* Don't use `ret' instruction in interrupt handler. */ |
| 5960 |
if (! reload_completed |
| 5961 |
|| frame_pointer_needed |
| 5962 |
|| cfun->machine->func_type != TYPE_NORMAL) |
| 5963 |
return 0; |
| 5964 |
|
| 5965 |
/* Don't allow more than 32k pop, since that's all we can do |
| 5966 |
with one instruction. */ |
| 5967 |
if (crtl->args.pops_args && crtl->args.size >= 32768) |
| 5968 |
return 0; |
| 5969 |
|
| 5970 |
struct ix86_frame &frame = cfun->machine->frame; |
| 5971 |
return (frame.stack_pointer_offset == UNITS_PER_WORD |
| 5972 |
&& (frame.nregs + frame.nsseregs) == 0); |
| 5973 |
} |
| 5974 |
|
| 5975 |
/* Return stack frame size. get_frame_size () returns used stack slots |
| 5976 |
during compilation, which may be optimized out later. If stack frame |
| 5977 |
is needed, stack_frame_required should be true. */ |
| 5978 |
|
| 5979 |
static HOST_WIDE_INT |
| 5980 |
ix86_get_frame_size (void) |
| 5981 |
{ |
| 5982 |
if (cfun->machine->stack_frame_required) |
| 5983 |
return get_frame_size (); |
| 5984 |
else |
| 5985 |
return 0; |
| 5986 |
} |
| 5987 |
|
| 5988 |
/* Value should be nonzero if functions must have frame pointers. |
| 5989 |
Zero means the frame pointer need not be set up (and parms may |
| 5990 |
be accessed via the stack pointer) in functions that seem suitable. */ |
| 5991 |
|
| 5992 |
static bool |
| 5993 |
ix86_frame_pointer_required (void) |
| 5994 |
{ |
| 5995 |
/* If we accessed previous frames, then the generated code expects |
| 5996 |
to be able to access the saved ebp value in our frame. */ |
| 5997 |
if (cfun->machine->accesses_prev_frame) |
| 5998 |
return true; |
| 5999 |
|
| 6000 |
/* Several x86 os'es need a frame pointer for other reasons, |
| 6001 |
usually pertaining to setjmp. */ |
| 6002 |
if (SUBTARGET_FRAME_POINTER_REQUIRED) |
| 6003 |
return true; |
| 6004 |
|
| 6005 |
/* For older 32-bit runtimes setjmp requires valid frame-pointer. */ |
| 6006 |
if (TARGET_32BIT_MS_ABI && cfun->calls_setjmp) |
| 6007 |
return true; |
| 6008 |
|
| 6009 |
/* Win64 SEH, very large frames need a frame-pointer as maximum stack |
| 6010 |
allocation is 4GB. */ |
| 6011 |
if (TARGET_64BIT_MS_ABI && ix86_get_frame_size () > SEH_MAX_FRAME_SIZE) |
| 6012 |
return true; |
| 6013 |
|
| 6014 |
/* SSE saves require frame-pointer when stack is misaligned. */ |
| 6015 |
if (TARGET_64BIT_MS_ABI && ix86_incoming_stack_boundary < 128) |
| 6016 |
return true; |
| 6017 |
|
| 6018 |
/* In ix86_option_override_internal, TARGET_OMIT_LEAF_FRAME_POINTER |
| 6019 |
turns off the frame pointer by default. Turn it back on now if |
| 6020 |
we've not got a leaf function. */ |
| 6021 |
if (TARGET_OMIT_LEAF_FRAME_POINTER |
| 6022 |
&& (!crtl->is_leaf |
| 6023 |
|| ix86_current_function_calls_tls_descriptor)) |
| 6024 |
return true; |
| 6025 |
|
| 6026 |
/* Several versions of mcount for the x86 assumes that there is a |
| 6027 |
frame, so we cannot allow profiling without a frame pointer. */ |
| 6028 |
if (crtl->profile && !flag_fentry) |
| 6029 |
return true; |
| 6030 |
|
| 6031 |
return false; |
| 6032 |
} |
| 6033 |
|
| 6034 |
/* Record that the current function accesses previous call frames. */ |
| 6035 |
|
| 6036 |
void |
| 6037 |
ix86_setup_frame_addresses (void) |
| 6038 |
{ |
| 6039 |
cfun->machine->accesses_prev_frame = 1; |
| 6040 |
} |
| 6041 |
|
| 6042 |
#if defined(HAVE_GAS_HIDDEN) && (SUPPORTS_ONE_ONLY - 0) |
| 6043 |
# define USE_HIDDEN_LINKONCE 1 |
| 6044 |
#else |
| 6045 |
# define USE_HIDDEN_LINKONCE 0 |
| 6046 |
#endif |
| 6047 |
|
| 6048 |
/* Label count for call and return thunks. It is used to make unique |
| 6049 |
labels in call and return thunks. */ |
| 6050 |
static int indirectlabelno; |
| 6051 |
|
| 6052 |
/* True if call thunk function is needed. */ |
| 6053 |
static bool indirect_thunk_needed = false; |
| 6054 |
|
| 6055 |
/* Bit masks of integer registers, which contain branch target, used |
| 6056 |
by call thunk functions. */ |
| 6057 |
static HARD_REG_SET indirect_thunks_used; |
| 6058 |
|
| 6059 |
/* True if return thunk function is needed. */ |
| 6060 |
static bool indirect_return_needed = false; |
| 6061 |
|
| 6062 |
/* True if return thunk function via CX is needed. */ |
| 6063 |
static bool indirect_return_via_cx; |
| 6064 |
|
| 6065 |
#ifndef INDIRECT_LABEL |
| 6066 |
# define INDIRECT_LABEL "LIND" |
| 6067 |
#endif |
| 6068 |
|
| 6069 |
/* Indicate what prefix is needed for an indirect branch. */ |
| 6070 |
enum indirect_thunk_prefix |
| 6071 |
{ |
| 6072 |
indirect_thunk_prefix_none, |
| 6073 |
indirect_thunk_prefix_nt |
| 6074 |
}; |
| 6075 |
|
| 6076 |
/* Return the prefix needed for an indirect branch INSN. */ |
| 6077 |
|
| 6078 |
enum indirect_thunk_prefix |
| 6079 |
indirect_thunk_need_prefix (rtx_insn *insn) |
| 6080 |
{ |
| 6081 |
enum indirect_thunk_prefix need_prefix; |
| 6082 |
if ((cfun->machine->indirect_branch_type |
| 6083 |
== indirect_branch_thunk_extern) |
| 6084 |
&& ix86_notrack_prefixed_insn_p (insn)) |
| 6085 |
{ |
| 6086 |
/* NOTRACK prefix is only used with external thunk so that it |
| 6087 |
can be properly updated to support CET at run-time. */ |
| 6088 |
need_prefix = indirect_thunk_prefix_nt; |
| 6089 |
} |
| 6090 |
else |
| 6091 |
need_prefix = indirect_thunk_prefix_none; |
| 6092 |
return need_prefix; |
| 6093 |
} |
| 6094 |
|
| 6095 |
/* Fills in the label name that should be used for the indirect thunk. */ |
| 6096 |
|
| 6097 |
static void |
| 6098 |
indirect_thunk_name (char name[32], unsigned int regno, |
| 6099 |
enum indirect_thunk_prefix need_prefix, |
| 6100 |
bool ret_p) |
| 6101 |
{ |
| 6102 |
if (regno != INVALID_REGNUM && regno != CX_REG && ret_p) |
| 6103 |
gcc_unreachable (); |
| 6104 |
|
| 6105 |
if (USE_HIDDEN_LINKONCE) |
| 6106 |
{ |
| 6107 |
const char *prefix; |
| 6108 |
|
| 6109 |
if (need_prefix == indirect_thunk_prefix_nt |
| 6110 |
&& regno != INVALID_REGNUM) |
| 6111 |
{ |
| 6112 |
/* NOTRACK prefix is only used with external thunk via |
| 6113 |
register so that NOTRACK prefix can be added to indirect |
| 6114 |
branch via register to support CET at run-time. */ |
| 6115 |
prefix = "_nt"; |
| 6116 |
} |
| 6117 |
else |
| 6118 |
prefix = ""; |
| 6119 |
|
| 6120 |
const char *ret = ret_p ? "return" : "indirect"; |
| 6121 |
|
| 6122 |
if (regno != INVALID_REGNUM) |
| 6123 |
{ |
| 6124 |
const char *reg_prefix; |
| 6125 |
if (LEGACY_INT_REGNO_P (regno)) |
| 6126 |
reg_prefix = TARGET_64BIT ? "r" : "e"; |
| 6127 |
else |
| 6128 |
reg_prefix = ""; |
| 6129 |
sprintf (name, "__x86_%s_thunk%s_%s%s", |
| 6130 |
ret, prefix, reg_prefix, reg_names[regno]); |
| 6131 |
} |
| 6132 |
else |
| 6133 |
sprintf (name, "__x86_%s_thunk%s", ret, prefix); |
| 6134 |
} |
| 6135 |
else |
| 6136 |
{ |
| 6137 |
if (regno != INVALID_REGNUM) |
| 6138 |
ASM_GENERATE_INTERNAL_LABEL (name, "LITR", regno); |
| 6139 |
else |
| 6140 |
{ |
| 6141 |
if (ret_p) |
| 6142 |
ASM_GENERATE_INTERNAL_LABEL (name, "LRT", 0); |
| 6143 |
else |
| 6144 |
ASM_GENERATE_INTERNAL_LABEL (name, "LIT", 0); |
| 6145 |
} |
| 6146 |
} |
| 6147 |
} |
| 6148 |
|
| 6149 |
/* Output a call and return thunk for indirect branch. If REGNO != -1, |
| 6150 |
the function address is in REGNO and the call and return thunk looks like: |
| 6151 |
|
| 6152 |
call L2 |
| 6153 |
L1: |
| 6154 |
pause |
| 6155 |
lfence |
| 6156 |
jmp L1 |
| 6157 |
L2: |
| 6158 |
mov %REG, (%sp) |
| 6159 |
ret |
| 6160 |
|
| 6161 |
Otherwise, the function address is on the top of stack and the |
| 6162 |
call and return thunk looks like: |
| 6163 |
|
| 6164 |
call L2 |
| 6165 |
L1: |
| 6166 |
pause |
| 6167 |
lfence |
| 6168 |
jmp L1 |
| 6169 |
L2: |
| 6170 |
lea WORD_SIZE(%sp), %sp |
| 6171 |
ret |
| 6172 |
*/ |
| 6173 |
|
| 6174 |
static void |
| 6175 |
output_indirect_thunk (unsigned int regno) |
| 6176 |
{ |
| 6177 |
char indirectlabel1[32]; |
| 6178 |
char indirectlabel2[32]; |
| 6179 |
|
| 6180 |
ASM_GENERATE_INTERNAL_LABEL (indirectlabel1, INDIRECT_LABEL, |
| 6181 |
indirectlabelno++); |
| 6182 |
ASM_GENERATE_INTERNAL_LABEL (indirectlabel2, INDIRECT_LABEL, |
| 6183 |
indirectlabelno++); |
| 6184 |
|
| 6185 |
/* Call */ |
| 6186 |
fputs ("\tcall\t", asm_out_file); |
| 6187 |
assemble_name_raw (asm_out_file, indirectlabel2); |
| 6188 |
fputc ('\n', asm_out_file); |
| 6189 |
|
| 6190 |
ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, indirectlabel1); |
| 6191 |
|
| 6192 |
/* AMD and Intel CPUs prefer each a different instruction as loop filler. |
| 6193 |
Usage of both pause + lfence is compromise solution. */ |
| 6194 |
fprintf (asm_out_file, "\tpause\n\tlfence\n"); |
| 6195 |
|
| 6196 |
/* Jump. */ |
| 6197 |
fputs ("\tjmp\t", asm_out_file); |
| 6198 |
assemble_name_raw (asm_out_file, indirectlabel1); |
| 6199 |
fputc ('\n', asm_out_file); |
| 6200 |
|
| 6201 |
ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, indirectlabel2); |
| 6202 |
|
| 6203 |
/* The above call insn pushed a word to stack. Adjust CFI info. */ |
| 6204 |
if (flag_asynchronous_unwind_tables && dwarf2out_do_frame ()) |
| 6205 |
{ |
| 6206 |
if (! dwarf2out_do_cfi_asm ()) |
| 6207 |
{ |
| 6208 |
dw_cfi_ref xcfi = ggc_cleared_alloc<dw_cfi_node> (); |
| 6209 |
xcfi->dw_cfi_opc = DW_CFA_advance_loc4; |
| 6210 |
xcfi->dw_cfi_oprnd1.dw_cfi_addr = ggc_strdup (indirectlabel2); |
| 6211 |
vec_safe_push (cfun->fde->dw_fde_cfi, xcfi); |
| 6212 |
} |
| 6213 |
dw_cfi_ref xcfi = ggc_cleared_alloc<dw_cfi_node> (); |
| 6214 |
xcfi->dw_cfi_opc = DW_CFA_def_cfa_offset; |
| 6215 |
xcfi->dw_cfi_oprnd1.dw_cfi_offset = 2 * UNITS_PER_WORD; |
| 6216 |
vec_safe_push (cfun->fde->dw_fde_cfi, xcfi); |
| 6217 |
dwarf2out_emit_cfi (xcfi); |
| 6218 |
} |
| 6219 |
|
| 6220 |
if (regno != INVALID_REGNUM) |
| 6221 |
{ |
| 6222 |
/* MOV. */ |
| 6223 |
rtx xops[2]; |
| 6224 |
xops[0] = gen_rtx_MEM (word_mode, stack_pointer_rtx); |
| 6225 |
xops[1] = gen_rtx_REG (word_mode, regno); |
| 6226 |
output_asm_insn ("mov\t{%1, %0|%0, %1}", xops); |
| 6227 |
} |
| 6228 |
else |
| 6229 |
{ |
| 6230 |
/* LEA. */ |
| 6231 |
rtx xops[2]; |
| 6232 |
xops[0] = stack_pointer_rtx; |
| 6233 |
xops[1] = plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD); |
| 6234 |
output_asm_insn ("lea\t{%E1, %0|%0, %E1}", xops); |
| 6235 |
} |
| 6236 |
|
| 6237 |
fputs ("\tret\n", asm_out_file); |
| 6238 |
if ((ix86_harden_sls & harden_sls_return)) |
| 6239 |
fputs ("\tint3\n", asm_out_file); |
| 6240 |
} |
| 6241 |
|
| 6242 |
/* Output a funtion with a call and return thunk for indirect branch. |
| 6243 |
If REGNO != INVALID_REGNUM, the function address is in REGNO. |
| 6244 |
Otherwise, the function address is on the top of stack. Thunk is |
| 6245 |
used for function return if RET_P is true. */ |
| 6246 |
|
| 6247 |
static void |
| 6248 |
output_indirect_thunk_function (enum indirect_thunk_prefix need_prefix, |
| 6249 |
unsigned int regno, bool ret_p) |
| 6250 |
{ |
| 6251 |
char name[32]; |
| 6252 |
tree decl; |
| 6253 |
|
| 6254 |
/* Create __x86_indirect_thunk. */ |
| 6255 |
indirect_thunk_name (name, regno, need_prefix, ret_p); |
| 6256 |
decl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL, |
| 6257 |
get_identifier (name), |
| 6258 |
build_function_type_list (void_type_node, NULL_TREE)); |
| 6259 |
DECL_RESULT (decl) = build_decl (BUILTINS_LOCATION, RESULT_DECL, |
| 6260 |
NULL_TREE, void_type_node); |
| 6261 |
TREE_PUBLIC (decl) = 1; |
| 6262 |
TREE_STATIC (decl) = 1; |
| 6263 |
DECL_IGNORED_P (decl) = 1; |
| 6264 |
|
| 6265 |
#if TARGET_MACHO |
| 6266 |
if (TARGET_MACHO) |
| 6267 |
{ |
| 6268 |
switch_to_section (darwin_sections[picbase_thunk_section]); |
| 6269 |
fputs ("\t.weak_definition\t", asm_out_file); |
| 6270 |
assemble_name (asm_out_file, name); |
| 6271 |
fputs ("\n\t.private_extern\t", asm_out_file); |
| 6272 |
assemble_name (asm_out_file, name); |
| 6273 |
putc ('\n', asm_out_file); |
| 6274 |
ASM_OUTPUT_LABEL (asm_out_file, name); |
| 6275 |
DECL_WEAK (decl) = 1; |
| 6276 |
} |
| 6277 |
else |
| 6278 |
#endif |
| 6279 |
if (USE_HIDDEN_LINKONCE) |
| 6280 |
{ |
| 6281 |
cgraph_node::create (decl)->set_comdat_group (DECL_ASSEMBLER_NAME (decl)); |
| 6282 |
|
| 6283 |
targetm.asm_out.unique_section (decl, 0); |
| 6284 |
switch_to_section (get_named_section (decl, NULL, 0)); |
| 6285 |
|
| 6286 |
targetm.asm_out.globalize_label (asm_out_file, name); |
| 6287 |
fputs ("\t.hidden\t", asm_out_file); |
| 6288 |
assemble_name (asm_out_file, name); |
| 6289 |
putc ('\n', asm_out_file); |
| 6290 |
ASM_DECLARE_FUNCTION_NAME (asm_out_file, name, decl); |
| 6291 |
} |
| 6292 |
else |
| 6293 |
{ |
| 6294 |
switch_to_section (text_section); |
| 6295 |
ASM_OUTPUT_LABEL (asm_out_file, name); |
| 6296 |
} |
| 6297 |
|
| 6298 |
DECL_INITIAL (decl) = make_node (BLOCK); |
| 6299 |
current_function_decl = decl; |
| 6300 |
allocate_struct_function (decl, false); |
| 6301 |
init_function_start (decl); |
| 6302 |
/* We're about to hide the function body from callees of final_* by |
| 6303 |
emitting it directly; tell them we're a thunk, if they care. */ |
| 6304 |
cfun->is_thunk = true; |
| 6305 |
first_function_block_is_cold = false; |
| 6306 |
/* Make sure unwind info is emitted for the thunk if needed. */ |
| 6307 |
final_start_function (emit_barrier (), asm_out_file, 1); |
| 6308 |
|
| 6309 |
output_indirect_thunk (regno); |
| 6310 |
|
| 6311 |
final_end_function (); |
| 6312 |
init_insn_lengths (); |
| 6313 |
free_after_compilation (cfun); |
| 6314 |
set_cfun (NULL); |
| 6315 |
current_function_decl = NULL; |
| 6316 |
} |
| 6317 |
|
| 6318 |
static int pic_labels_used; |
| 6319 |
|
| 6320 |
/* Fills in the label name that should be used for a pc thunk for |
| 6321 |
the given register. */ |
| 6322 |
|
| 6323 |
static void |
| 6324 |
get_pc_thunk_name (char name[32], unsigned int regno) |
| 6325 |
{ |
| 6326 |
gcc_assert (!TARGET_64BIT); |
| 6327 |
|
| 6328 |
if (USE_HIDDEN_LINKONCE) |
| 6329 |
sprintf (name, "__x86.get_pc_thunk.%s", reg_names[regno]); |
| 6330 |
else |
| 6331 |
ASM_GENERATE_INTERNAL_LABEL (name, "LPR", regno); |
| 6332 |
} |
| 6333 |
|
| 6334 |
|
| 6335 |
/* This function generates code for -fpic that loads %ebx with |
| 6336 |
the return address of the caller and then returns. */ |
| 6337 |
|
| 6338 |
static void |
| 6339 |
ix86_code_end (void) |
| 6340 |
{ |
| 6341 |
rtx xops[2]; |
| 6342 |
unsigned int regno; |
| 6343 |
|
| 6344 |
if (indirect_return_needed) |
| 6345 |
output_indirect_thunk_function (indirect_thunk_prefix_none, |
| 6346 |
INVALID_REGNUM, true); |
| 6347 |
if (indirect_return_via_cx) |
| 6348 |
output_indirect_thunk_function (indirect_thunk_prefix_none, |
| 6349 |
CX_REG, true); |
| 6350 |
if (indirect_thunk_needed) |
| 6351 |
output_indirect_thunk_function (indirect_thunk_prefix_none, |
| 6352 |
INVALID_REGNUM, false); |
| 6353 |
|
| 6354 |
for (regno = FIRST_REX_INT_REG; regno <= LAST_REX_INT_REG; regno++) |
| 6355 |
{ |
| 6356 |
if (TEST_HARD_REG_BIT (indirect_thunks_used, regno)) |
| 6357 |
output_indirect_thunk_function (indirect_thunk_prefix_none, |
| 6358 |
regno, false); |
| 6359 |
} |
| 6360 |
|
| 6361 |
for (regno = FIRST_REX2_INT_REG; regno <= LAST_REX2_INT_REG; regno++) |
| 6362 |
{ |
| 6363 |
if (TEST_HARD_REG_BIT (indirect_thunks_used, regno)) |
| 6364 |
output_indirect_thunk_function (indirect_thunk_prefix_none, |
| 6365 |
regno, false); |
| 6366 |
} |
| 6367 |
|
| 6368 |
for (regno = FIRST_INT_REG; regno <= LAST_INT_REG; regno++) |
| 6369 |
{ |
| 6370 |
char name[32]; |
| 6371 |
tree decl; |
| 6372 |
|
| 6373 |
if (TEST_HARD_REG_BIT (indirect_thunks_used, regno)) |
| 6374 |
output_indirect_thunk_function (indirect_thunk_prefix_none, |
| 6375 |
regno, false); |
| 6376 |
|
| 6377 |
if (!(pic_labels_used & (1 << regno))) |
| 6378 |
continue; |
| 6379 |
|
| 6380 |
get_pc_thunk_name (name, regno); |
| 6381 |
|
| 6382 |
decl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL, |
| 6383 |
get_identifier (name), |
| 6384 |
build_function_type_list (void_type_node, NULL_TREE)); |
| 6385 |
DECL_RESULT (decl) = build_decl (BUILTINS_LOCATION, RESULT_DECL, |
| 6386 |
NULL_TREE, void_type_node); |
| 6387 |
TREE_PUBLIC (decl) = 1; |
| 6388 |
TREE_STATIC (decl) = 1; |
| 6389 |
DECL_IGNORED_P (decl) = 1; |
| 6390 |
|
| 6391 |
#if TARGET_MACHO |
| 6392 |
if (TARGET_MACHO) |
| 6393 |
{ |
| 6394 |
switch_to_section (darwin_sections[picbase_thunk_section]); |
| 6395 |
fputs ("\t.weak_definition\t", asm_out_file); |
| 6396 |
assemble_name (asm_out_file, name); |
| 6397 |
fputs ("\n\t.private_extern\t", asm_out_file); |
| 6398 |
assemble_name (asm_out_file, name); |
| 6399 |
putc ('\n', asm_out_file); |
| 6400 |
ASM_OUTPUT_LABEL (asm_out_file, name); |
| 6401 |
DECL_WEAK (decl) = 1; |
| 6402 |
} |
| 6403 |
else |
| 6404 |
#endif |
| 6405 |
if (USE_HIDDEN_LINKONCE) |
| 6406 |
{ |
| 6407 |
cgraph_node::create (decl)->set_comdat_group (DECL_ASSEMBLER_NAME (decl)); |
| 6408 |
|
| 6409 |
targetm.asm_out.unique_section (decl, 0); |
| 6410 |
switch_to_section (get_named_section (decl, NULL, 0)); |
| 6411 |
|
| 6412 |
targetm.asm_out.globalize_label (asm_out_file, name); |
| 6413 |
fputs ("\t.hidden\t", asm_out_file); |
| 6414 |
assemble_name (asm_out_file, name); |
| 6415 |
putc ('\n', asm_out_file); |
| 6416 |
ASM_DECLARE_FUNCTION_NAME (asm_out_file, name, decl); |
| 6417 |
} |
| 6418 |
else |
| 6419 |
{ |
| 6420 |
switch_to_section (text_section); |
| 6421 |
ASM_OUTPUT_LABEL (asm_out_file, name); |
| 6422 |
} |
| 6423 |
|
| 6424 |
DECL_INITIAL (decl) = make_node (BLOCK); |
| 6425 |
current_function_decl = decl; |
| 6426 |
allocate_struct_function (decl, false); |
| 6427 |
init_function_start (decl); |
| 6428 |
/* We're about to hide the function body from callees of final_* by |
| 6429 |
emitting it directly; tell them we're a thunk, if they care. */ |
| 6430 |
cfun->is_thunk = true; |
| 6431 |
first_function_block_is_cold = false; |
| 6432 |
/* Make sure unwind info is emitted for the thunk if needed. */ |
| 6433 |
final_start_function (emit_barrier (), asm_out_file, 1); |
| 6434 |
|
| 6435 |
/* Pad stack IP move with 4 instructions (two NOPs count |
| 6436 |
as one instruction). */ |
| 6437 |
if (TARGET_PAD_SHORT_FUNCTION) |
| 6438 |
{ |
| 6439 |
int i = 8; |
| 6440 |
|
| 6441 |
while (i--) |
| 6442 |
fputs ("\tnop\n", asm_out_file); |
| 6443 |
} |
| 6444 |
|
| 6445 |
xops[0] = gen_rtx_REG (Pmode, regno); |
| 6446 |
xops[1] = gen_rtx_MEM (Pmode, stack_pointer_rtx); |
| 6447 |
output_asm_insn ("mov%z0\t{%1, %0|%0, %1}", xops); |
| 6448 |
fputs ("\tret\n", asm_out_file); |
| 6449 |
final_end_function (); |
| 6450 |
init_insn_lengths (); |
| 6451 |
free_after_compilation (cfun); |
| 6452 |
set_cfun (NULL); |
| 6453 |
current_function_decl = NULL; |
| 6454 |
} |
| 6455 |
|
| 6456 |
if (flag_split_stack) |
| 6457 |
file_end_indicate_split_stack (); |
| 6458 |
} |
| 6459 |
|
| 6460 |
/* Emit code for the SET_GOT patterns. */ |
| 6461 |
|
| 6462 |
const char * |
| 6463 |
output_set_got (rtx dest, rtx label) |
| 6464 |
{ |
| 6465 |
rtx xops[3]; |
| 6466 |
|
| 6467 |
xops[0] = dest; |
| 6468 |
|
| 6469 |
if (TARGET_VXWORKS_RTP && flag_pic) |
| 6470 |
{ |
| 6471 |
/* Load (*VXWORKS_GOTT_BASE) into the PIC register. */ |
| 6472 |
xops[2] = gen_rtx_MEM (Pmode, |
| 6473 |
gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_BASE)); |
| 6474 |
output_asm_insn ("mov{l}\t{%2, %0|%0, %2}", xops); |
| 6475 |
|
| 6476 |
/* Load (*VXWORKS_GOTT_BASE)[VXWORKS_GOTT_INDEX] into the PIC register. |
| 6477 |
Use %P and a local symbol in order to print VXWORKS_GOTT_INDEX as |
| 6478 |
an unadorned address. */ |
| 6479 |
xops[2] = gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_INDEX); |
| 6480 |
SYMBOL_REF_FLAGS (xops[2]) |= SYMBOL_FLAG_LOCAL; |
| 6481 |
output_asm_insn ("mov{l}\t{%P2(%0), %0|%0, DWORD PTR %P2[%0]}", xops); |
| 6482 |
return ""; |
| 6483 |
} |
| 6484 |
|
| 6485 |
xops[1] = gen_rtx_SYMBOL_REF (Pmode, GOT_SYMBOL_NAME); |
| 6486 |
|
| 6487 |
if (flag_pic) |
| 6488 |
{ |
| 6489 |
char name[32]; |
| 6490 |
get_pc_thunk_name (name, REGNO (dest)); |
| 6491 |
pic_labels_used |= 1 << REGNO (dest); |
| 6492 |
|
| 6493 |
xops[2] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (name)); |
| 6494 |
xops[2] = gen_rtx_MEM (QImode, xops[2]); |
| 6495 |
output_asm_insn ("%!call\t%X2", xops); |
| 6496 |
|
| 6497 |
#if TARGET_MACHO |
| 6498 |
/* Output the Mach-O "canonical" pic base label name ("Lxx$pb") here. |
| 6499 |
This is what will be referenced by the Mach-O PIC subsystem. */ |
| 6500 |
if (machopic_should_output_picbase_label () || !label) |
| 6501 |
ASM_OUTPUT_LABEL (asm_out_file, MACHOPIC_FUNCTION_BASE_NAME); |
| 6502 |
|
| 6503 |
/* When we are restoring the pic base at the site of a nonlocal label, |
| 6504 |
and we decided to emit the pic base above, we will still output a |
| 6505 |
local label used for calculating the correction offset (even though |
| 6506 |
the offset will be 0 in that case). */ |
| 6507 |
if (label) |
| 6508 |
targetm.asm_out.internal_label (asm_out_file, "L", |
| 6509 |
CODE_LABEL_NUMBER (label)); |
| 6510 |
#endif |
| 6511 |
} |
| 6512 |
else |
| 6513 |
{ |
| 6514 |
if (TARGET_MACHO) |
| 6515 |
/* We don't need a pic base, we're not producing pic. */ |
| 6516 |
gcc_unreachable (); |
| 6517 |
|
| 6518 |
xops[2] = gen_rtx_LABEL_REF (Pmode, label ? label : gen_label_rtx ()); |
| 6519 |
output_asm_insn ("mov%z0\t{%2, %0|%0, %2}", xops); |
| 6520 |
targetm.asm_out.internal_label (asm_out_file, "L", |
| 6521 |
CODE_LABEL_NUMBER (XEXP (xops[2], 0))); |
| 6522 |
} |
| 6523 |
|
| 6524 |
if (!TARGET_MACHO) |
| 6525 |
output_asm_insn ("add%z0\t{%1, %0|%0, %1}", xops); |
| 6526 |
|
| 6527 |
return ""; |
| 6528 |
} |
| 6529 |
|
| 6530 |
/* Generate an "push" pattern for input ARG. */ |
| 6531 |
|
| 6532 |
rtx |
| 6533 |
gen_push (rtx arg, bool ppx_p) |
| 6534 |
{ |
| 6535 |
struct machine_function *m = cfun->machine; |
| 6536 |
|
| 6537 |
if (m->fs.cfa_reg == stack_pointer_rtx) |
| 6538 |
m->fs.cfa_offset += UNITS_PER_WORD; |
| 6539 |
m->fs.sp_offset += UNITS_PER_WORD; |
| 6540 |
|
| 6541 |
if (REG_P (arg) && GET_MODE (arg) != word_mode) |
| 6542 |
arg = gen_rtx_REG (word_mode, REGNO (arg)); |
| 6543 |
|
| 6544 |
rtx stack = gen_rtx_MEM (word_mode, |
| 6545 |
gen_rtx_PRE_DEC (Pmode, |
| 6546 |
stack_pointer_rtx)); |
| 6547 |
return ppx_p ? gen_pushp_di (stack, arg) : gen_rtx_SET (stack, arg); |
| 6548 |
} |
| 6549 |
|
| 6550 |
rtx |
| 6551 |
gen_pushfl (void) |
| 6552 |
{ |
| 6553 |
struct machine_function *m = cfun->machine; |
| 6554 |
rtx flags, mem; |
| 6555 |
|
| 6556 |
if (m->fs.cfa_reg == stack_pointer_rtx) |
| 6557 |
m->fs.cfa_offset += UNITS_PER_WORD; |
| 6558 |
m->fs.sp_offset += UNITS_PER_WORD; |
| 6559 |
|
| 6560 |
flags = gen_rtx_REG (CCmode, FLAGS_REG); |
| 6561 |
|
| 6562 |
mem = gen_rtx_MEM (word_mode, |
| 6563 |
gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx)); |
| 6564 |
|
| 6565 |
return gen_pushfl2 (word_mode, mem, flags); |
| 6566 |
} |
| 6567 |
|
| 6568 |
/* Generate an "pop" pattern for input ARG. */ |
| 6569 |
|
| 6570 |
rtx |
| 6571 |
gen_pop (rtx arg, bool ppx_p) |
| 6572 |
{ |
| 6573 |
if (REG_P (arg) && GET_MODE (arg) != word_mode) |
| 6574 |
arg = gen_rtx_REG (word_mode, REGNO (arg)); |
| 6575 |
|
| 6576 |
rtx stack = gen_rtx_MEM (word_mode, |
| 6577 |
gen_rtx_POST_INC (Pmode, |
| 6578 |
stack_pointer_rtx)); |
| 6579 |
|
| 6580 |
return ppx_p ? gen_popp_di (arg, stack) : gen_rtx_SET (arg, stack); |
| 6581 |
} |
| 6582 |
|
| 6583 |
rtx |
| 6584 |
gen_popfl (void) |
| 6585 |
{ |
| 6586 |
rtx flags, mem; |
| 6587 |
|
| 6588 |
flags = gen_rtx_REG (CCmode, FLAGS_REG); |
| 6589 |
|
| 6590 |
mem = gen_rtx_MEM (word_mode, |
| 6591 |
gen_rtx_POST_INC (Pmode, stack_pointer_rtx)); |
| 6592 |
|
| 6593 |
return gen_popfl1 (word_mode, flags, mem); |
| 6594 |
} |
| 6595 |
|
| 6596 |
/* Generate a "push2" pattern for input ARG. */ |
| 6597 |
rtx |
| 6598 |
gen_push2 (rtx mem, rtx reg1, rtx reg2, bool ppx_p = false) |
| 6599 |
{ |
| 6600 |
struct machine_function *m = cfun->machine; |
| 6601 |
const int offset = UNITS_PER_WORD * 2; |
| 6602 |
|
| 6603 |
if (m->fs.cfa_reg == stack_pointer_rtx) |
| 6604 |
m->fs.cfa_offset += offset; |
| 6605 |
m->fs.sp_offset += offset; |
| 6606 |
|
| 6607 |
if (REG_P (reg1) && GET_MODE (reg1) != word_mode) |
| 6608 |
reg1 = gen_rtx_REG (word_mode, REGNO (reg1)); |
| 6609 |
|
| 6610 |
if (REG_P (reg2) && GET_MODE (reg2) != word_mode) |
| 6611 |
reg2 = gen_rtx_REG (word_mode, REGNO (reg2)); |
| 6612 |
|
| 6613 |
return ppx_p ? gen_push2p_di (mem, reg1, reg2) |
| 6614 |
: gen_push2_di (mem, reg1, reg2); |
| 6615 |
} |
| 6616 |
|
| 6617 |
/* Return >= 0 if there is an unused call-clobbered register available |
| 6618 |
for the entire function. */ |
| 6619 |
|
| 6620 |
static unsigned int |
| 6621 |
ix86_select_alt_pic_regnum (void) |
| 6622 |
{ |
| 6623 |
if (ix86_use_pseudo_pic_reg ()) |
| 6624 |
return INVALID_REGNUM; |
| 6625 |
|
| 6626 |
if (crtl->is_leaf |
| 6627 |
&& !crtl->profile |
| 6628 |
&& !ix86_current_function_calls_tls_descriptor) |
| 6629 |
{ |
| 6630 |
int i, drap; |
| 6631 |
/* Can't use the same register for both PIC and DRAP. */ |
| 6632 |
if (crtl->drap_reg) |
| 6633 |
drap = REGNO (crtl->drap_reg); |
| 6634 |
else |
| 6635 |
drap = -1; |
| 6636 |
for (i = 2; i >= 0; --i) |
| 6637 |
if (i != drap && !df_regs_ever_live_p (i)) |
| 6638 |
return i; |
| 6639 |
} |
| 6640 |
|
| 6641 |
return INVALID_REGNUM; |
| 6642 |
} |
| 6643 |
|
| 6644 |
/* Return true if REGNO is used by the epilogue. */ |
| 6645 |
|
| 6646 |
bool |
| 6647 |
ix86_epilogue_uses (int regno) |
| 6648 |
{ |
| 6649 |
/* If there are no caller-saved registers, we preserve all registers, |
| 6650 |
except for MMX and x87 registers which aren't supported when saving |
| 6651 |
and restoring registers. Don't explicitly save SP register since |
| 6652 |
it is always preserved. */ |
| 6653 |
return (epilogue_completed |
| 6654 |
&& (cfun->machine->call_saved_registers |
| 6655 |
== TYPE_NO_CALLER_SAVED_REGISTERS) |
| 6656 |
&& !fixed_regs[regno] |
| 6657 |
&& !STACK_REGNO_P (regno) |
| 6658 |
&& !MMX_REGNO_P (regno)); |
| 6659 |
} |
| 6660 |
|
| 6661 |
/* Return nonzero if register REGNO can be used as a scratch register |
| 6662 |
in peephole2. */ |
| 6663 |
|
| 6664 |
static bool |
| 6665 |
ix86_hard_regno_scratch_ok (unsigned int regno) |
| 6666 |
{ |
| 6667 |
/* If there are no caller-saved registers, we can't use any register |
| 6668 |
as a scratch register after epilogue and use REGNO as scratch |
| 6669 |
register only if it has been used before to avoid saving and |
| 6670 |
restoring it. */ |
| 6671 |
return ((cfun->machine->call_saved_registers |
| 6672 |
!= TYPE_NO_CALLER_SAVED_REGISTERS) |
| 6673 |
|| (!epilogue_completed |
| 6674 |
&& df_regs_ever_live_p (regno))); |
| 6675 |
} |
| 6676 |
|
| 6677 |
/* Return TRUE if we need to save REGNO. */ |
| 6678 |
|
| 6679 |
bool |
| 6680 |
ix86_save_reg (unsigned int regno, bool maybe_eh_return, bool ignore_outlined) |
| 6681 |
{ |
| 6682 |
rtx reg; |
| 6683 |
|
| 6684 |
switch (cfun->machine->call_saved_registers) |
| 6685 |
{ |
| 6686 |
case TYPE_DEFAULT_CALL_SAVED_REGISTERS: |
| 6687 |
break; |
| 6688 |
|
| 6689 |
case TYPE_NO_CALLER_SAVED_REGISTERS: |
| 6690 |
/* If there are no caller-saved registers, we preserve all |
| 6691 |
registers, except for MMX and x87 registers which aren't |
| 6692 |
supported when saving and restoring registers. Don't |
| 6693 |
explicitly save SP register since it is always preserved. |
| 6694 |
|
| 6695 |
Don't preserve registers used for function return value. */ |
| 6696 |
reg = crtl->return_rtx; |
| 6697 |
if (reg) |
| 6698 |
{ |
| 6699 |
unsigned int i = REGNO (reg); |
| 6700 |
unsigned int nregs = REG_NREGS (reg); |
| 6701 |
while (nregs-- > 0) |
| 6702 |
if ((i + nregs) == regno) |
| 6703 |
return false; |
| 6704 |
} |
| 6705 |
|
| 6706 |
return (df_regs_ever_live_p (regno) |
| 6707 |
&& !fixed_regs[regno] |
| 6708 |
&& !STACK_REGNO_P (regno) |
| 6709 |
&& !MMX_REGNO_P (regno) |
| 6710 |
&& (regno != HARD_FRAME_POINTER_REGNUM |
| 6711 |
|| !frame_pointer_needed)); |
| 6712 |
|
| 6713 |
case TYPE_NO_CALLEE_SAVED_REGISTERS: |
| 6714 |
return false; |
| 6715 |
|
| 6716 |
case TYPE_NO_CALLEE_SAVED_REGISTERS_EXCEPT_BP: |
| 6717 |
if (regno != HARD_FRAME_POINTER_REGNUM) |
| 6718 |
return false; |
| 6719 |
break; |
| 6720 |
} |
| 6721 |
|
| 6722 |
if (regno == REAL_PIC_OFFSET_TABLE_REGNUM |
| 6723 |
&& pic_offset_table_rtx) |
| 6724 |
{ |
| 6725 |
if (ix86_use_pseudo_pic_reg ()) |
| 6726 |
{ |
| 6727 |
/* REAL_PIC_OFFSET_TABLE_REGNUM used by call to |
| 6728 |
_mcount in prologue. */ |
| 6729 |
if (!TARGET_64BIT && flag_pic && crtl->profile) |
| 6730 |
return true; |
| 6731 |
} |
| 6732 |
else if (df_regs_ever_live_p (REAL_PIC_OFFSET_TABLE_REGNUM) |
| 6733 |
|| crtl->profile |
| 6734 |
|| crtl->calls_eh_return |
| 6735 |
|| crtl->uses_const_pool |
| 6736 |
|| cfun->has_nonlocal_label) |
| 6737 |
return ix86_select_alt_pic_regnum () == INVALID_REGNUM; |
| 6738 |
} |
| 6739 |
|
| 6740 |
if (crtl->calls_eh_return && maybe_eh_return) |
| 6741 |
{ |
| 6742 |
unsigned i; |
| 6743 |
for (i = 0; ; i++) |
| 6744 |
{ |
| 6745 |
unsigned test = EH_RETURN_DATA_REGNO (i); |
| 6746 |
if (test == INVALID_REGNUM) |
| 6747 |
break; |
| 6748 |
if (test == regno) |
| 6749 |
return true; |
| 6750 |
} |
| 6751 |
} |
| 6752 |
|
| 6753 |
if (ignore_outlined && cfun->machine->call_ms2sysv) |
| 6754 |
{ |
| 6755 |
unsigned count = cfun->machine->call_ms2sysv_extra_regs |
| 6756 |
+ xlogue_layout::MIN_REGS; |
| 6757 |
if (xlogue_layout::is_stub_managed_reg (regno, count)) |
| 6758 |
return false; |
| 6759 |
} |
| 6760 |
|
| 6761 |
if (crtl->drap_reg |
| 6762 |
&& regno == REGNO (crtl->drap_reg) |
| 6763 |
&& !cfun->machine->no_drap_save_restore) |
| 6764 |
return true; |
| 6765 |
|
| 6766 |
return (df_regs_ever_live_p (regno) |
| 6767 |
&& !call_used_or_fixed_reg_p (regno) |
| 6768 |
&& (regno != HARD_FRAME_POINTER_REGNUM || !frame_pointer_needed)); |
| 6769 |
} |
| 6770 |
|
| 6771 |
/* Return number of saved general prupose registers. */ |
| 6772 |
|
| 6773 |
static int |
| 6774 |
ix86_nsaved_regs (void) |
| 6775 |
{ |
| 6776 |
int nregs = 0; |
| 6777 |
int regno; |
| 6778 |
|
| 6779 |
for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) |
| 6780 |
if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, true, true)) |
| 6781 |
nregs ++; |
| 6782 |
return nregs; |
| 6783 |
} |
| 6784 |
|
| 6785 |
/* Return number of saved SSE registers. */ |
| 6786 |
|
| 6787 |
static int |
| 6788 |
ix86_nsaved_sseregs (void) |
| 6789 |
{ |
| 6790 |
int nregs = 0; |
| 6791 |
int regno; |
| 6792 |
|
| 6793 |
if (!TARGET_64BIT_MS_ABI) |
| 6794 |
return 0; |
| 6795 |
for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) |
| 6796 |
if (SSE_REGNO_P (regno) && ix86_save_reg (regno, true, true)) |
| 6797 |
nregs ++; |
| 6798 |
return nregs; |
| 6799 |
} |
| 6800 |
|
| 6801 |
/* Given FROM and TO register numbers, say whether this elimination is |
| 6802 |
allowed. If stack alignment is needed, we can only replace argument |
| 6803 |
pointer with hard frame pointer, or replace frame pointer with stack |
| 6804 |
pointer. Otherwise, frame pointer elimination is automatically |
| 6805 |
handled and all other eliminations are valid. */ |
| 6806 |
|
| 6807 |
static bool |
| 6808 |
ix86_can_eliminate (const int from, const int to) |
| 6809 |
{ |
| 6810 |
if (stack_realign_fp) |
| 6811 |
return ((from == ARG_POINTER_REGNUM |
| 6812 |
&& to == HARD_FRAME_POINTER_REGNUM) |
| 6813 |
|| (from == FRAME_POINTER_REGNUM |
| 6814 |
&& to == STACK_POINTER_REGNUM)); |
| 6815 |
else |
| 6816 |
return to == STACK_POINTER_REGNUM ? !frame_pointer_needed : true; |
| 6817 |
} |
| 6818 |
|
| 6819 |
/* Return the offset between two registers, one to be eliminated, and the other |
| 6820 |
its replacement, at the start of a routine. */ |
| 6821 |
|
| 6822 |
HOST_WIDE_INT |
| 6823 |
ix86_initial_elimination_offset (int from, int to) |
| 6824 |
{ |
| 6825 |
struct ix86_frame &frame = cfun->machine->frame; |
| 6826 |
|
| 6827 |
if (from == ARG_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM) |
| 6828 |
return frame.hard_frame_pointer_offset; |
| 6829 |
else if (from == FRAME_POINTER_REGNUM |
| 6830 |
&& to == HARD_FRAME_POINTER_REGNUM) |
| 6831 |
return frame.hard_frame_pointer_offset - frame.frame_pointer_offset; |
| 6832 |
else |
| 6833 |
{ |
| 6834 |
gcc_assert (to == STACK_POINTER_REGNUM); |
| 6835 |
|
| 6836 |
if (from == ARG_POINTER_REGNUM) |
| 6837 |
return frame.stack_pointer_offset; |
| 6838 |
|
| 6839 |
gcc_assert (from == FRAME_POINTER_REGNUM); |
| 6840 |
return frame.stack_pointer_offset - frame.frame_pointer_offset; |
| 6841 |
} |
| 6842 |
} |
| 6843 |
|
| 6844 |
/* Emits a warning for unsupported msabi to sysv pro/epilogues. */ |
| 6845 |
void |
| 6846 |
warn_once_call_ms2sysv_xlogues (const char *feature) |
| 6847 |
{ |
| 6848 |
static bool warned_once = false; |
| 6849 |
if (!warned_once) |
| 6850 |
{ |
| 6851 |
warning (0, "%<-mcall-ms2sysv-xlogues%> is not compatible with %s", |
| 6852 |
feature); |
| 6853 |
warned_once = true; |
| 6854 |
} |
| 6855 |
} |
| 6856 |
|
| 6857 |
/* Return the probing interval for -fstack-clash-protection. */ |
| 6858 |
|
| 6859 |
static HOST_WIDE_INT |
| 6860 |
get_probe_interval (void) |
| 6861 |
{ |
| 6862 |
if (flag_stack_clash_protection) |
| 6863 |
return (HOST_WIDE_INT_1U |
| 6864 |
<< param_stack_clash_protection_probe_interval); |
| 6865 |
else |
| 6866 |
return (HOST_WIDE_INT_1U << STACK_CHECK_PROBE_INTERVAL_EXP); |
| 6867 |
} |
| 6868 |
|
| 6869 |
/* When using -fsplit-stack, the allocation routines set a field in |
| 6870 |
the TCB to the bottom of the stack plus this much space, measured |
| 6871 |
in bytes. */ |
| 6872 |
|
| 6873 |
#define SPLIT_STACK_AVAILABLE 256 |
| 6874 |
|
| 6875 |
/* Return true if push2/pop2 can be generated. */ |
| 6876 |
|
| 6877 |
static bool |
| 6878 |
ix86_can_use_push2pop2 (void) |
| 6879 |
{ |
| 6880 |
/* Use push2/pop2 only if the incoming stack is 16-byte aligned. */ |
| 6881 |
unsigned int incoming_stack_boundary |
| 6882 |
= (crtl->parm_stack_boundary > ix86_incoming_stack_boundary |
| 6883 |
? crtl->parm_stack_boundary : ix86_incoming_stack_boundary); |
| 6884 |
return incoming_stack_boundary % 128 == 0; |
| 6885 |
} |
| 6886 |
|
| 6887 |
/* Helper function to determine whether push2/pop2 can be used in prologue or |
| 6888 |
epilogue for register save/restore. */ |
| 6889 |
static bool |
| 6890 |
ix86_pro_and_epilogue_can_use_push2pop2 (int nregs) |
| 6891 |
{ |
| 6892 |
if (!ix86_can_use_push2pop2 ()) |
| 6893 |
return false; |
| 6894 |
int aligned = cfun->machine->fs.sp_offset % 16 == 0; |
| 6895 |
return TARGET_APX_PUSH2POP2 |
| 6896 |
&& !cfun->machine->frame.save_regs_using_mov |
| 6897 |
&& cfun->machine->func_type == TYPE_NORMAL |
| 6898 |
&& (nregs + aligned) >= 3; |
| 6899 |
} |
| 6900 |
|
| 6901 |
/* Fill structure ix86_frame about frame of currently computed function. */ |
| 6902 |
|
| 6903 |
static void |
| 6904 |
ix86_compute_frame_layout (void) |
| 6905 |
{ |
| 6906 |
struct ix86_frame *frame = &cfun->machine->frame; |
| 6907 |
struct machine_function *m = cfun->machine; |
| 6908 |
unsigned HOST_WIDE_INT stack_alignment_needed; |
| 6909 |
HOST_WIDE_INT offset; |
| 6910 |
unsigned HOST_WIDE_INT preferred_alignment; |
| 6911 |
HOST_WIDE_INT size = ix86_get_frame_size (); |
| 6912 |
HOST_WIDE_INT to_allocate; |
| 6913 |
|
| 6914 |
/* m->call_ms2sysv is initially enabled in ix86_expand_call for all 64-bit |
| 6915 |
* ms_abi functions that call a sysv function. We now need to prune away |
| 6916 |
* cases where it should be disabled. */ |
| 6917 |
if (TARGET_64BIT && m->call_ms2sysv) |
| 6918 |
{ |
| 6919 |
gcc_assert (TARGET_64BIT_MS_ABI); |
| 6920 |
gcc_assert (TARGET_CALL_MS2SYSV_XLOGUES); |
| 6921 |
gcc_assert (!TARGET_SEH); |
| 6922 |
gcc_assert (TARGET_SSE); |
| 6923 |
gcc_assert (!ix86_using_red_zone ()); |
| 6924 |
|
| 6925 |
if (crtl->calls_eh_return) |
| 6926 |
{ |
| 6927 |
gcc_assert (!reload_completed); |
| 6928 |
m->call_ms2sysv = false; |
| 6929 |
warn_once_call_ms2sysv_xlogues ("__builtin_eh_return"); |
| 6930 |
} |
| 6931 |
|
| 6932 |
else if (ix86_static_chain_on_stack) |
| 6933 |
{ |
| 6934 |
gcc_assert (!reload_completed); |
| 6935 |
m->call_ms2sysv = false; |
| 6936 |
warn_once_call_ms2sysv_xlogues ("static call chains"); |
| 6937 |
} |
| 6938 |
|
| 6939 |
/* Finally, compute which registers the stub will manage. */ |
| 6940 |
else |
| 6941 |
{ |
| 6942 |
unsigned count = xlogue_layout::count_stub_managed_regs (); |
| 6943 |
m->call_ms2sysv_extra_regs = count - xlogue_layout::MIN_REGS; |
| 6944 |
m->call_ms2sysv_pad_in = 0; |
| 6945 |
} |
| 6946 |
} |
| 6947 |
|
| 6948 |
frame->nregs = ix86_nsaved_regs (); |
| 6949 |
frame->nsseregs = ix86_nsaved_sseregs (); |
| 6950 |
|
| 6951 |
/* 64-bit MS ABI seem to require stack alignment to be always 16, |
| 6952 |
except for function prologues, leaf functions and when the defult |
| 6953 |
incoming stack boundary is overriden at command line or via |
| 6954 |
force_align_arg_pointer attribute. |
| 6955 |
|
| 6956 |
Darwin's ABI specifies 128b alignment for both 32 and 64 bit variants |
| 6957 |
at call sites, including profile function calls. |
| 6958 |
|
| 6959 |
For APX push2/pop2, the stack also requires 128b alignment. */ |
| 6960 |
if ((ix86_pro_and_epilogue_can_use_push2pop2 (frame->nregs) |
| 6961 |
&& crtl->preferred_stack_boundary < 128) |
| 6962 |
|| (((TARGET_64BIT_MS_ABI || TARGET_MACHO) |
| 6963 |
&& crtl->preferred_stack_boundary < 128) |
| 6964 |
&& (!crtl->is_leaf || cfun->calls_alloca != 0 |
| 6965 |
|| ix86_current_function_calls_tls_descriptor |
| 6966 |
|| (TARGET_MACHO && crtl->profile) |
| 6967 |
|| ix86_incoming_stack_boundary < 128))) |
| 6968 |
{ |
| 6969 |
crtl->preferred_stack_boundary = 128; |
| 6970 |
if (crtl->stack_alignment_needed < 128) |
| 6971 |
crtl->stack_alignment_needed = 128; |
| 6972 |
} |
| 6973 |
|
| 6974 |
stack_alignment_needed = crtl->stack_alignment_needed / BITS_PER_UNIT; |
| 6975 |
preferred_alignment = crtl->preferred_stack_boundary / BITS_PER_UNIT; |
| 6976 |
|
| 6977 |
gcc_assert (!size || stack_alignment_needed); |
| 6978 |
gcc_assert (preferred_alignment >= STACK_BOUNDARY / BITS_PER_UNIT); |
| 6979 |
gcc_assert (preferred_alignment <= stack_alignment_needed); |
| 6980 |
|
| 6981 |
/* The only ABI saving SSE regs should be 64-bit ms_abi. */ |
| 6982 |
gcc_assert (TARGET_64BIT || !frame->nsseregs); |
| 6983 |
if (TARGET_64BIT && m->call_ms2sysv) |
| 6984 |
{ |
| 6985 |
gcc_assert (stack_alignment_needed >= 16); |
| 6986 |
gcc_assert (!frame->nsseregs); |
| 6987 |
} |
| 6988 |
|
| 6989 |
/* For SEH we have to limit the amount of code movement into the prologue. |
| 6990 |
At present we do this via a BLOCKAGE, at which point there's very little |
| 6991 |
scheduling that can be done, which means that there's very little point |
| 6992 |
in doing anything except PUSHs. */ |
| 6993 |
if (TARGET_SEH) |
| 6994 |
m->use_fast_prologue_epilogue = false; |
| 6995 |
else if (!optimize_bb_for_size_p (ENTRY_BLOCK_PTR_FOR_FN (cfun))) |
| 6996 |
{ |
| 6997 |
int count = frame->nregs; |
| 6998 |
struct cgraph_node *node = cgraph_node::get (current_function_decl); |
| 6999 |
|
| 7000 |
/* The fast prologue uses move instead of push to save registers. This |
| 7001 |
is significantly longer, but also executes faster as modern hardware |
| 7002 |
can execute the moves in parallel, but can't do that for push/pop. |
| 7003 |
|
| 7004 |
Be careful about choosing what prologue to emit: When function takes |
| 7005 |
many instructions to execute we may use slow version as well as in |
| 7006 |
case function is known to be outside hot spot (this is known with |
| 7007 |
feedback only). Weight the size of function by number of registers |
| 7008 |
to save as it is cheap to use one or two push instructions but very |
| 7009 |
slow to use many of them. |
| 7010 |
|
| 7011 |
Calling this hook multiple times with the same frame requirements |
| 7012 |
must produce the same layout, since the RA might otherwise be |
| 7013 |
unable to reach a fixed point or might fail its final sanity checks. |
| 7014 |
This means that once we've assumed that a function does or doesn't |
| 7015 |
have a particular size, we have to stick to that assumption |
| 7016 |
regardless of how the function has changed since. */ |
| 7017 |
if (count) |
| 7018 |
count = (count - 1) * FAST_PROLOGUE_INSN_COUNT; |
| 7019 |
if (node->frequency < NODE_FREQUENCY_NORMAL |
| 7020 |
|| (flag_branch_probabilities |
| 7021 |
&& node->frequency < NODE_FREQUENCY_HOT)) |
| 7022 |
m->use_fast_prologue_epilogue = false; |
| 7023 |
else |
| 7024 |
{ |
| 7025 |
if (count != frame->expensive_count) |
| 7026 |
{ |
| 7027 |
frame->expensive_count = count; |
| 7028 |
frame->expensive_p = expensive_function_p (count); |
| 7029 |
} |
| 7030 |
m->use_fast_prologue_epilogue = !frame->expensive_p; |
| 7031 |
} |
| 7032 |
} |
| 7033 |
|
| 7034 |
frame->save_regs_using_mov |
| 7035 |
= TARGET_PROLOGUE_USING_MOVE && m->use_fast_prologue_epilogue; |
| 7036 |
|
| 7037 |
/* Skip return address and error code in exception handler. */ |
| 7038 |
offset = INCOMING_FRAME_SP_OFFSET; |
| 7039 |
|
| 7040 |
/* Skip pushed static chain. */ |
| 7041 |
if (ix86_static_chain_on_stack) |
| 7042 |
offset += UNITS_PER_WORD; |
| 7043 |
|
| 7044 |
/* Skip saved base pointer. */ |
| 7045 |
if (frame_pointer_needed) |
| 7046 |
offset += UNITS_PER_WORD; |
| 7047 |
frame->hfp_save_offset = offset; |
| 7048 |
|
| 7049 |
/* The traditional frame pointer location is at the top of the frame. */ |
| 7050 |
frame->hard_frame_pointer_offset = offset; |
| 7051 |
|
| 7052 |
/* Register save area */ |
| 7053 |
offset += frame->nregs * UNITS_PER_WORD; |
| 7054 |
frame->reg_save_offset = offset; |
| 7055 |
|
| 7056 |
/* Calculate the size of the va-arg area (not including padding, if any). */ |
| 7057 |
frame->va_arg_size = ix86_varargs_gpr_size + ix86_varargs_fpr_size; |
| 7058 |
|
| 7059 |
/* Also adjust stack_realign_offset for the largest alignment of |
| 7060 |
stack slot actually used. */ |
| 7061 |
if (stack_realign_fp |
| 7062 |
|| (cfun->machine->max_used_stack_alignment != 0 |
| 7063 |
&& (offset % cfun->machine->max_used_stack_alignment) != 0)) |
| 7064 |
{ |
| 7065 |
/* We may need a 16-byte aligned stack for the remainder of the |
| 7066 |
register save area, but the stack frame for the local function |
| 7067 |
may require a greater alignment if using AVX/2/512. In order |
| 7068 |
to avoid wasting space, we first calculate the space needed for |
| 7069 |
the rest of the register saves, add that to the stack pointer, |
| 7070 |
and then realign the stack to the boundary of the start of the |
| 7071 |
frame for the local function. */ |
| 7072 |
HOST_WIDE_INT space_needed = 0; |
| 7073 |
HOST_WIDE_INT sse_reg_space_needed = 0; |
| 7074 |
|
| 7075 |
if (TARGET_64BIT) |
| 7076 |
{ |
| 7077 |
if (m->call_ms2sysv) |
| 7078 |
{ |
| 7079 |
m->call_ms2sysv_pad_in = 0; |
| 7080 |
space_needed = xlogue_layout::get_instance ().get_stack_space_used (); |
| 7081 |
} |
| 7082 |
|
| 7083 |
else if (frame->nsseregs) |
| 7084 |
/* The only ABI that has saved SSE registers (Win64) also has a |
| 7085 |
16-byte aligned default stack. However, many programs violate |
| 7086 |
the ABI, and Wine64 forces stack realignment to compensate. */ |
| 7087 |
space_needed = frame->nsseregs * 16; |
| 7088 |
|
| 7089 |
sse_reg_space_needed = space_needed = ROUND_UP (space_needed, 16); |
| 7090 |
|
| 7091 |
/* 64-bit frame->va_arg_size should always be a multiple of 16, but |
| 7092 |
rounding to be pedantic. */ |
| 7093 |
space_needed = ROUND_UP (space_needed + frame->va_arg_size, 16); |
| 7094 |
} |
| 7095 |
else |
| 7096 |
space_needed = frame->va_arg_size; |
| 7097 |
|
| 7098 |
/* Record the allocation size required prior to the realignment AND. */ |
| 7099 |
frame->stack_realign_allocate = space_needed; |
| 7100 |
|
| 7101 |
/* The re-aligned stack starts at frame->stack_realign_offset. Values |
| 7102 |
before this point are not directly comparable with values below |
| 7103 |
this point. Use sp_valid_at to determine if the stack pointer is |
| 7104 |
valid for a given offset, fp_valid_at for the frame pointer, or |
| 7105 |
choose_baseaddr to have a base register chosen for you. |
| 7106 |
|
| 7107 |
Note that the result of (frame->stack_realign_offset |
| 7108 |
& (stack_alignment_needed - 1)) may not equal zero. */ |
| 7109 |
offset = ROUND_UP (offset + space_needed, stack_alignment_needed); |
| 7110 |
frame->stack_realign_offset = offset - space_needed; |
| 7111 |
frame->sse_reg_save_offset = frame->stack_realign_offset |
| 7112 |
+ sse_reg_space_needed; |
| 7113 |
} |
| 7114 |
else |
| 7115 |
{ |
| 7116 |
frame->stack_realign_offset = offset; |
| 7117 |
|
| 7118 |
if (TARGET_64BIT && m->call_ms2sysv) |
| 7119 |
{ |
| 7120 |
m->call_ms2sysv_pad_in = !!(offset & UNITS_PER_WORD); |
| 7121 |
offset += xlogue_layout::get_instance ().get_stack_space_used (); |
| 7122 |
} |
| 7123 |
|
| 7124 |
/* Align and set SSE register save area. */ |
| 7125 |
else if (frame->nsseregs) |
| 7126 |
{ |
| 7127 |
/* If the incoming stack boundary is at least 16 bytes, or DRAP is |
| 7128 |
required and the DRAP re-alignment boundary is at least 16 bytes, |
| 7129 |
then we want the SSE register save area properly aligned. */ |
| 7130 |
if (ix86_incoming_stack_boundary >= 128 |
| 7131 |
|| (stack_realign_drap && stack_alignment_needed >= 16)) |
| 7132 |
offset = ROUND_UP (offset, 16); |
| 7133 |
offset += frame->nsseregs * 16; |
| 7134 |
} |
| 7135 |
frame->sse_reg_save_offset = offset; |
| 7136 |
offset += frame->va_arg_size; |
| 7137 |
} |
| 7138 |
|
| 7139 |
/* Align start of frame for local function. When a function call |
| 7140 |
is removed, it may become a leaf function. But if argument may |
| 7141 |
be passed on stack, we need to align the stack when there is no |
| 7142 |
tail call. */ |
| 7143 |
if (m->call_ms2sysv |
| 7144 |
|| frame->va_arg_size != 0 |
| 7145 |
|| size != 0 |
| 7146 |
|| !crtl->is_leaf |
| 7147 |
|| (!crtl->tail_call_emit |
| 7148 |
&& cfun->machine->outgoing_args_on_stack) |
| 7149 |
|| cfun->calls_alloca |
| 7150 |
|| ix86_current_function_calls_tls_descriptor) |
| 7151 |
offset = ROUND_UP (offset, stack_alignment_needed); |
| 7152 |
|
| 7153 |
/* Frame pointer points here. */ |
| 7154 |
frame->frame_pointer_offset = offset; |
| 7155 |
|
| 7156 |
offset += size; |
| 7157 |
|
| 7158 |
/* Add outgoing arguments area. Can be skipped if we eliminated |
| 7159 |
all the function calls as dead code. |
| 7160 |
Skipping is however impossible when function calls alloca. Alloca |
| 7161 |
expander assumes that last crtl->outgoing_args_size |
| 7162 |
of stack frame are unused. */ |
| 7163 |
if (ACCUMULATE_OUTGOING_ARGS |
| 7164 |
&& (!crtl->is_leaf || cfun->calls_alloca |
| 7165 |
|| ix86_current_function_calls_tls_descriptor)) |
| 7166 |
{ |
| 7167 |
offset += crtl->outgoing_args_size; |
| 7168 |
frame->outgoing_arguments_size = crtl->outgoing_args_size; |
| 7169 |
} |
| 7170 |
else |
| 7171 |
frame->outgoing_arguments_size = 0; |
| 7172 |
|
| 7173 |
/* Align stack boundary. Only needed if we're calling another function |
| 7174 |
or using alloca. */ |
| 7175 |
if (!crtl->is_leaf || cfun->calls_alloca |
| 7176 |
|| ix86_current_function_calls_tls_descriptor) |
| 7177 |
offset = ROUND_UP (offset, preferred_alignment); |
| 7178 |
|
| 7179 |
/* We've reached end of stack frame. */ |
| 7180 |
frame->stack_pointer_offset = offset; |
| 7181 |
|
| 7182 |
/* Size prologue needs to allocate. */ |
| 7183 |
to_allocate = offset - frame->sse_reg_save_offset; |
| 7184 |
|
| 7185 |
if ((!to_allocate && frame->nregs <= 1) |
| 7186 |
|| (TARGET_64BIT && to_allocate >= HOST_WIDE_INT_C (0x80000000)) |
| 7187 |
/* If static stack checking is enabled and done with probes, |
| 7188 |
the registers need to be saved before allocating the frame. */ |
| 7189 |
|| flag_stack_check == STATIC_BUILTIN_STACK_CHECK |
| 7190 |
/* If stack clash probing needs a loop, then it needs a |
| 7191 |
scratch register. But the returned register is only guaranteed |
| 7192 |
to be safe to use after register saves are complete. So if |
| 7193 |
stack clash protections are enabled and the allocated frame is |
| 7194 |
larger than the probe interval, then use pushes to save |
| 7195 |
callee saved registers. */ |
| 7196 |
|| (flag_stack_clash_protection |
| 7197 |
&& !ix86_target_stack_probe () |
| 7198 |
&& to_allocate > get_probe_interval ())) |
| 7199 |
frame->save_regs_using_mov = false; |
| 7200 |
|
| 7201 |
if (ix86_using_red_zone () |
| 7202 |
&& crtl->sp_is_unchanging |
| 7203 |
&& crtl->is_leaf |
| 7204 |
&& !cfun->machine->asm_redzone_clobber_seen |
| 7205 |
&& !ix86_pc_thunk_call_expanded |
| 7206 |
&& !ix86_current_function_calls_tls_descriptor) |
| 7207 |
{ |
| 7208 |
frame->red_zone_size = to_allocate; |
| 7209 |
if (frame->save_regs_using_mov) |
| 7210 |
frame->red_zone_size += frame->nregs * UNITS_PER_WORD; |
| 7211 |
if (frame->red_zone_size > RED_ZONE_SIZE - RED_ZONE_RESERVE) |
| 7212 |
frame->red_zone_size = RED_ZONE_SIZE - RED_ZONE_RESERVE; |
| 7213 |
} |
| 7214 |
else |
| 7215 |
frame->red_zone_size = 0; |
| 7216 |
frame->stack_pointer_offset -= frame->red_zone_size; |
| 7217 |
|
| 7218 |
/* The SEH frame pointer location is near the bottom of the frame. |
| 7219 |
This is enforced by the fact that the difference between the |
| 7220 |
stack pointer and the frame pointer is limited to 240 bytes in |
| 7221 |
the unwind data structure. */ |
| 7222 |
if (TARGET_SEH) |
| 7223 |
{ |
| 7224 |
/* Force the frame pointer to point at or below the lowest register save |
| 7225 |
area, see the SEH code in config/i386/winnt.cc for the rationale. */ |
| 7226 |
frame->hard_frame_pointer_offset = frame->sse_reg_save_offset; |
| 7227 |
|
| 7228 |
/* If we can leave the frame pointer where it is, do so; however return |
| 7229 |
the establisher frame for __builtin_frame_address (0) or else if the |
| 7230 |
frame overflows the SEH maximum frame size. |
| 7231 |
|
| 7232 |
Note that the value returned by __builtin_frame_address (0) is quite |
| 7233 |
constrained, because setjmp is piggybacked on the SEH machinery with |
| 7234 |
recent versions of MinGW: |
| 7235 |
|
| 7236 |
# elif defined(__SEH__) |
| 7237 |
# if defined(__aarch64__) || defined(_ARM64_) |
| 7238 |
# define setjmp(BUF) _setjmp((BUF), __builtin_sponentry()) |
| 7239 |
# elif (__MINGW_GCC_VERSION < 40702) |
| 7240 |
# define setjmp(BUF) _setjmp((BUF), mingw_getsp()) |
| 7241 |
# else |
| 7242 |
# define setjmp(BUF) _setjmp((BUF), __builtin_frame_address (0)) |
| 7243 |
# endif |
| 7244 |
|
| 7245 |
and the second argument passed to _setjmp, if not null, is forwarded |
| 7246 |
to the TargetFrame parameter of RtlUnwindEx by longjmp (after it has |
| 7247 |
built an ExceptionRecord on the fly describing the setjmp buffer). */ |
| 7248 |
const HOST_WIDE_INT diff |
| 7249 |
= frame->stack_pointer_offset - frame->hard_frame_pointer_offset; |
| 7250 |
if (diff <= 255 && !crtl->accesses_prior_frames) |
| 7251 |
{ |
| 7252 |
/* The resulting diff will be a multiple of 16 lower than 255, |
| 7253 |
i.e. at most 240 as required by the unwind data structure. */ |
| 7254 |
frame->hard_frame_pointer_offset += (diff & 15); |
| 7255 |
} |
| 7256 |
else if (diff <= SEH_MAX_FRAME_SIZE && !crtl->accesses_prior_frames) |
| 7257 |
{ |
| 7258 |
/* Ideally we'd determine what portion of the local stack frame |
| 7259 |
(within the constraint of the lowest 240) is most heavily used. |
| 7260 |
But without that complication, simply bias the frame pointer |
| 7261 |
by 128 bytes so as to maximize the amount of the local stack |
| 7262 |
frame that is addressable with 8-bit offsets. */ |
| 7263 |
frame->hard_frame_pointer_offset = frame->stack_pointer_offset - 128; |
| 7264 |
} |
| 7265 |
else |
| 7266 |
frame->hard_frame_pointer_offset = frame->hfp_save_offset; |
| 7267 |
} |
| 7268 |
} |
| 7269 |
|
| 7270 |
/* This is semi-inlined memory_address_length, but simplified |
| 7271 |
since we know that we're always dealing with reg+offset, and |
| 7272 |
to avoid having to create and discard all that rtl. */ |
| 7273 |
|
| 7274 |
static inline int |
| 7275 |
choose_baseaddr_len (unsigned int regno, HOST_WIDE_INT offset) |
| 7276 |
{ |
| 7277 |
int len = 4; |
| 7278 |
|
| 7279 |
if (offset == 0) |
| 7280 |
{ |
| 7281 |
/* EBP and R13 cannot be encoded without an offset. */ |
| 7282 |
len = (regno == BP_REG || regno == R13_REG); |
| 7283 |
} |
| 7284 |
else if (IN_RANGE (offset, -128, 127)) |
| 7285 |
len = 1; |
| 7286 |
|
| 7287 |
/* ESP and R12 must be encoded with a SIB byte. */ |
| 7288 |
if (regno == SP_REG || regno == R12_REG) |
| 7289 |
len++; |
| 7290 |
|
| 7291 |
return len; |
| 7292 |
} |
| 7293 |
|
| 7294 |
/* Determine if the stack pointer is valid for accessing the CFA_OFFSET in |
| 7295 |
the frame save area. The register is saved at CFA - CFA_OFFSET. */ |
| 7296 |
|
| 7297 |
static bool |
| 7298 |
sp_valid_at (HOST_WIDE_INT cfa_offset) |
| 7299 |
{ |
| 7300 |
const struct machine_frame_state &fs = cfun->machine->fs; |
| 7301 |
if (fs.sp_realigned && cfa_offset <= fs.sp_realigned_offset) |
| 7302 |
{ |
| 7303 |
/* Validate that the cfa_offset isn't in a "no-man's land". */ |
| 7304 |
gcc_assert (cfa_offset <= fs.sp_realigned_fp_last); |
| 7305 |
return false; |
| 7306 |
} |
| 7307 |
return fs.sp_valid; |
| 7308 |
} |
| 7309 |
|
| 7310 |
/* Determine if the frame pointer is valid for accessing the CFA_OFFSET in |
| 7311 |
the frame save area. The register is saved at CFA - CFA_OFFSET. */ |
| 7312 |
|
| 7313 |
static inline bool |
| 7314 |
fp_valid_at (HOST_WIDE_INT cfa_offset) |
| 7315 |
{ |
| 7316 |
const struct machine_frame_state &fs = cfun->machine->fs; |
| 7317 |
if (fs.sp_realigned && cfa_offset > fs.sp_realigned_fp_last) |
| 7318 |
{ |
| 7319 |
/* Validate that the cfa_offset isn't in a "no-man's land". */ |
| 7320 |
gcc_assert (cfa_offset >= fs.sp_realigned_offset); |
| 7321 |
return false; |
| 7322 |
} |
| 7323 |
return fs.fp_valid; |
| 7324 |
} |
| 7325 |
|
| 7326 |
/* Choose a base register based upon alignment requested, speed and/or |
| 7327 |
size. */ |
| 7328 |
|
| 7329 |
static void |
| 7330 |
choose_basereg (HOST_WIDE_INT cfa_offset, rtx &base_reg, |
| 7331 |
HOST_WIDE_INT &base_offset, |
| 7332 |
unsigned int align_reqested, unsigned int *align) |
| 7333 |
{ |
| 7334 |
const struct machine_function *m = cfun->machine; |
| 7335 |
unsigned int hfp_align; |
| 7336 |
unsigned int drap_align; |
| 7337 |
unsigned int sp_align; |
| 7338 |
bool hfp_ok = fp_valid_at (cfa_offset); |
| 7339 |
bool drap_ok = m->fs.drap_valid; |
| 7340 |
bool sp_ok = sp_valid_at (cfa_offset); |
| 7341 |
|
| 7342 |
hfp_align = drap_align = sp_align = INCOMING_STACK_BOUNDARY; |
| 7343 |
|
| 7344 |
/* Filter out any registers that don't meet the requested alignment |
| 7345 |
criteria. */ |
| 7346 |
if (align_reqested) |
| 7347 |
{ |
| 7348 |
if (m->fs.realigned) |
| 7349 |
hfp_align = drap_align = sp_align = crtl->stack_alignment_needed; |
| 7350 |
/* SEH unwind code does do not currently support REG_CFA_EXPRESSION |
| 7351 |
notes (which we would need to use a realigned stack pointer), |
| 7352 |
so disable on SEH targets. */ |
| 7353 |
else if (m->fs.sp_realigned) |
| 7354 |
sp_align = crtl->stack_alignment_needed; |
| 7355 |
|
| 7356 |
hfp_ok = hfp_ok && hfp_align >= align_reqested; |
| 7357 |
drap_ok = drap_ok && drap_align >= align_reqested; |
| 7358 |
sp_ok = sp_ok && sp_align >= align_reqested; |
| 7359 |
} |
| 7360 |
|
| 7361 |
if (m->use_fast_prologue_epilogue) |
| 7362 |
{ |
| 7363 |
/* Choose the base register most likely to allow the most scheduling |
| 7364 |
opportunities. Generally FP is valid throughout the function, |
| 7365 |
while DRAP must be reloaded within the epilogue. But choose either |
| 7366 |
over the SP due to increased encoding size. */ |
| 7367 |
|
| 7368 |
if (hfp_ok) |
| 7369 |
{ |
| 7370 |
base_reg = hard_frame_pointer_rtx; |
| 7371 |
base_offset = m->fs.fp_offset - cfa_offset; |
| 7372 |
} |
| 7373 |
else if (drap_ok) |
| 7374 |
{ |
| 7375 |
base_reg = crtl->drap_reg; |
| 7376 |
base_offset = 0 - cfa_offset; |
| 7377 |
} |
| 7378 |
else if (sp_ok) |
| 7379 |
{ |
| 7380 |
base_reg = stack_pointer_rtx; |
| 7381 |
base_offset = m->fs.sp_offset - cfa_offset; |
| 7382 |
} |
| 7383 |
} |
| 7384 |
else |
| 7385 |
{ |
| 7386 |
HOST_WIDE_INT toffset; |
| 7387 |
int len = 16, tlen; |
| 7388 |
|
| 7389 |
/* Choose the base register with the smallest address encoding. |
| 7390 |
With a tie, choose FP > DRAP > SP. */ |
| 7391 |
if (sp_ok) |
| 7392 |
{ |
| 7393 |
base_reg = stack_pointer_rtx; |
| 7394 |
base_offset = m->fs.sp_offset - cfa_offset; |
| 7395 |
len = choose_baseaddr_len (STACK_POINTER_REGNUM, base_offset); |
| 7396 |
} |
| 7397 |
if (drap_ok) |
| 7398 |
{ |
| 7399 |
toffset = 0 - cfa_offset; |
| 7400 |
tlen = choose_baseaddr_len (REGNO (crtl->drap_reg), toffset); |
| 7401 |
if (tlen <= len) |
| 7402 |
{ |
| 7403 |
base_reg = crtl->drap_reg; |
| 7404 |
base_offset = toffset; |
| 7405 |
len = tlen; |
| 7406 |
} |
| 7407 |
} |
| 7408 |
if (hfp_ok) |
| 7409 |
{ |
| 7410 |
toffset = m->fs.fp_offset - cfa_offset; |
| 7411 |
tlen = choose_baseaddr_len (HARD_FRAME_POINTER_REGNUM, toffset); |
| 7412 |
if (tlen <= len) |
| 7413 |
{ |
| 7414 |
base_reg = hard_frame_pointer_rtx; |
| 7415 |
base_offset = toffset; |
| 7416 |
} |
| 7417 |
} |
| 7418 |
} |
| 7419 |
|
| 7420 |
/* Set the align return value. */ |
| 7421 |
if (align) |
| 7422 |
{ |
| 7423 |
if (base_reg == stack_pointer_rtx) |
| 7424 |
*align = sp_align; |
| 7425 |
else if (base_reg == crtl->drap_reg) |
| 7426 |
*align = drap_align; |
| 7427 |
else if (base_reg == hard_frame_pointer_rtx) |
| 7428 |
*align = hfp_align; |
| 7429 |
} |
| 7430 |
} |
| 7431 |
|
| 7432 |
/* Return an RTX that points to CFA_OFFSET within the stack frame and |
| 7433 |
the alignment of address. If ALIGN is non-null, it should point to |
| 7434 |
an alignment value (in bits) that is preferred or zero and will |
| 7435 |
recieve the alignment of the base register that was selected, |
| 7436 |
irrespective of rather or not CFA_OFFSET is a multiple of that |
| 7437 |
alignment value. If it is possible for the base register offset to be |
| 7438 |
non-immediate then SCRATCH_REGNO should specify a scratch register to |
| 7439 |
use. |
| 7440 |
|
| 7441 |
The valid base registers are taken from CFUN->MACHINE->FS. */ |
| 7442 |
|
| 7443 |
static rtx |
| 7444 |
choose_baseaddr (HOST_WIDE_INT cfa_offset, unsigned int *align, |
| 7445 |
unsigned int scratch_regno = INVALID_REGNUM) |
| 7446 |
{ |
| 7447 |
rtx base_reg = NULL; |
| 7448 |
HOST_WIDE_INT base_offset = 0; |
| 7449 |
|
| 7450 |
/* If a specific alignment is requested, try to get a base register |
| 7451 |
with that alignment first. */ |
| 7452 |
if (align && *align) |
| 7453 |
choose_basereg (cfa_offset, base_reg, base_offset, *align, align); |
| 7454 |
|
| 7455 |
if (!base_reg) |
| 7456 |
choose_basereg (cfa_offset, base_reg, base_offset, 0, align); |
| 7457 |
|
| 7458 |
gcc_assert (base_reg != NULL); |
| 7459 |
|
| 7460 |
rtx base_offset_rtx = GEN_INT (base_offset); |
| 7461 |
|
| 7462 |
if (!x86_64_immediate_operand (base_offset_rtx, Pmode)) |
| 7463 |
{ |
| 7464 |
gcc_assert (scratch_regno != INVALID_REGNUM); |
| 7465 |
|
| 7466 |
rtx scratch_reg = gen_rtx_REG (Pmode, scratch_regno); |
| 7467 |
emit_move_insn (scratch_reg, base_offset_rtx); |
| 7468 |
|
| 7469 |
return gen_rtx_PLUS (Pmode, base_reg, scratch_reg); |
| 7470 |
} |
| 7471 |
|
| 7472 |
return plus_constant (Pmode, base_reg, base_offset); |
| 7473 |
} |
| 7474 |
|
| 7475 |
/* Emit code to save registers in the prologue. */ |
| 7476 |
|
| 7477 |
static void |
| 7478 |
ix86_emit_save_regs (void) |
| 7479 |
{ |
| 7480 |
int regno; |
| 7481 |
rtx_insn *insn; |
| 7482 |
bool use_ppx = TARGET_APX_PPX && !crtl->calls_eh_return; |
| 7483 |
|
| 7484 |
if (!TARGET_APX_PUSH2POP2 |
| 7485 |
|| !ix86_can_use_push2pop2 () |
| 7486 |
|| cfun->machine->func_type != TYPE_NORMAL) |
| 7487 |
{ |
| 7488 |
for (regno = FIRST_PSEUDO_REGISTER - 1; regno >= 0; regno--) |
| 7489 |
if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, true, true)) |
| 7490 |
{ |
| 7491 |
insn = emit_insn (gen_push (gen_rtx_REG (word_mode, regno), |
| 7492 |
use_ppx)); |
| 7493 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 7494 |
} |
| 7495 |
} |
| 7496 |
else |
| 7497 |
{ |
| 7498 |
int regno_list[2]; |
| 7499 |
regno_list[0] = regno_list[1] = -1; |
| 7500 |
int loaded_regnum = 0; |
| 7501 |
bool aligned = cfun->machine->fs.sp_offset % 16 == 0; |
| 7502 |
|
| 7503 |
for (regno = FIRST_PSEUDO_REGISTER - 1; regno >= 0; regno--) |
| 7504 |
if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, true, true)) |
| 7505 |
{ |
| 7506 |
if (aligned) |
| 7507 |
{ |
| 7508 |
regno_list[loaded_regnum++] = regno; |
| 7509 |
if (loaded_regnum == 2) |
| 7510 |
{ |
| 7511 |
gcc_assert (regno_list[0] != -1 |
| 7512 |
&& regno_list[1] != -1 |
| 7513 |
&& regno_list[0] != regno_list[1]); |
| 7514 |
const int offset = UNITS_PER_WORD * 2; |
| 7515 |
rtx mem = gen_rtx_MEM (TImode, |
| 7516 |
gen_rtx_PRE_DEC (Pmode, |
| 7517 |
stack_pointer_rtx)); |
| 7518 |
insn = emit_insn (gen_push2 (mem, |
| 7519 |
gen_rtx_REG (word_mode, |
| 7520 |
regno_list[0]), |
| 7521 |
gen_rtx_REG (word_mode, |
| 7522 |
regno_list[1]), |
| 7523 |
use_ppx)); |
| 7524 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 7525 |
rtx dwarf = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (3)); |
| 7526 |
|
| 7527 |
for (int i = 0; i < 2; i++) |
| 7528 |
{ |
| 7529 |
rtx dwarf_reg = gen_rtx_REG (word_mode, |
| 7530 |
regno_list[i]); |
| 7531 |
rtx sp_offset = plus_constant (Pmode, |
| 7532 |
stack_pointer_rtx, |
| 7533 |
+ UNITS_PER_WORD |
| 7534 |
* (1 - i)); |
| 7535 |
rtx tmp = gen_rtx_SET (gen_frame_mem (DImode, |
| 7536 |
sp_offset), |
| 7537 |
dwarf_reg); |
| 7538 |
RTX_FRAME_RELATED_P (tmp) = 1; |
| 7539 |
XVECEXP (dwarf, 0, i + 1) = tmp; |
| 7540 |
} |
| 7541 |
rtx sp_tmp = gen_rtx_SET (stack_pointer_rtx, |
| 7542 |
plus_constant (Pmode, |
| 7543 |
stack_pointer_rtx, |
| 7544 |
-offset)); |
| 7545 |
RTX_FRAME_RELATED_P (sp_tmp) = 1; |
| 7546 |
XVECEXP (dwarf, 0, 0) = sp_tmp; |
| 7547 |
add_reg_note (insn, REG_FRAME_RELATED_EXPR, dwarf); |
| 7548 |
|
| 7549 |
loaded_regnum = 0; |
| 7550 |
regno_list[0] = regno_list[1] = -1; |
| 7551 |
} |
| 7552 |
} |
| 7553 |
else |
| 7554 |
{ |
| 7555 |
insn = emit_insn (gen_push (gen_rtx_REG (word_mode, regno), |
| 7556 |
use_ppx)); |
| 7557 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 7558 |
aligned = true; |
| 7559 |
} |
| 7560 |
} |
| 7561 |
if (loaded_regnum == 1) |
| 7562 |
{ |
| 7563 |
insn = emit_insn (gen_push (gen_rtx_REG (word_mode, |
| 7564 |
regno_list[0]), |
| 7565 |
use_ppx)); |
| 7566 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 7567 |
} |
| 7568 |
} |
| 7569 |
} |
| 7570 |
|
| 7571 |
/* Emit a single register save at CFA - CFA_OFFSET. */ |
| 7572 |
|
| 7573 |
static void |
| 7574 |
ix86_emit_save_reg_using_mov (machine_mode mode, unsigned int regno, |
| 7575 |
HOST_WIDE_INT cfa_offset) |
| 7576 |
{ |
| 7577 |
struct machine_function *m = cfun->machine; |
| 7578 |
rtx reg = gen_rtx_REG (mode, regno); |
| 7579 |
rtx mem, addr, base, insn; |
| 7580 |
unsigned int align = GET_MODE_ALIGNMENT (mode); |
| 7581 |
|
| 7582 |
addr = choose_baseaddr (cfa_offset, &align); |
| 7583 |
mem = gen_frame_mem (mode, addr); |
| 7584 |
|
| 7585 |
/* The location aligment depends upon the base register. */ |
| 7586 |
align = MIN (GET_MODE_ALIGNMENT (mode), align); |
| 7587 |
gcc_assert (! (cfa_offset & (align / BITS_PER_UNIT - 1))); |
| 7588 |
set_mem_align (mem, align); |
| 7589 |
|
| 7590 |
insn = emit_insn (gen_rtx_SET (mem, reg)); |
| 7591 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 7592 |
|
| 7593 |
base = addr; |
| 7594 |
if (GET_CODE (base) == PLUS) |
| 7595 |
base = XEXP (base, 0); |
| 7596 |
gcc_checking_assert (REG_P (base)); |
| 7597 |
|
| 7598 |
/* When saving registers into a re-aligned local stack frame, avoid |
| 7599 |
any tricky guessing by dwarf2out. */ |
| 7600 |
if (m->fs.realigned) |
| 7601 |
{ |
| 7602 |
gcc_checking_assert (stack_realign_drap); |
| 7603 |
|
| 7604 |
if (regno == REGNO (crtl->drap_reg)) |
| 7605 |
{ |
| 7606 |
/* A bit of a hack. We force the DRAP register to be saved in |
| 7607 |
the re-aligned stack frame, which provides us with a copy |
| 7608 |
of the CFA that will last past the prologue. Install it. */ |
| 7609 |
gcc_checking_assert (cfun->machine->fs.fp_valid); |
| 7610 |
addr = plus_constant (Pmode, hard_frame_pointer_rtx, |
| 7611 |
cfun->machine->fs.fp_offset - cfa_offset); |
| 7612 |
mem = gen_rtx_MEM (mode, addr); |
| 7613 |
add_reg_note (insn, REG_CFA_DEF_CFA, mem); |
| 7614 |
} |
| 7615 |
else |
| 7616 |
{ |
| 7617 |
/* The frame pointer is a stable reference within the |
| 7618 |
aligned frame. Use it. */ |
| 7619 |
gcc_checking_assert (cfun->machine->fs.fp_valid); |
| 7620 |
addr = plus_constant (Pmode, hard_frame_pointer_rtx, |
| 7621 |
cfun->machine->fs.fp_offset - cfa_offset); |
| 7622 |
mem = gen_rtx_MEM (mode, addr); |
| 7623 |
add_reg_note (insn, REG_CFA_EXPRESSION, gen_rtx_SET (mem, reg)); |
| 7624 |
} |
| 7625 |
} |
| 7626 |
|
| 7627 |
else if (base == stack_pointer_rtx && m->fs.sp_realigned |
| 7628 |
&& cfa_offset >= m->fs.sp_realigned_offset) |
| 7629 |
{ |
| 7630 |
gcc_checking_assert (stack_realign_fp); |
| 7631 |
add_reg_note (insn, REG_CFA_EXPRESSION, gen_rtx_SET (mem, reg)); |
| 7632 |
} |
| 7633 |
|
| 7634 |
/* The memory may not be relative to the current CFA register, |
| 7635 |
which means that we may need to generate a new pattern for |
| 7636 |
use by the unwind info. */ |
| 7637 |
else if (base != m->fs.cfa_reg) |
| 7638 |
{ |
| 7639 |
addr = plus_constant (Pmode, m->fs.cfa_reg, |
| 7640 |
m->fs.cfa_offset - cfa_offset); |
| 7641 |
mem = gen_rtx_MEM (mode, addr); |
| 7642 |
add_reg_note (insn, REG_CFA_OFFSET, gen_rtx_SET (mem, reg)); |
| 7643 |
} |
| 7644 |
} |
| 7645 |
|
| 7646 |
/* Emit code to save registers using MOV insns. |
| 7647 |
First register is stored at CFA - CFA_OFFSET. */ |
| 7648 |
static void |
| 7649 |
ix86_emit_save_regs_using_mov (HOST_WIDE_INT cfa_offset) |
| 7650 |
{ |
| 7651 |
unsigned int regno; |
| 7652 |
|
| 7653 |
for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) |
| 7654 |
if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, true, true)) |
| 7655 |
{ |
| 7656 |
ix86_emit_save_reg_using_mov (word_mode, regno, cfa_offset); |
| 7657 |
cfa_offset -= UNITS_PER_WORD; |
| 7658 |
} |
| 7659 |
} |
| 7660 |
|
| 7661 |
/* Emit code to save SSE registers using MOV insns. |
| 7662 |
First register is stored at CFA - CFA_OFFSET. */ |
| 7663 |
static void |
| 7664 |
ix86_emit_save_sse_regs_using_mov (HOST_WIDE_INT cfa_offset) |
| 7665 |
{ |
| 7666 |
unsigned int regno; |
| 7667 |
|
| 7668 |
for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) |
| 7669 |
if (SSE_REGNO_P (regno) && ix86_save_reg (regno, true, true)) |
| 7670 |
{ |
| 7671 |
ix86_emit_save_reg_using_mov (V4SFmode, regno, cfa_offset); |
| 7672 |
cfa_offset -= GET_MODE_SIZE (V4SFmode); |
| 7673 |
} |
| 7674 |
} |
| 7675 |
|
| 7676 |
static GTY(()) rtx queued_cfa_restores; |
| 7677 |
|
| 7678 |
/* Add a REG_CFA_RESTORE REG note to INSN or queue them until next stack |
| 7679 |
manipulation insn. The value is on the stack at CFA - CFA_OFFSET. |
| 7680 |
Don't add the note if the previously saved value will be left untouched |
| 7681 |
within stack red-zone till return, as unwinders can find the same value |
| 7682 |
in the register and on the stack. */ |
| 7683 |
|
| 7684 |
static void |
| 7685 |
ix86_add_cfa_restore_note (rtx_insn *insn, rtx reg, HOST_WIDE_INT cfa_offset) |
| 7686 |
{ |
| 7687 |
if (!crtl->shrink_wrapped |
| 7688 |
&& cfa_offset <= cfun->machine->fs.red_zone_offset) |
| 7689 |
return; |
| 7690 |
|
| 7691 |
if (insn) |
| 7692 |
{ |
| 7693 |
add_reg_note (insn, REG_CFA_RESTORE, reg); |
| 7694 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 7695 |
} |
| 7696 |
else |
| 7697 |
queued_cfa_restores |
| 7698 |
= alloc_reg_note (REG_CFA_RESTORE, reg, queued_cfa_restores); |
| 7699 |
} |
| 7700 |
|
| 7701 |
/* Add queued REG_CFA_RESTORE notes if any to INSN. */ |
| 7702 |
|
| 7703 |
static void |
| 7704 |
ix86_add_queued_cfa_restore_notes (rtx insn) |
| 7705 |
{ |
| 7706 |
rtx last; |
| 7707 |
if (!queued_cfa_restores) |
| 7708 |
return; |
| 7709 |
for (last = queued_cfa_restores; XEXP (last, 1); last = XEXP (last, 1)) |
| 7710 |
; |
| 7711 |
XEXP (last, 1) = REG_NOTES (insn); |
| 7712 |
REG_NOTES (insn) = queued_cfa_restores; |
| 7713 |
queued_cfa_restores = NULL_RTX; |
| 7714 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 7715 |
} |
| 7716 |
|
| 7717 |
/* Expand prologue or epilogue stack adjustment. |
| 7718 |
The pattern exist to put a dependency on all ebp-based memory accesses. |
| 7719 |
STYLE should be negative if instructions should be marked as frame related, |
| 7720 |
zero if %r11 register is live and cannot be freely used and positive |
| 7721 |
otherwise. */ |
| 7722 |
|
| 7723 |
static rtx |
| 7724 |
pro_epilogue_adjust_stack (rtx dest, rtx src, rtx offset, |
| 7725 |
int style, bool set_cfa) |
| 7726 |
{ |
| 7727 |
struct machine_function *m = cfun->machine; |
| 7728 |
rtx addend = offset; |
| 7729 |
rtx insn; |
| 7730 |
bool add_frame_related_expr = false; |
| 7731 |
|
| 7732 |
if (!x86_64_immediate_operand (offset, Pmode)) |
| 7733 |
{ |
| 7734 |
/* r11 is used by indirect sibcall return as well, set before the |
| 7735 |
epilogue and used after the epilogue. */ |
| 7736 |
if (style) |
| 7737 |
addend = gen_rtx_REG (Pmode, R11_REG); |
| 7738 |
else |
| 7739 |
{ |
| 7740 |
gcc_assert (src != hard_frame_pointer_rtx |
| 7741 |
&& dest != hard_frame_pointer_rtx); |
| 7742 |
addend = hard_frame_pointer_rtx; |
| 7743 |
} |
| 7744 |
emit_insn (gen_rtx_SET (addend, offset)); |
| 7745 |
if (style < 0) |
| 7746 |
add_frame_related_expr = true; |
| 7747 |
} |
| 7748 |
|
| 7749 |
insn = emit_insn (gen_pro_epilogue_adjust_stack_add |
| 7750 |
(Pmode, dest, src, addend)); |
| 7751 |
if (style >= 0) |
| 7752 |
ix86_add_queued_cfa_restore_notes (insn); |
| 7753 |
|
| 7754 |
if (set_cfa) |
| 7755 |
{ |
| 7756 |
rtx r; |
| 7757 |
|
| 7758 |
gcc_assert (m->fs.cfa_reg == src); |
| 7759 |
m->fs.cfa_offset += INTVAL (offset); |
| 7760 |
m->fs.cfa_reg = dest; |
| 7761 |
|
| 7762 |
r = gen_rtx_PLUS (Pmode, src, offset); |
| 7763 |
r = gen_rtx_SET (dest, r); |
| 7764 |
add_reg_note (insn, REG_CFA_ADJUST_CFA, r); |
| 7765 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 7766 |
} |
| 7767 |
else if (style < 0) |
| 7768 |
{ |
| 7769 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 7770 |
if (add_frame_related_expr) |
| 7771 |
{ |
| 7772 |
rtx r = gen_rtx_PLUS (Pmode, src, offset); |
| 7773 |
r = gen_rtx_SET (dest, r); |
| 7774 |
add_reg_note (insn, REG_FRAME_RELATED_EXPR, r); |
| 7775 |
} |
| 7776 |
} |
| 7777 |
|
| 7778 |
if (dest == stack_pointer_rtx) |
| 7779 |
{ |
| 7780 |
HOST_WIDE_INT ooffset = m->fs.sp_offset; |
| 7781 |
bool valid = m->fs.sp_valid; |
| 7782 |
bool realigned = m->fs.sp_realigned; |
| 7783 |
|
| 7784 |
if (src == hard_frame_pointer_rtx) |
| 7785 |
{ |
| 7786 |
valid = m->fs.fp_valid; |
| 7787 |
realigned = false; |
| 7788 |
ooffset = m->fs.fp_offset; |
| 7789 |
} |
| 7790 |
else if (src == crtl->drap_reg) |
| 7791 |
{ |
| 7792 |
valid = m->fs.drap_valid; |
| 7793 |
realigned = false; |
| 7794 |
ooffset = 0; |
| 7795 |
} |
| 7796 |
else |
| 7797 |
{ |
| 7798 |
/* Else there are two possibilities: SP itself, which we set |
| 7799 |
up as the default above. Or EH_RETURN_STACKADJ_RTX, which is |
| 7800 |
taken care of this by hand along the eh_return path. */ |
| 7801 |
gcc_checking_assert (src == stack_pointer_rtx |
| 7802 |
|| offset == const0_rtx); |
| 7803 |
} |
| 7804 |
|
| 7805 |
m->fs.sp_offset = ooffset - INTVAL (offset); |
| 7806 |
m->fs.sp_valid = valid; |
| 7807 |
m->fs.sp_realigned = realigned; |
| 7808 |
} |
| 7809 |
return insn; |
| 7810 |
} |
| 7811 |
|
| 7812 |
/* Find an available register to be used as dynamic realign argument |
| 7813 |
pointer regsiter. Such a register will be written in prologue and |
| 7814 |
used in begin of body, so it must not be |
| 7815 |
1. parameter passing register. |
| 7816 |
2. GOT pointer. |
| 7817 |
We reuse static-chain register if it is available. Otherwise, we |
| 7818 |
use DI for i386 and R13 for x86-64. We chose R13 since it has |
| 7819 |
shorter encoding. |
| 7820 |
|
| 7821 |
Return: the regno of chosen register. */ |
| 7822 |
|
| 7823 |
static unsigned int |
| 7824 |
find_drap_reg (void) |
| 7825 |
{ |
| 7826 |
tree decl = cfun->decl; |
| 7827 |
|
| 7828 |
/* Always use callee-saved register if there are no caller-saved |
| 7829 |
registers. */ |
| 7830 |
if (TARGET_64BIT) |
| 7831 |
{ |
| 7832 |
/* Use R13 for nested function or function need static chain. |
| 7833 |
Since function with tail call may use any caller-saved |
| 7834 |
registers in epilogue, DRAP must not use caller-saved |
| 7835 |
register in such case. */ |
| 7836 |
if (DECL_STATIC_CHAIN (decl) |
| 7837 |
|| (cfun->machine->call_saved_registers |
| 7838 |
== TYPE_NO_CALLER_SAVED_REGISTERS) |
| 7839 |
|| crtl->tail_call_emit) |
| 7840 |
return R13_REG; |
| 7841 |
|
| 7842 |
return R10_REG; |
| 7843 |
} |
| 7844 |
else |
| 7845 |
{ |
| 7846 |
/* Use DI for nested function or function need static chain. |
| 7847 |
Since function with tail call may use any caller-saved |
| 7848 |
registers in epilogue, DRAP must not use caller-saved |
| 7849 |
register in such case. */ |
| 7850 |
if (DECL_STATIC_CHAIN (decl) |
| 7851 |
|| (cfun->machine->call_saved_registers |
| 7852 |
== TYPE_NO_CALLER_SAVED_REGISTERS) |
| 7853 |
|| crtl->tail_call_emit |
| 7854 |
|| crtl->calls_eh_return) |
| 7855 |
return DI_REG; |
| 7856 |
|
| 7857 |
/* Reuse static chain register if it isn't used for parameter |
| 7858 |
passing. */ |
| 7859 |
if (ix86_function_regparm (TREE_TYPE (decl), decl) <= 2) |
| 7860 |
{ |
| 7861 |
unsigned int ccvt = ix86_get_callcvt (TREE_TYPE (decl)); |
| 7862 |
if ((ccvt & (IX86_CALLCVT_FASTCALL | IX86_CALLCVT_THISCALL)) == 0) |
| 7863 |
return CX_REG; |
| 7864 |
} |
| 7865 |
return DI_REG; |
| 7866 |
} |
| 7867 |
} |
| 7868 |
|
| 7869 |
/* Return minimum incoming stack alignment. */ |
| 7870 |
|
| 7871 |
static unsigned int |
| 7872 |
ix86_minimum_incoming_stack_boundary (bool sibcall) |
| 7873 |
{ |
| 7874 |
unsigned int incoming_stack_boundary; |
| 7875 |
|
| 7876 |
/* Stack of interrupt handler is aligned to 128 bits in 64bit mode. */ |
| 7877 |
if (cfun->machine->func_type != TYPE_NORMAL) |
| 7878 |
incoming_stack_boundary = TARGET_64BIT ? 128 : MIN_STACK_BOUNDARY; |
| 7879 |
/* Prefer the one specified at command line. */ |
| 7880 |
else if (ix86_user_incoming_stack_boundary) |
| 7881 |
incoming_stack_boundary = ix86_user_incoming_stack_boundary; |
| 7882 |
/* In 32bit, use MIN_STACK_BOUNDARY for incoming stack boundary |
| 7883 |
if -mstackrealign is used, it isn't used for sibcall check and |
| 7884 |
estimated stack alignment is 128bit. */ |
| 7885 |
else if (!sibcall |
| 7886 |
&& ix86_force_align_arg_pointer |
| 7887 |
&& crtl->stack_alignment_estimated == 128) |
| 7888 |
incoming_stack_boundary = MIN_STACK_BOUNDARY; |
| 7889 |
else |
| 7890 |
incoming_stack_boundary = ix86_default_incoming_stack_boundary; |
| 7891 |
|
| 7892 |
/* Incoming stack alignment can be changed on individual functions |
| 7893 |
via force_align_arg_pointer attribute. We use the smallest |
| 7894 |
incoming stack boundary. */ |
| 7895 |
if (incoming_stack_boundary > MIN_STACK_BOUNDARY |
| 7896 |
&& lookup_attribute ("force_align_arg_pointer", |
| 7897 |
TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl)))) |
| 7898 |
incoming_stack_boundary = MIN_STACK_BOUNDARY; |
| 7899 |
|
| 7900 |
/* The incoming stack frame has to be aligned at least at |
| 7901 |
parm_stack_boundary. */ |
| 7902 |
if (incoming_stack_boundary < crtl->parm_stack_boundary) |
| 7903 |
incoming_stack_boundary = crtl->parm_stack_boundary; |
| 7904 |
|
| 7905 |
/* Stack at entrance of main is aligned by runtime. We use the |
| 7906 |
smallest incoming stack boundary. */ |
| 7907 |
if (incoming_stack_boundary > MAIN_STACK_BOUNDARY |
| 7908 |
&& DECL_NAME (current_function_decl) |
| 7909 |
&& MAIN_NAME_P (DECL_NAME (current_function_decl)) |
| 7910 |
&& DECL_FILE_SCOPE_P (current_function_decl)) |
| 7911 |
incoming_stack_boundary = MAIN_STACK_BOUNDARY; |
| 7912 |
|
| 7913 |
return incoming_stack_boundary; |
| 7914 |
} |
| 7915 |
|
| 7916 |
/* Update incoming stack boundary and estimated stack alignment. */ |
| 7917 |
|
| 7918 |
static void |
| 7919 |
ix86_update_stack_boundary (void) |
| 7920 |
{ |
| 7921 |
ix86_incoming_stack_boundary |
| 7922 |
= ix86_minimum_incoming_stack_boundary (false); |
| 7923 |
|
| 7924 |
/* x86_64 vararg needs 16byte stack alignment for register save area. */ |
| 7925 |
if (TARGET_64BIT |
| 7926 |
&& cfun->stdarg |
| 7927 |
&& crtl->stack_alignment_estimated < 128) |
| 7928 |
crtl->stack_alignment_estimated = 128; |
| 7929 |
|
| 7930 |
/* __tls_get_addr needs to be called with 16-byte aligned stack. */ |
| 7931 |
if (ix86_tls_descriptor_calls_expanded_in_cfun |
| 7932 |
&& crtl->preferred_stack_boundary < 128) |
| 7933 |
crtl->preferred_stack_boundary = 128; |
| 7934 |
} |
| 7935 |
|
| 7936 |
/* Handle the TARGET_GET_DRAP_RTX hook. Return NULL if no DRAP is |
| 7937 |
needed or an rtx for DRAP otherwise. */ |
| 7938 |
|
| 7939 |
static rtx |
| 7940 |
ix86_get_drap_rtx (void) |
| 7941 |
{ |
| 7942 |
/* We must use DRAP if there are outgoing arguments on stack or |
| 7943 |
the stack pointer register is clobbered by asm statment and |
| 7944 |
ACCUMULATE_OUTGOING_ARGS is false. */ |
| 7945 |
if (ix86_force_drap |
| 7946 |
|| ((cfun->machine->outgoing_args_on_stack |
| 7947 |
|| crtl->sp_is_clobbered_by_asm) |
| 7948 |
&& !ACCUMULATE_OUTGOING_ARGS)) |
| 7949 |
crtl->need_drap = true; |
| 7950 |
|
| 7951 |
if (stack_realign_drap) |
| 7952 |
{ |
| 7953 |
/* Assign DRAP to vDRAP and returns vDRAP */ |
| 7954 |
unsigned int regno = find_drap_reg (); |
| 7955 |
rtx drap_vreg; |
| 7956 |
rtx arg_ptr; |
| 7957 |
rtx_insn *seq, *insn; |
| 7958 |
|
| 7959 |
arg_ptr = gen_rtx_REG (Pmode, regno); |
| 7960 |
crtl->drap_reg = arg_ptr; |
| 7961 |
|
| 7962 |
start_sequence (); |
| 7963 |
drap_vreg = copy_to_reg (arg_ptr); |
| 7964 |
seq = get_insns (); |
| 7965 |
end_sequence (); |
| 7966 |
|
| 7967 |
insn = emit_insn_before (seq, NEXT_INSN (entry_of_function ())); |
| 7968 |
if (!optimize) |
| 7969 |
{ |
| 7970 |
add_reg_note (insn, REG_CFA_SET_VDRAP, drap_vreg); |
| 7971 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 7972 |
} |
| 7973 |
return drap_vreg; |
| 7974 |
} |
| 7975 |
else |
| 7976 |
return NULL; |
| 7977 |
} |
| 7978 |
|
| 7979 |
/* Handle the TARGET_INTERNAL_ARG_POINTER hook. */ |
| 7980 |
|
| 7981 |
static rtx |
| 7982 |
ix86_internal_arg_pointer (void) |
| 7983 |
{ |
| 7984 |
return virtual_incoming_args_rtx; |
| 7985 |
} |
| 7986 |
|
| 7987 |
struct scratch_reg { |
| 7988 |
rtx reg; |
| 7989 |
bool saved; |
| 7990 |
}; |
| 7991 |
|
| 7992 |
/* Return a short-lived scratch register for use on function entry. |
| 7993 |
In 32-bit mode, it is valid only after the registers are saved |
| 7994 |
in the prologue. This register must be released by means of |
| 7995 |
release_scratch_register_on_entry once it is dead. */ |
| 7996 |
|
| 7997 |
static void |
| 7998 |
get_scratch_register_on_entry (struct scratch_reg *sr) |
| 7999 |
{ |
| 8000 |
int regno; |
| 8001 |
|
| 8002 |
sr->saved = false; |
| 8003 |
|
| 8004 |
if (TARGET_64BIT) |
| 8005 |
{ |
| 8006 |
/* We always use R11 in 64-bit mode. */ |
| 8007 |
regno = R11_REG; |
| 8008 |
} |
| 8009 |
else |
| 8010 |
{ |
| 8011 |
tree decl = current_function_decl, fntype = TREE_TYPE (decl); |
| 8012 |
bool fastcall_p |
| 8013 |
= lookup_attribute ("fastcall", TYPE_ATTRIBUTES (fntype)) != NULL_TREE; |
| 8014 |
bool thiscall_p |
| 8015 |
= lookup_attribute ("thiscall", TYPE_ATTRIBUTES (fntype)) != NULL_TREE; |
| 8016 |
bool static_chain_p = DECL_STATIC_CHAIN (decl); |
| 8017 |
int regparm = ix86_function_regparm (fntype, decl); |
| 8018 |
int drap_regno |
| 8019 |
= crtl->drap_reg ? REGNO (crtl->drap_reg) : INVALID_REGNUM; |
| 8020 |
|
| 8021 |
/* 'fastcall' sets regparm to 2, uses ecx/edx for arguments and eax |
| 8022 |
for the static chain register. */ |
| 8023 |
if ((regparm < 1 || (fastcall_p && !static_chain_p)) |
| 8024 |
&& drap_regno != AX_REG) |
| 8025 |
regno = AX_REG; |
| 8026 |
/* 'thiscall' sets regparm to 1, uses ecx for arguments and edx |
| 8027 |
for the static chain register. */ |
| 8028 |
else if (thiscall_p && !static_chain_p && drap_regno != AX_REG) |
| 8029 |
regno = AX_REG; |
| 8030 |
else if (regparm < 2 && !thiscall_p && drap_regno != DX_REG) |
| 8031 |
regno = DX_REG; |
| 8032 |
/* ecx is the static chain register. */ |
| 8033 |
else if (regparm < 3 && !fastcall_p && !thiscall_p |
| 8034 |
&& !static_chain_p |
| 8035 |
&& drap_regno != CX_REG) |
| 8036 |
regno = CX_REG; |
| 8037 |
else if (ix86_save_reg (BX_REG, true, false)) |
| 8038 |
regno = BX_REG; |
| 8039 |
/* esi is the static chain register. */ |
| 8040 |
else if (!(regparm == 3 && static_chain_p) |
| 8041 |
&& ix86_save_reg (SI_REG, true, false)) |
| 8042 |
regno = SI_REG; |
| 8043 |
else if (ix86_save_reg (DI_REG, true, false)) |
| 8044 |
regno = DI_REG; |
| 8045 |
else |
| 8046 |
{ |
| 8047 |
regno = (drap_regno == AX_REG ? DX_REG : AX_REG); |
| 8048 |
sr->saved = true; |
| 8049 |
} |
| 8050 |
} |
| 8051 |
|
| 8052 |
sr->reg = gen_rtx_REG (Pmode, regno); |
| 8053 |
if (sr->saved) |
| 8054 |
{ |
| 8055 |
rtx_insn *insn = emit_insn (gen_push (sr->reg)); |
| 8056 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 8057 |
} |
| 8058 |
} |
| 8059 |
|
| 8060 |
/* Release a scratch register obtained from the preceding function. |
| 8061 |
|
| 8062 |
If RELEASE_VIA_POP is true, we just pop the register off the stack |
| 8063 |
to release it. This is what non-Linux systems use with -fstack-check. |
| 8064 |
|
| 8065 |
Otherwise we use OFFSET to locate the saved register and the |
| 8066 |
allocated stack space becomes part of the local frame and is |
| 8067 |
deallocated by the epilogue. */ |
| 8068 |
|
| 8069 |
static void |
| 8070 |
release_scratch_register_on_entry (struct scratch_reg *sr, HOST_WIDE_INT offset, |
| 8071 |
bool release_via_pop) |
| 8072 |
{ |
| 8073 |
if (sr->saved) |
| 8074 |
{ |
| 8075 |
if (release_via_pop) |
| 8076 |
{ |
| 8077 |
struct machine_function *m = cfun->machine; |
| 8078 |
rtx x, insn = emit_insn (gen_pop (sr->reg)); |
| 8079 |
|
| 8080 |
/* The RX FRAME_RELATED_P mechanism doesn't know about pop. */ |
| 8081 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 8082 |
x = plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD); |
| 8083 |
x = gen_rtx_SET (stack_pointer_rtx, x); |
| 8084 |
add_reg_note (insn, REG_FRAME_RELATED_EXPR, x); |
| 8085 |
m->fs.sp_offset -= UNITS_PER_WORD; |
| 8086 |
} |
| 8087 |
else |
| 8088 |
{ |
| 8089 |
rtx x = plus_constant (Pmode, stack_pointer_rtx, offset); |
| 8090 |
x = gen_rtx_SET (sr->reg, gen_rtx_MEM (word_mode, x)); |
| 8091 |
emit_insn (x); |
| 8092 |
} |
| 8093 |
} |
| 8094 |
} |
| 8095 |
|
| 8096 |
/* Emit code to adjust the stack pointer by SIZE bytes while probing it. |
| 8097 |
|
| 8098 |
If INT_REGISTERS_SAVED is true, then integer registers have already been |
| 8099 |
pushed on the stack. |
| 8100 |
|
| 8101 |
If PROTECTION AREA is true, then probe PROBE_INTERVAL plus a small dope |
| 8102 |
beyond SIZE bytes. |
| 8103 |
|
| 8104 |
This assumes no knowledge of the current probing state, i.e. it is never |
| 8105 |
allowed to allocate more than PROBE_INTERVAL bytes of stack space without |
| 8106 |
a suitable probe. */ |
| 8107 |
|
| 8108 |
static void |
| 8109 |
ix86_adjust_stack_and_probe (HOST_WIDE_INT size, |
| 8110 |
const bool int_registers_saved, |
| 8111 |
const bool protection_area) |
| 8112 |
{ |
| 8113 |
struct machine_function *m = cfun->machine; |
| 8114 |
|
| 8115 |
/* If this function does not statically allocate stack space, then |
| 8116 |
no probes are needed. */ |
| 8117 |
if (!size) |
| 8118 |
{ |
| 8119 |
/* However, the allocation of space via pushes for register |
| 8120 |
saves could be viewed as allocating space, but without the |
| 8121 |
need to probe. */ |
| 8122 |
if (m->frame.nregs || m->frame.nsseregs || frame_pointer_needed) |
| 8123 |
dump_stack_clash_frame_info (NO_PROBE_SMALL_FRAME, true); |
| 8124 |
else |
| 8125 |
dump_stack_clash_frame_info (NO_PROBE_NO_FRAME, false); |
| 8126 |
return; |
| 8127 |
} |
| 8128 |
|
| 8129 |
/* If we are a noreturn function, then we have to consider the |
| 8130 |
possibility that we're called via a jump rather than a call. |
| 8131 |
|
| 8132 |
Thus we don't have the implicit probe generated by saving the |
| 8133 |
return address into the stack at the call. Thus, the stack |
| 8134 |
pointer could be anywhere in the guard page. The safe thing |
| 8135 |
to do is emit a probe now. |
| 8136 |
|
| 8137 |
The probe can be avoided if we have already emitted any callee |
| 8138 |
register saves into the stack or have a frame pointer (which will |
| 8139 |
have been saved as well). Those saves will function as implicit |
| 8140 |
probes. |
| 8141 |
|
| 8142 |
?!? This should be revamped to work like aarch64 and s390 where |
| 8143 |
we track the offset from the most recent probe. Normally that |
| 8144 |
offset would be zero. For a noreturn function we would reset |
| 8145 |
it to PROBE_INTERVAL - (STACK_BOUNDARY / BITS_PER_UNIT). Then |
| 8146 |
we just probe when we cross PROBE_INTERVAL. */ |
| 8147 |
if (TREE_THIS_VOLATILE (cfun->decl) |
| 8148 |
&& !(m->frame.nregs || m->frame.nsseregs || frame_pointer_needed)) |
| 8149 |
{ |
| 8150 |
/* We can safely use any register here since we're just going to push |
| 8151 |
its value and immediately pop it back. But we do try and avoid |
| 8152 |
argument passing registers so as not to introduce dependencies in |
| 8153 |
the pipeline. For 32 bit we use %esi and for 64 bit we use %rax. */ |
| 8154 |
rtx dummy_reg = gen_rtx_REG (word_mode, TARGET_64BIT ? AX_REG : SI_REG); |
| 8155 |
rtx_insn *insn_push = emit_insn (gen_push (dummy_reg)); |
| 8156 |
rtx_insn *insn_pop = emit_insn (gen_pop (dummy_reg)); |
| 8157 |
m->fs.sp_offset -= UNITS_PER_WORD; |
| 8158 |
if (m->fs.cfa_reg == stack_pointer_rtx) |
| 8159 |
{ |
| 8160 |
m->fs.cfa_offset -= UNITS_PER_WORD; |
| 8161 |
rtx x = plus_constant (Pmode, stack_pointer_rtx, -UNITS_PER_WORD); |
| 8162 |
x = gen_rtx_SET (stack_pointer_rtx, x); |
| 8163 |
add_reg_note (insn_push, REG_CFA_ADJUST_CFA, x); |
| 8164 |
RTX_FRAME_RELATED_P (insn_push) = 1; |
| 8165 |
x = plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD); |
| 8166 |
x = gen_rtx_SET (stack_pointer_rtx, x); |
| 8167 |
add_reg_note (insn_pop, REG_CFA_ADJUST_CFA, x); |
| 8168 |
RTX_FRAME_RELATED_P (insn_pop) = 1; |
| 8169 |
} |
| 8170 |
emit_insn (gen_blockage ()); |
| 8171 |
} |
| 8172 |
|
| 8173 |
const HOST_WIDE_INT probe_interval = get_probe_interval (); |
| 8174 |
const int dope = 4 * UNITS_PER_WORD; |
| 8175 |
|
| 8176 |
/* If there is protection area, take it into account in the size. */ |
| 8177 |
if (protection_area) |
| 8178 |
size += probe_interval + dope; |
| 8179 |
|
| 8180 |
/* If we allocate less than the size of the guard statically, |
| 8181 |
then no probing is necessary, but we do need to allocate |
| 8182 |
the stack. */ |
| 8183 |
else if (size < (1 << param_stack_clash_protection_guard_size)) |
| 8184 |
{ |
| 8185 |
pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx, |
| 8186 |
GEN_INT (-size), -1, |
| 8187 |
m->fs.cfa_reg == stack_pointer_rtx); |
| 8188 |
dump_stack_clash_frame_info (NO_PROBE_SMALL_FRAME, true); |
| 8189 |
return; |
| 8190 |
} |
| 8191 |
|
| 8192 |
/* We're allocating a large enough stack frame that we need to |
| 8193 |
emit probes. Either emit them inline or in a loop depending |
| 8194 |
on the size. */ |
| 8195 |
if (size <= 4 * probe_interval) |
| 8196 |
{ |
| 8197 |
HOST_WIDE_INT i; |
| 8198 |
for (i = probe_interval; i <= size; i += probe_interval) |
| 8199 |
{ |
| 8200 |
/* Allocate PROBE_INTERVAL bytes. */ |
| 8201 |
rtx insn |
| 8202 |
= pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx, |
| 8203 |
GEN_INT (-probe_interval), -1, |
| 8204 |
m->fs.cfa_reg == stack_pointer_rtx); |
| 8205 |
add_reg_note (insn, REG_STACK_CHECK, const0_rtx); |
| 8206 |
|
| 8207 |
/* And probe at *sp. */ |
| 8208 |
emit_stack_probe (stack_pointer_rtx); |
| 8209 |
emit_insn (gen_blockage ()); |
| 8210 |
} |
| 8211 |
|
| 8212 |
/* We need to allocate space for the residual, but we do not need |
| 8213 |
to probe the residual... */ |
| 8214 |
HOST_WIDE_INT residual = (i - probe_interval - size); |
| 8215 |
if (residual) |
| 8216 |
{ |
| 8217 |
pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx, |
| 8218 |
GEN_INT (residual), -1, |
| 8219 |
m->fs.cfa_reg == stack_pointer_rtx); |
| 8220 |
|
| 8221 |
/* ...except if there is a protection area to maintain. */ |
| 8222 |
if (protection_area) |
| 8223 |
emit_stack_probe (stack_pointer_rtx); |
| 8224 |
} |
| 8225 |
|
| 8226 |
dump_stack_clash_frame_info (PROBE_INLINE, residual != 0); |
| 8227 |
} |
| 8228 |
else |
| 8229 |
{ |
| 8230 |
/* We expect the GP registers to be saved when probes are used |
| 8231 |
as the probing sequences might need a scratch register and |
| 8232 |
the routine to allocate one assumes the integer registers |
| 8233 |
have already been saved. */ |
| 8234 |
gcc_assert (int_registers_saved); |
| 8235 |
|
| 8236 |
struct scratch_reg sr; |
| 8237 |
get_scratch_register_on_entry (&sr); |
| 8238 |
|
| 8239 |
/* If we needed to save a register, then account for any space |
| 8240 |
that was pushed (we are not going to pop the register when |
| 8241 |
we do the restore). */ |
| 8242 |
if (sr.saved) |
| 8243 |
size -= UNITS_PER_WORD; |
| 8244 |
|
| 8245 |
/* Step 1: round SIZE down to a multiple of the interval. */ |
| 8246 |
HOST_WIDE_INT rounded_size = size & -probe_interval; |
| 8247 |
|
| 8248 |
/* Step 2: compute final value of the loop counter. Use lea if |
| 8249 |
possible. */ |
| 8250 |
rtx addr = plus_constant (Pmode, stack_pointer_rtx, -rounded_size); |
| 8251 |
rtx insn; |
| 8252 |
if (address_no_seg_operand (addr, Pmode)) |
| 8253 |
insn = emit_insn (gen_rtx_SET (sr.reg, addr)); |
| 8254 |
else |
| 8255 |
{ |
| 8256 |
emit_move_insn (sr.reg, GEN_INT (-rounded_size)); |
| 8257 |
insn = emit_insn (gen_rtx_SET (sr.reg, |
| 8258 |
gen_rtx_PLUS (Pmode, sr.reg, |
| 8259 |
stack_pointer_rtx))); |
| 8260 |
} |
| 8261 |
if (m->fs.cfa_reg == stack_pointer_rtx) |
| 8262 |
{ |
| 8263 |
add_reg_note (insn, REG_CFA_DEF_CFA, |
| 8264 |
plus_constant (Pmode, sr.reg, |
| 8265 |
m->fs.cfa_offset + rounded_size)); |
| 8266 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 8267 |
} |
| 8268 |
|
| 8269 |
/* Step 3: the loop. */ |
| 8270 |
rtx size_rtx = GEN_INT (rounded_size); |
| 8271 |
insn = emit_insn (gen_adjust_stack_and_probe (Pmode, sr.reg, sr.reg, |
| 8272 |
size_rtx)); |
| 8273 |
if (m->fs.cfa_reg == stack_pointer_rtx) |
| 8274 |
{ |
| 8275 |
m->fs.cfa_offset += rounded_size; |
| 8276 |
add_reg_note (insn, REG_CFA_DEF_CFA, |
| 8277 |
plus_constant (Pmode, stack_pointer_rtx, |
| 8278 |
m->fs.cfa_offset)); |
| 8279 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 8280 |
} |
| 8281 |
m->fs.sp_offset += rounded_size; |
| 8282 |
emit_insn (gen_blockage ()); |
| 8283 |
|
| 8284 |
/* Step 4: adjust SP if we cannot assert at compile-time that SIZE |
| 8285 |
is equal to ROUNDED_SIZE. */ |
| 8286 |
|
| 8287 |
if (size != rounded_size) |
| 8288 |
{ |
| 8289 |
pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx, |
| 8290 |
GEN_INT (rounded_size - size), -1, |
| 8291 |
m->fs.cfa_reg == stack_pointer_rtx); |
| 8292 |
|
| 8293 |
if (protection_area) |
| 8294 |
emit_stack_probe (stack_pointer_rtx); |
| 8295 |
} |
| 8296 |
|
| 8297 |
dump_stack_clash_frame_info (PROBE_LOOP, size != rounded_size); |
| 8298 |
|
| 8299 |
/* This does not deallocate the space reserved for the scratch |
| 8300 |
register. That will be deallocated in the epilogue. */ |
| 8301 |
release_scratch_register_on_entry (&sr, size, false); |
| 8302 |
} |
| 8303 |
|
| 8304 |
/* Adjust back to account for the protection area. */ |
| 8305 |
if (protection_area) |
| 8306 |
pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx, |
| 8307 |
GEN_INT (probe_interval + dope), -1, |
| 8308 |
m->fs.cfa_reg == stack_pointer_rtx); |
| 8309 |
|
| 8310 |
/* Make sure nothing is scheduled before we are done. */ |
| 8311 |
emit_insn (gen_blockage ()); |
| 8312 |
} |
| 8313 |
|
| 8314 |
/* Adjust the stack pointer up to REG while probing it. */ |
| 8315 |
|
| 8316 |
const char * |
| 8317 |
output_adjust_stack_and_probe (rtx reg) |
| 8318 |
{ |
| 8319 |
static int labelno = 0; |
| 8320 |
char loop_lab[32]; |
| 8321 |
rtx xops[2]; |
| 8322 |
|
| 8323 |
ASM_GENERATE_INTERNAL_LABEL (loop_lab, "LPSRL", labelno++); |
| 8324 |
|
| 8325 |
/* Loop. */ |
| 8326 |
ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, loop_lab); |
| 8327 |
|
| 8328 |
/* SP = SP + PROBE_INTERVAL. */ |
| 8329 |
xops[0] = stack_pointer_rtx; |
| 8330 |
xops[1] = GEN_INT (get_probe_interval ()); |
| 8331 |
output_asm_insn ("sub%z0\t{%1, %0|%0, %1}", xops); |
| 8332 |
|
| 8333 |
/* Probe at SP. */ |
| 8334 |
xops[1] = const0_rtx; |
| 8335 |
output_asm_insn ("or%z0\t{%1, (%0)|DWORD PTR [%0], %1}", xops); |
| 8336 |
|
| 8337 |
/* Test if SP == LAST_ADDR. */ |
| 8338 |
xops[0] = stack_pointer_rtx; |
| 8339 |
xops[1] = reg; |
| 8340 |
output_asm_insn ("cmp%z0\t{%1, %0|%0, %1}", xops); |
| 8341 |
|
| 8342 |
/* Branch. */ |
| 8343 |
fputs ("\tjne\t", asm_out_file); |
| 8344 |
assemble_name_raw (asm_out_file, loop_lab); |
| 8345 |
fputc ('\n', asm_out_file); |
| 8346 |
|
| 8347 |
return ""; |
| 8348 |
} |
| 8349 |
|
| 8350 |
/* Emit code to probe a range of stack addresses from FIRST to FIRST+SIZE, |
| 8351 |
inclusive. These are offsets from the current stack pointer. |
| 8352 |
|
| 8353 |
INT_REGISTERS_SAVED is true if integer registers have already been |
| 8354 |
pushed on the stack. */ |
| 8355 |
|
| 8356 |
static void |
| 8357 |
ix86_emit_probe_stack_range (HOST_WIDE_INT first, HOST_WIDE_INT size, |
| 8358 |
const bool int_registers_saved) |
| 8359 |
{ |
| 8360 |
const HOST_WIDE_INT probe_interval = get_probe_interval (); |
| 8361 |
|
| 8362 |
/* See if we have a constant small number of probes to generate. If so, |
| 8363 |
that's the easy case. The run-time loop is made up of 6 insns in the |
| 8364 |
generic case while the compile-time loop is made up of n insns for n # |
| 8365 |
of intervals. */ |
| 8366 |
if (size <= 6 * probe_interval) |
| 8367 |
{ |
| 8368 |
HOST_WIDE_INT i; |
| 8369 |
|
| 8370 |
/* Probe at FIRST + N * PROBE_INTERVAL for values of N from 1 until |
| 8371 |
it exceeds SIZE. If only one probe is needed, this will not |
| 8372 |
generate any code. Then probe at FIRST + SIZE. */ |
| 8373 |
for (i = probe_interval; i < size; i += probe_interval) |
| 8374 |
emit_stack_probe (plus_constant (Pmode, stack_pointer_rtx, |
| 8375 |
-(first + i))); |
| 8376 |
|
| 8377 |
emit_stack_probe (plus_constant (Pmode, stack_pointer_rtx, |
| 8378 |
-(first + size))); |
| 8379 |
} |
| 8380 |
|
| 8381 |
/* Otherwise, do the same as above, but in a loop. Note that we must be |
| 8382 |
extra careful with variables wrapping around because we might be at |
| 8383 |
the very top (or the very bottom) of the address space and we have |
| 8384 |
to be able to handle this case properly; in particular, we use an |
| 8385 |
equality test for the loop condition. */ |
| 8386 |
else |
| 8387 |
{ |
| 8388 |
/* We expect the GP registers to be saved when probes are used |
| 8389 |
as the probing sequences might need a scratch register and |
| 8390 |
the routine to allocate one assumes the integer registers |
| 8391 |
have already been saved. */ |
| 8392 |
gcc_assert (int_registers_saved); |
| 8393 |
|
| 8394 |
HOST_WIDE_INT rounded_size, last; |
| 8395 |
struct scratch_reg sr; |
| 8396 |
|
| 8397 |
get_scratch_register_on_entry (&sr); |
| 8398 |
|
| 8399 |
|
| 8400 |
/* Step 1: round SIZE to the previous multiple of the interval. */ |
| 8401 |
|
| 8402 |
rounded_size = ROUND_DOWN (size, probe_interval); |
| 8403 |
|
| 8404 |
|
| 8405 |
/* Step 2: compute initial and final value of the loop counter. */ |
| 8406 |
|
| 8407 |
/* TEST_OFFSET = FIRST. */ |
| 8408 |
emit_move_insn (sr.reg, GEN_INT (-first)); |
| 8409 |
|
| 8410 |
/* LAST_OFFSET = FIRST + ROUNDED_SIZE. */ |
| 8411 |
last = first + rounded_size; |
| 8412 |
|
| 8413 |
|
| 8414 |
/* Step 3: the loop |
| 8415 |
|
| 8416 |
do |
| 8417 |
{ |
| 8418 |
TEST_ADDR = TEST_ADDR + PROBE_INTERVAL |
| 8419 |
probe at TEST_ADDR |
| 8420 |
} |
| 8421 |
while (TEST_ADDR != LAST_ADDR) |
| 8422 |
|
| 8423 |
probes at FIRST + N * PROBE_INTERVAL for values of N from 1 |
| 8424 |
until it is equal to ROUNDED_SIZE. */ |
| 8425 |
|
| 8426 |
emit_insn |
| 8427 |
(gen_probe_stack_range (Pmode, sr.reg, sr.reg, GEN_INT (-last))); |
| 8428 |
|
| 8429 |
|
| 8430 |
/* Step 4: probe at FIRST + SIZE if we cannot assert at compile-time |
| 8431 |
that SIZE is equal to ROUNDED_SIZE. */ |
| 8432 |
|
| 8433 |
if (size != rounded_size) |
| 8434 |
emit_stack_probe (plus_constant (Pmode, |
| 8435 |
gen_rtx_PLUS (Pmode, |
| 8436 |
stack_pointer_rtx, |
| 8437 |
sr.reg), |
| 8438 |
rounded_size - size)); |
| 8439 |
|
| 8440 |
release_scratch_register_on_entry (&sr, size, true); |
| 8441 |
} |
| 8442 |
|
| 8443 |
/* Make sure nothing is scheduled before we are done. */ |
| 8444 |
emit_insn (gen_blockage ()); |
| 8445 |
} |
| 8446 |
|
| 8447 |
/* Probe a range of stack addresses from REG to END, inclusive. These are |
| 8448 |
offsets from the current stack pointer. */ |
| 8449 |
|
| 8450 |
const char * |
| 8451 |
output_probe_stack_range (rtx reg, rtx end) |
| 8452 |
{ |
| 8453 |
static int labelno = 0; |
| 8454 |
char loop_lab[32]; |
| 8455 |
rtx xops[3]; |
| 8456 |
|
| 8457 |
ASM_GENERATE_INTERNAL_LABEL (loop_lab, "LPSRL", labelno++); |
| 8458 |
|
| 8459 |
/* Loop. */ |
| 8460 |
ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, loop_lab); |
| 8461 |
|
| 8462 |
/* TEST_ADDR = TEST_ADDR + PROBE_INTERVAL. */ |
| 8463 |
xops[0] = reg; |
| 8464 |
xops[1] = GEN_INT (get_probe_interval ()); |
| 8465 |
output_asm_insn ("sub%z0\t{%1, %0|%0, %1}", xops); |
| 8466 |
|
| 8467 |
/* Probe at TEST_ADDR. */ |
| 8468 |
xops[0] = stack_pointer_rtx; |
| 8469 |
xops[1] = reg; |
| 8470 |
xops[2] = const0_rtx; |
| 8471 |
output_asm_insn ("or%z0\t{%2, (%0,%1)|DWORD PTR [%0+%1], %2}", xops); |
| 8472 |
|
| 8473 |
/* Test if TEST_ADDR == LAST_ADDR. */ |
| 8474 |
xops[0] = reg; |
| 8475 |
xops[1] = end; |
| 8476 |
output_asm_insn ("cmp%z0\t{%1, %0|%0, %1}", xops); |
| 8477 |
|
| 8478 |
/* Branch. */ |
| 8479 |
fputs ("\tjne\t", asm_out_file); |
| 8480 |
assemble_name_raw (asm_out_file, loop_lab); |
| 8481 |
fputc ('\n', asm_out_file); |
| 8482 |
|
| 8483 |
return ""; |
| 8484 |
} |
| 8485 |
|
| 8486 |
/* Set stack_frame_required to false if stack frame isn't required. |
| 8487 |
Update STACK_ALIGNMENT to the largest alignment, in bits, of stack |
| 8488 |
slot used if stack frame is required and CHECK_STACK_SLOT is true. */ |
| 8489 |
|
| 8490 |
static void |
| 8491 |
ix86_find_max_used_stack_alignment (unsigned int &stack_alignment, |
| 8492 |
bool check_stack_slot) |
| 8493 |
{ |
| 8494 |
HARD_REG_SET set_up_by_prologue, prologue_used; |
| 8495 |
basic_block bb; |
| 8496 |
|
| 8497 |
CLEAR_HARD_REG_SET (prologue_used); |
| 8498 |
CLEAR_HARD_REG_SET (set_up_by_prologue); |
| 8499 |
add_to_hard_reg_set (&set_up_by_prologue, Pmode, STACK_POINTER_REGNUM); |
| 8500 |
add_to_hard_reg_set (&set_up_by_prologue, Pmode, ARG_POINTER_REGNUM); |
| 8501 |
add_to_hard_reg_set (&set_up_by_prologue, Pmode, |
| 8502 |
HARD_FRAME_POINTER_REGNUM); |
| 8503 |
|
| 8504 |
/* The preferred stack alignment is the minimum stack alignment. */ |
| 8505 |
if (stack_alignment > crtl->preferred_stack_boundary) |
| 8506 |
stack_alignment = crtl->preferred_stack_boundary; |
| 8507 |
|
| 8508 |
bool require_stack_frame = false; |
| 8509 |
|
| 8510 |
FOR_EACH_BB_FN (bb, cfun) |
| 8511 |
{ |
| 8512 |
rtx_insn *insn; |
| 8513 |
FOR_BB_INSNS (bb, insn) |
| 8514 |
if (NONDEBUG_INSN_P (insn) |
| 8515 |
&& requires_stack_frame_p (insn, prologue_used, |
| 8516 |
set_up_by_prologue)) |
| 8517 |
{ |
| 8518 |
require_stack_frame = true; |
| 8519 |
|
| 8520 |
if (check_stack_slot) |
| 8521 |
{ |
| 8522 |
/* Find the maximum stack alignment. */ |
| 8523 |
subrtx_iterator::array_type array; |
| 8524 |
FOR_EACH_SUBRTX (iter, array, PATTERN (insn), ALL) |
| 8525 |
if (MEM_P (*iter) |
| 8526 |
&& (reg_mentioned_p (stack_pointer_rtx, |
| 8527 |
*iter) |
| 8528 |
|| reg_mentioned_p (frame_pointer_rtx, |
| 8529 |
*iter))) |
| 8530 |
{ |
| 8531 |
unsigned int alignment = MEM_ALIGN (*iter); |
| 8532 |
if (alignment > stack_alignment) |
| 8533 |
stack_alignment = alignment; |
| 8534 |
} |
| 8535 |
} |
| 8536 |
} |
| 8537 |
} |
| 8538 |
|
| 8539 |
cfun->machine->stack_frame_required = require_stack_frame; |
| 8540 |
} |
| 8541 |
|
| 8542 |
/* Finalize stack_realign_needed and frame_pointer_needed flags, which |
| 8543 |
will guide prologue/epilogue to be generated in correct form. */ |
| 8544 |
|
| 8545 |
static void |
| 8546 |
ix86_finalize_stack_frame_flags (void) |
| 8547 |
{ |
| 8548 |
/* Check if stack realign is really needed after reload, and |
| 8549 |
stores result in cfun */ |
| 8550 |
unsigned int incoming_stack_boundary |
| 8551 |
= (crtl->parm_stack_boundary > ix86_incoming_stack_boundary |
| 8552 |
? crtl->parm_stack_boundary : ix86_incoming_stack_boundary); |
| 8553 |
unsigned int stack_alignment |
| 8554 |
= (crtl->is_leaf && !ix86_current_function_calls_tls_descriptor |
| 8555 |
? crtl->max_used_stack_slot_alignment |
| 8556 |
: crtl->stack_alignment_needed); |
| 8557 |
unsigned int stack_realign |
| 8558 |
= (incoming_stack_boundary < stack_alignment); |
| 8559 |
bool recompute_frame_layout_p = false; |
| 8560 |
|
| 8561 |
if (crtl->stack_realign_finalized) |
| 8562 |
{ |
| 8563 |
/* After stack_realign_needed is finalized, we can't no longer |
| 8564 |
change it. */ |
| 8565 |
gcc_assert (crtl->stack_realign_needed == stack_realign); |
| 8566 |
return; |
| 8567 |
} |
| 8568 |
|
| 8569 |
/* It is always safe to compute max_used_stack_alignment. We |
| 8570 |
compute it only if 128-bit aligned load/store may be generated |
| 8571 |
on misaligned stack slot which will lead to segfault. */ |
| 8572 |
bool check_stack_slot |
| 8573 |
= (stack_realign || crtl->max_used_stack_slot_alignment >= 128); |
| 8574 |
ix86_find_max_used_stack_alignment (stack_alignment, |
| 8575 |
check_stack_slot); |
| 8576 |
|
| 8577 |
/* If the only reason for frame_pointer_needed is that we conservatively |
| 8578 |
assumed stack realignment might be needed or -fno-omit-frame-pointer |
| 8579 |
is used, but in the end nothing that needed the stack alignment had |
| 8580 |
been spilled nor stack access, clear frame_pointer_needed and say we |
| 8581 |
don't need stack realignment. |
| 8582 |
|
| 8583 |
When vector register is used for piecewise move and store, we don't |
| 8584 |
increase stack_alignment_needed as there is no register spill for |
| 8585 |
piecewise move and store. Since stack_realign_needed is set to true |
| 8586 |
by checking stack_alignment_estimated which is updated by pseudo |
| 8587 |
vector register usage, we also need to check stack_realign_needed to |
| 8588 |
eliminate frame pointer. */ |
| 8589 |
if ((stack_realign |
| 8590 |
|| (!flag_omit_frame_pointer && optimize) |
| 8591 |
|| crtl->stack_realign_needed) |
| 8592 |
&& frame_pointer_needed |
| 8593 |
&& crtl->is_leaf |
| 8594 |
&& crtl->sp_is_unchanging |
| 8595 |
&& !ix86_current_function_calls_tls_descriptor |
| 8596 |
&& !crtl->accesses_prior_frames |
| 8597 |
&& !cfun->calls_alloca |
| 8598 |
&& !crtl->calls_eh_return |
| 8599 |
/* See ira_setup_eliminable_regset for the rationale. */ |
| 8600 |
&& !(STACK_CHECK_MOVING_SP |
| 8601 |
&& flag_stack_check |
| 8602 |
&& flag_exceptions |
| 8603 |
&& cfun->can_throw_non_call_exceptions) |
| 8604 |
&& !ix86_frame_pointer_required () |
| 8605 |
&& ix86_get_frame_size () == 0 |
| 8606 |
&& ix86_nsaved_sseregs () == 0 |
| 8607 |
&& ix86_varargs_gpr_size + ix86_varargs_fpr_size == 0) |
| 8608 |
{ |
| 8609 |
if (cfun->machine->stack_frame_required) |
| 8610 |
{ |
| 8611 |
/* Stack frame is required. If stack alignment needed is less |
| 8612 |
than incoming stack boundary, don't realign stack. */ |
| 8613 |
stack_realign = incoming_stack_boundary < stack_alignment; |
| 8614 |
if (!stack_realign) |
| 8615 |
{ |
| 8616 |
crtl->max_used_stack_slot_alignment |
| 8617 |
= incoming_stack_boundary; |
| 8618 |
crtl->stack_alignment_needed |
| 8619 |
= incoming_stack_boundary; |
| 8620 |
/* Also update preferred_stack_boundary for leaf |
| 8621 |
functions. */ |
| 8622 |
crtl->preferred_stack_boundary |
| 8623 |
= incoming_stack_boundary; |
| 8624 |
} |
| 8625 |
} |
| 8626 |
else |
| 8627 |
{ |
| 8628 |
/* If drap has been set, but it actually isn't live at the |
| 8629 |
start of the function, there is no reason to set it up. */ |
| 8630 |
if (crtl->drap_reg) |
| 8631 |
{ |
| 8632 |
basic_block bb = ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb; |
| 8633 |
if (! REGNO_REG_SET_P (DF_LR_IN (bb), |
| 8634 |
REGNO (crtl->drap_reg))) |
| 8635 |
{ |
| 8636 |
crtl->drap_reg = NULL_RTX; |
| 8637 |
crtl->need_drap = false; |
| 8638 |
} |
| 8639 |
} |
| 8640 |
else |
| 8641 |
cfun->machine->no_drap_save_restore = true; |
| 8642 |
|
| 8643 |
frame_pointer_needed = false; |
| 8644 |
stack_realign = false; |
| 8645 |
crtl->max_used_stack_slot_alignment = incoming_stack_boundary; |
| 8646 |
crtl->stack_alignment_needed = incoming_stack_boundary; |
| 8647 |
crtl->stack_alignment_estimated = incoming_stack_boundary; |
| 8648 |
if (crtl->preferred_stack_boundary > incoming_stack_boundary) |
| 8649 |
crtl->preferred_stack_boundary = incoming_stack_boundary; |
| 8650 |
df_finish_pass (true); |
| 8651 |
df_scan_alloc (NULL); |
| 8652 |
df_scan_blocks (); |
| 8653 |
df_compute_regs_ever_live (true); |
| 8654 |
df_analyze (); |
| 8655 |
|
| 8656 |
if (flag_var_tracking) |
| 8657 |
{ |
| 8658 |
/* Since frame pointer is no longer available, replace it with |
| 8659 |
stack pointer - UNITS_PER_WORD in debug insns. */ |
| 8660 |
df_ref ref, next; |
| 8661 |
for (ref = DF_REG_USE_CHAIN (HARD_FRAME_POINTER_REGNUM); |
| 8662 |
ref; ref = next) |
| 8663 |
{ |
| 8664 |
next = DF_REF_NEXT_REG (ref); |
| 8665 |
if (!DF_REF_INSN_INFO (ref)) |
| 8666 |
continue; |
| 8667 |
|
| 8668 |
/* Make sure the next ref is for a different instruction, |
| 8669 |
so that we're not affected by the rescan. */ |
| 8670 |
rtx_insn *insn = DF_REF_INSN (ref); |
| 8671 |
while (next && DF_REF_INSN (next) == insn) |
| 8672 |
next = DF_REF_NEXT_REG (next); |
| 8673 |
|
| 8674 |
if (DEBUG_INSN_P (insn)) |
| 8675 |
{ |
| 8676 |
bool changed = false; |
| 8677 |
for (; ref != next; ref = DF_REF_NEXT_REG (ref)) |
| 8678 |
{ |
| 8679 |
rtx *loc = DF_REF_LOC (ref); |
| 8680 |
if (*loc == hard_frame_pointer_rtx) |
| 8681 |
{ |
| 8682 |
*loc = plus_constant (Pmode, |
| 8683 |
stack_pointer_rtx, |
| 8684 |
-UNITS_PER_WORD); |
| 8685 |
changed = true; |
| 8686 |
} |
| 8687 |
} |
| 8688 |
if (changed) |
| 8689 |
df_insn_rescan (insn); |
| 8690 |
} |
| 8691 |
} |
| 8692 |
} |
| 8693 |
|
| 8694 |
recompute_frame_layout_p = true; |
| 8695 |
} |
| 8696 |
} |
| 8697 |
else if (crtl->max_used_stack_slot_alignment >= 128 |
| 8698 |
&& cfun->machine->stack_frame_required) |
| 8699 |
{ |
| 8700 |
/* We don't need to realign stack. max_used_stack_alignment is |
| 8701 |
used to decide how stack frame should be aligned. This is |
| 8702 |
independent of any psABIs nor 32-bit vs 64-bit. */ |
| 8703 |
cfun->machine->max_used_stack_alignment |
| 8704 |
= stack_alignment / BITS_PER_UNIT; |
| 8705 |
} |
| 8706 |
|
| 8707 |
if (crtl->stack_realign_needed != stack_realign) |
| 8708 |
recompute_frame_layout_p = true; |
| 8709 |
crtl->stack_realign_needed = stack_realign; |
| 8710 |
crtl->stack_realign_finalized = true; |
| 8711 |
if (recompute_frame_layout_p) |
| 8712 |
ix86_compute_frame_layout (); |
| 8713 |
} |
| 8714 |
|
| 8715 |
/* Delete SET_GOT right after entry block if it is allocated to reg. */ |
| 8716 |
|
| 8717 |
static void |
| 8718 |
ix86_elim_entry_set_got (rtx reg) |
| 8719 |
{ |
| 8720 |
basic_block bb = ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb; |
| 8721 |
rtx_insn *c_insn = BB_HEAD (bb); |
| 8722 |
if (!NONDEBUG_INSN_P (c_insn)) |
| 8723 |
c_insn = next_nonnote_nondebug_insn (c_insn); |
| 8724 |
if (c_insn && NONJUMP_INSN_P (c_insn)) |
| 8725 |
{ |
| 8726 |
rtx pat = PATTERN (c_insn); |
| 8727 |
if (GET_CODE (pat) == PARALLEL) |
| 8728 |
{ |
| 8729 |
rtx set = XVECEXP (pat, 0, 0); |
| 8730 |
if (GET_CODE (set) == SET |
| 8731 |
&& GET_CODE (SET_SRC (set)) == UNSPEC |
| 8732 |
&& XINT (SET_SRC (set), 1) == UNSPEC_SET_GOT |
| 8733 |
&& REGNO (SET_DEST (set)) == REGNO (reg)) |
| 8734 |
delete_insn (c_insn); |
| 8735 |
} |
| 8736 |
} |
| 8737 |
} |
| 8738 |
|
| 8739 |
static rtx |
| 8740 |
gen_frame_set (rtx reg, rtx frame_reg, int offset, bool store) |
| 8741 |
{ |
| 8742 |
rtx addr, mem; |
| 8743 |
|
| 8744 |
if (offset) |
| 8745 |
addr = plus_constant (Pmode, frame_reg, offset); |
| 8746 |
mem = gen_frame_mem (GET_MODE (reg), offset ? addr : frame_reg); |
| 8747 |
return gen_rtx_SET (store ? mem : reg, store ? reg : mem); |
| 8748 |
} |
| 8749 |
|
| 8750 |
static inline rtx |
| 8751 |
gen_frame_load (rtx reg, rtx frame_reg, int offset) |
| 8752 |
{ |
| 8753 |
return gen_frame_set (reg, frame_reg, offset, false); |
| 8754 |
} |
| 8755 |
|
| 8756 |
static inline rtx |
| 8757 |
gen_frame_store (rtx reg, rtx frame_reg, int offset) |
| 8758 |
{ |
| 8759 |
return gen_frame_set (reg, frame_reg, offset, true); |
| 8760 |
} |
| 8761 |
|
| 8762 |
static void |
| 8763 |
ix86_emit_outlined_ms2sysv_save (const struct ix86_frame &frame) |
| 8764 |
{ |
| 8765 |
struct machine_function *m = cfun->machine; |
| 8766 |
const unsigned ncregs = NUM_X86_64_MS_CLOBBERED_REGS |
| 8767 |
+ m->call_ms2sysv_extra_regs; |
| 8768 |
rtvec v = rtvec_alloc (ncregs + 1); |
| 8769 |
unsigned int align, i, vi = 0; |
| 8770 |
rtx_insn *insn; |
| 8771 |
rtx sym, addr; |
| 8772 |
rtx rax = gen_rtx_REG (word_mode, AX_REG); |
| 8773 |
const class xlogue_layout &xlogue = xlogue_layout::get_instance (); |
| 8774 |
|
| 8775 |
/* AL should only be live with sysv_abi. */ |
| 8776 |
gcc_assert (!ix86_eax_live_at_start_p ()); |
| 8777 |
gcc_assert (m->fs.sp_offset >= frame.sse_reg_save_offset); |
| 8778 |
|
| 8779 |
/* Setup RAX as the stub's base pointer. We use stack_realign_offset rather |
| 8780 |
we've actually realigned the stack or not. */ |
| 8781 |
align = GET_MODE_ALIGNMENT (V4SFmode); |
| 8782 |
addr = choose_baseaddr (frame.stack_realign_offset |
| 8783 |
+ xlogue.get_stub_ptr_offset (), &align, AX_REG); |
| 8784 |
gcc_assert (align >= GET_MODE_ALIGNMENT (V4SFmode)); |
| 8785 |
|
| 8786 |
emit_insn (gen_rtx_SET (rax, addr)); |
| 8787 |
|
| 8788 |
/* Get the stub symbol. */ |
| 8789 |
sym = xlogue.get_stub_rtx (frame_pointer_needed ? XLOGUE_STUB_SAVE_HFP |
| 8790 |
: XLOGUE_STUB_SAVE); |
| 8791 |
RTVEC_ELT (v, vi++) = gen_rtx_USE (VOIDmode, sym); |
| 8792 |
|
| 8793 |
for (i = 0; i < ncregs; ++i) |
| 8794 |
{ |
| 8795 |
const xlogue_layout::reginfo &r = xlogue.get_reginfo (i); |
| 8796 |
rtx reg = gen_rtx_REG ((SSE_REGNO_P (r.regno) ? V4SFmode : word_mode), |
| 8797 |
r.regno); |
| 8798 |
RTVEC_ELT (v, vi++) = gen_frame_store (reg, rax, -r.offset); |
| 8799 |
} |
| 8800 |
|
| 8801 |
gcc_assert (vi == (unsigned)GET_NUM_ELEM (v)); |
| 8802 |
|
| 8803 |
insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, v)); |
| 8804 |
RTX_FRAME_RELATED_P (insn) = true; |
| 8805 |
} |
| 8806 |
|
| 8807 |
/* Generate and return an insn body to AND X with Y. */ |
| 8808 |
|
| 8809 |
static rtx_insn * |
| 8810 |
gen_and2_insn (rtx x, rtx y) |
| 8811 |
{ |
| 8812 |
enum insn_code icode = optab_handler (and_optab, GET_MODE (x)); |
| 8813 |
|
| 8814 |
gcc_assert (insn_operand_matches (icode, 0, x)); |
| 8815 |
gcc_assert (insn_operand_matches (icode, 1, x)); |
| 8816 |
gcc_assert (insn_operand_matches (icode, 2, y)); |
| 8817 |
|
| 8818 |
return GEN_FCN (icode) (x, x, y); |
| 8819 |
} |
| 8820 |
|
| 8821 |
/* Expand the prologue into a bunch of separate insns. */ |
| 8822 |
|
| 8823 |
void |
| 8824 |
ix86_expand_prologue (void) |
| 8825 |
{ |
| 8826 |
struct machine_function *m = cfun->machine; |
| 8827 |
rtx insn, t; |
| 8828 |
HOST_WIDE_INT allocate; |
| 8829 |
bool int_registers_saved; |
| 8830 |
bool sse_registers_saved; |
| 8831 |
bool save_stub_call_needed; |
| 8832 |
rtx static_chain = NULL_RTX; |
| 8833 |
|
| 8834 |
ix86_last_zero_store_uid = 0; |
| 8835 |
if (ix86_function_naked (current_function_decl)) |
| 8836 |
{ |
| 8837 |
if (flag_stack_usage_info) |
| 8838 |
current_function_static_stack_size = 0; |
| 8839 |
return; |
| 8840 |
} |
| 8841 |
|
| 8842 |
ix86_finalize_stack_frame_flags (); |
| 8843 |
|
| 8844 |
/* DRAP should not coexist with stack_realign_fp */ |
| 8845 |
gcc_assert (!(crtl->drap_reg && stack_realign_fp)); |
| 8846 |
|
| 8847 |
memset (&m->fs, 0, sizeof (m->fs)); |
| 8848 |
|
| 8849 |
/* Initialize CFA state for before the prologue. */ |
| 8850 |
m->fs.cfa_reg = stack_pointer_rtx; |
| 8851 |
m->fs.cfa_offset = INCOMING_FRAME_SP_OFFSET; |
| 8852 |
|
| 8853 |
/* Track SP offset to the CFA. We continue tracking this after we've |
| 8854 |
swapped the CFA register away from SP. In the case of re-alignment |
| 8855 |
this is fudged; we're interested to offsets within the local frame. */ |
| 8856 |
m->fs.sp_offset = INCOMING_FRAME_SP_OFFSET; |
| 8857 |
m->fs.sp_valid = true; |
| 8858 |
m->fs.sp_realigned = false; |
| 8859 |
|
| 8860 |
const struct ix86_frame &frame = cfun->machine->frame; |
| 8861 |
|
| 8862 |
if (!TARGET_64BIT && ix86_function_ms_hook_prologue (current_function_decl)) |
| 8863 |
{ |
| 8864 |
/* We should have already generated an error for any use of |
| 8865 |
ms_hook on a nested function. */ |
| 8866 |
gcc_checking_assert (!ix86_static_chain_on_stack); |
| 8867 |
|
| 8868 |
/* Check if profiling is active and we shall use profiling before |
| 8869 |
prologue variant. If so sorry. */ |
| 8870 |
if (crtl->profile && flag_fentry != 0) |
| 8871 |
sorry ("%<ms_hook_prologue%> attribute is not compatible " |
| 8872 |
"with %<-mfentry%> for 32-bit"); |
| 8873 |
|
| 8874 |
/* In ix86_asm_output_function_label we emitted: |
| 8875 |
8b ff movl.s %edi,%edi |
| 8876 |
55 push %ebp |
| 8877 |
8b ec movl.s %esp,%ebp |
| 8878 |
|
| 8879 |
This matches the hookable function prologue in Win32 API |
| 8880 |
functions in Microsoft Windows XP Service Pack 2 and newer. |
| 8881 |
Wine uses this to enable Windows apps to hook the Win32 API |
| 8882 |
functions provided by Wine. |
| 8883 |
|
| 8884 |
What that means is that we've already set up the frame pointer. */ |
| 8885 |
|
| 8886 |
if (frame_pointer_needed |
| 8887 |
&& !(crtl->drap_reg && crtl->stack_realign_needed)) |
| 8888 |
{ |
| 8889 |
rtx push, mov; |
| 8890 |
|
| 8891 |
/* We've decided to use the frame pointer already set up. |
| 8892 |
Describe this to the unwinder by pretending that both |
| 8893 |
push and mov insns happen right here. |
| 8894 |
|
| 8895 |
Putting the unwind info here at the end of the ms_hook |
| 8896 |
is done so that we can make absolutely certain we get |
| 8897 |
the required byte sequence at the start of the function, |
| 8898 |
rather than relying on an assembler that can produce |
| 8899 |
the exact encoding required. |
| 8900 |
|
| 8901 |
However it does mean (in the unpatched case) that we have |
| 8902 |
a 1 insn window where the asynchronous unwind info is |
| 8903 |
incorrect. However, if we placed the unwind info at |
| 8904 |
its correct location we would have incorrect unwind info |
| 8905 |
in the patched case. Which is probably all moot since |
| 8906 |
I don't expect Wine generates dwarf2 unwind info for the |
| 8907 |
system libraries that use this feature. */ |
| 8908 |
|
| 8909 |
insn = emit_insn (gen_blockage ()); |
| 8910 |
|
| 8911 |
push = gen_push (hard_frame_pointer_rtx); |
| 8912 |
mov = gen_rtx_SET (hard_frame_pointer_rtx, |
| 8913 |
stack_pointer_rtx); |
| 8914 |
RTX_FRAME_RELATED_P (push) = 1; |
| 8915 |
RTX_FRAME_RELATED_P (mov) = 1; |
| 8916 |
|
| 8917 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 8918 |
add_reg_note (insn, REG_FRAME_RELATED_EXPR, |
| 8919 |
gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, push, mov))); |
| 8920 |
|
| 8921 |
/* Note that gen_push incremented m->fs.cfa_offset, even |
| 8922 |
though we didn't emit the push insn here. */ |
| 8923 |
m->fs.cfa_reg = hard_frame_pointer_rtx; |
| 8924 |
m->fs.fp_offset = m->fs.cfa_offset; |
| 8925 |
m->fs.fp_valid = true; |
| 8926 |
} |
| 8927 |
else |
| 8928 |
{ |
| 8929 |
/* The frame pointer is not needed so pop %ebp again. |
| 8930 |
This leaves us with a pristine state. */ |
| 8931 |
emit_insn (gen_pop (hard_frame_pointer_rtx)); |
| 8932 |
} |
| 8933 |
} |
| 8934 |
|
| 8935 |
/* The first insn of a function that accepts its static chain on the |
| 8936 |
stack is to push the register that would be filled in by a direct |
| 8937 |
call. This insn will be skipped by the trampoline. */ |
| 8938 |
else if (ix86_static_chain_on_stack) |
| 8939 |
{ |
| 8940 |
static_chain = ix86_static_chain (cfun->decl, false); |
| 8941 |
insn = emit_insn (gen_push (static_chain)); |
| 8942 |
emit_insn (gen_blockage ()); |
| 8943 |
|
| 8944 |
/* We don't want to interpret this push insn as a register save, |
| 8945 |
only as a stack adjustment. The real copy of the register as |
| 8946 |
a save will be done later, if needed. */ |
| 8947 |
t = plus_constant (Pmode, stack_pointer_rtx, -UNITS_PER_WORD); |
| 8948 |
t = gen_rtx_SET (stack_pointer_rtx, t); |
| 8949 |
add_reg_note (insn, REG_CFA_ADJUST_CFA, t); |
| 8950 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 8951 |
} |
| 8952 |
|
| 8953 |
/* Emit prologue code to adjust stack alignment and setup DRAP, in case |
| 8954 |
of DRAP is needed and stack realignment is really needed after reload */ |
| 8955 |
if (stack_realign_drap) |
| 8956 |
{ |
| 8957 |
int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT; |
| 8958 |
|
| 8959 |
/* Can't use DRAP in interrupt function. */ |
| 8960 |
if (cfun->machine->func_type != TYPE_NORMAL) |
| 8961 |
sorry ("Dynamic Realign Argument Pointer (DRAP) not supported " |
| 8962 |
"in interrupt service routine. This may be worked " |
| 8963 |
"around by avoiding functions with aggregate return."); |
| 8964 |
|
| 8965 |
/* Only need to push parameter pointer reg if it is caller saved. */ |
| 8966 |
if (!call_used_or_fixed_reg_p (REGNO (crtl->drap_reg))) |
| 8967 |
{ |
| 8968 |
/* Push arg pointer reg */ |
| 8969 |
insn = emit_insn (gen_push (crtl->drap_reg)); |
| 8970 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 8971 |
} |
| 8972 |
|
| 8973 |
/* Grab the argument pointer. */ |
| 8974 |
t = plus_constant (Pmode, stack_pointer_rtx, m->fs.sp_offset); |
| 8975 |
insn = emit_insn (gen_rtx_SET (crtl->drap_reg, t)); |
| 8976 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 8977 |
m->fs.cfa_reg = crtl->drap_reg; |
| 8978 |
m->fs.cfa_offset = 0; |
| 8979 |
|
| 8980 |
/* Align the stack. */ |
| 8981 |
insn = emit_insn (gen_and2_insn (stack_pointer_rtx, |
| 8982 |
GEN_INT (-align_bytes))); |
| 8983 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 8984 |
|
| 8985 |
/* Replicate the return address on the stack so that return |
| 8986 |
address can be reached via (argp - 1) slot. This is needed |
| 8987 |
to implement macro RETURN_ADDR_RTX and intrinsic function |
| 8988 |
expand_builtin_return_addr etc. */ |
| 8989 |
t = plus_constant (Pmode, crtl->drap_reg, -UNITS_PER_WORD); |
| 8990 |
t = gen_frame_mem (word_mode, t); |
| 8991 |
insn = emit_insn (gen_push (t)); |
| 8992 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 8993 |
|
| 8994 |
/* For the purposes of frame and register save area addressing, |
| 8995 |
we've started over with a new frame. */ |
| 8996 |
m->fs.sp_offset = INCOMING_FRAME_SP_OFFSET; |
| 8997 |
m->fs.realigned = true; |
| 8998 |
|
| 8999 |
if (static_chain) |
| 9000 |
{ |
| 9001 |
/* Replicate static chain on the stack so that static chain |
| 9002 |
can be reached via (argp - 2) slot. This is needed for |
| 9003 |
nested function with stack realignment. */ |
| 9004 |
insn = emit_insn (gen_push (static_chain)); |
| 9005 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 9006 |
} |
| 9007 |
} |
| 9008 |
|
| 9009 |
int_registers_saved = (frame.nregs == 0); |
| 9010 |
sse_registers_saved = (frame.nsseregs == 0); |
| 9011 |
save_stub_call_needed = (m->call_ms2sysv); |
| 9012 |
gcc_assert (sse_registers_saved || !save_stub_call_needed); |
| 9013 |
|
| 9014 |
if (frame_pointer_needed && !m->fs.fp_valid) |
| 9015 |
{ |
| 9016 |
/* Note: AT&T enter does NOT have reversed args. Enter is probably |
| 9017 |
slower on all targets. Also sdb didn't like it. */ |
| 9018 |
insn = emit_insn (gen_push (hard_frame_pointer_rtx)); |
| 9019 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 9020 |
|
| 9021 |
if (m->fs.sp_offset == frame.hard_frame_pointer_offset) |
| 9022 |
{ |
| 9023 |
insn = emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx); |
| 9024 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 9025 |
|
| 9026 |
if (m->fs.cfa_reg == stack_pointer_rtx) |
| 9027 |
m->fs.cfa_reg = hard_frame_pointer_rtx; |
| 9028 |
m->fs.fp_offset = m->fs.sp_offset; |
| 9029 |
m->fs.fp_valid = true; |
| 9030 |
} |
| 9031 |
} |
| 9032 |
|
| 9033 |
if (!int_registers_saved) |
| 9034 |
{ |
| 9035 |
/* If saving registers via PUSH, do so now. */ |
| 9036 |
if (!frame.save_regs_using_mov) |
| 9037 |
{ |
| 9038 |
ix86_emit_save_regs (); |
| 9039 |
m->fs.apx_ppx_used = TARGET_APX_PPX && !crtl->calls_eh_return; |
| 9040 |
int_registers_saved = true; |
| 9041 |
gcc_assert (m->fs.sp_offset == frame.reg_save_offset); |
| 9042 |
} |
| 9043 |
|
| 9044 |
/* When using red zone we may start register saving before allocating |
| 9045 |
the stack frame saving one cycle of the prologue. However, avoid |
| 9046 |
doing this if we have to probe the stack; at least on x86_64 the |
| 9047 |
stack probe can turn into a call that clobbers a red zone location. */ |
| 9048 |
else if (ix86_using_red_zone () |
| 9049 |
&& (! TARGET_STACK_PROBE |
| 9050 |
|| frame.stack_pointer_offset < CHECK_STACK_LIMIT)) |
| 9051 |
{ |
| 9052 |
ix86_emit_save_regs_using_mov (frame.reg_save_offset); |
| 9053 |
cfun->machine->red_zone_used = true; |
| 9054 |
int_registers_saved = true; |
| 9055 |
} |
| 9056 |
} |
| 9057 |
|
| 9058 |
if (frame.red_zone_size != 0) |
| 9059 |
cfun->machine->red_zone_used = true; |
| 9060 |
|
| 9061 |
if (stack_realign_fp) |
| 9062 |
{ |
| 9063 |
int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT; |
| 9064 |
gcc_assert (align_bytes > MIN_STACK_BOUNDARY / BITS_PER_UNIT); |
| 9065 |
|
| 9066 |
/* Record last valid frame pointer offset. */ |
| 9067 |
m->fs.sp_realigned_fp_last = frame.reg_save_offset; |
| 9068 |
|
| 9069 |
/* The computation of the size of the re-aligned stack frame means |
| 9070 |
that we must allocate the size of the register save area before |
| 9071 |
performing the actual alignment. Otherwise we cannot guarantee |
| 9072 |
that there's enough storage above the realignment point. */ |
| 9073 |
allocate = frame.reg_save_offset - m->fs.sp_offset |
| 9074 |
+ frame.stack_realign_allocate; |
| 9075 |
if (allocate) |
| 9076 |
pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx, |
| 9077 |
GEN_INT (-allocate), -1, false); |
| 9078 |
|
| 9079 |
/* Align the stack. */ |
| 9080 |
emit_insn (gen_and2_insn (stack_pointer_rtx, GEN_INT (-align_bytes))); |
| 9081 |
m->fs.sp_offset = ROUND_UP (m->fs.sp_offset, align_bytes); |
| 9082 |
m->fs.sp_realigned_offset = m->fs.sp_offset |
| 9083 |
- frame.stack_realign_allocate; |
| 9084 |
/* The stack pointer may no longer be equal to CFA - m->fs.sp_offset. |
| 9085 |
Beyond this point, stack access should be done via choose_baseaddr or |
| 9086 |
by using sp_valid_at and fp_valid_at to determine the correct base |
| 9087 |
register. Henceforth, any CFA offset should be thought of as logical |
| 9088 |
and not physical. */ |
| 9089 |
gcc_assert (m->fs.sp_realigned_offset >= m->fs.sp_realigned_fp_last); |
| 9090 |
gcc_assert (m->fs.sp_realigned_offset == frame.stack_realign_offset); |
| 9091 |
m->fs.sp_realigned = true; |
| 9092 |
|
| 9093 |
/* SEH unwind emit doesn't currently support REG_CFA_EXPRESSION, which |
| 9094 |
is needed to describe where a register is saved using a realigned |
| 9095 |
stack pointer, so we need to invalidate the stack pointer for that |
| 9096 |
target. */ |
| 9097 |
if (TARGET_SEH) |
| 9098 |
m->fs.sp_valid = false; |
| 9099 |
|
| 9100 |
/* If SP offset is non-immediate after allocation of the stack frame, |
| 9101 |
then emit SSE saves or stub call prior to allocating the rest of the |
| 9102 |
stack frame. This is less efficient for the out-of-line stub because |
| 9103 |
we can't combine allocations across the call barrier, but it's better |
| 9104 |
than using a scratch register. */ |
| 9105 |
else if (!x86_64_immediate_operand (GEN_INT (frame.stack_pointer_offset |
| 9106 |
- m->fs.sp_realigned_offset), |
| 9107 |
Pmode)) |
| 9108 |
{ |
| 9109 |
if (!sse_registers_saved) |
| 9110 |
{ |
| 9111 |
ix86_emit_save_sse_regs_using_mov (frame.sse_reg_save_offset); |
| 9112 |
sse_registers_saved = true; |
| 9113 |
} |
| 9114 |
else if (save_stub_call_needed) |
| 9115 |
{ |
| 9116 |
ix86_emit_outlined_ms2sysv_save (frame); |
| 9117 |
save_stub_call_needed = false; |
| 9118 |
} |
| 9119 |
} |
| 9120 |
} |
| 9121 |
|
| 9122 |
allocate = frame.stack_pointer_offset - m->fs.sp_offset; |
| 9123 |
|
| 9124 |
if (flag_stack_usage_info) |
| 9125 |
{ |
| 9126 |
/* We start to count from ARG_POINTER. */ |
| 9127 |
HOST_WIDE_INT stack_size = frame.stack_pointer_offset; |
| 9128 |
|
| 9129 |
/* If it was realigned, take into account the fake frame. */ |
| 9130 |
if (stack_realign_drap) |
| 9131 |
{ |
| 9132 |
if (ix86_static_chain_on_stack) |
| 9133 |
stack_size += UNITS_PER_WORD; |
| 9134 |
|
| 9135 |
if (!call_used_or_fixed_reg_p (REGNO (crtl->drap_reg))) |
| 9136 |
stack_size += UNITS_PER_WORD; |
| 9137 |
|
| 9138 |
/* This over-estimates by 1 minimal-stack-alignment-unit but |
| 9139 |
mitigates that by counting in the new return address slot. */ |
| 9140 |
current_function_dynamic_stack_size |
| 9141 |
+= crtl->stack_alignment_needed / BITS_PER_UNIT; |
| 9142 |
} |
| 9143 |
|
| 9144 |
current_function_static_stack_size = stack_size; |
| 9145 |
} |
| 9146 |
|
| 9147 |
/* On SEH target with very large frame size, allocate an area to save |
| 9148 |
SSE registers (as the very large allocation won't be described). */ |
| 9149 |
if (TARGET_SEH |
| 9150 |
&& frame.stack_pointer_offset > SEH_MAX_FRAME_SIZE |
| 9151 |
&& !sse_registers_saved) |
| 9152 |
{ |
| 9153 |
HOST_WIDE_INT sse_size |
| 9154 |
= frame.sse_reg_save_offset - frame.reg_save_offset; |
| 9155 |
|
| 9156 |
gcc_assert (int_registers_saved); |
| 9157 |
|
| 9158 |
/* No need to do stack checking as the area will be immediately |
| 9159 |
written. */ |
| 9160 |
pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx, |
| 9161 |
GEN_INT (-sse_size), -1, |
| 9162 |
m->fs.cfa_reg == stack_pointer_rtx); |
| 9163 |
allocate -= sse_size; |
| 9164 |
ix86_emit_save_sse_regs_using_mov (frame.sse_reg_save_offset); |
| 9165 |
sse_registers_saved = true; |
| 9166 |
} |
| 9167 |
|
| 9168 |
/* If stack clash protection is requested, then probe the stack, unless it |
| 9169 |
is already probed on the target. */ |
| 9170 |
if (allocate >= 0 |
| 9171 |
&& flag_stack_clash_protection |
| 9172 |
&& !ix86_target_stack_probe ()) |
| 9173 |
{ |
| 9174 |
ix86_adjust_stack_and_probe (allocate, int_registers_saved, false); |
| 9175 |
allocate = 0; |
| 9176 |
} |
| 9177 |
|
| 9178 |
/* The stack has already been decremented by the instruction calling us |
| 9179 |
so probe if the size is non-negative to preserve the protection area. */ |
| 9180 |
else if (allocate >= 0 && flag_stack_check == STATIC_BUILTIN_STACK_CHECK) |
| 9181 |
{ |
| 9182 |
const HOST_WIDE_INT probe_interval = get_probe_interval (); |
| 9183 |
|
| 9184 |
if (STACK_CHECK_MOVING_SP) |
| 9185 |
{ |
| 9186 |
if (crtl->is_leaf |
| 9187 |
&& !cfun->calls_alloca |
| 9188 |
&& allocate <= probe_interval) |
| 9189 |
; |
| 9190 |
|
| 9191 |
else |
| 9192 |
{ |
| 9193 |
ix86_adjust_stack_and_probe (allocate, int_registers_saved, true); |
| 9194 |
allocate = 0; |
| 9195 |
} |
| 9196 |
} |
| 9197 |
|
| 9198 |
else |
| 9199 |
{ |
| 9200 |
HOST_WIDE_INT size = allocate; |
| 9201 |
|
| 9202 |
if (TARGET_64BIT && size >= HOST_WIDE_INT_C (0x80000000)) |
| 9203 |
size = 0x80000000 - get_stack_check_protect () - 1; |
| 9204 |
|
| 9205 |
if (TARGET_STACK_PROBE) |
| 9206 |
{ |
| 9207 |
if (crtl->is_leaf && !cfun->calls_alloca) |
| 9208 |
{ |
| 9209 |
if (size > probe_interval) |
| 9210 |
ix86_emit_probe_stack_range (0, size, int_registers_saved); |
| 9211 |
} |
| 9212 |
else |
| 9213 |
ix86_emit_probe_stack_range (0, |
| 9214 |
size + get_stack_check_protect (), |
| 9215 |
int_registers_saved); |
| 9216 |
} |
| 9217 |
else |
| 9218 |
{ |
| 9219 |
if (crtl->is_leaf && !cfun->calls_alloca) |
| 9220 |
{ |
| 9221 |
if (size > probe_interval |
| 9222 |
&& size > get_stack_check_protect ()) |
| 9223 |
ix86_emit_probe_stack_range (get_stack_check_protect (), |
| 9224 |
(size |
| 9225 |
- get_stack_check_protect ()), |
| 9226 |
int_registers_saved); |
| 9227 |
} |
| 9228 |
else |
| 9229 |
ix86_emit_probe_stack_range (get_stack_check_protect (), size, |
| 9230 |
int_registers_saved); |
| 9231 |
} |
| 9232 |
} |
| 9233 |
} |
| 9234 |
|
| 9235 |
if (allocate == 0) |
| 9236 |
; |
| 9237 |
else if (!ix86_target_stack_probe () |
| 9238 |
|| frame.stack_pointer_offset < CHECK_STACK_LIMIT) |
| 9239 |
{ |
| 9240 |
pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx, |
| 9241 |
GEN_INT (-allocate), -1, |
| 9242 |
m->fs.cfa_reg == stack_pointer_rtx); |
| 9243 |
} |
| 9244 |
else |
| 9245 |
{ |
| 9246 |
rtx eax = gen_rtx_REG (Pmode, AX_REG); |
| 9247 |
rtx r10 = NULL; |
| 9248 |
const bool sp_is_cfa_reg = (m->fs.cfa_reg == stack_pointer_rtx); |
| 9249 |
bool eax_live = ix86_eax_live_at_start_p (); |
| 9250 |
bool r10_live = false; |
| 9251 |
|
| 9252 |
if (TARGET_64BIT) |
| 9253 |
r10_live = (DECL_STATIC_CHAIN (current_function_decl) != 0); |
| 9254 |
|
| 9255 |
if (eax_live) |
| 9256 |
{ |
| 9257 |
insn = emit_insn (gen_push (eax)); |
| 9258 |
allocate -= UNITS_PER_WORD; |
| 9259 |
/* Note that SEH directives need to continue tracking the stack |
| 9260 |
pointer even after the frame pointer has been set up. */ |
| 9261 |
if (sp_is_cfa_reg || TARGET_SEH) |
| 9262 |
{ |
| 9263 |
if (sp_is_cfa_reg) |
| 9264 |
m->fs.cfa_offset += UNITS_PER_WORD; |
| 9265 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 9266 |
add_reg_note (insn, REG_FRAME_RELATED_EXPR, |
| 9267 |
gen_rtx_SET (stack_pointer_rtx, |
| 9268 |
plus_constant (Pmode, |
| 9269 |
stack_pointer_rtx, |
| 9270 |
-UNITS_PER_WORD))); |
| 9271 |
} |
| 9272 |
} |
| 9273 |
|
| 9274 |
if (r10_live) |
| 9275 |
{ |
| 9276 |
r10 = gen_rtx_REG (Pmode, R10_REG); |
| 9277 |
insn = emit_insn (gen_push (r10)); |
| 9278 |
allocate -= UNITS_PER_WORD; |
| 9279 |
if (sp_is_cfa_reg || TARGET_SEH) |
| 9280 |
{ |
| 9281 |
if (sp_is_cfa_reg) |
| 9282 |
m->fs.cfa_offset += UNITS_PER_WORD; |
| 9283 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 9284 |
add_reg_note (insn, REG_FRAME_RELATED_EXPR, |
| 9285 |
gen_rtx_SET (stack_pointer_rtx, |
| 9286 |
plus_constant (Pmode, |
| 9287 |
stack_pointer_rtx, |
| 9288 |
-UNITS_PER_WORD))); |
| 9289 |
} |
| 9290 |
} |
| 9291 |
|
| 9292 |
emit_move_insn (eax, GEN_INT (allocate)); |
| 9293 |
emit_insn (gen_allocate_stack_worker_probe (Pmode, eax, eax)); |
| 9294 |
|
| 9295 |
/* Use the fact that AX still contains ALLOCATE. */ |
| 9296 |
insn = emit_insn (gen_pro_epilogue_adjust_stack_sub |
| 9297 |
(Pmode, stack_pointer_rtx, stack_pointer_rtx, eax)); |
| 9298 |
|
| 9299 |
if (sp_is_cfa_reg || TARGET_SEH) |
| 9300 |
{ |
| 9301 |
if (sp_is_cfa_reg) |
| 9302 |
m->fs.cfa_offset += allocate; |
| 9303 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 9304 |
add_reg_note (insn, REG_FRAME_RELATED_EXPR, |
| 9305 |
gen_rtx_SET (stack_pointer_rtx, |
| 9306 |
plus_constant (Pmode, stack_pointer_rtx, |
| 9307 |
-allocate))); |
| 9308 |
} |
| 9309 |
m->fs.sp_offset += allocate; |
| 9310 |
|
| 9311 |
/* Use stack_pointer_rtx for relative addressing so that code works for |
| 9312 |
realigned stack. But this means that we need a blockage to prevent |
| 9313 |
stores based on the frame pointer from being scheduled before. */ |
| 9314 |
if (r10_live && eax_live) |
| 9315 |
{ |
| 9316 |
t = gen_rtx_PLUS (Pmode, stack_pointer_rtx, eax); |
| 9317 |
emit_move_insn (gen_rtx_REG (word_mode, R10_REG), |
| 9318 |
gen_frame_mem (word_mode, t)); |
| 9319 |
t = plus_constant (Pmode, t, UNITS_PER_WORD); |
| 9320 |
emit_move_insn (gen_rtx_REG (word_mode, AX_REG), |
| 9321 |
gen_frame_mem (word_mode, t)); |
| 9322 |
emit_insn (gen_memory_blockage ()); |
| 9323 |
} |
| 9324 |
else if (eax_live || r10_live) |
| 9325 |
{ |
| 9326 |
t = gen_rtx_PLUS (Pmode, stack_pointer_rtx, eax); |
| 9327 |
emit_move_insn (gen_rtx_REG (word_mode, |
| 9328 |
(eax_live ? AX_REG : R10_REG)), |
| 9329 |
gen_frame_mem (word_mode, t)); |
| 9330 |
emit_insn (gen_memory_blockage ()); |
| 9331 |
} |
| 9332 |
} |
| 9333 |
gcc_assert (m->fs.sp_offset == frame.stack_pointer_offset); |
| 9334 |
|
| 9335 |
/* If we havn't already set up the frame pointer, do so now. */ |
| 9336 |
if (frame_pointer_needed && !m->fs.fp_valid) |
| 9337 |
{ |
| 9338 |
insn = gen_add3_insn (hard_frame_pointer_rtx, stack_pointer_rtx, |
| 9339 |
GEN_INT (frame.stack_pointer_offset |
| 9340 |
- frame.hard_frame_pointer_offset)); |
| 9341 |
insn = emit_insn (insn); |
| 9342 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 9343 |
add_reg_note (insn, REG_CFA_ADJUST_CFA, NULL); |
| 9344 |
|
| 9345 |
if (m->fs.cfa_reg == stack_pointer_rtx) |
| 9346 |
m->fs.cfa_reg = hard_frame_pointer_rtx; |
| 9347 |
m->fs.fp_offset = frame.hard_frame_pointer_offset; |
| 9348 |
m->fs.fp_valid = true; |
| 9349 |
} |
| 9350 |
|
| 9351 |
if (!int_registers_saved) |
| 9352 |
ix86_emit_save_regs_using_mov (frame.reg_save_offset); |
| 9353 |
if (!sse_registers_saved) |
| 9354 |
ix86_emit_save_sse_regs_using_mov (frame.sse_reg_save_offset); |
| 9355 |
else if (save_stub_call_needed) |
| 9356 |
ix86_emit_outlined_ms2sysv_save (frame); |
| 9357 |
|
| 9358 |
/* For the mcount profiling on 32 bit PIC mode we need to emit SET_GOT |
| 9359 |
in PROLOGUE. */ |
| 9360 |
if (!TARGET_64BIT && pic_offset_table_rtx && crtl->profile && !flag_fentry) |
| 9361 |
{ |
| 9362 |
rtx pic = gen_rtx_REG (Pmode, REAL_PIC_OFFSET_TABLE_REGNUM); |
| 9363 |
insn = emit_insn (gen_set_got (pic)); |
| 9364 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 9365 |
add_reg_note (insn, REG_CFA_FLUSH_QUEUE, NULL_RTX); |
| 9366 |
emit_insn (gen_prologue_use (pic)); |
| 9367 |
/* Deleting already emmitted SET_GOT if exist and allocated to |
| 9368 |
REAL_PIC_OFFSET_TABLE_REGNUM. */ |
| 9369 |
ix86_elim_entry_set_got (pic); |
| 9370 |
} |
| 9371 |
|
| 9372 |
if (crtl->drap_reg && !crtl->stack_realign_needed) |
| 9373 |
{ |
| 9374 |
/* vDRAP is setup but after reload it turns out stack realign |
| 9375 |
isn't necessary, here we will emit prologue to setup DRAP |
| 9376 |
without stack realign adjustment */ |
| 9377 |
t = choose_baseaddr (0, NULL); |
| 9378 |
emit_insn (gen_rtx_SET (crtl->drap_reg, t)); |
| 9379 |
} |
| 9380 |
|
| 9381 |
/* Prevent instructions from being scheduled into register save push |
| 9382 |
sequence when access to the redzone area is done through frame pointer. |
| 9383 |
The offset between the frame pointer and the stack pointer is calculated |
| 9384 |
relative to the value of the stack pointer at the end of the function |
| 9385 |
prologue, and moving instructions that access redzone area via frame |
| 9386 |
pointer inside push sequence violates this assumption. */ |
| 9387 |
if (frame_pointer_needed && frame.red_zone_size) |
| 9388 |
emit_insn (gen_memory_blockage ()); |
| 9389 |
|
| 9390 |
/* SEH requires that the prologue end within 256 bytes of the start of |
| 9391 |
the function. Prevent instruction schedules that would extend that. |
| 9392 |
Further, prevent alloca modifications to the stack pointer from being |
| 9393 |
combined with prologue modifications. */ |
| 9394 |
if (TARGET_SEH) |
| 9395 |
emit_insn (gen_prologue_use (stack_pointer_rtx)); |
| 9396 |
} |
| 9397 |
|
| 9398 |
/* Emit code to restore REG using a POP or POPP insn. */ |
| 9399 |
|
| 9400 |
static void |
| 9401 |
ix86_emit_restore_reg_using_pop (rtx reg, bool ppx_p) |
| 9402 |
{ |
| 9403 |
struct machine_function *m = cfun->machine; |
| 9404 |
rtx_insn *insn = emit_insn (gen_pop (reg, ppx_p)); |
| 9405 |
|
| 9406 |
ix86_add_cfa_restore_note (insn, reg, m->fs.sp_offset); |
| 9407 |
m->fs.sp_offset -= UNITS_PER_WORD; |
| 9408 |
|
| 9409 |
if (m->fs.cfa_reg == crtl->drap_reg |
| 9410 |
&& REGNO (reg) == REGNO (crtl->drap_reg)) |
| 9411 |
{ |
| 9412 |
/* Previously we'd represented the CFA as an expression |
| 9413 |
like *(%ebp - 8). We've just popped that value from |
| 9414 |
the stack, which means we need to reset the CFA to |
| 9415 |
the drap register. This will remain until we restore |
| 9416 |
the stack pointer. */ |
| 9417 |
add_reg_note (insn, REG_CFA_DEF_CFA, reg); |
| 9418 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 9419 |
|
| 9420 |
/* This means that the DRAP register is valid for addressing too. */ |
| 9421 |
m->fs.drap_valid = true; |
| 9422 |
return; |
| 9423 |
} |
| 9424 |
|
| 9425 |
if (m->fs.cfa_reg == stack_pointer_rtx) |
| 9426 |
{ |
| 9427 |
rtx x = plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD); |
| 9428 |
x = gen_rtx_SET (stack_pointer_rtx, x); |
| 9429 |
add_reg_note (insn, REG_CFA_ADJUST_CFA, x); |
| 9430 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 9431 |
|
| 9432 |
m->fs.cfa_offset -= UNITS_PER_WORD; |
| 9433 |
} |
| 9434 |
|
| 9435 |
/* When the frame pointer is the CFA, and we pop it, we are |
| 9436 |
swapping back to the stack pointer as the CFA. This happens |
| 9437 |
for stack frames that don't allocate other data, so we assume |
| 9438 |
the stack pointer is now pointing at the return address, i.e. |
| 9439 |
the function entry state, which makes the offset be 1 word. */ |
| 9440 |
if (reg == hard_frame_pointer_rtx) |
| 9441 |
{ |
| 9442 |
m->fs.fp_valid = false; |
| 9443 |
if (m->fs.cfa_reg == hard_frame_pointer_rtx) |
| 9444 |
{ |
| 9445 |
m->fs.cfa_reg = stack_pointer_rtx; |
| 9446 |
m->fs.cfa_offset -= UNITS_PER_WORD; |
| 9447 |
|
| 9448 |
add_reg_note (insn, REG_CFA_DEF_CFA, |
| 9449 |
plus_constant (Pmode, stack_pointer_rtx, |
| 9450 |
m->fs.cfa_offset)); |
| 9451 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 9452 |
} |
| 9453 |
} |
| 9454 |
} |
| 9455 |
|
| 9456 |
/* Emit code to restore REG using a POP2 insn. */ |
| 9457 |
static void |
| 9458 |
ix86_emit_restore_reg_using_pop2 (rtx reg1, rtx reg2, bool ppx_p = false) |
| 9459 |
{ |
| 9460 |
struct machine_function *m = cfun->machine; |
| 9461 |
const int offset = UNITS_PER_WORD * 2; |
| 9462 |
rtx_insn *insn; |
| 9463 |
|
| 9464 |
rtx mem = gen_rtx_MEM (TImode, gen_rtx_POST_INC (Pmode, |
| 9465 |
stack_pointer_rtx)); |
| 9466 |
|
| 9467 |
if (ppx_p) |
| 9468 |
insn = emit_insn (gen_pop2p_di (reg1, mem, reg2)); |
| 9469 |
else |
| 9470 |
insn = emit_insn (gen_pop2_di (reg1, mem, reg2)); |
| 9471 |
|
| 9472 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 9473 |
|
| 9474 |
rtx dwarf = NULL_RTX; |
| 9475 |
dwarf = alloc_reg_note (REG_CFA_RESTORE, reg1, dwarf); |
| 9476 |
dwarf = alloc_reg_note (REG_CFA_RESTORE, reg2, dwarf); |
| 9477 |
REG_NOTES (insn) = dwarf; |
| 9478 |
m->fs.sp_offset -= offset; |
| 9479 |
|
| 9480 |
if (m->fs.cfa_reg == crtl->drap_reg |
| 9481 |
&& (REGNO (reg1) == REGNO (crtl->drap_reg) |
| 9482 |
|| REGNO (reg2) == REGNO (crtl->drap_reg))) |
| 9483 |
{ |
| 9484 |
/* Previously we'd represented the CFA as an expression |
| 9485 |
like *(%ebp - 8). We've just popped that value from |
| 9486 |
the stack, which means we need to reset the CFA to |
| 9487 |
the drap register. This will remain until we restore |
| 9488 |
the stack pointer. */ |
| 9489 |
add_reg_note (insn, REG_CFA_DEF_CFA, |
| 9490 |
REGNO (reg1) == REGNO (crtl->drap_reg) ? reg1 : reg2); |
| 9491 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 9492 |
|
| 9493 |
/* This means that the DRAP register is valid for addressing too. */ |
| 9494 |
m->fs.drap_valid = true; |
| 9495 |
return; |
| 9496 |
} |
| 9497 |
|
| 9498 |
if (m->fs.cfa_reg == stack_pointer_rtx) |
| 9499 |
{ |
| 9500 |
rtx x = plus_constant (Pmode, stack_pointer_rtx, offset); |
| 9501 |
x = gen_rtx_SET (stack_pointer_rtx, x); |
| 9502 |
add_reg_note (insn, REG_CFA_ADJUST_CFA, x); |
| 9503 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 9504 |
|
| 9505 |
m->fs.cfa_offset -= offset; |
| 9506 |
} |
| 9507 |
|
| 9508 |
/* When the frame pointer is the CFA, and we pop it, we are |
| 9509 |
swapping back to the stack pointer as the CFA. This happens |
| 9510 |
for stack frames that don't allocate other data, so we assume |
| 9511 |
the stack pointer is now pointing at the return address, i.e. |
| 9512 |
the function entry state, which makes the offset be 1 word. */ |
| 9513 |
if (reg1 == hard_frame_pointer_rtx || reg2 == hard_frame_pointer_rtx) |
| 9514 |
{ |
| 9515 |
m->fs.fp_valid = false; |
| 9516 |
if (m->fs.cfa_reg == hard_frame_pointer_rtx) |
| 9517 |
{ |
| 9518 |
m->fs.cfa_reg = stack_pointer_rtx; |
| 9519 |
m->fs.cfa_offset -= offset; |
| 9520 |
|
| 9521 |
add_reg_note (insn, REG_CFA_DEF_CFA, |
| 9522 |
plus_constant (Pmode, stack_pointer_rtx, |
| 9523 |
m->fs.cfa_offset)); |
| 9524 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 9525 |
} |
| 9526 |
} |
| 9527 |
} |
| 9528 |
|
| 9529 |
/* Emit code to restore saved registers using POP insns. */ |
| 9530 |
|
| 9531 |
static void |
| 9532 |
ix86_emit_restore_regs_using_pop (bool ppx_p) |
| 9533 |
{ |
| 9534 |
unsigned int regno; |
| 9535 |
|
| 9536 |
for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) |
| 9537 |
if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, false, true)) |
| 9538 |
ix86_emit_restore_reg_using_pop (gen_rtx_REG (word_mode, regno), ppx_p); |
| 9539 |
} |
| 9540 |
|
| 9541 |
/* Emit code to restore saved registers using POP2 insns. */ |
| 9542 |
|
| 9543 |
static void |
| 9544 |
ix86_emit_restore_regs_using_pop2 (void) |
| 9545 |
{ |
| 9546 |
int regno; |
| 9547 |
int regno_list[2]; |
| 9548 |
regno_list[0] = regno_list[1] = -1; |
| 9549 |
int loaded_regnum = 0; |
| 9550 |
bool aligned = cfun->machine->fs.sp_offset % 16 == 0; |
| 9551 |
|
| 9552 |
for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) |
| 9553 |
if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, false, true)) |
| 9554 |
{ |
| 9555 |
if (aligned) |
| 9556 |
{ |
| 9557 |
regno_list[loaded_regnum++] = regno; |
| 9558 |
if (loaded_regnum == 2) |
| 9559 |
{ |
| 9560 |
gcc_assert (regno_list[0] != -1 |
| 9561 |
&& regno_list[1] != -1 |
| 9562 |
&& regno_list[0] != regno_list[1]); |
| 9563 |
|
| 9564 |
ix86_emit_restore_reg_using_pop2 (gen_rtx_REG (word_mode, |
| 9565 |
regno_list[0]), |
| 9566 |
gen_rtx_REG (word_mode, |
| 9567 |
regno_list[1]), |
| 9568 |
TARGET_APX_PPX); |
| 9569 |
loaded_regnum = 0; |
| 9570 |
regno_list[0] = regno_list[1] = -1; |
| 9571 |
} |
| 9572 |
} |
| 9573 |
else |
| 9574 |
{ |
| 9575 |
ix86_emit_restore_reg_using_pop (gen_rtx_REG (word_mode, regno), |
| 9576 |
TARGET_APX_PPX); |
| 9577 |
aligned = true; |
| 9578 |
} |
| 9579 |
} |
| 9580 |
|
| 9581 |
if (loaded_regnum == 1) |
| 9582 |
ix86_emit_restore_reg_using_pop (gen_rtx_REG (word_mode, regno_list[0]), |
| 9583 |
TARGET_APX_PPX); |
| 9584 |
} |
| 9585 |
|
| 9586 |
/* Emit code and notes for the LEAVE instruction. If insn is non-null, |
| 9587 |
omits the emit and only attaches the notes. */ |
| 9588 |
|
| 9589 |
static void |
| 9590 |
ix86_emit_leave (rtx_insn *insn) |
| 9591 |
{ |
| 9592 |
struct machine_function *m = cfun->machine; |
| 9593 |
|
| 9594 |
if (!insn) |
| 9595 |
insn = emit_insn (gen_leave (word_mode)); |
| 9596 |
|
| 9597 |
ix86_add_queued_cfa_restore_notes (insn); |
| 9598 |
|
| 9599 |
gcc_assert (m->fs.fp_valid); |
| 9600 |
m->fs.sp_valid = true; |
| 9601 |
m->fs.sp_realigned = false; |
| 9602 |
m->fs.sp_offset = m->fs.fp_offset - UNITS_PER_WORD; |
| 9603 |
m->fs.fp_valid = false; |
| 9604 |
|
| 9605 |
if (m->fs.cfa_reg == hard_frame_pointer_rtx) |
| 9606 |
{ |
| 9607 |
m->fs.cfa_reg = stack_pointer_rtx; |
| 9608 |
m->fs.cfa_offset = m->fs.sp_offset; |
| 9609 |
|
| 9610 |
add_reg_note (insn, REG_CFA_DEF_CFA, |
| 9611 |
plus_constant (Pmode, stack_pointer_rtx, |
| 9612 |
m->fs.sp_offset)); |
| 9613 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 9614 |
} |
| 9615 |
ix86_add_cfa_restore_note (insn, hard_frame_pointer_rtx, |
| 9616 |
m->fs.fp_offset); |
| 9617 |
} |
| 9618 |
|
| 9619 |
/* Emit code to restore saved registers using MOV insns. |
| 9620 |
First register is restored from CFA - CFA_OFFSET. */ |
| 9621 |
static void |
| 9622 |
ix86_emit_restore_regs_using_mov (HOST_WIDE_INT cfa_offset, |
| 9623 |
bool maybe_eh_return) |
| 9624 |
{ |
| 9625 |
struct machine_function *m = cfun->machine; |
| 9626 |
unsigned int regno; |
| 9627 |
|
| 9628 |
for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) |
| 9629 |
if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, maybe_eh_return, true)) |
| 9630 |
{ |
| 9631 |
rtx reg = gen_rtx_REG (word_mode, regno); |
| 9632 |
rtx mem; |
| 9633 |
rtx_insn *insn; |
| 9634 |
|
| 9635 |
mem = choose_baseaddr (cfa_offset, NULL); |
| 9636 |
mem = gen_frame_mem (word_mode, mem); |
| 9637 |
insn = emit_move_insn (reg, mem); |
| 9638 |
|
| 9639 |
if (m->fs.cfa_reg == crtl->drap_reg && regno == REGNO (crtl->drap_reg)) |
| 9640 |
{ |
| 9641 |
/* Previously we'd represented the CFA as an expression |
| 9642 |
like *(%ebp - 8). We've just popped that value from |
| 9643 |
the stack, which means we need to reset the CFA to |
| 9644 |
the drap register. This will remain until we restore |
| 9645 |
the stack pointer. */ |
| 9646 |
add_reg_note (insn, REG_CFA_DEF_CFA, reg); |
| 9647 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 9648 |
|
| 9649 |
/* This means that the DRAP register is valid for addressing. */ |
| 9650 |
m->fs.drap_valid = true; |
| 9651 |
} |
| 9652 |
else |
| 9653 |
ix86_add_cfa_restore_note (NULL, reg, cfa_offset); |
| 9654 |
|
| 9655 |
cfa_offset -= UNITS_PER_WORD; |
| 9656 |
} |
| 9657 |
} |
| 9658 |
|
| 9659 |
/* Emit code to restore saved registers using MOV insns. |
| 9660 |
First register is restored from CFA - CFA_OFFSET. */ |
| 9661 |
static void |
| 9662 |
ix86_emit_restore_sse_regs_using_mov (HOST_WIDE_INT cfa_offset, |
| 9663 |
bool maybe_eh_return) |
| 9664 |
{ |
| 9665 |
unsigned int regno; |
| 9666 |
|
| 9667 |
for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) |
| 9668 |
if (SSE_REGNO_P (regno) && ix86_save_reg (regno, maybe_eh_return, true)) |
| 9669 |
{ |
| 9670 |
rtx reg = gen_rtx_REG (V4SFmode, regno); |
| 9671 |
rtx mem; |
| 9672 |
unsigned int align = GET_MODE_ALIGNMENT (V4SFmode); |
| 9673 |
|
| 9674 |
mem = choose_baseaddr (cfa_offset, &align); |
| 9675 |
mem = gen_rtx_MEM (V4SFmode, mem); |
| 9676 |
|
| 9677 |
/* The location aligment depends upon the base register. */ |
| 9678 |
align = MIN (GET_MODE_ALIGNMENT (V4SFmode), align); |
| 9679 |
gcc_assert (! (cfa_offset & (align / BITS_PER_UNIT - 1))); |
| 9680 |
set_mem_align (mem, align); |
| 9681 |
emit_insn (gen_rtx_SET (reg, mem)); |
| 9682 |
|
| 9683 |
ix86_add_cfa_restore_note (NULL, reg, cfa_offset); |
| 9684 |
|
| 9685 |
cfa_offset -= GET_MODE_SIZE (V4SFmode); |
| 9686 |
} |
| 9687 |
} |
| 9688 |
|
| 9689 |
static void |
| 9690 |
ix86_emit_outlined_ms2sysv_restore (const struct ix86_frame &frame, |
| 9691 |
bool use_call, int style) |
| 9692 |
{ |
| 9693 |
struct machine_function *m = cfun->machine; |
| 9694 |
const unsigned ncregs = NUM_X86_64_MS_CLOBBERED_REGS |
| 9695 |
+ m->call_ms2sysv_extra_regs; |
| 9696 |
rtvec v; |
| 9697 |
unsigned int elems_needed, align, i, vi = 0; |
| 9698 |
rtx_insn *insn; |
| 9699 |
rtx sym, tmp; |
| 9700 |
rtx rsi = gen_rtx_REG (word_mode, SI_REG); |
| 9701 |
rtx r10 = NULL_RTX; |
| 9702 |
const class xlogue_layout &xlogue = xlogue_layout::get_instance (); |
| 9703 |
HOST_WIDE_INT stub_ptr_offset = xlogue.get_stub_ptr_offset (); |
| 9704 |
HOST_WIDE_INT rsi_offset = frame.stack_realign_offset + stub_ptr_offset; |
| 9705 |
rtx rsi_frame_load = NULL_RTX; |
| 9706 |
HOST_WIDE_INT rsi_restore_offset = (HOST_WIDE_INT)-1; |
| 9707 |
enum xlogue_stub stub; |
| 9708 |
|
| 9709 |
gcc_assert (!m->fs.fp_valid || frame_pointer_needed); |
| 9710 |
|
| 9711 |
/* If using a realigned stack, we should never start with padding. */ |
| 9712 |
gcc_assert (!stack_realign_fp || !xlogue.get_stack_align_off_in ()); |
| 9713 |
|
| 9714 |
/* Setup RSI as the stub's base pointer. */ |
| 9715 |
align = GET_MODE_ALIGNMENT (V4SFmode); |
| 9716 |
tmp = choose_baseaddr (rsi_offset, &align, SI_REG); |
| 9717 |
gcc_assert (align >= GET_MODE_ALIGNMENT (V4SFmode)); |
| 9718 |
|
| 9719 |
emit_insn (gen_rtx_SET (rsi, tmp)); |
| 9720 |
|
| 9721 |
/* Get a symbol for the stub. */ |
| 9722 |
if (frame_pointer_needed) |
| 9723 |
stub = use_call ? XLOGUE_STUB_RESTORE_HFP |
| 9724 |
: XLOGUE_STUB_RESTORE_HFP_TAIL; |
| 9725 |
else |
| 9726 |
stub = use_call ? XLOGUE_STUB_RESTORE |
| 9727 |
: XLOGUE_STUB_RESTORE_TAIL; |
| 9728 |
sym = xlogue.get_stub_rtx (stub); |
| 9729 |
|
| 9730 |
elems_needed = ncregs; |
| 9731 |
if (use_call) |
| 9732 |
elems_needed += 1; |
| 9733 |
else |
| 9734 |
elems_needed += frame_pointer_needed ? 5 : 3; |
| 9735 |
v = rtvec_alloc (elems_needed); |
| 9736 |
|
| 9737 |
/* We call the epilogue stub when we need to pop incoming args or we are |
| 9738 |
doing a sibling call as the tail. Otherwise, we will emit a jmp to the |
| 9739 |
epilogue stub and it is the tail-call. */ |
| 9740 |
if (use_call) |
| 9741 |
RTVEC_ELT (v, vi++) = gen_rtx_USE (VOIDmode, sym); |
| 9742 |
else |
| 9743 |
{ |
| 9744 |
RTVEC_ELT (v, vi++) = ret_rtx; |
| 9745 |
RTVEC_ELT (v, vi++) = gen_rtx_USE (VOIDmode, sym); |
| 9746 |
if (frame_pointer_needed) |
| 9747 |
{ |
| 9748 |
rtx rbp = gen_rtx_REG (DImode, BP_REG); |
| 9749 |
gcc_assert (m->fs.fp_valid); |
| 9750 |
gcc_assert (m->fs.cfa_reg == hard_frame_pointer_rtx); |
| 9751 |
|
| 9752 |
tmp = plus_constant (DImode, rbp, 8); |
| 9753 |
RTVEC_ELT (v, vi++) = gen_rtx_SET (stack_pointer_rtx, tmp); |
| 9754 |
RTVEC_ELT (v, vi++) = gen_rtx_SET (rbp, gen_rtx_MEM (DImode, rbp)); |
| 9755 |
tmp = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (VOIDmode)); |
| 9756 |
RTVEC_ELT (v, vi++) = gen_rtx_CLOBBER (VOIDmode, tmp); |
| 9757 |
} |
| 9758 |
else |
| 9759 |
{ |
| 9760 |
/* If no hard frame pointer, we set R10 to the SP restore value. */ |
| 9761 |
gcc_assert (!m->fs.fp_valid); |
| 9762 |
gcc_assert (m->fs.cfa_reg == stack_pointer_rtx); |
| 9763 |
gcc_assert (m->fs.sp_valid); |
| 9764 |
|
| 9765 |
r10 = gen_rtx_REG (DImode, R10_REG); |
| 9766 |
tmp = plus_constant (Pmode, rsi, stub_ptr_offset); |
| 9767 |
emit_insn (gen_rtx_SET (r10, tmp)); |
| 9768 |
|
| 9769 |
RTVEC_ELT (v, vi++) = gen_rtx_SET (stack_pointer_rtx, r10); |
| 9770 |
} |
| 9771 |
} |
| 9772 |
|
| 9773 |
/* Generate frame load insns and restore notes. */ |
| 9774 |
for (i = 0; i < ncregs; ++i) |
| 9775 |
{ |
| 9776 |
const xlogue_layout::reginfo &r = xlogue.get_reginfo (i); |
| 9777 |
machine_mode mode = SSE_REGNO_P (r.regno) ? V4SFmode : word_mode; |
| 9778 |
rtx reg, frame_load; |
| 9779 |
|
| 9780 |
reg = gen_rtx_REG (mode, r.regno); |
| 9781 |
frame_load = gen_frame_load (reg, rsi, r.offset); |
| 9782 |
|
| 9783 |
/* Save RSI frame load insn & note to add last. */ |
| 9784 |
if (r.regno == SI_REG) |
| 9785 |
{ |
| 9786 |
gcc_assert (!rsi_frame_load); |
| 9787 |
rsi_frame_load = frame_load; |
| 9788 |
rsi_restore_offset = r.offset; |
| 9789 |
} |
| 9790 |
else |
| 9791 |
{ |
| 9792 |
RTVEC_ELT (v, vi++) = frame_load; |
| 9793 |
ix86_add_cfa_restore_note (NULL, reg, r.offset); |
| 9794 |
} |
| 9795 |
} |
| 9796 |
|
| 9797 |
/* Add RSI frame load & restore note at the end. */ |
| 9798 |
gcc_assert (rsi_frame_load); |
| 9799 |
gcc_assert (rsi_restore_offset != (HOST_WIDE_INT)-1); |
| 9800 |
RTVEC_ELT (v, vi++) = rsi_frame_load; |
| 9801 |
ix86_add_cfa_restore_note (NULL, gen_rtx_REG (DImode, SI_REG), |
| 9802 |
rsi_restore_offset); |
| 9803 |
|
| 9804 |
/* Finally, for tail-call w/o a hard frame pointer, set SP to R10. */ |
| 9805 |
if (!use_call && !frame_pointer_needed) |
| 9806 |
{ |
| 9807 |
gcc_assert (m->fs.sp_valid); |
| 9808 |
gcc_assert (!m->fs.sp_realigned); |
| 9809 |
|
| 9810 |
/* At this point, R10 should point to frame.stack_realign_offset. */ |
| 9811 |
if (m->fs.cfa_reg == stack_pointer_rtx) |
| 9812 |
m->fs.cfa_offset += m->fs.sp_offset - frame.stack_realign_offset; |
| 9813 |
m->fs.sp_offset = frame.stack_realign_offset; |
| 9814 |
} |
| 9815 |
|
| 9816 |
gcc_assert (vi == (unsigned int)GET_NUM_ELEM (v)); |
| 9817 |
tmp = gen_rtx_PARALLEL (VOIDmode, v); |
| 9818 |
if (use_call) |
| 9819 |
insn = emit_insn (tmp); |
| 9820 |
else |
| 9821 |
{ |
| 9822 |
insn = emit_jump_insn (tmp); |
| 9823 |
JUMP_LABEL (insn) = ret_rtx; |
| 9824 |
|
| 9825 |
if (frame_pointer_needed) |
| 9826 |
ix86_emit_leave (insn); |
| 9827 |
else |
| 9828 |
{ |
| 9829 |
/* Need CFA adjust note. */ |
| 9830 |
tmp = gen_rtx_SET (stack_pointer_rtx, r10); |
| 9831 |
add_reg_note (insn, REG_CFA_ADJUST_CFA, tmp); |
| 9832 |
} |
| 9833 |
} |
| 9834 |
|
| 9835 |
RTX_FRAME_RELATED_P (insn) = true; |
| 9836 |
ix86_add_queued_cfa_restore_notes (insn); |
| 9837 |
|
| 9838 |
/* If we're not doing a tail-call, we need to adjust the stack. */ |
| 9839 |
if (use_call && m->fs.sp_valid) |
| 9840 |
{ |
| 9841 |
HOST_WIDE_INT dealloc = m->fs.sp_offset - frame.stack_realign_offset; |
| 9842 |
pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx, |
| 9843 |
GEN_INT (dealloc), style, |
| 9844 |
m->fs.cfa_reg == stack_pointer_rtx); |
| 9845 |
} |
| 9846 |
} |
| 9847 |
|
| 9848 |
/* Restore function stack, frame, and registers. */ |
| 9849 |
|
| 9850 |
void |
| 9851 |
ix86_expand_epilogue (int style) |
| 9852 |
{ |
| 9853 |
struct machine_function *m = cfun->machine; |
| 9854 |
struct machine_frame_state frame_state_save = m->fs; |
| 9855 |
bool restore_regs_via_mov; |
| 9856 |
bool using_drap; |
| 9857 |
bool restore_stub_is_tail = false; |
| 9858 |
|
| 9859 |
if (ix86_function_naked (current_function_decl)) |
| 9860 |
{ |
| 9861 |
/* The program should not reach this point. */ |
| 9862 |
emit_insn (gen_ud2 ()); |
| 9863 |
return; |
| 9864 |
} |
| 9865 |
|
| 9866 |
ix86_finalize_stack_frame_flags (); |
| 9867 |
const struct ix86_frame &frame = cfun->machine->frame; |
| 9868 |
|
| 9869 |
m->fs.sp_realigned = stack_realign_fp; |
| 9870 |
m->fs.sp_valid = stack_realign_fp |
| 9871 |
|| !frame_pointer_needed |
| 9872 |
|| crtl->sp_is_unchanging; |
| 9873 |
gcc_assert (!m->fs.sp_valid |
| 9874 |
|| m->fs.sp_offset == frame.stack_pointer_offset); |
| 9875 |
|
| 9876 |
/* The FP must be valid if the frame pointer is present. */ |
| 9877 |
gcc_assert (frame_pointer_needed == m->fs.fp_valid); |
| 9878 |
gcc_assert (!m->fs.fp_valid |
| 9879 |
|| m->fs.fp_offset == frame.hard_frame_pointer_offset); |
| 9880 |
|
| 9881 |
/* We must have *some* valid pointer to the stack frame. */ |
| 9882 |
gcc_assert (m->fs.sp_valid || m->fs.fp_valid); |
| 9883 |
|
| 9884 |
/* The DRAP is never valid at this point. */ |
| 9885 |
gcc_assert (!m->fs.drap_valid); |
| 9886 |
|
| 9887 |
/* See the comment about red zone and frame |
| 9888 |
pointer usage in ix86_expand_prologue. */ |
| 9889 |
if (frame_pointer_needed && frame.red_zone_size) |
| 9890 |
emit_insn (gen_memory_blockage ()); |
| 9891 |
|
| 9892 |
using_drap = crtl->drap_reg && crtl->stack_realign_needed; |
| 9893 |
gcc_assert (!using_drap || m->fs.cfa_reg == crtl->drap_reg); |
| 9894 |
|
| 9895 |
/* Determine the CFA offset of the end of the red-zone. */ |
| 9896 |
m->fs.red_zone_offset = 0; |
| 9897 |
if (ix86_using_red_zone () && crtl->args.pops_args < 65536) |
| 9898 |
{ |
| 9899 |
/* The red-zone begins below return address and error code in |
| 9900 |
exception handler. */ |
| 9901 |
m->fs.red_zone_offset = RED_ZONE_SIZE + INCOMING_FRAME_SP_OFFSET; |
| 9902 |
|
| 9903 |
/* When the register save area is in the aligned portion of |
| 9904 |
the stack, determine the maximum runtime displacement that |
| 9905 |
matches up with the aligned frame. */ |
| 9906 |
if (stack_realign_drap) |
| 9907 |
m->fs.red_zone_offset -= (crtl->stack_alignment_needed / BITS_PER_UNIT |
| 9908 |
+ UNITS_PER_WORD); |
| 9909 |
} |
| 9910 |
|
| 9911 |
HOST_WIDE_INT reg_save_offset = frame.reg_save_offset; |
| 9912 |
|
| 9913 |
/* Special care must be taken for the normal return case of a function |
| 9914 |
using eh_return: the eax and edx registers are marked as saved, but |
| 9915 |
not restored along this path. Adjust the save location to match. */ |
| 9916 |
if (crtl->calls_eh_return && style != 2) |
| 9917 |
reg_save_offset -= 2 * UNITS_PER_WORD; |
| 9918 |
|
| 9919 |
/* EH_RETURN requires the use of moves to function properly. */ |
| 9920 |
if (crtl->calls_eh_return) |
| 9921 |
restore_regs_via_mov = true; |
| 9922 |
/* SEH requires the use of pops to identify the epilogue. */ |
| 9923 |
else if (TARGET_SEH) |
| 9924 |
restore_regs_via_mov = false; |
| 9925 |
/* If we already save reg with pushp, don't use move at epilogue. */ |
| 9926 |
else if (m->fs.apx_ppx_used) |
| 9927 |
restore_regs_via_mov = false; |
| 9928 |
/* If we're only restoring one register and sp cannot be used then |
| 9929 |
using a move instruction to restore the register since it's |
| 9930 |
less work than reloading sp and popping the register. */ |
| 9931 |
else if (!sp_valid_at (frame.hfp_save_offset) && frame.nregs <= 1) |
| 9932 |
restore_regs_via_mov = true; |
| 9933 |
else if (TARGET_EPILOGUE_USING_MOVE |
| 9934 |
&& cfun->machine->use_fast_prologue_epilogue |
| 9935 |
&& (frame.nregs > 1 |
| 9936 |
|| m->fs.sp_offset != reg_save_offset)) |
| 9937 |
restore_regs_via_mov = true; |
| 9938 |
else if (frame_pointer_needed |
| 9939 |
&& !frame.nregs |
| 9940 |
&& m->fs.sp_offset != reg_save_offset) |
| 9941 |
restore_regs_via_mov = true; |
| 9942 |
else if (frame_pointer_needed |
| 9943 |
&& TARGET_USE_LEAVE |
| 9944 |
&& cfun->machine->use_fast_prologue_epilogue |
| 9945 |
&& frame.nregs == 1) |
| 9946 |
restore_regs_via_mov = true; |
| 9947 |
else |
| 9948 |
restore_regs_via_mov = false; |
| 9949 |
|
| 9950 |
if (restore_regs_via_mov || frame.nsseregs) |
| 9951 |
{ |
| 9952 |
/* Ensure that the entire register save area is addressable via |
| 9953 |
the stack pointer, if we will restore SSE regs via sp. */ |
| 9954 |
if (TARGET_64BIT |
| 9955 |
&& m->fs.sp_offset > 0x7fffffff |
| 9956 |
&& sp_valid_at (frame.stack_realign_offset + 1) |
| 9957 |
&& (frame.nsseregs + frame.nregs) != 0) |
| 9958 |
{ |
| 9959 |
pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx, |
| 9960 |
GEN_INT (m->fs.sp_offset |
| 9961 |
- frame.sse_reg_save_offset), |
| 9962 |
style, |
| 9963 |
m->fs.cfa_reg == stack_pointer_rtx); |
| 9964 |
} |
| 9965 |
} |
| 9966 |
|
| 9967 |
/* If there are any SSE registers to restore, then we have to do it |
| 9968 |
via moves, since there's obviously no pop for SSE regs. */ |
| 9969 |
if (frame.nsseregs) |
| 9970 |
ix86_emit_restore_sse_regs_using_mov (frame.sse_reg_save_offset, |
| 9971 |
style == 2); |
| 9972 |
|
| 9973 |
if (m->call_ms2sysv) |
| 9974 |
{ |
| 9975 |
int pop_incoming_args = crtl->args.pops_args && crtl->args.size; |
| 9976 |
|
| 9977 |
/* We cannot use a tail-call for the stub if: |
| 9978 |
1. We have to pop incoming args, |
| 9979 |
2. We have additional int regs to restore, or |
| 9980 |
3. A sibling call will be the tail-call, or |
| 9981 |
4. We are emitting an eh_return_internal epilogue. |
| 9982 |
|
| 9983 |
TODO: Item 4 has not yet tested! |
| 9984 |
|
| 9985 |
If any of the above are true, we will call the stub rather than |
| 9986 |
jump to it. */ |
| 9987 |
restore_stub_is_tail = !(pop_incoming_args || frame.nregs || style != 1); |
| 9988 |
ix86_emit_outlined_ms2sysv_restore (frame, !restore_stub_is_tail, style); |
| 9989 |
} |
| 9990 |
|
| 9991 |
/* If using out-of-line stub that is a tail-call, then...*/ |
| 9992 |
if (m->call_ms2sysv && restore_stub_is_tail) |
| 9993 |
{ |
| 9994 |
/* TODO: parinoid tests. (remove eventually) */ |
| 9995 |
gcc_assert (m->fs.sp_valid); |
| 9996 |
gcc_assert (!m->fs.sp_realigned); |
| 9997 |
gcc_assert (!m->fs.fp_valid); |
| 9998 |
gcc_assert (!m->fs.realigned); |
| 9999 |
gcc_assert (m->fs.sp_offset == UNITS_PER_WORD); |
| 10000 |
gcc_assert (!crtl->drap_reg); |
| 10001 |
gcc_assert (!frame.nregs); |
| 10002 |
} |
| 10003 |
else if (restore_regs_via_mov) |
| 10004 |
{ |
| 10005 |
rtx t; |
| 10006 |
|
| 10007 |
if (frame.nregs) |
| 10008 |
ix86_emit_restore_regs_using_mov (reg_save_offset, style == 2); |
| 10009 |
|
| 10010 |
/* eh_return epilogues need %ecx added to the stack pointer. */ |
| 10011 |
if (style == 2) |
| 10012 |
{ |
| 10013 |
rtx sa = EH_RETURN_STACKADJ_RTX; |
| 10014 |
rtx_insn *insn; |
| 10015 |
|
| 10016 |
/* Stack realignment doesn't work with eh_return. */ |
| 10017 |
if (crtl->stack_realign_needed) |
| 10018 |
sorry ("Stack realignment not supported with " |
| 10019 |
"%<__builtin_eh_return%>"); |
| 10020 |
|
| 10021 |
/* regparm nested functions don't work with eh_return. */ |
| 10022 |
if (ix86_static_chain_on_stack) |
| 10023 |
sorry ("regparm nested function not supported with " |
| 10024 |
"%<__builtin_eh_return%>"); |
| 10025 |
|
| 10026 |
if (frame_pointer_needed) |
| 10027 |
{ |
| 10028 |
t = gen_rtx_PLUS (Pmode, hard_frame_pointer_rtx, sa); |
| 10029 |
t = plus_constant (Pmode, t, m->fs.fp_offset - UNITS_PER_WORD); |
| 10030 |
emit_insn (gen_rtx_SET (sa, t)); |
| 10031 |
|
| 10032 |
/* NB: eh_return epilogues must restore the frame pointer |
| 10033 |
in word_mode since the upper 32 bits of RBP register |
| 10034 |
can have any values. */ |
| 10035 |
t = gen_frame_mem (word_mode, hard_frame_pointer_rtx); |
| 10036 |
rtx frame_reg = gen_rtx_REG (word_mode, |
| 10037 |
HARD_FRAME_POINTER_REGNUM); |
| 10038 |
insn = emit_move_insn (frame_reg, t); |
| 10039 |
|
| 10040 |
/* Note that we use SA as a temporary CFA, as the return |
| 10041 |
address is at the proper place relative to it. We |
| 10042 |
pretend this happens at the FP restore insn because |
| 10043 |
prior to this insn the FP would be stored at the wrong |
| 10044 |
offset relative to SA, and after this insn we have no |
| 10045 |
other reasonable register to use for the CFA. We don't |
| 10046 |
bother resetting the CFA to the SP for the duration of |
| 10047 |
the return insn, unless the control flow instrumentation |
| 10048 |
is done. In this case the SP is used later and we have |
| 10049 |
to reset CFA to SP. */ |
| 10050 |
add_reg_note (insn, REG_CFA_DEF_CFA, |
| 10051 |
plus_constant (Pmode, sa, UNITS_PER_WORD)); |
| 10052 |
ix86_add_queued_cfa_restore_notes (insn); |
| 10053 |
add_reg_note (insn, REG_CFA_RESTORE, frame_reg); |
| 10054 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 10055 |
|
| 10056 |
m->fs.cfa_reg = sa; |
| 10057 |
m->fs.cfa_offset = UNITS_PER_WORD; |
| 10058 |
m->fs.fp_valid = false; |
| 10059 |
|
| 10060 |
pro_epilogue_adjust_stack (stack_pointer_rtx, sa, |
| 10061 |
const0_rtx, style, |
| 10062 |
flag_cf_protection); |
| 10063 |
} |
| 10064 |
else |
| 10065 |
{ |
| 10066 |
t = gen_rtx_PLUS (Pmode, stack_pointer_rtx, sa); |
| 10067 |
t = plus_constant (Pmode, t, m->fs.sp_offset - UNITS_PER_WORD); |
| 10068 |
insn = emit_insn (gen_rtx_SET (stack_pointer_rtx, t)); |
| 10069 |
ix86_add_queued_cfa_restore_notes (insn); |
| 10070 |
|
| 10071 |
gcc_assert (m->fs.cfa_reg == stack_pointer_rtx); |
| 10072 |
if (m->fs.cfa_offset != UNITS_PER_WORD) |
| 10073 |
{ |
| 10074 |
m->fs.cfa_offset = UNITS_PER_WORD; |
| 10075 |
add_reg_note (insn, REG_CFA_DEF_CFA, |
| 10076 |
plus_constant (Pmode, stack_pointer_rtx, |
| 10077 |
UNITS_PER_WORD)); |
| 10078 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 10079 |
} |
| 10080 |
} |
| 10081 |
m->fs.sp_offset = UNITS_PER_WORD; |
| 10082 |
m->fs.sp_valid = true; |
| 10083 |
m->fs.sp_realigned = false; |
| 10084 |
} |
| 10085 |
} |
| 10086 |
else |
| 10087 |
{ |
| 10088 |
/* SEH requires that the function end with (1) a stack adjustment |
| 10089 |
if necessary, (2) a sequence of pops, and (3) a return or |
| 10090 |
jump instruction. Prevent insns from the function body from |
| 10091 |
being scheduled into this sequence. */ |
| 10092 |
if (TARGET_SEH) |
| 10093 |
{ |
| 10094 |
/* Prevent a catch region from being adjacent to the standard |
| 10095 |
epilogue sequence. Unfortunately neither crtl->uses_eh_lsda |
| 10096 |
nor several other flags that would be interesting to test are |
| 10097 |
set up yet. */ |
| 10098 |
if (flag_non_call_exceptions) |
| 10099 |
emit_insn (gen_nops (const1_rtx)); |
| 10100 |
else |
| 10101 |
emit_insn (gen_blockage ()); |
| 10102 |
} |
| 10103 |
|
| 10104 |
/* First step is to deallocate the stack frame so that we can |
| 10105 |
pop the registers. If the stack pointer was realigned, it needs |
| 10106 |
to be restored now. Also do it on SEH target for very large |
| 10107 |
frame as the emitted instructions aren't allowed by the ABI |
| 10108 |
in epilogues. */ |
| 10109 |
if (!m->fs.sp_valid || m->fs.sp_realigned |
| 10110 |
|| (TARGET_SEH |
| 10111 |
&& (m->fs.sp_offset - reg_save_offset |
| 10112 |
>= SEH_MAX_FRAME_SIZE))) |
| 10113 |
{ |
| 10114 |
pro_epilogue_adjust_stack (stack_pointer_rtx, hard_frame_pointer_rtx, |
| 10115 |
GEN_INT (m->fs.fp_offset |
| 10116 |
- reg_save_offset), |
| 10117 |
style, false); |
| 10118 |
} |
| 10119 |
else if (m->fs.sp_offset != reg_save_offset) |
| 10120 |
{ |
| 10121 |
pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx, |
| 10122 |
GEN_INT (m->fs.sp_offset |
| 10123 |
- reg_save_offset), |
| 10124 |
style, |
| 10125 |
m->fs.cfa_reg == stack_pointer_rtx); |
| 10126 |
} |
| 10127 |
|
| 10128 |
if (TARGET_APX_PUSH2POP2 |
| 10129 |
&& ix86_can_use_push2pop2 () |
| 10130 |
&& m->func_type == TYPE_NORMAL) |
| 10131 |
ix86_emit_restore_regs_using_pop2 (); |
| 10132 |
else |
| 10133 |
ix86_emit_restore_regs_using_pop (TARGET_APX_PPX); |
| 10134 |
} |
| 10135 |
|
| 10136 |
/* If we used a stack pointer and haven't already got rid of it, |
| 10137 |
then do so now. */ |
| 10138 |
if (m->fs.fp_valid) |
| 10139 |
{ |
| 10140 |
/* If the stack pointer is valid and pointing at the frame |
| 10141 |
pointer store address, then we only need a pop. */ |
| 10142 |
if (sp_valid_at (frame.hfp_save_offset) |
| 10143 |
&& m->fs.sp_offset == frame.hfp_save_offset) |
| 10144 |
ix86_emit_restore_reg_using_pop (hard_frame_pointer_rtx); |
| 10145 |
/* Leave results in shorter dependency chains on CPUs that are |
| 10146 |
able to grok it fast. */ |
| 10147 |
else if (TARGET_USE_LEAVE |
| 10148 |
|| optimize_bb_for_size_p (EXIT_BLOCK_PTR_FOR_FN (cfun)) |
| 10149 |
|| !cfun->machine->use_fast_prologue_epilogue) |
| 10150 |
ix86_emit_leave (NULL); |
| 10151 |
else |
| 10152 |
{ |
| 10153 |
pro_epilogue_adjust_stack (stack_pointer_rtx, |
| 10154 |
hard_frame_pointer_rtx, |
| 10155 |
const0_rtx, style, !using_drap); |
| 10156 |
ix86_emit_restore_reg_using_pop (hard_frame_pointer_rtx); |
| 10157 |
} |
| 10158 |
} |
| 10159 |
|
| 10160 |
if (using_drap) |
| 10161 |
{ |
| 10162 |
int param_ptr_offset = UNITS_PER_WORD; |
| 10163 |
rtx_insn *insn; |
| 10164 |
|
| 10165 |
gcc_assert (stack_realign_drap); |
| 10166 |
|
| 10167 |
if (ix86_static_chain_on_stack) |
| 10168 |
param_ptr_offset += UNITS_PER_WORD; |
| 10169 |
if (!call_used_or_fixed_reg_p (REGNO (crtl->drap_reg))) |
| 10170 |
param_ptr_offset += UNITS_PER_WORD; |
| 10171 |
|
| 10172 |
insn = emit_insn (gen_rtx_SET |
| 10173 |
(stack_pointer_rtx, |
| 10174 |
plus_constant (Pmode, crtl->drap_reg, |
| 10175 |
-param_ptr_offset))); |
| 10176 |
m->fs.cfa_reg = stack_pointer_rtx; |
| 10177 |
m->fs.cfa_offset = param_ptr_offset; |
| 10178 |
m->fs.sp_offset = param_ptr_offset; |
| 10179 |
m->fs.realigned = false; |
| 10180 |
|
| 10181 |
add_reg_note (insn, REG_CFA_DEF_CFA, |
| 10182 |
plus_constant (Pmode, stack_pointer_rtx, |
| 10183 |
param_ptr_offset)); |
| 10184 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 10185 |
|
| 10186 |
if (!call_used_or_fixed_reg_p (REGNO (crtl->drap_reg))) |
| 10187 |
ix86_emit_restore_reg_using_pop (crtl->drap_reg); |
| 10188 |
} |
| 10189 |
|
| 10190 |
/* At this point the stack pointer must be valid, and we must have |
| 10191 |
restored all of the registers. We may not have deallocated the |
| 10192 |
entire stack frame. We've delayed this until now because it may |
| 10193 |
be possible to merge the local stack deallocation with the |
| 10194 |
deallocation forced by ix86_static_chain_on_stack. */ |
| 10195 |
gcc_assert (m->fs.sp_valid); |
| 10196 |
gcc_assert (!m->fs.sp_realigned); |
| 10197 |
gcc_assert (!m->fs.fp_valid); |
| 10198 |
gcc_assert (!m->fs.realigned); |
| 10199 |
if (m->fs.sp_offset != UNITS_PER_WORD) |
| 10200 |
{ |
| 10201 |
pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx, |
| 10202 |
GEN_INT (m->fs.sp_offset - UNITS_PER_WORD), |
| 10203 |
style, true); |
| 10204 |
} |
| 10205 |
else |
| 10206 |
ix86_add_queued_cfa_restore_notes (get_last_insn ()); |
| 10207 |
|
| 10208 |
/* Sibcall epilogues don't want a return instruction. */ |
| 10209 |
if (style == 0) |
| 10210 |
{ |
| 10211 |
m->fs = frame_state_save; |
| 10212 |
return; |
| 10213 |
} |
| 10214 |
|
| 10215 |
if (cfun->machine->func_type != TYPE_NORMAL) |
| 10216 |
emit_jump_insn (gen_interrupt_return ()); |
| 10217 |
else if (crtl->args.pops_args && crtl->args.size) |
| 10218 |
{ |
| 10219 |
rtx popc = GEN_INT (crtl->args.pops_args); |
| 10220 |
|
| 10221 |
/* i386 can only pop 64K bytes. If asked to pop more, pop return |
| 10222 |
address, do explicit add, and jump indirectly to the caller. */ |
| 10223 |
|
| 10224 |
if (crtl->args.pops_args >= 65536) |
| 10225 |
{ |
| 10226 |
rtx ecx = gen_rtx_REG (SImode, CX_REG); |
| 10227 |
rtx_insn *insn; |
| 10228 |
|
| 10229 |
/* There is no "pascal" calling convention in any 64bit ABI. */ |
| 10230 |
gcc_assert (!TARGET_64BIT); |
| 10231 |
|
| 10232 |
insn = emit_insn (gen_pop (ecx)); |
| 10233 |
m->fs.cfa_offset -= UNITS_PER_WORD; |
| 10234 |
m->fs.sp_offset -= UNITS_PER_WORD; |
| 10235 |
|
| 10236 |
rtx x = plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD); |
| 10237 |
x = gen_rtx_SET (stack_pointer_rtx, x); |
| 10238 |
add_reg_note (insn, REG_CFA_ADJUST_CFA, x); |
| 10239 |
add_reg_note (insn, REG_CFA_REGISTER, gen_rtx_SET (ecx, pc_rtx)); |
| 10240 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 10241 |
|
| 10242 |
pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx, |
| 10243 |
popc, -1, true); |
| 10244 |
emit_jump_insn (gen_simple_return_indirect_internal (ecx)); |
| 10245 |
} |
| 10246 |
else |
| 10247 |
emit_jump_insn (gen_simple_return_pop_internal (popc)); |
| 10248 |
} |
| 10249 |
else if (!m->call_ms2sysv || !restore_stub_is_tail) |
| 10250 |
{ |
| 10251 |
/* In case of return from EH a simple return cannot be used |
| 10252 |
as a return address will be compared with a shadow stack |
| 10253 |
return address. Use indirect jump instead. */ |
| 10254 |
if (style == 2 && flag_cf_protection) |
| 10255 |
{ |
| 10256 |
/* Register used in indirect jump must be in word_mode. But |
| 10257 |
Pmode may not be the same as word_mode for x32. */ |
| 10258 |
rtx ecx = gen_rtx_REG (word_mode, CX_REG); |
| 10259 |
rtx_insn *insn; |
| 10260 |
|
| 10261 |
insn = emit_insn (gen_pop (ecx)); |
| 10262 |
m->fs.cfa_offset -= UNITS_PER_WORD; |
| 10263 |
m->fs.sp_offset -= UNITS_PER_WORD; |
| 10264 |
|
| 10265 |
rtx x = plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD); |
| 10266 |
x = gen_rtx_SET (stack_pointer_rtx, x); |
| 10267 |
add_reg_note (insn, REG_CFA_ADJUST_CFA, x); |
| 10268 |
add_reg_note (insn, REG_CFA_REGISTER, gen_rtx_SET (ecx, pc_rtx)); |
| 10269 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 10270 |
|
| 10271 |
emit_jump_insn (gen_simple_return_indirect_internal (ecx)); |
| 10272 |
} |
| 10273 |
else |
| 10274 |
emit_jump_insn (gen_simple_return_internal ()); |
| 10275 |
} |
| 10276 |
|
| 10277 |
/* Restore the state back to the state from the prologue, |
| 10278 |
so that it's correct for the next epilogue. */ |
| 10279 |
m->fs = frame_state_save; |
| 10280 |
} |
| 10281 |
|
| 10282 |
/* Reset from the function's potential modifications. */ |
| 10283 |
|
| 10284 |
static void |
| 10285 |
ix86_output_function_epilogue (FILE *file ATTRIBUTE_UNUSED) |
| 10286 |
{ |
| 10287 |
if (pic_offset_table_rtx |
| 10288 |
&& !ix86_use_pseudo_pic_reg ()) |
| 10289 |
SET_REGNO (pic_offset_table_rtx, REAL_PIC_OFFSET_TABLE_REGNUM); |
| 10290 |
|
| 10291 |
if (TARGET_MACHO) |
| 10292 |
{ |
| 10293 |
rtx_insn *insn = get_last_insn (); |
| 10294 |
rtx_insn *deleted_debug_label = NULL; |
| 10295 |
|
| 10296 |
/* Mach-O doesn't support labels at the end of objects, so if |
| 10297 |
it looks like we might want one, take special action. |
| 10298 |
First, collect any sequence of deleted debug labels. */ |
| 10299 |
while (insn |
| 10300 |
&& NOTE_P (insn) |
| 10301 |
&& NOTE_KIND (insn) != NOTE_INSN_DELETED_LABEL) |
| 10302 |
{ |
| 10303 |
/* Don't insert a nop for NOTE_INSN_DELETED_DEBUG_LABEL |
| 10304 |
notes only, instead set their CODE_LABEL_NUMBER to -1, |
| 10305 |
otherwise there would be code generation differences |
| 10306 |
in between -g and -g0. */ |
| 10307 |
if (NOTE_P (insn) && NOTE_KIND (insn) |
| 10308 |
== NOTE_INSN_DELETED_DEBUG_LABEL) |
| 10309 |
deleted_debug_label = insn; |
| 10310 |
insn = PREV_INSN (insn); |
| 10311 |
} |
| 10312 |
|
| 10313 |
/* If we have: |
| 10314 |
label: |
| 10315 |
barrier |
| 10316 |
then this needs to be detected, so skip past the barrier. */ |
| 10317 |
|
| 10318 |
if (insn && BARRIER_P (insn)) |
| 10319 |
insn = PREV_INSN (insn); |
| 10320 |
|
| 10321 |
/* Up to now we've only seen notes or barriers. */ |
| 10322 |
if (insn) |
| 10323 |
{ |
| 10324 |
if (LABEL_P (insn) |
| 10325 |
|| (NOTE_P (insn) |
| 10326 |
&& NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL)) |
| 10327 |
/* Trailing label. */ |
| 10328 |
fputs ("\tnop\n", file); |
| 10329 |
else if (cfun && ! cfun->is_thunk) |
| 10330 |
{ |
| 10331 |
/* See if we have a completely empty function body, skipping |
| 10332 |
the special case of the picbase thunk emitted as asm. */ |
| 10333 |
while (insn && ! INSN_P (insn)) |
| 10334 |
insn = PREV_INSN (insn); |
| 10335 |
/* If we don't find any insns, we've got an empty function body; |
| 10336 |
I.e. completely empty - without a return or branch. This is |
| 10337 |
taken as the case where a function body has been removed |
| 10338 |
because it contains an inline __builtin_unreachable(). GCC |
| 10339 |
declares that reaching __builtin_unreachable() means UB so |
| 10340 |
we're not obliged to do anything special; however, we want |
| 10341 |
non-zero-sized function bodies. To meet this, and help the |
| 10342 |
user out, let's trap the case. */ |
| 10343 |
if (insn == NULL) |
| 10344 |
fputs ("\tud2\n", file); |
| 10345 |
} |
| 10346 |
} |
| 10347 |
else if (deleted_debug_label) |
| 10348 |
for (insn = deleted_debug_label; insn; insn = NEXT_INSN (insn)) |
| 10349 |
if (NOTE_KIND (insn) == NOTE_INSN_DELETED_DEBUG_LABEL) |
| 10350 |
CODE_LABEL_NUMBER (insn) = -1; |
| 10351 |
} |
| 10352 |
} |
| 10353 |
|
| 10354 |
/* Implement TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY. */ |
| 10355 |
|
| 10356 |
void |
| 10357 |
ix86_print_patchable_function_entry (FILE *file, |
| 10358 |
unsigned HOST_WIDE_INT patch_area_size, |
| 10359 |
bool record_p) |
| 10360 |
{ |
| 10361 |
if (cfun->machine->function_label_emitted) |
| 10362 |
{ |
| 10363 |
/* NB: When ix86_print_patchable_function_entry is called after |
| 10364 |
function table has been emitted, we have inserted or queued |
| 10365 |
a pseudo UNSPECV_PATCHABLE_AREA instruction at the proper |
| 10366 |
place. There is nothing to do here. */ |
| 10367 |
return; |
| 10368 |
} |
| 10369 |
|
| 10370 |
default_print_patchable_function_entry (file, patch_area_size, |
| 10371 |
record_p); |
| 10372 |
} |
| 10373 |
|
| 10374 |
/* Output patchable area. NB: default_print_patchable_function_entry |
| 10375 |
isn't available in i386.md. */ |
| 10376 |
|
| 10377 |
void |
| 10378 |
ix86_output_patchable_area (unsigned int patch_area_size, |
| 10379 |
bool record_p) |
| 10380 |
{ |
| 10381 |
default_print_patchable_function_entry (asm_out_file, |
| 10382 |
patch_area_size, |
| 10383 |
record_p); |
| 10384 |
} |
| 10385 |
|
| 10386 |
/* Return a scratch register to use in the split stack prologue. The |
| 10387 |
split stack prologue is used for -fsplit-stack. It is the first |
| 10388 |
instructions in the function, even before the regular prologue. |
| 10389 |
The scratch register can be any caller-saved register which is not |
| 10390 |
used for parameters or for the static chain. */ |
| 10391 |
|
| 10392 |
static unsigned int |
| 10393 |
split_stack_prologue_scratch_regno (void) |
| 10394 |
{ |
| 10395 |
if (TARGET_64BIT) |
| 10396 |
return R11_REG; |
| 10397 |
else |
| 10398 |
{ |
| 10399 |
bool is_fastcall, is_thiscall; |
| 10400 |
int regparm; |
| 10401 |
|
| 10402 |
is_fastcall = (lookup_attribute ("fastcall", |
| 10403 |
TYPE_ATTRIBUTES (TREE_TYPE (cfun->decl))) |
| 10404 |
!= NULL); |
| 10405 |
is_thiscall = (lookup_attribute ("thiscall", |
| 10406 |
TYPE_ATTRIBUTES (TREE_TYPE (cfun->decl))) |
| 10407 |
!= NULL); |
| 10408 |
regparm = ix86_function_regparm (TREE_TYPE (cfun->decl), cfun->decl); |
| 10409 |
|
| 10410 |
if (is_fastcall) |
| 10411 |
{ |
| 10412 |
if (DECL_STATIC_CHAIN (cfun->decl)) |
| 10413 |
{ |
| 10414 |
sorry ("%<-fsplit-stack%> does not support fastcall with " |
| 10415 |
"nested function"); |
| 10416 |
return INVALID_REGNUM; |
| 10417 |
} |
| 10418 |
return AX_REG; |
| 10419 |
} |
| 10420 |
else if (is_thiscall) |
| 10421 |
{ |
| 10422 |
if (!DECL_STATIC_CHAIN (cfun->decl)) |
| 10423 |
return DX_REG; |
| 10424 |
return AX_REG; |
| 10425 |
} |
| 10426 |
else if (regparm < 3) |
| 10427 |
{ |
| 10428 |
if (!DECL_STATIC_CHAIN (cfun->decl)) |
| 10429 |
return CX_REG; |
| 10430 |
else |
| 10431 |
{ |
| 10432 |
if (regparm >= 2) |
| 10433 |
{ |
| 10434 |
sorry ("%<-fsplit-stack%> does not support 2 register " |
| 10435 |
"parameters for a nested function"); |
| 10436 |
return INVALID_REGNUM; |
| 10437 |
} |
| 10438 |
return DX_REG; |
| 10439 |
} |
| 10440 |
} |
| 10441 |
else |
| 10442 |
{ |
| 10443 |
/* FIXME: We could make this work by pushing a register |
| 10444 |
around the addition and comparison. */ |
| 10445 |
sorry ("%<-fsplit-stack%> does not support 3 register parameters"); |
| 10446 |
return INVALID_REGNUM; |
| 10447 |
} |
| 10448 |
} |
| 10449 |
} |
| 10450 |
|
| 10451 |
/* A SYMBOL_REF for the function which allocates new stackspace for |
| 10452 |
-fsplit-stack. */ |
| 10453 |
|
| 10454 |
static GTY(()) rtx split_stack_fn; |
| 10455 |
|
| 10456 |
/* A SYMBOL_REF for the more stack function when using the large |
| 10457 |
model. */ |
| 10458 |
|
| 10459 |
static GTY(()) rtx split_stack_fn_large; |
| 10460 |
|
| 10461 |
/* Return location of the stack guard value in the TLS block. */ |
| 10462 |
|
| 10463 |
rtx |
| 10464 |
ix86_split_stack_guard (void) |
| 10465 |
{ |
| 10466 |
int offset; |
| 10467 |
addr_space_t as = DEFAULT_TLS_SEG_REG; |
| 10468 |
rtx r; |
| 10469 |
|
| 10470 |
gcc_assert (flag_split_stack); |
| 10471 |
|
| 10472 |
#ifdef TARGET_THREAD_SPLIT_STACK_OFFSET |
| 10473 |
offset = TARGET_THREAD_SPLIT_STACK_OFFSET; |
| 10474 |
#else |
| 10475 |
gcc_unreachable (); |
| 10476 |
#endif |
| 10477 |
|
| 10478 |
r = GEN_INT (offset); |
| 10479 |
r = gen_const_mem (Pmode, r); |
| 10480 |
set_mem_addr_space (r, as); |
| 10481 |
|
| 10482 |
return r; |
| 10483 |
} |
| 10484 |
|
| 10485 |
/* Handle -fsplit-stack. These are the first instructions in the |
| 10486 |
function, even before the regular prologue. */ |
| 10487 |
|
| 10488 |
void |
| 10489 |
ix86_expand_split_stack_prologue (void) |
| 10490 |
{ |
| 10491 |
HOST_WIDE_INT allocate; |
| 10492 |
unsigned HOST_WIDE_INT args_size; |
| 10493 |
rtx_code_label *label; |
| 10494 |
rtx limit, current, allocate_rtx, call_fusage; |
| 10495 |
rtx_insn *call_insn; |
| 10496 |
unsigned int scratch_regno = INVALID_REGNUM; |
| 10497 |
rtx scratch_reg = NULL_RTX; |
| 10498 |
rtx_code_label *varargs_label = NULL; |
| 10499 |
rtx fn; |
| 10500 |
|
| 10501 |
gcc_assert (flag_split_stack && reload_completed); |
| 10502 |
|
| 10503 |
ix86_finalize_stack_frame_flags (); |
| 10504 |
struct ix86_frame &frame = cfun->machine->frame; |
| 10505 |
allocate = frame.stack_pointer_offset - INCOMING_FRAME_SP_OFFSET; |
| 10506 |
|
| 10507 |
/* This is the label we will branch to if we have enough stack |
| 10508 |
space. We expect the basic block reordering pass to reverse this |
| 10509 |
branch if optimizing, so that we branch in the unlikely case. */ |
| 10510 |
label = gen_label_rtx (); |
| 10511 |
|
| 10512 |
/* We need to compare the stack pointer minus the frame size with |
| 10513 |
the stack boundary in the TCB. The stack boundary always gives |
| 10514 |
us SPLIT_STACK_AVAILABLE bytes, so if we need less than that we |
| 10515 |
can compare directly. Otherwise we need to do an addition. */ |
| 10516 |
|
| 10517 |
limit = ix86_split_stack_guard (); |
| 10518 |
|
| 10519 |
if (allocate >= SPLIT_STACK_AVAILABLE |
| 10520 |
|| flag_force_indirect_call) |
| 10521 |
{ |
| 10522 |
scratch_regno = split_stack_prologue_scratch_regno (); |
| 10523 |
if (scratch_regno == INVALID_REGNUM) |
| 10524 |
return; |
| 10525 |
} |
| 10526 |
|
| 10527 |
if (allocate >= SPLIT_STACK_AVAILABLE) |
| 10528 |
{ |
| 10529 |
rtx offset; |
| 10530 |
|
| 10531 |
/* We need a scratch register to hold the stack pointer minus |
| 10532 |
the required frame size. Since this is the very start of the |
| 10533 |
function, the scratch register can be any caller-saved |
| 10534 |
register which is not used for parameters. */ |
| 10535 |
offset = GEN_INT (- allocate); |
| 10536 |
|
| 10537 |
scratch_reg = gen_rtx_REG (Pmode, scratch_regno); |
| 10538 |
if (!TARGET_64BIT || x86_64_immediate_operand (offset, Pmode)) |
| 10539 |
{ |
| 10540 |
/* We don't use gen_add in this case because it will |
| 10541 |
want to split to lea, but when not optimizing the insn |
| 10542 |
will not be split after this point. */ |
| 10543 |
emit_insn (gen_rtx_SET (scratch_reg, |
| 10544 |
gen_rtx_PLUS (Pmode, stack_pointer_rtx, |
| 10545 |
offset))); |
| 10546 |
} |
| 10547 |
else |
| 10548 |
{ |
| 10549 |
emit_move_insn (scratch_reg, offset); |
| 10550 |
emit_insn (gen_add2_insn (scratch_reg, stack_pointer_rtx)); |
| 10551 |
} |
| 10552 |
current = scratch_reg; |
| 10553 |
} |
| 10554 |
else |
| 10555 |
current = stack_pointer_rtx; |
| 10556 |
|
| 10557 |
ix86_expand_branch (GEU, current, limit, label); |
| 10558 |
rtx_insn *jump_insn = get_last_insn (); |
| 10559 |
JUMP_LABEL (jump_insn) = label; |
| 10560 |
|
| 10561 |
/* Mark the jump as very likely to be taken. */ |
| 10562 |
add_reg_br_prob_note (jump_insn, profile_probability::very_likely ()); |
| 10563 |
|
| 10564 |
if (split_stack_fn == NULL_RTX) |
| 10565 |
{ |
| 10566 |
split_stack_fn = gen_rtx_SYMBOL_REF (Pmode, "__morestack"); |
| 10567 |
SYMBOL_REF_FLAGS (split_stack_fn) |= SYMBOL_FLAG_LOCAL; |
| 10568 |
} |
| 10569 |
fn = split_stack_fn; |
| 10570 |
|
| 10571 |
/* Get more stack space. We pass in the desired stack space and the |
| 10572 |
size of the arguments to copy to the new stack. In 32-bit mode |
| 10573 |
we push the parameters; __morestack will return on a new stack |
| 10574 |
anyhow. In 64-bit mode we pass the parameters in r10 and |
| 10575 |
r11. */ |
| 10576 |
allocate_rtx = GEN_INT (allocate); |
| 10577 |
args_size = crtl->args.size >= 0 ? (HOST_WIDE_INT) crtl->args.size : 0; |
| 10578 |
call_fusage = NULL_RTX; |
| 10579 |
rtx pop = NULL_RTX; |
| 10580 |
if (TARGET_64BIT) |
| 10581 |
{ |
| 10582 |
rtx reg10, reg11; |
| 10583 |
|
| 10584 |
reg10 = gen_rtx_REG (DImode, R10_REG); |
| 10585 |
reg11 = gen_rtx_REG (DImode, R11_REG); |
| 10586 |
|
| 10587 |
/* If this function uses a static chain, it will be in %r10. |
| 10588 |
Preserve it across the call to __morestack. */ |
| 10589 |
if (DECL_STATIC_CHAIN (cfun->decl)) |
| 10590 |
{ |
| 10591 |
rtx rax; |
| 10592 |
|
| 10593 |
rax = gen_rtx_REG (word_mode, AX_REG); |
| 10594 |
emit_move_insn (rax, gen_rtx_REG (word_mode, R10_REG)); |
| 10595 |
use_reg (&call_fusage, rax); |
| 10596 |
} |
| 10597 |
|
| 10598 |
if (flag_force_indirect_call |
| 10599 |
|| ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC) |
| 10600 |
{ |
| 10601 |
HOST_WIDE_INT argval; |
| 10602 |
|
| 10603 |
if (split_stack_fn_large == NULL_RTX) |
| 10604 |
{ |
| 10605 |
split_stack_fn_large |
| 10606 |
= gen_rtx_SYMBOL_REF (Pmode, "__morestack_large_model"); |
| 10607 |
SYMBOL_REF_FLAGS (split_stack_fn_large) |= SYMBOL_FLAG_LOCAL; |
| 10608 |
} |
| 10609 |
|
| 10610 |
fn = split_stack_fn_large; |
| 10611 |
|
| 10612 |
if (ix86_cmodel == CM_LARGE_PIC) |
| 10613 |
{ |
| 10614 |
rtx_code_label *label; |
| 10615 |
rtx x; |
| 10616 |
|
| 10617 |
gcc_assert (Pmode == DImode); |
| 10618 |
|
| 10619 |
label = gen_label_rtx (); |
| 10620 |
emit_label (label); |
| 10621 |
LABEL_PRESERVE_P (label) = 1; |
| 10622 |
emit_insn (gen_set_rip_rex64 (reg10, label)); |
| 10623 |
emit_insn (gen_set_got_offset_rex64 (reg11, label)); |
| 10624 |
emit_insn (gen_add2_insn (reg10, reg11)); |
| 10625 |
x = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, fn), UNSPEC_GOT); |
| 10626 |
x = gen_rtx_CONST (Pmode, x); |
| 10627 |
emit_move_insn (reg11, x); |
| 10628 |
x = gen_rtx_PLUS (Pmode, reg10, reg11); |
| 10629 |
x = gen_const_mem (Pmode, x); |
| 10630 |
fn = copy_to_suggested_reg (x, reg11, Pmode); |
| 10631 |
} |
| 10632 |
else if (ix86_cmodel == CM_LARGE) |
| 10633 |
fn = copy_to_suggested_reg (fn, reg11, Pmode); |
| 10634 |
|
| 10635 |
/* When using the large model we need to load the address |
| 10636 |
into a register, and we've run out of registers. So we |
| 10637 |
switch to a different calling convention, and we call a |
| 10638 |
different function: __morestack_large. We pass the |
| 10639 |
argument size in the upper 32 bits of r10 and pass the |
| 10640 |
frame size in the lower 32 bits. */ |
| 10641 |
gcc_assert ((allocate & HOST_WIDE_INT_C (0xffffffff)) == allocate); |
| 10642 |
gcc_assert ((args_size & 0xffffffff) == args_size); |
| 10643 |
|
| 10644 |
argval = ((args_size << 16) << 16) + allocate; |
| 10645 |
emit_move_insn (reg10, GEN_INT (argval)); |
| 10646 |
} |
| 10647 |
else |
| 10648 |
{ |
| 10649 |
emit_move_insn (reg10, allocate_rtx); |
| 10650 |
emit_move_insn (reg11, GEN_INT (args_size)); |
| 10651 |
use_reg (&call_fusage, reg11); |
| 10652 |
} |
| 10653 |
|
| 10654 |
use_reg (&call_fusage, reg10); |
| 10655 |
} |
| 10656 |
else |
| 10657 |
{ |
| 10658 |
if (flag_force_indirect_call && flag_pic) |
| 10659 |
{ |
| 10660 |
rtx x; |
| 10661 |
|
| 10662 |
gcc_assert (Pmode == SImode); |
| 10663 |
|
| 10664 |
scratch_reg = gen_rtx_REG (Pmode, scratch_regno); |
| 10665 |
|
| 10666 |
emit_insn (gen_set_got (scratch_reg)); |
| 10667 |
x = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, split_stack_fn), |
| 10668 |
UNSPEC_GOT); |
| 10669 |
x = gen_rtx_CONST (Pmode, x); |
| 10670 |
x = gen_rtx_PLUS (Pmode, scratch_reg, x); |
| 10671 |
x = gen_const_mem (Pmode, x); |
| 10672 |
fn = copy_to_suggested_reg (x, scratch_reg, Pmode); |
| 10673 |
} |
| 10674 |
|
| 10675 |
rtx_insn *insn = emit_insn (gen_push (GEN_INT (args_size))); |
| 10676 |
add_reg_note (insn, REG_ARGS_SIZE, GEN_INT (UNITS_PER_WORD)); |
| 10677 |
insn = emit_insn (gen_push (allocate_rtx)); |
| 10678 |
add_reg_note (insn, REG_ARGS_SIZE, GEN_INT (2 * UNITS_PER_WORD)); |
| 10679 |
pop = GEN_INT (2 * UNITS_PER_WORD); |
| 10680 |
} |
| 10681 |
|
| 10682 |
if (flag_force_indirect_call && !register_operand (fn, VOIDmode)) |
| 10683 |
{ |
| 10684 |
scratch_reg = gen_rtx_REG (word_mode, scratch_regno); |
| 10685 |
|
| 10686 |
if (GET_MODE (fn) != word_mode) |
| 10687 |
fn = gen_rtx_ZERO_EXTEND (word_mode, fn); |
| 10688 |
|
| 10689 |
fn = copy_to_suggested_reg (fn, scratch_reg, word_mode); |
| 10690 |
} |
| 10691 |
|
| 10692 |
call_insn = ix86_expand_call (NULL_RTX, gen_rtx_MEM (QImode, fn), |
| 10693 |
GEN_INT (UNITS_PER_WORD), constm1_rtx, |
| 10694 |
pop, false); |
| 10695 |
add_function_usage_to (call_insn, call_fusage); |
| 10696 |
if (!TARGET_64BIT) |
| 10697 |
add_reg_note (call_insn, REG_ARGS_SIZE, GEN_INT (0)); |
| 10698 |
/* Indicate that this function can't jump to non-local gotos. */ |
| 10699 |
make_reg_eh_region_note_nothrow_nononlocal (call_insn); |
| 10700 |
|
| 10701 |
/* In order to make call/return prediction work right, we now need |
| 10702 |
to execute a return instruction. See |
| 10703 |
libgcc/config/i386/morestack.S for the details on how this works. |
| 10704 |
|
| 10705 |
For flow purposes gcc must not see this as a return |
| 10706 |
instruction--we need control flow to continue at the subsequent |
| 10707 |
label. Therefore, we use an unspec. */ |
| 10708 |
gcc_assert (crtl->args.pops_args < 65536); |
| 10709 |
rtx_insn *ret_insn |
| 10710 |
= emit_insn (gen_split_stack_return (GEN_INT (crtl->args.pops_args))); |
| 10711 |
|
| 10712 |
if ((flag_cf_protection & CF_BRANCH)) |
| 10713 |
{ |
| 10714 |
/* Insert ENDBR since __morestack will jump back here via indirect |
| 10715 |
call. */ |
| 10716 |
rtx cet_eb = gen_nop_endbr (); |
| 10717 |
emit_insn_after (cet_eb, ret_insn); |
| 10718 |
} |
| 10719 |
|
| 10720 |
/* If we are in 64-bit mode and this function uses a static chain, |
| 10721 |
we saved %r10 in %rax before calling _morestack. */ |
| 10722 |
if (TARGET_64BIT && DECL_STATIC_CHAIN (cfun->decl)) |
| 10723 |
emit_move_insn (gen_rtx_REG (word_mode, R10_REG), |
| 10724 |
gen_rtx_REG (word_mode, AX_REG)); |
| 10725 |
|
| 10726 |
/* If this function calls va_start, we need to store a pointer to |
| 10727 |
the arguments on the old stack, because they may not have been |
| 10728 |
all copied to the new stack. At this point the old stack can be |
| 10729 |
found at the frame pointer value used by __morestack, because |
| 10730 |
__morestack has set that up before calling back to us. Here we |
| 10731 |
store that pointer in a scratch register, and in |
| 10732 |
ix86_expand_prologue we store the scratch register in a stack |
| 10733 |
slot. */ |
| 10734 |
if (cfun->machine->split_stack_varargs_pointer != NULL_RTX) |
| 10735 |
{ |
| 10736 |
rtx frame_reg; |
| 10737 |
int words; |
| 10738 |
|
| 10739 |
scratch_regno = split_stack_prologue_scratch_regno (); |
| 10740 |
scratch_reg = gen_rtx_REG (Pmode, scratch_regno); |
| 10741 |
frame_reg = gen_rtx_REG (Pmode, BP_REG); |
| 10742 |
|
| 10743 |
/* 64-bit: |
| 10744 |
fp -> old fp value |
| 10745 |
return address within this function |
| 10746 |
return address of caller of this function |
| 10747 |
stack arguments |
| 10748 |
So we add three words to get to the stack arguments. |
| 10749 |
|
| 10750 |
32-bit: |
| 10751 |
fp -> old fp value |
| 10752 |
return address within this function |
| 10753 |
first argument to __morestack |
| 10754 |
second argument to __morestack |
| 10755 |
return address of caller of this function |
| 10756 |
stack arguments |
| 10757 |
So we add five words to get to the stack arguments. |
| 10758 |
*/ |
| 10759 |
words = TARGET_64BIT ? 3 : 5; |
| 10760 |
emit_insn (gen_rtx_SET (scratch_reg, |
| 10761 |
plus_constant (Pmode, frame_reg, |
| 10762 |
words * UNITS_PER_WORD))); |
| 10763 |
|
| 10764 |
varargs_label = gen_label_rtx (); |
| 10765 |
emit_jump_insn (gen_jump (varargs_label)); |
| 10766 |
JUMP_LABEL (get_last_insn ()) = varargs_label; |
| 10767 |
|
| 10768 |
emit_barrier (); |
| 10769 |
} |
| 10770 |
|
| 10771 |
emit_label (label); |
| 10772 |
LABEL_NUSES (label) = 1; |
| 10773 |
|
| 10774 |
/* If this function calls va_start, we now have to set the scratch |
| 10775 |
register for the case where we do not call __morestack. In this |
| 10776 |
case we need to set it based on the stack pointer. */ |
| 10777 |
if (cfun->machine->split_stack_varargs_pointer != NULL_RTX) |
| 10778 |
{ |
| 10779 |
emit_insn (gen_rtx_SET (scratch_reg, |
| 10780 |
plus_constant (Pmode, stack_pointer_rtx, |
| 10781 |
UNITS_PER_WORD))); |
| 10782 |
|
| 10783 |
emit_label (varargs_label); |
| 10784 |
LABEL_NUSES (varargs_label) = 1; |
| 10785 |
} |
| 10786 |
} |
| 10787 |
|
| 10788 |
/* We may have to tell the dataflow pass that the split stack prologue |
| 10789 |
is initializing a scratch register. */ |
| 10790 |
|
| 10791 |
static void |
| 10792 |
ix86_live_on_entry (bitmap regs) |
| 10793 |
{ |
| 10794 |
if (cfun->machine->split_stack_varargs_pointer != NULL_RTX) |
| 10795 |
{ |
| 10796 |
gcc_assert (flag_split_stack); |
| 10797 |
bitmap_set_bit (regs, split_stack_prologue_scratch_regno ()); |
| 10798 |
} |
| 10799 |
} |
| 10800 |
|
| 10801 |
/* Extract the parts of an RTL expression that is a valid memory address |
| 10802 |
for an instruction. Return false if the structure of the address is |
| 10803 |
grossly off. */ |
| 10804 |
|
| 10805 |
bool |
| 10806 |
ix86_decompose_address (rtx addr, struct ix86_address *out) |
| 10807 |
{ |
| 10808 |
rtx base = NULL_RTX, index = NULL_RTX, disp = NULL_RTX; |
| 10809 |
rtx base_reg, index_reg; |
| 10810 |
HOST_WIDE_INT scale = 1; |
| 10811 |
rtx scale_rtx = NULL_RTX; |
| 10812 |
rtx tmp; |
| 10813 |
addr_space_t seg = ADDR_SPACE_GENERIC; |
| 10814 |
|
| 10815 |
/* Allow zero-extended SImode addresses, |
| 10816 |
they will be emitted with addr32 prefix. */ |
| 10817 |
if (TARGET_64BIT && GET_MODE (addr) == DImode) |
| 10818 |
{ |
| 10819 |
if (GET_CODE (addr) == ZERO_EXTEND |
| 10820 |
&& GET_MODE (XEXP (addr, 0)) == SImode) |
| 10821 |
{ |
| 10822 |
addr = XEXP (addr, 0); |
| 10823 |
if (CONST_INT_P (addr)) |
| 10824 |
return false; |
| 10825 |
} |
| 10826 |
else if (GET_CODE (addr) == AND) |
| 10827 |
{ |
| 10828 |
rtx mask = XEXP (addr, 1); |
| 10829 |
rtx shift_val; |
| 10830 |
|
| 10831 |
if (const_32bit_mask (mask, DImode) |
| 10832 |
/* For ASHIFT inside AND, combine will not generate |
| 10833 |
canonical zero-extend. Merge mask for AND and shift_count |
| 10834 |
to check if it is canonical zero-extend. */ |
| 10835 |
|| (CONST_INT_P (mask) |
| 10836 |
&& GET_CODE (XEXP (addr, 0)) == ASHIFT |
| 10837 |
&& CONST_INT_P (shift_val = XEXP (XEXP (addr, 0), 1)) |
| 10838 |
&& ((UINTVAL (mask) |
| 10839 |
| ((HOST_WIDE_INT_1U << INTVAL (shift_val)) - 1)) |
| 10840 |
== HOST_WIDE_INT_UC (0xffffffff)))) |
| 10841 |
{ |
| 10842 |
addr = lowpart_subreg (SImode, XEXP (addr, 0), DImode); |
| 10843 |
if (addr == NULL_RTX) |
| 10844 |
return false; |
| 10845 |
|
| 10846 |
if (CONST_INT_P (addr)) |
| 10847 |
return false; |
| 10848 |
} |
| 10849 |
} |
| 10850 |
} |
| 10851 |
|
| 10852 |
/* Allow SImode subregs of DImode addresses, |
| 10853 |
they will be emitted with addr32 prefix. */ |
| 10854 |
if (TARGET_64BIT && GET_MODE (addr) == SImode) |
| 10855 |
{ |
| 10856 |
if (SUBREG_P (addr) |
| 10857 |
&& GET_MODE (SUBREG_REG (addr)) == DImode) |
| 10858 |
{ |
| 10859 |
addr = SUBREG_REG (addr); |
| 10860 |
if (CONST_INT_P (addr)) |
| 10861 |
return false; |
| 10862 |
} |
| 10863 |
} |
| 10864 |
|
| 10865 |
if (REG_P (addr)) |
| 10866 |
base = addr; |
| 10867 |
else if (SUBREG_P (addr)) |
| 10868 |
{ |
| 10869 |
if (REG_P (SUBREG_REG (addr))) |
| 10870 |
base = addr; |
| 10871 |
else |
| 10872 |
return false; |
| 10873 |
} |
| 10874 |
else if (GET_CODE (addr) == PLUS) |
| 10875 |
{ |
| 10876 |
rtx addends[4], op; |
| 10877 |
int n = 0, i; |
| 10878 |
|
| 10879 |
op = addr; |
| 10880 |
do |
| 10881 |
{ |
| 10882 |
if (n >= 4) |
| 10883 |
return false; |
| 10884 |
addends[n++] = XEXP (op, 1); |
| 10885 |
op = XEXP (op, 0); |
| 10886 |
} |
| 10887 |
while (GET_CODE (op) == PLUS); |
| 10888 |
if (n >= 4) |
| 10889 |
return false; |
| 10890 |
addends[n] = op; |
| 10891 |
|
| 10892 |
for (i = n; i >= 0; --i) |
| 10893 |
{ |
| 10894 |
op = addends[i]; |
| 10895 |
switch (GET_CODE (op)) |
| 10896 |
{ |
| 10897 |
case MULT: |
| 10898 |
if (index) |
| 10899 |
return false; |
| 10900 |
index = XEXP (op, 0); |
| 10901 |
scale_rtx = XEXP (op, 1); |
| 10902 |
break; |
| 10903 |
|
| 10904 |
case ASHIFT: |
| 10905 |
if (index) |
| 10906 |
return false; |
| 10907 |
index = XEXP (op, 0); |
| 10908 |
tmp = XEXP (op, 1); |
| 10909 |
if (!CONST_INT_P (tmp)) |
| 10910 |
return false; |
| 10911 |
scale = INTVAL (tmp); |
| 10912 |
if ((unsigned HOST_WIDE_INT) scale > 3) |
| 10913 |
return false; |
| 10914 |
scale = 1 << scale; |
| 10915 |
break; |
| 10916 |
|
| 10917 |
case ZERO_EXTEND: |
| 10918 |
op = XEXP (op, 0); |
| 10919 |
if (GET_CODE (op) != UNSPEC) |
| 10920 |
return false; |
| 10921 |
/* FALLTHRU */ |
| 10922 |
|
| 10923 |
case UNSPEC: |
| 10924 |
if (XINT (op, 1) == UNSPEC_TP |
| 10925 |
&& TARGET_TLS_DIRECT_SEG_REFS |
| 10926 |
&& seg == ADDR_SPACE_GENERIC) |
| 10927 |
seg = DEFAULT_TLS_SEG_REG; |
| 10928 |
else |
| 10929 |
return false; |
| 10930 |
break; |
| 10931 |
|
| 10932 |
case SUBREG: |
| 10933 |
if (!REG_P (SUBREG_REG (op))) |
| 10934 |
return false; |
| 10935 |
/* FALLTHRU */ |
| 10936 |
|
| 10937 |
case REG: |
| 10938 |
if (!base) |
| 10939 |
base = op; |
| 10940 |
else if (!index) |
| 10941 |
index = op; |
| 10942 |
else |
| 10943 |
return false; |
| 10944 |
break; |
| 10945 |
|
| 10946 |
case CONST: |
| 10947 |
case CONST_INT: |
| 10948 |
case SYMBOL_REF: |
| 10949 |
case LABEL_REF: |
| 10950 |
if (disp) |
| 10951 |
return false; |
| 10952 |
disp = op; |
| 10953 |
break; |
| 10954 |
|
| 10955 |
default: |
| 10956 |
return false; |
| 10957 |
} |
| 10958 |
} |
| 10959 |
} |
| 10960 |
else if (GET_CODE (addr) == MULT) |
| 10961 |
{ |
| 10962 |
index = XEXP (addr, 0); /* index*scale */ |
| 10963 |
scale_rtx = XEXP (addr, 1); |
| 10964 |
} |
| 10965 |
else if (GET_CODE (addr) == ASHIFT) |
| 10966 |
{ |
| 10967 |
/* We're called for lea too, which implements ashift on occasion. */ |
| 10968 |
index = XEXP (addr, 0); |
| 10969 |
tmp = XEXP (addr, 1); |
| 10970 |
if (!CONST_INT_P (tmp)) |
| 10971 |
return false; |
| 10972 |
scale = INTVAL (tmp); |
| 10973 |
if ((unsigned HOST_WIDE_INT) scale > 3) |
| 10974 |
return false; |
| 10975 |
scale = 1 << scale; |
| 10976 |
} |
| 10977 |
else |
| 10978 |
disp = addr; /* displacement */ |
| 10979 |
|
| 10980 |
if (index) |
| 10981 |
{ |
| 10982 |
if (REG_P (index)) |
| 10983 |
; |
| 10984 |
else if (SUBREG_P (index) |
| 10985 |
&& REG_P (SUBREG_REG (index))) |
| 10986 |
; |
| 10987 |
else |
| 10988 |
return false; |
| 10989 |
} |
| 10990 |
|
| 10991 |
/* Extract the integral value of scale. */ |
| 10992 |
if (scale_rtx) |
| 10993 |
{ |
| 10994 |
if (!CONST_INT_P (scale_rtx)) |
| 10995 |
return false; |
| 10996 |
scale = INTVAL (scale_rtx); |
| 10997 |
} |
| 10998 |
|
| 10999 |
base_reg = base && SUBREG_P (base) ? SUBREG_REG (base) : base; |
| 11000 |
index_reg = index && SUBREG_P (index) ? SUBREG_REG (index) : index; |
| 11001 |
|
| 11002 |
/* Avoid useless 0 displacement. */ |
| 11003 |
if (disp == const0_rtx && (base || index)) |
| 11004 |
disp = NULL_RTX; |
| 11005 |
|
| 11006 |
/* Allow arg pointer and stack pointer as index if there is not scaling. */ |
| 11007 |
if (base_reg && index_reg && scale == 1 |
| 11008 |
&& (REGNO (index_reg) == ARG_POINTER_REGNUM |
| 11009 |
|| REGNO (index_reg) == FRAME_POINTER_REGNUM |
| 11010 |
|| REGNO (index_reg) == SP_REG)) |
| 11011 |
{ |
| 11012 |
std::swap (base, index); |
| 11013 |
std::swap (base_reg, index_reg); |
| 11014 |
} |
| 11015 |
|
| 11016 |
/* Special case: %ebp cannot be encoded as a base without a displacement. |
| 11017 |
Similarly %r13. */ |
| 11018 |
if (!disp && base_reg |
| 11019 |
&& (REGNO (base_reg) == ARG_POINTER_REGNUM |
| 11020 |
|| REGNO (base_reg) == FRAME_POINTER_REGNUM |
| 11021 |
|| REGNO (base_reg) == BP_REG |
| 11022 |
|| REGNO (base_reg) == R13_REG)) |
| 11023 |
disp = const0_rtx; |
| 11024 |
|
| 11025 |
/* Special case: on K6, [%esi] makes the instruction vector decoded. |
| 11026 |
Avoid this by transforming to [%esi+0]. |
| 11027 |
Reload calls address legitimization without cfun defined, so we need |
| 11028 |
to test cfun for being non-NULL. */ |
| 11029 |
if (TARGET_CPU_P (K6) && cfun && optimize_function_for_speed_p (cfun) |
| 11030 |
&& base_reg && !index_reg && !disp |
| 11031 |
&& REGNO (base_reg) == SI_REG) |
| 11032 |
disp = const0_rtx; |
| 11033 |
|
| 11034 |
/* Special case: encode reg+reg instead of reg*2. */ |
| 11035 |
if (!base && index && scale == 2) |
| 11036 |
base = index, base_reg = index_reg, scale = 1; |
| 11037 |
|
| 11038 |
/* Special case: scaling cannot be encoded without base or displacement. */ |
| 11039 |
if (!base && !disp && index && scale != 1) |
| 11040 |
disp = const0_rtx; |
| 11041 |
|
| 11042 |
out->base = base; |
| 11043 |
out->index = index; |
| 11044 |
out->disp = disp; |
| 11045 |
out->scale = scale; |
| 11046 |
out->seg = seg; |
| 11047 |
|
| 11048 |
return true; |
| 11049 |
} |
| 11050 |
|
| 11051 |
/* Return cost of the memory address x. |
| 11052 |
For i386, it is better to use a complex address than let gcc copy |
| 11053 |
the address into a reg and make a new pseudo. But not if the address |
| 11054 |
requires to two regs - that would mean more pseudos with longer |
| 11055 |
lifetimes. */ |
| 11056 |
static int |
| 11057 |
ix86_address_cost (rtx x, machine_mode, addr_space_t, bool) |
| 11058 |
{ |
| 11059 |
struct ix86_address parts; |
| 11060 |
int cost = 1; |
| 11061 |
int ok = ix86_decompose_address (x, &parts); |
| 11062 |
|
| 11063 |
gcc_assert (ok); |
| 11064 |
|
| 11065 |
if (parts.base && SUBREG_P (parts.base)) |
| 11066 |
parts.base = SUBREG_REG (parts.base); |
| 11067 |
if (parts.index && SUBREG_P (parts.index)) |
| 11068 |
parts.index = SUBREG_REG (parts.index); |
| 11069 |
|
| 11070 |
/* Attempt to minimize number of registers in the address by increasing |
| 11071 |
address cost for each used register. We don't increase address cost |
| 11072 |
for "pic_offset_table_rtx". When a memopt with "pic_offset_table_rtx" |
| 11073 |
is not invariant itself it most likely means that base or index is not |
| 11074 |
invariant. Therefore only "pic_offset_table_rtx" could be hoisted out, |
| 11075 |
which is not profitable for x86. */ |
| 11076 |
if (parts.base |
| 11077 |
&& (!REG_P (parts.base) || REGNO (parts.base) >= FIRST_PSEUDO_REGISTER) |
| 11078 |
&& (current_pass->type == GIMPLE_PASS |
| 11079 |
|| !pic_offset_table_rtx |
| 11080 |
|| !REG_P (parts.base) |
| 11081 |
|| REGNO (pic_offset_table_rtx) != REGNO (parts.base))) |
| 11082 |
cost++; |
| 11083 |
|
| 11084 |
if (parts.index |
| 11085 |
&& (!REG_P (parts.index) || REGNO (parts.index) >= FIRST_PSEUDO_REGISTER) |
| 11086 |
&& (current_pass->type == GIMPLE_PASS |
| 11087 |
|| !pic_offset_table_rtx |
| 11088 |
|| !REG_P (parts.index) |
| 11089 |
|| REGNO (pic_offset_table_rtx) != REGNO (parts.index))) |
| 11090 |
cost++; |
| 11091 |
|
| 11092 |
/* AMD-K6 don't like addresses with ModR/M set to 00_xxx_100b, |
| 11093 |
since it's predecode logic can't detect the length of instructions |
| 11094 |
and it degenerates to vector decoded. Increase cost of such |
| 11095 |
addresses here. The penalty is minimally 2 cycles. It may be worthwhile |
| 11096 |
to split such addresses or even refuse such addresses at all. |
| 11097 |
|
| 11098 |
Following addressing modes are affected: |
| 11099 |
[base+scale*index] |
| 11100 |
[scale*index+disp] |
| 11101 |
[base+index] |
| 11102 |
|
| 11103 |
The first and last case may be avoidable by explicitly coding the zero in |
| 11104 |
memory address, but I don't have AMD-K6 machine handy to check this |
| 11105 |
theory. */ |
| 11106 |
|
| 11107 |
if (TARGET_CPU_P (K6) |
| 11108 |
&& ((!parts.disp && parts.base && parts.index && parts.scale != 1) |
| 11109 |
|| (parts.disp && !parts.base && parts.index && parts.scale != 1) |
| 11110 |
|| (!parts.disp && parts.base && parts.index && parts.scale == 1))) |
| 11111 |
cost += 10; |
| 11112 |
|
| 11113 |
return cost; |
| 11114 |
} |
| 11115 |
|
| 11116 |
/* Allow {LABEL | SYMBOL}_REF - SYMBOL_REF-FOR-PICBASE for Mach-O as |
| 11117 |
this is used for to form addresses to local data when -fPIC is in |
| 11118 |
use. */ |
| 11119 |
|
| 11120 |
static bool |
| 11121 |
darwin_local_data_pic (rtx disp) |
| 11122 |
{ |
| 11123 |
return (GET_CODE (disp) == UNSPEC |
| 11124 |
&& XINT (disp, 1) == UNSPEC_MACHOPIC_OFFSET); |
| 11125 |
} |
| 11126 |
|
| 11127 |
/* True if the function symbol operand X should be loaded from GOT. |
| 11128 |
If CALL_P is true, X is a call operand. |
| 11129 |
|
| 11130 |
NB: -mno-direct-extern-access doesn't force load from GOT for |
| 11131 |
call. |
| 11132 |
|
| 11133 |
NB: In 32-bit mode, only non-PIC is allowed in inline assembly |
| 11134 |
statements, since a PIC register could not be available at the |
| 11135 |
call site. */ |
| 11136 |
|
| 11137 |
bool |
| 11138 |
ix86_force_load_from_GOT_p (rtx x, bool call_p) |
| 11139 |
{ |
| 11140 |
return ((TARGET_64BIT || (!flag_pic && HAVE_AS_IX86_GOT32X)) |
| 11141 |
&& !TARGET_PECOFF && !TARGET_MACHO |
| 11142 |
&& (!flag_pic || this_is_asm_operands) |
| 11143 |
&& ix86_cmodel != CM_LARGE |
| 11144 |
&& ix86_cmodel != CM_LARGE_PIC |
| 11145 |
&& GET_CODE (x) == SYMBOL_REF |
| 11146 |
&& ((!call_p |
| 11147 |
&& (!ix86_direct_extern_access |
| 11148 |
|| (SYMBOL_REF_DECL (x) |
| 11149 |
&& lookup_attribute ("nodirect_extern_access", |
| 11150 |
DECL_ATTRIBUTES (SYMBOL_REF_DECL (x)))))) |
| 11151 |
|| (SYMBOL_REF_FUNCTION_P (x) |
| 11152 |
&& (!flag_plt |
| 11153 |
|| (SYMBOL_REF_DECL (x) |
| 11154 |
&& lookup_attribute ("noplt", |
| 11155 |
DECL_ATTRIBUTES (SYMBOL_REF_DECL (x))))))) |
| 11156 |
&& !SYMBOL_REF_LOCAL_P (x)); |
| 11157 |
} |
| 11158 |
|
| 11159 |
/* Determine if a given RTX is a valid constant. We already know this |
| 11160 |
satisfies CONSTANT_P. */ |
| 11161 |
|
| 11162 |
static bool |
| 11163 |
ix86_legitimate_constant_p (machine_mode mode, rtx x) |
| 11164 |
{ |
| 11165 |
switch (GET_CODE (x)) |
| 11166 |
{ |
| 11167 |
case CONST: |
| 11168 |
x = XEXP (x, 0); |
| 11169 |
|
| 11170 |
if (GET_CODE (x) == PLUS) |
| 11171 |
{ |
| 11172 |
if (!CONST_INT_P (XEXP (x, 1))) |
| 11173 |
return false; |
| 11174 |
x = XEXP (x, 0); |
| 11175 |
} |
| 11176 |
|
| 11177 |
if (TARGET_MACHO && darwin_local_data_pic (x)) |
| 11178 |
return true; |
| 11179 |
|
| 11180 |
/* Only some unspecs are valid as "constants". */ |
| 11181 |
if (GET_CODE (x) == UNSPEC) |
| 11182 |
switch (XINT (x, 1)) |
| 11183 |
{ |
| 11184 |
case UNSPEC_GOT: |
| 11185 |
case UNSPEC_GOTOFF: |
| 11186 |
case UNSPEC_PLTOFF: |
| 11187 |
return TARGET_64BIT; |
| 11188 |
case UNSPEC_TPOFF: |
| 11189 |
case UNSPEC_NTPOFF: |
| 11190 |
x = XVECEXP (x, 0, 0); |
| 11191 |
return (GET_CODE (x) == SYMBOL_REF |
| 11192 |
&& SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_EXEC); |
| 11193 |
case UNSPEC_DTPOFF: |
| 11194 |
x = XVECEXP (x, 0, 0); |
| 11195 |
return (GET_CODE (x) == SYMBOL_REF |
| 11196 |
&& SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC); |
| 11197 |
default: |
| 11198 |
return false; |
| 11199 |
} |
| 11200 |
|
| 11201 |
/* We must have drilled down to a symbol. */ |
| 11202 |
if (GET_CODE (x) == LABEL_REF) |
| 11203 |
return true; |
| 11204 |
if (GET_CODE (x) != SYMBOL_REF) |
| 11205 |
return false; |
| 11206 |
/* FALLTHRU */ |
| 11207 |
|
| 11208 |
case SYMBOL_REF: |
| 11209 |
/* TLS symbols are never valid. */ |
| 11210 |
if (SYMBOL_REF_TLS_MODEL (x)) |
| 11211 |
return false; |
| 11212 |
|
| 11213 |
/* DLLIMPORT symbols are never valid. */ |
| 11214 |
if (TARGET_DLLIMPORT_DECL_ATTRIBUTES |
| 11215 |
&& SYMBOL_REF_DLLIMPORT_P (x)) |
| 11216 |
return false; |
| 11217 |
|
| 11218 |
#if TARGET_MACHO |
| 11219 |
/* mdynamic-no-pic */ |
| 11220 |
if (MACHO_DYNAMIC_NO_PIC_P) |
| 11221 |
return machopic_symbol_defined_p (x); |
| 11222 |
#endif |
| 11223 |
|
| 11224 |
/* External function address should be loaded |
| 11225 |
via the GOT slot to avoid PLT. */ |
| 11226 |
if (ix86_force_load_from_GOT_p (x)) |
| 11227 |
return false; |
| 11228 |
|
| 11229 |
break; |
| 11230 |
|
| 11231 |
CASE_CONST_SCALAR_INT: |
| 11232 |
if (ix86_endbr_immediate_operand (x, VOIDmode)) |
| 11233 |
return false; |
| 11234 |
|
| 11235 |
switch (mode) |
| 11236 |
{ |
| 11237 |
case E_TImode: |
| 11238 |
if (TARGET_64BIT) |
| 11239 |
return true; |
| 11240 |
/* FALLTHRU */ |
| 11241 |
case E_OImode: |
| 11242 |
case E_XImode: |
| 11243 |
if (!standard_sse_constant_p (x, mode) |
| 11244 |
&& GET_MODE_SIZE (TARGET_AVX512F && TARGET_EVEX512 |
| 11245 |
? XImode |
| 11246 |
: (TARGET_AVX |
| 11247 |
? OImode |
| 11248 |
: (TARGET_SSE2 |
| 11249 |
? TImode : DImode))) < GET_MODE_SIZE (mode)) |
| 11250 |
return false; |
| 11251 |
default: |
| 11252 |
break; |
| 11253 |
} |
| 11254 |
break; |
| 11255 |
|
| 11256 |
case CONST_VECTOR: |
| 11257 |
if (!standard_sse_constant_p (x, mode)) |
| 11258 |
return false; |
| 11259 |
break; |
| 11260 |
|
| 11261 |
case CONST_DOUBLE: |
| 11262 |
if (mode == E_BFmode) |
| 11263 |
return false; |
| 11264 |
|
| 11265 |
default: |
| 11266 |
break; |
| 11267 |
} |
| 11268 |
|
| 11269 |
/* Otherwise we handle everything else in the move patterns. */ |
| 11270 |
return true; |
| 11271 |
} |
| 11272 |
|
| 11273 |
/* Determine if it's legal to put X into the constant pool. This |
| 11274 |
is not possible for the address of thread-local symbols, which |
| 11275 |
is checked above. */ |
| 11276 |
|
| 11277 |
static bool |
| 11278 |
ix86_cannot_force_const_mem (machine_mode mode, rtx x) |
| 11279 |
{ |
| 11280 |
/* We can put any immediate constant in memory. */ |
| 11281 |
switch (GET_CODE (x)) |
| 11282 |
{ |
| 11283 |
CASE_CONST_ANY: |
| 11284 |
return false; |
| 11285 |
|
| 11286 |
default: |
| 11287 |
break; |
| 11288 |
} |
| 11289 |
|
| 11290 |
return !ix86_legitimate_constant_p (mode, x); |
| 11291 |
} |
| 11292 |
|
| 11293 |
/* Return a unique alias set for the GOT. */ |
| 11294 |
|
| 11295 |
alias_set_type |
| 11296 |
ix86_GOT_alias_set (void) |
| 11297 |
{ |
| 11298 |
static alias_set_type set = -1; |
| 11299 |
if (set == -1) |
| 11300 |
set = new_alias_set (); |
| 11301 |
return set; |
| 11302 |
} |
| 11303 |
|
| 11304 |
/* Nonzero if the constant value X is a legitimate general operand |
| 11305 |
when generating PIC code. It is given that flag_pic is on and |
| 11306 |
that X satisfies CONSTANT_P. */ |
| 11307 |
|
| 11308 |
bool |
| 11309 |
legitimate_pic_operand_p (rtx x) |
| 11310 |
{ |
| 11311 |
rtx inner; |
| 11312 |
|
| 11313 |
switch (GET_CODE (x)) |
| 11314 |
{ |
| 11315 |
case CONST: |
| 11316 |
inner = XEXP (x, 0); |
| 11317 |
if (GET_CODE (inner) == PLUS |
| 11318 |
&& CONST_INT_P (XEXP (inner, 1))) |
| 11319 |
inner = XEXP (inner, 0); |
| 11320 |
|
| 11321 |
/* Only some unspecs are valid as "constants". */ |
| 11322 |
if (GET_CODE (inner) == UNSPEC) |
| 11323 |
switch (XINT (inner, 1)) |
| 11324 |
{ |
| 11325 |
case UNSPEC_GOT: |
| 11326 |
case UNSPEC_GOTOFF: |
| 11327 |
case UNSPEC_PLTOFF: |
| 11328 |
return TARGET_64BIT; |
| 11329 |
case UNSPEC_TPOFF: |
| 11330 |
x = XVECEXP (inner, 0, 0); |
| 11331 |
return (GET_CODE (x) == SYMBOL_REF |
| 11332 |
&& SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_EXEC); |
| 11333 |
case UNSPEC_MACHOPIC_OFFSET: |
| 11334 |
return legitimate_pic_address_disp_p (x); |
| 11335 |
default: |
| 11336 |
return false; |
| 11337 |
} |
| 11338 |
/* FALLTHRU */ |
| 11339 |
|
| 11340 |
case SYMBOL_REF: |
| 11341 |
case LABEL_REF: |
| 11342 |
return legitimate_pic_address_disp_p (x); |
| 11343 |
|
| 11344 |
default: |
| 11345 |
return true; |
| 11346 |
} |
| 11347 |
} |
| 11348 |
|
| 11349 |
/* Determine if a given CONST RTX is a valid memory displacement |
| 11350 |
in PIC mode. */ |
| 11351 |
|
| 11352 |
bool |
| 11353 |
legitimate_pic_address_disp_p (rtx disp) |
| 11354 |
{ |
| 11355 |
bool saw_plus; |
| 11356 |
|
| 11357 |
/* In 64bit mode we can allow direct addresses of symbols and labels |
| 11358 |
when they are not dynamic symbols. */ |
| 11359 |
if (TARGET_64BIT) |
| 11360 |
{ |
| 11361 |
rtx op0 = disp, op1; |
| 11362 |
|
| 11363 |
switch (GET_CODE (disp)) |
| 11364 |
{ |
| 11365 |
case LABEL_REF: |
| 11366 |
return true; |
| 11367 |
|
| 11368 |
case CONST: |
| 11369 |
if (GET_CODE (XEXP (disp, 0)) != PLUS) |
| 11370 |
break; |
| 11371 |
op0 = XEXP (XEXP (disp, 0), 0); |
| 11372 |
op1 = XEXP (XEXP (disp, 0), 1); |
| 11373 |
if (!CONST_INT_P (op1)) |
| 11374 |
break; |
| 11375 |
if (GET_CODE (op0) == UNSPEC |
| 11376 |
&& (XINT (op0, 1) == UNSPEC_DTPOFF |
| 11377 |
|| XINT (op0, 1) == UNSPEC_NTPOFF) |
| 11378 |
&& trunc_int_for_mode (INTVAL (op1), SImode) == INTVAL (op1)) |
| 11379 |
return true; |
| 11380 |
if (INTVAL (op1) >= 16*1024*1024 |
| 11381 |
|| INTVAL (op1) < -16*1024*1024) |
| 11382 |
break; |
| 11383 |
if (GET_CODE (op0) == LABEL_REF) |
| 11384 |
return true; |
| 11385 |
if (GET_CODE (op0) == CONST |
| 11386 |
&& GET_CODE (XEXP (op0, 0)) == UNSPEC |
| 11387 |
&& XINT (XEXP (op0, 0), 1) == UNSPEC_PCREL) |
| 11388 |
return true; |
| 11389 |
if (GET_CODE (op0) == UNSPEC |
| 11390 |
&& XINT (op0, 1) == UNSPEC_PCREL) |
| 11391 |
return true; |
| 11392 |
if (GET_CODE (op0) != SYMBOL_REF) |
| 11393 |
break; |
| 11394 |
/* FALLTHRU */ |
| 11395 |
|
| 11396 |
case SYMBOL_REF: |
| 11397 |
/* TLS references should always be enclosed in UNSPEC. |
| 11398 |
The dllimported symbol needs always to be resolved. */ |
| 11399 |
if (SYMBOL_REF_TLS_MODEL (op0) |
| 11400 |
|| (TARGET_DLLIMPORT_DECL_ATTRIBUTES && SYMBOL_REF_DLLIMPORT_P (op0))) |
| 11401 |
return false; |
| 11402 |
|
| 11403 |
if (TARGET_PECOFF) |
| 11404 |
{ |
| 11405 |
#if TARGET_PECOFF |
| 11406 |
if (is_imported_p (op0)) |
| 11407 |
return true; |
| 11408 |
#endif |
| 11409 |
|
| 11410 |
if (SYMBOL_REF_FAR_ADDR_P (op0) || !SYMBOL_REF_LOCAL_P (op0)) |
| 11411 |
break; |
| 11412 |
|
| 11413 |
/* Non-external-weak function symbols need to be resolved only |
| 11414 |
for the large model. Non-external symbols don't need to be |
| 11415 |
resolved for large and medium models. For the small model, |
| 11416 |
we don't need to resolve anything here. */ |
| 11417 |
if ((ix86_cmodel != CM_LARGE_PIC |
| 11418 |
&& SYMBOL_REF_FUNCTION_P (op0) |
| 11419 |
&& !(SYMBOL_REF_EXTERNAL_P (op0) && SYMBOL_REF_WEAK (op0))) |
| 11420 |
|| !SYMBOL_REF_EXTERNAL_P (op0) |
| 11421 |
|| ix86_cmodel == CM_SMALL_PIC) |
| 11422 |
return true; |
| 11423 |
} |
| 11424 |
else if (!SYMBOL_REF_FAR_ADDR_P (op0) |
| 11425 |
&& (SYMBOL_REF_LOCAL_P (op0) |
| 11426 |
|| ((ix86_direct_extern_access |
| 11427 |
&& !(SYMBOL_REF_DECL (op0) |
| 11428 |
&& lookup_attribute ("nodirect_extern_access", |
| 11429 |
DECL_ATTRIBUTES (SYMBOL_REF_DECL (op0))))) |
| 11430 |
&& HAVE_LD_PIE_COPYRELOC |
| 11431 |
&& flag_pie |
| 11432 |
&& !SYMBOL_REF_WEAK (op0) |
| 11433 |
&& !SYMBOL_REF_FUNCTION_P (op0))) |
| 11434 |
&& ix86_cmodel != CM_LARGE_PIC) |
| 11435 |
return true; |
| 11436 |
break; |
| 11437 |
|
| 11438 |
default: |
| 11439 |
break; |
| 11440 |
} |
| 11441 |
} |
| 11442 |
if (GET_CODE (disp) != CONST) |
| 11443 |
return false; |
| 11444 |
disp = XEXP (disp, 0); |
| 11445 |
|
| 11446 |
if (TARGET_64BIT) |
| 11447 |
{ |
| 11448 |
/* We are unsafe to allow PLUS expressions. This limit allowed distance |
| 11449 |
of GOT tables. We should not need these anyway. */ |
| 11450 |
if (GET_CODE (disp) != UNSPEC |
| 11451 |
|| (XINT (disp, 1) != UNSPEC_GOTPCREL |
| 11452 |
&& XINT (disp, 1) != UNSPEC_GOTOFF |
| 11453 |
&& XINT (disp, 1) != UNSPEC_PCREL |
| 11454 |
&& XINT (disp, 1) != UNSPEC_PLTOFF)) |
| 11455 |
return false; |
| 11456 |
|
| 11457 |
if (GET_CODE (XVECEXP (disp, 0, 0)) != SYMBOL_REF |
| 11458 |
&& GET_CODE (XVECEXP (disp, 0, 0)) != LABEL_REF) |
| 11459 |
return false; |
| 11460 |
return true; |
| 11461 |
} |
| 11462 |
|
| 11463 |
saw_plus = false; |
| 11464 |
if (GET_CODE (disp) == PLUS) |
| 11465 |
{ |
| 11466 |
if (!CONST_INT_P (XEXP (disp, 1))) |
| 11467 |
return false; |
| 11468 |
disp = XEXP (disp, 0); |
| 11469 |
saw_plus = true; |
| 11470 |
} |
| 11471 |
|
| 11472 |
if (TARGET_MACHO && darwin_local_data_pic (disp)) |
| 11473 |
return true; |
| 11474 |
|
| 11475 |
if (GET_CODE (disp) != UNSPEC) |
| 11476 |
return false; |
| 11477 |
|
| 11478 |
switch (XINT (disp, 1)) |
| 11479 |
{ |
| 11480 |
case UNSPEC_GOT: |
| 11481 |
if (saw_plus) |
| 11482 |
return false; |
| 11483 |
/* We need to check for both symbols and labels because VxWorks loads |
| 11484 |
text labels with @GOT rather than @GOTOFF. See gotoff_operand for |
| 11485 |
details. */ |
| 11486 |
return (GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF |
| 11487 |
|| GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF); |
| 11488 |
case UNSPEC_GOTOFF: |
| 11489 |
/* Refuse GOTOFF in 64bit mode since it is always 64bit when used. |
| 11490 |
While ABI specify also 32bit relocation but we don't produce it in |
| 11491 |
small PIC model at all. */ |
| 11492 |
if ((GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF |
| 11493 |
|| GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF) |
| 11494 |
&& !TARGET_64BIT) |
| 11495 |
return !TARGET_PECOFF && gotoff_operand (XVECEXP (disp, 0, 0), Pmode); |
| 11496 |
return false; |
| 11497 |
case UNSPEC_GOTTPOFF: |
| 11498 |
case UNSPEC_GOTNTPOFF: |
| 11499 |
case UNSPEC_INDNTPOFF: |
| 11500 |
if (saw_plus) |
| 11501 |
return false; |
| 11502 |
disp = XVECEXP (disp, 0, 0); |
| 11503 |
return (GET_CODE (disp) == SYMBOL_REF |
| 11504 |
&& SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_INITIAL_EXEC); |
| 11505 |
case UNSPEC_NTPOFF: |
| 11506 |
disp = XVECEXP (disp, 0, 0); |
| 11507 |
return (GET_CODE (disp) == SYMBOL_REF |
| 11508 |
&& SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_LOCAL_EXEC); |
| 11509 |
case UNSPEC_DTPOFF: |
| 11510 |
disp = XVECEXP (disp, 0, 0); |
| 11511 |
return (GET_CODE (disp) == SYMBOL_REF |
| 11512 |
&& SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_LOCAL_DYNAMIC); |
| 11513 |
} |
| 11514 |
|
| 11515 |
return false; |
| 11516 |
} |
| 11517 |
|
| 11518 |
/* Determine if op is suitable RTX for an address register. |
| 11519 |
Return naked register if a register or a register subreg is |
| 11520 |
found, otherwise return NULL_RTX. */ |
| 11521 |
|
| 11522 |
static rtx |
| 11523 |
ix86_validate_address_register (rtx op) |
| 11524 |
{ |
| 11525 |
machine_mode mode = GET_MODE (op); |
| 11526 |
|
| 11527 |
/* Only SImode or DImode registers can form the address. */ |
| 11528 |
if (mode != SImode && mode != DImode) |
| 11529 |
return NULL_RTX; |
| 11530 |
|
| 11531 |
if (REG_P (op)) |
| 11532 |
return op; |
| 11533 |
else if (SUBREG_P (op)) |
| 11534 |
{ |
| 11535 |
rtx reg = SUBREG_REG (op); |
| 11536 |
|
| 11537 |
if (!REG_P (reg)) |
| 11538 |
return NULL_RTX; |
| 11539 |
|
| 11540 |
mode = GET_MODE (reg); |
| 11541 |
|
| 11542 |
/* Don't allow SUBREGs that span more than a word. It can |
| 11543 |
lead to spill failures when the register is one word out |
| 11544 |
of a two word structure. */ |
| 11545 |
if (GET_MODE_SIZE (mode) > UNITS_PER_WORD) |
| 11546 |
return NULL_RTX; |
| 11547 |
|
| 11548 |
/* Allow only SUBREGs of non-eliminable hard registers. */ |
| 11549 |
if (register_no_elim_operand (reg, mode)) |
| 11550 |
return reg; |
| 11551 |
} |
| 11552 |
|
| 11553 |
/* Op is not a register. */ |
| 11554 |
return NULL_RTX; |
| 11555 |
} |
| 11556 |
|
| 11557 |
/* Determine which memory address register set insn can use. */ |
| 11558 |
|
| 11559 |
static enum attr_addr |
| 11560 |
ix86_memory_address_reg_class (rtx_insn* insn) |
| 11561 |
{ |
| 11562 |
/* LRA can do some initialization with NULL insn, |
| 11563 |
return maximum register class in this case. */ |
| 11564 |
enum attr_addr addr_rclass = ADDR_GPR32; |
| 11565 |
|
| 11566 |
if (!insn) |
| 11567 |
return addr_rclass; |
| 11568 |
|
| 11569 |
if (asm_noperands (PATTERN (insn)) >= 0 |
| 11570 |
|| GET_CODE (PATTERN (insn)) == ASM_INPUT) |
| 11571 |
return ix86_apx_inline_asm_use_gpr32 ? ADDR_GPR32 : ADDR_GPR16; |
| 11572 |
|
| 11573 |
/* Return maximum register class for unrecognized instructions. */ |
| 11574 |
if (INSN_CODE (insn) < 0) |
| 11575 |
return addr_rclass; |
| 11576 |
|
| 11577 |
/* Try to recognize the insn before calling get_attr_addr. |
| 11578 |
Save current recog_data and current alternative. */ |
| 11579 |
struct recog_data_d saved_recog_data = recog_data; |
| 11580 |
int saved_alternative = which_alternative; |
| 11581 |
|
| 11582 |
/* Update recog_data for processing of alternatives. */ |
| 11583 |
extract_insn_cached (insn); |
| 11584 |
|
| 11585 |
/* If current alternative is not set, loop throught enabled |
| 11586 |
alternatives and get the most limited register class. */ |
| 11587 |
if (saved_alternative == -1) |
| 11588 |
{ |
| 11589 |
alternative_mask enabled = get_enabled_alternatives (insn); |
| 11590 |
|
| 11591 |
for (int i = 0; i < recog_data.n_alternatives; i++) |
| 11592 |
{ |
| 11593 |
if (!TEST_BIT (enabled, i)) |
| 11594 |
continue; |
| 11595 |
|
| 11596 |
which_alternative = i; |
| 11597 |
addr_rclass = MIN (addr_rclass, get_attr_addr (insn)); |
| 11598 |
} |
| 11599 |
} |
| 11600 |
else |
| 11601 |
{ |
| 11602 |
which_alternative = saved_alternative; |
| 11603 |
addr_rclass = get_attr_addr (insn); |
| 11604 |
} |
| 11605 |
|
| 11606 |
recog_data = saved_recog_data; |
| 11607 |
which_alternative = saved_alternative; |
| 11608 |
|
| 11609 |
return addr_rclass; |
| 11610 |
} |
| 11611 |
|
| 11612 |
/* Return memory address register class insn can use. */ |
| 11613 |
|
| 11614 |
enum reg_class |
| 11615 |
ix86_insn_base_reg_class (rtx_insn* insn) |
| 11616 |
{ |
| 11617 |
switch (ix86_memory_address_reg_class (insn)) |
| 11618 |
{ |
| 11619 |
case ADDR_GPR8: |
| 11620 |
return LEGACY_GENERAL_REGS; |
| 11621 |
case ADDR_GPR16: |
| 11622 |
return GENERAL_GPR16; |
| 11623 |
case ADDR_GPR32: |
| 11624 |
break; |
| 11625 |
default: |
| 11626 |
gcc_unreachable (); |
| 11627 |
} |
| 11628 |
|
| 11629 |
return BASE_REG_CLASS; |
| 11630 |
} |
| 11631 |
|
| 11632 |
bool |
| 11633 |
ix86_regno_ok_for_insn_base_p (int regno, rtx_insn* insn) |
| 11634 |
{ |
| 11635 |
switch (ix86_memory_address_reg_class (insn)) |
| 11636 |
{ |
| 11637 |
case ADDR_GPR8: |
| 11638 |
return LEGACY_INT_REGNO_P (regno); |
| 11639 |
case ADDR_GPR16: |
| 11640 |
return GENERAL_GPR16_REGNO_P (regno); |
| 11641 |
case ADDR_GPR32: |
| 11642 |
break; |
| 11643 |
default: |
| 11644 |
gcc_unreachable (); |
| 11645 |
} |
| 11646 |
|
| 11647 |
return GENERAL_REGNO_P (regno); |
| 11648 |
} |
| 11649 |
|
| 11650 |
enum reg_class |
| 11651 |
ix86_insn_index_reg_class (rtx_insn* insn) |
| 11652 |
{ |
| 11653 |
switch (ix86_memory_address_reg_class (insn)) |
| 11654 |
{ |
| 11655 |
case ADDR_GPR8: |
| 11656 |
return LEGACY_INDEX_REGS; |
| 11657 |
case ADDR_GPR16: |
| 11658 |
return INDEX_GPR16; |
| 11659 |
case ADDR_GPR32: |
| 11660 |
break; |
| 11661 |
default: |
| 11662 |
gcc_unreachable (); |
| 11663 |
} |
| 11664 |
|
| 11665 |
return INDEX_REG_CLASS; |
| 11666 |
} |
| 11667 |
|
| 11668 |
/* Recognizes RTL expressions that are valid memory addresses for an |
| 11669 |
instruction. The MODE argument is the machine mode for the MEM |
| 11670 |
expression that wants to use this address. |
| 11671 |
|
| 11672 |
It only recognizes address in canonical form. LEGITIMIZE_ADDRESS should |
| 11673 |
convert common non-canonical forms to canonical form so that they will |
| 11674 |
be recognized. */ |
| 11675 |
|
| 11676 |
static bool |
| 11677 |
ix86_legitimate_address_p (machine_mode, rtx addr, bool strict, |
| 11678 |
code_helper = ERROR_MARK) |
| 11679 |
{ |
| 11680 |
struct ix86_address parts; |
| 11681 |
rtx base, index, disp; |
| 11682 |
HOST_WIDE_INT scale; |
| 11683 |
addr_space_t seg; |
| 11684 |
|
| 11685 |
if (ix86_decompose_address (addr, &parts) == 0) |
| 11686 |
/* Decomposition failed. */ |
| 11687 |
return false; |
| 11688 |
|
| 11689 |
base = parts.base; |
| 11690 |
index = parts.index; |
| 11691 |
disp = parts.disp; |
| 11692 |
scale = parts.scale; |
| 11693 |
seg = parts.seg; |
| 11694 |
|
| 11695 |
/* Validate base register. */ |
| 11696 |
if (base) |
| 11697 |
{ |
| 11698 |
rtx reg = ix86_validate_address_register (base); |
| 11699 |
|
| 11700 |
if (reg == NULL_RTX) |
| 11701 |
return false; |
| 11702 |
|
| 11703 |
unsigned int regno = REGNO (reg); |
| 11704 |
if ((strict && !REGNO_OK_FOR_BASE_P (regno)) |
| 11705 |
|| (!strict && !REGNO_OK_FOR_BASE_NONSTRICT_P (regno))) |
| 11706 |
/* Base is not valid. */ |
| 11707 |
return false; |
| 11708 |
} |
| 11709 |
|
| 11710 |
/* Validate index register. */ |
| 11711 |
if (index) |
| 11712 |
{ |
| 11713 |
rtx reg = ix86_validate_address_register (index); |
| 11714 |
|
| 11715 |
if (reg == NULL_RTX) |
| 11716 |
return false; |
| 11717 |
|
| 11718 |
unsigned int regno = REGNO (reg); |
| 11719 |
if ((strict && !REGNO_OK_FOR_INDEX_P (regno)) |
| 11720 |
|| (!strict && !REGNO_OK_FOR_INDEX_NONSTRICT_P (regno))) |
| 11721 |
/* Index is not valid. */ |
| 11722 |
return false; |
| 11723 |
} |
| 11724 |
|
| 11725 |
/* Index and base should have the same mode. */ |
| 11726 |
if (base && index |
| 11727 |
&& GET_MODE (base) != GET_MODE (index)) |
| 11728 |
return false; |
| 11729 |
|
| 11730 |
/* Address override works only on the (%reg) part of %fs:(%reg). */ |
| 11731 |
if (seg != ADDR_SPACE_GENERIC |
| 11732 |
&& ((base && GET_MODE (base) != word_mode) |
| 11733 |
|| (index && GET_MODE (index) != word_mode))) |
| 11734 |
return false; |
| 11735 |
|
| 11736 |
/* Validate scale factor. */ |
| 11737 |
if (scale != 1) |
| 11738 |
{ |
| 11739 |
if (!index) |
| 11740 |
/* Scale without index. */ |
| 11741 |
return false; |
| 11742 |
|
| 11743 |
if (scale != 2 && scale != 4 && scale != 8) |
| 11744 |
/* Scale is not a valid multiplier. */ |
| 11745 |
return false; |
| 11746 |
} |
| 11747 |
|
| 11748 |
/* Validate displacement. */ |
| 11749 |
if (disp) |
| 11750 |
{ |
| 11751 |
if (ix86_endbr_immediate_operand (disp, VOIDmode)) |
| 11752 |
return false; |
| 11753 |
|
| 11754 |
if (GET_CODE (disp) == CONST |
| 11755 |
&& GET_CODE (XEXP (disp, 0)) == UNSPEC |
| 11756 |
&& XINT (XEXP (disp, 0), 1) != UNSPEC_MACHOPIC_OFFSET) |
| 11757 |
switch (XINT (XEXP (disp, 0), 1)) |
| 11758 |
{ |
| 11759 |
/* Refuse GOTOFF and GOT in 64bit mode since it is always 64bit |
| 11760 |
when used. While ABI specify also 32bit relocations, we |
| 11761 |
don't produce them at all and use IP relative instead. |
| 11762 |
Allow GOT in 32bit mode for both PIC and non-PIC if symbol |
| 11763 |
should be loaded via GOT. */ |
| 11764 |
case UNSPEC_GOT: |
| 11765 |
if (!TARGET_64BIT |
| 11766 |
&& ix86_force_load_from_GOT_p (XVECEXP (XEXP (disp, 0), 0, 0))) |
| 11767 |
goto is_legitimate_pic; |
| 11768 |
/* FALLTHRU */ |
| 11769 |
case UNSPEC_GOTOFF: |
| 11770 |
gcc_assert (flag_pic); |
| 11771 |
if (!TARGET_64BIT) |
| 11772 |
goto is_legitimate_pic; |
| 11773 |
|
| 11774 |
/* 64bit address unspec. */ |
| 11775 |
return false; |
| 11776 |
|
| 11777 |
case UNSPEC_GOTPCREL: |
| 11778 |
if (ix86_force_load_from_GOT_p (XVECEXP (XEXP (disp, 0), 0, 0))) |
| 11779 |
goto is_legitimate_pic; |
| 11780 |
/* FALLTHRU */ |
| 11781 |
case UNSPEC_PCREL: |
| 11782 |
gcc_assert (flag_pic); |
| 11783 |
goto is_legitimate_pic; |
| 11784 |
|
| 11785 |
case UNSPEC_GOTTPOFF: |
| 11786 |
case UNSPEC_GOTNTPOFF: |
| 11787 |
case UNSPEC_INDNTPOFF: |
| 11788 |
case UNSPEC_NTPOFF: |
| 11789 |
case UNSPEC_DTPOFF: |
| 11790 |
break; |
| 11791 |
|
| 11792 |
default: |
| 11793 |
/* Invalid address unspec. */ |
| 11794 |
return false; |
| 11795 |
} |
| 11796 |
|
| 11797 |
else if (SYMBOLIC_CONST (disp) |
| 11798 |
&& (flag_pic |
| 11799 |
#if TARGET_MACHO |
| 11800 |
|| (MACHOPIC_INDIRECT |
| 11801 |
&& !machopic_operand_p (disp)) |
| 11802 |
#endif |
| 11803 |
)) |
| 11804 |
{ |
| 11805 |
|
| 11806 |
is_legitimate_pic: |
| 11807 |
if (TARGET_64BIT && (index || base)) |
| 11808 |
{ |
| 11809 |
/* foo@dtpoff(%rX) is ok. */ |
| 11810 |
if (GET_CODE (disp) != CONST |
| 11811 |
|| GET_CODE (XEXP (disp, 0)) != PLUS |
| 11812 |
|| GET_CODE (XEXP (XEXP (disp, 0), 0)) != UNSPEC |
| 11813 |
|| !CONST_INT_P (XEXP (XEXP (disp, 0), 1)) |
| 11814 |
|| (XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_DTPOFF |
| 11815 |
&& XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_NTPOFF)) |
| 11816 |
/* Non-constant pic memory reference. */ |
| 11817 |
return false; |
| 11818 |
} |
| 11819 |
else if ((!TARGET_MACHO || flag_pic) |
| 11820 |
&& ! legitimate_pic_address_disp_p (disp)) |
| 11821 |
/* Displacement is an invalid pic construct. */ |
| 11822 |
return false; |
| 11823 |
#if TARGET_MACHO |
| 11824 |
else if (MACHO_DYNAMIC_NO_PIC_P |
| 11825 |
&& !ix86_legitimate_constant_p (Pmode, disp)) |
| 11826 |
/* displacment must be referenced via non_lazy_pointer */ |
| 11827 |
return false; |
| 11828 |
#endif |
| 11829 |
|
| 11830 |
/* This code used to verify that a symbolic pic displacement |
| 11831 |
includes the pic_offset_table_rtx register. |
| 11832 |
|
| 11833 |
While this is good idea, unfortunately these constructs may |
| 11834 |
be created by "adds using lea" optimization for incorrect |
| 11835 |
code like: |
| 11836 |
|
| 11837 |
int a; |
| 11838 |
int foo(int i) |
| 11839 |
{ |
| 11840 |
return *(&a+i); |
| 11841 |
} |
| 11842 |
|
| 11843 |
This code is nonsensical, but results in addressing |
| 11844 |
GOT table with pic_offset_table_rtx base. We can't |
| 11845 |
just refuse it easily, since it gets matched by |
| 11846 |
"addsi3" pattern, that later gets split to lea in the |
| 11847 |
case output register differs from input. While this |
| 11848 |
can be handled by separate addsi pattern for this case |
| 11849 |
that never results in lea, this seems to be easier and |
| 11850 |
correct fix for crash to disable this test. */ |
| 11851 |
} |
| 11852 |
else if (GET_CODE (disp) != LABEL_REF |
| 11853 |
&& !CONST_INT_P (disp) |
| 11854 |
&& (GET_CODE (disp) != CONST |
| 11855 |
|| !ix86_legitimate_constant_p (Pmode, disp)) |
| 11856 |
&& (GET_CODE (disp) != SYMBOL_REF |
| 11857 |
|| !ix86_legitimate_constant_p (Pmode, disp))) |
| 11858 |
/* Displacement is not constant. */ |
| 11859 |
return false; |
| 11860 |
else if (TARGET_64BIT |
| 11861 |
&& !x86_64_immediate_operand (disp, VOIDmode)) |
| 11862 |
/* Displacement is out of range. */ |
| 11863 |
return false; |
| 11864 |
/* In x32 mode, constant addresses are sign extended to 64bit, so |
| 11865 |
we have to prevent addresses from 0x80000000 to 0xffffffff. */ |
| 11866 |
else if (TARGET_X32 && !(index || base) |
| 11867 |
&& CONST_INT_P (disp) |
| 11868 |
&& val_signbit_known_set_p (SImode, INTVAL (disp))) |
| 11869 |
return false; |
| 11870 |
} |
| 11871 |
|
| 11872 |
/* Everything looks valid. */ |
| 11873 |
return true; |
| 11874 |
} |
| 11875 |
|
| 11876 |
/* Determine if a given RTX is a valid constant address. */ |
| 11877 |
|
| 11878 |
bool |
| 11879 |
constant_address_p (rtx x) |
| 11880 |
{ |
| 11881 |
return CONSTANT_P (x) && ix86_legitimate_address_p (Pmode, x, 1); |
| 11882 |
} |
| 11883 |
|
| 11884 |
|
| 11885 |
/* Return a legitimate reference for ORIG (an address) using the |
| 11886 |
register REG. If REG is 0, a new pseudo is generated. |
| 11887 |
|
| 11888 |
There are two types of references that must be handled: |
| 11889 |
|
| 11890 |
1. Global data references must load the address from the GOT, via |
| 11891 |
the PIC reg. An insn is emitted to do this load, and the reg is |
| 11892 |
returned. |
| 11893 |
|
| 11894 |
2. Static data references, constant pool addresses, and code labels |
| 11895 |
compute the address as an offset from the GOT, whose base is in |
| 11896 |
the PIC reg. Static data objects have SYMBOL_FLAG_LOCAL set to |
| 11897 |
differentiate them from global data objects. The returned |
| 11898 |
address is the PIC reg + an unspec constant. |
| 11899 |
|
| 11900 |
TARGET_LEGITIMATE_ADDRESS_P rejects symbolic references unless the PIC |
| 11901 |
reg also appears in the address. */ |
| 11902 |
|
| 11903 |
rtx |
| 11904 |
legitimize_pic_address (rtx orig, rtx reg) |
| 11905 |
{ |
| 11906 |
rtx addr = orig; |
| 11907 |
rtx new_rtx = orig; |
| 11908 |
|
| 11909 |
#if TARGET_MACHO |
| 11910 |
if (TARGET_MACHO && !TARGET_64BIT) |
| 11911 |
{ |
| 11912 |
if (reg == 0) |
| 11913 |
reg = gen_reg_rtx (Pmode); |
| 11914 |
/* Use the generic Mach-O PIC machinery. */ |
| 11915 |
return machopic_legitimize_pic_address (orig, GET_MODE (orig), reg); |
| 11916 |
} |
| 11917 |
#endif |
| 11918 |
|
| 11919 |
if (TARGET_64BIT && TARGET_DLLIMPORT_DECL_ATTRIBUTES) |
| 11920 |
{ |
| 11921 |
#if TARGET_PECOFF |
| 11922 |
rtx tmp = legitimize_pe_coff_symbol (addr, true); |
| 11923 |
if (tmp) |
| 11924 |
return tmp; |
| 11925 |
#endif |
| 11926 |
} |
| 11927 |
|
| 11928 |
if (TARGET_64BIT && legitimate_pic_address_disp_p (addr)) |
| 11929 |
new_rtx = addr; |
| 11930 |
else if ((!TARGET_64BIT |
| 11931 |
|| /* TARGET_64BIT && */ ix86_cmodel != CM_SMALL_PIC) |
| 11932 |
&& !TARGET_PECOFF |
| 11933 |
&& gotoff_operand (addr, Pmode)) |
| 11934 |
{ |
| 11935 |
/* This symbol may be referenced via a displacement |
| 11936 |
from the PIC base address (@GOTOFF). */ |
| 11937 |
if (GET_CODE (addr) == CONST) |
| 11938 |
addr = XEXP (addr, 0); |
| 11939 |
|
| 11940 |
if (GET_CODE (addr) == PLUS) |
| 11941 |
{ |
| 11942 |
new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, XEXP (addr, 0)), |
| 11943 |
UNSPEC_GOTOFF); |
| 11944 |
new_rtx = gen_rtx_PLUS (Pmode, new_rtx, XEXP (addr, 1)); |
| 11945 |
} |
| 11946 |
else |
| 11947 |
new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTOFF); |
| 11948 |
|
| 11949 |
new_rtx = gen_rtx_CONST (Pmode, new_rtx); |
| 11950 |
|
| 11951 |
if (TARGET_64BIT) |
| 11952 |
new_rtx = copy_to_suggested_reg (new_rtx, reg, Pmode); |
| 11953 |
|
| 11954 |
if (reg != 0) |
| 11955 |
{ |
| 11956 |
gcc_assert (REG_P (reg)); |
| 11957 |
new_rtx = expand_simple_binop (Pmode, PLUS, pic_offset_table_rtx, |
| 11958 |
new_rtx, reg, 1, OPTAB_DIRECT); |
| 11959 |
} |
| 11960 |
else |
| 11961 |
new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx); |
| 11962 |
} |
| 11963 |
else if ((GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (addr) == 0) |
| 11964 |
/* We can't always use @GOTOFF for text labels |
| 11965 |
on VxWorks, see gotoff_operand. */ |
| 11966 |
|| (TARGET_VXWORKS_RTP && GET_CODE (addr) == LABEL_REF)) |
| 11967 |
{ |
| 11968 |
#if TARGET_PECOFF |
| 11969 |
rtx tmp = legitimize_pe_coff_symbol (addr, true); |
| 11970 |
if (tmp) |
| 11971 |
return tmp; |
| 11972 |
#endif |
| 11973 |
|
| 11974 |
/* For x64 PE-COFF there is no GOT table, |
| 11975 |
so we use address directly. */ |
| 11976 |
if (TARGET_64BIT && TARGET_PECOFF) |
| 11977 |
{ |
| 11978 |
new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_PCREL); |
| 11979 |
new_rtx = gen_rtx_CONST (Pmode, new_rtx); |
| 11980 |
} |
| 11981 |
else if (TARGET_64BIT && ix86_cmodel != CM_LARGE_PIC) |
| 11982 |
{ |
| 11983 |
new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), |
| 11984 |
UNSPEC_GOTPCREL); |
| 11985 |
new_rtx = gen_rtx_CONST (Pmode, new_rtx); |
| 11986 |
new_rtx = gen_const_mem (Pmode, new_rtx); |
| 11987 |
set_mem_alias_set (new_rtx, GOT_ALIAS_SET); |
| 11988 |
} |
| 11989 |
else |
| 11990 |
{ |
| 11991 |
/* This symbol must be referenced via a load |
| 11992 |
from the Global Offset Table (@GOT). */ |
| 11993 |
new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOT); |
| 11994 |
new_rtx = gen_rtx_CONST (Pmode, new_rtx); |
| 11995 |
|
| 11996 |
if (TARGET_64BIT) |
| 11997 |
new_rtx = copy_to_suggested_reg (new_rtx, reg, Pmode); |
| 11998 |
|
| 11999 |
if (reg != 0) |
| 12000 |
{ |
| 12001 |
gcc_assert (REG_P (reg)); |
| 12002 |
new_rtx = expand_simple_binop (Pmode, PLUS, pic_offset_table_rtx, |
| 12003 |
new_rtx, reg, 1, OPTAB_DIRECT); |
| 12004 |
} |
| 12005 |
else |
| 12006 |
new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx); |
| 12007 |
|
| 12008 |
new_rtx = gen_const_mem (Pmode, new_rtx); |
| 12009 |
set_mem_alias_set (new_rtx, GOT_ALIAS_SET); |
| 12010 |
} |
| 12011 |
|
| 12012 |
new_rtx = copy_to_suggested_reg (new_rtx, reg, Pmode); |
| 12013 |
} |
| 12014 |
else |
| 12015 |
{ |
| 12016 |
if (CONST_INT_P (addr) |
| 12017 |
&& !x86_64_immediate_operand (addr, VOIDmode)) |
| 12018 |
new_rtx = copy_to_suggested_reg (addr, reg, Pmode); |
| 12019 |
else if (GET_CODE (addr) == CONST) |
| 12020 |
{ |
| 12021 |
addr = XEXP (addr, 0); |
| 12022 |
|
| 12023 |
/* We must match stuff we generate before. Assume the only |
| 12024 |
unspecs that can get here are ours. Not that we could do |
| 12025 |
anything with them anyway.... */ |
| 12026 |
if (GET_CODE (addr) == UNSPEC |
| 12027 |
|| (GET_CODE (addr) == PLUS |
| 12028 |
&& GET_CODE (XEXP (addr, 0)) == UNSPEC)) |
| 12029 |
return orig; |
| 12030 |
gcc_assert (GET_CODE (addr) == PLUS); |
| 12031 |
} |
| 12032 |
|
| 12033 |
if (GET_CODE (addr) == PLUS) |
| 12034 |
{ |
| 12035 |
rtx op0 = XEXP (addr, 0), op1 = XEXP (addr, 1); |
| 12036 |
|
| 12037 |
/* Check first to see if this is a constant |
| 12038 |
offset from a @GOTOFF symbol reference. */ |
| 12039 |
if (!TARGET_PECOFF |
| 12040 |
&& gotoff_operand (op0, Pmode) |
| 12041 |
&& CONST_INT_P (op1)) |
| 12042 |
{ |
| 12043 |
if (!TARGET_64BIT) |
| 12044 |
{ |
| 12045 |
new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op0), |
| 12046 |
UNSPEC_GOTOFF); |
| 12047 |
new_rtx = gen_rtx_PLUS (Pmode, new_rtx, op1); |
| 12048 |
new_rtx = gen_rtx_CONST (Pmode, new_rtx); |
| 12049 |
|
| 12050 |
if (reg != 0) |
| 12051 |
{ |
| 12052 |
gcc_assert (REG_P (reg)); |
| 12053 |
new_rtx = expand_simple_binop (Pmode, PLUS, |
| 12054 |
pic_offset_table_rtx, |
| 12055 |
new_rtx, reg, 1, |
| 12056 |
OPTAB_DIRECT); |
| 12057 |
} |
| 12058 |
else |
| 12059 |
new_rtx |
| 12060 |
= gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx); |
| 12061 |
} |
| 12062 |
else |
| 12063 |
{ |
| 12064 |
if (INTVAL (op1) < -16*1024*1024 |
| 12065 |
|| INTVAL (op1) >= 16*1024*1024) |
| 12066 |
{ |
| 12067 |
if (!x86_64_immediate_operand (op1, Pmode)) |
| 12068 |
op1 = force_reg (Pmode, op1); |
| 12069 |
|
| 12070 |
new_rtx |
| 12071 |
= gen_rtx_PLUS (Pmode, force_reg (Pmode, op0), op1); |
| 12072 |
} |
| 12073 |
} |
| 12074 |
} |
| 12075 |
else |
| 12076 |
{ |
| 12077 |
rtx base = legitimize_pic_address (op0, reg); |
| 12078 |
machine_mode mode = GET_MODE (base); |
| 12079 |
new_rtx |
| 12080 |
= legitimize_pic_address (op1, base == reg ? NULL_RTX : reg); |
| 12081 |
|
| 12082 |
if (CONST_INT_P (new_rtx)) |
| 12083 |
{ |
| 12084 |
if (INTVAL (new_rtx) < -16*1024*1024 |
| 12085 |
|| INTVAL (new_rtx) >= 16*1024*1024) |
| 12086 |
{ |
| 12087 |
if (!x86_64_immediate_operand (new_rtx, mode)) |
| 12088 |
new_rtx = force_reg (mode, new_rtx); |
| 12089 |
|
| 12090 |
new_rtx |
| 12091 |
= gen_rtx_PLUS (mode, force_reg (mode, base), new_rtx); |
| 12092 |
} |
| 12093 |
else |
| 12094 |
new_rtx = plus_constant (mode, base, INTVAL (new_rtx)); |
| 12095 |
} |
| 12096 |
else |
| 12097 |
{ |
| 12098 |
/* For %rip addressing, we have to use |
| 12099 |
just disp32, not base nor index. */ |
| 12100 |
if (TARGET_64BIT |
| 12101 |
&& (GET_CODE (base) == SYMBOL_REF |
| 12102 |
|| GET_CODE (base) == LABEL_REF)) |
| 12103 |
base = force_reg (mode, base); |
| 12104 |
if (GET_CODE (new_rtx) == PLUS |
| 12105 |
&& CONSTANT_P (XEXP (new_rtx, 1))) |
| 12106 |
{ |
| 12107 |
base = gen_rtx_PLUS (mode, base, XEXP (new_rtx, 0)); |
| 12108 |
new_rtx = XEXP (new_rtx, 1); |
| 12109 |
} |
| 12110 |
new_rtx = gen_rtx_PLUS (mode, base, new_rtx); |
| 12111 |
} |
| 12112 |
} |
| 12113 |
} |
| 12114 |
} |
| 12115 |
return new_rtx; |
| 12116 |
} |
| 12117 |
|
| 12118 |
/* Load the thread pointer. If TO_REG is true, force it into a register. */ |
| 12119 |
|
| 12120 |
static rtx |
| 12121 |
get_thread_pointer (machine_mode tp_mode, bool to_reg) |
| 12122 |
{ |
| 12123 |
rtx tp = gen_rtx_UNSPEC (ptr_mode, gen_rtvec (1, const0_rtx), UNSPEC_TP); |
| 12124 |
|
| 12125 |
if (GET_MODE (tp) != tp_mode) |
| 12126 |
{ |
| 12127 |
gcc_assert (GET_MODE (tp) == SImode); |
| 12128 |
gcc_assert (tp_mode == DImode); |
| 12129 |
|
| 12130 |
tp = gen_rtx_ZERO_EXTEND (tp_mode, tp); |
| 12131 |
} |
| 12132 |
|
| 12133 |
if (to_reg) |
| 12134 |
tp = copy_to_mode_reg (tp_mode, tp); |
| 12135 |
|
| 12136 |
return tp; |
| 12137 |
} |
| 12138 |
|
| 12139 |
/* Construct the SYMBOL_REF for the tls_get_addr function. */ |
| 12140 |
|
| 12141 |
static GTY(()) rtx ix86_tls_symbol; |
| 12142 |
|
| 12143 |
static rtx |
| 12144 |
ix86_tls_get_addr (void) |
| 12145 |
{ |
| 12146 |
if (cfun->machine->call_saved_registers |
| 12147 |
== TYPE_NO_CALLER_SAVED_REGISTERS) |
| 12148 |
{ |
| 12149 |
/* __tls_get_addr doesn't preserve vector registers. When a |
| 12150 |
function with no_caller_saved_registers attribute calls |
| 12151 |
__tls_get_addr, YMM and ZMM registers will be clobbered. |
| 12152 |
Issue an error and suggest -mtls-dialect=gnu2 in this case. */ |
| 12153 |
if (cfun->machine->func_type == TYPE_NORMAL) |
| 12154 |
error (G_("%<-mtls-dialect=gnu2%> must be used with a function" |
| 12155 |
" with the %<no_caller_saved_registers%> attribute")); |
| 12156 |
else |
| 12157 |
error (cfun->machine->func_type == TYPE_EXCEPTION |
| 12158 |
? G_("%<-mtls-dialect=gnu2%> must be used with an" |
| 12159 |
" exception service routine") |
| 12160 |
: G_("%<-mtls-dialect=gnu2%> must be used with an" |
| 12161 |
" interrupt service routine")); |
| 12162 |
/* Don't issue the same error twice. */ |
| 12163 |
cfun->machine->func_type = TYPE_NORMAL; |
| 12164 |
cfun->machine->call_saved_registers |
| 12165 |
= TYPE_DEFAULT_CALL_SAVED_REGISTERS; |
| 12166 |
} |
| 12167 |
|
| 12168 |
if (!ix86_tls_symbol) |
| 12169 |
{ |
| 12170 |
const char *sym |
| 12171 |
= ((TARGET_ANY_GNU_TLS && !TARGET_64BIT) |
| 12172 |
? "___tls_get_addr" : "__tls_get_addr"); |
| 12173 |
|
| 12174 |
ix86_tls_symbol = gen_rtx_SYMBOL_REF (Pmode, sym); |
| 12175 |
} |
| 12176 |
|
| 12177 |
if (ix86_cmodel == CM_LARGE_PIC && !TARGET_PECOFF) |
| 12178 |
{ |
| 12179 |
rtx unspec = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, ix86_tls_symbol), |
| 12180 |
UNSPEC_PLTOFF); |
| 12181 |
return gen_rtx_PLUS (Pmode, pic_offset_table_rtx, |
| 12182 |
gen_rtx_CONST (Pmode, unspec)); |
| 12183 |
} |
| 12184 |
|
| 12185 |
return ix86_tls_symbol; |
| 12186 |
} |
| 12187 |
|
| 12188 |
/* Construct the SYMBOL_REF for the _TLS_MODULE_BASE_ symbol. */ |
| 12189 |
|
| 12190 |
static GTY(()) rtx ix86_tls_module_base_symbol; |
| 12191 |
|
| 12192 |
rtx |
| 12193 |
ix86_tls_module_base (void) |
| 12194 |
{ |
| 12195 |
if (!ix86_tls_module_base_symbol) |
| 12196 |
{ |
| 12197 |
ix86_tls_module_base_symbol |
| 12198 |
= gen_rtx_SYMBOL_REF (ptr_mode, "_TLS_MODULE_BASE_"); |
| 12199 |
|
| 12200 |
SYMBOL_REF_FLAGS (ix86_tls_module_base_symbol) |
| 12201 |
|= TLS_MODEL_GLOBAL_DYNAMIC << SYMBOL_FLAG_TLS_SHIFT; |
| 12202 |
} |
| 12203 |
|
| 12204 |
return ix86_tls_module_base_symbol; |
| 12205 |
} |
| 12206 |
|
| 12207 |
/* A subroutine of ix86_legitimize_address and ix86_expand_move. FOR_MOV is |
| 12208 |
false if we expect this to be used for a memory address and true if |
| 12209 |
we expect to load the address into a register. */ |
| 12210 |
|
| 12211 |
rtx |
| 12212 |
legitimize_tls_address (rtx x, enum tls_model model, bool for_mov) |
| 12213 |
{ |
| 12214 |
rtx dest, base, off; |
| 12215 |
rtx pic = NULL_RTX, tp = NULL_RTX; |
| 12216 |
machine_mode tp_mode = Pmode; |
| 12217 |
int type; |
| 12218 |
|
| 12219 |
/* Fall back to global dynamic model if tool chain cannot support local |
| 12220 |
dynamic. */ |
| 12221 |
if (TARGET_SUN_TLS && !TARGET_64BIT |
| 12222 |
&& !HAVE_AS_IX86_TLSLDMPLT && !HAVE_AS_IX86_TLSLDM |
| 12223 |
&& model == TLS_MODEL_LOCAL_DYNAMIC) |
| 12224 |
model = TLS_MODEL_GLOBAL_DYNAMIC; |
| 12225 |
|
| 12226 |
switch (model) |
| 12227 |
{ |
| 12228 |
case TLS_MODEL_GLOBAL_DYNAMIC: |
| 12229 |
if (!TARGET_64BIT) |
| 12230 |
{ |
| 12231 |
if (flag_pic && !TARGET_PECOFF) |
| 12232 |
pic = pic_offset_table_rtx; |
| 12233 |
else |
| 12234 |
{ |
| 12235 |
pic = gen_reg_rtx (Pmode); |
| 12236 |
emit_insn (gen_set_got (pic)); |
| 12237 |
} |
| 12238 |
} |
| 12239 |
|
| 12240 |
if (TARGET_GNU2_TLS) |
| 12241 |
{ |
| 12242 |
dest = gen_reg_rtx (ptr_mode); |
| 12243 |
if (TARGET_64BIT) |
| 12244 |
emit_insn (gen_tls_dynamic_gnu2_64 (ptr_mode, dest, x)); |
| 12245 |
else |
| 12246 |
emit_insn (gen_tls_dynamic_gnu2_32 (dest, x, pic)); |
| 12247 |
|
| 12248 |
tp = get_thread_pointer (ptr_mode, true); |
| 12249 |
dest = gen_rtx_PLUS (ptr_mode, tp, dest); |
| 12250 |
if (GET_MODE (dest) != Pmode) |
| 12251 |
dest = gen_rtx_ZERO_EXTEND (Pmode, dest); |
| 12252 |
dest = force_reg (Pmode, dest); |
| 12253 |
|
| 12254 |
if (GET_MODE (x) != Pmode) |
| 12255 |
x = gen_rtx_ZERO_EXTEND (Pmode, x); |
| 12256 |
|
| 12257 |
set_unique_reg_note (get_last_insn (), REG_EQUAL, x); |
| 12258 |
} |
| 12259 |
else |
| 12260 |
{ |
| 12261 |
rtx caddr = ix86_tls_get_addr (); |
| 12262 |
|
| 12263 |
dest = gen_reg_rtx (Pmode); |
| 12264 |
if (TARGET_64BIT) |
| 12265 |
{ |
| 12266 |
rtx rax = gen_rtx_REG (Pmode, AX_REG); |
| 12267 |
rtx rdi = gen_rtx_REG (Pmode, DI_REG); |
| 12268 |
rtx_insn *insns; |
| 12269 |
|
| 12270 |
start_sequence (); |
| 12271 |
emit_call_insn |
| 12272 |
(gen_tls_global_dynamic_64 (Pmode, rax, x, caddr, rdi)); |
| 12273 |
insns = get_insns (); |
| 12274 |
end_sequence (); |
| 12275 |
|
| 12276 |
if (GET_MODE (x) != Pmode) |
| 12277 |
x = gen_rtx_ZERO_EXTEND (Pmode, x); |
| 12278 |
|
| 12279 |
RTL_CONST_CALL_P (insns) = 1; |
| 12280 |
emit_libcall_block (insns, dest, rax, x); |
| 12281 |
} |
| 12282 |
else |
| 12283 |
emit_insn (gen_tls_global_dynamic_32 (dest, x, pic, caddr)); |
| 12284 |
} |
| 12285 |
break; |
| 12286 |
|
| 12287 |
case TLS_MODEL_LOCAL_DYNAMIC: |
| 12288 |
if (!TARGET_64BIT) |
| 12289 |
{ |
| 12290 |
if (flag_pic) |
| 12291 |
pic = pic_offset_table_rtx; |
| 12292 |
else |
| 12293 |
{ |
| 12294 |
pic = gen_reg_rtx (Pmode); |
| 12295 |
emit_insn (gen_set_got (pic)); |
| 12296 |
} |
| 12297 |
} |
| 12298 |
|
| 12299 |
if (TARGET_GNU2_TLS) |
| 12300 |
{ |
| 12301 |
rtx tmp = ix86_tls_module_base (); |
| 12302 |
|
| 12303 |
base = gen_reg_rtx (ptr_mode); |
| 12304 |
if (TARGET_64BIT) |
| 12305 |
emit_insn (gen_tls_dynamic_gnu2_64 (ptr_mode, base, tmp)); |
| 12306 |
else |
| 12307 |
emit_insn (gen_tls_dynamic_gnu2_32 (base, tmp, pic)); |
| 12308 |
|
| 12309 |
tp = get_thread_pointer (ptr_mode, true); |
| 12310 |
if (GET_MODE (base) != Pmode) |
| 12311 |
base = gen_rtx_ZERO_EXTEND (Pmode, base); |
| 12312 |
base = force_reg (Pmode, base); |
| 12313 |
} |
| 12314 |
else |
| 12315 |
{ |
| 12316 |
rtx caddr = ix86_tls_get_addr (); |
| 12317 |
|
| 12318 |
base = gen_reg_rtx (Pmode); |
| 12319 |
if (TARGET_64BIT) |
| 12320 |
{ |
| 12321 |
rtx rax = gen_rtx_REG (Pmode, AX_REG); |
| 12322 |
rtx rdi = gen_rtx_REG (Pmode, DI_REG); |
| 12323 |
rtx_insn *insns; |
| 12324 |
rtx eqv; |
| 12325 |
|
| 12326 |
start_sequence (); |
| 12327 |
emit_call_insn |
| 12328 |
(gen_tls_local_dynamic_base_64 (Pmode, rax, caddr, rdi)); |
| 12329 |
insns = get_insns (); |
| 12330 |
end_sequence (); |
| 12331 |
|
| 12332 |
/* Attach a unique REG_EQUAL, to allow the RTL optimizers to |
| 12333 |
share the LD_BASE result with other LD model accesses. */ |
| 12334 |
eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx), |
| 12335 |
UNSPEC_TLS_LD_BASE); |
| 12336 |
|
| 12337 |
RTL_CONST_CALL_P (insns) = 1; |
| 12338 |
emit_libcall_block (insns, base, rax, eqv); |
| 12339 |
} |
| 12340 |
else |
| 12341 |
emit_insn (gen_tls_local_dynamic_base_32 (base, pic, caddr)); |
| 12342 |
} |
| 12343 |
|
| 12344 |
off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), UNSPEC_DTPOFF); |
| 12345 |
off = gen_rtx_CONST (Pmode, off); |
| 12346 |
|
| 12347 |
dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, base, off)); |
| 12348 |
|
| 12349 |
if (TARGET_GNU2_TLS) |
| 12350 |
{ |
| 12351 |
if (GET_MODE (tp) != Pmode) |
| 12352 |
{ |
| 12353 |
dest = lowpart_subreg (ptr_mode, dest, Pmode); |
| 12354 |
dest = gen_rtx_PLUS (ptr_mode, tp, dest); |
| 12355 |
dest = gen_rtx_ZERO_EXTEND (Pmode, dest); |
| 12356 |
} |
| 12357 |
else |
| 12358 |
dest = gen_rtx_PLUS (Pmode, tp, dest); |
| 12359 |
dest = force_reg (Pmode, dest); |
| 12360 |
|
| 12361 |
if (GET_MODE (x) != Pmode) |
| 12362 |
x = gen_rtx_ZERO_EXTEND (Pmode, x); |
| 12363 |
|
| 12364 |
set_unique_reg_note (get_last_insn (), REG_EQUAL, x); |
| 12365 |
} |
| 12366 |
break; |
| 12367 |
|
| 12368 |
case TLS_MODEL_INITIAL_EXEC: |
| 12369 |
if (TARGET_64BIT) |
| 12370 |
{ |
| 12371 |
/* Generate DImode references to avoid %fs:(%reg32) |
| 12372 |
problems and linker IE->LE relaxation bug. */ |
| 12373 |
tp_mode = DImode; |
| 12374 |
pic = NULL; |
| 12375 |
type = UNSPEC_GOTNTPOFF; |
| 12376 |
} |
| 12377 |
else if (flag_pic) |
| 12378 |
{ |
| 12379 |
pic = pic_offset_table_rtx; |
| 12380 |
type = TARGET_ANY_GNU_TLS ? UNSPEC_GOTNTPOFF : UNSPEC_GOTTPOFF; |
| 12381 |
} |
| 12382 |
else if (!TARGET_ANY_GNU_TLS) |
| 12383 |
{ |
| 12384 |
pic = gen_reg_rtx (Pmode); |
| 12385 |
emit_insn (gen_set_got (pic)); |
| 12386 |
type = UNSPEC_GOTTPOFF; |
| 12387 |
} |
| 12388 |
else |
| 12389 |
{ |
| 12390 |
pic = NULL; |
| 12391 |
type = UNSPEC_INDNTPOFF; |
| 12392 |
} |
| 12393 |
|
| 12394 |
off = gen_rtx_UNSPEC (tp_mode, gen_rtvec (1, x), type); |
| 12395 |
off = gen_rtx_CONST (tp_mode, off); |
| 12396 |
if (pic) |
| 12397 |
off = gen_rtx_PLUS (tp_mode, pic, off); |
| 12398 |
off = gen_const_mem (tp_mode, off); |
| 12399 |
set_mem_alias_set (off, GOT_ALIAS_SET); |
| 12400 |
|
| 12401 |
if (TARGET_64BIT || TARGET_ANY_GNU_TLS) |
| 12402 |
{ |
| 12403 |
base = get_thread_pointer (tp_mode, |
| 12404 |
for_mov || !TARGET_TLS_DIRECT_SEG_REFS); |
| 12405 |
off = force_reg (tp_mode, off); |
| 12406 |
dest = gen_rtx_PLUS (tp_mode, base, off); |
| 12407 |
if (tp_mode != Pmode) |
| 12408 |
dest = convert_to_mode (Pmode, dest, 1); |
| 12409 |
} |
| 12410 |
else |
| 12411 |
{ |
| 12412 |
base = get_thread_pointer (Pmode, true); |
| 12413 |
dest = gen_reg_rtx (Pmode); |
| 12414 |
emit_insn (gen_sub3_insn (dest, base, off)); |
| 12415 |
} |
| 12416 |
break; |
| 12417 |
|
| 12418 |
case TLS_MODEL_LOCAL_EXEC: |
| 12419 |
off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), |
| 12420 |
(TARGET_64BIT || TARGET_ANY_GNU_TLS) |
| 12421 |
? UNSPEC_NTPOFF : UNSPEC_TPOFF); |
| 12422 |
off = gen_rtx_CONST (Pmode, off); |
| 12423 |
|
| 12424 |
if (TARGET_64BIT || TARGET_ANY_GNU_TLS) |
| 12425 |
{ |
| 12426 |
base = get_thread_pointer (Pmode, |
| 12427 |
for_mov || !TARGET_TLS_DIRECT_SEG_REFS); |
| 12428 |
return gen_rtx_PLUS (Pmode, base, off); |
| 12429 |
} |
| 12430 |
else |
| 12431 |
{ |
| 12432 |
base = get_thread_pointer (Pmode, true); |
| 12433 |
dest = gen_reg_rtx (Pmode); |
| 12434 |
emit_insn (gen_sub3_insn (dest, base, off)); |
| 12435 |
} |
| 12436 |
break; |
| 12437 |
|
| 12438 |
default: |
| 12439 |
gcc_unreachable (); |
| 12440 |
} |
| 12441 |
|
| 12442 |
return dest; |
| 12443 |
} |
| 12444 |
|
| 12445 |
/* Return true if the TLS address requires insn using integer registers. |
| 12446 |
It's used to prevent KMOV/VMOV in TLS code sequences which require integer |
| 12447 |
MOV instructions, refer to PR103275. */ |
| 12448 |
bool |
| 12449 |
ix86_gpr_tls_address_pattern_p (rtx mem) |
| 12450 |
{ |
| 12451 |
gcc_assert (MEM_P (mem)); |
| 12452 |
|
| 12453 |
rtx addr = XEXP (mem, 0); |
| 12454 |
subrtx_var_iterator::array_type array; |
| 12455 |
FOR_EACH_SUBRTX_VAR (iter, array, addr, ALL) |
| 12456 |
{ |
| 12457 |
rtx op = *iter; |
| 12458 |
if (GET_CODE (op) == UNSPEC) |
| 12459 |
switch (XINT (op, 1)) |
| 12460 |
{ |
| 12461 |
case UNSPEC_GOTNTPOFF: |
| 12462 |
return true; |
| 12463 |
case UNSPEC_TPOFF: |
| 12464 |
if (!TARGET_64BIT) |
| 12465 |
return true; |
| 12466 |
break; |
| 12467 |
default: |
| 12468 |
break; |
| 12469 |
} |
| 12470 |
} |
| 12471 |
|
| 12472 |
return false; |
| 12473 |
} |
| 12474 |
|
| 12475 |
/* Return true if OP refers to a TLS address. */ |
| 12476 |
bool |
| 12477 |
ix86_tls_address_pattern_p (rtx op) |
| 12478 |
{ |
| 12479 |
subrtx_var_iterator::array_type array; |
| 12480 |
FOR_EACH_SUBRTX_VAR (iter, array, op, ALL) |
| 12481 |
{ |
| 12482 |
rtx op = *iter; |
| 12483 |
if (MEM_P (op)) |
| 12484 |
{ |
| 12485 |
rtx *x = &XEXP (op, 0); |
| 12486 |
while (GET_CODE (*x) == PLUS) |
| 12487 |
{ |
| 12488 |
int i; |
| 12489 |
for (i = 0; i < 2; i++) |
| 12490 |
{ |
| 12491 |
rtx u = XEXP (*x, i); |
| 12492 |
if (GET_CODE (u) == ZERO_EXTEND) |
| 12493 |
u = XEXP (u, 0); |
| 12494 |
if (GET_CODE (u) == UNSPEC |
| 12495 |
&& XINT (u, 1) == UNSPEC_TP) |
| 12496 |
return true; |
| 12497 |
} |
| 12498 |
x = &XEXP (*x, 0); |
| 12499 |
} |
| 12500 |
|
| 12501 |
iter.skip_subrtxes (); |
| 12502 |
} |
| 12503 |
} |
| 12504 |
|
| 12505 |
return false; |
| 12506 |
} |
| 12507 |
|
| 12508 |
/* Rewrite *LOC so that it refers to a default TLS address space. */ |
| 12509 |
static void |
| 12510 |
ix86_rewrite_tls_address_1 (rtx *loc) |
| 12511 |
{ |
| 12512 |
subrtx_ptr_iterator::array_type array; |
| 12513 |
FOR_EACH_SUBRTX_PTR (iter, array, loc, ALL) |
| 12514 |
{ |
| 12515 |
rtx *loc = *iter; |
| 12516 |
if (MEM_P (*loc)) |
| 12517 |
{ |
| 12518 |
rtx addr = XEXP (*loc, 0); |
| 12519 |
rtx *x = &addr; |
| 12520 |
while (GET_CODE (*x) == PLUS) |
| 12521 |
{ |
| 12522 |
int i; |
| 12523 |
for (i = 0; i < 2; i++) |
| 12524 |
{ |
| 12525 |
rtx u = XEXP (*x, i); |
| 12526 |
if (GET_CODE (u) == ZERO_EXTEND) |
| 12527 |
u = XEXP (u, 0); |
| 12528 |
if (GET_CODE (u) == UNSPEC |
| 12529 |
&& XINT (u, 1) == UNSPEC_TP) |
| 12530 |
{ |
| 12531 |
/* NB: Since address override only applies to the |
| 12532 |
(reg32) part in fs:(reg32), return if address |
| 12533 |
override is used. */ |
| 12534 |
if (Pmode != word_mode |
| 12535 |
&& REG_P (XEXP (*x, 1 - i))) |
| 12536 |
return; |
| 12537 |
|
| 12538 |
addr_space_t as = DEFAULT_TLS_SEG_REG; |
| 12539 |
|
| 12540 |
*x = XEXP (*x, 1 - i); |
| 12541 |
|
| 12542 |
*loc = replace_equiv_address_nv (*loc, addr, true); |
| 12543 |
set_mem_addr_space (*loc, as); |
| 12544 |
return; |
| 12545 |
} |
| 12546 |
} |
| 12547 |
x = &XEXP (*x, 0); |
| 12548 |
} |
| 12549 |
|
| 12550 |
iter.skip_subrtxes (); |
| 12551 |
} |
| 12552 |
} |
| 12553 |
} |
| 12554 |
|
| 12555 |
/* Rewrite instruction pattern involvning TLS address |
| 12556 |
so that it refers to a default TLS address space. */ |
| 12557 |
rtx |
| 12558 |
ix86_rewrite_tls_address (rtx pattern) |
| 12559 |
{ |
| 12560 |
pattern = copy_insn (pattern); |
| 12561 |
ix86_rewrite_tls_address_1 (&pattern); |
| 12562 |
return pattern; |
| 12563 |
} |
| 12564 |
|
| 12565 |
/* Try machine-dependent ways of modifying an illegitimate address |
| 12566 |
to be legitimate. If we find one, return the new, valid address. |
| 12567 |
This macro is used in only one place: `memory_address' in explow.cc. |
| 12568 |
|
| 12569 |
OLDX is the address as it was before break_out_memory_refs was called. |
| 12570 |
In some cases it is useful to look at this to decide what needs to be done. |
| 12571 |
|
| 12572 |
It is always safe for this macro to do nothing. It exists to recognize |
| 12573 |
opportunities to optimize the output. |
| 12574 |
|
| 12575 |
For the 80386, we handle X+REG by loading X into a register R and |
| 12576 |
using R+REG. R will go in a general reg and indexing will be used. |
| 12577 |
However, if REG is a broken-out memory address or multiplication, |
| 12578 |
nothing needs to be done because REG can certainly go in a general reg. |
| 12579 |
|
| 12580 |
When -fpic is used, special handling is needed for symbolic references. |
| 12581 |
See comments by legitimize_pic_address in i386.cc for details. */ |
| 12582 |
|
| 12583 |
static rtx |
| 12584 |
ix86_legitimize_address (rtx x, rtx, machine_mode mode) |
| 12585 |
{ |
| 12586 |
bool changed = false; |
| 12587 |
unsigned log; |
| 12588 |
|
| 12589 |
log = GET_CODE (x) == SYMBOL_REF ? SYMBOL_REF_TLS_MODEL (x) : 0; |
| 12590 |
if (log) |
| 12591 |
return legitimize_tls_address (x, (enum tls_model) log, false); |
| 12592 |
if (GET_CODE (x) == CONST |
| 12593 |
&& GET_CODE (XEXP (x, 0)) == PLUS |
| 12594 |
&& GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF |
| 12595 |
&& (log = SYMBOL_REF_TLS_MODEL (XEXP (XEXP (x, 0), 0)))) |
| 12596 |
{ |
| 12597 |
rtx t = legitimize_tls_address (XEXP (XEXP (x, 0), 0), |
| 12598 |
(enum tls_model) log, false); |
| 12599 |
return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (x, 0), 1)); |
| 12600 |
} |
| 12601 |
|
| 12602 |
if (TARGET_DLLIMPORT_DECL_ATTRIBUTES) |
| 12603 |
{ |
| 12604 |
#if TARGET_PECOFF |
| 12605 |
rtx tmp = legitimize_pe_coff_symbol (x, true); |
| 12606 |
if (tmp) |
| 12607 |
return tmp; |
| 12608 |
#endif |
| 12609 |
} |
| 12610 |
|
| 12611 |
if (flag_pic && SYMBOLIC_CONST (x)) |
| 12612 |
return legitimize_pic_address (x, 0); |
| 12613 |
|
| 12614 |
#if TARGET_MACHO |
| 12615 |
if (MACHO_DYNAMIC_NO_PIC_P && SYMBOLIC_CONST (x)) |
| 12616 |
return machopic_indirect_data_reference (x, 0); |
| 12617 |
#endif |
| 12618 |
|
| 12619 |
/* Canonicalize shifts by 0, 1, 2, 3 into multiply */ |
| 12620 |
if (GET_CODE (x) == ASHIFT |
| 12621 |
&& CONST_INT_P (XEXP (x, 1)) |
| 12622 |
&& (unsigned HOST_WIDE_INT) INTVAL (XEXP (x, 1)) < 4) |
| 12623 |
{ |
| 12624 |
changed = true; |
| 12625 |
log = INTVAL (XEXP (x, 1)); |
| 12626 |
x = gen_rtx_MULT (Pmode, force_reg (Pmode, XEXP (x, 0)), |
| 12627 |
GEN_INT (1 << log)); |
| 12628 |
} |
| 12629 |
|
| 12630 |
if (GET_CODE (x) == PLUS) |
| 12631 |
{ |
| 12632 |
/* Canonicalize shifts by 0, 1, 2, 3 into multiply. */ |
| 12633 |
|
| 12634 |
if (GET_CODE (XEXP (x, 0)) == ASHIFT |
| 12635 |
&& CONST_INT_P (XEXP (XEXP (x, 0), 1)) |
| 12636 |
&& (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 0), 1)) < 4) |
| 12637 |
{ |
| 12638 |
changed = true; |
| 12639 |
log = INTVAL (XEXP (XEXP (x, 0), 1)); |
| 12640 |
XEXP (x, 0) = gen_rtx_MULT (Pmode, |
| 12641 |
force_reg (Pmode, XEXP (XEXP (x, 0), 0)), |
| 12642 |
GEN_INT (1 << log)); |
| 12643 |
} |
| 12644 |
|
| 12645 |
if (GET_CODE (XEXP (x, 1)) == ASHIFT |
| 12646 |
&& CONST_INT_P (XEXP (XEXP (x, 1), 1)) |
| 12647 |
&& (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 1), 1)) < 4) |
| 12648 |
{ |
| 12649 |
changed = true; |
| 12650 |
log = INTVAL (XEXP (XEXP (x, 1), 1)); |
| 12651 |
XEXP (x, 1) = gen_rtx_MULT (Pmode, |
| 12652 |
force_reg (Pmode, XEXP (XEXP (x, 1), 0)), |
| 12653 |
GEN_INT (1 << log)); |
| 12654 |
} |
| 12655 |
|
| 12656 |
/* Put multiply first if it isn't already. */ |
| 12657 |
if (GET_CODE (XEXP (x, 1)) == MULT) |
| 12658 |
{ |
| 12659 |
std::swap (XEXP (x, 0), XEXP (x, 1)); |
| 12660 |
changed = true; |
| 12661 |
} |
| 12662 |
|
| 12663 |
/* Canonicalize (plus (mult (reg) (const)) (plus (reg) (const))) |
| 12664 |
into (plus (plus (mult (reg) (const)) (reg)) (const)). This can be |
| 12665 |
created by virtual register instantiation, register elimination, and |
| 12666 |
similar optimizations. */ |
| 12667 |
if (GET_CODE (XEXP (x, 0)) == MULT && GET_CODE (XEXP (x, 1)) == PLUS) |
| 12668 |
{ |
| 12669 |
changed = true; |
| 12670 |
x = gen_rtx_PLUS (Pmode, |
| 12671 |
gen_rtx_PLUS (Pmode, XEXP (x, 0), |
| 12672 |
XEXP (XEXP (x, 1), 0)), |
| 12673 |
XEXP (XEXP (x, 1), 1)); |
| 12674 |
} |
| 12675 |
|
| 12676 |
/* Canonicalize |
| 12677 |
(plus (plus (mult (reg) (const)) (plus (reg) (const))) const) |
| 12678 |
into (plus (plus (mult (reg) (const)) (reg)) (const)). */ |
| 12679 |
else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS |
| 12680 |
&& GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT |
| 12681 |
&& GET_CODE (XEXP (XEXP (x, 0), 1)) == PLUS |
| 12682 |
&& CONSTANT_P (XEXP (x, 1))) |
| 12683 |
{ |
| 12684 |
rtx constant; |
| 12685 |
rtx other = NULL_RTX; |
| 12686 |
|
| 12687 |
if (CONST_INT_P (XEXP (x, 1))) |
| 12688 |
{ |
| 12689 |
constant = XEXP (x, 1); |
| 12690 |
other = XEXP (XEXP (XEXP (x, 0), 1), 1); |
| 12691 |
} |
| 12692 |
else if (CONST_INT_P (XEXP (XEXP (XEXP (x, 0), 1), 1))) |
| 12693 |
{ |
| 12694 |
constant = XEXP (XEXP (XEXP (x, 0), 1), 1); |
| 12695 |
other = XEXP (x, 1); |
| 12696 |
} |
| 12697 |
else |
| 12698 |
constant = 0; |
| 12699 |
|
| 12700 |
if (constant) |
| 12701 |
{ |
| 12702 |
changed = true; |
| 12703 |
x = gen_rtx_PLUS (Pmode, |
| 12704 |
gen_rtx_PLUS (Pmode, XEXP (XEXP (x, 0), 0), |
| 12705 |
XEXP (XEXP (XEXP (x, 0), 1), 0)), |
| 12706 |
plus_constant (Pmode, other, |
| 12707 |
INTVAL (constant))); |
| 12708 |
} |
| 12709 |
} |
| 12710 |
|
| 12711 |
if (changed && ix86_legitimate_address_p (mode, x, false)) |
| 12712 |
return x; |
| 12713 |
|
| 12714 |
if (GET_CODE (XEXP (x, 0)) == MULT) |
| 12715 |
{ |
| 12716 |
changed = true; |
| 12717 |
XEXP (x, 0) = copy_addr_to_reg (XEXP (x, 0)); |
| 12718 |
} |
| 12719 |
|
| 12720 |
if (GET_CODE (XEXP (x, 1)) == MULT) |
| 12721 |
{ |
| 12722 |
changed = true; |
| 12723 |
XEXP (x, 1) = copy_addr_to_reg (XEXP (x, 1)); |
| 12724 |
} |
| 12725 |
|
| 12726 |
if (changed |
| 12727 |
&& REG_P (XEXP (x, 1)) |
| 12728 |
&& REG_P (XEXP (x, 0))) |
| 12729 |
return x; |
| 12730 |
|
| 12731 |
if (flag_pic && SYMBOLIC_CONST (XEXP (x, 1))) |
| 12732 |
{ |
| 12733 |
changed = true; |
| 12734 |
x = legitimize_pic_address (x, 0); |
| 12735 |
} |
| 12736 |
|
| 12737 |
if (changed && ix86_legitimate_address_p (mode, x, false)) |
| 12738 |
return x; |
| 12739 |
|
| 12740 |
if (REG_P (XEXP (x, 0))) |
| 12741 |
{ |
| 12742 |
rtx temp = gen_reg_rtx (Pmode); |
| 12743 |
rtx val = force_operand (XEXP (x, 1), temp); |
| 12744 |
if (val != temp) |
| 12745 |
{ |
| 12746 |
val = convert_to_mode (Pmode, val, 1); |
| 12747 |
emit_move_insn (temp, val); |
| 12748 |
} |
| 12749 |
|
| 12750 |
XEXP (x, 1) = temp; |
| 12751 |
return x; |
| 12752 |
} |
| 12753 |
|
| 12754 |
else if (REG_P (XEXP (x, 1))) |
| 12755 |
{ |
| 12756 |
rtx temp = gen_reg_rtx (Pmode); |
| 12757 |
rtx val = force_operand (XEXP (x, 0), temp); |
| 12758 |
if (val != temp) |
| 12759 |
{ |
| 12760 |
val = convert_to_mode (Pmode, val, 1); |
| 12761 |
emit_move_insn (temp, val); |
| 12762 |
} |
| 12763 |
|
| 12764 |
XEXP (x, 0) = temp; |
| 12765 |
return x; |
| 12766 |
} |
| 12767 |
} |
| 12768 |
|
| 12769 |
return x; |
| 12770 |
} |
| 12771 |
|
| 12772 |
/* Print an integer constant expression in assembler syntax. Addition |
| 12773 |
and subtraction are the only arithmetic that may appear in these |
| 12774 |
expressions. FILE is the stdio stream to write to, X is the rtx, and |
| 12775 |
CODE is the operand print code from the output string. */ |
| 12776 |
|
| 12777 |
static void |
| 12778 |
output_pic_addr_const (FILE *file, rtx x, int code) |
| 12779 |
{ |
| 12780 |
char buf[256]; |
| 12781 |
|
| 12782 |
switch (GET_CODE (x)) |
| 12783 |
{ |
| 12784 |
case PC: |
| 12785 |
gcc_assert (flag_pic); |
| 12786 |
putc ('.', file); |
| 12787 |
break; |
| 12788 |
|
| 12789 |
case SYMBOL_REF: |
| 12790 |
if (TARGET_64BIT || ! TARGET_MACHO_SYMBOL_STUBS) |
| 12791 |
output_addr_const (file, x); |
| 12792 |
else |
| 12793 |
{ |
| 12794 |
const char *name = XSTR (x, 0); |
| 12795 |
|
| 12796 |
/* Mark the decl as referenced so that cgraph will |
| 12797 |
output the function. */ |
| 12798 |
if (SYMBOL_REF_DECL (x)) |
| 12799 |
mark_decl_referenced (SYMBOL_REF_DECL (x)); |
| 12800 |
|
| 12801 |
#if TARGET_MACHO |
| 12802 |
if (MACHOPIC_INDIRECT |
| 12803 |
&& machopic_classify_symbol (x) == MACHOPIC_UNDEFINED_FUNCTION) |
| 12804 |
name = machopic_indirection_name (x, /*stub_p=*/true); |
| 12805 |
#endif |
| 12806 |
assemble_name (file, name); |
| 12807 |
} |
| 12808 |
if (!TARGET_MACHO && !(TARGET_64BIT && TARGET_PECOFF) |
| 12809 |
&& code == 'P' && ix86_call_use_plt_p (x)) |
| 12810 |
fputs ("@PLT", file); |
| 12811 |
break; |
| 12812 |
|
| 12813 |
case LABEL_REF: |
| 12814 |
x = XEXP (x, 0); |
| 12815 |
/* FALLTHRU */ |
| 12816 |
case CODE_LABEL: |
| 12817 |
ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x)); |
| 12818 |
assemble_name (asm_out_file, buf); |
| 12819 |
break; |
| 12820 |
|
| 12821 |
CASE_CONST_SCALAR_INT: |
| 12822 |
output_addr_const (file, x); |
| 12823 |
break; |
| 12824 |
|
| 12825 |
case CONST: |
| 12826 |
/* This used to output parentheses around the expression, |
| 12827 |
but that does not work on the 386 (either ATT or BSD assembler). */ |
| 12828 |
output_pic_addr_const (file, XEXP (x, 0), code); |
| 12829 |
break; |
| 12830 |
|
| 12831 |
case CONST_DOUBLE: |
| 12832 |
/* We can't handle floating point constants; |
| 12833 |
TARGET_PRINT_OPERAND must handle them. */ |
| 12834 |
output_operand_lossage ("floating constant misused"); |
| 12835 |
break; |
| 12836 |
|
| 12837 |
case PLUS: |
| 12838 |
/* Some assemblers need integer constants to appear first. */ |
| 12839 |
if (CONST_INT_P (XEXP (x, 0))) |
| 12840 |
{ |
| 12841 |
output_pic_addr_const (file, XEXP (x, 0), code); |
| 12842 |
putc ('+', file); |
| 12843 |
output_pic_addr_const (file, XEXP (x, 1), code); |
| 12844 |
} |
| 12845 |
else |
| 12846 |
{ |
| 12847 |
gcc_assert (CONST_INT_P (XEXP (x, 1))); |
| 12848 |
output_pic_addr_const (file, XEXP (x, 1), code); |
| 12849 |
putc ('+', file); |
| 12850 |
output_pic_addr_const (file, XEXP (x, 0), code); |
| 12851 |
} |
| 12852 |
break; |
| 12853 |
|
| 12854 |
case MINUS: |
| 12855 |
if (!TARGET_MACHO) |
| 12856 |
putc (ASSEMBLER_DIALECT == ASM_INTEL ? '(' : '[', file); |
| 12857 |
output_pic_addr_const (file, XEXP (x, 0), code); |
| 12858 |
putc ('-', file); |
| 12859 |
output_pic_addr_const (file, XEXP (x, 1), code); |
| 12860 |
if (!TARGET_MACHO) |
| 12861 |
putc (ASSEMBLER_DIALECT == ASM_INTEL ? ')' : ']', file); |
| 12862 |
break; |
| 12863 |
|
| 12864 |
case UNSPEC: |
| 12865 |
gcc_assert (XVECLEN (x, 0) == 1); |
| 12866 |
output_pic_addr_const (file, XVECEXP (x, 0, 0), code); |
| 12867 |
switch (XINT (x, 1)) |
| 12868 |
{ |
| 12869 |
case UNSPEC_GOT: |
| 12870 |
fputs ("@GOT", file); |
| 12871 |
break; |
| 12872 |
case UNSPEC_GOTOFF: |
| 12873 |
fputs ("@GOTOFF", file); |
| 12874 |
break; |
| 12875 |
case UNSPEC_PLTOFF: |
| 12876 |
fputs ("@PLTOFF", file); |
| 12877 |
break; |
| 12878 |
case UNSPEC_PCREL: |
| 12879 |
fputs (ASSEMBLER_DIALECT == ASM_ATT ? |
| 12880 |
"(%rip)" : "[rip]", file); |
| 12881 |
break; |
| 12882 |
case UNSPEC_GOTPCREL: |
| 12883 |
fputs (ASSEMBLER_DIALECT == ASM_ATT ? |
| 12884 |
"@GOTPCREL(%rip)" : "@GOTPCREL[rip]", file); |
| 12885 |
break; |
| 12886 |
case UNSPEC_GOTTPOFF: |
| 12887 |
/* FIXME: This might be @TPOFF in Sun ld too. */ |
| 12888 |
fputs ("@gottpoff", file); |
| 12889 |
break; |
| 12890 |
case UNSPEC_TPOFF: |
| 12891 |
fputs ("@tpoff", file); |
| 12892 |
break; |
| 12893 |
case UNSPEC_NTPOFF: |
| 12894 |
if (TARGET_64BIT) |
| 12895 |
fputs ("@tpoff", file); |
| 12896 |
else |
| 12897 |
fputs ("@ntpoff", file); |
| 12898 |
break; |
| 12899 |
case UNSPEC_DTPOFF: |
| 12900 |
fputs ("@dtpoff", file); |
| 12901 |
break; |
| 12902 |
case UNSPEC_GOTNTPOFF: |
| 12903 |
if (TARGET_64BIT) |
| 12904 |
fputs (ASSEMBLER_DIALECT == ASM_ATT ? |
| 12905 |
"@gottpoff(%rip)": "@gottpoff[rip]", file); |
| 12906 |
else |
| 12907 |
fputs ("@gotntpoff", file); |
| 12908 |
break; |
| 12909 |
case UNSPEC_INDNTPOFF: |
| 12910 |
fputs ("@indntpoff", file); |
| 12911 |
break; |
| 12912 |
#if TARGET_MACHO |
| 12913 |
case UNSPEC_MACHOPIC_OFFSET: |
| 12914 |
putc ('-', file); |
| 12915 |
machopic_output_function_base_name (file); |
| 12916 |
break; |
| 12917 |
#endif |
| 12918 |
default: |
| 12919 |
output_operand_lossage ("invalid UNSPEC as operand"); |
| 12920 |
break; |
| 12921 |
} |
| 12922 |
break; |
| 12923 |
|
| 12924 |
default: |
| 12925 |
output_operand_lossage ("invalid expression as operand"); |
| 12926 |
} |
| 12927 |
} |
| 12928 |
|
| 12929 |
/* This is called from dwarf2out.cc via TARGET_ASM_OUTPUT_DWARF_DTPREL. |
| 12930 |
We need to emit DTP-relative relocations. */ |
| 12931 |
|
| 12932 |
static void ATTRIBUTE_UNUSED |
| 12933 |
i386_output_dwarf_dtprel (FILE *file, int size, rtx x) |
| 12934 |
{ |
| 12935 |
fputs (ASM_LONG, file); |
| 12936 |
output_addr_const (file, x); |
| 12937 |
fputs ("@dtpoff", file); |
| 12938 |
switch (size) |
| 12939 |
{ |
| 12940 |
case 4: |
| 12941 |
break; |
| 12942 |
case 8: |
| 12943 |
fputs (", 0", file); |
| 12944 |
break; |
| 12945 |
default: |
| 12946 |
gcc_unreachable (); |
| 12947 |
} |
| 12948 |
} |
| 12949 |
|
| 12950 |
/* Return true if X is a representation of the PIC register. This copes |
| 12951 |
with calls from ix86_find_base_term, where the register might have |
| 12952 |
been replaced by a cselib value. */ |
| 12953 |
|
| 12954 |
static bool |
| 12955 |
ix86_pic_register_p (rtx x) |
| 12956 |
{ |
| 12957 |
if (GET_CODE (x) == VALUE && CSELIB_VAL_PTR (x)) |
| 12958 |
return (pic_offset_table_rtx |
| 12959 |
&& rtx_equal_for_cselib_p (x, pic_offset_table_rtx)); |
| 12960 |
else if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_SET_GOT) |
| 12961 |
return true; |
| 12962 |
else if (!REG_P (x)) |
| 12963 |
return false; |
| 12964 |
else if (pic_offset_table_rtx) |
| 12965 |
{ |
| 12966 |
if (REGNO (x) == REGNO (pic_offset_table_rtx)) |
| 12967 |
return true; |
| 12968 |
if (HARD_REGISTER_P (x) |
| 12969 |
&& !HARD_REGISTER_P (pic_offset_table_rtx) |
| 12970 |
&& ORIGINAL_REGNO (x) == REGNO (pic_offset_table_rtx)) |
| 12971 |
return true; |
| 12972 |
return false; |
| 12973 |
} |
| 12974 |
else |
| 12975 |
return REGNO (x) == PIC_OFFSET_TABLE_REGNUM; |
| 12976 |
} |
| 12977 |
|
| 12978 |
/* Helper function for ix86_delegitimize_address. |
| 12979 |
Attempt to delegitimize TLS local-exec accesses. */ |
| 12980 |
|
| 12981 |
static rtx |
| 12982 |
ix86_delegitimize_tls_address (rtx orig_x) |
| 12983 |
{ |
| 12984 |
rtx x = orig_x, unspec; |
| 12985 |
struct ix86_address addr; |
| 12986 |
|
| 12987 |
if (!TARGET_TLS_DIRECT_SEG_REFS) |
| 12988 |
return orig_x; |
| 12989 |
if (MEM_P (x)) |
| 12990 |
x = XEXP (x, 0); |
| 12991 |
if (GET_CODE (x) != PLUS || GET_MODE (x) != Pmode) |
| 12992 |
return orig_x; |
| 12993 |
if (ix86_decompose_address (x, &addr) == 0 |
| 12994 |
|| addr.seg != DEFAULT_TLS_SEG_REG |
| 12995 |
|| addr.disp == NULL_RTX |
| 12996 |
|| GET_CODE (addr.disp) != CONST) |
| 12997 |
return orig_x; |
| 12998 |
unspec = XEXP (addr.disp, 0); |
| 12999 |
if (GET_CODE (unspec) == PLUS && CONST_INT_P (XEXP (unspec, 1))) |
| 13000 |
unspec = XEXP (unspec, 0); |
| 13001 |
if (GET_CODE (unspec) != UNSPEC || XINT (unspec, 1) != UNSPEC_NTPOFF) |
| 13002 |
return orig_x; |
| 13003 |
x = XVECEXP (unspec, 0, 0); |
| 13004 |
gcc_assert (GET_CODE (x) == SYMBOL_REF); |
| 13005 |
if (unspec != XEXP (addr.disp, 0)) |
| 13006 |
x = gen_rtx_PLUS (Pmode, x, XEXP (XEXP (addr.disp, 0), 1)); |
| 13007 |
if (addr.index) |
| 13008 |
{ |
| 13009 |
rtx idx = addr.index; |
| 13010 |
if (addr.scale != 1) |
| 13011 |
idx = gen_rtx_MULT (Pmode, idx, GEN_INT (addr.scale)); |
| 13012 |
x = gen_rtx_PLUS (Pmode, idx, x); |
| 13013 |
} |
| 13014 |
if (addr.base) |
| 13015 |
x = gen_rtx_PLUS (Pmode, addr.base, x); |
| 13016 |
if (MEM_P (orig_x)) |
| 13017 |
x = replace_equiv_address_nv (orig_x, x); |
| 13018 |
return x; |
| 13019 |
} |
| 13020 |
|
| 13021 |
/* In the name of slightly smaller debug output, and to cater to |
| 13022 |
general assembler lossage, recognize PIC+GOTOFF and turn it back |
| 13023 |
into a direct symbol reference. |
| 13024 |
|
| 13025 |
On Darwin, this is necessary to avoid a crash, because Darwin |
| 13026 |
has a different PIC label for each routine but the DWARF debugging |
| 13027 |
information is not associated with any particular routine, so it's |
| 13028 |
necessary to remove references to the PIC label from RTL stored by |
| 13029 |
the DWARF output code. |
| 13030 |
|
| 13031 |
This helper is used in the normal ix86_delegitimize_address |
| 13032 |
entrypoint (e.g. used in the target delegitimization hook) and |
| 13033 |
in ix86_find_base_term. As compile time memory optimization, we |
| 13034 |
avoid allocating rtxes that will not change anything on the outcome |
| 13035 |
of the callers (find_base_value and find_base_term). */ |
| 13036 |
|
| 13037 |
static inline rtx |
| 13038 |
ix86_delegitimize_address_1 (rtx x, bool base_term_p) |
| 13039 |
{ |
| 13040 |
rtx orig_x = delegitimize_mem_from_attrs (x); |
| 13041 |
/* addend is NULL or some rtx if x is something+GOTOFF where |
| 13042 |
something doesn't include the PIC register. */ |
| 13043 |
rtx addend = NULL_RTX; |
| 13044 |
/* reg_addend is NULL or a multiple of some register. */ |
| 13045 |
rtx reg_addend = NULL_RTX; |
| 13046 |
/* const_addend is NULL or a const_int. */ |
| 13047 |
rtx const_addend = NULL_RTX; |
| 13048 |
/* This is the result, or NULL. */ |
| 13049 |
rtx result = NULL_RTX; |
| 13050 |
|
| 13051 |
x = orig_x; |
| 13052 |
|
| 13053 |
if (MEM_P (x)) |
| 13054 |
x = XEXP (x, 0); |
| 13055 |
|
| 13056 |
if (TARGET_64BIT) |
| 13057 |
{ |
| 13058 |
if (GET_CODE (x) == CONST |
| 13059 |
&& GET_CODE (XEXP (x, 0)) == PLUS |
| 13060 |
&& GET_MODE (XEXP (x, 0)) == Pmode |
| 13061 |
&& CONST_INT_P (XEXP (XEXP (x, 0), 1)) |
| 13062 |
&& GET_CODE (XEXP (XEXP (x, 0), 0)) == UNSPEC |
| 13063 |
&& XINT (XEXP (XEXP (x, 0), 0), 1) == UNSPEC_PCREL) |
| 13064 |
{ |
| 13065 |
/* find_base_{value,term} only care about MEMs with arg_pointer_rtx |
| 13066 |
base. A CONST can't be arg_pointer_rtx based. */ |
| 13067 |
if (base_term_p && MEM_P (orig_x)) |
| 13068 |
return orig_x; |
| 13069 |
rtx x2 = XVECEXP (XEXP (XEXP (x, 0), 0), 0, 0); |
| 13070 |
x = gen_rtx_PLUS (Pmode, XEXP (XEXP (x, 0), 1), x2); |
| 13071 |
if (MEM_P (orig_x)) |
| 13072 |
x = replace_equiv_address_nv (orig_x, x); |
| 13073 |
return x; |
| 13074 |
} |
| 13075 |
|
| 13076 |
if (GET_CODE (x) == CONST |
| 13077 |
&& GET_CODE (XEXP (x, 0)) == UNSPEC |
| 13078 |
&& (XINT (XEXP (x, 0), 1) == UNSPEC_GOTPCREL |
| 13079 |
|| XINT (XEXP (x, 0), 1) == UNSPEC_PCREL) |
| 13080 |
&& (MEM_P (orig_x) || XINT (XEXP (x, 0), 1) == UNSPEC_PCREL)) |
| 13081 |
{ |
| 13082 |
x = XVECEXP (XEXP (x, 0), 0, 0); |
| 13083 |
if (GET_MODE (orig_x) != GET_MODE (x) && MEM_P (orig_x)) |
| 13084 |
{ |
| 13085 |
x = lowpart_subreg (GET_MODE (orig_x), x, GET_MODE (x)); |
| 13086 |
if (x == NULL_RTX) |
| 13087 |
return orig_x; |
| 13088 |
} |
| 13089 |
return x; |
| 13090 |
} |
| 13091 |
|
| 13092 |
if (ix86_cmodel != CM_MEDIUM_PIC && ix86_cmodel != CM_LARGE_PIC) |
| 13093 |
return ix86_delegitimize_tls_address (orig_x); |
| 13094 |
|
| 13095 |
/* Fall thru into the code shared with -m32 for -mcmodel=large -fpic |
| 13096 |
and -mcmodel=medium -fpic. */ |
| 13097 |
} |
| 13098 |
|
| 13099 |
if (GET_CODE (x) != PLUS |
| 13100 |
|| GET_CODE (XEXP (x, 1)) != CONST) |
| 13101 |
return ix86_delegitimize_tls_address (orig_x); |
| 13102 |
|
| 13103 |
if (ix86_pic_register_p (XEXP (x, 0))) |
| 13104 |
/* %ebx + GOT/GOTOFF */ |
| 13105 |
; |
| 13106 |
else if (GET_CODE (XEXP (x, 0)) == PLUS) |
| 13107 |
{ |
| 13108 |
/* %ebx + %reg * scale + GOT/GOTOFF */ |
| 13109 |
reg_addend = XEXP (x, 0); |
| 13110 |
if (ix86_pic_register_p (XEXP (reg_addend, 0))) |
| 13111 |
reg_addend = XEXP (reg_addend, 1); |
| 13112 |
else if (ix86_pic_register_p (XEXP (reg_addend, 1))) |
| 13113 |
reg_addend = XEXP (reg_addend, 0); |
| 13114 |
else |
| 13115 |
{ |
| 13116 |
reg_addend = NULL_RTX; |
| 13117 |
addend = XEXP (x, 0); |
| 13118 |
} |
| 13119 |
} |
| 13120 |
else |
| 13121 |
addend = XEXP (x, 0); |
| 13122 |
|
| 13123 |
x = XEXP (XEXP (x, 1), 0); |
| 13124 |
if (GET_CODE (x) == PLUS |
| 13125 |
&& CONST_INT_P (XEXP (x, 1))) |
| 13126 |
{ |
| 13127 |
const_addend = XEXP (x, 1); |
| 13128 |
x = XEXP (x, 0); |
| 13129 |
} |
| 13130 |
|
| 13131 |
if (GET_CODE (x) == UNSPEC |
| 13132 |
&& ((XINT (x, 1) == UNSPEC_GOT && MEM_P (orig_x) && !addend) |
| 13133 |
|| (XINT (x, 1) == UNSPEC_GOTOFF && !MEM_P (orig_x)) |
| 13134 |
|| (XINT (x, 1) == UNSPEC_PLTOFF && ix86_cmodel == CM_LARGE_PIC |
| 13135 |
&& !MEM_P (orig_x) && !addend))) |
| 13136 |
result = XVECEXP (x, 0, 0); |
| 13137 |
|
| 13138 |
if (!TARGET_64BIT && TARGET_MACHO && darwin_local_data_pic (x) |
| 13139 |
&& !MEM_P (orig_x)) |
| 13140 |
result = XVECEXP (x, 0, 0); |
| 13141 |
|
| 13142 |
if (! result) |
| 13143 |
return ix86_delegitimize_tls_address (orig_x); |
| 13144 |
|
| 13145 |
/* For (PLUS something CONST_INT) both find_base_{value,term} just |
| 13146 |
recurse on the first operand. */ |
| 13147 |
if (const_addend && !base_term_p) |
| 13148 |
result = gen_rtx_CONST (Pmode, gen_rtx_PLUS (Pmode, result, const_addend)); |
| 13149 |
if (reg_addend) |
| 13150 |
result = gen_rtx_PLUS (Pmode, reg_addend, result); |
| 13151 |
if (addend) |
| 13152 |
{ |
| 13153 |
/* If the rest of original X doesn't involve the PIC register, add |
| 13154 |
addend and subtract pic_offset_table_rtx. This can happen e.g. |
| 13155 |
for code like: |
| 13156 |
leal (%ebx, %ecx, 4), %ecx |
| 13157 |
... |
| 13158 |
movl foo@GOTOFF(%ecx), %edx |
| 13159 |
in which case we return (%ecx - %ebx) + foo |
| 13160 |
or (%ecx - _GLOBAL_OFFSET_TABLE_) + foo if pseudo_pic_reg |
| 13161 |
and reload has completed. Don't do the latter for debug, |
| 13162 |
as _GLOBAL_OFFSET_TABLE_ can't be expressed in the assembly. */ |
| 13163 |
if (pic_offset_table_rtx |
| 13164 |
&& (!reload_completed || !ix86_use_pseudo_pic_reg ())) |
| 13165 |
result = gen_rtx_PLUS (Pmode, gen_rtx_MINUS (Pmode, copy_rtx (addend), |
| 13166 |
pic_offset_table_rtx), |
| 13167 |
result); |
| 13168 |
else if (base_term_p |
| 13169 |
&& pic_offset_table_rtx |
| 13170 |
&& !TARGET_MACHO |
| 13171 |
&& !TARGET_VXWORKS_RTP) |
| 13172 |
{ |
| 13173 |
rtx tmp = gen_rtx_SYMBOL_REF (Pmode, GOT_SYMBOL_NAME); |
| 13174 |
tmp = gen_rtx_MINUS (Pmode, copy_rtx (addend), tmp); |
| 13175 |
result = gen_rtx_PLUS (Pmode, tmp, result); |
| 13176 |
} |
| 13177 |
else |
| 13178 |
return orig_x; |
| 13179 |
} |
| 13180 |
if (GET_MODE (orig_x) != Pmode && MEM_P (orig_x)) |
| 13181 |
{ |
| 13182 |
result = lowpart_subreg (GET_MODE (orig_x), result, Pmode); |
| 13183 |
if (result == NULL_RTX) |
| 13184 |
return orig_x; |
| 13185 |
} |
| 13186 |
return result; |
| 13187 |
} |
| 13188 |
|
| 13189 |
/* The normal instantiation of the above template. */ |
| 13190 |
|
| 13191 |
static rtx |
| 13192 |
ix86_delegitimize_address (rtx x) |
| 13193 |
{ |
| 13194 |
return ix86_delegitimize_address_1 (x, false); |
| 13195 |
} |
| 13196 |
|
| 13197 |
/* If X is a machine specific address (i.e. a symbol or label being |
| 13198 |
referenced as a displacement from the GOT implemented using an |
| 13199 |
UNSPEC), then return the base term. Otherwise return X. */ |
| 13200 |
|
| 13201 |
rtx |
| 13202 |
ix86_find_base_term (rtx x) |
| 13203 |
{ |
| 13204 |
rtx term; |
| 13205 |
|
| 13206 |
if (TARGET_64BIT) |
| 13207 |
{ |
| 13208 |
if (GET_CODE (x) != CONST) |
| 13209 |
return x; |
| 13210 |
term = XEXP (x, 0); |
| 13211 |
if (GET_CODE (term) == PLUS |
| 13212 |
&& CONST_INT_P (XEXP (term, 1))) |
| 13213 |
term = XEXP (term, 0); |
| 13214 |
if (GET_CODE (term) != UNSPEC |
| 13215 |
|| (XINT (term, 1) != UNSPEC_GOTPCREL |
| 13216 |
&& XINT (term, 1) != UNSPEC_PCREL)) |
| 13217 |
return x; |
| 13218 |
|
| 13219 |
return XVECEXP (term, 0, 0); |
| 13220 |
} |
| 13221 |
|
| 13222 |
return ix86_delegitimize_address_1 (x, true); |
| 13223 |
} |
| 13224 |
|
| 13225 |
/* Return true if X shouldn't be emitted into the debug info. |
| 13226 |
Disallow UNSPECs other than @gotoff - we can't emit _GLOBAL_OFFSET_TABLE_ |
| 13227 |
symbol easily into the .debug_info section, so we need not to |
| 13228 |
delegitimize, but instead assemble as @gotoff. |
| 13229 |
Disallow _GLOBAL_OFFSET_TABLE_ SYMBOL_REF - the assembler magically |
| 13230 |
assembles that as _GLOBAL_OFFSET_TABLE_-. expression. */ |
| 13231 |
|
| 13232 |
static bool |
| 13233 |
ix86_const_not_ok_for_debug_p (rtx x) |
| 13234 |
{ |
| 13235 |
if (GET_CODE (x) == UNSPEC && XINT (x, 1) != UNSPEC_GOTOFF) |
| 13236 |
return true; |
| 13237 |
|
| 13238 |
if (SYMBOL_REF_P (x) && strcmp (XSTR (x, 0), GOT_SYMBOL_NAME) == 0) |
| 13239 |
return true; |
| 13240 |
|
| 13241 |
return false; |
| 13242 |
} |
| 13243 |
|
| 13244 |
static void |
| 13245 |
put_condition_code (enum rtx_code code, machine_mode mode, bool reverse, |
| 13246 |
bool fp, FILE *file) |
| 13247 |
{ |
| 13248 |
const char *suffix; |
| 13249 |
|
| 13250 |
if (mode == CCFPmode) |
| 13251 |
{ |
| 13252 |
code = ix86_fp_compare_code_to_integer (code); |
| 13253 |
mode = CCmode; |
| 13254 |
} |
| 13255 |
if (reverse) |
| 13256 |
code = reverse_condition (code); |
| 13257 |
|
| 13258 |
switch (code) |
| 13259 |
{ |
| 13260 |
case EQ: |
| 13261 |
gcc_assert (mode != CCGZmode); |
| 13262 |
switch (mode) |
| 13263 |
{ |
| 13264 |
case E_CCAmode: |
| 13265 |
suffix = "a"; |
| 13266 |
break; |
| 13267 |
case E_CCCmode: |
| 13268 |
suffix = "c"; |
| 13269 |
break; |
| 13270 |
case E_CCOmode: |
| 13271 |
suffix = "o"; |
| 13272 |
break; |
| 13273 |
case E_CCPmode: |
| 13274 |
suffix = "p"; |
| 13275 |
break; |
| 13276 |
case E_CCSmode: |
| 13277 |
suffix = "s"; |
| 13278 |
break; |
| 13279 |
default: |
| 13280 |
suffix = "e"; |
| 13281 |
break; |
| 13282 |
} |
| 13283 |
break; |
| 13284 |
case NE: |
| 13285 |
gcc_assert (mode != CCGZmode); |
| 13286 |
switch (mode) |
| 13287 |
{ |
| 13288 |
case E_CCAmode: |
| 13289 |
suffix = "na"; |
| 13290 |
break; |
| 13291 |
case E_CCCmode: |
| 13292 |
suffix = "nc"; |
| 13293 |
break; |
| 13294 |
case E_CCOmode: |
| 13295 |
suffix = "no"; |
| 13296 |
break; |
| 13297 |
case E_CCPmode: |
| 13298 |
suffix = "np"; |
| 13299 |
break; |
| 13300 |
case E_CCSmode: |
| 13301 |
suffix = "ns"; |
| 13302 |
break; |
| 13303 |
default: |
| 13304 |
suffix = "ne"; |
| 13305 |
break; |
| 13306 |
} |
| 13307 |
break; |
| 13308 |
case GT: |
| 13309 |
gcc_assert (mode == CCmode || mode == CCNOmode || mode == CCGCmode); |
| 13310 |
suffix = "g"; |
| 13311 |
break; |
| 13312 |
case GTU: |
| 13313 |
/* ??? Use "nbe" instead of "a" for fcmov lossage on some assemblers. |
| 13314 |
Those same assemblers have the same but opposite lossage on cmov. */ |
| 13315 |
if (mode == CCmode) |
| 13316 |
suffix = fp ? "nbe" : "a"; |
| 13317 |
else |
| 13318 |
gcc_unreachable (); |
| 13319 |
break; |
| 13320 |
case LT: |
| 13321 |
switch (mode) |
| 13322 |
{ |
| 13323 |
case E_CCNOmode: |
| 13324 |
case E_CCGOCmode: |
| 13325 |
suffix = "s"; |
| 13326 |
break; |
| 13327 |
|
| 13328 |
case E_CCmode: |
| 13329 |
case E_CCGCmode: |
| 13330 |
case E_CCGZmode: |
| 13331 |
suffix = "l"; |
| 13332 |
break; |
| 13333 |
|
| 13334 |
default: |
| 13335 |
gcc_unreachable (); |
| 13336 |
} |
| 13337 |
break; |
| 13338 |
case LTU: |
| 13339 |
if (mode == CCmode || mode == CCGZmode) |
| 13340 |
suffix = "b"; |
| 13341 |
else if (mode == CCCmode) |
| 13342 |
suffix = fp ? "b" : "c"; |
| 13343 |
else |
| 13344 |
gcc_unreachable (); |
| 13345 |
break; |
| 13346 |
case GE: |
| 13347 |
switch (mode) |
| 13348 |
{ |
| 13349 |
case E_CCNOmode: |
| 13350 |
case E_CCGOCmode: |
| 13351 |
suffix = "ns"; |
| 13352 |
break; |
| 13353 |
|
| 13354 |
case E_CCmode: |
| 13355 |
case E_CCGCmode: |
| 13356 |
case E_CCGZmode: |
| 13357 |
suffix = "ge"; |
| 13358 |
break; |
| 13359 |
|
| 13360 |
default: |
| 13361 |
gcc_unreachable (); |
| 13362 |
} |
| 13363 |
break; |
| 13364 |
case GEU: |
| 13365 |
if (mode == CCmode || mode == CCGZmode) |
| 13366 |
suffix = "nb"; |
| 13367 |
else if (mode == CCCmode) |
| 13368 |
suffix = fp ? "nb" : "nc"; |
| 13369 |
else |
| 13370 |
gcc_unreachable (); |
| 13371 |
break; |
| 13372 |
case LE: |
| 13373 |
gcc_assert (mode == CCmode || mode == CCGCmode || mode == CCNOmode); |
| 13374 |
suffix = "le"; |
| 13375 |
break; |
| 13376 |
case LEU: |
| 13377 |
if (mode == CCmode) |
| 13378 |
suffix = "be"; |
| 13379 |
else |
| 13380 |
gcc_unreachable (); |
| 13381 |
break; |
| 13382 |
case UNORDERED: |
| 13383 |
suffix = fp ? "u" : "p"; |
| 13384 |
break; |
| 13385 |
case ORDERED: |
| 13386 |
suffix = fp ? "nu" : "np"; |
| 13387 |
break; |
| 13388 |
default: |
| 13389 |
gcc_unreachable (); |
| 13390 |
} |
| 13391 |
fputs (suffix, file); |
| 13392 |
} |
| 13393 |
|
| 13394 |
/* Print the name of register X to FILE based on its machine mode and number. |
| 13395 |
If CODE is 'w', pretend the mode is HImode. |
| 13396 |
If CODE is 'b', pretend the mode is QImode. |
| 13397 |
If CODE is 'k', pretend the mode is SImode. |
| 13398 |
If CODE is 'q', pretend the mode is DImode. |
| 13399 |
If CODE is 'x', pretend the mode is V4SFmode. |
| 13400 |
If CODE is 't', pretend the mode is V8SFmode. |
| 13401 |
If CODE is 'g', pretend the mode is V16SFmode. |
| 13402 |
If CODE is 'h', pretend the reg is the 'high' byte register. |
| 13403 |
If CODE is 'y', print "st(0)" instead of "st", if the reg is stack op. |
| 13404 |
If CODE is 'd', duplicate the operand for AVX instruction. |
| 13405 |
If CODE is 'V', print naked full integer register name without %. |
| 13406 |
*/ |
| 13407 |
|
| 13408 |
void |
| 13409 |
print_reg (rtx x, int code, FILE *file) |
| 13410 |
{ |
| 13411 |
const char *reg; |
| 13412 |
int msize; |
| 13413 |
unsigned int regno; |
| 13414 |
bool duplicated; |
| 13415 |
|
| 13416 |
if (ASSEMBLER_DIALECT == ASM_ATT && code != 'V') |
| 13417 |
putc ('%', file); |
| 13418 |
|
| 13419 |
if (x == pc_rtx) |
| 13420 |
{ |
| 13421 |
gcc_assert (TARGET_64BIT); |
| 13422 |
fputs ("rip", file); |
| 13423 |
return; |
| 13424 |
} |
| 13425 |
|
| 13426 |
if (code == 'y' && STACK_TOP_P (x)) |
| 13427 |
{ |
| 13428 |
fputs ("st(0)", file); |
| 13429 |
return; |
| 13430 |
} |
| 13431 |
|
| 13432 |
if (code == 'w') |
| 13433 |
msize = 2; |
| 13434 |
else if (code == 'b') |
| 13435 |
msize = 1; |
| 13436 |
else if (code == 'k') |
| 13437 |
msize = 4; |
| 13438 |
else if (code == 'q') |
| 13439 |
msize = 8; |
| 13440 |
else if (code == 'h') |
| 13441 |
msize = 0; |
| 13442 |
else if (code == 'x') |
| 13443 |
msize = 16; |
| 13444 |
else if (code == 't') |
| 13445 |
msize = 32; |
| 13446 |
else if (code == 'g') |
| 13447 |
msize = 64; |
| 13448 |
else |
| 13449 |
msize = GET_MODE_SIZE (GET_MODE (x)); |
| 13450 |
|
| 13451 |
regno = REGNO (x); |
| 13452 |
|
| 13453 |
if (regno == ARG_POINTER_REGNUM |
| 13454 |
|| regno == FRAME_POINTER_REGNUM |
| 13455 |
|| regno == FPSR_REG) |
| 13456 |
{ |
| 13457 |
output_operand_lossage |
| 13458 |
("invalid use of register '%s'", reg_names[regno]); |
| 13459 |
return; |
| 13460 |
} |
| 13461 |
else if (regno == FLAGS_REG) |
| 13462 |
{ |
| 13463 |
output_operand_lossage ("invalid use of asm flag output"); |
| 13464 |
return; |
| 13465 |
} |
| 13466 |
|
| 13467 |
if (code == 'V') |
| 13468 |
{ |
| 13469 |
if (GENERAL_REGNO_P (regno)) |
| 13470 |
msize = GET_MODE_SIZE (word_mode); |
| 13471 |
else |
| 13472 |
error ("%<V%> modifier on non-integer register"); |
| 13473 |
} |
| 13474 |
|
| 13475 |
duplicated = code == 'd' && TARGET_AVX; |
| 13476 |
|
| 13477 |
switch (msize) |
| 13478 |
{ |
| 13479 |
case 16: |
| 13480 |
case 12: |
| 13481 |
case 8: |
| 13482 |
if (GENERAL_REGNO_P (regno) && msize > GET_MODE_SIZE (word_mode)) |
| 13483 |
warning (0, "unsupported size for integer register"); |
| 13484 |
/* FALLTHRU */ |
| 13485 |
case 4: |
| 13486 |
if (LEGACY_INT_REGNO_P (regno)) |
| 13487 |
putc (msize > 4 && TARGET_64BIT ? 'r' : 'e', file); |
| 13488 |
/* FALLTHRU */ |
| 13489 |
case 2: |
| 13490 |
normal: |
| 13491 |
reg = hi_reg_name[regno]; |
| 13492 |
break; |
| 13493 |
case 1: |
| 13494 |
if (regno >= ARRAY_SIZE (qi_reg_name)) |
| 13495 |
goto normal; |
| 13496 |
if (!ANY_QI_REGNO_P (regno)) |
| 13497 |
error ("unsupported size for integer register"); |
| 13498 |
reg = qi_reg_name[regno]; |
| 13499 |
break; |
| 13500 |
case 0: |
| 13501 |
if (regno >= ARRAY_SIZE (qi_high_reg_name)) |
| 13502 |
goto normal; |
| 13503 |
reg = qi_high_reg_name[regno]; |
| 13504 |
break; |
| 13505 |
case 32: |
| 13506 |
case 64: |
| 13507 |
if (SSE_REGNO_P (regno)) |
| 13508 |
{ |
| 13509 |
gcc_assert (!duplicated); |
| 13510 |
putc (msize == 32 ? 'y' : 'z', file); |
| 13511 |
reg = hi_reg_name[regno] + 1; |
| 13512 |
break; |
| 13513 |
} |
| 13514 |
goto normal; |
| 13515 |
default: |
| 13516 |
gcc_unreachable (); |
| 13517 |
} |
| 13518 |
|
| 13519 |
fputs (reg, file); |
| 13520 |
|
| 13521 |
/* Irritatingly, AMD extended registers use |
| 13522 |
different naming convention: "r%d[bwd]" */ |
| 13523 |
if (REX_INT_REGNO_P (regno) || REX2_INT_REGNO_P (regno)) |
| 13524 |
{ |
| 13525 |
gcc_assert (TARGET_64BIT); |
| 13526 |
switch (msize) |
| 13527 |
{ |
| 13528 |
case 0: |
| 13529 |
error ("extended registers have no high halves"); |
| 13530 |
break; |
| 13531 |
case 1: |
| 13532 |
putc ('b', file); |
| 13533 |
break; |
| 13534 |
case 2: |
| 13535 |
putc ('w', file); |
| 13536 |
break; |
| 13537 |
case 4: |
| 13538 |
putc ('d', file); |
| 13539 |
break; |
| 13540 |
case 8: |
| 13541 |
/* no suffix */ |
| 13542 |
break; |
| 13543 |
default: |
| 13544 |
error ("unsupported operand size for extended register"); |
| 13545 |
break; |
| 13546 |
} |
| 13547 |
return; |
| 13548 |
} |
| 13549 |
|
| 13550 |
if (duplicated) |
| 13551 |
{ |
| 13552 |
if (ASSEMBLER_DIALECT == ASM_ATT) |
| 13553 |
fprintf (file, ", %%%s", reg); |
| 13554 |
else |
| 13555 |
fprintf (file, ", %s", reg); |
| 13556 |
} |
| 13557 |
} |
| 13558 |
|
| 13559 |
/* Meaning of CODE: |
| 13560 |
L,W,B,Q,S,T -- print the opcode suffix for specified size of operand. |
| 13561 |
C -- print opcode suffix for set/cmov insn. |
| 13562 |
c -- like C, but print reversed condition |
| 13563 |
F,f -- likewise, but for floating-point. |
| 13564 |
O -- if HAVE_AS_IX86_CMOV_SUN_SYNTAX, expand to "w.", "l." or "q.", |
| 13565 |
otherwise nothing |
| 13566 |
R -- print embedded rounding and sae. |
| 13567 |
r -- print only sae. |
| 13568 |
z -- print the opcode suffix for the size of the current operand. |
| 13569 |
Z -- likewise, with special suffixes for x87 instructions. |
| 13570 |
* -- print a star (in certain assembler syntax) |
| 13571 |
A -- print an absolute memory reference. |
| 13572 |
E -- print address with DImode register names if TARGET_64BIT. |
| 13573 |
w -- print the operand as if it's a "word" (HImode) even if it isn't. |
| 13574 |
s -- print a shift double count, followed by the assemblers argument |
| 13575 |
delimiter. |
| 13576 |
b -- print the QImode name of the register for the indicated operand. |
| 13577 |
%b0 would print %al if operands[0] is reg 0. |
| 13578 |
w -- likewise, print the HImode name of the register. |
| 13579 |
k -- likewise, print the SImode name of the register. |
| 13580 |
q -- likewise, print the DImode name of the register. |
| 13581 |
x -- likewise, print the V4SFmode name of the register. |
| 13582 |
t -- likewise, print the V8SFmode name of the register. |
| 13583 |
g -- likewise, print the V16SFmode name of the register. |
| 13584 |
h -- print the QImode name for a "high" register, either ah, bh, ch or dh. |
| 13585 |
y -- print "st(0)" instead of "st" as a register. |
| 13586 |
d -- print duplicated register operand for AVX instruction. |
| 13587 |
D -- print condition for SSE cmp instruction. |
| 13588 |
P -- if PIC, print an @PLT suffix. For -fno-plt, load function |
| 13589 |
address from GOT. |
| 13590 |
p -- print raw symbol name. |
| 13591 |
X -- don't print any sort of PIC '@' suffix for a symbol. |
| 13592 |
& -- print some in-use local-dynamic symbol name. |
| 13593 |
H -- print a memory address offset by 8; used for sse high-parts |
| 13594 |
Y -- print condition for XOP pcom* instruction. |
| 13595 |
V -- print naked full integer register name without %. |
| 13596 |
+ -- print a branch hint as 'cs' or 'ds' prefix |
| 13597 |
; -- print a semicolon (after prefixes due to bug in older gas). |
| 13598 |
~ -- print "i" if TARGET_AVX2, "f" otherwise. |
| 13599 |
^ -- print addr32 prefix if TARGET_64BIT and Pmode != word_mode |
| 13600 |
M -- print addr32 prefix for TARGET_X32 with VSIB address. |
| 13601 |
! -- print NOTRACK prefix for jxx/call/ret instructions if required. |
| 13602 |
N -- print maskz if it's constant 0 operand. |
| 13603 |
G -- print embedded flag for ccmp/ctest. |
| 13604 |
*/ |
| 13605 |
|
| 13606 |
void |
| 13607 |
ix86_print_operand (FILE *file, rtx x, int code) |
| 13608 |
{ |
| 13609 |
if (code) |
| 13610 |
{ |
| 13611 |
switch (code) |
| 13612 |
{ |
| 13613 |
case 'A': |
| 13614 |
switch (ASSEMBLER_DIALECT) |
| 13615 |
{ |
| 13616 |
case ASM_ATT: |
| 13617 |
putc ('*', file); |
| 13618 |
break; |
| 13619 |
|
| 13620 |
case ASM_INTEL: |
| 13621 |
/* Intel syntax. For absolute addresses, registers should not |
| 13622 |
be surrounded by braces. */ |
| 13623 |
if (!REG_P (x)) |
| 13624 |
{ |
| 13625 |
putc ('[', file); |
| 13626 |
ix86_print_operand (file, x, 0); |
| 13627 |
putc (']', file); |
| 13628 |
return; |
| 13629 |
} |
| 13630 |
break; |
| 13631 |
|
| 13632 |
default: |
| 13633 |
gcc_unreachable (); |
| 13634 |
} |
| 13635 |
|
| 13636 |
ix86_print_operand (file, x, 0); |
| 13637 |
return; |
| 13638 |
|
| 13639 |
case 'E': |
| 13640 |
/* Wrap address in an UNSPEC to declare special handling. */ |
| 13641 |
if (TARGET_64BIT) |
| 13642 |
x = gen_rtx_UNSPEC (DImode, gen_rtvec (1, x), UNSPEC_LEA_ADDR); |
| 13643 |
|
| 13644 |
output_address (VOIDmode, x); |
| 13645 |
return; |
| 13646 |
|
| 13647 |
case 'L': |
| 13648 |
if (ASSEMBLER_DIALECT == ASM_ATT) |
| 13649 |
putc ('l', file); |
| 13650 |
return; |
| 13651 |
|
| 13652 |
case 'W': |
| 13653 |
if (ASSEMBLER_DIALECT == ASM_ATT) |
| 13654 |
putc ('w', file); |
| 13655 |
return; |
| 13656 |
|
| 13657 |
case 'B': |
| 13658 |
if (ASSEMBLER_DIALECT == ASM_ATT) |
| 13659 |
putc ('b', file); |
| 13660 |
return; |
| 13661 |
|
| 13662 |
case 'Q': |
| 13663 |
if (ASSEMBLER_DIALECT == ASM_ATT) |
| 13664 |
putc ('l', file); |
| 13665 |
return; |
| 13666 |
|
| 13667 |
case 'S': |
| 13668 |
if (ASSEMBLER_DIALECT == ASM_ATT) |
| 13669 |
putc ('s', file); |
| 13670 |
return; |
| 13671 |
|
| 13672 |
case 'T': |
| 13673 |
if (ASSEMBLER_DIALECT == ASM_ATT) |
| 13674 |
putc ('t', file); |
| 13675 |
return; |
| 13676 |
|
| 13677 |
case 'O': |
| 13678 |
#ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX |
| 13679 |
if (ASSEMBLER_DIALECT != ASM_ATT) |
| 13680 |
return; |
| 13681 |
|
| 13682 |
switch (GET_MODE_SIZE (GET_MODE (x))) |
| 13683 |
{ |
| 13684 |
case 2: |
| 13685 |
putc ('w', file); |
| 13686 |
break; |
| 13687 |
|
| 13688 |
case 4: |
| 13689 |
putc ('l', file); |
| 13690 |
break; |
| 13691 |
|
| 13692 |
case 8: |
| 13693 |
putc ('q', file); |
| 13694 |
break; |
| 13695 |
|
| 13696 |
default: |
| 13697 |
output_operand_lossage ("invalid operand size for operand " |
| 13698 |
"code 'O'"); |
| 13699 |
return; |
| 13700 |
} |
| 13701 |
|
| 13702 |
putc ('.', file); |
| 13703 |
#endif |
| 13704 |
return; |
| 13705 |
|
| 13706 |
case 'z': |
| 13707 |
if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT) |
| 13708 |
{ |
| 13709 |
/* Opcodes don't get size suffixes if using Intel opcodes. */ |
| 13710 |
if (ASSEMBLER_DIALECT == ASM_INTEL) |
| 13711 |
return; |
| 13712 |
|
| 13713 |
switch (GET_MODE_SIZE (GET_MODE (x))) |
| 13714 |
{ |
| 13715 |
case 1: |
| 13716 |
putc ('b', file); |
| 13717 |
return; |
| 13718 |
|
| 13719 |
case 2: |
| 13720 |
putc ('w', file); |
| 13721 |
return; |
| 13722 |
|
| 13723 |
case 4: |
| 13724 |
putc ('l', file); |
| 13725 |
return; |
| 13726 |
|
| 13727 |
case 8: |
| 13728 |
putc ('q', file); |
| 13729 |
return; |
| 13730 |
|
| 13731 |
default: |
| 13732 |
output_operand_lossage ("invalid operand size for operand " |
| 13733 |
"code 'z'"); |
| 13734 |
return; |
| 13735 |
} |
| 13736 |
} |
| 13737 |
|
| 13738 |
if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT) |
| 13739 |
{ |
| 13740 |
if (this_is_asm_operands) |
| 13741 |
warning_for_asm (this_is_asm_operands, |
| 13742 |
"non-integer operand used with operand code %<z%>"); |
| 13743 |
else |
| 13744 |
warning (0, "non-integer operand used with operand code %<z%>"); |
| 13745 |
} |
| 13746 |
/* FALLTHRU */ |
| 13747 |
|
| 13748 |
case 'Z': |
| 13749 |
/* 387 opcodes don't get size suffixes if using Intel opcodes. */ |
| 13750 |
if (ASSEMBLER_DIALECT == ASM_INTEL) |
| 13751 |
return; |
| 13752 |
|
| 13753 |
if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT) |
| 13754 |
{ |
| 13755 |
switch (GET_MODE_SIZE (GET_MODE (x))) |
| 13756 |
{ |
| 13757 |
case 2: |
| 13758 |
#ifdef HAVE_AS_IX86_FILDS |
| 13759 |
putc ('s', file); |
| 13760 |
#endif |
| 13761 |
return; |
| 13762 |
|
| 13763 |
case 4: |
| 13764 |
putc ('l', file); |
| 13765 |
return; |
| 13766 |
|
| 13767 |
case 8: |
| 13768 |
#ifdef HAVE_AS_IX86_FILDQ |
| 13769 |
putc ('q', file); |
| 13770 |
#else |
| 13771 |
fputs ("ll", file); |
| 13772 |
#endif |
| 13773 |
return; |
| 13774 |
|
| 13775 |
default: |
| 13776 |
break; |
| 13777 |
} |
| 13778 |
} |
| 13779 |
else if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT) |
| 13780 |
{ |
| 13781 |
/* 387 opcodes don't get size suffixes |
| 13782 |
if the operands are registers. */ |
| 13783 |
if (STACK_REG_P (x)) |
| 13784 |
return; |
| 13785 |
|
| 13786 |
switch (GET_MODE_SIZE (GET_MODE (x))) |
| 13787 |
{ |
| 13788 |
case 4: |
| 13789 |
putc ('s', file); |
| 13790 |
return; |
| 13791 |
|
| 13792 |
case 8: |
| 13793 |
putc ('l', file); |
| 13794 |
return; |
| 13795 |
|
| 13796 |
case 12: |
| 13797 |
case 16: |
| 13798 |
putc ('t', file); |
| 13799 |
return; |
| 13800 |
|
| 13801 |
default: |
| 13802 |
break; |
| 13803 |
} |
| 13804 |
} |
| 13805 |
else |
| 13806 |
{ |
| 13807 |
output_operand_lossage ("invalid operand type used with " |
| 13808 |
"operand code '%c'", code); |
| 13809 |
return; |
| 13810 |
} |
| 13811 |
|
| 13812 |
output_operand_lossage ("invalid operand size for operand code '%c'", |
| 13813 |
code); |
| 13814 |
return; |
| 13815 |
|
| 13816 |
case 'd': |
| 13817 |
case 'b': |
| 13818 |
case 'w': |
| 13819 |
case 'k': |
| 13820 |
case 'q': |
| 13821 |
case 'h': |
| 13822 |
case 't': |
| 13823 |
case 'g': |
| 13824 |
case 'y': |
| 13825 |
case 'x': |
| 13826 |
case 'X': |
| 13827 |
case 'P': |
| 13828 |
case 'p': |
| 13829 |
case 'V': |
| 13830 |
break; |
| 13831 |
|
| 13832 |
case 's': |
| 13833 |
if (CONST_INT_P (x) || ! SHIFT_DOUBLE_OMITS_COUNT) |
| 13834 |
{ |
| 13835 |
ix86_print_operand (file, x, 0); |
| 13836 |
fputs (", ", file); |
| 13837 |
} |
| 13838 |
return; |
| 13839 |
|
| 13840 |
case 'Y': |
| 13841 |
switch (GET_CODE (x)) |
| 13842 |
{ |
| 13843 |
case NE: |
| 13844 |
fputs ("neq", file); |
| 13845 |
break; |
| 13846 |
case EQ: |
| 13847 |
fputs ("eq", file); |
| 13848 |
break; |
| 13849 |
case GE: |
| 13850 |
case GEU: |
| 13851 |
fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "ge" : "unlt", file); |
| 13852 |
break; |
| 13853 |
case GT: |
| 13854 |
case GTU: |
| 13855 |
fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "gt" : "unle", file); |
| 13856 |
break; |
| 13857 |
case LE: |
| 13858 |
case LEU: |
| 13859 |
fputs ("le", file); |
| 13860 |
break; |
| 13861 |
case LT: |
| 13862 |
case LTU: |
| 13863 |
fputs ("lt", file); |
| 13864 |
break; |
| 13865 |
case UNORDERED: |
| 13866 |
fputs ("unord", file); |
| 13867 |
break; |
| 13868 |
case ORDERED: |
| 13869 |
fputs ("ord", file); |
| 13870 |
break; |
| 13871 |
case UNEQ: |
| 13872 |
fputs ("ueq", file); |
| 13873 |
break; |
| 13874 |
case UNGE: |
| 13875 |
fputs ("nlt", file); |
| 13876 |
break; |
| 13877 |
case UNGT: |
| 13878 |
fputs ("nle", file); |
| 13879 |
break; |
| 13880 |
case UNLE: |
| 13881 |
fputs ("ule", file); |
| 13882 |
break; |
| 13883 |
case UNLT: |
| 13884 |
fputs ("ult", file); |
| 13885 |
break; |
| 13886 |
case LTGT: |
| 13887 |
fputs ("une", file); |
| 13888 |
break; |
| 13889 |
default: |
| 13890 |
output_operand_lossage ("operand is not a condition code, " |
| 13891 |
"invalid operand code 'Y'"); |
| 13892 |
return; |
| 13893 |
} |
| 13894 |
return; |
| 13895 |
|
| 13896 |
case 'D': |
| 13897 |
/* Little bit of braindamage here. The SSE compare instructions |
| 13898 |
does use completely different names for the comparisons that the |
| 13899 |
fp conditional moves. */ |
| 13900 |
switch (GET_CODE (x)) |
| 13901 |
{ |
| 13902 |
case UNEQ: |
| 13903 |
if (TARGET_AVX) |
| 13904 |
{ |
| 13905 |
fputs ("eq_us", file); |
| 13906 |
break; |
| 13907 |
} |
| 13908 |
/* FALLTHRU */ |
| 13909 |
case EQ: |
| 13910 |
fputs ("eq", file); |
| 13911 |
break; |
| 13912 |
case UNLT: |
| 13913 |
if (TARGET_AVX) |
| 13914 |
{ |
| 13915 |
fputs ("nge", file); |
| 13916 |
break; |
| 13917 |
} |
| 13918 |
/* FALLTHRU */ |
| 13919 |
case LT: |
| 13920 |
fputs ("lt", file); |
| 13921 |
break; |
| 13922 |
case UNLE: |
| 13923 |
if (TARGET_AVX) |
| 13924 |
{ |
| 13925 |
fputs ("ngt", file); |
| 13926 |
break; |
| 13927 |
} |
| 13928 |
/* FALLTHRU */ |
| 13929 |
case LE: |
| 13930 |
fputs ("le", file); |
| 13931 |
break; |
| 13932 |
case UNORDERED: |
| 13933 |
fputs ("unord", file); |
| 13934 |
break; |
| 13935 |
case LTGT: |
| 13936 |
if (TARGET_AVX) |
| 13937 |
{ |
| 13938 |
fputs ("neq_oq", file); |
| 13939 |
break; |
| 13940 |
} |
| 13941 |
/* FALLTHRU */ |
| 13942 |
case NE: |
| 13943 |
fputs ("neq", file); |
| 13944 |
break; |
| 13945 |
case GE: |
| 13946 |
if (TARGET_AVX) |
| 13947 |
{ |
| 13948 |
fputs ("ge", file); |
| 13949 |
break; |
| 13950 |
} |
| 13951 |
/* FALLTHRU */ |
| 13952 |
case UNGE: |
| 13953 |
fputs ("nlt", file); |
| 13954 |
break; |
| 13955 |
case GT: |
| 13956 |
if (TARGET_AVX) |
| 13957 |
{ |
| 13958 |
fputs ("gt", file); |
| 13959 |
break; |
| 13960 |
} |
| 13961 |
/* FALLTHRU */ |
| 13962 |
case UNGT: |
| 13963 |
fputs ("nle", file); |
| 13964 |
break; |
| 13965 |
case ORDERED: |
| 13966 |
fputs ("ord", file); |
| 13967 |
break; |
| 13968 |
default: |
| 13969 |
output_operand_lossage ("operand is not a condition code, " |
| 13970 |
"invalid operand code 'D'"); |
| 13971 |
return; |
| 13972 |
} |
| 13973 |
return; |
| 13974 |
|
| 13975 |
case 'F': |
| 13976 |
case 'f': |
| 13977 |
#ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX |
| 13978 |
if (ASSEMBLER_DIALECT == ASM_ATT) |
| 13979 |
putc ('.', file); |
| 13980 |
gcc_fallthrough (); |
| 13981 |
#endif |
| 13982 |
|
| 13983 |
case 'C': |
| 13984 |
case 'c': |
| 13985 |
if (!COMPARISON_P (x)) |
| 13986 |
{ |
| 13987 |
output_operand_lossage ("operand is not a condition code, " |
| 13988 |
"invalid operand code '%c'", code); |
| 13989 |
return; |
| 13990 |
} |
| 13991 |
put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), |
| 13992 |
code == 'c' || code == 'f', |
| 13993 |
code == 'F' || code == 'f', |
| 13994 |
file); |
| 13995 |
return; |
| 13996 |
|
| 13997 |
case 'G': |
| 13998 |
{ |
| 13999 |
int dfv = INTVAL (x); |
| 14000 |
const char *dfv_suffix = ix86_ccmp_dfv_mapping[dfv]; |
| 14001 |
fputs (dfv_suffix, file); |
| 14002 |
} |
| 14003 |
return; |
| 14004 |
|
| 14005 |
case 'H': |
| 14006 |
if (!offsettable_memref_p (x)) |
| 14007 |
{ |
| 14008 |
output_operand_lossage ("operand is not an offsettable memory " |
| 14009 |
"reference, invalid operand code 'H'"); |
| 14010 |
return; |
| 14011 |
} |
| 14012 |
/* It doesn't actually matter what mode we use here, as we're |
| 14013 |
only going to use this for printing. */ |
| 14014 |
x = adjust_address_nv (x, DImode, 8); |
| 14015 |
/* Output 'qword ptr' for intel assembler dialect. */ |
| 14016 |
if (ASSEMBLER_DIALECT == ASM_INTEL) |
| 14017 |
code = 'q'; |
| 14018 |
break; |
| 14019 |
|
| 14020 |
case 'K': |
| 14021 |
if (!CONST_INT_P (x)) |
| 14022 |
{ |
| 14023 |
output_operand_lossage ("operand is not an integer, invalid " |
| 14024 |
"operand code 'K'"); |
| 14025 |
return; |
| 14026 |
} |
| 14027 |
|
| 14028 |
if (INTVAL (x) & IX86_HLE_ACQUIRE) |
| 14029 |
#ifdef HAVE_AS_IX86_HLE |
| 14030 |
fputs ("xacquire ", file); |
| 14031 |
#else |
| 14032 |
fputs ("\n" ASM_BYTE "0xf2\n\t", file); |
| 14033 |
#endif |
| 14034 |
else if (INTVAL (x) & IX86_HLE_RELEASE) |
| 14035 |
#ifdef HAVE_AS_IX86_HLE |
| 14036 |
fputs ("xrelease ", file); |
| 14037 |
#else |
| 14038 |
fputs ("\n" ASM_BYTE "0xf3\n\t", file); |
| 14039 |
#endif |
| 14040 |
/* We do not want to print value of the operand. */ |
| 14041 |
return; |
| 14042 |
|
| 14043 |
case 'N': |
| 14044 |
if (x == const0_rtx || x == CONST0_RTX (GET_MODE (x))) |
| 14045 |
fputs ("{z}", file); |
| 14046 |
return; |
| 14047 |
|
| 14048 |
case 'r': |
| 14049 |
if (!CONST_INT_P (x) || INTVAL (x) != ROUND_SAE) |
| 14050 |
{ |
| 14051 |
output_operand_lossage ("operand is not a specific integer, " |
| 14052 |
"invalid operand code 'r'"); |
| 14053 |
return; |
| 14054 |
} |
| 14055 |
|
| 14056 |
if (ASSEMBLER_DIALECT == ASM_INTEL) |
| 14057 |
fputs (", ", file); |
| 14058 |
|
| 14059 |
fputs ("{sae}", file); |
| 14060 |
|
| 14061 |
if (ASSEMBLER_DIALECT == ASM_ATT) |
| 14062 |
fputs (", ", file); |
| 14063 |
|
| 14064 |
return; |
| 14065 |
|
| 14066 |
case 'R': |
| 14067 |
if (!CONST_INT_P (x)) |
| 14068 |
{ |
| 14069 |
output_operand_lossage ("operand is not an integer, invalid " |
| 14070 |
"operand code 'R'"); |
| 14071 |
return; |
| 14072 |
} |
| 14073 |
|
| 14074 |
if (ASSEMBLER_DIALECT == ASM_INTEL) |
| 14075 |
fputs (", ", file); |
| 14076 |
|
| 14077 |
switch (INTVAL (x)) |
| 14078 |
{ |
| 14079 |
case ROUND_NEAREST_INT | ROUND_SAE: |
| 14080 |
fputs ("{rn-sae}", file); |
| 14081 |
break; |
| 14082 |
case ROUND_NEG_INF | ROUND_SAE: |
| 14083 |
fputs ("{rd-sae}", file); |
| 14084 |
break; |
| 14085 |
case ROUND_POS_INF | ROUND_SAE: |
| 14086 |
fputs ("{ru-sae}", file); |
| 14087 |
break; |
| 14088 |
case ROUND_ZERO | ROUND_SAE: |
| 14089 |
fputs ("{rz-sae}", file); |
| 14090 |
break; |
| 14091 |
default: |
| 14092 |
output_operand_lossage ("operand is not a specific integer, " |
| 14093 |
"invalid operand code 'R'"); |
| 14094 |
} |
| 14095 |
|
| 14096 |
if (ASSEMBLER_DIALECT == ASM_ATT) |
| 14097 |
fputs (", ", file); |
| 14098 |
|
| 14099 |
return; |
| 14100 |
|
| 14101 |
case '*': |
| 14102 |
if (ASSEMBLER_DIALECT == ASM_ATT) |
| 14103 |
putc ('*', file); |
| 14104 |
return; |
| 14105 |
|
| 14106 |
case '&': |
| 14107 |
{ |
| 14108 |
const char *name = get_some_local_dynamic_name (); |
| 14109 |
if (name == NULL) |
| 14110 |
output_operand_lossage ("'%%&' used without any " |
| 14111 |
"local dynamic TLS references"); |
| 14112 |
else |
| 14113 |
assemble_name (file, name); |
| 14114 |
return; |
| 14115 |
} |
| 14116 |
|
| 14117 |
case '+': |
| 14118 |
{ |
| 14119 |
rtx x; |
| 14120 |
|
| 14121 |
if (!optimize |
| 14122 |
|| optimize_function_for_size_p (cfun) |
| 14123 |
|| (!TARGET_BRANCH_PREDICTION_HINTS_NOT_TAKEN |
| 14124 |
&& !TARGET_BRANCH_PREDICTION_HINTS_TAKEN)) |
| 14125 |
return; |
| 14126 |
|
| 14127 |
x = find_reg_note (current_output_insn, REG_BR_PROB, 0); |
| 14128 |
if (x) |
| 14129 |
{ |
| 14130 |
int pred_val = profile_probability::from_reg_br_prob_note |
| 14131 |
(XINT (x, 0)).to_reg_br_prob_base (); |
| 14132 |
|
| 14133 |
bool taken = pred_val > REG_BR_PROB_BASE / 2; |
| 14134 |
/* We use 3e (DS) prefix for taken branches and |
| 14135 |
2e (CS) prefix for not taken branches. */ |
| 14136 |
if (taken && TARGET_BRANCH_PREDICTION_HINTS_TAKEN) |
| 14137 |
fputs ("ds ; ", file); |
| 14138 |
else if (!taken && TARGET_BRANCH_PREDICTION_HINTS_NOT_TAKEN) |
| 14139 |
fputs ("cs ; ", file); |
| 14140 |
} |
| 14141 |
return; |
| 14142 |
} |
| 14143 |
|
| 14144 |
case ';': |
| 14145 |
#ifndef HAVE_AS_IX86_REP_LOCK_PREFIX |
| 14146 |
putc (';', file); |
| 14147 |
#endif |
| 14148 |
return; |
| 14149 |
|
| 14150 |
case '~': |
| 14151 |
putc (TARGET_AVX2 ? 'i' : 'f', file); |
| 14152 |
return; |
| 14153 |
|
| 14154 |
case 'M': |
| 14155 |
if (TARGET_X32) |
| 14156 |
{ |
| 14157 |
/* NB: 32-bit indices in VSIB address are sign-extended |
| 14158 |
to 64 bits. In x32, if 32-bit address 0xf7fa3010 is |
| 14159 |
sign-extended to 0xfffffffff7fa3010 which is invalid |
| 14160 |
address. Add addr32 prefix if there is no base |
| 14161 |
register nor symbol. */ |
| 14162 |
bool ok; |
| 14163 |
struct ix86_address parts; |
| 14164 |
ok = ix86_decompose_address (x, &parts); |
| 14165 |
gcc_assert (ok && parts.index == NULL_RTX); |
| 14166 |
if (parts.base == NULL_RTX |
| 14167 |
&& (parts.disp == NULL_RTX |
| 14168 |
|| !symbolic_operand (parts.disp, |
| 14169 |
GET_MODE (parts.disp)))) |
| 14170 |
fputs ("addr32 ", file); |
| 14171 |
} |
| 14172 |
return; |
| 14173 |
|
| 14174 |
case '^': |
| 14175 |
if (TARGET_64BIT && Pmode != word_mode) |
| 14176 |
fputs ("addr32 ", file); |
| 14177 |
return; |
| 14178 |
|
| 14179 |
case '!': |
| 14180 |
if (ix86_notrack_prefixed_insn_p (current_output_insn)) |
| 14181 |
fputs ("notrack ", file); |
| 14182 |
return; |
| 14183 |
|
| 14184 |
default: |
| 14185 |
output_operand_lossage ("invalid operand code '%c'", code); |
| 14186 |
} |
| 14187 |
} |
| 14188 |
|
| 14189 |
if (REG_P (x)) |
| 14190 |
print_reg (x, code, file); |
| 14191 |
|
| 14192 |
else if (MEM_P (x)) |
| 14193 |
{ |
| 14194 |
rtx addr = XEXP (x, 0); |
| 14195 |
|
| 14196 |
/* No `byte ptr' prefix for call instructions ... */ |
| 14197 |
if (ASSEMBLER_DIALECT == ASM_INTEL && code != 'X' && code != 'P') |
| 14198 |
{ |
| 14199 |
machine_mode mode = GET_MODE (x); |
| 14200 |
const char *size; |
| 14201 |
|
| 14202 |
/* Check for explicit size override codes. */ |
| 14203 |
if (code == 'b') |
| 14204 |
size = "BYTE"; |
| 14205 |
else if (code == 'w') |
| 14206 |
size = "WORD"; |
| 14207 |
else if (code == 'k') |
| 14208 |
size = "DWORD"; |
| 14209 |
else if (code == 'q') |
| 14210 |
size = "QWORD"; |
| 14211 |
else if (code == 'x') |
| 14212 |
size = "XMMWORD"; |
| 14213 |
else if (code == 't') |
| 14214 |
size = "YMMWORD"; |
| 14215 |
else if (code == 'g') |
| 14216 |
size = "ZMMWORD"; |
| 14217 |
else if (mode == BLKmode) |
| 14218 |
/* ... or BLKmode operands, when not overridden. */ |
| 14219 |
size = NULL; |
| 14220 |
else |
| 14221 |
switch (GET_MODE_SIZE (mode)) |
| 14222 |
{ |
| 14223 |
case 1: size = "BYTE"; break; |
| 14224 |
case 2: size = "WORD"; break; |
| 14225 |
case 4: size = "DWORD"; break; |
| 14226 |
case 8: size = "QWORD"; break; |
| 14227 |
case 12: size = "TBYTE"; break; |
| 14228 |
case 16: |
| 14229 |
if (mode == XFmode) |
| 14230 |
size = "TBYTE"; |
| 14231 |
else |
| 14232 |
size = "XMMWORD"; |
| 14233 |
break; |
| 14234 |
case 32: size = "YMMWORD"; break; |
| 14235 |
case 64: size = "ZMMWORD"; break; |
| 14236 |
default: |
| 14237 |
gcc_unreachable (); |
| 14238 |
} |
| 14239 |
if (size) |
| 14240 |
{ |
| 14241 |
fputs (size, file); |
| 14242 |
fputs (" PTR ", file); |
| 14243 |
} |
| 14244 |
} |
| 14245 |
|
| 14246 |
if (this_is_asm_operands && ! address_operand (addr, VOIDmode)) |
| 14247 |
output_operand_lossage ("invalid constraints for operand"); |
| 14248 |
else |
| 14249 |
ix86_print_operand_address_as |
| 14250 |
(file, addr, MEM_ADDR_SPACE (x), code == 'p' || code == 'P'); |
| 14251 |
} |
| 14252 |
|
| 14253 |
else if (CONST_DOUBLE_P (x) && GET_MODE (x) == HFmode) |
| 14254 |
{ |
| 14255 |
long l = real_to_target (NULL, CONST_DOUBLE_REAL_VALUE (x), |
| 14256 |
REAL_MODE_FORMAT (HFmode)); |
| 14257 |
if (ASSEMBLER_DIALECT == ASM_ATT) |
| 14258 |
putc ('$', file); |
| 14259 |
fprintf (file, "0x%04x", (unsigned int) l); |
| 14260 |
} |
| 14261 |
|
| 14262 |
else if (CONST_DOUBLE_P (x) && GET_MODE (x) == SFmode) |
| 14263 |
{ |
| 14264 |
long l; |
| 14265 |
|
| 14266 |
REAL_VALUE_TO_TARGET_SINGLE (*CONST_DOUBLE_REAL_VALUE (x), l); |
| 14267 |
|
| 14268 |
if (ASSEMBLER_DIALECT == ASM_ATT) |
| 14269 |
putc ('$', file); |
| 14270 |
/* Sign extend 32bit SFmode immediate to 8 bytes. */ |
| 14271 |
if (code == 'q') |
| 14272 |
fprintf (file, "0x%08" HOST_LONG_LONG_FORMAT "x", |
| 14273 |
(unsigned long long) (int) l); |
| 14274 |
else |
| 14275 |
fprintf (file, "0x%08x", (unsigned int) l); |
| 14276 |
} |
| 14277 |
|
| 14278 |
else if (CONST_DOUBLE_P (x) && GET_MODE (x) == DFmode) |
| 14279 |
{ |
| 14280 |
long l[2]; |
| 14281 |
|
| 14282 |
REAL_VALUE_TO_TARGET_DOUBLE (*CONST_DOUBLE_REAL_VALUE (x), l); |
| 14283 |
|
| 14284 |
if (ASSEMBLER_DIALECT == ASM_ATT) |
| 14285 |
putc ('$', file); |
| 14286 |
fprintf (file, "0x%lx%08lx", l[1] & 0xffffffff, l[0] & 0xffffffff); |
| 14287 |
} |
| 14288 |
|
| 14289 |
/* These float cases don't actually occur as immediate operands. */ |
| 14290 |
else if (CONST_DOUBLE_P (x) && GET_MODE (x) == XFmode) |
| 14291 |
{ |
| 14292 |
char dstr[30]; |
| 14293 |
|
| 14294 |
real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (x), sizeof (dstr), 0, 1); |
| 14295 |
fputs (dstr, file); |
| 14296 |
} |
| 14297 |
|
| 14298 |
/* Print bcst_mem_operand. */ |
| 14299 |
else if (GET_CODE (x) == VEC_DUPLICATE) |
| 14300 |
{ |
| 14301 |
machine_mode vmode = GET_MODE (x); |
| 14302 |
/* Must be bcst_memory_operand. */ |
| 14303 |
gcc_assert (bcst_mem_operand (x, vmode)); |
| 14304 |
|
| 14305 |
rtx mem = XEXP (x,0); |
| 14306 |
ix86_print_operand (file, mem, 0); |
| 14307 |
|
| 14308 |
switch (vmode) |
| 14309 |
{ |
| 14310 |
case E_V2DImode: |
| 14311 |
case E_V2DFmode: |
| 14312 |
fputs ("{1to2}", file); |
| 14313 |
break; |
| 14314 |
case E_V4SImode: |
| 14315 |
case E_V4SFmode: |
| 14316 |
case E_V4DImode: |
| 14317 |
case E_V4DFmode: |
| 14318 |
fputs ("{1to4}", file); |
| 14319 |
break; |
| 14320 |
case E_V8SImode: |
| 14321 |
case E_V8SFmode: |
| 14322 |
case E_V8DFmode: |
| 14323 |
case E_V8DImode: |
| 14324 |
case E_V8HFmode: |
| 14325 |
fputs ("{1to8}", file); |
| 14326 |
break; |
| 14327 |
case E_V16SFmode: |
| 14328 |
case E_V16SImode: |
| 14329 |
case E_V16HFmode: |
| 14330 |
fputs ("{1to16}", file); |
| 14331 |
break; |
| 14332 |
case E_V32HFmode: |
| 14333 |
fputs ("{1to32}", file); |
| 14334 |
break; |
| 14335 |
default: |
| 14336 |
gcc_unreachable (); |
| 14337 |
} |
| 14338 |
} |
| 14339 |
|
| 14340 |
else |
| 14341 |
{ |
| 14342 |
/* We have patterns that allow zero sets of memory, for instance. |
| 14343 |
In 64-bit mode, we should probably support all 8-byte vectors, |
| 14344 |
since we can in fact encode that into an immediate. */ |
| 14345 |
if (GET_CODE (x) == CONST_VECTOR) |
| 14346 |
{ |
| 14347 |
if (x != CONST0_RTX (GET_MODE (x))) |
| 14348 |
output_operand_lossage ("invalid vector immediate"); |
| 14349 |
x = const0_rtx; |
| 14350 |
} |
| 14351 |
|
| 14352 |
if (code == 'P') |
| 14353 |
{ |
| 14354 |
if (ix86_force_load_from_GOT_p (x, true)) |
| 14355 |
{ |
| 14356 |
/* For inline assembly statement, load function address |
| 14357 |
from GOT with 'P' operand modifier to avoid PLT. */ |
| 14358 |
x = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), |
| 14359 |
(TARGET_64BIT |
| 14360 |
? UNSPEC_GOTPCREL |
| 14361 |
: UNSPEC_GOT)); |
| 14362 |
x = gen_rtx_CONST (Pmode, x); |
| 14363 |
x = gen_const_mem (Pmode, x); |
| 14364 |
ix86_print_operand (file, x, 'A'); |
| 14365 |
return; |
| 14366 |
} |
| 14367 |
} |
| 14368 |
else if (code != 'p') |
| 14369 |
{ |
| 14370 |
if (CONST_INT_P (x)) |
| 14371 |
{ |
| 14372 |
if (ASSEMBLER_DIALECT == ASM_ATT) |
| 14373 |
putc ('$', file); |
| 14374 |
} |
| 14375 |
else if (GET_CODE (x) == CONST || GET_CODE (x) == SYMBOL_REF |
| 14376 |
|| GET_CODE (x) == LABEL_REF) |
| 14377 |
{ |
| 14378 |
if (ASSEMBLER_DIALECT == ASM_ATT) |
| 14379 |
putc ('$', file); |
| 14380 |
else |
| 14381 |
fputs ("OFFSET FLAT:", file); |
| 14382 |
} |
| 14383 |
} |
| 14384 |
if (CONST_INT_P (x)) |
| 14385 |
fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x)); |
| 14386 |
else if (flag_pic || MACHOPIC_INDIRECT) |
| 14387 |
output_pic_addr_const (file, x, code); |
| 14388 |
else |
| 14389 |
output_addr_const (file, x); |
| 14390 |
} |
| 14391 |
} |
| 14392 |
|
| 14393 |
static bool |
| 14394 |
ix86_print_operand_punct_valid_p (unsigned char code) |
| 14395 |
{ |
| 14396 |
return (code == '*' || code == '+' || code == '&' || code == ';' |
| 14397 |
|| code == '~' || code == '^' || code == '!'); |
| 14398 |
} |
| 14399 |
|
| 14400 |
/* Print a memory operand whose address is ADDR. */ |
| 14401 |
|
| 14402 |
static void |
| 14403 |
ix86_print_operand_address_as (FILE *file, rtx addr, |
| 14404 |
addr_space_t as, bool raw) |
| 14405 |
{ |
| 14406 |
struct ix86_address parts; |
| 14407 |
rtx base, index, disp; |
| 14408 |
int scale; |
| 14409 |
int ok; |
| 14410 |
bool vsib = false; |
| 14411 |
int code = 0; |
| 14412 |
|
| 14413 |
if (GET_CODE (addr) == UNSPEC && XINT (addr, 1) == UNSPEC_VSIBADDR) |
| 14414 |
{ |
| 14415 |
ok = ix86_decompose_address (XVECEXP (addr, 0, 0), &parts); |
| 14416 |
gcc_assert (parts.index == NULL_RTX); |
| 14417 |
parts.index = XVECEXP (addr, 0, 1); |
| 14418 |
parts.scale = INTVAL (XVECEXP (addr, 0, 2)); |
| 14419 |
addr = XVECEXP (addr, 0, 0); |
| 14420 |
vsib = true; |
| 14421 |
} |
| 14422 |
else if (GET_CODE (addr) == UNSPEC && XINT (addr, 1) == UNSPEC_LEA_ADDR) |
| 14423 |
{ |
| 14424 |
gcc_assert (TARGET_64BIT); |
| 14425 |
ok = ix86_decompose_address (XVECEXP (addr, 0, 0), &parts); |
| 14426 |
code = 'q'; |
| 14427 |
} |
| 14428 |
else |
| 14429 |
ok = ix86_decompose_address (addr, &parts); |
| 14430 |
|
| 14431 |
gcc_assert (ok); |
| 14432 |
|
| 14433 |
base = parts.base; |
| 14434 |
index = parts.index; |
| 14435 |
disp = parts.disp; |
| 14436 |
scale = parts.scale; |
| 14437 |
|
| 14438 |
if (ADDR_SPACE_GENERIC_P (as)) |
| 14439 |
as = parts.seg; |
| 14440 |
else |
| 14441 |
gcc_assert (ADDR_SPACE_GENERIC_P (parts.seg)); |
| 14442 |
|
| 14443 |
if (!ADDR_SPACE_GENERIC_P (as) && !raw) |
| 14444 |
{ |
| 14445 |
if (ASSEMBLER_DIALECT == ASM_ATT) |
| 14446 |
putc ('%', file); |
| 14447 |
|
| 14448 |
switch (as) |
| 14449 |
{ |
| 14450 |
case ADDR_SPACE_SEG_FS: |
| 14451 |
fputs ("fs:", file); |
| 14452 |
break; |
| 14453 |
case ADDR_SPACE_SEG_GS: |
| 14454 |
fputs ("gs:", file); |
| 14455 |
break; |
| 14456 |
default: |
| 14457 |
gcc_unreachable (); |
| 14458 |
} |
| 14459 |
} |
| 14460 |
|
| 14461 |
/* Use one byte shorter RIP relative addressing for 64bit mode. */ |
| 14462 |
if (TARGET_64BIT && !base && !index && !raw) |
| 14463 |
{ |
| 14464 |
rtx symbol = disp; |
| 14465 |
|
| 14466 |
if (GET_CODE (disp) == CONST |
| 14467 |
&& GET_CODE (XEXP (disp, 0)) == PLUS |
| 14468 |
&& CONST_INT_P (XEXP (XEXP (disp, 0), 1))) |
| 14469 |
symbol = XEXP (XEXP (disp, 0), 0); |
| 14470 |
|
| 14471 |
if (GET_CODE (symbol) == LABEL_REF |
| 14472 |
|| (GET_CODE (symbol) == SYMBOL_REF |
| 14473 |
&& SYMBOL_REF_TLS_MODEL (symbol) == 0)) |
| 14474 |
base = pc_rtx; |
| 14475 |
} |
| 14476 |
|
| 14477 |
if (!base && !index) |
| 14478 |
{ |
| 14479 |
/* Displacement only requires special attention. */ |
| 14480 |
if (CONST_INT_P (disp)) |
| 14481 |
{ |
| 14482 |
if (ASSEMBLER_DIALECT == ASM_INTEL && ADDR_SPACE_GENERIC_P (as)) |
| 14483 |
fputs ("ds:", file); |
| 14484 |
fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (disp)); |
| 14485 |
} |
| 14486 |
/* Load the external function address via the GOT slot to avoid PLT. */ |
| 14487 |
else if (GET_CODE (disp) == CONST |
| 14488 |
&& GET_CODE (XEXP (disp, 0)) == UNSPEC |
| 14489 |
&& (XINT (XEXP (disp, 0), 1) == UNSPEC_GOTPCREL |
| 14490 |
|| XINT (XEXP (disp, 0), 1) == UNSPEC_GOT) |
| 14491 |
&& ix86_force_load_from_GOT_p (XVECEXP (XEXP (disp, 0), 0, 0))) |
| 14492 |
output_pic_addr_const (file, disp, 0); |
| 14493 |
else if (flag_pic) |
| 14494 |
output_pic_addr_const (file, disp, 0); |
| 14495 |
else |
| 14496 |
output_addr_const (file, disp); |
| 14497 |
} |
| 14498 |
else |
| 14499 |
{ |
| 14500 |
/* Print SImode register names to force addr32 prefix. */ |
| 14501 |
if (SImode_address_operand (addr, VOIDmode)) |
| 14502 |
{ |
| 14503 |
if (flag_checking) |
| 14504 |
{ |
| 14505 |
gcc_assert (TARGET_64BIT); |
| 14506 |
switch (GET_CODE (addr)) |
| 14507 |
{ |
| 14508 |
case SUBREG: |
| 14509 |
gcc_assert (GET_MODE (addr) == SImode); |
| 14510 |
gcc_assert (GET_MODE (SUBREG_REG (addr)) == DImode); |
| 14511 |
break; |
| 14512 |
case ZERO_EXTEND: |
| 14513 |
case AND: |
| 14514 |
gcc_assert (GET_MODE (addr) == DImode); |
| 14515 |
break; |
| 14516 |
default: |
| 14517 |
gcc_unreachable (); |
| 14518 |
} |
| 14519 |
} |
| 14520 |
gcc_assert (!code); |
| 14521 |
code = 'k'; |
| 14522 |
} |
| 14523 |
else if (code == 0 |
| 14524 |
&& TARGET_X32 |
| 14525 |
&& disp |
| 14526 |
&& CONST_INT_P (disp) |
| 14527 |
&& INTVAL (disp) < -16*1024*1024) |
| 14528 |
{ |
| 14529 |
/* X32 runs in 64-bit mode, where displacement, DISP, in |
| 14530 |
address DISP(%r64), is encoded as 32-bit immediate sign- |
| 14531 |
extended from 32-bit to 64-bit. For -0x40000300(%r64), |
| 14532 |
address is %r64 + 0xffffffffbffffd00. When %r64 < |
| 14533 |
0x40000300, like 0x37ffe064, address is 0xfffffffff7ffdd64, |
| 14534 |
which is invalid for x32. The correct address is %r64 |
| 14535 |
- 0x40000300 == 0xf7ffdd64. To properly encode |
| 14536 |
-0x40000300(%r64) for x32, we zero-extend negative |
| 14537 |
displacement by forcing addr32 prefix which truncates |
| 14538 |
0xfffffffff7ffdd64 to 0xf7ffdd64. In theory, we should |
| 14539 |
zero-extend all negative displacements, including -1(%rsp). |
| 14540 |
However, for small negative displacements, sign-extension |
| 14541 |
won't cause overflow. We only zero-extend negative |
| 14542 |
displacements if they < -16*1024*1024, which is also used |
| 14543 |
to check legitimate address displacements for PIC. */ |
| 14544 |
code = 'k'; |
| 14545 |
} |
| 14546 |
|
| 14547 |
/* Since the upper 32 bits of RSP are always zero for x32, |
| 14548 |
we can encode %esp as %rsp to avoid 0x67 prefix if |
| 14549 |
there is no index register. */ |
| 14550 |
if (TARGET_X32 && Pmode == SImode |
| 14551 |
&& !index && base && REG_P (base) && REGNO (base) == SP_REG) |
| 14552 |
code = 'q'; |
| 14553 |
|
| 14554 |
if (ASSEMBLER_DIALECT == ASM_ATT) |
| 14555 |
{ |
| 14556 |
if (disp) |
| 14557 |
{ |
| 14558 |
if (flag_pic) |
| 14559 |
output_pic_addr_const (file, disp, 0); |
| 14560 |
else if (GET_CODE (disp) == LABEL_REF) |
| 14561 |
output_asm_label (disp); |
| 14562 |
else |
| 14563 |
output_addr_const (file, disp); |
| 14564 |
} |
| 14565 |
|
| 14566 |
putc ('(', file); |
| 14567 |
if (base) |
| 14568 |
print_reg (base, code, file); |
| 14569 |
if (index) |
| 14570 |
{ |
| 14571 |
putc (',', file); |
| 14572 |
print_reg (index, vsib ? 0 : code, file); |
| 14573 |
if (scale != 1 || vsib) |
| 14574 |
fprintf (file, ",%d", scale); |
| 14575 |
} |
| 14576 |
putc (')', file); |
| 14577 |
} |
| 14578 |
else |
| 14579 |
{ |
| 14580 |
rtx offset = NULL_RTX; |
| 14581 |
|
| 14582 |
if (disp) |
| 14583 |
{ |
| 14584 |
/* Pull out the offset of a symbol; print any symbol itself. */ |
| 14585 |
if (GET_CODE (disp) == CONST |
| 14586 |
&& GET_CODE (XEXP (disp, 0)) == PLUS |
| 14587 |
&& CONST_INT_P (XEXP (XEXP (disp, 0), 1))) |
| 14588 |
{ |
| 14589 |
offset = XEXP (XEXP (disp, 0), 1); |
| 14590 |
disp = gen_rtx_CONST (VOIDmode, |
| 14591 |
XEXP (XEXP (disp, 0), 0)); |
| 14592 |
} |
| 14593 |
|
| 14594 |
if (flag_pic) |
| 14595 |
output_pic_addr_const (file, disp, 0); |
| 14596 |
else if (GET_CODE (disp) == LABEL_REF) |
| 14597 |
output_asm_label (disp); |
| 14598 |
else if (CONST_INT_P (disp)) |
| 14599 |
offset = disp; |
| 14600 |
else |
| 14601 |
output_addr_const (file, disp); |
| 14602 |
} |
| 14603 |
|
| 14604 |
putc ('[', file); |
| 14605 |
if (base) |
| 14606 |
{ |
| 14607 |
print_reg (base, code, file); |
| 14608 |
if (offset) |
| 14609 |
{ |
| 14610 |
if (INTVAL (offset) >= 0) |
| 14611 |
putc ('+', file); |
| 14612 |
fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset)); |
| 14613 |
} |
| 14614 |
} |
| 14615 |
else if (offset) |
| 14616 |
fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset)); |
| 14617 |
else |
| 14618 |
putc ('0', file); |
| 14619 |
|
| 14620 |
if (index) |
| 14621 |
{ |
| 14622 |
putc ('+', file); |
| 14623 |
print_reg (index, vsib ? 0 : code, file); |
| 14624 |
if (scale != 1 || vsib) |
| 14625 |
fprintf (file, "*%d", scale); |
| 14626 |
} |
| 14627 |
putc (']', file); |
| 14628 |
} |
| 14629 |
} |
| 14630 |
} |
| 14631 |
|
| 14632 |
static void |
| 14633 |
ix86_print_operand_address (FILE *file, machine_mode /*mode*/, rtx addr) |
| 14634 |
{ |
| 14635 |
if (this_is_asm_operands && ! address_operand (addr, VOIDmode)) |
| 14636 |
output_operand_lossage ("invalid constraints for operand"); |
| 14637 |
else |
| 14638 |
ix86_print_operand_address_as (file, addr, ADDR_SPACE_GENERIC, false); |
| 14639 |
} |
| 14640 |
|
| 14641 |
/* Implementation of TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA. */ |
| 14642 |
|
| 14643 |
static bool |
| 14644 |
i386_asm_output_addr_const_extra (FILE *file, rtx x) |
| 14645 |
{ |
| 14646 |
rtx op; |
| 14647 |
|
| 14648 |
if (GET_CODE (x) != UNSPEC) |
| 14649 |
return false; |
| 14650 |
|
| 14651 |
op = XVECEXP (x, 0, 0); |
| 14652 |
switch (XINT (x, 1)) |
| 14653 |
{ |
| 14654 |
case UNSPEC_GOTOFF: |
| 14655 |
output_addr_const (file, op); |
| 14656 |
fputs ("@gotoff", file); |
| 14657 |
break; |
| 14658 |
case UNSPEC_GOTTPOFF: |
| 14659 |
output_addr_const (file, op); |
| 14660 |
/* FIXME: This might be @TPOFF in Sun ld. */ |
| 14661 |
fputs ("@gottpoff", file); |
| 14662 |
break; |
| 14663 |
case UNSPEC_TPOFF: |
| 14664 |
output_addr_const (file, op); |
| 14665 |
fputs ("@tpoff", file); |
| 14666 |
break; |
| 14667 |
case UNSPEC_NTPOFF: |
| 14668 |
output_addr_const (file, op); |
| 14669 |
if (TARGET_64BIT) |
| 14670 |
fputs ("@tpoff", file); |
| 14671 |
else |
| 14672 |
fputs ("@ntpoff", file); |
| 14673 |
break; |
| 14674 |
case UNSPEC_DTPOFF: |
| 14675 |
output_addr_const (file, op); |
| 14676 |
fputs ("@dtpoff", file); |
| 14677 |
break; |
| 14678 |
case UNSPEC_GOTNTPOFF: |
| 14679 |
output_addr_const (file, op); |
| 14680 |
if (TARGET_64BIT) |
| 14681 |
fputs (ASSEMBLER_DIALECT == ASM_ATT ? |
| 14682 |
"@gottpoff(%rip)" : "@gottpoff[rip]", file); |
| 14683 |
else |
| 14684 |
fputs ("@gotntpoff", file); |
| 14685 |
break; |
| 14686 |
case UNSPEC_INDNTPOFF: |
| 14687 |
output_addr_const (file, op); |
| 14688 |
fputs ("@indntpoff", file); |
| 14689 |
break; |
| 14690 |
#if TARGET_MACHO |
| 14691 |
case UNSPEC_MACHOPIC_OFFSET: |
| 14692 |
output_addr_const (file, op); |
| 14693 |
putc ('-', file); |
| 14694 |
machopic_output_function_base_name (file); |
| 14695 |
break; |
| 14696 |
#endif |
| 14697 |
|
| 14698 |
default: |
| 14699 |
return false; |
| 14700 |
} |
| 14701 |
|
| 14702 |
return true; |
| 14703 |
} |
| 14704 |
|
| 14705 |
|
| 14706 |
/* Output code to perform a 387 binary operation in INSN, one of PLUS, |
| 14707 |
MINUS, MULT or DIV. OPERANDS are the insn operands, where operands[3] |
| 14708 |
is the expression of the binary operation. The output may either be |
| 14709 |
emitted here, or returned to the caller, like all output_* functions. |
| 14710 |
|
| 14711 |
There is no guarantee that the operands are the same mode, as they |
| 14712 |
might be within FLOAT or FLOAT_EXTEND expressions. */ |
| 14713 |
|
| 14714 |
#ifndef SYSV386_COMPAT |
| 14715 |
/* Set to 1 for compatibility with brain-damaged assemblers. No-one |
| 14716 |
wants to fix the assemblers because that causes incompatibility |
| 14717 |
with gcc. No-one wants to fix gcc because that causes |
| 14718 |
incompatibility with assemblers... You can use the option of |
| 14719 |
-DSYSV386_COMPAT=0 if you recompile both gcc and gas this way. */ |
| 14720 |
#define SYSV386_COMPAT 1 |
| 14721 |
#endif |
| 14722 |
|
| 14723 |
const char * |
| 14724 |
output_387_binary_op (rtx_insn *insn, rtx *operands) |
| 14725 |
{ |
| 14726 |
static char buf[40]; |
| 14727 |
const char *p; |
| 14728 |
bool is_sse |
| 14729 |
= (SSE_REG_P (operands[0]) |
| 14730 |
|| SSE_REG_P (operands[1]) || SSE_REG_P (operands[2])); |
| 14731 |
|
| 14732 |
if (is_sse) |
| 14733 |
p = "%v"; |
| 14734 |
else if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT |
| 14735 |
|| GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT) |
| 14736 |
p = "fi"; |
| 14737 |
else |
| 14738 |
p = "f"; |
| 14739 |
|
| 14740 |
strcpy (buf, p); |
| 14741 |
|
| 14742 |
switch (GET_CODE (operands[3])) |
| 14743 |
{ |
| 14744 |
case PLUS: |
| 14745 |
p = "add"; break; |
| 14746 |
case MINUS: |
| 14747 |
p = "sub"; break; |
| 14748 |
case MULT: |
| 14749 |
p = "mul"; break; |
| 14750 |
case DIV: |
| 14751 |
p = "div"; break; |
| 14752 |
default: |
| 14753 |
gcc_unreachable (); |
| 14754 |
} |
| 14755 |
|
| 14756 |
strcat (buf, p); |
| 14757 |
|
| 14758 |
if (is_sse) |
| 14759 |
{ |
| 14760 |
p = GET_MODE (operands[0]) == SFmode ? "ss" : "sd"; |
| 14761 |
strcat (buf, p); |
| 14762 |
|
| 14763 |
if (TARGET_AVX) |
| 14764 |
p = "\t{%2, %1, %0|%0, %1, %2}"; |
| 14765 |
else |
| 14766 |
p = "\t{%2, %0|%0, %2}"; |
| 14767 |
|
| 14768 |
strcat (buf, p); |
| 14769 |
return buf; |
| 14770 |
} |
| 14771 |
|
| 14772 |
/* Even if we do not want to check the inputs, this documents input |
| 14773 |
constraints. Which helps in understanding the following code. */ |
| 14774 |
if (flag_checking) |
| 14775 |
{ |
| 14776 |
if (STACK_REG_P (operands[0]) |
| 14777 |
&& ((REG_P (operands[1]) |
| 14778 |
&& REGNO (operands[0]) == REGNO (operands[1]) |
| 14779 |
&& (STACK_REG_P (operands[2]) || MEM_P (operands[2]))) |
| 14780 |
|| (REG_P (operands[2]) |
| 14781 |
&& REGNO (operands[0]) == REGNO (operands[2]) |
| 14782 |
&& (STACK_REG_P (operands[1]) || MEM_P (operands[1])))) |
| 14783 |
&& (STACK_TOP_P (operands[1]) || STACK_TOP_P (operands[2]))) |
| 14784 |
; /* ok */ |
| 14785 |
else |
| 14786 |
gcc_unreachable (); |
| 14787 |
} |
| 14788 |
|
| 14789 |
switch (GET_CODE (operands[3])) |
| 14790 |
{ |
| 14791 |
case MULT: |
| 14792 |
case PLUS: |
| 14793 |
if (REG_P (operands[2]) && REGNO (operands[0]) == REGNO (operands[2])) |
| 14794 |
std::swap (operands[1], operands[2]); |
| 14795 |
|
| 14796 |
/* know operands[0] == operands[1]. */ |
| 14797 |
|
| 14798 |
if (MEM_P (operands[2])) |
| 14799 |
{ |
| 14800 |
p = "%Z2\t%2"; |
| 14801 |
break; |
| 14802 |
} |
| 14803 |
|
| 14804 |
if (find_regno_note (insn, REG_DEAD, REGNO (operands[2]))) |
| 14805 |
{ |
| 14806 |
if (STACK_TOP_P (operands[0])) |
| 14807 |
/* How is it that we are storing to a dead operand[2]? |
| 14808 |
Well, presumably operands[1] is dead too. We can't |
| 14809 |
store the result to st(0) as st(0) gets popped on this |
| 14810 |
instruction. Instead store to operands[2] (which I |
| 14811 |
think has to be st(1)). st(1) will be popped later. |
| 14812 |
gcc <= 2.8.1 didn't have this check and generated |
| 14813 |
assembly code that the Unixware assembler rejected. */ |
| 14814 |
p = "p\t{%0, %2|%2, %0}"; /* st(1) = st(0) op st(1); pop */ |
| 14815 |
else |
| 14816 |
p = "p\t{%2, %0|%0, %2}"; /* st(r1) = st(r1) op st(0); pop */ |
| 14817 |
break; |
| 14818 |
} |
| 14819 |
|
| 14820 |
if (STACK_TOP_P (operands[0])) |
| 14821 |
p = "\t{%y2, %0|%0, %y2}"; /* st(0) = st(0) op st(r2) */ |
| 14822 |
else |
| 14823 |
p = "\t{%2, %0|%0, %2}"; /* st(r1) = st(r1) op st(0) */ |
| 14824 |
break; |
| 14825 |
|
| 14826 |
case MINUS: |
| 14827 |
case DIV: |
| 14828 |
if (MEM_P (operands[1])) |
| 14829 |
{ |
| 14830 |
p = "r%Z1\t%1"; |
| 14831 |
break; |
| 14832 |
} |
| 14833 |
|
| 14834 |
if (MEM_P (operands[2])) |
| 14835 |
{ |
| 14836 |
p = "%Z2\t%2"; |
| 14837 |
break; |
| 14838 |
} |
| 14839 |
|
| 14840 |
if (find_regno_note (insn, REG_DEAD, REGNO (operands[2]))) |
| 14841 |
{ |
| 14842 |
#if SYSV386_COMPAT |
| 14843 |
/* The SystemV/386 SVR3.2 assembler, and probably all AT&T |
| 14844 |
derived assemblers, confusingly reverse the direction of |
| 14845 |
the operation for fsub{r} and fdiv{r} when the |
| 14846 |
destination register is not st(0). The Intel assembler |
| 14847 |
doesn't have this brain damage. Read !SYSV386_COMPAT to |
| 14848 |
figure out what the hardware really does. */ |
| 14849 |
if (STACK_TOP_P (operands[0])) |
| 14850 |
p = "{p\t%0, %2|rp\t%2, %0}"; |
| 14851 |
else |
| 14852 |
p = "{rp\t%2, %0|p\t%0, %2}"; |
| 14853 |
#else |
| 14854 |
if (STACK_TOP_P (operands[0])) |
| 14855 |
/* As above for fmul/fadd, we can't store to st(0). */ |
| 14856 |
p = "rp\t{%0, %2|%2, %0}"; /* st(1) = st(0) op st(1); pop */ |
| 14857 |
else |
| 14858 |
p = "p\t{%2, %0|%0, %2}"; /* st(r1) = st(r1) op st(0); pop */ |
| 14859 |
#endif |
| 14860 |
break; |
| 14861 |
} |
| 14862 |
|
| 14863 |
if (find_regno_note (insn, REG_DEAD, REGNO (operands[1]))) |
| 14864 |
{ |
| 14865 |
#if SYSV386_COMPAT |
| 14866 |
if (STACK_TOP_P (operands[0])) |
| 14867 |
p = "{rp\t%0, %1|p\t%1, %0}"; |
| 14868 |
else |
| 14869 |
p = "{p\t%1, %0|rp\t%0, %1}"; |
| 14870 |
#else |
| 14871 |
if (STACK_TOP_P (operands[0])) |
| 14872 |
p = "p\t{%0, %1|%1, %0}"; /* st(1) = st(1) op st(0); pop */ |
| 14873 |
else |
| 14874 |
p = "rp\t{%1, %0|%0, %1}"; /* st(r2) = st(0) op st(r2); pop */ |
| 14875 |
#endif |
| 14876 |
break; |
| 14877 |
} |
| 14878 |
|
| 14879 |
if (STACK_TOP_P (operands[0])) |
| 14880 |
{ |
| 14881 |
if (STACK_TOP_P (operands[1])) |
| 14882 |
p = "\t{%y2, %0|%0, %y2}"; /* st(0) = st(0) op st(r2) */ |
| 14883 |
else |
| 14884 |
p = "r\t{%y1, %0|%0, %y1}"; /* st(0) = st(r1) op st(0) */ |
| 14885 |
break; |
| 14886 |
} |
| 14887 |
else if (STACK_TOP_P (operands[1])) |
| 14888 |
{ |
| 14889 |
#if SYSV386_COMPAT |
| 14890 |
p = "{\t%1, %0|r\t%0, %1}"; |
| 14891 |
#else |
| 14892 |
p = "r\t{%1, %0|%0, %1}"; /* st(r2) = st(0) op st(r2) */ |
| 14893 |
#endif |
| 14894 |
} |
| 14895 |
else |
| 14896 |
{ |
| 14897 |
#if SYSV386_COMPAT |
| 14898 |
p = "{r\t%2, %0|\t%0, %2}"; |
| 14899 |
#else |
| 14900 |
p = "\t{%2, %0|%0, %2}"; /* st(r1) = st(r1) op st(0) */ |
| 14901 |
#endif |
| 14902 |
} |
| 14903 |
break; |
| 14904 |
|
| 14905 |
default: |
| 14906 |
gcc_unreachable (); |
| 14907 |
} |
| 14908 |
|
| 14909 |
strcat (buf, p); |
| 14910 |
return buf; |
| 14911 |
} |
| 14912 |
|
| 14913 |
/* Return needed mode for entity in optimize_mode_switching pass. */ |
| 14914 |
|
| 14915 |
static int |
| 14916 |
ix86_dirflag_mode_needed (rtx_insn *insn) |
| 14917 |
{ |
| 14918 |
if (CALL_P (insn)) |
| 14919 |
{ |
| 14920 |
if (cfun->machine->func_type == TYPE_NORMAL) |
| 14921 |
return X86_DIRFLAG_ANY; |
| 14922 |
else |
| 14923 |
/* No need to emit CLD in interrupt handler for TARGET_CLD. */ |
| 14924 |
return TARGET_CLD ? X86_DIRFLAG_ANY : X86_DIRFLAG_RESET; |
| 14925 |
} |
| 14926 |
|
| 14927 |
if (recog_memoized (insn) < 0) |
| 14928 |
return X86_DIRFLAG_ANY; |
| 14929 |
|
| 14930 |
if (get_attr_type (insn) == TYPE_STR) |
| 14931 |
{ |
| 14932 |
/* Emit cld instruction if stringops are used in the function. */ |
| 14933 |
if (cfun->machine->func_type == TYPE_NORMAL) |
| 14934 |
return TARGET_CLD ? X86_DIRFLAG_RESET : X86_DIRFLAG_ANY; |
| 14935 |
else |
| 14936 |
return X86_DIRFLAG_RESET; |
| 14937 |
} |
| 14938 |
|
| 14939 |
return X86_DIRFLAG_ANY; |
| 14940 |
} |
| 14941 |
|
| 14942 |
/* Check if a 256bit or 512 bit AVX register is referenced inside of EXP. */ |
| 14943 |
|
| 14944 |
static bool |
| 14945 |
ix86_check_avx_upper_register (const_rtx exp) |
| 14946 |
{ |
| 14947 |
/* construct_container may return a parallel with expr_list |
| 14948 |
which contains the real reg and mode */ |
| 14949 |
subrtx_iterator::array_type array; |
| 14950 |
FOR_EACH_SUBRTX (iter, array, exp, NONCONST) |
| 14951 |
{ |
| 14952 |
const_rtx x = *iter; |
| 14953 |
if (SSE_REG_P (x) |
| 14954 |
&& !EXT_REX_SSE_REG_P (x) |
| 14955 |
&& GET_MODE_BITSIZE (GET_MODE (x)) > 128) |
| 14956 |
return true; |
| 14957 |
} |
| 14958 |
|
| 14959 |
return false; |
| 14960 |
} |
| 14961 |
|
| 14962 |
/* Check if a 256bit or 512bit AVX register is referenced in stores. */ |
| 14963 |
|
| 14964 |
static void |
| 14965 |
ix86_check_avx_upper_stores (rtx dest, const_rtx, void *data) |
| 14966 |
{ |
| 14967 |
if (SSE_REG_P (dest) |
| 14968 |
&& !EXT_REX_SSE_REG_P (dest) |
| 14969 |
&& GET_MODE_BITSIZE (GET_MODE (dest)) > 128) |
| 14970 |
{ |
| 14971 |
bool *used = (bool *) data; |
| 14972 |
*used = true; |
| 14973 |
} |
| 14974 |
} |
| 14975 |
|
| 14976 |
/* Return needed mode for entity in optimize_mode_switching pass. */ |
| 14977 |
|
| 14978 |
static int |
| 14979 |
ix86_avx_u128_mode_needed (rtx_insn *insn) |
| 14980 |
{ |
| 14981 |
if (DEBUG_INSN_P (insn)) |
| 14982 |
return AVX_U128_ANY; |
| 14983 |
|
| 14984 |
if (CALL_P (insn)) |
| 14985 |
{ |
| 14986 |
rtx link; |
| 14987 |
|
| 14988 |
/* Needed mode is set to AVX_U128_CLEAN if there are |
| 14989 |
no 256bit or 512bit modes used in function arguments. */ |
| 14990 |
for (link = CALL_INSN_FUNCTION_USAGE (insn); |
| 14991 |
link; |
| 14992 |
link = XEXP (link, 1)) |
| 14993 |
{ |
| 14994 |
if (GET_CODE (XEXP (link, 0)) == USE) |
| 14995 |
{ |
| 14996 |
rtx arg = XEXP (XEXP (link, 0), 0); |
| 14997 |
|
| 14998 |
if (ix86_check_avx_upper_register (arg)) |
| 14999 |
return AVX_U128_DIRTY; |
| 15000 |
} |
| 15001 |
} |
| 15002 |
|
| 15003 |
/* Needed mode is set to AVX_U128_CLEAN if there are no 256bit |
| 15004 |
nor 512bit registers used in the function return register. */ |
| 15005 |
bool avx_upper_reg_found = false; |
| 15006 |
note_stores (insn, ix86_check_avx_upper_stores, |
| 15007 |
&avx_upper_reg_found); |
| 15008 |
if (avx_upper_reg_found) |
| 15009 |
return AVX_U128_DIRTY; |
| 15010 |
|
| 15011 |
/* If the function is known to preserve some SSE registers, |
| 15012 |
RA and previous passes can legitimately rely on that for |
| 15013 |
modes wider than 256 bits. It's only safe to issue a |
| 15014 |
vzeroupper if all SSE registers are clobbered. */ |
| 15015 |
const function_abi &abi = insn_callee_abi (insn); |
| 15016 |
if (vzeroupper_pattern (PATTERN (insn), VOIDmode) |
| 15017 |
/* Should be safe to issue an vzeroupper before sibling_call_p. |
| 15018 |
Also there not mode_exit for sibling_call, so there could be |
| 15019 |
missing vzeroupper for that. */ |
| 15020 |
|| !(SIBLING_CALL_P (insn) |
| 15021 |
|| hard_reg_set_subset_p (reg_class_contents[SSE_REGS], |
| 15022 |
abi.mode_clobbers (V4DImode)))) |
| 15023 |
return AVX_U128_ANY; |
| 15024 |
|
| 15025 |
return AVX_U128_CLEAN; |
| 15026 |
} |
| 15027 |
|
| 15028 |
rtx set = single_set (insn); |
| 15029 |
if (set) |
| 15030 |
{ |
| 15031 |
rtx dest = SET_DEST (set); |
| 15032 |
rtx src = SET_SRC (set); |
| 15033 |
if (SSE_REG_P (dest) |
| 15034 |
&& !EXT_REX_SSE_REG_P (dest) |
| 15035 |
&& GET_MODE_BITSIZE (GET_MODE (dest)) > 128) |
| 15036 |
{ |
| 15037 |
/* This is an YMM/ZMM load. Return AVX_U128_DIRTY if the |
| 15038 |
source isn't zero. */ |
| 15039 |
if (standard_sse_constant_p (src, GET_MODE (dest)) != 1) |
| 15040 |
return AVX_U128_DIRTY; |
| 15041 |
else |
| 15042 |
return AVX_U128_ANY; |
| 15043 |
} |
| 15044 |
else |
| 15045 |
{ |
| 15046 |
if (ix86_check_avx_upper_register (src)) |
| 15047 |
return AVX_U128_DIRTY; |
| 15048 |
} |
| 15049 |
|
| 15050 |
/* This isn't YMM/ZMM load/store. */ |
| 15051 |
return AVX_U128_ANY; |
| 15052 |
} |
| 15053 |
|
| 15054 |
/* Require DIRTY mode if a 256bit or 512bit AVX register is referenced. |
| 15055 |
Hardware changes state only when a 256bit register is written to, |
| 15056 |
but we need to prevent the compiler from moving optimal insertion |
| 15057 |
point above eventual read from 256bit or 512 bit register. */ |
| 15058 |
if (ix86_check_avx_upper_register (PATTERN (insn))) |
| 15059 |
return AVX_U128_DIRTY; |
| 15060 |
|
| 15061 |
return AVX_U128_ANY; |
| 15062 |
} |
| 15063 |
|
| 15064 |
/* Return mode that i387 must be switched into |
| 15065 |
prior to the execution of insn. */ |
| 15066 |
|
| 15067 |
static int |
| 15068 |
ix86_i387_mode_needed (int entity, rtx_insn *insn) |
| 15069 |
{ |
| 15070 |
enum attr_i387_cw mode; |
| 15071 |
|
| 15072 |
/* The mode UNINITIALIZED is used to store control word after a |
| 15073 |
function call or ASM pattern. The mode ANY specify that function |
| 15074 |
has no requirements on the control word and make no changes in the |
| 15075 |
bits we are interested in. */ |
| 15076 |
|
| 15077 |
if (CALL_P (insn) |
| 15078 |
|| (NONJUMP_INSN_P (insn) |
| 15079 |
&& (asm_noperands (PATTERN (insn)) >= 0 |
| 15080 |
|| GET_CODE (PATTERN (insn)) == ASM_INPUT))) |
| 15081 |
return I387_CW_UNINITIALIZED; |
| 15082 |
|
| 15083 |
if (recog_memoized (insn) < 0) |
| 15084 |
return I387_CW_ANY; |
| 15085 |
|
| 15086 |
mode = get_attr_i387_cw (insn); |
| 15087 |
|
| 15088 |
switch (entity) |
| 15089 |
{ |
| 15090 |
case I387_ROUNDEVEN: |
| 15091 |
if (mode == I387_CW_ROUNDEVEN) |
| 15092 |
return mode; |
| 15093 |
break; |
| 15094 |
|
| 15095 |
case I387_TRUNC: |
| 15096 |
if (mode == I387_CW_TRUNC) |
| 15097 |
return mode; |
| 15098 |
break; |
| 15099 |
|
| 15100 |
case I387_FLOOR: |
| 15101 |
if (mode == I387_CW_FLOOR) |
| 15102 |
return mode; |
| 15103 |
break; |
| 15104 |
|
| 15105 |
case I387_CEIL: |
| 15106 |
if (mode == I387_CW_CEIL) |
| 15107 |
return mode; |
| 15108 |
break; |
| 15109 |
|
| 15110 |
default: |
| 15111 |
gcc_unreachable (); |
| 15112 |
} |
| 15113 |
|
| 15114 |
return I387_CW_ANY; |
| 15115 |
} |
| 15116 |
|
| 15117 |
/* Return mode that entity must be switched into |
| 15118 |
prior to the execution of insn. */ |
| 15119 |
|
| 15120 |
static int |
| 15121 |
ix86_mode_needed (int entity, rtx_insn *insn, HARD_REG_SET) |
| 15122 |
{ |
| 15123 |
switch (entity) |
| 15124 |
{ |
| 15125 |
case X86_DIRFLAG: |
| 15126 |
return ix86_dirflag_mode_needed (insn); |
| 15127 |
case AVX_U128: |
| 15128 |
return ix86_avx_u128_mode_needed (insn); |
| 15129 |
case I387_ROUNDEVEN: |
| 15130 |
case I387_TRUNC: |
| 15131 |
case I387_FLOOR: |
| 15132 |
case I387_CEIL: |
| 15133 |
return ix86_i387_mode_needed (entity, insn); |
| 15134 |
default: |
| 15135 |
gcc_unreachable (); |
| 15136 |
} |
| 15137 |
return 0; |
| 15138 |
} |
| 15139 |
|
| 15140 |
/* Calculate mode of upper 128bit AVX registers after the insn. */ |
| 15141 |
|
| 15142 |
static int |
| 15143 |
ix86_avx_u128_mode_after (int mode, rtx_insn *insn) |
| 15144 |
{ |
| 15145 |
rtx pat = PATTERN (insn); |
| 15146 |
|
| 15147 |
if (vzeroupper_pattern (pat, VOIDmode) |
| 15148 |
|| vzeroall_pattern (pat, VOIDmode)) |
| 15149 |
return AVX_U128_CLEAN; |
| 15150 |
|
| 15151 |
/* We know that state is clean after CALL insn if there are no |
| 15152 |
256bit or 512bit registers used in the function return register. */ |
| 15153 |
if (CALL_P (insn)) |
| 15154 |
{ |
| 15155 |
bool avx_upper_reg_found = false; |
| 15156 |
note_stores (insn, ix86_check_avx_upper_stores, &avx_upper_reg_found); |
| 15157 |
|
| 15158 |
if (avx_upper_reg_found) |
| 15159 |
return AVX_U128_DIRTY; |
| 15160 |
|
| 15161 |
/* If the function desn't clobber any sse registers or only clobber |
| 15162 |
128-bit part, Then vzeroupper isn't issued before the function exit. |
| 15163 |
the status not CLEAN but ANY after the function. */ |
| 15164 |
const function_abi &abi = insn_callee_abi (insn); |
| 15165 |
if (!(SIBLING_CALL_P (insn) |
| 15166 |
|| hard_reg_set_subset_p (reg_class_contents[SSE_REGS], |
| 15167 |
abi.mode_clobbers (V4DImode)))) |
| 15168 |
return AVX_U128_ANY; |
| 15169 |
|
| 15170 |
return AVX_U128_CLEAN; |
| 15171 |
} |
| 15172 |
|
| 15173 |
/* Otherwise, return current mode. Remember that if insn |
| 15174 |
references AVX 256bit or 512bit registers, the mode was already |
| 15175 |
changed to DIRTY from MODE_NEEDED. */ |
| 15176 |
return mode; |
| 15177 |
} |
| 15178 |
|
| 15179 |
/* Return the mode that an insn results in. */ |
| 15180 |
|
| 15181 |
static int |
| 15182 |
ix86_mode_after (int entity, int mode, rtx_insn *insn, HARD_REG_SET) |
| 15183 |
{ |
| 15184 |
switch (entity) |
| 15185 |
{ |
| 15186 |
case X86_DIRFLAG: |
| 15187 |
return mode; |
| 15188 |
case AVX_U128: |
| 15189 |
return ix86_avx_u128_mode_after (mode, insn); |
| 15190 |
case I387_ROUNDEVEN: |
| 15191 |
case I387_TRUNC: |
| 15192 |
case I387_FLOOR: |
| 15193 |
case I387_CEIL: |
| 15194 |
return mode; |
| 15195 |
default: |
| 15196 |
gcc_unreachable (); |
| 15197 |
} |
| 15198 |
} |
| 15199 |
|
| 15200 |
static int |
| 15201 |
ix86_dirflag_mode_entry (void) |
| 15202 |
{ |
| 15203 |
/* For TARGET_CLD or in the interrupt handler we can't assume |
| 15204 |
direction flag state at function entry. */ |
| 15205 |
if (TARGET_CLD |
| 15206 |
|| cfun->machine->func_type != TYPE_NORMAL) |
| 15207 |
return X86_DIRFLAG_ANY; |
| 15208 |
|
| 15209 |
return X86_DIRFLAG_RESET; |
| 15210 |
} |
| 15211 |
|
| 15212 |
static int |
| 15213 |
ix86_avx_u128_mode_entry (void) |
| 15214 |
{ |
| 15215 |
tree arg; |
| 15216 |
|
| 15217 |
/* Entry mode is set to AVX_U128_DIRTY if there are |
| 15218 |
256bit or 512bit modes used in function arguments. */ |
| 15219 |
for (arg = DECL_ARGUMENTS (current_function_decl); arg; |
| 15220 |
arg = TREE_CHAIN (arg)) |
| 15221 |
{ |
| 15222 |
rtx incoming = DECL_INCOMING_RTL (arg); |
| 15223 |
|
| 15224 |
if (incoming && ix86_check_avx_upper_register (incoming)) |
| 15225 |
return AVX_U128_DIRTY; |
| 15226 |
} |
| 15227 |
|
| 15228 |
return AVX_U128_CLEAN; |
| 15229 |
} |
| 15230 |
|
| 15231 |
/* Return a mode that ENTITY is assumed to be |
| 15232 |
switched to at function entry. */ |
| 15233 |
|
| 15234 |
static int |
| 15235 |
ix86_mode_entry (int entity) |
| 15236 |
{ |
| 15237 |
switch (entity) |
| 15238 |
{ |
| 15239 |
case X86_DIRFLAG: |
| 15240 |
return ix86_dirflag_mode_entry (); |
| 15241 |
case AVX_U128: |
| 15242 |
return ix86_avx_u128_mode_entry (); |
| 15243 |
case I387_ROUNDEVEN: |
| 15244 |
case I387_TRUNC: |
| 15245 |
case I387_FLOOR: |
| 15246 |
case I387_CEIL: |
| 15247 |
return I387_CW_ANY; |
| 15248 |
default: |
| 15249 |
gcc_unreachable (); |
| 15250 |
} |
| 15251 |
} |
| 15252 |
|
| 15253 |
static int |
| 15254 |
ix86_avx_u128_mode_exit (void) |
| 15255 |
{ |
| 15256 |
rtx reg = crtl->return_rtx; |
| 15257 |
|
| 15258 |
/* Exit mode is set to AVX_U128_DIRTY if there are 256bit |
| 15259 |
or 512 bit modes used in the function return register. */ |
| 15260 |
if (reg && ix86_check_avx_upper_register (reg)) |
| 15261 |
return AVX_U128_DIRTY; |
| 15262 |
|
| 15263 |
/* Exit mode is set to AVX_U128_DIRTY if there are 256bit or 512bit |
| 15264 |
modes used in function arguments, otherwise return AVX_U128_CLEAN. |
| 15265 |
*/ |
| 15266 |
return ix86_avx_u128_mode_entry (); |
| 15267 |
} |
| 15268 |
|
| 15269 |
/* Return a mode that ENTITY is assumed to be |
| 15270 |
switched to at function exit. */ |
| 15271 |
|
| 15272 |
static int |
| 15273 |
ix86_mode_exit (int entity) |
| 15274 |
{ |
| 15275 |
switch (entity) |
| 15276 |
{ |
| 15277 |
case X86_DIRFLAG: |
| 15278 |
return X86_DIRFLAG_ANY; |
| 15279 |
case AVX_U128: |
| 15280 |
return ix86_avx_u128_mode_exit (); |
| 15281 |
case I387_ROUNDEVEN: |
| 15282 |
case I387_TRUNC: |
| 15283 |
case I387_FLOOR: |
| 15284 |
case I387_CEIL: |
| 15285 |
return I387_CW_ANY; |
| 15286 |
default: |
| 15287 |
gcc_unreachable (); |
| 15288 |
} |
| 15289 |
} |
| 15290 |
|
| 15291 |
static int |
| 15292 |
ix86_mode_priority (int, int n) |
| 15293 |
{ |
| 15294 |
return n; |
| 15295 |
} |
| 15296 |
|
| 15297 |
/* Output code to initialize control word copies used by trunc?f?i and |
| 15298 |
rounding patterns. CURRENT_MODE is set to current control word, |
| 15299 |
while NEW_MODE is set to new control word. */ |
| 15300 |
|
| 15301 |
static void |
| 15302 |
emit_i387_cw_initialization (int mode) |
| 15303 |
{ |
| 15304 |
rtx stored_mode = assign_386_stack_local (HImode, SLOT_CW_STORED); |
| 15305 |
rtx new_mode; |
| 15306 |
|
| 15307 |
enum ix86_stack_slot slot; |
| 15308 |
|
| 15309 |
rtx reg = gen_reg_rtx (HImode); |
| 15310 |
|
| 15311 |
emit_insn (gen_x86_fnstcw_1 (stored_mode)); |
| 15312 |
emit_move_insn (reg, copy_rtx (stored_mode)); |
| 15313 |
|
| 15314 |
switch (mode) |
| 15315 |
{ |
| 15316 |
case I387_CW_ROUNDEVEN: |
| 15317 |
/* round to nearest */ |
| 15318 |
emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00))); |
| 15319 |
slot = SLOT_CW_ROUNDEVEN; |
| 15320 |
break; |
| 15321 |
|
| 15322 |
case I387_CW_TRUNC: |
| 15323 |
/* round toward zero (truncate) */ |
| 15324 |
emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0c00))); |
| 15325 |
slot = SLOT_CW_TRUNC; |
| 15326 |
break; |
| 15327 |
|
| 15328 |
case I387_CW_FLOOR: |
| 15329 |
/* round down toward -oo */ |
| 15330 |
emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00))); |
| 15331 |
emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0400))); |
| 15332 |
slot = SLOT_CW_FLOOR; |
| 15333 |
break; |
| 15334 |
|
| 15335 |
case I387_CW_CEIL: |
| 15336 |
/* round up toward +oo */ |
| 15337 |
emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00))); |
| 15338 |
emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0800))); |
| 15339 |
slot = SLOT_CW_CEIL; |
| 15340 |
break; |
| 15341 |
|
| 15342 |
default: |
| 15343 |
gcc_unreachable (); |
| 15344 |
} |
| 15345 |
|
| 15346 |
gcc_assert (slot < MAX_386_STACK_LOCALS); |
| 15347 |
|
| 15348 |
new_mode = assign_386_stack_local (HImode, slot); |
| 15349 |
emit_move_insn (new_mode, reg); |
| 15350 |
} |
| 15351 |
|
| 15352 |
/* Generate one or more insns to set ENTITY to MODE. */ |
| 15353 |
|
| 15354 |
static void |
| 15355 |
ix86_emit_mode_set (int entity, int mode, int prev_mode ATTRIBUTE_UNUSED, |
| 15356 |
HARD_REG_SET regs_live ATTRIBUTE_UNUSED) |
| 15357 |
{ |
| 15358 |
switch (entity) |
| 15359 |
{ |
| 15360 |
case X86_DIRFLAG: |
| 15361 |
if (mode == X86_DIRFLAG_RESET) |
| 15362 |
emit_insn (gen_cld ()); |
| 15363 |
break; |
| 15364 |
case AVX_U128: |
| 15365 |
if (mode == AVX_U128_CLEAN) |
| 15366 |
ix86_expand_avx_vzeroupper (); |
| 15367 |
break; |
| 15368 |
case I387_ROUNDEVEN: |
| 15369 |
case I387_TRUNC: |
| 15370 |
case I387_FLOOR: |
| 15371 |
case I387_CEIL: |
| 15372 |
if (mode != I387_CW_ANY |
| 15373 |
&& mode != I387_CW_UNINITIALIZED) |
| 15374 |
emit_i387_cw_initialization (mode); |
| 15375 |
break; |
| 15376 |
default: |
| 15377 |
gcc_unreachable (); |
| 15378 |
} |
| 15379 |
} |
| 15380 |
|
| 15381 |
/* Output code for INSN to convert a float to a signed int. OPERANDS |
| 15382 |
are the insn operands. The output may be [HSD]Imode and the input |
| 15383 |
operand may be [SDX]Fmode. */ |
| 15384 |
|
| 15385 |
const char * |
| 15386 |
output_fix_trunc (rtx_insn *insn, rtx *operands, bool fisttp) |
| 15387 |
{ |
| 15388 |
bool stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG); |
| 15389 |
bool dimode_p = GET_MODE (operands[0]) == DImode; |
| 15390 |
int round_mode = get_attr_i387_cw (insn); |
| 15391 |
|
| 15392 |
static char buf[40]; |
| 15393 |
const char *p; |
| 15394 |
|
| 15395 |
/* Jump through a hoop or two for DImode, since the hardware has no |
| 15396 |
non-popping instruction. We used to do this a different way, but |
| 15397 |
that was somewhat fragile and broke with post-reload splitters. */ |
| 15398 |
if ((dimode_p || fisttp) && !stack_top_dies) |
| 15399 |
output_asm_insn ("fld\t%y1", operands); |
| 15400 |
|
| 15401 |
gcc_assert (STACK_TOP_P (operands[1])); |
| 15402 |
gcc_assert (MEM_P (operands[0])); |
| 15403 |
gcc_assert (GET_MODE (operands[1]) != TFmode); |
| 15404 |
|
| 15405 |
if (fisttp) |
| 15406 |
return "fisttp%Z0\t%0"; |
| 15407 |
|
| 15408 |
strcpy (buf, "fist"); |
| 15409 |
|
| 15410 |
if (round_mode != I387_CW_ANY) |
| 15411 |
output_asm_insn ("fldcw\t%3", operands); |
| 15412 |
|
| 15413 |
p = "p%Z0\t%0"; |
| 15414 |
strcat (buf, p + !(stack_top_dies || dimode_p)); |
| 15415 |
|
| 15416 |
output_asm_insn (buf, operands); |
| 15417 |
|
| 15418 |
if (round_mode != I387_CW_ANY) |
| 15419 |
output_asm_insn ("fldcw\t%2", operands); |
| 15420 |
|
| 15421 |
return ""; |
| 15422 |
} |
| 15423 |
|
| 15424 |
/* Output code for x87 ffreep insn. The OPNO argument, which may only |
| 15425 |
have the values zero or one, indicates the ffreep insn's operand |
| 15426 |
from the OPERANDS array. */ |
| 15427 |
|
| 15428 |
static const char * |
| 15429 |
output_387_ffreep (rtx *operands ATTRIBUTE_UNUSED, int opno) |
| 15430 |
{ |
| 15431 |
if (TARGET_USE_FFREEP) |
| 15432 |
#ifdef HAVE_AS_IX86_FFREEP |
| 15433 |
return opno ? "ffreep\t%y1" : "ffreep\t%y0"; |
| 15434 |
#else |
| 15435 |
{ |
| 15436 |
static char retval[32]; |
| 15437 |
int regno = REGNO (operands[opno]); |
| 15438 |
|
| 15439 |
gcc_assert (STACK_REGNO_P (regno)); |
| 15440 |
|
| 15441 |
regno -= FIRST_STACK_REG; |
| 15442 |
|
| 15443 |
snprintf (retval, sizeof (retval), ASM_SHORT "0xc%ddf", regno); |
| 15444 |
return retval; |
| 15445 |
} |
| 15446 |
#endif |
| 15447 |
|
| 15448 |
return opno ? "fstp\t%y1" : "fstp\t%y0"; |
| 15449 |
} |
| 15450 |
|
| 15451 |
|
| 15452 |
/* Output code for INSN to compare OPERANDS. EFLAGS_P is 1 when fcomi |
| 15453 |
should be used. UNORDERED_P is true when fucom should be used. */ |
| 15454 |
|
| 15455 |
const char * |
| 15456 |
output_fp_compare (rtx_insn *insn, rtx *operands, |
| 15457 |
bool eflags_p, bool unordered_p) |
| 15458 |
{ |
| 15459 |
rtx *xops = eflags_p ? &operands[0] : &operands[1]; |
| 15460 |
bool stack_top_dies; |
| 15461 |
|
| 15462 |
static char buf[40]; |
| 15463 |
const char *p; |
| 15464 |
|
| 15465 |
gcc_assert (STACK_TOP_P (xops[0])); |
| 15466 |
|
| 15467 |
stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG); |
| 15468 |
|
| 15469 |
if (eflags_p) |
| 15470 |
{ |
| 15471 |
p = unordered_p ? "fucomi" : "fcomi"; |
| 15472 |
strcpy (buf, p); |
| 15473 |
|
| 15474 |
p = "p\t{%y1, %0|%0, %y1}"; |
| 15475 |
strcat (buf, p + !stack_top_dies); |
| 15476 |
|
| 15477 |
return buf; |
| 15478 |
} |
| 15479 |
|
| 15480 |
if (STACK_REG_P (xops[1]) |
| 15481 |
&& stack_top_dies |
| 15482 |
&& find_regno_note (insn, REG_DEAD, FIRST_STACK_REG + 1)) |
| 15483 |
{ |
| 15484 |
gcc_assert (REGNO (xops[1]) == FIRST_STACK_REG + 1); |
| 15485 |
|
| 15486 |
/* If both the top of the 387 stack die, and the other operand |
| 15487 |
is also a stack register that dies, then this must be a |
| 15488 |
`fcompp' float compare. */ |
| 15489 |
p = unordered_p ? "fucompp" : "fcompp"; |
| 15490 |
strcpy (buf, p); |
| 15491 |
} |
| 15492 |
else if (const0_operand (xops[1], VOIDmode)) |
| 15493 |
{ |
| 15494 |
gcc_assert (!unordered_p); |
| 15495 |
strcpy (buf, "ftst"); |
| 15496 |
} |
| 15497 |
else |
| 15498 |
{ |
| 15499 |
if (GET_MODE_CLASS (GET_MODE (xops[1])) == MODE_INT) |
| 15500 |
{ |
| 15501 |
gcc_assert (!unordered_p); |
| 15502 |
p = "ficom"; |
| 15503 |
} |
| 15504 |
else |
| 15505 |
p = unordered_p ? "fucom" : "fcom"; |
| 15506 |
|
| 15507 |
strcpy (buf, p); |
| 15508 |
|
| 15509 |
p = "p%Z2\t%y2"; |
| 15510 |
strcat (buf, p + !stack_top_dies); |
| 15511 |
} |
| 15512 |
|
| 15513 |
output_asm_insn (buf, operands); |
| 15514 |
return "fnstsw\t%0"; |
| 15515 |
} |
| 15516 |
|
| 15517 |
void |
| 15518 |
ix86_output_addr_vec_elt (FILE *file, int value) |
| 15519 |
{ |
| 15520 |
const char *directive = ASM_LONG; |
| 15521 |
|
| 15522 |
#ifdef ASM_QUAD |
| 15523 |
if (TARGET_LP64) |
| 15524 |
directive = ASM_QUAD; |
| 15525 |
#else |
| 15526 |
gcc_assert (!TARGET_64BIT); |
| 15527 |
#endif |
| 15528 |
|
| 15529 |
fprintf (file, "%s%s%d\n", directive, LPREFIX, value); |
| 15530 |
} |
| 15531 |
|
| 15532 |
void |
| 15533 |
ix86_output_addr_diff_elt (FILE *file, int value, int rel) |
| 15534 |
{ |
| 15535 |
const char *directive = ASM_LONG; |
| 15536 |
|
| 15537 |
#ifdef ASM_QUAD |
| 15538 |
if (TARGET_64BIT && CASE_VECTOR_MODE == DImode) |
| 15539 |
directive = ASM_QUAD; |
| 15540 |
#else |
| 15541 |
gcc_assert (!TARGET_64BIT); |
| 15542 |
#endif |
| 15543 |
/* We can't use @GOTOFF for text labels on VxWorks; see gotoff_operand. */ |
| 15544 |
if (TARGET_64BIT || TARGET_VXWORKS_RTP) |
| 15545 |
fprintf (file, "%s%s%d-%s%d\n", |
| 15546 |
directive, LPREFIX, value, LPREFIX, rel); |
| 15547 |
#if TARGET_MACHO |
| 15548 |
else if (TARGET_MACHO) |
| 15549 |
{ |
| 15550 |
fprintf (file, ASM_LONG "%s%d-", LPREFIX, value); |
| 15551 |
machopic_output_function_base_name (file); |
| 15552 |
putc ('\n', file); |
| 15553 |
} |
| 15554 |
#endif |
| 15555 |
else if (HAVE_AS_GOTOFF_IN_DATA) |
| 15556 |
fprintf (file, ASM_LONG "%s%d@GOTOFF\n", LPREFIX, value); |
| 15557 |
else |
| 15558 |
asm_fprintf (file, ASM_LONG "%U%s+[.-%s%d]\n", |
| 15559 |
GOT_SYMBOL_NAME, LPREFIX, value); |
| 15560 |
} |
| 15561 |
|
| 15562 |
#define LEA_MAX_STALL (3) |
| 15563 |
#define LEA_SEARCH_THRESHOLD (LEA_MAX_STALL << 1) |
| 15564 |
|
| 15565 |
/* Increase given DISTANCE in half-cycles according to |
| 15566 |
dependencies between PREV and NEXT instructions. |
| 15567 |
Add 1 half-cycle if there is no dependency and |
| 15568 |
go to next cycle if there is some dependecy. */ |
| 15569 |
|
| 15570 |
static unsigned int |
| 15571 |
increase_distance (rtx_insn *prev, rtx_insn *next, unsigned int distance) |
| 15572 |
{ |
| 15573 |
df_ref def, use; |
| 15574 |
|
| 15575 |
if (!prev || !next) |
| 15576 |
return distance + (distance & 1) + 2; |
| 15577 |
|
| 15578 |
if (!DF_INSN_USES (next) || !DF_INSN_DEFS (prev)) |
| 15579 |
return distance + 1; |
| 15580 |
|
| 15581 |
FOR_EACH_INSN_USE (use, next) |
| 15582 |
FOR_EACH_INSN_DEF (def, prev) |
| 15583 |
if (!DF_REF_IS_ARTIFICIAL (def) |
| 15584 |
&& DF_REF_REGNO (use) == DF_REF_REGNO (def)) |
| 15585 |
return distance + (distance & 1) + 2; |
| 15586 |
|
| 15587 |
return distance + 1; |
| 15588 |
} |
| 15589 |
|
| 15590 |
/* Function checks if instruction INSN defines register number |
| 15591 |
REGNO1 or REGNO2. */ |
| 15592 |
|
| 15593 |
bool |
| 15594 |
insn_defines_reg (unsigned int regno1, unsigned int regno2, |
| 15595 |
rtx_insn *insn) |
| 15596 |
{ |
| 15597 |
df_ref def; |
| 15598 |
|
| 15599 |
FOR_EACH_INSN_DEF (def, insn) |
| 15600 |
if (DF_REF_REG_DEF_P (def) |
| 15601 |
&& !DF_REF_IS_ARTIFICIAL (def) |
| 15602 |
&& (regno1 == DF_REF_REGNO (def) |
| 15603 |
|| regno2 == DF_REF_REGNO (def))) |
| 15604 |
return true; |
| 15605 |
|
| 15606 |
return false; |
| 15607 |
} |
| 15608 |
|
| 15609 |
/* Function checks if instruction INSN uses register number |
| 15610 |
REGNO as a part of address expression. */ |
| 15611 |
|
| 15612 |
static bool |
| 15613 |
insn_uses_reg_mem (unsigned int regno, rtx insn) |
| 15614 |
{ |
| 15615 |
df_ref use; |
| 15616 |
|
| 15617 |
FOR_EACH_INSN_USE (use, insn) |
| 15618 |
if (DF_REF_REG_MEM_P (use) && regno == DF_REF_REGNO (use)) |
| 15619 |
return true; |
| 15620 |
|
| 15621 |
return false; |
| 15622 |
} |
| 15623 |
|
| 15624 |
/* Search backward for non-agu definition of register number REGNO1 |
| 15625 |
or register number REGNO2 in basic block starting from instruction |
| 15626 |
START up to head of basic block or instruction INSN. |
| 15627 |
|
| 15628 |
Function puts true value into *FOUND var if definition was found |
| 15629 |
and false otherwise. |
| 15630 |
|
| 15631 |
Distance in half-cycles between START and found instruction or head |
| 15632 |
of BB is added to DISTANCE and returned. */ |
| 15633 |
|
| 15634 |
static int |
| 15635 |
distance_non_agu_define_in_bb (unsigned int regno1, unsigned int regno2, |
| 15636 |
rtx_insn *insn, int distance, |
| 15637 |
rtx_insn *start, bool *found) |
| 15638 |
{ |
| 15639 |
basic_block bb = start ? BLOCK_FOR_INSN (start) : NULL; |
| 15640 |
rtx_insn *prev = start; |
| 15641 |
rtx_insn *next = NULL; |
| 15642 |
|
| 15643 |
*found = false; |
| 15644 |
|
| 15645 |
while (prev |
| 15646 |
&& prev != insn |
| 15647 |
&& distance < LEA_SEARCH_THRESHOLD) |
| 15648 |
{ |
| 15649 |
if (NONDEBUG_INSN_P (prev) && NONJUMP_INSN_P (prev)) |
| 15650 |
{ |
| 15651 |
distance = increase_distance (prev, next, distance); |
| 15652 |
if (insn_defines_reg (regno1, regno2, prev)) |
| 15653 |
{ |
| 15654 |
if (recog_memoized (prev) < 0 |
| 15655 |
|| get_attr_type (prev) != TYPE_LEA) |
| 15656 |
{ |
| 15657 |
*found = true; |
| 15658 |
return distance; |
| 15659 |
} |
| 15660 |
} |
| 15661 |
|
| 15662 |
next = prev; |
| 15663 |
} |
| 15664 |
if (prev == BB_HEAD (bb)) |
| 15665 |
break; |
| 15666 |
|
| 15667 |
prev = PREV_INSN (prev); |
| 15668 |
} |
| 15669 |
|
| 15670 |
return distance; |
| 15671 |
} |
| 15672 |
|
| 15673 |
/* Search backward for non-agu definition of register number REGNO1 |
| 15674 |
or register number REGNO2 in INSN's basic block until |
| 15675 |
1. Pass LEA_SEARCH_THRESHOLD instructions, or |
| 15676 |
2. Reach neighbor BBs boundary, or |
| 15677 |
3. Reach agu definition. |
| 15678 |
Returns the distance between the non-agu definition point and INSN. |
| 15679 |
If no definition point, returns -1. */ |
| 15680 |
|
| 15681 |
static int |
| 15682 |
distance_non_agu_define (unsigned int regno1, unsigned int regno2, |
| 15683 |
rtx_insn *insn) |
| 15684 |
{ |
| 15685 |
basic_block bb = BLOCK_FOR_INSN (insn); |
| 15686 |
int distance = 0; |
| 15687 |
bool found = false; |
| 15688 |
|
| 15689 |
if (insn != BB_HEAD (bb)) |
| 15690 |
distance = distance_non_agu_define_in_bb (regno1, regno2, insn, |
| 15691 |
distance, PREV_INSN (insn), |
| 15692 |
&found); |
| 15693 |
|
| 15694 |
if (!found && distance < LEA_SEARCH_THRESHOLD) |
| 15695 |
{ |
| 15696 |
edge e; |
| 15697 |
edge_iterator ei; |
| 15698 |
bool simple_loop = false; |
| 15699 |
|
| 15700 |
FOR_EACH_EDGE (e, ei, bb->preds) |
| 15701 |
if (e->src == bb) |
| 15702 |
{ |
| 15703 |
simple_loop = true; |
| 15704 |
break; |
| 15705 |
} |
| 15706 |
|
| 15707 |
if (simple_loop) |
| 15708 |
distance = distance_non_agu_define_in_bb (regno1, regno2, |
| 15709 |
insn, distance, |
| 15710 |
BB_END (bb), &found); |
| 15711 |
else |
| 15712 |
{ |
| 15713 |
int shortest_dist = -1; |
| 15714 |
bool found_in_bb = false; |
| 15715 |
|
| 15716 |
FOR_EACH_EDGE (e, ei, bb->preds) |
| 15717 |
{ |
| 15718 |
int bb_dist |
| 15719 |
= distance_non_agu_define_in_bb (regno1, regno2, |
| 15720 |
insn, distance, |
| 15721 |
BB_END (e->src), |
| 15722 |
&found_in_bb); |
| 15723 |
if (found_in_bb) |
| 15724 |
{ |
| 15725 |
if (shortest_dist < 0) |
| 15726 |
shortest_dist = bb_dist; |
| 15727 |
else if (bb_dist > 0) |
| 15728 |
shortest_dist = MIN (bb_dist, shortest_dist); |
| 15729 |
|
| 15730 |
found = true; |
| 15731 |
} |
| 15732 |
} |
| 15733 |
|
| 15734 |
distance = shortest_dist; |
| 15735 |
} |
| 15736 |
} |
| 15737 |
|
| 15738 |
if (!found) |
| 15739 |
return -1; |
| 15740 |
|
| 15741 |
return distance >> 1; |
| 15742 |
} |
| 15743 |
|
| 15744 |
/* Return the distance in half-cycles between INSN and the next |
| 15745 |
insn that uses register number REGNO in memory address added |
| 15746 |
to DISTANCE. Return -1 if REGNO0 is set. |
| 15747 |
|
| 15748 |
Put true value into *FOUND if register usage was found and |
| 15749 |
false otherwise. |
| 15750 |
Put true value into *REDEFINED if register redefinition was |
| 15751 |
found and false otherwise. */ |
| 15752 |
|
| 15753 |
static int |
| 15754 |
distance_agu_use_in_bb (unsigned int regno, |
| 15755 |
rtx_insn *insn, int distance, rtx_insn *start, |
| 15756 |
bool *found, bool *redefined) |
| 15757 |
{ |
| 15758 |
basic_block bb = NULL; |
| 15759 |
rtx_insn *next = start; |
| 15760 |
rtx_insn *prev = NULL; |
| 15761 |
|
| 15762 |
*found = false; |
| 15763 |
*redefined = false; |
| 15764 |
|
| 15765 |
if (start != NULL_RTX) |
| 15766 |
{ |
| 15767 |
bb = BLOCK_FOR_INSN (start); |
| 15768 |
if (start != BB_HEAD (bb)) |
| 15769 |
/* If insn and start belong to the same bb, set prev to insn, |
| 15770 |
so the call to increase_distance will increase the distance |
| 15771 |
between insns by 1. */ |
| 15772 |
prev = insn; |
| 15773 |
} |
| 15774 |
|
| 15775 |
while (next |
| 15776 |
&& next != insn |
| 15777 |
&& distance < LEA_SEARCH_THRESHOLD) |
| 15778 |
{ |
| 15779 |
if (NONDEBUG_INSN_P (next) && NONJUMP_INSN_P (next)) |
| 15780 |
{ |
| 15781 |
distance = increase_distance(prev, next, distance); |
| 15782 |
if (insn_uses_reg_mem (regno, next)) |
| 15783 |
{ |
| 15784 |
/* Return DISTANCE if OP0 is used in memory |
| 15785 |
address in NEXT. */ |
| 15786 |
*found = true; |
| 15787 |
return distance; |
| 15788 |
} |
| 15789 |
|
| 15790 |
if (insn_defines_reg (regno, INVALID_REGNUM, next)) |
| 15791 |
{ |
| 15792 |
/* Return -1 if OP0 is set in NEXT. */ |
| 15793 |
*redefined = true; |
| 15794 |
return -1; |
| 15795 |
} |
| 15796 |
|
| 15797 |
prev = next; |
| 15798 |
} |
| 15799 |
|
| 15800 |
if (next == BB_END (bb)) |
| 15801 |
break; |
| 15802 |
|
| 15803 |
next = NEXT_INSN (next); |
| 15804 |
} |
| 15805 |
|
| 15806 |
return distance; |
| 15807 |
} |
| 15808 |
|
| 15809 |
/* Return the distance between INSN and the next insn that uses |
| 15810 |
register number REGNO0 in memory address. Return -1 if no such |
| 15811 |
a use is found within LEA_SEARCH_THRESHOLD or REGNO0 is set. */ |
| 15812 |
|
| 15813 |
static int |
| 15814 |
distance_agu_use (unsigned int regno0, rtx_insn *insn) |
| 15815 |
{ |
| 15816 |
basic_block bb = BLOCK_FOR_INSN (insn); |
| 15817 |
int distance = 0; |
| 15818 |
bool found = false; |
| 15819 |
bool redefined = false; |
| 15820 |
|
| 15821 |
if (insn != BB_END (bb)) |
| 15822 |
distance = distance_agu_use_in_bb (regno0, insn, distance, |
| 15823 |
NEXT_INSN (insn), |
| 15824 |
&found, &redefined); |
| 15825 |
|
| 15826 |
if (!found && !redefined && distance < LEA_SEARCH_THRESHOLD) |
| 15827 |
{ |
| 15828 |
edge e; |
| 15829 |
edge_iterator ei; |
| 15830 |
bool simple_loop = false; |
| 15831 |
|
| 15832 |
FOR_EACH_EDGE (e, ei, bb->succs) |
| 15833 |
if (e->dest == bb) |
| 15834 |
{ |
| 15835 |
simple_loop = true; |
| 15836 |
break; |
| 15837 |
} |
| 15838 |
|
| 15839 |
if (simple_loop) |
| 15840 |
distance = distance_agu_use_in_bb (regno0, insn, |
| 15841 |
distance, BB_HEAD (bb), |
| 15842 |
&found, &redefined); |
| 15843 |
else |
| 15844 |
{ |
| 15845 |
int shortest_dist = -1; |
| 15846 |
bool found_in_bb = false; |
| 15847 |
bool redefined_in_bb = false; |
| 15848 |
|
| 15849 |
FOR_EACH_EDGE (e, ei, bb->succs) |
| 15850 |
{ |
| 15851 |
int bb_dist |
| 15852 |
= distance_agu_use_in_bb (regno0, insn, |
| 15853 |
distance, BB_HEAD (e->dest), |
| 15854 |
&found_in_bb, &redefined_in_bb); |
| 15855 |
if (found_in_bb) |
| 15856 |
{ |
| 15857 |
if (shortest_dist < 0) |
| 15858 |
shortest_dist = bb_dist; |
| 15859 |
else if (bb_dist > 0) |
| 15860 |
shortest_dist = MIN (bb_dist, shortest_dist); |
| 15861 |
|
| 15862 |
found = true; |
| 15863 |
} |
| 15864 |
} |
| 15865 |
|
| 15866 |
distance = shortest_dist; |
| 15867 |
} |
| 15868 |
} |
| 15869 |
|
| 15870 |
if (!found || redefined) |
| 15871 |
return -1; |
| 15872 |
|
| 15873 |
return distance >> 1; |
| 15874 |
} |
| 15875 |
|
| 15876 |
/* Define this macro to tune LEA priority vs ADD, it take effect when |
| 15877 |
there is a dilemma of choosing LEA or ADD |
| 15878 |
Negative value: ADD is more preferred than LEA |
| 15879 |
Zero: Neutral |
| 15880 |
Positive value: LEA is more preferred than ADD. */ |
| 15881 |
#define IX86_LEA_PRIORITY 0 |
| 15882 |
|
| 15883 |
/* Return true if usage of lea INSN has performance advantage |
| 15884 |
over a sequence of instructions. Instructions sequence has |
| 15885 |
SPLIT_COST cycles higher latency than lea latency. */ |
| 15886 |
|
| 15887 |
static bool |
| 15888 |
ix86_lea_outperforms (rtx_insn *insn, unsigned int regno0, unsigned int regno1, |
| 15889 |
unsigned int regno2, int split_cost, bool has_scale) |
| 15890 |
{ |
| 15891 |
int dist_define, dist_use; |
| 15892 |
|
| 15893 |
/* For Atom processors newer than Bonnell, if using a 2-source or |
| 15894 |
3-source LEA for non-destructive destination purposes, or due to |
| 15895 |
wanting ability to use SCALE, the use of LEA is justified. */ |
| 15896 |
if (!TARGET_CPU_P (BONNELL)) |
| 15897 |
{ |
| 15898 |
if (has_scale) |
| 15899 |
return true; |
| 15900 |
if (split_cost < 1) |
| 15901 |
return false; |
| 15902 |
if (regno0 == regno1 || regno0 == regno2) |
| 15903 |
return false; |
| 15904 |
return true; |
| 15905 |
} |
| 15906 |
|
| 15907 |
/* Remember recog_data content. */ |
| 15908 |
struct recog_data_d recog_data_save = recog_data; |
| 15909 |
|
| 15910 |
dist_define = distance_non_agu_define (regno1, regno2, insn); |
| 15911 |
dist_use = distance_agu_use (regno0, insn); |
| 15912 |
|
| 15913 |
/* distance_non_agu_define can call get_attr_type which can call |
| 15914 |
recog_memoized, restore recog_data back to previous content. */ |
| 15915 |
recog_data = recog_data_save; |
| 15916 |
|
| 15917 |
if (dist_define < 0 || dist_define >= LEA_MAX_STALL) |
| 15918 |
{ |
| 15919 |
/* If there is no non AGU operand definition, no AGU |
| 15920 |
operand usage and split cost is 0 then both lea |
| 15921 |
and non lea variants have same priority. Currently |
| 15922 |
we prefer lea for 64 bit code and non lea on 32 bit |
| 15923 |
code. */ |
| 15924 |
if (dist_use < 0 && split_cost == 0) |
| 15925 |
return TARGET_64BIT || IX86_LEA_PRIORITY; |
| 15926 |
else |
| 15927 |
return true; |
| 15928 |
} |
| 15929 |
|
| 15930 |
/* With longer definitions distance lea is more preferable. |
| 15931 |
Here we change it to take into account splitting cost and |
| 15932 |
lea priority. */ |
| 15933 |
dist_define += split_cost + IX86_LEA_PRIORITY; |
| 15934 |
|
| 15935 |
/* If there is no use in memory addess then we just check |
| 15936 |
that split cost exceeds AGU stall. */ |
| 15937 |
if (dist_use < 0) |
| 15938 |
return dist_define > LEA_MAX_STALL; |
| 15939 |
|
| 15940 |
/* If this insn has both backward non-agu dependence and forward |
| 15941 |
agu dependence, the one with short distance takes effect. */ |
| 15942 |
return dist_define >= dist_use; |
| 15943 |
} |
| 15944 |
|
| 15945 |
/* Return true if we need to split op0 = op1 + op2 into a sequence of |
| 15946 |
move and add to avoid AGU stalls. */ |
| 15947 |
|
| 15948 |
bool |
| 15949 |
ix86_avoid_lea_for_add (rtx_insn *insn, rtx operands[]) |
| 15950 |
{ |
| 15951 |
unsigned int regno0, regno1, regno2; |
| 15952 |
|
| 15953 |
/* Check if we need to optimize. */ |
| 15954 |
if (!TARGET_OPT_AGU || optimize_function_for_size_p (cfun)) |
| 15955 |
return false; |
| 15956 |
|
| 15957 |
regno0 = true_regnum (operands[0]); |
| 15958 |
regno1 = true_regnum (operands[1]); |
| 15959 |
regno2 = true_regnum (operands[2]); |
| 15960 |
|
| 15961 |
/* We need to split only adds with non destructive |
| 15962 |
destination operand. */ |
| 15963 |
if (regno0 == regno1 || regno0 == regno2) |
| 15964 |
return false; |
| 15965 |
else |
| 15966 |
return !ix86_lea_outperforms (insn, regno0, regno1, regno2, 1, false); |
| 15967 |
} |
| 15968 |
|
| 15969 |
/* Return true if we should emit lea instruction instead of mov |
| 15970 |
instruction. */ |
| 15971 |
|
| 15972 |
bool |
| 15973 |
ix86_use_lea_for_mov (rtx_insn *insn, rtx operands[]) |
| 15974 |
{ |
| 15975 |
unsigned int regno0, regno1; |
| 15976 |
|
| 15977 |
/* Check if we need to optimize. */ |
| 15978 |
if (!TARGET_OPT_AGU || optimize_function_for_size_p (cfun)) |
| 15979 |
return false; |
| 15980 |
|
| 15981 |
/* Use lea for reg to reg moves only. */ |
| 15982 |
if (!REG_P (operands[0]) || !REG_P (operands[1])) |
| 15983 |
return false; |
| 15984 |
|
| 15985 |
regno0 = true_regnum (operands[0]); |
| 15986 |
regno1 = true_regnum (operands[1]); |
| 15987 |
|
| 15988 |
return ix86_lea_outperforms (insn, regno0, regno1, INVALID_REGNUM, 0, false); |
| 15989 |
} |
| 15990 |
|
| 15991 |
/* Return true if we need to split lea into a sequence of |
| 15992 |
instructions to avoid AGU stalls during peephole2. */ |
| 15993 |
|
| 15994 |
bool |
| 15995 |
ix86_avoid_lea_for_addr (rtx_insn *insn, rtx operands[]) |
| 15996 |
{ |
| 15997 |
unsigned int regno0, regno1, regno2; |
| 15998 |
int split_cost; |
| 15999 |
struct ix86_address parts; |
| 16000 |
int ok; |
| 16001 |
|
| 16002 |
/* The "at least two components" test below might not catch simple |
| 16003 |
move or zero extension insns if parts.base is non-NULL and parts.disp |
| 16004 |
is const0_rtx as the only components in the address, e.g. if the |
| 16005 |
register is %rbp or %r13. As this test is much cheaper and moves or |
| 16006 |
zero extensions are the common case, do this check first. */ |
| 16007 |
if (REG_P (operands[1]) |
| 16008 |
|| (SImode_address_operand (operands[1], VOIDmode) |
| 16009 |
&& REG_P (XEXP (operands[1], 0)))) |
| 16010 |
return false; |
| 16011 |
|
| 16012 |
ok = ix86_decompose_address (operands[1], &parts); |
| 16013 |
gcc_assert (ok); |
| 16014 |
|
| 16015 |
/* There should be at least two components in the address. */ |
| 16016 |
if ((parts.base != NULL_RTX) + (parts.index != NULL_RTX) |
| 16017 |
+ (parts.disp != NULL_RTX) + (parts.scale > 1) < 2) |
| 16018 |
return false; |
| 16019 |
|
| 16020 |
/* We should not split into add if non legitimate pic |
| 16021 |
operand is used as displacement. */ |
| 16022 |
if (parts.disp && flag_pic && !LEGITIMATE_PIC_OPERAND_P (parts.disp)) |
| 16023 |
return false; |
| 16024 |
|
| 16025 |
regno0 = true_regnum (operands[0]) ; |
| 16026 |
regno1 = INVALID_REGNUM; |
| 16027 |
regno2 = INVALID_REGNUM; |
| 16028 |
|
| 16029 |
if (parts.base) |
| 16030 |
regno1 = true_regnum (parts.base); |
| 16031 |
if (parts.index) |
| 16032 |
regno2 = true_regnum (parts.index); |
| 16033 |
|
| 16034 |
/* Use add for a = a + b and a = b + a since it is faster and shorter |
| 16035 |
than lea for most processors. For the processors like BONNELL, if |
| 16036 |
the destination register of LEA holds an actual address which will |
| 16037 |
be used soon, LEA is better and otherwise ADD is better. */ |
| 16038 |
if (!TARGET_CPU_P (BONNELL) |
| 16039 |
&& parts.scale == 1 |
| 16040 |
&& (!parts.disp || parts.disp == const0_rtx) |
| 16041 |
&& (regno0 == regno1 || regno0 == regno2)) |
| 16042 |
return true; |
| 16043 |
|
| 16044 |
/* Split with -Oz if the encoding requires fewer bytes. */ |
| 16045 |
if (optimize_size > 1 |
| 16046 |
&& parts.scale > 1 |
| 16047 |
&& !parts.base |
| 16048 |
&& (!parts.disp || parts.disp == const0_rtx)) |
| 16049 |
return true; |
| 16050 |
|
| 16051 |
/* Check we need to optimize. */ |
| 16052 |
if (!TARGET_AVOID_LEA_FOR_ADDR || optimize_function_for_size_p (cfun)) |
| 16053 |
return false; |
| 16054 |
|
| 16055 |
split_cost = 0; |
| 16056 |
|
| 16057 |
/* Compute how many cycles we will add to execution time |
| 16058 |
if split lea into a sequence of instructions. */ |
| 16059 |
if (parts.base || parts.index) |
| 16060 |
{ |
| 16061 |
/* Have to use mov instruction if non desctructive |
| 16062 |
destination form is used. */ |
| 16063 |
if (regno1 != regno0 && regno2 != regno0) |
| 16064 |
split_cost += 1; |
| 16065 |
|
| 16066 |
/* Have to add index to base if both exist. */ |
| 16067 |
if (parts.base && parts.index) |
| 16068 |
split_cost += 1; |
| 16069 |
|
| 16070 |
/* Have to use shift and adds if scale is 2 or greater. */ |
| 16071 |
if (parts.scale > 1) |
| 16072 |
{ |
| 16073 |
if (regno0 != regno1) |
| 16074 |
split_cost += 1; |
| 16075 |
else if (regno2 == regno0) |
| 16076 |
split_cost += 4; |
| 16077 |
else |
| 16078 |
split_cost += parts.scale; |
| 16079 |
} |
| 16080 |
|
| 16081 |
/* Have to use add instruction with immediate if |
| 16082 |
disp is non zero. */ |
| 16083 |
if (parts.disp && parts.disp != const0_rtx) |
| 16084 |
split_cost += 1; |
| 16085 |
|
| 16086 |
/* Subtract the price of lea. */ |
| 16087 |
split_cost -= 1; |
| 16088 |
} |
| 16089 |
|
| 16090 |
return !ix86_lea_outperforms (insn, regno0, regno1, regno2, split_cost, |
| 16091 |
parts.scale > 1); |
| 16092 |
} |
| 16093 |
|
| 16094 |
/* Return true if it is ok to optimize an ADD operation to LEA |
| 16095 |
operation to avoid flag register consumation. For most processors, |
| 16096 |
ADD is faster than LEA. For the processors like BONNELL, if the |
| 16097 |
destination register of LEA holds an actual address which will be |
| 16098 |
used soon, LEA is better and otherwise ADD is better. */ |
| 16099 |
|
| 16100 |
bool |
| 16101 |
ix86_lea_for_add_ok (rtx_insn *insn, rtx operands[]) |
| 16102 |
{ |
| 16103 |
unsigned int regno0 = true_regnum (operands[0]); |
| 16104 |
unsigned int regno1 = true_regnum (operands[1]); |
| 16105 |
unsigned int regno2 = true_regnum (operands[2]); |
| 16106 |
|
| 16107 |
/* If a = b + c, (a!=b && a!=c), must use lea form. */ |
| 16108 |
if (regno0 != regno1 && regno0 != regno2) |
| 16109 |
return true; |
| 16110 |
|
| 16111 |
if (!TARGET_OPT_AGU || optimize_function_for_size_p (cfun)) |
| 16112 |
return false; |
| 16113 |
|
| 16114 |
return ix86_lea_outperforms (insn, regno0, regno1, regno2, 0, false); |
| 16115 |
} |
| 16116 |
|
| 16117 |
/* Return true if destination reg of SET_BODY is shift count of |
| 16118 |
USE_BODY. */ |
| 16119 |
|
| 16120 |
static bool |
| 16121 |
ix86_dep_by_shift_count_body (const_rtx set_body, const_rtx use_body) |
| 16122 |
{ |
| 16123 |
rtx set_dest; |
| 16124 |
rtx shift_rtx; |
| 16125 |
int i; |
| 16126 |
|
| 16127 |
/* Retrieve destination of SET_BODY. */ |
| 16128 |
switch (GET_CODE (set_body)) |
| 16129 |
{ |
| 16130 |
case SET: |
| 16131 |
set_dest = SET_DEST (set_body); |
| 16132 |
if (!set_dest || !REG_P (set_dest)) |
| 16133 |
return false; |
| 16134 |
break; |
| 16135 |
case PARALLEL: |
| 16136 |
for (i = XVECLEN (set_body, 0) - 1; i >= 0; i--) |
| 16137 |
if (ix86_dep_by_shift_count_body (XVECEXP (set_body, 0, i), |
| 16138 |
use_body)) |
| 16139 |
return true; |
| 16140 |
/* FALLTHROUGH */ |
| 16141 |
default: |
| 16142 |
return false; |
| 16143 |
} |
| 16144 |
|
| 16145 |
/* Retrieve shift count of USE_BODY. */ |
| 16146 |
switch (GET_CODE (use_body)) |
| 16147 |
{ |
| 16148 |
case SET: |
| 16149 |
shift_rtx = XEXP (use_body, 1); |
| 16150 |
break; |
| 16151 |
case PARALLEL: |
| 16152 |
for (i = XVECLEN (use_body, 0) - 1; i >= 0; i--) |
| 16153 |
if (ix86_dep_by_shift_count_body (set_body, |
| 16154 |
XVECEXP (use_body, 0, i))) |
| 16155 |
return true; |
| 16156 |
/* FALLTHROUGH */ |
| 16157 |
default: |
| 16158 |
return false; |
| 16159 |
} |
| 16160 |
|
| 16161 |
if (shift_rtx |
| 16162 |
&& (GET_CODE (shift_rtx) == ASHIFT |
| 16163 |
|| GET_CODE (shift_rtx) == LSHIFTRT |
| 16164 |
|| GET_CODE (shift_rtx) == ASHIFTRT |
| 16165 |
|| GET_CODE (shift_rtx) == ROTATE |
| 16166 |
|| GET_CODE (shift_rtx) == ROTATERT)) |
| 16167 |
{ |
| 16168 |
rtx shift_count = XEXP (shift_rtx, 1); |
| 16169 |
|
| 16170 |
/* Return true if shift count is dest of SET_BODY. */ |
| 16171 |
if (REG_P (shift_count)) |
| 16172 |
{ |
| 16173 |
/* Add check since it can be invoked before register |
| 16174 |
allocation in pre-reload schedule. */ |
| 16175 |
if (reload_completed |
| 16176 |
&& true_regnum (set_dest) == true_regnum (shift_count)) |
| 16177 |
return true; |
| 16178 |
else if (REGNO(set_dest) == REGNO(shift_count)) |
| 16179 |
return true; |
| 16180 |
} |
| 16181 |
} |
| 16182 |
|
| 16183 |
return false; |
| 16184 |
} |
| 16185 |
|
| 16186 |
/* Return true if destination reg of SET_INSN is shift count of |
| 16187 |
USE_INSN. */ |
| 16188 |
|
| 16189 |
bool |
| 16190 |
ix86_dep_by_shift_count (const_rtx set_insn, const_rtx use_insn) |
| 16191 |
{ |
| 16192 |
return ix86_dep_by_shift_count_body (PATTERN (set_insn), |
| 16193 |
PATTERN (use_insn)); |
| 16194 |
} |
| 16195 |
|
| 16196 |
/* Return TRUE if the operands to a vec_interleave_{high,low}v2df |
| 16197 |
are ok, keeping in mind the possible movddup alternative. */ |
| 16198 |
|
| 16199 |
bool |
| 16200 |
ix86_vec_interleave_v2df_operator_ok (rtx operands[3], bool high) |
| 16201 |
{ |
| 16202 |
if (MEM_P (operands[0])) |
| 16203 |
return rtx_equal_p (operands[0], operands[1 + high]); |
| 16204 |
if (MEM_P (operands[1]) && MEM_P (operands[2])) |
| 16205 |
return false; |
| 16206 |
return true; |
| 16207 |
} |
| 16208 |
|
| 16209 |
/* A subroutine of ix86_build_signbit_mask. If VECT is true, |
| 16210 |
then replicate the value for all elements of the vector |
| 16211 |
register. */ |
| 16212 |
|
| 16213 |
rtx |
| 16214 |
ix86_build_const_vector (machine_mode mode, bool vect, rtx value) |
| 16215 |
{ |
| 16216 |
int i, n_elt; |
| 16217 |
rtvec v; |
| 16218 |
machine_mode scalar_mode; |
| 16219 |
|
| 16220 |
switch (mode) |
| 16221 |
{ |
| 16222 |
case E_V64QImode: |
| 16223 |
case E_V32QImode: |
| 16224 |
case E_V16QImode: |
| 16225 |
case E_V32HImode: |
| 16226 |
case E_V16HImode: |
| 16227 |
case E_V8HImode: |
| 16228 |
case E_V16SImode: |
| 16229 |
case E_V8SImode: |
| 16230 |
case E_V4SImode: |
| 16231 |
case E_V2SImode: |
| 16232 |
case E_V8DImode: |
| 16233 |
case E_V4DImode: |
| 16234 |
case E_V2DImode: |
| 16235 |
gcc_assert (vect); |
| 16236 |
/* FALLTHRU */ |
| 16237 |
case E_V2HFmode: |
| 16238 |
case E_V4HFmode: |
| 16239 |
case E_V8HFmode: |
| 16240 |
case E_V16HFmode: |
| 16241 |
case E_V32HFmode: |
| 16242 |
case E_V16SFmode: |
| 16243 |
case E_V8SFmode: |
| 16244 |
case E_V4SFmode: |
| 16245 |
case E_V2SFmode: |
| 16246 |
case E_V8DFmode: |
| 16247 |
case E_V4DFmode: |
| 16248 |
case E_V2DFmode: |
| 16249 |
case E_V32BFmode: |
| 16250 |
case E_V16BFmode: |
| 16251 |
case E_V8BFmode: |
| 16252 |
case E_V4BFmode: |
| 16253 |
case E_V2BFmode: |
| 16254 |
n_elt = GET_MODE_NUNITS (mode); |
| 16255 |
v = rtvec_alloc (n_elt); |
| 16256 |
scalar_mode = GET_MODE_INNER (mode); |
| 16257 |
|
| 16258 |
RTVEC_ELT (v, 0) = value; |
| 16259 |
|
| 16260 |
for (i = 1; i < n_elt; ++i) |
| 16261 |
RTVEC_ELT (v, i) = vect ? value : CONST0_RTX (scalar_mode); |
| 16262 |
|
| 16263 |
return gen_rtx_CONST_VECTOR (mode, v); |
| 16264 |
|
| 16265 |
default: |
| 16266 |
gcc_unreachable (); |
| 16267 |
} |
| 16268 |
} |
| 16269 |
|
| 16270 |
/* A subroutine of ix86_expand_fp_absneg_operator, copysign expanders |
| 16271 |
and ix86_expand_int_vcond. Create a mask for the sign bit in MODE |
| 16272 |
for an SSE register. If VECT is true, then replicate the mask for |
| 16273 |
all elements of the vector register. If INVERT is true, then create |
| 16274 |
a mask excluding the sign bit. */ |
| 16275 |
|
| 16276 |
rtx |
| 16277 |
ix86_build_signbit_mask (machine_mode mode, bool vect, bool invert) |
| 16278 |
{ |
| 16279 |
machine_mode vec_mode, imode; |
| 16280 |
wide_int w; |
| 16281 |
rtx mask, v; |
| 16282 |
|
| 16283 |
switch (mode) |
| 16284 |
{ |
| 16285 |
case E_V2HFmode: |
| 16286 |
case E_V4HFmode: |
| 16287 |
case E_V8HFmode: |
| 16288 |
case E_V16HFmode: |
| 16289 |
case E_V32HFmode: |
| 16290 |
case E_V32BFmode: |
| 16291 |
case E_V16BFmode: |
| 16292 |
case E_V8BFmode: |
| 16293 |
case E_V4BFmode: |
| 16294 |
case E_V2BFmode: |
| 16295 |
vec_mode = mode; |
| 16296 |
imode = HImode; |
| 16297 |
break; |
| 16298 |
|
| 16299 |
case E_V16SImode: |
| 16300 |
case E_V16SFmode: |
| 16301 |
case E_V8SImode: |
| 16302 |
case E_V4SImode: |
| 16303 |
case E_V8SFmode: |
| 16304 |
case E_V4SFmode: |
| 16305 |
case E_V2SFmode: |
| 16306 |
case E_V2SImode: |
| 16307 |
vec_mode = mode; |
| 16308 |
imode = SImode; |
| 16309 |
break; |
| 16310 |
|
| 16311 |
case E_V8DImode: |
| 16312 |
case E_V4DImode: |
| 16313 |
case E_V2DImode: |
| 16314 |
case E_V8DFmode: |
| 16315 |
case E_V4DFmode: |
| 16316 |
case E_V2DFmode: |
| 16317 |
vec_mode = mode; |
| 16318 |
imode = DImode; |
| 16319 |
break; |
| 16320 |
|
| 16321 |
case E_TImode: |
| 16322 |
case E_TFmode: |
| 16323 |
vec_mode = VOIDmode; |
| 16324 |
imode = TImode; |
| 16325 |
break; |
| 16326 |
|
| 16327 |
default: |
| 16328 |
gcc_unreachable (); |
| 16329 |
} |
| 16330 |
|
| 16331 |
machine_mode inner_mode = GET_MODE_INNER (mode); |
| 16332 |
w = wi::set_bit_in_zero (GET_MODE_BITSIZE (inner_mode) - 1, |
| 16333 |
GET_MODE_BITSIZE (inner_mode)); |
| 16334 |
if (invert) |
| 16335 |
w = wi::bit_not (w); |
| 16336 |
|
| 16337 |
/* Force this value into the low part of a fp vector constant. */ |
| 16338 |
mask = immed_wide_int_const (w, imode); |
| 16339 |
mask = gen_lowpart (inner_mode, mask); |
| 16340 |
|
| 16341 |
if (vec_mode == VOIDmode) |
| 16342 |
return force_reg (inner_mode, mask); |
| 16343 |
|
| 16344 |
v = ix86_build_const_vector (vec_mode, vect, mask); |
| 16345 |
return force_reg (vec_mode, v); |
| 16346 |
} |
| 16347 |
|
| 16348 |
/* Return HOST_WIDE_INT for const vector OP in MODE. */ |
| 16349 |
|
| 16350 |
HOST_WIDE_INT |
| 16351 |
ix86_convert_const_vector_to_integer (rtx op, machine_mode mode) |
| 16352 |
{ |
| 16353 |
if (GET_MODE_SIZE (mode) > UNITS_PER_WORD) |
| 16354 |
gcc_unreachable (); |
| 16355 |
|
| 16356 |
int nunits = GET_MODE_NUNITS (mode); |
| 16357 |
wide_int val = wi::zero (GET_MODE_BITSIZE (mode)); |
| 16358 |
machine_mode innermode = GET_MODE_INNER (mode); |
| 16359 |
unsigned int innermode_bits = GET_MODE_BITSIZE (innermode); |
| 16360 |
|
| 16361 |
switch (mode) |
| 16362 |
{ |
| 16363 |
case E_V2QImode: |
| 16364 |
case E_V4QImode: |
| 16365 |
case E_V2HImode: |
| 16366 |
case E_V8QImode: |
| 16367 |
case E_V4HImode: |
| 16368 |
case E_V2SImode: |
| 16369 |
for (int i = 0; i < nunits; ++i) |
| 16370 |
{ |
| 16371 |
int v = INTVAL (XVECEXP (op, 0, i)); |
| 16372 |
wide_int wv = wi::shwi (v, innermode_bits); |
| 16373 |
val = wi::insert (val, wv, innermode_bits * i, innermode_bits); |
| 16374 |
} |
| 16375 |
break; |
| 16376 |
case E_V2HFmode: |
| 16377 |
case E_V2BFmode: |
| 16378 |
case E_V4HFmode: |
| 16379 |
case E_V4BFmode: |
| 16380 |
case E_V2SFmode: |
| 16381 |
for (int i = 0; i < nunits; ++i) |
| 16382 |
{ |
| 16383 |
rtx x = XVECEXP (op, 0, i); |
| 16384 |
int v = real_to_target (NULL, CONST_DOUBLE_REAL_VALUE (x), |
| 16385 |
REAL_MODE_FORMAT (innermode)); |
| 16386 |
wide_int wv = wi::shwi (v, innermode_bits); |
| 16387 |
val = wi::insert (val, wv, innermode_bits * i, innermode_bits); |
| 16388 |
} |
| 16389 |
break; |
| 16390 |
default: |
| 16391 |
gcc_unreachable (); |
| 16392 |
} |
| 16393 |
|
| 16394 |
return val.to_shwi (); |
| 16395 |
} |
| 16396 |
|
| 16397 |
int ix86_get_flags_cc (rtx_code code) |
| 16398 |
{ |
| 16399 |
switch (code) |
| 16400 |
{ |
| 16401 |
case NE: return X86_CCNE; |
| 16402 |
case EQ: return X86_CCE; |
| 16403 |
case GE: return X86_CCNL; |
| 16404 |
case GT: return X86_CCNLE; |
| 16405 |
case LE: return X86_CCLE; |
| 16406 |
case LT: return X86_CCL; |
| 16407 |
case GEU: return X86_CCNB; |
| 16408 |
case GTU: return X86_CCNBE; |
| 16409 |
case LEU: return X86_CCBE; |
| 16410 |
case LTU: return X86_CCB; |
| 16411 |
default: return -1; |
| 16412 |
} |
| 16413 |
} |
| 16414 |
|
| 16415 |
/* Return TRUE or FALSE depending on whether the first SET in INSN |
| 16416 |
has source and destination with matching CC modes, and that the |
| 16417 |
CC mode is at least as constrained as REQ_MODE. */ |
| 16418 |
|
| 16419 |
bool |
| 16420 |
ix86_match_ccmode (rtx insn, machine_mode req_mode) |
| 16421 |
{ |
| 16422 |
rtx set; |
| 16423 |
machine_mode set_mode; |
| 16424 |
|
| 16425 |
set = PATTERN (insn); |
| 16426 |
if (GET_CODE (set) == PARALLEL) |
| 16427 |
set = XVECEXP (set, 0, 0); |
| 16428 |
gcc_assert (GET_CODE (set) == SET); |
| 16429 |
gcc_assert (GET_CODE (SET_SRC (set)) == COMPARE); |
| 16430 |
|
| 16431 |
set_mode = GET_MODE (SET_DEST (set)); |
| 16432 |
switch (set_mode) |
| 16433 |
{ |
| 16434 |
case E_CCNOmode: |
| 16435 |
if (req_mode != CCNOmode |
| 16436 |
&& (req_mode != CCmode |
| 16437 |
|| XEXP (SET_SRC (set), 1) != const0_rtx)) |
| 16438 |
return false; |
| 16439 |
break; |
| 16440 |
case E_CCmode: |
| 16441 |
if (req_mode == CCGCmode) |
| 16442 |
return false; |
| 16443 |
/* FALLTHRU */ |
| 16444 |
case E_CCGCmode: |
| 16445 |
if (req_mode == CCGOCmode || req_mode == CCNOmode) |
| 16446 |
return false; |
| 16447 |
/* FALLTHRU */ |
| 16448 |
case E_CCGOCmode: |
| 16449 |
if (req_mode == CCZmode) |
| 16450 |
return false; |
| 16451 |
/* FALLTHRU */ |
| 16452 |
case E_CCZmode: |
| 16453 |
break; |
| 16454 |
|
| 16455 |
case E_CCGZmode: |
| 16456 |
|
| 16457 |
case E_CCAmode: |
| 16458 |
case E_CCCmode: |
| 16459 |
case E_CCOmode: |
| 16460 |
case E_CCPmode: |
| 16461 |
case E_CCSmode: |
| 16462 |
if (set_mode != req_mode) |
| 16463 |
return false; |
| 16464 |
break; |
| 16465 |
|
| 16466 |
default: |
| 16467 |
gcc_unreachable (); |
| 16468 |
} |
| 16469 |
|
| 16470 |
return GET_MODE (SET_SRC (set)) == set_mode; |
| 16471 |
} |
| 16472 |
|
| 16473 |
machine_mode |
| 16474 |
ix86_cc_mode (enum rtx_code code, rtx op0, rtx op1) |
| 16475 |
{ |
| 16476 |
machine_mode mode = GET_MODE (op0); |
| 16477 |
|
| 16478 |
if (SCALAR_FLOAT_MODE_P (mode)) |
| 16479 |
{ |
| 16480 |
gcc_assert (!DECIMAL_FLOAT_MODE_P (mode)); |
| 16481 |
return CCFPmode; |
| 16482 |
} |
| 16483 |
|
| 16484 |
switch (code) |
| 16485 |
{ |
| 16486 |
/* Only zero flag is needed. */ |
| 16487 |
case EQ: /* ZF=0 */ |
| 16488 |
case NE: /* ZF!=0 */ |
| 16489 |
return CCZmode; |
| 16490 |
/* Codes needing carry flag. */ |
| 16491 |
case GEU: /* CF=0 */ |
| 16492 |
case LTU: /* CF=1 */ |
| 16493 |
rtx geu; |
| 16494 |
/* Detect overflow checks. They need just the carry flag. */ |
| 16495 |
if (GET_CODE (op0) == PLUS |
| 16496 |
&& (rtx_equal_p (op1, XEXP (op0, 0)) |
| 16497 |
|| rtx_equal_p (op1, XEXP (op0, 1)))) |
| 16498 |
return CCCmode; |
| 16499 |
/* Similarly for *setcc_qi_addqi3_cconly_overflow_1_* patterns. |
| 16500 |
Match LTU of op0 |
| 16501 |
(neg:QI (geu:QI (reg:CC_CCC FLAGS_REG) (const_int 0))) |
| 16502 |
and op1 |
| 16503 |
(ltu:QI (reg:CC_CCC FLAGS_REG) (const_int 0)) |
| 16504 |
where CC_CCC is either CC or CCC. */ |
| 16505 |
else if (code == LTU |
| 16506 |
&& GET_CODE (op0) == NEG |
| 16507 |
&& GET_CODE (geu = XEXP (op0, 0)) == GEU |
| 16508 |
&& REG_P (XEXP (geu, 0)) |
| 16509 |
&& (GET_MODE (XEXP (geu, 0)) == CCCmode |
| 16510 |
|| GET_MODE (XEXP (geu, 0)) == CCmode) |
| 16511 |
&& REGNO (XEXP (geu, 0)) == FLAGS_REG |
| 16512 |
&& XEXP (geu, 1) == const0_rtx |
| 16513 |
&& GET_CODE (op1) == LTU |
| 16514 |
&& REG_P (XEXP (op1, 0)) |
| 16515 |
&& GET_MODE (XEXP (op1, 0)) == GET_MODE (XEXP (geu, 0)) |
| 16516 |
&& REGNO (XEXP (op1, 0)) == FLAGS_REG |
| 16517 |
&& XEXP (op1, 1) == const0_rtx) |
| 16518 |
return CCCmode; |
| 16519 |
/* Similarly for *x86_cmc pattern. |
| 16520 |
Match LTU of op0 (neg:QI (ltu:QI (reg:CCC FLAGS_REG) (const_int 0))) |
| 16521 |
and op1 (geu:QI (reg:CCC FLAGS_REG) (const_int 0)). |
| 16522 |
It is sufficient to test that the operand modes are CCCmode. */ |
| 16523 |
else if (code == LTU |
| 16524 |
&& GET_CODE (op0) == NEG |
| 16525 |
&& GET_CODE (XEXP (op0, 0)) == LTU |
| 16526 |
&& GET_MODE (XEXP (XEXP (op0, 0), 0)) == CCCmode |
| 16527 |
&& GET_CODE (op1) == GEU |
| 16528 |
&& GET_MODE (XEXP (op1, 0)) == CCCmode) |
| 16529 |
return CCCmode; |
| 16530 |
/* Similarly for the comparison of addcarry/subborrow pattern. */ |
| 16531 |
else if (code == LTU |
| 16532 |
&& GET_CODE (op0) == ZERO_EXTEND |
| 16533 |
&& GET_CODE (op1) == PLUS |
| 16534 |
&& ix86_carry_flag_operator (XEXP (op1, 0), VOIDmode) |
| 16535 |
&& GET_CODE (XEXP (op1, 1)) == ZERO_EXTEND) |
| 16536 |
return CCCmode; |
| 16537 |
else |
| 16538 |
return CCmode; |
| 16539 |
case GTU: /* CF=0 & ZF=0 */ |
| 16540 |
case LEU: /* CF=1 | ZF=1 */ |
| 16541 |
return CCmode; |
| 16542 |
/* Codes possibly doable only with sign flag when |
| 16543 |
comparing against zero. */ |
| 16544 |
case GE: /* SF=OF or SF=0 */ |
| 16545 |
case LT: /* SF<>OF or SF=1 */ |
| 16546 |
if (op1 == const0_rtx) |
| 16547 |
return CCGOCmode; |
| 16548 |
else |
| 16549 |
/* For other cases Carry flag is not required. */ |
| 16550 |
return CCGCmode; |
| 16551 |
/* Codes doable only with sign flag when comparing |
| 16552 |
against zero, but we miss jump instruction for it |
| 16553 |
so we need to use relational tests against overflow |
| 16554 |
that thus needs to be zero. */ |
| 16555 |
case GT: /* ZF=0 & SF=OF */ |
| 16556 |
case LE: /* ZF=1 | SF<>OF */ |
| 16557 |
if (op1 == const0_rtx) |
| 16558 |
return CCNOmode; |
| 16559 |
else |
| 16560 |
return CCGCmode; |
| 16561 |
default: |
| 16562 |
/* CCmode should be used in all other cases. */ |
| 16563 |
return CCmode; |
| 16564 |
} |
| 16565 |
} |
| 16566 |
|
| 16567 |
/* Return TRUE or FALSE depending on whether the ptest instruction |
| 16568 |
INSN has source and destination with suitable matching CC modes. */ |
| 16569 |
|
| 16570 |
bool |
| 16571 |
ix86_match_ptest_ccmode (rtx insn) |
| 16572 |
{ |
| 16573 |
rtx set, src; |
| 16574 |
machine_mode set_mode; |
| 16575 |
|
| 16576 |
set = PATTERN (insn); |
| 16577 |
gcc_assert (GET_CODE (set) == SET); |
| 16578 |
src = SET_SRC (set); |
| 16579 |
gcc_assert (GET_CODE (src) == UNSPEC |
| 16580 |
&& XINT (src, 1) == UNSPEC_PTEST); |
| 16581 |
|
| 16582 |
set_mode = GET_MODE (src); |
| 16583 |
if (set_mode != CCZmode |
| 16584 |
&& set_mode != CCCmode |
| 16585 |
&& set_mode != CCmode) |
| 16586 |
return false; |
| 16587 |
return GET_MODE (SET_DEST (set)) == set_mode; |
| 16588 |
} |
| 16589 |
|
| 16590 |
/* Return the fixed registers used for condition codes. */ |
| 16591 |
|
| 16592 |
static bool |
| 16593 |
ix86_fixed_condition_code_regs (unsigned int *p1, unsigned int *p2) |
| 16594 |
{ |
| 16595 |
*p1 = FLAGS_REG; |
| 16596 |
*p2 = INVALID_REGNUM; |
| 16597 |
return true; |
| 16598 |
} |
| 16599 |
|
| 16600 |
/* If two condition code modes are compatible, return a condition code |
| 16601 |
mode which is compatible with both. Otherwise, return |
| 16602 |
VOIDmode. */ |
| 16603 |
|
| 16604 |
static machine_mode |
| 16605 |
ix86_cc_modes_compatible (machine_mode m1, machine_mode m2) |
| 16606 |
{ |
| 16607 |
if (m1 == m2) |
| 16608 |
return m1; |
| 16609 |
|
| 16610 |
if (GET_MODE_CLASS (m1) != MODE_CC || GET_MODE_CLASS (m2) != MODE_CC) |
| 16611 |
return VOIDmode; |
| 16612 |
|
| 16613 |
if ((m1 == CCGCmode && m2 == CCGOCmode) |
| 16614 |
|| (m1 == CCGOCmode && m2 == CCGCmode)) |
| 16615 |
return CCGCmode; |
| 16616 |
|
| 16617 |
if ((m1 == CCNOmode && m2 == CCGOCmode) |
| 16618 |
|| (m1 == CCGOCmode && m2 == CCNOmode)) |
| 16619 |
return CCNOmode; |
| 16620 |
|
| 16621 |
if (m1 == CCZmode |
| 16622 |
&& (m2 == CCGCmode || m2 == CCGOCmode || m2 == CCNOmode)) |
| 16623 |
return m2; |
| 16624 |
else if (m2 == CCZmode |
| 16625 |
&& (m1 == CCGCmode || m1 == CCGOCmode || m1 == CCNOmode)) |
| 16626 |
return m1; |
| 16627 |
|
| 16628 |
switch (m1) |
| 16629 |
{ |
| 16630 |
default: |
| 16631 |
gcc_unreachable (); |
| 16632 |
|
| 16633 |
case E_CCmode: |
| 16634 |
case E_CCGCmode: |
| 16635 |
case E_CCGOCmode: |
| 16636 |
case E_CCNOmode: |
| 16637 |
case E_CCAmode: |
| 16638 |
case E_CCCmode: |
| 16639 |
case E_CCOmode: |
| 16640 |
case E_CCPmode: |
| 16641 |
case E_CCSmode: |
| 16642 |
case E_CCZmode: |
| 16643 |
switch (m2) |
| 16644 |
{ |
| 16645 |
default: |
| 16646 |
return VOIDmode; |
| 16647 |
|
| 16648 |
case E_CCmode: |
| 16649 |
case E_CCGCmode: |
| 16650 |
case E_CCGOCmode: |
| 16651 |
case E_CCNOmode: |
| 16652 |
case E_CCAmode: |
| 16653 |
case E_CCCmode: |
| 16654 |
case E_CCOmode: |
| 16655 |
case E_CCPmode: |
| 16656 |
case E_CCSmode: |
| 16657 |
case E_CCZmode: |
| 16658 |
return CCmode; |
| 16659 |
} |
| 16660 |
|
| 16661 |
case E_CCFPmode: |
| 16662 |
/* These are only compatible with themselves, which we already |
| 16663 |
checked above. */ |
| 16664 |
return VOIDmode; |
| 16665 |
} |
| 16666 |
} |
| 16667 |
|
| 16668 |
/* Return strategy to use for floating-point. We assume that fcomi is always |
| 16669 |
preferrable where available, since that is also true when looking at size |
| 16670 |
(2 bytes, vs. 3 for fnstsw+sahf and at least 5 for fnstsw+test). */ |
| 16671 |
|
| 16672 |
enum ix86_fpcmp_strategy |
| 16673 |
ix86_fp_comparison_strategy (enum rtx_code) |
| 16674 |
{ |
| 16675 |
/* Do fcomi/sahf based test when profitable. */ |
| 16676 |
|
| 16677 |
if (TARGET_CMOVE) |
| 16678 |
return IX86_FPCMP_COMI; |
| 16679 |
|
| 16680 |
if (TARGET_SAHF && (TARGET_USE_SAHF || optimize_insn_for_size_p ())) |
| 16681 |
return IX86_FPCMP_SAHF; |
| 16682 |
|
| 16683 |
return IX86_FPCMP_ARITH; |
| 16684 |
} |
| 16685 |
|
| 16686 |
/* Convert comparison codes we use to represent FP comparison to integer |
| 16687 |
code that will result in proper branch. Return UNKNOWN if no such code |
| 16688 |
is available. */ |
| 16689 |
|
| 16690 |
enum rtx_code |
| 16691 |
ix86_fp_compare_code_to_integer (enum rtx_code code) |
| 16692 |
{ |
| 16693 |
switch (code) |
| 16694 |
{ |
| 16695 |
case GT: |
| 16696 |
return GTU; |
| 16697 |
case GE: |
| 16698 |
return GEU; |
| 16699 |
case ORDERED: |
| 16700 |
case UNORDERED: |
| 16701 |
return code; |
| 16702 |
case UNEQ: |
| 16703 |
return EQ; |
| 16704 |
case UNLT: |
| 16705 |
return LTU; |
| 16706 |
case UNLE: |
| 16707 |
return LEU; |
| 16708 |
case LTGT: |
| 16709 |
return NE; |
| 16710 |
case EQ: |
| 16711 |
case NE: |
| 16712 |
if (TARGET_AVX10_2) |
| 16713 |
return code; |
| 16714 |
/* FALLTHRU. */ |
| 16715 |
default: |
| 16716 |
return UNKNOWN; |
| 16717 |
} |
| 16718 |
} |
| 16719 |
|
| 16720 |
/* Zero extend possibly SImode EXP to Pmode register. */ |
| 16721 |
rtx |
| 16722 |
ix86_zero_extend_to_Pmode (rtx exp) |
| 16723 |
{ |
| 16724 |
return force_reg (Pmode, convert_to_mode (Pmode, exp, 1)); |
| 16725 |
} |
| 16726 |
|
| 16727 |
/* Return true if the function is called via PLT. */ |
| 16728 |
|
| 16729 |
bool |
| 16730 |
ix86_call_use_plt_p (rtx call_op) |
| 16731 |
{ |
| 16732 |
if (SYMBOL_REF_LOCAL_P (call_op)) |
| 16733 |
{ |
| 16734 |
if (SYMBOL_REF_DECL (call_op) |
| 16735 |
&& TREE_CODE (SYMBOL_REF_DECL (call_op)) == FUNCTION_DECL) |
| 16736 |
{ |
| 16737 |
/* NB: All ifunc functions must be called via PLT. */ |
| 16738 |
cgraph_node *node |
| 16739 |
= cgraph_node::get (SYMBOL_REF_DECL (call_op)); |
| 16740 |
if (node && node->ifunc_resolver) |
| 16741 |
return true; |
| 16742 |
} |
| 16743 |
return false; |
| 16744 |
} |
| 16745 |
return true; |
| 16746 |
} |
| 16747 |
|
| 16748 |
/* Implement TARGET_IFUNC_REF_LOCAL_OK. If this hook returns true, |
| 16749 |
the PLT entry will be used as the function address for local IFUNC |
| 16750 |
functions. When the PIC register is needed for PLT call, indirect |
| 16751 |
call via the PLT entry will fail since the PIC register may not be |
| 16752 |
set up properly for indirect call. In this case, we should return |
| 16753 |
false. */ |
| 16754 |
|
| 16755 |
static bool |
| 16756 |
ix86_ifunc_ref_local_ok (void) |
| 16757 |
{ |
| 16758 |
return !flag_pic || (TARGET_64BIT && ix86_cmodel != CM_LARGE_PIC); |
| 16759 |
} |
| 16760 |
|
| 16761 |
/* Return true if the function being called was marked with attribute |
| 16762 |
"noplt" or using -fno-plt and we are compiling for non-PIC. We need |
| 16763 |
to handle the non-PIC case in the backend because there is no easy |
| 16764 |
interface for the front-end to force non-PLT calls to use the GOT. |
| 16765 |
This is currently used only with 64-bit or 32-bit GOT32X ELF targets |
| 16766 |
to call the function marked "noplt" indirectly. */ |
| 16767 |
|
| 16768 |
bool |
| 16769 |
ix86_nopic_noplt_attribute_p (rtx call_op) |
| 16770 |
{ |
| 16771 |
if (flag_pic || ix86_cmodel == CM_LARGE |
| 16772 |
|| !(TARGET_64BIT || HAVE_AS_IX86_GOT32X) |
| 16773 |
|| TARGET_MACHO || TARGET_SEH || TARGET_PECOFF |
| 16774 |
|| SYMBOL_REF_LOCAL_P (call_op)) |
| 16775 |
return false; |
| 16776 |
|
| 16777 |
tree symbol_decl = SYMBOL_REF_DECL (call_op); |
| 16778 |
|
| 16779 |
if (!flag_plt |
| 16780 |
|| (symbol_decl != NULL_TREE |
| 16781 |
&& lookup_attribute ("noplt", DECL_ATTRIBUTES (symbol_decl)))) |
| 16782 |
return true; |
| 16783 |
|
| 16784 |
return false; |
| 16785 |
} |
| 16786 |
|
| 16787 |
/* Helper to output the jmp/call. */ |
| 16788 |
static void |
| 16789 |
ix86_output_jmp_thunk_or_indirect (const char *thunk_name, const int regno) |
| 16790 |
{ |
| 16791 |
if (thunk_name != NULL) |
| 16792 |
{ |
| 16793 |
if ((REX_INT_REGNO_P (regno) || REX2_INT_REGNO_P (regno)) |
| 16794 |
&& ix86_indirect_branch_cs_prefix) |
| 16795 |
fprintf (asm_out_file, "\tcs\n"); |
| 16796 |
fprintf (asm_out_file, "\tjmp\t"); |
| 16797 |
assemble_name (asm_out_file, thunk_name); |
| 16798 |
putc ('\n', asm_out_file); |
| 16799 |
if ((ix86_harden_sls & harden_sls_indirect_jmp)) |
| 16800 |
fputs ("\tint3\n", asm_out_file); |
| 16801 |
} |
| 16802 |
else |
| 16803 |
output_indirect_thunk (regno); |
| 16804 |
} |
| 16805 |
|
| 16806 |
/* Output indirect branch via a call and return thunk. CALL_OP is a |
| 16807 |
register which contains the branch target. XASM is the assembly |
| 16808 |
template for CALL_OP. Branch is a tail call if SIBCALL_P is true. |
| 16809 |
A normal call is converted to: |
| 16810 |
|
| 16811 |
call __x86_indirect_thunk_reg |
| 16812 |
|
| 16813 |
and a tail call is converted to: |
| 16814 |
|
| 16815 |
jmp __x86_indirect_thunk_reg |
| 16816 |
*/ |
| 16817 |
|
| 16818 |
static void |
| 16819 |
ix86_output_indirect_branch_via_reg (rtx call_op, bool sibcall_p) |
| 16820 |
{ |
| 16821 |
char thunk_name_buf[32]; |
| 16822 |
char *thunk_name; |
| 16823 |
enum indirect_thunk_prefix need_prefix |
| 16824 |
= indirect_thunk_need_prefix (current_output_insn); |
| 16825 |
int regno = REGNO (call_op); |
| 16826 |
|
| 16827 |
if (cfun->machine->indirect_branch_type |
| 16828 |
!= indirect_branch_thunk_inline) |
| 16829 |
{ |
| 16830 |
if (cfun->machine->indirect_branch_type == indirect_branch_thunk) |
| 16831 |
SET_HARD_REG_BIT (indirect_thunks_used, regno); |
| 16832 |
|
| 16833 |
indirect_thunk_name (thunk_name_buf, regno, need_prefix, false); |
| 16834 |
thunk_name = thunk_name_buf; |
| 16835 |
} |
| 16836 |
else |
| 16837 |
thunk_name = NULL; |
| 16838 |
|
| 16839 |
if (sibcall_p) |
| 16840 |
ix86_output_jmp_thunk_or_indirect (thunk_name, regno); |
| 16841 |
else |
| 16842 |
{ |
| 16843 |
if (thunk_name != NULL) |
| 16844 |
{ |
| 16845 |
if ((REX_INT_REGNO_P (regno) || REX_INT_REGNO_P (regno)) |
| 16846 |
&& ix86_indirect_branch_cs_prefix) |
| 16847 |
fprintf (asm_out_file, "\tcs\n"); |
| 16848 |
fprintf (asm_out_file, "\tcall\t"); |
| 16849 |
assemble_name (asm_out_file, thunk_name); |
| 16850 |
putc ('\n', asm_out_file); |
| 16851 |
return; |
| 16852 |
} |
| 16853 |
|
| 16854 |
char indirectlabel1[32]; |
| 16855 |
char indirectlabel2[32]; |
| 16856 |
|
| 16857 |
ASM_GENERATE_INTERNAL_LABEL (indirectlabel1, |
| 16858 |
INDIRECT_LABEL, |
| 16859 |
indirectlabelno++); |
| 16860 |
ASM_GENERATE_INTERNAL_LABEL (indirectlabel2, |
| 16861 |
INDIRECT_LABEL, |
| 16862 |
indirectlabelno++); |
| 16863 |
|
| 16864 |
/* Jump. */ |
| 16865 |
fputs ("\tjmp\t", asm_out_file); |
| 16866 |
assemble_name_raw (asm_out_file, indirectlabel2); |
| 16867 |
fputc ('\n', asm_out_file); |
| 16868 |
|
| 16869 |
ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, indirectlabel1); |
| 16870 |
|
| 16871 |
ix86_output_jmp_thunk_or_indirect (thunk_name, regno); |
| 16872 |
|
| 16873 |
ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, indirectlabel2); |
| 16874 |
|
| 16875 |
/* Call. */ |
| 16876 |
fputs ("\tcall\t", asm_out_file); |
| 16877 |
assemble_name_raw (asm_out_file, indirectlabel1); |
| 16878 |
fputc ('\n', asm_out_file); |
| 16879 |
} |
| 16880 |
} |
| 16881 |
|
| 16882 |
/* Output indirect branch via a call and return thunk. CALL_OP is |
| 16883 |
the branch target. XASM is the assembly template for CALL_OP. |
| 16884 |
Branch is a tail call if SIBCALL_P is true. A normal call is |
| 16885 |
converted to: |
| 16886 |
|
| 16887 |
jmp L2 |
| 16888 |
L1: |
| 16889 |
push CALL_OP |
| 16890 |
jmp __x86_indirect_thunk |
| 16891 |
L2: |
| 16892 |
call L1 |
| 16893 |
|
| 16894 |
and a tail call is converted to: |
| 16895 |
|
| 16896 |
push CALL_OP |
| 16897 |
jmp __x86_indirect_thunk |
| 16898 |
*/ |
| 16899 |
|
| 16900 |
static void |
| 16901 |
ix86_output_indirect_branch_via_push (rtx call_op, const char *xasm, |
| 16902 |
bool sibcall_p) |
| 16903 |
{ |
| 16904 |
char thunk_name_buf[32]; |
| 16905 |
char *thunk_name; |
| 16906 |
char push_buf[64]; |
| 16907 |
enum indirect_thunk_prefix need_prefix |
| 16908 |
= indirect_thunk_need_prefix (current_output_insn); |
| 16909 |
int regno = -1; |
| 16910 |
|
| 16911 |
if (cfun->machine->indirect_branch_type |
| 16912 |
!= indirect_branch_thunk_inline) |
| 16913 |
{ |
| 16914 |
if (cfun->machine->indirect_branch_type == indirect_branch_thunk) |
| 16915 |
indirect_thunk_needed = true; |
| 16916 |
indirect_thunk_name (thunk_name_buf, regno, need_prefix, false); |
| 16917 |
thunk_name = thunk_name_buf; |
| 16918 |
} |
| 16919 |
else |
| 16920 |
thunk_name = NULL; |
| 16921 |
|
| 16922 |
snprintf (push_buf, sizeof (push_buf), "push{%c}\t%s", |
| 16923 |
TARGET_64BIT ? 'q' : 'l', xasm); |
| 16924 |
|
| 16925 |
if (sibcall_p) |
| 16926 |
{ |
| 16927 |
output_asm_insn (push_buf, &call_op); |
| 16928 |
ix86_output_jmp_thunk_or_indirect (thunk_name, regno); |
| 16929 |
} |
| 16930 |
else |
| 16931 |
{ |
| 16932 |
char indirectlabel1[32]; |
| 16933 |
char indirectlabel2[32]; |
| 16934 |
|
| 16935 |
ASM_GENERATE_INTERNAL_LABEL (indirectlabel1, |
| 16936 |
INDIRECT_LABEL, |
| 16937 |
indirectlabelno++); |
| 16938 |
ASM_GENERATE_INTERNAL_LABEL (indirectlabel2, |
| 16939 |
INDIRECT_LABEL, |
| 16940 |
indirectlabelno++); |
| 16941 |
|
| 16942 |
/* Jump. */ |
| 16943 |
fputs ("\tjmp\t", asm_out_file); |
| 16944 |
assemble_name_raw (asm_out_file, indirectlabel2); |
| 16945 |
fputc ('\n', asm_out_file); |
| 16946 |
|
| 16947 |
ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, indirectlabel1); |
| 16948 |
|
| 16949 |
/* An external function may be called via GOT, instead of PLT. */ |
| 16950 |
if (MEM_P (call_op)) |
| 16951 |
{ |
| 16952 |
struct ix86_address parts; |
| 16953 |
rtx addr = XEXP (call_op, 0); |
| 16954 |
if (ix86_decompose_address (addr, &parts) |
| 16955 |
&& parts.base == stack_pointer_rtx) |
| 16956 |
{ |
| 16957 |
/* Since call will adjust stack by -UNITS_PER_WORD, |
| 16958 |
we must convert "disp(stack, index, scale)" to |
| 16959 |
"disp+UNITS_PER_WORD(stack, index, scale)". */ |
| 16960 |
if (parts.index) |
| 16961 |
{ |
| 16962 |
addr = gen_rtx_MULT (Pmode, parts.index, |
| 16963 |
GEN_INT (parts.scale)); |
| 16964 |
addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx, |
| 16965 |
addr); |
| 16966 |
} |
| 16967 |
else |
| 16968 |
addr = stack_pointer_rtx; |
| 16969 |
|
| 16970 |
rtx disp; |
| 16971 |
if (parts.disp != NULL_RTX) |
| 16972 |
disp = plus_constant (Pmode, parts.disp, |
| 16973 |
UNITS_PER_WORD); |
| 16974 |
else |
| 16975 |
disp = GEN_INT (UNITS_PER_WORD); |
| 16976 |
|
| 16977 |
addr = gen_rtx_PLUS (Pmode, addr, disp); |
| 16978 |
call_op = gen_rtx_MEM (GET_MODE (call_op), addr); |
| 16979 |
} |
| 16980 |
} |
| 16981 |
|
| 16982 |
output_asm_insn (push_buf, &call_op); |
| 16983 |
|
| 16984 |
ix86_output_jmp_thunk_or_indirect (thunk_name, regno); |
| 16985 |
|
| 16986 |
ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, indirectlabel2); |
| 16987 |
|
| 16988 |
/* Call. */ |
| 16989 |
fputs ("\tcall\t", asm_out_file); |
| 16990 |
assemble_name_raw (asm_out_file, indirectlabel1); |
| 16991 |
fputc ('\n', asm_out_file); |
| 16992 |
} |
| 16993 |
} |
| 16994 |
|
| 16995 |
/* Output indirect branch via a call and return thunk. CALL_OP is |
| 16996 |
the branch target. XASM is the assembly template for CALL_OP. |
| 16997 |
Branch is a tail call if SIBCALL_P is true. */ |
| 16998 |
|
| 16999 |
static void |
| 17000 |
ix86_output_indirect_branch (rtx call_op, const char *xasm, |
| 17001 |
bool sibcall_p) |
| 17002 |
{ |
| 17003 |
if (REG_P (call_op)) |
| 17004 |
ix86_output_indirect_branch_via_reg (call_op, sibcall_p); |
| 17005 |
else |
| 17006 |
ix86_output_indirect_branch_via_push (call_op, xasm, sibcall_p); |
| 17007 |
} |
| 17008 |
|
| 17009 |
/* Output indirect jump. CALL_OP is the jump target. */ |
| 17010 |
|
| 17011 |
const char * |
| 17012 |
ix86_output_indirect_jmp (rtx call_op) |
| 17013 |
{ |
| 17014 |
if (cfun->machine->indirect_branch_type != indirect_branch_keep) |
| 17015 |
{ |
| 17016 |
/* We can't have red-zone since "call" in the indirect thunk |
| 17017 |
pushes the return address onto stack, destroying red-zone. */ |
| 17018 |
if (ix86_red_zone_used) |
| 17019 |
gcc_unreachable (); |
| 17020 |
|
| 17021 |
ix86_output_indirect_branch (call_op, "%0", true); |
| 17022 |
} |
| 17023 |
else |
| 17024 |
output_asm_insn ("%!jmp\t%A0", &call_op); |
| 17025 |
return (ix86_harden_sls & harden_sls_indirect_jmp) ? "int3" : ""; |
| 17026 |
} |
| 17027 |
|
| 17028 |
/* Output return instrumentation for current function if needed. */ |
| 17029 |
|
| 17030 |
static void |
| 17031 |
output_return_instrumentation (void) |
| 17032 |
{ |
| 17033 |
if (ix86_instrument_return != instrument_return_none |
| 17034 |
&& flag_fentry |
| 17035 |
&& !DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (cfun->decl)) |
| 17036 |
{ |
| 17037 |
if (ix86_flag_record_return) |
| 17038 |
fprintf (asm_out_file, "1:\n"); |
| 17039 |
switch (ix86_instrument_return) |
| 17040 |
{ |
| 17041 |
case instrument_return_call: |
| 17042 |
fprintf (asm_out_file, "\tcall\t__return__\n"); |
| 17043 |
break; |
| 17044 |
case instrument_return_nop5: |
| 17045 |
/* 5 byte nop: nopl 0(%[re]ax,%[re]ax,1) */ |
| 17046 |
fprintf (asm_out_file, ASM_BYTE "0x0f, 0x1f, 0x44, 0x00, 0x00\n"); |
| 17047 |
break; |
| 17048 |
case instrument_return_none: |
| 17049 |
break; |
| 17050 |
} |
| 17051 |
|
| 17052 |
if (ix86_flag_record_return) |
| 17053 |
{ |
| 17054 |
fprintf (asm_out_file, "\t.section __return_loc, \"a\",@progbits\n"); |
| 17055 |
fprintf (asm_out_file, "\t.%s 1b\n", TARGET_64BIT ? "quad" : "long"); |
| 17056 |
fprintf (asm_out_file, "\t.previous\n"); |
| 17057 |
} |
| 17058 |
} |
| 17059 |
} |
| 17060 |
|
| 17061 |
/* Output function return. CALL_OP is the jump target. Add a REP |
| 17062 |
prefix to RET if LONG_P is true and function return is kept. */ |
| 17063 |
|
| 17064 |
const char * |
| 17065 |
ix86_output_function_return (bool long_p) |
| 17066 |
{ |
| 17067 |
output_return_instrumentation (); |
| 17068 |
|
| 17069 |
if (cfun->machine->function_return_type != indirect_branch_keep) |
| 17070 |
{ |
| 17071 |
char thunk_name[32]; |
| 17072 |
enum indirect_thunk_prefix need_prefix |
| 17073 |
= indirect_thunk_need_prefix (current_output_insn); |
| 17074 |
|
| 17075 |
if (cfun->machine->function_return_type |
| 17076 |
!= indirect_branch_thunk_inline) |
| 17077 |
{ |
| 17078 |
bool need_thunk = (cfun->machine->function_return_type |
| 17079 |
== indirect_branch_thunk); |
| 17080 |
indirect_thunk_name (thunk_name, INVALID_REGNUM, need_prefix, |
| 17081 |
true); |
| 17082 |
indirect_return_needed |= need_thunk; |
| 17083 |
fprintf (asm_out_file, "\tjmp\t"); |
| 17084 |
assemble_name (asm_out_file, thunk_name); |
| 17085 |
putc ('\n', asm_out_file); |
| 17086 |
} |
| 17087 |
else |
| 17088 |
output_indirect_thunk (INVALID_REGNUM); |
| 17089 |
|
| 17090 |
return ""; |
| 17091 |
} |
| 17092 |
|
| 17093 |
output_asm_insn (long_p ? "rep%; ret" : "ret", nullptr); |
| 17094 |
return (ix86_harden_sls & harden_sls_return) ? "int3" : ""; |
| 17095 |
} |
| 17096 |
|
| 17097 |
/* Output indirect function return. RET_OP is the function return |
| 17098 |
target. */ |
| 17099 |
|
| 17100 |
const char * |
| 17101 |
ix86_output_indirect_function_return (rtx ret_op) |
| 17102 |
{ |
| 17103 |
if (cfun->machine->function_return_type != indirect_branch_keep) |
| 17104 |
{ |
| 17105 |
char thunk_name[32]; |
| 17106 |
enum indirect_thunk_prefix need_prefix |
| 17107 |
= indirect_thunk_need_prefix (current_output_insn); |
| 17108 |
unsigned int regno = REGNO (ret_op); |
| 17109 |
gcc_assert (regno == CX_REG); |
| 17110 |
|
| 17111 |
if (cfun->machine->function_return_type |
| 17112 |
!= indirect_branch_thunk_inline) |
| 17113 |
{ |
| 17114 |
bool need_thunk = (cfun->machine->function_return_type |
| 17115 |
== indirect_branch_thunk); |
| 17116 |
indirect_thunk_name (thunk_name, regno, need_prefix, true); |
| 17117 |
|
| 17118 |
if (need_thunk) |
| 17119 |
{ |
| 17120 |
indirect_return_via_cx = true; |
| 17121 |
SET_HARD_REG_BIT (indirect_thunks_used, CX_REG); |
| 17122 |
} |
| 17123 |
fprintf (asm_out_file, "\tjmp\t"); |
| 17124 |
assemble_name (asm_out_file, thunk_name); |
| 17125 |
putc ('\n', asm_out_file); |
| 17126 |
} |
| 17127 |
else |
| 17128 |
output_indirect_thunk (regno); |
| 17129 |
} |
| 17130 |
else |
| 17131 |
{ |
| 17132 |
output_asm_insn ("%!jmp\t%A0", &ret_op); |
| 17133 |
if (ix86_harden_sls & harden_sls_indirect_jmp) |
| 17134 |
fputs ("\tint3\n", asm_out_file); |
| 17135 |
} |
| 17136 |
return ""; |
| 17137 |
} |
| 17138 |
|
| 17139 |
/* Output the assembly for a call instruction. */ |
| 17140 |
|
| 17141 |
const char * |
| 17142 |
ix86_output_call_insn (rtx_insn *insn, rtx call_op) |
| 17143 |
{ |
| 17144 |
bool direct_p = constant_call_address_operand (call_op, VOIDmode); |
| 17145 |
bool output_indirect_p |
| 17146 |
= (!TARGET_SEH |
| 17147 |
&& cfun->machine->indirect_branch_type != indirect_branch_keep); |
| 17148 |
bool seh_nop_p = false; |
| 17149 |
const char *xasm; |
| 17150 |
|
| 17151 |
if (SIBLING_CALL_P (insn)) |
| 17152 |
{ |
| 17153 |
output_return_instrumentation (); |
| 17154 |
if (direct_p) |
| 17155 |
{ |
| 17156 |
if (ix86_nopic_noplt_attribute_p (call_op)) |
| 17157 |
{ |
| 17158 |
direct_p = false; |
| 17159 |
if (TARGET_64BIT) |
| 17160 |
{ |
| 17161 |
if (output_indirect_p) |
| 17162 |
xasm = "{%p0@GOTPCREL(%%rip)|[QWORD PTR %p0@GOTPCREL[rip]]}"; |
| 17163 |
else |
| 17164 |
xasm = "%!jmp\t{*%p0@GOTPCREL(%%rip)|[QWORD PTR %p0@GOTPCREL[rip]]}"; |
| 17165 |
} |
| 17166 |
else |
| 17167 |
{ |
| 17168 |
if (output_indirect_p) |
| 17169 |
xasm = "{%p0@GOT|[DWORD PTR %p0@GOT]}"; |
| 17170 |
else |
| 17171 |
xasm = "%!jmp\t{*%p0@GOT|[DWORD PTR %p0@GOT]}"; |
| 17172 |
} |
| 17173 |
} |
| 17174 |
else |
| 17175 |
xasm = "%!jmp\t%P0"; |
| 17176 |
} |
| 17177 |
/* SEH epilogue detection requires the indirect branch case |
| 17178 |
to include REX.W. */ |
| 17179 |
else if (TARGET_SEH) |
| 17180 |
xasm = "%!rex.W jmp\t%A0"; |
| 17181 |
else |
| 17182 |
{ |
| 17183 |
if (output_indirect_p) |
| 17184 |
xasm = "%0"; |
| 17185 |
else |
| 17186 |
xasm = "%!jmp\t%A0"; |
| 17187 |
} |
| 17188 |
|
| 17189 |
if (output_indirect_p && !direct_p) |
| 17190 |
ix86_output_indirect_branch (call_op, xasm, true); |
| 17191 |
else |
| 17192 |
{ |
| 17193 |
output_asm_insn (xasm, &call_op); |
| 17194 |
if (!direct_p |
| 17195 |
&& (ix86_harden_sls & harden_sls_indirect_jmp)) |
| 17196 |
return "int3"; |
| 17197 |
} |
| 17198 |
return ""; |
| 17199 |
} |
| 17200 |
|
| 17201 |
/* SEH unwinding can require an extra nop to be emitted in several |
| 17202 |
circumstances. Determine if we have one of those. */ |
| 17203 |
if (TARGET_SEH) |
| 17204 |
{ |
| 17205 |
rtx_insn *i; |
| 17206 |
|
| 17207 |
for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i)) |
| 17208 |
{ |
| 17209 |
/* Prevent a catch region from being adjacent to a jump that would |
| 17210 |
be interpreted as an epilogue sequence by the unwinder. */ |
| 17211 |
if (JUMP_P(i) && CROSSING_JUMP_P (i)) |
| 17212 |
{ |
| 17213 |
seh_nop_p = true; |
| 17214 |
break; |
| 17215 |
} |
| 17216 |
|
| 17217 |
/* If we get to another real insn, we don't need the nop. */ |
| 17218 |
if (INSN_P (i)) |
| 17219 |
break; |
| 17220 |
|
| 17221 |
/* If we get to the epilogue note, prevent a catch region from |
| 17222 |
being adjacent to the standard epilogue sequence. Note that, |
| 17223 |
if non-call exceptions are enabled, we already did it during |
| 17224 |
epilogue expansion, or else, if the insn can throw internally, |
| 17225 |
we already did it during the reorg pass. */ |
| 17226 |
if (NOTE_P (i) && NOTE_KIND (i) == NOTE_INSN_EPILOGUE_BEG |
| 17227 |
&& !flag_non_call_exceptions |
| 17228 |
&& !can_throw_internal (insn)) |
| 17229 |
{ |
| 17230 |
seh_nop_p = true; |
| 17231 |
break; |
| 17232 |
} |
| 17233 |
} |
| 17234 |
|
| 17235 |
/* If we didn't find a real insn following the call, prevent the |
| 17236 |
unwinder from looking into the next function. */ |
| 17237 |
if (i == NULL) |
| 17238 |
seh_nop_p = true; |
| 17239 |
} |
| 17240 |
|
| 17241 |
if (direct_p) |
| 17242 |
{ |
| 17243 |
if (ix86_nopic_noplt_attribute_p (call_op)) |
| 17244 |
{ |
| 17245 |
direct_p = false; |
| 17246 |
if (TARGET_64BIT) |
| 17247 |
{ |
| 17248 |
if (output_indirect_p) |
| 17249 |
xasm = "{%p0@GOTPCREL(%%rip)|[QWORD PTR %p0@GOTPCREL[rip]]}"; |
| 17250 |
else |
| 17251 |
xasm = "%!call\t{*%p0@GOTPCREL(%%rip)|[QWORD PTR %p0@GOTPCREL[rip]]}"; |
| 17252 |
} |
| 17253 |
else |
| 17254 |
{ |
| 17255 |
if (output_indirect_p) |
| 17256 |
xasm = "{%p0@GOT|[DWORD PTR %p0@GOT]}"; |
| 17257 |
else |
| 17258 |
xasm = "%!call\t{*%p0@GOT|[DWORD PTR %p0@GOT]}"; |
| 17259 |
} |
| 17260 |
} |
| 17261 |
else |
| 17262 |
xasm = "%!call\t%P0"; |
| 17263 |
} |
| 17264 |
else |
| 17265 |
{ |
| 17266 |
if (output_indirect_p) |
| 17267 |
xasm = "%0"; |
| 17268 |
else |
| 17269 |
xasm = "%!call\t%A0"; |
| 17270 |
} |
| 17271 |
|
| 17272 |
if (output_indirect_p && !direct_p) |
| 17273 |
ix86_output_indirect_branch (call_op, xasm, false); |
| 17274 |
else |
| 17275 |
output_asm_insn (xasm, &call_op); |
| 17276 |
|
| 17277 |
if (seh_nop_p) |
| 17278 |
return "nop"; |
| 17279 |
|
| 17280 |
return ""; |
| 17281 |
} |
| 17282 |
|
| 17283 |
/* Return a MEM corresponding to a stack slot with mode MODE. |
| 17284 |
Allocate a new slot if necessary. |
| 17285 |
|
| 17286 |
The RTL for a function can have several slots available: N is |
| 17287 |
which slot to use. */ |
| 17288 |
|
| 17289 |
rtx |
| 17290 |
assign_386_stack_local (machine_mode mode, enum ix86_stack_slot n) |
| 17291 |
{ |
| 17292 |
struct stack_local_entry *s; |
| 17293 |
|
| 17294 |
gcc_assert (n < MAX_386_STACK_LOCALS); |
| 17295 |
|
| 17296 |
for (s = ix86_stack_locals; s; s = s->next) |
| 17297 |
if (s->mode == mode && s->n == n) |
| 17298 |
return validize_mem (copy_rtx (s->rtl)); |
| 17299 |
|
| 17300 |
int align = 0; |
| 17301 |
/* For DImode with SLOT_FLOATxFDI_387 use 32-bit |
| 17302 |
alignment with -m32 -mpreferred-stack-boundary=2. */ |
| 17303 |
if (mode == DImode |
| 17304 |
&& !TARGET_64BIT |
| 17305 |
&& n == SLOT_FLOATxFDI_387 |
| 17306 |
&& ix86_preferred_stack_boundary < GET_MODE_ALIGNMENT (DImode)) |
| 17307 |
align = 32; |
| 17308 |
s = ggc_alloc<stack_local_entry> (); |
| 17309 |
s->n = n; |
| 17310 |
s->mode = mode; |
| 17311 |
s->rtl = assign_stack_local (mode, GET_MODE_SIZE (mode), align); |
| 17312 |
|
| 17313 |
s->next = ix86_stack_locals; |
| 17314 |
ix86_stack_locals = s; |
| 17315 |
return validize_mem (copy_rtx (s->rtl)); |
| 17316 |
} |
| 17317 |
|
| 17318 |
static void |
| 17319 |
ix86_instantiate_decls (void) |
| 17320 |
{ |
| 17321 |
struct stack_local_entry *s; |
| 17322 |
|
| 17323 |
for (s = ix86_stack_locals; s; s = s->next) |
| 17324 |
if (s->rtl != NULL_RTX) |
| 17325 |
instantiate_decl_rtl (s->rtl); |
| 17326 |
} |
| 17327 |
|
| 17328 |
/* Check whether x86 address PARTS is a pc-relative address. */ |
| 17329 |
|
| 17330 |
bool |
| 17331 |
ix86_rip_relative_addr_p (struct ix86_address *parts) |
| 17332 |
{ |
| 17333 |
rtx base, index, disp; |
| 17334 |
|
| 17335 |
base = parts->base; |
| 17336 |
index = parts->index; |
| 17337 |
disp = parts->disp; |
| 17338 |
|
| 17339 |
if (disp && !base && !index) |
| 17340 |
{ |
| 17341 |
if (TARGET_64BIT) |
| 17342 |
{ |
| 17343 |
rtx symbol = disp; |
| 17344 |
|
| 17345 |
if (GET_CODE (disp) == CONST) |
| 17346 |
symbol = XEXP (disp, 0); |
| 17347 |
if (GET_CODE (symbol) == PLUS |
| 17348 |
&& CONST_INT_P (XEXP (symbol, 1))) |
| 17349 |
symbol = XEXP (symbol, 0); |
| 17350 |
|
| 17351 |
if (GET_CODE (symbol) == LABEL_REF |
| 17352 |
|| (GET_CODE (symbol) == SYMBOL_REF |
| 17353 |
&& SYMBOL_REF_TLS_MODEL (symbol) == 0) |
| 17354 |
|| (GET_CODE (symbol) == UNSPEC |
| 17355 |
&& (XINT (symbol, 1) == UNSPEC_GOTPCREL |
| 17356 |
|| XINT (symbol, 1) == UNSPEC_PCREL |
| 17357 |
|| XINT (symbol, 1) == UNSPEC_GOTNTPOFF))) |
| 17358 |
return true; |
| 17359 |
} |
| 17360 |
} |
| 17361 |
return false; |
| 17362 |
} |
| 17363 |
|
| 17364 |
/* Calculate the length of the memory address in the instruction encoding. |
| 17365 |
Includes addr32 prefix, does not include the one-byte modrm, opcode, |
| 17366 |
or other prefixes. We never generate addr32 prefix for LEA insn. */ |
| 17367 |
|
| 17368 |
int |
| 17369 |
memory_address_length (rtx addr, bool lea) |
| 17370 |
{ |
| 17371 |
struct ix86_address parts; |
| 17372 |
rtx base, index, disp; |
| 17373 |
int len; |
| 17374 |
int ok; |
| 17375 |
|
| 17376 |
if (GET_CODE (addr) == PRE_DEC |
| 17377 |
|| GET_CODE (addr) == POST_INC |
| 17378 |
|| GET_CODE (addr) == PRE_MODIFY |
| 17379 |
|| GET_CODE (addr) == POST_MODIFY) |
| 17380 |
return 0; |
| 17381 |
|
| 17382 |
ok = ix86_decompose_address (addr, &parts); |
| 17383 |
gcc_assert (ok); |
| 17384 |
|
| 17385 |
len = (parts.seg == ADDR_SPACE_GENERIC) ? 0 : 1; |
| 17386 |
|
| 17387 |
/* If this is not LEA instruction, add the length of addr32 prefix. */ |
| 17388 |
if (TARGET_64BIT && !lea |
| 17389 |
&& (SImode_address_operand (addr, VOIDmode) |
| 17390 |
|| (parts.base && GET_MODE (parts.base) == SImode) |
| 17391 |
|| (parts.index && GET_MODE (parts.index) == SImode))) |
| 17392 |
len++; |
| 17393 |
|
| 17394 |
base = parts.base; |
| 17395 |
index = parts.index; |
| 17396 |
disp = parts.disp; |
| 17397 |
|
| 17398 |
if (base && SUBREG_P (base)) |
| 17399 |
base = SUBREG_REG (base); |
| 17400 |
if (index && SUBREG_P (index)) |
| 17401 |
index = SUBREG_REG (index); |
| 17402 |
|
| 17403 |
gcc_assert (base == NULL_RTX || REG_P (base)); |
| 17404 |
gcc_assert (index == NULL_RTX || REG_P (index)); |
| 17405 |
|
| 17406 |
/* Rule of thumb: |
| 17407 |
- esp as the base always wants an index, |
| 17408 |
- ebp as the base always wants a displacement, |
| 17409 |
- r12 as the base always wants an index, |
| 17410 |
- r13 as the base always wants a displacement. */ |
| 17411 |
|
| 17412 |
/* Register Indirect. */ |
| 17413 |
if (base && !index && !disp) |
| 17414 |
{ |
| 17415 |
/* esp (for its index) and ebp (for its displacement) need |
| 17416 |
the two-byte modrm form. Similarly for r12 and r13 in 64-bit |
| 17417 |
code. */ |
| 17418 |
if (base == arg_pointer_rtx |
| 17419 |
|| base == frame_pointer_rtx |
| 17420 |
|| REGNO (base) == SP_REG |
| 17421 |
|| REGNO (base) == BP_REG |
| 17422 |
|| REGNO (base) == R12_REG |
| 17423 |
|| REGNO (base) == R13_REG) |
| 17424 |
len++; |
| 17425 |
} |
| 17426 |
|
| 17427 |
/* Direct Addressing. In 64-bit mode mod 00 r/m 5 |
| 17428 |
is not disp32, but disp32(%rip), so for disp32 |
| 17429 |
SIB byte is needed, unless print_operand_address |
| 17430 |
optimizes it into disp32(%rip) or (%rip) is implied |
| 17431 |
by UNSPEC. */ |
| 17432 |
else if (disp && !base && !index) |
| 17433 |
{ |
| 17434 |
len += 4; |
| 17435 |
if (!ix86_rip_relative_addr_p (&parts)) |
| 17436 |
len++; |
| 17437 |
} |
| 17438 |
else |
| 17439 |
{ |
| 17440 |
/* Find the length of the displacement constant. */ |
| 17441 |
if (disp) |
| 17442 |
{ |
| 17443 |
if (base && satisfies_constraint_K (disp)) |
| 17444 |
len += 1; |
| 17445 |
else |
| 17446 |
len += 4; |
| 17447 |
} |
| 17448 |
/* ebp always wants a displacement. Similarly r13. */ |
| 17449 |
else if (base && (REGNO (base) == BP_REG || REGNO (base) == R13_REG)) |
| 17450 |
len++; |
| 17451 |
|
| 17452 |
/* An index requires the two-byte modrm form.... */ |
| 17453 |
if (index |
| 17454 |
/* ...like esp (or r12), which always wants an index. */ |
| 17455 |
|| base == arg_pointer_rtx |
| 17456 |
|| base == frame_pointer_rtx |
| 17457 |
|| (base && (REGNO (base) == SP_REG || REGNO (base) == R12_REG))) |
| 17458 |
len++; |
| 17459 |
} |
| 17460 |
|
| 17461 |
return len; |
| 17462 |
} |
| 17463 |
|
| 17464 |
/* Compute default value for "length_immediate" attribute. When SHORTFORM |
| 17465 |
is set, expect that insn have 8bit immediate alternative. */ |
| 17466 |
int |
| 17467 |
ix86_attr_length_immediate_default (rtx_insn *insn, bool shortform) |
| 17468 |
{ |
| 17469 |
int len = 0; |
| 17470 |
int i; |
| 17471 |
extract_insn_cached (insn); |
| 17472 |
for (i = recog_data.n_operands - 1; i >= 0; --i) |
| 17473 |
if (CONSTANT_P (recog_data.operand[i])) |
| 17474 |
{ |
| 17475 |
enum attr_mode mode = get_attr_mode (insn); |
| 17476 |
|
| 17477 |
gcc_assert (!len); |
| 17478 |
if (shortform && CONST_INT_P (recog_data.operand[i])) |
| 17479 |
{ |
| 17480 |
HOST_WIDE_INT ival = INTVAL (recog_data.operand[i]); |
| 17481 |
switch (mode) |
| 17482 |
{ |
| 17483 |
case MODE_QI: |
| 17484 |
len = 1; |
| 17485 |
continue; |
| 17486 |
case MODE_HI: |
| 17487 |
ival = trunc_int_for_mode (ival, HImode); |
| 17488 |
break; |
| 17489 |
case MODE_SI: |
| 17490 |
ival = trunc_int_for_mode (ival, SImode); |
| 17491 |
break; |
| 17492 |
default: |
| 17493 |
break; |
| 17494 |
} |
| 17495 |
if (IN_RANGE (ival, -128, 127)) |
| 17496 |
{ |
| 17497 |
len = 1; |
| 17498 |
continue; |
| 17499 |
} |
| 17500 |
} |
| 17501 |
switch (mode) |
| 17502 |
{ |
| 17503 |
case MODE_QI: |
| 17504 |
len = 1; |
| 17505 |
break; |
| 17506 |
case MODE_HI: |
| 17507 |
len = 2; |
| 17508 |
break; |
| 17509 |
case MODE_SI: |
| 17510 |
len = 4; |
| 17511 |
break; |
| 17512 |
/* Immediates for DImode instructions are encoded |
| 17513 |
as 32bit sign extended values. */ |
| 17514 |
case MODE_DI: |
| 17515 |
len = 4; |
| 17516 |
break; |
| 17517 |
default: |
| 17518 |
fatal_insn ("unknown insn mode", insn); |
| 17519 |
} |
| 17520 |
} |
| 17521 |
return len; |
| 17522 |
} |
| 17523 |
|
| 17524 |
/* Compute default value for "length_address" attribute. */ |
| 17525 |
int |
| 17526 |
ix86_attr_length_address_default (rtx_insn *insn) |
| 17527 |
{ |
| 17528 |
int i; |
| 17529 |
|
| 17530 |
if (get_attr_type (insn) == TYPE_LEA) |
| 17531 |
{ |
| 17532 |
rtx set = PATTERN (insn), addr; |
| 17533 |
|
| 17534 |
if (GET_CODE (set) == PARALLEL) |
| 17535 |
set = XVECEXP (set, 0, 0); |
| 17536 |
|
| 17537 |
gcc_assert (GET_CODE (set) == SET); |
| 17538 |
|
| 17539 |
addr = SET_SRC (set); |
| 17540 |
|
| 17541 |
return memory_address_length (addr, true); |
| 17542 |
} |
| 17543 |
|
| 17544 |
extract_insn_cached (insn); |
| 17545 |
for (i = recog_data.n_operands - 1; i >= 0; --i) |
| 17546 |
{ |
| 17547 |
rtx op = recog_data.operand[i]; |
| 17548 |
if (MEM_P (op)) |
| 17549 |
{ |
| 17550 |
constrain_operands_cached (insn, reload_completed); |
| 17551 |
if (which_alternative != -1) |
| 17552 |
{ |
| 17553 |
const char *constraints = recog_data.constraints[i]; |
| 17554 |
int alt = which_alternative; |
| 17555 |
|
| 17556 |
while (*constraints == '=' || *constraints == '+') |
| 17557 |
constraints++; |
| 17558 |
while (alt-- > 0) |
| 17559 |
while (*constraints++ != ',') |
| 17560 |
; |
| 17561 |
/* Skip ignored operands. */ |
| 17562 |
if (*constraints == 'X') |
| 17563 |
continue; |
| 17564 |
} |
| 17565 |
|
| 17566 |
int len = memory_address_length (XEXP (op, 0), false); |
| 17567 |
|
| 17568 |
/* Account for segment prefix for non-default addr spaces. */ |
| 17569 |
if (!ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (op))) |
| 17570 |
len++; |
| 17571 |
|
| 17572 |
return len; |
| 17573 |
} |
| 17574 |
} |
| 17575 |
return 0; |
| 17576 |
} |
| 17577 |
|
| 17578 |
/* Compute default value for "length_vex" attribute. It includes |
| 17579 |
2 or 3 byte VEX prefix and 1 opcode byte. */ |
| 17580 |
|
| 17581 |
int |
| 17582 |
ix86_attr_length_vex_default (rtx_insn *insn, bool has_0f_opcode, |
| 17583 |
bool has_vex_w) |
| 17584 |
{ |
| 17585 |
int i, reg_only = 2 + 1; |
| 17586 |
bool has_mem = false; |
| 17587 |
|
| 17588 |
/* Only 0f opcode can use 2 byte VEX prefix and VEX W bit uses 3 |
| 17589 |
byte VEX prefix. */ |
| 17590 |
if (!has_0f_opcode || has_vex_w) |
| 17591 |
return 3 + 1; |
| 17592 |
|
| 17593 |
/* We can always use 2 byte VEX prefix in 32bit. */ |
| 17594 |
if (!TARGET_64BIT) |
| 17595 |
return 2 + 1; |
| 17596 |
|
| 17597 |
extract_insn_cached (insn); |
| 17598 |
|
| 17599 |
for (i = recog_data.n_operands - 1; i >= 0; --i) |
| 17600 |
if (REG_P (recog_data.operand[i])) |
| 17601 |
{ |
| 17602 |
/* REX.W bit uses 3 byte VEX prefix. |
| 17603 |
REX2 with vex use extended EVEX prefix length is 4-byte. */ |
| 17604 |
if (GET_MODE (recog_data.operand[i]) == DImode |
| 17605 |
&& GENERAL_REG_P (recog_data.operand[i])) |
| 17606 |
return 3 + 1; |
| 17607 |
|
| 17608 |
/* REX.B bit requires 3-byte VEX. Right here we don't know which |
| 17609 |
operand will be encoded using VEX.B, so be conservative. |
| 17610 |
REX2 with vex use extended EVEX prefix length is 4-byte. */ |
| 17611 |
if (REX_INT_REGNO_P (recog_data.operand[i]) |
| 17612 |
|| REX2_INT_REGNO_P (recog_data.operand[i]) |
| 17613 |
|| REX_SSE_REGNO_P (recog_data.operand[i])) |
| 17614 |
reg_only = 3 + 1; |
| 17615 |
} |
| 17616 |
else if (MEM_P (recog_data.operand[i])) |
| 17617 |
{ |
| 17618 |
/* REX2.X or REX2.B bits use 3 byte VEX prefix. */ |
| 17619 |
if (x86_extended_rex2reg_mentioned_p (recog_data.operand[i])) |
| 17620 |
return 4; |
| 17621 |
|
| 17622 |
/* REX.X or REX.B bits use 3 byte VEX prefix. */ |
| 17623 |
if (x86_extended_reg_mentioned_p (recog_data.operand[i])) |
| 17624 |
return 3 + 1; |
| 17625 |
|
| 17626 |
has_mem = true; |
| 17627 |
} |
| 17628 |
|
| 17629 |
return has_mem ? 2 + 1 : reg_only; |
| 17630 |
} |
| 17631 |
|
| 17632 |
|
| 17633 |
static bool |
| 17634 |
ix86_class_likely_spilled_p (reg_class_t); |
| 17635 |
|
| 17636 |
/* Returns true if lhs of insn is HW function argument register and set up |
| 17637 |
is_spilled to true if it is likely spilled HW register. */ |
| 17638 |
static bool |
| 17639 |
insn_is_function_arg (rtx insn, bool* is_spilled) |
| 17640 |
{ |
| 17641 |
rtx dst; |
| 17642 |
|
| 17643 |
if (!NONDEBUG_INSN_P (insn)) |
| 17644 |
return false; |
| 17645 |
/* Call instructions are not movable, ignore it. */ |
| 17646 |
if (CALL_P (insn)) |
| 17647 |
return false; |
| 17648 |
insn = PATTERN (insn); |
| 17649 |
if (GET_CODE (insn) == PARALLEL) |
| 17650 |
insn = XVECEXP (insn, 0, 0); |
| 17651 |
if (GET_CODE (insn) != SET) |
| 17652 |
return false; |
| 17653 |
dst = SET_DEST (insn); |
| 17654 |
if (REG_P (dst) && HARD_REGISTER_P (dst) |
| 17655 |
&& ix86_function_arg_regno_p (REGNO (dst))) |
| 17656 |
{ |
| 17657 |
/* Is it likely spilled HW register? */ |
| 17658 |
if (!TEST_HARD_REG_BIT (fixed_reg_set, REGNO (dst)) |
| 17659 |
&& ix86_class_likely_spilled_p (REGNO_REG_CLASS (REGNO (dst)))) |
| 17660 |
*is_spilled = true; |
| 17661 |
return true; |
| 17662 |
} |
| 17663 |
return false; |
| 17664 |
} |
| 17665 |
|
| 17666 |
/* Add output dependencies for chain of function adjacent arguments if only |
| 17667 |
there is a move to likely spilled HW register. Return first argument |
| 17668 |
if at least one dependence was added or NULL otherwise. */ |
| 17669 |
static rtx_insn * |
| 17670 |
add_parameter_dependencies (rtx_insn *call, rtx_insn *head) |
| 17671 |
{ |
| 17672 |
rtx_insn *insn; |
| 17673 |
rtx_insn *last = call; |
| 17674 |
rtx_insn *first_arg = NULL; |
| 17675 |
bool is_spilled = false; |
| 17676 |
|
| 17677 |
head = PREV_INSN (head); |
| 17678 |
|
| 17679 |
/* Find nearest to call argument passing instruction. */ |
| 17680 |
while (true) |
| 17681 |
{ |
| 17682 |
last = PREV_INSN (last); |
| 17683 |
if (last == head) |
| 17684 |
return NULL; |
| 17685 |
if (!NONDEBUG_INSN_P (last)) |
| 17686 |
continue; |
| 17687 |
if (insn_is_function_arg (last, &is_spilled)) |
| 17688 |
break; |
| 17689 |
return NULL; |
| 17690 |
} |
| 17691 |
|
| 17692 |
first_arg = last; |
| 17693 |
while (true) |
| 17694 |
{ |
| 17695 |
insn = PREV_INSN (last); |
| 17696 |
if (!INSN_P (insn)) |
| 17697 |
break; |
| 17698 |
if (insn == head) |
| 17699 |
break; |
| 17700 |
if (!NONDEBUG_INSN_P (insn)) |
| 17701 |
{ |
| 17702 |
last = insn; |
| 17703 |
continue; |
| 17704 |
} |
| 17705 |
if (insn_is_function_arg (insn, &is_spilled)) |
| 17706 |
{ |
| 17707 |
/* Add output depdendence between two function arguments if chain |
| 17708 |
of output arguments contains likely spilled HW registers. */ |
| 17709 |
if (is_spilled) |
| 17710 |
add_dependence (first_arg, insn, REG_DEP_OUTPUT); |
| 17711 |
first_arg = last = insn; |
| 17712 |
} |
| 17713 |
else |
| 17714 |
break; |
| 17715 |
} |
| 17716 |
if (!is_spilled) |
| 17717 |
return NULL; |
| 17718 |
return first_arg; |
| 17719 |
} |
| 17720 |
|
| 17721 |
/* Add output or anti dependency from insn to first_arg to restrict its code |
| 17722 |
motion. */ |
| 17723 |
static void |
| 17724 |
avoid_func_arg_motion (rtx_insn *first_arg, rtx_insn *insn) |
| 17725 |
{ |
| 17726 |
rtx set; |
| 17727 |
rtx tmp; |
| 17728 |
|
| 17729 |
set = single_set (insn); |
| 17730 |
if (!set) |
| 17731 |
return; |
| 17732 |
tmp = SET_DEST (set); |
| 17733 |
if (REG_P (tmp)) |
| 17734 |
{ |
| 17735 |
/* Add output dependency to the first function argument. */ |
| 17736 |
add_dependence (first_arg, insn, REG_DEP_OUTPUT); |
| 17737 |
return; |
| 17738 |
} |
| 17739 |
/* Add anti dependency. */ |
| 17740 |
add_dependence (first_arg, insn, REG_DEP_ANTI); |
| 17741 |
} |
| 17742 |
|
| 17743 |
/* Avoid cross block motion of function argument through adding dependency |
| 17744 |
from the first non-jump instruction in bb. */ |
| 17745 |
static void |
| 17746 |
add_dependee_for_func_arg (rtx_insn *arg, basic_block bb) |
| 17747 |
{ |
| 17748 |
rtx_insn *insn = BB_END (bb); |
| 17749 |
|
| 17750 |
while (insn) |
| 17751 |
{ |
| 17752 |
if (NONDEBUG_INSN_P (insn) && NONJUMP_INSN_P (insn)) |
| 17753 |
{ |
| 17754 |
rtx set = single_set (insn); |
| 17755 |
if (set) |
| 17756 |
{ |
| 17757 |
avoid_func_arg_motion (arg, insn); |
| 17758 |
return; |
| 17759 |
} |
| 17760 |
} |
| 17761 |
if (insn == BB_HEAD (bb)) |
| 17762 |
return; |
| 17763 |
insn = PREV_INSN (insn); |
| 17764 |
} |
| 17765 |
} |
| 17766 |
|
| 17767 |
/* Hook for pre-reload schedule - avoid motion of function arguments |
| 17768 |
passed in likely spilled HW registers. */ |
| 17769 |
static void |
| 17770 |
ix86_dependencies_evaluation_hook (rtx_insn *head, rtx_insn *tail) |
| 17771 |
{ |
| 17772 |
rtx_insn *insn; |
| 17773 |
rtx_insn *first_arg = NULL; |
| 17774 |
if (reload_completed) |
| 17775 |
return; |
| 17776 |
while (head != tail && DEBUG_INSN_P (head)) |
| 17777 |
head = NEXT_INSN (head); |
| 17778 |
for (insn = tail; insn != head; insn = PREV_INSN (insn)) |
| 17779 |
if (INSN_P (insn) && CALL_P (insn)) |
| 17780 |
{ |
| 17781 |
first_arg = add_parameter_dependencies (insn, head); |
| 17782 |
if (first_arg) |
| 17783 |
{ |
| 17784 |
/* Add dependee for first argument to predecessors if only |
| 17785 |
region contains more than one block. */ |
| 17786 |
basic_block bb = BLOCK_FOR_INSN (insn); |
| 17787 |
int rgn = CONTAINING_RGN (bb->index); |
| 17788 |
int nr_blks = RGN_NR_BLOCKS (rgn); |
| 17789 |
/* Skip trivial regions and region head blocks that can have |
| 17790 |
predecessors outside of region. */ |
| 17791 |
if (nr_blks > 1 && BLOCK_TO_BB (bb->index) != 0) |
| 17792 |
{ |
| 17793 |
edge e; |
| 17794 |
edge_iterator ei; |
| 17795 |
|
| 17796 |
/* Regions are SCCs with the exception of selective |
| 17797 |
scheduling with pipelining of outer blocks enabled. |
| 17798 |
So also check that immediate predecessors of a non-head |
| 17799 |
block are in the same region. */ |
| 17800 |
FOR_EACH_EDGE (e, ei, bb->preds) |
| 17801 |
{ |
| 17802 |
/* Avoid creating of loop-carried dependencies through |
| 17803 |
using topological ordering in the region. */ |
| 17804 |
if (rgn == CONTAINING_RGN (e->src->index) |
| 17805 |
&& BLOCK_TO_BB (bb->index) > BLOCK_TO_BB (e->src->index)) |
| 17806 |
add_dependee_for_func_arg (first_arg, e->src); |
| 17807 |
} |
| 17808 |
} |
| 17809 |
insn = first_arg; |
| 17810 |
if (insn == head) |
| 17811 |
break; |
| 17812 |
} |
| 17813 |
} |
| 17814 |
else if (first_arg) |
| 17815 |
avoid_func_arg_motion (first_arg, insn); |
| 17816 |
} |
| 17817 |
|
| 17818 |
/* Hook for pre-reload schedule - set priority of moves from likely spilled |
| 17819 |
HW registers to maximum, to schedule them at soon as possible. These are |
| 17820 |
moves from function argument registers at the top of the function entry |
| 17821 |
and moves from function return value registers after call. */ |
| 17822 |
static int |
| 17823 |
ix86_adjust_priority (rtx_insn *insn, int priority) |
| 17824 |
{ |
| 17825 |
rtx set; |
| 17826 |
|
| 17827 |
if (reload_completed) |
| 17828 |
return priority; |
| 17829 |
|
| 17830 |
if (!NONDEBUG_INSN_P (insn)) |
| 17831 |
return priority; |
| 17832 |
|
| 17833 |
set = single_set (insn); |
| 17834 |
if (set) |
| 17835 |
{ |
| 17836 |
rtx tmp = SET_SRC (set); |
| 17837 |
if (REG_P (tmp) |
| 17838 |
&& HARD_REGISTER_P (tmp) |
| 17839 |
&& !TEST_HARD_REG_BIT (fixed_reg_set, REGNO (tmp)) |
| 17840 |
&& ix86_class_likely_spilled_p (REGNO_REG_CLASS (REGNO (tmp)))) |
| 17841 |
return current_sched_info->sched_max_insns_priority; |
| 17842 |
} |
| 17843 |
|
| 17844 |
return priority; |
| 17845 |
} |
| 17846 |
|
| 17847 |
/* Prepare for scheduling pass. */ |
| 17848 |
static void |
| 17849 |
ix86_sched_init_global (FILE *, int, int) |
| 17850 |
{ |
| 17851 |
/* Install scheduling hooks for current CPU. Some of these hooks are used |
| 17852 |
in time-critical parts of the scheduler, so we only set them up when |
| 17853 |
they are actually used. */ |
| 17854 |
switch (ix86_tune) |
| 17855 |
{ |
| 17856 |
case PROCESSOR_CORE2: |
| 17857 |
case PROCESSOR_NEHALEM: |
| 17858 |
case PROCESSOR_SANDYBRIDGE: |
| 17859 |
case PROCESSOR_HASWELL: |
| 17860 |
case PROCESSOR_TREMONT: |
| 17861 |
case PROCESSOR_ALDERLAKE: |
| 17862 |
case PROCESSOR_GENERIC: |
| 17863 |
/* Do not perform multipass scheduling for pre-reload schedule |
| 17864 |
to save compile time. */ |
| 17865 |
if (reload_completed) |
| 17866 |
{ |
| 17867 |
ix86_core2i7_init_hooks (); |
| 17868 |
break; |
| 17869 |
} |
| 17870 |
/* Fall through. */ |
| 17871 |
default: |
| 17872 |
targetm.sched.dfa_post_advance_cycle = NULL; |
| 17873 |
targetm.sched.first_cycle_multipass_init = NULL; |
| 17874 |
targetm.sched.first_cycle_multipass_begin = NULL; |
| 17875 |
targetm.sched.first_cycle_multipass_issue = NULL; |
| 17876 |
targetm.sched.first_cycle_multipass_backtrack = NULL; |
| 17877 |
targetm.sched.first_cycle_multipass_end = NULL; |
| 17878 |
targetm.sched.first_cycle_multipass_fini = NULL; |
| 17879 |
break; |
| 17880 |
} |
| 17881 |
} |
| 17882 |
|
| 17883 |
|
| 17884 |
/* Implement TARGET_STATIC_RTX_ALIGNMENT. */ |
| 17885 |
|
| 17886 |
static HOST_WIDE_INT |
| 17887 |
ix86_static_rtx_alignment (machine_mode mode) |
| 17888 |
{ |
| 17889 |
if (mode == DFmode) |
| 17890 |
return 64; |
| 17891 |
if (ALIGN_MODE_128 (mode)) |
| 17892 |
return MAX (128, GET_MODE_ALIGNMENT (mode)); |
| 17893 |
return GET_MODE_ALIGNMENT (mode); |
| 17894 |
} |
| 17895 |
|
| 17896 |
/* Implement TARGET_CONSTANT_ALIGNMENT. */ |
| 17897 |
|
| 17898 |
static HOST_WIDE_INT |
| 17899 |
ix86_constant_alignment (const_tree exp, HOST_WIDE_INT align) |
| 17900 |
{ |
| 17901 |
if (TREE_CODE (exp) == REAL_CST || TREE_CODE (exp) == VECTOR_CST |
| 17902 |
|| TREE_CODE (exp) == INTEGER_CST) |
| 17903 |
{ |
| 17904 |
machine_mode mode = TYPE_MODE (TREE_TYPE (exp)); |
| 17905 |
HOST_WIDE_INT mode_align = ix86_static_rtx_alignment (mode); |
| 17906 |
return MAX (mode_align, align); |
| 17907 |
} |
| 17908 |
else if (!optimize_size && TREE_CODE (exp) == STRING_CST |
| 17909 |
&& TREE_STRING_LENGTH (exp) >= 31 && align < BITS_PER_WORD) |
| 17910 |
return BITS_PER_WORD; |
| 17911 |
|
| 17912 |
return align; |
| 17913 |
} |
| 17914 |
|
| 17915 |
/* Implement TARGET_EMPTY_RECORD_P. */ |
| 17916 |
|
| 17917 |
static bool |
| 17918 |
ix86_is_empty_record (const_tree type) |
| 17919 |
{ |
| 17920 |
if (!TARGET_64BIT) |
| 17921 |
return false; |
| 17922 |
return default_is_empty_record (type); |
| 17923 |
} |
| 17924 |
|
| 17925 |
/* Implement TARGET_WARN_PARAMETER_PASSING_ABI. */ |
| 17926 |
|
| 17927 |
static void |
| 17928 |
ix86_warn_parameter_passing_abi (cumulative_args_t cum_v, tree type) |
| 17929 |
{ |
| 17930 |
CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v); |
| 17931 |
|
| 17932 |
if (!cum->warn_empty) |
| 17933 |
return; |
| 17934 |
|
| 17935 |
if (!TYPE_EMPTY_P (type)) |
| 17936 |
return; |
| 17937 |
|
| 17938 |
/* Don't warn if the function isn't visible outside of the TU. */ |
| 17939 |
if (cum->decl && !TREE_PUBLIC (cum->decl)) |
| 17940 |
return; |
| 17941 |
|
| 17942 |
const_tree ctx = get_ultimate_context (cum->decl); |
| 17943 |
if (ctx != NULL_TREE |
| 17944 |
&& !TRANSLATION_UNIT_WARN_EMPTY_P (ctx)) |
| 17945 |
return; |
| 17946 |
|
| 17947 |
/* If the actual size of the type is zero, then there is no change |
| 17948 |
in how objects of this size are passed. */ |
| 17949 |
if (int_size_in_bytes (type) == 0) |
| 17950 |
return; |
| 17951 |
|
| 17952 |
warning (OPT_Wabi, "empty class %qT parameter passing ABI " |
| 17953 |
"changes in %<-fabi-version=12%> (GCC 8)", type); |
| 17954 |
|
| 17955 |
/* Only warn once. */ |
| 17956 |
cum->warn_empty = false; |
| 17957 |
} |
| 17958 |
|
| 17959 |
/* This hook returns name of multilib ABI. */ |
| 17960 |
|
| 17961 |
static const char * |
| 17962 |
ix86_get_multilib_abi_name (void) |
| 17963 |
{ |
| 17964 |
if (!(TARGET_64BIT_P (ix86_isa_flags))) |
| 17965 |
return "i386"; |
| 17966 |
else if (TARGET_X32_P (ix86_isa_flags)) |
| 17967 |
return "x32"; |
| 17968 |
else |
| 17969 |
return "x86_64"; |
| 17970 |
} |
| 17971 |
|
| 17972 |
/* Compute the alignment for a variable for Intel MCU psABI. TYPE is |
| 17973 |
the data type, and ALIGN is the alignment that the object would |
| 17974 |
ordinarily have. */ |
| 17975 |
|
| 17976 |
static int |
| 17977 |
iamcu_alignment (tree type, int align) |
| 17978 |
{ |
| 17979 |
machine_mode mode; |
| 17980 |
|
| 17981 |
if (align < 32 || TYPE_USER_ALIGN (type)) |
| 17982 |
return align; |
| 17983 |
|
| 17984 |
/* Intel MCU psABI specifies scalar types > 4 bytes aligned to 4 |
| 17985 |
bytes. */ |
| 17986 |
type = strip_array_types (type); |
| 17987 |
if (TYPE_ATOMIC (type)) |
| 17988 |
return align; |
| 17989 |
|
| 17990 |
mode = TYPE_MODE (type); |
| 17991 |
switch (GET_MODE_CLASS (mode)) |
| 17992 |
{ |
| 17993 |
case MODE_INT: |
| 17994 |
case MODE_COMPLEX_INT: |
| 17995 |
case MODE_COMPLEX_FLOAT: |
| 17996 |
case MODE_FLOAT: |
| 17997 |
case MODE_DECIMAL_FLOAT: |
| 17998 |
return 32; |
| 17999 |
default: |
| 18000 |
return align; |
| 18001 |
} |
| 18002 |
} |
| 18003 |
|
| 18004 |
/* Compute the alignment for a static variable. |
| 18005 |
TYPE is the data type, and ALIGN is the alignment that |
| 18006 |
the object would ordinarily have. The value of this function is used |
| 18007 |
instead of that alignment to align the object. */ |
| 18008 |
|
| 18009 |
int |
| 18010 |
ix86_data_alignment (tree type, unsigned int align, bool opt) |
| 18011 |
{ |
| 18012 |
/* GCC 4.8 and earlier used to incorrectly assume this alignment even |
| 18013 |
for symbols from other compilation units or symbols that don't need |
| 18014 |
to bind locally. In order to preserve some ABI compatibility with |
| 18015 |
those compilers, ensure we don't decrease alignment from what we |
| 18016 |
used to assume. */ |
| 18017 |
|
| 18018 |
unsigned int max_align_compat = MIN (256, MAX_OFILE_ALIGNMENT); |
| 18019 |
|
| 18020 |
/* A data structure, equal or greater than the size of a cache line |
| 18021 |
(64 bytes in the Pentium 4 and other recent Intel processors, including |
| 18022 |
processors based on Intel Core microarchitecture) should be aligned |
| 18023 |
so that its base address is a multiple of a cache line size. */ |
| 18024 |
|
| 18025 |
unsigned int max_align |
| 18026 |
= MIN ((unsigned) ix86_tune_cost->prefetch_block * 8, MAX_OFILE_ALIGNMENT); |
| 18027 |
|
| 18028 |
if (max_align < BITS_PER_WORD) |
| 18029 |
max_align = BITS_PER_WORD; |
| 18030 |
|
| 18031 |
switch (ix86_align_data_type) |
| 18032 |
{ |
| 18033 |
case ix86_align_data_type_abi: opt = false; break; |
| 18034 |
case ix86_align_data_type_compat: max_align = BITS_PER_WORD; break; |
| 18035 |
case ix86_align_data_type_cacheline: break; |
| 18036 |
} |
| 18037 |
|
| 18038 |
if (TARGET_IAMCU) |
| 18039 |
align = iamcu_alignment (type, align); |
| 18040 |
|
| 18041 |
if (opt |
| 18042 |
&& AGGREGATE_TYPE_P (type) |
| 18043 |
&& TYPE_SIZE (type) |
| 18044 |
&& TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST) |
| 18045 |
{ |
| 18046 |
if (wi::geu_p (wi::to_wide (TYPE_SIZE (type)), max_align_compat) |
| 18047 |
&& align < max_align_compat) |
| 18048 |
align = max_align_compat; |
| 18049 |
if (wi::geu_p (wi::to_wide (TYPE_SIZE (type)), max_align) |
| 18050 |
&& align < max_align) |
| 18051 |
align = max_align; |
| 18052 |
} |
| 18053 |
|
| 18054 |
/* x86-64 ABI requires arrays greater than 16 bytes to be aligned |
| 18055 |
to 16byte boundary. */ |
| 18056 |
if (TARGET_64BIT) |
| 18057 |
{ |
| 18058 |
if ((opt ? AGGREGATE_TYPE_P (type) : TREE_CODE (type) == ARRAY_TYPE) |
| 18059 |
&& TYPE_SIZE (type) |
| 18060 |
&& TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST |
| 18061 |
&& wi::geu_p (wi::to_wide (TYPE_SIZE (type)), 128) |
| 18062 |
&& align < 128) |
| 18063 |
return 128; |
| 18064 |
} |
| 18065 |
|
| 18066 |
if (!opt) |
| 18067 |
return align; |
| 18068 |
|
| 18069 |
if (TREE_CODE (type) == ARRAY_TYPE) |
| 18070 |
{ |
| 18071 |
if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64) |
| 18072 |
return 64; |
| 18073 |
if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128) |
| 18074 |
return 128; |
| 18075 |
} |
| 18076 |
else if (TREE_CODE (type) == COMPLEX_TYPE) |
| 18077 |
{ |
| 18078 |
|
| 18079 |
if (TYPE_MODE (type) == DCmode && align < 64) |
| 18080 |
return 64; |
| 18081 |
if ((TYPE_MODE (type) == XCmode |
| 18082 |
|| TYPE_MODE (type) == TCmode) && align < 128) |
| 18083 |
return 128; |
| 18084 |
} |
| 18085 |
else if (RECORD_OR_UNION_TYPE_P (type) |
| 18086 |
&& TYPE_FIELDS (type)) |
| 18087 |
{ |
| 18088 |
if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64) |
| 18089 |
return 64; |
| 18090 |
if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128) |
| 18091 |
return 128; |
| 18092 |
} |
| 18093 |
else if (SCALAR_FLOAT_TYPE_P (type) || VECTOR_TYPE_P (type) |
| 18094 |
|| TREE_CODE (type) == INTEGER_TYPE) |
| 18095 |
{ |
| 18096 |
if (TYPE_MODE (type) == DFmode && align < 64) |
| 18097 |
return 64; |
| 18098 |
if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128) |
| 18099 |
return 128; |
| 18100 |
} |
| 18101 |
|
| 18102 |
return align; |
| 18103 |
} |
| 18104 |
|
| 18105 |
/* Implememnt TARGET_LOWER_LOCAL_DECL_ALIGNMENT. */ |
| 18106 |
static void |
| 18107 |
ix86_lower_local_decl_alignment (tree decl) |
| 18108 |
{ |
| 18109 |
unsigned int new_align = ix86_local_alignment (decl, VOIDmode, |
| 18110 |
DECL_ALIGN (decl), true); |
| 18111 |
if (new_align < DECL_ALIGN (decl)) |
| 18112 |
SET_DECL_ALIGN (decl, new_align); |
| 18113 |
} |
| 18114 |
|
| 18115 |
/* Compute the alignment for a local variable or a stack slot. EXP is |
| 18116 |
the data type or decl itself, MODE is the widest mode available and |
| 18117 |
ALIGN is the alignment that the object would ordinarily have. The |
| 18118 |
value of this macro is used instead of that alignment to align the |
| 18119 |
object. */ |
| 18120 |
|
| 18121 |
unsigned int |
| 18122 |
ix86_local_alignment (tree exp, machine_mode mode, |
| 18123 |
unsigned int align, bool may_lower) |
| 18124 |
{ |
| 18125 |
tree type, decl; |
| 18126 |
|
| 18127 |
if (exp && DECL_P (exp)) |
| 18128 |
{ |
| 18129 |
type = TREE_TYPE (exp); |
| 18130 |
decl = exp; |
| 18131 |
} |
| 18132 |
else |
| 18133 |
{ |
| 18134 |
type = exp; |
| 18135 |
decl = NULL; |
| 18136 |
} |
| 18137 |
|
| 18138 |
/* Don't do dynamic stack realignment for long long objects with |
| 18139 |
-mpreferred-stack-boundary=2. */ |
| 18140 |
if (may_lower |
| 18141 |
&& !TARGET_64BIT |
| 18142 |
&& align == 64 |
| 18143 |
&& ix86_preferred_stack_boundary < 64 |
| 18144 |
&& (mode == DImode || (type && TYPE_MODE (type) == DImode)) |
| 18145 |
&& (!type || (!TYPE_USER_ALIGN (type) |
| 18146 |
&& !TYPE_ATOMIC (strip_array_types (type)))) |
| 18147 |
&& (!decl || !DECL_USER_ALIGN (decl))) |
| 18148 |
align = 32; |
| 18149 |
|
| 18150 |
/* If TYPE is NULL, we are allocating a stack slot for caller-save |
| 18151 |
register in MODE. We will return the largest alignment of XF |
| 18152 |
and DF. */ |
| 18153 |
if (!type) |
| 18154 |
{ |
| 18155 |
if (mode == XFmode && align < GET_MODE_ALIGNMENT (DFmode)) |
| 18156 |
align = GET_MODE_ALIGNMENT (DFmode); |
| 18157 |
return align; |
| 18158 |
} |
| 18159 |
|
| 18160 |
/* Don't increase alignment for Intel MCU psABI. */ |
| 18161 |
if (TARGET_IAMCU) |
| 18162 |
return align; |
| 18163 |
|
| 18164 |
/* x86-64 ABI requires arrays greater than 16 bytes to be aligned |
| 18165 |
to 16byte boundary. Exact wording is: |
| 18166 |
|
| 18167 |
An array uses the same alignment as its elements, except that a local or |
| 18168 |
global array variable of length at least 16 bytes or |
| 18169 |
a C99 variable-length array variable always has alignment of at least 16 bytes. |
| 18170 |
|
| 18171 |
This was added to allow use of aligned SSE instructions at arrays. This |
| 18172 |
rule is meant for static storage (where compiler cannot do the analysis |
| 18173 |
by itself). We follow it for automatic variables only when convenient. |
| 18174 |
We fully control everything in the function compiled and functions from |
| 18175 |
other unit cannot rely on the alignment. |
| 18176 |
|
| 18177 |
Exclude va_list type. It is the common case of local array where |
| 18178 |
we cannot benefit from the alignment. |
| 18179 |
|
| 18180 |
TODO: Probably one should optimize for size only when var is not escaping. */ |
| 18181 |
if (TARGET_64BIT && optimize_function_for_speed_p (cfun) |
| 18182 |
&& TARGET_SSE) |
| 18183 |
{ |
| 18184 |
if (AGGREGATE_TYPE_P (type) |
| 18185 |
&& (va_list_type_node == NULL_TREE |
| 18186 |
|| (TYPE_MAIN_VARIANT (type) |
| 18187 |
!= TYPE_MAIN_VARIANT (va_list_type_node))) |
| 18188 |
&& TYPE_SIZE (type) |
| 18189 |
&& TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST |
| 18190 |
&& wi::geu_p (wi::to_wide (TYPE_SIZE (type)), 128) |
| 18191 |
&& align < 128) |
| 18192 |
return 128; |
| 18193 |
} |
| 18194 |
if (TREE_CODE (type) == ARRAY_TYPE) |
| 18195 |
{ |
| 18196 |
if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64) |
| 18197 |
return 64; |
| 18198 |
if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128) |
| 18199 |
return 128; |
| 18200 |
} |
| 18201 |
else if (TREE_CODE (type) == COMPLEX_TYPE) |
| 18202 |
{ |
| 18203 |
if (TYPE_MODE (type) == DCmode && align < 64) |
| 18204 |
return 64; |
| 18205 |
if ((TYPE_MODE (type) == XCmode |
| 18206 |
|| TYPE_MODE (type) == TCmode) && align < 128) |
| 18207 |
return 128; |
| 18208 |
} |
| 18209 |
else if (RECORD_OR_UNION_TYPE_P (type) |
| 18210 |
&& TYPE_FIELDS (type)) |
| 18211 |
{ |
| 18212 |
if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64) |
| 18213 |
return 64; |
| 18214 |
if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128) |
| 18215 |
return 128; |
| 18216 |
} |
| 18217 |
else if (SCALAR_FLOAT_TYPE_P (type) || VECTOR_TYPE_P (type) |
| 18218 |
|| TREE_CODE (type) == INTEGER_TYPE) |
| 18219 |
{ |
| 18220 |
|
| 18221 |
if (TYPE_MODE (type) == DFmode && align < 64) |
| 18222 |
return 64; |
| 18223 |
if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128) |
| 18224 |
return 128; |
| 18225 |
} |
| 18226 |
return align; |
| 18227 |
} |
| 18228 |
|
| 18229 |
/* Compute the minimum required alignment for dynamic stack realignment |
| 18230 |
purposes for a local variable, parameter or a stack slot. EXP is |
| 18231 |
the data type or decl itself, MODE is its mode and ALIGN is the |
| 18232 |
alignment that the object would ordinarily have. */ |
| 18233 |
|
| 18234 |
unsigned int |
| 18235 |
ix86_minimum_alignment (tree exp, machine_mode mode, |
| 18236 |
unsigned int align) |
| 18237 |
{ |
| 18238 |
tree type, decl; |
| 18239 |
|
| 18240 |
if (exp && DECL_P (exp)) |
| 18241 |
{ |
| 18242 |
type = TREE_TYPE (exp); |
| 18243 |
decl = exp; |
| 18244 |
} |
| 18245 |
else |
| 18246 |
{ |
| 18247 |
type = exp; |
| 18248 |
decl = NULL; |
| 18249 |
} |
| 18250 |
|
| 18251 |
if (TARGET_64BIT || align != 64 || ix86_preferred_stack_boundary >= 64) |
| 18252 |
return align; |
| 18253 |
|
| 18254 |
/* Don't do dynamic stack realignment for long long objects with |
| 18255 |
-mpreferred-stack-boundary=2. */ |
| 18256 |
if ((mode == DImode || (type && TYPE_MODE (type) == DImode)) |
| 18257 |
&& (!type || (!TYPE_USER_ALIGN (type) |
| 18258 |
&& !TYPE_ATOMIC (strip_array_types (type)))) |
| 18259 |
&& (!decl || !DECL_USER_ALIGN (decl))) |
| 18260 |
{ |
| 18261 |
gcc_checking_assert (!TARGET_STV); |
| 18262 |
return 32; |
| 18263 |
} |
| 18264 |
|
| 18265 |
return align; |
| 18266 |
} |
| 18267 |
|
| 18268 |
/* Find a location for the static chain incoming to a nested function. |
| 18269 |
This is a register, unless all free registers are used by arguments. */ |
| 18270 |
|
| 18271 |
static rtx |
| 18272 |
ix86_static_chain (const_tree fndecl_or_type, bool incoming_p) |
| 18273 |
{ |
| 18274 |
unsigned regno; |
| 18275 |
|
| 18276 |
if (TARGET_64BIT) |
| 18277 |
{ |
| 18278 |
/* We always use R10 in 64-bit mode. */ |
| 18279 |
regno = R10_REG; |
| 18280 |
} |
| 18281 |
else |
| 18282 |
{ |
| 18283 |
const_tree fntype, fndecl; |
| 18284 |
unsigned int ccvt; |
| 18285 |
|
| 18286 |
/* By default in 32-bit mode we use ECX to pass the static chain. */ |
| 18287 |
regno = CX_REG; |
| 18288 |
|
| 18289 |
if (TREE_CODE (fndecl_or_type) == FUNCTION_DECL) |
| 18290 |
{ |
| 18291 |
fntype = TREE_TYPE (fndecl_or_type); |
| 18292 |
fndecl = fndecl_or_type; |
| 18293 |
} |
| 18294 |
else |
| 18295 |
{ |
| 18296 |
fntype = fndecl_or_type; |
| 18297 |
fndecl = NULL; |
| 18298 |
} |
| 18299 |
|
| 18300 |
ccvt = ix86_get_callcvt (fntype); |
| 18301 |
if ((ccvt & IX86_CALLCVT_FASTCALL) != 0) |
| 18302 |
{ |
| 18303 |
/* Fastcall functions use ecx/edx for arguments, which leaves |
| 18304 |
us with EAX for the static chain. |
| 18305 |
Thiscall functions use ecx for arguments, which also |
| 18306 |
leaves us with EAX for the static chain. */ |
| 18307 |
regno = AX_REG; |
| 18308 |
} |
| 18309 |
else if ((ccvt & IX86_CALLCVT_THISCALL) != 0) |
| 18310 |
{ |
| 18311 |
/* Thiscall functions use ecx for arguments, which leaves |
| 18312 |
us with EAX and EDX for the static chain. |
| 18313 |
We are using for abi-compatibility EAX. */ |
| 18314 |
regno = AX_REG; |
| 18315 |
} |
| 18316 |
else if (ix86_function_regparm (fntype, fndecl) == 3) |
| 18317 |
{ |
| 18318 |
/* For regparm 3, we have no free call-clobbered registers in |
| 18319 |
which to store the static chain. In order to implement this, |
| 18320 |
we have the trampoline push the static chain to the stack. |
| 18321 |
However, we can't push a value below the return address when |
| 18322 |
we call the nested function directly, so we have to use an |
| 18323 |
alternate entry point. For this we use ESI, and have the |
| 18324 |
alternate entry point push ESI, so that things appear the |
| 18325 |
same once we're executing the nested function. */ |
| 18326 |
if (incoming_p) |
| 18327 |
{ |
| 18328 |
if (fndecl == current_function_decl |
| 18329 |
&& !ix86_static_chain_on_stack) |
| 18330 |
{ |
| 18331 |
gcc_assert (!reload_completed); |
| 18332 |
ix86_static_chain_on_stack = true; |
| 18333 |
} |
| 18334 |
return gen_frame_mem (SImode, |
| 18335 |
plus_constant (Pmode, |
| 18336 |
arg_pointer_rtx, -8)); |
| 18337 |
} |
| 18338 |
regno = SI_REG; |
| 18339 |
} |
| 18340 |
} |
| 18341 |
|
| 18342 |
return gen_rtx_REG (Pmode, regno); |
| 18343 |
} |
| 18344 |
|
| 18345 |
/* Emit RTL insns to initialize the variable parts of a trampoline. |
| 18346 |
FNDECL is the decl of the target address; M_TRAMP is a MEM for |
| 18347 |
the trampoline, and CHAIN_VALUE is an RTX for the static chain |
| 18348 |
to be passed to the target function. */ |
| 18349 |
|
| 18350 |
static void |
| 18351 |
ix86_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value) |
| 18352 |
{ |
| 18353 |
rtx mem, fnaddr; |
| 18354 |
int opcode; |
| 18355 |
int offset = 0; |
| 18356 |
bool need_endbr = (flag_cf_protection & CF_BRANCH); |
| 18357 |
|
| 18358 |
fnaddr = XEXP (DECL_RTL (fndecl), 0); |
| 18359 |
|
| 18360 |
if (TARGET_64BIT) |
| 18361 |
{ |
| 18362 |
int size; |
| 18363 |
|
| 18364 |
if (need_endbr) |
| 18365 |
{ |
| 18366 |
/* Insert ENDBR64. */ |
| 18367 |
mem = adjust_address (m_tramp, SImode, offset); |
| 18368 |
emit_move_insn (mem, gen_int_mode (0xfa1e0ff3, SImode)); |
| 18369 |
offset += 4; |
| 18370 |
} |
| 18371 |
|
| 18372 |
/* Load the function address to r11. Try to load address using |
| 18373 |
the shorter movl instead of movabs. We may want to support |
| 18374 |
movq for kernel mode, but kernel does not use trampolines at |
| 18375 |
the moment. FNADDR is a 32bit address and may not be in |
| 18376 |
DImode when ptr_mode == SImode. Always use movl in this |
| 18377 |
case. */ |
| 18378 |
if (ptr_mode == SImode |
| 18379 |
|| x86_64_zext_immediate_operand (fnaddr, VOIDmode)) |
| 18380 |
{ |
| 18381 |
fnaddr = copy_addr_to_reg (fnaddr); |
| 18382 |
|
| 18383 |
mem = adjust_address (m_tramp, HImode, offset); |
| 18384 |
emit_move_insn (mem, gen_int_mode (0xbb41, HImode)); |
| 18385 |
|
| 18386 |
mem = adjust_address (m_tramp, SImode, offset + 2); |
| 18387 |
emit_move_insn (mem, gen_lowpart (SImode, fnaddr)); |
| 18388 |
offset += 6; |
| 18389 |
} |
| 18390 |
else |
| 18391 |
{ |
| 18392 |
mem = adjust_address (m_tramp, HImode, offset); |
| 18393 |
emit_move_insn (mem, gen_int_mode (0xbb49, HImode)); |
| 18394 |
|
| 18395 |
mem = adjust_address (m_tramp, DImode, offset + 2); |
| 18396 |
emit_move_insn (mem, fnaddr); |
| 18397 |
offset += 10; |
| 18398 |
} |
| 18399 |
|
| 18400 |
/* Load static chain using movabs to r10. Use the shorter movl |
| 18401 |
instead of movabs when ptr_mode == SImode. */ |
| 18402 |
if (ptr_mode == SImode) |
| 18403 |
{ |
| 18404 |
opcode = 0xba41; |
| 18405 |
size = 6; |
| 18406 |
} |
| 18407 |
else |
| 18408 |
{ |
| 18409 |
opcode = 0xba49; |
| 18410 |
size = 10; |
| 18411 |
} |
| 18412 |
|
| 18413 |
mem = adjust_address (m_tramp, HImode, offset); |
| 18414 |
emit_move_insn (mem, gen_int_mode (opcode, HImode)); |
| 18415 |
|
| 18416 |
mem = adjust_address (m_tramp, ptr_mode, offset + 2); |
| 18417 |
emit_move_insn (mem, chain_value); |
| 18418 |
offset += size; |
| 18419 |
|
| 18420 |
/* Jump to r11; the last (unused) byte is a nop, only there to |
| 18421 |
pad the write out to a single 32-bit store. */ |
| 18422 |
mem = adjust_address (m_tramp, SImode, offset); |
| 18423 |
emit_move_insn (mem, gen_int_mode (0x90e3ff49, SImode)); |
| 18424 |
offset += 4; |
| 18425 |
} |
| 18426 |
else |
| 18427 |
{ |
| 18428 |
rtx disp, chain; |
| 18429 |
|
| 18430 |
/* Depending on the static chain location, either load a register |
| 18431 |
with a constant, or push the constant to the stack. All of the |
| 18432 |
instructions are the same size. */ |
| 18433 |
chain = ix86_static_chain (fndecl, true); |
| 18434 |
if (REG_P (chain)) |
| 18435 |
{ |
| 18436 |
switch (REGNO (chain)) |
| 18437 |
{ |
| 18438 |
case AX_REG: |
| 18439 |
opcode = 0xb8; break; |
| 18440 |
case CX_REG: |
| 18441 |
opcode = 0xb9; break; |
| 18442 |
default: |
| 18443 |
gcc_unreachable (); |
| 18444 |
} |
| 18445 |
} |
| 18446 |
else |
| 18447 |
opcode = 0x68; |
| 18448 |
|
| 18449 |
if (need_endbr) |
| 18450 |
{ |
| 18451 |
/* Insert ENDBR32. */ |
| 18452 |
mem = adjust_address (m_tramp, SImode, offset); |
| 18453 |
emit_move_insn (mem, gen_int_mode (0xfb1e0ff3, SImode)); |
| 18454 |
offset += 4; |
| 18455 |
} |
| 18456 |
|
| 18457 |
mem = adjust_address (m_tramp, QImode, offset); |
| 18458 |
emit_move_insn (mem, gen_int_mode (opcode, QImode)); |
| 18459 |
|
| 18460 |
mem = adjust_address (m_tramp, SImode, offset + 1); |
| 18461 |
emit_move_insn (mem, chain_value); |
| 18462 |
offset += 5; |
| 18463 |
|
| 18464 |
mem = adjust_address (m_tramp, QImode, offset); |
| 18465 |
emit_move_insn (mem, gen_int_mode (0xe9, QImode)); |
| 18466 |
|
| 18467 |
mem = adjust_address (m_tramp, SImode, offset + 1); |
| 18468 |
|
| 18469 |
/* Compute offset from the end of the jmp to the target function. |
| 18470 |
In the case in which the trampoline stores the static chain on |
| 18471 |
the stack, we need to skip the first insn which pushes the |
| 18472 |
(call-saved) register static chain; this push is 1 byte. */ |
| 18473 |
offset += 5; |
| 18474 |
int skip = MEM_P (chain) ? 1 : 0; |
| 18475 |
/* Skip ENDBR32 at the entry of the target function. */ |
| 18476 |
if (need_endbr |
| 18477 |
&& !cgraph_node::get (fndecl)->only_called_directly_p ()) |
| 18478 |
skip += 4; |
| 18479 |
disp = expand_binop (SImode, sub_optab, fnaddr, |
| 18480 |
plus_constant (Pmode, XEXP (m_tramp, 0), |
| 18481 |
offset - skip), |
| 18482 |
NULL_RTX, 1, OPTAB_DIRECT); |
| 18483 |
emit_move_insn (mem, disp); |
| 18484 |
} |
| 18485 |
|
| 18486 |
gcc_assert (offset <= TRAMPOLINE_SIZE); |
| 18487 |
|
| 18488 |
#ifdef HAVE_ENABLE_EXECUTE_STACK |
| 18489 |
#ifdef CHECK_EXECUTE_STACK_ENABLED |
| 18490 |
if (CHECK_EXECUTE_STACK_ENABLED) |
| 18491 |
#endif |
| 18492 |
emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"), |
| 18493 |
LCT_NORMAL, VOIDmode, XEXP (m_tramp, 0), Pmode); |
| 18494 |
#endif |
| 18495 |
} |
| 18496 |
|
| 18497 |
static bool |
| 18498 |
ix86_allocate_stack_slots_for_args (void) |
| 18499 |
{ |
| 18500 |
/* Naked functions should not allocate stack slots for arguments. */ |
| 18501 |
return !ix86_function_naked (current_function_decl); |
| 18502 |
} |
| 18503 |
|
| 18504 |
static bool |
| 18505 |
ix86_warn_func_return (tree decl) |
| 18506 |
{ |
| 18507 |
/* Naked functions are implemented entirely in assembly, including the |
| 18508 |
return sequence, so suppress warnings about this. */ |
| 18509 |
return !ix86_function_naked (decl); |
| 18510 |
} |
| 18511 |
|
| 18512 |
/* Return the shift count of a vector by scalar shift builtin second argument |
| 18513 |
ARG1. */ |
| 18514 |
static tree |
| 18515 |
ix86_vector_shift_count (tree arg1) |
| 18516 |
{ |
| 18517 |
if (tree_fits_uhwi_p (arg1)) |
| 18518 |
return arg1; |
| 18519 |
else if (TREE_CODE (arg1) == VECTOR_CST && CHAR_BIT == 8) |
| 18520 |
{ |
| 18521 |
/* The count argument is weird, passed in as various 128-bit |
| 18522 |
(or 64-bit) vectors, the low 64 bits from it are the count. */ |
| 18523 |
unsigned char buf[16]; |
| 18524 |
int len = native_encode_expr (arg1, buf, 16); |
| 18525 |
if (len == 0) |
| 18526 |
return NULL_TREE; |
| 18527 |
tree t = native_interpret_expr (uint64_type_node, buf, len); |
| 18528 |
if (t && tree_fits_uhwi_p (t)) |
| 18529 |
return t; |
| 18530 |
} |
| 18531 |
return NULL_TREE; |
| 18532 |
} |
| 18533 |
|
| 18534 |
/* Return true if arg_mask is all ones, ELEMS is elements number of |
| 18535 |
corresponding vector. */ |
| 18536 |
static bool |
| 18537 |
ix86_masked_all_ones (unsigned HOST_WIDE_INT elems, tree arg_mask) |
| 18538 |
{ |
| 18539 |
if (TREE_CODE (arg_mask) != INTEGER_CST) |
| 18540 |
return false; |
| 18541 |
|
| 18542 |
unsigned HOST_WIDE_INT mask = TREE_INT_CST_LOW (arg_mask); |
| 18543 |
if (elems == HOST_BITS_PER_WIDE_INT) |
| 18544 |
return mask == HOST_WIDE_INT_M1U; |
| 18545 |
if ((mask | (HOST_WIDE_INT_M1U << elems)) != HOST_WIDE_INT_M1U) |
| 18546 |
return false; |
| 18547 |
|
| 18548 |
return true; |
| 18549 |
} |
| 18550 |
|
| 18551 |
static tree |
| 18552 |
ix86_fold_builtin (tree fndecl, int n_args, |
| 18553 |
tree *args, bool ignore ATTRIBUTE_UNUSED) |
| 18554 |
{ |
| 18555 |
if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD) |
| 18556 |
{ |
| 18557 |
enum ix86_builtins fn_code |
| 18558 |
= (enum ix86_builtins) DECL_MD_FUNCTION_CODE (fndecl); |
| 18559 |
enum rtx_code rcode; |
| 18560 |
bool is_vshift; |
| 18561 |
enum tree_code tcode; |
| 18562 |
bool is_scalar; |
| 18563 |
unsigned HOST_WIDE_INT mask; |
| 18564 |
|
| 18565 |
switch (fn_code) |
| 18566 |
{ |
| 18567 |
case IX86_BUILTIN_CPU_IS: |
| 18568 |
case IX86_BUILTIN_CPU_SUPPORTS: |
| 18569 |
gcc_assert (n_args == 1); |
| 18570 |
return fold_builtin_cpu (fndecl, args); |
| 18571 |
|
| 18572 |
case IX86_BUILTIN_NANQ: |
| 18573 |
case IX86_BUILTIN_NANSQ: |
| 18574 |
{ |
| 18575 |
tree type = TREE_TYPE (TREE_TYPE (fndecl)); |
| 18576 |
const char *str = c_getstr (*args); |
| 18577 |
int quiet = fn_code == IX86_BUILTIN_NANQ; |
| 18578 |
REAL_VALUE_TYPE real; |
| 18579 |
|
| 18580 |
if (str && real_nan (&real, str, quiet, TYPE_MODE (type))) |
| 18581 |
return build_real (type, real); |
| 18582 |
return NULL_TREE; |
| 18583 |
} |
| 18584 |
|
| 18585 |
case IX86_BUILTIN_INFQ: |
| 18586 |
case IX86_BUILTIN_HUGE_VALQ: |
| 18587 |
{ |
| 18588 |
tree type = TREE_TYPE (TREE_TYPE (fndecl)); |
| 18589 |
REAL_VALUE_TYPE inf; |
| 18590 |
real_inf (&inf); |
| 18591 |
return build_real (type, inf); |
| 18592 |
} |
| 18593 |
|
| 18594 |
case IX86_BUILTIN_TZCNT16: |
| 18595 |
case IX86_BUILTIN_CTZS: |
| 18596 |
case IX86_BUILTIN_TZCNT32: |
| 18597 |
case IX86_BUILTIN_TZCNT64: |
| 18598 |
gcc_assert (n_args == 1); |
| 18599 |
if (TREE_CODE (args[0]) == INTEGER_CST) |
| 18600 |
{ |
| 18601 |
tree type = TREE_TYPE (TREE_TYPE (fndecl)); |
| 18602 |
tree arg = args[0]; |
| 18603 |
if (fn_code == IX86_BUILTIN_TZCNT16 |
| 18604 |
|| fn_code == IX86_BUILTIN_CTZS) |
| 18605 |
arg = fold_convert (short_unsigned_type_node, arg); |
| 18606 |
if (integer_zerop (arg)) |
| 18607 |
return build_int_cst (type, TYPE_PRECISION (TREE_TYPE (arg))); |
| 18608 |
else |
| 18609 |
return fold_const_call (CFN_CTZ, type, arg); |
| 18610 |
} |
| 18611 |
break; |
| 18612 |
|
| 18613 |
case IX86_BUILTIN_LZCNT16: |
| 18614 |
case IX86_BUILTIN_CLZS: |
| 18615 |
case IX86_BUILTIN_LZCNT32: |
| 18616 |
case IX86_BUILTIN_LZCNT64: |
| 18617 |
gcc_assert (n_args == 1); |
| 18618 |
if (TREE_CODE (args[0]) == INTEGER_CST) |
| 18619 |
{ |
| 18620 |
tree type = TREE_TYPE (TREE_TYPE (fndecl)); |
| 18621 |
tree arg = args[0]; |
| 18622 |
if (fn_code == IX86_BUILTIN_LZCNT16 |
| 18623 |
|| fn_code == IX86_BUILTIN_CLZS) |
| 18624 |
arg = fold_convert (short_unsigned_type_node, arg); |
| 18625 |
if (integer_zerop (arg)) |
| 18626 |
return build_int_cst (type, TYPE_PRECISION (TREE_TYPE (arg))); |
| 18627 |
else |
| 18628 |
return fold_const_call (CFN_CLZ, type, arg); |
| 18629 |
} |
| 18630 |
break; |
| 18631 |
|
| 18632 |
case IX86_BUILTIN_BEXTR32: |
| 18633 |
case IX86_BUILTIN_BEXTR64: |
| 18634 |
case IX86_BUILTIN_BEXTRI32: |
| 18635 |
case IX86_BUILTIN_BEXTRI64: |
| 18636 |
gcc_assert (n_args == 2); |
| 18637 |
if (tree_fits_uhwi_p (args[1])) |
| 18638 |
{ |
| 18639 |
unsigned HOST_WIDE_INT res = 0; |
| 18640 |
unsigned int prec = TYPE_PRECISION (TREE_TYPE (args[0])); |
| 18641 |
unsigned int start = tree_to_uhwi (args[1]); |
| 18642 |
unsigned int len = (start & 0xff00) >> 8; |
| 18643 |
tree lhs_type = TREE_TYPE (TREE_TYPE (fndecl)); |
| 18644 |
start &= 0xff; |
| 18645 |
if (start >= prec || len == 0) |
| 18646 |
return omit_one_operand (lhs_type, build_zero_cst (lhs_type), |
| 18647 |
args[0]); |
| 18648 |
else if (!tree_fits_uhwi_p (args[0])) |
| 18649 |
break; |
| 18650 |
else |
| 18651 |
res = tree_to_uhwi (args[0]) >> start; |
| 18652 |
if (len > prec) |
| 18653 |
len = prec; |
| 18654 |
if (len < HOST_BITS_PER_WIDE_INT) |
| 18655 |
res &= (HOST_WIDE_INT_1U << len) - 1; |
| 18656 |
return build_int_cstu (lhs_type, res); |
| 18657 |
} |
| 18658 |
break; |
| 18659 |
|
| 18660 |
case IX86_BUILTIN_BZHI32: |
| 18661 |
case IX86_BUILTIN_BZHI64: |
| 18662 |
gcc_assert (n_args == 2); |
| 18663 |
if (tree_fits_uhwi_p (args[1])) |
| 18664 |
{ |
| 18665 |
unsigned int idx = tree_to_uhwi (args[1]) & 0xff; |
| 18666 |
tree lhs_type = TREE_TYPE (TREE_TYPE (fndecl)); |
| 18667 |
if (idx >= TYPE_PRECISION (TREE_TYPE (args[0]))) |
| 18668 |
return args[0]; |
| 18669 |
if (idx == 0) |
| 18670 |
return omit_one_operand (lhs_type, build_zero_cst (lhs_type), |
| 18671 |
args[0]); |
| 18672 |
if (!tree_fits_uhwi_p (args[0])) |
| 18673 |
break; |
| 18674 |
unsigned HOST_WIDE_INT res = tree_to_uhwi (args[0]); |
| 18675 |
res &= ~(HOST_WIDE_INT_M1U << idx); |
| 18676 |
return build_int_cstu (lhs_type, res); |
| 18677 |
} |
| 18678 |
break; |
| 18679 |
|
| 18680 |
case IX86_BUILTIN_PDEP32: |
| 18681 |
case IX86_BUILTIN_PDEP64: |
| 18682 |
gcc_assert (n_args == 2); |
| 18683 |
if (tree_fits_uhwi_p (args[0]) && tree_fits_uhwi_p (args[1])) |
| 18684 |
{ |
| 18685 |
unsigned HOST_WIDE_INT src = tree_to_uhwi (args[0]); |
| 18686 |
unsigned HOST_WIDE_INT mask = tree_to_uhwi (args[1]); |
| 18687 |
unsigned HOST_WIDE_INT res = 0; |
| 18688 |
unsigned HOST_WIDE_INT m, k = 1; |
| 18689 |
for (m = 1; m; m <<= 1) |
| 18690 |
if ((mask & m) != 0) |
| 18691 |
{ |
| 18692 |
if ((src & k) != 0) |
| 18693 |
res |= m; |
| 18694 |
k <<= 1; |
| 18695 |
} |
| 18696 |
return build_int_cstu (TREE_TYPE (TREE_TYPE (fndecl)), res); |
| 18697 |
} |
| 18698 |
break; |
| 18699 |
|
| 18700 |
case IX86_BUILTIN_PEXT32: |
| 18701 |
case IX86_BUILTIN_PEXT64: |
| 18702 |
gcc_assert (n_args == 2); |
| 18703 |
if (tree_fits_uhwi_p (args[0]) && tree_fits_uhwi_p (args[1])) |
| 18704 |
{ |
| 18705 |
unsigned HOST_WIDE_INT src = tree_to_uhwi (args[0]); |
| 18706 |
unsigned HOST_WIDE_INT mask = tree_to_uhwi (args[1]); |
| 18707 |
unsigned HOST_WIDE_INT res = 0; |
| 18708 |
unsigned HOST_WIDE_INT m, k = 1; |
| 18709 |
for (m = 1; m; m <<= 1) |
| 18710 |
if ((mask & m) != 0) |
| 18711 |
{ |
| 18712 |
if ((src & m) != 0) |
| 18713 |
res |= k; |
| 18714 |
k <<= 1; |
| 18715 |
} |
| 18716 |
return build_int_cstu (TREE_TYPE (TREE_TYPE (fndecl)), res); |
| 18717 |
} |
| 18718 |
break; |
| 18719 |
|
| 18720 |
case IX86_BUILTIN_MOVMSKPS: |
| 18721 |
case IX86_BUILTIN_PMOVMSKB: |
| 18722 |
case IX86_BUILTIN_MOVMSKPD: |
| 18723 |
case IX86_BUILTIN_PMOVMSKB128: |
| 18724 |
case IX86_BUILTIN_MOVMSKPD256: |
| 18725 |
case IX86_BUILTIN_MOVMSKPS256: |
| 18726 |
case IX86_BUILTIN_PMOVMSKB256: |
| 18727 |
gcc_assert (n_args == 1); |
| 18728 |
if (TREE_CODE (args[0]) == VECTOR_CST) |
| 18729 |
{ |
| 18730 |
HOST_WIDE_INT res = 0; |
| 18731 |
for (unsigned i = 0; i < VECTOR_CST_NELTS (args[0]); ++i) |
| 18732 |
{ |
| 18733 |
tree e = VECTOR_CST_ELT (args[0], i); |
| 18734 |
if (TREE_CODE (e) == INTEGER_CST && !TREE_OVERFLOW (e)) |
| 18735 |
{ |
| 18736 |
if (wi::neg_p (wi::to_wide (e))) |
| 18737 |
res |= HOST_WIDE_INT_1 << i; |
| 18738 |
} |
| 18739 |
else if (TREE_CODE (e) == REAL_CST && !TREE_OVERFLOW (e)) |
| 18740 |
{ |
| 18741 |
if (TREE_REAL_CST (e).sign) |
| 18742 |
res |= HOST_WIDE_INT_1 << i; |
| 18743 |
} |
| 18744 |
else |
| 18745 |
return NULL_TREE; |
| 18746 |
} |
| 18747 |
return build_int_cst (TREE_TYPE (TREE_TYPE (fndecl)), res); |
| 18748 |
} |
| 18749 |
break; |
| 18750 |
|
| 18751 |
case IX86_BUILTIN_PSLLD: |
| 18752 |
case IX86_BUILTIN_PSLLD128: |
| 18753 |
case IX86_BUILTIN_PSLLD128_MASK: |
| 18754 |
case IX86_BUILTIN_PSLLD256: |
| 18755 |
case IX86_BUILTIN_PSLLD256_MASK: |
| 18756 |
case IX86_BUILTIN_PSLLD512: |
| 18757 |
case IX86_BUILTIN_PSLLDI: |
| 18758 |
case IX86_BUILTIN_PSLLDI128: |
| 18759 |
case IX86_BUILTIN_PSLLDI128_MASK: |
| 18760 |
case IX86_BUILTIN_PSLLDI256: |
| 18761 |
case IX86_BUILTIN_PSLLDI256_MASK: |
| 18762 |
case IX86_BUILTIN_PSLLDI512: |
| 18763 |
case IX86_BUILTIN_PSLLQ: |
| 18764 |
case IX86_BUILTIN_PSLLQ128: |
| 18765 |
case IX86_BUILTIN_PSLLQ128_MASK: |
| 18766 |
case IX86_BUILTIN_PSLLQ256: |
| 18767 |
case IX86_BUILTIN_PSLLQ256_MASK: |
| 18768 |
case IX86_BUILTIN_PSLLQ512: |
| 18769 |
case IX86_BUILTIN_PSLLQI: |
| 18770 |
case IX86_BUILTIN_PSLLQI128: |
| 18771 |
case IX86_BUILTIN_PSLLQI128_MASK: |
| 18772 |
case IX86_BUILTIN_PSLLQI256: |
| 18773 |
case IX86_BUILTIN_PSLLQI256_MASK: |
| 18774 |
case IX86_BUILTIN_PSLLQI512: |
| 18775 |
case IX86_BUILTIN_PSLLW: |
| 18776 |
case IX86_BUILTIN_PSLLW128: |
| 18777 |
case IX86_BUILTIN_PSLLW128_MASK: |
| 18778 |
case IX86_BUILTIN_PSLLW256: |
| 18779 |
case IX86_BUILTIN_PSLLW256_MASK: |
| 18780 |
case IX86_BUILTIN_PSLLW512_MASK: |
| 18781 |
case IX86_BUILTIN_PSLLWI: |
| 18782 |
case IX86_BUILTIN_PSLLWI128: |
| 18783 |
case IX86_BUILTIN_PSLLWI128_MASK: |
| 18784 |
case IX86_BUILTIN_PSLLWI256: |
| 18785 |
case IX86_BUILTIN_PSLLWI256_MASK: |
| 18786 |
case IX86_BUILTIN_PSLLWI512_MASK: |
| 18787 |
rcode = ASHIFT; |
| 18788 |
is_vshift = false; |
| 18789 |
goto do_shift; |
| 18790 |
case IX86_BUILTIN_PSRAD: |
| 18791 |
case IX86_BUILTIN_PSRAD128: |
| 18792 |
case IX86_BUILTIN_PSRAD128_MASK: |
| 18793 |
case IX86_BUILTIN_PSRAD256: |
| 18794 |
case IX86_BUILTIN_PSRAD256_MASK: |
| 18795 |
case IX86_BUILTIN_PSRAD512: |
| 18796 |
case IX86_BUILTIN_PSRADI: |
| 18797 |
case IX86_BUILTIN_PSRADI128: |
| 18798 |
case IX86_BUILTIN_PSRADI128_MASK: |
| 18799 |
case IX86_BUILTIN_PSRADI256: |
| 18800 |
case IX86_BUILTIN_PSRADI256_MASK: |
| 18801 |
case IX86_BUILTIN_PSRADI512: |
| 18802 |
case IX86_BUILTIN_PSRAQ128_MASK: |
| 18803 |
case IX86_BUILTIN_PSRAQ256_MASK: |
| 18804 |
case IX86_BUILTIN_PSRAQ512: |
| 18805 |
case IX86_BUILTIN_PSRAQI128_MASK: |
| 18806 |
case IX86_BUILTIN_PSRAQI256_MASK: |
| 18807 |
case IX86_BUILTIN_PSRAQI512: |
| 18808 |
case IX86_BUILTIN_PSRAW: |
| 18809 |
case IX86_BUILTIN_PSRAW128: |
| 18810 |
case IX86_BUILTIN_PSRAW128_MASK: |
| 18811 |
case IX86_BUILTIN_PSRAW256: |
| 18812 |
case IX86_BUILTIN_PSRAW256_MASK: |
| 18813 |
case IX86_BUILTIN_PSRAW512: |
| 18814 |
case IX86_BUILTIN_PSRAWI: |
| 18815 |
case IX86_BUILTIN_PSRAWI128: |
| 18816 |
case IX86_BUILTIN_PSRAWI128_MASK: |
| 18817 |
case IX86_BUILTIN_PSRAWI256: |
| 18818 |
case IX86_BUILTIN_PSRAWI256_MASK: |
| 18819 |
case IX86_BUILTIN_PSRAWI512: |
| 18820 |
rcode = ASHIFTRT; |
| 18821 |
is_vshift = false; |
| 18822 |
goto do_shift; |
| 18823 |
case IX86_BUILTIN_PSRLD: |
| 18824 |
case IX86_BUILTIN_PSRLD128: |
| 18825 |
case IX86_BUILTIN_PSRLD128_MASK: |
| 18826 |
case IX86_BUILTIN_PSRLD256: |
| 18827 |
case IX86_BUILTIN_PSRLD256_MASK: |
| 18828 |
case IX86_BUILTIN_PSRLD512: |
| 18829 |
case IX86_BUILTIN_PSRLDI: |
| 18830 |
case IX86_BUILTIN_PSRLDI128: |
| 18831 |
case IX86_BUILTIN_PSRLDI128_MASK: |
| 18832 |
case IX86_BUILTIN_PSRLDI256: |
| 18833 |
case IX86_BUILTIN_PSRLDI256_MASK: |
| 18834 |
case IX86_BUILTIN_PSRLDI512: |
| 18835 |
case IX86_BUILTIN_PSRLQ: |
| 18836 |
case IX86_BUILTIN_PSRLQ128: |
| 18837 |
case IX86_BUILTIN_PSRLQ128_MASK: |
| 18838 |
case IX86_BUILTIN_PSRLQ256: |
| 18839 |
case IX86_BUILTIN_PSRLQ256_MASK: |
| 18840 |
case IX86_BUILTIN_PSRLQ512: |
| 18841 |
case IX86_BUILTIN_PSRLQI: |
| 18842 |
case IX86_BUILTIN_PSRLQI128: |
| 18843 |
case IX86_BUILTIN_PSRLQI128_MASK: |
| 18844 |
case IX86_BUILTIN_PSRLQI256: |
| 18845 |
case IX86_BUILTIN_PSRLQI256_MASK: |
| 18846 |
case IX86_BUILTIN_PSRLQI512: |
| 18847 |
case IX86_BUILTIN_PSRLW: |
| 18848 |
case IX86_BUILTIN_PSRLW128: |
| 18849 |
case IX86_BUILTIN_PSRLW128_MASK: |
| 18850 |
case IX86_BUILTIN_PSRLW256: |
| 18851 |
case IX86_BUILTIN_PSRLW256_MASK: |
| 18852 |
case IX86_BUILTIN_PSRLW512: |
| 18853 |
case IX86_BUILTIN_PSRLWI: |
| 18854 |
case IX86_BUILTIN_PSRLWI128: |
| 18855 |
case IX86_BUILTIN_PSRLWI128_MASK: |
| 18856 |
case IX86_BUILTIN_PSRLWI256: |
| 18857 |
case IX86_BUILTIN_PSRLWI256_MASK: |
| 18858 |
case IX86_BUILTIN_PSRLWI512: |
| 18859 |
rcode = LSHIFTRT; |
| 18860 |
is_vshift = false; |
| 18861 |
goto do_shift; |
| 18862 |
case IX86_BUILTIN_PSLLVV16HI: |
| 18863 |
case IX86_BUILTIN_PSLLVV16SI: |
| 18864 |
case IX86_BUILTIN_PSLLVV2DI: |
| 18865 |
case IX86_BUILTIN_PSLLVV2DI_MASK: |
| 18866 |
case IX86_BUILTIN_PSLLVV32HI: |
| 18867 |
case IX86_BUILTIN_PSLLVV4DI: |
| 18868 |
case IX86_BUILTIN_PSLLVV4DI_MASK: |
| 18869 |
case IX86_BUILTIN_PSLLVV4SI: |
| 18870 |
case IX86_BUILTIN_PSLLVV4SI_MASK: |
| 18871 |
case IX86_BUILTIN_PSLLVV8DI: |
| 18872 |
case IX86_BUILTIN_PSLLVV8HI: |
| 18873 |
case IX86_BUILTIN_PSLLVV8SI: |
| 18874 |
case IX86_BUILTIN_PSLLVV8SI_MASK: |
| 18875 |
rcode = ASHIFT; |
| 18876 |
is_vshift = true; |
| 18877 |
goto do_shift; |
| 18878 |
case IX86_BUILTIN_PSRAVQ128: |
| 18879 |
case IX86_BUILTIN_PSRAVQ256: |
| 18880 |
case IX86_BUILTIN_PSRAVV16HI: |
| 18881 |
case IX86_BUILTIN_PSRAVV16SI: |
| 18882 |
case IX86_BUILTIN_PSRAVV32HI: |
| 18883 |
case IX86_BUILTIN_PSRAVV4SI: |
| 18884 |
case IX86_BUILTIN_PSRAVV4SI_MASK: |
| 18885 |
case IX86_BUILTIN_PSRAVV8DI: |
| 18886 |
case IX86_BUILTIN_PSRAVV8HI: |
| 18887 |
case IX86_BUILTIN_PSRAVV8SI: |
| 18888 |
case IX86_BUILTIN_PSRAVV8SI_MASK: |
| 18889 |
rcode = ASHIFTRT; |
| 18890 |
is_vshift = true; |
| 18891 |
goto do_shift; |
| 18892 |
case IX86_BUILTIN_PSRLVV16HI: |
| 18893 |
case IX86_BUILTIN_PSRLVV16SI: |
| 18894 |
case IX86_BUILTIN_PSRLVV2DI: |
| 18895 |
case IX86_BUILTIN_PSRLVV2DI_MASK: |
| 18896 |
case IX86_BUILTIN_PSRLVV32HI: |
| 18897 |
case IX86_BUILTIN_PSRLVV4DI: |
| 18898 |
case IX86_BUILTIN_PSRLVV4DI_MASK: |
| 18899 |
case IX86_BUILTIN_PSRLVV4SI: |
| 18900 |
case IX86_BUILTIN_PSRLVV4SI_MASK: |
| 18901 |
case IX86_BUILTIN_PSRLVV8DI: |
| 18902 |
case IX86_BUILTIN_PSRLVV8HI: |
| 18903 |
case IX86_BUILTIN_PSRLVV8SI: |
| 18904 |
case IX86_BUILTIN_PSRLVV8SI_MASK: |
| 18905 |
rcode = LSHIFTRT; |
| 18906 |
is_vshift = true; |
| 18907 |
goto do_shift; |
| 18908 |
|
| 18909 |
do_shift: |
| 18910 |
gcc_assert (n_args >= 2); |
| 18911 |
if (TREE_CODE (args[0]) != VECTOR_CST) |
| 18912 |
break; |
| 18913 |
mask = HOST_WIDE_INT_M1U; |
| 18914 |
if (n_args > 2) |
| 18915 |
{ |
| 18916 |
/* This is masked shift. */ |
| 18917 |
if (!tree_fits_uhwi_p (args[n_args - 1]) |
| 18918 |
|| TREE_SIDE_EFFECTS (args[n_args - 2])) |
| 18919 |
break; |
| 18920 |
mask = tree_to_uhwi (args[n_args - 1]); |
| 18921 |
unsigned elems = TYPE_VECTOR_SUBPARTS (TREE_TYPE (args[0])); |
| 18922 |
mask |= HOST_WIDE_INT_M1U << elems; |
| 18923 |
if (mask != HOST_WIDE_INT_M1U |
| 18924 |
&& TREE_CODE (args[n_args - 2]) != VECTOR_CST) |
| 18925 |
break; |
| 18926 |
if (mask == (HOST_WIDE_INT_M1U << elems)) |
| 18927 |
return args[n_args - 2]; |
| 18928 |
} |
| 18929 |
if (is_vshift && TREE_CODE (args[1]) != VECTOR_CST) |
| 18930 |
break; |
| 18931 |
if (tree tem = (is_vshift ? integer_one_node |
| 18932 |
: ix86_vector_shift_count (args[1]))) |
| 18933 |
{ |
| 18934 |
unsigned HOST_WIDE_INT count = tree_to_uhwi (tem); |
| 18935 |
unsigned HOST_WIDE_INT prec |
| 18936 |
= TYPE_PRECISION (TREE_TYPE (TREE_TYPE (args[0]))); |
| 18937 |
if (count == 0 && mask == HOST_WIDE_INT_M1U) |
| 18938 |
return args[0]; |
| 18939 |
if (count >= prec) |
| 18940 |
{ |
| 18941 |
if (rcode == ASHIFTRT) |
| 18942 |
count = prec - 1; |
| 18943 |
else if (mask == HOST_WIDE_INT_M1U) |
| 18944 |
return build_zero_cst (TREE_TYPE (args[0])); |
| 18945 |
} |
| 18946 |
tree countt = NULL_TREE; |
| 18947 |
if (!is_vshift) |
| 18948 |
{ |
| 18949 |
if (count >= prec) |
| 18950 |
countt = integer_zero_node; |
| 18951 |
else |
| 18952 |
countt = build_int_cst (integer_type_node, count); |
| 18953 |
} |
| 18954 |
tree_vector_builder builder; |
| 18955 |
if (mask != HOST_WIDE_INT_M1U || is_vshift) |
| 18956 |
builder.new_vector (TREE_TYPE (args[0]), |
| 18957 |
TYPE_VECTOR_SUBPARTS (TREE_TYPE (args[0])), |
| 18958 |
1); |
| 18959 |
else |
| 18960 |
builder.new_unary_operation (TREE_TYPE (args[0]), args[0], |
| 18961 |
false); |
| 18962 |
unsigned int cnt = builder.encoded_nelts (); |
| 18963 |
for (unsigned int i = 0; i < cnt; ++i) |
| 18964 |
{ |
| 18965 |
tree elt = VECTOR_CST_ELT (args[0], i); |
| 18966 |
if (TREE_CODE (elt) != INTEGER_CST || TREE_OVERFLOW (elt)) |
| 18967 |
return NULL_TREE; |
| 18968 |
tree type = TREE_TYPE (elt); |
| 18969 |
if (rcode == LSHIFTRT) |
| 18970 |
elt = fold_convert (unsigned_type_for (type), elt); |
| 18971 |
if (is_vshift) |
| 18972 |
{ |
| 18973 |
countt = VECTOR_CST_ELT (args[1], i); |
| 18974 |
if (TREE_CODE (countt) != INTEGER_CST |
| 18975 |
|| TREE_OVERFLOW (countt)) |
| 18976 |
return NULL_TREE; |
| 18977 |
if (wi::neg_p (wi::to_wide (countt)) |
| 18978 |
|| wi::to_widest (countt) >= prec) |
| 18979 |
{ |
| 18980 |
if (rcode == ASHIFTRT) |
| 18981 |
countt = build_int_cst (TREE_TYPE (countt), |
| 18982 |
prec - 1); |
| 18983 |
else |
| 18984 |
{ |
| 18985 |
elt = build_zero_cst (TREE_TYPE (elt)); |
| 18986 |
countt = build_zero_cst (TREE_TYPE (countt)); |
| 18987 |
} |
| 18988 |
} |
| 18989 |
} |
| 18990 |
else if (count >= prec) |
| 18991 |
elt = build_zero_cst (TREE_TYPE (elt)); |
| 18992 |
elt = const_binop (rcode == ASHIFT |
| 18993 |
? LSHIFT_EXPR : RSHIFT_EXPR, |
| 18994 |
TREE_TYPE (elt), elt, countt); |
| 18995 |
if (!elt || TREE_CODE (elt) != INTEGER_CST) |
| 18996 |
return NULL_TREE; |
| 18997 |
if (rcode == LSHIFTRT) |
| 18998 |
elt = fold_convert (type, elt); |
| 18999 |
if ((mask & (HOST_WIDE_INT_1U << i)) == 0) |
| 19000 |
{ |
| 19001 |
elt = VECTOR_CST_ELT (args[n_args - 2], i); |
| 19002 |
if (TREE_CODE (elt) != INTEGER_CST |
| 19003 |
|| TREE_OVERFLOW (elt)) |
| 19004 |
return NULL_TREE; |
| 19005 |
} |
| 19006 |
builder.quick_push (elt); |
| 19007 |
} |
| 19008 |
return builder.build (); |
| 19009 |
} |
| 19010 |
break; |
| 19011 |
|
| 19012 |
case IX86_BUILTIN_MINSS: |
| 19013 |
case IX86_BUILTIN_MINSH_MASK: |
| 19014 |
tcode = LT_EXPR; |
| 19015 |
is_scalar = true; |
| 19016 |
goto do_minmax; |
| 19017 |
|
| 19018 |
case IX86_BUILTIN_MAXSS: |
| 19019 |
case IX86_BUILTIN_MAXSH_MASK: |
| 19020 |
tcode = GT_EXPR; |
| 19021 |
is_scalar = true; |
| 19022 |
goto do_minmax; |
| 19023 |
|
| 19024 |
case IX86_BUILTIN_MINPS: |
| 19025 |
case IX86_BUILTIN_MINPD: |
| 19026 |
case IX86_BUILTIN_MINPS256: |
| 19027 |
case IX86_BUILTIN_MINPD256: |
| 19028 |
case IX86_BUILTIN_MINPS512: |
| 19029 |
case IX86_BUILTIN_MINPD512: |
| 19030 |
case IX86_BUILTIN_MINPS128_MASK: |
| 19031 |
case IX86_BUILTIN_MINPD128_MASK: |
| 19032 |
case IX86_BUILTIN_MINPS256_MASK: |
| 19033 |
case IX86_BUILTIN_MINPD256_MASK: |
| 19034 |
case IX86_BUILTIN_MINPH128_MASK: |
| 19035 |
case IX86_BUILTIN_MINPH256_MASK: |
| 19036 |
case IX86_BUILTIN_MINPH512_MASK: |
| 19037 |
tcode = LT_EXPR; |
| 19038 |
is_scalar = false; |
| 19039 |
goto do_minmax; |
| 19040 |
|
| 19041 |
case IX86_BUILTIN_MAXPS: |
| 19042 |
case IX86_BUILTIN_MAXPD: |
| 19043 |
case IX86_BUILTIN_MAXPS256: |
| 19044 |
case IX86_BUILTIN_MAXPD256: |
| 19045 |
case IX86_BUILTIN_MAXPS512: |
| 19046 |
case IX86_BUILTIN_MAXPD512: |
| 19047 |
case IX86_BUILTIN_MAXPS128_MASK: |
| 19048 |
case IX86_BUILTIN_MAXPD128_MASK: |
| 19049 |
case IX86_BUILTIN_MAXPS256_MASK: |
| 19050 |
case IX86_BUILTIN_MAXPD256_MASK: |
| 19051 |
case IX86_BUILTIN_MAXPH128_MASK: |
| 19052 |
case IX86_BUILTIN_MAXPH256_MASK: |
| 19053 |
case IX86_BUILTIN_MAXPH512_MASK: |
| 19054 |
tcode = GT_EXPR; |
| 19055 |
is_scalar = false; |
| 19056 |
do_minmax: |
| 19057 |
gcc_assert (n_args >= 2); |
| 19058 |
if (TREE_CODE (args[0]) != VECTOR_CST |
| 19059 |
|| TREE_CODE (args[1]) != VECTOR_CST) |
| 19060 |
break; |
| 19061 |
mask = HOST_WIDE_INT_M1U; |
| 19062 |
if (n_args > 2) |
| 19063 |
{ |
| 19064 |
gcc_assert (n_args >= 4); |
| 19065 |
/* This is masked minmax. */ |
| 19066 |
if (TREE_CODE (args[3]) != INTEGER_CST |
| 19067 |
|| TREE_SIDE_EFFECTS (args[2])) |
| 19068 |
break; |
| 19069 |
mask = TREE_INT_CST_LOW (args[3]); |
| 19070 |
unsigned elems = TYPE_VECTOR_SUBPARTS (TREE_TYPE (args[0])); |
| 19071 |
mask |= HOST_WIDE_INT_M1U << elems; |
| 19072 |
if (mask != HOST_WIDE_INT_M1U |
| 19073 |
&& TREE_CODE (args[2]) != VECTOR_CST) |
| 19074 |
break; |
| 19075 |
if (n_args >= 5) |
| 19076 |
{ |
| 19077 |
if (!tree_fits_uhwi_p (args[4])) |
| 19078 |
break; |
| 19079 |
if (tree_to_uhwi (args[4]) != 4 |
| 19080 |
&& tree_to_uhwi (args[4]) != 8) |
| 19081 |
break; |
| 19082 |
} |
| 19083 |
if (mask == (HOST_WIDE_INT_M1U << elems)) |
| 19084 |
return args[2]; |
| 19085 |
} |
| 19086 |
/* Punt on NaNs, unless exceptions are disabled. */ |
| 19087 |
if (HONOR_NANS (args[0]) |
| 19088 |
&& (n_args < 5 || tree_to_uhwi (args[4]) != 8)) |
| 19089 |
for (int i = 0; i < 2; ++i) |
| 19090 |
{ |
| 19091 |
unsigned count = vector_cst_encoded_nelts (args[i]); |
| 19092 |
for (unsigned j = 0; j < count; ++j) |
| 19093 |
if (tree_expr_nan_p (VECTOR_CST_ENCODED_ELT (args[i], j))) |
| 19094 |
return NULL_TREE; |
| 19095 |
} |
| 19096 |
{ |
| 19097 |
tree res = const_binop (tcode, |
| 19098 |
truth_type_for (TREE_TYPE (args[0])), |
| 19099 |
args[0], args[1]); |
| 19100 |
if (res == NULL_TREE || TREE_CODE (res) != VECTOR_CST) |
| 19101 |
break; |
| 19102 |
res = fold_ternary (VEC_COND_EXPR, TREE_TYPE (args[0]), res, |
| 19103 |
args[0], args[1]); |
| 19104 |
if (res == NULL_TREE || TREE_CODE (res) != VECTOR_CST) |
| 19105 |
break; |
| 19106 |
if (mask != HOST_WIDE_INT_M1U) |
| 19107 |
{ |
| 19108 |
unsigned nelts = TYPE_VECTOR_SUBPARTS (TREE_TYPE (args[0])); |
| 19109 |
vec_perm_builder sel (nelts, nelts, 1); |
| 19110 |
for (unsigned int i = 0; i < nelts; i++) |
| 19111 |
if (mask & (HOST_WIDE_INT_1U << i)) |
| 19112 |
sel.quick_push (i); |
| 19113 |
else |
| 19114 |
sel.quick_push (nelts + i); |
| 19115 |
vec_perm_indices indices (sel, 2, nelts); |
| 19116 |
res = fold_vec_perm (TREE_TYPE (args[0]), res, args[2], |
| 19117 |
indices); |
| 19118 |
if (res == NULL_TREE || TREE_CODE (res) != VECTOR_CST) |
| 19119 |
break; |
| 19120 |
} |
| 19121 |
if (is_scalar) |
| 19122 |
{ |
| 19123 |
unsigned nelts = TYPE_VECTOR_SUBPARTS (TREE_TYPE (args[0])); |
| 19124 |
vec_perm_builder sel (nelts, nelts, 1); |
| 19125 |
sel.quick_push (0); |
| 19126 |
for (unsigned int i = 1; i < nelts; i++) |
| 19127 |
sel.quick_push (nelts + i); |
| 19128 |
vec_perm_indices indices (sel, 2, nelts); |
| 19129 |
res = fold_vec_perm (TREE_TYPE (args[0]), res, args[0], |
| 19130 |
indices); |
| 19131 |
if (res == NULL_TREE || TREE_CODE (res) != VECTOR_CST) |
| 19132 |
break; |
| 19133 |
} |
| 19134 |
return res; |
| 19135 |
} |
| 19136 |
|
| 19137 |
default: |
| 19138 |
break; |
| 19139 |
} |
| 19140 |
} |
| 19141 |
|
| 19142 |
#ifdef SUBTARGET_FOLD_BUILTIN |
| 19143 |
return SUBTARGET_FOLD_BUILTIN (fndecl, n_args, args, ignore); |
| 19144 |
#endif |
| 19145 |
|
| 19146 |
return NULL_TREE; |
| 19147 |
} |
| 19148 |
|
| 19149 |
/* Fold a MD builtin (use ix86_fold_builtin for folding into |
| 19150 |
constant) in GIMPLE. */ |
| 19151 |
|
| 19152 |
bool |
| 19153 |
ix86_gimple_fold_builtin (gimple_stmt_iterator *gsi) |
| 19154 |
{ |
| 19155 |
gimple *stmt = gsi_stmt (*gsi), *g; |
| 19156 |
gimple_seq stmts = NULL; |
| 19157 |
tree fndecl = gimple_call_fndecl (stmt); |
| 19158 |
gcc_checking_assert (fndecl && fndecl_built_in_p (fndecl, BUILT_IN_MD)); |
| 19159 |
int n_args = gimple_call_num_args (stmt); |
| 19160 |
enum ix86_builtins fn_code |
| 19161 |
= (enum ix86_builtins) DECL_MD_FUNCTION_CODE (fndecl); |
| 19162 |
tree decl = NULL_TREE; |
| 19163 |
tree arg0, arg1, arg2; |
| 19164 |
enum rtx_code rcode; |
| 19165 |
enum tree_code tcode; |
| 19166 |
unsigned HOST_WIDE_INT count; |
| 19167 |
bool is_vshift; |
| 19168 |
unsigned HOST_WIDE_INT elems; |
| 19169 |
location_t loc; |
| 19170 |
|
| 19171 |
/* Don't fold when there's isa mismatch. */ |
| 19172 |
if (!ix86_check_builtin_isa_match (fn_code, NULL, NULL)) |
| 19173 |
return false; |
| 19174 |
|
| 19175 |
switch (fn_code) |
| 19176 |
{ |
| 19177 |
case IX86_BUILTIN_TZCNT32: |
| 19178 |
decl = builtin_decl_implicit (BUILT_IN_CTZ); |
| 19179 |
goto fold_tzcnt_lzcnt; |
| 19180 |
|
| 19181 |
case IX86_BUILTIN_TZCNT64: |
| 19182 |
decl = builtin_decl_implicit (BUILT_IN_CTZLL); |
| 19183 |
goto fold_tzcnt_lzcnt; |
| 19184 |
|
| 19185 |
case IX86_BUILTIN_LZCNT32: |
| 19186 |
decl = builtin_decl_implicit (BUILT_IN_CLZ); |
| 19187 |
goto fold_tzcnt_lzcnt; |
| 19188 |
|
| 19189 |
case IX86_BUILTIN_LZCNT64: |
| 19190 |
decl = builtin_decl_implicit (BUILT_IN_CLZLL); |
| 19191 |
goto fold_tzcnt_lzcnt; |
| 19192 |
|
| 19193 |
fold_tzcnt_lzcnt: |
| 19194 |
gcc_assert (n_args == 1); |
| 19195 |
arg0 = gimple_call_arg (stmt, 0); |
| 19196 |
if (TREE_CODE (arg0) == SSA_NAME && decl && gimple_call_lhs (stmt)) |
| 19197 |
{ |
| 19198 |
int prec = TYPE_PRECISION (TREE_TYPE (arg0)); |
| 19199 |
/* If arg0 is provably non-zero, optimize into generic |
| 19200 |
__builtin_c[tl]z{,ll} function the middle-end handles |
| 19201 |
better. */ |
| 19202 |
if (!expr_not_equal_to (arg0, wi::zero (prec))) |
| 19203 |
return false; |
| 19204 |
|
| 19205 |
loc = gimple_location (stmt); |
| 19206 |
g = gimple_build_call (decl, 1, arg0); |
| 19207 |
gimple_set_location (g, loc); |
| 19208 |
tree lhs = make_ssa_name (integer_type_node); |
| 19209 |
gimple_call_set_lhs (g, lhs); |
| 19210 |
gsi_insert_before (gsi, g, GSI_SAME_STMT); |
| 19211 |
g = gimple_build_assign (gimple_call_lhs (stmt), NOP_EXPR, lhs); |
| 19212 |
gimple_set_location (g, loc); |
| 19213 |
gsi_replace (gsi, g, false); |
| 19214 |
return true; |
| 19215 |
} |
| 19216 |
break; |
| 19217 |
|
| 19218 |
case IX86_BUILTIN_BZHI32: |
| 19219 |
case IX86_BUILTIN_BZHI64: |
| 19220 |
gcc_assert (n_args == 2); |
| 19221 |
arg1 = gimple_call_arg (stmt, 1); |
| 19222 |
if (tree_fits_uhwi_p (arg1) && gimple_call_lhs (stmt)) |
| 19223 |
{ |
| 19224 |
unsigned int idx = tree_to_uhwi (arg1) & 0xff; |
| 19225 |
arg0 = gimple_call_arg (stmt, 0); |
| 19226 |
if (idx < TYPE_PRECISION (TREE_TYPE (arg0))) |
| 19227 |
break; |
| 19228 |
loc = gimple_location (stmt); |
| 19229 |
g = gimple_build_assign (gimple_call_lhs (stmt), arg0); |
| 19230 |
gimple_set_location (g, loc); |
| 19231 |
gsi_replace (gsi, g, false); |
| 19232 |
return true; |
| 19233 |
} |
| 19234 |
break; |
| 19235 |
|
| 19236 |
case IX86_BUILTIN_PDEP32: |
| 19237 |
case IX86_BUILTIN_PDEP64: |
| 19238 |
case IX86_BUILTIN_PEXT32: |
| 19239 |
case IX86_BUILTIN_PEXT64: |
| 19240 |
gcc_assert (n_args == 2); |
| 19241 |
arg1 = gimple_call_arg (stmt, 1); |
| 19242 |
if (integer_all_onesp (arg1) && gimple_call_lhs (stmt)) |
| 19243 |
{ |
| 19244 |
loc = gimple_location (stmt); |
| 19245 |
arg0 = gimple_call_arg (stmt, 0); |
| 19246 |
g = gimple_build_assign (gimple_call_lhs (stmt), arg0); |
| 19247 |
gimple_set_location (g, loc); |
| 19248 |
gsi_replace (gsi, g, false); |
| 19249 |
return true; |
| 19250 |
} |
| 19251 |
break; |
| 19252 |
|
| 19253 |
case IX86_BUILTIN_PBLENDVB256: |
| 19254 |
case IX86_BUILTIN_BLENDVPS256: |
| 19255 |
case IX86_BUILTIN_BLENDVPD256: |
| 19256 |
/* pcmpeqb/d/q is under avx2, w/o avx2, it's veclower |
| 19257 |
to scalar operations and not combined back. */ |
| 19258 |
if (!TARGET_AVX2) |
| 19259 |
break; |
| 19260 |
|
| 19261 |
/* FALLTHRU. */ |
| 19262 |
case IX86_BUILTIN_BLENDVPD: |
| 19263 |
/* blendvpd is under sse4.1 but pcmpgtq is under sse4.2, |
| 19264 |
w/o sse4.2, it's veclowered to scalar operations and |
| 19265 |
not combined back. */ |
| 19266 |
if (!TARGET_SSE4_2) |
| 19267 |
break; |
| 19268 |
/* FALLTHRU. */ |
| 19269 |
case IX86_BUILTIN_PBLENDVB128: |
| 19270 |
case IX86_BUILTIN_BLENDVPS: |
| 19271 |
gcc_assert (n_args == 3); |
| 19272 |
arg0 = gimple_call_arg (stmt, 0); |
| 19273 |
arg1 = gimple_call_arg (stmt, 1); |
| 19274 |
arg2 = gimple_call_arg (stmt, 2); |
| 19275 |
if (gimple_call_lhs (stmt)) |
| 19276 |
{ |
| 19277 |
loc = gimple_location (stmt); |
| 19278 |
tree type = TREE_TYPE (arg2); |
| 19279 |
if (VECTOR_FLOAT_TYPE_P (type)) |
| 19280 |
{ |
| 19281 |
tree itype = GET_MODE_INNER (TYPE_MODE (type)) == E_SFmode |
| 19282 |
? intSI_type_node : intDI_type_node; |
| 19283 |
type = get_same_sized_vectype (itype, type); |
| 19284 |
} |
| 19285 |
else |
| 19286 |
type = signed_type_for (type); |
| 19287 |
arg2 = gimple_build (&stmts, VIEW_CONVERT_EXPR, type, arg2); |
| 19288 |
tree zero_vec = build_zero_cst (type); |
| 19289 |
tree cmp_type = truth_type_for (type); |
| 19290 |
tree cmp = gimple_build (&stmts, LT_EXPR, cmp_type, arg2, zero_vec); |
| 19291 |
gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT); |
| 19292 |
g = gimple_build_assign (gimple_call_lhs (stmt), |
| 19293 |
VEC_COND_EXPR, cmp, |
| 19294 |
arg1, arg0); |
| 19295 |
gimple_set_location (g, loc); |
| 19296 |
gsi_replace (gsi, g, false); |
| 19297 |
} |
| 19298 |
else |
| 19299 |
gsi_replace (gsi, gimple_build_nop (), false); |
| 19300 |
return true; |
| 19301 |
|
| 19302 |
|
| 19303 |
case IX86_BUILTIN_PCMPEQB128: |
| 19304 |
case IX86_BUILTIN_PCMPEQW128: |
| 19305 |
case IX86_BUILTIN_PCMPEQD128: |
| 19306 |
case IX86_BUILTIN_PCMPEQQ: |
| 19307 |
case IX86_BUILTIN_PCMPEQB256: |
| 19308 |
case IX86_BUILTIN_PCMPEQW256: |
| 19309 |
case IX86_BUILTIN_PCMPEQD256: |
| 19310 |
case IX86_BUILTIN_PCMPEQQ256: |
| 19311 |
tcode = EQ_EXPR; |
| 19312 |
goto do_cmp; |
| 19313 |
|
| 19314 |
case IX86_BUILTIN_PCMPGTB128: |
| 19315 |
case IX86_BUILTIN_PCMPGTW128: |
| 19316 |
case IX86_BUILTIN_PCMPGTD128: |
| 19317 |
case IX86_BUILTIN_PCMPGTQ: |
| 19318 |
case IX86_BUILTIN_PCMPGTB256: |
| 19319 |
case IX86_BUILTIN_PCMPGTW256: |
| 19320 |
case IX86_BUILTIN_PCMPGTD256: |
| 19321 |
case IX86_BUILTIN_PCMPGTQ256: |
| 19322 |
tcode = GT_EXPR; |
| 19323 |
|
| 19324 |
do_cmp: |
| 19325 |
gcc_assert (n_args == 2); |
| 19326 |
arg0 = gimple_call_arg (stmt, 0); |
| 19327 |
arg1 = gimple_call_arg (stmt, 1); |
| 19328 |
if (gimple_call_lhs (stmt)) |
| 19329 |
{ |
| 19330 |
loc = gimple_location (stmt); |
| 19331 |
tree type = TREE_TYPE (arg0); |
| 19332 |
tree zero_vec = build_zero_cst (type); |
| 19333 |
tree minus_one_vec = build_minus_one_cst (type); |
| 19334 |
tree cmp_type = truth_type_for (type); |
| 19335 |
tree cmp = gimple_build (&stmts, tcode, cmp_type, arg0, arg1); |
| 19336 |
gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT); |
| 19337 |
g = gimple_build_assign (gimple_call_lhs (stmt), |
| 19338 |
VEC_COND_EXPR, cmp, |
| 19339 |
minus_one_vec, zero_vec); |
| 19340 |
gimple_set_location (g, loc); |
| 19341 |
gsi_replace (gsi, g, false); |
| 19342 |
} |
| 19343 |
else |
| 19344 |
gsi_replace (gsi, gimple_build_nop (), false); |
| 19345 |
return true; |
| 19346 |
|
| 19347 |
case IX86_BUILTIN_PSLLD: |
| 19348 |
case IX86_BUILTIN_PSLLD128: |
| 19349 |
case IX86_BUILTIN_PSLLD128_MASK: |
| 19350 |
case IX86_BUILTIN_PSLLD256: |
| 19351 |
case IX86_BUILTIN_PSLLD256_MASK: |
| 19352 |
case IX86_BUILTIN_PSLLD512: |
| 19353 |
case IX86_BUILTIN_PSLLDI: |
| 19354 |
case IX86_BUILTIN_PSLLDI128: |
| 19355 |
case IX86_BUILTIN_PSLLDI128_MASK: |
| 19356 |
case IX86_BUILTIN_PSLLDI256: |
| 19357 |
case IX86_BUILTIN_PSLLDI256_MASK: |
| 19358 |
case IX86_BUILTIN_PSLLDI512: |
| 19359 |
case IX86_BUILTIN_PSLLQ: |
| 19360 |
case IX86_BUILTIN_PSLLQ128: |
| 19361 |
case IX86_BUILTIN_PSLLQ128_MASK: |
| 19362 |
case IX86_BUILTIN_PSLLQ256: |
| 19363 |
case IX86_BUILTIN_PSLLQ256_MASK: |
| 19364 |
case IX86_BUILTIN_PSLLQ512: |
| 19365 |
case IX86_BUILTIN_PSLLQI: |
| 19366 |
case IX86_BUILTIN_PSLLQI128: |
| 19367 |
case IX86_BUILTIN_PSLLQI128_MASK: |
| 19368 |
case IX86_BUILTIN_PSLLQI256: |
| 19369 |
case IX86_BUILTIN_PSLLQI256_MASK: |
| 19370 |
case IX86_BUILTIN_PSLLQI512: |
| 19371 |
case IX86_BUILTIN_PSLLW: |
| 19372 |
case IX86_BUILTIN_PSLLW128: |
| 19373 |
case IX86_BUILTIN_PSLLW128_MASK: |
| 19374 |
case IX86_BUILTIN_PSLLW256: |
| 19375 |
case IX86_BUILTIN_PSLLW256_MASK: |
| 19376 |
case IX86_BUILTIN_PSLLW512_MASK: |
| 19377 |
case IX86_BUILTIN_PSLLWI: |
| 19378 |
case IX86_BUILTIN_PSLLWI128: |
| 19379 |
case IX86_BUILTIN_PSLLWI128_MASK: |
| 19380 |
case IX86_BUILTIN_PSLLWI256: |
| 19381 |
case IX86_BUILTIN_PSLLWI256_MASK: |
| 19382 |
case IX86_BUILTIN_PSLLWI512_MASK: |
| 19383 |
rcode = ASHIFT; |
| 19384 |
is_vshift = false; |
| 19385 |
goto do_shift; |
| 19386 |
case IX86_BUILTIN_PSRAD: |
| 19387 |
case IX86_BUILTIN_PSRAD128: |
| 19388 |
case IX86_BUILTIN_PSRAD128_MASK: |
| 19389 |
case IX86_BUILTIN_PSRAD256: |
| 19390 |
case IX86_BUILTIN_PSRAD256_MASK: |
| 19391 |
case IX86_BUILTIN_PSRAD512: |
| 19392 |
case IX86_BUILTIN_PSRADI: |
| 19393 |
case IX86_BUILTIN_PSRADI128: |
| 19394 |
case IX86_BUILTIN_PSRADI128_MASK: |
| 19395 |
case IX86_BUILTIN_PSRADI256: |
| 19396 |
case IX86_BUILTIN_PSRADI256_MASK: |
| 19397 |
case IX86_BUILTIN_PSRADI512: |
| 19398 |
case IX86_BUILTIN_PSRAQ128_MASK: |
| 19399 |
case IX86_BUILTIN_PSRAQ256_MASK: |
| 19400 |
case IX86_BUILTIN_PSRAQ512: |
| 19401 |
case IX86_BUILTIN_PSRAQI128_MASK: |
| 19402 |
case IX86_BUILTIN_PSRAQI256_MASK: |
| 19403 |
case IX86_BUILTIN_PSRAQI512: |
| 19404 |
case IX86_BUILTIN_PSRAW: |
| 19405 |
case IX86_BUILTIN_PSRAW128: |
| 19406 |
case IX86_BUILTIN_PSRAW128_MASK: |
| 19407 |
case IX86_BUILTIN_PSRAW256: |
| 19408 |
case IX86_BUILTIN_PSRAW256_MASK: |
| 19409 |
case IX86_BUILTIN_PSRAW512: |
| 19410 |
case IX86_BUILTIN_PSRAWI: |
| 19411 |
case IX86_BUILTIN_PSRAWI128: |
| 19412 |
case IX86_BUILTIN_PSRAWI128_MASK: |
| 19413 |
case IX86_BUILTIN_PSRAWI256: |
| 19414 |
case IX86_BUILTIN_PSRAWI256_MASK: |
| 19415 |
case IX86_BUILTIN_PSRAWI512: |
| 19416 |
rcode = ASHIFTRT; |
| 19417 |
is_vshift = false; |
| 19418 |
goto do_shift; |
| 19419 |
case IX86_BUILTIN_PSRLD: |
| 19420 |
case IX86_BUILTIN_PSRLD128: |
| 19421 |
case IX86_BUILTIN_PSRLD128_MASK: |
| 19422 |
case IX86_BUILTIN_PSRLD256: |
| 19423 |
case IX86_BUILTIN_PSRLD256_MASK: |
| 19424 |
case IX86_BUILTIN_PSRLD512: |
| 19425 |
case IX86_BUILTIN_PSRLDI: |
| 19426 |
case IX86_BUILTIN_PSRLDI128: |
| 19427 |
case IX86_BUILTIN_PSRLDI128_MASK: |
| 19428 |
case IX86_BUILTIN_PSRLDI256: |
| 19429 |
case IX86_BUILTIN_PSRLDI256_MASK: |
| 19430 |
case IX86_BUILTIN_PSRLDI512: |
| 19431 |
case IX86_BUILTIN_PSRLQ: |
| 19432 |
case IX86_BUILTIN_PSRLQ128: |
| 19433 |
case IX86_BUILTIN_PSRLQ128_MASK: |
| 19434 |
case IX86_BUILTIN_PSRLQ256: |
| 19435 |
case IX86_BUILTIN_PSRLQ256_MASK: |
| 19436 |
case IX86_BUILTIN_PSRLQ512: |
| 19437 |
case IX86_BUILTIN_PSRLQI: |
| 19438 |
case IX86_BUILTIN_PSRLQI128: |
| 19439 |
case IX86_BUILTIN_PSRLQI128_MASK: |
| 19440 |
case IX86_BUILTIN_PSRLQI256: |
| 19441 |
case IX86_BUILTIN_PSRLQI256_MASK: |
| 19442 |
case IX86_BUILTIN_PSRLQI512: |
| 19443 |
case IX86_BUILTIN_PSRLW: |
| 19444 |
case IX86_BUILTIN_PSRLW128: |
| 19445 |
case IX86_BUILTIN_PSRLW128_MASK: |
| 19446 |
case IX86_BUILTIN_PSRLW256: |
| 19447 |
case IX86_BUILTIN_PSRLW256_MASK: |
| 19448 |
case IX86_BUILTIN_PSRLW512: |
| 19449 |
case IX86_BUILTIN_PSRLWI: |
| 19450 |
case IX86_BUILTIN_PSRLWI128: |
| 19451 |
case IX86_BUILTIN_PSRLWI128_MASK: |
| 19452 |
case IX86_BUILTIN_PSRLWI256: |
| 19453 |
case IX86_BUILTIN_PSRLWI256_MASK: |
| 19454 |
case IX86_BUILTIN_PSRLWI512: |
| 19455 |
rcode = LSHIFTRT; |
| 19456 |
is_vshift = false; |
| 19457 |
goto do_shift; |
| 19458 |
case IX86_BUILTIN_PSLLVV16HI: |
| 19459 |
case IX86_BUILTIN_PSLLVV16SI: |
| 19460 |
case IX86_BUILTIN_PSLLVV2DI: |
| 19461 |
case IX86_BUILTIN_PSLLVV2DI_MASK: |
| 19462 |
case IX86_BUILTIN_PSLLVV32HI: |
| 19463 |
case IX86_BUILTIN_PSLLVV4DI: |
| 19464 |
case IX86_BUILTIN_PSLLVV4DI_MASK: |
| 19465 |
case IX86_BUILTIN_PSLLVV4SI: |
| 19466 |
case IX86_BUILTIN_PSLLVV4SI_MASK: |
| 19467 |
case IX86_BUILTIN_PSLLVV8DI: |
| 19468 |
case IX86_BUILTIN_PSLLVV8HI: |
| 19469 |
case IX86_BUILTIN_PSLLVV8SI: |
| 19470 |
case IX86_BUILTIN_PSLLVV8SI_MASK: |
| 19471 |
rcode = ASHIFT; |
| 19472 |
is_vshift = true; |
| 19473 |
goto do_shift; |
| 19474 |
case IX86_BUILTIN_PSRAVQ128: |
| 19475 |
case IX86_BUILTIN_PSRAVQ256: |
| 19476 |
case IX86_BUILTIN_PSRAVV16HI: |
| 19477 |
case IX86_BUILTIN_PSRAVV16SI: |
| 19478 |
case IX86_BUILTIN_PSRAVV32HI: |
| 19479 |
case IX86_BUILTIN_PSRAVV4SI: |
| 19480 |
case IX86_BUILTIN_PSRAVV4SI_MASK: |
| 19481 |
case IX86_BUILTIN_PSRAVV8DI: |
| 19482 |
case IX86_BUILTIN_PSRAVV8HI: |
| 19483 |
case IX86_BUILTIN_PSRAVV8SI: |
| 19484 |
case IX86_BUILTIN_PSRAVV8SI_MASK: |
| 19485 |
rcode = ASHIFTRT; |
| 19486 |
is_vshift = true; |
| 19487 |
goto do_shift; |
| 19488 |
case IX86_BUILTIN_PSRLVV16HI: |
| 19489 |
case IX86_BUILTIN_PSRLVV16SI: |
| 19490 |
case IX86_BUILTIN_PSRLVV2DI: |
| 19491 |
case IX86_BUILTIN_PSRLVV2DI_MASK: |
| 19492 |
case IX86_BUILTIN_PSRLVV32HI: |
| 19493 |
case IX86_BUILTIN_PSRLVV4DI: |
| 19494 |
case IX86_BUILTIN_PSRLVV4DI_MASK: |
| 19495 |
case IX86_BUILTIN_PSRLVV4SI: |
| 19496 |
case IX86_BUILTIN_PSRLVV4SI_MASK: |
| 19497 |
case IX86_BUILTIN_PSRLVV8DI: |
| 19498 |
case IX86_BUILTIN_PSRLVV8HI: |
| 19499 |
case IX86_BUILTIN_PSRLVV8SI: |
| 19500 |
case IX86_BUILTIN_PSRLVV8SI_MASK: |
| 19501 |
rcode = LSHIFTRT; |
| 19502 |
is_vshift = true; |
| 19503 |
goto do_shift; |
| 19504 |
|
| 19505 |
do_shift: |
| 19506 |
gcc_assert (n_args >= 2); |
| 19507 |
if (!gimple_call_lhs (stmt)) |
| 19508 |
{ |
| 19509 |
gsi_replace (gsi, gimple_build_nop (), false); |
| 19510 |
return true; |
| 19511 |
} |
| 19512 |
arg0 = gimple_call_arg (stmt, 0); |
| 19513 |
arg1 = gimple_call_arg (stmt, 1); |
| 19514 |
elems = TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0)); |
| 19515 |
/* For masked shift, only optimize if the mask is all ones. */ |
| 19516 |
if (n_args > 2 |
| 19517 |
&& !ix86_masked_all_ones (elems, gimple_call_arg (stmt, n_args - 1))) |
| 19518 |
break; |
| 19519 |
if (is_vshift) |
| 19520 |
{ |
| 19521 |
if (TREE_CODE (arg1) != VECTOR_CST) |
| 19522 |
break; |
| 19523 |
count = TYPE_PRECISION (TREE_TYPE (TREE_TYPE (arg0))); |
| 19524 |
if (integer_zerop (arg1)) |
| 19525 |
count = 0; |
| 19526 |
else if (rcode == ASHIFTRT) |
| 19527 |
break; |
| 19528 |
else |
| 19529 |
for (unsigned int i = 0; i < VECTOR_CST_NELTS (arg1); ++i) |
| 19530 |
{ |
| 19531 |
tree elt = VECTOR_CST_ELT (arg1, i); |
| 19532 |
if (!wi::neg_p (wi::to_wide (elt)) |
| 19533 |
&& wi::to_widest (elt) < count) |
| 19534 |
return false; |
| 19535 |
} |
| 19536 |
} |
| 19537 |
else |
| 19538 |
{ |
| 19539 |
arg1 = ix86_vector_shift_count (arg1); |
| 19540 |
if (!arg1) |
| 19541 |
break; |
| 19542 |
count = tree_to_uhwi (arg1); |
| 19543 |
} |
| 19544 |
if (count == 0) |
| 19545 |
{ |
| 19546 |
/* Just return the first argument for shift by 0. */ |
| 19547 |
loc = gimple_location (stmt); |
| 19548 |
g = gimple_build_assign (gimple_call_lhs (stmt), arg0); |
| 19549 |
gimple_set_location (g, loc); |
| 19550 |
gsi_replace (gsi, g, false); |
| 19551 |
return true; |
| 19552 |
} |
| 19553 |
if (rcode != ASHIFTRT |
| 19554 |
&& count >= TYPE_PRECISION (TREE_TYPE (TREE_TYPE (arg0)))) |
| 19555 |
{ |
| 19556 |
/* For shift counts equal or greater than precision, except for |
| 19557 |
arithmetic right shift the result is zero. */ |
| 19558 |
loc = gimple_location (stmt); |
| 19559 |
g = gimple_build_assign (gimple_call_lhs (stmt), |
| 19560 |
build_zero_cst (TREE_TYPE (arg0))); |
| 19561 |
gimple_set_location (g, loc); |
| 19562 |
gsi_replace (gsi, g, false); |
| 19563 |
return true; |
| 19564 |
} |
| 19565 |
break; |
| 19566 |
|
| 19567 |
case IX86_BUILTIN_SHUFPD512: |
| 19568 |
case IX86_BUILTIN_SHUFPS512: |
| 19569 |
case IX86_BUILTIN_SHUFPD: |
| 19570 |
case IX86_BUILTIN_SHUFPD256: |
| 19571 |
case IX86_BUILTIN_SHUFPS: |
| 19572 |
case IX86_BUILTIN_SHUFPS256: |
| 19573 |
arg0 = gimple_call_arg (stmt, 0); |
| 19574 |
elems = TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0)); |
| 19575 |
/* This is masked shuffle. Only optimize if the mask is all ones. */ |
| 19576 |
if (n_args > 3 |
| 19577 |
&& !ix86_masked_all_ones (elems, |
| 19578 |
gimple_call_arg (stmt, n_args - 1))) |
| 19579 |
break; |
| 19580 |
arg2 = gimple_call_arg (stmt, 2); |
| 19581 |
if (TREE_CODE (arg2) == INTEGER_CST && gimple_call_lhs (stmt)) |
| 19582 |
{ |
| 19583 |
unsigned HOST_WIDE_INT shuffle_mask = TREE_INT_CST_LOW (arg2); |
| 19584 |
/* Check valid imm, refer to gcc.target/i386/testimm-10.c. */ |
| 19585 |
if (shuffle_mask > 255) |
| 19586 |
return false; |
| 19587 |
|
| 19588 |
machine_mode imode = GET_MODE_INNER (TYPE_MODE (TREE_TYPE (arg0))); |
| 19589 |
loc = gimple_location (stmt); |
| 19590 |
tree itype = (imode == E_DFmode |
| 19591 |
? long_long_integer_type_node : integer_type_node); |
| 19592 |
tree vtype = build_vector_type (itype, elems); |
| 19593 |
tree_vector_builder elts (vtype, elems, 1); |
| 19594 |
|
| 19595 |
|
| 19596 |
/* Transform integer shuffle_mask to vector perm_mask which |
| 19597 |
is used by vec_perm_expr, refer to shuflp[sd]256/512 in sse.md. */ |
| 19598 |
for (unsigned i = 0; i != elems; i++) |
| 19599 |
{ |
| 19600 |
unsigned sel_idx; |
| 19601 |
/* Imm[1:0](if VL > 128, then use Imm[3:2],Imm[5:4],Imm[7:6]) |
| 19602 |
provide 2 select constrols for each element of the |
| 19603 |
destination. */ |
| 19604 |
if (imode == E_DFmode) |
| 19605 |
sel_idx = (i & 1) * elems + (i & ~1) |
| 19606 |
+ ((shuffle_mask >> i) & 1); |
| 19607 |
else |
| 19608 |
{ |
| 19609 |
/* Imm[7:0](if VL > 128, also use Imm[7:0]) provide 4 select |
| 19610 |
controls for each element of the destination. */ |
| 19611 |
unsigned j = i % 4; |
| 19612 |
sel_idx = ((i >> 1) & 1) * elems + (i & ~3) |
| 19613 |
+ ((shuffle_mask >> 2 * j) & 3); |
| 19614 |
} |
| 19615 |
elts.quick_push (build_int_cst (itype, sel_idx)); |
| 19616 |
} |
| 19617 |
|
| 19618 |
tree perm_mask = elts.build (); |
| 19619 |
arg1 = gimple_call_arg (stmt, 1); |
| 19620 |
g = gimple_build_assign (gimple_call_lhs (stmt), |
| 19621 |
VEC_PERM_EXPR, |
| 19622 |
arg0, arg1, perm_mask); |
| 19623 |
gimple_set_location (g, loc); |
| 19624 |
gsi_replace (gsi, g, false); |
| 19625 |
return true; |
| 19626 |
} |
| 19627 |
// Do not error yet, the constant could be propagated later? |
| 19628 |
break; |
| 19629 |
|
| 19630 |
case IX86_BUILTIN_PABSB: |
| 19631 |
case IX86_BUILTIN_PABSW: |
| 19632 |
case IX86_BUILTIN_PABSD: |
| 19633 |
/* 64-bit vector abs<mode>2 is only supported under TARGET_MMX_WITH_SSE. */ |
| 19634 |
if (!TARGET_MMX_WITH_SSE) |
| 19635 |
break; |
| 19636 |
/* FALLTHRU. */ |
| 19637 |
case IX86_BUILTIN_PABSB128: |
| 19638 |
case IX86_BUILTIN_PABSB256: |
| 19639 |
case IX86_BUILTIN_PABSB512: |
| 19640 |
case IX86_BUILTIN_PABSW128: |
| 19641 |
case IX86_BUILTIN_PABSW256: |
| 19642 |
case IX86_BUILTIN_PABSW512: |
| 19643 |
case IX86_BUILTIN_PABSD128: |
| 19644 |
case IX86_BUILTIN_PABSD256: |
| 19645 |
case IX86_BUILTIN_PABSD512: |
| 19646 |
case IX86_BUILTIN_PABSQ128: |
| 19647 |
case IX86_BUILTIN_PABSQ256: |
| 19648 |
case IX86_BUILTIN_PABSQ512: |
| 19649 |
case IX86_BUILTIN_PABSB128_MASK: |
| 19650 |
case IX86_BUILTIN_PABSB256_MASK: |
| 19651 |
case IX86_BUILTIN_PABSW128_MASK: |
| 19652 |
case IX86_BUILTIN_PABSW256_MASK: |
| 19653 |
case IX86_BUILTIN_PABSD128_MASK: |
| 19654 |
case IX86_BUILTIN_PABSD256_MASK: |
| 19655 |
gcc_assert (n_args >= 1); |
| 19656 |
if (!gimple_call_lhs (stmt)) |
| 19657 |
{ |
| 19658 |
gsi_replace (gsi, gimple_build_nop (), false); |
| 19659 |
return true; |
| 19660 |
} |
| 19661 |
arg0 = gimple_call_arg (stmt, 0); |
| 19662 |
elems = TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0)); |
| 19663 |
/* For masked ABS, only optimize if the mask is all ones. */ |
| 19664 |
if (n_args > 1 |
| 19665 |
&& !ix86_masked_all_ones (elems, gimple_call_arg (stmt, n_args - 1))) |
| 19666 |
break; |
| 19667 |
{ |
| 19668 |
tree utype, ures, vce; |
| 19669 |
utype = unsigned_type_for (TREE_TYPE (arg0)); |
| 19670 |
/* PABSB/W/D/Q store the unsigned result in dst, use ABSU_EXPR |
| 19671 |
instead of ABS_EXPR to hanlde overflow case(TYPE_MIN). */ |
| 19672 |
ures = gimple_build (&stmts, ABSU_EXPR, utype, arg0); |
| 19673 |
gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT); |
| 19674 |
loc = gimple_location (stmt); |
| 19675 |
vce = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (arg0), ures); |
| 19676 |
g = gimple_build_assign (gimple_call_lhs (stmt), |
| 19677 |
VIEW_CONVERT_EXPR, vce); |
| 19678 |
gsi_replace (gsi, g, false); |
| 19679 |
} |
| 19680 |
return true; |
| 19681 |
|
| 19682 |
case IX86_BUILTIN_MINPS: |
| 19683 |
case IX86_BUILTIN_MINPD: |
| 19684 |
case IX86_BUILTIN_MINPS256: |
| 19685 |
case IX86_BUILTIN_MINPD256: |
| 19686 |
case IX86_BUILTIN_MINPS512: |
| 19687 |
case IX86_BUILTIN_MINPD512: |
| 19688 |
case IX86_BUILTIN_MINPS128_MASK: |
| 19689 |
case IX86_BUILTIN_MINPD128_MASK: |
| 19690 |
case IX86_BUILTIN_MINPS256_MASK: |
| 19691 |
case IX86_BUILTIN_MINPD256_MASK: |
| 19692 |
case IX86_BUILTIN_MINPH128_MASK: |
| 19693 |
case IX86_BUILTIN_MINPH256_MASK: |
| 19694 |
case IX86_BUILTIN_MINPH512_MASK: |
| 19695 |
tcode = LT_EXPR; |
| 19696 |
goto do_minmax; |
| 19697 |
|
| 19698 |
case IX86_BUILTIN_MAXPS: |
| 19699 |
case IX86_BUILTIN_MAXPD: |
| 19700 |
case IX86_BUILTIN_MAXPS256: |
| 19701 |
case IX86_BUILTIN_MAXPD256: |
| 19702 |
case IX86_BUILTIN_MAXPS512: |
| 19703 |
case IX86_BUILTIN_MAXPD512: |
| 19704 |
case IX86_BUILTIN_MAXPS128_MASK: |
| 19705 |
case IX86_BUILTIN_MAXPD128_MASK: |
| 19706 |
case IX86_BUILTIN_MAXPS256_MASK: |
| 19707 |
case IX86_BUILTIN_MAXPD256_MASK: |
| 19708 |
case IX86_BUILTIN_MAXPH128_MASK: |
| 19709 |
case IX86_BUILTIN_MAXPH256_MASK: |
| 19710 |
case IX86_BUILTIN_MAXPH512_MASK: |
| 19711 |
tcode = GT_EXPR; |
| 19712 |
do_minmax: |
| 19713 |
gcc_assert (n_args >= 2); |
| 19714 |
/* Without SSE4.1 we often aren't able to pattern match it back to the |
| 19715 |
desired instruction. */ |
| 19716 |
if (!gimple_call_lhs (stmt) || !optimize || !TARGET_SSE4_1) |
| 19717 |
break; |
| 19718 |
arg0 = gimple_call_arg (stmt, 0); |
| 19719 |
arg1 = gimple_call_arg (stmt, 1); |
| 19720 |
elems = TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0)); |
| 19721 |
/* For masked minmax, only optimize if the mask is all ones. */ |
| 19722 |
if (n_args > 2 |
| 19723 |
&& !ix86_masked_all_ones (elems, gimple_call_arg (stmt, 3))) |
| 19724 |
break; |
| 19725 |
if (n_args >= 5) |
| 19726 |
{ |
| 19727 |
tree arg4 = gimple_call_arg (stmt, 4); |
| 19728 |
if (!tree_fits_uhwi_p (arg4)) |
| 19729 |
break; |
| 19730 |
if (tree_to_uhwi (arg4) == 4) |
| 19731 |
/* Ok. */; |
| 19732 |
else if (tree_to_uhwi (arg4) != 8) |
| 19733 |
/* Invalid round argument. */ |
| 19734 |
break; |
| 19735 |
else if (HONOR_NANS (arg0)) |
| 19736 |
/* Lowering to comparison would raise exceptions which |
| 19737 |
shouldn't be raised. */ |
| 19738 |
break; |
| 19739 |
} |
| 19740 |
{ |
| 19741 |
tree type = truth_type_for (TREE_TYPE (arg0)); |
| 19742 |
tree cmpres = gimple_build (&stmts, tcode, type, arg0, arg1); |
| 19743 |
gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT); |
| 19744 |
g = gimple_build_assign (gimple_call_lhs (stmt), |
| 19745 |
VEC_COND_EXPR, cmpres, arg0, arg1); |
| 19746 |
gsi_replace (gsi, g, false); |
| 19747 |
} |
| 19748 |
return true; |
| 19749 |
|
| 19750 |
default: |
| 19751 |
break; |
| 19752 |
} |
| 19753 |
|
| 19754 |
return false; |
| 19755 |
} |
| 19756 |
|
| 19757 |
/* Handler for an SVML-style interface to |
| 19758 |
a library with vectorized intrinsics. */ |
| 19759 |
|
| 19760 |
tree |
| 19761 |
ix86_veclibabi_svml (combined_fn fn, tree type_out, tree type_in) |
| 19762 |
{ |
| 19763 |
char name[20]; |
| 19764 |
tree fntype, new_fndecl, args; |
| 19765 |
unsigned arity; |
| 19766 |
const char *bname; |
| 19767 |
machine_mode el_mode, in_mode; |
| 19768 |
int n, in_n; |
| 19769 |
|
| 19770 |
/* The SVML is suitable for unsafe math only. */ |
| 19771 |
if (!flag_unsafe_math_optimizations) |
| 19772 |
return NULL_TREE; |
| 19773 |
|
| 19774 |
el_mode = TYPE_MODE (TREE_TYPE (type_out)); |
| 19775 |
n = TYPE_VECTOR_SUBPARTS (type_out); |
| 19776 |
in_mode = TYPE_MODE (TREE_TYPE (type_in)); |
| 19777 |
in_n = TYPE_VECTOR_SUBPARTS (type_in); |
| 19778 |
if (el_mode != in_mode |
| 19779 |
|| n != in_n) |
| 19780 |
return NULL_TREE; |
| 19781 |
|
| 19782 |
switch (fn) |
| 19783 |
{ |
| 19784 |
CASE_CFN_EXP: |
| 19785 |
CASE_CFN_LOG: |
| 19786 |
CASE_CFN_LOG10: |
| 19787 |
CASE_CFN_POW: |
| 19788 |
CASE_CFN_TANH: |
| 19789 |
CASE_CFN_TAN: |
| 19790 |
CASE_CFN_ATAN: |
| 19791 |
CASE_CFN_ATAN2: |
| 19792 |
CASE_CFN_ATANH: |
| 19793 |
CASE_CFN_CBRT: |
| 19794 |
CASE_CFN_SINH: |
| 19795 |
CASE_CFN_SIN: |
| 19796 |
CASE_CFN_ASINH: |
| 19797 |
CASE_CFN_ASIN: |
| 19798 |
CASE_CFN_COSH: |
| 19799 |
CASE_CFN_COS: |
| 19800 |
CASE_CFN_ACOSH: |
| 19801 |
CASE_CFN_ACOS: |
| 19802 |
if ((el_mode != DFmode || n != 2) |
| 19803 |
&& (el_mode != SFmode || n != 4)) |
| 19804 |
return NULL_TREE; |
| 19805 |
break; |
| 19806 |
|
| 19807 |
default: |
| 19808 |
return NULL_TREE; |
| 19809 |
} |
| 19810 |
|
| 19811 |
tree fndecl = mathfn_built_in (el_mode == DFmode |
| 19812 |
? double_type_node : float_type_node, fn); |
| 19813 |
bname = IDENTIFIER_POINTER (DECL_NAME (fndecl)); |
| 19814 |
|
| 19815 |
if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_LOGF) |
| 19816 |
strcpy (name, "vmlsLn4"); |
| 19817 |
else if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_LOG) |
| 19818 |
strcpy (name, "vmldLn2"); |
| 19819 |
else if (n == 4) |
| 19820 |
{ |
| 19821 |
sprintf (name, "vmls%s", bname+10); |
| 19822 |
name[strlen (name)-1] = '4'; |
| 19823 |
} |
| 19824 |
else |
| 19825 |
sprintf (name, "vmld%s2", bname+10); |
| 19826 |
|
| 19827 |
/* Convert to uppercase. */ |
| 19828 |
name[4] &= ~0x20; |
| 19829 |
|
| 19830 |
arity = 0; |
| 19831 |
for (args = DECL_ARGUMENTS (fndecl); args; args = TREE_CHAIN (args)) |
| 19832 |
arity++; |
| 19833 |
|
| 19834 |
if (arity == 1) |
| 19835 |
fntype = build_function_type_list (type_out, type_in, NULL); |
| 19836 |
else |
| 19837 |
fntype = build_function_type_list (type_out, type_in, type_in, NULL); |
| 19838 |
|
| 19839 |
/* Build a function declaration for the vectorized function. */ |
| 19840 |
new_fndecl = build_decl (BUILTINS_LOCATION, |
| 19841 |
FUNCTION_DECL, get_identifier (name), fntype); |
| 19842 |
TREE_PUBLIC (new_fndecl) = 1; |
| 19843 |
DECL_EXTERNAL (new_fndecl) = 1; |
| 19844 |
DECL_IS_NOVOPS (new_fndecl) = 1; |
| 19845 |
TREE_READONLY (new_fndecl) = 1; |
| 19846 |
|
| 19847 |
return new_fndecl; |
| 19848 |
} |
| 19849 |
|
| 19850 |
/* Handler for an ACML-style interface to |
| 19851 |
a library with vectorized intrinsics. */ |
| 19852 |
|
| 19853 |
tree |
| 19854 |
ix86_veclibabi_acml (combined_fn fn, tree type_out, tree type_in) |
| 19855 |
{ |
| 19856 |
char name[20] = "__vr.._"; |
| 19857 |
tree fntype, new_fndecl, args; |
| 19858 |
unsigned arity; |
| 19859 |
const char *bname; |
| 19860 |
machine_mode el_mode, in_mode; |
| 19861 |
int n, in_n; |
| 19862 |
|
| 19863 |
/* The ACML is 64bits only and suitable for unsafe math only as |
| 19864 |
it does not correctly support parts of IEEE with the required |
| 19865 |
precision such as denormals. */ |
| 19866 |
if (!TARGET_64BIT |
| 19867 |
|| !flag_unsafe_math_optimizations) |
| 19868 |
return NULL_TREE; |
| 19869 |
|
| 19870 |
el_mode = TYPE_MODE (TREE_TYPE (type_out)); |
| 19871 |
n = TYPE_VECTOR_SUBPARTS (type_out); |
| 19872 |
in_mode = TYPE_MODE (TREE_TYPE (type_in)); |
| 19873 |
in_n = TYPE_VECTOR_SUBPARTS (type_in); |
| 19874 |
if (el_mode != in_mode |
| 19875 |
|| n != in_n) |
| 19876 |
return NULL_TREE; |
| 19877 |
|
| 19878 |
switch (fn) |
| 19879 |
{ |
| 19880 |
CASE_CFN_SIN: |
| 19881 |
CASE_CFN_COS: |
| 19882 |
CASE_CFN_EXP: |
| 19883 |
CASE_CFN_LOG: |
| 19884 |
CASE_CFN_LOG2: |
| 19885 |
CASE_CFN_LOG10: |
| 19886 |
if (el_mode == DFmode && n == 2) |
| 19887 |
{ |
| 19888 |
name[4] = 'd'; |
| 19889 |
name[5] = '2'; |
| 19890 |
} |
| 19891 |
else if (el_mode == SFmode && n == 4) |
| 19892 |
{ |
| 19893 |
name[4] = 's'; |
| 19894 |
name[5] = '4'; |
| 19895 |
} |
| 19896 |
else |
| 19897 |
return NULL_TREE; |
| 19898 |
break; |
| 19899 |
|
| 19900 |
default: |
| 19901 |
return NULL_TREE; |
| 19902 |
} |
| 19903 |
|
| 19904 |
tree fndecl = mathfn_built_in (el_mode == DFmode |
| 19905 |
? double_type_node : float_type_node, fn); |
| 19906 |
bname = IDENTIFIER_POINTER (DECL_NAME (fndecl)); |
| 19907 |
sprintf (name + 7, "%s", bname+10); |
| 19908 |
|
| 19909 |
arity = 0; |
| 19910 |
for (args = DECL_ARGUMENTS (fndecl); args; args = TREE_CHAIN (args)) |
| 19911 |
arity++; |
| 19912 |
|
| 19913 |
if (arity == 1) |
| 19914 |
fntype = build_function_type_list (type_out, type_in, NULL); |
| 19915 |
else |
| 19916 |
fntype = build_function_type_list (type_out, type_in, type_in, NULL); |
| 19917 |
|
| 19918 |
/* Build a function declaration for the vectorized function. */ |
| 19919 |
new_fndecl = build_decl (BUILTINS_LOCATION, |
| 19920 |
FUNCTION_DECL, get_identifier (name), fntype); |
| 19921 |
TREE_PUBLIC (new_fndecl) = 1; |
| 19922 |
DECL_EXTERNAL (new_fndecl) = 1; |
| 19923 |
DECL_IS_NOVOPS (new_fndecl) = 1; |
| 19924 |
TREE_READONLY (new_fndecl) = 1; |
| 19925 |
|
| 19926 |
return new_fndecl; |
| 19927 |
} |
| 19928 |
|
| 19929 |
/* Handler for an AOCL-LibM-style interface to |
| 19930 |
a library with vectorized intrinsics. */ |
| 19931 |
|
| 19932 |
tree |
| 19933 |
ix86_veclibabi_aocl (combined_fn fn, tree type_out, tree type_in) |
| 19934 |
{ |
| 19935 |
char name[20] = "amd_vr"; |
| 19936 |
int name_len = 6; |
| 19937 |
tree fntype, new_fndecl, args; |
| 19938 |
unsigned arity; |
| 19939 |
const char *bname; |
| 19940 |
machine_mode el_mode, in_mode; |
| 19941 |
int n, in_n; |
| 19942 |
|
| 19943 |
/* AOCL-LibM is 64bits only. It is also only suitable for unsafe math only |
| 19944 |
as it trades off some accuracy for increased performance. */ |
| 19945 |
if (!TARGET_64BIT |
| 19946 |
|| !flag_unsafe_math_optimizations) |
| 19947 |
return NULL_TREE; |
| 19948 |
|
| 19949 |
el_mode = TYPE_MODE (TREE_TYPE (type_out)); |
| 19950 |
n = TYPE_VECTOR_SUBPARTS (type_out); |
| 19951 |
in_mode = TYPE_MODE (TREE_TYPE (type_in)); |
| 19952 |
in_n = TYPE_VECTOR_SUBPARTS (type_in); |
| 19953 |
if (el_mode != in_mode |
| 19954 |
|| n != in_n) |
| 19955 |
return NULL_TREE; |
| 19956 |
|
| 19957 |
gcc_checking_assert (n > 0); |
| 19958 |
|
| 19959 |
/* Decide whether there exists a function for the combination of FN, the mode |
| 19960 |
and the vector width. Return early if it doesn't. */ |
| 19961 |
|
| 19962 |
if (el_mode != DFmode && el_mode != SFmode) |
| 19963 |
return NULL_TREE; |
| 19964 |
|
| 19965 |
/* Supported vector widths for given FN and single/double precision. Zeros |
| 19966 |
are used to fill out unused positions in the arrays. */ |
| 19967 |
static const int supported_n[][2][3] = { |
| 19968 |
/* Single prec. , Double prec. */ |
| 19969 |
{ { 16, 0, 0 }, { 2, 4, 8 } }, /* TAN. */ |
| 19970 |
{ { 4, 8, 16 }, { 2, 4, 8 } }, /* EXP. */ |
| 19971 |
{ { 4, 8, 16 }, { 2, 4, 8 } }, /* EXP2. */ |
| 19972 |
{ { 4, 8, 16 }, { 2, 4, 8 } }, /* LOG. */ |
| 19973 |
{ { 4, 8, 16 }, { 2, 4, 8 } }, /* LOG2. */ |
| 19974 |
{ { 4, 8, 16 }, { 2, 4, 8 } }, /* COS. */ |
| 19975 |
{ { 4, 8, 16 }, { 2, 4, 8 } }, /* SIN. */ |
| 19976 |
{ { 4, 8, 16 }, { 2, 4, 8 } }, /* POW. */ |
| 19977 |
{ { 4, 8, 16 }, { 2, 4, 8 } }, /* ERF. */ |
| 19978 |
{ { 4, 8, 16 }, { 2, 8, 0 } }, /* ATAN. */ |
| 19979 |
{ { 4, 8, 16 }, { 2, 0, 0 } }, /* LOG10. */ |
| 19980 |
{ { 4, 0, 0 }, { 2, 0, 0 } }, /* EXP10. */ |
| 19981 |
{ { 4, 0, 0 }, { 2, 0, 0 } }, /* LOG1P. */ |
| 19982 |
{ { 4, 8, 16 }, { 8, 0, 0 } }, /* ASIN. */ |
| 19983 |
{ { 4, 16, 0 }, { 0, 0, 0 } }, /* ACOS. */ |
| 19984 |
{ { 4, 8, 16 }, { 0, 0, 0 } }, /* TANH. */ |
| 19985 |
{ { 4, 0, 0 }, { 0, 0, 0 } }, /* EXPM1. */ |
| 19986 |
{ { 4, 8, 0 }, { 0, 0, 0 } }, /* COSH. */ |
| 19987 |
}; |
| 19988 |
|
| 19989 |
/* We cannot simply index the supported_n array with FN since multiple FNs |
| 19990 |
may correspond to a single operation (see the definitions of these |
| 19991 |
CASE_CFN_* macros). */ |
| 19992 |
int i; |
| 19993 |
switch (fn) |
| 19994 |
{ |
| 19995 |
CASE_CFN_TAN : i = 0; break; |
| 19996 |
CASE_CFN_EXP : i = 1; break; |
| 19997 |
CASE_CFN_EXP2 : i = 2; break; |
| 19998 |
CASE_CFN_LOG : i = 3; break; |
| 19999 |
CASE_CFN_LOG2 : i = 4; break; |
| 20000 |
CASE_CFN_COS : i = 5; break; |
| 20001 |
CASE_CFN_SIN : i = 6; break; |
| 20002 |
CASE_CFN_POW : i = 7; break; |
| 20003 |
CASE_CFN_ERF : i = 8; break; |
| 20004 |
CASE_CFN_ATAN : i = 9; break; |
| 20005 |
CASE_CFN_LOG10 : i = 10; break; |
| 20006 |
CASE_CFN_EXP10 : i = 11; break; |
| 20007 |
CASE_CFN_LOG1P : i = 12; break; |
| 20008 |
CASE_CFN_ASIN : i = 13; break; |
| 20009 |
CASE_CFN_ACOS : i = 14; break; |
| 20010 |
CASE_CFN_TANH : i = 15; break; |
| 20011 |
CASE_CFN_EXPM1 : i = 16; break; |
| 20012 |
CASE_CFN_COSH : i = 17; break; |
| 20013 |
default: return NULL_TREE; |
| 20014 |
} |
| 20015 |
|
| 20016 |
int j = el_mode == DFmode; |
| 20017 |
bool n_is_supported = false; |
| 20018 |
for (unsigned k = 0; k < 3; k++) |
| 20019 |
if (supported_n[i][j][k] == n) |
| 20020 |
{ |
| 20021 |
n_is_supported = true; |
| 20022 |
break; |
| 20023 |
} |
| 20024 |
if (!n_is_supported) |
| 20025 |
return NULL_TREE; |
| 20026 |
|
| 20027 |
/* Append the precision and the vector width to the function name we are |
| 20028 |
constructing. */ |
| 20029 |
name[name_len++] = el_mode == DFmode ? 'd' : 's'; |
| 20030 |
switch (n) |
| 20031 |
{ |
| 20032 |
case 2: |
| 20033 |
case 4: |
| 20034 |
case 8: |
| 20035 |
name[name_len++] = '0' + n; |
| 20036 |
break; |
| 20037 |
case 16: |
| 20038 |
name[name_len++] = '1'; |
| 20039 |
name[name_len++] = '6'; |
| 20040 |
break; |
| 20041 |
default: |
| 20042 |
gcc_unreachable (); |
| 20043 |
} |
| 20044 |
name[name_len++] = '_'; |
| 20045 |
|
| 20046 |
/* Append the operation name (steal it from the name of a builtin). */ |
| 20047 |
tree fndecl = mathfn_built_in (el_mode == DFmode |
| 20048 |
? double_type_node : float_type_node, fn); |
| 20049 |
bname = IDENTIFIER_POINTER (DECL_NAME (fndecl)); |
| 20050 |
sprintf (name + name_len, "%s", bname + 10); |
| 20051 |
|
| 20052 |
arity = 0; |
| 20053 |
for (args = DECL_ARGUMENTS (fndecl); args; args = TREE_CHAIN (args)) |
| 20054 |
arity++; |
| 20055 |
|
| 20056 |
if (arity == 1) |
| 20057 |
fntype = build_function_type_list (type_out, type_in, NULL); |
| 20058 |
else |
| 20059 |
fntype = build_function_type_list (type_out, type_in, type_in, NULL); |
| 20060 |
|
| 20061 |
/* Build a function declaration for the vectorized function. */ |
| 20062 |
new_fndecl = build_decl (BUILTINS_LOCATION, |
| 20063 |
FUNCTION_DECL, get_identifier (name), fntype); |
| 20064 |
TREE_PUBLIC (new_fndecl) = 1; |
| 20065 |
DECL_EXTERNAL (new_fndecl) = 1; |
| 20066 |
TREE_READONLY (new_fndecl) = 1; |
| 20067 |
|
| 20068 |
return new_fndecl; |
| 20069 |
} |
| 20070 |
|
| 20071 |
/* Returns a decl of a function that implements scatter store with |
| 20072 |
register type VECTYPE and index type INDEX_TYPE and SCALE. |
| 20073 |
Return NULL_TREE if it is not available. */ |
| 20074 |
|
| 20075 |
static tree |
| 20076 |
ix86_vectorize_builtin_scatter (const_tree vectype, |
| 20077 |
const_tree index_type, int scale) |
| 20078 |
{ |
| 20079 |
bool si; |
| 20080 |
enum ix86_builtins code; |
| 20081 |
const machine_mode mode = TYPE_MODE (TREE_TYPE (vectype)); |
| 20082 |
|
| 20083 |
if (!TARGET_AVX512F) |
| 20084 |
return NULL_TREE; |
| 20085 |
|
| 20086 |
if (!TARGET_EVEX512 && GET_MODE_SIZE (mode) == 64) |
| 20087 |
return NULL_TREE; |
| 20088 |
|
| 20089 |
if (known_eq (TYPE_VECTOR_SUBPARTS (vectype), 2u) |
| 20090 |
? !TARGET_USE_SCATTER_2PARTS |
| 20091 |
: (known_eq (TYPE_VECTOR_SUBPARTS (vectype), 4u) |
| 20092 |
? !TARGET_USE_SCATTER_4PARTS |
| 20093 |
: !TARGET_USE_SCATTER_8PARTS)) |
| 20094 |
return NULL_TREE; |
| 20095 |
|
| 20096 |
if ((TREE_CODE (index_type) != INTEGER_TYPE |
| 20097 |
&& !POINTER_TYPE_P (index_type)) |
| 20098 |
|| (TYPE_MODE (index_type) != SImode |
| 20099 |
&& TYPE_MODE (index_type) != DImode)) |
| 20100 |
return NULL_TREE; |
| 20101 |
|
| 20102 |
if (TYPE_PRECISION (index_type) > POINTER_SIZE) |
| 20103 |
return NULL_TREE; |
| 20104 |
|
| 20105 |
/* v*scatter* insn sign extends index to pointer mode. */ |
| 20106 |
if (TYPE_PRECISION (index_type) < POINTER_SIZE |
| 20107 |
&& TYPE_UNSIGNED (index_type)) |
| 20108 |
return NULL_TREE; |
| 20109 |
|
| 20110 |
/* Scale can be 1, 2, 4 or 8. */ |
| 20111 |
if (scale <= 0 |
| 20112 |
|| scale > 8 |
| 20113 |
|| (scale & (scale - 1)) != 0) |
| 20114 |
return NULL_TREE; |
| 20115 |
|
| 20116 |
si = TYPE_MODE (index_type) == SImode; |
| 20117 |
switch (TYPE_MODE (vectype)) |
| 20118 |
{ |
| 20119 |
case E_V8DFmode: |
| 20120 |
code = si ? IX86_BUILTIN_SCATTERALTSIV8DF : IX86_BUILTIN_SCATTERDIV8DF; |
| 20121 |
break; |
| 20122 |
case E_V8DImode: |
| 20123 |
code = si ? IX86_BUILTIN_SCATTERALTSIV8DI : IX86_BUILTIN_SCATTERDIV8DI; |
| 20124 |
break; |
| 20125 |
case E_V16SFmode: |
| 20126 |
code = si ? IX86_BUILTIN_SCATTERSIV16SF : IX86_BUILTIN_SCATTERALTDIV16SF; |
| 20127 |
break; |
| 20128 |
case E_V16SImode: |
| 20129 |
code = si ? IX86_BUILTIN_SCATTERSIV16SI : IX86_BUILTIN_SCATTERALTDIV16SI; |
| 20130 |
break; |
| 20131 |
case E_V4DFmode: |
| 20132 |
if (TARGET_AVX512VL) |
| 20133 |
code = si ? IX86_BUILTIN_SCATTERALTSIV4DF : IX86_BUILTIN_SCATTERDIV4DF; |
| 20134 |
else |
| 20135 |
return NULL_TREE; |
| 20136 |
break; |
| 20137 |
case E_V4DImode: |
| 20138 |
if (TARGET_AVX512VL) |
| 20139 |
code = si ? IX86_BUILTIN_SCATTERALTSIV4DI : IX86_BUILTIN_SCATTERDIV4DI; |
| 20140 |
else |
| 20141 |
return NULL_TREE; |
| 20142 |
break; |
| 20143 |
case E_V8SFmode: |
| 20144 |
if (TARGET_AVX512VL) |
| 20145 |
code = si ? IX86_BUILTIN_SCATTERSIV8SF : IX86_BUILTIN_SCATTERALTDIV8SF; |
| 20146 |
else |
| 20147 |
return NULL_TREE; |
| 20148 |
break; |
| 20149 |
case E_V8SImode: |
| 20150 |
if (TARGET_AVX512VL) |
| 20151 |
code = si ? IX86_BUILTIN_SCATTERSIV8SI : IX86_BUILTIN_SCATTERALTDIV8SI; |
| 20152 |
else |
| 20153 |
return NULL_TREE; |
| 20154 |
break; |
| 20155 |
case E_V2DFmode: |
| 20156 |
if (TARGET_AVX512VL) |
| 20157 |
code = si ? IX86_BUILTIN_SCATTERALTSIV2DF : IX86_BUILTIN_SCATTERDIV2DF; |
| 20158 |
else |
| 20159 |
return NULL_TREE; |
| 20160 |
break; |
| 20161 |
case E_V2DImode: |
| 20162 |
if (TARGET_AVX512VL) |
| 20163 |
code = si ? IX86_BUILTIN_SCATTERALTSIV2DI : IX86_BUILTIN_SCATTERDIV2DI; |
| 20164 |
else |
| 20165 |
return NULL_TREE; |
| 20166 |
break; |
| 20167 |
case E_V4SFmode: |
| 20168 |
if (TARGET_AVX512VL) |
| 20169 |
code = si ? IX86_BUILTIN_SCATTERSIV4SF : IX86_BUILTIN_SCATTERALTDIV4SF; |
| 20170 |
else |
| 20171 |
return NULL_TREE; |
| 20172 |
break; |
| 20173 |
case E_V4SImode: |
| 20174 |
if (TARGET_AVX512VL) |
| 20175 |
code = si ? IX86_BUILTIN_SCATTERSIV4SI : IX86_BUILTIN_SCATTERALTDIV4SI; |
| 20176 |
else |
| 20177 |
return NULL_TREE; |
| 20178 |
break; |
| 20179 |
default: |
| 20180 |
return NULL_TREE; |
| 20181 |
} |
| 20182 |
|
| 20183 |
return get_ix86_builtin (code); |
| 20184 |
} |
| 20185 |
|
| 20186 |
/* Return true if it is safe to use the rsqrt optabs to optimize |
| 20187 |
1.0/sqrt. */ |
| 20188 |
|
| 20189 |
static bool |
| 20190 |
use_rsqrt_p (machine_mode mode) |
| 20191 |
{ |
| 20192 |
return ((mode == HFmode |
| 20193 |
|| (TARGET_SSE && TARGET_SSE_MATH)) |
| 20194 |
&& flag_finite_math_only |
| 20195 |
&& !flag_trapping_math |
| 20196 |
&& flag_unsafe_math_optimizations); |
| 20197 |
} |
| 20198 |
|
| 20199 |
/* Helper for avx_vpermilps256_operand et al. This is also used by |
| 20200 |
the expansion functions to turn the parallel back into a mask. |
| 20201 |
The return value is 0 for no match and the imm8+1 for a match. */ |
| 20202 |
|
| 20203 |
int |
| 20204 |
avx_vpermilp_parallel (rtx par, machine_mode mode) |
| 20205 |
{ |
| 20206 |
unsigned i, nelt = GET_MODE_NUNITS (mode); |
| 20207 |
unsigned mask = 0; |
| 20208 |
unsigned char ipar[16] = {}; /* Silence -Wuninitialized warning. */ |
| 20209 |
|
| 20210 |
if (XVECLEN (par, 0) != (int) nelt) |
| 20211 |
return 0; |
| 20212 |
|
| 20213 |
/* Validate that all of the elements are constants, and not totally |
| 20214 |
out of range. Copy the data into an integral array to make the |
| 20215 |
subsequent checks easier. */ |
| 20216 |
for (i = 0; i < nelt; ++i) |
| 20217 |
{ |
| 20218 |
rtx er = XVECEXP (par, 0, i); |
| 20219 |
unsigned HOST_WIDE_INT ei; |
| 20220 |
|
| 20221 |
if (!CONST_INT_P (er)) |
| 20222 |
return 0; |
| 20223 |
ei = INTVAL (er); |
| 20224 |
if (ei >= nelt) |
| 20225 |
return 0; |
| 20226 |
ipar[i] = ei; |
| 20227 |
} |
| 20228 |
|
| 20229 |
switch (mode) |
| 20230 |
{ |
| 20231 |
case E_V8DFmode: |
| 20232 |
/* In the 512-bit DFmode case, we can only move elements within |
| 20233 |
a 128-bit lane. First fill the second part of the mask, |
| 20234 |
then fallthru. */ |
| 20235 |
for (i = 4; i < 6; ++i) |
| 20236 |
{ |
| 20237 |
if (ipar[i] < 4 || ipar[i] >= 6) |
| 20238 |
return 0; |
| 20239 |
mask |= (ipar[i] - 4) << i; |
| 20240 |
} |
| 20241 |
for (i = 6; i < 8; ++i) |
| 20242 |
{ |
| 20243 |
if (ipar[i] < 6) |
| 20244 |
return 0; |
| 20245 |
mask |= (ipar[i] - 6) << i; |
| 20246 |
} |
| 20247 |
/* FALLTHRU */ |
| 20248 |
|
| 20249 |
case E_V4DFmode: |
| 20250 |
/* In the 256-bit DFmode case, we can only move elements within |
| 20251 |
a 128-bit lane. */ |
| 20252 |
for (i = 0; i < 2; ++i) |
| 20253 |
{ |
| 20254 |
if (ipar[i] >= 2) |
| 20255 |
return 0; |
| 20256 |
mask |= ipar[i] << i; |
| 20257 |
} |
| 20258 |
for (i = 2; i < 4; ++i) |
| 20259 |
{ |
| 20260 |
if (ipar[i] < 2 || ipar[i] >= 4) |
| 20261 |
return 0; |
| 20262 |
mask |= (ipar[i] - 2) << i; |
| 20263 |
} |
| 20264 |
break; |
| 20265 |
|
| 20266 |
case E_V16SFmode: |
| 20267 |
/* In 512 bit SFmode case, permutation in the upper 256 bits |
| 20268 |
must mirror the permutation in the lower 256-bits. */ |
| 20269 |
for (i = 0; i < 8; ++i) |
| 20270 |
if (ipar[i] + 8 != ipar[i + 8]) |
| 20271 |
return 0; |
| 20272 |
/* FALLTHRU */ |
| 20273 |
|
| 20274 |
case E_V8SFmode: |
| 20275 |
/* In 256 bit SFmode case, we have full freedom of |
| 20276 |
movement within the low 128-bit lane, but the high 128-bit |
| 20277 |
lane must mirror the exact same pattern. */ |
| 20278 |
for (i = 0; i < 4; ++i) |
| 20279 |
if (ipar[i] + 4 != ipar[i + 4]) |
| 20280 |
return 0; |
| 20281 |
nelt = 4; |
| 20282 |
/* FALLTHRU */ |
| 20283 |
|
| 20284 |
case E_V2DFmode: |
| 20285 |
case E_V4SFmode: |
| 20286 |
/* In the 128-bit case, we've full freedom in the placement of |
| 20287 |
the elements from the source operand. */ |
| 20288 |
for (i = 0; i < nelt; ++i) |
| 20289 |
mask |= ipar[i] << (i * (nelt / 2)); |
| 20290 |
break; |
| 20291 |
|
| 20292 |
default: |
| 20293 |
gcc_unreachable (); |
| 20294 |
} |
| 20295 |
|
| 20296 |
/* Make sure success has a non-zero value by adding one. */ |
| 20297 |
return mask + 1; |
| 20298 |
} |
| 20299 |
|
| 20300 |
/* Helper for avx_vperm2f128_v4df_operand et al. This is also used by |
| 20301 |
the expansion functions to turn the parallel back into a mask. |
| 20302 |
The return value is 0 for no match and the imm8+1 for a match. */ |
| 20303 |
|
| 20304 |
int |
| 20305 |
avx_vperm2f128_parallel (rtx par, machine_mode mode) |
| 20306 |
{ |
| 20307 |
unsigned i, nelt = GET_MODE_NUNITS (mode), nelt2 = nelt / 2; |
| 20308 |
unsigned mask = 0; |
| 20309 |
unsigned char ipar[8] = {}; /* Silence -Wuninitialized warning. */ |
| 20310 |
|
| 20311 |
if (XVECLEN (par, 0) != (int) nelt) |
| 20312 |
return 0; |
| 20313 |
|
| 20314 |
/* Validate that all of the elements are constants, and not totally |
| 20315 |
out of range. Copy the data into an integral array to make the |
| 20316 |
subsequent checks easier. */ |
| 20317 |
for (i = 0; i < nelt; ++i) |
| 20318 |
{ |
| 20319 |
rtx er = XVECEXP (par, 0, i); |
| 20320 |
unsigned HOST_WIDE_INT ei; |
| 20321 |
|
| 20322 |
if (!CONST_INT_P (er)) |
| 20323 |
return 0; |
| 20324 |
ei = INTVAL (er); |
| 20325 |
if (ei >= 2 * nelt) |
| 20326 |
return 0; |
| 20327 |
ipar[i] = ei; |
| 20328 |
} |
| 20329 |
|
| 20330 |
/* Validate that the halves of the permute are halves. */ |
| 20331 |
for (i = 0; i < nelt2 - 1; ++i) |
| 20332 |
if (ipar[i] + 1 != ipar[i + 1]) |
| 20333 |
return 0; |
| 20334 |
for (i = nelt2; i < nelt - 1; ++i) |
| 20335 |
if (ipar[i] + 1 != ipar[i + 1]) |
| 20336 |
return 0; |
| 20337 |
|
| 20338 |
/* Reconstruct the mask. */ |
| 20339 |
for (i = 0; i < 2; ++i) |
| 20340 |
{ |
| 20341 |
unsigned e = ipar[i * nelt2]; |
| 20342 |
if (e % nelt2) |
| 20343 |
return 0; |
| 20344 |
e /= nelt2; |
| 20345 |
mask |= e << (i * 4); |
| 20346 |
} |
| 20347 |
|
| 20348 |
/* Make sure success has a non-zero value by adding one. */ |
| 20349 |
return mask + 1; |
| 20350 |
} |
| 20351 |
|
| 20352 |
/* Return a mask of VPTERNLOG operands that do not affect output. */ |
| 20353 |
|
| 20354 |
int |
| 20355 |
vpternlog_redundant_operand_mask (rtx pternlog_imm) |
| 20356 |
{ |
| 20357 |
int mask = 0; |
| 20358 |
int imm8 = INTVAL (pternlog_imm); |
| 20359 |
|
| 20360 |
if (((imm8 >> 4) & 0x0F) == (imm8 & 0x0F)) |
| 20361 |
mask |= 1; |
| 20362 |
if (((imm8 >> 2) & 0x33) == (imm8 & 0x33)) |
| 20363 |
mask |= 2; |
| 20364 |
if (((imm8 >> 1) & 0x55) == (imm8 & 0x55)) |
| 20365 |
mask |= 4; |
| 20366 |
|
| 20367 |
return mask; |
| 20368 |
} |
| 20369 |
|
| 20370 |
/* Eliminate false dependencies on operands that do not affect output |
| 20371 |
by substituting other operands of a VPTERNLOG. */ |
| 20372 |
|
| 20373 |
void |
| 20374 |
substitute_vpternlog_operands (rtx *operands) |
| 20375 |
{ |
| 20376 |
int mask = vpternlog_redundant_operand_mask (operands[4]); |
| 20377 |
|
| 20378 |
if (mask & 1) /* The first operand is redundant. */ |
| 20379 |
operands[1] = operands[2]; |
| 20380 |
|
| 20381 |
if (mask & 2) /* The second operand is redundant. */ |
| 20382 |
operands[2] = operands[1]; |
| 20383 |
|
| 20384 |
if (mask & 4) /* The third operand is redundant. */ |
| 20385 |
operands[3] = operands[1]; |
| 20386 |
else if (REG_P (operands[3])) |
| 20387 |
{ |
| 20388 |
if (mask & 1) |
| 20389 |
operands[1] = operands[3]; |
| 20390 |
if (mask & 2) |
| 20391 |
operands[2] = operands[3]; |
| 20392 |
} |
| 20393 |
} |
| 20394 |
|
| 20395 |
/* Return a register priority for hard reg REGNO. */ |
| 20396 |
static int |
| 20397 |
ix86_register_priority (int hard_regno) |
| 20398 |
{ |
| 20399 |
/* ebp and r13 as the base always wants a displacement, r12 as the |
| 20400 |
base always wants an index. So discourage their usage in an |
| 20401 |
address. */ |
| 20402 |
if (hard_regno == R12_REG || hard_regno == R13_REG) |
| 20403 |
return 0; |
| 20404 |
if (hard_regno == BP_REG) |
| 20405 |
return 1; |
| 20406 |
/* New x86-64 int registers result in bigger code size. Discourage them. */ |
| 20407 |
if (REX_INT_REGNO_P (hard_regno)) |
| 20408 |
return 2; |
| 20409 |
if (REX2_INT_REGNO_P (hard_regno)) |
| 20410 |
return 2; |
| 20411 |
/* New x86-64 SSE registers result in bigger code size. Discourage them. */ |
| 20412 |
if (REX_SSE_REGNO_P (hard_regno)) |
| 20413 |
return 2; |
| 20414 |
if (EXT_REX_SSE_REGNO_P (hard_regno)) |
| 20415 |
return 1; |
| 20416 |
/* Usage of AX register results in smaller code. Prefer it. */ |
| 20417 |
if (hard_regno == AX_REG) |
| 20418 |
return 4; |
| 20419 |
return 3; |
| 20420 |
} |
| 20421 |
|
| 20422 |
/* Implement TARGET_PREFERRED_RELOAD_CLASS. |
| 20423 |
|
| 20424 |
Put float CONST_DOUBLE in the constant pool instead of fp regs. |
| 20425 |
QImode must go into class Q_REGS. |
| 20426 |
Narrow ALL_REGS to GENERAL_REGS. This supports allowing movsf and |
| 20427 |
movdf to do mem-to-mem moves through integer regs. */ |
| 20428 |
|
| 20429 |
static reg_class_t |
| 20430 |
ix86_preferred_reload_class (rtx x, reg_class_t regclass) |
| 20431 |
{ |
| 20432 |
machine_mode mode = GET_MODE (x); |
| 20433 |
|
| 20434 |
/* We're only allowed to return a subclass of CLASS. Many of the |
| 20435 |
following checks fail for NO_REGS, so eliminate that early. */ |
| 20436 |
if (regclass == NO_REGS) |
| 20437 |
return NO_REGS; |
| 20438 |
|
| 20439 |
/* All classes can load zeros. */ |
| 20440 |
if (x == CONST0_RTX (mode)) |
| 20441 |
return regclass; |
| 20442 |
|
| 20443 |
/* Force constants into memory if we are loading a (nonzero) constant into |
| 20444 |
an MMX, SSE or MASK register. This is because there are no MMX/SSE/MASK |
| 20445 |
instructions to load from a constant. */ |
| 20446 |
if (CONSTANT_P (x) |
| 20447 |
&& (MAYBE_MMX_CLASS_P (regclass) |
| 20448 |
|| MAYBE_SSE_CLASS_P (regclass) |
| 20449 |
|| MAYBE_MASK_CLASS_P (regclass))) |
| 20450 |
return NO_REGS; |
| 20451 |
|
| 20452 |
/* Floating-point constants need more complex checks. */ |
| 20453 |
if (CONST_DOUBLE_P (x)) |
| 20454 |
{ |
| 20455 |
/* General regs can load everything. */ |
| 20456 |
if (INTEGER_CLASS_P (regclass)) |
| 20457 |
return regclass; |
| 20458 |
|
| 20459 |
/* Floats can load 0 and 1 plus some others. Note that we eliminated |
| 20460 |
zero above. We only want to wind up preferring 80387 registers if |
| 20461 |
we plan on doing computation with them. */ |
| 20462 |
if (IS_STACK_MODE (mode) |
| 20463 |
&& standard_80387_constant_p (x) > 0) |
| 20464 |
{ |
| 20465 |
/* Limit class to FP regs. */ |
| 20466 |
if (FLOAT_CLASS_P (regclass)) |
| 20467 |
return FLOAT_REGS; |
| 20468 |
} |
| 20469 |
|
| 20470 |
return NO_REGS; |
| 20471 |
} |
| 20472 |
|
| 20473 |
/* Prefer SSE if we can use them for math. Also allow integer regs |
| 20474 |
when moves between register units are cheap. */ |
| 20475 |
if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH) |
| 20476 |
{ |
| 20477 |
if (TARGET_INTER_UNIT_MOVES_FROM_VEC |
| 20478 |
&& TARGET_INTER_UNIT_MOVES_TO_VEC |
| 20479 |
&& GET_MODE_SIZE (mode) <= GET_MODE_SIZE (word_mode)) |
| 20480 |
return INT_SSE_CLASS_P (regclass) ? regclass : NO_REGS; |
| 20481 |
else |
| 20482 |
return SSE_CLASS_P (regclass) ? regclass : NO_REGS; |
| 20483 |
} |
| 20484 |
|
| 20485 |
/* Generally when we see PLUS here, it's the function invariant |
| 20486 |
(plus soft-fp const_int). Which can only be computed into general |
| 20487 |
regs. */ |
| 20488 |
if (GET_CODE (x) == PLUS) |
| 20489 |
return INTEGER_CLASS_P (regclass) ? regclass : NO_REGS; |
| 20490 |
|
| 20491 |
/* QImode constants are easy to load, but non-constant QImode data |
| 20492 |
must go into Q_REGS or ALL_MASK_REGS. */ |
| 20493 |
if (GET_MODE (x) == QImode && !CONSTANT_P (x)) |
| 20494 |
{ |
| 20495 |
if (Q_CLASS_P (regclass)) |
| 20496 |
return regclass; |
| 20497 |
else if (reg_class_subset_p (Q_REGS, regclass)) |
| 20498 |
return Q_REGS; |
| 20499 |
else if (MASK_CLASS_P (regclass)) |
| 20500 |
return regclass; |
| 20501 |
else |
| 20502 |
return NO_REGS; |
| 20503 |
} |
| 20504 |
|
| 20505 |
return regclass; |
| 20506 |
} |
| 20507 |
|
| 20508 |
/* Discourage putting floating-point values in SSE registers unless |
| 20509 |
SSE math is being used, and likewise for the 387 registers. */ |
| 20510 |
static reg_class_t |
| 20511 |
ix86_preferred_output_reload_class (rtx x, reg_class_t regclass) |
| 20512 |
{ |
| 20513 |
/* Restrict the output reload class to the register bank that we are doing |
| 20514 |
math on. If we would like not to return a subset of CLASS, reject this |
| 20515 |
alternative: if reload cannot do this, it will still use its choice. */ |
| 20516 |
machine_mode mode = GET_MODE (x); |
| 20517 |
if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH) |
| 20518 |
return MAYBE_SSE_CLASS_P (regclass) ? ALL_SSE_REGS : NO_REGS; |
| 20519 |
|
| 20520 |
if (IS_STACK_MODE (mode)) |
| 20521 |
return FLOAT_CLASS_P (regclass) ? regclass : NO_REGS; |
| 20522 |
|
| 20523 |
return regclass; |
| 20524 |
} |
| 20525 |
|
| 20526 |
static reg_class_t |
| 20527 |
ix86_secondary_reload (bool in_p, rtx x, reg_class_t rclass, |
| 20528 |
machine_mode mode, secondary_reload_info *sri) |
| 20529 |
{ |
| 20530 |
/* Double-word spills from general registers to non-offsettable memory |
| 20531 |
references (zero-extended addresses) require special handling. */ |
| 20532 |
if (TARGET_64BIT |
| 20533 |
&& MEM_P (x) |
| 20534 |
&& GET_MODE_SIZE (mode) > UNITS_PER_WORD |
| 20535 |
&& INTEGER_CLASS_P (rclass) |
| 20536 |
&& !offsettable_memref_p (x)) |
| 20537 |
{ |
| 20538 |
sri->icode = (in_p |
| 20539 |
? CODE_FOR_reload_noff_load |
| 20540 |
: CODE_FOR_reload_noff_store); |
| 20541 |
/* Add the cost of moving address to a temporary. */ |
| 20542 |
sri->extra_cost = 1; |
| 20543 |
|
| 20544 |
return NO_REGS; |
| 20545 |
} |
| 20546 |
|
| 20547 |
/* QImode spills from non-QI registers require |
| 20548 |
intermediate register on 32bit targets. */ |
| 20549 |
if (mode == QImode |
| 20550 |
&& ((!TARGET_64BIT && !in_p |
| 20551 |
&& INTEGER_CLASS_P (rclass) |
| 20552 |
&& MAYBE_NON_Q_CLASS_P (rclass)) |
| 20553 |
|| (!TARGET_AVX512DQ |
| 20554 |
&& MAYBE_MASK_CLASS_P (rclass)))) |
| 20555 |
{ |
| 20556 |
int regno = true_regnum (x); |
| 20557 |
|
| 20558 |
/* Return Q_REGS if the operand is in memory. */ |
| 20559 |
if (regno == -1) |
| 20560 |
return Q_REGS; |
| 20561 |
|
| 20562 |
return NO_REGS; |
| 20563 |
} |
| 20564 |
|
| 20565 |
/* Require movement to gpr, and then store to memory. */ |
| 20566 |
if ((mode == HFmode || mode == HImode || mode == V2QImode |
| 20567 |
|| mode == BFmode) |
| 20568 |
&& !TARGET_SSE4_1 |
| 20569 |
&& SSE_CLASS_P (rclass) |
| 20570 |
&& !in_p && MEM_P (x)) |
| 20571 |
{ |
| 20572 |
sri->extra_cost = 1; |
| 20573 |
return GENERAL_REGS; |
| 20574 |
} |
| 20575 |
|
| 20576 |
/* This condition handles corner case where an expression involving |
| 20577 |
pointers gets vectorized. We're trying to use the address of a |
| 20578 |
stack slot as a vector initializer. |
| 20579 |
|
| 20580 |
(set (reg:V2DI 74 [ vect_cst_.2 ]) |
| 20581 |
(vec_duplicate:V2DI (reg/f:DI 20 frame))) |
| 20582 |
|
| 20583 |
Eventually frame gets turned into sp+offset like this: |
| 20584 |
|
| 20585 |
(set (reg:V2DI 21 xmm0 [orig:74 vect_cst_.2 ] [74]) |
| 20586 |
(vec_duplicate:V2DI (plus:DI (reg/f:DI 7 sp) |
| 20587 |
(const_int 392 [0x188])))) |
| 20588 |
|
| 20589 |
That later gets turned into: |
| 20590 |
|
| 20591 |
(set (reg:V2DI 21 xmm0 [orig:74 vect_cst_.2 ] [74]) |
| 20592 |
(vec_duplicate:V2DI (plus:DI (reg/f:DI 7 sp) |
| 20593 |
(mem/u/c/i:DI (symbol_ref/u:DI ("*.LC0") [flags 0x2]) [0 S8 A64])))) |
| 20594 |
|
| 20595 |
We'll have the following reload recorded: |
| 20596 |
|
| 20597 |
Reload 0: reload_in (DI) = |
| 20598 |
(plus:DI (reg/f:DI 7 sp) |
| 20599 |
(mem/u/c/i:DI (symbol_ref/u:DI ("*.LC0") [flags 0x2]) [0 S8 A64])) |
| 20600 |
reload_out (V2DI) = (reg:V2DI 21 xmm0 [orig:74 vect_cst_.2 ] [74]) |
| 20601 |
SSE_REGS, RELOAD_OTHER (opnum = 0), can't combine |
| 20602 |
reload_in_reg: (plus:DI (reg/f:DI 7 sp) (const_int 392 [0x188])) |
| 20603 |
reload_out_reg: (reg:V2DI 21 xmm0 [orig:74 vect_cst_.2 ] [74]) |
| 20604 |
reload_reg_rtx: (reg:V2DI 22 xmm1) |
| 20605 |
|
| 20606 |
Which isn't going to work since SSE instructions can't handle scalar |
| 20607 |
additions. Returning GENERAL_REGS forces the addition into integer |
| 20608 |
register and reload can handle subsequent reloads without problems. */ |
| 20609 |
|
| 20610 |
if (in_p && GET_CODE (x) == PLUS |
| 20611 |
&& SSE_CLASS_P (rclass) |
| 20612 |
&& SCALAR_INT_MODE_P (mode)) |
| 20613 |
return GENERAL_REGS; |
| 20614 |
|
| 20615 |
return NO_REGS; |
| 20616 |
} |
| 20617 |
|
| 20618 |
/* Implement TARGET_CLASS_LIKELY_SPILLED_P. */ |
| 20619 |
|
| 20620 |
static bool |
| 20621 |
ix86_class_likely_spilled_p (reg_class_t rclass) |
| 20622 |
{ |
| 20623 |
switch (rclass) |
| 20624 |
{ |
| 20625 |
case AREG: |
| 20626 |
case DREG: |
| 20627 |
case CREG: |
| 20628 |
case BREG: |
| 20629 |
case AD_REGS: |
| 20630 |
case SIREG: |
| 20631 |
case DIREG: |
| 20632 |
case SSE_FIRST_REG: |
| 20633 |
case FP_TOP_REG: |
| 20634 |
case FP_SECOND_REG: |
| 20635 |
return true; |
| 20636 |
|
| 20637 |
default: |
| 20638 |
break; |
| 20639 |
} |
| 20640 |
|
| 20641 |
return false; |
| 20642 |
} |
| 20643 |
|
| 20644 |
/* Implement TARGET_CALLEE_SAVE_COST. */ |
| 20645 |
|
| 20646 |
static int |
| 20647 |
ix86_callee_save_cost (spill_cost_type, unsigned int hard_regno, machine_mode, |
| 20648 |
unsigned int, int mem_cost, const HARD_REG_SET &, bool) |
| 20649 |
{ |
| 20650 |
/* Account for the fact that push and pop are shorter and do their |
| 20651 |
own allocation and deallocation. */ |
| 20652 |
if (GENERAL_REGNO_P (hard_regno)) |
| 20653 |
{ |
| 20654 |
/* push is 1 byte while typical spill is 4-5 bytes. |
| 20655 |
??? We probably should adjust size costs accordingly. |
| 20656 |
Costs are relative to reg-reg move that has 2 bytes for 32bit |
| 20657 |
and 3 bytes otherwise. Be sure that no cost table sets cost |
| 20658 |
to 2, so we end up with 0. */ |
| 20659 |
if (mem_cost <= 2 || optimize_function_for_size_p (cfun)) |
| 20660 |
return 1; |
| 20661 |
return mem_cost - 2; |
| 20662 |
} |
| 20663 |
return mem_cost; |
| 20664 |
} |
| 20665 |
|
| 20666 |
/* Return true if a set of DST by the expression SRC should be allowed. |
| 20667 |
This prevents complex sets of likely_spilled hard regs before split1. */ |
| 20668 |
|
| 20669 |
bool |
| 20670 |
ix86_hardreg_mov_ok (rtx dst, rtx src) |
| 20671 |
{ |
| 20672 |
/* Avoid complex sets of likely_spilled hard registers before reload. */ |
| 20673 |
if (REG_P (dst) && HARD_REGISTER_P (dst) |
| 20674 |
&& !REG_P (src) && !MEM_P (src) |
| 20675 |
&& !(VECTOR_MODE_P (GET_MODE (dst)) |
| 20676 |
? standard_sse_constant_p (src, GET_MODE (dst)) |
| 20677 |
: x86_64_immediate_operand (src, GET_MODE (dst))) |
| 20678 |
&& ix86_class_likely_spilled_p (REGNO_REG_CLASS (REGNO (dst))) |
| 20679 |
&& ix86_pre_reload_split ()) |
| 20680 |
return false; |
| 20681 |
return true; |
| 20682 |
} |
| 20683 |
|
| 20684 |
/* If we are copying between registers from different register sets |
| 20685 |
(e.g. FP and integer), we may need a memory location. |
| 20686 |
|
| 20687 |
The function can't work reliably when one of the CLASSES is a class |
| 20688 |
containing registers from multiple sets. We avoid this by never combining |
| 20689 |
different sets in a single alternative in the machine description. |
| 20690 |
Ensure that this constraint holds to avoid unexpected surprises. |
| 20691 |
|
| 20692 |
When STRICT is false, we are being called from REGISTER_MOVE_COST, |
| 20693 |
so do not enforce these sanity checks. |
| 20694 |
|
| 20695 |
To optimize register_move_cost performance, define inline variant. */ |
| 20696 |
|
| 20697 |
static inline bool |
| 20698 |
inline_secondary_memory_needed (machine_mode mode, reg_class_t class1, |
| 20699 |
reg_class_t class2, int strict) |
| 20700 |
{ |
| 20701 |
if (lra_in_progress && (class1 == NO_REGS || class2 == NO_REGS)) |
| 20702 |
return false; |
| 20703 |
|
| 20704 |
if (MAYBE_FLOAT_CLASS_P (class1) != FLOAT_CLASS_P (class1) |
| 20705 |
|| MAYBE_FLOAT_CLASS_P (class2) != FLOAT_CLASS_P (class2) |
| 20706 |
|| MAYBE_SSE_CLASS_P (class1) != SSE_CLASS_P (class1) |
| 20707 |
|| MAYBE_SSE_CLASS_P (class2) != SSE_CLASS_P (class2) |
| 20708 |
|| MAYBE_MMX_CLASS_P (class1) != MMX_CLASS_P (class1) |
| 20709 |
|| MAYBE_MMX_CLASS_P (class2) != MMX_CLASS_P (class2) |
| 20710 |
|| MAYBE_MASK_CLASS_P (class1) != MASK_CLASS_P (class1) |
| 20711 |
|| MAYBE_MASK_CLASS_P (class2) != MASK_CLASS_P (class2)) |
| 20712 |
{ |
| 20713 |
gcc_assert (!strict || lra_in_progress); |
| 20714 |
return true; |
| 20715 |
} |
| 20716 |
|
| 20717 |
if (FLOAT_CLASS_P (class1) != FLOAT_CLASS_P (class2)) |
| 20718 |
return true; |
| 20719 |
|
| 20720 |
/* ??? This is a lie. We do have moves between mmx/general, and for |
| 20721 |
mmx/sse2. But by saying we need secondary memory we discourage the |
| 20722 |
register allocator from using the mmx registers unless needed. */ |
| 20723 |
if (MMX_CLASS_P (class1) != MMX_CLASS_P (class2)) |
| 20724 |
return true; |
| 20725 |
|
| 20726 |
/* Between mask and general, we have moves no larger than word size. */ |
| 20727 |
if (MASK_CLASS_P (class1) != MASK_CLASS_P (class2)) |
| 20728 |
{ |
| 20729 |
if (!(INTEGER_CLASS_P (class1) || INTEGER_CLASS_P (class2)) |
| 20730 |
|| GET_MODE_SIZE (mode) > UNITS_PER_WORD) |
| 20731 |
return true; |
| 20732 |
} |
| 20733 |
|
| 20734 |
if (SSE_CLASS_P (class1) != SSE_CLASS_P (class2)) |
| 20735 |
{ |
| 20736 |
/* SSE1 doesn't have any direct moves from other classes. */ |
| 20737 |
if (!TARGET_SSE2) |
| 20738 |
return true; |
| 20739 |
|
| 20740 |
if (!(INTEGER_CLASS_P (class1) || INTEGER_CLASS_P (class2))) |
| 20741 |
return true; |
| 20742 |
|
| 20743 |
/* If the target says that inter-unit moves are more expensive |
| 20744 |
than moving through memory, then don't generate them. */ |
| 20745 |
if ((SSE_CLASS_P (class1) && !TARGET_INTER_UNIT_MOVES_FROM_VEC) |
| 20746 |
|| (SSE_CLASS_P (class2) && !TARGET_INTER_UNIT_MOVES_TO_VEC)) |
| 20747 |
return true; |
| 20748 |
|
| 20749 |
/* With SSE4.1, *mov{ti,di}_internal supports moves between |
| 20750 |
SSE_REGS and GENERAL_REGS using pinsr{q,d} or pextr{q,d}. */ |
| 20751 |
if (TARGET_SSE4_1 |
| 20752 |
&& (TARGET_64BIT ? mode == TImode : mode == DImode)) |
| 20753 |
return false; |
| 20754 |
|
| 20755 |
int msize = GET_MODE_SIZE (mode); |
| 20756 |
|
| 20757 |
/* Between SSE and general, we have moves no larger than word size. */ |
| 20758 |
if (msize > UNITS_PER_WORD) |
| 20759 |
return true; |
| 20760 |
|
| 20761 |
/* In addition to SImode moves, HImode moves are supported for SSE2 and above, |
| 20762 |
Use vmovw with AVX512FP16, or pinsrw/pextrw without AVX512FP16. */ |
| 20763 |
int minsize = GET_MODE_SIZE (TARGET_SSE2 ? HImode : SImode); |
| 20764 |
|
| 20765 |
if (msize < minsize) |
| 20766 |
return true; |
| 20767 |
} |
| 20768 |
|
| 20769 |
return false; |
| 20770 |
} |
| 20771 |
|
| 20772 |
/* Implement TARGET_SECONDARY_MEMORY_NEEDED. */ |
| 20773 |
|
| 20774 |
static bool |
| 20775 |
ix86_secondary_memory_needed (machine_mode mode, reg_class_t class1, |
| 20776 |
reg_class_t class2) |
| 20777 |
{ |
| 20778 |
return inline_secondary_memory_needed (mode, class1, class2, true); |
| 20779 |
} |
| 20780 |
|
| 20781 |
/* Implement TARGET_SECONDARY_MEMORY_NEEDED_MODE. |
| 20782 |
|
| 20783 |
get_secondary_mem widens integral modes to BITS_PER_WORD. |
| 20784 |
There is no need to emit full 64 bit move on 64 bit targets |
| 20785 |
for integral modes that can be moved using 32 bit move. */ |
| 20786 |
|
| 20787 |
static machine_mode |
| 20788 |
ix86_secondary_memory_needed_mode (machine_mode mode) |
| 20789 |
{ |
| 20790 |
if (GET_MODE_BITSIZE (mode) < 32 && INTEGRAL_MODE_P (mode)) |
| 20791 |
return mode_for_size (32, GET_MODE_CLASS (mode), 0).require (); |
| 20792 |
return mode; |
| 20793 |
} |
| 20794 |
|
| 20795 |
/* Implement the TARGET_CLASS_MAX_NREGS hook. |
| 20796 |
|
| 20797 |
On the 80386, this is the size of MODE in words, |
| 20798 |
except in the FP regs, where a single reg is always enough. */ |
| 20799 |
|
| 20800 |
static unsigned char |
| 20801 |
ix86_class_max_nregs (reg_class_t rclass, machine_mode mode) |
| 20802 |
{ |
| 20803 |
if (MAYBE_INTEGER_CLASS_P (rclass)) |
| 20804 |
{ |
| 20805 |
if (mode == XFmode) |
| 20806 |
return (TARGET_64BIT ? 2 : 3); |
| 20807 |
else if (mode == XCmode) |
| 20808 |
return (TARGET_64BIT ? 4 : 6); |
| 20809 |
else |
| 20810 |
return CEIL (GET_MODE_SIZE (mode), UNITS_PER_WORD); |
| 20811 |
} |
| 20812 |
else |
| 20813 |
{ |
| 20814 |
if (COMPLEX_MODE_P (mode)) |
| 20815 |
return 2; |
| 20816 |
else |
| 20817 |
return 1; |
| 20818 |
} |
| 20819 |
} |
| 20820 |
|
| 20821 |
/* Implement TARGET_CAN_CHANGE_MODE_CLASS. */ |
| 20822 |
|
| 20823 |
static bool |
| 20824 |
ix86_can_change_mode_class (machine_mode from, machine_mode to, |
| 20825 |
reg_class_t regclass) |
| 20826 |
{ |
| 20827 |
if (from == to) |
| 20828 |
return true; |
| 20829 |
|
| 20830 |
/* x87 registers can't do subreg at all, as all values are reformatted |
| 20831 |
to extended precision. */ |
| 20832 |
if (MAYBE_FLOAT_CLASS_P (regclass)) |
| 20833 |
return false; |
| 20834 |
|
| 20835 |
if (MAYBE_SSE_CLASS_P (regclass) || MAYBE_MMX_CLASS_P (regclass)) |
| 20836 |
{ |
| 20837 |
/* Vector registers do not support QI or HImode loads. If we don't |
| 20838 |
disallow a change to these modes, reload will assume it's ok to |
| 20839 |
drop the subreg from (subreg:SI (reg:HI 100) 0). This affects |
| 20840 |
the vec_dupv4hi pattern. |
| 20841 |
NB: SSE2 can load 16bit data to sse register via pinsrw. */ |
| 20842 |
int mov_size = MAYBE_SSE_CLASS_P (regclass) && TARGET_SSE2 ? 2 : 4; |
| 20843 |
if (GET_MODE_SIZE (from) < mov_size |
| 20844 |
|| GET_MODE_SIZE (to) < mov_size) |
| 20845 |
return false; |
| 20846 |
} |
| 20847 |
|
| 20848 |
return true; |
| 20849 |
} |
| 20850 |
|
| 20851 |
/* Return index of MODE in the sse load/store tables. */ |
| 20852 |
|
| 20853 |
static inline int |
| 20854 |
sse_store_index (machine_mode mode) |
| 20855 |
{ |
| 20856 |
/* NB: Use SFmode cost for HFmode instead of adding HFmode load/store |
| 20857 |
costs to processor_costs, which requires changes to all entries in |
| 20858 |
processor cost table. */ |
| 20859 |
if (mode == E_HFmode) |
| 20860 |
mode = E_SFmode; |
| 20861 |
|
| 20862 |
switch (GET_MODE_SIZE (mode)) |
| 20863 |
{ |
| 20864 |
case 4: |
| 20865 |
return 0; |
| 20866 |
case 8: |
| 20867 |
return 1; |
| 20868 |
case 16: |
| 20869 |
return 2; |
| 20870 |
case 32: |
| 20871 |
return 3; |
| 20872 |
case 64: |
| 20873 |
return 4; |
| 20874 |
default: |
| 20875 |
return -1; |
| 20876 |
} |
| 20877 |
} |
| 20878 |
|
| 20879 |
/* Return the cost of moving data of mode M between a |
| 20880 |
register and memory. A value of 2 is the default; this cost is |
| 20881 |
relative to those in `REGISTER_MOVE_COST'. |
| 20882 |
|
| 20883 |
This function is used extensively by register_move_cost that is used to |
| 20884 |
build tables at startup. Make it inline in this case. |
| 20885 |
When IN is 2, return maximum of in and out move cost. |
| 20886 |
|
| 20887 |
If moving between registers and memory is more expensive than |
| 20888 |
between two registers, you should define this macro to express the |
| 20889 |
relative cost. |
| 20890 |
|
| 20891 |
Model also increased moving costs of QImode registers in non |
| 20892 |
Q_REGS classes. |
| 20893 |
*/ |
| 20894 |
static inline int |
| 20895 |
inline_memory_move_cost (machine_mode mode, enum reg_class regclass, int in) |
| 20896 |
{ |
| 20897 |
int cost; |
| 20898 |
|
| 20899 |
if (FLOAT_CLASS_P (regclass)) |
| 20900 |
{ |
| 20901 |
int index; |
| 20902 |
switch (mode) |
| 20903 |
{ |
| 20904 |
case E_SFmode: |
| 20905 |
index = 0; |
| 20906 |
break; |
| 20907 |
case E_DFmode: |
| 20908 |
index = 1; |
| 20909 |
break; |
| 20910 |
case E_XFmode: |
| 20911 |
index = 2; |
| 20912 |
break; |
| 20913 |
default: |
| 20914 |
return 100; |
| 20915 |
} |
| 20916 |
if (in == 2) |
| 20917 |
return MAX (ix86_cost->hard_register.fp_load [index], |
| 20918 |
ix86_cost->hard_register.fp_store [index]); |
| 20919 |
return in ? ix86_cost->hard_register.fp_load [index] |
| 20920 |
: ix86_cost->hard_register.fp_store [index]; |
| 20921 |
} |
| 20922 |
if (SSE_CLASS_P (regclass)) |
| 20923 |
{ |
| 20924 |
int index = sse_store_index (mode); |
| 20925 |
if (index == -1) |
| 20926 |
return 100; |
| 20927 |
if (in == 2) |
| 20928 |
return MAX (ix86_cost->hard_register.sse_load [index], |
| 20929 |
ix86_cost->hard_register.sse_store [index]); |
| 20930 |
return in ? ix86_cost->hard_register.sse_load [index] |
| 20931 |
: ix86_cost->hard_register.sse_store [index]; |
| 20932 |
} |
| 20933 |
if (MASK_CLASS_P (regclass)) |
| 20934 |
{ |
| 20935 |
int index; |
| 20936 |
switch (GET_MODE_SIZE (mode)) |
| 20937 |
{ |
| 20938 |
case 1: |
| 20939 |
index = 0; |
| 20940 |
break; |
| 20941 |
case 2: |
| 20942 |
index = 1; |
| 20943 |
break; |
| 20944 |
/* DImode loads and stores assumed to cost the same as SImode. */ |
| 20945 |
case 4: |
| 20946 |
case 8: |
| 20947 |
index = 2; |
| 20948 |
break; |
| 20949 |
default: |
| 20950 |
return 100; |
| 20951 |
} |
| 20952 |
|
| 20953 |
if (in == 2) |
| 20954 |
return MAX (ix86_cost->hard_register.mask_load[index], |
| 20955 |
ix86_cost->hard_register.mask_store[index]); |
| 20956 |
return in ? ix86_cost->hard_register.mask_load[2] |
| 20957 |
: ix86_cost->hard_register.mask_store[2]; |
| 20958 |
} |
| 20959 |
if (MMX_CLASS_P (regclass)) |
| 20960 |
{ |
| 20961 |
int index; |
| 20962 |
switch (GET_MODE_SIZE (mode)) |
| 20963 |
{ |
| 20964 |
case 4: |
| 20965 |
index = 0; |
| 20966 |
break; |
| 20967 |
case 8: |
| 20968 |
index = 1; |
| 20969 |
break; |
| 20970 |
default: |
| 20971 |
return 100; |
| 20972 |
} |
| 20973 |
if (in == 2) |
| 20974 |
return MAX (ix86_cost->hard_register.mmx_load [index], |
| 20975 |
ix86_cost->hard_register.mmx_store [index]); |
| 20976 |
return in ? ix86_cost->hard_register.mmx_load [index] |
| 20977 |
: ix86_cost->hard_register.mmx_store [index]; |
| 20978 |
} |
| 20979 |
switch (GET_MODE_SIZE (mode)) |
| 20980 |
{ |
| 20981 |
case 1: |
| 20982 |
if (Q_CLASS_P (regclass) || TARGET_64BIT) |
| 20983 |
{ |
| 20984 |
if (!in) |
| 20985 |
return ix86_cost->hard_register.int_store[0]; |
| 20986 |
if (TARGET_PARTIAL_REG_DEPENDENCY |
| 20987 |
&& optimize_function_for_speed_p (cfun)) |
| 20988 |
cost = ix86_cost->hard_register.movzbl_load; |
| 20989 |
else |
| 20990 |
cost = ix86_cost->hard_register.int_load[0]; |
| 20991 |
if (in == 2) |
| 20992 |
return MAX (cost, ix86_cost->hard_register.int_store[0]); |
| 20993 |
return cost; |
| 20994 |
} |
| 20995 |
else |
| 20996 |
{ |
| 20997 |
if (in == 2) |
| 20998 |
return MAX (ix86_cost->hard_register.movzbl_load, |
| 20999 |
ix86_cost->hard_register.int_store[0] + 4); |
| 21000 |
if (in) |
| 21001 |
return ix86_cost->hard_register.movzbl_load; |
| 21002 |
else |
| 21003 |
return ix86_cost->hard_register.int_store[0] + 4; |
| 21004 |
} |
| 21005 |
break; |
| 21006 |
case 2: |
| 21007 |
{ |
| 21008 |
int cost; |
| 21009 |
if (in == 2) |
| 21010 |
cost = MAX (ix86_cost->hard_register.int_load[1], |
| 21011 |
ix86_cost->hard_register.int_store[1]); |
| 21012 |
else |
| 21013 |
cost = in ? ix86_cost->hard_register.int_load[1] |
| 21014 |
: ix86_cost->hard_register.int_store[1]; |
| 21015 |
|
| 21016 |
if (mode == E_HFmode) |
| 21017 |
{ |
| 21018 |
/* Prefer SSE over GPR for HFmode. */ |
| 21019 |
int sse_cost; |
| 21020 |
int index = sse_store_index (mode); |
| 21021 |
if (in == 2) |
| 21022 |
sse_cost = MAX (ix86_cost->hard_register.sse_load[index], |
| 21023 |
ix86_cost->hard_register.sse_store[index]); |
| 21024 |
else |
| 21025 |
sse_cost = (in |
| 21026 |
? ix86_cost->hard_register.sse_load [index] |
| 21027 |
: ix86_cost->hard_register.sse_store [index]); |
| 21028 |
if (sse_cost >= cost) |
| 21029 |
cost = sse_cost + 1; |
| 21030 |
} |
| 21031 |
return cost; |
| 21032 |
} |
| 21033 |
default: |
| 21034 |
if (in == 2) |
| 21035 |
cost = MAX (ix86_cost->hard_register.int_load[2], |
| 21036 |
ix86_cost->hard_register.int_store[2]); |
| 21037 |
else if (in) |
| 21038 |
cost = ix86_cost->hard_register.int_load[2]; |
| 21039 |
else |
| 21040 |
cost = ix86_cost->hard_register.int_store[2]; |
| 21041 |
/* Multiply with the number of GPR moves needed. */ |
| 21042 |
return cost * CEIL ((int) GET_MODE_SIZE (mode), UNITS_PER_WORD); |
| 21043 |
} |
| 21044 |
} |
| 21045 |
|
| 21046 |
static int |
| 21047 |
ix86_memory_move_cost (machine_mode mode, reg_class_t regclass, bool in) |
| 21048 |
{ |
| 21049 |
return inline_memory_move_cost (mode, (enum reg_class) regclass, in ? 1 : 0); |
| 21050 |
} |
| 21051 |
|
| 21052 |
|
| 21053 |
/* Return the cost of moving data from a register in class CLASS1 to |
| 21054 |
one in class CLASS2. |
| 21055 |
|
| 21056 |
It is not required that the cost always equal 2 when FROM is the same as TO; |
| 21057 |
on some machines it is expensive to move between registers if they are not |
| 21058 |
general registers. */ |
| 21059 |
|
| 21060 |
static int |
| 21061 |
ix86_register_move_cost (machine_mode mode, reg_class_t class1_i, |
| 21062 |
reg_class_t class2_i) |
| 21063 |
{ |
| 21064 |
enum reg_class class1 = (enum reg_class) class1_i; |
| 21065 |
enum reg_class class2 = (enum reg_class) class2_i; |
| 21066 |
|
| 21067 |
/* In case we require secondary memory, compute cost of the store followed |
| 21068 |
by load. In order to avoid bad register allocation choices, we need |
| 21069 |
for this to be *at least* as high as the symmetric MEMORY_MOVE_COST. */ |
| 21070 |
|
| 21071 |
if (inline_secondary_memory_needed (mode, class1, class2, false)) |
| 21072 |
{ |
| 21073 |
int cost = 1; |
| 21074 |
|
| 21075 |
cost += inline_memory_move_cost (mode, class1, 2); |
| 21076 |
cost += inline_memory_move_cost (mode, class2, 2); |
| 21077 |
|
| 21078 |
/* In case of copying from general_purpose_register we may emit multiple |
| 21079 |
stores followed by single load causing memory size mismatch stall. |
| 21080 |
Count this as arbitrarily high cost of 20. */ |
| 21081 |
if (GET_MODE_BITSIZE (mode) > BITS_PER_WORD |
| 21082 |
&& TARGET_MEMORY_MISMATCH_STALL |
| 21083 |
&& targetm.class_max_nregs (class1, mode) |
| 21084 |
> targetm.class_max_nregs (class2, mode)) |
| 21085 |
cost += 20; |
| 21086 |
|
| 21087 |
/* In the case of FP/MMX moves, the registers actually overlap, and we |
| 21088 |
have to switch modes in order to treat them differently. */ |
| 21089 |
if ((MMX_CLASS_P (class1) && MAYBE_FLOAT_CLASS_P (class2)) |
| 21090 |
|| (MMX_CLASS_P (class2) && MAYBE_FLOAT_CLASS_P (class1))) |
| 21091 |
cost += 20; |
| 21092 |
|
| 21093 |
return cost; |
| 21094 |
} |
| 21095 |
|
| 21096 |
/* Moves between MMX and non-MMX units require secondary memory. */ |
| 21097 |
if (MMX_CLASS_P (class1) != MMX_CLASS_P (class2)) |
| 21098 |
gcc_unreachable (); |
| 21099 |
|
| 21100 |
if (SSE_CLASS_P (class1) != SSE_CLASS_P (class2)) |
| 21101 |
return (SSE_CLASS_P (class1) |
| 21102 |
? ix86_cost->hard_register.sse_to_integer |
| 21103 |
: ix86_cost->hard_register.integer_to_sse); |
| 21104 |
|
| 21105 |
/* Moves between mask register and GPR. */ |
| 21106 |
if (MASK_CLASS_P (class1) != MASK_CLASS_P (class2)) |
| 21107 |
{ |
| 21108 |
return (MASK_CLASS_P (class1) |
| 21109 |
? ix86_cost->hard_register.mask_to_integer |
| 21110 |
: ix86_cost->hard_register.integer_to_mask); |
| 21111 |
} |
| 21112 |
/* Moving between mask registers. */ |
| 21113 |
if (MASK_CLASS_P (class1) && MASK_CLASS_P (class2)) |
| 21114 |
return ix86_cost->hard_register.mask_move; |
| 21115 |
|
| 21116 |
if (MAYBE_FLOAT_CLASS_P (class1)) |
| 21117 |
return ix86_cost->hard_register.fp_move; |
| 21118 |
if (MAYBE_SSE_CLASS_P (class1)) |
| 21119 |
{ |
| 21120 |
if (GET_MODE_BITSIZE (mode) <= 128) |
| 21121 |
return ix86_cost->hard_register.xmm_move; |
| 21122 |
if (GET_MODE_BITSIZE (mode) <= 256) |
| 21123 |
return ix86_cost->hard_register.ymm_move; |
| 21124 |
return ix86_cost->hard_register.zmm_move; |
| 21125 |
} |
| 21126 |
if (MAYBE_MMX_CLASS_P (class1)) |
| 21127 |
return ix86_cost->hard_register.mmx_move; |
| 21128 |
return 2; |
| 21129 |
} |
| 21130 |
|
| 21131 |
/* Implement TARGET_HARD_REGNO_NREGS. This is ordinarily the length in |
| 21132 |
words of a value of mode MODE but can be less for certain modes in |
| 21133 |
special long registers. |
| 21134 |
|
| 21135 |
Actually there are no two word move instructions for consecutive |
| 21136 |
registers. And only registers 0-3 may have mov byte instructions |
| 21137 |
applied to them. */ |
| 21138 |
|
| 21139 |
static unsigned int |
| 21140 |
ix86_hard_regno_nregs (unsigned int regno, machine_mode mode) |
| 21141 |
{ |
| 21142 |
if (GENERAL_REGNO_P (regno)) |
| 21143 |
{ |
| 21144 |
if (mode == XFmode) |
| 21145 |
return TARGET_64BIT ? 2 : 3; |
| 21146 |
if (mode == XCmode) |
| 21147 |
return TARGET_64BIT ? 4 : 6; |
| 21148 |
return CEIL (GET_MODE_SIZE (mode), UNITS_PER_WORD); |
| 21149 |
} |
| 21150 |
if (COMPLEX_MODE_P (mode)) |
| 21151 |
return 2; |
| 21152 |
/* Register pair for mask registers. */ |
| 21153 |
if (mode == P2QImode || mode == P2HImode) |
| 21154 |
return 2; |
| 21155 |
if (mode == V64SFmode || mode == V64SImode) |
| 21156 |
return 4; |
| 21157 |
return 1; |
| 21158 |
} |
| 21159 |
|
| 21160 |
/* Implement REGMODE_NATURAL_SIZE(MODE). */ |
| 21161 |
unsigned int |
| 21162 |
ix86_regmode_natural_size (machine_mode mode) |
| 21163 |
{ |
| 21164 |
if (mode == P2HImode || mode == P2QImode) |
| 21165 |
return GET_MODE_SIZE (mode) / 2; |
| 21166 |
return UNITS_PER_WORD; |
| 21167 |
} |
| 21168 |
|
| 21169 |
/* Implement TARGET_HARD_REGNO_MODE_OK. */ |
| 21170 |
|
| 21171 |
static bool |
| 21172 |
ix86_hard_regno_mode_ok (unsigned int regno, machine_mode mode) |
| 21173 |
{ |
| 21174 |
/* Flags and only flags can only hold CCmode values. */ |
| 21175 |
if (CC_REGNO_P (regno)) |
| 21176 |
return GET_MODE_CLASS (mode) == MODE_CC; |
| 21177 |
if (GET_MODE_CLASS (mode) == MODE_CC |
| 21178 |
|| GET_MODE_CLASS (mode) == MODE_RANDOM) |
| 21179 |
return false; |
| 21180 |
if (STACK_REGNO_P (regno)) |
| 21181 |
return VALID_FP_MODE_P (mode); |
| 21182 |
if (MASK_REGNO_P (regno)) |
| 21183 |
{ |
| 21184 |
/* Register pair only starts at even register number. */ |
| 21185 |
if ((mode == P2QImode || mode == P2HImode)) |
| 21186 |
return MASK_PAIR_REGNO_P(regno); |
| 21187 |
|
| 21188 |
return ((TARGET_AVX512F && VALID_MASK_REG_MODE (mode)) |
| 21189 |
|| (TARGET_AVX512BW && VALID_MASK_AVX512BW_MODE (mode))); |
| 21190 |
} |
| 21191 |
|
| 21192 |
if (GET_MODE_CLASS (mode) == MODE_PARTIAL_INT) |
| 21193 |
return false; |
| 21194 |
|
| 21195 |
if (SSE_REGNO_P (regno)) |
| 21196 |
{ |
| 21197 |
/* We implement the move patterns for all vector modes into and |
| 21198 |
out of SSE registers, even when no operation instructions |
| 21199 |
are available. */ |
| 21200 |
|
| 21201 |
/* For AVX-512 we allow, regardless of regno: |
| 21202 |
- XI mode |
| 21203 |
- any of 512-bit wide vector mode |
| 21204 |
- any scalar mode. */ |
| 21205 |
if (TARGET_AVX512F |
| 21206 |
&& ((VALID_AVX512F_REG_OR_XI_MODE (mode) && TARGET_EVEX512) |
| 21207 |
|| VALID_AVX512F_SCALAR_MODE (mode))) |
| 21208 |
return true; |
| 21209 |
|
| 21210 |
/* TODO check for QI/HI scalars. */ |
| 21211 |
/* AVX512VL allows sse regs16+ for 128/256 bit modes. */ |
| 21212 |
if (TARGET_AVX512VL |
| 21213 |
&& (VALID_AVX256_REG_OR_OI_MODE (mode) |
| 21214 |
|| VALID_AVX512VL_128_REG_MODE (mode))) |
| 21215 |
return true; |
| 21216 |
|
| 21217 |
/* xmm16-xmm31 are only available for AVX-512. */ |
| 21218 |
if (EXT_REX_SSE_REGNO_P (regno)) |
| 21219 |
return false; |
| 21220 |
|
| 21221 |
/* OImode and AVX modes are available only when AVX is enabled. */ |
| 21222 |
return ((TARGET_AVX |
| 21223 |
&& VALID_AVX256_REG_OR_OI_MODE (mode)) |
| 21224 |
|| VALID_SSE_REG_MODE (mode) |
| 21225 |
|| VALID_SSE2_REG_MODE (mode) |
| 21226 |
|| VALID_MMX_REG_MODE (mode) |
| 21227 |
|| VALID_MMX_REG_MODE_3DNOW (mode)); |
| 21228 |
} |
| 21229 |
if (MMX_REGNO_P (regno)) |
| 21230 |
{ |
| 21231 |
/* We implement the move patterns for 3DNOW modes even in MMX mode, |
| 21232 |
so if the register is available at all, then we can move data of |
| 21233 |
the given mode into or out of it. */ |
| 21234 |
return (VALID_MMX_REG_MODE (mode) |
| 21235 |
|| VALID_MMX_REG_MODE_3DNOW (mode)); |
| 21236 |
} |
| 21237 |
|
| 21238 |
if (mode == QImode) |
| 21239 |
{ |
| 21240 |
/* Take care for QImode values - they can be in non-QI regs, |
| 21241 |
but then they do cause partial register stalls. */ |
| 21242 |
if (ANY_QI_REGNO_P (regno)) |
| 21243 |
return true; |
| 21244 |
if (!TARGET_PARTIAL_REG_STALL) |
| 21245 |
return true; |
| 21246 |
/* LRA checks if the hard register is OK for the given mode. |
| 21247 |
QImode values can live in non-QI regs, so we allow all |
| 21248 |
registers here. */ |
| 21249 |
if (lra_in_progress) |
| 21250 |
return true; |
| 21251 |
return !can_create_pseudo_p (); |
| 21252 |
} |
| 21253 |
/* We handle both integer and floats in the general purpose registers. */ |
| 21254 |
else if (VALID_INT_MODE_P (mode) |
| 21255 |
|| VALID_FP_MODE_P (mode)) |
| 21256 |
return true; |
| 21257 |
/* Lots of MMX code casts 8 byte vector modes to DImode. If we then go |
| 21258 |
on to use that value in smaller contexts, this can easily force a |
| 21259 |
pseudo to be allocated to GENERAL_REGS. Since this is no worse than |
| 21260 |
supporting DImode, allow it. */ |
| 21261 |
else if (VALID_MMX_REG_MODE_3DNOW (mode) || VALID_MMX_REG_MODE (mode)) |
| 21262 |
return true; |
| 21263 |
|
| 21264 |
return false; |
| 21265 |
} |
| 21266 |
|
| 21267 |
/* Implement TARGET_INSN_CALLEE_ABI. */ |
| 21268 |
|
| 21269 |
const predefined_function_abi & |
| 21270 |
ix86_insn_callee_abi (const rtx_insn *insn) |
| 21271 |
{ |
| 21272 |
unsigned int abi_id = 0; |
| 21273 |
rtx pat = PATTERN (insn); |
| 21274 |
if (vzeroupper_pattern (pat, VOIDmode)) |
| 21275 |
abi_id = ABI_VZEROUPPER; |
| 21276 |
|
| 21277 |
return function_abis[abi_id]; |
| 21278 |
} |
| 21279 |
|
| 21280 |
/* Initialize function_abis with corresponding abi_id, |
| 21281 |
currently only handle vzeroupper. */ |
| 21282 |
void |
| 21283 |
ix86_initialize_callee_abi (unsigned int abi_id) |
| 21284 |
{ |
| 21285 |
gcc_assert (abi_id == ABI_VZEROUPPER); |
| 21286 |
predefined_function_abi &vzeroupper_abi = function_abis[abi_id]; |
| 21287 |
if (!vzeroupper_abi.initialized_p ()) |
| 21288 |
{ |
| 21289 |
HARD_REG_SET full_reg_clobbers; |
| 21290 |
CLEAR_HARD_REG_SET (full_reg_clobbers); |
| 21291 |
vzeroupper_abi.initialize (ABI_VZEROUPPER, full_reg_clobbers); |
| 21292 |
} |
| 21293 |
} |
| 21294 |
|
| 21295 |
void |
| 21296 |
ix86_expand_avx_vzeroupper (void) |
| 21297 |
{ |
| 21298 |
/* Initialize vzeroupper_abi here. */ |
| 21299 |
ix86_initialize_callee_abi (ABI_VZEROUPPER); |
| 21300 |
rtx_insn *insn = emit_call_insn (gen_avx_vzeroupper_callee_abi ()); |
| 21301 |
/* Return false for non-local goto in can_nonlocal_goto. */ |
| 21302 |
make_reg_eh_region_note (insn, 0, INT_MIN); |
| 21303 |
/* Flag used for call_insn indicates it's a fake call. */ |
| 21304 |
RTX_FLAG (insn, used) = 1; |
| 21305 |
} |
| 21306 |
|
| 21307 |
|
| 21308 |
/* Implement TARGET_HARD_REGNO_CALL_PART_CLOBBERED. The only ABI that |
| 21309 |
saves SSE registers across calls is Win64 (thus no need to check the |
| 21310 |
current ABI here), and with AVX enabled Win64 only guarantees that |
| 21311 |
the low 16 bytes are saved. */ |
| 21312 |
|
| 21313 |
static bool |
| 21314 |
ix86_hard_regno_call_part_clobbered (unsigned int abi_id, unsigned int regno, |
| 21315 |
machine_mode mode) |
| 21316 |
{ |
| 21317 |
/* Special ABI for vzeroupper which only clobber higher part of sse regs. */ |
| 21318 |
if (abi_id == ABI_VZEROUPPER) |
| 21319 |
return (GET_MODE_SIZE (mode) > 16 |
| 21320 |
&& ((TARGET_64BIT && REX_SSE_REGNO_P (regno)) |
| 21321 |
|| LEGACY_SSE_REGNO_P (regno))); |
| 21322 |
|
| 21323 |
return SSE_REGNO_P (regno) && GET_MODE_SIZE (mode) > 16; |
| 21324 |
} |
| 21325 |
|
| 21326 |
/* A subroutine of ix86_modes_tieable_p. Return true if MODE is a |
| 21327 |
tieable integer mode. */ |
| 21328 |
|
| 21329 |
static bool |
| 21330 |
ix86_tieable_integer_mode_p (machine_mode mode) |
| 21331 |
{ |
| 21332 |
switch (mode) |
| 21333 |
{ |
| 21334 |
case E_HImode: |
| 21335 |
case E_SImode: |
| 21336 |
return true; |
| 21337 |
|
| 21338 |
case E_QImode: |
| 21339 |
return TARGET_64BIT || !TARGET_PARTIAL_REG_STALL; |
| 21340 |
|
| 21341 |
case E_DImode: |
| 21342 |
return TARGET_64BIT; |
| 21343 |
|
| 21344 |
default: |
| 21345 |
return false; |
| 21346 |
} |
| 21347 |
} |
| 21348 |
|
| 21349 |
/* Implement TARGET_MODES_TIEABLE_P. |
| 21350 |
|
| 21351 |
Return true if MODE1 is accessible in a register that can hold MODE2 |
| 21352 |
without copying. That is, all register classes that can hold MODE2 |
| 21353 |
can also hold MODE1. */ |
| 21354 |
|
| 21355 |
static bool |
| 21356 |
ix86_modes_tieable_p (machine_mode mode1, machine_mode mode2) |
| 21357 |
{ |
| 21358 |
if (mode1 == mode2) |
| 21359 |
return true; |
| 21360 |
|
| 21361 |
if (ix86_tieable_integer_mode_p (mode1) |
| 21362 |
&& ix86_tieable_integer_mode_p (mode2)) |
| 21363 |
return true; |
| 21364 |
|
| 21365 |
/* MODE2 being XFmode implies fp stack or general regs, which means we |
| 21366 |
can tie any smaller floating point modes to it. Note that we do not |
| 21367 |
tie this with TFmode. */ |
| 21368 |
if (mode2 == XFmode) |
| 21369 |
return mode1 == SFmode || mode1 == DFmode; |
| 21370 |
|
| 21371 |
/* MODE2 being DFmode implies fp stack, general or sse regs, which means |
| 21372 |
that we can tie it with SFmode. */ |
| 21373 |
if (mode2 == DFmode) |
| 21374 |
return mode1 == SFmode; |
| 21375 |
|
| 21376 |
/* If MODE2 is only appropriate for an SSE register, then tie with |
| 21377 |
any other mode acceptable to SSE registers. */ |
| 21378 |
if (GET_MODE_SIZE (mode2) == 64 |
| 21379 |
&& ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode2)) |
| 21380 |
return (GET_MODE_SIZE (mode1) == 64 |
| 21381 |
&& ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode1)); |
| 21382 |
if (GET_MODE_SIZE (mode2) == 32 |
| 21383 |
&& ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode2)) |
| 21384 |
return (GET_MODE_SIZE (mode1) == 32 |
| 21385 |
&& ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode1)); |
| 21386 |
if (GET_MODE_SIZE (mode2) == 16 |
| 21387 |
&& ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode2)) |
| 21388 |
return (GET_MODE_SIZE (mode1) == 16 |
| 21389 |
&& ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode1)); |
| 21390 |
|
| 21391 |
/* If MODE2 is appropriate for an MMX register, then tie |
| 21392 |
with any other mode acceptable to MMX registers. */ |
| 21393 |
if (GET_MODE_SIZE (mode2) == 8 |
| 21394 |
&& ix86_hard_regno_mode_ok (FIRST_MMX_REG, mode2)) |
| 21395 |
return (GET_MODE_SIZE (mode1) == 8 |
| 21396 |
&& ix86_hard_regno_mode_ok (FIRST_MMX_REG, mode1)); |
| 21397 |
|
| 21398 |
/* SCmode and DImode can be tied. */ |
| 21399 |
if ((mode1 == E_SCmode && mode2 == E_DImode) |
| 21400 |
|| (mode1 == E_DImode && mode2 == E_SCmode)) |
| 21401 |
return TARGET_64BIT; |
| 21402 |
|
| 21403 |
/* [SD]Cmode and V2[SD]Fmode modes can be tied. */ |
| 21404 |
if ((mode1 == E_SCmode && mode2 == E_V2SFmode) |
| 21405 |
|| (mode1 == E_V2SFmode && mode2 == E_SCmode) |
| 21406 |
|| (mode1 == E_DCmode && mode2 == E_V2DFmode) |
| 21407 |
|| (mode1 == E_V2DFmode && mode2 == E_DCmode)) |
| 21408 |
return true; |
| 21409 |
|
| 21410 |
return false; |
| 21411 |
} |
| 21412 |
|
| 21413 |
/* Return the cost of moving between two registers of mode MODE. */ |
| 21414 |
|
| 21415 |
static int |
| 21416 |
ix86_set_reg_reg_cost (machine_mode mode) |
| 21417 |
{ |
| 21418 |
unsigned int units = UNITS_PER_WORD; |
| 21419 |
|
| 21420 |
switch (GET_MODE_CLASS (mode)) |
| 21421 |
{ |
| 21422 |
default: |
| 21423 |
break; |
| 21424 |
|
| 21425 |
case MODE_CC: |
| 21426 |
units = GET_MODE_SIZE (CCmode); |
| 21427 |
break; |
| 21428 |
|
| 21429 |
case MODE_FLOAT: |
| 21430 |
if ((TARGET_SSE && mode == TFmode) |
| 21431 |
|| (TARGET_80387 && mode == XFmode) |
| 21432 |
|| ((TARGET_80387 || TARGET_SSE2) && mode == DFmode) |
| 21433 |
|| ((TARGET_80387 || TARGET_SSE) && mode == SFmode)) |
| 21434 |
units = GET_MODE_SIZE (mode); |
| 21435 |
break; |
| 21436 |
|
| 21437 |
case MODE_COMPLEX_FLOAT: |
| 21438 |
if ((TARGET_SSE && mode == TCmode) |
| 21439 |
|| (TARGET_80387 && mode == XCmode) |
| 21440 |
|| ((TARGET_80387 || TARGET_SSE2) && mode == DCmode) |
| 21441 |
|| ((TARGET_80387 || TARGET_SSE) && mode == SCmode)) |
| 21442 |
units = GET_MODE_SIZE (mode); |
| 21443 |
break; |
| 21444 |
|
| 21445 |
case MODE_VECTOR_INT: |
| 21446 |
case MODE_VECTOR_FLOAT: |
| 21447 |
if ((TARGET_AVX512F && TARGET_EVEX512 && VALID_AVX512F_REG_MODE (mode)) |
| 21448 |
|| (TARGET_AVX && VALID_AVX256_REG_MODE (mode)) |
| 21449 |
|| (TARGET_SSE2 && VALID_SSE2_REG_MODE (mode)) |
| 21450 |
|| (TARGET_SSE && VALID_SSE_REG_MODE (mode)) |
| 21451 |
|| ((TARGET_MMX || TARGET_MMX_WITH_SSE) |
| 21452 |
&& VALID_MMX_REG_MODE (mode))) |
| 21453 |
units = GET_MODE_SIZE (mode); |
| 21454 |
} |
| 21455 |
|
| 21456 |
/* Return the cost of moving between two registers of mode MODE, |
| 21457 |
assuming that the move will be in pieces of at most UNITS bytes. */ |
| 21458 |
return COSTS_N_INSNS (CEIL (GET_MODE_SIZE (mode), units)); |
| 21459 |
} |
| 21460 |
|
| 21461 |
/* Return cost of vector operation in MODE given that scalar version has |
| 21462 |
COST. */ |
| 21463 |
|
| 21464 |
static int |
| 21465 |
ix86_vec_cost (machine_mode mode, int cost) |
| 21466 |
{ |
| 21467 |
if (!VECTOR_MODE_P (mode)) |
| 21468 |
return cost; |
| 21469 |
|
| 21470 |
if (GET_MODE_BITSIZE (mode) == 128 |
| 21471 |
&& TARGET_SSE_SPLIT_REGS) |
| 21472 |
return cost * GET_MODE_BITSIZE (mode) / 64; |
| 21473 |
else if (GET_MODE_BITSIZE (mode) > 128 |
| 21474 |
&& TARGET_AVX256_SPLIT_REGS) |
| 21475 |
return cost * GET_MODE_BITSIZE (mode) / 128; |
| 21476 |
else if (GET_MODE_BITSIZE (mode) > 256 |
| 21477 |
&& TARGET_AVX512_SPLIT_REGS) |
| 21478 |
return cost * GET_MODE_BITSIZE (mode) / 256; |
| 21479 |
return cost; |
| 21480 |
} |
| 21481 |
|
| 21482 |
/* Return cost of vec_widen_<s>mult_hi/lo_<mode>, |
| 21483 |
vec_widen_<s>mul_hi/lo_<mode> is only available for VI124_AVX2. */ |
| 21484 |
static int |
| 21485 |
ix86_widen_mult_cost (const struct processor_costs *cost, |
| 21486 |
enum machine_mode mode, bool uns_p) |
| 21487 |
{ |
| 21488 |
gcc_assert (GET_MODE_CLASS (mode) == MODE_VECTOR_INT); |
| 21489 |
int extra_cost = 0; |
| 21490 |
int basic_cost = 0; |
| 21491 |
switch (mode) |
| 21492 |
{ |
| 21493 |
case V8HImode: |
| 21494 |
case V16HImode: |
| 21495 |
if (!uns_p || mode == V16HImode) |
| 21496 |
extra_cost = cost->sse_op * 2; |
| 21497 |
basic_cost = cost->mulss * 2 + cost->sse_op * 4; |
| 21498 |
break; |
| 21499 |
case V4SImode: |
| 21500 |
case V8SImode: |
| 21501 |
/* pmulhw/pmullw can be used. */ |
| 21502 |
basic_cost = cost->mulss * 2 + cost->sse_op * 2; |
| 21503 |
break; |
| 21504 |
case V2DImode: |
| 21505 |
/* pmuludq under sse2, pmuldq under sse4.1, for sign_extend, |
| 21506 |
require extra 4 mul, 4 add, 4 cmp and 2 shift. */ |
| 21507 |
if (!TARGET_SSE4_1 && !uns_p) |
| 21508 |
extra_cost = (cost->mulss + cost->addss + cost->sse_op) * 4 |
| 21509 |
+ cost->sse_op * 2; |
| 21510 |
/* Fallthru. */ |
| 21511 |
case V4DImode: |
| 21512 |
basic_cost = cost->mulss * 2 + cost->sse_op * 4; |
| 21513 |
break; |
| 21514 |
default: |
| 21515 |
/* Not implemented. */ |
| 21516 |
return 100; |
| 21517 |
} |
| 21518 |
return ix86_vec_cost (mode, basic_cost + extra_cost); |
| 21519 |
} |
| 21520 |
|
| 21521 |
/* Return cost of multiplication in MODE. */ |
| 21522 |
|
| 21523 |
static int |
| 21524 |
ix86_multiplication_cost (const struct processor_costs *cost, |
| 21525 |
enum machine_mode mode) |
| 21526 |
{ |
| 21527 |
machine_mode inner_mode = mode; |
| 21528 |
if (VECTOR_MODE_P (mode)) |
| 21529 |
inner_mode = GET_MODE_INNER (mode); |
| 21530 |
|
| 21531 |
if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode)) |
| 21532 |
return inner_mode == DFmode ? cost->mulsd : cost->mulss; |
| 21533 |
else if (X87_FLOAT_MODE_P (mode)) |
| 21534 |
return cost->fmul; |
| 21535 |
else if (FLOAT_MODE_P (mode)) |
| 21536 |
return ix86_vec_cost (mode, |
| 21537 |
inner_mode == DFmode ? cost->mulsd : cost->mulss); |
| 21538 |
else if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT) |
| 21539 |
{ |
| 21540 |
int nmults, nops; |
| 21541 |
/* Cost of reading the memory. */ |
| 21542 |
int extra; |
| 21543 |
|
| 21544 |
switch (mode) |
| 21545 |
{ |
| 21546 |
case V4QImode: |
| 21547 |
case V8QImode: |
| 21548 |
/* Partial V*QImode is emulated with 4-6 insns. */ |
| 21549 |
nmults = 1; |
| 21550 |
nops = 3; |
| 21551 |
extra = 0; |
| 21552 |
|
| 21553 |
if (TARGET_AVX512BW && TARGET_AVX512VL) |
| 21554 |
; |
| 21555 |
else if (TARGET_AVX2) |
| 21556 |
nops += 2; |
| 21557 |
else if (TARGET_XOP) |
| 21558 |
extra += cost->sse_load[2]; |
| 21559 |
else |
| 21560 |
{ |
| 21561 |
nops += 1; |
| 21562 |
extra += cost->sse_load[2]; |
| 21563 |
} |
| 21564 |
goto do_qimode; |
| 21565 |
|
| 21566 |
case V16QImode: |
| 21567 |
/* V*QImode is emulated with 4-11 insns. */ |
| 21568 |
nmults = 1; |
| 21569 |
nops = 3; |
| 21570 |
extra = 0; |
| 21571 |
|
| 21572 |
if (TARGET_AVX2 && !TARGET_PREFER_AVX128) |
| 21573 |
{ |
| 21574 |
if (!(TARGET_AVX512BW && TARGET_AVX512VL)) |
| 21575 |
nops += 3; |
| 21576 |
} |
| 21577 |
else if (TARGET_XOP) |
| 21578 |
{ |
| 21579 |
nmults += 1; |
| 21580 |
nops += 2; |
| 21581 |
extra += cost->sse_load[2]; |
| 21582 |
} |
| 21583 |
else |
| 21584 |
{ |
| 21585 |
nmults += 1; |
| 21586 |
nops += 4; |
| 21587 |
extra += cost->sse_load[2]; |
| 21588 |
} |
| 21589 |
goto do_qimode; |
| 21590 |
|
| 21591 |
case V32QImode: |
| 21592 |
nmults = 1; |
| 21593 |
nops = 3; |
| 21594 |
extra = 0; |
| 21595 |
|
| 21596 |
if (!TARGET_AVX512BW || TARGET_PREFER_AVX256) |
| 21597 |
{ |
| 21598 |
nmults += 1; |
| 21599 |
nops += 4; |
| 21600 |
extra += cost->sse_load[3] * 2; |
| 21601 |
} |
| 21602 |
goto do_qimode; |
| 21603 |
|
| 21604 |
case V64QImode: |
| 21605 |
nmults = 2; |
| 21606 |
nops = 9; |
| 21607 |
extra = cost->sse_load[3] * 2 + cost->sse_load[4] * 2; |
| 21608 |
|
| 21609 |
do_qimode: |
| 21610 |
return ix86_vec_cost (mode, cost->mulss * nmults |
| 21611 |
+ cost->sse_op * nops) + extra; |
| 21612 |
|
| 21613 |
case V4SImode: |
| 21614 |
/* pmulld is used in this case. No emulation is needed. */ |
| 21615 |
if (TARGET_SSE4_1) |
| 21616 |
goto do_native; |
| 21617 |
/* V4SImode is emulated with 7 insns. */ |
| 21618 |
else |
| 21619 |
return ix86_vec_cost (mode, cost->mulss * 2 + cost->sse_op * 5); |
| 21620 |
|
| 21621 |
case V2DImode: |
| 21622 |
case V4DImode: |
| 21623 |
/* vpmullq is used in this case. No emulation is needed. */ |
| 21624 |
if (TARGET_AVX512DQ && TARGET_AVX512VL) |
| 21625 |
goto do_native; |
| 21626 |
/* V*DImode is emulated with 6-8 insns. */ |
| 21627 |
else if (TARGET_XOP && mode == V2DImode) |
| 21628 |
return ix86_vec_cost (mode, cost->mulss * 2 + cost->sse_op * 4); |
| 21629 |
/* FALLTHRU */ |
| 21630 |
case V8DImode: |
| 21631 |
/* vpmullq is used in this case. No emulation is needed. */ |
| 21632 |
if (TARGET_AVX512DQ && mode == V8DImode) |
| 21633 |
goto do_native; |
| 21634 |
else |
| 21635 |
return ix86_vec_cost (mode, cost->mulss * 3 + cost->sse_op * 5); |
| 21636 |
|
| 21637 |
default: |
| 21638 |
do_native: |
| 21639 |
return ix86_vec_cost (mode, cost->mulss); |
| 21640 |
} |
| 21641 |
} |
| 21642 |
else |
| 21643 |
return (cost->mult_init[MODE_INDEX (mode)] + cost->mult_bit * 7); |
| 21644 |
} |
| 21645 |
|
| 21646 |
/* Return cost of multiplication in MODE. */ |
| 21647 |
|
| 21648 |
static int |
| 21649 |
ix86_division_cost (const struct processor_costs *cost, |
| 21650 |
enum machine_mode mode) |
| 21651 |
{ |
| 21652 |
machine_mode inner_mode = mode; |
| 21653 |
if (VECTOR_MODE_P (mode)) |
| 21654 |
inner_mode = GET_MODE_INNER (mode); |
| 21655 |
|
| 21656 |
if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode)) |
| 21657 |
return inner_mode == DFmode ? cost->divsd : cost->divss; |
| 21658 |
else if (X87_FLOAT_MODE_P (mode)) |
| 21659 |
return cost->fdiv; |
| 21660 |
else if (FLOAT_MODE_P (mode)) |
| 21661 |
return ix86_vec_cost (mode, |
| 21662 |
inner_mode == DFmode ? cost->divsd : cost->divss); |
| 21663 |
else |
| 21664 |
return cost->divide[MODE_INDEX (mode)]; |
| 21665 |
} |
| 21666 |
|
| 21667 |
/* Return cost of shift in MODE. |
| 21668 |
If CONSTANT_OP1 is true, the op1 value is known and set in OP1_VAL. |
| 21669 |
AND_IN_OP1 specify in op1 is result of AND and SHIFT_AND_TRUNCATE |
| 21670 |
if op1 is a result of subreg. |
| 21671 |
|
| 21672 |
SKIP_OP0/1 is set to true if cost of OP0/1 should be ignored. */ |
| 21673 |
|
| 21674 |
static int |
| 21675 |
ix86_shift_rotate_cost (const struct processor_costs *cost, |
| 21676 |
enum rtx_code code, |
| 21677 |
enum machine_mode mode, bool constant_op1, |
| 21678 |
HOST_WIDE_INT op1_val, |
| 21679 |
bool and_in_op1, |
| 21680 |
bool shift_and_truncate, |
| 21681 |
bool *skip_op0, bool *skip_op1) |
| 21682 |
{ |
| 21683 |
if (skip_op0) |
| 21684 |
*skip_op0 = *skip_op1 = false; |
| 21685 |
|
| 21686 |
if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT) |
| 21687 |
{ |
| 21688 |
int count; |
| 21689 |
/* Cost of reading the memory. */ |
| 21690 |
int extra; |
| 21691 |
|
| 21692 |
switch (mode) |
| 21693 |
{ |
| 21694 |
case V4QImode: |
| 21695 |
case V8QImode: |
| 21696 |
if (TARGET_AVX2) |
| 21697 |
/* Use vpbroadcast. */ |
| 21698 |
extra = cost->sse_op; |
| 21699 |
else |
| 21700 |
extra = cost->sse_load[2]; |
| 21701 |
|
| 21702 |
if (constant_op1) |
| 21703 |
{ |
| 21704 |
if (code == ASHIFTRT) |
| 21705 |
{ |
| 21706 |
count = 4; |
| 21707 |
extra *= 2; |
| 21708 |
} |
| 21709 |
else |
| 21710 |
count = 2; |
| 21711 |
} |
| 21712 |
else if (TARGET_AVX512BW && TARGET_AVX512VL) |
| 21713 |
return ix86_vec_cost (mode, cost->sse_op * 4); |
| 21714 |
else if (TARGET_SSE4_1) |
| 21715 |
count = 5; |
| 21716 |
else if (code == ASHIFTRT) |
| 21717 |
count = 6; |
| 21718 |
else |
| 21719 |
count = 5; |
| 21720 |
return ix86_vec_cost (mode, cost->sse_op * count) + extra; |
| 21721 |
|
| 21722 |
case V16QImode: |
| 21723 |
if (TARGET_XOP) |
| 21724 |
{ |
| 21725 |
/* For XOP we use vpshab, which requires a broadcast of the |
| 21726 |
value to the variable shift insn. For constants this |
| 21727 |
means a V16Q const in mem; even when we can perform the |
| 21728 |
shift with one insn set the cost to prefer paddb. */ |
| 21729 |
if (constant_op1) |
| 21730 |
{ |
| 21731 |
extra = cost->sse_load[2]; |
| 21732 |
return ix86_vec_cost (mode, cost->sse_op) + extra; |
| 21733 |
} |
| 21734 |
else |
| 21735 |
{ |
| 21736 |
count = (code == ASHIFT) ? 3 : 4; |
| 21737 |
return ix86_vec_cost (mode, cost->sse_op * count); |
| 21738 |
} |
| 21739 |
} |
| 21740 |
/* FALLTHRU */ |
| 21741 |
case V32QImode: |
| 21742 |
if (TARGET_AVX2) |
| 21743 |
/* Use vpbroadcast. */ |
| 21744 |
extra = cost->sse_op; |
| 21745 |
else |
| 21746 |
extra = (mode == V16QImode) ? cost->sse_load[2] : cost->sse_load[3]; |
| 21747 |
|
| 21748 |
if (constant_op1) |
| 21749 |
{ |
| 21750 |
if (code == ASHIFTRT) |
| 21751 |
{ |
| 21752 |
count = 4; |
| 21753 |
extra *= 2; |
| 21754 |
} |
| 21755 |
else |
| 21756 |
count = 2; |
| 21757 |
} |
| 21758 |
else if (TARGET_AVX512BW |
| 21759 |
&& ((mode == V32QImode && !TARGET_PREFER_AVX256) |
| 21760 |
|| (mode == V16QImode && TARGET_AVX512VL |
| 21761 |
&& !TARGET_PREFER_AVX128))) |
| 21762 |
return ix86_vec_cost (mode, cost->sse_op * 4); |
| 21763 |
else if (TARGET_AVX2 |
| 21764 |
&& mode == V16QImode && !TARGET_PREFER_AVX128) |
| 21765 |
count = 6; |
| 21766 |
else if (TARGET_SSE4_1) |
| 21767 |
count = 9; |
| 21768 |
else if (code == ASHIFTRT) |
| 21769 |
count = 10; |
| 21770 |
else |
| 21771 |
count = 9; |
| 21772 |
return ix86_vec_cost (mode, cost->sse_op * count) + extra; |
| 21773 |
|
| 21774 |
case V2DImode: |
| 21775 |
case V4DImode: |
| 21776 |
/* V*DImode arithmetic right shift is emulated. */ |
| 21777 |
if (code == ASHIFTRT && !TARGET_AVX512VL) |
| 21778 |
{ |
| 21779 |
if (constant_op1) |
| 21780 |
{ |
| 21781 |
if (op1_val == 63) |
| 21782 |
count = TARGET_SSE4_2 ? 1 : 2; |
| 21783 |
else if (TARGET_XOP) |
| 21784 |
count = 2; |
| 21785 |
else if (TARGET_SSE4_1) |
| 21786 |
count = 3; |
| 21787 |
else |
| 21788 |
count = 4; |
| 21789 |
} |
| 21790 |
else if (TARGET_XOP) |
| 21791 |
count = 3; |
| 21792 |
else if (TARGET_SSE4_2) |
| 21793 |
count = 4; |
| 21794 |
else |
| 21795 |
count = 5; |
| 21796 |
|
| 21797 |
return ix86_vec_cost (mode, cost->sse_op * count); |
| 21798 |
} |
| 21799 |
/* FALLTHRU */ |
| 21800 |
default: |
| 21801 |
return ix86_vec_cost (mode, cost->sse_op); |
| 21802 |
} |
| 21803 |
} |
| 21804 |
|
| 21805 |
if (GET_MODE_SIZE (mode) > UNITS_PER_WORD) |
| 21806 |
{ |
| 21807 |
if (constant_op1) |
| 21808 |
{ |
| 21809 |
if (op1_val > 32) |
| 21810 |
return cost->shift_const + COSTS_N_INSNS (2); |
| 21811 |
else |
| 21812 |
return cost->shift_const * 2; |
| 21813 |
} |
| 21814 |
else |
| 21815 |
{ |
| 21816 |
if (and_in_op1) |
| 21817 |
return cost->shift_var * 2; |
| 21818 |
else |
| 21819 |
return cost->shift_var * 6 + COSTS_N_INSNS (2); |
| 21820 |
} |
| 21821 |
} |
| 21822 |
else |
| 21823 |
{ |
| 21824 |
if (constant_op1) |
| 21825 |
return cost->shift_const; |
| 21826 |
else if (shift_and_truncate) |
| 21827 |
{ |
| 21828 |
if (skip_op0) |
| 21829 |
*skip_op0 = *skip_op1 = true; |
| 21830 |
/* Return the cost after shift-and truncation. */ |
| 21831 |
return cost->shift_var; |
| 21832 |
} |
| 21833 |
else |
| 21834 |
return cost->shift_var; |
| 21835 |
} |
| 21836 |
} |
| 21837 |
|
| 21838 |
static int |
| 21839 |
ix86_insn_cost (rtx_insn *insn, bool speed) |
| 21840 |
{ |
| 21841 |
int insn_cost = 0; |
| 21842 |
/* Add extra cost to avoid post_reload late_combine revert |
| 21843 |
the optimization did in pass_rpad. */ |
| 21844 |
if (reload_completed |
| 21845 |
&& ix86_rpad_gate () |
| 21846 |
&& recog_memoized (insn) >= 0 |
| 21847 |
&& get_attr_avx_partial_xmm_update (insn) |
| 21848 |
== AVX_PARTIAL_XMM_UPDATE_TRUE) |
| 21849 |
insn_cost += COSTS_N_INSNS (3); |
| 21850 |
|
| 21851 |
return insn_cost + pattern_cost (PATTERN (insn), speed); |
| 21852 |
} |
| 21853 |
|
| 21854 |
/* Compute a (partial) cost for rtx X. Return true if the complete |
| 21855 |
cost has been computed, and false if subexpressions should be |
| 21856 |
scanned. In either case, *TOTAL contains the cost result. */ |
| 21857 |
|
| 21858 |
static bool |
| 21859 |
ix86_rtx_costs (rtx x, machine_mode mode, int outer_code_i, int opno, |
| 21860 |
int *total, bool speed) |
| 21861 |
{ |
| 21862 |
rtx mask; |
| 21863 |
enum rtx_code code = GET_CODE (x); |
| 21864 |
enum rtx_code outer_code = (enum rtx_code) outer_code_i; |
| 21865 |
const struct processor_costs *cost |
| 21866 |
= speed ? ix86_tune_cost : &ix86_size_cost; |
| 21867 |
int src_cost; |
| 21868 |
|
| 21869 |
/* Handling different vternlog variants. */ |
| 21870 |
if ((GET_MODE_SIZE (mode) == 64 |
| 21871 |
? (TARGET_AVX512F && TARGET_EVEX512) |
| 21872 |
: (TARGET_AVX512VL |
| 21873 |
|| (TARGET_AVX512F && TARGET_EVEX512 && !TARGET_PREFER_AVX256))) |
| 21874 |
&& GET_MODE_SIZE (mode) >= 16 |
| 21875 |
&& outer_code_i == SET |
| 21876 |
&& ternlog_operand (x, mode)) |
| 21877 |
{ |
| 21878 |
rtx args[3]; |
| 21879 |
|
| 21880 |
args[0] = NULL_RTX; |
| 21881 |
args[1] = NULL_RTX; |
| 21882 |
args[2] = NULL_RTX; |
| 21883 |
int idx = ix86_ternlog_idx (x, args); |
| 21884 |
gcc_assert (idx >= 0); |
| 21885 |
|
| 21886 |
*total = cost->sse_op; |
| 21887 |
for (int i = 0; i != 3; i++) |
| 21888 |
if (args[i]) |
| 21889 |
*total += rtx_cost (args[i], GET_MODE (args[i]), UNSPEC, i, speed); |
| 21890 |
return true; |
| 21891 |
} |
| 21892 |
|
| 21893 |
|
| 21894 |
switch (code) |
| 21895 |
{ |
| 21896 |
case SET: |
| 21897 |
if (register_operand (SET_DEST (x), VOIDmode) |
| 21898 |
&& register_operand (SET_SRC (x), VOIDmode)) |
| 21899 |
{ |
| 21900 |
*total = ix86_set_reg_reg_cost (GET_MODE (SET_DEST (x))); |
| 21901 |
return true; |
| 21902 |
} |
| 21903 |
|
| 21904 |
if (register_operand (SET_SRC (x), VOIDmode)) |
| 21905 |
/* Avoid potentially incorrect high cost from rtx_costs |
| 21906 |
for non-tieable SUBREGs. */ |
| 21907 |
src_cost = 0; |
| 21908 |
else |
| 21909 |
{ |
| 21910 |
src_cost = rtx_cost (SET_SRC (x), mode, SET, 1, speed); |
| 21911 |
|
| 21912 |
if (CONSTANT_P (SET_SRC (x))) |
| 21913 |
/* Constant costs assume a base value of COSTS_N_INSNS (1) and add |
| 21914 |
a small value, possibly zero for cheap constants. */ |
| 21915 |
src_cost += COSTS_N_INSNS (1); |
| 21916 |
} |
| 21917 |
|
| 21918 |
*total = src_cost + rtx_cost (SET_DEST (x), mode, SET, 0, speed); |
| 21919 |
return true; |
| 21920 |
|
| 21921 |
case CONST_INT: |
| 21922 |
case CONST: |
| 21923 |
case LABEL_REF: |
| 21924 |
case SYMBOL_REF: |
| 21925 |
if (x86_64_immediate_operand (x, VOIDmode)) |
| 21926 |
*total = 0; |
| 21927 |
else if (TARGET_64BIT && x86_64_zext_immediate_operand (x, VOIDmode)) |
| 21928 |
/* Consider the zext constants slightly more expensive, as they |
| 21929 |
can't appear in most instructions. */ |
| 21930 |
*total = 1; |
| 21931 |
else |
| 21932 |
/* movabsq is slightly more expensive than a simple instruction. */ |
| 21933 |
*total = COSTS_N_INSNS (1) + 1; |
| 21934 |
return true; |
| 21935 |
|
| 21936 |
case CONST_DOUBLE: |
| 21937 |
if (IS_STACK_MODE (mode)) |
| 21938 |
switch (standard_80387_constant_p (x)) |
| 21939 |
{ |
| 21940 |
case -1: |
| 21941 |
case 0: |
| 21942 |
break; |
| 21943 |
case 1: /* 0.0 */ |
| 21944 |
*total = 1; |
| 21945 |
return true; |
| 21946 |
default: /* Other constants */ |
| 21947 |
*total = 2; |
| 21948 |
return true; |
| 21949 |
} |
| 21950 |
/* FALLTHRU */ |
| 21951 |
|
| 21952 |
case CONST_VECTOR: |
| 21953 |
switch (standard_sse_constant_p (x, mode)) |
| 21954 |
{ |
| 21955 |
case 0: |
| 21956 |
break; |
| 21957 |
case 1: /* 0: xor eliminates false dependency */ |
| 21958 |
*total = 0; |
| 21959 |
return true; |
| 21960 |
default: /* -1: cmp contains false dependency */ |
| 21961 |
*total = 1; |
| 21962 |
return true; |
| 21963 |
} |
| 21964 |
/* FALLTHRU */ |
| 21965 |
|
| 21966 |
case CONST_WIDE_INT: |
| 21967 |
/* Fall back to (MEM (SYMBOL_REF)), since that's where |
| 21968 |
it'll probably end up. Add a penalty for size. */ |
| 21969 |
*total = (COSTS_N_INSNS (1) |
| 21970 |
+ (!TARGET_64BIT && flag_pic) |
| 21971 |
+ (GET_MODE_SIZE (mode) <= 4 |
| 21972 |
? 0 : GET_MODE_SIZE (mode) <= 8 ? 1 : 2)); |
| 21973 |
return true; |
| 21974 |
|
| 21975 |
case ZERO_EXTEND: |
| 21976 |
/* The zero extensions is often completely free on x86_64, so make |
| 21977 |
it as cheap as possible. */ |
| 21978 |
if (TARGET_64BIT && mode == DImode |
| 21979 |
&& GET_MODE (XEXP (x, 0)) == SImode) |
| 21980 |
*total = 1; |
| 21981 |
else if (TARGET_ZERO_EXTEND_WITH_AND) |
| 21982 |
*total = cost->add; |
| 21983 |
else |
| 21984 |
*total = cost->movzx; |
| 21985 |
return false; |
| 21986 |
|
| 21987 |
case SIGN_EXTEND: |
| 21988 |
*total = cost->movsx; |
| 21989 |
return false; |
| 21990 |
|
| 21991 |
case ASHIFT: |
| 21992 |
if (SCALAR_INT_MODE_P (mode) |
| 21993 |
&& GET_MODE_SIZE (mode) < UNITS_PER_WORD |
| 21994 |
&& CONST_INT_P (XEXP (x, 1))) |
| 21995 |
{ |
| 21996 |
HOST_WIDE_INT value = INTVAL (XEXP (x, 1)); |
| 21997 |
if (value == 1) |
| 21998 |
{ |
| 21999 |
*total = cost->add; |
| 22000 |
return false; |
| 22001 |
} |
| 22002 |
if ((value == 2 || value == 3) |
| 22003 |
&& cost->lea <= cost->shift_const) |
| 22004 |
{ |
| 22005 |
*total = cost->lea; |
| 22006 |
return false; |
| 22007 |
} |
| 22008 |
} |
| 22009 |
/* FALLTHRU */ |
| 22010 |
|
| 22011 |
case ROTATE: |
| 22012 |
case ASHIFTRT: |
| 22013 |
case LSHIFTRT: |
| 22014 |
case ROTATERT: |
| 22015 |
bool skip_op0, skip_op1; |
| 22016 |
*total = ix86_shift_rotate_cost (cost, code, mode, |
| 22017 |
CONSTANT_P (XEXP (x, 1)), |
| 22018 |
CONST_INT_P (XEXP (x, 1)) |
| 22019 |
? INTVAL (XEXP (x, 1)) : -1, |
| 22020 |
GET_CODE (XEXP (x, 1)) == AND, |
| 22021 |
SUBREG_P (XEXP (x, 1)) |
| 22022 |
&& GET_CODE (XEXP (XEXP (x, 1), |
| 22023 |
0)) == AND, |
| 22024 |
&skip_op0, &skip_op1); |
| 22025 |
if (skip_op0 || skip_op1) |
| 22026 |
{ |
| 22027 |
if (!skip_op0) |
| 22028 |
*total += rtx_cost (XEXP (x, 0), mode, code, 0, speed); |
| 22029 |
if (!skip_op1) |
| 22030 |
*total += rtx_cost (XEXP (x, 1), mode, code, 0, speed); |
| 22031 |
return true; |
| 22032 |
} |
| 22033 |
return false; |
| 22034 |
|
| 22035 |
case FMA: |
| 22036 |
{ |
| 22037 |
rtx sub; |
| 22038 |
|
| 22039 |
gcc_assert (FLOAT_MODE_P (mode)); |
| 22040 |
gcc_assert (TARGET_FMA || TARGET_FMA4 || TARGET_AVX512F); |
| 22041 |
|
| 22042 |
*total = ix86_vec_cost (mode, |
| 22043 |
GET_MODE_INNER (mode) == SFmode |
| 22044 |
? cost->fmass : cost->fmasd); |
| 22045 |
*total += rtx_cost (XEXP (x, 1), mode, FMA, 1, speed); |
| 22046 |
|
| 22047 |
/* Negate in op0 or op2 is free: FMS, FNMA, FNMS. */ |
| 22048 |
sub = XEXP (x, 0); |
| 22049 |
if (GET_CODE (sub) == NEG) |
| 22050 |
sub = XEXP (sub, 0); |
| 22051 |
*total += rtx_cost (sub, mode, FMA, 0, speed); |
| 22052 |
|
| 22053 |
sub = XEXP (x, 2); |
| 22054 |
if (GET_CODE (sub) == NEG) |
| 22055 |
sub = XEXP (sub, 0); |
| 22056 |
*total += rtx_cost (sub, mode, FMA, 2, speed); |
| 22057 |
return true; |
| 22058 |
} |
| 22059 |
|
| 22060 |
case MULT: |
| 22061 |
if (!FLOAT_MODE_P (mode) && !VECTOR_MODE_P (mode)) |
| 22062 |
{ |
| 22063 |
rtx op0 = XEXP (x, 0); |
| 22064 |
rtx op1 = XEXP (x, 1); |
| 22065 |
int nbits; |
| 22066 |
if (CONST_INT_P (XEXP (x, 1))) |
| 22067 |
{ |
| 22068 |
unsigned HOST_WIDE_INT value = INTVAL (XEXP (x, 1)); |
| 22069 |
for (nbits = 0; value != 0; value &= value - 1) |
| 22070 |
nbits++; |
| 22071 |
} |
| 22072 |
else |
| 22073 |
/* This is arbitrary. */ |
| 22074 |
nbits = 7; |
| 22075 |
|
| 22076 |
/* Compute costs correctly for widening multiplication. */ |
| 22077 |
if ((GET_CODE (op0) == SIGN_EXTEND || GET_CODE (op0) == ZERO_EXTEND) |
| 22078 |
&& GET_MODE_SIZE (GET_MODE (XEXP (op0, 0))) * 2 |
| 22079 |
== GET_MODE_SIZE (mode)) |
| 22080 |
{ |
| 22081 |
int is_mulwiden = 0; |
| 22082 |
machine_mode inner_mode = GET_MODE (op0); |
| 22083 |
|
| 22084 |
if (GET_CODE (op0) == GET_CODE (op1)) |
| 22085 |
is_mulwiden = 1, op1 = XEXP (op1, 0); |
| 22086 |
else if (CONST_INT_P (op1)) |
| 22087 |
{ |
| 22088 |
if (GET_CODE (op0) == SIGN_EXTEND) |
| 22089 |
is_mulwiden = trunc_int_for_mode (INTVAL (op1), inner_mode) |
| 22090 |
== INTVAL (op1); |
| 22091 |
else |
| 22092 |
is_mulwiden = !(INTVAL (op1) & ~GET_MODE_MASK (inner_mode)); |
| 22093 |
} |
| 22094 |
|
| 22095 |
if (is_mulwiden) |
| 22096 |
op0 = XEXP (op0, 0), mode = GET_MODE (op0); |
| 22097 |
} |
| 22098 |
|
| 22099 |
int mult_init; |
| 22100 |
// Double word multiplication requires 3 mults and 2 adds. |
| 22101 |
if (GET_MODE_SIZE (mode) > UNITS_PER_WORD) |
| 22102 |
{ |
| 22103 |
mult_init = 3 * cost->mult_init[MODE_INDEX (word_mode)] |
| 22104 |
+ 2 * cost->add; |
| 22105 |
nbits *= 3; |
| 22106 |
} |
| 22107 |
else mult_init = cost->mult_init[MODE_INDEX (mode)]; |
| 22108 |
|
| 22109 |
*total = (mult_init |
| 22110 |
+ nbits * cost->mult_bit |
| 22111 |
+ rtx_cost (op0, mode, outer_code, opno, speed) |
| 22112 |
+ rtx_cost (op1, mode, outer_code, opno, speed)); |
| 22113 |
|
| 22114 |
return true; |
| 22115 |
} |
| 22116 |
*total = ix86_multiplication_cost (cost, mode); |
| 22117 |
return false; |
| 22118 |
|
| 22119 |
case DIV: |
| 22120 |
case UDIV: |
| 22121 |
case MOD: |
| 22122 |
case UMOD: |
| 22123 |
*total = ix86_division_cost (cost, mode); |
| 22124 |
return false; |
| 22125 |
|
| 22126 |
case PLUS: |
| 22127 |
if (GET_MODE_CLASS (mode) == MODE_INT |
| 22128 |
&& GET_MODE_SIZE (mode) <= UNITS_PER_WORD) |
| 22129 |
{ |
| 22130 |
if (GET_CODE (XEXP (x, 0)) == PLUS |
| 22131 |
&& GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT |
| 22132 |
&& CONST_INT_P (XEXP (XEXP (XEXP (x, 0), 0), 1)) |
| 22133 |
&& CONSTANT_P (XEXP (x, 1))) |
| 22134 |
{ |
| 22135 |
HOST_WIDE_INT val = INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1)); |
| 22136 |
if (val == 2 || val == 4 || val == 8) |
| 22137 |
{ |
| 22138 |
*total = cost->lea; |
| 22139 |
*total += rtx_cost (XEXP (XEXP (x, 0), 1), mode, |
| 22140 |
outer_code, opno, speed); |
| 22141 |
*total += rtx_cost (XEXP (XEXP (XEXP (x, 0), 0), 0), mode, |
| 22142 |
outer_code, opno, speed); |
| 22143 |
*total += rtx_cost (XEXP (x, 1), mode, |
| 22144 |
outer_code, opno, speed); |
| 22145 |
return true; |
| 22146 |
} |
| 22147 |
} |
| 22148 |
else if (GET_CODE (XEXP (x, 0)) == MULT |
| 22149 |
&& CONST_INT_P (XEXP (XEXP (x, 0), 1))) |
| 22150 |
{ |
| 22151 |
HOST_WIDE_INT val = INTVAL (XEXP (XEXP (x, 0), 1)); |
| 22152 |
if (val == 2 || val == 4 || val == 8) |
| 22153 |
{ |
| 22154 |
*total = cost->lea; |
| 22155 |
*total += rtx_cost (XEXP (XEXP (x, 0), 0), mode, |
| 22156 |
outer_code, opno, speed); |
| 22157 |
*total += rtx_cost (XEXP (x, 1), mode, |
| 22158 |
outer_code, opno, speed); |
| 22159 |
return true; |
| 22160 |
} |
| 22161 |
} |
| 22162 |
else if (GET_CODE (XEXP (x, 0)) == PLUS) |
| 22163 |
{ |
| 22164 |
rtx op = XEXP (XEXP (x, 0), 0); |
| 22165 |
|
| 22166 |
/* Add with carry, ignore the cost of adding a carry flag. */ |
| 22167 |
if (ix86_carry_flag_operator (op, mode) |
| 22168 |
|| ix86_carry_flag_unset_operator (op, mode)) |
| 22169 |
*total = cost->add; |
| 22170 |
else |
| 22171 |
{ |
| 22172 |
*total = cost->lea; |
| 22173 |
*total += rtx_cost (op, mode, |
| 22174 |
outer_code, opno, speed); |
| 22175 |
} |
| 22176 |
|
| 22177 |
*total += rtx_cost (XEXP (XEXP (x, 0), 1), mode, |
| 22178 |
outer_code, opno, speed); |
| 22179 |
*total += rtx_cost (XEXP (x, 1), mode, |
| 22180 |
outer_code, opno, speed); |
| 22181 |
return true; |
| 22182 |
} |
| 22183 |
} |
| 22184 |
/* FALLTHRU */ |
| 22185 |
|
| 22186 |
case MINUS: |
| 22187 |
/* Subtract with borrow, ignore the cost of subtracting a carry flag. */ |
| 22188 |
if (GET_MODE_CLASS (mode) == MODE_INT |
| 22189 |
&& GET_MODE_SIZE (mode) <= UNITS_PER_WORD |
| 22190 |
&& GET_CODE (XEXP (x, 0)) == MINUS |
| 22191 |
&& (ix86_carry_flag_operator (XEXP (XEXP (x, 0), 1), mode) |
| 22192 |
|| ix86_carry_flag_unset_operator (XEXP (XEXP (x, 0), 1), mode))) |
| 22193 |
{ |
| 22194 |
*total = cost->add; |
| 22195 |
*total += rtx_cost (XEXP (XEXP (x, 0), 0), mode, |
| 22196 |
outer_code, opno, speed); |
| 22197 |
*total += rtx_cost (XEXP (x, 1), mode, |
| 22198 |
outer_code, opno, speed); |
| 22199 |
return true; |
| 22200 |
} |
| 22201 |
|
| 22202 |
if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode)) |
| 22203 |
*total = cost->addss; |
| 22204 |
else if (X87_FLOAT_MODE_P (mode)) |
| 22205 |
*total = cost->fadd; |
| 22206 |
else if (FLOAT_MODE_P (mode)) |
| 22207 |
*total = ix86_vec_cost (mode, cost->addss); |
| 22208 |
else if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT) |
| 22209 |
*total = ix86_vec_cost (mode, cost->sse_op); |
| 22210 |
else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD) |
| 22211 |
*total = cost->add * 2; |
| 22212 |
else |
| 22213 |
*total = cost->add; |
| 22214 |
return false; |
| 22215 |
|
| 22216 |
case IOR: |
| 22217 |
if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT |
| 22218 |
|| SSE_FLOAT_MODE_P (mode)) |
| 22219 |
{ |
| 22220 |
/* (ior (not ...) ...) can be a single insn in AVX512. */ |
| 22221 |
if (GET_CODE (XEXP (x, 0)) == NOT && TARGET_AVX512F |
| 22222 |
&& ((TARGET_EVEX512 |
| 22223 |
&& GET_MODE_SIZE (mode) == 64) |
| 22224 |
|| (TARGET_AVX512VL |
| 22225 |
&& (GET_MODE_SIZE (mode) == 32 |
| 22226 |
|| GET_MODE_SIZE (mode) == 16)))) |
| 22227 |
{ |
| 22228 |
rtx right = GET_CODE (XEXP (x, 1)) != NOT |
| 22229 |
? XEXP (x, 1) : XEXP (XEXP (x, 1), 0); |
| 22230 |
|
| 22231 |
*total = ix86_vec_cost (mode, cost->sse_op) |
| 22232 |
+ rtx_cost (XEXP (XEXP (x, 0), 0), mode, |
| 22233 |
outer_code, opno, speed) |
| 22234 |
+ rtx_cost (right, mode, outer_code, opno, speed); |
| 22235 |
return true; |
| 22236 |
} |
| 22237 |
*total = ix86_vec_cost (mode, cost->sse_op); |
| 22238 |
} |
| 22239 |
else if (TARGET_64BIT |
| 22240 |
&& mode == TImode |
| 22241 |
&& GET_CODE (XEXP (x, 0)) == ASHIFT |
| 22242 |
&& GET_CODE (XEXP (XEXP (x, 0), 0)) == ZERO_EXTEND |
| 22243 |
&& GET_MODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == DImode |
| 22244 |
&& CONST_INT_P (XEXP (XEXP (x, 0), 1)) |
| 22245 |
&& INTVAL (XEXP (XEXP (x, 0), 1)) == 64 |
| 22246 |
&& GET_CODE (XEXP (x, 1)) == ZERO_EXTEND |
| 22247 |
&& GET_MODE (XEXP (XEXP (x, 1), 0)) == DImode) |
| 22248 |
{ |
| 22249 |
/* *concatditi3 is cheap. */ |
| 22250 |
rtx op0 = XEXP (XEXP (XEXP (x, 0), 0), 0); |
| 22251 |
rtx op1 = XEXP (XEXP (x, 1), 0); |
| 22252 |
*total = (SUBREG_P (op0) && GET_MODE (SUBREG_REG (op0)) == DFmode) |
| 22253 |
? COSTS_N_INSNS (1) /* movq. */ |
| 22254 |
: set_src_cost (op0, DImode, speed); |
| 22255 |
*total += (SUBREG_P (op1) && GET_MODE (SUBREG_REG (op1)) == DFmode) |
| 22256 |
? COSTS_N_INSNS (1) /* movq. */ |
| 22257 |
: set_src_cost (op1, DImode, speed); |
| 22258 |
return true; |
| 22259 |
} |
| 22260 |
else if (TARGET_64BIT |
| 22261 |
&& mode == TImode |
| 22262 |
&& GET_CODE (XEXP (x, 0)) == AND |
| 22263 |
&& REG_P (XEXP (XEXP (x, 0), 0)) |
| 22264 |
&& CONST_WIDE_INT_P (XEXP (XEXP (x, 0), 1)) |
| 22265 |
&& CONST_WIDE_INT_NUNITS (XEXP (XEXP (x, 0), 1)) == 2 |
| 22266 |
&& CONST_WIDE_INT_ELT (XEXP (XEXP (x, 0), 1), 0) == -1 |
| 22267 |
&& CONST_WIDE_INT_ELT (XEXP (XEXP (x, 0), 1), 1) == 0 |
| 22268 |
&& GET_CODE (XEXP (x, 1)) == ASHIFT |
| 22269 |
&& GET_CODE (XEXP (XEXP (x, 1), 0)) == ZERO_EXTEND |
| 22270 |
&& GET_MODE (XEXP (XEXP (XEXP (x, 1), 0), 0)) == DImode |
| 22271 |
&& CONST_INT_P (XEXP (XEXP (x, 1), 1)) |
| 22272 |
&& INTVAL (XEXP (XEXP (x, 1), 1)) == 64) |
| 22273 |
{ |
| 22274 |
/* *insvti_highpart is cheap. */ |
| 22275 |
rtx op = XEXP (XEXP (XEXP (x, 1), 0), 0); |
| 22276 |
*total = COSTS_N_INSNS (1) + 1; |
| 22277 |
*total += (SUBREG_P (op) && GET_MODE (SUBREG_REG (op)) == DFmode) |
| 22278 |
? COSTS_N_INSNS (1) /* movq. */ |
| 22279 |
: set_src_cost (op, DImode, speed); |
| 22280 |
return true; |
| 22281 |
} |
| 22282 |
else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD) |
| 22283 |
*total = cost->add * 2; |
| 22284 |
else |
| 22285 |
*total = cost->add; |
| 22286 |
return false; |
| 22287 |
|
| 22288 |
case XOR: |
| 22289 |
if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT |
| 22290 |
|| SSE_FLOAT_MODE_P (mode)) |
| 22291 |
*total = ix86_vec_cost (mode, cost->sse_op); |
| 22292 |
else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD) |
| 22293 |
*total = cost->add * 2; |
| 22294 |
else |
| 22295 |
*total = cost->add; |
| 22296 |
return false; |
| 22297 |
|
| 22298 |
case AND: |
| 22299 |
if (address_no_seg_operand (x, mode)) |
| 22300 |
{ |
| 22301 |
*total = cost->lea; |
| 22302 |
return true; |
| 22303 |
} |
| 22304 |
else if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT |
| 22305 |
|| SSE_FLOAT_MODE_P (mode)) |
| 22306 |
{ |
| 22307 |
/* pandn is a single instruction. */ |
| 22308 |
if (GET_CODE (XEXP (x, 0)) == NOT) |
| 22309 |
{ |
| 22310 |
rtx right = XEXP (x, 1); |
| 22311 |
|
| 22312 |
/* (and (not ...) (not ...)) can be a single insn in AVX512. */ |
| 22313 |
if (GET_CODE (right) == NOT && TARGET_AVX512F |
| 22314 |
&& ((TARGET_EVEX512 |
| 22315 |
&& GET_MODE_SIZE (mode) == 64) |
| 22316 |
|| (TARGET_AVX512VL |
| 22317 |
&& (GET_MODE_SIZE (mode) == 32 |
| 22318 |
|| GET_MODE_SIZE (mode) == 16)))) |
| 22319 |
right = XEXP (right, 0); |
| 22320 |
|
| 22321 |
*total = ix86_vec_cost (mode, cost->sse_op) |
| 22322 |
+ rtx_cost (XEXP (XEXP (x, 0), 0), mode, |
| 22323 |
outer_code, opno, speed) |
| 22324 |
+ rtx_cost (right, mode, outer_code, opno, speed); |
| 22325 |
return true; |
| 22326 |
} |
| 22327 |
else if (GET_CODE (XEXP (x, 1)) == NOT) |
| 22328 |
{ |
| 22329 |
*total = ix86_vec_cost (mode, cost->sse_op) |
| 22330 |
+ rtx_cost (XEXP (x, 0), mode, |
| 22331 |
outer_code, opno, speed) |
| 22332 |
+ rtx_cost (XEXP (XEXP (x, 1), 0), mode, |
| 22333 |
outer_code, opno, speed); |
| 22334 |
return true; |
| 22335 |
} |
| 22336 |
*total = ix86_vec_cost (mode, cost->sse_op); |
| 22337 |
} |
| 22338 |
else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD) |
| 22339 |
{ |
| 22340 |
if (TARGET_BMI && GET_CODE (XEXP (x,0)) == NOT) |
| 22341 |
{ |
| 22342 |
*total = cost->add * 2 |
| 22343 |
+ rtx_cost (XEXP (XEXP (x, 0), 0), mode, |
| 22344 |
outer_code, opno, speed) |
| 22345 |
+ rtx_cost (XEXP (x, 1), mode, |
| 22346 |
outer_code, opno, speed); |
| 22347 |
return true; |
| 22348 |
} |
| 22349 |
else if (TARGET_BMI && GET_CODE (XEXP (x, 1)) == NOT) |
| 22350 |
{ |
| 22351 |
*total = cost->add * 2 |
| 22352 |
+ rtx_cost (XEXP (x, 0), mode, |
| 22353 |
outer_code, opno, speed) |
| 22354 |
+ rtx_cost (XEXP (XEXP (x, 1), 0), mode, |
| 22355 |
outer_code, opno, speed); |
| 22356 |
return true; |
| 22357 |
} |
| 22358 |
*total = cost->add * 2; |
| 22359 |
} |
| 22360 |
else if (TARGET_BMI && GET_CODE (XEXP (x,0)) == NOT) |
| 22361 |
{ |
| 22362 |
*total = cost->add |
| 22363 |
+ rtx_cost (XEXP (XEXP (x, 0), 0), mode, |
| 22364 |
outer_code, opno, speed) |
| 22365 |
+ rtx_cost (XEXP (x, 1), mode, outer_code, opno, speed); |
| 22366 |
return true; |
| 22367 |
} |
| 22368 |
else if (TARGET_BMI && GET_CODE (XEXP (x,1)) == NOT) |
| 22369 |
{ |
| 22370 |
*total = cost->add |
| 22371 |
+ rtx_cost (XEXP (x, 0), mode, outer_code, opno, speed) |
| 22372 |
+ rtx_cost (XEXP (XEXP (x, 1), 0), mode, |
| 22373 |
outer_code, opno, speed); |
| 22374 |
return true; |
| 22375 |
} |
| 22376 |
else |
| 22377 |
*total = cost->add; |
| 22378 |
return false; |
| 22379 |
|
| 22380 |
case NOT: |
| 22381 |
if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT) |
| 22382 |
{ |
| 22383 |
/* (not (xor ...)) can be a single insn in AVX512. */ |
| 22384 |
if (GET_CODE (XEXP (x, 0)) == XOR && TARGET_AVX512F |
| 22385 |
&& ((TARGET_EVEX512 |
| 22386 |
&& GET_MODE_SIZE (mode) == 64) |
| 22387 |
|| (TARGET_AVX512VL |
| 22388 |
&& (GET_MODE_SIZE (mode) == 32 |
| 22389 |
|| GET_MODE_SIZE (mode) == 16)))) |
| 22390 |
{ |
| 22391 |
*total = ix86_vec_cost (mode, cost->sse_op) |
| 22392 |
+ rtx_cost (XEXP (XEXP (x, 0), 0), mode, |
| 22393 |
outer_code, opno, speed) |
| 22394 |
+ rtx_cost (XEXP (XEXP (x, 0), 1), mode, |
| 22395 |
outer_code, opno, speed); |
| 22396 |
return true; |
| 22397 |
} |
| 22398 |
|
| 22399 |
// vnot is pxor -1. |
| 22400 |
*total = ix86_vec_cost (mode, cost->sse_op) + 1; |
| 22401 |
} |
| 22402 |
else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD) |
| 22403 |
*total = cost->add * 2; |
| 22404 |
else |
| 22405 |
*total = cost->add; |
| 22406 |
return false; |
| 22407 |
|
| 22408 |
case NEG: |
| 22409 |
if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode)) |
| 22410 |
*total = cost->sse_op; |
| 22411 |
else if (X87_FLOAT_MODE_P (mode)) |
| 22412 |
*total = cost->fchs; |
| 22413 |
else if (FLOAT_MODE_P (mode)) |
| 22414 |
*total = ix86_vec_cost (mode, cost->sse_op); |
| 22415 |
else if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT) |
| 22416 |
*total = ix86_vec_cost (mode, cost->sse_op); |
| 22417 |
else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD) |
| 22418 |
*total = cost->add * 3; |
| 22419 |
else |
| 22420 |
*total = cost->add; |
| 22421 |
return false; |
| 22422 |
|
| 22423 |
case COMPARE: |
| 22424 |
rtx op0, op1; |
| 22425 |
op0 = XEXP (x, 0); |
| 22426 |
op1 = XEXP (x, 1); |
| 22427 |
if (GET_CODE (op0) == ZERO_EXTRACT |
| 22428 |
&& XEXP (op0, 1) == const1_rtx |
| 22429 |
&& CONST_INT_P (XEXP (op0, 2)) |
| 22430 |
&& op1 == const0_rtx) |
| 22431 |
{ |
| 22432 |
/* This kind of construct is implemented using test[bwl]. |
| 22433 |
Treat it as if we had an AND. */ |
| 22434 |
mode = GET_MODE (XEXP (op0, 0)); |
| 22435 |
*total = (cost->add |
| 22436 |
+ rtx_cost (XEXP (op0, 0), mode, outer_code, |
| 22437 |
opno, speed) |
| 22438 |
+ rtx_cost (const1_rtx, mode, outer_code, opno, speed)); |
| 22439 |
return true; |
| 22440 |
} |
| 22441 |
|
| 22442 |
if (GET_CODE (op0) == PLUS && rtx_equal_p (XEXP (op0, 0), op1)) |
| 22443 |
{ |
| 22444 |
/* This is an overflow detection, count it as a normal compare. */ |
| 22445 |
*total = rtx_cost (op0, GET_MODE (op0), COMPARE, 0, speed); |
| 22446 |
return true; |
| 22447 |
} |
| 22448 |
|
| 22449 |
rtx geu; |
| 22450 |
/* Match x |
| 22451 |
(compare:CCC (neg:QI (geu:QI (reg:CC_CCC FLAGS_REG) (const_int 0))) |
| 22452 |
(ltu:QI (reg:CC_CCC FLAGS_REG) (const_int 0))) */ |
| 22453 |
if (mode == CCCmode |
| 22454 |
&& GET_CODE (op0) == NEG |
| 22455 |
&& GET_CODE (geu = XEXP (op0, 0)) == GEU |
| 22456 |
&& REG_P (XEXP (geu, 0)) |
| 22457 |
&& (GET_MODE (XEXP (geu, 0)) == CCCmode |
| 22458 |
|| GET_MODE (XEXP (geu, 0)) == CCmode) |
| 22459 |
&& REGNO (XEXP (geu, 0)) == FLAGS_REG |
| 22460 |
&& XEXP (geu, 1) == const0_rtx |
| 22461 |
&& GET_CODE (op1) == LTU |
| 22462 |
&& REG_P (XEXP (op1, 0)) |
| 22463 |
&& GET_MODE (XEXP (op1, 0)) == GET_MODE (XEXP (geu, 0)) |
| 22464 |
&& REGNO (XEXP (op1, 0)) == FLAGS_REG |
| 22465 |
&& XEXP (op1, 1) == const0_rtx) |
| 22466 |
{ |
| 22467 |
/* This is *setcc_qi_addqi3_cconly_overflow_1_* patterns, a nop. */ |
| 22468 |
*total = 0; |
| 22469 |
return true; |
| 22470 |
} |
| 22471 |
/* Match x |
| 22472 |
(compare:CCC (neg:QI (ltu:QI (reg:CCC FLAGS_REG) (const_int 0))) |
| 22473 |
(geu:QI (reg:CCC FLAGS_REG) (const_int 0))) */ |
| 22474 |
if (mode == CCCmode |
| 22475 |
&& GET_CODE (op0) == NEG |
| 22476 |
&& GET_CODE (XEXP (op0, 0)) == LTU |
| 22477 |
&& REG_P (XEXP (XEXP (op0, 0), 0)) |
| 22478 |
&& GET_MODE (XEXP (XEXP (op0, 0), 0)) == CCCmode |
| 22479 |
&& REGNO (XEXP (XEXP (op0, 0), 0)) == FLAGS_REG |
| 22480 |
&& XEXP (XEXP (op0, 0), 1) == const0_rtx |
| 22481 |
&& GET_CODE (op1) == GEU |
| 22482 |
&& REG_P (XEXP (op1, 0)) |
| 22483 |
&& GET_MODE (XEXP (op1, 0)) == CCCmode |
| 22484 |
&& REGNO (XEXP (op1, 0)) == FLAGS_REG |
| 22485 |
&& XEXP (op1, 1) == const0_rtx) |
| 22486 |
{ |
| 22487 |
/* This is *x86_cmc. */ |
| 22488 |
if (!speed) |
| 22489 |
*total = COSTS_N_BYTES (1); |
| 22490 |
else if (TARGET_SLOW_STC) |
| 22491 |
*total = COSTS_N_INSNS (2); |
| 22492 |
else |
| 22493 |
*total = COSTS_N_INSNS (1); |
| 22494 |
return true; |
| 22495 |
} |
| 22496 |
|
| 22497 |
if (SCALAR_INT_MODE_P (GET_MODE (op0)) |
| 22498 |
&& GET_MODE_SIZE (GET_MODE (op0)) > UNITS_PER_WORD) |
| 22499 |
{ |
| 22500 |
if (op1 == const0_rtx) |
| 22501 |
*total = cost->add |
| 22502 |
+ rtx_cost (op0, GET_MODE (op0), outer_code, opno, speed); |
| 22503 |
else |
| 22504 |
*total = 3*cost->add |
| 22505 |
+ rtx_cost (op0, GET_MODE (op0), outer_code, opno, speed) |
| 22506 |
+ rtx_cost (op1, GET_MODE (op0), outer_code, opno, speed); |
| 22507 |
return true; |
| 22508 |
} |
| 22509 |
|
| 22510 |
/* The embedded comparison operand is completely free. */ |
| 22511 |
if (!general_operand (op0, GET_MODE (op0)) && op1 == const0_rtx) |
| 22512 |
*total = 0; |
| 22513 |
|
| 22514 |
return false; |
| 22515 |
|
| 22516 |
case FLOAT_EXTEND: |
| 22517 |
if (!SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode)) |
| 22518 |
*total = 0; |
| 22519 |
else |
| 22520 |
*total = ix86_vec_cost (mode, cost->addss); |
| 22521 |
return false; |
| 22522 |
|
| 22523 |
case FLOAT_TRUNCATE: |
| 22524 |
if (!SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode)) |
| 22525 |
*total = cost->fadd; |
| 22526 |
else |
| 22527 |
*total = ix86_vec_cost (mode, cost->addss); |
| 22528 |
return false; |
| 22529 |
|
| 22530 |
case ABS: |
| 22531 |
/* SSE requires memory load for the constant operand. It may make |
| 22532 |
sense to account for this. Of course the constant operand may or |
| 22533 |
may not be reused. */ |
| 22534 |
if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode)) |
| 22535 |
*total = cost->sse_op; |
| 22536 |
else if (X87_FLOAT_MODE_P (mode)) |
| 22537 |
*total = cost->fabs; |
| 22538 |
else if (FLOAT_MODE_P (mode)) |
| 22539 |
*total = ix86_vec_cost (mode, cost->sse_op); |
| 22540 |
else if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT) |
| 22541 |
*total = cost->sse_op; |
| 22542 |
return false; |
| 22543 |
|
| 22544 |
case SQRT: |
| 22545 |
if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode)) |
| 22546 |
*total = mode == SFmode ? cost->sqrtss : cost->sqrtsd; |
| 22547 |
else if (X87_FLOAT_MODE_P (mode)) |
| 22548 |
*total = cost->fsqrt; |
| 22549 |
else if (FLOAT_MODE_P (mode)) |
| 22550 |
*total = ix86_vec_cost (mode, |
| 22551 |
mode == SFmode ? cost->sqrtss : cost->sqrtsd); |
| 22552 |
return false; |
| 22553 |
|
| 22554 |
case UNSPEC: |
| 22555 |
if (XINT (x, 1) == UNSPEC_TP) |
| 22556 |
*total = 0; |
| 22557 |
else if (XINT (x, 1) == UNSPEC_VTERNLOG) |
| 22558 |
{ |
| 22559 |
*total = cost->sse_op; |
| 22560 |
*total += rtx_cost (XVECEXP (x, 0, 0), mode, code, 0, speed); |
| 22561 |
*total += rtx_cost (XVECEXP (x, 0, 1), mode, code, 1, speed); |
| 22562 |
*total += rtx_cost (XVECEXP (x, 0, 2), mode, code, 2, speed); |
| 22563 |
return true; |
| 22564 |
} |
| 22565 |
else if (XINT (x, 1) == UNSPEC_PTEST) |
| 22566 |
{ |
| 22567 |
*total = cost->sse_op; |
| 22568 |
rtx test_op0 = XVECEXP (x, 0, 0); |
| 22569 |
if (!rtx_equal_p (test_op0, XVECEXP (x, 0, 1))) |
| 22570 |
return false; |
| 22571 |
if (GET_CODE (test_op0) == AND) |
| 22572 |
{ |
| 22573 |
rtx and_op0 = XEXP (test_op0, 0); |
| 22574 |
if (GET_CODE (and_op0) == NOT) |
| 22575 |
and_op0 = XEXP (and_op0, 0); |
| 22576 |
*total += rtx_cost (and_op0, GET_MODE (and_op0), |
| 22577 |
AND, 0, speed) |
| 22578 |
+ rtx_cost (XEXP (test_op0, 1), GET_MODE (and_op0), |
| 22579 |
AND, 1, speed); |
| 22580 |
} |
| 22581 |
else |
| 22582 |
*total = rtx_cost (test_op0, GET_MODE (test_op0), |
| 22583 |
UNSPEC, 0, speed); |
| 22584 |
return true; |
| 22585 |
} |
| 22586 |
return false; |
| 22587 |
|
| 22588 |
case VEC_SELECT: |
| 22589 |
case VEC_CONCAT: |
| 22590 |
/* ??? Assume all of these vector manipulation patterns are |
| 22591 |
recognizable. In which case they all pretty much have the |
| 22592 |
same cost. */ |
| 22593 |
*total = cost->sse_op; |
| 22594 |
return true; |
| 22595 |
case VEC_DUPLICATE: |
| 22596 |
*total = rtx_cost (XEXP (x, 0), |
| 22597 |
GET_MODE (XEXP (x, 0)), |
| 22598 |
VEC_DUPLICATE, 0, speed); |
| 22599 |
/* It's broadcast instruction, not embedded broadcasting. */ |
| 22600 |
if (outer_code == SET) |
| 22601 |
*total += cost->sse_op; |
| 22602 |
|
| 22603 |
return true; |
| 22604 |
|
| 22605 |
case VEC_MERGE: |
| 22606 |
mask = XEXP (x, 2); |
| 22607 |
/* This is masked instruction, assume the same cost, |
| 22608 |
as nonmasked variant. */ |
| 22609 |
if (TARGET_AVX512F && register_operand (mask, GET_MODE (mask))) |
| 22610 |
*total = rtx_cost (XEXP (x, 0), mode, outer_code, opno, speed); |
| 22611 |
else |
| 22612 |
*total = cost->sse_op; |
| 22613 |
return true; |
| 22614 |
|
| 22615 |
case MEM: |
| 22616 |
/* CONST_VECTOR_DUPLICATE_P in constant_pool is just broadcast. |
| 22617 |
or variants in ix86_vector_duplicate_simode_const. */ |
| 22618 |
|
| 22619 |
if (GET_MODE_SIZE (mode) >= 16 |
| 22620 |
&& VECTOR_MODE_P (mode) |
| 22621 |
&& SYMBOL_REF_P (XEXP (x, 0)) |
| 22622 |
&& CONSTANT_POOL_ADDRESS_P (XEXP (x, 0)) |
| 22623 |
&& ix86_broadcast_from_constant (mode, x)) |
| 22624 |
{ |
| 22625 |
*total = COSTS_N_INSNS (2) + speed; |
| 22626 |
return true; |
| 22627 |
} |
| 22628 |
|
| 22629 |
/* An insn that accesses memory is slightly more expensive |
| 22630 |
than one that does not. */ |
| 22631 |
if (speed) |
| 22632 |
{ |
| 22633 |
*total += 1; |
| 22634 |
rtx addr = XEXP (x, 0); |
| 22635 |
/* For MEM, rtx_cost iterates each subrtx, and adds up the costs, |
| 22636 |
so for MEM (reg) and MEM (reg + 4), the former costs 5, |
| 22637 |
the latter costs 9, it is not accurate for x86. Ideally |
| 22638 |
address_cost should be used, but it reduce cost too much. |
| 22639 |
So current solution is make constant disp as cheap as possible. */ |
| 22640 |
if (GET_CODE (addr) == PLUS |
| 22641 |
&& x86_64_immediate_operand (XEXP (addr, 1), Pmode) |
| 22642 |
/* Only hanlde (reg + disp) since other forms of addr are mostly LEA, |
| 22643 |
there's no additional cost for the plus of disp. */ |
| 22644 |
&& register_operand (XEXP (addr, 0), Pmode)) |
| 22645 |
{ |
| 22646 |
*total += 1; |
| 22647 |
*total += rtx_cost (XEXP (addr, 0), Pmode, PLUS, 0, speed); |
| 22648 |
return true; |
| 22649 |
} |
| 22650 |
} |
| 22651 |
|
| 22652 |
return false; |
| 22653 |
|
| 22654 |
case ZERO_EXTRACT: |
| 22655 |
if (XEXP (x, 1) == const1_rtx |
| 22656 |
&& GET_CODE (XEXP (x, 2)) == ZERO_EXTEND |
| 22657 |
&& GET_MODE (XEXP (x, 2)) == SImode |
| 22658 |
&& GET_MODE (XEXP (XEXP (x, 2), 0)) == QImode) |
| 22659 |
{ |
| 22660 |
/* Ignore cost of zero extension and masking of last argument. */ |
| 22661 |
*total += rtx_cost (XEXP (x, 0), mode, code, 0, speed); |
| 22662 |
*total += rtx_cost (XEXP (x, 1), mode, code, 1, speed); |
| 22663 |
*total += rtx_cost (XEXP (XEXP (x, 2), 0), mode, code, 2, speed); |
| 22664 |
return true; |
| 22665 |
} |
| 22666 |
return false; |
| 22667 |
|
| 22668 |
case IF_THEN_ELSE: |
| 22669 |
if (TARGET_XOP |
| 22670 |
&& VECTOR_MODE_P (mode) |
| 22671 |
&& (GET_MODE_SIZE (mode) == 16 || GET_MODE_SIZE (mode) == 32)) |
| 22672 |
{ |
| 22673 |
/* vpcmov. */ |
| 22674 |
*total = speed ? COSTS_N_INSNS (2) : COSTS_N_BYTES (6); |
| 22675 |
if (!REG_P (XEXP (x, 0))) |
| 22676 |
*total += rtx_cost (XEXP (x, 0), mode, code, 0, speed); |
| 22677 |
if (!REG_P (XEXP (x, 1))) |
| 22678 |
*total += rtx_cost (XEXP (x, 1), mode, code, 1, speed); |
| 22679 |
if (!REG_P (XEXP (x, 2))) |
| 22680 |
*total += rtx_cost (XEXP (x, 2), mode, code, 2, speed); |
| 22681 |
return true; |
| 22682 |
} |
| 22683 |
else if (TARGET_CMOVE |
| 22684 |
&& SCALAR_INT_MODE_P (mode) |
| 22685 |
&& GET_MODE_SIZE (mode) <= UNITS_PER_WORD) |
| 22686 |
{ |
| 22687 |
/* cmov. */ |
| 22688 |
*total = COSTS_N_INSNS (1); |
| 22689 |
if (!COMPARISON_P (XEXP (x, 0)) && !REG_P (XEXP (x, 0))) |
| 22690 |
*total += rtx_cost (XEXP (x, 0), mode, code, 0, speed); |
| 22691 |
if (!REG_P (XEXP (x, 1))) |
| 22692 |
*total += rtx_cost (XEXP (x, 1), mode, code, 1, speed); |
| 22693 |
if (!REG_P (XEXP (x, 2))) |
| 22694 |
*total += rtx_cost (XEXP (x, 2), mode, code, 2, speed); |
| 22695 |
return true; |
| 22696 |
} |
| 22697 |
return false; |
| 22698 |
|
| 22699 |
default: |
| 22700 |
return false; |
| 22701 |
} |
| 22702 |
} |
| 22703 |
|
| 22704 |
#if TARGET_MACHO |
| 22705 |
|
| 22706 |
static int current_machopic_label_num; |
| 22707 |
|
| 22708 |
/* Given a symbol name and its associated stub, write out the |
| 22709 |
definition of the stub. */ |
| 22710 |
|
| 22711 |
void |
| 22712 |
machopic_output_stub (FILE *file, const char *symb, const char *stub) |
| 22713 |
{ |
| 22714 |
unsigned int length; |
| 22715 |
char *binder_name, *symbol_name, lazy_ptr_name[32]; |
| 22716 |
int label = ++current_machopic_label_num; |
| 22717 |
|
| 22718 |
/* For 64-bit we shouldn't get here. */ |
| 22719 |
gcc_assert (!TARGET_64BIT); |
| 22720 |
|
| 22721 |
/* Lose our funky encoding stuff so it doesn't contaminate the stub. */ |
| 22722 |
symb = targetm.strip_name_encoding (symb); |
| 22723 |
|
| 22724 |
length = strlen (stub); |
| 22725 |
binder_name = XALLOCAVEC (char, length + 32); |
| 22726 |
GEN_BINDER_NAME_FOR_STUB (binder_name, stub, length); |
| 22727 |
|
| 22728 |
length = strlen (symb); |
| 22729 |
symbol_name = XALLOCAVEC (char, length + 32); |
| 22730 |
GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length); |
| 22731 |
|
| 22732 |
sprintf (lazy_ptr_name, "L%d$lz", label); |
| 22733 |
|
| 22734 |
if (MACHOPIC_ATT_STUB) |
| 22735 |
switch_to_section (darwin_sections[machopic_picsymbol_stub3_section]); |
| 22736 |
else if (MACHOPIC_PURE) |
| 22737 |
switch_to_section (darwin_sections[machopic_picsymbol_stub2_section]); |
| 22738 |
else |
| 22739 |
switch_to_section (darwin_sections[machopic_symbol_stub_section]); |
| 22740 |
|
| 22741 |
fprintf (file, "%s:\n", stub); |
| 22742 |
fprintf (file, "\t.indirect_symbol %s\n", symbol_name); |
| 22743 |
|
| 22744 |
if (MACHOPIC_ATT_STUB) |
| 22745 |
{ |
| 22746 |
fprintf (file, "\thlt ; hlt ; hlt ; hlt ; hlt\n"); |
| 22747 |
} |
| 22748 |
else if (MACHOPIC_PURE) |
| 22749 |
{ |
| 22750 |
/* PIC stub. */ |
| 22751 |
/* 25-byte PIC stub using "CALL get_pc_thunk". */ |
| 22752 |
rtx tmp = gen_rtx_REG (SImode, 2 /* ECX */); |
| 22753 |
output_set_got (tmp, NULL_RTX); /* "CALL ___<cpu>.get_pc_thunk.cx". */ |
| 22754 |
fprintf (file, "LPC$%d:\tmovl\t%s-LPC$%d(%%ecx),%%ecx\n", |
| 22755 |
label, lazy_ptr_name, label); |
| 22756 |
fprintf (file, "\tjmp\t*%%ecx\n"); |
| 22757 |
} |
| 22758 |
else |
| 22759 |
fprintf (file, "\tjmp\t*%s\n", lazy_ptr_name); |
| 22760 |
|
| 22761 |
/* The AT&T-style ("self-modifying") stub is not lazily bound, thus |
| 22762 |
it needs no stub-binding-helper. */ |
| 22763 |
if (MACHOPIC_ATT_STUB) |
| 22764 |
return; |
| 22765 |
|
| 22766 |
fprintf (file, "%s:\n", binder_name); |
| 22767 |
|
| 22768 |
if (MACHOPIC_PURE) |
| 22769 |
{ |
| 22770 |
fprintf (file, "\tlea\t%s-%s(%%ecx),%%ecx\n", lazy_ptr_name, binder_name); |
| 22771 |
fprintf (file, "\tpushl\t%%ecx\n"); |
| 22772 |
} |
| 22773 |
else |
| 22774 |
fprintf (file, "\tpushl\t$%s\n", lazy_ptr_name); |
| 22775 |
|
| 22776 |
fputs ("\tjmp\tdyld_stub_binding_helper\n", file); |
| 22777 |
|
| 22778 |
/* N.B. Keep the correspondence of these |
| 22779 |
'symbol_ptr/symbol_ptr2/symbol_ptr3' sections consistent with the |
| 22780 |
old-pic/new-pic/non-pic stubs; altering this will break |
| 22781 |
compatibility with existing dylibs. */ |
| 22782 |
if (MACHOPIC_PURE) |
| 22783 |
{ |
| 22784 |
/* 25-byte PIC stub using "CALL get_pc_thunk". */ |
| 22785 |
switch_to_section (darwin_sections[machopic_lazy_symbol_ptr2_section]); |
| 22786 |
} |
| 22787 |
else |
| 22788 |
/* 16-byte -mdynamic-no-pic stub. */ |
| 22789 |
switch_to_section(darwin_sections[machopic_lazy_symbol_ptr3_section]); |
| 22790 |
|
| 22791 |
fprintf (file, "%s:\n", lazy_ptr_name); |
| 22792 |
fprintf (file, "\t.indirect_symbol %s\n", symbol_name); |
| 22793 |
fprintf (file, ASM_LONG "%s\n", binder_name); |
| 22794 |
} |
| 22795 |
#endif /* TARGET_MACHO */ |
| 22796 |
|
| 22797 |
/* Order the registers for register allocator. */ |
| 22798 |
|
| 22799 |
void |
| 22800 |
x86_order_regs_for_local_alloc (void) |
| 22801 |
{ |
| 22802 |
int pos = 0; |
| 22803 |
int i; |
| 22804 |
|
| 22805 |
/* First allocate the local general purpose registers. */ |
| 22806 |
for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) |
| 22807 |
if (GENERAL_REGNO_P (i) && call_used_or_fixed_reg_p (i)) |
| 22808 |
reg_alloc_order [pos++] = i; |
| 22809 |
|
| 22810 |
/* Global general purpose registers. */ |
| 22811 |
for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) |
| 22812 |
if (GENERAL_REGNO_P (i) && !call_used_or_fixed_reg_p (i)) |
| 22813 |
reg_alloc_order [pos++] = i; |
| 22814 |
|
| 22815 |
/* x87 registers come first in case we are doing FP math |
| 22816 |
using them. */ |
| 22817 |
if (!TARGET_SSE_MATH) |
| 22818 |
for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++) |
| 22819 |
reg_alloc_order [pos++] = i; |
| 22820 |
|
| 22821 |
/* SSE registers. */ |
| 22822 |
for (i = FIRST_SSE_REG; i <= LAST_SSE_REG; i++) |
| 22823 |
reg_alloc_order [pos++] = i; |
| 22824 |
for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++) |
| 22825 |
reg_alloc_order [pos++] = i; |
| 22826 |
|
| 22827 |
/* Extended REX SSE registers. */ |
| 22828 |
for (i = FIRST_EXT_REX_SSE_REG; i <= LAST_EXT_REX_SSE_REG; i++) |
| 22829 |
reg_alloc_order [pos++] = i; |
| 22830 |
|
| 22831 |
/* Mask register. */ |
| 22832 |
for (i = FIRST_MASK_REG; i <= LAST_MASK_REG; i++) |
| 22833 |
reg_alloc_order [pos++] = i; |
| 22834 |
|
| 22835 |
/* x87 registers. */ |
| 22836 |
if (TARGET_SSE_MATH) |
| 22837 |
for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++) |
| 22838 |
reg_alloc_order [pos++] = i; |
| 22839 |
|
| 22840 |
for (i = FIRST_MMX_REG; i <= LAST_MMX_REG; i++) |
| 22841 |
reg_alloc_order [pos++] = i; |
| 22842 |
|
| 22843 |
/* Initialize the rest of array as we do not allocate some registers |
| 22844 |
at all. */ |
| 22845 |
while (pos < FIRST_PSEUDO_REGISTER) |
| 22846 |
reg_alloc_order [pos++] = 0; |
| 22847 |
} |
| 22848 |
|
| 22849 |
static bool |
| 22850 |
ix86_ms_bitfield_layout_p (const_tree record_type) |
| 22851 |
{ |
| 22852 |
return ((TARGET_MS_BITFIELD_LAYOUT |
| 22853 |
&& !lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (record_type))) |
| 22854 |
|| lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (record_type))); |
| 22855 |
} |
| 22856 |
|
| 22857 |
/* Returns an expression indicating where the this parameter is |
| 22858 |
located on entry to the FUNCTION. */ |
| 22859 |
|
| 22860 |
static rtx |
| 22861 |
x86_this_parameter (tree function) |
| 22862 |
{ |
| 22863 |
tree type = TREE_TYPE (function); |
| 22864 |
bool aggr = aggregate_value_p (TREE_TYPE (type), type) != 0; |
| 22865 |
int nregs; |
| 22866 |
|
| 22867 |
if (TARGET_64BIT) |
| 22868 |
{ |
| 22869 |
const int *parm_regs; |
| 22870 |
|
| 22871 |
if (ix86_function_type_abi (type) == MS_ABI) |
| 22872 |
parm_regs = x86_64_ms_abi_int_parameter_registers; |
| 22873 |
else |
| 22874 |
parm_regs = x86_64_int_parameter_registers; |
| 22875 |
return gen_rtx_REG (Pmode, parm_regs[aggr]); |
| 22876 |
} |
| 22877 |
|
| 22878 |
nregs = ix86_function_regparm (type, function); |
| 22879 |
|
| 22880 |
if (nregs > 0 && !stdarg_p (type)) |
| 22881 |
{ |
| 22882 |
int regno; |
| 22883 |
unsigned int ccvt = ix86_get_callcvt (type); |
| 22884 |
|
| 22885 |
if ((ccvt & IX86_CALLCVT_FASTCALL) != 0) |
| 22886 |
regno = aggr ? DX_REG : CX_REG; |
| 22887 |
else if ((ccvt & IX86_CALLCVT_THISCALL) != 0) |
| 22888 |
{ |
| 22889 |
regno = CX_REG; |
| 22890 |
if (aggr) |
| 22891 |
return gen_rtx_MEM (SImode, |
| 22892 |
plus_constant (Pmode, stack_pointer_rtx, 4)); |
| 22893 |
} |
| 22894 |
else |
| 22895 |
{ |
| 22896 |
regno = AX_REG; |
| 22897 |
if (aggr) |
| 22898 |
{ |
| 22899 |
regno = DX_REG; |
| 22900 |
if (nregs == 1) |
| 22901 |
return gen_rtx_MEM (SImode, |
| 22902 |
plus_constant (Pmode, |
| 22903 |
stack_pointer_rtx, 4)); |
| 22904 |
} |
| 22905 |
} |
| 22906 |
return gen_rtx_REG (SImode, regno); |
| 22907 |
} |
| 22908 |
|
| 22909 |
return gen_rtx_MEM (SImode, plus_constant (Pmode, stack_pointer_rtx, |
| 22910 |
aggr ? 8 : 4)); |
| 22911 |
} |
| 22912 |
|
| 22913 |
/* Determine whether x86_output_mi_thunk can succeed. */ |
| 22914 |
|
| 22915 |
static bool |
| 22916 |
x86_can_output_mi_thunk (const_tree, HOST_WIDE_INT, HOST_WIDE_INT vcall_offset, |
| 22917 |
const_tree function) |
| 22918 |
{ |
| 22919 |
/* 64-bit can handle anything. */ |
| 22920 |
if (TARGET_64BIT) |
| 22921 |
return true; |
| 22922 |
|
| 22923 |
/* For 32-bit, everything's fine if we have one free register. */ |
| 22924 |
if (ix86_function_regparm (TREE_TYPE (function), function) < 3) |
| 22925 |
return true; |
| 22926 |
|
| 22927 |
/* Need a free register for vcall_offset. */ |
| 22928 |
if (vcall_offset) |
| 22929 |
return false; |
| 22930 |
|
| 22931 |
/* Need a free register for GOT references. */ |
| 22932 |
if (flag_pic && !targetm.binds_local_p (function)) |
| 22933 |
return false; |
| 22934 |
|
| 22935 |
/* Otherwise ok. */ |
| 22936 |
return true; |
| 22937 |
} |
| 22938 |
|
| 22939 |
/* Output the assembler code for a thunk function. THUNK_DECL is the |
| 22940 |
declaration for the thunk function itself, FUNCTION is the decl for |
| 22941 |
the target function. DELTA is an immediate constant offset to be |
| 22942 |
added to THIS. If VCALL_OFFSET is nonzero, the word at |
| 22943 |
*(*this + vcall_offset) should be added to THIS. */ |
| 22944 |
|
| 22945 |
static void |
| 22946 |
x86_output_mi_thunk (FILE *file, tree thunk_fndecl, HOST_WIDE_INT delta, |
| 22947 |
HOST_WIDE_INT vcall_offset, tree function) |
| 22948 |
{ |
| 22949 |
const char *fnname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (thunk_fndecl)); |
| 22950 |
rtx this_param = x86_this_parameter (function); |
| 22951 |
rtx this_reg, tmp, fnaddr; |
| 22952 |
unsigned int tmp_regno; |
| 22953 |
rtx_insn *insn; |
| 22954 |
int saved_flag_force_indirect_call = flag_force_indirect_call; |
| 22955 |
|
| 22956 |
if (TARGET_64BIT) |
| 22957 |
tmp_regno = R10_REG; |
| 22958 |
else |
| 22959 |
{ |
| 22960 |
unsigned int ccvt = ix86_get_callcvt (TREE_TYPE (function)); |
| 22961 |
if ((ccvt & IX86_CALLCVT_FASTCALL) != 0) |
| 22962 |
tmp_regno = AX_REG; |
| 22963 |
else if ((ccvt & IX86_CALLCVT_THISCALL) != 0) |
| 22964 |
tmp_regno = DX_REG; |
| 22965 |
else |
| 22966 |
tmp_regno = CX_REG; |
| 22967 |
|
| 22968 |
if (flag_pic) |
| 22969 |
flag_force_indirect_call = 0; |
| 22970 |
} |
| 22971 |
|
| 22972 |
emit_note (NOTE_INSN_PROLOGUE_END); |
| 22973 |
|
| 22974 |
/* CET is enabled, insert EB instruction. */ |
| 22975 |
if ((flag_cf_protection & CF_BRANCH)) |
| 22976 |
emit_insn (gen_nop_endbr ()); |
| 22977 |
|
| 22978 |
/* If VCALL_OFFSET, we'll need THIS in a register. Might as well |
| 22979 |
pull it in now and let DELTA benefit. */ |
| 22980 |
if (REG_P (this_param)) |
| 22981 |
this_reg = this_param; |
| 22982 |
else if (vcall_offset) |
| 22983 |
{ |
| 22984 |
/* Put the this parameter into %eax. */ |
| 22985 |
this_reg = gen_rtx_REG (Pmode, AX_REG); |
| 22986 |
emit_move_insn (this_reg, this_param); |
| 22987 |
} |
| 22988 |
else |
| 22989 |
this_reg = NULL_RTX; |
| 22990 |
|
| 22991 |
/* Adjust the this parameter by a fixed constant. */ |
| 22992 |
if (delta) |
| 22993 |
{ |
| 22994 |
rtx delta_rtx = GEN_INT (delta); |
| 22995 |
rtx delta_dst = this_reg ? this_reg : this_param; |
| 22996 |
|
| 22997 |
if (TARGET_64BIT) |
| 22998 |
{ |
| 22999 |
if (!x86_64_general_operand (delta_rtx, Pmode)) |
| 23000 |
{ |
| 23001 |
tmp = gen_rtx_REG (Pmode, tmp_regno); |
| 23002 |
emit_move_insn (tmp, delta_rtx); |
| 23003 |
delta_rtx = tmp; |
| 23004 |
} |
| 23005 |
} |
| 23006 |
|
| 23007 |
ix86_emit_binop (PLUS, Pmode, delta_dst, delta_rtx); |
| 23008 |
} |
| 23009 |
|
| 23010 |
/* Adjust the this parameter by a value stored in the vtable. */ |
| 23011 |
if (vcall_offset) |
| 23012 |
{ |
| 23013 |
rtx vcall_addr, vcall_mem, this_mem; |
| 23014 |
|
| 23015 |
tmp = gen_rtx_REG (Pmode, tmp_regno); |
| 23016 |
|
| 23017 |
this_mem = gen_rtx_MEM (ptr_mode, this_reg); |
| 23018 |
if (Pmode != ptr_mode) |
| 23019 |
this_mem = gen_rtx_ZERO_EXTEND (Pmode, this_mem); |
| 23020 |
emit_move_insn (tmp, this_mem); |
| 23021 |
|
| 23022 |
/* Adjust the this parameter. */ |
| 23023 |
vcall_addr = plus_constant (Pmode, tmp, vcall_offset); |
| 23024 |
if (TARGET_64BIT |
| 23025 |
&& !ix86_legitimate_address_p (ptr_mode, vcall_addr, true)) |
| 23026 |
{ |
| 23027 |
rtx tmp2 = gen_rtx_REG (Pmode, R11_REG); |
| 23028 |
emit_move_insn (tmp2, GEN_INT (vcall_offset)); |
| 23029 |
vcall_addr = gen_rtx_PLUS (Pmode, tmp, tmp2); |
| 23030 |
} |
| 23031 |
|
| 23032 |
vcall_mem = gen_rtx_MEM (ptr_mode, vcall_addr); |
| 23033 |
if (Pmode != ptr_mode) |
| 23034 |
emit_insn (gen_addsi_1_zext (this_reg, |
| 23035 |
gen_rtx_REG (ptr_mode, |
| 23036 |
REGNO (this_reg)), |
| 23037 |
vcall_mem)); |
| 23038 |
else |
| 23039 |
ix86_emit_binop (PLUS, Pmode, this_reg, vcall_mem); |
| 23040 |
} |
| 23041 |
|
| 23042 |
/* If necessary, drop THIS back to its stack slot. */ |
| 23043 |
if (this_reg && this_reg != this_param) |
| 23044 |
emit_move_insn (this_param, this_reg); |
| 23045 |
|
| 23046 |
fnaddr = XEXP (DECL_RTL (function), 0); |
| 23047 |
if (TARGET_64BIT) |
| 23048 |
{ |
| 23049 |
if (!flag_pic || targetm.binds_local_p (function) |
| 23050 |
|| TARGET_PECOFF) |
| 23051 |
; |
| 23052 |
else |
| 23053 |
{ |
| 23054 |
tmp = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, fnaddr), UNSPEC_GOTPCREL); |
| 23055 |
tmp = gen_rtx_CONST (Pmode, tmp); |
| 23056 |
fnaddr = gen_const_mem (Pmode, tmp); |
| 23057 |
} |
| 23058 |
} |
| 23059 |
else |
| 23060 |
{ |
| 23061 |
if (!flag_pic || targetm.binds_local_p (function)) |
| 23062 |
; |
| 23063 |
#if TARGET_MACHO |
| 23064 |
else if (TARGET_MACHO) |
| 23065 |
{ |
| 23066 |
fnaddr = machopic_indirect_call_target (DECL_RTL (function)); |
| 23067 |
fnaddr = XEXP (fnaddr, 0); |
| 23068 |
} |
| 23069 |
#endif /* TARGET_MACHO */ |
| 23070 |
else |
| 23071 |
{ |
| 23072 |
tmp = gen_rtx_REG (Pmode, CX_REG); |
| 23073 |
output_set_got (tmp, NULL_RTX); |
| 23074 |
|
| 23075 |
fnaddr = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, fnaddr), UNSPEC_GOT); |
| 23076 |
fnaddr = gen_rtx_CONST (Pmode, fnaddr); |
| 23077 |
fnaddr = gen_rtx_PLUS (Pmode, tmp, fnaddr); |
| 23078 |
fnaddr = gen_const_mem (Pmode, fnaddr); |
| 23079 |
} |
| 23080 |
} |
| 23081 |
|
| 23082 |
/* Our sibling call patterns do not allow memories, because we have no |
| 23083 |
predicate that can distinguish between frame and non-frame memory. |
| 23084 |
For our purposes here, we can get away with (ab)using a jump pattern, |
| 23085 |
because we're going to do no optimization. */ |
| 23086 |
if (MEM_P (fnaddr)) |
| 23087 |
{ |
| 23088 |
if (sibcall_insn_operand (fnaddr, word_mode)) |
| 23089 |
{ |
| 23090 |
fnaddr = XEXP (DECL_RTL (function), 0); |
| 23091 |
tmp = gen_rtx_MEM (QImode, fnaddr); |
| 23092 |
tmp = gen_rtx_CALL (VOIDmode, tmp, const0_rtx); |
| 23093 |
tmp = emit_call_insn (tmp); |
| 23094 |
SIBLING_CALL_P (tmp) = 1; |
| 23095 |
} |
| 23096 |
else |
| 23097 |
emit_jump_insn (gen_indirect_jump (fnaddr)); |
| 23098 |
} |
| 23099 |
else |
| 23100 |
{ |
| 23101 |
if (ix86_cmodel == CM_LARGE_PIC && SYMBOLIC_CONST (fnaddr)) |
| 23102 |
{ |
| 23103 |
// CM_LARGE_PIC always uses pseudo PIC register which is |
| 23104 |
// uninitialized. Since FUNCTION is local and calling it |
| 23105 |
// doesn't go through PLT, we use scratch register %r11 as |
| 23106 |
// PIC register and initialize it here. |
| 23107 |
pic_offset_table_rtx = gen_rtx_REG (Pmode, R11_REG); |
| 23108 |
ix86_init_large_pic_reg (tmp_regno); |
| 23109 |
fnaddr = legitimize_pic_address (fnaddr, |
| 23110 |
gen_rtx_REG (Pmode, tmp_regno)); |
| 23111 |
} |
| 23112 |
|
| 23113 |
if (!sibcall_insn_operand (fnaddr, word_mode)) |
| 23114 |
{ |
| 23115 |
tmp = gen_rtx_REG (word_mode, tmp_regno); |
| 23116 |
if (GET_MODE (fnaddr) != word_mode) |
| 23117 |
fnaddr = gen_rtx_ZERO_EXTEND (word_mode, fnaddr); |
| 23118 |
emit_move_insn (tmp, fnaddr); |
| 23119 |
fnaddr = tmp; |
| 23120 |
} |
| 23121 |
|
| 23122 |
tmp = gen_rtx_MEM (QImode, fnaddr); |
| 23123 |
tmp = gen_rtx_CALL (VOIDmode, tmp, const0_rtx); |
| 23124 |
tmp = emit_call_insn (tmp); |
| 23125 |
SIBLING_CALL_P (tmp) = 1; |
| 23126 |
} |
| 23127 |
emit_barrier (); |
| 23128 |
|
| 23129 |
/* Emit just enough of rest_of_compilation to get the insns emitted. */ |
| 23130 |
insn = get_insns (); |
| 23131 |
shorten_branches (insn); |
| 23132 |
assemble_start_function (thunk_fndecl, fnname); |
| 23133 |
final_start_function (insn, file, 1); |
| 23134 |
final (insn, file, 1); |
| 23135 |
final_end_function (); |
| 23136 |
assemble_end_function (thunk_fndecl, fnname); |
| 23137 |
|
| 23138 |
flag_force_indirect_call = saved_flag_force_indirect_call; |
| 23139 |
} |
| 23140 |
|
| 23141 |
static void |
| 23142 |
x86_file_start (void) |
| 23143 |
{ |
| 23144 |
default_file_start (); |
| 23145 |
if (TARGET_16BIT) |
| 23146 |
fputs ("\t.code16gcc\n", asm_out_file); |
| 23147 |
#if TARGET_MACHO |
| 23148 |
darwin_file_start (); |
| 23149 |
#endif |
| 23150 |
if (X86_FILE_START_VERSION_DIRECTIVE) |
| 23151 |
fputs ("\t.version\t\"01.01\"\n", asm_out_file); |
| 23152 |
if (X86_FILE_START_FLTUSED) |
| 23153 |
fputs ("\t.global\t__fltused\n", asm_out_file); |
| 23154 |
if (ix86_asm_dialect == ASM_INTEL) |
| 23155 |
fputs ("\t.intel_syntax noprefix\n", asm_out_file); |
| 23156 |
} |
| 23157 |
|
| 23158 |
int |
| 23159 |
x86_field_alignment (tree type, int computed) |
| 23160 |
{ |
| 23161 |
machine_mode mode; |
| 23162 |
|
| 23163 |
if (TARGET_64BIT || TARGET_ALIGN_DOUBLE) |
| 23164 |
return computed; |
| 23165 |
if (TARGET_IAMCU) |
| 23166 |
return iamcu_alignment (type, computed); |
| 23167 |
type = strip_array_types (type); |
| 23168 |
mode = TYPE_MODE (type); |
| 23169 |
if (mode == DFmode || mode == DCmode |
| 23170 |
|| GET_MODE_CLASS (mode) == MODE_INT |
| 23171 |
|| GET_MODE_CLASS (mode) == MODE_COMPLEX_INT) |
| 23172 |
{ |
| 23173 |
if (TYPE_ATOMIC (type) && computed > 32) |
| 23174 |
{ |
| 23175 |
static bool warned; |
| 23176 |
|
| 23177 |
if (!warned && warn_psabi) |
| 23178 |
{ |
| 23179 |
const char *url |
| 23180 |
= CHANGES_ROOT_URL "gcc-11/changes.html#ia32_atomic"; |
| 23181 |
|
| 23182 |
warned = true; |
| 23183 |
inform (input_location, "the alignment of %<_Atomic %T%> " |
| 23184 |
"fields changed in %{GCC 11.1%}", |
| 23185 |
TYPE_MAIN_VARIANT (type), url); |
| 23186 |
} |
| 23187 |
} |
| 23188 |
else |
| 23189 |
return MIN (32, computed); |
| 23190 |
} |
| 23191 |
return computed; |
| 23192 |
} |
| 23193 |
|
| 23194 |
/* Print call to TARGET to FILE. */ |
| 23195 |
|
| 23196 |
static void |
| 23197 |
x86_print_call_or_nop (FILE *file, const char *target) |
| 23198 |
{ |
| 23199 |
if (flag_nop_mcount || !strcmp (target, "nop")) |
| 23200 |
/* 5 byte nop: nopl 0(%[re]ax,%[re]ax,1) */ |
| 23201 |
fprintf (file, "1:" ASM_BYTE "0x0f, 0x1f, 0x44, 0x00, 0x00\n"); |
| 23202 |
else if (!TARGET_PECOFF && flag_pic) |
| 23203 |
{ |
| 23204 |
gcc_assert (flag_plt); |
| 23205 |
|
| 23206 |
fprintf (file, "1:\tcall\t%s@PLT\n", target); |
| 23207 |
} |
| 23208 |
else |
| 23209 |
fprintf (file, "1:\tcall\t%s\n", target); |
| 23210 |
} |
| 23211 |
|
| 23212 |
static bool |
| 23213 |
current_fentry_name (const char **name) |
| 23214 |
{ |
| 23215 |
tree attr = lookup_attribute ("fentry_name", |
| 23216 |
DECL_ATTRIBUTES (current_function_decl)); |
| 23217 |
if (!attr) |
| 23218 |
return false; |
| 23219 |
*name = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))); |
| 23220 |
return true; |
| 23221 |
} |
| 23222 |
|
| 23223 |
static bool |
| 23224 |
current_fentry_section (const char **name) |
| 23225 |
{ |
| 23226 |
tree attr = lookup_attribute ("fentry_section", |
| 23227 |
DECL_ATTRIBUTES (current_function_decl)); |
| 23228 |
if (!attr) |
| 23229 |
return false; |
| 23230 |
*name = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))); |
| 23231 |
return true; |
| 23232 |
} |
| 23233 |
|
| 23234 |
/* Return a caller-saved register which isn't live or a callee-saved |
| 23235 |
register which has been saved on stack in the prologue at entry for |
| 23236 |
profile. */ |
| 23237 |
|
| 23238 |
static int |
| 23239 |
x86_64_select_profile_regnum (bool r11_ok ATTRIBUTE_UNUSED) |
| 23240 |
{ |
| 23241 |
/* Use %r10 if the profiler is emitted before the prologue or it isn't |
| 23242 |
used by DRAP. */ |
| 23243 |
if (ix86_profile_before_prologue () |
| 23244 |
|| !crtl->drap_reg |
| 23245 |
|| REGNO (crtl->drap_reg) != R10_REG) |
| 23246 |
return R10_REG; |
| 23247 |
|
| 23248 |
/* The profiler is emitted after the prologue. If there is a |
| 23249 |
caller-saved register which isn't live or a callee-saved |
| 23250 |
register saved on stack in the prologue, use it. */ |
| 23251 |
|
| 23252 |
bitmap reg_live = df_get_live_out (ENTRY_BLOCK_PTR_FOR_FN (cfun)); |
| 23253 |
|
| 23254 |
int i; |
| 23255 |
for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) |
| 23256 |
if (GENERAL_REGNO_P (i) |
| 23257 |
&& i != R10_REG |
| 23258 |
#ifdef NO_PROFILE_COUNTERS |
| 23259 |
&& (r11_ok || i != R11_REG) |
| 23260 |
#else |
| 23261 |
&& i != R11_REG |
| 23262 |
#endif |
| 23263 |
&& TEST_HARD_REG_BIT (accessible_reg_set, i) |
| 23264 |
&& (ix86_save_reg (i, true, true) |
| 23265 |
|| (call_used_regs[i] |
| 23266 |
&& !fixed_regs[i] |
| 23267 |
&& !REGNO_REG_SET_P (reg_live, i)))) |
| 23268 |
return i; |
| 23269 |
|
| 23270 |
sorry ("no register available for profiling %<-mcmodel=large%s%>", |
| 23271 |
ix86_cmodel == CM_LARGE_PIC ? " -fPIC" : ""); |
| 23272 |
|
| 23273 |
return R10_REG; |
| 23274 |
} |
| 23275 |
|
| 23276 |
/* Output assembler code to FILE to increment profiler label # LABELNO |
| 23277 |
for profiling a function entry. */ |
| 23278 |
void |
| 23279 |
x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED) |
| 23280 |
{ |
| 23281 |
if (cfun->machine->insn_queued_at_entrance) |
| 23282 |
{ |
| 23283 |
if (cfun->machine->insn_queued_at_entrance == TYPE_ENDBR) |
| 23284 |
fprintf (file, "\t%s\n", TARGET_64BIT ? "endbr64" : "endbr32"); |
| 23285 |
unsigned int patch_area_size |
| 23286 |
= crtl->patch_area_size - crtl->patch_area_entry; |
| 23287 |
if (patch_area_size) |
| 23288 |
ix86_output_patchable_area (patch_area_size, |
| 23289 |
crtl->patch_area_entry == 0); |
| 23290 |
} |
| 23291 |
|
| 23292 |
const char *mcount_name = MCOUNT_NAME; |
| 23293 |
|
| 23294 |
if (current_fentry_name (&mcount_name)) |
| 23295 |
; |
| 23296 |
else if (fentry_name) |
| 23297 |
mcount_name = fentry_name; |
| 23298 |
else if (flag_fentry) |
| 23299 |
mcount_name = MCOUNT_NAME_BEFORE_PROLOGUE; |
| 23300 |
|
| 23301 |
if (TARGET_64BIT) |
| 23302 |
{ |
| 23303 |
#ifndef NO_PROFILE_COUNTERS |
| 23304 |
if (ASSEMBLER_DIALECT == ASM_INTEL) |
| 23305 |
fprintf (file, "\tlea\tr11, %sP%d[rip]\n", LPREFIX, labelno); |
| 23306 |
else |
| 23307 |
fprintf (file, "\tleaq\t%sP%d(%%rip), %%r11\n", LPREFIX, labelno); |
| 23308 |
#endif |
| 23309 |
|
| 23310 |
int scratch; |
| 23311 |
const char *reg; |
| 23312 |
char legacy_reg[4] = { 0 }; |
| 23313 |
|
| 23314 |
if (!TARGET_PECOFF) |
| 23315 |
{ |
| 23316 |
switch (ix86_cmodel) |
| 23317 |
{ |
| 23318 |
case CM_LARGE: |
| 23319 |
scratch = x86_64_select_profile_regnum (true); |
| 23320 |
reg = hi_reg_name[scratch]; |
| 23321 |
if (LEGACY_INT_REGNO_P (scratch)) |
| 23322 |
{ |
| 23323 |
legacy_reg[0] = 'r'; |
| 23324 |
legacy_reg[1] = reg[0]; |
| 23325 |
legacy_reg[2] = reg[1]; |
| 23326 |
reg = legacy_reg; |
| 23327 |
} |
| 23328 |
if (ASSEMBLER_DIALECT == ASM_INTEL) |
| 23329 |
fprintf (file, "1:\tmovabs\t%s, OFFSET FLAT:%s\n" |
| 23330 |
"\tcall\t%s\n", reg, mcount_name, reg); |
| 23331 |
else |
| 23332 |
fprintf (file, "1:\tmovabsq\t$%s, %%%s\n\tcall\t*%%%s\n", |
| 23333 |
mcount_name, reg, reg); |
| 23334 |
break; |
| 23335 |
case CM_LARGE_PIC: |
| 23336 |
#ifdef NO_PROFILE_COUNTERS |
| 23337 |
scratch = x86_64_select_profile_regnum (false); |
| 23338 |
reg = hi_reg_name[scratch]; |
| 23339 |
if (LEGACY_INT_REGNO_P (scratch)) |
| 23340 |
{ |
| 23341 |
legacy_reg[0] = 'r'; |
| 23342 |
legacy_reg[1] = reg[0]; |
| 23343 |
legacy_reg[2] = reg[1]; |
| 23344 |
reg = legacy_reg; |
| 23345 |
} |
| 23346 |
if (ASSEMBLER_DIALECT == ASM_INTEL) |
| 23347 |
{ |
| 23348 |
fprintf (file, "1:movabs\tr11, " |
| 23349 |
"OFFSET FLAT:_GLOBAL_OFFSET_TABLE_-1b\n"); |
| 23350 |
fprintf (file, "\tlea\t%s, 1b[rip]\n", reg); |
| 23351 |
fprintf (file, "\tadd\t%s, r11\n", reg); |
| 23352 |
fprintf (file, "\tmovabs\tr11, OFFSET FLAT:%s@PLTOFF\n", |
| 23353 |
mcount_name); |
| 23354 |
fprintf (file, "\tadd\t%s, r11\n", reg); |
| 23355 |
fprintf (file, "\tcall\t%s\n", reg); |
| 23356 |
break; |
| 23357 |
} |
| 23358 |
fprintf (file, |
| 23359 |
"1:\tmovabsq\t$_GLOBAL_OFFSET_TABLE_-1b, %%r11\n"); |
| 23360 |
fprintf (file, "\tleaq\t1b(%%rip), %%%s\n", reg); |
| 23361 |
fprintf (file, "\taddq\t%%r11, %%%s\n", reg); |
| 23362 |
fprintf (file, "\tmovabsq\t$%s@PLTOFF, %%r11\n", mcount_name); |
| 23363 |
fprintf (file, "\taddq\t%%r11, %%%s\n", reg); |
| 23364 |
fprintf (file, "\tcall\t*%%%s\n", reg); |
| 23365 |
#else |
| 23366 |
sorry ("profiling %<-mcmodel=large%> with PIC is not supported"); |
| 23367 |
#endif |
| 23368 |
break; |
| 23369 |
case CM_SMALL_PIC: |
| 23370 |
case CM_MEDIUM_PIC: |
| 23371 |
if (!flag_plt) |
| 23372 |
{ |
| 23373 |
if (ASSEMBLER_DIALECT == ASM_INTEL) |
| 23374 |
fprintf (file, "1:\tcall\t[QWORD PTR %s@GOTPCREL[rip]]\n", |
| 23375 |
mcount_name); |
| 23376 |
else |
| 23377 |
fprintf (file, "1:\tcall\t*%s@GOTPCREL(%%rip)\n", |
| 23378 |
mcount_name); |
| 23379 |
break; |
| 23380 |
} |
| 23381 |
/* fall through */ |
| 23382 |
default: |
| 23383 |
x86_print_call_or_nop (file, mcount_name); |
| 23384 |
break; |
| 23385 |
} |
| 23386 |
} |
| 23387 |
else |
| 23388 |
x86_print_call_or_nop (file, mcount_name); |
| 23389 |
} |
| 23390 |
else if (flag_pic) |
| 23391 |
{ |
| 23392 |
#ifndef NO_PROFILE_COUNTERS |
| 23393 |
if (ASSEMBLER_DIALECT == ASM_INTEL) |
| 23394 |
fprintf (file, |
| 23395 |
"\tlea\t" PROFILE_COUNT_REGISTER ", %sP%d@GOTOFF[ebx]\n", |
| 23396 |
LPREFIX, labelno); |
| 23397 |
else |
| 23398 |
fprintf (file, |
| 23399 |
"\tleal\t%sP%d@GOTOFF(%%ebx), %%" PROFILE_COUNT_REGISTER "\n", |
| 23400 |
LPREFIX, labelno); |
| 23401 |
#endif |
| 23402 |
if (flag_plt) |
| 23403 |
x86_print_call_or_nop (file, mcount_name); |
| 23404 |
else if (ASSEMBLER_DIALECT == ASM_INTEL) |
| 23405 |
fprintf (file, "1:\tcall\t[DWORD PTR %s@GOT[ebx]]\n", mcount_name); |
| 23406 |
else |
| 23407 |
fprintf (file, "1:\tcall\t*%s@GOT(%%ebx)\n", mcount_name); |
| 23408 |
} |
| 23409 |
else |
| 23410 |
{ |
| 23411 |
#ifndef NO_PROFILE_COUNTERS |
| 23412 |
if (ASSEMBLER_DIALECT == ASM_INTEL) |
| 23413 |
fprintf (file, |
| 23414 |
"\tmov\t" PROFILE_COUNT_REGISTER ", OFFSET FLAT:%sP%d\n", |
| 23415 |
LPREFIX, labelno); |
| 23416 |
else |
| 23417 |
fprintf (file, "\tmovl\t$%sP%d, %%" PROFILE_COUNT_REGISTER "\n", |
| 23418 |
LPREFIX, labelno); |
| 23419 |
#endif |
| 23420 |
x86_print_call_or_nop (file, mcount_name); |
| 23421 |
} |
| 23422 |
|
| 23423 |
if (flag_record_mcount |
| 23424 |
|| lookup_attribute ("fentry_section", |
| 23425 |
DECL_ATTRIBUTES (current_function_decl))) |
| 23426 |
{ |
| 23427 |
const char *sname = "__mcount_loc"; |
| 23428 |
|
| 23429 |
if (current_fentry_section (&sname)) |
| 23430 |
; |
| 23431 |
else if (fentry_section) |
| 23432 |
sname = fentry_section; |
| 23433 |
|
| 23434 |
fprintf (file, "\t.section %s, \"a\",@progbits\n", sname); |
| 23435 |
fprintf (file, "\t.%s 1b\n", TARGET_64BIT ? "quad" : "long"); |
| 23436 |
fprintf (file, "\t.previous\n"); |
| 23437 |
} |
| 23438 |
} |
| 23439 |
|
| 23440 |
/* We don't have exact information about the insn sizes, but we may assume |
| 23441 |
quite safely that we are informed about all 1 byte insns and memory |
| 23442 |
address sizes. This is enough to eliminate unnecessary padding in |
| 23443 |
99% of cases. */ |
| 23444 |
|
| 23445 |
int |
| 23446 |
ix86_min_insn_size (rtx_insn *insn) |
| 23447 |
{ |
| 23448 |
int l = 0, len; |
| 23449 |
|
| 23450 |
if (!INSN_P (insn) || !active_insn_p (insn)) |
| 23451 |
return 0; |
| 23452 |
|
| 23453 |
/* Discard alignments we've emit and jump instructions. */ |
| 23454 |
if (GET_CODE (PATTERN (insn)) == UNSPEC_VOLATILE |
| 23455 |
&& XINT (PATTERN (insn), 1) == UNSPECV_ALIGN) |
| 23456 |
return 0; |
| 23457 |
|
| 23458 |
/* Important case - calls are always 5 bytes. |
| 23459 |
It is common to have many calls in the row. */ |
| 23460 |
if (CALL_P (insn) |
| 23461 |
&& symbolic_reference_mentioned_p (PATTERN (insn)) |
| 23462 |
&& !SIBLING_CALL_P (insn)) |
| 23463 |
return 5; |
| 23464 |
len = get_attr_length (insn); |
| 23465 |
if (len <= 1) |
| 23466 |
return 1; |
| 23467 |
|
| 23468 |
/* For normal instructions we rely on get_attr_length being exact, |
| 23469 |
with a few exceptions. */ |
| 23470 |
if (!JUMP_P (insn)) |
| 23471 |
{ |
| 23472 |
enum attr_type type = get_attr_type (insn); |
| 23473 |
|
| 23474 |
switch (type) |
| 23475 |
{ |
| 23476 |
case TYPE_MULTI: |
| 23477 |
if (GET_CODE (PATTERN (insn)) == ASM_INPUT |
| 23478 |
|| asm_noperands (PATTERN (insn)) >= 0) |
| 23479 |
return 0; |
| 23480 |
break; |
| 23481 |
case TYPE_OTHER: |
| 23482 |
case TYPE_FCMP: |
| 23483 |
break; |
| 23484 |
default: |
| 23485 |
/* Otherwise trust get_attr_length. */ |
| 23486 |
return len; |
| 23487 |
} |
| 23488 |
|
| 23489 |
l = get_attr_length_address (insn); |
| 23490 |
if (l < 4 && symbolic_reference_mentioned_p (PATTERN (insn))) |
| 23491 |
l = 4; |
| 23492 |
} |
| 23493 |
if (l) |
| 23494 |
return 1+l; |
| 23495 |
else |
| 23496 |
return 2; |
| 23497 |
} |
| 23498 |
|
| 23499 |
#ifdef ASM_OUTPUT_MAX_SKIP_ALIGN |
| 23500 |
|
| 23501 |
/* AMD K8 core mispredicts jumps when there are more than 3 jumps in 16 byte |
| 23502 |
window. */ |
| 23503 |
|
| 23504 |
static void |
| 23505 |
ix86_avoid_jump_mispredicts (void) |
| 23506 |
{ |
| 23507 |
rtx_insn *insn, *start = get_insns (); |
| 23508 |
int nbytes = 0, njumps = 0; |
| 23509 |
bool isjump = false; |
| 23510 |
|
| 23511 |
/* Look for all minimal intervals of instructions containing 4 jumps. |
| 23512 |
The intervals are bounded by START and INSN. NBYTES is the total |
| 23513 |
size of instructions in the interval including INSN and not including |
| 23514 |
START. When the NBYTES is smaller than 16 bytes, it is possible |
| 23515 |
that the end of START and INSN ends up in the same 16byte page. |
| 23516 |
|
| 23517 |
The smallest offset in the page INSN can start is the case where START |
| 23518 |
ends on the offset 0. Offset of INSN is then NBYTES - sizeof (INSN). |
| 23519 |
We add p2align to 16byte window with maxskip 15 - NBYTES + sizeof (INSN). |
| 23520 |
|
| 23521 |
Don't consider asm goto as jump, while it can contain a jump, it doesn't |
| 23522 |
have to, control transfer to label(s) can be performed through other |
| 23523 |
means, and also we estimate minimum length of all asm stmts as 0. */ |
| 23524 |
for (insn = start; insn; insn = NEXT_INSN (insn)) |
| 23525 |
{ |
| 23526 |
int min_size; |
| 23527 |
|
| 23528 |
if (LABEL_P (insn)) |
| 23529 |
{ |
| 23530 |
align_flags alignment = label_to_alignment (insn); |
| 23531 |
int align = alignment.levels[0].log; |
| 23532 |
int max_skip = alignment.levels[0].maxskip; |
| 23533 |
|
| 23534 |
if (max_skip > 15) |
| 23535 |
max_skip = 15; |
| 23536 |
/* If align > 3, only up to 16 - max_skip - 1 bytes can be |
| 23537 |
already in the current 16 byte page, because otherwise |
| 23538 |
ASM_OUTPUT_MAX_SKIP_ALIGN could skip max_skip or fewer |
| 23539 |
bytes to reach 16 byte boundary. */ |
| 23540 |
if (align <= 0 |
| 23541 |
|| (align <= 3 && max_skip != (1 << align) - 1)) |
| 23542 |
max_skip = 0; |
| 23543 |
if (dump_file) |
| 23544 |
fprintf (dump_file, "Label %i with max_skip %i\n", |
| 23545 |
INSN_UID (insn), max_skip); |
| 23546 |
if (max_skip) |
| 23547 |
{ |
| 23548 |
while (nbytes + max_skip >= 16) |
| 23549 |
{ |
| 23550 |
start = NEXT_INSN (start); |
| 23551 |
if ((JUMP_P (start) && asm_noperands (PATTERN (start)) < 0) |
| 23552 |
|| CALL_P (start)) |
| 23553 |
njumps--, isjump = true; |
| 23554 |
else |
| 23555 |
isjump = false; |
| 23556 |
nbytes -= ix86_min_insn_size (start); |
| 23557 |
} |
| 23558 |
} |
| 23559 |
continue; |
| 23560 |
} |
| 23561 |
|
| 23562 |
min_size = ix86_min_insn_size (insn); |
| 23563 |
nbytes += min_size; |
| 23564 |
if (dump_file) |
| 23565 |
fprintf (dump_file, "Insn %i estimated to %i bytes\n", |
| 23566 |
INSN_UID (insn), min_size); |
| 23567 |
if ((JUMP_P (insn) && asm_noperands (PATTERN (insn)) < 0) |
| 23568 |
|| CALL_P (insn)) |
| 23569 |
njumps++; |
| 23570 |
else |
| 23571 |
continue; |
| 23572 |
|
| 23573 |
while (njumps > 3) |
| 23574 |
{ |
| 23575 |
start = NEXT_INSN (start); |
| 23576 |
if ((JUMP_P (start) && asm_noperands (PATTERN (start)) < 0) |
| 23577 |
|| CALL_P (start)) |
| 23578 |
njumps--, isjump = true; |
| 23579 |
else |
| 23580 |
isjump = false; |
| 23581 |
nbytes -= ix86_min_insn_size (start); |
| 23582 |
} |
| 23583 |
gcc_assert (njumps >= 0); |
| 23584 |
if (dump_file) |
| 23585 |
fprintf (dump_file, "Interval %i to %i has %i bytes\n", |
| 23586 |
INSN_UID (start), INSN_UID (insn), nbytes); |
| 23587 |
|
| 23588 |
if (njumps == 3 && isjump && nbytes < 16) |
| 23589 |
{ |
| 23590 |
int padsize = 15 - nbytes + ix86_min_insn_size (insn); |
| 23591 |
|
| 23592 |
if (dump_file) |
| 23593 |
fprintf (dump_file, "Padding insn %i by %i bytes!\n", |
| 23594 |
INSN_UID (insn), padsize); |
| 23595 |
emit_insn_before (gen_max_skip_align (GEN_INT (4), GEN_INT (padsize)), insn); |
| 23596 |
} |
| 23597 |
} |
| 23598 |
} |
| 23599 |
#endif |
| 23600 |
|
| 23601 |
/* AMD Athlon works faster |
| 23602 |
when RET is not destination of conditional jump or directly preceded |
| 23603 |
by other jump instruction. We avoid the penalty by inserting NOP just |
| 23604 |
before the RET instructions in such cases. */ |
| 23605 |
static void |
| 23606 |
ix86_pad_returns (void) |
| 23607 |
{ |
| 23608 |
edge e; |
| 23609 |
edge_iterator ei; |
| 23610 |
|
| 23611 |
FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds) |
| 23612 |
{ |
| 23613 |
basic_block bb = e->src; |
| 23614 |
rtx_insn *ret = BB_END (bb); |
| 23615 |
rtx_insn *prev; |
| 23616 |
bool replace = false; |
| 23617 |
|
| 23618 |
if (!JUMP_P (ret) || !ANY_RETURN_P (PATTERN (ret)) |
| 23619 |
|| optimize_bb_for_size_p (bb)) |
| 23620 |
continue; |
| 23621 |
for (prev = PREV_INSN (ret); prev; prev = PREV_INSN (prev)) |
| 23622 |
if (active_insn_p (prev) || LABEL_P (prev)) |
| 23623 |
break; |
| 23624 |
if (prev && LABEL_P (prev)) |
| 23625 |
{ |
| 23626 |
edge e; |
| 23627 |
edge_iterator ei; |
| 23628 |
|
| 23629 |
FOR_EACH_EDGE (e, ei, bb->preds) |
| 23630 |
if (EDGE_FREQUENCY (e) && e->src->index >= 0 |
| 23631 |
&& !(e->flags & EDGE_FALLTHRU)) |
| 23632 |
{ |
| 23633 |
replace = true; |
| 23634 |
break; |
| 23635 |
} |
| 23636 |
} |
| 23637 |
if (!replace) |
| 23638 |
{ |
| 23639 |
prev = prev_active_insn (ret); |
| 23640 |
if (prev |
| 23641 |
&& ((JUMP_P (prev) && any_condjump_p (prev)) |
| 23642 |
|| CALL_P (prev))) |
| 23643 |
replace = true; |
| 23644 |
/* Empty functions get branch mispredict even when |
| 23645 |
the jump destination is not visible to us. */ |
| 23646 |
if (!prev && !optimize_function_for_size_p (cfun)) |
| 23647 |
replace = true; |
| 23648 |
} |
| 23649 |
if (replace) |
| 23650 |
{ |
| 23651 |
emit_jump_insn_before (gen_simple_return_internal_long (), ret); |
| 23652 |
delete_insn (ret); |
| 23653 |
} |
| 23654 |
} |
| 23655 |
} |
| 23656 |
|
| 23657 |
/* Count the minimum number of instructions in BB. Return 4 if the |
| 23658 |
number of instructions >= 4. */ |
| 23659 |
|
| 23660 |
static int |
| 23661 |
ix86_count_insn_bb (basic_block bb) |
| 23662 |
{ |
| 23663 |
rtx_insn *insn; |
| 23664 |
int insn_count = 0; |
| 23665 |
|
| 23666 |
/* Count number of instructions in this block. Return 4 if the number |
| 23667 |
of instructions >= 4. */ |
| 23668 |
FOR_BB_INSNS (bb, insn) |
| 23669 |
{ |
| 23670 |
/* Only happen in exit blocks. */ |
| 23671 |
if (JUMP_P (insn) |
| 23672 |
&& ANY_RETURN_P (PATTERN (insn))) |
| 23673 |
break; |
| 23674 |
|
| 23675 |
if (NONDEBUG_INSN_P (insn) |
| 23676 |
&& GET_CODE (PATTERN (insn)) != USE |
| 23677 |
&& GET_CODE (PATTERN (insn)) != CLOBBER) |
| 23678 |
{ |
| 23679 |
insn_count++; |
| 23680 |
if (insn_count >= 4) |
| 23681 |
return insn_count; |
| 23682 |
} |
| 23683 |
} |
| 23684 |
|
| 23685 |
return insn_count; |
| 23686 |
} |
| 23687 |
|
| 23688 |
|
| 23689 |
/* Count the minimum number of instructions in code path in BB. |
| 23690 |
Return 4 if the number of instructions >= 4. */ |
| 23691 |
|
| 23692 |
static int |
| 23693 |
ix86_count_insn (basic_block bb) |
| 23694 |
{ |
| 23695 |
edge e; |
| 23696 |
edge_iterator ei; |
| 23697 |
int min_prev_count; |
| 23698 |
|
| 23699 |
/* Only bother counting instructions along paths with no |
| 23700 |
more than 2 basic blocks between entry and exit. Given |
| 23701 |
that BB has an edge to exit, determine if a predecessor |
| 23702 |
of BB has an edge from entry. If so, compute the number |
| 23703 |
of instructions in the predecessor block. If there |
| 23704 |
happen to be multiple such blocks, compute the minimum. */ |
| 23705 |
min_prev_count = 4; |
| 23706 |
FOR_EACH_EDGE (e, ei, bb->preds) |
| 23707 |
{ |
| 23708 |
edge prev_e; |
| 23709 |
edge_iterator prev_ei; |
| 23710 |
|
| 23711 |
if (e->src == ENTRY_BLOCK_PTR_FOR_FN (cfun)) |
| 23712 |
{ |
| 23713 |
min_prev_count = 0; |
| 23714 |
break; |
| 23715 |
} |
| 23716 |
FOR_EACH_EDGE (prev_e, prev_ei, e->src->preds) |
| 23717 |
{ |
| 23718 |
if (prev_e->src == ENTRY_BLOCK_PTR_FOR_FN (cfun)) |
| 23719 |
{ |
| 23720 |
int count = ix86_count_insn_bb (e->src); |
| 23721 |
if (count < min_prev_count) |
| 23722 |
min_prev_count = count; |
| 23723 |
break; |
| 23724 |
} |
| 23725 |
} |
| 23726 |
} |
| 23727 |
|
| 23728 |
if (min_prev_count < 4) |
| 23729 |
min_prev_count += ix86_count_insn_bb (bb); |
| 23730 |
|
| 23731 |
return min_prev_count; |
| 23732 |
} |
| 23733 |
|
| 23734 |
/* Pad short function to 4 instructions. */ |
| 23735 |
|
| 23736 |
static void |
| 23737 |
ix86_pad_short_function (void) |
| 23738 |
{ |
| 23739 |
edge e; |
| 23740 |
edge_iterator ei; |
| 23741 |
|
| 23742 |
FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds) |
| 23743 |
{ |
| 23744 |
rtx_insn *ret = BB_END (e->src); |
| 23745 |
if (JUMP_P (ret) && ANY_RETURN_P (PATTERN (ret))) |
| 23746 |
{ |
| 23747 |
int insn_count = ix86_count_insn (e->src); |
| 23748 |
|
| 23749 |
/* Pad short function. */ |
| 23750 |
if (insn_count < 4) |
| 23751 |
{ |
| 23752 |
rtx_insn *insn = ret; |
| 23753 |
|
| 23754 |
/* Find epilogue. */ |
| 23755 |
while (insn |
| 23756 |
&& (!NOTE_P (insn) |
| 23757 |
|| NOTE_KIND (insn) != NOTE_INSN_EPILOGUE_BEG)) |
| 23758 |
insn = PREV_INSN (insn); |
| 23759 |
|
| 23760 |
if (!insn) |
| 23761 |
insn = ret; |
| 23762 |
|
| 23763 |
/* Two NOPs count as one instruction. */ |
| 23764 |
insn_count = 2 * (4 - insn_count); |
| 23765 |
emit_insn_before (gen_nops (GEN_INT (insn_count)), insn); |
| 23766 |
} |
| 23767 |
} |
| 23768 |
} |
| 23769 |
} |
| 23770 |
|
| 23771 |
/* Fix up a Windows system unwinder issue. If an EH region falls through into |
| 23772 |
the epilogue, the Windows system unwinder will apply epilogue logic and |
| 23773 |
produce incorrect offsets. This can be avoided by adding a nop between |
| 23774 |
the last insn that can throw and the first insn of the epilogue. */ |
| 23775 |
|
| 23776 |
static void |
| 23777 |
ix86_seh_fixup_eh_fallthru (void) |
| 23778 |
{ |
| 23779 |
edge e; |
| 23780 |
edge_iterator ei; |
| 23781 |
|
| 23782 |
FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds) |
| 23783 |
{ |
| 23784 |
rtx_insn *insn, *next; |
| 23785 |
|
| 23786 |
/* Find the beginning of the epilogue. */ |
| 23787 |
for (insn = BB_END (e->src); insn != NULL; insn = PREV_INSN (insn)) |
| 23788 |
if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_EPILOGUE_BEG) |
| 23789 |
break; |
| 23790 |
if (insn == NULL) |
| 23791 |
continue; |
| 23792 |
|
| 23793 |
/* We only care about preceding insns that can throw. */ |
| 23794 |
insn = prev_active_insn (insn); |
| 23795 |
if (insn == NULL || !can_throw_internal (insn)) |
| 23796 |
continue; |
| 23797 |
|
| 23798 |
/* Do not separate calls from their debug information. */ |
| 23799 |
for (next = NEXT_INSN (insn); next != NULL; next = NEXT_INSN (next)) |
| 23800 |
if (NOTE_P (next) && NOTE_KIND (next) == NOTE_INSN_VAR_LOCATION) |
| 23801 |
insn = next; |
| 23802 |
else |
| 23803 |
break; |
| 23804 |
|
| 23805 |
emit_insn_after (gen_nops (const1_rtx), insn); |
| 23806 |
} |
| 23807 |
} |
| 23808 |
/* Split vector load from parm_decl to elemental loads to avoid STLF |
| 23809 |
stalls. */ |
| 23810 |
static void |
| 23811 |
ix86_split_stlf_stall_load () |
| 23812 |
{ |
| 23813 |
rtx_insn* insn, *start = get_insns (); |
| 23814 |
unsigned window = 0; |
| 23815 |
|
| 23816 |
for (insn = start; insn; insn = NEXT_INSN (insn)) |
| 23817 |
{ |
| 23818 |
if (!NONDEBUG_INSN_P (insn)) |
| 23819 |
continue; |
| 23820 |
window++; |
| 23821 |
/* Insert 64 vaddps %xmm18, %xmm19, %xmm20(no dependence between each |
| 23822 |
other, just emulate for pipeline) before stalled load, stlf stall |
| 23823 |
case is as fast as no stall cases on CLX. |
| 23824 |
Since CFG is freed before machine_reorg, just do a rough |
| 23825 |
calculation of the window according to the layout. */ |
| 23826 |
if (window > (unsigned) x86_stlf_window_ninsns) |
| 23827 |
return; |
| 23828 |
|
| 23829 |
if (any_uncondjump_p (insn) |
| 23830 |
|| ANY_RETURN_P (PATTERN (insn)) |
| 23831 |
|| CALL_P (insn)) |
| 23832 |
return; |
| 23833 |
|
| 23834 |
rtx set = single_set (insn); |
| 23835 |
if (!set) |
| 23836 |
continue; |
| 23837 |
rtx src = SET_SRC (set); |
| 23838 |
if (!MEM_P (src) |
| 23839 |
/* Only handle V2DFmode load since it doesn't need any scratch |
| 23840 |
register. */ |
| 23841 |
|| GET_MODE (src) != E_V2DFmode |
| 23842 |
|| !MEM_EXPR (src) |
| 23843 |
|| TREE_CODE (get_base_address (MEM_EXPR (src))) != PARM_DECL) |
| 23844 |
continue; |
| 23845 |
|
| 23846 |
rtx zero = CONST0_RTX (V2DFmode); |
| 23847 |
rtx dest = SET_DEST (set); |
| 23848 |
rtx m = adjust_address (src, DFmode, 0); |
| 23849 |
rtx loadlpd = gen_sse2_loadlpd (dest, zero, m); |
| 23850 |
emit_insn_before (loadlpd, insn); |
| 23851 |
m = adjust_address (src, DFmode, 8); |
| 23852 |
rtx loadhpd = gen_sse2_loadhpd (dest, dest, m); |
| 23853 |
if (dump_file && (dump_flags & TDF_DETAILS)) |
| 23854 |
{ |
| 23855 |
fputs ("Due to potential STLF stall, split instruction:\n", |
| 23856 |
dump_file); |
| 23857 |
print_rtl_single (dump_file, insn); |
| 23858 |
fputs ("To:\n", dump_file); |
| 23859 |
print_rtl_single (dump_file, loadlpd); |
| 23860 |
print_rtl_single (dump_file, loadhpd); |
| 23861 |
} |
| 23862 |
PATTERN (insn) = loadhpd; |
| 23863 |
INSN_CODE (insn) = -1; |
| 23864 |
gcc_assert (recog_memoized (insn) != -1); |
| 23865 |
} |
| 23866 |
} |
| 23867 |
|
| 23868 |
/* Implement machine specific optimizations. We implement padding of returns |
| 23869 |
for K8 CPUs and pass to avoid 4 jumps in the single 16 byte window. */ |
| 23870 |
static void |
| 23871 |
ix86_reorg (void) |
| 23872 |
{ |
| 23873 |
/* We are freeing block_for_insn in the toplev to keep compatibility |
| 23874 |
with old MDEP_REORGS that are not CFG based. Recompute it now. */ |
| 23875 |
compute_bb_for_insn (); |
| 23876 |
|
| 23877 |
if (TARGET_SEH && current_function_has_exception_handlers ()) |
| 23878 |
ix86_seh_fixup_eh_fallthru (); |
| 23879 |
|
| 23880 |
if (optimize && optimize_function_for_speed_p (cfun)) |
| 23881 |
{ |
| 23882 |
if (TARGET_SSE2) |
| 23883 |
ix86_split_stlf_stall_load (); |
| 23884 |
if (TARGET_PAD_SHORT_FUNCTION) |
| 23885 |
ix86_pad_short_function (); |
| 23886 |
else if (TARGET_PAD_RETURNS) |
| 23887 |
ix86_pad_returns (); |
| 23888 |
#ifdef ASM_OUTPUT_MAX_SKIP_ALIGN |
| 23889 |
if (TARGET_FOUR_JUMP_LIMIT) |
| 23890 |
ix86_avoid_jump_mispredicts (); |
| 23891 |
#endif |
| 23892 |
} |
| 23893 |
} |
| 23894 |
|
| 23895 |
/* Return nonzero when QImode register that must be represented via REX prefix |
| 23896 |
is used. */ |
| 23897 |
bool |
| 23898 |
x86_extended_QIreg_mentioned_p (rtx_insn *insn) |
| 23899 |
{ |
| 23900 |
int i; |
| 23901 |
extract_insn_cached (insn); |
| 23902 |
for (i = 0; i < recog_data.n_operands; i++) |
| 23903 |
if (GENERAL_REG_P (recog_data.operand[i]) |
| 23904 |
&& !QI_REGNO_P (REGNO (recog_data.operand[i]))) |
| 23905 |
return true; |
| 23906 |
return false; |
| 23907 |
} |
| 23908 |
|
| 23909 |
/* Return true when INSN mentions register that must be encoded using REX |
| 23910 |
prefix. */ |
| 23911 |
bool |
| 23912 |
x86_extended_reg_mentioned_p (rtx insn) |
| 23913 |
{ |
| 23914 |
subrtx_iterator::array_type array; |
| 23915 |
FOR_EACH_SUBRTX (iter, array, INSN_P (insn) ? PATTERN (insn) : insn, NONCONST) |
| 23916 |
{ |
| 23917 |
const_rtx x = *iter; |
| 23918 |
if (REG_P (x) |
| 23919 |
&& (REX_INT_REGNO_P (REGNO (x)) || REX_SSE_REGNO_P (REGNO (x)) |
| 23920 |
|| REX2_INT_REGNO_P (REGNO (x)))) |
| 23921 |
return true; |
| 23922 |
} |
| 23923 |
return false; |
| 23924 |
} |
| 23925 |
|
| 23926 |
/* Return true when INSN mentions register that must be encoded using REX2 |
| 23927 |
prefix. */ |
| 23928 |
bool |
| 23929 |
x86_extended_rex2reg_mentioned_p (rtx insn) |
| 23930 |
{ |
| 23931 |
subrtx_iterator::array_type array; |
| 23932 |
FOR_EACH_SUBRTX (iter, array, INSN_P (insn) ? PATTERN (insn) : insn, NONCONST) |
| 23933 |
{ |
| 23934 |
const_rtx x = *iter; |
| 23935 |
if (REG_P (x) && REX2_INT_REGNO_P (REGNO (x))) |
| 23936 |
return true; |
| 23937 |
} |
| 23938 |
return false; |
| 23939 |
} |
| 23940 |
|
| 23941 |
/* Return true when rtx operands mentions register that must be encoded using |
| 23942 |
evex prefix. */ |
| 23943 |
bool |
| 23944 |
x86_evex_reg_mentioned_p (rtx operands[], int nops) |
| 23945 |
{ |
| 23946 |
int i; |
| 23947 |
for (i = 0; i < nops; i++) |
| 23948 |
if (EXT_REX_SSE_REG_P (operands[i]) |
| 23949 |
|| x86_extended_rex2reg_mentioned_p (operands[i])) |
| 23950 |
return true; |
| 23951 |
return false; |
| 23952 |
} |
| 23953 |
|
| 23954 |
/* If profitable, negate (without causing overflow) integer constant |
| 23955 |
of mode MODE at location LOC. Return true in this case. */ |
| 23956 |
bool |
| 23957 |
x86_maybe_negate_const_int (rtx *loc, machine_mode mode) |
| 23958 |
{ |
| 23959 |
HOST_WIDE_INT val; |
| 23960 |
|
| 23961 |
if (!CONST_INT_P (*loc)) |
| 23962 |
return false; |
| 23963 |
|
| 23964 |
switch (mode) |
| 23965 |
{ |
| 23966 |
case E_DImode: |
| 23967 |
/* DImode x86_64 constants must fit in 32 bits. */ |
| 23968 |
gcc_assert (x86_64_immediate_operand (*loc, mode)); |
| 23969 |
|
| 23970 |
mode = SImode; |
| 23971 |
break; |
| 23972 |
|
| 23973 |
case E_SImode: |
| 23974 |
case E_HImode: |
| 23975 |
case E_QImode: |
| 23976 |
break; |
| 23977 |
|
| 23978 |
default: |
| 23979 |
gcc_unreachable (); |
| 23980 |
} |
| 23981 |
|
| 23982 |
/* Avoid overflows. */ |
| 23983 |
if (mode_signbit_p (mode, *loc)) |
| 23984 |
return false; |
| 23985 |
|
| 23986 |
val = INTVAL (*loc); |
| 23987 |
|
| 23988 |
/* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'. |
| 23989 |
Exceptions: -128 encodes smaller than 128, so swap sign and op. */ |
| 23990 |
if ((val < 0 && val != -128) |
| 23991 |
|| val == 128) |
| 23992 |
{ |
| 23993 |
*loc = GEN_INT (-val); |
| 23994 |
return true; |
| 23995 |
} |
| 23996 |
|
| 23997 |
return false; |
| 23998 |
} |
| 23999 |
|
| 24000 |
/* Generate an unsigned DImode/SImode to FP conversion. This is the same code |
| 24001 |
optabs would emit if we didn't have TFmode patterns. */ |
| 24002 |
|
| 24003 |
void |
| 24004 |
x86_emit_floatuns (rtx operands[2]) |
| 24005 |
{ |
| 24006 |
rtx_code_label *neglab, *donelab; |
| 24007 |
rtx i0, i1, f0, in, out; |
| 24008 |
machine_mode mode, inmode; |
| 24009 |
|
| 24010 |
inmode = GET_MODE (operands[1]); |
| 24011 |
gcc_assert (inmode == SImode || inmode == DImode); |
| 24012 |
|
| 24013 |
out = operands[0]; |
| 24014 |
in = force_reg (inmode, operands[1]); |
| 24015 |
mode = GET_MODE (out); |
| 24016 |
neglab = gen_label_rtx (); |
| 24017 |
donelab = gen_label_rtx (); |
| 24018 |
f0 = gen_reg_rtx (mode); |
| 24019 |
|
| 24020 |
emit_cmp_and_jump_insns (in, const0_rtx, LT, const0_rtx, inmode, 0, neglab); |
| 24021 |
|
| 24022 |
expand_float (out, in, 0); |
| 24023 |
|
| 24024 |
emit_jump_insn (gen_jump (donelab)); |
| 24025 |
emit_barrier (); |
| 24026 |
|
| 24027 |
emit_label (neglab); |
| 24028 |
|
| 24029 |
i0 = expand_simple_binop (inmode, LSHIFTRT, in, const1_rtx, NULL, |
| 24030 |
1, OPTAB_DIRECT); |
| 24031 |
i1 = expand_simple_binop (inmode, AND, in, const1_rtx, NULL, |
| 24032 |
1, OPTAB_DIRECT); |
| 24033 |
i0 = expand_simple_binop (inmode, IOR, i0, i1, i0, 1, OPTAB_DIRECT); |
| 24034 |
|
| 24035 |
expand_float (f0, i0, 0); |
| 24036 |
|
| 24037 |
emit_insn (gen_rtx_SET (out, gen_rtx_PLUS (mode, f0, f0))); |
| 24038 |
|
| 24039 |
emit_label (donelab); |
| 24040 |
} |
| 24041 |
|
| 24042 |
/* Return the diagnostic message string if conversion from FROMTYPE to |
| 24043 |
TOTYPE is not allowed, NULL otherwise. */ |
| 24044 |
|
| 24045 |
static const char * |
| 24046 |
ix86_invalid_conversion (const_tree fromtype, const_tree totype) |
| 24047 |
{ |
| 24048 |
machine_mode from_mode = element_mode (fromtype); |
| 24049 |
machine_mode to_mode = element_mode (totype); |
| 24050 |
|
| 24051 |
if (!TARGET_SSE2 && from_mode != to_mode) |
| 24052 |
{ |
| 24053 |
/* Do no allow conversions to/from BFmode/HFmode scalar types |
| 24054 |
when TARGET_SSE2 is not available. */ |
| 24055 |
if (from_mode == BFmode) |
| 24056 |
return N_("invalid conversion from type %<__bf16%> " |
| 24057 |
"without option %<-msse2%>"); |
| 24058 |
if (from_mode == HFmode) |
| 24059 |
return N_("invalid conversion from type %<_Float16%> " |
| 24060 |
"without option %<-msse2%>"); |
| 24061 |
if (to_mode == BFmode) |
| 24062 |
return N_("invalid conversion to type %<__bf16%> " |
| 24063 |
"without option %<-msse2%>"); |
| 24064 |
if (to_mode == HFmode) |
| 24065 |
return N_("invalid conversion to type %<_Float16%> " |
| 24066 |
"without option %<-msse2%>"); |
| 24067 |
} |
| 24068 |
|
| 24069 |
/* Warn for silent implicit conversion between __bf16 and short, |
| 24070 |
since __bfloat16 is refined as real __bf16 instead of short |
| 24071 |
since GCC13. */ |
| 24072 |
if (element_mode (fromtype) != element_mode (totype) |
| 24073 |
&& (TARGET_AVX512BF16 || TARGET_AVXNECONVERT)) |
| 24074 |
{ |
| 24075 |
/* Warn for silent implicit conversion where user may expect |
| 24076 |
a bitcast. */ |
| 24077 |
if ((TYPE_MODE (fromtype) == BFmode |
| 24078 |
&& TYPE_MODE (totype) == HImode) |
| 24079 |
|| (TYPE_MODE (totype) == BFmode |
| 24080 |
&& TYPE_MODE (fromtype) == HImode)) |
| 24081 |
warning (0, "%<__bfloat16%> is redefined from typedef %<short%> " |
| 24082 |
"to real %<__bf16%> since GCC 13.1, be careful of " |
| 24083 |
"implicit conversion between %<__bf16%> and %<short%>; " |
| 24084 |
"an explicit bitcast may be needed here"); |
| 24085 |
} |
| 24086 |
|
| 24087 |
/* Conversion allowed. */ |
| 24088 |
return NULL; |
| 24089 |
} |
| 24090 |
|
| 24091 |
/* Return the diagnostic message string if the unary operation OP is |
| 24092 |
not permitted on TYPE, NULL otherwise. */ |
| 24093 |
|
| 24094 |
static const char * |
| 24095 |
ix86_invalid_unary_op (int op, const_tree type) |
| 24096 |
{ |
| 24097 |
machine_mode mmode = element_mode (type); |
| 24098 |
/* Reject all single-operand operations on BFmode/HFmode except for & |
| 24099 |
when TARGET_SSE2 is not available. */ |
| 24100 |
if (!TARGET_SSE2 && op != ADDR_EXPR) |
| 24101 |
{ |
| 24102 |
if (mmode == BFmode) |
| 24103 |
return N_("operation not permitted on type %<__bf16%> " |
| 24104 |
"without option %<-msse2%>"); |
| 24105 |
if (mmode == HFmode) |
| 24106 |
return N_("operation not permitted on type %<_Float16%> " |
| 24107 |
"without option %<-msse2%>"); |
| 24108 |
} |
| 24109 |
|
| 24110 |
/* Operation allowed. */ |
| 24111 |
return NULL; |
| 24112 |
} |
| 24113 |
|
| 24114 |
/* Return the diagnostic message string if the binary operation OP is |
| 24115 |
not permitted on TYPE1 and TYPE2, NULL otherwise. */ |
| 24116 |
|
| 24117 |
static const char * |
| 24118 |
ix86_invalid_binary_op (int op ATTRIBUTE_UNUSED, const_tree type1, |
| 24119 |
const_tree type2) |
| 24120 |
{ |
| 24121 |
machine_mode type1_mode = element_mode (type1); |
| 24122 |
machine_mode type2_mode = element_mode (type2); |
| 24123 |
/* Reject all 2-operand operations on BFmode or HFmode |
| 24124 |
when TARGET_SSE2 is not available. */ |
| 24125 |
if (!TARGET_SSE2) |
| 24126 |
{ |
| 24127 |
if (type1_mode == BFmode || type2_mode == BFmode) |
| 24128 |
return N_("operation not permitted on type %<__bf16%> " |
| 24129 |
"without option %<-msse2%>"); |
| 24130 |
|
| 24131 |
if (type1_mode == HFmode || type2_mode == HFmode) |
| 24132 |
return N_("operation not permitted on type %<_Float16%> " |
| 24133 |
"without option %<-msse2%>"); |
| 24134 |
} |
| 24135 |
|
| 24136 |
/* Operation allowed. */ |
| 24137 |
return NULL; |
| 24138 |
} |
| 24139 |
|
| 24140 |
|
| 24141 |
/* Target hook for scalar_mode_supported_p. */ |
| 24142 |
static bool |
| 24143 |
ix86_scalar_mode_supported_p (scalar_mode mode) |
| 24144 |
{ |
| 24145 |
if (DECIMAL_FLOAT_MODE_P (mode)) |
| 24146 |
return default_decimal_float_supported_p (); |
| 24147 |
else if (mode == TFmode) |
| 24148 |
return true; |
| 24149 |
else if (mode == HFmode || mode == BFmode) |
| 24150 |
return true; |
| 24151 |
else |
| 24152 |
return default_scalar_mode_supported_p (mode); |
| 24153 |
} |
| 24154 |
|
| 24155 |
/* Implement TARGET_LIBGCC_FLOATING_POINT_MODE_SUPPORTED_P - return TRUE |
| 24156 |
if MODE is HFmode, and punt to the generic implementation otherwise. */ |
| 24157 |
|
| 24158 |
static bool |
| 24159 |
ix86_libgcc_floating_mode_supported_p (scalar_float_mode mode) |
| 24160 |
{ |
| 24161 |
/* NB: Always return TRUE for HFmode so that the _Float16 type will |
| 24162 |
be defined by the C front-end for AVX512FP16 intrinsics. We will |
| 24163 |
issue an error in ix86_expand_move for HFmode if AVX512FP16 isn't |
| 24164 |
enabled. */ |
| 24165 |
return ((mode == HFmode || mode == BFmode) |
| 24166 |
? true |
| 24167 |
: default_libgcc_floating_mode_supported_p (mode)); |
| 24168 |
} |
| 24169 |
|
| 24170 |
/* Implements target hook vector_mode_supported_p. */ |
| 24171 |
static bool |
| 24172 |
ix86_vector_mode_supported_p (machine_mode mode) |
| 24173 |
{ |
| 24174 |
/* For ia32, scalar TImode isn't supported and so V1TImode shouldn't be |
| 24175 |
either. */ |
| 24176 |
if (!TARGET_64BIT && GET_MODE_INNER (mode) == TImode) |
| 24177 |
return false; |
| 24178 |
if (TARGET_SSE && VALID_SSE_REG_MODE (mode)) |
| 24179 |
return true; |
| 24180 |
if (TARGET_SSE2 && VALID_SSE2_REG_MODE (mode)) |
| 24181 |
return true; |
| 24182 |
if (TARGET_AVX && VALID_AVX256_REG_MODE (mode)) |
| 24183 |
return true; |
| 24184 |
if (TARGET_AVX512F && TARGET_EVEX512 && VALID_AVX512F_REG_MODE (mode)) |
| 24185 |
return true; |
| 24186 |
if ((TARGET_MMX || TARGET_MMX_WITH_SSE) |
| 24187 |
&& VALID_MMX_REG_MODE (mode)) |
| 24188 |
return true; |
| 24189 |
if ((TARGET_3DNOW || TARGET_MMX_WITH_SSE) |
| 24190 |
&& VALID_MMX_REG_MODE_3DNOW (mode)) |
| 24191 |
return true; |
| 24192 |
if (mode == V2QImode) |
| 24193 |
return true; |
| 24194 |
return false; |
| 24195 |
} |
| 24196 |
|
| 24197 |
/* Target hook for c_mode_for_suffix. */ |
| 24198 |
static machine_mode |
| 24199 |
ix86_c_mode_for_suffix (char suffix) |
| 24200 |
{ |
| 24201 |
if (suffix == 'q') |
| 24202 |
return TFmode; |
| 24203 |
if (suffix == 'w') |
| 24204 |
return XFmode; |
| 24205 |
|
| 24206 |
return VOIDmode; |
| 24207 |
} |
| 24208 |
|
| 24209 |
/* Helper function to map common constraints to non-EGPR ones. |
| 24210 |
All related constraints have h prefix, and h plus Upper letter |
| 24211 |
means the constraint is strictly EGPR enabled, while h plus |
| 24212 |
lower letter indicates the constraint is strictly gpr16 only. |
| 24213 |
|
| 24214 |
Specially for "g" constraint, split it to rmi as there is |
| 24215 |
no corresponding general constraint define for backend. |
| 24216 |
|
| 24217 |
Here is the full list to map constraints that may involve |
| 24218 |
gpr to h prefixed. |
| 24219 |
|
| 24220 |
"g" -> "jrjmi" |
| 24221 |
"r" -> "jr" |
| 24222 |
"m" -> "jm" |
| 24223 |
"<" -> "j<" |
| 24224 |
">" -> "j>" |
| 24225 |
"o" -> "jo" |
| 24226 |
"V" -> "jV" |
| 24227 |
"p" -> "jp" |
| 24228 |
"Bm" -> "ja" |
| 24229 |
*/ |
| 24230 |
|
| 24231 |
static void map_egpr_constraints (vec<const char *> &constraints) |
| 24232 |
{ |
| 24233 |
for (size_t i = 0; i < constraints.length(); i++) |
| 24234 |
{ |
| 24235 |
const char *cur = constraints[i]; |
| 24236 |
|
| 24237 |
if (startswith (cur, "=@cc")) |
| 24238 |
continue; |
| 24239 |
|
| 24240 |
int len = strlen (cur); |
| 24241 |
auto_vec<char> buf; |
| 24242 |
|
| 24243 |
for (int j = 0; j < len; j++) |
| 24244 |
{ |
| 24245 |
switch (cur[j]) |
| 24246 |
{ |
| 24247 |
case 'g': |
| 24248 |
buf.safe_push ('j'); |
| 24249 |
buf.safe_push ('r'); |
| 24250 |
buf.safe_push ('j'); |
| 24251 |
buf.safe_push ('m'); |
| 24252 |
buf.safe_push ('i'); |
| 24253 |
break; |
| 24254 |
case 'r': |
| 24255 |
case 'm': |
| 24256 |
case '<': |
| 24257 |
case '>': |
| 24258 |
case 'o': |
| 24259 |
case 'V': |
| 24260 |
case 'p': |
| 24261 |
buf.safe_push ('j'); |
| 24262 |
buf.safe_push (cur[j]); |
| 24263 |
break; |
| 24264 |
case 'B': |
| 24265 |
if (cur[j + 1] == 'm') |
| 24266 |
{ |
| 24267 |
buf.safe_push ('j'); |
| 24268 |
buf.safe_push ('a'); |
| 24269 |
j++; |
| 24270 |
} |
| 24271 |
else |
| 24272 |
{ |
| 24273 |
buf.safe_push (cur[j]); |
| 24274 |
buf.safe_push (cur[j + 1]); |
| 24275 |
j++; |
| 24276 |
} |
| 24277 |
break; |
| 24278 |
case 'T': |
| 24279 |
case 'Y': |
| 24280 |
case 'W': |
| 24281 |
case 'j': |
| 24282 |
buf.safe_push (cur[j]); |
| 24283 |
buf.safe_push (cur[j + 1]); |
| 24284 |
j++; |
| 24285 |
break; |
| 24286 |
default: |
| 24287 |
buf.safe_push (cur[j]); |
| 24288 |
break; |
| 24289 |
} |
| 24290 |
} |
| 24291 |
buf.safe_push ('\0'); |
| 24292 |
constraints[i] = xstrdup (buf.address ()); |
| 24293 |
} |
| 24294 |
} |
| 24295 |
|
| 24296 |
/* Worker function for TARGET_MD_ASM_ADJUST. |
| 24297 |
|
| 24298 |
We implement asm flag outputs, and maintain source compatibility |
| 24299 |
with the old cc0-based compiler. */ |
| 24300 |
|
| 24301 |
static rtx_insn * |
| 24302 |
ix86_md_asm_adjust (vec<rtx> &outputs, vec<rtx> & /*inputs*/, |
| 24303 |
vec<machine_mode> & /*input_modes*/, |
| 24304 |
vec<const char *> &constraints, vec<rtx> &/*uses*/, |
| 24305 |
vec<rtx> &clobbers, HARD_REG_SET &clobbered_regs, |
| 24306 |
location_t loc) |
| 24307 |
{ |
| 24308 |
bool saw_asm_flag = false; |
| 24309 |
|
| 24310 |
start_sequence (); |
| 24311 |
|
| 24312 |
if (TARGET_APX_EGPR && !ix86_apx_inline_asm_use_gpr32) |
| 24313 |
map_egpr_constraints (constraints); |
| 24314 |
|
| 24315 |
for (unsigned i = 0, n = outputs.length (); i < n; ++i) |
| 24316 |
{ |
| 24317 |
const char *con = constraints[i]; |
| 24318 |
if (!startswith (con, "=@cc")) |
| 24319 |
continue; |
| 24320 |
con += 4; |
| 24321 |
if (strchr (con, ',') != NULL) |
| 24322 |
{ |
| 24323 |
error_at (loc, "alternatives not allowed in %<asm%> flag output"); |
| 24324 |
continue; |
| 24325 |
} |
| 24326 |
|
| 24327 |
bool invert = false; |
| 24328 |
if (con[0] == 'n') |
| 24329 |
invert = true, con++; |
| 24330 |
|
| 24331 |
machine_mode mode = CCmode; |
| 24332 |
rtx_code code = UNKNOWN; |
| 24333 |
|
| 24334 |
switch (con[0]) |
| 24335 |
{ |
| 24336 |
case 'a': |
| 24337 |
if (con[1] == 0) |
| 24338 |
mode = CCAmode, code = EQ; |
| 24339 |
else if (con[1] == 'e' && con[2] == 0) |
| 24340 |
mode = CCCmode, code = NE; |
| 24341 |
break; |
| 24342 |
case 'b': |
| 24343 |
if (con[1] == 0) |
| 24344 |
mode = CCCmode, code = EQ; |
| 24345 |
else if (con[1] == 'e' && con[2] == 0) |
| 24346 |
mode = CCAmode, code = NE; |
| 24347 |
break; |
| 24348 |
case 'c': |
| 24349 |
if (con[1] == 0) |
| 24350 |
mode = CCCmode, code = EQ; |
| 24351 |
break; |
| 24352 |
case 'e': |
| 24353 |
if (con[1] == 0) |
| 24354 |
mode = CCZmode, code = EQ; |
| 24355 |
break; |
| 24356 |
case 'g': |
| 24357 |
if (con[1] == 0) |
| 24358 |
mode = CCGCmode, code = GT; |
| 24359 |
else if (con[1] == 'e' && con[2] == 0) |
| 24360 |
mode = CCGCmode, code = GE; |
| 24361 |
break; |
| 24362 |
case 'l': |
| 24363 |
if (con[1] == 0) |
| 24364 |
mode = CCGCmode, code = LT; |
| 24365 |
else if (con[1] == 'e' && con[2] == 0) |
| 24366 |
mode = CCGCmode, code = LE; |
| 24367 |
break; |
| 24368 |
case 'o': |
| 24369 |
if (con[1] == 0) |
| 24370 |
mode = CCOmode, code = EQ; |
| 24371 |
break; |
| 24372 |
case 'p': |
| 24373 |
if (con[1] == 0) |
| 24374 |
mode = CCPmode, code = EQ; |
| 24375 |
break; |
| 24376 |
case 's': |
| 24377 |
if (con[1] == 0) |
| 24378 |
mode = CCSmode, code = EQ; |
| 24379 |
break; |
| 24380 |
case 'z': |
| 24381 |
if (con[1] == 0) |
| 24382 |
mode = CCZmode, code = EQ; |
| 24383 |
break; |
| 24384 |
} |
| 24385 |
if (code == UNKNOWN) |
| 24386 |
{ |
| 24387 |
error_at (loc, "unknown %<asm%> flag output %qs", constraints[i]); |
| 24388 |
continue; |
| 24389 |
} |
| 24390 |
if (invert) |
| 24391 |
code = reverse_condition (code); |
| 24392 |
|
| 24393 |
rtx dest = outputs[i]; |
| 24394 |
if (!saw_asm_flag) |
| 24395 |
{ |
| 24396 |
/* This is the first asm flag output. Here we put the flags |
| 24397 |
register in as the real output and adjust the condition to |
| 24398 |
allow it. */ |
| 24399 |
constraints[i] = "=Bf"; |
| 24400 |
outputs[i] = gen_rtx_REG (CCmode, FLAGS_REG); |
| 24401 |
saw_asm_flag = true; |
| 24402 |
} |
| 24403 |
else |
| 24404 |
{ |
| 24405 |
/* We don't need the flags register as output twice. */ |
| 24406 |
constraints[i] = "=X"; |
| 24407 |
outputs[i] = gen_rtx_SCRATCH (SImode); |
| 24408 |
} |
| 24409 |
|
| 24410 |
rtx x = gen_rtx_REG (mode, FLAGS_REG); |
| 24411 |
x = gen_rtx_fmt_ee (code, QImode, x, const0_rtx); |
| 24412 |
|
| 24413 |
machine_mode dest_mode = GET_MODE (dest); |
| 24414 |
if (!SCALAR_INT_MODE_P (dest_mode)) |
| 24415 |
{ |
| 24416 |
error_at (loc, "invalid type for %<asm%> flag output"); |
| 24417 |
continue; |
| 24418 |
} |
| 24419 |
|
| 24420 |
if (dest_mode == QImode) |
| 24421 |
emit_insn (gen_rtx_SET (dest, x)); |
| 24422 |
else |
| 24423 |
{ |
| 24424 |
rtx reg = gen_reg_rtx (QImode); |
| 24425 |
emit_insn (gen_rtx_SET (reg, x)); |
| 24426 |
|
| 24427 |
reg = convert_to_mode (dest_mode, reg, 1); |
| 24428 |
emit_move_insn (dest, reg); |
| 24429 |
} |
| 24430 |
} |
| 24431 |
|
| 24432 |
rtx_insn *seq = get_insns (); |
| 24433 |
end_sequence (); |
| 24434 |
|
| 24435 |
if (saw_asm_flag) |
| 24436 |
return seq; |
| 24437 |
else |
| 24438 |
{ |
| 24439 |
/* If we had no asm flag outputs, clobber the flags. */ |
| 24440 |
clobbers.safe_push (gen_rtx_REG (CCmode, FLAGS_REG)); |
| 24441 |
SET_HARD_REG_BIT (clobbered_regs, FLAGS_REG); |
| 24442 |
return NULL; |
| 24443 |
} |
| 24444 |
} |
| 24445 |
|
| 24446 |
/* Implements target vector targetm.asm.encode_section_info. */ |
| 24447 |
|
| 24448 |
static void ATTRIBUTE_UNUSED |
| 24449 |
ix86_encode_section_info (tree decl, rtx rtl, int first) |
| 24450 |
{ |
| 24451 |
default_encode_section_info (decl, rtl, first); |
| 24452 |
|
| 24453 |
if (ix86_in_large_data_p (decl)) |
| 24454 |
SYMBOL_REF_FLAGS (XEXP (rtl, 0)) |= SYMBOL_FLAG_FAR_ADDR; |
| 24455 |
} |
| 24456 |
|
| 24457 |
/* Worker function for REVERSE_CONDITION. */ |
| 24458 |
|
| 24459 |
enum rtx_code |
| 24460 |
ix86_reverse_condition (enum rtx_code code, machine_mode mode) |
| 24461 |
{ |
| 24462 |
return (mode == CCFPmode |
| 24463 |
? reverse_condition_maybe_unordered (code) |
| 24464 |
: reverse_condition (code)); |
| 24465 |
} |
| 24466 |
|
| 24467 |
/* Output code to perform an x87 FP register move, from OPERANDS[1] |
| 24468 |
to OPERANDS[0]. */ |
| 24469 |
|
| 24470 |
const char * |
| 24471 |
output_387_reg_move (rtx_insn *insn, rtx *operands) |
| 24472 |
{ |
| 24473 |
if (REG_P (operands[0])) |
| 24474 |
{ |
| 24475 |
if (REG_P (operands[1]) |
| 24476 |
&& find_regno_note (insn, REG_DEAD, REGNO (operands[1]))) |
| 24477 |
{ |
| 24478 |
if (REGNO (operands[0]) == FIRST_STACK_REG) |
| 24479 |
return output_387_ffreep (operands, 0); |
| 24480 |
return "fstp\t%y0"; |
| 24481 |
} |
| 24482 |
if (STACK_TOP_P (operands[0])) |
| 24483 |
return "fld%Z1\t%y1"; |
| 24484 |
return "fst\t%y0"; |
| 24485 |
} |
| 24486 |
else if (MEM_P (operands[0])) |
| 24487 |
{ |
| 24488 |
gcc_assert (REG_P (operands[1])); |
| 24489 |
if (find_regno_note (insn, REG_DEAD, REGNO (operands[1]))) |
| 24490 |
return "fstp%Z0\t%y0"; |
| 24491 |
else |
| 24492 |
{ |
| 24493 |
/* There is no non-popping store to memory for XFmode. |
| 24494 |
So if we need one, follow the store with a load. */ |
| 24495 |
if (GET_MODE (operands[0]) == XFmode) |
| 24496 |
return "fstp%Z0\t%y0\n\tfld%Z0\t%y0"; |
| 24497 |
else |
| 24498 |
return "fst%Z0\t%y0"; |
| 24499 |
} |
| 24500 |
} |
| 24501 |
else |
| 24502 |
gcc_unreachable(); |
| 24503 |
} |
| 24504 |
#ifdef TARGET_SOLARIS |
| 24505 |
/* Solaris implementation of TARGET_ASM_NAMED_SECTION. */ |
| 24506 |
|
| 24507 |
static void |
| 24508 |
i386_solaris_elf_named_section (const char *name, unsigned int flags, |
| 24509 |
tree decl) |
| 24510 |
{ |
| 24511 |
/* With Binutils 2.15, the "@unwind" marker must be specified on |
| 24512 |
every occurrence of the ".eh_frame" section, not just the first |
| 24513 |
one. */ |
| 24514 |
if (TARGET_64BIT |
| 24515 |
&& strcmp (name, ".eh_frame") == 0) |
| 24516 |
{ |
| 24517 |
fprintf (asm_out_file, "\t.section\t%s,\"%s\",@unwind\n", name, |
| 24518 |
flags & SECTION_WRITE ? "aw" : "a"); |
| 24519 |
return; |
| 24520 |
} |
| 24521 |
|
| 24522 |
#ifndef USE_GAS |
| 24523 |
if (HAVE_COMDAT_GROUP && flags & SECTION_LINKONCE) |
| 24524 |
{ |
| 24525 |
solaris_elf_asm_comdat_section (name, flags, decl); |
| 24526 |
return; |
| 24527 |
} |
| 24528 |
|
| 24529 |
/* Solaris/x86 as uses the same syntax for the SHF_EXCLUDE flags as the |
| 24530 |
SPARC assembler. One cannot mix single-letter flags and #exclude, so |
| 24531 |
only emit the latter here. */ |
| 24532 |
if (flags & SECTION_EXCLUDE) |
| 24533 |
{ |
| 24534 |
fprintf (asm_out_file, "\t.section\t%s,#exclude\n", name); |
| 24535 |
return; |
| 24536 |
} |
| 24537 |
#endif |
| 24538 |
|
| 24539 |
default_elf_asm_named_section (name, flags, decl); |
| 24540 |
} |
| 24541 |
#endif /* TARGET_SOLARIS */ |
| 24542 |
|
| 24543 |
/* Return the mangling of TYPE if it is an extended fundamental type. */ |
| 24544 |
|
| 24545 |
static const char * |
| 24546 |
ix86_mangle_type (const_tree type) |
| 24547 |
{ |
| 24548 |
type = TYPE_MAIN_VARIANT (type); |
| 24549 |
|
| 24550 |
if (TREE_CODE (type) != VOID_TYPE && TREE_CODE (type) != BOOLEAN_TYPE |
| 24551 |
&& TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE) |
| 24552 |
return NULL; |
| 24553 |
|
| 24554 |
if (type == float128_type_node || type == float64x_type_node) |
| 24555 |
return NULL; |
| 24556 |
|
| 24557 |
switch (TYPE_MODE (type)) |
| 24558 |
{ |
| 24559 |
case E_BFmode: |
| 24560 |
return "DF16b"; |
| 24561 |
case E_HFmode: |
| 24562 |
/* _Float16 is "DF16_". |
| 24563 |
Align with clang's decision in https://reviews.llvm.org/D33719. */ |
| 24564 |
return "DF16_"; |
| 24565 |
case E_TFmode: |
| 24566 |
/* __float128 is "g". */ |
| 24567 |
return "g"; |
| 24568 |
case E_XFmode: |
| 24569 |
/* "long double" or __float80 is "e". */ |
| 24570 |
return "e"; |
| 24571 |
default: |
| 24572 |
return NULL; |
| 24573 |
} |
| 24574 |
} |
| 24575 |
|
| 24576 |
/* Create C++ tinfo symbols for only conditionally available fundamental |
| 24577 |
types. */ |
| 24578 |
|
| 24579 |
static void |
| 24580 |
ix86_emit_support_tinfos (emit_support_tinfos_callback callback) |
| 24581 |
{ |
| 24582 |
extern tree ix86_float16_type_node; |
| 24583 |
extern tree ix86_bf16_type_node; |
| 24584 |
|
| 24585 |
if (!TARGET_SSE2) |
| 24586 |
{ |
| 24587 |
if (!float16_type_node) |
| 24588 |
float16_type_node = ix86_float16_type_node; |
| 24589 |
if (!bfloat16_type_node) |
| 24590 |
bfloat16_type_node = ix86_bf16_type_node; |
| 24591 |
callback (float16_type_node); |
| 24592 |
callback (bfloat16_type_node); |
| 24593 |
float16_type_node = NULL_TREE; |
| 24594 |
bfloat16_type_node = NULL_TREE; |
| 24595 |
} |
| 24596 |
} |
| 24597 |
|
| 24598 |
static GTY(()) tree ix86_tls_stack_chk_guard_decl; |
| 24599 |
|
| 24600 |
static tree |
| 24601 |
ix86_stack_protect_guard (void) |
| 24602 |
{ |
| 24603 |
if (TARGET_SSP_TLS_GUARD) |
| 24604 |
{ |
| 24605 |
tree type_node = lang_hooks.types.type_for_mode (ptr_mode, 1); |
| 24606 |
int qual = ENCODE_QUAL_ADDR_SPACE (ix86_stack_protector_guard_reg); |
| 24607 |
tree type = build_qualified_type (type_node, qual); |
| 24608 |
tree t; |
| 24609 |
|
| 24610 |
if (OPTION_SET_P (ix86_stack_protector_guard_symbol_str)) |
| 24611 |
{ |
| 24612 |
t = ix86_tls_stack_chk_guard_decl; |
| 24613 |
|
| 24614 |
if (t == NULL) |
| 24615 |
{ |
| 24616 |
rtx x; |
| 24617 |
|
| 24618 |
t = build_decl |
| 24619 |
(UNKNOWN_LOCATION, VAR_DECL, |
| 24620 |
get_identifier (ix86_stack_protector_guard_symbol_str), |
| 24621 |
type); |
| 24622 |
TREE_STATIC (t) = 1; |
| 24623 |
TREE_PUBLIC (t) = 1; |
| 24624 |
DECL_EXTERNAL (t) = 1; |
| 24625 |
TREE_USED (t) = 1; |
| 24626 |
TREE_THIS_VOLATILE (t) = 1; |
| 24627 |
DECL_ARTIFICIAL (t) = 1; |
| 24628 |
DECL_IGNORED_P (t) = 1; |
| 24629 |
|
| 24630 |
/* Do not share RTL as the declaration is visible outside of |
| 24631 |
current function. */ |
| 24632 |
x = DECL_RTL (t); |
| 24633 |
RTX_FLAG (x, used) = 1; |
| 24634 |
|
| 24635 |
ix86_tls_stack_chk_guard_decl = t; |
| 24636 |
} |
| 24637 |
} |
| 24638 |
else |
| 24639 |
{ |
| 24640 |
tree asptrtype = build_pointer_type (type); |
| 24641 |
|
| 24642 |
t = build_int_cst (asptrtype, ix86_stack_protector_guard_offset); |
| 24643 |
t = build2 (MEM_REF, asptrtype, t, |
| 24644 |
build_int_cst (asptrtype, 0)); |
| 24645 |
TREE_THIS_VOLATILE (t) = 1; |
| 24646 |
} |
| 24647 |
|
| 24648 |
return t; |
| 24649 |
} |
| 24650 |
|
| 24651 |
return default_stack_protect_guard (); |
| 24652 |
} |
| 24653 |
|
| 24654 |
static bool |
| 24655 |
ix86_stack_protect_runtime_enabled_p (void) |
| 24656 |
{ |
| 24657 |
/* Naked functions should not enable stack protector. */ |
| 24658 |
return !ix86_function_naked (current_function_decl); |
| 24659 |
} |
| 24660 |
|
| 24661 |
/* For 32-bit code we can save PIC register setup by using |
| 24662 |
__stack_chk_fail_local hidden function instead of calling |
| 24663 |
__stack_chk_fail directly. 64-bit code doesn't need to setup any PIC |
| 24664 |
register, so it is better to call __stack_chk_fail directly. */ |
| 24665 |
|
| 24666 |
static tree ATTRIBUTE_UNUSED |
| 24667 |
ix86_stack_protect_fail (void) |
| 24668 |
{ |
| 24669 |
return TARGET_64BIT |
| 24670 |
? default_external_stack_protect_fail () |
| 24671 |
: default_hidden_stack_protect_fail (); |
| 24672 |
} |
| 24673 |
|
| 24674 |
/* Select a format to encode pointers in exception handling data. CODE |
| 24675 |
is 0 for data, 1 for code labels, 2 for function pointers. GLOBAL is |
| 24676 |
true if the symbol may be affected by dynamic relocations. |
| 24677 |
|
| 24678 |
??? All x86 object file formats are capable of representing this. |
| 24679 |
After all, the relocation needed is the same as for the call insn. |
| 24680 |
Whether or not a particular assembler allows us to enter such, I |
| 24681 |
guess we'll have to see. */ |
| 24682 |
|
| 24683 |
int |
| 24684 |
asm_preferred_eh_data_format (int code, int global) |
| 24685 |
{ |
| 24686 |
/* PE-COFF is effectively always -fPIC because of the .reloc section. */ |
| 24687 |
if (flag_pic || TARGET_PECOFF || !ix86_direct_extern_access) |
| 24688 |
{ |
| 24689 |
int type = DW_EH_PE_sdata8; |
| 24690 |
if (ptr_mode == SImode |
| 24691 |
|| ix86_cmodel == CM_SMALL_PIC |
| 24692 |
|| (ix86_cmodel == CM_MEDIUM_PIC && (global || code))) |
| 24693 |
type = DW_EH_PE_sdata4; |
| 24694 |
return (global ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | type; |
| 24695 |
} |
| 24696 |
|
| 24697 |
if (ix86_cmodel == CM_SMALL |
| 24698 |
|| (ix86_cmodel == CM_MEDIUM && code)) |
| 24699 |
return DW_EH_PE_udata4; |
| 24700 |
|
| 24701 |
return DW_EH_PE_absptr; |
| 24702 |
} |
| 24703 |
|
| 24704 |
/* Implement targetm.vectorize.builtin_vectorization_cost. */ |
| 24705 |
static int |
| 24706 |
ix86_builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost, |
| 24707 |
tree vectype, int) |
| 24708 |
{ |
| 24709 |
bool fp = false; |
| 24710 |
machine_mode mode = TImode; |
| 24711 |
int index; |
| 24712 |
if (vectype != NULL) |
| 24713 |
{ |
| 24714 |
fp = FLOAT_TYPE_P (vectype); |
| 24715 |
mode = TYPE_MODE (vectype); |
| 24716 |
} |
| 24717 |
|
| 24718 |
switch (type_of_cost) |
| 24719 |
{ |
| 24720 |
case scalar_stmt: |
| 24721 |
return fp ? ix86_cost->addss : COSTS_N_INSNS (1); |
| 24722 |
|
| 24723 |
case scalar_load: |
| 24724 |
/* load/store costs are relative to register move which is 2. Recompute |
| 24725 |
it to COSTS_N_INSNS so everything have same base. */ |
| 24726 |
return COSTS_N_INSNS (fp ? ix86_cost->sse_load[0] |
| 24727 |
: ix86_cost->int_load [2]) / 2; |
| 24728 |
|
| 24729 |
case scalar_store: |
| 24730 |
return COSTS_N_INSNS (fp ? ix86_cost->sse_store[0] |
| 24731 |
: ix86_cost->int_store [2]) / 2; |
| 24732 |
|
| 24733 |
case vector_stmt: |
| 24734 |
return ix86_vec_cost (mode, |
| 24735 |
fp ? ix86_cost->addss : ix86_cost->sse_op); |
| 24736 |
|
| 24737 |
case vector_load: |
| 24738 |
index = sse_store_index (mode); |
| 24739 |
/* See PR82713 - we may end up being called on non-vector type. */ |
| 24740 |
if (index < 0) |
| 24741 |
index = 2; |
| 24742 |
return COSTS_N_INSNS (ix86_cost->sse_load[index]) / 2; |
| 24743 |
|
| 24744 |
case vector_store: |
| 24745 |
index = sse_store_index (mode); |
| 24746 |
/* See PR82713 - we may end up being called on non-vector type. */ |
| 24747 |
if (index < 0) |
| 24748 |
index = 2; |
| 24749 |
return COSTS_N_INSNS (ix86_cost->sse_store[index]) / 2; |
| 24750 |
|
| 24751 |
case vec_to_scalar: |
| 24752 |
case scalar_to_vec: |
| 24753 |
return ix86_vec_cost (mode, ix86_cost->sse_op); |
| 24754 |
|
| 24755 |
/* We should have separate costs for unaligned loads and gather/scatter. |
| 24756 |
Do that incrementally. */ |
| 24757 |
case unaligned_load: |
| 24758 |
index = sse_store_index (mode); |
| 24759 |
/* See PR82713 - we may end up being called on non-vector type. */ |
| 24760 |
if (index < 0) |
| 24761 |
index = 2; |
| 24762 |
return COSTS_N_INSNS (ix86_cost->sse_unaligned_load[index]) / 2; |
| 24763 |
|
| 24764 |
case unaligned_store: |
| 24765 |
index = sse_store_index (mode); |
| 24766 |
/* See PR82713 - we may end up being called on non-vector type. */ |
| 24767 |
if (index < 0) |
| 24768 |
index = 2; |
| 24769 |
return COSTS_N_INSNS (ix86_cost->sse_unaligned_store[index]) / 2; |
| 24770 |
|
| 24771 |
case vector_gather_load: |
| 24772 |
return ix86_vec_cost (mode, |
| 24773 |
COSTS_N_INSNS |
| 24774 |
(ix86_cost->gather_static |
| 24775 |
+ ix86_cost->gather_per_elt |
| 24776 |
* TYPE_VECTOR_SUBPARTS (vectype)) / 2); |
| 24777 |
|
| 24778 |
case vector_scatter_store: |
| 24779 |
return ix86_vec_cost (mode, |
| 24780 |
COSTS_N_INSNS |
| 24781 |
(ix86_cost->scatter_static |
| 24782 |
+ ix86_cost->scatter_per_elt |
| 24783 |
* TYPE_VECTOR_SUBPARTS (vectype)) / 2); |
| 24784 |
|
| 24785 |
case cond_branch_taken: |
| 24786 |
return ix86_cost->cond_taken_branch_cost; |
| 24787 |
|
| 24788 |
case cond_branch_not_taken: |
| 24789 |
return ix86_cost->cond_not_taken_branch_cost; |
| 24790 |
|
| 24791 |
case vec_perm: |
| 24792 |
case vec_promote_demote: |
| 24793 |
return ix86_vec_cost (mode, ix86_cost->sse_op); |
| 24794 |
|
| 24795 |
case vec_construct: |
| 24796 |
{ |
| 24797 |
int n = TYPE_VECTOR_SUBPARTS (vectype); |
| 24798 |
/* N - 1 element inserts into an SSE vector, the possible |
| 24799 |
GPR -> XMM move is accounted for in add_stmt_cost. */ |
| 24800 |
if (GET_MODE_BITSIZE (mode) <= 128) |
| 24801 |
return (n - 1) * ix86_cost->sse_op; |
| 24802 |
/* One vinserti128 for combining two SSE vectors for AVX256. */ |
| 24803 |
else if (GET_MODE_BITSIZE (mode) == 256) |
| 24804 |
return ((n - 2) * ix86_cost->sse_op |
| 24805 |
+ ix86_vec_cost (mode, ix86_cost->addss)); |
| 24806 |
/* One vinserti64x4 and two vinserti128 for combining SSE |
| 24807 |
and AVX256 vectors to AVX512. */ |
| 24808 |
else if (GET_MODE_BITSIZE (mode) == 512) |
| 24809 |
return ((n - 4) * ix86_cost->sse_op |
| 24810 |
+ 3 * ix86_vec_cost (mode, ix86_cost->addss)); |
| 24811 |
gcc_unreachable (); |
| 24812 |
} |
| 24813 |
|
| 24814 |
default: |
| 24815 |
gcc_unreachable (); |
| 24816 |
} |
| 24817 |
} |
| 24818 |
|
| 24819 |
|
| 24820 |
/* This function returns the calling abi specific va_list type node. |
| 24821 |
It returns the FNDECL specific va_list type. */ |
| 24822 |
|
| 24823 |
static tree |
| 24824 |
ix86_fn_abi_va_list (tree fndecl) |
| 24825 |
{ |
| 24826 |
if (!TARGET_64BIT) |
| 24827 |
return va_list_type_node; |
| 24828 |
gcc_assert (fndecl != NULL_TREE); |
| 24829 |
|
| 24830 |
if (ix86_function_abi ((const_tree) fndecl) == MS_ABI) |
| 24831 |
return ms_va_list_type_node; |
| 24832 |
else |
| 24833 |
return sysv_va_list_type_node; |
| 24834 |
} |
| 24835 |
|
| 24836 |
/* Returns the canonical va_list type specified by TYPE. If there |
| 24837 |
is no valid TYPE provided, it return NULL_TREE. */ |
| 24838 |
|
| 24839 |
static tree |
| 24840 |
ix86_canonical_va_list_type (tree type) |
| 24841 |
{ |
| 24842 |
if (TARGET_64BIT) |
| 24843 |
{ |
| 24844 |
if (lookup_attribute ("ms_abi va_list", TYPE_ATTRIBUTES (type))) |
| 24845 |
return ms_va_list_type_node; |
| 24846 |
|
| 24847 |
if ((TREE_CODE (type) == ARRAY_TYPE |
| 24848 |
&& integer_zerop (array_type_nelts_minus_one (type))) |
| 24849 |
|| POINTER_TYPE_P (type)) |
| 24850 |
{ |
| 24851 |
tree elem_type = TREE_TYPE (type); |
| 24852 |
if (TREE_CODE (elem_type) == RECORD_TYPE |
| 24853 |
&& lookup_attribute ("sysv_abi va_list", |
| 24854 |
TYPE_ATTRIBUTES (elem_type))) |
| 24855 |
return sysv_va_list_type_node; |
| 24856 |
} |
| 24857 |
|
| 24858 |
return NULL_TREE; |
| 24859 |
} |
| 24860 |
|
| 24861 |
return std_canonical_va_list_type (type); |
| 24862 |
} |
| 24863 |
|
| 24864 |
/* Iterate through the target-specific builtin types for va_list. |
| 24865 |
IDX denotes the iterator, *PTREE is set to the result type of |
| 24866 |
the va_list builtin, and *PNAME to its internal type. |
| 24867 |
Returns zero if there is no element for this index, otherwise |
| 24868 |
IDX should be increased upon the next call. |
| 24869 |
Note, do not iterate a base builtin's name like __builtin_va_list. |
| 24870 |
Used from c_common_nodes_and_builtins. */ |
| 24871 |
|
| 24872 |
static int |
| 24873 |
ix86_enum_va_list (int idx, const char **pname, tree *ptree) |
| 24874 |
{ |
| 24875 |
if (TARGET_64BIT) |
| 24876 |
{ |
| 24877 |
switch (idx) |
| 24878 |
{ |
| 24879 |
default: |
| 24880 |
break; |
| 24881 |
|
| 24882 |
case 0: |
| 24883 |
*ptree = ms_va_list_type_node; |
| 24884 |
*pname = "__builtin_ms_va_list"; |
| 24885 |
return 1; |
| 24886 |
|
| 24887 |
case 1: |
| 24888 |
*ptree = sysv_va_list_type_node; |
| 24889 |
*pname = "__builtin_sysv_va_list"; |
| 24890 |
return 1; |
| 24891 |
} |
| 24892 |
} |
| 24893 |
|
| 24894 |
return 0; |
| 24895 |
} |
| 24896 |
|
| 24897 |
#undef TARGET_SCHED_DISPATCH |
| 24898 |
#define TARGET_SCHED_DISPATCH ix86_bd_has_dispatch |
| 24899 |
#undef TARGET_SCHED_DISPATCH_DO |
| 24900 |
#define TARGET_SCHED_DISPATCH_DO ix86_bd_do_dispatch |
| 24901 |
#undef TARGET_SCHED_REASSOCIATION_WIDTH |
| 24902 |
#define TARGET_SCHED_REASSOCIATION_WIDTH ix86_reassociation_width |
| 24903 |
#undef TARGET_SCHED_REORDER |
| 24904 |
#define TARGET_SCHED_REORDER ix86_atom_sched_reorder |
| 24905 |
#undef TARGET_SCHED_ADJUST_PRIORITY |
| 24906 |
#define TARGET_SCHED_ADJUST_PRIORITY ix86_adjust_priority |
| 24907 |
#undef TARGET_SCHED_DEPENDENCIES_EVALUATION_HOOK |
| 24908 |
#define TARGET_SCHED_DEPENDENCIES_EVALUATION_HOOK \ |
| 24909 |
ix86_dependencies_evaluation_hook |
| 24910 |
|
| 24911 |
|
| 24912 |
/* Implementation of reassociation_width target hook used by |
| 24913 |
reassoc phase to identify parallelism level in reassociated |
| 24914 |
tree. Statements tree_code is passed in OPC. Arguments type |
| 24915 |
is passed in MODE. */ |
| 24916 |
|
| 24917 |
static int |
| 24918 |
ix86_reassociation_width (unsigned int op, machine_mode mode) |
| 24919 |
{ |
| 24920 |
int width = 1; |
| 24921 |
/* Vector part. */ |
| 24922 |
if (VECTOR_MODE_P (mode)) |
| 24923 |
{ |
| 24924 |
int div = 1; |
| 24925 |
if (INTEGRAL_MODE_P (mode)) |
| 24926 |
width = ix86_cost->reassoc_vec_int; |
| 24927 |
else if (FLOAT_MODE_P (mode)) |
| 24928 |
width = ix86_cost->reassoc_vec_fp; |
| 24929 |
|
| 24930 |
if (width == 1) |
| 24931 |
return 1; |
| 24932 |
|
| 24933 |
/* Znver1-4 Integer vector instructions execute in FP unit |
| 24934 |
and can execute 3 additions and one multiplication per cycle. */ |
| 24935 |
if ((ix86_tune == PROCESSOR_ZNVER1 || ix86_tune == PROCESSOR_ZNVER2 |
| 24936 |
|| ix86_tune == PROCESSOR_ZNVER3 || ix86_tune == PROCESSOR_ZNVER4 |
| 24937 |
|| ix86_tune == PROCESSOR_C86_4G_M4 |
| 24938 |
|| ix86_tune == PROCESSOR_C86_4G_M6 |
| 24939 |
|| ix86_tune == PROCESSOR_C86_4G_M7) |
| 24940 |
&& INTEGRAL_MODE_P (mode) && op != PLUS && op != MINUS) |
| 24941 |
return 1; |
| 24942 |
/* Znver5 can do 2 integer multiplications per cycle with latency |
| 24943 |
of 3. */ |
| 24944 |
if (ix86_tune == PROCESSOR_ZNVER5 |
| 24945 |
&& INTEGRAL_MODE_P (mode) && op != PLUS && op != MINUS) |
| 24946 |
width = 6; |
| 24947 |
|
| 24948 |
/* Account for targets that splits wide vectors into multiple parts. */ |
| 24949 |
if (TARGET_AVX512_SPLIT_REGS && GET_MODE_BITSIZE (mode) > 256) |
| 24950 |
div = GET_MODE_BITSIZE (mode) / 256; |
| 24951 |
else if (TARGET_AVX256_SPLIT_REGS && GET_MODE_BITSIZE (mode) > 128) |
| 24952 |
div = GET_MODE_BITSIZE (mode) / 128; |
| 24953 |
else if (TARGET_SSE_SPLIT_REGS && GET_MODE_BITSIZE (mode) > 64) |
| 24954 |
div = GET_MODE_BITSIZE (mode) / 64; |
| 24955 |
width = (width + div - 1) / div; |
| 24956 |
} |
| 24957 |
/* Scalar part. */ |
| 24958 |
else if (INTEGRAL_MODE_P (mode)) |
| 24959 |
width = ix86_cost->reassoc_int; |
| 24960 |
else if (FLOAT_MODE_P (mode)) |
| 24961 |
width = ix86_cost->reassoc_fp; |
| 24962 |
|
| 24963 |
/* Avoid using too many registers in 32bit mode. */ |
| 24964 |
if (!TARGET_64BIT && width > 2) |
| 24965 |
width = 2; |
| 24966 |
return width; |
| 24967 |
} |
| 24968 |
|
| 24969 |
/* ??? No autovectorization into MMX or 3DNOW until we can reliably |
| 24970 |
place emms and femms instructions. */ |
| 24971 |
|
| 24972 |
static machine_mode |
| 24973 |
ix86_preferred_simd_mode (scalar_mode mode) |
| 24974 |
{ |
| 24975 |
if (!TARGET_SSE) |
| 24976 |
return word_mode; |
| 24977 |
|
| 24978 |
switch (mode) |
| 24979 |
{ |
| 24980 |
case E_QImode: |
| 24981 |
if (TARGET_AVX512BW && TARGET_EVEX512 && !TARGET_PREFER_AVX256) |
| 24982 |
return V64QImode; |
| 24983 |
else if (TARGET_AVX && !TARGET_PREFER_AVX128) |
| 24984 |
return V32QImode; |
| 24985 |
else |
| 24986 |
return V16QImode; |
| 24987 |
|
| 24988 |
case E_HImode: |
| 24989 |
if (TARGET_AVX512BW && TARGET_EVEX512 && !TARGET_PREFER_AVX256) |
| 24990 |
return V32HImode; |
| 24991 |
else if (TARGET_AVX && !TARGET_PREFER_AVX128) |
| 24992 |
return V16HImode; |
| 24993 |
else |
| 24994 |
return V8HImode; |
| 24995 |
|
| 24996 |
case E_SImode: |
| 24997 |
if (TARGET_AVX512F && TARGET_EVEX512 && !TARGET_PREFER_AVX256) |
| 24998 |
return V16SImode; |
| 24999 |
else if (TARGET_AVX && !TARGET_PREFER_AVX128) |
| 25000 |
return V8SImode; |
| 25001 |
else |
| 25002 |
return V4SImode; |
| 25003 |
|
| 25004 |
case E_DImode: |
| 25005 |
if (TARGET_AVX512F && TARGET_EVEX512 && !TARGET_PREFER_AVX256) |
| 25006 |
return V8DImode; |
| 25007 |
else if (TARGET_AVX && !TARGET_PREFER_AVX128) |
| 25008 |
return V4DImode; |
| 25009 |
else |
| 25010 |
return V2DImode; |
| 25011 |
|
| 25012 |
case E_HFmode: |
| 25013 |
if (TARGET_AVX512FP16) |
| 25014 |
{ |
| 25015 |
if (TARGET_AVX512VL) |
| 25016 |
{ |
| 25017 |
if (TARGET_PREFER_AVX128) |
| 25018 |
return V8HFmode; |
| 25019 |
else if (TARGET_PREFER_AVX256 || !TARGET_EVEX512) |
| 25020 |
return V16HFmode; |
| 25021 |
} |
| 25022 |
if (TARGET_EVEX512) |
| 25023 |
return V32HFmode; |
| 25024 |
} |
| 25025 |
return word_mode; |
| 25026 |
|
| 25027 |
case E_BFmode: |
| 25028 |
if (TARGET_AVX512F && TARGET_EVEX512 && !TARGET_PREFER_AVX256) |
| 25029 |
return V32BFmode; |
| 25030 |
else if (TARGET_AVX && !TARGET_PREFER_AVX128) |
| 25031 |
return V16BFmode; |
| 25032 |
else |
| 25033 |
return V8BFmode; |
| 25034 |
|
| 25035 |
case E_SFmode: |
| 25036 |
if (TARGET_AVX512F && TARGET_EVEX512 && !TARGET_PREFER_AVX256) |
| 25037 |
return V16SFmode; |
| 25038 |
else if (TARGET_AVX && !TARGET_PREFER_AVX128) |
| 25039 |
return V8SFmode; |
| 25040 |
else |
| 25041 |
return V4SFmode; |
| 25042 |
|
| 25043 |
case E_DFmode: |
| 25044 |
if (TARGET_AVX512F && TARGET_EVEX512 && !TARGET_PREFER_AVX256) |
| 25045 |
return V8DFmode; |
| 25046 |
else if (TARGET_AVX && !TARGET_PREFER_AVX128) |
| 25047 |
return V4DFmode; |
| 25048 |
else if (TARGET_SSE2) |
| 25049 |
return V2DFmode; |
| 25050 |
/* FALLTHRU */ |
| 25051 |
|
| 25052 |
default: |
| 25053 |
return word_mode; |
| 25054 |
} |
| 25055 |
} |
| 25056 |
|
| 25057 |
/* If AVX is enabled then try vectorizing with both 256bit and 128bit |
| 25058 |
vectors. If AVX512F is enabled then try vectorizing with 512bit, |
| 25059 |
256bit and 128bit vectors. */ |
| 25060 |
|
| 25061 |
static unsigned int |
| 25062 |
ix86_autovectorize_vector_modes (vector_modes *modes, bool all) |
| 25063 |
{ |
| 25064 |
if (TARGET_AVX512F && TARGET_EVEX512 && !TARGET_PREFER_AVX256) |
| 25065 |
{ |
| 25066 |
modes->safe_push (V64QImode); |
| 25067 |
modes->safe_push (V32QImode); |
| 25068 |
modes->safe_push (V16QImode); |
| 25069 |
} |
| 25070 |
else if (TARGET_AVX512F && TARGET_EVEX512 && all) |
| 25071 |
{ |
| 25072 |
modes->safe_push (V32QImode); |
| 25073 |
modes->safe_push (V16QImode); |
| 25074 |
modes->safe_push (V64QImode); |
| 25075 |
} |
| 25076 |
else if (TARGET_AVX && !TARGET_PREFER_AVX128) |
| 25077 |
{ |
| 25078 |
modes->safe_push (V32QImode); |
| 25079 |
modes->safe_push (V16QImode); |
| 25080 |
} |
| 25081 |
else if (TARGET_AVX && all) |
| 25082 |
{ |
| 25083 |
modes->safe_push (V16QImode); |
| 25084 |
modes->safe_push (V32QImode); |
| 25085 |
} |
| 25086 |
else if (TARGET_SSE2) |
| 25087 |
modes->safe_push (V16QImode); |
| 25088 |
|
| 25089 |
if (TARGET_MMX_WITH_SSE) |
| 25090 |
modes->safe_push (V8QImode); |
| 25091 |
|
| 25092 |
if (TARGET_SSE2) |
| 25093 |
modes->safe_push (V4QImode); |
| 25094 |
|
| 25095 |
return 0; |
| 25096 |
} |
| 25097 |
|
| 25098 |
/* Implemenation of targetm.vectorize.get_mask_mode. */ |
| 25099 |
|
| 25100 |
static opt_machine_mode |
| 25101 |
ix86_get_mask_mode (machine_mode data_mode) |
| 25102 |
{ |
| 25103 |
unsigned vector_size = GET_MODE_SIZE (data_mode); |
| 25104 |
unsigned nunits = GET_MODE_NUNITS (data_mode); |
| 25105 |
unsigned elem_size = vector_size / nunits; |
| 25106 |
|
| 25107 |
/* Scalar mask case. */ |
| 25108 |
if ((TARGET_AVX512F && TARGET_EVEX512 && vector_size == 64) |
| 25109 |
|| (TARGET_AVX512VL && (vector_size == 32 || vector_size == 16)) |
| 25110 |
/* AVX512FP16 only supports vector comparison |
| 25111 |
to kmask for _Float16. */ |
| 25112 |
|| (TARGET_AVX512VL && TARGET_AVX512FP16 |
| 25113 |
&& GET_MODE_INNER (data_mode) == E_HFmode) |
| 25114 |
|| (TARGET_AVX10_2 && GET_MODE_INNER (data_mode) == E_BFmode)) |
| 25115 |
{ |
| 25116 |
if (elem_size == 4 |
| 25117 |
|| elem_size == 8 |
| 25118 |
|| (TARGET_AVX512BW && (elem_size == 1 || elem_size == 2))) |
| 25119 |
return smallest_int_mode_for_size (nunits).require (); |
| 25120 |
} |
| 25121 |
|
| 25122 |
scalar_int_mode elem_mode |
| 25123 |
= smallest_int_mode_for_size (elem_size * BITS_PER_UNIT).require (); |
| 25124 |
|
| 25125 |
gcc_assert (elem_size * nunits == vector_size); |
| 25126 |
|
| 25127 |
return mode_for_vector (elem_mode, nunits); |
| 25128 |
} |
| 25129 |
|
| 25130 |
|
| 25131 |
|
| 25132 |
/* Return class of registers which could be used for pseudo of MODE |
| 25133 |
and of class RCLASS for spilling instead of memory. Return NO_REGS |
| 25134 |
if it is not possible or non-profitable. */ |
| 25135 |
|
| 25136 |
/* Disabled due to PRs 70902, 71453, 71555, 71596 and 71657. */ |
| 25137 |
|
| 25138 |
static reg_class_t |
| 25139 |
ix86_spill_class (reg_class_t rclass, machine_mode mode) |
| 25140 |
{ |
| 25141 |
if (0 && TARGET_GENERAL_REGS_SSE_SPILL |
| 25142 |
&& TARGET_SSE2 |
| 25143 |
&& TARGET_INTER_UNIT_MOVES_TO_VEC |
| 25144 |
&& TARGET_INTER_UNIT_MOVES_FROM_VEC |
| 25145 |
&& (mode == SImode || (TARGET_64BIT && mode == DImode)) |
| 25146 |
&& INTEGER_CLASS_P (rclass)) |
| 25147 |
return ALL_SSE_REGS; |
| 25148 |
return NO_REGS; |
| 25149 |
} |
| 25150 |
|
| 25151 |
/* Implement TARGET_MAX_NOCE_IFCVT_SEQ_COST. Like the default implementation, |
| 25152 |
but returns a lower bound. */ |
| 25153 |
|
| 25154 |
static unsigned int |
| 25155 |
ix86_max_noce_ifcvt_seq_cost (edge e) |
| 25156 |
{ |
| 25157 |
bool predictable_p = predictable_edge_p (e); |
| 25158 |
if (predictable_p) |
| 25159 |
{ |
| 25160 |
if (OPTION_SET_P (param_max_rtl_if_conversion_predictable_cost)) |
| 25161 |
return param_max_rtl_if_conversion_predictable_cost; |
| 25162 |
} |
| 25163 |
else |
| 25164 |
{ |
| 25165 |
if (OPTION_SET_P (param_max_rtl_if_conversion_unpredictable_cost)) |
| 25166 |
return param_max_rtl_if_conversion_unpredictable_cost; |
| 25167 |
} |
| 25168 |
|
| 25169 |
/* For modern machines with deeper pipeline, the penalty for branch |
| 25170 |
misprediction could be higher than before to reset the pipeline |
| 25171 |
slots. Add parameter br_mispredict_scale as a factor to describe |
| 25172 |
the impact of reseting the pipeline. */ |
| 25173 |
|
| 25174 |
return BRANCH_COST (true, predictable_p) |
| 25175 |
* ix86_tune_cost->br_mispredict_scale; |
| 25176 |
} |
| 25177 |
|
| 25178 |
/* Return true if SEQ is a good candidate as a replacement for the |
| 25179 |
if-convertible sequence described in IF_INFO. */ |
| 25180 |
|
| 25181 |
static bool |
| 25182 |
ix86_noce_conversion_profitable_p (rtx_insn *seq, struct noce_if_info *if_info) |
| 25183 |
{ |
| 25184 |
if (TARGET_ONE_IF_CONV_INSN && if_info->speed_p) |
| 25185 |
{ |
| 25186 |
int cmov_cnt = 0; |
| 25187 |
/* Punt if SEQ contains more than one CMOV or FCMOV instruction. |
| 25188 |
Maybe we should allow even more conditional moves as long as they |
| 25189 |
are used far enough not to stall the CPU, or also consider |
| 25190 |
IF_INFO->TEST_BB succ edge probabilities. */ |
| 25191 |
for (rtx_insn *insn = seq; insn; insn = NEXT_INSN (insn)) |
| 25192 |
{ |
| 25193 |
rtx set = single_set (insn); |
| 25194 |
if (!set) |
| 25195 |
continue; |
| 25196 |
if (GET_CODE (SET_SRC (set)) != IF_THEN_ELSE) |
| 25197 |
continue; |
| 25198 |
rtx src = SET_SRC (set); |
| 25199 |
machine_mode mode = GET_MODE (src); |
| 25200 |
if (GET_MODE_CLASS (mode) != MODE_INT |
| 25201 |
&& GET_MODE_CLASS (mode) != MODE_FLOAT) |
| 25202 |
continue; |
| 25203 |
if ((!REG_P (XEXP (src, 1)) && !MEM_P (XEXP (src, 1))) |
| 25204 |
|| (!REG_P (XEXP (src, 2)) && !MEM_P (XEXP (src, 2)))) |
| 25205 |
continue; |
| 25206 |
/* insn is CMOV or FCMOV. */ |
| 25207 |
if (++cmov_cnt > 1) |
| 25208 |
return false; |
| 25209 |
} |
| 25210 |
} |
| 25211 |
|
| 25212 |
/* W/o TARGET_SSE4_1, it takes 3 instructions (pand, pandn and por) |
| 25213 |
for movdfcc/movsfcc, and could possibly fail cost comparison. |
| 25214 |
Increase branch cost will hurt performance for other modes, so |
| 25215 |
specially add some preference for floating point ifcvt. */ |
| 25216 |
if (!TARGET_SSE4_1 && if_info->x |
| 25217 |
&& GET_MODE_CLASS (GET_MODE (if_info->x)) == MODE_FLOAT |
| 25218 |
&& if_info->speed_p) |
| 25219 |
{ |
| 25220 |
unsigned cost = seq_cost (seq, true); |
| 25221 |
|
| 25222 |
if (cost <= if_info->original_cost) |
| 25223 |
return true; |
| 25224 |
|
| 25225 |
return cost <= (if_info->max_seq_cost + COSTS_N_INSNS (2)); |
| 25226 |
} |
| 25227 |
|
| 25228 |
return default_noce_conversion_profitable_p (seq, if_info); |
| 25229 |
} |
| 25230 |
|
| 25231 |
/* x86-specific vector costs. */ |
| 25232 |
class ix86_vector_costs : public vector_costs |
| 25233 |
{ |
| 25234 |
public: |
| 25235 |
ix86_vector_costs (vec_info *, bool); |
| 25236 |
|
| 25237 |
unsigned int add_stmt_cost (int count, vect_cost_for_stmt kind, |
| 25238 |
stmt_vec_info stmt_info, slp_tree node, |
| 25239 |
tree vectype, int misalign, |
| 25240 |
vect_cost_model_location where) override; |
| 25241 |
void finish_cost (const vector_costs *) override; |
| 25242 |
|
| 25243 |
private: |
| 25244 |
|
| 25245 |
/* Estimate register pressure of the vectorized code. */ |
| 25246 |
void ix86_vect_estimate_reg_pressure (); |
| 25247 |
/* Number of GENERAL_REGS/SSE_REGS used in the vectorizer, it's used for |
| 25248 |
estimation of register pressure. |
| 25249 |
??? Currently it's only used by vec_construct/scalar_to_vec |
| 25250 |
where we know it's not loaded from memory. */ |
| 25251 |
unsigned m_num_gpr_needed[3]; |
| 25252 |
unsigned m_num_sse_needed[3]; |
| 25253 |
/* Number of 256-bit vector permutation. */ |
| 25254 |
unsigned m_num_avx256_vec_perm[3]; |
| 25255 |
}; |
| 25256 |
|
| 25257 |
ix86_vector_costs::ix86_vector_costs (vec_info* vinfo, bool costing_for_scalar) |
| 25258 |
: vector_costs (vinfo, costing_for_scalar), |
| 25259 |
m_num_gpr_needed (), |
| 25260 |
m_num_sse_needed (), |
| 25261 |
m_num_avx256_vec_perm () |
| 25262 |
{ |
| 25263 |
} |
| 25264 |
|
| 25265 |
/* Implement targetm.vectorize.create_costs. */ |
| 25266 |
|
| 25267 |
static vector_costs * |
| 25268 |
ix86_vectorize_create_costs (vec_info *vinfo, bool costing_for_scalar) |
| 25269 |
{ |
| 25270 |
return new ix86_vector_costs (vinfo, costing_for_scalar); |
| 25271 |
} |
| 25272 |
|
| 25273 |
unsigned |
| 25274 |
ix86_vector_costs::add_stmt_cost (int count, vect_cost_for_stmt kind, |
| 25275 |
stmt_vec_info stmt_info, slp_tree node, |
| 25276 |
tree vectype, int misalign, |
| 25277 |
vect_cost_model_location where) |
| 25278 |
{ |
| 25279 |
unsigned retval = 0; |
| 25280 |
bool scalar_p |
| 25281 |
= (kind == scalar_stmt || kind == scalar_load || kind == scalar_store); |
| 25282 |
int stmt_cost = - 1; |
| 25283 |
|
| 25284 |
bool fp = false; |
| 25285 |
machine_mode mode = scalar_p ? SImode : TImode; |
| 25286 |
|
| 25287 |
if (vectype != NULL) |
| 25288 |
{ |
| 25289 |
fp = FLOAT_TYPE_P (vectype); |
| 25290 |
mode = TYPE_MODE (vectype); |
| 25291 |
if (scalar_p) |
| 25292 |
mode = TYPE_MODE (TREE_TYPE (vectype)); |
| 25293 |
} |
| 25294 |
|
| 25295 |
if ((kind == vector_stmt || kind == scalar_stmt) |
| 25296 |
&& stmt_info |
| 25297 |
&& stmt_info->stmt && gimple_code (stmt_info->stmt) == GIMPLE_ASSIGN) |
| 25298 |
{ |
| 25299 |
tree_code subcode = gimple_assign_rhs_code (stmt_info->stmt); |
| 25300 |
/*machine_mode inner_mode = mode; |
| 25301 |
if (VECTOR_MODE_P (mode)) |
| 25302 |
inner_mode = GET_MODE_INNER (mode);*/ |
| 25303 |
|
| 25304 |
switch (subcode) |
| 25305 |
{ |
| 25306 |
case PLUS_EXPR: |
| 25307 |
case POINTER_PLUS_EXPR: |
| 25308 |
case MINUS_EXPR: |
| 25309 |
if (kind == scalar_stmt) |
| 25310 |
{ |
| 25311 |
if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode)) |
| 25312 |
stmt_cost = ix86_cost->addss; |
| 25313 |
else if (X87_FLOAT_MODE_P (mode)) |
| 25314 |
stmt_cost = ix86_cost->fadd; |
| 25315 |
else |
| 25316 |
stmt_cost = ix86_cost->add; |
| 25317 |
} |
| 25318 |
else |
| 25319 |
stmt_cost = ix86_vec_cost (mode, fp ? ix86_cost->addss |
| 25320 |
: ix86_cost->sse_op); |
| 25321 |
break; |
| 25322 |
|
| 25323 |
case MULT_EXPR: |
| 25324 |
/* For MULT_HIGHPART_EXPR, x86 only supports pmulhw, |
| 25325 |
take it as MULT_EXPR. */ |
| 25326 |
case MULT_HIGHPART_EXPR: |
| 25327 |
stmt_cost = ix86_multiplication_cost (ix86_cost, mode); |
| 25328 |
break; |
| 25329 |
/* There's no direct instruction for WIDEN_MULT_EXPR, |
| 25330 |
take emulation into account. */ |
| 25331 |
case WIDEN_MULT_EXPR: |
| 25332 |
stmt_cost = ix86_widen_mult_cost (ix86_cost, mode, |
| 25333 |
TYPE_UNSIGNED (vectype)); |
| 25334 |
break; |
| 25335 |
|
| 25336 |
case NEGATE_EXPR: |
| 25337 |
if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode)) |
| 25338 |
stmt_cost = ix86_cost->sse_op; |
| 25339 |
else if (X87_FLOAT_MODE_P (mode)) |
| 25340 |
stmt_cost = ix86_cost->fchs; |
| 25341 |
else if (VECTOR_MODE_P (mode)) |
| 25342 |
stmt_cost = ix86_vec_cost (mode, ix86_cost->sse_op); |
| 25343 |
else |
| 25344 |
stmt_cost = ix86_cost->add; |
| 25345 |
break; |
| 25346 |
case TRUNC_DIV_EXPR: |
| 25347 |
case CEIL_DIV_EXPR: |
| 25348 |
case FLOOR_DIV_EXPR: |
| 25349 |
case ROUND_DIV_EXPR: |
| 25350 |
case TRUNC_MOD_EXPR: |
| 25351 |
case CEIL_MOD_EXPR: |
| 25352 |
case FLOOR_MOD_EXPR: |
| 25353 |
case RDIV_EXPR: |
| 25354 |
case ROUND_MOD_EXPR: |
| 25355 |
case EXACT_DIV_EXPR: |
| 25356 |
stmt_cost = ix86_division_cost (ix86_cost, mode); |
| 25357 |
break; |
| 25358 |
|
| 25359 |
case RSHIFT_EXPR: |
| 25360 |
case LSHIFT_EXPR: |
| 25361 |
case LROTATE_EXPR: |
| 25362 |
case RROTATE_EXPR: |
| 25363 |
{ |
| 25364 |
tree op1 = gimple_assign_rhs1 (stmt_info->stmt); |
| 25365 |
tree op2 = gimple_assign_rhs2 (stmt_info->stmt); |
| 25366 |
stmt_cost = ix86_shift_rotate_cost |
| 25367 |
(ix86_cost, |
| 25368 |
(subcode == RSHIFT_EXPR |
| 25369 |
&& !TYPE_UNSIGNED (TREE_TYPE (op1))) |
| 25370 |
? ASHIFTRT : LSHIFTRT, mode, |
| 25371 |
TREE_CODE (op2) == INTEGER_CST, |
| 25372 |
cst_and_fits_in_hwi (op2) |
| 25373 |
? int_cst_value (op2) : -1, |
| 25374 |
false, false, NULL, NULL); |
| 25375 |
} |
| 25376 |
break; |
| 25377 |
case NOP_EXPR: |
| 25378 |
/* Only sign-conversions are free. */ |
| 25379 |
if (tree_nop_conversion_p |
| 25380 |
(TREE_TYPE (gimple_assign_lhs (stmt_info->stmt)), |
| 25381 |
TREE_TYPE (gimple_assign_rhs1 (stmt_info->stmt)))) |
| 25382 |
stmt_cost = 0; |
| 25383 |
break; |
| 25384 |
|
| 25385 |
case BIT_IOR_EXPR: |
| 25386 |
case ABS_EXPR: |
| 25387 |
case ABSU_EXPR: |
| 25388 |
case MIN_EXPR: |
| 25389 |
case MAX_EXPR: |
| 25390 |
case BIT_XOR_EXPR: |
| 25391 |
case BIT_AND_EXPR: |
| 25392 |
case BIT_NOT_EXPR: |
| 25393 |
if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode)) |
| 25394 |
stmt_cost = ix86_cost->sse_op; |
| 25395 |
else if (VECTOR_MODE_P (mode)) |
| 25396 |
stmt_cost = ix86_vec_cost (mode, ix86_cost->sse_op); |
| 25397 |
else |
| 25398 |
stmt_cost = ix86_cost->add; |
| 25399 |
break; |
| 25400 |
default: |
| 25401 |
break; |
| 25402 |
} |
| 25403 |
} |
| 25404 |
|
| 25405 |
combined_fn cfn; |
| 25406 |
if ((kind == vector_stmt || kind == scalar_stmt) |
| 25407 |
&& stmt_info |
| 25408 |
&& stmt_info->stmt |
| 25409 |
&& (cfn = gimple_call_combined_fn (stmt_info->stmt)) != CFN_LAST) |
| 25410 |
switch (cfn) |
| 25411 |
{ |
| 25412 |
case CFN_FMA: |
| 25413 |
stmt_cost = ix86_vec_cost (mode, |
| 25414 |
mode == SFmode ? ix86_cost->fmass |
| 25415 |
: ix86_cost->fmasd); |
| 25416 |
break; |
| 25417 |
case CFN_MULH: |
| 25418 |
stmt_cost = ix86_multiplication_cost (ix86_cost, mode); |
| 25419 |
break; |
| 25420 |
default: |
| 25421 |
break; |
| 25422 |
} |
| 25423 |
|
| 25424 |
/* If we do elementwise loads into a vector then we are bound by |
| 25425 |
latency and execution resources for the many scalar loads |
| 25426 |
(AGU and load ports). Try to account for this by scaling the |
| 25427 |
construction cost by the number of elements involved. */ |
| 25428 |
if ((kind == vec_construct || kind == vec_to_scalar) |
| 25429 |
&& ((stmt_info |
| 25430 |
&& (STMT_VINFO_TYPE (stmt_info) == load_vec_info_type |
| 25431 |
|| STMT_VINFO_TYPE (stmt_info) == store_vec_info_type) |
| 25432 |
&& ((STMT_VINFO_MEMORY_ACCESS_TYPE (stmt_info) == VMAT_ELEMENTWISE |
| 25433 |
&& (TREE_CODE (DR_STEP (STMT_VINFO_DATA_REF (stmt_info))) |
| 25434 |
!= INTEGER_CST)) |
| 25435 |
|| (STMT_VINFO_MEMORY_ACCESS_TYPE (stmt_info) |
| 25436 |
== VMAT_GATHER_SCATTER))) |
| 25437 |
|| (node |
| 25438 |
&& (((SLP_TREE_MEMORY_ACCESS_TYPE (node) == VMAT_ELEMENTWISE |
| 25439 |
|| (SLP_TREE_MEMORY_ACCESS_TYPE (node) == VMAT_STRIDED_SLP |
| 25440 |
&& SLP_TREE_LANES (node) == 1)) |
| 25441 |
&& (TREE_CODE (DR_STEP (STMT_VINFO_DATA_REF |
| 25442 |
(SLP_TREE_REPRESENTATIVE (node)))) |
| 25443 |
!= INTEGER_CST)) |
| 25444 |
|| (SLP_TREE_MEMORY_ACCESS_TYPE (node) |
| 25445 |
== VMAT_GATHER_SCATTER))))) |
| 25446 |
{ |
| 25447 |
stmt_cost = ix86_builtin_vectorization_cost (kind, vectype, misalign); |
| 25448 |
stmt_cost *= (TYPE_VECTOR_SUBPARTS (vectype) + 1); |
| 25449 |
} |
| 25450 |
else if ((kind == vec_construct || kind == scalar_to_vec) |
| 25451 |
&& node |
| 25452 |
&& SLP_TREE_DEF_TYPE (node) == vect_external_def) |
| 25453 |
{ |
| 25454 |
stmt_cost = ix86_builtin_vectorization_cost (kind, vectype, misalign); |
| 25455 |
unsigned i; |
| 25456 |
tree op; |
| 25457 |
FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_OPS (node), i, op) |
| 25458 |
if (TREE_CODE (op) == SSA_NAME) |
| 25459 |
TREE_VISITED (op) = 0; |
| 25460 |
FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_OPS (node), i, op) |
| 25461 |
{ |
| 25462 |
if (TREE_CODE (op) != SSA_NAME |
| 25463 |
|| TREE_VISITED (op)) |
| 25464 |
continue; |
| 25465 |
TREE_VISITED (op) = 1; |
| 25466 |
gimple *def = SSA_NAME_DEF_STMT (op); |
| 25467 |
tree tem; |
| 25468 |
if (is_gimple_assign (def) |
| 25469 |
&& CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def)) |
| 25470 |
&& ((tem = gimple_assign_rhs1 (def)), true) |
| 25471 |
&& TREE_CODE (tem) == SSA_NAME |
| 25472 |
/* A sign-change expands to nothing. */ |
| 25473 |
&& tree_nop_conversion_p (TREE_TYPE (gimple_assign_lhs (def)), |
| 25474 |
TREE_TYPE (tem))) |
| 25475 |
def = SSA_NAME_DEF_STMT (tem); |
| 25476 |
/* When the component is loaded from memory we can directly |
| 25477 |
move it to a vector register, otherwise we have to go |
| 25478 |
via a GPR or via vpinsr which involves similar cost. |
| 25479 |
Likewise with a BIT_FIELD_REF extracting from a vector |
| 25480 |
register we can hope to avoid using a GPR. */ |
| 25481 |
if (!is_gimple_assign (def) |
| 25482 |
|| ((!gimple_assign_load_p (def) |
| 25483 |
|| (!TARGET_SSE4_1 |
| 25484 |
&& GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op))) == 1)) |
| 25485 |
&& (gimple_assign_rhs_code (def) != BIT_FIELD_REF |
| 25486 |
|| !VECTOR_TYPE_P (TREE_TYPE |
| 25487 |
(TREE_OPERAND (gimple_assign_rhs1 (def), 0)))))) |
| 25488 |
{ |
| 25489 |
if (fp) |
| 25490 |
m_num_sse_needed[where]++; |
| 25491 |
else |
| 25492 |
{ |
| 25493 |
m_num_gpr_needed[where]++; |
| 25494 |
stmt_cost += ix86_cost->sse_to_integer; |
| 25495 |
} |
| 25496 |
} |
| 25497 |
} |
| 25498 |
FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_OPS (node), i, op) |
| 25499 |
if (TREE_CODE (op) == SSA_NAME) |
| 25500 |
TREE_VISITED (op) = 0; |
| 25501 |
} |
| 25502 |
if (stmt_cost == -1) |
| 25503 |
stmt_cost = ix86_builtin_vectorization_cost (kind, vectype, misalign); |
| 25504 |
|
| 25505 |
if (kind == vec_perm && vectype |
| 25506 |
&& GET_MODE_SIZE (TYPE_MODE (vectype)) == 32) |
| 25507 |
m_num_avx256_vec_perm[where]++; |
| 25508 |
|
| 25509 |
/* Penalize DFmode vector operations for Bonnell. */ |
| 25510 |
if (TARGET_CPU_P (BONNELL) && kind == vector_stmt |
| 25511 |
&& vectype && GET_MODE_INNER (TYPE_MODE (vectype)) == DFmode) |
| 25512 |
stmt_cost *= 5; /* FIXME: The value here is arbitrary. */ |
| 25513 |
|
| 25514 |
/* Statements in an inner loop relative to the loop being |
| 25515 |
vectorized are weighted more heavily. The value here is |
| 25516 |
arbitrary and could potentially be improved with analysis. */ |
| 25517 |
retval = adjust_cost_for_freq (stmt_info, where, count * stmt_cost); |
| 25518 |
|
| 25519 |
/* We need to multiply all vector stmt cost by 1.7 (estimated cost) |
| 25520 |
for Silvermont as it has out of order integer pipeline and can execute |
| 25521 |
2 scalar instruction per tick, but has in order SIMD pipeline. */ |
| 25522 |
if ((TARGET_CPU_P (SILVERMONT) || TARGET_CPU_P (GOLDMONT) |
| 25523 |
|| TARGET_CPU_P (GOLDMONT_PLUS) || TARGET_CPU_P (INTEL)) |
| 25524 |
&& stmt_info && stmt_info->stmt) |
| 25525 |
{ |
| 25526 |
tree lhs_op = gimple_get_lhs (stmt_info->stmt); |
| 25527 |
if (lhs_op && TREE_CODE (TREE_TYPE (lhs_op)) == INTEGER_TYPE) |
| 25528 |
retval = (retval * 17) / 10; |
| 25529 |
} |
| 25530 |
|
| 25531 |
m_costs[where] += retval; |
| 25532 |
|
| 25533 |
return retval; |
| 25534 |
} |
| 25535 |
|
| 25536 |
void |
| 25537 |
ix86_vector_costs::ix86_vect_estimate_reg_pressure () |
| 25538 |
{ |
| 25539 |
unsigned gpr_spill_cost = COSTS_N_INSNS (ix86_cost->int_store [2]) / 2; |
| 25540 |
unsigned sse_spill_cost = COSTS_N_INSNS (ix86_cost->sse_store[0]) / 2; |
| 25541 |
|
| 25542 |
/* Any better way to have target available fp registers, currently use SSE_REGS. */ |
| 25543 |
unsigned target_avail_sse = TARGET_64BIT ? (TARGET_AVX512F ? 32 : 16) : 8; |
| 25544 |
for (unsigned i = 0; i != 3; i++) |
| 25545 |
{ |
| 25546 |
if (m_num_gpr_needed[i] > target_avail_regs) |
| 25547 |
m_costs[i] += gpr_spill_cost * (m_num_gpr_needed[i] - target_avail_regs); |
| 25548 |
/* Only measure sse registers pressure. */ |
| 25549 |
if (TARGET_SSE && (m_num_sse_needed[i] > target_avail_sse)) |
| 25550 |
m_costs[i] += sse_spill_cost * (m_num_sse_needed[i] - target_avail_sse); |
| 25551 |
} |
| 25552 |
} |
| 25553 |
|
| 25554 |
void |
| 25555 |
ix86_vector_costs::finish_cost (const vector_costs *scalar_costs) |
| 25556 |
{ |
| 25557 |
loop_vec_info loop_vinfo = dyn_cast<loop_vec_info> (m_vinfo); |
| 25558 |
if (loop_vinfo && !m_costing_for_scalar) |
| 25559 |
{ |
| 25560 |
/* We are currently not asking the vectorizer to compare costs |
| 25561 |
between different vector mode sizes. When using predication |
| 25562 |
that will end up always choosing the prefered mode size even |
| 25563 |
if there's a smaller mode covering all lanes. Test for this |
| 25564 |
situation and artificially reject the larger mode attempt. |
| 25565 |
??? We currently lack masked ops for sub-SSE sized modes, |
| 25566 |
so we could restrict this rejection to AVX and AVX512 modes |
| 25567 |
but error on the safe side for now. */ |
| 25568 |
if (LOOP_VINFO_USING_PARTIAL_VECTORS_P (loop_vinfo) |
| 25569 |
&& !LOOP_VINFO_EPILOGUE_P (loop_vinfo) |
| 25570 |
&& LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo) |
| 25571 |
&& (exact_log2 (LOOP_VINFO_VECT_FACTOR (loop_vinfo).to_constant ()) |
| 25572 |
> ceil_log2 (LOOP_VINFO_INT_NITERS (loop_vinfo)))) |
| 25573 |
m_costs[vect_body] = INT_MAX; |
| 25574 |
} |
| 25575 |
|
| 25576 |
ix86_vect_estimate_reg_pressure (); |
| 25577 |
|
| 25578 |
for (int i = 0; i != 3; i++) |
| 25579 |
if (m_num_avx256_vec_perm[i] |
| 25580 |
&& TARGET_AVX256_AVOID_VEC_PERM) |
| 25581 |
m_costs[i] = INT_MAX; |
| 25582 |
|
| 25583 |
/* When X86_TUNE_AVX512_TWO_EPILOGUES is enabled arrange for both |
| 25584 |
a AVX2 and a SSE epilogue for AVX512 vectorized loops. */ |
| 25585 |
if (loop_vinfo |
| 25586 |
&& LOOP_VINFO_EPILOGUE_P (loop_vinfo) |
| 25587 |
&& GET_MODE_SIZE (loop_vinfo->vector_mode) == 32 |
| 25588 |
&& ix86_tune_features[X86_TUNE_AVX512_TWO_EPILOGUES]) |
| 25589 |
m_suggested_epilogue_mode = V16QImode; |
| 25590 |
/* When a 128bit SSE vectorized epilogue still has a VF of 16 or larger |
| 25591 |
enable a 64bit SSE epilogue. */ |
| 25592 |
if (loop_vinfo |
| 25593 |
&& LOOP_VINFO_EPILOGUE_P (loop_vinfo) |
| 25594 |
&& GET_MODE_SIZE (loop_vinfo->vector_mode) == 16 |
| 25595 |
&& LOOP_VINFO_VECT_FACTOR (loop_vinfo).to_constant () >= 16) |
| 25596 |
m_suggested_epilogue_mode = V8QImode; |
| 25597 |
|
| 25598 |
vector_costs::finish_cost (scalar_costs); |
| 25599 |
} |
| 25600 |
|
| 25601 |
/* Validate target specific memory model bits in VAL. */ |
| 25602 |
|
| 25603 |
static unsigned HOST_WIDE_INT |
| 25604 |
ix86_memmodel_check (unsigned HOST_WIDE_INT val) |
| 25605 |
{ |
| 25606 |
enum memmodel model = memmodel_from_int (val); |
| 25607 |
bool strong; |
| 25608 |
|
| 25609 |
if (val & ~(unsigned HOST_WIDE_INT)(IX86_HLE_ACQUIRE|IX86_HLE_RELEASE |
| 25610 |
|MEMMODEL_MASK) |
| 25611 |
|| ((val & IX86_HLE_ACQUIRE) && (val & IX86_HLE_RELEASE))) |
| 25612 |
{ |
| 25613 |
warning (OPT_Winvalid_memory_model, |
| 25614 |
"unknown architecture specific memory model"); |
| 25615 |
return MEMMODEL_SEQ_CST; |
| 25616 |
} |
| 25617 |
strong = (is_mm_acq_rel (model) || is_mm_seq_cst (model)); |
| 25618 |
if (val & IX86_HLE_ACQUIRE && !(is_mm_acquire (model) || strong)) |
| 25619 |
{ |
| 25620 |
warning (OPT_Winvalid_memory_model, |
| 25621 |
"%<HLE_ACQUIRE%> not used with %<ACQUIRE%> or stronger " |
| 25622 |
"memory model"); |
| 25623 |
return MEMMODEL_SEQ_CST | IX86_HLE_ACQUIRE; |
| 25624 |
} |
| 25625 |
if (val & IX86_HLE_RELEASE && !(is_mm_release (model) || strong)) |
| 25626 |
{ |
| 25627 |
warning (OPT_Winvalid_memory_model, |
| 25628 |
"%<HLE_RELEASE%> not used with %<RELEASE%> or stronger " |
| 25629 |
"memory model"); |
| 25630 |
return MEMMODEL_SEQ_CST | IX86_HLE_RELEASE; |
| 25631 |
} |
| 25632 |
return val; |
| 25633 |
} |
| 25634 |
|
| 25635 |
/* Set CLONEI->vecsize_mangle, CLONEI->mask_mode, CLONEI->vecsize_int, |
| 25636 |
CLONEI->vecsize_float and if CLONEI->simdlen is 0, also |
| 25637 |
CLONEI->simdlen. Return 0 if SIMD clones shouldn't be emitted, |
| 25638 |
or number of vecsize_mangle variants that should be emitted. */ |
| 25639 |
|
| 25640 |
static int |
| 25641 |
ix86_simd_clone_compute_vecsize_and_simdlen (struct cgraph_node *node, |
| 25642 |
struct cgraph_simd_clone *clonei, |
| 25643 |
tree base_type, int num, |
| 25644 |
bool explicit_p) |
| 25645 |
{ |
| 25646 |
int ret = 1; |
| 25647 |
|
| 25648 |
if (clonei->simdlen |
| 25649 |
&& (clonei->simdlen < 2 |
| 25650 |
|| clonei->simdlen > 1024 |
| 25651 |
|| (clonei->simdlen & (clonei->simdlen - 1)) != 0)) |
| 25652 |
{ |
| 25653 |
if (explicit_p) |
| 25654 |
warning_at (DECL_SOURCE_LOCATION (node->decl), 0, |
| 25655 |
"unsupported simdlen %wd", clonei->simdlen.to_constant ()); |
| 25656 |
return 0; |
| 25657 |
} |
| 25658 |
|
| 25659 |
tree ret_type = TREE_TYPE (TREE_TYPE (node->decl)); |
| 25660 |
if (TREE_CODE (ret_type) != VOID_TYPE) |
| 25661 |
switch (TYPE_MODE (ret_type)) |
| 25662 |
{ |
| 25663 |
case E_QImode: |
| 25664 |
case E_HImode: |
| 25665 |
case E_SImode: |
| 25666 |
case E_DImode: |
| 25667 |
case E_SFmode: |
| 25668 |
case E_DFmode: |
| 25669 |
/* case E_SCmode: */ |
| 25670 |
/* case E_DCmode: */ |
| 25671 |
if (!AGGREGATE_TYPE_P (ret_type)) |
| 25672 |
break; |
| 25673 |
/* FALLTHRU */ |
| 25674 |
default: |
| 25675 |
if (explicit_p) |
| 25676 |
warning_at (DECL_SOURCE_LOCATION (node->decl), 0, |
| 25677 |
"unsupported return type %qT for simd", ret_type); |
| 25678 |
return 0; |
| 25679 |
} |
| 25680 |
|
| 25681 |
tree t; |
| 25682 |
int i; |
| 25683 |
tree type_arg_types = TYPE_ARG_TYPES (TREE_TYPE (node->decl)); |
| 25684 |
bool decl_arg_p = (node->definition || type_arg_types == NULL_TREE); |
| 25685 |
|
| 25686 |
for (t = (decl_arg_p ? DECL_ARGUMENTS (node->decl) : type_arg_types), i = 0; |
| 25687 |
t && t != void_list_node; t = TREE_CHAIN (t), i++) |
| 25688 |
{ |
| 25689 |
tree arg_type = decl_arg_p ? TREE_TYPE (t) : TREE_VALUE (t); |
| 25690 |
switch (TYPE_MODE (arg_type)) |
| 25691 |
{ |
| 25692 |
case E_QImode: |
| 25693 |
case E_HImode: |
| 25694 |
case E_SImode: |
| 25695 |
case E_DImode: |
| 25696 |
case E_SFmode: |
| 25697 |
case E_DFmode: |
| 25698 |
/* case E_SCmode: */ |
| 25699 |
/* case E_DCmode: */ |
| 25700 |
if (!AGGREGATE_TYPE_P (arg_type)) |
| 25701 |
break; |
| 25702 |
/* FALLTHRU */ |
| 25703 |
default: |
| 25704 |
if (clonei->args[i].arg_type == SIMD_CLONE_ARG_TYPE_UNIFORM) |
| 25705 |
break; |
| 25706 |
if (explicit_p) |
| 25707 |
warning_at (DECL_SOURCE_LOCATION (node->decl), 0, |
| 25708 |
"unsupported argument type %qT for simd", arg_type); |
| 25709 |
return 0; |
| 25710 |
} |
| 25711 |
} |
| 25712 |
|
| 25713 |
if (!TREE_PUBLIC (node->decl) || !explicit_p) |
| 25714 |
{ |
| 25715 |
/* If the function isn't exported, we can pick up just one ISA |
| 25716 |
for the clones. */ |
| 25717 |
if (TARGET_AVX512F && TARGET_EVEX512) |
| 25718 |
clonei->vecsize_mangle = 'e'; |
| 25719 |
else if (TARGET_AVX2) |
| 25720 |
clonei->vecsize_mangle = 'd'; |
| 25721 |
else if (TARGET_AVX) |
| 25722 |
clonei->vecsize_mangle = 'c'; |
| 25723 |
else |
| 25724 |
clonei->vecsize_mangle = 'b'; |
| 25725 |
ret = 1; |
| 25726 |
} |
| 25727 |
else |
| 25728 |
{ |
| 25729 |
clonei->vecsize_mangle = "bcde"[num]; |
| 25730 |
ret = 4; |
| 25731 |
} |
| 25732 |
clonei->mask_mode = VOIDmode; |
| 25733 |
switch (clonei->vecsize_mangle) |
| 25734 |
{ |
| 25735 |
case 'b': |
| 25736 |
clonei->vecsize_int = 128; |
| 25737 |
clonei->vecsize_float = 128; |
| 25738 |
break; |
| 25739 |
case 'c': |
| 25740 |
clonei->vecsize_int = 128; |
| 25741 |
clonei->vecsize_float = 256; |
| 25742 |
break; |
| 25743 |
case 'd': |
| 25744 |
clonei->vecsize_int = 256; |
| 25745 |
clonei->vecsize_float = 256; |
| 25746 |
break; |
| 25747 |
case 'e': |
| 25748 |
clonei->vecsize_int = 512; |
| 25749 |
clonei->vecsize_float = 512; |
| 25750 |
if (TYPE_MODE (base_type) == QImode) |
| 25751 |
clonei->mask_mode = DImode; |
| 25752 |
else |
| 25753 |
clonei->mask_mode = SImode; |
| 25754 |
break; |
| 25755 |
} |
| 25756 |
if (clonei->simdlen == 0) |
| 25757 |
{ |
| 25758 |
if (SCALAR_INT_MODE_P (TYPE_MODE (base_type))) |
| 25759 |
clonei->simdlen = clonei->vecsize_int; |
| 25760 |
else |
| 25761 |
clonei->simdlen = clonei->vecsize_float; |
| 25762 |
clonei->simdlen = clonei->simdlen |
| 25763 |
/ GET_MODE_BITSIZE (TYPE_MODE (base_type)); |
| 25764 |
} |
| 25765 |
else if (clonei->simdlen > 16) |
| 25766 |
{ |
| 25767 |
/* For compatibility with ICC, use the same upper bounds |
| 25768 |
for simdlen. In particular, for CTYPE below, use the return type, |
| 25769 |
unless the function returns void, in that case use the characteristic |
| 25770 |
type. If it is possible for given SIMDLEN to pass CTYPE value |
| 25771 |
in registers (8 [XYZ]MM* regs for 32-bit code, 16 [XYZ]MM* regs |
| 25772 |
for 64-bit code), accept that SIMDLEN, otherwise warn and don't |
| 25773 |
emit corresponding clone. */ |
| 25774 |
tree ctype = ret_type; |
| 25775 |
if (VOID_TYPE_P (ret_type)) |
| 25776 |
ctype = base_type; |
| 25777 |
int cnt = GET_MODE_BITSIZE (TYPE_MODE (ctype)) * clonei->simdlen; |
| 25778 |
if (SCALAR_INT_MODE_P (TYPE_MODE (ctype))) |
| 25779 |
cnt /= clonei->vecsize_int; |
| 25780 |
else |
| 25781 |
cnt /= clonei->vecsize_float; |
| 25782 |
if (cnt > (TARGET_64BIT ? 16 : 8)) |
| 25783 |
{ |
| 25784 |
if (explicit_p) |
| 25785 |
warning_at (DECL_SOURCE_LOCATION (node->decl), 0, |
| 25786 |
"unsupported simdlen %wd", |
| 25787 |
clonei->simdlen.to_constant ()); |
| 25788 |
return 0; |
| 25789 |
} |
| 25790 |
} |
| 25791 |
return ret; |
| 25792 |
} |
| 25793 |
|
| 25794 |
/* If SIMD clone NODE can't be used in a vectorized loop |
| 25795 |
in current function, return -1, otherwise return a badness of using it |
| 25796 |
(0 if it is most desirable from vecsize_mangle point of view, 1 |
| 25797 |
slightly less desirable, etc.). */ |
| 25798 |
|
| 25799 |
static int |
| 25800 |
ix86_simd_clone_usable (struct cgraph_node *node, machine_mode) |
| 25801 |
{ |
| 25802 |
switch (node->simdclone->vecsize_mangle) |
| 25803 |
{ |
| 25804 |
case 'b': |
| 25805 |
if (!TARGET_SSE2) |
| 25806 |
return -1; |
| 25807 |
if (!TARGET_AVX) |
| 25808 |
return 0; |
| 25809 |
return (TARGET_AVX512F && TARGET_EVEX512) ? 3 : TARGET_AVX2 ? 2 : 1; |
| 25810 |
case 'c': |
| 25811 |
if (!TARGET_AVX) |
| 25812 |
return -1; |
| 25813 |
return (TARGET_AVX512F && TARGET_EVEX512) ? 2 : TARGET_AVX2 ? 1 : 0; |
| 25814 |
case 'd': |
| 25815 |
if (!TARGET_AVX2) |
| 25816 |
return -1; |
| 25817 |
return (TARGET_AVX512F && TARGET_EVEX512) ? 1 : 0; |
| 25818 |
case 'e': |
| 25819 |
if (!TARGET_AVX512F || !TARGET_EVEX512) |
| 25820 |
return -1; |
| 25821 |
return 0; |
| 25822 |
default: |
| 25823 |
gcc_unreachable (); |
| 25824 |
} |
| 25825 |
} |
| 25826 |
|
| 25827 |
/* This function adjusts the unroll factor based on |
| 25828 |
the hardware capabilities. For ex, bdver3 has |
| 25829 |
a loop buffer which makes unrolling of smaller |
| 25830 |
loops less important. This function decides the |
| 25831 |
unroll factor using number of memory references |
| 25832 |
(value 32 is used) as a heuristic. */ |
| 25833 |
|
| 25834 |
static unsigned |
| 25835 |
ix86_loop_unroll_adjust (unsigned nunroll, class loop *loop) |
| 25836 |
{ |
| 25837 |
basic_block *bbs; |
| 25838 |
rtx_insn *insn; |
| 25839 |
unsigned i; |
| 25840 |
unsigned mem_count = 0; |
| 25841 |
|
| 25842 |
/* Unroll small size loop when unroll factor is not explicitly |
| 25843 |
specified. */ |
| 25844 |
if (ix86_unroll_only_small_loops && !loop->unroll) |
| 25845 |
{ |
| 25846 |
if (loop->ninsns <= ix86_cost->small_unroll_ninsns) |
| 25847 |
return MIN (nunroll, ix86_cost->small_unroll_factor); |
| 25848 |
else |
| 25849 |
return 1; |
| 25850 |
} |
| 25851 |
|
| 25852 |
if (!TARGET_ADJUST_UNROLL) |
| 25853 |
return nunroll; |
| 25854 |
|
| 25855 |
/* Count the number of memory references within the loop body. |
| 25856 |
This value determines the unrolling factor for bdver3 and bdver4 |
| 25857 |
architectures. */ |
| 25858 |
subrtx_iterator::array_type array; |
| 25859 |
bbs = get_loop_body (loop); |
| 25860 |
for (i = 0; i < loop->num_nodes; i++) |
| 25861 |
FOR_BB_INSNS (bbs[i], insn) |
| 25862 |
if (NONDEBUG_INSN_P (insn)) |
| 25863 |
FOR_EACH_SUBRTX (iter, array, PATTERN (insn), NONCONST) |
| 25864 |
if (const_rtx x = *iter) |
| 25865 |
if (MEM_P (x)) |
| 25866 |
{ |
| 25867 |
machine_mode mode = GET_MODE (x); |
| 25868 |
unsigned int n_words = GET_MODE_SIZE (mode) / UNITS_PER_WORD; |
| 25869 |
if (n_words > 4) |
| 25870 |
mem_count += 2; |
| 25871 |
else |
| 25872 |
mem_count += 1; |
| 25873 |
} |
| 25874 |
free (bbs); |
| 25875 |
|
| 25876 |
if (mem_count && mem_count <=32) |
| 25877 |
return MIN (nunroll, 32 / mem_count); |
| 25878 |
|
| 25879 |
return nunroll; |
| 25880 |
} |
| 25881 |
|
| 25882 |
|
| 25883 |
/* Implement TARGET_FLOAT_EXCEPTIONS_ROUNDING_SUPPORTED_P. */ |
| 25884 |
|
| 25885 |
static bool |
| 25886 |
ix86_float_exceptions_rounding_supported_p (void) |
| 25887 |
{ |
| 25888 |
/* For x87 floating point with standard excess precision handling, |
| 25889 |
there is no adddf3 pattern (since x87 floating point only has |
| 25890 |
XFmode operations) so the default hook implementation gets this |
| 25891 |
wrong. */ |
| 25892 |
return TARGET_80387 || (TARGET_SSE && TARGET_SSE_MATH); |
| 25893 |
} |
| 25894 |
|
| 25895 |
/* Implement TARGET_ATOMIC_ASSIGN_EXPAND_FENV. */ |
| 25896 |
|
| 25897 |
static void |
| 25898 |
ix86_atomic_assign_expand_fenv (tree *hold, tree *clear, tree *update) |
| 25899 |
{ |
| 25900 |
if (!TARGET_80387 && !(TARGET_SSE && TARGET_SSE_MATH)) |
| 25901 |
return; |
| 25902 |
tree exceptions_var = create_tmp_var_raw (integer_type_node); |
| 25903 |
if (TARGET_80387) |
| 25904 |
{ |
| 25905 |
tree fenv_index_type = build_index_type (size_int (6)); |
| 25906 |
tree fenv_type = build_array_type (unsigned_type_node, fenv_index_type); |
| 25907 |
tree fenv_var = create_tmp_var_raw (fenv_type); |
| 25908 |
TREE_ADDRESSABLE (fenv_var) = 1; |
| 25909 |
tree fenv_ptr = build_pointer_type (fenv_type); |
| 25910 |
tree fenv_addr = build1 (ADDR_EXPR, fenv_ptr, fenv_var); |
| 25911 |
fenv_addr = fold_convert (ptr_type_node, fenv_addr); |
| 25912 |
tree fnstenv = get_ix86_builtin (IX86_BUILTIN_FNSTENV); |
| 25913 |
tree fldenv = get_ix86_builtin (IX86_BUILTIN_FLDENV); |
| 25914 |
tree fnstsw = get_ix86_builtin (IX86_BUILTIN_FNSTSW); |
| 25915 |
tree fnclex = get_ix86_builtin (IX86_BUILTIN_FNCLEX); |
| 25916 |
tree hold_fnstenv = build_call_expr (fnstenv, 1, fenv_addr); |
| 25917 |
tree hold_fnclex = build_call_expr (fnclex, 0); |
| 25918 |
fenv_var = build4 (TARGET_EXPR, fenv_type, fenv_var, hold_fnstenv, |
| 25919 |
NULL_TREE, NULL_TREE); |
| 25920 |
*hold = build2 (COMPOUND_EXPR, void_type_node, fenv_var, |
| 25921 |
hold_fnclex); |
| 25922 |
*clear = build_call_expr (fnclex, 0); |
| 25923 |
tree sw_var = create_tmp_var_raw (short_unsigned_type_node); |
| 25924 |
tree fnstsw_call = build_call_expr (fnstsw, 0); |
| 25925 |
tree sw_mod = build4 (TARGET_EXPR, short_unsigned_type_node, sw_var, |
| 25926 |
fnstsw_call, NULL_TREE, NULL_TREE); |
| 25927 |
tree exceptions_x87 = fold_convert (integer_type_node, sw_var); |
| 25928 |
tree update_mod = build4 (TARGET_EXPR, integer_type_node, |
| 25929 |
exceptions_var, exceptions_x87, |
| 25930 |
NULL_TREE, NULL_TREE); |
| 25931 |
*update = build2 (COMPOUND_EXPR, integer_type_node, |
| 25932 |
sw_mod, update_mod); |
| 25933 |
tree update_fldenv = build_call_expr (fldenv, 1, fenv_addr); |
| 25934 |
*update = build2 (COMPOUND_EXPR, void_type_node, *update, update_fldenv); |
| 25935 |
} |
| 25936 |
if (TARGET_SSE && TARGET_SSE_MATH) |
| 25937 |
{ |
| 25938 |
tree mxcsr_orig_var = create_tmp_var_raw (unsigned_type_node); |
| 25939 |
tree mxcsr_mod_var = create_tmp_var_raw (unsigned_type_node); |
| 25940 |
tree stmxcsr = get_ix86_builtin (IX86_BUILTIN_STMXCSR); |
| 25941 |
tree ldmxcsr = get_ix86_builtin (IX86_BUILTIN_LDMXCSR); |
| 25942 |
tree stmxcsr_hold_call = build_call_expr (stmxcsr, 0); |
| 25943 |
tree hold_assign_orig = build4 (TARGET_EXPR, unsigned_type_node, |
| 25944 |
mxcsr_orig_var, stmxcsr_hold_call, |
| 25945 |
NULL_TREE, NULL_TREE); |
| 25946 |
tree hold_mod_val = build2 (BIT_IOR_EXPR, unsigned_type_node, |
| 25947 |
mxcsr_orig_var, |
| 25948 |
build_int_cst (unsigned_type_node, 0x1f80)); |
| 25949 |
hold_mod_val = build2 (BIT_AND_EXPR, unsigned_type_node, hold_mod_val, |
| 25950 |
build_int_cst (unsigned_type_node, 0xffffffc0)); |
| 25951 |
tree hold_assign_mod = build4 (TARGET_EXPR, unsigned_type_node, |
| 25952 |
mxcsr_mod_var, hold_mod_val, |
| 25953 |
NULL_TREE, NULL_TREE); |
| 25954 |
tree ldmxcsr_hold_call = build_call_expr (ldmxcsr, 1, mxcsr_mod_var); |
| 25955 |
tree hold_all = build2 (COMPOUND_EXPR, unsigned_type_node, |
| 25956 |
hold_assign_orig, hold_assign_mod); |
| 25957 |
hold_all = build2 (COMPOUND_EXPR, void_type_node, hold_all, |
| 25958 |
ldmxcsr_hold_call); |
| 25959 |
if (*hold) |
| 25960 |
*hold = build2 (COMPOUND_EXPR, void_type_node, *hold, hold_all); |
| 25961 |
else |
| 25962 |
*hold = hold_all; |
| 25963 |
tree ldmxcsr_clear_call = build_call_expr (ldmxcsr, 1, mxcsr_mod_var); |
| 25964 |
if (*clear) |
| 25965 |
*clear = build2 (COMPOUND_EXPR, void_type_node, *clear, |
| 25966 |
ldmxcsr_clear_call); |
| 25967 |
else |
| 25968 |
*clear = ldmxcsr_clear_call; |
| 25969 |
tree stxmcsr_update_call = build_call_expr (stmxcsr, 0); |
| 25970 |
tree exceptions_sse = fold_convert (integer_type_node, |
| 25971 |
stxmcsr_update_call); |
| 25972 |
if (*update) |
| 25973 |
{ |
| 25974 |
tree exceptions_mod = build2 (BIT_IOR_EXPR, integer_type_node, |
| 25975 |
exceptions_var, exceptions_sse); |
| 25976 |
tree exceptions_assign = build2 (MODIFY_EXPR, integer_type_node, |
| 25977 |
exceptions_var, exceptions_mod); |
| 25978 |
*update = build2 (COMPOUND_EXPR, integer_type_node, *update, |
| 25979 |
exceptions_assign); |
| 25980 |
} |
| 25981 |
else |
| 25982 |
*update = build4 (TARGET_EXPR, integer_type_node, exceptions_var, |
| 25983 |
exceptions_sse, NULL_TREE, NULL_TREE); |
| 25984 |
tree ldmxcsr_update_call = build_call_expr (ldmxcsr, 1, mxcsr_orig_var); |
| 25985 |
*update = build2 (COMPOUND_EXPR, void_type_node, *update, |
| 25986 |
ldmxcsr_update_call); |
| 25987 |
} |
| 25988 |
tree atomic_feraiseexcept |
| 25989 |
= builtin_decl_implicit (BUILT_IN_ATOMIC_FERAISEEXCEPT); |
| 25990 |
tree atomic_feraiseexcept_call = build_call_expr (atomic_feraiseexcept, |
| 25991 |
1, exceptions_var); |
| 25992 |
*update = build2 (COMPOUND_EXPR, void_type_node, *update, |
| 25993 |
atomic_feraiseexcept_call); |
| 25994 |
} |
| 25995 |
|
| 25996 |
#if !TARGET_MACHO && !TARGET_DLLIMPORT_DECL_ATTRIBUTES |
| 25997 |
/* For i386, common symbol is local only for non-PIE binaries. For |
| 25998 |
x86-64, common symbol is local only for non-PIE binaries or linker |
| 25999 |
supports copy reloc in PIE binaries. */ |
| 26000 |
|
| 26001 |
static bool |
| 26002 |
ix86_binds_local_p (const_tree exp) |
| 26003 |
{ |
| 26004 |
bool direct_extern_access |
| 26005 |
= (ix86_direct_extern_access |
| 26006 |
&& !(VAR_OR_FUNCTION_DECL_P (exp) |
| 26007 |
&& lookup_attribute ("nodirect_extern_access", |
| 26008 |
DECL_ATTRIBUTES (exp)))); |
| 26009 |
if (!direct_extern_access) |
| 26010 |
ix86_has_no_direct_extern_access = true; |
| 26011 |
return default_binds_local_p_3 (exp, flag_shlib != 0, true, |
| 26012 |
direct_extern_access, |
| 26013 |
(direct_extern_access |
| 26014 |
&& (!flag_pic |
| 26015 |
|| (TARGET_64BIT |
| 26016 |
&& HAVE_LD_PIE_COPYRELOC != 0)))); |
| 26017 |
} |
| 26018 |
|
| 26019 |
/* If flag_pic or ix86_direct_extern_access is false, then neither |
| 26020 |
local nor global relocs should be placed in readonly memory. */ |
| 26021 |
|
| 26022 |
static int |
| 26023 |
ix86_reloc_rw_mask (void) |
| 26024 |
{ |
| 26025 |
return (flag_pic || !ix86_direct_extern_access) ? 3 : 0; |
| 26026 |
} |
| 26027 |
#endif |
| 26028 |
|
| 26029 |
/* Return true iff ADDR can be used as a symbolic base address. */ |
| 26030 |
|
| 26031 |
static bool |
| 26032 |
symbolic_base_address_p (rtx addr) |
| 26033 |
{ |
| 26034 |
if (GET_CODE (addr) == SYMBOL_REF) |
| 26035 |
return true; |
| 26036 |
|
| 26037 |
if (GET_CODE (addr) == UNSPEC && XINT (addr, 1) == UNSPEC_GOTOFF) |
| 26038 |
return true; |
| 26039 |
|
| 26040 |
return false; |
| 26041 |
} |
| 26042 |
|
| 26043 |
/* Return true iff ADDR can be used as a base address. */ |
| 26044 |
|
| 26045 |
static bool |
| 26046 |
base_address_p (rtx addr) |
| 26047 |
{ |
| 26048 |
if (REG_P (addr)) |
| 26049 |
return true; |
| 26050 |
|
| 26051 |
if (symbolic_base_address_p (addr)) |
| 26052 |
return true; |
| 26053 |
|
| 26054 |
return false; |
| 26055 |
} |
| 26056 |
|
| 26057 |
/* If MEM is in the form of [(base+symbase)+offset], extract the three |
| 26058 |
parts of address and set to BASE, SYMBASE and OFFSET, otherwise |
| 26059 |
return false. */ |
| 26060 |
|
| 26061 |
static bool |
| 26062 |
extract_base_offset_in_addr (rtx mem, rtx *base, rtx *symbase, rtx *offset) |
| 26063 |
{ |
| 26064 |
rtx addr; |
| 26065 |
|
| 26066 |
gcc_assert (MEM_P (mem)); |
| 26067 |
|
| 26068 |
addr = XEXP (mem, 0); |
| 26069 |
|
| 26070 |
if (GET_CODE (addr) == CONST) |
| 26071 |
addr = XEXP (addr, 0); |
| 26072 |
|
| 26073 |
if (base_address_p (addr)) |
| 26074 |
{ |
| 26075 |
*base = addr; |
| 26076 |
*symbase = const0_rtx; |
| 26077 |
*offset = const0_rtx; |
| 26078 |
return true; |
| 26079 |
} |
| 26080 |
|
| 26081 |
if (GET_CODE (addr) == PLUS |
| 26082 |
&& base_address_p (XEXP (addr, 0))) |
| 26083 |
{ |
| 26084 |
rtx addend = XEXP (addr, 1); |
| 26085 |
|
| 26086 |
if (GET_CODE (addend) == CONST) |
| 26087 |
addend = XEXP (addend, 0); |
| 26088 |
|
| 26089 |
if (CONST_INT_P (addend)) |
| 26090 |
{ |
| 26091 |
*base = XEXP (addr, 0); |
| 26092 |
*symbase = const0_rtx; |
| 26093 |
*offset = addend; |
| 26094 |
return true; |
| 26095 |
} |
| 26096 |
|
| 26097 |
/* Also accept REG + symbolic ref, with or without a CONST_INT |
| 26098 |
offset. */ |
| 26099 |
if (REG_P (XEXP (addr, 0))) |
| 26100 |
{ |
| 26101 |
if (symbolic_base_address_p (addend)) |
| 26102 |
{ |
| 26103 |
*base = XEXP (addr, 0); |
| 26104 |
*symbase = addend; |
| 26105 |
*offset = const0_rtx; |
| 26106 |
return true; |
| 26107 |
} |
| 26108 |
|
| 26109 |
if (GET_CODE (addend) == PLUS |
| 26110 |
&& symbolic_base_address_p (XEXP (addend, 0)) |
| 26111 |
&& CONST_INT_P (XEXP (addend, 1))) |
| 26112 |
{ |
| 26113 |
*base = XEXP (addr, 0); |
| 26114 |
*symbase = XEXP (addend, 0); |
| 26115 |
*offset = XEXP (addend, 1); |
| 26116 |
return true; |
| 26117 |
} |
| 26118 |
} |
| 26119 |
} |
| 26120 |
|
| 26121 |
return false; |
| 26122 |
} |
| 26123 |
|
| 26124 |
/* Given OPERANDS of consecutive load/store, check if we can merge |
| 26125 |
them into move multiple. LOAD is true if they are load instructions. |
| 26126 |
MODE is the mode of memory operands. */ |
| 26127 |
|
| 26128 |
bool |
| 26129 |
ix86_operands_ok_for_move_multiple (rtx *operands, bool load, |
| 26130 |
machine_mode mode) |
| 26131 |
{ |
| 26132 |
HOST_WIDE_INT offval_1, offval_2, msize; |
| 26133 |
rtx mem_1, mem_2, reg_1, reg_2, base_1, base_2, |
| 26134 |
symbase_1, symbase_2, offset_1, offset_2; |
| 26135 |
|
| 26136 |
if (load) |
| 26137 |
{ |
| 26138 |
mem_1 = operands[1]; |
| 26139 |
mem_2 = operands[3]; |
| 26140 |
reg_1 = operands[0]; |
| 26141 |
reg_2 = operands[2]; |
| 26142 |
} |
| 26143 |
else |
| 26144 |
{ |
| 26145 |
mem_1 = operands[0]; |
| 26146 |
mem_2 = operands[2]; |
| 26147 |
reg_1 = operands[1]; |
| 26148 |
reg_2 = operands[3]; |
| 26149 |
} |
| 26150 |
|
| 26151 |
gcc_assert (REG_P (reg_1) && REG_P (reg_2)); |
| 26152 |
|
| 26153 |
if (REGNO (reg_1) != REGNO (reg_2)) |
| 26154 |
return false; |
| 26155 |
|
| 26156 |
/* Check if the addresses are in the form of [base+offset]. */ |
| 26157 |
if (!extract_base_offset_in_addr (mem_1, &base_1, &symbase_1, &offset_1)) |
| 26158 |
return false; |
| 26159 |
if (!extract_base_offset_in_addr (mem_2, &base_2, &symbase_2, &offset_2)) |
| 26160 |
return false; |
| 26161 |
|
| 26162 |
/* Check if the bases are the same. */ |
| 26163 |
if (!rtx_equal_p (base_1, base_2) || !rtx_equal_p (symbase_1, symbase_2)) |
| 26164 |
return false; |
| 26165 |
|
| 26166 |
offval_1 = INTVAL (offset_1); |
| 26167 |
offval_2 = INTVAL (offset_2); |
| 26168 |
msize = GET_MODE_SIZE (mode); |
| 26169 |
/* Check if mem_1 is adjacent to mem_2 and mem_1 has lower address. */ |
| 26170 |
if (offval_1 + msize != offval_2) |
| 26171 |
return false; |
| 26172 |
|
| 26173 |
return true; |
| 26174 |
} |
| 26175 |
|
| 26176 |
/* Implement the TARGET_OPTAB_SUPPORTED_P hook. */ |
| 26177 |
|
| 26178 |
static bool |
| 26179 |
ix86_optab_supported_p (int op, machine_mode mode1, machine_mode, |
| 26180 |
optimization_type opt_type) |
| 26181 |
{ |
| 26182 |
switch (op) |
| 26183 |
{ |
| 26184 |
case asin_optab: |
| 26185 |
case acos_optab: |
| 26186 |
case log1p_optab: |
| 26187 |
case exp_optab: |
| 26188 |
case exp10_optab: |
| 26189 |
case exp2_optab: |
| 26190 |
case expm1_optab: |
| 26191 |
case ldexp_optab: |
| 26192 |
case scalb_optab: |
| 26193 |
case round_optab: |
| 26194 |
case lround_optab: |
| 26195 |
return opt_type == OPTIMIZE_FOR_SPEED; |
| 26196 |
|
| 26197 |
case rint_optab: |
| 26198 |
if (SSE_FLOAT_MODE_P (mode1) |
| 26199 |
&& TARGET_SSE_MATH |
| 26200 |
&& !flag_trapping_math |
| 26201 |
&& !TARGET_SSE4_1 |
| 26202 |
&& mode1 != HFmode) |
| 26203 |
return opt_type == OPTIMIZE_FOR_SPEED; |
| 26204 |
return true; |
| 26205 |
|
| 26206 |
case floor_optab: |
| 26207 |
case ceil_optab: |
| 26208 |
case btrunc_optab: |
| 26209 |
if (((SSE_FLOAT_MODE_P (mode1) |
| 26210 |
&& TARGET_SSE_MATH |
| 26211 |
&& TARGET_SSE4_1) |
| 26212 |
|| mode1 == HFmode) |
| 26213 |
&& !flag_trapping_math) |
| 26214 |
return true; |
| 26215 |
return opt_type == OPTIMIZE_FOR_SPEED; |
| 26216 |
|
| 26217 |
case rsqrt_optab: |
| 26218 |
return opt_type == OPTIMIZE_FOR_SPEED && use_rsqrt_p (mode1); |
| 26219 |
|
| 26220 |
default: |
| 26221 |
return true; |
| 26222 |
} |
| 26223 |
} |
| 26224 |
|
| 26225 |
/* Address space support. |
| 26226 |
|
| 26227 |
This is not "far pointers" in the 16-bit sense, but an easy way |
| 26228 |
to use %fs and %gs segment prefixes. Therefore: |
| 26229 |
|
| 26230 |
(a) All address spaces have the same modes, |
| 26231 |
(b) All address spaces have the same addresss forms, |
| 26232 |
(c) While %fs and %gs are technically subsets of the generic |
| 26233 |
address space, they are probably not subsets of each other. |
| 26234 |
(d) Since we have no access to the segment base register values |
| 26235 |
without resorting to a system call, we cannot convert a |
| 26236 |
non-default address space to a default address space. |
| 26237 |
Therefore we do not claim %fs or %gs are subsets of generic. |
| 26238 |
|
| 26239 |
Therefore we can (mostly) use the default hooks. */ |
| 26240 |
|
| 26241 |
/* All use of segmentation is assumed to make address 0 valid. */ |
| 26242 |
|
| 26243 |
static bool |
| 26244 |
ix86_addr_space_zero_address_valid (addr_space_t as) |
| 26245 |
{ |
| 26246 |
return as != ADDR_SPACE_GENERIC; |
| 26247 |
} |
| 26248 |
|
| 26249 |
static void |
| 26250 |
ix86_init_libfuncs (void) |
| 26251 |
{ |
| 26252 |
if (TARGET_64BIT) |
| 26253 |
{ |
| 26254 |
set_optab_libfunc (sdivmod_optab, TImode, "__divmodti4"); |
| 26255 |
set_optab_libfunc (udivmod_optab, TImode, "__udivmodti4"); |
| 26256 |
} |
| 26257 |
else |
| 26258 |
{ |
| 26259 |
set_optab_libfunc (sdivmod_optab, DImode, "__divmoddi4"); |
| 26260 |
set_optab_libfunc (udivmod_optab, DImode, "__udivmoddi4"); |
| 26261 |
} |
| 26262 |
|
| 26263 |
#if TARGET_MACHO |
| 26264 |
darwin_rename_builtins (); |
| 26265 |
#endif |
| 26266 |
} |
| 26267 |
|
| 26268 |
/* Set the value of FLT_EVAL_METHOD in float.h. When using only the |
| 26269 |
FPU, assume that the fpcw is set to extended precision; when using |
| 26270 |
only SSE, rounding is correct; when using both SSE and the FPU, |
| 26271 |
the rounding precision is indeterminate, since either may be chosen |
| 26272 |
apparently at random. */ |
| 26273 |
|
| 26274 |
static enum flt_eval_method |
| 26275 |
ix86_get_excess_precision (enum excess_precision_type type) |
| 26276 |
{ |
| 26277 |
switch (type) |
| 26278 |
{ |
| 26279 |
case EXCESS_PRECISION_TYPE_FAST: |
| 26280 |
/* The fastest type to promote to will always be the native type, |
| 26281 |
whether that occurs with implicit excess precision or |
| 26282 |
otherwise. */ |
| 26283 |
return TARGET_AVX512FP16 |
| 26284 |
? FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16 |
| 26285 |
: FLT_EVAL_METHOD_PROMOTE_TO_FLOAT; |
| 26286 |
case EXCESS_PRECISION_TYPE_STANDARD: |
| 26287 |
case EXCESS_PRECISION_TYPE_IMPLICIT: |
| 26288 |
/* Otherwise, the excess precision we want when we are |
| 26289 |
in a standards compliant mode, and the implicit precision we |
| 26290 |
provide would be identical were it not for the unpredictable |
| 26291 |
cases. */ |
| 26292 |
if (TARGET_AVX512FP16 && TARGET_SSE_MATH) |
| 26293 |
return FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16; |
| 26294 |
else if (!TARGET_80387) |
| 26295 |
return FLT_EVAL_METHOD_PROMOTE_TO_FLOAT; |
| 26296 |
else if (!TARGET_MIX_SSE_I387) |
| 26297 |
{ |
| 26298 |
if (!(TARGET_SSE && TARGET_SSE_MATH)) |
| 26299 |
return FLT_EVAL_METHOD_PROMOTE_TO_LONG_DOUBLE; |
| 26300 |
else if (TARGET_SSE2) |
| 26301 |
return FLT_EVAL_METHOD_PROMOTE_TO_FLOAT; |
| 26302 |
} |
| 26303 |
|
| 26304 |
/* If we are in standards compliant mode, but we know we will |
| 26305 |
calculate in unpredictable precision, return |
| 26306 |
FLT_EVAL_METHOD_FLOAT. There is no reason to introduce explicit |
| 26307 |
excess precision if the target can't guarantee it will honor |
| 26308 |
it. */ |
| 26309 |
return (type == EXCESS_PRECISION_TYPE_STANDARD |
| 26310 |
? FLT_EVAL_METHOD_PROMOTE_TO_FLOAT |
| 26311 |
: FLT_EVAL_METHOD_UNPREDICTABLE); |
| 26312 |
case EXCESS_PRECISION_TYPE_FLOAT16: |
| 26313 |
if (TARGET_80387 |
| 26314 |
&& !(TARGET_SSE_MATH && TARGET_SSE)) |
| 26315 |
error ("%<-fexcess-precision=16%> is not compatible with %<-mfpmath=387%>"); |
| 26316 |
return FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16; |
| 26317 |
default: |
| 26318 |
gcc_unreachable (); |
| 26319 |
} |
| 26320 |
|
| 26321 |
return FLT_EVAL_METHOD_UNPREDICTABLE; |
| 26322 |
} |
| 26323 |
|
| 26324 |
/* Return true if _BitInt(N) is supported and fill its details into *INFO. */ |
| 26325 |
bool |
| 26326 |
ix86_bitint_type_info (int n, struct bitint_info *info) |
| 26327 |
{ |
| 26328 |
if (n <= 8) |
| 26329 |
info->limb_mode = QImode; |
| 26330 |
else if (n <= 16) |
| 26331 |
info->limb_mode = HImode; |
| 26332 |
else if (n <= 32 || (!TARGET_64BIT && n > 64)) |
| 26333 |
info->limb_mode = SImode; |
| 26334 |
else |
| 26335 |
info->limb_mode = DImode; |
| 26336 |
info->abi_limb_mode = info->limb_mode; |
| 26337 |
info->big_endian = false; |
| 26338 |
info->extended = false; |
| 26339 |
return true; |
| 26340 |
} |
| 26341 |
|
| 26342 |
/* Implement TARGET_C_MODE_FOR_FLOATING_TYPE. Return DFmode, TFmode |
| 26343 |
or XFmode for TI_LONG_DOUBLE_TYPE which is for long double type, |
| 26344 |
based on long double bits, go with the default one for the others. */ |
| 26345 |
|
| 26346 |
static machine_mode |
| 26347 |
ix86_c_mode_for_floating_type (enum tree_index ti) |
| 26348 |
{ |
| 26349 |
if (ti == TI_LONG_DOUBLE_TYPE) |
| 26350 |
return (TARGET_LONG_DOUBLE_64 ? DFmode |
| 26351 |
: (TARGET_LONG_DOUBLE_128 ? TFmode : XFmode)); |
| 26352 |
return default_mode_for_floating_type (ti); |
| 26353 |
} |
| 26354 |
|
| 26355 |
/* Returns modified FUNCTION_TYPE for cdtor callabi. */ |
| 26356 |
tree |
| 26357 |
ix86_cxx_adjust_cdtor_callabi_fntype (tree fntype) |
| 26358 |
{ |
| 26359 |
if (TARGET_64BIT |
| 26360 |
|| TARGET_RTD |
| 26361 |
|| ix86_function_type_abi (fntype) != MS_ABI) |
| 26362 |
return fntype; |
| 26363 |
/* For 32-bit MS ABI add thiscall attribute. */ |
| 26364 |
tree attribs = tree_cons (get_identifier ("thiscall"), NULL_TREE, |
| 26365 |
TYPE_ATTRIBUTES (fntype)); |
| 26366 |
return build_type_attribute_variant (fntype, attribs); |
| 26367 |
} |
| 26368 |
|
| 26369 |
/* Implement PUSH_ROUNDING. On 386, we have pushw instruction that |
| 26370 |
decrements by exactly 2 no matter what the position was, there is no pushb. |
| 26371 |
|
| 26372 |
But as CIE data alignment factor on this arch is -4 for 32bit targets |
| 26373 |
and -8 for 64bit targets, we need to make sure all stack pointer adjustments |
| 26374 |
are in multiple of 4 for 32bit targets and 8 for 64bit targets. */ |
| 26375 |
|
| 26376 |
poly_int64 |
| 26377 |
ix86_push_rounding (poly_int64 bytes) |
| 26378 |
{ |
| 26379 |
return ROUND_UP (bytes, UNITS_PER_WORD); |
| 26380 |
} |
| 26381 |
|
| 26382 |
/* Use 8 bits metadata start from bit48 for LAM_U48, |
| 26383 |
6 bits metadat start from bit57 for LAM_U57. */ |
| 26384 |
#define IX86_HWASAN_SHIFT (ix86_lam_type == lam_u48 \ |
| 26385 |
? 48 \ |
| 26386 |
: (ix86_lam_type == lam_u57 ? 57 : 0)) |
| 26387 |
#define IX86_HWASAN_TAG_SIZE (ix86_lam_type == lam_u48 \ |
| 26388 |
? 8 \ |
| 26389 |
: (ix86_lam_type == lam_u57 ? 6 : 0)) |
| 26390 |
|
| 26391 |
/* Implement TARGET_MEMTAG_CAN_TAG_ADDRESSES. */ |
| 26392 |
bool |
| 26393 |
ix86_memtag_can_tag_addresses () |
| 26394 |
{ |
| 26395 |
return ix86_lam_type != lam_none && TARGET_LP64; |
| 26396 |
} |
| 26397 |
|
| 26398 |
/* Implement TARGET_MEMTAG_TAG_SIZE. */ |
| 26399 |
unsigned char |
| 26400 |
ix86_memtag_tag_size () |
| 26401 |
{ |
| 26402 |
return IX86_HWASAN_TAG_SIZE; |
| 26403 |
} |
| 26404 |
|
| 26405 |
/* Implement TARGET_MEMTAG_SET_TAG. */ |
| 26406 |
rtx |
| 26407 |
ix86_memtag_set_tag (rtx untagged, rtx tag, rtx target) |
| 26408 |
{ |
| 26409 |
/* default_memtag_insert_random_tag may |
| 26410 |
generate tag with value more than 6 bits. */ |
| 26411 |
if (ix86_lam_type == lam_u57) |
| 26412 |
{ |
| 26413 |
unsigned HOST_WIDE_INT and_imm |
| 26414 |
= (HOST_WIDE_INT_1U << IX86_HWASAN_TAG_SIZE) - 1; |
| 26415 |
|
| 26416 |
emit_insn (gen_andqi3 (tag, tag, GEN_INT (and_imm))); |
| 26417 |
} |
| 26418 |
tag = expand_simple_binop (Pmode, ASHIFT, tag, |
| 26419 |
GEN_INT (IX86_HWASAN_SHIFT), NULL_RTX, |
| 26420 |
/* unsignedp = */1, OPTAB_WIDEN); |
| 26421 |
rtx ret = expand_simple_binop (Pmode, IOR, untagged, tag, target, |
| 26422 |
/* unsignedp = */1, OPTAB_DIRECT); |
| 26423 |
return ret; |
| 26424 |
} |
| 26425 |
|
| 26426 |
/* Implement TARGET_MEMTAG_EXTRACT_TAG. */ |
| 26427 |
rtx |
| 26428 |
ix86_memtag_extract_tag (rtx tagged_pointer, rtx target) |
| 26429 |
{ |
| 26430 |
rtx tag = expand_simple_binop (Pmode, LSHIFTRT, tagged_pointer, |
| 26431 |
GEN_INT (IX86_HWASAN_SHIFT), target, |
| 26432 |
/* unsignedp = */0, |
| 26433 |
OPTAB_DIRECT); |
| 26434 |
rtx ret = gen_reg_rtx (QImode); |
| 26435 |
/* Mask off bit63 when LAM_U57. */ |
| 26436 |
if (ix86_lam_type == lam_u57) |
| 26437 |
{ |
| 26438 |
unsigned HOST_WIDE_INT and_imm |
| 26439 |
= (HOST_WIDE_INT_1U << IX86_HWASAN_TAG_SIZE) - 1; |
| 26440 |
emit_insn (gen_andqi3 (ret, gen_lowpart (QImode, tag), |
| 26441 |
gen_int_mode (and_imm, QImode))); |
| 26442 |
} |
| 26443 |
else |
| 26444 |
emit_move_insn (ret, gen_lowpart (QImode, tag)); |
| 26445 |
return ret; |
| 26446 |
} |
| 26447 |
|
| 26448 |
/* The default implementation of TARGET_MEMTAG_UNTAGGED_POINTER. */ |
| 26449 |
rtx |
| 26450 |
ix86_memtag_untagged_pointer (rtx tagged_pointer, rtx target) |
| 26451 |
{ |
| 26452 |
/* Leave bit63 alone. */ |
| 26453 |
rtx tag_mask = gen_int_mode (((HOST_WIDE_INT_1U << IX86_HWASAN_SHIFT) |
| 26454 |
+ (HOST_WIDE_INT_1U << 63) - 1), |
| 26455 |
Pmode); |
| 26456 |
rtx untagged_base = expand_simple_binop (Pmode, AND, tagged_pointer, |
| 26457 |
tag_mask, target, true, |
| 26458 |
OPTAB_DIRECT); |
| 26459 |
gcc_assert (untagged_base); |
| 26460 |
return untagged_base; |
| 26461 |
} |
| 26462 |
|
| 26463 |
/* Implement TARGET_MEMTAG_ADD_TAG. */ |
| 26464 |
rtx |
| 26465 |
ix86_memtag_add_tag (rtx base, poly_int64 offset, unsigned char tag_offset) |
| 26466 |
{ |
| 26467 |
rtx base_tag = gen_reg_rtx (QImode); |
| 26468 |
rtx base_addr = gen_reg_rtx (Pmode); |
| 26469 |
rtx tagged_addr = gen_reg_rtx (Pmode); |
| 26470 |
rtx new_tag = gen_reg_rtx (QImode); |
| 26471 |
unsigned HOST_WIDE_INT and_imm |
| 26472 |
= (HOST_WIDE_INT_1U << IX86_HWASAN_SHIFT) - 1; |
| 26473 |
|
| 26474 |
/* When there's "overflow" in tag adding, |
| 26475 |
need to mask the most significant bit off. */ |
| 26476 |
emit_move_insn (base_tag, ix86_memtag_extract_tag (base, NULL_RTX)); |
| 26477 |
emit_move_insn (base_addr, |
| 26478 |
ix86_memtag_untagged_pointer (base, NULL_RTX)); |
| 26479 |
emit_insn (gen_add2_insn (base_tag, gen_int_mode (tag_offset, QImode))); |
| 26480 |
emit_move_insn (new_tag, base_tag); |
| 26481 |
emit_insn (gen_andqi3 (new_tag, new_tag, gen_int_mode (and_imm, QImode))); |
| 26482 |
emit_move_insn (tagged_addr, |
| 26483 |
ix86_memtag_set_tag (base_addr, new_tag, NULL_RTX)); |
| 26484 |
return plus_constant (Pmode, tagged_addr, offset); |
| 26485 |
} |
| 26486 |
|
| 26487 |
/* Implement TARGET_HAVE_CCMP. */ |
| 26488 |
static bool |
| 26489 |
ix86_have_ccmp () |
| 26490 |
{ |
| 26491 |
return (bool) TARGET_APX_CCMP; |
| 26492 |
} |
| 26493 |
|
| 26494 |
/* Implement TARGET_MODE_CAN_TRANSFER_BITS. */ |
| 26495 |
static bool |
| 26496 |
ix86_mode_can_transfer_bits (machine_mode mode) |
| 26497 |
{ |
| 26498 |
if (GET_MODE_CLASS (mode) == MODE_FLOAT |
| 26499 |
|| GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT) |
| 26500 |
switch (GET_MODE_INNER (mode)) |
| 26501 |
{ |
| 26502 |
case E_SFmode: |
| 26503 |
case E_DFmode: |
| 26504 |
/* These suffer from normalization upon load when not using SSE. */ |
| 26505 |
return !(ix86_fpmath & FPMATH_387); |
| 26506 |
default: |
| 26507 |
return true; |
| 26508 |
} |
| 26509 |
|
| 26510 |
return true; |
| 26511 |
} |
| 26512 |
|
| 26513 |
/* Implement TARGET_REDZONE_CLOBBER. */ |
| 26514 |
static rtx |
| 26515 |
ix86_redzone_clobber () |
| 26516 |
{ |
| 26517 |
cfun->machine->asm_redzone_clobber_seen = true; |
| 26518 |
if (ix86_using_red_zone ()) |
| 26519 |
{ |
| 26520 |
rtx base = plus_constant (Pmode, stack_pointer_rtx, -RED_ZONE_SIZE); |
| 26521 |
rtx mem = gen_rtx_MEM (BLKmode, base); |
| 26522 |
set_mem_size (mem, RED_ZONE_SIZE); |
| 26523 |
return mem; |
| 26524 |
} |
| 26525 |
return NULL_RTX; |
| 26526 |
} |
| 26527 |
|
| 26528 |
/* Target-specific selftests. */ |
| 26529 |
|
| 26530 |
#if CHECKING_P |
| 26531 |
|
| 26532 |
namespace selftest { |
| 26533 |
|
| 26534 |
/* Verify that hard regs are dumped as expected (in compact mode). */ |
| 26535 |
|
| 26536 |
static void |
| 26537 |
ix86_test_dumping_hard_regs () |
| 26538 |
{ |
| 26539 |
ASSERT_RTL_DUMP_EQ ("(reg:SI ax)", gen_raw_REG (SImode, 0)); |
| 26540 |
ASSERT_RTL_DUMP_EQ ("(reg:SI dx)", gen_raw_REG (SImode, 1)); |
| 26541 |
} |
| 26542 |
|
| 26543 |
/* Test dumping an insn with repeated references to the same SCRATCH, |
| 26544 |
to verify the rtx_reuse code. */ |
| 26545 |
|
| 26546 |
static void |
| 26547 |
ix86_test_dumping_memory_blockage () |
| 26548 |
{ |
| 26549 |
set_new_first_and_last_insn (NULL, NULL); |
| 26550 |
|
| 26551 |
rtx pat = gen_memory_blockage (); |
| 26552 |
rtx_reuse_manager r; |
| 26553 |
r.preprocess (pat); |
| 26554 |
|
| 26555 |
/* Verify that the repeated references to the SCRATCH show use |
| 26556 |
reuse IDS. The first should be prefixed with a reuse ID, |
| 26557 |
and the second should be dumped as a "reuse_rtx" of that ID. |
| 26558 |
The expected string assumes Pmode == DImode. */ |
| 26559 |
if (Pmode == DImode) |
| 26560 |
ASSERT_RTL_DUMP_EQ_WITH_REUSE |
| 26561 |
("(cinsn 1 (set (mem/v:BLK (0|scratch:DI) [0 A8])\n" |
| 26562 |
" (unspec:BLK [\n" |
| 26563 |
" (mem/v:BLK (reuse_rtx 0) [0 A8])\n" |
| 26564 |
" ] UNSPEC_MEMORY_BLOCKAGE)))\n", pat, &r); |
| 26565 |
} |
| 26566 |
|
| 26567 |
/* Verify loading an RTL dump; specifically a dump of copying |
| 26568 |
a param on x86_64 from a hard reg into the frame. |
| 26569 |
This test is target-specific since the dump contains target-specific |
| 26570 |
hard reg names. */ |
| 26571 |
|
| 26572 |
static void |
| 26573 |
ix86_test_loading_dump_fragment_1 () |
| 26574 |
{ |
| 26575 |
rtl_dump_test t (SELFTEST_LOCATION, |
| 26576 |
locate_file ("x86_64/copy-hard-reg-into-frame.rtl")); |
| 26577 |
|
| 26578 |
rtx_insn *insn = get_insn_by_uid (1); |
| 26579 |
|
| 26580 |
/* The block structure and indentation here is purely for |
| 26581 |
readability; it mirrors the structure of the rtx. */ |
| 26582 |
tree mem_expr; |
| 26583 |
{ |
| 26584 |
rtx pat = PATTERN (insn); |
| 26585 |
ASSERT_EQ (SET, GET_CODE (pat)); |
| 26586 |
{ |
| 26587 |
rtx dest = SET_DEST (pat); |
| 26588 |
ASSERT_EQ (MEM, GET_CODE (dest)); |
| 26589 |
/* Verify the "/c" was parsed. */ |
| 26590 |
ASSERT_TRUE (RTX_FLAG (dest, call)); |
| 26591 |
ASSERT_EQ (SImode, GET_MODE (dest)); |
| 26592 |
{ |
| 26593 |
rtx addr = XEXP (dest, 0); |
| 26594 |
ASSERT_EQ (PLUS, GET_CODE (addr)); |
| 26595 |
ASSERT_EQ (DImode, GET_MODE (addr)); |
| 26596 |
{ |
| 26597 |
rtx lhs = XEXP (addr, 0); |
| 26598 |
/* Verify that the "frame" REG was consolidated. */ |
| 26599 |
ASSERT_RTX_PTR_EQ (frame_pointer_rtx, lhs); |
| 26600 |
} |
| 26601 |
{ |
| 26602 |
rtx rhs = XEXP (addr, 1); |
| 26603 |
ASSERT_EQ (CONST_INT, GET_CODE (rhs)); |
| 26604 |
ASSERT_EQ (-4, INTVAL (rhs)); |
| 26605 |
} |
| 26606 |
} |
| 26607 |
/* Verify the "[1 i+0 S4 A32]" was parsed. */ |
| 26608 |
ASSERT_EQ (1, MEM_ALIAS_SET (dest)); |
| 26609 |
/* "i" should have been handled by synthesizing a global int |
| 26610 |
variable named "i". */ |
| 26611 |
mem_expr = MEM_EXPR (dest); |
| 26612 |
ASSERT_NE (mem_expr, NULL); |
| 26613 |
ASSERT_EQ (VAR_DECL, TREE_CODE (mem_expr)); |
| 26614 |
ASSERT_EQ (integer_type_node, TREE_TYPE (mem_expr)); |
| 26615 |
ASSERT_EQ (IDENTIFIER_NODE, TREE_CODE (DECL_NAME (mem_expr))); |
| 26616 |
ASSERT_STREQ ("i", IDENTIFIER_POINTER (DECL_NAME (mem_expr))); |
| 26617 |
/* "+0". */ |
| 26618 |
ASSERT_TRUE (MEM_OFFSET_KNOWN_P (dest)); |
| 26619 |
ASSERT_EQ (0, MEM_OFFSET (dest)); |
| 26620 |
/* "S4". */ |
| 26621 |
ASSERT_EQ (4, MEM_SIZE (dest)); |
| 26622 |
/* "A32. */ |
| 26623 |
ASSERT_EQ (32, MEM_ALIGN (dest)); |
| 26624 |
} |
| 26625 |
{ |
| 26626 |
rtx src = SET_SRC (pat); |
| 26627 |
ASSERT_EQ (REG, GET_CODE (src)); |
| 26628 |
ASSERT_EQ (SImode, GET_MODE (src)); |
| 26629 |
ASSERT_EQ (5, REGNO (src)); |
| 26630 |
tree reg_expr = REG_EXPR (src); |
| 26631 |
/* "i" here should point to the same var as for the MEM_EXPR. */ |
| 26632 |
ASSERT_EQ (reg_expr, mem_expr); |
| 26633 |
} |
| 26634 |
} |
| 26635 |
} |
| 26636 |
|
| 26637 |
/* Verify that the RTL loader copes with a call_insn dump. |
| 26638 |
This test is target-specific since the dump contains a target-specific |
| 26639 |
hard reg name. */ |
| 26640 |
|
| 26641 |
static void |
| 26642 |
ix86_test_loading_call_insn () |
| 26643 |
{ |
| 26644 |
/* The test dump includes register "xmm0", where requires TARGET_SSE |
| 26645 |
to exist. */ |
| 26646 |
if (!TARGET_SSE) |
| 26647 |
return; |
| 26648 |
|
| 26649 |
rtl_dump_test t (SELFTEST_LOCATION, locate_file ("x86_64/call-insn.rtl")); |
| 26650 |
|
| 26651 |
rtx_insn *insn = get_insns (); |
| 26652 |
ASSERT_EQ (CALL_INSN, GET_CODE (insn)); |
| 26653 |
|
| 26654 |
/* "/j". */ |
| 26655 |
ASSERT_TRUE (RTX_FLAG (insn, jump)); |
| 26656 |
|
| 26657 |
rtx pat = PATTERN (insn); |
| 26658 |
ASSERT_EQ (CALL, GET_CODE (SET_SRC (pat))); |
| 26659 |
|
| 26660 |
/* Verify REG_NOTES. */ |
| 26661 |
{ |
| 26662 |
/* "(expr_list:REG_CALL_DECL". */ |
| 26663 |
ASSERT_EQ (EXPR_LIST, GET_CODE (REG_NOTES (insn))); |
| 26664 |
rtx_expr_list *note0 = as_a <rtx_expr_list *> (REG_NOTES (insn)); |
| 26665 |
ASSERT_EQ (REG_CALL_DECL, REG_NOTE_KIND (note0)); |
| 26666 |
|
| 26667 |
/* "(expr_list:REG_EH_REGION (const_int 0 [0])". */ |
| 26668 |
rtx_expr_list *note1 = note0->next (); |
| 26669 |
ASSERT_EQ (REG_EH_REGION, REG_NOTE_KIND (note1)); |
| 26670 |
|
| 26671 |
ASSERT_EQ (NULL, note1->next ()); |
| 26672 |
} |
| 26673 |
|
| 26674 |
/* Verify CALL_INSN_FUNCTION_USAGE. */ |
| 26675 |
{ |
| 26676 |
/* "(expr_list:DF (use (reg:DF 21 xmm0))". */ |
| 26677 |
rtx_expr_list *usage |
| 26678 |
= as_a <rtx_expr_list *> (CALL_INSN_FUNCTION_USAGE (insn)); |
| 26679 |
ASSERT_EQ (EXPR_LIST, GET_CODE (usage)); |
| 26680 |
ASSERT_EQ (DFmode, GET_MODE (usage)); |
| 26681 |
ASSERT_EQ (USE, GET_CODE (usage->element ())); |
| 26682 |
ASSERT_EQ (NULL, usage->next ()); |
| 26683 |
} |
| 26684 |
} |
| 26685 |
|
| 26686 |
/* Verify that the RTL loader copes a dump from print_rtx_function. |
| 26687 |
This test is target-specific since the dump contains target-specific |
| 26688 |
hard reg names. */ |
| 26689 |
|
| 26690 |
static void |
| 26691 |
ix86_test_loading_full_dump () |
| 26692 |
{ |
| 26693 |
rtl_dump_test t (SELFTEST_LOCATION, locate_file ("x86_64/times-two.rtl")); |
| 26694 |
|
| 26695 |
ASSERT_STREQ ("times_two", IDENTIFIER_POINTER (DECL_NAME (cfun->decl))); |
| 26696 |
|
| 26697 |
rtx_insn *insn_1 = get_insn_by_uid (1); |
| 26698 |
ASSERT_EQ (NOTE, GET_CODE (insn_1)); |
| 26699 |
|
| 26700 |
rtx_insn *insn_7 = get_insn_by_uid (7); |
| 26701 |
ASSERT_EQ (INSN, GET_CODE (insn_7)); |
| 26702 |
ASSERT_EQ (PARALLEL, GET_CODE (PATTERN (insn_7))); |
| 26703 |
|
| 26704 |
rtx_insn *insn_15 = get_insn_by_uid (15); |
| 26705 |
ASSERT_EQ (INSN, GET_CODE (insn_15)); |
| 26706 |
ASSERT_EQ (USE, GET_CODE (PATTERN (insn_15))); |
| 26707 |
|
| 26708 |
/* Verify crtl->return_rtx. */ |
| 26709 |
ASSERT_EQ (REG, GET_CODE (crtl->return_rtx)); |
| 26710 |
ASSERT_EQ (0, REGNO (crtl->return_rtx)); |
| 26711 |
ASSERT_EQ (SImode, GET_MODE (crtl->return_rtx)); |
| 26712 |
} |
| 26713 |
|
| 26714 |
/* Verify that the RTL loader copes with UNSPEC and UNSPEC_VOLATILE insns. |
| 26715 |
In particular, verify that it correctly loads the 2nd operand. |
| 26716 |
This test is target-specific since these are machine-specific |
| 26717 |
operands (and enums). */ |
| 26718 |
|
| 26719 |
static void |
| 26720 |
ix86_test_loading_unspec () |
| 26721 |
{ |
| 26722 |
rtl_dump_test t (SELFTEST_LOCATION, locate_file ("x86_64/unspec.rtl")); |
| 26723 |
|
| 26724 |
ASSERT_STREQ ("test_unspec", IDENTIFIER_POINTER (DECL_NAME (cfun->decl))); |
| 26725 |
|
| 26726 |
ASSERT_TRUE (cfun); |
| 26727 |
|
| 26728 |
/* Test of an UNSPEC. */ |
| 26729 |
rtx_insn *insn = get_insns (); |
| 26730 |
ASSERT_EQ (INSN, GET_CODE (insn)); |
| 26731 |
rtx set = single_set (insn); |
| 26732 |
ASSERT_NE (NULL, set); |
| 26733 |
rtx dst = SET_DEST (set); |
| 26734 |
ASSERT_EQ (MEM, GET_CODE (dst)); |
| 26735 |
rtx src = SET_SRC (set); |
| 26736 |
ASSERT_EQ (UNSPEC, GET_CODE (src)); |
| 26737 |
ASSERT_EQ (BLKmode, GET_MODE (src)); |
| 26738 |
ASSERT_EQ (UNSPEC_MEMORY_BLOCKAGE, XINT (src, 1)); |
| 26739 |
|
| 26740 |
rtx v0 = XVECEXP (src, 0, 0); |
| 26741 |
|
| 26742 |
/* Verify that the two uses of the first SCRATCH have pointer |
| 26743 |
equality. */ |
| 26744 |
rtx scratch_a = XEXP (dst, 0); |
| 26745 |
ASSERT_EQ (SCRATCH, GET_CODE (scratch_a)); |
| 26746 |
|
| 26747 |
rtx scratch_b = XEXP (v0, 0); |
| 26748 |
ASSERT_EQ (SCRATCH, GET_CODE (scratch_b)); |
| 26749 |
|
| 26750 |
ASSERT_EQ (scratch_a, scratch_b); |
| 26751 |
|
| 26752 |
/* Verify that the two mems are thus treated as equal. */ |
| 26753 |
ASSERT_TRUE (rtx_equal_p (dst, v0)); |
| 26754 |
|
| 26755 |
/* Verify that the insn is recognized. */ |
| 26756 |
ASSERT_NE(-1, recog_memoized (insn)); |
| 26757 |
|
| 26758 |
/* Test of an UNSPEC_VOLATILE, which has its own enum values. */ |
| 26759 |
insn = NEXT_INSN (insn); |
| 26760 |
ASSERT_EQ (INSN, GET_CODE (insn)); |
| 26761 |
|
| 26762 |
set = single_set (insn); |
| 26763 |
ASSERT_NE (NULL, set); |
| 26764 |
|
| 26765 |
src = SET_SRC (set); |
| 26766 |
ASSERT_EQ (UNSPEC_VOLATILE, GET_CODE (src)); |
| 26767 |
ASSERT_EQ (UNSPECV_RDTSCP, XINT (src, 1)); |
| 26768 |
} |
| 26769 |
|
| 26770 |
/* Run all target-specific selftests. */ |
| 26771 |
|
| 26772 |
static void |
| 26773 |
ix86_run_selftests (void) |
| 26774 |
{ |
| 26775 |
ix86_test_dumping_hard_regs (); |
| 26776 |
ix86_test_dumping_memory_blockage (); |
| 26777 |
|
| 26778 |
/* Various tests of loading RTL dumps, here because they contain |
| 26779 |
ix86-isms (e.g. names of hard regs). */ |
| 26780 |
ix86_test_loading_dump_fragment_1 (); |
| 26781 |
ix86_test_loading_call_insn (); |
| 26782 |
ix86_test_loading_full_dump (); |
| 26783 |
ix86_test_loading_unspec (); |
| 26784 |
} |
| 26785 |
|
| 26786 |
} // namespace selftest |
| 26787 |
|
| 26788 |
#endif /* CHECKING_P */ |
| 26789 |
|
| 26790 |
static const scoped_attribute_specs *const ix86_attribute_table[] = |
| 26791 |
{ |
| 26792 |
&ix86_gnu_attribute_table |
| 26793 |
}; |
| 26794 |
|
| 26795 |
/* Initialize the GCC target structure. */ |
| 26796 |
#undef TARGET_RETURN_IN_MEMORY |
| 26797 |
#define TARGET_RETURN_IN_MEMORY ix86_return_in_memory |
| 26798 |
|
| 26799 |
#undef TARGET_LEGITIMIZE_ADDRESS |
| 26800 |
#define TARGET_LEGITIMIZE_ADDRESS ix86_legitimize_address |
| 26801 |
|
| 26802 |
#undef TARGET_ATTRIBUTE_TABLE |
| 26803 |
#define TARGET_ATTRIBUTE_TABLE ix86_attribute_table |
| 26804 |
#undef TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P |
| 26805 |
#define TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P hook_bool_const_tree_true |
| 26806 |
#if TARGET_DLLIMPORT_DECL_ATTRIBUTES |
| 26807 |
# undef TARGET_MERGE_DECL_ATTRIBUTES |
| 26808 |
# define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes |
| 26809 |
#endif |
| 26810 |
|
| 26811 |
#undef TARGET_INVALID_CONVERSION |
| 26812 |
#define TARGET_INVALID_CONVERSION ix86_invalid_conversion |
| 26813 |
|
| 26814 |
#undef TARGET_INVALID_UNARY_OP |
| 26815 |
#define TARGET_INVALID_UNARY_OP ix86_invalid_unary_op |
| 26816 |
|
| 26817 |
#undef TARGET_INVALID_BINARY_OP |
| 26818 |
#define TARGET_INVALID_BINARY_OP ix86_invalid_binary_op |
| 26819 |
|
| 26820 |
#undef TARGET_COMP_TYPE_ATTRIBUTES |
| 26821 |
#define TARGET_COMP_TYPE_ATTRIBUTES ix86_comp_type_attributes |
| 26822 |
|
| 26823 |
#undef TARGET_INIT_BUILTINS |
| 26824 |
#define TARGET_INIT_BUILTINS ix86_init_builtins |
| 26825 |
#undef TARGET_BUILTIN_DECL |
| 26826 |
#define TARGET_BUILTIN_DECL ix86_builtin_decl |
| 26827 |
#undef TARGET_EXPAND_BUILTIN |
| 26828 |
#define TARGET_EXPAND_BUILTIN ix86_expand_builtin |
| 26829 |
|
| 26830 |
#undef TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION |
| 26831 |
#define TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION \ |
| 26832 |
ix86_builtin_vectorized_function |
| 26833 |
|
| 26834 |
#undef TARGET_VECTORIZE_BUILTIN_GATHER |
| 26835 |
#define TARGET_VECTORIZE_BUILTIN_GATHER ix86_vectorize_builtin_gather |
| 26836 |
|
| 26837 |
#undef TARGET_VECTORIZE_BUILTIN_SCATTER |
| 26838 |
#define TARGET_VECTORIZE_BUILTIN_SCATTER ix86_vectorize_builtin_scatter |
| 26839 |
|
| 26840 |
#undef TARGET_BUILTIN_RECIPROCAL |
| 26841 |
#define TARGET_BUILTIN_RECIPROCAL ix86_builtin_reciprocal |
| 26842 |
|
| 26843 |
#undef TARGET_ASM_FUNCTION_EPILOGUE |
| 26844 |
#define TARGET_ASM_FUNCTION_EPILOGUE ix86_output_function_epilogue |
| 26845 |
|
| 26846 |
#undef TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY |
| 26847 |
#define TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY \ |
| 26848 |
ix86_print_patchable_function_entry |
| 26849 |
|
| 26850 |
#undef TARGET_ENCODE_SECTION_INFO |
| 26851 |
#ifndef SUBTARGET_ENCODE_SECTION_INFO |
| 26852 |
#define TARGET_ENCODE_SECTION_INFO ix86_encode_section_info |
| 26853 |
#else |
| 26854 |
#define TARGET_ENCODE_SECTION_INFO SUBTARGET_ENCODE_SECTION_INFO |
| 26855 |
#endif |
| 26856 |
|
| 26857 |
#undef TARGET_ASM_OPEN_PAREN |
| 26858 |
#define TARGET_ASM_OPEN_PAREN "" |
| 26859 |
#undef TARGET_ASM_CLOSE_PAREN |
| 26860 |
#define TARGET_ASM_CLOSE_PAREN "" |
| 26861 |
|
| 26862 |
#undef TARGET_ASM_BYTE_OP |
| 26863 |
#define TARGET_ASM_BYTE_OP ASM_BYTE |
| 26864 |
|
| 26865 |
#undef TARGET_ASM_ALIGNED_HI_OP |
| 26866 |
#define TARGET_ASM_ALIGNED_HI_OP ASM_SHORT |
| 26867 |
#undef TARGET_ASM_ALIGNED_SI_OP |
| 26868 |
#define TARGET_ASM_ALIGNED_SI_OP ASM_LONG |
| 26869 |
#ifdef ASM_QUAD |
| 26870 |
#undef TARGET_ASM_ALIGNED_DI_OP |
| 26871 |
#define TARGET_ASM_ALIGNED_DI_OP ASM_QUAD |
| 26872 |
#endif |
| 26873 |
|
| 26874 |
#undef TARGET_PROFILE_BEFORE_PROLOGUE |
| 26875 |
#define TARGET_PROFILE_BEFORE_PROLOGUE ix86_profile_before_prologue |
| 26876 |
|
| 26877 |
#undef TARGET_MANGLE_DECL_ASSEMBLER_NAME |
| 26878 |
#define TARGET_MANGLE_DECL_ASSEMBLER_NAME ix86_mangle_decl_assembler_name |
| 26879 |
|
| 26880 |
#undef TARGET_ASM_UNALIGNED_HI_OP |
| 26881 |
#define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP |
| 26882 |
#undef TARGET_ASM_UNALIGNED_SI_OP |
| 26883 |
#define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP |
| 26884 |
#undef TARGET_ASM_UNALIGNED_DI_OP |
| 26885 |
#define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP |
| 26886 |
|
| 26887 |
#undef TARGET_PRINT_OPERAND |
| 26888 |
#define TARGET_PRINT_OPERAND ix86_print_operand |
| 26889 |
#undef TARGET_PRINT_OPERAND_ADDRESS |
| 26890 |
#define TARGET_PRINT_OPERAND_ADDRESS ix86_print_operand_address |
| 26891 |
#undef TARGET_PRINT_OPERAND_PUNCT_VALID_P |
| 26892 |
#define TARGET_PRINT_OPERAND_PUNCT_VALID_P ix86_print_operand_punct_valid_p |
| 26893 |
#undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA |
| 26894 |
#define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA i386_asm_output_addr_const_extra |
| 26895 |
|
| 26896 |
#undef TARGET_SCHED_INIT_GLOBAL |
| 26897 |
#define TARGET_SCHED_INIT_GLOBAL ix86_sched_init_global |
| 26898 |
#undef TARGET_SCHED_ADJUST_COST |
| 26899 |
#define TARGET_SCHED_ADJUST_COST ix86_adjust_cost |
| 26900 |
#undef TARGET_SCHED_ISSUE_RATE |
| 26901 |
#define TARGET_SCHED_ISSUE_RATE ix86_issue_rate |
| 26902 |
#undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD |
| 26903 |
#define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \ |
| 26904 |
ia32_multipass_dfa_lookahead |
| 26905 |
#undef TARGET_SCHED_MACRO_FUSION_P |
| 26906 |
#define TARGET_SCHED_MACRO_FUSION_P ix86_macro_fusion_p |
| 26907 |
#undef TARGET_SCHED_MACRO_FUSION_PAIR_P |
| 26908 |
#define TARGET_SCHED_MACRO_FUSION_PAIR_P ix86_macro_fusion_pair_p |
| 26909 |
|
| 26910 |
#undef TARGET_FUNCTION_OK_FOR_SIBCALL |
| 26911 |
#define TARGET_FUNCTION_OK_FOR_SIBCALL ix86_function_ok_for_sibcall |
| 26912 |
|
| 26913 |
#undef TARGET_MEMMODEL_CHECK |
| 26914 |
#define TARGET_MEMMODEL_CHECK ix86_memmodel_check |
| 26915 |
|
| 26916 |
#undef TARGET_ATOMIC_ASSIGN_EXPAND_FENV |
| 26917 |
#define TARGET_ATOMIC_ASSIGN_EXPAND_FENV ix86_atomic_assign_expand_fenv |
| 26918 |
|
| 26919 |
#ifdef HAVE_AS_TLS |
| 26920 |
#undef TARGET_HAVE_TLS |
| 26921 |
#define TARGET_HAVE_TLS true |
| 26922 |
#endif |
| 26923 |
#undef TARGET_CANNOT_FORCE_CONST_MEM |
| 26924 |
#define TARGET_CANNOT_FORCE_CONST_MEM ix86_cannot_force_const_mem |
| 26925 |
#undef TARGET_USE_BLOCKS_FOR_CONSTANT_P |
| 26926 |
#define TARGET_USE_BLOCKS_FOR_CONSTANT_P hook_bool_mode_const_rtx_true |
| 26927 |
|
| 26928 |
#undef TARGET_DELEGITIMIZE_ADDRESS |
| 26929 |
#define TARGET_DELEGITIMIZE_ADDRESS ix86_delegitimize_address |
| 26930 |
|
| 26931 |
#undef TARGET_CONST_NOT_OK_FOR_DEBUG_P |
| 26932 |
#define TARGET_CONST_NOT_OK_FOR_DEBUG_P ix86_const_not_ok_for_debug_p |
| 26933 |
|
| 26934 |
#undef TARGET_MS_BITFIELD_LAYOUT_P |
| 26935 |
#define TARGET_MS_BITFIELD_LAYOUT_P ix86_ms_bitfield_layout_p |
| 26936 |
|
| 26937 |
#if TARGET_MACHO |
| 26938 |
#undef TARGET_BINDS_LOCAL_P |
| 26939 |
#define TARGET_BINDS_LOCAL_P darwin_binds_local_p |
| 26940 |
#else |
| 26941 |
#undef TARGET_BINDS_LOCAL_P |
| 26942 |
#define TARGET_BINDS_LOCAL_P ix86_binds_local_p |
| 26943 |
#endif |
| 26944 |
#if TARGET_DLLIMPORT_DECL_ATTRIBUTES |
| 26945 |
#undef TARGET_BINDS_LOCAL_P |
| 26946 |
#define TARGET_BINDS_LOCAL_P i386_pe_binds_local_p |
| 26947 |
#endif |
| 26948 |
|
| 26949 |
#undef TARGET_ASM_OUTPUT_MI_THUNK |
| 26950 |
#define TARGET_ASM_OUTPUT_MI_THUNK x86_output_mi_thunk |
| 26951 |
#undef TARGET_ASM_CAN_OUTPUT_MI_THUNK |
| 26952 |
#define TARGET_ASM_CAN_OUTPUT_MI_THUNK x86_can_output_mi_thunk |
| 26953 |
|
| 26954 |
#undef TARGET_ASM_FILE_START |
| 26955 |
#define TARGET_ASM_FILE_START x86_file_start |
| 26956 |
|
| 26957 |
#undef TARGET_OPTION_OVERRIDE |
| 26958 |
#define TARGET_OPTION_OVERRIDE ix86_option_override |
| 26959 |
|
| 26960 |
#undef TARGET_REGISTER_MOVE_COST |
| 26961 |
#define TARGET_REGISTER_MOVE_COST ix86_register_move_cost |
| 26962 |
#undef TARGET_MEMORY_MOVE_COST |
| 26963 |
#define TARGET_MEMORY_MOVE_COST ix86_memory_move_cost |
| 26964 |
#undef TARGET_RTX_COSTS |
| 26965 |
#define TARGET_RTX_COSTS ix86_rtx_costs |
| 26966 |
#undef TARGET_INSN_COST |
| 26967 |
#define TARGET_INSN_COST ix86_insn_cost |
| 26968 |
#undef TARGET_ADDRESS_COST |
| 26969 |
#define TARGET_ADDRESS_COST ix86_address_cost |
| 26970 |
|
| 26971 |
#undef TARGET_OVERLAP_OP_BY_PIECES_P |
| 26972 |
#define TARGET_OVERLAP_OP_BY_PIECES_P hook_bool_void_true |
| 26973 |
|
| 26974 |
#undef TARGET_FLAGS_REGNUM |
| 26975 |
#define TARGET_FLAGS_REGNUM FLAGS_REG |
| 26976 |
#undef TARGET_FIXED_CONDITION_CODE_REGS |
| 26977 |
#define TARGET_FIXED_CONDITION_CODE_REGS ix86_fixed_condition_code_regs |
| 26978 |
#undef TARGET_CC_MODES_COMPATIBLE |
| 26979 |
#define TARGET_CC_MODES_COMPATIBLE ix86_cc_modes_compatible |
| 26980 |
|
| 26981 |
#undef TARGET_MACHINE_DEPENDENT_REORG |
| 26982 |
#define TARGET_MACHINE_DEPENDENT_REORG ix86_reorg |
| 26983 |
|
| 26984 |
#undef TARGET_BUILD_BUILTIN_VA_LIST |
| 26985 |
#define TARGET_BUILD_BUILTIN_VA_LIST ix86_build_builtin_va_list |
| 26986 |
|
| 26987 |
#undef TARGET_FOLD_BUILTIN |
| 26988 |
#define TARGET_FOLD_BUILTIN ix86_fold_builtin |
| 26989 |
|
| 26990 |
#undef TARGET_GIMPLE_FOLD_BUILTIN |
| 26991 |
#define TARGET_GIMPLE_FOLD_BUILTIN ix86_gimple_fold_builtin |
| 26992 |
|
| 26993 |
#undef TARGET_COMPARE_VERSION_PRIORITY |
| 26994 |
#define TARGET_COMPARE_VERSION_PRIORITY ix86_compare_version_priority |
| 26995 |
|
| 26996 |
#undef TARGET_GENERATE_VERSION_DISPATCHER_BODY |
| 26997 |
#define TARGET_GENERATE_VERSION_DISPATCHER_BODY \ |
| 26998 |
ix86_generate_version_dispatcher_body |
| 26999 |
|
| 27000 |
#undef TARGET_GET_FUNCTION_VERSIONS_DISPATCHER |
| 27001 |
#define TARGET_GET_FUNCTION_VERSIONS_DISPATCHER \ |
| 27002 |
ix86_get_function_versions_dispatcher |
| 27003 |
|
| 27004 |
#undef TARGET_ENUM_VA_LIST_P |
| 27005 |
#define TARGET_ENUM_VA_LIST_P ix86_enum_va_list |
| 27006 |
|
| 27007 |
#undef TARGET_FN_ABI_VA_LIST |
| 27008 |
#define TARGET_FN_ABI_VA_LIST ix86_fn_abi_va_list |
| 27009 |
|
| 27010 |
#undef TARGET_CANONICAL_VA_LIST_TYPE |
| 27011 |
#define TARGET_CANONICAL_VA_LIST_TYPE ix86_canonical_va_list_type |
| 27012 |
|
| 27013 |
#undef TARGET_EXPAND_BUILTIN_VA_START |
| 27014 |
#define TARGET_EXPAND_BUILTIN_VA_START ix86_va_start |
| 27015 |
|
| 27016 |
#undef TARGET_MD_ASM_ADJUST |
| 27017 |
#define TARGET_MD_ASM_ADJUST ix86_md_asm_adjust |
| 27018 |
|
| 27019 |
#undef TARGET_C_EXCESS_PRECISION |
| 27020 |
#define TARGET_C_EXCESS_PRECISION ix86_get_excess_precision |
| 27021 |
#undef TARGET_C_BITINT_TYPE_INFO |
| 27022 |
#define TARGET_C_BITINT_TYPE_INFO ix86_bitint_type_info |
| 27023 |
#undef TARGET_C_MODE_FOR_FLOATING_TYPE |
| 27024 |
#define TARGET_C_MODE_FOR_FLOATING_TYPE ix86_c_mode_for_floating_type |
| 27025 |
#undef TARGET_CXX_ADJUST_CDTOR_CALLABI_FNTYPE |
| 27026 |
#define TARGET_CXX_ADJUST_CDTOR_CALLABI_FNTYPE ix86_cxx_adjust_cdtor_callabi_fntype |
| 27027 |
#undef TARGET_PROMOTE_PROTOTYPES |
| 27028 |
#define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true |
| 27029 |
#undef TARGET_PUSH_ARGUMENT |
| 27030 |
#define TARGET_PUSH_ARGUMENT ix86_push_argument |
| 27031 |
#undef TARGET_SETUP_INCOMING_VARARGS |
| 27032 |
#define TARGET_SETUP_INCOMING_VARARGS ix86_setup_incoming_varargs |
| 27033 |
#undef TARGET_MUST_PASS_IN_STACK |
| 27034 |
#define TARGET_MUST_PASS_IN_STACK ix86_must_pass_in_stack |
| 27035 |
#undef TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS |
| 27036 |
#define TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS ix86_allocate_stack_slots_for_args |
| 27037 |
#undef TARGET_FUNCTION_ARG_ADVANCE |
| 27038 |
#define TARGET_FUNCTION_ARG_ADVANCE ix86_function_arg_advance |
| 27039 |
#undef TARGET_FUNCTION_ARG |
| 27040 |
#define TARGET_FUNCTION_ARG ix86_function_arg |
| 27041 |
#undef TARGET_INIT_PIC_REG |
| 27042 |
#define TARGET_INIT_PIC_REG ix86_init_pic_reg |
| 27043 |
#undef TARGET_USE_PSEUDO_PIC_REG |
| 27044 |
#define TARGET_USE_PSEUDO_PIC_REG ix86_use_pseudo_pic_reg |
| 27045 |
#undef TARGET_FUNCTION_ARG_BOUNDARY |
| 27046 |
#define TARGET_FUNCTION_ARG_BOUNDARY ix86_function_arg_boundary |
| 27047 |
#undef TARGET_PASS_BY_REFERENCE |
| 27048 |
#define TARGET_PASS_BY_REFERENCE ix86_pass_by_reference |
| 27049 |
#undef TARGET_INTERNAL_ARG_POINTER |
| 27050 |
#define TARGET_INTERNAL_ARG_POINTER ix86_internal_arg_pointer |
| 27051 |
#undef TARGET_UPDATE_STACK_BOUNDARY |
| 27052 |
#define TARGET_UPDATE_STACK_BOUNDARY ix86_update_stack_boundary |
| 27053 |
#undef TARGET_GET_DRAP_RTX |
| 27054 |
#define TARGET_GET_DRAP_RTX ix86_get_drap_rtx |
| 27055 |
#undef TARGET_STRICT_ARGUMENT_NAMING |
| 27056 |
#define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true |
| 27057 |
#undef TARGET_STATIC_CHAIN |
| 27058 |
#define TARGET_STATIC_CHAIN ix86_static_chain |
| 27059 |
#undef TARGET_TRAMPOLINE_INIT |
| 27060 |
#define TARGET_TRAMPOLINE_INIT ix86_trampoline_init |
| 27061 |
#undef TARGET_RETURN_POPS_ARGS |
| 27062 |
#define TARGET_RETURN_POPS_ARGS ix86_return_pops_args |
| 27063 |
|
| 27064 |
#undef TARGET_WARN_FUNC_RETURN |
| 27065 |
#define TARGET_WARN_FUNC_RETURN ix86_warn_func_return |
| 27066 |
|
| 27067 |
#undef TARGET_LEGITIMATE_COMBINED_INSN |
| 27068 |
#define TARGET_LEGITIMATE_COMBINED_INSN ix86_legitimate_combined_insn |
| 27069 |
|
| 27070 |
#undef TARGET_ASAN_SHADOW_OFFSET |
| 27071 |
#define TARGET_ASAN_SHADOW_OFFSET ix86_asan_shadow_offset |
| 27072 |
|
| 27073 |
#undef TARGET_GIMPLIFY_VA_ARG_EXPR |
| 27074 |
#define TARGET_GIMPLIFY_VA_ARG_EXPR ix86_gimplify_va_arg |
| 27075 |
|
| 27076 |
#undef TARGET_SCALAR_MODE_SUPPORTED_P |
| 27077 |
#define TARGET_SCALAR_MODE_SUPPORTED_P ix86_scalar_mode_supported_p |
| 27078 |
|
| 27079 |
#undef TARGET_LIBGCC_FLOATING_MODE_SUPPORTED_P |
| 27080 |
#define TARGET_LIBGCC_FLOATING_MODE_SUPPORTED_P \ |
| 27081 |
ix86_libgcc_floating_mode_supported_p |
| 27082 |
|
| 27083 |
#undef TARGET_VECTOR_MODE_SUPPORTED_P |
| 27084 |
#define TARGET_VECTOR_MODE_SUPPORTED_P ix86_vector_mode_supported_p |
| 27085 |
|
| 27086 |
#undef TARGET_C_MODE_FOR_SUFFIX |
| 27087 |
#define TARGET_C_MODE_FOR_SUFFIX ix86_c_mode_for_suffix |
| 27088 |
|
| 27089 |
#ifdef HAVE_AS_TLS |
| 27090 |
#undef TARGET_ASM_OUTPUT_DWARF_DTPREL |
| 27091 |
#define TARGET_ASM_OUTPUT_DWARF_DTPREL i386_output_dwarf_dtprel |
| 27092 |
#endif |
| 27093 |
|
| 27094 |
#ifdef SUBTARGET_INSERT_ATTRIBUTES |
| 27095 |
#undef TARGET_INSERT_ATTRIBUTES |
| 27096 |
#define TARGET_INSERT_ATTRIBUTES SUBTARGET_INSERT_ATTRIBUTES |
| 27097 |
#endif |
| 27098 |
|
| 27099 |
#undef TARGET_MANGLE_TYPE |
| 27100 |
#define TARGET_MANGLE_TYPE ix86_mangle_type |
| 27101 |
|
| 27102 |
#undef TARGET_EMIT_SUPPORT_TINFOS |
| 27103 |
#define TARGET_EMIT_SUPPORT_TINFOS ix86_emit_support_tinfos |
| 27104 |
|
| 27105 |
#undef TARGET_STACK_PROTECT_GUARD |
| 27106 |
#define TARGET_STACK_PROTECT_GUARD ix86_stack_protect_guard |
| 27107 |
|
| 27108 |
#undef TARGET_STACK_PROTECT_RUNTIME_ENABLED_P |
| 27109 |
#define TARGET_STACK_PROTECT_RUNTIME_ENABLED_P \ |
| 27110 |
ix86_stack_protect_runtime_enabled_p |
| 27111 |
|
| 27112 |
#if !TARGET_MACHO |
| 27113 |
#undef TARGET_STACK_PROTECT_FAIL |
| 27114 |
#define TARGET_STACK_PROTECT_FAIL ix86_stack_protect_fail |
| 27115 |
#endif |
| 27116 |
|
| 27117 |
#undef TARGET_FUNCTION_VALUE |
| 27118 |
#define TARGET_FUNCTION_VALUE ix86_function_value |
| 27119 |
|
| 27120 |
#undef TARGET_FUNCTION_VALUE_REGNO_P |
| 27121 |
#define TARGET_FUNCTION_VALUE_REGNO_P ix86_function_value_regno_p |
| 27122 |
|
| 27123 |
#undef TARGET_ZERO_CALL_USED_REGS |
| 27124 |
#define TARGET_ZERO_CALL_USED_REGS ix86_zero_call_used_regs |
| 27125 |
|
| 27126 |
#undef TARGET_PROMOTE_FUNCTION_MODE |
| 27127 |
#define TARGET_PROMOTE_FUNCTION_MODE ix86_promote_function_mode |
| 27128 |
|
| 27129 |
#undef TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE |
| 27130 |
#define TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE ix86_override_options_after_change |
| 27131 |
|
| 27132 |
#undef TARGET_MEMBER_TYPE_FORCES_BLK |
| 27133 |
#define TARGET_MEMBER_TYPE_FORCES_BLK ix86_member_type_forces_blk |
| 27134 |
|
| 27135 |
#undef TARGET_INSTANTIATE_DECLS |
| 27136 |
#define TARGET_INSTANTIATE_DECLS ix86_instantiate_decls |
| 27137 |
|
| 27138 |
#undef TARGET_SECONDARY_RELOAD |
| 27139 |
#define TARGET_SECONDARY_RELOAD ix86_secondary_reload |
| 27140 |
#undef TARGET_SECONDARY_MEMORY_NEEDED |
| 27141 |
#define TARGET_SECONDARY_MEMORY_NEEDED ix86_secondary_memory_needed |
| 27142 |
#undef TARGET_SECONDARY_MEMORY_NEEDED_MODE |
| 27143 |
#define TARGET_SECONDARY_MEMORY_NEEDED_MODE ix86_secondary_memory_needed_mode |
| 27144 |
|
| 27145 |
#undef TARGET_CLASS_MAX_NREGS |
| 27146 |
#define TARGET_CLASS_MAX_NREGS ix86_class_max_nregs |
| 27147 |
|
| 27148 |
#undef TARGET_PREFERRED_RELOAD_CLASS |
| 27149 |
#define TARGET_PREFERRED_RELOAD_CLASS ix86_preferred_reload_class |
| 27150 |
#undef TARGET_PREFERRED_OUTPUT_RELOAD_CLASS |
| 27151 |
#define TARGET_PREFERRED_OUTPUT_RELOAD_CLASS ix86_preferred_output_reload_class |
| 27152 |
/* When this hook returns true for MODE, the compiler allows |
| 27153 |
registers explicitly used in the rtl to be used as spill registers |
| 27154 |
but prevents the compiler from extending the lifetime of these |
| 27155 |
registers. */ |
| 27156 |
#undef TARGET_SMALL_REGISTER_CLASSES_FOR_MODE_P |
| 27157 |
#define TARGET_SMALL_REGISTER_CLASSES_FOR_MODE_P hook_bool_mode_true |
| 27158 |
#undef TARGET_CLASS_LIKELY_SPILLED_P |
| 27159 |
#define TARGET_CLASS_LIKELY_SPILLED_P ix86_class_likely_spilled_p |
| 27160 |
#undef TARGET_CALLEE_SAVE_COST |
| 27161 |
#define TARGET_CALLEE_SAVE_COST ix86_callee_save_cost |
| 27162 |
|
| 27163 |
#undef TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST |
| 27164 |
#define TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST \ |
| 27165 |
ix86_builtin_vectorization_cost |
| 27166 |
#undef TARGET_VECTORIZE_VEC_PERM_CONST |
| 27167 |
#define TARGET_VECTORIZE_VEC_PERM_CONST ix86_vectorize_vec_perm_const |
| 27168 |
#undef TARGET_VECTORIZE_PREFERRED_SIMD_MODE |
| 27169 |
#define TARGET_VECTORIZE_PREFERRED_SIMD_MODE \ |
| 27170 |
ix86_preferred_simd_mode |
| 27171 |
#undef TARGET_VECTORIZE_SPLIT_REDUCTION |
| 27172 |
#define TARGET_VECTORIZE_SPLIT_REDUCTION \ |
| 27173 |
ix86_split_reduction |
| 27174 |
#undef TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_MODES |
| 27175 |
#define TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_MODES \ |
| 27176 |
ix86_autovectorize_vector_modes |
| 27177 |
#undef TARGET_VECTORIZE_GET_MASK_MODE |
| 27178 |
#define TARGET_VECTORIZE_GET_MASK_MODE ix86_get_mask_mode |
| 27179 |
#undef TARGET_VECTORIZE_CREATE_COSTS |
| 27180 |
#define TARGET_VECTORIZE_CREATE_COSTS ix86_vectorize_create_costs |
| 27181 |
|
| 27182 |
#undef TARGET_SET_CURRENT_FUNCTION |
| 27183 |
#define TARGET_SET_CURRENT_FUNCTION ix86_set_current_function |
| 27184 |
|
| 27185 |
#undef TARGET_OPTION_VALID_ATTRIBUTE_P |
| 27186 |
#define TARGET_OPTION_VALID_ATTRIBUTE_P ix86_valid_target_attribute_p |
| 27187 |
|
| 27188 |
#undef TARGET_OPTION_SAVE |
| 27189 |
#define TARGET_OPTION_SAVE ix86_function_specific_save |
| 27190 |
|
| 27191 |
#undef TARGET_OPTION_RESTORE |
| 27192 |
#define TARGET_OPTION_RESTORE ix86_function_specific_restore |
| 27193 |
|
| 27194 |
#undef TARGET_OPTION_POST_STREAM_IN |
| 27195 |
#define TARGET_OPTION_POST_STREAM_IN ix86_function_specific_post_stream_in |
| 27196 |
|
| 27197 |
#undef TARGET_OPTION_PRINT |
| 27198 |
#define TARGET_OPTION_PRINT ix86_function_specific_print |
| 27199 |
|
| 27200 |
#undef TARGET_OPTION_FUNCTION_VERSIONS |
| 27201 |
#define TARGET_OPTION_FUNCTION_VERSIONS common_function_versions |
| 27202 |
|
| 27203 |
#undef TARGET_CAN_INLINE_P |
| 27204 |
#define TARGET_CAN_INLINE_P ix86_can_inline_p |
| 27205 |
|
| 27206 |
#undef TARGET_LEGITIMATE_ADDRESS_P |
| 27207 |
#define TARGET_LEGITIMATE_ADDRESS_P ix86_legitimate_address_p |
| 27208 |
|
| 27209 |
#undef TARGET_REGISTER_PRIORITY |
| 27210 |
#define TARGET_REGISTER_PRIORITY ix86_register_priority |
| 27211 |
|
| 27212 |
#undef TARGET_REGISTER_USAGE_LEVELING_P |
| 27213 |
#define TARGET_REGISTER_USAGE_LEVELING_P hook_bool_void_true |
| 27214 |
|
| 27215 |
#undef TARGET_LEGITIMATE_CONSTANT_P |
| 27216 |
#define TARGET_LEGITIMATE_CONSTANT_P ix86_legitimate_constant_p |
| 27217 |
|
| 27218 |
#undef TARGET_COMPUTE_FRAME_LAYOUT |
| 27219 |
#define TARGET_COMPUTE_FRAME_LAYOUT ix86_compute_frame_layout |
| 27220 |
|
| 27221 |
#undef TARGET_FRAME_POINTER_REQUIRED |
| 27222 |
#define TARGET_FRAME_POINTER_REQUIRED ix86_frame_pointer_required |
| 27223 |
|
| 27224 |
#undef TARGET_CAN_ELIMINATE |
| 27225 |
#define TARGET_CAN_ELIMINATE ix86_can_eliminate |
| 27226 |
|
| 27227 |
#undef TARGET_EXTRA_LIVE_ON_ENTRY |
| 27228 |
#define TARGET_EXTRA_LIVE_ON_ENTRY ix86_live_on_entry |
| 27229 |
|
| 27230 |
#undef TARGET_ASM_CODE_END |
| 27231 |
#define TARGET_ASM_CODE_END ix86_code_end |
| 27232 |
|
| 27233 |
#undef TARGET_CONDITIONAL_REGISTER_USAGE |
| 27234 |
#define TARGET_CONDITIONAL_REGISTER_USAGE ix86_conditional_register_usage |
| 27235 |
|
| 27236 |
#undef TARGET_CANONICALIZE_COMPARISON |
| 27237 |
#define TARGET_CANONICALIZE_COMPARISON ix86_canonicalize_comparison |
| 27238 |
|
| 27239 |
#undef TARGET_LOOP_UNROLL_ADJUST |
| 27240 |
#define TARGET_LOOP_UNROLL_ADJUST ix86_loop_unroll_adjust |
| 27241 |
|
| 27242 |
/* Disabled due to PRs 70902, 71453, 71555, 71596 and 71657. */ |
| 27243 |
#undef TARGET_SPILL_CLASS |
| 27244 |
#define TARGET_SPILL_CLASS ix86_spill_class |
| 27245 |
|
| 27246 |
#undef TARGET_SIMD_CLONE_COMPUTE_VECSIZE_AND_SIMDLEN |
| 27247 |
#define TARGET_SIMD_CLONE_COMPUTE_VECSIZE_AND_SIMDLEN \ |
| 27248 |
ix86_simd_clone_compute_vecsize_and_simdlen |
| 27249 |
|
| 27250 |
#undef TARGET_SIMD_CLONE_ADJUST |
| 27251 |
#define TARGET_SIMD_CLONE_ADJUST ix86_simd_clone_adjust |
| 27252 |
|
| 27253 |
#undef TARGET_SIMD_CLONE_USABLE |
| 27254 |
#define TARGET_SIMD_CLONE_USABLE ix86_simd_clone_usable |
| 27255 |
|
| 27256 |
#undef TARGET_OMP_DEVICE_KIND_ARCH_ISA |
| 27257 |
#define TARGET_OMP_DEVICE_KIND_ARCH_ISA ix86_omp_device_kind_arch_isa |
| 27258 |
|
| 27259 |
#undef TARGET_FLOAT_EXCEPTIONS_ROUNDING_SUPPORTED_P |
| 27260 |
#define TARGET_FLOAT_EXCEPTIONS_ROUNDING_SUPPORTED_P \ |
| 27261 |
ix86_float_exceptions_rounding_supported_p |
| 27262 |
|
| 27263 |
#undef TARGET_MODE_EMIT |
| 27264 |
#define TARGET_MODE_EMIT ix86_emit_mode_set |
| 27265 |
|
| 27266 |
#undef TARGET_MODE_NEEDED |
| 27267 |
#define TARGET_MODE_NEEDED ix86_mode_needed |
| 27268 |
|
| 27269 |
#undef TARGET_MODE_AFTER |
| 27270 |
#define TARGET_MODE_AFTER ix86_mode_after |
| 27271 |
|
| 27272 |
#undef TARGET_MODE_ENTRY |
| 27273 |
#define TARGET_MODE_ENTRY ix86_mode_entry |
| 27274 |
|
| 27275 |
#undef TARGET_MODE_EXIT |
| 27276 |
#define TARGET_MODE_EXIT ix86_mode_exit |
| 27277 |
|
| 27278 |
#undef TARGET_MODE_PRIORITY |
| 27279 |
#define TARGET_MODE_PRIORITY ix86_mode_priority |
| 27280 |
|
| 27281 |
#undef TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS |
| 27282 |
#define TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS true |
| 27283 |
|
| 27284 |
#undef TARGET_OFFLOAD_OPTIONS |
| 27285 |
#define TARGET_OFFLOAD_OPTIONS \ |
| 27286 |
ix86_offload_options |
| 27287 |
|
| 27288 |
#undef TARGET_ABSOLUTE_BIGGEST_ALIGNMENT |
| 27289 |
#define TARGET_ABSOLUTE_BIGGEST_ALIGNMENT 512 |
| 27290 |
|
| 27291 |
#undef TARGET_OPTAB_SUPPORTED_P |
| 27292 |
#define TARGET_OPTAB_SUPPORTED_P ix86_optab_supported_p |
| 27293 |
|
| 27294 |
#undef TARGET_HARD_REGNO_SCRATCH_OK |
| 27295 |
#define TARGET_HARD_REGNO_SCRATCH_OK ix86_hard_regno_scratch_ok |
| 27296 |
|
| 27297 |
#undef TARGET_CUSTOM_FUNCTION_DESCRIPTORS |
| 27298 |
#define TARGET_CUSTOM_FUNCTION_DESCRIPTORS X86_CUSTOM_FUNCTION_TEST |
| 27299 |
|
| 27300 |
#undef TARGET_ADDR_SPACE_ZERO_ADDRESS_VALID |
| 27301 |
#define TARGET_ADDR_SPACE_ZERO_ADDRESS_VALID ix86_addr_space_zero_address_valid |
| 27302 |
|
| 27303 |
#undef TARGET_INIT_LIBFUNCS |
| 27304 |
#define TARGET_INIT_LIBFUNCS ix86_init_libfuncs |
| 27305 |
|
| 27306 |
#undef TARGET_EXPAND_DIVMOD_LIBFUNC |
| 27307 |
#define TARGET_EXPAND_DIVMOD_LIBFUNC ix86_expand_divmod_libfunc |
| 27308 |
|
| 27309 |
#undef TARGET_MAX_NOCE_IFCVT_SEQ_COST |
| 27310 |
#define TARGET_MAX_NOCE_IFCVT_SEQ_COST ix86_max_noce_ifcvt_seq_cost |
| 27311 |
|
| 27312 |
#undef TARGET_NOCE_CONVERSION_PROFITABLE_P |
| 27313 |
#define TARGET_NOCE_CONVERSION_PROFITABLE_P ix86_noce_conversion_profitable_p |
| 27314 |
|
| 27315 |
#undef TARGET_HARD_REGNO_NREGS |
| 27316 |
#define TARGET_HARD_REGNO_NREGS ix86_hard_regno_nregs |
| 27317 |
#undef TARGET_HARD_REGNO_MODE_OK |
| 27318 |
#define TARGET_HARD_REGNO_MODE_OK ix86_hard_regno_mode_ok |
| 27319 |
|
| 27320 |
#undef TARGET_MODES_TIEABLE_P |
| 27321 |
#define TARGET_MODES_TIEABLE_P ix86_modes_tieable_p |
| 27322 |
|
| 27323 |
#undef TARGET_HARD_REGNO_CALL_PART_CLOBBERED |
| 27324 |
#define TARGET_HARD_REGNO_CALL_PART_CLOBBERED \ |
| 27325 |
ix86_hard_regno_call_part_clobbered |
| 27326 |
|
| 27327 |
#undef TARGET_INSN_CALLEE_ABI |
| 27328 |
#define TARGET_INSN_CALLEE_ABI ix86_insn_callee_abi |
| 27329 |
|
| 27330 |
#undef TARGET_CAN_CHANGE_MODE_CLASS |
| 27331 |
#define TARGET_CAN_CHANGE_MODE_CLASS ix86_can_change_mode_class |
| 27332 |
|
| 27333 |
#undef TARGET_LOWER_LOCAL_DECL_ALIGNMENT |
| 27334 |
#define TARGET_LOWER_LOCAL_DECL_ALIGNMENT ix86_lower_local_decl_alignment |
| 27335 |
|
| 27336 |
#undef TARGET_STATIC_RTX_ALIGNMENT |
| 27337 |
#define TARGET_STATIC_RTX_ALIGNMENT ix86_static_rtx_alignment |
| 27338 |
#undef TARGET_CONSTANT_ALIGNMENT |
| 27339 |
#define TARGET_CONSTANT_ALIGNMENT ix86_constant_alignment |
| 27340 |
|
| 27341 |
#undef TARGET_EMPTY_RECORD_P |
| 27342 |
#define TARGET_EMPTY_RECORD_P ix86_is_empty_record |
| 27343 |
|
| 27344 |
#undef TARGET_WARN_PARAMETER_PASSING_ABI |
| 27345 |
#define TARGET_WARN_PARAMETER_PASSING_ABI ix86_warn_parameter_passing_abi |
| 27346 |
|
| 27347 |
#undef TARGET_GET_MULTILIB_ABI_NAME |
| 27348 |
#define TARGET_GET_MULTILIB_ABI_NAME \ |
| 27349 |
ix86_get_multilib_abi_name |
| 27350 |
|
| 27351 |
#undef TARGET_IFUNC_REF_LOCAL_OK |
| 27352 |
#define TARGET_IFUNC_REF_LOCAL_OK ix86_ifunc_ref_local_ok |
| 27353 |
|
| 27354 |
#if !TARGET_MACHO && !TARGET_DLLIMPORT_DECL_ATTRIBUTES |
| 27355 |
# undef TARGET_ASM_RELOC_RW_MASK |
| 27356 |
# define TARGET_ASM_RELOC_RW_MASK ix86_reloc_rw_mask |
| 27357 |
#endif |
| 27358 |
|
| 27359 |
#undef TARGET_MEMTAG_CAN_TAG_ADDRESSES |
| 27360 |
#define TARGET_MEMTAG_CAN_TAG_ADDRESSES ix86_memtag_can_tag_addresses |
| 27361 |
|
| 27362 |
#undef TARGET_MEMTAG_ADD_TAG |
| 27363 |
#define TARGET_MEMTAG_ADD_TAG ix86_memtag_add_tag |
| 27364 |
|
| 27365 |
#undef TARGET_MEMTAG_SET_TAG |
| 27366 |
#define TARGET_MEMTAG_SET_TAG ix86_memtag_set_tag |
| 27367 |
|
| 27368 |
#undef TARGET_MEMTAG_EXTRACT_TAG |
| 27369 |
#define TARGET_MEMTAG_EXTRACT_TAG ix86_memtag_extract_tag |
| 27370 |
|
| 27371 |
#undef TARGET_MEMTAG_UNTAGGED_POINTER |
| 27372 |
#define TARGET_MEMTAG_UNTAGGED_POINTER ix86_memtag_untagged_pointer |
| 27373 |
|
| 27374 |
#undef TARGET_MEMTAG_TAG_SIZE |
| 27375 |
#define TARGET_MEMTAG_TAG_SIZE ix86_memtag_tag_size |
| 27376 |
|
| 27377 |
#undef TARGET_GEN_CCMP_FIRST |
| 27378 |
#define TARGET_GEN_CCMP_FIRST ix86_gen_ccmp_first |
| 27379 |
|
| 27380 |
#undef TARGET_GEN_CCMP_NEXT |
| 27381 |
#define TARGET_GEN_CCMP_NEXT ix86_gen_ccmp_next |
| 27382 |
|
| 27383 |
#undef TARGET_HAVE_CCMP |
| 27384 |
#define TARGET_HAVE_CCMP ix86_have_ccmp |
| 27385 |
|
| 27386 |
#undef TARGET_MODE_CAN_TRANSFER_BITS |
| 27387 |
#define TARGET_MODE_CAN_TRANSFER_BITS ix86_mode_can_transfer_bits |
| 27388 |
|
| 27389 |
#undef TARGET_REDZONE_CLOBBER |
| 27390 |
#define TARGET_REDZONE_CLOBBER ix86_redzone_clobber |
| 27391 |
|
| 27392 |
static bool |
| 27393 |
ix86_libc_has_fast_function (int fcode ATTRIBUTE_UNUSED) |
| 27394 |
{ |
| 27395 |
#ifdef OPTION_GLIBC |
| 27396 |
if (OPTION_GLIBC) |
| 27397 |
return (built_in_function)fcode == BUILT_IN_MEMPCPY; |
| 27398 |
else |
| 27399 |
return false; |
| 27400 |
#else |
| 27401 |
return false; |
| 27402 |
#endif |
| 27403 |
} |
| 27404 |
|
| 27405 |
#undef TARGET_LIBC_HAS_FAST_FUNCTION |
| 27406 |
#define TARGET_LIBC_HAS_FAST_FUNCTION ix86_libc_has_fast_function |
| 27407 |
|
| 27408 |
static unsigned |
| 27409 |
ix86_libm_function_max_error (unsigned cfn, machine_mode mode, |
| 27410 |
bool boundary_p) |
| 27411 |
{ |
| 27412 |
#ifdef OPTION_GLIBC |
| 27413 |
bool glibc_p = OPTION_GLIBC; |
| 27414 |
#else |
| 27415 |
bool glibc_p = false; |
| 27416 |
#endif |
| 27417 |
if (glibc_p) |
| 27418 |
{ |
| 27419 |
/* If __FAST_MATH__ is defined, glibc provides libmvec. */ |
| 27420 |
unsigned int libmvec_ret = 0; |
| 27421 |
if (!flag_trapping_math |
| 27422 |
&& flag_unsafe_math_optimizations |
| 27423 |
&& flag_finite_math_only |
| 27424 |
&& !flag_signed_zeros |
| 27425 |
&& !flag_errno_math) |
| 27426 |
switch (cfn) |
| 27427 |
{ |
| 27428 |
CASE_CFN_COS: |
| 27429 |
CASE_CFN_COS_FN: |
| 27430 |
CASE_CFN_SIN: |
| 27431 |
CASE_CFN_SIN_FN: |
| 27432 |
if (!boundary_p) |
| 27433 |
{ |
| 27434 |
/* With non-default rounding modes, libmvec provides |
| 27435 |
complete garbage in results. E.g. |
| 27436 |
_ZGVcN8v_sinf for 1.40129846e-45f in FE_UPWARD |
| 27437 |
returns 0.00333309174f rather than 1.40129846e-45f. */ |
| 27438 |
if (flag_rounding_math) |
| 27439 |
return ~0U; |
| 27440 |
/* https://www.gnu.org/software/libc/manual/html_node/Errors-in-Math-Functions.html |
| 27441 |
claims libmvec maximum error is 4ulps. |
| 27442 |
My own random testing indicates 2ulps for SFmode and |
| 27443 |
0.5ulps for DFmode, but let's go with the 4ulps. */ |
| 27444 |
libmvec_ret = 4; |
| 27445 |
} |
| 27446 |
break; |
| 27447 |
default: |
| 27448 |
break; |
| 27449 |
} |
| 27450 |
unsigned int ret = glibc_linux_libm_function_max_error (cfn, mode, |
| 27451 |
boundary_p); |
| 27452 |
return MAX (ret, libmvec_ret); |
| 27453 |
} |
| 27454 |
return default_libm_function_max_error (cfn, mode, boundary_p); |
| 27455 |
} |
| 27456 |
|
| 27457 |
#undef TARGET_LIBM_FUNCTION_MAX_ERROR |
| 27458 |
#define TARGET_LIBM_FUNCTION_MAX_ERROR ix86_libm_function_max_error |
| 27459 |
|
| 27460 |
#if TARGET_MACHO |
| 27461 |
static bool |
| 27462 |
ix86_cannot_copy_insn_p (rtx_insn *insn) |
| 27463 |
{ |
| 27464 |
if (TARGET_64BIT) |
| 27465 |
return false; |
| 27466 |
|
| 27467 |
rtx set = single_set (insn); |
| 27468 |
if (set) |
| 27469 |
{ |
| 27470 |
rtx src = SET_SRC (set); |
| 27471 |
if (GET_CODE (src) == UNSPEC |
| 27472 |
&& XINT (src, 1) == UNSPEC_SET_GOT) |
| 27473 |
return true; |
| 27474 |
} |
| 27475 |
return false; |
| 27476 |
} |
| 27477 |
|
| 27478 |
#undef TARGET_CANNOT_COPY_INSN_P |
| 27479 |
#define TARGET_CANNOT_COPY_INSN_P ix86_cannot_copy_insn_p |
| 27480 |
|
| 27481 |
#endif |
| 27482 |
|
| 27483 |
#if CHECKING_P |
| 27484 |
#undef TARGET_RUN_TARGET_SELFTESTS |
| 27485 |
#define TARGET_RUN_TARGET_SELFTESTS selftest::ix86_run_selftests |
| 27486 |
#endif /* #if CHECKING_P */ |
| 27487 |
|
| 27488 |
#undef TARGET_DOCUMENTATION_NAME |
| 27489 |
#define TARGET_DOCUMENTATION_NAME "x86" |
| 27490 |
|
| 27491 |
struct gcc_target targetm = TARGET_INITIALIZER; |
| 27492 |
|
| 27493 |
#include "gt-i386.h" |