1 /* Subroutines used for code generation on IBM S/390 and zSeries
2 Copyright (C) 1999-2015 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"
31 #include "double-int.h"
38 #include "fold-const.h"
39 #include "print-tree.h"
40 #include "stringpool.h"
41 #include "stor-layout.h"
46 #include "hard-reg-set.h"
47 #include "insn-config.h"
48 #include "conditions.h"
50 #include "insn-attr.h"
56 #include "statistics.h"
58 #include "fixed-value.h"
66 #include "diagnostic-core.h"
68 #include "dominance.h"
74 #include "cfgcleanup.h"
75 #include "basic-block.h"
78 #include "target-def.h"
80 #include "langhooks.h"
81 #include "insn-codes.h"
83 #include "hash-table.h"
84 #include "tree-ssa-alias.h"
85 #include "internal-fn.h"
86 #include "gimple-fold.h"
88 #include "gimple-expr.h"
96 #include "tree-pass.h"
101 /* Define the specific costs for a given cpu. */
103 struct processor_costs
106 const int m
; /* cost of an M instruction. */
107 const int mghi
; /* cost of an MGHI instruction. */
108 const int mh
; /* cost of an MH instruction. */
109 const int mhi
; /* cost of an MHI instruction. */
110 const int ml
; /* cost of an ML instruction. */
111 const int mr
; /* cost of an MR instruction. */
112 const int ms
; /* cost of an MS instruction. */
113 const int msg
; /* cost of an MSG instruction. */
114 const int msgf
; /* cost of an MSGF instruction. */
115 const int msgfr
; /* cost of an MSGFR instruction. */
116 const int msgr
; /* cost of an MSGR instruction. */
117 const int msr
; /* cost of an MSR instruction. */
118 const int mult_df
; /* cost of multiplication in DFmode. */
121 const int sqxbr
; /* cost of square root in TFmode. */
122 const int sqdbr
; /* cost of square root in DFmode. */
123 const int sqebr
; /* cost of square root in SFmode. */
124 /* multiply and add */
125 const int madbr
; /* cost of multiply and add in DFmode. */
126 const int maebr
; /* cost of multiply and add in SFmode. */
138 const struct processor_costs
*s390_cost
;
141 struct processor_costs z900_cost
=
143 COSTS_N_INSNS (5), /* M */
144 COSTS_N_INSNS (10), /* MGHI */
145 COSTS_N_INSNS (5), /* MH */
146 COSTS_N_INSNS (4), /* MHI */
147 COSTS_N_INSNS (5), /* ML */
148 COSTS_N_INSNS (5), /* MR */
149 COSTS_N_INSNS (4), /* MS */
150 COSTS_N_INSNS (15), /* MSG */
151 COSTS_N_INSNS (7), /* MSGF */
152 COSTS_N_INSNS (7), /* MSGFR */
153 COSTS_N_INSNS (10), /* MSGR */
154 COSTS_N_INSNS (4), /* MSR */
155 COSTS_N_INSNS (7), /* multiplication in DFmode */
156 COSTS_N_INSNS (13), /* MXBR */
157 COSTS_N_INSNS (136), /* SQXBR */
158 COSTS_N_INSNS (44), /* SQDBR */
159 COSTS_N_INSNS (35), /* SQEBR */
160 COSTS_N_INSNS (18), /* MADBR */
161 COSTS_N_INSNS (13), /* MAEBR */
162 COSTS_N_INSNS (134), /* DXBR */
163 COSTS_N_INSNS (30), /* DDBR */
164 COSTS_N_INSNS (27), /* DEBR */
165 COSTS_N_INSNS (220), /* DLGR */
166 COSTS_N_INSNS (34), /* DLR */
167 COSTS_N_INSNS (34), /* DR */
168 COSTS_N_INSNS (32), /* DSGFR */
169 COSTS_N_INSNS (32), /* DSGR */
173 struct processor_costs z990_cost
=
175 COSTS_N_INSNS (4), /* M */
176 COSTS_N_INSNS (2), /* MGHI */
177 COSTS_N_INSNS (2), /* MH */
178 COSTS_N_INSNS (2), /* MHI */
179 COSTS_N_INSNS (4), /* ML */
180 COSTS_N_INSNS (4), /* MR */
181 COSTS_N_INSNS (5), /* MS */
182 COSTS_N_INSNS (6), /* MSG */
183 COSTS_N_INSNS (4), /* MSGF */
184 COSTS_N_INSNS (4), /* MSGFR */
185 COSTS_N_INSNS (4), /* MSGR */
186 COSTS_N_INSNS (4), /* MSR */
187 COSTS_N_INSNS (1), /* multiplication in DFmode */
188 COSTS_N_INSNS (28), /* MXBR */
189 COSTS_N_INSNS (130), /* SQXBR */
190 COSTS_N_INSNS (66), /* SQDBR */
191 COSTS_N_INSNS (38), /* SQEBR */
192 COSTS_N_INSNS (1), /* MADBR */
193 COSTS_N_INSNS (1), /* MAEBR */
194 COSTS_N_INSNS (60), /* DXBR */
195 COSTS_N_INSNS (40), /* DDBR */
196 COSTS_N_INSNS (26), /* DEBR */
197 COSTS_N_INSNS (176), /* DLGR */
198 COSTS_N_INSNS (31), /* DLR */
199 COSTS_N_INSNS (31), /* DR */
200 COSTS_N_INSNS (31), /* DSGFR */
201 COSTS_N_INSNS (31), /* DSGR */
205 struct processor_costs z9_109_cost
=
207 COSTS_N_INSNS (4), /* M */
208 COSTS_N_INSNS (2), /* MGHI */
209 COSTS_N_INSNS (2), /* MH */
210 COSTS_N_INSNS (2), /* MHI */
211 COSTS_N_INSNS (4), /* ML */
212 COSTS_N_INSNS (4), /* MR */
213 COSTS_N_INSNS (5), /* MS */
214 COSTS_N_INSNS (6), /* MSG */
215 COSTS_N_INSNS (4), /* MSGF */
216 COSTS_N_INSNS (4), /* MSGFR */
217 COSTS_N_INSNS (4), /* MSGR */
218 COSTS_N_INSNS (4), /* MSR */
219 COSTS_N_INSNS (1), /* multiplication in DFmode */
220 COSTS_N_INSNS (28), /* MXBR */
221 COSTS_N_INSNS (130), /* SQXBR */
222 COSTS_N_INSNS (66), /* SQDBR */
223 COSTS_N_INSNS (38), /* SQEBR */
224 COSTS_N_INSNS (1), /* MADBR */
225 COSTS_N_INSNS (1), /* MAEBR */
226 COSTS_N_INSNS (60), /* DXBR */
227 COSTS_N_INSNS (40), /* DDBR */
228 COSTS_N_INSNS (26), /* DEBR */
229 COSTS_N_INSNS (30), /* DLGR */
230 COSTS_N_INSNS (23), /* DLR */
231 COSTS_N_INSNS (23), /* DR */
232 COSTS_N_INSNS (24), /* DSGFR */
233 COSTS_N_INSNS (24), /* DSGR */
237 struct processor_costs z10_cost
=
239 COSTS_N_INSNS (10), /* M */
240 COSTS_N_INSNS (10), /* MGHI */
241 COSTS_N_INSNS (10), /* MH */
242 COSTS_N_INSNS (10), /* MHI */
243 COSTS_N_INSNS (10), /* ML */
244 COSTS_N_INSNS (10), /* MR */
245 COSTS_N_INSNS (10), /* MS */
246 COSTS_N_INSNS (10), /* MSG */
247 COSTS_N_INSNS (10), /* MSGF */
248 COSTS_N_INSNS (10), /* MSGFR */
249 COSTS_N_INSNS (10), /* MSGR */
250 COSTS_N_INSNS (10), /* MSR */
251 COSTS_N_INSNS (1) , /* multiplication in DFmode */
252 COSTS_N_INSNS (50), /* MXBR */
253 COSTS_N_INSNS (120), /* SQXBR */
254 COSTS_N_INSNS (52), /* SQDBR */
255 COSTS_N_INSNS (38), /* SQEBR */
256 COSTS_N_INSNS (1), /* MADBR */
257 COSTS_N_INSNS (1), /* MAEBR */
258 COSTS_N_INSNS (111), /* DXBR */
259 COSTS_N_INSNS (39), /* DDBR */
260 COSTS_N_INSNS (32), /* DEBR */
261 COSTS_N_INSNS (160), /* DLGR */
262 COSTS_N_INSNS (71), /* DLR */
263 COSTS_N_INSNS (71), /* DR */
264 COSTS_N_INSNS (71), /* DSGFR */
265 COSTS_N_INSNS (71), /* DSGR */
269 struct processor_costs z196_cost
=
271 COSTS_N_INSNS (7), /* M */
272 COSTS_N_INSNS (5), /* MGHI */
273 COSTS_N_INSNS (5), /* MH */
274 COSTS_N_INSNS (5), /* MHI */
275 COSTS_N_INSNS (7), /* ML */
276 COSTS_N_INSNS (7), /* MR */
277 COSTS_N_INSNS (6), /* MS */
278 COSTS_N_INSNS (8), /* MSG */
279 COSTS_N_INSNS (6), /* MSGF */
280 COSTS_N_INSNS (6), /* MSGFR */
281 COSTS_N_INSNS (8), /* MSGR */
282 COSTS_N_INSNS (6), /* MSR */
283 COSTS_N_INSNS (1) , /* multiplication in DFmode */
284 COSTS_N_INSNS (40), /* MXBR B+40 */
285 COSTS_N_INSNS (100), /* SQXBR B+100 */
286 COSTS_N_INSNS (42), /* SQDBR B+42 */
287 COSTS_N_INSNS (28), /* SQEBR B+28 */
288 COSTS_N_INSNS (1), /* MADBR B */
289 COSTS_N_INSNS (1), /* MAEBR B */
290 COSTS_N_INSNS (101), /* DXBR B+101 */
291 COSTS_N_INSNS (29), /* DDBR */
292 COSTS_N_INSNS (22), /* DEBR */
293 COSTS_N_INSNS (160), /* DLGR cracked */
294 COSTS_N_INSNS (160), /* DLR cracked */
295 COSTS_N_INSNS (160), /* DR expanded */
296 COSTS_N_INSNS (160), /* DSGFR cracked */
297 COSTS_N_INSNS (160), /* DSGR cracked */
301 struct processor_costs zEC12_cost
=
303 COSTS_N_INSNS (7), /* M */
304 COSTS_N_INSNS (5), /* MGHI */
305 COSTS_N_INSNS (5), /* MH */
306 COSTS_N_INSNS (5), /* MHI */
307 COSTS_N_INSNS (7), /* ML */
308 COSTS_N_INSNS (7), /* MR */
309 COSTS_N_INSNS (6), /* MS */
310 COSTS_N_INSNS (8), /* MSG */
311 COSTS_N_INSNS (6), /* MSGF */
312 COSTS_N_INSNS (6), /* MSGFR */
313 COSTS_N_INSNS (8), /* MSGR */
314 COSTS_N_INSNS (6), /* MSR */
315 COSTS_N_INSNS (1) , /* multiplication in DFmode */
316 COSTS_N_INSNS (40), /* MXBR B+40 */
317 COSTS_N_INSNS (100), /* SQXBR B+100 */
318 COSTS_N_INSNS (42), /* SQDBR B+42 */
319 COSTS_N_INSNS (28), /* SQEBR B+28 */
320 COSTS_N_INSNS (1), /* MADBR B */
321 COSTS_N_INSNS (1), /* MAEBR B */
322 COSTS_N_INSNS (131), /* DXBR B+131 */
323 COSTS_N_INSNS (29), /* DDBR */
324 COSTS_N_INSNS (22), /* DEBR */
325 COSTS_N_INSNS (160), /* DLGR cracked */
326 COSTS_N_INSNS (160), /* DLR cracked */
327 COSTS_N_INSNS (160), /* DR expanded */
328 COSTS_N_INSNS (160), /* DSGFR cracked */
329 COSTS_N_INSNS (160), /* DSGR cracked */
332 extern int reload_completed
;
334 /* Kept up to date using the SCHED_VARIABLE_ISSUE hook. */
335 static rtx_insn
*last_scheduled_insn
;
337 /* Structure used to hold the components of a S/390 memory
338 address. A legitimate address on S/390 is of the general
340 base + index + displacement
341 where any of the components is optional.
343 base and index are registers of the class ADDR_REGS,
344 displacement is an unsigned 12-bit immediate constant. */
355 /* The following structure is embedded in the machine
356 specific part of struct function. */
358 struct GTY (()) s390_frame_layout
360 /* Offset within stack frame. */
361 HOST_WIDE_INT gprs_offset
;
362 HOST_WIDE_INT f0_offset
;
363 HOST_WIDE_INT f4_offset
;
364 HOST_WIDE_INT f8_offset
;
365 HOST_WIDE_INT backchain_offset
;
367 /* Number of first and last gpr where slots in the register
368 save area are reserved for. */
369 int first_save_gpr_slot
;
370 int last_save_gpr_slot
;
372 /* Location (FP register number) where GPRs (r0-r15) should
374 0 - does not need to be saved at all
376 signed char gpr_save_slots
[16];
378 /* Number of first and last gpr to be saved, restored. */
380 int first_restore_gpr
;
382 int last_restore_gpr
;
384 /* Bits standing for floating point registers. Set, if the
385 respective register has to be saved. Starting with reg 16 (f0)
386 at the rightmost bit.
387 Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
388 fpr 15 13 11 9 14 12 10 8 7 5 3 1 6 4 2 0
389 reg 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 */
390 unsigned int fpr_bitmap
;
392 /* Number of floating point registers f8-f15 which must be saved. */
395 /* Set if return address needs to be saved.
396 This flag is set by s390_return_addr_rtx if it could not use
397 the initial value of r14 and therefore depends on r14 saved
399 bool save_return_addr_p
;
401 /* Size of stack frame. */
402 HOST_WIDE_INT frame_size
;
405 /* Define the structure for the machine field in struct function. */
407 struct GTY(()) machine_function
409 struct s390_frame_layout frame_layout
;
411 /* Literal pool base register. */
414 /* True if we may need to perform branch splitting. */
415 bool split_branches_pending_p
;
417 bool has_landing_pad_p
;
419 /* True if the current function may contain a tbegin clobbering
424 /* Few accessor macros for struct cfun->machine->s390_frame_layout. */
426 #define cfun_frame_layout (cfun->machine->frame_layout)
427 #define cfun_save_high_fprs_p (!!cfun_frame_layout.high_fprs)
428 #define cfun_save_arg_fprs_p (!!(TARGET_64BIT \
429 ? cfun_frame_layout.fpr_bitmap & 0x0f \
430 : cfun_frame_layout.fpr_bitmap & 0x03))
431 #define cfun_gprs_save_area_size ((cfun_frame_layout.last_save_gpr_slot - \
432 cfun_frame_layout.first_save_gpr_slot + 1) * UNITS_PER_LONG)
433 #define cfun_set_fpr_save(REGNO) (cfun->machine->frame_layout.fpr_bitmap |= \
434 (1 << (REGNO - FPR0_REGNUM)))
435 #define cfun_fpr_save_p(REGNO) (!!(cfun->machine->frame_layout.fpr_bitmap & \
436 (1 << (REGNO - FPR0_REGNUM))))
437 #define cfun_gpr_save_slot(REGNO) \
438 cfun->machine->frame_layout.gpr_save_slots[REGNO]
440 /* Number of GPRs and FPRs used for argument passing. */
441 #define GP_ARG_NUM_REG 5
442 #define FP_ARG_NUM_REG (TARGET_64BIT? 4 : 2)
444 /* A couple of shortcuts. */
445 #define CONST_OK_FOR_J(x) \
446 CONST_OK_FOR_CONSTRAINT_P((x), 'J', "J")
447 #define CONST_OK_FOR_K(x) \
448 CONST_OK_FOR_CONSTRAINT_P((x), 'K', "K")
449 #define CONST_OK_FOR_Os(x) \
450 CONST_OK_FOR_CONSTRAINT_P((x), 'O', "Os")
451 #define CONST_OK_FOR_Op(x) \
452 CONST_OK_FOR_CONSTRAINT_P((x), 'O', "Op")
453 #define CONST_OK_FOR_On(x) \
454 CONST_OK_FOR_CONSTRAINT_P((x), 'O', "On")
456 #define REGNO_PAIR_OK(REGNO, MODE) \
457 (HARD_REGNO_NREGS ((REGNO), (MODE)) == 1 || !((REGNO) & 1))
459 /* That's the read ahead of the dynamic branch prediction unit in
460 bytes on a z10 (or higher) CPU. */
461 #define PREDICT_DISTANCE (TARGET_Z10 ? 384 : 2048)
463 static const int s390_hotpatch_trampoline_halfwords_default
= 12;
464 static const int s390_hotpatch_trampoline_halfwords_max
= 1000000;
465 static int s390_hotpatch_trampoline_halfwords
= -1;
467 /* Return the argument of the given hotpatch attribute or the default value if
468 no argument is present. */
471 get_hotpatch_attribute (tree hotpatch_attr
)
475 args
= TREE_VALUE (hotpatch_attr
);
478 TREE_INT_CST_LOW (TREE_VALUE (args
)):
479 s390_hotpatch_trampoline_halfwords_default
;
482 /* Check whether the hotpatch attribute is applied to a function and, if it has
483 an argument, the argument is valid. */
486 s390_handle_hotpatch_attribute (tree
*node
, tree name
, tree args
,
487 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
489 if (TREE_CODE (*node
) != FUNCTION_DECL
)
491 warning (OPT_Wattributes
, "%qE attribute only applies to functions",
493 *no_add_attrs
= true;
497 tree expr
= TREE_VALUE (args
);
499 if (TREE_CODE (expr
) != INTEGER_CST
500 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
))
501 || wi::gtu_p (expr
, s390_hotpatch_trampoline_halfwords_max
))
503 error ("requested %qE attribute is not a non-negative integer"
504 " constant or too large (max. %d)", name
,
505 s390_hotpatch_trampoline_halfwords_max
);
506 *no_add_attrs
= true;
513 static const struct attribute_spec s390_attribute_table
[] = {
514 { "hotpatch", 0, 1, true, false, false, s390_handle_hotpatch_attribute
, false
517 { NULL
, 0, 0, false, false, false, NULL
, false }
520 /* Return the alignment for LABEL. We default to the -falign-labels
521 value except for the literal pool base label. */
523 s390_label_align (rtx label
)
525 rtx_insn
*prev_insn
= prev_active_insn (label
);
528 if (prev_insn
== NULL_RTX
)
531 set
= single_set (prev_insn
);
538 /* Don't align literal pool base labels. */
539 if (GET_CODE (src
) == UNSPEC
540 && XINT (src
, 1) == UNSPEC_MAIN_BASE
)
544 return align_labels_log
;
548 s390_libgcc_cmp_return_mode (void)
550 return TARGET_64BIT
? DImode
: SImode
;
554 s390_libgcc_shift_count_mode (void)
556 return TARGET_64BIT
? DImode
: SImode
;
560 s390_unwind_word_mode (void)
562 return TARGET_64BIT
? DImode
: SImode
;
565 /* Return true if the back end supports mode MODE. */
567 s390_scalar_mode_supported_p (machine_mode mode
)
569 /* In contrast to the default implementation reject TImode constants on 31bit
570 TARGET_ZARCH for ABI compliance. */
571 if (!TARGET_64BIT
&& TARGET_ZARCH
&& mode
== TImode
)
574 if (DECIMAL_FLOAT_MODE_P (mode
))
575 return default_decimal_float_supported_p ();
577 return default_scalar_mode_supported_p (mode
);
580 /* Set the has_landing_pad_p flag in struct machine_function to VALUE. */
583 s390_set_has_landing_pad_p (bool value
)
585 cfun
->machine
->has_landing_pad_p
= value
;
588 /* If two condition code modes are compatible, return a condition code
589 mode which is compatible with both. Otherwise, return
593 s390_cc_modes_compatible (machine_mode m1
, machine_mode m2
)
601 if (m2
== CCUmode
|| m2
== CCTmode
|| m2
== CCZ1mode
602 || m2
== CCSmode
|| m2
== CCSRmode
|| m2
== CCURmode
)
623 /* Return true if SET either doesn't set the CC register, or else
624 the source and destination have matching CC modes and that
625 CC mode is at least as constrained as REQ_MODE. */
628 s390_match_ccmode_set (rtx set
, machine_mode req_mode
)
630 machine_mode set_mode
;
632 gcc_assert (GET_CODE (set
) == SET
);
634 if (GET_CODE (SET_DEST (set
)) != REG
|| !CC_REGNO_P (REGNO (SET_DEST (set
))))
637 set_mode
= GET_MODE (SET_DEST (set
));
651 if (req_mode
!= set_mode
)
656 if (req_mode
!= CCSmode
&& req_mode
!= CCUmode
&& req_mode
!= CCTmode
657 && req_mode
!= CCSRmode
&& req_mode
!= CCURmode
)
663 if (req_mode
!= CCAmode
)
671 return (GET_MODE (SET_SRC (set
)) == set_mode
);
674 /* Return true if every SET in INSN that sets the CC register
675 has source and destination with matching CC modes and that
676 CC mode is at least as constrained as REQ_MODE.
677 If REQ_MODE is VOIDmode, always return false. */
680 s390_match_ccmode (rtx_insn
*insn
, machine_mode req_mode
)
684 /* s390_tm_ccmode returns VOIDmode to indicate failure. */
685 if (req_mode
== VOIDmode
)
688 if (GET_CODE (PATTERN (insn
)) == SET
)
689 return s390_match_ccmode_set (PATTERN (insn
), req_mode
);
691 if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
692 for (i
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
694 rtx set
= XVECEXP (PATTERN (insn
), 0, i
);
695 if (GET_CODE (set
) == SET
)
696 if (!s390_match_ccmode_set (set
, req_mode
))
703 /* If a test-under-mask instruction can be used to implement
704 (compare (and ... OP1) OP2), return the CC mode required
705 to do that. Otherwise, return VOIDmode.
706 MIXED is true if the instruction can distinguish between
707 CC1 and CC2 for mixed selected bits (TMxx), it is false
708 if the instruction cannot (TM). */
711 s390_tm_ccmode (rtx op1
, rtx op2
, bool mixed
)
715 /* ??? Fixme: should work on CONST_DOUBLE as well. */
716 if (GET_CODE (op1
) != CONST_INT
|| GET_CODE (op2
) != CONST_INT
)
719 /* Selected bits all zero: CC0.
720 e.g.: int a; if ((a & (16 + 128)) == 0) */
721 if (INTVAL (op2
) == 0)
724 /* Selected bits all one: CC3.
725 e.g.: int a; if ((a & (16 + 128)) == 16 + 128) */
726 if (INTVAL (op2
) == INTVAL (op1
))
729 /* Exactly two bits selected, mixed zeroes and ones: CC1 or CC2. e.g.:
731 if ((a & (16 + 128)) == 16) -> CCT1
732 if ((a & (16 + 128)) == 128) -> CCT2 */
735 bit1
= exact_log2 (INTVAL (op2
));
736 bit0
= exact_log2 (INTVAL (op1
) ^ INTVAL (op2
));
737 if (bit0
!= -1 && bit1
!= -1)
738 return bit0
> bit1
? CCT1mode
: CCT2mode
;
744 /* Given a comparison code OP (EQ, NE, etc.) and the operands
745 OP0 and OP1 of a COMPARE, return the mode to be used for the
749 s390_select_ccmode (enum rtx_code code
, rtx op0
, rtx op1
)
755 if ((GET_CODE (op0
) == NEG
|| GET_CODE (op0
) == ABS
)
756 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
758 if (GET_CODE (op0
) == PLUS
&& GET_CODE (XEXP (op0
, 1)) == CONST_INT
759 && CONST_OK_FOR_K (INTVAL (XEXP (op0
, 1))))
761 if ((GET_CODE (op0
) == PLUS
|| GET_CODE (op0
) == MINUS
762 || GET_CODE (op1
) == NEG
)
763 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
766 if (GET_CODE (op0
) == AND
)
768 /* Check whether we can potentially do it via TM. */
770 ccmode
= s390_tm_ccmode (XEXP (op0
, 1), op1
, 1);
771 if (ccmode
!= VOIDmode
)
773 /* Relax CCTmode to CCZmode to allow fall-back to AND
774 if that turns out to be beneficial. */
775 return ccmode
== CCTmode
? CCZmode
: ccmode
;
779 if (register_operand (op0
, HImode
)
780 && GET_CODE (op1
) == CONST_INT
781 && (INTVAL (op1
) == -1 || INTVAL (op1
) == 65535))
783 if (register_operand (op0
, QImode
)
784 && GET_CODE (op1
) == CONST_INT
785 && (INTVAL (op1
) == -1 || INTVAL (op1
) == 255))
794 /* The only overflow condition of NEG and ABS happens when
795 -INT_MAX is used as parameter, which stays negative. So
796 we have an overflow from a positive value to a negative.
797 Using CCAP mode the resulting cc can be used for comparisons. */
798 if ((GET_CODE (op0
) == NEG
|| GET_CODE (op0
) == ABS
)
799 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
802 /* If constants are involved in an add instruction it is possible to use
803 the resulting cc for comparisons with zero. Knowing the sign of the
804 constant the overflow behavior gets predictable. e.g.:
805 int a, b; if ((b = a + c) > 0)
806 with c as a constant value: c < 0 -> CCAN and c >= 0 -> CCAP */
807 if (GET_CODE (op0
) == PLUS
&& GET_CODE (XEXP (op0
, 1)) == CONST_INT
808 && (CONST_OK_FOR_K (INTVAL (XEXP (op0
, 1)))
809 || (CONST_OK_FOR_CONSTRAINT_P (INTVAL (XEXP (op0
, 1)), 'O', "Os")
810 /* Avoid INT32_MIN on 32 bit. */
811 && (!TARGET_ZARCH
|| INTVAL (XEXP (op0
, 1)) != -0x7fffffff - 1))))
813 if (INTVAL (XEXP((op0
), 1)) < 0)
827 if ((GET_CODE (op0
) == SIGN_EXTEND
|| GET_CODE (op0
) == ZERO_EXTEND
)
828 && GET_CODE (op1
) != CONST_INT
)
834 if (GET_CODE (op0
) == PLUS
835 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
838 if ((GET_CODE (op0
) == SIGN_EXTEND
|| GET_CODE (op0
) == ZERO_EXTEND
)
839 && GET_CODE (op1
) != CONST_INT
)
845 if (GET_CODE (op0
) == MINUS
846 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
849 if ((GET_CODE (op0
) == SIGN_EXTEND
|| GET_CODE (op0
) == ZERO_EXTEND
)
850 && GET_CODE (op1
) != CONST_INT
)
859 /* Replace the comparison OP0 CODE OP1 by a semantically equivalent one
860 that we can implement more efficiently. */
863 s390_canonicalize_comparison (int *code
, rtx
*op0
, rtx
*op1
,
864 bool op0_preserve_value
)
866 if (op0_preserve_value
)
869 /* Convert ZERO_EXTRACT back to AND to enable TM patterns. */
870 if ((*code
== EQ
|| *code
== NE
)
871 && *op1
== const0_rtx
872 && GET_CODE (*op0
) == ZERO_EXTRACT
873 && GET_CODE (XEXP (*op0
, 1)) == CONST_INT
874 && GET_CODE (XEXP (*op0
, 2)) == CONST_INT
875 && SCALAR_INT_MODE_P (GET_MODE (XEXP (*op0
, 0))))
877 rtx inner
= XEXP (*op0
, 0);
878 HOST_WIDE_INT modesize
= GET_MODE_BITSIZE (GET_MODE (inner
));
879 HOST_WIDE_INT len
= INTVAL (XEXP (*op0
, 1));
880 HOST_WIDE_INT pos
= INTVAL (XEXP (*op0
, 2));
882 if (len
> 0 && len
< modesize
883 && pos
>= 0 && pos
+ len
<= modesize
884 && modesize
<= HOST_BITS_PER_WIDE_INT
)
886 unsigned HOST_WIDE_INT block
;
887 block
= ((unsigned HOST_WIDE_INT
) 1 << len
) - 1;
888 block
<<= modesize
- pos
- len
;
890 *op0
= gen_rtx_AND (GET_MODE (inner
), inner
,
891 gen_int_mode (block
, GET_MODE (inner
)));
895 /* Narrow AND of memory against immediate to enable TM. */
896 if ((*code
== EQ
|| *code
== NE
)
897 && *op1
== const0_rtx
898 && GET_CODE (*op0
) == AND
899 && GET_CODE (XEXP (*op0
, 1)) == CONST_INT
900 && SCALAR_INT_MODE_P (GET_MODE (XEXP (*op0
, 0))))
902 rtx inner
= XEXP (*op0
, 0);
903 rtx mask
= XEXP (*op0
, 1);
905 /* Ignore paradoxical SUBREGs if all extra bits are masked out. */
906 if (GET_CODE (inner
) == SUBREG
907 && SCALAR_INT_MODE_P (GET_MODE (SUBREG_REG (inner
)))
908 && (GET_MODE_SIZE (GET_MODE (inner
))
909 >= GET_MODE_SIZE (GET_MODE (SUBREG_REG (inner
))))
911 & GET_MODE_MASK (GET_MODE (inner
))
912 & ~GET_MODE_MASK (GET_MODE (SUBREG_REG (inner
))))
914 inner
= SUBREG_REG (inner
);
916 /* Do not change volatile MEMs. */
917 if (MEM_P (inner
) && !MEM_VOLATILE_P (inner
))
919 int part
= s390_single_part (XEXP (*op0
, 1),
920 GET_MODE (inner
), QImode
, 0);
923 mask
= gen_int_mode (s390_extract_part (mask
, QImode
, 0), QImode
);
924 inner
= adjust_address_nv (inner
, QImode
, part
);
925 *op0
= gen_rtx_AND (QImode
, inner
, mask
);
930 /* Narrow comparisons against 0xffff to HImode if possible. */
931 if ((*code
== EQ
|| *code
== NE
)
932 && GET_CODE (*op1
) == CONST_INT
933 && INTVAL (*op1
) == 0xffff
934 && SCALAR_INT_MODE_P (GET_MODE (*op0
))
935 && (nonzero_bits (*op0
, GET_MODE (*op0
))
936 & ~(unsigned HOST_WIDE_INT
) 0xffff) == 0)
938 *op0
= gen_lowpart (HImode
, *op0
);
942 /* Remove redundant UNSPEC_STRCMPCC_TO_INT conversions if possible. */
943 if (GET_CODE (*op0
) == UNSPEC
944 && XINT (*op0
, 1) == UNSPEC_STRCMPCC_TO_INT
945 && XVECLEN (*op0
, 0) == 1
946 && GET_MODE (XVECEXP (*op0
, 0, 0)) == CCUmode
947 && GET_CODE (XVECEXP (*op0
, 0, 0)) == REG
948 && REGNO (XVECEXP (*op0
, 0, 0)) == CC_REGNUM
949 && *op1
== const0_rtx
)
951 enum rtx_code new_code
= UNKNOWN
;
954 case EQ
: new_code
= EQ
; break;
955 case NE
: new_code
= NE
; break;
956 case LT
: new_code
= GTU
; break;
957 case GT
: new_code
= LTU
; break;
958 case LE
: new_code
= GEU
; break;
959 case GE
: new_code
= LEU
; break;
963 if (new_code
!= UNKNOWN
)
965 *op0
= XVECEXP (*op0
, 0, 0);
970 /* Remove redundant UNSPEC_CC_TO_INT conversions if possible. */
971 if (GET_CODE (*op0
) == UNSPEC
972 && XINT (*op0
, 1) == UNSPEC_CC_TO_INT
973 && XVECLEN (*op0
, 0) == 1
974 && GET_CODE (XVECEXP (*op0
, 0, 0)) == REG
975 && REGNO (XVECEXP (*op0
, 0, 0)) == CC_REGNUM
976 && CONST_INT_P (*op1
))
978 enum rtx_code new_code
= UNKNOWN
;
979 switch (GET_MODE (XVECEXP (*op0
, 0, 0)))
985 case EQ
: new_code
= EQ
; break;
986 case NE
: new_code
= NE
; break;
993 if (new_code
!= UNKNOWN
)
995 /* For CCRAWmode put the required cc mask into the second
997 if (GET_MODE (XVECEXP (*op0
, 0, 0)) == CCRAWmode
998 && INTVAL (*op1
) >= 0 && INTVAL (*op1
) <= 3)
999 *op1
= gen_rtx_CONST_INT (VOIDmode
, 1 << (3 - INTVAL (*op1
)));
1000 *op0
= XVECEXP (*op0
, 0, 0);
1005 /* Simplify cascaded EQ, NE with const0_rtx. */
1006 if ((*code
== NE
|| *code
== EQ
)
1007 && (GET_CODE (*op0
) == EQ
|| GET_CODE (*op0
) == NE
)
1008 && GET_MODE (*op0
) == SImode
1009 && GET_MODE (XEXP (*op0
, 0)) == CCZ1mode
1010 && REG_P (XEXP (*op0
, 0))
1011 && XEXP (*op0
, 1) == const0_rtx
1012 && *op1
== const0_rtx
)
1014 if ((*code
== EQ
&& GET_CODE (*op0
) == NE
)
1015 || (*code
== NE
&& GET_CODE (*op0
) == EQ
))
1019 *op0
= XEXP (*op0
, 0);
1022 /* Prefer register over memory as first operand. */
1023 if (MEM_P (*op0
) && REG_P (*op1
))
1025 rtx tem
= *op0
; *op0
= *op1
; *op1
= tem
;
1026 *code
= (int)swap_condition ((enum rtx_code
)*code
);
1030 /* Emit a compare instruction suitable to implement the comparison
1031 OP0 CODE OP1. Return the correct condition RTL to be placed in
1032 the IF_THEN_ELSE of the conditional branch testing the result. */
1035 s390_emit_compare (enum rtx_code code
, rtx op0
, rtx op1
)
1037 machine_mode mode
= s390_select_ccmode (code
, op0
, op1
);
1040 /* Do not output a redundant compare instruction if a compare_and_swap
1041 pattern already computed the result and the machine modes are compatible. */
1042 if (GET_MODE_CLASS (GET_MODE (op0
)) == MODE_CC
)
1044 gcc_assert (s390_cc_modes_compatible (GET_MODE (op0
), mode
)
1050 cc
= gen_rtx_REG (mode
, CC_REGNUM
);
1051 emit_insn (gen_rtx_SET (VOIDmode
, cc
, gen_rtx_COMPARE (mode
, op0
, op1
)));
1054 return gen_rtx_fmt_ee (code
, VOIDmode
, cc
, const0_rtx
);
1057 /* Emit a SImode compare and swap instruction setting MEM to NEW_RTX if OLD
1059 Return the correct condition RTL to be placed in the IF_THEN_ELSE of the
1060 conditional branch testing the result. */
1063 s390_emit_compare_and_swap (enum rtx_code code
, rtx old
, rtx mem
,
1064 rtx cmp
, rtx new_rtx
)
1066 emit_insn (gen_atomic_compare_and_swapsi_internal (old
, mem
, cmp
, new_rtx
));
1067 return s390_emit_compare (code
, gen_rtx_REG (CCZ1mode
, CC_REGNUM
),
1071 /* Emit a jump instruction to TARGET and return it. If COND is
1072 NULL_RTX, emit an unconditional jump, else a conditional jump under
1076 s390_emit_jump (rtx target
, rtx cond
)
1080 target
= gen_rtx_LABEL_REF (VOIDmode
, target
);
1082 target
= gen_rtx_IF_THEN_ELSE (VOIDmode
, cond
, target
, pc_rtx
);
1084 insn
= gen_rtx_SET (VOIDmode
, pc_rtx
, target
);
1085 return emit_jump_insn (insn
);
1088 /* Return branch condition mask to implement a branch
1089 specified by CODE. Return -1 for invalid comparisons. */
1092 s390_branch_condition_mask (rtx code
)
1094 const int CC0
= 1 << 3;
1095 const int CC1
= 1 << 2;
1096 const int CC2
= 1 << 1;
1097 const int CC3
= 1 << 0;
1099 gcc_assert (GET_CODE (XEXP (code
, 0)) == REG
);
1100 gcc_assert (REGNO (XEXP (code
, 0)) == CC_REGNUM
);
1101 gcc_assert (XEXP (code
, 1) == const0_rtx
1102 || (GET_MODE (XEXP (code
, 0)) == CCRAWmode
1103 && CONST_INT_P (XEXP (code
, 1))));
1106 switch (GET_MODE (XEXP (code
, 0)))
1110 switch (GET_CODE (code
))
1112 case EQ
: return CC0
;
1113 case NE
: return CC1
| CC2
| CC3
;
1119 switch (GET_CODE (code
))
1121 case EQ
: return CC1
;
1122 case NE
: return CC0
| CC2
| CC3
;
1128 switch (GET_CODE (code
))
1130 case EQ
: return CC2
;
1131 case NE
: return CC0
| CC1
| CC3
;
1137 switch (GET_CODE (code
))
1139 case EQ
: return CC3
;
1140 case NE
: return CC0
| CC1
| CC2
;
1146 switch (GET_CODE (code
))
1148 case EQ
: return CC0
| CC2
;
1149 case NE
: return CC1
| CC3
;
1155 switch (GET_CODE (code
))
1157 case LTU
: return CC2
| CC3
; /* carry */
1158 case GEU
: return CC0
| CC1
; /* no carry */
1164 switch (GET_CODE (code
))
1166 case GTU
: return CC0
| CC1
; /* borrow */
1167 case LEU
: return CC2
| CC3
; /* no borrow */
1173 switch (GET_CODE (code
))
1175 case EQ
: return CC0
| CC2
;
1176 case NE
: return CC1
| CC3
;
1177 case LTU
: return CC1
;
1178 case GTU
: return CC3
;
1179 case LEU
: return CC1
| CC2
;
1180 case GEU
: return CC2
| CC3
;
1185 switch (GET_CODE (code
))
1187 case EQ
: return CC0
;
1188 case NE
: return CC1
| CC2
| CC3
;
1189 case LTU
: return CC1
;
1190 case GTU
: return CC2
;
1191 case LEU
: return CC0
| CC1
;
1192 case GEU
: return CC0
| CC2
;
1198 switch (GET_CODE (code
))
1200 case EQ
: return CC0
;
1201 case NE
: return CC2
| CC1
| CC3
;
1202 case LTU
: return CC2
;
1203 case GTU
: return CC1
;
1204 case LEU
: return CC0
| CC2
;
1205 case GEU
: return CC0
| CC1
;
1211 switch (GET_CODE (code
))
1213 case EQ
: return CC0
;
1214 case NE
: return CC1
| CC2
| CC3
;
1215 case LT
: return CC1
| CC3
;
1216 case GT
: return CC2
;
1217 case LE
: return CC0
| CC1
| CC3
;
1218 case GE
: return CC0
| CC2
;
1224 switch (GET_CODE (code
))
1226 case EQ
: return CC0
;
1227 case NE
: return CC1
| CC2
| CC3
;
1228 case LT
: return CC1
;
1229 case GT
: return CC2
| CC3
;
1230 case LE
: return CC0
| CC1
;
1231 case GE
: return CC0
| CC2
| CC3
;
1237 switch (GET_CODE (code
))
1239 case EQ
: return CC0
;
1240 case NE
: return CC1
| CC2
| CC3
;
1241 case LT
: return CC1
;
1242 case GT
: return CC2
;
1243 case LE
: return CC0
| CC1
;
1244 case GE
: return CC0
| CC2
;
1245 case UNORDERED
: return CC3
;
1246 case ORDERED
: return CC0
| CC1
| CC2
;
1247 case UNEQ
: return CC0
| CC3
;
1248 case UNLT
: return CC1
| CC3
;
1249 case UNGT
: return CC2
| CC3
;
1250 case UNLE
: return CC0
| CC1
| CC3
;
1251 case UNGE
: return CC0
| CC2
| CC3
;
1252 case LTGT
: return CC1
| CC2
;
1258 switch (GET_CODE (code
))
1260 case EQ
: return CC0
;
1261 case NE
: return CC2
| CC1
| CC3
;
1262 case LT
: return CC2
;
1263 case GT
: return CC1
;
1264 case LE
: return CC0
| CC2
;
1265 case GE
: return CC0
| CC1
;
1266 case UNORDERED
: return CC3
;
1267 case ORDERED
: return CC0
| CC2
| CC1
;
1268 case UNEQ
: return CC0
| CC3
;
1269 case UNLT
: return CC2
| CC3
;
1270 case UNGT
: return CC1
| CC3
;
1271 case UNLE
: return CC0
| CC2
| CC3
;
1272 case UNGE
: return CC0
| CC1
| CC3
;
1273 case LTGT
: return CC2
| CC1
;
1279 switch (GET_CODE (code
))
1282 return INTVAL (XEXP (code
, 1));
1284 return (INTVAL (XEXP (code
, 1))) ^ 0xf;
1295 /* Return branch condition mask to implement a compare and branch
1296 specified by CODE. Return -1 for invalid comparisons. */
1299 s390_compare_and_branch_condition_mask (rtx code
)
1301 const int CC0
= 1 << 3;
1302 const int CC1
= 1 << 2;
1303 const int CC2
= 1 << 1;
1305 switch (GET_CODE (code
))
1329 /* If INV is false, return assembler mnemonic string to implement
1330 a branch specified by CODE. If INV is true, return mnemonic
1331 for the corresponding inverted branch. */
1334 s390_branch_condition_mnemonic (rtx code
, int inv
)
1338 static const char *const mnemonic
[16] =
1340 NULL
, "o", "h", "nle",
1341 "l", "nhe", "lh", "ne",
1342 "e", "nlh", "he", "nl",
1343 "le", "nh", "no", NULL
1346 if (GET_CODE (XEXP (code
, 0)) == REG
1347 && REGNO (XEXP (code
, 0)) == CC_REGNUM
1348 && (XEXP (code
, 1) == const0_rtx
1349 || (GET_MODE (XEXP (code
, 0)) == CCRAWmode
1350 && CONST_INT_P (XEXP (code
, 1)))))
1351 mask
= s390_branch_condition_mask (code
);
1353 mask
= s390_compare_and_branch_condition_mask (code
);
1355 gcc_assert (mask
>= 0);
1360 gcc_assert (mask
>= 1 && mask
<= 14);
1362 return mnemonic
[mask
];
1365 /* Return the part of op which has a value different from def.
1366 The size of the part is determined by mode.
1367 Use this function only if you already know that op really
1368 contains such a part. */
1370 unsigned HOST_WIDE_INT
1371 s390_extract_part (rtx op
, machine_mode mode
, int def
)
1373 unsigned HOST_WIDE_INT value
= 0;
1374 int max_parts
= HOST_BITS_PER_WIDE_INT
/ GET_MODE_BITSIZE (mode
);
1375 int part_bits
= GET_MODE_BITSIZE (mode
);
1376 unsigned HOST_WIDE_INT part_mask
1377 = ((unsigned HOST_WIDE_INT
)1 << part_bits
) - 1;
1380 for (i
= 0; i
< max_parts
; i
++)
1383 value
= (unsigned HOST_WIDE_INT
) INTVAL (op
);
1385 value
>>= part_bits
;
1387 if ((value
& part_mask
) != (def
& part_mask
))
1388 return value
& part_mask
;
1394 /* If OP is an integer constant of mode MODE with exactly one
1395 part of mode PART_MODE unequal to DEF, return the number of that
1396 part. Otherwise, return -1. */
1399 s390_single_part (rtx op
,
1401 machine_mode part_mode
,
1404 unsigned HOST_WIDE_INT value
= 0;
1405 int n_parts
= GET_MODE_SIZE (mode
) / GET_MODE_SIZE (part_mode
);
1406 unsigned HOST_WIDE_INT part_mask
1407 = ((unsigned HOST_WIDE_INT
)1 << GET_MODE_BITSIZE (part_mode
)) - 1;
1410 if (GET_CODE (op
) != CONST_INT
)
1413 for (i
= 0; i
< n_parts
; i
++)
1416 value
= (unsigned HOST_WIDE_INT
) INTVAL (op
);
1418 value
>>= GET_MODE_BITSIZE (part_mode
);
1420 if ((value
& part_mask
) != (def
& part_mask
))
1428 return part
== -1 ? -1 : n_parts
- 1 - part
;
1431 /* Return true if IN contains a contiguous bitfield in the lower SIZE
1432 bits and no other bits are set in IN. POS and LENGTH can be used
1433 to obtain the start position and the length of the bitfield.
1435 POS gives the position of the first bit of the bitfield counting
1436 from the lowest order bit starting with zero. In order to use this
1437 value for S/390 instructions this has to be converted to "bits big
1441 s390_contiguous_bitmask_p (unsigned HOST_WIDE_INT in
, int size
,
1442 int *pos
, int *length
)
1447 unsigned HOST_WIDE_INT mask
= 1ULL;
1448 bool contiguous
= false;
1450 for (i
= 0; i
< size
; mask
<<= 1, i
++)
1474 /* Calculate a mask for all bits beyond the contiguous bits. */
1475 mask
= (-1LL & ~(((1ULL << (tmp_length
+ tmp_pos
- 1)) << 1) - 1));
1480 if (tmp_length
+ tmp_pos
- 1 > size
)
1484 *length
= tmp_length
;
1492 /* Check whether a rotate of ROTL followed by an AND of CONTIG is
1493 equivalent to a shift followed by the AND. In particular, CONTIG
1494 should not overlap the (rotated) bit 0/bit 63 gap. Negative values
1495 for ROTL indicate a rotate to the right. */
1498 s390_extzv_shift_ok (int bitsize
, int rotl
, unsigned HOST_WIDE_INT contig
)
1503 ok
= s390_contiguous_bitmask_p (contig
, bitsize
, &pos
, &len
);
1506 return ((rotl
>= 0 && rotl
<= pos
)
1507 || (rotl
< 0 && -rotl
<= bitsize
- len
- pos
));
1510 /* Check whether we can (and want to) split a double-word
1511 move in mode MODE from SRC to DST into two single-word
1512 moves, moving the subword FIRST_SUBWORD first. */
1515 s390_split_ok_p (rtx dst
, rtx src
, machine_mode mode
, int first_subword
)
1517 /* Floating point registers cannot be split. */
1518 if (FP_REG_P (src
) || FP_REG_P (dst
))
1521 /* We don't need to split if operands are directly accessible. */
1522 if (s_operand (src
, mode
) || s_operand (dst
, mode
))
1525 /* Non-offsettable memory references cannot be split. */
1526 if ((GET_CODE (src
) == MEM
&& !offsettable_memref_p (src
))
1527 || (GET_CODE (dst
) == MEM
&& !offsettable_memref_p (dst
)))
1530 /* Moving the first subword must not clobber a register
1531 needed to move the second subword. */
1532 if (register_operand (dst
, mode
))
1534 rtx subreg
= operand_subword (dst
, first_subword
, 0, mode
);
1535 if (reg_overlap_mentioned_p (subreg
, src
))
1542 /* Return true if it can be proven that [MEM1, MEM1 + SIZE]
1543 and [MEM2, MEM2 + SIZE] do overlap and false
1547 s390_overlap_p (rtx mem1
, rtx mem2
, HOST_WIDE_INT size
)
1549 rtx addr1
, addr2
, addr_delta
;
1550 HOST_WIDE_INT delta
;
1552 if (GET_CODE (mem1
) != MEM
|| GET_CODE (mem2
) != MEM
)
1558 addr1
= XEXP (mem1
, 0);
1559 addr2
= XEXP (mem2
, 0);
1561 addr_delta
= simplify_binary_operation (MINUS
, Pmode
, addr2
, addr1
);
1563 /* This overlapping check is used by peepholes merging memory block operations.
1564 Overlapping operations would otherwise be recognized by the S/390 hardware
1565 and would fall back to a slower implementation. Allowing overlapping
1566 operations would lead to slow code but not to wrong code. Therefore we are
1567 somewhat optimistic if we cannot prove that the memory blocks are
1569 That's why we return false here although this may accept operations on
1570 overlapping memory areas. */
1571 if (!addr_delta
|| GET_CODE (addr_delta
) != CONST_INT
)
1574 delta
= INTVAL (addr_delta
);
1577 || (delta
> 0 && delta
< size
)
1578 || (delta
< 0 && -delta
< size
))
1584 /* Check whether the address of memory reference MEM2 equals exactly
1585 the address of memory reference MEM1 plus DELTA. Return true if
1586 we can prove this to be the case, false otherwise. */
1589 s390_offset_p (rtx mem1
, rtx mem2
, rtx delta
)
1591 rtx addr1
, addr2
, addr_delta
;
1593 if (GET_CODE (mem1
) != MEM
|| GET_CODE (mem2
) != MEM
)
1596 addr1
= XEXP (mem1
, 0);
1597 addr2
= XEXP (mem2
, 0);
1599 addr_delta
= simplify_binary_operation (MINUS
, Pmode
, addr2
, addr1
);
1600 if (!addr_delta
|| !rtx_equal_p (addr_delta
, delta
))
1606 /* Expand logical operator CODE in mode MODE with operands OPERANDS. */
1609 s390_expand_logical_operator (enum rtx_code code
, machine_mode mode
,
1612 machine_mode wmode
= mode
;
1613 rtx dst
= operands
[0];
1614 rtx src1
= operands
[1];
1615 rtx src2
= operands
[2];
1618 /* If we cannot handle the operation directly, use a temp register. */
1619 if (!s390_logical_operator_ok_p (operands
))
1620 dst
= gen_reg_rtx (mode
);
1622 /* QImode and HImode patterns make sense only if we have a destination
1623 in memory. Otherwise perform the operation in SImode. */
1624 if ((mode
== QImode
|| mode
== HImode
) && GET_CODE (dst
) != MEM
)
1627 /* Widen operands if required. */
1630 if (GET_CODE (dst
) == SUBREG
1631 && (tem
= simplify_subreg (wmode
, dst
, mode
, 0)) != 0)
1633 else if (REG_P (dst
))
1634 dst
= gen_rtx_SUBREG (wmode
, dst
, 0);
1636 dst
= gen_reg_rtx (wmode
);
1638 if (GET_CODE (src1
) == SUBREG
1639 && (tem
= simplify_subreg (wmode
, src1
, mode
, 0)) != 0)
1641 else if (GET_MODE (src1
) != VOIDmode
)
1642 src1
= gen_rtx_SUBREG (wmode
, force_reg (mode
, src1
), 0);
1644 if (GET_CODE (src2
) == SUBREG
1645 && (tem
= simplify_subreg (wmode
, src2
, mode
, 0)) != 0)
1647 else if (GET_MODE (src2
) != VOIDmode
)
1648 src2
= gen_rtx_SUBREG (wmode
, force_reg (mode
, src2
), 0);
1651 /* Emit the instruction. */
1652 op
= gen_rtx_SET (VOIDmode
, dst
, gen_rtx_fmt_ee (code
, wmode
, src1
, src2
));
1653 clob
= gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
1654 emit_insn (gen_rtx_PARALLEL (VOIDmode
, gen_rtvec (2, op
, clob
)));
1656 /* Fix up the destination if needed. */
1657 if (dst
!= operands
[0])
1658 emit_move_insn (operands
[0], gen_lowpart (mode
, dst
));
1661 /* Check whether OPERANDS are OK for a logical operation (AND, IOR, XOR). */
1664 s390_logical_operator_ok_p (rtx
*operands
)
1666 /* If the destination operand is in memory, it needs to coincide
1667 with one of the source operands. After reload, it has to be
1668 the first source operand. */
1669 if (GET_CODE (operands
[0]) == MEM
)
1670 return rtx_equal_p (operands
[0], operands
[1])
1671 || (!reload_completed
&& rtx_equal_p (operands
[0], operands
[2]));
1676 /* Narrow logical operation CODE of memory operand MEMOP with immediate
1677 operand IMMOP to switch from SS to SI type instructions. */
1680 s390_narrow_logical_operator (enum rtx_code code
, rtx
*memop
, rtx
*immop
)
1682 int def
= code
== AND
? -1 : 0;
1686 gcc_assert (GET_CODE (*memop
) == MEM
);
1687 gcc_assert (!MEM_VOLATILE_P (*memop
));
1689 mask
= s390_extract_part (*immop
, QImode
, def
);
1690 part
= s390_single_part (*immop
, GET_MODE (*memop
), QImode
, def
);
1691 gcc_assert (part
>= 0);
1693 *memop
= adjust_address (*memop
, QImode
, part
);
1694 *immop
= gen_int_mode (mask
, QImode
);
1698 /* How to allocate a 'struct machine_function'. */
1700 static struct machine_function
*
1701 s390_init_machine_status (void)
1703 return ggc_cleared_alloc
<machine_function
> ();
1706 /* Map for smallest class containing reg regno. */
1708 const enum reg_class regclass_map
[FIRST_PSEUDO_REGISTER
] =
1709 { GENERAL_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1710 ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1711 ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1712 ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1713 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1714 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1715 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1716 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1717 ADDR_REGS
, CC_REGS
, ADDR_REGS
, ADDR_REGS
,
1718 ACCESS_REGS
, ACCESS_REGS
1721 /* Return attribute type of insn. */
1723 static enum attr_type
1724 s390_safe_attr_type (rtx_insn
*insn
)
1726 if (recog_memoized (insn
) >= 0)
1727 return get_attr_type (insn
);
1732 /* Return true if DISP is a valid short displacement. */
1735 s390_short_displacement (rtx disp
)
1737 /* No displacement is OK. */
1741 /* Without the long displacement facility we don't need to
1742 distingiush between long and short displacement. */
1743 if (!TARGET_LONG_DISPLACEMENT
)
1746 /* Integer displacement in range. */
1747 if (GET_CODE (disp
) == CONST_INT
)
1748 return INTVAL (disp
) >= 0 && INTVAL (disp
) < 4096;
1750 /* GOT offset is not OK, the GOT can be large. */
1751 if (GET_CODE (disp
) == CONST
1752 && GET_CODE (XEXP (disp
, 0)) == UNSPEC
1753 && (XINT (XEXP (disp
, 0), 1) == UNSPEC_GOT
1754 || XINT (XEXP (disp
, 0), 1) == UNSPEC_GOTNTPOFF
))
1757 /* All other symbolic constants are literal pool references,
1758 which are OK as the literal pool must be small. */
1759 if (GET_CODE (disp
) == CONST
)
1765 /* Decompose a RTL expression ADDR for a memory address into
1766 its components, returned in OUT.
1768 Returns false if ADDR is not a valid memory address, true
1769 otherwise. If OUT is NULL, don't return the components,
1770 but check for validity only.
1772 Note: Only addresses in canonical form are recognized.
1773 LEGITIMIZE_ADDRESS should convert non-canonical forms to the
1774 canonical form so that they will be recognized. */
1777 s390_decompose_address (rtx addr
, struct s390_address
*out
)
1779 HOST_WIDE_INT offset
= 0;
1780 rtx base
= NULL_RTX
;
1781 rtx indx
= NULL_RTX
;
1782 rtx disp
= NULL_RTX
;
1784 bool pointer
= false;
1785 bool base_ptr
= false;
1786 bool indx_ptr
= false;
1787 bool literal_pool
= false;
1789 /* We may need to substitute the literal pool base register into the address
1790 below. However, at this point we do not know which register is going to
1791 be used as base, so we substitute the arg pointer register. This is going
1792 to be treated as holding a pointer below -- it shouldn't be used for any
1794 rtx fake_pool_base
= gen_rtx_REG (Pmode
, ARG_POINTER_REGNUM
);
1796 /* Decompose address into base + index + displacement. */
1798 if (GET_CODE (addr
) == REG
|| GET_CODE (addr
) == UNSPEC
)
1801 else if (GET_CODE (addr
) == PLUS
)
1803 rtx op0
= XEXP (addr
, 0);
1804 rtx op1
= XEXP (addr
, 1);
1805 enum rtx_code code0
= GET_CODE (op0
);
1806 enum rtx_code code1
= GET_CODE (op1
);
1808 if (code0
== REG
|| code0
== UNSPEC
)
1810 if (code1
== REG
|| code1
== UNSPEC
)
1812 indx
= op0
; /* index + base */
1818 base
= op0
; /* base + displacement */
1823 else if (code0
== PLUS
)
1825 indx
= XEXP (op0
, 0); /* index + base + disp */
1826 base
= XEXP (op0
, 1);
1837 disp
= addr
; /* displacement */
1839 /* Extract integer part of displacement. */
1843 if (GET_CODE (disp
) == CONST_INT
)
1845 offset
= INTVAL (disp
);
1848 else if (GET_CODE (disp
) == CONST
1849 && GET_CODE (XEXP (disp
, 0)) == PLUS
1850 && GET_CODE (XEXP (XEXP (disp
, 0), 1)) == CONST_INT
)
1852 offset
= INTVAL (XEXP (XEXP (disp
, 0), 1));
1853 disp
= XEXP (XEXP (disp
, 0), 0);
1857 /* Strip off CONST here to avoid special case tests later. */
1858 if (disp
&& GET_CODE (disp
) == CONST
)
1859 disp
= XEXP (disp
, 0);
1861 /* We can convert literal pool addresses to
1862 displacements by basing them off the base register. */
1863 if (disp
&& GET_CODE (disp
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (disp
))
1865 /* Either base or index must be free to hold the base register. */
1867 base
= fake_pool_base
, literal_pool
= true;
1869 indx
= fake_pool_base
, literal_pool
= true;
1873 /* Mark up the displacement. */
1874 disp
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, disp
),
1875 UNSPEC_LTREL_OFFSET
);
1878 /* Validate base register. */
1881 if (GET_CODE (base
) == UNSPEC
)
1882 switch (XINT (base
, 1))
1886 disp
= gen_rtx_UNSPEC (Pmode
,
1887 gen_rtvec (1, XVECEXP (base
, 0, 0)),
1888 UNSPEC_LTREL_OFFSET
);
1892 base
= XVECEXP (base
, 0, 1);
1895 case UNSPEC_LTREL_BASE
:
1896 if (XVECLEN (base
, 0) == 1)
1897 base
= fake_pool_base
, literal_pool
= true;
1899 base
= XVECEXP (base
, 0, 1);
1907 || (GET_MODE (base
) != SImode
1908 && GET_MODE (base
) != Pmode
))
1911 if (REGNO (base
) == STACK_POINTER_REGNUM
1912 || REGNO (base
) == FRAME_POINTER_REGNUM
1913 || ((reload_completed
|| reload_in_progress
)
1914 && frame_pointer_needed
1915 && REGNO (base
) == HARD_FRAME_POINTER_REGNUM
)
1916 || REGNO (base
) == ARG_POINTER_REGNUM
1918 && REGNO (base
) == PIC_OFFSET_TABLE_REGNUM
))
1919 pointer
= base_ptr
= true;
1921 if ((reload_completed
|| reload_in_progress
)
1922 && base
== cfun
->machine
->base_reg
)
1923 pointer
= base_ptr
= literal_pool
= true;
1926 /* Validate index register. */
1929 if (GET_CODE (indx
) == UNSPEC
)
1930 switch (XINT (indx
, 1))
1934 disp
= gen_rtx_UNSPEC (Pmode
,
1935 gen_rtvec (1, XVECEXP (indx
, 0, 0)),
1936 UNSPEC_LTREL_OFFSET
);
1940 indx
= XVECEXP (indx
, 0, 1);
1943 case UNSPEC_LTREL_BASE
:
1944 if (XVECLEN (indx
, 0) == 1)
1945 indx
= fake_pool_base
, literal_pool
= true;
1947 indx
= XVECEXP (indx
, 0, 1);
1955 || (GET_MODE (indx
) != SImode
1956 && GET_MODE (indx
) != Pmode
))
1959 if (REGNO (indx
) == STACK_POINTER_REGNUM
1960 || REGNO (indx
) == FRAME_POINTER_REGNUM
1961 || ((reload_completed
|| reload_in_progress
)
1962 && frame_pointer_needed
1963 && REGNO (indx
) == HARD_FRAME_POINTER_REGNUM
)
1964 || REGNO (indx
) == ARG_POINTER_REGNUM
1966 && REGNO (indx
) == PIC_OFFSET_TABLE_REGNUM
))
1967 pointer
= indx_ptr
= true;
1969 if ((reload_completed
|| reload_in_progress
)
1970 && indx
== cfun
->machine
->base_reg
)
1971 pointer
= indx_ptr
= literal_pool
= true;
1974 /* Prefer to use pointer as base, not index. */
1975 if (base
&& indx
&& !base_ptr
1976 && (indx_ptr
|| (!REG_POINTER (base
) && REG_POINTER (indx
))))
1983 /* Validate displacement. */
1986 /* If virtual registers are involved, the displacement will change later
1987 anyway as the virtual registers get eliminated. This could make a
1988 valid displacement invalid, but it is more likely to make an invalid
1989 displacement valid, because we sometimes access the register save area
1990 via negative offsets to one of those registers.
1991 Thus we don't check the displacement for validity here. If after
1992 elimination the displacement turns out to be invalid after all,
1993 this is fixed up by reload in any case. */
1994 /* LRA maintains always displacements up to date and we need to
1995 know the displacement is right during all LRA not only at the
1996 final elimination. */
1998 || (base
!= arg_pointer_rtx
1999 && indx
!= arg_pointer_rtx
2000 && base
!= return_address_pointer_rtx
2001 && indx
!= return_address_pointer_rtx
2002 && base
!= frame_pointer_rtx
2003 && indx
!= frame_pointer_rtx
2004 && base
!= virtual_stack_vars_rtx
2005 && indx
!= virtual_stack_vars_rtx
))
2006 if (!DISP_IN_RANGE (offset
))
2011 /* All the special cases are pointers. */
2014 /* In the small-PIC case, the linker converts @GOT
2015 and @GOTNTPOFF offsets to possible displacements. */
2016 if (GET_CODE (disp
) == UNSPEC
2017 && (XINT (disp
, 1) == UNSPEC_GOT
2018 || XINT (disp
, 1) == UNSPEC_GOTNTPOFF
)
2024 /* Accept pool label offsets. */
2025 else if (GET_CODE (disp
) == UNSPEC
2026 && XINT (disp
, 1) == UNSPEC_POOL_OFFSET
)
2029 /* Accept literal pool references. */
2030 else if (GET_CODE (disp
) == UNSPEC
2031 && XINT (disp
, 1) == UNSPEC_LTREL_OFFSET
)
2033 /* In case CSE pulled a non literal pool reference out of
2034 the pool we have to reject the address. This is
2035 especially important when loading the GOT pointer on non
2036 zarch CPUs. In this case the literal pool contains an lt
2037 relative offset to the _GLOBAL_OFFSET_TABLE_ label which
2038 will most likely exceed the displacement. */
2039 if (GET_CODE (XVECEXP (disp
, 0, 0)) != SYMBOL_REF
2040 || !CONSTANT_POOL_ADDRESS_P (XVECEXP (disp
, 0, 0)))
2043 orig_disp
= gen_rtx_CONST (Pmode
, disp
);
2046 /* If we have an offset, make sure it does not
2047 exceed the size of the constant pool entry. */
2048 rtx sym
= XVECEXP (disp
, 0, 0);
2049 if (offset
>= GET_MODE_SIZE (get_pool_mode (sym
)))
2052 orig_disp
= plus_constant (Pmode
, orig_disp
, offset
);
2067 out
->disp
= orig_disp
;
2068 out
->pointer
= pointer
;
2069 out
->literal_pool
= literal_pool
;
2075 /* Decompose a RTL expression OP for a shift count into its components,
2076 and return the base register in BASE and the offset in OFFSET.
2078 Return true if OP is a valid shift count, false if not. */
2081 s390_decompose_shift_count (rtx op
, rtx
*base
, HOST_WIDE_INT
*offset
)
2083 HOST_WIDE_INT off
= 0;
2085 /* We can have an integer constant, an address register,
2086 or a sum of the two. */
2087 if (GET_CODE (op
) == CONST_INT
)
2092 if (op
&& GET_CODE (op
) == PLUS
&& GET_CODE (XEXP (op
, 1)) == CONST_INT
)
2094 off
= INTVAL (XEXP (op
, 1));
2097 while (op
&& GET_CODE (op
) == SUBREG
)
2098 op
= SUBREG_REG (op
);
2100 if (op
&& GET_CODE (op
) != REG
)
2112 /* Return true if CODE is a valid address without index. */
2115 s390_legitimate_address_without_index_p (rtx op
)
2117 struct s390_address addr
;
2119 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
2128 /* Return TRUE if ADDR is an operand valid for a load/store relative
2129 instruction. Be aware that the alignment of the operand needs to
2130 be checked separately.
2131 Valid addresses are single references or a sum of a reference and a
2132 constant integer. Return these parts in SYMREF and ADDEND. You can
2133 pass NULL in REF and/or ADDEND if you are not interested in these
2134 values. Literal pool references are *not* considered symbol
2138 s390_loadrelative_operand_p (rtx addr
, rtx
*symref
, HOST_WIDE_INT
*addend
)
2140 HOST_WIDE_INT tmpaddend
= 0;
2142 if (GET_CODE (addr
) == CONST
)
2143 addr
= XEXP (addr
, 0);
2145 if (GET_CODE (addr
) == PLUS
)
2147 if (!CONST_INT_P (XEXP (addr
, 1)))
2150 tmpaddend
= INTVAL (XEXP (addr
, 1));
2151 addr
= XEXP (addr
, 0);
2154 if ((GET_CODE (addr
) == SYMBOL_REF
&& !CONSTANT_POOL_ADDRESS_P (addr
))
2155 || (GET_CODE (addr
) == UNSPEC
2156 && (XINT (addr
, 1) == UNSPEC_GOTENT
2157 || (TARGET_CPU_ZARCH
&& XINT (addr
, 1) == UNSPEC_PLT
))))
2162 *addend
= tmpaddend
;
2169 /* Return true if the address in OP is valid for constraint letter C
2170 if wrapped in a MEM rtx. Set LIT_POOL_OK to true if it literal
2171 pool MEMs should be accepted. Only the Q, R, S, T constraint
2172 letters are allowed for C. */
2175 s390_check_qrst_address (char c
, rtx op
, bool lit_pool_ok
)
2177 struct s390_address addr
;
2178 bool decomposed
= false;
2180 /* This check makes sure that no symbolic address (except literal
2181 pool references) are accepted by the R or T constraints. */
2182 if (s390_loadrelative_operand_p (op
, NULL
, NULL
))
2185 /* Ensure literal pool references are only accepted if LIT_POOL_OK. */
2188 if (!s390_decompose_address (op
, &addr
))
2190 if (addr
.literal_pool
)
2197 case 'Q': /* no index short displacement */
2198 if (!decomposed
&& !s390_decompose_address (op
, &addr
))
2202 if (!s390_short_displacement (addr
.disp
))
2206 case 'R': /* with index short displacement */
2207 if (TARGET_LONG_DISPLACEMENT
)
2209 if (!decomposed
&& !s390_decompose_address (op
, &addr
))
2211 if (!s390_short_displacement (addr
.disp
))
2214 /* Any invalid address here will be fixed up by reload,
2215 so accept it for the most generic constraint. */
2218 case 'S': /* no index long displacement */
2219 if (!TARGET_LONG_DISPLACEMENT
)
2221 if (!decomposed
&& !s390_decompose_address (op
, &addr
))
2225 if (s390_short_displacement (addr
.disp
))
2229 case 'T': /* with index long displacement */
2230 if (!TARGET_LONG_DISPLACEMENT
)
2232 /* Any invalid address here will be fixed up by reload,
2233 so accept it for the most generic constraint. */
2234 if ((decomposed
|| s390_decompose_address (op
, &addr
))
2235 && s390_short_displacement (addr
.disp
))
2245 /* Evaluates constraint strings described by the regular expression
2246 ([A|B|Z](Q|R|S|T))|U|W|Y and returns 1 if OP is a valid operand for
2247 the constraint given in STR, or 0 else. */
2250 s390_mem_constraint (const char *str
, rtx op
)
2257 /* Check for offsettable variants of memory constraints. */
2258 if (!MEM_P (op
) || MEM_VOLATILE_P (op
))
2260 if ((reload_completed
|| reload_in_progress
)
2261 ? !offsettable_memref_p (op
) : !offsettable_nonstrict_memref_p (op
))
2263 return s390_check_qrst_address (str
[1], XEXP (op
, 0), true);
2265 /* Check for non-literal-pool variants of memory constraints. */
2268 return s390_check_qrst_address (str
[1], XEXP (op
, 0), false);
2273 if (GET_CODE (op
) != MEM
)
2275 return s390_check_qrst_address (c
, XEXP (op
, 0), true);
2277 return (s390_check_qrst_address ('Q', op
, true)
2278 || s390_check_qrst_address ('R', op
, true));
2280 return (s390_check_qrst_address ('S', op
, true)
2281 || s390_check_qrst_address ('T', op
, true));
2283 /* Simply check for the basic form of a shift count. Reload will
2284 take care of making sure we have a proper base register. */
2285 if (!s390_decompose_shift_count (op
, NULL
, NULL
))
2289 return s390_check_qrst_address (str
[1], op
, true);
2297 /* Evaluates constraint strings starting with letter O. Input
2298 parameter C is the second letter following the "O" in the constraint
2299 string. Returns 1 if VALUE meets the respective constraint and 0
2303 s390_O_constraint_str (const char c
, HOST_WIDE_INT value
)
2311 return trunc_int_for_mode (value
, SImode
) == value
;
2315 || s390_single_part (GEN_INT (value
), DImode
, SImode
, 0) == 1;
2318 return s390_single_part (GEN_INT (value
- 1), DImode
, SImode
, -1) == 1;
2326 /* Evaluates constraint strings starting with letter N. Parameter STR
2327 contains the letters following letter "N" in the constraint string.
2328 Returns true if VALUE matches the constraint. */
2331 s390_N_constraint_str (const char *str
, HOST_WIDE_INT value
)
2333 machine_mode mode
, part_mode
;
2335 int part
, part_goal
;
2341 part_goal
= str
[0] - '0';
2385 if (GET_MODE_SIZE (mode
) <= GET_MODE_SIZE (part_mode
))
2388 part
= s390_single_part (GEN_INT (value
), mode
, part_mode
, def
);
2391 if (part_goal
!= -1 && part_goal
!= part
)
2398 /* Returns true if the input parameter VALUE is a float zero. */
2401 s390_float_const_zero_p (rtx value
)
2403 return (GET_MODE_CLASS (GET_MODE (value
)) == MODE_FLOAT
2404 && value
== CONST0_RTX (GET_MODE (value
)));
2407 /* Implement TARGET_REGISTER_MOVE_COST. */
2410 s390_register_move_cost (machine_mode mode ATTRIBUTE_UNUSED
,
2411 reg_class_t from
, reg_class_t to
)
2413 /* On s390, copy between fprs and gprs is expensive as long as no
2414 ldgr/lgdr can be used. */
2415 if ((!TARGET_Z10
|| GET_MODE_SIZE (mode
) != 8)
2416 && ((reg_classes_intersect_p (from
, GENERAL_REGS
)
2417 && reg_classes_intersect_p (to
, FP_REGS
))
2418 || (reg_classes_intersect_p (from
, FP_REGS
)
2419 && reg_classes_intersect_p (to
, GENERAL_REGS
))))
2425 /* Implement TARGET_MEMORY_MOVE_COST. */
2428 s390_memory_move_cost (machine_mode mode ATTRIBUTE_UNUSED
,
2429 reg_class_t rclass ATTRIBUTE_UNUSED
,
2430 bool in ATTRIBUTE_UNUSED
)
2435 /* Compute a (partial) cost for rtx X. Return true if the complete
2436 cost has been computed, and false if subexpressions should be
2437 scanned. In either case, *TOTAL contains the cost result.
2438 CODE contains GET_CODE (x), OUTER_CODE contains the code
2439 of the superexpression of x. */
2442 s390_rtx_costs (rtx x
, int code
, int outer_code
, int opno ATTRIBUTE_UNUSED
,
2443 int *total
, bool speed ATTRIBUTE_UNUSED
)
2466 *total
= COSTS_N_INSNS (1);
2471 *total
= COSTS_N_INSNS (1);
2475 switch (GET_MODE (x
))
2479 rtx left
= XEXP (x
, 0);
2480 rtx right
= XEXP (x
, 1);
2481 if (GET_CODE (right
) == CONST_INT
2482 && CONST_OK_FOR_K (INTVAL (right
)))
2483 *total
= s390_cost
->mhi
;
2484 else if (GET_CODE (left
) == SIGN_EXTEND
)
2485 *total
= s390_cost
->mh
;
2487 *total
= s390_cost
->ms
; /* msr, ms, msy */
2492 rtx left
= XEXP (x
, 0);
2493 rtx right
= XEXP (x
, 1);
2496 if (GET_CODE (right
) == CONST_INT
2497 && CONST_OK_FOR_K (INTVAL (right
)))
2498 *total
= s390_cost
->mghi
;
2499 else if (GET_CODE (left
) == SIGN_EXTEND
)
2500 *total
= s390_cost
->msgf
;
2502 *total
= s390_cost
->msg
; /* msgr, msg */
2504 else /* TARGET_31BIT */
2506 if (GET_CODE (left
) == SIGN_EXTEND
2507 && GET_CODE (right
) == SIGN_EXTEND
)
2508 /* mulsidi case: mr, m */
2509 *total
= s390_cost
->m
;
2510 else if (GET_CODE (left
) == ZERO_EXTEND
2511 && GET_CODE (right
) == ZERO_EXTEND
2512 && TARGET_CPU_ZARCH
)
2513 /* umulsidi case: ml, mlr */
2514 *total
= s390_cost
->ml
;
2516 /* Complex calculation is required. */
2517 *total
= COSTS_N_INSNS (40);
2523 *total
= s390_cost
->mult_df
;
2526 *total
= s390_cost
->mxbr
;
2534 switch (GET_MODE (x
))
2537 *total
= s390_cost
->madbr
;
2540 *total
= s390_cost
->maebr
;
2545 /* Negate in the third argument is free: FMSUB. */
2546 if (GET_CODE (XEXP (x
, 2)) == NEG
)
2548 *total
+= (rtx_cost (XEXP (x
, 0), FMA
, 0, speed
)
2549 + rtx_cost (XEXP (x
, 1), FMA
, 1, speed
)
2550 + rtx_cost (XEXP (XEXP (x
, 2), 0), FMA
, 2, speed
));
2557 if (GET_MODE (x
) == TImode
) /* 128 bit division */
2558 *total
= s390_cost
->dlgr
;
2559 else if (GET_MODE (x
) == DImode
)
2561 rtx right
= XEXP (x
, 1);
2562 if (GET_CODE (right
) == ZERO_EXTEND
) /* 64 by 32 bit division */
2563 *total
= s390_cost
->dlr
;
2564 else /* 64 by 64 bit division */
2565 *total
= s390_cost
->dlgr
;
2567 else if (GET_MODE (x
) == SImode
) /* 32 bit division */
2568 *total
= s390_cost
->dlr
;
2573 if (GET_MODE (x
) == DImode
)
2575 rtx right
= XEXP (x
, 1);
2576 if (GET_CODE (right
) == ZERO_EXTEND
) /* 64 by 32 bit division */
2578 *total
= s390_cost
->dsgfr
;
2580 *total
= s390_cost
->dr
;
2581 else /* 64 by 64 bit division */
2582 *total
= s390_cost
->dsgr
;
2584 else if (GET_MODE (x
) == SImode
) /* 32 bit division */
2585 *total
= s390_cost
->dlr
;
2586 else if (GET_MODE (x
) == SFmode
)
2588 *total
= s390_cost
->debr
;
2590 else if (GET_MODE (x
) == DFmode
)
2592 *total
= s390_cost
->ddbr
;
2594 else if (GET_MODE (x
) == TFmode
)
2596 *total
= s390_cost
->dxbr
;
2601 if (GET_MODE (x
) == SFmode
)
2602 *total
= s390_cost
->sqebr
;
2603 else if (GET_MODE (x
) == DFmode
)
2604 *total
= s390_cost
->sqdbr
;
2606 *total
= s390_cost
->sqxbr
;
2611 if (outer_code
== MULT
|| outer_code
== DIV
|| outer_code
== MOD
2612 || outer_code
== PLUS
|| outer_code
== MINUS
2613 || outer_code
== COMPARE
)
2618 *total
= COSTS_N_INSNS (1);
2619 if (GET_CODE (XEXP (x
, 0)) == AND
2620 && GET_CODE (XEXP (x
, 1)) == CONST_INT
2621 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
)
2623 rtx op0
= XEXP (XEXP (x
, 0), 0);
2624 rtx op1
= XEXP (XEXP (x
, 0), 1);
2625 rtx op2
= XEXP (x
, 1);
2627 if (memory_operand (op0
, GET_MODE (op0
))
2628 && s390_tm_ccmode (op1
, op2
, 0) != VOIDmode
)
2630 if (register_operand (op0
, GET_MODE (op0
))
2631 && s390_tm_ccmode (op1
, op2
, 1) != VOIDmode
)
2641 /* Return the cost of an address rtx ADDR. */
2644 s390_address_cost (rtx addr
, machine_mode mode ATTRIBUTE_UNUSED
,
2645 addr_space_t as ATTRIBUTE_UNUSED
,
2646 bool speed ATTRIBUTE_UNUSED
)
2648 struct s390_address ad
;
2649 if (!s390_decompose_address (addr
, &ad
))
2652 return ad
.indx
? COSTS_N_INSNS (1) + 1 : COSTS_N_INSNS (1);
2655 /* If OP is a SYMBOL_REF of a thread-local symbol, return its TLS mode,
2656 otherwise return 0. */
2659 tls_symbolic_operand (rtx op
)
2661 if (GET_CODE (op
) != SYMBOL_REF
)
2663 return SYMBOL_REF_TLS_MODEL (op
);
2666 /* Split DImode access register reference REG (on 64-bit) into its constituent
2667 low and high parts, and store them into LO and HI. Note that gen_lowpart/
2668 gen_highpart cannot be used as they assume all registers are word-sized,
2669 while our access registers have only half that size. */
2672 s390_split_access_reg (rtx reg
, rtx
*lo
, rtx
*hi
)
2674 gcc_assert (TARGET_64BIT
);
2675 gcc_assert (ACCESS_REG_P (reg
));
2676 gcc_assert (GET_MODE (reg
) == DImode
);
2677 gcc_assert (!(REGNO (reg
) & 1));
2679 *lo
= gen_rtx_REG (SImode
, REGNO (reg
) + 1);
2680 *hi
= gen_rtx_REG (SImode
, REGNO (reg
));
2683 /* Return true if OP contains a symbol reference */
2686 symbolic_reference_mentioned_p (rtx op
)
2691 if (GET_CODE (op
) == SYMBOL_REF
|| GET_CODE (op
) == LABEL_REF
)
2694 fmt
= GET_RTX_FORMAT (GET_CODE (op
));
2695 for (i
= GET_RTX_LENGTH (GET_CODE (op
)) - 1; i
>= 0; i
--)
2701 for (j
= XVECLEN (op
, i
) - 1; j
>= 0; j
--)
2702 if (symbolic_reference_mentioned_p (XVECEXP (op
, i
, j
)))
2706 else if (fmt
[i
] == 'e' && symbolic_reference_mentioned_p (XEXP (op
, i
)))
2713 /* Return true if OP contains a reference to a thread-local symbol. */
2716 tls_symbolic_reference_mentioned_p (rtx op
)
2721 if (GET_CODE (op
) == SYMBOL_REF
)
2722 return tls_symbolic_operand (op
);
2724 fmt
= GET_RTX_FORMAT (GET_CODE (op
));
2725 for (i
= GET_RTX_LENGTH (GET_CODE (op
)) - 1; i
>= 0; i
--)
2731 for (j
= XVECLEN (op
, i
) - 1; j
>= 0; j
--)
2732 if (tls_symbolic_reference_mentioned_p (XVECEXP (op
, i
, j
)))
2736 else if (fmt
[i
] == 'e' && tls_symbolic_reference_mentioned_p (XEXP (op
, i
)))
2744 /* Return true if OP is a legitimate general operand when
2745 generating PIC code. It is given that flag_pic is on
2746 and that OP satisfies CONSTANT_P or is a CONST_DOUBLE. */
2749 legitimate_pic_operand_p (rtx op
)
2751 /* Accept all non-symbolic constants. */
2752 if (!SYMBOLIC_CONST (op
))
2755 /* Reject everything else; must be handled
2756 via emit_symbolic_move. */
2760 /* Returns true if the constant value OP is a legitimate general operand.
2761 It is given that OP satisfies CONSTANT_P or is a CONST_DOUBLE. */
2764 s390_legitimate_constant_p (machine_mode mode
, rtx op
)
2766 /* Accept all non-symbolic constants. */
2767 if (!SYMBOLIC_CONST (op
))
2770 /* Accept immediate LARL operands. */
2771 if (TARGET_CPU_ZARCH
&& larl_operand (op
, mode
))
2774 /* Thread-local symbols are never legal constants. This is
2775 so that emit_call knows that computing such addresses
2776 might require a function call. */
2777 if (TLS_SYMBOLIC_CONST (op
))
2780 /* In the PIC case, symbolic constants must *not* be
2781 forced into the literal pool. We accept them here,
2782 so that they will be handled by emit_symbolic_move. */
2786 /* All remaining non-PIC symbolic constants are
2787 forced into the literal pool. */
2791 /* Determine if it's legal to put X into the constant pool. This
2792 is not possible if X contains the address of a symbol that is
2793 not constant (TLS) or not known at final link time (PIC). */
2796 s390_cannot_force_const_mem (machine_mode mode
, rtx x
)
2798 switch (GET_CODE (x
))
2802 /* Accept all non-symbolic constants. */
2806 /* Labels are OK iff we are non-PIC. */
2807 return flag_pic
!= 0;
2810 /* 'Naked' TLS symbol references are never OK,
2811 non-TLS symbols are OK iff we are non-PIC. */
2812 if (tls_symbolic_operand (x
))
2815 return flag_pic
!= 0;
2818 return s390_cannot_force_const_mem (mode
, XEXP (x
, 0));
2821 return s390_cannot_force_const_mem (mode
, XEXP (x
, 0))
2822 || s390_cannot_force_const_mem (mode
, XEXP (x
, 1));
2825 switch (XINT (x
, 1))
2827 /* Only lt-relative or GOT-relative UNSPECs are OK. */
2828 case UNSPEC_LTREL_OFFSET
:
2836 case UNSPEC_GOTNTPOFF
:
2837 case UNSPEC_INDNTPOFF
:
2840 /* If the literal pool shares the code section, be put
2841 execute template placeholders into the pool as well. */
2843 return TARGET_CPU_ZARCH
;
2855 /* Returns true if the constant value OP is a legitimate general
2856 operand during and after reload. The difference to
2857 legitimate_constant_p is that this function will not accept
2858 a constant that would need to be forced to the literal pool
2859 before it can be used as operand.
2860 This function accepts all constants which can be loaded directly
2864 legitimate_reload_constant_p (rtx op
)
2866 /* Accept la(y) operands. */
2867 if (GET_CODE (op
) == CONST_INT
2868 && DISP_IN_RANGE (INTVAL (op
)))
2871 /* Accept l(g)hi/l(g)fi operands. */
2872 if (GET_CODE (op
) == CONST_INT
2873 && (CONST_OK_FOR_K (INTVAL (op
)) || CONST_OK_FOR_Os (INTVAL (op
))))
2876 /* Accept lliXX operands. */
2878 && GET_CODE (op
) == CONST_INT
2879 && trunc_int_for_mode (INTVAL (op
), word_mode
) == INTVAL (op
)
2880 && s390_single_part (op
, word_mode
, HImode
, 0) >= 0)
2884 && GET_CODE (op
) == CONST_INT
2885 && trunc_int_for_mode (INTVAL (op
), word_mode
) == INTVAL (op
)
2886 && s390_single_part (op
, word_mode
, SImode
, 0) >= 0)
2889 /* Accept larl operands. */
2890 if (TARGET_CPU_ZARCH
2891 && larl_operand (op
, VOIDmode
))
2894 /* Accept floating-point zero operands that fit into a single GPR. */
2895 if (GET_CODE (op
) == CONST_DOUBLE
2896 && s390_float_const_zero_p (op
)
2897 && GET_MODE_SIZE (GET_MODE (op
)) <= UNITS_PER_WORD
)
2900 /* Accept double-word operands that can be split. */
2901 if (GET_CODE (op
) == CONST_INT
2902 && trunc_int_for_mode (INTVAL (op
), word_mode
) != INTVAL (op
))
2904 machine_mode dword_mode
= word_mode
== SImode
? DImode
: TImode
;
2905 rtx hi
= operand_subword (op
, 0, 0, dword_mode
);
2906 rtx lo
= operand_subword (op
, 1, 0, dword_mode
);
2907 return legitimate_reload_constant_p (hi
)
2908 && legitimate_reload_constant_p (lo
);
2911 /* Everything else cannot be handled without reload. */
2915 /* Returns true if the constant value OP is a legitimate fp operand
2916 during and after reload.
2917 This function accepts all constants which can be loaded directly
2921 legitimate_reload_fp_constant_p (rtx op
)
2923 /* Accept floating-point zero operands if the load zero instruction
2924 can be used. Prior to z196 the load fp zero instruction caused a
2925 performance penalty if the result is used as BFP number. */
2927 && GET_CODE (op
) == CONST_DOUBLE
2928 && s390_float_const_zero_p (op
))
2934 /* Given an rtx OP being reloaded into a reg required to be in class RCLASS,
2935 return the class of reg to actually use. */
2938 s390_preferred_reload_class (rtx op
, reg_class_t rclass
)
2940 switch (GET_CODE (op
))
2942 /* Constants we cannot reload into general registers
2943 must be forced into the literal pool. */
2946 if (reg_class_subset_p (GENERAL_REGS
, rclass
)
2947 && legitimate_reload_constant_p (op
))
2948 return GENERAL_REGS
;
2949 else if (reg_class_subset_p (ADDR_REGS
, rclass
)
2950 && legitimate_reload_constant_p (op
))
2952 else if (reg_class_subset_p (FP_REGS
, rclass
)
2953 && legitimate_reload_fp_constant_p (op
))
2957 /* If a symbolic constant or a PLUS is reloaded,
2958 it is most likely being used as an address, so
2959 prefer ADDR_REGS. If 'class' is not a superset
2960 of ADDR_REGS, e.g. FP_REGS, reject this reload. */
2962 /* Symrefs cannot be pushed into the literal pool with -fPIC
2963 so we *MUST NOT* return NO_REGS for these cases
2964 (s390_cannot_force_const_mem will return true).
2966 On the other hand we MUST return NO_REGS for symrefs with
2967 invalid addend which might have been pushed to the literal
2968 pool (no -fPIC). Usually we would expect them to be
2969 handled via secondary reload but this does not happen if
2970 they are used as literal pool slot replacement in reload
2971 inheritance (see emit_input_reload_insns). */
2972 if (TARGET_CPU_ZARCH
2973 && GET_CODE (XEXP (op
, 0)) == PLUS
2974 && GET_CODE (XEXP (XEXP(op
, 0), 0)) == SYMBOL_REF
2975 && GET_CODE (XEXP (XEXP(op
, 0), 1)) == CONST_INT
)
2977 if (flag_pic
&& reg_class_subset_p (ADDR_REGS
, rclass
))
2985 if (!legitimate_reload_constant_p (op
))
2989 /* load address will be used. */
2990 if (reg_class_subset_p (ADDR_REGS
, rclass
))
3002 /* Return true if ADDR is SYMBOL_REF + addend with addend being a
3003 multiple of ALIGNMENT and the SYMBOL_REF being naturally
3007 s390_check_symref_alignment (rtx addr
, HOST_WIDE_INT alignment
)
3009 HOST_WIDE_INT addend
;
3012 if (!s390_loadrelative_operand_p (addr
, &symref
, &addend
))
3015 if (addend
& (alignment
- 1))
3018 if (GET_CODE (symref
) == SYMBOL_REF
3019 && !SYMBOL_REF_NOT_NATURALLY_ALIGNED_P (symref
))
3022 if (GET_CODE (symref
) == UNSPEC
3023 && alignment
<= UNITS_PER_LONG
)
3029 /* ADDR is moved into REG using larl. If ADDR isn't a valid larl
3030 operand SCRATCH is used to reload the even part of the address and
3034 s390_reload_larl_operand (rtx reg
, rtx addr
, rtx scratch
)
3036 HOST_WIDE_INT addend
;
3039 if (!s390_loadrelative_operand_p (addr
, &symref
, &addend
))
3043 /* Easy case. The addend is even so larl will do fine. */
3044 emit_move_insn (reg
, addr
);
3047 /* We can leave the scratch register untouched if the target
3048 register is a valid base register. */
3049 if (REGNO (reg
) < FIRST_PSEUDO_REGISTER
3050 && REGNO_REG_CLASS (REGNO (reg
)) == ADDR_REGS
)
3053 gcc_assert (REGNO (scratch
) < FIRST_PSEUDO_REGISTER
);
3054 gcc_assert (REGNO_REG_CLASS (REGNO (scratch
)) == ADDR_REGS
);
3057 emit_move_insn (scratch
,
3058 gen_rtx_CONST (Pmode
,
3059 gen_rtx_PLUS (Pmode
, symref
,
3060 GEN_INT (addend
- 1))));
3062 emit_move_insn (scratch
, symref
);
3064 /* Increment the address using la in order to avoid clobbering cc. */
3065 s390_load_address (reg
, gen_rtx_PLUS (Pmode
, scratch
, const1_rtx
));
3069 /* Generate what is necessary to move between REG and MEM using
3070 SCRATCH. The direction is given by TOMEM. */
3073 s390_reload_symref_address (rtx reg
, rtx mem
, rtx scratch
, bool tomem
)
3075 /* Reload might have pulled a constant out of the literal pool.
3076 Force it back in. */
3077 if (CONST_INT_P (mem
) || GET_CODE (mem
) == CONST_DOUBLE
3078 || GET_CODE (mem
) == CONST
)
3079 mem
= force_const_mem (GET_MODE (reg
), mem
);
3081 gcc_assert (MEM_P (mem
));
3083 /* For a load from memory we can leave the scratch register
3084 untouched if the target register is a valid base register. */
3086 && REGNO (reg
) < FIRST_PSEUDO_REGISTER
3087 && REGNO_REG_CLASS (REGNO (reg
)) == ADDR_REGS
3088 && GET_MODE (reg
) == GET_MODE (scratch
))
3091 /* Load address into scratch register. Since we can't have a
3092 secondary reload for a secondary reload we have to cover the case
3093 where larl would need a secondary reload here as well. */
3094 s390_reload_larl_operand (scratch
, XEXP (mem
, 0), scratch
);
3096 /* Now we can use a standard load/store to do the move. */
3098 emit_move_insn (replace_equiv_address (mem
, scratch
), reg
);
3100 emit_move_insn (reg
, replace_equiv_address (mem
, scratch
));
3103 /* Inform reload about cases where moving X with a mode MODE to a register in
3104 RCLASS requires an extra scratch or immediate register. Return the class
3105 needed for the immediate register. */
3108 s390_secondary_reload (bool in_p
, rtx x
, reg_class_t rclass_i
,
3109 machine_mode mode
, secondary_reload_info
*sri
)
3111 enum reg_class rclass
= (enum reg_class
) rclass_i
;
3113 /* Intermediate register needed. */
3114 if (reg_classes_intersect_p (CC_REGS
, rclass
))
3115 return GENERAL_REGS
;
3119 HOST_WIDE_INT offset
;
3122 /* On z10 several optimizer steps may generate larl operands with
3125 && s390_loadrelative_operand_p (x
, &symref
, &offset
)
3127 && !SYMBOL_REF_ALIGN1_P (symref
)
3128 && (offset
& 1) == 1)
3129 sri
->icode
= ((mode
== DImode
) ? CODE_FOR_reloaddi_larl_odd_addend_z10
3130 : CODE_FOR_reloadsi_larl_odd_addend_z10
);
3132 /* On z10 we need a scratch register when moving QI, TI or floating
3133 point mode values from or to a memory location with a SYMBOL_REF
3134 or if the symref addend of a SI or DI move is not aligned to the
3135 width of the access. */
3137 && s390_loadrelative_operand_p (XEXP (x
, 0), NULL
, NULL
)
3138 && (mode
== QImode
|| mode
== TImode
|| FLOAT_MODE_P (mode
)
3139 || (!TARGET_ZARCH
&& mode
== DImode
)
3140 || ((mode
== HImode
|| mode
== SImode
|| mode
== DImode
)
3141 && (!s390_check_symref_alignment (XEXP (x
, 0),
3142 GET_MODE_SIZE (mode
))))))
3144 #define __SECONDARY_RELOAD_CASE(M,m) \
3147 sri->icode = in_p ? CODE_FOR_reload##m##di_toreg_z10 : \
3148 CODE_FOR_reload##m##di_tomem_z10; \
3150 sri->icode = in_p ? CODE_FOR_reload##m##si_toreg_z10 : \
3151 CODE_FOR_reload##m##si_tomem_z10; \
3154 switch (GET_MODE (x
))
3156 __SECONDARY_RELOAD_CASE (QI
, qi
);
3157 __SECONDARY_RELOAD_CASE (HI
, hi
);
3158 __SECONDARY_RELOAD_CASE (SI
, si
);
3159 __SECONDARY_RELOAD_CASE (DI
, di
);
3160 __SECONDARY_RELOAD_CASE (TI
, ti
);
3161 __SECONDARY_RELOAD_CASE (SF
, sf
);
3162 __SECONDARY_RELOAD_CASE (DF
, df
);
3163 __SECONDARY_RELOAD_CASE (TF
, tf
);
3164 __SECONDARY_RELOAD_CASE (SD
, sd
);
3165 __SECONDARY_RELOAD_CASE (DD
, dd
);
3166 __SECONDARY_RELOAD_CASE (TD
, td
);
3171 #undef __SECONDARY_RELOAD_CASE
3175 /* We need a scratch register when loading a PLUS expression which
3176 is not a legitimate operand of the LOAD ADDRESS instruction. */
3177 /* LRA can deal with transformation of plus op very well -- so we
3178 don't need to prompt LRA in this case. */
3179 if (! lra_in_progress
&& in_p
&& s390_plus_operand (x
, mode
))
3180 sri
->icode
= (TARGET_64BIT
?
3181 CODE_FOR_reloaddi_plus
: CODE_FOR_reloadsi_plus
);
3183 /* Performing a multiword move from or to memory we have to make sure the
3184 second chunk in memory is addressable without causing a displacement
3185 overflow. If that would be the case we calculate the address in
3186 a scratch register. */
3188 && GET_CODE (XEXP (x
, 0)) == PLUS
3189 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
3190 && !DISP_IN_RANGE (INTVAL (XEXP (XEXP (x
, 0), 1))
3191 + GET_MODE_SIZE (mode
) - 1))
3193 /* For GENERAL_REGS a displacement overflow is no problem if occurring
3194 in a s_operand address since we may fallback to lm/stm. So we only
3195 have to care about overflows in the b+i+d case. */
3196 if ((reg_classes_intersect_p (GENERAL_REGS
, rclass
)
3197 && s390_class_max_nregs (GENERAL_REGS
, mode
) > 1
3198 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == PLUS
)
3199 /* For FP_REGS no lm/stm is available so this check is triggered
3200 for displacement overflows in b+i+d and b+d like addresses. */
3201 || (reg_classes_intersect_p (FP_REGS
, rclass
)
3202 && s390_class_max_nregs (FP_REGS
, mode
) > 1))
3205 sri
->icode
= (TARGET_64BIT
?
3206 CODE_FOR_reloaddi_nonoffmem_in
:
3207 CODE_FOR_reloadsi_nonoffmem_in
);
3209 sri
->icode
= (TARGET_64BIT
?
3210 CODE_FOR_reloaddi_nonoffmem_out
:
3211 CODE_FOR_reloadsi_nonoffmem_out
);
3215 /* A scratch address register is needed when a symbolic constant is
3216 copied to r0 compiling with -fPIC. In other cases the target
3217 register might be used as temporary (see legitimize_pic_address). */
3218 if (in_p
&& SYMBOLIC_CONST (x
) && flag_pic
== 2 && rclass
!= ADDR_REGS
)
3219 sri
->icode
= (TARGET_64BIT
?
3220 CODE_FOR_reloaddi_PIC_addr
:
3221 CODE_FOR_reloadsi_PIC_addr
);
3223 /* Either scratch or no register needed. */
3227 /* Generate code to load SRC, which is PLUS that is not a
3228 legitimate operand for the LA instruction, into TARGET.
3229 SCRATCH may be used as scratch register. */
3232 s390_expand_plus_operand (rtx target
, rtx src
,
3236 struct s390_address ad
;
3238 /* src must be a PLUS; get its two operands. */
3239 gcc_assert (GET_CODE (src
) == PLUS
);
3240 gcc_assert (GET_MODE (src
) == Pmode
);
3242 /* Check if any of the two operands is already scheduled
3243 for replacement by reload. This can happen e.g. when
3244 float registers occur in an address. */
3245 sum1
= find_replacement (&XEXP (src
, 0));
3246 sum2
= find_replacement (&XEXP (src
, 1));
3247 src
= gen_rtx_PLUS (Pmode
, sum1
, sum2
);
3249 /* If the address is already strictly valid, there's nothing to do. */
3250 if (!s390_decompose_address (src
, &ad
)
3251 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
3252 || (ad
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (ad
.indx
))))
3254 /* Otherwise, one of the operands cannot be an address register;
3255 we reload its value into the scratch register. */
3256 if (true_regnum (sum1
) < 1 || true_regnum (sum1
) > 15)
3258 emit_move_insn (scratch
, sum1
);
3261 if (true_regnum (sum2
) < 1 || true_regnum (sum2
) > 15)
3263 emit_move_insn (scratch
, sum2
);
3267 /* According to the way these invalid addresses are generated
3268 in reload.c, it should never happen (at least on s390) that
3269 *neither* of the PLUS components, after find_replacements
3270 was applied, is an address register. */
3271 if (sum1
== scratch
&& sum2
== scratch
)
3277 src
= gen_rtx_PLUS (Pmode
, sum1
, sum2
);
3280 /* Emit the LOAD ADDRESS pattern. Note that reload of PLUS
3281 is only ever performed on addresses, so we can mark the
3282 sum as legitimate for LA in any case. */
3283 s390_load_address (target
, src
);
3287 /* Return true if ADDR is a valid memory address.
3288 STRICT specifies whether strict register checking applies. */
3291 s390_legitimate_address_p (machine_mode mode
, rtx addr
, bool strict
)
3293 struct s390_address ad
;
3296 && larl_operand (addr
, VOIDmode
)
3297 && (mode
== VOIDmode
3298 || s390_check_symref_alignment (addr
, GET_MODE_SIZE (mode
))))
3301 if (!s390_decompose_address (addr
, &ad
))
3306 if (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
3309 if (ad
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (ad
.indx
)))
3315 && !(REGNO (ad
.base
) >= FIRST_PSEUDO_REGISTER
3316 || REGNO_REG_CLASS (REGNO (ad
.base
)) == ADDR_REGS
))
3320 && !(REGNO (ad
.indx
) >= FIRST_PSEUDO_REGISTER
3321 || REGNO_REG_CLASS (REGNO (ad
.indx
)) == ADDR_REGS
))
3327 /* Return true if OP is a valid operand for the LA instruction.
3328 In 31-bit, we need to prove that the result is used as an
3329 address, as LA performs only a 31-bit addition. */
3332 legitimate_la_operand_p (rtx op
)
3334 struct s390_address addr
;
3335 if (!s390_decompose_address (op
, &addr
))
3338 return (TARGET_64BIT
|| addr
.pointer
);
3341 /* Return true if it is valid *and* preferable to use LA to
3342 compute the sum of OP1 and OP2. */
3345 preferred_la_operand_p (rtx op1
, rtx op2
)
3347 struct s390_address addr
;
3349 if (op2
!= const0_rtx
)
3350 op1
= gen_rtx_PLUS (Pmode
, op1
, op2
);
3352 if (!s390_decompose_address (op1
, &addr
))
3354 if (addr
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (addr
.base
)))
3356 if (addr
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (addr
.indx
)))
3359 /* Avoid LA instructions with index register on z196; it is
3360 preferable to use regular add instructions when possible.
3361 Starting with zEC12 the la with index register is "uncracked"
3363 if (addr
.indx
&& s390_tune
== PROCESSOR_2817_Z196
)
3366 if (!TARGET_64BIT
&& !addr
.pointer
)
3372 if ((addr
.base
&& REG_P (addr
.base
) && REG_POINTER (addr
.base
))
3373 || (addr
.indx
&& REG_P (addr
.indx
) && REG_POINTER (addr
.indx
)))
3379 /* Emit a forced load-address operation to load SRC into DST.
3380 This will use the LOAD ADDRESS instruction even in situations
3381 where legitimate_la_operand_p (SRC) returns false. */
3384 s390_load_address (rtx dst
, rtx src
)
3387 emit_move_insn (dst
, src
);
3389 emit_insn (gen_force_la_31 (dst
, src
));
3392 /* Return a legitimate reference for ORIG (an address) using the
3393 register REG. If REG is 0, a new pseudo is generated.
3395 There are two types of references that must be handled:
3397 1. Global data references must load the address from the GOT, via
3398 the PIC reg. An insn is emitted to do this load, and the reg is
3401 2. Static data references, constant pool addresses, and code labels
3402 compute the address as an offset from the GOT, whose base is in
3403 the PIC reg. Static data objects have SYMBOL_FLAG_LOCAL set to
3404 differentiate them from global data objects. The returned
3405 address is the PIC reg + an unspec constant.
3407 TARGET_LEGITIMIZE_ADDRESS_P rejects symbolic references unless the PIC
3408 reg also appears in the address. */
3411 legitimize_pic_address (rtx orig
, rtx reg
)
3414 rtx addend
= const0_rtx
;
3417 gcc_assert (!TLS_SYMBOLIC_CONST (addr
));
3419 if (GET_CODE (addr
) == CONST
)
3420 addr
= XEXP (addr
, 0);
3422 if (GET_CODE (addr
) == PLUS
)
3424 addend
= XEXP (addr
, 1);
3425 addr
= XEXP (addr
, 0);
3428 if ((GET_CODE (addr
) == LABEL_REF
3429 || (GET_CODE (addr
) == SYMBOL_REF
&& SYMBOL_REF_LOCAL_P (addr
))
3430 || (GET_CODE (addr
) == UNSPEC
&&
3431 (XINT (addr
, 1) == UNSPEC_GOTENT
3432 || (TARGET_CPU_ZARCH
&& XINT (addr
, 1) == UNSPEC_PLT
))))
3433 && GET_CODE (addend
) == CONST_INT
)
3435 /* This can be locally addressed. */
3437 /* larl_operand requires UNSPECs to be wrapped in a const rtx. */
3438 rtx const_addr
= (GET_CODE (addr
) == UNSPEC
?
3439 gen_rtx_CONST (Pmode
, addr
) : addr
);
3441 if (TARGET_CPU_ZARCH
3442 && larl_operand (const_addr
, VOIDmode
)
3443 && INTVAL (addend
) < (HOST_WIDE_INT
)1 << 31
3444 && INTVAL (addend
) >= -((HOST_WIDE_INT
)1 << 31))
3446 if (INTVAL (addend
) & 1)
3448 /* LARL can't handle odd offsets, so emit a pair of LARL
3450 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3452 if (!DISP_IN_RANGE (INTVAL (addend
)))
3454 HOST_WIDE_INT even
= INTVAL (addend
) - 1;
3455 addr
= gen_rtx_PLUS (Pmode
, addr
, GEN_INT (even
));
3456 addr
= gen_rtx_CONST (Pmode
, addr
);
3457 addend
= const1_rtx
;
3460 emit_move_insn (temp
, addr
);
3461 new_rtx
= gen_rtx_PLUS (Pmode
, temp
, addend
);
3465 s390_load_address (reg
, new_rtx
);
3471 /* If the offset is even, we can just use LARL. This
3472 will happen automatically. */
3477 /* No larl - Access local symbols relative to the GOT. */
3479 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3481 if (reload_in_progress
|| reload_completed
)
3482 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3484 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTOFF
);
3485 if (addend
!= const0_rtx
)
3486 addr
= gen_rtx_PLUS (Pmode
, addr
, addend
);
3487 addr
= gen_rtx_CONST (Pmode
, addr
);
3488 addr
= force_const_mem (Pmode
, addr
);
3489 emit_move_insn (temp
, addr
);
3491 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3494 s390_load_address (reg
, new_rtx
);
3499 else if (GET_CODE (addr
) == SYMBOL_REF
&& addend
== const0_rtx
)
3501 /* A non-local symbol reference without addend.
3503 The symbol ref is wrapped into an UNSPEC to make sure the
3504 proper operand modifier (@GOT or @GOTENT) will be emitted.
3505 This will tell the linker to put the symbol into the GOT.
3507 Additionally the code dereferencing the GOT slot is emitted here.
3509 An addend to the symref needs to be added afterwards.
3510 legitimize_pic_address calls itself recursively to handle
3511 that case. So no need to do it here. */
3514 reg
= gen_reg_rtx (Pmode
);
3518 /* Use load relative if possible.
3519 lgrl <target>, sym@GOTENT */
3520 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTENT
);
3521 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3522 new_rtx
= gen_const_mem (GET_MODE (reg
), new_rtx
);
3524 emit_move_insn (reg
, new_rtx
);
3527 else if (flag_pic
== 1)
3529 /* Assume GOT offset is a valid displacement operand (< 4k
3530 or < 512k with z990). This is handled the same way in
3531 both 31- and 64-bit code (@GOT).
3532 lg <target>, sym@GOT(r12) */
3534 if (reload_in_progress
|| reload_completed
)
3535 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3537 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOT
);
3538 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3539 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, new_rtx
);
3540 new_rtx
= gen_const_mem (Pmode
, new_rtx
);
3541 emit_move_insn (reg
, new_rtx
);
3544 else if (TARGET_CPU_ZARCH
)
3546 /* If the GOT offset might be >= 4k, we determine the position
3547 of the GOT entry via a PC-relative LARL (@GOTENT).
3548 larl temp, sym@GOTENT
3549 lg <target>, 0(temp) */
3551 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3553 gcc_assert (REGNO (temp
) >= FIRST_PSEUDO_REGISTER
3554 || REGNO_REG_CLASS (REGNO (temp
)) == ADDR_REGS
);
3556 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTENT
);
3557 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3558 emit_move_insn (temp
, new_rtx
);
3560 new_rtx
= gen_const_mem (Pmode
, temp
);
3561 emit_move_insn (reg
, new_rtx
);
3567 /* If the GOT offset might be >= 4k, we have to load it
3568 from the literal pool (@GOT).
3570 lg temp, lit-litbase(r13)
3571 lg <target>, 0(temp)
3572 lit: .long sym@GOT */
3574 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3576 gcc_assert (REGNO (temp
) >= FIRST_PSEUDO_REGISTER
3577 || REGNO_REG_CLASS (REGNO (temp
)) == ADDR_REGS
);
3579 if (reload_in_progress
|| reload_completed
)
3580 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3582 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOT
);
3583 addr
= gen_rtx_CONST (Pmode
, addr
);
3584 addr
= force_const_mem (Pmode
, addr
);
3585 emit_move_insn (temp
, addr
);
3587 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3588 new_rtx
= gen_const_mem (Pmode
, new_rtx
);
3589 emit_move_insn (reg
, new_rtx
);
3593 else if (GET_CODE (addr
) == UNSPEC
&& GET_CODE (addend
) == CONST_INT
)
3595 gcc_assert (XVECLEN (addr
, 0) == 1);
3596 switch (XINT (addr
, 1))
3598 /* These address symbols (or PLT slots) relative to the GOT
3599 (not GOT slots!). In general this will exceed the
3600 displacement range so these value belong into the literal
3604 new_rtx
= force_const_mem (Pmode
, orig
);
3607 /* For -fPIC the GOT size might exceed the displacement
3608 range so make sure the value is in the literal pool. */
3611 new_rtx
= force_const_mem (Pmode
, orig
);
3614 /* For @GOTENT larl is used. This is handled like local
3620 /* @PLT is OK as is on 64-bit, must be converted to
3621 GOT-relative @PLTOFF on 31-bit. */
3623 if (!TARGET_CPU_ZARCH
)
3625 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3627 if (reload_in_progress
|| reload_completed
)
3628 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3630 addr
= XVECEXP (addr
, 0, 0);
3631 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
),
3633 if (addend
!= const0_rtx
)
3634 addr
= gen_rtx_PLUS (Pmode
, addr
, addend
);
3635 addr
= gen_rtx_CONST (Pmode
, addr
);
3636 addr
= force_const_mem (Pmode
, addr
);
3637 emit_move_insn (temp
, addr
);
3639 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3642 s390_load_address (reg
, new_rtx
);
3647 /* On 64 bit larl can be used. This case is handled like
3648 local symbol refs. */
3652 /* Everything else cannot happen. */
3657 else if (addend
!= const0_rtx
)
3659 /* Otherwise, compute the sum. */
3661 rtx base
= legitimize_pic_address (addr
, reg
);
3662 new_rtx
= legitimize_pic_address (addend
,
3663 base
== reg
? NULL_RTX
: reg
);
3664 if (GET_CODE (new_rtx
) == CONST_INT
)
3665 new_rtx
= plus_constant (Pmode
, base
, INTVAL (new_rtx
));
3668 if (GET_CODE (new_rtx
) == PLUS
&& CONSTANT_P (XEXP (new_rtx
, 1)))
3670 base
= gen_rtx_PLUS (Pmode
, base
, XEXP (new_rtx
, 0));
3671 new_rtx
= XEXP (new_rtx
, 1);
3673 new_rtx
= gen_rtx_PLUS (Pmode
, base
, new_rtx
);
3676 if (GET_CODE (new_rtx
) == CONST
)
3677 new_rtx
= XEXP (new_rtx
, 0);
3678 new_rtx
= force_operand (new_rtx
, 0);
3684 /* Load the thread pointer into a register. */
3687 s390_get_thread_pointer (void)
3689 rtx tp
= gen_reg_rtx (Pmode
);
3691 emit_move_insn (tp
, gen_rtx_REG (Pmode
, TP_REGNUM
));
3692 mark_reg_pointer (tp
, BITS_PER_WORD
);
3697 /* Emit a tls call insn. The call target is the SYMBOL_REF stored
3698 in s390_tls_symbol which always refers to __tls_get_offset.
3699 The returned offset is written to RESULT_REG and an USE rtx is
3700 generated for TLS_CALL. */
3702 static GTY(()) rtx s390_tls_symbol
;
3705 s390_emit_tls_call_insn (rtx result_reg
, rtx tls_call
)
3710 emit_insn (s390_load_got ());
3712 if (!s390_tls_symbol
)
3713 s390_tls_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "__tls_get_offset");
3715 insn
= s390_emit_call (s390_tls_symbol
, tls_call
, result_reg
,
3716 gen_rtx_REG (Pmode
, RETURN_REGNUM
));
3718 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), result_reg
);
3719 RTL_CONST_CALL_P (insn
) = 1;
3722 /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
3723 this (thread-local) address. REG may be used as temporary. */
3726 legitimize_tls_address (rtx addr
, rtx reg
)
3728 rtx new_rtx
, tls_call
, temp
, base
, r2
, insn
;
3730 if (GET_CODE (addr
) == SYMBOL_REF
)
3731 switch (tls_symbolic_operand (addr
))
3733 case TLS_MODEL_GLOBAL_DYNAMIC
:
3735 r2
= gen_rtx_REG (Pmode
, 2);
3736 tls_call
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_TLSGD
);
3737 new_rtx
= gen_rtx_CONST (Pmode
, tls_call
);
3738 new_rtx
= force_const_mem (Pmode
, new_rtx
);
3739 emit_move_insn (r2
, new_rtx
);
3740 s390_emit_tls_call_insn (r2
, tls_call
);
3741 insn
= get_insns ();
3744 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_NTPOFF
);
3745 temp
= gen_reg_rtx (Pmode
);
3746 emit_libcall_block (insn
, temp
, r2
, new_rtx
);
3748 new_rtx
= gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3751 s390_load_address (reg
, new_rtx
);
3756 case TLS_MODEL_LOCAL_DYNAMIC
:
3758 r2
= gen_rtx_REG (Pmode
, 2);
3759 tls_call
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, const0_rtx
), UNSPEC_TLSLDM
);
3760 new_rtx
= gen_rtx_CONST (Pmode
, tls_call
);
3761 new_rtx
= force_const_mem (Pmode
, new_rtx
);
3762 emit_move_insn (r2
, new_rtx
);
3763 s390_emit_tls_call_insn (r2
, tls_call
);
3764 insn
= get_insns ();
3767 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, const0_rtx
), UNSPEC_TLSLDM_NTPOFF
);
3768 temp
= gen_reg_rtx (Pmode
);
3769 emit_libcall_block (insn
, temp
, r2
, new_rtx
);
3771 new_rtx
= gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3772 base
= gen_reg_rtx (Pmode
);
3773 s390_load_address (base
, new_rtx
);
3775 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_DTPOFF
);
3776 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3777 new_rtx
= force_const_mem (Pmode
, new_rtx
);
3778 temp
= gen_reg_rtx (Pmode
);
3779 emit_move_insn (temp
, new_rtx
);
3781 new_rtx
= gen_rtx_PLUS (Pmode
, base
, temp
);
3784 s390_load_address (reg
, new_rtx
);
3789 case TLS_MODEL_INITIAL_EXEC
:
3792 /* Assume GOT offset < 4k. This is handled the same way
3793 in both 31- and 64-bit code. */
3795 if (reload_in_progress
|| reload_completed
)
3796 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3798 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTNTPOFF
);
3799 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3800 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, new_rtx
);
3801 new_rtx
= gen_const_mem (Pmode
, new_rtx
);
3802 temp
= gen_reg_rtx (Pmode
);
3803 emit_move_insn (temp
, new_rtx
);
3805 else if (TARGET_CPU_ZARCH
)
3807 /* If the GOT offset might be >= 4k, we determine the position
3808 of the GOT entry via a PC-relative LARL. */
3810 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_INDNTPOFF
);
3811 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3812 temp
= gen_reg_rtx (Pmode
);
3813 emit_move_insn (temp
, new_rtx
);
3815 new_rtx
= gen_const_mem (Pmode
, temp
);
3816 temp
= gen_reg_rtx (Pmode
);
3817 emit_move_insn (temp
, new_rtx
);
3821 /* If the GOT offset might be >= 4k, we have to load it
3822 from the literal pool. */
3824 if (reload_in_progress
|| reload_completed
)
3825 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3827 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTNTPOFF
);
3828 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3829 new_rtx
= force_const_mem (Pmode
, new_rtx
);
3830 temp
= gen_reg_rtx (Pmode
);
3831 emit_move_insn (temp
, new_rtx
);
3833 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3834 new_rtx
= gen_const_mem (Pmode
, new_rtx
);
3836 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, new_rtx
, addr
), UNSPEC_TLS_LOAD
);
3837 temp
= gen_reg_rtx (Pmode
);
3838 emit_insn (gen_rtx_SET (Pmode
, temp
, new_rtx
));
3842 /* In position-dependent code, load the absolute address of
3843 the GOT entry from the literal pool. */
3845 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_INDNTPOFF
);
3846 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3847 new_rtx
= force_const_mem (Pmode
, new_rtx
);
3848 temp
= gen_reg_rtx (Pmode
);
3849 emit_move_insn (temp
, new_rtx
);
3852 new_rtx
= gen_const_mem (Pmode
, new_rtx
);
3853 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, new_rtx
, addr
), UNSPEC_TLS_LOAD
);
3854 temp
= gen_reg_rtx (Pmode
);
3855 emit_insn (gen_rtx_SET (Pmode
, temp
, new_rtx
));
3858 new_rtx
= gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3861 s390_load_address (reg
, new_rtx
);
3866 case TLS_MODEL_LOCAL_EXEC
:
3867 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_NTPOFF
);
3868 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3869 new_rtx
= force_const_mem (Pmode
, new_rtx
);
3870 temp
= gen_reg_rtx (Pmode
);
3871 emit_move_insn (temp
, new_rtx
);
3873 new_rtx
= gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3876 s390_load_address (reg
, new_rtx
);
3885 else if (GET_CODE (addr
) == CONST
&& GET_CODE (XEXP (addr
, 0)) == UNSPEC
)
3887 switch (XINT (XEXP (addr
, 0), 1))
3889 case UNSPEC_INDNTPOFF
:
3890 gcc_assert (TARGET_CPU_ZARCH
);
3899 else if (GET_CODE (addr
) == CONST
&& GET_CODE (XEXP (addr
, 0)) == PLUS
3900 && GET_CODE (XEXP (XEXP (addr
, 0), 1)) == CONST_INT
)
3902 new_rtx
= XEXP (XEXP (addr
, 0), 0);
3903 if (GET_CODE (new_rtx
) != SYMBOL_REF
)
3904 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3906 new_rtx
= legitimize_tls_address (new_rtx
, reg
);
3907 new_rtx
= plus_constant (Pmode
, new_rtx
,
3908 INTVAL (XEXP (XEXP (addr
, 0), 1)));
3909 new_rtx
= force_operand (new_rtx
, 0);
3913 gcc_unreachable (); /* for now ... */
3918 /* Emit insns making the address in operands[1] valid for a standard
3919 move to operands[0]. operands[1] is replaced by an address which
3920 should be used instead of the former RTX to emit the move
3924 emit_symbolic_move (rtx
*operands
)
3926 rtx temp
= !can_create_pseudo_p () ? operands
[0] : gen_reg_rtx (Pmode
);
3928 if (GET_CODE (operands
[0]) == MEM
)
3929 operands
[1] = force_reg (Pmode
, operands
[1]);
3930 else if (TLS_SYMBOLIC_CONST (operands
[1]))
3931 operands
[1] = legitimize_tls_address (operands
[1], temp
);
3933 operands
[1] = legitimize_pic_address (operands
[1], temp
);
3936 /* Try machine-dependent ways of modifying an illegitimate address X
3937 to be legitimate. If we find one, return the new, valid address.
3939 OLDX is the address as it was before break_out_memory_refs was called.
3940 In some cases it is useful to look at this to decide what needs to be done.
3942 MODE is the mode of the operand pointed to by X.
3944 When -fpic is used, special handling is needed for symbolic references.
3945 See comments by legitimize_pic_address for details. */
3948 s390_legitimize_address (rtx x
, rtx oldx ATTRIBUTE_UNUSED
,
3949 machine_mode mode ATTRIBUTE_UNUSED
)
3951 rtx constant_term
= const0_rtx
;
3953 if (TLS_SYMBOLIC_CONST (x
))
3955 x
= legitimize_tls_address (x
, 0);
3957 if (s390_legitimate_address_p (mode
, x
, FALSE
))
3960 else if (GET_CODE (x
) == PLUS
3961 && (TLS_SYMBOLIC_CONST (XEXP (x
, 0))
3962 || TLS_SYMBOLIC_CONST (XEXP (x
, 1))))
3968 if (SYMBOLIC_CONST (x
)
3969 || (GET_CODE (x
) == PLUS
3970 && (SYMBOLIC_CONST (XEXP (x
, 0))
3971 || SYMBOLIC_CONST (XEXP (x
, 1)))))
3972 x
= legitimize_pic_address (x
, 0);
3974 if (s390_legitimate_address_p (mode
, x
, FALSE
))
3978 x
= eliminate_constant_term (x
, &constant_term
);
3980 /* Optimize loading of large displacements by splitting them
3981 into the multiple of 4K and the rest; this allows the
3982 former to be CSE'd if possible.
3984 Don't do this if the displacement is added to a register
3985 pointing into the stack frame, as the offsets will
3986 change later anyway. */
3988 if (GET_CODE (constant_term
) == CONST_INT
3989 && !TARGET_LONG_DISPLACEMENT
3990 && !DISP_IN_RANGE (INTVAL (constant_term
))
3991 && !(REG_P (x
) && REGNO_PTR_FRAME_P (REGNO (x
))))
3993 HOST_WIDE_INT lower
= INTVAL (constant_term
) & 0xfff;
3994 HOST_WIDE_INT upper
= INTVAL (constant_term
) ^ lower
;
3996 rtx temp
= gen_reg_rtx (Pmode
);
3997 rtx val
= force_operand (GEN_INT (upper
), temp
);
3999 emit_move_insn (temp
, val
);
4001 x
= gen_rtx_PLUS (Pmode
, x
, temp
);
4002 constant_term
= GEN_INT (lower
);
4005 if (GET_CODE (x
) == PLUS
)
4007 if (GET_CODE (XEXP (x
, 0)) == REG
)
4009 rtx temp
= gen_reg_rtx (Pmode
);
4010 rtx val
= force_operand (XEXP (x
, 1), temp
);
4012 emit_move_insn (temp
, val
);
4014 x
= gen_rtx_PLUS (Pmode
, XEXP (x
, 0), temp
);
4017 else if (GET_CODE (XEXP (x
, 1)) == REG
)
4019 rtx temp
= gen_reg_rtx (Pmode
);
4020 rtx val
= force_operand (XEXP (x
, 0), temp
);
4022 emit_move_insn (temp
, val
);
4024 x
= gen_rtx_PLUS (Pmode
, temp
, XEXP (x
, 1));
4028 if (constant_term
!= const0_rtx
)
4029 x
= gen_rtx_PLUS (Pmode
, x
, constant_term
);
4034 /* Try a machine-dependent way of reloading an illegitimate address AD
4035 operand. If we find one, push the reload and return the new address.
4037 MODE is the mode of the enclosing MEM. OPNUM is the operand number
4038 and TYPE is the reload type of the current reload. */
4041 legitimize_reload_address (rtx ad
, machine_mode mode ATTRIBUTE_UNUSED
,
4042 int opnum
, int type
)
4044 if (!optimize
|| TARGET_LONG_DISPLACEMENT
)
4047 if (GET_CODE (ad
) == PLUS
)
4049 rtx tem
= simplify_binary_operation (PLUS
, Pmode
,
4050 XEXP (ad
, 0), XEXP (ad
, 1));
4055 if (GET_CODE (ad
) == PLUS
4056 && GET_CODE (XEXP (ad
, 0)) == REG
4057 && GET_CODE (XEXP (ad
, 1)) == CONST_INT
4058 && !DISP_IN_RANGE (INTVAL (XEXP (ad
, 1))))
4060 HOST_WIDE_INT lower
= INTVAL (XEXP (ad
, 1)) & 0xfff;
4061 HOST_WIDE_INT upper
= INTVAL (XEXP (ad
, 1)) ^ lower
;
4062 rtx cst
, tem
, new_rtx
;
4064 cst
= GEN_INT (upper
);
4065 if (!legitimate_reload_constant_p (cst
))
4066 cst
= force_const_mem (Pmode
, cst
);
4068 tem
= gen_rtx_PLUS (Pmode
, XEXP (ad
, 0), cst
);
4069 new_rtx
= gen_rtx_PLUS (Pmode
, tem
, GEN_INT (lower
));
4071 push_reload (XEXP (tem
, 1), 0, &XEXP (tem
, 1), 0,
4072 BASE_REG_CLASS
, Pmode
, VOIDmode
, 0, 0,
4073 opnum
, (enum reload_type
) type
);
4080 /* Emit code to move LEN bytes from DST to SRC. */
4083 s390_expand_movmem (rtx dst
, rtx src
, rtx len
)
4085 /* When tuning for z10 or higher we rely on the Glibc functions to
4086 do the right thing. Only for constant lengths below 64k we will
4087 generate inline code. */
4088 if (s390_tune
>= PROCESSOR_2097_Z10
4089 && (GET_CODE (len
) != CONST_INT
|| INTVAL (len
) > (1<<16)))
4092 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) >= 0 && INTVAL (len
) <= 256)
4094 if (INTVAL (len
) > 0)
4095 emit_insn (gen_movmem_short (dst
, src
, GEN_INT (INTVAL (len
) - 1)));
4098 else if (TARGET_MVCLE
)
4100 emit_insn (gen_movmem_long (dst
, src
, convert_to_mode (Pmode
, len
, 1)));
4105 rtx dst_addr
, src_addr
, count
, blocks
, temp
;
4106 rtx_code_label
*loop_start_label
= gen_label_rtx ();
4107 rtx_code_label
*loop_end_label
= gen_label_rtx ();
4108 rtx_code_label
*end_label
= gen_label_rtx ();
4111 mode
= GET_MODE (len
);
4112 if (mode
== VOIDmode
)
4115 dst_addr
= gen_reg_rtx (Pmode
);
4116 src_addr
= gen_reg_rtx (Pmode
);
4117 count
= gen_reg_rtx (mode
);
4118 blocks
= gen_reg_rtx (mode
);
4120 convert_move (count
, len
, 1);
4121 emit_cmp_and_jump_insns (count
, const0_rtx
,
4122 EQ
, NULL_RTX
, mode
, 1, end_label
);
4124 emit_move_insn (dst_addr
, force_operand (XEXP (dst
, 0), NULL_RTX
));
4125 emit_move_insn (src_addr
, force_operand (XEXP (src
, 0), NULL_RTX
));
4126 dst
= change_address (dst
, VOIDmode
, dst_addr
);
4127 src
= change_address (src
, VOIDmode
, src_addr
);
4129 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1,
4132 emit_move_insn (count
, temp
);
4134 temp
= expand_binop (mode
, lshr_optab
, count
, GEN_INT (8), blocks
, 1,
4137 emit_move_insn (blocks
, temp
);
4139 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
4140 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
4142 emit_label (loop_start_label
);
4145 && (GET_CODE (len
) != CONST_INT
|| INTVAL (len
) > 768))
4149 /* Issue a read prefetch for the +3 cache line. */
4150 prefetch
= gen_prefetch (gen_rtx_PLUS (Pmode
, src_addr
, GEN_INT (768)),
4151 const0_rtx
, const0_rtx
);
4152 PREFETCH_SCHEDULE_BARRIER_P (prefetch
) = true;
4153 emit_insn (prefetch
);
4155 /* Issue a write prefetch for the +3 cache line. */
4156 prefetch
= gen_prefetch (gen_rtx_PLUS (Pmode
, dst_addr
, GEN_INT (768)),
4157 const1_rtx
, const0_rtx
);
4158 PREFETCH_SCHEDULE_BARRIER_P (prefetch
) = true;
4159 emit_insn (prefetch
);
4162 emit_insn (gen_movmem_short (dst
, src
, GEN_INT (255)));
4163 s390_load_address (dst_addr
,
4164 gen_rtx_PLUS (Pmode
, dst_addr
, GEN_INT (256)));
4165 s390_load_address (src_addr
,
4166 gen_rtx_PLUS (Pmode
, src_addr
, GEN_INT (256)));
4168 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1,
4171 emit_move_insn (blocks
, temp
);
4173 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
4174 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
4176 emit_jump (loop_start_label
);
4177 emit_label (loop_end_label
);
4179 emit_insn (gen_movmem_short (dst
, src
,
4180 convert_to_mode (Pmode
, count
, 1)));
4181 emit_label (end_label
);
4186 /* Emit code to set LEN bytes at DST to VAL.
4187 Make use of clrmem if VAL is zero. */
4190 s390_expand_setmem (rtx dst
, rtx len
, rtx val
)
4192 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) == 0)
4195 gcc_assert (GET_CODE (val
) == CONST_INT
|| GET_MODE (val
) == QImode
);
4197 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) > 0 && INTVAL (len
) <= 257)
4199 if (val
== const0_rtx
&& INTVAL (len
) <= 256)
4200 emit_insn (gen_clrmem_short (dst
, GEN_INT (INTVAL (len
) - 1)));
4203 /* Initialize memory by storing the first byte. */
4204 emit_move_insn (adjust_address (dst
, QImode
, 0), val
);
4206 if (INTVAL (len
) > 1)
4208 /* Initiate 1 byte overlap move.
4209 The first byte of DST is propagated through DSTP1.
4210 Prepare a movmem for: DST+1 = DST (length = LEN - 1).
4211 DST is set to size 1 so the rest of the memory location
4212 does not count as source operand. */
4213 rtx dstp1
= adjust_address (dst
, VOIDmode
, 1);
4214 set_mem_size (dst
, 1);
4216 emit_insn (gen_movmem_short (dstp1
, dst
,
4217 GEN_INT (INTVAL (len
) - 2)));
4222 else if (TARGET_MVCLE
)
4224 val
= force_not_mem (convert_modes (Pmode
, QImode
, val
, 1));
4225 emit_insn (gen_setmem_long (dst
, convert_to_mode (Pmode
, len
, 1), val
));
4230 rtx dst_addr
, count
, blocks
, temp
, dstp1
= NULL_RTX
;
4231 rtx_code_label
*loop_start_label
= gen_label_rtx ();
4232 rtx_code_label
*loop_end_label
= gen_label_rtx ();
4233 rtx_code_label
*end_label
= gen_label_rtx ();
4236 mode
= GET_MODE (len
);
4237 if (mode
== VOIDmode
)
4240 dst_addr
= gen_reg_rtx (Pmode
);
4241 count
= gen_reg_rtx (mode
);
4242 blocks
= gen_reg_rtx (mode
);
4244 convert_move (count
, len
, 1);
4245 emit_cmp_and_jump_insns (count
, const0_rtx
,
4246 EQ
, NULL_RTX
, mode
, 1, end_label
);
4248 emit_move_insn (dst_addr
, force_operand (XEXP (dst
, 0), NULL_RTX
));
4249 dst
= change_address (dst
, VOIDmode
, dst_addr
);
4251 if (val
== const0_rtx
)
4252 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1,
4256 dstp1
= adjust_address (dst
, VOIDmode
, 1);
4257 set_mem_size (dst
, 1);
4259 /* Initialize memory by storing the first byte. */
4260 emit_move_insn (adjust_address (dst
, QImode
, 0), val
);
4262 /* If count is 1 we are done. */
4263 emit_cmp_and_jump_insns (count
, const1_rtx
,
4264 EQ
, NULL_RTX
, mode
, 1, end_label
);
4266 temp
= expand_binop (mode
, add_optab
, count
, GEN_INT (-2), count
, 1,
4270 emit_move_insn (count
, temp
);
4272 temp
= expand_binop (mode
, lshr_optab
, count
, GEN_INT (8), blocks
, 1,
4275 emit_move_insn (blocks
, temp
);
4277 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
4278 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
4280 emit_label (loop_start_label
);
4283 && (GET_CODE (len
) != CONST_INT
|| INTVAL (len
) > 1024))
4285 /* Issue a write prefetch for the +4 cache line. */
4286 rtx prefetch
= gen_prefetch (gen_rtx_PLUS (Pmode
, dst_addr
,
4288 const1_rtx
, const0_rtx
);
4289 emit_insn (prefetch
);
4290 PREFETCH_SCHEDULE_BARRIER_P (prefetch
) = true;
4293 if (val
== const0_rtx
)
4294 emit_insn (gen_clrmem_short (dst
, GEN_INT (255)));
4296 emit_insn (gen_movmem_short (dstp1
, dst
, GEN_INT (255)));
4297 s390_load_address (dst_addr
,
4298 gen_rtx_PLUS (Pmode
, dst_addr
, GEN_INT (256)));
4300 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1,
4303 emit_move_insn (blocks
, temp
);
4305 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
4306 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
4308 emit_jump (loop_start_label
);
4309 emit_label (loop_end_label
);
4311 if (val
== const0_rtx
)
4312 emit_insn (gen_clrmem_short (dst
, convert_to_mode (Pmode
, count
, 1)));
4314 emit_insn (gen_movmem_short (dstp1
, dst
, convert_to_mode (Pmode
, count
, 1)));
4315 emit_label (end_label
);
4319 /* Emit code to compare LEN bytes at OP0 with those at OP1,
4320 and return the result in TARGET. */
4323 s390_expand_cmpmem (rtx target
, rtx op0
, rtx op1
, rtx len
)
4325 rtx ccreg
= gen_rtx_REG (CCUmode
, CC_REGNUM
);
4328 /* When tuning for z10 or higher we rely on the Glibc functions to
4329 do the right thing. Only for constant lengths below 64k we will
4330 generate inline code. */
4331 if (s390_tune
>= PROCESSOR_2097_Z10
4332 && (GET_CODE (len
) != CONST_INT
|| INTVAL (len
) > (1<<16)))
4335 /* As the result of CMPINT is inverted compared to what we need,
4336 we have to swap the operands. */
4337 tmp
= op0
; op0
= op1
; op1
= tmp
;
4339 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) >= 0 && INTVAL (len
) <= 256)
4341 if (INTVAL (len
) > 0)
4343 emit_insn (gen_cmpmem_short (op0
, op1
, GEN_INT (INTVAL (len
) - 1)));
4344 emit_insn (gen_cmpint (target
, ccreg
));
4347 emit_move_insn (target
, const0_rtx
);
4349 else if (TARGET_MVCLE
)
4351 emit_insn (gen_cmpmem_long (op0
, op1
, convert_to_mode (Pmode
, len
, 1)));
4352 emit_insn (gen_cmpint (target
, ccreg
));
4356 rtx addr0
, addr1
, count
, blocks
, temp
;
4357 rtx_code_label
*loop_start_label
= gen_label_rtx ();
4358 rtx_code_label
*loop_end_label
= gen_label_rtx ();
4359 rtx_code_label
*end_label
= gen_label_rtx ();
4362 mode
= GET_MODE (len
);
4363 if (mode
== VOIDmode
)
4366 addr0
= gen_reg_rtx (Pmode
);
4367 addr1
= gen_reg_rtx (Pmode
);
4368 count
= gen_reg_rtx (mode
);
4369 blocks
= gen_reg_rtx (mode
);
4371 convert_move (count
, len
, 1);
4372 emit_cmp_and_jump_insns (count
, const0_rtx
,
4373 EQ
, NULL_RTX
, mode
, 1, end_label
);
4375 emit_move_insn (addr0
, force_operand (XEXP (op0
, 0), NULL_RTX
));
4376 emit_move_insn (addr1
, force_operand (XEXP (op1
, 0), NULL_RTX
));
4377 op0
= change_address (op0
, VOIDmode
, addr0
);
4378 op1
= change_address (op1
, VOIDmode
, addr1
);
4380 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1,
4383 emit_move_insn (count
, temp
);
4385 temp
= expand_binop (mode
, lshr_optab
, count
, GEN_INT (8), blocks
, 1,
4388 emit_move_insn (blocks
, temp
);
4390 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
4391 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
4393 emit_label (loop_start_label
);
4396 && (GET_CODE (len
) != CONST_INT
|| INTVAL (len
) > 512))
4400 /* Issue a read prefetch for the +2 cache line of operand 1. */
4401 prefetch
= gen_prefetch (gen_rtx_PLUS (Pmode
, addr0
, GEN_INT (512)),
4402 const0_rtx
, const0_rtx
);
4403 emit_insn (prefetch
);
4404 PREFETCH_SCHEDULE_BARRIER_P (prefetch
) = true;
4406 /* Issue a read prefetch for the +2 cache line of operand 2. */
4407 prefetch
= gen_prefetch (gen_rtx_PLUS (Pmode
, addr1
, GEN_INT (512)),
4408 const0_rtx
, const0_rtx
);
4409 emit_insn (prefetch
);
4410 PREFETCH_SCHEDULE_BARRIER_P (prefetch
) = true;
4413 emit_insn (gen_cmpmem_short (op0
, op1
, GEN_INT (255)));
4414 temp
= gen_rtx_NE (VOIDmode
, ccreg
, const0_rtx
);
4415 temp
= gen_rtx_IF_THEN_ELSE (VOIDmode
, temp
,
4416 gen_rtx_LABEL_REF (VOIDmode
, end_label
), pc_rtx
);
4417 temp
= gen_rtx_SET (VOIDmode
, pc_rtx
, temp
);
4418 emit_jump_insn (temp
);
4420 s390_load_address (addr0
,
4421 gen_rtx_PLUS (Pmode
, addr0
, GEN_INT (256)));
4422 s390_load_address (addr1
,
4423 gen_rtx_PLUS (Pmode
, addr1
, GEN_INT (256)));
4425 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1,
4428 emit_move_insn (blocks
, temp
);
4430 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
4431 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
4433 emit_jump (loop_start_label
);
4434 emit_label (loop_end_label
);
4436 emit_insn (gen_cmpmem_short (op0
, op1
,
4437 convert_to_mode (Pmode
, count
, 1)));
4438 emit_label (end_label
);
4440 emit_insn (gen_cmpint (target
, ccreg
));
4446 /* Expand conditional increment or decrement using alc/slb instructions.
4447 Should generate code setting DST to either SRC or SRC + INCREMENT,
4448 depending on the result of the comparison CMP_OP0 CMP_CODE CMP_OP1.
4449 Returns true if successful, false otherwise.
4451 That makes it possible to implement some if-constructs without jumps e.g.:
4452 (borrow = CC0 | CC1 and carry = CC2 | CC3)
4453 unsigned int a, b, c;
4454 if (a < b) c++; -> CCU b > a -> CC2; c += carry;
4455 if (a < b) c--; -> CCL3 a - b -> borrow; c -= borrow;
4456 if (a <= b) c++; -> CCL3 b - a -> borrow; c += carry;
4457 if (a <= b) c--; -> CCU a <= b -> borrow; c -= borrow;
4459 Checks for EQ and NE with a nonzero value need an additional xor e.g.:
4460 if (a == b) c++; -> CCL3 a ^= b; 0 - a -> borrow; c += carry;
4461 if (a == b) c--; -> CCU a ^= b; a <= 0 -> CC0 | CC1; c -= borrow;
4462 if (a != b) c++; -> CCU a ^= b; a > 0 -> CC2; c += carry;
4463 if (a != b) c--; -> CCL3 a ^= b; 0 - a -> borrow; c -= borrow; */
4466 s390_expand_addcc (enum rtx_code cmp_code
, rtx cmp_op0
, rtx cmp_op1
,
4467 rtx dst
, rtx src
, rtx increment
)
4469 machine_mode cmp_mode
;
4470 machine_mode cc_mode
;
4476 if ((GET_MODE (cmp_op0
) == SImode
|| GET_MODE (cmp_op0
) == VOIDmode
)
4477 && (GET_MODE (cmp_op1
) == SImode
|| GET_MODE (cmp_op1
) == VOIDmode
))
4479 else if ((GET_MODE (cmp_op0
) == DImode
|| GET_MODE (cmp_op0
) == VOIDmode
)
4480 && (GET_MODE (cmp_op1
) == DImode
|| GET_MODE (cmp_op1
) == VOIDmode
))
4485 /* Try ADD LOGICAL WITH CARRY. */
4486 if (increment
== const1_rtx
)
4488 /* Determine CC mode to use. */
4489 if (cmp_code
== EQ
|| cmp_code
== NE
)
4491 if (cmp_op1
!= const0_rtx
)
4493 cmp_op0
= expand_simple_binop (cmp_mode
, XOR
, cmp_op0
, cmp_op1
,
4494 NULL_RTX
, 0, OPTAB_WIDEN
);
4495 cmp_op1
= const0_rtx
;
4498 cmp_code
= cmp_code
== EQ
? LEU
: GTU
;
4501 if (cmp_code
== LTU
|| cmp_code
== LEU
)
4506 cmp_code
= swap_condition (cmp_code
);
4523 /* Emit comparison instruction pattern. */
4524 if (!register_operand (cmp_op0
, cmp_mode
))
4525 cmp_op0
= force_reg (cmp_mode
, cmp_op0
);
4527 insn
= gen_rtx_SET (VOIDmode
, gen_rtx_REG (cc_mode
, CC_REGNUM
),
4528 gen_rtx_COMPARE (cc_mode
, cmp_op0
, cmp_op1
));
4529 /* We use insn_invalid_p here to add clobbers if required. */
4530 ret
= insn_invalid_p (emit_insn (insn
), false);
4533 /* Emit ALC instruction pattern. */
4534 op_res
= gen_rtx_fmt_ee (cmp_code
, GET_MODE (dst
),
4535 gen_rtx_REG (cc_mode
, CC_REGNUM
),
4538 if (src
!= const0_rtx
)
4540 if (!register_operand (src
, GET_MODE (dst
)))
4541 src
= force_reg (GET_MODE (dst
), src
);
4543 op_res
= gen_rtx_PLUS (GET_MODE (dst
), op_res
, src
);
4544 op_res
= gen_rtx_PLUS (GET_MODE (dst
), op_res
, const0_rtx
);
4547 p
= rtvec_alloc (2);
4549 gen_rtx_SET (VOIDmode
, dst
, op_res
);
4551 gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
4552 emit_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
4557 /* Try SUBTRACT LOGICAL WITH BORROW. */
4558 if (increment
== constm1_rtx
)
4560 /* Determine CC mode to use. */
4561 if (cmp_code
== EQ
|| cmp_code
== NE
)
4563 if (cmp_op1
!= const0_rtx
)
4565 cmp_op0
= expand_simple_binop (cmp_mode
, XOR
, cmp_op0
, cmp_op1
,
4566 NULL_RTX
, 0, OPTAB_WIDEN
);
4567 cmp_op1
= const0_rtx
;
4570 cmp_code
= cmp_code
== EQ
? LEU
: GTU
;
4573 if (cmp_code
== GTU
|| cmp_code
== GEU
)
4578 cmp_code
= swap_condition (cmp_code
);
4595 /* Emit comparison instruction pattern. */
4596 if (!register_operand (cmp_op0
, cmp_mode
))
4597 cmp_op0
= force_reg (cmp_mode
, cmp_op0
);
4599 insn
= gen_rtx_SET (VOIDmode
, gen_rtx_REG (cc_mode
, CC_REGNUM
),
4600 gen_rtx_COMPARE (cc_mode
, cmp_op0
, cmp_op1
));
4601 /* We use insn_invalid_p here to add clobbers if required. */
4602 ret
= insn_invalid_p (emit_insn (insn
), false);
4605 /* Emit SLB instruction pattern. */
4606 if (!register_operand (src
, GET_MODE (dst
)))
4607 src
= force_reg (GET_MODE (dst
), src
);
4609 op_res
= gen_rtx_MINUS (GET_MODE (dst
),
4610 gen_rtx_MINUS (GET_MODE (dst
), src
, const0_rtx
),
4611 gen_rtx_fmt_ee (cmp_code
, GET_MODE (dst
),
4612 gen_rtx_REG (cc_mode
, CC_REGNUM
),
4614 p
= rtvec_alloc (2);
4616 gen_rtx_SET (VOIDmode
, dst
, op_res
);
4618 gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
4619 emit_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
4627 /* Expand code for the insv template. Return true if successful. */
4630 s390_expand_insv (rtx dest
, rtx op1
, rtx op2
, rtx src
)
4632 int bitsize
= INTVAL (op1
);
4633 int bitpos
= INTVAL (op2
);
4634 machine_mode mode
= GET_MODE (dest
);
4636 int smode_bsize
, mode_bsize
;
4639 if (bitsize
+ bitpos
> GET_MODE_BITSIZE (mode
))
4642 /* Generate INSERT IMMEDIATE (IILL et al). */
4643 /* (set (ze (reg)) (const_int)). */
4645 && register_operand (dest
, word_mode
)
4646 && (bitpos
% 16) == 0
4647 && (bitsize
% 16) == 0
4648 && const_int_operand (src
, VOIDmode
))
4650 HOST_WIDE_INT val
= INTVAL (src
);
4651 int regpos
= bitpos
+ bitsize
;
4653 while (regpos
> bitpos
)
4655 machine_mode putmode
;
4658 if (TARGET_EXTIMM
&& (regpos
% 32 == 0) && (regpos
>= bitpos
+ 32))
4663 putsize
= GET_MODE_BITSIZE (putmode
);
4665 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
,
4668 gen_int_mode (val
, putmode
));
4671 gcc_assert (regpos
== bitpos
);
4675 smode
= smallest_mode_for_size (bitsize
, MODE_INT
);
4676 smode_bsize
= GET_MODE_BITSIZE (smode
);
4677 mode_bsize
= GET_MODE_BITSIZE (mode
);
4679 /* Generate STORE CHARACTERS UNDER MASK (STCM et al). */
4681 && (bitsize
% BITS_PER_UNIT
) == 0
4683 && (register_operand (src
, word_mode
)
4684 || const_int_operand (src
, VOIDmode
)))
4686 /* Emit standard pattern if possible. */
4687 if (smode_bsize
== bitsize
)
4689 emit_move_insn (adjust_address (dest
, smode
, 0),
4690 gen_lowpart (smode
, src
));
4694 /* (set (ze (mem)) (const_int)). */
4695 else if (const_int_operand (src
, VOIDmode
))
4697 int size
= bitsize
/ BITS_PER_UNIT
;
4698 rtx src_mem
= adjust_address (force_const_mem (word_mode
, src
),
4700 UNITS_PER_WORD
- size
);
4702 dest
= adjust_address (dest
, BLKmode
, 0);
4703 set_mem_size (dest
, size
);
4704 s390_expand_movmem (dest
, src_mem
, GEN_INT (size
));
4708 /* (set (ze (mem)) (reg)). */
4709 else if (register_operand (src
, word_mode
))
4712 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
, op1
,
4716 /* Emit st,stcmh sequence. */
4717 int stcmh_width
= bitsize
- 32;
4718 int size
= stcmh_width
/ BITS_PER_UNIT
;
4720 emit_move_insn (adjust_address (dest
, SImode
, size
),
4721 gen_lowpart (SImode
, src
));
4722 set_mem_size (dest
, size
);
4723 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
,
4724 GEN_INT (stcmh_width
),
4726 gen_rtx_LSHIFTRT (word_mode
, src
, GEN_INT (32)));
4732 /* Generate INSERT CHARACTERS UNDER MASK (IC, ICM et al). */
4733 if ((bitpos
% BITS_PER_UNIT
) == 0
4734 && (bitsize
% BITS_PER_UNIT
) == 0
4735 && (bitpos
& 32) == ((bitpos
+ bitsize
- 1) & 32)
4737 && (mode
== DImode
|| mode
== SImode
)
4738 && register_operand (dest
, mode
))
4740 /* Emit a strict_low_part pattern if possible. */
4741 if (smode_bsize
== bitsize
&& bitpos
== mode_bsize
- smode_bsize
)
4743 op
= gen_rtx_STRICT_LOW_PART (VOIDmode
, gen_lowpart (smode
, dest
));
4744 op
= gen_rtx_SET (VOIDmode
, op
, gen_lowpart (smode
, src
));
4745 clobber
= gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
4746 emit_insn (gen_rtx_PARALLEL (VOIDmode
, gen_rtvec (2, op
, clobber
)));
4750 /* ??? There are more powerful versions of ICM that are not
4751 completely represented in the md file. */
4754 /* For z10, generate ROTATE THEN INSERT SELECTED BITS (RISBG et al). */
4755 if (TARGET_Z10
&& (mode
== DImode
|| mode
== SImode
))
4757 machine_mode mode_s
= GET_MODE (src
);
4759 if (mode_s
== VOIDmode
)
4761 /* Assume const_int etc already in the proper mode. */
4762 src
= force_reg (mode
, src
);
4764 else if (mode_s
!= mode
)
4766 gcc_assert (GET_MODE_BITSIZE (mode_s
) >= bitsize
);
4767 src
= force_reg (mode_s
, src
);
4768 src
= gen_lowpart (mode
, src
);
4771 op
= gen_rtx_ZERO_EXTRACT (mode
, dest
, op1
, op2
),
4772 op
= gen_rtx_SET (VOIDmode
, op
, src
);
4776 clobber
= gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
4777 op
= gen_rtx_PARALLEL (VOIDmode
, gen_rtvec (2, op
, clobber
));
4787 /* A subroutine of s390_expand_cs_hqi and s390_expand_atomic which returns a
4788 register that holds VAL of mode MODE shifted by COUNT bits. */
4791 s390_expand_mask_and_shift (rtx val
, machine_mode mode
, rtx count
)
4793 val
= expand_simple_binop (SImode
, AND
, val
, GEN_INT (GET_MODE_MASK (mode
)),
4794 NULL_RTX
, 1, OPTAB_DIRECT
);
4795 return expand_simple_binop (SImode
, ASHIFT
, val
, count
,
4796 NULL_RTX
, 1, OPTAB_DIRECT
);
4799 /* Structure to hold the initial parameters for a compare_and_swap operation
4800 in HImode and QImode. */
4802 struct alignment_context
4804 rtx memsi
; /* SI aligned memory location. */
4805 rtx shift
; /* Bit offset with regard to lsb. */
4806 rtx modemask
; /* Mask of the HQImode shifted by SHIFT bits. */
4807 rtx modemaski
; /* ~modemask */
4808 bool aligned
; /* True if memory is aligned, false else. */
4811 /* A subroutine of s390_expand_cs_hqi and s390_expand_atomic to initialize
4812 structure AC for transparent simplifying, if the memory alignment is known
4813 to be at least 32bit. MEM is the memory location for the actual operation
4814 and MODE its mode. */
4817 init_alignment_context (struct alignment_context
*ac
, rtx mem
,
4820 ac
->shift
= GEN_INT (GET_MODE_SIZE (SImode
) - GET_MODE_SIZE (mode
));
4821 ac
->aligned
= (MEM_ALIGN (mem
) >= GET_MODE_BITSIZE (SImode
));
4824 ac
->memsi
= adjust_address (mem
, SImode
, 0); /* Memory is aligned. */
4827 /* Alignment is unknown. */
4828 rtx byteoffset
, addr
, align
;
4830 /* Force the address into a register. */
4831 addr
= force_reg (Pmode
, XEXP (mem
, 0));
4833 /* Align it to SImode. */
4834 align
= expand_simple_binop (Pmode
, AND
, addr
,
4835 GEN_INT (-GET_MODE_SIZE (SImode
)),
4836 NULL_RTX
, 1, OPTAB_DIRECT
);
4838 ac
->memsi
= gen_rtx_MEM (SImode
, align
);
4839 MEM_VOLATILE_P (ac
->memsi
) = MEM_VOLATILE_P (mem
);
4840 set_mem_alias_set (ac
->memsi
, ALIAS_SET_MEMORY_BARRIER
);
4841 set_mem_align (ac
->memsi
, GET_MODE_BITSIZE (SImode
));
4843 /* Calculate shiftcount. */
4844 byteoffset
= expand_simple_binop (Pmode
, AND
, addr
,
4845 GEN_INT (GET_MODE_SIZE (SImode
) - 1),
4846 NULL_RTX
, 1, OPTAB_DIRECT
);
4847 /* As we already have some offset, evaluate the remaining distance. */
4848 ac
->shift
= expand_simple_binop (SImode
, MINUS
, ac
->shift
, byteoffset
,
4849 NULL_RTX
, 1, OPTAB_DIRECT
);
4852 /* Shift is the byte count, but we need the bitcount. */
4853 ac
->shift
= expand_simple_binop (SImode
, ASHIFT
, ac
->shift
, GEN_INT (3),
4854 NULL_RTX
, 1, OPTAB_DIRECT
);
4856 /* Calculate masks. */
4857 ac
->modemask
= expand_simple_binop (SImode
, ASHIFT
,
4858 GEN_INT (GET_MODE_MASK (mode
)),
4859 ac
->shift
, NULL_RTX
, 1, OPTAB_DIRECT
);
4860 ac
->modemaski
= expand_simple_unop (SImode
, NOT
, ac
->modemask
,
4864 /* A subroutine of s390_expand_cs_hqi. Insert INS into VAL. If possible,
4865 use a single insv insn into SEQ2. Otherwise, put prep insns in SEQ1 and
4866 perform the merge in SEQ2. */
4869 s390_two_part_insv (struct alignment_context
*ac
, rtx
*seq1
, rtx
*seq2
,
4870 machine_mode mode
, rtx val
, rtx ins
)
4877 tmp
= copy_to_mode_reg (SImode
, val
);
4878 if (s390_expand_insv (tmp
, GEN_INT (GET_MODE_BITSIZE (mode
)),
4882 *seq2
= get_insns ();
4889 /* Failed to use insv. Generate a two part shift and mask. */
4891 tmp
= s390_expand_mask_and_shift (ins
, mode
, ac
->shift
);
4892 *seq1
= get_insns ();
4896 tmp
= expand_simple_binop (SImode
, IOR
, tmp
, val
, NULL_RTX
, 1, OPTAB_DIRECT
);
4897 *seq2
= get_insns ();
4903 /* Expand an atomic compare and swap operation for HImode and QImode. MEM is
4904 the memory location, CMP the old value to compare MEM with and NEW_RTX the
4905 value to set if CMP == MEM. */
4908 s390_expand_cs_hqi (machine_mode mode
, rtx btarget
, rtx vtarget
, rtx mem
,
4909 rtx cmp
, rtx new_rtx
, bool is_weak
)
4911 struct alignment_context ac
;
4912 rtx cmpv
, newv
, val
, cc
, seq0
, seq1
, seq2
, seq3
;
4913 rtx res
= gen_reg_rtx (SImode
);
4914 rtx_code_label
*csloop
= NULL
, *csend
= NULL
;
4916 gcc_assert (MEM_P (mem
));
4918 init_alignment_context (&ac
, mem
, mode
);
4920 /* Load full word. Subsequent loads are performed by CS. */
4921 val
= expand_simple_binop (SImode
, AND
, ac
.memsi
, ac
.modemaski
,
4922 NULL_RTX
, 1, OPTAB_DIRECT
);
4924 /* Prepare insertions of cmp and new_rtx into the loaded value. When
4925 possible, we try to use insv to make this happen efficiently. If
4926 that fails we'll generate code both inside and outside the loop. */
4927 cmpv
= s390_two_part_insv (&ac
, &seq0
, &seq2
, mode
, val
, cmp
);
4928 newv
= s390_two_part_insv (&ac
, &seq1
, &seq3
, mode
, val
, new_rtx
);
4935 /* Start CS loop. */
4938 /* Begin assuming success. */
4939 emit_move_insn (btarget
, const1_rtx
);
4941 csloop
= gen_label_rtx ();
4942 csend
= gen_label_rtx ();
4943 emit_label (csloop
);
4946 /* val = "<mem>00..0<mem>"
4947 * cmp = "00..0<cmp>00..0"
4948 * new = "00..0<new>00..0"
4954 cc
= s390_emit_compare_and_swap (EQ
, res
, ac
.memsi
, cmpv
, newv
);
4956 emit_insn (gen_cstorecc4 (btarget
, cc
, XEXP (cc
, 0), XEXP (cc
, 1)));
4961 /* Jump to end if we're done (likely?). */
4962 s390_emit_jump (csend
, cc
);
4964 /* Check for changes outside mode, and loop internal if so.
4965 Arrange the moves so that the compare is adjacent to the
4966 branch so that we can generate CRJ. */
4967 tmp
= copy_to_reg (val
);
4968 force_expand_binop (SImode
, and_optab
, res
, ac
.modemaski
, val
,
4970 cc
= s390_emit_compare (NE
, val
, tmp
);
4971 s390_emit_jump (csloop
, cc
);
4974 emit_move_insn (btarget
, const0_rtx
);
4978 /* Return the correct part of the bitfield. */
4979 convert_move (vtarget
, expand_simple_binop (SImode
, LSHIFTRT
, res
, ac
.shift
,
4980 NULL_RTX
, 1, OPTAB_DIRECT
), 1);
4983 /* Expand an atomic operation CODE of mode MODE. MEM is the memory location
4984 and VAL the value to play with. If AFTER is true then store the value
4985 MEM holds after the operation, if AFTER is false then store the value MEM
4986 holds before the operation. If TARGET is zero then discard that value, else
4987 store it to TARGET. */
4990 s390_expand_atomic (machine_mode mode
, enum rtx_code code
,
4991 rtx target
, rtx mem
, rtx val
, bool after
)
4993 struct alignment_context ac
;
4995 rtx new_rtx
= gen_reg_rtx (SImode
);
4996 rtx orig
= gen_reg_rtx (SImode
);
4997 rtx_code_label
*csloop
= gen_label_rtx ();
4999 gcc_assert (!target
|| register_operand (target
, VOIDmode
));
5000 gcc_assert (MEM_P (mem
));
5002 init_alignment_context (&ac
, mem
, mode
);
5004 /* Shift val to the correct bit positions.
5005 Preserve "icm", but prevent "ex icm". */
5006 if (!(ac
.aligned
&& code
== SET
&& MEM_P (val
)))
5007 val
= s390_expand_mask_and_shift (val
, mode
, ac
.shift
);
5009 /* Further preparation insns. */
5010 if (code
== PLUS
|| code
== MINUS
)
5011 emit_move_insn (orig
, val
);
5012 else if (code
== MULT
|| code
== AND
) /* val = "11..1<val>11..1" */
5013 val
= expand_simple_binop (SImode
, XOR
, val
, ac
.modemaski
,
5014 NULL_RTX
, 1, OPTAB_DIRECT
);
5016 /* Load full word. Subsequent loads are performed by CS. */
5017 cmp
= force_reg (SImode
, ac
.memsi
);
5019 /* Start CS loop. */
5020 emit_label (csloop
);
5021 emit_move_insn (new_rtx
, cmp
);
5023 /* Patch new with val at correct position. */
5028 val
= expand_simple_binop (SImode
, code
, new_rtx
, orig
,
5029 NULL_RTX
, 1, OPTAB_DIRECT
);
5030 val
= expand_simple_binop (SImode
, AND
, val
, ac
.modemask
,
5031 NULL_RTX
, 1, OPTAB_DIRECT
);
5034 if (ac
.aligned
&& MEM_P (val
))
5035 store_bit_field (new_rtx
, GET_MODE_BITSIZE (mode
), 0,
5039 new_rtx
= expand_simple_binop (SImode
, AND
, new_rtx
, ac
.modemaski
,
5040 NULL_RTX
, 1, OPTAB_DIRECT
);
5041 new_rtx
= expand_simple_binop (SImode
, IOR
, new_rtx
, val
,
5042 NULL_RTX
, 1, OPTAB_DIRECT
);
5048 new_rtx
= expand_simple_binop (SImode
, code
, new_rtx
, val
,
5049 NULL_RTX
, 1, OPTAB_DIRECT
);
5051 case MULT
: /* NAND */
5052 new_rtx
= expand_simple_binop (SImode
, AND
, new_rtx
, val
,
5053 NULL_RTX
, 1, OPTAB_DIRECT
);
5054 new_rtx
= expand_simple_binop (SImode
, XOR
, new_rtx
, ac
.modemask
,
5055 NULL_RTX
, 1, OPTAB_DIRECT
);
5061 s390_emit_jump (csloop
, s390_emit_compare_and_swap (NE
, cmp
,
5062 ac
.memsi
, cmp
, new_rtx
));
5064 /* Return the correct part of the bitfield. */
5066 convert_move (target
, expand_simple_binop (SImode
, LSHIFTRT
,
5067 after
? new_rtx
: cmp
, ac
.shift
,
5068 NULL_RTX
, 1, OPTAB_DIRECT
), 1);
5071 /* This is called from dwarf2out.c via TARGET_ASM_OUTPUT_DWARF_DTPREL.
5072 We need to emit DTP-relative relocations. */
5074 static void s390_output_dwarf_dtprel (FILE *, int, rtx
) ATTRIBUTE_UNUSED
;
5077 s390_output_dwarf_dtprel (FILE *file
, int size
, rtx x
)
5082 fputs ("\t.long\t", file
);
5085 fputs ("\t.quad\t", file
);
5090 output_addr_const (file
, x
);
5091 fputs ("@DTPOFF", file
);
5094 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
5095 /* Implement TARGET_MANGLE_TYPE. */
5098 s390_mangle_type (const_tree type
)
5100 if (TYPE_MAIN_VARIANT (type
) == long_double_type_node
5101 && TARGET_LONG_DOUBLE_128
)
5104 /* For all other types, use normal C++ mangling. */
5109 /* In the name of slightly smaller debug output, and to cater to
5110 general assembler lossage, recognize various UNSPEC sequences
5111 and turn them back into a direct symbol reference. */
5114 s390_delegitimize_address (rtx orig_x
)
5118 orig_x
= delegitimize_mem_from_attrs (orig_x
);
5121 /* Extract the symbol ref from:
5122 (plus:SI (reg:SI 12 %r12)
5123 (const:SI (unspec:SI [(symbol_ref/f:SI ("*.LC0"))]
5124 UNSPEC_GOTOFF/PLTOFF)))
5126 (plus:SI (reg:SI 12 %r12)
5127 (const:SI (plus:SI (unspec:SI [(symbol_ref:SI ("L"))]
5128 UNSPEC_GOTOFF/PLTOFF)
5129 (const_int 4 [0x4])))) */
5130 if (GET_CODE (x
) == PLUS
5131 && REG_P (XEXP (x
, 0))
5132 && REGNO (XEXP (x
, 0)) == PIC_OFFSET_TABLE_REGNUM
5133 && GET_CODE (XEXP (x
, 1)) == CONST
)
5135 HOST_WIDE_INT offset
= 0;
5137 /* The const operand. */
5138 y
= XEXP (XEXP (x
, 1), 0);
5140 if (GET_CODE (y
) == PLUS
5141 && GET_CODE (XEXP (y
, 1)) == CONST_INT
)
5143 offset
= INTVAL (XEXP (y
, 1));
5147 if (GET_CODE (y
) == UNSPEC
5148 && (XINT (y
, 1) == UNSPEC_GOTOFF
5149 || XINT (y
, 1) == UNSPEC_PLTOFF
))
5150 return plus_constant (Pmode
, XVECEXP (y
, 0, 0), offset
);
5153 if (GET_CODE (x
) != MEM
)
5157 if (GET_CODE (x
) == PLUS
5158 && GET_CODE (XEXP (x
, 1)) == CONST
5159 && GET_CODE (XEXP (x
, 0)) == REG
5160 && REGNO (XEXP (x
, 0)) == PIC_OFFSET_TABLE_REGNUM
)
5162 y
= XEXP (XEXP (x
, 1), 0);
5163 if (GET_CODE (y
) == UNSPEC
5164 && XINT (y
, 1) == UNSPEC_GOT
)
5165 y
= XVECEXP (y
, 0, 0);
5169 else if (GET_CODE (x
) == CONST
)
5171 /* Extract the symbol ref from:
5172 (mem:QI (const:DI (unspec:DI [(symbol_ref:DI ("foo"))]
5173 UNSPEC_PLT/GOTENT))) */
5176 if (GET_CODE (y
) == UNSPEC
5177 && (XINT (y
, 1) == UNSPEC_GOTENT
5178 || XINT (y
, 1) == UNSPEC_PLT
))
5179 y
= XVECEXP (y
, 0, 0);
5186 if (GET_MODE (orig_x
) != Pmode
)
5188 if (GET_MODE (orig_x
) == BLKmode
)
5190 y
= lowpart_subreg (GET_MODE (orig_x
), y
, Pmode
);
5197 /* Output operand OP to stdio stream FILE.
5198 OP is an address (register + offset) which is not used to address data;
5199 instead the rightmost bits are interpreted as the value. */
5202 print_shift_count_operand (FILE *file
, rtx op
)
5204 HOST_WIDE_INT offset
;
5207 /* Extract base register and offset. */
5208 if (!s390_decompose_shift_count (op
, &base
, &offset
))
5214 gcc_assert (GET_CODE (base
) == REG
);
5215 gcc_assert (REGNO (base
) < FIRST_PSEUDO_REGISTER
);
5216 gcc_assert (REGNO_REG_CLASS (REGNO (base
)) == ADDR_REGS
);
5219 /* Offsets are constricted to twelve bits. */
5220 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, offset
& ((1 << 12) - 1));
5222 fprintf (file
, "(%s)", reg_names
[REGNO (base
)]);
5225 /* Returns -1 if the function should not be made hotpatchable. Otherwise it
5226 returns a number >= 0 that is the desired size of the hotpatch trampoline
5229 static int s390_function_num_hotpatch_trampoline_halfwords (tree decl
,
5234 if (DECL_DECLARED_INLINE_P (decl
)
5235 || DECL_ARTIFICIAL (decl
)
5236 || MAIN_NAME_P (DECL_NAME (decl
)))
5238 /* - Explicitly inlined functions cannot be hotpatched.
5239 - Artificial functions need not be hotpatched.
5240 - Making the main function hotpatchable is useless. */
5243 attr
= lookup_attribute ("hotpatch", DECL_ATTRIBUTES (decl
));
5244 if (attr
|| s390_hotpatch_trampoline_halfwords
>= 0)
5246 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (decl
)))
5249 warning (OPT_Wattributes
, "function %qE with the %qs attribute"
5250 " is not hotpatchable", DECL_NAME (decl
), "always_inline");
5256 get_hotpatch_attribute (attr
) : s390_hotpatch_trampoline_halfwords
;
5263 /* Hook to determine if one function can safely inline another. */
5266 s390_can_inline_p (tree caller
, tree callee
)
5268 if (s390_function_num_hotpatch_trampoline_halfwords (callee
, false) >= 0)
5271 return default_target_can_inline_p (caller
, callee
);
5274 /* Write the extra assembler code needed to declare a function properly. */
5277 s390_asm_output_function_label (FILE *asm_out_file
, const char *fname
,
5280 int hotpatch_trampoline_halfwords
= -1;
5284 hotpatch_trampoline_halfwords
=
5285 s390_function_num_hotpatch_trampoline_halfwords (decl
, true);
5286 if (hotpatch_trampoline_halfwords
>= 0
5287 && decl_function_context (decl
) != NULL_TREE
)
5289 warning_at (DECL_SOURCE_LOCATION (decl
), OPT_mhotpatch
,
5290 "hotpatching is not compatible with nested functions");
5291 hotpatch_trampoline_halfwords
= -1;
5295 if (hotpatch_trampoline_halfwords
> 0)
5299 /* Add a trampoline code area before the function label and initialize it
5300 with two-byte nop instructions. This area can be overwritten with code
5301 that jumps to a patched version of the function. */
5302 for (i
= 0; i
< hotpatch_trampoline_halfwords
; i
++)
5303 asm_fprintf (asm_out_file
, "\tnopr\t%%r7\n");
5304 /* Note: The function label must be aligned so that (a) the bytes of the
5305 following nop do not cross a cacheline boundary, and (b) a jump address
5306 (eight bytes for 64 bit targets, 4 bytes for 32 bit targets) can be
5307 stored directly before the label without crossing a cacheline
5308 boundary. All this is necessary to make sure the trampoline code can
5309 be changed atomically. */
5312 ASM_OUTPUT_LABEL (asm_out_file
, fname
);
5314 /* Output a four-byte nop if hotpatching is enabled. This can be overwritten
5315 atomically with a relative backwards jump to the trampoline area. */
5316 if (hotpatch_trampoline_halfwords
>= 0)
5317 asm_fprintf (asm_out_file
, "\tnop\t0\n");
5320 /* Output machine-dependent UNSPECs occurring in address constant X
5321 in assembler syntax to stdio stream FILE. Returns true if the
5322 constant X could be recognized, false otherwise. */
5325 s390_output_addr_const_extra (FILE *file
, rtx x
)
5327 if (GET_CODE (x
) == UNSPEC
&& XVECLEN (x
, 0) == 1)
5328 switch (XINT (x
, 1))
5331 output_addr_const (file
, XVECEXP (x
, 0, 0));
5332 fprintf (file
, "@GOTENT");
5335 output_addr_const (file
, XVECEXP (x
, 0, 0));
5336 fprintf (file
, "@GOT");
5339 output_addr_const (file
, XVECEXP (x
, 0, 0));
5340 fprintf (file
, "@GOTOFF");
5343 output_addr_const (file
, XVECEXP (x
, 0, 0));
5344 fprintf (file
, "@PLT");
5347 output_addr_const (file
, XVECEXP (x
, 0, 0));
5348 fprintf (file
, "@PLTOFF");
5351 output_addr_const (file
, XVECEXP (x
, 0, 0));
5352 fprintf (file
, "@TLSGD");
5355 assemble_name (file
, get_some_local_dynamic_name ());
5356 fprintf (file
, "@TLSLDM");
5359 output_addr_const (file
, XVECEXP (x
, 0, 0));
5360 fprintf (file
, "@DTPOFF");
5363 output_addr_const (file
, XVECEXP (x
, 0, 0));
5364 fprintf (file
, "@NTPOFF");
5366 case UNSPEC_GOTNTPOFF
:
5367 output_addr_const (file
, XVECEXP (x
, 0, 0));
5368 fprintf (file
, "@GOTNTPOFF");
5370 case UNSPEC_INDNTPOFF
:
5371 output_addr_const (file
, XVECEXP (x
, 0, 0));
5372 fprintf (file
, "@INDNTPOFF");
5376 if (GET_CODE (x
) == UNSPEC
&& XVECLEN (x
, 0) == 2)
5377 switch (XINT (x
, 1))
5379 case UNSPEC_POOL_OFFSET
:
5380 x
= gen_rtx_MINUS (GET_MODE (x
), XVECEXP (x
, 0, 0), XVECEXP (x
, 0, 1));
5381 output_addr_const (file
, x
);
5387 /* Output address operand ADDR in assembler syntax to
5388 stdio stream FILE. */
5391 print_operand_address (FILE *file
, rtx addr
)
5393 struct s390_address ad
;
5395 if (s390_loadrelative_operand_p (addr
, NULL
, NULL
))
5399 output_operand_lossage ("symbolic memory references are "
5400 "only supported on z10 or later");
5403 output_addr_const (file
, addr
);
5407 if (!s390_decompose_address (addr
, &ad
)
5408 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
5409 || (ad
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (ad
.indx
))))
5410 output_operand_lossage ("cannot decompose address");
5413 output_addr_const (file
, ad
.disp
);
5415 fprintf (file
, "0");
5417 if (ad
.base
&& ad
.indx
)
5418 fprintf (file
, "(%s,%s)", reg_names
[REGNO (ad
.indx
)],
5419 reg_names
[REGNO (ad
.base
)]);
5421 fprintf (file
, "(%s)", reg_names
[REGNO (ad
.base
)]);
5424 /* Output operand X in assembler syntax to stdio stream FILE.
5425 CODE specified the format flag. The following format flags
5428 'C': print opcode suffix for branch condition.
5429 'D': print opcode suffix for inverse branch condition.
5430 'E': print opcode suffix for branch on index instruction.
5431 'G': print the size of the operand in bytes.
5432 'J': print tls_load/tls_gdcall/tls_ldcall suffix
5433 'M': print the second word of a TImode operand.
5434 'N': print the second word of a DImode operand.
5435 'O': print only the displacement of a memory reference.
5436 'R': print only the base register of a memory reference.
5437 'S': print S-type memory reference (base+displacement).
5438 'Y': print shift count operand.
5440 'b': print integer X as if it's an unsigned byte.
5441 'c': print integer X as if it's an signed byte.
5442 'e': "end" of DImode contiguous bitmask X.
5443 'f': "end" of SImode contiguous bitmask X.
5444 'h': print integer X as if it's a signed halfword.
5445 'i': print the first nonzero HImode part of X.
5446 'j': print the first HImode part unequal to -1 of X.
5447 'k': print the first nonzero SImode part of X.
5448 'm': print the first SImode part unequal to -1 of X.
5449 'o': print integer X as if it's an unsigned 32bit word.
5450 's': "start" of DImode contiguous bitmask X.
5451 't': "start" of SImode contiguous bitmask X.
5452 'x': print integer X as if it's an unsigned halfword.
5456 print_operand (FILE *file
, rtx x
, int code
)
5463 fprintf (file
, s390_branch_condition_mnemonic (x
, FALSE
));
5467 fprintf (file
, s390_branch_condition_mnemonic (x
, TRUE
));
5471 if (GET_CODE (x
) == LE
)
5472 fprintf (file
, "l");
5473 else if (GET_CODE (x
) == GT
)
5474 fprintf (file
, "h");
5476 output_operand_lossage ("invalid comparison operator "
5477 "for 'E' output modifier");
5481 if (GET_CODE (x
) == SYMBOL_REF
)
5483 fprintf (file
, "%s", ":tls_load:");
5484 output_addr_const (file
, x
);
5486 else if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_TLSGD
)
5488 fprintf (file
, "%s", ":tls_gdcall:");
5489 output_addr_const (file
, XVECEXP (x
, 0, 0));
5491 else if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_TLSLDM
)
5493 fprintf (file
, "%s", ":tls_ldcall:");
5494 const char *name
= get_some_local_dynamic_name ();
5496 assemble_name (file
, name
);
5499 output_operand_lossage ("invalid reference for 'J' output modifier");
5503 fprintf (file
, "%u", GET_MODE_SIZE (GET_MODE (x
)));
5508 struct s390_address ad
;
5513 output_operand_lossage ("memory reference expected for "
5514 "'O' output modifier");
5518 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
5521 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
5524 output_operand_lossage ("invalid address for 'O' output modifier");
5529 output_addr_const (file
, ad
.disp
);
5531 fprintf (file
, "0");
5537 struct s390_address ad
;
5542 output_operand_lossage ("memory reference expected for "
5543 "'R' output modifier");
5547 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
5550 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
5553 output_operand_lossage ("invalid address for 'R' output modifier");
5558 fprintf (file
, "%s", reg_names
[REGNO (ad
.base
)]);
5560 fprintf (file
, "0");
5566 struct s390_address ad
;
5571 output_operand_lossage ("memory reference expected for "
5572 "'S' output modifier");
5575 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
5578 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
5581 output_operand_lossage ("invalid address for 'S' output modifier");
5586 output_addr_const (file
, ad
.disp
);
5588 fprintf (file
, "0");
5591 fprintf (file
, "(%s)", reg_names
[REGNO (ad
.base
)]);
5596 if (GET_CODE (x
) == REG
)
5597 x
= gen_rtx_REG (GET_MODE (x
), REGNO (x
) + 1);
5598 else if (GET_CODE (x
) == MEM
)
5599 x
= change_address (x
, VOIDmode
,
5600 plus_constant (Pmode
, XEXP (x
, 0), 4));
5602 output_operand_lossage ("register or memory expression expected "
5603 "for 'N' output modifier");
5607 if (GET_CODE (x
) == REG
)
5608 x
= gen_rtx_REG (GET_MODE (x
), REGNO (x
) + 1);
5609 else if (GET_CODE (x
) == MEM
)
5610 x
= change_address (x
, VOIDmode
,
5611 plus_constant (Pmode
, XEXP (x
, 0), 8));
5613 output_operand_lossage ("register or memory expression expected "
5614 "for 'M' output modifier");
5618 print_shift_count_operand (file
, x
);
5622 switch (GET_CODE (x
))
5625 fprintf (file
, "%s", reg_names
[REGNO (x
)]);
5629 output_address (XEXP (x
, 0));
5636 output_addr_const (file
, x
);
5649 ival
= ((ival
& 0xff) ^ 0x80) - 0x80;
5655 ival
= ((ival
& 0xffff) ^ 0x8000) - 0x8000;
5658 ival
= s390_extract_part (x
, HImode
, 0);
5661 ival
= s390_extract_part (x
, HImode
, -1);
5664 ival
= s390_extract_part (x
, SImode
, 0);
5667 ival
= s390_extract_part (x
, SImode
, -1);
5678 len
= (code
== 's' || code
== 'e' ? 64 : 32);
5679 ok
= s390_contiguous_bitmask_p (ival
, len
, &pos
, &len
);
5681 if (code
== 's' || code
== 't')
5682 ival
= 64 - pos
- len
;
5684 ival
= 64 - 1 - pos
;
5688 output_operand_lossage ("invalid constant for output modifier '%c'", code
);
5690 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, ival
);
5694 gcc_assert (GET_MODE (x
) == VOIDmode
);
5696 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, CONST_DOUBLE_LOW (x
) & 0xff);
5697 else if (code
== 'x')
5698 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, CONST_DOUBLE_LOW (x
) & 0xffff);
5699 else if (code
== 'h')
5700 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
5701 ((CONST_DOUBLE_LOW (x
) & 0xffff) ^ 0x8000) - 0x8000);
5705 output_operand_lossage ("invalid constant - try using "
5706 "an output modifier");
5708 output_operand_lossage ("invalid constant for output modifier '%c'",
5715 output_operand_lossage ("invalid expression - try using "
5716 "an output modifier");
5718 output_operand_lossage ("invalid expression for output "
5719 "modifier '%c'", code
);
5724 /* Target hook for assembling integer objects. We need to define it
5725 here to work a round a bug in some versions of GAS, which couldn't
5726 handle values smaller than INT_MIN when printed in decimal. */
5729 s390_assemble_integer (rtx x
, unsigned int size
, int aligned_p
)
5731 if (size
== 8 && aligned_p
5732 && GET_CODE (x
) == CONST_INT
&& INTVAL (x
) < INT_MIN
)
5734 fprintf (asm_out_file
, "\t.quad\t" HOST_WIDE_INT_PRINT_HEX
"\n",
5738 return default_assemble_integer (x
, size
, aligned_p
);
5741 /* Returns true if register REGNO is used for forming
5742 a memory address in expression X. */
5745 reg_used_in_mem_p (int regno
, rtx x
)
5747 enum rtx_code code
= GET_CODE (x
);
5753 if (refers_to_regno_p (regno
, XEXP (x
, 0)))
5756 else if (code
== SET
5757 && GET_CODE (SET_DEST (x
)) == PC
)
5759 if (refers_to_regno_p (regno
, SET_SRC (x
)))
5763 fmt
= GET_RTX_FORMAT (code
);
5764 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
5767 && reg_used_in_mem_p (regno
, XEXP (x
, i
)))
5770 else if (fmt
[i
] == 'E')
5771 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
5772 if (reg_used_in_mem_p (regno
, XVECEXP (x
, i
, j
)))
5778 /* Returns true if expression DEP_RTX sets an address register
5779 used by instruction INSN to address memory. */
5782 addr_generation_dependency_p (rtx dep_rtx
, rtx_insn
*insn
)
5786 if (NONJUMP_INSN_P (dep_rtx
))
5787 dep_rtx
= PATTERN (dep_rtx
);
5789 if (GET_CODE (dep_rtx
) == SET
)
5791 target
= SET_DEST (dep_rtx
);
5792 if (GET_CODE (target
) == STRICT_LOW_PART
)
5793 target
= XEXP (target
, 0);
5794 while (GET_CODE (target
) == SUBREG
)
5795 target
= SUBREG_REG (target
);
5797 if (GET_CODE (target
) == REG
)
5799 int regno
= REGNO (target
);
5801 if (s390_safe_attr_type (insn
) == TYPE_LA
)
5803 pat
= PATTERN (insn
);
5804 if (GET_CODE (pat
) == PARALLEL
)
5806 gcc_assert (XVECLEN (pat
, 0) == 2);
5807 pat
= XVECEXP (pat
, 0, 0);
5809 gcc_assert (GET_CODE (pat
) == SET
);
5810 return refers_to_regno_p (regno
, SET_SRC (pat
));
5812 else if (get_attr_atype (insn
) == ATYPE_AGEN
)
5813 return reg_used_in_mem_p (regno
, PATTERN (insn
));
5819 /* Return 1, if dep_insn sets register used in insn in the agen unit. */
5822 s390_agen_dep_p (rtx_insn
*dep_insn
, rtx_insn
*insn
)
5824 rtx dep_rtx
= PATTERN (dep_insn
);
5827 if (GET_CODE (dep_rtx
) == SET
5828 && addr_generation_dependency_p (dep_rtx
, insn
))
5830 else if (GET_CODE (dep_rtx
) == PARALLEL
)
5832 for (i
= 0; i
< XVECLEN (dep_rtx
, 0); i
++)
5834 if (addr_generation_dependency_p (XVECEXP (dep_rtx
, 0, i
), insn
))
5842 /* A C statement (sans semicolon) to update the integer scheduling priority
5843 INSN_PRIORITY (INSN). Increase the priority to execute the INSN earlier,
5844 reduce the priority to execute INSN later. Do not define this macro if
5845 you do not need to adjust the scheduling priorities of insns.
5847 A STD instruction should be scheduled earlier,
5848 in order to use the bypass. */
5850 s390_adjust_priority (rtx_insn
*insn
, int priority
)
5852 if (! INSN_P (insn
))
5855 if (s390_tune
!= PROCESSOR_2084_Z990
5856 && s390_tune
!= PROCESSOR_2094_Z9_109
5857 && s390_tune
!= PROCESSOR_2097_Z10
5858 && s390_tune
!= PROCESSOR_2817_Z196
5859 && s390_tune
!= PROCESSOR_2827_ZEC12
)
5862 switch (s390_safe_attr_type (insn
))
5866 priority
= priority
<< 3;
5870 priority
= priority
<< 1;
5879 /* The number of instructions that can be issued per cycle. */
5882 s390_issue_rate (void)
5886 case PROCESSOR_2084_Z990
:
5887 case PROCESSOR_2094_Z9_109
:
5888 case PROCESSOR_2817_Z196
:
5890 case PROCESSOR_2097_Z10
:
5891 case PROCESSOR_2827_ZEC12
:
5899 s390_first_cycle_multipass_dfa_lookahead (void)
5904 /* Annotate every literal pool reference in X by an UNSPEC_LTREF expression.
5905 Fix up MEMs as required. */
5908 annotate_constant_pool_refs (rtx
*x
)
5913 gcc_assert (GET_CODE (*x
) != SYMBOL_REF
5914 || !CONSTANT_POOL_ADDRESS_P (*x
));
5916 /* Literal pool references can only occur inside a MEM ... */
5917 if (GET_CODE (*x
) == MEM
)
5919 rtx memref
= XEXP (*x
, 0);
5921 if (GET_CODE (memref
) == SYMBOL_REF
5922 && CONSTANT_POOL_ADDRESS_P (memref
))
5924 rtx base
= cfun
->machine
->base_reg
;
5925 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, memref
, base
),
5928 *x
= replace_equiv_address (*x
, addr
);
5932 if (GET_CODE (memref
) == CONST
5933 && GET_CODE (XEXP (memref
, 0)) == PLUS
5934 && GET_CODE (XEXP (XEXP (memref
, 0), 1)) == CONST_INT
5935 && GET_CODE (XEXP (XEXP (memref
, 0), 0)) == SYMBOL_REF
5936 && CONSTANT_POOL_ADDRESS_P (XEXP (XEXP (memref
, 0), 0)))
5938 HOST_WIDE_INT off
= INTVAL (XEXP (XEXP (memref
, 0), 1));
5939 rtx sym
= XEXP (XEXP (memref
, 0), 0);
5940 rtx base
= cfun
->machine
->base_reg
;
5941 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, sym
, base
),
5944 *x
= replace_equiv_address (*x
, plus_constant (Pmode
, addr
, off
));
5949 /* ... or a load-address type pattern. */
5950 if (GET_CODE (*x
) == SET
)
5952 rtx addrref
= SET_SRC (*x
);
5954 if (GET_CODE (addrref
) == SYMBOL_REF
5955 && CONSTANT_POOL_ADDRESS_P (addrref
))
5957 rtx base
= cfun
->machine
->base_reg
;
5958 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, addrref
, base
),
5961 SET_SRC (*x
) = addr
;
5965 if (GET_CODE (addrref
) == CONST
5966 && GET_CODE (XEXP (addrref
, 0)) == PLUS
5967 && GET_CODE (XEXP (XEXP (addrref
, 0), 1)) == CONST_INT
5968 && GET_CODE (XEXP (XEXP (addrref
, 0), 0)) == SYMBOL_REF
5969 && CONSTANT_POOL_ADDRESS_P (XEXP (XEXP (addrref
, 0), 0)))
5971 HOST_WIDE_INT off
= INTVAL (XEXP (XEXP (addrref
, 0), 1));
5972 rtx sym
= XEXP (XEXP (addrref
, 0), 0);
5973 rtx base
= cfun
->machine
->base_reg
;
5974 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, sym
, base
),
5977 SET_SRC (*x
) = plus_constant (Pmode
, addr
, off
);
5982 /* Annotate LTREL_BASE as well. */
5983 if (GET_CODE (*x
) == UNSPEC
5984 && XINT (*x
, 1) == UNSPEC_LTREL_BASE
)
5986 rtx base
= cfun
->machine
->base_reg
;
5987 *x
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, XVECEXP (*x
, 0, 0), base
),
5992 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
5993 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
5997 annotate_constant_pool_refs (&XEXP (*x
, i
));
5999 else if (fmt
[i
] == 'E')
6001 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
6002 annotate_constant_pool_refs (&XVECEXP (*x
, i
, j
));
6007 /* Split all branches that exceed the maximum distance.
6008 Returns true if this created a new literal pool entry. */
6011 s390_split_branches (void)
6013 rtx temp_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
6014 int new_literal
= 0, ret
;
6019 /* We need correct insn addresses. */
6021 shorten_branches (get_insns ());
6023 /* Find all branches that exceed 64KB, and split them. */
6025 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6027 if (! JUMP_P (insn
) || tablejump_p (insn
, NULL
, NULL
))
6030 pat
= PATTERN (insn
);
6031 if (GET_CODE (pat
) == PARALLEL
)
6032 pat
= XVECEXP (pat
, 0, 0);
6033 if (GET_CODE (pat
) != SET
|| SET_DEST (pat
) != pc_rtx
)
6036 if (GET_CODE (SET_SRC (pat
)) == LABEL_REF
)
6038 label
= &SET_SRC (pat
);
6040 else if (GET_CODE (SET_SRC (pat
)) == IF_THEN_ELSE
)
6042 if (GET_CODE (XEXP (SET_SRC (pat
), 1)) == LABEL_REF
)
6043 label
= &XEXP (SET_SRC (pat
), 1);
6044 else if (GET_CODE (XEXP (SET_SRC (pat
), 2)) == LABEL_REF
)
6045 label
= &XEXP (SET_SRC (pat
), 2);
6052 if (get_attr_length (insn
) <= 4)
6055 /* We are going to use the return register as scratch register,
6056 make sure it will be saved/restored by the prologue/epilogue. */
6057 cfun_frame_layout
.save_return_addr_p
= 1;
6062 rtx mem
= force_const_mem (Pmode
, *label
);
6063 rtx_insn
*set_insn
= emit_insn_before (gen_rtx_SET (Pmode
, temp_reg
, mem
), insn
);
6064 INSN_ADDRESSES_NEW (set_insn
, -1);
6065 annotate_constant_pool_refs (&PATTERN (set_insn
));
6072 target
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, *label
),
6073 UNSPEC_LTREL_OFFSET
);
6074 target
= gen_rtx_CONST (Pmode
, target
);
6075 target
= force_const_mem (Pmode
, target
);
6076 rtx_insn
*set_insn
= emit_insn_before (gen_rtx_SET (Pmode
, temp_reg
, target
), insn
);
6077 INSN_ADDRESSES_NEW (set_insn
, -1);
6078 annotate_constant_pool_refs (&PATTERN (set_insn
));
6080 target
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, XEXP (target
, 0),
6081 cfun
->machine
->base_reg
),
6083 target
= gen_rtx_PLUS (Pmode
, temp_reg
, target
);
6086 ret
= validate_change (insn
, label
, target
, 0);
6094 /* Find an annotated literal pool symbol referenced in RTX X,
6095 and store it at REF. Will abort if X contains references to
6096 more than one such pool symbol; multiple references to the same
6097 symbol are allowed, however.
6099 The rtx pointed to by REF must be initialized to NULL_RTX
6100 by the caller before calling this routine. */
6103 find_constant_pool_ref (rtx x
, rtx
*ref
)
6108 /* Ignore LTREL_BASE references. */
6109 if (GET_CODE (x
) == UNSPEC
6110 && XINT (x
, 1) == UNSPEC_LTREL_BASE
)
6112 /* Likewise POOL_ENTRY insns. */
6113 if (GET_CODE (x
) == UNSPEC_VOLATILE
6114 && XINT (x
, 1) == UNSPECV_POOL_ENTRY
)
6117 gcc_assert (GET_CODE (x
) != SYMBOL_REF
6118 || !CONSTANT_POOL_ADDRESS_P (x
));
6120 if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_LTREF
)
6122 rtx sym
= XVECEXP (x
, 0, 0);
6123 gcc_assert (GET_CODE (sym
) == SYMBOL_REF
6124 && CONSTANT_POOL_ADDRESS_P (sym
));
6126 if (*ref
== NULL_RTX
)
6129 gcc_assert (*ref
== sym
);
6134 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
6135 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
6139 find_constant_pool_ref (XEXP (x
, i
), ref
);
6141 else if (fmt
[i
] == 'E')
6143 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
6144 find_constant_pool_ref (XVECEXP (x
, i
, j
), ref
);
6149 /* Replace every reference to the annotated literal pool
6150 symbol REF in X by its base plus OFFSET. */
6153 replace_constant_pool_ref (rtx
*x
, rtx ref
, rtx offset
)
6158 gcc_assert (*x
!= ref
);
6160 if (GET_CODE (*x
) == UNSPEC
6161 && XINT (*x
, 1) == UNSPEC_LTREF
6162 && XVECEXP (*x
, 0, 0) == ref
)
6164 *x
= gen_rtx_PLUS (Pmode
, XVECEXP (*x
, 0, 1), offset
);
6168 if (GET_CODE (*x
) == PLUS
6169 && GET_CODE (XEXP (*x
, 1)) == CONST_INT
6170 && GET_CODE (XEXP (*x
, 0)) == UNSPEC
6171 && XINT (XEXP (*x
, 0), 1) == UNSPEC_LTREF
6172 && XVECEXP (XEXP (*x
, 0), 0, 0) == ref
)
6174 rtx addr
= gen_rtx_PLUS (Pmode
, XVECEXP (XEXP (*x
, 0), 0, 1), offset
);
6175 *x
= plus_constant (Pmode
, addr
, INTVAL (XEXP (*x
, 1)));
6179 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
6180 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
6184 replace_constant_pool_ref (&XEXP (*x
, i
), ref
, offset
);
6186 else if (fmt
[i
] == 'E')
6188 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
6189 replace_constant_pool_ref (&XVECEXP (*x
, i
, j
), ref
, offset
);
6194 /* Check whether X contains an UNSPEC_LTREL_BASE.
6195 Return its constant pool symbol if found, NULL_RTX otherwise. */
6198 find_ltrel_base (rtx x
)
6203 if (GET_CODE (x
) == UNSPEC
6204 && XINT (x
, 1) == UNSPEC_LTREL_BASE
)
6205 return XVECEXP (x
, 0, 0);
6207 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
6208 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
6212 rtx fnd
= find_ltrel_base (XEXP (x
, i
));
6216 else if (fmt
[i
] == 'E')
6218 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
6220 rtx fnd
= find_ltrel_base (XVECEXP (x
, i
, j
));
6230 /* Replace any occurrence of UNSPEC_LTREL_BASE in X with its base. */
6233 replace_ltrel_base (rtx
*x
)
6238 if (GET_CODE (*x
) == UNSPEC
6239 && XINT (*x
, 1) == UNSPEC_LTREL_BASE
)
6241 *x
= XVECEXP (*x
, 0, 1);
6245 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
6246 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
6250 replace_ltrel_base (&XEXP (*x
, i
));
6252 else if (fmt
[i
] == 'E')
6254 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
6255 replace_ltrel_base (&XVECEXP (*x
, i
, j
));
6261 /* We keep a list of constants which we have to add to internal
6262 constant tables in the middle of large functions. */
6264 #define NR_C_MODES 11
6265 machine_mode constant_modes
[NR_C_MODES
] =
6267 TFmode
, TImode
, TDmode
,
6268 DFmode
, DImode
, DDmode
,
6269 SFmode
, SImode
, SDmode
,
6276 struct constant
*next
;
6278 rtx_code_label
*label
;
6281 struct constant_pool
6283 struct constant_pool
*next
;
6284 rtx_insn
*first_insn
;
6285 rtx_insn
*pool_insn
;
6287 rtx_insn
*emit_pool_after
;
6289 struct constant
*constants
[NR_C_MODES
];
6290 struct constant
*execute
;
6291 rtx_code_label
*label
;
6295 /* Allocate new constant_pool structure. */
6297 static struct constant_pool
*
6298 s390_alloc_pool (void)
6300 struct constant_pool
*pool
;
6303 pool
= (struct constant_pool
*) xmalloc (sizeof *pool
);
6305 for (i
= 0; i
< NR_C_MODES
; i
++)
6306 pool
->constants
[i
] = NULL
;
6308 pool
->execute
= NULL
;
6309 pool
->label
= gen_label_rtx ();
6310 pool
->first_insn
= NULL
;
6311 pool
->pool_insn
= NULL
;
6312 pool
->insns
= BITMAP_ALLOC (NULL
);
6314 pool
->emit_pool_after
= NULL
;
6319 /* Create new constant pool covering instructions starting at INSN
6320 and chain it to the end of POOL_LIST. */
6322 static struct constant_pool
*
6323 s390_start_pool (struct constant_pool
**pool_list
, rtx_insn
*insn
)
6325 struct constant_pool
*pool
, **prev
;
6327 pool
= s390_alloc_pool ();
6328 pool
->first_insn
= insn
;
6330 for (prev
= pool_list
; *prev
; prev
= &(*prev
)->next
)
6337 /* End range of instructions covered by POOL at INSN and emit
6338 placeholder insn representing the pool. */
6341 s390_end_pool (struct constant_pool
*pool
, rtx_insn
*insn
)
6343 rtx pool_size
= GEN_INT (pool
->size
+ 8 /* alignment slop */);
6346 insn
= get_last_insn ();
6348 pool
->pool_insn
= emit_insn_after (gen_pool (pool_size
), insn
);
6349 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
6352 /* Add INSN to the list of insns covered by POOL. */
6355 s390_add_pool_insn (struct constant_pool
*pool
, rtx insn
)
6357 bitmap_set_bit (pool
->insns
, INSN_UID (insn
));
6360 /* Return pool out of POOL_LIST that covers INSN. */
6362 static struct constant_pool
*
6363 s390_find_pool (struct constant_pool
*pool_list
, rtx insn
)
6365 struct constant_pool
*pool
;
6367 for (pool
= pool_list
; pool
; pool
= pool
->next
)
6368 if (bitmap_bit_p (pool
->insns
, INSN_UID (insn
)))
6374 /* Add constant VAL of mode MODE to the constant pool POOL. */
6377 s390_add_constant (struct constant_pool
*pool
, rtx val
, machine_mode mode
)
6382 for (i
= 0; i
< NR_C_MODES
; i
++)
6383 if (constant_modes
[i
] == mode
)
6385 gcc_assert (i
!= NR_C_MODES
);
6387 for (c
= pool
->constants
[i
]; c
!= NULL
; c
= c
->next
)
6388 if (rtx_equal_p (val
, c
->value
))
6393 c
= (struct constant
*) xmalloc (sizeof *c
);
6395 c
->label
= gen_label_rtx ();
6396 c
->next
= pool
->constants
[i
];
6397 pool
->constants
[i
] = c
;
6398 pool
->size
+= GET_MODE_SIZE (mode
);
6402 /* Return an rtx that represents the offset of X from the start of
6406 s390_pool_offset (struct constant_pool
*pool
, rtx x
)
6410 label
= gen_rtx_LABEL_REF (GET_MODE (x
), pool
->label
);
6411 x
= gen_rtx_UNSPEC (GET_MODE (x
), gen_rtvec (2, x
, label
),
6412 UNSPEC_POOL_OFFSET
);
6413 return gen_rtx_CONST (GET_MODE (x
), x
);
6416 /* Find constant VAL of mode MODE in the constant pool POOL.
6417 Return an RTX describing the distance from the start of
6418 the pool to the location of the new constant. */
6421 s390_find_constant (struct constant_pool
*pool
, rtx val
,
6427 for (i
= 0; i
< NR_C_MODES
; i
++)
6428 if (constant_modes
[i
] == mode
)
6430 gcc_assert (i
!= NR_C_MODES
);
6432 for (c
= pool
->constants
[i
]; c
!= NULL
; c
= c
->next
)
6433 if (rtx_equal_p (val
, c
->value
))
6438 return s390_pool_offset (pool
, gen_rtx_LABEL_REF (Pmode
, c
->label
));
6441 /* Check whether INSN is an execute. Return the label_ref to its
6442 execute target template if so, NULL_RTX otherwise. */
6445 s390_execute_label (rtx insn
)
6447 if (NONJUMP_INSN_P (insn
)
6448 && GET_CODE (PATTERN (insn
)) == PARALLEL
6449 && GET_CODE (XVECEXP (PATTERN (insn
), 0, 0)) == UNSPEC
6450 && XINT (XVECEXP (PATTERN (insn
), 0, 0), 1) == UNSPEC_EXECUTE
)
6451 return XVECEXP (XVECEXP (PATTERN (insn
), 0, 0), 0, 2);
6456 /* Add execute target for INSN to the constant pool POOL. */
6459 s390_add_execute (struct constant_pool
*pool
, rtx insn
)
6463 for (c
= pool
->execute
; c
!= NULL
; c
= c
->next
)
6464 if (INSN_UID (insn
) == INSN_UID (c
->value
))
6469 c
= (struct constant
*) xmalloc (sizeof *c
);
6471 c
->label
= gen_label_rtx ();
6472 c
->next
= pool
->execute
;
6478 /* Find execute target for INSN in the constant pool POOL.
6479 Return an RTX describing the distance from the start of
6480 the pool to the location of the execute target. */
6483 s390_find_execute (struct constant_pool
*pool
, rtx insn
)
6487 for (c
= pool
->execute
; c
!= NULL
; c
= c
->next
)
6488 if (INSN_UID (insn
) == INSN_UID (c
->value
))
6493 return s390_pool_offset (pool
, gen_rtx_LABEL_REF (Pmode
, c
->label
));
6496 /* For an execute INSN, extract the execute target template. */
6499 s390_execute_target (rtx insn
)
6501 rtx pattern
= PATTERN (insn
);
6502 gcc_assert (s390_execute_label (insn
));
6504 if (XVECLEN (pattern
, 0) == 2)
6506 pattern
= copy_rtx (XVECEXP (pattern
, 0, 1));
6510 rtvec vec
= rtvec_alloc (XVECLEN (pattern
, 0) - 1);
6513 for (i
= 0; i
< XVECLEN (pattern
, 0) - 1; i
++)
6514 RTVEC_ELT (vec
, i
) = copy_rtx (XVECEXP (pattern
, 0, i
+ 1));
6516 pattern
= gen_rtx_PARALLEL (VOIDmode
, vec
);
6522 /* Indicate that INSN cannot be duplicated. This is the case for
6523 execute insns that carry a unique label. */
6526 s390_cannot_copy_insn_p (rtx_insn
*insn
)
6528 rtx label
= s390_execute_label (insn
);
6529 return label
&& label
!= const0_rtx
;
6532 /* Dump out the constants in POOL. If REMOTE_LABEL is true,
6533 do not emit the pool base label. */
6536 s390_dump_pool (struct constant_pool
*pool
, bool remote_label
)
6539 rtx_insn
*insn
= pool
->pool_insn
;
6542 /* Switch to rodata section. */
6543 if (TARGET_CPU_ZARCH
)
6545 insn
= emit_insn_after (gen_pool_section_start (), insn
);
6546 INSN_ADDRESSES_NEW (insn
, -1);
6549 /* Ensure minimum pool alignment. */
6550 if (TARGET_CPU_ZARCH
)
6551 insn
= emit_insn_after (gen_pool_align (GEN_INT (8)), insn
);
6553 insn
= emit_insn_after (gen_pool_align (GEN_INT (4)), insn
);
6554 INSN_ADDRESSES_NEW (insn
, -1);
6556 /* Emit pool base label. */
6559 insn
= emit_label_after (pool
->label
, insn
);
6560 INSN_ADDRESSES_NEW (insn
, -1);
6563 /* Dump constants in descending alignment requirement order,
6564 ensuring proper alignment for every constant. */
6565 for (i
= 0; i
< NR_C_MODES
; i
++)
6566 for (c
= pool
->constants
[i
]; c
; c
= c
->next
)
6568 /* Convert UNSPEC_LTREL_OFFSET unspecs to pool-relative references. */
6569 rtx value
= copy_rtx (c
->value
);
6570 if (GET_CODE (value
) == CONST
6571 && GET_CODE (XEXP (value
, 0)) == UNSPEC
6572 && XINT (XEXP (value
, 0), 1) == UNSPEC_LTREL_OFFSET
6573 && XVECLEN (XEXP (value
, 0), 0) == 1)
6574 value
= s390_pool_offset (pool
, XVECEXP (XEXP (value
, 0), 0, 0));
6576 insn
= emit_label_after (c
->label
, insn
);
6577 INSN_ADDRESSES_NEW (insn
, -1);
6579 value
= gen_rtx_UNSPEC_VOLATILE (constant_modes
[i
],
6580 gen_rtvec (1, value
),
6581 UNSPECV_POOL_ENTRY
);
6582 insn
= emit_insn_after (value
, insn
);
6583 INSN_ADDRESSES_NEW (insn
, -1);
6586 /* Ensure minimum alignment for instructions. */
6587 insn
= emit_insn_after (gen_pool_align (GEN_INT (2)), insn
);
6588 INSN_ADDRESSES_NEW (insn
, -1);
6590 /* Output in-pool execute template insns. */
6591 for (c
= pool
->execute
; c
; c
= c
->next
)
6593 insn
= emit_label_after (c
->label
, insn
);
6594 INSN_ADDRESSES_NEW (insn
, -1);
6596 insn
= emit_insn_after (s390_execute_target (c
->value
), insn
);
6597 INSN_ADDRESSES_NEW (insn
, -1);
6600 /* Switch back to previous section. */
6601 if (TARGET_CPU_ZARCH
)
6603 insn
= emit_insn_after (gen_pool_section_end (), insn
);
6604 INSN_ADDRESSES_NEW (insn
, -1);
6607 insn
= emit_barrier_after (insn
);
6608 INSN_ADDRESSES_NEW (insn
, -1);
6610 /* Remove placeholder insn. */
6611 remove_insn (pool
->pool_insn
);
6614 /* Free all memory used by POOL. */
6617 s390_free_pool (struct constant_pool
*pool
)
6619 struct constant
*c
, *next
;
6622 for (i
= 0; i
< NR_C_MODES
; i
++)
6623 for (c
= pool
->constants
[i
]; c
; c
= next
)
6629 for (c
= pool
->execute
; c
; c
= next
)
6635 BITMAP_FREE (pool
->insns
);
6640 /* Collect main literal pool. Return NULL on overflow. */
6642 static struct constant_pool
*
6643 s390_mainpool_start (void)
6645 struct constant_pool
*pool
;
6648 pool
= s390_alloc_pool ();
6650 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6652 if (NONJUMP_INSN_P (insn
)
6653 && GET_CODE (PATTERN (insn
)) == SET
6654 && GET_CODE (SET_SRC (PATTERN (insn
))) == UNSPEC_VOLATILE
6655 && XINT (SET_SRC (PATTERN (insn
)), 1) == UNSPECV_MAIN_POOL
)
6657 /* There might be two main_pool instructions if base_reg
6658 is call-clobbered; one for shrink-wrapped code and one
6659 for the rest. We want to keep the first. */
6660 if (pool
->pool_insn
)
6662 insn
= PREV_INSN (insn
);
6663 delete_insn (NEXT_INSN (insn
));
6666 pool
->pool_insn
= insn
;
6669 if (!TARGET_CPU_ZARCH
&& s390_execute_label (insn
))
6671 s390_add_execute (pool
, insn
);
6673 else if (NONJUMP_INSN_P (insn
) || CALL_P (insn
))
6675 rtx pool_ref
= NULL_RTX
;
6676 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
6679 rtx constant
= get_pool_constant (pool_ref
);
6680 machine_mode mode
= get_pool_mode (pool_ref
);
6681 s390_add_constant (pool
, constant
, mode
);
6685 /* If hot/cold partitioning is enabled we have to make sure that
6686 the literal pool is emitted in the same section where the
6687 initialization of the literal pool base pointer takes place.
6688 emit_pool_after is only used in the non-overflow case on non
6689 Z cpus where we can emit the literal pool at the end of the
6690 function body within the text section. */
6692 && NOTE_KIND (insn
) == NOTE_INSN_SWITCH_TEXT_SECTIONS
6693 && !pool
->emit_pool_after
)
6694 pool
->emit_pool_after
= PREV_INSN (insn
);
6697 gcc_assert (pool
->pool_insn
|| pool
->size
== 0);
6699 if (pool
->size
>= 4096)
6701 /* We're going to chunkify the pool, so remove the main
6702 pool placeholder insn. */
6703 remove_insn (pool
->pool_insn
);
6705 s390_free_pool (pool
);
6709 /* If the functions ends with the section where the literal pool
6710 should be emitted set the marker to its end. */
6711 if (pool
&& !pool
->emit_pool_after
)
6712 pool
->emit_pool_after
= get_last_insn ();
6717 /* POOL holds the main literal pool as collected by s390_mainpool_start.
6718 Modify the current function to output the pool constants as well as
6719 the pool register setup instruction. */
6722 s390_mainpool_finish (struct constant_pool
*pool
)
6724 rtx base_reg
= cfun
->machine
->base_reg
;
6726 /* If the pool is empty, we're done. */
6727 if (pool
->size
== 0)
6729 /* We don't actually need a base register after all. */
6730 cfun
->machine
->base_reg
= NULL_RTX
;
6732 if (pool
->pool_insn
)
6733 remove_insn (pool
->pool_insn
);
6734 s390_free_pool (pool
);
6738 /* We need correct insn addresses. */
6739 shorten_branches (get_insns ());
6741 /* On zSeries, we use a LARL to load the pool register. The pool is
6742 located in the .rodata section, so we emit it after the function. */
6743 if (TARGET_CPU_ZARCH
)
6745 rtx set
= gen_main_base_64 (base_reg
, pool
->label
);
6746 rtx_insn
*insn
= emit_insn_after (set
, pool
->pool_insn
);
6747 INSN_ADDRESSES_NEW (insn
, -1);
6748 remove_insn (pool
->pool_insn
);
6750 insn
= get_last_insn ();
6751 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
6752 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
6754 s390_dump_pool (pool
, 0);
6757 /* On S/390, if the total size of the function's code plus literal pool
6758 does not exceed 4096 bytes, we use BASR to set up a function base
6759 pointer, and emit the literal pool at the end of the function. */
6760 else if (INSN_ADDRESSES (INSN_UID (pool
->emit_pool_after
))
6761 + pool
->size
+ 8 /* alignment slop */ < 4096)
6763 rtx set
= gen_main_base_31_small (base_reg
, pool
->label
);
6764 rtx_insn
*insn
= emit_insn_after (set
, pool
->pool_insn
);
6765 INSN_ADDRESSES_NEW (insn
, -1);
6766 remove_insn (pool
->pool_insn
);
6768 insn
= emit_label_after (pool
->label
, insn
);
6769 INSN_ADDRESSES_NEW (insn
, -1);
6771 /* emit_pool_after will be set by s390_mainpool_start to the
6772 last insn of the section where the literal pool should be
6774 insn
= pool
->emit_pool_after
;
6776 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
6777 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
6779 s390_dump_pool (pool
, 1);
6782 /* Otherwise, we emit an inline literal pool and use BASR to branch
6783 over it, setting up the pool register at the same time. */
6786 rtx_code_label
*pool_end
= gen_label_rtx ();
6788 rtx pat
= gen_main_base_31_large (base_reg
, pool
->label
, pool_end
);
6789 rtx_insn
*insn
= emit_jump_insn_after (pat
, pool
->pool_insn
);
6790 JUMP_LABEL (insn
) = pool_end
;
6791 INSN_ADDRESSES_NEW (insn
, -1);
6792 remove_insn (pool
->pool_insn
);
6794 insn
= emit_label_after (pool
->label
, insn
);
6795 INSN_ADDRESSES_NEW (insn
, -1);
6797 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
6798 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
6800 insn
= emit_label_after (pool_end
, pool
->pool_insn
);
6801 INSN_ADDRESSES_NEW (insn
, -1);
6803 s390_dump_pool (pool
, 1);
6807 /* Replace all literal pool references. */
6809 for (rtx_insn
*insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6812 replace_ltrel_base (&PATTERN (insn
));
6814 if (NONJUMP_INSN_P (insn
) || CALL_P (insn
))
6816 rtx addr
, pool_ref
= NULL_RTX
;
6817 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
6820 if (s390_execute_label (insn
))
6821 addr
= s390_find_execute (pool
, insn
);
6823 addr
= s390_find_constant (pool
, get_pool_constant (pool_ref
),
6824 get_pool_mode (pool_ref
));
6826 replace_constant_pool_ref (&PATTERN (insn
), pool_ref
, addr
);
6827 INSN_CODE (insn
) = -1;
6833 /* Free the pool. */
6834 s390_free_pool (pool
);
6837 /* POOL holds the main literal pool as collected by s390_mainpool_start.
6838 We have decided we cannot use this pool, so revert all changes
6839 to the current function that were done by s390_mainpool_start. */
6841 s390_mainpool_cancel (struct constant_pool
*pool
)
6843 /* We didn't actually change the instruction stream, so simply
6844 free the pool memory. */
6845 s390_free_pool (pool
);
6849 /* Chunkify the literal pool. */
6851 #define S390_POOL_CHUNK_MIN 0xc00
6852 #define S390_POOL_CHUNK_MAX 0xe00
6854 static struct constant_pool
*
6855 s390_chunkify_start (void)
6857 struct constant_pool
*curr_pool
= NULL
, *pool_list
= NULL
;
6860 rtx pending_ltrel
= NULL_RTX
;
6863 rtx (*gen_reload_base
) (rtx
, rtx
) =
6864 TARGET_CPU_ZARCH
? gen_reload_base_64
: gen_reload_base_31
;
6867 /* We need correct insn addresses. */
6869 shorten_branches (get_insns ());
6871 /* Scan all insns and move literals to pool chunks. */
6873 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6875 bool section_switch_p
= false;
6877 /* Check for pending LTREL_BASE. */
6880 rtx ltrel_base
= find_ltrel_base (PATTERN (insn
));
6883 gcc_assert (ltrel_base
== pending_ltrel
);
6884 pending_ltrel
= NULL_RTX
;
6888 if (!TARGET_CPU_ZARCH
&& s390_execute_label (insn
))
6891 curr_pool
= s390_start_pool (&pool_list
, insn
);
6893 s390_add_execute (curr_pool
, insn
);
6894 s390_add_pool_insn (curr_pool
, insn
);
6896 else if (NONJUMP_INSN_P (insn
) || CALL_P (insn
))
6898 rtx pool_ref
= NULL_RTX
;
6899 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
6902 rtx constant
= get_pool_constant (pool_ref
);
6903 machine_mode mode
= get_pool_mode (pool_ref
);
6906 curr_pool
= s390_start_pool (&pool_list
, insn
);
6908 s390_add_constant (curr_pool
, constant
, mode
);
6909 s390_add_pool_insn (curr_pool
, insn
);
6911 /* Don't split the pool chunk between a LTREL_OFFSET load
6912 and the corresponding LTREL_BASE. */
6913 if (GET_CODE (constant
) == CONST
6914 && GET_CODE (XEXP (constant
, 0)) == UNSPEC
6915 && XINT (XEXP (constant
, 0), 1) == UNSPEC_LTREL_OFFSET
)
6917 gcc_assert (!pending_ltrel
);
6918 pending_ltrel
= pool_ref
;
6923 if (JUMP_P (insn
) || JUMP_TABLE_DATA_P (insn
) || LABEL_P (insn
))
6926 s390_add_pool_insn (curr_pool
, insn
);
6927 /* An LTREL_BASE must follow within the same basic block. */
6928 gcc_assert (!pending_ltrel
);
6932 switch (NOTE_KIND (insn
))
6934 case NOTE_INSN_SWITCH_TEXT_SECTIONS
:
6935 section_switch_p
= true;
6937 case NOTE_INSN_VAR_LOCATION
:
6938 case NOTE_INSN_CALL_ARG_LOCATION
:
6945 || INSN_ADDRESSES_SIZE () <= (size_t) INSN_UID (insn
)
6946 || INSN_ADDRESSES (INSN_UID (insn
)) == -1)
6949 if (TARGET_CPU_ZARCH
)
6951 if (curr_pool
->size
< S390_POOL_CHUNK_MAX
)
6954 s390_end_pool (curr_pool
, NULL
);
6959 int chunk_size
= INSN_ADDRESSES (INSN_UID (insn
))
6960 - INSN_ADDRESSES (INSN_UID (curr_pool
->first_insn
))
6963 /* We will later have to insert base register reload insns.
6964 Those will have an effect on code size, which we need to
6965 consider here. This calculation makes rather pessimistic
6966 worst-case assumptions. */
6970 if (chunk_size
< S390_POOL_CHUNK_MIN
6971 && curr_pool
->size
< S390_POOL_CHUNK_MIN
6972 && !section_switch_p
)
6975 /* Pool chunks can only be inserted after BARRIERs ... */
6976 if (BARRIER_P (insn
))
6978 s390_end_pool (curr_pool
, insn
);
6983 /* ... so if we don't find one in time, create one. */
6984 else if (chunk_size
> S390_POOL_CHUNK_MAX
6985 || curr_pool
->size
> S390_POOL_CHUNK_MAX
6986 || section_switch_p
)
6988 rtx_insn
*label
, *jump
, *barrier
, *next
, *prev
;
6990 if (!section_switch_p
)
6992 /* We can insert the barrier only after a 'real' insn. */
6993 if (! NONJUMP_INSN_P (insn
) && ! CALL_P (insn
))
6995 if (get_attr_length (insn
) == 0)
6997 /* Don't separate LTREL_BASE from the corresponding
6998 LTREL_OFFSET load. */
7005 next
= NEXT_INSN (insn
);
7009 && (NOTE_KIND (next
) == NOTE_INSN_VAR_LOCATION
7010 || NOTE_KIND (next
) == NOTE_INSN_CALL_ARG_LOCATION
));
7014 gcc_assert (!pending_ltrel
);
7016 /* The old pool has to end before the section switch
7017 note in order to make it part of the current
7019 insn
= PREV_INSN (insn
);
7022 label
= gen_label_rtx ();
7024 if (prev
&& NOTE_P (prev
))
7025 prev
= prev_nonnote_insn (prev
);
7027 jump
= emit_jump_insn_after_setloc (gen_jump (label
), insn
,
7028 INSN_LOCATION (prev
));
7030 jump
= emit_jump_insn_after_noloc (gen_jump (label
), insn
);
7031 barrier
= emit_barrier_after (jump
);
7032 insn
= emit_label_after (label
, barrier
);
7033 JUMP_LABEL (jump
) = label
;
7034 LABEL_NUSES (label
) = 1;
7036 INSN_ADDRESSES_NEW (jump
, -1);
7037 INSN_ADDRESSES_NEW (barrier
, -1);
7038 INSN_ADDRESSES_NEW (insn
, -1);
7040 s390_end_pool (curr_pool
, barrier
);
7048 s390_end_pool (curr_pool
, NULL
);
7049 gcc_assert (!pending_ltrel
);
7051 /* Find all labels that are branched into
7052 from an insn belonging to a different chunk. */
7054 far_labels
= BITMAP_ALLOC (NULL
);
7056 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
7058 rtx_jump_table_data
*table
;
7060 /* Labels marked with LABEL_PRESERVE_P can be target
7061 of non-local jumps, so we have to mark them.
7062 The same holds for named labels.
7064 Don't do that, however, if it is the label before
7068 && (LABEL_PRESERVE_P (insn
) || LABEL_NAME (insn
)))
7070 rtx_insn
*vec_insn
= NEXT_INSN (insn
);
7071 if (! vec_insn
|| ! JUMP_TABLE_DATA_P (vec_insn
))
7072 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (insn
));
7074 /* Check potential targets in a table jump (casesi_jump). */
7075 else if (tablejump_p (insn
, NULL
, &table
))
7077 rtx vec_pat
= PATTERN (table
);
7078 int i
, diff_p
= GET_CODE (vec_pat
) == ADDR_DIFF_VEC
;
7080 for (i
= 0; i
< XVECLEN (vec_pat
, diff_p
); i
++)
7082 rtx label
= XEXP (XVECEXP (vec_pat
, diff_p
, i
), 0);
7084 if (s390_find_pool (pool_list
, label
)
7085 != s390_find_pool (pool_list
, insn
))
7086 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (label
));
7089 /* If we have a direct jump (conditional or unconditional),
7090 check all potential targets. */
7091 else if (JUMP_P (insn
))
7093 rtx pat
= PATTERN (insn
);
7095 if (GET_CODE (pat
) == PARALLEL
)
7096 pat
= XVECEXP (pat
, 0, 0);
7098 if (GET_CODE (pat
) == SET
)
7100 rtx label
= JUMP_LABEL (insn
);
7101 if (label
&& !ANY_RETURN_P (label
))
7103 if (s390_find_pool (pool_list
, label
)
7104 != s390_find_pool (pool_list
, insn
))
7105 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (label
));
7111 /* Insert base register reload insns before every pool. */
7113 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
7115 rtx new_insn
= gen_reload_base (cfun
->machine
->base_reg
,
7117 rtx_insn
*insn
= curr_pool
->first_insn
;
7118 INSN_ADDRESSES_NEW (emit_insn_before (new_insn
, insn
), -1);
7121 /* Insert base register reload insns at every far label. */
7123 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
7125 && bitmap_bit_p (far_labels
, CODE_LABEL_NUMBER (insn
)))
7127 struct constant_pool
*pool
= s390_find_pool (pool_list
, insn
);
7130 rtx new_insn
= gen_reload_base (cfun
->machine
->base_reg
,
7132 INSN_ADDRESSES_NEW (emit_insn_after (new_insn
, insn
), -1);
7137 BITMAP_FREE (far_labels
);
7140 /* Recompute insn addresses. */
7142 init_insn_lengths ();
7143 shorten_branches (get_insns ());
7148 /* POOL_LIST is a chunk list as prepared by s390_chunkify_start.
7149 After we have decided to use this list, finish implementing
7150 all changes to the current function as required. */
7153 s390_chunkify_finish (struct constant_pool
*pool_list
)
7155 struct constant_pool
*curr_pool
= NULL
;
7159 /* Replace all literal pool references. */
7161 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
7164 replace_ltrel_base (&PATTERN (insn
));
7166 curr_pool
= s390_find_pool (pool_list
, insn
);
7170 if (NONJUMP_INSN_P (insn
) || CALL_P (insn
))
7172 rtx addr
, pool_ref
= NULL_RTX
;
7173 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
7176 if (s390_execute_label (insn
))
7177 addr
= s390_find_execute (curr_pool
, insn
);
7179 addr
= s390_find_constant (curr_pool
,
7180 get_pool_constant (pool_ref
),
7181 get_pool_mode (pool_ref
));
7183 replace_constant_pool_ref (&PATTERN (insn
), pool_ref
, addr
);
7184 INSN_CODE (insn
) = -1;
7189 /* Dump out all literal pools. */
7191 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
7192 s390_dump_pool (curr_pool
, 0);
7194 /* Free pool list. */
7198 struct constant_pool
*next
= pool_list
->next
;
7199 s390_free_pool (pool_list
);
7204 /* POOL_LIST is a chunk list as prepared by s390_chunkify_start.
7205 We have decided we cannot use this list, so revert all changes
7206 to the current function that were done by s390_chunkify_start. */
7209 s390_chunkify_cancel (struct constant_pool
*pool_list
)
7211 struct constant_pool
*curr_pool
= NULL
;
7214 /* Remove all pool placeholder insns. */
7216 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
7218 /* Did we insert an extra barrier? Remove it. */
7219 rtx_insn
*barrier
= PREV_INSN (curr_pool
->pool_insn
);
7220 rtx_insn
*jump
= barrier
? PREV_INSN (barrier
) : NULL
;
7221 rtx_insn
*label
= NEXT_INSN (curr_pool
->pool_insn
);
7223 if (jump
&& JUMP_P (jump
)
7224 && barrier
&& BARRIER_P (barrier
)
7225 && label
&& LABEL_P (label
)
7226 && GET_CODE (PATTERN (jump
)) == SET
7227 && SET_DEST (PATTERN (jump
)) == pc_rtx
7228 && GET_CODE (SET_SRC (PATTERN (jump
))) == LABEL_REF
7229 && XEXP (SET_SRC (PATTERN (jump
)), 0) == label
)
7232 remove_insn (barrier
);
7233 remove_insn (label
);
7236 remove_insn (curr_pool
->pool_insn
);
7239 /* Remove all base register reload insns. */
7241 for (insn
= get_insns (); insn
; )
7243 rtx_insn
*next_insn
= NEXT_INSN (insn
);
7245 if (NONJUMP_INSN_P (insn
)
7246 && GET_CODE (PATTERN (insn
)) == SET
7247 && GET_CODE (SET_SRC (PATTERN (insn
))) == UNSPEC
7248 && XINT (SET_SRC (PATTERN (insn
)), 1) == UNSPEC_RELOAD_BASE
)
7254 /* Free pool list. */
7258 struct constant_pool
*next
= pool_list
->next
;
7259 s390_free_pool (pool_list
);
7264 /* Output the constant pool entry EXP in mode MODE with alignment ALIGN. */
7267 s390_output_pool_entry (rtx exp
, machine_mode mode
, unsigned int align
)
7271 switch (GET_MODE_CLASS (mode
))
7274 case MODE_DECIMAL_FLOAT
:
7275 gcc_assert (GET_CODE (exp
) == CONST_DOUBLE
);
7277 REAL_VALUE_FROM_CONST_DOUBLE (r
, exp
);
7278 assemble_real (r
, mode
, align
);
7282 assemble_integer (exp
, GET_MODE_SIZE (mode
), align
, 1);
7283 mark_symbol_refs_as_used (exp
);
7292 /* Return an RTL expression representing the value of the return address
7293 for the frame COUNT steps up from the current frame. FRAME is the
7294 frame pointer of that frame. */
7297 s390_return_addr_rtx (int count
, rtx frame ATTRIBUTE_UNUSED
)
7302 /* Without backchain, we fail for all but the current frame. */
7304 if (!TARGET_BACKCHAIN
&& count
> 0)
7307 /* For the current frame, we need to make sure the initial
7308 value of RETURN_REGNUM is actually saved. */
7312 /* On non-z architectures branch splitting could overwrite r14. */
7313 if (TARGET_CPU_ZARCH
)
7314 return get_hard_reg_initial_val (Pmode
, RETURN_REGNUM
);
7317 cfun_frame_layout
.save_return_addr_p
= true;
7318 return gen_rtx_MEM (Pmode
, return_address_pointer_rtx
);
7322 if (TARGET_PACKED_STACK
)
7323 offset
= -2 * UNITS_PER_LONG
;
7325 offset
= RETURN_REGNUM
* UNITS_PER_LONG
;
7327 addr
= plus_constant (Pmode
, frame
, offset
);
7328 addr
= memory_address (Pmode
, addr
);
7329 return gen_rtx_MEM (Pmode
, addr
);
7332 /* Return an RTL expression representing the back chain stored in
7333 the current stack frame. */
7336 s390_back_chain_rtx (void)
7340 gcc_assert (TARGET_BACKCHAIN
);
7342 if (TARGET_PACKED_STACK
)
7343 chain
= plus_constant (Pmode
, stack_pointer_rtx
,
7344 STACK_POINTER_OFFSET
- UNITS_PER_LONG
);
7346 chain
= stack_pointer_rtx
;
7348 chain
= gen_rtx_MEM (Pmode
, chain
);
7352 /* Find first call clobbered register unused in a function.
7353 This could be used as base register in a leaf function
7354 or for holding the return address before epilogue. */
7357 find_unused_clobbered_reg (void)
7360 for (i
= 0; i
< 6; i
++)
7361 if (!df_regs_ever_live_p (i
))
7367 /* Helper function for s390_regs_ever_clobbered. Sets the fields in DATA for all
7368 clobbered hard regs in SETREG. */
7371 s390_reg_clobbered_rtx (rtx setreg
, const_rtx set_insn ATTRIBUTE_UNUSED
, void *data
)
7373 char *regs_ever_clobbered
= (char *)data
;
7374 unsigned int i
, regno
;
7375 machine_mode mode
= GET_MODE (setreg
);
7377 if (GET_CODE (setreg
) == SUBREG
)
7379 rtx inner
= SUBREG_REG (setreg
);
7380 if (!GENERAL_REG_P (inner
) && !FP_REG_P (inner
))
7382 regno
= subreg_regno (setreg
);
7384 else if (GENERAL_REG_P (setreg
) || FP_REG_P (setreg
))
7385 regno
= REGNO (setreg
);
7390 i
< regno
+ HARD_REGNO_NREGS (regno
, mode
);
7392 regs_ever_clobbered
[i
] = 1;
7395 /* Walks through all basic blocks of the current function looking
7396 for clobbered hard regs using s390_reg_clobbered_rtx. The fields
7397 of the passed integer array REGS_EVER_CLOBBERED are set to one for
7398 each of those regs. */
7401 s390_regs_ever_clobbered (char regs_ever_clobbered
[])
7407 memset (regs_ever_clobbered
, 0, 32);
7409 /* For non-leaf functions we have to consider all call clobbered regs to be
7413 for (i
= 0; i
< 32; i
++)
7414 regs_ever_clobbered
[i
] = call_really_used_regs
[i
];
7417 /* Make the "magic" eh_return registers live if necessary. For regs_ever_live
7418 this work is done by liveness analysis (mark_regs_live_at_end).
7419 Special care is needed for functions containing landing pads. Landing pads
7420 may use the eh registers, but the code which sets these registers is not
7421 contained in that function. Hence s390_regs_ever_clobbered is not able to
7422 deal with this automatically. */
7423 if (crtl
->calls_eh_return
|| cfun
->machine
->has_landing_pad_p
)
7424 for (i
= 0; EH_RETURN_DATA_REGNO (i
) != INVALID_REGNUM
; i
++)
7425 if (crtl
->calls_eh_return
7426 || (cfun
->machine
->has_landing_pad_p
7427 && df_regs_ever_live_p (EH_RETURN_DATA_REGNO (i
))))
7428 regs_ever_clobbered
[EH_RETURN_DATA_REGNO (i
)] = 1;
7430 /* For nonlocal gotos all call-saved registers have to be saved.
7431 This flag is also set for the unwinding code in libgcc.
7432 See expand_builtin_unwind_init. For regs_ever_live this is done by
7434 if (crtl
->saves_all_registers
)
7435 for (i
= 0; i
< 32; i
++)
7436 if (!call_really_used_regs
[i
])
7437 regs_ever_clobbered
[i
] = 1;
7439 FOR_EACH_BB_FN (cur_bb
, cfun
)
7441 FOR_BB_INSNS (cur_bb
, cur_insn
)
7445 if (!INSN_P (cur_insn
))
7448 pat
= PATTERN (cur_insn
);
7450 /* Ignore GPR restore insns. */
7451 if (epilogue_completed
&& RTX_FRAME_RELATED_P (cur_insn
))
7453 if (GET_CODE (pat
) == SET
7454 && GENERAL_REG_P (SET_DEST (pat
)))
7457 if (GET_MODE (SET_SRC (pat
)) == DImode
7458 && FP_REG_P (SET_SRC (pat
)))
7462 if (GET_CODE (SET_SRC (pat
)) == MEM
)
7467 if (GET_CODE (pat
) == PARALLEL
7468 && load_multiple_operation (pat
, VOIDmode
))
7473 s390_reg_clobbered_rtx
,
7474 regs_ever_clobbered
);
7479 /* Determine the frame area which actually has to be accessed
7480 in the function epilogue. The values are stored at the
7481 given pointers AREA_BOTTOM (address of the lowest used stack
7482 address) and AREA_TOP (address of the first item which does
7483 not belong to the stack frame). */
7486 s390_frame_area (int *area_bottom
, int *area_top
)
7493 if (cfun_frame_layout
.first_restore_gpr
!= -1)
7495 b
= (cfun_frame_layout
.gprs_offset
7496 + cfun_frame_layout
.first_restore_gpr
* UNITS_PER_LONG
);
7497 t
= b
+ (cfun_frame_layout
.last_restore_gpr
7498 - cfun_frame_layout
.first_restore_gpr
+ 1) * UNITS_PER_LONG
;
7501 if (TARGET_64BIT
&& cfun_save_high_fprs_p
)
7503 b
= MIN (b
, cfun_frame_layout
.f8_offset
);
7504 t
= MAX (t
, (cfun_frame_layout
.f8_offset
7505 + cfun_frame_layout
.high_fprs
* 8));
7510 if (cfun_fpr_save_p (FPR4_REGNUM
))
7512 b
= MIN (b
, cfun_frame_layout
.f4_offset
);
7513 t
= MAX (t
, cfun_frame_layout
.f4_offset
+ 8);
7515 if (cfun_fpr_save_p (FPR6_REGNUM
))
7517 b
= MIN (b
, cfun_frame_layout
.f4_offset
+ 8);
7518 t
= MAX (t
, cfun_frame_layout
.f4_offset
+ 16);
7524 /* Update gpr_save_slots in the frame layout trying to make use of
7525 FPRs as GPR save slots.
7526 This is a helper routine of s390_register_info. */
7529 s390_register_info_gprtofpr ()
7531 int save_reg_slot
= FPR0_REGNUM
;
7534 if (!TARGET_Z10
|| !TARGET_HARD_FLOAT
|| !crtl
->is_leaf
)
7537 for (i
= 15; i
>= 6; i
--)
7539 if (cfun_gpr_save_slot (i
) == 0)
7542 /* Advance to the next FP register which can be used as a
7544 while ((!call_really_used_regs
[save_reg_slot
]
7545 || df_regs_ever_live_p (save_reg_slot
)
7546 || cfun_fpr_save_p (save_reg_slot
))
7547 && FP_REGNO_P (save_reg_slot
))
7549 if (!FP_REGNO_P (save_reg_slot
))
7551 /* We only want to use ldgr/lgdr if we can get rid of
7552 stm/lm entirely. So undo the gpr slot allocation in
7553 case we ran out of FPR save slots. */
7554 for (j
= 6; j
<= 15; j
++)
7555 if (FP_REGNO_P (cfun_gpr_save_slot (j
)))
7556 cfun_gpr_save_slot (j
) = -1;
7559 cfun_gpr_save_slot (i
) = save_reg_slot
++;
7563 /* Set the bits in fpr_bitmap for FPRs which need to be saved due to
7565 This is a helper routine for s390_register_info. */
7568 s390_register_info_stdarg_fpr ()
7574 /* Save the FP argument regs for stdarg. f0, f2 for 31 bit and
7575 f0-f4 for 64 bit. */
7577 || !TARGET_HARD_FLOAT
7578 || !cfun
->va_list_fpr_size
7579 || crtl
->args
.info
.fprs
>= FP_ARG_NUM_REG
)
7582 min_fpr
= crtl
->args
.info
.fprs
;
7583 max_fpr
= min_fpr
+ cfun
->va_list_fpr_size
;
7584 if (max_fpr
> FP_ARG_NUM_REG
)
7585 max_fpr
= FP_ARG_NUM_REG
;
7587 for (i
= min_fpr
; i
< max_fpr
; i
++)
7588 cfun_set_fpr_save (i
+ FPR0_REGNUM
);
7591 /* Reserve the GPR save slots for GPRs which need to be saved due to
7593 This is a helper routine for s390_register_info. */
7596 s390_register_info_stdarg_gpr ()
7603 || !cfun
->va_list_gpr_size
7604 || crtl
->args
.info
.gprs
>= GP_ARG_NUM_REG
)
7607 min_gpr
= crtl
->args
.info
.gprs
;
7608 max_gpr
= min_gpr
+ cfun
->va_list_gpr_size
;
7609 if (max_gpr
> GP_ARG_NUM_REG
)
7610 max_gpr
= GP_ARG_NUM_REG
;
7612 for (i
= min_gpr
; i
< max_gpr
; i
++)
7613 cfun_gpr_save_slot (2 + i
) = -1;
7616 /* The GPR and FPR save slots in cfun->machine->frame_layout are set
7617 for registers which need to be saved in function prologue.
7618 This function can be used until the insns emitted for save/restore
7619 of the regs are visible in the RTL stream. */
7622 s390_register_info ()
7625 char clobbered_regs
[32];
7627 gcc_assert (!epilogue_completed
);
7629 if (reload_completed
)
7630 /* After reload we rely on our own routine to determine which
7631 registers need saving. */
7632 s390_regs_ever_clobbered (clobbered_regs
);
7634 /* During reload we use regs_ever_live as a base since reload
7635 does changes in there which we otherwise would not be aware
7637 for (i
= 0; i
< 32; i
++)
7638 clobbered_regs
[i
] = df_regs_ever_live_p (i
);
7640 for (i
= 0; i
< 32; i
++)
7641 clobbered_regs
[i
] = clobbered_regs
[i
] && !global_regs
[i
];
7643 /* Mark the call-saved FPRs which need to be saved.
7644 This needs to be done before checking the special GPRs since the
7645 stack pointer usage depends on whether high FPRs have to be saved
7647 cfun_frame_layout
.fpr_bitmap
= 0;
7648 cfun_frame_layout
.high_fprs
= 0;
7649 for (i
= FPR0_REGNUM
; i
<= FPR15_REGNUM
; i
++)
7650 if (clobbered_regs
[i
] && !call_really_used_regs
[i
])
7652 cfun_set_fpr_save (i
);
7653 if (i
>= FPR8_REGNUM
)
7654 cfun_frame_layout
.high_fprs
++;
7658 clobbered_regs
[PIC_OFFSET_TABLE_REGNUM
]
7659 |= !!df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM
);
7661 clobbered_regs
[BASE_REGNUM
]
7662 |= (cfun
->machine
->base_reg
7663 && REGNO (cfun
->machine
->base_reg
) == BASE_REGNUM
);
7665 clobbered_regs
[HARD_FRAME_POINTER_REGNUM
]
7666 |= !!frame_pointer_needed
;
7668 /* On pre z900 machines this might take until machine dependent
7670 save_return_addr_p will only be set on non-zarch machines so
7671 there is no risk that r14 goes into an FPR instead of a stack
7673 clobbered_regs
[RETURN_REGNUM
]
7675 || TARGET_TPF_PROFILING
7676 || cfun
->machine
->split_branches_pending_p
7677 || cfun_frame_layout
.save_return_addr_p
7678 || crtl
->calls_eh_return
);
7680 clobbered_regs
[STACK_POINTER_REGNUM
]
7682 || TARGET_TPF_PROFILING
7683 || cfun_save_high_fprs_p
7684 || get_frame_size () > 0
7685 || (reload_completed
&& cfun_frame_layout
.frame_size
> 0)
7686 || cfun
->calls_alloca
);
7688 memset (cfun_frame_layout
.gpr_save_slots
, 0, 16);
7690 for (i
= 6; i
< 16; i
++)
7691 if (clobbered_regs
[i
])
7692 cfun_gpr_save_slot (i
) = -1;
7694 s390_register_info_stdarg_fpr ();
7695 s390_register_info_gprtofpr ();
7697 /* First find the range of GPRs to be restored. Vararg regs don't
7698 need to be restored so we do it before assigning slots to the
7700 for (i
= 0; i
< 16 && cfun_gpr_save_slot (i
) != -1; i
++);
7701 for (j
= 15; j
> i
&& cfun_gpr_save_slot (j
) != -1; j
--);
7702 cfun_frame_layout
.first_restore_gpr
= (i
== 16) ? -1 : i
;
7703 cfun_frame_layout
.last_restore_gpr
= (i
== 16) ? -1 : j
;
7705 /* stdarg functions might need to save GPRs 2 to 6. This might
7706 override the GPR->FPR save decision made above for r6 since
7707 vararg regs must go to the stack. */
7708 s390_register_info_stdarg_gpr ();
7710 /* Now the range of GPRs which need saving. */
7711 for (i
= 0; i
< 16 && cfun_gpr_save_slot (i
) != -1; i
++);
7712 for (j
= 15; j
> i
&& cfun_gpr_save_slot (j
) != -1; j
--);
7713 cfun_frame_layout
.first_save_gpr
= (i
== 16) ? -1 : i
;
7714 cfun_frame_layout
.last_save_gpr
= (i
== 16) ? -1 : j
;
7717 /* This function is called by s390_optimize_prologue in order to get
7718 rid of unnecessary GPR save/restore instructions. The register info
7719 for the GPRs is re-computed and the ranges are re-calculated. */
7722 s390_optimize_register_info ()
7724 char clobbered_regs
[32];
7727 gcc_assert (epilogue_completed
);
7728 gcc_assert (!cfun
->machine
->split_branches_pending_p
);
7730 s390_regs_ever_clobbered (clobbered_regs
);
7732 for (i
= 0; i
< 32; i
++)
7733 clobbered_regs
[i
] = clobbered_regs
[i
] && !global_regs
[i
];
7735 /* There is still special treatment needed for cases invisible to
7736 s390_regs_ever_clobbered. */
7737 clobbered_regs
[RETURN_REGNUM
]
7738 |= (TARGET_TPF_PROFILING
7739 /* When expanding builtin_return_addr in ESA mode we do not
7740 know whether r14 will later be needed as scratch reg when
7741 doing branch splitting. So the builtin always accesses the
7742 r14 save slot and we need to stick to the save/restore
7743 decision for r14 even if it turns out that it didn't get
7745 || cfun_frame_layout
.save_return_addr_p
7746 || crtl
->calls_eh_return
);
7748 memset (cfun_frame_layout
.gpr_save_slots
, 0, 6);
7750 for (i
= 6; i
< 16; i
++)
7751 if (!clobbered_regs
[i
])
7752 cfun_gpr_save_slot (i
) = 0;
7754 for (i
= 0; i
< 16 && cfun_gpr_save_slot (i
) != -1; i
++);
7755 for (j
= 15; j
> i
&& cfun_gpr_save_slot (j
) != -1; j
--);
7756 cfun_frame_layout
.first_restore_gpr
= (i
== 16) ? -1 : i
;
7757 cfun_frame_layout
.last_restore_gpr
= (i
== 16) ? -1 : j
;
7759 s390_register_info_stdarg_gpr ();
7761 for (i
= 0; i
< 16 && cfun_gpr_save_slot (i
) != -1; i
++);
7762 for (j
= 15; j
> i
&& cfun_gpr_save_slot (j
) != -1; j
--);
7763 cfun_frame_layout
.first_save_gpr
= (i
== 16) ? -1 : i
;
7764 cfun_frame_layout
.last_save_gpr
= (i
== 16) ? -1 : j
;
7767 /* Fill cfun->machine with info about frame of current function. */
7770 s390_frame_info (void)
7772 HOST_WIDE_INT lowest_offset
;
7774 cfun_frame_layout
.first_save_gpr_slot
= cfun_frame_layout
.first_save_gpr
;
7775 cfun_frame_layout
.last_save_gpr_slot
= cfun_frame_layout
.last_save_gpr
;
7777 /* The va_arg builtin uses a constant distance of 16 *
7778 UNITS_PER_LONG (r0-r15) to reach the FPRs from the reg_save_area
7779 pointer. So even if we are going to save the stack pointer in an
7780 FPR we need the stack space in order to keep the offsets
7782 if (cfun
->stdarg
&& cfun_save_arg_fprs_p
)
7784 cfun_frame_layout
.last_save_gpr_slot
= STACK_POINTER_REGNUM
;
7786 if (cfun_frame_layout
.first_save_gpr_slot
== -1)
7787 cfun_frame_layout
.first_save_gpr_slot
= STACK_POINTER_REGNUM
;
7790 cfun_frame_layout
.frame_size
= get_frame_size ();
7791 if (!TARGET_64BIT
&& cfun_frame_layout
.frame_size
> 0x7fff0000)
7792 fatal_error ("total size of local variables exceeds architecture limit");
7794 if (!TARGET_PACKED_STACK
)
7796 /* Fixed stack layout. */
7797 cfun_frame_layout
.backchain_offset
= 0;
7798 cfun_frame_layout
.f0_offset
= 16 * UNITS_PER_LONG
;
7799 cfun_frame_layout
.f4_offset
= cfun_frame_layout
.f0_offset
+ 2 * 8;
7800 cfun_frame_layout
.f8_offset
= -cfun_frame_layout
.high_fprs
* 8;
7801 cfun_frame_layout
.gprs_offset
= (cfun_frame_layout
.first_save_gpr_slot
7804 else if (TARGET_BACKCHAIN
)
7806 /* Kernel stack layout - packed stack, backchain, no float */
7807 gcc_assert (TARGET_SOFT_FLOAT
);
7808 cfun_frame_layout
.backchain_offset
= (STACK_POINTER_OFFSET
7811 /* The distance between the backchain and the return address
7812 save slot must not change. So we always need a slot for the
7813 stack pointer which resides in between. */
7814 cfun_frame_layout
.last_save_gpr_slot
= STACK_POINTER_REGNUM
;
7816 cfun_frame_layout
.gprs_offset
7817 = cfun_frame_layout
.backchain_offset
- cfun_gprs_save_area_size
;
7819 /* FPRs will not be saved. Nevertheless pick sane values to
7820 keep area calculations valid. */
7821 cfun_frame_layout
.f0_offset
=
7822 cfun_frame_layout
.f4_offset
=
7823 cfun_frame_layout
.f8_offset
= cfun_frame_layout
.gprs_offset
;
7829 /* Packed stack layout without backchain. */
7831 /* With stdarg FPRs need their dedicated slots. */
7832 num_fprs
= (TARGET_64BIT
&& cfun
->stdarg
? 2
7833 : (cfun_fpr_save_p (FPR4_REGNUM
) +
7834 cfun_fpr_save_p (FPR6_REGNUM
)));
7835 cfun_frame_layout
.f4_offset
= STACK_POINTER_OFFSET
- 8 * num_fprs
;
7837 num_fprs
= (cfun
->stdarg
? 2
7838 : (cfun_fpr_save_p (FPR0_REGNUM
)
7839 + cfun_fpr_save_p (FPR2_REGNUM
)));
7840 cfun_frame_layout
.f0_offset
= cfun_frame_layout
.f4_offset
- 8 * num_fprs
;
7842 cfun_frame_layout
.gprs_offset
7843 = cfun_frame_layout
.f0_offset
- cfun_gprs_save_area_size
;
7845 cfun_frame_layout
.f8_offset
= (cfun_frame_layout
.gprs_offset
7846 - cfun_frame_layout
.high_fprs
* 8);
7849 if (cfun_save_high_fprs_p
)
7850 cfun_frame_layout
.frame_size
+= cfun_frame_layout
.high_fprs
* 8;
7853 cfun_frame_layout
.frame_size
+= crtl
->outgoing_args_size
;
7855 /* In the following cases we have to allocate a STACK_POINTER_OFFSET
7856 sized area at the bottom of the stack. This is required also for
7857 leaf functions. When GCC generates a local stack reference it
7858 will always add STACK_POINTER_OFFSET to all these references. */
7860 && !TARGET_TPF_PROFILING
7861 && cfun_frame_layout
.frame_size
== 0
7862 && !cfun
->calls_alloca
)
7865 /* Calculate the number of bytes we have used in our own register
7866 save area. With the packed stack layout we can re-use the
7867 remaining bytes for normal stack elements. */
7869 if (TARGET_PACKED_STACK
)
7870 lowest_offset
= MIN (MIN (cfun_frame_layout
.f0_offset
,
7871 cfun_frame_layout
.f4_offset
),
7872 cfun_frame_layout
.gprs_offset
);
7876 if (TARGET_BACKCHAIN
)
7877 lowest_offset
= MIN (lowest_offset
, cfun_frame_layout
.backchain_offset
);
7879 cfun_frame_layout
.frame_size
+= STACK_POINTER_OFFSET
- lowest_offset
;
7881 /* If under 31 bit an odd number of gprs has to be saved we have to
7882 adjust the frame size to sustain 8 byte alignment of stack
7884 cfun_frame_layout
.frame_size
= ((cfun_frame_layout
.frame_size
+
7885 STACK_BOUNDARY
/ BITS_PER_UNIT
- 1)
7886 & ~(STACK_BOUNDARY
/ BITS_PER_UNIT
- 1));
7889 /* Generate frame layout. Fills in register and frame data for the current
7890 function in cfun->machine. This routine can be called multiple times;
7891 it will re-do the complete frame layout every time. */
7894 s390_init_frame_layout (void)
7896 HOST_WIDE_INT frame_size
;
7899 gcc_assert (!reload_completed
);
7901 /* On S/390 machines, we may need to perform branch splitting, which
7902 will require both base and return address register. We have no
7903 choice but to assume we're going to need them until right at the
7904 end of the machine dependent reorg phase. */
7905 if (!TARGET_CPU_ZARCH
)
7906 cfun
->machine
->split_branches_pending_p
= true;
7910 frame_size
= cfun_frame_layout
.frame_size
;
7912 /* Try to predict whether we'll need the base register. */
7913 base_used
= cfun
->machine
->split_branches_pending_p
7914 || crtl
->uses_const_pool
7915 || (!DISP_IN_RANGE (frame_size
)
7916 && !CONST_OK_FOR_K (frame_size
));
7918 /* Decide which register to use as literal pool base. In small
7919 leaf functions, try to use an unused call-clobbered register
7920 as base register to avoid save/restore overhead. */
7922 cfun
->machine
->base_reg
= NULL_RTX
;
7923 else if (crtl
->is_leaf
&& !df_regs_ever_live_p (5))
7924 cfun
->machine
->base_reg
= gen_rtx_REG (Pmode
, 5);
7926 cfun
->machine
->base_reg
= gen_rtx_REG (Pmode
, BASE_REGNUM
);
7928 s390_register_info ();
7931 while (frame_size
!= cfun_frame_layout
.frame_size
);
7934 /* Remove the FPR clobbers from a tbegin insn if it can be proven that
7935 the TX is nonescaping. A transaction is considered escaping if
7936 there is at least one path from tbegin returning CC0 to the
7937 function exit block without an tend.
7939 The check so far has some limitations:
7940 - only single tbegin/tend BBs are supported
7941 - the first cond jump after tbegin must separate the CC0 path from ~CC0
7942 - when CC is copied to a GPR and the CC0 check is done with the GPR
7943 this is not supported
7947 s390_optimize_nonescaping_tx (void)
7949 const unsigned int CC0
= 1 << 3;
7950 basic_block tbegin_bb
= NULL
;
7951 basic_block tend_bb
= NULL
;
7956 rtx_insn
*tbegin_insn
= NULL
;
7958 if (!cfun
->machine
->tbegin_p
)
7961 for (bb_index
= 0; bb_index
< n_basic_blocks_for_fn (cfun
); bb_index
++)
7963 bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
7968 FOR_BB_INSNS (bb
, insn
)
7970 rtx ite
, cc
, pat
, target
;
7971 unsigned HOST_WIDE_INT mask
;
7973 if (!INSN_P (insn
) || INSN_CODE (insn
) <= 0)
7976 pat
= PATTERN (insn
);
7978 if (GET_CODE (pat
) == PARALLEL
)
7979 pat
= XVECEXP (pat
, 0, 0);
7981 if (GET_CODE (pat
) != SET
7982 || GET_CODE (SET_SRC (pat
)) != UNSPEC_VOLATILE
)
7985 if (XINT (SET_SRC (pat
), 1) == UNSPECV_TBEGIN
)
7991 /* Just return if the tbegin doesn't have clobbers. */
7992 if (GET_CODE (PATTERN (insn
)) != PARALLEL
)
7995 if (tbegin_bb
!= NULL
)
7998 /* Find the next conditional jump. */
7999 for (tmp
= NEXT_INSN (insn
);
8001 tmp
= NEXT_INSN (tmp
))
8003 if (reg_set_p (gen_rtx_REG (CCmode
, CC_REGNUM
), tmp
))
8008 ite
= SET_SRC (PATTERN (tmp
));
8009 if (GET_CODE (ite
) != IF_THEN_ELSE
)
8012 cc
= XEXP (XEXP (ite
, 0), 0);
8013 if (!REG_P (cc
) || !CC_REGNO_P (REGNO (cc
))
8014 || GET_MODE (cc
) != CCRAWmode
8015 || GET_CODE (XEXP (XEXP (ite
, 0), 1)) != CONST_INT
)
8018 if (bb
->succs
->length () != 2)
8021 mask
= INTVAL (XEXP (XEXP (ite
, 0), 1));
8022 if (GET_CODE (XEXP (ite
, 0)) == NE
)
8026 target
= XEXP (ite
, 1);
8027 else if (mask
== (CC0
^ 0xf))
8028 target
= XEXP (ite
, 2);
8036 ei
= ei_start (bb
->succs
);
8037 e1
= ei_safe_edge (ei
);
8039 e2
= ei_safe_edge (ei
);
8041 if (e2
->flags
& EDGE_FALLTHRU
)
8044 e1
= ei_safe_edge (ei
);
8047 if (!(e1
->flags
& EDGE_FALLTHRU
))
8050 tbegin_bb
= (target
== pc_rtx
) ? e1
->dest
: e2
->dest
;
8052 if (tmp
== BB_END (bb
))
8057 if (XINT (SET_SRC (pat
), 1) == UNSPECV_TEND
)
8059 if (tend_bb
!= NULL
)
8066 /* Either we successfully remove the FPR clobbers here or we are not
8067 able to do anything for this TX. Both cases don't qualify for
8069 cfun
->machine
->tbegin_p
= false;
8071 if (tbegin_bb
== NULL
|| tend_bb
== NULL
)
8074 calculate_dominance_info (CDI_POST_DOMINATORS
);
8075 result
= dominated_by_p (CDI_POST_DOMINATORS
, tbegin_bb
, tend_bb
);
8076 free_dominance_info (CDI_POST_DOMINATORS
);
8081 PATTERN (tbegin_insn
) = gen_rtx_PARALLEL (VOIDmode
,
8083 XVECEXP (PATTERN (tbegin_insn
), 0, 0),
8084 XVECEXP (PATTERN (tbegin_insn
), 0, 1)));
8085 INSN_CODE (tbegin_insn
) = -1;
8086 df_insn_rescan (tbegin_insn
);
8091 /* Return true if it is legal to put a value with MODE into REGNO. */
8094 s390_hard_regno_mode_ok (unsigned int regno
, machine_mode mode
)
8096 switch (REGNO_REG_CLASS (regno
))
8099 if (REGNO_PAIR_OK (regno
, mode
))
8101 if (mode
== SImode
|| mode
== DImode
)
8104 if (FLOAT_MODE_P (mode
) && GET_MODE_CLASS (mode
) != MODE_VECTOR_FLOAT
)
8109 if (FRAME_REGNO_P (regno
) && mode
== Pmode
)
8114 if (REGNO_PAIR_OK (regno
, mode
))
8117 || (mode
!= TFmode
&& mode
!= TCmode
&& mode
!= TDmode
))
8122 if (GET_MODE_CLASS (mode
) == MODE_CC
)
8126 if (REGNO_PAIR_OK (regno
, mode
))
8128 if (mode
== SImode
|| mode
== Pmode
)
8139 /* Return nonzero if register OLD_REG can be renamed to register NEW_REG. */
8142 s390_hard_regno_rename_ok (unsigned int old_reg
, unsigned int new_reg
)
8144 /* Once we've decided upon a register to use as base register, it must
8145 no longer be used for any other purpose. */
8146 if (cfun
->machine
->base_reg
)
8147 if (REGNO (cfun
->machine
->base_reg
) == old_reg
8148 || REGNO (cfun
->machine
->base_reg
) == new_reg
)
8151 /* Prevent regrename from using call-saved regs which haven't
8152 actually been saved. This is necessary since regrename assumes
8153 the backend save/restore decisions are based on
8154 df_regs_ever_live. Since we have our own routine we have to tell
8155 regrename manually about it. */
8156 if (GENERAL_REGNO_P (new_reg
)
8157 && !call_really_used_regs
[new_reg
]
8158 && cfun_gpr_save_slot (new_reg
) == 0)
8164 /* Return nonzero if register REGNO can be used as a scratch register
8168 s390_hard_regno_scratch_ok (unsigned int regno
)
8170 /* See s390_hard_regno_rename_ok. */
8171 if (GENERAL_REGNO_P (regno
)
8172 && !call_really_used_regs
[regno
]
8173 && cfun_gpr_save_slot (regno
) == 0)
8179 /* Maximum number of registers to represent a value of mode MODE
8180 in a register of class RCLASS. */
8183 s390_class_max_nregs (enum reg_class rclass
, machine_mode mode
)
8188 if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
)
8189 return 2 * ((GET_MODE_SIZE (mode
) / 2 + 8 - 1) / 8);
8191 return (GET_MODE_SIZE (mode
) + 8 - 1) / 8;
8193 return (GET_MODE_SIZE (mode
) + 4 - 1) / 4;
8197 return (GET_MODE_SIZE (mode
) + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
8200 /* Return true if we use LRA instead of reload pass. */
8204 return s390_lra_flag
;
8207 /* Return true if register FROM can be eliminated via register TO. */
8210 s390_can_eliminate (const int from
, const int to
)
8212 /* On zSeries machines, we have not marked the base register as fixed.
8213 Instead, we have an elimination rule BASE_REGNUM -> BASE_REGNUM.
8214 If a function requires the base register, we say here that this
8215 elimination cannot be performed. This will cause reload to free
8216 up the base register (as if it were fixed). On the other hand,
8217 if the current function does *not* require the base register, we
8218 say here the elimination succeeds, which in turn allows reload
8219 to allocate the base register for any other purpose. */
8220 if (from
== BASE_REGNUM
&& to
== BASE_REGNUM
)
8222 if (TARGET_CPU_ZARCH
)
8224 s390_init_frame_layout ();
8225 return cfun
->machine
->base_reg
== NULL_RTX
;
8231 /* Everything else must point into the stack frame. */
8232 gcc_assert (to
== STACK_POINTER_REGNUM
8233 || to
== HARD_FRAME_POINTER_REGNUM
);
8235 gcc_assert (from
== FRAME_POINTER_REGNUM
8236 || from
== ARG_POINTER_REGNUM
8237 || from
== RETURN_ADDRESS_POINTER_REGNUM
);
8239 /* Make sure we actually saved the return address. */
8240 if (from
== RETURN_ADDRESS_POINTER_REGNUM
)
8241 if (!crtl
->calls_eh_return
8243 && !cfun_frame_layout
.save_return_addr_p
)
8249 /* Return offset between register FROM and TO initially after prolog. */
8252 s390_initial_elimination_offset (int from
, int to
)
8254 HOST_WIDE_INT offset
;
8256 /* ??? Why are we called for non-eliminable pairs? */
8257 if (!s390_can_eliminate (from
, to
))
8262 case FRAME_POINTER_REGNUM
:
8263 offset
= (get_frame_size()
8264 + STACK_POINTER_OFFSET
8265 + crtl
->outgoing_args_size
);
8268 case ARG_POINTER_REGNUM
:
8269 s390_init_frame_layout ();
8270 offset
= cfun_frame_layout
.frame_size
+ STACK_POINTER_OFFSET
;
8273 case RETURN_ADDRESS_POINTER_REGNUM
:
8274 s390_init_frame_layout ();
8276 if (cfun_frame_layout
.first_save_gpr_slot
== -1)
8278 /* If it turns out that for stdarg nothing went into the reg
8279 save area we also do not need the return address
8281 if (cfun
->stdarg
&& !cfun_save_arg_fprs_p
)
8287 /* In order to make the following work it is not necessary for
8288 r14 to have a save slot. It is sufficient if one other GPR
8289 got one. Since the GPRs are always stored without gaps we
8290 are able to calculate where the r14 save slot would
8292 offset
= (cfun_frame_layout
.frame_size
+ cfun_frame_layout
.gprs_offset
+
8293 (RETURN_REGNUM
- cfun_frame_layout
.first_save_gpr_slot
) *
8308 /* Emit insn to save fpr REGNUM at offset OFFSET relative
8309 to register BASE. Return generated insn. */
8312 save_fpr (rtx base
, int offset
, int regnum
)
8315 addr
= gen_rtx_MEM (DFmode
, plus_constant (Pmode
, base
, offset
));
8317 if (regnum
>= 16 && regnum
<= (16 + FP_ARG_NUM_REG
))
8318 set_mem_alias_set (addr
, get_varargs_alias_set ());
8320 set_mem_alias_set (addr
, get_frame_alias_set ());
8322 return emit_move_insn (addr
, gen_rtx_REG (DFmode
, regnum
));
8325 /* Emit insn to restore fpr REGNUM from offset OFFSET relative
8326 to register BASE. Return generated insn. */
8329 restore_fpr (rtx base
, int offset
, int regnum
)
8332 addr
= gen_rtx_MEM (DFmode
, plus_constant (Pmode
, base
, offset
));
8333 set_mem_alias_set (addr
, get_frame_alias_set ());
8335 return emit_move_insn (gen_rtx_REG (DFmode
, regnum
), addr
);
8338 /* Return true if REGNO is a global register, but not one
8339 of the special ones that need to be saved/restored in anyway. */
8342 global_not_special_regno_p (int regno
)
8344 return (global_regs
[regno
]
8345 /* These registers are special and need to be
8346 restored in any case. */
8347 && !(regno
== STACK_POINTER_REGNUM
8348 || regno
== RETURN_REGNUM
8349 || regno
== BASE_REGNUM
8350 || (flag_pic
&& regno
== (int)PIC_OFFSET_TABLE_REGNUM
)));
8353 /* Generate insn to save registers FIRST to LAST into
8354 the register save area located at offset OFFSET
8355 relative to register BASE. */
8358 save_gprs (rtx base
, int offset
, int first
, int last
)
8360 rtx addr
, insn
, note
;
8363 addr
= plus_constant (Pmode
, base
, offset
);
8364 addr
= gen_rtx_MEM (Pmode
, addr
);
8366 set_mem_alias_set (addr
, get_frame_alias_set ());
8368 /* Special-case single register. */
8372 insn
= gen_movdi (addr
, gen_rtx_REG (Pmode
, first
));
8374 insn
= gen_movsi (addr
, gen_rtx_REG (Pmode
, first
));
8376 if (!global_not_special_regno_p (first
))
8377 RTX_FRAME_RELATED_P (insn
) = 1;
8382 insn
= gen_store_multiple (addr
,
8383 gen_rtx_REG (Pmode
, first
),
8384 GEN_INT (last
- first
+ 1));
8386 if (first
<= 6 && cfun
->stdarg
)
8387 for (i
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
8389 rtx mem
= XEXP (XVECEXP (PATTERN (insn
), 0, i
), 0);
8392 set_mem_alias_set (mem
, get_varargs_alias_set ());
8395 /* We need to set the FRAME_RELATED flag on all SETs
8396 inside the store-multiple pattern.
8398 However, we must not emit DWARF records for registers 2..5
8399 if they are stored for use by variable arguments ...
8401 ??? Unfortunately, it is not enough to simply not the
8402 FRAME_RELATED flags for those SETs, because the first SET
8403 of the PARALLEL is always treated as if it had the flag
8404 set, even if it does not. Therefore we emit a new pattern
8405 without those registers as REG_FRAME_RELATED_EXPR note. */
8407 if (first
>= 6 && !global_not_special_regno_p (first
))
8409 rtx pat
= PATTERN (insn
);
8411 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
8412 if (GET_CODE (XVECEXP (pat
, 0, i
)) == SET
8413 && !global_not_special_regno_p (REGNO (SET_SRC (XVECEXP (pat
,
8415 RTX_FRAME_RELATED_P (XVECEXP (pat
, 0, i
)) = 1;
8417 RTX_FRAME_RELATED_P (insn
) = 1;
8423 for (start
= first
>= 6 ? first
: 6; start
<= last
; start
++)
8424 if (!global_not_special_regno_p (start
))
8430 addr
= plus_constant (Pmode
, base
,
8431 offset
+ (start
- first
) * UNITS_PER_LONG
);
8436 note
= gen_movdi (gen_rtx_MEM (Pmode
, addr
),
8437 gen_rtx_REG (Pmode
, start
));
8439 note
= gen_movsi (gen_rtx_MEM (Pmode
, addr
),
8440 gen_rtx_REG (Pmode
, start
));
8441 note
= PATTERN (note
);
8443 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
, note
);
8444 RTX_FRAME_RELATED_P (insn
) = 1;
8449 note
= gen_store_multiple (gen_rtx_MEM (Pmode
, addr
),
8450 gen_rtx_REG (Pmode
, start
),
8451 GEN_INT (last
- start
+ 1));
8452 note
= PATTERN (note
);
8454 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
, note
);
8456 for (i
= 0; i
< XVECLEN (note
, 0); i
++)
8457 if (GET_CODE (XVECEXP (note
, 0, i
)) == SET
8458 && !global_not_special_regno_p (REGNO (SET_SRC (XVECEXP (note
,
8460 RTX_FRAME_RELATED_P (XVECEXP (note
, 0, i
)) = 1;
8462 RTX_FRAME_RELATED_P (insn
) = 1;
8468 /* Generate insn to restore registers FIRST to LAST from
8469 the register save area located at offset OFFSET
8470 relative to register BASE. */
8473 restore_gprs (rtx base
, int offset
, int first
, int last
)
8477 addr
= plus_constant (Pmode
, base
, offset
);
8478 addr
= gen_rtx_MEM (Pmode
, addr
);
8479 set_mem_alias_set (addr
, get_frame_alias_set ());
8481 /* Special-case single register. */
8485 insn
= gen_movdi (gen_rtx_REG (Pmode
, first
), addr
);
8487 insn
= gen_movsi (gen_rtx_REG (Pmode
, first
), addr
);
8489 RTX_FRAME_RELATED_P (insn
) = 1;
8493 insn
= gen_load_multiple (gen_rtx_REG (Pmode
, first
),
8495 GEN_INT (last
- first
+ 1));
8496 RTX_FRAME_RELATED_P (insn
) = 1;
8500 /* Return insn sequence to load the GOT register. */
8502 static GTY(()) rtx got_symbol
;
8504 s390_load_got (void)
8508 /* We cannot use pic_offset_table_rtx here since we use this
8509 function also for non-pic if __tls_get_offset is called and in
8510 that case PIC_OFFSET_TABLE_REGNUM as well as pic_offset_table_rtx
8512 rtx got_rtx
= gen_rtx_REG (Pmode
, 12);
8516 got_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "_GLOBAL_OFFSET_TABLE_");
8517 SYMBOL_REF_FLAGS (got_symbol
) = SYMBOL_FLAG_LOCAL
;
8522 if (TARGET_CPU_ZARCH
)
8524 emit_move_insn (got_rtx
, got_symbol
);
8530 offset
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, got_symbol
),
8531 UNSPEC_LTREL_OFFSET
);
8532 offset
= gen_rtx_CONST (Pmode
, offset
);
8533 offset
= force_const_mem (Pmode
, offset
);
8535 emit_move_insn (got_rtx
, offset
);
8537 offset
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, XEXP (offset
, 0)),
8539 offset
= gen_rtx_PLUS (Pmode
, got_rtx
, offset
);
8541 emit_move_insn (got_rtx
, offset
);
8544 insns
= get_insns ();
8549 /* This ties together stack memory (MEM with an alias set of frame_alias_set)
8550 and the change to the stack pointer. */
8553 s390_emit_stack_tie (void)
8555 rtx mem
= gen_frame_mem (BLKmode
,
8556 gen_rtx_REG (Pmode
, STACK_POINTER_REGNUM
));
8558 emit_insn (gen_stack_tie (mem
));
8561 /* Copy GPRS into FPR save slots. */
8564 s390_save_gprs_to_fprs (void)
8568 if (!TARGET_Z10
|| !TARGET_HARD_FLOAT
|| !crtl
->is_leaf
)
8571 for (i
= 6; i
< 16; i
++)
8573 if (FP_REGNO_P (cfun_gpr_save_slot (i
)))
8576 emit_move_insn (gen_rtx_REG (DImode
, cfun_gpr_save_slot (i
)),
8577 gen_rtx_REG (DImode
, i
));
8578 RTX_FRAME_RELATED_P (insn
) = 1;
8583 /* Restore GPRs from FPR save slots. */
8586 s390_restore_gprs_from_fprs (void)
8590 if (!TARGET_Z10
|| !TARGET_HARD_FLOAT
|| !crtl
->is_leaf
)
8593 for (i
= 6; i
< 16; i
++)
8595 if (FP_REGNO_P (cfun_gpr_save_slot (i
)))
8598 emit_move_insn (gen_rtx_REG (DImode
, i
),
8599 gen_rtx_REG (DImode
, cfun_gpr_save_slot (i
)));
8600 df_set_regs_ever_live (i
, true);
8601 add_reg_note (insn
, REG_CFA_RESTORE
, gen_rtx_REG (DImode
, i
));
8602 if (i
== STACK_POINTER_REGNUM
)
8603 add_reg_note (insn
, REG_CFA_DEF_CFA
,
8604 plus_constant (Pmode
, stack_pointer_rtx
,
8605 STACK_POINTER_OFFSET
));
8606 RTX_FRAME_RELATED_P (insn
) = 1;
8612 /* A pass run immediately before shrink-wrapping and prologue and epilogue
8617 const pass_data pass_data_s390_early_mach
=
8619 RTL_PASS
, /* type */
8620 "early_mach", /* name */
8621 OPTGROUP_NONE
, /* optinfo_flags */
8622 TV_MACH_DEP
, /* tv_id */
8623 0, /* properties_required */
8624 0, /* properties_provided */
8625 0, /* properties_destroyed */
8626 0, /* todo_flags_start */
8627 ( TODO_df_verify
| TODO_df_finish
), /* todo_flags_finish */
8630 class pass_s390_early_mach
: public rtl_opt_pass
8633 pass_s390_early_mach (gcc::context
*ctxt
)
8634 : rtl_opt_pass (pass_data_s390_early_mach
, ctxt
)
8637 /* opt_pass methods: */
8638 virtual unsigned int execute (function
*);
8640 }; // class pass_s390_early_mach
8643 pass_s390_early_mach::execute (function
*fun
)
8647 /* Try to get rid of the FPR clobbers. */
8648 s390_optimize_nonescaping_tx ();
8650 /* Re-compute register info. */
8651 s390_register_info ();
8653 /* If we're using a base register, ensure that it is always valid for
8654 the first non-prologue instruction. */
8655 if (fun
->machine
->base_reg
)
8656 emit_insn_at_entry (gen_main_pool (fun
->machine
->base_reg
));
8658 /* Annotate all constant pool references to let the scheduler know
8659 they implicitly use the base register. */
8660 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
8663 annotate_constant_pool_refs (&PATTERN (insn
));
8664 df_insn_rescan (insn
);
8671 /* Expand the prologue into a bunch of separate insns. */
8674 s390_emit_prologue (void)
8682 /* Choose best register to use for temp use within prologue.
8683 See below for why TPF must use the register 1. */
8685 if (!has_hard_reg_initial_val (Pmode
, RETURN_REGNUM
)
8687 && !TARGET_TPF_PROFILING
)
8688 temp_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
8690 temp_reg
= gen_rtx_REG (Pmode
, 1);
8692 s390_save_gprs_to_fprs ();
8694 /* Save call saved gprs. */
8695 if (cfun_frame_layout
.first_save_gpr
!= -1)
8697 insn
= save_gprs (stack_pointer_rtx
,
8698 cfun_frame_layout
.gprs_offset
+
8699 UNITS_PER_LONG
* (cfun_frame_layout
.first_save_gpr
8700 - cfun_frame_layout
.first_save_gpr_slot
),
8701 cfun_frame_layout
.first_save_gpr
,
8702 cfun_frame_layout
.last_save_gpr
);
8706 /* Dummy insn to mark literal pool slot. */
8708 if (cfun
->machine
->base_reg
)
8709 emit_insn (gen_main_pool (cfun
->machine
->base_reg
));
8711 offset
= cfun_frame_layout
.f0_offset
;
8713 /* Save f0 and f2. */
8714 for (i
= FPR0_REGNUM
; i
<= FPR0_REGNUM
+ 1; i
++)
8716 if (cfun_fpr_save_p (i
))
8718 save_fpr (stack_pointer_rtx
, offset
, i
);
8721 else if (!TARGET_PACKED_STACK
|| cfun
->stdarg
)
8725 /* Save f4 and f6. */
8726 offset
= cfun_frame_layout
.f4_offset
;
8727 for (i
= FPR4_REGNUM
; i
<= FPR4_REGNUM
+ 1; i
++)
8729 if (cfun_fpr_save_p (i
))
8731 insn
= save_fpr (stack_pointer_rtx
, offset
, i
);
8734 /* If f4 and f6 are call clobbered they are saved due to
8735 stdargs and therefore are not frame related. */
8736 if (!call_really_used_regs
[i
])
8737 RTX_FRAME_RELATED_P (insn
) = 1;
8739 else if (!TARGET_PACKED_STACK
|| call_really_used_regs
[i
])
8743 if (TARGET_PACKED_STACK
8744 && cfun_save_high_fprs_p
8745 && cfun_frame_layout
.f8_offset
+ cfun_frame_layout
.high_fprs
* 8 > 0)
8747 offset
= (cfun_frame_layout
.f8_offset
8748 + (cfun_frame_layout
.high_fprs
- 1) * 8);
8750 for (i
= FPR15_REGNUM
; i
>= FPR8_REGNUM
&& offset
>= 0; i
--)
8751 if (cfun_fpr_save_p (i
))
8753 insn
= save_fpr (stack_pointer_rtx
, offset
, i
);
8755 RTX_FRAME_RELATED_P (insn
) = 1;
8758 if (offset
>= cfun_frame_layout
.f8_offset
)
8762 if (!TARGET_PACKED_STACK
)
8763 next_fpr
= cfun_save_high_fprs_p
? FPR15_REGNUM
: 0;
8765 if (flag_stack_usage_info
)
8766 current_function_static_stack_size
= cfun_frame_layout
.frame_size
;
8768 /* Decrement stack pointer. */
8770 if (cfun_frame_layout
.frame_size
> 0)
8772 rtx frame_off
= GEN_INT (-cfun_frame_layout
.frame_size
);
8775 if (s390_stack_size
)
8777 HOST_WIDE_INT stack_guard
;
8779 if (s390_stack_guard
)
8780 stack_guard
= s390_stack_guard
;
8783 /* If no value for stack guard is provided the smallest power of 2
8784 larger than the current frame size is chosen. */
8786 while (stack_guard
< cfun_frame_layout
.frame_size
)
8790 if (cfun_frame_layout
.frame_size
>= s390_stack_size
)
8792 warning (0, "frame size of function %qs is %wd"
8793 " bytes exceeding user provided stack limit of "
8795 "An unconditional trap is added.",
8796 current_function_name(), cfun_frame_layout
.frame_size
,
8798 emit_insn (gen_trap ());
8802 /* stack_guard has to be smaller than s390_stack_size.
8803 Otherwise we would emit an AND with zero which would
8804 not match the test under mask pattern. */
8805 if (stack_guard
>= s390_stack_size
)
8807 warning (0, "frame size of function %qs is %wd"
8808 " bytes which is more than half the stack size. "
8809 "The dynamic check would not be reliable. "
8810 "No check emitted for this function.",
8811 current_function_name(),
8812 cfun_frame_layout
.frame_size
);
8816 HOST_WIDE_INT stack_check_mask
= ((s390_stack_size
- 1)
8817 & ~(stack_guard
- 1));
8819 rtx t
= gen_rtx_AND (Pmode
, stack_pointer_rtx
,
8820 GEN_INT (stack_check_mask
));
8822 emit_insn (gen_ctrapdi4 (gen_rtx_EQ (VOIDmode
,
8824 t
, const0_rtx
, const0_rtx
));
8826 emit_insn (gen_ctrapsi4 (gen_rtx_EQ (VOIDmode
,
8828 t
, const0_rtx
, const0_rtx
));
8833 if (s390_warn_framesize
> 0
8834 && cfun_frame_layout
.frame_size
>= s390_warn_framesize
)
8835 warning (0, "frame size of %qs is %wd bytes",
8836 current_function_name (), cfun_frame_layout
.frame_size
);
8838 if (s390_warn_dynamicstack_p
&& cfun
->calls_alloca
)
8839 warning (0, "%qs uses dynamic stack allocation", current_function_name ());
8841 /* Save incoming stack pointer into temp reg. */
8842 if (TARGET_BACKCHAIN
|| next_fpr
)
8843 insn
= emit_insn (gen_move_insn (temp_reg
, stack_pointer_rtx
));
8845 /* Subtract frame size from stack pointer. */
8847 if (DISP_IN_RANGE (INTVAL (frame_off
)))
8849 insn
= gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
8850 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
8852 insn
= emit_insn (insn
);
8856 if (!CONST_OK_FOR_K (INTVAL (frame_off
)))
8857 frame_off
= force_const_mem (Pmode
, frame_off
);
8859 insn
= emit_insn (gen_add2_insn (stack_pointer_rtx
, frame_off
));
8860 annotate_constant_pool_refs (&PATTERN (insn
));
8863 RTX_FRAME_RELATED_P (insn
) = 1;
8864 real_frame_off
= GEN_INT (-cfun_frame_layout
.frame_size
);
8865 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
,
8866 gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
8867 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
8870 /* Set backchain. */
8872 if (TARGET_BACKCHAIN
)
8874 if (cfun_frame_layout
.backchain_offset
)
8875 addr
= gen_rtx_MEM (Pmode
,
8876 plus_constant (Pmode
, stack_pointer_rtx
,
8877 cfun_frame_layout
.backchain_offset
));
8879 addr
= gen_rtx_MEM (Pmode
, stack_pointer_rtx
);
8880 set_mem_alias_set (addr
, get_frame_alias_set ());
8881 insn
= emit_insn (gen_move_insn (addr
, temp_reg
));
8884 /* If we support non-call exceptions (e.g. for Java),
8885 we need to make sure the backchain pointer is set up
8886 before any possibly trapping memory access. */
8887 if (TARGET_BACKCHAIN
&& cfun
->can_throw_non_call_exceptions
)
8889 addr
= gen_rtx_MEM (BLKmode
, gen_rtx_SCRATCH (VOIDmode
));
8890 emit_clobber (addr
);
8894 /* Save fprs 8 - 15 (64 bit ABI). */
8896 if (cfun_save_high_fprs_p
&& next_fpr
)
8898 /* If the stack might be accessed through a different register
8899 we have to make sure that the stack pointer decrement is not
8900 moved below the use of the stack slots. */
8901 s390_emit_stack_tie ();
8903 insn
= emit_insn (gen_add2_insn (temp_reg
,
8904 GEN_INT (cfun_frame_layout
.f8_offset
)));
8908 for (i
= FPR8_REGNUM
; i
<= next_fpr
; i
++)
8909 if (cfun_fpr_save_p (i
))
8911 rtx addr
= plus_constant (Pmode
, stack_pointer_rtx
,
8912 cfun_frame_layout
.frame_size
8913 + cfun_frame_layout
.f8_offset
8916 insn
= save_fpr (temp_reg
, offset
, i
);
8918 RTX_FRAME_RELATED_P (insn
) = 1;
8919 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
,
8920 gen_rtx_SET (VOIDmode
,
8921 gen_rtx_MEM (DFmode
, addr
),
8922 gen_rtx_REG (DFmode
, i
)));
8926 /* Set frame pointer, if needed. */
8928 if (frame_pointer_needed
)
8930 insn
= emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
);
8931 RTX_FRAME_RELATED_P (insn
) = 1;
8934 /* Set up got pointer, if needed. */
8936 if (flag_pic
&& df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM
))
8938 rtx_insn
*insns
= s390_load_got ();
8940 for (rtx_insn
*insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
8941 annotate_constant_pool_refs (&PATTERN (insn
));
8946 if (TARGET_TPF_PROFILING
)
8948 /* Generate a BAS instruction to serve as a function
8949 entry intercept to facilitate the use of tracing
8950 algorithms located at the branch target. */
8951 emit_insn (gen_prologue_tpf ());
8953 /* Emit a blockage here so that all code
8954 lies between the profiling mechanisms. */
8955 emit_insn (gen_blockage ());
8959 /* Expand the epilogue into a bunch of separate insns. */
8962 s390_emit_epilogue (bool sibcall
)
8964 rtx frame_pointer
, return_reg
, cfa_restores
= NULL_RTX
;
8965 int area_bottom
, area_top
, offset
= 0;
8970 if (TARGET_TPF_PROFILING
)
8973 /* Generate a BAS instruction to serve as a function
8974 entry intercept to facilitate the use of tracing
8975 algorithms located at the branch target. */
8977 /* Emit a blockage here so that all code
8978 lies between the profiling mechanisms. */
8979 emit_insn (gen_blockage ());
8981 emit_insn (gen_epilogue_tpf ());
8984 /* Check whether to use frame or stack pointer for restore. */
8986 frame_pointer
= (frame_pointer_needed
8987 ? hard_frame_pointer_rtx
: stack_pointer_rtx
);
8989 s390_frame_area (&area_bottom
, &area_top
);
8991 /* Check whether we can access the register save area.
8992 If not, increment the frame pointer as required. */
8994 if (area_top
<= area_bottom
)
8996 /* Nothing to restore. */
8998 else if (DISP_IN_RANGE (cfun_frame_layout
.frame_size
+ area_bottom
)
8999 && DISP_IN_RANGE (cfun_frame_layout
.frame_size
+ area_top
- 1))
9001 /* Area is in range. */
9002 offset
= cfun_frame_layout
.frame_size
;
9006 rtx insn
, frame_off
, cfa
;
9008 offset
= area_bottom
< 0 ? -area_bottom
: 0;
9009 frame_off
= GEN_INT (cfun_frame_layout
.frame_size
- offset
);
9011 cfa
= gen_rtx_SET (VOIDmode
, frame_pointer
,
9012 gen_rtx_PLUS (Pmode
, frame_pointer
, frame_off
));
9013 if (DISP_IN_RANGE (INTVAL (frame_off
)))
9015 insn
= gen_rtx_SET (VOIDmode
, frame_pointer
,
9016 gen_rtx_PLUS (Pmode
, frame_pointer
, frame_off
));
9017 insn
= emit_insn (insn
);
9021 if (!CONST_OK_FOR_K (INTVAL (frame_off
)))
9022 frame_off
= force_const_mem (Pmode
, frame_off
);
9024 insn
= emit_insn (gen_add2_insn (frame_pointer
, frame_off
));
9025 annotate_constant_pool_refs (&PATTERN (insn
));
9027 add_reg_note (insn
, REG_CFA_ADJUST_CFA
, cfa
);
9028 RTX_FRAME_RELATED_P (insn
) = 1;
9031 /* Restore call saved fprs. */
9035 if (cfun_save_high_fprs_p
)
9037 next_offset
= cfun_frame_layout
.f8_offset
;
9038 for (i
= FPR8_REGNUM
; i
<= FPR15_REGNUM
; i
++)
9040 if (cfun_fpr_save_p (i
))
9042 restore_fpr (frame_pointer
,
9043 offset
+ next_offset
, i
);
9045 = alloc_reg_note (REG_CFA_RESTORE
,
9046 gen_rtx_REG (DFmode
, i
), cfa_restores
);
9055 next_offset
= cfun_frame_layout
.f4_offset
;
9057 for (i
= FPR4_REGNUM
; i
<= FPR4_REGNUM
+ 1; i
++)
9059 if (cfun_fpr_save_p (i
))
9061 restore_fpr (frame_pointer
,
9062 offset
+ next_offset
, i
);
9064 = alloc_reg_note (REG_CFA_RESTORE
,
9065 gen_rtx_REG (DFmode
, i
), cfa_restores
);
9068 else if (!TARGET_PACKED_STACK
)
9074 /* Return register. */
9076 return_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
9078 /* Restore call saved gprs. */
9080 if (cfun_frame_layout
.first_restore_gpr
!= -1)
9085 /* Check for global register and save them
9086 to stack location from where they get restored. */
9088 for (i
= cfun_frame_layout
.first_restore_gpr
;
9089 i
<= cfun_frame_layout
.last_restore_gpr
;
9092 if (global_not_special_regno_p (i
))
9094 addr
= plus_constant (Pmode
, frame_pointer
,
9095 offset
+ cfun_frame_layout
.gprs_offset
9096 + (i
- cfun_frame_layout
.first_save_gpr_slot
)
9098 addr
= gen_rtx_MEM (Pmode
, addr
);
9099 set_mem_alias_set (addr
, get_frame_alias_set ());
9100 emit_move_insn (addr
, gen_rtx_REG (Pmode
, i
));
9104 = alloc_reg_note (REG_CFA_RESTORE
,
9105 gen_rtx_REG (Pmode
, i
), cfa_restores
);
9110 /* Fetch return address from stack before load multiple,
9111 this will do good for scheduling.
9113 Only do this if we already decided that r14 needs to be
9114 saved to a stack slot. (And not just because r14 happens to
9115 be in between two GPRs which need saving.) Otherwise it
9116 would be difficult to take that decision back in
9117 s390_optimize_prologue. */
9118 if (cfun_gpr_save_slot (RETURN_REGNUM
) == -1)
9120 int return_regnum
= find_unused_clobbered_reg();
9123 return_reg
= gen_rtx_REG (Pmode
, return_regnum
);
9125 addr
= plus_constant (Pmode
, frame_pointer
,
9126 offset
+ cfun_frame_layout
.gprs_offset
9128 - cfun_frame_layout
.first_save_gpr_slot
)
9130 addr
= gen_rtx_MEM (Pmode
, addr
);
9131 set_mem_alias_set (addr
, get_frame_alias_set ());
9132 emit_move_insn (return_reg
, addr
);
9134 /* Once we did that optimization we have to make sure
9135 s390_optimize_prologue does not try to remove the
9136 store of r14 since we will not be able to find the
9137 load issued here. */
9138 cfun_frame_layout
.save_return_addr_p
= true;
9142 insn
= restore_gprs (frame_pointer
,
9143 offset
+ cfun_frame_layout
.gprs_offset
9144 + (cfun_frame_layout
.first_restore_gpr
9145 - cfun_frame_layout
.first_save_gpr_slot
)
9147 cfun_frame_layout
.first_restore_gpr
,
9148 cfun_frame_layout
.last_restore_gpr
);
9149 insn
= emit_insn (insn
);
9150 REG_NOTES (insn
) = cfa_restores
;
9151 add_reg_note (insn
, REG_CFA_DEF_CFA
,
9152 plus_constant (Pmode
, stack_pointer_rtx
,
9153 STACK_POINTER_OFFSET
));
9154 RTX_FRAME_RELATED_P (insn
) = 1;
9157 s390_restore_gprs_from_fprs ();
9162 /* Return to caller. */
9164 p
= rtvec_alloc (2);
9166 RTVEC_ELT (p
, 0) = ret_rtx
;
9167 RTVEC_ELT (p
, 1) = gen_rtx_USE (VOIDmode
, return_reg
);
9168 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
9172 /* Implement TARGET_SET_UP_BY_PROLOGUE. */
9175 s300_set_up_by_prologue (hard_reg_set_container
*regs
)
9177 if (cfun
->machine
->base_reg
9178 && !call_really_used_regs
[REGNO (cfun
->machine
->base_reg
)])
9179 SET_HARD_REG_BIT (regs
->set
, REGNO (cfun
->machine
->base_reg
));
9182 /* Return true if the function can use simple_return to return outside
9183 of a shrink-wrapped region. At present shrink-wrapping is supported
9187 s390_can_use_simple_return_insn (void)
9192 /* Return true if the epilogue is guaranteed to contain only a return
9193 instruction and if a direct return can therefore be used instead.
9194 One of the main advantages of using direct return instructions
9195 is that we can then use conditional returns. */
9198 s390_can_use_return_insn (void)
9202 if (!reload_completed
)
9208 if (TARGET_TPF_PROFILING
)
9211 for (i
= 0; i
< 16; i
++)
9212 if (cfun_gpr_save_slot (i
))
9215 /* For 31 bit this is not covered by the frame_size check below
9216 since f4, f6 are saved in the register save area without needing
9217 additional stack space. */
9219 && (cfun_fpr_save_p (FPR4_REGNUM
) || cfun_fpr_save_p (FPR6_REGNUM
)))
9222 if (cfun
->machine
->base_reg
9223 && !call_really_used_regs
[REGNO (cfun
->machine
->base_reg
)])
9226 return cfun_frame_layout
.frame_size
== 0;
9229 /* Return the size in bytes of a function argument of
9230 type TYPE and/or mode MODE. At least one of TYPE or
9231 MODE must be specified. */
9234 s390_function_arg_size (machine_mode mode
, const_tree type
)
9237 return int_size_in_bytes (type
);
9239 /* No type info available for some library calls ... */
9240 if (mode
!= BLKmode
)
9241 return GET_MODE_SIZE (mode
);
9243 /* If we have neither type nor mode, abort */
9247 /* Return true if a function argument of type TYPE and mode MODE
9248 is to be passed in a floating-point register, if available. */
9251 s390_function_arg_float (machine_mode mode
, const_tree type
)
9253 int size
= s390_function_arg_size (mode
, type
);
9257 /* Soft-float changes the ABI: no floating-point registers are used. */
9258 if (TARGET_SOFT_FLOAT
)
9261 /* No type info available for some library calls ... */
9263 return mode
== SFmode
|| mode
== DFmode
|| mode
== SDmode
|| mode
== DDmode
;
9265 /* The ABI says that record types with a single member are treated
9266 just like that member would be. */
9267 while (TREE_CODE (type
) == RECORD_TYPE
)
9269 tree field
, single
= NULL_TREE
;
9271 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
9273 if (TREE_CODE (field
) != FIELD_DECL
)
9276 if (single
== NULL_TREE
)
9277 single
= TREE_TYPE (field
);
9282 if (single
== NULL_TREE
)
9288 return TREE_CODE (type
) == REAL_TYPE
;
9291 /* Return true if a function argument of type TYPE and mode MODE
9292 is to be passed in an integer register, or a pair of integer
9293 registers, if available. */
9296 s390_function_arg_integer (machine_mode mode
, const_tree type
)
9298 int size
= s390_function_arg_size (mode
, type
);
9302 /* No type info available for some library calls ... */
9304 return GET_MODE_CLASS (mode
) == MODE_INT
9305 || (TARGET_SOFT_FLOAT
&& SCALAR_FLOAT_MODE_P (mode
));
9307 /* We accept small integral (and similar) types. */
9308 if (INTEGRAL_TYPE_P (type
)
9309 || POINTER_TYPE_P (type
)
9310 || TREE_CODE (type
) == NULLPTR_TYPE
9311 || TREE_CODE (type
) == OFFSET_TYPE
9312 || (TARGET_SOFT_FLOAT
&& TREE_CODE (type
) == REAL_TYPE
))
9315 /* We also accept structs of size 1, 2, 4, 8 that are not
9316 passed in floating-point registers. */
9317 if (AGGREGATE_TYPE_P (type
)
9318 && exact_log2 (size
) >= 0
9319 && !s390_function_arg_float (mode
, type
))
9325 /* Return 1 if a function argument of type TYPE and mode MODE
9326 is to be passed by reference. The ABI specifies that only
9327 structures of size 1, 2, 4, or 8 bytes are passed by value,
9328 all other structures (and complex numbers) are passed by
9332 s390_pass_by_reference (cumulative_args_t ca ATTRIBUTE_UNUSED
,
9333 machine_mode mode
, const_tree type
,
9334 bool named ATTRIBUTE_UNUSED
)
9336 int size
= s390_function_arg_size (mode
, type
);
9342 if (AGGREGATE_TYPE_P (type
) && exact_log2 (size
) < 0)
9345 if (TREE_CODE (type
) == COMPLEX_TYPE
9346 || TREE_CODE (type
) == VECTOR_TYPE
)
9353 /* Update the data in CUM to advance over an argument of mode MODE and
9354 data type TYPE. (TYPE is null for libcalls where that information
9355 may not be available.). The boolean NAMED specifies whether the
9356 argument is a named argument (as opposed to an unnamed argument
9357 matching an ellipsis). */
9360 s390_function_arg_advance (cumulative_args_t cum_v
, machine_mode mode
,
9361 const_tree type
, bool named ATTRIBUTE_UNUSED
)
9363 CUMULATIVE_ARGS
*cum
= get_cumulative_args (cum_v
);
9365 if (s390_function_arg_float (mode
, type
))
9369 else if (s390_function_arg_integer (mode
, type
))
9371 int size
= s390_function_arg_size (mode
, type
);
9372 cum
->gprs
+= ((size
+ UNITS_PER_LONG
- 1) / UNITS_PER_LONG
);
9378 /* Define where to put the arguments to a function.
9379 Value is zero to push the argument on the stack,
9380 or a hard register in which to store the argument.
9382 MODE is the argument's machine mode.
9383 TYPE is the data type of the argument (as a tree).
9384 This is null for libcalls where that information may
9386 CUM is a variable of type CUMULATIVE_ARGS which gives info about
9387 the preceding args and about the function being called.
9388 NAMED is nonzero if this argument is a named parameter
9389 (otherwise it is an extra parameter matching an ellipsis).
9391 On S/390, we use general purpose registers 2 through 6 to
9392 pass integer, pointer, and certain structure arguments, and
9393 floating point registers 0 and 2 (0, 2, 4, and 6 on 64-bit)
9394 to pass floating point arguments. All remaining arguments
9395 are pushed to the stack. */
9398 s390_function_arg (cumulative_args_t cum_v
, machine_mode mode
,
9399 const_tree type
, bool named ATTRIBUTE_UNUSED
)
9401 CUMULATIVE_ARGS
*cum
= get_cumulative_args (cum_v
);
9403 if (s390_function_arg_float (mode
, type
))
9405 if (cum
->fprs
+ 1 > FP_ARG_NUM_REG
)
9408 return gen_rtx_REG (mode
, cum
->fprs
+ 16);
9410 else if (s390_function_arg_integer (mode
, type
))
9412 int size
= s390_function_arg_size (mode
, type
);
9413 int n_gprs
= (size
+ UNITS_PER_LONG
- 1) / UNITS_PER_LONG
;
9415 if (cum
->gprs
+ n_gprs
> GP_ARG_NUM_REG
)
9417 else if (n_gprs
== 1 || UNITS_PER_WORD
== UNITS_PER_LONG
)
9418 return gen_rtx_REG (mode
, cum
->gprs
+ 2);
9419 else if (n_gprs
== 2)
9421 rtvec p
= rtvec_alloc (2);
9424 = gen_rtx_EXPR_LIST (SImode
, gen_rtx_REG (SImode
, cum
->gprs
+ 2),
9427 = gen_rtx_EXPR_LIST (SImode
, gen_rtx_REG (SImode
, cum
->gprs
+ 3),
9430 return gen_rtx_PARALLEL (mode
, p
);
9434 /* After the real arguments, expand_call calls us once again
9435 with a void_type_node type. Whatever we return here is
9436 passed as operand 2 to the call expanders.
9438 We don't need this feature ... */
9439 else if (type
== void_type_node
)
9445 /* Return true if return values of type TYPE should be returned
9446 in a memory buffer whose address is passed by the caller as
9447 hidden first argument. */
9450 s390_return_in_memory (const_tree type
, const_tree fundecl ATTRIBUTE_UNUSED
)
9452 /* We accept small integral (and similar) types. */
9453 if (INTEGRAL_TYPE_P (type
)
9454 || POINTER_TYPE_P (type
)
9455 || TREE_CODE (type
) == OFFSET_TYPE
9456 || TREE_CODE (type
) == REAL_TYPE
)
9457 return int_size_in_bytes (type
) > 8;
9459 /* Aggregates and similar constructs are always returned
9461 if (AGGREGATE_TYPE_P (type
)
9462 || TREE_CODE (type
) == COMPLEX_TYPE
9463 || TREE_CODE (type
) == VECTOR_TYPE
)
9466 /* ??? We get called on all sorts of random stuff from
9467 aggregate_value_p. We can't abort, but it's not clear
9468 what's safe to return. Pretend it's a struct I guess. */
9472 /* Function arguments and return values are promoted to word size. */
9475 s390_promote_function_mode (const_tree type
, machine_mode mode
,
9477 const_tree fntype ATTRIBUTE_UNUSED
,
9478 int for_return ATTRIBUTE_UNUSED
)
9480 if (INTEGRAL_MODE_P (mode
)
9481 && GET_MODE_SIZE (mode
) < UNITS_PER_LONG
)
9483 if (type
!= NULL_TREE
&& POINTER_TYPE_P (type
))
9484 *punsignedp
= POINTERS_EXTEND_UNSIGNED
;
9491 /* Define where to return a (scalar) value of type RET_TYPE.
9492 If RET_TYPE is null, define where to return a (scalar)
9493 value of mode MODE from a libcall. */
9496 s390_function_and_libcall_value (machine_mode mode
,
9497 const_tree ret_type
,
9498 const_tree fntype_or_decl
,
9499 bool outgoing ATTRIBUTE_UNUSED
)
9501 /* For normal functions perform the promotion as
9502 promote_function_mode would do. */
9505 int unsignedp
= TYPE_UNSIGNED (ret_type
);
9506 mode
= promote_function_mode (ret_type
, mode
, &unsignedp
,
9510 gcc_assert (GET_MODE_CLASS (mode
) == MODE_INT
|| SCALAR_FLOAT_MODE_P (mode
));
9511 gcc_assert (GET_MODE_SIZE (mode
) <= 8);
9513 if (TARGET_HARD_FLOAT
&& SCALAR_FLOAT_MODE_P (mode
))
9514 return gen_rtx_REG (mode
, 16);
9515 else if (GET_MODE_SIZE (mode
) <= UNITS_PER_LONG
9516 || UNITS_PER_LONG
== UNITS_PER_WORD
)
9517 return gen_rtx_REG (mode
, 2);
9518 else if (GET_MODE_SIZE (mode
) == 2 * UNITS_PER_LONG
)
9520 /* This case is triggered when returning a 64 bit value with
9521 -m31 -mzarch. Although the value would fit into a single
9522 register it has to be forced into a 32 bit register pair in
9523 order to match the ABI. */
9524 rtvec p
= rtvec_alloc (2);
9527 = gen_rtx_EXPR_LIST (SImode
, gen_rtx_REG (SImode
, 2), const0_rtx
);
9529 = gen_rtx_EXPR_LIST (SImode
, gen_rtx_REG (SImode
, 3), GEN_INT (4));
9531 return gen_rtx_PARALLEL (mode
, p
);
9537 /* Define where to return a scalar return value of type RET_TYPE. */
9540 s390_function_value (const_tree ret_type
, const_tree fn_decl_or_type
,
9543 return s390_function_and_libcall_value (TYPE_MODE (ret_type
), ret_type
,
9544 fn_decl_or_type
, outgoing
);
9547 /* Define where to return a scalar libcall return value of mode
9551 s390_libcall_value (machine_mode mode
, const_rtx fun ATTRIBUTE_UNUSED
)
9553 return s390_function_and_libcall_value (mode
, NULL_TREE
,
9558 /* Create and return the va_list datatype.
9560 On S/390, va_list is an array type equivalent to
9562 typedef struct __va_list_tag
9566 void *__overflow_arg_area;
9567 void *__reg_save_area;
9570 where __gpr and __fpr hold the number of general purpose
9571 or floating point arguments used up to now, respectively,
9572 __overflow_arg_area points to the stack location of the
9573 next argument passed on the stack, and __reg_save_area
9574 always points to the start of the register area in the
9575 call frame of the current function. The function prologue
9576 saves all registers used for argument passing into this
9577 area if the function uses variable arguments. */
9580 s390_build_builtin_va_list (void)
9582 tree f_gpr
, f_fpr
, f_ovf
, f_sav
, record
, type_decl
;
9584 record
= lang_hooks
.types
.make_type (RECORD_TYPE
);
9587 build_decl (BUILTINS_LOCATION
,
9588 TYPE_DECL
, get_identifier ("__va_list_tag"), record
);
9590 f_gpr
= build_decl (BUILTINS_LOCATION
,
9591 FIELD_DECL
, get_identifier ("__gpr"),
9592 long_integer_type_node
);
9593 f_fpr
= build_decl (BUILTINS_LOCATION
,
9594 FIELD_DECL
, get_identifier ("__fpr"),
9595 long_integer_type_node
);
9596 f_ovf
= build_decl (BUILTINS_LOCATION
,
9597 FIELD_DECL
, get_identifier ("__overflow_arg_area"),
9599 f_sav
= build_decl (BUILTINS_LOCATION
,
9600 FIELD_DECL
, get_identifier ("__reg_save_area"),
9603 va_list_gpr_counter_field
= f_gpr
;
9604 va_list_fpr_counter_field
= f_fpr
;
9606 DECL_FIELD_CONTEXT (f_gpr
) = record
;
9607 DECL_FIELD_CONTEXT (f_fpr
) = record
;
9608 DECL_FIELD_CONTEXT (f_ovf
) = record
;
9609 DECL_FIELD_CONTEXT (f_sav
) = record
;
9611 TYPE_STUB_DECL (record
) = type_decl
;
9612 TYPE_NAME (record
) = type_decl
;
9613 TYPE_FIELDS (record
) = f_gpr
;
9614 DECL_CHAIN (f_gpr
) = f_fpr
;
9615 DECL_CHAIN (f_fpr
) = f_ovf
;
9616 DECL_CHAIN (f_ovf
) = f_sav
;
9618 layout_type (record
);
9620 /* The correct type is an array type of one element. */
9621 return build_array_type (record
, build_index_type (size_zero_node
));
9624 /* Implement va_start by filling the va_list structure VALIST.
9625 STDARG_P is always true, and ignored.
9626 NEXTARG points to the first anonymous stack argument.
9628 The following global variables are used to initialize
9629 the va_list structure:
9632 holds number of gprs and fprs used for named arguments.
9633 crtl->args.arg_offset_rtx:
9634 holds the offset of the first anonymous stack argument
9635 (relative to the virtual arg pointer). */
9638 s390_va_start (tree valist
, rtx nextarg ATTRIBUTE_UNUSED
)
9640 HOST_WIDE_INT n_gpr
, n_fpr
;
9642 tree f_gpr
, f_fpr
, f_ovf
, f_sav
;
9643 tree gpr
, fpr
, ovf
, sav
, t
;
9645 f_gpr
= TYPE_FIELDS (TREE_TYPE (va_list_type_node
));
9646 f_fpr
= DECL_CHAIN (f_gpr
);
9647 f_ovf
= DECL_CHAIN (f_fpr
);
9648 f_sav
= DECL_CHAIN (f_ovf
);
9650 valist
= build_simple_mem_ref (valist
);
9651 gpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_gpr
), valist
, f_gpr
, NULL_TREE
);
9652 fpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_fpr
), valist
, f_fpr
, NULL_TREE
);
9653 ovf
= build3 (COMPONENT_REF
, TREE_TYPE (f_ovf
), valist
, f_ovf
, NULL_TREE
);
9654 sav
= build3 (COMPONENT_REF
, TREE_TYPE (f_sav
), valist
, f_sav
, NULL_TREE
);
9656 /* Count number of gp and fp argument registers used. */
9658 n_gpr
= crtl
->args
.info
.gprs
;
9659 n_fpr
= crtl
->args
.info
.fprs
;
9661 if (cfun
->va_list_gpr_size
)
9663 t
= build2 (MODIFY_EXPR
, TREE_TYPE (gpr
), gpr
,
9664 build_int_cst (NULL_TREE
, n_gpr
));
9665 TREE_SIDE_EFFECTS (t
) = 1;
9666 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
9669 if (cfun
->va_list_fpr_size
)
9671 t
= build2 (MODIFY_EXPR
, TREE_TYPE (fpr
), fpr
,
9672 build_int_cst (NULL_TREE
, n_fpr
));
9673 TREE_SIDE_EFFECTS (t
) = 1;
9674 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
9677 /* Find the overflow area. */
9678 if (n_gpr
+ cfun
->va_list_gpr_size
> GP_ARG_NUM_REG
9679 || n_fpr
+ cfun
->va_list_fpr_size
> FP_ARG_NUM_REG
)
9681 t
= make_tree (TREE_TYPE (ovf
), virtual_incoming_args_rtx
);
9683 off
= INTVAL (crtl
->args
.arg_offset_rtx
);
9684 off
= off
< 0 ? 0 : off
;
9685 if (TARGET_DEBUG_ARG
)
9686 fprintf (stderr
, "va_start: n_gpr = %d, n_fpr = %d off %d\n",
9687 (int)n_gpr
, (int)n_fpr
, off
);
9689 t
= fold_build_pointer_plus_hwi (t
, off
);
9691 t
= build2 (MODIFY_EXPR
, TREE_TYPE (ovf
), ovf
, t
);
9692 TREE_SIDE_EFFECTS (t
) = 1;
9693 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
9696 /* Find the register save area. */
9697 if ((cfun
->va_list_gpr_size
&& n_gpr
< GP_ARG_NUM_REG
)
9698 || (cfun
->va_list_fpr_size
&& n_fpr
< FP_ARG_NUM_REG
))
9700 t
= make_tree (TREE_TYPE (sav
), return_address_pointer_rtx
);
9701 t
= fold_build_pointer_plus_hwi (t
, -RETURN_REGNUM
* UNITS_PER_LONG
);
9703 t
= build2 (MODIFY_EXPR
, TREE_TYPE (sav
), sav
, t
);
9704 TREE_SIDE_EFFECTS (t
) = 1;
9705 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
9709 /* Implement va_arg by updating the va_list structure
9710 VALIST as required to retrieve an argument of type
9711 TYPE, and returning that argument.
9713 Generates code equivalent to:
9715 if (integral value) {
9716 if (size <= 4 && args.gpr < 5 ||
9717 size > 4 && args.gpr < 4 )
9718 ret = args.reg_save_area[args.gpr+8]
9720 ret = *args.overflow_arg_area++;
9721 } else if (float value) {
9723 ret = args.reg_save_area[args.fpr+64]
9725 ret = *args.overflow_arg_area++;
9726 } else if (aggregate value) {
9728 ret = *args.reg_save_area[args.gpr]
9730 ret = **args.overflow_arg_area++;
9734 s390_gimplify_va_arg (tree valist
, tree type
, gimple_seq
*pre_p
,
9735 gimple_seq
*post_p ATTRIBUTE_UNUSED
)
9737 tree f_gpr
, f_fpr
, f_ovf
, f_sav
;
9738 tree gpr
, fpr
, ovf
, sav
, reg
, t
, u
;
9739 int indirect_p
, size
, n_reg
, sav_ofs
, sav_scale
, max_reg
;
9740 tree lab_false
, lab_over
, addr
;
9742 f_gpr
= TYPE_FIELDS (TREE_TYPE (va_list_type_node
));
9743 f_fpr
= DECL_CHAIN (f_gpr
);
9744 f_ovf
= DECL_CHAIN (f_fpr
);
9745 f_sav
= DECL_CHAIN (f_ovf
);
9747 valist
= build_va_arg_indirect_ref (valist
);
9748 gpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_gpr
), valist
, f_gpr
, NULL_TREE
);
9749 fpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_fpr
), valist
, f_fpr
, NULL_TREE
);
9750 sav
= build3 (COMPONENT_REF
, TREE_TYPE (f_sav
), valist
, f_sav
, NULL_TREE
);
9752 /* The tree for args* cannot be shared between gpr/fpr and ovf since
9753 both appear on a lhs. */
9754 valist
= unshare_expr (valist
);
9755 ovf
= build3 (COMPONENT_REF
, TREE_TYPE (f_ovf
), valist
, f_ovf
, NULL_TREE
);
9757 size
= int_size_in_bytes (type
);
9759 if (pass_by_reference (NULL
, TYPE_MODE (type
), type
, false))
9761 if (TARGET_DEBUG_ARG
)
9763 fprintf (stderr
, "va_arg: aggregate type");
9767 /* Aggregates are passed by reference. */
9772 /* kernel stack layout on 31 bit: It is assumed here that no padding
9773 will be added by s390_frame_info because for va_args always an even
9774 number of gprs has to be saved r15-r2 = 14 regs. */
9775 sav_ofs
= 2 * UNITS_PER_LONG
;
9776 sav_scale
= UNITS_PER_LONG
;
9777 size
= UNITS_PER_LONG
;
9778 max_reg
= GP_ARG_NUM_REG
- n_reg
;
9780 else if (s390_function_arg_float (TYPE_MODE (type
), type
))
9782 if (TARGET_DEBUG_ARG
)
9784 fprintf (stderr
, "va_arg: float type");
9788 /* FP args go in FP registers, if present. */
9792 sav_ofs
= 16 * UNITS_PER_LONG
;
9794 max_reg
= FP_ARG_NUM_REG
- n_reg
;
9798 if (TARGET_DEBUG_ARG
)
9800 fprintf (stderr
, "va_arg: other type");
9804 /* Otherwise into GP registers. */
9807 n_reg
= (size
+ UNITS_PER_LONG
- 1) / UNITS_PER_LONG
;
9809 /* kernel stack layout on 31 bit: It is assumed here that no padding
9810 will be added by s390_frame_info because for va_args always an even
9811 number of gprs has to be saved r15-r2 = 14 regs. */
9812 sav_ofs
= 2 * UNITS_PER_LONG
;
9814 if (size
< UNITS_PER_LONG
)
9815 sav_ofs
+= UNITS_PER_LONG
- size
;
9817 sav_scale
= UNITS_PER_LONG
;
9818 max_reg
= GP_ARG_NUM_REG
- n_reg
;
9821 /* Pull the value out of the saved registers ... */
9823 lab_false
= create_artificial_label (UNKNOWN_LOCATION
);
9824 lab_over
= create_artificial_label (UNKNOWN_LOCATION
);
9825 addr
= create_tmp_var (ptr_type_node
, "addr");
9827 t
= fold_convert (TREE_TYPE (reg
), size_int (max_reg
));
9828 t
= build2 (GT_EXPR
, boolean_type_node
, reg
, t
);
9829 u
= build1 (GOTO_EXPR
, void_type_node
, lab_false
);
9830 t
= build3 (COND_EXPR
, void_type_node
, t
, u
, NULL_TREE
);
9831 gimplify_and_add (t
, pre_p
);
9833 t
= fold_build_pointer_plus_hwi (sav
, sav_ofs
);
9834 u
= build2 (MULT_EXPR
, TREE_TYPE (reg
), reg
,
9835 fold_convert (TREE_TYPE (reg
), size_int (sav_scale
)));
9836 t
= fold_build_pointer_plus (t
, u
);
9838 gimplify_assign (addr
, t
, pre_p
);
9840 gimple_seq_add_stmt (pre_p
, gimple_build_goto (lab_over
));
9842 gimple_seq_add_stmt (pre_p
, gimple_build_label (lab_false
));
9845 /* ... Otherwise out of the overflow area. */
9848 if (size
< UNITS_PER_LONG
)
9849 t
= fold_build_pointer_plus_hwi (t
, UNITS_PER_LONG
- size
);
9851 gimplify_expr (&t
, pre_p
, NULL
, is_gimple_val
, fb_rvalue
);
9853 gimplify_assign (addr
, t
, pre_p
);
9855 t
= fold_build_pointer_plus_hwi (t
, size
);
9856 gimplify_assign (ovf
, t
, pre_p
);
9858 gimple_seq_add_stmt (pre_p
, gimple_build_label (lab_over
));
9861 /* Increment register save count. */
9863 u
= build2 (PREINCREMENT_EXPR
, TREE_TYPE (reg
), reg
,
9864 fold_convert (TREE_TYPE (reg
), size_int (n_reg
)));
9865 gimplify_and_add (u
, pre_p
);
9869 t
= build_pointer_type_for_mode (build_pointer_type (type
),
9871 addr
= fold_convert (t
, addr
);
9872 addr
= build_va_arg_indirect_ref (addr
);
9876 t
= build_pointer_type_for_mode (type
, ptr_mode
, true);
9877 addr
= fold_convert (t
, addr
);
9880 return build_va_arg_indirect_ref (addr
);
9883 /* Emit rtl for the tbegin or tbegin_retry (RETRY != NULL_RTX)
9885 DEST - Register location where CC will be stored.
9886 TDB - Pointer to a 256 byte area where to store the transaction.
9887 diagnostic block. NULL if TDB is not needed.
9888 RETRY - Retry count value. If non-NULL a retry loop for CC2
9890 CLOBBER_FPRS_P - If true clobbers for all FPRs are emitted as part
9891 of the tbegin instruction pattern. */
9894 s390_expand_tbegin (rtx dest
, rtx tdb
, rtx retry
, bool clobber_fprs_p
)
9896 rtx retry_plus_two
= gen_reg_rtx (SImode
);
9897 rtx retry_reg
= gen_reg_rtx (SImode
);
9898 rtx_code_label
*retry_label
= NULL
;
9900 if (retry
!= NULL_RTX
)
9902 emit_move_insn (retry_reg
, retry
);
9903 emit_insn (gen_addsi3 (retry_plus_two
, retry_reg
, const2_rtx
));
9904 emit_insn (gen_addsi3 (retry_reg
, retry_reg
, const1_rtx
));
9905 retry_label
= gen_label_rtx ();
9906 emit_label (retry_label
);
9910 emit_insn (gen_tbegin_1 (gen_rtx_CONST_INT (VOIDmode
, TBEGIN_MASK
), tdb
));
9912 emit_insn (gen_tbegin_nofloat_1 (gen_rtx_CONST_INT (VOIDmode
, TBEGIN_MASK
),
9915 emit_move_insn (dest
, gen_rtx_UNSPEC (SImode
,
9916 gen_rtvec (1, gen_rtx_REG (CCRAWmode
,
9919 if (retry
!= NULL_RTX
)
9921 const int CC0
= 1 << 3;
9922 const int CC1
= 1 << 2;
9923 const int CC3
= 1 << 0;
9925 rtx count
= gen_reg_rtx (SImode
);
9926 rtx_code_label
*leave_label
= gen_label_rtx ();
9928 /* Exit for success and permanent failures. */
9929 jump
= s390_emit_jump (leave_label
,
9930 gen_rtx_EQ (VOIDmode
,
9931 gen_rtx_REG (CCRAWmode
, CC_REGNUM
),
9932 gen_rtx_CONST_INT (VOIDmode
, CC0
| CC1
| CC3
)));
9933 LABEL_NUSES (leave_label
) = 1;
9935 /* CC2 - transient failure. Perform retry with ppa. */
9936 emit_move_insn (count
, retry_plus_two
);
9937 emit_insn (gen_subsi3 (count
, count
, retry_reg
));
9938 emit_insn (gen_tx_assist (count
));
9939 jump
= emit_jump_insn (gen_doloop_si64 (retry_label
,
9942 JUMP_LABEL (jump
) = retry_label
;
9943 LABEL_NUSES (retry_label
) = 1;
9944 emit_label (leave_label
);
9952 S390_BUILTIN_TBEGIN
,
9953 S390_BUILTIN_TBEGIN_NOFLOAT
,
9954 S390_BUILTIN_TBEGIN_RETRY
,
9955 S390_BUILTIN_TBEGIN_RETRY_NOFLOAT
,
9956 S390_BUILTIN_TBEGINC
,
9958 S390_BUILTIN_TABORT
,
9959 S390_BUILTIN_NON_TX_STORE
,
9960 S390_BUILTIN_TX_NESTING_DEPTH
,
9961 S390_BUILTIN_TX_ASSIST
,
9966 static enum insn_code
const code_for_builtin
[S390_BUILTIN_max
] = {
9968 CODE_FOR_tbegin_nofloat
,
9969 CODE_FOR_tbegin_retry
,
9970 CODE_FOR_tbegin_retry_nofloat
,
9980 s390_init_builtins (void)
9982 tree ftype
, uint64_type
;
9983 tree returns_twice_attr
= tree_cons (get_identifier ("returns_twice"),
9985 tree noreturn_attr
= tree_cons (get_identifier ("noreturn"), NULL
, NULL
);
9987 /* void foo (void) */
9988 ftype
= build_function_type_list (void_type_node
, NULL_TREE
);
9989 add_builtin_function ("__builtin_tbeginc", ftype
, S390_BUILTIN_TBEGINC
,
9990 BUILT_IN_MD
, NULL
, NULL_TREE
);
9992 /* void foo (int) */
9993 ftype
= build_function_type_list (void_type_node
, integer_type_node
,
9995 add_builtin_function ("__builtin_tabort", ftype
,
9996 S390_BUILTIN_TABORT
, BUILT_IN_MD
, NULL
, noreturn_attr
);
9997 add_builtin_function ("__builtin_tx_assist", ftype
,
9998 S390_BUILTIN_TX_ASSIST
, BUILT_IN_MD
, NULL
, NULL_TREE
);
10000 /* int foo (void *) */
10001 ftype
= build_function_type_list (integer_type_node
, ptr_type_node
, NULL_TREE
);
10002 add_builtin_function ("__builtin_tbegin", ftype
, S390_BUILTIN_TBEGIN
,
10003 BUILT_IN_MD
, NULL
, returns_twice_attr
);
10004 add_builtin_function ("__builtin_tbegin_nofloat", ftype
,
10005 S390_BUILTIN_TBEGIN_NOFLOAT
,
10006 BUILT_IN_MD
, NULL
, returns_twice_attr
);
10008 /* int foo (void *, int) */
10009 ftype
= build_function_type_list (integer_type_node
, ptr_type_node
,
10010 integer_type_node
, NULL_TREE
);
10011 add_builtin_function ("__builtin_tbegin_retry", ftype
,
10012 S390_BUILTIN_TBEGIN_RETRY
,
10014 NULL
, returns_twice_attr
);
10015 add_builtin_function ("__builtin_tbegin_retry_nofloat", ftype
,
10016 S390_BUILTIN_TBEGIN_RETRY_NOFLOAT
,
10018 NULL
, returns_twice_attr
);
10020 /* int foo (void) */
10021 ftype
= build_function_type_list (integer_type_node
, NULL_TREE
);
10022 add_builtin_function ("__builtin_tx_nesting_depth", ftype
,
10023 S390_BUILTIN_TX_NESTING_DEPTH
,
10024 BUILT_IN_MD
, NULL
, NULL_TREE
);
10025 add_builtin_function ("__builtin_tend", ftype
,
10026 S390_BUILTIN_TEND
, BUILT_IN_MD
, NULL
, NULL_TREE
);
10028 /* void foo (uint64_t *, uint64_t) */
10030 uint64_type
= long_unsigned_type_node
;
10032 uint64_type
= long_long_unsigned_type_node
;
10034 ftype
= build_function_type_list (void_type_node
,
10035 build_pointer_type (uint64_type
),
10036 uint64_type
, NULL_TREE
);
10037 add_builtin_function ("__builtin_non_tx_store", ftype
,
10038 S390_BUILTIN_NON_TX_STORE
,
10039 BUILT_IN_MD
, NULL
, NULL_TREE
);
10042 /* Expand an expression EXP that calls a built-in function,
10043 with result going to TARGET if that's convenient
10044 (and in mode MODE if that's convenient).
10045 SUBTARGET may be used as the target for computing one of EXP's operands.
10046 IGNORE is nonzero if the value is to be ignored. */
10049 s390_expand_builtin (tree exp
, rtx target
, rtx subtarget ATTRIBUTE_UNUSED
,
10050 machine_mode mode ATTRIBUTE_UNUSED
,
10051 int ignore ATTRIBUTE_UNUSED
)
10055 tree fndecl
= TREE_OPERAND (CALL_EXPR_FN (exp
), 0);
10056 unsigned int fcode
= DECL_FUNCTION_CODE (fndecl
);
10057 enum insn_code icode
;
10058 rtx op
[MAX_ARGS
], pat
;
10062 call_expr_arg_iterator iter
;
10064 if (fcode
>= S390_BUILTIN_max
)
10065 internal_error ("bad builtin fcode");
10066 icode
= code_for_builtin
[fcode
];
10068 internal_error ("bad builtin fcode");
10071 error ("Transactional execution builtins not enabled (-mhtm)\n");
10073 /* Set a flag in the machine specific cfun part in order to support
10074 saving/restoring of FPRs. */
10075 if (fcode
== S390_BUILTIN_TBEGIN
|| fcode
== S390_BUILTIN_TBEGIN_RETRY
)
10076 cfun
->machine
->tbegin_p
= true;
10078 nonvoid
= TREE_TYPE (TREE_TYPE (fndecl
)) != void_type_node
;
10081 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, exp
)
10083 const struct insn_operand_data
*insn_op
;
10085 if (arg
== error_mark_node
)
10087 if (arity
>= MAX_ARGS
)
10090 insn_op
= &insn_data
[icode
].operand
[arity
+ nonvoid
];
10092 op
[arity
] = expand_expr (arg
, NULL_RTX
, insn_op
->mode
, EXPAND_NORMAL
);
10094 if (!(*insn_op
->predicate
) (op
[arity
], insn_op
->mode
))
10096 if (insn_op
->predicate
== memory_operand
)
10098 /* Don't move a NULL pointer into a register. Otherwise
10099 we have to rely on combine being able to move it back
10100 in order to get an immediate 0 in the instruction. */
10101 if (op
[arity
] != const0_rtx
)
10102 op
[arity
] = copy_to_mode_reg (Pmode
, op
[arity
]);
10103 op
[arity
] = gen_rtx_MEM (insn_op
->mode
, op
[arity
]);
10106 op
[arity
] = copy_to_mode_reg (insn_op
->mode
, op
[arity
]);
10114 machine_mode tmode
= insn_data
[icode
].operand
[0].mode
;
10116 || GET_MODE (target
) != tmode
10117 || !(*insn_data
[icode
].operand
[0].predicate
) (target
, tmode
))
10118 target
= gen_reg_rtx (tmode
);
10124 pat
= GEN_FCN (icode
) (target
);
10128 pat
= GEN_FCN (icode
) (target
, op
[0]);
10130 pat
= GEN_FCN (icode
) (op
[0]);
10134 pat
= GEN_FCN (icode
) (target
, op
[0], op
[1]);
10136 pat
= GEN_FCN (icode
) (op
[0], op
[1]);
10139 gcc_unreachable ();
10151 /* We call mcount before the function prologue. So a profiled leaf
10152 function should stay a leaf function. */
10155 s390_keep_leaf_when_profiled ()
10160 /* Output assembly code for the trampoline template to
10163 On S/390, we use gpr 1 internally in the trampoline code;
10164 gpr 0 is used to hold the static chain. */
10167 s390_asm_trampoline_template (FILE *file
)
10170 op
[0] = gen_rtx_REG (Pmode
, 0);
10171 op
[1] = gen_rtx_REG (Pmode
, 1);
10175 output_asm_insn ("basr\t%1,0", op
); /* 2 byte */
10176 output_asm_insn ("lmg\t%0,%1,14(%1)", op
); /* 6 byte */
10177 output_asm_insn ("br\t%1", op
); /* 2 byte */
10178 ASM_OUTPUT_SKIP (file
, (HOST_WIDE_INT
)(TRAMPOLINE_SIZE
- 10));
10182 output_asm_insn ("basr\t%1,0", op
); /* 2 byte */
10183 output_asm_insn ("lm\t%0,%1,6(%1)", op
); /* 4 byte */
10184 output_asm_insn ("br\t%1", op
); /* 2 byte */
10185 ASM_OUTPUT_SKIP (file
, (HOST_WIDE_INT
)(TRAMPOLINE_SIZE
- 8));
10189 /* Emit RTL insns to initialize the variable parts of a trampoline.
10190 FNADDR is an RTX for the address of the function's pure code.
10191 CXT is an RTX for the static chain value for the function. */
10194 s390_trampoline_init (rtx m_tramp
, tree fndecl
, rtx cxt
)
10196 rtx fnaddr
= XEXP (DECL_RTL (fndecl
), 0);
10199 emit_block_move (m_tramp
, assemble_trampoline_template (),
10200 GEN_INT (2 * UNITS_PER_LONG
), BLOCK_OP_NORMAL
);
10202 mem
= adjust_address (m_tramp
, Pmode
, 2 * UNITS_PER_LONG
);
10203 emit_move_insn (mem
, cxt
);
10204 mem
= adjust_address (m_tramp
, Pmode
, 3 * UNITS_PER_LONG
);
10205 emit_move_insn (mem
, fnaddr
);
10208 /* Output assembler code to FILE to increment profiler label # LABELNO
10209 for profiling a function entry. */
10212 s390_function_profiler (FILE *file
, int labelno
)
10217 ASM_GENERATE_INTERNAL_LABEL (label
, "LP", labelno
);
10219 fprintf (file
, "# function profiler \n");
10221 op
[0] = gen_rtx_REG (Pmode
, RETURN_REGNUM
);
10222 op
[1] = gen_rtx_REG (Pmode
, STACK_POINTER_REGNUM
);
10223 op
[1] = gen_rtx_MEM (Pmode
, plus_constant (Pmode
, op
[1], UNITS_PER_LONG
));
10225 op
[2] = gen_rtx_REG (Pmode
, 1);
10226 op
[3] = gen_rtx_SYMBOL_REF (Pmode
, label
);
10227 SYMBOL_REF_FLAGS (op
[3]) = SYMBOL_FLAG_LOCAL
;
10229 op
[4] = gen_rtx_SYMBOL_REF (Pmode
, "_mcount");
10232 op
[4] = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op
[4]), UNSPEC_PLT
);
10233 op
[4] = gen_rtx_CONST (Pmode
, op
[4]);
10238 output_asm_insn ("stg\t%0,%1", op
);
10239 output_asm_insn ("larl\t%2,%3", op
);
10240 output_asm_insn ("brasl\t%0,%4", op
);
10241 output_asm_insn ("lg\t%0,%1", op
);
10243 else if (!flag_pic
)
10245 op
[6] = gen_label_rtx ();
10247 output_asm_insn ("st\t%0,%1", op
);
10248 output_asm_insn ("bras\t%2,%l6", op
);
10249 output_asm_insn (".long\t%4", op
);
10250 output_asm_insn (".long\t%3", op
);
10251 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[6]));
10252 output_asm_insn ("l\t%0,0(%2)", op
);
10253 output_asm_insn ("l\t%2,4(%2)", op
);
10254 output_asm_insn ("basr\t%0,%0", op
);
10255 output_asm_insn ("l\t%0,%1", op
);
10259 op
[5] = gen_label_rtx ();
10260 op
[6] = gen_label_rtx ();
10262 output_asm_insn ("st\t%0,%1", op
);
10263 output_asm_insn ("bras\t%2,%l6", op
);
10264 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[5]));
10265 output_asm_insn (".long\t%4-%l5", op
);
10266 output_asm_insn (".long\t%3-%l5", op
);
10267 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[6]));
10268 output_asm_insn ("lr\t%0,%2", op
);
10269 output_asm_insn ("a\t%0,0(%2)", op
);
10270 output_asm_insn ("a\t%2,4(%2)", op
);
10271 output_asm_insn ("basr\t%0,%0", op
);
10272 output_asm_insn ("l\t%0,%1", op
);
10276 /* Encode symbol attributes (local vs. global, tls model) of a SYMBOL_REF
10277 into its SYMBOL_REF_FLAGS. */
10280 s390_encode_section_info (tree decl
, rtx rtl
, int first
)
10282 default_encode_section_info (decl
, rtl
, first
);
10284 if (TREE_CODE (decl
) == VAR_DECL
)
10286 /* If a variable has a forced alignment to < 2 bytes, mark it
10287 with SYMBOL_FLAG_ALIGN1 to prevent it from being used as LARL
10289 if (DECL_USER_ALIGN (decl
) && DECL_ALIGN (decl
) < 16)
10290 SYMBOL_REF_FLAGS (XEXP (rtl
, 0)) |= SYMBOL_FLAG_ALIGN1
;
10291 if (!DECL_SIZE (decl
)
10292 || !DECL_ALIGN (decl
)
10293 || !tree_fits_shwi_p (DECL_SIZE (decl
))
10294 || (DECL_ALIGN (decl
) <= 64
10295 && DECL_ALIGN (decl
) != tree_to_shwi (DECL_SIZE (decl
))))
10296 SYMBOL_REF_FLAGS (XEXP (rtl
, 0)) |= SYMBOL_FLAG_NOT_NATURALLY_ALIGNED
;
10299 /* Literal pool references don't have a decl so they are handled
10300 differently here. We rely on the information in the MEM_ALIGN
10301 entry to decide upon natural alignment. */
10303 && GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
10304 && TREE_CONSTANT_POOL_ADDRESS_P (XEXP (rtl
, 0))
10305 && (MEM_ALIGN (rtl
) == 0
10306 || GET_MODE_BITSIZE (GET_MODE (rtl
)) == 0
10307 || MEM_ALIGN (rtl
) < GET_MODE_BITSIZE (GET_MODE (rtl
))))
10308 SYMBOL_REF_FLAGS (XEXP (rtl
, 0)) |= SYMBOL_FLAG_NOT_NATURALLY_ALIGNED
;
10311 /* Output thunk to FILE that implements a C++ virtual function call (with
10312 multiple inheritance) to FUNCTION. The thunk adjusts the this pointer
10313 by DELTA, and unless VCALL_OFFSET is zero, applies an additional adjustment
10314 stored at VCALL_OFFSET in the vtable whose address is located at offset 0
10315 relative to the resulting this pointer. */
10318 s390_output_mi_thunk (FILE *file
, tree thunk ATTRIBUTE_UNUSED
,
10319 HOST_WIDE_INT delta
, HOST_WIDE_INT vcall_offset
,
10325 /* Make sure unwind info is emitted for the thunk if needed. */
10326 final_start_function (emit_barrier (), file
, 1);
10328 /* Operand 0 is the target function. */
10329 op
[0] = XEXP (DECL_RTL (function
), 0);
10330 if (flag_pic
&& !SYMBOL_REF_LOCAL_P (op
[0]))
10333 op
[0] = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op
[0]),
10334 TARGET_64BIT
? UNSPEC_PLT
: UNSPEC_GOT
);
10335 op
[0] = gen_rtx_CONST (Pmode
, op
[0]);
10338 /* Operand 1 is the 'this' pointer. */
10339 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function
)), function
))
10340 op
[1] = gen_rtx_REG (Pmode
, 3);
10342 op
[1] = gen_rtx_REG (Pmode
, 2);
10344 /* Operand 2 is the delta. */
10345 op
[2] = GEN_INT (delta
);
10347 /* Operand 3 is the vcall_offset. */
10348 op
[3] = GEN_INT (vcall_offset
);
10350 /* Operand 4 is the temporary register. */
10351 op
[4] = gen_rtx_REG (Pmode
, 1);
10353 /* Operands 5 to 8 can be used as labels. */
10359 /* Operand 9 can be used for temporary register. */
10362 /* Generate code. */
10365 /* Setup literal pool pointer if required. */
10366 if ((!DISP_IN_RANGE (delta
)
10367 && !CONST_OK_FOR_K (delta
)
10368 && !CONST_OK_FOR_Os (delta
))
10369 || (!DISP_IN_RANGE (vcall_offset
)
10370 && !CONST_OK_FOR_K (vcall_offset
)
10371 && !CONST_OK_FOR_Os (vcall_offset
)))
10373 op
[5] = gen_label_rtx ();
10374 output_asm_insn ("larl\t%4,%5", op
);
10377 /* Add DELTA to this pointer. */
10380 if (CONST_OK_FOR_J (delta
))
10381 output_asm_insn ("la\t%1,%2(%1)", op
);
10382 else if (DISP_IN_RANGE (delta
))
10383 output_asm_insn ("lay\t%1,%2(%1)", op
);
10384 else if (CONST_OK_FOR_K (delta
))
10385 output_asm_insn ("aghi\t%1,%2", op
);
10386 else if (CONST_OK_FOR_Os (delta
))
10387 output_asm_insn ("agfi\t%1,%2", op
);
10390 op
[6] = gen_label_rtx ();
10391 output_asm_insn ("agf\t%1,%6-%5(%4)", op
);
10395 /* Perform vcall adjustment. */
10398 if (DISP_IN_RANGE (vcall_offset
))
10400 output_asm_insn ("lg\t%4,0(%1)", op
);
10401 output_asm_insn ("ag\t%1,%3(%4)", op
);
10403 else if (CONST_OK_FOR_K (vcall_offset
))
10405 output_asm_insn ("lghi\t%4,%3", op
);
10406 output_asm_insn ("ag\t%4,0(%1)", op
);
10407 output_asm_insn ("ag\t%1,0(%4)", op
);
10409 else if (CONST_OK_FOR_Os (vcall_offset
))
10411 output_asm_insn ("lgfi\t%4,%3", op
);
10412 output_asm_insn ("ag\t%4,0(%1)", op
);
10413 output_asm_insn ("ag\t%1,0(%4)", op
);
10417 op
[7] = gen_label_rtx ();
10418 output_asm_insn ("llgf\t%4,%7-%5(%4)", op
);
10419 output_asm_insn ("ag\t%4,0(%1)", op
);
10420 output_asm_insn ("ag\t%1,0(%4)", op
);
10424 /* Jump to target. */
10425 output_asm_insn ("jg\t%0", op
);
10427 /* Output literal pool if required. */
10430 output_asm_insn (".align\t4", op
);
10431 targetm
.asm_out
.internal_label (file
, "L",
10432 CODE_LABEL_NUMBER (op
[5]));
10436 targetm
.asm_out
.internal_label (file
, "L",
10437 CODE_LABEL_NUMBER (op
[6]));
10438 output_asm_insn (".long\t%2", op
);
10442 targetm
.asm_out
.internal_label (file
, "L",
10443 CODE_LABEL_NUMBER (op
[7]));
10444 output_asm_insn (".long\t%3", op
);
10449 /* Setup base pointer if required. */
10451 || (!DISP_IN_RANGE (delta
)
10452 && !CONST_OK_FOR_K (delta
)
10453 && !CONST_OK_FOR_Os (delta
))
10454 || (!DISP_IN_RANGE (delta
)
10455 && !CONST_OK_FOR_K (vcall_offset
)
10456 && !CONST_OK_FOR_Os (vcall_offset
)))
10458 op
[5] = gen_label_rtx ();
10459 output_asm_insn ("basr\t%4,0", op
);
10460 targetm
.asm_out
.internal_label (file
, "L",
10461 CODE_LABEL_NUMBER (op
[5]));
10464 /* Add DELTA to this pointer. */
10467 if (CONST_OK_FOR_J (delta
))
10468 output_asm_insn ("la\t%1,%2(%1)", op
);
10469 else if (DISP_IN_RANGE (delta
))
10470 output_asm_insn ("lay\t%1,%2(%1)", op
);
10471 else if (CONST_OK_FOR_K (delta
))
10472 output_asm_insn ("ahi\t%1,%2", op
);
10473 else if (CONST_OK_FOR_Os (delta
))
10474 output_asm_insn ("afi\t%1,%2", op
);
10477 op
[6] = gen_label_rtx ();
10478 output_asm_insn ("a\t%1,%6-%5(%4)", op
);
10482 /* Perform vcall adjustment. */
10485 if (CONST_OK_FOR_J (vcall_offset
))
10487 output_asm_insn ("l\t%4,0(%1)", op
);
10488 output_asm_insn ("a\t%1,%3(%4)", op
);
10490 else if (DISP_IN_RANGE (vcall_offset
))
10492 output_asm_insn ("l\t%4,0(%1)", op
);
10493 output_asm_insn ("ay\t%1,%3(%4)", op
);
10495 else if (CONST_OK_FOR_K (vcall_offset
))
10497 output_asm_insn ("lhi\t%4,%3", op
);
10498 output_asm_insn ("a\t%4,0(%1)", op
);
10499 output_asm_insn ("a\t%1,0(%4)", op
);
10501 else if (CONST_OK_FOR_Os (vcall_offset
))
10503 output_asm_insn ("iilf\t%4,%3", op
);
10504 output_asm_insn ("a\t%4,0(%1)", op
);
10505 output_asm_insn ("a\t%1,0(%4)", op
);
10509 op
[7] = gen_label_rtx ();
10510 output_asm_insn ("l\t%4,%7-%5(%4)", op
);
10511 output_asm_insn ("a\t%4,0(%1)", op
);
10512 output_asm_insn ("a\t%1,0(%4)", op
);
10515 /* We had to clobber the base pointer register.
10516 Re-setup the base pointer (with a different base). */
10517 op
[5] = gen_label_rtx ();
10518 output_asm_insn ("basr\t%4,0", op
);
10519 targetm
.asm_out
.internal_label (file
, "L",
10520 CODE_LABEL_NUMBER (op
[5]));
10523 /* Jump to target. */
10524 op
[8] = gen_label_rtx ();
10527 output_asm_insn ("l\t%4,%8-%5(%4)", op
);
10528 else if (!nonlocal
)
10529 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
10530 /* We cannot call through .plt, since .plt requires %r12 loaded. */
10531 else if (flag_pic
== 1)
10533 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
10534 output_asm_insn ("l\t%4,%0(%4)", op
);
10536 else if (flag_pic
== 2)
10538 op
[9] = gen_rtx_REG (Pmode
, 0);
10539 output_asm_insn ("l\t%9,%8-4-%5(%4)", op
);
10540 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
10541 output_asm_insn ("ar\t%4,%9", op
);
10542 output_asm_insn ("l\t%4,0(%4)", op
);
10545 output_asm_insn ("br\t%4", op
);
10547 /* Output literal pool. */
10548 output_asm_insn (".align\t4", op
);
10550 if (nonlocal
&& flag_pic
== 2)
10551 output_asm_insn (".long\t%0", op
);
10554 op
[0] = gen_rtx_SYMBOL_REF (Pmode
, "_GLOBAL_OFFSET_TABLE_");
10555 SYMBOL_REF_FLAGS (op
[0]) = SYMBOL_FLAG_LOCAL
;
10558 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[8]));
10560 output_asm_insn (".long\t%0", op
);
10562 output_asm_insn (".long\t%0-%5", op
);
10566 targetm
.asm_out
.internal_label (file
, "L",
10567 CODE_LABEL_NUMBER (op
[6]));
10568 output_asm_insn (".long\t%2", op
);
10572 targetm
.asm_out
.internal_label (file
, "L",
10573 CODE_LABEL_NUMBER (op
[7]));
10574 output_asm_insn (".long\t%3", op
);
10577 final_end_function ();
10581 s390_valid_pointer_mode (machine_mode mode
)
10583 return (mode
== SImode
|| (TARGET_64BIT
&& mode
== DImode
));
10586 /* Checks whether the given CALL_EXPR would use a caller
10587 saved register. This is used to decide whether sibling call
10588 optimization could be performed on the respective function
10592 s390_call_saved_register_used (tree call_expr
)
10594 CUMULATIVE_ARGS cum_v
;
10595 cumulative_args_t cum
;
10602 INIT_CUMULATIVE_ARGS (cum_v
, NULL
, NULL
, 0, 0);
10603 cum
= pack_cumulative_args (&cum_v
);
10605 for (i
= 0; i
< call_expr_nargs (call_expr
); i
++)
10607 parameter
= CALL_EXPR_ARG (call_expr
, i
);
10608 gcc_assert (parameter
);
10610 /* For an undeclared variable passed as parameter we will get
10611 an ERROR_MARK node here. */
10612 if (TREE_CODE (parameter
) == ERROR_MARK
)
10615 type
= TREE_TYPE (parameter
);
10618 mode
= TYPE_MODE (type
);
10621 if (pass_by_reference (&cum_v
, mode
, type
, true))
10624 type
= build_pointer_type (type
);
10627 parm_rtx
= s390_function_arg (cum
, mode
, type
, 0);
10629 s390_function_arg_advance (cum
, mode
, type
, 0);
10634 if (REG_P (parm_rtx
))
10637 reg
< HARD_REGNO_NREGS (REGNO (parm_rtx
), GET_MODE (parm_rtx
));
10639 if (!call_used_regs
[reg
+ REGNO (parm_rtx
)])
10643 if (GET_CODE (parm_rtx
) == PARALLEL
)
10647 for (i
= 0; i
< XVECLEN (parm_rtx
, 0); i
++)
10649 rtx r
= XEXP (XVECEXP (parm_rtx
, 0, i
), 0);
10651 gcc_assert (REG_P (r
));
10654 reg
< HARD_REGNO_NREGS (REGNO (r
), GET_MODE (r
));
10656 if (!call_used_regs
[reg
+ REGNO (r
)])
10665 /* Return true if the given call expression can be
10666 turned into a sibling call.
10667 DECL holds the declaration of the function to be called whereas
10668 EXP is the call expression itself. */
10671 s390_function_ok_for_sibcall (tree decl
, tree exp
)
10673 /* The TPF epilogue uses register 1. */
10674 if (TARGET_TPF_PROFILING
)
10677 /* The 31 bit PLT code uses register 12 (GOT pointer - caller saved)
10678 which would have to be restored before the sibcall. */
10679 if (!TARGET_64BIT
&& flag_pic
&& decl
&& !targetm
.binds_local_p (decl
))
10682 /* Register 6 on s390 is available as an argument register but unfortunately
10683 "caller saved". This makes functions needing this register for arguments
10684 not suitable for sibcalls. */
10685 return !s390_call_saved_register_used (exp
);
10688 /* Return the fixed registers used for condition codes. */
10691 s390_fixed_condition_code_regs (unsigned int *p1
, unsigned int *p2
)
10694 *p2
= INVALID_REGNUM
;
10699 /* This function is used by the call expanders of the machine description.
10700 It emits the call insn itself together with the necessary operations
10701 to adjust the target address and returns the emitted insn.
10702 ADDR_LOCATION is the target address rtx
10703 TLS_CALL the location of the thread-local symbol
10704 RESULT_REG the register where the result of the call should be stored
10705 RETADDR_REG the register where the return address should be stored
10706 If this parameter is NULL_RTX the call is considered
10707 to be a sibling call. */
10710 s390_emit_call (rtx addr_location
, rtx tls_call
, rtx result_reg
,
10713 bool plt_call
= false;
10719 /* Direct function calls need special treatment. */
10720 if (GET_CODE (addr_location
) == SYMBOL_REF
)
10722 /* When calling a global routine in PIC mode, we must
10723 replace the symbol itself with the PLT stub. */
10724 if (flag_pic
&& !SYMBOL_REF_LOCAL_P (addr_location
))
10726 if (retaddr_reg
!= NULL_RTX
)
10728 addr_location
= gen_rtx_UNSPEC (Pmode
,
10729 gen_rtvec (1, addr_location
),
10731 addr_location
= gen_rtx_CONST (Pmode
, addr_location
);
10735 /* For -fpic code the PLT entries might use r12 which is
10736 call-saved. Therefore we cannot do a sibcall when
10737 calling directly using a symbol ref. When reaching
10738 this point we decided (in s390_function_ok_for_sibcall)
10739 to do a sibcall for a function pointer but one of the
10740 optimizers was able to get rid of the function pointer
10741 by propagating the symbol ref into the call. This
10742 optimization is illegal for S/390 so we turn the direct
10743 call into a indirect call again. */
10744 addr_location
= force_reg (Pmode
, addr_location
);
10747 /* Unless we can use the bras(l) insn, force the
10748 routine address into a register. */
10749 if (!TARGET_SMALL_EXEC
&& !TARGET_CPU_ZARCH
)
10752 addr_location
= legitimize_pic_address (addr_location
, 0);
10754 addr_location
= force_reg (Pmode
, addr_location
);
10758 /* If it is already an indirect call or the code above moved the
10759 SYMBOL_REF to somewhere else make sure the address can be found in
10761 if (retaddr_reg
== NULL_RTX
10762 && GET_CODE (addr_location
) != SYMBOL_REF
10765 emit_move_insn (gen_rtx_REG (Pmode
, SIBCALL_REGNUM
), addr_location
);
10766 addr_location
= gen_rtx_REG (Pmode
, SIBCALL_REGNUM
);
10769 addr_location
= gen_rtx_MEM (QImode
, addr_location
);
10770 call
= gen_rtx_CALL (VOIDmode
, addr_location
, const0_rtx
);
10772 if (result_reg
!= NULL_RTX
)
10773 call
= gen_rtx_SET (VOIDmode
, result_reg
, call
);
10775 if (retaddr_reg
!= NULL_RTX
)
10777 clobber
= gen_rtx_CLOBBER (VOIDmode
, retaddr_reg
);
10779 if (tls_call
!= NULL_RTX
)
10780 vec
= gen_rtvec (3, call
, clobber
,
10781 gen_rtx_USE (VOIDmode
, tls_call
));
10783 vec
= gen_rtvec (2, call
, clobber
);
10785 call
= gen_rtx_PARALLEL (VOIDmode
, vec
);
10788 insn
= emit_call_insn (call
);
10790 /* 31-bit PLT stubs and tls calls use the GOT register implicitly. */
10791 if ((!TARGET_64BIT
&& plt_call
) || tls_call
!= NULL_RTX
)
10793 /* s390_function_ok_for_sibcall should
10794 have denied sibcalls in this case. */
10795 gcc_assert (retaddr_reg
!= NULL_RTX
);
10796 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), gen_rtx_REG (Pmode
, 12));
10801 /* Implement TARGET_CONDITIONAL_REGISTER_USAGE. */
10804 s390_conditional_register_usage (void)
10810 fixed_regs
[PIC_OFFSET_TABLE_REGNUM
] = 1;
10811 call_used_regs
[PIC_OFFSET_TABLE_REGNUM
] = 1;
10813 if (TARGET_CPU_ZARCH
)
10815 fixed_regs
[BASE_REGNUM
] = 0;
10816 call_used_regs
[BASE_REGNUM
] = 0;
10817 fixed_regs
[RETURN_REGNUM
] = 0;
10818 call_used_regs
[RETURN_REGNUM
] = 0;
10822 for (i
= FPR8_REGNUM
; i
<= FPR15_REGNUM
; i
++)
10823 call_used_regs
[i
] = call_really_used_regs
[i
] = 0;
10827 call_used_regs
[FPR4_REGNUM
] = call_really_used_regs
[FPR4_REGNUM
] = 0;
10828 call_used_regs
[FPR6_REGNUM
] = call_really_used_regs
[FPR6_REGNUM
] = 0;
10831 if (TARGET_SOFT_FLOAT
)
10833 for (i
= FPR0_REGNUM
; i
<= FPR15_REGNUM
; i
++)
10834 call_used_regs
[i
] = fixed_regs
[i
] = 1;
10838 /* Corresponding function to eh_return expander. */
10840 static GTY(()) rtx s390_tpf_eh_return_symbol
;
10842 s390_emit_tpf_eh_return (rtx target
)
10847 if (!s390_tpf_eh_return_symbol
)
10848 s390_tpf_eh_return_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "__tpf_eh_return");
10850 reg
= gen_rtx_REG (Pmode
, 2);
10851 orig_ra
= gen_rtx_REG (Pmode
, 3);
10853 emit_move_insn (reg
, target
);
10854 emit_move_insn (orig_ra
, get_hard_reg_initial_val (Pmode
, RETURN_REGNUM
));
10855 insn
= s390_emit_call (s390_tpf_eh_return_symbol
, NULL_RTX
, reg
,
10856 gen_rtx_REG (Pmode
, RETURN_REGNUM
));
10857 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), reg
);
10858 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), orig_ra
);
10860 emit_move_insn (EH_RETURN_HANDLER_RTX
, reg
);
10863 /* Rework the prologue/epilogue to avoid saving/restoring
10864 registers unnecessarily. */
10867 s390_optimize_prologue (void)
10869 rtx_insn
*insn
, *new_insn
, *next_insn
;
10871 /* Do a final recompute of the frame-related data. */
10872 s390_optimize_register_info ();
10874 /* If all special registers are in fact used, there's nothing we
10875 can do, so no point in walking the insn list. */
10877 if (cfun_frame_layout
.first_save_gpr
<= BASE_REGNUM
10878 && cfun_frame_layout
.last_save_gpr
>= BASE_REGNUM
10879 && (TARGET_CPU_ZARCH
10880 || (cfun_frame_layout
.first_save_gpr
<= RETURN_REGNUM
10881 && cfun_frame_layout
.last_save_gpr
>= RETURN_REGNUM
)))
10884 /* Search for prologue/epilogue insns and replace them. */
10886 for (insn
= get_insns (); insn
; insn
= next_insn
)
10888 int first
, last
, off
;
10889 rtx set
, base
, offset
;
10892 next_insn
= NEXT_INSN (insn
);
10894 if (! NONJUMP_INSN_P (insn
) || ! RTX_FRAME_RELATED_P (insn
))
10897 pat
= PATTERN (insn
);
10899 /* Remove ldgr/lgdr instructions used for saving and restore
10900 GPRs if possible. */
10902 && GET_CODE (pat
) == SET
10903 && GET_MODE (SET_SRC (pat
)) == DImode
10904 && REG_P (SET_SRC (pat
))
10905 && REG_P (SET_DEST (pat
)))
10907 int src_regno
= REGNO (SET_SRC (pat
));
10908 int dest_regno
= REGNO (SET_DEST (pat
));
10912 if (!((GENERAL_REGNO_P (src_regno
) && FP_REGNO_P (dest_regno
))
10913 || (FP_REGNO_P (src_regno
) && GENERAL_REGNO_P (dest_regno
))))
10916 gpr_regno
= GENERAL_REGNO_P (src_regno
) ? src_regno
: dest_regno
;
10917 fpr_regno
= FP_REGNO_P (src_regno
) ? src_regno
: dest_regno
;
10919 /* GPR must be call-saved, FPR must be call-clobbered. */
10920 if (!call_really_used_regs
[fpr_regno
]
10921 || call_really_used_regs
[gpr_regno
])
10924 /* It must not happen that what we once saved in an FPR now
10925 needs a stack slot. */
10926 gcc_assert (cfun_gpr_save_slot (gpr_regno
) != -1);
10928 if (cfun_gpr_save_slot (gpr_regno
) == 0)
10930 remove_insn (insn
);
10935 if (GET_CODE (pat
) == PARALLEL
10936 && store_multiple_operation (pat
, VOIDmode
))
10938 set
= XVECEXP (pat
, 0, 0);
10939 first
= REGNO (SET_SRC (set
));
10940 last
= first
+ XVECLEN (pat
, 0) - 1;
10941 offset
= const0_rtx
;
10942 base
= eliminate_constant_term (XEXP (SET_DEST (set
), 0), &offset
);
10943 off
= INTVAL (offset
);
10945 if (GET_CODE (base
) != REG
|| off
< 0)
10947 if (cfun_frame_layout
.first_save_gpr
!= -1
10948 && (cfun_frame_layout
.first_save_gpr
< first
10949 || cfun_frame_layout
.last_save_gpr
> last
))
10951 if (REGNO (base
) != STACK_POINTER_REGNUM
10952 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
10954 if (first
> BASE_REGNUM
|| last
< BASE_REGNUM
)
10957 if (cfun_frame_layout
.first_save_gpr
!= -1)
10959 rtx s_pat
= save_gprs (base
,
10960 off
+ (cfun_frame_layout
.first_save_gpr
10961 - first
) * UNITS_PER_LONG
,
10962 cfun_frame_layout
.first_save_gpr
,
10963 cfun_frame_layout
.last_save_gpr
);
10964 new_insn
= emit_insn_before (s_pat
, insn
);
10965 INSN_ADDRESSES_NEW (new_insn
, -1);
10968 remove_insn (insn
);
10972 if (cfun_frame_layout
.first_save_gpr
== -1
10973 && GET_CODE (pat
) == SET
10974 && GENERAL_REG_P (SET_SRC (pat
))
10975 && GET_CODE (SET_DEST (pat
)) == MEM
)
10978 first
= REGNO (SET_SRC (set
));
10979 offset
= const0_rtx
;
10980 base
= eliminate_constant_term (XEXP (SET_DEST (set
), 0), &offset
);
10981 off
= INTVAL (offset
);
10983 if (GET_CODE (base
) != REG
|| off
< 0)
10985 if (REGNO (base
) != STACK_POINTER_REGNUM
10986 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
10989 remove_insn (insn
);
10993 if (GET_CODE (pat
) == PARALLEL
10994 && load_multiple_operation (pat
, VOIDmode
))
10996 set
= XVECEXP (pat
, 0, 0);
10997 first
= REGNO (SET_DEST (set
));
10998 last
= first
+ XVECLEN (pat
, 0) - 1;
10999 offset
= const0_rtx
;
11000 base
= eliminate_constant_term (XEXP (SET_SRC (set
), 0), &offset
);
11001 off
= INTVAL (offset
);
11003 if (GET_CODE (base
) != REG
|| off
< 0)
11006 if (cfun_frame_layout
.first_restore_gpr
!= -1
11007 && (cfun_frame_layout
.first_restore_gpr
< first
11008 || cfun_frame_layout
.last_restore_gpr
> last
))
11010 if (REGNO (base
) != STACK_POINTER_REGNUM
11011 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
11013 if (first
> BASE_REGNUM
|| last
< BASE_REGNUM
)
11016 if (cfun_frame_layout
.first_restore_gpr
!= -1)
11018 rtx rpat
= restore_gprs (base
,
11019 off
+ (cfun_frame_layout
.first_restore_gpr
11020 - first
) * UNITS_PER_LONG
,
11021 cfun_frame_layout
.first_restore_gpr
,
11022 cfun_frame_layout
.last_restore_gpr
);
11024 /* Remove REG_CFA_RESTOREs for registers that we no
11025 longer need to save. */
11026 REG_NOTES (rpat
) = REG_NOTES (insn
);
11027 for (rtx
*ptr
= ®_NOTES (rpat
); *ptr
; )
11028 if (REG_NOTE_KIND (*ptr
) == REG_CFA_RESTORE
11029 && ((int) REGNO (XEXP (*ptr
, 0))
11030 < cfun_frame_layout
.first_restore_gpr
))
11031 *ptr
= XEXP (*ptr
, 1);
11033 ptr
= &XEXP (*ptr
, 1);
11034 new_insn
= emit_insn_before (rpat
, insn
);
11035 RTX_FRAME_RELATED_P (new_insn
) = 1;
11036 INSN_ADDRESSES_NEW (new_insn
, -1);
11039 remove_insn (insn
);
11043 if (cfun_frame_layout
.first_restore_gpr
== -1
11044 && GET_CODE (pat
) == SET
11045 && GENERAL_REG_P (SET_DEST (pat
))
11046 && GET_CODE (SET_SRC (pat
)) == MEM
)
11049 first
= REGNO (SET_DEST (set
));
11050 offset
= const0_rtx
;
11051 base
= eliminate_constant_term (XEXP (SET_SRC (set
), 0), &offset
);
11052 off
= INTVAL (offset
);
11054 if (GET_CODE (base
) != REG
|| off
< 0)
11057 if (REGNO (base
) != STACK_POINTER_REGNUM
11058 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
11061 remove_insn (insn
);
11067 /* On z10 and later the dynamic branch prediction must see the
11068 backward jump within a certain windows. If not it falls back to
11069 the static prediction. This function rearranges the loop backward
11070 branch in a way which makes the static prediction always correct.
11071 The function returns true if it added an instruction. */
11073 s390_fix_long_loop_prediction (rtx_insn
*insn
)
11075 rtx set
= single_set (insn
);
11076 rtx code_label
, label_ref
, new_label
;
11077 rtx_insn
*uncond_jump
;
11078 rtx_insn
*cur_insn
;
11082 /* This will exclude branch on count and branch on index patterns
11083 since these are correctly statically predicted. */
11085 || SET_DEST (set
) != pc_rtx
11086 || GET_CODE (SET_SRC(set
)) != IF_THEN_ELSE
)
11089 /* Skip conditional returns. */
11090 if (ANY_RETURN_P (XEXP (SET_SRC (set
), 1))
11091 && XEXP (SET_SRC (set
), 2) == pc_rtx
)
11094 label_ref
= (GET_CODE (XEXP (SET_SRC (set
), 1)) == LABEL_REF
?
11095 XEXP (SET_SRC (set
), 1) : XEXP (SET_SRC (set
), 2));
11097 gcc_assert (GET_CODE (label_ref
) == LABEL_REF
);
11099 code_label
= XEXP (label_ref
, 0);
11101 if (INSN_ADDRESSES (INSN_UID (code_label
)) == -1
11102 || INSN_ADDRESSES (INSN_UID (insn
)) == -1
11103 || (INSN_ADDRESSES (INSN_UID (insn
))
11104 - INSN_ADDRESSES (INSN_UID (code_label
)) < PREDICT_DISTANCE
))
11107 for (distance
= 0, cur_insn
= PREV_INSN (insn
);
11108 distance
< PREDICT_DISTANCE
- 6;
11109 distance
+= get_attr_length (cur_insn
), cur_insn
= PREV_INSN (cur_insn
))
11110 if (!cur_insn
|| JUMP_P (cur_insn
) || LABEL_P (cur_insn
))
11113 new_label
= gen_label_rtx ();
11114 uncond_jump
= emit_jump_insn_after (
11115 gen_rtx_SET (VOIDmode
, pc_rtx
,
11116 gen_rtx_LABEL_REF (VOIDmode
, code_label
)),
11118 emit_label_after (new_label
, uncond_jump
);
11120 tmp
= XEXP (SET_SRC (set
), 1);
11121 XEXP (SET_SRC (set
), 1) = XEXP (SET_SRC (set
), 2);
11122 XEXP (SET_SRC (set
), 2) = tmp
;
11123 INSN_CODE (insn
) = -1;
11125 XEXP (label_ref
, 0) = new_label
;
11126 JUMP_LABEL (insn
) = new_label
;
11127 JUMP_LABEL (uncond_jump
) = code_label
;
11132 /* Returns 1 if INSN reads the value of REG for purposes not related
11133 to addressing of memory, and 0 otherwise. */
11135 s390_non_addr_reg_read_p (rtx reg
, rtx_insn
*insn
)
11137 return reg_referenced_p (reg
, PATTERN (insn
))
11138 && !reg_used_in_mem_p (REGNO (reg
), PATTERN (insn
));
11141 /* Starting from INSN find_cond_jump looks downwards in the insn
11142 stream for a single jump insn which is the last user of the
11143 condition code set in INSN. */
11145 find_cond_jump (rtx_insn
*insn
)
11147 for (; insn
; insn
= NEXT_INSN (insn
))
11151 if (LABEL_P (insn
))
11154 if (!JUMP_P (insn
))
11156 if (reg_mentioned_p (gen_rtx_REG (CCmode
, CC_REGNUM
), insn
))
11161 /* This will be triggered by a return. */
11162 if (GET_CODE (PATTERN (insn
)) != SET
)
11165 gcc_assert (SET_DEST (PATTERN (insn
)) == pc_rtx
);
11166 ite
= SET_SRC (PATTERN (insn
));
11168 if (GET_CODE (ite
) != IF_THEN_ELSE
)
11171 cc
= XEXP (XEXP (ite
, 0), 0);
11172 if (!REG_P (cc
) || !CC_REGNO_P (REGNO (cc
)))
11175 if (find_reg_note (insn
, REG_DEAD
, cc
))
11183 /* Swap the condition in COND and the operands in OP0 and OP1 so that
11184 the semantics does not change. If NULL_RTX is passed as COND the
11185 function tries to find the conditional jump starting with INSN. */
11187 s390_swap_cmp (rtx cond
, rtx
*op0
, rtx
*op1
, rtx_insn
*insn
)
11191 if (cond
== NULL_RTX
)
11193 rtx_insn
*jump
= find_cond_jump (NEXT_INSN (insn
));
11194 rtx set
= jump
? single_set (jump
) : NULL_RTX
;
11196 if (set
== NULL_RTX
)
11199 cond
= XEXP (SET_SRC (set
), 0);
11204 PUT_CODE (cond
, swap_condition (GET_CODE (cond
)));
11207 /* On z10, instructions of the compare-and-branch family have the
11208 property to access the register occurring as second operand with
11209 its bits complemented. If such a compare is grouped with a second
11210 instruction that accesses the same register non-complemented, and
11211 if that register's value is delivered via a bypass, then the
11212 pipeline recycles, thereby causing significant performance decline.
11213 This function locates such situations and exchanges the two
11214 operands of the compare. The function return true whenever it
11217 s390_z10_optimize_cmp (rtx_insn
*insn
)
11219 rtx_insn
*prev_insn
, *next_insn
;
11220 bool insn_added_p
= false;
11221 rtx cond
, *op0
, *op1
;
11223 if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
11225 /* Handle compare and branch and branch on count
11227 rtx pattern
= single_set (insn
);
11230 || SET_DEST (pattern
) != pc_rtx
11231 || GET_CODE (SET_SRC (pattern
)) != IF_THEN_ELSE
)
11234 cond
= XEXP (SET_SRC (pattern
), 0);
11235 op0
= &XEXP (cond
, 0);
11236 op1
= &XEXP (cond
, 1);
11238 else if (GET_CODE (PATTERN (insn
)) == SET
)
11242 /* Handle normal compare instructions. */
11243 src
= SET_SRC (PATTERN (insn
));
11244 dest
= SET_DEST (PATTERN (insn
));
11247 || !CC_REGNO_P (REGNO (dest
))
11248 || GET_CODE (src
) != COMPARE
)
11251 /* s390_swap_cmp will try to find the conditional
11252 jump when passing NULL_RTX as condition. */
11254 op0
= &XEXP (src
, 0);
11255 op1
= &XEXP (src
, 1);
11260 if (!REG_P (*op0
) || !REG_P (*op1
))
11263 if (GET_MODE_CLASS (GET_MODE (*op0
)) != MODE_INT
)
11266 /* Swap the COMPARE arguments and its mask if there is a
11267 conflicting access in the previous insn. */
11268 prev_insn
= prev_active_insn (insn
);
11269 if (prev_insn
!= NULL_RTX
&& INSN_P (prev_insn
)
11270 && reg_referenced_p (*op1
, PATTERN (prev_insn
)))
11271 s390_swap_cmp (cond
, op0
, op1
, insn
);
11273 /* Check if there is a conflict with the next insn. If there
11274 was no conflict with the previous insn, then swap the
11275 COMPARE arguments and its mask. If we already swapped
11276 the operands, or if swapping them would cause a conflict
11277 with the previous insn, issue a NOP after the COMPARE in
11278 order to separate the two instuctions. */
11279 next_insn
= next_active_insn (insn
);
11280 if (next_insn
!= NULL_RTX
&& INSN_P (next_insn
)
11281 && s390_non_addr_reg_read_p (*op1
, next_insn
))
11283 if (prev_insn
!= NULL_RTX
&& INSN_P (prev_insn
)
11284 && s390_non_addr_reg_read_p (*op0
, prev_insn
))
11286 if (REGNO (*op1
) == 0)
11287 emit_insn_after (gen_nop1 (), insn
);
11289 emit_insn_after (gen_nop (), insn
);
11290 insn_added_p
= true;
11293 s390_swap_cmp (cond
, op0
, op1
, insn
);
11295 return insn_added_p
;
11298 /* Perform machine-dependent processing. */
11303 bool pool_overflow
= false;
11305 /* Make sure all splits have been performed; splits after
11306 machine_dependent_reorg might confuse insn length counts. */
11307 split_all_insns_noflow ();
11309 /* Install the main literal pool and the associated base
11310 register load insns.
11312 In addition, there are two problematic situations we need
11315 - the literal pool might be > 4096 bytes in size, so that
11316 some of its elements cannot be directly accessed
11318 - a branch target might be > 64K away from the branch, so that
11319 it is not possible to use a PC-relative instruction.
11321 To fix those, we split the single literal pool into multiple
11322 pool chunks, reloading the pool base register at various
11323 points throughout the function to ensure it always points to
11324 the pool chunk the following code expects, and / or replace
11325 PC-relative branches by absolute branches.
11327 However, the two problems are interdependent: splitting the
11328 literal pool can move a branch further away from its target,
11329 causing the 64K limit to overflow, and on the other hand,
11330 replacing a PC-relative branch by an absolute branch means
11331 we need to put the branch target address into the literal
11332 pool, possibly causing it to overflow.
11334 So, we loop trying to fix up both problems until we manage
11335 to satisfy both conditions at the same time. Note that the
11336 loop is guaranteed to terminate as every pass of the loop
11337 strictly decreases the total number of PC-relative branches
11338 in the function. (This is not completely true as there
11339 might be branch-over-pool insns introduced by chunkify_start.
11340 Those never need to be split however.) */
11344 struct constant_pool
*pool
= NULL
;
11346 /* Collect the literal pool. */
11347 if (!pool_overflow
)
11349 pool
= s390_mainpool_start ();
11351 pool_overflow
= true;
11354 /* If literal pool overflowed, start to chunkify it. */
11356 pool
= s390_chunkify_start ();
11358 /* Split out-of-range branches. If this has created new
11359 literal pool entries, cancel current chunk list and
11360 recompute it. zSeries machines have large branch
11361 instructions, so we never need to split a branch. */
11362 if (!TARGET_CPU_ZARCH
&& s390_split_branches ())
11365 s390_chunkify_cancel (pool
);
11367 s390_mainpool_cancel (pool
);
11372 /* If we made it up to here, both conditions are satisfied.
11373 Finish up literal pool related changes. */
11375 s390_chunkify_finish (pool
);
11377 s390_mainpool_finish (pool
);
11379 /* We're done splitting branches. */
11380 cfun
->machine
->split_branches_pending_p
= false;
11384 /* Generate out-of-pool execute target insns. */
11385 if (TARGET_CPU_ZARCH
)
11387 rtx_insn
*insn
, *target
;
11390 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
11392 label
= s390_execute_label (insn
);
11396 gcc_assert (label
!= const0_rtx
);
11398 target
= emit_label (XEXP (label
, 0));
11399 INSN_ADDRESSES_NEW (target
, -1);
11401 target
= emit_insn (s390_execute_target (insn
));
11402 INSN_ADDRESSES_NEW (target
, -1);
11406 /* Try to optimize prologue and epilogue further. */
11407 s390_optimize_prologue ();
11409 /* Walk over the insns and do some >=z10 specific changes. */
11410 if (s390_tune
== PROCESSOR_2097_Z10
11411 || s390_tune
== PROCESSOR_2817_Z196
11412 || s390_tune
== PROCESSOR_2827_ZEC12
)
11415 bool insn_added_p
= false;
11417 /* The insn lengths and addresses have to be up to date for the
11418 following manipulations. */
11419 shorten_branches (get_insns ());
11421 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
11423 if (!INSN_P (insn
) || INSN_CODE (insn
) <= 0)
11427 insn_added_p
|= s390_fix_long_loop_prediction (insn
);
11429 if ((GET_CODE (PATTERN (insn
)) == PARALLEL
11430 || GET_CODE (PATTERN (insn
)) == SET
)
11431 && s390_tune
== PROCESSOR_2097_Z10
)
11432 insn_added_p
|= s390_z10_optimize_cmp (insn
);
11435 /* Adjust branches if we added new instructions. */
11437 shorten_branches (get_insns ());
11441 /* Return true if INSN is a fp load insn writing register REGNO. */
11443 s390_fpload_toreg (rtx_insn
*insn
, unsigned int regno
)
11446 enum attr_type flag
= s390_safe_attr_type (insn
);
11448 if (flag
!= TYPE_FLOADSF
&& flag
!= TYPE_FLOADDF
)
11451 set
= single_set (insn
);
11453 if (set
== NULL_RTX
)
11456 if (!REG_P (SET_DEST (set
)) || !MEM_P (SET_SRC (set
)))
11459 if (REGNO (SET_DEST (set
)) != regno
)
11465 /* This value describes the distance to be avoided between an
11466 aritmetic fp instruction and an fp load writing the same register.
11467 Z10_EARLYLOAD_DISTANCE - 1 as well as Z10_EARLYLOAD_DISTANCE + 1 is
11468 fine but the exact value has to be avoided. Otherwise the FP
11469 pipeline will throw an exception causing a major penalty. */
11470 #define Z10_EARLYLOAD_DISTANCE 7
11472 /* Rearrange the ready list in order to avoid the situation described
11473 for Z10_EARLYLOAD_DISTANCE. A problematic load instruction is
11474 moved to the very end of the ready list. */
11476 s390_z10_prevent_earlyload_conflicts (rtx_insn
**ready
, int *nready_p
)
11478 unsigned int regno
;
11479 int nready
= *nready_p
;
11484 enum attr_type flag
;
11487 /* Skip DISTANCE - 1 active insns. */
11488 for (insn
= last_scheduled_insn
, distance
= Z10_EARLYLOAD_DISTANCE
- 1;
11489 distance
> 0 && insn
!= NULL_RTX
;
11490 distance
--, insn
= prev_active_insn (insn
))
11491 if (CALL_P (insn
) || JUMP_P (insn
))
11494 if (insn
== NULL_RTX
)
11497 set
= single_set (insn
);
11499 if (set
== NULL_RTX
|| !REG_P (SET_DEST (set
))
11500 || GET_MODE_CLASS (GET_MODE (SET_DEST (set
))) != MODE_FLOAT
)
11503 flag
= s390_safe_attr_type (insn
);
11505 if (flag
== TYPE_FLOADSF
|| flag
== TYPE_FLOADDF
)
11508 regno
= REGNO (SET_DEST (set
));
11511 while (!s390_fpload_toreg (ready
[i
], regno
) && i
> 0)
11518 memmove (&ready
[1], &ready
[0], sizeof (rtx_insn
*) * i
);
11523 /* The s390_sched_state variable tracks the state of the current or
11524 the last instruction group.
11526 0,1,2 number of instructions scheduled in the current group
11527 3 the last group is complete - normal insns
11528 4 the last group was a cracked/expanded insn */
11530 static int s390_sched_state
;
11532 #define S390_OOO_SCHED_STATE_NORMAL 3
11533 #define S390_OOO_SCHED_STATE_CRACKED 4
11535 #define S390_OOO_SCHED_ATTR_MASK_CRACKED 0x1
11536 #define S390_OOO_SCHED_ATTR_MASK_EXPANDED 0x2
11537 #define S390_OOO_SCHED_ATTR_MASK_ENDGROUP 0x4
11538 #define S390_OOO_SCHED_ATTR_MASK_GROUPALONE 0x8
11540 static unsigned int
11541 s390_get_sched_attrmask (rtx_insn
*insn
)
11543 unsigned int mask
= 0;
11545 if (get_attr_ooo_cracked (insn
))
11546 mask
|= S390_OOO_SCHED_ATTR_MASK_CRACKED
;
11547 if (get_attr_ooo_expanded (insn
))
11548 mask
|= S390_OOO_SCHED_ATTR_MASK_EXPANDED
;
11549 if (get_attr_ooo_endgroup (insn
))
11550 mask
|= S390_OOO_SCHED_ATTR_MASK_ENDGROUP
;
11551 if (get_attr_ooo_groupalone (insn
))
11552 mask
|= S390_OOO_SCHED_ATTR_MASK_GROUPALONE
;
11556 /* Return the scheduling score for INSN. The higher the score the
11557 better. The score is calculated from the OOO scheduling attributes
11558 of INSN and the scheduling state s390_sched_state. */
11560 s390_sched_score (rtx_insn
*insn
)
11562 unsigned int mask
= s390_get_sched_attrmask (insn
);
11565 switch (s390_sched_state
)
11568 /* Try to put insns into the first slot which would otherwise
11570 if ((mask
& S390_OOO_SCHED_ATTR_MASK_CRACKED
) != 0
11571 || (mask
& S390_OOO_SCHED_ATTR_MASK_EXPANDED
) != 0)
11573 if ((mask
& S390_OOO_SCHED_ATTR_MASK_GROUPALONE
) != 0)
11576 /* Prefer not cracked insns while trying to put together a
11578 if ((mask
& S390_OOO_SCHED_ATTR_MASK_CRACKED
) == 0
11579 && (mask
& S390_OOO_SCHED_ATTR_MASK_EXPANDED
) == 0
11580 && (mask
& S390_OOO_SCHED_ATTR_MASK_GROUPALONE
) == 0)
11582 if ((mask
& S390_OOO_SCHED_ATTR_MASK_ENDGROUP
) == 0)
11586 /* Prefer not cracked insns while trying to put together a
11588 if ((mask
& S390_OOO_SCHED_ATTR_MASK_CRACKED
) == 0
11589 && (mask
& S390_OOO_SCHED_ATTR_MASK_EXPANDED
) == 0
11590 && (mask
& S390_OOO_SCHED_ATTR_MASK_GROUPALONE
) == 0)
11592 /* Prefer endgroup insns in the last slot. */
11593 if ((mask
& S390_OOO_SCHED_ATTR_MASK_ENDGROUP
) != 0)
11596 case S390_OOO_SCHED_STATE_NORMAL
:
11597 /* Prefer not cracked insns if the last was not cracked. */
11598 if ((mask
& S390_OOO_SCHED_ATTR_MASK_CRACKED
) == 0
11599 && (mask
& S390_OOO_SCHED_ATTR_MASK_EXPANDED
) == 0)
11601 if ((mask
& S390_OOO_SCHED_ATTR_MASK_GROUPALONE
) != 0)
11604 case S390_OOO_SCHED_STATE_CRACKED
:
11605 /* Try to keep cracked insns together to prevent them from
11606 interrupting groups. */
11607 if ((mask
& S390_OOO_SCHED_ATTR_MASK_CRACKED
) != 0
11608 || (mask
& S390_OOO_SCHED_ATTR_MASK_EXPANDED
) != 0)
11615 /* This function is called via hook TARGET_SCHED_REORDER before
11616 issuing one insn from list READY which contains *NREADYP entries.
11617 For target z10 it reorders load instructions to avoid early load
11618 conflicts in the floating point pipeline */
11620 s390_sched_reorder (FILE *file
, int verbose
,
11621 rtx_insn
**ready
, int *nreadyp
, int clock ATTRIBUTE_UNUSED
)
11623 if (s390_tune
== PROCESSOR_2097_Z10
)
11624 if (reload_completed
&& *nreadyp
> 1)
11625 s390_z10_prevent_earlyload_conflicts (ready
, nreadyp
);
11627 if (s390_tune
== PROCESSOR_2827_ZEC12
11628 && reload_completed
11632 int last_index
= *nreadyp
- 1;
11633 int max_index
= -1;
11634 int max_score
= -1;
11637 /* Just move the insn with the highest score to the top (the
11638 end) of the list. A full sort is not needed since a conflict
11639 in the hazard recognition cannot happen. So the top insn in
11640 the ready list will always be taken. */
11641 for (i
= last_index
; i
>= 0; i
--)
11645 if (recog_memoized (ready
[i
]) < 0)
11648 score
= s390_sched_score (ready
[i
]);
11649 if (score
> max_score
)
11656 if (max_index
!= -1)
11658 if (max_index
!= last_index
)
11660 tmp
= ready
[max_index
];
11661 ready
[max_index
] = ready
[last_index
];
11662 ready
[last_index
] = tmp
;
11666 "move insn %d to the top of list\n",
11667 INSN_UID (ready
[last_index
]));
11669 else if (verbose
> 5)
11671 "best insn %d already on top\n",
11672 INSN_UID (ready
[last_index
]));
11677 fprintf (file
, "ready list ooo attributes - sched state: %d\n",
11680 for (i
= last_index
; i
>= 0; i
--)
11682 if (recog_memoized (ready
[i
]) < 0)
11684 fprintf (file
, "insn %d score: %d: ", INSN_UID (ready
[i
]),
11685 s390_sched_score (ready
[i
]));
11686 #define PRINT_OOO_ATTR(ATTR) fprintf (file, "%s ", get_attr_##ATTR (ready[i]) ? #ATTR : "!" #ATTR);
11687 PRINT_OOO_ATTR (ooo_cracked
);
11688 PRINT_OOO_ATTR (ooo_expanded
);
11689 PRINT_OOO_ATTR (ooo_endgroup
);
11690 PRINT_OOO_ATTR (ooo_groupalone
);
11691 #undef PRINT_OOO_ATTR
11692 fprintf (file
, "\n");
11697 return s390_issue_rate ();
11701 /* This function is called via hook TARGET_SCHED_VARIABLE_ISSUE after
11702 the scheduler has issued INSN. It stores the last issued insn into
11703 last_scheduled_insn in order to make it available for
11704 s390_sched_reorder. */
11706 s390_sched_variable_issue (FILE *file
, int verbose
, rtx_insn
*insn
, int more
)
11708 last_scheduled_insn
= insn
;
11710 if (s390_tune
== PROCESSOR_2827_ZEC12
11711 && reload_completed
11712 && recog_memoized (insn
) >= 0)
11714 unsigned int mask
= s390_get_sched_attrmask (insn
);
11716 if ((mask
& S390_OOO_SCHED_ATTR_MASK_CRACKED
) != 0
11717 || (mask
& S390_OOO_SCHED_ATTR_MASK_EXPANDED
) != 0)
11718 s390_sched_state
= S390_OOO_SCHED_STATE_CRACKED
;
11719 else if ((mask
& S390_OOO_SCHED_ATTR_MASK_ENDGROUP
) != 0
11720 || (mask
& S390_OOO_SCHED_ATTR_MASK_GROUPALONE
) != 0)
11721 s390_sched_state
= S390_OOO_SCHED_STATE_NORMAL
;
11724 /* Only normal insns are left (mask == 0). */
11725 switch (s390_sched_state
)
11730 case S390_OOO_SCHED_STATE_NORMAL
:
11731 if (s390_sched_state
== S390_OOO_SCHED_STATE_NORMAL
)
11732 s390_sched_state
= 1;
11734 s390_sched_state
++;
11737 case S390_OOO_SCHED_STATE_CRACKED
:
11738 s390_sched_state
= S390_OOO_SCHED_STATE_NORMAL
;
11744 fprintf (file
, "insn %d: ", INSN_UID (insn
));
11745 #define PRINT_OOO_ATTR(ATTR) \
11746 fprintf (file, "%s ", get_attr_##ATTR (insn) ? #ATTR : "");
11747 PRINT_OOO_ATTR (ooo_cracked
);
11748 PRINT_OOO_ATTR (ooo_expanded
);
11749 PRINT_OOO_ATTR (ooo_endgroup
);
11750 PRINT_OOO_ATTR (ooo_groupalone
);
11751 #undef PRINT_OOO_ATTR
11752 fprintf (file
, "\n");
11753 fprintf (file
, "sched state: %d\n", s390_sched_state
);
11757 if (GET_CODE (PATTERN (insn
)) != USE
11758 && GET_CODE (PATTERN (insn
)) != CLOBBER
)
11765 s390_sched_init (FILE *file ATTRIBUTE_UNUSED
,
11766 int verbose ATTRIBUTE_UNUSED
,
11767 int max_ready ATTRIBUTE_UNUSED
)
11769 last_scheduled_insn
= NULL
;
11770 s390_sched_state
= 0;
11773 /* This target hook implementation for TARGET_LOOP_UNROLL_ADJUST calculates
11774 a new number struct loop *loop should be unrolled if tuned for cpus with
11775 a built-in stride prefetcher.
11776 The loop is analyzed for memory accesses by calling check_dpu for
11777 each rtx of the loop. Depending on the loop_depth and the amount of
11778 memory accesses a new number <=nunroll is returned to improve the
11779 behaviour of the hardware prefetch unit. */
11781 s390_loop_unroll_adjust (unsigned nunroll
, struct loop
*loop
)
11786 unsigned mem_count
= 0;
11788 if (s390_tune
!= PROCESSOR_2097_Z10
11789 && s390_tune
!= PROCESSOR_2817_Z196
11790 && s390_tune
!= PROCESSOR_2827_ZEC12
)
11793 /* Count the number of memory references within the loop body. */
11794 bbs
= get_loop_body (loop
);
11795 subrtx_iterator::array_type array
;
11796 for (i
= 0; i
< loop
->num_nodes
; i
++)
11797 FOR_BB_INSNS (bbs
[i
], insn
)
11798 if (INSN_P (insn
) && INSN_CODE (insn
) != -1)
11799 FOR_EACH_SUBRTX (iter
, array
, PATTERN (insn
), NONCONST
)
11804 /* Prevent division by zero, and we do not need to adjust nunroll in this case. */
11805 if (mem_count
== 0)
11808 switch (loop_depth(loop
))
11811 return MIN (nunroll
, 28 / mem_count
);
11813 return MIN (nunroll
, 22 / mem_count
);
11815 return MIN (nunroll
, 16 / mem_count
);
11820 s390_option_override (void)
11823 cl_deferred_option
*opt
;
11824 vec
<cl_deferred_option
> *v
=
11825 (vec
<cl_deferred_option
> *) s390_deferred_options
;
11828 FOR_EACH_VEC_ELT (*v
, i
, opt
)
11830 switch (opt
->opt_index
)
11832 case OPT_mhotpatch
:
11833 s390_hotpatch_trampoline_halfwords
= (opt
->value
) ?
11834 s390_hotpatch_trampoline_halfwords_default
: -1;
11836 case OPT_mhotpatch_
:
11840 val
= integral_argument (opt
->arg
);
11843 /* argument is not a plain number */
11844 error ("argument to %qs should be a non-negative integer",
11848 else if (val
> s390_hotpatch_trampoline_halfwords_max
)
11850 error ("argument to %qs is too large (max. %d)",
11851 "-mhotpatch=", s390_hotpatch_trampoline_halfwords_max
);
11854 s390_hotpatch_trampoline_halfwords
= val
;
11858 gcc_unreachable ();
11862 /* Set up function hooks. */
11863 init_machine_status
= s390_init_machine_status
;
11865 /* Architecture mode defaults according to ABI. */
11866 if (!(target_flags_explicit
& MASK_ZARCH
))
11869 target_flags
|= MASK_ZARCH
;
11871 target_flags
&= ~MASK_ZARCH
;
11874 /* Set the march default in case it hasn't been specified on
11876 if (s390_arch
== PROCESSOR_max
)
11878 s390_arch_string
= TARGET_ZARCH
? "z900" : "g5";
11879 s390_arch
= TARGET_ZARCH
? PROCESSOR_2064_Z900
: PROCESSOR_9672_G5
;
11880 s390_arch_flags
= processor_flags_table
[(int)s390_arch
];
11883 /* Determine processor to tune for. */
11884 if (s390_tune
== PROCESSOR_max
)
11886 s390_tune
= s390_arch
;
11887 s390_tune_flags
= s390_arch_flags
;
11890 /* Sanity checks. */
11891 if (TARGET_ZARCH
&& !TARGET_CPU_ZARCH
)
11892 error ("z/Architecture mode not supported on %s", s390_arch_string
);
11893 if (TARGET_64BIT
&& !TARGET_ZARCH
)
11894 error ("64-bit ABI not supported in ESA/390 mode");
11896 /* Use hardware DFP if available and not explicitly disabled by
11897 user. E.g. with -m31 -march=z10 -mzarch */
11898 if (!(target_flags_explicit
& MASK_HARD_DFP
) && TARGET_DFP
)
11899 target_flags
|= MASK_HARD_DFP
;
11901 /* Enable hardware transactions if available and not explicitly
11902 disabled by user. E.g. with -m31 -march=zEC12 -mzarch */
11903 if (!(target_flags_explicit
& MASK_OPT_HTM
) && TARGET_CPU_HTM
&& TARGET_ZARCH
)
11904 target_flags
|= MASK_OPT_HTM
;
11906 if (TARGET_HARD_DFP
&& !TARGET_DFP
)
11908 if (target_flags_explicit
& MASK_HARD_DFP
)
11910 if (!TARGET_CPU_DFP
)
11911 error ("hardware decimal floating point instructions"
11912 " not available on %s", s390_arch_string
);
11914 error ("hardware decimal floating point instructions"
11915 " not available in ESA/390 mode");
11918 target_flags
&= ~MASK_HARD_DFP
;
11921 if ((target_flags_explicit
& MASK_SOFT_FLOAT
) && TARGET_SOFT_FLOAT
)
11923 if ((target_flags_explicit
& MASK_HARD_DFP
) && TARGET_HARD_DFP
)
11924 error ("-mhard-dfp can%'t be used in conjunction with -msoft-float");
11926 target_flags
&= ~MASK_HARD_DFP
;
11929 /* Set processor cost function. */
11932 case PROCESSOR_2084_Z990
:
11933 s390_cost
= &z990_cost
;
11935 case PROCESSOR_2094_Z9_109
:
11936 s390_cost
= &z9_109_cost
;
11938 case PROCESSOR_2097_Z10
:
11939 s390_cost
= &z10_cost
;
11941 case PROCESSOR_2817_Z196
:
11942 s390_cost
= &z196_cost
;
11944 case PROCESSOR_2827_ZEC12
:
11945 s390_cost
= &zEC12_cost
;
11948 s390_cost
= &z900_cost
;
11951 if (TARGET_BACKCHAIN
&& TARGET_PACKED_STACK
&& TARGET_HARD_FLOAT
)
11952 error ("-mbackchain -mpacked-stack -mhard-float are not supported "
11955 if (s390_stack_size
)
11957 if (s390_stack_guard
>= s390_stack_size
)
11958 error ("stack size must be greater than the stack guard value");
11959 else if (s390_stack_size
> 1 << 16)
11960 error ("stack size must not be greater than 64k");
11962 else if (s390_stack_guard
)
11963 error ("-mstack-guard implies use of -mstack-size");
11965 #ifdef TARGET_DEFAULT_LONG_DOUBLE_128
11966 if (!(target_flags_explicit
& MASK_LONG_DOUBLE_128
))
11967 target_flags
|= MASK_LONG_DOUBLE_128
;
11970 if (s390_tune
== PROCESSOR_2097_Z10
11971 || s390_tune
== PROCESSOR_2817_Z196
11972 || s390_tune
== PROCESSOR_2827_ZEC12
)
11974 maybe_set_param_value (PARAM_MAX_UNROLLED_INSNS
, 100,
11975 global_options
.x_param_values
,
11976 global_options_set
.x_param_values
);
11977 maybe_set_param_value (PARAM_MAX_UNROLL_TIMES
, 32,
11978 global_options
.x_param_values
,
11979 global_options_set
.x_param_values
);
11980 maybe_set_param_value (PARAM_MAX_COMPLETELY_PEELED_INSNS
, 2000,
11981 global_options
.x_param_values
,
11982 global_options_set
.x_param_values
);
11983 maybe_set_param_value (PARAM_MAX_COMPLETELY_PEEL_TIMES
, 64,
11984 global_options
.x_param_values
,
11985 global_options_set
.x_param_values
);
11988 maybe_set_param_value (PARAM_MAX_PENDING_LIST_LENGTH
, 256,
11989 global_options
.x_param_values
,
11990 global_options_set
.x_param_values
);
11991 /* values for loop prefetching */
11992 maybe_set_param_value (PARAM_L1_CACHE_LINE_SIZE
, 256,
11993 global_options
.x_param_values
,
11994 global_options_set
.x_param_values
);
11995 maybe_set_param_value (PARAM_L1_CACHE_SIZE
, 128,
11996 global_options
.x_param_values
,
11997 global_options_set
.x_param_values
);
11998 /* s390 has more than 2 levels and the size is much larger. Since
11999 we are always running virtualized assume that we only get a small
12000 part of the caches above l1. */
12001 maybe_set_param_value (PARAM_L2_CACHE_SIZE
, 1500,
12002 global_options
.x_param_values
,
12003 global_options_set
.x_param_values
);
12004 maybe_set_param_value (PARAM_PREFETCH_MIN_INSN_TO_MEM_RATIO
, 2,
12005 global_options
.x_param_values
,
12006 global_options_set
.x_param_values
);
12007 maybe_set_param_value (PARAM_SIMULTANEOUS_PREFETCHES
, 6,
12008 global_options
.x_param_values
,
12009 global_options_set
.x_param_values
);
12011 /* This cannot reside in s390_option_optimization_table since HAVE_prefetch
12012 requires the arch flags to be evaluated already. Since prefetching
12013 is beneficial on s390, we enable it if available. */
12014 if (flag_prefetch_loop_arrays
< 0 && HAVE_prefetch
&& optimize
>= 3)
12015 flag_prefetch_loop_arrays
= 1;
12017 /* Use the alternative scheduling-pressure algorithm by default. */
12018 maybe_set_param_value (PARAM_SCHED_PRESSURE_ALGORITHM
, 2,
12019 global_options
.x_param_values
,
12020 global_options_set
.x_param_values
);
12024 /* Don't emit DWARF3/4 unless specifically selected. The TPF
12025 debuggers do not yet support DWARF 3/4. */
12026 if (!global_options_set
.x_dwarf_strict
)
12028 if (!global_options_set
.x_dwarf_version
)
12032 /* Register a target-specific optimization-and-lowering pass
12033 to run immediately before prologue and epilogue generation.
12035 Registering the pass must be done at start up. It's
12036 convenient to do it here. */
12037 opt_pass
*new_pass
= new pass_s390_early_mach (g
);
12038 struct register_pass_info insert_pass_s390_early_mach
=
12040 new_pass
, /* pass */
12041 "pro_and_epilogue", /* reference_pass_name */
12042 1, /* ref_pass_instance_number */
12043 PASS_POS_INSERT_BEFORE
/* po_op */
12045 register_pass (&insert_pass_s390_early_mach
);
12048 /* Implement TARGET_USE_BY_PIECES_INFRASTRUCTURE_P. */
12051 s390_use_by_pieces_infrastructure_p (unsigned HOST_WIDE_INT size
,
12052 unsigned int align ATTRIBUTE_UNUSED
,
12053 enum by_pieces_operation op ATTRIBUTE_UNUSED
,
12054 bool speed_p ATTRIBUTE_UNUSED
)
12056 return (size
== 1 || size
== 2
12057 || size
== 4 || (TARGET_ZARCH
&& size
== 8));
12060 /* Initialize GCC target structure. */
12062 #undef TARGET_ASM_ALIGNED_HI_OP
12063 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
12064 #undef TARGET_ASM_ALIGNED_DI_OP
12065 #define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
12066 #undef TARGET_ASM_INTEGER
12067 #define TARGET_ASM_INTEGER s390_assemble_integer
12069 #undef TARGET_ASM_OPEN_PAREN
12070 #define TARGET_ASM_OPEN_PAREN ""
12072 #undef TARGET_ASM_CLOSE_PAREN
12073 #define TARGET_ASM_CLOSE_PAREN ""
12075 #undef TARGET_OPTION_OVERRIDE
12076 #define TARGET_OPTION_OVERRIDE s390_option_override
12078 #undef TARGET_ENCODE_SECTION_INFO
12079 #define TARGET_ENCODE_SECTION_INFO s390_encode_section_info
12081 #undef TARGET_SCALAR_MODE_SUPPORTED_P
12082 #define TARGET_SCALAR_MODE_SUPPORTED_P s390_scalar_mode_supported_p
12085 #undef TARGET_HAVE_TLS
12086 #define TARGET_HAVE_TLS true
12088 #undef TARGET_CANNOT_FORCE_CONST_MEM
12089 #define TARGET_CANNOT_FORCE_CONST_MEM s390_cannot_force_const_mem
12091 #undef TARGET_DELEGITIMIZE_ADDRESS
12092 #define TARGET_DELEGITIMIZE_ADDRESS s390_delegitimize_address
12094 #undef TARGET_LEGITIMIZE_ADDRESS
12095 #define TARGET_LEGITIMIZE_ADDRESS s390_legitimize_address
12097 #undef TARGET_RETURN_IN_MEMORY
12098 #define TARGET_RETURN_IN_MEMORY s390_return_in_memory
12100 #undef TARGET_INIT_BUILTINS
12101 #define TARGET_INIT_BUILTINS s390_init_builtins
12102 #undef TARGET_EXPAND_BUILTIN
12103 #define TARGET_EXPAND_BUILTIN s390_expand_builtin
12105 #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA
12106 #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA s390_output_addr_const_extra
12108 #undef TARGET_ASM_OUTPUT_MI_THUNK
12109 #define TARGET_ASM_OUTPUT_MI_THUNK s390_output_mi_thunk
12110 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
12111 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_const_tree_hwi_hwi_const_tree_true
12113 #undef TARGET_SCHED_ADJUST_PRIORITY
12114 #define TARGET_SCHED_ADJUST_PRIORITY s390_adjust_priority
12115 #undef TARGET_SCHED_ISSUE_RATE
12116 #define TARGET_SCHED_ISSUE_RATE s390_issue_rate
12117 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
12118 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD s390_first_cycle_multipass_dfa_lookahead
12120 #undef TARGET_SCHED_VARIABLE_ISSUE
12121 #define TARGET_SCHED_VARIABLE_ISSUE s390_sched_variable_issue
12122 #undef TARGET_SCHED_REORDER
12123 #define TARGET_SCHED_REORDER s390_sched_reorder
12124 #undef TARGET_SCHED_INIT
12125 #define TARGET_SCHED_INIT s390_sched_init
12127 #undef TARGET_CANNOT_COPY_INSN_P
12128 #define TARGET_CANNOT_COPY_INSN_P s390_cannot_copy_insn_p
12129 #undef TARGET_RTX_COSTS
12130 #define TARGET_RTX_COSTS s390_rtx_costs
12131 #undef TARGET_ADDRESS_COST
12132 #define TARGET_ADDRESS_COST s390_address_cost
12133 #undef TARGET_REGISTER_MOVE_COST
12134 #define TARGET_REGISTER_MOVE_COST s390_register_move_cost
12135 #undef TARGET_MEMORY_MOVE_COST
12136 #define TARGET_MEMORY_MOVE_COST s390_memory_move_cost
12138 #undef TARGET_MACHINE_DEPENDENT_REORG
12139 #define TARGET_MACHINE_DEPENDENT_REORG s390_reorg
12141 #undef TARGET_VALID_POINTER_MODE
12142 #define TARGET_VALID_POINTER_MODE s390_valid_pointer_mode
12144 #undef TARGET_BUILD_BUILTIN_VA_LIST
12145 #define TARGET_BUILD_BUILTIN_VA_LIST s390_build_builtin_va_list
12146 #undef TARGET_EXPAND_BUILTIN_VA_START
12147 #define TARGET_EXPAND_BUILTIN_VA_START s390_va_start
12148 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
12149 #define TARGET_GIMPLIFY_VA_ARG_EXPR s390_gimplify_va_arg
12151 #undef TARGET_PROMOTE_FUNCTION_MODE
12152 #define TARGET_PROMOTE_FUNCTION_MODE s390_promote_function_mode
12153 #undef TARGET_PASS_BY_REFERENCE
12154 #define TARGET_PASS_BY_REFERENCE s390_pass_by_reference
12156 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
12157 #define TARGET_FUNCTION_OK_FOR_SIBCALL s390_function_ok_for_sibcall
12158 #undef TARGET_FUNCTION_ARG
12159 #define TARGET_FUNCTION_ARG s390_function_arg
12160 #undef TARGET_FUNCTION_ARG_ADVANCE
12161 #define TARGET_FUNCTION_ARG_ADVANCE s390_function_arg_advance
12162 #undef TARGET_FUNCTION_VALUE
12163 #define TARGET_FUNCTION_VALUE s390_function_value
12164 #undef TARGET_LIBCALL_VALUE
12165 #define TARGET_LIBCALL_VALUE s390_libcall_value
12167 #undef TARGET_KEEP_LEAF_WHEN_PROFILED
12168 #define TARGET_KEEP_LEAF_WHEN_PROFILED s390_keep_leaf_when_profiled
12170 #undef TARGET_FIXED_CONDITION_CODE_REGS
12171 #define TARGET_FIXED_CONDITION_CODE_REGS s390_fixed_condition_code_regs
12173 #undef TARGET_CC_MODES_COMPATIBLE
12174 #define TARGET_CC_MODES_COMPATIBLE s390_cc_modes_compatible
12176 #undef TARGET_INVALID_WITHIN_DOLOOP
12177 #define TARGET_INVALID_WITHIN_DOLOOP hook_constcharptr_const_rtx_insn_null
12180 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
12181 #define TARGET_ASM_OUTPUT_DWARF_DTPREL s390_output_dwarf_dtprel
12184 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
12185 #undef TARGET_MANGLE_TYPE
12186 #define TARGET_MANGLE_TYPE s390_mangle_type
12189 #undef TARGET_SCALAR_MODE_SUPPORTED_P
12190 #define TARGET_SCALAR_MODE_SUPPORTED_P s390_scalar_mode_supported_p
12192 #undef TARGET_PREFERRED_RELOAD_CLASS
12193 #define TARGET_PREFERRED_RELOAD_CLASS s390_preferred_reload_class
12195 #undef TARGET_SECONDARY_RELOAD
12196 #define TARGET_SECONDARY_RELOAD s390_secondary_reload
12198 #undef TARGET_LIBGCC_CMP_RETURN_MODE
12199 #define TARGET_LIBGCC_CMP_RETURN_MODE s390_libgcc_cmp_return_mode
12201 #undef TARGET_LIBGCC_SHIFT_COUNT_MODE
12202 #define TARGET_LIBGCC_SHIFT_COUNT_MODE s390_libgcc_shift_count_mode
12204 #undef TARGET_LEGITIMATE_ADDRESS_P
12205 #define TARGET_LEGITIMATE_ADDRESS_P s390_legitimate_address_p
12207 #undef TARGET_LEGITIMATE_CONSTANT_P
12208 #define TARGET_LEGITIMATE_CONSTANT_P s390_legitimate_constant_p
12210 #undef TARGET_LRA_P
12211 #define TARGET_LRA_P s390_lra_p
12213 #undef TARGET_CAN_ELIMINATE
12214 #define TARGET_CAN_ELIMINATE s390_can_eliminate
12216 #undef TARGET_CONDITIONAL_REGISTER_USAGE
12217 #define TARGET_CONDITIONAL_REGISTER_USAGE s390_conditional_register_usage
12219 #undef TARGET_LOOP_UNROLL_ADJUST
12220 #define TARGET_LOOP_UNROLL_ADJUST s390_loop_unroll_adjust
12222 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
12223 #define TARGET_ASM_TRAMPOLINE_TEMPLATE s390_asm_trampoline_template
12224 #undef TARGET_TRAMPOLINE_INIT
12225 #define TARGET_TRAMPOLINE_INIT s390_trampoline_init
12227 #undef TARGET_UNWIND_WORD_MODE
12228 #define TARGET_UNWIND_WORD_MODE s390_unwind_word_mode
12230 #undef TARGET_CANONICALIZE_COMPARISON
12231 #define TARGET_CANONICALIZE_COMPARISON s390_canonicalize_comparison
12233 #undef TARGET_HARD_REGNO_SCRATCH_OK
12234 #define TARGET_HARD_REGNO_SCRATCH_OK s390_hard_regno_scratch_ok
12236 #undef TARGET_ATTRIBUTE_TABLE
12237 #define TARGET_ATTRIBUTE_TABLE s390_attribute_table
12239 #undef TARGET_CAN_INLINE_P
12240 #define TARGET_CAN_INLINE_P s390_can_inline_p
12242 #undef TARGET_SET_UP_BY_PROLOGUE
12243 #define TARGET_SET_UP_BY_PROLOGUE s300_set_up_by_prologue
12245 #undef TARGET_USE_BY_PIECES_INFRASTRUCTURE_P
12246 #define TARGET_USE_BY_PIECES_INFRASTRUCTURE_P \
12247 s390_use_by_pieces_infrastructure_p
12249 struct gcc_target targetm
= TARGET_INITIALIZER
;
12251 #include "gt-s390.h"