1 /* Subroutines used for code generation on IBM S/390 and zSeries
2 Copyright (C) 1999-2016 Free Software Foundation, Inc.
3 Contributed by Hartmut Penner (hpenner@de.ibm.com) and
4 Ulrich Weigand (uweigand@de.ibm.com) and
5 Andreas Krebbel (Andreas.Krebbel@de.ibm.com).
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
25 #include "coretypes.h"
28 #include "target-globals.h"
36 #include "stringpool.h"
43 #include "diagnostic-core.h"
44 #include "diagnostic.h"
46 #include "fold-const.h"
47 #include "print-tree.h"
48 #include "stor-layout.h"
51 #include "conditions.h"
53 #include "insn-attr.h"
65 #include "cfgcleanup.h"
67 #include "langhooks.h"
68 #include "internal-fn.h"
69 #include "gimple-fold.h"
74 #include "tree-pass.h"
79 #include "tm-constrs.h"
81 /* This file should be included last. */
82 #include "target-def.h"
84 /* Remember the last target of s390_set_current_function. */
85 static GTY(()) tree s390_previous_fndecl
;
87 /* Define the specific costs for a given cpu. */
89 struct processor_costs
92 const int m
; /* cost of an M instruction. */
93 const int mghi
; /* cost of an MGHI instruction. */
94 const int mh
; /* cost of an MH instruction. */
95 const int mhi
; /* cost of an MHI instruction. */
96 const int ml
; /* cost of an ML instruction. */
97 const int mr
; /* cost of an MR instruction. */
98 const int ms
; /* cost of an MS instruction. */
99 const int msg
; /* cost of an MSG instruction. */
100 const int msgf
; /* cost of an MSGF instruction. */
101 const int msgfr
; /* cost of an MSGFR instruction. */
102 const int msgr
; /* cost of an MSGR instruction. */
103 const int msr
; /* cost of an MSR instruction. */
104 const int mult_df
; /* cost of multiplication in DFmode. */
107 const int sqxbr
; /* cost of square root in TFmode. */
108 const int sqdbr
; /* cost of square root in DFmode. */
109 const int sqebr
; /* cost of square root in SFmode. */
110 /* multiply and add */
111 const int madbr
; /* cost of multiply and add in DFmode. */
112 const int maebr
; /* cost of multiply and add in SFmode. */
124 #define s390_cost ((const struct processor_costs *)(s390_cost_pointer))
127 struct processor_costs z900_cost
=
129 COSTS_N_INSNS (5), /* M */
130 COSTS_N_INSNS (10), /* MGHI */
131 COSTS_N_INSNS (5), /* MH */
132 COSTS_N_INSNS (4), /* MHI */
133 COSTS_N_INSNS (5), /* ML */
134 COSTS_N_INSNS (5), /* MR */
135 COSTS_N_INSNS (4), /* MS */
136 COSTS_N_INSNS (15), /* MSG */
137 COSTS_N_INSNS (7), /* MSGF */
138 COSTS_N_INSNS (7), /* MSGFR */
139 COSTS_N_INSNS (10), /* MSGR */
140 COSTS_N_INSNS (4), /* MSR */
141 COSTS_N_INSNS (7), /* multiplication in DFmode */
142 COSTS_N_INSNS (13), /* MXBR */
143 COSTS_N_INSNS (136), /* SQXBR */
144 COSTS_N_INSNS (44), /* SQDBR */
145 COSTS_N_INSNS (35), /* SQEBR */
146 COSTS_N_INSNS (18), /* MADBR */
147 COSTS_N_INSNS (13), /* MAEBR */
148 COSTS_N_INSNS (134), /* DXBR */
149 COSTS_N_INSNS (30), /* DDBR */
150 COSTS_N_INSNS (27), /* DEBR */
151 COSTS_N_INSNS (220), /* DLGR */
152 COSTS_N_INSNS (34), /* DLR */
153 COSTS_N_INSNS (34), /* DR */
154 COSTS_N_INSNS (32), /* DSGFR */
155 COSTS_N_INSNS (32), /* DSGR */
159 struct processor_costs z990_cost
=
161 COSTS_N_INSNS (4), /* M */
162 COSTS_N_INSNS (2), /* MGHI */
163 COSTS_N_INSNS (2), /* MH */
164 COSTS_N_INSNS (2), /* MHI */
165 COSTS_N_INSNS (4), /* ML */
166 COSTS_N_INSNS (4), /* MR */
167 COSTS_N_INSNS (5), /* MS */
168 COSTS_N_INSNS (6), /* MSG */
169 COSTS_N_INSNS (4), /* MSGF */
170 COSTS_N_INSNS (4), /* MSGFR */
171 COSTS_N_INSNS (4), /* MSGR */
172 COSTS_N_INSNS (4), /* MSR */
173 COSTS_N_INSNS (1), /* multiplication in DFmode */
174 COSTS_N_INSNS (28), /* MXBR */
175 COSTS_N_INSNS (130), /* SQXBR */
176 COSTS_N_INSNS (66), /* SQDBR */
177 COSTS_N_INSNS (38), /* SQEBR */
178 COSTS_N_INSNS (1), /* MADBR */
179 COSTS_N_INSNS (1), /* MAEBR */
180 COSTS_N_INSNS (60), /* DXBR */
181 COSTS_N_INSNS (40), /* DDBR */
182 COSTS_N_INSNS (26), /* DEBR */
183 COSTS_N_INSNS (176), /* DLGR */
184 COSTS_N_INSNS (31), /* DLR */
185 COSTS_N_INSNS (31), /* DR */
186 COSTS_N_INSNS (31), /* DSGFR */
187 COSTS_N_INSNS (31), /* DSGR */
191 struct processor_costs z9_109_cost
=
193 COSTS_N_INSNS (4), /* M */
194 COSTS_N_INSNS (2), /* MGHI */
195 COSTS_N_INSNS (2), /* MH */
196 COSTS_N_INSNS (2), /* MHI */
197 COSTS_N_INSNS (4), /* ML */
198 COSTS_N_INSNS (4), /* MR */
199 COSTS_N_INSNS (5), /* MS */
200 COSTS_N_INSNS (6), /* MSG */
201 COSTS_N_INSNS (4), /* MSGF */
202 COSTS_N_INSNS (4), /* MSGFR */
203 COSTS_N_INSNS (4), /* MSGR */
204 COSTS_N_INSNS (4), /* MSR */
205 COSTS_N_INSNS (1), /* multiplication in DFmode */
206 COSTS_N_INSNS (28), /* MXBR */
207 COSTS_N_INSNS (130), /* SQXBR */
208 COSTS_N_INSNS (66), /* SQDBR */
209 COSTS_N_INSNS (38), /* SQEBR */
210 COSTS_N_INSNS (1), /* MADBR */
211 COSTS_N_INSNS (1), /* MAEBR */
212 COSTS_N_INSNS (60), /* DXBR */
213 COSTS_N_INSNS (40), /* DDBR */
214 COSTS_N_INSNS (26), /* DEBR */
215 COSTS_N_INSNS (30), /* DLGR */
216 COSTS_N_INSNS (23), /* DLR */
217 COSTS_N_INSNS (23), /* DR */
218 COSTS_N_INSNS (24), /* DSGFR */
219 COSTS_N_INSNS (24), /* DSGR */
223 struct processor_costs z10_cost
=
225 COSTS_N_INSNS (10), /* M */
226 COSTS_N_INSNS (10), /* MGHI */
227 COSTS_N_INSNS (10), /* MH */
228 COSTS_N_INSNS (10), /* MHI */
229 COSTS_N_INSNS (10), /* ML */
230 COSTS_N_INSNS (10), /* MR */
231 COSTS_N_INSNS (10), /* MS */
232 COSTS_N_INSNS (10), /* MSG */
233 COSTS_N_INSNS (10), /* MSGF */
234 COSTS_N_INSNS (10), /* MSGFR */
235 COSTS_N_INSNS (10), /* MSGR */
236 COSTS_N_INSNS (10), /* MSR */
237 COSTS_N_INSNS (1) , /* multiplication in DFmode */
238 COSTS_N_INSNS (50), /* MXBR */
239 COSTS_N_INSNS (120), /* SQXBR */
240 COSTS_N_INSNS (52), /* SQDBR */
241 COSTS_N_INSNS (38), /* SQEBR */
242 COSTS_N_INSNS (1), /* MADBR */
243 COSTS_N_INSNS (1), /* MAEBR */
244 COSTS_N_INSNS (111), /* DXBR */
245 COSTS_N_INSNS (39), /* DDBR */
246 COSTS_N_INSNS (32), /* DEBR */
247 COSTS_N_INSNS (160), /* DLGR */
248 COSTS_N_INSNS (71), /* DLR */
249 COSTS_N_INSNS (71), /* DR */
250 COSTS_N_INSNS (71), /* DSGFR */
251 COSTS_N_INSNS (71), /* DSGR */
255 struct processor_costs z196_cost
=
257 COSTS_N_INSNS (7), /* M */
258 COSTS_N_INSNS (5), /* MGHI */
259 COSTS_N_INSNS (5), /* MH */
260 COSTS_N_INSNS (5), /* MHI */
261 COSTS_N_INSNS (7), /* ML */
262 COSTS_N_INSNS (7), /* MR */
263 COSTS_N_INSNS (6), /* MS */
264 COSTS_N_INSNS (8), /* MSG */
265 COSTS_N_INSNS (6), /* MSGF */
266 COSTS_N_INSNS (6), /* MSGFR */
267 COSTS_N_INSNS (8), /* MSGR */
268 COSTS_N_INSNS (6), /* MSR */
269 COSTS_N_INSNS (1) , /* multiplication in DFmode */
270 COSTS_N_INSNS (40), /* MXBR B+40 */
271 COSTS_N_INSNS (100), /* SQXBR B+100 */
272 COSTS_N_INSNS (42), /* SQDBR B+42 */
273 COSTS_N_INSNS (28), /* SQEBR B+28 */
274 COSTS_N_INSNS (1), /* MADBR B */
275 COSTS_N_INSNS (1), /* MAEBR B */
276 COSTS_N_INSNS (101), /* DXBR B+101 */
277 COSTS_N_INSNS (29), /* DDBR */
278 COSTS_N_INSNS (22), /* DEBR */
279 COSTS_N_INSNS (160), /* DLGR cracked */
280 COSTS_N_INSNS (160), /* DLR cracked */
281 COSTS_N_INSNS (160), /* DR expanded */
282 COSTS_N_INSNS (160), /* DSGFR cracked */
283 COSTS_N_INSNS (160), /* DSGR cracked */
287 struct processor_costs zEC12_cost
=
289 COSTS_N_INSNS (7), /* M */
290 COSTS_N_INSNS (5), /* MGHI */
291 COSTS_N_INSNS (5), /* MH */
292 COSTS_N_INSNS (5), /* MHI */
293 COSTS_N_INSNS (7), /* ML */
294 COSTS_N_INSNS (7), /* MR */
295 COSTS_N_INSNS (6), /* MS */
296 COSTS_N_INSNS (8), /* MSG */
297 COSTS_N_INSNS (6), /* MSGF */
298 COSTS_N_INSNS (6), /* MSGFR */
299 COSTS_N_INSNS (8), /* MSGR */
300 COSTS_N_INSNS (6), /* MSR */
301 COSTS_N_INSNS (1) , /* multiplication in DFmode */
302 COSTS_N_INSNS (40), /* MXBR B+40 */
303 COSTS_N_INSNS (100), /* SQXBR B+100 */
304 COSTS_N_INSNS (42), /* SQDBR B+42 */
305 COSTS_N_INSNS (28), /* SQEBR B+28 */
306 COSTS_N_INSNS (1), /* MADBR B */
307 COSTS_N_INSNS (1), /* MAEBR B */
308 COSTS_N_INSNS (131), /* DXBR B+131 */
309 COSTS_N_INSNS (29), /* DDBR */
310 COSTS_N_INSNS (22), /* DEBR */
311 COSTS_N_INSNS (160), /* DLGR cracked */
312 COSTS_N_INSNS (160), /* DLR cracked */
313 COSTS_N_INSNS (160), /* DR expanded */
314 COSTS_N_INSNS (160), /* DSGFR cracked */
315 COSTS_N_INSNS (160), /* DSGR cracked */
320 const char *const name
;
321 const enum processor_type processor
;
322 const struct processor_costs
*cost
;
324 const processor_table
[] =
326 { "g5", PROCESSOR_9672_G5
, &z900_cost
},
327 { "g6", PROCESSOR_9672_G6
, &z900_cost
},
328 { "z900", PROCESSOR_2064_Z900
, &z900_cost
},
329 { "z990", PROCESSOR_2084_Z990
, &z990_cost
},
330 { "z9-109", PROCESSOR_2094_Z9_109
, &z9_109_cost
},
331 { "z9-ec", PROCESSOR_2094_Z9_EC
, &z9_109_cost
},
332 { "z10", PROCESSOR_2097_Z10
, &z10_cost
},
333 { "z196", PROCESSOR_2817_Z196
, &z196_cost
},
334 { "zEC12", PROCESSOR_2827_ZEC12
, &zEC12_cost
},
335 { "z13", PROCESSOR_2964_Z13
, &zEC12_cost
},
336 { "native", PROCESSOR_NATIVE
, NULL
}
339 extern int reload_completed
;
341 /* Kept up to date using the SCHED_VARIABLE_ISSUE hook. */
342 static rtx_insn
*last_scheduled_insn
;
343 #define MAX_SCHED_UNITS 3
344 static int last_scheduled_unit_distance
[MAX_SCHED_UNITS
];
346 /* The maximum score added for an instruction whose unit hasn't been
347 in use for MAX_SCHED_MIX_DISTANCE steps. Increase this value to
348 give instruction mix scheduling more priority over instruction
350 #define MAX_SCHED_MIX_SCORE 8
352 /* The maximum distance up to which individual scores will be
353 calculated. Everything beyond this gives MAX_SCHED_MIX_SCORE.
354 Increase this with the OOO windows size of the machine. */
355 #define MAX_SCHED_MIX_DISTANCE 100
357 /* Structure used to hold the components of a S/390 memory
358 address. A legitimate address on S/390 is of the general
360 base + index + displacement
361 where any of the components is optional.
363 base and index are registers of the class ADDR_REGS,
364 displacement is an unsigned 12-bit immediate constant. */
375 /* The following structure is embedded in the machine
376 specific part of struct function. */
378 struct GTY (()) s390_frame_layout
380 /* Offset within stack frame. */
381 HOST_WIDE_INT gprs_offset
;
382 HOST_WIDE_INT f0_offset
;
383 HOST_WIDE_INT f4_offset
;
384 HOST_WIDE_INT f8_offset
;
385 HOST_WIDE_INT backchain_offset
;
387 /* Number of first and last gpr where slots in the register
388 save area are reserved for. */
389 int first_save_gpr_slot
;
390 int last_save_gpr_slot
;
392 /* Location (FP register number) where GPRs (r0-r15) should
394 0 - does not need to be saved at all
396 #define SAVE_SLOT_NONE 0
397 #define SAVE_SLOT_STACK -1
398 signed char gpr_save_slots
[16];
400 /* Number of first and last gpr to be saved, restored. */
402 int first_restore_gpr
;
404 int last_restore_gpr
;
406 /* Bits standing for floating point registers. Set, if the
407 respective register has to be saved. Starting with reg 16 (f0)
408 at the rightmost bit.
409 Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
410 fpr 15 13 11 9 14 12 10 8 7 5 3 1 6 4 2 0
411 reg 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 */
412 unsigned int fpr_bitmap
;
414 /* Number of floating point registers f8-f15 which must be saved. */
417 /* Set if return address needs to be saved.
418 This flag is set by s390_return_addr_rtx if it could not use
419 the initial value of r14 and therefore depends on r14 saved
421 bool save_return_addr_p
;
423 /* Size of stack frame. */
424 HOST_WIDE_INT frame_size
;
427 /* Define the structure for the machine field in struct function. */
429 struct GTY(()) machine_function
431 struct s390_frame_layout frame_layout
;
433 /* Literal pool base register. */
436 /* True if we may need to perform branch splitting. */
437 bool split_branches_pending_p
;
439 bool has_landing_pad_p
;
441 /* True if the current function may contain a tbegin clobbering
445 /* For -fsplit-stack support: A stack local which holds a pointer to
446 the stack arguments for a function with a variable number of
447 arguments. This is set at the start of the function and is used
448 to initialize the overflow_arg_area field of the va_list
450 rtx split_stack_varargs_pointer
;
453 /* Few accessor macros for struct cfun->machine->s390_frame_layout. */
455 #define cfun_frame_layout (cfun->machine->frame_layout)
456 #define cfun_save_high_fprs_p (!!cfun_frame_layout.high_fprs)
457 #define cfun_save_arg_fprs_p (!!(TARGET_64BIT \
458 ? cfun_frame_layout.fpr_bitmap & 0x0f \
459 : cfun_frame_layout.fpr_bitmap & 0x03))
460 #define cfun_gprs_save_area_size ((cfun_frame_layout.last_save_gpr_slot - \
461 cfun_frame_layout.first_save_gpr_slot + 1) * UNITS_PER_LONG)
462 #define cfun_set_fpr_save(REGNO) (cfun->machine->frame_layout.fpr_bitmap |= \
463 (1 << (REGNO - FPR0_REGNUM)))
464 #define cfun_fpr_save_p(REGNO) (!!(cfun->machine->frame_layout.fpr_bitmap & \
465 (1 << (REGNO - FPR0_REGNUM))))
466 #define cfun_gpr_save_slot(REGNO) \
467 cfun->machine->frame_layout.gpr_save_slots[REGNO]
469 /* Number of GPRs and FPRs used for argument passing. */
470 #define GP_ARG_NUM_REG 5
471 #define FP_ARG_NUM_REG (TARGET_64BIT? 4 : 2)
472 #define VEC_ARG_NUM_REG 8
474 /* A couple of shortcuts. */
475 #define CONST_OK_FOR_J(x) \
476 CONST_OK_FOR_CONSTRAINT_P((x), 'J', "J")
477 #define CONST_OK_FOR_K(x) \
478 CONST_OK_FOR_CONSTRAINT_P((x), 'K', "K")
479 #define CONST_OK_FOR_Os(x) \
480 CONST_OK_FOR_CONSTRAINT_P((x), 'O', "Os")
481 #define CONST_OK_FOR_Op(x) \
482 CONST_OK_FOR_CONSTRAINT_P((x), 'O', "Op")
483 #define CONST_OK_FOR_On(x) \
484 CONST_OK_FOR_CONSTRAINT_P((x), 'O', "On")
486 #define REGNO_PAIR_OK(REGNO, MODE) \
487 (HARD_REGNO_NREGS ((REGNO), (MODE)) == 1 || !((REGNO) & 1))
489 /* That's the read ahead of the dynamic branch prediction unit in
490 bytes on a z10 (or higher) CPU. */
491 #define PREDICT_DISTANCE (TARGET_Z10 ? 384 : 2048)
494 /* Indicate which ABI has been used for passing vector args.
495 0 - no vector type arguments have been passed where the ABI is relevant
496 1 - the old ABI has been used
497 2 - a vector type argument has been passed either in a vector register
498 or on the stack by value */
499 static int s390_vector_abi
= 0;
501 /* Set the vector ABI marker if TYPE is subject to the vector ABI
502 switch. The vector ABI affects only vector data types. There are
503 two aspects of the vector ABI relevant here:
505 1. vectors >= 16 bytes have an alignment of 8 bytes with the new
506 ABI and natural alignment with the old.
508 2. vector <= 16 bytes are passed in VRs or by value on the stack
509 with the new ABI but by reference on the stack with the old.
511 If ARG_P is true TYPE is used for a function argument or return
512 value. The ABI marker then is set for all vector data types. If
513 ARG_P is false only type 1 vectors are being checked. */
516 s390_check_type_for_vector_abi (const_tree type
, bool arg_p
, bool in_struct_p
)
518 static hash_set
<const_tree
> visited_types_hash
;
523 if (type
== NULL_TREE
|| TREE_CODE (type
) == ERROR_MARK
)
526 if (visited_types_hash
.contains (type
))
529 visited_types_hash
.add (type
);
531 if (VECTOR_TYPE_P (type
))
533 int type_size
= int_size_in_bytes (type
);
535 /* Outside arguments only the alignment is changing and this
536 only happens for vector types >= 16 bytes. */
537 if (!arg_p
&& type_size
< 16)
540 /* In arguments vector types > 16 are passed as before (GCC
541 never enforced the bigger alignment for arguments which was
542 required by the old vector ABI). However, it might still be
543 ABI relevant due to the changed alignment if it is a struct
545 if (arg_p
&& type_size
> 16 && !in_struct_p
)
548 s390_vector_abi
= TARGET_VX_ABI
? 2 : 1;
550 else if (POINTER_TYPE_P (type
) || TREE_CODE (type
) == ARRAY_TYPE
)
552 /* ARRAY_TYPE: Since with neither of the ABIs we have more than
553 natural alignment there will never be ABI dependent padding
554 in an array type. That's why we do not set in_struct_p to
556 s390_check_type_for_vector_abi (TREE_TYPE (type
), arg_p
, in_struct_p
);
558 else if (TREE_CODE (type
) == FUNCTION_TYPE
|| TREE_CODE (type
) == METHOD_TYPE
)
562 /* Check the return type. */
563 s390_check_type_for_vector_abi (TREE_TYPE (type
), true, false);
565 for (arg_chain
= TYPE_ARG_TYPES (type
);
567 arg_chain
= TREE_CHAIN (arg_chain
))
568 s390_check_type_for_vector_abi (TREE_VALUE (arg_chain
), true, false);
570 else if (RECORD_OR_UNION_TYPE_P (type
))
574 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
576 if (TREE_CODE (field
) != FIELD_DECL
)
579 s390_check_type_for_vector_abi (TREE_TYPE (field
), arg_p
, true);
585 /* System z builtins. */
587 #include "s390-builtins.h"
589 const unsigned int bflags_builtin
[S390_BUILTIN_MAX
+ 1] =
594 #define B_DEF(NAME, PATTERN, ATTRS, BFLAGS, ...) BFLAGS,
596 #define OB_DEF_VAR(...)
597 #include "s390-builtins.def"
601 const unsigned int opflags_builtin
[S390_BUILTIN_MAX
+ 1] =
606 #define B_DEF(NAME, PATTERN, ATTRS, BFLAGS, OPFLAGS, ...) OPFLAGS,
608 #define OB_DEF_VAR(...)
609 #include "s390-builtins.def"
613 const unsigned int bflags_overloaded_builtin
[S390_OVERLOADED_BUILTIN_MAX
+ 1] =
619 #define OB_DEF(NAME, FIRST_VAR_NAME, LAST_VAR_NAME, BFLAGS, ...) BFLAGS,
620 #define OB_DEF_VAR(...)
621 #include "s390-builtins.def"
626 opflags_overloaded_builtin_var
[S390_OVERLOADED_BUILTIN_VAR_MAX
+ 1] =
633 #define OB_DEF_VAR(NAME, PATTERN, FLAGS, FNTYPE) FLAGS,
634 #include "s390-builtins.def"
638 tree s390_builtin_types
[BT_MAX
];
639 tree s390_builtin_fn_types
[BT_FN_MAX
];
640 tree s390_builtin_decls
[S390_BUILTIN_MAX
+
641 S390_OVERLOADED_BUILTIN_MAX
+
642 S390_OVERLOADED_BUILTIN_VAR_MAX
];
644 static enum insn_code
const code_for_builtin
[S390_BUILTIN_MAX
+ 1] = {
648 #define B_DEF(NAME, PATTERN, ...) CODE_FOR_##PATTERN,
650 #define OB_DEF_VAR(...)
652 #include "s390-builtins.def"
657 s390_init_builtins (void)
659 /* These definitions are being used in s390-builtins.def. */
660 tree returns_twice_attr
= tree_cons (get_identifier ("returns_twice"),
662 tree noreturn_attr
= tree_cons (get_identifier ("noreturn"), NULL
, NULL
);
663 tree c_uint64_type_node
;
665 /* The uint64_type_node from tree.c is not compatible to the C99
666 uint64_t data type. What we want is c_uint64_type_node from
667 c-common.c. But since backend code is not supposed to interface
668 with the frontend we recreate it here. */
670 c_uint64_type_node
= long_unsigned_type_node
;
672 c_uint64_type_node
= long_long_unsigned_type_node
;
675 #define DEF_TYPE(INDEX, BFLAGS, NODE, CONST_P) \
676 if (s390_builtin_types[INDEX] == NULL) \
677 s390_builtin_types[INDEX] = (!CONST_P) ? \
678 (NODE) : build_type_variant ((NODE), 1, 0);
680 #undef DEF_POINTER_TYPE
681 #define DEF_POINTER_TYPE(INDEX, BFLAGS, INDEX_BASE) \
682 if (s390_builtin_types[INDEX] == NULL) \
683 s390_builtin_types[INDEX] = \
684 build_pointer_type (s390_builtin_types[INDEX_BASE]);
686 #undef DEF_DISTINCT_TYPE
687 #define DEF_DISTINCT_TYPE(INDEX, BFLAGS, INDEX_BASE) \
688 if (s390_builtin_types[INDEX] == NULL) \
689 s390_builtin_types[INDEX] = \
690 build_distinct_type_copy (s390_builtin_types[INDEX_BASE]);
692 #undef DEF_VECTOR_TYPE
693 #define DEF_VECTOR_TYPE(INDEX, BFLAGS, INDEX_BASE, ELEMENTS) \
694 if (s390_builtin_types[INDEX] == NULL) \
695 s390_builtin_types[INDEX] = \
696 build_vector_type (s390_builtin_types[INDEX_BASE], ELEMENTS);
698 #undef DEF_OPAQUE_VECTOR_TYPE
699 #define DEF_OPAQUE_VECTOR_TYPE(INDEX, BFLAGS, INDEX_BASE, ELEMENTS) \
700 if (s390_builtin_types[INDEX] == NULL) \
701 s390_builtin_types[INDEX] = \
702 build_opaque_vector_type (s390_builtin_types[INDEX_BASE], ELEMENTS);
705 #define DEF_FN_TYPE(INDEX, BFLAGS, args...) \
706 if (s390_builtin_fn_types[INDEX] == NULL) \
707 s390_builtin_fn_types[INDEX] = \
708 build_function_type_list (args, NULL_TREE);
710 #define DEF_OV_TYPE(...)
711 #include "s390-builtin-types.def"
714 #define B_DEF(NAME, PATTERN, ATTRS, BFLAGS, OPFLAGS, FNTYPE) \
715 if (s390_builtin_decls[S390_BUILTIN_##NAME] == NULL) \
716 s390_builtin_decls[S390_BUILTIN_##NAME] = \
717 add_builtin_function ("__builtin_" #NAME, \
718 s390_builtin_fn_types[FNTYPE], \
719 S390_BUILTIN_##NAME, \
724 #define OB_DEF(NAME, FIRST_VAR_NAME, LAST_VAR_NAME, BFLAGS, FNTYPE) \
725 if (s390_builtin_decls[S390_OVERLOADED_BUILTIN_##NAME + S390_BUILTIN_MAX] \
727 s390_builtin_decls[S390_OVERLOADED_BUILTIN_##NAME + S390_BUILTIN_MAX] = \
728 add_builtin_function ("__builtin_" #NAME, \
729 s390_builtin_fn_types[FNTYPE], \
730 S390_OVERLOADED_BUILTIN_##NAME + S390_BUILTIN_MAX, \
735 #define OB_DEF_VAR(...)
736 #include "s390-builtins.def"
740 /* Return true if ARG is appropriate as argument number ARGNUM of
741 builtin DECL. The operand flags from s390-builtins.def have to
742 passed as OP_FLAGS. */
744 s390_const_operand_ok (tree arg
, int argnum
, int op_flags
, tree decl
)
746 if (O_UIMM_P (op_flags
))
748 int bitwidths
[] = { 1, 2, 3, 4, 5, 8, 12, 16, 32 };
749 int bitwidth
= bitwidths
[op_flags
- O_U1
];
751 if (!tree_fits_uhwi_p (arg
)
752 || tree_to_uhwi (arg
) > ((unsigned HOST_WIDE_INT
)1 << bitwidth
) - 1)
754 error("constant argument %d for builtin %qF is out of range (0.."
755 HOST_WIDE_INT_PRINT_UNSIGNED
")",
757 ((unsigned HOST_WIDE_INT
)1 << bitwidth
) - 1);
762 if (O_SIMM_P (op_flags
))
764 int bitwidths
[] = { 2, 3, 4, 5, 8, 12, 16, 32 };
765 int bitwidth
= bitwidths
[op_flags
- O_S2
];
767 if (!tree_fits_shwi_p (arg
)
768 || tree_to_shwi (arg
) < -((HOST_WIDE_INT
)1 << (bitwidth
- 1))
769 || tree_to_shwi (arg
) > (((HOST_WIDE_INT
)1 << (bitwidth
- 1)) - 1))
771 error("constant argument %d for builtin %qF is out of range ("
772 HOST_WIDE_INT_PRINT_DEC
".."
773 HOST_WIDE_INT_PRINT_DEC
")",
775 -((HOST_WIDE_INT
)1 << (bitwidth
- 1)),
776 ((HOST_WIDE_INT
)1 << (bitwidth
- 1)) - 1);
783 /* Expand an expression EXP that calls a built-in function,
784 with result going to TARGET if that's convenient
785 (and in mode MODE if that's convenient).
786 SUBTARGET may be used as the target for computing one of EXP's operands.
787 IGNORE is nonzero if the value is to be ignored. */
790 s390_expand_builtin (tree exp
, rtx target
, rtx subtarget ATTRIBUTE_UNUSED
,
791 machine_mode mode ATTRIBUTE_UNUSED
,
792 int ignore ATTRIBUTE_UNUSED
)
796 tree fndecl
= TREE_OPERAND (CALL_EXPR_FN (exp
), 0);
797 unsigned int fcode
= DECL_FUNCTION_CODE (fndecl
);
798 enum insn_code icode
;
799 rtx op
[MAX_ARGS
], pat
;
803 call_expr_arg_iterator iter
;
804 unsigned int all_op_flags
= opflags_for_builtin (fcode
);
805 machine_mode last_vec_mode
= VOIDmode
;
807 if (TARGET_DEBUG_ARG
)
810 "s390_expand_builtin, code = %4d, %s, bflags = 0x%x\n",
811 (int)fcode
, IDENTIFIER_POINTER (DECL_NAME (fndecl
)),
812 bflags_for_builtin (fcode
));
815 if (S390_USE_TARGET_ATTRIBUTE
)
819 bflags
= bflags_for_builtin (fcode
);
820 if ((bflags
& B_HTM
) && !TARGET_HTM
)
822 error ("Builtin %qF is not supported without -mhtm "
823 "(default with -march=zEC12 and higher).", fndecl
);
826 if ((bflags
& B_VX
) && !TARGET_VX
)
828 error ("Builtin %qF is not supported without -mvx "
829 "(default with -march=z13 and higher).", fndecl
);
833 if (fcode
>= S390_OVERLOADED_BUILTIN_VAR_OFFSET
834 && fcode
< S390_ALL_BUILTIN_MAX
)
838 else if (fcode
< S390_OVERLOADED_BUILTIN_OFFSET
)
840 icode
= code_for_builtin
[fcode
];
841 /* Set a flag in the machine specific cfun part in order to support
842 saving/restoring of FPRs. */
843 if (fcode
== S390_BUILTIN_tbegin
|| fcode
== S390_BUILTIN_tbegin_retry
)
844 cfun
->machine
->tbegin_p
= true;
846 else if (fcode
< S390_OVERLOADED_BUILTIN_VAR_OFFSET
)
848 error ("Unresolved overloaded builtin");
852 internal_error ("bad builtin fcode");
855 internal_error ("bad builtin icode");
857 nonvoid
= TREE_TYPE (TREE_TYPE (fndecl
)) != void_type_node
;
861 machine_mode tmode
= insn_data
[icode
].operand
[0].mode
;
863 || GET_MODE (target
) != tmode
864 || !(*insn_data
[icode
].operand
[0].predicate
) (target
, tmode
))
865 target
= gen_reg_rtx (tmode
);
867 /* There are builtins (e.g. vec_promote) with no vector
868 arguments but an element selector. So we have to also look
869 at the vector return type when emitting the modulo
871 if (VECTOR_MODE_P (insn_data
[icode
].operand
[0].mode
))
872 last_vec_mode
= insn_data
[icode
].operand
[0].mode
;
876 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, exp
)
878 const struct insn_operand_data
*insn_op
;
879 unsigned int op_flags
= all_op_flags
& ((1 << O_SHIFT
) - 1);
881 all_op_flags
= all_op_flags
>> O_SHIFT
;
883 if (arg
== error_mark_node
)
885 if (arity
>= MAX_ARGS
)
888 if (O_IMM_P (op_flags
)
889 && TREE_CODE (arg
) != INTEGER_CST
)
891 error ("constant value required for builtin %qF argument %d",
896 if (!s390_const_operand_ok (arg
, arity
+ 1, op_flags
, fndecl
))
899 insn_op
= &insn_data
[icode
].operand
[arity
+ nonvoid
];
900 op
[arity
] = expand_expr (arg
, NULL_RTX
, insn_op
->mode
, EXPAND_NORMAL
);
902 /* expand_expr truncates constants to the target mode only if it
903 is "convenient". However, our checks below rely on this
905 if (CONST_INT_P (op
[arity
])
906 && SCALAR_INT_MODE_P (insn_op
->mode
)
907 && GET_MODE (op
[arity
]) != insn_op
->mode
)
908 op
[arity
] = GEN_INT (trunc_int_for_mode (INTVAL (op
[arity
]),
911 /* Wrap the expanded RTX for pointer types into a MEM expr with
912 the proper mode. This allows us to use e.g. (match_operand
913 "memory_operand"..) in the insn patterns instead of (mem
914 (match_operand "address_operand)). This is helpful for
915 patterns not just accepting MEMs. */
916 if (POINTER_TYPE_P (TREE_TYPE (arg
))
917 && insn_op
->predicate
!= address_operand
)
918 op
[arity
] = gen_rtx_MEM (insn_op
->mode
, op
[arity
]);
920 /* Expand the module operation required on element selectors. */
921 if (op_flags
== O_ELEM
)
923 gcc_assert (last_vec_mode
!= VOIDmode
);
924 op
[arity
] = simplify_expand_binop (SImode
, code_to_optab (AND
),
926 GEN_INT (GET_MODE_NUNITS (last_vec_mode
) - 1),
927 NULL_RTX
, 1, OPTAB_DIRECT
);
930 /* Record the vector mode used for an element selector. This assumes:
931 1. There is no builtin with two different vector modes and an element selector
932 2. The element selector comes after the vector type it is referring to.
933 This currently the true for all the builtins but FIXME we
934 should better check for that. */
935 if (VECTOR_MODE_P (insn_op
->mode
))
936 last_vec_mode
= insn_op
->mode
;
938 if (insn_op
->predicate (op
[arity
], insn_op
->mode
))
944 if (MEM_P (op
[arity
])
945 && insn_op
->predicate
== memory_operand
946 && (GET_MODE (XEXP (op
[arity
], 0)) == Pmode
947 || GET_MODE (XEXP (op
[arity
], 0)) == VOIDmode
))
949 op
[arity
] = replace_equiv_address (op
[arity
],
950 copy_to_mode_reg (Pmode
,
951 XEXP (op
[arity
], 0)));
953 else if (GET_MODE (op
[arity
]) == insn_op
->mode
954 || GET_MODE (op
[arity
]) == VOIDmode
955 || (insn_op
->predicate
== address_operand
956 && GET_MODE (op
[arity
]) == Pmode
))
958 /* An address_operand usually has VOIDmode in the expander
959 so we cannot use this. */
960 machine_mode target_mode
=
961 (insn_op
->predicate
== address_operand
962 ? Pmode
: insn_op
->mode
);
963 op
[arity
] = copy_to_mode_reg (target_mode
, op
[arity
]);
966 if (!insn_op
->predicate (op
[arity
], insn_op
->mode
))
968 error ("Invalid argument %d for builtin %qF", arity
+ 1, fndecl
);
977 pat
= GEN_FCN (icode
) (target
);
981 pat
= GEN_FCN (icode
) (target
, op
[0]);
983 pat
= GEN_FCN (icode
) (op
[0]);
987 pat
= GEN_FCN (icode
) (target
, op
[0], op
[1]);
989 pat
= GEN_FCN (icode
) (op
[0], op
[1]);
993 pat
= GEN_FCN (icode
) (target
, op
[0], op
[1], op
[2]);
995 pat
= GEN_FCN (icode
) (op
[0], op
[1], op
[2]);
999 pat
= GEN_FCN (icode
) (target
, op
[0], op
[1], op
[2], op
[3]);
1001 pat
= GEN_FCN (icode
) (op
[0], op
[1], op
[2], op
[3]);
1005 pat
= GEN_FCN (icode
) (target
, op
[0], op
[1], op
[2], op
[3], op
[4]);
1007 pat
= GEN_FCN (icode
) (op
[0], op
[1], op
[2], op
[3], op
[4]);
1011 pat
= GEN_FCN (icode
) (target
, op
[0], op
[1], op
[2], op
[3], op
[4], op
[5]);
1013 pat
= GEN_FCN (icode
) (op
[0], op
[1], op
[2], op
[3], op
[4], op
[5]);
1029 static const int s390_hotpatch_hw_max
= 1000000;
1030 static int s390_hotpatch_hw_before_label
= 0;
1031 static int s390_hotpatch_hw_after_label
= 0;
1033 /* Check whether the hotpatch attribute is applied to a function and, if it has
1034 an argument, the argument is valid. */
1037 s390_handle_hotpatch_attribute (tree
*node
, tree name
, tree args
,
1038 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
1044 if (TREE_CODE (*node
) != FUNCTION_DECL
)
1046 warning (OPT_Wattributes
, "%qE attribute only applies to functions",
1048 *no_add_attrs
= true;
1050 if (args
!= NULL
&& TREE_CHAIN (args
) != NULL
)
1052 expr
= TREE_VALUE (args
);
1053 expr2
= TREE_VALUE (TREE_CHAIN (args
));
1055 if (args
== NULL
|| TREE_CHAIN (args
) == NULL
)
1057 else if (TREE_CODE (expr
) != INTEGER_CST
1058 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
))
1059 || wi::gtu_p (expr
, s390_hotpatch_hw_max
))
1061 else if (TREE_CODE (expr2
) != INTEGER_CST
1062 || !INTEGRAL_TYPE_P (TREE_TYPE (expr2
))
1063 || wi::gtu_p (expr2
, s390_hotpatch_hw_max
))
1069 error ("requested %qE attribute is not a comma separated pair of"
1070 " non-negative integer constants or too large (max. %d)", name
,
1071 s390_hotpatch_hw_max
);
1072 *no_add_attrs
= true;
1078 /* Expand the s390_vector_bool type attribute. */
1081 s390_handle_vectorbool_attribute (tree
*node
, tree name ATTRIBUTE_UNUSED
,
1082 tree args ATTRIBUTE_UNUSED
,
1083 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
1085 tree type
= *node
, result
= NULL_TREE
;
1088 while (POINTER_TYPE_P (type
)
1089 || TREE_CODE (type
) == FUNCTION_TYPE
1090 || TREE_CODE (type
) == METHOD_TYPE
1091 || TREE_CODE (type
) == ARRAY_TYPE
)
1092 type
= TREE_TYPE (type
);
1094 mode
= TYPE_MODE (type
);
1097 case DImode
: case V2DImode
: result
= s390_builtin_types
[BT_BV2DI
]; break;
1098 case SImode
: case V4SImode
: result
= s390_builtin_types
[BT_BV4SI
]; break;
1099 case HImode
: case V8HImode
: result
= s390_builtin_types
[BT_BV8HI
]; break;
1100 case QImode
: case V16QImode
: result
= s390_builtin_types
[BT_BV16QI
];
1104 *no_add_attrs
= true; /* No need to hang on to the attribute. */
1107 *node
= lang_hooks
.types
.reconstruct_complex_type (*node
, result
);
1112 static const struct attribute_spec s390_attribute_table
[] = {
1113 { "hotpatch", 2, 2, true, false, false, s390_handle_hotpatch_attribute
, false },
1114 { "s390_vector_bool", 0, 0, false, true, false, s390_handle_vectorbool_attribute
, true },
1116 { NULL
, 0, 0, false, false, false, NULL
, false }
1119 /* Return the alignment for LABEL. We default to the -falign-labels
1120 value except for the literal pool base label. */
1122 s390_label_align (rtx label
)
1124 rtx_insn
*prev_insn
= prev_active_insn (label
);
1127 if (prev_insn
== NULL_RTX
)
1130 set
= single_set (prev_insn
);
1132 if (set
== NULL_RTX
)
1135 src
= SET_SRC (set
);
1137 /* Don't align literal pool base labels. */
1138 if (GET_CODE (src
) == UNSPEC
1139 && XINT (src
, 1) == UNSPEC_MAIN_BASE
)
1143 return align_labels_log
;
1147 s390_libgcc_cmp_return_mode (void)
1149 return TARGET_64BIT
? DImode
: SImode
;
1153 s390_libgcc_shift_count_mode (void)
1155 return TARGET_64BIT
? DImode
: SImode
;
1159 s390_unwind_word_mode (void)
1161 return TARGET_64BIT
? DImode
: SImode
;
1164 /* Return true if the back end supports mode MODE. */
1166 s390_scalar_mode_supported_p (machine_mode mode
)
1168 /* In contrast to the default implementation reject TImode constants on 31bit
1169 TARGET_ZARCH for ABI compliance. */
1170 if (!TARGET_64BIT
&& TARGET_ZARCH
&& mode
== TImode
)
1173 if (DECIMAL_FLOAT_MODE_P (mode
))
1174 return default_decimal_float_supported_p ();
1176 return default_scalar_mode_supported_p (mode
);
1179 /* Return true if the back end supports vector mode MODE. */
1181 s390_vector_mode_supported_p (machine_mode mode
)
1185 if (!VECTOR_MODE_P (mode
)
1187 || GET_MODE_SIZE (mode
) > 16)
1190 inner
= GET_MODE_INNER (mode
);
1208 /* Set the has_landing_pad_p flag in struct machine_function to VALUE. */
1211 s390_set_has_landing_pad_p (bool value
)
1213 cfun
->machine
->has_landing_pad_p
= value
;
1216 /* If two condition code modes are compatible, return a condition code
1217 mode which is compatible with both. Otherwise, return
1221 s390_cc_modes_compatible (machine_mode m1
, machine_mode m2
)
1229 if (m2
== CCUmode
|| m2
== CCTmode
|| m2
== CCZ1mode
1230 || m2
== CCSmode
|| m2
== CCSRmode
|| m2
== CCURmode
)
1251 /* Return true if SET either doesn't set the CC register, or else
1252 the source and destination have matching CC modes and that
1253 CC mode is at least as constrained as REQ_MODE. */
1256 s390_match_ccmode_set (rtx set
, machine_mode req_mode
)
1258 machine_mode set_mode
;
1260 gcc_assert (GET_CODE (set
) == SET
);
1262 if (GET_CODE (SET_DEST (set
)) != REG
|| !CC_REGNO_P (REGNO (SET_DEST (set
))))
1265 set_mode
= GET_MODE (SET_DEST (set
));
1284 if (req_mode
!= set_mode
)
1289 if (req_mode
!= CCSmode
&& req_mode
!= CCUmode
&& req_mode
!= CCTmode
1290 && req_mode
!= CCSRmode
&& req_mode
!= CCURmode
)
1296 if (req_mode
!= CCAmode
)
1304 return (GET_MODE (SET_SRC (set
)) == set_mode
);
1307 /* Return true if every SET in INSN that sets the CC register
1308 has source and destination with matching CC modes and that
1309 CC mode is at least as constrained as REQ_MODE.
1310 If REQ_MODE is VOIDmode, always return false. */
1313 s390_match_ccmode (rtx_insn
*insn
, machine_mode req_mode
)
1317 /* s390_tm_ccmode returns VOIDmode to indicate failure. */
1318 if (req_mode
== VOIDmode
)
1321 if (GET_CODE (PATTERN (insn
)) == SET
)
1322 return s390_match_ccmode_set (PATTERN (insn
), req_mode
);
1324 if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
1325 for (i
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
1327 rtx set
= XVECEXP (PATTERN (insn
), 0, i
);
1328 if (GET_CODE (set
) == SET
)
1329 if (!s390_match_ccmode_set (set
, req_mode
))
1336 /* If a test-under-mask instruction can be used to implement
1337 (compare (and ... OP1) OP2), return the CC mode required
1338 to do that. Otherwise, return VOIDmode.
1339 MIXED is true if the instruction can distinguish between
1340 CC1 and CC2 for mixed selected bits (TMxx), it is false
1341 if the instruction cannot (TM). */
1344 s390_tm_ccmode (rtx op1
, rtx op2
, bool mixed
)
1348 /* ??? Fixme: should work on CONST_WIDE_INT as well. */
1349 if (GET_CODE (op1
) != CONST_INT
|| GET_CODE (op2
) != CONST_INT
)
1352 /* Selected bits all zero: CC0.
1353 e.g.: int a; if ((a & (16 + 128)) == 0) */
1354 if (INTVAL (op2
) == 0)
1357 /* Selected bits all one: CC3.
1358 e.g.: int a; if ((a & (16 + 128)) == 16 + 128) */
1359 if (INTVAL (op2
) == INTVAL (op1
))
1362 /* Exactly two bits selected, mixed zeroes and ones: CC1 or CC2. e.g.:
1364 if ((a & (16 + 128)) == 16) -> CCT1
1365 if ((a & (16 + 128)) == 128) -> CCT2 */
1368 bit1
= exact_log2 (INTVAL (op2
));
1369 bit0
= exact_log2 (INTVAL (op1
) ^ INTVAL (op2
));
1370 if (bit0
!= -1 && bit1
!= -1)
1371 return bit0
> bit1
? CCT1mode
: CCT2mode
;
1377 /* Given a comparison code OP (EQ, NE, etc.) and the operands
1378 OP0 and OP1 of a COMPARE, return the mode to be used for the
1382 s390_select_ccmode (enum rtx_code code
, rtx op0
, rtx op1
)
1385 && register_operand (op0
, DFmode
)
1386 && register_operand (op1
, DFmode
))
1388 /* LT, LE, UNGT, UNGE require swapping OP0 and OP1. Either
1389 s390_emit_compare or s390_canonicalize_comparison will take
1411 if ((GET_CODE (op0
) == NEG
|| GET_CODE (op0
) == ABS
)
1412 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
1414 if (GET_CODE (op0
) == PLUS
&& GET_CODE (XEXP (op0
, 1)) == CONST_INT
1415 && CONST_OK_FOR_K (INTVAL (XEXP (op0
, 1))))
1417 if ((GET_CODE (op0
) == PLUS
|| GET_CODE (op0
) == MINUS
1418 || GET_CODE (op1
) == NEG
)
1419 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
1422 if (GET_CODE (op0
) == AND
)
1424 /* Check whether we can potentially do it via TM. */
1425 machine_mode ccmode
;
1426 ccmode
= s390_tm_ccmode (XEXP (op0
, 1), op1
, 1);
1427 if (ccmode
!= VOIDmode
)
1429 /* Relax CCTmode to CCZmode to allow fall-back to AND
1430 if that turns out to be beneficial. */
1431 return ccmode
== CCTmode
? CCZmode
: ccmode
;
1435 if (register_operand (op0
, HImode
)
1436 && GET_CODE (op1
) == CONST_INT
1437 && (INTVAL (op1
) == -1 || INTVAL (op1
) == 65535))
1439 if (register_operand (op0
, QImode
)
1440 && GET_CODE (op1
) == CONST_INT
1441 && (INTVAL (op1
) == -1 || INTVAL (op1
) == 255))
1450 /* The only overflow condition of NEG and ABS happens when
1451 -INT_MAX is used as parameter, which stays negative. So
1452 we have an overflow from a positive value to a negative.
1453 Using CCAP mode the resulting cc can be used for comparisons. */
1454 if ((GET_CODE (op0
) == NEG
|| GET_CODE (op0
) == ABS
)
1455 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
1458 /* If constants are involved in an add instruction it is possible to use
1459 the resulting cc for comparisons with zero. Knowing the sign of the
1460 constant the overflow behavior gets predictable. e.g.:
1461 int a, b; if ((b = a + c) > 0)
1462 with c as a constant value: c < 0 -> CCAN and c >= 0 -> CCAP */
1463 if (GET_CODE (op0
) == PLUS
&& GET_CODE (XEXP (op0
, 1)) == CONST_INT
1464 && (CONST_OK_FOR_K (INTVAL (XEXP (op0
, 1)))
1465 || (CONST_OK_FOR_CONSTRAINT_P (INTVAL (XEXP (op0
, 1)), 'O', "Os")
1466 /* Avoid INT32_MIN on 32 bit. */
1467 && (!TARGET_ZARCH
|| INTVAL (XEXP (op0
, 1)) != -0x7fffffff - 1))))
1469 if (INTVAL (XEXP((op0
), 1)) < 0)
1483 if ((GET_CODE (op0
) == SIGN_EXTEND
|| GET_CODE (op0
) == ZERO_EXTEND
)
1484 && GET_CODE (op1
) != CONST_INT
)
1490 if (GET_CODE (op0
) == PLUS
1491 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
1494 if ((GET_CODE (op0
) == SIGN_EXTEND
|| GET_CODE (op0
) == ZERO_EXTEND
)
1495 && GET_CODE (op1
) != CONST_INT
)
1501 if (GET_CODE (op0
) == MINUS
1502 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
1505 if ((GET_CODE (op0
) == SIGN_EXTEND
|| GET_CODE (op0
) == ZERO_EXTEND
)
1506 && GET_CODE (op1
) != CONST_INT
)
1515 /* Replace the comparison OP0 CODE OP1 by a semantically equivalent one
1516 that we can implement more efficiently. */
1519 s390_canonicalize_comparison (int *code
, rtx
*op0
, rtx
*op1
,
1520 bool op0_preserve_value
)
1522 if (op0_preserve_value
)
1525 /* Convert ZERO_EXTRACT back to AND to enable TM patterns. */
1526 if ((*code
== EQ
|| *code
== NE
)
1527 && *op1
== const0_rtx
1528 && GET_CODE (*op0
) == ZERO_EXTRACT
1529 && GET_CODE (XEXP (*op0
, 1)) == CONST_INT
1530 && GET_CODE (XEXP (*op0
, 2)) == CONST_INT
1531 && SCALAR_INT_MODE_P (GET_MODE (XEXP (*op0
, 0))))
1533 rtx inner
= XEXP (*op0
, 0);
1534 HOST_WIDE_INT modesize
= GET_MODE_BITSIZE (GET_MODE (inner
));
1535 HOST_WIDE_INT len
= INTVAL (XEXP (*op0
, 1));
1536 HOST_WIDE_INT pos
= INTVAL (XEXP (*op0
, 2));
1538 if (len
> 0 && len
< modesize
1539 && pos
>= 0 && pos
+ len
<= modesize
1540 && modesize
<= HOST_BITS_PER_WIDE_INT
)
1542 unsigned HOST_WIDE_INT block
;
1543 block
= ((unsigned HOST_WIDE_INT
) 1 << len
) - 1;
1544 block
<<= modesize
- pos
- len
;
1546 *op0
= gen_rtx_AND (GET_MODE (inner
), inner
,
1547 gen_int_mode (block
, GET_MODE (inner
)));
1551 /* Narrow AND of memory against immediate to enable TM. */
1552 if ((*code
== EQ
|| *code
== NE
)
1553 && *op1
== const0_rtx
1554 && GET_CODE (*op0
) == AND
1555 && GET_CODE (XEXP (*op0
, 1)) == CONST_INT
1556 && SCALAR_INT_MODE_P (GET_MODE (XEXP (*op0
, 0))))
1558 rtx inner
= XEXP (*op0
, 0);
1559 rtx mask
= XEXP (*op0
, 1);
1561 /* Ignore paradoxical SUBREGs if all extra bits are masked out. */
1562 if (GET_CODE (inner
) == SUBREG
1563 && SCALAR_INT_MODE_P (GET_MODE (SUBREG_REG (inner
)))
1564 && (GET_MODE_SIZE (GET_MODE (inner
))
1565 >= GET_MODE_SIZE (GET_MODE (SUBREG_REG (inner
))))
1567 & GET_MODE_MASK (GET_MODE (inner
))
1568 & ~GET_MODE_MASK (GET_MODE (SUBREG_REG (inner
))))
1570 inner
= SUBREG_REG (inner
);
1572 /* Do not change volatile MEMs. */
1573 if (MEM_P (inner
) && !MEM_VOLATILE_P (inner
))
1575 int part
= s390_single_part (XEXP (*op0
, 1),
1576 GET_MODE (inner
), QImode
, 0);
1579 mask
= gen_int_mode (s390_extract_part (mask
, QImode
, 0), QImode
);
1580 inner
= adjust_address_nv (inner
, QImode
, part
);
1581 *op0
= gen_rtx_AND (QImode
, inner
, mask
);
1586 /* Narrow comparisons against 0xffff to HImode if possible. */
1587 if ((*code
== EQ
|| *code
== NE
)
1588 && GET_CODE (*op1
) == CONST_INT
1589 && INTVAL (*op1
) == 0xffff
1590 && SCALAR_INT_MODE_P (GET_MODE (*op0
))
1591 && (nonzero_bits (*op0
, GET_MODE (*op0
))
1592 & ~(unsigned HOST_WIDE_INT
) 0xffff) == 0)
1594 *op0
= gen_lowpart (HImode
, *op0
);
1598 /* Remove redundant UNSPEC_STRCMPCC_TO_INT conversions if possible. */
1599 if (GET_CODE (*op0
) == UNSPEC
1600 && XINT (*op0
, 1) == UNSPEC_STRCMPCC_TO_INT
1601 && XVECLEN (*op0
, 0) == 1
1602 && GET_MODE (XVECEXP (*op0
, 0, 0)) == CCUmode
1603 && GET_CODE (XVECEXP (*op0
, 0, 0)) == REG
1604 && REGNO (XVECEXP (*op0
, 0, 0)) == CC_REGNUM
1605 && *op1
== const0_rtx
)
1607 enum rtx_code new_code
= UNKNOWN
;
1610 case EQ
: new_code
= EQ
; break;
1611 case NE
: new_code
= NE
; break;
1612 case LT
: new_code
= GTU
; break;
1613 case GT
: new_code
= LTU
; break;
1614 case LE
: new_code
= GEU
; break;
1615 case GE
: new_code
= LEU
; break;
1619 if (new_code
!= UNKNOWN
)
1621 *op0
= XVECEXP (*op0
, 0, 0);
1626 /* Remove redundant UNSPEC_CC_TO_INT conversions if possible. */
1627 if (GET_CODE (*op0
) == UNSPEC
1628 && XINT (*op0
, 1) == UNSPEC_CC_TO_INT
1629 && XVECLEN (*op0
, 0) == 1
1630 && GET_CODE (XVECEXP (*op0
, 0, 0)) == REG
1631 && REGNO (XVECEXP (*op0
, 0, 0)) == CC_REGNUM
1632 && CONST_INT_P (*op1
))
1634 enum rtx_code new_code
= UNKNOWN
;
1635 switch (GET_MODE (XVECEXP (*op0
, 0, 0)))
1641 case EQ
: new_code
= EQ
; break;
1642 case NE
: new_code
= NE
; break;
1649 if (new_code
!= UNKNOWN
)
1651 /* For CCRAWmode put the required cc mask into the second
1653 if (GET_MODE (XVECEXP (*op0
, 0, 0)) == CCRAWmode
1654 && INTVAL (*op1
) >= 0 && INTVAL (*op1
) <= 3)
1655 *op1
= gen_rtx_CONST_INT (VOIDmode
, 1 << (3 - INTVAL (*op1
)));
1656 *op0
= XVECEXP (*op0
, 0, 0);
1661 /* Simplify cascaded EQ, NE with const0_rtx. */
1662 if ((*code
== NE
|| *code
== EQ
)
1663 && (GET_CODE (*op0
) == EQ
|| GET_CODE (*op0
) == NE
)
1664 && GET_MODE (*op0
) == SImode
1665 && GET_MODE (XEXP (*op0
, 0)) == CCZ1mode
1666 && REG_P (XEXP (*op0
, 0))
1667 && XEXP (*op0
, 1) == const0_rtx
1668 && *op1
== const0_rtx
)
1670 if ((*code
== EQ
&& GET_CODE (*op0
) == NE
)
1671 || (*code
== NE
&& GET_CODE (*op0
) == EQ
))
1675 *op0
= XEXP (*op0
, 0);
1678 /* Prefer register over memory as first operand. */
1679 if (MEM_P (*op0
) && REG_P (*op1
))
1681 rtx tem
= *op0
; *op0
= *op1
; *op1
= tem
;
1682 *code
= (int)swap_condition ((enum rtx_code
)*code
);
1685 /* Using the scalar variants of vector instructions for 64 bit FP
1686 comparisons might require swapping the operands. */
1688 && register_operand (*op0
, DFmode
)
1689 && register_operand (*op1
, DFmode
)
1690 && (*code
== LT
|| *code
== LE
|| *code
== UNGT
|| *code
== UNGE
))
1696 case LT
: *code
= GT
; break;
1697 case LE
: *code
= GE
; break;
1698 case UNGT
: *code
= UNLE
; break;
1699 case UNGE
: *code
= UNLT
; break;
1702 tmp
= *op0
; *op0
= *op1
; *op1
= tmp
;
1706 /* Helper function for s390_emit_compare. If possible emit a 64 bit
1707 FP compare using the single element variant of vector instructions.
1708 Replace CODE with the comparison code to be used in the CC reg
1709 compare and return the condition code register RTX in CC. */
1712 s390_expand_vec_compare_scalar (enum rtx_code
*code
, rtx cmp1
, rtx cmp2
,
1715 machine_mode cmp_mode
;
1716 bool swap_p
= false;
1720 case EQ
: cmp_mode
= CCVEQmode
; break;
1721 case NE
: cmp_mode
= CCVEQmode
; break;
1722 case GT
: cmp_mode
= CCVFHmode
; break;
1723 case GE
: cmp_mode
= CCVFHEmode
; break;
1724 case UNLE
: cmp_mode
= CCVFHmode
; break;
1725 case UNLT
: cmp_mode
= CCVFHEmode
; break;
1726 case LT
: cmp_mode
= CCVFHmode
; *code
= GT
; swap_p
= true; break;
1727 case LE
: cmp_mode
= CCVFHEmode
; *code
= GE
; swap_p
= true; break;
1728 case UNGE
: cmp_mode
= CCVFHmode
; *code
= UNLE
; swap_p
= true; break;
1729 case UNGT
: cmp_mode
= CCVFHEmode
; *code
= UNLT
; swap_p
= true; break;
1730 default: return false;
1739 *cc
= gen_rtx_REG (cmp_mode
, CC_REGNUM
);
1740 emit_insn (gen_rtx_PARALLEL (VOIDmode
,
1743 gen_rtx_COMPARE (cmp_mode
, cmp1
,
1745 gen_rtx_CLOBBER (VOIDmode
,
1746 gen_rtx_SCRATCH (V2DImode
)))));
1751 /* Emit a compare instruction suitable to implement the comparison
1752 OP0 CODE OP1. Return the correct condition RTL to be placed in
1753 the IF_THEN_ELSE of the conditional branch testing the result. */
1756 s390_emit_compare (enum rtx_code code
, rtx op0
, rtx op1
)
1758 machine_mode mode
= s390_select_ccmode (code
, op0
, op1
);
1762 && register_operand (op0
, DFmode
)
1763 && register_operand (op1
, DFmode
)
1764 && s390_expand_vec_compare_scalar (&code
, op0
, op1
, &cc
))
1766 /* Work has been done by s390_expand_vec_compare_scalar already. */
1768 else if (GET_MODE_CLASS (GET_MODE (op0
)) == MODE_CC
)
1770 /* Do not output a redundant compare instruction if a
1771 compare_and_swap pattern already computed the result and the
1772 machine modes are compatible. */
1773 gcc_assert (s390_cc_modes_compatible (GET_MODE (op0
), mode
)
1779 cc
= gen_rtx_REG (mode
, CC_REGNUM
);
1780 emit_insn (gen_rtx_SET (cc
, gen_rtx_COMPARE (mode
, op0
, op1
)));
1783 return gen_rtx_fmt_ee (code
, VOIDmode
, cc
, const0_rtx
);
1786 /* Emit a SImode compare and swap instruction setting MEM to NEW_RTX if OLD
1788 Return the correct condition RTL to be placed in the IF_THEN_ELSE of the
1789 conditional branch testing the result. */
1792 s390_emit_compare_and_swap (enum rtx_code code
, rtx old
, rtx mem
,
1793 rtx cmp
, rtx new_rtx
)
1795 emit_insn (gen_atomic_compare_and_swapsi_internal (old
, mem
, cmp
, new_rtx
));
1796 return s390_emit_compare (code
, gen_rtx_REG (CCZ1mode
, CC_REGNUM
),
1800 /* Emit a jump instruction to TARGET and return it. If COND is
1801 NULL_RTX, emit an unconditional jump, else a conditional jump under
1805 s390_emit_jump (rtx target
, rtx cond
)
1809 target
= gen_rtx_LABEL_REF (VOIDmode
, target
);
1811 target
= gen_rtx_IF_THEN_ELSE (VOIDmode
, cond
, target
, pc_rtx
);
1813 insn
= gen_rtx_SET (pc_rtx
, target
);
1814 return emit_jump_insn (insn
);
1817 /* Return branch condition mask to implement a branch
1818 specified by CODE. Return -1 for invalid comparisons. */
1821 s390_branch_condition_mask (rtx code
)
1823 const int CC0
= 1 << 3;
1824 const int CC1
= 1 << 2;
1825 const int CC2
= 1 << 1;
1826 const int CC3
= 1 << 0;
1828 gcc_assert (GET_CODE (XEXP (code
, 0)) == REG
);
1829 gcc_assert (REGNO (XEXP (code
, 0)) == CC_REGNUM
);
1830 gcc_assert (XEXP (code
, 1) == const0_rtx
1831 || (GET_MODE (XEXP (code
, 0)) == CCRAWmode
1832 && CONST_INT_P (XEXP (code
, 1))));
1835 switch (GET_MODE (XEXP (code
, 0)))
1839 switch (GET_CODE (code
))
1841 case EQ
: return CC0
;
1842 case NE
: return CC1
| CC2
| CC3
;
1848 switch (GET_CODE (code
))
1850 case EQ
: return CC1
;
1851 case NE
: return CC0
| CC2
| CC3
;
1857 switch (GET_CODE (code
))
1859 case EQ
: return CC2
;
1860 case NE
: return CC0
| CC1
| CC3
;
1866 switch (GET_CODE (code
))
1868 case EQ
: return CC3
;
1869 case NE
: return CC0
| CC1
| CC2
;
1875 switch (GET_CODE (code
))
1877 case EQ
: return CC0
| CC2
;
1878 case NE
: return CC1
| CC3
;
1884 switch (GET_CODE (code
))
1886 case LTU
: return CC2
| CC3
; /* carry */
1887 case GEU
: return CC0
| CC1
; /* no carry */
1893 switch (GET_CODE (code
))
1895 case GTU
: return CC0
| CC1
; /* borrow */
1896 case LEU
: return CC2
| CC3
; /* no borrow */
1902 switch (GET_CODE (code
))
1904 case EQ
: return CC0
| CC2
;
1905 case NE
: return CC1
| CC3
;
1906 case LTU
: return CC1
;
1907 case GTU
: return CC3
;
1908 case LEU
: return CC1
| CC2
;
1909 case GEU
: return CC2
| CC3
;
1914 switch (GET_CODE (code
))
1916 case EQ
: return CC0
;
1917 case NE
: return CC1
| CC2
| CC3
;
1918 case LTU
: return CC1
;
1919 case GTU
: return CC2
;
1920 case LEU
: return CC0
| CC1
;
1921 case GEU
: return CC0
| CC2
;
1927 switch (GET_CODE (code
))
1929 case EQ
: return CC0
;
1930 case NE
: return CC2
| CC1
| CC3
;
1931 case LTU
: return CC2
;
1932 case GTU
: return CC1
;
1933 case LEU
: return CC0
| CC2
;
1934 case GEU
: return CC0
| CC1
;
1940 switch (GET_CODE (code
))
1942 case EQ
: return CC0
;
1943 case NE
: return CC1
| CC2
| CC3
;
1944 case LT
: return CC1
| CC3
;
1945 case GT
: return CC2
;
1946 case LE
: return CC0
| CC1
| CC3
;
1947 case GE
: return CC0
| CC2
;
1953 switch (GET_CODE (code
))
1955 case EQ
: return CC0
;
1956 case NE
: return CC1
| CC2
| CC3
;
1957 case LT
: return CC1
;
1958 case GT
: return CC2
| CC3
;
1959 case LE
: return CC0
| CC1
;
1960 case GE
: return CC0
| CC2
| CC3
;
1966 switch (GET_CODE (code
))
1968 case EQ
: return CC0
;
1969 case NE
: return CC1
| CC2
| CC3
;
1970 case LT
: return CC1
;
1971 case GT
: return CC2
;
1972 case LE
: return CC0
| CC1
;
1973 case GE
: return CC0
| CC2
;
1974 case UNORDERED
: return CC3
;
1975 case ORDERED
: return CC0
| CC1
| CC2
;
1976 case UNEQ
: return CC0
| CC3
;
1977 case UNLT
: return CC1
| CC3
;
1978 case UNGT
: return CC2
| CC3
;
1979 case UNLE
: return CC0
| CC1
| CC3
;
1980 case UNGE
: return CC0
| CC2
| CC3
;
1981 case LTGT
: return CC1
| CC2
;
1987 switch (GET_CODE (code
))
1989 case EQ
: return CC0
;
1990 case NE
: return CC2
| CC1
| CC3
;
1991 case LT
: return CC2
;
1992 case GT
: return CC1
;
1993 case LE
: return CC0
| CC2
;
1994 case GE
: return CC0
| CC1
;
1995 case UNORDERED
: return CC3
;
1996 case ORDERED
: return CC0
| CC2
| CC1
;
1997 case UNEQ
: return CC0
| CC3
;
1998 case UNLT
: return CC2
| CC3
;
1999 case UNGT
: return CC1
| CC3
;
2000 case UNLE
: return CC0
| CC2
| CC3
;
2001 case UNGE
: return CC0
| CC1
| CC3
;
2002 case LTGT
: return CC2
| CC1
;
2007 /* Vector comparison modes. */
2010 switch (GET_CODE (code
))
2012 case EQ
: return CC0
;
2013 case NE
: return CC3
;
2018 switch (GET_CODE (code
))
2020 case EQ
: return CC0
| CC1
;
2021 case NE
: return CC3
| CC1
;
2025 /* Integer vector compare modes. */
2028 switch (GET_CODE (code
))
2030 case GT
: return CC0
;
2031 case LE
: return CC3
;
2036 switch (GET_CODE (code
))
2038 case GT
: return CC0
| CC1
;
2039 case LE
: return CC3
| CC1
;
2044 switch (GET_CODE (code
))
2046 case GTU
: return CC0
;
2047 case LEU
: return CC3
;
2052 switch (GET_CODE (code
))
2054 case GTU
: return CC0
| CC1
;
2055 case LEU
: return CC3
| CC1
;
2059 /* FP vector compare modes. */
2062 switch (GET_CODE (code
))
2064 case GT
: return CC0
;
2065 case UNLE
: return CC3
;
2070 switch (GET_CODE (code
))
2072 case GT
: return CC0
| CC1
;
2073 case UNLE
: return CC3
| CC1
;
2078 switch (GET_CODE (code
))
2080 case GE
: return CC0
;
2081 case UNLT
: return CC3
;
2086 switch (GET_CODE (code
))
2088 case GE
: return CC0
| CC1
;
2089 case UNLT
: return CC3
| CC1
;
2095 switch (GET_CODE (code
))
2098 return INTVAL (XEXP (code
, 1));
2100 return (INTVAL (XEXP (code
, 1))) ^ 0xf;
2111 /* Return branch condition mask to implement a compare and branch
2112 specified by CODE. Return -1 for invalid comparisons. */
2115 s390_compare_and_branch_condition_mask (rtx code
)
2117 const int CC0
= 1 << 3;
2118 const int CC1
= 1 << 2;
2119 const int CC2
= 1 << 1;
2121 switch (GET_CODE (code
))
2145 /* If INV is false, return assembler mnemonic string to implement
2146 a branch specified by CODE. If INV is true, return mnemonic
2147 for the corresponding inverted branch. */
2150 s390_branch_condition_mnemonic (rtx code
, int inv
)
2154 static const char *const mnemonic
[16] =
2156 NULL
, "o", "h", "nle",
2157 "l", "nhe", "lh", "ne",
2158 "e", "nlh", "he", "nl",
2159 "le", "nh", "no", NULL
2162 if (GET_CODE (XEXP (code
, 0)) == REG
2163 && REGNO (XEXP (code
, 0)) == CC_REGNUM
2164 && (XEXP (code
, 1) == const0_rtx
2165 || (GET_MODE (XEXP (code
, 0)) == CCRAWmode
2166 && CONST_INT_P (XEXP (code
, 1)))))
2167 mask
= s390_branch_condition_mask (code
);
2169 mask
= s390_compare_and_branch_condition_mask (code
);
2171 gcc_assert (mask
>= 0);
2176 gcc_assert (mask
>= 1 && mask
<= 14);
2178 return mnemonic
[mask
];
2181 /* Return the part of op which has a value different from def.
2182 The size of the part is determined by mode.
2183 Use this function only if you already know that op really
2184 contains such a part. */
2186 unsigned HOST_WIDE_INT
2187 s390_extract_part (rtx op
, machine_mode mode
, int def
)
2189 unsigned HOST_WIDE_INT value
= 0;
2190 int max_parts
= HOST_BITS_PER_WIDE_INT
/ GET_MODE_BITSIZE (mode
);
2191 int part_bits
= GET_MODE_BITSIZE (mode
);
2192 unsigned HOST_WIDE_INT part_mask
2193 = ((unsigned HOST_WIDE_INT
)1 << part_bits
) - 1;
2196 for (i
= 0; i
< max_parts
; i
++)
2199 value
= (unsigned HOST_WIDE_INT
) INTVAL (op
);
2201 value
>>= part_bits
;
2203 if ((value
& part_mask
) != (def
& part_mask
))
2204 return value
& part_mask
;
2210 /* If OP is an integer constant of mode MODE with exactly one
2211 part of mode PART_MODE unequal to DEF, return the number of that
2212 part. Otherwise, return -1. */
2215 s390_single_part (rtx op
,
2217 machine_mode part_mode
,
2220 unsigned HOST_WIDE_INT value
= 0;
2221 int n_parts
= GET_MODE_SIZE (mode
) / GET_MODE_SIZE (part_mode
);
2222 unsigned HOST_WIDE_INT part_mask
2223 = ((unsigned HOST_WIDE_INT
)1 << GET_MODE_BITSIZE (part_mode
)) - 1;
2226 if (GET_CODE (op
) != CONST_INT
)
2229 for (i
= 0; i
< n_parts
; i
++)
2232 value
= (unsigned HOST_WIDE_INT
) INTVAL (op
);
2234 value
>>= GET_MODE_BITSIZE (part_mode
);
2236 if ((value
& part_mask
) != (def
& part_mask
))
2244 return part
== -1 ? -1 : n_parts
- 1 - part
;
2247 /* Return true if IN contains a contiguous bitfield in the lower SIZE
2248 bits and no other bits are set in IN. POS and LENGTH can be used
2249 to obtain the start position and the length of the bitfield.
2251 POS gives the position of the first bit of the bitfield counting
2252 from the lowest order bit starting with zero. In order to use this
2253 value for S/390 instructions this has to be converted to "bits big
2257 s390_contiguous_bitmask_p (unsigned HOST_WIDE_INT in
, int size
,
2258 int *pos
, int *length
)
2263 unsigned HOST_WIDE_INT mask
= 1ULL;
2264 bool contiguous
= false;
2266 for (i
= 0; i
< size
; mask
<<= 1, i
++)
2290 /* Calculate a mask for all bits beyond the contiguous bits. */
2291 mask
= (-1LL & ~(((1ULL << (tmp_length
+ tmp_pos
- 1)) << 1) - 1));
2293 if ((unsigned)size
< sizeof (HOST_WIDE_INT
) * BITS_PER_UNIT
)
2294 mask
&= (HOST_WIDE_INT_1U
<< size
) - 1;
2299 if (tmp_length
+ tmp_pos
- 1 > size
)
2303 *length
= tmp_length
;
2311 /* Return true if OP contains the same contiguous bitfield in *all*
2312 its elements. START and END can be used to obtain the start and
2313 end position of the bitfield.
2315 START/STOP give the position of the first/last bit of the bitfield
2316 counting from the lowest order bit starting with zero. In order to
2317 use these values for S/390 instructions this has to be converted to
2318 "bits big endian" style. */
2321 s390_contiguous_bitmask_vector_p (rtx op
, int *start
, int *end
)
2323 unsigned HOST_WIDE_INT mask
;
2327 if (!const_vec_duplicate_p (op
, &elt
)
2328 || !CONST_INT_P (elt
))
2331 size
= GET_MODE_UNIT_BITSIZE (GET_MODE (op
));
2333 /* We cannot deal with V1TI/V1TF. This would require a vgmq. */
2337 mask
= UINTVAL (elt
);
2338 if (s390_contiguous_bitmask_p (mask
, size
, start
,
2339 end
!= NULL
? &length
: NULL
))
2342 *end
= *start
+ length
- 1;
2345 /* 0xff00000f style immediates can be covered by swapping start and
2346 end indices in vgm. */
2347 if (s390_contiguous_bitmask_p (~mask
, size
, start
,
2348 end
!= NULL
? &length
: NULL
))
2353 *start
= *start
+ length
;
2359 /* Return true if C consists only of byte chunks being either 0 or
2360 0xff. If MASK is !=NULL a byte mask is generated which is
2361 appropriate for the vector generate byte mask instruction. */
2364 s390_bytemask_vector_p (rtx op
, unsigned *mask
)
2367 unsigned tmp_mask
= 0;
2368 int nunit
, unit_size
;
2370 if (!VECTOR_MODE_P (GET_MODE (op
))
2371 || GET_CODE (op
) != CONST_VECTOR
2372 || !CONST_INT_P (XVECEXP (op
, 0, 0)))
2375 nunit
= GET_MODE_NUNITS (GET_MODE (op
));
2376 unit_size
= GET_MODE_UNIT_SIZE (GET_MODE (op
));
2378 for (i
= 0; i
< nunit
; i
++)
2380 unsigned HOST_WIDE_INT c
;
2383 if (!CONST_INT_P (XVECEXP (op
, 0, i
)))
2386 c
= UINTVAL (XVECEXP (op
, 0, i
));
2387 for (j
= 0; j
< unit_size
; j
++)
2389 if ((c
& 0xff) != 0 && (c
& 0xff) != 0xff)
2391 tmp_mask
|= (c
& 1) << ((nunit
- 1 - i
) * unit_size
+ j
);
2392 c
= c
>> BITS_PER_UNIT
;
2402 /* Check whether a rotate of ROTL followed by an AND of CONTIG is
2403 equivalent to a shift followed by the AND. In particular, CONTIG
2404 should not overlap the (rotated) bit 0/bit 63 gap. Negative values
2405 for ROTL indicate a rotate to the right. */
2408 s390_extzv_shift_ok (int bitsize
, int rotl
, unsigned HOST_WIDE_INT contig
)
2413 ok
= s390_contiguous_bitmask_p (contig
, bitsize
, &pos
, &len
);
2416 return ((rotl
>= 0 && rotl
<= pos
)
2417 || (rotl
< 0 && -rotl
<= bitsize
- len
- pos
));
2420 /* Check whether we can (and want to) split a double-word
2421 move in mode MODE from SRC to DST into two single-word
2422 moves, moving the subword FIRST_SUBWORD first. */
2425 s390_split_ok_p (rtx dst
, rtx src
, machine_mode mode
, int first_subword
)
2427 /* Floating point and vector registers cannot be split. */
2428 if (FP_REG_P (src
) || FP_REG_P (dst
) || VECTOR_REG_P (src
) || VECTOR_REG_P (dst
))
2431 /* We don't need to split if operands are directly accessible. */
2432 if (s_operand (src
, mode
) || s_operand (dst
, mode
))
2435 /* Non-offsettable memory references cannot be split. */
2436 if ((GET_CODE (src
) == MEM
&& !offsettable_memref_p (src
))
2437 || (GET_CODE (dst
) == MEM
&& !offsettable_memref_p (dst
)))
2440 /* Moving the first subword must not clobber a register
2441 needed to move the second subword. */
2442 if (register_operand (dst
, mode
))
2444 rtx subreg
= operand_subword (dst
, first_subword
, 0, mode
);
2445 if (reg_overlap_mentioned_p (subreg
, src
))
2452 /* Return true if it can be proven that [MEM1, MEM1 + SIZE]
2453 and [MEM2, MEM2 + SIZE] do overlap and false
2457 s390_overlap_p (rtx mem1
, rtx mem2
, HOST_WIDE_INT size
)
2459 rtx addr1
, addr2
, addr_delta
;
2460 HOST_WIDE_INT delta
;
2462 if (GET_CODE (mem1
) != MEM
|| GET_CODE (mem2
) != MEM
)
2468 addr1
= XEXP (mem1
, 0);
2469 addr2
= XEXP (mem2
, 0);
2471 addr_delta
= simplify_binary_operation (MINUS
, Pmode
, addr2
, addr1
);
2473 /* This overlapping check is used by peepholes merging memory block operations.
2474 Overlapping operations would otherwise be recognized by the S/390 hardware
2475 and would fall back to a slower implementation. Allowing overlapping
2476 operations would lead to slow code but not to wrong code. Therefore we are
2477 somewhat optimistic if we cannot prove that the memory blocks are
2479 That's why we return false here although this may accept operations on
2480 overlapping memory areas. */
2481 if (!addr_delta
|| GET_CODE (addr_delta
) != CONST_INT
)
2484 delta
= INTVAL (addr_delta
);
2487 || (delta
> 0 && delta
< size
)
2488 || (delta
< 0 && -delta
< size
))
2494 /* Check whether the address of memory reference MEM2 equals exactly
2495 the address of memory reference MEM1 plus DELTA. Return true if
2496 we can prove this to be the case, false otherwise. */
2499 s390_offset_p (rtx mem1
, rtx mem2
, rtx delta
)
2501 rtx addr1
, addr2
, addr_delta
;
2503 if (GET_CODE (mem1
) != MEM
|| GET_CODE (mem2
) != MEM
)
2506 addr1
= XEXP (mem1
, 0);
2507 addr2
= XEXP (mem2
, 0);
2509 addr_delta
= simplify_binary_operation (MINUS
, Pmode
, addr2
, addr1
);
2510 if (!addr_delta
|| !rtx_equal_p (addr_delta
, delta
))
2516 /* Expand logical operator CODE in mode MODE with operands OPERANDS. */
2519 s390_expand_logical_operator (enum rtx_code code
, machine_mode mode
,
2522 machine_mode wmode
= mode
;
2523 rtx dst
= operands
[0];
2524 rtx src1
= operands
[1];
2525 rtx src2
= operands
[2];
2528 /* If we cannot handle the operation directly, use a temp register. */
2529 if (!s390_logical_operator_ok_p (operands
))
2530 dst
= gen_reg_rtx (mode
);
2532 /* QImode and HImode patterns make sense only if we have a destination
2533 in memory. Otherwise perform the operation in SImode. */
2534 if ((mode
== QImode
|| mode
== HImode
) && GET_CODE (dst
) != MEM
)
2537 /* Widen operands if required. */
2540 if (GET_CODE (dst
) == SUBREG
2541 && (tem
= simplify_subreg (wmode
, dst
, mode
, 0)) != 0)
2543 else if (REG_P (dst
))
2544 dst
= gen_rtx_SUBREG (wmode
, dst
, 0);
2546 dst
= gen_reg_rtx (wmode
);
2548 if (GET_CODE (src1
) == SUBREG
2549 && (tem
= simplify_subreg (wmode
, src1
, mode
, 0)) != 0)
2551 else if (GET_MODE (src1
) != VOIDmode
)
2552 src1
= gen_rtx_SUBREG (wmode
, force_reg (mode
, src1
), 0);
2554 if (GET_CODE (src2
) == SUBREG
2555 && (tem
= simplify_subreg (wmode
, src2
, mode
, 0)) != 0)
2557 else if (GET_MODE (src2
) != VOIDmode
)
2558 src2
= gen_rtx_SUBREG (wmode
, force_reg (mode
, src2
), 0);
2561 /* Emit the instruction. */
2562 op
= gen_rtx_SET (dst
, gen_rtx_fmt_ee (code
, wmode
, src1
, src2
));
2563 clob
= gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
2564 emit_insn (gen_rtx_PARALLEL (VOIDmode
, gen_rtvec (2, op
, clob
)));
2566 /* Fix up the destination if needed. */
2567 if (dst
!= operands
[0])
2568 emit_move_insn (operands
[0], gen_lowpart (mode
, dst
));
2571 /* Check whether OPERANDS are OK for a logical operation (AND, IOR, XOR). */
2574 s390_logical_operator_ok_p (rtx
*operands
)
2576 /* If the destination operand is in memory, it needs to coincide
2577 with one of the source operands. After reload, it has to be
2578 the first source operand. */
2579 if (GET_CODE (operands
[0]) == MEM
)
2580 return rtx_equal_p (operands
[0], operands
[1])
2581 || (!reload_completed
&& rtx_equal_p (operands
[0], operands
[2]));
2586 /* Narrow logical operation CODE of memory operand MEMOP with immediate
2587 operand IMMOP to switch from SS to SI type instructions. */
2590 s390_narrow_logical_operator (enum rtx_code code
, rtx
*memop
, rtx
*immop
)
2592 int def
= code
== AND
? -1 : 0;
2596 gcc_assert (GET_CODE (*memop
) == MEM
);
2597 gcc_assert (!MEM_VOLATILE_P (*memop
));
2599 mask
= s390_extract_part (*immop
, QImode
, def
);
2600 part
= s390_single_part (*immop
, GET_MODE (*memop
), QImode
, def
);
2601 gcc_assert (part
>= 0);
2603 *memop
= adjust_address (*memop
, QImode
, part
);
2604 *immop
= gen_int_mode (mask
, QImode
);
2608 /* How to allocate a 'struct machine_function'. */
2610 static struct machine_function
*
2611 s390_init_machine_status (void)
2613 return ggc_cleared_alloc
<machine_function
> ();
2616 /* Map for smallest class containing reg regno. */
2618 const enum reg_class regclass_map
[FIRST_PSEUDO_REGISTER
] =
2619 { GENERAL_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, /* 0 */
2620 ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, /* 4 */
2621 ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, /* 8 */
2622 ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, /* 12 */
2623 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
, /* 16 */
2624 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
, /* 20 */
2625 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
, /* 24 */
2626 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
, /* 28 */
2627 ADDR_REGS
, CC_REGS
, ADDR_REGS
, ADDR_REGS
, /* 32 */
2628 ACCESS_REGS
, ACCESS_REGS
, VEC_REGS
, VEC_REGS
, /* 36 */
2629 VEC_REGS
, VEC_REGS
, VEC_REGS
, VEC_REGS
, /* 40 */
2630 VEC_REGS
, VEC_REGS
, VEC_REGS
, VEC_REGS
, /* 44 */
2631 VEC_REGS
, VEC_REGS
, VEC_REGS
, VEC_REGS
, /* 48 */
2632 VEC_REGS
, VEC_REGS
/* 52 */
2635 /* Return attribute type of insn. */
2637 static enum attr_type
2638 s390_safe_attr_type (rtx_insn
*insn
)
2640 if (recog_memoized (insn
) >= 0)
2641 return get_attr_type (insn
);
2646 /* Return true if DISP is a valid short displacement. */
2649 s390_short_displacement (rtx disp
)
2651 /* No displacement is OK. */
2655 /* Without the long displacement facility we don't need to
2656 distingiush between long and short displacement. */
2657 if (!TARGET_LONG_DISPLACEMENT
)
2660 /* Integer displacement in range. */
2661 if (GET_CODE (disp
) == CONST_INT
)
2662 return INTVAL (disp
) >= 0 && INTVAL (disp
) < 4096;
2664 /* GOT offset is not OK, the GOT can be large. */
2665 if (GET_CODE (disp
) == CONST
2666 && GET_CODE (XEXP (disp
, 0)) == UNSPEC
2667 && (XINT (XEXP (disp
, 0), 1) == UNSPEC_GOT
2668 || XINT (XEXP (disp
, 0), 1) == UNSPEC_GOTNTPOFF
))
2671 /* All other symbolic constants are literal pool references,
2672 which are OK as the literal pool must be small. */
2673 if (GET_CODE (disp
) == CONST
)
2679 /* Decompose a RTL expression ADDR for a memory address into
2680 its components, returned in OUT.
2682 Returns false if ADDR is not a valid memory address, true
2683 otherwise. If OUT is NULL, don't return the components,
2684 but check for validity only.
2686 Note: Only addresses in canonical form are recognized.
2687 LEGITIMIZE_ADDRESS should convert non-canonical forms to the
2688 canonical form so that they will be recognized. */
2691 s390_decompose_address (rtx addr
, struct s390_address
*out
)
2693 HOST_WIDE_INT offset
= 0;
2694 rtx base
= NULL_RTX
;
2695 rtx indx
= NULL_RTX
;
2696 rtx disp
= NULL_RTX
;
2698 bool pointer
= false;
2699 bool base_ptr
= false;
2700 bool indx_ptr
= false;
2701 bool literal_pool
= false;
2703 /* We may need to substitute the literal pool base register into the address
2704 below. However, at this point we do not know which register is going to
2705 be used as base, so we substitute the arg pointer register. This is going
2706 to be treated as holding a pointer below -- it shouldn't be used for any
2708 rtx fake_pool_base
= gen_rtx_REG (Pmode
, ARG_POINTER_REGNUM
);
2710 /* Decompose address into base + index + displacement. */
2712 if (GET_CODE (addr
) == REG
|| GET_CODE (addr
) == UNSPEC
)
2715 else if (GET_CODE (addr
) == PLUS
)
2717 rtx op0
= XEXP (addr
, 0);
2718 rtx op1
= XEXP (addr
, 1);
2719 enum rtx_code code0
= GET_CODE (op0
);
2720 enum rtx_code code1
= GET_CODE (op1
);
2722 if (code0
== REG
|| code0
== UNSPEC
)
2724 if (code1
== REG
|| code1
== UNSPEC
)
2726 indx
= op0
; /* index + base */
2732 base
= op0
; /* base + displacement */
2737 else if (code0
== PLUS
)
2739 indx
= XEXP (op0
, 0); /* index + base + disp */
2740 base
= XEXP (op0
, 1);
2751 disp
= addr
; /* displacement */
2753 /* Extract integer part of displacement. */
2757 if (GET_CODE (disp
) == CONST_INT
)
2759 offset
= INTVAL (disp
);
2762 else if (GET_CODE (disp
) == CONST
2763 && GET_CODE (XEXP (disp
, 0)) == PLUS
2764 && GET_CODE (XEXP (XEXP (disp
, 0), 1)) == CONST_INT
)
2766 offset
= INTVAL (XEXP (XEXP (disp
, 0), 1));
2767 disp
= XEXP (XEXP (disp
, 0), 0);
2771 /* Strip off CONST here to avoid special case tests later. */
2772 if (disp
&& GET_CODE (disp
) == CONST
)
2773 disp
= XEXP (disp
, 0);
2775 /* We can convert literal pool addresses to
2776 displacements by basing them off the base register. */
2777 if (disp
&& GET_CODE (disp
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (disp
))
2779 /* Either base or index must be free to hold the base register. */
2781 base
= fake_pool_base
, literal_pool
= true;
2783 indx
= fake_pool_base
, literal_pool
= true;
2787 /* Mark up the displacement. */
2788 disp
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, disp
),
2789 UNSPEC_LTREL_OFFSET
);
2792 /* Validate base register. */
2795 if (GET_CODE (base
) == UNSPEC
)
2796 switch (XINT (base
, 1))
2800 disp
= gen_rtx_UNSPEC (Pmode
,
2801 gen_rtvec (1, XVECEXP (base
, 0, 0)),
2802 UNSPEC_LTREL_OFFSET
);
2806 base
= XVECEXP (base
, 0, 1);
2809 case UNSPEC_LTREL_BASE
:
2810 if (XVECLEN (base
, 0) == 1)
2811 base
= fake_pool_base
, literal_pool
= true;
2813 base
= XVECEXP (base
, 0, 1);
2820 if (!REG_P (base
) || GET_MODE (base
) != Pmode
)
2823 if (REGNO (base
) == STACK_POINTER_REGNUM
2824 || REGNO (base
) == FRAME_POINTER_REGNUM
2825 || ((reload_completed
|| reload_in_progress
)
2826 && frame_pointer_needed
2827 && REGNO (base
) == HARD_FRAME_POINTER_REGNUM
)
2828 || REGNO (base
) == ARG_POINTER_REGNUM
2830 && REGNO (base
) == PIC_OFFSET_TABLE_REGNUM
))
2831 pointer
= base_ptr
= true;
2833 if ((reload_completed
|| reload_in_progress
)
2834 && base
== cfun
->machine
->base_reg
)
2835 pointer
= base_ptr
= literal_pool
= true;
2838 /* Validate index register. */
2841 if (GET_CODE (indx
) == UNSPEC
)
2842 switch (XINT (indx
, 1))
2846 disp
= gen_rtx_UNSPEC (Pmode
,
2847 gen_rtvec (1, XVECEXP (indx
, 0, 0)),
2848 UNSPEC_LTREL_OFFSET
);
2852 indx
= XVECEXP (indx
, 0, 1);
2855 case UNSPEC_LTREL_BASE
:
2856 if (XVECLEN (indx
, 0) == 1)
2857 indx
= fake_pool_base
, literal_pool
= true;
2859 indx
= XVECEXP (indx
, 0, 1);
2866 if (!REG_P (indx
) || GET_MODE (indx
) != Pmode
)
2869 if (REGNO (indx
) == STACK_POINTER_REGNUM
2870 || REGNO (indx
) == FRAME_POINTER_REGNUM
2871 || ((reload_completed
|| reload_in_progress
)
2872 && frame_pointer_needed
2873 && REGNO (indx
) == HARD_FRAME_POINTER_REGNUM
)
2874 || REGNO (indx
) == ARG_POINTER_REGNUM
2876 && REGNO (indx
) == PIC_OFFSET_TABLE_REGNUM
))
2877 pointer
= indx_ptr
= true;
2879 if ((reload_completed
|| reload_in_progress
)
2880 && indx
== cfun
->machine
->base_reg
)
2881 pointer
= indx_ptr
= literal_pool
= true;
2884 /* Prefer to use pointer as base, not index. */
2885 if (base
&& indx
&& !base_ptr
2886 && (indx_ptr
|| (!REG_POINTER (base
) && REG_POINTER (indx
))))
2893 /* Validate displacement. */
2896 /* If virtual registers are involved, the displacement will change later
2897 anyway as the virtual registers get eliminated. This could make a
2898 valid displacement invalid, but it is more likely to make an invalid
2899 displacement valid, because we sometimes access the register save area
2900 via negative offsets to one of those registers.
2901 Thus we don't check the displacement for validity here. If after
2902 elimination the displacement turns out to be invalid after all,
2903 this is fixed up by reload in any case. */
2904 /* LRA maintains always displacements up to date and we need to
2905 know the displacement is right during all LRA not only at the
2906 final elimination. */
2908 || (base
!= arg_pointer_rtx
2909 && indx
!= arg_pointer_rtx
2910 && base
!= return_address_pointer_rtx
2911 && indx
!= return_address_pointer_rtx
2912 && base
!= frame_pointer_rtx
2913 && indx
!= frame_pointer_rtx
2914 && base
!= virtual_stack_vars_rtx
2915 && indx
!= virtual_stack_vars_rtx
))
2916 if (!DISP_IN_RANGE (offset
))
2921 /* All the special cases are pointers. */
2924 /* In the small-PIC case, the linker converts @GOT
2925 and @GOTNTPOFF offsets to possible displacements. */
2926 if (GET_CODE (disp
) == UNSPEC
2927 && (XINT (disp
, 1) == UNSPEC_GOT
2928 || XINT (disp
, 1) == UNSPEC_GOTNTPOFF
)
2934 /* Accept pool label offsets. */
2935 else if (GET_CODE (disp
) == UNSPEC
2936 && XINT (disp
, 1) == UNSPEC_POOL_OFFSET
)
2939 /* Accept literal pool references. */
2940 else if (GET_CODE (disp
) == UNSPEC
2941 && XINT (disp
, 1) == UNSPEC_LTREL_OFFSET
)
2943 /* In case CSE pulled a non literal pool reference out of
2944 the pool we have to reject the address. This is
2945 especially important when loading the GOT pointer on non
2946 zarch CPUs. In this case the literal pool contains an lt
2947 relative offset to the _GLOBAL_OFFSET_TABLE_ label which
2948 will most likely exceed the displacement. */
2949 if (GET_CODE (XVECEXP (disp
, 0, 0)) != SYMBOL_REF
2950 || !CONSTANT_POOL_ADDRESS_P (XVECEXP (disp
, 0, 0)))
2953 orig_disp
= gen_rtx_CONST (Pmode
, disp
);
2956 /* If we have an offset, make sure it does not
2957 exceed the size of the constant pool entry. */
2958 rtx sym
= XVECEXP (disp
, 0, 0);
2959 if (offset
>= GET_MODE_SIZE (get_pool_mode (sym
)))
2962 orig_disp
= plus_constant (Pmode
, orig_disp
, offset
);
2977 out
->disp
= orig_disp
;
2978 out
->pointer
= pointer
;
2979 out
->literal_pool
= literal_pool
;
2985 /* Decompose a RTL expression OP for an address style operand into its
2986 components, and return the base register in BASE and the offset in
2987 OFFSET. While OP looks like an address it is never supposed to be
2990 Return true if OP is a valid address operand, false if not. */
2993 s390_decompose_addrstyle_without_index (rtx op
, rtx
*base
,
2994 HOST_WIDE_INT
*offset
)
2998 /* We can have an integer constant, an address register,
2999 or a sum of the two. */
3000 if (CONST_SCALAR_INT_P (op
))
3005 if (op
&& GET_CODE (op
) == PLUS
&& CONST_SCALAR_INT_P (XEXP (op
, 1)))
3010 while (op
&& GET_CODE (op
) == SUBREG
)
3011 op
= SUBREG_REG (op
);
3013 if (op
&& GET_CODE (op
) != REG
)
3018 if (off
== NULL_RTX
)
3020 else if (CONST_INT_P (off
))
3021 *offset
= INTVAL (off
);
3022 else if (CONST_WIDE_INT_P (off
))
3023 /* The offset will anyway be cut down to 12 bits so take just
3024 the lowest order chunk of the wide int. */
3025 *offset
= CONST_WIDE_INT_ELT (off
, 0);
3036 /* Return true if CODE is a valid address without index. */
3039 s390_legitimate_address_without_index_p (rtx op
)
3041 struct s390_address addr
;
3043 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
3052 /* Return TRUE if ADDR is an operand valid for a load/store relative
3053 instruction. Be aware that the alignment of the operand needs to
3054 be checked separately.
3055 Valid addresses are single references or a sum of a reference and a
3056 constant integer. Return these parts in SYMREF and ADDEND. You can
3057 pass NULL in REF and/or ADDEND if you are not interested in these
3058 values. Literal pool references are *not* considered symbol
3062 s390_loadrelative_operand_p (rtx addr
, rtx
*symref
, HOST_WIDE_INT
*addend
)
3064 HOST_WIDE_INT tmpaddend
= 0;
3066 if (GET_CODE (addr
) == CONST
)
3067 addr
= XEXP (addr
, 0);
3069 if (GET_CODE (addr
) == PLUS
)
3071 if (!CONST_INT_P (XEXP (addr
, 1)))
3074 tmpaddend
= INTVAL (XEXP (addr
, 1));
3075 addr
= XEXP (addr
, 0);
3078 if ((GET_CODE (addr
) == SYMBOL_REF
&& !CONSTANT_POOL_ADDRESS_P (addr
))
3079 || (GET_CODE (addr
) == UNSPEC
3080 && (XINT (addr
, 1) == UNSPEC_GOTENT
3081 || (TARGET_CPU_ZARCH
&& XINT (addr
, 1) == UNSPEC_PLT
))))
3086 *addend
= tmpaddend
;
3093 /* Return true if the address in OP is valid for constraint letter C
3094 if wrapped in a MEM rtx. Set LIT_POOL_OK to true if it literal
3095 pool MEMs should be accepted. Only the Q, R, S, T constraint
3096 letters are allowed for C. */
3099 s390_check_qrst_address (char c
, rtx op
, bool lit_pool_ok
)
3101 struct s390_address addr
;
3102 bool decomposed
= false;
3104 /* This check makes sure that no symbolic address (except literal
3105 pool references) are accepted by the R or T constraints. */
3106 if (s390_loadrelative_operand_p (op
, NULL
, NULL
))
3109 /* Ensure literal pool references are only accepted if LIT_POOL_OK. */
3112 if (!s390_decompose_address (op
, &addr
))
3114 if (addr
.literal_pool
)
3121 case 'Q': /* no index short displacement */
3122 if (!decomposed
&& !s390_decompose_address (op
, &addr
))
3126 if (!s390_short_displacement (addr
.disp
))
3130 case 'R': /* with index short displacement */
3131 if (TARGET_LONG_DISPLACEMENT
)
3133 if (!decomposed
&& !s390_decompose_address (op
, &addr
))
3135 if (!s390_short_displacement (addr
.disp
))
3138 /* Any invalid address here will be fixed up by reload,
3139 so accept it for the most generic constraint. */
3142 case 'S': /* no index long displacement */
3143 if (!TARGET_LONG_DISPLACEMENT
)
3145 if (!decomposed
&& !s390_decompose_address (op
, &addr
))
3149 if (s390_short_displacement (addr
.disp
))
3153 case 'T': /* with index long displacement */
3154 if (!TARGET_LONG_DISPLACEMENT
)
3156 /* Any invalid address here will be fixed up by reload,
3157 so accept it for the most generic constraint. */
3158 if ((decomposed
|| s390_decompose_address (op
, &addr
))
3159 && s390_short_displacement (addr
.disp
))
3169 /* Evaluates constraint strings described by the regular expression
3170 ([A|B|Z](Q|R|S|T))|U|W|Y and returns 1 if OP is a valid operand for
3171 the constraint given in STR, or 0 else. */
3174 s390_mem_constraint (const char *str
, rtx op
)
3181 /* Check for offsettable variants of memory constraints. */
3182 if (!MEM_P (op
) || MEM_VOLATILE_P (op
))
3184 if ((reload_completed
|| reload_in_progress
)
3185 ? !offsettable_memref_p (op
) : !offsettable_nonstrict_memref_p (op
))
3187 return s390_check_qrst_address (str
[1], XEXP (op
, 0), true);
3189 /* Check for non-literal-pool variants of memory constraints. */
3192 return s390_check_qrst_address (str
[1], XEXP (op
, 0), false);
3197 if (GET_CODE (op
) != MEM
)
3199 return s390_check_qrst_address (c
, XEXP (op
, 0), true);
3201 return (s390_check_qrst_address ('Q', op
, true)
3202 || s390_check_qrst_address ('R', op
, true));
3204 return (s390_check_qrst_address ('S', op
, true)
3205 || s390_check_qrst_address ('T', op
, true));
3207 /* Simply check for the basic form of a shift count. Reload will
3208 take care of making sure we have a proper base register. */
3209 if (!s390_decompose_addrstyle_without_index (op
, NULL
, NULL
))
3213 return s390_check_qrst_address (str
[1], op
, true);
3221 /* Evaluates constraint strings starting with letter O. Input
3222 parameter C is the second letter following the "O" in the constraint
3223 string. Returns 1 if VALUE meets the respective constraint and 0
3227 s390_O_constraint_str (const char c
, HOST_WIDE_INT value
)
3235 return trunc_int_for_mode (value
, SImode
) == value
;
3239 || s390_single_part (GEN_INT (value
), DImode
, SImode
, 0) == 1;
3242 return s390_single_part (GEN_INT (value
- 1), DImode
, SImode
, -1) == 1;
3250 /* Evaluates constraint strings starting with letter N. Parameter STR
3251 contains the letters following letter "N" in the constraint string.
3252 Returns true if VALUE matches the constraint. */
3255 s390_N_constraint_str (const char *str
, HOST_WIDE_INT value
)
3257 machine_mode mode
, part_mode
;
3259 int part
, part_goal
;
3265 part_goal
= str
[0] - '0';
3309 if (GET_MODE_SIZE (mode
) <= GET_MODE_SIZE (part_mode
))
3312 part
= s390_single_part (GEN_INT (value
), mode
, part_mode
, def
);
3315 if (part_goal
!= -1 && part_goal
!= part
)
3322 /* Returns true if the input parameter VALUE is a float zero. */
3325 s390_float_const_zero_p (rtx value
)
3327 return (GET_MODE_CLASS (GET_MODE (value
)) == MODE_FLOAT
3328 && value
== CONST0_RTX (GET_MODE (value
)));
3331 /* Implement TARGET_REGISTER_MOVE_COST. */
3334 s390_register_move_cost (machine_mode mode
,
3335 reg_class_t from
, reg_class_t to
)
3337 /* On s390, copy between fprs and gprs is expensive. */
3339 /* It becomes somewhat faster having ldgr/lgdr. */
3340 if (TARGET_Z10
&& GET_MODE_SIZE (mode
) == 8)
3342 /* ldgr is single cycle. */
3343 if (reg_classes_intersect_p (from
, GENERAL_REGS
)
3344 && reg_classes_intersect_p (to
, FP_REGS
))
3346 /* lgdr needs 3 cycles. */
3347 if (reg_classes_intersect_p (to
, GENERAL_REGS
)
3348 && reg_classes_intersect_p (from
, FP_REGS
))
3352 /* Otherwise copying is done via memory. */
3353 if ((reg_classes_intersect_p (from
, GENERAL_REGS
)
3354 && reg_classes_intersect_p (to
, FP_REGS
))
3355 || (reg_classes_intersect_p (from
, FP_REGS
)
3356 && reg_classes_intersect_p (to
, GENERAL_REGS
)))
3362 /* Implement TARGET_MEMORY_MOVE_COST. */
3365 s390_memory_move_cost (machine_mode mode ATTRIBUTE_UNUSED
,
3366 reg_class_t rclass ATTRIBUTE_UNUSED
,
3367 bool in ATTRIBUTE_UNUSED
)
3372 /* Compute a (partial) cost for rtx X. Return true if the complete
3373 cost has been computed, and false if subexpressions should be
3374 scanned. In either case, *TOTAL contains the cost result.
3375 OUTER_CODE contains the code of the superexpression of x. */
3378 s390_rtx_costs (rtx x
, machine_mode mode
, int outer_code
,
3379 int opno ATTRIBUTE_UNUSED
,
3380 int *total
, bool speed ATTRIBUTE_UNUSED
)
3382 int code
= GET_CODE (x
);
3390 case CONST_WIDE_INT
:
3397 if (GET_CODE (XEXP (x
, 0)) == AND
3398 && GET_CODE (XEXP (x
, 1)) == ASHIFT
3399 && REG_P (XEXP (XEXP (x
, 0), 0))
3400 && REG_P (XEXP (XEXP (x
, 1), 0))
3401 && CONST_INT_P (XEXP (XEXP (x
, 0), 1))
3402 && CONST_INT_P (XEXP (XEXP (x
, 1), 1))
3403 && (UINTVAL (XEXP (XEXP (x
, 0), 1)) ==
3404 (1UL << UINTVAL (XEXP (XEXP (x
, 1), 1))) - 1))
3406 *total
= COSTS_N_INSNS (2);
3418 *total
= COSTS_N_INSNS (1);
3423 *total
= COSTS_N_INSNS (1);
3431 rtx left
= XEXP (x
, 0);
3432 rtx right
= XEXP (x
, 1);
3433 if (GET_CODE (right
) == CONST_INT
3434 && CONST_OK_FOR_K (INTVAL (right
)))
3435 *total
= s390_cost
->mhi
;
3436 else if (GET_CODE (left
) == SIGN_EXTEND
)
3437 *total
= s390_cost
->mh
;
3439 *total
= s390_cost
->ms
; /* msr, ms, msy */
3444 rtx left
= XEXP (x
, 0);
3445 rtx right
= XEXP (x
, 1);
3448 if (GET_CODE (right
) == CONST_INT
3449 && CONST_OK_FOR_K (INTVAL (right
)))
3450 *total
= s390_cost
->mghi
;
3451 else if (GET_CODE (left
) == SIGN_EXTEND
)
3452 *total
= s390_cost
->msgf
;
3454 *total
= s390_cost
->msg
; /* msgr, msg */
3456 else /* TARGET_31BIT */
3458 if (GET_CODE (left
) == SIGN_EXTEND
3459 && GET_CODE (right
) == SIGN_EXTEND
)
3460 /* mulsidi case: mr, m */
3461 *total
= s390_cost
->m
;
3462 else if (GET_CODE (left
) == ZERO_EXTEND
3463 && GET_CODE (right
) == ZERO_EXTEND
3464 && TARGET_CPU_ZARCH
)
3465 /* umulsidi case: ml, mlr */
3466 *total
= s390_cost
->ml
;
3468 /* Complex calculation is required. */
3469 *total
= COSTS_N_INSNS (40);
3475 *total
= s390_cost
->mult_df
;
3478 *total
= s390_cost
->mxbr
;
3489 *total
= s390_cost
->madbr
;
3492 *total
= s390_cost
->maebr
;
3497 /* Negate in the third argument is free: FMSUB. */
3498 if (GET_CODE (XEXP (x
, 2)) == NEG
)
3500 *total
+= (rtx_cost (XEXP (x
, 0), mode
, FMA
, 0, speed
)
3501 + rtx_cost (XEXP (x
, 1), mode
, FMA
, 1, speed
)
3502 + rtx_cost (XEXP (XEXP (x
, 2), 0), mode
, FMA
, 2, speed
));
3509 if (mode
== TImode
) /* 128 bit division */
3510 *total
= s390_cost
->dlgr
;
3511 else if (mode
== DImode
)
3513 rtx right
= XEXP (x
, 1);
3514 if (GET_CODE (right
) == ZERO_EXTEND
) /* 64 by 32 bit division */
3515 *total
= s390_cost
->dlr
;
3516 else /* 64 by 64 bit division */
3517 *total
= s390_cost
->dlgr
;
3519 else if (mode
== SImode
) /* 32 bit division */
3520 *total
= s390_cost
->dlr
;
3527 rtx right
= XEXP (x
, 1);
3528 if (GET_CODE (right
) == ZERO_EXTEND
) /* 64 by 32 bit division */
3530 *total
= s390_cost
->dsgfr
;
3532 *total
= s390_cost
->dr
;
3533 else /* 64 by 64 bit division */
3534 *total
= s390_cost
->dsgr
;
3536 else if (mode
== SImode
) /* 32 bit division */
3537 *total
= s390_cost
->dlr
;
3538 else if (mode
== SFmode
)
3540 *total
= s390_cost
->debr
;
3542 else if (mode
== DFmode
)
3544 *total
= s390_cost
->ddbr
;
3546 else if (mode
== TFmode
)
3548 *total
= s390_cost
->dxbr
;
3554 *total
= s390_cost
->sqebr
;
3555 else if (mode
== DFmode
)
3556 *total
= s390_cost
->sqdbr
;
3558 *total
= s390_cost
->sqxbr
;
3563 if (outer_code
== MULT
|| outer_code
== DIV
|| outer_code
== MOD
3564 || outer_code
== PLUS
|| outer_code
== MINUS
3565 || outer_code
== COMPARE
)
3570 *total
= COSTS_N_INSNS (1);
3571 if (GET_CODE (XEXP (x
, 0)) == AND
3572 && GET_CODE (XEXP (x
, 1)) == CONST_INT
3573 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
)
3575 rtx op0
= XEXP (XEXP (x
, 0), 0);
3576 rtx op1
= XEXP (XEXP (x
, 0), 1);
3577 rtx op2
= XEXP (x
, 1);
3579 if (memory_operand (op0
, GET_MODE (op0
))
3580 && s390_tm_ccmode (op1
, op2
, 0) != VOIDmode
)
3582 if (register_operand (op0
, GET_MODE (op0
))
3583 && s390_tm_ccmode (op1
, op2
, 1) != VOIDmode
)
3593 /* Return the cost of an address rtx ADDR. */
3596 s390_address_cost (rtx addr
, machine_mode mode ATTRIBUTE_UNUSED
,
3597 addr_space_t as ATTRIBUTE_UNUSED
,
3598 bool speed ATTRIBUTE_UNUSED
)
3600 struct s390_address ad
;
3601 if (!s390_decompose_address (addr
, &ad
))
3604 return ad
.indx
? COSTS_N_INSNS (1) + 1 : COSTS_N_INSNS (1);
3607 /* If OP is a SYMBOL_REF of a thread-local symbol, return its TLS mode,
3608 otherwise return 0. */
3611 tls_symbolic_operand (rtx op
)
3613 if (GET_CODE (op
) != SYMBOL_REF
)
3615 return SYMBOL_REF_TLS_MODEL (op
);
3618 /* Split DImode access register reference REG (on 64-bit) into its constituent
3619 low and high parts, and store them into LO and HI. Note that gen_lowpart/
3620 gen_highpart cannot be used as they assume all registers are word-sized,
3621 while our access registers have only half that size. */
3624 s390_split_access_reg (rtx reg
, rtx
*lo
, rtx
*hi
)
3626 gcc_assert (TARGET_64BIT
);
3627 gcc_assert (ACCESS_REG_P (reg
));
3628 gcc_assert (GET_MODE (reg
) == DImode
);
3629 gcc_assert (!(REGNO (reg
) & 1));
3631 *lo
= gen_rtx_REG (SImode
, REGNO (reg
) + 1);
3632 *hi
= gen_rtx_REG (SImode
, REGNO (reg
));
3635 /* Return true if OP contains a symbol reference */
3638 symbolic_reference_mentioned_p (rtx op
)
3643 if (GET_CODE (op
) == SYMBOL_REF
|| GET_CODE (op
) == LABEL_REF
)
3646 fmt
= GET_RTX_FORMAT (GET_CODE (op
));
3647 for (i
= GET_RTX_LENGTH (GET_CODE (op
)) - 1; i
>= 0; i
--)
3653 for (j
= XVECLEN (op
, i
) - 1; j
>= 0; j
--)
3654 if (symbolic_reference_mentioned_p (XVECEXP (op
, i
, j
)))
3658 else if (fmt
[i
] == 'e' && symbolic_reference_mentioned_p (XEXP (op
, i
)))
3665 /* Return true if OP contains a reference to a thread-local symbol. */
3668 tls_symbolic_reference_mentioned_p (rtx op
)
3673 if (GET_CODE (op
) == SYMBOL_REF
)
3674 return tls_symbolic_operand (op
);
3676 fmt
= GET_RTX_FORMAT (GET_CODE (op
));
3677 for (i
= GET_RTX_LENGTH (GET_CODE (op
)) - 1; i
>= 0; i
--)
3683 for (j
= XVECLEN (op
, i
) - 1; j
>= 0; j
--)
3684 if (tls_symbolic_reference_mentioned_p (XVECEXP (op
, i
, j
)))
3688 else if (fmt
[i
] == 'e' && tls_symbolic_reference_mentioned_p (XEXP (op
, i
)))
3696 /* Return true if OP is a legitimate general operand when
3697 generating PIC code. It is given that flag_pic is on
3698 and that OP satisfies CONSTANT_P. */
3701 legitimate_pic_operand_p (rtx op
)
3703 /* Accept all non-symbolic constants. */
3704 if (!SYMBOLIC_CONST (op
))
3707 /* Reject everything else; must be handled
3708 via emit_symbolic_move. */
3712 /* Returns true if the constant value OP is a legitimate general operand.
3713 It is given that OP satisfies CONSTANT_P. */
3716 s390_legitimate_constant_p (machine_mode mode
, rtx op
)
3718 if (TARGET_VX
&& VECTOR_MODE_P (mode
) && GET_CODE (op
) == CONST_VECTOR
)
3720 if (GET_MODE_SIZE (mode
) != 16)
3723 if (!satisfies_constraint_j00 (op
)
3724 && !satisfies_constraint_jm1 (op
)
3725 && !satisfies_constraint_jKK (op
)
3726 && !satisfies_constraint_jxx (op
)
3727 && !satisfies_constraint_jyy (op
))
3731 /* Accept all non-symbolic constants. */
3732 if (!SYMBOLIC_CONST (op
))
3735 /* Accept immediate LARL operands. */
3736 if (TARGET_CPU_ZARCH
&& larl_operand (op
, mode
))
3739 /* Thread-local symbols are never legal constants. This is
3740 so that emit_call knows that computing such addresses
3741 might require a function call. */
3742 if (TLS_SYMBOLIC_CONST (op
))
3745 /* In the PIC case, symbolic constants must *not* be
3746 forced into the literal pool. We accept them here,
3747 so that they will be handled by emit_symbolic_move. */
3751 /* All remaining non-PIC symbolic constants are
3752 forced into the literal pool. */
3756 /* Determine if it's legal to put X into the constant pool. This
3757 is not possible if X contains the address of a symbol that is
3758 not constant (TLS) or not known at final link time (PIC). */
3761 s390_cannot_force_const_mem (machine_mode mode
, rtx x
)
3763 switch (GET_CODE (x
))
3767 case CONST_WIDE_INT
:
3769 /* Accept all non-symbolic constants. */
3773 /* Labels are OK iff we are non-PIC. */
3774 return flag_pic
!= 0;
3777 /* 'Naked' TLS symbol references are never OK,
3778 non-TLS symbols are OK iff we are non-PIC. */
3779 if (tls_symbolic_operand (x
))
3782 return flag_pic
!= 0;
3785 return s390_cannot_force_const_mem (mode
, XEXP (x
, 0));
3788 return s390_cannot_force_const_mem (mode
, XEXP (x
, 0))
3789 || s390_cannot_force_const_mem (mode
, XEXP (x
, 1));
3792 switch (XINT (x
, 1))
3794 /* Only lt-relative or GOT-relative UNSPECs are OK. */
3795 case UNSPEC_LTREL_OFFSET
:
3803 case UNSPEC_GOTNTPOFF
:
3804 case UNSPEC_INDNTPOFF
:
3807 /* If the literal pool shares the code section, be put
3808 execute template placeholders into the pool as well. */
3810 return TARGET_CPU_ZARCH
;
3822 /* Returns true if the constant value OP is a legitimate general
3823 operand during and after reload. The difference to
3824 legitimate_constant_p is that this function will not accept
3825 a constant that would need to be forced to the literal pool
3826 before it can be used as operand.
3827 This function accepts all constants which can be loaded directly
3831 legitimate_reload_constant_p (rtx op
)
3833 /* Accept la(y) operands. */
3834 if (GET_CODE (op
) == CONST_INT
3835 && DISP_IN_RANGE (INTVAL (op
)))
3838 /* Accept l(g)hi/l(g)fi operands. */
3839 if (GET_CODE (op
) == CONST_INT
3840 && (CONST_OK_FOR_K (INTVAL (op
)) || CONST_OK_FOR_Os (INTVAL (op
))))
3843 /* Accept lliXX operands. */
3845 && GET_CODE (op
) == CONST_INT
3846 && trunc_int_for_mode (INTVAL (op
), word_mode
) == INTVAL (op
)
3847 && s390_single_part (op
, word_mode
, HImode
, 0) >= 0)
3851 && GET_CODE (op
) == CONST_INT
3852 && trunc_int_for_mode (INTVAL (op
), word_mode
) == INTVAL (op
)
3853 && s390_single_part (op
, word_mode
, SImode
, 0) >= 0)
3856 /* Accept larl operands. */
3857 if (TARGET_CPU_ZARCH
3858 && larl_operand (op
, VOIDmode
))
3861 /* Accept floating-point zero operands that fit into a single GPR. */
3862 if (GET_CODE (op
) == CONST_DOUBLE
3863 && s390_float_const_zero_p (op
)
3864 && GET_MODE_SIZE (GET_MODE (op
)) <= UNITS_PER_WORD
)
3867 /* Accept double-word operands that can be split. */
3868 if (GET_CODE (op
) == CONST_WIDE_INT
3869 || (GET_CODE (op
) == CONST_INT
3870 && trunc_int_for_mode (INTVAL (op
), word_mode
) != INTVAL (op
)))
3872 machine_mode dword_mode
= word_mode
== SImode
? DImode
: TImode
;
3873 rtx hi
= operand_subword (op
, 0, 0, dword_mode
);
3874 rtx lo
= operand_subword (op
, 1, 0, dword_mode
);
3875 return legitimate_reload_constant_p (hi
)
3876 && legitimate_reload_constant_p (lo
);
3879 /* Everything else cannot be handled without reload. */
3883 /* Returns true if the constant value OP is a legitimate fp operand
3884 during and after reload.
3885 This function accepts all constants which can be loaded directly
3889 legitimate_reload_fp_constant_p (rtx op
)
3891 /* Accept floating-point zero operands if the load zero instruction
3892 can be used. Prior to z196 the load fp zero instruction caused a
3893 performance penalty if the result is used as BFP number. */
3895 && GET_CODE (op
) == CONST_DOUBLE
3896 && s390_float_const_zero_p (op
))
3902 /* Returns true if the constant value OP is a legitimate vector operand
3903 during and after reload.
3904 This function accepts all constants which can be loaded directly
3908 legitimate_reload_vector_constant_p (rtx op
)
3910 if (TARGET_VX
&& GET_MODE_SIZE (GET_MODE (op
)) == 16
3911 && (satisfies_constraint_j00 (op
)
3912 || satisfies_constraint_jm1 (op
)
3913 || satisfies_constraint_jKK (op
)
3914 || satisfies_constraint_jxx (op
)
3915 || satisfies_constraint_jyy (op
)))
3921 /* Given an rtx OP being reloaded into a reg required to be in class RCLASS,
3922 return the class of reg to actually use. */
3925 s390_preferred_reload_class (rtx op
, reg_class_t rclass
)
3927 switch (GET_CODE (op
))
3929 /* Constants we cannot reload into general registers
3930 must be forced into the literal pool. */
3934 case CONST_WIDE_INT
:
3935 if (reg_class_subset_p (GENERAL_REGS
, rclass
)
3936 && legitimate_reload_constant_p (op
))
3937 return GENERAL_REGS
;
3938 else if (reg_class_subset_p (ADDR_REGS
, rclass
)
3939 && legitimate_reload_constant_p (op
))
3941 else if (reg_class_subset_p (FP_REGS
, rclass
)
3942 && legitimate_reload_fp_constant_p (op
))
3944 else if (reg_class_subset_p (VEC_REGS
, rclass
)
3945 && legitimate_reload_vector_constant_p (op
))
3950 /* If a symbolic constant or a PLUS is reloaded,
3951 it is most likely being used as an address, so
3952 prefer ADDR_REGS. If 'class' is not a superset
3953 of ADDR_REGS, e.g. FP_REGS, reject this reload. */
3955 /* Symrefs cannot be pushed into the literal pool with -fPIC
3956 so we *MUST NOT* return NO_REGS for these cases
3957 (s390_cannot_force_const_mem will return true).
3959 On the other hand we MUST return NO_REGS for symrefs with
3960 invalid addend which might have been pushed to the literal
3961 pool (no -fPIC). Usually we would expect them to be
3962 handled via secondary reload but this does not happen if
3963 they are used as literal pool slot replacement in reload
3964 inheritance (see emit_input_reload_insns). */
3965 if (TARGET_CPU_ZARCH
3966 && GET_CODE (XEXP (op
, 0)) == PLUS
3967 && GET_CODE (XEXP (XEXP(op
, 0), 0)) == SYMBOL_REF
3968 && GET_CODE (XEXP (XEXP(op
, 0), 1)) == CONST_INT
)
3970 if (flag_pic
&& reg_class_subset_p (ADDR_REGS
, rclass
))
3978 if (!legitimate_reload_constant_p (op
))
3982 /* load address will be used. */
3983 if (reg_class_subset_p (ADDR_REGS
, rclass
))
3995 /* Return true if ADDR is SYMBOL_REF + addend with addend being a
3996 multiple of ALIGNMENT and the SYMBOL_REF being naturally
4000 s390_check_symref_alignment (rtx addr
, HOST_WIDE_INT alignment
)
4002 HOST_WIDE_INT addend
;
4005 /* The "required alignment" might be 0 (e.g. for certain structs
4006 accessed via BLKmode). Early abort in this case, as well as when
4007 an alignment > 8 is required. */
4008 if (alignment
< 2 || alignment
> 8)
4011 if (!s390_loadrelative_operand_p (addr
, &symref
, &addend
))
4014 if (addend
& (alignment
- 1))
4017 if (GET_CODE (symref
) == SYMBOL_REF
)
4019 /* We have load-relative instructions for 2-byte, 4-byte, and
4020 8-byte alignment so allow only these. */
4023 case 8: return !SYMBOL_FLAG_NOTALIGN8_P (symref
);
4024 case 4: return !SYMBOL_FLAG_NOTALIGN4_P (symref
);
4025 case 2: return !SYMBOL_FLAG_NOTALIGN2_P (symref
);
4026 default: return false;
4030 if (GET_CODE (symref
) == UNSPEC
4031 && alignment
<= UNITS_PER_LONG
)
4037 /* ADDR is moved into REG using larl. If ADDR isn't a valid larl
4038 operand SCRATCH is used to reload the even part of the address and
4042 s390_reload_larl_operand (rtx reg
, rtx addr
, rtx scratch
)
4044 HOST_WIDE_INT addend
;
4047 if (!s390_loadrelative_operand_p (addr
, &symref
, &addend
))
4051 /* Easy case. The addend is even so larl will do fine. */
4052 emit_move_insn (reg
, addr
);
4055 /* We can leave the scratch register untouched if the target
4056 register is a valid base register. */
4057 if (REGNO (reg
) < FIRST_PSEUDO_REGISTER
4058 && REGNO_REG_CLASS (REGNO (reg
)) == ADDR_REGS
)
4061 gcc_assert (REGNO (scratch
) < FIRST_PSEUDO_REGISTER
);
4062 gcc_assert (REGNO_REG_CLASS (REGNO (scratch
)) == ADDR_REGS
);
4065 emit_move_insn (scratch
,
4066 gen_rtx_CONST (Pmode
,
4067 gen_rtx_PLUS (Pmode
, symref
,
4068 GEN_INT (addend
- 1))));
4070 emit_move_insn (scratch
, symref
);
4072 /* Increment the address using la in order to avoid clobbering cc. */
4073 s390_load_address (reg
, gen_rtx_PLUS (Pmode
, scratch
, const1_rtx
));
4077 /* Generate what is necessary to move between REG and MEM using
4078 SCRATCH. The direction is given by TOMEM. */
4081 s390_reload_symref_address (rtx reg
, rtx mem
, rtx scratch
, bool tomem
)
4083 /* Reload might have pulled a constant out of the literal pool.
4084 Force it back in. */
4085 if (CONST_INT_P (mem
) || GET_CODE (mem
) == CONST_DOUBLE
4086 || GET_CODE (mem
) == CONST_WIDE_INT
4087 || GET_CODE (mem
) == CONST_VECTOR
4088 || GET_CODE (mem
) == CONST
)
4089 mem
= force_const_mem (GET_MODE (reg
), mem
);
4091 gcc_assert (MEM_P (mem
));
4093 /* For a load from memory we can leave the scratch register
4094 untouched if the target register is a valid base register. */
4096 && REGNO (reg
) < FIRST_PSEUDO_REGISTER
4097 && REGNO_REG_CLASS (REGNO (reg
)) == ADDR_REGS
4098 && GET_MODE (reg
) == GET_MODE (scratch
))
4101 /* Load address into scratch register. Since we can't have a
4102 secondary reload for a secondary reload we have to cover the case
4103 where larl would need a secondary reload here as well. */
4104 s390_reload_larl_operand (scratch
, XEXP (mem
, 0), scratch
);
4106 /* Now we can use a standard load/store to do the move. */
4108 emit_move_insn (replace_equiv_address (mem
, scratch
), reg
);
4110 emit_move_insn (reg
, replace_equiv_address (mem
, scratch
));
4113 /* Inform reload about cases where moving X with a mode MODE to a register in
4114 RCLASS requires an extra scratch or immediate register. Return the class
4115 needed for the immediate register. */
4118 s390_secondary_reload (bool in_p
, rtx x
, reg_class_t rclass_i
,
4119 machine_mode mode
, secondary_reload_info
*sri
)
4121 enum reg_class rclass
= (enum reg_class
) rclass_i
;
4123 /* Intermediate register needed. */
4124 if (reg_classes_intersect_p (CC_REGS
, rclass
))
4125 return GENERAL_REGS
;
4129 /* The vst/vl vector move instructions allow only for short
4132 && GET_CODE (XEXP (x
, 0)) == PLUS
4133 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
4134 && !SHORT_DISP_IN_RANGE(INTVAL (XEXP (XEXP (x
, 0), 1)))
4135 && reg_class_subset_p (rclass
, VEC_REGS
)
4136 && (!reg_class_subset_p (rclass
, FP_REGS
)
4137 || (GET_MODE_SIZE (mode
) > 8
4138 && s390_class_max_nregs (FP_REGS
, mode
) == 1)))
4141 sri
->icode
= (TARGET_64BIT
?
4142 CODE_FOR_reloaddi_la_in
:
4143 CODE_FOR_reloadsi_la_in
);
4145 sri
->icode
= (TARGET_64BIT
?
4146 CODE_FOR_reloaddi_la_out
:
4147 CODE_FOR_reloadsi_la_out
);
4153 HOST_WIDE_INT offset
;
4156 /* On z10 several optimizer steps may generate larl operands with
4159 && s390_loadrelative_operand_p (x
, &symref
, &offset
)
4161 && !SYMBOL_FLAG_NOTALIGN2_P (symref
)
4162 && (offset
& 1) == 1)
4163 sri
->icode
= ((mode
== DImode
) ? CODE_FOR_reloaddi_larl_odd_addend_z10
4164 : CODE_FOR_reloadsi_larl_odd_addend_z10
);
4166 /* Handle all the (mem (symref)) accesses we cannot use the z10
4167 instructions for. */
4169 && s390_loadrelative_operand_p (XEXP (x
, 0), NULL
, NULL
)
4171 || !reg_class_subset_p (rclass
, GENERAL_REGS
)
4172 || GET_MODE_SIZE (mode
) > UNITS_PER_WORD
4173 || !s390_check_symref_alignment (XEXP (x
, 0),
4174 GET_MODE_SIZE (mode
))))
4176 #define __SECONDARY_RELOAD_CASE(M,m) \
4179 sri->icode = in_p ? CODE_FOR_reload##m##di_toreg_z10 : \
4180 CODE_FOR_reload##m##di_tomem_z10; \
4182 sri->icode = in_p ? CODE_FOR_reload##m##si_toreg_z10 : \
4183 CODE_FOR_reload##m##si_tomem_z10; \
4186 switch (GET_MODE (x
))
4188 __SECONDARY_RELOAD_CASE (QI
, qi
);
4189 __SECONDARY_RELOAD_CASE (HI
, hi
);
4190 __SECONDARY_RELOAD_CASE (SI
, si
);
4191 __SECONDARY_RELOAD_CASE (DI
, di
);
4192 __SECONDARY_RELOAD_CASE (TI
, ti
);
4193 __SECONDARY_RELOAD_CASE (SF
, sf
);
4194 __SECONDARY_RELOAD_CASE (DF
, df
);
4195 __SECONDARY_RELOAD_CASE (TF
, tf
);
4196 __SECONDARY_RELOAD_CASE (SD
, sd
);
4197 __SECONDARY_RELOAD_CASE (DD
, dd
);
4198 __SECONDARY_RELOAD_CASE (TD
, td
);
4199 __SECONDARY_RELOAD_CASE (V1QI
, v1qi
);
4200 __SECONDARY_RELOAD_CASE (V2QI
, v2qi
);
4201 __SECONDARY_RELOAD_CASE (V4QI
, v4qi
);
4202 __SECONDARY_RELOAD_CASE (V8QI
, v8qi
);
4203 __SECONDARY_RELOAD_CASE (V16QI
, v16qi
);
4204 __SECONDARY_RELOAD_CASE (V1HI
, v1hi
);
4205 __SECONDARY_RELOAD_CASE (V2HI
, v2hi
);
4206 __SECONDARY_RELOAD_CASE (V4HI
, v4hi
);
4207 __SECONDARY_RELOAD_CASE (V8HI
, v8hi
);
4208 __SECONDARY_RELOAD_CASE (V1SI
, v1si
);
4209 __SECONDARY_RELOAD_CASE (V2SI
, v2si
);
4210 __SECONDARY_RELOAD_CASE (V4SI
, v4si
);
4211 __SECONDARY_RELOAD_CASE (V1DI
, v1di
);
4212 __SECONDARY_RELOAD_CASE (V2DI
, v2di
);
4213 __SECONDARY_RELOAD_CASE (V1TI
, v1ti
);
4214 __SECONDARY_RELOAD_CASE (V1SF
, v1sf
);
4215 __SECONDARY_RELOAD_CASE (V2SF
, v2sf
);
4216 __SECONDARY_RELOAD_CASE (V4SF
, v4sf
);
4217 __SECONDARY_RELOAD_CASE (V1DF
, v1df
);
4218 __SECONDARY_RELOAD_CASE (V2DF
, v2df
);
4219 __SECONDARY_RELOAD_CASE (V1TF
, v1tf
);
4223 #undef __SECONDARY_RELOAD_CASE
4227 /* We need a scratch register when loading a PLUS expression which
4228 is not a legitimate operand of the LOAD ADDRESS instruction. */
4229 /* LRA can deal with transformation of plus op very well -- so we
4230 don't need to prompt LRA in this case. */
4231 if (! lra_in_progress
&& in_p
&& s390_plus_operand (x
, mode
))
4232 sri
->icode
= (TARGET_64BIT
?
4233 CODE_FOR_reloaddi_plus
: CODE_FOR_reloadsi_plus
);
4235 /* Performing a multiword move from or to memory we have to make sure the
4236 second chunk in memory is addressable without causing a displacement
4237 overflow. If that would be the case we calculate the address in
4238 a scratch register. */
4240 && GET_CODE (XEXP (x
, 0)) == PLUS
4241 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
4242 && !DISP_IN_RANGE (INTVAL (XEXP (XEXP (x
, 0), 1))
4243 + GET_MODE_SIZE (mode
) - 1))
4245 /* For GENERAL_REGS a displacement overflow is no problem if occurring
4246 in a s_operand address since we may fallback to lm/stm. So we only
4247 have to care about overflows in the b+i+d case. */
4248 if ((reg_classes_intersect_p (GENERAL_REGS
, rclass
)
4249 && s390_class_max_nregs (GENERAL_REGS
, mode
) > 1
4250 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == PLUS
)
4251 /* For FP_REGS no lm/stm is available so this check is triggered
4252 for displacement overflows in b+i+d and b+d like addresses. */
4253 || (reg_classes_intersect_p (FP_REGS
, rclass
)
4254 && s390_class_max_nregs (FP_REGS
, mode
) > 1))
4257 sri
->icode
= (TARGET_64BIT
?
4258 CODE_FOR_reloaddi_la_in
:
4259 CODE_FOR_reloadsi_la_in
);
4261 sri
->icode
= (TARGET_64BIT
?
4262 CODE_FOR_reloaddi_la_out
:
4263 CODE_FOR_reloadsi_la_out
);
4267 /* A scratch address register is needed when a symbolic constant is
4268 copied to r0 compiling with -fPIC. In other cases the target
4269 register might be used as temporary (see legitimize_pic_address). */
4270 if (in_p
&& SYMBOLIC_CONST (x
) && flag_pic
== 2 && rclass
!= ADDR_REGS
)
4271 sri
->icode
= (TARGET_64BIT
?
4272 CODE_FOR_reloaddi_PIC_addr
:
4273 CODE_FOR_reloadsi_PIC_addr
);
4275 /* Either scratch or no register needed. */
4279 /* Generate code to load SRC, which is PLUS that is not a
4280 legitimate operand for the LA instruction, into TARGET.
4281 SCRATCH may be used as scratch register. */
4284 s390_expand_plus_operand (rtx target
, rtx src
,
4288 struct s390_address ad
;
4290 /* src must be a PLUS; get its two operands. */
4291 gcc_assert (GET_CODE (src
) == PLUS
);
4292 gcc_assert (GET_MODE (src
) == Pmode
);
4294 /* Check if any of the two operands is already scheduled
4295 for replacement by reload. This can happen e.g. when
4296 float registers occur in an address. */
4297 sum1
= find_replacement (&XEXP (src
, 0));
4298 sum2
= find_replacement (&XEXP (src
, 1));
4299 src
= gen_rtx_PLUS (Pmode
, sum1
, sum2
);
4301 /* If the address is already strictly valid, there's nothing to do. */
4302 if (!s390_decompose_address (src
, &ad
)
4303 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
4304 || (ad
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (ad
.indx
))))
4306 /* Otherwise, one of the operands cannot be an address register;
4307 we reload its value into the scratch register. */
4308 if (true_regnum (sum1
) < 1 || true_regnum (sum1
) > 15)
4310 emit_move_insn (scratch
, sum1
);
4313 if (true_regnum (sum2
) < 1 || true_regnum (sum2
) > 15)
4315 emit_move_insn (scratch
, sum2
);
4319 /* According to the way these invalid addresses are generated
4320 in reload.c, it should never happen (at least on s390) that
4321 *neither* of the PLUS components, after find_replacements
4322 was applied, is an address register. */
4323 if (sum1
== scratch
&& sum2
== scratch
)
4329 src
= gen_rtx_PLUS (Pmode
, sum1
, sum2
);
4332 /* Emit the LOAD ADDRESS pattern. Note that reload of PLUS
4333 is only ever performed on addresses, so we can mark the
4334 sum as legitimate for LA in any case. */
4335 s390_load_address (target
, src
);
4339 /* Return true if ADDR is a valid memory address.
4340 STRICT specifies whether strict register checking applies. */
4343 s390_legitimate_address_p (machine_mode mode
, rtx addr
, bool strict
)
4345 struct s390_address ad
;
4348 && larl_operand (addr
, VOIDmode
)
4349 && (mode
== VOIDmode
4350 || s390_check_symref_alignment (addr
, GET_MODE_SIZE (mode
))))
4353 if (!s390_decompose_address (addr
, &ad
))
4358 if (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
4361 if (ad
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (ad
.indx
)))
4367 && !(REGNO (ad
.base
) >= FIRST_PSEUDO_REGISTER
4368 || REGNO_REG_CLASS (REGNO (ad
.base
)) == ADDR_REGS
))
4372 && !(REGNO (ad
.indx
) >= FIRST_PSEUDO_REGISTER
4373 || REGNO_REG_CLASS (REGNO (ad
.indx
)) == ADDR_REGS
))
4379 /* Return true if OP is a valid operand for the LA instruction.
4380 In 31-bit, we need to prove that the result is used as an
4381 address, as LA performs only a 31-bit addition. */
4384 legitimate_la_operand_p (rtx op
)
4386 struct s390_address addr
;
4387 if (!s390_decompose_address (op
, &addr
))
4390 return (TARGET_64BIT
|| addr
.pointer
);
4393 /* Return true if it is valid *and* preferable to use LA to
4394 compute the sum of OP1 and OP2. */
4397 preferred_la_operand_p (rtx op1
, rtx op2
)
4399 struct s390_address addr
;
4401 if (op2
!= const0_rtx
)
4402 op1
= gen_rtx_PLUS (Pmode
, op1
, op2
);
4404 if (!s390_decompose_address (op1
, &addr
))
4406 if (addr
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (addr
.base
)))
4408 if (addr
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (addr
.indx
)))
4411 /* Avoid LA instructions with index register on z196; it is
4412 preferable to use regular add instructions when possible.
4413 Starting with zEC12 the la with index register is "uncracked"
4415 if (addr
.indx
&& s390_tune
== PROCESSOR_2817_Z196
)
4418 if (!TARGET_64BIT
&& !addr
.pointer
)
4424 if ((addr
.base
&& REG_P (addr
.base
) && REG_POINTER (addr
.base
))
4425 || (addr
.indx
&& REG_P (addr
.indx
) && REG_POINTER (addr
.indx
)))
4431 /* Emit a forced load-address operation to load SRC into DST.
4432 This will use the LOAD ADDRESS instruction even in situations
4433 where legitimate_la_operand_p (SRC) returns false. */
4436 s390_load_address (rtx dst
, rtx src
)
4439 emit_move_insn (dst
, src
);
4441 emit_insn (gen_force_la_31 (dst
, src
));
4444 /* Return a legitimate reference for ORIG (an address) using the
4445 register REG. If REG is 0, a new pseudo is generated.
4447 There are two types of references that must be handled:
4449 1. Global data references must load the address from the GOT, via
4450 the PIC reg. An insn is emitted to do this load, and the reg is
4453 2. Static data references, constant pool addresses, and code labels
4454 compute the address as an offset from the GOT, whose base is in
4455 the PIC reg. Static data objects have SYMBOL_FLAG_LOCAL set to
4456 differentiate them from global data objects. The returned
4457 address is the PIC reg + an unspec constant.
4459 TARGET_LEGITIMIZE_ADDRESS_P rejects symbolic references unless the PIC
4460 reg also appears in the address. */
4463 legitimize_pic_address (rtx orig
, rtx reg
)
4466 rtx addend
= const0_rtx
;
4469 gcc_assert (!TLS_SYMBOLIC_CONST (addr
));
4471 if (GET_CODE (addr
) == CONST
)
4472 addr
= XEXP (addr
, 0);
4474 if (GET_CODE (addr
) == PLUS
)
4476 addend
= XEXP (addr
, 1);
4477 addr
= XEXP (addr
, 0);
4480 if ((GET_CODE (addr
) == LABEL_REF
4481 || (GET_CODE (addr
) == SYMBOL_REF
&& SYMBOL_REF_LOCAL_P (addr
))
4482 || (GET_CODE (addr
) == UNSPEC
&&
4483 (XINT (addr
, 1) == UNSPEC_GOTENT
4484 || (TARGET_CPU_ZARCH
&& XINT (addr
, 1) == UNSPEC_PLT
))))
4485 && GET_CODE (addend
) == CONST_INT
)
4487 /* This can be locally addressed. */
4489 /* larl_operand requires UNSPECs to be wrapped in a const rtx. */
4490 rtx const_addr
= (GET_CODE (addr
) == UNSPEC
?
4491 gen_rtx_CONST (Pmode
, addr
) : addr
);
4493 if (TARGET_CPU_ZARCH
4494 && larl_operand (const_addr
, VOIDmode
)
4495 && INTVAL (addend
) < (HOST_WIDE_INT
)1 << 31
4496 && INTVAL (addend
) >= -((HOST_WIDE_INT
)1 << 31))
4498 if (INTVAL (addend
) & 1)
4500 /* LARL can't handle odd offsets, so emit a pair of LARL
4502 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
4504 if (!DISP_IN_RANGE (INTVAL (addend
)))
4506 HOST_WIDE_INT even
= INTVAL (addend
) - 1;
4507 addr
= gen_rtx_PLUS (Pmode
, addr
, GEN_INT (even
));
4508 addr
= gen_rtx_CONST (Pmode
, addr
);
4509 addend
= const1_rtx
;
4512 emit_move_insn (temp
, addr
);
4513 new_rtx
= gen_rtx_PLUS (Pmode
, temp
, addend
);
4517 s390_load_address (reg
, new_rtx
);
4523 /* If the offset is even, we can just use LARL. This
4524 will happen automatically. */
4529 /* No larl - Access local symbols relative to the GOT. */
4531 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
4533 if (reload_in_progress
|| reload_completed
)
4534 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
4536 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTOFF
);
4537 if (addend
!= const0_rtx
)
4538 addr
= gen_rtx_PLUS (Pmode
, addr
, addend
);
4539 addr
= gen_rtx_CONST (Pmode
, addr
);
4540 addr
= force_const_mem (Pmode
, addr
);
4541 emit_move_insn (temp
, addr
);
4543 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
4546 s390_load_address (reg
, new_rtx
);
4551 else if (GET_CODE (addr
) == SYMBOL_REF
&& addend
== const0_rtx
)
4553 /* A non-local symbol reference without addend.
4555 The symbol ref is wrapped into an UNSPEC to make sure the
4556 proper operand modifier (@GOT or @GOTENT) will be emitted.
4557 This will tell the linker to put the symbol into the GOT.
4559 Additionally the code dereferencing the GOT slot is emitted here.
4561 An addend to the symref needs to be added afterwards.
4562 legitimize_pic_address calls itself recursively to handle
4563 that case. So no need to do it here. */
4566 reg
= gen_reg_rtx (Pmode
);
4570 /* Use load relative if possible.
4571 lgrl <target>, sym@GOTENT */
4572 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTENT
);
4573 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
4574 new_rtx
= gen_const_mem (GET_MODE (reg
), new_rtx
);
4576 emit_move_insn (reg
, new_rtx
);
4579 else if (flag_pic
== 1)
4581 /* Assume GOT offset is a valid displacement operand (< 4k
4582 or < 512k with z990). This is handled the same way in
4583 both 31- and 64-bit code (@GOT).
4584 lg <target>, sym@GOT(r12) */
4586 if (reload_in_progress
|| reload_completed
)
4587 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
4589 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOT
);
4590 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
4591 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, new_rtx
);
4592 new_rtx
= gen_const_mem (Pmode
, new_rtx
);
4593 emit_move_insn (reg
, new_rtx
);
4596 else if (TARGET_CPU_ZARCH
)
4598 /* If the GOT offset might be >= 4k, we determine the position
4599 of the GOT entry via a PC-relative LARL (@GOTENT).
4600 larl temp, sym@GOTENT
4601 lg <target>, 0(temp) */
4603 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
4605 gcc_assert (REGNO (temp
) >= FIRST_PSEUDO_REGISTER
4606 || REGNO_REG_CLASS (REGNO (temp
)) == ADDR_REGS
);
4608 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTENT
);
4609 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
4610 emit_move_insn (temp
, new_rtx
);
4612 new_rtx
= gen_const_mem (Pmode
, temp
);
4613 emit_move_insn (reg
, new_rtx
);
4619 /* If the GOT offset might be >= 4k, we have to load it
4620 from the literal pool (@GOT).
4622 lg temp, lit-litbase(r13)
4623 lg <target>, 0(temp)
4624 lit: .long sym@GOT */
4626 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
4628 gcc_assert (REGNO (temp
) >= FIRST_PSEUDO_REGISTER
4629 || REGNO_REG_CLASS (REGNO (temp
)) == ADDR_REGS
);
4631 if (reload_in_progress
|| reload_completed
)
4632 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
4634 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOT
);
4635 addr
= gen_rtx_CONST (Pmode
, addr
);
4636 addr
= force_const_mem (Pmode
, addr
);
4637 emit_move_insn (temp
, addr
);
4639 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
4640 new_rtx
= gen_const_mem (Pmode
, new_rtx
);
4641 emit_move_insn (reg
, new_rtx
);
4645 else if (GET_CODE (addr
) == UNSPEC
&& GET_CODE (addend
) == CONST_INT
)
4647 gcc_assert (XVECLEN (addr
, 0) == 1);
4648 switch (XINT (addr
, 1))
4650 /* These address symbols (or PLT slots) relative to the GOT
4651 (not GOT slots!). In general this will exceed the
4652 displacement range so these value belong into the literal
4656 new_rtx
= force_const_mem (Pmode
, orig
);
4659 /* For -fPIC the GOT size might exceed the displacement
4660 range so make sure the value is in the literal pool. */
4663 new_rtx
= force_const_mem (Pmode
, orig
);
4666 /* For @GOTENT larl is used. This is handled like local
4672 /* @PLT is OK as is on 64-bit, must be converted to
4673 GOT-relative @PLTOFF on 31-bit. */
4675 if (!TARGET_CPU_ZARCH
)
4677 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
4679 if (reload_in_progress
|| reload_completed
)
4680 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
4682 addr
= XVECEXP (addr
, 0, 0);
4683 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
),
4685 if (addend
!= const0_rtx
)
4686 addr
= gen_rtx_PLUS (Pmode
, addr
, addend
);
4687 addr
= gen_rtx_CONST (Pmode
, addr
);
4688 addr
= force_const_mem (Pmode
, addr
);
4689 emit_move_insn (temp
, addr
);
4691 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
4694 s390_load_address (reg
, new_rtx
);
4699 /* On 64 bit larl can be used. This case is handled like
4700 local symbol refs. */
4704 /* Everything else cannot happen. */
4709 else if (addend
!= const0_rtx
)
4711 /* Otherwise, compute the sum. */
4713 rtx base
= legitimize_pic_address (addr
, reg
);
4714 new_rtx
= legitimize_pic_address (addend
,
4715 base
== reg
? NULL_RTX
: reg
);
4716 if (GET_CODE (new_rtx
) == CONST_INT
)
4717 new_rtx
= plus_constant (Pmode
, base
, INTVAL (new_rtx
));
4720 if (GET_CODE (new_rtx
) == PLUS
&& CONSTANT_P (XEXP (new_rtx
, 1)))
4722 base
= gen_rtx_PLUS (Pmode
, base
, XEXP (new_rtx
, 0));
4723 new_rtx
= XEXP (new_rtx
, 1);
4725 new_rtx
= gen_rtx_PLUS (Pmode
, base
, new_rtx
);
4728 if (GET_CODE (new_rtx
) == CONST
)
4729 new_rtx
= XEXP (new_rtx
, 0);
4730 new_rtx
= force_operand (new_rtx
, 0);
4736 /* Load the thread pointer into a register. */
4739 s390_get_thread_pointer (void)
4741 rtx tp
= gen_reg_rtx (Pmode
);
4743 emit_move_insn (tp
, gen_rtx_REG (Pmode
, TP_REGNUM
));
4744 mark_reg_pointer (tp
, BITS_PER_WORD
);
4749 /* Emit a tls call insn. The call target is the SYMBOL_REF stored
4750 in s390_tls_symbol which always refers to __tls_get_offset.
4751 The returned offset is written to RESULT_REG and an USE rtx is
4752 generated for TLS_CALL. */
4754 static GTY(()) rtx s390_tls_symbol
;
4757 s390_emit_tls_call_insn (rtx result_reg
, rtx tls_call
)
4762 emit_insn (s390_load_got ());
4764 if (!s390_tls_symbol
)
4765 s390_tls_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "__tls_get_offset");
4767 insn
= s390_emit_call (s390_tls_symbol
, tls_call
, result_reg
,
4768 gen_rtx_REG (Pmode
, RETURN_REGNUM
));
4770 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), result_reg
);
4771 RTL_CONST_CALL_P (insn
) = 1;
4774 /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
4775 this (thread-local) address. REG may be used as temporary. */
4778 legitimize_tls_address (rtx addr
, rtx reg
)
4780 rtx new_rtx
, tls_call
, temp
, base
, r2
, insn
;
4782 if (GET_CODE (addr
) == SYMBOL_REF
)
4783 switch (tls_symbolic_operand (addr
))
4785 case TLS_MODEL_GLOBAL_DYNAMIC
:
4787 r2
= gen_rtx_REG (Pmode
, 2);
4788 tls_call
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_TLSGD
);
4789 new_rtx
= gen_rtx_CONST (Pmode
, tls_call
);
4790 new_rtx
= force_const_mem (Pmode
, new_rtx
);
4791 emit_move_insn (r2
, new_rtx
);
4792 s390_emit_tls_call_insn (r2
, tls_call
);
4793 insn
= get_insns ();
4796 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_NTPOFF
);
4797 temp
= gen_reg_rtx (Pmode
);
4798 emit_libcall_block (insn
, temp
, r2
, new_rtx
);
4800 new_rtx
= gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
4803 s390_load_address (reg
, new_rtx
);
4808 case TLS_MODEL_LOCAL_DYNAMIC
:
4810 r2
= gen_rtx_REG (Pmode
, 2);
4811 tls_call
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, const0_rtx
), UNSPEC_TLSLDM
);
4812 new_rtx
= gen_rtx_CONST (Pmode
, tls_call
);
4813 new_rtx
= force_const_mem (Pmode
, new_rtx
);
4814 emit_move_insn (r2
, new_rtx
);
4815 s390_emit_tls_call_insn (r2
, tls_call
);
4816 insn
= get_insns ();
4819 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, const0_rtx
), UNSPEC_TLSLDM_NTPOFF
);
4820 temp
= gen_reg_rtx (Pmode
);
4821 emit_libcall_block (insn
, temp
, r2
, new_rtx
);
4823 new_rtx
= gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
4824 base
= gen_reg_rtx (Pmode
);
4825 s390_load_address (base
, new_rtx
);
4827 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_DTPOFF
);
4828 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
4829 new_rtx
= force_const_mem (Pmode
, new_rtx
);
4830 temp
= gen_reg_rtx (Pmode
);
4831 emit_move_insn (temp
, new_rtx
);
4833 new_rtx
= gen_rtx_PLUS (Pmode
, base
, temp
);
4836 s390_load_address (reg
, new_rtx
);
4841 case TLS_MODEL_INITIAL_EXEC
:
4844 /* Assume GOT offset < 4k. This is handled the same way
4845 in both 31- and 64-bit code. */
4847 if (reload_in_progress
|| reload_completed
)
4848 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
4850 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTNTPOFF
);
4851 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
4852 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, new_rtx
);
4853 new_rtx
= gen_const_mem (Pmode
, new_rtx
);
4854 temp
= gen_reg_rtx (Pmode
);
4855 emit_move_insn (temp
, new_rtx
);
4857 else if (TARGET_CPU_ZARCH
)
4859 /* If the GOT offset might be >= 4k, we determine the position
4860 of the GOT entry via a PC-relative LARL. */
4862 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_INDNTPOFF
);
4863 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
4864 temp
= gen_reg_rtx (Pmode
);
4865 emit_move_insn (temp
, new_rtx
);
4867 new_rtx
= gen_const_mem (Pmode
, temp
);
4868 temp
= gen_reg_rtx (Pmode
);
4869 emit_move_insn (temp
, new_rtx
);
4873 /* If the GOT offset might be >= 4k, we have to load it
4874 from the literal pool. */
4876 if (reload_in_progress
|| reload_completed
)
4877 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
4879 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTNTPOFF
);
4880 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
4881 new_rtx
= force_const_mem (Pmode
, new_rtx
);
4882 temp
= gen_reg_rtx (Pmode
);
4883 emit_move_insn (temp
, new_rtx
);
4885 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
4886 new_rtx
= gen_const_mem (Pmode
, new_rtx
);
4888 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, new_rtx
, addr
), UNSPEC_TLS_LOAD
);
4889 temp
= gen_reg_rtx (Pmode
);
4890 emit_insn (gen_rtx_SET (temp
, new_rtx
));
4894 /* In position-dependent code, load the absolute address of
4895 the GOT entry from the literal pool. */
4897 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_INDNTPOFF
);
4898 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
4899 new_rtx
= force_const_mem (Pmode
, new_rtx
);
4900 temp
= gen_reg_rtx (Pmode
);
4901 emit_move_insn (temp
, new_rtx
);
4904 new_rtx
= gen_const_mem (Pmode
, new_rtx
);
4905 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, new_rtx
, addr
), UNSPEC_TLS_LOAD
);
4906 temp
= gen_reg_rtx (Pmode
);
4907 emit_insn (gen_rtx_SET (temp
, new_rtx
));
4910 new_rtx
= gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
4913 s390_load_address (reg
, new_rtx
);
4918 case TLS_MODEL_LOCAL_EXEC
:
4919 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_NTPOFF
);
4920 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
4921 new_rtx
= force_const_mem (Pmode
, new_rtx
);
4922 temp
= gen_reg_rtx (Pmode
);
4923 emit_move_insn (temp
, new_rtx
);
4925 new_rtx
= gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
4928 s390_load_address (reg
, new_rtx
);
4937 else if (GET_CODE (addr
) == CONST
&& GET_CODE (XEXP (addr
, 0)) == UNSPEC
)
4939 switch (XINT (XEXP (addr
, 0), 1))
4941 case UNSPEC_INDNTPOFF
:
4942 gcc_assert (TARGET_CPU_ZARCH
);
4951 else if (GET_CODE (addr
) == CONST
&& GET_CODE (XEXP (addr
, 0)) == PLUS
4952 && GET_CODE (XEXP (XEXP (addr
, 0), 1)) == CONST_INT
)
4954 new_rtx
= XEXP (XEXP (addr
, 0), 0);
4955 if (GET_CODE (new_rtx
) != SYMBOL_REF
)
4956 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
4958 new_rtx
= legitimize_tls_address (new_rtx
, reg
);
4959 new_rtx
= plus_constant (Pmode
, new_rtx
,
4960 INTVAL (XEXP (XEXP (addr
, 0), 1)));
4961 new_rtx
= force_operand (new_rtx
, 0);
4965 gcc_unreachable (); /* for now ... */
4970 /* Emit insns making the address in operands[1] valid for a standard
4971 move to operands[0]. operands[1] is replaced by an address which
4972 should be used instead of the former RTX to emit the move
4976 emit_symbolic_move (rtx
*operands
)
4978 rtx temp
= !can_create_pseudo_p () ? operands
[0] : gen_reg_rtx (Pmode
);
4980 if (GET_CODE (operands
[0]) == MEM
)
4981 operands
[1] = force_reg (Pmode
, operands
[1]);
4982 else if (TLS_SYMBOLIC_CONST (operands
[1]))
4983 operands
[1] = legitimize_tls_address (operands
[1], temp
);
4985 operands
[1] = legitimize_pic_address (operands
[1], temp
);
4988 /* Try machine-dependent ways of modifying an illegitimate address X
4989 to be legitimate. If we find one, return the new, valid address.
4991 OLDX is the address as it was before break_out_memory_refs was called.
4992 In some cases it is useful to look at this to decide what needs to be done.
4994 MODE is the mode of the operand pointed to by X.
4996 When -fpic is used, special handling is needed for symbolic references.
4997 See comments by legitimize_pic_address for details. */
5000 s390_legitimize_address (rtx x
, rtx oldx ATTRIBUTE_UNUSED
,
5001 machine_mode mode ATTRIBUTE_UNUSED
)
5003 rtx constant_term
= const0_rtx
;
5005 if (TLS_SYMBOLIC_CONST (x
))
5007 x
= legitimize_tls_address (x
, 0);
5009 if (s390_legitimate_address_p (mode
, x
, FALSE
))
5012 else if (GET_CODE (x
) == PLUS
5013 && (TLS_SYMBOLIC_CONST (XEXP (x
, 0))
5014 || TLS_SYMBOLIC_CONST (XEXP (x
, 1))))
5020 if (SYMBOLIC_CONST (x
)
5021 || (GET_CODE (x
) == PLUS
5022 && (SYMBOLIC_CONST (XEXP (x
, 0))
5023 || SYMBOLIC_CONST (XEXP (x
, 1)))))
5024 x
= legitimize_pic_address (x
, 0);
5026 if (s390_legitimate_address_p (mode
, x
, FALSE
))
5030 x
= eliminate_constant_term (x
, &constant_term
);
5032 /* Optimize loading of large displacements by splitting them
5033 into the multiple of 4K and the rest; this allows the
5034 former to be CSE'd if possible.
5036 Don't do this if the displacement is added to a register
5037 pointing into the stack frame, as the offsets will
5038 change later anyway. */
5040 if (GET_CODE (constant_term
) == CONST_INT
5041 && !TARGET_LONG_DISPLACEMENT
5042 && !DISP_IN_RANGE (INTVAL (constant_term
))
5043 && !(REG_P (x
) && REGNO_PTR_FRAME_P (REGNO (x
))))
5045 HOST_WIDE_INT lower
= INTVAL (constant_term
) & 0xfff;
5046 HOST_WIDE_INT upper
= INTVAL (constant_term
) ^ lower
;
5048 rtx temp
= gen_reg_rtx (Pmode
);
5049 rtx val
= force_operand (GEN_INT (upper
), temp
);
5051 emit_move_insn (temp
, val
);
5053 x
= gen_rtx_PLUS (Pmode
, x
, temp
);
5054 constant_term
= GEN_INT (lower
);
5057 if (GET_CODE (x
) == PLUS
)
5059 if (GET_CODE (XEXP (x
, 0)) == REG
)
5061 rtx temp
= gen_reg_rtx (Pmode
);
5062 rtx val
= force_operand (XEXP (x
, 1), temp
);
5064 emit_move_insn (temp
, val
);
5066 x
= gen_rtx_PLUS (Pmode
, XEXP (x
, 0), temp
);
5069 else if (GET_CODE (XEXP (x
, 1)) == REG
)
5071 rtx temp
= gen_reg_rtx (Pmode
);
5072 rtx val
= force_operand (XEXP (x
, 0), temp
);
5074 emit_move_insn (temp
, val
);
5076 x
= gen_rtx_PLUS (Pmode
, temp
, XEXP (x
, 1));
5080 if (constant_term
!= const0_rtx
)
5081 x
= gen_rtx_PLUS (Pmode
, x
, constant_term
);
5086 /* Try a machine-dependent way of reloading an illegitimate address AD
5087 operand. If we find one, push the reload and return the new address.
5089 MODE is the mode of the enclosing MEM. OPNUM is the operand number
5090 and TYPE is the reload type of the current reload. */
5093 legitimize_reload_address (rtx ad
, machine_mode mode ATTRIBUTE_UNUSED
,
5094 int opnum
, int type
)
5096 if (!optimize
|| TARGET_LONG_DISPLACEMENT
)
5099 if (GET_CODE (ad
) == PLUS
)
5101 rtx tem
= simplify_binary_operation (PLUS
, Pmode
,
5102 XEXP (ad
, 0), XEXP (ad
, 1));
5107 if (GET_CODE (ad
) == PLUS
5108 && GET_CODE (XEXP (ad
, 0)) == REG
5109 && GET_CODE (XEXP (ad
, 1)) == CONST_INT
5110 && !DISP_IN_RANGE (INTVAL (XEXP (ad
, 1))))
5112 HOST_WIDE_INT lower
= INTVAL (XEXP (ad
, 1)) & 0xfff;
5113 HOST_WIDE_INT upper
= INTVAL (XEXP (ad
, 1)) ^ lower
;
5114 rtx cst
, tem
, new_rtx
;
5116 cst
= GEN_INT (upper
);
5117 if (!legitimate_reload_constant_p (cst
))
5118 cst
= force_const_mem (Pmode
, cst
);
5120 tem
= gen_rtx_PLUS (Pmode
, XEXP (ad
, 0), cst
);
5121 new_rtx
= gen_rtx_PLUS (Pmode
, tem
, GEN_INT (lower
));
5123 push_reload (XEXP (tem
, 1), 0, &XEXP (tem
, 1), 0,
5124 BASE_REG_CLASS
, Pmode
, VOIDmode
, 0, 0,
5125 opnum
, (enum reload_type
) type
);
5132 /* Emit code to move LEN bytes from DST to SRC. */
5135 s390_expand_movmem (rtx dst
, rtx src
, rtx len
)
5137 /* When tuning for z10 or higher we rely on the Glibc functions to
5138 do the right thing. Only for constant lengths below 64k we will
5139 generate inline code. */
5140 if (s390_tune
>= PROCESSOR_2097_Z10
5141 && (GET_CODE (len
) != CONST_INT
|| INTVAL (len
) > (1<<16)))
5144 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) >= 0 && INTVAL (len
) <= 256)
5146 if (INTVAL (len
) > 0)
5147 emit_insn (gen_movmem_short (dst
, src
, GEN_INT (INTVAL (len
) - 1)));
5150 else if (TARGET_MVCLE
)
5152 emit_insn (gen_movmem_long (dst
, src
, convert_to_mode (Pmode
, len
, 1)));
5157 rtx dst_addr
, src_addr
, count
, blocks
, temp
;
5158 rtx_code_label
*loop_start_label
= gen_label_rtx ();
5159 rtx_code_label
*loop_end_label
= gen_label_rtx ();
5160 rtx_code_label
*end_label
= gen_label_rtx ();
5163 mode
= GET_MODE (len
);
5164 if (mode
== VOIDmode
)
5167 dst_addr
= gen_reg_rtx (Pmode
);
5168 src_addr
= gen_reg_rtx (Pmode
);
5169 count
= gen_reg_rtx (mode
);
5170 blocks
= gen_reg_rtx (mode
);
5172 convert_move (count
, len
, 1);
5173 emit_cmp_and_jump_insns (count
, const0_rtx
,
5174 EQ
, NULL_RTX
, mode
, 1, end_label
);
5176 emit_move_insn (dst_addr
, force_operand (XEXP (dst
, 0), NULL_RTX
));
5177 emit_move_insn (src_addr
, force_operand (XEXP (src
, 0), NULL_RTX
));
5178 dst
= change_address (dst
, VOIDmode
, dst_addr
);
5179 src
= change_address (src
, VOIDmode
, src_addr
);
5181 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1,
5184 emit_move_insn (count
, temp
);
5186 temp
= expand_binop (mode
, lshr_optab
, count
, GEN_INT (8), blocks
, 1,
5189 emit_move_insn (blocks
, temp
);
5191 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
5192 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
5194 emit_label (loop_start_label
);
5197 && (GET_CODE (len
) != CONST_INT
|| INTVAL (len
) > 768))
5201 /* Issue a read prefetch for the +3 cache line. */
5202 prefetch
= gen_prefetch (gen_rtx_PLUS (Pmode
, src_addr
, GEN_INT (768)),
5203 const0_rtx
, const0_rtx
);
5204 PREFETCH_SCHEDULE_BARRIER_P (prefetch
) = true;
5205 emit_insn (prefetch
);
5207 /* Issue a write prefetch for the +3 cache line. */
5208 prefetch
= gen_prefetch (gen_rtx_PLUS (Pmode
, dst_addr
, GEN_INT (768)),
5209 const1_rtx
, const0_rtx
);
5210 PREFETCH_SCHEDULE_BARRIER_P (prefetch
) = true;
5211 emit_insn (prefetch
);
5214 emit_insn (gen_movmem_short (dst
, src
, GEN_INT (255)));
5215 s390_load_address (dst_addr
,
5216 gen_rtx_PLUS (Pmode
, dst_addr
, GEN_INT (256)));
5217 s390_load_address (src_addr
,
5218 gen_rtx_PLUS (Pmode
, src_addr
, GEN_INT (256)));
5220 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1,
5223 emit_move_insn (blocks
, temp
);
5225 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
5226 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
5228 emit_jump (loop_start_label
);
5229 emit_label (loop_end_label
);
5231 emit_insn (gen_movmem_short (dst
, src
,
5232 convert_to_mode (Pmode
, count
, 1)));
5233 emit_label (end_label
);
5238 /* Emit code to set LEN bytes at DST to VAL.
5239 Make use of clrmem if VAL is zero. */
5242 s390_expand_setmem (rtx dst
, rtx len
, rtx val
)
5244 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) == 0)
5247 gcc_assert (GET_CODE (val
) == CONST_INT
|| GET_MODE (val
) == QImode
);
5249 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) > 0 && INTVAL (len
) <= 257)
5251 if (val
== const0_rtx
&& INTVAL (len
) <= 256)
5252 emit_insn (gen_clrmem_short (dst
, GEN_INT (INTVAL (len
) - 1)));
5255 /* Initialize memory by storing the first byte. */
5256 emit_move_insn (adjust_address (dst
, QImode
, 0), val
);
5258 if (INTVAL (len
) > 1)
5260 /* Initiate 1 byte overlap move.
5261 The first byte of DST is propagated through DSTP1.
5262 Prepare a movmem for: DST+1 = DST (length = LEN - 1).
5263 DST is set to size 1 so the rest of the memory location
5264 does not count as source operand. */
5265 rtx dstp1
= adjust_address (dst
, VOIDmode
, 1);
5266 set_mem_size (dst
, 1);
5268 emit_insn (gen_movmem_short (dstp1
, dst
,
5269 GEN_INT (INTVAL (len
) - 2)));
5274 else if (TARGET_MVCLE
)
5276 val
= force_not_mem (convert_modes (Pmode
, QImode
, val
, 1));
5278 emit_insn (gen_setmem_long_di (dst
, convert_to_mode (Pmode
, len
, 1),
5281 emit_insn (gen_setmem_long_si (dst
, convert_to_mode (Pmode
, len
, 1),
5287 rtx dst_addr
, count
, blocks
, temp
, dstp1
= NULL_RTX
;
5288 rtx_code_label
*loop_start_label
= gen_label_rtx ();
5289 rtx_code_label
*loop_end_label
= gen_label_rtx ();
5290 rtx_code_label
*end_label
= gen_label_rtx ();
5293 mode
= GET_MODE (len
);
5294 if (mode
== VOIDmode
)
5297 dst_addr
= gen_reg_rtx (Pmode
);
5298 count
= gen_reg_rtx (mode
);
5299 blocks
= gen_reg_rtx (mode
);
5301 convert_move (count
, len
, 1);
5302 emit_cmp_and_jump_insns (count
, const0_rtx
,
5303 EQ
, NULL_RTX
, mode
, 1, end_label
);
5305 emit_move_insn (dst_addr
, force_operand (XEXP (dst
, 0), NULL_RTX
));
5306 dst
= change_address (dst
, VOIDmode
, dst_addr
);
5308 if (val
== const0_rtx
)
5309 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1,
5313 dstp1
= adjust_address (dst
, VOIDmode
, 1);
5314 set_mem_size (dst
, 1);
5316 /* Initialize memory by storing the first byte. */
5317 emit_move_insn (adjust_address (dst
, QImode
, 0), val
);
5319 /* If count is 1 we are done. */
5320 emit_cmp_and_jump_insns (count
, const1_rtx
,
5321 EQ
, NULL_RTX
, mode
, 1, end_label
);
5323 temp
= expand_binop (mode
, add_optab
, count
, GEN_INT (-2), count
, 1,
5327 emit_move_insn (count
, temp
);
5329 temp
= expand_binop (mode
, lshr_optab
, count
, GEN_INT (8), blocks
, 1,
5332 emit_move_insn (blocks
, temp
);
5334 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
5335 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
5337 emit_label (loop_start_label
);
5340 && (GET_CODE (len
) != CONST_INT
|| INTVAL (len
) > 1024))
5342 /* Issue a write prefetch for the +4 cache line. */
5343 rtx prefetch
= gen_prefetch (gen_rtx_PLUS (Pmode
, dst_addr
,
5345 const1_rtx
, const0_rtx
);
5346 emit_insn (prefetch
);
5347 PREFETCH_SCHEDULE_BARRIER_P (prefetch
) = true;
5350 if (val
== const0_rtx
)
5351 emit_insn (gen_clrmem_short (dst
, GEN_INT (255)));
5353 emit_insn (gen_movmem_short (dstp1
, dst
, GEN_INT (255)));
5354 s390_load_address (dst_addr
,
5355 gen_rtx_PLUS (Pmode
, dst_addr
, GEN_INT (256)));
5357 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1,
5360 emit_move_insn (blocks
, temp
);
5362 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
5363 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
5365 emit_jump (loop_start_label
);
5366 emit_label (loop_end_label
);
5368 if (val
== const0_rtx
)
5369 emit_insn (gen_clrmem_short (dst
, convert_to_mode (Pmode
, count
, 1)));
5371 emit_insn (gen_movmem_short (dstp1
, dst
, convert_to_mode (Pmode
, count
, 1)));
5372 emit_label (end_label
);
5376 /* Emit code to compare LEN bytes at OP0 with those at OP1,
5377 and return the result in TARGET. */
5380 s390_expand_cmpmem (rtx target
, rtx op0
, rtx op1
, rtx len
)
5382 rtx ccreg
= gen_rtx_REG (CCUmode
, CC_REGNUM
);
5385 /* When tuning for z10 or higher we rely on the Glibc functions to
5386 do the right thing. Only for constant lengths below 64k we will
5387 generate inline code. */
5388 if (s390_tune
>= PROCESSOR_2097_Z10
5389 && (GET_CODE (len
) != CONST_INT
|| INTVAL (len
) > (1<<16)))
5392 /* As the result of CMPINT is inverted compared to what we need,
5393 we have to swap the operands. */
5394 tmp
= op0
; op0
= op1
; op1
= tmp
;
5396 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) >= 0 && INTVAL (len
) <= 256)
5398 if (INTVAL (len
) > 0)
5400 emit_insn (gen_cmpmem_short (op0
, op1
, GEN_INT (INTVAL (len
) - 1)));
5401 emit_insn (gen_cmpint (target
, ccreg
));
5404 emit_move_insn (target
, const0_rtx
);
5406 else if (TARGET_MVCLE
)
5408 emit_insn (gen_cmpmem_long (op0
, op1
, convert_to_mode (Pmode
, len
, 1)));
5409 emit_insn (gen_cmpint (target
, ccreg
));
5413 rtx addr0
, addr1
, count
, blocks
, temp
;
5414 rtx_code_label
*loop_start_label
= gen_label_rtx ();
5415 rtx_code_label
*loop_end_label
= gen_label_rtx ();
5416 rtx_code_label
*end_label
= gen_label_rtx ();
5419 mode
= GET_MODE (len
);
5420 if (mode
== VOIDmode
)
5423 addr0
= gen_reg_rtx (Pmode
);
5424 addr1
= gen_reg_rtx (Pmode
);
5425 count
= gen_reg_rtx (mode
);
5426 blocks
= gen_reg_rtx (mode
);
5428 convert_move (count
, len
, 1);
5429 emit_cmp_and_jump_insns (count
, const0_rtx
,
5430 EQ
, NULL_RTX
, mode
, 1, end_label
);
5432 emit_move_insn (addr0
, force_operand (XEXP (op0
, 0), NULL_RTX
));
5433 emit_move_insn (addr1
, force_operand (XEXP (op1
, 0), NULL_RTX
));
5434 op0
= change_address (op0
, VOIDmode
, addr0
);
5435 op1
= change_address (op1
, VOIDmode
, addr1
);
5437 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1,
5440 emit_move_insn (count
, temp
);
5442 temp
= expand_binop (mode
, lshr_optab
, count
, GEN_INT (8), blocks
, 1,
5445 emit_move_insn (blocks
, temp
);
5447 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
5448 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
5450 emit_label (loop_start_label
);
5453 && (GET_CODE (len
) != CONST_INT
|| INTVAL (len
) > 512))
5457 /* Issue a read prefetch for the +2 cache line of operand 1. */
5458 prefetch
= gen_prefetch (gen_rtx_PLUS (Pmode
, addr0
, GEN_INT (512)),
5459 const0_rtx
, const0_rtx
);
5460 emit_insn (prefetch
);
5461 PREFETCH_SCHEDULE_BARRIER_P (prefetch
) = true;
5463 /* Issue a read prefetch for the +2 cache line of operand 2. */
5464 prefetch
= gen_prefetch (gen_rtx_PLUS (Pmode
, addr1
, GEN_INT (512)),
5465 const0_rtx
, const0_rtx
);
5466 emit_insn (prefetch
);
5467 PREFETCH_SCHEDULE_BARRIER_P (prefetch
) = true;
5470 emit_insn (gen_cmpmem_short (op0
, op1
, GEN_INT (255)));
5471 temp
= gen_rtx_NE (VOIDmode
, ccreg
, const0_rtx
);
5472 temp
= gen_rtx_IF_THEN_ELSE (VOIDmode
, temp
,
5473 gen_rtx_LABEL_REF (VOIDmode
, end_label
), pc_rtx
);
5474 temp
= gen_rtx_SET (pc_rtx
, temp
);
5475 emit_jump_insn (temp
);
5477 s390_load_address (addr0
,
5478 gen_rtx_PLUS (Pmode
, addr0
, GEN_INT (256)));
5479 s390_load_address (addr1
,
5480 gen_rtx_PLUS (Pmode
, addr1
, GEN_INT (256)));
5482 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1,
5485 emit_move_insn (blocks
, temp
);
5487 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
5488 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
5490 emit_jump (loop_start_label
);
5491 emit_label (loop_end_label
);
5493 emit_insn (gen_cmpmem_short (op0
, op1
,
5494 convert_to_mode (Pmode
, count
, 1)));
5495 emit_label (end_label
);
5497 emit_insn (gen_cmpint (target
, ccreg
));
5502 /* Emit a conditional jump to LABEL for condition code mask MASK using
5503 comparsion operator COMPARISON. Return the emitted jump insn. */
5506 s390_emit_ccraw_jump (HOST_WIDE_INT mask
, enum rtx_code comparison
, rtx label
)
5510 gcc_assert (comparison
== EQ
|| comparison
== NE
);
5511 gcc_assert (mask
> 0 && mask
< 15);
5513 temp
= gen_rtx_fmt_ee (comparison
, VOIDmode
,
5514 gen_rtx_REG (CCRAWmode
, CC_REGNUM
), GEN_INT (mask
));
5515 temp
= gen_rtx_IF_THEN_ELSE (VOIDmode
, temp
,
5516 gen_rtx_LABEL_REF (VOIDmode
, label
), pc_rtx
);
5517 temp
= gen_rtx_SET (pc_rtx
, temp
);
5518 return emit_jump_insn (temp
);
5521 /* Emit the instructions to implement strlen of STRING and store the
5522 result in TARGET. The string has the known ALIGNMENT. This
5523 version uses vector instructions and is therefore not appropriate
5524 for targets prior to z13. */
5527 s390_expand_vec_strlen (rtx target
, rtx string
, rtx alignment
)
5529 int very_unlikely
= REG_BR_PROB_BASE
/ 100 - 1;
5530 int very_likely
= REG_BR_PROB_BASE
- 1;
5531 rtx highest_index_to_load_reg
= gen_reg_rtx (Pmode
);
5532 rtx str_reg
= gen_reg_rtx (V16QImode
);
5533 rtx str_addr_base_reg
= gen_reg_rtx (Pmode
);
5534 rtx str_idx_reg
= gen_reg_rtx (Pmode
);
5535 rtx result_reg
= gen_reg_rtx (V16QImode
);
5536 rtx is_aligned_label
= gen_label_rtx ();
5537 rtx into_loop_label
= NULL_RTX
;
5538 rtx loop_start_label
= gen_label_rtx ();
5540 rtx len
= gen_reg_rtx (QImode
);
5543 s390_load_address (str_addr_base_reg
, XEXP (string
, 0));
5544 emit_move_insn (str_idx_reg
, const0_rtx
);
5546 if (INTVAL (alignment
) < 16)
5548 /* Check whether the address happens to be aligned properly so
5549 jump directly to the aligned loop. */
5550 emit_cmp_and_jump_insns (gen_rtx_AND (Pmode
,
5551 str_addr_base_reg
, GEN_INT (15)),
5552 const0_rtx
, EQ
, NULL_RTX
,
5553 Pmode
, 1, is_aligned_label
);
5555 temp
= gen_reg_rtx (Pmode
);
5556 temp
= expand_binop (Pmode
, and_optab
, str_addr_base_reg
,
5557 GEN_INT (15), temp
, 1, OPTAB_DIRECT
);
5558 gcc_assert (REG_P (temp
));
5559 highest_index_to_load_reg
=
5560 expand_binop (Pmode
, sub_optab
, GEN_INT (15), temp
,
5561 highest_index_to_load_reg
, 1, OPTAB_DIRECT
);
5562 gcc_assert (REG_P (highest_index_to_load_reg
));
5563 emit_insn (gen_vllv16qi (str_reg
,
5564 convert_to_mode (SImode
, highest_index_to_load_reg
, 1),
5565 gen_rtx_MEM (BLKmode
, str_addr_base_reg
)));
5567 into_loop_label
= gen_label_rtx ();
5568 s390_emit_jump (into_loop_label
, NULL_RTX
);
5572 emit_label (is_aligned_label
);
5573 LABEL_NUSES (is_aligned_label
) = INTVAL (alignment
) < 16 ? 2 : 1;
5575 /* Reaching this point we are only performing 16 bytes aligned
5577 emit_move_insn (highest_index_to_load_reg
, GEN_INT (15));
5579 emit_label (loop_start_label
);
5580 LABEL_NUSES (loop_start_label
) = 1;
5582 /* Load 16 bytes of the string into VR. */
5583 emit_move_insn (str_reg
,
5584 gen_rtx_MEM (V16QImode
,
5585 gen_rtx_PLUS (Pmode
, str_idx_reg
,
5586 str_addr_base_reg
)));
5587 if (into_loop_label
!= NULL_RTX
)
5589 emit_label (into_loop_label
);
5590 LABEL_NUSES (into_loop_label
) = 1;
5593 /* Increment string index by 16 bytes. */
5594 expand_binop (Pmode
, add_optab
, str_idx_reg
, GEN_INT (16),
5595 str_idx_reg
, 1, OPTAB_DIRECT
);
5597 emit_insn (gen_vec_vfenesv16qi (result_reg
, str_reg
, str_reg
,
5598 GEN_INT (VSTRING_FLAG_ZS
| VSTRING_FLAG_CS
)));
5600 add_int_reg_note (s390_emit_ccraw_jump (8, NE
, loop_start_label
),
5601 REG_BR_PROB
, very_likely
);
5602 emit_insn (gen_vec_extractv16qi (len
, result_reg
, GEN_INT (7)));
5604 /* If the string pointer wasn't aligned we have loaded less then 16
5605 bytes and the remaining bytes got filled with zeros (by vll).
5606 Now we have to check whether the resulting index lies within the
5607 bytes actually part of the string. */
5609 cond
= s390_emit_compare (GT
, convert_to_mode (Pmode
, len
, 1),
5610 highest_index_to_load_reg
);
5611 s390_load_address (highest_index_to_load_reg
,
5612 gen_rtx_PLUS (Pmode
, highest_index_to_load_reg
,
5615 emit_insn (gen_movdicc (str_idx_reg
, cond
,
5616 highest_index_to_load_reg
, str_idx_reg
));
5618 emit_insn (gen_movsicc (str_idx_reg
, cond
,
5619 highest_index_to_load_reg
, str_idx_reg
));
5621 add_int_reg_note (s390_emit_jump (is_aligned_label
, cond
), REG_BR_PROB
,
5624 expand_binop (Pmode
, add_optab
, str_idx_reg
,
5625 GEN_INT (-16), str_idx_reg
, 1, OPTAB_DIRECT
);
5626 /* FIXME: len is already zero extended - so avoid the llgcr emitted
5628 temp
= expand_binop (Pmode
, add_optab
, str_idx_reg
,
5629 convert_to_mode (Pmode
, len
, 1),
5630 target
, 1, OPTAB_DIRECT
);
5632 emit_move_insn (target
, temp
);
5636 s390_expand_vec_movstr (rtx result
, rtx dst
, rtx src
)
5638 int very_unlikely
= REG_BR_PROB_BASE
/ 100 - 1;
5639 rtx temp
= gen_reg_rtx (Pmode
);
5640 rtx src_addr
= XEXP (src
, 0);
5641 rtx dst_addr
= XEXP (dst
, 0);
5642 rtx src_addr_reg
= gen_reg_rtx (Pmode
);
5643 rtx dst_addr_reg
= gen_reg_rtx (Pmode
);
5644 rtx offset
= gen_reg_rtx (Pmode
);
5645 rtx vsrc
= gen_reg_rtx (V16QImode
);
5646 rtx vpos
= gen_reg_rtx (V16QImode
);
5647 rtx loadlen
= gen_reg_rtx (SImode
);
5648 rtx gpos_qi
= gen_reg_rtx(QImode
);
5649 rtx gpos
= gen_reg_rtx (SImode
);
5650 rtx done_label
= gen_label_rtx ();
5651 rtx loop_label
= gen_label_rtx ();
5652 rtx exit_label
= gen_label_rtx ();
5653 rtx full_label
= gen_label_rtx ();
5655 /* Perform a quick check for string ending on the first up to 16
5656 bytes and exit early if successful. */
5658 emit_insn (gen_vlbb (vsrc
, src
, GEN_INT (6)));
5659 emit_insn (gen_lcbb (loadlen
, src_addr
, GEN_INT (6)));
5660 emit_insn (gen_vfenezv16qi (vpos
, vsrc
, vsrc
));
5661 emit_insn (gen_vec_extractv16qi (gpos_qi
, vpos
, GEN_INT (7)));
5662 emit_move_insn (gpos
, gen_rtx_SUBREG (SImode
, gpos_qi
, 0));
5663 /* gpos is the byte index if a zero was found and 16 otherwise.
5664 So if it is lower than the loaded bytes we have a hit. */
5665 emit_cmp_and_jump_insns (gpos
, loadlen
, GE
, NULL_RTX
, SImode
, 1,
5667 emit_insn (gen_vstlv16qi (vsrc
, gpos
, dst
));
5669 force_expand_binop (Pmode
, add_optab
, dst_addr
, gpos
, result
,
5671 emit_jump (exit_label
);
5674 emit_label (full_label
);
5675 LABEL_NUSES (full_label
) = 1;
5677 /* Calculate `offset' so that src + offset points to the last byte
5678 before 16 byte alignment. */
5680 /* temp = src_addr & 0xf */
5681 force_expand_binop (Pmode
, and_optab
, src_addr
, GEN_INT (15), temp
,
5684 /* offset = 0xf - temp */
5685 emit_move_insn (offset
, GEN_INT (15));
5686 force_expand_binop (Pmode
, sub_optab
, offset
, temp
, offset
,
5689 /* Store `offset' bytes in the dstination string. The quick check
5690 has loaded at least `offset' bytes into vsrc. */
5692 emit_insn (gen_vstlv16qi (vsrc
, gen_lowpart (SImode
, offset
), dst
));
5694 /* Advance to the next byte to be loaded. */
5695 force_expand_binop (Pmode
, add_optab
, offset
, const1_rtx
, offset
,
5698 /* Make sure the addresses are single regs which can be used as a
5700 emit_move_insn (src_addr_reg
, src_addr
);
5701 emit_move_insn (dst_addr_reg
, dst_addr
);
5705 emit_label (loop_label
);
5706 LABEL_NUSES (loop_label
) = 1;
5708 emit_move_insn (vsrc
,
5709 gen_rtx_MEM (V16QImode
,
5710 gen_rtx_PLUS (Pmode
, src_addr_reg
, offset
)));
5712 emit_insn (gen_vec_vfenesv16qi (vpos
, vsrc
, vsrc
,
5713 GEN_INT (VSTRING_FLAG_ZS
| VSTRING_FLAG_CS
)));
5714 add_int_reg_note (s390_emit_ccraw_jump (8, EQ
, done_label
),
5715 REG_BR_PROB
, very_unlikely
);
5717 emit_move_insn (gen_rtx_MEM (V16QImode
,
5718 gen_rtx_PLUS (Pmode
, dst_addr_reg
, offset
)),
5721 force_expand_binop (Pmode
, add_optab
, offset
, GEN_INT (16),
5722 offset
, 1, OPTAB_DIRECT
);
5724 emit_jump (loop_label
);
5729 /* We are done. Add the offset of the zero character to the dst_addr
5730 pointer to get the result. */
5732 emit_label (done_label
);
5733 LABEL_NUSES (done_label
) = 1;
5735 force_expand_binop (Pmode
, add_optab
, dst_addr_reg
, offset
, dst_addr_reg
,
5738 emit_insn (gen_vec_extractv16qi (gpos_qi
, vpos
, GEN_INT (7)));
5739 emit_move_insn (gpos
, gen_rtx_SUBREG (SImode
, gpos_qi
, 0));
5741 emit_insn (gen_vstlv16qi (vsrc
, gpos
, gen_rtx_MEM (BLKmode
, dst_addr_reg
)));
5743 force_expand_binop (Pmode
, add_optab
, dst_addr_reg
, gpos
, result
,
5748 emit_label (exit_label
);
5749 LABEL_NUSES (exit_label
) = 1;
5753 /* Expand conditional increment or decrement using alc/slb instructions.
5754 Should generate code setting DST to either SRC or SRC + INCREMENT,
5755 depending on the result of the comparison CMP_OP0 CMP_CODE CMP_OP1.
5756 Returns true if successful, false otherwise.
5758 That makes it possible to implement some if-constructs without jumps e.g.:
5759 (borrow = CC0 | CC1 and carry = CC2 | CC3)
5760 unsigned int a, b, c;
5761 if (a < b) c++; -> CCU b > a -> CC2; c += carry;
5762 if (a < b) c--; -> CCL3 a - b -> borrow; c -= borrow;
5763 if (a <= b) c++; -> CCL3 b - a -> borrow; c += carry;
5764 if (a <= b) c--; -> CCU a <= b -> borrow; c -= borrow;
5766 Checks for EQ and NE with a nonzero value need an additional xor e.g.:
5767 if (a == b) c++; -> CCL3 a ^= b; 0 - a -> borrow; c += carry;
5768 if (a == b) c--; -> CCU a ^= b; a <= 0 -> CC0 | CC1; c -= borrow;
5769 if (a != b) c++; -> CCU a ^= b; a > 0 -> CC2; c += carry;
5770 if (a != b) c--; -> CCL3 a ^= b; 0 - a -> borrow; c -= borrow; */
5773 s390_expand_addcc (enum rtx_code cmp_code
, rtx cmp_op0
, rtx cmp_op1
,
5774 rtx dst
, rtx src
, rtx increment
)
5776 machine_mode cmp_mode
;
5777 machine_mode cc_mode
;
5783 if ((GET_MODE (cmp_op0
) == SImode
|| GET_MODE (cmp_op0
) == VOIDmode
)
5784 && (GET_MODE (cmp_op1
) == SImode
|| GET_MODE (cmp_op1
) == VOIDmode
))
5786 else if ((GET_MODE (cmp_op0
) == DImode
|| GET_MODE (cmp_op0
) == VOIDmode
)
5787 && (GET_MODE (cmp_op1
) == DImode
|| GET_MODE (cmp_op1
) == VOIDmode
))
5792 /* Try ADD LOGICAL WITH CARRY. */
5793 if (increment
== const1_rtx
)
5795 /* Determine CC mode to use. */
5796 if (cmp_code
== EQ
|| cmp_code
== NE
)
5798 if (cmp_op1
!= const0_rtx
)
5800 cmp_op0
= expand_simple_binop (cmp_mode
, XOR
, cmp_op0
, cmp_op1
,
5801 NULL_RTX
, 0, OPTAB_WIDEN
);
5802 cmp_op1
= const0_rtx
;
5805 cmp_code
= cmp_code
== EQ
? LEU
: GTU
;
5808 if (cmp_code
== LTU
|| cmp_code
== LEU
)
5813 cmp_code
= swap_condition (cmp_code
);
5830 /* Emit comparison instruction pattern. */
5831 if (!register_operand (cmp_op0
, cmp_mode
))
5832 cmp_op0
= force_reg (cmp_mode
, cmp_op0
);
5834 insn
= gen_rtx_SET (gen_rtx_REG (cc_mode
, CC_REGNUM
),
5835 gen_rtx_COMPARE (cc_mode
, cmp_op0
, cmp_op1
));
5836 /* We use insn_invalid_p here to add clobbers if required. */
5837 ret
= insn_invalid_p (emit_insn (insn
), false);
5840 /* Emit ALC instruction pattern. */
5841 op_res
= gen_rtx_fmt_ee (cmp_code
, GET_MODE (dst
),
5842 gen_rtx_REG (cc_mode
, CC_REGNUM
),
5845 if (src
!= const0_rtx
)
5847 if (!register_operand (src
, GET_MODE (dst
)))
5848 src
= force_reg (GET_MODE (dst
), src
);
5850 op_res
= gen_rtx_PLUS (GET_MODE (dst
), op_res
, src
);
5851 op_res
= gen_rtx_PLUS (GET_MODE (dst
), op_res
, const0_rtx
);
5854 p
= rtvec_alloc (2);
5856 gen_rtx_SET (dst
, op_res
);
5858 gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
5859 emit_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
5864 /* Try SUBTRACT LOGICAL WITH BORROW. */
5865 if (increment
== constm1_rtx
)
5867 /* Determine CC mode to use. */
5868 if (cmp_code
== EQ
|| cmp_code
== NE
)
5870 if (cmp_op1
!= const0_rtx
)
5872 cmp_op0
= expand_simple_binop (cmp_mode
, XOR
, cmp_op0
, cmp_op1
,
5873 NULL_RTX
, 0, OPTAB_WIDEN
);
5874 cmp_op1
= const0_rtx
;
5877 cmp_code
= cmp_code
== EQ
? LEU
: GTU
;
5880 if (cmp_code
== GTU
|| cmp_code
== GEU
)
5885 cmp_code
= swap_condition (cmp_code
);
5902 /* Emit comparison instruction pattern. */
5903 if (!register_operand (cmp_op0
, cmp_mode
))
5904 cmp_op0
= force_reg (cmp_mode
, cmp_op0
);
5906 insn
= gen_rtx_SET (gen_rtx_REG (cc_mode
, CC_REGNUM
),
5907 gen_rtx_COMPARE (cc_mode
, cmp_op0
, cmp_op1
));
5908 /* We use insn_invalid_p here to add clobbers if required. */
5909 ret
= insn_invalid_p (emit_insn (insn
), false);
5912 /* Emit SLB instruction pattern. */
5913 if (!register_operand (src
, GET_MODE (dst
)))
5914 src
= force_reg (GET_MODE (dst
), src
);
5916 op_res
= gen_rtx_MINUS (GET_MODE (dst
),
5917 gen_rtx_MINUS (GET_MODE (dst
), src
, const0_rtx
),
5918 gen_rtx_fmt_ee (cmp_code
, GET_MODE (dst
),
5919 gen_rtx_REG (cc_mode
, CC_REGNUM
),
5921 p
= rtvec_alloc (2);
5923 gen_rtx_SET (dst
, op_res
);
5925 gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
5926 emit_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
5934 /* Expand code for the insv template. Return true if successful. */
5937 s390_expand_insv (rtx dest
, rtx op1
, rtx op2
, rtx src
)
5939 int bitsize
= INTVAL (op1
);
5940 int bitpos
= INTVAL (op2
);
5941 machine_mode mode
= GET_MODE (dest
);
5943 int smode_bsize
, mode_bsize
;
5946 if (bitsize
+ bitpos
> GET_MODE_BITSIZE (mode
))
5949 /* Generate INSERT IMMEDIATE (IILL et al). */
5950 /* (set (ze (reg)) (const_int)). */
5952 && register_operand (dest
, word_mode
)
5953 && (bitpos
% 16) == 0
5954 && (bitsize
% 16) == 0
5955 && const_int_operand (src
, VOIDmode
))
5957 HOST_WIDE_INT val
= INTVAL (src
);
5958 int regpos
= bitpos
+ bitsize
;
5960 while (regpos
> bitpos
)
5962 machine_mode putmode
;
5965 if (TARGET_EXTIMM
&& (regpos
% 32 == 0) && (regpos
>= bitpos
+ 32))
5970 putsize
= GET_MODE_BITSIZE (putmode
);
5972 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
,
5975 gen_int_mode (val
, putmode
));
5978 gcc_assert (regpos
== bitpos
);
5982 smode
= smallest_mode_for_size (bitsize
, MODE_INT
);
5983 smode_bsize
= GET_MODE_BITSIZE (smode
);
5984 mode_bsize
= GET_MODE_BITSIZE (mode
);
5986 /* Generate STORE CHARACTERS UNDER MASK (STCM et al). */
5988 && (bitsize
% BITS_PER_UNIT
) == 0
5990 && (register_operand (src
, word_mode
)
5991 || const_int_operand (src
, VOIDmode
)))
5993 /* Emit standard pattern if possible. */
5994 if (smode_bsize
== bitsize
)
5996 emit_move_insn (adjust_address (dest
, smode
, 0),
5997 gen_lowpart (smode
, src
));
6001 /* (set (ze (mem)) (const_int)). */
6002 else if (const_int_operand (src
, VOIDmode
))
6004 int size
= bitsize
/ BITS_PER_UNIT
;
6005 rtx src_mem
= adjust_address (force_const_mem (word_mode
, src
),
6007 UNITS_PER_WORD
- size
);
6009 dest
= adjust_address (dest
, BLKmode
, 0);
6010 set_mem_size (dest
, size
);
6011 s390_expand_movmem (dest
, src_mem
, GEN_INT (size
));
6015 /* (set (ze (mem)) (reg)). */
6016 else if (register_operand (src
, word_mode
))
6019 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
, op1
,
6023 /* Emit st,stcmh sequence. */
6024 int stcmh_width
= bitsize
- 32;
6025 int size
= stcmh_width
/ BITS_PER_UNIT
;
6027 emit_move_insn (adjust_address (dest
, SImode
, size
),
6028 gen_lowpart (SImode
, src
));
6029 set_mem_size (dest
, size
);
6030 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
,
6031 GEN_INT (stcmh_width
),
6033 gen_rtx_LSHIFTRT (word_mode
, src
, GEN_INT (32)));
6039 /* Generate INSERT CHARACTERS UNDER MASK (IC, ICM et al). */
6040 if ((bitpos
% BITS_PER_UNIT
) == 0
6041 && (bitsize
% BITS_PER_UNIT
) == 0
6042 && (bitpos
& 32) == ((bitpos
+ bitsize
- 1) & 32)
6044 && (mode
== DImode
|| mode
== SImode
)
6045 && register_operand (dest
, mode
))
6047 /* Emit a strict_low_part pattern if possible. */
6048 if (smode_bsize
== bitsize
&& bitpos
== mode_bsize
- smode_bsize
)
6050 op
= gen_rtx_STRICT_LOW_PART (VOIDmode
, gen_lowpart (smode
, dest
));
6051 op
= gen_rtx_SET (op
, gen_lowpart (smode
, src
));
6052 clobber
= gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
6053 emit_insn (gen_rtx_PARALLEL (VOIDmode
, gen_rtvec (2, op
, clobber
)));
6057 /* ??? There are more powerful versions of ICM that are not
6058 completely represented in the md file. */
6061 /* For z10, generate ROTATE THEN INSERT SELECTED BITS (RISBG et al). */
6062 if (TARGET_Z10
&& (mode
== DImode
|| mode
== SImode
))
6064 machine_mode mode_s
= GET_MODE (src
);
6066 if (CONSTANT_P (src
))
6068 /* For constant zero values the representation with AND
6069 appears to be folded in more situations than the (set
6070 (zero_extract) ...).
6071 We only do this when the start and end of the bitfield
6072 remain in the same SImode chunk. That way nihf or nilf
6074 The AND patterns might still generate a risbg for this. */
6075 if (src
== const0_rtx
&& bitpos
/ 32 == (bitpos
+ bitsize
- 1) / 32)
6078 src
= force_reg (mode
, src
);
6080 else if (mode_s
!= mode
)
6082 gcc_assert (GET_MODE_BITSIZE (mode_s
) >= bitsize
);
6083 src
= force_reg (mode_s
, src
);
6084 src
= gen_lowpart (mode
, src
);
6087 op
= gen_rtx_ZERO_EXTRACT (mode
, dest
, op1
, op2
),
6088 op
= gen_rtx_SET (op
, src
);
6092 clobber
= gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
6093 op
= gen_rtx_PARALLEL (VOIDmode
, gen_rtvec (2, op
, clobber
));
6103 /* A subroutine of s390_expand_cs_hqi and s390_expand_atomic which returns a
6104 register that holds VAL of mode MODE shifted by COUNT bits. */
6107 s390_expand_mask_and_shift (rtx val
, machine_mode mode
, rtx count
)
6109 val
= expand_simple_binop (SImode
, AND
, val
, GEN_INT (GET_MODE_MASK (mode
)),
6110 NULL_RTX
, 1, OPTAB_DIRECT
);
6111 return expand_simple_binop (SImode
, ASHIFT
, val
, count
,
6112 NULL_RTX
, 1, OPTAB_DIRECT
);
6115 /* Generate a vector comparison COND of CMP_OP1 and CMP_OP2 and store
6116 the result in TARGET. */
6119 s390_expand_vec_compare (rtx target
, enum rtx_code cond
,
6120 rtx cmp_op1
, rtx cmp_op2
)
6122 machine_mode mode
= GET_MODE (target
);
6123 bool neg_p
= false, swap_p
= false;
6126 if (GET_MODE (cmp_op1
) == V2DFmode
)
6130 /* NE a != b -> !(a == b) */
6131 case NE
: cond
= EQ
; neg_p
= true; break;
6132 /* UNGT a u> b -> !(b >= a) */
6133 case UNGT
: cond
= GE
; neg_p
= true; swap_p
= true; break;
6134 /* UNGE a u>= b -> !(b > a) */
6135 case UNGE
: cond
= GT
; neg_p
= true; swap_p
= true; break;
6136 /* LE: a <= b -> b >= a */
6137 case LE
: cond
= GE
; swap_p
= true; break;
6138 /* UNLE: a u<= b -> !(a > b) */
6139 case UNLE
: cond
= GT
; neg_p
= true; break;
6140 /* LT: a < b -> b > a */
6141 case LT
: cond
= GT
; swap_p
= true; break;
6142 /* UNLT: a u< b -> !(a >= b) */
6143 case UNLT
: cond
= GE
; neg_p
= true; break;
6145 emit_insn (gen_vec_cmpuneqv2df (target
, cmp_op1
, cmp_op2
));
6148 emit_insn (gen_vec_cmpltgtv2df (target
, cmp_op1
, cmp_op2
));
6151 emit_insn (gen_vec_orderedv2df (target
, cmp_op1
, cmp_op2
));
6154 emit_insn (gen_vec_unorderedv2df (target
, cmp_op1
, cmp_op2
));
6163 /* NE: a != b -> !(a == b) */
6164 case NE
: cond
= EQ
; neg_p
= true; break;
6165 /* GE: a >= b -> !(b > a) */
6166 case GE
: cond
= GT
; neg_p
= true; swap_p
= true; break;
6167 /* GEU: a >= b -> !(b > a) */
6168 case GEU
: cond
= GTU
; neg_p
= true; swap_p
= true; break;
6169 /* LE: a <= b -> !(a > b) */
6170 case LE
: cond
= GT
; neg_p
= true; break;
6171 /* LEU: a <= b -> !(a > b) */
6172 case LEU
: cond
= GTU
; neg_p
= true; break;
6173 /* LT: a < b -> b > a */
6174 case LT
: cond
= GT
; swap_p
= true; break;
6175 /* LTU: a < b -> b > a */
6176 case LTU
: cond
= GTU
; swap_p
= true; break;
6183 tmp
= cmp_op1
; cmp_op1
= cmp_op2
; cmp_op2
= tmp
;
6186 emit_insn (gen_rtx_SET (target
, gen_rtx_fmt_ee (cond
,
6188 cmp_op1
, cmp_op2
)));
6190 emit_insn (gen_rtx_SET (target
, gen_rtx_NOT (mode
, target
)));
6193 /* Expand the comparison CODE of CMP1 and CMP2 and copy 1 or 0 into
6194 TARGET if either all (ALL_P is true) or any (ALL_P is false) of the
6195 elements in CMP1 and CMP2 fulfill the comparison. */
6197 s390_expand_vec_compare_cc (rtx target
, enum rtx_code code
,
6198 rtx cmp1
, rtx cmp2
, bool all_p
)
6200 enum rtx_code new_code
= code
;
6201 machine_mode cmp_mode
, full_cmp_mode
, scratch_mode
;
6202 rtx tmp_reg
= gen_reg_rtx (SImode
);
6203 bool swap_p
= false;
6205 if (GET_MODE_CLASS (GET_MODE (cmp1
)) == MODE_VECTOR_INT
)
6209 case EQ
: cmp_mode
= CCVEQmode
; break;
6210 case NE
: cmp_mode
= CCVEQmode
; break;
6211 case GT
: cmp_mode
= CCVHmode
; break;
6212 case GE
: cmp_mode
= CCVHmode
; new_code
= LE
; swap_p
= true; break;
6213 case LT
: cmp_mode
= CCVHmode
; new_code
= GT
; swap_p
= true; break;
6214 case LE
: cmp_mode
= CCVHmode
; new_code
= LE
; break;
6215 case GTU
: cmp_mode
= CCVHUmode
; break;
6216 case GEU
: cmp_mode
= CCVHUmode
; new_code
= LEU
; swap_p
= true; break;
6217 case LTU
: cmp_mode
= CCVHUmode
; new_code
= GTU
; swap_p
= true; break;
6218 case LEU
: cmp_mode
= CCVHUmode
; new_code
= LEU
; break;
6219 default: gcc_unreachable ();
6221 scratch_mode
= GET_MODE (cmp1
);
6223 else if (GET_MODE (cmp1
) == V2DFmode
)
6227 case EQ
: cmp_mode
= CCVEQmode
; break;
6228 case NE
: cmp_mode
= CCVEQmode
; break;
6229 case GT
: cmp_mode
= CCVFHmode
; break;
6230 case GE
: cmp_mode
= CCVFHEmode
; break;
6231 case UNLE
: cmp_mode
= CCVFHmode
; break;
6232 case UNLT
: cmp_mode
= CCVFHEmode
; break;
6233 case LT
: cmp_mode
= CCVFHmode
; new_code
= GT
; swap_p
= true; break;
6234 case LE
: cmp_mode
= CCVFHEmode
; new_code
= GE
; swap_p
= true; break;
6235 default: gcc_unreachable ();
6237 scratch_mode
= V2DImode
;
6245 case CCVEQmode
: full_cmp_mode
= CCVEQANYmode
; break;
6246 case CCVHmode
: full_cmp_mode
= CCVHANYmode
; break;
6247 case CCVHUmode
: full_cmp_mode
= CCVHUANYmode
; break;
6248 case CCVFHmode
: full_cmp_mode
= CCVFHANYmode
; break;
6249 case CCVFHEmode
: full_cmp_mode
= CCVFHEANYmode
; break;
6250 default: gcc_unreachable ();
6253 /* The modes without ANY match the ALL modes. */
6254 full_cmp_mode
= cmp_mode
;
6263 emit_insn (gen_rtx_PARALLEL (VOIDmode
,
6264 gen_rtvec (2, gen_rtx_SET (
6265 gen_rtx_REG (cmp_mode
, CC_REGNUM
),
6266 gen_rtx_COMPARE (cmp_mode
, cmp1
, cmp2
)),
6267 gen_rtx_CLOBBER (VOIDmode
,
6268 gen_rtx_SCRATCH (scratch_mode
)))));
6269 emit_move_insn (target
, const0_rtx
);
6270 emit_move_insn (tmp_reg
, const1_rtx
);
6272 emit_move_insn (target
,
6273 gen_rtx_IF_THEN_ELSE (SImode
,
6274 gen_rtx_fmt_ee (new_code
, VOIDmode
,
6275 gen_rtx_REG (full_cmp_mode
, CC_REGNUM
),
6280 /* Generate a vector comparison expression loading either elements of
6281 THEN or ELS into TARGET depending on the comparison COND of CMP_OP1
6285 s390_expand_vcond (rtx target
, rtx then
, rtx els
,
6286 enum rtx_code cond
, rtx cmp_op1
, rtx cmp_op2
)
6289 machine_mode result_mode
;
6292 machine_mode target_mode
= GET_MODE (target
);
6293 machine_mode cmp_mode
= GET_MODE (cmp_op1
);
6294 rtx op
= (cond
== LT
) ? els
: then
;
6296 /* Try to optimize x < 0 ? -1 : 0 into (signed) x >> 31
6297 and x < 0 ? 1 : 0 into (unsigned) x >> 31. Likewise
6298 for short and byte (x >> 15 and x >> 7 respectively). */
6299 if ((cond
== LT
|| cond
== GE
)
6300 && target_mode
== cmp_mode
6301 && cmp_op2
== CONST0_RTX (cmp_mode
)
6302 && op
== CONST0_RTX (target_mode
)
6303 && s390_vector_mode_supported_p (target_mode
)
6304 && GET_MODE_CLASS (target_mode
) == MODE_VECTOR_INT
)
6306 rtx negop
= (cond
== LT
) ? then
: els
;
6308 int shift
= GET_MODE_BITSIZE (GET_MODE_INNER (target_mode
)) - 1;
6310 /* if x < 0 ? 1 : 0 or if x >= 0 ? 0 : 1 */
6311 if (negop
== CONST1_RTX (target_mode
))
6313 rtx res
= expand_simple_binop (cmp_mode
, LSHIFTRT
, cmp_op1
,
6314 GEN_INT (shift
), target
,
6317 emit_move_insn (target
, res
);
6321 /* if x < 0 ? -1 : 0 or if x >= 0 ? 0 : -1 */
6322 else if (all_ones_operand (negop
, target_mode
))
6324 rtx res
= expand_simple_binop (cmp_mode
, ASHIFTRT
, cmp_op1
,
6325 GEN_INT (shift
), target
,
6328 emit_move_insn (target
, res
);
6333 /* We always use an integral type vector to hold the comparison
6335 result_mode
= cmp_mode
== V2DFmode
? V2DImode
: cmp_mode
;
6336 result_target
= gen_reg_rtx (result_mode
);
6338 /* We allow vector immediates as comparison operands that
6339 can be handled by the optimization above but not by the
6340 following code. Hence, force them into registers here. */
6341 if (!REG_P (cmp_op1
))
6342 cmp_op1
= force_reg (GET_MODE (cmp_op1
), cmp_op1
);
6344 if (!REG_P (cmp_op2
))
6345 cmp_op2
= force_reg (GET_MODE (cmp_op2
), cmp_op2
);
6347 s390_expand_vec_compare (result_target
, cond
,
6350 /* If the results are supposed to be either -1 or 0 we are done
6351 since this is what our compare instructions generate anyway. */
6352 if (all_ones_operand (then
, GET_MODE (then
))
6353 && const0_operand (els
, GET_MODE (els
)))
6355 emit_move_insn (target
, gen_rtx_SUBREG (target_mode
,
6360 /* Otherwise we will do a vsel afterwards. */
6361 /* This gets triggered e.g.
6362 with gcc.c-torture/compile/pr53410-1.c */
6364 then
= force_reg (target_mode
, then
);
6367 els
= force_reg (target_mode
, els
);
6369 tmp
= gen_rtx_fmt_ee (EQ
, VOIDmode
,
6371 CONST0_RTX (result_mode
));
6373 /* We compared the result against zero above so we have to swap then
6375 tmp
= gen_rtx_IF_THEN_ELSE (target_mode
, tmp
, els
, then
);
6377 gcc_assert (target_mode
== GET_MODE (then
));
6378 emit_insn (gen_rtx_SET (target
, tmp
));
6381 /* Emit the RTX necessary to initialize the vector TARGET with values
6384 s390_expand_vec_init (rtx target
, rtx vals
)
6386 machine_mode mode
= GET_MODE (target
);
6387 machine_mode inner_mode
= GET_MODE_INNER (mode
);
6388 int n_elts
= GET_MODE_NUNITS (mode
);
6389 bool all_same
= true, all_regs
= true, all_const_int
= true;
6393 for (i
= 0; i
< n_elts
; ++i
)
6395 x
= XVECEXP (vals
, 0, i
);
6397 if (!CONST_INT_P (x
))
6398 all_const_int
= false;
6400 if (i
> 0 && !rtx_equal_p (x
, XVECEXP (vals
, 0, 0)))
6407 /* Use vector gen mask or vector gen byte mask if possible. */
6408 if (all_same
&& all_const_int
6409 && (XVECEXP (vals
, 0, 0) == const0_rtx
6410 || s390_contiguous_bitmask_vector_p (XVECEXP (vals
, 0, 0),
6412 || s390_bytemask_vector_p (XVECEXP (vals
, 0, 0), NULL
)))
6414 emit_insn (gen_rtx_SET (target
,
6415 gen_rtx_CONST_VECTOR (mode
, XVEC (vals
, 0))));
6421 emit_insn (gen_rtx_SET (target
,
6422 gen_rtx_VEC_DUPLICATE (mode
,
6423 XVECEXP (vals
, 0, 0))));
6427 if (all_regs
&& REG_P (target
) && n_elts
== 2 && inner_mode
== DImode
)
6429 /* Use vector load pair. */
6430 emit_insn (gen_rtx_SET (target
,
6431 gen_rtx_VEC_CONCAT (mode
,
6432 XVECEXP (vals
, 0, 0),
6433 XVECEXP (vals
, 0, 1))));
6437 /* We are about to set the vector elements one by one. Zero out the
6438 full register first in order to help the data flow framework to
6439 detect it as full VR set. */
6440 emit_insn (gen_rtx_SET (target
, CONST0_RTX (mode
)));
6442 /* Unfortunately the vec_init expander is not allowed to fail. So
6443 we have to implement the fallback ourselves. */
6444 for (i
= 0; i
< n_elts
; i
++)
6445 emit_insn (gen_rtx_SET (target
,
6446 gen_rtx_UNSPEC (mode
,
6447 gen_rtvec (3, XVECEXP (vals
, 0, i
),
6448 GEN_INT (i
), target
),
6452 /* Structure to hold the initial parameters for a compare_and_swap operation
6453 in HImode and QImode. */
6455 struct alignment_context
6457 rtx memsi
; /* SI aligned memory location. */
6458 rtx shift
; /* Bit offset with regard to lsb. */
6459 rtx modemask
; /* Mask of the HQImode shifted by SHIFT bits. */
6460 rtx modemaski
; /* ~modemask */
6461 bool aligned
; /* True if memory is aligned, false else. */
6464 /* A subroutine of s390_expand_cs_hqi and s390_expand_atomic to initialize
6465 structure AC for transparent simplifying, if the memory alignment is known
6466 to be at least 32bit. MEM is the memory location for the actual operation
6467 and MODE its mode. */
6470 init_alignment_context (struct alignment_context
*ac
, rtx mem
,
6473 ac
->shift
= GEN_INT (GET_MODE_SIZE (SImode
) - GET_MODE_SIZE (mode
));
6474 ac
->aligned
= (MEM_ALIGN (mem
) >= GET_MODE_BITSIZE (SImode
));
6477 ac
->memsi
= adjust_address (mem
, SImode
, 0); /* Memory is aligned. */
6480 /* Alignment is unknown. */
6481 rtx byteoffset
, addr
, align
;
6483 /* Force the address into a register. */
6484 addr
= force_reg (Pmode
, XEXP (mem
, 0));
6486 /* Align it to SImode. */
6487 align
= expand_simple_binop (Pmode
, AND
, addr
,
6488 GEN_INT (-GET_MODE_SIZE (SImode
)),
6489 NULL_RTX
, 1, OPTAB_DIRECT
);
6491 ac
->memsi
= gen_rtx_MEM (SImode
, align
);
6492 MEM_VOLATILE_P (ac
->memsi
) = MEM_VOLATILE_P (mem
);
6493 set_mem_alias_set (ac
->memsi
, ALIAS_SET_MEMORY_BARRIER
);
6494 set_mem_align (ac
->memsi
, GET_MODE_BITSIZE (SImode
));
6496 /* Calculate shiftcount. */
6497 byteoffset
= expand_simple_binop (Pmode
, AND
, addr
,
6498 GEN_INT (GET_MODE_SIZE (SImode
) - 1),
6499 NULL_RTX
, 1, OPTAB_DIRECT
);
6500 /* As we already have some offset, evaluate the remaining distance. */
6501 ac
->shift
= expand_simple_binop (SImode
, MINUS
, ac
->shift
, byteoffset
,
6502 NULL_RTX
, 1, OPTAB_DIRECT
);
6505 /* Shift is the byte count, but we need the bitcount. */
6506 ac
->shift
= expand_simple_binop (SImode
, ASHIFT
, ac
->shift
, GEN_INT (3),
6507 NULL_RTX
, 1, OPTAB_DIRECT
);
6509 /* Calculate masks. */
6510 ac
->modemask
= expand_simple_binop (SImode
, ASHIFT
,
6511 GEN_INT (GET_MODE_MASK (mode
)),
6512 ac
->shift
, NULL_RTX
, 1, OPTAB_DIRECT
);
6513 ac
->modemaski
= expand_simple_unop (SImode
, NOT
, ac
->modemask
,
6517 /* A subroutine of s390_expand_cs_hqi. Insert INS into VAL. If possible,
6518 use a single insv insn into SEQ2. Otherwise, put prep insns in SEQ1 and
6519 perform the merge in SEQ2. */
6522 s390_two_part_insv (struct alignment_context
*ac
, rtx
*seq1
, rtx
*seq2
,
6523 machine_mode mode
, rtx val
, rtx ins
)
6530 tmp
= copy_to_mode_reg (SImode
, val
);
6531 if (s390_expand_insv (tmp
, GEN_INT (GET_MODE_BITSIZE (mode
)),
6535 *seq2
= get_insns ();
6542 /* Failed to use insv. Generate a two part shift and mask. */
6544 tmp
= s390_expand_mask_and_shift (ins
, mode
, ac
->shift
);
6545 *seq1
= get_insns ();
6549 tmp
= expand_simple_binop (SImode
, IOR
, tmp
, val
, NULL_RTX
, 1, OPTAB_DIRECT
);
6550 *seq2
= get_insns ();
6556 /* Expand an atomic compare and swap operation for HImode and QImode. MEM is
6557 the memory location, CMP the old value to compare MEM with and NEW_RTX the
6558 value to set if CMP == MEM. */
6561 s390_expand_cs_hqi (machine_mode mode
, rtx btarget
, rtx vtarget
, rtx mem
,
6562 rtx cmp
, rtx new_rtx
, bool is_weak
)
6564 struct alignment_context ac
;
6565 rtx cmpv
, newv
, val
, cc
, seq0
, seq1
, seq2
, seq3
;
6566 rtx res
= gen_reg_rtx (SImode
);
6567 rtx_code_label
*csloop
= NULL
, *csend
= NULL
;
6569 gcc_assert (MEM_P (mem
));
6571 init_alignment_context (&ac
, mem
, mode
);
6573 /* Load full word. Subsequent loads are performed by CS. */
6574 val
= expand_simple_binop (SImode
, AND
, ac
.memsi
, ac
.modemaski
,
6575 NULL_RTX
, 1, OPTAB_DIRECT
);
6577 /* Prepare insertions of cmp and new_rtx into the loaded value. When
6578 possible, we try to use insv to make this happen efficiently. If
6579 that fails we'll generate code both inside and outside the loop. */
6580 cmpv
= s390_two_part_insv (&ac
, &seq0
, &seq2
, mode
, val
, cmp
);
6581 newv
= s390_two_part_insv (&ac
, &seq1
, &seq3
, mode
, val
, new_rtx
);
6588 /* Start CS loop. */
6591 /* Begin assuming success. */
6592 emit_move_insn (btarget
, const1_rtx
);
6594 csloop
= gen_label_rtx ();
6595 csend
= gen_label_rtx ();
6596 emit_label (csloop
);
6599 /* val = "<mem>00..0<mem>"
6600 * cmp = "00..0<cmp>00..0"
6601 * new = "00..0<new>00..0"
6607 cc
= s390_emit_compare_and_swap (EQ
, res
, ac
.memsi
, cmpv
, newv
);
6609 emit_insn (gen_cstorecc4 (btarget
, cc
, XEXP (cc
, 0), XEXP (cc
, 1)));
6614 /* Jump to end if we're done (likely?). */
6615 s390_emit_jump (csend
, cc
);
6617 /* Check for changes outside mode, and loop internal if so.
6618 Arrange the moves so that the compare is adjacent to the
6619 branch so that we can generate CRJ. */
6620 tmp
= copy_to_reg (val
);
6621 force_expand_binop (SImode
, and_optab
, res
, ac
.modemaski
, val
,
6623 cc
= s390_emit_compare (NE
, val
, tmp
);
6624 s390_emit_jump (csloop
, cc
);
6627 emit_move_insn (btarget
, const0_rtx
);
6631 /* Return the correct part of the bitfield. */
6632 convert_move (vtarget
, expand_simple_binop (SImode
, LSHIFTRT
, res
, ac
.shift
,
6633 NULL_RTX
, 1, OPTAB_DIRECT
), 1);
6636 /* Expand an atomic operation CODE of mode MODE. MEM is the memory location
6637 and VAL the value to play with. If AFTER is true then store the value
6638 MEM holds after the operation, if AFTER is false then store the value MEM
6639 holds before the operation. If TARGET is zero then discard that value, else
6640 store it to TARGET. */
6643 s390_expand_atomic (machine_mode mode
, enum rtx_code code
,
6644 rtx target
, rtx mem
, rtx val
, bool after
)
6646 struct alignment_context ac
;
6648 rtx new_rtx
= gen_reg_rtx (SImode
);
6649 rtx orig
= gen_reg_rtx (SImode
);
6650 rtx_code_label
*csloop
= gen_label_rtx ();
6652 gcc_assert (!target
|| register_operand (target
, VOIDmode
));
6653 gcc_assert (MEM_P (mem
));
6655 init_alignment_context (&ac
, mem
, mode
);
6657 /* Shift val to the correct bit positions.
6658 Preserve "icm", but prevent "ex icm". */
6659 if (!(ac
.aligned
&& code
== SET
&& MEM_P (val
)))
6660 val
= s390_expand_mask_and_shift (val
, mode
, ac
.shift
);
6662 /* Further preparation insns. */
6663 if (code
== PLUS
|| code
== MINUS
)
6664 emit_move_insn (orig
, val
);
6665 else if (code
== MULT
|| code
== AND
) /* val = "11..1<val>11..1" */
6666 val
= expand_simple_binop (SImode
, XOR
, val
, ac
.modemaski
,
6667 NULL_RTX
, 1, OPTAB_DIRECT
);
6669 /* Load full word. Subsequent loads are performed by CS. */
6670 cmp
= force_reg (SImode
, ac
.memsi
);
6672 /* Start CS loop. */
6673 emit_label (csloop
);
6674 emit_move_insn (new_rtx
, cmp
);
6676 /* Patch new with val at correct position. */
6681 val
= expand_simple_binop (SImode
, code
, new_rtx
, orig
,
6682 NULL_RTX
, 1, OPTAB_DIRECT
);
6683 val
= expand_simple_binop (SImode
, AND
, val
, ac
.modemask
,
6684 NULL_RTX
, 1, OPTAB_DIRECT
);
6687 if (ac
.aligned
&& MEM_P (val
))
6688 store_bit_field (new_rtx
, GET_MODE_BITSIZE (mode
), 0,
6689 0, 0, SImode
, val
, false);
6692 new_rtx
= expand_simple_binop (SImode
, AND
, new_rtx
, ac
.modemaski
,
6693 NULL_RTX
, 1, OPTAB_DIRECT
);
6694 new_rtx
= expand_simple_binop (SImode
, IOR
, new_rtx
, val
,
6695 NULL_RTX
, 1, OPTAB_DIRECT
);
6701 new_rtx
= expand_simple_binop (SImode
, code
, new_rtx
, val
,
6702 NULL_RTX
, 1, OPTAB_DIRECT
);
6704 case MULT
: /* NAND */
6705 new_rtx
= expand_simple_binop (SImode
, AND
, new_rtx
, val
,
6706 NULL_RTX
, 1, OPTAB_DIRECT
);
6707 new_rtx
= expand_simple_binop (SImode
, XOR
, new_rtx
, ac
.modemask
,
6708 NULL_RTX
, 1, OPTAB_DIRECT
);
6714 s390_emit_jump (csloop
, s390_emit_compare_and_swap (NE
, cmp
,
6715 ac
.memsi
, cmp
, new_rtx
));
6717 /* Return the correct part of the bitfield. */
6719 convert_move (target
, expand_simple_binop (SImode
, LSHIFTRT
,
6720 after
? new_rtx
: cmp
, ac
.shift
,
6721 NULL_RTX
, 1, OPTAB_DIRECT
), 1);
6724 /* This is called from dwarf2out.c via TARGET_ASM_OUTPUT_DWARF_DTPREL.
6725 We need to emit DTP-relative relocations. */
6727 static void s390_output_dwarf_dtprel (FILE *, int, rtx
) ATTRIBUTE_UNUSED
;
6730 s390_output_dwarf_dtprel (FILE *file
, int size
, rtx x
)
6735 fputs ("\t.long\t", file
);
6738 fputs ("\t.quad\t", file
);
6743 output_addr_const (file
, x
);
6744 fputs ("@DTPOFF", file
);
6747 /* Return the proper mode for REGNO being represented in the dwarf
6750 s390_dwarf_frame_reg_mode (int regno
)
6752 machine_mode save_mode
= default_dwarf_frame_reg_mode (regno
);
6754 /* Make sure not to return DImode for any GPR with -m31 -mzarch. */
6755 if (GENERAL_REGNO_P (regno
))
6758 /* The rightmost 64 bits of vector registers are call-clobbered. */
6759 if (GET_MODE_SIZE (save_mode
) > 8)
6765 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
6766 /* Implement TARGET_MANGLE_TYPE. */
6769 s390_mangle_type (const_tree type
)
6771 type
= TYPE_MAIN_VARIANT (type
);
6773 if (TREE_CODE (type
) != VOID_TYPE
&& TREE_CODE (type
) != BOOLEAN_TYPE
6774 && TREE_CODE (type
) != INTEGER_TYPE
&& TREE_CODE (type
) != REAL_TYPE
)
6777 if (type
== s390_builtin_types
[BT_BV16QI
]) return "U6__boolc";
6778 if (type
== s390_builtin_types
[BT_BV8HI
]) return "U6__bools";
6779 if (type
== s390_builtin_types
[BT_BV4SI
]) return "U6__booli";
6780 if (type
== s390_builtin_types
[BT_BV2DI
]) return "U6__booll";
6782 if (TYPE_MAIN_VARIANT (type
) == long_double_type_node
6783 && TARGET_LONG_DOUBLE_128
)
6786 /* For all other types, use normal C++ mangling. */
6791 /* In the name of slightly smaller debug output, and to cater to
6792 general assembler lossage, recognize various UNSPEC sequences
6793 and turn them back into a direct symbol reference. */
6796 s390_delegitimize_address (rtx orig_x
)
6800 orig_x
= delegitimize_mem_from_attrs (orig_x
);
6803 /* Extract the symbol ref from:
6804 (plus:SI (reg:SI 12 %r12)
6805 (const:SI (unspec:SI [(symbol_ref/f:SI ("*.LC0"))]
6806 UNSPEC_GOTOFF/PLTOFF)))
6808 (plus:SI (reg:SI 12 %r12)
6809 (const:SI (plus:SI (unspec:SI [(symbol_ref:SI ("L"))]
6810 UNSPEC_GOTOFF/PLTOFF)
6811 (const_int 4 [0x4])))) */
6812 if (GET_CODE (x
) == PLUS
6813 && REG_P (XEXP (x
, 0))
6814 && REGNO (XEXP (x
, 0)) == PIC_OFFSET_TABLE_REGNUM
6815 && GET_CODE (XEXP (x
, 1)) == CONST
)
6817 HOST_WIDE_INT offset
= 0;
6819 /* The const operand. */
6820 y
= XEXP (XEXP (x
, 1), 0);
6822 if (GET_CODE (y
) == PLUS
6823 && GET_CODE (XEXP (y
, 1)) == CONST_INT
)
6825 offset
= INTVAL (XEXP (y
, 1));
6829 if (GET_CODE (y
) == UNSPEC
6830 && (XINT (y
, 1) == UNSPEC_GOTOFF
6831 || XINT (y
, 1) == UNSPEC_PLTOFF
))
6832 return plus_constant (Pmode
, XVECEXP (y
, 0, 0), offset
);
6835 if (GET_CODE (x
) != MEM
)
6839 if (GET_CODE (x
) == PLUS
6840 && GET_CODE (XEXP (x
, 1)) == CONST
6841 && GET_CODE (XEXP (x
, 0)) == REG
6842 && REGNO (XEXP (x
, 0)) == PIC_OFFSET_TABLE_REGNUM
)
6844 y
= XEXP (XEXP (x
, 1), 0);
6845 if (GET_CODE (y
) == UNSPEC
6846 && XINT (y
, 1) == UNSPEC_GOT
)
6847 y
= XVECEXP (y
, 0, 0);
6851 else if (GET_CODE (x
) == CONST
)
6853 /* Extract the symbol ref from:
6854 (mem:QI (const:DI (unspec:DI [(symbol_ref:DI ("foo"))]
6855 UNSPEC_PLT/GOTENT))) */
6858 if (GET_CODE (y
) == UNSPEC
6859 && (XINT (y
, 1) == UNSPEC_GOTENT
6860 || XINT (y
, 1) == UNSPEC_PLT
))
6861 y
= XVECEXP (y
, 0, 0);
6868 if (GET_MODE (orig_x
) != Pmode
)
6870 if (GET_MODE (orig_x
) == BLKmode
)
6872 y
= lowpart_subreg (GET_MODE (orig_x
), y
, Pmode
);
6879 /* Output operand OP to stdio stream FILE.
6880 OP is an address (register + offset) which is not used to address data;
6881 instead the rightmost bits are interpreted as the value. */
6884 print_addrstyle_operand (FILE *file
, rtx op
)
6886 HOST_WIDE_INT offset
;
6889 /* Extract base register and offset. */
6890 if (!s390_decompose_addrstyle_without_index (op
, &base
, &offset
))
6896 gcc_assert (GET_CODE (base
) == REG
);
6897 gcc_assert (REGNO (base
) < FIRST_PSEUDO_REGISTER
);
6898 gcc_assert (REGNO_REG_CLASS (REGNO (base
)) == ADDR_REGS
);
6901 /* Offsets are constricted to twelve bits. */
6902 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, offset
& ((1 << 12) - 1));
6904 fprintf (file
, "(%s)", reg_names
[REGNO (base
)]);
6907 /* Assigns the number of NOP halfwords to be emitted before and after the
6908 function label to *HW_BEFORE and *HW_AFTER. Both pointers must not be NULL.
6909 If hotpatching is disabled for the function, the values are set to zero.
6913 s390_function_num_hotpatch_hw (tree decl
,
6919 attr
= lookup_attribute ("hotpatch", DECL_ATTRIBUTES (decl
));
6921 /* Handle the arguments of the hotpatch attribute. The values
6922 specified via attribute might override the cmdline argument
6926 tree args
= TREE_VALUE (attr
);
6928 *hw_before
= TREE_INT_CST_LOW (TREE_VALUE (args
));
6929 *hw_after
= TREE_INT_CST_LOW (TREE_VALUE (TREE_CHAIN (args
)));
6933 /* Use the values specified by the cmdline arguments. */
6934 *hw_before
= s390_hotpatch_hw_before_label
;
6935 *hw_after
= s390_hotpatch_hw_after_label
;
6939 /* Write the current .machine and .machinemode specification to the assembler
6942 #ifdef HAVE_AS_MACHINE_MACHINEMODE
6944 s390_asm_output_machine_for_arch (FILE *asm_out_file
)
6946 fprintf (asm_out_file
, "\t.machinemode %s\n",
6947 (TARGET_ZARCH
) ? "zarch" : "esa");
6948 fprintf (asm_out_file
, "\t.machine \"%s", processor_table
[s390_arch
].name
);
6949 if (S390_USE_ARCHITECTURE_MODIFIERS
)
6953 cpu_flags
= processor_flags_table
[(int) s390_arch
];
6954 if (TARGET_HTM
&& !(cpu_flags
& PF_TX
))
6955 fprintf (asm_out_file
, "+htm");
6956 else if (!TARGET_HTM
&& (cpu_flags
& PF_TX
))
6957 fprintf (asm_out_file
, "+nohtm");
6958 if (TARGET_VX
&& !(cpu_flags
& PF_VX
))
6959 fprintf (asm_out_file
, "+vx");
6960 else if (!TARGET_VX
&& (cpu_flags
& PF_VX
))
6961 fprintf (asm_out_file
, "+novx");
6963 fprintf (asm_out_file
, "\"\n");
6966 /* Write an extra function header before the very start of the function. */
6969 s390_asm_output_function_prefix (FILE *asm_out_file
,
6970 const char *fnname ATTRIBUTE_UNUSED
)
6972 if (DECL_FUNCTION_SPECIFIC_TARGET (current_function_decl
) == NULL
)
6974 /* Since only the function specific options are saved but not the indications
6975 which options are set, it's too much work here to figure out which options
6976 have actually changed. Thus, generate .machine and .machinemode whenever a
6977 function has the target attribute or pragma. */
6978 fprintf (asm_out_file
, "\t.machinemode push\n");
6979 fprintf (asm_out_file
, "\t.machine push\n");
6980 s390_asm_output_machine_for_arch (asm_out_file
);
6983 /* Write an extra function footer after the very end of the function. */
6986 s390_asm_declare_function_size (FILE *asm_out_file
,
6987 const char *fnname
, tree decl
)
6989 if (!flag_inhibit_size_directive
)
6990 ASM_OUTPUT_MEASURED_SIZE (asm_out_file
, fnname
);
6991 if (DECL_FUNCTION_SPECIFIC_TARGET (decl
) == NULL
)
6993 fprintf (asm_out_file
, "\t.machine pop\n");
6994 fprintf (asm_out_file
, "\t.machinemode pop\n");
6998 /* Write the extra assembler code needed to declare a function properly. */
7001 s390_asm_output_function_label (FILE *asm_out_file
, const char *fname
,
7004 int hw_before
, hw_after
;
7006 s390_function_num_hotpatch_hw (decl
, &hw_before
, &hw_after
);
7009 unsigned int function_alignment
;
7012 /* Add a trampoline code area before the function label and initialize it
7013 with two-byte nop instructions. This area can be overwritten with code
7014 that jumps to a patched version of the function. */
7015 asm_fprintf (asm_out_file
, "\tnopr\t%%r7"
7016 "\t# pre-label NOPs for hotpatch (%d halfwords)\n",
7018 for (i
= 1; i
< hw_before
; i
++)
7019 fputs ("\tnopr\t%r7\n", asm_out_file
);
7021 /* Note: The function label must be aligned so that (a) the bytes of the
7022 following nop do not cross a cacheline boundary, and (b) a jump address
7023 (eight bytes for 64 bit targets, 4 bytes for 32 bit targets) can be
7024 stored directly before the label without crossing a cacheline
7025 boundary. All this is necessary to make sure the trampoline code can
7026 be changed atomically.
7027 This alignment is done automatically using the FOUNCTION_BOUNDARY, but
7028 if there are NOPs before the function label, the alignment is placed
7029 before them. So it is necessary to duplicate the alignment after the
7031 function_alignment
= MAX (8, DECL_ALIGN (decl
) / BITS_PER_UNIT
);
7032 if (! DECL_USER_ALIGN (decl
))
7033 function_alignment
= MAX (function_alignment
,
7034 (unsigned int) align_functions
);
7035 fputs ("\t# alignment for hotpatch\n", asm_out_file
);
7036 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (function_alignment
));
7039 if (S390_USE_TARGET_ATTRIBUTE
&& TARGET_DEBUG_ARG
)
7041 asm_fprintf (asm_out_file
, "\t# fn:%s ar%d\n", fname
, s390_arch
);
7042 asm_fprintf (asm_out_file
, "\t# fn:%s tu%d\n", fname
, s390_tune
);
7043 asm_fprintf (asm_out_file
, "\t# fn:%s sg%d\n", fname
, s390_stack_guard
);
7044 asm_fprintf (asm_out_file
, "\t# fn:%s ss%d\n", fname
, s390_stack_size
);
7045 asm_fprintf (asm_out_file
, "\t# fn:%s bc%d\n", fname
, s390_branch_cost
);
7046 asm_fprintf (asm_out_file
, "\t# fn:%s wf%d\n", fname
,
7047 s390_warn_framesize
);
7048 asm_fprintf (asm_out_file
, "\t# fn:%s ba%d\n", fname
, TARGET_BACKCHAIN
);
7049 asm_fprintf (asm_out_file
, "\t# fn:%s hd%d\n", fname
, TARGET_HARD_DFP
);
7050 asm_fprintf (asm_out_file
, "\t# fn:%s hf%d\n", fname
, !TARGET_SOFT_FLOAT
);
7051 asm_fprintf (asm_out_file
, "\t# fn:%s ht%d\n", fname
, TARGET_OPT_HTM
);
7052 asm_fprintf (asm_out_file
, "\t# fn:%s vx%d\n", fname
, TARGET_OPT_VX
);
7053 asm_fprintf (asm_out_file
, "\t# fn:%s ps%d\n", fname
,
7054 TARGET_PACKED_STACK
);
7055 asm_fprintf (asm_out_file
, "\t# fn:%s se%d\n", fname
, TARGET_SMALL_EXEC
);
7056 asm_fprintf (asm_out_file
, "\t# fn:%s mv%d\n", fname
, TARGET_MVCLE
);
7057 asm_fprintf (asm_out_file
, "\t# fn:%s zv%d\n", fname
, TARGET_ZVECTOR
);
7058 asm_fprintf (asm_out_file
, "\t# fn:%s wd%d\n", fname
,
7059 s390_warn_dynamicstack_p
);
7061 ASM_OUTPUT_LABEL (asm_out_file
, fname
);
7063 asm_fprintf (asm_out_file
,
7064 "\t# post-label NOPs for hotpatch (%d halfwords)\n",
7068 /* Output machine-dependent UNSPECs occurring in address constant X
7069 in assembler syntax to stdio stream FILE. Returns true if the
7070 constant X could be recognized, false otherwise. */
7073 s390_output_addr_const_extra (FILE *file
, rtx x
)
7075 if (GET_CODE (x
) == UNSPEC
&& XVECLEN (x
, 0) == 1)
7076 switch (XINT (x
, 1))
7079 output_addr_const (file
, XVECEXP (x
, 0, 0));
7080 fprintf (file
, "@GOTENT");
7083 output_addr_const (file
, XVECEXP (x
, 0, 0));
7084 fprintf (file
, "@GOT");
7087 output_addr_const (file
, XVECEXP (x
, 0, 0));
7088 fprintf (file
, "@GOTOFF");
7091 output_addr_const (file
, XVECEXP (x
, 0, 0));
7092 fprintf (file
, "@PLT");
7095 output_addr_const (file
, XVECEXP (x
, 0, 0));
7096 fprintf (file
, "@PLTOFF");
7099 output_addr_const (file
, XVECEXP (x
, 0, 0));
7100 fprintf (file
, "@TLSGD");
7103 assemble_name (file
, get_some_local_dynamic_name ());
7104 fprintf (file
, "@TLSLDM");
7107 output_addr_const (file
, XVECEXP (x
, 0, 0));
7108 fprintf (file
, "@DTPOFF");
7111 output_addr_const (file
, XVECEXP (x
, 0, 0));
7112 fprintf (file
, "@NTPOFF");
7114 case UNSPEC_GOTNTPOFF
:
7115 output_addr_const (file
, XVECEXP (x
, 0, 0));
7116 fprintf (file
, "@GOTNTPOFF");
7118 case UNSPEC_INDNTPOFF
:
7119 output_addr_const (file
, XVECEXP (x
, 0, 0));
7120 fprintf (file
, "@INDNTPOFF");
7124 if (GET_CODE (x
) == UNSPEC
&& XVECLEN (x
, 0) == 2)
7125 switch (XINT (x
, 1))
7127 case UNSPEC_POOL_OFFSET
:
7128 x
= gen_rtx_MINUS (GET_MODE (x
), XVECEXP (x
, 0, 0), XVECEXP (x
, 0, 1));
7129 output_addr_const (file
, x
);
7135 /* Output address operand ADDR in assembler syntax to
7136 stdio stream FILE. */
7139 print_operand_address (FILE *file
, rtx addr
)
7141 struct s390_address ad
;
7143 if (s390_loadrelative_operand_p (addr
, NULL
, NULL
))
7147 output_operand_lossage ("symbolic memory references are "
7148 "only supported on z10 or later");
7151 output_addr_const (file
, addr
);
7155 if (!s390_decompose_address (addr
, &ad
)
7156 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
7157 || (ad
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (ad
.indx
))))
7158 output_operand_lossage ("cannot decompose address");
7161 output_addr_const (file
, ad
.disp
);
7163 fprintf (file
, "0");
7165 if (ad
.base
&& ad
.indx
)
7166 fprintf (file
, "(%s,%s)", reg_names
[REGNO (ad
.indx
)],
7167 reg_names
[REGNO (ad
.base
)]);
7169 fprintf (file
, "(%s)", reg_names
[REGNO (ad
.base
)]);
7172 /* Output operand X in assembler syntax to stdio stream FILE.
7173 CODE specified the format flag. The following format flags
7176 'C': print opcode suffix for branch condition.
7177 'D': print opcode suffix for inverse branch condition.
7178 'E': print opcode suffix for branch on index instruction.
7179 'G': print the size of the operand in bytes.
7180 'J': print tls_load/tls_gdcall/tls_ldcall suffix
7181 'M': print the second word of a TImode operand.
7182 'N': print the second word of a DImode operand.
7183 'O': print only the displacement of a memory reference or address.
7184 'R': print only the base register of a memory reference or address.
7185 'S': print S-type memory reference (base+displacement).
7186 'Y': print address style operand without index (e.g. shift count or setmem
7189 'b': print integer X as if it's an unsigned byte.
7190 'c': print integer X as if it's an signed byte.
7191 'e': "end" contiguous bitmask X in either DImode or vector inner mode.
7192 'f': "end" contiguous bitmask X in SImode.
7193 'h': print integer X as if it's a signed halfword.
7194 'i': print the first nonzero HImode part of X.
7195 'j': print the first HImode part unequal to -1 of X.
7196 'k': print the first nonzero SImode part of X.
7197 'm': print the first SImode part unequal to -1 of X.
7198 'o': print integer X as if it's an unsigned 32bit word.
7199 's': "start" of contiguous bitmask X in either DImode or vector inner mode.
7200 't': CONST_INT: "start" of contiguous bitmask X in SImode.
7201 CONST_VECTOR: Generate a bitmask for vgbm instruction.
7202 'x': print integer X as if it's an unsigned halfword.
7203 'v': print register number as vector register (v1 instead of f1).
7207 print_operand (FILE *file
, rtx x
, int code
)
7214 fprintf (file
, s390_branch_condition_mnemonic (x
, FALSE
));
7218 fprintf (file
, s390_branch_condition_mnemonic (x
, TRUE
));
7222 if (GET_CODE (x
) == LE
)
7223 fprintf (file
, "l");
7224 else if (GET_CODE (x
) == GT
)
7225 fprintf (file
, "h");
7227 output_operand_lossage ("invalid comparison operator "
7228 "for 'E' output modifier");
7232 if (GET_CODE (x
) == SYMBOL_REF
)
7234 fprintf (file
, "%s", ":tls_load:");
7235 output_addr_const (file
, x
);
7237 else if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_TLSGD
)
7239 fprintf (file
, "%s", ":tls_gdcall:");
7240 output_addr_const (file
, XVECEXP (x
, 0, 0));
7242 else if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_TLSLDM
)
7244 fprintf (file
, "%s", ":tls_ldcall:");
7245 const char *name
= get_some_local_dynamic_name ();
7247 assemble_name (file
, name
);
7250 output_operand_lossage ("invalid reference for 'J' output modifier");
7254 fprintf (file
, "%u", GET_MODE_SIZE (GET_MODE (x
)));
7259 struct s390_address ad
;
7262 ret
= s390_decompose_address (MEM_P (x
) ? XEXP (x
, 0) : x
, &ad
);
7265 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
7268 output_operand_lossage ("invalid address for 'O' output modifier");
7273 output_addr_const (file
, ad
.disp
);
7275 fprintf (file
, "0");
7281 struct s390_address ad
;
7284 ret
= s390_decompose_address (MEM_P (x
) ? XEXP (x
, 0) : x
, &ad
);
7287 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
7290 output_operand_lossage ("invalid address for 'R' output modifier");
7295 fprintf (file
, "%s", reg_names
[REGNO (ad
.base
)]);
7297 fprintf (file
, "0");
7303 struct s390_address ad
;
7308 output_operand_lossage ("memory reference expected for "
7309 "'S' output modifier");
7312 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
7315 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
7318 output_operand_lossage ("invalid address for 'S' output modifier");
7323 output_addr_const (file
, ad
.disp
);
7325 fprintf (file
, "0");
7328 fprintf (file
, "(%s)", reg_names
[REGNO (ad
.base
)]);
7333 if (GET_CODE (x
) == REG
)
7334 x
= gen_rtx_REG (GET_MODE (x
), REGNO (x
) + 1);
7335 else if (GET_CODE (x
) == MEM
)
7336 x
= change_address (x
, VOIDmode
,
7337 plus_constant (Pmode
, XEXP (x
, 0), 4));
7339 output_operand_lossage ("register or memory expression expected "
7340 "for 'N' output modifier");
7344 if (GET_CODE (x
) == REG
)
7345 x
= gen_rtx_REG (GET_MODE (x
), REGNO (x
) + 1);
7346 else if (GET_CODE (x
) == MEM
)
7347 x
= change_address (x
, VOIDmode
,
7348 plus_constant (Pmode
, XEXP (x
, 0), 8));
7350 output_operand_lossage ("register or memory expression expected "
7351 "for 'M' output modifier");
7355 print_addrstyle_operand (file
, x
);
7359 switch (GET_CODE (x
))
7362 /* Print FP regs as fx instead of vx when they are accessed
7363 through non-vector mode. */
7365 || VECTOR_NOFP_REG_P (x
)
7366 || (FP_REG_P (x
) && VECTOR_MODE_P (GET_MODE (x
)))
7367 || (VECTOR_REG_P (x
)
7368 && (GET_MODE_SIZE (GET_MODE (x
)) /
7369 s390_class_max_nregs (FP_REGS
, GET_MODE (x
))) > 8))
7370 fprintf (file
, "%%v%s", reg_names
[REGNO (x
)] + 2);
7372 fprintf (file
, "%s", reg_names
[REGNO (x
)]);
7376 output_address (GET_MODE (x
), XEXP (x
, 0));
7383 output_addr_const (file
, x
);
7396 ival
= ((ival
& 0xff) ^ 0x80) - 0x80;
7402 ival
= ((ival
& 0xffff) ^ 0x8000) - 0x8000;
7405 ival
= s390_extract_part (x
, HImode
, 0);
7408 ival
= s390_extract_part (x
, HImode
, -1);
7411 ival
= s390_extract_part (x
, SImode
, 0);
7414 ival
= s390_extract_part (x
, SImode
, -1);
7425 len
= (code
== 's' || code
== 'e' ? 64 : 32);
7426 ok
= s390_contiguous_bitmask_p (ival
, len
, &pos
, &len
);
7428 if (code
== 's' || code
== 't')
7429 ival
= 64 - pos
- len
;
7431 ival
= 64 - 1 - pos
;
7435 output_operand_lossage ("invalid constant for output modifier '%c'", code
);
7437 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, ival
);
7440 case CONST_WIDE_INT
:
7442 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
7443 CONST_WIDE_INT_ELT (x
, 0) & 0xff);
7444 else if (code
== 'x')
7445 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
7446 CONST_WIDE_INT_ELT (x
, 0) & 0xffff);
7447 else if (code
== 'h')
7448 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
7449 ((CONST_WIDE_INT_ELT (x
, 0) & 0xffff) ^ 0x8000) - 0x8000);
7453 output_operand_lossage ("invalid constant - try using "
7454 "an output modifier");
7456 output_operand_lossage ("invalid constant for output modifier '%c'",
7464 gcc_assert (const_vec_duplicate_p (x
));
7465 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
7466 ((INTVAL (XVECEXP (x
, 0, 0)) & 0xffff) ^ 0x8000) - 0x8000);
7471 int start
, stop
, inner_len
;
7474 inner_len
= GET_MODE_UNIT_BITSIZE (GET_MODE (x
));
7475 ok
= s390_contiguous_bitmask_vector_p (x
, &start
, &stop
);
7477 if (code
== 's' || code
== 't')
7478 ival
= inner_len
- stop
- 1;
7480 ival
= inner_len
- start
- 1;
7481 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, ival
);
7487 bool ok
= s390_bytemask_vector_p (x
, &mask
);
7489 fprintf (file
, "%u", mask
);
7494 output_operand_lossage ("invalid constant vector for output "
7495 "modifier '%c'", code
);
7501 output_operand_lossage ("invalid expression - try using "
7502 "an output modifier");
7504 output_operand_lossage ("invalid expression for output "
7505 "modifier '%c'", code
);
7510 /* Target hook for assembling integer objects. We need to define it
7511 here to work a round a bug in some versions of GAS, which couldn't
7512 handle values smaller than INT_MIN when printed in decimal. */
7515 s390_assemble_integer (rtx x
, unsigned int size
, int aligned_p
)
7517 if (size
== 8 && aligned_p
7518 && GET_CODE (x
) == CONST_INT
&& INTVAL (x
) < INT_MIN
)
7520 fprintf (asm_out_file
, "\t.quad\t" HOST_WIDE_INT_PRINT_HEX
"\n",
7524 return default_assemble_integer (x
, size
, aligned_p
);
7527 /* Returns true if register REGNO is used for forming
7528 a memory address in expression X. */
7531 reg_used_in_mem_p (int regno
, rtx x
)
7533 enum rtx_code code
= GET_CODE (x
);
7539 if (refers_to_regno_p (regno
, XEXP (x
, 0)))
7542 else if (code
== SET
7543 && GET_CODE (SET_DEST (x
)) == PC
)
7545 if (refers_to_regno_p (regno
, SET_SRC (x
)))
7549 fmt
= GET_RTX_FORMAT (code
);
7550 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
7553 && reg_used_in_mem_p (regno
, XEXP (x
, i
)))
7556 else if (fmt
[i
] == 'E')
7557 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
7558 if (reg_used_in_mem_p (regno
, XVECEXP (x
, i
, j
)))
7564 /* Returns true if expression DEP_RTX sets an address register
7565 used by instruction INSN to address memory. */
7568 addr_generation_dependency_p (rtx dep_rtx
, rtx_insn
*insn
)
7572 if (NONJUMP_INSN_P (dep_rtx
))
7573 dep_rtx
= PATTERN (dep_rtx
);
7575 if (GET_CODE (dep_rtx
) == SET
)
7577 target
= SET_DEST (dep_rtx
);
7578 if (GET_CODE (target
) == STRICT_LOW_PART
)
7579 target
= XEXP (target
, 0);
7580 while (GET_CODE (target
) == SUBREG
)
7581 target
= SUBREG_REG (target
);
7583 if (GET_CODE (target
) == REG
)
7585 int regno
= REGNO (target
);
7587 if (s390_safe_attr_type (insn
) == TYPE_LA
)
7589 pat
= PATTERN (insn
);
7590 if (GET_CODE (pat
) == PARALLEL
)
7592 gcc_assert (XVECLEN (pat
, 0) == 2);
7593 pat
= XVECEXP (pat
, 0, 0);
7595 gcc_assert (GET_CODE (pat
) == SET
);
7596 return refers_to_regno_p (regno
, SET_SRC (pat
));
7598 else if (get_attr_atype (insn
) == ATYPE_AGEN
)
7599 return reg_used_in_mem_p (regno
, PATTERN (insn
));
7605 /* Return 1, if dep_insn sets register used in insn in the agen unit. */
7608 s390_agen_dep_p (rtx_insn
*dep_insn
, rtx_insn
*insn
)
7610 rtx dep_rtx
= PATTERN (dep_insn
);
7613 if (GET_CODE (dep_rtx
) == SET
7614 && addr_generation_dependency_p (dep_rtx
, insn
))
7616 else if (GET_CODE (dep_rtx
) == PARALLEL
)
7618 for (i
= 0; i
< XVECLEN (dep_rtx
, 0); i
++)
7620 if (addr_generation_dependency_p (XVECEXP (dep_rtx
, 0, i
), insn
))
7628 /* A C statement (sans semicolon) to update the integer scheduling priority
7629 INSN_PRIORITY (INSN). Increase the priority to execute the INSN earlier,
7630 reduce the priority to execute INSN later. Do not define this macro if
7631 you do not need to adjust the scheduling priorities of insns.
7633 A STD instruction should be scheduled earlier,
7634 in order to use the bypass. */
7636 s390_adjust_priority (rtx_insn
*insn
, int priority
)
7638 if (! INSN_P (insn
))
7641 if (s390_tune
<= PROCESSOR_2064_Z900
)
7644 switch (s390_safe_attr_type (insn
))
7648 priority
= priority
<< 3;
7652 priority
= priority
<< 1;
7661 /* The number of instructions that can be issued per cycle. */
7664 s390_issue_rate (void)
7668 case PROCESSOR_2084_Z990
:
7669 case PROCESSOR_2094_Z9_109
:
7670 case PROCESSOR_2094_Z9_EC
:
7671 case PROCESSOR_2817_Z196
:
7673 case PROCESSOR_2097_Z10
:
7675 case PROCESSOR_9672_G5
:
7676 case PROCESSOR_9672_G6
:
7677 case PROCESSOR_2064_Z900
:
7678 /* Starting with EC12 we use the sched_reorder hook to take care
7679 of instruction dispatch constraints. The algorithm only
7680 picks the best instruction and assumes only a single
7681 instruction gets issued per cycle. */
7682 case PROCESSOR_2827_ZEC12
:
7683 case PROCESSOR_2964_Z13
:
7690 s390_first_cycle_multipass_dfa_lookahead (void)
7695 /* Annotate every literal pool reference in X by an UNSPEC_LTREF expression.
7696 Fix up MEMs as required. */
7699 annotate_constant_pool_refs (rtx
*x
)
7704 gcc_assert (GET_CODE (*x
) != SYMBOL_REF
7705 || !CONSTANT_POOL_ADDRESS_P (*x
));
7707 /* Literal pool references can only occur inside a MEM ... */
7708 if (GET_CODE (*x
) == MEM
)
7710 rtx memref
= XEXP (*x
, 0);
7712 if (GET_CODE (memref
) == SYMBOL_REF
7713 && CONSTANT_POOL_ADDRESS_P (memref
))
7715 rtx base
= cfun
->machine
->base_reg
;
7716 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, memref
, base
),
7719 *x
= replace_equiv_address (*x
, addr
);
7723 if (GET_CODE (memref
) == CONST
7724 && GET_CODE (XEXP (memref
, 0)) == PLUS
7725 && GET_CODE (XEXP (XEXP (memref
, 0), 1)) == CONST_INT
7726 && GET_CODE (XEXP (XEXP (memref
, 0), 0)) == SYMBOL_REF
7727 && CONSTANT_POOL_ADDRESS_P (XEXP (XEXP (memref
, 0), 0)))
7729 HOST_WIDE_INT off
= INTVAL (XEXP (XEXP (memref
, 0), 1));
7730 rtx sym
= XEXP (XEXP (memref
, 0), 0);
7731 rtx base
= cfun
->machine
->base_reg
;
7732 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, sym
, base
),
7735 *x
= replace_equiv_address (*x
, plus_constant (Pmode
, addr
, off
));
7740 /* ... or a load-address type pattern. */
7741 if (GET_CODE (*x
) == SET
)
7743 rtx addrref
= SET_SRC (*x
);
7745 if (GET_CODE (addrref
) == SYMBOL_REF
7746 && CONSTANT_POOL_ADDRESS_P (addrref
))
7748 rtx base
= cfun
->machine
->base_reg
;
7749 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, addrref
, base
),
7752 SET_SRC (*x
) = addr
;
7756 if (GET_CODE (addrref
) == CONST
7757 && GET_CODE (XEXP (addrref
, 0)) == PLUS
7758 && GET_CODE (XEXP (XEXP (addrref
, 0), 1)) == CONST_INT
7759 && GET_CODE (XEXP (XEXP (addrref
, 0), 0)) == SYMBOL_REF
7760 && CONSTANT_POOL_ADDRESS_P (XEXP (XEXP (addrref
, 0), 0)))
7762 HOST_WIDE_INT off
= INTVAL (XEXP (XEXP (addrref
, 0), 1));
7763 rtx sym
= XEXP (XEXP (addrref
, 0), 0);
7764 rtx base
= cfun
->machine
->base_reg
;
7765 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, sym
, base
),
7768 SET_SRC (*x
) = plus_constant (Pmode
, addr
, off
);
7773 /* Annotate LTREL_BASE as well. */
7774 if (GET_CODE (*x
) == UNSPEC
7775 && XINT (*x
, 1) == UNSPEC_LTREL_BASE
)
7777 rtx base
= cfun
->machine
->base_reg
;
7778 *x
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, XVECEXP (*x
, 0, 0), base
),
7783 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
7784 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
7788 annotate_constant_pool_refs (&XEXP (*x
, i
));
7790 else if (fmt
[i
] == 'E')
7792 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
7793 annotate_constant_pool_refs (&XVECEXP (*x
, i
, j
));
7798 /* Split all branches that exceed the maximum distance.
7799 Returns true if this created a new literal pool entry. */
7802 s390_split_branches (void)
7804 rtx temp_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
7805 int new_literal
= 0, ret
;
7810 /* We need correct insn addresses. */
7812 shorten_branches (get_insns ());
7814 /* Find all branches that exceed 64KB, and split them. */
7816 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
7818 if (! JUMP_P (insn
) || tablejump_p (insn
, NULL
, NULL
))
7821 pat
= PATTERN (insn
);
7822 if (GET_CODE (pat
) == PARALLEL
)
7823 pat
= XVECEXP (pat
, 0, 0);
7824 if (GET_CODE (pat
) != SET
|| SET_DEST (pat
) != pc_rtx
)
7827 if (GET_CODE (SET_SRC (pat
)) == LABEL_REF
)
7829 label
= &SET_SRC (pat
);
7831 else if (GET_CODE (SET_SRC (pat
)) == IF_THEN_ELSE
)
7833 if (GET_CODE (XEXP (SET_SRC (pat
), 1)) == LABEL_REF
)
7834 label
= &XEXP (SET_SRC (pat
), 1);
7835 else if (GET_CODE (XEXP (SET_SRC (pat
), 2)) == LABEL_REF
)
7836 label
= &XEXP (SET_SRC (pat
), 2);
7843 if (get_attr_length (insn
) <= 4)
7846 /* We are going to use the return register as scratch register,
7847 make sure it will be saved/restored by the prologue/epilogue. */
7848 cfun_frame_layout
.save_return_addr_p
= 1;
7853 rtx mem
= force_const_mem (Pmode
, *label
);
7854 rtx_insn
*set_insn
= emit_insn_before (gen_rtx_SET (temp_reg
, mem
),
7856 INSN_ADDRESSES_NEW (set_insn
, -1);
7857 annotate_constant_pool_refs (&PATTERN (set_insn
));
7864 target
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, *label
),
7865 UNSPEC_LTREL_OFFSET
);
7866 target
= gen_rtx_CONST (Pmode
, target
);
7867 target
= force_const_mem (Pmode
, target
);
7868 rtx_insn
*set_insn
= emit_insn_before (gen_rtx_SET (temp_reg
, target
),
7870 INSN_ADDRESSES_NEW (set_insn
, -1);
7871 annotate_constant_pool_refs (&PATTERN (set_insn
));
7873 target
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, XEXP (target
, 0),
7874 cfun
->machine
->base_reg
),
7876 target
= gen_rtx_PLUS (Pmode
, temp_reg
, target
);
7879 ret
= validate_change (insn
, label
, target
, 0);
7887 /* Find an annotated literal pool symbol referenced in RTX X,
7888 and store it at REF. Will abort if X contains references to
7889 more than one such pool symbol; multiple references to the same
7890 symbol are allowed, however.
7892 The rtx pointed to by REF must be initialized to NULL_RTX
7893 by the caller before calling this routine. */
7896 find_constant_pool_ref (rtx x
, rtx
*ref
)
7901 /* Ignore LTREL_BASE references. */
7902 if (GET_CODE (x
) == UNSPEC
7903 && XINT (x
, 1) == UNSPEC_LTREL_BASE
)
7905 /* Likewise POOL_ENTRY insns. */
7906 if (GET_CODE (x
) == UNSPEC_VOLATILE
7907 && XINT (x
, 1) == UNSPECV_POOL_ENTRY
)
7910 gcc_assert (GET_CODE (x
) != SYMBOL_REF
7911 || !CONSTANT_POOL_ADDRESS_P (x
));
7913 if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_LTREF
)
7915 rtx sym
= XVECEXP (x
, 0, 0);
7916 gcc_assert (GET_CODE (sym
) == SYMBOL_REF
7917 && CONSTANT_POOL_ADDRESS_P (sym
));
7919 if (*ref
== NULL_RTX
)
7922 gcc_assert (*ref
== sym
);
7927 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
7928 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
7932 find_constant_pool_ref (XEXP (x
, i
), ref
);
7934 else if (fmt
[i
] == 'E')
7936 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
7937 find_constant_pool_ref (XVECEXP (x
, i
, j
), ref
);
7942 /* Replace every reference to the annotated literal pool
7943 symbol REF in X by its base plus OFFSET. */
7946 replace_constant_pool_ref (rtx
*x
, rtx ref
, rtx offset
)
7951 gcc_assert (*x
!= ref
);
7953 if (GET_CODE (*x
) == UNSPEC
7954 && XINT (*x
, 1) == UNSPEC_LTREF
7955 && XVECEXP (*x
, 0, 0) == ref
)
7957 *x
= gen_rtx_PLUS (Pmode
, XVECEXP (*x
, 0, 1), offset
);
7961 if (GET_CODE (*x
) == PLUS
7962 && GET_CODE (XEXP (*x
, 1)) == CONST_INT
7963 && GET_CODE (XEXP (*x
, 0)) == UNSPEC
7964 && XINT (XEXP (*x
, 0), 1) == UNSPEC_LTREF
7965 && XVECEXP (XEXP (*x
, 0), 0, 0) == ref
)
7967 rtx addr
= gen_rtx_PLUS (Pmode
, XVECEXP (XEXP (*x
, 0), 0, 1), offset
);
7968 *x
= plus_constant (Pmode
, addr
, INTVAL (XEXP (*x
, 1)));
7972 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
7973 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
7977 replace_constant_pool_ref (&XEXP (*x
, i
), ref
, offset
);
7979 else if (fmt
[i
] == 'E')
7981 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
7982 replace_constant_pool_ref (&XVECEXP (*x
, i
, j
), ref
, offset
);
7987 /* Check whether X contains an UNSPEC_LTREL_BASE.
7988 Return its constant pool symbol if found, NULL_RTX otherwise. */
7991 find_ltrel_base (rtx x
)
7996 if (GET_CODE (x
) == UNSPEC
7997 && XINT (x
, 1) == UNSPEC_LTREL_BASE
)
7998 return XVECEXP (x
, 0, 0);
8000 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
8001 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
8005 rtx fnd
= find_ltrel_base (XEXP (x
, i
));
8009 else if (fmt
[i
] == 'E')
8011 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
8013 rtx fnd
= find_ltrel_base (XVECEXP (x
, i
, j
));
8023 /* Replace any occurrence of UNSPEC_LTREL_BASE in X with its base. */
8026 replace_ltrel_base (rtx
*x
)
8031 if (GET_CODE (*x
) == UNSPEC
8032 && XINT (*x
, 1) == UNSPEC_LTREL_BASE
)
8034 *x
= XVECEXP (*x
, 0, 1);
8038 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
8039 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
8043 replace_ltrel_base (&XEXP (*x
, i
));
8045 else if (fmt
[i
] == 'E')
8047 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
8048 replace_ltrel_base (&XVECEXP (*x
, i
, j
));
8054 /* We keep a list of constants which we have to add to internal
8055 constant tables in the middle of large functions. */
8057 #define NR_C_MODES 32
8058 machine_mode constant_modes
[NR_C_MODES
] =
8060 TFmode
, TImode
, TDmode
,
8061 V16QImode
, V8HImode
, V4SImode
, V2DImode
, V1TImode
,
8062 V4SFmode
, V2DFmode
, V1TFmode
,
8063 DFmode
, DImode
, DDmode
,
8064 V8QImode
, V4HImode
, V2SImode
, V1DImode
, V2SFmode
, V1DFmode
,
8065 SFmode
, SImode
, SDmode
,
8066 V4QImode
, V2HImode
, V1SImode
, V1SFmode
,
8075 struct constant
*next
;
8077 rtx_code_label
*label
;
8080 struct constant_pool
8082 struct constant_pool
*next
;
8083 rtx_insn
*first_insn
;
8084 rtx_insn
*pool_insn
;
8086 rtx_insn
*emit_pool_after
;
8088 struct constant
*constants
[NR_C_MODES
];
8089 struct constant
*execute
;
8090 rtx_code_label
*label
;
8094 /* Allocate new constant_pool structure. */
8096 static struct constant_pool
*
8097 s390_alloc_pool (void)
8099 struct constant_pool
*pool
;
8102 pool
= (struct constant_pool
*) xmalloc (sizeof *pool
);
8104 for (i
= 0; i
< NR_C_MODES
; i
++)
8105 pool
->constants
[i
] = NULL
;
8107 pool
->execute
= NULL
;
8108 pool
->label
= gen_label_rtx ();
8109 pool
->first_insn
= NULL
;
8110 pool
->pool_insn
= NULL
;
8111 pool
->insns
= BITMAP_ALLOC (NULL
);
8113 pool
->emit_pool_after
= NULL
;
8118 /* Create new constant pool covering instructions starting at INSN
8119 and chain it to the end of POOL_LIST. */
8121 static struct constant_pool
*
8122 s390_start_pool (struct constant_pool
**pool_list
, rtx_insn
*insn
)
8124 struct constant_pool
*pool
, **prev
;
8126 pool
= s390_alloc_pool ();
8127 pool
->first_insn
= insn
;
8129 for (prev
= pool_list
; *prev
; prev
= &(*prev
)->next
)
8136 /* End range of instructions covered by POOL at INSN and emit
8137 placeholder insn representing the pool. */
8140 s390_end_pool (struct constant_pool
*pool
, rtx_insn
*insn
)
8142 rtx pool_size
= GEN_INT (pool
->size
+ 8 /* alignment slop */);
8145 insn
= get_last_insn ();
8147 pool
->pool_insn
= emit_insn_after (gen_pool (pool_size
), insn
);
8148 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
8151 /* Add INSN to the list of insns covered by POOL. */
8154 s390_add_pool_insn (struct constant_pool
*pool
, rtx insn
)
8156 bitmap_set_bit (pool
->insns
, INSN_UID (insn
));
8159 /* Return pool out of POOL_LIST that covers INSN. */
8161 static struct constant_pool
*
8162 s390_find_pool (struct constant_pool
*pool_list
, rtx insn
)
8164 struct constant_pool
*pool
;
8166 for (pool
= pool_list
; pool
; pool
= pool
->next
)
8167 if (bitmap_bit_p (pool
->insns
, INSN_UID (insn
)))
8173 /* Add constant VAL of mode MODE to the constant pool POOL. */
8176 s390_add_constant (struct constant_pool
*pool
, rtx val
, machine_mode mode
)
8181 for (i
= 0; i
< NR_C_MODES
; i
++)
8182 if (constant_modes
[i
] == mode
)
8184 gcc_assert (i
!= NR_C_MODES
);
8186 for (c
= pool
->constants
[i
]; c
!= NULL
; c
= c
->next
)
8187 if (rtx_equal_p (val
, c
->value
))
8192 c
= (struct constant
*) xmalloc (sizeof *c
);
8194 c
->label
= gen_label_rtx ();
8195 c
->next
= pool
->constants
[i
];
8196 pool
->constants
[i
] = c
;
8197 pool
->size
+= GET_MODE_SIZE (mode
);
8201 /* Return an rtx that represents the offset of X from the start of
8205 s390_pool_offset (struct constant_pool
*pool
, rtx x
)
8209 label
= gen_rtx_LABEL_REF (GET_MODE (x
), pool
->label
);
8210 x
= gen_rtx_UNSPEC (GET_MODE (x
), gen_rtvec (2, x
, label
),
8211 UNSPEC_POOL_OFFSET
);
8212 return gen_rtx_CONST (GET_MODE (x
), x
);
8215 /* Find constant VAL of mode MODE in the constant pool POOL.
8216 Return an RTX describing the distance from the start of
8217 the pool to the location of the new constant. */
8220 s390_find_constant (struct constant_pool
*pool
, rtx val
,
8226 for (i
= 0; i
< NR_C_MODES
; i
++)
8227 if (constant_modes
[i
] == mode
)
8229 gcc_assert (i
!= NR_C_MODES
);
8231 for (c
= pool
->constants
[i
]; c
!= NULL
; c
= c
->next
)
8232 if (rtx_equal_p (val
, c
->value
))
8237 return s390_pool_offset (pool
, gen_rtx_LABEL_REF (Pmode
, c
->label
));
8240 /* Check whether INSN is an execute. Return the label_ref to its
8241 execute target template if so, NULL_RTX otherwise. */
8244 s390_execute_label (rtx insn
)
8246 if (NONJUMP_INSN_P (insn
)
8247 && GET_CODE (PATTERN (insn
)) == PARALLEL
8248 && GET_CODE (XVECEXP (PATTERN (insn
), 0, 0)) == UNSPEC
8249 && XINT (XVECEXP (PATTERN (insn
), 0, 0), 1) == UNSPEC_EXECUTE
)
8250 return XVECEXP (XVECEXP (PATTERN (insn
), 0, 0), 0, 2);
8255 /* Add execute target for INSN to the constant pool POOL. */
8258 s390_add_execute (struct constant_pool
*pool
, rtx insn
)
8262 for (c
= pool
->execute
; c
!= NULL
; c
= c
->next
)
8263 if (INSN_UID (insn
) == INSN_UID (c
->value
))
8268 c
= (struct constant
*) xmalloc (sizeof *c
);
8270 c
->label
= gen_label_rtx ();
8271 c
->next
= pool
->execute
;
8277 /* Find execute target for INSN in the constant pool POOL.
8278 Return an RTX describing the distance from the start of
8279 the pool to the location of the execute target. */
8282 s390_find_execute (struct constant_pool
*pool
, rtx insn
)
8286 for (c
= pool
->execute
; c
!= NULL
; c
= c
->next
)
8287 if (INSN_UID (insn
) == INSN_UID (c
->value
))
8292 return s390_pool_offset (pool
, gen_rtx_LABEL_REF (Pmode
, c
->label
));
8295 /* For an execute INSN, extract the execute target template. */
8298 s390_execute_target (rtx insn
)
8300 rtx pattern
= PATTERN (insn
);
8301 gcc_assert (s390_execute_label (insn
));
8303 if (XVECLEN (pattern
, 0) == 2)
8305 pattern
= copy_rtx (XVECEXP (pattern
, 0, 1));
8309 rtvec vec
= rtvec_alloc (XVECLEN (pattern
, 0) - 1);
8312 for (i
= 0; i
< XVECLEN (pattern
, 0) - 1; i
++)
8313 RTVEC_ELT (vec
, i
) = copy_rtx (XVECEXP (pattern
, 0, i
+ 1));
8315 pattern
= gen_rtx_PARALLEL (VOIDmode
, vec
);
8321 /* Indicate that INSN cannot be duplicated. This is the case for
8322 execute insns that carry a unique label. */
8325 s390_cannot_copy_insn_p (rtx_insn
*insn
)
8327 rtx label
= s390_execute_label (insn
);
8328 return label
&& label
!= const0_rtx
;
8331 /* Dump out the constants in POOL. If REMOTE_LABEL is true,
8332 do not emit the pool base label. */
8335 s390_dump_pool (struct constant_pool
*pool
, bool remote_label
)
8338 rtx_insn
*insn
= pool
->pool_insn
;
8341 /* Switch to rodata section. */
8342 if (TARGET_CPU_ZARCH
)
8344 insn
= emit_insn_after (gen_pool_section_start (), insn
);
8345 INSN_ADDRESSES_NEW (insn
, -1);
8348 /* Ensure minimum pool alignment. */
8349 if (TARGET_CPU_ZARCH
)
8350 insn
= emit_insn_after (gen_pool_align (GEN_INT (8)), insn
);
8352 insn
= emit_insn_after (gen_pool_align (GEN_INT (4)), insn
);
8353 INSN_ADDRESSES_NEW (insn
, -1);
8355 /* Emit pool base label. */
8358 insn
= emit_label_after (pool
->label
, insn
);
8359 INSN_ADDRESSES_NEW (insn
, -1);
8362 /* Dump constants in descending alignment requirement order,
8363 ensuring proper alignment for every constant. */
8364 for (i
= 0; i
< NR_C_MODES
; i
++)
8365 for (c
= pool
->constants
[i
]; c
; c
= c
->next
)
8367 /* Convert UNSPEC_LTREL_OFFSET unspecs to pool-relative references. */
8368 rtx value
= copy_rtx (c
->value
);
8369 if (GET_CODE (value
) == CONST
8370 && GET_CODE (XEXP (value
, 0)) == UNSPEC
8371 && XINT (XEXP (value
, 0), 1) == UNSPEC_LTREL_OFFSET
8372 && XVECLEN (XEXP (value
, 0), 0) == 1)
8373 value
= s390_pool_offset (pool
, XVECEXP (XEXP (value
, 0), 0, 0));
8375 insn
= emit_label_after (c
->label
, insn
);
8376 INSN_ADDRESSES_NEW (insn
, -1);
8378 value
= gen_rtx_UNSPEC_VOLATILE (constant_modes
[i
],
8379 gen_rtvec (1, value
),
8380 UNSPECV_POOL_ENTRY
);
8381 insn
= emit_insn_after (value
, insn
);
8382 INSN_ADDRESSES_NEW (insn
, -1);
8385 /* Ensure minimum alignment for instructions. */
8386 insn
= emit_insn_after (gen_pool_align (GEN_INT (2)), insn
);
8387 INSN_ADDRESSES_NEW (insn
, -1);
8389 /* Output in-pool execute template insns. */
8390 for (c
= pool
->execute
; c
; c
= c
->next
)
8392 insn
= emit_label_after (c
->label
, insn
);
8393 INSN_ADDRESSES_NEW (insn
, -1);
8395 insn
= emit_insn_after (s390_execute_target (c
->value
), insn
);
8396 INSN_ADDRESSES_NEW (insn
, -1);
8399 /* Switch back to previous section. */
8400 if (TARGET_CPU_ZARCH
)
8402 insn
= emit_insn_after (gen_pool_section_end (), insn
);
8403 INSN_ADDRESSES_NEW (insn
, -1);
8406 insn
= emit_barrier_after (insn
);
8407 INSN_ADDRESSES_NEW (insn
, -1);
8409 /* Remove placeholder insn. */
8410 remove_insn (pool
->pool_insn
);
8413 /* Free all memory used by POOL. */
8416 s390_free_pool (struct constant_pool
*pool
)
8418 struct constant
*c
, *next
;
8421 for (i
= 0; i
< NR_C_MODES
; i
++)
8422 for (c
= pool
->constants
[i
]; c
; c
= next
)
8428 for (c
= pool
->execute
; c
; c
= next
)
8434 BITMAP_FREE (pool
->insns
);
8439 /* Collect main literal pool. Return NULL on overflow. */
8441 static struct constant_pool
*
8442 s390_mainpool_start (void)
8444 struct constant_pool
*pool
;
8447 pool
= s390_alloc_pool ();
8449 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
8451 if (NONJUMP_INSN_P (insn
)
8452 && GET_CODE (PATTERN (insn
)) == SET
8453 && GET_CODE (SET_SRC (PATTERN (insn
))) == UNSPEC_VOLATILE
8454 && XINT (SET_SRC (PATTERN (insn
)), 1) == UNSPECV_MAIN_POOL
)
8456 /* There might be two main_pool instructions if base_reg
8457 is call-clobbered; one for shrink-wrapped code and one
8458 for the rest. We want to keep the first. */
8459 if (pool
->pool_insn
)
8461 insn
= PREV_INSN (insn
);
8462 delete_insn (NEXT_INSN (insn
));
8465 pool
->pool_insn
= insn
;
8468 if (!TARGET_CPU_ZARCH
&& s390_execute_label (insn
))
8470 s390_add_execute (pool
, insn
);
8472 else if (NONJUMP_INSN_P (insn
) || CALL_P (insn
))
8474 rtx pool_ref
= NULL_RTX
;
8475 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
8478 rtx constant
= get_pool_constant (pool_ref
);
8479 machine_mode mode
= get_pool_mode (pool_ref
);
8480 s390_add_constant (pool
, constant
, mode
);
8484 /* If hot/cold partitioning is enabled we have to make sure that
8485 the literal pool is emitted in the same section where the
8486 initialization of the literal pool base pointer takes place.
8487 emit_pool_after is only used in the non-overflow case on non
8488 Z cpus where we can emit the literal pool at the end of the
8489 function body within the text section. */
8491 && NOTE_KIND (insn
) == NOTE_INSN_SWITCH_TEXT_SECTIONS
8492 && !pool
->emit_pool_after
)
8493 pool
->emit_pool_after
= PREV_INSN (insn
);
8496 gcc_assert (pool
->pool_insn
|| pool
->size
== 0);
8498 if (pool
->size
>= 4096)
8500 /* We're going to chunkify the pool, so remove the main
8501 pool placeholder insn. */
8502 remove_insn (pool
->pool_insn
);
8504 s390_free_pool (pool
);
8508 /* If the functions ends with the section where the literal pool
8509 should be emitted set the marker to its end. */
8510 if (pool
&& !pool
->emit_pool_after
)
8511 pool
->emit_pool_after
= get_last_insn ();
8516 /* POOL holds the main literal pool as collected by s390_mainpool_start.
8517 Modify the current function to output the pool constants as well as
8518 the pool register setup instruction. */
8521 s390_mainpool_finish (struct constant_pool
*pool
)
8523 rtx base_reg
= cfun
->machine
->base_reg
;
8525 /* If the pool is empty, we're done. */
8526 if (pool
->size
== 0)
8528 /* We don't actually need a base register after all. */
8529 cfun
->machine
->base_reg
= NULL_RTX
;
8531 if (pool
->pool_insn
)
8532 remove_insn (pool
->pool_insn
);
8533 s390_free_pool (pool
);
8537 /* We need correct insn addresses. */
8538 shorten_branches (get_insns ());
8540 /* On zSeries, we use a LARL to load the pool register. The pool is
8541 located in the .rodata section, so we emit it after the function. */
8542 if (TARGET_CPU_ZARCH
)
8544 rtx set
= gen_main_base_64 (base_reg
, pool
->label
);
8545 rtx_insn
*insn
= emit_insn_after (set
, pool
->pool_insn
);
8546 INSN_ADDRESSES_NEW (insn
, -1);
8547 remove_insn (pool
->pool_insn
);
8549 insn
= get_last_insn ();
8550 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
8551 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
8553 s390_dump_pool (pool
, 0);
8556 /* On S/390, if the total size of the function's code plus literal pool
8557 does not exceed 4096 bytes, we use BASR to set up a function base
8558 pointer, and emit the literal pool at the end of the function. */
8559 else if (INSN_ADDRESSES (INSN_UID (pool
->emit_pool_after
))
8560 + pool
->size
+ 8 /* alignment slop */ < 4096)
8562 rtx set
= gen_main_base_31_small (base_reg
, pool
->label
);
8563 rtx_insn
*insn
= emit_insn_after (set
, pool
->pool_insn
);
8564 INSN_ADDRESSES_NEW (insn
, -1);
8565 remove_insn (pool
->pool_insn
);
8567 insn
= emit_label_after (pool
->label
, insn
);
8568 INSN_ADDRESSES_NEW (insn
, -1);
8570 /* emit_pool_after will be set by s390_mainpool_start to the
8571 last insn of the section where the literal pool should be
8573 insn
= pool
->emit_pool_after
;
8575 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
8576 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
8578 s390_dump_pool (pool
, 1);
8581 /* Otherwise, we emit an inline literal pool and use BASR to branch
8582 over it, setting up the pool register at the same time. */
8585 rtx_code_label
*pool_end
= gen_label_rtx ();
8587 rtx pat
= gen_main_base_31_large (base_reg
, pool
->label
, pool_end
);
8588 rtx_insn
*insn
= emit_jump_insn_after (pat
, pool
->pool_insn
);
8589 JUMP_LABEL (insn
) = pool_end
;
8590 INSN_ADDRESSES_NEW (insn
, -1);
8591 remove_insn (pool
->pool_insn
);
8593 insn
= emit_label_after (pool
->label
, insn
);
8594 INSN_ADDRESSES_NEW (insn
, -1);
8596 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
8597 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
8599 insn
= emit_label_after (pool_end
, pool
->pool_insn
);
8600 INSN_ADDRESSES_NEW (insn
, -1);
8602 s390_dump_pool (pool
, 1);
8606 /* Replace all literal pool references. */
8608 for (rtx_insn
*insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
8611 replace_ltrel_base (&PATTERN (insn
));
8613 if (NONJUMP_INSN_P (insn
) || CALL_P (insn
))
8615 rtx addr
, pool_ref
= NULL_RTX
;
8616 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
8619 if (s390_execute_label (insn
))
8620 addr
= s390_find_execute (pool
, insn
);
8622 addr
= s390_find_constant (pool
, get_pool_constant (pool_ref
),
8623 get_pool_mode (pool_ref
));
8625 replace_constant_pool_ref (&PATTERN (insn
), pool_ref
, addr
);
8626 INSN_CODE (insn
) = -1;
8632 /* Free the pool. */
8633 s390_free_pool (pool
);
8636 /* POOL holds the main literal pool as collected by s390_mainpool_start.
8637 We have decided we cannot use this pool, so revert all changes
8638 to the current function that were done by s390_mainpool_start. */
8640 s390_mainpool_cancel (struct constant_pool
*pool
)
8642 /* We didn't actually change the instruction stream, so simply
8643 free the pool memory. */
8644 s390_free_pool (pool
);
8648 /* Chunkify the literal pool. */
8650 #define S390_POOL_CHUNK_MIN 0xc00
8651 #define S390_POOL_CHUNK_MAX 0xe00
8653 static struct constant_pool
*
8654 s390_chunkify_start (void)
8656 struct constant_pool
*curr_pool
= NULL
, *pool_list
= NULL
;
8659 rtx pending_ltrel
= NULL_RTX
;
8662 rtx (*gen_reload_base
) (rtx
, rtx
) =
8663 TARGET_CPU_ZARCH
? gen_reload_base_64
: gen_reload_base_31
;
8666 /* We need correct insn addresses. */
8668 shorten_branches (get_insns ());
8670 /* Scan all insns and move literals to pool chunks. */
8672 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
8674 bool section_switch_p
= false;
8676 /* Check for pending LTREL_BASE. */
8679 rtx ltrel_base
= find_ltrel_base (PATTERN (insn
));
8682 gcc_assert (ltrel_base
== pending_ltrel
);
8683 pending_ltrel
= NULL_RTX
;
8687 if (!TARGET_CPU_ZARCH
&& s390_execute_label (insn
))
8690 curr_pool
= s390_start_pool (&pool_list
, insn
);
8692 s390_add_execute (curr_pool
, insn
);
8693 s390_add_pool_insn (curr_pool
, insn
);
8695 else if (NONJUMP_INSN_P (insn
) || CALL_P (insn
))
8697 rtx pool_ref
= NULL_RTX
;
8698 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
8701 rtx constant
= get_pool_constant (pool_ref
);
8702 machine_mode mode
= get_pool_mode (pool_ref
);
8705 curr_pool
= s390_start_pool (&pool_list
, insn
);
8707 s390_add_constant (curr_pool
, constant
, mode
);
8708 s390_add_pool_insn (curr_pool
, insn
);
8710 /* Don't split the pool chunk between a LTREL_OFFSET load
8711 and the corresponding LTREL_BASE. */
8712 if (GET_CODE (constant
) == CONST
8713 && GET_CODE (XEXP (constant
, 0)) == UNSPEC
8714 && XINT (XEXP (constant
, 0), 1) == UNSPEC_LTREL_OFFSET
)
8716 gcc_assert (!pending_ltrel
);
8717 pending_ltrel
= pool_ref
;
8722 if (JUMP_P (insn
) || JUMP_TABLE_DATA_P (insn
) || LABEL_P (insn
))
8725 s390_add_pool_insn (curr_pool
, insn
);
8726 /* An LTREL_BASE must follow within the same basic block. */
8727 gcc_assert (!pending_ltrel
);
8731 switch (NOTE_KIND (insn
))
8733 case NOTE_INSN_SWITCH_TEXT_SECTIONS
:
8734 section_switch_p
= true;
8736 case NOTE_INSN_VAR_LOCATION
:
8737 case NOTE_INSN_CALL_ARG_LOCATION
:
8744 || INSN_ADDRESSES_SIZE () <= (size_t) INSN_UID (insn
)
8745 || INSN_ADDRESSES (INSN_UID (insn
)) == -1)
8748 if (TARGET_CPU_ZARCH
)
8750 if (curr_pool
->size
< S390_POOL_CHUNK_MAX
)
8753 s390_end_pool (curr_pool
, NULL
);
8758 int chunk_size
= INSN_ADDRESSES (INSN_UID (insn
))
8759 - INSN_ADDRESSES (INSN_UID (curr_pool
->first_insn
))
8762 /* We will later have to insert base register reload insns.
8763 Those will have an effect on code size, which we need to
8764 consider here. This calculation makes rather pessimistic
8765 worst-case assumptions. */
8769 if (chunk_size
< S390_POOL_CHUNK_MIN
8770 && curr_pool
->size
< S390_POOL_CHUNK_MIN
8771 && !section_switch_p
)
8774 /* Pool chunks can only be inserted after BARRIERs ... */
8775 if (BARRIER_P (insn
))
8777 s390_end_pool (curr_pool
, insn
);
8782 /* ... so if we don't find one in time, create one. */
8783 else if (chunk_size
> S390_POOL_CHUNK_MAX
8784 || curr_pool
->size
> S390_POOL_CHUNK_MAX
8785 || section_switch_p
)
8787 rtx_insn
*label
, *jump
, *barrier
, *next
, *prev
;
8789 if (!section_switch_p
)
8791 /* We can insert the barrier only after a 'real' insn. */
8792 if (! NONJUMP_INSN_P (insn
) && ! CALL_P (insn
))
8794 if (get_attr_length (insn
) == 0)
8796 /* Don't separate LTREL_BASE from the corresponding
8797 LTREL_OFFSET load. */
8804 next
= NEXT_INSN (insn
);
8808 && (NOTE_KIND (next
) == NOTE_INSN_VAR_LOCATION
8809 || NOTE_KIND (next
) == NOTE_INSN_CALL_ARG_LOCATION
));
8813 gcc_assert (!pending_ltrel
);
8815 /* The old pool has to end before the section switch
8816 note in order to make it part of the current
8818 insn
= PREV_INSN (insn
);
8821 label
= gen_label_rtx ();
8823 if (prev
&& NOTE_P (prev
))
8824 prev
= prev_nonnote_insn (prev
);
8826 jump
= emit_jump_insn_after_setloc (gen_jump (label
), insn
,
8827 INSN_LOCATION (prev
));
8829 jump
= emit_jump_insn_after_noloc (gen_jump (label
), insn
);
8830 barrier
= emit_barrier_after (jump
);
8831 insn
= emit_label_after (label
, barrier
);
8832 JUMP_LABEL (jump
) = label
;
8833 LABEL_NUSES (label
) = 1;
8835 INSN_ADDRESSES_NEW (jump
, -1);
8836 INSN_ADDRESSES_NEW (barrier
, -1);
8837 INSN_ADDRESSES_NEW (insn
, -1);
8839 s390_end_pool (curr_pool
, barrier
);
8847 s390_end_pool (curr_pool
, NULL
);
8848 gcc_assert (!pending_ltrel
);
8850 /* Find all labels that are branched into
8851 from an insn belonging to a different chunk. */
8853 far_labels
= BITMAP_ALLOC (NULL
);
8855 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
8857 rtx_jump_table_data
*table
;
8859 /* Labels marked with LABEL_PRESERVE_P can be target
8860 of non-local jumps, so we have to mark them.
8861 The same holds for named labels.
8863 Don't do that, however, if it is the label before
8867 && (LABEL_PRESERVE_P (insn
) || LABEL_NAME (insn
)))
8869 rtx_insn
*vec_insn
= NEXT_INSN (insn
);
8870 if (! vec_insn
|| ! JUMP_TABLE_DATA_P (vec_insn
))
8871 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (insn
));
8873 /* Check potential targets in a table jump (casesi_jump). */
8874 else if (tablejump_p (insn
, NULL
, &table
))
8876 rtx vec_pat
= PATTERN (table
);
8877 int i
, diff_p
= GET_CODE (vec_pat
) == ADDR_DIFF_VEC
;
8879 for (i
= 0; i
< XVECLEN (vec_pat
, diff_p
); i
++)
8881 rtx label
= XEXP (XVECEXP (vec_pat
, diff_p
, i
), 0);
8883 if (s390_find_pool (pool_list
, label
)
8884 != s390_find_pool (pool_list
, insn
))
8885 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (label
));
8888 /* If we have a direct jump (conditional or unconditional),
8889 check all potential targets. */
8890 else if (JUMP_P (insn
))
8892 rtx pat
= PATTERN (insn
);
8894 if (GET_CODE (pat
) == PARALLEL
)
8895 pat
= XVECEXP (pat
, 0, 0);
8897 if (GET_CODE (pat
) == SET
)
8899 rtx label
= JUMP_LABEL (insn
);
8900 if (label
&& !ANY_RETURN_P (label
))
8902 if (s390_find_pool (pool_list
, label
)
8903 != s390_find_pool (pool_list
, insn
))
8904 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (label
));
8910 /* Insert base register reload insns before every pool. */
8912 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
8914 rtx new_insn
= gen_reload_base (cfun
->machine
->base_reg
,
8916 rtx_insn
*insn
= curr_pool
->first_insn
;
8917 INSN_ADDRESSES_NEW (emit_insn_before (new_insn
, insn
), -1);
8920 /* Insert base register reload insns at every far label. */
8922 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
8924 && bitmap_bit_p (far_labels
, CODE_LABEL_NUMBER (insn
)))
8926 struct constant_pool
*pool
= s390_find_pool (pool_list
, insn
);
8929 rtx new_insn
= gen_reload_base (cfun
->machine
->base_reg
,
8931 INSN_ADDRESSES_NEW (emit_insn_after (new_insn
, insn
), -1);
8936 BITMAP_FREE (far_labels
);
8939 /* Recompute insn addresses. */
8941 init_insn_lengths ();
8942 shorten_branches (get_insns ());
8947 /* POOL_LIST is a chunk list as prepared by s390_chunkify_start.
8948 After we have decided to use this list, finish implementing
8949 all changes to the current function as required. */
8952 s390_chunkify_finish (struct constant_pool
*pool_list
)
8954 struct constant_pool
*curr_pool
= NULL
;
8958 /* Replace all literal pool references. */
8960 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
8963 replace_ltrel_base (&PATTERN (insn
));
8965 curr_pool
= s390_find_pool (pool_list
, insn
);
8969 if (NONJUMP_INSN_P (insn
) || CALL_P (insn
))
8971 rtx addr
, pool_ref
= NULL_RTX
;
8972 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
8975 if (s390_execute_label (insn
))
8976 addr
= s390_find_execute (curr_pool
, insn
);
8978 addr
= s390_find_constant (curr_pool
,
8979 get_pool_constant (pool_ref
),
8980 get_pool_mode (pool_ref
));
8982 replace_constant_pool_ref (&PATTERN (insn
), pool_ref
, addr
);
8983 INSN_CODE (insn
) = -1;
8988 /* Dump out all literal pools. */
8990 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
8991 s390_dump_pool (curr_pool
, 0);
8993 /* Free pool list. */
8997 struct constant_pool
*next
= pool_list
->next
;
8998 s390_free_pool (pool_list
);
9003 /* POOL_LIST is a chunk list as prepared by s390_chunkify_start.
9004 We have decided we cannot use this list, so revert all changes
9005 to the current function that were done by s390_chunkify_start. */
9008 s390_chunkify_cancel (struct constant_pool
*pool_list
)
9010 struct constant_pool
*curr_pool
= NULL
;
9013 /* Remove all pool placeholder insns. */
9015 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
9017 /* Did we insert an extra barrier? Remove it. */
9018 rtx_insn
*barrier
= PREV_INSN (curr_pool
->pool_insn
);
9019 rtx_insn
*jump
= barrier
? PREV_INSN (barrier
) : NULL
;
9020 rtx_insn
*label
= NEXT_INSN (curr_pool
->pool_insn
);
9022 if (jump
&& JUMP_P (jump
)
9023 && barrier
&& BARRIER_P (barrier
)
9024 && label
&& LABEL_P (label
)
9025 && GET_CODE (PATTERN (jump
)) == SET
9026 && SET_DEST (PATTERN (jump
)) == pc_rtx
9027 && GET_CODE (SET_SRC (PATTERN (jump
))) == LABEL_REF
9028 && XEXP (SET_SRC (PATTERN (jump
)), 0) == label
)
9031 remove_insn (barrier
);
9032 remove_insn (label
);
9035 remove_insn (curr_pool
->pool_insn
);
9038 /* Remove all base register reload insns. */
9040 for (insn
= get_insns (); insn
; )
9042 rtx_insn
*next_insn
= NEXT_INSN (insn
);
9044 if (NONJUMP_INSN_P (insn
)
9045 && GET_CODE (PATTERN (insn
)) == SET
9046 && GET_CODE (SET_SRC (PATTERN (insn
))) == UNSPEC
9047 && XINT (SET_SRC (PATTERN (insn
)), 1) == UNSPEC_RELOAD_BASE
)
9053 /* Free pool list. */
9057 struct constant_pool
*next
= pool_list
->next
;
9058 s390_free_pool (pool_list
);
9063 /* Output the constant pool entry EXP in mode MODE with alignment ALIGN. */
9066 s390_output_pool_entry (rtx exp
, machine_mode mode
, unsigned int align
)
9068 switch (GET_MODE_CLASS (mode
))
9071 case MODE_DECIMAL_FLOAT
:
9072 gcc_assert (GET_CODE (exp
) == CONST_DOUBLE
);
9074 assemble_real (*CONST_DOUBLE_REAL_VALUE (exp
), mode
, align
);
9078 assemble_integer (exp
, GET_MODE_SIZE (mode
), align
, 1);
9079 mark_symbol_refs_as_used (exp
);
9082 case MODE_VECTOR_INT
:
9083 case MODE_VECTOR_FLOAT
:
9086 machine_mode inner_mode
;
9087 gcc_assert (GET_CODE (exp
) == CONST_VECTOR
);
9089 inner_mode
= GET_MODE_INNER (GET_MODE (exp
));
9090 for (i
= 0; i
< XVECLEN (exp
, 0); i
++)
9091 s390_output_pool_entry (XVECEXP (exp
, 0, i
),
9095 : GET_MODE_BITSIZE (inner_mode
));
9105 /* Return an RTL expression representing the value of the return address
9106 for the frame COUNT steps up from the current frame. FRAME is the
9107 frame pointer of that frame. */
9110 s390_return_addr_rtx (int count
, rtx frame ATTRIBUTE_UNUSED
)
9115 /* Without backchain, we fail for all but the current frame. */
9117 if (!TARGET_BACKCHAIN
&& count
> 0)
9120 /* For the current frame, we need to make sure the initial
9121 value of RETURN_REGNUM is actually saved. */
9125 /* On non-z architectures branch splitting could overwrite r14. */
9126 if (TARGET_CPU_ZARCH
)
9127 return get_hard_reg_initial_val (Pmode
, RETURN_REGNUM
);
9130 cfun_frame_layout
.save_return_addr_p
= true;
9131 return gen_rtx_MEM (Pmode
, return_address_pointer_rtx
);
9135 if (TARGET_PACKED_STACK
)
9136 offset
= -2 * UNITS_PER_LONG
;
9138 offset
= RETURN_REGNUM
* UNITS_PER_LONG
;
9140 addr
= plus_constant (Pmode
, frame
, offset
);
9141 addr
= memory_address (Pmode
, addr
);
9142 return gen_rtx_MEM (Pmode
, addr
);
9145 /* Return an RTL expression representing the back chain stored in
9146 the current stack frame. */
9149 s390_back_chain_rtx (void)
9153 gcc_assert (TARGET_BACKCHAIN
);
9155 if (TARGET_PACKED_STACK
)
9156 chain
= plus_constant (Pmode
, stack_pointer_rtx
,
9157 STACK_POINTER_OFFSET
- UNITS_PER_LONG
);
9159 chain
= stack_pointer_rtx
;
9161 chain
= gen_rtx_MEM (Pmode
, chain
);
9165 /* Find first call clobbered register unused in a function.
9166 This could be used as base register in a leaf function
9167 or for holding the return address before epilogue. */
9170 find_unused_clobbered_reg (void)
9173 for (i
= 0; i
< 6; i
++)
9174 if (!df_regs_ever_live_p (i
))
9180 /* Helper function for s390_regs_ever_clobbered. Sets the fields in DATA for all
9181 clobbered hard regs in SETREG. */
9184 s390_reg_clobbered_rtx (rtx setreg
, const_rtx set_insn ATTRIBUTE_UNUSED
, void *data
)
9186 char *regs_ever_clobbered
= (char *)data
;
9187 unsigned int i
, regno
;
9188 machine_mode mode
= GET_MODE (setreg
);
9190 if (GET_CODE (setreg
) == SUBREG
)
9192 rtx inner
= SUBREG_REG (setreg
);
9193 if (!GENERAL_REG_P (inner
) && !FP_REG_P (inner
))
9195 regno
= subreg_regno (setreg
);
9197 else if (GENERAL_REG_P (setreg
) || FP_REG_P (setreg
))
9198 regno
= REGNO (setreg
);
9203 i
< regno
+ HARD_REGNO_NREGS (regno
, mode
);
9205 regs_ever_clobbered
[i
] = 1;
9208 /* Walks through all basic blocks of the current function looking
9209 for clobbered hard regs using s390_reg_clobbered_rtx. The fields
9210 of the passed integer array REGS_EVER_CLOBBERED are set to one for
9211 each of those regs. */
9214 s390_regs_ever_clobbered (char regs_ever_clobbered
[])
9220 memset (regs_ever_clobbered
, 0, 32);
9222 /* For non-leaf functions we have to consider all call clobbered regs to be
9226 for (i
= 0; i
< 32; i
++)
9227 regs_ever_clobbered
[i
] = call_really_used_regs
[i
];
9230 /* Make the "magic" eh_return registers live if necessary. For regs_ever_live
9231 this work is done by liveness analysis (mark_regs_live_at_end).
9232 Special care is needed for functions containing landing pads. Landing pads
9233 may use the eh registers, but the code which sets these registers is not
9234 contained in that function. Hence s390_regs_ever_clobbered is not able to
9235 deal with this automatically. */
9236 if (crtl
->calls_eh_return
|| cfun
->machine
->has_landing_pad_p
)
9237 for (i
= 0; EH_RETURN_DATA_REGNO (i
) != INVALID_REGNUM
; i
++)
9238 if (crtl
->calls_eh_return
9239 || (cfun
->machine
->has_landing_pad_p
9240 && df_regs_ever_live_p (EH_RETURN_DATA_REGNO (i
))))
9241 regs_ever_clobbered
[EH_RETURN_DATA_REGNO (i
)] = 1;
9243 /* For nonlocal gotos all call-saved registers have to be saved.
9244 This flag is also set for the unwinding code in libgcc.
9245 See expand_builtin_unwind_init. For regs_ever_live this is done by
9247 if (crtl
->saves_all_registers
)
9248 for (i
= 0; i
< 32; i
++)
9249 if (!call_really_used_regs
[i
])
9250 regs_ever_clobbered
[i
] = 1;
9252 FOR_EACH_BB_FN (cur_bb
, cfun
)
9254 FOR_BB_INSNS (cur_bb
, cur_insn
)
9258 if (!INSN_P (cur_insn
))
9261 pat
= PATTERN (cur_insn
);
9263 /* Ignore GPR restore insns. */
9264 if (epilogue_completed
&& RTX_FRAME_RELATED_P (cur_insn
))
9266 if (GET_CODE (pat
) == SET
9267 && GENERAL_REG_P (SET_DEST (pat
)))
9270 if (GET_MODE (SET_SRC (pat
)) == DImode
9271 && FP_REG_P (SET_SRC (pat
)))
9275 if (GET_CODE (SET_SRC (pat
)) == MEM
)
9280 if (GET_CODE (pat
) == PARALLEL
9281 && load_multiple_operation (pat
, VOIDmode
))
9286 s390_reg_clobbered_rtx
,
9287 regs_ever_clobbered
);
9292 /* Determine the frame area which actually has to be accessed
9293 in the function epilogue. The values are stored at the
9294 given pointers AREA_BOTTOM (address of the lowest used stack
9295 address) and AREA_TOP (address of the first item which does
9296 not belong to the stack frame). */
9299 s390_frame_area (int *area_bottom
, int *area_top
)
9306 if (cfun_frame_layout
.first_restore_gpr
!= -1)
9308 b
= (cfun_frame_layout
.gprs_offset
9309 + cfun_frame_layout
.first_restore_gpr
* UNITS_PER_LONG
);
9310 t
= b
+ (cfun_frame_layout
.last_restore_gpr
9311 - cfun_frame_layout
.first_restore_gpr
+ 1) * UNITS_PER_LONG
;
9314 if (TARGET_64BIT
&& cfun_save_high_fprs_p
)
9316 b
= MIN (b
, cfun_frame_layout
.f8_offset
);
9317 t
= MAX (t
, (cfun_frame_layout
.f8_offset
9318 + cfun_frame_layout
.high_fprs
* 8));
9323 if (cfun_fpr_save_p (FPR4_REGNUM
))
9325 b
= MIN (b
, cfun_frame_layout
.f4_offset
);
9326 t
= MAX (t
, cfun_frame_layout
.f4_offset
+ 8);
9328 if (cfun_fpr_save_p (FPR6_REGNUM
))
9330 b
= MIN (b
, cfun_frame_layout
.f4_offset
+ 8);
9331 t
= MAX (t
, cfun_frame_layout
.f4_offset
+ 16);
9337 /* Update gpr_save_slots in the frame layout trying to make use of
9338 FPRs as GPR save slots.
9339 This is a helper routine of s390_register_info. */
9342 s390_register_info_gprtofpr ()
9344 int save_reg_slot
= FPR0_REGNUM
;
9347 if (!TARGET_Z10
|| !TARGET_HARD_FLOAT
|| !crtl
->is_leaf
)
9350 for (i
= 15; i
>= 6; i
--)
9352 if (cfun_gpr_save_slot (i
) == SAVE_SLOT_NONE
)
9355 /* Advance to the next FP register which can be used as a
9357 while ((!call_really_used_regs
[save_reg_slot
]
9358 || df_regs_ever_live_p (save_reg_slot
)
9359 || cfun_fpr_save_p (save_reg_slot
))
9360 && FP_REGNO_P (save_reg_slot
))
9362 if (!FP_REGNO_P (save_reg_slot
))
9364 /* We only want to use ldgr/lgdr if we can get rid of
9365 stm/lm entirely. So undo the gpr slot allocation in
9366 case we ran out of FPR save slots. */
9367 for (j
= 6; j
<= 15; j
++)
9368 if (FP_REGNO_P (cfun_gpr_save_slot (j
)))
9369 cfun_gpr_save_slot (j
) = SAVE_SLOT_STACK
;
9372 cfun_gpr_save_slot (i
) = save_reg_slot
++;
9376 /* Set the bits in fpr_bitmap for FPRs which need to be saved due to
9378 This is a helper routine for s390_register_info. */
9381 s390_register_info_stdarg_fpr ()
9387 /* Save the FP argument regs for stdarg. f0, f2 for 31 bit and
9388 f0-f4 for 64 bit. */
9390 || !TARGET_HARD_FLOAT
9391 || !cfun
->va_list_fpr_size
9392 || crtl
->args
.info
.fprs
>= FP_ARG_NUM_REG
)
9395 min_fpr
= crtl
->args
.info
.fprs
;
9396 max_fpr
= min_fpr
+ cfun
->va_list_fpr_size
- 1;
9397 if (max_fpr
>= FP_ARG_NUM_REG
)
9398 max_fpr
= FP_ARG_NUM_REG
- 1;
9400 /* FPR argument regs start at f0. */
9401 min_fpr
+= FPR0_REGNUM
;
9402 max_fpr
+= FPR0_REGNUM
;
9404 for (i
= min_fpr
; i
<= max_fpr
; i
++)
9405 cfun_set_fpr_save (i
);
9408 /* Reserve the GPR save slots for GPRs which need to be saved due to
9410 This is a helper routine for s390_register_info. */
9413 s390_register_info_stdarg_gpr ()
9420 || !cfun
->va_list_gpr_size
9421 || crtl
->args
.info
.gprs
>= GP_ARG_NUM_REG
)
9424 min_gpr
= crtl
->args
.info
.gprs
;
9425 max_gpr
= min_gpr
+ cfun
->va_list_gpr_size
- 1;
9426 if (max_gpr
>= GP_ARG_NUM_REG
)
9427 max_gpr
= GP_ARG_NUM_REG
- 1;
9429 /* GPR argument regs start at r2. */
9430 min_gpr
+= GPR2_REGNUM
;
9431 max_gpr
+= GPR2_REGNUM
;
9433 /* If r6 was supposed to be saved into an FPR and now needs to go to
9434 the stack for vararg we have to adjust the restore range to make
9435 sure that the restore is done from stack as well. */
9436 if (FP_REGNO_P (cfun_gpr_save_slot (GPR6_REGNUM
))
9437 && min_gpr
<= GPR6_REGNUM
9438 && max_gpr
>= GPR6_REGNUM
)
9440 if (cfun_frame_layout
.first_restore_gpr
== -1
9441 || cfun_frame_layout
.first_restore_gpr
> GPR6_REGNUM
)
9442 cfun_frame_layout
.first_restore_gpr
= GPR6_REGNUM
;
9443 if (cfun_frame_layout
.last_restore_gpr
== -1
9444 || cfun_frame_layout
.last_restore_gpr
< GPR6_REGNUM
)
9445 cfun_frame_layout
.last_restore_gpr
= GPR6_REGNUM
;
9448 if (cfun_frame_layout
.first_save_gpr
== -1
9449 || cfun_frame_layout
.first_save_gpr
> min_gpr
)
9450 cfun_frame_layout
.first_save_gpr
= min_gpr
;
9452 if (cfun_frame_layout
.last_save_gpr
== -1
9453 || cfun_frame_layout
.last_save_gpr
< max_gpr
)
9454 cfun_frame_layout
.last_save_gpr
= max_gpr
;
9456 for (i
= min_gpr
; i
<= max_gpr
; i
++)
9457 cfun_gpr_save_slot (i
) = SAVE_SLOT_STACK
;
9460 /* Calculate the save and restore ranges for stm(g) and lm(g) in the
9461 prologue and epilogue. */
9464 s390_register_info_set_ranges ()
9468 /* Find the first and the last save slot supposed to use the stack
9469 to set the restore range.
9470 Vararg regs might be marked as save to stack but only the
9471 call-saved regs really need restoring (i.e. r6). This code
9472 assumes that the vararg regs have not yet been recorded in
9473 cfun_gpr_save_slot. */
9474 for (i
= 0; i
< 16 && cfun_gpr_save_slot (i
) != SAVE_SLOT_STACK
; i
++);
9475 for (j
= 15; j
> i
&& cfun_gpr_save_slot (j
) != SAVE_SLOT_STACK
; j
--);
9476 cfun_frame_layout
.first_restore_gpr
= (i
== 16) ? -1 : i
;
9477 cfun_frame_layout
.last_restore_gpr
= (i
== 16) ? -1 : j
;
9478 cfun_frame_layout
.first_save_gpr
= (i
== 16) ? -1 : i
;
9479 cfun_frame_layout
.last_save_gpr
= (i
== 16) ? -1 : j
;
9482 /* The GPR and FPR save slots in cfun->machine->frame_layout are set
9483 for registers which need to be saved in function prologue.
9484 This function can be used until the insns emitted for save/restore
9485 of the regs are visible in the RTL stream. */
9488 s390_register_info ()
9491 char clobbered_regs
[32];
9493 gcc_assert (!epilogue_completed
);
9495 if (reload_completed
)
9496 /* After reload we rely on our own routine to determine which
9497 registers need saving. */
9498 s390_regs_ever_clobbered (clobbered_regs
);
9500 /* During reload we use regs_ever_live as a base since reload
9501 does changes in there which we otherwise would not be aware
9503 for (i
= 0; i
< 32; i
++)
9504 clobbered_regs
[i
] = df_regs_ever_live_p (i
);
9506 for (i
= 0; i
< 32; i
++)
9507 clobbered_regs
[i
] = clobbered_regs
[i
] && !global_regs
[i
];
9509 /* Mark the call-saved FPRs which need to be saved.
9510 This needs to be done before checking the special GPRs since the
9511 stack pointer usage depends on whether high FPRs have to be saved
9513 cfun_frame_layout
.fpr_bitmap
= 0;
9514 cfun_frame_layout
.high_fprs
= 0;
9515 for (i
= FPR0_REGNUM
; i
<= FPR15_REGNUM
; i
++)
9516 if (clobbered_regs
[i
] && !call_really_used_regs
[i
])
9518 cfun_set_fpr_save (i
);
9519 if (i
>= FPR8_REGNUM
)
9520 cfun_frame_layout
.high_fprs
++;
9523 /* Register 12 is used for GOT address, but also as temp in prologue
9524 for split-stack stdarg functions (unless r14 is available). */
9526 |= ((flag_pic
&& df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM
))
9527 || (flag_split_stack
&& cfun
->stdarg
9528 && (crtl
->is_leaf
|| TARGET_TPF_PROFILING
9529 || has_hard_reg_initial_val (Pmode
, RETURN_REGNUM
))));
9531 clobbered_regs
[BASE_REGNUM
]
9532 |= (cfun
->machine
->base_reg
9533 && REGNO (cfun
->machine
->base_reg
) == BASE_REGNUM
);
9535 clobbered_regs
[HARD_FRAME_POINTER_REGNUM
]
9536 |= !!frame_pointer_needed
;
9538 /* On pre z900 machines this might take until machine dependent
9540 save_return_addr_p will only be set on non-zarch machines so
9541 there is no risk that r14 goes into an FPR instead of a stack
9543 clobbered_regs
[RETURN_REGNUM
]
9545 || TARGET_TPF_PROFILING
9546 || cfun
->machine
->split_branches_pending_p
9547 || cfun_frame_layout
.save_return_addr_p
9548 || crtl
->calls_eh_return
);
9550 clobbered_regs
[STACK_POINTER_REGNUM
]
9552 || TARGET_TPF_PROFILING
9553 || cfun_save_high_fprs_p
9554 || get_frame_size () > 0
9555 || (reload_completed
&& cfun_frame_layout
.frame_size
> 0)
9556 || cfun
->calls_alloca
);
9558 memset (cfun_frame_layout
.gpr_save_slots
, SAVE_SLOT_NONE
, 16);
9560 for (i
= 6; i
< 16; i
++)
9561 if (clobbered_regs
[i
])
9562 cfun_gpr_save_slot (i
) = SAVE_SLOT_STACK
;
9564 s390_register_info_stdarg_fpr ();
9565 s390_register_info_gprtofpr ();
9566 s390_register_info_set_ranges ();
9567 /* stdarg functions might need to save GPRs 2 to 6. This might
9568 override the GPR->FPR save decision made by
9569 s390_register_info_gprtofpr for r6 since vararg regs must go to
9571 s390_register_info_stdarg_gpr ();
9574 /* This function is called by s390_optimize_prologue in order to get
9575 rid of unnecessary GPR save/restore instructions. The register info
9576 for the GPRs is re-computed and the ranges are re-calculated. */
9579 s390_optimize_register_info ()
9581 char clobbered_regs
[32];
9584 gcc_assert (epilogue_completed
);
9585 gcc_assert (!cfun
->machine
->split_branches_pending_p
);
9587 s390_regs_ever_clobbered (clobbered_regs
);
9589 for (i
= 0; i
< 32; i
++)
9590 clobbered_regs
[i
] = clobbered_regs
[i
] && !global_regs
[i
];
9592 /* There is still special treatment needed for cases invisible to
9593 s390_regs_ever_clobbered. */
9594 clobbered_regs
[RETURN_REGNUM
]
9595 |= (TARGET_TPF_PROFILING
9596 /* When expanding builtin_return_addr in ESA mode we do not
9597 know whether r14 will later be needed as scratch reg when
9598 doing branch splitting. So the builtin always accesses the
9599 r14 save slot and we need to stick to the save/restore
9600 decision for r14 even if it turns out that it didn't get
9602 || cfun_frame_layout
.save_return_addr_p
9603 || crtl
->calls_eh_return
);
9605 memset (cfun_frame_layout
.gpr_save_slots
, SAVE_SLOT_NONE
, 6);
9607 for (i
= 6; i
< 16; i
++)
9608 if (!clobbered_regs
[i
])
9609 cfun_gpr_save_slot (i
) = SAVE_SLOT_NONE
;
9611 s390_register_info_set_ranges ();
9612 s390_register_info_stdarg_gpr ();
9615 /* Fill cfun->machine with info about frame of current function. */
9618 s390_frame_info (void)
9620 HOST_WIDE_INT lowest_offset
;
9622 cfun_frame_layout
.first_save_gpr_slot
= cfun_frame_layout
.first_save_gpr
;
9623 cfun_frame_layout
.last_save_gpr_slot
= cfun_frame_layout
.last_save_gpr
;
9625 /* The va_arg builtin uses a constant distance of 16 *
9626 UNITS_PER_LONG (r0-r15) to reach the FPRs from the reg_save_area
9627 pointer. So even if we are going to save the stack pointer in an
9628 FPR we need the stack space in order to keep the offsets
9630 if (cfun
->stdarg
&& cfun_save_arg_fprs_p
)
9632 cfun_frame_layout
.last_save_gpr_slot
= STACK_POINTER_REGNUM
;
9634 if (cfun_frame_layout
.first_save_gpr_slot
== -1)
9635 cfun_frame_layout
.first_save_gpr_slot
= STACK_POINTER_REGNUM
;
9638 cfun_frame_layout
.frame_size
= get_frame_size ();
9639 if (!TARGET_64BIT
&& cfun_frame_layout
.frame_size
> 0x7fff0000)
9640 fatal_error (input_location
,
9641 "total size of local variables exceeds architecture limit");
9643 if (!TARGET_PACKED_STACK
)
9645 /* Fixed stack layout. */
9646 cfun_frame_layout
.backchain_offset
= 0;
9647 cfun_frame_layout
.f0_offset
= 16 * UNITS_PER_LONG
;
9648 cfun_frame_layout
.f4_offset
= cfun_frame_layout
.f0_offset
+ 2 * 8;
9649 cfun_frame_layout
.f8_offset
= -cfun_frame_layout
.high_fprs
* 8;
9650 cfun_frame_layout
.gprs_offset
= (cfun_frame_layout
.first_save_gpr_slot
9653 else if (TARGET_BACKCHAIN
)
9655 /* Kernel stack layout - packed stack, backchain, no float */
9656 gcc_assert (TARGET_SOFT_FLOAT
);
9657 cfun_frame_layout
.backchain_offset
= (STACK_POINTER_OFFSET
9660 /* The distance between the backchain and the return address
9661 save slot must not change. So we always need a slot for the
9662 stack pointer which resides in between. */
9663 cfun_frame_layout
.last_save_gpr_slot
= STACK_POINTER_REGNUM
;
9665 cfun_frame_layout
.gprs_offset
9666 = cfun_frame_layout
.backchain_offset
- cfun_gprs_save_area_size
;
9668 /* FPRs will not be saved. Nevertheless pick sane values to
9669 keep area calculations valid. */
9670 cfun_frame_layout
.f0_offset
=
9671 cfun_frame_layout
.f4_offset
=
9672 cfun_frame_layout
.f8_offset
= cfun_frame_layout
.gprs_offset
;
9678 /* Packed stack layout without backchain. */
9680 /* With stdarg FPRs need their dedicated slots. */
9681 num_fprs
= (TARGET_64BIT
&& cfun
->stdarg
? 2
9682 : (cfun_fpr_save_p (FPR4_REGNUM
) +
9683 cfun_fpr_save_p (FPR6_REGNUM
)));
9684 cfun_frame_layout
.f4_offset
= STACK_POINTER_OFFSET
- 8 * num_fprs
;
9686 num_fprs
= (cfun
->stdarg
? 2
9687 : (cfun_fpr_save_p (FPR0_REGNUM
)
9688 + cfun_fpr_save_p (FPR2_REGNUM
)));
9689 cfun_frame_layout
.f0_offset
= cfun_frame_layout
.f4_offset
- 8 * num_fprs
;
9691 cfun_frame_layout
.gprs_offset
9692 = cfun_frame_layout
.f0_offset
- cfun_gprs_save_area_size
;
9694 cfun_frame_layout
.f8_offset
= (cfun_frame_layout
.gprs_offset
9695 - cfun_frame_layout
.high_fprs
* 8);
9698 if (cfun_save_high_fprs_p
)
9699 cfun_frame_layout
.frame_size
+= cfun_frame_layout
.high_fprs
* 8;
9702 cfun_frame_layout
.frame_size
+= crtl
->outgoing_args_size
;
9704 /* In the following cases we have to allocate a STACK_POINTER_OFFSET
9705 sized area at the bottom of the stack. This is required also for
9706 leaf functions. When GCC generates a local stack reference it
9707 will always add STACK_POINTER_OFFSET to all these references. */
9709 && !TARGET_TPF_PROFILING
9710 && cfun_frame_layout
.frame_size
== 0
9711 && !cfun
->calls_alloca
)
9714 /* Calculate the number of bytes we have used in our own register
9715 save area. With the packed stack layout we can re-use the
9716 remaining bytes for normal stack elements. */
9718 if (TARGET_PACKED_STACK
)
9719 lowest_offset
= MIN (MIN (cfun_frame_layout
.f0_offset
,
9720 cfun_frame_layout
.f4_offset
),
9721 cfun_frame_layout
.gprs_offset
);
9725 if (TARGET_BACKCHAIN
)
9726 lowest_offset
= MIN (lowest_offset
, cfun_frame_layout
.backchain_offset
);
9728 cfun_frame_layout
.frame_size
+= STACK_POINTER_OFFSET
- lowest_offset
;
9730 /* If under 31 bit an odd number of gprs has to be saved we have to
9731 adjust the frame size to sustain 8 byte alignment of stack
9733 cfun_frame_layout
.frame_size
= ((cfun_frame_layout
.frame_size
+
9734 STACK_BOUNDARY
/ BITS_PER_UNIT
- 1)
9735 & ~(STACK_BOUNDARY
/ BITS_PER_UNIT
- 1));
9738 /* Generate frame layout. Fills in register and frame data for the current
9739 function in cfun->machine. This routine can be called multiple times;
9740 it will re-do the complete frame layout every time. */
9743 s390_init_frame_layout (void)
9745 HOST_WIDE_INT frame_size
;
9748 /* After LRA the frame layout is supposed to be read-only and should
9749 not be re-computed. */
9750 if (reload_completed
)
9753 /* On S/390 machines, we may need to perform branch splitting, which
9754 will require both base and return address register. We have no
9755 choice but to assume we're going to need them until right at the
9756 end of the machine dependent reorg phase. */
9757 if (!TARGET_CPU_ZARCH
)
9758 cfun
->machine
->split_branches_pending_p
= true;
9762 frame_size
= cfun_frame_layout
.frame_size
;
9764 /* Try to predict whether we'll need the base register. */
9765 base_used
= cfun
->machine
->split_branches_pending_p
9766 || crtl
->uses_const_pool
9767 || (!DISP_IN_RANGE (frame_size
)
9768 && !CONST_OK_FOR_K (frame_size
));
9770 /* Decide which register to use as literal pool base. In small
9771 leaf functions, try to use an unused call-clobbered register
9772 as base register to avoid save/restore overhead. */
9774 cfun
->machine
->base_reg
= NULL_RTX
;
9780 /* Prefer r5 (most likely to be free). */
9781 for (br
= 5; br
>= 2 && df_regs_ever_live_p (br
); br
--)
9783 cfun
->machine
->base_reg
=
9784 gen_rtx_REG (Pmode
, (br
>= 2) ? br
: BASE_REGNUM
);
9787 s390_register_info ();
9790 while (frame_size
!= cfun_frame_layout
.frame_size
);
9793 /* Remove the FPR clobbers from a tbegin insn if it can be proven that
9794 the TX is nonescaping. A transaction is considered escaping if
9795 there is at least one path from tbegin returning CC0 to the
9796 function exit block without an tend.
9798 The check so far has some limitations:
9799 - only single tbegin/tend BBs are supported
9800 - the first cond jump after tbegin must separate the CC0 path from ~CC0
9801 - when CC is copied to a GPR and the CC0 check is done with the GPR
9802 this is not supported
9806 s390_optimize_nonescaping_tx (void)
9808 const unsigned int CC0
= 1 << 3;
9809 basic_block tbegin_bb
= NULL
;
9810 basic_block tend_bb
= NULL
;
9815 rtx_insn
*tbegin_insn
= NULL
;
9817 if (!cfun
->machine
->tbegin_p
)
9820 for (bb_index
= 0; bb_index
< n_basic_blocks_for_fn (cfun
); bb_index
++)
9822 bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
9827 FOR_BB_INSNS (bb
, insn
)
9829 rtx ite
, cc
, pat
, target
;
9830 unsigned HOST_WIDE_INT mask
;
9832 if (!INSN_P (insn
) || INSN_CODE (insn
) <= 0)
9835 pat
= PATTERN (insn
);
9837 if (GET_CODE (pat
) == PARALLEL
)
9838 pat
= XVECEXP (pat
, 0, 0);
9840 if (GET_CODE (pat
) != SET
9841 || GET_CODE (SET_SRC (pat
)) != UNSPEC_VOLATILE
)
9844 if (XINT (SET_SRC (pat
), 1) == UNSPECV_TBEGIN
)
9850 /* Just return if the tbegin doesn't have clobbers. */
9851 if (GET_CODE (PATTERN (insn
)) != PARALLEL
)
9854 if (tbegin_bb
!= NULL
)
9857 /* Find the next conditional jump. */
9858 for (tmp
= NEXT_INSN (insn
);
9860 tmp
= NEXT_INSN (tmp
))
9862 if (reg_set_p (gen_rtx_REG (CCmode
, CC_REGNUM
), tmp
))
9867 ite
= SET_SRC (PATTERN (tmp
));
9868 if (GET_CODE (ite
) != IF_THEN_ELSE
)
9871 cc
= XEXP (XEXP (ite
, 0), 0);
9872 if (!REG_P (cc
) || !CC_REGNO_P (REGNO (cc
))
9873 || GET_MODE (cc
) != CCRAWmode
9874 || GET_CODE (XEXP (XEXP (ite
, 0), 1)) != CONST_INT
)
9877 if (bb
->succs
->length () != 2)
9880 mask
= INTVAL (XEXP (XEXP (ite
, 0), 1));
9881 if (GET_CODE (XEXP (ite
, 0)) == NE
)
9885 target
= XEXP (ite
, 1);
9886 else if (mask
== (CC0
^ 0xf))
9887 target
= XEXP (ite
, 2);
9895 ei
= ei_start (bb
->succs
);
9896 e1
= ei_safe_edge (ei
);
9898 e2
= ei_safe_edge (ei
);
9900 if (e2
->flags
& EDGE_FALLTHRU
)
9903 e1
= ei_safe_edge (ei
);
9906 if (!(e1
->flags
& EDGE_FALLTHRU
))
9909 tbegin_bb
= (target
== pc_rtx
) ? e1
->dest
: e2
->dest
;
9911 if (tmp
== BB_END (bb
))
9916 if (XINT (SET_SRC (pat
), 1) == UNSPECV_TEND
)
9918 if (tend_bb
!= NULL
)
9925 /* Either we successfully remove the FPR clobbers here or we are not
9926 able to do anything for this TX. Both cases don't qualify for
9928 cfun
->machine
->tbegin_p
= false;
9930 if (tbegin_bb
== NULL
|| tend_bb
== NULL
)
9933 calculate_dominance_info (CDI_POST_DOMINATORS
);
9934 result
= dominated_by_p (CDI_POST_DOMINATORS
, tbegin_bb
, tend_bb
);
9935 free_dominance_info (CDI_POST_DOMINATORS
);
9940 PATTERN (tbegin_insn
) = gen_rtx_PARALLEL (VOIDmode
,
9942 XVECEXP (PATTERN (tbegin_insn
), 0, 0),
9943 XVECEXP (PATTERN (tbegin_insn
), 0, 1)));
9944 INSN_CODE (tbegin_insn
) = -1;
9945 df_insn_rescan (tbegin_insn
);
9950 /* Return true if it is legal to put a value with MODE into REGNO. */
9953 s390_hard_regno_mode_ok (unsigned int regno
, machine_mode mode
)
9955 if (!TARGET_VX
&& VECTOR_NOFP_REGNO_P (regno
))
9958 switch (REGNO_REG_CLASS (regno
))
9961 return ((GET_MODE_CLASS (mode
) == MODE_INT
9962 && s390_class_max_nregs (VEC_REGS
, mode
) == 1)
9964 || s390_vector_mode_supported_p (mode
));
9968 && ((GET_MODE_CLASS (mode
) == MODE_INT
9969 && s390_class_max_nregs (FP_REGS
, mode
) == 1)
9971 || s390_vector_mode_supported_p (mode
)))
9974 if (REGNO_PAIR_OK (regno
, mode
))
9976 if (mode
== SImode
|| mode
== DImode
)
9979 if (FLOAT_MODE_P (mode
) && GET_MODE_CLASS (mode
) != MODE_VECTOR_FLOAT
)
9984 if (FRAME_REGNO_P (regno
) && mode
== Pmode
)
9989 if (REGNO_PAIR_OK (regno
, mode
))
9992 || (mode
!= TFmode
&& mode
!= TCmode
&& mode
!= TDmode
))
9997 if (GET_MODE_CLASS (mode
) == MODE_CC
)
10001 if (REGNO_PAIR_OK (regno
, mode
))
10003 if (mode
== SImode
|| mode
== Pmode
)
10014 /* Return nonzero if register OLD_REG can be renamed to register NEW_REG. */
10017 s390_hard_regno_rename_ok (unsigned int old_reg
, unsigned int new_reg
)
10019 /* Once we've decided upon a register to use as base register, it must
10020 no longer be used for any other purpose. */
10021 if (cfun
->machine
->base_reg
)
10022 if (REGNO (cfun
->machine
->base_reg
) == old_reg
10023 || REGNO (cfun
->machine
->base_reg
) == new_reg
)
10026 /* Prevent regrename from using call-saved regs which haven't
10027 actually been saved. This is necessary since regrename assumes
10028 the backend save/restore decisions are based on
10029 df_regs_ever_live. Since we have our own routine we have to tell
10030 regrename manually about it. */
10031 if (GENERAL_REGNO_P (new_reg
)
10032 && !call_really_used_regs
[new_reg
]
10033 && cfun_gpr_save_slot (new_reg
) == SAVE_SLOT_NONE
)
10039 /* Return nonzero if register REGNO can be used as a scratch register
10043 s390_hard_regno_scratch_ok (unsigned int regno
)
10045 /* See s390_hard_regno_rename_ok. */
10046 if (GENERAL_REGNO_P (regno
)
10047 && !call_really_used_regs
[regno
]
10048 && cfun_gpr_save_slot (regno
) == SAVE_SLOT_NONE
)
10054 /* Maximum number of registers to represent a value of mode MODE
10055 in a register of class RCLASS. */
10058 s390_class_max_nregs (enum reg_class rclass
, machine_mode mode
)
10061 bool reg_pair_required_p
= false;
10067 reg_size
= TARGET_VX
? 16 : 8;
10069 /* TF and TD modes would fit into a VR but we put them into a
10070 register pair since we do not have 128bit FP instructions on
10073 && SCALAR_FLOAT_MODE_P (mode
)
10074 && GET_MODE_SIZE (mode
) >= 16)
10075 reg_pair_required_p
= true;
10077 /* Even if complex types would fit into a single FPR/VR we force
10078 them into a register pair to deal with the parts more easily.
10079 (FIXME: What about complex ints?) */
10080 if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
)
10081 reg_pair_required_p
= true;
10087 reg_size
= UNITS_PER_WORD
;
10091 if (reg_pair_required_p
)
10092 return 2 * ((GET_MODE_SIZE (mode
) / 2 + reg_size
- 1) / reg_size
);
10094 return (GET_MODE_SIZE (mode
) + reg_size
- 1) / reg_size
;
10097 /* Return TRUE if changing mode from FROM to TO should not be allowed
10098 for register class CLASS. */
10101 s390_cannot_change_mode_class (machine_mode from_mode
,
10102 machine_mode to_mode
,
10103 enum reg_class rclass
)
10105 machine_mode small_mode
;
10106 machine_mode big_mode
;
10108 if (GET_MODE_SIZE (from_mode
) == GET_MODE_SIZE (to_mode
))
10111 if (GET_MODE_SIZE (from_mode
) < GET_MODE_SIZE (to_mode
))
10113 small_mode
= from_mode
;
10114 big_mode
= to_mode
;
10118 small_mode
= to_mode
;
10119 big_mode
= from_mode
;
10122 /* Values residing in VRs are little-endian style. All modes are
10123 placed left-aligned in an VR. This means that we cannot allow
10124 switching between modes with differing sizes. Also if the vector
10125 facility is available we still place TFmode values in VR register
10126 pairs, since the only instructions we have operating on TFmodes
10127 only deal with register pairs. Therefore we have to allow DFmode
10128 subregs of TFmodes to enable the TFmode splitters. */
10129 if (reg_classes_intersect_p (VEC_REGS
, rclass
)
10130 && (GET_MODE_SIZE (small_mode
) < 8
10131 || s390_class_max_nregs (VEC_REGS
, big_mode
) == 1))
10134 /* Likewise for access registers, since they have only half the
10135 word size on 64-bit. */
10136 if (reg_classes_intersect_p (ACCESS_REGS
, rclass
))
10142 /* Return true if we use LRA instead of reload pass. */
10146 return s390_lra_flag
;
10149 /* Return true if register FROM can be eliminated via register TO. */
10152 s390_can_eliminate (const int from
, const int to
)
10154 /* On zSeries machines, we have not marked the base register as fixed.
10155 Instead, we have an elimination rule BASE_REGNUM -> BASE_REGNUM.
10156 If a function requires the base register, we say here that this
10157 elimination cannot be performed. This will cause reload to free
10158 up the base register (as if it were fixed). On the other hand,
10159 if the current function does *not* require the base register, we
10160 say here the elimination succeeds, which in turn allows reload
10161 to allocate the base register for any other purpose. */
10162 if (from
== BASE_REGNUM
&& to
== BASE_REGNUM
)
10164 if (TARGET_CPU_ZARCH
)
10166 s390_init_frame_layout ();
10167 return cfun
->machine
->base_reg
== NULL_RTX
;
10173 /* Everything else must point into the stack frame. */
10174 gcc_assert (to
== STACK_POINTER_REGNUM
10175 || to
== HARD_FRAME_POINTER_REGNUM
);
10177 gcc_assert (from
== FRAME_POINTER_REGNUM
10178 || from
== ARG_POINTER_REGNUM
10179 || from
== RETURN_ADDRESS_POINTER_REGNUM
);
10181 /* Make sure we actually saved the return address. */
10182 if (from
== RETURN_ADDRESS_POINTER_REGNUM
)
10183 if (!crtl
->calls_eh_return
10185 && !cfun_frame_layout
.save_return_addr_p
)
10191 /* Return offset between register FROM and TO initially after prolog. */
10194 s390_initial_elimination_offset (int from
, int to
)
10196 HOST_WIDE_INT offset
;
10198 /* ??? Why are we called for non-eliminable pairs? */
10199 if (!s390_can_eliminate (from
, to
))
10204 case FRAME_POINTER_REGNUM
:
10205 offset
= (get_frame_size()
10206 + STACK_POINTER_OFFSET
10207 + crtl
->outgoing_args_size
);
10210 case ARG_POINTER_REGNUM
:
10211 s390_init_frame_layout ();
10212 offset
= cfun_frame_layout
.frame_size
+ STACK_POINTER_OFFSET
;
10215 case RETURN_ADDRESS_POINTER_REGNUM
:
10216 s390_init_frame_layout ();
10218 if (cfun_frame_layout
.first_save_gpr_slot
== -1)
10220 /* If it turns out that for stdarg nothing went into the reg
10221 save area we also do not need the return address
10223 if (cfun
->stdarg
&& !cfun_save_arg_fprs_p
)
10226 gcc_unreachable ();
10229 /* In order to make the following work it is not necessary for
10230 r14 to have a save slot. It is sufficient if one other GPR
10231 got one. Since the GPRs are always stored without gaps we
10232 are able to calculate where the r14 save slot would
10234 offset
= (cfun_frame_layout
.frame_size
+ cfun_frame_layout
.gprs_offset
+
10235 (RETURN_REGNUM
- cfun_frame_layout
.first_save_gpr_slot
) *
10244 gcc_unreachable ();
10250 /* Emit insn to save fpr REGNUM at offset OFFSET relative
10251 to register BASE. Return generated insn. */
10254 save_fpr (rtx base
, int offset
, int regnum
)
10257 addr
= gen_rtx_MEM (DFmode
, plus_constant (Pmode
, base
, offset
));
10259 if (regnum
>= 16 && regnum
<= (16 + FP_ARG_NUM_REG
))
10260 set_mem_alias_set (addr
, get_varargs_alias_set ());
10262 set_mem_alias_set (addr
, get_frame_alias_set ());
10264 return emit_move_insn (addr
, gen_rtx_REG (DFmode
, regnum
));
10267 /* Emit insn to restore fpr REGNUM from offset OFFSET relative
10268 to register BASE. Return generated insn. */
10271 restore_fpr (rtx base
, int offset
, int regnum
)
10274 addr
= gen_rtx_MEM (DFmode
, plus_constant (Pmode
, base
, offset
));
10275 set_mem_alias_set (addr
, get_frame_alias_set ());
10277 return emit_move_insn (gen_rtx_REG (DFmode
, regnum
), addr
);
10280 /* Return true if REGNO is a global register, but not one
10281 of the special ones that need to be saved/restored in anyway. */
10284 global_not_special_regno_p (int regno
)
10286 return (global_regs
[regno
]
10287 /* These registers are special and need to be
10288 restored in any case. */
10289 && !(regno
== STACK_POINTER_REGNUM
10290 || regno
== RETURN_REGNUM
10291 || regno
== BASE_REGNUM
10292 || (flag_pic
&& regno
== (int)PIC_OFFSET_TABLE_REGNUM
)));
10295 /* Generate insn to save registers FIRST to LAST into
10296 the register save area located at offset OFFSET
10297 relative to register BASE. */
10300 save_gprs (rtx base
, int offset
, int first
, int last
)
10302 rtx addr
, insn
, note
;
10305 addr
= plus_constant (Pmode
, base
, offset
);
10306 addr
= gen_rtx_MEM (Pmode
, addr
);
10308 set_mem_alias_set (addr
, get_frame_alias_set ());
10310 /* Special-case single register. */
10314 insn
= gen_movdi (addr
, gen_rtx_REG (Pmode
, first
));
10316 insn
= gen_movsi (addr
, gen_rtx_REG (Pmode
, first
));
10318 if (!global_not_special_regno_p (first
))
10319 RTX_FRAME_RELATED_P (insn
) = 1;
10324 insn
= gen_store_multiple (addr
,
10325 gen_rtx_REG (Pmode
, first
),
10326 GEN_INT (last
- first
+ 1));
10328 if (first
<= 6 && cfun
->stdarg
)
10329 for (i
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
10331 rtx mem
= XEXP (XVECEXP (PATTERN (insn
), 0, i
), 0);
10333 if (first
+ i
<= 6)
10334 set_mem_alias_set (mem
, get_varargs_alias_set ());
10337 /* We need to set the FRAME_RELATED flag on all SETs
10338 inside the store-multiple pattern.
10340 However, we must not emit DWARF records for registers 2..5
10341 if they are stored for use by variable arguments ...
10343 ??? Unfortunately, it is not enough to simply not the
10344 FRAME_RELATED flags for those SETs, because the first SET
10345 of the PARALLEL is always treated as if it had the flag
10346 set, even if it does not. Therefore we emit a new pattern
10347 without those registers as REG_FRAME_RELATED_EXPR note. */
10349 if (first
>= 6 && !global_not_special_regno_p (first
))
10351 rtx pat
= PATTERN (insn
);
10353 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
10354 if (GET_CODE (XVECEXP (pat
, 0, i
)) == SET
10355 && !global_not_special_regno_p (REGNO (SET_SRC (XVECEXP (pat
,
10357 RTX_FRAME_RELATED_P (XVECEXP (pat
, 0, i
)) = 1;
10359 RTX_FRAME_RELATED_P (insn
) = 1;
10361 else if (last
>= 6)
10365 for (start
= first
>= 6 ? first
: 6; start
<= last
; start
++)
10366 if (!global_not_special_regno_p (start
))
10372 addr
= plus_constant (Pmode
, base
,
10373 offset
+ (start
- first
) * UNITS_PER_LONG
);
10378 note
= gen_movdi (gen_rtx_MEM (Pmode
, addr
),
10379 gen_rtx_REG (Pmode
, start
));
10381 note
= gen_movsi (gen_rtx_MEM (Pmode
, addr
),
10382 gen_rtx_REG (Pmode
, start
));
10383 note
= PATTERN (note
);
10385 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
, note
);
10386 RTX_FRAME_RELATED_P (insn
) = 1;
10391 note
= gen_store_multiple (gen_rtx_MEM (Pmode
, addr
),
10392 gen_rtx_REG (Pmode
, start
),
10393 GEN_INT (last
- start
+ 1));
10394 note
= PATTERN (note
);
10396 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
, note
);
10398 for (i
= 0; i
< XVECLEN (note
, 0); i
++)
10399 if (GET_CODE (XVECEXP (note
, 0, i
)) == SET
10400 && !global_not_special_regno_p (REGNO (SET_SRC (XVECEXP (note
,
10402 RTX_FRAME_RELATED_P (XVECEXP (note
, 0, i
)) = 1;
10404 RTX_FRAME_RELATED_P (insn
) = 1;
10410 /* Generate insn to restore registers FIRST to LAST from
10411 the register save area located at offset OFFSET
10412 relative to register BASE. */
10415 restore_gprs (rtx base
, int offset
, int first
, int last
)
10419 addr
= plus_constant (Pmode
, base
, offset
);
10420 addr
= gen_rtx_MEM (Pmode
, addr
);
10421 set_mem_alias_set (addr
, get_frame_alias_set ());
10423 /* Special-case single register. */
10427 insn
= gen_movdi (gen_rtx_REG (Pmode
, first
), addr
);
10429 insn
= gen_movsi (gen_rtx_REG (Pmode
, first
), addr
);
10431 RTX_FRAME_RELATED_P (insn
) = 1;
10435 insn
= gen_load_multiple (gen_rtx_REG (Pmode
, first
),
10437 GEN_INT (last
- first
+ 1));
10438 RTX_FRAME_RELATED_P (insn
) = 1;
10442 /* Return insn sequence to load the GOT register. */
10444 static GTY(()) rtx got_symbol
;
10446 s390_load_got (void)
10450 /* We cannot use pic_offset_table_rtx here since we use this
10451 function also for non-pic if __tls_get_offset is called and in
10452 that case PIC_OFFSET_TABLE_REGNUM as well as pic_offset_table_rtx
10454 rtx got_rtx
= gen_rtx_REG (Pmode
, 12);
10458 got_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "_GLOBAL_OFFSET_TABLE_");
10459 SYMBOL_REF_FLAGS (got_symbol
) = SYMBOL_FLAG_LOCAL
;
10464 if (TARGET_CPU_ZARCH
)
10466 emit_move_insn (got_rtx
, got_symbol
);
10472 offset
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, got_symbol
),
10473 UNSPEC_LTREL_OFFSET
);
10474 offset
= gen_rtx_CONST (Pmode
, offset
);
10475 offset
= force_const_mem (Pmode
, offset
);
10477 emit_move_insn (got_rtx
, offset
);
10479 offset
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, XEXP (offset
, 0)),
10480 UNSPEC_LTREL_BASE
);
10481 offset
= gen_rtx_PLUS (Pmode
, got_rtx
, offset
);
10483 emit_move_insn (got_rtx
, offset
);
10486 insns
= get_insns ();
10491 /* This ties together stack memory (MEM with an alias set of frame_alias_set)
10492 and the change to the stack pointer. */
10495 s390_emit_stack_tie (void)
10497 rtx mem
= gen_frame_mem (BLKmode
,
10498 gen_rtx_REG (Pmode
, STACK_POINTER_REGNUM
));
10500 emit_insn (gen_stack_tie (mem
));
10503 /* Copy GPRS into FPR save slots. */
10506 s390_save_gprs_to_fprs (void)
10510 if (!TARGET_Z10
|| !TARGET_HARD_FLOAT
|| !crtl
->is_leaf
)
10513 for (i
= 6; i
< 16; i
++)
10515 if (FP_REGNO_P (cfun_gpr_save_slot (i
)))
10518 emit_move_insn (gen_rtx_REG (DImode
, cfun_gpr_save_slot (i
)),
10519 gen_rtx_REG (DImode
, i
));
10520 RTX_FRAME_RELATED_P (insn
) = 1;
10521 /* This prevents dwarf2cfi from interpreting the set. Doing
10522 so it might emit def_cfa_register infos setting an FPR as
10524 add_reg_note (insn
, REG_CFA_REGISTER
, PATTERN (insn
));
10529 /* Restore GPRs from FPR save slots. */
10532 s390_restore_gprs_from_fprs (void)
10536 if (!TARGET_Z10
|| !TARGET_HARD_FLOAT
|| !crtl
->is_leaf
)
10539 for (i
= 6; i
< 16; i
++)
10541 if (FP_REGNO_P (cfun_gpr_save_slot (i
)))
10544 emit_move_insn (gen_rtx_REG (DImode
, i
),
10545 gen_rtx_REG (DImode
, cfun_gpr_save_slot (i
)));
10546 df_set_regs_ever_live (i
, true);
10547 add_reg_note (insn
, REG_CFA_RESTORE
, gen_rtx_REG (DImode
, i
));
10548 if (i
== STACK_POINTER_REGNUM
)
10549 add_reg_note (insn
, REG_CFA_DEF_CFA
,
10550 plus_constant (Pmode
, stack_pointer_rtx
,
10551 STACK_POINTER_OFFSET
));
10552 RTX_FRAME_RELATED_P (insn
) = 1;
10558 /* A pass run immediately before shrink-wrapping and prologue and epilogue
10563 const pass_data pass_data_s390_early_mach
=
10565 RTL_PASS
, /* type */
10566 "early_mach", /* name */
10567 OPTGROUP_NONE
, /* optinfo_flags */
10568 TV_MACH_DEP
, /* tv_id */
10569 0, /* properties_required */
10570 0, /* properties_provided */
10571 0, /* properties_destroyed */
10572 0, /* todo_flags_start */
10573 ( TODO_df_verify
| TODO_df_finish
), /* todo_flags_finish */
10576 class pass_s390_early_mach
: public rtl_opt_pass
10579 pass_s390_early_mach (gcc::context
*ctxt
)
10580 : rtl_opt_pass (pass_data_s390_early_mach
, ctxt
)
10583 /* opt_pass methods: */
10584 virtual unsigned int execute (function
*);
10586 }; // class pass_s390_early_mach
10589 pass_s390_early_mach::execute (function
*fun
)
10593 /* Try to get rid of the FPR clobbers. */
10594 s390_optimize_nonescaping_tx ();
10596 /* Re-compute register info. */
10597 s390_register_info ();
10599 /* If we're using a base register, ensure that it is always valid for
10600 the first non-prologue instruction. */
10601 if (fun
->machine
->base_reg
)
10602 emit_insn_at_entry (gen_main_pool (fun
->machine
->base_reg
));
10604 /* Annotate all constant pool references to let the scheduler know
10605 they implicitly use the base register. */
10606 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
10609 annotate_constant_pool_refs (&PATTERN (insn
));
10610 df_insn_rescan (insn
);
10615 } // anon namespace
10617 /* Expand the prologue into a bunch of separate insns. */
10620 s390_emit_prologue (void)
10628 /* Choose best register to use for temp use within prologue.
10629 TPF with profiling must avoid the register 14 - the tracing function
10630 needs the original contents of r14 to be preserved. */
10632 if (!has_hard_reg_initial_val (Pmode
, RETURN_REGNUM
)
10634 && !TARGET_TPF_PROFILING
)
10635 temp_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
10636 else if (flag_split_stack
&& cfun
->stdarg
)
10637 temp_reg
= gen_rtx_REG (Pmode
, 12);
10639 temp_reg
= gen_rtx_REG (Pmode
, 1);
10641 s390_save_gprs_to_fprs ();
10643 /* Save call saved gprs. */
10644 if (cfun_frame_layout
.first_save_gpr
!= -1)
10646 insn
= save_gprs (stack_pointer_rtx
,
10647 cfun_frame_layout
.gprs_offset
+
10648 UNITS_PER_LONG
* (cfun_frame_layout
.first_save_gpr
10649 - cfun_frame_layout
.first_save_gpr_slot
),
10650 cfun_frame_layout
.first_save_gpr
,
10651 cfun_frame_layout
.last_save_gpr
);
10655 /* Dummy insn to mark literal pool slot. */
10657 if (cfun
->machine
->base_reg
)
10658 emit_insn (gen_main_pool (cfun
->machine
->base_reg
));
10660 offset
= cfun_frame_layout
.f0_offset
;
10662 /* Save f0 and f2. */
10663 for (i
= FPR0_REGNUM
; i
<= FPR0_REGNUM
+ 1; i
++)
10665 if (cfun_fpr_save_p (i
))
10667 save_fpr (stack_pointer_rtx
, offset
, i
);
10670 else if (!TARGET_PACKED_STACK
|| cfun
->stdarg
)
10674 /* Save f4 and f6. */
10675 offset
= cfun_frame_layout
.f4_offset
;
10676 for (i
= FPR4_REGNUM
; i
<= FPR4_REGNUM
+ 1; i
++)
10678 if (cfun_fpr_save_p (i
))
10680 insn
= save_fpr (stack_pointer_rtx
, offset
, i
);
10683 /* If f4 and f6 are call clobbered they are saved due to
10684 stdargs and therefore are not frame related. */
10685 if (!call_really_used_regs
[i
])
10686 RTX_FRAME_RELATED_P (insn
) = 1;
10688 else if (!TARGET_PACKED_STACK
|| call_really_used_regs
[i
])
10692 if (TARGET_PACKED_STACK
10693 && cfun_save_high_fprs_p
10694 && cfun_frame_layout
.f8_offset
+ cfun_frame_layout
.high_fprs
* 8 > 0)
10696 offset
= (cfun_frame_layout
.f8_offset
10697 + (cfun_frame_layout
.high_fprs
- 1) * 8);
10699 for (i
= FPR15_REGNUM
; i
>= FPR8_REGNUM
&& offset
>= 0; i
--)
10700 if (cfun_fpr_save_p (i
))
10702 insn
= save_fpr (stack_pointer_rtx
, offset
, i
);
10704 RTX_FRAME_RELATED_P (insn
) = 1;
10707 if (offset
>= cfun_frame_layout
.f8_offset
)
10711 if (!TARGET_PACKED_STACK
)
10712 next_fpr
= cfun_save_high_fprs_p
? FPR15_REGNUM
: 0;
10714 if (flag_stack_usage_info
)
10715 current_function_static_stack_size
= cfun_frame_layout
.frame_size
;
10717 /* Decrement stack pointer. */
10719 if (cfun_frame_layout
.frame_size
> 0)
10721 rtx frame_off
= GEN_INT (-cfun_frame_layout
.frame_size
);
10722 rtx real_frame_off
;
10724 if (s390_stack_size
)
10726 HOST_WIDE_INT stack_guard
;
10728 if (s390_stack_guard
)
10729 stack_guard
= s390_stack_guard
;
10732 /* If no value for stack guard is provided the smallest power of 2
10733 larger than the current frame size is chosen. */
10735 while (stack_guard
< cfun_frame_layout
.frame_size
)
10739 if (cfun_frame_layout
.frame_size
>= s390_stack_size
)
10741 warning (0, "frame size of function %qs is %wd"
10742 " bytes exceeding user provided stack limit of "
10744 "An unconditional trap is added.",
10745 current_function_name(), cfun_frame_layout
.frame_size
,
10747 emit_insn (gen_trap ());
10752 /* stack_guard has to be smaller than s390_stack_size.
10753 Otherwise we would emit an AND with zero which would
10754 not match the test under mask pattern. */
10755 if (stack_guard
>= s390_stack_size
)
10757 warning (0, "frame size of function %qs is %wd"
10758 " bytes which is more than half the stack size. "
10759 "The dynamic check would not be reliable. "
10760 "No check emitted for this function.",
10761 current_function_name(),
10762 cfun_frame_layout
.frame_size
);
10766 HOST_WIDE_INT stack_check_mask
= ((s390_stack_size
- 1)
10767 & ~(stack_guard
- 1));
10769 rtx t
= gen_rtx_AND (Pmode
, stack_pointer_rtx
,
10770 GEN_INT (stack_check_mask
));
10772 emit_insn (gen_ctrapdi4 (gen_rtx_EQ (VOIDmode
,
10774 t
, const0_rtx
, const0_rtx
));
10776 emit_insn (gen_ctrapsi4 (gen_rtx_EQ (VOIDmode
,
10778 t
, const0_rtx
, const0_rtx
));
10783 if (s390_warn_framesize
> 0
10784 && cfun_frame_layout
.frame_size
>= s390_warn_framesize
)
10785 warning (0, "frame size of %qs is %wd bytes",
10786 current_function_name (), cfun_frame_layout
.frame_size
);
10788 if (s390_warn_dynamicstack_p
&& cfun
->calls_alloca
)
10789 warning (0, "%qs uses dynamic stack allocation", current_function_name ());
10791 /* Save incoming stack pointer into temp reg. */
10792 if (TARGET_BACKCHAIN
|| next_fpr
)
10793 insn
= emit_insn (gen_move_insn (temp_reg
, stack_pointer_rtx
));
10795 /* Subtract frame size from stack pointer. */
10797 if (DISP_IN_RANGE (INTVAL (frame_off
)))
10799 insn
= gen_rtx_SET (stack_pointer_rtx
,
10800 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
10802 insn
= emit_insn (insn
);
10806 if (!CONST_OK_FOR_K (INTVAL (frame_off
)))
10807 frame_off
= force_const_mem (Pmode
, frame_off
);
10809 insn
= emit_insn (gen_add2_insn (stack_pointer_rtx
, frame_off
));
10810 annotate_constant_pool_refs (&PATTERN (insn
));
10813 RTX_FRAME_RELATED_P (insn
) = 1;
10814 real_frame_off
= GEN_INT (-cfun_frame_layout
.frame_size
);
10815 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
,
10816 gen_rtx_SET (stack_pointer_rtx
,
10817 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
10820 /* Set backchain. */
10822 if (TARGET_BACKCHAIN
)
10824 if (cfun_frame_layout
.backchain_offset
)
10825 addr
= gen_rtx_MEM (Pmode
,
10826 plus_constant (Pmode
, stack_pointer_rtx
,
10827 cfun_frame_layout
.backchain_offset
));
10829 addr
= gen_rtx_MEM (Pmode
, stack_pointer_rtx
);
10830 set_mem_alias_set (addr
, get_frame_alias_set ());
10831 insn
= emit_insn (gen_move_insn (addr
, temp_reg
));
10834 /* If we support non-call exceptions (e.g. for Java),
10835 we need to make sure the backchain pointer is set up
10836 before any possibly trapping memory access. */
10837 if (TARGET_BACKCHAIN
&& cfun
->can_throw_non_call_exceptions
)
10839 addr
= gen_rtx_MEM (BLKmode
, gen_rtx_SCRATCH (VOIDmode
));
10840 emit_clobber (addr
);
10844 /* Save fprs 8 - 15 (64 bit ABI). */
10846 if (cfun_save_high_fprs_p
&& next_fpr
)
10848 /* If the stack might be accessed through a different register
10849 we have to make sure that the stack pointer decrement is not
10850 moved below the use of the stack slots. */
10851 s390_emit_stack_tie ();
10853 insn
= emit_insn (gen_add2_insn (temp_reg
,
10854 GEN_INT (cfun_frame_layout
.f8_offset
)));
10858 for (i
= FPR8_REGNUM
; i
<= next_fpr
; i
++)
10859 if (cfun_fpr_save_p (i
))
10861 rtx addr
= plus_constant (Pmode
, stack_pointer_rtx
,
10862 cfun_frame_layout
.frame_size
10863 + cfun_frame_layout
.f8_offset
10866 insn
= save_fpr (temp_reg
, offset
, i
);
10868 RTX_FRAME_RELATED_P (insn
) = 1;
10869 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
,
10870 gen_rtx_SET (gen_rtx_MEM (DFmode
, addr
),
10871 gen_rtx_REG (DFmode
, i
)));
10875 /* Set frame pointer, if needed. */
10877 if (frame_pointer_needed
)
10879 insn
= emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
);
10880 RTX_FRAME_RELATED_P (insn
) = 1;
10883 /* Set up got pointer, if needed. */
10885 if (flag_pic
&& df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM
))
10887 rtx_insn
*insns
= s390_load_got ();
10889 for (rtx_insn
*insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
10890 annotate_constant_pool_refs (&PATTERN (insn
));
10895 if (TARGET_TPF_PROFILING
)
10897 /* Generate a BAS instruction to serve as a function
10898 entry intercept to facilitate the use of tracing
10899 algorithms located at the branch target. */
10900 emit_insn (gen_prologue_tpf ());
10902 /* Emit a blockage here so that all code
10903 lies between the profiling mechanisms. */
10904 emit_insn (gen_blockage ());
10908 /* Expand the epilogue into a bunch of separate insns. */
10911 s390_emit_epilogue (bool sibcall
)
10913 rtx frame_pointer
, return_reg
, cfa_restores
= NULL_RTX
;
10914 int area_bottom
, area_top
, offset
= 0;
10919 if (TARGET_TPF_PROFILING
)
10922 /* Generate a BAS instruction to serve as a function
10923 entry intercept to facilitate the use of tracing
10924 algorithms located at the branch target. */
10926 /* Emit a blockage here so that all code
10927 lies between the profiling mechanisms. */
10928 emit_insn (gen_blockage ());
10930 emit_insn (gen_epilogue_tpf ());
10933 /* Check whether to use frame or stack pointer for restore. */
10935 frame_pointer
= (frame_pointer_needed
10936 ? hard_frame_pointer_rtx
: stack_pointer_rtx
);
10938 s390_frame_area (&area_bottom
, &area_top
);
10940 /* Check whether we can access the register save area.
10941 If not, increment the frame pointer as required. */
10943 if (area_top
<= area_bottom
)
10945 /* Nothing to restore. */
10947 else if (DISP_IN_RANGE (cfun_frame_layout
.frame_size
+ area_bottom
)
10948 && DISP_IN_RANGE (cfun_frame_layout
.frame_size
+ area_top
- 1))
10950 /* Area is in range. */
10951 offset
= cfun_frame_layout
.frame_size
;
10955 rtx insn
, frame_off
, cfa
;
10957 offset
= area_bottom
< 0 ? -area_bottom
: 0;
10958 frame_off
= GEN_INT (cfun_frame_layout
.frame_size
- offset
);
10960 cfa
= gen_rtx_SET (frame_pointer
,
10961 gen_rtx_PLUS (Pmode
, frame_pointer
, frame_off
));
10962 if (DISP_IN_RANGE (INTVAL (frame_off
)))
10964 insn
= gen_rtx_SET (frame_pointer
,
10965 gen_rtx_PLUS (Pmode
, frame_pointer
, frame_off
));
10966 insn
= emit_insn (insn
);
10970 if (!CONST_OK_FOR_K (INTVAL (frame_off
)))
10971 frame_off
= force_const_mem (Pmode
, frame_off
);
10973 insn
= emit_insn (gen_add2_insn (frame_pointer
, frame_off
));
10974 annotate_constant_pool_refs (&PATTERN (insn
));
10976 add_reg_note (insn
, REG_CFA_ADJUST_CFA
, cfa
);
10977 RTX_FRAME_RELATED_P (insn
) = 1;
10980 /* Restore call saved fprs. */
10984 if (cfun_save_high_fprs_p
)
10986 next_offset
= cfun_frame_layout
.f8_offset
;
10987 for (i
= FPR8_REGNUM
; i
<= FPR15_REGNUM
; i
++)
10989 if (cfun_fpr_save_p (i
))
10991 restore_fpr (frame_pointer
,
10992 offset
+ next_offset
, i
);
10994 = alloc_reg_note (REG_CFA_RESTORE
,
10995 gen_rtx_REG (DFmode
, i
), cfa_restores
);
11004 next_offset
= cfun_frame_layout
.f4_offset
;
11006 for (i
= FPR4_REGNUM
; i
<= FPR4_REGNUM
+ 1; i
++)
11008 if (cfun_fpr_save_p (i
))
11010 restore_fpr (frame_pointer
,
11011 offset
+ next_offset
, i
);
11013 = alloc_reg_note (REG_CFA_RESTORE
,
11014 gen_rtx_REG (DFmode
, i
), cfa_restores
);
11017 else if (!TARGET_PACKED_STACK
)
11023 /* Return register. */
11025 return_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
11027 /* Restore call saved gprs. */
11029 if (cfun_frame_layout
.first_restore_gpr
!= -1)
11034 /* Check for global register and save them
11035 to stack location from where they get restored. */
11037 for (i
= cfun_frame_layout
.first_restore_gpr
;
11038 i
<= cfun_frame_layout
.last_restore_gpr
;
11041 if (global_not_special_regno_p (i
))
11043 addr
= plus_constant (Pmode
, frame_pointer
,
11044 offset
+ cfun_frame_layout
.gprs_offset
11045 + (i
- cfun_frame_layout
.first_save_gpr_slot
)
11047 addr
= gen_rtx_MEM (Pmode
, addr
);
11048 set_mem_alias_set (addr
, get_frame_alias_set ());
11049 emit_move_insn (addr
, gen_rtx_REG (Pmode
, i
));
11053 = alloc_reg_note (REG_CFA_RESTORE
,
11054 gen_rtx_REG (Pmode
, i
), cfa_restores
);
11059 /* Fetch return address from stack before load multiple,
11060 this will do good for scheduling.
11062 Only do this if we already decided that r14 needs to be
11063 saved to a stack slot. (And not just because r14 happens to
11064 be in between two GPRs which need saving.) Otherwise it
11065 would be difficult to take that decision back in
11066 s390_optimize_prologue. */
11067 if (cfun_gpr_save_slot (RETURN_REGNUM
) == SAVE_SLOT_STACK
)
11069 int return_regnum
= find_unused_clobbered_reg();
11070 if (!return_regnum
)
11072 return_reg
= gen_rtx_REG (Pmode
, return_regnum
);
11074 addr
= plus_constant (Pmode
, frame_pointer
,
11075 offset
+ cfun_frame_layout
.gprs_offset
11077 - cfun_frame_layout
.first_save_gpr_slot
)
11079 addr
= gen_rtx_MEM (Pmode
, addr
);
11080 set_mem_alias_set (addr
, get_frame_alias_set ());
11081 emit_move_insn (return_reg
, addr
);
11083 /* Once we did that optimization we have to make sure
11084 s390_optimize_prologue does not try to remove the
11085 store of r14 since we will not be able to find the
11086 load issued here. */
11087 cfun_frame_layout
.save_return_addr_p
= true;
11091 insn
= restore_gprs (frame_pointer
,
11092 offset
+ cfun_frame_layout
.gprs_offset
11093 + (cfun_frame_layout
.first_restore_gpr
11094 - cfun_frame_layout
.first_save_gpr_slot
)
11096 cfun_frame_layout
.first_restore_gpr
,
11097 cfun_frame_layout
.last_restore_gpr
);
11098 insn
= emit_insn (insn
);
11099 REG_NOTES (insn
) = cfa_restores
;
11100 add_reg_note (insn
, REG_CFA_DEF_CFA
,
11101 plus_constant (Pmode
, stack_pointer_rtx
,
11102 STACK_POINTER_OFFSET
));
11103 RTX_FRAME_RELATED_P (insn
) = 1;
11106 s390_restore_gprs_from_fprs ();
11111 /* Return to caller. */
11113 p
= rtvec_alloc (2);
11115 RTVEC_ELT (p
, 0) = ret_rtx
;
11116 RTVEC_ELT (p
, 1) = gen_rtx_USE (VOIDmode
, return_reg
);
11117 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
11121 /* Implement TARGET_SET_UP_BY_PROLOGUE. */
11124 s300_set_up_by_prologue (hard_reg_set_container
*regs
)
11126 if (cfun
->machine
->base_reg
11127 && !call_really_used_regs
[REGNO (cfun
->machine
->base_reg
)])
11128 SET_HARD_REG_BIT (regs
->set
, REGNO (cfun
->machine
->base_reg
));
11131 /* -fsplit-stack support. */
11133 /* A SYMBOL_REF for __morestack. */
11134 static GTY(()) rtx morestack_ref
;
11136 /* When using -fsplit-stack, the allocation routines set a field in
11137 the TCB to the bottom of the stack plus this much space, measured
11140 #define SPLIT_STACK_AVAILABLE 1024
11142 /* Emit -fsplit-stack prologue, which goes before the regular function
11146 s390_expand_split_stack_prologue (void)
11148 rtx r1
, guard
, cc
= NULL
;
11150 /* Offset from thread pointer to __private_ss. */
11151 int psso
= TARGET_64BIT
? 0x38 : 0x20;
11152 /* Pointer size in bytes. */
11153 /* Frame size and argument size - the two parameters to __morestack. */
11154 HOST_WIDE_INT frame_size
= cfun_frame_layout
.frame_size
;
11155 /* Align argument size to 8 bytes - simplifies __morestack code. */
11156 HOST_WIDE_INT args_size
= crtl
->args
.size
>= 0
11157 ? ((crtl
->args
.size
+ 7) & ~7)
11159 /* Label to be called by __morestack. */
11160 rtx_code_label
*call_done
= NULL
;
11161 rtx_code_label
*parm_base
= NULL
;
11164 gcc_assert (flag_split_stack
&& reload_completed
);
11165 if (!TARGET_CPU_ZARCH
)
11167 sorry ("CPUs older than z900 are not supported for -fsplit-stack");
11171 r1
= gen_rtx_REG (Pmode
, 1);
11173 /* If no stack frame will be allocated, don't do anything. */
11176 if (cfun
->machine
->split_stack_varargs_pointer
!= NULL_RTX
)
11178 /* If va_start is used, just use r15. */
11179 emit_move_insn (r1
,
11180 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
11181 GEN_INT (STACK_POINTER_OFFSET
)));
11187 if (morestack_ref
== NULL_RTX
)
11189 morestack_ref
= gen_rtx_SYMBOL_REF (Pmode
, "__morestack");
11190 SYMBOL_REF_FLAGS (morestack_ref
) |= (SYMBOL_FLAG_LOCAL
11191 | SYMBOL_FLAG_FUNCTION
);
11194 if (CONST_OK_FOR_K (frame_size
) || CONST_OK_FOR_Op (frame_size
))
11196 /* If frame_size will fit in an add instruction, do a stack space
11197 check, and only call __morestack if there's not enough space. */
11199 /* Get thread pointer. r1 is the only register we can always destroy - r0
11200 could contain a static chain (and cannot be used to address memory
11201 anyway), r2-r6 can contain parameters, and r6-r15 are callee-saved. */
11202 emit_move_insn (r1
, gen_rtx_REG (Pmode
, TP_REGNUM
));
11203 /* Aim at __private_ss. */
11204 guard
= gen_rtx_MEM (Pmode
, plus_constant (Pmode
, r1
, psso
));
11206 /* If less that 1kiB used, skip addition and compare directly with
11208 if (frame_size
> SPLIT_STACK_AVAILABLE
)
11210 emit_move_insn (r1
, guard
);
11212 emit_insn (gen_adddi3 (r1
, r1
, GEN_INT (frame_size
)));
11214 emit_insn (gen_addsi3 (r1
, r1
, GEN_INT (frame_size
)));
11218 /* Compare the (maybe adjusted) guard with the stack pointer. */
11219 cc
= s390_emit_compare (LT
, stack_pointer_rtx
, guard
);
11222 call_done
= gen_label_rtx ();
11223 parm_base
= gen_label_rtx ();
11225 /* Emit the parameter block. */
11226 tmp
= gen_split_stack_data (parm_base
, call_done
,
11227 GEN_INT (frame_size
),
11228 GEN_INT (args_size
));
11229 insn
= emit_insn (tmp
);
11230 add_reg_note (insn
, REG_LABEL_OPERAND
, call_done
);
11231 LABEL_NUSES (call_done
)++;
11232 add_reg_note (insn
, REG_LABEL_OPERAND
, parm_base
);
11233 LABEL_NUSES (parm_base
)++;
11235 /* %r1 = litbase. */
11236 insn
= emit_move_insn (r1
, gen_rtx_LABEL_REF (VOIDmode
, parm_base
));
11237 add_reg_note (insn
, REG_LABEL_OPERAND
, parm_base
);
11238 LABEL_NUSES (parm_base
)++;
11240 /* Now, we need to call __morestack. It has very special calling
11241 conventions: it preserves param/return/static chain registers for
11242 calling main function body, and looks for its own parameters at %r1. */
11246 tmp
= gen_split_stack_cond_call (morestack_ref
, cc
, call_done
);
11248 insn
= emit_jump_insn (tmp
);
11249 JUMP_LABEL (insn
) = call_done
;
11250 LABEL_NUSES (call_done
)++;
11252 /* Mark the jump as very unlikely to be taken. */
11253 add_int_reg_note (insn
, REG_BR_PROB
, REG_BR_PROB_BASE
/ 100);
11255 if (cfun
->machine
->split_stack_varargs_pointer
!= NULL_RTX
)
11257 /* If va_start is used, and __morestack was not called, just use
11259 emit_move_insn (r1
,
11260 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
11261 GEN_INT (STACK_POINTER_OFFSET
)));
11266 tmp
= gen_split_stack_call (morestack_ref
, call_done
);
11267 insn
= emit_jump_insn (tmp
);
11268 JUMP_LABEL (insn
) = call_done
;
11269 LABEL_NUSES (call_done
)++;
11273 /* __morestack will call us here. */
11275 emit_label (call_done
);
11278 /* We may have to tell the dataflow pass that the split stack prologue
11279 is initializing a register. */
11282 s390_live_on_entry (bitmap regs
)
11284 if (cfun
->machine
->split_stack_varargs_pointer
!= NULL_RTX
)
11286 gcc_assert (flag_split_stack
);
11287 bitmap_set_bit (regs
, 1);
11291 /* Return true if the function can use simple_return to return outside
11292 of a shrink-wrapped region. At present shrink-wrapping is supported
11296 s390_can_use_simple_return_insn (void)
11301 /* Return true if the epilogue is guaranteed to contain only a return
11302 instruction and if a direct return can therefore be used instead.
11303 One of the main advantages of using direct return instructions
11304 is that we can then use conditional returns. */
11307 s390_can_use_return_insn (void)
11311 if (!reload_completed
)
11317 if (TARGET_TPF_PROFILING
)
11320 for (i
= 0; i
< 16; i
++)
11321 if (cfun_gpr_save_slot (i
) != SAVE_SLOT_NONE
)
11324 /* For 31 bit this is not covered by the frame_size check below
11325 since f4, f6 are saved in the register save area without needing
11326 additional stack space. */
11328 && (cfun_fpr_save_p (FPR4_REGNUM
) || cfun_fpr_save_p (FPR6_REGNUM
)))
11331 if (cfun
->machine
->base_reg
11332 && !call_really_used_regs
[REGNO (cfun
->machine
->base_reg
)])
11335 return cfun_frame_layout
.frame_size
== 0;
11338 /* The VX ABI differs for vararg functions. Therefore we need the
11339 prototype of the callee to be available when passing vector type
11341 static const char *
11342 s390_invalid_arg_for_unprototyped_fn (const_tree typelist
, const_tree funcdecl
, const_tree val
)
11344 return ((TARGET_VX_ABI
11346 && VECTOR_TYPE_P (TREE_TYPE (val
))
11347 && (funcdecl
== NULL_TREE
11348 || (TREE_CODE (funcdecl
) == FUNCTION_DECL
11349 && DECL_BUILT_IN_CLASS (funcdecl
) != BUILT_IN_MD
)))
11350 ? N_("Vector argument passed to unprototyped function")
11355 /* Return the size in bytes of a function argument of
11356 type TYPE and/or mode MODE. At least one of TYPE or
11357 MODE must be specified. */
11360 s390_function_arg_size (machine_mode mode
, const_tree type
)
11363 return int_size_in_bytes (type
);
11365 /* No type info available for some library calls ... */
11366 if (mode
!= BLKmode
)
11367 return GET_MODE_SIZE (mode
);
11369 /* If we have neither type nor mode, abort */
11370 gcc_unreachable ();
11373 /* Return true if a function argument of type TYPE and mode MODE
11374 is to be passed in a vector register, if available. */
11377 s390_function_arg_vector (machine_mode mode
, const_tree type
)
11379 if (!TARGET_VX_ABI
)
11382 if (s390_function_arg_size (mode
, type
) > 16)
11385 /* No type info available for some library calls ... */
11387 return VECTOR_MODE_P (mode
);
11389 /* The ABI says that record types with a single member are treated
11390 just like that member would be. */
11391 while (TREE_CODE (type
) == RECORD_TYPE
)
11393 tree field
, single
= NULL_TREE
;
11395 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
11397 if (TREE_CODE (field
) != FIELD_DECL
)
11400 if (single
== NULL_TREE
)
11401 single
= TREE_TYPE (field
);
11406 if (single
== NULL_TREE
)
11410 /* If the field declaration adds extra byte due to
11411 e.g. padding this is not accepted as vector type. */
11412 if (int_size_in_bytes (single
) <= 0
11413 || int_size_in_bytes (single
) != int_size_in_bytes (type
))
11419 return VECTOR_TYPE_P (type
);
11422 /* Return true if a function argument of type TYPE and mode MODE
11423 is to be passed in a floating-point register, if available. */
11426 s390_function_arg_float (machine_mode mode
, const_tree type
)
11428 if (s390_function_arg_size (mode
, type
) > 8)
11431 /* Soft-float changes the ABI: no floating-point registers are used. */
11432 if (TARGET_SOFT_FLOAT
)
11435 /* No type info available for some library calls ... */
11437 return mode
== SFmode
|| mode
== DFmode
|| mode
== SDmode
|| mode
== DDmode
;
11439 /* The ABI says that record types with a single member are treated
11440 just like that member would be. */
11441 while (TREE_CODE (type
) == RECORD_TYPE
)
11443 tree field
, single
= NULL_TREE
;
11445 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
11447 if (TREE_CODE (field
) != FIELD_DECL
)
11450 if (single
== NULL_TREE
)
11451 single
= TREE_TYPE (field
);
11456 if (single
== NULL_TREE
)
11462 return TREE_CODE (type
) == REAL_TYPE
;
11465 /* Return true if a function argument of type TYPE and mode MODE
11466 is to be passed in an integer register, or a pair of integer
11467 registers, if available. */
11470 s390_function_arg_integer (machine_mode mode
, const_tree type
)
11472 int size
= s390_function_arg_size (mode
, type
);
11476 /* No type info available for some library calls ... */
11478 return GET_MODE_CLASS (mode
) == MODE_INT
11479 || (TARGET_SOFT_FLOAT
&& SCALAR_FLOAT_MODE_P (mode
));
11481 /* We accept small integral (and similar) types. */
11482 if (INTEGRAL_TYPE_P (type
)
11483 || POINTER_TYPE_P (type
)
11484 || TREE_CODE (type
) == NULLPTR_TYPE
11485 || TREE_CODE (type
) == OFFSET_TYPE
11486 || (TARGET_SOFT_FLOAT
&& TREE_CODE (type
) == REAL_TYPE
))
11489 /* We also accept structs of size 1, 2, 4, 8 that are not
11490 passed in floating-point registers. */
11491 if (AGGREGATE_TYPE_P (type
)
11492 && exact_log2 (size
) >= 0
11493 && !s390_function_arg_float (mode
, type
))
11499 /* Return 1 if a function argument of type TYPE and mode MODE
11500 is to be passed by reference. The ABI specifies that only
11501 structures of size 1, 2, 4, or 8 bytes are passed by value,
11502 all other structures (and complex numbers) are passed by
11506 s390_pass_by_reference (cumulative_args_t ca ATTRIBUTE_UNUSED
,
11507 machine_mode mode
, const_tree type
,
11508 bool named ATTRIBUTE_UNUSED
)
11510 int size
= s390_function_arg_size (mode
, type
);
11512 if (s390_function_arg_vector (mode
, type
))
11520 if (AGGREGATE_TYPE_P (type
) && exact_log2 (size
) < 0)
11523 if (TREE_CODE (type
) == COMPLEX_TYPE
11524 || TREE_CODE (type
) == VECTOR_TYPE
)
11531 /* Update the data in CUM to advance over an argument of mode MODE and
11532 data type TYPE. (TYPE is null for libcalls where that information
11533 may not be available.). The boolean NAMED specifies whether the
11534 argument is a named argument (as opposed to an unnamed argument
11535 matching an ellipsis). */
11538 s390_function_arg_advance (cumulative_args_t cum_v
, machine_mode mode
,
11539 const_tree type
, bool named
)
11541 CUMULATIVE_ARGS
*cum
= get_cumulative_args (cum_v
);
11543 if (s390_function_arg_vector (mode
, type
))
11545 /* We are called for unnamed vector stdarg arguments which are
11546 passed on the stack. In this case this hook does not have to
11547 do anything since stack arguments are tracked by common
11553 else if (s390_function_arg_float (mode
, type
))
11557 else if (s390_function_arg_integer (mode
, type
))
11559 int size
= s390_function_arg_size (mode
, type
);
11560 cum
->gprs
+= ((size
+ UNITS_PER_LONG
- 1) / UNITS_PER_LONG
);
11563 gcc_unreachable ();
11566 /* Define where to put the arguments to a function.
11567 Value is zero to push the argument on the stack,
11568 or a hard register in which to store the argument.
11570 MODE is the argument's machine mode.
11571 TYPE is the data type of the argument (as a tree).
11572 This is null for libcalls where that information may
11574 CUM is a variable of type CUMULATIVE_ARGS which gives info about
11575 the preceding args and about the function being called.
11576 NAMED is nonzero if this argument is a named parameter
11577 (otherwise it is an extra parameter matching an ellipsis).
11579 On S/390, we use general purpose registers 2 through 6 to
11580 pass integer, pointer, and certain structure arguments, and
11581 floating point registers 0 and 2 (0, 2, 4, and 6 on 64-bit)
11582 to pass floating point arguments. All remaining arguments
11583 are pushed to the stack. */
11586 s390_function_arg (cumulative_args_t cum_v
, machine_mode mode
,
11587 const_tree type
, bool named
)
11589 CUMULATIVE_ARGS
*cum
= get_cumulative_args (cum_v
);
11592 s390_check_type_for_vector_abi (type
, true, false);
11594 if (s390_function_arg_vector (mode
, type
))
11596 /* Vector arguments being part of the ellipsis are passed on the
11598 if (!named
|| (cum
->vrs
+ 1 > VEC_ARG_NUM_REG
))
11601 return gen_rtx_REG (mode
, cum
->vrs
+ FIRST_VEC_ARG_REGNO
);
11603 else if (s390_function_arg_float (mode
, type
))
11605 if (cum
->fprs
+ 1 > FP_ARG_NUM_REG
)
11608 return gen_rtx_REG (mode
, cum
->fprs
+ 16);
11610 else if (s390_function_arg_integer (mode
, type
))
11612 int size
= s390_function_arg_size (mode
, type
);
11613 int n_gprs
= (size
+ UNITS_PER_LONG
- 1) / UNITS_PER_LONG
;
11615 if (cum
->gprs
+ n_gprs
> GP_ARG_NUM_REG
)
11617 else if (n_gprs
== 1 || UNITS_PER_WORD
== UNITS_PER_LONG
)
11618 return gen_rtx_REG (mode
, cum
->gprs
+ 2);
11619 else if (n_gprs
== 2)
11621 rtvec p
= rtvec_alloc (2);
11624 = gen_rtx_EXPR_LIST (SImode
, gen_rtx_REG (SImode
, cum
->gprs
+ 2),
11627 = gen_rtx_EXPR_LIST (SImode
, gen_rtx_REG (SImode
, cum
->gprs
+ 3),
11630 return gen_rtx_PARALLEL (mode
, p
);
11634 /* After the real arguments, expand_call calls us once again
11635 with a void_type_node type. Whatever we return here is
11636 passed as operand 2 to the call expanders.
11638 We don't need this feature ... */
11639 else if (type
== void_type_node
)
11642 gcc_unreachable ();
11645 /* Return true if return values of type TYPE should be returned
11646 in a memory buffer whose address is passed by the caller as
11647 hidden first argument. */
11650 s390_return_in_memory (const_tree type
, const_tree fundecl ATTRIBUTE_UNUSED
)
11652 /* We accept small integral (and similar) types. */
11653 if (INTEGRAL_TYPE_P (type
)
11654 || POINTER_TYPE_P (type
)
11655 || TREE_CODE (type
) == OFFSET_TYPE
11656 || TREE_CODE (type
) == REAL_TYPE
)
11657 return int_size_in_bytes (type
) > 8;
11659 /* vector types which fit into a VR. */
11661 && VECTOR_TYPE_P (type
)
11662 && int_size_in_bytes (type
) <= 16)
11665 /* Aggregates and similar constructs are always returned
11667 if (AGGREGATE_TYPE_P (type
)
11668 || TREE_CODE (type
) == COMPLEX_TYPE
11669 || VECTOR_TYPE_P (type
))
11672 /* ??? We get called on all sorts of random stuff from
11673 aggregate_value_p. We can't abort, but it's not clear
11674 what's safe to return. Pretend it's a struct I guess. */
11678 /* Function arguments and return values are promoted to word size. */
11680 static machine_mode
11681 s390_promote_function_mode (const_tree type
, machine_mode mode
,
11683 const_tree fntype ATTRIBUTE_UNUSED
,
11684 int for_return ATTRIBUTE_UNUSED
)
11686 if (INTEGRAL_MODE_P (mode
)
11687 && GET_MODE_SIZE (mode
) < UNITS_PER_LONG
)
11689 if (type
!= NULL_TREE
&& POINTER_TYPE_P (type
))
11690 *punsignedp
= POINTERS_EXTEND_UNSIGNED
;
11697 /* Define where to return a (scalar) value of type RET_TYPE.
11698 If RET_TYPE is null, define where to return a (scalar)
11699 value of mode MODE from a libcall. */
11702 s390_function_and_libcall_value (machine_mode mode
,
11703 const_tree ret_type
,
11704 const_tree fntype_or_decl
,
11705 bool outgoing ATTRIBUTE_UNUSED
)
11707 /* For vector return types it is important to use the RET_TYPE
11708 argument whenever available since the middle-end might have
11709 changed the mode to a scalar mode. */
11710 bool vector_ret_type_p
= ((ret_type
&& VECTOR_TYPE_P (ret_type
))
11711 || (!ret_type
&& VECTOR_MODE_P (mode
)));
11713 /* For normal functions perform the promotion as
11714 promote_function_mode would do. */
11717 int unsignedp
= TYPE_UNSIGNED (ret_type
);
11718 mode
= promote_function_mode (ret_type
, mode
, &unsignedp
,
11719 fntype_or_decl
, 1);
11722 gcc_assert (GET_MODE_CLASS (mode
) == MODE_INT
11723 || SCALAR_FLOAT_MODE_P (mode
)
11724 || (TARGET_VX_ABI
&& vector_ret_type_p
));
11725 gcc_assert (GET_MODE_SIZE (mode
) <= (TARGET_VX_ABI
? 16 : 8));
11727 if (TARGET_VX_ABI
&& vector_ret_type_p
)
11728 return gen_rtx_REG (mode
, FIRST_VEC_ARG_REGNO
);
11729 else if (TARGET_HARD_FLOAT
&& SCALAR_FLOAT_MODE_P (mode
))
11730 return gen_rtx_REG (mode
, 16);
11731 else if (GET_MODE_SIZE (mode
) <= UNITS_PER_LONG
11732 || UNITS_PER_LONG
== UNITS_PER_WORD
)
11733 return gen_rtx_REG (mode
, 2);
11734 else if (GET_MODE_SIZE (mode
) == 2 * UNITS_PER_LONG
)
11736 /* This case is triggered when returning a 64 bit value with
11737 -m31 -mzarch. Although the value would fit into a single
11738 register it has to be forced into a 32 bit register pair in
11739 order to match the ABI. */
11740 rtvec p
= rtvec_alloc (2);
11743 = gen_rtx_EXPR_LIST (SImode
, gen_rtx_REG (SImode
, 2), const0_rtx
);
11745 = gen_rtx_EXPR_LIST (SImode
, gen_rtx_REG (SImode
, 3), GEN_INT (4));
11747 return gen_rtx_PARALLEL (mode
, p
);
11750 gcc_unreachable ();
11753 /* Define where to return a scalar return value of type RET_TYPE. */
11756 s390_function_value (const_tree ret_type
, const_tree fn_decl_or_type
,
11759 return s390_function_and_libcall_value (TYPE_MODE (ret_type
), ret_type
,
11760 fn_decl_or_type
, outgoing
);
11763 /* Define where to return a scalar libcall return value of mode
11767 s390_libcall_value (machine_mode mode
, const_rtx fun ATTRIBUTE_UNUSED
)
11769 return s390_function_and_libcall_value (mode
, NULL_TREE
,
11774 /* Create and return the va_list datatype.
11776 On S/390, va_list is an array type equivalent to
11778 typedef struct __va_list_tag
11782 void *__overflow_arg_area;
11783 void *__reg_save_area;
11786 where __gpr and __fpr hold the number of general purpose
11787 or floating point arguments used up to now, respectively,
11788 __overflow_arg_area points to the stack location of the
11789 next argument passed on the stack, and __reg_save_area
11790 always points to the start of the register area in the
11791 call frame of the current function. The function prologue
11792 saves all registers used for argument passing into this
11793 area if the function uses variable arguments. */
11796 s390_build_builtin_va_list (void)
11798 tree f_gpr
, f_fpr
, f_ovf
, f_sav
, record
, type_decl
;
11800 record
= lang_hooks
.types
.make_type (RECORD_TYPE
);
11803 build_decl (BUILTINS_LOCATION
,
11804 TYPE_DECL
, get_identifier ("__va_list_tag"), record
);
11806 f_gpr
= build_decl (BUILTINS_LOCATION
,
11807 FIELD_DECL
, get_identifier ("__gpr"),
11808 long_integer_type_node
);
11809 f_fpr
= build_decl (BUILTINS_LOCATION
,
11810 FIELD_DECL
, get_identifier ("__fpr"),
11811 long_integer_type_node
);
11812 f_ovf
= build_decl (BUILTINS_LOCATION
,
11813 FIELD_DECL
, get_identifier ("__overflow_arg_area"),
11815 f_sav
= build_decl (BUILTINS_LOCATION
,
11816 FIELD_DECL
, get_identifier ("__reg_save_area"),
11819 va_list_gpr_counter_field
= f_gpr
;
11820 va_list_fpr_counter_field
= f_fpr
;
11822 DECL_FIELD_CONTEXT (f_gpr
) = record
;
11823 DECL_FIELD_CONTEXT (f_fpr
) = record
;
11824 DECL_FIELD_CONTEXT (f_ovf
) = record
;
11825 DECL_FIELD_CONTEXT (f_sav
) = record
;
11827 TYPE_STUB_DECL (record
) = type_decl
;
11828 TYPE_NAME (record
) = type_decl
;
11829 TYPE_FIELDS (record
) = f_gpr
;
11830 DECL_CHAIN (f_gpr
) = f_fpr
;
11831 DECL_CHAIN (f_fpr
) = f_ovf
;
11832 DECL_CHAIN (f_ovf
) = f_sav
;
11834 layout_type (record
);
11836 /* The correct type is an array type of one element. */
11837 return build_array_type (record
, build_index_type (size_zero_node
));
11840 /* Implement va_start by filling the va_list structure VALIST.
11841 STDARG_P is always true, and ignored.
11842 NEXTARG points to the first anonymous stack argument.
11844 The following global variables are used to initialize
11845 the va_list structure:
11848 holds number of gprs and fprs used for named arguments.
11849 crtl->args.arg_offset_rtx:
11850 holds the offset of the first anonymous stack argument
11851 (relative to the virtual arg pointer). */
11854 s390_va_start (tree valist
, rtx nextarg ATTRIBUTE_UNUSED
)
11856 HOST_WIDE_INT n_gpr
, n_fpr
;
11858 tree f_gpr
, f_fpr
, f_ovf
, f_sav
;
11859 tree gpr
, fpr
, ovf
, sav
, t
;
11861 f_gpr
= TYPE_FIELDS (TREE_TYPE (va_list_type_node
));
11862 f_fpr
= DECL_CHAIN (f_gpr
);
11863 f_ovf
= DECL_CHAIN (f_fpr
);
11864 f_sav
= DECL_CHAIN (f_ovf
);
11866 valist
= build_simple_mem_ref (valist
);
11867 gpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_gpr
), valist
, f_gpr
, NULL_TREE
);
11868 fpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_fpr
), valist
, f_fpr
, NULL_TREE
);
11869 ovf
= build3 (COMPONENT_REF
, TREE_TYPE (f_ovf
), valist
, f_ovf
, NULL_TREE
);
11870 sav
= build3 (COMPONENT_REF
, TREE_TYPE (f_sav
), valist
, f_sav
, NULL_TREE
);
11872 /* Count number of gp and fp argument registers used. */
11874 n_gpr
= crtl
->args
.info
.gprs
;
11875 n_fpr
= crtl
->args
.info
.fprs
;
11877 if (cfun
->va_list_gpr_size
)
11879 t
= build2 (MODIFY_EXPR
, TREE_TYPE (gpr
), gpr
,
11880 build_int_cst (NULL_TREE
, n_gpr
));
11881 TREE_SIDE_EFFECTS (t
) = 1;
11882 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
11885 if (cfun
->va_list_fpr_size
)
11887 t
= build2 (MODIFY_EXPR
, TREE_TYPE (fpr
), fpr
,
11888 build_int_cst (NULL_TREE
, n_fpr
));
11889 TREE_SIDE_EFFECTS (t
) = 1;
11890 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
11893 if (flag_split_stack
11894 && (lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (cfun
->decl
))
11896 && cfun
->machine
->split_stack_varargs_pointer
== NULL_RTX
)
11901 reg
= gen_reg_rtx (Pmode
);
11902 cfun
->machine
->split_stack_varargs_pointer
= reg
;
11905 emit_move_insn (reg
, gen_rtx_REG (Pmode
, 1));
11906 seq
= get_insns ();
11909 push_topmost_sequence ();
11910 emit_insn_after (seq
, entry_of_function ());
11911 pop_topmost_sequence ();
11914 /* Find the overflow area.
11915 FIXME: This currently is too pessimistic when the vector ABI is
11916 enabled. In that case we *always* set up the overflow area
11918 if (n_gpr
+ cfun
->va_list_gpr_size
> GP_ARG_NUM_REG
11919 || n_fpr
+ cfun
->va_list_fpr_size
> FP_ARG_NUM_REG
11922 if (cfun
->machine
->split_stack_varargs_pointer
== NULL_RTX
)
11923 t
= make_tree (TREE_TYPE (ovf
), virtual_incoming_args_rtx
);
11925 t
= make_tree (TREE_TYPE (ovf
), cfun
->machine
->split_stack_varargs_pointer
);
11927 off
= INTVAL (crtl
->args
.arg_offset_rtx
);
11928 off
= off
< 0 ? 0 : off
;
11929 if (TARGET_DEBUG_ARG
)
11930 fprintf (stderr
, "va_start: n_gpr = %d, n_fpr = %d off %d\n",
11931 (int)n_gpr
, (int)n_fpr
, off
);
11933 t
= fold_build_pointer_plus_hwi (t
, off
);
11935 t
= build2 (MODIFY_EXPR
, TREE_TYPE (ovf
), ovf
, t
);
11936 TREE_SIDE_EFFECTS (t
) = 1;
11937 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
11940 /* Find the register save area. */
11941 if ((cfun
->va_list_gpr_size
&& n_gpr
< GP_ARG_NUM_REG
)
11942 || (cfun
->va_list_fpr_size
&& n_fpr
< FP_ARG_NUM_REG
))
11944 t
= make_tree (TREE_TYPE (sav
), return_address_pointer_rtx
);
11945 t
= fold_build_pointer_plus_hwi (t
, -RETURN_REGNUM
* UNITS_PER_LONG
);
11947 t
= build2 (MODIFY_EXPR
, TREE_TYPE (sav
), sav
, t
);
11948 TREE_SIDE_EFFECTS (t
) = 1;
11949 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
11953 /* Implement va_arg by updating the va_list structure
11954 VALIST as required to retrieve an argument of type
11955 TYPE, and returning that argument.
11957 Generates code equivalent to:
11959 if (integral value) {
11960 if (size <= 4 && args.gpr < 5 ||
11961 size > 4 && args.gpr < 4 )
11962 ret = args.reg_save_area[args.gpr+8]
11964 ret = *args.overflow_arg_area++;
11965 } else if (vector value) {
11966 ret = *args.overflow_arg_area;
11967 args.overflow_arg_area += size / 8;
11968 } else if (float value) {
11970 ret = args.reg_save_area[args.fpr+64]
11972 ret = *args.overflow_arg_area++;
11973 } else if (aggregate value) {
11975 ret = *args.reg_save_area[args.gpr]
11977 ret = **args.overflow_arg_area++;
11981 s390_gimplify_va_arg (tree valist
, tree type
, gimple_seq
*pre_p
,
11982 gimple_seq
*post_p ATTRIBUTE_UNUSED
)
11984 tree f_gpr
, f_fpr
, f_ovf
, f_sav
;
11985 tree gpr
, fpr
, ovf
, sav
, reg
, t
, u
;
11986 int indirect_p
, size
, n_reg
, sav_ofs
, sav_scale
, max_reg
;
11987 tree lab_false
, lab_over
;
11988 tree addr
= create_tmp_var (ptr_type_node
, "addr");
11989 bool left_align_p
; /* How a value < UNITS_PER_LONG is aligned within
11992 f_gpr
= TYPE_FIELDS (TREE_TYPE (va_list_type_node
));
11993 f_fpr
= DECL_CHAIN (f_gpr
);
11994 f_ovf
= DECL_CHAIN (f_fpr
);
11995 f_sav
= DECL_CHAIN (f_ovf
);
11997 gpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_gpr
), valist
, f_gpr
, NULL_TREE
);
11998 fpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_fpr
), valist
, f_fpr
, NULL_TREE
);
11999 sav
= build3 (COMPONENT_REF
, TREE_TYPE (f_sav
), valist
, f_sav
, NULL_TREE
);
12001 /* The tree for args* cannot be shared between gpr/fpr and ovf since
12002 both appear on a lhs. */
12003 valist
= unshare_expr (valist
);
12004 ovf
= build3 (COMPONENT_REF
, TREE_TYPE (f_ovf
), valist
, f_ovf
, NULL_TREE
);
12006 size
= int_size_in_bytes (type
);
12008 s390_check_type_for_vector_abi (type
, true, false);
12010 if (pass_by_reference (NULL
, TYPE_MODE (type
), type
, false))
12012 if (TARGET_DEBUG_ARG
)
12014 fprintf (stderr
, "va_arg: aggregate type");
12018 /* Aggregates are passed by reference. */
12023 /* kernel stack layout on 31 bit: It is assumed here that no padding
12024 will be added by s390_frame_info because for va_args always an even
12025 number of gprs has to be saved r15-r2 = 14 regs. */
12026 sav_ofs
= 2 * UNITS_PER_LONG
;
12027 sav_scale
= UNITS_PER_LONG
;
12028 size
= UNITS_PER_LONG
;
12029 max_reg
= GP_ARG_NUM_REG
- n_reg
;
12030 left_align_p
= false;
12032 else if (s390_function_arg_vector (TYPE_MODE (type
), type
))
12034 if (TARGET_DEBUG_ARG
)
12036 fprintf (stderr
, "va_arg: vector type");
12046 left_align_p
= true;
12048 else if (s390_function_arg_float (TYPE_MODE (type
), type
))
12050 if (TARGET_DEBUG_ARG
)
12052 fprintf (stderr
, "va_arg: float type");
12056 /* FP args go in FP registers, if present. */
12060 sav_ofs
= 16 * UNITS_PER_LONG
;
12062 max_reg
= FP_ARG_NUM_REG
- n_reg
;
12063 left_align_p
= false;
12067 if (TARGET_DEBUG_ARG
)
12069 fprintf (stderr
, "va_arg: other type");
12073 /* Otherwise into GP registers. */
12076 n_reg
= (size
+ UNITS_PER_LONG
- 1) / UNITS_PER_LONG
;
12078 /* kernel stack layout on 31 bit: It is assumed here that no padding
12079 will be added by s390_frame_info because for va_args always an even
12080 number of gprs has to be saved r15-r2 = 14 regs. */
12081 sav_ofs
= 2 * UNITS_PER_LONG
;
12083 if (size
< UNITS_PER_LONG
)
12084 sav_ofs
+= UNITS_PER_LONG
- size
;
12086 sav_scale
= UNITS_PER_LONG
;
12087 max_reg
= GP_ARG_NUM_REG
- n_reg
;
12088 left_align_p
= false;
12091 /* Pull the value out of the saved registers ... */
12093 if (reg
!= NULL_TREE
)
12096 if (reg > ((typeof (reg))max_reg))
12099 addr = sav + sav_ofs + reg * save_scale;
12106 lab_false
= create_artificial_label (UNKNOWN_LOCATION
);
12107 lab_over
= create_artificial_label (UNKNOWN_LOCATION
);
12109 t
= fold_convert (TREE_TYPE (reg
), size_int (max_reg
));
12110 t
= build2 (GT_EXPR
, boolean_type_node
, reg
, t
);
12111 u
= build1 (GOTO_EXPR
, void_type_node
, lab_false
);
12112 t
= build3 (COND_EXPR
, void_type_node
, t
, u
, NULL_TREE
);
12113 gimplify_and_add (t
, pre_p
);
12115 t
= fold_build_pointer_plus_hwi (sav
, sav_ofs
);
12116 u
= build2 (MULT_EXPR
, TREE_TYPE (reg
), reg
,
12117 fold_convert (TREE_TYPE (reg
), size_int (sav_scale
)));
12118 t
= fold_build_pointer_plus (t
, u
);
12120 gimplify_assign (addr
, t
, pre_p
);
12122 gimple_seq_add_stmt (pre_p
, gimple_build_goto (lab_over
));
12124 gimple_seq_add_stmt (pre_p
, gimple_build_label (lab_false
));
12127 /* ... Otherwise out of the overflow area. */
12130 if (size
< UNITS_PER_LONG
&& !left_align_p
)
12131 t
= fold_build_pointer_plus_hwi (t
, UNITS_PER_LONG
- size
);
12133 gimplify_expr (&t
, pre_p
, NULL
, is_gimple_val
, fb_rvalue
);
12135 gimplify_assign (addr
, t
, pre_p
);
12137 if (size
< UNITS_PER_LONG
&& left_align_p
)
12138 t
= fold_build_pointer_plus_hwi (t
, UNITS_PER_LONG
);
12140 t
= fold_build_pointer_plus_hwi (t
, size
);
12142 gimplify_assign (ovf
, t
, pre_p
);
12144 if (reg
!= NULL_TREE
)
12145 gimple_seq_add_stmt (pre_p
, gimple_build_label (lab_over
));
12148 /* Increment register save count. */
12152 u
= build2 (PREINCREMENT_EXPR
, TREE_TYPE (reg
), reg
,
12153 fold_convert (TREE_TYPE (reg
), size_int (n_reg
)));
12154 gimplify_and_add (u
, pre_p
);
12159 t
= build_pointer_type_for_mode (build_pointer_type (type
),
12161 addr
= fold_convert (t
, addr
);
12162 addr
= build_va_arg_indirect_ref (addr
);
12166 t
= build_pointer_type_for_mode (type
, ptr_mode
, true);
12167 addr
= fold_convert (t
, addr
);
12170 return build_va_arg_indirect_ref (addr
);
12173 /* Emit rtl for the tbegin or tbegin_retry (RETRY != NULL_RTX)
12175 DEST - Register location where CC will be stored.
12176 TDB - Pointer to a 256 byte area where to store the transaction.
12177 diagnostic block. NULL if TDB is not needed.
12178 RETRY - Retry count value. If non-NULL a retry loop for CC2
12180 CLOBBER_FPRS_P - If true clobbers for all FPRs are emitted as part
12181 of the tbegin instruction pattern. */
12184 s390_expand_tbegin (rtx dest
, rtx tdb
, rtx retry
, bool clobber_fprs_p
)
12186 rtx retry_plus_two
= gen_reg_rtx (SImode
);
12187 rtx retry_reg
= gen_reg_rtx (SImode
);
12188 rtx_code_label
*retry_label
= NULL
;
12190 if (retry
!= NULL_RTX
)
12192 emit_move_insn (retry_reg
, retry
);
12193 emit_insn (gen_addsi3 (retry_plus_two
, retry_reg
, const2_rtx
));
12194 emit_insn (gen_addsi3 (retry_reg
, retry_reg
, const1_rtx
));
12195 retry_label
= gen_label_rtx ();
12196 emit_label (retry_label
);
12199 if (clobber_fprs_p
)
12202 emit_insn (gen_tbegin_1_z13 (gen_rtx_CONST_INT (VOIDmode
, TBEGIN_MASK
),
12205 emit_insn (gen_tbegin_1 (gen_rtx_CONST_INT (VOIDmode
, TBEGIN_MASK
),
12209 emit_insn (gen_tbegin_nofloat_1 (gen_rtx_CONST_INT (VOIDmode
, TBEGIN_MASK
),
12212 emit_move_insn (dest
, gen_rtx_UNSPEC (SImode
,
12213 gen_rtvec (1, gen_rtx_REG (CCRAWmode
,
12215 UNSPEC_CC_TO_INT
));
12216 if (retry
!= NULL_RTX
)
12218 const int CC0
= 1 << 3;
12219 const int CC1
= 1 << 2;
12220 const int CC3
= 1 << 0;
12222 rtx count
= gen_reg_rtx (SImode
);
12223 rtx_code_label
*leave_label
= gen_label_rtx ();
12225 /* Exit for success and permanent failures. */
12226 jump
= s390_emit_jump (leave_label
,
12227 gen_rtx_EQ (VOIDmode
,
12228 gen_rtx_REG (CCRAWmode
, CC_REGNUM
),
12229 gen_rtx_CONST_INT (VOIDmode
, CC0
| CC1
| CC3
)));
12230 LABEL_NUSES (leave_label
) = 1;
12232 /* CC2 - transient failure. Perform retry with ppa. */
12233 emit_move_insn (count
, retry_plus_two
);
12234 emit_insn (gen_subsi3 (count
, count
, retry_reg
));
12235 emit_insn (gen_tx_assist (count
));
12236 jump
= emit_jump_insn (gen_doloop_si64 (retry_label
,
12239 JUMP_LABEL (jump
) = retry_label
;
12240 LABEL_NUSES (retry_label
) = 1;
12241 emit_label (leave_label
);
12246 /* Return the decl for the target specific builtin with the function
12250 s390_builtin_decl (unsigned fcode
, bool initialized_p ATTRIBUTE_UNUSED
)
12252 if (fcode
>= S390_BUILTIN_MAX
)
12253 return error_mark_node
;
12255 return s390_builtin_decls
[fcode
];
12258 /* We call mcount before the function prologue. So a profiled leaf
12259 function should stay a leaf function. */
12262 s390_keep_leaf_when_profiled ()
12267 /* Output assembly code for the trampoline template to
12270 On S/390, we use gpr 1 internally in the trampoline code;
12271 gpr 0 is used to hold the static chain. */
12274 s390_asm_trampoline_template (FILE *file
)
12277 op
[0] = gen_rtx_REG (Pmode
, 0);
12278 op
[1] = gen_rtx_REG (Pmode
, 1);
12282 output_asm_insn ("basr\t%1,0", op
); /* 2 byte */
12283 output_asm_insn ("lmg\t%0,%1,14(%1)", op
); /* 6 byte */
12284 output_asm_insn ("br\t%1", op
); /* 2 byte */
12285 ASM_OUTPUT_SKIP (file
, (HOST_WIDE_INT
)(TRAMPOLINE_SIZE
- 10));
12289 output_asm_insn ("basr\t%1,0", op
); /* 2 byte */
12290 output_asm_insn ("lm\t%0,%1,6(%1)", op
); /* 4 byte */
12291 output_asm_insn ("br\t%1", op
); /* 2 byte */
12292 ASM_OUTPUT_SKIP (file
, (HOST_WIDE_INT
)(TRAMPOLINE_SIZE
- 8));
12296 /* Emit RTL insns to initialize the variable parts of a trampoline.
12297 FNADDR is an RTX for the address of the function's pure code.
12298 CXT is an RTX for the static chain value for the function. */
12301 s390_trampoline_init (rtx m_tramp
, tree fndecl
, rtx cxt
)
12303 rtx fnaddr
= XEXP (DECL_RTL (fndecl
), 0);
12306 emit_block_move (m_tramp
, assemble_trampoline_template (),
12307 GEN_INT (2 * UNITS_PER_LONG
), BLOCK_OP_NORMAL
);
12309 mem
= adjust_address (m_tramp
, Pmode
, 2 * UNITS_PER_LONG
);
12310 emit_move_insn (mem
, cxt
);
12311 mem
= adjust_address (m_tramp
, Pmode
, 3 * UNITS_PER_LONG
);
12312 emit_move_insn (mem
, fnaddr
);
12315 /* Output assembler code to FILE to increment profiler label # LABELNO
12316 for profiling a function entry. */
12319 s390_function_profiler (FILE *file
, int labelno
)
12324 ASM_GENERATE_INTERNAL_LABEL (label
, "LP", labelno
);
12326 fprintf (file
, "# function profiler \n");
12328 op
[0] = gen_rtx_REG (Pmode
, RETURN_REGNUM
);
12329 op
[1] = gen_rtx_REG (Pmode
, STACK_POINTER_REGNUM
);
12330 op
[1] = gen_rtx_MEM (Pmode
, plus_constant (Pmode
, op
[1], UNITS_PER_LONG
));
12332 op
[2] = gen_rtx_REG (Pmode
, 1);
12333 op
[3] = gen_rtx_SYMBOL_REF (Pmode
, label
);
12334 SYMBOL_REF_FLAGS (op
[3]) = SYMBOL_FLAG_LOCAL
;
12336 op
[4] = gen_rtx_SYMBOL_REF (Pmode
, "_mcount");
12339 op
[4] = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op
[4]), UNSPEC_PLT
);
12340 op
[4] = gen_rtx_CONST (Pmode
, op
[4]);
12345 output_asm_insn ("stg\t%0,%1", op
);
12346 output_asm_insn ("larl\t%2,%3", op
);
12347 output_asm_insn ("brasl\t%0,%4", op
);
12348 output_asm_insn ("lg\t%0,%1", op
);
12350 else if (TARGET_CPU_ZARCH
)
12352 output_asm_insn ("st\t%0,%1", op
);
12353 output_asm_insn ("larl\t%2,%3", op
);
12354 output_asm_insn ("brasl\t%0,%4", op
);
12355 output_asm_insn ("l\t%0,%1", op
);
12357 else if (!flag_pic
)
12359 op
[6] = gen_label_rtx ();
12361 output_asm_insn ("st\t%0,%1", op
);
12362 output_asm_insn ("bras\t%2,%l6", op
);
12363 output_asm_insn (".long\t%4", op
);
12364 output_asm_insn (".long\t%3", op
);
12365 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[6]));
12366 output_asm_insn ("l\t%0,0(%2)", op
);
12367 output_asm_insn ("l\t%2,4(%2)", op
);
12368 output_asm_insn ("basr\t%0,%0", op
);
12369 output_asm_insn ("l\t%0,%1", op
);
12373 op
[5] = gen_label_rtx ();
12374 op
[6] = gen_label_rtx ();
12376 output_asm_insn ("st\t%0,%1", op
);
12377 output_asm_insn ("bras\t%2,%l6", op
);
12378 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[5]));
12379 output_asm_insn (".long\t%4-%l5", op
);
12380 output_asm_insn (".long\t%3-%l5", op
);
12381 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[6]));
12382 output_asm_insn ("lr\t%0,%2", op
);
12383 output_asm_insn ("a\t%0,0(%2)", op
);
12384 output_asm_insn ("a\t%2,4(%2)", op
);
12385 output_asm_insn ("basr\t%0,%0", op
);
12386 output_asm_insn ("l\t%0,%1", op
);
12390 /* Encode symbol attributes (local vs. global, tls model) of a SYMBOL_REF
12391 into its SYMBOL_REF_FLAGS. */
12394 s390_encode_section_info (tree decl
, rtx rtl
, int first
)
12396 default_encode_section_info (decl
, rtl
, first
);
12398 if (TREE_CODE (decl
) == VAR_DECL
)
12400 /* Store the alignment to be able to check if we can use
12401 a larl/load-relative instruction. We only handle the cases
12402 that can go wrong (i.e. no FUNC_DECLs). If a symref does
12403 not have any flag we assume it to be correctly aligned. */
12405 if (DECL_ALIGN (decl
) % 64)
12406 SYMBOL_FLAG_SET_NOTALIGN8 (XEXP (rtl
, 0));
12408 if (DECL_ALIGN (decl
) % 32)
12409 SYMBOL_FLAG_SET_NOTALIGN4 (XEXP (rtl
, 0));
12411 if (DECL_ALIGN (decl
) == 0 || DECL_ALIGN (decl
) % 16)
12412 SYMBOL_FLAG_SET_NOTALIGN2 (XEXP (rtl
, 0));
12415 /* Literal pool references don't have a decl so they are handled
12416 differently here. We rely on the information in the MEM_ALIGN
12417 entry to decide upon the alignment. */
12419 && GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
12420 && TREE_CONSTANT_POOL_ADDRESS_P (XEXP (rtl
, 0))
12421 && MEM_ALIGN (rtl
) != 0
12422 && GET_MODE_BITSIZE (GET_MODE (rtl
)) != 0)
12424 if (MEM_ALIGN (rtl
) % 64)
12425 SYMBOL_FLAG_SET_NOTALIGN8 (XEXP (rtl
, 0));
12427 if (MEM_ALIGN (rtl
) % 32)
12428 SYMBOL_FLAG_SET_NOTALIGN4 (XEXP (rtl
, 0));
12430 if (MEM_ALIGN (rtl
) == 0 || MEM_ALIGN (rtl
) % 16)
12431 SYMBOL_FLAG_SET_NOTALIGN2 (XEXP (rtl
, 0));
12435 /* Output thunk to FILE that implements a C++ virtual function call (with
12436 multiple inheritance) to FUNCTION. The thunk adjusts the this pointer
12437 by DELTA, and unless VCALL_OFFSET is zero, applies an additional adjustment
12438 stored at VCALL_OFFSET in the vtable whose address is located at offset 0
12439 relative to the resulting this pointer. */
12442 s390_output_mi_thunk (FILE *file
, tree thunk ATTRIBUTE_UNUSED
,
12443 HOST_WIDE_INT delta
, HOST_WIDE_INT vcall_offset
,
12449 /* Make sure unwind info is emitted for the thunk if needed. */
12450 final_start_function (emit_barrier (), file
, 1);
12452 /* Operand 0 is the target function. */
12453 op
[0] = XEXP (DECL_RTL (function
), 0);
12454 if (flag_pic
&& !SYMBOL_REF_LOCAL_P (op
[0]))
12457 op
[0] = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op
[0]),
12458 TARGET_64BIT
? UNSPEC_PLT
: UNSPEC_GOT
);
12459 op
[0] = gen_rtx_CONST (Pmode
, op
[0]);
12462 /* Operand 1 is the 'this' pointer. */
12463 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function
)), function
))
12464 op
[1] = gen_rtx_REG (Pmode
, 3);
12466 op
[1] = gen_rtx_REG (Pmode
, 2);
12468 /* Operand 2 is the delta. */
12469 op
[2] = GEN_INT (delta
);
12471 /* Operand 3 is the vcall_offset. */
12472 op
[3] = GEN_INT (vcall_offset
);
12474 /* Operand 4 is the temporary register. */
12475 op
[4] = gen_rtx_REG (Pmode
, 1);
12477 /* Operands 5 to 8 can be used as labels. */
12483 /* Operand 9 can be used for temporary register. */
12486 /* Generate code. */
12489 /* Setup literal pool pointer if required. */
12490 if ((!DISP_IN_RANGE (delta
)
12491 && !CONST_OK_FOR_K (delta
)
12492 && !CONST_OK_FOR_Os (delta
))
12493 || (!DISP_IN_RANGE (vcall_offset
)
12494 && !CONST_OK_FOR_K (vcall_offset
)
12495 && !CONST_OK_FOR_Os (vcall_offset
)))
12497 op
[5] = gen_label_rtx ();
12498 output_asm_insn ("larl\t%4,%5", op
);
12501 /* Add DELTA to this pointer. */
12504 if (CONST_OK_FOR_J (delta
))
12505 output_asm_insn ("la\t%1,%2(%1)", op
);
12506 else if (DISP_IN_RANGE (delta
))
12507 output_asm_insn ("lay\t%1,%2(%1)", op
);
12508 else if (CONST_OK_FOR_K (delta
))
12509 output_asm_insn ("aghi\t%1,%2", op
);
12510 else if (CONST_OK_FOR_Os (delta
))
12511 output_asm_insn ("agfi\t%1,%2", op
);
12514 op
[6] = gen_label_rtx ();
12515 output_asm_insn ("agf\t%1,%6-%5(%4)", op
);
12519 /* Perform vcall adjustment. */
12522 if (DISP_IN_RANGE (vcall_offset
))
12524 output_asm_insn ("lg\t%4,0(%1)", op
);
12525 output_asm_insn ("ag\t%1,%3(%4)", op
);
12527 else if (CONST_OK_FOR_K (vcall_offset
))
12529 output_asm_insn ("lghi\t%4,%3", op
);
12530 output_asm_insn ("ag\t%4,0(%1)", op
);
12531 output_asm_insn ("ag\t%1,0(%4)", op
);
12533 else if (CONST_OK_FOR_Os (vcall_offset
))
12535 output_asm_insn ("lgfi\t%4,%3", op
);
12536 output_asm_insn ("ag\t%4,0(%1)", op
);
12537 output_asm_insn ("ag\t%1,0(%4)", op
);
12541 op
[7] = gen_label_rtx ();
12542 output_asm_insn ("llgf\t%4,%7-%5(%4)", op
);
12543 output_asm_insn ("ag\t%4,0(%1)", op
);
12544 output_asm_insn ("ag\t%1,0(%4)", op
);
12548 /* Jump to target. */
12549 output_asm_insn ("jg\t%0", op
);
12551 /* Output literal pool if required. */
12554 output_asm_insn (".align\t4", op
);
12555 targetm
.asm_out
.internal_label (file
, "L",
12556 CODE_LABEL_NUMBER (op
[5]));
12560 targetm
.asm_out
.internal_label (file
, "L",
12561 CODE_LABEL_NUMBER (op
[6]));
12562 output_asm_insn (".long\t%2", op
);
12566 targetm
.asm_out
.internal_label (file
, "L",
12567 CODE_LABEL_NUMBER (op
[7]));
12568 output_asm_insn (".long\t%3", op
);
12573 /* Setup base pointer if required. */
12575 || (!DISP_IN_RANGE (delta
)
12576 && !CONST_OK_FOR_K (delta
)
12577 && !CONST_OK_FOR_Os (delta
))
12578 || (!DISP_IN_RANGE (delta
)
12579 && !CONST_OK_FOR_K (vcall_offset
)
12580 && !CONST_OK_FOR_Os (vcall_offset
)))
12582 op
[5] = gen_label_rtx ();
12583 output_asm_insn ("basr\t%4,0", op
);
12584 targetm
.asm_out
.internal_label (file
, "L",
12585 CODE_LABEL_NUMBER (op
[5]));
12588 /* Add DELTA to this pointer. */
12591 if (CONST_OK_FOR_J (delta
))
12592 output_asm_insn ("la\t%1,%2(%1)", op
);
12593 else if (DISP_IN_RANGE (delta
))
12594 output_asm_insn ("lay\t%1,%2(%1)", op
);
12595 else if (CONST_OK_FOR_K (delta
))
12596 output_asm_insn ("ahi\t%1,%2", op
);
12597 else if (CONST_OK_FOR_Os (delta
))
12598 output_asm_insn ("afi\t%1,%2", op
);
12601 op
[6] = gen_label_rtx ();
12602 output_asm_insn ("a\t%1,%6-%5(%4)", op
);
12606 /* Perform vcall adjustment. */
12609 if (CONST_OK_FOR_J (vcall_offset
))
12611 output_asm_insn ("l\t%4,0(%1)", op
);
12612 output_asm_insn ("a\t%1,%3(%4)", op
);
12614 else if (DISP_IN_RANGE (vcall_offset
))
12616 output_asm_insn ("l\t%4,0(%1)", op
);
12617 output_asm_insn ("ay\t%1,%3(%4)", op
);
12619 else if (CONST_OK_FOR_K (vcall_offset
))
12621 output_asm_insn ("lhi\t%4,%3", op
);
12622 output_asm_insn ("a\t%4,0(%1)", op
);
12623 output_asm_insn ("a\t%1,0(%4)", op
);
12625 else if (CONST_OK_FOR_Os (vcall_offset
))
12627 output_asm_insn ("iilf\t%4,%3", op
);
12628 output_asm_insn ("a\t%4,0(%1)", op
);
12629 output_asm_insn ("a\t%1,0(%4)", op
);
12633 op
[7] = gen_label_rtx ();
12634 output_asm_insn ("l\t%4,%7-%5(%4)", op
);
12635 output_asm_insn ("a\t%4,0(%1)", op
);
12636 output_asm_insn ("a\t%1,0(%4)", op
);
12639 /* We had to clobber the base pointer register.
12640 Re-setup the base pointer (with a different base). */
12641 op
[5] = gen_label_rtx ();
12642 output_asm_insn ("basr\t%4,0", op
);
12643 targetm
.asm_out
.internal_label (file
, "L",
12644 CODE_LABEL_NUMBER (op
[5]));
12647 /* Jump to target. */
12648 op
[8] = gen_label_rtx ();
12651 output_asm_insn ("l\t%4,%8-%5(%4)", op
);
12652 else if (!nonlocal
)
12653 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
12654 /* We cannot call through .plt, since .plt requires %r12 loaded. */
12655 else if (flag_pic
== 1)
12657 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
12658 output_asm_insn ("l\t%4,%0(%4)", op
);
12660 else if (flag_pic
== 2)
12662 op
[9] = gen_rtx_REG (Pmode
, 0);
12663 output_asm_insn ("l\t%9,%8-4-%5(%4)", op
);
12664 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
12665 output_asm_insn ("ar\t%4,%9", op
);
12666 output_asm_insn ("l\t%4,0(%4)", op
);
12669 output_asm_insn ("br\t%4", op
);
12671 /* Output literal pool. */
12672 output_asm_insn (".align\t4", op
);
12674 if (nonlocal
&& flag_pic
== 2)
12675 output_asm_insn (".long\t%0", op
);
12678 op
[0] = gen_rtx_SYMBOL_REF (Pmode
, "_GLOBAL_OFFSET_TABLE_");
12679 SYMBOL_REF_FLAGS (op
[0]) = SYMBOL_FLAG_LOCAL
;
12682 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[8]));
12684 output_asm_insn (".long\t%0", op
);
12686 output_asm_insn (".long\t%0-%5", op
);
12690 targetm
.asm_out
.internal_label (file
, "L",
12691 CODE_LABEL_NUMBER (op
[6]));
12692 output_asm_insn (".long\t%2", op
);
12696 targetm
.asm_out
.internal_label (file
, "L",
12697 CODE_LABEL_NUMBER (op
[7]));
12698 output_asm_insn (".long\t%3", op
);
12701 final_end_function ();
12705 s390_valid_pointer_mode (machine_mode mode
)
12707 return (mode
== SImode
|| (TARGET_64BIT
&& mode
== DImode
));
12710 /* Checks whether the given CALL_EXPR would use a caller
12711 saved register. This is used to decide whether sibling call
12712 optimization could be performed on the respective function
12716 s390_call_saved_register_used (tree call_expr
)
12718 CUMULATIVE_ARGS cum_v
;
12719 cumulative_args_t cum
;
12726 INIT_CUMULATIVE_ARGS (cum_v
, NULL
, NULL
, 0, 0);
12727 cum
= pack_cumulative_args (&cum_v
);
12729 for (i
= 0; i
< call_expr_nargs (call_expr
); i
++)
12731 parameter
= CALL_EXPR_ARG (call_expr
, i
);
12732 gcc_assert (parameter
);
12734 /* For an undeclared variable passed as parameter we will get
12735 an ERROR_MARK node here. */
12736 if (TREE_CODE (parameter
) == ERROR_MARK
)
12739 type
= TREE_TYPE (parameter
);
12742 mode
= TYPE_MODE (type
);
12745 /* We assume that in the target function all parameters are
12746 named. This only has an impact on vector argument register
12747 usage none of which is call-saved. */
12748 if (pass_by_reference (&cum_v
, mode
, type
, true))
12751 type
= build_pointer_type (type
);
12754 parm_rtx
= s390_function_arg (cum
, mode
, type
, true);
12756 s390_function_arg_advance (cum
, mode
, type
, true);
12761 if (REG_P (parm_rtx
))
12764 reg
< HARD_REGNO_NREGS (REGNO (parm_rtx
), GET_MODE (parm_rtx
));
12766 if (!call_used_regs
[reg
+ REGNO (parm_rtx
)])
12770 if (GET_CODE (parm_rtx
) == PARALLEL
)
12774 for (i
= 0; i
< XVECLEN (parm_rtx
, 0); i
++)
12776 rtx r
= XEXP (XVECEXP (parm_rtx
, 0, i
), 0);
12778 gcc_assert (REG_P (r
));
12781 reg
< HARD_REGNO_NREGS (REGNO (r
), GET_MODE (r
));
12783 if (!call_used_regs
[reg
+ REGNO (r
)])
12792 /* Return true if the given call expression can be
12793 turned into a sibling call.
12794 DECL holds the declaration of the function to be called whereas
12795 EXP is the call expression itself. */
12798 s390_function_ok_for_sibcall (tree decl
, tree exp
)
12800 /* The TPF epilogue uses register 1. */
12801 if (TARGET_TPF_PROFILING
)
12804 /* The 31 bit PLT code uses register 12 (GOT pointer - caller saved)
12805 which would have to be restored before the sibcall. */
12806 if (!TARGET_64BIT
&& flag_pic
&& decl
&& !targetm
.binds_local_p (decl
))
12809 /* Register 6 on s390 is available as an argument register but unfortunately
12810 "caller saved". This makes functions needing this register for arguments
12811 not suitable for sibcalls. */
12812 return !s390_call_saved_register_used (exp
);
12815 /* Return the fixed registers used for condition codes. */
12818 s390_fixed_condition_code_regs (unsigned int *p1
, unsigned int *p2
)
12821 *p2
= INVALID_REGNUM
;
12826 /* This function is used by the call expanders of the machine description.
12827 It emits the call insn itself together with the necessary operations
12828 to adjust the target address and returns the emitted insn.
12829 ADDR_LOCATION is the target address rtx
12830 TLS_CALL the location of the thread-local symbol
12831 RESULT_REG the register where the result of the call should be stored
12832 RETADDR_REG the register where the return address should be stored
12833 If this parameter is NULL_RTX the call is considered
12834 to be a sibling call. */
12837 s390_emit_call (rtx addr_location
, rtx tls_call
, rtx result_reg
,
12840 bool plt_call
= false;
12846 /* Direct function calls need special treatment. */
12847 if (GET_CODE (addr_location
) == SYMBOL_REF
)
12849 /* When calling a global routine in PIC mode, we must
12850 replace the symbol itself with the PLT stub. */
12851 if (flag_pic
&& !SYMBOL_REF_LOCAL_P (addr_location
))
12853 if (TARGET_64BIT
|| retaddr_reg
!= NULL_RTX
)
12855 addr_location
= gen_rtx_UNSPEC (Pmode
,
12856 gen_rtvec (1, addr_location
),
12858 addr_location
= gen_rtx_CONST (Pmode
, addr_location
);
12862 /* For -fpic code the PLT entries might use r12 which is
12863 call-saved. Therefore we cannot do a sibcall when
12864 calling directly using a symbol ref. When reaching
12865 this point we decided (in s390_function_ok_for_sibcall)
12866 to do a sibcall for a function pointer but one of the
12867 optimizers was able to get rid of the function pointer
12868 by propagating the symbol ref into the call. This
12869 optimization is illegal for S/390 so we turn the direct
12870 call into a indirect call again. */
12871 addr_location
= force_reg (Pmode
, addr_location
);
12874 /* Unless we can use the bras(l) insn, force the
12875 routine address into a register. */
12876 if (!TARGET_SMALL_EXEC
&& !TARGET_CPU_ZARCH
)
12879 addr_location
= legitimize_pic_address (addr_location
, 0);
12881 addr_location
= force_reg (Pmode
, addr_location
);
12885 /* If it is already an indirect call or the code above moved the
12886 SYMBOL_REF to somewhere else make sure the address can be found in
12888 if (retaddr_reg
== NULL_RTX
12889 && GET_CODE (addr_location
) != SYMBOL_REF
12892 emit_move_insn (gen_rtx_REG (Pmode
, SIBCALL_REGNUM
), addr_location
);
12893 addr_location
= gen_rtx_REG (Pmode
, SIBCALL_REGNUM
);
12896 addr_location
= gen_rtx_MEM (QImode
, addr_location
);
12897 call
= gen_rtx_CALL (VOIDmode
, addr_location
, const0_rtx
);
12899 if (result_reg
!= NULL_RTX
)
12900 call
= gen_rtx_SET (result_reg
, call
);
12902 if (retaddr_reg
!= NULL_RTX
)
12904 clobber
= gen_rtx_CLOBBER (VOIDmode
, retaddr_reg
);
12906 if (tls_call
!= NULL_RTX
)
12907 vec
= gen_rtvec (3, call
, clobber
,
12908 gen_rtx_USE (VOIDmode
, tls_call
));
12910 vec
= gen_rtvec (2, call
, clobber
);
12912 call
= gen_rtx_PARALLEL (VOIDmode
, vec
);
12915 insn
= emit_call_insn (call
);
12917 /* 31-bit PLT stubs and tls calls use the GOT register implicitly. */
12918 if ((!TARGET_64BIT
&& plt_call
) || tls_call
!= NULL_RTX
)
12920 /* s390_function_ok_for_sibcall should
12921 have denied sibcalls in this case. */
12922 gcc_assert (retaddr_reg
!= NULL_RTX
);
12923 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), gen_rtx_REG (Pmode
, 12));
12928 /* Implement TARGET_CONDITIONAL_REGISTER_USAGE. */
12931 s390_conditional_register_usage (void)
12937 fixed_regs
[PIC_OFFSET_TABLE_REGNUM
] = 1;
12938 call_used_regs
[PIC_OFFSET_TABLE_REGNUM
] = 1;
12940 if (TARGET_CPU_ZARCH
)
12942 fixed_regs
[BASE_REGNUM
] = 0;
12943 call_used_regs
[BASE_REGNUM
] = 0;
12944 fixed_regs
[RETURN_REGNUM
] = 0;
12945 call_used_regs
[RETURN_REGNUM
] = 0;
12949 for (i
= FPR8_REGNUM
; i
<= FPR15_REGNUM
; i
++)
12950 call_used_regs
[i
] = call_really_used_regs
[i
] = 0;
12954 call_used_regs
[FPR4_REGNUM
] = call_really_used_regs
[FPR4_REGNUM
] = 0;
12955 call_used_regs
[FPR6_REGNUM
] = call_really_used_regs
[FPR6_REGNUM
] = 0;
12958 if (TARGET_SOFT_FLOAT
)
12960 for (i
= FPR0_REGNUM
; i
<= FPR15_REGNUM
; i
++)
12961 call_used_regs
[i
] = fixed_regs
[i
] = 1;
12964 /* Disable v16 - v31 for non-vector target. */
12967 for (i
= VR16_REGNUM
; i
<= VR31_REGNUM
; i
++)
12968 fixed_regs
[i
] = call_used_regs
[i
] = call_really_used_regs
[i
] = 1;
12972 /* Corresponding function to eh_return expander. */
12974 static GTY(()) rtx s390_tpf_eh_return_symbol
;
12976 s390_emit_tpf_eh_return (rtx target
)
12981 if (!s390_tpf_eh_return_symbol
)
12982 s390_tpf_eh_return_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "__tpf_eh_return");
12984 reg
= gen_rtx_REG (Pmode
, 2);
12985 orig_ra
= gen_rtx_REG (Pmode
, 3);
12987 emit_move_insn (reg
, target
);
12988 emit_move_insn (orig_ra
, get_hard_reg_initial_val (Pmode
, RETURN_REGNUM
));
12989 insn
= s390_emit_call (s390_tpf_eh_return_symbol
, NULL_RTX
, reg
,
12990 gen_rtx_REG (Pmode
, RETURN_REGNUM
));
12991 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), reg
);
12992 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), orig_ra
);
12994 emit_move_insn (EH_RETURN_HANDLER_RTX
, reg
);
12997 /* Rework the prologue/epilogue to avoid saving/restoring
12998 registers unnecessarily. */
13001 s390_optimize_prologue (void)
13003 rtx_insn
*insn
, *new_insn
, *next_insn
;
13005 /* Do a final recompute of the frame-related data. */
13006 s390_optimize_register_info ();
13008 /* If all special registers are in fact used, there's nothing we
13009 can do, so no point in walking the insn list. */
13011 if (cfun_frame_layout
.first_save_gpr
<= BASE_REGNUM
13012 && cfun_frame_layout
.last_save_gpr
>= BASE_REGNUM
13013 && (TARGET_CPU_ZARCH
13014 || (cfun_frame_layout
.first_save_gpr
<= RETURN_REGNUM
13015 && cfun_frame_layout
.last_save_gpr
>= RETURN_REGNUM
)))
13018 /* Search for prologue/epilogue insns and replace them. */
13020 for (insn
= get_insns (); insn
; insn
= next_insn
)
13022 int first
, last
, off
;
13023 rtx set
, base
, offset
;
13026 next_insn
= NEXT_INSN (insn
);
13028 if (! NONJUMP_INSN_P (insn
) || ! RTX_FRAME_RELATED_P (insn
))
13031 pat
= PATTERN (insn
);
13033 /* Remove ldgr/lgdr instructions used for saving and restore
13034 GPRs if possible. */
13036 && GET_CODE (pat
) == SET
13037 && GET_MODE (SET_SRC (pat
)) == DImode
13038 && REG_P (SET_SRC (pat
))
13039 && REG_P (SET_DEST (pat
)))
13041 int src_regno
= REGNO (SET_SRC (pat
));
13042 int dest_regno
= REGNO (SET_DEST (pat
));
13046 if (!((GENERAL_REGNO_P (src_regno
) && FP_REGNO_P (dest_regno
))
13047 || (FP_REGNO_P (src_regno
) && GENERAL_REGNO_P (dest_regno
))))
13050 gpr_regno
= GENERAL_REGNO_P (src_regno
) ? src_regno
: dest_regno
;
13051 fpr_regno
= FP_REGNO_P (src_regno
) ? src_regno
: dest_regno
;
13053 /* GPR must be call-saved, FPR must be call-clobbered. */
13054 if (!call_really_used_regs
[fpr_regno
]
13055 || call_really_used_regs
[gpr_regno
])
13058 /* It must not happen that what we once saved in an FPR now
13059 needs a stack slot. */
13060 gcc_assert (cfun_gpr_save_slot (gpr_regno
) != SAVE_SLOT_STACK
);
13062 if (cfun_gpr_save_slot (gpr_regno
) == SAVE_SLOT_NONE
)
13064 remove_insn (insn
);
13069 if (GET_CODE (pat
) == PARALLEL
13070 && store_multiple_operation (pat
, VOIDmode
))
13072 set
= XVECEXP (pat
, 0, 0);
13073 first
= REGNO (SET_SRC (set
));
13074 last
= first
+ XVECLEN (pat
, 0) - 1;
13075 offset
= const0_rtx
;
13076 base
= eliminate_constant_term (XEXP (SET_DEST (set
), 0), &offset
);
13077 off
= INTVAL (offset
);
13079 if (GET_CODE (base
) != REG
|| off
< 0)
13081 if (cfun_frame_layout
.first_save_gpr
!= -1
13082 && (cfun_frame_layout
.first_save_gpr
< first
13083 || cfun_frame_layout
.last_save_gpr
> last
))
13085 if (REGNO (base
) != STACK_POINTER_REGNUM
13086 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
13088 if (first
> BASE_REGNUM
|| last
< BASE_REGNUM
)
13091 if (cfun_frame_layout
.first_save_gpr
!= -1)
13093 rtx s_pat
= save_gprs (base
,
13094 off
+ (cfun_frame_layout
.first_save_gpr
13095 - first
) * UNITS_PER_LONG
,
13096 cfun_frame_layout
.first_save_gpr
,
13097 cfun_frame_layout
.last_save_gpr
);
13098 new_insn
= emit_insn_before (s_pat
, insn
);
13099 INSN_ADDRESSES_NEW (new_insn
, -1);
13102 remove_insn (insn
);
13106 if (cfun_frame_layout
.first_save_gpr
== -1
13107 && GET_CODE (pat
) == SET
13108 && GENERAL_REG_P (SET_SRC (pat
))
13109 && GET_CODE (SET_DEST (pat
)) == MEM
)
13112 first
= REGNO (SET_SRC (set
));
13113 offset
= const0_rtx
;
13114 base
= eliminate_constant_term (XEXP (SET_DEST (set
), 0), &offset
);
13115 off
= INTVAL (offset
);
13117 if (GET_CODE (base
) != REG
|| off
< 0)
13119 if (REGNO (base
) != STACK_POINTER_REGNUM
13120 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
13123 remove_insn (insn
);
13127 if (GET_CODE (pat
) == PARALLEL
13128 && load_multiple_operation (pat
, VOIDmode
))
13130 set
= XVECEXP (pat
, 0, 0);
13131 first
= REGNO (SET_DEST (set
));
13132 last
= first
+ XVECLEN (pat
, 0) - 1;
13133 offset
= const0_rtx
;
13134 base
= eliminate_constant_term (XEXP (SET_SRC (set
), 0), &offset
);
13135 off
= INTVAL (offset
);
13137 if (GET_CODE (base
) != REG
|| off
< 0)
13140 if (cfun_frame_layout
.first_restore_gpr
!= -1
13141 && (cfun_frame_layout
.first_restore_gpr
< first
13142 || cfun_frame_layout
.last_restore_gpr
> last
))
13144 if (REGNO (base
) != STACK_POINTER_REGNUM
13145 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
13147 if (first
> BASE_REGNUM
|| last
< BASE_REGNUM
)
13150 if (cfun_frame_layout
.first_restore_gpr
!= -1)
13152 rtx rpat
= restore_gprs (base
,
13153 off
+ (cfun_frame_layout
.first_restore_gpr
13154 - first
) * UNITS_PER_LONG
,
13155 cfun_frame_layout
.first_restore_gpr
,
13156 cfun_frame_layout
.last_restore_gpr
);
13158 /* Remove REG_CFA_RESTOREs for registers that we no
13159 longer need to save. */
13160 REG_NOTES (rpat
) = REG_NOTES (insn
);
13161 for (rtx
*ptr
= ®_NOTES (rpat
); *ptr
; )
13162 if (REG_NOTE_KIND (*ptr
) == REG_CFA_RESTORE
13163 && ((int) REGNO (XEXP (*ptr
, 0))
13164 < cfun_frame_layout
.first_restore_gpr
))
13165 *ptr
= XEXP (*ptr
, 1);
13167 ptr
= &XEXP (*ptr
, 1);
13168 new_insn
= emit_insn_before (rpat
, insn
);
13169 RTX_FRAME_RELATED_P (new_insn
) = 1;
13170 INSN_ADDRESSES_NEW (new_insn
, -1);
13173 remove_insn (insn
);
13177 if (cfun_frame_layout
.first_restore_gpr
== -1
13178 && GET_CODE (pat
) == SET
13179 && GENERAL_REG_P (SET_DEST (pat
))
13180 && GET_CODE (SET_SRC (pat
)) == MEM
)
13183 first
= REGNO (SET_DEST (set
));
13184 offset
= const0_rtx
;
13185 base
= eliminate_constant_term (XEXP (SET_SRC (set
), 0), &offset
);
13186 off
= INTVAL (offset
);
13188 if (GET_CODE (base
) != REG
|| off
< 0)
13191 if (REGNO (base
) != STACK_POINTER_REGNUM
13192 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
13195 remove_insn (insn
);
13201 /* On z10 and later the dynamic branch prediction must see the
13202 backward jump within a certain windows. If not it falls back to
13203 the static prediction. This function rearranges the loop backward
13204 branch in a way which makes the static prediction always correct.
13205 The function returns true if it added an instruction. */
13207 s390_fix_long_loop_prediction (rtx_insn
*insn
)
13209 rtx set
= single_set (insn
);
13210 rtx code_label
, label_ref
, new_label
;
13211 rtx_insn
*uncond_jump
;
13212 rtx_insn
*cur_insn
;
13216 /* This will exclude branch on count and branch on index patterns
13217 since these are correctly statically predicted. */
13219 || SET_DEST (set
) != pc_rtx
13220 || GET_CODE (SET_SRC(set
)) != IF_THEN_ELSE
)
13223 /* Skip conditional returns. */
13224 if (ANY_RETURN_P (XEXP (SET_SRC (set
), 1))
13225 && XEXP (SET_SRC (set
), 2) == pc_rtx
)
13228 label_ref
= (GET_CODE (XEXP (SET_SRC (set
), 1)) == LABEL_REF
?
13229 XEXP (SET_SRC (set
), 1) : XEXP (SET_SRC (set
), 2));
13231 gcc_assert (GET_CODE (label_ref
) == LABEL_REF
);
13233 code_label
= XEXP (label_ref
, 0);
13235 if (INSN_ADDRESSES (INSN_UID (code_label
)) == -1
13236 || INSN_ADDRESSES (INSN_UID (insn
)) == -1
13237 || (INSN_ADDRESSES (INSN_UID (insn
))
13238 - INSN_ADDRESSES (INSN_UID (code_label
)) < PREDICT_DISTANCE
))
13241 for (distance
= 0, cur_insn
= PREV_INSN (insn
);
13242 distance
< PREDICT_DISTANCE
- 6;
13243 distance
+= get_attr_length (cur_insn
), cur_insn
= PREV_INSN (cur_insn
))
13244 if (!cur_insn
|| JUMP_P (cur_insn
) || LABEL_P (cur_insn
))
13247 new_label
= gen_label_rtx ();
13248 uncond_jump
= emit_jump_insn_after (
13249 gen_rtx_SET (pc_rtx
,
13250 gen_rtx_LABEL_REF (VOIDmode
, code_label
)),
13252 emit_label_after (new_label
, uncond_jump
);
13254 tmp
= XEXP (SET_SRC (set
), 1);
13255 XEXP (SET_SRC (set
), 1) = XEXP (SET_SRC (set
), 2);
13256 XEXP (SET_SRC (set
), 2) = tmp
;
13257 INSN_CODE (insn
) = -1;
13259 XEXP (label_ref
, 0) = new_label
;
13260 JUMP_LABEL (insn
) = new_label
;
13261 JUMP_LABEL (uncond_jump
) = code_label
;
13266 /* Returns 1 if INSN reads the value of REG for purposes not related
13267 to addressing of memory, and 0 otherwise. */
13269 s390_non_addr_reg_read_p (rtx reg
, rtx_insn
*insn
)
13271 return reg_referenced_p (reg
, PATTERN (insn
))
13272 && !reg_used_in_mem_p (REGNO (reg
), PATTERN (insn
));
13275 /* Starting from INSN find_cond_jump looks downwards in the insn
13276 stream for a single jump insn which is the last user of the
13277 condition code set in INSN. */
13279 find_cond_jump (rtx_insn
*insn
)
13281 for (; insn
; insn
= NEXT_INSN (insn
))
13285 if (LABEL_P (insn
))
13288 if (!JUMP_P (insn
))
13290 if (reg_mentioned_p (gen_rtx_REG (CCmode
, CC_REGNUM
), insn
))
13295 /* This will be triggered by a return. */
13296 if (GET_CODE (PATTERN (insn
)) != SET
)
13299 gcc_assert (SET_DEST (PATTERN (insn
)) == pc_rtx
);
13300 ite
= SET_SRC (PATTERN (insn
));
13302 if (GET_CODE (ite
) != IF_THEN_ELSE
)
13305 cc
= XEXP (XEXP (ite
, 0), 0);
13306 if (!REG_P (cc
) || !CC_REGNO_P (REGNO (cc
)))
13309 if (find_reg_note (insn
, REG_DEAD
, cc
))
13317 /* Swap the condition in COND and the operands in OP0 and OP1 so that
13318 the semantics does not change. If NULL_RTX is passed as COND the
13319 function tries to find the conditional jump starting with INSN. */
13321 s390_swap_cmp (rtx cond
, rtx
*op0
, rtx
*op1
, rtx_insn
*insn
)
13325 if (cond
== NULL_RTX
)
13327 rtx_insn
*jump
= find_cond_jump (NEXT_INSN (insn
));
13328 rtx set
= jump
? single_set (jump
) : NULL_RTX
;
13330 if (set
== NULL_RTX
)
13333 cond
= XEXP (SET_SRC (set
), 0);
13338 PUT_CODE (cond
, swap_condition (GET_CODE (cond
)));
13341 /* On z10, instructions of the compare-and-branch family have the
13342 property to access the register occurring as second operand with
13343 its bits complemented. If such a compare is grouped with a second
13344 instruction that accesses the same register non-complemented, and
13345 if that register's value is delivered via a bypass, then the
13346 pipeline recycles, thereby causing significant performance decline.
13347 This function locates such situations and exchanges the two
13348 operands of the compare. The function return true whenever it
13351 s390_z10_optimize_cmp (rtx_insn
*insn
)
13353 rtx_insn
*prev_insn
, *next_insn
;
13354 bool insn_added_p
= false;
13355 rtx cond
, *op0
, *op1
;
13357 if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
13359 /* Handle compare and branch and branch on count
13361 rtx pattern
= single_set (insn
);
13364 || SET_DEST (pattern
) != pc_rtx
13365 || GET_CODE (SET_SRC (pattern
)) != IF_THEN_ELSE
)
13368 cond
= XEXP (SET_SRC (pattern
), 0);
13369 op0
= &XEXP (cond
, 0);
13370 op1
= &XEXP (cond
, 1);
13372 else if (GET_CODE (PATTERN (insn
)) == SET
)
13376 /* Handle normal compare instructions. */
13377 src
= SET_SRC (PATTERN (insn
));
13378 dest
= SET_DEST (PATTERN (insn
));
13381 || !CC_REGNO_P (REGNO (dest
))
13382 || GET_CODE (src
) != COMPARE
)
13385 /* s390_swap_cmp will try to find the conditional
13386 jump when passing NULL_RTX as condition. */
13388 op0
= &XEXP (src
, 0);
13389 op1
= &XEXP (src
, 1);
13394 if (!REG_P (*op0
) || !REG_P (*op1
))
13397 if (GET_MODE_CLASS (GET_MODE (*op0
)) != MODE_INT
)
13400 /* Swap the COMPARE arguments and its mask if there is a
13401 conflicting access in the previous insn. */
13402 prev_insn
= prev_active_insn (insn
);
13403 if (prev_insn
!= NULL_RTX
&& INSN_P (prev_insn
)
13404 && reg_referenced_p (*op1
, PATTERN (prev_insn
)))
13405 s390_swap_cmp (cond
, op0
, op1
, insn
);
13407 /* Check if there is a conflict with the next insn. If there
13408 was no conflict with the previous insn, then swap the
13409 COMPARE arguments and its mask. If we already swapped
13410 the operands, or if swapping them would cause a conflict
13411 with the previous insn, issue a NOP after the COMPARE in
13412 order to separate the two instuctions. */
13413 next_insn
= next_active_insn (insn
);
13414 if (next_insn
!= NULL_RTX
&& INSN_P (next_insn
)
13415 && s390_non_addr_reg_read_p (*op1
, next_insn
))
13417 if (prev_insn
!= NULL_RTX
&& INSN_P (prev_insn
)
13418 && s390_non_addr_reg_read_p (*op0
, prev_insn
))
13420 if (REGNO (*op1
) == 0)
13421 emit_insn_after (gen_nop1 (), insn
);
13423 emit_insn_after (gen_nop (), insn
);
13424 insn_added_p
= true;
13427 s390_swap_cmp (cond
, op0
, op1
, insn
);
13429 return insn_added_p
;
13432 /* Perform machine-dependent processing. */
13437 bool pool_overflow
= false;
13438 int hw_before
, hw_after
;
13440 /* Make sure all splits have been performed; splits after
13441 machine_dependent_reorg might confuse insn length counts. */
13442 split_all_insns_noflow ();
13444 /* Install the main literal pool and the associated base
13445 register load insns.
13447 In addition, there are two problematic situations we need
13450 - the literal pool might be > 4096 bytes in size, so that
13451 some of its elements cannot be directly accessed
13453 - a branch target might be > 64K away from the branch, so that
13454 it is not possible to use a PC-relative instruction.
13456 To fix those, we split the single literal pool into multiple
13457 pool chunks, reloading the pool base register at various
13458 points throughout the function to ensure it always points to
13459 the pool chunk the following code expects, and / or replace
13460 PC-relative branches by absolute branches.
13462 However, the two problems are interdependent: splitting the
13463 literal pool can move a branch further away from its target,
13464 causing the 64K limit to overflow, and on the other hand,
13465 replacing a PC-relative branch by an absolute branch means
13466 we need to put the branch target address into the literal
13467 pool, possibly causing it to overflow.
13469 So, we loop trying to fix up both problems until we manage
13470 to satisfy both conditions at the same time. Note that the
13471 loop is guaranteed to terminate as every pass of the loop
13472 strictly decreases the total number of PC-relative branches
13473 in the function. (This is not completely true as there
13474 might be branch-over-pool insns introduced by chunkify_start.
13475 Those never need to be split however.) */
13479 struct constant_pool
*pool
= NULL
;
13481 /* Collect the literal pool. */
13482 if (!pool_overflow
)
13484 pool
= s390_mainpool_start ();
13486 pool_overflow
= true;
13489 /* If literal pool overflowed, start to chunkify it. */
13491 pool
= s390_chunkify_start ();
13493 /* Split out-of-range branches. If this has created new
13494 literal pool entries, cancel current chunk list and
13495 recompute it. zSeries machines have large branch
13496 instructions, so we never need to split a branch. */
13497 if (!TARGET_CPU_ZARCH
&& s390_split_branches ())
13500 s390_chunkify_cancel (pool
);
13502 s390_mainpool_cancel (pool
);
13507 /* If we made it up to here, both conditions are satisfied.
13508 Finish up literal pool related changes. */
13510 s390_chunkify_finish (pool
);
13512 s390_mainpool_finish (pool
);
13514 /* We're done splitting branches. */
13515 cfun
->machine
->split_branches_pending_p
= false;
13519 /* Generate out-of-pool execute target insns. */
13520 if (TARGET_CPU_ZARCH
)
13522 rtx_insn
*insn
, *target
;
13525 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
13527 label
= s390_execute_label (insn
);
13531 gcc_assert (label
!= const0_rtx
);
13533 target
= emit_label (XEXP (label
, 0));
13534 INSN_ADDRESSES_NEW (target
, -1);
13536 target
= emit_insn (s390_execute_target (insn
));
13537 INSN_ADDRESSES_NEW (target
, -1);
13541 /* Try to optimize prologue and epilogue further. */
13542 s390_optimize_prologue ();
13544 /* Walk over the insns and do some >=z10 specific changes. */
13545 if (s390_tune
>= PROCESSOR_2097_Z10
)
13548 bool insn_added_p
= false;
13550 /* The insn lengths and addresses have to be up to date for the
13551 following manipulations. */
13552 shorten_branches (get_insns ());
13554 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
13556 if (!INSN_P (insn
) || INSN_CODE (insn
) <= 0)
13560 insn_added_p
|= s390_fix_long_loop_prediction (insn
);
13562 if ((GET_CODE (PATTERN (insn
)) == PARALLEL
13563 || GET_CODE (PATTERN (insn
)) == SET
)
13564 && s390_tune
== PROCESSOR_2097_Z10
)
13565 insn_added_p
|= s390_z10_optimize_cmp (insn
);
13568 /* Adjust branches if we added new instructions. */
13570 shorten_branches (get_insns ());
13573 s390_function_num_hotpatch_hw (current_function_decl
, &hw_before
, &hw_after
);
13578 /* Insert NOPs for hotpatching. */
13579 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
13581 1. inside the area covered by debug information to allow setting
13582 breakpoints at the NOPs,
13583 2. before any insn which results in an asm instruction,
13584 3. before in-function labels to avoid jumping to the NOPs, for
13585 example as part of a loop,
13586 4. before any barrier in case the function is completely empty
13587 (__builtin_unreachable ()) and has neither internal labels nor
13590 if (active_insn_p (insn
) || BARRIER_P (insn
) || LABEL_P (insn
))
13592 /* Output a series of NOPs before the first active insn. */
13593 while (insn
&& hw_after
> 0)
13595 if (hw_after
>= 3 && TARGET_CPU_ZARCH
)
13597 emit_insn_before (gen_nop_6_byte (), insn
);
13600 else if (hw_after
>= 2)
13602 emit_insn_before (gen_nop_4_byte (), insn
);
13607 emit_insn_before (gen_nop_2_byte (), insn
);
13614 /* Return true if INSN is a fp load insn writing register REGNO. */
13616 s390_fpload_toreg (rtx_insn
*insn
, unsigned int regno
)
13619 enum attr_type flag
= s390_safe_attr_type (insn
);
13621 if (flag
!= TYPE_FLOADSF
&& flag
!= TYPE_FLOADDF
)
13624 set
= single_set (insn
);
13626 if (set
== NULL_RTX
)
13629 if (!REG_P (SET_DEST (set
)) || !MEM_P (SET_SRC (set
)))
13632 if (REGNO (SET_DEST (set
)) != regno
)
13638 /* This value describes the distance to be avoided between an
13639 aritmetic fp instruction and an fp load writing the same register.
13640 Z10_EARLYLOAD_DISTANCE - 1 as well as Z10_EARLYLOAD_DISTANCE + 1 is
13641 fine but the exact value has to be avoided. Otherwise the FP
13642 pipeline will throw an exception causing a major penalty. */
13643 #define Z10_EARLYLOAD_DISTANCE 7
13645 /* Rearrange the ready list in order to avoid the situation described
13646 for Z10_EARLYLOAD_DISTANCE. A problematic load instruction is
13647 moved to the very end of the ready list. */
13649 s390_z10_prevent_earlyload_conflicts (rtx_insn
**ready
, int *nready_p
)
13651 unsigned int regno
;
13652 int nready
= *nready_p
;
13657 enum attr_type flag
;
13660 /* Skip DISTANCE - 1 active insns. */
13661 for (insn
= last_scheduled_insn
, distance
= Z10_EARLYLOAD_DISTANCE
- 1;
13662 distance
> 0 && insn
!= NULL_RTX
;
13663 distance
--, insn
= prev_active_insn (insn
))
13664 if (CALL_P (insn
) || JUMP_P (insn
))
13667 if (insn
== NULL_RTX
)
13670 set
= single_set (insn
);
13672 if (set
== NULL_RTX
|| !REG_P (SET_DEST (set
))
13673 || GET_MODE_CLASS (GET_MODE (SET_DEST (set
))) != MODE_FLOAT
)
13676 flag
= s390_safe_attr_type (insn
);
13678 if (flag
== TYPE_FLOADSF
|| flag
== TYPE_FLOADDF
)
13681 regno
= REGNO (SET_DEST (set
));
13684 while (!s390_fpload_toreg (ready
[i
], regno
) && i
> 0)
13691 memmove (&ready
[1], &ready
[0], sizeof (rtx_insn
*) * i
);
13696 /* The s390_sched_state variable tracks the state of the current or
13697 the last instruction group.
13699 0,1,2 number of instructions scheduled in the current group
13700 3 the last group is complete - normal insns
13701 4 the last group was a cracked/expanded insn */
13703 static int s390_sched_state
;
13705 #define S390_SCHED_STATE_NORMAL 3
13706 #define S390_SCHED_STATE_CRACKED 4
13708 #define S390_SCHED_ATTR_MASK_CRACKED 0x1
13709 #define S390_SCHED_ATTR_MASK_EXPANDED 0x2
13710 #define S390_SCHED_ATTR_MASK_ENDGROUP 0x4
13711 #define S390_SCHED_ATTR_MASK_GROUPALONE 0x8
13713 static unsigned int
13714 s390_get_sched_attrmask (rtx_insn
*insn
)
13716 unsigned int mask
= 0;
13720 case PROCESSOR_2827_ZEC12
:
13721 if (get_attr_zEC12_cracked (insn
))
13722 mask
|= S390_SCHED_ATTR_MASK_CRACKED
;
13723 if (get_attr_zEC12_expanded (insn
))
13724 mask
|= S390_SCHED_ATTR_MASK_EXPANDED
;
13725 if (get_attr_zEC12_endgroup (insn
))
13726 mask
|= S390_SCHED_ATTR_MASK_ENDGROUP
;
13727 if (get_attr_zEC12_groupalone (insn
))
13728 mask
|= S390_SCHED_ATTR_MASK_GROUPALONE
;
13730 case PROCESSOR_2964_Z13
:
13731 if (get_attr_z13_cracked (insn
))
13732 mask
|= S390_SCHED_ATTR_MASK_CRACKED
;
13733 if (get_attr_z13_expanded (insn
))
13734 mask
|= S390_SCHED_ATTR_MASK_EXPANDED
;
13735 if (get_attr_z13_endgroup (insn
))
13736 mask
|= S390_SCHED_ATTR_MASK_ENDGROUP
;
13737 if (get_attr_z13_groupalone (insn
))
13738 mask
|= S390_SCHED_ATTR_MASK_GROUPALONE
;
13741 gcc_unreachable ();
13746 static unsigned int
13747 s390_get_unit_mask (rtx_insn
*insn
, int *units
)
13749 unsigned int mask
= 0;
13753 case PROCESSOR_2964_Z13
:
13755 if (get_attr_z13_unit_lsu (insn
))
13757 if (get_attr_z13_unit_fxu (insn
))
13759 if (get_attr_z13_unit_vfu (insn
))
13763 gcc_unreachable ();
13768 /* Return the scheduling score for INSN. The higher the score the
13769 better. The score is calculated from the OOO scheduling attributes
13770 of INSN and the scheduling state s390_sched_state. */
13772 s390_sched_score (rtx_insn
*insn
)
13774 unsigned int mask
= s390_get_sched_attrmask (insn
);
13777 switch (s390_sched_state
)
13780 /* Try to put insns into the first slot which would otherwise
13782 if ((mask
& S390_SCHED_ATTR_MASK_CRACKED
) != 0
13783 || (mask
& S390_SCHED_ATTR_MASK_EXPANDED
) != 0)
13785 if ((mask
& S390_SCHED_ATTR_MASK_GROUPALONE
) != 0)
13788 /* Prefer not cracked insns while trying to put together a
13790 if ((mask
& S390_SCHED_ATTR_MASK_CRACKED
) == 0
13791 && (mask
& S390_SCHED_ATTR_MASK_EXPANDED
) == 0
13792 && (mask
& S390_SCHED_ATTR_MASK_GROUPALONE
) == 0)
13794 if ((mask
& S390_SCHED_ATTR_MASK_ENDGROUP
) == 0)
13798 /* Prefer not cracked insns while trying to put together a
13800 if ((mask
& S390_SCHED_ATTR_MASK_CRACKED
) == 0
13801 && (mask
& S390_SCHED_ATTR_MASK_EXPANDED
) == 0
13802 && (mask
& S390_SCHED_ATTR_MASK_GROUPALONE
) == 0)
13804 /* Prefer endgroup insns in the last slot. */
13805 if ((mask
& S390_SCHED_ATTR_MASK_ENDGROUP
) != 0)
13808 case S390_SCHED_STATE_NORMAL
:
13809 /* Prefer not cracked insns if the last was not cracked. */
13810 if ((mask
& S390_SCHED_ATTR_MASK_CRACKED
) == 0
13811 && (mask
& S390_SCHED_ATTR_MASK_EXPANDED
) == 0)
13813 if ((mask
& S390_SCHED_ATTR_MASK_GROUPALONE
) != 0)
13816 case S390_SCHED_STATE_CRACKED
:
13817 /* Try to keep cracked insns together to prevent them from
13818 interrupting groups. */
13819 if ((mask
& S390_SCHED_ATTR_MASK_CRACKED
) != 0
13820 || (mask
& S390_SCHED_ATTR_MASK_EXPANDED
) != 0)
13825 if (s390_tune
== PROCESSOR_2964_Z13
)
13828 unsigned unit_mask
, m
= 1;
13830 unit_mask
= s390_get_unit_mask (insn
, &units
);
13831 gcc_assert (units
<= MAX_SCHED_UNITS
);
13833 /* Add a score in range 0..MAX_SCHED_MIX_SCORE depending on how long
13834 ago the last insn of this unit type got scheduled. This is
13835 supposed to help providing a proper instruction mix to the
13837 for (i
= 0; i
< units
; i
++, m
<<= 1)
13839 score
+= (last_scheduled_unit_distance
[i
] * MAX_SCHED_MIX_SCORE
/
13840 MAX_SCHED_MIX_DISTANCE
);
13845 /* This function is called via hook TARGET_SCHED_REORDER before
13846 issuing one insn from list READY which contains *NREADYP entries.
13847 For target z10 it reorders load instructions to avoid early load
13848 conflicts in the floating point pipeline */
13850 s390_sched_reorder (FILE *file
, int verbose
,
13851 rtx_insn
**ready
, int *nreadyp
, int clock ATTRIBUTE_UNUSED
)
13853 if (s390_tune
== PROCESSOR_2097_Z10
13854 && reload_completed
13856 s390_z10_prevent_earlyload_conflicts (ready
, nreadyp
);
13858 if (s390_tune
>= PROCESSOR_2827_ZEC12
13859 && reload_completed
13863 int last_index
= *nreadyp
- 1;
13864 int max_index
= -1;
13865 int max_score
= -1;
13868 /* Just move the insn with the highest score to the top (the
13869 end) of the list. A full sort is not needed since a conflict
13870 in the hazard recognition cannot happen. So the top insn in
13871 the ready list will always be taken. */
13872 for (i
= last_index
; i
>= 0; i
--)
13876 if (recog_memoized (ready
[i
]) < 0)
13879 score
= s390_sched_score (ready
[i
]);
13880 if (score
> max_score
)
13887 if (max_index
!= -1)
13889 if (max_index
!= last_index
)
13891 tmp
= ready
[max_index
];
13892 ready
[max_index
] = ready
[last_index
];
13893 ready
[last_index
] = tmp
;
13897 ";;\t\tBACKEND: move insn %d to the top of list\n",
13898 INSN_UID (ready
[last_index
]));
13900 else if (verbose
> 5)
13902 ";;\t\tBACKEND: best insn %d already on top\n",
13903 INSN_UID (ready
[last_index
]));
13908 fprintf (file
, "ready list ooo attributes - sched state: %d\n",
13911 for (i
= last_index
; i
>= 0; i
--)
13913 unsigned int sched_mask
;
13914 rtx_insn
*insn
= ready
[i
];
13916 if (recog_memoized (insn
) < 0)
13919 sched_mask
= s390_get_sched_attrmask (insn
);
13920 fprintf (file
, ";;\t\tBACKEND: insn %d score: %d: ",
13922 s390_sched_score (insn
));
13923 #define PRINT_SCHED_ATTR(M, ATTR) fprintf (file, "%s ",\
13924 ((M) & sched_mask) ? #ATTR : "");
13925 PRINT_SCHED_ATTR (S390_SCHED_ATTR_MASK_CRACKED
, cracked
);
13926 PRINT_SCHED_ATTR (S390_SCHED_ATTR_MASK_EXPANDED
, expanded
);
13927 PRINT_SCHED_ATTR (S390_SCHED_ATTR_MASK_ENDGROUP
, endgroup
);
13928 PRINT_SCHED_ATTR (S390_SCHED_ATTR_MASK_GROUPALONE
, groupalone
);
13929 #undef PRINT_SCHED_ATTR
13930 if (s390_tune
== PROCESSOR_2964_Z13
)
13932 unsigned int unit_mask
, m
= 1;
13935 unit_mask
= s390_get_unit_mask (insn
, &units
);
13936 fprintf (file
, "(units:");
13937 for (j
= 0; j
< units
; j
++, m
<<= 1)
13939 fprintf (file
, " u%d", j
);
13940 fprintf (file
, ")");
13942 fprintf (file
, "\n");
13947 return s390_issue_rate ();
13951 /* This function is called via hook TARGET_SCHED_VARIABLE_ISSUE after
13952 the scheduler has issued INSN. It stores the last issued insn into
13953 last_scheduled_insn in order to make it available for
13954 s390_sched_reorder. */
13956 s390_sched_variable_issue (FILE *file
, int verbose
, rtx_insn
*insn
, int more
)
13958 last_scheduled_insn
= insn
;
13960 if (s390_tune
>= PROCESSOR_2827_ZEC12
13961 && reload_completed
13962 && recog_memoized (insn
) >= 0)
13964 unsigned int mask
= s390_get_sched_attrmask (insn
);
13966 if ((mask
& S390_SCHED_ATTR_MASK_CRACKED
) != 0
13967 || (mask
& S390_SCHED_ATTR_MASK_EXPANDED
) != 0)
13968 s390_sched_state
= S390_SCHED_STATE_CRACKED
;
13969 else if ((mask
& S390_SCHED_ATTR_MASK_ENDGROUP
) != 0
13970 || (mask
& S390_SCHED_ATTR_MASK_GROUPALONE
) != 0)
13971 s390_sched_state
= S390_SCHED_STATE_NORMAL
;
13974 /* Only normal insns are left (mask == 0). */
13975 switch (s390_sched_state
)
13980 case S390_SCHED_STATE_NORMAL
:
13981 if (s390_sched_state
== S390_SCHED_STATE_NORMAL
)
13982 s390_sched_state
= 1;
13984 s390_sched_state
++;
13987 case S390_SCHED_STATE_CRACKED
:
13988 s390_sched_state
= S390_SCHED_STATE_NORMAL
;
13993 if (s390_tune
== PROCESSOR_2964_Z13
)
13996 unsigned unit_mask
, m
= 1;
13998 unit_mask
= s390_get_unit_mask (insn
, &units
);
13999 gcc_assert (units
<= MAX_SCHED_UNITS
);
14001 for (i
= 0; i
< units
; i
++, m
<<= 1)
14003 last_scheduled_unit_distance
[i
] = 0;
14004 else if (last_scheduled_unit_distance
[i
] < MAX_SCHED_MIX_DISTANCE
)
14005 last_scheduled_unit_distance
[i
]++;
14010 unsigned int sched_mask
;
14012 sched_mask
= s390_get_sched_attrmask (insn
);
14014 fprintf (file
, ";;\t\tBACKEND: insn %d: ", INSN_UID (insn
));
14015 #define PRINT_SCHED_ATTR(M, ATTR) fprintf (file, "%s ", ((M) & sched_mask) ? #ATTR : "");
14016 PRINT_SCHED_ATTR (S390_SCHED_ATTR_MASK_CRACKED
, cracked
);
14017 PRINT_SCHED_ATTR (S390_SCHED_ATTR_MASK_EXPANDED
, expanded
);
14018 PRINT_SCHED_ATTR (S390_SCHED_ATTR_MASK_ENDGROUP
, endgroup
);
14019 PRINT_SCHED_ATTR (S390_SCHED_ATTR_MASK_GROUPALONE
, groupalone
);
14020 #undef PRINT_SCHED_ATTR
14022 if (s390_tune
== PROCESSOR_2964_Z13
)
14024 unsigned int unit_mask
, m
= 1;
14027 unit_mask
= s390_get_unit_mask (insn
, &units
);
14028 fprintf (file
, "(units:");
14029 for (j
= 0; j
< units
; j
++, m
<<= 1)
14031 fprintf (file
, " %d", j
);
14032 fprintf (file
, ")");
14034 fprintf (file
, " sched state: %d\n", s390_sched_state
);
14036 if (s390_tune
== PROCESSOR_2964_Z13
)
14040 s390_get_unit_mask (insn
, &units
);
14042 fprintf (file
, ";;\t\tBACKEND: units unused for: ");
14043 for (j
= 0; j
< units
; j
++)
14044 fprintf (file
, "%d:%d ", j
, last_scheduled_unit_distance
[j
]);
14045 fprintf (file
, "\n");
14050 if (GET_CODE (PATTERN (insn
)) != USE
14051 && GET_CODE (PATTERN (insn
)) != CLOBBER
)
14058 s390_sched_init (FILE *file ATTRIBUTE_UNUSED
,
14059 int verbose ATTRIBUTE_UNUSED
,
14060 int max_ready ATTRIBUTE_UNUSED
)
14062 last_scheduled_insn
= NULL
;
14063 memset (last_scheduled_unit_distance
, 0, MAX_SCHED_UNITS
* sizeof (int));
14064 s390_sched_state
= 0;
14067 /* This target hook implementation for TARGET_LOOP_UNROLL_ADJUST calculates
14068 a new number struct loop *loop should be unrolled if tuned for cpus with
14069 a built-in stride prefetcher.
14070 The loop is analyzed for memory accesses by calling check_dpu for
14071 each rtx of the loop. Depending on the loop_depth and the amount of
14072 memory accesses a new number <=nunroll is returned to improve the
14073 behavior of the hardware prefetch unit. */
14075 s390_loop_unroll_adjust (unsigned nunroll
, struct loop
*loop
)
14080 unsigned mem_count
= 0;
14082 if (s390_tune
< PROCESSOR_2097_Z10
)
14085 /* Count the number of memory references within the loop body. */
14086 bbs
= get_loop_body (loop
);
14087 subrtx_iterator::array_type array
;
14088 for (i
= 0; i
< loop
->num_nodes
; i
++)
14089 FOR_BB_INSNS (bbs
[i
], insn
)
14090 if (INSN_P (insn
) && INSN_CODE (insn
) != -1)
14091 FOR_EACH_SUBRTX (iter
, array
, PATTERN (insn
), NONCONST
)
14096 /* Prevent division by zero, and we do not need to adjust nunroll in this case. */
14097 if (mem_count
== 0)
14100 switch (loop_depth(loop
))
14103 return MIN (nunroll
, 28 / mem_count
);
14105 return MIN (nunroll
, 22 / mem_count
);
14107 return MIN (nunroll
, 16 / mem_count
);
14111 /* Restore the current options. This is a hook function and also called
14115 s390_function_specific_restore (struct gcc_options
*opts
,
14116 struct cl_target_option
*ptr ATTRIBUTE_UNUSED
)
14118 opts
->x_s390_cost_pointer
= (long)processor_table
[opts
->x_s390_tune
].cost
;
14122 s390_option_override_internal (bool main_args_p
,
14123 struct gcc_options
*opts
,
14124 const struct gcc_options
*opts_set
)
14126 const char *prefix
;
14127 const char *suffix
;
14129 /* Set up prefix/suffix so the error messages refer to either the command
14130 line argument, or the attribute(target). */
14138 prefix
= "option(\"";
14143 /* Architecture mode defaults according to ABI. */
14144 if (!(opts_set
->x_target_flags
& MASK_ZARCH
))
14147 opts
->x_target_flags
|= MASK_ZARCH
;
14149 opts
->x_target_flags
&= ~MASK_ZARCH
;
14152 /* Set the march default in case it hasn't been specified on cmdline. */
14153 if (!opts_set
->x_s390_arch
)
14154 opts
->x_s390_arch
= PROCESSOR_2064_Z900
;
14155 else if (opts
->x_s390_arch
== PROCESSOR_9672_G5
14156 || opts
->x_s390_arch
== PROCESSOR_9672_G6
)
14157 warning (OPT_Wdeprecated
, "%sarch=%s%s is deprecated and will be removed "
14158 "in future releases; use at least %sarch=z900%s",
14159 prefix
, opts
->x_s390_arch
== PROCESSOR_9672_G5
? "g5" : "g6",
14160 suffix
, prefix
, suffix
);
14162 opts
->x_s390_arch_flags
= processor_flags_table
[(int) opts
->x_s390_arch
];
14164 /* Determine processor to tune for. */
14165 if (!opts_set
->x_s390_tune
)
14166 opts
->x_s390_tune
= opts
->x_s390_arch
;
14167 else if (opts
->x_s390_tune
== PROCESSOR_9672_G5
14168 || opts
->x_s390_tune
== PROCESSOR_9672_G6
)
14169 warning (OPT_Wdeprecated
, "%stune=%s%s is deprecated and will be removed "
14170 "in future releases; use at least %stune=z900%s",
14171 prefix
, opts
->x_s390_tune
== PROCESSOR_9672_G5
? "g5" : "g6",
14172 suffix
, prefix
, suffix
);
14174 opts
->x_s390_tune_flags
= processor_flags_table
[opts
->x_s390_tune
];
14176 /* Sanity checks. */
14177 if (opts
->x_s390_arch
== PROCESSOR_NATIVE
14178 || opts
->x_s390_tune
== PROCESSOR_NATIVE
)
14179 gcc_unreachable ();
14180 if (TARGET_ZARCH_P (opts
->x_target_flags
) && !TARGET_CPU_ZARCH_P (opts
))
14181 error ("z/Architecture mode not supported on %s",
14182 processor_table
[(int)opts
->x_s390_arch
].name
);
14183 if (TARGET_64BIT
&& !TARGET_ZARCH_P (opts
->x_target_flags
))
14184 error ("64-bit ABI not supported in ESA/390 mode");
14186 /* Enable hardware transactions if available and not explicitly
14187 disabled by user. E.g. with -m31 -march=zEC12 -mzarch */
14188 if (!TARGET_OPT_HTM_P (opts_set
->x_target_flags
))
14190 if (TARGET_CPU_HTM_P (opts
) && TARGET_ZARCH_P (opts
->x_target_flags
))
14191 opts
->x_target_flags
|= MASK_OPT_HTM
;
14193 opts
->x_target_flags
&= ~MASK_OPT_HTM
;
14196 if (TARGET_OPT_VX_P (opts_set
->x_target_flags
))
14198 if (TARGET_OPT_VX_P (opts
->x_target_flags
))
14200 if (!TARGET_CPU_VX_P (opts
))
14201 error ("hardware vector support not available on %s",
14202 processor_table
[(int)opts
->x_s390_arch
].name
);
14203 if (TARGET_SOFT_FLOAT_P (opts
->x_target_flags
))
14204 error ("hardware vector support not available with -msoft-float");
14209 if (TARGET_CPU_VX_P (opts
))
14210 /* Enable vector support if available and not explicitly disabled
14211 by user. E.g. with -m31 -march=z13 -mzarch */
14212 opts
->x_target_flags
|= MASK_OPT_VX
;
14214 opts
->x_target_flags
&= ~MASK_OPT_VX
;
14217 /* Use hardware DFP if available and not explicitly disabled by
14218 user. E.g. with -m31 -march=z10 -mzarch */
14219 if (!TARGET_HARD_DFP_P (opts_set
->x_target_flags
))
14221 if (TARGET_DFP_P (opts
))
14222 opts
->x_target_flags
|= MASK_HARD_DFP
;
14224 opts
->x_target_flags
&= ~MASK_HARD_DFP
;
14227 if (TARGET_HARD_DFP_P (opts
->x_target_flags
) && !TARGET_DFP_P (opts
))
14229 if (TARGET_HARD_DFP_P (opts_set
->x_target_flags
))
14231 if (!TARGET_CPU_DFP_P (opts
))
14232 error ("hardware decimal floating point instructions"
14233 " not available on %s",
14234 processor_table
[(int)opts
->x_s390_arch
].name
);
14235 if (!TARGET_ZARCH_P (opts
->x_target_flags
))
14236 error ("hardware decimal floating point instructions"
14237 " not available in ESA/390 mode");
14240 opts
->x_target_flags
&= ~MASK_HARD_DFP
;
14243 if (TARGET_SOFT_FLOAT_P (opts_set
->x_target_flags
)
14244 && TARGET_SOFT_FLOAT_P (opts
->x_target_flags
))
14246 if (TARGET_HARD_DFP_P (opts_set
->x_target_flags
)
14247 && TARGET_HARD_DFP_P (opts
->x_target_flags
))
14248 error ("-mhard-dfp can%'t be used in conjunction with -msoft-float");
14250 opts
->x_target_flags
&= ~MASK_HARD_DFP
;
14253 if (TARGET_BACKCHAIN_P (opts
->x_target_flags
)
14254 && TARGET_PACKED_STACK_P (opts
->x_target_flags
)
14255 && TARGET_HARD_FLOAT_P (opts
->x_target_flags
))
14256 error ("-mbackchain -mpacked-stack -mhard-float are not supported "
14259 if (opts
->x_s390_stack_size
)
14261 if (opts
->x_s390_stack_guard
>= opts
->x_s390_stack_size
)
14262 error ("stack size must be greater than the stack guard value");
14263 else if (opts
->x_s390_stack_size
> 1 << 16)
14264 error ("stack size must not be greater than 64k");
14266 else if (opts
->x_s390_stack_guard
)
14267 error ("-mstack-guard implies use of -mstack-size");
14269 #ifdef TARGET_DEFAULT_LONG_DOUBLE_128
14270 if (!TARGET_LONG_DOUBLE_128_P (opts_set
->x_target_flags
))
14271 opts
->x_target_flags
|= MASK_LONG_DOUBLE_128
;
14274 if (opts
->x_s390_tune
>= PROCESSOR_2097_Z10
)
14276 maybe_set_param_value (PARAM_MAX_UNROLLED_INSNS
, 100,
14277 opts
->x_param_values
,
14278 opts_set
->x_param_values
);
14279 maybe_set_param_value (PARAM_MAX_UNROLL_TIMES
, 32,
14280 opts
->x_param_values
,
14281 opts_set
->x_param_values
);
14282 maybe_set_param_value (PARAM_MAX_COMPLETELY_PEELED_INSNS
, 2000,
14283 opts
->x_param_values
,
14284 opts_set
->x_param_values
);
14285 maybe_set_param_value (PARAM_MAX_COMPLETELY_PEEL_TIMES
, 64,
14286 opts
->x_param_values
,
14287 opts_set
->x_param_values
);
14290 maybe_set_param_value (PARAM_MAX_PENDING_LIST_LENGTH
, 256,
14291 opts
->x_param_values
,
14292 opts_set
->x_param_values
);
14293 /* values for loop prefetching */
14294 maybe_set_param_value (PARAM_L1_CACHE_LINE_SIZE
, 256,
14295 opts
->x_param_values
,
14296 opts_set
->x_param_values
);
14297 maybe_set_param_value (PARAM_L1_CACHE_SIZE
, 128,
14298 opts
->x_param_values
,
14299 opts_set
->x_param_values
);
14300 /* s390 has more than 2 levels and the size is much larger. Since
14301 we are always running virtualized assume that we only get a small
14302 part of the caches above l1. */
14303 maybe_set_param_value (PARAM_L2_CACHE_SIZE
, 1500,
14304 opts
->x_param_values
,
14305 opts_set
->x_param_values
);
14306 maybe_set_param_value (PARAM_PREFETCH_MIN_INSN_TO_MEM_RATIO
, 2,
14307 opts
->x_param_values
,
14308 opts_set
->x_param_values
);
14309 maybe_set_param_value (PARAM_SIMULTANEOUS_PREFETCHES
, 6,
14310 opts
->x_param_values
,
14311 opts_set
->x_param_values
);
14313 /* Use the alternative scheduling-pressure algorithm by default. */
14314 maybe_set_param_value (PARAM_SCHED_PRESSURE_ALGORITHM
, 2,
14315 opts
->x_param_values
,
14316 opts_set
->x_param_values
);
14318 /* Call target specific restore function to do post-init work. At the moment,
14319 this just sets opts->x_s390_cost_pointer. */
14320 s390_function_specific_restore (opts
, NULL
);
14324 s390_option_override (void)
14327 cl_deferred_option
*opt
;
14328 vec
<cl_deferred_option
> *v
=
14329 (vec
<cl_deferred_option
> *) s390_deferred_options
;
14332 FOR_EACH_VEC_ELT (*v
, i
, opt
)
14334 switch (opt
->opt_index
)
14336 case OPT_mhotpatch_
:
14343 strncpy (s
, opt
->arg
, 256);
14345 t
= strchr (s
, ',');
14350 val1
= integral_argument (s
);
14351 val2
= integral_argument (t
);
14358 if (val1
== -1 || val2
== -1)
14360 /* argument is not a plain number */
14361 error ("arguments to %qs should be non-negative integers",
14365 else if (val1
> s390_hotpatch_hw_max
14366 || val2
> s390_hotpatch_hw_max
)
14368 error ("argument to %qs is too large (max. %d)",
14369 "-mhotpatch=n,m", s390_hotpatch_hw_max
);
14372 s390_hotpatch_hw_before_label
= val1
;
14373 s390_hotpatch_hw_after_label
= val2
;
14377 gcc_unreachable ();
14381 /* Set up function hooks. */
14382 init_machine_status
= s390_init_machine_status
;
14384 s390_option_override_internal (true, &global_options
, &global_options_set
);
14386 /* Save the initial options in case the user does function specific
14388 target_option_default_node
= build_target_option_node (&global_options
);
14389 target_option_current_node
= target_option_default_node
;
14391 /* This cannot reside in s390_option_optimization_table since HAVE_prefetch
14392 requires the arch flags to be evaluated already. Since prefetching
14393 is beneficial on s390, we enable it if available. */
14394 if (flag_prefetch_loop_arrays
< 0 && HAVE_prefetch
&& optimize
>= 3)
14395 flag_prefetch_loop_arrays
= 1;
14399 /* Don't emit DWARF3/4 unless specifically selected. The TPF
14400 debuggers do not yet support DWARF 3/4. */
14401 if (!global_options_set
.x_dwarf_strict
)
14403 if (!global_options_set
.x_dwarf_version
)
14407 /* Register a target-specific optimization-and-lowering pass
14408 to run immediately before prologue and epilogue generation.
14410 Registering the pass must be done at start up. It's
14411 convenient to do it here. */
14412 opt_pass
*new_pass
= new pass_s390_early_mach (g
);
14413 struct register_pass_info insert_pass_s390_early_mach
=
14415 new_pass
, /* pass */
14416 "pro_and_epilogue", /* reference_pass_name */
14417 1, /* ref_pass_instance_number */
14418 PASS_POS_INSERT_BEFORE
/* po_op */
14420 register_pass (&insert_pass_s390_early_mach
);
14423 #if S390_USE_TARGET_ATTRIBUTE
14424 /* Inner function to process the attribute((target(...))), take an argument and
14425 set the current options from the argument. If we have a list, recursively go
14429 s390_valid_target_attribute_inner_p (tree args
,
14430 struct gcc_options
*opts
,
14431 struct gcc_options
*new_opts_set
,
14437 #define S390_ATTRIB(S,O,A) { S, sizeof (S)-1, O, A, 0 }
14438 #define S390_PRAGMA(S,O,A) { S, sizeof (S)-1, O, A, 1 }
14439 static const struct
14441 const char *string
;
14445 int only_as_pragma
;
14448 S390_ATTRIB ("arch=", OPT_march_
, 1),
14449 S390_ATTRIB ("tune=", OPT_mtune_
, 1),
14450 /* uinteger options */
14451 S390_ATTRIB ("stack-guard=", OPT_mstack_guard_
, 1),
14452 S390_ATTRIB ("stack-size=", OPT_mstack_size_
, 1),
14453 S390_ATTRIB ("branch-cost=", OPT_mbranch_cost_
, 1),
14454 S390_ATTRIB ("warn-framesize=", OPT_mwarn_framesize_
, 1),
14456 S390_ATTRIB ("backchain", OPT_mbackchain
, 0),
14457 S390_ATTRIB ("hard-dfp", OPT_mhard_dfp
, 0),
14458 S390_ATTRIB ("hard-float", OPT_mhard_float
, 0),
14459 S390_ATTRIB ("htm", OPT_mhtm
, 0),
14460 S390_ATTRIB ("vx", OPT_mvx
, 0),
14461 S390_ATTRIB ("packed-stack", OPT_mpacked_stack
, 0),
14462 S390_ATTRIB ("small-exec", OPT_msmall_exec
, 0),
14463 S390_ATTRIB ("soft-float", OPT_msoft_float
, 0),
14464 S390_ATTRIB ("mvcle", OPT_mmvcle
, 0),
14465 S390_PRAGMA ("zvector", OPT_mzvector
, 0),
14466 /* boolean options */
14467 S390_ATTRIB ("warn-dynamicstack", OPT_mwarn_dynamicstack
, 0),
14472 /* If this is a list, recurse to get the options. */
14473 if (TREE_CODE (args
) == TREE_LIST
)
14476 int num_pragma_values
;
14479 /* Note: attribs.c:decl_attributes prepends the values from
14480 current_target_pragma to the list of target attributes. To determine
14481 whether we're looking at a value of the attribute or the pragma we
14482 assume that the first [list_length (current_target_pragma)] values in
14483 the list are the values from the pragma. */
14484 num_pragma_values
= (!force_pragma
&& current_target_pragma
!= NULL
)
14485 ? list_length (current_target_pragma
) : 0;
14486 for (i
= 0; args
; args
= TREE_CHAIN (args
), i
++)
14490 is_pragma
= (force_pragma
|| i
< num_pragma_values
);
14491 if (TREE_VALUE (args
)
14492 && !s390_valid_target_attribute_inner_p (TREE_VALUE (args
),
14493 opts
, new_opts_set
,
14502 else if (TREE_CODE (args
) != STRING_CST
)
14504 error ("attribute %<target%> argument not a string");
14508 /* Handle multiple arguments separated by commas. */
14509 next_optstr
= ASTRDUP (TREE_STRING_POINTER (args
));
14511 while (next_optstr
&& *next_optstr
!= '\0')
14513 char *p
= next_optstr
;
14515 char *comma
= strchr (next_optstr
, ',');
14516 size_t len
, opt_len
;
14522 enum cl_var_type var_type
;
14528 len
= comma
- next_optstr
;
14529 next_optstr
= comma
+ 1;
14534 next_optstr
= NULL
;
14537 /* Recognize no-xxx. */
14538 if (len
> 3 && p
[0] == 'n' && p
[1] == 'o' && p
[2] == '-')
14547 /* Find the option. */
14550 for (i
= 0; i
< ARRAY_SIZE (attrs
); i
++)
14552 opt_len
= attrs
[i
].len
;
14553 if (ch
== attrs
[i
].string
[0]
14554 && ((attrs
[i
].has_arg
) ? len
> opt_len
: len
== opt_len
)
14555 && memcmp (p
, attrs
[i
].string
, opt_len
) == 0)
14557 opt
= attrs
[i
].opt
;
14558 if (!opt_set_p
&& cl_options
[opt
].cl_reject_negative
)
14560 mask
= cl_options
[opt
].var_value
;
14561 var_type
= cl_options
[opt
].var_type
;
14567 /* Process the option. */
14570 error ("attribute(target(\"%s\")) is unknown", orig_p
);
14573 else if (attrs
[i
].only_as_pragma
&& !force_pragma
)
14575 /* Value is not allowed for the target attribute. */
14576 error ("Value %qs is not supported by attribute %<target%>",
14581 else if (var_type
== CLVC_BIT_SET
|| var_type
== CLVC_BIT_CLEAR
)
14583 if (var_type
== CLVC_BIT_CLEAR
)
14584 opt_set_p
= !opt_set_p
;
14587 opts
->x_target_flags
|= mask
;
14589 opts
->x_target_flags
&= ~mask
;
14590 new_opts_set
->x_target_flags
|= mask
;
14593 else if (cl_options
[opt
].var_type
== CLVC_BOOLEAN
)
14597 if (cl_options
[opt
].cl_uinteger
)
14599 /* Unsigned integer argument. Code based on the function
14600 decode_cmdline_option () in opts-common.c. */
14601 value
= integral_argument (p
+ opt_len
);
14604 value
= (opt_set_p
) ? 1 : 0;
14608 struct cl_decoded_option decoded
;
14610 /* Value range check; only implemented for numeric and boolean
14611 options at the moment. */
14612 generate_option (opt
, NULL
, value
, CL_TARGET
, &decoded
);
14613 s390_handle_option (opts
, new_opts_set
, &decoded
, input_location
);
14614 set_option (opts
, new_opts_set
, opt
, value
,
14615 p
+ opt_len
, DK_UNSPECIFIED
, input_location
,
14620 error ("attribute(target(\"%s\")) is unknown", orig_p
);
14625 else if (cl_options
[opt
].var_type
== CLVC_ENUM
)
14630 arg_ok
= opt_enum_arg_to_value (opt
, p
+ opt_len
, &value
, CL_TARGET
);
14632 set_option (opts
, new_opts_set
, opt
, value
,
14633 p
+ opt_len
, DK_UNSPECIFIED
, input_location
,
14637 error ("attribute(target(\"%s\")) is unknown", orig_p
);
14643 gcc_unreachable ();
14648 /* Return a TARGET_OPTION_NODE tree of the target options listed or NULL. */
14651 s390_valid_target_attribute_tree (tree args
,
14652 struct gcc_options
*opts
,
14653 const struct gcc_options
*opts_set
,
14656 tree t
= NULL_TREE
;
14657 struct gcc_options new_opts_set
;
14659 memset (&new_opts_set
, 0, sizeof (new_opts_set
));
14661 /* Process each of the options on the chain. */
14662 if (! s390_valid_target_attribute_inner_p (args
, opts
, &new_opts_set
,
14664 return error_mark_node
;
14666 /* If some option was set (even if it has not changed), rerun
14667 s390_option_override_internal, and then save the options away. */
14668 if (new_opts_set
.x_target_flags
14669 || new_opts_set
.x_s390_arch
14670 || new_opts_set
.x_s390_tune
14671 || new_opts_set
.x_s390_stack_guard
14672 || new_opts_set
.x_s390_stack_size
14673 || new_opts_set
.x_s390_branch_cost
14674 || new_opts_set
.x_s390_warn_framesize
14675 || new_opts_set
.x_s390_warn_dynamicstack_p
)
14677 const unsigned char *src
= (const unsigned char *)opts_set
;
14678 unsigned char *dest
= (unsigned char *)&new_opts_set
;
14681 /* Merge the original option flags into the new ones. */
14682 for (i
= 0; i
< sizeof(*opts_set
); i
++)
14685 /* Do any overrides, such as arch=xxx, or tune=xxx support. */
14686 s390_option_override_internal (false, opts
, &new_opts_set
);
14687 /* Save the current options unless we are validating options for
14689 t
= build_target_option_node (opts
);
14694 /* Hook to validate attribute((target("string"))). */
14697 s390_valid_target_attribute_p (tree fndecl
,
14698 tree
ARG_UNUSED (name
),
14700 int ARG_UNUSED (flags
))
14702 struct gcc_options func_options
;
14703 tree new_target
, new_optimize
;
14706 /* attribute((target("default"))) does nothing, beyond
14707 affecting multi-versioning. */
14708 if (TREE_VALUE (args
)
14709 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
14710 && TREE_CHAIN (args
) == NULL_TREE
14711 && strcmp (TREE_STRING_POINTER (TREE_VALUE (args
)), "default") == 0)
14714 tree old_optimize
= build_optimization_node (&global_options
);
14716 /* Get the optimization options of the current function. */
14717 tree func_optimize
= DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl
);
14719 if (!func_optimize
)
14720 func_optimize
= old_optimize
;
14722 /* Init func_options. */
14723 memset (&func_options
, 0, sizeof (func_options
));
14724 init_options_struct (&func_options
, NULL
);
14725 lang_hooks
.init_options_struct (&func_options
);
14727 cl_optimization_restore (&func_options
, TREE_OPTIMIZATION (func_optimize
));
14729 /* Initialize func_options to the default before its target options can
14731 cl_target_option_restore (&func_options
,
14732 TREE_TARGET_OPTION (target_option_default_node
));
14734 new_target
= s390_valid_target_attribute_tree (args
, &func_options
,
14735 &global_options_set
,
14737 current_target_pragma
));
14738 new_optimize
= build_optimization_node (&func_options
);
14739 if (new_target
== error_mark_node
)
14741 else if (fndecl
&& new_target
)
14743 DECL_FUNCTION_SPECIFIC_TARGET (fndecl
) = new_target
;
14744 if (old_optimize
!= new_optimize
)
14745 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl
) = new_optimize
;
14750 /* Restore targets globals from NEW_TREE and invalidate s390_previous_fndecl
14754 s390_activate_target_options (tree new_tree
)
14756 cl_target_option_restore (&global_options
, TREE_TARGET_OPTION (new_tree
));
14757 if (TREE_TARGET_GLOBALS (new_tree
))
14758 restore_target_globals (TREE_TARGET_GLOBALS (new_tree
));
14759 else if (new_tree
== target_option_default_node
)
14760 restore_target_globals (&default_target_globals
);
14762 TREE_TARGET_GLOBALS (new_tree
) = save_target_globals_default_opts ();
14763 s390_previous_fndecl
= NULL_TREE
;
14766 /* Establish appropriate back-end context for processing the function
14767 FNDECL. The argument might be NULL to indicate processing at top
14768 level, outside of any function scope. */
14770 s390_set_current_function (tree fndecl
)
14772 /* Only change the context if the function changes. This hook is called
14773 several times in the course of compiling a function, and we don't want to
14774 slow things down too much or call target_reinit when it isn't safe. */
14775 if (fndecl
== s390_previous_fndecl
)
14779 if (s390_previous_fndecl
== NULL_TREE
)
14780 old_tree
= target_option_current_node
;
14781 else if (DECL_FUNCTION_SPECIFIC_TARGET (s390_previous_fndecl
))
14782 old_tree
= DECL_FUNCTION_SPECIFIC_TARGET (s390_previous_fndecl
);
14784 old_tree
= target_option_default_node
;
14786 if (fndecl
== NULL_TREE
)
14788 if (old_tree
!= target_option_current_node
)
14789 s390_activate_target_options (target_option_current_node
);
14793 tree new_tree
= DECL_FUNCTION_SPECIFIC_TARGET (fndecl
);
14794 if (new_tree
== NULL_TREE
)
14795 new_tree
= target_option_default_node
;
14797 if (old_tree
!= new_tree
)
14798 s390_activate_target_options (new_tree
);
14799 s390_previous_fndecl
= fndecl
;
14803 /* Implement TARGET_USE_BY_PIECES_INFRASTRUCTURE_P. */
14806 s390_use_by_pieces_infrastructure_p (unsigned HOST_WIDE_INT size
,
14807 unsigned int align ATTRIBUTE_UNUSED
,
14808 enum by_pieces_operation op ATTRIBUTE_UNUSED
,
14809 bool speed_p ATTRIBUTE_UNUSED
)
14811 return (size
== 1 || size
== 2
14812 || size
== 4 || (TARGET_ZARCH
&& size
== 8));
14815 /* Implement TARGET_ATOMIC_ASSIGN_EXPAND_FENV hook. */
14818 s390_atomic_assign_expand_fenv (tree
*hold
, tree
*clear
, tree
*update
)
14820 tree sfpc
= s390_builtin_decls
[S390_BUILTIN_s390_sfpc
];
14821 tree efpc
= s390_builtin_decls
[S390_BUILTIN_s390_efpc
];
14822 tree call_efpc
= build_call_expr (efpc
, 0);
14823 tree fenv_var
= create_tmp_var_raw (unsigned_type_node
);
14825 #define FPC_EXCEPTION_MASK HOST_WIDE_INT_UC (0xf8000000)
14826 #define FPC_FLAGS_MASK HOST_WIDE_INT_UC (0x00f80000)
14827 #define FPC_DXC_MASK HOST_WIDE_INT_UC (0x0000ff00)
14828 #define FPC_EXCEPTION_MASK_SHIFT HOST_WIDE_INT_UC (24)
14829 #define FPC_FLAGS_SHIFT HOST_WIDE_INT_UC (16)
14830 #define FPC_DXC_SHIFT HOST_WIDE_INT_UC (8)
14832 /* Generates the equivalent of feholdexcept (&fenv_var)
14834 fenv_var = __builtin_s390_efpc ();
14835 __builtin_s390_sfpc (fenv_var & mask) */
14836 tree old_fpc
= build2 (MODIFY_EXPR
, unsigned_type_node
, fenv_var
, call_efpc
);
14838 build2 (BIT_AND_EXPR
, unsigned_type_node
, fenv_var
,
14839 build_int_cst (unsigned_type_node
,
14840 ~(FPC_DXC_MASK
| FPC_FLAGS_MASK
|
14841 FPC_EXCEPTION_MASK
)));
14842 tree set_new_fpc
= build_call_expr (sfpc
, 1, new_fpc
);
14843 *hold
= build2 (COMPOUND_EXPR
, void_type_node
, old_fpc
, set_new_fpc
);
14845 /* Generates the equivalent of feclearexcept (FE_ALL_EXCEPT)
14847 __builtin_s390_sfpc (__builtin_s390_efpc () & mask) */
14848 new_fpc
= build2 (BIT_AND_EXPR
, unsigned_type_node
, call_efpc
,
14849 build_int_cst (unsigned_type_node
,
14850 ~(FPC_DXC_MASK
| FPC_FLAGS_MASK
)));
14851 *clear
= build_call_expr (sfpc
, 1, new_fpc
);
14853 /* Generates the equivalent of feupdateenv (fenv_var)
14855 old_fpc = __builtin_s390_efpc ();
14856 __builtin_s390_sfpc (fenv_var);
14857 __atomic_feraiseexcept ((old_fpc & FPC_FLAGS_MASK) >> FPC_FLAGS_SHIFT); */
14859 old_fpc
= create_tmp_var_raw (unsigned_type_node
);
14860 tree store_old_fpc
= build2 (MODIFY_EXPR
, void_type_node
,
14861 old_fpc
, call_efpc
);
14863 set_new_fpc
= build_call_expr (sfpc
, 1, fenv_var
);
14865 tree raise_old_except
= build2 (BIT_AND_EXPR
, unsigned_type_node
, old_fpc
,
14866 build_int_cst (unsigned_type_node
,
14868 raise_old_except
= build2 (RSHIFT_EXPR
, unsigned_type_node
, raise_old_except
,
14869 build_int_cst (unsigned_type_node
,
14871 tree atomic_feraiseexcept
14872 = builtin_decl_implicit (BUILT_IN_ATOMIC_FERAISEEXCEPT
);
14873 raise_old_except
= build_call_expr (atomic_feraiseexcept
,
14874 1, raise_old_except
);
14876 *update
= build2 (COMPOUND_EXPR
, void_type_node
,
14877 build2 (COMPOUND_EXPR
, void_type_node
,
14878 store_old_fpc
, set_new_fpc
),
14881 #undef FPC_EXCEPTION_MASK
14882 #undef FPC_FLAGS_MASK
14883 #undef FPC_DXC_MASK
14884 #undef FPC_EXCEPTION_MASK_SHIFT
14885 #undef FPC_FLAGS_SHIFT
14886 #undef FPC_DXC_SHIFT
14889 /* Return the vector mode to be used for inner mode MODE when doing
14891 static machine_mode
14892 s390_preferred_simd_mode (machine_mode mode
)
14912 /* Our hardware does not require vectors to be strictly aligned. */
14914 s390_support_vector_misalignment (machine_mode mode ATTRIBUTE_UNUSED
,
14915 const_tree type ATTRIBUTE_UNUSED
,
14916 int misalignment ATTRIBUTE_UNUSED
,
14917 bool is_packed ATTRIBUTE_UNUSED
)
14922 return default_builtin_support_vector_misalignment (mode
, type
, misalignment
,
14926 /* The vector ABI requires vector types to be aligned on an 8 byte
14927 boundary (our stack alignment). However, we allow this to be
14928 overriden by the user, while this definitely breaks the ABI. */
14929 static HOST_WIDE_INT
14930 s390_vector_alignment (const_tree type
)
14932 if (!TARGET_VX_ABI
)
14933 return default_vector_alignment (type
);
14935 if (TYPE_USER_ALIGN (type
))
14936 return TYPE_ALIGN (type
);
14938 return MIN (64, tree_to_shwi (TYPE_SIZE (type
)));
14941 #ifdef HAVE_AS_MACHINE_MACHINEMODE
14942 /* Implement TARGET_ASM_FILE_START. */
14944 s390_asm_file_start (void)
14946 s390_asm_output_machine_for_arch (asm_out_file
);
14950 /* Implement TARGET_ASM_FILE_END. */
14952 s390_asm_file_end (void)
14954 #ifdef HAVE_AS_GNU_ATTRIBUTE
14955 varpool_node
*vnode
;
14956 cgraph_node
*cnode
;
14958 FOR_EACH_VARIABLE (vnode
)
14959 if (TREE_PUBLIC (vnode
->decl
))
14960 s390_check_type_for_vector_abi (TREE_TYPE (vnode
->decl
), false, false);
14962 FOR_EACH_FUNCTION (cnode
)
14963 if (TREE_PUBLIC (cnode
->decl
))
14964 s390_check_type_for_vector_abi (TREE_TYPE (cnode
->decl
), false, false);
14967 if (s390_vector_abi
!= 0)
14968 fprintf (asm_out_file
, "\t.gnu_attribute 8, %d\n",
14971 file_end_indicate_exec_stack ();
14973 if (flag_split_stack
)
14974 file_end_indicate_split_stack ();
14977 /* Return true if TYPE is a vector bool type. */
14979 s390_vector_bool_type_p (const_tree type
)
14981 return TYPE_VECTOR_OPAQUE (type
);
14984 /* Return the diagnostic message string if the binary operation OP is
14985 not permitted on TYPE1 and TYPE2, NULL otherwise. */
14987 s390_invalid_binary_op (int op ATTRIBUTE_UNUSED
, const_tree type1
, const_tree type2
)
14989 bool bool1_p
, bool2_p
;
14993 machine_mode mode1
, mode2
;
14995 if (!TARGET_ZVECTOR
)
14998 if (!VECTOR_TYPE_P (type1
) || !VECTOR_TYPE_P (type2
))
15001 bool1_p
= s390_vector_bool_type_p (type1
);
15002 bool2_p
= s390_vector_bool_type_p (type2
);
15004 /* Mixing signed and unsigned types is forbidden for all
15006 if (!bool1_p
&& !bool2_p
15007 && TYPE_UNSIGNED (type1
) != TYPE_UNSIGNED (type2
))
15008 return N_("types differ in signess");
15010 plusminus_p
= (op
== PLUS_EXPR
|| op
== MINUS_EXPR
);
15011 muldiv_p
= (op
== MULT_EXPR
|| op
== RDIV_EXPR
|| op
== TRUNC_DIV_EXPR
15012 || op
== CEIL_DIV_EXPR
|| op
== FLOOR_DIV_EXPR
15013 || op
== ROUND_DIV_EXPR
);
15014 compare_p
= (op
== LT_EXPR
|| op
== LE_EXPR
|| op
== GT_EXPR
|| op
== GE_EXPR
15015 || op
== EQ_EXPR
|| op
== NE_EXPR
);
15017 if (bool1_p
&& bool2_p
&& (plusminus_p
|| muldiv_p
))
15018 return N_("binary operator does not support two vector bool operands");
15020 if (bool1_p
!= bool2_p
&& (muldiv_p
|| compare_p
))
15021 return N_("binary operator does not support vector bool operand");
15023 mode1
= TYPE_MODE (type1
);
15024 mode2
= TYPE_MODE (type2
);
15026 if (bool1_p
!= bool2_p
&& plusminus_p
15027 && (GET_MODE_CLASS (mode1
) == MODE_VECTOR_FLOAT
15028 || GET_MODE_CLASS (mode2
) == MODE_VECTOR_FLOAT
))
15029 return N_("binary operator does not support mixing vector "
15030 "bool with floating point vector operands");
15035 /* Initialize GCC target structure. */
15037 #undef TARGET_ASM_ALIGNED_HI_OP
15038 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
15039 #undef TARGET_ASM_ALIGNED_DI_OP
15040 #define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
15041 #undef TARGET_ASM_INTEGER
15042 #define TARGET_ASM_INTEGER s390_assemble_integer
15044 #undef TARGET_ASM_OPEN_PAREN
15045 #define TARGET_ASM_OPEN_PAREN ""
15047 #undef TARGET_ASM_CLOSE_PAREN
15048 #define TARGET_ASM_CLOSE_PAREN ""
15050 #undef TARGET_OPTION_OVERRIDE
15051 #define TARGET_OPTION_OVERRIDE s390_option_override
15053 #undef TARGET_ENCODE_SECTION_INFO
15054 #define TARGET_ENCODE_SECTION_INFO s390_encode_section_info
15056 #undef TARGET_SCALAR_MODE_SUPPORTED_P
15057 #define TARGET_SCALAR_MODE_SUPPORTED_P s390_scalar_mode_supported_p
15060 #undef TARGET_HAVE_TLS
15061 #define TARGET_HAVE_TLS true
15063 #undef TARGET_CANNOT_FORCE_CONST_MEM
15064 #define TARGET_CANNOT_FORCE_CONST_MEM s390_cannot_force_const_mem
15066 #undef TARGET_DELEGITIMIZE_ADDRESS
15067 #define TARGET_DELEGITIMIZE_ADDRESS s390_delegitimize_address
15069 #undef TARGET_LEGITIMIZE_ADDRESS
15070 #define TARGET_LEGITIMIZE_ADDRESS s390_legitimize_address
15072 #undef TARGET_RETURN_IN_MEMORY
15073 #define TARGET_RETURN_IN_MEMORY s390_return_in_memory
15075 #undef TARGET_INIT_BUILTINS
15076 #define TARGET_INIT_BUILTINS s390_init_builtins
15077 #undef TARGET_EXPAND_BUILTIN
15078 #define TARGET_EXPAND_BUILTIN s390_expand_builtin
15079 #undef TARGET_BUILTIN_DECL
15080 #define TARGET_BUILTIN_DECL s390_builtin_decl
15082 #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA
15083 #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA s390_output_addr_const_extra
15085 #undef TARGET_ASM_OUTPUT_MI_THUNK
15086 #define TARGET_ASM_OUTPUT_MI_THUNK s390_output_mi_thunk
15087 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
15088 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_const_tree_hwi_hwi_const_tree_true
15090 #undef TARGET_SCHED_ADJUST_PRIORITY
15091 #define TARGET_SCHED_ADJUST_PRIORITY s390_adjust_priority
15092 #undef TARGET_SCHED_ISSUE_RATE
15093 #define TARGET_SCHED_ISSUE_RATE s390_issue_rate
15094 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
15095 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD s390_first_cycle_multipass_dfa_lookahead
15097 #undef TARGET_SCHED_VARIABLE_ISSUE
15098 #define TARGET_SCHED_VARIABLE_ISSUE s390_sched_variable_issue
15099 #undef TARGET_SCHED_REORDER
15100 #define TARGET_SCHED_REORDER s390_sched_reorder
15101 #undef TARGET_SCHED_INIT
15102 #define TARGET_SCHED_INIT s390_sched_init
15104 #undef TARGET_CANNOT_COPY_INSN_P
15105 #define TARGET_CANNOT_COPY_INSN_P s390_cannot_copy_insn_p
15106 #undef TARGET_RTX_COSTS
15107 #define TARGET_RTX_COSTS s390_rtx_costs
15108 #undef TARGET_ADDRESS_COST
15109 #define TARGET_ADDRESS_COST s390_address_cost
15110 #undef TARGET_REGISTER_MOVE_COST
15111 #define TARGET_REGISTER_MOVE_COST s390_register_move_cost
15112 #undef TARGET_MEMORY_MOVE_COST
15113 #define TARGET_MEMORY_MOVE_COST s390_memory_move_cost
15115 #undef TARGET_MACHINE_DEPENDENT_REORG
15116 #define TARGET_MACHINE_DEPENDENT_REORG s390_reorg
15118 #undef TARGET_VALID_POINTER_MODE
15119 #define TARGET_VALID_POINTER_MODE s390_valid_pointer_mode
15121 #undef TARGET_BUILD_BUILTIN_VA_LIST
15122 #define TARGET_BUILD_BUILTIN_VA_LIST s390_build_builtin_va_list
15123 #undef TARGET_EXPAND_BUILTIN_VA_START
15124 #define TARGET_EXPAND_BUILTIN_VA_START s390_va_start
15125 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
15126 #define TARGET_GIMPLIFY_VA_ARG_EXPR s390_gimplify_va_arg
15128 #undef TARGET_PROMOTE_FUNCTION_MODE
15129 #define TARGET_PROMOTE_FUNCTION_MODE s390_promote_function_mode
15130 #undef TARGET_PASS_BY_REFERENCE
15131 #define TARGET_PASS_BY_REFERENCE s390_pass_by_reference
15133 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
15134 #define TARGET_FUNCTION_OK_FOR_SIBCALL s390_function_ok_for_sibcall
15135 #undef TARGET_FUNCTION_ARG
15136 #define TARGET_FUNCTION_ARG s390_function_arg
15137 #undef TARGET_FUNCTION_ARG_ADVANCE
15138 #define TARGET_FUNCTION_ARG_ADVANCE s390_function_arg_advance
15139 #undef TARGET_FUNCTION_VALUE
15140 #define TARGET_FUNCTION_VALUE s390_function_value
15141 #undef TARGET_LIBCALL_VALUE
15142 #define TARGET_LIBCALL_VALUE s390_libcall_value
15143 #undef TARGET_STRICT_ARGUMENT_NAMING
15144 #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
15146 #undef TARGET_KEEP_LEAF_WHEN_PROFILED
15147 #define TARGET_KEEP_LEAF_WHEN_PROFILED s390_keep_leaf_when_profiled
15149 #undef TARGET_FIXED_CONDITION_CODE_REGS
15150 #define TARGET_FIXED_CONDITION_CODE_REGS s390_fixed_condition_code_regs
15152 #undef TARGET_CC_MODES_COMPATIBLE
15153 #define TARGET_CC_MODES_COMPATIBLE s390_cc_modes_compatible
15155 #undef TARGET_INVALID_WITHIN_DOLOOP
15156 #define TARGET_INVALID_WITHIN_DOLOOP hook_constcharptr_const_rtx_insn_null
15159 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
15160 #define TARGET_ASM_OUTPUT_DWARF_DTPREL s390_output_dwarf_dtprel
15163 #undef TARGET_DWARF_FRAME_REG_MODE
15164 #define TARGET_DWARF_FRAME_REG_MODE s390_dwarf_frame_reg_mode
15166 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
15167 #undef TARGET_MANGLE_TYPE
15168 #define TARGET_MANGLE_TYPE s390_mangle_type
15171 #undef TARGET_SCALAR_MODE_SUPPORTED_P
15172 #define TARGET_SCALAR_MODE_SUPPORTED_P s390_scalar_mode_supported_p
15174 #undef TARGET_VECTOR_MODE_SUPPORTED_P
15175 #define TARGET_VECTOR_MODE_SUPPORTED_P s390_vector_mode_supported_p
15177 #undef TARGET_PREFERRED_RELOAD_CLASS
15178 #define TARGET_PREFERRED_RELOAD_CLASS s390_preferred_reload_class
15180 #undef TARGET_SECONDARY_RELOAD
15181 #define TARGET_SECONDARY_RELOAD s390_secondary_reload
15183 #undef TARGET_LIBGCC_CMP_RETURN_MODE
15184 #define TARGET_LIBGCC_CMP_RETURN_MODE s390_libgcc_cmp_return_mode
15186 #undef TARGET_LIBGCC_SHIFT_COUNT_MODE
15187 #define TARGET_LIBGCC_SHIFT_COUNT_MODE s390_libgcc_shift_count_mode
15189 #undef TARGET_LEGITIMATE_ADDRESS_P
15190 #define TARGET_LEGITIMATE_ADDRESS_P s390_legitimate_address_p
15192 #undef TARGET_LEGITIMATE_CONSTANT_P
15193 #define TARGET_LEGITIMATE_CONSTANT_P s390_legitimate_constant_p
15195 #undef TARGET_LRA_P
15196 #define TARGET_LRA_P s390_lra_p
15198 #undef TARGET_CAN_ELIMINATE
15199 #define TARGET_CAN_ELIMINATE s390_can_eliminate
15201 #undef TARGET_CONDITIONAL_REGISTER_USAGE
15202 #define TARGET_CONDITIONAL_REGISTER_USAGE s390_conditional_register_usage
15204 #undef TARGET_LOOP_UNROLL_ADJUST
15205 #define TARGET_LOOP_UNROLL_ADJUST s390_loop_unroll_adjust
15207 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
15208 #define TARGET_ASM_TRAMPOLINE_TEMPLATE s390_asm_trampoline_template
15209 #undef TARGET_TRAMPOLINE_INIT
15210 #define TARGET_TRAMPOLINE_INIT s390_trampoline_init
15212 #undef TARGET_UNWIND_WORD_MODE
15213 #define TARGET_UNWIND_WORD_MODE s390_unwind_word_mode
15215 #undef TARGET_CANONICALIZE_COMPARISON
15216 #define TARGET_CANONICALIZE_COMPARISON s390_canonicalize_comparison
15218 #undef TARGET_HARD_REGNO_SCRATCH_OK
15219 #define TARGET_HARD_REGNO_SCRATCH_OK s390_hard_regno_scratch_ok
15221 #undef TARGET_ATTRIBUTE_TABLE
15222 #define TARGET_ATTRIBUTE_TABLE s390_attribute_table
15224 #undef TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P
15225 #define TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P hook_bool_const_tree_true
15227 #undef TARGET_SET_UP_BY_PROLOGUE
15228 #define TARGET_SET_UP_BY_PROLOGUE s300_set_up_by_prologue
15230 #undef TARGET_EXTRA_LIVE_ON_ENTRY
15231 #define TARGET_EXTRA_LIVE_ON_ENTRY s390_live_on_entry
15233 #undef TARGET_USE_BY_PIECES_INFRASTRUCTURE_P
15234 #define TARGET_USE_BY_PIECES_INFRASTRUCTURE_P \
15235 s390_use_by_pieces_infrastructure_p
15237 #undef TARGET_ATOMIC_ASSIGN_EXPAND_FENV
15238 #define TARGET_ATOMIC_ASSIGN_EXPAND_FENV s390_atomic_assign_expand_fenv
15240 #undef TARGET_INVALID_ARG_FOR_UNPROTOTYPED_FN
15241 #define TARGET_INVALID_ARG_FOR_UNPROTOTYPED_FN s390_invalid_arg_for_unprototyped_fn
15243 #undef TARGET_VECTORIZE_PREFERRED_SIMD_MODE
15244 #define TARGET_VECTORIZE_PREFERRED_SIMD_MODE s390_preferred_simd_mode
15246 #undef TARGET_VECTORIZE_SUPPORT_VECTOR_MISALIGNMENT
15247 #define TARGET_VECTORIZE_SUPPORT_VECTOR_MISALIGNMENT s390_support_vector_misalignment
15249 #undef TARGET_VECTOR_ALIGNMENT
15250 #define TARGET_VECTOR_ALIGNMENT s390_vector_alignment
15252 #undef TARGET_INVALID_BINARY_OP
15253 #define TARGET_INVALID_BINARY_OP s390_invalid_binary_op
15255 #ifdef HAVE_AS_MACHINE_MACHINEMODE
15256 #undef TARGET_ASM_FILE_START
15257 #define TARGET_ASM_FILE_START s390_asm_file_start
15260 #undef TARGET_ASM_FILE_END
15261 #define TARGET_ASM_FILE_END s390_asm_file_end
15263 #if S390_USE_TARGET_ATTRIBUTE
15264 #undef TARGET_SET_CURRENT_FUNCTION
15265 #define TARGET_SET_CURRENT_FUNCTION s390_set_current_function
15267 #undef TARGET_OPTION_VALID_ATTRIBUTE_P
15268 #define TARGET_OPTION_VALID_ATTRIBUTE_P s390_valid_target_attribute_p
15271 #undef TARGET_OPTION_RESTORE
15272 #define TARGET_OPTION_RESTORE s390_function_specific_restore
15274 struct gcc_target targetm
= TARGET_INITIALIZER
;
15276 #include "gt-s390.h"