1 /* Subroutines used for code generation on IBM S/390 and zSeries
2 Copyright (C) 1999-2014 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"
29 #include "print-tree.h"
30 #include "stringpool.h"
31 #include "stor-layout.h"
36 #include "hard-reg-set.h"
37 #include "insn-config.h"
38 #include "conditions.h"
40 #include "insn-attr.h"
52 #include "diagnostic-core.h"
53 #include "basic-block.h"
56 #include "target-def.h"
58 #include "langhooks.h"
60 #include "hash-table.h"
61 #include "basic-block.h"
62 #include "tree-ssa-alias.h"
63 #include "internal-fn.h"
64 #include "gimple-fold.h"
66 #include "gimple-expr.h"
74 #include "tree-pass.h"
78 /* Define the specific costs for a given cpu. */
80 struct processor_costs
83 const int m
; /* cost of an M instruction. */
84 const int mghi
; /* cost of an MGHI instruction. */
85 const int mh
; /* cost of an MH instruction. */
86 const int mhi
; /* cost of an MHI instruction. */
87 const int ml
; /* cost of an ML instruction. */
88 const int mr
; /* cost of an MR instruction. */
89 const int ms
; /* cost of an MS instruction. */
90 const int msg
; /* cost of an MSG instruction. */
91 const int msgf
; /* cost of an MSGF instruction. */
92 const int msgfr
; /* cost of an MSGFR instruction. */
93 const int msgr
; /* cost of an MSGR instruction. */
94 const int msr
; /* cost of an MSR instruction. */
95 const int mult_df
; /* cost of multiplication in DFmode. */
98 const int sqxbr
; /* cost of square root in TFmode. */
99 const int sqdbr
; /* cost of square root in DFmode. */
100 const int sqebr
; /* cost of square root in SFmode. */
101 /* multiply and add */
102 const int madbr
; /* cost of multiply and add in DFmode. */
103 const int maebr
; /* cost of multiply and add in SFmode. */
115 const struct processor_costs
*s390_cost
;
118 struct processor_costs z900_cost
=
120 COSTS_N_INSNS (5), /* M */
121 COSTS_N_INSNS (10), /* MGHI */
122 COSTS_N_INSNS (5), /* MH */
123 COSTS_N_INSNS (4), /* MHI */
124 COSTS_N_INSNS (5), /* ML */
125 COSTS_N_INSNS (5), /* MR */
126 COSTS_N_INSNS (4), /* MS */
127 COSTS_N_INSNS (15), /* MSG */
128 COSTS_N_INSNS (7), /* MSGF */
129 COSTS_N_INSNS (7), /* MSGFR */
130 COSTS_N_INSNS (10), /* MSGR */
131 COSTS_N_INSNS (4), /* MSR */
132 COSTS_N_INSNS (7), /* multiplication in DFmode */
133 COSTS_N_INSNS (13), /* MXBR */
134 COSTS_N_INSNS (136), /* SQXBR */
135 COSTS_N_INSNS (44), /* SQDBR */
136 COSTS_N_INSNS (35), /* SQEBR */
137 COSTS_N_INSNS (18), /* MADBR */
138 COSTS_N_INSNS (13), /* MAEBR */
139 COSTS_N_INSNS (134), /* DXBR */
140 COSTS_N_INSNS (30), /* DDBR */
141 COSTS_N_INSNS (27), /* DEBR */
142 COSTS_N_INSNS (220), /* DLGR */
143 COSTS_N_INSNS (34), /* DLR */
144 COSTS_N_INSNS (34), /* DR */
145 COSTS_N_INSNS (32), /* DSGFR */
146 COSTS_N_INSNS (32), /* DSGR */
150 struct processor_costs z990_cost
=
152 COSTS_N_INSNS (4), /* M */
153 COSTS_N_INSNS (2), /* MGHI */
154 COSTS_N_INSNS (2), /* MH */
155 COSTS_N_INSNS (2), /* MHI */
156 COSTS_N_INSNS (4), /* ML */
157 COSTS_N_INSNS (4), /* MR */
158 COSTS_N_INSNS (5), /* MS */
159 COSTS_N_INSNS (6), /* MSG */
160 COSTS_N_INSNS (4), /* MSGF */
161 COSTS_N_INSNS (4), /* MSGFR */
162 COSTS_N_INSNS (4), /* MSGR */
163 COSTS_N_INSNS (4), /* MSR */
164 COSTS_N_INSNS (1), /* multiplication in DFmode */
165 COSTS_N_INSNS (28), /* MXBR */
166 COSTS_N_INSNS (130), /* SQXBR */
167 COSTS_N_INSNS (66), /* SQDBR */
168 COSTS_N_INSNS (38), /* SQEBR */
169 COSTS_N_INSNS (1), /* MADBR */
170 COSTS_N_INSNS (1), /* MAEBR */
171 COSTS_N_INSNS (60), /* DXBR */
172 COSTS_N_INSNS (40), /* DDBR */
173 COSTS_N_INSNS (26), /* DEBR */
174 COSTS_N_INSNS (176), /* DLGR */
175 COSTS_N_INSNS (31), /* DLR */
176 COSTS_N_INSNS (31), /* DR */
177 COSTS_N_INSNS (31), /* DSGFR */
178 COSTS_N_INSNS (31), /* DSGR */
182 struct processor_costs z9_109_cost
=
184 COSTS_N_INSNS (4), /* M */
185 COSTS_N_INSNS (2), /* MGHI */
186 COSTS_N_INSNS (2), /* MH */
187 COSTS_N_INSNS (2), /* MHI */
188 COSTS_N_INSNS (4), /* ML */
189 COSTS_N_INSNS (4), /* MR */
190 COSTS_N_INSNS (5), /* MS */
191 COSTS_N_INSNS (6), /* MSG */
192 COSTS_N_INSNS (4), /* MSGF */
193 COSTS_N_INSNS (4), /* MSGFR */
194 COSTS_N_INSNS (4), /* MSGR */
195 COSTS_N_INSNS (4), /* MSR */
196 COSTS_N_INSNS (1), /* multiplication in DFmode */
197 COSTS_N_INSNS (28), /* MXBR */
198 COSTS_N_INSNS (130), /* SQXBR */
199 COSTS_N_INSNS (66), /* SQDBR */
200 COSTS_N_INSNS (38), /* SQEBR */
201 COSTS_N_INSNS (1), /* MADBR */
202 COSTS_N_INSNS (1), /* MAEBR */
203 COSTS_N_INSNS (60), /* DXBR */
204 COSTS_N_INSNS (40), /* DDBR */
205 COSTS_N_INSNS (26), /* DEBR */
206 COSTS_N_INSNS (30), /* DLGR */
207 COSTS_N_INSNS (23), /* DLR */
208 COSTS_N_INSNS (23), /* DR */
209 COSTS_N_INSNS (24), /* DSGFR */
210 COSTS_N_INSNS (24), /* DSGR */
214 struct processor_costs z10_cost
=
216 COSTS_N_INSNS (10), /* M */
217 COSTS_N_INSNS (10), /* MGHI */
218 COSTS_N_INSNS (10), /* MH */
219 COSTS_N_INSNS (10), /* MHI */
220 COSTS_N_INSNS (10), /* ML */
221 COSTS_N_INSNS (10), /* MR */
222 COSTS_N_INSNS (10), /* MS */
223 COSTS_N_INSNS (10), /* MSG */
224 COSTS_N_INSNS (10), /* MSGF */
225 COSTS_N_INSNS (10), /* MSGFR */
226 COSTS_N_INSNS (10), /* MSGR */
227 COSTS_N_INSNS (10), /* MSR */
228 COSTS_N_INSNS (1) , /* multiplication in DFmode */
229 COSTS_N_INSNS (50), /* MXBR */
230 COSTS_N_INSNS (120), /* SQXBR */
231 COSTS_N_INSNS (52), /* SQDBR */
232 COSTS_N_INSNS (38), /* SQEBR */
233 COSTS_N_INSNS (1), /* MADBR */
234 COSTS_N_INSNS (1), /* MAEBR */
235 COSTS_N_INSNS (111), /* DXBR */
236 COSTS_N_INSNS (39), /* DDBR */
237 COSTS_N_INSNS (32), /* DEBR */
238 COSTS_N_INSNS (160), /* DLGR */
239 COSTS_N_INSNS (71), /* DLR */
240 COSTS_N_INSNS (71), /* DR */
241 COSTS_N_INSNS (71), /* DSGFR */
242 COSTS_N_INSNS (71), /* DSGR */
246 struct processor_costs z196_cost
=
248 COSTS_N_INSNS (7), /* M */
249 COSTS_N_INSNS (5), /* MGHI */
250 COSTS_N_INSNS (5), /* MH */
251 COSTS_N_INSNS (5), /* MHI */
252 COSTS_N_INSNS (7), /* ML */
253 COSTS_N_INSNS (7), /* MR */
254 COSTS_N_INSNS (6), /* MS */
255 COSTS_N_INSNS (8), /* MSG */
256 COSTS_N_INSNS (6), /* MSGF */
257 COSTS_N_INSNS (6), /* MSGFR */
258 COSTS_N_INSNS (8), /* MSGR */
259 COSTS_N_INSNS (6), /* MSR */
260 COSTS_N_INSNS (1) , /* multiplication in DFmode */
261 COSTS_N_INSNS (40), /* MXBR B+40 */
262 COSTS_N_INSNS (100), /* SQXBR B+100 */
263 COSTS_N_INSNS (42), /* SQDBR B+42 */
264 COSTS_N_INSNS (28), /* SQEBR B+28 */
265 COSTS_N_INSNS (1), /* MADBR B */
266 COSTS_N_INSNS (1), /* MAEBR B */
267 COSTS_N_INSNS (101), /* DXBR B+101 */
268 COSTS_N_INSNS (29), /* DDBR */
269 COSTS_N_INSNS (22), /* DEBR */
270 COSTS_N_INSNS (160), /* DLGR cracked */
271 COSTS_N_INSNS (160), /* DLR cracked */
272 COSTS_N_INSNS (160), /* DR expanded */
273 COSTS_N_INSNS (160), /* DSGFR cracked */
274 COSTS_N_INSNS (160), /* DSGR cracked */
278 struct processor_costs zEC12_cost
=
280 COSTS_N_INSNS (7), /* M */
281 COSTS_N_INSNS (5), /* MGHI */
282 COSTS_N_INSNS (5), /* MH */
283 COSTS_N_INSNS (5), /* MHI */
284 COSTS_N_INSNS (7), /* ML */
285 COSTS_N_INSNS (7), /* MR */
286 COSTS_N_INSNS (6), /* MS */
287 COSTS_N_INSNS (8), /* MSG */
288 COSTS_N_INSNS (6), /* MSGF */
289 COSTS_N_INSNS (6), /* MSGFR */
290 COSTS_N_INSNS (8), /* MSGR */
291 COSTS_N_INSNS (6), /* MSR */
292 COSTS_N_INSNS (1) , /* multiplication in DFmode */
293 COSTS_N_INSNS (40), /* MXBR B+40 */
294 COSTS_N_INSNS (100), /* SQXBR B+100 */
295 COSTS_N_INSNS (42), /* SQDBR B+42 */
296 COSTS_N_INSNS (28), /* SQEBR B+28 */
297 COSTS_N_INSNS (1), /* MADBR B */
298 COSTS_N_INSNS (1), /* MAEBR B */
299 COSTS_N_INSNS (131), /* DXBR B+131 */
300 COSTS_N_INSNS (29), /* DDBR */
301 COSTS_N_INSNS (22), /* DEBR */
302 COSTS_N_INSNS (160), /* DLGR cracked */
303 COSTS_N_INSNS (160), /* DLR cracked */
304 COSTS_N_INSNS (160), /* DR expanded */
305 COSTS_N_INSNS (160), /* DSGFR cracked */
306 COSTS_N_INSNS (160), /* DSGR cracked */
309 extern int reload_completed
;
311 /* Kept up to date using the SCHED_VARIABLE_ISSUE hook. */
312 static rtx_insn
*last_scheduled_insn
;
314 /* Structure used to hold the components of a S/390 memory
315 address. A legitimate address on S/390 is of the general
317 base + index + displacement
318 where any of the components is optional.
320 base and index are registers of the class ADDR_REGS,
321 displacement is an unsigned 12-bit immediate constant. */
332 /* The following structure is embedded in the machine
333 specific part of struct function. */
335 struct GTY (()) s390_frame_layout
337 /* Offset within stack frame. */
338 HOST_WIDE_INT gprs_offset
;
339 HOST_WIDE_INT f0_offset
;
340 HOST_WIDE_INT f4_offset
;
341 HOST_WIDE_INT f8_offset
;
342 HOST_WIDE_INT backchain_offset
;
344 /* Number of first and last gpr where slots in the register
345 save area are reserved for. */
346 int first_save_gpr_slot
;
347 int last_save_gpr_slot
;
349 /* Location (FP register number) where GPRs (r0-r15) should
351 0 - does not need to be saved at all
353 signed char gpr_save_slots
[16];
355 /* Number of first and last gpr to be saved, restored. */
357 int first_restore_gpr
;
359 int last_restore_gpr
;
361 /* Bits standing for floating point registers. Set, if the
362 respective register has to be saved. Starting with reg 16 (f0)
363 at the rightmost bit.
364 Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
365 fpr 15 13 11 9 14 12 10 8 7 5 3 1 6 4 2 0
366 reg 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 */
367 unsigned int fpr_bitmap
;
369 /* Number of floating point registers f8-f15 which must be saved. */
372 /* Set if return address needs to be saved.
373 This flag is set by s390_return_addr_rtx if it could not use
374 the initial value of r14 and therefore depends on r14 saved
376 bool save_return_addr_p
;
378 /* Size of stack frame. */
379 HOST_WIDE_INT frame_size
;
382 /* Define the structure for the machine field in struct function. */
384 struct GTY(()) machine_function
386 struct s390_frame_layout frame_layout
;
388 /* Literal pool base register. */
391 /* True if we may need to perform branch splitting. */
392 bool split_branches_pending_p
;
394 bool has_landing_pad_p
;
396 /* True if the current function may contain a tbegin clobbering
401 /* Few accessor macros for struct cfun->machine->s390_frame_layout. */
403 #define cfun_frame_layout (cfun->machine->frame_layout)
404 #define cfun_save_high_fprs_p (!!cfun_frame_layout.high_fprs)
405 #define cfun_save_arg_fprs_p (!!(TARGET_64BIT \
406 ? cfun_frame_layout.fpr_bitmap & 0x0f \
407 : cfun_frame_layout.fpr_bitmap & 0x03))
408 #define cfun_gprs_save_area_size ((cfun_frame_layout.last_save_gpr_slot - \
409 cfun_frame_layout.first_save_gpr_slot + 1) * UNITS_PER_LONG)
410 #define cfun_set_fpr_save(REGNO) (cfun->machine->frame_layout.fpr_bitmap |= \
411 (1 << (REGNO - FPR0_REGNUM)))
412 #define cfun_fpr_save_p(REGNO) (!!(cfun->machine->frame_layout.fpr_bitmap & \
413 (1 << (REGNO - FPR0_REGNUM))))
414 #define cfun_gpr_save_slot(REGNO) \
415 cfun->machine->frame_layout.gpr_save_slots[REGNO]
417 /* Number of GPRs and FPRs used for argument passing. */
418 #define GP_ARG_NUM_REG 5
419 #define FP_ARG_NUM_REG (TARGET_64BIT? 4 : 2)
421 /* A couple of shortcuts. */
422 #define CONST_OK_FOR_J(x) \
423 CONST_OK_FOR_CONSTRAINT_P((x), 'J', "J")
424 #define CONST_OK_FOR_K(x) \
425 CONST_OK_FOR_CONSTRAINT_P((x), 'K', "K")
426 #define CONST_OK_FOR_Os(x) \
427 CONST_OK_FOR_CONSTRAINT_P((x), 'O', "Os")
428 #define CONST_OK_FOR_Op(x) \
429 CONST_OK_FOR_CONSTRAINT_P((x), 'O', "Op")
430 #define CONST_OK_FOR_On(x) \
431 CONST_OK_FOR_CONSTRAINT_P((x), 'O', "On")
433 #define REGNO_PAIR_OK(REGNO, MODE) \
434 (HARD_REGNO_NREGS ((REGNO), (MODE)) == 1 || !((REGNO) & 1))
436 /* That's the read ahead of the dynamic branch prediction unit in
437 bytes on a z10 (or higher) CPU. */
438 #define PREDICT_DISTANCE (TARGET_Z10 ? 384 : 2048)
440 static const int s390_hotpatch_trampoline_halfwords_default
= 12;
441 static const int s390_hotpatch_trampoline_halfwords_max
= 1000000;
442 static int s390_hotpatch_trampoline_halfwords
= -1;
444 /* Return the argument of the given hotpatch attribute or the default value if
445 no argument is present. */
448 get_hotpatch_attribute (tree hotpatch_attr
)
452 args
= TREE_VALUE (hotpatch_attr
);
455 TREE_INT_CST_LOW (TREE_VALUE (args
)):
456 s390_hotpatch_trampoline_halfwords_default
;
459 /* Check whether the hotpatch attribute is applied to a function and, if it has
460 an argument, the argument is valid. */
463 s390_handle_hotpatch_attribute (tree
*node
, tree name
, tree args
,
464 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
466 if (TREE_CODE (*node
) != FUNCTION_DECL
)
468 warning (OPT_Wattributes
, "%qE attribute only applies to functions",
470 *no_add_attrs
= true;
474 tree expr
= TREE_VALUE (args
);
476 if (TREE_CODE (expr
) != INTEGER_CST
477 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
))
478 || wi::gtu_p (expr
, s390_hotpatch_trampoline_halfwords_max
))
480 error ("requested %qE attribute is not a non-negative integer"
481 " constant or too large (max. %d)", name
,
482 s390_hotpatch_trampoline_halfwords_max
);
483 *no_add_attrs
= true;
490 static const struct attribute_spec s390_attribute_table
[] = {
491 { "hotpatch", 0, 1, true, false, false, s390_handle_hotpatch_attribute
, false
494 { NULL
, 0, 0, false, false, false, NULL
, false }
497 /* Return the alignment for LABEL. We default to the -falign-labels
498 value except for the literal pool base label. */
500 s390_label_align (rtx label
)
502 rtx_insn
*prev_insn
= prev_active_insn (label
);
505 if (prev_insn
== NULL_RTX
)
508 set
= single_set (prev_insn
);
515 /* Don't align literal pool base labels. */
516 if (GET_CODE (src
) == UNSPEC
517 && XINT (src
, 1) == UNSPEC_MAIN_BASE
)
521 return align_labels_log
;
524 static enum machine_mode
525 s390_libgcc_cmp_return_mode (void)
527 return TARGET_64BIT
? DImode
: SImode
;
530 static enum machine_mode
531 s390_libgcc_shift_count_mode (void)
533 return TARGET_64BIT
? DImode
: SImode
;
536 static enum machine_mode
537 s390_unwind_word_mode (void)
539 return TARGET_64BIT
? DImode
: SImode
;
542 /* Return true if the back end supports mode MODE. */
544 s390_scalar_mode_supported_p (enum machine_mode mode
)
546 /* In contrast to the default implementation reject TImode constants on 31bit
547 TARGET_ZARCH for ABI compliance. */
548 if (!TARGET_64BIT
&& TARGET_ZARCH
&& mode
== TImode
)
551 if (DECIMAL_FLOAT_MODE_P (mode
))
552 return default_decimal_float_supported_p ();
554 return default_scalar_mode_supported_p (mode
);
557 /* Set the has_landing_pad_p flag in struct machine_function to VALUE. */
560 s390_set_has_landing_pad_p (bool value
)
562 cfun
->machine
->has_landing_pad_p
= value
;
565 /* If two condition code modes are compatible, return a condition code
566 mode which is compatible with both. Otherwise, return
569 static enum machine_mode
570 s390_cc_modes_compatible (enum machine_mode m1
, enum machine_mode m2
)
578 if (m2
== CCUmode
|| m2
== CCTmode
|| m2
== CCZ1mode
579 || m2
== CCSmode
|| m2
== CCSRmode
|| m2
== CCURmode
)
600 /* Return true if SET either doesn't set the CC register, or else
601 the source and destination have matching CC modes and that
602 CC mode is at least as constrained as REQ_MODE. */
605 s390_match_ccmode_set (rtx set
, enum machine_mode req_mode
)
607 enum machine_mode set_mode
;
609 gcc_assert (GET_CODE (set
) == SET
);
611 if (GET_CODE (SET_DEST (set
)) != REG
|| !CC_REGNO_P (REGNO (SET_DEST (set
))))
614 set_mode
= GET_MODE (SET_DEST (set
));
628 if (req_mode
!= set_mode
)
633 if (req_mode
!= CCSmode
&& req_mode
!= CCUmode
&& req_mode
!= CCTmode
634 && req_mode
!= CCSRmode
&& req_mode
!= CCURmode
)
640 if (req_mode
!= CCAmode
)
648 return (GET_MODE (SET_SRC (set
)) == set_mode
);
651 /* Return true if every SET in INSN that sets the CC register
652 has source and destination with matching CC modes and that
653 CC mode is at least as constrained as REQ_MODE.
654 If REQ_MODE is VOIDmode, always return false. */
657 s390_match_ccmode (rtx_insn
*insn
, enum machine_mode req_mode
)
661 /* s390_tm_ccmode returns VOIDmode to indicate failure. */
662 if (req_mode
== VOIDmode
)
665 if (GET_CODE (PATTERN (insn
)) == SET
)
666 return s390_match_ccmode_set (PATTERN (insn
), req_mode
);
668 if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
669 for (i
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
671 rtx set
= XVECEXP (PATTERN (insn
), 0, i
);
672 if (GET_CODE (set
) == SET
)
673 if (!s390_match_ccmode_set (set
, req_mode
))
680 /* If a test-under-mask instruction can be used to implement
681 (compare (and ... OP1) OP2), return the CC mode required
682 to do that. Otherwise, return VOIDmode.
683 MIXED is true if the instruction can distinguish between
684 CC1 and CC2 for mixed selected bits (TMxx), it is false
685 if the instruction cannot (TM). */
688 s390_tm_ccmode (rtx op1
, rtx op2
, bool mixed
)
692 /* ??? Fixme: should work on CONST_DOUBLE as well. */
693 if (GET_CODE (op1
) != CONST_INT
|| GET_CODE (op2
) != CONST_INT
)
696 /* Selected bits all zero: CC0.
697 e.g.: int a; if ((a & (16 + 128)) == 0) */
698 if (INTVAL (op2
) == 0)
701 /* Selected bits all one: CC3.
702 e.g.: int a; if ((a & (16 + 128)) == 16 + 128) */
703 if (INTVAL (op2
) == INTVAL (op1
))
706 /* Exactly two bits selected, mixed zeroes and ones: CC1 or CC2. e.g.:
708 if ((a & (16 + 128)) == 16) -> CCT1
709 if ((a & (16 + 128)) == 128) -> CCT2 */
712 bit1
= exact_log2 (INTVAL (op2
));
713 bit0
= exact_log2 (INTVAL (op1
) ^ INTVAL (op2
));
714 if (bit0
!= -1 && bit1
!= -1)
715 return bit0
> bit1
? CCT1mode
: CCT2mode
;
721 /* Given a comparison code OP (EQ, NE, etc.) and the operands
722 OP0 and OP1 of a COMPARE, return the mode to be used for the
726 s390_select_ccmode (enum rtx_code code
, rtx op0
, rtx op1
)
732 if ((GET_CODE (op0
) == NEG
|| GET_CODE (op0
) == ABS
)
733 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
735 if (GET_CODE (op0
) == PLUS
&& GET_CODE (XEXP (op0
, 1)) == CONST_INT
736 && CONST_OK_FOR_K (INTVAL (XEXP (op0
, 1))))
738 if ((GET_CODE (op0
) == PLUS
|| GET_CODE (op0
) == MINUS
739 || GET_CODE (op1
) == NEG
)
740 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
743 if (GET_CODE (op0
) == AND
)
745 /* Check whether we can potentially do it via TM. */
746 enum machine_mode ccmode
;
747 ccmode
= s390_tm_ccmode (XEXP (op0
, 1), op1
, 1);
748 if (ccmode
!= VOIDmode
)
750 /* Relax CCTmode to CCZmode to allow fall-back to AND
751 if that turns out to be beneficial. */
752 return ccmode
== CCTmode
? CCZmode
: ccmode
;
756 if (register_operand (op0
, HImode
)
757 && GET_CODE (op1
) == CONST_INT
758 && (INTVAL (op1
) == -1 || INTVAL (op1
) == 65535))
760 if (register_operand (op0
, QImode
)
761 && GET_CODE (op1
) == CONST_INT
762 && (INTVAL (op1
) == -1 || INTVAL (op1
) == 255))
771 /* The only overflow condition of NEG and ABS happens when
772 -INT_MAX is used as parameter, which stays negative. So
773 we have an overflow from a positive value to a negative.
774 Using CCAP mode the resulting cc can be used for comparisons. */
775 if ((GET_CODE (op0
) == NEG
|| GET_CODE (op0
) == ABS
)
776 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
779 /* If constants are involved in an add instruction it is possible to use
780 the resulting cc for comparisons with zero. Knowing the sign of the
781 constant the overflow behavior gets predictable. e.g.:
782 int a, b; if ((b = a + c) > 0)
783 with c as a constant value: c < 0 -> CCAN and c >= 0 -> CCAP */
784 if (GET_CODE (op0
) == PLUS
&& GET_CODE (XEXP (op0
, 1)) == CONST_INT
785 && (CONST_OK_FOR_K (INTVAL (XEXP (op0
, 1)))
786 || (CONST_OK_FOR_CONSTRAINT_P (INTVAL (XEXP (op0
, 1)), 'O', "Os")
787 /* Avoid INT32_MIN on 32 bit. */
788 && (!TARGET_ZARCH
|| INTVAL (XEXP (op0
, 1)) != -0x7fffffff - 1))))
790 if (INTVAL (XEXP((op0
), 1)) < 0)
804 if ((GET_CODE (op0
) == SIGN_EXTEND
|| GET_CODE (op0
) == ZERO_EXTEND
)
805 && GET_CODE (op1
) != CONST_INT
)
811 if (GET_CODE (op0
) == PLUS
812 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
815 if ((GET_CODE (op0
) == SIGN_EXTEND
|| GET_CODE (op0
) == ZERO_EXTEND
)
816 && GET_CODE (op1
) != CONST_INT
)
822 if (GET_CODE (op0
) == MINUS
823 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
826 if ((GET_CODE (op0
) == SIGN_EXTEND
|| GET_CODE (op0
) == ZERO_EXTEND
)
827 && GET_CODE (op1
) != CONST_INT
)
836 /* Replace the comparison OP0 CODE OP1 by a semantically equivalent one
837 that we can implement more efficiently. */
840 s390_canonicalize_comparison (int *code
, rtx
*op0
, rtx
*op1
,
841 bool op0_preserve_value
)
843 if (op0_preserve_value
)
846 /* Convert ZERO_EXTRACT back to AND to enable TM patterns. */
847 if ((*code
== EQ
|| *code
== NE
)
848 && *op1
== const0_rtx
849 && GET_CODE (*op0
) == ZERO_EXTRACT
850 && GET_CODE (XEXP (*op0
, 1)) == CONST_INT
851 && GET_CODE (XEXP (*op0
, 2)) == CONST_INT
852 && SCALAR_INT_MODE_P (GET_MODE (XEXP (*op0
, 0))))
854 rtx inner
= XEXP (*op0
, 0);
855 HOST_WIDE_INT modesize
= GET_MODE_BITSIZE (GET_MODE (inner
));
856 HOST_WIDE_INT len
= INTVAL (XEXP (*op0
, 1));
857 HOST_WIDE_INT pos
= INTVAL (XEXP (*op0
, 2));
859 if (len
> 0 && len
< modesize
860 && pos
>= 0 && pos
+ len
<= modesize
861 && modesize
<= HOST_BITS_PER_WIDE_INT
)
863 unsigned HOST_WIDE_INT block
;
864 block
= ((unsigned HOST_WIDE_INT
) 1 << len
) - 1;
865 block
<<= modesize
- pos
- len
;
867 *op0
= gen_rtx_AND (GET_MODE (inner
), inner
,
868 gen_int_mode (block
, GET_MODE (inner
)));
872 /* Narrow AND of memory against immediate to enable TM. */
873 if ((*code
== EQ
|| *code
== NE
)
874 && *op1
== const0_rtx
875 && GET_CODE (*op0
) == AND
876 && GET_CODE (XEXP (*op0
, 1)) == CONST_INT
877 && SCALAR_INT_MODE_P (GET_MODE (XEXP (*op0
, 0))))
879 rtx inner
= XEXP (*op0
, 0);
880 rtx mask
= XEXP (*op0
, 1);
882 /* Ignore paradoxical SUBREGs if all extra bits are masked out. */
883 if (GET_CODE (inner
) == SUBREG
884 && SCALAR_INT_MODE_P (GET_MODE (SUBREG_REG (inner
)))
885 && (GET_MODE_SIZE (GET_MODE (inner
))
886 >= GET_MODE_SIZE (GET_MODE (SUBREG_REG (inner
))))
888 & GET_MODE_MASK (GET_MODE (inner
))
889 & ~GET_MODE_MASK (GET_MODE (SUBREG_REG (inner
))))
891 inner
= SUBREG_REG (inner
);
893 /* Do not change volatile MEMs. */
894 if (MEM_P (inner
) && !MEM_VOLATILE_P (inner
))
896 int part
= s390_single_part (XEXP (*op0
, 1),
897 GET_MODE (inner
), QImode
, 0);
900 mask
= gen_int_mode (s390_extract_part (mask
, QImode
, 0), QImode
);
901 inner
= adjust_address_nv (inner
, QImode
, part
);
902 *op0
= gen_rtx_AND (QImode
, inner
, mask
);
907 /* Narrow comparisons against 0xffff to HImode if possible. */
908 if ((*code
== EQ
|| *code
== NE
)
909 && GET_CODE (*op1
) == CONST_INT
910 && INTVAL (*op1
) == 0xffff
911 && SCALAR_INT_MODE_P (GET_MODE (*op0
))
912 && (nonzero_bits (*op0
, GET_MODE (*op0
))
913 & ~(unsigned HOST_WIDE_INT
) 0xffff) == 0)
915 *op0
= gen_lowpart (HImode
, *op0
);
919 /* Remove redundant UNSPEC_STRCMPCC_TO_INT conversions if possible. */
920 if (GET_CODE (*op0
) == UNSPEC
921 && XINT (*op0
, 1) == UNSPEC_STRCMPCC_TO_INT
922 && XVECLEN (*op0
, 0) == 1
923 && GET_MODE (XVECEXP (*op0
, 0, 0)) == CCUmode
924 && GET_CODE (XVECEXP (*op0
, 0, 0)) == REG
925 && REGNO (XVECEXP (*op0
, 0, 0)) == CC_REGNUM
926 && *op1
== const0_rtx
)
928 enum rtx_code new_code
= UNKNOWN
;
931 case EQ
: new_code
= EQ
; break;
932 case NE
: new_code
= NE
; break;
933 case LT
: new_code
= GTU
; break;
934 case GT
: new_code
= LTU
; break;
935 case LE
: new_code
= GEU
; break;
936 case GE
: new_code
= LEU
; break;
940 if (new_code
!= UNKNOWN
)
942 *op0
= XVECEXP (*op0
, 0, 0);
947 /* Remove redundant UNSPEC_CC_TO_INT conversions if possible. */
948 if (GET_CODE (*op0
) == UNSPEC
949 && XINT (*op0
, 1) == UNSPEC_CC_TO_INT
950 && XVECLEN (*op0
, 0) == 1
951 && GET_CODE (XVECEXP (*op0
, 0, 0)) == REG
952 && REGNO (XVECEXP (*op0
, 0, 0)) == CC_REGNUM
953 && CONST_INT_P (*op1
))
955 enum rtx_code new_code
= UNKNOWN
;
956 switch (GET_MODE (XVECEXP (*op0
, 0, 0)))
962 case EQ
: new_code
= EQ
; break;
963 case NE
: new_code
= NE
; break;
970 if (new_code
!= UNKNOWN
)
972 /* For CCRAWmode put the required cc mask into the second
974 if (GET_MODE (XVECEXP (*op0
, 0, 0)) == CCRAWmode
975 && INTVAL (*op1
) >= 0 && INTVAL (*op1
) <= 3)
976 *op1
= gen_rtx_CONST_INT (VOIDmode
, 1 << (3 - INTVAL (*op1
)));
977 *op0
= XVECEXP (*op0
, 0, 0);
982 /* Simplify cascaded EQ, NE with const0_rtx. */
983 if ((*code
== NE
|| *code
== EQ
)
984 && (GET_CODE (*op0
) == EQ
|| GET_CODE (*op0
) == NE
)
985 && GET_MODE (*op0
) == SImode
986 && GET_MODE (XEXP (*op0
, 0)) == CCZ1mode
987 && REG_P (XEXP (*op0
, 0))
988 && XEXP (*op0
, 1) == const0_rtx
989 && *op1
== const0_rtx
)
991 if ((*code
== EQ
&& GET_CODE (*op0
) == NE
)
992 || (*code
== NE
&& GET_CODE (*op0
) == EQ
))
996 *op0
= XEXP (*op0
, 0);
999 /* Prefer register over memory as first operand. */
1000 if (MEM_P (*op0
) && REG_P (*op1
))
1002 rtx tem
= *op0
; *op0
= *op1
; *op1
= tem
;
1003 *code
= (int)swap_condition ((enum rtx_code
)*code
);
1007 /* Emit a compare instruction suitable to implement the comparison
1008 OP0 CODE OP1. Return the correct condition RTL to be placed in
1009 the IF_THEN_ELSE of the conditional branch testing the result. */
1012 s390_emit_compare (enum rtx_code code
, rtx op0
, rtx op1
)
1014 enum machine_mode mode
= s390_select_ccmode (code
, op0
, op1
);
1017 /* Do not output a redundant compare instruction if a compare_and_swap
1018 pattern already computed the result and the machine modes are compatible. */
1019 if (GET_MODE_CLASS (GET_MODE (op0
)) == MODE_CC
)
1021 gcc_assert (s390_cc_modes_compatible (GET_MODE (op0
), mode
)
1027 cc
= gen_rtx_REG (mode
, CC_REGNUM
);
1028 emit_insn (gen_rtx_SET (VOIDmode
, cc
, gen_rtx_COMPARE (mode
, op0
, op1
)));
1031 return gen_rtx_fmt_ee (code
, VOIDmode
, cc
, const0_rtx
);
1034 /* Emit a SImode compare and swap instruction setting MEM to NEW_RTX if OLD
1036 Return the correct condition RTL to be placed in the IF_THEN_ELSE of the
1037 conditional branch testing the result. */
1040 s390_emit_compare_and_swap (enum rtx_code code
, rtx old
, rtx mem
,
1041 rtx cmp
, rtx new_rtx
)
1043 emit_insn (gen_atomic_compare_and_swapsi_internal (old
, mem
, cmp
, new_rtx
));
1044 return s390_emit_compare (code
, gen_rtx_REG (CCZ1mode
, CC_REGNUM
),
1048 /* Emit a jump instruction to TARGET and return it. If COND is
1049 NULL_RTX, emit an unconditional jump, else a conditional jump under
1053 s390_emit_jump (rtx target
, rtx cond
)
1057 target
= gen_rtx_LABEL_REF (VOIDmode
, target
);
1059 target
= gen_rtx_IF_THEN_ELSE (VOIDmode
, cond
, target
, pc_rtx
);
1061 insn
= gen_rtx_SET (VOIDmode
, pc_rtx
, target
);
1062 return emit_jump_insn (insn
);
1065 /* Return branch condition mask to implement a branch
1066 specified by CODE. Return -1 for invalid comparisons. */
1069 s390_branch_condition_mask (rtx code
)
1071 const int CC0
= 1 << 3;
1072 const int CC1
= 1 << 2;
1073 const int CC2
= 1 << 1;
1074 const int CC3
= 1 << 0;
1076 gcc_assert (GET_CODE (XEXP (code
, 0)) == REG
);
1077 gcc_assert (REGNO (XEXP (code
, 0)) == CC_REGNUM
);
1078 gcc_assert (XEXP (code
, 1) == const0_rtx
1079 || (GET_MODE (XEXP (code
, 0)) == CCRAWmode
1080 && CONST_INT_P (XEXP (code
, 1))));
1083 switch (GET_MODE (XEXP (code
, 0)))
1087 switch (GET_CODE (code
))
1089 case EQ
: return CC0
;
1090 case NE
: return CC1
| CC2
| CC3
;
1096 switch (GET_CODE (code
))
1098 case EQ
: return CC1
;
1099 case NE
: return CC0
| CC2
| CC3
;
1105 switch (GET_CODE (code
))
1107 case EQ
: return CC2
;
1108 case NE
: return CC0
| CC1
| CC3
;
1114 switch (GET_CODE (code
))
1116 case EQ
: return CC3
;
1117 case NE
: return CC0
| CC1
| CC2
;
1123 switch (GET_CODE (code
))
1125 case EQ
: return CC0
| CC2
;
1126 case NE
: return CC1
| CC3
;
1132 switch (GET_CODE (code
))
1134 case LTU
: return CC2
| CC3
; /* carry */
1135 case GEU
: return CC0
| CC1
; /* no carry */
1141 switch (GET_CODE (code
))
1143 case GTU
: return CC0
| CC1
; /* borrow */
1144 case LEU
: return CC2
| CC3
; /* no borrow */
1150 switch (GET_CODE (code
))
1152 case EQ
: return CC0
| CC2
;
1153 case NE
: return CC1
| CC3
;
1154 case LTU
: return CC1
;
1155 case GTU
: return CC3
;
1156 case LEU
: return CC1
| CC2
;
1157 case GEU
: return CC2
| CC3
;
1162 switch (GET_CODE (code
))
1164 case EQ
: return CC0
;
1165 case NE
: return CC1
| CC2
| CC3
;
1166 case LTU
: return CC1
;
1167 case GTU
: return CC2
;
1168 case LEU
: return CC0
| CC1
;
1169 case GEU
: return CC0
| CC2
;
1175 switch (GET_CODE (code
))
1177 case EQ
: return CC0
;
1178 case NE
: return CC2
| CC1
| CC3
;
1179 case LTU
: return CC2
;
1180 case GTU
: return CC1
;
1181 case LEU
: return CC0
| CC2
;
1182 case GEU
: return CC0
| CC1
;
1188 switch (GET_CODE (code
))
1190 case EQ
: return CC0
;
1191 case NE
: return CC1
| CC2
| CC3
;
1192 case LT
: return CC1
| CC3
;
1193 case GT
: return CC2
;
1194 case LE
: return CC0
| CC1
| CC3
;
1195 case GE
: return CC0
| CC2
;
1201 switch (GET_CODE (code
))
1203 case EQ
: return CC0
;
1204 case NE
: return CC1
| CC2
| CC3
;
1205 case LT
: return CC1
;
1206 case GT
: return CC2
| CC3
;
1207 case LE
: return CC0
| CC1
;
1208 case GE
: return CC0
| CC2
| CC3
;
1214 switch (GET_CODE (code
))
1216 case EQ
: return CC0
;
1217 case NE
: return CC1
| CC2
| CC3
;
1218 case LT
: return CC1
;
1219 case GT
: return CC2
;
1220 case LE
: return CC0
| CC1
;
1221 case GE
: return CC0
| CC2
;
1222 case UNORDERED
: return CC3
;
1223 case ORDERED
: return CC0
| CC1
| CC2
;
1224 case UNEQ
: return CC0
| CC3
;
1225 case UNLT
: return CC1
| CC3
;
1226 case UNGT
: return CC2
| CC3
;
1227 case UNLE
: return CC0
| CC1
| CC3
;
1228 case UNGE
: return CC0
| CC2
| CC3
;
1229 case LTGT
: return CC1
| CC2
;
1235 switch (GET_CODE (code
))
1237 case EQ
: return CC0
;
1238 case NE
: return CC2
| CC1
| CC3
;
1239 case LT
: return CC2
;
1240 case GT
: return CC1
;
1241 case LE
: return CC0
| CC2
;
1242 case GE
: return CC0
| CC1
;
1243 case UNORDERED
: return CC3
;
1244 case ORDERED
: return CC0
| CC2
| CC1
;
1245 case UNEQ
: return CC0
| CC3
;
1246 case UNLT
: return CC2
| CC3
;
1247 case UNGT
: return CC1
| CC3
;
1248 case UNLE
: return CC0
| CC2
| CC3
;
1249 case UNGE
: return CC0
| CC1
| CC3
;
1250 case LTGT
: return CC2
| CC1
;
1256 switch (GET_CODE (code
))
1259 return INTVAL (XEXP (code
, 1));
1261 return (INTVAL (XEXP (code
, 1))) ^ 0xf;
1272 /* Return branch condition mask to implement a compare and branch
1273 specified by CODE. Return -1 for invalid comparisons. */
1276 s390_compare_and_branch_condition_mask (rtx code
)
1278 const int CC0
= 1 << 3;
1279 const int CC1
= 1 << 2;
1280 const int CC2
= 1 << 1;
1282 switch (GET_CODE (code
))
1306 /* If INV is false, return assembler mnemonic string to implement
1307 a branch specified by CODE. If INV is true, return mnemonic
1308 for the corresponding inverted branch. */
1311 s390_branch_condition_mnemonic (rtx code
, int inv
)
1315 static const char *const mnemonic
[16] =
1317 NULL
, "o", "h", "nle",
1318 "l", "nhe", "lh", "ne",
1319 "e", "nlh", "he", "nl",
1320 "le", "nh", "no", NULL
1323 if (GET_CODE (XEXP (code
, 0)) == REG
1324 && REGNO (XEXP (code
, 0)) == CC_REGNUM
1325 && (XEXP (code
, 1) == const0_rtx
1326 || (GET_MODE (XEXP (code
, 0)) == CCRAWmode
1327 && CONST_INT_P (XEXP (code
, 1)))))
1328 mask
= s390_branch_condition_mask (code
);
1330 mask
= s390_compare_and_branch_condition_mask (code
);
1332 gcc_assert (mask
>= 0);
1337 gcc_assert (mask
>= 1 && mask
<= 14);
1339 return mnemonic
[mask
];
1342 /* Return the part of op which has a value different from def.
1343 The size of the part is determined by mode.
1344 Use this function only if you already know that op really
1345 contains such a part. */
1347 unsigned HOST_WIDE_INT
1348 s390_extract_part (rtx op
, enum machine_mode mode
, int def
)
1350 unsigned HOST_WIDE_INT value
= 0;
1351 int max_parts
= HOST_BITS_PER_WIDE_INT
/ GET_MODE_BITSIZE (mode
);
1352 int part_bits
= GET_MODE_BITSIZE (mode
);
1353 unsigned HOST_WIDE_INT part_mask
1354 = ((unsigned HOST_WIDE_INT
)1 << part_bits
) - 1;
1357 for (i
= 0; i
< max_parts
; i
++)
1360 value
= (unsigned HOST_WIDE_INT
) INTVAL (op
);
1362 value
>>= part_bits
;
1364 if ((value
& part_mask
) != (def
& part_mask
))
1365 return value
& part_mask
;
1371 /* If OP is an integer constant of mode MODE with exactly one
1372 part of mode PART_MODE unequal to DEF, return the number of that
1373 part. Otherwise, return -1. */
1376 s390_single_part (rtx op
,
1377 enum machine_mode mode
,
1378 enum machine_mode part_mode
,
1381 unsigned HOST_WIDE_INT value
= 0;
1382 int n_parts
= GET_MODE_SIZE (mode
) / GET_MODE_SIZE (part_mode
);
1383 unsigned HOST_WIDE_INT part_mask
1384 = ((unsigned HOST_WIDE_INT
)1 << GET_MODE_BITSIZE (part_mode
)) - 1;
1387 if (GET_CODE (op
) != CONST_INT
)
1390 for (i
= 0; i
< n_parts
; i
++)
1393 value
= (unsigned HOST_WIDE_INT
) INTVAL (op
);
1395 value
>>= GET_MODE_BITSIZE (part_mode
);
1397 if ((value
& part_mask
) != (def
& part_mask
))
1405 return part
== -1 ? -1 : n_parts
- 1 - part
;
1408 /* Return true if IN contains a contiguous bitfield in the lower SIZE
1409 bits and no other bits are set in IN. POS and LENGTH can be used
1410 to obtain the start position and the length of the bitfield.
1412 POS gives the position of the first bit of the bitfield counting
1413 from the lowest order bit starting with zero. In order to use this
1414 value for S/390 instructions this has to be converted to "bits big
1418 s390_contiguous_bitmask_p (unsigned HOST_WIDE_INT in
, int size
,
1419 int *pos
, int *length
)
1424 unsigned HOST_WIDE_INT mask
= 1ULL;
1425 bool contiguous
= false;
1427 for (i
= 0; i
< size
; mask
<<= 1, i
++)
1451 /* Calculate a mask for all bits beyond the contiguous bits. */
1452 mask
= (-1LL & ~(((1ULL << (tmp_length
+ tmp_pos
- 1)) << 1) - 1));
1457 if (tmp_length
+ tmp_pos
- 1 > size
)
1461 *length
= tmp_length
;
1469 /* Check whether a rotate of ROTL followed by an AND of CONTIG is
1470 equivalent to a shift followed by the AND. In particular, CONTIG
1471 should not overlap the (rotated) bit 0/bit 63 gap. Negative values
1472 for ROTL indicate a rotate to the right. */
1475 s390_extzv_shift_ok (int bitsize
, int rotl
, unsigned HOST_WIDE_INT contig
)
1480 ok
= s390_contiguous_bitmask_p (contig
, bitsize
, &pos
, &len
);
1483 return ((rotl
>= 0 && rotl
<= pos
)
1484 || (rotl
< 0 && -rotl
<= bitsize
- len
- pos
));
1487 /* Check whether we can (and want to) split a double-word
1488 move in mode MODE from SRC to DST into two single-word
1489 moves, moving the subword FIRST_SUBWORD first. */
1492 s390_split_ok_p (rtx dst
, rtx src
, enum machine_mode mode
, int first_subword
)
1494 /* Floating point registers cannot be split. */
1495 if (FP_REG_P (src
) || FP_REG_P (dst
))
1498 /* We don't need to split if operands are directly accessible. */
1499 if (s_operand (src
, mode
) || s_operand (dst
, mode
))
1502 /* Non-offsettable memory references cannot be split. */
1503 if ((GET_CODE (src
) == MEM
&& !offsettable_memref_p (src
))
1504 || (GET_CODE (dst
) == MEM
&& !offsettable_memref_p (dst
)))
1507 /* Moving the first subword must not clobber a register
1508 needed to move the second subword. */
1509 if (register_operand (dst
, mode
))
1511 rtx subreg
= operand_subword (dst
, first_subword
, 0, mode
);
1512 if (reg_overlap_mentioned_p (subreg
, src
))
1519 /* Return true if it can be proven that [MEM1, MEM1 + SIZE]
1520 and [MEM2, MEM2 + SIZE] do overlap and false
1524 s390_overlap_p (rtx mem1
, rtx mem2
, HOST_WIDE_INT size
)
1526 rtx addr1
, addr2
, addr_delta
;
1527 HOST_WIDE_INT delta
;
1529 if (GET_CODE (mem1
) != MEM
|| GET_CODE (mem2
) != MEM
)
1535 addr1
= XEXP (mem1
, 0);
1536 addr2
= XEXP (mem2
, 0);
1538 addr_delta
= simplify_binary_operation (MINUS
, Pmode
, addr2
, addr1
);
1540 /* This overlapping check is used by peepholes merging memory block operations.
1541 Overlapping operations would otherwise be recognized by the S/390 hardware
1542 and would fall back to a slower implementation. Allowing overlapping
1543 operations would lead to slow code but not to wrong code. Therefore we are
1544 somewhat optimistic if we cannot prove that the memory blocks are
1546 That's why we return false here although this may accept operations on
1547 overlapping memory areas. */
1548 if (!addr_delta
|| GET_CODE (addr_delta
) != CONST_INT
)
1551 delta
= INTVAL (addr_delta
);
1554 || (delta
> 0 && delta
< size
)
1555 || (delta
< 0 && -delta
< size
))
1561 /* Check whether the address of memory reference MEM2 equals exactly
1562 the address of memory reference MEM1 plus DELTA. Return true if
1563 we can prove this to be the case, false otherwise. */
1566 s390_offset_p (rtx mem1
, rtx mem2
, rtx delta
)
1568 rtx addr1
, addr2
, addr_delta
;
1570 if (GET_CODE (mem1
) != MEM
|| GET_CODE (mem2
) != MEM
)
1573 addr1
= XEXP (mem1
, 0);
1574 addr2
= XEXP (mem2
, 0);
1576 addr_delta
= simplify_binary_operation (MINUS
, Pmode
, addr2
, addr1
);
1577 if (!addr_delta
|| !rtx_equal_p (addr_delta
, delta
))
1583 /* Expand logical operator CODE in mode MODE with operands OPERANDS. */
1586 s390_expand_logical_operator (enum rtx_code code
, enum machine_mode mode
,
1589 enum machine_mode wmode
= mode
;
1590 rtx dst
= operands
[0];
1591 rtx src1
= operands
[1];
1592 rtx src2
= operands
[2];
1595 /* If we cannot handle the operation directly, use a temp register. */
1596 if (!s390_logical_operator_ok_p (operands
))
1597 dst
= gen_reg_rtx (mode
);
1599 /* QImode and HImode patterns make sense only if we have a destination
1600 in memory. Otherwise perform the operation in SImode. */
1601 if ((mode
== QImode
|| mode
== HImode
) && GET_CODE (dst
) != MEM
)
1604 /* Widen operands if required. */
1607 if (GET_CODE (dst
) == SUBREG
1608 && (tem
= simplify_subreg (wmode
, dst
, mode
, 0)) != 0)
1610 else if (REG_P (dst
))
1611 dst
= gen_rtx_SUBREG (wmode
, dst
, 0);
1613 dst
= gen_reg_rtx (wmode
);
1615 if (GET_CODE (src1
) == SUBREG
1616 && (tem
= simplify_subreg (wmode
, src1
, mode
, 0)) != 0)
1618 else if (GET_MODE (src1
) != VOIDmode
)
1619 src1
= gen_rtx_SUBREG (wmode
, force_reg (mode
, src1
), 0);
1621 if (GET_CODE (src2
) == SUBREG
1622 && (tem
= simplify_subreg (wmode
, src2
, mode
, 0)) != 0)
1624 else if (GET_MODE (src2
) != VOIDmode
)
1625 src2
= gen_rtx_SUBREG (wmode
, force_reg (mode
, src2
), 0);
1628 /* Emit the instruction. */
1629 op
= gen_rtx_SET (VOIDmode
, dst
, gen_rtx_fmt_ee (code
, wmode
, src1
, src2
));
1630 clob
= gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
1631 emit_insn (gen_rtx_PARALLEL (VOIDmode
, gen_rtvec (2, op
, clob
)));
1633 /* Fix up the destination if needed. */
1634 if (dst
!= operands
[0])
1635 emit_move_insn (operands
[0], gen_lowpart (mode
, dst
));
1638 /* Check whether OPERANDS are OK for a logical operation (AND, IOR, XOR). */
1641 s390_logical_operator_ok_p (rtx
*operands
)
1643 /* If the destination operand is in memory, it needs to coincide
1644 with one of the source operands. After reload, it has to be
1645 the first source operand. */
1646 if (GET_CODE (operands
[0]) == MEM
)
1647 return rtx_equal_p (operands
[0], operands
[1])
1648 || (!reload_completed
&& rtx_equal_p (operands
[0], operands
[2]));
1653 /* Narrow logical operation CODE of memory operand MEMOP with immediate
1654 operand IMMOP to switch from SS to SI type instructions. */
1657 s390_narrow_logical_operator (enum rtx_code code
, rtx
*memop
, rtx
*immop
)
1659 int def
= code
== AND
? -1 : 0;
1663 gcc_assert (GET_CODE (*memop
) == MEM
);
1664 gcc_assert (!MEM_VOLATILE_P (*memop
));
1666 mask
= s390_extract_part (*immop
, QImode
, def
);
1667 part
= s390_single_part (*immop
, GET_MODE (*memop
), QImode
, def
);
1668 gcc_assert (part
>= 0);
1670 *memop
= adjust_address (*memop
, QImode
, part
);
1671 *immop
= gen_int_mode (mask
, QImode
);
1675 /* How to allocate a 'struct machine_function'. */
1677 static struct machine_function
*
1678 s390_init_machine_status (void)
1680 return ggc_cleared_alloc
<machine_function
> ();
1683 /* Map for smallest class containing reg regno. */
1685 const enum reg_class regclass_map
[FIRST_PSEUDO_REGISTER
] =
1686 { GENERAL_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1687 ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1688 ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1689 ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1690 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1691 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1692 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1693 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1694 ADDR_REGS
, CC_REGS
, ADDR_REGS
, ADDR_REGS
,
1695 ACCESS_REGS
, ACCESS_REGS
1698 /* Return attribute type of insn. */
1700 static enum attr_type
1701 s390_safe_attr_type (rtx_insn
*insn
)
1703 if (recog_memoized (insn
) >= 0)
1704 return get_attr_type (insn
);
1709 /* Return true if DISP is a valid short displacement. */
1712 s390_short_displacement (rtx disp
)
1714 /* No displacement is OK. */
1718 /* Without the long displacement facility we don't need to
1719 distingiush between long and short displacement. */
1720 if (!TARGET_LONG_DISPLACEMENT
)
1723 /* Integer displacement in range. */
1724 if (GET_CODE (disp
) == CONST_INT
)
1725 return INTVAL (disp
) >= 0 && INTVAL (disp
) < 4096;
1727 /* GOT offset is not OK, the GOT can be large. */
1728 if (GET_CODE (disp
) == CONST
1729 && GET_CODE (XEXP (disp
, 0)) == UNSPEC
1730 && (XINT (XEXP (disp
, 0), 1) == UNSPEC_GOT
1731 || XINT (XEXP (disp
, 0), 1) == UNSPEC_GOTNTPOFF
))
1734 /* All other symbolic constants are literal pool references,
1735 which are OK as the literal pool must be small. */
1736 if (GET_CODE (disp
) == CONST
)
1742 /* Decompose a RTL expression ADDR for a memory address into
1743 its components, returned in OUT.
1745 Returns false if ADDR is not a valid memory address, true
1746 otherwise. If OUT is NULL, don't return the components,
1747 but check for validity only.
1749 Note: Only addresses in canonical form are recognized.
1750 LEGITIMIZE_ADDRESS should convert non-canonical forms to the
1751 canonical form so that they will be recognized. */
1754 s390_decompose_address (rtx addr
, struct s390_address
*out
)
1756 HOST_WIDE_INT offset
= 0;
1757 rtx base
= NULL_RTX
;
1758 rtx indx
= NULL_RTX
;
1759 rtx disp
= NULL_RTX
;
1761 bool pointer
= false;
1762 bool base_ptr
= false;
1763 bool indx_ptr
= false;
1764 bool literal_pool
= false;
1766 /* We may need to substitute the literal pool base register into the address
1767 below. However, at this point we do not know which register is going to
1768 be used as base, so we substitute the arg pointer register. This is going
1769 to be treated as holding a pointer below -- it shouldn't be used for any
1771 rtx fake_pool_base
= gen_rtx_REG (Pmode
, ARG_POINTER_REGNUM
);
1773 /* Decompose address into base + index + displacement. */
1775 if (GET_CODE (addr
) == REG
|| GET_CODE (addr
) == UNSPEC
)
1778 else if (GET_CODE (addr
) == PLUS
)
1780 rtx op0
= XEXP (addr
, 0);
1781 rtx op1
= XEXP (addr
, 1);
1782 enum rtx_code code0
= GET_CODE (op0
);
1783 enum rtx_code code1
= GET_CODE (op1
);
1785 if (code0
== REG
|| code0
== UNSPEC
)
1787 if (code1
== REG
|| code1
== UNSPEC
)
1789 indx
= op0
; /* index + base */
1795 base
= op0
; /* base + displacement */
1800 else if (code0
== PLUS
)
1802 indx
= XEXP (op0
, 0); /* index + base + disp */
1803 base
= XEXP (op0
, 1);
1814 disp
= addr
; /* displacement */
1816 /* Extract integer part of displacement. */
1820 if (GET_CODE (disp
) == CONST_INT
)
1822 offset
= INTVAL (disp
);
1825 else if (GET_CODE (disp
) == CONST
1826 && GET_CODE (XEXP (disp
, 0)) == PLUS
1827 && GET_CODE (XEXP (XEXP (disp
, 0), 1)) == CONST_INT
)
1829 offset
= INTVAL (XEXP (XEXP (disp
, 0), 1));
1830 disp
= XEXP (XEXP (disp
, 0), 0);
1834 /* Strip off CONST here to avoid special case tests later. */
1835 if (disp
&& GET_CODE (disp
) == CONST
)
1836 disp
= XEXP (disp
, 0);
1838 /* We can convert literal pool addresses to
1839 displacements by basing them off the base register. */
1840 if (disp
&& GET_CODE (disp
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (disp
))
1842 /* Either base or index must be free to hold the base register. */
1844 base
= fake_pool_base
, literal_pool
= true;
1846 indx
= fake_pool_base
, literal_pool
= true;
1850 /* Mark up the displacement. */
1851 disp
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, disp
),
1852 UNSPEC_LTREL_OFFSET
);
1855 /* Validate base register. */
1858 if (GET_CODE (base
) == UNSPEC
)
1859 switch (XINT (base
, 1))
1863 disp
= gen_rtx_UNSPEC (Pmode
,
1864 gen_rtvec (1, XVECEXP (base
, 0, 0)),
1865 UNSPEC_LTREL_OFFSET
);
1869 base
= XVECEXP (base
, 0, 1);
1872 case UNSPEC_LTREL_BASE
:
1873 if (XVECLEN (base
, 0) == 1)
1874 base
= fake_pool_base
, literal_pool
= true;
1876 base
= XVECEXP (base
, 0, 1);
1884 || (GET_MODE (base
) != SImode
1885 && GET_MODE (base
) != Pmode
))
1888 if (REGNO (base
) == STACK_POINTER_REGNUM
1889 || REGNO (base
) == FRAME_POINTER_REGNUM
1890 || ((reload_completed
|| reload_in_progress
)
1891 && frame_pointer_needed
1892 && REGNO (base
) == HARD_FRAME_POINTER_REGNUM
)
1893 || REGNO (base
) == ARG_POINTER_REGNUM
1895 && REGNO (base
) == PIC_OFFSET_TABLE_REGNUM
))
1896 pointer
= base_ptr
= true;
1898 if ((reload_completed
|| reload_in_progress
)
1899 && base
== cfun
->machine
->base_reg
)
1900 pointer
= base_ptr
= literal_pool
= true;
1903 /* Validate index register. */
1906 if (GET_CODE (indx
) == UNSPEC
)
1907 switch (XINT (indx
, 1))
1911 disp
= gen_rtx_UNSPEC (Pmode
,
1912 gen_rtvec (1, XVECEXP (indx
, 0, 0)),
1913 UNSPEC_LTREL_OFFSET
);
1917 indx
= XVECEXP (indx
, 0, 1);
1920 case UNSPEC_LTREL_BASE
:
1921 if (XVECLEN (indx
, 0) == 1)
1922 indx
= fake_pool_base
, literal_pool
= true;
1924 indx
= XVECEXP (indx
, 0, 1);
1932 || (GET_MODE (indx
) != SImode
1933 && GET_MODE (indx
) != Pmode
))
1936 if (REGNO (indx
) == STACK_POINTER_REGNUM
1937 || REGNO (indx
) == FRAME_POINTER_REGNUM
1938 || ((reload_completed
|| reload_in_progress
)
1939 && frame_pointer_needed
1940 && REGNO (indx
) == HARD_FRAME_POINTER_REGNUM
)
1941 || REGNO (indx
) == ARG_POINTER_REGNUM
1943 && REGNO (indx
) == PIC_OFFSET_TABLE_REGNUM
))
1944 pointer
= indx_ptr
= true;
1946 if ((reload_completed
|| reload_in_progress
)
1947 && indx
== cfun
->machine
->base_reg
)
1948 pointer
= indx_ptr
= literal_pool
= true;
1951 /* Prefer to use pointer as base, not index. */
1952 if (base
&& indx
&& !base_ptr
1953 && (indx_ptr
|| (!REG_POINTER (base
) && REG_POINTER (indx
))))
1960 /* Validate displacement. */
1963 /* If virtual registers are involved, the displacement will change later
1964 anyway as the virtual registers get eliminated. This could make a
1965 valid displacement invalid, but it is more likely to make an invalid
1966 displacement valid, because we sometimes access the register save area
1967 via negative offsets to one of those registers.
1968 Thus we don't check the displacement for validity here. If after
1969 elimination the displacement turns out to be invalid after all,
1970 this is fixed up by reload in any case. */
1971 /* LRA maintains always displacements up to date and we need to
1972 know the displacement is right during all LRA not only at the
1973 final elimination. */
1975 || (base
!= arg_pointer_rtx
1976 && indx
!= arg_pointer_rtx
1977 && base
!= return_address_pointer_rtx
1978 && indx
!= return_address_pointer_rtx
1979 && base
!= frame_pointer_rtx
1980 && indx
!= frame_pointer_rtx
1981 && base
!= virtual_stack_vars_rtx
1982 && indx
!= virtual_stack_vars_rtx
))
1983 if (!DISP_IN_RANGE (offset
))
1988 /* All the special cases are pointers. */
1991 /* In the small-PIC case, the linker converts @GOT
1992 and @GOTNTPOFF offsets to possible displacements. */
1993 if (GET_CODE (disp
) == UNSPEC
1994 && (XINT (disp
, 1) == UNSPEC_GOT
1995 || XINT (disp
, 1) == UNSPEC_GOTNTPOFF
)
2001 /* Accept pool label offsets. */
2002 else if (GET_CODE (disp
) == UNSPEC
2003 && XINT (disp
, 1) == UNSPEC_POOL_OFFSET
)
2006 /* Accept literal pool references. */
2007 else if (GET_CODE (disp
) == UNSPEC
2008 && XINT (disp
, 1) == UNSPEC_LTREL_OFFSET
)
2010 /* In case CSE pulled a non literal pool reference out of
2011 the pool we have to reject the address. This is
2012 especially important when loading the GOT pointer on non
2013 zarch CPUs. In this case the literal pool contains an lt
2014 relative offset to the _GLOBAL_OFFSET_TABLE_ label which
2015 will most likely exceed the displacement. */
2016 if (GET_CODE (XVECEXP (disp
, 0, 0)) != SYMBOL_REF
2017 || !CONSTANT_POOL_ADDRESS_P (XVECEXP (disp
, 0, 0)))
2020 orig_disp
= gen_rtx_CONST (Pmode
, disp
);
2023 /* If we have an offset, make sure it does not
2024 exceed the size of the constant pool entry. */
2025 rtx sym
= XVECEXP (disp
, 0, 0);
2026 if (offset
>= GET_MODE_SIZE (get_pool_mode (sym
)))
2029 orig_disp
= plus_constant (Pmode
, orig_disp
, offset
);
2044 out
->disp
= orig_disp
;
2045 out
->pointer
= pointer
;
2046 out
->literal_pool
= literal_pool
;
2052 /* Decompose a RTL expression OP for a shift count into its components,
2053 and return the base register in BASE and the offset in OFFSET.
2055 Return true if OP is a valid shift count, false if not. */
2058 s390_decompose_shift_count (rtx op
, rtx
*base
, HOST_WIDE_INT
*offset
)
2060 HOST_WIDE_INT off
= 0;
2062 /* We can have an integer constant, an address register,
2063 or a sum of the two. */
2064 if (GET_CODE (op
) == CONST_INT
)
2069 if (op
&& GET_CODE (op
) == PLUS
&& GET_CODE (XEXP (op
, 1)) == CONST_INT
)
2071 off
= INTVAL (XEXP (op
, 1));
2074 while (op
&& GET_CODE (op
) == SUBREG
)
2075 op
= SUBREG_REG (op
);
2077 if (op
&& GET_CODE (op
) != REG
)
2089 /* Return true if CODE is a valid address without index. */
2092 s390_legitimate_address_without_index_p (rtx op
)
2094 struct s390_address addr
;
2096 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
2105 /* Return TRUE if ADDR is an operand valid for a load/store relative
2106 instruction. Be aware that the alignment of the operand needs to
2107 be checked separately.
2108 Valid addresses are single references or a sum of a reference and a
2109 constant integer. Return these parts in SYMREF and ADDEND. You can
2110 pass NULL in REF and/or ADDEND if you are not interested in these
2111 values. Literal pool references are *not* considered symbol
2115 s390_loadrelative_operand_p (rtx addr
, rtx
*symref
, HOST_WIDE_INT
*addend
)
2117 HOST_WIDE_INT tmpaddend
= 0;
2119 if (GET_CODE (addr
) == CONST
)
2120 addr
= XEXP (addr
, 0);
2122 if (GET_CODE (addr
) == PLUS
)
2124 if (!CONST_INT_P (XEXP (addr
, 1)))
2127 tmpaddend
= INTVAL (XEXP (addr
, 1));
2128 addr
= XEXP (addr
, 0);
2131 if ((GET_CODE (addr
) == SYMBOL_REF
&& !CONSTANT_POOL_ADDRESS_P (addr
))
2132 || (GET_CODE (addr
) == UNSPEC
2133 && (XINT (addr
, 1) == UNSPEC_GOTENT
2134 || (TARGET_CPU_ZARCH
&& XINT (addr
, 1) == UNSPEC_PLT
))))
2139 *addend
= tmpaddend
;
2146 /* Return true if the address in OP is valid for constraint letter C
2147 if wrapped in a MEM rtx. Set LIT_POOL_OK to true if it literal
2148 pool MEMs should be accepted. Only the Q, R, S, T constraint
2149 letters are allowed for C. */
2152 s390_check_qrst_address (char c
, rtx op
, bool lit_pool_ok
)
2154 struct s390_address addr
;
2155 bool decomposed
= false;
2157 /* This check makes sure that no symbolic address (except literal
2158 pool references) are accepted by the R or T constraints. */
2159 if (s390_loadrelative_operand_p (op
, NULL
, NULL
))
2162 /* Ensure literal pool references are only accepted if LIT_POOL_OK. */
2165 if (!s390_decompose_address (op
, &addr
))
2167 if (addr
.literal_pool
)
2174 case 'Q': /* no index short displacement */
2175 if (!decomposed
&& !s390_decompose_address (op
, &addr
))
2179 if (!s390_short_displacement (addr
.disp
))
2183 case 'R': /* with index short displacement */
2184 if (TARGET_LONG_DISPLACEMENT
)
2186 if (!decomposed
&& !s390_decompose_address (op
, &addr
))
2188 if (!s390_short_displacement (addr
.disp
))
2191 /* Any invalid address here will be fixed up by reload,
2192 so accept it for the most generic constraint. */
2195 case 'S': /* no index long displacement */
2196 if (!TARGET_LONG_DISPLACEMENT
)
2198 if (!decomposed
&& !s390_decompose_address (op
, &addr
))
2202 if (s390_short_displacement (addr
.disp
))
2206 case 'T': /* with index long displacement */
2207 if (!TARGET_LONG_DISPLACEMENT
)
2209 /* Any invalid address here will be fixed up by reload,
2210 so accept it for the most generic constraint. */
2211 if ((decomposed
|| s390_decompose_address (op
, &addr
))
2212 && s390_short_displacement (addr
.disp
))
2222 /* Evaluates constraint strings described by the regular expression
2223 ([A|B|Z](Q|R|S|T))|U|W|Y and returns 1 if OP is a valid operand for
2224 the constraint given in STR, or 0 else. */
2227 s390_mem_constraint (const char *str
, rtx op
)
2234 /* Check for offsettable variants of memory constraints. */
2235 if (!MEM_P (op
) || MEM_VOLATILE_P (op
))
2237 if ((reload_completed
|| reload_in_progress
)
2238 ? !offsettable_memref_p (op
) : !offsettable_nonstrict_memref_p (op
))
2240 return s390_check_qrst_address (str
[1], XEXP (op
, 0), true);
2242 /* Check for non-literal-pool variants of memory constraints. */
2245 return s390_check_qrst_address (str
[1], XEXP (op
, 0), false);
2250 if (GET_CODE (op
) != MEM
)
2252 return s390_check_qrst_address (c
, XEXP (op
, 0), true);
2254 return (s390_check_qrst_address ('Q', op
, true)
2255 || s390_check_qrst_address ('R', op
, true));
2257 return (s390_check_qrst_address ('S', op
, true)
2258 || s390_check_qrst_address ('T', op
, true));
2260 /* Simply check for the basic form of a shift count. Reload will
2261 take care of making sure we have a proper base register. */
2262 if (!s390_decompose_shift_count (op
, NULL
, NULL
))
2266 return s390_check_qrst_address (str
[1], op
, true);
2274 /* Evaluates constraint strings starting with letter O. Input
2275 parameter C is the second letter following the "O" in the constraint
2276 string. Returns 1 if VALUE meets the respective constraint and 0
2280 s390_O_constraint_str (const char c
, HOST_WIDE_INT value
)
2288 return trunc_int_for_mode (value
, SImode
) == value
;
2292 || s390_single_part (GEN_INT (value
), DImode
, SImode
, 0) == 1;
2295 return s390_single_part (GEN_INT (value
- 1), DImode
, SImode
, -1) == 1;
2303 /* Evaluates constraint strings starting with letter N. Parameter STR
2304 contains the letters following letter "N" in the constraint string.
2305 Returns true if VALUE matches the constraint. */
2308 s390_N_constraint_str (const char *str
, HOST_WIDE_INT value
)
2310 enum machine_mode mode
, part_mode
;
2312 int part
, part_goal
;
2318 part_goal
= str
[0] - '0';
2362 if (GET_MODE_SIZE (mode
) <= GET_MODE_SIZE (part_mode
))
2365 part
= s390_single_part (GEN_INT (value
), mode
, part_mode
, def
);
2368 if (part_goal
!= -1 && part_goal
!= part
)
2375 /* Returns true if the input parameter VALUE is a float zero. */
2378 s390_float_const_zero_p (rtx value
)
2380 return (GET_MODE_CLASS (GET_MODE (value
)) == MODE_FLOAT
2381 && value
== CONST0_RTX (GET_MODE (value
)));
2384 /* Implement TARGET_REGISTER_MOVE_COST. */
2387 s390_register_move_cost (enum machine_mode mode ATTRIBUTE_UNUSED
,
2388 reg_class_t from
, reg_class_t to
)
2390 /* On s390, copy between fprs and gprs is expensive as long as no
2391 ldgr/lgdr can be used. */
2392 if ((!TARGET_Z10
|| GET_MODE_SIZE (mode
) != 8)
2393 && ((reg_classes_intersect_p (from
, GENERAL_REGS
)
2394 && reg_classes_intersect_p (to
, FP_REGS
))
2395 || (reg_classes_intersect_p (from
, FP_REGS
)
2396 && reg_classes_intersect_p (to
, GENERAL_REGS
))))
2402 /* Implement TARGET_MEMORY_MOVE_COST. */
2405 s390_memory_move_cost (enum machine_mode mode ATTRIBUTE_UNUSED
,
2406 reg_class_t rclass ATTRIBUTE_UNUSED
,
2407 bool in ATTRIBUTE_UNUSED
)
2412 /* Compute a (partial) cost for rtx X. Return true if the complete
2413 cost has been computed, and false if subexpressions should be
2414 scanned. In either case, *TOTAL contains the cost result.
2415 CODE contains GET_CODE (x), OUTER_CODE contains the code
2416 of the superexpression of x. */
2419 s390_rtx_costs (rtx x
, int code
, int outer_code
, int opno ATTRIBUTE_UNUSED
,
2420 int *total
, bool speed ATTRIBUTE_UNUSED
)
2443 *total
= COSTS_N_INSNS (1);
2448 *total
= COSTS_N_INSNS (1);
2452 switch (GET_MODE (x
))
2456 rtx left
= XEXP (x
, 0);
2457 rtx right
= XEXP (x
, 1);
2458 if (GET_CODE (right
) == CONST_INT
2459 && CONST_OK_FOR_K (INTVAL (right
)))
2460 *total
= s390_cost
->mhi
;
2461 else if (GET_CODE (left
) == SIGN_EXTEND
)
2462 *total
= s390_cost
->mh
;
2464 *total
= s390_cost
->ms
; /* msr, ms, msy */
2469 rtx left
= XEXP (x
, 0);
2470 rtx right
= XEXP (x
, 1);
2473 if (GET_CODE (right
) == CONST_INT
2474 && CONST_OK_FOR_K (INTVAL (right
)))
2475 *total
= s390_cost
->mghi
;
2476 else if (GET_CODE (left
) == SIGN_EXTEND
)
2477 *total
= s390_cost
->msgf
;
2479 *total
= s390_cost
->msg
; /* msgr, msg */
2481 else /* TARGET_31BIT */
2483 if (GET_CODE (left
) == SIGN_EXTEND
2484 && GET_CODE (right
) == SIGN_EXTEND
)
2485 /* mulsidi case: mr, m */
2486 *total
= s390_cost
->m
;
2487 else if (GET_CODE (left
) == ZERO_EXTEND
2488 && GET_CODE (right
) == ZERO_EXTEND
2489 && TARGET_CPU_ZARCH
)
2490 /* umulsidi case: ml, mlr */
2491 *total
= s390_cost
->ml
;
2493 /* Complex calculation is required. */
2494 *total
= COSTS_N_INSNS (40);
2500 *total
= s390_cost
->mult_df
;
2503 *total
= s390_cost
->mxbr
;
2511 switch (GET_MODE (x
))
2514 *total
= s390_cost
->madbr
;
2517 *total
= s390_cost
->maebr
;
2522 /* Negate in the third argument is free: FMSUB. */
2523 if (GET_CODE (XEXP (x
, 2)) == NEG
)
2525 *total
+= (rtx_cost (XEXP (x
, 0), FMA
, 0, speed
)
2526 + rtx_cost (XEXP (x
, 1), FMA
, 1, speed
)
2527 + rtx_cost (XEXP (XEXP (x
, 2), 0), FMA
, 2, speed
));
2534 if (GET_MODE (x
) == TImode
) /* 128 bit division */
2535 *total
= s390_cost
->dlgr
;
2536 else if (GET_MODE (x
) == DImode
)
2538 rtx right
= XEXP (x
, 1);
2539 if (GET_CODE (right
) == ZERO_EXTEND
) /* 64 by 32 bit division */
2540 *total
= s390_cost
->dlr
;
2541 else /* 64 by 64 bit division */
2542 *total
= s390_cost
->dlgr
;
2544 else if (GET_MODE (x
) == SImode
) /* 32 bit division */
2545 *total
= s390_cost
->dlr
;
2550 if (GET_MODE (x
) == DImode
)
2552 rtx right
= XEXP (x
, 1);
2553 if (GET_CODE (right
) == ZERO_EXTEND
) /* 64 by 32 bit division */
2555 *total
= s390_cost
->dsgfr
;
2557 *total
= s390_cost
->dr
;
2558 else /* 64 by 64 bit division */
2559 *total
= s390_cost
->dsgr
;
2561 else if (GET_MODE (x
) == SImode
) /* 32 bit division */
2562 *total
= s390_cost
->dlr
;
2563 else if (GET_MODE (x
) == SFmode
)
2565 *total
= s390_cost
->debr
;
2567 else if (GET_MODE (x
) == DFmode
)
2569 *total
= s390_cost
->ddbr
;
2571 else if (GET_MODE (x
) == TFmode
)
2573 *total
= s390_cost
->dxbr
;
2578 if (GET_MODE (x
) == SFmode
)
2579 *total
= s390_cost
->sqebr
;
2580 else if (GET_MODE (x
) == DFmode
)
2581 *total
= s390_cost
->sqdbr
;
2583 *total
= s390_cost
->sqxbr
;
2588 if (outer_code
== MULT
|| outer_code
== DIV
|| outer_code
== MOD
2589 || outer_code
== PLUS
|| outer_code
== MINUS
2590 || outer_code
== COMPARE
)
2595 *total
= COSTS_N_INSNS (1);
2596 if (GET_CODE (XEXP (x
, 0)) == AND
2597 && GET_CODE (XEXP (x
, 1)) == CONST_INT
2598 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
)
2600 rtx op0
= XEXP (XEXP (x
, 0), 0);
2601 rtx op1
= XEXP (XEXP (x
, 0), 1);
2602 rtx op2
= XEXP (x
, 1);
2604 if (memory_operand (op0
, GET_MODE (op0
))
2605 && s390_tm_ccmode (op1
, op2
, 0) != VOIDmode
)
2607 if (register_operand (op0
, GET_MODE (op0
))
2608 && s390_tm_ccmode (op1
, op2
, 1) != VOIDmode
)
2618 /* Return the cost of an address rtx ADDR. */
2621 s390_address_cost (rtx addr
, enum machine_mode mode ATTRIBUTE_UNUSED
,
2622 addr_space_t as ATTRIBUTE_UNUSED
,
2623 bool speed ATTRIBUTE_UNUSED
)
2625 struct s390_address ad
;
2626 if (!s390_decompose_address (addr
, &ad
))
2629 return ad
.indx
? COSTS_N_INSNS (1) + 1 : COSTS_N_INSNS (1);
2632 /* If OP is a SYMBOL_REF of a thread-local symbol, return its TLS mode,
2633 otherwise return 0. */
2636 tls_symbolic_operand (rtx op
)
2638 if (GET_CODE (op
) != SYMBOL_REF
)
2640 return SYMBOL_REF_TLS_MODEL (op
);
2643 /* Split DImode access register reference REG (on 64-bit) into its constituent
2644 low and high parts, and store them into LO and HI. Note that gen_lowpart/
2645 gen_highpart cannot be used as they assume all registers are word-sized,
2646 while our access registers have only half that size. */
2649 s390_split_access_reg (rtx reg
, rtx
*lo
, rtx
*hi
)
2651 gcc_assert (TARGET_64BIT
);
2652 gcc_assert (ACCESS_REG_P (reg
));
2653 gcc_assert (GET_MODE (reg
) == DImode
);
2654 gcc_assert (!(REGNO (reg
) & 1));
2656 *lo
= gen_rtx_REG (SImode
, REGNO (reg
) + 1);
2657 *hi
= gen_rtx_REG (SImode
, REGNO (reg
));
2660 /* Return true if OP contains a symbol reference */
2663 symbolic_reference_mentioned_p (rtx op
)
2668 if (GET_CODE (op
) == SYMBOL_REF
|| GET_CODE (op
) == LABEL_REF
)
2671 fmt
= GET_RTX_FORMAT (GET_CODE (op
));
2672 for (i
= GET_RTX_LENGTH (GET_CODE (op
)) - 1; i
>= 0; i
--)
2678 for (j
= XVECLEN (op
, i
) - 1; j
>= 0; j
--)
2679 if (symbolic_reference_mentioned_p (XVECEXP (op
, i
, j
)))
2683 else if (fmt
[i
] == 'e' && symbolic_reference_mentioned_p (XEXP (op
, i
)))
2690 /* Return true if OP contains a reference to a thread-local symbol. */
2693 tls_symbolic_reference_mentioned_p (rtx op
)
2698 if (GET_CODE (op
) == SYMBOL_REF
)
2699 return tls_symbolic_operand (op
);
2701 fmt
= GET_RTX_FORMAT (GET_CODE (op
));
2702 for (i
= GET_RTX_LENGTH (GET_CODE (op
)) - 1; i
>= 0; i
--)
2708 for (j
= XVECLEN (op
, i
) - 1; j
>= 0; j
--)
2709 if (tls_symbolic_reference_mentioned_p (XVECEXP (op
, i
, j
)))
2713 else if (fmt
[i
] == 'e' && tls_symbolic_reference_mentioned_p (XEXP (op
, i
)))
2721 /* Return true if OP is a legitimate general operand when
2722 generating PIC code. It is given that flag_pic is on
2723 and that OP satisfies CONSTANT_P or is a CONST_DOUBLE. */
2726 legitimate_pic_operand_p (rtx op
)
2728 /* Accept all non-symbolic constants. */
2729 if (!SYMBOLIC_CONST (op
))
2732 /* Reject everything else; must be handled
2733 via emit_symbolic_move. */
2737 /* Returns true if the constant value OP is a legitimate general operand.
2738 It is given that OP satisfies CONSTANT_P or is a CONST_DOUBLE. */
2741 s390_legitimate_constant_p (enum machine_mode mode
, rtx op
)
2743 /* Accept all non-symbolic constants. */
2744 if (!SYMBOLIC_CONST (op
))
2747 /* Accept immediate LARL operands. */
2748 if (TARGET_CPU_ZARCH
&& larl_operand (op
, mode
))
2751 /* Thread-local symbols are never legal constants. This is
2752 so that emit_call knows that computing such addresses
2753 might require a function call. */
2754 if (TLS_SYMBOLIC_CONST (op
))
2757 /* In the PIC case, symbolic constants must *not* be
2758 forced into the literal pool. We accept them here,
2759 so that they will be handled by emit_symbolic_move. */
2763 /* All remaining non-PIC symbolic constants are
2764 forced into the literal pool. */
2768 /* Determine if it's legal to put X into the constant pool. This
2769 is not possible if X contains the address of a symbol that is
2770 not constant (TLS) or not known at final link time (PIC). */
2773 s390_cannot_force_const_mem (enum machine_mode mode
, rtx x
)
2775 switch (GET_CODE (x
))
2779 /* Accept all non-symbolic constants. */
2783 /* Labels are OK iff we are non-PIC. */
2784 return flag_pic
!= 0;
2787 /* 'Naked' TLS symbol references are never OK,
2788 non-TLS symbols are OK iff we are non-PIC. */
2789 if (tls_symbolic_operand (x
))
2792 return flag_pic
!= 0;
2795 return s390_cannot_force_const_mem (mode
, XEXP (x
, 0));
2798 return s390_cannot_force_const_mem (mode
, XEXP (x
, 0))
2799 || s390_cannot_force_const_mem (mode
, XEXP (x
, 1));
2802 switch (XINT (x
, 1))
2804 /* Only lt-relative or GOT-relative UNSPECs are OK. */
2805 case UNSPEC_LTREL_OFFSET
:
2813 case UNSPEC_GOTNTPOFF
:
2814 case UNSPEC_INDNTPOFF
:
2817 /* If the literal pool shares the code section, be put
2818 execute template placeholders into the pool as well. */
2820 return TARGET_CPU_ZARCH
;
2832 /* Returns true if the constant value OP is a legitimate general
2833 operand during and after reload. The difference to
2834 legitimate_constant_p is that this function will not accept
2835 a constant that would need to be forced to the literal pool
2836 before it can be used as operand.
2837 This function accepts all constants which can be loaded directly
2841 legitimate_reload_constant_p (rtx op
)
2843 /* Accept la(y) operands. */
2844 if (GET_CODE (op
) == CONST_INT
2845 && DISP_IN_RANGE (INTVAL (op
)))
2848 /* Accept l(g)hi/l(g)fi operands. */
2849 if (GET_CODE (op
) == CONST_INT
2850 && (CONST_OK_FOR_K (INTVAL (op
)) || CONST_OK_FOR_Os (INTVAL (op
))))
2853 /* Accept lliXX operands. */
2855 && GET_CODE (op
) == CONST_INT
2856 && trunc_int_for_mode (INTVAL (op
), word_mode
) == INTVAL (op
)
2857 && s390_single_part (op
, word_mode
, HImode
, 0) >= 0)
2861 && GET_CODE (op
) == CONST_INT
2862 && trunc_int_for_mode (INTVAL (op
), word_mode
) == INTVAL (op
)
2863 && s390_single_part (op
, word_mode
, SImode
, 0) >= 0)
2866 /* Accept larl operands. */
2867 if (TARGET_CPU_ZARCH
2868 && larl_operand (op
, VOIDmode
))
2871 /* Accept floating-point zero operands that fit into a single GPR. */
2872 if (GET_CODE (op
) == CONST_DOUBLE
2873 && s390_float_const_zero_p (op
)
2874 && GET_MODE_SIZE (GET_MODE (op
)) <= UNITS_PER_WORD
)
2877 /* Accept double-word operands that can be split. */
2878 if (GET_CODE (op
) == CONST_INT
2879 && trunc_int_for_mode (INTVAL (op
), word_mode
) != INTVAL (op
))
2881 enum machine_mode dword_mode
= word_mode
== SImode
? DImode
: TImode
;
2882 rtx hi
= operand_subword (op
, 0, 0, dword_mode
);
2883 rtx lo
= operand_subword (op
, 1, 0, dword_mode
);
2884 return legitimate_reload_constant_p (hi
)
2885 && legitimate_reload_constant_p (lo
);
2888 /* Everything else cannot be handled without reload. */
2892 /* Returns true if the constant value OP is a legitimate fp operand
2893 during and after reload.
2894 This function accepts all constants which can be loaded directly
2898 legitimate_reload_fp_constant_p (rtx op
)
2900 /* Accept floating-point zero operands if the load zero instruction
2901 can be used. Prior to z196 the load fp zero instruction caused a
2902 performance penalty if the result is used as BFP number. */
2904 && GET_CODE (op
) == CONST_DOUBLE
2905 && s390_float_const_zero_p (op
))
2911 /* Given an rtx OP being reloaded into a reg required to be in class RCLASS,
2912 return the class of reg to actually use. */
2915 s390_preferred_reload_class (rtx op
, reg_class_t rclass
)
2917 switch (GET_CODE (op
))
2919 /* Constants we cannot reload into general registers
2920 must be forced into the literal pool. */
2923 if (reg_class_subset_p (GENERAL_REGS
, rclass
)
2924 && legitimate_reload_constant_p (op
))
2925 return GENERAL_REGS
;
2926 else if (reg_class_subset_p (ADDR_REGS
, rclass
)
2927 && legitimate_reload_constant_p (op
))
2929 else if (reg_class_subset_p (FP_REGS
, rclass
)
2930 && legitimate_reload_fp_constant_p (op
))
2934 /* If a symbolic constant or a PLUS is reloaded,
2935 it is most likely being used as an address, so
2936 prefer ADDR_REGS. If 'class' is not a superset
2937 of ADDR_REGS, e.g. FP_REGS, reject this reload. */
2939 /* Symrefs cannot be pushed into the literal pool with -fPIC
2940 so we *MUST NOT* return NO_REGS for these cases
2941 (s390_cannot_force_const_mem will return true).
2943 On the other hand we MUST return NO_REGS for symrefs with
2944 invalid addend which might have been pushed to the literal
2945 pool (no -fPIC). Usually we would expect them to be
2946 handled via secondary reload but this does not happen if
2947 they are used as literal pool slot replacement in reload
2948 inheritance (see emit_input_reload_insns). */
2949 if (TARGET_CPU_ZARCH
2950 && GET_CODE (XEXP (op
, 0)) == PLUS
2951 && GET_CODE (XEXP (XEXP(op
, 0), 0)) == SYMBOL_REF
2952 && GET_CODE (XEXP (XEXP(op
, 0), 1)) == CONST_INT
)
2954 if (flag_pic
&& reg_class_subset_p (ADDR_REGS
, rclass
))
2962 if (!legitimate_reload_constant_p (op
))
2966 /* load address will be used. */
2967 if (reg_class_subset_p (ADDR_REGS
, rclass
))
2979 /* Return true if ADDR is SYMBOL_REF + addend with addend being a
2980 multiple of ALIGNMENT and the SYMBOL_REF being naturally
2984 s390_check_symref_alignment (rtx addr
, HOST_WIDE_INT alignment
)
2986 HOST_WIDE_INT addend
;
2989 if (!s390_loadrelative_operand_p (addr
, &symref
, &addend
))
2992 if (addend
& (alignment
- 1))
2995 if (GET_CODE (symref
) == SYMBOL_REF
2996 && !SYMBOL_REF_NOT_NATURALLY_ALIGNED_P (symref
))
2999 if (GET_CODE (symref
) == UNSPEC
3000 && alignment
<= UNITS_PER_LONG
)
3006 /* ADDR is moved into REG using larl. If ADDR isn't a valid larl
3007 operand SCRATCH is used to reload the even part of the address and
3011 s390_reload_larl_operand (rtx reg
, rtx addr
, rtx scratch
)
3013 HOST_WIDE_INT addend
;
3016 if (!s390_loadrelative_operand_p (addr
, &symref
, &addend
))
3020 /* Easy case. The addend is even so larl will do fine. */
3021 emit_move_insn (reg
, addr
);
3024 /* We can leave the scratch register untouched if the target
3025 register is a valid base register. */
3026 if (REGNO (reg
) < FIRST_PSEUDO_REGISTER
3027 && REGNO_REG_CLASS (REGNO (reg
)) == ADDR_REGS
)
3030 gcc_assert (REGNO (scratch
) < FIRST_PSEUDO_REGISTER
);
3031 gcc_assert (REGNO_REG_CLASS (REGNO (scratch
)) == ADDR_REGS
);
3034 emit_move_insn (scratch
,
3035 gen_rtx_CONST (Pmode
,
3036 gen_rtx_PLUS (Pmode
, symref
,
3037 GEN_INT (addend
- 1))));
3039 emit_move_insn (scratch
, symref
);
3041 /* Increment the address using la in order to avoid clobbering cc. */
3042 s390_load_address (reg
, gen_rtx_PLUS (Pmode
, scratch
, const1_rtx
));
3046 /* Generate what is necessary to move between REG and MEM using
3047 SCRATCH. The direction is given by TOMEM. */
3050 s390_reload_symref_address (rtx reg
, rtx mem
, rtx scratch
, bool tomem
)
3052 /* Reload might have pulled a constant out of the literal pool.
3053 Force it back in. */
3054 if (CONST_INT_P (mem
) || GET_CODE (mem
) == CONST_DOUBLE
3055 || GET_CODE (mem
) == CONST
)
3056 mem
= force_const_mem (GET_MODE (reg
), mem
);
3058 gcc_assert (MEM_P (mem
));
3060 /* For a load from memory we can leave the scratch register
3061 untouched if the target register is a valid base register. */
3063 && REGNO (reg
) < FIRST_PSEUDO_REGISTER
3064 && REGNO_REG_CLASS (REGNO (reg
)) == ADDR_REGS
3065 && GET_MODE (reg
) == GET_MODE (scratch
))
3068 /* Load address into scratch register. Since we can't have a
3069 secondary reload for a secondary reload we have to cover the case
3070 where larl would need a secondary reload here as well. */
3071 s390_reload_larl_operand (scratch
, XEXP (mem
, 0), scratch
);
3073 /* Now we can use a standard load/store to do the move. */
3075 emit_move_insn (replace_equiv_address (mem
, scratch
), reg
);
3077 emit_move_insn (reg
, replace_equiv_address (mem
, scratch
));
3080 /* Inform reload about cases where moving X with a mode MODE to a register in
3081 RCLASS requires an extra scratch or immediate register. Return the class
3082 needed for the immediate register. */
3085 s390_secondary_reload (bool in_p
, rtx x
, reg_class_t rclass_i
,
3086 enum machine_mode mode
, secondary_reload_info
*sri
)
3088 enum reg_class rclass
= (enum reg_class
) rclass_i
;
3090 /* Intermediate register needed. */
3091 if (reg_classes_intersect_p (CC_REGS
, rclass
))
3092 return GENERAL_REGS
;
3096 HOST_WIDE_INT offset
;
3099 /* On z10 several optimizer steps may generate larl operands with
3102 && s390_loadrelative_operand_p (x
, &symref
, &offset
)
3104 && !SYMBOL_REF_ALIGN1_P (symref
)
3105 && (offset
& 1) == 1)
3106 sri
->icode
= ((mode
== DImode
) ? CODE_FOR_reloaddi_larl_odd_addend_z10
3107 : CODE_FOR_reloadsi_larl_odd_addend_z10
);
3109 /* On z10 we need a scratch register when moving QI, TI or floating
3110 point mode values from or to a memory location with a SYMBOL_REF
3111 or if the symref addend of a SI or DI move is not aligned to the
3112 width of the access. */
3114 && s390_loadrelative_operand_p (XEXP (x
, 0), NULL
, NULL
)
3115 && (mode
== QImode
|| mode
== TImode
|| FLOAT_MODE_P (mode
)
3116 || (!TARGET_ZARCH
&& mode
== DImode
)
3117 || ((mode
== HImode
|| mode
== SImode
|| mode
== DImode
)
3118 && (!s390_check_symref_alignment (XEXP (x
, 0),
3119 GET_MODE_SIZE (mode
))))))
3121 #define __SECONDARY_RELOAD_CASE(M,m) \
3124 sri->icode = in_p ? CODE_FOR_reload##m##di_toreg_z10 : \
3125 CODE_FOR_reload##m##di_tomem_z10; \
3127 sri->icode = in_p ? CODE_FOR_reload##m##si_toreg_z10 : \
3128 CODE_FOR_reload##m##si_tomem_z10; \
3131 switch (GET_MODE (x
))
3133 __SECONDARY_RELOAD_CASE (QI
, qi
);
3134 __SECONDARY_RELOAD_CASE (HI
, hi
);
3135 __SECONDARY_RELOAD_CASE (SI
, si
);
3136 __SECONDARY_RELOAD_CASE (DI
, di
);
3137 __SECONDARY_RELOAD_CASE (TI
, ti
);
3138 __SECONDARY_RELOAD_CASE (SF
, sf
);
3139 __SECONDARY_RELOAD_CASE (DF
, df
);
3140 __SECONDARY_RELOAD_CASE (TF
, tf
);
3141 __SECONDARY_RELOAD_CASE (SD
, sd
);
3142 __SECONDARY_RELOAD_CASE (DD
, dd
);
3143 __SECONDARY_RELOAD_CASE (TD
, td
);
3148 #undef __SECONDARY_RELOAD_CASE
3152 /* We need a scratch register when loading a PLUS expression which
3153 is not a legitimate operand of the LOAD ADDRESS instruction. */
3154 /* LRA can deal with transformation of plus op very well -- so we
3155 don't need to prompt LRA in this case. */
3156 if (! lra_in_progress
&& in_p
&& s390_plus_operand (x
, mode
))
3157 sri
->icode
= (TARGET_64BIT
?
3158 CODE_FOR_reloaddi_plus
: CODE_FOR_reloadsi_plus
);
3160 /* Performing a multiword move from or to memory we have to make sure the
3161 second chunk in memory is addressable without causing a displacement
3162 overflow. If that would be the case we calculate the address in
3163 a scratch register. */
3165 && GET_CODE (XEXP (x
, 0)) == PLUS
3166 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
3167 && !DISP_IN_RANGE (INTVAL (XEXP (XEXP (x
, 0), 1))
3168 + GET_MODE_SIZE (mode
) - 1))
3170 /* For GENERAL_REGS a displacement overflow is no problem if occurring
3171 in a s_operand address since we may fallback to lm/stm. So we only
3172 have to care about overflows in the b+i+d case. */
3173 if ((reg_classes_intersect_p (GENERAL_REGS
, rclass
)
3174 && s390_class_max_nregs (GENERAL_REGS
, mode
) > 1
3175 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == PLUS
)
3176 /* For FP_REGS no lm/stm is available so this check is triggered
3177 for displacement overflows in b+i+d and b+d like addresses. */
3178 || (reg_classes_intersect_p (FP_REGS
, rclass
)
3179 && s390_class_max_nregs (FP_REGS
, mode
) > 1))
3182 sri
->icode
= (TARGET_64BIT
?
3183 CODE_FOR_reloaddi_nonoffmem_in
:
3184 CODE_FOR_reloadsi_nonoffmem_in
);
3186 sri
->icode
= (TARGET_64BIT
?
3187 CODE_FOR_reloaddi_nonoffmem_out
:
3188 CODE_FOR_reloadsi_nonoffmem_out
);
3192 /* A scratch address register is needed when a symbolic constant is
3193 copied to r0 compiling with -fPIC. In other cases the target
3194 register might be used as temporary (see legitimize_pic_address). */
3195 if (in_p
&& SYMBOLIC_CONST (x
) && flag_pic
== 2 && rclass
!= ADDR_REGS
)
3196 sri
->icode
= (TARGET_64BIT
?
3197 CODE_FOR_reloaddi_PIC_addr
:
3198 CODE_FOR_reloadsi_PIC_addr
);
3200 /* Either scratch or no register needed. */
3204 /* Generate code to load SRC, which is PLUS that is not a
3205 legitimate operand for the LA instruction, into TARGET.
3206 SCRATCH may be used as scratch register. */
3209 s390_expand_plus_operand (rtx target
, rtx src
,
3213 struct s390_address ad
;
3215 /* src must be a PLUS; get its two operands. */
3216 gcc_assert (GET_CODE (src
) == PLUS
);
3217 gcc_assert (GET_MODE (src
) == Pmode
);
3219 /* Check if any of the two operands is already scheduled
3220 for replacement by reload. This can happen e.g. when
3221 float registers occur in an address. */
3222 sum1
= find_replacement (&XEXP (src
, 0));
3223 sum2
= find_replacement (&XEXP (src
, 1));
3224 src
= gen_rtx_PLUS (Pmode
, sum1
, sum2
);
3226 /* If the address is already strictly valid, there's nothing to do. */
3227 if (!s390_decompose_address (src
, &ad
)
3228 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
3229 || (ad
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (ad
.indx
))))
3231 /* Otherwise, one of the operands cannot be an address register;
3232 we reload its value into the scratch register. */
3233 if (true_regnum (sum1
) < 1 || true_regnum (sum1
) > 15)
3235 emit_move_insn (scratch
, sum1
);
3238 if (true_regnum (sum2
) < 1 || true_regnum (sum2
) > 15)
3240 emit_move_insn (scratch
, sum2
);
3244 /* According to the way these invalid addresses are generated
3245 in reload.c, it should never happen (at least on s390) that
3246 *neither* of the PLUS components, after find_replacements
3247 was applied, is an address register. */
3248 if (sum1
== scratch
&& sum2
== scratch
)
3254 src
= gen_rtx_PLUS (Pmode
, sum1
, sum2
);
3257 /* Emit the LOAD ADDRESS pattern. Note that reload of PLUS
3258 is only ever performed on addresses, so we can mark the
3259 sum as legitimate for LA in any case. */
3260 s390_load_address (target
, src
);
3264 /* Return true if ADDR is a valid memory address.
3265 STRICT specifies whether strict register checking applies. */
3268 s390_legitimate_address_p (enum machine_mode mode
, rtx addr
, bool strict
)
3270 struct s390_address ad
;
3273 && larl_operand (addr
, VOIDmode
)
3274 && (mode
== VOIDmode
3275 || s390_check_symref_alignment (addr
, GET_MODE_SIZE (mode
))))
3278 if (!s390_decompose_address (addr
, &ad
))
3283 if (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
3286 if (ad
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (ad
.indx
)))
3292 && !(REGNO (ad
.base
) >= FIRST_PSEUDO_REGISTER
3293 || REGNO_REG_CLASS (REGNO (ad
.base
)) == ADDR_REGS
))
3297 && !(REGNO (ad
.indx
) >= FIRST_PSEUDO_REGISTER
3298 || REGNO_REG_CLASS (REGNO (ad
.indx
)) == ADDR_REGS
))
3304 /* Return true if OP is a valid operand for the LA instruction.
3305 In 31-bit, we need to prove that the result is used as an
3306 address, as LA performs only a 31-bit addition. */
3309 legitimate_la_operand_p (rtx op
)
3311 struct s390_address addr
;
3312 if (!s390_decompose_address (op
, &addr
))
3315 return (TARGET_64BIT
|| addr
.pointer
);
3318 /* Return true if it is valid *and* preferable to use LA to
3319 compute the sum of OP1 and OP2. */
3322 preferred_la_operand_p (rtx op1
, rtx op2
)
3324 struct s390_address addr
;
3326 if (op2
!= const0_rtx
)
3327 op1
= gen_rtx_PLUS (Pmode
, op1
, op2
);
3329 if (!s390_decompose_address (op1
, &addr
))
3331 if (addr
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (addr
.base
)))
3333 if (addr
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (addr
.indx
)))
3336 /* Avoid LA instructions with index register on z196; it is
3337 preferable to use regular add instructions when possible.
3338 Starting with zEC12 the la with index register is "uncracked"
3340 if (addr
.indx
&& s390_tune
== PROCESSOR_2817_Z196
)
3343 if (!TARGET_64BIT
&& !addr
.pointer
)
3349 if ((addr
.base
&& REG_P (addr
.base
) && REG_POINTER (addr
.base
))
3350 || (addr
.indx
&& REG_P (addr
.indx
) && REG_POINTER (addr
.indx
)))
3356 /* Emit a forced load-address operation to load SRC into DST.
3357 This will use the LOAD ADDRESS instruction even in situations
3358 where legitimate_la_operand_p (SRC) returns false. */
3361 s390_load_address (rtx dst
, rtx src
)
3364 emit_move_insn (dst
, src
);
3366 emit_insn (gen_force_la_31 (dst
, src
));
3369 /* Return a legitimate reference for ORIG (an address) using the
3370 register REG. If REG is 0, a new pseudo is generated.
3372 There are two types of references that must be handled:
3374 1. Global data references must load the address from the GOT, via
3375 the PIC reg. An insn is emitted to do this load, and the reg is
3378 2. Static data references, constant pool addresses, and code labels
3379 compute the address as an offset from the GOT, whose base is in
3380 the PIC reg. Static data objects have SYMBOL_FLAG_LOCAL set to
3381 differentiate them from global data objects. The returned
3382 address is the PIC reg + an unspec constant.
3384 TARGET_LEGITIMIZE_ADDRESS_P rejects symbolic references unless the PIC
3385 reg also appears in the address. */
3388 legitimize_pic_address (rtx orig
, rtx reg
)
3391 rtx addend
= const0_rtx
;
3394 gcc_assert (!TLS_SYMBOLIC_CONST (addr
));
3396 if (GET_CODE (addr
) == CONST
)
3397 addr
= XEXP (addr
, 0);
3399 if (GET_CODE (addr
) == PLUS
)
3401 addend
= XEXP (addr
, 1);
3402 addr
= XEXP (addr
, 0);
3405 if ((GET_CODE (addr
) == LABEL_REF
3406 || (GET_CODE (addr
) == SYMBOL_REF
&& SYMBOL_REF_LOCAL_P (addr
))
3407 || (GET_CODE (addr
) == UNSPEC
&&
3408 (XINT (addr
, 1) == UNSPEC_GOTENT
3409 || (TARGET_CPU_ZARCH
&& XINT (addr
, 1) == UNSPEC_PLT
))))
3410 && GET_CODE (addend
) == CONST_INT
)
3412 /* This can be locally addressed. */
3414 /* larl_operand requires UNSPECs to be wrapped in a const rtx. */
3415 rtx const_addr
= (GET_CODE (addr
) == UNSPEC
?
3416 gen_rtx_CONST (Pmode
, addr
) : addr
);
3418 if (TARGET_CPU_ZARCH
3419 && larl_operand (const_addr
, VOIDmode
)
3420 && INTVAL (addend
) < (HOST_WIDE_INT
)1 << 31
3421 && INTVAL (addend
) >= -((HOST_WIDE_INT
)1 << 31))
3423 if (INTVAL (addend
) & 1)
3425 /* LARL can't handle odd offsets, so emit a pair of LARL
3427 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3429 if (!DISP_IN_RANGE (INTVAL (addend
)))
3431 HOST_WIDE_INT even
= INTVAL (addend
) - 1;
3432 addr
= gen_rtx_PLUS (Pmode
, addr
, GEN_INT (even
));
3433 addr
= gen_rtx_CONST (Pmode
, addr
);
3434 addend
= const1_rtx
;
3437 emit_move_insn (temp
, addr
);
3438 new_rtx
= gen_rtx_PLUS (Pmode
, temp
, addend
);
3442 s390_load_address (reg
, new_rtx
);
3448 /* If the offset is even, we can just use LARL. This
3449 will happen automatically. */
3454 /* No larl - Access local symbols relative to the GOT. */
3456 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3458 if (reload_in_progress
|| reload_completed
)
3459 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3461 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTOFF
);
3462 if (addend
!= const0_rtx
)
3463 addr
= gen_rtx_PLUS (Pmode
, addr
, addend
);
3464 addr
= gen_rtx_CONST (Pmode
, addr
);
3465 addr
= force_const_mem (Pmode
, addr
);
3466 emit_move_insn (temp
, addr
);
3468 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3471 s390_load_address (reg
, new_rtx
);
3476 else if (GET_CODE (addr
) == SYMBOL_REF
&& addend
== const0_rtx
)
3478 /* A non-local symbol reference without addend.
3480 The symbol ref is wrapped into an UNSPEC to make sure the
3481 proper operand modifier (@GOT or @GOTENT) will be emitted.
3482 This will tell the linker to put the symbol into the GOT.
3484 Additionally the code dereferencing the GOT slot is emitted here.
3486 An addend to the symref needs to be added afterwards.
3487 legitimize_pic_address calls itself recursively to handle
3488 that case. So no need to do it here. */
3491 reg
= gen_reg_rtx (Pmode
);
3495 /* Use load relative if possible.
3496 lgrl <target>, sym@GOTENT */
3497 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTENT
);
3498 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3499 new_rtx
= gen_const_mem (GET_MODE (reg
), new_rtx
);
3501 emit_move_insn (reg
, new_rtx
);
3504 else if (flag_pic
== 1)
3506 /* Assume GOT offset is a valid displacement operand (< 4k
3507 or < 512k with z990). This is handled the same way in
3508 both 31- and 64-bit code (@GOT).
3509 lg <target>, sym@GOT(r12) */
3511 if (reload_in_progress
|| reload_completed
)
3512 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3514 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOT
);
3515 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3516 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, new_rtx
);
3517 new_rtx
= gen_const_mem (Pmode
, new_rtx
);
3518 emit_move_insn (reg
, new_rtx
);
3521 else if (TARGET_CPU_ZARCH
)
3523 /* If the GOT offset might be >= 4k, we determine the position
3524 of the GOT entry via a PC-relative LARL (@GOTENT).
3525 larl temp, sym@GOTENT
3526 lg <target>, 0(temp) */
3528 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3530 gcc_assert (REGNO (temp
) >= FIRST_PSEUDO_REGISTER
3531 || REGNO_REG_CLASS (REGNO (temp
)) == ADDR_REGS
);
3533 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTENT
);
3534 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3535 emit_move_insn (temp
, new_rtx
);
3537 new_rtx
= gen_const_mem (Pmode
, temp
);
3538 emit_move_insn (reg
, new_rtx
);
3544 /* If the GOT offset might be >= 4k, we have to load it
3545 from the literal pool (@GOT).
3547 lg temp, lit-litbase(r13)
3548 lg <target>, 0(temp)
3549 lit: .long sym@GOT */
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 if (reload_in_progress
|| reload_completed
)
3557 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3559 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOT
);
3560 addr
= gen_rtx_CONST (Pmode
, addr
);
3561 addr
= force_const_mem (Pmode
, addr
);
3562 emit_move_insn (temp
, addr
);
3564 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3565 new_rtx
= gen_const_mem (Pmode
, new_rtx
);
3566 emit_move_insn (reg
, new_rtx
);
3570 else if (GET_CODE (addr
) == UNSPEC
&& GET_CODE (addend
) == CONST_INT
)
3572 gcc_assert (XVECLEN (addr
, 0) == 1);
3573 switch (XINT (addr
, 1))
3575 /* These address symbols (or PLT slots) relative to the GOT
3576 (not GOT slots!). In general this will exceed the
3577 displacement range so these value belong into the literal
3581 new_rtx
= force_const_mem (Pmode
, orig
);
3584 /* For -fPIC the GOT size might exceed the displacement
3585 range so make sure the value is in the literal pool. */
3588 new_rtx
= force_const_mem (Pmode
, orig
);
3591 /* For @GOTENT larl is used. This is handled like local
3597 /* @PLT is OK as is on 64-bit, must be converted to
3598 GOT-relative @PLTOFF on 31-bit. */
3600 if (!TARGET_CPU_ZARCH
)
3602 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3604 if (reload_in_progress
|| reload_completed
)
3605 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3607 addr
= XVECEXP (addr
, 0, 0);
3608 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
),
3610 if (addend
!= const0_rtx
)
3611 addr
= gen_rtx_PLUS (Pmode
, addr
, addend
);
3612 addr
= gen_rtx_CONST (Pmode
, addr
);
3613 addr
= force_const_mem (Pmode
, addr
);
3614 emit_move_insn (temp
, addr
);
3616 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3619 s390_load_address (reg
, new_rtx
);
3624 /* On 64 bit larl can be used. This case is handled like
3625 local symbol refs. */
3629 /* Everything else cannot happen. */
3634 else if (addend
!= const0_rtx
)
3636 /* Otherwise, compute the sum. */
3638 rtx base
= legitimize_pic_address (addr
, reg
);
3639 new_rtx
= legitimize_pic_address (addend
,
3640 base
== reg
? NULL_RTX
: reg
);
3641 if (GET_CODE (new_rtx
) == CONST_INT
)
3642 new_rtx
= plus_constant (Pmode
, base
, INTVAL (new_rtx
));
3645 if (GET_CODE (new_rtx
) == PLUS
&& CONSTANT_P (XEXP (new_rtx
, 1)))
3647 base
= gen_rtx_PLUS (Pmode
, base
, XEXP (new_rtx
, 0));
3648 new_rtx
= XEXP (new_rtx
, 1);
3650 new_rtx
= gen_rtx_PLUS (Pmode
, base
, new_rtx
);
3653 if (GET_CODE (new_rtx
) == CONST
)
3654 new_rtx
= XEXP (new_rtx
, 0);
3655 new_rtx
= force_operand (new_rtx
, 0);
3661 /* Load the thread pointer into a register. */
3664 s390_get_thread_pointer (void)
3666 rtx tp
= gen_reg_rtx (Pmode
);
3668 emit_move_insn (tp
, gen_rtx_REG (Pmode
, TP_REGNUM
));
3669 mark_reg_pointer (tp
, BITS_PER_WORD
);
3674 /* Emit a tls call insn. The call target is the SYMBOL_REF stored
3675 in s390_tls_symbol which always refers to __tls_get_offset.
3676 The returned offset is written to RESULT_REG and an USE rtx is
3677 generated for TLS_CALL. */
3679 static GTY(()) rtx s390_tls_symbol
;
3682 s390_emit_tls_call_insn (rtx result_reg
, rtx tls_call
)
3687 emit_insn (s390_load_got ());
3689 if (!s390_tls_symbol
)
3690 s390_tls_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "__tls_get_offset");
3692 insn
= s390_emit_call (s390_tls_symbol
, tls_call
, result_reg
,
3693 gen_rtx_REG (Pmode
, RETURN_REGNUM
));
3695 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), result_reg
);
3696 RTL_CONST_CALL_P (insn
) = 1;
3699 /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
3700 this (thread-local) address. REG may be used as temporary. */
3703 legitimize_tls_address (rtx addr
, rtx reg
)
3705 rtx new_rtx
, tls_call
, temp
, base
, r2
, insn
;
3707 if (GET_CODE (addr
) == SYMBOL_REF
)
3708 switch (tls_symbolic_operand (addr
))
3710 case TLS_MODEL_GLOBAL_DYNAMIC
:
3712 r2
= gen_rtx_REG (Pmode
, 2);
3713 tls_call
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_TLSGD
);
3714 new_rtx
= gen_rtx_CONST (Pmode
, tls_call
);
3715 new_rtx
= force_const_mem (Pmode
, new_rtx
);
3716 emit_move_insn (r2
, new_rtx
);
3717 s390_emit_tls_call_insn (r2
, tls_call
);
3718 insn
= get_insns ();
3721 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_NTPOFF
);
3722 temp
= gen_reg_rtx (Pmode
);
3723 emit_libcall_block (insn
, temp
, r2
, new_rtx
);
3725 new_rtx
= gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3728 s390_load_address (reg
, new_rtx
);
3733 case TLS_MODEL_LOCAL_DYNAMIC
:
3735 r2
= gen_rtx_REG (Pmode
, 2);
3736 tls_call
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, const0_rtx
), UNSPEC_TLSLDM
);
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, const0_rtx
), UNSPEC_TLSLDM_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
);
3749 base
= gen_reg_rtx (Pmode
);
3750 s390_load_address (base
, new_rtx
);
3752 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_DTPOFF
);
3753 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3754 new_rtx
= force_const_mem (Pmode
, new_rtx
);
3755 temp
= gen_reg_rtx (Pmode
);
3756 emit_move_insn (temp
, new_rtx
);
3758 new_rtx
= gen_rtx_PLUS (Pmode
, base
, temp
);
3761 s390_load_address (reg
, new_rtx
);
3766 case TLS_MODEL_INITIAL_EXEC
:
3769 /* Assume GOT offset < 4k. This is handled the same way
3770 in both 31- and 64-bit code. */
3772 if (reload_in_progress
|| reload_completed
)
3773 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3775 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTNTPOFF
);
3776 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3777 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, new_rtx
);
3778 new_rtx
= gen_const_mem (Pmode
, new_rtx
);
3779 temp
= gen_reg_rtx (Pmode
);
3780 emit_move_insn (temp
, new_rtx
);
3782 else if (TARGET_CPU_ZARCH
)
3784 /* If the GOT offset might be >= 4k, we determine the position
3785 of the GOT entry via a PC-relative LARL. */
3787 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_INDNTPOFF
);
3788 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3789 temp
= gen_reg_rtx (Pmode
);
3790 emit_move_insn (temp
, new_rtx
);
3792 new_rtx
= gen_const_mem (Pmode
, temp
);
3793 temp
= gen_reg_rtx (Pmode
);
3794 emit_move_insn (temp
, new_rtx
);
3798 /* If the GOT offset might be >= 4k, we have to load it
3799 from the literal pool. */
3801 if (reload_in_progress
|| reload_completed
)
3802 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3804 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTNTPOFF
);
3805 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3806 new_rtx
= force_const_mem (Pmode
, new_rtx
);
3807 temp
= gen_reg_rtx (Pmode
);
3808 emit_move_insn (temp
, new_rtx
);
3810 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3811 new_rtx
= gen_const_mem (Pmode
, new_rtx
);
3813 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, new_rtx
, addr
), UNSPEC_TLS_LOAD
);
3814 temp
= gen_reg_rtx (Pmode
);
3815 emit_insn (gen_rtx_SET (Pmode
, temp
, new_rtx
));
3819 /* In position-dependent code, load the absolute address of
3820 the GOT entry from the literal pool. */
3822 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_INDNTPOFF
);
3823 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3824 new_rtx
= force_const_mem (Pmode
, new_rtx
);
3825 temp
= gen_reg_rtx (Pmode
);
3826 emit_move_insn (temp
, new_rtx
);
3829 new_rtx
= gen_const_mem (Pmode
, new_rtx
);
3830 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, new_rtx
, addr
), UNSPEC_TLS_LOAD
);
3831 temp
= gen_reg_rtx (Pmode
);
3832 emit_insn (gen_rtx_SET (Pmode
, temp
, new_rtx
));
3835 new_rtx
= gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3838 s390_load_address (reg
, new_rtx
);
3843 case TLS_MODEL_LOCAL_EXEC
:
3844 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_NTPOFF
);
3845 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3846 new_rtx
= force_const_mem (Pmode
, new_rtx
);
3847 temp
= gen_reg_rtx (Pmode
);
3848 emit_move_insn (temp
, new_rtx
);
3850 new_rtx
= gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3853 s390_load_address (reg
, new_rtx
);
3862 else if (GET_CODE (addr
) == CONST
&& GET_CODE (XEXP (addr
, 0)) == UNSPEC
)
3864 switch (XINT (XEXP (addr
, 0), 1))
3866 case UNSPEC_INDNTPOFF
:
3867 gcc_assert (TARGET_CPU_ZARCH
);
3876 else if (GET_CODE (addr
) == CONST
&& GET_CODE (XEXP (addr
, 0)) == PLUS
3877 && GET_CODE (XEXP (XEXP (addr
, 0), 1)) == CONST_INT
)
3879 new_rtx
= XEXP (XEXP (addr
, 0), 0);
3880 if (GET_CODE (new_rtx
) != SYMBOL_REF
)
3881 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3883 new_rtx
= legitimize_tls_address (new_rtx
, reg
);
3884 new_rtx
= plus_constant (Pmode
, new_rtx
,
3885 INTVAL (XEXP (XEXP (addr
, 0), 1)));
3886 new_rtx
= force_operand (new_rtx
, 0);
3890 gcc_unreachable (); /* for now ... */
3895 /* Emit insns making the address in operands[1] valid for a standard
3896 move to operands[0]. operands[1] is replaced by an address which
3897 should be used instead of the former RTX to emit the move
3901 emit_symbolic_move (rtx
*operands
)
3903 rtx temp
= !can_create_pseudo_p () ? operands
[0] : gen_reg_rtx (Pmode
);
3905 if (GET_CODE (operands
[0]) == MEM
)
3906 operands
[1] = force_reg (Pmode
, operands
[1]);
3907 else if (TLS_SYMBOLIC_CONST (operands
[1]))
3908 operands
[1] = legitimize_tls_address (operands
[1], temp
);
3910 operands
[1] = legitimize_pic_address (operands
[1], temp
);
3913 /* Try machine-dependent ways of modifying an illegitimate address X
3914 to be legitimate. If we find one, return the new, valid address.
3916 OLDX is the address as it was before break_out_memory_refs was called.
3917 In some cases it is useful to look at this to decide what needs to be done.
3919 MODE is the mode of the operand pointed to by X.
3921 When -fpic is used, special handling is needed for symbolic references.
3922 See comments by legitimize_pic_address for details. */
3925 s390_legitimize_address (rtx x
, rtx oldx ATTRIBUTE_UNUSED
,
3926 enum machine_mode mode ATTRIBUTE_UNUSED
)
3928 rtx constant_term
= const0_rtx
;
3930 if (TLS_SYMBOLIC_CONST (x
))
3932 x
= legitimize_tls_address (x
, 0);
3934 if (s390_legitimate_address_p (mode
, x
, FALSE
))
3937 else if (GET_CODE (x
) == PLUS
3938 && (TLS_SYMBOLIC_CONST (XEXP (x
, 0))
3939 || TLS_SYMBOLIC_CONST (XEXP (x
, 1))))
3945 if (SYMBOLIC_CONST (x
)
3946 || (GET_CODE (x
) == PLUS
3947 && (SYMBOLIC_CONST (XEXP (x
, 0))
3948 || SYMBOLIC_CONST (XEXP (x
, 1)))))
3949 x
= legitimize_pic_address (x
, 0);
3951 if (s390_legitimate_address_p (mode
, x
, FALSE
))
3955 x
= eliminate_constant_term (x
, &constant_term
);
3957 /* Optimize loading of large displacements by splitting them
3958 into the multiple of 4K and the rest; this allows the
3959 former to be CSE'd if possible.
3961 Don't do this if the displacement is added to a register
3962 pointing into the stack frame, as the offsets will
3963 change later anyway. */
3965 if (GET_CODE (constant_term
) == CONST_INT
3966 && !TARGET_LONG_DISPLACEMENT
3967 && !DISP_IN_RANGE (INTVAL (constant_term
))
3968 && !(REG_P (x
) && REGNO_PTR_FRAME_P (REGNO (x
))))
3970 HOST_WIDE_INT lower
= INTVAL (constant_term
) & 0xfff;
3971 HOST_WIDE_INT upper
= INTVAL (constant_term
) ^ lower
;
3973 rtx temp
= gen_reg_rtx (Pmode
);
3974 rtx val
= force_operand (GEN_INT (upper
), temp
);
3976 emit_move_insn (temp
, val
);
3978 x
= gen_rtx_PLUS (Pmode
, x
, temp
);
3979 constant_term
= GEN_INT (lower
);
3982 if (GET_CODE (x
) == PLUS
)
3984 if (GET_CODE (XEXP (x
, 0)) == REG
)
3986 rtx temp
= gen_reg_rtx (Pmode
);
3987 rtx val
= force_operand (XEXP (x
, 1), temp
);
3989 emit_move_insn (temp
, val
);
3991 x
= gen_rtx_PLUS (Pmode
, XEXP (x
, 0), temp
);
3994 else if (GET_CODE (XEXP (x
, 1)) == REG
)
3996 rtx temp
= gen_reg_rtx (Pmode
);
3997 rtx val
= force_operand (XEXP (x
, 0), temp
);
3999 emit_move_insn (temp
, val
);
4001 x
= gen_rtx_PLUS (Pmode
, temp
, XEXP (x
, 1));
4005 if (constant_term
!= const0_rtx
)
4006 x
= gen_rtx_PLUS (Pmode
, x
, constant_term
);
4011 /* Try a machine-dependent way of reloading an illegitimate address AD
4012 operand. If we find one, push the reload and return the new address.
4014 MODE is the mode of the enclosing MEM. OPNUM is the operand number
4015 and TYPE is the reload type of the current reload. */
4018 legitimize_reload_address (rtx ad
, enum machine_mode mode ATTRIBUTE_UNUSED
,
4019 int opnum
, int type
)
4021 if (!optimize
|| TARGET_LONG_DISPLACEMENT
)
4024 if (GET_CODE (ad
) == PLUS
)
4026 rtx tem
= simplify_binary_operation (PLUS
, Pmode
,
4027 XEXP (ad
, 0), XEXP (ad
, 1));
4032 if (GET_CODE (ad
) == PLUS
4033 && GET_CODE (XEXP (ad
, 0)) == REG
4034 && GET_CODE (XEXP (ad
, 1)) == CONST_INT
4035 && !DISP_IN_RANGE (INTVAL (XEXP (ad
, 1))))
4037 HOST_WIDE_INT lower
= INTVAL (XEXP (ad
, 1)) & 0xfff;
4038 HOST_WIDE_INT upper
= INTVAL (XEXP (ad
, 1)) ^ lower
;
4039 rtx cst
, tem
, new_rtx
;
4041 cst
= GEN_INT (upper
);
4042 if (!legitimate_reload_constant_p (cst
))
4043 cst
= force_const_mem (Pmode
, cst
);
4045 tem
= gen_rtx_PLUS (Pmode
, XEXP (ad
, 0), cst
);
4046 new_rtx
= gen_rtx_PLUS (Pmode
, tem
, GEN_INT (lower
));
4048 push_reload (XEXP (tem
, 1), 0, &XEXP (tem
, 1), 0,
4049 BASE_REG_CLASS
, Pmode
, VOIDmode
, 0, 0,
4050 opnum
, (enum reload_type
) type
);
4057 /* Emit code to move LEN bytes from DST to SRC. */
4060 s390_expand_movmem (rtx dst
, rtx src
, rtx len
)
4062 /* When tuning for z10 or higher we rely on the Glibc functions to
4063 do the right thing. Only for constant lengths below 64k we will
4064 generate inline code. */
4065 if (s390_tune
>= PROCESSOR_2097_Z10
4066 && (GET_CODE (len
) != CONST_INT
|| INTVAL (len
) > (1<<16)))
4069 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) >= 0 && INTVAL (len
) <= 256)
4071 if (INTVAL (len
) > 0)
4072 emit_insn (gen_movmem_short (dst
, src
, GEN_INT (INTVAL (len
) - 1)));
4075 else if (TARGET_MVCLE
)
4077 emit_insn (gen_movmem_long (dst
, src
, convert_to_mode (Pmode
, len
, 1)));
4082 rtx dst_addr
, src_addr
, count
, blocks
, temp
;
4083 rtx_code_label
*loop_start_label
= gen_label_rtx ();
4084 rtx_code_label
*loop_end_label
= gen_label_rtx ();
4085 rtx_code_label
*end_label
= gen_label_rtx ();
4086 enum machine_mode mode
;
4088 mode
= GET_MODE (len
);
4089 if (mode
== VOIDmode
)
4092 dst_addr
= gen_reg_rtx (Pmode
);
4093 src_addr
= gen_reg_rtx (Pmode
);
4094 count
= gen_reg_rtx (mode
);
4095 blocks
= gen_reg_rtx (mode
);
4097 convert_move (count
, len
, 1);
4098 emit_cmp_and_jump_insns (count
, const0_rtx
,
4099 EQ
, NULL_RTX
, mode
, 1, end_label
);
4101 emit_move_insn (dst_addr
, force_operand (XEXP (dst
, 0), NULL_RTX
));
4102 emit_move_insn (src_addr
, force_operand (XEXP (src
, 0), NULL_RTX
));
4103 dst
= change_address (dst
, VOIDmode
, dst_addr
);
4104 src
= change_address (src
, VOIDmode
, src_addr
);
4106 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1,
4109 emit_move_insn (count
, temp
);
4111 temp
= expand_binop (mode
, lshr_optab
, count
, GEN_INT (8), blocks
, 1,
4114 emit_move_insn (blocks
, temp
);
4116 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
4117 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
4119 emit_label (loop_start_label
);
4122 && (GET_CODE (len
) != CONST_INT
|| INTVAL (len
) > 768))
4126 /* Issue a read prefetch for the +3 cache line. */
4127 prefetch
= gen_prefetch (gen_rtx_PLUS (Pmode
, src_addr
, GEN_INT (768)),
4128 const0_rtx
, const0_rtx
);
4129 PREFETCH_SCHEDULE_BARRIER_P (prefetch
) = true;
4130 emit_insn (prefetch
);
4132 /* Issue a write prefetch for the +3 cache line. */
4133 prefetch
= gen_prefetch (gen_rtx_PLUS (Pmode
, dst_addr
, GEN_INT (768)),
4134 const1_rtx
, const0_rtx
);
4135 PREFETCH_SCHEDULE_BARRIER_P (prefetch
) = true;
4136 emit_insn (prefetch
);
4139 emit_insn (gen_movmem_short (dst
, src
, GEN_INT (255)));
4140 s390_load_address (dst_addr
,
4141 gen_rtx_PLUS (Pmode
, dst_addr
, GEN_INT (256)));
4142 s390_load_address (src_addr
,
4143 gen_rtx_PLUS (Pmode
, src_addr
, GEN_INT (256)));
4145 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1,
4148 emit_move_insn (blocks
, temp
);
4150 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
4151 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
4153 emit_jump (loop_start_label
);
4154 emit_label (loop_end_label
);
4156 emit_insn (gen_movmem_short (dst
, src
,
4157 convert_to_mode (Pmode
, count
, 1)));
4158 emit_label (end_label
);
4163 /* Emit code to set LEN bytes at DST to VAL.
4164 Make use of clrmem if VAL is zero. */
4167 s390_expand_setmem (rtx dst
, rtx len
, rtx val
)
4169 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) == 0)
4172 gcc_assert (GET_CODE (val
) == CONST_INT
|| GET_MODE (val
) == QImode
);
4174 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) > 0 && INTVAL (len
) <= 257)
4176 if (val
== const0_rtx
&& INTVAL (len
) <= 256)
4177 emit_insn (gen_clrmem_short (dst
, GEN_INT (INTVAL (len
) - 1)));
4180 /* Initialize memory by storing the first byte. */
4181 emit_move_insn (adjust_address (dst
, QImode
, 0), val
);
4183 if (INTVAL (len
) > 1)
4185 /* Initiate 1 byte overlap move.
4186 The first byte of DST is propagated through DSTP1.
4187 Prepare a movmem for: DST+1 = DST (length = LEN - 1).
4188 DST is set to size 1 so the rest of the memory location
4189 does not count as source operand. */
4190 rtx dstp1
= adjust_address (dst
, VOIDmode
, 1);
4191 set_mem_size (dst
, 1);
4193 emit_insn (gen_movmem_short (dstp1
, dst
,
4194 GEN_INT (INTVAL (len
) - 2)));
4199 else if (TARGET_MVCLE
)
4201 val
= force_not_mem (convert_modes (Pmode
, QImode
, val
, 1));
4202 emit_insn (gen_setmem_long (dst
, convert_to_mode (Pmode
, len
, 1), val
));
4207 rtx dst_addr
, count
, blocks
, temp
, dstp1
= NULL_RTX
;
4208 rtx_code_label
*loop_start_label
= gen_label_rtx ();
4209 rtx_code_label
*loop_end_label
= gen_label_rtx ();
4210 rtx_code_label
*end_label
= gen_label_rtx ();
4211 enum machine_mode mode
;
4213 mode
= GET_MODE (len
);
4214 if (mode
== VOIDmode
)
4217 dst_addr
= gen_reg_rtx (Pmode
);
4218 count
= gen_reg_rtx (mode
);
4219 blocks
= gen_reg_rtx (mode
);
4221 convert_move (count
, len
, 1);
4222 emit_cmp_and_jump_insns (count
, const0_rtx
,
4223 EQ
, NULL_RTX
, mode
, 1, end_label
);
4225 emit_move_insn (dst_addr
, force_operand (XEXP (dst
, 0), NULL_RTX
));
4226 dst
= change_address (dst
, VOIDmode
, dst_addr
);
4228 if (val
== const0_rtx
)
4229 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1,
4233 dstp1
= adjust_address (dst
, VOIDmode
, 1);
4234 set_mem_size (dst
, 1);
4236 /* Initialize memory by storing the first byte. */
4237 emit_move_insn (adjust_address (dst
, QImode
, 0), val
);
4239 /* If count is 1 we are done. */
4240 emit_cmp_and_jump_insns (count
, const1_rtx
,
4241 EQ
, NULL_RTX
, mode
, 1, end_label
);
4243 temp
= expand_binop (mode
, add_optab
, count
, GEN_INT (-2), count
, 1,
4247 emit_move_insn (count
, temp
);
4249 temp
= expand_binop (mode
, lshr_optab
, count
, GEN_INT (8), blocks
, 1,
4252 emit_move_insn (blocks
, temp
);
4254 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
4255 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
4257 emit_label (loop_start_label
);
4260 && (GET_CODE (len
) != CONST_INT
|| INTVAL (len
) > 1024))
4262 /* Issue a write prefetch for the +4 cache line. */
4263 rtx prefetch
= gen_prefetch (gen_rtx_PLUS (Pmode
, dst_addr
,
4265 const1_rtx
, const0_rtx
);
4266 emit_insn (prefetch
);
4267 PREFETCH_SCHEDULE_BARRIER_P (prefetch
) = true;
4270 if (val
== const0_rtx
)
4271 emit_insn (gen_clrmem_short (dst
, GEN_INT (255)));
4273 emit_insn (gen_movmem_short (dstp1
, dst
, GEN_INT (255)));
4274 s390_load_address (dst_addr
,
4275 gen_rtx_PLUS (Pmode
, dst_addr
, GEN_INT (256)));
4277 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1,
4280 emit_move_insn (blocks
, temp
);
4282 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
4283 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
4285 emit_jump (loop_start_label
);
4286 emit_label (loop_end_label
);
4288 if (val
== const0_rtx
)
4289 emit_insn (gen_clrmem_short (dst
, convert_to_mode (Pmode
, count
, 1)));
4291 emit_insn (gen_movmem_short (dstp1
, dst
, convert_to_mode (Pmode
, count
, 1)));
4292 emit_label (end_label
);
4296 /* Emit code to compare LEN bytes at OP0 with those at OP1,
4297 and return the result in TARGET. */
4300 s390_expand_cmpmem (rtx target
, rtx op0
, rtx op1
, rtx len
)
4302 rtx ccreg
= gen_rtx_REG (CCUmode
, CC_REGNUM
);
4305 /* When tuning for z10 or higher we rely on the Glibc functions to
4306 do the right thing. Only for constant lengths below 64k we will
4307 generate inline code. */
4308 if (s390_tune
>= PROCESSOR_2097_Z10
4309 && (GET_CODE (len
) != CONST_INT
|| INTVAL (len
) > (1<<16)))
4312 /* As the result of CMPINT is inverted compared to what we need,
4313 we have to swap the operands. */
4314 tmp
= op0
; op0
= op1
; op1
= tmp
;
4316 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) >= 0 && INTVAL (len
) <= 256)
4318 if (INTVAL (len
) > 0)
4320 emit_insn (gen_cmpmem_short (op0
, op1
, GEN_INT (INTVAL (len
) - 1)));
4321 emit_insn (gen_cmpint (target
, ccreg
));
4324 emit_move_insn (target
, const0_rtx
);
4326 else if (TARGET_MVCLE
)
4328 emit_insn (gen_cmpmem_long (op0
, op1
, convert_to_mode (Pmode
, len
, 1)));
4329 emit_insn (gen_cmpint (target
, ccreg
));
4333 rtx addr0
, addr1
, count
, blocks
, temp
;
4334 rtx_code_label
*loop_start_label
= gen_label_rtx ();
4335 rtx_code_label
*loop_end_label
= gen_label_rtx ();
4336 rtx_code_label
*end_label
= gen_label_rtx ();
4337 enum machine_mode mode
;
4339 mode
= GET_MODE (len
);
4340 if (mode
== VOIDmode
)
4343 addr0
= gen_reg_rtx (Pmode
);
4344 addr1
= gen_reg_rtx (Pmode
);
4345 count
= gen_reg_rtx (mode
);
4346 blocks
= gen_reg_rtx (mode
);
4348 convert_move (count
, len
, 1);
4349 emit_cmp_and_jump_insns (count
, const0_rtx
,
4350 EQ
, NULL_RTX
, mode
, 1, end_label
);
4352 emit_move_insn (addr0
, force_operand (XEXP (op0
, 0), NULL_RTX
));
4353 emit_move_insn (addr1
, force_operand (XEXP (op1
, 0), NULL_RTX
));
4354 op0
= change_address (op0
, VOIDmode
, addr0
);
4355 op1
= change_address (op1
, VOIDmode
, addr1
);
4357 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1,
4360 emit_move_insn (count
, temp
);
4362 temp
= expand_binop (mode
, lshr_optab
, count
, GEN_INT (8), blocks
, 1,
4365 emit_move_insn (blocks
, temp
);
4367 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
4368 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
4370 emit_label (loop_start_label
);
4373 && (GET_CODE (len
) != CONST_INT
|| INTVAL (len
) > 512))
4377 /* Issue a read prefetch for the +2 cache line of operand 1. */
4378 prefetch
= gen_prefetch (gen_rtx_PLUS (Pmode
, addr0
, GEN_INT (512)),
4379 const0_rtx
, const0_rtx
);
4380 emit_insn (prefetch
);
4381 PREFETCH_SCHEDULE_BARRIER_P (prefetch
) = true;
4383 /* Issue a read prefetch for the +2 cache line of operand 2. */
4384 prefetch
= gen_prefetch (gen_rtx_PLUS (Pmode
, addr1
, GEN_INT (512)),
4385 const0_rtx
, const0_rtx
);
4386 emit_insn (prefetch
);
4387 PREFETCH_SCHEDULE_BARRIER_P (prefetch
) = true;
4390 emit_insn (gen_cmpmem_short (op0
, op1
, GEN_INT (255)));
4391 temp
= gen_rtx_NE (VOIDmode
, ccreg
, const0_rtx
);
4392 temp
= gen_rtx_IF_THEN_ELSE (VOIDmode
, temp
,
4393 gen_rtx_LABEL_REF (VOIDmode
, end_label
), pc_rtx
);
4394 temp
= gen_rtx_SET (VOIDmode
, pc_rtx
, temp
);
4395 emit_jump_insn (temp
);
4397 s390_load_address (addr0
,
4398 gen_rtx_PLUS (Pmode
, addr0
, GEN_INT (256)));
4399 s390_load_address (addr1
,
4400 gen_rtx_PLUS (Pmode
, addr1
, GEN_INT (256)));
4402 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1,
4405 emit_move_insn (blocks
, temp
);
4407 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
4408 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
4410 emit_jump (loop_start_label
);
4411 emit_label (loop_end_label
);
4413 emit_insn (gen_cmpmem_short (op0
, op1
,
4414 convert_to_mode (Pmode
, count
, 1)));
4415 emit_label (end_label
);
4417 emit_insn (gen_cmpint (target
, ccreg
));
4423 /* Expand conditional increment or decrement using alc/slb instructions.
4424 Should generate code setting DST to either SRC or SRC + INCREMENT,
4425 depending on the result of the comparison CMP_OP0 CMP_CODE CMP_OP1.
4426 Returns true if successful, false otherwise.
4428 That makes it possible to implement some if-constructs without jumps e.g.:
4429 (borrow = CC0 | CC1 and carry = CC2 | CC3)
4430 unsigned int a, b, c;
4431 if (a < b) c++; -> CCU b > a -> CC2; c += carry;
4432 if (a < b) c--; -> CCL3 a - b -> borrow; c -= borrow;
4433 if (a <= b) c++; -> CCL3 b - a -> borrow; c += carry;
4434 if (a <= b) c--; -> CCU a <= b -> borrow; c -= borrow;
4436 Checks for EQ and NE with a nonzero value need an additional xor e.g.:
4437 if (a == b) c++; -> CCL3 a ^= b; 0 - a -> borrow; c += carry;
4438 if (a == b) c--; -> CCU a ^= b; a <= 0 -> CC0 | CC1; c -= borrow;
4439 if (a != b) c++; -> CCU a ^= b; a > 0 -> CC2; c += carry;
4440 if (a != b) c--; -> CCL3 a ^= b; 0 - a -> borrow; c -= borrow; */
4443 s390_expand_addcc (enum rtx_code cmp_code
, rtx cmp_op0
, rtx cmp_op1
,
4444 rtx dst
, rtx src
, rtx increment
)
4446 enum machine_mode cmp_mode
;
4447 enum machine_mode cc_mode
;
4453 if ((GET_MODE (cmp_op0
) == SImode
|| GET_MODE (cmp_op0
) == VOIDmode
)
4454 && (GET_MODE (cmp_op1
) == SImode
|| GET_MODE (cmp_op1
) == VOIDmode
))
4456 else if ((GET_MODE (cmp_op0
) == DImode
|| GET_MODE (cmp_op0
) == VOIDmode
)
4457 && (GET_MODE (cmp_op1
) == DImode
|| GET_MODE (cmp_op1
) == VOIDmode
))
4462 /* Try ADD LOGICAL WITH CARRY. */
4463 if (increment
== const1_rtx
)
4465 /* Determine CC mode to use. */
4466 if (cmp_code
== EQ
|| cmp_code
== NE
)
4468 if (cmp_op1
!= const0_rtx
)
4470 cmp_op0
= expand_simple_binop (cmp_mode
, XOR
, cmp_op0
, cmp_op1
,
4471 NULL_RTX
, 0, OPTAB_WIDEN
);
4472 cmp_op1
= const0_rtx
;
4475 cmp_code
= cmp_code
== EQ
? LEU
: GTU
;
4478 if (cmp_code
== LTU
|| cmp_code
== LEU
)
4483 cmp_code
= swap_condition (cmp_code
);
4500 /* Emit comparison instruction pattern. */
4501 if (!register_operand (cmp_op0
, cmp_mode
))
4502 cmp_op0
= force_reg (cmp_mode
, cmp_op0
);
4504 insn
= gen_rtx_SET (VOIDmode
, gen_rtx_REG (cc_mode
, CC_REGNUM
),
4505 gen_rtx_COMPARE (cc_mode
, cmp_op0
, cmp_op1
));
4506 /* We use insn_invalid_p here to add clobbers if required. */
4507 ret
= insn_invalid_p (emit_insn (insn
), false);
4510 /* Emit ALC instruction pattern. */
4511 op_res
= gen_rtx_fmt_ee (cmp_code
, GET_MODE (dst
),
4512 gen_rtx_REG (cc_mode
, CC_REGNUM
),
4515 if (src
!= const0_rtx
)
4517 if (!register_operand (src
, GET_MODE (dst
)))
4518 src
= force_reg (GET_MODE (dst
), src
);
4520 op_res
= gen_rtx_PLUS (GET_MODE (dst
), op_res
, src
);
4521 op_res
= gen_rtx_PLUS (GET_MODE (dst
), op_res
, const0_rtx
);
4524 p
= rtvec_alloc (2);
4526 gen_rtx_SET (VOIDmode
, dst
, op_res
);
4528 gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
4529 emit_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
4534 /* Try SUBTRACT LOGICAL WITH BORROW. */
4535 if (increment
== constm1_rtx
)
4537 /* Determine CC mode to use. */
4538 if (cmp_code
== EQ
|| cmp_code
== NE
)
4540 if (cmp_op1
!= const0_rtx
)
4542 cmp_op0
= expand_simple_binop (cmp_mode
, XOR
, cmp_op0
, cmp_op1
,
4543 NULL_RTX
, 0, OPTAB_WIDEN
);
4544 cmp_op1
= const0_rtx
;
4547 cmp_code
= cmp_code
== EQ
? LEU
: GTU
;
4550 if (cmp_code
== GTU
|| cmp_code
== GEU
)
4555 cmp_code
= swap_condition (cmp_code
);
4572 /* Emit comparison instruction pattern. */
4573 if (!register_operand (cmp_op0
, cmp_mode
))
4574 cmp_op0
= force_reg (cmp_mode
, cmp_op0
);
4576 insn
= gen_rtx_SET (VOIDmode
, gen_rtx_REG (cc_mode
, CC_REGNUM
),
4577 gen_rtx_COMPARE (cc_mode
, cmp_op0
, cmp_op1
));
4578 /* We use insn_invalid_p here to add clobbers if required. */
4579 ret
= insn_invalid_p (emit_insn (insn
), false);
4582 /* Emit SLB instruction pattern. */
4583 if (!register_operand (src
, GET_MODE (dst
)))
4584 src
= force_reg (GET_MODE (dst
), src
);
4586 op_res
= gen_rtx_MINUS (GET_MODE (dst
),
4587 gen_rtx_MINUS (GET_MODE (dst
), src
, const0_rtx
),
4588 gen_rtx_fmt_ee (cmp_code
, GET_MODE (dst
),
4589 gen_rtx_REG (cc_mode
, CC_REGNUM
),
4591 p
= rtvec_alloc (2);
4593 gen_rtx_SET (VOIDmode
, dst
, op_res
);
4595 gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
4596 emit_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
4604 /* Expand code for the insv template. Return true if successful. */
4607 s390_expand_insv (rtx dest
, rtx op1
, rtx op2
, rtx src
)
4609 int bitsize
= INTVAL (op1
);
4610 int bitpos
= INTVAL (op2
);
4611 enum machine_mode mode
= GET_MODE (dest
);
4612 enum machine_mode smode
;
4613 int smode_bsize
, mode_bsize
;
4616 if (bitsize
+ bitpos
> GET_MODE_BITSIZE (mode
))
4619 /* Generate INSERT IMMEDIATE (IILL et al). */
4620 /* (set (ze (reg)) (const_int)). */
4622 && register_operand (dest
, word_mode
)
4623 && (bitpos
% 16) == 0
4624 && (bitsize
% 16) == 0
4625 && const_int_operand (src
, VOIDmode
))
4627 HOST_WIDE_INT val
= INTVAL (src
);
4628 int regpos
= bitpos
+ bitsize
;
4630 while (regpos
> bitpos
)
4632 enum machine_mode putmode
;
4635 if (TARGET_EXTIMM
&& (regpos
% 32 == 0) && (regpos
>= bitpos
+ 32))
4640 putsize
= GET_MODE_BITSIZE (putmode
);
4642 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
,
4645 gen_int_mode (val
, putmode
));
4648 gcc_assert (regpos
== bitpos
);
4652 smode
= smallest_mode_for_size (bitsize
, MODE_INT
);
4653 smode_bsize
= GET_MODE_BITSIZE (smode
);
4654 mode_bsize
= GET_MODE_BITSIZE (mode
);
4656 /* Generate STORE CHARACTERS UNDER MASK (STCM et al). */
4658 && (bitsize
% BITS_PER_UNIT
) == 0
4660 && (register_operand (src
, word_mode
)
4661 || const_int_operand (src
, VOIDmode
)))
4663 /* Emit standard pattern if possible. */
4664 if (smode_bsize
== bitsize
)
4666 emit_move_insn (adjust_address (dest
, smode
, 0),
4667 gen_lowpart (smode
, src
));
4671 /* (set (ze (mem)) (const_int)). */
4672 else if (const_int_operand (src
, VOIDmode
))
4674 int size
= bitsize
/ BITS_PER_UNIT
;
4675 rtx src_mem
= adjust_address (force_const_mem (word_mode
, src
),
4677 UNITS_PER_WORD
- size
);
4679 dest
= adjust_address (dest
, BLKmode
, 0);
4680 set_mem_size (dest
, size
);
4681 s390_expand_movmem (dest
, src_mem
, GEN_INT (size
));
4685 /* (set (ze (mem)) (reg)). */
4686 else if (register_operand (src
, word_mode
))
4689 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
, op1
,
4693 /* Emit st,stcmh sequence. */
4694 int stcmh_width
= bitsize
- 32;
4695 int size
= stcmh_width
/ BITS_PER_UNIT
;
4697 emit_move_insn (adjust_address (dest
, SImode
, size
),
4698 gen_lowpart (SImode
, src
));
4699 set_mem_size (dest
, size
);
4700 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
,
4701 GEN_INT (stcmh_width
),
4703 gen_rtx_LSHIFTRT (word_mode
, src
, GEN_INT (32)));
4709 /* Generate INSERT CHARACTERS UNDER MASK (IC, ICM et al). */
4710 if ((bitpos
% BITS_PER_UNIT
) == 0
4711 && (bitsize
% BITS_PER_UNIT
) == 0
4712 && (bitpos
& 32) == ((bitpos
+ bitsize
- 1) & 32)
4714 && (mode
== DImode
|| mode
== SImode
)
4715 && register_operand (dest
, mode
))
4717 /* Emit a strict_low_part pattern if possible. */
4718 if (smode_bsize
== bitsize
&& bitpos
== mode_bsize
- smode_bsize
)
4720 op
= gen_rtx_STRICT_LOW_PART (VOIDmode
, gen_lowpart (smode
, dest
));
4721 op
= gen_rtx_SET (VOIDmode
, op
, gen_lowpart (smode
, src
));
4722 clobber
= gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
4723 emit_insn (gen_rtx_PARALLEL (VOIDmode
, gen_rtvec (2, op
, clobber
)));
4727 /* ??? There are more powerful versions of ICM that are not
4728 completely represented in the md file. */
4731 /* For z10, generate ROTATE THEN INSERT SELECTED BITS (RISBG et al). */
4732 if (TARGET_Z10
&& (mode
== DImode
|| mode
== SImode
))
4734 enum machine_mode mode_s
= GET_MODE (src
);
4736 if (mode_s
== VOIDmode
)
4738 /* Assume const_int etc already in the proper mode. */
4739 src
= force_reg (mode
, src
);
4741 else if (mode_s
!= mode
)
4743 gcc_assert (GET_MODE_BITSIZE (mode_s
) >= bitsize
);
4744 src
= force_reg (mode_s
, src
);
4745 src
= gen_lowpart (mode
, src
);
4748 op
= gen_rtx_ZERO_EXTRACT (mode
, dest
, op1
, op2
),
4749 op
= gen_rtx_SET (VOIDmode
, op
, src
);
4753 clobber
= gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
4754 op
= gen_rtx_PARALLEL (VOIDmode
, gen_rtvec (2, op
, clobber
));
4764 /* A subroutine of s390_expand_cs_hqi and s390_expand_atomic which returns a
4765 register that holds VAL of mode MODE shifted by COUNT bits. */
4768 s390_expand_mask_and_shift (rtx val
, enum machine_mode mode
, rtx count
)
4770 val
= expand_simple_binop (SImode
, AND
, val
, GEN_INT (GET_MODE_MASK (mode
)),
4771 NULL_RTX
, 1, OPTAB_DIRECT
);
4772 return expand_simple_binop (SImode
, ASHIFT
, val
, count
,
4773 NULL_RTX
, 1, OPTAB_DIRECT
);
4776 /* Structure to hold the initial parameters for a compare_and_swap operation
4777 in HImode and QImode. */
4779 struct alignment_context
4781 rtx memsi
; /* SI aligned memory location. */
4782 rtx shift
; /* Bit offset with regard to lsb. */
4783 rtx modemask
; /* Mask of the HQImode shifted by SHIFT bits. */
4784 rtx modemaski
; /* ~modemask */
4785 bool aligned
; /* True if memory is aligned, false else. */
4788 /* A subroutine of s390_expand_cs_hqi and s390_expand_atomic to initialize
4789 structure AC for transparent simplifying, if the memory alignment is known
4790 to be at least 32bit. MEM is the memory location for the actual operation
4791 and MODE its mode. */
4794 init_alignment_context (struct alignment_context
*ac
, rtx mem
,
4795 enum machine_mode mode
)
4797 ac
->shift
= GEN_INT (GET_MODE_SIZE (SImode
) - GET_MODE_SIZE (mode
));
4798 ac
->aligned
= (MEM_ALIGN (mem
) >= GET_MODE_BITSIZE (SImode
));
4801 ac
->memsi
= adjust_address (mem
, SImode
, 0); /* Memory is aligned. */
4804 /* Alignment is unknown. */
4805 rtx byteoffset
, addr
, align
;
4807 /* Force the address into a register. */
4808 addr
= force_reg (Pmode
, XEXP (mem
, 0));
4810 /* Align it to SImode. */
4811 align
= expand_simple_binop (Pmode
, AND
, addr
,
4812 GEN_INT (-GET_MODE_SIZE (SImode
)),
4813 NULL_RTX
, 1, OPTAB_DIRECT
);
4815 ac
->memsi
= gen_rtx_MEM (SImode
, align
);
4816 MEM_VOLATILE_P (ac
->memsi
) = MEM_VOLATILE_P (mem
);
4817 set_mem_alias_set (ac
->memsi
, ALIAS_SET_MEMORY_BARRIER
);
4818 set_mem_align (ac
->memsi
, GET_MODE_BITSIZE (SImode
));
4820 /* Calculate shiftcount. */
4821 byteoffset
= expand_simple_binop (Pmode
, AND
, addr
,
4822 GEN_INT (GET_MODE_SIZE (SImode
) - 1),
4823 NULL_RTX
, 1, OPTAB_DIRECT
);
4824 /* As we already have some offset, evaluate the remaining distance. */
4825 ac
->shift
= expand_simple_binop (SImode
, MINUS
, ac
->shift
, byteoffset
,
4826 NULL_RTX
, 1, OPTAB_DIRECT
);
4829 /* Shift is the byte count, but we need the bitcount. */
4830 ac
->shift
= expand_simple_binop (SImode
, ASHIFT
, ac
->shift
, GEN_INT (3),
4831 NULL_RTX
, 1, OPTAB_DIRECT
);
4833 /* Calculate masks. */
4834 ac
->modemask
= expand_simple_binop (SImode
, ASHIFT
,
4835 GEN_INT (GET_MODE_MASK (mode
)),
4836 ac
->shift
, NULL_RTX
, 1, OPTAB_DIRECT
);
4837 ac
->modemaski
= expand_simple_unop (SImode
, NOT
, ac
->modemask
,
4841 /* A subroutine of s390_expand_cs_hqi. Insert INS into VAL. If possible,
4842 use a single insv insn into SEQ2. Otherwise, put prep insns in SEQ1 and
4843 perform the merge in SEQ2. */
4846 s390_two_part_insv (struct alignment_context
*ac
, rtx
*seq1
, rtx
*seq2
,
4847 enum machine_mode mode
, rtx val
, rtx ins
)
4854 tmp
= copy_to_mode_reg (SImode
, val
);
4855 if (s390_expand_insv (tmp
, GEN_INT (GET_MODE_BITSIZE (mode
)),
4859 *seq2
= get_insns ();
4866 /* Failed to use insv. Generate a two part shift and mask. */
4868 tmp
= s390_expand_mask_and_shift (ins
, mode
, ac
->shift
);
4869 *seq1
= get_insns ();
4873 tmp
= expand_simple_binop (SImode
, IOR
, tmp
, val
, NULL_RTX
, 1, OPTAB_DIRECT
);
4874 *seq2
= get_insns ();
4880 /* Expand an atomic compare and swap operation for HImode and QImode. MEM is
4881 the memory location, CMP the old value to compare MEM with and NEW_RTX the
4882 value to set if CMP == MEM. */
4885 s390_expand_cs_hqi (enum machine_mode mode
, rtx btarget
, rtx vtarget
, rtx mem
,
4886 rtx cmp
, rtx new_rtx
, bool is_weak
)
4888 struct alignment_context ac
;
4889 rtx cmpv
, newv
, val
, cc
, seq0
, seq1
, seq2
, seq3
;
4890 rtx res
= gen_reg_rtx (SImode
);
4891 rtx_code_label
*csloop
= NULL
, *csend
= NULL
;
4893 gcc_assert (MEM_P (mem
));
4895 init_alignment_context (&ac
, mem
, mode
);
4897 /* Load full word. Subsequent loads are performed by CS. */
4898 val
= expand_simple_binop (SImode
, AND
, ac
.memsi
, ac
.modemaski
,
4899 NULL_RTX
, 1, OPTAB_DIRECT
);
4901 /* Prepare insertions of cmp and new_rtx into the loaded value. When
4902 possible, we try to use insv to make this happen efficiently. If
4903 that fails we'll generate code both inside and outside the loop. */
4904 cmpv
= s390_two_part_insv (&ac
, &seq0
, &seq2
, mode
, val
, cmp
);
4905 newv
= s390_two_part_insv (&ac
, &seq1
, &seq3
, mode
, val
, new_rtx
);
4912 /* Start CS loop. */
4915 /* Begin assuming success. */
4916 emit_move_insn (btarget
, const1_rtx
);
4918 csloop
= gen_label_rtx ();
4919 csend
= gen_label_rtx ();
4920 emit_label (csloop
);
4923 /* val = "<mem>00..0<mem>"
4924 * cmp = "00..0<cmp>00..0"
4925 * new = "00..0<new>00..0"
4931 cc
= s390_emit_compare_and_swap (EQ
, res
, ac
.memsi
, cmpv
, newv
);
4933 emit_insn (gen_cstorecc4 (btarget
, cc
, XEXP (cc
, 0), XEXP (cc
, 1)));
4938 /* Jump to end if we're done (likely?). */
4939 s390_emit_jump (csend
, cc
);
4941 /* Check for changes outside mode, and loop internal if so.
4942 Arrange the moves so that the compare is adjacent to the
4943 branch so that we can generate CRJ. */
4944 tmp
= copy_to_reg (val
);
4945 force_expand_binop (SImode
, and_optab
, res
, ac
.modemaski
, val
,
4947 cc
= s390_emit_compare (NE
, val
, tmp
);
4948 s390_emit_jump (csloop
, cc
);
4951 emit_move_insn (btarget
, const0_rtx
);
4955 /* Return the correct part of the bitfield. */
4956 convert_move (vtarget
, expand_simple_binop (SImode
, LSHIFTRT
, res
, ac
.shift
,
4957 NULL_RTX
, 1, OPTAB_DIRECT
), 1);
4960 /* Expand an atomic operation CODE of mode MODE. MEM is the memory location
4961 and VAL the value to play with. If AFTER is true then store the value
4962 MEM holds after the operation, if AFTER is false then store the value MEM
4963 holds before the operation. If TARGET is zero then discard that value, else
4964 store it to TARGET. */
4967 s390_expand_atomic (enum machine_mode mode
, enum rtx_code code
,
4968 rtx target
, rtx mem
, rtx val
, bool after
)
4970 struct alignment_context ac
;
4972 rtx new_rtx
= gen_reg_rtx (SImode
);
4973 rtx orig
= gen_reg_rtx (SImode
);
4974 rtx_code_label
*csloop
= gen_label_rtx ();
4976 gcc_assert (!target
|| register_operand (target
, VOIDmode
));
4977 gcc_assert (MEM_P (mem
));
4979 init_alignment_context (&ac
, mem
, mode
);
4981 /* Shift val to the correct bit positions.
4982 Preserve "icm", but prevent "ex icm". */
4983 if (!(ac
.aligned
&& code
== SET
&& MEM_P (val
)))
4984 val
= s390_expand_mask_and_shift (val
, mode
, ac
.shift
);
4986 /* Further preparation insns. */
4987 if (code
== PLUS
|| code
== MINUS
)
4988 emit_move_insn (orig
, val
);
4989 else if (code
== MULT
|| code
== AND
) /* val = "11..1<val>11..1" */
4990 val
= expand_simple_binop (SImode
, XOR
, val
, ac
.modemaski
,
4991 NULL_RTX
, 1, OPTAB_DIRECT
);
4993 /* Load full word. Subsequent loads are performed by CS. */
4994 cmp
= force_reg (SImode
, ac
.memsi
);
4996 /* Start CS loop. */
4997 emit_label (csloop
);
4998 emit_move_insn (new_rtx
, cmp
);
5000 /* Patch new with val at correct position. */
5005 val
= expand_simple_binop (SImode
, code
, new_rtx
, orig
,
5006 NULL_RTX
, 1, OPTAB_DIRECT
);
5007 val
= expand_simple_binop (SImode
, AND
, val
, ac
.modemask
,
5008 NULL_RTX
, 1, OPTAB_DIRECT
);
5011 if (ac
.aligned
&& MEM_P (val
))
5012 store_bit_field (new_rtx
, GET_MODE_BITSIZE (mode
), 0,
5016 new_rtx
= expand_simple_binop (SImode
, AND
, new_rtx
, ac
.modemaski
,
5017 NULL_RTX
, 1, OPTAB_DIRECT
);
5018 new_rtx
= expand_simple_binop (SImode
, IOR
, new_rtx
, val
,
5019 NULL_RTX
, 1, OPTAB_DIRECT
);
5025 new_rtx
= expand_simple_binop (SImode
, code
, new_rtx
, val
,
5026 NULL_RTX
, 1, OPTAB_DIRECT
);
5028 case MULT
: /* NAND */
5029 new_rtx
= expand_simple_binop (SImode
, AND
, new_rtx
, val
,
5030 NULL_RTX
, 1, OPTAB_DIRECT
);
5031 new_rtx
= expand_simple_binop (SImode
, XOR
, new_rtx
, ac
.modemask
,
5032 NULL_RTX
, 1, OPTAB_DIRECT
);
5038 s390_emit_jump (csloop
, s390_emit_compare_and_swap (NE
, cmp
,
5039 ac
.memsi
, cmp
, new_rtx
));
5041 /* Return the correct part of the bitfield. */
5043 convert_move (target
, expand_simple_binop (SImode
, LSHIFTRT
,
5044 after
? new_rtx
: cmp
, ac
.shift
,
5045 NULL_RTX
, 1, OPTAB_DIRECT
), 1);
5048 /* This is called from dwarf2out.c via TARGET_ASM_OUTPUT_DWARF_DTPREL.
5049 We need to emit DTP-relative relocations. */
5051 static void s390_output_dwarf_dtprel (FILE *, int, rtx
) ATTRIBUTE_UNUSED
;
5054 s390_output_dwarf_dtprel (FILE *file
, int size
, rtx x
)
5059 fputs ("\t.long\t", file
);
5062 fputs ("\t.quad\t", file
);
5067 output_addr_const (file
, x
);
5068 fputs ("@DTPOFF", file
);
5071 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
5072 /* Implement TARGET_MANGLE_TYPE. */
5075 s390_mangle_type (const_tree type
)
5077 if (TYPE_MAIN_VARIANT (type
) == long_double_type_node
5078 && TARGET_LONG_DOUBLE_128
)
5081 /* For all other types, use normal C++ mangling. */
5086 /* In the name of slightly smaller debug output, and to cater to
5087 general assembler lossage, recognize various UNSPEC sequences
5088 and turn them back into a direct symbol reference. */
5091 s390_delegitimize_address (rtx orig_x
)
5095 orig_x
= delegitimize_mem_from_attrs (orig_x
);
5098 /* Extract the symbol ref from:
5099 (plus:SI (reg:SI 12 %r12)
5100 (const:SI (unspec:SI [(symbol_ref/f:SI ("*.LC0"))]
5101 UNSPEC_GOTOFF/PLTOFF)))
5103 (plus:SI (reg:SI 12 %r12)
5104 (const:SI (plus:SI (unspec:SI [(symbol_ref:SI ("L"))]
5105 UNSPEC_GOTOFF/PLTOFF)
5106 (const_int 4 [0x4])))) */
5107 if (GET_CODE (x
) == PLUS
5108 && REG_P (XEXP (x
, 0))
5109 && REGNO (XEXP (x
, 0)) == PIC_OFFSET_TABLE_REGNUM
5110 && GET_CODE (XEXP (x
, 1)) == CONST
)
5112 HOST_WIDE_INT offset
= 0;
5114 /* The const operand. */
5115 y
= XEXP (XEXP (x
, 1), 0);
5117 if (GET_CODE (y
) == PLUS
5118 && GET_CODE (XEXP (y
, 1)) == CONST_INT
)
5120 offset
= INTVAL (XEXP (y
, 1));
5124 if (GET_CODE (y
) == UNSPEC
5125 && (XINT (y
, 1) == UNSPEC_GOTOFF
5126 || XINT (y
, 1) == UNSPEC_PLTOFF
))
5127 return plus_constant (Pmode
, XVECEXP (y
, 0, 0), offset
);
5130 if (GET_CODE (x
) != MEM
)
5134 if (GET_CODE (x
) == PLUS
5135 && GET_CODE (XEXP (x
, 1)) == CONST
5136 && GET_CODE (XEXP (x
, 0)) == REG
5137 && REGNO (XEXP (x
, 0)) == PIC_OFFSET_TABLE_REGNUM
)
5139 y
= XEXP (XEXP (x
, 1), 0);
5140 if (GET_CODE (y
) == UNSPEC
5141 && XINT (y
, 1) == UNSPEC_GOT
)
5142 y
= XVECEXP (y
, 0, 0);
5146 else if (GET_CODE (x
) == CONST
)
5148 /* Extract the symbol ref from:
5149 (mem:QI (const:DI (unspec:DI [(symbol_ref:DI ("foo"))]
5150 UNSPEC_PLT/GOTENT))) */
5153 if (GET_CODE (y
) == UNSPEC
5154 && (XINT (y
, 1) == UNSPEC_GOTENT
5155 || XINT (y
, 1) == UNSPEC_PLT
))
5156 y
= XVECEXP (y
, 0, 0);
5163 if (GET_MODE (orig_x
) != Pmode
)
5165 if (GET_MODE (orig_x
) == BLKmode
)
5167 y
= lowpart_subreg (GET_MODE (orig_x
), y
, Pmode
);
5174 /* Output operand OP to stdio stream FILE.
5175 OP is an address (register + offset) which is not used to address data;
5176 instead the rightmost bits are interpreted as the value. */
5179 print_shift_count_operand (FILE *file
, rtx op
)
5181 HOST_WIDE_INT offset
;
5184 /* Extract base register and offset. */
5185 if (!s390_decompose_shift_count (op
, &base
, &offset
))
5191 gcc_assert (GET_CODE (base
) == REG
);
5192 gcc_assert (REGNO (base
) < FIRST_PSEUDO_REGISTER
);
5193 gcc_assert (REGNO_REG_CLASS (REGNO (base
)) == ADDR_REGS
);
5196 /* Offsets are constricted to twelve bits. */
5197 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, offset
& ((1 << 12) - 1));
5199 fprintf (file
, "(%s)", reg_names
[REGNO (base
)]);
5202 /* Returns -1 if the function should not be made hotpatchable. Otherwise it
5203 returns a number >= 0 that is the desired size of the hotpatch trampoline
5206 static int s390_function_num_hotpatch_trampoline_halfwords (tree decl
,
5211 if (DECL_DECLARED_INLINE_P (decl
)
5212 || DECL_ARTIFICIAL (decl
)
5213 || MAIN_NAME_P (DECL_NAME (decl
)))
5215 /* - Explicitly inlined functions cannot be hotpatched.
5216 - Artificial functions need not be hotpatched.
5217 - Making the main function hotpatchable is useless. */
5220 attr
= lookup_attribute ("hotpatch", DECL_ATTRIBUTES (decl
));
5221 if (attr
|| s390_hotpatch_trampoline_halfwords
>= 0)
5223 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (decl
)))
5226 warning (OPT_Wattributes
, "function %qE with the %qs attribute"
5227 " is not hotpatchable", DECL_NAME (decl
), "always_inline");
5233 get_hotpatch_attribute (attr
) : s390_hotpatch_trampoline_halfwords
;
5240 /* Hook to determine if one function can safely inline another. */
5243 s390_can_inline_p (tree caller
, tree callee
)
5245 if (s390_function_num_hotpatch_trampoline_halfwords (callee
, false) >= 0)
5248 return default_target_can_inline_p (caller
, callee
);
5251 /* Write the extra assembler code needed to declare a function properly. */
5254 s390_asm_output_function_label (FILE *asm_out_file
, const char *fname
,
5257 int hotpatch_trampoline_halfwords
= -1;
5261 hotpatch_trampoline_halfwords
=
5262 s390_function_num_hotpatch_trampoline_halfwords (decl
, true);
5263 if (hotpatch_trampoline_halfwords
>= 0
5264 && decl_function_context (decl
) != NULL_TREE
)
5266 warning_at (DECL_SOURCE_LOCATION (decl
), OPT_mhotpatch
,
5267 "hotpatching is not compatible with nested functions");
5268 hotpatch_trampoline_halfwords
= -1;
5272 if (hotpatch_trampoline_halfwords
> 0)
5276 /* Add a trampoline code area before the function label and initialize it
5277 with two-byte nop instructions. This area can be overwritten with code
5278 that jumps to a patched version of the function. */
5279 for (i
= 0; i
< hotpatch_trampoline_halfwords
; i
++)
5280 asm_fprintf (asm_out_file
, "\tnopr\t%%r7\n");
5281 /* Note: The function label must be aligned so that (a) the bytes of the
5282 following nop do not cross a cacheline boundary, and (b) a jump address
5283 (eight bytes for 64 bit targets, 4 bytes for 32 bit targets) can be
5284 stored directly before the label without crossing a cacheline
5285 boundary. All this is necessary to make sure the trampoline code can
5286 be changed atomically. */
5289 ASM_OUTPUT_LABEL (asm_out_file
, fname
);
5291 /* Output a four-byte nop if hotpatching is enabled. This can be overwritten
5292 atomically with a relative backwards jump to the trampoline area. */
5293 if (hotpatch_trampoline_halfwords
>= 0)
5294 asm_fprintf (asm_out_file
, "\tnop\t0\n");
5297 /* Output machine-dependent UNSPECs occurring in address constant X
5298 in assembler syntax to stdio stream FILE. Returns true if the
5299 constant X could be recognized, false otherwise. */
5302 s390_output_addr_const_extra (FILE *file
, rtx x
)
5304 if (GET_CODE (x
) == UNSPEC
&& XVECLEN (x
, 0) == 1)
5305 switch (XINT (x
, 1))
5308 output_addr_const (file
, XVECEXP (x
, 0, 0));
5309 fprintf (file
, "@GOTENT");
5312 output_addr_const (file
, XVECEXP (x
, 0, 0));
5313 fprintf (file
, "@GOT");
5316 output_addr_const (file
, XVECEXP (x
, 0, 0));
5317 fprintf (file
, "@GOTOFF");
5320 output_addr_const (file
, XVECEXP (x
, 0, 0));
5321 fprintf (file
, "@PLT");
5324 output_addr_const (file
, XVECEXP (x
, 0, 0));
5325 fprintf (file
, "@PLTOFF");
5328 output_addr_const (file
, XVECEXP (x
, 0, 0));
5329 fprintf (file
, "@TLSGD");
5332 assemble_name (file
, get_some_local_dynamic_name ());
5333 fprintf (file
, "@TLSLDM");
5336 output_addr_const (file
, XVECEXP (x
, 0, 0));
5337 fprintf (file
, "@DTPOFF");
5340 output_addr_const (file
, XVECEXP (x
, 0, 0));
5341 fprintf (file
, "@NTPOFF");
5343 case UNSPEC_GOTNTPOFF
:
5344 output_addr_const (file
, XVECEXP (x
, 0, 0));
5345 fprintf (file
, "@GOTNTPOFF");
5347 case UNSPEC_INDNTPOFF
:
5348 output_addr_const (file
, XVECEXP (x
, 0, 0));
5349 fprintf (file
, "@INDNTPOFF");
5353 if (GET_CODE (x
) == UNSPEC
&& XVECLEN (x
, 0) == 2)
5354 switch (XINT (x
, 1))
5356 case UNSPEC_POOL_OFFSET
:
5357 x
= gen_rtx_MINUS (GET_MODE (x
), XVECEXP (x
, 0, 0), XVECEXP (x
, 0, 1));
5358 output_addr_const (file
, x
);
5364 /* Output address operand ADDR in assembler syntax to
5365 stdio stream FILE. */
5368 print_operand_address (FILE *file
, rtx addr
)
5370 struct s390_address ad
;
5372 if (s390_loadrelative_operand_p (addr
, NULL
, NULL
))
5376 output_operand_lossage ("symbolic memory references are "
5377 "only supported on z10 or later");
5380 output_addr_const (file
, addr
);
5384 if (!s390_decompose_address (addr
, &ad
)
5385 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
5386 || (ad
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (ad
.indx
))))
5387 output_operand_lossage ("cannot decompose address");
5390 output_addr_const (file
, ad
.disp
);
5392 fprintf (file
, "0");
5394 if (ad
.base
&& ad
.indx
)
5395 fprintf (file
, "(%s,%s)", reg_names
[REGNO (ad
.indx
)],
5396 reg_names
[REGNO (ad
.base
)]);
5398 fprintf (file
, "(%s)", reg_names
[REGNO (ad
.base
)]);
5401 /* Output operand X in assembler syntax to stdio stream FILE.
5402 CODE specified the format flag. The following format flags
5405 'C': print opcode suffix for branch condition.
5406 'D': print opcode suffix for inverse branch condition.
5407 'E': print opcode suffix for branch on index instruction.
5408 'G': print the size of the operand in bytes.
5409 'J': print tls_load/tls_gdcall/tls_ldcall suffix
5410 'M': print the second word of a TImode operand.
5411 'N': print the second word of a DImode operand.
5412 'O': print only the displacement of a memory reference.
5413 'R': print only the base register of a memory reference.
5414 'S': print S-type memory reference (base+displacement).
5415 'Y': print shift count operand.
5417 'b': print integer X as if it's an unsigned byte.
5418 'c': print integer X as if it's an signed byte.
5419 'e': "end" of DImode contiguous bitmask X.
5420 'f': "end" of SImode contiguous bitmask X.
5421 'h': print integer X as if it's a signed halfword.
5422 'i': print the first nonzero HImode part of X.
5423 'j': print the first HImode part unequal to -1 of X.
5424 'k': print the first nonzero SImode part of X.
5425 'm': print the first SImode part unequal to -1 of X.
5426 'o': print integer X as if it's an unsigned 32bit word.
5427 's': "start" of DImode contiguous bitmask X.
5428 't': "start" of SImode contiguous bitmask X.
5429 'x': print integer X as if it's an unsigned halfword.
5433 print_operand (FILE *file
, rtx x
, int code
)
5440 fprintf (file
, s390_branch_condition_mnemonic (x
, FALSE
));
5444 fprintf (file
, s390_branch_condition_mnemonic (x
, TRUE
));
5448 if (GET_CODE (x
) == LE
)
5449 fprintf (file
, "l");
5450 else if (GET_CODE (x
) == GT
)
5451 fprintf (file
, "h");
5453 output_operand_lossage ("invalid comparison operator "
5454 "for 'E' output modifier");
5458 if (GET_CODE (x
) == SYMBOL_REF
)
5460 fprintf (file
, "%s", ":tls_load:");
5461 output_addr_const (file
, x
);
5463 else if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_TLSGD
)
5465 fprintf (file
, "%s", ":tls_gdcall:");
5466 output_addr_const (file
, XVECEXP (x
, 0, 0));
5468 else if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_TLSLDM
)
5470 fprintf (file
, "%s", ":tls_ldcall:");
5471 const char *name
= get_some_local_dynamic_name ();
5473 assemble_name (file
, name
);
5476 output_operand_lossage ("invalid reference for 'J' output modifier");
5480 fprintf (file
, "%u", GET_MODE_SIZE (GET_MODE (x
)));
5485 struct s390_address ad
;
5490 output_operand_lossage ("memory reference expected for "
5491 "'O' output modifier");
5495 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
5498 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
5501 output_operand_lossage ("invalid address for 'O' output modifier");
5506 output_addr_const (file
, ad
.disp
);
5508 fprintf (file
, "0");
5514 struct s390_address ad
;
5519 output_operand_lossage ("memory reference expected for "
5520 "'R' output modifier");
5524 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
5527 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
5530 output_operand_lossage ("invalid address for 'R' output modifier");
5535 fprintf (file
, "%s", reg_names
[REGNO (ad
.base
)]);
5537 fprintf (file
, "0");
5543 struct s390_address ad
;
5548 output_operand_lossage ("memory reference expected for "
5549 "'S' output modifier");
5552 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
5555 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
5558 output_operand_lossage ("invalid address for 'S' output modifier");
5563 output_addr_const (file
, ad
.disp
);
5565 fprintf (file
, "0");
5568 fprintf (file
, "(%s)", reg_names
[REGNO (ad
.base
)]);
5573 if (GET_CODE (x
) == REG
)
5574 x
= gen_rtx_REG (GET_MODE (x
), REGNO (x
) + 1);
5575 else if (GET_CODE (x
) == MEM
)
5576 x
= change_address (x
, VOIDmode
,
5577 plus_constant (Pmode
, XEXP (x
, 0), 4));
5579 output_operand_lossage ("register or memory expression expected "
5580 "for 'N' output modifier");
5584 if (GET_CODE (x
) == REG
)
5585 x
= gen_rtx_REG (GET_MODE (x
), REGNO (x
) + 1);
5586 else if (GET_CODE (x
) == MEM
)
5587 x
= change_address (x
, VOIDmode
,
5588 plus_constant (Pmode
, XEXP (x
, 0), 8));
5590 output_operand_lossage ("register or memory expression expected "
5591 "for 'M' output modifier");
5595 print_shift_count_operand (file
, x
);
5599 switch (GET_CODE (x
))
5602 fprintf (file
, "%s", reg_names
[REGNO (x
)]);
5606 output_address (XEXP (x
, 0));
5613 output_addr_const (file
, x
);
5626 ival
= ((ival
& 0xff) ^ 0x80) - 0x80;
5632 ival
= ((ival
& 0xffff) ^ 0x8000) - 0x8000;
5635 ival
= s390_extract_part (x
, HImode
, 0);
5638 ival
= s390_extract_part (x
, HImode
, -1);
5641 ival
= s390_extract_part (x
, SImode
, 0);
5644 ival
= s390_extract_part (x
, SImode
, -1);
5655 len
= (code
== 's' || code
== 'e' ? 64 : 32);
5656 ok
= s390_contiguous_bitmask_p (ival
, len
, &pos
, &len
);
5658 if (code
== 's' || code
== 't')
5659 ival
= 64 - pos
- len
;
5661 ival
= 64 - 1 - pos
;
5665 output_operand_lossage ("invalid constant for output modifier '%c'", code
);
5667 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, ival
);
5671 gcc_assert (GET_MODE (x
) == VOIDmode
);
5673 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, CONST_DOUBLE_LOW (x
) & 0xff);
5674 else if (code
== 'x')
5675 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, CONST_DOUBLE_LOW (x
) & 0xffff);
5676 else if (code
== 'h')
5677 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
5678 ((CONST_DOUBLE_LOW (x
) & 0xffff) ^ 0x8000) - 0x8000);
5682 output_operand_lossage ("invalid constant - try using "
5683 "an output modifier");
5685 output_operand_lossage ("invalid constant for output modifier '%c'",
5692 output_operand_lossage ("invalid expression - try using "
5693 "an output modifier");
5695 output_operand_lossage ("invalid expression for output "
5696 "modifier '%c'", code
);
5701 /* Target hook for assembling integer objects. We need to define it
5702 here to work a round a bug in some versions of GAS, which couldn't
5703 handle values smaller than INT_MIN when printed in decimal. */
5706 s390_assemble_integer (rtx x
, unsigned int size
, int aligned_p
)
5708 if (size
== 8 && aligned_p
5709 && GET_CODE (x
) == CONST_INT
&& INTVAL (x
) < INT_MIN
)
5711 fprintf (asm_out_file
, "\t.quad\t" HOST_WIDE_INT_PRINT_HEX
"\n",
5715 return default_assemble_integer (x
, size
, aligned_p
);
5718 /* Returns true if register REGNO is used for forming
5719 a memory address in expression X. */
5722 reg_used_in_mem_p (int regno
, rtx x
)
5724 enum rtx_code code
= GET_CODE (x
);
5730 if (refers_to_regno_p (regno
, regno
+1,
5734 else if (code
== SET
5735 && GET_CODE (SET_DEST (x
)) == PC
)
5737 if (refers_to_regno_p (regno
, regno
+1,
5742 fmt
= GET_RTX_FORMAT (code
);
5743 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
5746 && reg_used_in_mem_p (regno
, XEXP (x
, i
)))
5749 else if (fmt
[i
] == 'E')
5750 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
5751 if (reg_used_in_mem_p (regno
, XVECEXP (x
, i
, j
)))
5757 /* Returns true if expression DEP_RTX sets an address register
5758 used by instruction INSN to address memory. */
5761 addr_generation_dependency_p (rtx dep_rtx
, rtx_insn
*insn
)
5765 if (NONJUMP_INSN_P (dep_rtx
))
5766 dep_rtx
= PATTERN (dep_rtx
);
5768 if (GET_CODE (dep_rtx
) == SET
)
5770 target
= SET_DEST (dep_rtx
);
5771 if (GET_CODE (target
) == STRICT_LOW_PART
)
5772 target
= XEXP (target
, 0);
5773 while (GET_CODE (target
) == SUBREG
)
5774 target
= SUBREG_REG (target
);
5776 if (GET_CODE (target
) == REG
)
5778 int regno
= REGNO (target
);
5780 if (s390_safe_attr_type (insn
) == TYPE_LA
)
5782 pat
= PATTERN (insn
);
5783 if (GET_CODE (pat
) == PARALLEL
)
5785 gcc_assert (XVECLEN (pat
, 0) == 2);
5786 pat
= XVECEXP (pat
, 0, 0);
5788 gcc_assert (GET_CODE (pat
) == SET
);
5789 return refers_to_regno_p (regno
, regno
+1, SET_SRC (pat
), 0);
5791 else if (get_attr_atype (insn
) == ATYPE_AGEN
)
5792 return reg_used_in_mem_p (regno
, PATTERN (insn
));
5798 /* Return 1, if dep_insn sets register used in insn in the agen unit. */
5801 s390_agen_dep_p (rtx_insn
*dep_insn
, rtx_insn
*insn
)
5803 rtx dep_rtx
= PATTERN (dep_insn
);
5806 if (GET_CODE (dep_rtx
) == SET
5807 && addr_generation_dependency_p (dep_rtx
, insn
))
5809 else if (GET_CODE (dep_rtx
) == PARALLEL
)
5811 for (i
= 0; i
< XVECLEN (dep_rtx
, 0); i
++)
5813 if (addr_generation_dependency_p (XVECEXP (dep_rtx
, 0, i
), insn
))
5821 /* A C statement (sans semicolon) to update the integer scheduling priority
5822 INSN_PRIORITY (INSN). Increase the priority to execute the INSN earlier,
5823 reduce the priority to execute INSN later. Do not define this macro if
5824 you do not need to adjust the scheduling priorities of insns.
5826 A STD instruction should be scheduled earlier,
5827 in order to use the bypass. */
5829 s390_adjust_priority (rtx_insn
*insn
, int priority
)
5831 if (! INSN_P (insn
))
5834 if (s390_tune
!= PROCESSOR_2084_Z990
5835 && s390_tune
!= PROCESSOR_2094_Z9_109
5836 && s390_tune
!= PROCESSOR_2097_Z10
5837 && s390_tune
!= PROCESSOR_2817_Z196
5838 && s390_tune
!= PROCESSOR_2827_ZEC12
)
5841 switch (s390_safe_attr_type (insn
))
5845 priority
= priority
<< 3;
5849 priority
= priority
<< 1;
5858 /* The number of instructions that can be issued per cycle. */
5861 s390_issue_rate (void)
5865 case PROCESSOR_2084_Z990
:
5866 case PROCESSOR_2094_Z9_109
:
5867 case PROCESSOR_2817_Z196
:
5869 case PROCESSOR_2097_Z10
:
5870 case PROCESSOR_2827_ZEC12
:
5878 s390_first_cycle_multipass_dfa_lookahead (void)
5883 /* Annotate every literal pool reference in X by an UNSPEC_LTREF expression.
5884 Fix up MEMs as required. */
5887 annotate_constant_pool_refs (rtx
*x
)
5892 gcc_assert (GET_CODE (*x
) != SYMBOL_REF
5893 || !CONSTANT_POOL_ADDRESS_P (*x
));
5895 /* Literal pool references can only occur inside a MEM ... */
5896 if (GET_CODE (*x
) == MEM
)
5898 rtx memref
= XEXP (*x
, 0);
5900 if (GET_CODE (memref
) == SYMBOL_REF
5901 && CONSTANT_POOL_ADDRESS_P (memref
))
5903 rtx base
= cfun
->machine
->base_reg
;
5904 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, memref
, base
),
5907 *x
= replace_equiv_address (*x
, addr
);
5911 if (GET_CODE (memref
) == CONST
5912 && GET_CODE (XEXP (memref
, 0)) == PLUS
5913 && GET_CODE (XEXP (XEXP (memref
, 0), 1)) == CONST_INT
5914 && GET_CODE (XEXP (XEXP (memref
, 0), 0)) == SYMBOL_REF
5915 && CONSTANT_POOL_ADDRESS_P (XEXP (XEXP (memref
, 0), 0)))
5917 HOST_WIDE_INT off
= INTVAL (XEXP (XEXP (memref
, 0), 1));
5918 rtx sym
= XEXP (XEXP (memref
, 0), 0);
5919 rtx base
= cfun
->machine
->base_reg
;
5920 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, sym
, base
),
5923 *x
= replace_equiv_address (*x
, plus_constant (Pmode
, addr
, off
));
5928 /* ... or a load-address type pattern. */
5929 if (GET_CODE (*x
) == SET
)
5931 rtx addrref
= SET_SRC (*x
);
5933 if (GET_CODE (addrref
) == SYMBOL_REF
5934 && CONSTANT_POOL_ADDRESS_P (addrref
))
5936 rtx base
= cfun
->machine
->base_reg
;
5937 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, addrref
, base
),
5940 SET_SRC (*x
) = addr
;
5944 if (GET_CODE (addrref
) == CONST
5945 && GET_CODE (XEXP (addrref
, 0)) == PLUS
5946 && GET_CODE (XEXP (XEXP (addrref
, 0), 1)) == CONST_INT
5947 && GET_CODE (XEXP (XEXP (addrref
, 0), 0)) == SYMBOL_REF
5948 && CONSTANT_POOL_ADDRESS_P (XEXP (XEXP (addrref
, 0), 0)))
5950 HOST_WIDE_INT off
= INTVAL (XEXP (XEXP (addrref
, 0), 1));
5951 rtx sym
= XEXP (XEXP (addrref
, 0), 0);
5952 rtx base
= cfun
->machine
->base_reg
;
5953 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, sym
, base
),
5956 SET_SRC (*x
) = plus_constant (Pmode
, addr
, off
);
5961 /* Annotate LTREL_BASE as well. */
5962 if (GET_CODE (*x
) == UNSPEC
5963 && XINT (*x
, 1) == UNSPEC_LTREL_BASE
)
5965 rtx base
= cfun
->machine
->base_reg
;
5966 *x
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, XVECEXP (*x
, 0, 0), base
),
5971 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
5972 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
5976 annotate_constant_pool_refs (&XEXP (*x
, i
));
5978 else if (fmt
[i
] == 'E')
5980 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
5981 annotate_constant_pool_refs (&XVECEXP (*x
, i
, j
));
5986 /* Split all branches that exceed the maximum distance.
5987 Returns true if this created a new literal pool entry. */
5990 s390_split_branches (void)
5992 rtx temp_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
5993 int new_literal
= 0, ret
;
5998 /* We need correct insn addresses. */
6000 shorten_branches (get_insns ());
6002 /* Find all branches that exceed 64KB, and split them. */
6004 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6006 if (! JUMP_P (insn
) || tablejump_p (insn
, NULL
, NULL
))
6009 pat
= PATTERN (insn
);
6010 if (GET_CODE (pat
) == PARALLEL
)
6011 pat
= XVECEXP (pat
, 0, 0);
6012 if (GET_CODE (pat
) != SET
|| SET_DEST (pat
) != pc_rtx
)
6015 if (GET_CODE (SET_SRC (pat
)) == LABEL_REF
)
6017 label
= &SET_SRC (pat
);
6019 else if (GET_CODE (SET_SRC (pat
)) == IF_THEN_ELSE
)
6021 if (GET_CODE (XEXP (SET_SRC (pat
), 1)) == LABEL_REF
)
6022 label
= &XEXP (SET_SRC (pat
), 1);
6023 else if (GET_CODE (XEXP (SET_SRC (pat
), 2)) == LABEL_REF
)
6024 label
= &XEXP (SET_SRC (pat
), 2);
6031 if (get_attr_length (insn
) <= 4)
6034 /* We are going to use the return register as scratch register,
6035 make sure it will be saved/restored by the prologue/epilogue. */
6036 cfun_frame_layout
.save_return_addr_p
= 1;
6041 rtx mem
= force_const_mem (Pmode
, *label
);
6042 rtx_insn
*set_insn
= emit_insn_before (gen_rtx_SET (Pmode
, temp_reg
, mem
), insn
);
6043 INSN_ADDRESSES_NEW (set_insn
, -1);
6044 annotate_constant_pool_refs (&PATTERN (set_insn
));
6051 target
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, *label
),
6052 UNSPEC_LTREL_OFFSET
);
6053 target
= gen_rtx_CONST (Pmode
, target
);
6054 target
= force_const_mem (Pmode
, target
);
6055 rtx_insn
*set_insn
= emit_insn_before (gen_rtx_SET (Pmode
, temp_reg
, target
), insn
);
6056 INSN_ADDRESSES_NEW (set_insn
, -1);
6057 annotate_constant_pool_refs (&PATTERN (set_insn
));
6059 target
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, XEXP (target
, 0),
6060 cfun
->machine
->base_reg
),
6062 target
= gen_rtx_PLUS (Pmode
, temp_reg
, target
);
6065 ret
= validate_change (insn
, label
, target
, 0);
6073 /* Find an annotated literal pool symbol referenced in RTX X,
6074 and store it at REF. Will abort if X contains references to
6075 more than one such pool symbol; multiple references to the same
6076 symbol are allowed, however.
6078 The rtx pointed to by REF must be initialized to NULL_RTX
6079 by the caller before calling this routine. */
6082 find_constant_pool_ref (rtx x
, rtx
*ref
)
6087 /* Ignore LTREL_BASE references. */
6088 if (GET_CODE (x
) == UNSPEC
6089 && XINT (x
, 1) == UNSPEC_LTREL_BASE
)
6091 /* Likewise POOL_ENTRY insns. */
6092 if (GET_CODE (x
) == UNSPEC_VOLATILE
6093 && XINT (x
, 1) == UNSPECV_POOL_ENTRY
)
6096 gcc_assert (GET_CODE (x
) != SYMBOL_REF
6097 || !CONSTANT_POOL_ADDRESS_P (x
));
6099 if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_LTREF
)
6101 rtx sym
= XVECEXP (x
, 0, 0);
6102 gcc_assert (GET_CODE (sym
) == SYMBOL_REF
6103 && CONSTANT_POOL_ADDRESS_P (sym
));
6105 if (*ref
== NULL_RTX
)
6108 gcc_assert (*ref
== sym
);
6113 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
6114 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
6118 find_constant_pool_ref (XEXP (x
, i
), ref
);
6120 else if (fmt
[i
] == 'E')
6122 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
6123 find_constant_pool_ref (XVECEXP (x
, i
, j
), ref
);
6128 /* Replace every reference to the annotated literal pool
6129 symbol REF in X by its base plus OFFSET. */
6132 replace_constant_pool_ref (rtx
*x
, rtx ref
, rtx offset
)
6137 gcc_assert (*x
!= ref
);
6139 if (GET_CODE (*x
) == UNSPEC
6140 && XINT (*x
, 1) == UNSPEC_LTREF
6141 && XVECEXP (*x
, 0, 0) == ref
)
6143 *x
= gen_rtx_PLUS (Pmode
, XVECEXP (*x
, 0, 1), offset
);
6147 if (GET_CODE (*x
) == PLUS
6148 && GET_CODE (XEXP (*x
, 1)) == CONST_INT
6149 && GET_CODE (XEXP (*x
, 0)) == UNSPEC
6150 && XINT (XEXP (*x
, 0), 1) == UNSPEC_LTREF
6151 && XVECEXP (XEXP (*x
, 0), 0, 0) == ref
)
6153 rtx addr
= gen_rtx_PLUS (Pmode
, XVECEXP (XEXP (*x
, 0), 0, 1), offset
);
6154 *x
= plus_constant (Pmode
, addr
, INTVAL (XEXP (*x
, 1)));
6158 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
6159 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
6163 replace_constant_pool_ref (&XEXP (*x
, i
), ref
, offset
);
6165 else if (fmt
[i
] == 'E')
6167 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
6168 replace_constant_pool_ref (&XVECEXP (*x
, i
, j
), ref
, offset
);
6173 /* Check whether X contains an UNSPEC_LTREL_BASE.
6174 Return its constant pool symbol if found, NULL_RTX otherwise. */
6177 find_ltrel_base (rtx x
)
6182 if (GET_CODE (x
) == UNSPEC
6183 && XINT (x
, 1) == UNSPEC_LTREL_BASE
)
6184 return XVECEXP (x
, 0, 0);
6186 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
6187 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
6191 rtx fnd
= find_ltrel_base (XEXP (x
, i
));
6195 else if (fmt
[i
] == 'E')
6197 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
6199 rtx fnd
= find_ltrel_base (XVECEXP (x
, i
, j
));
6209 /* Replace any occurrence of UNSPEC_LTREL_BASE in X with its base. */
6212 replace_ltrel_base (rtx
*x
)
6217 if (GET_CODE (*x
) == UNSPEC
6218 && XINT (*x
, 1) == UNSPEC_LTREL_BASE
)
6220 *x
= XVECEXP (*x
, 0, 1);
6224 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
6225 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
6229 replace_ltrel_base (&XEXP (*x
, i
));
6231 else if (fmt
[i
] == 'E')
6233 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
6234 replace_ltrel_base (&XVECEXP (*x
, i
, j
));
6240 /* We keep a list of constants which we have to add to internal
6241 constant tables in the middle of large functions. */
6243 #define NR_C_MODES 11
6244 enum machine_mode constant_modes
[NR_C_MODES
] =
6246 TFmode
, TImode
, TDmode
,
6247 DFmode
, DImode
, DDmode
,
6248 SFmode
, SImode
, SDmode
,
6255 struct constant
*next
;
6257 rtx_code_label
*label
;
6260 struct constant_pool
6262 struct constant_pool
*next
;
6263 rtx_insn
*first_insn
;
6264 rtx_insn
*pool_insn
;
6266 rtx_insn
*emit_pool_after
;
6268 struct constant
*constants
[NR_C_MODES
];
6269 struct constant
*execute
;
6270 rtx_code_label
*label
;
6274 /* Allocate new constant_pool structure. */
6276 static struct constant_pool
*
6277 s390_alloc_pool (void)
6279 struct constant_pool
*pool
;
6282 pool
= (struct constant_pool
*) xmalloc (sizeof *pool
);
6284 for (i
= 0; i
< NR_C_MODES
; i
++)
6285 pool
->constants
[i
] = NULL
;
6287 pool
->execute
= NULL
;
6288 pool
->label
= gen_label_rtx ();
6289 pool
->first_insn
= NULL
;
6290 pool
->pool_insn
= NULL
;
6291 pool
->insns
= BITMAP_ALLOC (NULL
);
6293 pool
->emit_pool_after
= NULL
;
6298 /* Create new constant pool covering instructions starting at INSN
6299 and chain it to the end of POOL_LIST. */
6301 static struct constant_pool
*
6302 s390_start_pool (struct constant_pool
**pool_list
, rtx_insn
*insn
)
6304 struct constant_pool
*pool
, **prev
;
6306 pool
= s390_alloc_pool ();
6307 pool
->first_insn
= insn
;
6309 for (prev
= pool_list
; *prev
; prev
= &(*prev
)->next
)
6316 /* End range of instructions covered by POOL at INSN and emit
6317 placeholder insn representing the pool. */
6320 s390_end_pool (struct constant_pool
*pool
, rtx_insn
*insn
)
6322 rtx pool_size
= GEN_INT (pool
->size
+ 8 /* alignment slop */);
6325 insn
= get_last_insn ();
6327 pool
->pool_insn
= emit_insn_after (gen_pool (pool_size
), insn
);
6328 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
6331 /* Add INSN to the list of insns covered by POOL. */
6334 s390_add_pool_insn (struct constant_pool
*pool
, rtx insn
)
6336 bitmap_set_bit (pool
->insns
, INSN_UID (insn
));
6339 /* Return pool out of POOL_LIST that covers INSN. */
6341 static struct constant_pool
*
6342 s390_find_pool (struct constant_pool
*pool_list
, rtx insn
)
6344 struct constant_pool
*pool
;
6346 for (pool
= pool_list
; pool
; pool
= pool
->next
)
6347 if (bitmap_bit_p (pool
->insns
, INSN_UID (insn
)))
6353 /* Add constant VAL of mode MODE to the constant pool POOL. */
6356 s390_add_constant (struct constant_pool
*pool
, rtx val
, enum machine_mode mode
)
6361 for (i
= 0; i
< NR_C_MODES
; i
++)
6362 if (constant_modes
[i
] == mode
)
6364 gcc_assert (i
!= NR_C_MODES
);
6366 for (c
= pool
->constants
[i
]; c
!= NULL
; c
= c
->next
)
6367 if (rtx_equal_p (val
, c
->value
))
6372 c
= (struct constant
*) xmalloc (sizeof *c
);
6374 c
->label
= gen_label_rtx ();
6375 c
->next
= pool
->constants
[i
];
6376 pool
->constants
[i
] = c
;
6377 pool
->size
+= GET_MODE_SIZE (mode
);
6381 /* Return an rtx that represents the offset of X from the start of
6385 s390_pool_offset (struct constant_pool
*pool
, rtx x
)
6389 label
= gen_rtx_LABEL_REF (GET_MODE (x
), pool
->label
);
6390 x
= gen_rtx_UNSPEC (GET_MODE (x
), gen_rtvec (2, x
, label
),
6391 UNSPEC_POOL_OFFSET
);
6392 return gen_rtx_CONST (GET_MODE (x
), x
);
6395 /* Find constant VAL of mode MODE in the constant pool POOL.
6396 Return an RTX describing the distance from the start of
6397 the pool to the location of the new constant. */
6400 s390_find_constant (struct constant_pool
*pool
, rtx val
,
6401 enum machine_mode mode
)
6406 for (i
= 0; i
< NR_C_MODES
; i
++)
6407 if (constant_modes
[i
] == mode
)
6409 gcc_assert (i
!= NR_C_MODES
);
6411 for (c
= pool
->constants
[i
]; c
!= NULL
; c
= c
->next
)
6412 if (rtx_equal_p (val
, c
->value
))
6417 return s390_pool_offset (pool
, gen_rtx_LABEL_REF (Pmode
, c
->label
));
6420 /* Check whether INSN is an execute. Return the label_ref to its
6421 execute target template if so, NULL_RTX otherwise. */
6424 s390_execute_label (rtx insn
)
6426 if (NONJUMP_INSN_P (insn
)
6427 && GET_CODE (PATTERN (insn
)) == PARALLEL
6428 && GET_CODE (XVECEXP (PATTERN (insn
), 0, 0)) == UNSPEC
6429 && XINT (XVECEXP (PATTERN (insn
), 0, 0), 1) == UNSPEC_EXECUTE
)
6430 return XVECEXP (XVECEXP (PATTERN (insn
), 0, 0), 0, 2);
6435 /* Add execute target for INSN to the constant pool POOL. */
6438 s390_add_execute (struct constant_pool
*pool
, rtx insn
)
6442 for (c
= pool
->execute
; c
!= NULL
; c
= c
->next
)
6443 if (INSN_UID (insn
) == INSN_UID (c
->value
))
6448 c
= (struct constant
*) xmalloc (sizeof *c
);
6450 c
->label
= gen_label_rtx ();
6451 c
->next
= pool
->execute
;
6457 /* Find execute target for INSN in the constant pool POOL.
6458 Return an RTX describing the distance from the start of
6459 the pool to the location of the execute target. */
6462 s390_find_execute (struct constant_pool
*pool
, rtx insn
)
6466 for (c
= pool
->execute
; c
!= NULL
; c
= c
->next
)
6467 if (INSN_UID (insn
) == INSN_UID (c
->value
))
6472 return s390_pool_offset (pool
, gen_rtx_LABEL_REF (Pmode
, c
->label
));
6475 /* For an execute INSN, extract the execute target template. */
6478 s390_execute_target (rtx insn
)
6480 rtx pattern
= PATTERN (insn
);
6481 gcc_assert (s390_execute_label (insn
));
6483 if (XVECLEN (pattern
, 0) == 2)
6485 pattern
= copy_rtx (XVECEXP (pattern
, 0, 1));
6489 rtvec vec
= rtvec_alloc (XVECLEN (pattern
, 0) - 1);
6492 for (i
= 0; i
< XVECLEN (pattern
, 0) - 1; i
++)
6493 RTVEC_ELT (vec
, i
) = copy_rtx (XVECEXP (pattern
, 0, i
+ 1));
6495 pattern
= gen_rtx_PARALLEL (VOIDmode
, vec
);
6501 /* Indicate that INSN cannot be duplicated. This is the case for
6502 execute insns that carry a unique label. */
6505 s390_cannot_copy_insn_p (rtx_insn
*insn
)
6507 rtx label
= s390_execute_label (insn
);
6508 return label
&& label
!= const0_rtx
;
6511 /* Dump out the constants in POOL. If REMOTE_LABEL is true,
6512 do not emit the pool base label. */
6515 s390_dump_pool (struct constant_pool
*pool
, bool remote_label
)
6518 rtx_insn
*insn
= pool
->pool_insn
;
6521 /* Switch to rodata section. */
6522 if (TARGET_CPU_ZARCH
)
6524 insn
= emit_insn_after (gen_pool_section_start (), insn
);
6525 INSN_ADDRESSES_NEW (insn
, -1);
6528 /* Ensure minimum pool alignment. */
6529 if (TARGET_CPU_ZARCH
)
6530 insn
= emit_insn_after (gen_pool_align (GEN_INT (8)), insn
);
6532 insn
= emit_insn_after (gen_pool_align (GEN_INT (4)), insn
);
6533 INSN_ADDRESSES_NEW (insn
, -1);
6535 /* Emit pool base label. */
6538 insn
= emit_label_after (pool
->label
, insn
);
6539 INSN_ADDRESSES_NEW (insn
, -1);
6542 /* Dump constants in descending alignment requirement order,
6543 ensuring proper alignment for every constant. */
6544 for (i
= 0; i
< NR_C_MODES
; i
++)
6545 for (c
= pool
->constants
[i
]; c
; c
= c
->next
)
6547 /* Convert UNSPEC_LTREL_OFFSET unspecs to pool-relative references. */
6548 rtx value
= copy_rtx (c
->value
);
6549 if (GET_CODE (value
) == CONST
6550 && GET_CODE (XEXP (value
, 0)) == UNSPEC
6551 && XINT (XEXP (value
, 0), 1) == UNSPEC_LTREL_OFFSET
6552 && XVECLEN (XEXP (value
, 0), 0) == 1)
6553 value
= s390_pool_offset (pool
, XVECEXP (XEXP (value
, 0), 0, 0));
6555 insn
= emit_label_after (c
->label
, insn
);
6556 INSN_ADDRESSES_NEW (insn
, -1);
6558 value
= gen_rtx_UNSPEC_VOLATILE (constant_modes
[i
],
6559 gen_rtvec (1, value
),
6560 UNSPECV_POOL_ENTRY
);
6561 insn
= emit_insn_after (value
, insn
);
6562 INSN_ADDRESSES_NEW (insn
, -1);
6565 /* Ensure minimum alignment for instructions. */
6566 insn
= emit_insn_after (gen_pool_align (GEN_INT (2)), insn
);
6567 INSN_ADDRESSES_NEW (insn
, -1);
6569 /* Output in-pool execute template insns. */
6570 for (c
= pool
->execute
; c
; c
= c
->next
)
6572 insn
= emit_label_after (c
->label
, insn
);
6573 INSN_ADDRESSES_NEW (insn
, -1);
6575 insn
= emit_insn_after (s390_execute_target (c
->value
), insn
);
6576 INSN_ADDRESSES_NEW (insn
, -1);
6579 /* Switch back to previous section. */
6580 if (TARGET_CPU_ZARCH
)
6582 insn
= emit_insn_after (gen_pool_section_end (), insn
);
6583 INSN_ADDRESSES_NEW (insn
, -1);
6586 insn
= emit_barrier_after (insn
);
6587 INSN_ADDRESSES_NEW (insn
, -1);
6589 /* Remove placeholder insn. */
6590 remove_insn (pool
->pool_insn
);
6593 /* Free all memory used by POOL. */
6596 s390_free_pool (struct constant_pool
*pool
)
6598 struct constant
*c
, *next
;
6601 for (i
= 0; i
< NR_C_MODES
; i
++)
6602 for (c
= pool
->constants
[i
]; c
; c
= next
)
6608 for (c
= pool
->execute
; c
; c
= next
)
6614 BITMAP_FREE (pool
->insns
);
6619 /* Collect main literal pool. Return NULL on overflow. */
6621 static struct constant_pool
*
6622 s390_mainpool_start (void)
6624 struct constant_pool
*pool
;
6627 pool
= s390_alloc_pool ();
6629 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6631 if (NONJUMP_INSN_P (insn
)
6632 && GET_CODE (PATTERN (insn
)) == SET
6633 && GET_CODE (SET_SRC (PATTERN (insn
))) == UNSPEC_VOLATILE
6634 && XINT (SET_SRC (PATTERN (insn
)), 1) == UNSPECV_MAIN_POOL
)
6636 /* There might be two main_pool instructions if base_reg
6637 is call-clobbered; one for shrink-wrapped code and one
6638 for the rest. We want to keep the first. */
6639 if (pool
->pool_insn
)
6641 insn
= PREV_INSN (insn
);
6642 delete_insn (NEXT_INSN (insn
));
6645 pool
->pool_insn
= insn
;
6648 if (!TARGET_CPU_ZARCH
&& s390_execute_label (insn
))
6650 s390_add_execute (pool
, insn
);
6652 else if (NONJUMP_INSN_P (insn
) || CALL_P (insn
))
6654 rtx pool_ref
= NULL_RTX
;
6655 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
6658 rtx constant
= get_pool_constant (pool_ref
);
6659 enum machine_mode mode
= get_pool_mode (pool_ref
);
6660 s390_add_constant (pool
, constant
, mode
);
6664 /* If hot/cold partitioning is enabled we have to make sure that
6665 the literal pool is emitted in the same section where the
6666 initialization of the literal pool base pointer takes place.
6667 emit_pool_after is only used in the non-overflow case on non
6668 Z cpus where we can emit the literal pool at the end of the
6669 function body within the text section. */
6671 && NOTE_KIND (insn
) == NOTE_INSN_SWITCH_TEXT_SECTIONS
6672 && !pool
->emit_pool_after
)
6673 pool
->emit_pool_after
= PREV_INSN (insn
);
6676 gcc_assert (pool
->pool_insn
|| pool
->size
== 0);
6678 if (pool
->size
>= 4096)
6680 /* We're going to chunkify the pool, so remove the main
6681 pool placeholder insn. */
6682 remove_insn (pool
->pool_insn
);
6684 s390_free_pool (pool
);
6688 /* If the functions ends with the section where the literal pool
6689 should be emitted set the marker to its end. */
6690 if (pool
&& !pool
->emit_pool_after
)
6691 pool
->emit_pool_after
= get_last_insn ();
6696 /* POOL holds the main literal pool as collected by s390_mainpool_start.
6697 Modify the current function to output the pool constants as well as
6698 the pool register setup instruction. */
6701 s390_mainpool_finish (struct constant_pool
*pool
)
6703 rtx base_reg
= cfun
->machine
->base_reg
;
6705 /* If the pool is empty, we're done. */
6706 if (pool
->size
== 0)
6708 /* We don't actually need a base register after all. */
6709 cfun
->machine
->base_reg
= NULL_RTX
;
6711 if (pool
->pool_insn
)
6712 remove_insn (pool
->pool_insn
);
6713 s390_free_pool (pool
);
6717 /* We need correct insn addresses. */
6718 shorten_branches (get_insns ());
6720 /* On zSeries, we use a LARL to load the pool register. The pool is
6721 located in the .rodata section, so we emit it after the function. */
6722 if (TARGET_CPU_ZARCH
)
6724 rtx set
= gen_main_base_64 (base_reg
, pool
->label
);
6725 rtx_insn
*insn
= emit_insn_after (set
, pool
->pool_insn
);
6726 INSN_ADDRESSES_NEW (insn
, -1);
6727 remove_insn (pool
->pool_insn
);
6729 insn
= get_last_insn ();
6730 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
6731 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
6733 s390_dump_pool (pool
, 0);
6736 /* On S/390, if the total size of the function's code plus literal pool
6737 does not exceed 4096 bytes, we use BASR to set up a function base
6738 pointer, and emit the literal pool at the end of the function. */
6739 else if (INSN_ADDRESSES (INSN_UID (pool
->emit_pool_after
))
6740 + pool
->size
+ 8 /* alignment slop */ < 4096)
6742 rtx set
= gen_main_base_31_small (base_reg
, pool
->label
);
6743 rtx_insn
*insn
= emit_insn_after (set
, pool
->pool_insn
);
6744 INSN_ADDRESSES_NEW (insn
, -1);
6745 remove_insn (pool
->pool_insn
);
6747 insn
= emit_label_after (pool
->label
, insn
);
6748 INSN_ADDRESSES_NEW (insn
, -1);
6750 /* emit_pool_after will be set by s390_mainpool_start to the
6751 last insn of the section where the literal pool should be
6753 insn
= pool
->emit_pool_after
;
6755 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
6756 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
6758 s390_dump_pool (pool
, 1);
6761 /* Otherwise, we emit an inline literal pool and use BASR to branch
6762 over it, setting up the pool register at the same time. */
6765 rtx_code_label
*pool_end
= gen_label_rtx ();
6767 rtx pat
= gen_main_base_31_large (base_reg
, pool
->label
, pool_end
);
6768 rtx_insn
*insn
= emit_jump_insn_after (pat
, pool
->pool_insn
);
6769 JUMP_LABEL (insn
) = pool_end
;
6770 INSN_ADDRESSES_NEW (insn
, -1);
6771 remove_insn (pool
->pool_insn
);
6773 insn
= emit_label_after (pool
->label
, insn
);
6774 INSN_ADDRESSES_NEW (insn
, -1);
6776 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
6777 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
6779 insn
= emit_label_after (pool_end
, pool
->pool_insn
);
6780 INSN_ADDRESSES_NEW (insn
, -1);
6782 s390_dump_pool (pool
, 1);
6786 /* Replace all literal pool references. */
6788 for (rtx_insn
*insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6791 replace_ltrel_base (&PATTERN (insn
));
6793 if (NONJUMP_INSN_P (insn
) || CALL_P (insn
))
6795 rtx addr
, pool_ref
= NULL_RTX
;
6796 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
6799 if (s390_execute_label (insn
))
6800 addr
= s390_find_execute (pool
, insn
);
6802 addr
= s390_find_constant (pool
, get_pool_constant (pool_ref
),
6803 get_pool_mode (pool_ref
));
6805 replace_constant_pool_ref (&PATTERN (insn
), pool_ref
, addr
);
6806 INSN_CODE (insn
) = -1;
6812 /* Free the pool. */
6813 s390_free_pool (pool
);
6816 /* POOL holds the main literal pool as collected by s390_mainpool_start.
6817 We have decided we cannot use this pool, so revert all changes
6818 to the current function that were done by s390_mainpool_start. */
6820 s390_mainpool_cancel (struct constant_pool
*pool
)
6822 /* We didn't actually change the instruction stream, so simply
6823 free the pool memory. */
6824 s390_free_pool (pool
);
6828 /* Chunkify the literal pool. */
6830 #define S390_POOL_CHUNK_MIN 0xc00
6831 #define S390_POOL_CHUNK_MAX 0xe00
6833 static struct constant_pool
*
6834 s390_chunkify_start (void)
6836 struct constant_pool
*curr_pool
= NULL
, *pool_list
= NULL
;
6839 rtx pending_ltrel
= NULL_RTX
;
6842 rtx (*gen_reload_base
) (rtx
, rtx
) =
6843 TARGET_CPU_ZARCH
? gen_reload_base_64
: gen_reload_base_31
;
6846 /* We need correct insn addresses. */
6848 shorten_branches (get_insns ());
6850 /* Scan all insns and move literals to pool chunks. */
6852 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6854 bool section_switch_p
= false;
6856 /* Check for pending LTREL_BASE. */
6859 rtx ltrel_base
= find_ltrel_base (PATTERN (insn
));
6862 gcc_assert (ltrel_base
== pending_ltrel
);
6863 pending_ltrel
= NULL_RTX
;
6867 if (!TARGET_CPU_ZARCH
&& s390_execute_label (insn
))
6870 curr_pool
= s390_start_pool (&pool_list
, insn
);
6872 s390_add_execute (curr_pool
, insn
);
6873 s390_add_pool_insn (curr_pool
, insn
);
6875 else if (NONJUMP_INSN_P (insn
) || CALL_P (insn
))
6877 rtx pool_ref
= NULL_RTX
;
6878 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
6881 rtx constant
= get_pool_constant (pool_ref
);
6882 enum machine_mode mode
= get_pool_mode (pool_ref
);
6885 curr_pool
= s390_start_pool (&pool_list
, insn
);
6887 s390_add_constant (curr_pool
, constant
, mode
);
6888 s390_add_pool_insn (curr_pool
, insn
);
6890 /* Don't split the pool chunk between a LTREL_OFFSET load
6891 and the corresponding LTREL_BASE. */
6892 if (GET_CODE (constant
) == CONST
6893 && GET_CODE (XEXP (constant
, 0)) == UNSPEC
6894 && XINT (XEXP (constant
, 0), 1) == UNSPEC_LTREL_OFFSET
)
6896 gcc_assert (!pending_ltrel
);
6897 pending_ltrel
= pool_ref
;
6902 if (JUMP_P (insn
) || JUMP_TABLE_DATA_P (insn
) || LABEL_P (insn
))
6905 s390_add_pool_insn (curr_pool
, insn
);
6906 /* An LTREL_BASE must follow within the same basic block. */
6907 gcc_assert (!pending_ltrel
);
6911 switch (NOTE_KIND (insn
))
6913 case NOTE_INSN_SWITCH_TEXT_SECTIONS
:
6914 section_switch_p
= true;
6916 case NOTE_INSN_VAR_LOCATION
:
6917 case NOTE_INSN_CALL_ARG_LOCATION
:
6924 || INSN_ADDRESSES_SIZE () <= (size_t) INSN_UID (insn
)
6925 || INSN_ADDRESSES (INSN_UID (insn
)) == -1)
6928 if (TARGET_CPU_ZARCH
)
6930 if (curr_pool
->size
< S390_POOL_CHUNK_MAX
)
6933 s390_end_pool (curr_pool
, NULL
);
6938 int chunk_size
= INSN_ADDRESSES (INSN_UID (insn
))
6939 - INSN_ADDRESSES (INSN_UID (curr_pool
->first_insn
))
6942 /* We will later have to insert base register reload insns.
6943 Those will have an effect on code size, which we need to
6944 consider here. This calculation makes rather pessimistic
6945 worst-case assumptions. */
6949 if (chunk_size
< S390_POOL_CHUNK_MIN
6950 && curr_pool
->size
< S390_POOL_CHUNK_MIN
6951 && !section_switch_p
)
6954 /* Pool chunks can only be inserted after BARRIERs ... */
6955 if (BARRIER_P (insn
))
6957 s390_end_pool (curr_pool
, insn
);
6962 /* ... so if we don't find one in time, create one. */
6963 else if (chunk_size
> S390_POOL_CHUNK_MAX
6964 || curr_pool
->size
> S390_POOL_CHUNK_MAX
6965 || section_switch_p
)
6967 rtx_insn
*label
, *jump
, *barrier
, *next
, *prev
;
6969 if (!section_switch_p
)
6971 /* We can insert the barrier only after a 'real' insn. */
6972 if (! NONJUMP_INSN_P (insn
) && ! CALL_P (insn
))
6974 if (get_attr_length (insn
) == 0)
6976 /* Don't separate LTREL_BASE from the corresponding
6977 LTREL_OFFSET load. */
6984 next
= NEXT_INSN (insn
);
6988 && (NOTE_KIND (next
) == NOTE_INSN_VAR_LOCATION
6989 || NOTE_KIND (next
) == NOTE_INSN_CALL_ARG_LOCATION
));
6993 gcc_assert (!pending_ltrel
);
6995 /* The old pool has to end before the section switch
6996 note in order to make it part of the current
6998 insn
= PREV_INSN (insn
);
7001 label
= gen_label_rtx ();
7003 if (prev
&& NOTE_P (prev
))
7004 prev
= prev_nonnote_insn (prev
);
7006 jump
= emit_jump_insn_after_setloc (gen_jump (label
), insn
,
7007 INSN_LOCATION (prev
));
7009 jump
= emit_jump_insn_after_noloc (gen_jump (label
), insn
);
7010 barrier
= emit_barrier_after (jump
);
7011 insn
= emit_label_after (label
, barrier
);
7012 JUMP_LABEL (jump
) = label
;
7013 LABEL_NUSES (label
) = 1;
7015 INSN_ADDRESSES_NEW (jump
, -1);
7016 INSN_ADDRESSES_NEW (barrier
, -1);
7017 INSN_ADDRESSES_NEW (insn
, -1);
7019 s390_end_pool (curr_pool
, barrier
);
7027 s390_end_pool (curr_pool
, NULL
);
7028 gcc_assert (!pending_ltrel
);
7030 /* Find all labels that are branched into
7031 from an insn belonging to a different chunk. */
7033 far_labels
= BITMAP_ALLOC (NULL
);
7035 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
7037 rtx_jump_table_data
*table
;
7039 /* Labels marked with LABEL_PRESERVE_P can be target
7040 of non-local jumps, so we have to mark them.
7041 The same holds for named labels.
7043 Don't do that, however, if it is the label before
7047 && (LABEL_PRESERVE_P (insn
) || LABEL_NAME (insn
)))
7049 rtx_insn
*vec_insn
= NEXT_INSN (insn
);
7050 if (! vec_insn
|| ! JUMP_TABLE_DATA_P (vec_insn
))
7051 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (insn
));
7053 /* Check potential targets in a table jump (casesi_jump). */
7054 else if (tablejump_p (insn
, NULL
, &table
))
7056 rtx vec_pat
= PATTERN (table
);
7057 int i
, diff_p
= GET_CODE (vec_pat
) == ADDR_DIFF_VEC
;
7059 for (i
= 0; i
< XVECLEN (vec_pat
, diff_p
); i
++)
7061 rtx label
= XEXP (XVECEXP (vec_pat
, diff_p
, i
), 0);
7063 if (s390_find_pool (pool_list
, label
)
7064 != s390_find_pool (pool_list
, insn
))
7065 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (label
));
7068 /* If we have a direct jump (conditional or unconditional),
7069 check all potential targets. */
7070 else if (JUMP_P (insn
))
7072 rtx pat
= PATTERN (insn
);
7074 if (GET_CODE (pat
) == PARALLEL
)
7075 pat
= XVECEXP (pat
, 0, 0);
7077 if (GET_CODE (pat
) == SET
)
7079 rtx label
= JUMP_LABEL (insn
);
7080 if (label
&& !ANY_RETURN_P (label
))
7082 if (s390_find_pool (pool_list
, label
)
7083 != s390_find_pool (pool_list
, insn
))
7084 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (label
));
7090 /* Insert base register reload insns before every pool. */
7092 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
7094 rtx new_insn
= gen_reload_base (cfun
->machine
->base_reg
,
7096 rtx_insn
*insn
= curr_pool
->first_insn
;
7097 INSN_ADDRESSES_NEW (emit_insn_before (new_insn
, insn
), -1);
7100 /* Insert base register reload insns at every far label. */
7102 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
7104 && bitmap_bit_p (far_labels
, CODE_LABEL_NUMBER (insn
)))
7106 struct constant_pool
*pool
= s390_find_pool (pool_list
, insn
);
7109 rtx new_insn
= gen_reload_base (cfun
->machine
->base_reg
,
7111 INSN_ADDRESSES_NEW (emit_insn_after (new_insn
, insn
), -1);
7116 BITMAP_FREE (far_labels
);
7119 /* Recompute insn addresses. */
7121 init_insn_lengths ();
7122 shorten_branches (get_insns ());
7127 /* POOL_LIST is a chunk list as prepared by s390_chunkify_start.
7128 After we have decided to use this list, finish implementing
7129 all changes to the current function as required. */
7132 s390_chunkify_finish (struct constant_pool
*pool_list
)
7134 struct constant_pool
*curr_pool
= NULL
;
7138 /* Replace all literal pool references. */
7140 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
7143 replace_ltrel_base (&PATTERN (insn
));
7145 curr_pool
= s390_find_pool (pool_list
, insn
);
7149 if (NONJUMP_INSN_P (insn
) || CALL_P (insn
))
7151 rtx addr
, pool_ref
= NULL_RTX
;
7152 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
7155 if (s390_execute_label (insn
))
7156 addr
= s390_find_execute (curr_pool
, insn
);
7158 addr
= s390_find_constant (curr_pool
,
7159 get_pool_constant (pool_ref
),
7160 get_pool_mode (pool_ref
));
7162 replace_constant_pool_ref (&PATTERN (insn
), pool_ref
, addr
);
7163 INSN_CODE (insn
) = -1;
7168 /* Dump out all literal pools. */
7170 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
7171 s390_dump_pool (curr_pool
, 0);
7173 /* Free pool list. */
7177 struct constant_pool
*next
= pool_list
->next
;
7178 s390_free_pool (pool_list
);
7183 /* POOL_LIST is a chunk list as prepared by s390_chunkify_start.
7184 We have decided we cannot use this list, so revert all changes
7185 to the current function that were done by s390_chunkify_start. */
7188 s390_chunkify_cancel (struct constant_pool
*pool_list
)
7190 struct constant_pool
*curr_pool
= NULL
;
7193 /* Remove all pool placeholder insns. */
7195 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
7197 /* Did we insert an extra barrier? Remove it. */
7198 rtx_insn
*barrier
= PREV_INSN (curr_pool
->pool_insn
);
7199 rtx_insn
*jump
= barrier
? PREV_INSN (barrier
) : NULL
;
7200 rtx_insn
*label
= NEXT_INSN (curr_pool
->pool_insn
);
7202 if (jump
&& JUMP_P (jump
)
7203 && barrier
&& BARRIER_P (barrier
)
7204 && label
&& LABEL_P (label
)
7205 && GET_CODE (PATTERN (jump
)) == SET
7206 && SET_DEST (PATTERN (jump
)) == pc_rtx
7207 && GET_CODE (SET_SRC (PATTERN (jump
))) == LABEL_REF
7208 && XEXP (SET_SRC (PATTERN (jump
)), 0) == label
)
7211 remove_insn (barrier
);
7212 remove_insn (label
);
7215 remove_insn (curr_pool
->pool_insn
);
7218 /* Remove all base register reload insns. */
7220 for (insn
= get_insns (); insn
; )
7222 rtx_insn
*next_insn
= NEXT_INSN (insn
);
7224 if (NONJUMP_INSN_P (insn
)
7225 && GET_CODE (PATTERN (insn
)) == SET
7226 && GET_CODE (SET_SRC (PATTERN (insn
))) == UNSPEC
7227 && XINT (SET_SRC (PATTERN (insn
)), 1) == UNSPEC_RELOAD_BASE
)
7233 /* Free pool list. */
7237 struct constant_pool
*next
= pool_list
->next
;
7238 s390_free_pool (pool_list
);
7243 /* Output the constant pool entry EXP in mode MODE with alignment ALIGN. */
7246 s390_output_pool_entry (rtx exp
, enum machine_mode mode
, unsigned int align
)
7250 switch (GET_MODE_CLASS (mode
))
7253 case MODE_DECIMAL_FLOAT
:
7254 gcc_assert (GET_CODE (exp
) == CONST_DOUBLE
);
7256 REAL_VALUE_FROM_CONST_DOUBLE (r
, exp
);
7257 assemble_real (r
, mode
, align
);
7261 assemble_integer (exp
, GET_MODE_SIZE (mode
), align
, 1);
7262 mark_symbol_refs_as_used (exp
);
7271 /* Return an RTL expression representing the value of the return address
7272 for the frame COUNT steps up from the current frame. FRAME is the
7273 frame pointer of that frame. */
7276 s390_return_addr_rtx (int count
, rtx frame ATTRIBUTE_UNUSED
)
7281 /* Without backchain, we fail for all but the current frame. */
7283 if (!TARGET_BACKCHAIN
&& count
> 0)
7286 /* For the current frame, we need to make sure the initial
7287 value of RETURN_REGNUM is actually saved. */
7291 /* On non-z architectures branch splitting could overwrite r14. */
7292 if (TARGET_CPU_ZARCH
)
7293 return get_hard_reg_initial_val (Pmode
, RETURN_REGNUM
);
7296 cfun_frame_layout
.save_return_addr_p
= true;
7297 return gen_rtx_MEM (Pmode
, return_address_pointer_rtx
);
7301 if (TARGET_PACKED_STACK
)
7302 offset
= -2 * UNITS_PER_LONG
;
7304 offset
= RETURN_REGNUM
* UNITS_PER_LONG
;
7306 addr
= plus_constant (Pmode
, frame
, offset
);
7307 addr
= memory_address (Pmode
, addr
);
7308 return gen_rtx_MEM (Pmode
, addr
);
7311 /* Return an RTL expression representing the back chain stored in
7312 the current stack frame. */
7315 s390_back_chain_rtx (void)
7319 gcc_assert (TARGET_BACKCHAIN
);
7321 if (TARGET_PACKED_STACK
)
7322 chain
= plus_constant (Pmode
, stack_pointer_rtx
,
7323 STACK_POINTER_OFFSET
- UNITS_PER_LONG
);
7325 chain
= stack_pointer_rtx
;
7327 chain
= gen_rtx_MEM (Pmode
, chain
);
7331 /* Find first call clobbered register unused in a function.
7332 This could be used as base register in a leaf function
7333 or for holding the return address before epilogue. */
7336 find_unused_clobbered_reg (void)
7339 for (i
= 0; i
< 6; i
++)
7340 if (!df_regs_ever_live_p (i
))
7346 /* Helper function for s390_regs_ever_clobbered. Sets the fields in DATA for all
7347 clobbered hard regs in SETREG. */
7350 s390_reg_clobbered_rtx (rtx setreg
, const_rtx set_insn ATTRIBUTE_UNUSED
, void *data
)
7352 char *regs_ever_clobbered
= (char *)data
;
7353 unsigned int i
, regno
;
7354 enum machine_mode mode
= GET_MODE (setreg
);
7356 if (GET_CODE (setreg
) == SUBREG
)
7358 rtx inner
= SUBREG_REG (setreg
);
7359 if (!GENERAL_REG_P (inner
) && !FP_REG_P (inner
))
7361 regno
= subreg_regno (setreg
);
7363 else if (GENERAL_REG_P (setreg
) || FP_REG_P (setreg
))
7364 regno
= REGNO (setreg
);
7369 i
< regno
+ HARD_REGNO_NREGS (regno
, mode
);
7371 regs_ever_clobbered
[i
] = 1;
7374 /* Walks through all basic blocks of the current function looking
7375 for clobbered hard regs using s390_reg_clobbered_rtx. The fields
7376 of the passed integer array REGS_EVER_CLOBBERED are set to one for
7377 each of those regs. */
7380 s390_regs_ever_clobbered (char regs_ever_clobbered
[])
7386 memset (regs_ever_clobbered
, 0, 32);
7388 /* For non-leaf functions we have to consider all call clobbered regs to be
7392 for (i
= 0; i
< 32; i
++)
7393 regs_ever_clobbered
[i
] = call_really_used_regs
[i
];
7396 /* Make the "magic" eh_return registers live if necessary. For regs_ever_live
7397 this work is done by liveness analysis (mark_regs_live_at_end).
7398 Special care is needed for functions containing landing pads. Landing pads
7399 may use the eh registers, but the code which sets these registers is not
7400 contained in that function. Hence s390_regs_ever_clobbered is not able to
7401 deal with this automatically. */
7402 if (crtl
->calls_eh_return
|| cfun
->machine
->has_landing_pad_p
)
7403 for (i
= 0; EH_RETURN_DATA_REGNO (i
) != INVALID_REGNUM
; i
++)
7404 if (crtl
->calls_eh_return
7405 || (cfun
->machine
->has_landing_pad_p
7406 && df_regs_ever_live_p (EH_RETURN_DATA_REGNO (i
))))
7407 regs_ever_clobbered
[EH_RETURN_DATA_REGNO (i
)] = 1;
7409 /* For nonlocal gotos all call-saved registers have to be saved.
7410 This flag is also set for the unwinding code in libgcc.
7411 See expand_builtin_unwind_init. For regs_ever_live this is done by
7413 if (crtl
->saves_all_registers
)
7414 for (i
= 0; i
< 32; i
++)
7415 if (!call_really_used_regs
[i
])
7416 regs_ever_clobbered
[i
] = 1;
7418 FOR_EACH_BB_FN (cur_bb
, cfun
)
7420 FOR_BB_INSNS (cur_bb
, cur_insn
)
7424 if (!INSN_P (cur_insn
))
7427 pat
= PATTERN (cur_insn
);
7429 /* Ignore GPR restore insns. */
7430 if (epilogue_completed
&& RTX_FRAME_RELATED_P (cur_insn
))
7432 if (GET_CODE (pat
) == SET
7433 && GENERAL_REG_P (SET_DEST (pat
)))
7436 if (GET_MODE (SET_SRC (pat
)) == DImode
7437 && FP_REG_P (SET_SRC (pat
)))
7441 if (GET_CODE (SET_SRC (pat
)) == MEM
)
7446 if (GET_CODE (pat
) == PARALLEL
7447 && load_multiple_operation (pat
, VOIDmode
))
7452 s390_reg_clobbered_rtx
,
7453 regs_ever_clobbered
);
7458 /* Determine the frame area which actually has to be accessed
7459 in the function epilogue. The values are stored at the
7460 given pointers AREA_BOTTOM (address of the lowest used stack
7461 address) and AREA_TOP (address of the first item which does
7462 not belong to the stack frame). */
7465 s390_frame_area (int *area_bottom
, int *area_top
)
7472 if (cfun_frame_layout
.first_restore_gpr
!= -1)
7474 b
= (cfun_frame_layout
.gprs_offset
7475 + cfun_frame_layout
.first_restore_gpr
* UNITS_PER_LONG
);
7476 t
= b
+ (cfun_frame_layout
.last_restore_gpr
7477 - cfun_frame_layout
.first_restore_gpr
+ 1) * UNITS_PER_LONG
;
7480 if (TARGET_64BIT
&& cfun_save_high_fprs_p
)
7482 b
= MIN (b
, cfun_frame_layout
.f8_offset
);
7483 t
= MAX (t
, (cfun_frame_layout
.f8_offset
7484 + cfun_frame_layout
.high_fprs
* 8));
7489 if (cfun_fpr_save_p (FPR4_REGNUM
))
7491 b
= MIN (b
, cfun_frame_layout
.f4_offset
);
7492 t
= MAX (t
, cfun_frame_layout
.f4_offset
+ 8);
7494 if (cfun_fpr_save_p (FPR6_REGNUM
))
7496 b
= MIN (b
, cfun_frame_layout
.f4_offset
+ 8);
7497 t
= MAX (t
, cfun_frame_layout
.f4_offset
+ 16);
7503 /* Update gpr_save_slots in the frame layout trying to make use of
7504 FPRs as GPR save slots.
7505 This is a helper routine of s390_register_info. */
7508 s390_register_info_gprtofpr ()
7510 int save_reg_slot
= FPR0_REGNUM
;
7513 if (!TARGET_Z10
|| !TARGET_HARD_FLOAT
|| !crtl
->is_leaf
)
7516 for (i
= 15; i
>= 6; i
--)
7518 if (cfun_gpr_save_slot (i
) == 0)
7521 /* Advance to the next FP register which can be used as a
7523 while ((!call_really_used_regs
[save_reg_slot
]
7524 || df_regs_ever_live_p (save_reg_slot
)
7525 || cfun_fpr_save_p (save_reg_slot
))
7526 && FP_REGNO_P (save_reg_slot
))
7528 if (!FP_REGNO_P (save_reg_slot
))
7530 /* We only want to use ldgr/lgdr if we can get rid of
7531 stm/lm entirely. So undo the gpr slot allocation in
7532 case we ran out of FPR save slots. */
7533 for (j
= 6; j
<= 15; j
++)
7534 if (FP_REGNO_P (cfun_gpr_save_slot (j
)))
7535 cfun_gpr_save_slot (j
) = -1;
7538 cfun_gpr_save_slot (i
) = save_reg_slot
++;
7542 /* Set the bits in fpr_bitmap for FPRs which need to be saved due to
7544 This is a helper routine for s390_register_info. */
7547 s390_register_info_stdarg_fpr ()
7553 /* Save the FP argument regs for stdarg. f0, f2 for 31 bit and
7554 f0-f4 for 64 bit. */
7556 || !TARGET_HARD_FLOAT
7557 || !cfun
->va_list_fpr_size
7558 || crtl
->args
.info
.fprs
>= FP_ARG_NUM_REG
)
7561 min_fpr
= crtl
->args
.info
.fprs
;
7562 max_fpr
= min_fpr
+ cfun
->va_list_fpr_size
;
7563 if (max_fpr
> FP_ARG_NUM_REG
)
7564 max_fpr
= FP_ARG_NUM_REG
;
7566 for (i
= min_fpr
; i
< max_fpr
; i
++)
7567 cfun_set_fpr_save (i
+ FPR0_REGNUM
);
7570 /* Reserve the GPR save slots for GPRs which need to be saved due to
7572 This is a helper routine for s390_register_info. */
7575 s390_register_info_stdarg_gpr ()
7582 || !cfun
->va_list_gpr_size
7583 || crtl
->args
.info
.gprs
>= GP_ARG_NUM_REG
)
7586 min_gpr
= crtl
->args
.info
.gprs
;
7587 max_gpr
= min_gpr
+ cfun
->va_list_gpr_size
;
7588 if (max_gpr
> GP_ARG_NUM_REG
)
7589 max_gpr
= GP_ARG_NUM_REG
;
7591 for (i
= min_gpr
; i
< max_gpr
; i
++)
7592 cfun_gpr_save_slot (2 + i
) = -1;
7595 /* The GPR and FPR save slots in cfun->machine->frame_layout are set
7596 for registers which need to be saved in function prologue.
7597 This function can be used until the insns emitted for save/restore
7598 of the regs are visible in the RTL stream. */
7601 s390_register_info ()
7604 char clobbered_regs
[32];
7606 gcc_assert (!epilogue_completed
);
7608 if (reload_completed
)
7609 /* After reload we rely on our own routine to determine which
7610 registers need saving. */
7611 s390_regs_ever_clobbered (clobbered_regs
);
7613 /* During reload we use regs_ever_live as a base since reload
7614 does changes in there which we otherwise would not be aware
7616 for (i
= 0; i
< 32; i
++)
7617 clobbered_regs
[i
] = df_regs_ever_live_p (i
);
7619 for (i
= 0; i
< 32; i
++)
7620 clobbered_regs
[i
] = clobbered_regs
[i
] && !global_regs
[i
];
7622 /* Mark the call-saved FPRs which need to be saved.
7623 This needs to be done before checking the special GPRs since the
7624 stack pointer usage depends on whether high FPRs have to be saved
7626 cfun_frame_layout
.fpr_bitmap
= 0;
7627 cfun_frame_layout
.high_fprs
= 0;
7628 for (i
= FPR0_REGNUM
; i
<= FPR15_REGNUM
; i
++)
7629 if (clobbered_regs
[i
] && !call_really_used_regs
[i
])
7631 cfun_set_fpr_save (i
);
7632 if (i
>= FPR8_REGNUM
)
7633 cfun_frame_layout
.high_fprs
++;
7637 clobbered_regs
[PIC_OFFSET_TABLE_REGNUM
]
7638 |= !!df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM
);
7640 clobbered_regs
[BASE_REGNUM
]
7641 |= (cfun
->machine
->base_reg
7642 && REGNO (cfun
->machine
->base_reg
) == BASE_REGNUM
);
7644 clobbered_regs
[HARD_FRAME_POINTER_REGNUM
]
7645 |= !!frame_pointer_needed
;
7647 /* On pre z900 machines this might take until machine dependent
7649 save_return_addr_p will only be set on non-zarch machines so
7650 there is no risk that r14 goes into an FPR instead of a stack
7652 clobbered_regs
[RETURN_REGNUM
]
7654 || TARGET_TPF_PROFILING
7655 || cfun
->machine
->split_branches_pending_p
7656 || cfun_frame_layout
.save_return_addr_p
7657 || crtl
->calls_eh_return
);
7659 clobbered_regs
[STACK_POINTER_REGNUM
]
7661 || TARGET_TPF_PROFILING
7662 || cfun_save_high_fprs_p
7663 || get_frame_size () > 0
7664 || (reload_completed
&& cfun_frame_layout
.frame_size
> 0)
7665 || cfun
->calls_alloca
);
7667 memset (cfun_frame_layout
.gpr_save_slots
, 0, 16);
7669 for (i
= 6; i
< 16; i
++)
7670 if (clobbered_regs
[i
])
7671 cfun_gpr_save_slot (i
) = -1;
7673 s390_register_info_stdarg_fpr ();
7674 s390_register_info_gprtofpr ();
7676 /* First find the range of GPRs to be restored. Vararg regs don't
7677 need to be restored so we do it before assigning slots to the
7679 for (i
= 0; i
< 16 && cfun_gpr_save_slot (i
) != -1; i
++);
7680 for (j
= 15; j
> i
&& cfun_gpr_save_slot (j
) != -1; j
--);
7681 cfun_frame_layout
.first_restore_gpr
= (i
== 16) ? -1 : i
;
7682 cfun_frame_layout
.last_restore_gpr
= (i
== 16) ? -1 : j
;
7684 /* stdarg functions might need to save GPRs 2 to 6. This might
7685 override the GPR->FPR save decision made above for r6 since
7686 vararg regs must go to the stack. */
7687 s390_register_info_stdarg_gpr ();
7689 /* Now the range of GPRs which need saving. */
7690 for (i
= 0; i
< 16 && cfun_gpr_save_slot (i
) != -1; i
++);
7691 for (j
= 15; j
> i
&& cfun_gpr_save_slot (j
) != -1; j
--);
7692 cfun_frame_layout
.first_save_gpr
= (i
== 16) ? -1 : i
;
7693 cfun_frame_layout
.last_save_gpr
= (i
== 16) ? -1 : j
;
7696 /* This function is called by s390_optimize_prologue in order to get
7697 rid of unnecessary GPR save/restore instructions. The register info
7698 for the GPRs is re-computed and the ranges are re-calculated. */
7701 s390_optimize_register_info ()
7703 char clobbered_regs
[32];
7706 gcc_assert (epilogue_completed
);
7707 gcc_assert (!cfun
->machine
->split_branches_pending_p
);
7709 s390_regs_ever_clobbered (clobbered_regs
);
7711 for (i
= 0; i
< 32; i
++)
7712 clobbered_regs
[i
] = clobbered_regs
[i
] && !global_regs
[i
];
7714 /* There is still special treatment needed for cases invisible to
7715 s390_regs_ever_clobbered. */
7716 clobbered_regs
[RETURN_REGNUM
]
7717 |= (TARGET_TPF_PROFILING
7718 /* When expanding builtin_return_addr in ESA mode we do not
7719 know whether r14 will later be needed as scratch reg when
7720 doing branch splitting. So the builtin always accesses the
7721 r14 save slot and we need to stick to the save/restore
7722 decision for r14 even if it turns out that it didn't get
7724 || cfun_frame_layout
.save_return_addr_p
7725 || crtl
->calls_eh_return
);
7727 memset (cfun_frame_layout
.gpr_save_slots
, 0, 6);
7729 for (i
= 6; i
< 16; i
++)
7730 if (!clobbered_regs
[i
])
7731 cfun_gpr_save_slot (i
) = 0;
7733 for (i
= 0; i
< 16 && cfun_gpr_save_slot (i
) != -1; i
++);
7734 for (j
= 15; j
> i
&& cfun_gpr_save_slot (j
) != -1; j
--);
7735 cfun_frame_layout
.first_restore_gpr
= (i
== 16) ? -1 : i
;
7736 cfun_frame_layout
.last_restore_gpr
= (i
== 16) ? -1 : j
;
7738 s390_register_info_stdarg_gpr ();
7740 for (i
= 0; i
< 16 && cfun_gpr_save_slot (i
) != -1; i
++);
7741 for (j
= 15; j
> i
&& cfun_gpr_save_slot (j
) != -1; j
--);
7742 cfun_frame_layout
.first_save_gpr
= (i
== 16) ? -1 : i
;
7743 cfun_frame_layout
.last_save_gpr
= (i
== 16) ? -1 : j
;
7746 /* Fill cfun->machine with info about frame of current function. */
7749 s390_frame_info (void)
7751 HOST_WIDE_INT lowest_offset
;
7753 cfun_frame_layout
.first_save_gpr_slot
= cfun_frame_layout
.first_save_gpr
;
7754 cfun_frame_layout
.last_save_gpr_slot
= cfun_frame_layout
.last_save_gpr
;
7756 /* The va_arg builtin uses a constant distance of 16 *
7757 UNITS_PER_LONG (r0-r15) to reach the FPRs from the reg_save_area
7758 pointer. So even if we are going to save the stack pointer in an
7759 FPR we need the stack space in order to keep the offsets
7761 if (cfun
->stdarg
&& cfun_save_arg_fprs_p
)
7763 cfun_frame_layout
.last_save_gpr_slot
= STACK_POINTER_REGNUM
;
7765 if (cfun_frame_layout
.first_save_gpr_slot
== -1)
7766 cfun_frame_layout
.first_save_gpr_slot
= STACK_POINTER_REGNUM
;
7769 cfun_frame_layout
.frame_size
= get_frame_size ();
7770 if (!TARGET_64BIT
&& cfun_frame_layout
.frame_size
> 0x7fff0000)
7771 fatal_error ("total size of local variables exceeds architecture limit");
7773 if (!TARGET_PACKED_STACK
)
7775 /* Fixed stack layout. */
7776 cfun_frame_layout
.backchain_offset
= 0;
7777 cfun_frame_layout
.f0_offset
= 16 * UNITS_PER_LONG
;
7778 cfun_frame_layout
.f4_offset
= cfun_frame_layout
.f0_offset
+ 2 * 8;
7779 cfun_frame_layout
.f8_offset
= -cfun_frame_layout
.high_fprs
* 8;
7780 cfun_frame_layout
.gprs_offset
= (cfun_frame_layout
.first_save_gpr_slot
7783 else if (TARGET_BACKCHAIN
)
7785 /* Kernel stack layout - packed stack, backchain, no float */
7786 gcc_assert (TARGET_SOFT_FLOAT
);
7787 cfun_frame_layout
.backchain_offset
= (STACK_POINTER_OFFSET
7790 /* The distance between the backchain and the return address
7791 save slot must not change. So we always need a slot for the
7792 stack pointer which resides in between. */
7793 cfun_frame_layout
.last_save_gpr_slot
= STACK_POINTER_REGNUM
;
7795 cfun_frame_layout
.gprs_offset
7796 = cfun_frame_layout
.backchain_offset
- cfun_gprs_save_area_size
;
7798 /* FPRs will not be saved. Nevertheless pick sane values to
7799 keep area calculations valid. */
7800 cfun_frame_layout
.f0_offset
=
7801 cfun_frame_layout
.f4_offset
=
7802 cfun_frame_layout
.f8_offset
= cfun_frame_layout
.gprs_offset
;
7808 /* Packed stack layout without backchain. */
7810 /* With stdarg FPRs need their dedicated slots. */
7811 num_fprs
= (TARGET_64BIT
&& cfun
->stdarg
? 2
7812 : (cfun_fpr_save_p (FPR4_REGNUM
) +
7813 cfun_fpr_save_p (FPR6_REGNUM
)));
7814 cfun_frame_layout
.f4_offset
= STACK_POINTER_OFFSET
- 8 * num_fprs
;
7816 num_fprs
= (cfun
->stdarg
? 2
7817 : (cfun_fpr_save_p (FPR0_REGNUM
)
7818 + cfun_fpr_save_p (FPR2_REGNUM
)));
7819 cfun_frame_layout
.f0_offset
= cfun_frame_layout
.f4_offset
- 8 * num_fprs
;
7821 cfun_frame_layout
.gprs_offset
7822 = cfun_frame_layout
.f0_offset
- cfun_gprs_save_area_size
;
7824 cfun_frame_layout
.f8_offset
= (cfun_frame_layout
.gprs_offset
7825 - cfun_frame_layout
.high_fprs
* 8);
7828 if (cfun_save_high_fprs_p
)
7829 cfun_frame_layout
.frame_size
+= cfun_frame_layout
.high_fprs
* 8;
7832 cfun_frame_layout
.frame_size
+= crtl
->outgoing_args_size
;
7834 /* In the following cases we have to allocate a STACK_POINTER_OFFSET
7835 sized area at the bottom of the stack. This is required also for
7836 leaf functions. When GCC generates a local stack reference it
7837 will always add STACK_POINTER_OFFSET to all these references. */
7839 && !TARGET_TPF_PROFILING
7840 && cfun_frame_layout
.frame_size
== 0
7841 && !cfun
->calls_alloca
)
7844 /* Calculate the number of bytes we have used in our own register
7845 save area. With the packed stack layout we can re-use the
7846 remaining bytes for normal stack elements. */
7848 if (TARGET_PACKED_STACK
)
7849 lowest_offset
= MIN (MIN (cfun_frame_layout
.f0_offset
,
7850 cfun_frame_layout
.f4_offset
),
7851 cfun_frame_layout
.gprs_offset
);
7855 if (TARGET_BACKCHAIN
)
7856 lowest_offset
= MIN (lowest_offset
, cfun_frame_layout
.backchain_offset
);
7858 cfun_frame_layout
.frame_size
+= STACK_POINTER_OFFSET
- lowest_offset
;
7860 /* If under 31 bit an odd number of gprs has to be saved we have to
7861 adjust the frame size to sustain 8 byte alignment of stack
7863 cfun_frame_layout
.frame_size
= ((cfun_frame_layout
.frame_size
+
7864 STACK_BOUNDARY
/ BITS_PER_UNIT
- 1)
7865 & ~(STACK_BOUNDARY
/ BITS_PER_UNIT
- 1));
7868 /* Generate frame layout. Fills in register and frame data for the current
7869 function in cfun->machine. This routine can be called multiple times;
7870 it will re-do the complete frame layout every time. */
7873 s390_init_frame_layout (void)
7875 HOST_WIDE_INT frame_size
;
7878 gcc_assert (!reload_completed
);
7880 /* On S/390 machines, we may need to perform branch splitting, which
7881 will require both base and return address register. We have no
7882 choice but to assume we're going to need them until right at the
7883 end of the machine dependent reorg phase. */
7884 if (!TARGET_CPU_ZARCH
)
7885 cfun
->machine
->split_branches_pending_p
= true;
7889 frame_size
= cfun_frame_layout
.frame_size
;
7891 /* Try to predict whether we'll need the base register. */
7892 base_used
= cfun
->machine
->split_branches_pending_p
7893 || crtl
->uses_const_pool
7894 || (!DISP_IN_RANGE (frame_size
)
7895 && !CONST_OK_FOR_K (frame_size
));
7897 /* Decide which register to use as literal pool base. In small
7898 leaf functions, try to use an unused call-clobbered register
7899 as base register to avoid save/restore overhead. */
7901 cfun
->machine
->base_reg
= NULL_RTX
;
7902 else if (crtl
->is_leaf
&& !df_regs_ever_live_p (5))
7903 cfun
->machine
->base_reg
= gen_rtx_REG (Pmode
, 5);
7905 cfun
->machine
->base_reg
= gen_rtx_REG (Pmode
, BASE_REGNUM
);
7907 s390_register_info ();
7910 while (frame_size
!= cfun_frame_layout
.frame_size
);
7913 /* Remove the FPR clobbers from a tbegin insn if it can be proven that
7914 the TX is nonescaping. A transaction is considered escaping if
7915 there is at least one path from tbegin returning CC0 to the
7916 function exit block without an tend.
7918 The check so far has some limitations:
7919 - only single tbegin/tend BBs are supported
7920 - the first cond jump after tbegin must separate the CC0 path from ~CC0
7921 - when CC is copied to a GPR and the CC0 check is done with the GPR
7922 this is not supported
7926 s390_optimize_nonescaping_tx (void)
7928 const unsigned int CC0
= 1 << 3;
7929 basic_block tbegin_bb
= NULL
;
7930 basic_block tend_bb
= NULL
;
7935 rtx_insn
*tbegin_insn
= NULL
;
7937 if (!cfun
->machine
->tbegin_p
)
7940 for (bb_index
= 0; bb_index
< n_basic_blocks_for_fn (cfun
); bb_index
++)
7942 bb
= BASIC_BLOCK_FOR_FN (cfun
, bb_index
);
7947 FOR_BB_INSNS (bb
, insn
)
7949 rtx ite
, cc
, pat
, target
;
7950 unsigned HOST_WIDE_INT mask
;
7952 if (!INSN_P (insn
) || INSN_CODE (insn
) <= 0)
7955 pat
= PATTERN (insn
);
7957 if (GET_CODE (pat
) == PARALLEL
)
7958 pat
= XVECEXP (pat
, 0, 0);
7960 if (GET_CODE (pat
) != SET
7961 || GET_CODE (SET_SRC (pat
)) != UNSPEC_VOLATILE
)
7964 if (XINT (SET_SRC (pat
), 1) == UNSPECV_TBEGIN
)
7970 /* Just return if the tbegin doesn't have clobbers. */
7971 if (GET_CODE (PATTERN (insn
)) != PARALLEL
)
7974 if (tbegin_bb
!= NULL
)
7977 /* Find the next conditional jump. */
7978 for (tmp
= NEXT_INSN (insn
);
7980 tmp
= NEXT_INSN (tmp
))
7982 if (reg_set_p (gen_rtx_REG (CCmode
, CC_REGNUM
), tmp
))
7987 ite
= SET_SRC (PATTERN (tmp
));
7988 if (GET_CODE (ite
) != IF_THEN_ELSE
)
7991 cc
= XEXP (XEXP (ite
, 0), 0);
7992 if (!REG_P (cc
) || !CC_REGNO_P (REGNO (cc
))
7993 || GET_MODE (cc
) != CCRAWmode
7994 || GET_CODE (XEXP (XEXP (ite
, 0), 1)) != CONST_INT
)
7997 if (bb
->succs
->length () != 2)
8000 mask
= INTVAL (XEXP (XEXP (ite
, 0), 1));
8001 if (GET_CODE (XEXP (ite
, 0)) == NE
)
8005 target
= XEXP (ite
, 1);
8006 else if (mask
== (CC0
^ 0xf))
8007 target
= XEXP (ite
, 2);
8015 ei
= ei_start (bb
->succs
);
8016 e1
= ei_safe_edge (ei
);
8018 e2
= ei_safe_edge (ei
);
8020 if (e2
->flags
& EDGE_FALLTHRU
)
8023 e1
= ei_safe_edge (ei
);
8026 if (!(e1
->flags
& EDGE_FALLTHRU
))
8029 tbegin_bb
= (target
== pc_rtx
) ? e1
->dest
: e2
->dest
;
8031 if (tmp
== BB_END (bb
))
8036 if (XINT (SET_SRC (pat
), 1) == UNSPECV_TEND
)
8038 if (tend_bb
!= NULL
)
8045 /* Either we successfully remove the FPR clobbers here or we are not
8046 able to do anything for this TX. Both cases don't qualify for
8048 cfun
->machine
->tbegin_p
= false;
8050 if (tbegin_bb
== NULL
|| tend_bb
== NULL
)
8053 calculate_dominance_info (CDI_POST_DOMINATORS
);
8054 result
= dominated_by_p (CDI_POST_DOMINATORS
, tbegin_bb
, tend_bb
);
8055 free_dominance_info (CDI_POST_DOMINATORS
);
8060 PATTERN (tbegin_insn
) = gen_rtx_PARALLEL (VOIDmode
,
8062 XVECEXP (PATTERN (tbegin_insn
), 0, 0),
8063 XVECEXP (PATTERN (tbegin_insn
), 0, 1)));
8064 INSN_CODE (tbegin_insn
) = -1;
8065 df_insn_rescan (tbegin_insn
);
8070 /* Return true if it is legal to put a value with MODE into REGNO. */
8073 s390_hard_regno_mode_ok (unsigned int regno
, enum machine_mode mode
)
8075 switch (REGNO_REG_CLASS (regno
))
8078 if (REGNO_PAIR_OK (regno
, mode
))
8080 if (mode
== SImode
|| mode
== DImode
)
8083 if (FLOAT_MODE_P (mode
) && GET_MODE_CLASS (mode
) != MODE_VECTOR_FLOAT
)
8088 if (FRAME_REGNO_P (regno
) && mode
== Pmode
)
8093 if (REGNO_PAIR_OK (regno
, mode
))
8096 || (mode
!= TFmode
&& mode
!= TCmode
&& mode
!= TDmode
))
8101 if (GET_MODE_CLASS (mode
) == MODE_CC
)
8105 if (REGNO_PAIR_OK (regno
, mode
))
8107 if (mode
== SImode
|| mode
== Pmode
)
8118 /* Return nonzero if register OLD_REG can be renamed to register NEW_REG. */
8121 s390_hard_regno_rename_ok (unsigned int old_reg
, unsigned int new_reg
)
8123 /* Once we've decided upon a register to use as base register, it must
8124 no longer be used for any other purpose. */
8125 if (cfun
->machine
->base_reg
)
8126 if (REGNO (cfun
->machine
->base_reg
) == old_reg
8127 || REGNO (cfun
->machine
->base_reg
) == new_reg
)
8130 /* Prevent regrename from using call-saved regs which haven't
8131 actually been saved. This is necessary since regrename assumes
8132 the backend save/restore decisions are based on
8133 df_regs_ever_live. Since we have our own routine we have to tell
8134 regrename manually about it. */
8135 if (GENERAL_REGNO_P (new_reg
)
8136 && !call_really_used_regs
[new_reg
]
8137 && cfun_gpr_save_slot (new_reg
) == 0)
8143 /* Return nonzero if register REGNO can be used as a scratch register
8147 s390_hard_regno_scratch_ok (unsigned int regno
)
8149 /* See s390_hard_regno_rename_ok. */
8150 if (GENERAL_REGNO_P (regno
)
8151 && !call_really_used_regs
[regno
]
8152 && cfun_gpr_save_slot (regno
) == 0)
8158 /* Maximum number of registers to represent a value of mode MODE
8159 in a register of class RCLASS. */
8162 s390_class_max_nregs (enum reg_class rclass
, enum machine_mode mode
)
8167 if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
)
8168 return 2 * ((GET_MODE_SIZE (mode
) / 2 + 8 - 1) / 8);
8170 return (GET_MODE_SIZE (mode
) + 8 - 1) / 8;
8172 return (GET_MODE_SIZE (mode
) + 4 - 1) / 4;
8176 return (GET_MODE_SIZE (mode
) + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
8179 /* Return true if we use LRA instead of reload pass. */
8183 return s390_lra_flag
;
8186 /* Return true if register FROM can be eliminated via register TO. */
8189 s390_can_eliminate (const int from
, const int to
)
8191 /* On zSeries machines, we have not marked the base register as fixed.
8192 Instead, we have an elimination rule BASE_REGNUM -> BASE_REGNUM.
8193 If a function requires the base register, we say here that this
8194 elimination cannot be performed. This will cause reload to free
8195 up the base register (as if it were fixed). On the other hand,
8196 if the current function does *not* require the base register, we
8197 say here the elimination succeeds, which in turn allows reload
8198 to allocate the base register for any other purpose. */
8199 if (from
== BASE_REGNUM
&& to
== BASE_REGNUM
)
8201 if (TARGET_CPU_ZARCH
)
8203 s390_init_frame_layout ();
8204 return cfun
->machine
->base_reg
== NULL_RTX
;
8210 /* Everything else must point into the stack frame. */
8211 gcc_assert (to
== STACK_POINTER_REGNUM
8212 || to
== HARD_FRAME_POINTER_REGNUM
);
8214 gcc_assert (from
== FRAME_POINTER_REGNUM
8215 || from
== ARG_POINTER_REGNUM
8216 || from
== RETURN_ADDRESS_POINTER_REGNUM
);
8218 /* Make sure we actually saved the return address. */
8219 if (from
== RETURN_ADDRESS_POINTER_REGNUM
)
8220 if (!crtl
->calls_eh_return
8222 && !cfun_frame_layout
.save_return_addr_p
)
8228 /* Return offset between register FROM and TO initially after prolog. */
8231 s390_initial_elimination_offset (int from
, int to
)
8233 HOST_WIDE_INT offset
;
8235 /* ??? Why are we called for non-eliminable pairs? */
8236 if (!s390_can_eliminate (from
, to
))
8241 case FRAME_POINTER_REGNUM
:
8242 offset
= (get_frame_size()
8243 + STACK_POINTER_OFFSET
8244 + crtl
->outgoing_args_size
);
8247 case ARG_POINTER_REGNUM
:
8248 s390_init_frame_layout ();
8249 offset
= cfun_frame_layout
.frame_size
+ STACK_POINTER_OFFSET
;
8252 case RETURN_ADDRESS_POINTER_REGNUM
:
8253 s390_init_frame_layout ();
8255 if (cfun_frame_layout
.first_save_gpr_slot
== -1)
8257 /* If it turns out that for stdarg nothing went into the reg
8258 save area we also do not need the return address
8260 if (cfun
->stdarg
&& !cfun_save_arg_fprs_p
)
8266 /* In order to make the following work it is not necessary for
8267 r14 to have a save slot. It is sufficient if one other GPR
8268 got one. Since the GPRs are always stored without gaps we
8269 are able to calculate where the r14 save slot would
8271 offset
= (cfun_frame_layout
.frame_size
+ cfun_frame_layout
.gprs_offset
+
8272 (RETURN_REGNUM
- cfun_frame_layout
.first_save_gpr_slot
) *
8287 /* Emit insn to save fpr REGNUM at offset OFFSET relative
8288 to register BASE. Return generated insn. */
8291 save_fpr (rtx base
, int offset
, int regnum
)
8294 addr
= gen_rtx_MEM (DFmode
, plus_constant (Pmode
, base
, offset
));
8296 if (regnum
>= 16 && regnum
<= (16 + FP_ARG_NUM_REG
))
8297 set_mem_alias_set (addr
, get_varargs_alias_set ());
8299 set_mem_alias_set (addr
, get_frame_alias_set ());
8301 return emit_move_insn (addr
, gen_rtx_REG (DFmode
, regnum
));
8304 /* Emit insn to restore fpr REGNUM from offset OFFSET relative
8305 to register BASE. Return generated insn. */
8308 restore_fpr (rtx base
, int offset
, int regnum
)
8311 addr
= gen_rtx_MEM (DFmode
, plus_constant (Pmode
, base
, offset
));
8312 set_mem_alias_set (addr
, get_frame_alias_set ());
8314 return emit_move_insn (gen_rtx_REG (DFmode
, regnum
), addr
);
8317 /* Return true if REGNO is a global register, but not one
8318 of the special ones that need to be saved/restored in anyway. */
8321 global_not_special_regno_p (int regno
)
8323 return (global_regs
[regno
]
8324 /* These registers are special and need to be
8325 restored in any case. */
8326 && !(regno
== STACK_POINTER_REGNUM
8327 || regno
== RETURN_REGNUM
8328 || regno
== BASE_REGNUM
8329 || (flag_pic
&& regno
== (int)PIC_OFFSET_TABLE_REGNUM
)));
8332 /* Generate insn to save registers FIRST to LAST into
8333 the register save area located at offset OFFSET
8334 relative to register BASE. */
8337 save_gprs (rtx base
, int offset
, int first
, int last
)
8339 rtx addr
, insn
, note
;
8342 addr
= plus_constant (Pmode
, base
, offset
);
8343 addr
= gen_rtx_MEM (Pmode
, addr
);
8345 set_mem_alias_set (addr
, get_frame_alias_set ());
8347 /* Special-case single register. */
8351 insn
= gen_movdi (addr
, gen_rtx_REG (Pmode
, first
));
8353 insn
= gen_movsi (addr
, gen_rtx_REG (Pmode
, first
));
8355 if (!global_not_special_regno_p (first
))
8356 RTX_FRAME_RELATED_P (insn
) = 1;
8361 insn
= gen_store_multiple (addr
,
8362 gen_rtx_REG (Pmode
, first
),
8363 GEN_INT (last
- first
+ 1));
8365 if (first
<= 6 && cfun
->stdarg
)
8366 for (i
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
8368 rtx mem
= XEXP (XVECEXP (PATTERN (insn
), 0, i
), 0);
8371 set_mem_alias_set (mem
, get_varargs_alias_set ());
8374 /* We need to set the FRAME_RELATED flag on all SETs
8375 inside the store-multiple pattern.
8377 However, we must not emit DWARF records for registers 2..5
8378 if they are stored for use by variable arguments ...
8380 ??? Unfortunately, it is not enough to simply not the
8381 FRAME_RELATED flags for those SETs, because the first SET
8382 of the PARALLEL is always treated as if it had the flag
8383 set, even if it does not. Therefore we emit a new pattern
8384 without those registers as REG_FRAME_RELATED_EXPR note. */
8386 if (first
>= 6 && !global_not_special_regno_p (first
))
8388 rtx pat
= PATTERN (insn
);
8390 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
8391 if (GET_CODE (XVECEXP (pat
, 0, i
)) == SET
8392 && !global_not_special_regno_p (REGNO (SET_SRC (XVECEXP (pat
,
8394 RTX_FRAME_RELATED_P (XVECEXP (pat
, 0, i
)) = 1;
8396 RTX_FRAME_RELATED_P (insn
) = 1;
8402 for (start
= first
>= 6 ? first
: 6; start
<= last
; start
++)
8403 if (!global_not_special_regno_p (start
))
8409 addr
= plus_constant (Pmode
, base
,
8410 offset
+ (start
- first
) * UNITS_PER_LONG
);
8415 note
= gen_movdi (gen_rtx_MEM (Pmode
, addr
),
8416 gen_rtx_REG (Pmode
, start
));
8418 note
= gen_movsi (gen_rtx_MEM (Pmode
, addr
),
8419 gen_rtx_REG (Pmode
, start
));
8420 note
= PATTERN (note
);
8422 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
, note
);
8423 RTX_FRAME_RELATED_P (insn
) = 1;
8428 note
= gen_store_multiple (gen_rtx_MEM (Pmode
, addr
),
8429 gen_rtx_REG (Pmode
, start
),
8430 GEN_INT (last
- start
+ 1));
8431 note
= PATTERN (note
);
8433 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
, note
);
8435 for (i
= 0; i
< XVECLEN (note
, 0); i
++)
8436 if (GET_CODE (XVECEXP (note
, 0, i
)) == SET
8437 && !global_not_special_regno_p (REGNO (SET_SRC (XVECEXP (note
,
8439 RTX_FRAME_RELATED_P (XVECEXP (note
, 0, i
)) = 1;
8441 RTX_FRAME_RELATED_P (insn
) = 1;
8447 /* Generate insn to restore registers FIRST to LAST from
8448 the register save area located at offset OFFSET
8449 relative to register BASE. */
8452 restore_gprs (rtx base
, int offset
, int first
, int last
)
8456 addr
= plus_constant (Pmode
, base
, offset
);
8457 addr
= gen_rtx_MEM (Pmode
, addr
);
8458 set_mem_alias_set (addr
, get_frame_alias_set ());
8460 /* Special-case single register. */
8464 insn
= gen_movdi (gen_rtx_REG (Pmode
, first
), addr
);
8466 insn
= gen_movsi (gen_rtx_REG (Pmode
, first
), addr
);
8468 RTX_FRAME_RELATED_P (insn
) = 1;
8472 insn
= gen_load_multiple (gen_rtx_REG (Pmode
, first
),
8474 GEN_INT (last
- first
+ 1));
8475 RTX_FRAME_RELATED_P (insn
) = 1;
8479 /* Return insn sequence to load the GOT register. */
8481 static GTY(()) rtx got_symbol
;
8483 s390_load_got (void)
8487 /* We cannot use pic_offset_table_rtx here since we use this
8488 function also for non-pic if __tls_get_offset is called and in
8489 that case PIC_OFFSET_TABLE_REGNUM as well as pic_offset_table_rtx
8491 rtx got_rtx
= gen_rtx_REG (Pmode
, 12);
8495 got_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "_GLOBAL_OFFSET_TABLE_");
8496 SYMBOL_REF_FLAGS (got_symbol
) = SYMBOL_FLAG_LOCAL
;
8501 if (TARGET_CPU_ZARCH
)
8503 emit_move_insn (got_rtx
, got_symbol
);
8509 offset
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, got_symbol
),
8510 UNSPEC_LTREL_OFFSET
);
8511 offset
= gen_rtx_CONST (Pmode
, offset
);
8512 offset
= force_const_mem (Pmode
, offset
);
8514 emit_move_insn (got_rtx
, offset
);
8516 offset
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, XEXP (offset
, 0)),
8518 offset
= gen_rtx_PLUS (Pmode
, got_rtx
, offset
);
8520 emit_move_insn (got_rtx
, offset
);
8523 insns
= get_insns ();
8528 /* This ties together stack memory (MEM with an alias set of frame_alias_set)
8529 and the change to the stack pointer. */
8532 s390_emit_stack_tie (void)
8534 rtx mem
= gen_frame_mem (BLKmode
,
8535 gen_rtx_REG (Pmode
, STACK_POINTER_REGNUM
));
8537 emit_insn (gen_stack_tie (mem
));
8540 /* Copy GPRS into FPR save slots. */
8543 s390_save_gprs_to_fprs (void)
8547 if (!TARGET_Z10
|| !TARGET_HARD_FLOAT
|| !crtl
->is_leaf
)
8550 for (i
= 6; i
< 16; i
++)
8552 if (FP_REGNO_P (cfun_gpr_save_slot (i
)))
8555 emit_move_insn (gen_rtx_REG (DImode
, cfun_gpr_save_slot (i
)),
8556 gen_rtx_REG (DImode
, i
));
8557 RTX_FRAME_RELATED_P (insn
) = 1;
8562 /* Restore GPRs from FPR save slots. */
8565 s390_restore_gprs_from_fprs (void)
8569 if (!TARGET_Z10
|| !TARGET_HARD_FLOAT
|| !crtl
->is_leaf
)
8572 for (i
= 6; i
< 16; i
++)
8574 if (FP_REGNO_P (cfun_gpr_save_slot (i
)))
8577 emit_move_insn (gen_rtx_REG (DImode
, i
),
8578 gen_rtx_REG (DImode
, cfun_gpr_save_slot (i
)));
8579 df_set_regs_ever_live (i
, true);
8580 add_reg_note (insn
, REG_CFA_RESTORE
, gen_rtx_REG (DImode
, i
));
8581 if (i
== STACK_POINTER_REGNUM
)
8582 add_reg_note (insn
, REG_CFA_DEF_CFA
,
8583 plus_constant (Pmode
, stack_pointer_rtx
,
8584 STACK_POINTER_OFFSET
));
8585 RTX_FRAME_RELATED_P (insn
) = 1;
8591 /* A pass run immediately before shrink-wrapping and prologue and epilogue
8596 const pass_data pass_data_s390_early_mach
=
8598 RTL_PASS
, /* type */
8599 "early_mach", /* name */
8600 OPTGROUP_NONE
, /* optinfo_flags */
8601 TV_MACH_DEP
, /* tv_id */
8602 0, /* properties_required */
8603 0, /* properties_provided */
8604 0, /* properties_destroyed */
8605 0, /* todo_flags_start */
8606 ( TODO_df_verify
| TODO_df_finish
), /* todo_flags_finish */
8609 class pass_s390_early_mach
: public rtl_opt_pass
8612 pass_s390_early_mach (gcc::context
*ctxt
)
8613 : rtl_opt_pass (pass_data_s390_early_mach
, ctxt
)
8616 /* opt_pass methods: */
8617 virtual unsigned int execute (function
*);
8619 }; // class pass_s390_early_mach
8622 pass_s390_early_mach::execute (function
*fun
)
8626 /* Try to get rid of the FPR clobbers. */
8627 s390_optimize_nonescaping_tx ();
8629 /* Re-compute register info. */
8630 s390_register_info ();
8632 /* If we're using a base register, ensure that it is always valid for
8633 the first non-prologue instruction. */
8634 if (fun
->machine
->base_reg
)
8635 emit_insn_at_entry (gen_main_pool (fun
->machine
->base_reg
));
8637 /* Annotate all constant pool references to let the scheduler know
8638 they implicitly use the base register. */
8639 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
8642 annotate_constant_pool_refs (&PATTERN (insn
));
8643 df_insn_rescan (insn
);
8650 /* Expand the prologue into a bunch of separate insns. */
8653 s390_emit_prologue (void)
8661 /* Choose best register to use for temp use within prologue.
8662 See below for why TPF must use the register 1. */
8664 if (!has_hard_reg_initial_val (Pmode
, RETURN_REGNUM
)
8666 && !TARGET_TPF_PROFILING
)
8667 temp_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
8669 temp_reg
= gen_rtx_REG (Pmode
, 1);
8671 s390_save_gprs_to_fprs ();
8673 /* Save call saved gprs. */
8674 if (cfun_frame_layout
.first_save_gpr
!= -1)
8676 insn
= save_gprs (stack_pointer_rtx
,
8677 cfun_frame_layout
.gprs_offset
+
8678 UNITS_PER_LONG
* (cfun_frame_layout
.first_save_gpr
8679 - cfun_frame_layout
.first_save_gpr_slot
),
8680 cfun_frame_layout
.first_save_gpr
,
8681 cfun_frame_layout
.last_save_gpr
);
8685 /* Dummy insn to mark literal pool slot. */
8687 if (cfun
->machine
->base_reg
)
8688 emit_insn (gen_main_pool (cfun
->machine
->base_reg
));
8690 offset
= cfun_frame_layout
.f0_offset
;
8692 /* Save f0 and f2. */
8693 for (i
= FPR0_REGNUM
; i
<= FPR0_REGNUM
+ 1; i
++)
8695 if (cfun_fpr_save_p (i
))
8697 save_fpr (stack_pointer_rtx
, offset
, i
);
8700 else if (!TARGET_PACKED_STACK
|| cfun
->stdarg
)
8704 /* Save f4 and f6. */
8705 offset
= cfun_frame_layout
.f4_offset
;
8706 for (i
= FPR4_REGNUM
; i
<= FPR4_REGNUM
+ 1; i
++)
8708 if (cfun_fpr_save_p (i
))
8710 insn
= save_fpr (stack_pointer_rtx
, offset
, i
);
8713 /* If f4 and f6 are call clobbered they are saved due to
8714 stdargs and therefore are not frame related. */
8715 if (!call_really_used_regs
[i
])
8716 RTX_FRAME_RELATED_P (insn
) = 1;
8718 else if (!TARGET_PACKED_STACK
|| call_really_used_regs
[i
])
8722 if (TARGET_PACKED_STACK
8723 && cfun_save_high_fprs_p
8724 && cfun_frame_layout
.f8_offset
+ cfun_frame_layout
.high_fprs
* 8 > 0)
8726 offset
= (cfun_frame_layout
.f8_offset
8727 + (cfun_frame_layout
.high_fprs
- 1) * 8);
8729 for (i
= FPR15_REGNUM
; i
>= FPR8_REGNUM
&& offset
>= 0; i
--)
8730 if (cfun_fpr_save_p (i
))
8732 insn
= save_fpr (stack_pointer_rtx
, offset
, i
);
8734 RTX_FRAME_RELATED_P (insn
) = 1;
8737 if (offset
>= cfun_frame_layout
.f8_offset
)
8741 if (!TARGET_PACKED_STACK
)
8742 next_fpr
= cfun_save_high_fprs_p
? FPR15_REGNUM
: 0;
8744 if (flag_stack_usage_info
)
8745 current_function_static_stack_size
= cfun_frame_layout
.frame_size
;
8747 /* Decrement stack pointer. */
8749 if (cfun_frame_layout
.frame_size
> 0)
8751 rtx frame_off
= GEN_INT (-cfun_frame_layout
.frame_size
);
8754 if (s390_stack_size
)
8756 HOST_WIDE_INT stack_guard
;
8758 if (s390_stack_guard
)
8759 stack_guard
= s390_stack_guard
;
8762 /* If no value for stack guard is provided the smallest power of 2
8763 larger than the current frame size is chosen. */
8765 while (stack_guard
< cfun_frame_layout
.frame_size
)
8769 if (cfun_frame_layout
.frame_size
>= s390_stack_size
)
8771 warning (0, "frame size of function %qs is %wd"
8772 " bytes exceeding user provided stack limit of "
8774 "An unconditional trap is added.",
8775 current_function_name(), cfun_frame_layout
.frame_size
,
8777 emit_insn (gen_trap ());
8781 /* stack_guard has to be smaller than s390_stack_size.
8782 Otherwise we would emit an AND with zero which would
8783 not match the test under mask pattern. */
8784 if (stack_guard
>= s390_stack_size
)
8786 warning (0, "frame size of function %qs is %wd"
8787 " bytes which is more than half the stack size. "
8788 "The dynamic check would not be reliable. "
8789 "No check emitted for this function.",
8790 current_function_name(),
8791 cfun_frame_layout
.frame_size
);
8795 HOST_WIDE_INT stack_check_mask
= ((s390_stack_size
- 1)
8796 & ~(stack_guard
- 1));
8798 rtx t
= gen_rtx_AND (Pmode
, stack_pointer_rtx
,
8799 GEN_INT (stack_check_mask
));
8801 emit_insn (gen_ctrapdi4 (gen_rtx_EQ (VOIDmode
,
8803 t
, const0_rtx
, const0_rtx
));
8805 emit_insn (gen_ctrapsi4 (gen_rtx_EQ (VOIDmode
,
8807 t
, const0_rtx
, const0_rtx
));
8812 if (s390_warn_framesize
> 0
8813 && cfun_frame_layout
.frame_size
>= s390_warn_framesize
)
8814 warning (0, "frame size of %qs is %wd bytes",
8815 current_function_name (), cfun_frame_layout
.frame_size
);
8817 if (s390_warn_dynamicstack_p
&& cfun
->calls_alloca
)
8818 warning (0, "%qs uses dynamic stack allocation", current_function_name ());
8820 /* Save incoming stack pointer into temp reg. */
8821 if (TARGET_BACKCHAIN
|| next_fpr
)
8822 insn
= emit_insn (gen_move_insn (temp_reg
, stack_pointer_rtx
));
8824 /* Subtract frame size from stack pointer. */
8826 if (DISP_IN_RANGE (INTVAL (frame_off
)))
8828 insn
= gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
8829 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
8831 insn
= emit_insn (insn
);
8835 if (!CONST_OK_FOR_K (INTVAL (frame_off
)))
8836 frame_off
= force_const_mem (Pmode
, frame_off
);
8838 insn
= emit_insn (gen_add2_insn (stack_pointer_rtx
, frame_off
));
8839 annotate_constant_pool_refs (&PATTERN (insn
));
8842 RTX_FRAME_RELATED_P (insn
) = 1;
8843 real_frame_off
= GEN_INT (-cfun_frame_layout
.frame_size
);
8844 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
,
8845 gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
8846 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
8849 /* Set backchain. */
8851 if (TARGET_BACKCHAIN
)
8853 if (cfun_frame_layout
.backchain_offset
)
8854 addr
= gen_rtx_MEM (Pmode
,
8855 plus_constant (Pmode
, stack_pointer_rtx
,
8856 cfun_frame_layout
.backchain_offset
));
8858 addr
= gen_rtx_MEM (Pmode
, stack_pointer_rtx
);
8859 set_mem_alias_set (addr
, get_frame_alias_set ());
8860 insn
= emit_insn (gen_move_insn (addr
, temp_reg
));
8863 /* If we support non-call exceptions (e.g. for Java),
8864 we need to make sure the backchain pointer is set up
8865 before any possibly trapping memory access. */
8866 if (TARGET_BACKCHAIN
&& cfun
->can_throw_non_call_exceptions
)
8868 addr
= gen_rtx_MEM (BLKmode
, gen_rtx_SCRATCH (VOIDmode
));
8869 emit_clobber (addr
);
8873 /* Save fprs 8 - 15 (64 bit ABI). */
8875 if (cfun_save_high_fprs_p
&& next_fpr
)
8877 /* If the stack might be accessed through a different register
8878 we have to make sure that the stack pointer decrement is not
8879 moved below the use of the stack slots. */
8880 s390_emit_stack_tie ();
8882 insn
= emit_insn (gen_add2_insn (temp_reg
,
8883 GEN_INT (cfun_frame_layout
.f8_offset
)));
8887 for (i
= FPR8_REGNUM
; i
<= next_fpr
; i
++)
8888 if (cfun_fpr_save_p (i
))
8890 rtx addr
= plus_constant (Pmode
, stack_pointer_rtx
,
8891 cfun_frame_layout
.frame_size
8892 + cfun_frame_layout
.f8_offset
8895 insn
= save_fpr (temp_reg
, offset
, i
);
8897 RTX_FRAME_RELATED_P (insn
) = 1;
8898 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
,
8899 gen_rtx_SET (VOIDmode
,
8900 gen_rtx_MEM (DFmode
, addr
),
8901 gen_rtx_REG (DFmode
, i
)));
8905 /* Set frame pointer, if needed. */
8907 if (frame_pointer_needed
)
8909 insn
= emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
);
8910 RTX_FRAME_RELATED_P (insn
) = 1;
8913 /* Set up got pointer, if needed. */
8915 if (flag_pic
&& df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM
))
8917 rtx_insn
*insns
= s390_load_got ();
8919 for (rtx_insn
*insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
8920 annotate_constant_pool_refs (&PATTERN (insn
));
8925 if (TARGET_TPF_PROFILING
)
8927 /* Generate a BAS instruction to serve as a function
8928 entry intercept to facilitate the use of tracing
8929 algorithms located at the branch target. */
8930 emit_insn (gen_prologue_tpf ());
8932 /* Emit a blockage here so that all code
8933 lies between the profiling mechanisms. */
8934 emit_insn (gen_blockage ());
8938 /* Expand the epilogue into a bunch of separate insns. */
8941 s390_emit_epilogue (bool sibcall
)
8943 rtx frame_pointer
, return_reg
, cfa_restores
= NULL_RTX
;
8944 int area_bottom
, area_top
, offset
= 0;
8949 if (TARGET_TPF_PROFILING
)
8952 /* Generate a BAS instruction to serve as a function
8953 entry intercept to facilitate the use of tracing
8954 algorithms located at the branch target. */
8956 /* Emit a blockage here so that all code
8957 lies between the profiling mechanisms. */
8958 emit_insn (gen_blockage ());
8960 emit_insn (gen_epilogue_tpf ());
8963 /* Check whether to use frame or stack pointer for restore. */
8965 frame_pointer
= (frame_pointer_needed
8966 ? hard_frame_pointer_rtx
: stack_pointer_rtx
);
8968 s390_frame_area (&area_bottom
, &area_top
);
8970 /* Check whether we can access the register save area.
8971 If not, increment the frame pointer as required. */
8973 if (area_top
<= area_bottom
)
8975 /* Nothing to restore. */
8977 else if (DISP_IN_RANGE (cfun_frame_layout
.frame_size
+ area_bottom
)
8978 && DISP_IN_RANGE (cfun_frame_layout
.frame_size
+ area_top
- 1))
8980 /* Area is in range. */
8981 offset
= cfun_frame_layout
.frame_size
;
8985 rtx insn
, frame_off
, cfa
;
8987 offset
= area_bottom
< 0 ? -area_bottom
: 0;
8988 frame_off
= GEN_INT (cfun_frame_layout
.frame_size
- offset
);
8990 cfa
= gen_rtx_SET (VOIDmode
, frame_pointer
,
8991 gen_rtx_PLUS (Pmode
, frame_pointer
, frame_off
));
8992 if (DISP_IN_RANGE (INTVAL (frame_off
)))
8994 insn
= gen_rtx_SET (VOIDmode
, frame_pointer
,
8995 gen_rtx_PLUS (Pmode
, frame_pointer
, frame_off
));
8996 insn
= emit_insn (insn
);
9000 if (!CONST_OK_FOR_K (INTVAL (frame_off
)))
9001 frame_off
= force_const_mem (Pmode
, frame_off
);
9003 insn
= emit_insn (gen_add2_insn (frame_pointer
, frame_off
));
9004 annotate_constant_pool_refs (&PATTERN (insn
));
9006 add_reg_note (insn
, REG_CFA_ADJUST_CFA
, cfa
);
9007 RTX_FRAME_RELATED_P (insn
) = 1;
9010 /* Restore call saved fprs. */
9014 if (cfun_save_high_fprs_p
)
9016 next_offset
= cfun_frame_layout
.f8_offset
;
9017 for (i
= FPR8_REGNUM
; i
<= FPR15_REGNUM
; i
++)
9019 if (cfun_fpr_save_p (i
))
9021 restore_fpr (frame_pointer
,
9022 offset
+ next_offset
, i
);
9024 = alloc_reg_note (REG_CFA_RESTORE
,
9025 gen_rtx_REG (DFmode
, i
), cfa_restores
);
9034 next_offset
= cfun_frame_layout
.f4_offset
;
9036 for (i
= FPR4_REGNUM
; i
<= FPR4_REGNUM
+ 1; i
++)
9038 if (cfun_fpr_save_p (i
))
9040 restore_fpr (frame_pointer
,
9041 offset
+ next_offset
, i
);
9043 = alloc_reg_note (REG_CFA_RESTORE
,
9044 gen_rtx_REG (DFmode
, i
), cfa_restores
);
9047 else if (!TARGET_PACKED_STACK
)
9053 /* Return register. */
9055 return_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
9057 /* Restore call saved gprs. */
9059 if (cfun_frame_layout
.first_restore_gpr
!= -1)
9064 /* Check for global register and save them
9065 to stack location from where they get restored. */
9067 for (i
= cfun_frame_layout
.first_restore_gpr
;
9068 i
<= cfun_frame_layout
.last_restore_gpr
;
9071 if (global_not_special_regno_p (i
))
9073 addr
= plus_constant (Pmode
, frame_pointer
,
9074 offset
+ cfun_frame_layout
.gprs_offset
9075 + (i
- cfun_frame_layout
.first_save_gpr_slot
)
9077 addr
= gen_rtx_MEM (Pmode
, addr
);
9078 set_mem_alias_set (addr
, get_frame_alias_set ());
9079 emit_move_insn (addr
, gen_rtx_REG (Pmode
, i
));
9083 = alloc_reg_note (REG_CFA_RESTORE
,
9084 gen_rtx_REG (Pmode
, i
), cfa_restores
);
9089 /* Fetch return address from stack before load multiple,
9090 this will do good for scheduling.
9092 Only do this if we already decided that r14 needs to be
9093 saved to a stack slot. (And not just because r14 happens to
9094 be in between two GPRs which need saving.) Otherwise it
9095 would be difficult to take that decision back in
9096 s390_optimize_prologue. */
9097 if (cfun_gpr_save_slot (RETURN_REGNUM
) == -1)
9099 int return_regnum
= find_unused_clobbered_reg();
9102 return_reg
= gen_rtx_REG (Pmode
, return_regnum
);
9104 addr
= plus_constant (Pmode
, frame_pointer
,
9105 offset
+ cfun_frame_layout
.gprs_offset
9107 - cfun_frame_layout
.first_save_gpr_slot
)
9109 addr
= gen_rtx_MEM (Pmode
, addr
);
9110 set_mem_alias_set (addr
, get_frame_alias_set ());
9111 emit_move_insn (return_reg
, addr
);
9113 /* Once we did that optimization we have to make sure
9114 s390_optimize_prologue does not try to remove the
9115 store of r14 since we will not be able to find the
9116 load issued here. */
9117 cfun_frame_layout
.save_return_addr_p
= true;
9121 insn
= restore_gprs (frame_pointer
,
9122 offset
+ cfun_frame_layout
.gprs_offset
9123 + (cfun_frame_layout
.first_restore_gpr
9124 - cfun_frame_layout
.first_save_gpr_slot
)
9126 cfun_frame_layout
.first_restore_gpr
,
9127 cfun_frame_layout
.last_restore_gpr
);
9128 insn
= emit_insn (insn
);
9129 REG_NOTES (insn
) = cfa_restores
;
9130 add_reg_note (insn
, REG_CFA_DEF_CFA
,
9131 plus_constant (Pmode
, stack_pointer_rtx
,
9132 STACK_POINTER_OFFSET
));
9133 RTX_FRAME_RELATED_P (insn
) = 1;
9136 s390_restore_gprs_from_fprs ();
9141 /* Return to caller. */
9143 p
= rtvec_alloc (2);
9145 RTVEC_ELT (p
, 0) = ret_rtx
;
9146 RTVEC_ELT (p
, 1) = gen_rtx_USE (VOIDmode
, return_reg
);
9147 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
9151 /* Implement TARGET_SET_UP_BY_PROLOGUE. */
9154 s300_set_up_by_prologue (hard_reg_set_container
*regs
)
9156 if (cfun
->machine
->base_reg
9157 && !call_really_used_regs
[REGNO (cfun
->machine
->base_reg
)])
9158 SET_HARD_REG_BIT (regs
->set
, REGNO (cfun
->machine
->base_reg
));
9161 /* Return true if the function can use simple_return to return outside
9162 of a shrink-wrapped region. At present shrink-wrapping is supported
9166 s390_can_use_simple_return_insn (void)
9171 /* Return true if the epilogue is guaranteed to contain only a return
9172 instruction and if a direct return can therefore be used instead.
9173 One of the main advantages of using direct return instructions
9174 is that we can then use conditional returns. */
9177 s390_can_use_return_insn (void)
9181 if (!reload_completed
)
9187 if (TARGET_TPF_PROFILING
)
9190 for (i
= 0; i
< 16; i
++)
9191 if (cfun_gpr_save_slot (i
))
9194 /* For 31 bit this is not covered by the frame_size check below
9195 since f4, f6 are saved in the register save area without needing
9196 additional stack space. */
9198 && (cfun_fpr_save_p (FPR4_REGNUM
) || cfun_fpr_save_p (FPR6_REGNUM
)))
9201 if (cfun
->machine
->base_reg
9202 && !call_really_used_regs
[REGNO (cfun
->machine
->base_reg
)])
9205 return cfun_frame_layout
.frame_size
== 0;
9208 /* Return the size in bytes of a function argument of
9209 type TYPE and/or mode MODE. At least one of TYPE or
9210 MODE must be specified. */
9213 s390_function_arg_size (enum machine_mode mode
, const_tree type
)
9216 return int_size_in_bytes (type
);
9218 /* No type info available for some library calls ... */
9219 if (mode
!= BLKmode
)
9220 return GET_MODE_SIZE (mode
);
9222 /* If we have neither type nor mode, abort */
9226 /* Return true if a function argument of type TYPE and mode MODE
9227 is to be passed in a floating-point register, if available. */
9230 s390_function_arg_float (enum machine_mode mode
, const_tree type
)
9232 int size
= s390_function_arg_size (mode
, type
);
9236 /* Soft-float changes the ABI: no floating-point registers are used. */
9237 if (TARGET_SOFT_FLOAT
)
9240 /* No type info available for some library calls ... */
9242 return mode
== SFmode
|| mode
== DFmode
|| mode
== SDmode
|| mode
== DDmode
;
9244 /* The ABI says that record types with a single member are treated
9245 just like that member would be. */
9246 while (TREE_CODE (type
) == RECORD_TYPE
)
9248 tree field
, single
= NULL_TREE
;
9250 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
9252 if (TREE_CODE (field
) != FIELD_DECL
)
9255 if (single
== NULL_TREE
)
9256 single
= TREE_TYPE (field
);
9261 if (single
== NULL_TREE
)
9267 return TREE_CODE (type
) == REAL_TYPE
;
9270 /* Return true if a function argument of type TYPE and mode MODE
9271 is to be passed in an integer register, or a pair of integer
9272 registers, if available. */
9275 s390_function_arg_integer (enum machine_mode mode
, const_tree type
)
9277 int size
= s390_function_arg_size (mode
, type
);
9281 /* No type info available for some library calls ... */
9283 return GET_MODE_CLASS (mode
) == MODE_INT
9284 || (TARGET_SOFT_FLOAT
&& SCALAR_FLOAT_MODE_P (mode
));
9286 /* We accept small integral (and similar) types. */
9287 if (INTEGRAL_TYPE_P (type
)
9288 || POINTER_TYPE_P (type
)
9289 || TREE_CODE (type
) == NULLPTR_TYPE
9290 || TREE_CODE (type
) == OFFSET_TYPE
9291 || (TARGET_SOFT_FLOAT
&& TREE_CODE (type
) == REAL_TYPE
))
9294 /* We also accept structs of size 1, 2, 4, 8 that are not
9295 passed in floating-point registers. */
9296 if (AGGREGATE_TYPE_P (type
)
9297 && exact_log2 (size
) >= 0
9298 && !s390_function_arg_float (mode
, type
))
9304 /* Return 1 if a function argument of type TYPE and mode MODE
9305 is to be passed by reference. The ABI specifies that only
9306 structures of size 1, 2, 4, or 8 bytes are passed by value,
9307 all other structures (and complex numbers) are passed by
9311 s390_pass_by_reference (cumulative_args_t ca ATTRIBUTE_UNUSED
,
9312 enum machine_mode mode
, const_tree type
,
9313 bool named ATTRIBUTE_UNUSED
)
9315 int size
= s390_function_arg_size (mode
, type
);
9321 if (AGGREGATE_TYPE_P (type
) && exact_log2 (size
) < 0)
9324 if (TREE_CODE (type
) == COMPLEX_TYPE
9325 || TREE_CODE (type
) == VECTOR_TYPE
)
9332 /* Update the data in CUM to advance over an argument of mode MODE and
9333 data type TYPE. (TYPE is null for libcalls where that information
9334 may not be available.). The boolean NAMED specifies whether the
9335 argument is a named argument (as opposed to an unnamed argument
9336 matching an ellipsis). */
9339 s390_function_arg_advance (cumulative_args_t cum_v
, enum machine_mode mode
,
9340 const_tree type
, bool named ATTRIBUTE_UNUSED
)
9342 CUMULATIVE_ARGS
*cum
= get_cumulative_args (cum_v
);
9344 if (s390_function_arg_float (mode
, type
))
9348 else if (s390_function_arg_integer (mode
, type
))
9350 int size
= s390_function_arg_size (mode
, type
);
9351 cum
->gprs
+= ((size
+ UNITS_PER_LONG
- 1) / UNITS_PER_LONG
);
9357 /* Define where to put the arguments to a function.
9358 Value is zero to push the argument on the stack,
9359 or a hard register in which to store the argument.
9361 MODE is the argument's machine mode.
9362 TYPE is the data type of the argument (as a tree).
9363 This is null for libcalls where that information may
9365 CUM is a variable of type CUMULATIVE_ARGS which gives info about
9366 the preceding args and about the function being called.
9367 NAMED is nonzero if this argument is a named parameter
9368 (otherwise it is an extra parameter matching an ellipsis).
9370 On S/390, we use general purpose registers 2 through 6 to
9371 pass integer, pointer, and certain structure arguments, and
9372 floating point registers 0 and 2 (0, 2, 4, and 6 on 64-bit)
9373 to pass floating point arguments. All remaining arguments
9374 are pushed to the stack. */
9377 s390_function_arg (cumulative_args_t cum_v
, enum machine_mode mode
,
9378 const_tree type
, bool named ATTRIBUTE_UNUSED
)
9380 CUMULATIVE_ARGS
*cum
= get_cumulative_args (cum_v
);
9382 if (s390_function_arg_float (mode
, type
))
9384 if (cum
->fprs
+ 1 > FP_ARG_NUM_REG
)
9387 return gen_rtx_REG (mode
, cum
->fprs
+ 16);
9389 else if (s390_function_arg_integer (mode
, type
))
9391 int size
= s390_function_arg_size (mode
, type
);
9392 int n_gprs
= (size
+ UNITS_PER_LONG
- 1) / UNITS_PER_LONG
;
9394 if (cum
->gprs
+ n_gprs
> GP_ARG_NUM_REG
)
9396 else if (n_gprs
== 1 || UNITS_PER_WORD
== UNITS_PER_LONG
)
9397 return gen_rtx_REG (mode
, cum
->gprs
+ 2);
9398 else if (n_gprs
== 2)
9400 rtvec p
= rtvec_alloc (2);
9403 = gen_rtx_EXPR_LIST (SImode
, gen_rtx_REG (SImode
, cum
->gprs
+ 2),
9406 = gen_rtx_EXPR_LIST (SImode
, gen_rtx_REG (SImode
, cum
->gprs
+ 3),
9409 return gen_rtx_PARALLEL (mode
, p
);
9413 /* After the real arguments, expand_call calls us once again
9414 with a void_type_node type. Whatever we return here is
9415 passed as operand 2 to the call expanders.
9417 We don't need this feature ... */
9418 else if (type
== void_type_node
)
9424 /* Return true if return values of type TYPE should be returned
9425 in a memory buffer whose address is passed by the caller as
9426 hidden first argument. */
9429 s390_return_in_memory (const_tree type
, const_tree fundecl ATTRIBUTE_UNUSED
)
9431 /* We accept small integral (and similar) types. */
9432 if (INTEGRAL_TYPE_P (type
)
9433 || POINTER_TYPE_P (type
)
9434 || TREE_CODE (type
) == OFFSET_TYPE
9435 || TREE_CODE (type
) == REAL_TYPE
)
9436 return int_size_in_bytes (type
) > 8;
9438 /* Aggregates and similar constructs are always returned
9440 if (AGGREGATE_TYPE_P (type
)
9441 || TREE_CODE (type
) == COMPLEX_TYPE
9442 || TREE_CODE (type
) == VECTOR_TYPE
)
9445 /* ??? We get called on all sorts of random stuff from
9446 aggregate_value_p. We can't abort, but it's not clear
9447 what's safe to return. Pretend it's a struct I guess. */
9451 /* Function arguments and return values are promoted to word size. */
9453 static enum machine_mode
9454 s390_promote_function_mode (const_tree type
, enum machine_mode mode
,
9456 const_tree fntype ATTRIBUTE_UNUSED
,
9457 int for_return ATTRIBUTE_UNUSED
)
9459 if (INTEGRAL_MODE_P (mode
)
9460 && GET_MODE_SIZE (mode
) < UNITS_PER_LONG
)
9462 if (type
!= NULL_TREE
&& POINTER_TYPE_P (type
))
9463 *punsignedp
= POINTERS_EXTEND_UNSIGNED
;
9470 /* Define where to return a (scalar) value of type RET_TYPE.
9471 If RET_TYPE is null, define where to return a (scalar)
9472 value of mode MODE from a libcall. */
9475 s390_function_and_libcall_value (enum machine_mode mode
,
9476 const_tree ret_type
,
9477 const_tree fntype_or_decl
,
9478 bool outgoing ATTRIBUTE_UNUSED
)
9480 /* For normal functions perform the promotion as
9481 promote_function_mode would do. */
9484 int unsignedp
= TYPE_UNSIGNED (ret_type
);
9485 mode
= promote_function_mode (ret_type
, mode
, &unsignedp
,
9489 gcc_assert (GET_MODE_CLASS (mode
) == MODE_INT
|| SCALAR_FLOAT_MODE_P (mode
));
9490 gcc_assert (GET_MODE_SIZE (mode
) <= 8);
9492 if (TARGET_HARD_FLOAT
&& SCALAR_FLOAT_MODE_P (mode
))
9493 return gen_rtx_REG (mode
, 16);
9494 else if (GET_MODE_SIZE (mode
) <= UNITS_PER_LONG
9495 || UNITS_PER_LONG
== UNITS_PER_WORD
)
9496 return gen_rtx_REG (mode
, 2);
9497 else if (GET_MODE_SIZE (mode
) == 2 * UNITS_PER_LONG
)
9499 /* This case is triggered when returning a 64 bit value with
9500 -m31 -mzarch. Although the value would fit into a single
9501 register it has to be forced into a 32 bit register pair in
9502 order to match the ABI. */
9503 rtvec p
= rtvec_alloc (2);
9506 = gen_rtx_EXPR_LIST (SImode
, gen_rtx_REG (SImode
, 2), const0_rtx
);
9508 = gen_rtx_EXPR_LIST (SImode
, gen_rtx_REG (SImode
, 3), GEN_INT (4));
9510 return gen_rtx_PARALLEL (mode
, p
);
9516 /* Define where to return a scalar return value of type RET_TYPE. */
9519 s390_function_value (const_tree ret_type
, const_tree fn_decl_or_type
,
9522 return s390_function_and_libcall_value (TYPE_MODE (ret_type
), ret_type
,
9523 fn_decl_or_type
, outgoing
);
9526 /* Define where to return a scalar libcall return value of mode
9530 s390_libcall_value (enum machine_mode mode
, const_rtx fun ATTRIBUTE_UNUSED
)
9532 return s390_function_and_libcall_value (mode
, NULL_TREE
,
9537 /* Create and return the va_list datatype.
9539 On S/390, va_list is an array type equivalent to
9541 typedef struct __va_list_tag
9545 void *__overflow_arg_area;
9546 void *__reg_save_area;
9549 where __gpr and __fpr hold the number of general purpose
9550 or floating point arguments used up to now, respectively,
9551 __overflow_arg_area points to the stack location of the
9552 next argument passed on the stack, and __reg_save_area
9553 always points to the start of the register area in the
9554 call frame of the current function. The function prologue
9555 saves all registers used for argument passing into this
9556 area if the function uses variable arguments. */
9559 s390_build_builtin_va_list (void)
9561 tree f_gpr
, f_fpr
, f_ovf
, f_sav
, record
, type_decl
;
9563 record
= lang_hooks
.types
.make_type (RECORD_TYPE
);
9566 build_decl (BUILTINS_LOCATION
,
9567 TYPE_DECL
, get_identifier ("__va_list_tag"), record
);
9569 f_gpr
= build_decl (BUILTINS_LOCATION
,
9570 FIELD_DECL
, get_identifier ("__gpr"),
9571 long_integer_type_node
);
9572 f_fpr
= build_decl (BUILTINS_LOCATION
,
9573 FIELD_DECL
, get_identifier ("__fpr"),
9574 long_integer_type_node
);
9575 f_ovf
= build_decl (BUILTINS_LOCATION
,
9576 FIELD_DECL
, get_identifier ("__overflow_arg_area"),
9578 f_sav
= build_decl (BUILTINS_LOCATION
,
9579 FIELD_DECL
, get_identifier ("__reg_save_area"),
9582 va_list_gpr_counter_field
= f_gpr
;
9583 va_list_fpr_counter_field
= f_fpr
;
9585 DECL_FIELD_CONTEXT (f_gpr
) = record
;
9586 DECL_FIELD_CONTEXT (f_fpr
) = record
;
9587 DECL_FIELD_CONTEXT (f_ovf
) = record
;
9588 DECL_FIELD_CONTEXT (f_sav
) = record
;
9590 TYPE_STUB_DECL (record
) = type_decl
;
9591 TYPE_NAME (record
) = type_decl
;
9592 TYPE_FIELDS (record
) = f_gpr
;
9593 DECL_CHAIN (f_gpr
) = f_fpr
;
9594 DECL_CHAIN (f_fpr
) = f_ovf
;
9595 DECL_CHAIN (f_ovf
) = f_sav
;
9597 layout_type (record
);
9599 /* The correct type is an array type of one element. */
9600 return build_array_type (record
, build_index_type (size_zero_node
));
9603 /* Implement va_start by filling the va_list structure VALIST.
9604 STDARG_P is always true, and ignored.
9605 NEXTARG points to the first anonymous stack argument.
9607 The following global variables are used to initialize
9608 the va_list structure:
9611 holds number of gprs and fprs used for named arguments.
9612 crtl->args.arg_offset_rtx:
9613 holds the offset of the first anonymous stack argument
9614 (relative to the virtual arg pointer). */
9617 s390_va_start (tree valist
, rtx nextarg ATTRIBUTE_UNUSED
)
9619 HOST_WIDE_INT n_gpr
, n_fpr
;
9621 tree f_gpr
, f_fpr
, f_ovf
, f_sav
;
9622 tree gpr
, fpr
, ovf
, sav
, t
;
9624 f_gpr
= TYPE_FIELDS (TREE_TYPE (va_list_type_node
));
9625 f_fpr
= DECL_CHAIN (f_gpr
);
9626 f_ovf
= DECL_CHAIN (f_fpr
);
9627 f_sav
= DECL_CHAIN (f_ovf
);
9629 valist
= build_simple_mem_ref (valist
);
9630 gpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_gpr
), valist
, f_gpr
, NULL_TREE
);
9631 fpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_fpr
), valist
, f_fpr
, NULL_TREE
);
9632 ovf
= build3 (COMPONENT_REF
, TREE_TYPE (f_ovf
), valist
, f_ovf
, NULL_TREE
);
9633 sav
= build3 (COMPONENT_REF
, TREE_TYPE (f_sav
), valist
, f_sav
, NULL_TREE
);
9635 /* Count number of gp and fp argument registers used. */
9637 n_gpr
= crtl
->args
.info
.gprs
;
9638 n_fpr
= crtl
->args
.info
.fprs
;
9640 if (cfun
->va_list_gpr_size
)
9642 t
= build2 (MODIFY_EXPR
, TREE_TYPE (gpr
), gpr
,
9643 build_int_cst (NULL_TREE
, n_gpr
));
9644 TREE_SIDE_EFFECTS (t
) = 1;
9645 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
9648 if (cfun
->va_list_fpr_size
)
9650 t
= build2 (MODIFY_EXPR
, TREE_TYPE (fpr
), fpr
,
9651 build_int_cst (NULL_TREE
, n_fpr
));
9652 TREE_SIDE_EFFECTS (t
) = 1;
9653 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
9656 /* Find the overflow area. */
9657 if (n_gpr
+ cfun
->va_list_gpr_size
> GP_ARG_NUM_REG
9658 || n_fpr
+ cfun
->va_list_fpr_size
> FP_ARG_NUM_REG
)
9660 t
= make_tree (TREE_TYPE (ovf
), virtual_incoming_args_rtx
);
9662 off
= INTVAL (crtl
->args
.arg_offset_rtx
);
9663 off
= off
< 0 ? 0 : off
;
9664 if (TARGET_DEBUG_ARG
)
9665 fprintf (stderr
, "va_start: n_gpr = %d, n_fpr = %d off %d\n",
9666 (int)n_gpr
, (int)n_fpr
, off
);
9668 t
= fold_build_pointer_plus_hwi (t
, off
);
9670 t
= build2 (MODIFY_EXPR
, TREE_TYPE (ovf
), ovf
, t
);
9671 TREE_SIDE_EFFECTS (t
) = 1;
9672 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
9675 /* Find the register save area. */
9676 if ((cfun
->va_list_gpr_size
&& n_gpr
< GP_ARG_NUM_REG
)
9677 || (cfun
->va_list_fpr_size
&& n_fpr
< FP_ARG_NUM_REG
))
9679 t
= make_tree (TREE_TYPE (sav
), return_address_pointer_rtx
);
9680 t
= fold_build_pointer_plus_hwi (t
, -RETURN_REGNUM
* UNITS_PER_LONG
);
9682 t
= build2 (MODIFY_EXPR
, TREE_TYPE (sav
), sav
, t
);
9683 TREE_SIDE_EFFECTS (t
) = 1;
9684 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
9688 /* Implement va_arg by updating the va_list structure
9689 VALIST as required to retrieve an argument of type
9690 TYPE, and returning that argument.
9692 Generates code equivalent to:
9694 if (integral value) {
9695 if (size <= 4 && args.gpr < 5 ||
9696 size > 4 && args.gpr < 4 )
9697 ret = args.reg_save_area[args.gpr+8]
9699 ret = *args.overflow_arg_area++;
9700 } else if (float value) {
9702 ret = args.reg_save_area[args.fpr+64]
9704 ret = *args.overflow_arg_area++;
9705 } else if (aggregate value) {
9707 ret = *args.reg_save_area[args.gpr]
9709 ret = **args.overflow_arg_area++;
9713 s390_gimplify_va_arg (tree valist
, tree type
, gimple_seq
*pre_p
,
9714 gimple_seq
*post_p ATTRIBUTE_UNUSED
)
9716 tree f_gpr
, f_fpr
, f_ovf
, f_sav
;
9717 tree gpr
, fpr
, ovf
, sav
, reg
, t
, u
;
9718 int indirect_p
, size
, n_reg
, sav_ofs
, sav_scale
, max_reg
;
9719 tree lab_false
, lab_over
, addr
;
9721 f_gpr
= TYPE_FIELDS (TREE_TYPE (va_list_type_node
));
9722 f_fpr
= DECL_CHAIN (f_gpr
);
9723 f_ovf
= DECL_CHAIN (f_fpr
);
9724 f_sav
= DECL_CHAIN (f_ovf
);
9726 valist
= build_va_arg_indirect_ref (valist
);
9727 gpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_gpr
), valist
, f_gpr
, NULL_TREE
);
9728 fpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_fpr
), valist
, f_fpr
, NULL_TREE
);
9729 sav
= build3 (COMPONENT_REF
, TREE_TYPE (f_sav
), valist
, f_sav
, NULL_TREE
);
9731 /* The tree for args* cannot be shared between gpr/fpr and ovf since
9732 both appear on a lhs. */
9733 valist
= unshare_expr (valist
);
9734 ovf
= build3 (COMPONENT_REF
, TREE_TYPE (f_ovf
), valist
, f_ovf
, NULL_TREE
);
9736 size
= int_size_in_bytes (type
);
9738 if (pass_by_reference (NULL
, TYPE_MODE (type
), type
, false))
9740 if (TARGET_DEBUG_ARG
)
9742 fprintf (stderr
, "va_arg: aggregate type");
9746 /* Aggregates are passed by reference. */
9751 /* kernel stack layout on 31 bit: It is assumed here that no padding
9752 will be added by s390_frame_info because for va_args always an even
9753 number of gprs has to be saved r15-r2 = 14 regs. */
9754 sav_ofs
= 2 * UNITS_PER_LONG
;
9755 sav_scale
= UNITS_PER_LONG
;
9756 size
= UNITS_PER_LONG
;
9757 max_reg
= GP_ARG_NUM_REG
- n_reg
;
9759 else if (s390_function_arg_float (TYPE_MODE (type
), type
))
9761 if (TARGET_DEBUG_ARG
)
9763 fprintf (stderr
, "va_arg: float type");
9767 /* FP args go in FP registers, if present. */
9771 sav_ofs
= 16 * UNITS_PER_LONG
;
9773 max_reg
= FP_ARG_NUM_REG
- n_reg
;
9777 if (TARGET_DEBUG_ARG
)
9779 fprintf (stderr
, "va_arg: other type");
9783 /* Otherwise into GP registers. */
9786 n_reg
= (size
+ UNITS_PER_LONG
- 1) / UNITS_PER_LONG
;
9788 /* kernel stack layout on 31 bit: It is assumed here that no padding
9789 will be added by s390_frame_info because for va_args always an even
9790 number of gprs has to be saved r15-r2 = 14 regs. */
9791 sav_ofs
= 2 * UNITS_PER_LONG
;
9793 if (size
< UNITS_PER_LONG
)
9794 sav_ofs
+= UNITS_PER_LONG
- size
;
9796 sav_scale
= UNITS_PER_LONG
;
9797 max_reg
= GP_ARG_NUM_REG
- n_reg
;
9800 /* Pull the value out of the saved registers ... */
9802 lab_false
= create_artificial_label (UNKNOWN_LOCATION
);
9803 lab_over
= create_artificial_label (UNKNOWN_LOCATION
);
9804 addr
= create_tmp_var (ptr_type_node
, "addr");
9806 t
= fold_convert (TREE_TYPE (reg
), size_int (max_reg
));
9807 t
= build2 (GT_EXPR
, boolean_type_node
, reg
, t
);
9808 u
= build1 (GOTO_EXPR
, void_type_node
, lab_false
);
9809 t
= build3 (COND_EXPR
, void_type_node
, t
, u
, NULL_TREE
);
9810 gimplify_and_add (t
, pre_p
);
9812 t
= fold_build_pointer_plus_hwi (sav
, sav_ofs
);
9813 u
= build2 (MULT_EXPR
, TREE_TYPE (reg
), reg
,
9814 fold_convert (TREE_TYPE (reg
), size_int (sav_scale
)));
9815 t
= fold_build_pointer_plus (t
, u
);
9817 gimplify_assign (addr
, t
, pre_p
);
9819 gimple_seq_add_stmt (pre_p
, gimple_build_goto (lab_over
));
9821 gimple_seq_add_stmt (pre_p
, gimple_build_label (lab_false
));
9824 /* ... Otherwise out of the overflow area. */
9827 if (size
< UNITS_PER_LONG
)
9828 t
= fold_build_pointer_plus_hwi (t
, UNITS_PER_LONG
- size
);
9830 gimplify_expr (&t
, pre_p
, NULL
, is_gimple_val
, fb_rvalue
);
9832 gimplify_assign (addr
, t
, pre_p
);
9834 t
= fold_build_pointer_plus_hwi (t
, size
);
9835 gimplify_assign (ovf
, t
, pre_p
);
9837 gimple_seq_add_stmt (pre_p
, gimple_build_label (lab_over
));
9840 /* Increment register save count. */
9842 u
= build2 (PREINCREMENT_EXPR
, TREE_TYPE (reg
), reg
,
9843 fold_convert (TREE_TYPE (reg
), size_int (n_reg
)));
9844 gimplify_and_add (u
, pre_p
);
9848 t
= build_pointer_type_for_mode (build_pointer_type (type
),
9850 addr
= fold_convert (t
, addr
);
9851 addr
= build_va_arg_indirect_ref (addr
);
9855 t
= build_pointer_type_for_mode (type
, ptr_mode
, true);
9856 addr
= fold_convert (t
, addr
);
9859 return build_va_arg_indirect_ref (addr
);
9862 /* Emit rtl for the tbegin or tbegin_retry (RETRY != NULL_RTX)
9864 DEST - Register location where CC will be stored.
9865 TDB - Pointer to a 256 byte area where to store the transaction.
9866 diagnostic block. NULL if TDB is not needed.
9867 RETRY - Retry count value. If non-NULL a retry loop for CC2
9869 CLOBBER_FPRS_P - If true clobbers for all FPRs are emitted as part
9870 of the tbegin instruction pattern. */
9873 s390_expand_tbegin (rtx dest
, rtx tdb
, rtx retry
, bool clobber_fprs_p
)
9875 rtx retry_plus_two
= gen_reg_rtx (SImode
);
9876 rtx retry_reg
= gen_reg_rtx (SImode
);
9877 rtx_code_label
*retry_label
= NULL
;
9879 if (retry
!= NULL_RTX
)
9881 emit_move_insn (retry_reg
, retry
);
9882 emit_insn (gen_addsi3 (retry_plus_two
, retry_reg
, const2_rtx
));
9883 emit_insn (gen_addsi3 (retry_reg
, retry_reg
, const1_rtx
));
9884 retry_label
= gen_label_rtx ();
9885 emit_label (retry_label
);
9889 emit_insn (gen_tbegin_1 (gen_rtx_CONST_INT (VOIDmode
, TBEGIN_MASK
), tdb
));
9891 emit_insn (gen_tbegin_nofloat_1 (gen_rtx_CONST_INT (VOIDmode
, TBEGIN_MASK
),
9894 emit_move_insn (dest
, gen_rtx_UNSPEC (SImode
,
9895 gen_rtvec (1, gen_rtx_REG (CCRAWmode
,
9898 if (retry
!= NULL_RTX
)
9900 const int CC0
= 1 << 3;
9901 const int CC1
= 1 << 2;
9902 const int CC3
= 1 << 0;
9904 rtx count
= gen_reg_rtx (SImode
);
9905 rtx_code_label
*leave_label
= gen_label_rtx ();
9907 /* Exit for success and permanent failures. */
9908 jump
= s390_emit_jump (leave_label
,
9909 gen_rtx_EQ (VOIDmode
,
9910 gen_rtx_REG (CCRAWmode
, CC_REGNUM
),
9911 gen_rtx_CONST_INT (VOIDmode
, CC0
| CC1
| CC3
)));
9912 LABEL_NUSES (leave_label
) = 1;
9914 /* CC2 - transient failure. Perform retry with ppa. */
9915 emit_move_insn (count
, retry_plus_two
);
9916 emit_insn (gen_subsi3 (count
, count
, retry_reg
));
9917 emit_insn (gen_tx_assist (count
));
9918 jump
= emit_jump_insn (gen_doloop_si64 (retry_label
,
9921 JUMP_LABEL (jump
) = retry_label
;
9922 LABEL_NUSES (retry_label
) = 1;
9923 emit_label (leave_label
);
9931 S390_BUILTIN_TBEGIN
,
9932 S390_BUILTIN_TBEGIN_NOFLOAT
,
9933 S390_BUILTIN_TBEGIN_RETRY
,
9934 S390_BUILTIN_TBEGIN_RETRY_NOFLOAT
,
9935 S390_BUILTIN_TBEGINC
,
9937 S390_BUILTIN_TABORT
,
9938 S390_BUILTIN_NON_TX_STORE
,
9939 S390_BUILTIN_TX_NESTING_DEPTH
,
9940 S390_BUILTIN_TX_ASSIST
,
9945 static enum insn_code
const code_for_builtin
[S390_BUILTIN_max
] = {
9947 CODE_FOR_tbegin_nofloat
,
9948 CODE_FOR_tbegin_retry
,
9949 CODE_FOR_tbegin_retry_nofloat
,
9959 s390_init_builtins (void)
9961 tree ftype
, uint64_type
;
9962 tree returns_twice_attr
= tree_cons (get_identifier ("returns_twice"),
9964 tree noreturn_attr
= tree_cons (get_identifier ("noreturn"), NULL
, NULL
);
9966 /* void foo (void) */
9967 ftype
= build_function_type_list (void_type_node
, NULL_TREE
);
9968 add_builtin_function ("__builtin_tbeginc", ftype
, S390_BUILTIN_TBEGINC
,
9969 BUILT_IN_MD
, NULL
, NULL_TREE
);
9971 /* void foo (int) */
9972 ftype
= build_function_type_list (void_type_node
, integer_type_node
,
9974 add_builtin_function ("__builtin_tabort", ftype
,
9975 S390_BUILTIN_TABORT
, BUILT_IN_MD
, NULL
, noreturn_attr
);
9976 add_builtin_function ("__builtin_tx_assist", ftype
,
9977 S390_BUILTIN_TX_ASSIST
, BUILT_IN_MD
, NULL
, NULL_TREE
);
9979 /* int foo (void *) */
9980 ftype
= build_function_type_list (integer_type_node
, ptr_type_node
, NULL_TREE
);
9981 add_builtin_function ("__builtin_tbegin", ftype
, S390_BUILTIN_TBEGIN
,
9982 BUILT_IN_MD
, NULL
, returns_twice_attr
);
9983 add_builtin_function ("__builtin_tbegin_nofloat", ftype
,
9984 S390_BUILTIN_TBEGIN_NOFLOAT
,
9985 BUILT_IN_MD
, NULL
, returns_twice_attr
);
9987 /* int foo (void *, int) */
9988 ftype
= build_function_type_list (integer_type_node
, ptr_type_node
,
9989 integer_type_node
, NULL_TREE
);
9990 add_builtin_function ("__builtin_tbegin_retry", ftype
,
9991 S390_BUILTIN_TBEGIN_RETRY
,
9993 NULL
, returns_twice_attr
);
9994 add_builtin_function ("__builtin_tbegin_retry_nofloat", ftype
,
9995 S390_BUILTIN_TBEGIN_RETRY_NOFLOAT
,
9997 NULL
, returns_twice_attr
);
9999 /* int foo (void) */
10000 ftype
= build_function_type_list (integer_type_node
, NULL_TREE
);
10001 add_builtin_function ("__builtin_tx_nesting_depth", ftype
,
10002 S390_BUILTIN_TX_NESTING_DEPTH
,
10003 BUILT_IN_MD
, NULL
, NULL_TREE
);
10004 add_builtin_function ("__builtin_tend", ftype
,
10005 S390_BUILTIN_TEND
, BUILT_IN_MD
, NULL
, NULL_TREE
);
10007 /* void foo (uint64_t *, uint64_t) */
10009 uint64_type
= long_unsigned_type_node
;
10011 uint64_type
= long_long_unsigned_type_node
;
10013 ftype
= build_function_type_list (void_type_node
,
10014 build_pointer_type (uint64_type
),
10015 uint64_type
, NULL_TREE
);
10016 add_builtin_function ("__builtin_non_tx_store", ftype
,
10017 S390_BUILTIN_NON_TX_STORE
,
10018 BUILT_IN_MD
, NULL
, NULL_TREE
);
10021 /* Expand an expression EXP that calls a built-in function,
10022 with result going to TARGET if that's convenient
10023 (and in mode MODE if that's convenient).
10024 SUBTARGET may be used as the target for computing one of EXP's operands.
10025 IGNORE is nonzero if the value is to be ignored. */
10028 s390_expand_builtin (tree exp
, rtx target
, rtx subtarget ATTRIBUTE_UNUSED
,
10029 enum machine_mode mode ATTRIBUTE_UNUSED
,
10030 int ignore ATTRIBUTE_UNUSED
)
10034 tree fndecl
= TREE_OPERAND (CALL_EXPR_FN (exp
), 0);
10035 unsigned int fcode
= DECL_FUNCTION_CODE (fndecl
);
10036 enum insn_code icode
;
10037 rtx op
[MAX_ARGS
], pat
;
10041 call_expr_arg_iterator iter
;
10043 if (fcode
>= S390_BUILTIN_max
)
10044 internal_error ("bad builtin fcode");
10045 icode
= code_for_builtin
[fcode
];
10047 internal_error ("bad builtin fcode");
10050 error ("Transactional execution builtins not enabled (-mhtm)\n");
10052 /* Set a flag in the machine specific cfun part in order to support
10053 saving/restoring of FPRs. */
10054 if (fcode
== S390_BUILTIN_TBEGIN
|| fcode
== S390_BUILTIN_TBEGIN_RETRY
)
10055 cfun
->machine
->tbegin_p
= true;
10057 nonvoid
= TREE_TYPE (TREE_TYPE (fndecl
)) != void_type_node
;
10060 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, exp
)
10062 const struct insn_operand_data
*insn_op
;
10064 if (arg
== error_mark_node
)
10066 if (arity
>= MAX_ARGS
)
10069 insn_op
= &insn_data
[icode
].operand
[arity
+ nonvoid
];
10071 op
[arity
] = expand_expr (arg
, NULL_RTX
, insn_op
->mode
, EXPAND_NORMAL
);
10073 if (!(*insn_op
->predicate
) (op
[arity
], insn_op
->mode
))
10075 if (insn_op
->predicate
== memory_operand
)
10077 /* Don't move a NULL pointer into a register. Otherwise
10078 we have to rely on combine being able to move it back
10079 in order to get an immediate 0 in the instruction. */
10080 if (op
[arity
] != const0_rtx
)
10081 op
[arity
] = copy_to_mode_reg (Pmode
, op
[arity
]);
10082 op
[arity
] = gen_rtx_MEM (insn_op
->mode
, op
[arity
]);
10085 op
[arity
] = copy_to_mode_reg (insn_op
->mode
, op
[arity
]);
10093 enum machine_mode tmode
= insn_data
[icode
].operand
[0].mode
;
10095 || GET_MODE (target
) != tmode
10096 || !(*insn_data
[icode
].operand
[0].predicate
) (target
, tmode
))
10097 target
= gen_reg_rtx (tmode
);
10103 pat
= GEN_FCN (icode
) (target
);
10107 pat
= GEN_FCN (icode
) (target
, op
[0]);
10109 pat
= GEN_FCN (icode
) (op
[0]);
10113 pat
= GEN_FCN (icode
) (target
, op
[0], op
[1]);
10115 pat
= GEN_FCN (icode
) (op
[0], op
[1]);
10118 gcc_unreachable ();
10130 /* We call mcount before the function prologue. So a profiled leaf
10131 function should stay a leaf function. */
10134 s390_keep_leaf_when_profiled ()
10139 /* Output assembly code for the trampoline template to
10142 On S/390, we use gpr 1 internally in the trampoline code;
10143 gpr 0 is used to hold the static chain. */
10146 s390_asm_trampoline_template (FILE *file
)
10149 op
[0] = gen_rtx_REG (Pmode
, 0);
10150 op
[1] = gen_rtx_REG (Pmode
, 1);
10154 output_asm_insn ("basr\t%1,0", op
); /* 2 byte */
10155 output_asm_insn ("lmg\t%0,%1,14(%1)", op
); /* 6 byte */
10156 output_asm_insn ("br\t%1", op
); /* 2 byte */
10157 ASM_OUTPUT_SKIP (file
, (HOST_WIDE_INT
)(TRAMPOLINE_SIZE
- 10));
10161 output_asm_insn ("basr\t%1,0", op
); /* 2 byte */
10162 output_asm_insn ("lm\t%0,%1,6(%1)", op
); /* 4 byte */
10163 output_asm_insn ("br\t%1", op
); /* 2 byte */
10164 ASM_OUTPUT_SKIP (file
, (HOST_WIDE_INT
)(TRAMPOLINE_SIZE
- 8));
10168 /* Emit RTL insns to initialize the variable parts of a trampoline.
10169 FNADDR is an RTX for the address of the function's pure code.
10170 CXT is an RTX for the static chain value for the function. */
10173 s390_trampoline_init (rtx m_tramp
, tree fndecl
, rtx cxt
)
10175 rtx fnaddr
= XEXP (DECL_RTL (fndecl
), 0);
10178 emit_block_move (m_tramp
, assemble_trampoline_template (),
10179 GEN_INT (2 * UNITS_PER_LONG
), BLOCK_OP_NORMAL
);
10181 mem
= adjust_address (m_tramp
, Pmode
, 2 * UNITS_PER_LONG
);
10182 emit_move_insn (mem
, cxt
);
10183 mem
= adjust_address (m_tramp
, Pmode
, 3 * UNITS_PER_LONG
);
10184 emit_move_insn (mem
, fnaddr
);
10187 /* Output assembler code to FILE to increment profiler label # LABELNO
10188 for profiling a function entry. */
10191 s390_function_profiler (FILE *file
, int labelno
)
10196 ASM_GENERATE_INTERNAL_LABEL (label
, "LP", labelno
);
10198 fprintf (file
, "# function profiler \n");
10200 op
[0] = gen_rtx_REG (Pmode
, RETURN_REGNUM
);
10201 op
[1] = gen_rtx_REG (Pmode
, STACK_POINTER_REGNUM
);
10202 op
[1] = gen_rtx_MEM (Pmode
, plus_constant (Pmode
, op
[1], UNITS_PER_LONG
));
10204 op
[2] = gen_rtx_REG (Pmode
, 1);
10205 op
[3] = gen_rtx_SYMBOL_REF (Pmode
, label
);
10206 SYMBOL_REF_FLAGS (op
[3]) = SYMBOL_FLAG_LOCAL
;
10208 op
[4] = gen_rtx_SYMBOL_REF (Pmode
, "_mcount");
10211 op
[4] = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op
[4]), UNSPEC_PLT
);
10212 op
[4] = gen_rtx_CONST (Pmode
, op
[4]);
10217 output_asm_insn ("stg\t%0,%1", op
);
10218 output_asm_insn ("larl\t%2,%3", op
);
10219 output_asm_insn ("brasl\t%0,%4", op
);
10220 output_asm_insn ("lg\t%0,%1", op
);
10222 else if (!flag_pic
)
10224 op
[6] = gen_label_rtx ();
10226 output_asm_insn ("st\t%0,%1", op
);
10227 output_asm_insn ("bras\t%2,%l6", op
);
10228 output_asm_insn (".long\t%4", op
);
10229 output_asm_insn (".long\t%3", op
);
10230 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[6]));
10231 output_asm_insn ("l\t%0,0(%2)", op
);
10232 output_asm_insn ("l\t%2,4(%2)", op
);
10233 output_asm_insn ("basr\t%0,%0", op
);
10234 output_asm_insn ("l\t%0,%1", op
);
10238 op
[5] = gen_label_rtx ();
10239 op
[6] = gen_label_rtx ();
10241 output_asm_insn ("st\t%0,%1", op
);
10242 output_asm_insn ("bras\t%2,%l6", op
);
10243 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[5]));
10244 output_asm_insn (".long\t%4-%l5", op
);
10245 output_asm_insn (".long\t%3-%l5", op
);
10246 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[6]));
10247 output_asm_insn ("lr\t%0,%2", op
);
10248 output_asm_insn ("a\t%0,0(%2)", op
);
10249 output_asm_insn ("a\t%2,4(%2)", op
);
10250 output_asm_insn ("basr\t%0,%0", op
);
10251 output_asm_insn ("l\t%0,%1", op
);
10255 /* Encode symbol attributes (local vs. global, tls model) of a SYMBOL_REF
10256 into its SYMBOL_REF_FLAGS. */
10259 s390_encode_section_info (tree decl
, rtx rtl
, int first
)
10261 default_encode_section_info (decl
, rtl
, first
);
10263 if (TREE_CODE (decl
) == VAR_DECL
)
10265 /* If a variable has a forced alignment to < 2 bytes, mark it
10266 with SYMBOL_FLAG_ALIGN1 to prevent it from being used as LARL
10268 if (DECL_USER_ALIGN (decl
) && DECL_ALIGN (decl
) < 16)
10269 SYMBOL_REF_FLAGS (XEXP (rtl
, 0)) |= SYMBOL_FLAG_ALIGN1
;
10270 if (!DECL_SIZE (decl
)
10271 || !DECL_ALIGN (decl
)
10272 || !tree_fits_shwi_p (DECL_SIZE (decl
))
10273 || (DECL_ALIGN (decl
) <= 64
10274 && DECL_ALIGN (decl
) != tree_to_shwi (DECL_SIZE (decl
))))
10275 SYMBOL_REF_FLAGS (XEXP (rtl
, 0)) |= SYMBOL_FLAG_NOT_NATURALLY_ALIGNED
;
10278 /* Literal pool references don't have a decl so they are handled
10279 differently here. We rely on the information in the MEM_ALIGN
10280 entry to decide upon natural alignment. */
10282 && GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
10283 && TREE_CONSTANT_POOL_ADDRESS_P (XEXP (rtl
, 0))
10284 && (MEM_ALIGN (rtl
) == 0
10285 || GET_MODE_BITSIZE (GET_MODE (rtl
)) == 0
10286 || MEM_ALIGN (rtl
) < GET_MODE_BITSIZE (GET_MODE (rtl
))))
10287 SYMBOL_REF_FLAGS (XEXP (rtl
, 0)) |= SYMBOL_FLAG_NOT_NATURALLY_ALIGNED
;
10290 /* Output thunk to FILE that implements a C++ virtual function call (with
10291 multiple inheritance) to FUNCTION. The thunk adjusts the this pointer
10292 by DELTA, and unless VCALL_OFFSET is zero, applies an additional adjustment
10293 stored at VCALL_OFFSET in the vtable whose address is located at offset 0
10294 relative to the resulting this pointer. */
10297 s390_output_mi_thunk (FILE *file
, tree thunk ATTRIBUTE_UNUSED
,
10298 HOST_WIDE_INT delta
, HOST_WIDE_INT vcall_offset
,
10304 /* Make sure unwind info is emitted for the thunk if needed. */
10305 final_start_function (emit_barrier (), file
, 1);
10307 /* Operand 0 is the target function. */
10308 op
[0] = XEXP (DECL_RTL (function
), 0);
10309 if (flag_pic
&& !SYMBOL_REF_LOCAL_P (op
[0]))
10312 op
[0] = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op
[0]),
10313 TARGET_64BIT
? UNSPEC_PLT
: UNSPEC_GOT
);
10314 op
[0] = gen_rtx_CONST (Pmode
, op
[0]);
10317 /* Operand 1 is the 'this' pointer. */
10318 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function
)), function
))
10319 op
[1] = gen_rtx_REG (Pmode
, 3);
10321 op
[1] = gen_rtx_REG (Pmode
, 2);
10323 /* Operand 2 is the delta. */
10324 op
[2] = GEN_INT (delta
);
10326 /* Operand 3 is the vcall_offset. */
10327 op
[3] = GEN_INT (vcall_offset
);
10329 /* Operand 4 is the temporary register. */
10330 op
[4] = gen_rtx_REG (Pmode
, 1);
10332 /* Operands 5 to 8 can be used as labels. */
10338 /* Operand 9 can be used for temporary register. */
10341 /* Generate code. */
10344 /* Setup literal pool pointer if required. */
10345 if ((!DISP_IN_RANGE (delta
)
10346 && !CONST_OK_FOR_K (delta
)
10347 && !CONST_OK_FOR_Os (delta
))
10348 || (!DISP_IN_RANGE (vcall_offset
)
10349 && !CONST_OK_FOR_K (vcall_offset
)
10350 && !CONST_OK_FOR_Os (vcall_offset
)))
10352 op
[5] = gen_label_rtx ();
10353 output_asm_insn ("larl\t%4,%5", op
);
10356 /* Add DELTA to this pointer. */
10359 if (CONST_OK_FOR_J (delta
))
10360 output_asm_insn ("la\t%1,%2(%1)", op
);
10361 else if (DISP_IN_RANGE (delta
))
10362 output_asm_insn ("lay\t%1,%2(%1)", op
);
10363 else if (CONST_OK_FOR_K (delta
))
10364 output_asm_insn ("aghi\t%1,%2", op
);
10365 else if (CONST_OK_FOR_Os (delta
))
10366 output_asm_insn ("agfi\t%1,%2", op
);
10369 op
[6] = gen_label_rtx ();
10370 output_asm_insn ("agf\t%1,%6-%5(%4)", op
);
10374 /* Perform vcall adjustment. */
10377 if (DISP_IN_RANGE (vcall_offset
))
10379 output_asm_insn ("lg\t%4,0(%1)", op
);
10380 output_asm_insn ("ag\t%1,%3(%4)", op
);
10382 else if (CONST_OK_FOR_K (vcall_offset
))
10384 output_asm_insn ("lghi\t%4,%3", op
);
10385 output_asm_insn ("ag\t%4,0(%1)", op
);
10386 output_asm_insn ("ag\t%1,0(%4)", op
);
10388 else if (CONST_OK_FOR_Os (vcall_offset
))
10390 output_asm_insn ("lgfi\t%4,%3", op
);
10391 output_asm_insn ("ag\t%4,0(%1)", op
);
10392 output_asm_insn ("ag\t%1,0(%4)", op
);
10396 op
[7] = gen_label_rtx ();
10397 output_asm_insn ("llgf\t%4,%7-%5(%4)", op
);
10398 output_asm_insn ("ag\t%4,0(%1)", op
);
10399 output_asm_insn ("ag\t%1,0(%4)", op
);
10403 /* Jump to target. */
10404 output_asm_insn ("jg\t%0", op
);
10406 /* Output literal pool if required. */
10409 output_asm_insn (".align\t4", op
);
10410 targetm
.asm_out
.internal_label (file
, "L",
10411 CODE_LABEL_NUMBER (op
[5]));
10415 targetm
.asm_out
.internal_label (file
, "L",
10416 CODE_LABEL_NUMBER (op
[6]));
10417 output_asm_insn (".long\t%2", op
);
10421 targetm
.asm_out
.internal_label (file
, "L",
10422 CODE_LABEL_NUMBER (op
[7]));
10423 output_asm_insn (".long\t%3", op
);
10428 /* Setup base pointer if required. */
10430 || (!DISP_IN_RANGE (delta
)
10431 && !CONST_OK_FOR_K (delta
)
10432 && !CONST_OK_FOR_Os (delta
))
10433 || (!DISP_IN_RANGE (delta
)
10434 && !CONST_OK_FOR_K (vcall_offset
)
10435 && !CONST_OK_FOR_Os (vcall_offset
)))
10437 op
[5] = gen_label_rtx ();
10438 output_asm_insn ("basr\t%4,0", op
);
10439 targetm
.asm_out
.internal_label (file
, "L",
10440 CODE_LABEL_NUMBER (op
[5]));
10443 /* Add DELTA to this pointer. */
10446 if (CONST_OK_FOR_J (delta
))
10447 output_asm_insn ("la\t%1,%2(%1)", op
);
10448 else if (DISP_IN_RANGE (delta
))
10449 output_asm_insn ("lay\t%1,%2(%1)", op
);
10450 else if (CONST_OK_FOR_K (delta
))
10451 output_asm_insn ("ahi\t%1,%2", op
);
10452 else if (CONST_OK_FOR_Os (delta
))
10453 output_asm_insn ("afi\t%1,%2", op
);
10456 op
[6] = gen_label_rtx ();
10457 output_asm_insn ("a\t%1,%6-%5(%4)", op
);
10461 /* Perform vcall adjustment. */
10464 if (CONST_OK_FOR_J (vcall_offset
))
10466 output_asm_insn ("l\t%4,0(%1)", op
);
10467 output_asm_insn ("a\t%1,%3(%4)", op
);
10469 else if (DISP_IN_RANGE (vcall_offset
))
10471 output_asm_insn ("l\t%4,0(%1)", op
);
10472 output_asm_insn ("ay\t%1,%3(%4)", op
);
10474 else if (CONST_OK_FOR_K (vcall_offset
))
10476 output_asm_insn ("lhi\t%4,%3", op
);
10477 output_asm_insn ("a\t%4,0(%1)", op
);
10478 output_asm_insn ("a\t%1,0(%4)", op
);
10480 else if (CONST_OK_FOR_Os (vcall_offset
))
10482 output_asm_insn ("iilf\t%4,%3", op
);
10483 output_asm_insn ("a\t%4,0(%1)", op
);
10484 output_asm_insn ("a\t%1,0(%4)", op
);
10488 op
[7] = gen_label_rtx ();
10489 output_asm_insn ("l\t%4,%7-%5(%4)", op
);
10490 output_asm_insn ("a\t%4,0(%1)", op
);
10491 output_asm_insn ("a\t%1,0(%4)", op
);
10494 /* We had to clobber the base pointer register.
10495 Re-setup the base pointer (with a different base). */
10496 op
[5] = gen_label_rtx ();
10497 output_asm_insn ("basr\t%4,0", op
);
10498 targetm
.asm_out
.internal_label (file
, "L",
10499 CODE_LABEL_NUMBER (op
[5]));
10502 /* Jump to target. */
10503 op
[8] = gen_label_rtx ();
10506 output_asm_insn ("l\t%4,%8-%5(%4)", op
);
10507 else if (!nonlocal
)
10508 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
10509 /* We cannot call through .plt, since .plt requires %r12 loaded. */
10510 else if (flag_pic
== 1)
10512 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
10513 output_asm_insn ("l\t%4,%0(%4)", op
);
10515 else if (flag_pic
== 2)
10517 op
[9] = gen_rtx_REG (Pmode
, 0);
10518 output_asm_insn ("l\t%9,%8-4-%5(%4)", op
);
10519 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
10520 output_asm_insn ("ar\t%4,%9", op
);
10521 output_asm_insn ("l\t%4,0(%4)", op
);
10524 output_asm_insn ("br\t%4", op
);
10526 /* Output literal pool. */
10527 output_asm_insn (".align\t4", op
);
10529 if (nonlocal
&& flag_pic
== 2)
10530 output_asm_insn (".long\t%0", op
);
10533 op
[0] = gen_rtx_SYMBOL_REF (Pmode
, "_GLOBAL_OFFSET_TABLE_");
10534 SYMBOL_REF_FLAGS (op
[0]) = SYMBOL_FLAG_LOCAL
;
10537 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[8]));
10539 output_asm_insn (".long\t%0", op
);
10541 output_asm_insn (".long\t%0-%5", op
);
10545 targetm
.asm_out
.internal_label (file
, "L",
10546 CODE_LABEL_NUMBER (op
[6]));
10547 output_asm_insn (".long\t%2", op
);
10551 targetm
.asm_out
.internal_label (file
, "L",
10552 CODE_LABEL_NUMBER (op
[7]));
10553 output_asm_insn (".long\t%3", op
);
10556 final_end_function ();
10560 s390_valid_pointer_mode (enum machine_mode mode
)
10562 return (mode
== SImode
|| (TARGET_64BIT
&& mode
== DImode
));
10565 /* Checks whether the given CALL_EXPR would use a caller
10566 saved register. This is used to decide whether sibling call
10567 optimization could be performed on the respective function
10571 s390_call_saved_register_used (tree call_expr
)
10573 CUMULATIVE_ARGS cum_v
;
10574 cumulative_args_t cum
;
10576 enum machine_mode mode
;
10581 INIT_CUMULATIVE_ARGS (cum_v
, NULL
, NULL
, 0, 0);
10582 cum
= pack_cumulative_args (&cum_v
);
10584 for (i
= 0; i
< call_expr_nargs (call_expr
); i
++)
10586 parameter
= CALL_EXPR_ARG (call_expr
, i
);
10587 gcc_assert (parameter
);
10589 /* For an undeclared variable passed as parameter we will get
10590 an ERROR_MARK node here. */
10591 if (TREE_CODE (parameter
) == ERROR_MARK
)
10594 type
= TREE_TYPE (parameter
);
10597 mode
= TYPE_MODE (type
);
10600 if (pass_by_reference (&cum_v
, mode
, type
, true))
10603 type
= build_pointer_type (type
);
10606 parm_rtx
= s390_function_arg (cum
, mode
, type
, 0);
10608 s390_function_arg_advance (cum
, mode
, type
, 0);
10613 if (REG_P (parm_rtx
))
10616 reg
< HARD_REGNO_NREGS (REGNO (parm_rtx
), GET_MODE (parm_rtx
));
10618 if (!call_used_regs
[reg
+ REGNO (parm_rtx
)])
10622 if (GET_CODE (parm_rtx
) == PARALLEL
)
10626 for (i
= 0; i
< XVECLEN (parm_rtx
, 0); i
++)
10628 rtx r
= XEXP (XVECEXP (parm_rtx
, 0, i
), 0);
10630 gcc_assert (REG_P (r
));
10633 reg
< HARD_REGNO_NREGS (REGNO (r
), GET_MODE (r
));
10635 if (!call_used_regs
[reg
+ REGNO (r
)])
10644 /* Return true if the given call expression can be
10645 turned into a sibling call.
10646 DECL holds the declaration of the function to be called whereas
10647 EXP is the call expression itself. */
10650 s390_function_ok_for_sibcall (tree decl
, tree exp
)
10652 /* The TPF epilogue uses register 1. */
10653 if (TARGET_TPF_PROFILING
)
10656 /* The 31 bit PLT code uses register 12 (GOT pointer - caller saved)
10657 which would have to be restored before the sibcall. */
10658 if (!TARGET_64BIT
&& flag_pic
&& decl
&& !targetm
.binds_local_p (decl
))
10661 /* Register 6 on s390 is available as an argument register but unfortunately
10662 "caller saved". This makes functions needing this register for arguments
10663 not suitable for sibcalls. */
10664 return !s390_call_saved_register_used (exp
);
10667 /* Return the fixed registers used for condition codes. */
10670 s390_fixed_condition_code_regs (unsigned int *p1
, unsigned int *p2
)
10673 *p2
= INVALID_REGNUM
;
10678 /* This function is used by the call expanders of the machine description.
10679 It emits the call insn itself together with the necessary operations
10680 to adjust the target address and returns the emitted insn.
10681 ADDR_LOCATION is the target address rtx
10682 TLS_CALL the location of the thread-local symbol
10683 RESULT_REG the register where the result of the call should be stored
10684 RETADDR_REG the register where the return address should be stored
10685 If this parameter is NULL_RTX the call is considered
10686 to be a sibling call. */
10689 s390_emit_call (rtx addr_location
, rtx tls_call
, rtx result_reg
,
10692 bool plt_call
= false;
10698 /* Direct function calls need special treatment. */
10699 if (GET_CODE (addr_location
) == SYMBOL_REF
)
10701 /* When calling a global routine in PIC mode, we must
10702 replace the symbol itself with the PLT stub. */
10703 if (flag_pic
&& !SYMBOL_REF_LOCAL_P (addr_location
))
10705 if (retaddr_reg
!= NULL_RTX
)
10707 addr_location
= gen_rtx_UNSPEC (Pmode
,
10708 gen_rtvec (1, addr_location
),
10710 addr_location
= gen_rtx_CONST (Pmode
, addr_location
);
10714 /* For -fpic code the PLT entries might use r12 which is
10715 call-saved. Therefore we cannot do a sibcall when
10716 calling directly using a symbol ref. When reaching
10717 this point we decided (in s390_function_ok_for_sibcall)
10718 to do a sibcall for a function pointer but one of the
10719 optimizers was able to get rid of the function pointer
10720 by propagating the symbol ref into the call. This
10721 optimization is illegal for S/390 so we turn the direct
10722 call into a indirect call again. */
10723 addr_location
= force_reg (Pmode
, addr_location
);
10726 /* Unless we can use the bras(l) insn, force the
10727 routine address into a register. */
10728 if (!TARGET_SMALL_EXEC
&& !TARGET_CPU_ZARCH
)
10731 addr_location
= legitimize_pic_address (addr_location
, 0);
10733 addr_location
= force_reg (Pmode
, addr_location
);
10737 /* If it is already an indirect call or the code above moved the
10738 SYMBOL_REF to somewhere else make sure the address can be found in
10740 if (retaddr_reg
== NULL_RTX
10741 && GET_CODE (addr_location
) != SYMBOL_REF
10744 emit_move_insn (gen_rtx_REG (Pmode
, SIBCALL_REGNUM
), addr_location
);
10745 addr_location
= gen_rtx_REG (Pmode
, SIBCALL_REGNUM
);
10748 addr_location
= gen_rtx_MEM (QImode
, addr_location
);
10749 call
= gen_rtx_CALL (VOIDmode
, addr_location
, const0_rtx
);
10751 if (result_reg
!= NULL_RTX
)
10752 call
= gen_rtx_SET (VOIDmode
, result_reg
, call
);
10754 if (retaddr_reg
!= NULL_RTX
)
10756 clobber
= gen_rtx_CLOBBER (VOIDmode
, retaddr_reg
);
10758 if (tls_call
!= NULL_RTX
)
10759 vec
= gen_rtvec (3, call
, clobber
,
10760 gen_rtx_USE (VOIDmode
, tls_call
));
10762 vec
= gen_rtvec (2, call
, clobber
);
10764 call
= gen_rtx_PARALLEL (VOIDmode
, vec
);
10767 insn
= emit_call_insn (call
);
10769 /* 31-bit PLT stubs and tls calls use the GOT register implicitly. */
10770 if ((!TARGET_64BIT
&& plt_call
) || tls_call
!= NULL_RTX
)
10772 /* s390_function_ok_for_sibcall should
10773 have denied sibcalls in this case. */
10774 gcc_assert (retaddr_reg
!= NULL_RTX
);
10775 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), gen_rtx_REG (Pmode
, 12));
10780 /* Implement TARGET_CONDITIONAL_REGISTER_USAGE. */
10783 s390_conditional_register_usage (void)
10789 fixed_regs
[PIC_OFFSET_TABLE_REGNUM
] = 1;
10790 call_used_regs
[PIC_OFFSET_TABLE_REGNUM
] = 1;
10792 if (TARGET_CPU_ZARCH
)
10794 fixed_regs
[BASE_REGNUM
] = 0;
10795 call_used_regs
[BASE_REGNUM
] = 0;
10796 fixed_regs
[RETURN_REGNUM
] = 0;
10797 call_used_regs
[RETURN_REGNUM
] = 0;
10801 for (i
= FPR8_REGNUM
; i
<= FPR15_REGNUM
; i
++)
10802 call_used_regs
[i
] = call_really_used_regs
[i
] = 0;
10806 call_used_regs
[FPR4_REGNUM
] = call_really_used_regs
[FPR4_REGNUM
] = 0;
10807 call_used_regs
[FPR6_REGNUM
] = call_really_used_regs
[FPR6_REGNUM
] = 0;
10810 if (TARGET_SOFT_FLOAT
)
10812 for (i
= FPR0_REGNUM
; i
<= FPR15_REGNUM
; i
++)
10813 call_used_regs
[i
] = fixed_regs
[i
] = 1;
10817 /* Corresponding function to eh_return expander. */
10819 static GTY(()) rtx s390_tpf_eh_return_symbol
;
10821 s390_emit_tpf_eh_return (rtx target
)
10826 if (!s390_tpf_eh_return_symbol
)
10827 s390_tpf_eh_return_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "__tpf_eh_return");
10829 reg
= gen_rtx_REG (Pmode
, 2);
10830 orig_ra
= gen_rtx_REG (Pmode
, 3);
10832 emit_move_insn (reg
, target
);
10833 emit_move_insn (orig_ra
, get_hard_reg_initial_val (Pmode
, RETURN_REGNUM
));
10834 insn
= s390_emit_call (s390_tpf_eh_return_symbol
, NULL_RTX
, reg
,
10835 gen_rtx_REG (Pmode
, RETURN_REGNUM
));
10836 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), reg
);
10837 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), orig_ra
);
10839 emit_move_insn (EH_RETURN_HANDLER_RTX
, reg
);
10842 /* Rework the prologue/epilogue to avoid saving/restoring
10843 registers unnecessarily. */
10846 s390_optimize_prologue (void)
10848 rtx_insn
*insn
, *new_insn
, *next_insn
;
10850 /* Do a final recompute of the frame-related data. */
10851 s390_optimize_register_info ();
10853 /* If all special registers are in fact used, there's nothing we
10854 can do, so no point in walking the insn list. */
10856 if (cfun_frame_layout
.first_save_gpr
<= BASE_REGNUM
10857 && cfun_frame_layout
.last_save_gpr
>= BASE_REGNUM
10858 && (TARGET_CPU_ZARCH
10859 || (cfun_frame_layout
.first_save_gpr
<= RETURN_REGNUM
10860 && cfun_frame_layout
.last_save_gpr
>= RETURN_REGNUM
)))
10863 /* Search for prologue/epilogue insns and replace them. */
10865 for (insn
= get_insns (); insn
; insn
= next_insn
)
10867 int first
, last
, off
;
10868 rtx set
, base
, offset
;
10871 next_insn
= NEXT_INSN (insn
);
10873 if (! NONJUMP_INSN_P (insn
) || ! RTX_FRAME_RELATED_P (insn
))
10876 pat
= PATTERN (insn
);
10878 /* Remove ldgr/lgdr instructions used for saving and restore
10879 GPRs if possible. */
10881 && GET_CODE (pat
) == SET
10882 && GET_MODE (SET_SRC (pat
)) == DImode
10883 && REG_P (SET_SRC (pat
))
10884 && REG_P (SET_DEST (pat
)))
10886 int src_regno
= REGNO (SET_SRC (pat
));
10887 int dest_regno
= REGNO (SET_DEST (pat
));
10891 if (!((GENERAL_REGNO_P (src_regno
) && FP_REGNO_P (dest_regno
))
10892 || (FP_REGNO_P (src_regno
) && GENERAL_REGNO_P (dest_regno
))))
10895 gpr_regno
= GENERAL_REGNO_P (src_regno
) ? src_regno
: dest_regno
;
10896 fpr_regno
= FP_REGNO_P (src_regno
) ? src_regno
: dest_regno
;
10898 /* GPR must be call-saved, FPR must be call-clobbered. */
10899 if (!call_really_used_regs
[fpr_regno
]
10900 || call_really_used_regs
[gpr_regno
])
10903 /* It must not happen that what we once saved in an FPR now
10904 needs a stack slot. */
10905 gcc_assert (cfun_gpr_save_slot (gpr_regno
) != -1);
10907 if (cfun_gpr_save_slot (gpr_regno
) == 0)
10909 remove_insn (insn
);
10914 if (GET_CODE (pat
) == PARALLEL
10915 && store_multiple_operation (pat
, VOIDmode
))
10917 set
= XVECEXP (pat
, 0, 0);
10918 first
= REGNO (SET_SRC (set
));
10919 last
= first
+ XVECLEN (pat
, 0) - 1;
10920 offset
= const0_rtx
;
10921 base
= eliminate_constant_term (XEXP (SET_DEST (set
), 0), &offset
);
10922 off
= INTVAL (offset
);
10924 if (GET_CODE (base
) != REG
|| off
< 0)
10926 if (cfun_frame_layout
.first_save_gpr
!= -1
10927 && (cfun_frame_layout
.first_save_gpr
< first
10928 || cfun_frame_layout
.last_save_gpr
> last
))
10930 if (REGNO (base
) != STACK_POINTER_REGNUM
10931 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
10933 if (first
> BASE_REGNUM
|| last
< BASE_REGNUM
)
10936 if (cfun_frame_layout
.first_save_gpr
!= -1)
10938 rtx s_pat
= save_gprs (base
,
10939 off
+ (cfun_frame_layout
.first_save_gpr
10940 - first
) * UNITS_PER_LONG
,
10941 cfun_frame_layout
.first_save_gpr
,
10942 cfun_frame_layout
.last_save_gpr
);
10943 new_insn
= emit_insn_before (s_pat
, insn
);
10944 INSN_ADDRESSES_NEW (new_insn
, -1);
10947 remove_insn (insn
);
10951 if (cfun_frame_layout
.first_save_gpr
== -1
10952 && GET_CODE (pat
) == SET
10953 && GENERAL_REG_P (SET_SRC (pat
))
10954 && GET_CODE (SET_DEST (pat
)) == MEM
)
10957 first
= REGNO (SET_SRC (set
));
10958 offset
= const0_rtx
;
10959 base
= eliminate_constant_term (XEXP (SET_DEST (set
), 0), &offset
);
10960 off
= INTVAL (offset
);
10962 if (GET_CODE (base
) != REG
|| off
< 0)
10964 if (REGNO (base
) != STACK_POINTER_REGNUM
10965 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
10968 remove_insn (insn
);
10972 if (GET_CODE (pat
) == PARALLEL
10973 && load_multiple_operation (pat
, VOIDmode
))
10975 set
= XVECEXP (pat
, 0, 0);
10976 first
= REGNO (SET_DEST (set
));
10977 last
= first
+ XVECLEN (pat
, 0) - 1;
10978 offset
= const0_rtx
;
10979 base
= eliminate_constant_term (XEXP (SET_SRC (set
), 0), &offset
);
10980 off
= INTVAL (offset
);
10982 if (GET_CODE (base
) != REG
|| off
< 0)
10985 if (cfun_frame_layout
.first_restore_gpr
!= -1
10986 && (cfun_frame_layout
.first_restore_gpr
< first
10987 || cfun_frame_layout
.last_restore_gpr
> last
))
10989 if (REGNO (base
) != STACK_POINTER_REGNUM
10990 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
10992 if (first
> BASE_REGNUM
|| last
< BASE_REGNUM
)
10995 if (cfun_frame_layout
.first_restore_gpr
!= -1)
10997 rtx rpat
= restore_gprs (base
,
10998 off
+ (cfun_frame_layout
.first_restore_gpr
10999 - first
) * UNITS_PER_LONG
,
11000 cfun_frame_layout
.first_restore_gpr
,
11001 cfun_frame_layout
.last_restore_gpr
);
11003 /* Remove REG_CFA_RESTOREs for registers that we no
11004 longer need to save. */
11005 REG_NOTES (rpat
) = REG_NOTES (insn
);
11006 for (rtx
*ptr
= ®_NOTES (rpat
); *ptr
; )
11007 if (REG_NOTE_KIND (*ptr
) == REG_CFA_RESTORE
11008 && ((int) REGNO (XEXP (*ptr
, 0))
11009 < cfun_frame_layout
.first_restore_gpr
))
11010 *ptr
= XEXP (*ptr
, 1);
11012 ptr
= &XEXP (*ptr
, 1);
11013 new_insn
= emit_insn_before (rpat
, insn
);
11014 RTX_FRAME_RELATED_P (new_insn
) = 1;
11015 INSN_ADDRESSES_NEW (new_insn
, -1);
11018 remove_insn (insn
);
11022 if (cfun_frame_layout
.first_restore_gpr
== -1
11023 && GET_CODE (pat
) == SET
11024 && GENERAL_REG_P (SET_DEST (pat
))
11025 && GET_CODE (SET_SRC (pat
)) == MEM
)
11028 first
= REGNO (SET_DEST (set
));
11029 offset
= const0_rtx
;
11030 base
= eliminate_constant_term (XEXP (SET_SRC (set
), 0), &offset
);
11031 off
= INTVAL (offset
);
11033 if (GET_CODE (base
) != REG
|| off
< 0)
11036 if (REGNO (base
) != STACK_POINTER_REGNUM
11037 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
11040 remove_insn (insn
);
11046 /* On z10 and later the dynamic branch prediction must see the
11047 backward jump within a certain windows. If not it falls back to
11048 the static prediction. This function rearranges the loop backward
11049 branch in a way which makes the static prediction always correct.
11050 The function returns true if it added an instruction. */
11052 s390_fix_long_loop_prediction (rtx_insn
*insn
)
11054 rtx set
= single_set (insn
);
11055 rtx code_label
, label_ref
, new_label
;
11056 rtx_insn
*uncond_jump
;
11057 rtx_insn
*cur_insn
;
11061 /* This will exclude branch on count and branch on index patterns
11062 since these are correctly statically predicted. */
11064 || SET_DEST (set
) != pc_rtx
11065 || GET_CODE (SET_SRC(set
)) != IF_THEN_ELSE
)
11068 /* Skip conditional returns. */
11069 if (ANY_RETURN_P (XEXP (SET_SRC (set
), 1))
11070 && XEXP (SET_SRC (set
), 2) == pc_rtx
)
11073 label_ref
= (GET_CODE (XEXP (SET_SRC (set
), 1)) == LABEL_REF
?
11074 XEXP (SET_SRC (set
), 1) : XEXP (SET_SRC (set
), 2));
11076 gcc_assert (GET_CODE (label_ref
) == LABEL_REF
);
11078 code_label
= XEXP (label_ref
, 0);
11080 if (INSN_ADDRESSES (INSN_UID (code_label
)) == -1
11081 || INSN_ADDRESSES (INSN_UID (insn
)) == -1
11082 || (INSN_ADDRESSES (INSN_UID (insn
))
11083 - INSN_ADDRESSES (INSN_UID (code_label
)) < PREDICT_DISTANCE
))
11086 for (distance
= 0, cur_insn
= PREV_INSN (insn
);
11087 distance
< PREDICT_DISTANCE
- 6;
11088 distance
+= get_attr_length (cur_insn
), cur_insn
= PREV_INSN (cur_insn
))
11089 if (!cur_insn
|| JUMP_P (cur_insn
) || LABEL_P (cur_insn
))
11092 new_label
= gen_label_rtx ();
11093 uncond_jump
= emit_jump_insn_after (
11094 gen_rtx_SET (VOIDmode
, pc_rtx
,
11095 gen_rtx_LABEL_REF (VOIDmode
, code_label
)),
11097 emit_label_after (new_label
, uncond_jump
);
11099 tmp
= XEXP (SET_SRC (set
), 1);
11100 XEXP (SET_SRC (set
), 1) = XEXP (SET_SRC (set
), 2);
11101 XEXP (SET_SRC (set
), 2) = tmp
;
11102 INSN_CODE (insn
) = -1;
11104 XEXP (label_ref
, 0) = new_label
;
11105 JUMP_LABEL (insn
) = new_label
;
11106 JUMP_LABEL (uncond_jump
) = code_label
;
11111 /* Returns 1 if INSN reads the value of REG for purposes not related
11112 to addressing of memory, and 0 otherwise. */
11114 s390_non_addr_reg_read_p (rtx reg
, rtx_insn
*insn
)
11116 return reg_referenced_p (reg
, PATTERN (insn
))
11117 && !reg_used_in_mem_p (REGNO (reg
), PATTERN (insn
));
11120 /* Starting from INSN find_cond_jump looks downwards in the insn
11121 stream for a single jump insn which is the last user of the
11122 condition code set in INSN. */
11124 find_cond_jump (rtx_insn
*insn
)
11126 for (; insn
; insn
= NEXT_INSN (insn
))
11130 if (LABEL_P (insn
))
11133 if (!JUMP_P (insn
))
11135 if (reg_mentioned_p (gen_rtx_REG (CCmode
, CC_REGNUM
), insn
))
11140 /* This will be triggered by a return. */
11141 if (GET_CODE (PATTERN (insn
)) != SET
)
11144 gcc_assert (SET_DEST (PATTERN (insn
)) == pc_rtx
);
11145 ite
= SET_SRC (PATTERN (insn
));
11147 if (GET_CODE (ite
) != IF_THEN_ELSE
)
11150 cc
= XEXP (XEXP (ite
, 0), 0);
11151 if (!REG_P (cc
) || !CC_REGNO_P (REGNO (cc
)))
11154 if (find_reg_note (insn
, REG_DEAD
, cc
))
11162 /* Swap the condition in COND and the operands in OP0 and OP1 so that
11163 the semantics does not change. If NULL_RTX is passed as COND the
11164 function tries to find the conditional jump starting with INSN. */
11166 s390_swap_cmp (rtx cond
, rtx
*op0
, rtx
*op1
, rtx_insn
*insn
)
11170 if (cond
== NULL_RTX
)
11172 rtx_insn
*jump
= find_cond_jump (NEXT_INSN (insn
));
11173 rtx set
= jump
? single_set (jump
) : NULL_RTX
;
11175 if (set
== NULL_RTX
)
11178 cond
= XEXP (SET_SRC (set
), 0);
11183 PUT_CODE (cond
, swap_condition (GET_CODE (cond
)));
11186 /* On z10, instructions of the compare-and-branch family have the
11187 property to access the register occurring as second operand with
11188 its bits complemented. If such a compare is grouped with a second
11189 instruction that accesses the same register non-complemented, and
11190 if that register's value is delivered via a bypass, then the
11191 pipeline recycles, thereby causing significant performance decline.
11192 This function locates such situations and exchanges the two
11193 operands of the compare. The function return true whenever it
11196 s390_z10_optimize_cmp (rtx_insn
*insn
)
11198 rtx_insn
*prev_insn
, *next_insn
;
11199 bool insn_added_p
= false;
11200 rtx cond
, *op0
, *op1
;
11202 if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
11204 /* Handle compare and branch and branch on count
11206 rtx pattern
= single_set (insn
);
11209 || SET_DEST (pattern
) != pc_rtx
11210 || GET_CODE (SET_SRC (pattern
)) != IF_THEN_ELSE
)
11213 cond
= XEXP (SET_SRC (pattern
), 0);
11214 op0
= &XEXP (cond
, 0);
11215 op1
= &XEXP (cond
, 1);
11217 else if (GET_CODE (PATTERN (insn
)) == SET
)
11221 /* Handle normal compare instructions. */
11222 src
= SET_SRC (PATTERN (insn
));
11223 dest
= SET_DEST (PATTERN (insn
));
11226 || !CC_REGNO_P (REGNO (dest
))
11227 || GET_CODE (src
) != COMPARE
)
11230 /* s390_swap_cmp will try to find the conditional
11231 jump when passing NULL_RTX as condition. */
11233 op0
= &XEXP (src
, 0);
11234 op1
= &XEXP (src
, 1);
11239 if (!REG_P (*op0
) || !REG_P (*op1
))
11242 if (GET_MODE_CLASS (GET_MODE (*op0
)) != MODE_INT
)
11245 /* Swap the COMPARE arguments and its mask if there is a
11246 conflicting access in the previous insn. */
11247 prev_insn
= prev_active_insn (insn
);
11248 if (prev_insn
!= NULL_RTX
&& INSN_P (prev_insn
)
11249 && reg_referenced_p (*op1
, PATTERN (prev_insn
)))
11250 s390_swap_cmp (cond
, op0
, op1
, insn
);
11252 /* Check if there is a conflict with the next insn. If there
11253 was no conflict with the previous insn, then swap the
11254 COMPARE arguments and its mask. If we already swapped
11255 the operands, or if swapping them would cause a conflict
11256 with the previous insn, issue a NOP after the COMPARE in
11257 order to separate the two instuctions. */
11258 next_insn
= next_active_insn (insn
);
11259 if (next_insn
!= NULL_RTX
&& INSN_P (next_insn
)
11260 && s390_non_addr_reg_read_p (*op1
, next_insn
))
11262 if (prev_insn
!= NULL_RTX
&& INSN_P (prev_insn
)
11263 && s390_non_addr_reg_read_p (*op0
, prev_insn
))
11265 if (REGNO (*op1
) == 0)
11266 emit_insn_after (gen_nop1 (), insn
);
11268 emit_insn_after (gen_nop (), insn
);
11269 insn_added_p
= true;
11272 s390_swap_cmp (cond
, op0
, op1
, insn
);
11274 return insn_added_p
;
11277 /* Perform machine-dependent processing. */
11282 bool pool_overflow
= false;
11284 /* Make sure all splits have been performed; splits after
11285 machine_dependent_reorg might confuse insn length counts. */
11286 split_all_insns_noflow ();
11288 /* Install the main literal pool and the associated base
11289 register load insns.
11291 In addition, there are two problematic situations we need
11294 - the literal pool might be > 4096 bytes in size, so that
11295 some of its elements cannot be directly accessed
11297 - a branch target might be > 64K away from the branch, so that
11298 it is not possible to use a PC-relative instruction.
11300 To fix those, we split the single literal pool into multiple
11301 pool chunks, reloading the pool base register at various
11302 points throughout the function to ensure it always points to
11303 the pool chunk the following code expects, and / or replace
11304 PC-relative branches by absolute branches.
11306 However, the two problems are interdependent: splitting the
11307 literal pool can move a branch further away from its target,
11308 causing the 64K limit to overflow, and on the other hand,
11309 replacing a PC-relative branch by an absolute branch means
11310 we need to put the branch target address into the literal
11311 pool, possibly causing it to overflow.
11313 So, we loop trying to fix up both problems until we manage
11314 to satisfy both conditions at the same time. Note that the
11315 loop is guaranteed to terminate as every pass of the loop
11316 strictly decreases the total number of PC-relative branches
11317 in the function. (This is not completely true as there
11318 might be branch-over-pool insns introduced by chunkify_start.
11319 Those never need to be split however.) */
11323 struct constant_pool
*pool
= NULL
;
11325 /* Collect the literal pool. */
11326 if (!pool_overflow
)
11328 pool
= s390_mainpool_start ();
11330 pool_overflow
= true;
11333 /* If literal pool overflowed, start to chunkify it. */
11335 pool
= s390_chunkify_start ();
11337 /* Split out-of-range branches. If this has created new
11338 literal pool entries, cancel current chunk list and
11339 recompute it. zSeries machines have large branch
11340 instructions, so we never need to split a branch. */
11341 if (!TARGET_CPU_ZARCH
&& s390_split_branches ())
11344 s390_chunkify_cancel (pool
);
11346 s390_mainpool_cancel (pool
);
11351 /* If we made it up to here, both conditions are satisfied.
11352 Finish up literal pool related changes. */
11354 s390_chunkify_finish (pool
);
11356 s390_mainpool_finish (pool
);
11358 /* We're done splitting branches. */
11359 cfun
->machine
->split_branches_pending_p
= false;
11363 /* Generate out-of-pool execute target insns. */
11364 if (TARGET_CPU_ZARCH
)
11366 rtx_insn
*insn
, *target
;
11369 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
11371 label
= s390_execute_label (insn
);
11375 gcc_assert (label
!= const0_rtx
);
11377 target
= emit_label (XEXP (label
, 0));
11378 INSN_ADDRESSES_NEW (target
, -1);
11380 target
= emit_insn (s390_execute_target (insn
));
11381 INSN_ADDRESSES_NEW (target
, -1);
11385 /* Try to optimize prologue and epilogue further. */
11386 s390_optimize_prologue ();
11388 /* Walk over the insns and do some >=z10 specific changes. */
11389 if (s390_tune
== PROCESSOR_2097_Z10
11390 || s390_tune
== PROCESSOR_2817_Z196
11391 || s390_tune
== PROCESSOR_2827_ZEC12
)
11394 bool insn_added_p
= false;
11396 /* The insn lengths and addresses have to be up to date for the
11397 following manipulations. */
11398 shorten_branches (get_insns ());
11400 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
11402 if (!INSN_P (insn
) || INSN_CODE (insn
) <= 0)
11406 insn_added_p
|= s390_fix_long_loop_prediction (insn
);
11408 if ((GET_CODE (PATTERN (insn
)) == PARALLEL
11409 || GET_CODE (PATTERN (insn
)) == SET
)
11410 && s390_tune
== PROCESSOR_2097_Z10
)
11411 insn_added_p
|= s390_z10_optimize_cmp (insn
);
11414 /* Adjust branches if we added new instructions. */
11416 shorten_branches (get_insns ());
11420 /* Return true if INSN is a fp load insn writing register REGNO. */
11422 s390_fpload_toreg (rtx_insn
*insn
, unsigned int regno
)
11425 enum attr_type flag
= s390_safe_attr_type (insn
);
11427 if (flag
!= TYPE_FLOADSF
&& flag
!= TYPE_FLOADDF
)
11430 set
= single_set (insn
);
11432 if (set
== NULL_RTX
)
11435 if (!REG_P (SET_DEST (set
)) || !MEM_P (SET_SRC (set
)))
11438 if (REGNO (SET_DEST (set
)) != regno
)
11444 /* This value describes the distance to be avoided between an
11445 aritmetic fp instruction and an fp load writing the same register.
11446 Z10_EARLYLOAD_DISTANCE - 1 as well as Z10_EARLYLOAD_DISTANCE + 1 is
11447 fine but the exact value has to be avoided. Otherwise the FP
11448 pipeline will throw an exception causing a major penalty. */
11449 #define Z10_EARLYLOAD_DISTANCE 7
11451 /* Rearrange the ready list in order to avoid the situation described
11452 for Z10_EARLYLOAD_DISTANCE. A problematic load instruction is
11453 moved to the very end of the ready list. */
11455 s390_z10_prevent_earlyload_conflicts (rtx_insn
**ready
, int *nready_p
)
11457 unsigned int regno
;
11458 int nready
= *nready_p
;
11463 enum attr_type flag
;
11466 /* Skip DISTANCE - 1 active insns. */
11467 for (insn
= last_scheduled_insn
, distance
= Z10_EARLYLOAD_DISTANCE
- 1;
11468 distance
> 0 && insn
!= NULL_RTX
;
11469 distance
--, insn
= prev_active_insn (insn
))
11470 if (CALL_P (insn
) || JUMP_P (insn
))
11473 if (insn
== NULL_RTX
)
11476 set
= single_set (insn
);
11478 if (set
== NULL_RTX
|| !REG_P (SET_DEST (set
))
11479 || GET_MODE_CLASS (GET_MODE (SET_DEST (set
))) != MODE_FLOAT
)
11482 flag
= s390_safe_attr_type (insn
);
11484 if (flag
== TYPE_FLOADSF
|| flag
== TYPE_FLOADDF
)
11487 regno
= REGNO (SET_DEST (set
));
11490 while (!s390_fpload_toreg (ready
[i
], regno
) && i
> 0)
11497 memmove (&ready
[1], &ready
[0], sizeof (rtx_insn
*) * i
);
11502 /* The s390_sched_state variable tracks the state of the current or
11503 the last instruction group.
11505 0,1,2 number of instructions scheduled in the current group
11506 3 the last group is complete - normal insns
11507 4 the last group was a cracked/expanded insn */
11509 static int s390_sched_state
;
11511 #define S390_OOO_SCHED_STATE_NORMAL 3
11512 #define S390_OOO_SCHED_STATE_CRACKED 4
11514 #define S390_OOO_SCHED_ATTR_MASK_CRACKED 0x1
11515 #define S390_OOO_SCHED_ATTR_MASK_EXPANDED 0x2
11516 #define S390_OOO_SCHED_ATTR_MASK_ENDGROUP 0x4
11517 #define S390_OOO_SCHED_ATTR_MASK_GROUPALONE 0x8
11519 static unsigned int
11520 s390_get_sched_attrmask (rtx_insn
*insn
)
11522 unsigned int mask
= 0;
11524 if (get_attr_ooo_cracked (insn
))
11525 mask
|= S390_OOO_SCHED_ATTR_MASK_CRACKED
;
11526 if (get_attr_ooo_expanded (insn
))
11527 mask
|= S390_OOO_SCHED_ATTR_MASK_EXPANDED
;
11528 if (get_attr_ooo_endgroup (insn
))
11529 mask
|= S390_OOO_SCHED_ATTR_MASK_ENDGROUP
;
11530 if (get_attr_ooo_groupalone (insn
))
11531 mask
|= S390_OOO_SCHED_ATTR_MASK_GROUPALONE
;
11535 /* Return the scheduling score for INSN. The higher the score the
11536 better. The score is calculated from the OOO scheduling attributes
11537 of INSN and the scheduling state s390_sched_state. */
11539 s390_sched_score (rtx_insn
*insn
)
11541 unsigned int mask
= s390_get_sched_attrmask (insn
);
11544 switch (s390_sched_state
)
11547 /* Try to put insns into the first slot which would otherwise
11549 if ((mask
& S390_OOO_SCHED_ATTR_MASK_CRACKED
) != 0
11550 || (mask
& S390_OOO_SCHED_ATTR_MASK_EXPANDED
) != 0)
11552 if ((mask
& S390_OOO_SCHED_ATTR_MASK_GROUPALONE
) != 0)
11555 /* Prefer not cracked insns while trying to put together a
11557 if ((mask
& S390_OOO_SCHED_ATTR_MASK_CRACKED
) == 0
11558 && (mask
& S390_OOO_SCHED_ATTR_MASK_EXPANDED
) == 0
11559 && (mask
& S390_OOO_SCHED_ATTR_MASK_GROUPALONE
) == 0)
11561 if ((mask
& S390_OOO_SCHED_ATTR_MASK_ENDGROUP
) == 0)
11565 /* Prefer not cracked insns while trying to put together a
11567 if ((mask
& S390_OOO_SCHED_ATTR_MASK_CRACKED
) == 0
11568 && (mask
& S390_OOO_SCHED_ATTR_MASK_EXPANDED
) == 0
11569 && (mask
& S390_OOO_SCHED_ATTR_MASK_GROUPALONE
) == 0)
11571 /* Prefer endgroup insns in the last slot. */
11572 if ((mask
& S390_OOO_SCHED_ATTR_MASK_ENDGROUP
) != 0)
11575 case S390_OOO_SCHED_STATE_NORMAL
:
11576 /* Prefer not cracked insns if the last was not cracked. */
11577 if ((mask
& S390_OOO_SCHED_ATTR_MASK_CRACKED
) == 0
11578 && (mask
& S390_OOO_SCHED_ATTR_MASK_EXPANDED
) == 0)
11580 if ((mask
& S390_OOO_SCHED_ATTR_MASK_GROUPALONE
) != 0)
11583 case S390_OOO_SCHED_STATE_CRACKED
:
11584 /* Try to keep cracked insns together to prevent them from
11585 interrupting groups. */
11586 if ((mask
& S390_OOO_SCHED_ATTR_MASK_CRACKED
) != 0
11587 || (mask
& S390_OOO_SCHED_ATTR_MASK_EXPANDED
) != 0)
11594 /* This function is called via hook TARGET_SCHED_REORDER before
11595 issuing one insn from list READY which contains *NREADYP entries.
11596 For target z10 it reorders load instructions to avoid early load
11597 conflicts in the floating point pipeline */
11599 s390_sched_reorder (FILE *file
, int verbose
,
11600 rtx_insn
**ready
, int *nreadyp
, int clock ATTRIBUTE_UNUSED
)
11602 if (s390_tune
== PROCESSOR_2097_Z10
)
11603 if (reload_completed
&& *nreadyp
> 1)
11604 s390_z10_prevent_earlyload_conflicts (ready
, nreadyp
);
11606 if (s390_tune
== PROCESSOR_2827_ZEC12
11607 && reload_completed
11611 int last_index
= *nreadyp
- 1;
11612 int max_index
= -1;
11613 int max_score
= -1;
11616 /* Just move the insn with the highest score to the top (the
11617 end) of the list. A full sort is not needed since a conflict
11618 in the hazard recognition cannot happen. So the top insn in
11619 the ready list will always be taken. */
11620 for (i
= last_index
; i
>= 0; i
--)
11624 if (recog_memoized (ready
[i
]) < 0)
11627 score
= s390_sched_score (ready
[i
]);
11628 if (score
> max_score
)
11635 if (max_index
!= -1)
11637 if (max_index
!= last_index
)
11639 tmp
= ready
[max_index
];
11640 ready
[max_index
] = ready
[last_index
];
11641 ready
[last_index
] = tmp
;
11645 "move insn %d to the top of list\n",
11646 INSN_UID (ready
[last_index
]));
11648 else if (verbose
> 5)
11650 "best insn %d already on top\n",
11651 INSN_UID (ready
[last_index
]));
11656 fprintf (file
, "ready list ooo attributes - sched state: %d\n",
11659 for (i
= last_index
; i
>= 0; i
--)
11661 if (recog_memoized (ready
[i
]) < 0)
11663 fprintf (file
, "insn %d score: %d: ", INSN_UID (ready
[i
]),
11664 s390_sched_score (ready
[i
]));
11665 #define PRINT_OOO_ATTR(ATTR) fprintf (file, "%s ", get_attr_##ATTR (ready[i]) ? #ATTR : "!" #ATTR);
11666 PRINT_OOO_ATTR (ooo_cracked
);
11667 PRINT_OOO_ATTR (ooo_expanded
);
11668 PRINT_OOO_ATTR (ooo_endgroup
);
11669 PRINT_OOO_ATTR (ooo_groupalone
);
11670 #undef PRINT_OOO_ATTR
11671 fprintf (file
, "\n");
11676 return s390_issue_rate ();
11680 /* This function is called via hook TARGET_SCHED_VARIABLE_ISSUE after
11681 the scheduler has issued INSN. It stores the last issued insn into
11682 last_scheduled_insn in order to make it available for
11683 s390_sched_reorder. */
11685 s390_sched_variable_issue (FILE *file
, int verbose
, rtx_insn
*insn
, int more
)
11687 last_scheduled_insn
= insn
;
11689 if (s390_tune
== PROCESSOR_2827_ZEC12
11690 && reload_completed
11691 && recog_memoized (insn
) >= 0)
11693 unsigned int mask
= s390_get_sched_attrmask (insn
);
11695 if ((mask
& S390_OOO_SCHED_ATTR_MASK_CRACKED
) != 0
11696 || (mask
& S390_OOO_SCHED_ATTR_MASK_EXPANDED
) != 0)
11697 s390_sched_state
= S390_OOO_SCHED_STATE_CRACKED
;
11698 else if ((mask
& S390_OOO_SCHED_ATTR_MASK_ENDGROUP
) != 0
11699 || (mask
& S390_OOO_SCHED_ATTR_MASK_GROUPALONE
) != 0)
11700 s390_sched_state
= S390_OOO_SCHED_STATE_NORMAL
;
11703 /* Only normal insns are left (mask == 0). */
11704 switch (s390_sched_state
)
11709 case S390_OOO_SCHED_STATE_NORMAL
:
11710 if (s390_sched_state
== S390_OOO_SCHED_STATE_NORMAL
)
11711 s390_sched_state
= 1;
11713 s390_sched_state
++;
11716 case S390_OOO_SCHED_STATE_CRACKED
:
11717 s390_sched_state
= S390_OOO_SCHED_STATE_NORMAL
;
11723 fprintf (file
, "insn %d: ", INSN_UID (insn
));
11724 #define PRINT_OOO_ATTR(ATTR) \
11725 fprintf (file, "%s ", get_attr_##ATTR (insn) ? #ATTR : "");
11726 PRINT_OOO_ATTR (ooo_cracked
);
11727 PRINT_OOO_ATTR (ooo_expanded
);
11728 PRINT_OOO_ATTR (ooo_endgroup
);
11729 PRINT_OOO_ATTR (ooo_groupalone
);
11730 #undef PRINT_OOO_ATTR
11731 fprintf (file
, "\n");
11732 fprintf (file
, "sched state: %d\n", s390_sched_state
);
11736 if (GET_CODE (PATTERN (insn
)) != USE
11737 && GET_CODE (PATTERN (insn
)) != CLOBBER
)
11744 s390_sched_init (FILE *file ATTRIBUTE_UNUSED
,
11745 int verbose ATTRIBUTE_UNUSED
,
11746 int max_ready ATTRIBUTE_UNUSED
)
11748 last_scheduled_insn
= NULL
;
11749 s390_sched_state
= 0;
11752 /* This function checks the whole of insn X for memory references. The
11753 function always returns zero because the framework it is called
11754 from would stop recursively analyzing the insn upon a return value
11755 other than zero. The real result of this function is updating
11756 counter variable MEM_COUNT. */
11758 check_dpu (rtx
*x
, unsigned *mem_count
)
11760 if (*x
!= NULL_RTX
&& MEM_P (*x
))
11765 /* This target hook implementation for TARGET_LOOP_UNROLL_ADJUST calculates
11766 a new number struct loop *loop should be unrolled if tuned for cpus with
11767 a built-in stride prefetcher.
11768 The loop is analyzed for memory accesses by calling check_dpu for
11769 each rtx of the loop. Depending on the loop_depth and the amount of
11770 memory accesses a new number <=nunroll is returned to improve the
11771 behaviour of the hardware prefetch unit. */
11773 s390_loop_unroll_adjust (unsigned nunroll
, struct loop
*loop
)
11778 unsigned mem_count
= 0;
11780 if (s390_tune
!= PROCESSOR_2097_Z10
11781 && s390_tune
!= PROCESSOR_2817_Z196
11782 && s390_tune
!= PROCESSOR_2827_ZEC12
)
11785 /* Count the number of memory references within the loop body. */
11786 bbs
= get_loop_body (loop
);
11787 for (i
= 0; i
< loop
->num_nodes
; i
++)
11789 for (insn
= BB_HEAD (bbs
[i
]); insn
!= BB_END (bbs
[i
]); insn
= NEXT_INSN (insn
))
11790 if (INSN_P (insn
) && INSN_CODE (insn
) != -1)
11791 for_each_rtx_in_insn (&insn
, (rtx_function
) check_dpu
, &mem_count
);
11795 /* Prevent division by zero, and we do not need to adjust nunroll in this case. */
11796 if (mem_count
== 0)
11799 switch (loop_depth(loop
))
11802 return MIN (nunroll
, 28 / mem_count
);
11804 return MIN (nunroll
, 22 / mem_count
);
11806 return MIN (nunroll
, 16 / mem_count
);
11811 s390_option_override (void)
11814 cl_deferred_option
*opt
;
11815 vec
<cl_deferred_option
> *v
=
11816 (vec
<cl_deferred_option
> *) s390_deferred_options
;
11819 FOR_EACH_VEC_ELT (*v
, i
, opt
)
11821 switch (opt
->opt_index
)
11823 case OPT_mhotpatch
:
11824 s390_hotpatch_trampoline_halfwords
= (opt
->value
) ?
11825 s390_hotpatch_trampoline_halfwords_default
: -1;
11827 case OPT_mhotpatch_
:
11831 val
= integral_argument (opt
->arg
);
11834 /* argument is not a plain number */
11835 error ("argument to %qs should be a non-negative integer",
11839 else if (val
> s390_hotpatch_trampoline_halfwords_max
)
11841 error ("argument to %qs is too large (max. %d)",
11842 "-mhotpatch=", s390_hotpatch_trampoline_halfwords_max
);
11845 s390_hotpatch_trampoline_halfwords
= val
;
11849 gcc_unreachable ();
11853 /* Set up function hooks. */
11854 init_machine_status
= s390_init_machine_status
;
11856 /* Architecture mode defaults according to ABI. */
11857 if (!(target_flags_explicit
& MASK_ZARCH
))
11860 target_flags
|= MASK_ZARCH
;
11862 target_flags
&= ~MASK_ZARCH
;
11865 /* Set the march default in case it hasn't been specified on
11867 if (s390_arch
== PROCESSOR_max
)
11869 s390_arch_string
= TARGET_ZARCH
? "z900" : "g5";
11870 s390_arch
= TARGET_ZARCH
? PROCESSOR_2064_Z900
: PROCESSOR_9672_G5
;
11871 s390_arch_flags
= processor_flags_table
[(int)s390_arch
];
11874 /* Determine processor to tune for. */
11875 if (s390_tune
== PROCESSOR_max
)
11877 s390_tune
= s390_arch
;
11878 s390_tune_flags
= s390_arch_flags
;
11881 /* Sanity checks. */
11882 if (TARGET_ZARCH
&& !TARGET_CPU_ZARCH
)
11883 error ("z/Architecture mode not supported on %s", s390_arch_string
);
11884 if (TARGET_64BIT
&& !TARGET_ZARCH
)
11885 error ("64-bit ABI not supported in ESA/390 mode");
11887 /* Use hardware DFP if available and not explicitly disabled by
11888 user. E.g. with -m31 -march=z10 -mzarch */
11889 if (!(target_flags_explicit
& MASK_HARD_DFP
) && TARGET_DFP
)
11890 target_flags
|= MASK_HARD_DFP
;
11892 /* Enable hardware transactions if available and not explicitly
11893 disabled by user. E.g. with -m31 -march=zEC12 -mzarch */
11894 if (!(target_flags_explicit
& MASK_OPT_HTM
) && TARGET_CPU_HTM
&& TARGET_ZARCH
)
11895 target_flags
|= MASK_OPT_HTM
;
11897 if (TARGET_HARD_DFP
&& !TARGET_DFP
)
11899 if (target_flags_explicit
& MASK_HARD_DFP
)
11901 if (!TARGET_CPU_DFP
)
11902 error ("hardware decimal floating point instructions"
11903 " not available on %s", s390_arch_string
);
11905 error ("hardware decimal floating point instructions"
11906 " not available in ESA/390 mode");
11909 target_flags
&= ~MASK_HARD_DFP
;
11912 if ((target_flags_explicit
& MASK_SOFT_FLOAT
) && TARGET_SOFT_FLOAT
)
11914 if ((target_flags_explicit
& MASK_HARD_DFP
) && TARGET_HARD_DFP
)
11915 error ("-mhard-dfp can%'t be used in conjunction with -msoft-float");
11917 target_flags
&= ~MASK_HARD_DFP
;
11920 /* Set processor cost function. */
11923 case PROCESSOR_2084_Z990
:
11924 s390_cost
= &z990_cost
;
11926 case PROCESSOR_2094_Z9_109
:
11927 s390_cost
= &z9_109_cost
;
11929 case PROCESSOR_2097_Z10
:
11930 s390_cost
= &z10_cost
;
11932 case PROCESSOR_2817_Z196
:
11933 s390_cost
= &z196_cost
;
11935 case PROCESSOR_2827_ZEC12
:
11936 s390_cost
= &zEC12_cost
;
11939 s390_cost
= &z900_cost
;
11942 if (TARGET_BACKCHAIN
&& TARGET_PACKED_STACK
&& TARGET_HARD_FLOAT
)
11943 error ("-mbackchain -mpacked-stack -mhard-float are not supported "
11946 if (s390_stack_size
)
11948 if (s390_stack_guard
>= s390_stack_size
)
11949 error ("stack size must be greater than the stack guard value");
11950 else if (s390_stack_size
> 1 << 16)
11951 error ("stack size must not be greater than 64k");
11953 else if (s390_stack_guard
)
11954 error ("-mstack-guard implies use of -mstack-size");
11956 #ifdef TARGET_DEFAULT_LONG_DOUBLE_128
11957 if (!(target_flags_explicit
& MASK_LONG_DOUBLE_128
))
11958 target_flags
|= MASK_LONG_DOUBLE_128
;
11961 if (s390_tune
== PROCESSOR_2097_Z10
11962 || s390_tune
== PROCESSOR_2817_Z196
11963 || s390_tune
== PROCESSOR_2827_ZEC12
)
11965 maybe_set_param_value (PARAM_MAX_UNROLLED_INSNS
, 100,
11966 global_options
.x_param_values
,
11967 global_options_set
.x_param_values
);
11968 maybe_set_param_value (PARAM_MAX_UNROLL_TIMES
, 32,
11969 global_options
.x_param_values
,
11970 global_options_set
.x_param_values
);
11971 maybe_set_param_value (PARAM_MAX_COMPLETELY_PEELED_INSNS
, 2000,
11972 global_options
.x_param_values
,
11973 global_options_set
.x_param_values
);
11974 maybe_set_param_value (PARAM_MAX_COMPLETELY_PEEL_TIMES
, 64,
11975 global_options
.x_param_values
,
11976 global_options_set
.x_param_values
);
11979 maybe_set_param_value (PARAM_MAX_PENDING_LIST_LENGTH
, 256,
11980 global_options
.x_param_values
,
11981 global_options_set
.x_param_values
);
11982 /* values for loop prefetching */
11983 maybe_set_param_value (PARAM_L1_CACHE_LINE_SIZE
, 256,
11984 global_options
.x_param_values
,
11985 global_options_set
.x_param_values
);
11986 maybe_set_param_value (PARAM_L1_CACHE_SIZE
, 128,
11987 global_options
.x_param_values
,
11988 global_options_set
.x_param_values
);
11989 /* s390 has more than 2 levels and the size is much larger. Since
11990 we are always running virtualized assume that we only get a small
11991 part of the caches above l1. */
11992 maybe_set_param_value (PARAM_L2_CACHE_SIZE
, 1500,
11993 global_options
.x_param_values
,
11994 global_options_set
.x_param_values
);
11995 maybe_set_param_value (PARAM_PREFETCH_MIN_INSN_TO_MEM_RATIO
, 2,
11996 global_options
.x_param_values
,
11997 global_options_set
.x_param_values
);
11998 maybe_set_param_value (PARAM_SIMULTANEOUS_PREFETCHES
, 6,
11999 global_options
.x_param_values
,
12000 global_options_set
.x_param_values
);
12002 /* This cannot reside in s390_option_optimization_table since HAVE_prefetch
12003 requires the arch flags to be evaluated already. Since prefetching
12004 is beneficial on s390, we enable it if available. */
12005 if (flag_prefetch_loop_arrays
< 0 && HAVE_prefetch
&& optimize
>= 3)
12006 flag_prefetch_loop_arrays
= 1;
12008 /* Use the alternative scheduling-pressure algorithm by default. */
12009 maybe_set_param_value (PARAM_SCHED_PRESSURE_ALGORITHM
, 2,
12010 global_options
.x_param_values
,
12011 global_options_set
.x_param_values
);
12015 /* Don't emit DWARF3/4 unless specifically selected. The TPF
12016 debuggers do not yet support DWARF 3/4. */
12017 if (!global_options_set
.x_dwarf_strict
)
12019 if (!global_options_set
.x_dwarf_version
)
12023 /* Register a target-specific optimization-and-lowering pass
12024 to run immediately before prologue and epilogue generation.
12026 Registering the pass must be done at start up. It's
12027 convenient to do it here. */
12028 opt_pass
*new_pass
= new pass_s390_early_mach (g
);
12029 struct register_pass_info insert_pass_s390_early_mach
=
12031 new_pass
, /* pass */
12032 "pro_and_epilogue", /* reference_pass_name */
12033 1, /* ref_pass_instance_number */
12034 PASS_POS_INSERT_BEFORE
/* po_op */
12036 register_pass (&insert_pass_s390_early_mach
);
12039 /* Initialize GCC target structure. */
12041 #undef TARGET_ASM_ALIGNED_HI_OP
12042 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
12043 #undef TARGET_ASM_ALIGNED_DI_OP
12044 #define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
12045 #undef TARGET_ASM_INTEGER
12046 #define TARGET_ASM_INTEGER s390_assemble_integer
12048 #undef TARGET_ASM_OPEN_PAREN
12049 #define TARGET_ASM_OPEN_PAREN ""
12051 #undef TARGET_ASM_CLOSE_PAREN
12052 #define TARGET_ASM_CLOSE_PAREN ""
12054 #undef TARGET_OPTION_OVERRIDE
12055 #define TARGET_OPTION_OVERRIDE s390_option_override
12057 #undef TARGET_ENCODE_SECTION_INFO
12058 #define TARGET_ENCODE_SECTION_INFO s390_encode_section_info
12060 #undef TARGET_SCALAR_MODE_SUPPORTED_P
12061 #define TARGET_SCALAR_MODE_SUPPORTED_P s390_scalar_mode_supported_p
12064 #undef TARGET_HAVE_TLS
12065 #define TARGET_HAVE_TLS true
12067 #undef TARGET_CANNOT_FORCE_CONST_MEM
12068 #define TARGET_CANNOT_FORCE_CONST_MEM s390_cannot_force_const_mem
12070 #undef TARGET_DELEGITIMIZE_ADDRESS
12071 #define TARGET_DELEGITIMIZE_ADDRESS s390_delegitimize_address
12073 #undef TARGET_LEGITIMIZE_ADDRESS
12074 #define TARGET_LEGITIMIZE_ADDRESS s390_legitimize_address
12076 #undef TARGET_RETURN_IN_MEMORY
12077 #define TARGET_RETURN_IN_MEMORY s390_return_in_memory
12079 #undef TARGET_INIT_BUILTINS
12080 #define TARGET_INIT_BUILTINS s390_init_builtins
12081 #undef TARGET_EXPAND_BUILTIN
12082 #define TARGET_EXPAND_BUILTIN s390_expand_builtin
12084 #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA
12085 #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA s390_output_addr_const_extra
12087 #undef TARGET_ASM_OUTPUT_MI_THUNK
12088 #define TARGET_ASM_OUTPUT_MI_THUNK s390_output_mi_thunk
12089 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
12090 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_const_tree_hwi_hwi_const_tree_true
12092 #undef TARGET_SCHED_ADJUST_PRIORITY
12093 #define TARGET_SCHED_ADJUST_PRIORITY s390_adjust_priority
12094 #undef TARGET_SCHED_ISSUE_RATE
12095 #define TARGET_SCHED_ISSUE_RATE s390_issue_rate
12096 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
12097 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD s390_first_cycle_multipass_dfa_lookahead
12099 #undef TARGET_SCHED_VARIABLE_ISSUE
12100 #define TARGET_SCHED_VARIABLE_ISSUE s390_sched_variable_issue
12101 #undef TARGET_SCHED_REORDER
12102 #define TARGET_SCHED_REORDER s390_sched_reorder
12103 #undef TARGET_SCHED_INIT
12104 #define TARGET_SCHED_INIT s390_sched_init
12106 #undef TARGET_CANNOT_COPY_INSN_P
12107 #define TARGET_CANNOT_COPY_INSN_P s390_cannot_copy_insn_p
12108 #undef TARGET_RTX_COSTS
12109 #define TARGET_RTX_COSTS s390_rtx_costs
12110 #undef TARGET_ADDRESS_COST
12111 #define TARGET_ADDRESS_COST s390_address_cost
12112 #undef TARGET_REGISTER_MOVE_COST
12113 #define TARGET_REGISTER_MOVE_COST s390_register_move_cost
12114 #undef TARGET_MEMORY_MOVE_COST
12115 #define TARGET_MEMORY_MOVE_COST s390_memory_move_cost
12117 #undef TARGET_MACHINE_DEPENDENT_REORG
12118 #define TARGET_MACHINE_DEPENDENT_REORG s390_reorg
12120 #undef TARGET_VALID_POINTER_MODE
12121 #define TARGET_VALID_POINTER_MODE s390_valid_pointer_mode
12123 #undef TARGET_BUILD_BUILTIN_VA_LIST
12124 #define TARGET_BUILD_BUILTIN_VA_LIST s390_build_builtin_va_list
12125 #undef TARGET_EXPAND_BUILTIN_VA_START
12126 #define TARGET_EXPAND_BUILTIN_VA_START s390_va_start
12127 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
12128 #define TARGET_GIMPLIFY_VA_ARG_EXPR s390_gimplify_va_arg
12130 #undef TARGET_PROMOTE_FUNCTION_MODE
12131 #define TARGET_PROMOTE_FUNCTION_MODE s390_promote_function_mode
12132 #undef TARGET_PASS_BY_REFERENCE
12133 #define TARGET_PASS_BY_REFERENCE s390_pass_by_reference
12135 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
12136 #define TARGET_FUNCTION_OK_FOR_SIBCALL s390_function_ok_for_sibcall
12137 #undef TARGET_FUNCTION_ARG
12138 #define TARGET_FUNCTION_ARG s390_function_arg
12139 #undef TARGET_FUNCTION_ARG_ADVANCE
12140 #define TARGET_FUNCTION_ARG_ADVANCE s390_function_arg_advance
12141 #undef TARGET_FUNCTION_VALUE
12142 #define TARGET_FUNCTION_VALUE s390_function_value
12143 #undef TARGET_LIBCALL_VALUE
12144 #define TARGET_LIBCALL_VALUE s390_libcall_value
12146 #undef TARGET_KEEP_LEAF_WHEN_PROFILED
12147 #define TARGET_KEEP_LEAF_WHEN_PROFILED s390_keep_leaf_when_profiled
12149 #undef TARGET_FIXED_CONDITION_CODE_REGS
12150 #define TARGET_FIXED_CONDITION_CODE_REGS s390_fixed_condition_code_regs
12152 #undef TARGET_CC_MODES_COMPATIBLE
12153 #define TARGET_CC_MODES_COMPATIBLE s390_cc_modes_compatible
12155 #undef TARGET_INVALID_WITHIN_DOLOOP
12156 #define TARGET_INVALID_WITHIN_DOLOOP hook_constcharptr_const_rtx_insn_null
12159 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
12160 #define TARGET_ASM_OUTPUT_DWARF_DTPREL s390_output_dwarf_dtprel
12163 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
12164 #undef TARGET_MANGLE_TYPE
12165 #define TARGET_MANGLE_TYPE s390_mangle_type
12168 #undef TARGET_SCALAR_MODE_SUPPORTED_P
12169 #define TARGET_SCALAR_MODE_SUPPORTED_P s390_scalar_mode_supported_p
12171 #undef TARGET_PREFERRED_RELOAD_CLASS
12172 #define TARGET_PREFERRED_RELOAD_CLASS s390_preferred_reload_class
12174 #undef TARGET_SECONDARY_RELOAD
12175 #define TARGET_SECONDARY_RELOAD s390_secondary_reload
12177 #undef TARGET_LIBGCC_CMP_RETURN_MODE
12178 #define TARGET_LIBGCC_CMP_RETURN_MODE s390_libgcc_cmp_return_mode
12180 #undef TARGET_LIBGCC_SHIFT_COUNT_MODE
12181 #define TARGET_LIBGCC_SHIFT_COUNT_MODE s390_libgcc_shift_count_mode
12183 #undef TARGET_LEGITIMATE_ADDRESS_P
12184 #define TARGET_LEGITIMATE_ADDRESS_P s390_legitimate_address_p
12186 #undef TARGET_LEGITIMATE_CONSTANT_P
12187 #define TARGET_LEGITIMATE_CONSTANT_P s390_legitimate_constant_p
12189 #undef TARGET_LRA_P
12190 #define TARGET_LRA_P s390_lra_p
12192 #undef TARGET_CAN_ELIMINATE
12193 #define TARGET_CAN_ELIMINATE s390_can_eliminate
12195 #undef TARGET_CONDITIONAL_REGISTER_USAGE
12196 #define TARGET_CONDITIONAL_REGISTER_USAGE s390_conditional_register_usage
12198 #undef TARGET_LOOP_UNROLL_ADJUST
12199 #define TARGET_LOOP_UNROLL_ADJUST s390_loop_unroll_adjust
12201 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
12202 #define TARGET_ASM_TRAMPOLINE_TEMPLATE s390_asm_trampoline_template
12203 #undef TARGET_TRAMPOLINE_INIT
12204 #define TARGET_TRAMPOLINE_INIT s390_trampoline_init
12206 #undef TARGET_UNWIND_WORD_MODE
12207 #define TARGET_UNWIND_WORD_MODE s390_unwind_word_mode
12209 #undef TARGET_CANONICALIZE_COMPARISON
12210 #define TARGET_CANONICALIZE_COMPARISON s390_canonicalize_comparison
12212 #undef TARGET_HARD_REGNO_SCRATCH_OK
12213 #define TARGET_HARD_REGNO_SCRATCH_OK s390_hard_regno_scratch_ok
12215 #undef TARGET_ATTRIBUTE_TABLE
12216 #define TARGET_ATTRIBUTE_TABLE s390_attribute_table
12218 #undef TARGET_CAN_INLINE_P
12219 #define TARGET_CAN_INLINE_P s390_can_inline_p
12221 #undef TARGET_SET_UP_BY_PROLOGUE
12222 #define TARGET_SET_UP_BY_PROLOGUE s300_set_up_by_prologue
12224 struct gcc_target targetm
= TARGET_INITIALIZER
;
12226 #include "gt-s390.h"