1 /* Subroutines used for code generation on IBM S/390 and zSeries
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
3 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
4 Contributed by Hartmut Penner (hpenner@de.ibm.com) and
5 Ulrich Weigand (uweigand@de.ibm.com) and
6 Andreas Krebbel (Andreas.Krebbel@de.ibm.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
26 #include "coretypes.h"
32 #include "hard-reg-set.h"
33 #include "insn-config.h"
34 #include "conditions.h"
36 #include "insn-attr.h"
43 #include "diagnostic-core.h"
44 #include "basic-block.h"
45 #include "integrate.h"
48 #include "target-def.h"
50 #include "langhooks.h"
58 /* Define the specific costs for a given cpu. */
60 struct processor_costs
63 const int m
; /* cost of an M instruction. */
64 const int mghi
; /* cost of an MGHI instruction. */
65 const int mh
; /* cost of an MH instruction. */
66 const int mhi
; /* cost of an MHI instruction. */
67 const int ml
; /* cost of an ML instruction. */
68 const int mr
; /* cost of an MR instruction. */
69 const int ms
; /* cost of an MS instruction. */
70 const int msg
; /* cost of an MSG instruction. */
71 const int msgf
; /* cost of an MSGF instruction. */
72 const int msgfr
; /* cost of an MSGFR instruction. */
73 const int msgr
; /* cost of an MSGR instruction. */
74 const int msr
; /* cost of an MSR instruction. */
75 const int mult_df
; /* cost of multiplication in DFmode. */
78 const int sqxbr
; /* cost of square root in TFmode. */
79 const int sqdbr
; /* cost of square root in DFmode. */
80 const int sqebr
; /* cost of square root in SFmode. */
81 /* multiply and add */
82 const int madbr
; /* cost of multiply and add in DFmode. */
83 const int maebr
; /* cost of multiply and add in SFmode. */
95 const struct processor_costs
*s390_cost
;
98 struct processor_costs z900_cost
=
100 COSTS_N_INSNS (5), /* M */
101 COSTS_N_INSNS (10), /* MGHI */
102 COSTS_N_INSNS (5), /* MH */
103 COSTS_N_INSNS (4), /* MHI */
104 COSTS_N_INSNS (5), /* ML */
105 COSTS_N_INSNS (5), /* MR */
106 COSTS_N_INSNS (4), /* MS */
107 COSTS_N_INSNS (15), /* MSG */
108 COSTS_N_INSNS (7), /* MSGF */
109 COSTS_N_INSNS (7), /* MSGFR */
110 COSTS_N_INSNS (10), /* MSGR */
111 COSTS_N_INSNS (4), /* MSR */
112 COSTS_N_INSNS (7), /* multiplication in DFmode */
113 COSTS_N_INSNS (13), /* MXBR */
114 COSTS_N_INSNS (136), /* SQXBR */
115 COSTS_N_INSNS (44), /* SQDBR */
116 COSTS_N_INSNS (35), /* SQEBR */
117 COSTS_N_INSNS (18), /* MADBR */
118 COSTS_N_INSNS (13), /* MAEBR */
119 COSTS_N_INSNS (134), /* DXBR */
120 COSTS_N_INSNS (30), /* DDBR */
121 COSTS_N_INSNS (27), /* DEBR */
122 COSTS_N_INSNS (220), /* DLGR */
123 COSTS_N_INSNS (34), /* DLR */
124 COSTS_N_INSNS (34), /* DR */
125 COSTS_N_INSNS (32), /* DSGFR */
126 COSTS_N_INSNS (32), /* DSGR */
130 struct processor_costs z990_cost
=
132 COSTS_N_INSNS (4), /* M */
133 COSTS_N_INSNS (2), /* MGHI */
134 COSTS_N_INSNS (2), /* MH */
135 COSTS_N_INSNS (2), /* MHI */
136 COSTS_N_INSNS (4), /* ML */
137 COSTS_N_INSNS (4), /* MR */
138 COSTS_N_INSNS (5), /* MS */
139 COSTS_N_INSNS (6), /* MSG */
140 COSTS_N_INSNS (4), /* MSGF */
141 COSTS_N_INSNS (4), /* MSGFR */
142 COSTS_N_INSNS (4), /* MSGR */
143 COSTS_N_INSNS (4), /* MSR */
144 COSTS_N_INSNS (1), /* multiplication in DFmode */
145 COSTS_N_INSNS (28), /* MXBR */
146 COSTS_N_INSNS (130), /* SQXBR */
147 COSTS_N_INSNS (66), /* SQDBR */
148 COSTS_N_INSNS (38), /* SQEBR */
149 COSTS_N_INSNS (1), /* MADBR */
150 COSTS_N_INSNS (1), /* MAEBR */
151 COSTS_N_INSNS (60), /* DXBR */
152 COSTS_N_INSNS (40), /* DDBR */
153 COSTS_N_INSNS (26), /* DEBR */
154 COSTS_N_INSNS (176), /* DLGR */
155 COSTS_N_INSNS (31), /* DLR */
156 COSTS_N_INSNS (31), /* DR */
157 COSTS_N_INSNS (31), /* DSGFR */
158 COSTS_N_INSNS (31), /* DSGR */
162 struct processor_costs z9_109_cost
=
164 COSTS_N_INSNS (4), /* M */
165 COSTS_N_INSNS (2), /* MGHI */
166 COSTS_N_INSNS (2), /* MH */
167 COSTS_N_INSNS (2), /* MHI */
168 COSTS_N_INSNS (4), /* ML */
169 COSTS_N_INSNS (4), /* MR */
170 COSTS_N_INSNS (5), /* MS */
171 COSTS_N_INSNS (6), /* MSG */
172 COSTS_N_INSNS (4), /* MSGF */
173 COSTS_N_INSNS (4), /* MSGFR */
174 COSTS_N_INSNS (4), /* MSGR */
175 COSTS_N_INSNS (4), /* MSR */
176 COSTS_N_INSNS (1), /* multiplication in DFmode */
177 COSTS_N_INSNS (28), /* MXBR */
178 COSTS_N_INSNS (130), /* SQXBR */
179 COSTS_N_INSNS (66), /* SQDBR */
180 COSTS_N_INSNS (38), /* SQEBR */
181 COSTS_N_INSNS (1), /* MADBR */
182 COSTS_N_INSNS (1), /* MAEBR */
183 COSTS_N_INSNS (60), /* DXBR */
184 COSTS_N_INSNS (40), /* DDBR */
185 COSTS_N_INSNS (26), /* DEBR */
186 COSTS_N_INSNS (30), /* DLGR */
187 COSTS_N_INSNS (23), /* DLR */
188 COSTS_N_INSNS (23), /* DR */
189 COSTS_N_INSNS (24), /* DSGFR */
190 COSTS_N_INSNS (24), /* DSGR */
194 struct processor_costs z10_cost
=
196 COSTS_N_INSNS (10), /* M */
197 COSTS_N_INSNS (10), /* MGHI */
198 COSTS_N_INSNS (10), /* MH */
199 COSTS_N_INSNS (10), /* MHI */
200 COSTS_N_INSNS (10), /* ML */
201 COSTS_N_INSNS (10), /* MR */
202 COSTS_N_INSNS (10), /* MS */
203 COSTS_N_INSNS (10), /* MSG */
204 COSTS_N_INSNS (10), /* MSGF */
205 COSTS_N_INSNS (10), /* MSGFR */
206 COSTS_N_INSNS (10), /* MSGR */
207 COSTS_N_INSNS (10), /* MSR */
208 COSTS_N_INSNS (1) , /* multiplication in DFmode */
209 COSTS_N_INSNS (50), /* MXBR */
210 COSTS_N_INSNS (120), /* SQXBR */
211 COSTS_N_INSNS (52), /* SQDBR */
212 COSTS_N_INSNS (38), /* SQEBR */
213 COSTS_N_INSNS (1), /* MADBR */
214 COSTS_N_INSNS (1), /* MAEBR */
215 COSTS_N_INSNS (111), /* DXBR */
216 COSTS_N_INSNS (39), /* DDBR */
217 COSTS_N_INSNS (32), /* DEBR */
218 COSTS_N_INSNS (160), /* DLGR */
219 COSTS_N_INSNS (71), /* DLR */
220 COSTS_N_INSNS (71), /* DR */
221 COSTS_N_INSNS (71), /* DSGFR */
222 COSTS_N_INSNS (71), /* DSGR */
226 struct processor_costs z196_cost
=
228 COSTS_N_INSNS (7), /* M */
229 COSTS_N_INSNS (5), /* MGHI */
230 COSTS_N_INSNS (5), /* MH */
231 COSTS_N_INSNS (5), /* MHI */
232 COSTS_N_INSNS (7), /* ML */
233 COSTS_N_INSNS (7), /* MR */
234 COSTS_N_INSNS (6), /* MS */
235 COSTS_N_INSNS (8), /* MSG */
236 COSTS_N_INSNS (6), /* MSGF */
237 COSTS_N_INSNS (6), /* MSGFR */
238 COSTS_N_INSNS (8), /* MSGR */
239 COSTS_N_INSNS (6), /* MSR */
240 COSTS_N_INSNS (1) , /* multiplication in DFmode */
241 COSTS_N_INSNS (40), /* MXBR B+40 */
242 COSTS_N_INSNS (100), /* SQXBR B+100 */
243 COSTS_N_INSNS (42), /* SQDBR B+42 */
244 COSTS_N_INSNS (28), /* SQEBR B+28 */
245 COSTS_N_INSNS (1), /* MADBR B */
246 COSTS_N_INSNS (1), /* MAEBR B */
247 COSTS_N_INSNS (101), /* DXBR B+101 */
248 COSTS_N_INSNS (29), /* DDBR */
249 COSTS_N_INSNS (22), /* DEBR */
250 COSTS_N_INSNS (160), /* DLGR cracked */
251 COSTS_N_INSNS (160), /* DLR cracked */
252 COSTS_N_INSNS (160), /* DR expanded */
253 COSTS_N_INSNS (160), /* DSGFR cracked */
254 COSTS_N_INSNS (160), /* DSGR cracked */
257 extern int reload_completed
;
259 /* Kept up to date using the SCHED_VARIABLE_ISSUE hook. */
260 static rtx last_scheduled_insn
;
262 /* Structure used to hold the components of a S/390 memory
263 address. A legitimate address on S/390 is of the general
265 base + index + displacement
266 where any of the components is optional.
268 base and index are registers of the class ADDR_REGS,
269 displacement is an unsigned 12-bit immediate constant. */
280 /* Which cpu are we tuning for. */
281 enum processor_type s390_tune
= PROCESSOR_max
;
283 /* Which instruction set architecture to use. */
284 enum processor_type s390_arch
;
287 HOST_WIDE_INT s390_warn_framesize
= 0;
288 HOST_WIDE_INT s390_stack_size
= 0;
289 HOST_WIDE_INT s390_stack_guard
= 0;
291 /* The following structure is embedded in the machine
292 specific part of struct function. */
294 struct GTY (()) s390_frame_layout
296 /* Offset within stack frame. */
297 HOST_WIDE_INT gprs_offset
;
298 HOST_WIDE_INT f0_offset
;
299 HOST_WIDE_INT f4_offset
;
300 HOST_WIDE_INT f8_offset
;
301 HOST_WIDE_INT backchain_offset
;
303 /* Number of first and last gpr where slots in the register
304 save area are reserved for. */
305 int first_save_gpr_slot
;
306 int last_save_gpr_slot
;
308 /* Number of first and last gpr to be saved, restored. */
310 int first_restore_gpr
;
312 int last_restore_gpr
;
314 /* Bits standing for floating point registers. Set, if the
315 respective register has to be saved. Starting with reg 16 (f0)
316 at the rightmost bit.
317 Bit 15 - 8 7 6 5 4 3 2 1 0
318 fpr 15 - 8 7 5 3 1 6 4 2 0
319 reg 31 - 24 23 22 21 20 19 18 17 16 */
320 unsigned int fpr_bitmap
;
322 /* Number of floating point registers f8-f15 which must be saved. */
325 /* Set if return address needs to be saved.
326 This flag is set by s390_return_addr_rtx if it could not use
327 the initial value of r14 and therefore depends on r14 saved
329 bool save_return_addr_p
;
331 /* Size of stack frame. */
332 HOST_WIDE_INT frame_size
;
335 /* Define the structure for the machine field in struct function. */
337 struct GTY(()) machine_function
339 struct s390_frame_layout frame_layout
;
341 /* Literal pool base register. */
344 /* True if we may need to perform branch splitting. */
345 bool split_branches_pending_p
;
347 /* Some local-dynamic TLS symbol name. */
348 const char *some_ld_name
;
350 bool has_landing_pad_p
;
353 /* Few accessor macros for struct cfun->machine->s390_frame_layout. */
355 #define cfun_frame_layout (cfun->machine->frame_layout)
356 #define cfun_save_high_fprs_p (!!cfun_frame_layout.high_fprs)
357 #define cfun_gprs_save_area_size ((cfun_frame_layout.last_save_gpr_slot - \
358 cfun_frame_layout.first_save_gpr_slot + 1) * UNITS_PER_LONG)
359 #define cfun_set_fpr_bit(BITNUM) (cfun->machine->frame_layout.fpr_bitmap |= \
361 #define cfun_fpr_bit_p(BITNUM) (!!(cfun->machine->frame_layout.fpr_bitmap & \
364 /* Number of GPRs and FPRs used for argument passing. */
365 #define GP_ARG_NUM_REG 5
366 #define FP_ARG_NUM_REG (TARGET_64BIT? 4 : 2)
368 /* A couple of shortcuts. */
369 #define CONST_OK_FOR_J(x) \
370 CONST_OK_FOR_CONSTRAINT_P((x), 'J', "J")
371 #define CONST_OK_FOR_K(x) \
372 CONST_OK_FOR_CONSTRAINT_P((x), 'K', "K")
373 #define CONST_OK_FOR_Os(x) \
374 CONST_OK_FOR_CONSTRAINT_P((x), 'O', "Os")
375 #define CONST_OK_FOR_Op(x) \
376 CONST_OK_FOR_CONSTRAINT_P((x), 'O', "Op")
377 #define CONST_OK_FOR_On(x) \
378 CONST_OK_FOR_CONSTRAINT_P((x), 'O', "On")
380 #define REGNO_PAIR_OK(REGNO, MODE) \
381 (HARD_REGNO_NREGS ((REGNO), (MODE)) == 1 || !((REGNO) & 1))
383 /* That's the read ahead of the dynamic branch prediction unit in
384 bytes on a z10 (or higher) CPU. */
385 #define PREDICT_DISTANCE (TARGET_Z10 ? 384 : 2048)
387 static enum machine_mode
388 s390_libgcc_cmp_return_mode (void)
390 return TARGET_64BIT
? DImode
: SImode
;
393 static enum machine_mode
394 s390_libgcc_shift_count_mode (void)
396 return TARGET_64BIT
? DImode
: SImode
;
399 static enum machine_mode
400 s390_unwind_word_mode (void)
402 return TARGET_64BIT
? DImode
: SImode
;
405 /* Return true if the back end supports mode MODE. */
407 s390_scalar_mode_supported_p (enum machine_mode mode
)
409 /* In contrast to the default implementation reject TImode constants on 31bit
410 TARGET_ZARCH for ABI compliance. */
411 if (!TARGET_64BIT
&& TARGET_ZARCH
&& mode
== TImode
)
414 if (DECIMAL_FLOAT_MODE_P (mode
))
415 return default_decimal_float_supported_p ();
417 return default_scalar_mode_supported_p (mode
);
420 /* Set the has_landing_pad_p flag in struct machine_function to VALUE. */
423 s390_set_has_landing_pad_p (bool value
)
425 cfun
->machine
->has_landing_pad_p
= value
;
428 /* If two condition code modes are compatible, return a condition code
429 mode which is compatible with both. Otherwise, return
432 static enum machine_mode
433 s390_cc_modes_compatible (enum machine_mode m1
, enum machine_mode m2
)
441 if (m2
== CCUmode
|| m2
== CCTmode
|| m2
== CCZ1mode
442 || m2
== CCSmode
|| m2
== CCSRmode
|| m2
== CCURmode
)
463 /* Return true if SET either doesn't set the CC register, or else
464 the source and destination have matching CC modes and that
465 CC mode is at least as constrained as REQ_MODE. */
468 s390_match_ccmode_set (rtx set
, enum machine_mode req_mode
)
470 enum machine_mode set_mode
;
472 gcc_assert (GET_CODE (set
) == SET
);
474 if (GET_CODE (SET_DEST (set
)) != REG
|| !CC_REGNO_P (REGNO (SET_DEST (set
))))
477 set_mode
= GET_MODE (SET_DEST (set
));
491 if (req_mode
!= set_mode
)
496 if (req_mode
!= CCSmode
&& req_mode
!= CCUmode
&& req_mode
!= CCTmode
497 && req_mode
!= CCSRmode
&& req_mode
!= CCURmode
)
503 if (req_mode
!= CCAmode
)
511 return (GET_MODE (SET_SRC (set
)) == set_mode
);
514 /* Return true if every SET in INSN that sets the CC register
515 has source and destination with matching CC modes and that
516 CC mode is at least as constrained as REQ_MODE.
517 If REQ_MODE is VOIDmode, always return false. */
520 s390_match_ccmode (rtx insn
, enum machine_mode req_mode
)
524 /* s390_tm_ccmode returns VOIDmode to indicate failure. */
525 if (req_mode
== VOIDmode
)
528 if (GET_CODE (PATTERN (insn
)) == SET
)
529 return s390_match_ccmode_set (PATTERN (insn
), req_mode
);
531 if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
532 for (i
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
534 rtx set
= XVECEXP (PATTERN (insn
), 0, i
);
535 if (GET_CODE (set
) == SET
)
536 if (!s390_match_ccmode_set (set
, req_mode
))
543 /* If a test-under-mask instruction can be used to implement
544 (compare (and ... OP1) OP2), return the CC mode required
545 to do that. Otherwise, return VOIDmode.
546 MIXED is true if the instruction can distinguish between
547 CC1 and CC2 for mixed selected bits (TMxx), it is false
548 if the instruction cannot (TM). */
551 s390_tm_ccmode (rtx op1
, rtx op2
, bool mixed
)
555 /* ??? Fixme: should work on CONST_DOUBLE as well. */
556 if (GET_CODE (op1
) != CONST_INT
|| GET_CODE (op2
) != CONST_INT
)
559 /* Selected bits all zero: CC0.
560 e.g.: int a; if ((a & (16 + 128)) == 0) */
561 if (INTVAL (op2
) == 0)
564 /* Selected bits all one: CC3.
565 e.g.: int a; if ((a & (16 + 128)) == 16 + 128) */
566 if (INTVAL (op2
) == INTVAL (op1
))
569 /* Exactly two bits selected, mixed zeroes and ones: CC1 or CC2. e.g.:
571 if ((a & (16 + 128)) == 16) -> CCT1
572 if ((a & (16 + 128)) == 128) -> CCT2 */
575 bit1
= exact_log2 (INTVAL (op2
));
576 bit0
= exact_log2 (INTVAL (op1
) ^ INTVAL (op2
));
577 if (bit0
!= -1 && bit1
!= -1)
578 return bit0
> bit1
? CCT1mode
: CCT2mode
;
584 /* Given a comparison code OP (EQ, NE, etc.) and the operands
585 OP0 and OP1 of a COMPARE, return the mode to be used for the
589 s390_select_ccmode (enum rtx_code code
, rtx op0
, rtx op1
)
595 if ((GET_CODE (op0
) == NEG
|| GET_CODE (op0
) == ABS
)
596 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
598 if (GET_CODE (op0
) == PLUS
&& GET_CODE (XEXP (op0
, 1)) == CONST_INT
599 && CONST_OK_FOR_K (INTVAL (XEXP (op0
, 1))))
601 if ((GET_CODE (op0
) == PLUS
|| GET_CODE (op0
) == MINUS
602 || GET_CODE (op1
) == NEG
)
603 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
606 if (GET_CODE (op0
) == AND
)
608 /* Check whether we can potentially do it via TM. */
609 enum machine_mode ccmode
;
610 ccmode
= s390_tm_ccmode (XEXP (op0
, 1), op1
, 1);
611 if (ccmode
!= VOIDmode
)
613 /* Relax CCTmode to CCZmode to allow fall-back to AND
614 if that turns out to be beneficial. */
615 return ccmode
== CCTmode
? CCZmode
: ccmode
;
619 if (register_operand (op0
, HImode
)
620 && GET_CODE (op1
) == CONST_INT
621 && (INTVAL (op1
) == -1 || INTVAL (op1
) == 65535))
623 if (register_operand (op0
, QImode
)
624 && GET_CODE (op1
) == CONST_INT
625 && (INTVAL (op1
) == -1 || INTVAL (op1
) == 255))
634 /* The only overflow condition of NEG and ABS happens when
635 -INT_MAX is used as parameter, which stays negative. So
636 we have an overflow from a positive value to a negative.
637 Using CCAP mode the resulting cc can be used for comparisons. */
638 if ((GET_CODE (op0
) == NEG
|| GET_CODE (op0
) == ABS
)
639 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
642 /* If constants are involved in an add instruction it is possible to use
643 the resulting cc for comparisons with zero. Knowing the sign of the
644 constant the overflow behavior gets predictable. e.g.:
645 int a, b; if ((b = a + c) > 0)
646 with c as a constant value: c < 0 -> CCAN and c >= 0 -> CCAP */
647 if (GET_CODE (op0
) == PLUS
&& GET_CODE (XEXP (op0
, 1)) == CONST_INT
648 && CONST_OK_FOR_K (INTVAL (XEXP (op0
, 1))))
650 if (INTVAL (XEXP((op0
), 1)) < 0)
664 if ((GET_CODE (op0
) == SIGN_EXTEND
|| GET_CODE (op0
) == ZERO_EXTEND
)
665 && GET_CODE (op1
) != CONST_INT
)
671 if (GET_CODE (op0
) == PLUS
672 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
675 if ((GET_CODE (op0
) == SIGN_EXTEND
|| GET_CODE (op0
) == ZERO_EXTEND
)
676 && GET_CODE (op1
) != CONST_INT
)
682 if (GET_CODE (op0
) == MINUS
683 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
686 if ((GET_CODE (op0
) == SIGN_EXTEND
|| GET_CODE (op0
) == ZERO_EXTEND
)
687 && GET_CODE (op1
) != CONST_INT
)
696 /* Replace the comparison OP0 CODE OP1 by a semantically equivalent one
697 that we can implement more efficiently. */
700 s390_canonicalize_comparison (enum rtx_code
*code
, rtx
*op0
, rtx
*op1
)
702 /* Convert ZERO_EXTRACT back to AND to enable TM patterns. */
703 if ((*code
== EQ
|| *code
== NE
)
704 && *op1
== const0_rtx
705 && GET_CODE (*op0
) == ZERO_EXTRACT
706 && GET_CODE (XEXP (*op0
, 1)) == CONST_INT
707 && GET_CODE (XEXP (*op0
, 2)) == CONST_INT
708 && SCALAR_INT_MODE_P (GET_MODE (XEXP (*op0
, 0))))
710 rtx inner
= XEXP (*op0
, 0);
711 HOST_WIDE_INT modesize
= GET_MODE_BITSIZE (GET_MODE (inner
));
712 HOST_WIDE_INT len
= INTVAL (XEXP (*op0
, 1));
713 HOST_WIDE_INT pos
= INTVAL (XEXP (*op0
, 2));
715 if (len
> 0 && len
< modesize
716 && pos
>= 0 && pos
+ len
<= modesize
717 && modesize
<= HOST_BITS_PER_WIDE_INT
)
719 unsigned HOST_WIDE_INT block
;
720 block
= ((unsigned HOST_WIDE_INT
) 1 << len
) - 1;
721 block
<<= modesize
- pos
- len
;
723 *op0
= gen_rtx_AND (GET_MODE (inner
), inner
,
724 gen_int_mode (block
, GET_MODE (inner
)));
728 /* Narrow AND of memory against immediate to enable TM. */
729 if ((*code
== EQ
|| *code
== NE
)
730 && *op1
== const0_rtx
731 && GET_CODE (*op0
) == AND
732 && GET_CODE (XEXP (*op0
, 1)) == CONST_INT
733 && SCALAR_INT_MODE_P (GET_MODE (XEXP (*op0
, 0))))
735 rtx inner
= XEXP (*op0
, 0);
736 rtx mask
= XEXP (*op0
, 1);
738 /* Ignore paradoxical SUBREGs if all extra bits are masked out. */
739 if (GET_CODE (inner
) == SUBREG
740 && SCALAR_INT_MODE_P (GET_MODE (SUBREG_REG (inner
)))
741 && (GET_MODE_SIZE (GET_MODE (inner
))
742 >= GET_MODE_SIZE (GET_MODE (SUBREG_REG (inner
))))
744 & GET_MODE_MASK (GET_MODE (inner
))
745 & ~GET_MODE_MASK (GET_MODE (SUBREG_REG (inner
))))
747 inner
= SUBREG_REG (inner
);
749 /* Do not change volatile MEMs. */
750 if (MEM_P (inner
) && !MEM_VOLATILE_P (inner
))
752 int part
= s390_single_part (XEXP (*op0
, 1),
753 GET_MODE (inner
), QImode
, 0);
756 mask
= gen_int_mode (s390_extract_part (mask
, QImode
, 0), QImode
);
757 inner
= adjust_address_nv (inner
, QImode
, part
);
758 *op0
= gen_rtx_AND (QImode
, inner
, mask
);
763 /* Narrow comparisons against 0xffff to HImode if possible. */
764 if ((*code
== EQ
|| *code
== NE
)
765 && GET_CODE (*op1
) == CONST_INT
766 && INTVAL (*op1
) == 0xffff
767 && SCALAR_INT_MODE_P (GET_MODE (*op0
))
768 && (nonzero_bits (*op0
, GET_MODE (*op0
))
769 & ~(unsigned HOST_WIDE_INT
) 0xffff) == 0)
771 *op0
= gen_lowpart (HImode
, *op0
);
775 /* Remove redundant UNSPEC_CCU_TO_INT conversions if possible. */
776 if (GET_CODE (*op0
) == UNSPEC
777 && XINT (*op0
, 1) == UNSPEC_CCU_TO_INT
778 && XVECLEN (*op0
, 0) == 1
779 && GET_MODE (XVECEXP (*op0
, 0, 0)) == CCUmode
780 && GET_CODE (XVECEXP (*op0
, 0, 0)) == REG
781 && REGNO (XVECEXP (*op0
, 0, 0)) == CC_REGNUM
782 && *op1
== const0_rtx
)
784 enum rtx_code new_code
= UNKNOWN
;
787 case EQ
: new_code
= EQ
; break;
788 case NE
: new_code
= NE
; break;
789 case LT
: new_code
= GTU
; break;
790 case GT
: new_code
= LTU
; break;
791 case LE
: new_code
= GEU
; break;
792 case GE
: new_code
= LEU
; break;
796 if (new_code
!= UNKNOWN
)
798 *op0
= XVECEXP (*op0
, 0, 0);
803 /* Remove redundant UNSPEC_CCZ_TO_INT conversions if possible. */
804 if (GET_CODE (*op0
) == UNSPEC
805 && XINT (*op0
, 1) == UNSPEC_CCZ_TO_INT
806 && XVECLEN (*op0
, 0) == 1
807 && GET_MODE (XVECEXP (*op0
, 0, 0)) == CCZmode
808 && GET_CODE (XVECEXP (*op0
, 0, 0)) == REG
809 && REGNO (XVECEXP (*op0
, 0, 0)) == CC_REGNUM
810 && *op1
== const0_rtx
)
812 enum rtx_code new_code
= UNKNOWN
;
815 case EQ
: new_code
= EQ
; break;
816 case NE
: new_code
= NE
; break;
820 if (new_code
!= UNKNOWN
)
822 *op0
= XVECEXP (*op0
, 0, 0);
827 /* Simplify cascaded EQ, NE with const0_rtx. */
828 if ((*code
== NE
|| *code
== EQ
)
829 && (GET_CODE (*op0
) == EQ
|| GET_CODE (*op0
) == NE
)
830 && GET_MODE (*op0
) == SImode
831 && GET_MODE (XEXP (*op0
, 0)) == CCZ1mode
832 && REG_P (XEXP (*op0
, 0))
833 && XEXP (*op0
, 1) == const0_rtx
834 && *op1
== const0_rtx
)
836 if ((*code
== EQ
&& GET_CODE (*op0
) == NE
)
837 || (*code
== NE
&& GET_CODE (*op0
) == EQ
))
841 *op0
= XEXP (*op0
, 0);
844 /* Prefer register over memory as first operand. */
845 if (MEM_P (*op0
) && REG_P (*op1
))
847 rtx tem
= *op0
; *op0
= *op1
; *op1
= tem
;
848 *code
= swap_condition (*code
);
852 /* Emit a compare instruction suitable to implement the comparison
853 OP0 CODE OP1. Return the correct condition RTL to be placed in
854 the IF_THEN_ELSE of the conditional branch testing the result. */
857 s390_emit_compare (enum rtx_code code
, rtx op0
, rtx op1
)
859 enum machine_mode mode
= s390_select_ccmode (code
, op0
, op1
);
862 /* Do not output a redundant compare instruction if a compare_and_swap
863 pattern already computed the result and the machine modes are compatible. */
864 if (GET_MODE_CLASS (GET_MODE (op0
)) == MODE_CC
)
866 gcc_assert (s390_cc_modes_compatible (GET_MODE (op0
), mode
)
872 cc
= gen_rtx_REG (mode
, CC_REGNUM
);
873 emit_insn (gen_rtx_SET (VOIDmode
, cc
, gen_rtx_COMPARE (mode
, op0
, op1
)));
876 return gen_rtx_fmt_ee (code
, VOIDmode
, cc
, const0_rtx
);
879 /* Emit a SImode compare and swap instruction setting MEM to NEW_RTX if OLD
881 Return the correct condition RTL to be placed in the IF_THEN_ELSE of the
882 conditional branch testing the result. */
885 s390_emit_compare_and_swap (enum rtx_code code
, rtx old
, rtx mem
, rtx cmp
, rtx new_rtx
)
887 emit_insn (gen_sync_compare_and_swapsi (old
, mem
, cmp
, new_rtx
));
888 return s390_emit_compare (code
, gen_rtx_REG (CCZ1mode
, CC_REGNUM
), const0_rtx
);
891 /* Emit a jump instruction to TARGET. If COND is NULL_RTX, emit an
892 unconditional jump, else a conditional jump under condition COND. */
895 s390_emit_jump (rtx target
, rtx cond
)
899 target
= gen_rtx_LABEL_REF (VOIDmode
, target
);
901 target
= gen_rtx_IF_THEN_ELSE (VOIDmode
, cond
, target
, pc_rtx
);
903 insn
= gen_rtx_SET (VOIDmode
, pc_rtx
, target
);
904 emit_jump_insn (insn
);
907 /* Return branch condition mask to implement a branch
908 specified by CODE. Return -1 for invalid comparisons. */
911 s390_branch_condition_mask (rtx code
)
913 const int CC0
= 1 << 3;
914 const int CC1
= 1 << 2;
915 const int CC2
= 1 << 1;
916 const int CC3
= 1 << 0;
918 gcc_assert (GET_CODE (XEXP (code
, 0)) == REG
);
919 gcc_assert (REGNO (XEXP (code
, 0)) == CC_REGNUM
);
920 gcc_assert (XEXP (code
, 1) == const0_rtx
);
922 switch (GET_MODE (XEXP (code
, 0)))
926 switch (GET_CODE (code
))
929 case NE
: return CC1
| CC2
| CC3
;
935 switch (GET_CODE (code
))
938 case NE
: return CC0
| CC2
| CC3
;
944 switch (GET_CODE (code
))
947 case NE
: return CC0
| CC1
| CC3
;
953 switch (GET_CODE (code
))
956 case NE
: return CC0
| CC1
| CC2
;
962 switch (GET_CODE (code
))
964 case EQ
: return CC0
| CC2
;
965 case NE
: return CC1
| CC3
;
971 switch (GET_CODE (code
))
973 case LTU
: return CC2
| CC3
; /* carry */
974 case GEU
: return CC0
| CC1
; /* no carry */
980 switch (GET_CODE (code
))
982 case GTU
: return CC0
| CC1
; /* borrow */
983 case LEU
: return CC2
| CC3
; /* no borrow */
989 switch (GET_CODE (code
))
991 case EQ
: return CC0
| CC2
;
992 case NE
: return CC1
| CC3
;
993 case LTU
: return CC1
;
994 case GTU
: return CC3
;
995 case LEU
: return CC1
| CC2
;
996 case GEU
: return CC2
| CC3
;
1001 switch (GET_CODE (code
))
1003 case EQ
: return CC0
;
1004 case NE
: return CC1
| CC2
| CC3
;
1005 case LTU
: return CC1
;
1006 case GTU
: return CC2
;
1007 case LEU
: return CC0
| CC1
;
1008 case GEU
: return CC0
| CC2
;
1014 switch (GET_CODE (code
))
1016 case EQ
: return CC0
;
1017 case NE
: return CC2
| CC1
| CC3
;
1018 case LTU
: return CC2
;
1019 case GTU
: return CC1
;
1020 case LEU
: return CC0
| CC2
;
1021 case GEU
: return CC0
| CC1
;
1027 switch (GET_CODE (code
))
1029 case EQ
: return CC0
;
1030 case NE
: return CC1
| CC2
| CC3
;
1031 case LT
: return CC1
| CC3
;
1032 case GT
: return CC2
;
1033 case LE
: return CC0
| CC1
| CC3
;
1034 case GE
: return CC0
| CC2
;
1040 switch (GET_CODE (code
))
1042 case EQ
: return CC0
;
1043 case NE
: return CC1
| CC2
| CC3
;
1044 case LT
: return CC1
;
1045 case GT
: return CC2
| CC3
;
1046 case LE
: return CC0
| CC1
;
1047 case GE
: return CC0
| CC2
| CC3
;
1053 switch (GET_CODE (code
))
1055 case EQ
: return CC0
;
1056 case NE
: return CC1
| CC2
| CC3
;
1057 case LT
: return CC1
;
1058 case GT
: return CC2
;
1059 case LE
: return CC0
| CC1
;
1060 case GE
: return CC0
| CC2
;
1061 case UNORDERED
: return CC3
;
1062 case ORDERED
: return CC0
| CC1
| CC2
;
1063 case UNEQ
: return CC0
| CC3
;
1064 case UNLT
: return CC1
| CC3
;
1065 case UNGT
: return CC2
| CC3
;
1066 case UNLE
: return CC0
| CC1
| CC3
;
1067 case UNGE
: return CC0
| CC2
| CC3
;
1068 case LTGT
: return CC1
| CC2
;
1074 switch (GET_CODE (code
))
1076 case EQ
: return CC0
;
1077 case NE
: return CC2
| CC1
| CC3
;
1078 case LT
: return CC2
;
1079 case GT
: return CC1
;
1080 case LE
: return CC0
| CC2
;
1081 case GE
: return CC0
| CC1
;
1082 case UNORDERED
: return CC3
;
1083 case ORDERED
: return CC0
| CC2
| CC1
;
1084 case UNEQ
: return CC0
| CC3
;
1085 case UNLT
: return CC2
| CC3
;
1086 case UNGT
: return CC1
| CC3
;
1087 case UNLE
: return CC0
| CC2
| CC3
;
1088 case UNGE
: return CC0
| CC1
| CC3
;
1089 case LTGT
: return CC2
| CC1
;
1100 /* Return branch condition mask to implement a compare and branch
1101 specified by CODE. Return -1 for invalid comparisons. */
1104 s390_compare_and_branch_condition_mask (rtx code
)
1106 const int CC0
= 1 << 3;
1107 const int CC1
= 1 << 2;
1108 const int CC2
= 1 << 1;
1110 switch (GET_CODE (code
))
1134 /* If INV is false, return assembler mnemonic string to implement
1135 a branch specified by CODE. If INV is true, return mnemonic
1136 for the corresponding inverted branch. */
1139 s390_branch_condition_mnemonic (rtx code
, int inv
)
1143 static const char *const mnemonic
[16] =
1145 NULL
, "o", "h", "nle",
1146 "l", "nhe", "lh", "ne",
1147 "e", "nlh", "he", "nl",
1148 "le", "nh", "no", NULL
1151 if (GET_CODE (XEXP (code
, 0)) == REG
1152 && REGNO (XEXP (code
, 0)) == CC_REGNUM
1153 && XEXP (code
, 1) == const0_rtx
)
1154 mask
= s390_branch_condition_mask (code
);
1156 mask
= s390_compare_and_branch_condition_mask (code
);
1158 gcc_assert (mask
>= 0);
1163 gcc_assert (mask
>= 1 && mask
<= 14);
1165 return mnemonic
[mask
];
1168 /* Return the part of op which has a value different from def.
1169 The size of the part is determined by mode.
1170 Use this function only if you already know that op really
1171 contains such a part. */
1173 unsigned HOST_WIDE_INT
1174 s390_extract_part (rtx op
, enum machine_mode mode
, int def
)
1176 unsigned HOST_WIDE_INT value
= 0;
1177 int max_parts
= HOST_BITS_PER_WIDE_INT
/ GET_MODE_BITSIZE (mode
);
1178 int part_bits
= GET_MODE_BITSIZE (mode
);
1179 unsigned HOST_WIDE_INT part_mask
1180 = ((unsigned HOST_WIDE_INT
)1 << part_bits
) - 1;
1183 for (i
= 0; i
< max_parts
; i
++)
1186 value
= (unsigned HOST_WIDE_INT
) INTVAL (op
);
1188 value
>>= part_bits
;
1190 if ((value
& part_mask
) != (def
& part_mask
))
1191 return value
& part_mask
;
1197 /* If OP is an integer constant of mode MODE with exactly one
1198 part of mode PART_MODE unequal to DEF, return the number of that
1199 part. Otherwise, return -1. */
1202 s390_single_part (rtx op
,
1203 enum machine_mode mode
,
1204 enum machine_mode part_mode
,
1207 unsigned HOST_WIDE_INT value
= 0;
1208 int n_parts
= GET_MODE_SIZE (mode
) / GET_MODE_SIZE (part_mode
);
1209 unsigned HOST_WIDE_INT part_mask
1210 = ((unsigned HOST_WIDE_INT
)1 << GET_MODE_BITSIZE (part_mode
)) - 1;
1213 if (GET_CODE (op
) != CONST_INT
)
1216 for (i
= 0; i
< n_parts
; i
++)
1219 value
= (unsigned HOST_WIDE_INT
) INTVAL (op
);
1221 value
>>= GET_MODE_BITSIZE (part_mode
);
1223 if ((value
& part_mask
) != (def
& part_mask
))
1231 return part
== -1 ? -1 : n_parts
- 1 - part
;
1234 /* Return true if IN contains a contiguous bitfield in the lower SIZE
1235 bits and no other bits are set in IN. POS and LENGTH can be used
1236 to obtain the start position and the length of the bitfield.
1238 POS gives the position of the first bit of the bitfield counting
1239 from the lowest order bit starting with zero. In order to use this
1240 value for S/390 instructions this has to be converted to "bits big
1244 s390_contiguous_bitmask_p (unsigned HOST_WIDE_INT in
, int size
,
1245 int *pos
, int *length
)
1250 unsigned HOST_WIDE_INT mask
= 1ULL;
1251 bool contiguous
= false;
1253 for (i
= 0; i
< size
; mask
<<= 1, i
++)
1277 /* Calculate a mask for all bits beyond the contiguous bits. */
1278 mask
= (-1LL & ~(((1ULL << (tmp_length
+ tmp_pos
- 1)) << 1) - 1));
1283 if (tmp_length
+ tmp_pos
- 1 > size
)
1287 *length
= tmp_length
;
1295 /* Check whether we can (and want to) split a double-word
1296 move in mode MODE from SRC to DST into two single-word
1297 moves, moving the subword FIRST_SUBWORD first. */
1300 s390_split_ok_p (rtx dst
, rtx src
, enum machine_mode mode
, int first_subword
)
1302 /* Floating point registers cannot be split. */
1303 if (FP_REG_P (src
) || FP_REG_P (dst
))
1306 /* We don't need to split if operands are directly accessible. */
1307 if (s_operand (src
, mode
) || s_operand (dst
, mode
))
1310 /* Non-offsettable memory references cannot be split. */
1311 if ((GET_CODE (src
) == MEM
&& !offsettable_memref_p (src
))
1312 || (GET_CODE (dst
) == MEM
&& !offsettable_memref_p (dst
)))
1315 /* Moving the first subword must not clobber a register
1316 needed to move the second subword. */
1317 if (register_operand (dst
, mode
))
1319 rtx subreg
= operand_subword (dst
, first_subword
, 0, mode
);
1320 if (reg_overlap_mentioned_p (subreg
, src
))
1327 /* Return true if it can be proven that [MEM1, MEM1 + SIZE]
1328 and [MEM2, MEM2 + SIZE] do overlap and false
1332 s390_overlap_p (rtx mem1
, rtx mem2
, HOST_WIDE_INT size
)
1334 rtx addr1
, addr2
, addr_delta
;
1335 HOST_WIDE_INT delta
;
1337 if (GET_CODE (mem1
) != MEM
|| GET_CODE (mem2
) != MEM
)
1343 addr1
= XEXP (mem1
, 0);
1344 addr2
= XEXP (mem2
, 0);
1346 addr_delta
= simplify_binary_operation (MINUS
, Pmode
, addr2
, addr1
);
1348 /* This overlapping check is used by peepholes merging memory block operations.
1349 Overlapping operations would otherwise be recognized by the S/390 hardware
1350 and would fall back to a slower implementation. Allowing overlapping
1351 operations would lead to slow code but not to wrong code. Therefore we are
1352 somewhat optimistic if we cannot prove that the memory blocks are
1354 That's why we return false here although this may accept operations on
1355 overlapping memory areas. */
1356 if (!addr_delta
|| GET_CODE (addr_delta
) != CONST_INT
)
1359 delta
= INTVAL (addr_delta
);
1362 || (delta
> 0 && delta
< size
)
1363 || (delta
< 0 && -delta
< size
))
1369 /* Check whether the address of memory reference MEM2 equals exactly
1370 the address of memory reference MEM1 plus DELTA. Return true if
1371 we can prove this to be the case, false otherwise. */
1374 s390_offset_p (rtx mem1
, rtx mem2
, rtx delta
)
1376 rtx addr1
, addr2
, addr_delta
;
1378 if (GET_CODE (mem1
) != MEM
|| GET_CODE (mem2
) != MEM
)
1381 addr1
= XEXP (mem1
, 0);
1382 addr2
= XEXP (mem2
, 0);
1384 addr_delta
= simplify_binary_operation (MINUS
, Pmode
, addr2
, addr1
);
1385 if (!addr_delta
|| !rtx_equal_p (addr_delta
, delta
))
1391 /* Expand logical operator CODE in mode MODE with operands OPERANDS. */
1394 s390_expand_logical_operator (enum rtx_code code
, enum machine_mode mode
,
1397 enum machine_mode wmode
= mode
;
1398 rtx dst
= operands
[0];
1399 rtx src1
= operands
[1];
1400 rtx src2
= operands
[2];
1403 /* If we cannot handle the operation directly, use a temp register. */
1404 if (!s390_logical_operator_ok_p (operands
))
1405 dst
= gen_reg_rtx (mode
);
1407 /* QImode and HImode patterns make sense only if we have a destination
1408 in memory. Otherwise perform the operation in SImode. */
1409 if ((mode
== QImode
|| mode
== HImode
) && GET_CODE (dst
) != MEM
)
1412 /* Widen operands if required. */
1415 if (GET_CODE (dst
) == SUBREG
1416 && (tem
= simplify_subreg (wmode
, dst
, mode
, 0)) != 0)
1418 else if (REG_P (dst
))
1419 dst
= gen_rtx_SUBREG (wmode
, dst
, 0);
1421 dst
= gen_reg_rtx (wmode
);
1423 if (GET_CODE (src1
) == SUBREG
1424 && (tem
= simplify_subreg (wmode
, src1
, mode
, 0)) != 0)
1426 else if (GET_MODE (src1
) != VOIDmode
)
1427 src1
= gen_rtx_SUBREG (wmode
, force_reg (mode
, src1
), 0);
1429 if (GET_CODE (src2
) == SUBREG
1430 && (tem
= simplify_subreg (wmode
, src2
, mode
, 0)) != 0)
1432 else if (GET_MODE (src2
) != VOIDmode
)
1433 src2
= gen_rtx_SUBREG (wmode
, force_reg (mode
, src2
), 0);
1436 /* Emit the instruction. */
1437 op
= gen_rtx_SET (VOIDmode
, dst
, gen_rtx_fmt_ee (code
, wmode
, src1
, src2
));
1438 clob
= gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
1439 emit_insn (gen_rtx_PARALLEL (VOIDmode
, gen_rtvec (2, op
, clob
)));
1441 /* Fix up the destination if needed. */
1442 if (dst
!= operands
[0])
1443 emit_move_insn (operands
[0], gen_lowpart (mode
, dst
));
1446 /* Check whether OPERANDS are OK for a logical operation (AND, IOR, XOR). */
1449 s390_logical_operator_ok_p (rtx
*operands
)
1451 /* If the destination operand is in memory, it needs to coincide
1452 with one of the source operands. After reload, it has to be
1453 the first source operand. */
1454 if (GET_CODE (operands
[0]) == MEM
)
1455 return rtx_equal_p (operands
[0], operands
[1])
1456 || (!reload_completed
&& rtx_equal_p (operands
[0], operands
[2]));
1461 /* Narrow logical operation CODE of memory operand MEMOP with immediate
1462 operand IMMOP to switch from SS to SI type instructions. */
1465 s390_narrow_logical_operator (enum rtx_code code
, rtx
*memop
, rtx
*immop
)
1467 int def
= code
== AND
? -1 : 0;
1471 gcc_assert (GET_CODE (*memop
) == MEM
);
1472 gcc_assert (!MEM_VOLATILE_P (*memop
));
1474 mask
= s390_extract_part (*immop
, QImode
, def
);
1475 part
= s390_single_part (*immop
, GET_MODE (*memop
), QImode
, def
);
1476 gcc_assert (part
>= 0);
1478 *memop
= adjust_address (*memop
, QImode
, part
);
1479 *immop
= gen_int_mode (mask
, QImode
);
1483 /* How to allocate a 'struct machine_function'. */
1485 static struct machine_function
*
1486 s390_init_machine_status (void)
1488 return ggc_alloc_cleared_machine_function ();
1491 /* Change optimizations to be performed, depending on the
1492 optimization level. */
1494 static const struct default_options s390_option_optimization_table
[] =
1496 { OPT_LEVELS_1_PLUS
, OPT_fomit_frame_pointer
, NULL
, 1 },
1498 /* ??? There are apparently still problems with -fcaller-saves. */
1499 { OPT_LEVELS_ALL
, OPT_fcaller_saves
, NULL
, 0 },
1501 /* Use MVCLE instructions to decrease code size if requested. */
1502 { OPT_LEVELS_SIZE
, OPT_mmvcle
, NULL
, 1 },
1504 { OPT_LEVELS_NONE
, 0, NULL
, 0 }
1507 /* Implement TARGET_OPTION_INIT_STRUCT. */
1510 s390_option_init_struct (struct gcc_options
*opts
)
1512 /* By default, always emit DWARF-2 unwind info. This allows debugging
1513 without maintaining a stack frame back-chain. */
1514 opts
->x_flag_asynchronous_unwind_tables
= 1;
1517 /* Return true if ARG is the name of a processor. Set *TYPE and *FLAGS
1518 to the associated processor_type and processor_flags if so. */
1521 s390_handle_arch_option (const char *arg
,
1522 enum processor_type
*type
,
1527 const char *const name
; /* processor name or nickname. */
1528 const enum processor_type processor
;
1529 const int flags
; /* From enum processor_flags. */
1531 const processor_alias_table
[] =
1533 {"g5", PROCESSOR_9672_G5
, PF_IEEE_FLOAT
},
1534 {"g6", PROCESSOR_9672_G6
, PF_IEEE_FLOAT
},
1535 {"z900", PROCESSOR_2064_Z900
, PF_IEEE_FLOAT
| PF_ZARCH
},
1536 {"z990", PROCESSOR_2084_Z990
, PF_IEEE_FLOAT
| PF_ZARCH
1537 | PF_LONG_DISPLACEMENT
},
1538 {"z9-109", PROCESSOR_2094_Z9_109
, PF_IEEE_FLOAT
| PF_ZARCH
1539 | PF_LONG_DISPLACEMENT
| PF_EXTIMM
},
1540 {"z9-ec", PROCESSOR_2094_Z9_109
, PF_IEEE_FLOAT
| PF_ZARCH
1541 | PF_LONG_DISPLACEMENT
| PF_EXTIMM
| PF_DFP
},
1542 {"z10", PROCESSOR_2097_Z10
, PF_IEEE_FLOAT
| PF_ZARCH
1543 | PF_LONG_DISPLACEMENT
| PF_EXTIMM
| PF_DFP
| PF_Z10
},
1544 {"z196", PROCESSOR_2817_Z196
, PF_IEEE_FLOAT
| PF_ZARCH
1545 | PF_LONG_DISPLACEMENT
| PF_EXTIMM
| PF_DFP
| PF_Z10
| PF_Z196
},
1549 for (i
= 0; i
< ARRAY_SIZE (processor_alias_table
); i
++)
1550 if (strcmp (arg
, processor_alias_table
[i
].name
) == 0)
1552 *type
= processor_alias_table
[i
].processor
;
1553 *flags
= processor_alias_table
[i
].flags
;
1557 *type
= PROCESSOR_max
;
1562 /* Implement TARGET_HANDLE_OPTION. */
1565 s390_handle_option (size_t code
, const char *arg
, int value ATTRIBUTE_UNUSED
)
1570 return s390_handle_arch_option (arg
, &s390_arch
, &s390_arch_flags
);
1572 case OPT_mstack_guard_
:
1573 if (sscanf (arg
, HOST_WIDE_INT_PRINT_DEC
, &s390_stack_guard
) != 1)
1575 if (exact_log2 (s390_stack_guard
) == -1)
1576 error ("stack guard value must be an exact power of 2");
1579 case OPT_mstack_size_
:
1580 if (sscanf (arg
, HOST_WIDE_INT_PRINT_DEC
, &s390_stack_size
) != 1)
1582 if (exact_log2 (s390_stack_size
) == -1)
1583 error ("stack size must be an exact power of 2");
1587 return s390_handle_arch_option (arg
, &s390_tune
, &s390_tune_flags
);
1589 case OPT_mwarn_framesize_
:
1590 return sscanf (arg
, HOST_WIDE_INT_PRINT_DEC
, &s390_warn_framesize
) == 1;
1598 s390_option_override (void)
1600 /* Set up function hooks. */
1601 init_machine_status
= s390_init_machine_status
;
1603 /* Architecture mode defaults according to ABI. */
1604 if (!(target_flags_explicit
& MASK_ZARCH
))
1607 target_flags
|= MASK_ZARCH
;
1609 target_flags
&= ~MASK_ZARCH
;
1612 /* Determine processor architectural level. */
1613 if (!s390_arch_string
)
1615 s390_arch_string
= TARGET_ZARCH
? "z900" : "g5";
1616 s390_handle_arch_option (s390_arch_string
, &s390_arch
, &s390_arch_flags
);
1619 /* This check is triggered when the user specified a wrong -march=
1620 string and prevents subsequent error messages from being
1622 if (s390_arch
== PROCESSOR_max
)
1625 /* Determine processor to tune for. */
1626 if (s390_tune
== PROCESSOR_max
)
1628 s390_tune
= s390_arch
;
1629 s390_tune_flags
= s390_arch_flags
;
1632 /* Sanity checks. */
1633 if (TARGET_ZARCH
&& !TARGET_CPU_ZARCH
)
1634 error ("z/Architecture mode not supported on %s", s390_arch_string
);
1635 if (TARGET_64BIT
&& !TARGET_ZARCH
)
1636 error ("64-bit ABI not supported in ESA/390 mode");
1638 if (TARGET_HARD_DFP
&& !TARGET_DFP
)
1640 if (target_flags_explicit
& MASK_HARD_DFP
)
1642 if (!TARGET_CPU_DFP
)
1643 error ("hardware decimal floating point instructions"
1644 " not available on %s", s390_arch_string
);
1646 error ("hardware decimal floating point instructions"
1647 " not available in ESA/390 mode");
1650 target_flags
&= ~MASK_HARD_DFP
;
1653 if ((target_flags_explicit
& MASK_SOFT_FLOAT
) && TARGET_SOFT_FLOAT
)
1655 if ((target_flags_explicit
& MASK_HARD_DFP
) && TARGET_HARD_DFP
)
1656 error ("-mhard-dfp can%'t be used in conjunction with -msoft-float");
1658 target_flags
&= ~MASK_HARD_DFP
;
1661 /* Set processor cost function. */
1664 case PROCESSOR_2084_Z990
:
1665 s390_cost
= &z990_cost
;
1667 case PROCESSOR_2094_Z9_109
:
1668 s390_cost
= &z9_109_cost
;
1670 case PROCESSOR_2097_Z10
:
1671 s390_cost
= &z10_cost
;
1672 case PROCESSOR_2817_Z196
:
1673 s390_cost
= &z196_cost
;
1676 s390_cost
= &z900_cost
;
1679 if (TARGET_BACKCHAIN
&& TARGET_PACKED_STACK
&& TARGET_HARD_FLOAT
)
1680 error ("-mbackchain -mpacked-stack -mhard-float are not supported "
1683 if (s390_stack_size
)
1685 if (s390_stack_guard
>= s390_stack_size
)
1686 error ("stack size must be greater than the stack guard value");
1687 else if (s390_stack_size
> 1 << 16)
1688 error ("stack size must not be greater than 64k");
1690 else if (s390_stack_guard
)
1691 error ("-mstack-guard implies use of -mstack-size");
1693 #ifdef TARGET_DEFAULT_LONG_DOUBLE_128
1694 if (!(target_flags_explicit
& MASK_LONG_DOUBLE_128
))
1695 target_flags
|= MASK_LONG_DOUBLE_128
;
1698 if (s390_tune
== PROCESSOR_2097_Z10
1699 || s390_tune
== PROCESSOR_2817_Z196
)
1701 maybe_set_param_value (PARAM_MAX_UNROLLED_INSNS
, 100,
1702 global_options
.x_param_values
,
1703 global_options_set
.x_param_values
);
1704 maybe_set_param_value (PARAM_MAX_UNROLL_TIMES
, 32,
1705 global_options
.x_param_values
,
1706 global_options_set
.x_param_values
);
1707 maybe_set_param_value (PARAM_MAX_COMPLETELY_PEELED_INSNS
, 2000,
1708 global_options
.x_param_values
,
1709 global_options_set
.x_param_values
);
1710 maybe_set_param_value (PARAM_MAX_COMPLETELY_PEEL_TIMES
, 64,
1711 global_options
.x_param_values
,
1712 global_options_set
.x_param_values
);
1715 maybe_set_param_value (PARAM_MAX_PENDING_LIST_LENGTH
, 256,
1716 global_options
.x_param_values
,
1717 global_options_set
.x_param_values
);
1718 /* values for loop prefetching */
1719 maybe_set_param_value (PARAM_L1_CACHE_LINE_SIZE
, 256,
1720 global_options
.x_param_values
,
1721 global_options_set
.x_param_values
);
1722 maybe_set_param_value (PARAM_L1_CACHE_SIZE
, 128,
1723 global_options
.x_param_values
,
1724 global_options_set
.x_param_values
);
1725 /* s390 has more than 2 levels and the size is much larger. Since
1726 we are always running virtualized assume that we only get a small
1727 part of the caches above l1. */
1728 maybe_set_param_value (PARAM_L2_CACHE_SIZE
, 1500,
1729 global_options
.x_param_values
,
1730 global_options_set
.x_param_values
);
1731 maybe_set_param_value (PARAM_PREFETCH_MIN_INSN_TO_MEM_RATIO
, 2,
1732 global_options
.x_param_values
,
1733 global_options_set
.x_param_values
);
1734 maybe_set_param_value (PARAM_SIMULTANEOUS_PREFETCHES
, 6,
1735 global_options
.x_param_values
,
1736 global_options_set
.x_param_values
);
1738 /* This cannot reside in s390_option_optimization_table since HAVE_prefetch
1739 requires the arch flags to be evaluated already. Since prefetching
1740 is beneficial on s390, we enable it if available. */
1741 if (flag_prefetch_loop_arrays
< 0 && HAVE_prefetch
&& optimize
>= 3)
1742 flag_prefetch_loop_arrays
= 1;
1745 /* Map for smallest class containing reg regno. */
1747 const enum reg_class regclass_map
[FIRST_PSEUDO_REGISTER
] =
1748 { GENERAL_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1749 ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1750 ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1751 ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1752 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1753 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1754 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1755 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1756 ADDR_REGS
, CC_REGS
, ADDR_REGS
, ADDR_REGS
,
1757 ACCESS_REGS
, ACCESS_REGS
1760 /* Return attribute type of insn. */
1762 static enum attr_type
1763 s390_safe_attr_type (rtx insn
)
1765 if (recog_memoized (insn
) >= 0)
1766 return get_attr_type (insn
);
1771 /* Return true if DISP is a valid short displacement. */
1774 s390_short_displacement (rtx disp
)
1776 /* No displacement is OK. */
1780 /* Without the long displacement facility we don't need to
1781 distingiush between long and short displacement. */
1782 if (!TARGET_LONG_DISPLACEMENT
)
1785 /* Integer displacement in range. */
1786 if (GET_CODE (disp
) == CONST_INT
)
1787 return INTVAL (disp
) >= 0 && INTVAL (disp
) < 4096;
1789 /* GOT offset is not OK, the GOT can be large. */
1790 if (GET_CODE (disp
) == CONST
1791 && GET_CODE (XEXP (disp
, 0)) == UNSPEC
1792 && (XINT (XEXP (disp
, 0), 1) == UNSPEC_GOT
1793 || XINT (XEXP (disp
, 0), 1) == UNSPEC_GOTNTPOFF
))
1796 /* All other symbolic constants are literal pool references,
1797 which are OK as the literal pool must be small. */
1798 if (GET_CODE (disp
) == CONST
)
1804 /* Decompose a RTL expression ADDR for a memory address into
1805 its components, returned in OUT.
1807 Returns false if ADDR is not a valid memory address, true
1808 otherwise. If OUT is NULL, don't return the components,
1809 but check for validity only.
1811 Note: Only addresses in canonical form are recognized.
1812 LEGITIMIZE_ADDRESS should convert non-canonical forms to the
1813 canonical form so that they will be recognized. */
1816 s390_decompose_address (rtx addr
, struct s390_address
*out
)
1818 HOST_WIDE_INT offset
= 0;
1819 rtx base
= NULL_RTX
;
1820 rtx indx
= NULL_RTX
;
1821 rtx disp
= NULL_RTX
;
1823 bool pointer
= false;
1824 bool base_ptr
= false;
1825 bool indx_ptr
= false;
1826 bool literal_pool
= false;
1828 /* We may need to substitute the literal pool base register into the address
1829 below. However, at this point we do not know which register is going to
1830 be used as base, so we substitute the arg pointer register. This is going
1831 to be treated as holding a pointer below -- it shouldn't be used for any
1833 rtx fake_pool_base
= gen_rtx_REG (Pmode
, ARG_POINTER_REGNUM
);
1835 /* Decompose address into base + index + displacement. */
1837 if (GET_CODE (addr
) == REG
|| GET_CODE (addr
) == UNSPEC
)
1840 else if (GET_CODE (addr
) == PLUS
)
1842 rtx op0
= XEXP (addr
, 0);
1843 rtx op1
= XEXP (addr
, 1);
1844 enum rtx_code code0
= GET_CODE (op0
);
1845 enum rtx_code code1
= GET_CODE (op1
);
1847 if (code0
== REG
|| code0
== UNSPEC
)
1849 if (code1
== REG
|| code1
== UNSPEC
)
1851 indx
= op0
; /* index + base */
1857 base
= op0
; /* base + displacement */
1862 else if (code0
== PLUS
)
1864 indx
= XEXP (op0
, 0); /* index + base + disp */
1865 base
= XEXP (op0
, 1);
1876 disp
= addr
; /* displacement */
1878 /* Extract integer part of displacement. */
1882 if (GET_CODE (disp
) == CONST_INT
)
1884 offset
= INTVAL (disp
);
1887 else if (GET_CODE (disp
) == CONST
1888 && GET_CODE (XEXP (disp
, 0)) == PLUS
1889 && GET_CODE (XEXP (XEXP (disp
, 0), 1)) == CONST_INT
)
1891 offset
= INTVAL (XEXP (XEXP (disp
, 0), 1));
1892 disp
= XEXP (XEXP (disp
, 0), 0);
1896 /* Strip off CONST here to avoid special case tests later. */
1897 if (disp
&& GET_CODE (disp
) == CONST
)
1898 disp
= XEXP (disp
, 0);
1900 /* We can convert literal pool addresses to
1901 displacements by basing them off the base register. */
1902 if (disp
&& GET_CODE (disp
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (disp
))
1904 /* Either base or index must be free to hold the base register. */
1906 base
= fake_pool_base
, literal_pool
= true;
1908 indx
= fake_pool_base
, literal_pool
= true;
1912 /* Mark up the displacement. */
1913 disp
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, disp
),
1914 UNSPEC_LTREL_OFFSET
);
1917 /* Validate base register. */
1920 if (GET_CODE (base
) == UNSPEC
)
1921 switch (XINT (base
, 1))
1925 disp
= gen_rtx_UNSPEC (Pmode
,
1926 gen_rtvec (1, XVECEXP (base
, 0, 0)),
1927 UNSPEC_LTREL_OFFSET
);
1931 base
= XVECEXP (base
, 0, 1);
1934 case UNSPEC_LTREL_BASE
:
1935 if (XVECLEN (base
, 0) == 1)
1936 base
= fake_pool_base
, literal_pool
= true;
1938 base
= XVECEXP (base
, 0, 1);
1946 || (GET_MODE (base
) != SImode
1947 && GET_MODE (base
) != Pmode
))
1950 if (REGNO (base
) == STACK_POINTER_REGNUM
1951 || REGNO (base
) == FRAME_POINTER_REGNUM
1952 || ((reload_completed
|| reload_in_progress
)
1953 && frame_pointer_needed
1954 && REGNO (base
) == HARD_FRAME_POINTER_REGNUM
)
1955 || REGNO (base
) == ARG_POINTER_REGNUM
1957 && REGNO (base
) == PIC_OFFSET_TABLE_REGNUM
))
1958 pointer
= base_ptr
= true;
1960 if ((reload_completed
|| reload_in_progress
)
1961 && base
== cfun
->machine
->base_reg
)
1962 pointer
= base_ptr
= literal_pool
= true;
1965 /* Validate index register. */
1968 if (GET_CODE (indx
) == UNSPEC
)
1969 switch (XINT (indx
, 1))
1973 disp
= gen_rtx_UNSPEC (Pmode
,
1974 gen_rtvec (1, XVECEXP (indx
, 0, 0)),
1975 UNSPEC_LTREL_OFFSET
);
1979 indx
= XVECEXP (indx
, 0, 1);
1982 case UNSPEC_LTREL_BASE
:
1983 if (XVECLEN (indx
, 0) == 1)
1984 indx
= fake_pool_base
, literal_pool
= true;
1986 indx
= XVECEXP (indx
, 0, 1);
1994 || (GET_MODE (indx
) != SImode
1995 && GET_MODE (indx
) != Pmode
))
1998 if (REGNO (indx
) == STACK_POINTER_REGNUM
1999 || REGNO (indx
) == FRAME_POINTER_REGNUM
2000 || ((reload_completed
|| reload_in_progress
)
2001 && frame_pointer_needed
2002 && REGNO (indx
) == HARD_FRAME_POINTER_REGNUM
)
2003 || REGNO (indx
) == ARG_POINTER_REGNUM
2005 && REGNO (indx
) == PIC_OFFSET_TABLE_REGNUM
))
2006 pointer
= indx_ptr
= true;
2008 if ((reload_completed
|| reload_in_progress
)
2009 && indx
== cfun
->machine
->base_reg
)
2010 pointer
= indx_ptr
= literal_pool
= true;
2013 /* Prefer to use pointer as base, not index. */
2014 if (base
&& indx
&& !base_ptr
2015 && (indx_ptr
|| (!REG_POINTER (base
) && REG_POINTER (indx
))))
2022 /* Validate displacement. */
2025 /* If virtual registers are involved, the displacement will change later
2026 anyway as the virtual registers get eliminated. This could make a
2027 valid displacement invalid, but it is more likely to make an invalid
2028 displacement valid, because we sometimes access the register save area
2029 via negative offsets to one of those registers.
2030 Thus we don't check the displacement for validity here. If after
2031 elimination the displacement turns out to be invalid after all,
2032 this is fixed up by reload in any case. */
2033 if (base
!= arg_pointer_rtx
2034 && indx
!= arg_pointer_rtx
2035 && base
!= return_address_pointer_rtx
2036 && indx
!= return_address_pointer_rtx
2037 && base
!= frame_pointer_rtx
2038 && indx
!= frame_pointer_rtx
2039 && base
!= virtual_stack_vars_rtx
2040 && indx
!= virtual_stack_vars_rtx
)
2041 if (!DISP_IN_RANGE (offset
))
2046 /* All the special cases are pointers. */
2049 /* In the small-PIC case, the linker converts @GOT
2050 and @GOTNTPOFF offsets to possible displacements. */
2051 if (GET_CODE (disp
) == UNSPEC
2052 && (XINT (disp
, 1) == UNSPEC_GOT
2053 || XINT (disp
, 1) == UNSPEC_GOTNTPOFF
)
2059 /* Accept pool label offsets. */
2060 else if (GET_CODE (disp
) == UNSPEC
2061 && XINT (disp
, 1) == UNSPEC_POOL_OFFSET
)
2064 /* Accept literal pool references. */
2065 else if (GET_CODE (disp
) == UNSPEC
2066 && XINT (disp
, 1) == UNSPEC_LTREL_OFFSET
)
2068 orig_disp
= gen_rtx_CONST (Pmode
, disp
);
2071 /* If we have an offset, make sure it does not
2072 exceed the size of the constant pool entry. */
2073 rtx sym
= XVECEXP (disp
, 0, 0);
2074 if (offset
>= GET_MODE_SIZE (get_pool_mode (sym
)))
2077 orig_disp
= plus_constant (orig_disp
, offset
);
2092 out
->disp
= orig_disp
;
2093 out
->pointer
= pointer
;
2094 out
->literal_pool
= literal_pool
;
2100 /* Decompose a RTL expression OP for a shift count into its components,
2101 and return the base register in BASE and the offset in OFFSET.
2103 Return true if OP is a valid shift count, false if not. */
2106 s390_decompose_shift_count (rtx op
, rtx
*base
, HOST_WIDE_INT
*offset
)
2108 HOST_WIDE_INT off
= 0;
2110 /* We can have an integer constant, an address register,
2111 or a sum of the two. */
2112 if (GET_CODE (op
) == CONST_INT
)
2117 if (op
&& GET_CODE (op
) == PLUS
&& GET_CODE (XEXP (op
, 1)) == CONST_INT
)
2119 off
= INTVAL (XEXP (op
, 1));
2122 while (op
&& GET_CODE (op
) == SUBREG
)
2123 op
= SUBREG_REG (op
);
2125 if (op
&& GET_CODE (op
) != REG
)
2137 /* Return true if CODE is a valid address without index. */
2140 s390_legitimate_address_without_index_p (rtx op
)
2142 struct s390_address addr
;
2144 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
2153 /* Return true if ADDR is of kind symbol_ref or symbol_ref + const_int
2154 and return these parts in SYMREF and ADDEND. You can pass NULL in
2155 SYMREF and/or ADDEND if you are not interested in these values.
2156 Literal pool references are *not* considered symbol references. */
2159 s390_symref_operand_p (rtx addr
, rtx
*symref
, HOST_WIDE_INT
*addend
)
2161 HOST_WIDE_INT tmpaddend
= 0;
2163 if (GET_CODE (addr
) == CONST
)
2164 addr
= XEXP (addr
, 0);
2166 if (GET_CODE (addr
) == PLUS
)
2168 if (GET_CODE (XEXP (addr
, 0)) == SYMBOL_REF
2169 && !CONSTANT_POOL_ADDRESS_P (XEXP (addr
, 0))
2170 && CONST_INT_P (XEXP (addr
, 1)))
2172 tmpaddend
= INTVAL (XEXP (addr
, 1));
2173 addr
= XEXP (addr
, 0);
2179 if (GET_CODE (addr
) != SYMBOL_REF
|| CONSTANT_POOL_ADDRESS_P (addr
))
2185 *addend
= tmpaddend
;
2191 /* Return true if the address in OP is valid for constraint letter C
2192 if wrapped in a MEM rtx. Set LIT_POOL_OK to true if it literal
2193 pool MEMs should be accepted. Only the Q, R, S, T constraint
2194 letters are allowed for C. */
2197 s390_check_qrst_address (char c
, rtx op
, bool lit_pool_ok
)
2199 struct s390_address addr
;
2200 bool decomposed
= false;
2202 /* This check makes sure that no symbolic address (except literal
2203 pool references) are accepted by the R or T constraints. */
2204 if (s390_symref_operand_p (op
, NULL
, NULL
))
2207 /* Ensure literal pool references are only accepted if LIT_POOL_OK. */
2210 if (!s390_decompose_address (op
, &addr
))
2212 if (addr
.literal_pool
)
2219 case 'Q': /* no index short displacement */
2220 if (!decomposed
&& !s390_decompose_address (op
, &addr
))
2224 if (!s390_short_displacement (addr
.disp
))
2228 case 'R': /* with index short displacement */
2229 if (TARGET_LONG_DISPLACEMENT
)
2231 if (!decomposed
&& !s390_decompose_address (op
, &addr
))
2233 if (!s390_short_displacement (addr
.disp
))
2236 /* Any invalid address here will be fixed up by reload,
2237 so accept it for the most generic constraint. */
2240 case 'S': /* no index long displacement */
2241 if (!TARGET_LONG_DISPLACEMENT
)
2243 if (!decomposed
&& !s390_decompose_address (op
, &addr
))
2247 if (s390_short_displacement (addr
.disp
))
2251 case 'T': /* with index long displacement */
2252 if (!TARGET_LONG_DISPLACEMENT
)
2254 /* Any invalid address here will be fixed up by reload,
2255 so accept it for the most generic constraint. */
2256 if ((decomposed
|| s390_decompose_address (op
, &addr
))
2257 && s390_short_displacement (addr
.disp
))
2267 /* Evaluates constraint strings described by the regular expression
2268 ([A|B|Z](Q|R|S|T))|U|W|Y and returns 1 if OP is a valid operand for
2269 the constraint given in STR, or 0 else. */
2272 s390_mem_constraint (const char *str
, rtx op
)
2279 /* Check for offsettable variants of memory constraints. */
2280 if (!MEM_P (op
) || MEM_VOLATILE_P (op
))
2282 if ((reload_completed
|| reload_in_progress
)
2283 ? !offsettable_memref_p (op
) : !offsettable_nonstrict_memref_p (op
))
2285 return s390_check_qrst_address (str
[1], XEXP (op
, 0), true);
2287 /* Check for non-literal-pool variants of memory constraints. */
2290 return s390_check_qrst_address (str
[1], XEXP (op
, 0), false);
2295 if (GET_CODE (op
) != MEM
)
2297 return s390_check_qrst_address (c
, XEXP (op
, 0), true);
2299 return (s390_check_qrst_address ('Q', op
, true)
2300 || s390_check_qrst_address ('R', op
, true));
2302 return (s390_check_qrst_address ('S', op
, true)
2303 || s390_check_qrst_address ('T', op
, true));
2305 /* Simply check for the basic form of a shift count. Reload will
2306 take care of making sure we have a proper base register. */
2307 if (!s390_decompose_shift_count (op
, NULL
, NULL
))
2311 return s390_check_qrst_address (str
[1], op
, true);
2319 /* Evaluates constraint strings starting with letter O. Input
2320 parameter C is the second letter following the "O" in the constraint
2321 string. Returns 1 if VALUE meets the respective constraint and 0
2325 s390_O_constraint_str (const char c
, HOST_WIDE_INT value
)
2333 return trunc_int_for_mode (value
, SImode
) == value
;
2337 || s390_single_part (GEN_INT (value
), DImode
, SImode
, 0) == 1;
2340 return s390_single_part (GEN_INT (value
- 1), DImode
, SImode
, -1) == 1;
2348 /* Evaluates constraint strings starting with letter N. Parameter STR
2349 contains the letters following letter "N" in the constraint string.
2350 Returns true if VALUE matches the constraint. */
2353 s390_N_constraint_str (const char *str
, HOST_WIDE_INT value
)
2355 enum machine_mode mode
, part_mode
;
2357 int part
, part_goal
;
2363 part_goal
= str
[0] - '0';
2407 if (GET_MODE_SIZE (mode
) <= GET_MODE_SIZE (part_mode
))
2410 part
= s390_single_part (GEN_INT (value
), mode
, part_mode
, def
);
2413 if (part_goal
!= -1 && part_goal
!= part
)
2420 /* Returns true if the input parameter VALUE is a float zero. */
2423 s390_float_const_zero_p (rtx value
)
2425 return (GET_MODE_CLASS (GET_MODE (value
)) == MODE_FLOAT
2426 && value
== CONST0_RTX (GET_MODE (value
)));
2429 /* Implement TARGET_REGISTER_MOVE_COST. */
2432 s390_register_move_cost (enum machine_mode mode ATTRIBUTE_UNUSED
,
2433 reg_class_t from
, reg_class_t to
)
2435 /* On s390, copy between fprs and gprs is expensive. */
2436 if ((reg_classes_intersect_p (from
, GENERAL_REGS
)
2437 && reg_classes_intersect_p (to
, FP_REGS
))
2438 || (reg_classes_intersect_p (from
, FP_REGS
)
2439 && reg_classes_intersect_p (to
, GENERAL_REGS
)))
2445 /* Implement TARGET_MEMORY_MOVE_COST. */
2448 s390_memory_move_cost (enum machine_mode mode ATTRIBUTE_UNUSED
,
2449 reg_class_t rclass ATTRIBUTE_UNUSED
,
2450 bool in ATTRIBUTE_UNUSED
)
2455 /* Compute a (partial) cost for rtx X. Return true if the complete
2456 cost has been computed, and false if subexpressions should be
2457 scanned. In either case, *TOTAL contains the cost result.
2458 CODE contains GET_CODE (x), OUTER_CODE contains the code
2459 of the superexpression of x. */
2462 s390_rtx_costs (rtx x
, int code
, int outer_code
, int *total
,
2463 bool speed ATTRIBUTE_UNUSED
)
2486 *total
= COSTS_N_INSNS (1);
2491 *total
= COSTS_N_INSNS (1);
2495 switch (GET_MODE (x
))
2499 rtx left
= XEXP (x
, 0);
2500 rtx right
= XEXP (x
, 1);
2501 if (GET_CODE (right
) == CONST_INT
2502 && CONST_OK_FOR_K (INTVAL (right
)))
2503 *total
= s390_cost
->mhi
;
2504 else if (GET_CODE (left
) == SIGN_EXTEND
)
2505 *total
= s390_cost
->mh
;
2507 *total
= s390_cost
->ms
; /* msr, ms, msy */
2512 rtx left
= XEXP (x
, 0);
2513 rtx right
= XEXP (x
, 1);
2516 if (GET_CODE (right
) == CONST_INT
2517 && CONST_OK_FOR_K (INTVAL (right
)))
2518 *total
= s390_cost
->mghi
;
2519 else if (GET_CODE (left
) == SIGN_EXTEND
)
2520 *total
= s390_cost
->msgf
;
2522 *total
= s390_cost
->msg
; /* msgr, msg */
2524 else /* TARGET_31BIT */
2526 if (GET_CODE (left
) == SIGN_EXTEND
2527 && GET_CODE (right
) == SIGN_EXTEND
)
2528 /* mulsidi case: mr, m */
2529 *total
= s390_cost
->m
;
2530 else if (GET_CODE (left
) == ZERO_EXTEND
2531 && GET_CODE (right
) == ZERO_EXTEND
2532 && TARGET_CPU_ZARCH
)
2533 /* umulsidi case: ml, mlr */
2534 *total
= s390_cost
->ml
;
2536 /* Complex calculation is required. */
2537 *total
= COSTS_N_INSNS (40);
2543 *total
= s390_cost
->mult_df
;
2546 *total
= s390_cost
->mxbr
;
2554 switch (GET_MODE (x
))
2557 *total
= s390_cost
->madbr
;
2560 *total
= s390_cost
->maebr
;
2565 /* Negate in the third argument is free: FMSUB. */
2566 if (GET_CODE (XEXP (x
, 2)) == NEG
)
2568 *total
+= (rtx_cost (XEXP (x
, 0), FMA
, speed
)
2569 + rtx_cost (XEXP (x
, 1), FMA
, speed
)
2570 + rtx_cost (XEXP (XEXP (x
, 2), 0), FMA
, speed
));
2577 if (GET_MODE (x
) == TImode
) /* 128 bit division */
2578 *total
= s390_cost
->dlgr
;
2579 else if (GET_MODE (x
) == DImode
)
2581 rtx right
= XEXP (x
, 1);
2582 if (GET_CODE (right
) == ZERO_EXTEND
) /* 64 by 32 bit division */
2583 *total
= s390_cost
->dlr
;
2584 else /* 64 by 64 bit division */
2585 *total
= s390_cost
->dlgr
;
2587 else if (GET_MODE (x
) == SImode
) /* 32 bit division */
2588 *total
= s390_cost
->dlr
;
2593 if (GET_MODE (x
) == DImode
)
2595 rtx right
= XEXP (x
, 1);
2596 if (GET_CODE (right
) == ZERO_EXTEND
) /* 64 by 32 bit division */
2598 *total
= s390_cost
->dsgfr
;
2600 *total
= s390_cost
->dr
;
2601 else /* 64 by 64 bit division */
2602 *total
= s390_cost
->dsgr
;
2604 else if (GET_MODE (x
) == SImode
) /* 32 bit division */
2605 *total
= s390_cost
->dlr
;
2606 else if (GET_MODE (x
) == SFmode
)
2608 *total
= s390_cost
->debr
;
2610 else if (GET_MODE (x
) == DFmode
)
2612 *total
= s390_cost
->ddbr
;
2614 else if (GET_MODE (x
) == TFmode
)
2616 *total
= s390_cost
->dxbr
;
2621 if (GET_MODE (x
) == SFmode
)
2622 *total
= s390_cost
->sqebr
;
2623 else if (GET_MODE (x
) == DFmode
)
2624 *total
= s390_cost
->sqdbr
;
2626 *total
= s390_cost
->sqxbr
;
2631 if (outer_code
== MULT
|| outer_code
== DIV
|| outer_code
== MOD
2632 || outer_code
== PLUS
|| outer_code
== MINUS
2633 || outer_code
== COMPARE
)
2638 *total
= COSTS_N_INSNS (1);
2639 if (GET_CODE (XEXP (x
, 0)) == AND
2640 && GET_CODE (XEXP (x
, 1)) == CONST_INT
2641 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
)
2643 rtx op0
= XEXP (XEXP (x
, 0), 0);
2644 rtx op1
= XEXP (XEXP (x
, 0), 1);
2645 rtx op2
= XEXP (x
, 1);
2647 if (memory_operand (op0
, GET_MODE (op0
))
2648 && s390_tm_ccmode (op1
, op2
, 0) != VOIDmode
)
2650 if (register_operand (op0
, GET_MODE (op0
))
2651 && s390_tm_ccmode (op1
, op2
, 1) != VOIDmode
)
2661 /* Return the cost of an address rtx ADDR. */
2664 s390_address_cost (rtx addr
, bool speed ATTRIBUTE_UNUSED
)
2666 struct s390_address ad
;
2667 if (!s390_decompose_address (addr
, &ad
))
2670 return ad
.indx
? COSTS_N_INSNS (1) + 1 : COSTS_N_INSNS (1);
2673 /* If OP is a SYMBOL_REF of a thread-local symbol, return its TLS mode,
2674 otherwise return 0. */
2677 tls_symbolic_operand (rtx op
)
2679 if (GET_CODE (op
) != SYMBOL_REF
)
2681 return SYMBOL_REF_TLS_MODEL (op
);
2684 /* Split DImode access register reference REG (on 64-bit) into its constituent
2685 low and high parts, and store them into LO and HI. Note that gen_lowpart/
2686 gen_highpart cannot be used as they assume all registers are word-sized,
2687 while our access registers have only half that size. */
2690 s390_split_access_reg (rtx reg
, rtx
*lo
, rtx
*hi
)
2692 gcc_assert (TARGET_64BIT
);
2693 gcc_assert (ACCESS_REG_P (reg
));
2694 gcc_assert (GET_MODE (reg
) == DImode
);
2695 gcc_assert (!(REGNO (reg
) & 1));
2697 *lo
= gen_rtx_REG (SImode
, REGNO (reg
) + 1);
2698 *hi
= gen_rtx_REG (SImode
, REGNO (reg
));
2701 /* Return true if OP contains a symbol reference */
2704 symbolic_reference_mentioned_p (rtx op
)
2709 if (GET_CODE (op
) == SYMBOL_REF
|| GET_CODE (op
) == LABEL_REF
)
2712 fmt
= GET_RTX_FORMAT (GET_CODE (op
));
2713 for (i
= GET_RTX_LENGTH (GET_CODE (op
)) - 1; i
>= 0; i
--)
2719 for (j
= XVECLEN (op
, i
) - 1; j
>= 0; j
--)
2720 if (symbolic_reference_mentioned_p (XVECEXP (op
, i
, j
)))
2724 else if (fmt
[i
] == 'e' && symbolic_reference_mentioned_p (XEXP (op
, i
)))
2731 /* Return true if OP contains a reference to a thread-local symbol. */
2734 tls_symbolic_reference_mentioned_p (rtx op
)
2739 if (GET_CODE (op
) == SYMBOL_REF
)
2740 return tls_symbolic_operand (op
);
2742 fmt
= GET_RTX_FORMAT (GET_CODE (op
));
2743 for (i
= GET_RTX_LENGTH (GET_CODE (op
)) - 1; i
>= 0; i
--)
2749 for (j
= XVECLEN (op
, i
) - 1; j
>= 0; j
--)
2750 if (tls_symbolic_reference_mentioned_p (XVECEXP (op
, i
, j
)))
2754 else if (fmt
[i
] == 'e' && tls_symbolic_reference_mentioned_p (XEXP (op
, i
)))
2762 /* Return true if OP is a legitimate general operand when
2763 generating PIC code. It is given that flag_pic is on
2764 and that OP satisfies CONSTANT_P or is a CONST_DOUBLE. */
2767 legitimate_pic_operand_p (rtx op
)
2769 /* Accept all non-symbolic constants. */
2770 if (!SYMBOLIC_CONST (op
))
2773 /* Reject everything else; must be handled
2774 via emit_symbolic_move. */
2778 /* Returns true if the constant value OP is a legitimate general operand.
2779 It is given that OP satisfies CONSTANT_P or is a CONST_DOUBLE. */
2782 legitimate_constant_p (rtx op
)
2784 /* Accept all non-symbolic constants. */
2785 if (!SYMBOLIC_CONST (op
))
2788 /* Accept immediate LARL operands. */
2789 if (TARGET_CPU_ZARCH
&& larl_operand (op
, VOIDmode
))
2792 /* Thread-local symbols are never legal constants. This is
2793 so that emit_call knows that computing such addresses
2794 might require a function call. */
2795 if (TLS_SYMBOLIC_CONST (op
))
2798 /* In the PIC case, symbolic constants must *not* be
2799 forced into the literal pool. We accept them here,
2800 so that they will be handled by emit_symbolic_move. */
2804 /* All remaining non-PIC symbolic constants are
2805 forced into the literal pool. */
2809 /* Determine if it's legal to put X into the constant pool. This
2810 is not possible if X contains the address of a symbol that is
2811 not constant (TLS) or not known at final link time (PIC). */
2814 s390_cannot_force_const_mem (rtx x
)
2816 switch (GET_CODE (x
))
2820 /* Accept all non-symbolic constants. */
2824 /* Labels are OK iff we are non-PIC. */
2825 return flag_pic
!= 0;
2828 /* 'Naked' TLS symbol references are never OK,
2829 non-TLS symbols are OK iff we are non-PIC. */
2830 if (tls_symbolic_operand (x
))
2833 return flag_pic
!= 0;
2836 return s390_cannot_force_const_mem (XEXP (x
, 0));
2839 return s390_cannot_force_const_mem (XEXP (x
, 0))
2840 || s390_cannot_force_const_mem (XEXP (x
, 1));
2843 switch (XINT (x
, 1))
2845 /* Only lt-relative or GOT-relative UNSPECs are OK. */
2846 case UNSPEC_LTREL_OFFSET
:
2854 case UNSPEC_GOTNTPOFF
:
2855 case UNSPEC_INDNTPOFF
:
2858 /* If the literal pool shares the code section, be put
2859 execute template placeholders into the pool as well. */
2861 return TARGET_CPU_ZARCH
;
2873 /* Returns true if the constant value OP is a legitimate general
2874 operand during and after reload. The difference to
2875 legitimate_constant_p is that this function will not accept
2876 a constant that would need to be forced to the literal pool
2877 before it can be used as operand.
2878 This function accepts all constants which can be loaded directly
2882 legitimate_reload_constant_p (rtx op
)
2884 /* Accept la(y) operands. */
2885 if (GET_CODE (op
) == CONST_INT
2886 && DISP_IN_RANGE (INTVAL (op
)))
2889 /* Accept l(g)hi/l(g)fi operands. */
2890 if (GET_CODE (op
) == CONST_INT
2891 && (CONST_OK_FOR_K (INTVAL (op
)) || CONST_OK_FOR_Os (INTVAL (op
))))
2894 /* Accept lliXX operands. */
2896 && GET_CODE (op
) == CONST_INT
2897 && trunc_int_for_mode (INTVAL (op
), word_mode
) == INTVAL (op
)
2898 && s390_single_part (op
, word_mode
, HImode
, 0) >= 0)
2902 && GET_CODE (op
) == CONST_INT
2903 && trunc_int_for_mode (INTVAL (op
), word_mode
) == INTVAL (op
)
2904 && s390_single_part (op
, word_mode
, SImode
, 0) >= 0)
2907 /* Accept larl operands. */
2908 if (TARGET_CPU_ZARCH
2909 && larl_operand (op
, VOIDmode
))
2912 /* Accept floating-point zero operands that fit into a single GPR. */
2913 if (GET_CODE (op
) == CONST_DOUBLE
2914 && s390_float_const_zero_p (op
)
2915 && GET_MODE_SIZE (GET_MODE (op
)) <= UNITS_PER_WORD
)
2918 /* Accept double-word operands that can be split. */
2919 if (GET_CODE (op
) == CONST_INT
2920 && trunc_int_for_mode (INTVAL (op
), word_mode
) != INTVAL (op
))
2922 enum machine_mode dword_mode
= word_mode
== SImode
? DImode
: TImode
;
2923 rtx hi
= operand_subword (op
, 0, 0, dword_mode
);
2924 rtx lo
= operand_subword (op
, 1, 0, dword_mode
);
2925 return legitimate_reload_constant_p (hi
)
2926 && legitimate_reload_constant_p (lo
);
2929 /* Everything else cannot be handled without reload. */
2933 /* Returns true if the constant value OP is a legitimate fp operand
2934 during and after reload.
2935 This function accepts all constants which can be loaded directly
2939 legitimate_reload_fp_constant_p (rtx op
)
2941 /* Accept floating-point zero operands if the load zero instruction
2944 && GET_CODE (op
) == CONST_DOUBLE
2945 && s390_float_const_zero_p (op
))
2951 /* Given an rtx OP being reloaded into a reg required to be in class RCLASS,
2952 return the class of reg to actually use. */
2955 s390_preferred_reload_class (rtx op
, reg_class_t rclass
)
2957 switch (GET_CODE (op
))
2959 /* Constants we cannot reload into general registers
2960 must be forced into the literal pool. */
2963 if (reg_class_subset_p (GENERAL_REGS
, rclass
)
2964 && legitimate_reload_constant_p (op
))
2965 return GENERAL_REGS
;
2966 else if (reg_class_subset_p (ADDR_REGS
, rclass
)
2967 && legitimate_reload_constant_p (op
))
2969 else if (reg_class_subset_p (FP_REGS
, rclass
)
2970 && legitimate_reload_fp_constant_p (op
))
2974 /* If a symbolic constant or a PLUS is reloaded,
2975 it is most likely being used as an address, so
2976 prefer ADDR_REGS. If 'class' is not a superset
2977 of ADDR_REGS, e.g. FP_REGS, reject this reload. */
2982 if (reg_class_subset_p (ADDR_REGS
, rclass
))
2994 /* Return true if ADDR is SYMBOL_REF + addend with addend being a
2995 multiple of ALIGNMENT and the SYMBOL_REF being naturally
2999 s390_check_symref_alignment (rtx addr
, HOST_WIDE_INT alignment
)
3001 HOST_WIDE_INT addend
;
3004 if (!s390_symref_operand_p (addr
, &symref
, &addend
))
3007 return (!SYMBOL_REF_NOT_NATURALLY_ALIGNED_P (symref
)
3008 && !(addend
& (alignment
- 1)));
3011 /* ADDR is moved into REG using larl. If ADDR isn't a valid larl
3012 operand SCRATCH is used to reload the even part of the address and
3016 s390_reload_larl_operand (rtx reg
, rtx addr
, rtx scratch
)
3018 HOST_WIDE_INT addend
;
3021 if (!s390_symref_operand_p (addr
, &symref
, &addend
))
3025 /* Easy case. The addend is even so larl will do fine. */
3026 emit_move_insn (reg
, addr
);
3029 /* We can leave the scratch register untouched if the target
3030 register is a valid base register. */
3031 if (REGNO (reg
) < FIRST_PSEUDO_REGISTER
3032 && REGNO_REG_CLASS (REGNO (reg
)) == ADDR_REGS
)
3035 gcc_assert (REGNO (scratch
) < FIRST_PSEUDO_REGISTER
);
3036 gcc_assert (REGNO_REG_CLASS (REGNO (scratch
)) == ADDR_REGS
);
3039 emit_move_insn (scratch
,
3040 gen_rtx_CONST (Pmode
,
3041 gen_rtx_PLUS (Pmode
, symref
,
3042 GEN_INT (addend
- 1))));
3044 emit_move_insn (scratch
, symref
);
3046 /* Increment the address using la in order to avoid clobbering cc. */
3047 emit_move_insn (reg
, gen_rtx_PLUS (Pmode
, scratch
, const1_rtx
));
3051 /* Generate what is necessary to move between REG and MEM using
3052 SCRATCH. The direction is given by TOMEM. */
3055 s390_reload_symref_address (rtx reg
, rtx mem
, rtx scratch
, bool tomem
)
3057 /* Reload might have pulled a constant out of the literal pool.
3058 Force it back in. */
3059 if (CONST_INT_P (mem
) || GET_CODE (mem
) == CONST_DOUBLE
3060 || GET_CODE (mem
) == CONST
)
3061 mem
= force_const_mem (GET_MODE (reg
), mem
);
3063 gcc_assert (MEM_P (mem
));
3065 /* For a load from memory we can leave the scratch register
3066 untouched if the target register is a valid base register. */
3068 && REGNO (reg
) < FIRST_PSEUDO_REGISTER
3069 && REGNO_REG_CLASS (REGNO (reg
)) == ADDR_REGS
3070 && GET_MODE (reg
) == GET_MODE (scratch
))
3073 /* Load address into scratch register. Since we can't have a
3074 secondary reload for a secondary reload we have to cover the case
3075 where larl would need a secondary reload here as well. */
3076 s390_reload_larl_operand (scratch
, XEXP (mem
, 0), scratch
);
3078 /* Now we can use a standard load/store to do the move. */
3080 emit_move_insn (replace_equiv_address (mem
, scratch
), reg
);
3082 emit_move_insn (reg
, replace_equiv_address (mem
, scratch
));
3085 /* Inform reload about cases where moving X with a mode MODE to a register in
3086 RCLASS requires an extra scratch or immediate register. Return the class
3087 needed for the immediate register. */
3090 s390_secondary_reload (bool in_p
, rtx x
, reg_class_t rclass_i
,
3091 enum machine_mode mode
, secondary_reload_info
*sri
)
3093 enum reg_class rclass
= (enum reg_class
) rclass_i
;
3095 /* Intermediate register needed. */
3096 if (reg_classes_intersect_p (CC_REGS
, rclass
))
3097 return GENERAL_REGS
;
3101 /* On z10 several optimizer steps may generate larl operands with
3104 && s390_symref_operand_p (x
, NULL
, NULL
)
3106 && !s390_check_symref_alignment (x
, 2))
3107 sri
->icode
= ((mode
== DImode
) ? CODE_FOR_reloaddi_larl_odd_addend_z10
3108 : CODE_FOR_reloadsi_larl_odd_addend_z10
);
3110 /* On z10 we need a scratch register when moving QI, TI or floating
3111 point mode values from or to a memory location with a SYMBOL_REF
3112 or if the symref addend of a SI or DI move is not aligned to the
3113 width of the access. */
3115 && s390_symref_operand_p (XEXP (x
, 0), NULL
, NULL
)
3116 && (mode
== QImode
|| mode
== TImode
|| FLOAT_MODE_P (mode
)
3117 || (!TARGET_ZARCH
&& mode
== DImode
)
3118 || ((mode
== HImode
|| mode
== SImode
|| mode
== DImode
)
3119 && (!s390_check_symref_alignment (XEXP (x
, 0),
3120 GET_MODE_SIZE (mode
))))))
3122 #define __SECONDARY_RELOAD_CASE(M,m) \
3125 sri->icode = in_p ? CODE_FOR_reload##m##di_toreg_z10 : \
3126 CODE_FOR_reload##m##di_tomem_z10; \
3128 sri->icode = in_p ? CODE_FOR_reload##m##si_toreg_z10 : \
3129 CODE_FOR_reload##m##si_tomem_z10; \
3132 switch (GET_MODE (x
))
3134 __SECONDARY_RELOAD_CASE (QI
, qi
);
3135 __SECONDARY_RELOAD_CASE (HI
, hi
);
3136 __SECONDARY_RELOAD_CASE (SI
, si
);
3137 __SECONDARY_RELOAD_CASE (DI
, di
);
3138 __SECONDARY_RELOAD_CASE (TI
, ti
);
3139 __SECONDARY_RELOAD_CASE (SF
, sf
);
3140 __SECONDARY_RELOAD_CASE (DF
, df
);
3141 __SECONDARY_RELOAD_CASE (TF
, tf
);
3142 __SECONDARY_RELOAD_CASE (SD
, sd
);
3143 __SECONDARY_RELOAD_CASE (DD
, dd
);
3144 __SECONDARY_RELOAD_CASE (TD
, td
);
3149 #undef __SECONDARY_RELOAD_CASE
3153 /* We need a scratch register when loading a PLUS expression which
3154 is not a legitimate operand of the LOAD ADDRESS instruction. */
3155 if (in_p
&& s390_plus_operand (x
, mode
))
3156 sri
->icode
= (TARGET_64BIT
?
3157 CODE_FOR_reloaddi_plus
: CODE_FOR_reloadsi_plus
);
3159 /* Performing a multiword move from or to memory we have to make sure the
3160 second chunk in memory is addressable without causing a displacement
3161 overflow. If that would be the case we calculate the address in
3162 a scratch register. */
3164 && GET_CODE (XEXP (x
, 0)) == PLUS
3165 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
3166 && !DISP_IN_RANGE (INTVAL (XEXP (XEXP (x
, 0), 1))
3167 + GET_MODE_SIZE (mode
) - 1))
3169 /* For GENERAL_REGS a displacement overflow is no problem if occurring
3170 in a s_operand address since we may fallback to lm/stm. So we only
3171 have to care about overflows in the b+i+d case. */
3172 if ((reg_classes_intersect_p (GENERAL_REGS
, rclass
)
3173 && s390_class_max_nregs (GENERAL_REGS
, mode
) > 1
3174 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == PLUS
)
3175 /* For FP_REGS no lm/stm is available so this check is triggered
3176 for displacement overflows in b+i+d and b+d like addresses. */
3177 || (reg_classes_intersect_p (FP_REGS
, rclass
)
3178 && s390_class_max_nregs (FP_REGS
, mode
) > 1))
3181 sri
->icode
= (TARGET_64BIT
?
3182 CODE_FOR_reloaddi_nonoffmem_in
:
3183 CODE_FOR_reloadsi_nonoffmem_in
);
3185 sri
->icode
= (TARGET_64BIT
?
3186 CODE_FOR_reloaddi_nonoffmem_out
:
3187 CODE_FOR_reloadsi_nonoffmem_out
);
3191 /* A scratch address register is needed when a symbolic constant is
3192 copied to r0 compiling with -fPIC. In other cases the target
3193 register might be used as temporary (see legitimize_pic_address). */
3194 if (in_p
&& SYMBOLIC_CONST (x
) && flag_pic
== 2 && rclass
!= ADDR_REGS
)
3195 sri
->icode
= (TARGET_64BIT
?
3196 CODE_FOR_reloaddi_PIC_addr
:
3197 CODE_FOR_reloadsi_PIC_addr
);
3199 /* Either scratch or no register needed. */
3203 /* Generate code to load SRC, which is PLUS that is not a
3204 legitimate operand for the LA instruction, into TARGET.
3205 SCRATCH may be used as scratch register. */
3208 s390_expand_plus_operand (rtx target
, rtx src
,
3212 struct s390_address ad
;
3214 /* src must be a PLUS; get its two operands. */
3215 gcc_assert (GET_CODE (src
) == PLUS
);
3216 gcc_assert (GET_MODE (src
) == Pmode
);
3218 /* Check if any of the two operands is already scheduled
3219 for replacement by reload. This can happen e.g. when
3220 float registers occur in an address. */
3221 sum1
= find_replacement (&XEXP (src
, 0));
3222 sum2
= find_replacement (&XEXP (src
, 1));
3223 src
= gen_rtx_PLUS (Pmode
, sum1
, sum2
);
3225 /* If the address is already strictly valid, there's nothing to do. */
3226 if (!s390_decompose_address (src
, &ad
)
3227 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
3228 || (ad
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (ad
.indx
))))
3230 /* Otherwise, one of the operands cannot be an address register;
3231 we reload its value into the scratch register. */
3232 if (true_regnum (sum1
) < 1 || true_regnum (sum1
) > 15)
3234 emit_move_insn (scratch
, sum1
);
3237 if (true_regnum (sum2
) < 1 || true_regnum (sum2
) > 15)
3239 emit_move_insn (scratch
, sum2
);
3243 /* According to the way these invalid addresses are generated
3244 in reload.c, it should never happen (at least on s390) that
3245 *neither* of the PLUS components, after find_replacements
3246 was applied, is an address register. */
3247 if (sum1
== scratch
&& sum2
== scratch
)
3253 src
= gen_rtx_PLUS (Pmode
, sum1
, sum2
);
3256 /* Emit the LOAD ADDRESS pattern. Note that reload of PLUS
3257 is only ever performed on addresses, so we can mark the
3258 sum as legitimate for LA in any case. */
3259 s390_load_address (target
, src
);
3263 /* Return true if ADDR is a valid memory address.
3264 STRICT specifies whether strict register checking applies. */
3267 s390_legitimate_address_p (enum machine_mode mode
, rtx addr
, bool strict
)
3269 struct s390_address ad
;
3272 && larl_operand (addr
, VOIDmode
)
3273 && (mode
== VOIDmode
3274 || s390_check_symref_alignment (addr
, GET_MODE_SIZE (mode
))))
3277 if (!s390_decompose_address (addr
, &ad
))
3282 if (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
3285 if (ad
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (ad
.indx
)))
3291 && !(REGNO (ad
.base
) >= FIRST_PSEUDO_REGISTER
3292 || REGNO_REG_CLASS (REGNO (ad
.base
)) == ADDR_REGS
))
3296 && !(REGNO (ad
.indx
) >= FIRST_PSEUDO_REGISTER
3297 || REGNO_REG_CLASS (REGNO (ad
.indx
)) == ADDR_REGS
))
3303 /* Return true if OP is a valid operand for the LA instruction.
3304 In 31-bit, we need to prove that the result is used as an
3305 address, as LA performs only a 31-bit addition. */
3308 legitimate_la_operand_p (rtx op
)
3310 struct s390_address addr
;
3311 if (!s390_decompose_address (op
, &addr
))
3314 return (TARGET_64BIT
|| addr
.pointer
);
3317 /* Return true if it is valid *and* preferable to use LA to
3318 compute the sum of OP1 and OP2. */
3321 preferred_la_operand_p (rtx op1
, rtx op2
)
3323 struct s390_address addr
;
3325 if (op2
!= const0_rtx
)
3326 op1
= gen_rtx_PLUS (Pmode
, op1
, op2
);
3328 if (!s390_decompose_address (op1
, &addr
))
3330 if (addr
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (addr
.base
)))
3332 if (addr
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (addr
.indx
)))
3335 /* Avoid LA instructions with index register on z196; it is
3336 preferable to use regular add instructions when possible. */
3337 if (addr
.indx
&& s390_tune
== PROCESSOR_2817_Z196
)
3340 if (!TARGET_64BIT
&& !addr
.pointer
)
3346 if ((addr
.base
&& REG_P (addr
.base
) && REG_POINTER (addr
.base
))
3347 || (addr
.indx
&& REG_P (addr
.indx
) && REG_POINTER (addr
.indx
)))
3353 /* Emit a forced load-address operation to load SRC into DST.
3354 This will use the LOAD ADDRESS instruction even in situations
3355 where legitimate_la_operand_p (SRC) returns false. */
3358 s390_load_address (rtx dst
, rtx src
)
3361 emit_move_insn (dst
, src
);
3363 emit_insn (gen_force_la_31 (dst
, src
));
3366 /* Return a legitimate reference for ORIG (an address) using the
3367 register REG. If REG is 0, a new pseudo is generated.
3369 There are two types of references that must be handled:
3371 1. Global data references must load the address from the GOT, via
3372 the PIC reg. An insn is emitted to do this load, and the reg is
3375 2. Static data references, constant pool addresses, and code labels
3376 compute the address as an offset from the GOT, whose base is in
3377 the PIC reg. Static data objects have SYMBOL_FLAG_LOCAL set to
3378 differentiate them from global data objects. The returned
3379 address is the PIC reg + an unspec constant.
3381 TARGET_LEGITIMIZE_ADDRESS_P rejects symbolic references unless the PIC
3382 reg also appears in the address. */
3385 legitimize_pic_address (rtx orig
, rtx reg
)
3391 gcc_assert (!TLS_SYMBOLIC_CONST (addr
));
3393 if (GET_CODE (addr
) == LABEL_REF
3394 || (GET_CODE (addr
) == SYMBOL_REF
&& SYMBOL_REF_LOCAL_P (addr
)))
3396 /* This is a local symbol. */
3397 if (TARGET_CPU_ZARCH
&& larl_operand (addr
, VOIDmode
))
3399 /* Access local symbols PC-relative via LARL.
3400 This is the same as in the non-PIC case, so it is
3401 handled automatically ... */
3405 /* Access local symbols relative to the GOT. */
3407 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3409 if (reload_in_progress
|| reload_completed
)
3410 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3412 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTOFF
);
3413 addr
= gen_rtx_CONST (Pmode
, addr
);
3414 addr
= force_const_mem (Pmode
, addr
);
3415 emit_move_insn (temp
, addr
);
3417 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3420 s390_load_address (reg
, new_rtx
);
3425 else if (GET_CODE (addr
) == SYMBOL_REF
)
3428 reg
= gen_reg_rtx (Pmode
);
3432 /* Assume GOT offset < 4k. This is handled the same way
3433 in both 31- and 64-bit code (@GOT). */
3435 if (reload_in_progress
|| reload_completed
)
3436 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3438 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOT
);
3439 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3440 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, new_rtx
);
3441 new_rtx
= gen_const_mem (Pmode
, new_rtx
);
3442 emit_move_insn (reg
, new_rtx
);
3445 else if (TARGET_CPU_ZARCH
)
3447 /* If the GOT offset might be >= 4k, we determine the position
3448 of the GOT entry via a PC-relative LARL (@GOTENT). */
3450 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3452 gcc_assert (REGNO (temp
) >= FIRST_PSEUDO_REGISTER
3453 || REGNO_REG_CLASS (REGNO (temp
)) == ADDR_REGS
);
3455 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTENT
);
3456 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3457 emit_move_insn (temp
, new_rtx
);
3459 new_rtx
= gen_const_mem (Pmode
, temp
);
3460 emit_move_insn (reg
, new_rtx
);
3465 /* If the GOT offset might be >= 4k, we have to load it
3466 from the literal pool (@GOT). */
3468 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3470 gcc_assert (REGNO (temp
) >= FIRST_PSEUDO_REGISTER
3471 || REGNO_REG_CLASS (REGNO (temp
)) == ADDR_REGS
);
3473 if (reload_in_progress
|| reload_completed
)
3474 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3476 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOT
);
3477 addr
= gen_rtx_CONST (Pmode
, addr
);
3478 addr
= force_const_mem (Pmode
, addr
);
3479 emit_move_insn (temp
, addr
);
3481 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3482 new_rtx
= gen_const_mem (Pmode
, new_rtx
);
3483 emit_move_insn (reg
, new_rtx
);
3489 if (GET_CODE (addr
) == CONST
)
3491 addr
= XEXP (addr
, 0);
3492 if (GET_CODE (addr
) == UNSPEC
)
3494 gcc_assert (XVECLEN (addr
, 0) == 1);
3495 switch (XINT (addr
, 1))
3497 /* If someone moved a GOT-relative UNSPEC
3498 out of the literal pool, force them back in. */
3501 new_rtx
= force_const_mem (Pmode
, orig
);
3504 /* @GOT is OK as is if small. */
3507 new_rtx
= force_const_mem (Pmode
, orig
);
3510 /* @GOTENT is OK as is. */
3514 /* @PLT is OK as is on 64-bit, must be converted to
3515 GOT-relative @PLTOFF on 31-bit. */
3517 if (!TARGET_CPU_ZARCH
)
3519 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3521 if (reload_in_progress
|| reload_completed
)
3522 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3524 addr
= XVECEXP (addr
, 0, 0);
3525 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
),
3527 addr
= gen_rtx_CONST (Pmode
, addr
);
3528 addr
= force_const_mem (Pmode
, addr
);
3529 emit_move_insn (temp
, addr
);
3531 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3534 s390_load_address (reg
, new_rtx
);
3540 /* Everything else cannot happen. */
3546 gcc_assert (GET_CODE (addr
) == PLUS
);
3548 if (GET_CODE (addr
) == PLUS
)
3550 rtx op0
= XEXP (addr
, 0), op1
= XEXP (addr
, 1);
3552 gcc_assert (!TLS_SYMBOLIC_CONST (op0
));
3553 gcc_assert (!TLS_SYMBOLIC_CONST (op1
));
3555 /* Check first to see if this is a constant offset
3556 from a local symbol reference. */
3557 if ((GET_CODE (op0
) == LABEL_REF
3558 || (GET_CODE (op0
) == SYMBOL_REF
&& SYMBOL_REF_LOCAL_P (op0
)))
3559 && GET_CODE (op1
) == CONST_INT
)
3561 if (TARGET_CPU_ZARCH
3562 && larl_operand (op0
, VOIDmode
)
3563 && INTVAL (op1
) < (HOST_WIDE_INT
)1 << 31
3564 && INTVAL (op1
) >= -((HOST_WIDE_INT
)1 << 31))
3566 if (INTVAL (op1
) & 1)
3568 /* LARL can't handle odd offsets, so emit a
3569 pair of LARL and LA. */
3570 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3572 if (!DISP_IN_RANGE (INTVAL (op1
)))
3574 HOST_WIDE_INT even
= INTVAL (op1
) - 1;
3575 op0
= gen_rtx_PLUS (Pmode
, op0
, GEN_INT (even
));
3576 op0
= gen_rtx_CONST (Pmode
, op0
);
3580 emit_move_insn (temp
, op0
);
3581 new_rtx
= gen_rtx_PLUS (Pmode
, temp
, op1
);
3585 s390_load_address (reg
, new_rtx
);
3591 /* If the offset is even, we can just use LARL.
3592 This will happen automatically. */
3597 /* Access local symbols relative to the GOT. */
3599 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3601 if (reload_in_progress
|| reload_completed
)
3602 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3604 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op0
),
3606 addr
= gen_rtx_PLUS (Pmode
, addr
, op1
);
3607 addr
= gen_rtx_CONST (Pmode
, addr
);
3608 addr
= force_const_mem (Pmode
, addr
);
3609 emit_move_insn (temp
, addr
);
3611 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3614 s390_load_address (reg
, new_rtx
);
3620 /* Now, check whether it is a GOT relative symbol plus offset
3621 that was pulled out of the literal pool. Force it back in. */
3623 else if (GET_CODE (op0
) == UNSPEC
3624 && GET_CODE (op1
) == CONST_INT
3625 && XINT (op0
, 1) == UNSPEC_GOTOFF
)
3627 gcc_assert (XVECLEN (op0
, 0) == 1);
3629 new_rtx
= force_const_mem (Pmode
, orig
);
3632 /* Otherwise, compute the sum. */
3635 base
= legitimize_pic_address (XEXP (addr
, 0), reg
);
3636 new_rtx
= legitimize_pic_address (XEXP (addr
, 1),
3637 base
== reg
? NULL_RTX
: reg
);
3638 if (GET_CODE (new_rtx
) == CONST_INT
)
3639 new_rtx
= plus_constant (base
, INTVAL (new_rtx
));
3642 if (GET_CODE (new_rtx
) == PLUS
&& CONSTANT_P (XEXP (new_rtx
, 1)))
3644 base
= gen_rtx_PLUS (Pmode
, base
, XEXP (new_rtx
, 0));
3645 new_rtx
= XEXP (new_rtx
, 1);
3647 new_rtx
= gen_rtx_PLUS (Pmode
, base
, new_rtx
);
3650 if (GET_CODE (new_rtx
) == CONST
)
3651 new_rtx
= XEXP (new_rtx
, 0);
3652 new_rtx
= force_operand (new_rtx
, 0);
3659 /* Load the thread pointer into a register. */
3662 s390_get_thread_pointer (void)
3664 rtx tp
= gen_reg_rtx (Pmode
);
3666 emit_move_insn (tp
, gen_rtx_REG (Pmode
, TP_REGNUM
));
3667 mark_reg_pointer (tp
, BITS_PER_WORD
);
3672 /* Emit a tls call insn. The call target is the SYMBOL_REF stored
3673 in s390_tls_symbol which always refers to __tls_get_offset.
3674 The returned offset is written to RESULT_REG and an USE rtx is
3675 generated for TLS_CALL. */
3677 static GTY(()) rtx s390_tls_symbol
;
3680 s390_emit_tls_call_insn (rtx result_reg
, rtx tls_call
)
3684 gcc_assert (flag_pic
);
3686 if (!s390_tls_symbol
)
3687 s390_tls_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "__tls_get_offset");
3689 insn
= s390_emit_call (s390_tls_symbol
, tls_call
, result_reg
,
3690 gen_rtx_REG (Pmode
, RETURN_REGNUM
));
3692 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), result_reg
);
3693 RTL_CONST_CALL_P (insn
) = 1;
3696 /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
3697 this (thread-local) address. REG may be used as temporary. */
3700 legitimize_tls_address (rtx addr
, rtx reg
)
3702 rtx new_rtx
, tls_call
, temp
, base
, r2
, insn
;
3704 if (GET_CODE (addr
) == SYMBOL_REF
)
3705 switch (tls_symbolic_operand (addr
))
3707 case TLS_MODEL_GLOBAL_DYNAMIC
:
3709 r2
= gen_rtx_REG (Pmode
, 2);
3710 tls_call
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_TLSGD
);
3711 new_rtx
= gen_rtx_CONST (Pmode
, tls_call
);
3712 new_rtx
= force_const_mem (Pmode
, new_rtx
);
3713 emit_move_insn (r2
, new_rtx
);
3714 s390_emit_tls_call_insn (r2
, tls_call
);
3715 insn
= get_insns ();
3718 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_NTPOFF
);
3719 temp
= gen_reg_rtx (Pmode
);
3720 emit_libcall_block (insn
, temp
, r2
, new_rtx
);
3722 new_rtx
= gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3725 s390_load_address (reg
, new_rtx
);
3730 case TLS_MODEL_LOCAL_DYNAMIC
:
3732 r2
= gen_rtx_REG (Pmode
, 2);
3733 tls_call
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, const0_rtx
), UNSPEC_TLSLDM
);
3734 new_rtx
= gen_rtx_CONST (Pmode
, tls_call
);
3735 new_rtx
= force_const_mem (Pmode
, new_rtx
);
3736 emit_move_insn (r2
, new_rtx
);
3737 s390_emit_tls_call_insn (r2
, tls_call
);
3738 insn
= get_insns ();
3741 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, const0_rtx
), UNSPEC_TLSLDM_NTPOFF
);
3742 temp
= gen_reg_rtx (Pmode
);
3743 emit_libcall_block (insn
, temp
, r2
, new_rtx
);
3745 new_rtx
= gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3746 base
= gen_reg_rtx (Pmode
);
3747 s390_load_address (base
, new_rtx
);
3749 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_DTPOFF
);
3750 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3751 new_rtx
= force_const_mem (Pmode
, new_rtx
);
3752 temp
= gen_reg_rtx (Pmode
);
3753 emit_move_insn (temp
, new_rtx
);
3755 new_rtx
= gen_rtx_PLUS (Pmode
, base
, temp
);
3758 s390_load_address (reg
, new_rtx
);
3763 case TLS_MODEL_INITIAL_EXEC
:
3766 /* Assume GOT offset < 4k. This is handled the same way
3767 in both 31- and 64-bit code. */
3769 if (reload_in_progress
|| reload_completed
)
3770 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3772 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTNTPOFF
);
3773 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3774 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, new_rtx
);
3775 new_rtx
= gen_const_mem (Pmode
, new_rtx
);
3776 temp
= gen_reg_rtx (Pmode
);
3777 emit_move_insn (temp
, new_rtx
);
3779 else if (TARGET_CPU_ZARCH
)
3781 /* If the GOT offset might be >= 4k, we determine the position
3782 of the GOT entry via a PC-relative LARL. */
3784 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_INDNTPOFF
);
3785 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3786 temp
= gen_reg_rtx (Pmode
);
3787 emit_move_insn (temp
, new_rtx
);
3789 new_rtx
= gen_const_mem (Pmode
, temp
);
3790 temp
= gen_reg_rtx (Pmode
);
3791 emit_move_insn (temp
, new_rtx
);
3795 /* If the GOT offset might be >= 4k, we have to load it
3796 from the literal pool. */
3798 if (reload_in_progress
|| reload_completed
)
3799 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3801 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTNTPOFF
);
3802 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3803 new_rtx
= force_const_mem (Pmode
, new_rtx
);
3804 temp
= gen_reg_rtx (Pmode
);
3805 emit_move_insn (temp
, new_rtx
);
3807 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3808 new_rtx
= gen_const_mem (Pmode
, new_rtx
);
3810 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, new_rtx
, addr
), UNSPEC_TLS_LOAD
);
3811 temp
= gen_reg_rtx (Pmode
);
3812 emit_insn (gen_rtx_SET (Pmode
, temp
, new_rtx
));
3816 /* In position-dependent code, load the absolute address of
3817 the GOT entry from the literal pool. */
3819 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_INDNTPOFF
);
3820 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3821 new_rtx
= force_const_mem (Pmode
, new_rtx
);
3822 temp
= gen_reg_rtx (Pmode
);
3823 emit_move_insn (temp
, new_rtx
);
3826 new_rtx
= gen_const_mem (Pmode
, new_rtx
);
3827 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, new_rtx
, addr
), UNSPEC_TLS_LOAD
);
3828 temp
= gen_reg_rtx (Pmode
);
3829 emit_insn (gen_rtx_SET (Pmode
, temp
, new_rtx
));
3832 new_rtx
= gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3835 s390_load_address (reg
, new_rtx
);
3840 case TLS_MODEL_LOCAL_EXEC
:
3841 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_NTPOFF
);
3842 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3843 new_rtx
= force_const_mem (Pmode
, new_rtx
);
3844 temp
= gen_reg_rtx (Pmode
);
3845 emit_move_insn (temp
, new_rtx
);
3847 new_rtx
= gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3850 s390_load_address (reg
, new_rtx
);
3859 else if (GET_CODE (addr
) == CONST
&& GET_CODE (XEXP (addr
, 0)) == UNSPEC
)
3861 switch (XINT (XEXP (addr
, 0), 1))
3863 case UNSPEC_INDNTPOFF
:
3864 gcc_assert (TARGET_CPU_ZARCH
);
3873 else if (GET_CODE (addr
) == CONST
&& GET_CODE (XEXP (addr
, 0)) == PLUS
3874 && GET_CODE (XEXP (XEXP (addr
, 0), 1)) == CONST_INT
)
3876 new_rtx
= XEXP (XEXP (addr
, 0), 0);
3877 if (GET_CODE (new_rtx
) != SYMBOL_REF
)
3878 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3880 new_rtx
= legitimize_tls_address (new_rtx
, reg
);
3881 new_rtx
= plus_constant (new_rtx
, INTVAL (XEXP (XEXP (addr
, 0), 1)));
3882 new_rtx
= force_operand (new_rtx
, 0);
3886 gcc_unreachable (); /* for now ... */
3891 /* Emit insns making the address in operands[1] valid for a standard
3892 move to operands[0]. operands[1] is replaced by an address which
3893 should be used instead of the former RTX to emit the move
3897 emit_symbolic_move (rtx
*operands
)
3899 rtx temp
= !can_create_pseudo_p () ? operands
[0] : gen_reg_rtx (Pmode
);
3901 if (GET_CODE (operands
[0]) == MEM
)
3902 operands
[1] = force_reg (Pmode
, operands
[1]);
3903 else if (TLS_SYMBOLIC_CONST (operands
[1]))
3904 operands
[1] = legitimize_tls_address (operands
[1], temp
);
3906 operands
[1] = legitimize_pic_address (operands
[1], temp
);
3909 /* Try machine-dependent ways of modifying an illegitimate address X
3910 to be legitimate. If we find one, return the new, valid address.
3912 OLDX is the address as it was before break_out_memory_refs was called.
3913 In some cases it is useful to look at this to decide what needs to be done.
3915 MODE is the mode of the operand pointed to by X.
3917 When -fpic is used, special handling is needed for symbolic references.
3918 See comments by legitimize_pic_address for details. */
3921 s390_legitimize_address (rtx x
, rtx oldx ATTRIBUTE_UNUSED
,
3922 enum machine_mode mode ATTRIBUTE_UNUSED
)
3924 rtx constant_term
= const0_rtx
;
3926 if (TLS_SYMBOLIC_CONST (x
))
3928 x
= legitimize_tls_address (x
, 0);
3930 if (s390_legitimate_address_p (mode
, x
, FALSE
))
3933 else if (GET_CODE (x
) == PLUS
3934 && (TLS_SYMBOLIC_CONST (XEXP (x
, 0))
3935 || TLS_SYMBOLIC_CONST (XEXP (x
, 1))))
3941 if (SYMBOLIC_CONST (x
)
3942 || (GET_CODE (x
) == PLUS
3943 && (SYMBOLIC_CONST (XEXP (x
, 0))
3944 || SYMBOLIC_CONST (XEXP (x
, 1)))))
3945 x
= legitimize_pic_address (x
, 0);
3947 if (s390_legitimate_address_p (mode
, x
, FALSE
))
3951 x
= eliminate_constant_term (x
, &constant_term
);
3953 /* Optimize loading of large displacements by splitting them
3954 into the multiple of 4K and the rest; this allows the
3955 former to be CSE'd if possible.
3957 Don't do this if the displacement is added to a register
3958 pointing into the stack frame, as the offsets will
3959 change later anyway. */
3961 if (GET_CODE (constant_term
) == CONST_INT
3962 && !TARGET_LONG_DISPLACEMENT
3963 && !DISP_IN_RANGE (INTVAL (constant_term
))
3964 && !(REG_P (x
) && REGNO_PTR_FRAME_P (REGNO (x
))))
3966 HOST_WIDE_INT lower
= INTVAL (constant_term
) & 0xfff;
3967 HOST_WIDE_INT upper
= INTVAL (constant_term
) ^ lower
;
3969 rtx temp
= gen_reg_rtx (Pmode
);
3970 rtx val
= force_operand (GEN_INT (upper
), temp
);
3972 emit_move_insn (temp
, val
);
3974 x
= gen_rtx_PLUS (Pmode
, x
, temp
);
3975 constant_term
= GEN_INT (lower
);
3978 if (GET_CODE (x
) == PLUS
)
3980 if (GET_CODE (XEXP (x
, 0)) == REG
)
3982 rtx temp
= gen_reg_rtx (Pmode
);
3983 rtx val
= force_operand (XEXP (x
, 1), temp
);
3985 emit_move_insn (temp
, val
);
3987 x
= gen_rtx_PLUS (Pmode
, XEXP (x
, 0), temp
);
3990 else if (GET_CODE (XEXP (x
, 1)) == REG
)
3992 rtx temp
= gen_reg_rtx (Pmode
);
3993 rtx val
= force_operand (XEXP (x
, 0), temp
);
3995 emit_move_insn (temp
, val
);
3997 x
= gen_rtx_PLUS (Pmode
, temp
, XEXP (x
, 1));
4001 if (constant_term
!= const0_rtx
)
4002 x
= gen_rtx_PLUS (Pmode
, x
, constant_term
);
4007 /* Try a machine-dependent way of reloading an illegitimate address AD
4008 operand. If we find one, push the reload and and return the new address.
4010 MODE is the mode of the enclosing MEM. OPNUM is the operand number
4011 and TYPE is the reload type of the current reload. */
4014 legitimize_reload_address (rtx ad
, enum machine_mode mode ATTRIBUTE_UNUSED
,
4015 int opnum
, int type
)
4017 if (!optimize
|| TARGET_LONG_DISPLACEMENT
)
4020 if (GET_CODE (ad
) == PLUS
)
4022 rtx tem
= simplify_binary_operation (PLUS
, Pmode
,
4023 XEXP (ad
, 0), XEXP (ad
, 1));
4028 if (GET_CODE (ad
) == PLUS
4029 && GET_CODE (XEXP (ad
, 0)) == REG
4030 && GET_CODE (XEXP (ad
, 1)) == CONST_INT
4031 && !DISP_IN_RANGE (INTVAL (XEXP (ad
, 1))))
4033 HOST_WIDE_INT lower
= INTVAL (XEXP (ad
, 1)) & 0xfff;
4034 HOST_WIDE_INT upper
= INTVAL (XEXP (ad
, 1)) ^ lower
;
4035 rtx cst
, tem
, new_rtx
;
4037 cst
= GEN_INT (upper
);
4038 if (!legitimate_reload_constant_p (cst
))
4039 cst
= force_const_mem (Pmode
, cst
);
4041 tem
= gen_rtx_PLUS (Pmode
, XEXP (ad
, 0), cst
);
4042 new_rtx
= gen_rtx_PLUS (Pmode
, tem
, GEN_INT (lower
));
4044 push_reload (XEXP (tem
, 1), 0, &XEXP (tem
, 1), 0,
4045 BASE_REG_CLASS
, Pmode
, VOIDmode
, 0, 0,
4046 opnum
, (enum reload_type
) type
);
4053 /* Emit code to move LEN bytes from DST to SRC. */
4056 s390_expand_movmem (rtx dst
, rtx src
, rtx len
)
4058 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) >= 0 && INTVAL (len
) <= 256)
4060 if (INTVAL (len
) > 0)
4061 emit_insn (gen_movmem_short (dst
, src
, GEN_INT (INTVAL (len
) - 1)));
4064 else if (TARGET_MVCLE
)
4066 emit_insn (gen_movmem_long (dst
, src
, convert_to_mode (Pmode
, len
, 1)));
4071 rtx dst_addr
, src_addr
, count
, blocks
, temp
;
4072 rtx loop_start_label
= gen_label_rtx ();
4073 rtx loop_end_label
= gen_label_rtx ();
4074 rtx end_label
= gen_label_rtx ();
4075 enum machine_mode mode
;
4077 mode
= GET_MODE (len
);
4078 if (mode
== VOIDmode
)
4081 dst_addr
= gen_reg_rtx (Pmode
);
4082 src_addr
= gen_reg_rtx (Pmode
);
4083 count
= gen_reg_rtx (mode
);
4084 blocks
= gen_reg_rtx (mode
);
4086 convert_move (count
, len
, 1);
4087 emit_cmp_and_jump_insns (count
, const0_rtx
,
4088 EQ
, NULL_RTX
, mode
, 1, end_label
);
4090 emit_move_insn (dst_addr
, force_operand (XEXP (dst
, 0), NULL_RTX
));
4091 emit_move_insn (src_addr
, force_operand (XEXP (src
, 0), NULL_RTX
));
4092 dst
= change_address (dst
, VOIDmode
, dst_addr
);
4093 src
= change_address (src
, VOIDmode
, src_addr
);
4095 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1,
4098 emit_move_insn (count
, temp
);
4100 temp
= expand_binop (mode
, lshr_optab
, count
, GEN_INT (8), blocks
, 1,
4103 emit_move_insn (blocks
, temp
);
4105 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
4106 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
4108 emit_label (loop_start_label
);
4111 && (GET_CODE (len
) != CONST_INT
|| INTVAL (len
) > 768))
4115 /* Issue a read prefetch for the +3 cache line. */
4116 prefetch
= gen_prefetch (gen_rtx_PLUS (Pmode
, src_addr
, GEN_INT (768)),
4117 const0_rtx
, const0_rtx
);
4118 PREFETCH_SCHEDULE_BARRIER_P (prefetch
) = true;
4119 emit_insn (prefetch
);
4121 /* Issue a write prefetch for the +3 cache line. */
4122 prefetch
= gen_prefetch (gen_rtx_PLUS (Pmode
, dst_addr
, GEN_INT (768)),
4123 const1_rtx
, const0_rtx
);
4124 PREFETCH_SCHEDULE_BARRIER_P (prefetch
) = true;
4125 emit_insn (prefetch
);
4128 emit_insn (gen_movmem_short (dst
, src
, GEN_INT (255)));
4129 s390_load_address (dst_addr
,
4130 gen_rtx_PLUS (Pmode
, dst_addr
, GEN_INT (256)));
4131 s390_load_address (src_addr
,
4132 gen_rtx_PLUS (Pmode
, src_addr
, GEN_INT (256)));
4134 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1,
4137 emit_move_insn (blocks
, temp
);
4139 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
4140 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
4142 emit_jump (loop_start_label
);
4143 emit_label (loop_end_label
);
4145 emit_insn (gen_movmem_short (dst
, src
,
4146 convert_to_mode (Pmode
, count
, 1)));
4147 emit_label (end_label
);
4151 /* Emit code to set LEN bytes at DST to VAL.
4152 Make use of clrmem if VAL is zero. */
4155 s390_expand_setmem (rtx dst
, rtx len
, rtx val
)
4157 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) == 0)
4160 gcc_assert (GET_CODE (val
) == CONST_INT
|| GET_MODE (val
) == QImode
);
4162 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) > 0 && INTVAL (len
) <= 257)
4164 if (val
== const0_rtx
&& INTVAL (len
) <= 256)
4165 emit_insn (gen_clrmem_short (dst
, GEN_INT (INTVAL (len
) - 1)));
4168 /* Initialize memory by storing the first byte. */
4169 emit_move_insn (adjust_address (dst
, QImode
, 0), val
);
4171 if (INTVAL (len
) > 1)
4173 /* Initiate 1 byte overlap move.
4174 The first byte of DST is propagated through DSTP1.
4175 Prepare a movmem for: DST+1 = DST (length = LEN - 1).
4176 DST is set to size 1 so the rest of the memory location
4177 does not count as source operand. */
4178 rtx dstp1
= adjust_address (dst
, VOIDmode
, 1);
4179 set_mem_size (dst
, const1_rtx
);
4181 emit_insn (gen_movmem_short (dstp1
, dst
,
4182 GEN_INT (INTVAL (len
) - 2)));
4187 else if (TARGET_MVCLE
)
4189 val
= force_not_mem (convert_modes (Pmode
, QImode
, val
, 1));
4190 emit_insn (gen_setmem_long (dst
, convert_to_mode (Pmode
, len
, 1), val
));
4195 rtx dst_addr
, count
, blocks
, temp
, dstp1
= NULL_RTX
;
4196 rtx loop_start_label
= gen_label_rtx ();
4197 rtx loop_end_label
= gen_label_rtx ();
4198 rtx end_label
= gen_label_rtx ();
4199 enum machine_mode mode
;
4201 mode
= GET_MODE (len
);
4202 if (mode
== VOIDmode
)
4205 dst_addr
= gen_reg_rtx (Pmode
);
4206 count
= gen_reg_rtx (mode
);
4207 blocks
= gen_reg_rtx (mode
);
4209 convert_move (count
, len
, 1);
4210 emit_cmp_and_jump_insns (count
, const0_rtx
,
4211 EQ
, NULL_RTX
, mode
, 1, end_label
);
4213 emit_move_insn (dst_addr
, force_operand (XEXP (dst
, 0), NULL_RTX
));
4214 dst
= change_address (dst
, VOIDmode
, dst_addr
);
4216 if (val
== const0_rtx
)
4217 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1,
4221 dstp1
= adjust_address (dst
, VOIDmode
, 1);
4222 set_mem_size (dst
, const1_rtx
);
4224 /* Initialize memory by storing the first byte. */
4225 emit_move_insn (adjust_address (dst
, QImode
, 0), val
);
4227 /* If count is 1 we are done. */
4228 emit_cmp_and_jump_insns (count
, const1_rtx
,
4229 EQ
, NULL_RTX
, mode
, 1, end_label
);
4231 temp
= expand_binop (mode
, add_optab
, count
, GEN_INT (-2), count
, 1,
4235 emit_move_insn (count
, temp
);
4237 temp
= expand_binop (mode
, lshr_optab
, count
, GEN_INT (8), blocks
, 1,
4240 emit_move_insn (blocks
, temp
);
4242 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
4243 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
4245 emit_label (loop_start_label
);
4248 && (GET_CODE (len
) != CONST_INT
|| INTVAL (len
) > 1024))
4250 /* Issue a write prefetch for the +4 cache line. */
4251 rtx prefetch
= gen_prefetch (gen_rtx_PLUS (Pmode
, dst_addr
,
4253 const1_rtx
, const0_rtx
);
4254 emit_insn (prefetch
);
4255 PREFETCH_SCHEDULE_BARRIER_P (prefetch
) = true;
4258 if (val
== const0_rtx
)
4259 emit_insn (gen_clrmem_short (dst
, GEN_INT (255)));
4261 emit_insn (gen_movmem_short (dstp1
, dst
, GEN_INT (255)));
4262 s390_load_address (dst_addr
,
4263 gen_rtx_PLUS (Pmode
, dst_addr
, GEN_INT (256)));
4265 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1,
4268 emit_move_insn (blocks
, temp
);
4270 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
4271 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
4273 emit_jump (loop_start_label
);
4274 emit_label (loop_end_label
);
4276 if (val
== const0_rtx
)
4277 emit_insn (gen_clrmem_short (dst
, convert_to_mode (Pmode
, count
, 1)));
4279 emit_insn (gen_movmem_short (dstp1
, dst
, convert_to_mode (Pmode
, count
, 1)));
4280 emit_label (end_label
);
4284 /* Emit code to compare LEN bytes at OP0 with those at OP1,
4285 and return the result in TARGET. */
4288 s390_expand_cmpmem (rtx target
, rtx op0
, rtx op1
, rtx len
)
4290 rtx ccreg
= gen_rtx_REG (CCUmode
, CC_REGNUM
);
4293 /* As the result of CMPINT is inverted compared to what we need,
4294 we have to swap the operands. */
4295 tmp
= op0
; op0
= op1
; op1
= tmp
;
4297 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) >= 0 && INTVAL (len
) <= 256)
4299 if (INTVAL (len
) > 0)
4301 emit_insn (gen_cmpmem_short (op0
, op1
, GEN_INT (INTVAL (len
) - 1)));
4302 emit_insn (gen_cmpint (target
, ccreg
));
4305 emit_move_insn (target
, const0_rtx
);
4307 else if (TARGET_MVCLE
)
4309 emit_insn (gen_cmpmem_long (op0
, op1
, convert_to_mode (Pmode
, len
, 1)));
4310 emit_insn (gen_cmpint (target
, ccreg
));
4314 rtx addr0
, addr1
, count
, blocks
, temp
;
4315 rtx loop_start_label
= gen_label_rtx ();
4316 rtx loop_end_label
= gen_label_rtx ();
4317 rtx end_label
= gen_label_rtx ();
4318 enum machine_mode mode
;
4320 mode
= GET_MODE (len
);
4321 if (mode
== VOIDmode
)
4324 addr0
= gen_reg_rtx (Pmode
);
4325 addr1
= gen_reg_rtx (Pmode
);
4326 count
= gen_reg_rtx (mode
);
4327 blocks
= gen_reg_rtx (mode
);
4329 convert_move (count
, len
, 1);
4330 emit_cmp_and_jump_insns (count
, const0_rtx
,
4331 EQ
, NULL_RTX
, mode
, 1, end_label
);
4333 emit_move_insn (addr0
, force_operand (XEXP (op0
, 0), NULL_RTX
));
4334 emit_move_insn (addr1
, force_operand (XEXP (op1
, 0), NULL_RTX
));
4335 op0
= change_address (op0
, VOIDmode
, addr0
);
4336 op1
= change_address (op1
, VOIDmode
, addr1
);
4338 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1,
4341 emit_move_insn (count
, temp
);
4343 temp
= expand_binop (mode
, lshr_optab
, count
, GEN_INT (8), blocks
, 1,
4346 emit_move_insn (blocks
, temp
);
4348 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
4349 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
4351 emit_label (loop_start_label
);
4354 && (GET_CODE (len
) != CONST_INT
|| INTVAL (len
) > 512))
4358 /* Issue a read prefetch for the +2 cache line of operand 1. */
4359 prefetch
= gen_prefetch (gen_rtx_PLUS (Pmode
, addr0
, GEN_INT (512)),
4360 const0_rtx
, const0_rtx
);
4361 emit_insn (prefetch
);
4362 PREFETCH_SCHEDULE_BARRIER_P (prefetch
) = true;
4364 /* Issue a read prefetch for the +2 cache line of operand 2. */
4365 prefetch
= gen_prefetch (gen_rtx_PLUS (Pmode
, addr1
, GEN_INT (512)),
4366 const0_rtx
, const0_rtx
);
4367 emit_insn (prefetch
);
4368 PREFETCH_SCHEDULE_BARRIER_P (prefetch
) = true;
4371 emit_insn (gen_cmpmem_short (op0
, op1
, GEN_INT (255)));
4372 temp
= gen_rtx_NE (VOIDmode
, ccreg
, const0_rtx
);
4373 temp
= gen_rtx_IF_THEN_ELSE (VOIDmode
, temp
,
4374 gen_rtx_LABEL_REF (VOIDmode
, end_label
), pc_rtx
);
4375 temp
= gen_rtx_SET (VOIDmode
, pc_rtx
, temp
);
4376 emit_jump_insn (temp
);
4378 s390_load_address (addr0
,
4379 gen_rtx_PLUS (Pmode
, addr0
, GEN_INT (256)));
4380 s390_load_address (addr1
,
4381 gen_rtx_PLUS (Pmode
, addr1
, GEN_INT (256)));
4383 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1,
4386 emit_move_insn (blocks
, temp
);
4388 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
4389 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
4391 emit_jump (loop_start_label
);
4392 emit_label (loop_end_label
);
4394 emit_insn (gen_cmpmem_short (op0
, op1
,
4395 convert_to_mode (Pmode
, count
, 1)));
4396 emit_label (end_label
);
4398 emit_insn (gen_cmpint (target
, ccreg
));
4403 /* Expand conditional increment or decrement using alc/slb instructions.
4404 Should generate code setting DST to either SRC or SRC + INCREMENT,
4405 depending on the result of the comparison CMP_OP0 CMP_CODE CMP_OP1.
4406 Returns true if successful, false otherwise.
4408 That makes it possible to implement some if-constructs without jumps e.g.:
4409 (borrow = CC0 | CC1 and carry = CC2 | CC3)
4410 unsigned int a, b, c;
4411 if (a < b) c++; -> CCU b > a -> CC2; c += carry;
4412 if (a < b) c--; -> CCL3 a - b -> borrow; c -= borrow;
4413 if (a <= b) c++; -> CCL3 b - a -> borrow; c += carry;
4414 if (a <= b) c--; -> CCU a <= b -> borrow; c -= borrow;
4416 Checks for EQ and NE with a nonzero value need an additional xor e.g.:
4417 if (a == b) c++; -> CCL3 a ^= b; 0 - a -> borrow; c += carry;
4418 if (a == b) c--; -> CCU a ^= b; a <= 0 -> CC0 | CC1; c -= borrow;
4419 if (a != b) c++; -> CCU a ^= b; a > 0 -> CC2; c += carry;
4420 if (a != b) c--; -> CCL3 a ^= b; 0 - a -> borrow; c -= borrow; */
4423 s390_expand_addcc (enum rtx_code cmp_code
, rtx cmp_op0
, rtx cmp_op1
,
4424 rtx dst
, rtx src
, rtx increment
)
4426 enum machine_mode cmp_mode
;
4427 enum machine_mode cc_mode
;
4433 if ((GET_MODE (cmp_op0
) == SImode
|| GET_MODE (cmp_op0
) == VOIDmode
)
4434 && (GET_MODE (cmp_op1
) == SImode
|| GET_MODE (cmp_op1
) == VOIDmode
))
4436 else if ((GET_MODE (cmp_op0
) == DImode
|| GET_MODE (cmp_op0
) == VOIDmode
)
4437 && (GET_MODE (cmp_op1
) == DImode
|| GET_MODE (cmp_op1
) == VOIDmode
))
4442 /* Try ADD LOGICAL WITH CARRY. */
4443 if (increment
== const1_rtx
)
4445 /* Determine CC mode to use. */
4446 if (cmp_code
== EQ
|| cmp_code
== NE
)
4448 if (cmp_op1
!= const0_rtx
)
4450 cmp_op0
= expand_simple_binop (cmp_mode
, XOR
, cmp_op0
, cmp_op1
,
4451 NULL_RTX
, 0, OPTAB_WIDEN
);
4452 cmp_op1
= const0_rtx
;
4455 cmp_code
= cmp_code
== EQ
? LEU
: GTU
;
4458 if (cmp_code
== LTU
|| cmp_code
== LEU
)
4463 cmp_code
= swap_condition (cmp_code
);
4480 /* Emit comparison instruction pattern. */
4481 if (!register_operand (cmp_op0
, cmp_mode
))
4482 cmp_op0
= force_reg (cmp_mode
, cmp_op0
);
4484 insn
= gen_rtx_SET (VOIDmode
, gen_rtx_REG (cc_mode
, CC_REGNUM
),
4485 gen_rtx_COMPARE (cc_mode
, cmp_op0
, cmp_op1
));
4486 /* We use insn_invalid_p here to add clobbers if required. */
4487 ret
= insn_invalid_p (emit_insn (insn
));
4490 /* Emit ALC instruction pattern. */
4491 op_res
= gen_rtx_fmt_ee (cmp_code
, GET_MODE (dst
),
4492 gen_rtx_REG (cc_mode
, CC_REGNUM
),
4495 if (src
!= const0_rtx
)
4497 if (!register_operand (src
, GET_MODE (dst
)))
4498 src
= force_reg (GET_MODE (dst
), src
);
4500 op_res
= gen_rtx_PLUS (GET_MODE (dst
), op_res
, src
);
4501 op_res
= gen_rtx_PLUS (GET_MODE (dst
), op_res
, const0_rtx
);
4504 p
= rtvec_alloc (2);
4506 gen_rtx_SET (VOIDmode
, dst
, op_res
);
4508 gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
4509 emit_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
4514 /* Try SUBTRACT LOGICAL WITH BORROW. */
4515 if (increment
== constm1_rtx
)
4517 /* Determine CC mode to use. */
4518 if (cmp_code
== EQ
|| cmp_code
== NE
)
4520 if (cmp_op1
!= const0_rtx
)
4522 cmp_op0
= expand_simple_binop (cmp_mode
, XOR
, cmp_op0
, cmp_op1
,
4523 NULL_RTX
, 0, OPTAB_WIDEN
);
4524 cmp_op1
= const0_rtx
;
4527 cmp_code
= cmp_code
== EQ
? LEU
: GTU
;
4530 if (cmp_code
== GTU
|| cmp_code
== GEU
)
4535 cmp_code
= swap_condition (cmp_code
);
4552 /* Emit comparison instruction pattern. */
4553 if (!register_operand (cmp_op0
, cmp_mode
))
4554 cmp_op0
= force_reg (cmp_mode
, cmp_op0
);
4556 insn
= gen_rtx_SET (VOIDmode
, gen_rtx_REG (cc_mode
, CC_REGNUM
),
4557 gen_rtx_COMPARE (cc_mode
, cmp_op0
, cmp_op1
));
4558 /* We use insn_invalid_p here to add clobbers if required. */
4559 ret
= insn_invalid_p (emit_insn (insn
));
4562 /* Emit SLB instruction pattern. */
4563 if (!register_operand (src
, GET_MODE (dst
)))
4564 src
= force_reg (GET_MODE (dst
), src
);
4566 op_res
= gen_rtx_MINUS (GET_MODE (dst
),
4567 gen_rtx_MINUS (GET_MODE (dst
), src
, const0_rtx
),
4568 gen_rtx_fmt_ee (cmp_code
, GET_MODE (dst
),
4569 gen_rtx_REG (cc_mode
, CC_REGNUM
),
4571 p
= rtvec_alloc (2);
4573 gen_rtx_SET (VOIDmode
, dst
, op_res
);
4575 gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
4576 emit_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
4584 /* Expand code for the insv template. Return true if successful. */
4587 s390_expand_insv (rtx dest
, rtx op1
, rtx op2
, rtx src
)
4589 int bitsize
= INTVAL (op1
);
4590 int bitpos
= INTVAL (op2
);
4592 /* On z10 we can use the risbg instruction to implement insv. */
4594 && ((GET_MODE (dest
) == DImode
&& GET_MODE (src
) == DImode
)
4595 || (GET_MODE (dest
) == SImode
&& GET_MODE (src
) == SImode
)))
4600 op
= gen_rtx_SET (GET_MODE(src
),
4601 gen_rtx_ZERO_EXTRACT (GET_MODE (dest
), dest
, op1
, op2
),
4603 clobber
= gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
4604 emit_insn (gen_rtx_PARALLEL (VOIDmode
, gen_rtvec (2, op
, clobber
)));
4609 /* We need byte alignment. */
4610 if (bitsize
% BITS_PER_UNIT
)
4614 && memory_operand (dest
, VOIDmode
)
4615 && (register_operand (src
, word_mode
)
4616 || const_int_operand (src
, VOIDmode
)))
4618 /* Emit standard pattern if possible. */
4619 enum machine_mode mode
= smallest_mode_for_size (bitsize
, MODE_INT
);
4620 if (GET_MODE_BITSIZE (mode
) == bitsize
)
4621 emit_move_insn (adjust_address (dest
, mode
, 0), gen_lowpart (mode
, src
));
4623 /* (set (ze (mem)) (const_int)). */
4624 else if (const_int_operand (src
, VOIDmode
))
4626 int size
= bitsize
/ BITS_PER_UNIT
;
4627 rtx src_mem
= adjust_address (force_const_mem (word_mode
, src
), BLKmode
,
4628 GET_MODE_SIZE (word_mode
) - size
);
4630 dest
= adjust_address (dest
, BLKmode
, 0);
4631 set_mem_size (dest
, GEN_INT (size
));
4632 s390_expand_movmem (dest
, src_mem
, GEN_INT (size
));
4635 /* (set (ze (mem)) (reg)). */
4636 else if (register_operand (src
, word_mode
))
4638 if (bitsize
<= GET_MODE_BITSIZE (SImode
))
4639 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
, op1
,
4643 /* Emit st,stcmh sequence. */
4644 int stcmh_width
= bitsize
- GET_MODE_BITSIZE (SImode
);
4645 int size
= stcmh_width
/ BITS_PER_UNIT
;
4647 emit_move_insn (adjust_address (dest
, SImode
, size
),
4648 gen_lowpart (SImode
, src
));
4649 set_mem_size (dest
, GEN_INT (size
));
4650 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
, GEN_INT
4651 (stcmh_width
), const0_rtx
),
4652 gen_rtx_LSHIFTRT (word_mode
, src
, GEN_INT
4653 (GET_MODE_BITSIZE (SImode
))));
4662 /* (set (ze (reg)) (const_int)). */
4664 && register_operand (dest
, word_mode
)
4665 && (bitpos
% 16) == 0
4666 && (bitsize
% 16) == 0
4667 && const_int_operand (src
, VOIDmode
))
4669 HOST_WIDE_INT val
= INTVAL (src
);
4670 int regpos
= bitpos
+ bitsize
;
4672 while (regpos
> bitpos
)
4674 enum machine_mode putmode
;
4677 if (TARGET_EXTIMM
&& (regpos
% 32 == 0) && (regpos
>= bitpos
+ 32))
4682 putsize
= GET_MODE_BITSIZE (putmode
);
4684 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
,
4687 gen_int_mode (val
, putmode
));
4690 gcc_assert (regpos
== bitpos
);
4697 /* A subroutine of s390_expand_cs_hqi and s390_expand_atomic which returns a
4698 register that holds VAL of mode MODE shifted by COUNT bits. */
4701 s390_expand_mask_and_shift (rtx val
, enum machine_mode mode
, rtx count
)
4703 val
= expand_simple_binop (SImode
, AND
, val
, GEN_INT (GET_MODE_MASK (mode
)),
4704 NULL_RTX
, 1, OPTAB_DIRECT
);
4705 return expand_simple_binop (SImode
, ASHIFT
, val
, count
,
4706 NULL_RTX
, 1, OPTAB_DIRECT
);
4709 /* Structure to hold the initial parameters for a compare_and_swap operation
4710 in HImode and QImode. */
4712 struct alignment_context
4714 rtx memsi
; /* SI aligned memory location. */
4715 rtx shift
; /* Bit offset with regard to lsb. */
4716 rtx modemask
; /* Mask of the HQImode shifted by SHIFT bits. */
4717 rtx modemaski
; /* ~modemask */
4718 bool aligned
; /* True if memory is aligned, false else. */
4721 /* A subroutine of s390_expand_cs_hqi and s390_expand_atomic to initialize
4722 structure AC for transparent simplifying, if the memory alignment is known
4723 to be at least 32bit. MEM is the memory location for the actual operation
4724 and MODE its mode. */
4727 init_alignment_context (struct alignment_context
*ac
, rtx mem
,
4728 enum machine_mode mode
)
4730 ac
->shift
= GEN_INT (GET_MODE_SIZE (SImode
) - GET_MODE_SIZE (mode
));
4731 ac
->aligned
= (MEM_ALIGN (mem
) >= GET_MODE_BITSIZE (SImode
));
4734 ac
->memsi
= adjust_address (mem
, SImode
, 0); /* Memory is aligned. */
4737 /* Alignment is unknown. */
4738 rtx byteoffset
, addr
, align
;
4740 /* Force the address into a register. */
4741 addr
= force_reg (Pmode
, XEXP (mem
, 0));
4743 /* Align it to SImode. */
4744 align
= expand_simple_binop (Pmode
, AND
, addr
,
4745 GEN_INT (-GET_MODE_SIZE (SImode
)),
4746 NULL_RTX
, 1, OPTAB_DIRECT
);
4748 ac
->memsi
= gen_rtx_MEM (SImode
, align
);
4749 MEM_VOLATILE_P (ac
->memsi
) = MEM_VOLATILE_P (mem
);
4750 set_mem_alias_set (ac
->memsi
, ALIAS_SET_MEMORY_BARRIER
);
4751 set_mem_align (ac
->memsi
, GET_MODE_BITSIZE (SImode
));
4753 /* Calculate shiftcount. */
4754 byteoffset
= expand_simple_binop (Pmode
, AND
, addr
,
4755 GEN_INT (GET_MODE_SIZE (SImode
) - 1),
4756 NULL_RTX
, 1, OPTAB_DIRECT
);
4757 /* As we already have some offset, evaluate the remaining distance. */
4758 ac
->shift
= expand_simple_binop (SImode
, MINUS
, ac
->shift
, byteoffset
,
4759 NULL_RTX
, 1, OPTAB_DIRECT
);
4762 /* Shift is the byte count, but we need the bitcount. */
4763 ac
->shift
= expand_simple_binop (SImode
, MULT
, ac
->shift
, GEN_INT (BITS_PER_UNIT
),
4764 NULL_RTX
, 1, OPTAB_DIRECT
);
4765 /* Calculate masks. */
4766 ac
->modemask
= expand_simple_binop (SImode
, ASHIFT
,
4767 GEN_INT (GET_MODE_MASK (mode
)), ac
->shift
,
4768 NULL_RTX
, 1, OPTAB_DIRECT
);
4769 ac
->modemaski
= expand_simple_unop (SImode
, NOT
, ac
->modemask
, NULL_RTX
, 1);
4772 /* Expand an atomic compare and swap operation for HImode and QImode. MEM is
4773 the memory location, CMP the old value to compare MEM with and NEW_RTX the value
4774 to set if CMP == MEM.
4775 CMP is never in memory for compare_and_swap_cc because
4776 expand_bool_compare_and_swap puts it into a register for later compare. */
4779 s390_expand_cs_hqi (enum machine_mode mode
, rtx target
, rtx mem
, rtx cmp
, rtx new_rtx
)
4781 struct alignment_context ac
;
4782 rtx cmpv
, newv
, val
, resv
, cc
;
4783 rtx res
= gen_reg_rtx (SImode
);
4784 rtx csloop
= gen_label_rtx ();
4785 rtx csend
= gen_label_rtx ();
4787 gcc_assert (register_operand (target
, VOIDmode
));
4788 gcc_assert (MEM_P (mem
));
4790 init_alignment_context (&ac
, mem
, mode
);
4792 /* Shift the values to the correct bit positions. */
4793 if (!(ac
.aligned
&& MEM_P (cmp
)))
4794 cmp
= s390_expand_mask_and_shift (cmp
, mode
, ac
.shift
);
4795 if (!(ac
.aligned
&& MEM_P (new_rtx
)))
4796 new_rtx
= s390_expand_mask_and_shift (new_rtx
, mode
, ac
.shift
);
4798 /* Load full word. Subsequent loads are performed by CS. */
4799 val
= expand_simple_binop (SImode
, AND
, ac
.memsi
, ac
.modemaski
,
4800 NULL_RTX
, 1, OPTAB_DIRECT
);
4802 /* Start CS loop. */
4803 emit_label (csloop
);
4804 /* val = "<mem>00..0<mem>"
4805 * cmp = "00..0<cmp>00..0"
4806 * new = "00..0<new>00..0"
4809 /* Patch cmp and new with val at correct position. */
4810 if (ac
.aligned
&& MEM_P (cmp
))
4812 cmpv
= force_reg (SImode
, val
);
4813 store_bit_field (cmpv
, GET_MODE_BITSIZE (mode
), 0, SImode
, cmp
);
4816 cmpv
= force_reg (SImode
, expand_simple_binop (SImode
, IOR
, cmp
, val
,
4817 NULL_RTX
, 1, OPTAB_DIRECT
));
4818 if (ac
.aligned
&& MEM_P (new_rtx
))
4820 newv
= force_reg (SImode
, val
);
4821 store_bit_field (newv
, GET_MODE_BITSIZE (mode
), 0, SImode
, new_rtx
);
4824 newv
= force_reg (SImode
, expand_simple_binop (SImode
, IOR
, new_rtx
, val
,
4825 NULL_RTX
, 1, OPTAB_DIRECT
));
4827 /* Jump to end if we're done (likely?). */
4828 s390_emit_jump (csend
, s390_emit_compare_and_swap (EQ
, res
, ac
.memsi
,
4831 /* Check for changes outside mode. */
4832 resv
= expand_simple_binop (SImode
, AND
, res
, ac
.modemaski
,
4833 NULL_RTX
, 1, OPTAB_DIRECT
);
4834 cc
= s390_emit_compare (NE
, resv
, val
);
4835 emit_move_insn (val
, resv
);
4836 /* Loop internal if so. */
4837 s390_emit_jump (csloop
, cc
);
4841 /* Return the correct part of the bitfield. */
4842 convert_move (target
, expand_simple_binop (SImode
, LSHIFTRT
, res
, ac
.shift
,
4843 NULL_RTX
, 1, OPTAB_DIRECT
), 1);
4846 /* Expand an atomic operation CODE of mode MODE. MEM is the memory location
4847 and VAL the value to play with. If AFTER is true then store the value
4848 MEM holds after the operation, if AFTER is false then store the value MEM
4849 holds before the operation. If TARGET is zero then discard that value, else
4850 store it to TARGET. */
4853 s390_expand_atomic (enum machine_mode mode
, enum rtx_code code
,
4854 rtx target
, rtx mem
, rtx val
, bool after
)
4856 struct alignment_context ac
;
4858 rtx new_rtx
= gen_reg_rtx (SImode
);
4859 rtx orig
= gen_reg_rtx (SImode
);
4860 rtx csloop
= gen_label_rtx ();
4862 gcc_assert (!target
|| register_operand (target
, VOIDmode
));
4863 gcc_assert (MEM_P (mem
));
4865 init_alignment_context (&ac
, mem
, mode
);
4867 /* Shift val to the correct bit positions.
4868 Preserve "icm", but prevent "ex icm". */
4869 if (!(ac
.aligned
&& code
== SET
&& MEM_P (val
)))
4870 val
= s390_expand_mask_and_shift (val
, mode
, ac
.shift
);
4872 /* Further preparation insns. */
4873 if (code
== PLUS
|| code
== MINUS
)
4874 emit_move_insn (orig
, val
);
4875 else if (code
== MULT
|| code
== AND
) /* val = "11..1<val>11..1" */
4876 val
= expand_simple_binop (SImode
, XOR
, val
, ac
.modemaski
,
4877 NULL_RTX
, 1, OPTAB_DIRECT
);
4879 /* Load full word. Subsequent loads are performed by CS. */
4880 cmp
= force_reg (SImode
, ac
.memsi
);
4882 /* Start CS loop. */
4883 emit_label (csloop
);
4884 emit_move_insn (new_rtx
, cmp
);
4886 /* Patch new with val at correct position. */
4891 val
= expand_simple_binop (SImode
, code
, new_rtx
, orig
,
4892 NULL_RTX
, 1, OPTAB_DIRECT
);
4893 val
= expand_simple_binop (SImode
, AND
, val
, ac
.modemask
,
4894 NULL_RTX
, 1, OPTAB_DIRECT
);
4897 if (ac
.aligned
&& MEM_P (val
))
4898 store_bit_field (new_rtx
, GET_MODE_BITSIZE (mode
), 0, SImode
, val
);
4901 new_rtx
= expand_simple_binop (SImode
, AND
, new_rtx
, ac
.modemaski
,
4902 NULL_RTX
, 1, OPTAB_DIRECT
);
4903 new_rtx
= expand_simple_binop (SImode
, IOR
, new_rtx
, val
,
4904 NULL_RTX
, 1, OPTAB_DIRECT
);
4910 new_rtx
= expand_simple_binop (SImode
, code
, new_rtx
, val
,
4911 NULL_RTX
, 1, OPTAB_DIRECT
);
4913 case MULT
: /* NAND */
4914 new_rtx
= expand_simple_binop (SImode
, AND
, new_rtx
, val
,
4915 NULL_RTX
, 1, OPTAB_DIRECT
);
4916 new_rtx
= expand_simple_binop (SImode
, XOR
, new_rtx
, ac
.modemask
,
4917 NULL_RTX
, 1, OPTAB_DIRECT
);
4923 s390_emit_jump (csloop
, s390_emit_compare_and_swap (NE
, cmp
,
4924 ac
.memsi
, cmp
, new_rtx
));
4926 /* Return the correct part of the bitfield. */
4928 convert_move (target
, expand_simple_binop (SImode
, LSHIFTRT
,
4929 after
? new_rtx
: cmp
, ac
.shift
,
4930 NULL_RTX
, 1, OPTAB_DIRECT
), 1);
4933 /* This is called from dwarf2out.c via TARGET_ASM_OUTPUT_DWARF_DTPREL.
4934 We need to emit DTP-relative relocations. */
4936 static void s390_output_dwarf_dtprel (FILE *, int, rtx
) ATTRIBUTE_UNUSED
;
4939 s390_output_dwarf_dtprel (FILE *file
, int size
, rtx x
)
4944 fputs ("\t.long\t", file
);
4947 fputs ("\t.quad\t", file
);
4952 output_addr_const (file
, x
);
4953 fputs ("@DTPOFF", file
);
4956 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
4957 /* Implement TARGET_MANGLE_TYPE. */
4960 s390_mangle_type (const_tree type
)
4962 if (TYPE_MAIN_VARIANT (type
) == long_double_type_node
4963 && TARGET_LONG_DOUBLE_128
)
4966 /* For all other types, use normal C++ mangling. */
4971 /* In the name of slightly smaller debug output, and to cater to
4972 general assembler lossage, recognize various UNSPEC sequences
4973 and turn them back into a direct symbol reference. */
4976 s390_delegitimize_address (rtx orig_x
)
4980 orig_x
= delegitimize_mem_from_attrs (orig_x
);
4982 if (GET_CODE (x
) != MEM
)
4986 if (GET_CODE (x
) == PLUS
4987 && GET_CODE (XEXP (x
, 1)) == CONST
4988 && GET_CODE (XEXP (x
, 0)) == REG
4989 && REGNO (XEXP (x
, 0)) == PIC_OFFSET_TABLE_REGNUM
)
4991 y
= XEXP (XEXP (x
, 1), 0);
4992 if (GET_CODE (y
) == UNSPEC
4993 && XINT (y
, 1) == UNSPEC_GOT
)
4994 return XVECEXP (y
, 0, 0);
4998 if (GET_CODE (x
) == CONST
)
5001 if (GET_CODE (y
) == UNSPEC
5002 && XINT (y
, 1) == UNSPEC_GOTENT
)
5003 return XVECEXP (y
, 0, 0);
5010 /* Output operand OP to stdio stream FILE.
5011 OP is an address (register + offset) which is not used to address data;
5012 instead the rightmost bits are interpreted as the value. */
5015 print_shift_count_operand (FILE *file
, rtx op
)
5017 HOST_WIDE_INT offset
;
5020 /* Extract base register and offset. */
5021 if (!s390_decompose_shift_count (op
, &base
, &offset
))
5027 gcc_assert (GET_CODE (base
) == REG
);
5028 gcc_assert (REGNO (base
) < FIRST_PSEUDO_REGISTER
);
5029 gcc_assert (REGNO_REG_CLASS (REGNO (base
)) == ADDR_REGS
);
5032 /* Offsets are constricted to twelve bits. */
5033 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, offset
& ((1 << 12) - 1));
5035 fprintf (file
, "(%s)", reg_names
[REGNO (base
)]);
5038 /* See 'get_some_local_dynamic_name'. */
5041 get_some_local_dynamic_name_1 (rtx
*px
, void *data ATTRIBUTE_UNUSED
)
5045 if (GET_CODE (x
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (x
))
5047 x
= get_pool_constant (x
);
5048 return for_each_rtx (&x
, get_some_local_dynamic_name_1
, 0);
5051 if (GET_CODE (x
) == SYMBOL_REF
5052 && tls_symbolic_operand (x
) == TLS_MODEL_LOCAL_DYNAMIC
)
5054 cfun
->machine
->some_ld_name
= XSTR (x
, 0);
5061 /* Locate some local-dynamic symbol still in use by this function
5062 so that we can print its name in local-dynamic base patterns. */
5065 get_some_local_dynamic_name (void)
5069 if (cfun
->machine
->some_ld_name
)
5070 return cfun
->machine
->some_ld_name
;
5072 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5074 && for_each_rtx (&PATTERN (insn
), get_some_local_dynamic_name_1
, 0))
5075 return cfun
->machine
->some_ld_name
;
5080 /* Output machine-dependent UNSPECs occurring in address constant X
5081 in assembler syntax to stdio stream FILE. Returns true if the
5082 constant X could be recognized, false otherwise. */
5085 s390_output_addr_const_extra (FILE *file
, rtx x
)
5087 if (GET_CODE (x
) == UNSPEC
&& XVECLEN (x
, 0) == 1)
5088 switch (XINT (x
, 1))
5091 output_addr_const (file
, XVECEXP (x
, 0, 0));
5092 fprintf (file
, "@GOTENT");
5095 output_addr_const (file
, XVECEXP (x
, 0, 0));
5096 fprintf (file
, "@GOT");
5099 output_addr_const (file
, XVECEXP (x
, 0, 0));
5100 fprintf (file
, "@GOTOFF");
5103 output_addr_const (file
, XVECEXP (x
, 0, 0));
5104 fprintf (file
, "@PLT");
5107 output_addr_const (file
, XVECEXP (x
, 0, 0));
5108 fprintf (file
, "@PLTOFF");
5111 output_addr_const (file
, XVECEXP (x
, 0, 0));
5112 fprintf (file
, "@TLSGD");
5115 assemble_name (file
, get_some_local_dynamic_name ());
5116 fprintf (file
, "@TLSLDM");
5119 output_addr_const (file
, XVECEXP (x
, 0, 0));
5120 fprintf (file
, "@DTPOFF");
5123 output_addr_const (file
, XVECEXP (x
, 0, 0));
5124 fprintf (file
, "@NTPOFF");
5126 case UNSPEC_GOTNTPOFF
:
5127 output_addr_const (file
, XVECEXP (x
, 0, 0));
5128 fprintf (file
, "@GOTNTPOFF");
5130 case UNSPEC_INDNTPOFF
:
5131 output_addr_const (file
, XVECEXP (x
, 0, 0));
5132 fprintf (file
, "@INDNTPOFF");
5136 if (GET_CODE (x
) == UNSPEC
&& XVECLEN (x
, 0) == 2)
5137 switch (XINT (x
, 1))
5139 case UNSPEC_POOL_OFFSET
:
5140 x
= gen_rtx_MINUS (GET_MODE (x
), XVECEXP (x
, 0, 0), XVECEXP (x
, 0, 1));
5141 output_addr_const (file
, x
);
5147 /* Output address operand ADDR in assembler syntax to
5148 stdio stream FILE. */
5151 print_operand_address (FILE *file
, rtx addr
)
5153 struct s390_address ad
;
5155 if (s390_symref_operand_p (addr
, NULL
, NULL
))
5159 output_operand_lossage ("symbolic memory references are "
5160 "only supported on z10 or later");
5163 output_addr_const (file
, addr
);
5167 if (!s390_decompose_address (addr
, &ad
)
5168 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
5169 || (ad
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (ad
.indx
))))
5170 output_operand_lossage ("cannot decompose address");
5173 output_addr_const (file
, ad
.disp
);
5175 fprintf (file
, "0");
5177 if (ad
.base
&& ad
.indx
)
5178 fprintf (file
, "(%s,%s)", reg_names
[REGNO (ad
.indx
)],
5179 reg_names
[REGNO (ad
.base
)]);
5181 fprintf (file
, "(%s)", reg_names
[REGNO (ad
.base
)]);
5184 /* Output operand X in assembler syntax to stdio stream FILE.
5185 CODE specified the format flag. The following format flags
5188 'C': print opcode suffix for branch condition.
5189 'D': print opcode suffix for inverse branch condition.
5190 'E': print opcode suffix for branch on index instruction.
5191 'J': print tls_load/tls_gdcall/tls_ldcall suffix
5192 'G': print the size of the operand in bytes.
5193 'O': print only the displacement of a memory reference.
5194 'R': print only the base register of a memory reference.
5195 'S': print S-type memory reference (base+displacement).
5196 'N': print the second word of a DImode operand.
5197 'M': print the second word of a TImode operand.
5198 'Y': print shift count operand.
5200 'b': print integer X as if it's an unsigned byte.
5201 'c': print integer X as if it's an signed byte.
5202 'x': print integer X as if it's an unsigned halfword.
5203 'h': print integer X as if it's a signed halfword.
5204 'i': print the first nonzero HImode part of X.
5205 'j': print the first HImode part unequal to -1 of X.
5206 'k': print the first nonzero SImode part of X.
5207 'm': print the first SImode part unequal to -1 of X.
5208 'o': print integer X as if it's an unsigned 32bit word. */
5211 print_operand (FILE *file
, rtx x
, int code
)
5216 fprintf (file
, s390_branch_condition_mnemonic (x
, FALSE
));
5220 fprintf (file
, s390_branch_condition_mnemonic (x
, TRUE
));
5224 if (GET_CODE (x
) == LE
)
5225 fprintf (file
, "l");
5226 else if (GET_CODE (x
) == GT
)
5227 fprintf (file
, "h");
5229 output_operand_lossage ("invalid comparison operator "
5230 "for 'E' output modifier");
5234 if (GET_CODE (x
) == SYMBOL_REF
)
5236 fprintf (file
, "%s", ":tls_load:");
5237 output_addr_const (file
, x
);
5239 else if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_TLSGD
)
5241 fprintf (file
, "%s", ":tls_gdcall:");
5242 output_addr_const (file
, XVECEXP (x
, 0, 0));
5244 else if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_TLSLDM
)
5246 fprintf (file
, "%s", ":tls_ldcall:");
5247 assemble_name (file
, get_some_local_dynamic_name ());
5250 output_operand_lossage ("invalid reference for 'J' output modifier");
5254 fprintf (file
, "%u", GET_MODE_SIZE (GET_MODE (x
)));
5259 struct s390_address ad
;
5264 output_operand_lossage ("memory reference expected for "
5265 "'O' output modifier");
5269 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
5272 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
5275 output_operand_lossage ("invalid address for 'O' output modifier");
5280 output_addr_const (file
, ad
.disp
);
5282 fprintf (file
, "0");
5288 struct s390_address ad
;
5293 output_operand_lossage ("memory reference expected for "
5294 "'R' output modifier");
5298 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
5301 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
5304 output_operand_lossage ("invalid address for 'R' output modifier");
5309 fprintf (file
, "%s", reg_names
[REGNO (ad
.base
)]);
5311 fprintf (file
, "0");
5317 struct s390_address ad
;
5322 output_operand_lossage ("memory reference expected for "
5323 "'S' output modifier");
5326 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
5329 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
5332 output_operand_lossage ("invalid address for 'S' output modifier");
5337 output_addr_const (file
, ad
.disp
);
5339 fprintf (file
, "0");
5342 fprintf (file
, "(%s)", reg_names
[REGNO (ad
.base
)]);
5347 if (GET_CODE (x
) == REG
)
5348 x
= gen_rtx_REG (GET_MODE (x
), REGNO (x
) + 1);
5349 else if (GET_CODE (x
) == MEM
)
5350 x
= change_address (x
, VOIDmode
, plus_constant (XEXP (x
, 0), 4));
5352 output_operand_lossage ("register or memory expression expected "
5353 "for 'N' output modifier");
5357 if (GET_CODE (x
) == REG
)
5358 x
= gen_rtx_REG (GET_MODE (x
), REGNO (x
) + 1);
5359 else if (GET_CODE (x
) == MEM
)
5360 x
= change_address (x
, VOIDmode
, plus_constant (XEXP (x
, 0), 8));
5362 output_operand_lossage ("register or memory expression expected "
5363 "for 'M' output modifier");
5367 print_shift_count_operand (file
, x
);
5371 switch (GET_CODE (x
))
5374 fprintf (file
, "%s", reg_names
[REGNO (x
)]);
5378 output_address (XEXP (x
, 0));
5385 output_addr_const (file
, x
);
5390 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
) & 0xff);
5391 else if (code
== 'c')
5392 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, ((INTVAL (x
) & 0xff) ^ 0x80) - 0x80);
5393 else if (code
== 'x')
5394 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
) & 0xffff);
5395 else if (code
== 'h')
5396 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, ((INTVAL (x
) & 0xffff) ^ 0x8000) - 0x8000);
5397 else if (code
== 'i')
5398 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
5399 s390_extract_part (x
, HImode
, 0));
5400 else if (code
== 'j')
5401 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
5402 s390_extract_part (x
, HImode
, -1));
5403 else if (code
== 'k')
5404 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
5405 s390_extract_part (x
, SImode
, 0));
5406 else if (code
== 'm')
5407 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
5408 s390_extract_part (x
, SImode
, -1));
5409 else if (code
== 'o')
5410 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
) & 0xffffffff);
5412 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
));
5416 gcc_assert (GET_MODE (x
) == VOIDmode
);
5418 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, CONST_DOUBLE_LOW (x
) & 0xff);
5419 else if (code
== 'x')
5420 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, CONST_DOUBLE_LOW (x
) & 0xffff);
5421 else if (code
== 'h')
5422 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
5423 ((CONST_DOUBLE_LOW (x
) & 0xffff) ^ 0x8000) - 0x8000);
5427 output_operand_lossage ("invalid constant - try using "
5428 "an output modifier");
5430 output_operand_lossage ("invalid constant for output modifier '%c'",
5437 output_operand_lossage ("invalid expression - try using "
5438 "an output modifier");
5440 output_operand_lossage ("invalid expression for output "
5441 "modifier '%c'", code
);
5446 /* Target hook for assembling integer objects. We need to define it
5447 here to work a round a bug in some versions of GAS, which couldn't
5448 handle values smaller than INT_MIN when printed in decimal. */
5451 s390_assemble_integer (rtx x
, unsigned int size
, int aligned_p
)
5453 if (size
== 8 && aligned_p
5454 && GET_CODE (x
) == CONST_INT
&& INTVAL (x
) < INT_MIN
)
5456 fprintf (asm_out_file
, "\t.quad\t" HOST_WIDE_INT_PRINT_HEX
"\n",
5460 return default_assemble_integer (x
, size
, aligned_p
);
5463 /* Returns true if register REGNO is used for forming
5464 a memory address in expression X. */
5467 reg_used_in_mem_p (int regno
, rtx x
)
5469 enum rtx_code code
= GET_CODE (x
);
5475 if (refers_to_regno_p (regno
, regno
+1,
5479 else if (code
== SET
5480 && GET_CODE (SET_DEST (x
)) == PC
)
5482 if (refers_to_regno_p (regno
, regno
+1,
5487 fmt
= GET_RTX_FORMAT (code
);
5488 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
5491 && reg_used_in_mem_p (regno
, XEXP (x
, i
)))
5494 else if (fmt
[i
] == 'E')
5495 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
5496 if (reg_used_in_mem_p (regno
, XVECEXP (x
, i
, j
)))
5502 /* Returns true if expression DEP_RTX sets an address register
5503 used by instruction INSN to address memory. */
5506 addr_generation_dependency_p (rtx dep_rtx
, rtx insn
)
5510 if (GET_CODE (dep_rtx
) == INSN
)
5511 dep_rtx
= PATTERN (dep_rtx
);
5513 if (GET_CODE (dep_rtx
) == SET
)
5515 target
= SET_DEST (dep_rtx
);
5516 if (GET_CODE (target
) == STRICT_LOW_PART
)
5517 target
= XEXP (target
, 0);
5518 while (GET_CODE (target
) == SUBREG
)
5519 target
= SUBREG_REG (target
);
5521 if (GET_CODE (target
) == REG
)
5523 int regno
= REGNO (target
);
5525 if (s390_safe_attr_type (insn
) == TYPE_LA
)
5527 pat
= PATTERN (insn
);
5528 if (GET_CODE (pat
) == PARALLEL
)
5530 gcc_assert (XVECLEN (pat
, 0) == 2);
5531 pat
= XVECEXP (pat
, 0, 0);
5533 gcc_assert (GET_CODE (pat
) == SET
);
5534 return refers_to_regno_p (regno
, regno
+1, SET_SRC (pat
), 0);
5536 else if (get_attr_atype (insn
) == ATYPE_AGEN
)
5537 return reg_used_in_mem_p (regno
, PATTERN (insn
));
5543 /* Return 1, if dep_insn sets register used in insn in the agen unit. */
5546 s390_agen_dep_p (rtx dep_insn
, rtx insn
)
5548 rtx dep_rtx
= PATTERN (dep_insn
);
5551 if (GET_CODE (dep_rtx
) == SET
5552 && addr_generation_dependency_p (dep_rtx
, insn
))
5554 else if (GET_CODE (dep_rtx
) == PARALLEL
)
5556 for (i
= 0; i
< XVECLEN (dep_rtx
, 0); i
++)
5558 if (addr_generation_dependency_p (XVECEXP (dep_rtx
, 0, i
), insn
))
5566 /* A C statement (sans semicolon) to update the integer scheduling priority
5567 INSN_PRIORITY (INSN). Increase the priority to execute the INSN earlier,
5568 reduce the priority to execute INSN later. Do not define this macro if
5569 you do not need to adjust the scheduling priorities of insns.
5571 A STD instruction should be scheduled earlier,
5572 in order to use the bypass. */
5574 s390_adjust_priority (rtx insn ATTRIBUTE_UNUSED
, int priority
)
5576 if (! INSN_P (insn
))
5579 if (s390_tune
!= PROCESSOR_2084_Z990
5580 && s390_tune
!= PROCESSOR_2094_Z9_109
5581 && s390_tune
!= PROCESSOR_2097_Z10
5582 && s390_tune
!= PROCESSOR_2817_Z196
)
5585 switch (s390_safe_attr_type (insn
))
5589 priority
= priority
<< 3;
5593 priority
= priority
<< 1;
5602 /* The number of instructions that can be issued per cycle. */
5605 s390_issue_rate (void)
5609 case PROCESSOR_2084_Z990
:
5610 case PROCESSOR_2094_Z9_109
:
5611 case PROCESSOR_2817_Z196
:
5613 case PROCESSOR_2097_Z10
:
5621 s390_first_cycle_multipass_dfa_lookahead (void)
5626 /* Annotate every literal pool reference in X by an UNSPEC_LTREF expression.
5627 Fix up MEMs as required. */
5630 annotate_constant_pool_refs (rtx
*x
)
5635 gcc_assert (GET_CODE (*x
) != SYMBOL_REF
5636 || !CONSTANT_POOL_ADDRESS_P (*x
));
5638 /* Literal pool references can only occur inside a MEM ... */
5639 if (GET_CODE (*x
) == MEM
)
5641 rtx memref
= XEXP (*x
, 0);
5643 if (GET_CODE (memref
) == SYMBOL_REF
5644 && CONSTANT_POOL_ADDRESS_P (memref
))
5646 rtx base
= cfun
->machine
->base_reg
;
5647 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, memref
, base
),
5650 *x
= replace_equiv_address (*x
, addr
);
5654 if (GET_CODE (memref
) == CONST
5655 && GET_CODE (XEXP (memref
, 0)) == PLUS
5656 && GET_CODE (XEXP (XEXP (memref
, 0), 1)) == CONST_INT
5657 && GET_CODE (XEXP (XEXP (memref
, 0), 0)) == SYMBOL_REF
5658 && CONSTANT_POOL_ADDRESS_P (XEXP (XEXP (memref
, 0), 0)))
5660 HOST_WIDE_INT off
= INTVAL (XEXP (XEXP (memref
, 0), 1));
5661 rtx sym
= XEXP (XEXP (memref
, 0), 0);
5662 rtx base
= cfun
->machine
->base_reg
;
5663 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, sym
, base
),
5666 *x
= replace_equiv_address (*x
, plus_constant (addr
, off
));
5671 /* ... or a load-address type pattern. */
5672 if (GET_CODE (*x
) == SET
)
5674 rtx addrref
= SET_SRC (*x
);
5676 if (GET_CODE (addrref
) == SYMBOL_REF
5677 && CONSTANT_POOL_ADDRESS_P (addrref
))
5679 rtx base
= cfun
->machine
->base_reg
;
5680 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, addrref
, base
),
5683 SET_SRC (*x
) = addr
;
5687 if (GET_CODE (addrref
) == CONST
5688 && GET_CODE (XEXP (addrref
, 0)) == PLUS
5689 && GET_CODE (XEXP (XEXP (addrref
, 0), 1)) == CONST_INT
5690 && GET_CODE (XEXP (XEXP (addrref
, 0), 0)) == SYMBOL_REF
5691 && CONSTANT_POOL_ADDRESS_P (XEXP (XEXP (addrref
, 0), 0)))
5693 HOST_WIDE_INT off
= INTVAL (XEXP (XEXP (addrref
, 0), 1));
5694 rtx sym
= XEXP (XEXP (addrref
, 0), 0);
5695 rtx base
= cfun
->machine
->base_reg
;
5696 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, sym
, base
),
5699 SET_SRC (*x
) = plus_constant (addr
, off
);
5704 /* Annotate LTREL_BASE as well. */
5705 if (GET_CODE (*x
) == UNSPEC
5706 && XINT (*x
, 1) == UNSPEC_LTREL_BASE
)
5708 rtx base
= cfun
->machine
->base_reg
;
5709 *x
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, XVECEXP (*x
, 0, 0), base
),
5714 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
5715 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
5719 annotate_constant_pool_refs (&XEXP (*x
, i
));
5721 else if (fmt
[i
] == 'E')
5723 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
5724 annotate_constant_pool_refs (&XVECEXP (*x
, i
, j
));
5729 /* Split all branches that exceed the maximum distance.
5730 Returns true if this created a new literal pool entry. */
5733 s390_split_branches (void)
5735 rtx temp_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
5736 int new_literal
= 0, ret
;
5737 rtx insn
, pat
, tmp
, target
;
5740 /* We need correct insn addresses. */
5742 shorten_branches (get_insns ());
5744 /* Find all branches that exceed 64KB, and split them. */
5746 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5748 if (GET_CODE (insn
) != JUMP_INSN
)
5751 pat
= PATTERN (insn
);
5752 if (GET_CODE (pat
) == PARALLEL
&& XVECLEN (pat
, 0) > 2)
5753 pat
= XVECEXP (pat
, 0, 0);
5754 if (GET_CODE (pat
) != SET
|| SET_DEST (pat
) != pc_rtx
)
5757 if (GET_CODE (SET_SRC (pat
)) == LABEL_REF
)
5759 label
= &SET_SRC (pat
);
5761 else if (GET_CODE (SET_SRC (pat
)) == IF_THEN_ELSE
)
5763 if (GET_CODE (XEXP (SET_SRC (pat
), 1)) == LABEL_REF
)
5764 label
= &XEXP (SET_SRC (pat
), 1);
5765 else if (GET_CODE (XEXP (SET_SRC (pat
), 2)) == LABEL_REF
)
5766 label
= &XEXP (SET_SRC (pat
), 2);
5773 if (get_attr_length (insn
) <= 4)
5776 /* We are going to use the return register as scratch register,
5777 make sure it will be saved/restored by the prologue/epilogue. */
5778 cfun_frame_layout
.save_return_addr_p
= 1;
5783 tmp
= force_const_mem (Pmode
, *label
);
5784 tmp
= emit_insn_before (gen_rtx_SET (Pmode
, temp_reg
, tmp
), insn
);
5785 INSN_ADDRESSES_NEW (tmp
, -1);
5786 annotate_constant_pool_refs (&PATTERN (tmp
));
5793 target
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, *label
),
5794 UNSPEC_LTREL_OFFSET
);
5795 target
= gen_rtx_CONST (Pmode
, target
);
5796 target
= force_const_mem (Pmode
, target
);
5797 tmp
= emit_insn_before (gen_rtx_SET (Pmode
, temp_reg
, target
), insn
);
5798 INSN_ADDRESSES_NEW (tmp
, -1);
5799 annotate_constant_pool_refs (&PATTERN (tmp
));
5801 target
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, XEXP (target
, 0),
5802 cfun
->machine
->base_reg
),
5804 target
= gen_rtx_PLUS (Pmode
, temp_reg
, target
);
5807 ret
= validate_change (insn
, label
, target
, 0);
5815 /* Find an annotated literal pool symbol referenced in RTX X,
5816 and store it at REF. Will abort if X contains references to
5817 more than one such pool symbol; multiple references to the same
5818 symbol are allowed, however.
5820 The rtx pointed to by REF must be initialized to NULL_RTX
5821 by the caller before calling this routine. */
5824 find_constant_pool_ref (rtx x
, rtx
*ref
)
5829 /* Ignore LTREL_BASE references. */
5830 if (GET_CODE (x
) == UNSPEC
5831 && XINT (x
, 1) == UNSPEC_LTREL_BASE
)
5833 /* Likewise POOL_ENTRY insns. */
5834 if (GET_CODE (x
) == UNSPEC_VOLATILE
5835 && XINT (x
, 1) == UNSPECV_POOL_ENTRY
)
5838 gcc_assert (GET_CODE (x
) != SYMBOL_REF
5839 || !CONSTANT_POOL_ADDRESS_P (x
));
5841 if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_LTREF
)
5843 rtx sym
= XVECEXP (x
, 0, 0);
5844 gcc_assert (GET_CODE (sym
) == SYMBOL_REF
5845 && CONSTANT_POOL_ADDRESS_P (sym
));
5847 if (*ref
== NULL_RTX
)
5850 gcc_assert (*ref
== sym
);
5855 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
5856 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
5860 find_constant_pool_ref (XEXP (x
, i
), ref
);
5862 else if (fmt
[i
] == 'E')
5864 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
5865 find_constant_pool_ref (XVECEXP (x
, i
, j
), ref
);
5870 /* Replace every reference to the annotated literal pool
5871 symbol REF in X by its base plus OFFSET. */
5874 replace_constant_pool_ref (rtx
*x
, rtx ref
, rtx offset
)
5879 gcc_assert (*x
!= ref
);
5881 if (GET_CODE (*x
) == UNSPEC
5882 && XINT (*x
, 1) == UNSPEC_LTREF
5883 && XVECEXP (*x
, 0, 0) == ref
)
5885 *x
= gen_rtx_PLUS (Pmode
, XVECEXP (*x
, 0, 1), offset
);
5889 if (GET_CODE (*x
) == PLUS
5890 && GET_CODE (XEXP (*x
, 1)) == CONST_INT
5891 && GET_CODE (XEXP (*x
, 0)) == UNSPEC
5892 && XINT (XEXP (*x
, 0), 1) == UNSPEC_LTREF
5893 && XVECEXP (XEXP (*x
, 0), 0, 0) == ref
)
5895 rtx addr
= gen_rtx_PLUS (Pmode
, XVECEXP (XEXP (*x
, 0), 0, 1), offset
);
5896 *x
= plus_constant (addr
, INTVAL (XEXP (*x
, 1)));
5900 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
5901 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
5905 replace_constant_pool_ref (&XEXP (*x
, i
), ref
, offset
);
5907 else if (fmt
[i
] == 'E')
5909 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
5910 replace_constant_pool_ref (&XVECEXP (*x
, i
, j
), ref
, offset
);
5915 /* Check whether X contains an UNSPEC_LTREL_BASE.
5916 Return its constant pool symbol if found, NULL_RTX otherwise. */
5919 find_ltrel_base (rtx x
)
5924 if (GET_CODE (x
) == UNSPEC
5925 && XINT (x
, 1) == UNSPEC_LTREL_BASE
)
5926 return XVECEXP (x
, 0, 0);
5928 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
5929 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
5933 rtx fnd
= find_ltrel_base (XEXP (x
, i
));
5937 else if (fmt
[i
] == 'E')
5939 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
5941 rtx fnd
= find_ltrel_base (XVECEXP (x
, i
, j
));
5951 /* Replace any occurrence of UNSPEC_LTREL_BASE in X with its base. */
5954 replace_ltrel_base (rtx
*x
)
5959 if (GET_CODE (*x
) == UNSPEC
5960 && XINT (*x
, 1) == UNSPEC_LTREL_BASE
)
5962 *x
= XVECEXP (*x
, 0, 1);
5966 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
5967 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
5971 replace_ltrel_base (&XEXP (*x
, i
));
5973 else if (fmt
[i
] == 'E')
5975 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
5976 replace_ltrel_base (&XVECEXP (*x
, i
, j
));
5982 /* We keep a list of constants which we have to add to internal
5983 constant tables in the middle of large functions. */
5985 #define NR_C_MODES 11
5986 enum machine_mode constant_modes
[NR_C_MODES
] =
5988 TFmode
, TImode
, TDmode
,
5989 DFmode
, DImode
, DDmode
,
5990 SFmode
, SImode
, SDmode
,
5997 struct constant
*next
;
6002 struct constant_pool
6004 struct constant_pool
*next
;
6008 rtx emit_pool_after
;
6010 struct constant
*constants
[NR_C_MODES
];
6011 struct constant
*execute
;
6016 /* Allocate new constant_pool structure. */
6018 static struct constant_pool
*
6019 s390_alloc_pool (void)
6021 struct constant_pool
*pool
;
6024 pool
= (struct constant_pool
*) xmalloc (sizeof *pool
);
6026 for (i
= 0; i
< NR_C_MODES
; i
++)
6027 pool
->constants
[i
] = NULL
;
6029 pool
->execute
= NULL
;
6030 pool
->label
= gen_label_rtx ();
6031 pool
->first_insn
= NULL_RTX
;
6032 pool
->pool_insn
= NULL_RTX
;
6033 pool
->insns
= BITMAP_ALLOC (NULL
);
6035 pool
->emit_pool_after
= NULL_RTX
;
6040 /* Create new constant pool covering instructions starting at INSN
6041 and chain it to the end of POOL_LIST. */
6043 static struct constant_pool
*
6044 s390_start_pool (struct constant_pool
**pool_list
, rtx insn
)
6046 struct constant_pool
*pool
, **prev
;
6048 pool
= s390_alloc_pool ();
6049 pool
->first_insn
= insn
;
6051 for (prev
= pool_list
; *prev
; prev
= &(*prev
)->next
)
6058 /* End range of instructions covered by POOL at INSN and emit
6059 placeholder insn representing the pool. */
6062 s390_end_pool (struct constant_pool
*pool
, rtx insn
)
6064 rtx pool_size
= GEN_INT (pool
->size
+ 8 /* alignment slop */);
6067 insn
= get_last_insn ();
6069 pool
->pool_insn
= emit_insn_after (gen_pool (pool_size
), insn
);
6070 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
6073 /* Add INSN to the list of insns covered by POOL. */
6076 s390_add_pool_insn (struct constant_pool
*pool
, rtx insn
)
6078 bitmap_set_bit (pool
->insns
, INSN_UID (insn
));
6081 /* Return pool out of POOL_LIST that covers INSN. */
6083 static struct constant_pool
*
6084 s390_find_pool (struct constant_pool
*pool_list
, rtx insn
)
6086 struct constant_pool
*pool
;
6088 for (pool
= pool_list
; pool
; pool
= pool
->next
)
6089 if (bitmap_bit_p (pool
->insns
, INSN_UID (insn
)))
6095 /* Add constant VAL of mode MODE to the constant pool POOL. */
6098 s390_add_constant (struct constant_pool
*pool
, rtx val
, enum machine_mode mode
)
6103 for (i
= 0; i
< NR_C_MODES
; i
++)
6104 if (constant_modes
[i
] == mode
)
6106 gcc_assert (i
!= NR_C_MODES
);
6108 for (c
= pool
->constants
[i
]; c
!= NULL
; c
= c
->next
)
6109 if (rtx_equal_p (val
, c
->value
))
6114 c
= (struct constant
*) xmalloc (sizeof *c
);
6116 c
->label
= gen_label_rtx ();
6117 c
->next
= pool
->constants
[i
];
6118 pool
->constants
[i
] = c
;
6119 pool
->size
+= GET_MODE_SIZE (mode
);
6123 /* Return an rtx that represents the offset of X from the start of
6127 s390_pool_offset (struct constant_pool
*pool
, rtx x
)
6131 label
= gen_rtx_LABEL_REF (GET_MODE (x
), pool
->label
);
6132 x
= gen_rtx_UNSPEC (GET_MODE (x
), gen_rtvec (2, x
, label
),
6133 UNSPEC_POOL_OFFSET
);
6134 return gen_rtx_CONST (GET_MODE (x
), x
);
6137 /* Find constant VAL of mode MODE in the constant pool POOL.
6138 Return an RTX describing the distance from the start of
6139 the pool to the location of the new constant. */
6142 s390_find_constant (struct constant_pool
*pool
, rtx val
,
6143 enum machine_mode mode
)
6148 for (i
= 0; i
< NR_C_MODES
; i
++)
6149 if (constant_modes
[i
] == mode
)
6151 gcc_assert (i
!= NR_C_MODES
);
6153 for (c
= pool
->constants
[i
]; c
!= NULL
; c
= c
->next
)
6154 if (rtx_equal_p (val
, c
->value
))
6159 return s390_pool_offset (pool
, gen_rtx_LABEL_REF (Pmode
, c
->label
));
6162 /* Check whether INSN is an execute. Return the label_ref to its
6163 execute target template if so, NULL_RTX otherwise. */
6166 s390_execute_label (rtx insn
)
6168 if (GET_CODE (insn
) == INSN
6169 && GET_CODE (PATTERN (insn
)) == PARALLEL
6170 && GET_CODE (XVECEXP (PATTERN (insn
), 0, 0)) == UNSPEC
6171 && XINT (XVECEXP (PATTERN (insn
), 0, 0), 1) == UNSPEC_EXECUTE
)
6172 return XVECEXP (XVECEXP (PATTERN (insn
), 0, 0), 0, 2);
6177 /* Add execute target for INSN to the constant pool POOL. */
6180 s390_add_execute (struct constant_pool
*pool
, rtx insn
)
6184 for (c
= pool
->execute
; c
!= NULL
; c
= c
->next
)
6185 if (INSN_UID (insn
) == INSN_UID (c
->value
))
6190 c
= (struct constant
*) xmalloc (sizeof *c
);
6192 c
->label
= gen_label_rtx ();
6193 c
->next
= pool
->execute
;
6199 /* Find execute target for INSN in the constant pool POOL.
6200 Return an RTX describing the distance from the start of
6201 the pool to the location of the execute target. */
6204 s390_find_execute (struct constant_pool
*pool
, rtx insn
)
6208 for (c
= pool
->execute
; c
!= NULL
; c
= c
->next
)
6209 if (INSN_UID (insn
) == INSN_UID (c
->value
))
6214 return s390_pool_offset (pool
, gen_rtx_LABEL_REF (Pmode
, c
->label
));
6217 /* For an execute INSN, extract the execute target template. */
6220 s390_execute_target (rtx insn
)
6222 rtx pattern
= PATTERN (insn
);
6223 gcc_assert (s390_execute_label (insn
));
6225 if (XVECLEN (pattern
, 0) == 2)
6227 pattern
= copy_rtx (XVECEXP (pattern
, 0, 1));
6231 rtvec vec
= rtvec_alloc (XVECLEN (pattern
, 0) - 1);
6234 for (i
= 0; i
< XVECLEN (pattern
, 0) - 1; i
++)
6235 RTVEC_ELT (vec
, i
) = copy_rtx (XVECEXP (pattern
, 0, i
+ 1));
6237 pattern
= gen_rtx_PARALLEL (VOIDmode
, vec
);
6243 /* Indicate that INSN cannot be duplicated. This is the case for
6244 execute insns that carry a unique label. */
6247 s390_cannot_copy_insn_p (rtx insn
)
6249 rtx label
= s390_execute_label (insn
);
6250 return label
&& label
!= const0_rtx
;
6253 /* Dump out the constants in POOL. If REMOTE_LABEL is true,
6254 do not emit the pool base label. */
6257 s390_dump_pool (struct constant_pool
*pool
, bool remote_label
)
6260 rtx insn
= pool
->pool_insn
;
6263 /* Switch to rodata section. */
6264 if (TARGET_CPU_ZARCH
)
6266 insn
= emit_insn_after (gen_pool_section_start (), insn
);
6267 INSN_ADDRESSES_NEW (insn
, -1);
6270 /* Ensure minimum pool alignment. */
6271 if (TARGET_CPU_ZARCH
)
6272 insn
= emit_insn_after (gen_pool_align (GEN_INT (8)), insn
);
6274 insn
= emit_insn_after (gen_pool_align (GEN_INT (4)), insn
);
6275 INSN_ADDRESSES_NEW (insn
, -1);
6277 /* Emit pool base label. */
6280 insn
= emit_label_after (pool
->label
, insn
);
6281 INSN_ADDRESSES_NEW (insn
, -1);
6284 /* Dump constants in descending alignment requirement order,
6285 ensuring proper alignment for every constant. */
6286 for (i
= 0; i
< NR_C_MODES
; i
++)
6287 for (c
= pool
->constants
[i
]; c
; c
= c
->next
)
6289 /* Convert UNSPEC_LTREL_OFFSET unspecs to pool-relative references. */
6290 rtx value
= copy_rtx (c
->value
);
6291 if (GET_CODE (value
) == CONST
6292 && GET_CODE (XEXP (value
, 0)) == UNSPEC
6293 && XINT (XEXP (value
, 0), 1) == UNSPEC_LTREL_OFFSET
6294 && XVECLEN (XEXP (value
, 0), 0) == 1)
6295 value
= s390_pool_offset (pool
, XVECEXP (XEXP (value
, 0), 0, 0));
6297 insn
= emit_label_after (c
->label
, insn
);
6298 INSN_ADDRESSES_NEW (insn
, -1);
6300 value
= gen_rtx_UNSPEC_VOLATILE (constant_modes
[i
],
6301 gen_rtvec (1, value
),
6302 UNSPECV_POOL_ENTRY
);
6303 insn
= emit_insn_after (value
, insn
);
6304 INSN_ADDRESSES_NEW (insn
, -1);
6307 /* Ensure minimum alignment for instructions. */
6308 insn
= emit_insn_after (gen_pool_align (GEN_INT (2)), insn
);
6309 INSN_ADDRESSES_NEW (insn
, -1);
6311 /* Output in-pool execute template insns. */
6312 for (c
= pool
->execute
; c
; c
= c
->next
)
6314 insn
= emit_label_after (c
->label
, insn
);
6315 INSN_ADDRESSES_NEW (insn
, -1);
6317 insn
= emit_insn_after (s390_execute_target (c
->value
), insn
);
6318 INSN_ADDRESSES_NEW (insn
, -1);
6321 /* Switch back to previous section. */
6322 if (TARGET_CPU_ZARCH
)
6324 insn
= emit_insn_after (gen_pool_section_end (), insn
);
6325 INSN_ADDRESSES_NEW (insn
, -1);
6328 insn
= emit_barrier_after (insn
);
6329 INSN_ADDRESSES_NEW (insn
, -1);
6331 /* Remove placeholder insn. */
6332 remove_insn (pool
->pool_insn
);
6335 /* Free all memory used by POOL. */
6338 s390_free_pool (struct constant_pool
*pool
)
6340 struct constant
*c
, *next
;
6343 for (i
= 0; i
< NR_C_MODES
; i
++)
6344 for (c
= pool
->constants
[i
]; c
; c
= next
)
6350 for (c
= pool
->execute
; c
; c
= next
)
6356 BITMAP_FREE (pool
->insns
);
6361 /* Collect main literal pool. Return NULL on overflow. */
6363 static struct constant_pool
*
6364 s390_mainpool_start (void)
6366 struct constant_pool
*pool
;
6369 pool
= s390_alloc_pool ();
6371 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6373 if (GET_CODE (insn
) == INSN
6374 && GET_CODE (PATTERN (insn
)) == SET
6375 && GET_CODE (SET_SRC (PATTERN (insn
))) == UNSPEC_VOLATILE
6376 && XINT (SET_SRC (PATTERN (insn
)), 1) == UNSPECV_MAIN_POOL
)
6378 gcc_assert (!pool
->pool_insn
);
6379 pool
->pool_insn
= insn
;
6382 if (!TARGET_CPU_ZARCH
&& s390_execute_label (insn
))
6384 s390_add_execute (pool
, insn
);
6386 else if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
6388 rtx pool_ref
= NULL_RTX
;
6389 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
6392 rtx constant
= get_pool_constant (pool_ref
);
6393 enum machine_mode mode
= get_pool_mode (pool_ref
);
6394 s390_add_constant (pool
, constant
, mode
);
6398 /* If hot/cold partitioning is enabled we have to make sure that
6399 the literal pool is emitted in the same section where the
6400 initialization of the literal pool base pointer takes place.
6401 emit_pool_after is only used in the non-overflow case on non
6402 Z cpus where we can emit the literal pool at the end of the
6403 function body within the text section. */
6405 && NOTE_KIND (insn
) == NOTE_INSN_SWITCH_TEXT_SECTIONS
6406 && !pool
->emit_pool_after
)
6407 pool
->emit_pool_after
= PREV_INSN (insn
);
6410 gcc_assert (pool
->pool_insn
|| pool
->size
== 0);
6412 if (pool
->size
>= 4096)
6414 /* We're going to chunkify the pool, so remove the main
6415 pool placeholder insn. */
6416 remove_insn (pool
->pool_insn
);
6418 s390_free_pool (pool
);
6422 /* If the functions ends with the section where the literal pool
6423 should be emitted set the marker to its end. */
6424 if (pool
&& !pool
->emit_pool_after
)
6425 pool
->emit_pool_after
= get_last_insn ();
6430 /* POOL holds the main literal pool as collected by s390_mainpool_start.
6431 Modify the current function to output the pool constants as well as
6432 the pool register setup instruction. */
6435 s390_mainpool_finish (struct constant_pool
*pool
)
6437 rtx base_reg
= cfun
->machine
->base_reg
;
6440 /* If the pool is empty, we're done. */
6441 if (pool
->size
== 0)
6443 /* We don't actually need a base register after all. */
6444 cfun
->machine
->base_reg
= NULL_RTX
;
6446 if (pool
->pool_insn
)
6447 remove_insn (pool
->pool_insn
);
6448 s390_free_pool (pool
);
6452 /* We need correct insn addresses. */
6453 shorten_branches (get_insns ());
6455 /* On zSeries, we use a LARL to load the pool register. The pool is
6456 located in the .rodata section, so we emit it after the function. */
6457 if (TARGET_CPU_ZARCH
)
6459 insn
= gen_main_base_64 (base_reg
, pool
->label
);
6460 insn
= emit_insn_after (insn
, pool
->pool_insn
);
6461 INSN_ADDRESSES_NEW (insn
, -1);
6462 remove_insn (pool
->pool_insn
);
6464 insn
= get_last_insn ();
6465 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
6466 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
6468 s390_dump_pool (pool
, 0);
6471 /* On S/390, if the total size of the function's code plus literal pool
6472 does not exceed 4096 bytes, we use BASR to set up a function base
6473 pointer, and emit the literal pool at the end of the function. */
6474 else if (INSN_ADDRESSES (INSN_UID (pool
->emit_pool_after
))
6475 + pool
->size
+ 8 /* alignment slop */ < 4096)
6477 insn
= gen_main_base_31_small (base_reg
, pool
->label
);
6478 insn
= emit_insn_after (insn
, pool
->pool_insn
);
6479 INSN_ADDRESSES_NEW (insn
, -1);
6480 remove_insn (pool
->pool_insn
);
6482 insn
= emit_label_after (pool
->label
, insn
);
6483 INSN_ADDRESSES_NEW (insn
, -1);
6485 /* emit_pool_after will be set by s390_mainpool_start to the
6486 last insn of the section where the literal pool should be
6488 insn
= pool
->emit_pool_after
;
6490 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
6491 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
6493 s390_dump_pool (pool
, 1);
6496 /* Otherwise, we emit an inline literal pool and use BASR to branch
6497 over it, setting up the pool register at the same time. */
6500 rtx pool_end
= gen_label_rtx ();
6502 insn
= gen_main_base_31_large (base_reg
, pool
->label
, pool_end
);
6503 insn
= emit_insn_after (insn
, pool
->pool_insn
);
6504 INSN_ADDRESSES_NEW (insn
, -1);
6505 remove_insn (pool
->pool_insn
);
6507 insn
= emit_label_after (pool
->label
, insn
);
6508 INSN_ADDRESSES_NEW (insn
, -1);
6510 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
6511 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
6513 insn
= emit_label_after (pool_end
, pool
->pool_insn
);
6514 INSN_ADDRESSES_NEW (insn
, -1);
6516 s390_dump_pool (pool
, 1);
6520 /* Replace all literal pool references. */
6522 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6525 replace_ltrel_base (&PATTERN (insn
));
6527 if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
6529 rtx addr
, pool_ref
= NULL_RTX
;
6530 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
6533 if (s390_execute_label (insn
))
6534 addr
= s390_find_execute (pool
, insn
);
6536 addr
= s390_find_constant (pool
, get_pool_constant (pool_ref
),
6537 get_pool_mode (pool_ref
));
6539 replace_constant_pool_ref (&PATTERN (insn
), pool_ref
, addr
);
6540 INSN_CODE (insn
) = -1;
6546 /* Free the pool. */
6547 s390_free_pool (pool
);
6550 /* POOL holds the main literal pool as collected by s390_mainpool_start.
6551 We have decided we cannot use this pool, so revert all changes
6552 to the current function that were done by s390_mainpool_start. */
6554 s390_mainpool_cancel (struct constant_pool
*pool
)
6556 /* We didn't actually change the instruction stream, so simply
6557 free the pool memory. */
6558 s390_free_pool (pool
);
6562 /* Chunkify the literal pool. */
6564 #define S390_POOL_CHUNK_MIN 0xc00
6565 #define S390_POOL_CHUNK_MAX 0xe00
6567 static struct constant_pool
*
6568 s390_chunkify_start (void)
6570 struct constant_pool
*curr_pool
= NULL
, *pool_list
= NULL
;
6573 rtx pending_ltrel
= NULL_RTX
;
6576 rtx (*gen_reload_base
) (rtx
, rtx
) =
6577 TARGET_CPU_ZARCH
? gen_reload_base_64
: gen_reload_base_31
;
6580 /* We need correct insn addresses. */
6582 shorten_branches (get_insns ());
6584 /* Scan all insns and move literals to pool chunks. */
6586 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6588 bool section_switch_p
= false;
6590 /* Check for pending LTREL_BASE. */
6593 rtx ltrel_base
= find_ltrel_base (PATTERN (insn
));
6596 gcc_assert (ltrel_base
== pending_ltrel
);
6597 pending_ltrel
= NULL_RTX
;
6601 if (!TARGET_CPU_ZARCH
&& s390_execute_label (insn
))
6604 curr_pool
= s390_start_pool (&pool_list
, insn
);
6606 s390_add_execute (curr_pool
, insn
);
6607 s390_add_pool_insn (curr_pool
, insn
);
6609 else if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
6611 rtx pool_ref
= NULL_RTX
;
6612 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
6615 rtx constant
= get_pool_constant (pool_ref
);
6616 enum machine_mode mode
= get_pool_mode (pool_ref
);
6619 curr_pool
= s390_start_pool (&pool_list
, insn
);
6621 s390_add_constant (curr_pool
, constant
, mode
);
6622 s390_add_pool_insn (curr_pool
, insn
);
6624 /* Don't split the pool chunk between a LTREL_OFFSET load
6625 and the corresponding LTREL_BASE. */
6626 if (GET_CODE (constant
) == CONST
6627 && GET_CODE (XEXP (constant
, 0)) == UNSPEC
6628 && XINT (XEXP (constant
, 0), 1) == UNSPEC_LTREL_OFFSET
)
6630 gcc_assert (!pending_ltrel
);
6631 pending_ltrel
= pool_ref
;
6636 if (GET_CODE (insn
) == JUMP_INSN
|| GET_CODE (insn
) == CODE_LABEL
)
6639 s390_add_pool_insn (curr_pool
, insn
);
6640 /* An LTREL_BASE must follow within the same basic block. */
6641 gcc_assert (!pending_ltrel
);
6644 if (NOTE_P (insn
) && NOTE_KIND (insn
) == NOTE_INSN_SWITCH_TEXT_SECTIONS
)
6645 section_switch_p
= true;
6648 || INSN_ADDRESSES_SIZE () <= (size_t) INSN_UID (insn
)
6649 || INSN_ADDRESSES (INSN_UID (insn
)) == -1)
6652 if (TARGET_CPU_ZARCH
)
6654 if (curr_pool
->size
< S390_POOL_CHUNK_MAX
)
6657 s390_end_pool (curr_pool
, NULL_RTX
);
6662 int chunk_size
= INSN_ADDRESSES (INSN_UID (insn
))
6663 - INSN_ADDRESSES (INSN_UID (curr_pool
->first_insn
))
6666 /* We will later have to insert base register reload insns.
6667 Those will have an effect on code size, which we need to
6668 consider here. This calculation makes rather pessimistic
6669 worst-case assumptions. */
6670 if (GET_CODE (insn
) == CODE_LABEL
)
6673 if (chunk_size
< S390_POOL_CHUNK_MIN
6674 && curr_pool
->size
< S390_POOL_CHUNK_MIN
6675 && !section_switch_p
)
6678 /* Pool chunks can only be inserted after BARRIERs ... */
6679 if (GET_CODE (insn
) == BARRIER
)
6681 s390_end_pool (curr_pool
, insn
);
6686 /* ... so if we don't find one in time, create one. */
6687 else if (chunk_size
> S390_POOL_CHUNK_MAX
6688 || curr_pool
->size
> S390_POOL_CHUNK_MAX
6689 || section_switch_p
)
6691 rtx label
, jump
, barrier
;
6693 if (!section_switch_p
)
6695 /* We can insert the barrier only after a 'real' insn. */
6696 if (GET_CODE (insn
) != INSN
&& GET_CODE (insn
) != CALL_INSN
)
6698 if (get_attr_length (insn
) == 0)
6700 /* Don't separate LTREL_BASE from the corresponding
6701 LTREL_OFFSET load. */
6707 gcc_assert (!pending_ltrel
);
6709 /* The old pool has to end before the section switch
6710 note in order to make it part of the current
6712 insn
= PREV_INSN (insn
);
6715 label
= gen_label_rtx ();
6716 jump
= emit_jump_insn_after (gen_jump (label
), insn
);
6717 barrier
= emit_barrier_after (jump
);
6718 insn
= emit_label_after (label
, barrier
);
6719 JUMP_LABEL (jump
) = label
;
6720 LABEL_NUSES (label
) = 1;
6722 INSN_ADDRESSES_NEW (jump
, -1);
6723 INSN_ADDRESSES_NEW (barrier
, -1);
6724 INSN_ADDRESSES_NEW (insn
, -1);
6726 s390_end_pool (curr_pool
, barrier
);
6734 s390_end_pool (curr_pool
, NULL_RTX
);
6735 gcc_assert (!pending_ltrel
);
6737 /* Find all labels that are branched into
6738 from an insn belonging to a different chunk. */
6740 far_labels
= BITMAP_ALLOC (NULL
);
6742 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6744 /* Labels marked with LABEL_PRESERVE_P can be target
6745 of non-local jumps, so we have to mark them.
6746 The same holds for named labels.
6748 Don't do that, however, if it is the label before
6751 if (GET_CODE (insn
) == CODE_LABEL
6752 && (LABEL_PRESERVE_P (insn
) || LABEL_NAME (insn
)))
6754 rtx vec_insn
= next_real_insn (insn
);
6755 rtx vec_pat
= vec_insn
&& GET_CODE (vec_insn
) == JUMP_INSN
?
6756 PATTERN (vec_insn
) : NULL_RTX
;
6758 || !(GET_CODE (vec_pat
) == ADDR_VEC
6759 || GET_CODE (vec_pat
) == ADDR_DIFF_VEC
))
6760 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (insn
));
6763 /* If we have a direct jump (conditional or unconditional)
6764 or a casesi jump, check all potential targets. */
6765 else if (GET_CODE (insn
) == JUMP_INSN
)
6767 rtx pat
= PATTERN (insn
);
6768 if (GET_CODE (pat
) == PARALLEL
&& XVECLEN (pat
, 0) > 2)
6769 pat
= XVECEXP (pat
, 0, 0);
6771 if (GET_CODE (pat
) == SET
)
6773 rtx label
= JUMP_LABEL (insn
);
6776 if (s390_find_pool (pool_list
, label
)
6777 != s390_find_pool (pool_list
, insn
))
6778 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (label
));
6781 else if (GET_CODE (pat
) == PARALLEL
6782 && XVECLEN (pat
, 0) == 2
6783 && GET_CODE (XVECEXP (pat
, 0, 0)) == SET
6784 && GET_CODE (XVECEXP (pat
, 0, 1)) == USE
6785 && GET_CODE (XEXP (XVECEXP (pat
, 0, 1), 0)) == LABEL_REF
)
6787 /* Find the jump table used by this casesi jump. */
6788 rtx vec_label
= XEXP (XEXP (XVECEXP (pat
, 0, 1), 0), 0);
6789 rtx vec_insn
= next_real_insn (vec_label
);
6790 rtx vec_pat
= vec_insn
&& GET_CODE (vec_insn
) == JUMP_INSN
?
6791 PATTERN (vec_insn
) : NULL_RTX
;
6793 && (GET_CODE (vec_pat
) == ADDR_VEC
6794 || GET_CODE (vec_pat
) == ADDR_DIFF_VEC
))
6796 int i
, diff_p
= GET_CODE (vec_pat
) == ADDR_DIFF_VEC
;
6798 for (i
= 0; i
< XVECLEN (vec_pat
, diff_p
); i
++)
6800 rtx label
= XEXP (XVECEXP (vec_pat
, diff_p
, i
), 0);
6802 if (s390_find_pool (pool_list
, label
)
6803 != s390_find_pool (pool_list
, insn
))
6804 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (label
));
6811 /* Insert base register reload insns before every pool. */
6813 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
6815 rtx new_insn
= gen_reload_base (cfun
->machine
->base_reg
,
6817 rtx insn
= curr_pool
->first_insn
;
6818 INSN_ADDRESSES_NEW (emit_insn_before (new_insn
, insn
), -1);
6821 /* Insert base register reload insns at every far label. */
6823 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6824 if (GET_CODE (insn
) == CODE_LABEL
6825 && bitmap_bit_p (far_labels
, CODE_LABEL_NUMBER (insn
)))
6827 struct constant_pool
*pool
= s390_find_pool (pool_list
, insn
);
6830 rtx new_insn
= gen_reload_base (cfun
->machine
->base_reg
,
6832 INSN_ADDRESSES_NEW (emit_insn_after (new_insn
, insn
), -1);
6837 BITMAP_FREE (far_labels
);
6840 /* Recompute insn addresses. */
6842 init_insn_lengths ();
6843 shorten_branches (get_insns ());
6848 /* POOL_LIST is a chunk list as prepared by s390_chunkify_start.
6849 After we have decided to use this list, finish implementing
6850 all changes to the current function as required. */
6853 s390_chunkify_finish (struct constant_pool
*pool_list
)
6855 struct constant_pool
*curr_pool
= NULL
;
6859 /* Replace all literal pool references. */
6861 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6864 replace_ltrel_base (&PATTERN (insn
));
6866 curr_pool
= s390_find_pool (pool_list
, insn
);
6870 if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
6872 rtx addr
, pool_ref
= NULL_RTX
;
6873 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
6876 if (s390_execute_label (insn
))
6877 addr
= s390_find_execute (curr_pool
, insn
);
6879 addr
= s390_find_constant (curr_pool
,
6880 get_pool_constant (pool_ref
),
6881 get_pool_mode (pool_ref
));
6883 replace_constant_pool_ref (&PATTERN (insn
), pool_ref
, addr
);
6884 INSN_CODE (insn
) = -1;
6889 /* Dump out all literal pools. */
6891 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
6892 s390_dump_pool (curr_pool
, 0);
6894 /* Free pool list. */
6898 struct constant_pool
*next
= pool_list
->next
;
6899 s390_free_pool (pool_list
);
6904 /* POOL_LIST is a chunk list as prepared by s390_chunkify_start.
6905 We have decided we cannot use this list, so revert all changes
6906 to the current function that were done by s390_chunkify_start. */
6909 s390_chunkify_cancel (struct constant_pool
*pool_list
)
6911 struct constant_pool
*curr_pool
= NULL
;
6914 /* Remove all pool placeholder insns. */
6916 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
6918 /* Did we insert an extra barrier? Remove it. */
6919 rtx barrier
= PREV_INSN (curr_pool
->pool_insn
);
6920 rtx jump
= barrier
? PREV_INSN (barrier
) : NULL_RTX
;
6921 rtx label
= NEXT_INSN (curr_pool
->pool_insn
);
6923 if (jump
&& GET_CODE (jump
) == JUMP_INSN
6924 && barrier
&& GET_CODE (barrier
) == BARRIER
6925 && label
&& GET_CODE (label
) == CODE_LABEL
6926 && GET_CODE (PATTERN (jump
)) == SET
6927 && SET_DEST (PATTERN (jump
)) == pc_rtx
6928 && GET_CODE (SET_SRC (PATTERN (jump
))) == LABEL_REF
6929 && XEXP (SET_SRC (PATTERN (jump
)), 0) == label
)
6932 remove_insn (barrier
);
6933 remove_insn (label
);
6936 remove_insn (curr_pool
->pool_insn
);
6939 /* Remove all base register reload insns. */
6941 for (insn
= get_insns (); insn
; )
6943 rtx next_insn
= NEXT_INSN (insn
);
6945 if (GET_CODE (insn
) == INSN
6946 && GET_CODE (PATTERN (insn
)) == SET
6947 && GET_CODE (SET_SRC (PATTERN (insn
))) == UNSPEC
6948 && XINT (SET_SRC (PATTERN (insn
)), 1) == UNSPEC_RELOAD_BASE
)
6954 /* Free pool list. */
6958 struct constant_pool
*next
= pool_list
->next
;
6959 s390_free_pool (pool_list
);
6964 /* Output the constant pool entry EXP in mode MODE with alignment ALIGN. */
6967 s390_output_pool_entry (rtx exp
, enum machine_mode mode
, unsigned int align
)
6971 switch (GET_MODE_CLASS (mode
))
6974 case MODE_DECIMAL_FLOAT
:
6975 gcc_assert (GET_CODE (exp
) == CONST_DOUBLE
);
6977 REAL_VALUE_FROM_CONST_DOUBLE (r
, exp
);
6978 assemble_real (r
, mode
, align
);
6982 assemble_integer (exp
, GET_MODE_SIZE (mode
), align
, 1);
6983 mark_symbol_refs_as_used (exp
);
6992 /* Return an RTL expression representing the value of the return address
6993 for the frame COUNT steps up from the current frame. FRAME is the
6994 frame pointer of that frame. */
6997 s390_return_addr_rtx (int count
, rtx frame ATTRIBUTE_UNUSED
)
7002 /* Without backchain, we fail for all but the current frame. */
7004 if (!TARGET_BACKCHAIN
&& count
> 0)
7007 /* For the current frame, we need to make sure the initial
7008 value of RETURN_REGNUM is actually saved. */
7012 /* On non-z architectures branch splitting could overwrite r14. */
7013 if (TARGET_CPU_ZARCH
)
7014 return get_hard_reg_initial_val (Pmode
, RETURN_REGNUM
);
7017 cfun_frame_layout
.save_return_addr_p
= true;
7018 return gen_rtx_MEM (Pmode
, return_address_pointer_rtx
);
7022 if (TARGET_PACKED_STACK
)
7023 offset
= -2 * UNITS_PER_LONG
;
7025 offset
= RETURN_REGNUM
* UNITS_PER_LONG
;
7027 addr
= plus_constant (frame
, offset
);
7028 addr
= memory_address (Pmode
, addr
);
7029 return gen_rtx_MEM (Pmode
, addr
);
7032 /* Return an RTL expression representing the back chain stored in
7033 the current stack frame. */
7036 s390_back_chain_rtx (void)
7040 gcc_assert (TARGET_BACKCHAIN
);
7042 if (TARGET_PACKED_STACK
)
7043 chain
= plus_constant (stack_pointer_rtx
,
7044 STACK_POINTER_OFFSET
- UNITS_PER_LONG
);
7046 chain
= stack_pointer_rtx
;
7048 chain
= gen_rtx_MEM (Pmode
, chain
);
7052 /* Find first call clobbered register unused in a function.
7053 This could be used as base register in a leaf function
7054 or for holding the return address before epilogue. */
7057 find_unused_clobbered_reg (void)
7060 for (i
= 0; i
< 6; i
++)
7061 if (!df_regs_ever_live_p (i
))
7067 /* Helper function for s390_regs_ever_clobbered. Sets the fields in DATA for all
7068 clobbered hard regs in SETREG. */
7071 s390_reg_clobbered_rtx (rtx setreg
, const_rtx set_insn ATTRIBUTE_UNUSED
, void *data
)
7073 int *regs_ever_clobbered
= (int *)data
;
7074 unsigned int i
, regno
;
7075 enum machine_mode mode
= GET_MODE (setreg
);
7077 if (GET_CODE (setreg
) == SUBREG
)
7079 rtx inner
= SUBREG_REG (setreg
);
7080 if (!GENERAL_REG_P (inner
))
7082 regno
= subreg_regno (setreg
);
7084 else if (GENERAL_REG_P (setreg
))
7085 regno
= REGNO (setreg
);
7090 i
< regno
+ HARD_REGNO_NREGS (regno
, mode
);
7092 regs_ever_clobbered
[i
] = 1;
7095 /* Walks through all basic blocks of the current function looking
7096 for clobbered hard regs using s390_reg_clobbered_rtx. The fields
7097 of the passed integer array REGS_EVER_CLOBBERED are set to one for
7098 each of those regs. */
7101 s390_regs_ever_clobbered (int *regs_ever_clobbered
)
7107 memset (regs_ever_clobbered
, 0, 16 * sizeof (int));
7109 /* For non-leaf functions we have to consider all call clobbered regs to be
7111 if (!current_function_is_leaf
)
7113 for (i
= 0; i
< 16; i
++)
7114 regs_ever_clobbered
[i
] = call_really_used_regs
[i
];
7117 /* Make the "magic" eh_return registers live if necessary. For regs_ever_live
7118 this work is done by liveness analysis (mark_regs_live_at_end).
7119 Special care is needed for functions containing landing pads. Landing pads
7120 may use the eh registers, but the code which sets these registers is not
7121 contained in that function. Hence s390_regs_ever_clobbered is not able to
7122 deal with this automatically. */
7123 if (crtl
->calls_eh_return
|| cfun
->machine
->has_landing_pad_p
)
7124 for (i
= 0; EH_RETURN_DATA_REGNO (i
) != INVALID_REGNUM
; i
++)
7125 if (crtl
->calls_eh_return
7126 || (cfun
->machine
->has_landing_pad_p
7127 && df_regs_ever_live_p (EH_RETURN_DATA_REGNO (i
))))
7128 regs_ever_clobbered
[EH_RETURN_DATA_REGNO (i
)] = 1;
7130 /* For nonlocal gotos all call-saved registers have to be saved.
7131 This flag is also set for the unwinding code in libgcc.
7132 See expand_builtin_unwind_init. For regs_ever_live this is done by
7134 if (cfun
->has_nonlocal_label
)
7135 for (i
= 0; i
< 16; i
++)
7136 if (!call_really_used_regs
[i
])
7137 regs_ever_clobbered
[i
] = 1;
7139 FOR_EACH_BB (cur_bb
)
7141 FOR_BB_INSNS (cur_bb
, cur_insn
)
7143 if (INSN_P (cur_insn
))
7144 note_stores (PATTERN (cur_insn
),
7145 s390_reg_clobbered_rtx
,
7146 regs_ever_clobbered
);
7151 /* Determine the frame area which actually has to be accessed
7152 in the function epilogue. The values are stored at the
7153 given pointers AREA_BOTTOM (address of the lowest used stack
7154 address) and AREA_TOP (address of the first item which does
7155 not belong to the stack frame). */
7158 s390_frame_area (int *area_bottom
, int *area_top
)
7166 if (cfun_frame_layout
.first_restore_gpr
!= -1)
7168 b
= (cfun_frame_layout
.gprs_offset
7169 + cfun_frame_layout
.first_restore_gpr
* UNITS_PER_LONG
);
7170 t
= b
+ (cfun_frame_layout
.last_restore_gpr
7171 - cfun_frame_layout
.first_restore_gpr
+ 1) * UNITS_PER_LONG
;
7174 if (TARGET_64BIT
&& cfun_save_high_fprs_p
)
7176 b
= MIN (b
, cfun_frame_layout
.f8_offset
);
7177 t
= MAX (t
, (cfun_frame_layout
.f8_offset
7178 + cfun_frame_layout
.high_fprs
* 8));
7182 for (i
= 2; i
< 4; i
++)
7183 if (cfun_fpr_bit_p (i
))
7185 b
= MIN (b
, cfun_frame_layout
.f4_offset
+ (i
- 2) * 8);
7186 t
= MAX (t
, cfun_frame_layout
.f4_offset
+ (i
- 1) * 8);
7193 /* Fill cfun->machine with info about register usage of current function.
7194 Return in CLOBBERED_REGS which GPRs are currently considered set. */
7197 s390_register_info (int clobbered_regs
[])
7201 /* fprs 8 - 15 are call saved for 64 Bit ABI. */
7202 cfun_frame_layout
.fpr_bitmap
= 0;
7203 cfun_frame_layout
.high_fprs
= 0;
7205 for (i
= 24; i
< 32; i
++)
7206 if (df_regs_ever_live_p (i
) && !global_regs
[i
])
7208 cfun_set_fpr_bit (i
- 16);
7209 cfun_frame_layout
.high_fprs
++;
7212 /* Find first and last gpr to be saved. We trust regs_ever_live
7213 data, except that we don't save and restore global registers.
7215 Also, all registers with special meaning to the compiler need
7216 to be handled extra. */
7218 s390_regs_ever_clobbered (clobbered_regs
);
7220 for (i
= 0; i
< 16; i
++)
7221 clobbered_regs
[i
] = clobbered_regs
[i
] && !global_regs
[i
] && !fixed_regs
[i
];
7223 if (frame_pointer_needed
)
7224 clobbered_regs
[HARD_FRAME_POINTER_REGNUM
] = 1;
7227 clobbered_regs
[PIC_OFFSET_TABLE_REGNUM
]
7228 |= df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM
);
7230 clobbered_regs
[BASE_REGNUM
]
7231 |= (cfun
->machine
->base_reg
7232 && REGNO (cfun
->machine
->base_reg
) == BASE_REGNUM
);
7234 clobbered_regs
[RETURN_REGNUM
]
7235 |= (!current_function_is_leaf
7236 || TARGET_TPF_PROFILING
7237 || cfun
->machine
->split_branches_pending_p
7238 || cfun_frame_layout
.save_return_addr_p
7239 || crtl
->calls_eh_return
7242 clobbered_regs
[STACK_POINTER_REGNUM
]
7243 |= (!current_function_is_leaf
7244 || TARGET_TPF_PROFILING
7245 || cfun_save_high_fprs_p
7246 || get_frame_size () > 0
7247 || cfun
->calls_alloca
7250 for (i
= 6; i
< 16; i
++)
7251 if (df_regs_ever_live_p (i
) || clobbered_regs
[i
])
7253 for (j
= 15; j
> i
; j
--)
7254 if (df_regs_ever_live_p (j
) || clobbered_regs
[j
])
7259 /* Nothing to save/restore. */
7260 cfun_frame_layout
.first_save_gpr_slot
= -1;
7261 cfun_frame_layout
.last_save_gpr_slot
= -1;
7262 cfun_frame_layout
.first_save_gpr
= -1;
7263 cfun_frame_layout
.first_restore_gpr
= -1;
7264 cfun_frame_layout
.last_save_gpr
= -1;
7265 cfun_frame_layout
.last_restore_gpr
= -1;
7269 /* Save slots for gprs from i to j. */
7270 cfun_frame_layout
.first_save_gpr_slot
= i
;
7271 cfun_frame_layout
.last_save_gpr_slot
= j
;
7273 for (i
= cfun_frame_layout
.first_save_gpr_slot
;
7274 i
< cfun_frame_layout
.last_save_gpr_slot
+ 1;
7276 if (clobbered_regs
[i
])
7279 for (j
= cfun_frame_layout
.last_save_gpr_slot
; j
> i
; j
--)
7280 if (clobbered_regs
[j
])
7283 if (i
== cfun_frame_layout
.last_save_gpr_slot
+ 1)
7285 /* Nothing to save/restore. */
7286 cfun_frame_layout
.first_save_gpr
= -1;
7287 cfun_frame_layout
.first_restore_gpr
= -1;
7288 cfun_frame_layout
.last_save_gpr
= -1;
7289 cfun_frame_layout
.last_restore_gpr
= -1;
7293 /* Save / Restore from gpr i to j. */
7294 cfun_frame_layout
.first_save_gpr
= i
;
7295 cfun_frame_layout
.first_restore_gpr
= i
;
7296 cfun_frame_layout
.last_save_gpr
= j
;
7297 cfun_frame_layout
.last_restore_gpr
= j
;
7303 /* Varargs functions need to save gprs 2 to 6. */
7304 if (cfun
->va_list_gpr_size
7305 && crtl
->args
.info
.gprs
< GP_ARG_NUM_REG
)
7307 int min_gpr
= crtl
->args
.info
.gprs
;
7308 int max_gpr
= min_gpr
+ cfun
->va_list_gpr_size
;
7309 if (max_gpr
> GP_ARG_NUM_REG
)
7310 max_gpr
= GP_ARG_NUM_REG
;
7312 if (cfun_frame_layout
.first_save_gpr
== -1
7313 || cfun_frame_layout
.first_save_gpr
> 2 + min_gpr
)
7315 cfun_frame_layout
.first_save_gpr
= 2 + min_gpr
;
7316 cfun_frame_layout
.first_save_gpr_slot
= 2 + min_gpr
;
7319 if (cfun_frame_layout
.last_save_gpr
== -1
7320 || cfun_frame_layout
.last_save_gpr
< 2 + max_gpr
- 1)
7322 cfun_frame_layout
.last_save_gpr
= 2 + max_gpr
- 1;
7323 cfun_frame_layout
.last_save_gpr_slot
= 2 + max_gpr
- 1;
7327 /* Mark f0, f2 for 31 bit and f0-f4 for 64 bit to be saved. */
7328 if (TARGET_HARD_FLOAT
&& cfun
->va_list_fpr_size
7329 && crtl
->args
.info
.fprs
< FP_ARG_NUM_REG
)
7331 int min_fpr
= crtl
->args
.info
.fprs
;
7332 int max_fpr
= min_fpr
+ cfun
->va_list_fpr_size
;
7333 if (max_fpr
> FP_ARG_NUM_REG
)
7334 max_fpr
= FP_ARG_NUM_REG
;
7336 /* ??? This is currently required to ensure proper location
7337 of the fpr save slots within the va_list save area. */
7338 if (TARGET_PACKED_STACK
)
7341 for (i
= min_fpr
; i
< max_fpr
; i
++)
7342 cfun_set_fpr_bit (i
);
7347 for (i
= 2; i
< 4; i
++)
7348 if (df_regs_ever_live_p (i
+ 16) && !global_regs
[i
+ 16])
7349 cfun_set_fpr_bit (i
);
7352 /* Fill cfun->machine with info about frame of current function. */
7355 s390_frame_info (void)
7359 cfun_frame_layout
.frame_size
= get_frame_size ();
7360 if (!TARGET_64BIT
&& cfun_frame_layout
.frame_size
> 0x7fff0000)
7361 fatal_error ("total size of local variables exceeds architecture limit");
7363 if (!TARGET_PACKED_STACK
)
7365 cfun_frame_layout
.backchain_offset
= 0;
7366 cfun_frame_layout
.f0_offset
= 16 * UNITS_PER_LONG
;
7367 cfun_frame_layout
.f4_offset
= cfun_frame_layout
.f0_offset
+ 2 * 8;
7368 cfun_frame_layout
.f8_offset
= -cfun_frame_layout
.high_fprs
* 8;
7369 cfun_frame_layout
.gprs_offset
= (cfun_frame_layout
.first_save_gpr_slot
7372 else if (TARGET_BACKCHAIN
) /* kernel stack layout */
7374 cfun_frame_layout
.backchain_offset
= (STACK_POINTER_OFFSET
7376 cfun_frame_layout
.gprs_offset
7377 = (cfun_frame_layout
.backchain_offset
7378 - (STACK_POINTER_REGNUM
- cfun_frame_layout
.first_save_gpr_slot
+ 1)
7383 cfun_frame_layout
.f4_offset
7384 = (cfun_frame_layout
.gprs_offset
7385 - 8 * (cfun_fpr_bit_p (2) + cfun_fpr_bit_p (3)));
7387 cfun_frame_layout
.f0_offset
7388 = (cfun_frame_layout
.f4_offset
7389 - 8 * (cfun_fpr_bit_p (0) + cfun_fpr_bit_p (1)));
7393 /* On 31 bit we have to care about alignment of the
7394 floating point regs to provide fastest access. */
7395 cfun_frame_layout
.f0_offset
7396 = ((cfun_frame_layout
.gprs_offset
7397 & ~(STACK_BOUNDARY
/ BITS_PER_UNIT
- 1))
7398 - 8 * (cfun_fpr_bit_p (0) + cfun_fpr_bit_p (1)));
7400 cfun_frame_layout
.f4_offset
7401 = (cfun_frame_layout
.f0_offset
7402 - 8 * (cfun_fpr_bit_p (2) + cfun_fpr_bit_p (3)));
7405 else /* no backchain */
7407 cfun_frame_layout
.f4_offset
7408 = (STACK_POINTER_OFFSET
7409 - 8 * (cfun_fpr_bit_p (2) + cfun_fpr_bit_p (3)));
7411 cfun_frame_layout
.f0_offset
7412 = (cfun_frame_layout
.f4_offset
7413 - 8 * (cfun_fpr_bit_p (0) + cfun_fpr_bit_p (1)));
7415 cfun_frame_layout
.gprs_offset
7416 = cfun_frame_layout
.f0_offset
- cfun_gprs_save_area_size
;
7419 if (current_function_is_leaf
7420 && !TARGET_TPF_PROFILING
7421 && cfun_frame_layout
.frame_size
== 0
7422 && !cfun_save_high_fprs_p
7423 && !cfun
->calls_alloca
7427 if (!TARGET_PACKED_STACK
)
7428 cfun_frame_layout
.frame_size
+= (STACK_POINTER_OFFSET
7429 + crtl
->outgoing_args_size
7430 + cfun_frame_layout
.high_fprs
* 8);
7433 if (TARGET_BACKCHAIN
)
7434 cfun_frame_layout
.frame_size
+= UNITS_PER_LONG
;
7436 /* No alignment trouble here because f8-f15 are only saved under
7438 cfun_frame_layout
.f8_offset
= (MIN (MIN (cfun_frame_layout
.f0_offset
,
7439 cfun_frame_layout
.f4_offset
),
7440 cfun_frame_layout
.gprs_offset
)
7441 - cfun_frame_layout
.high_fprs
* 8);
7443 cfun_frame_layout
.frame_size
+= cfun_frame_layout
.high_fprs
* 8;
7445 for (i
= 0; i
< 8; i
++)
7446 if (cfun_fpr_bit_p (i
))
7447 cfun_frame_layout
.frame_size
+= 8;
7449 cfun_frame_layout
.frame_size
+= cfun_gprs_save_area_size
;
7451 /* If under 31 bit an odd number of gprs has to be saved we have to adjust
7452 the frame size to sustain 8 byte alignment of stack frames. */
7453 cfun_frame_layout
.frame_size
= ((cfun_frame_layout
.frame_size
+
7454 STACK_BOUNDARY
/ BITS_PER_UNIT
- 1)
7455 & ~(STACK_BOUNDARY
/ BITS_PER_UNIT
- 1));
7457 cfun_frame_layout
.frame_size
+= crtl
->outgoing_args_size
;
7461 /* Generate frame layout. Fills in register and frame data for the current
7462 function in cfun->machine. This routine can be called multiple times;
7463 it will re-do the complete frame layout every time. */
7466 s390_init_frame_layout (void)
7468 HOST_WIDE_INT frame_size
;
7470 int clobbered_regs
[16];
7472 /* On S/390 machines, we may need to perform branch splitting, which
7473 will require both base and return address register. We have no
7474 choice but to assume we're going to need them until right at the
7475 end of the machine dependent reorg phase. */
7476 if (!TARGET_CPU_ZARCH
)
7477 cfun
->machine
->split_branches_pending_p
= true;
7481 frame_size
= cfun_frame_layout
.frame_size
;
7483 /* Try to predict whether we'll need the base register. */
7484 base_used
= cfun
->machine
->split_branches_pending_p
7485 || crtl
->uses_const_pool
7486 || (!DISP_IN_RANGE (frame_size
)
7487 && !CONST_OK_FOR_K (frame_size
));
7489 /* Decide which register to use as literal pool base. In small
7490 leaf functions, try to use an unused call-clobbered register
7491 as base register to avoid save/restore overhead. */
7493 cfun
->machine
->base_reg
= NULL_RTX
;
7494 else if (current_function_is_leaf
&& !df_regs_ever_live_p (5))
7495 cfun
->machine
->base_reg
= gen_rtx_REG (Pmode
, 5);
7497 cfun
->machine
->base_reg
= gen_rtx_REG (Pmode
, BASE_REGNUM
);
7499 s390_register_info (clobbered_regs
);
7502 while (frame_size
!= cfun_frame_layout
.frame_size
);
7505 /* Update frame layout. Recompute actual register save data based on
7506 current info and update regs_ever_live for the special registers.
7507 May be called multiple times, but may never cause *more* registers
7508 to be saved than s390_init_frame_layout allocated room for. */
7511 s390_update_frame_layout (void)
7513 int clobbered_regs
[16];
7515 s390_register_info (clobbered_regs
);
7517 df_set_regs_ever_live (BASE_REGNUM
,
7518 clobbered_regs
[BASE_REGNUM
] ? true : false);
7519 df_set_regs_ever_live (RETURN_REGNUM
,
7520 clobbered_regs
[RETURN_REGNUM
] ? true : false);
7521 df_set_regs_ever_live (STACK_POINTER_REGNUM
,
7522 clobbered_regs
[STACK_POINTER_REGNUM
] ? true : false);
7524 if (cfun
->machine
->base_reg
)
7525 df_set_regs_ever_live (REGNO (cfun
->machine
->base_reg
), true);
7528 /* Return true if it is legal to put a value with MODE into REGNO. */
7531 s390_hard_regno_mode_ok (unsigned int regno
, enum machine_mode mode
)
7533 switch (REGNO_REG_CLASS (regno
))
7536 if (REGNO_PAIR_OK (regno
, mode
))
7538 if (mode
== SImode
|| mode
== DImode
)
7541 if (FLOAT_MODE_P (mode
) && GET_MODE_CLASS (mode
) != MODE_VECTOR_FLOAT
)
7546 if (FRAME_REGNO_P (regno
) && mode
== Pmode
)
7551 if (REGNO_PAIR_OK (regno
, mode
))
7554 || (mode
!= TFmode
&& mode
!= TCmode
&& mode
!= TDmode
))
7559 if (GET_MODE_CLASS (mode
) == MODE_CC
)
7563 if (REGNO_PAIR_OK (regno
, mode
))
7565 if (mode
== SImode
|| mode
== Pmode
)
7576 /* Return nonzero if register OLD_REG can be renamed to register NEW_REG. */
7579 s390_hard_regno_rename_ok (unsigned int old_reg
, unsigned int new_reg
)
7581 /* Once we've decided upon a register to use as base register, it must
7582 no longer be used for any other purpose. */
7583 if (cfun
->machine
->base_reg
)
7584 if (REGNO (cfun
->machine
->base_reg
) == old_reg
7585 || REGNO (cfun
->machine
->base_reg
) == new_reg
)
7591 /* Maximum number of registers to represent a value of mode MODE
7592 in a register of class RCLASS. */
7595 s390_class_max_nregs (enum reg_class rclass
, enum machine_mode mode
)
7600 if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
)
7601 return 2 * ((GET_MODE_SIZE (mode
) / 2 + 8 - 1) / 8);
7603 return (GET_MODE_SIZE (mode
) + 8 - 1) / 8;
7605 return (GET_MODE_SIZE (mode
) + 4 - 1) / 4;
7609 return (GET_MODE_SIZE (mode
) + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
7612 /* Return true if register FROM can be eliminated via register TO. */
7615 s390_can_eliminate (const int from
, const int to
)
7617 /* On zSeries machines, we have not marked the base register as fixed.
7618 Instead, we have an elimination rule BASE_REGNUM -> BASE_REGNUM.
7619 If a function requires the base register, we say here that this
7620 elimination cannot be performed. This will cause reload to free
7621 up the base register (as if it were fixed). On the other hand,
7622 if the current function does *not* require the base register, we
7623 say here the elimination succeeds, which in turn allows reload
7624 to allocate the base register for any other purpose. */
7625 if (from
== BASE_REGNUM
&& to
== BASE_REGNUM
)
7627 if (TARGET_CPU_ZARCH
)
7629 s390_init_frame_layout ();
7630 return cfun
->machine
->base_reg
== NULL_RTX
;
7636 /* Everything else must point into the stack frame. */
7637 gcc_assert (to
== STACK_POINTER_REGNUM
7638 || to
== HARD_FRAME_POINTER_REGNUM
);
7640 gcc_assert (from
== FRAME_POINTER_REGNUM
7641 || from
== ARG_POINTER_REGNUM
7642 || from
== RETURN_ADDRESS_POINTER_REGNUM
);
7644 /* Make sure we actually saved the return address. */
7645 if (from
== RETURN_ADDRESS_POINTER_REGNUM
)
7646 if (!crtl
->calls_eh_return
7648 && !cfun_frame_layout
.save_return_addr_p
)
7654 /* Return offset between register FROM and TO initially after prolog. */
7657 s390_initial_elimination_offset (int from
, int to
)
7659 HOST_WIDE_INT offset
;
7662 /* ??? Why are we called for non-eliminable pairs? */
7663 if (!s390_can_eliminate (from
, to
))
7668 case FRAME_POINTER_REGNUM
:
7669 offset
= (get_frame_size()
7670 + STACK_POINTER_OFFSET
7671 + crtl
->outgoing_args_size
);
7674 case ARG_POINTER_REGNUM
:
7675 s390_init_frame_layout ();
7676 offset
= cfun_frame_layout
.frame_size
+ STACK_POINTER_OFFSET
;
7679 case RETURN_ADDRESS_POINTER_REGNUM
:
7680 s390_init_frame_layout ();
7681 index
= RETURN_REGNUM
- cfun_frame_layout
.first_save_gpr_slot
;
7682 gcc_assert (index
>= 0);
7683 offset
= cfun_frame_layout
.frame_size
+ cfun_frame_layout
.gprs_offset
;
7684 offset
+= index
* UNITS_PER_LONG
;
7698 /* Emit insn to save fpr REGNUM at offset OFFSET relative
7699 to register BASE. Return generated insn. */
7702 save_fpr (rtx base
, int offset
, int regnum
)
7705 addr
= gen_rtx_MEM (DFmode
, plus_constant (base
, offset
));
7707 if (regnum
>= 16 && regnum
<= (16 + FP_ARG_NUM_REG
))
7708 set_mem_alias_set (addr
, get_varargs_alias_set ());
7710 set_mem_alias_set (addr
, get_frame_alias_set ());
7712 return emit_move_insn (addr
, gen_rtx_REG (DFmode
, regnum
));
7715 /* Emit insn to restore fpr REGNUM from offset OFFSET relative
7716 to register BASE. Return generated insn. */
7719 restore_fpr (rtx base
, int offset
, int regnum
)
7722 addr
= gen_rtx_MEM (DFmode
, plus_constant (base
, offset
));
7723 set_mem_alias_set (addr
, get_frame_alias_set ());
7725 return emit_move_insn (gen_rtx_REG (DFmode
, regnum
), addr
);
7728 /* Return true if REGNO is a global register, but not one
7729 of the special ones that need to be saved/restored in anyway. */
7732 global_not_special_regno_p (int regno
)
7734 return (global_regs
[regno
]
7735 /* These registers are special and need to be
7736 restored in any case. */
7737 && !(regno
== STACK_POINTER_REGNUM
7738 || regno
== RETURN_REGNUM
7739 || regno
== BASE_REGNUM
7740 || (flag_pic
&& regno
== (int)PIC_OFFSET_TABLE_REGNUM
)));
7743 /* Generate insn to save registers FIRST to LAST into
7744 the register save area located at offset OFFSET
7745 relative to register BASE. */
7748 save_gprs (rtx base
, int offset
, int first
, int last
)
7750 rtx addr
, insn
, note
;
7753 addr
= plus_constant (base
, offset
);
7754 addr
= gen_rtx_MEM (Pmode
, addr
);
7756 set_mem_alias_set (addr
, get_frame_alias_set ());
7758 /* Special-case single register. */
7762 insn
= gen_movdi (addr
, gen_rtx_REG (Pmode
, first
));
7764 insn
= gen_movsi (addr
, gen_rtx_REG (Pmode
, first
));
7766 if (!global_not_special_regno_p (first
))
7767 RTX_FRAME_RELATED_P (insn
) = 1;
7772 insn
= gen_store_multiple (addr
,
7773 gen_rtx_REG (Pmode
, first
),
7774 GEN_INT (last
- first
+ 1));
7776 if (first
<= 6 && cfun
->stdarg
)
7777 for (i
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
7779 rtx mem
= XEXP (XVECEXP (PATTERN (insn
), 0, i
), 0);
7782 set_mem_alias_set (mem
, get_varargs_alias_set ());
7785 /* We need to set the FRAME_RELATED flag on all SETs
7786 inside the store-multiple pattern.
7788 However, we must not emit DWARF records for registers 2..5
7789 if they are stored for use by variable arguments ...
7791 ??? Unfortunately, it is not enough to simply not the
7792 FRAME_RELATED flags for those SETs, because the first SET
7793 of the PARALLEL is always treated as if it had the flag
7794 set, even if it does not. Therefore we emit a new pattern
7795 without those registers as REG_FRAME_RELATED_EXPR note. */
7797 if (first
>= 6 && !global_not_special_regno_p (first
))
7799 rtx pat
= PATTERN (insn
);
7801 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
7802 if (GET_CODE (XVECEXP (pat
, 0, i
)) == SET
7803 && !global_not_special_regno_p (REGNO (SET_SRC (XVECEXP (pat
,
7805 RTX_FRAME_RELATED_P (XVECEXP (pat
, 0, i
)) = 1;
7807 RTX_FRAME_RELATED_P (insn
) = 1;
7813 for (start
= first
>= 6 ? first
: 6; start
<= last
; start
++)
7814 if (!global_not_special_regno_p (start
))
7820 addr
= plus_constant (base
, offset
+ (start
- first
) * UNITS_PER_LONG
);
7821 note
= gen_store_multiple (gen_rtx_MEM (Pmode
, addr
),
7822 gen_rtx_REG (Pmode
, start
),
7823 GEN_INT (last
- start
+ 1));
7824 note
= PATTERN (note
);
7826 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
, note
);
7828 for (i
= 0; i
< XVECLEN (note
, 0); i
++)
7829 if (GET_CODE (XVECEXP (note
, 0, i
)) == SET
7830 && !global_not_special_regno_p (REGNO (SET_SRC (XVECEXP (note
,
7832 RTX_FRAME_RELATED_P (XVECEXP (note
, 0, i
)) = 1;
7834 RTX_FRAME_RELATED_P (insn
) = 1;
7840 /* Generate insn to restore registers FIRST to LAST from
7841 the register save area located at offset OFFSET
7842 relative to register BASE. */
7845 restore_gprs (rtx base
, int offset
, int first
, int last
)
7849 addr
= plus_constant (base
, offset
);
7850 addr
= gen_rtx_MEM (Pmode
, addr
);
7851 set_mem_alias_set (addr
, get_frame_alias_set ());
7853 /* Special-case single register. */
7857 insn
= gen_movdi (gen_rtx_REG (Pmode
, first
), addr
);
7859 insn
= gen_movsi (gen_rtx_REG (Pmode
, first
), addr
);
7864 insn
= gen_load_multiple (gen_rtx_REG (Pmode
, first
),
7866 GEN_INT (last
- first
+ 1));
7870 /* Return insn sequence to load the GOT register. */
7872 static GTY(()) rtx got_symbol
;
7874 s390_load_got (void)
7880 got_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "_GLOBAL_OFFSET_TABLE_");
7881 SYMBOL_REF_FLAGS (got_symbol
) = SYMBOL_FLAG_LOCAL
;
7886 if (TARGET_CPU_ZARCH
)
7888 emit_move_insn (pic_offset_table_rtx
, got_symbol
);
7894 offset
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, got_symbol
),
7895 UNSPEC_LTREL_OFFSET
);
7896 offset
= gen_rtx_CONST (Pmode
, offset
);
7897 offset
= force_const_mem (Pmode
, offset
);
7899 emit_move_insn (pic_offset_table_rtx
, offset
);
7901 offset
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, XEXP (offset
, 0)),
7903 offset
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, offset
);
7905 emit_move_insn (pic_offset_table_rtx
, offset
);
7908 insns
= get_insns ();
7913 /* This ties together stack memory (MEM with an alias set of frame_alias_set)
7914 and the change to the stack pointer. */
7917 s390_emit_stack_tie (void)
7919 rtx mem
= gen_frame_mem (BLKmode
,
7920 gen_rtx_REG (Pmode
, STACK_POINTER_REGNUM
));
7922 emit_insn (gen_stack_tie (mem
));
7925 /* Expand the prologue into a bunch of separate insns. */
7928 s390_emit_prologue (void)
7936 /* Complete frame layout. */
7938 s390_update_frame_layout ();
7940 /* Annotate all constant pool references to let the scheduler know
7941 they implicitly use the base register. */
7943 push_topmost_sequence ();
7945 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
7948 annotate_constant_pool_refs (&PATTERN (insn
));
7949 df_insn_rescan (insn
);
7952 pop_topmost_sequence ();
7954 /* Choose best register to use for temp use within prologue.
7955 See below for why TPF must use the register 1. */
7957 if (!has_hard_reg_initial_val (Pmode
, RETURN_REGNUM
)
7958 && !current_function_is_leaf
7959 && !TARGET_TPF_PROFILING
)
7960 temp_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
7962 temp_reg
= gen_rtx_REG (Pmode
, 1);
7964 /* Save call saved gprs. */
7965 if (cfun_frame_layout
.first_save_gpr
!= -1)
7967 insn
= save_gprs (stack_pointer_rtx
,
7968 cfun_frame_layout
.gprs_offset
+
7969 UNITS_PER_LONG
* (cfun_frame_layout
.first_save_gpr
7970 - cfun_frame_layout
.first_save_gpr_slot
),
7971 cfun_frame_layout
.first_save_gpr
,
7972 cfun_frame_layout
.last_save_gpr
);
7976 /* Dummy insn to mark literal pool slot. */
7978 if (cfun
->machine
->base_reg
)
7979 emit_insn (gen_main_pool (cfun
->machine
->base_reg
));
7981 offset
= cfun_frame_layout
.f0_offset
;
7983 /* Save f0 and f2. */
7984 for (i
= 0; i
< 2; i
++)
7986 if (cfun_fpr_bit_p (i
))
7988 save_fpr (stack_pointer_rtx
, offset
, i
+ 16);
7991 else if (!TARGET_PACKED_STACK
)
7995 /* Save f4 and f6. */
7996 offset
= cfun_frame_layout
.f4_offset
;
7997 for (i
= 2; i
< 4; i
++)
7999 if (cfun_fpr_bit_p (i
))
8001 insn
= save_fpr (stack_pointer_rtx
, offset
, i
+ 16);
8004 /* If f4 and f6 are call clobbered they are saved due to stdargs and
8005 therefore are not frame related. */
8006 if (!call_really_used_regs
[i
+ 16])
8007 RTX_FRAME_RELATED_P (insn
) = 1;
8009 else if (!TARGET_PACKED_STACK
)
8013 if (TARGET_PACKED_STACK
8014 && cfun_save_high_fprs_p
8015 && cfun_frame_layout
.f8_offset
+ cfun_frame_layout
.high_fprs
* 8 > 0)
8017 offset
= (cfun_frame_layout
.f8_offset
8018 + (cfun_frame_layout
.high_fprs
- 1) * 8);
8020 for (i
= 15; i
> 7 && offset
>= 0; i
--)
8021 if (cfun_fpr_bit_p (i
))
8023 insn
= save_fpr (stack_pointer_rtx
, offset
, i
+ 16);
8025 RTX_FRAME_RELATED_P (insn
) = 1;
8028 if (offset
>= cfun_frame_layout
.f8_offset
)
8032 if (!TARGET_PACKED_STACK
)
8033 next_fpr
= cfun_save_high_fprs_p
? 31 : 0;
8035 if (flag_stack_usage
)
8036 current_function_static_stack_size
= cfun_frame_layout
.frame_size
;
8038 /* Decrement stack pointer. */
8040 if (cfun_frame_layout
.frame_size
> 0)
8042 rtx frame_off
= GEN_INT (-cfun_frame_layout
.frame_size
);
8045 if (s390_stack_size
)
8047 HOST_WIDE_INT stack_guard
;
8049 if (s390_stack_guard
)
8050 stack_guard
= s390_stack_guard
;
8053 /* If no value for stack guard is provided the smallest power of 2
8054 larger than the current frame size is chosen. */
8056 while (stack_guard
< cfun_frame_layout
.frame_size
)
8060 if (cfun_frame_layout
.frame_size
>= s390_stack_size
)
8062 warning (0, "frame size of function %qs is "
8063 HOST_WIDE_INT_PRINT_DEC
8064 " bytes exceeding user provided stack limit of "
8065 HOST_WIDE_INT_PRINT_DEC
" bytes. "
8066 "An unconditional trap is added.",
8067 current_function_name(), cfun_frame_layout
.frame_size
,
8069 emit_insn (gen_trap ());
8073 /* stack_guard has to be smaller than s390_stack_size.
8074 Otherwise we would emit an AND with zero which would
8075 not match the test under mask pattern. */
8076 if (stack_guard
>= s390_stack_size
)
8078 warning (0, "frame size of function %qs is "
8079 HOST_WIDE_INT_PRINT_DEC
8080 " bytes which is more than half the stack size. "
8081 "The dynamic check would not be reliable. "
8082 "No check emitted for this function.",
8083 current_function_name(),
8084 cfun_frame_layout
.frame_size
);
8088 HOST_WIDE_INT stack_check_mask
= ((s390_stack_size
- 1)
8089 & ~(stack_guard
- 1));
8091 rtx t
= gen_rtx_AND (Pmode
, stack_pointer_rtx
,
8092 GEN_INT (stack_check_mask
));
8094 emit_insn (gen_ctrapdi4 (gen_rtx_EQ (VOIDmode
,
8096 t
, const0_rtx
, const0_rtx
));
8098 emit_insn (gen_ctrapsi4 (gen_rtx_EQ (VOIDmode
,
8100 t
, const0_rtx
, const0_rtx
));
8105 if (s390_warn_framesize
> 0
8106 && cfun_frame_layout
.frame_size
>= s390_warn_framesize
)
8107 warning (0, "frame size of %qs is " HOST_WIDE_INT_PRINT_DEC
" bytes",
8108 current_function_name (), cfun_frame_layout
.frame_size
);
8110 if (s390_warn_dynamicstack_p
&& cfun
->calls_alloca
)
8111 warning (0, "%qs uses dynamic stack allocation", current_function_name ());
8113 /* Save incoming stack pointer into temp reg. */
8114 if (TARGET_BACKCHAIN
|| next_fpr
)
8115 insn
= emit_insn (gen_move_insn (temp_reg
, stack_pointer_rtx
));
8117 /* Subtract frame size from stack pointer. */
8119 if (DISP_IN_RANGE (INTVAL (frame_off
)))
8121 insn
= gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
8122 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
8124 insn
= emit_insn (insn
);
8128 if (!CONST_OK_FOR_K (INTVAL (frame_off
)))
8129 frame_off
= force_const_mem (Pmode
, frame_off
);
8131 insn
= emit_insn (gen_add2_insn (stack_pointer_rtx
, frame_off
));
8132 annotate_constant_pool_refs (&PATTERN (insn
));
8135 RTX_FRAME_RELATED_P (insn
) = 1;
8136 real_frame_off
= GEN_INT (-cfun_frame_layout
.frame_size
);
8137 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
,
8138 gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
8139 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
8142 /* Set backchain. */
8144 if (TARGET_BACKCHAIN
)
8146 if (cfun_frame_layout
.backchain_offset
)
8147 addr
= gen_rtx_MEM (Pmode
,
8148 plus_constant (stack_pointer_rtx
,
8149 cfun_frame_layout
.backchain_offset
));
8151 addr
= gen_rtx_MEM (Pmode
, stack_pointer_rtx
);
8152 set_mem_alias_set (addr
, get_frame_alias_set ());
8153 insn
= emit_insn (gen_move_insn (addr
, temp_reg
));
8156 /* If we support non-call exceptions (e.g. for Java),
8157 we need to make sure the backchain pointer is set up
8158 before any possibly trapping memory access. */
8159 if (TARGET_BACKCHAIN
&& cfun
->can_throw_non_call_exceptions
)
8161 addr
= gen_rtx_MEM (BLKmode
, gen_rtx_SCRATCH (VOIDmode
));
8162 emit_clobber (addr
);
8166 /* Save fprs 8 - 15 (64 bit ABI). */
8168 if (cfun_save_high_fprs_p
&& next_fpr
)
8170 /* If the stack might be accessed through a different register
8171 we have to make sure that the stack pointer decrement is not
8172 moved below the use of the stack slots. */
8173 s390_emit_stack_tie ();
8175 insn
= emit_insn (gen_add2_insn (temp_reg
,
8176 GEN_INT (cfun_frame_layout
.f8_offset
)));
8180 for (i
= 24; i
<= next_fpr
; i
++)
8181 if (cfun_fpr_bit_p (i
- 16))
8183 rtx addr
= plus_constant (stack_pointer_rtx
,
8184 cfun_frame_layout
.frame_size
8185 + cfun_frame_layout
.f8_offset
8188 insn
= save_fpr (temp_reg
, offset
, i
);
8190 RTX_FRAME_RELATED_P (insn
) = 1;
8191 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
,
8192 gen_rtx_SET (VOIDmode
,
8193 gen_rtx_MEM (DFmode
, addr
),
8194 gen_rtx_REG (DFmode
, i
)));
8198 /* Set frame pointer, if needed. */
8200 if (frame_pointer_needed
)
8202 insn
= emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
);
8203 RTX_FRAME_RELATED_P (insn
) = 1;
8206 /* Set up got pointer, if needed. */
8208 if (flag_pic
&& df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM
))
8210 rtx insns
= s390_load_got ();
8212 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
8213 annotate_constant_pool_refs (&PATTERN (insn
));
8218 if (TARGET_TPF_PROFILING
)
8220 /* Generate a BAS instruction to serve as a function
8221 entry intercept to facilitate the use of tracing
8222 algorithms located at the branch target. */
8223 emit_insn (gen_prologue_tpf ());
8225 /* Emit a blockage here so that all code
8226 lies between the profiling mechanisms. */
8227 emit_insn (gen_blockage ());
8231 /* Expand the epilogue into a bunch of separate insns. */
8234 s390_emit_epilogue (bool sibcall
)
8236 rtx frame_pointer
, return_reg
, cfa_restores
= NULL_RTX
;
8237 int area_bottom
, area_top
, offset
= 0;
8242 if (TARGET_TPF_PROFILING
)
8245 /* Generate a BAS instruction to serve as a function
8246 entry intercept to facilitate the use of tracing
8247 algorithms located at the branch target. */
8249 /* Emit a blockage here so that all code
8250 lies between the profiling mechanisms. */
8251 emit_insn (gen_blockage ());
8253 emit_insn (gen_epilogue_tpf ());
8256 /* Check whether to use frame or stack pointer for restore. */
8258 frame_pointer
= (frame_pointer_needed
8259 ? hard_frame_pointer_rtx
: stack_pointer_rtx
);
8261 s390_frame_area (&area_bottom
, &area_top
);
8263 /* Check whether we can access the register save area.
8264 If not, increment the frame pointer as required. */
8266 if (area_top
<= area_bottom
)
8268 /* Nothing to restore. */
8270 else if (DISP_IN_RANGE (cfun_frame_layout
.frame_size
+ area_bottom
)
8271 && DISP_IN_RANGE (cfun_frame_layout
.frame_size
+ area_top
- 1))
8273 /* Area is in range. */
8274 offset
= cfun_frame_layout
.frame_size
;
8278 rtx insn
, frame_off
, cfa
;
8280 offset
= area_bottom
< 0 ? -area_bottom
: 0;
8281 frame_off
= GEN_INT (cfun_frame_layout
.frame_size
- offset
);
8283 cfa
= gen_rtx_SET (VOIDmode
, frame_pointer
,
8284 gen_rtx_PLUS (Pmode
, frame_pointer
, frame_off
));
8285 if (DISP_IN_RANGE (INTVAL (frame_off
)))
8287 insn
= gen_rtx_SET (VOIDmode
, frame_pointer
,
8288 gen_rtx_PLUS (Pmode
, frame_pointer
, frame_off
));
8289 insn
= emit_insn (insn
);
8293 if (!CONST_OK_FOR_K (INTVAL (frame_off
)))
8294 frame_off
= force_const_mem (Pmode
, frame_off
);
8296 insn
= emit_insn (gen_add2_insn (frame_pointer
, frame_off
));
8297 annotate_constant_pool_refs (&PATTERN (insn
));
8299 add_reg_note (insn
, REG_CFA_ADJUST_CFA
, cfa
);
8300 RTX_FRAME_RELATED_P (insn
) = 1;
8303 /* Restore call saved fprs. */
8307 if (cfun_save_high_fprs_p
)
8309 next_offset
= cfun_frame_layout
.f8_offset
;
8310 for (i
= 24; i
< 32; i
++)
8312 if (cfun_fpr_bit_p (i
- 16))
8314 restore_fpr (frame_pointer
,
8315 offset
+ next_offset
, i
);
8317 = alloc_reg_note (REG_CFA_RESTORE
,
8318 gen_rtx_REG (DFmode
, i
), cfa_restores
);
8327 next_offset
= cfun_frame_layout
.f4_offset
;
8328 for (i
= 18; i
< 20; i
++)
8330 if (cfun_fpr_bit_p (i
- 16))
8332 restore_fpr (frame_pointer
,
8333 offset
+ next_offset
, i
);
8335 = alloc_reg_note (REG_CFA_RESTORE
,
8336 gen_rtx_REG (DFmode
, i
), cfa_restores
);
8339 else if (!TARGET_PACKED_STACK
)
8345 /* Return register. */
8347 return_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
8349 /* Restore call saved gprs. */
8351 if (cfun_frame_layout
.first_restore_gpr
!= -1)
8356 /* Check for global register and save them
8357 to stack location from where they get restored. */
8359 for (i
= cfun_frame_layout
.first_restore_gpr
;
8360 i
<= cfun_frame_layout
.last_restore_gpr
;
8363 if (global_not_special_regno_p (i
))
8365 addr
= plus_constant (frame_pointer
,
8366 offset
+ cfun_frame_layout
.gprs_offset
8367 + (i
- cfun_frame_layout
.first_save_gpr_slot
)
8369 addr
= gen_rtx_MEM (Pmode
, addr
);
8370 set_mem_alias_set (addr
, get_frame_alias_set ());
8371 emit_move_insn (addr
, gen_rtx_REG (Pmode
, i
));
8375 = alloc_reg_note (REG_CFA_RESTORE
,
8376 gen_rtx_REG (Pmode
, i
), cfa_restores
);
8381 /* Fetch return address from stack before load multiple,
8382 this will do good for scheduling. */
8384 if (cfun_frame_layout
.save_return_addr_p
8385 || (cfun_frame_layout
.first_restore_gpr
< BASE_REGNUM
8386 && cfun_frame_layout
.last_restore_gpr
> RETURN_REGNUM
))
8388 int return_regnum
= find_unused_clobbered_reg();
8391 return_reg
= gen_rtx_REG (Pmode
, return_regnum
);
8393 addr
= plus_constant (frame_pointer
,
8394 offset
+ cfun_frame_layout
.gprs_offset
8396 - cfun_frame_layout
.first_save_gpr_slot
)
8398 addr
= gen_rtx_MEM (Pmode
, addr
);
8399 set_mem_alias_set (addr
, get_frame_alias_set ());
8400 emit_move_insn (return_reg
, addr
);
8404 insn
= restore_gprs (frame_pointer
,
8405 offset
+ cfun_frame_layout
.gprs_offset
8406 + (cfun_frame_layout
.first_restore_gpr
8407 - cfun_frame_layout
.first_save_gpr_slot
)
8409 cfun_frame_layout
.first_restore_gpr
,
8410 cfun_frame_layout
.last_restore_gpr
);
8411 insn
= emit_insn (insn
);
8412 REG_NOTES (insn
) = cfa_restores
;
8413 add_reg_note (insn
, REG_CFA_DEF_CFA
,
8414 plus_constant (stack_pointer_rtx
, STACK_POINTER_OFFSET
));
8415 RTX_FRAME_RELATED_P (insn
) = 1;
8421 /* Return to caller. */
8423 p
= rtvec_alloc (2);
8425 RTVEC_ELT (p
, 0) = gen_rtx_RETURN (VOIDmode
);
8426 RTVEC_ELT (p
, 1) = gen_rtx_USE (VOIDmode
, return_reg
);
8427 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
8432 /* Return the size in bytes of a function argument of
8433 type TYPE and/or mode MODE. At least one of TYPE or
8434 MODE must be specified. */
8437 s390_function_arg_size (enum machine_mode mode
, const_tree type
)
8440 return int_size_in_bytes (type
);
8442 /* No type info available for some library calls ... */
8443 if (mode
!= BLKmode
)
8444 return GET_MODE_SIZE (mode
);
8446 /* If we have neither type nor mode, abort */
8450 /* Return true if a function argument of type TYPE and mode MODE
8451 is to be passed in a floating-point register, if available. */
8454 s390_function_arg_float (enum machine_mode mode
, const_tree type
)
8456 int size
= s390_function_arg_size (mode
, type
);
8460 /* Soft-float changes the ABI: no floating-point registers are used. */
8461 if (TARGET_SOFT_FLOAT
)
8464 /* No type info available for some library calls ... */
8466 return mode
== SFmode
|| mode
== DFmode
|| mode
== SDmode
|| mode
== DDmode
;
8468 /* The ABI says that record types with a single member are treated
8469 just like that member would be. */
8470 while (TREE_CODE (type
) == RECORD_TYPE
)
8472 tree field
, single
= NULL_TREE
;
8474 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
8476 if (TREE_CODE (field
) != FIELD_DECL
)
8479 if (single
== NULL_TREE
)
8480 single
= TREE_TYPE (field
);
8485 if (single
== NULL_TREE
)
8491 return TREE_CODE (type
) == REAL_TYPE
;
8494 /* Return true if a function argument of type TYPE and mode MODE
8495 is to be passed in an integer register, or a pair of integer
8496 registers, if available. */
8499 s390_function_arg_integer (enum machine_mode mode
, const_tree type
)
8501 int size
= s390_function_arg_size (mode
, type
);
8505 /* No type info available for some library calls ... */
8507 return GET_MODE_CLASS (mode
) == MODE_INT
8508 || (TARGET_SOFT_FLOAT
&& SCALAR_FLOAT_MODE_P (mode
));
8510 /* We accept small integral (and similar) types. */
8511 if (INTEGRAL_TYPE_P (type
)
8512 || POINTER_TYPE_P (type
)
8513 || TREE_CODE (type
) == NULLPTR_TYPE
8514 || TREE_CODE (type
) == OFFSET_TYPE
8515 || (TARGET_SOFT_FLOAT
&& TREE_CODE (type
) == REAL_TYPE
))
8518 /* We also accept structs of size 1, 2, 4, 8 that are not
8519 passed in floating-point registers. */
8520 if (AGGREGATE_TYPE_P (type
)
8521 && exact_log2 (size
) >= 0
8522 && !s390_function_arg_float (mode
, type
))
8528 /* Return 1 if a function argument of type TYPE and mode MODE
8529 is to be passed by reference. The ABI specifies that only
8530 structures of size 1, 2, 4, or 8 bytes are passed by value,
8531 all other structures (and complex numbers) are passed by
8535 s390_pass_by_reference (CUMULATIVE_ARGS
*ca ATTRIBUTE_UNUSED
,
8536 enum machine_mode mode
, const_tree type
,
8537 bool named ATTRIBUTE_UNUSED
)
8539 int size
= s390_function_arg_size (mode
, type
);
8545 if (AGGREGATE_TYPE_P (type
) && exact_log2 (size
) < 0)
8548 if (TREE_CODE (type
) == COMPLEX_TYPE
8549 || TREE_CODE (type
) == VECTOR_TYPE
)
8556 /* Update the data in CUM to advance over an argument of mode MODE and
8557 data type TYPE. (TYPE is null for libcalls where that information
8558 may not be available.). The boolean NAMED specifies whether the
8559 argument is a named argument (as opposed to an unnamed argument
8560 matching an ellipsis). */
8563 s390_function_arg_advance (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
,
8564 const_tree type
, bool named ATTRIBUTE_UNUSED
)
8566 if (s390_function_arg_float (mode
, type
))
8570 else if (s390_function_arg_integer (mode
, type
))
8572 int size
= s390_function_arg_size (mode
, type
);
8573 cum
->gprs
+= ((size
+ UNITS_PER_LONG
- 1) / UNITS_PER_LONG
);
8579 /* Define where to put the arguments to a function.
8580 Value is zero to push the argument on the stack,
8581 or a hard register in which to store the argument.
8583 MODE is the argument's machine mode.
8584 TYPE is the data type of the argument (as a tree).
8585 This is null for libcalls where that information may
8587 CUM is a variable of type CUMULATIVE_ARGS which gives info about
8588 the preceding args and about the function being called.
8589 NAMED is nonzero if this argument is a named parameter
8590 (otherwise it is an extra parameter matching an ellipsis).
8592 On S/390, we use general purpose registers 2 through 6 to
8593 pass integer, pointer, and certain structure arguments, and
8594 floating point registers 0 and 2 (0, 2, 4, and 6 on 64-bit)
8595 to pass floating point arguments. All remaining arguments
8596 are pushed to the stack. */
8599 s390_function_arg (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
,
8600 const_tree type
, bool named ATTRIBUTE_UNUSED
)
8602 if (s390_function_arg_float (mode
, type
))
8604 if (cum
->fprs
+ 1 > FP_ARG_NUM_REG
)
8607 return gen_rtx_REG (mode
, cum
->fprs
+ 16);
8609 else if (s390_function_arg_integer (mode
, type
))
8611 int size
= s390_function_arg_size (mode
, type
);
8612 int n_gprs
= (size
+ UNITS_PER_LONG
- 1) / UNITS_PER_LONG
;
8614 if (cum
->gprs
+ n_gprs
> GP_ARG_NUM_REG
)
8616 else if (n_gprs
== 1 || UNITS_PER_WORD
== UNITS_PER_LONG
)
8617 return gen_rtx_REG (mode
, cum
->gprs
+ 2);
8618 else if (n_gprs
== 2)
8620 rtvec p
= rtvec_alloc (2);
8623 = gen_rtx_EXPR_LIST (SImode
, gen_rtx_REG (SImode
, cum
->gprs
+ 2),
8626 = gen_rtx_EXPR_LIST (SImode
, gen_rtx_REG (SImode
, cum
->gprs
+ 3),
8629 return gen_rtx_PARALLEL (mode
, p
);
8633 /* After the real arguments, expand_call calls us once again
8634 with a void_type_node type. Whatever we return here is
8635 passed as operand 2 to the call expanders.
8637 We don't need this feature ... */
8638 else if (type
== void_type_node
)
8644 /* Return true if return values of type TYPE should be returned
8645 in a memory buffer whose address is passed by the caller as
8646 hidden first argument. */
8649 s390_return_in_memory (const_tree type
, const_tree fundecl ATTRIBUTE_UNUSED
)
8651 /* We accept small integral (and similar) types. */
8652 if (INTEGRAL_TYPE_P (type
)
8653 || POINTER_TYPE_P (type
)
8654 || TREE_CODE (type
) == OFFSET_TYPE
8655 || TREE_CODE (type
) == REAL_TYPE
)
8656 return int_size_in_bytes (type
) > 8;
8658 /* Aggregates and similar constructs are always returned
8660 if (AGGREGATE_TYPE_P (type
)
8661 || TREE_CODE (type
) == COMPLEX_TYPE
8662 || TREE_CODE (type
) == VECTOR_TYPE
)
8665 /* ??? We get called on all sorts of random stuff from
8666 aggregate_value_p. We can't abort, but it's not clear
8667 what's safe to return. Pretend it's a struct I guess. */
8671 /* Function arguments and return values are promoted to word size. */
8673 static enum machine_mode
8674 s390_promote_function_mode (const_tree type
, enum machine_mode mode
,
8676 const_tree fntype ATTRIBUTE_UNUSED
,
8677 int for_return ATTRIBUTE_UNUSED
)
8679 if (INTEGRAL_MODE_P (mode
)
8680 && GET_MODE_SIZE (mode
) < UNITS_PER_LONG
)
8682 if (POINTER_TYPE_P (type
))
8683 *punsignedp
= POINTERS_EXTEND_UNSIGNED
;
8690 /* Define where to return a (scalar) value of type TYPE.
8691 If TYPE is null, define where to return a (scalar)
8692 value of mode MODE from a libcall. */
8695 s390_function_value (const_tree type
, const_tree fn
, enum machine_mode mode
)
8699 int unsignedp
= TYPE_UNSIGNED (type
);
8700 mode
= promote_function_mode (type
, TYPE_MODE (type
), &unsignedp
, fn
, 1);
8703 gcc_assert (GET_MODE_CLASS (mode
) == MODE_INT
|| SCALAR_FLOAT_MODE_P (mode
));
8704 gcc_assert (GET_MODE_SIZE (mode
) <= 8);
8706 if (TARGET_HARD_FLOAT
&& SCALAR_FLOAT_MODE_P (mode
))
8707 return gen_rtx_REG (mode
, 16);
8708 else if (GET_MODE_SIZE (mode
) <= UNITS_PER_LONG
8709 || UNITS_PER_LONG
== UNITS_PER_WORD
)
8710 return gen_rtx_REG (mode
, 2);
8711 else if (GET_MODE_SIZE (mode
) == 2 * UNITS_PER_LONG
)
8713 rtvec p
= rtvec_alloc (2);
8716 = gen_rtx_EXPR_LIST (SImode
, gen_rtx_REG (SImode
, 2), const0_rtx
);
8718 = gen_rtx_EXPR_LIST (SImode
, gen_rtx_REG (SImode
, 3), GEN_INT (4));
8720 return gen_rtx_PARALLEL (mode
, p
);
8727 /* Create and return the va_list datatype.
8729 On S/390, va_list is an array type equivalent to
8731 typedef struct __va_list_tag
8735 void *__overflow_arg_area;
8736 void *__reg_save_area;
8739 where __gpr and __fpr hold the number of general purpose
8740 or floating point arguments used up to now, respectively,
8741 __overflow_arg_area points to the stack location of the
8742 next argument passed on the stack, and __reg_save_area
8743 always points to the start of the register area in the
8744 call frame of the current function. The function prologue
8745 saves all registers used for argument passing into this
8746 area if the function uses variable arguments. */
8749 s390_build_builtin_va_list (void)
8751 tree f_gpr
, f_fpr
, f_ovf
, f_sav
, record
, type_decl
;
8753 record
= lang_hooks
.types
.make_type (RECORD_TYPE
);
8756 build_decl (BUILTINS_LOCATION
,
8757 TYPE_DECL
, get_identifier ("__va_list_tag"), record
);
8759 f_gpr
= build_decl (BUILTINS_LOCATION
,
8760 FIELD_DECL
, get_identifier ("__gpr"),
8761 long_integer_type_node
);
8762 f_fpr
= build_decl (BUILTINS_LOCATION
,
8763 FIELD_DECL
, get_identifier ("__fpr"),
8764 long_integer_type_node
);
8765 f_ovf
= build_decl (BUILTINS_LOCATION
,
8766 FIELD_DECL
, get_identifier ("__overflow_arg_area"),
8768 f_sav
= build_decl (BUILTINS_LOCATION
,
8769 FIELD_DECL
, get_identifier ("__reg_save_area"),
8772 va_list_gpr_counter_field
= f_gpr
;
8773 va_list_fpr_counter_field
= f_fpr
;
8775 DECL_FIELD_CONTEXT (f_gpr
) = record
;
8776 DECL_FIELD_CONTEXT (f_fpr
) = record
;
8777 DECL_FIELD_CONTEXT (f_ovf
) = record
;
8778 DECL_FIELD_CONTEXT (f_sav
) = record
;
8780 TYPE_STUB_DECL (record
) = type_decl
;
8781 TYPE_NAME (record
) = type_decl
;
8782 TYPE_FIELDS (record
) = f_gpr
;
8783 DECL_CHAIN (f_gpr
) = f_fpr
;
8784 DECL_CHAIN (f_fpr
) = f_ovf
;
8785 DECL_CHAIN (f_ovf
) = f_sav
;
8787 layout_type (record
);
8789 /* The correct type is an array type of one element. */
8790 return build_array_type (record
, build_index_type (size_zero_node
));
8793 /* Implement va_start by filling the va_list structure VALIST.
8794 STDARG_P is always true, and ignored.
8795 NEXTARG points to the first anonymous stack argument.
8797 The following global variables are used to initialize
8798 the va_list structure:
8801 holds number of gprs and fprs used for named arguments.
8802 crtl->args.arg_offset_rtx:
8803 holds the offset of the first anonymous stack argument
8804 (relative to the virtual arg pointer). */
8807 s390_va_start (tree valist
, rtx nextarg ATTRIBUTE_UNUSED
)
8809 HOST_WIDE_INT n_gpr
, n_fpr
;
8811 tree f_gpr
, f_fpr
, f_ovf
, f_sav
;
8812 tree gpr
, fpr
, ovf
, sav
, t
;
8814 f_gpr
= TYPE_FIELDS (TREE_TYPE (va_list_type_node
));
8815 f_fpr
= DECL_CHAIN (f_gpr
);
8816 f_ovf
= DECL_CHAIN (f_fpr
);
8817 f_sav
= DECL_CHAIN (f_ovf
);
8819 valist
= build_simple_mem_ref (valist
);
8820 gpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_gpr
), valist
, f_gpr
, NULL_TREE
);
8821 fpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_fpr
), valist
, f_fpr
, NULL_TREE
);
8822 ovf
= build3 (COMPONENT_REF
, TREE_TYPE (f_ovf
), valist
, f_ovf
, NULL_TREE
);
8823 sav
= build3 (COMPONENT_REF
, TREE_TYPE (f_sav
), valist
, f_sav
, NULL_TREE
);
8825 /* Count number of gp and fp argument registers used. */
8827 n_gpr
= crtl
->args
.info
.gprs
;
8828 n_fpr
= crtl
->args
.info
.fprs
;
8830 if (cfun
->va_list_gpr_size
)
8832 t
= build2 (MODIFY_EXPR
, TREE_TYPE (gpr
), gpr
,
8833 build_int_cst (NULL_TREE
, n_gpr
));
8834 TREE_SIDE_EFFECTS (t
) = 1;
8835 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
8838 if (cfun
->va_list_fpr_size
)
8840 t
= build2 (MODIFY_EXPR
, TREE_TYPE (fpr
), fpr
,
8841 build_int_cst (NULL_TREE
, n_fpr
));
8842 TREE_SIDE_EFFECTS (t
) = 1;
8843 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
8846 /* Find the overflow area. */
8847 if (n_gpr
+ cfun
->va_list_gpr_size
> GP_ARG_NUM_REG
8848 || n_fpr
+ cfun
->va_list_fpr_size
> FP_ARG_NUM_REG
)
8850 t
= make_tree (TREE_TYPE (ovf
), virtual_incoming_args_rtx
);
8852 off
= INTVAL (crtl
->args
.arg_offset_rtx
);
8853 off
= off
< 0 ? 0 : off
;
8854 if (TARGET_DEBUG_ARG
)
8855 fprintf (stderr
, "va_start: n_gpr = %d, n_fpr = %d off %d\n",
8856 (int)n_gpr
, (int)n_fpr
, off
);
8858 t
= build2 (POINTER_PLUS_EXPR
, TREE_TYPE (ovf
), t
, size_int (off
));
8860 t
= build2 (MODIFY_EXPR
, TREE_TYPE (ovf
), ovf
, t
);
8861 TREE_SIDE_EFFECTS (t
) = 1;
8862 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
8865 /* Find the register save area. */
8866 if ((cfun
->va_list_gpr_size
&& n_gpr
< GP_ARG_NUM_REG
)
8867 || (cfun
->va_list_fpr_size
&& n_fpr
< FP_ARG_NUM_REG
))
8869 t
= make_tree (TREE_TYPE (sav
), return_address_pointer_rtx
);
8870 t
= build2 (POINTER_PLUS_EXPR
, TREE_TYPE (sav
), t
,
8871 size_int (-RETURN_REGNUM
* UNITS_PER_LONG
));
8873 t
= build2 (MODIFY_EXPR
, TREE_TYPE (sav
), sav
, t
);
8874 TREE_SIDE_EFFECTS (t
) = 1;
8875 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
8879 /* Implement va_arg by updating the va_list structure
8880 VALIST as required to retrieve an argument of type
8881 TYPE, and returning that argument.
8883 Generates code equivalent to:
8885 if (integral value) {
8886 if (size <= 4 && args.gpr < 5 ||
8887 size > 4 && args.gpr < 4 )
8888 ret = args.reg_save_area[args.gpr+8]
8890 ret = *args.overflow_arg_area++;
8891 } else if (float value) {
8893 ret = args.reg_save_area[args.fpr+64]
8895 ret = *args.overflow_arg_area++;
8896 } else if (aggregate value) {
8898 ret = *args.reg_save_area[args.gpr]
8900 ret = **args.overflow_arg_area++;
8904 s390_gimplify_va_arg (tree valist
, tree type
, gimple_seq
*pre_p
,
8905 gimple_seq
*post_p ATTRIBUTE_UNUSED
)
8907 tree f_gpr
, f_fpr
, f_ovf
, f_sav
;
8908 tree gpr
, fpr
, ovf
, sav
, reg
, t
, u
;
8909 int indirect_p
, size
, n_reg
, sav_ofs
, sav_scale
, max_reg
;
8910 tree lab_false
, lab_over
, addr
;
8912 f_gpr
= TYPE_FIELDS (TREE_TYPE (va_list_type_node
));
8913 f_fpr
= DECL_CHAIN (f_gpr
);
8914 f_ovf
= DECL_CHAIN (f_fpr
);
8915 f_sav
= DECL_CHAIN (f_ovf
);
8917 valist
= build_va_arg_indirect_ref (valist
);
8918 gpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_gpr
), valist
, f_gpr
, NULL_TREE
);
8919 fpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_fpr
), valist
, f_fpr
, NULL_TREE
);
8920 sav
= build3 (COMPONENT_REF
, TREE_TYPE (f_sav
), valist
, f_sav
, NULL_TREE
);
8922 /* The tree for args* cannot be shared between gpr/fpr and ovf since
8923 both appear on a lhs. */
8924 valist
= unshare_expr (valist
);
8925 ovf
= build3 (COMPONENT_REF
, TREE_TYPE (f_ovf
), valist
, f_ovf
, NULL_TREE
);
8927 size
= int_size_in_bytes (type
);
8929 if (pass_by_reference (NULL
, TYPE_MODE (type
), type
, false))
8931 if (TARGET_DEBUG_ARG
)
8933 fprintf (stderr
, "va_arg: aggregate type");
8937 /* Aggregates are passed by reference. */
8942 /* kernel stack layout on 31 bit: It is assumed here that no padding
8943 will be added by s390_frame_info because for va_args always an even
8944 number of gprs has to be saved r15-r2 = 14 regs. */
8945 sav_ofs
= 2 * UNITS_PER_LONG
;
8946 sav_scale
= UNITS_PER_LONG
;
8947 size
= UNITS_PER_LONG
;
8948 max_reg
= GP_ARG_NUM_REG
- n_reg
;
8950 else if (s390_function_arg_float (TYPE_MODE (type
), type
))
8952 if (TARGET_DEBUG_ARG
)
8954 fprintf (stderr
, "va_arg: float type");
8958 /* FP args go in FP registers, if present. */
8962 sav_ofs
= 16 * UNITS_PER_LONG
;
8964 max_reg
= FP_ARG_NUM_REG
- n_reg
;
8968 if (TARGET_DEBUG_ARG
)
8970 fprintf (stderr
, "va_arg: other type");
8974 /* Otherwise into GP registers. */
8977 n_reg
= (size
+ UNITS_PER_LONG
- 1) / UNITS_PER_LONG
;
8979 /* kernel stack layout on 31 bit: It is assumed here that no padding
8980 will be added by s390_frame_info because for va_args always an even
8981 number of gprs has to be saved r15-r2 = 14 regs. */
8982 sav_ofs
= 2 * UNITS_PER_LONG
;
8984 if (size
< UNITS_PER_LONG
)
8985 sav_ofs
+= UNITS_PER_LONG
- size
;
8987 sav_scale
= UNITS_PER_LONG
;
8988 max_reg
= GP_ARG_NUM_REG
- n_reg
;
8991 /* Pull the value out of the saved registers ... */
8993 lab_false
= create_artificial_label (UNKNOWN_LOCATION
);
8994 lab_over
= create_artificial_label (UNKNOWN_LOCATION
);
8995 addr
= create_tmp_var (ptr_type_node
, "addr");
8997 t
= fold_convert (TREE_TYPE (reg
), size_int (max_reg
));
8998 t
= build2 (GT_EXPR
, boolean_type_node
, reg
, t
);
8999 u
= build1 (GOTO_EXPR
, void_type_node
, lab_false
);
9000 t
= build3 (COND_EXPR
, void_type_node
, t
, u
, NULL_TREE
);
9001 gimplify_and_add (t
, pre_p
);
9003 t
= build2 (POINTER_PLUS_EXPR
, ptr_type_node
, sav
,
9004 size_int (sav_ofs
));
9005 u
= build2 (MULT_EXPR
, TREE_TYPE (reg
), reg
,
9006 fold_convert (TREE_TYPE (reg
), size_int (sav_scale
)));
9007 t
= build2 (POINTER_PLUS_EXPR
, ptr_type_node
, t
, fold_convert (sizetype
, u
));
9009 gimplify_assign (addr
, t
, pre_p
);
9011 gimple_seq_add_stmt (pre_p
, gimple_build_goto (lab_over
));
9013 gimple_seq_add_stmt (pre_p
, gimple_build_label (lab_false
));
9016 /* ... Otherwise out of the overflow area. */
9019 if (size
< UNITS_PER_LONG
)
9020 t
= build2 (POINTER_PLUS_EXPR
, ptr_type_node
, t
,
9021 size_int (UNITS_PER_LONG
- size
));
9023 gimplify_expr (&t
, pre_p
, NULL
, is_gimple_val
, fb_rvalue
);
9025 gimplify_assign (addr
, t
, pre_p
);
9027 t
= build2 (POINTER_PLUS_EXPR
, ptr_type_node
, t
,
9029 gimplify_assign (ovf
, t
, pre_p
);
9031 gimple_seq_add_stmt (pre_p
, gimple_build_label (lab_over
));
9034 /* Increment register save count. */
9036 u
= build2 (PREINCREMENT_EXPR
, TREE_TYPE (reg
), reg
,
9037 fold_convert (TREE_TYPE (reg
), size_int (n_reg
)));
9038 gimplify_and_add (u
, pre_p
);
9042 t
= build_pointer_type_for_mode (build_pointer_type (type
),
9044 addr
= fold_convert (t
, addr
);
9045 addr
= build_va_arg_indirect_ref (addr
);
9049 t
= build_pointer_type_for_mode (type
, ptr_mode
, true);
9050 addr
= fold_convert (t
, addr
);
9053 return build_va_arg_indirect_ref (addr
);
9061 S390_BUILTIN_THREAD_POINTER
,
9062 S390_BUILTIN_SET_THREAD_POINTER
,
9067 static enum insn_code
const code_for_builtin_64
[S390_BUILTIN_max
] = {
9072 static enum insn_code
const code_for_builtin_31
[S390_BUILTIN_max
] = {
9078 s390_init_builtins (void)
9082 ftype
= build_function_type (ptr_type_node
, void_list_node
);
9083 add_builtin_function ("__builtin_thread_pointer", ftype
,
9084 S390_BUILTIN_THREAD_POINTER
, BUILT_IN_MD
,
9087 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
9088 add_builtin_function ("__builtin_set_thread_pointer", ftype
,
9089 S390_BUILTIN_SET_THREAD_POINTER
, BUILT_IN_MD
,
9093 /* Expand an expression EXP that calls a built-in function,
9094 with result going to TARGET if that's convenient
9095 (and in mode MODE if that's convenient).
9096 SUBTARGET may be used as the target for computing one of EXP's operands.
9097 IGNORE is nonzero if the value is to be ignored. */
9100 s390_expand_builtin (tree exp
, rtx target
, rtx subtarget ATTRIBUTE_UNUSED
,
9101 enum machine_mode mode ATTRIBUTE_UNUSED
,
9102 int ignore ATTRIBUTE_UNUSED
)
9106 enum insn_code
const *code_for_builtin
=
9107 TARGET_64BIT
? code_for_builtin_64
: code_for_builtin_31
;
9109 tree fndecl
= TREE_OPERAND (CALL_EXPR_FN (exp
), 0);
9110 unsigned int fcode
= DECL_FUNCTION_CODE (fndecl
);
9111 enum insn_code icode
;
9112 rtx op
[MAX_ARGS
], pat
;
9116 call_expr_arg_iterator iter
;
9118 if (fcode
>= S390_BUILTIN_max
)
9119 internal_error ("bad builtin fcode");
9120 icode
= code_for_builtin
[fcode
];
9122 internal_error ("bad builtin fcode");
9124 nonvoid
= TREE_TYPE (TREE_TYPE (fndecl
)) != void_type_node
;
9127 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, exp
)
9129 const struct insn_operand_data
*insn_op
;
9131 if (arg
== error_mark_node
)
9133 if (arity
> MAX_ARGS
)
9136 insn_op
= &insn_data
[icode
].operand
[arity
+ nonvoid
];
9138 op
[arity
] = expand_expr (arg
, NULL_RTX
, insn_op
->mode
, EXPAND_NORMAL
);
9140 if (!(*insn_op
->predicate
) (op
[arity
], insn_op
->mode
))
9141 op
[arity
] = copy_to_mode_reg (insn_op
->mode
, op
[arity
]);
9147 enum machine_mode tmode
= insn_data
[icode
].operand
[0].mode
;
9149 || GET_MODE (target
) != tmode
9150 || !(*insn_data
[icode
].operand
[0].predicate
) (target
, tmode
))
9151 target
= gen_reg_rtx (tmode
);
9157 pat
= GEN_FCN (icode
) (target
);
9161 pat
= GEN_FCN (icode
) (target
, op
[0]);
9163 pat
= GEN_FCN (icode
) (op
[0]);
9166 pat
= GEN_FCN (icode
) (target
, op
[0], op
[1]);
9182 /* Output assembly code for the trampoline template to
9185 On S/390, we use gpr 1 internally in the trampoline code;
9186 gpr 0 is used to hold the static chain. */
9189 s390_asm_trampoline_template (FILE *file
)
9192 op
[0] = gen_rtx_REG (Pmode
, 0);
9193 op
[1] = gen_rtx_REG (Pmode
, 1);
9197 output_asm_insn ("basr\t%1,0", op
);
9198 output_asm_insn ("lmg\t%0,%1,14(%1)", op
);
9199 output_asm_insn ("br\t%1", op
);
9200 ASM_OUTPUT_SKIP (file
, (HOST_WIDE_INT
)(TRAMPOLINE_SIZE
- 10));
9204 output_asm_insn ("basr\t%1,0", op
);
9205 output_asm_insn ("lm\t%0,%1,6(%1)", op
);
9206 output_asm_insn ("br\t%1", op
);
9207 ASM_OUTPUT_SKIP (file
, (HOST_WIDE_INT
)(TRAMPOLINE_SIZE
- 8));
9211 /* Emit RTL insns to initialize the variable parts of a trampoline.
9212 FNADDR is an RTX for the address of the function's pure code.
9213 CXT is an RTX for the static chain value for the function. */
9216 s390_trampoline_init (rtx m_tramp
, tree fndecl
, rtx cxt
)
9218 rtx fnaddr
= XEXP (DECL_RTL (fndecl
), 0);
9221 emit_block_move (m_tramp
, assemble_trampoline_template (),
9222 GEN_INT (2*UNITS_PER_WORD
), BLOCK_OP_NORMAL
);
9224 mem
= adjust_address (m_tramp
, Pmode
, 2*UNITS_PER_WORD
);
9225 emit_move_insn (mem
, cxt
);
9226 mem
= adjust_address (m_tramp
, Pmode
, 3*UNITS_PER_WORD
);
9227 emit_move_insn (mem
, fnaddr
);
9230 /* Output assembler code to FILE to increment profiler label # LABELNO
9231 for profiling a function entry. */
9234 s390_function_profiler (FILE *file
, int labelno
)
9239 ASM_GENERATE_INTERNAL_LABEL (label
, "LP", labelno
);
9241 fprintf (file
, "# function profiler \n");
9243 op
[0] = gen_rtx_REG (Pmode
, RETURN_REGNUM
);
9244 op
[1] = gen_rtx_REG (Pmode
, STACK_POINTER_REGNUM
);
9245 op
[1] = gen_rtx_MEM (Pmode
, plus_constant (op
[1], UNITS_PER_LONG
));
9247 op
[2] = gen_rtx_REG (Pmode
, 1);
9248 op
[3] = gen_rtx_SYMBOL_REF (Pmode
, label
);
9249 SYMBOL_REF_FLAGS (op
[3]) = SYMBOL_FLAG_LOCAL
;
9251 op
[4] = gen_rtx_SYMBOL_REF (Pmode
, "_mcount");
9254 op
[4] = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op
[4]), UNSPEC_PLT
);
9255 op
[4] = gen_rtx_CONST (Pmode
, op
[4]);
9260 output_asm_insn ("stg\t%0,%1", op
);
9261 output_asm_insn ("larl\t%2,%3", op
);
9262 output_asm_insn ("brasl\t%0,%4", op
);
9263 output_asm_insn ("lg\t%0,%1", op
);
9267 op
[6] = gen_label_rtx ();
9269 output_asm_insn ("st\t%0,%1", op
);
9270 output_asm_insn ("bras\t%2,%l6", op
);
9271 output_asm_insn (".long\t%4", op
);
9272 output_asm_insn (".long\t%3", op
);
9273 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[6]));
9274 output_asm_insn ("l\t%0,0(%2)", op
);
9275 output_asm_insn ("l\t%2,4(%2)", op
);
9276 output_asm_insn ("basr\t%0,%0", op
);
9277 output_asm_insn ("l\t%0,%1", op
);
9281 op
[5] = gen_label_rtx ();
9282 op
[6] = gen_label_rtx ();
9284 output_asm_insn ("st\t%0,%1", op
);
9285 output_asm_insn ("bras\t%2,%l6", op
);
9286 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[5]));
9287 output_asm_insn (".long\t%4-%l5", op
);
9288 output_asm_insn (".long\t%3-%l5", op
);
9289 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[6]));
9290 output_asm_insn ("lr\t%0,%2", op
);
9291 output_asm_insn ("a\t%0,0(%2)", op
);
9292 output_asm_insn ("a\t%2,4(%2)", op
);
9293 output_asm_insn ("basr\t%0,%0", op
);
9294 output_asm_insn ("l\t%0,%1", op
);
9298 /* Encode symbol attributes (local vs. global, tls model) of a SYMBOL_REF
9299 into its SYMBOL_REF_FLAGS. */
9302 s390_encode_section_info (tree decl
, rtx rtl
, int first
)
9304 default_encode_section_info (decl
, rtl
, first
);
9306 if (TREE_CODE (decl
) == VAR_DECL
)
9308 /* If a variable has a forced alignment to < 2 bytes, mark it
9309 with SYMBOL_FLAG_ALIGN1 to prevent it from being used as LARL
9311 if (DECL_USER_ALIGN (decl
) && DECL_ALIGN (decl
) < 16)
9312 SYMBOL_REF_FLAGS (XEXP (rtl
, 0)) |= SYMBOL_FLAG_ALIGN1
;
9313 if (!DECL_SIZE (decl
)
9314 || !DECL_ALIGN (decl
)
9315 || !host_integerp (DECL_SIZE (decl
), 0)
9316 || (DECL_ALIGN (decl
) <= 64
9317 && DECL_ALIGN (decl
) != tree_low_cst (DECL_SIZE (decl
), 0)))
9318 SYMBOL_REF_FLAGS (XEXP (rtl
, 0)) |= SYMBOL_FLAG_NOT_NATURALLY_ALIGNED
;
9321 /* Literal pool references don't have a decl so they are handled
9322 differently here. We rely on the information in the MEM_ALIGN
9323 entry to decide upon natural alignment. */
9325 && GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
9326 && TREE_CONSTANT_POOL_ADDRESS_P (XEXP (rtl
, 0))
9327 && (MEM_ALIGN (rtl
) == 0
9328 || GET_MODE_BITSIZE (GET_MODE (rtl
)) == 0
9329 || MEM_ALIGN (rtl
) < GET_MODE_BITSIZE (GET_MODE (rtl
))))
9330 SYMBOL_REF_FLAGS (XEXP (rtl
, 0)) |= SYMBOL_FLAG_NOT_NATURALLY_ALIGNED
;
9333 /* Output thunk to FILE that implements a C++ virtual function call (with
9334 multiple inheritance) to FUNCTION. The thunk adjusts the this pointer
9335 by DELTA, and unless VCALL_OFFSET is zero, applies an additional adjustment
9336 stored at VCALL_OFFSET in the vtable whose address is located at offset 0
9337 relative to the resulting this pointer. */
9340 s390_output_mi_thunk (FILE *file
, tree thunk ATTRIBUTE_UNUSED
,
9341 HOST_WIDE_INT delta
, HOST_WIDE_INT vcall_offset
,
9347 /* Make sure unwind info is emitted for the thunk if needed. */
9348 final_start_function (emit_barrier (), file
, 1);
9350 /* Operand 0 is the target function. */
9351 op
[0] = XEXP (DECL_RTL (function
), 0);
9352 if (flag_pic
&& !SYMBOL_REF_LOCAL_P (op
[0]))
9355 op
[0] = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op
[0]),
9356 TARGET_64BIT
? UNSPEC_PLT
: UNSPEC_GOT
);
9357 op
[0] = gen_rtx_CONST (Pmode
, op
[0]);
9360 /* Operand 1 is the 'this' pointer. */
9361 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function
)), function
))
9362 op
[1] = gen_rtx_REG (Pmode
, 3);
9364 op
[1] = gen_rtx_REG (Pmode
, 2);
9366 /* Operand 2 is the delta. */
9367 op
[2] = GEN_INT (delta
);
9369 /* Operand 3 is the vcall_offset. */
9370 op
[3] = GEN_INT (vcall_offset
);
9372 /* Operand 4 is the temporary register. */
9373 op
[4] = gen_rtx_REG (Pmode
, 1);
9375 /* Operands 5 to 8 can be used as labels. */
9381 /* Operand 9 can be used for temporary register. */
9384 /* Generate code. */
9387 /* Setup literal pool pointer if required. */
9388 if ((!DISP_IN_RANGE (delta
)
9389 && !CONST_OK_FOR_K (delta
)
9390 && !CONST_OK_FOR_Os (delta
))
9391 || (!DISP_IN_RANGE (vcall_offset
)
9392 && !CONST_OK_FOR_K (vcall_offset
)
9393 && !CONST_OK_FOR_Os (vcall_offset
)))
9395 op
[5] = gen_label_rtx ();
9396 output_asm_insn ("larl\t%4,%5", op
);
9399 /* Add DELTA to this pointer. */
9402 if (CONST_OK_FOR_J (delta
))
9403 output_asm_insn ("la\t%1,%2(%1)", op
);
9404 else if (DISP_IN_RANGE (delta
))
9405 output_asm_insn ("lay\t%1,%2(%1)", op
);
9406 else if (CONST_OK_FOR_K (delta
))
9407 output_asm_insn ("aghi\t%1,%2", op
);
9408 else if (CONST_OK_FOR_Os (delta
))
9409 output_asm_insn ("agfi\t%1,%2", op
);
9412 op
[6] = gen_label_rtx ();
9413 output_asm_insn ("agf\t%1,%6-%5(%4)", op
);
9417 /* Perform vcall adjustment. */
9420 if (DISP_IN_RANGE (vcall_offset
))
9422 output_asm_insn ("lg\t%4,0(%1)", op
);
9423 output_asm_insn ("ag\t%1,%3(%4)", op
);
9425 else if (CONST_OK_FOR_K (vcall_offset
))
9427 output_asm_insn ("lghi\t%4,%3", op
);
9428 output_asm_insn ("ag\t%4,0(%1)", op
);
9429 output_asm_insn ("ag\t%1,0(%4)", op
);
9431 else if (CONST_OK_FOR_Os (vcall_offset
))
9433 output_asm_insn ("lgfi\t%4,%3", op
);
9434 output_asm_insn ("ag\t%4,0(%1)", op
);
9435 output_asm_insn ("ag\t%1,0(%4)", op
);
9439 op
[7] = gen_label_rtx ();
9440 output_asm_insn ("llgf\t%4,%7-%5(%4)", op
);
9441 output_asm_insn ("ag\t%4,0(%1)", op
);
9442 output_asm_insn ("ag\t%1,0(%4)", op
);
9446 /* Jump to target. */
9447 output_asm_insn ("jg\t%0", op
);
9449 /* Output literal pool if required. */
9452 output_asm_insn (".align\t4", op
);
9453 targetm
.asm_out
.internal_label (file
, "L",
9454 CODE_LABEL_NUMBER (op
[5]));
9458 targetm
.asm_out
.internal_label (file
, "L",
9459 CODE_LABEL_NUMBER (op
[6]));
9460 output_asm_insn (".long\t%2", op
);
9464 targetm
.asm_out
.internal_label (file
, "L",
9465 CODE_LABEL_NUMBER (op
[7]));
9466 output_asm_insn (".long\t%3", op
);
9471 /* Setup base pointer if required. */
9473 || (!DISP_IN_RANGE (delta
)
9474 && !CONST_OK_FOR_K (delta
)
9475 && !CONST_OK_FOR_Os (delta
))
9476 || (!DISP_IN_RANGE (delta
)
9477 && !CONST_OK_FOR_K (vcall_offset
)
9478 && !CONST_OK_FOR_Os (vcall_offset
)))
9480 op
[5] = gen_label_rtx ();
9481 output_asm_insn ("basr\t%4,0", op
);
9482 targetm
.asm_out
.internal_label (file
, "L",
9483 CODE_LABEL_NUMBER (op
[5]));
9486 /* Add DELTA to this pointer. */
9489 if (CONST_OK_FOR_J (delta
))
9490 output_asm_insn ("la\t%1,%2(%1)", op
);
9491 else if (DISP_IN_RANGE (delta
))
9492 output_asm_insn ("lay\t%1,%2(%1)", op
);
9493 else if (CONST_OK_FOR_K (delta
))
9494 output_asm_insn ("ahi\t%1,%2", op
);
9495 else if (CONST_OK_FOR_Os (delta
))
9496 output_asm_insn ("afi\t%1,%2", op
);
9499 op
[6] = gen_label_rtx ();
9500 output_asm_insn ("a\t%1,%6-%5(%4)", op
);
9504 /* Perform vcall adjustment. */
9507 if (CONST_OK_FOR_J (vcall_offset
))
9509 output_asm_insn ("l\t%4,0(%1)", op
);
9510 output_asm_insn ("a\t%1,%3(%4)", op
);
9512 else if (DISP_IN_RANGE (vcall_offset
))
9514 output_asm_insn ("l\t%4,0(%1)", op
);
9515 output_asm_insn ("ay\t%1,%3(%4)", op
);
9517 else if (CONST_OK_FOR_K (vcall_offset
))
9519 output_asm_insn ("lhi\t%4,%3", op
);
9520 output_asm_insn ("a\t%4,0(%1)", op
);
9521 output_asm_insn ("a\t%1,0(%4)", op
);
9523 else if (CONST_OK_FOR_Os (vcall_offset
))
9525 output_asm_insn ("iilf\t%4,%3", op
);
9526 output_asm_insn ("a\t%4,0(%1)", op
);
9527 output_asm_insn ("a\t%1,0(%4)", op
);
9531 op
[7] = gen_label_rtx ();
9532 output_asm_insn ("l\t%4,%7-%5(%4)", op
);
9533 output_asm_insn ("a\t%4,0(%1)", op
);
9534 output_asm_insn ("a\t%1,0(%4)", op
);
9537 /* We had to clobber the base pointer register.
9538 Re-setup the base pointer (with a different base). */
9539 op
[5] = gen_label_rtx ();
9540 output_asm_insn ("basr\t%4,0", op
);
9541 targetm
.asm_out
.internal_label (file
, "L",
9542 CODE_LABEL_NUMBER (op
[5]));
9545 /* Jump to target. */
9546 op
[8] = gen_label_rtx ();
9549 output_asm_insn ("l\t%4,%8-%5(%4)", op
);
9551 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
9552 /* We cannot call through .plt, since .plt requires %r12 loaded. */
9553 else if (flag_pic
== 1)
9555 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
9556 output_asm_insn ("l\t%4,%0(%4)", op
);
9558 else if (flag_pic
== 2)
9560 op
[9] = gen_rtx_REG (Pmode
, 0);
9561 output_asm_insn ("l\t%9,%8-4-%5(%4)", op
);
9562 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
9563 output_asm_insn ("ar\t%4,%9", op
);
9564 output_asm_insn ("l\t%4,0(%4)", op
);
9567 output_asm_insn ("br\t%4", op
);
9569 /* Output literal pool. */
9570 output_asm_insn (".align\t4", op
);
9572 if (nonlocal
&& flag_pic
== 2)
9573 output_asm_insn (".long\t%0", op
);
9576 op
[0] = gen_rtx_SYMBOL_REF (Pmode
, "_GLOBAL_OFFSET_TABLE_");
9577 SYMBOL_REF_FLAGS (op
[0]) = SYMBOL_FLAG_LOCAL
;
9580 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[8]));
9582 output_asm_insn (".long\t%0", op
);
9584 output_asm_insn (".long\t%0-%5", op
);
9588 targetm
.asm_out
.internal_label (file
, "L",
9589 CODE_LABEL_NUMBER (op
[6]));
9590 output_asm_insn (".long\t%2", op
);
9594 targetm
.asm_out
.internal_label (file
, "L",
9595 CODE_LABEL_NUMBER (op
[7]));
9596 output_asm_insn (".long\t%3", op
);
9599 final_end_function ();
9603 s390_valid_pointer_mode (enum machine_mode mode
)
9605 return (mode
== SImode
|| (TARGET_64BIT
&& mode
== DImode
));
9608 /* Checks whether the given CALL_EXPR would use a caller
9609 saved register. This is used to decide whether sibling call
9610 optimization could be performed on the respective function
9614 s390_call_saved_register_used (tree call_expr
)
9616 CUMULATIVE_ARGS cum
;
9618 enum machine_mode mode
;
9623 INIT_CUMULATIVE_ARGS (cum
, NULL
, NULL
, 0, 0);
9625 for (i
= 0; i
< call_expr_nargs (call_expr
); i
++)
9627 parameter
= CALL_EXPR_ARG (call_expr
, i
);
9628 gcc_assert (parameter
);
9630 /* For an undeclared variable passed as parameter we will get
9631 an ERROR_MARK node here. */
9632 if (TREE_CODE (parameter
) == ERROR_MARK
)
9635 type
= TREE_TYPE (parameter
);
9638 mode
= TYPE_MODE (type
);
9641 if (pass_by_reference (&cum
, mode
, type
, true))
9644 type
= build_pointer_type (type
);
9647 parm_rtx
= s390_function_arg (&cum
, mode
, type
, 0);
9649 s390_function_arg_advance (&cum
, mode
, type
, 0);
9654 if (REG_P (parm_rtx
))
9657 reg
< HARD_REGNO_NREGS (REGNO (parm_rtx
), GET_MODE (parm_rtx
));
9659 if (!call_used_regs
[reg
+ REGNO (parm_rtx
)])
9663 if (GET_CODE (parm_rtx
) == PARALLEL
)
9667 for (i
= 0; i
< XVECLEN (parm_rtx
, 0); i
++)
9669 rtx r
= XEXP (XVECEXP (parm_rtx
, 0, i
), 0);
9671 gcc_assert (REG_P (r
));
9674 reg
< HARD_REGNO_NREGS (REGNO (r
), GET_MODE (r
));
9676 if (!call_used_regs
[reg
+ REGNO (r
)])
9685 /* Return true if the given call expression can be
9686 turned into a sibling call.
9687 DECL holds the declaration of the function to be called whereas
9688 EXP is the call expression itself. */
9691 s390_function_ok_for_sibcall (tree decl
, tree exp
)
9693 /* The TPF epilogue uses register 1. */
9694 if (TARGET_TPF_PROFILING
)
9697 /* The 31 bit PLT code uses register 12 (GOT pointer - caller saved)
9698 which would have to be restored before the sibcall. */
9699 if (!TARGET_64BIT
&& flag_pic
&& decl
&& !targetm
.binds_local_p (decl
))
9702 /* Register 6 on s390 is available as an argument register but unfortunately
9703 "caller saved". This makes functions needing this register for arguments
9704 not suitable for sibcalls. */
9705 return !s390_call_saved_register_used (exp
);
9708 /* Return the fixed registers used for condition codes. */
9711 s390_fixed_condition_code_regs (unsigned int *p1
, unsigned int *p2
)
9714 *p2
= INVALID_REGNUM
;
9719 /* This function is used by the call expanders of the machine description.
9720 It emits the call insn itself together with the necessary operations
9721 to adjust the target address and returns the emitted insn.
9722 ADDR_LOCATION is the target address rtx
9723 TLS_CALL the location of the thread-local symbol
9724 RESULT_REG the register where the result of the call should be stored
9725 RETADDR_REG the register where the return address should be stored
9726 If this parameter is NULL_RTX the call is considered
9727 to be a sibling call. */
9730 s390_emit_call (rtx addr_location
, rtx tls_call
, rtx result_reg
,
9733 bool plt_call
= false;
9739 /* Direct function calls need special treatment. */
9740 if (GET_CODE (addr_location
) == SYMBOL_REF
)
9742 /* When calling a global routine in PIC mode, we must
9743 replace the symbol itself with the PLT stub. */
9744 if (flag_pic
&& !SYMBOL_REF_LOCAL_P (addr_location
))
9746 if (retaddr_reg
!= NULL_RTX
)
9748 addr_location
= gen_rtx_UNSPEC (Pmode
,
9749 gen_rtvec (1, addr_location
),
9751 addr_location
= gen_rtx_CONST (Pmode
, addr_location
);
9755 /* For -fpic code the PLT entries might use r12 which is
9756 call-saved. Therefore we cannot do a sibcall when
9757 calling directly using a symbol ref. When reaching
9758 this point we decided (in s390_function_ok_for_sibcall)
9759 to do a sibcall for a function pointer but one of the
9760 optimizers was able to get rid of the function pointer
9761 by propagating the symbol ref into the call. This
9762 optimization is illegal for S/390 so we turn the direct
9763 call into a indirect call again. */
9764 addr_location
= force_reg (Pmode
, addr_location
);
9767 /* Unless we can use the bras(l) insn, force the
9768 routine address into a register. */
9769 if (!TARGET_SMALL_EXEC
&& !TARGET_CPU_ZARCH
)
9772 addr_location
= legitimize_pic_address (addr_location
, 0);
9774 addr_location
= force_reg (Pmode
, addr_location
);
9778 /* If it is already an indirect call or the code above moved the
9779 SYMBOL_REF to somewhere else make sure the address can be found in
9781 if (retaddr_reg
== NULL_RTX
9782 && GET_CODE (addr_location
) != SYMBOL_REF
9785 emit_move_insn (gen_rtx_REG (Pmode
, SIBCALL_REGNUM
), addr_location
);
9786 addr_location
= gen_rtx_REG (Pmode
, SIBCALL_REGNUM
);
9789 addr_location
= gen_rtx_MEM (QImode
, addr_location
);
9790 call
= gen_rtx_CALL (VOIDmode
, addr_location
, const0_rtx
);
9792 if (result_reg
!= NULL_RTX
)
9793 call
= gen_rtx_SET (VOIDmode
, result_reg
, call
);
9795 if (retaddr_reg
!= NULL_RTX
)
9797 clobber
= gen_rtx_CLOBBER (VOIDmode
, retaddr_reg
);
9799 if (tls_call
!= NULL_RTX
)
9800 vec
= gen_rtvec (3, call
, clobber
,
9801 gen_rtx_USE (VOIDmode
, tls_call
));
9803 vec
= gen_rtvec (2, call
, clobber
);
9805 call
= gen_rtx_PARALLEL (VOIDmode
, vec
);
9808 insn
= emit_call_insn (call
);
9810 /* 31-bit PLT stubs and tls calls use the GOT register implicitly. */
9811 if ((!TARGET_64BIT
&& plt_call
) || tls_call
!= NULL_RTX
)
9813 /* s390_function_ok_for_sibcall should
9814 have denied sibcalls in this case. */
9815 gcc_assert (retaddr_reg
!= NULL_RTX
);
9817 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), pic_offset_table_rtx
);
9822 /* Implement TARGET_CONDITIONAL_REGISTER_USAGE. */
9825 s390_conditional_register_usage (void)
9831 fixed_regs
[PIC_OFFSET_TABLE_REGNUM
] = 1;
9832 call_used_regs
[PIC_OFFSET_TABLE_REGNUM
] = 1;
9834 if (TARGET_CPU_ZARCH
)
9836 fixed_regs
[BASE_REGNUM
] = 0;
9837 call_used_regs
[BASE_REGNUM
] = 0;
9838 fixed_regs
[RETURN_REGNUM
] = 0;
9839 call_used_regs
[RETURN_REGNUM
] = 0;
9843 for (i
= 24; i
< 32; i
++)
9844 call_used_regs
[i
] = call_really_used_regs
[i
] = 0;
9848 for (i
= 18; i
< 20; i
++)
9849 call_used_regs
[i
] = call_really_used_regs
[i
] = 0;
9852 if (TARGET_SOFT_FLOAT
)
9854 for (i
= 16; i
< 32; i
++)
9855 call_used_regs
[i
] = fixed_regs
[i
] = 1;
9859 /* Corresponding function to eh_return expander. */
9861 static GTY(()) rtx s390_tpf_eh_return_symbol
;
9863 s390_emit_tpf_eh_return (rtx target
)
9867 if (!s390_tpf_eh_return_symbol
)
9868 s390_tpf_eh_return_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "__tpf_eh_return");
9870 reg
= gen_rtx_REG (Pmode
, 2);
9872 emit_move_insn (reg
, target
);
9873 insn
= s390_emit_call (s390_tpf_eh_return_symbol
, NULL_RTX
, reg
,
9874 gen_rtx_REG (Pmode
, RETURN_REGNUM
));
9875 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), reg
);
9877 emit_move_insn (EH_RETURN_HANDLER_RTX
, reg
);
9880 /* Rework the prologue/epilogue to avoid saving/restoring
9881 registers unnecessarily. */
9884 s390_optimize_prologue (void)
9886 rtx insn
, new_insn
, next_insn
;
9888 /* Do a final recompute of the frame-related data. */
9890 s390_update_frame_layout ();
9892 /* If all special registers are in fact used, there's nothing we
9893 can do, so no point in walking the insn list. */
9895 if (cfun_frame_layout
.first_save_gpr
<= BASE_REGNUM
9896 && cfun_frame_layout
.last_save_gpr
>= BASE_REGNUM
9897 && (TARGET_CPU_ZARCH
9898 || (cfun_frame_layout
.first_save_gpr
<= RETURN_REGNUM
9899 && cfun_frame_layout
.last_save_gpr
>= RETURN_REGNUM
)))
9902 /* Search for prologue/epilogue insns and replace them. */
9904 for (insn
= get_insns (); insn
; insn
= next_insn
)
9906 int first
, last
, off
;
9907 rtx set
, base
, offset
;
9909 next_insn
= NEXT_INSN (insn
);
9911 if (GET_CODE (insn
) != INSN
)
9914 if (GET_CODE (PATTERN (insn
)) == PARALLEL
9915 && store_multiple_operation (PATTERN (insn
), VOIDmode
))
9917 set
= XVECEXP (PATTERN (insn
), 0, 0);
9918 first
= REGNO (SET_SRC (set
));
9919 last
= first
+ XVECLEN (PATTERN (insn
), 0) - 1;
9920 offset
= const0_rtx
;
9921 base
= eliminate_constant_term (XEXP (SET_DEST (set
), 0), &offset
);
9922 off
= INTVAL (offset
);
9924 if (GET_CODE (base
) != REG
|| off
< 0)
9926 if (cfun_frame_layout
.first_save_gpr
!= -1
9927 && (cfun_frame_layout
.first_save_gpr
< first
9928 || cfun_frame_layout
.last_save_gpr
> last
))
9930 if (REGNO (base
) != STACK_POINTER_REGNUM
9931 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
9933 if (first
> BASE_REGNUM
|| last
< BASE_REGNUM
)
9936 if (cfun_frame_layout
.first_save_gpr
!= -1)
9938 new_insn
= save_gprs (base
,
9939 off
+ (cfun_frame_layout
.first_save_gpr
9940 - first
) * UNITS_PER_LONG
,
9941 cfun_frame_layout
.first_save_gpr
,
9942 cfun_frame_layout
.last_save_gpr
);
9943 new_insn
= emit_insn_before (new_insn
, insn
);
9944 INSN_ADDRESSES_NEW (new_insn
, -1);
9951 if (cfun_frame_layout
.first_save_gpr
== -1
9952 && GET_CODE (PATTERN (insn
)) == SET
9953 && GET_CODE (SET_SRC (PATTERN (insn
))) == REG
9954 && (REGNO (SET_SRC (PATTERN (insn
))) == BASE_REGNUM
9955 || (!TARGET_CPU_ZARCH
9956 && REGNO (SET_SRC (PATTERN (insn
))) == RETURN_REGNUM
))
9957 && GET_CODE (SET_DEST (PATTERN (insn
))) == MEM
)
9959 set
= PATTERN (insn
);
9960 first
= REGNO (SET_SRC (set
));
9961 offset
= const0_rtx
;
9962 base
= eliminate_constant_term (XEXP (SET_DEST (set
), 0), &offset
);
9963 off
= INTVAL (offset
);
9965 if (GET_CODE (base
) != REG
|| off
< 0)
9967 if (REGNO (base
) != STACK_POINTER_REGNUM
9968 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
9975 if (GET_CODE (PATTERN (insn
)) == PARALLEL
9976 && load_multiple_operation (PATTERN (insn
), VOIDmode
))
9978 set
= XVECEXP (PATTERN (insn
), 0, 0);
9979 first
= REGNO (SET_DEST (set
));
9980 last
= first
+ XVECLEN (PATTERN (insn
), 0) - 1;
9981 offset
= const0_rtx
;
9982 base
= eliminate_constant_term (XEXP (SET_SRC (set
), 0), &offset
);
9983 off
= INTVAL (offset
);
9985 if (GET_CODE (base
) != REG
|| off
< 0)
9987 if (cfun_frame_layout
.first_restore_gpr
!= -1
9988 && (cfun_frame_layout
.first_restore_gpr
< first
9989 || cfun_frame_layout
.last_restore_gpr
> last
))
9991 if (REGNO (base
) != STACK_POINTER_REGNUM
9992 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
9994 if (first
> BASE_REGNUM
|| last
< BASE_REGNUM
)
9997 if (cfun_frame_layout
.first_restore_gpr
!= -1)
9999 new_insn
= restore_gprs (base
,
10000 off
+ (cfun_frame_layout
.first_restore_gpr
10001 - first
) * UNITS_PER_LONG
,
10002 cfun_frame_layout
.first_restore_gpr
,
10003 cfun_frame_layout
.last_restore_gpr
);
10004 new_insn
= emit_insn_before (new_insn
, insn
);
10005 INSN_ADDRESSES_NEW (new_insn
, -1);
10008 remove_insn (insn
);
10012 if (cfun_frame_layout
.first_restore_gpr
== -1
10013 && GET_CODE (PATTERN (insn
)) == SET
10014 && GET_CODE (SET_DEST (PATTERN (insn
))) == REG
10015 && (REGNO (SET_DEST (PATTERN (insn
))) == BASE_REGNUM
10016 || (!TARGET_CPU_ZARCH
10017 && REGNO (SET_DEST (PATTERN (insn
))) == RETURN_REGNUM
))
10018 && GET_CODE (SET_SRC (PATTERN (insn
))) == MEM
)
10020 set
= PATTERN (insn
);
10021 first
= REGNO (SET_DEST (set
));
10022 offset
= const0_rtx
;
10023 base
= eliminate_constant_term (XEXP (SET_SRC (set
), 0), &offset
);
10024 off
= INTVAL (offset
);
10026 if (GET_CODE (base
) != REG
|| off
< 0)
10028 if (REGNO (base
) != STACK_POINTER_REGNUM
10029 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
10032 remove_insn (insn
);
10038 /* On z10 and later the dynamic branch prediction must see the
10039 backward jump within a certain windows. If not it falls back to
10040 the static prediction. This function rearranges the loop backward
10041 branch in a way which makes the static prediction always correct.
10042 The function returns true if it added an instruction. */
10044 s390_fix_long_loop_prediction (rtx insn
)
10046 rtx set
= single_set (insn
);
10047 rtx code_label
, label_ref
, new_label
;
10053 /* This will exclude branch on count and branch on index patterns
10054 since these are correctly statically predicted. */
10056 || SET_DEST (set
) != pc_rtx
10057 || GET_CODE (SET_SRC(set
)) != IF_THEN_ELSE
)
10060 label_ref
= (GET_CODE (XEXP (SET_SRC (set
), 1)) == LABEL_REF
?
10061 XEXP (SET_SRC (set
), 1) : XEXP (SET_SRC (set
), 2));
10063 gcc_assert (GET_CODE (label_ref
) == LABEL_REF
);
10065 code_label
= XEXP (label_ref
, 0);
10067 if (INSN_ADDRESSES (INSN_UID (code_label
)) == -1
10068 || INSN_ADDRESSES (INSN_UID (insn
)) == -1
10069 || (INSN_ADDRESSES (INSN_UID (insn
))
10070 - INSN_ADDRESSES (INSN_UID (code_label
)) < PREDICT_DISTANCE
))
10073 for (distance
= 0, cur_insn
= PREV_INSN (insn
);
10074 distance
< PREDICT_DISTANCE
- 6;
10075 distance
+= get_attr_length (cur_insn
), cur_insn
= PREV_INSN (cur_insn
))
10076 if (!cur_insn
|| JUMP_P (cur_insn
) || LABEL_P (cur_insn
))
10079 new_label
= gen_label_rtx ();
10080 uncond_jump
= emit_jump_insn_after (
10081 gen_rtx_SET (VOIDmode
, pc_rtx
,
10082 gen_rtx_LABEL_REF (VOIDmode
, code_label
)),
10084 emit_label_after (new_label
, uncond_jump
);
10086 tmp
= XEXP (SET_SRC (set
), 1);
10087 XEXP (SET_SRC (set
), 1) = XEXP (SET_SRC (set
), 2);
10088 XEXP (SET_SRC (set
), 2) = tmp
;
10089 INSN_CODE (insn
) = -1;
10091 XEXP (label_ref
, 0) = new_label
;
10092 JUMP_LABEL (insn
) = new_label
;
10093 JUMP_LABEL (uncond_jump
) = code_label
;
10098 /* Returns 1 if INSN reads the value of REG for purposes not related
10099 to addressing of memory, and 0 otherwise. */
10101 s390_non_addr_reg_read_p (rtx reg
, rtx insn
)
10103 return reg_referenced_p (reg
, PATTERN (insn
))
10104 && !reg_used_in_mem_p (REGNO (reg
), PATTERN (insn
));
10107 /* Starting from INSN find_cond_jump looks downwards in the insn
10108 stream for a single jump insn which is the last user of the
10109 condition code set in INSN. */
10111 find_cond_jump (rtx insn
)
10113 for (; insn
; insn
= NEXT_INSN (insn
))
10117 if (LABEL_P (insn
))
10120 if (!JUMP_P (insn
))
10122 if (reg_mentioned_p (gen_rtx_REG (CCmode
, CC_REGNUM
), insn
))
10127 /* This will be triggered by a return. */
10128 if (GET_CODE (PATTERN (insn
)) != SET
)
10131 gcc_assert (SET_DEST (PATTERN (insn
)) == pc_rtx
);
10132 ite
= SET_SRC (PATTERN (insn
));
10134 if (GET_CODE (ite
) != IF_THEN_ELSE
)
10137 cc
= XEXP (XEXP (ite
, 0), 0);
10138 if (!REG_P (cc
) || !CC_REGNO_P (REGNO (cc
)))
10141 if (find_reg_note (insn
, REG_DEAD
, cc
))
10149 /* Swap the condition in COND and the operands in OP0 and OP1 so that
10150 the semantics does not change. If NULL_RTX is passed as COND the
10151 function tries to find the conditional jump starting with INSN. */
10153 s390_swap_cmp (rtx cond
, rtx
*op0
, rtx
*op1
, rtx insn
)
10157 if (cond
== NULL_RTX
)
10159 rtx jump
= find_cond_jump (NEXT_INSN (insn
));
10160 jump
= jump
? single_set (jump
) : NULL_RTX
;
10162 if (jump
== NULL_RTX
)
10165 cond
= XEXP (XEXP (jump
, 1), 0);
10170 PUT_CODE (cond
, swap_condition (GET_CODE (cond
)));
10173 /* On z10, instructions of the compare-and-branch family have the
10174 property to access the register occurring as second operand with
10175 its bits complemented. If such a compare is grouped with a second
10176 instruction that accesses the same register non-complemented, and
10177 if that register's value is delivered via a bypass, then the
10178 pipeline recycles, thereby causing significant performance decline.
10179 This function locates such situations and exchanges the two
10180 operands of the compare. The function return true whenever it
10183 s390_z10_optimize_cmp (rtx insn
)
10185 rtx prev_insn
, next_insn
;
10186 bool insn_added_p
= false;
10187 rtx cond
, *op0
, *op1
;
10189 if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
10191 /* Handle compare and branch and branch on count
10193 rtx pattern
= single_set (insn
);
10196 || SET_DEST (pattern
) != pc_rtx
10197 || GET_CODE (SET_SRC (pattern
)) != IF_THEN_ELSE
)
10200 cond
= XEXP (SET_SRC (pattern
), 0);
10201 op0
= &XEXP (cond
, 0);
10202 op1
= &XEXP (cond
, 1);
10204 else if (GET_CODE (PATTERN (insn
)) == SET
)
10208 /* Handle normal compare instructions. */
10209 src
= SET_SRC (PATTERN (insn
));
10210 dest
= SET_DEST (PATTERN (insn
));
10213 || !CC_REGNO_P (REGNO (dest
))
10214 || GET_CODE (src
) != COMPARE
)
10217 /* s390_swap_cmp will try to find the conditional
10218 jump when passing NULL_RTX as condition. */
10220 op0
= &XEXP (src
, 0);
10221 op1
= &XEXP (src
, 1);
10226 if (!REG_P (*op0
) || !REG_P (*op1
))
10229 if (GET_MODE_CLASS (GET_MODE (*op0
)) != MODE_INT
)
10232 /* Swap the COMPARE arguments and its mask if there is a
10233 conflicting access in the previous insn. */
10234 prev_insn
= prev_active_insn (insn
);
10235 if (prev_insn
!= NULL_RTX
&& INSN_P (prev_insn
)
10236 && reg_referenced_p (*op1
, PATTERN (prev_insn
)))
10237 s390_swap_cmp (cond
, op0
, op1
, insn
);
10239 /* Check if there is a conflict with the next insn. If there
10240 was no conflict with the previous insn, then swap the
10241 COMPARE arguments and its mask. If we already swapped
10242 the operands, or if swapping them would cause a conflict
10243 with the previous insn, issue a NOP after the COMPARE in
10244 order to separate the two instuctions. */
10245 next_insn
= next_active_insn (insn
);
10246 if (next_insn
!= NULL_RTX
&& INSN_P (next_insn
)
10247 && s390_non_addr_reg_read_p (*op1
, next_insn
))
10249 if (prev_insn
!= NULL_RTX
&& INSN_P (prev_insn
)
10250 && s390_non_addr_reg_read_p (*op0
, prev_insn
))
10252 if (REGNO (*op1
) == 0)
10253 emit_insn_after (gen_nop1 (), insn
);
10255 emit_insn_after (gen_nop (), insn
);
10256 insn_added_p
= true;
10259 s390_swap_cmp (cond
, op0
, op1
, insn
);
10261 return insn_added_p
;
10264 /* Perform machine-dependent processing. */
10269 bool pool_overflow
= false;
10271 /* Make sure all splits have been performed; splits after
10272 machine_dependent_reorg might confuse insn length counts. */
10273 split_all_insns_noflow ();
10275 /* Install the main literal pool and the associated base
10276 register load insns.
10278 In addition, there are two problematic situations we need
10281 - the literal pool might be > 4096 bytes in size, so that
10282 some of its elements cannot be directly accessed
10284 - a branch target might be > 64K away from the branch, so that
10285 it is not possible to use a PC-relative instruction.
10287 To fix those, we split the single literal pool into multiple
10288 pool chunks, reloading the pool base register at various
10289 points throughout the function to ensure it always points to
10290 the pool chunk the following code expects, and / or replace
10291 PC-relative branches by absolute branches.
10293 However, the two problems are interdependent: splitting the
10294 literal pool can move a branch further away from its target,
10295 causing the 64K limit to overflow, and on the other hand,
10296 replacing a PC-relative branch by an absolute branch means
10297 we need to put the branch target address into the literal
10298 pool, possibly causing it to overflow.
10300 So, we loop trying to fix up both problems until we manage
10301 to satisfy both conditions at the same time. Note that the
10302 loop is guaranteed to terminate as every pass of the loop
10303 strictly decreases the total number of PC-relative branches
10304 in the function. (This is not completely true as there
10305 might be branch-over-pool insns introduced by chunkify_start.
10306 Those never need to be split however.) */
10310 struct constant_pool
*pool
= NULL
;
10312 /* Collect the literal pool. */
10313 if (!pool_overflow
)
10315 pool
= s390_mainpool_start ();
10317 pool_overflow
= true;
10320 /* If literal pool overflowed, start to chunkify it. */
10322 pool
= s390_chunkify_start ();
10324 /* Split out-of-range branches. If this has created new
10325 literal pool entries, cancel current chunk list and
10326 recompute it. zSeries machines have large branch
10327 instructions, so we never need to split a branch. */
10328 if (!TARGET_CPU_ZARCH
&& s390_split_branches ())
10331 s390_chunkify_cancel (pool
);
10333 s390_mainpool_cancel (pool
);
10338 /* If we made it up to here, both conditions are satisfied.
10339 Finish up literal pool related changes. */
10341 s390_chunkify_finish (pool
);
10343 s390_mainpool_finish (pool
);
10345 /* We're done splitting branches. */
10346 cfun
->machine
->split_branches_pending_p
= false;
10350 /* Generate out-of-pool execute target insns. */
10351 if (TARGET_CPU_ZARCH
)
10353 rtx insn
, label
, target
;
10355 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
10357 label
= s390_execute_label (insn
);
10361 gcc_assert (label
!= const0_rtx
);
10363 target
= emit_label (XEXP (label
, 0));
10364 INSN_ADDRESSES_NEW (target
, -1);
10366 target
= emit_insn (s390_execute_target (insn
));
10367 INSN_ADDRESSES_NEW (target
, -1);
10371 /* Try to optimize prologue and epilogue further. */
10372 s390_optimize_prologue ();
10374 /* Walk over the insns and do some >=z10 specific changes. */
10375 if (s390_tune
== PROCESSOR_2097_Z10
10376 || s390_tune
== PROCESSOR_2817_Z196
)
10379 bool insn_added_p
= false;
10381 /* The insn lengths and addresses have to be up to date for the
10382 following manipulations. */
10383 shorten_branches (get_insns ());
10385 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
10387 if (!INSN_P (insn
) || INSN_CODE (insn
) <= 0)
10391 insn_added_p
|= s390_fix_long_loop_prediction (insn
);
10393 if ((GET_CODE (PATTERN (insn
)) == PARALLEL
10394 || GET_CODE (PATTERN (insn
)) == SET
)
10395 && s390_tune
== PROCESSOR_2097_Z10
)
10396 insn_added_p
|= s390_z10_optimize_cmp (insn
);
10399 /* Adjust branches if we added new instructions. */
10401 shorten_branches (get_insns ());
10405 /* Return true if INSN is a fp load insn writing register REGNO. */
10407 s390_fpload_toreg (rtx insn
, unsigned int regno
)
10410 enum attr_type flag
= s390_safe_attr_type (insn
);
10412 if (flag
!= TYPE_FLOADSF
&& flag
!= TYPE_FLOADDF
)
10415 set
= single_set (insn
);
10417 if (set
== NULL_RTX
)
10420 if (!REG_P (SET_DEST (set
)) || !MEM_P (SET_SRC (set
)))
10423 if (REGNO (SET_DEST (set
)) != regno
)
10429 /* This value describes the distance to be avoided between an
10430 aritmetic fp instruction and an fp load writing the same register.
10431 Z10_EARLYLOAD_DISTANCE - 1 as well as Z10_EARLYLOAD_DISTANCE + 1 is
10432 fine but the exact value has to be avoided. Otherwise the FP
10433 pipeline will throw an exception causing a major penalty. */
10434 #define Z10_EARLYLOAD_DISTANCE 7
10436 /* Rearrange the ready list in order to avoid the situation described
10437 for Z10_EARLYLOAD_DISTANCE. A problematic load instruction is
10438 moved to the very end of the ready list. */
10440 s390_z10_prevent_earlyload_conflicts (rtx
*ready
, int *nready_p
)
10442 unsigned int regno
;
10443 int nready
= *nready_p
;
10448 enum attr_type flag
;
10451 /* Skip DISTANCE - 1 active insns. */
10452 for (insn
= last_scheduled_insn
, distance
= Z10_EARLYLOAD_DISTANCE
- 1;
10453 distance
> 0 && insn
!= NULL_RTX
;
10454 distance
--, insn
= prev_active_insn (insn
))
10455 if (CALL_P (insn
) || JUMP_P (insn
))
10458 if (insn
== NULL_RTX
)
10461 set
= single_set (insn
);
10463 if (set
== NULL_RTX
|| !REG_P (SET_DEST (set
))
10464 || GET_MODE_CLASS (GET_MODE (SET_DEST (set
))) != MODE_FLOAT
)
10467 flag
= s390_safe_attr_type (insn
);
10469 if (flag
== TYPE_FLOADSF
|| flag
== TYPE_FLOADDF
)
10472 regno
= REGNO (SET_DEST (set
));
10475 while (!s390_fpload_toreg (ready
[i
], regno
) && i
> 0)
10482 memmove (&ready
[1], &ready
[0], sizeof (rtx
) * i
);
10486 /* This function is called via hook TARGET_SCHED_REORDER before
10487 issueing one insn from list READY which contains *NREADYP entries.
10488 For target z10 it reorders load instructions to avoid early load
10489 conflicts in the floating point pipeline */
10491 s390_sched_reorder (FILE *file ATTRIBUTE_UNUSED
, int verbose ATTRIBUTE_UNUSED
,
10492 rtx
*ready
, int *nreadyp
, int clock ATTRIBUTE_UNUSED
)
10494 if (s390_tune
== PROCESSOR_2097_Z10
)
10495 if (reload_completed
&& *nreadyp
> 1)
10496 s390_z10_prevent_earlyload_conflicts (ready
, nreadyp
);
10498 return s390_issue_rate ();
10501 /* This function is called via hook TARGET_SCHED_VARIABLE_ISSUE after
10502 the scheduler has issued INSN. It stores the last issued insn into
10503 last_scheduled_insn in order to make it available for
10504 s390_sched_reorder. */
10506 s390_sched_variable_issue (FILE *file ATTRIBUTE_UNUSED
,
10507 int verbose ATTRIBUTE_UNUSED
,
10508 rtx insn
, int more
)
10510 last_scheduled_insn
= insn
;
10512 if (GET_CODE (PATTERN (insn
)) != USE
10513 && GET_CODE (PATTERN (insn
)) != CLOBBER
)
10520 s390_sched_init (FILE *file ATTRIBUTE_UNUSED
,
10521 int verbose ATTRIBUTE_UNUSED
,
10522 int max_ready ATTRIBUTE_UNUSED
)
10524 last_scheduled_insn
= NULL_RTX
;
10527 /* This function checks the whole of insn X for memory references. The
10528 function always returns zero because the framework it is called
10529 from would stop recursively analyzing the insn upon a return value
10530 other than zero. The real result of this function is updating
10531 counter variable MEM_COUNT. */
10533 check_dpu (rtx
*x
, unsigned *mem_count
)
10535 if (*x
!= NULL_RTX
&& MEM_P (*x
))
10540 /* This target hook implementation for TARGET_LOOP_UNROLL_ADJUST calculates
10541 a new number struct loop *loop should be unrolled if tuned for cpus with
10542 a built-in stride prefetcher.
10543 The loop is analyzed for memory accesses by calling check_dpu for
10544 each rtx of the loop. Depending on the loop_depth and the amount of
10545 memory accesses a new number <=nunroll is returned to improve the
10546 behaviour of the hardware prefetch unit. */
10548 s390_loop_unroll_adjust (unsigned nunroll
, struct loop
*loop
)
10553 unsigned mem_count
= 0;
10555 if (s390_tune
!= PROCESSOR_2097_Z10
&& s390_tune
!= PROCESSOR_2817_Z196
)
10558 /* Count the number of memory references within the loop body. */
10559 bbs
= get_loop_body (loop
);
10560 for (i
= 0; i
< loop
->num_nodes
; i
++)
10562 for (insn
= BB_HEAD (bbs
[i
]); insn
!= BB_END (bbs
[i
]); insn
= NEXT_INSN (insn
))
10563 if (INSN_P (insn
) && INSN_CODE (insn
) != -1)
10564 for_each_rtx (&insn
, (rtx_function
) check_dpu
, &mem_count
);
10568 /* Prevent division by zero, and we do not need to adjust nunroll in this case. */
10569 if (mem_count
== 0)
10572 switch (loop_depth(loop
))
10575 return MIN (nunroll
, 28 / mem_count
);
10577 return MIN (nunroll
, 22 / mem_count
);
10579 return MIN (nunroll
, 16 / mem_count
);
10583 /* Initialize GCC target structure. */
10585 #undef TARGET_ASM_ALIGNED_HI_OP
10586 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
10587 #undef TARGET_ASM_ALIGNED_DI_OP
10588 #define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
10589 #undef TARGET_ASM_INTEGER
10590 #define TARGET_ASM_INTEGER s390_assemble_integer
10592 #undef TARGET_ASM_OPEN_PAREN
10593 #define TARGET_ASM_OPEN_PAREN ""
10595 #undef TARGET_ASM_CLOSE_PAREN
10596 #define TARGET_ASM_CLOSE_PAREN ""
10598 #undef TARGET_DEFAULT_TARGET_FLAGS
10599 #define TARGET_DEFAULT_TARGET_FLAGS (TARGET_DEFAULT)
10601 #undef TARGET_HANDLE_OPTION
10602 #define TARGET_HANDLE_OPTION s390_handle_option
10604 #undef TARGET_OPTION_OVERRIDE
10605 #define TARGET_OPTION_OVERRIDE s390_option_override
10607 #undef TARGET_OPTION_OPTIMIZATION_TABLE
10608 #define TARGET_OPTION_OPTIMIZATION_TABLE s390_option_optimization_table
10610 #undef TARGET_OPTION_INIT_STRUCT
10611 #define TARGET_OPTION_INIT_STRUCT s390_option_init_struct
10613 #undef TARGET_ENCODE_SECTION_INFO
10614 #define TARGET_ENCODE_SECTION_INFO s390_encode_section_info
10616 #undef TARGET_SCALAR_MODE_SUPPORTED_P
10617 #define TARGET_SCALAR_MODE_SUPPORTED_P s390_scalar_mode_supported_p
10620 #undef TARGET_HAVE_TLS
10621 #define TARGET_HAVE_TLS true
10623 #undef TARGET_CANNOT_FORCE_CONST_MEM
10624 #define TARGET_CANNOT_FORCE_CONST_MEM s390_cannot_force_const_mem
10626 #undef TARGET_DELEGITIMIZE_ADDRESS
10627 #define TARGET_DELEGITIMIZE_ADDRESS s390_delegitimize_address
10629 #undef TARGET_LEGITIMIZE_ADDRESS
10630 #define TARGET_LEGITIMIZE_ADDRESS s390_legitimize_address
10632 #undef TARGET_RETURN_IN_MEMORY
10633 #define TARGET_RETURN_IN_MEMORY s390_return_in_memory
10635 #undef TARGET_INIT_BUILTINS
10636 #define TARGET_INIT_BUILTINS s390_init_builtins
10637 #undef TARGET_EXPAND_BUILTIN
10638 #define TARGET_EXPAND_BUILTIN s390_expand_builtin
10640 #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA
10641 #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA s390_output_addr_const_extra
10643 #undef TARGET_ASM_OUTPUT_MI_THUNK
10644 #define TARGET_ASM_OUTPUT_MI_THUNK s390_output_mi_thunk
10645 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
10646 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_const_tree_hwi_hwi_const_tree_true
10648 #undef TARGET_SCHED_ADJUST_PRIORITY
10649 #define TARGET_SCHED_ADJUST_PRIORITY s390_adjust_priority
10650 #undef TARGET_SCHED_ISSUE_RATE
10651 #define TARGET_SCHED_ISSUE_RATE s390_issue_rate
10652 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
10653 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD s390_first_cycle_multipass_dfa_lookahead
10655 #undef TARGET_SCHED_VARIABLE_ISSUE
10656 #define TARGET_SCHED_VARIABLE_ISSUE s390_sched_variable_issue
10657 #undef TARGET_SCHED_REORDER
10658 #define TARGET_SCHED_REORDER s390_sched_reorder
10659 #undef TARGET_SCHED_INIT
10660 #define TARGET_SCHED_INIT s390_sched_init
10662 #undef TARGET_CANNOT_COPY_INSN_P
10663 #define TARGET_CANNOT_COPY_INSN_P s390_cannot_copy_insn_p
10664 #undef TARGET_RTX_COSTS
10665 #define TARGET_RTX_COSTS s390_rtx_costs
10666 #undef TARGET_ADDRESS_COST
10667 #define TARGET_ADDRESS_COST s390_address_cost
10668 #undef TARGET_REGISTER_MOVE_COST
10669 #define TARGET_REGISTER_MOVE_COST s390_register_move_cost
10670 #undef TARGET_MEMORY_MOVE_COST
10671 #define TARGET_MEMORY_MOVE_COST s390_memory_move_cost
10673 #undef TARGET_MACHINE_DEPENDENT_REORG
10674 #define TARGET_MACHINE_DEPENDENT_REORG s390_reorg
10676 #undef TARGET_VALID_POINTER_MODE
10677 #define TARGET_VALID_POINTER_MODE s390_valid_pointer_mode
10679 #undef TARGET_BUILD_BUILTIN_VA_LIST
10680 #define TARGET_BUILD_BUILTIN_VA_LIST s390_build_builtin_va_list
10681 #undef TARGET_EXPAND_BUILTIN_VA_START
10682 #define TARGET_EXPAND_BUILTIN_VA_START s390_va_start
10683 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
10684 #define TARGET_GIMPLIFY_VA_ARG_EXPR s390_gimplify_va_arg
10686 #undef TARGET_PROMOTE_FUNCTION_MODE
10687 #define TARGET_PROMOTE_FUNCTION_MODE s390_promote_function_mode
10688 #undef TARGET_PASS_BY_REFERENCE
10689 #define TARGET_PASS_BY_REFERENCE s390_pass_by_reference
10691 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
10692 #define TARGET_FUNCTION_OK_FOR_SIBCALL s390_function_ok_for_sibcall
10693 #undef TARGET_FUNCTION_ARG
10694 #define TARGET_FUNCTION_ARG s390_function_arg
10695 #undef TARGET_FUNCTION_ARG_ADVANCE
10696 #define TARGET_FUNCTION_ARG_ADVANCE s390_function_arg_advance
10698 #undef TARGET_FIXED_CONDITION_CODE_REGS
10699 #define TARGET_FIXED_CONDITION_CODE_REGS s390_fixed_condition_code_regs
10701 #undef TARGET_CC_MODES_COMPATIBLE
10702 #define TARGET_CC_MODES_COMPATIBLE s390_cc_modes_compatible
10704 #undef TARGET_INVALID_WITHIN_DOLOOP
10705 #define TARGET_INVALID_WITHIN_DOLOOP hook_constcharptr_const_rtx_null
10708 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
10709 #define TARGET_ASM_OUTPUT_DWARF_DTPREL s390_output_dwarf_dtprel
10712 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
10713 #undef TARGET_MANGLE_TYPE
10714 #define TARGET_MANGLE_TYPE s390_mangle_type
10717 #undef TARGET_SCALAR_MODE_SUPPORTED_P
10718 #define TARGET_SCALAR_MODE_SUPPORTED_P s390_scalar_mode_supported_p
10720 #undef TARGET_PREFERRED_RELOAD_CLASS
10721 #define TARGET_PREFERRED_RELOAD_CLASS s390_preferred_reload_class
10723 #undef TARGET_SECONDARY_RELOAD
10724 #define TARGET_SECONDARY_RELOAD s390_secondary_reload
10726 #undef TARGET_LIBGCC_CMP_RETURN_MODE
10727 #define TARGET_LIBGCC_CMP_RETURN_MODE s390_libgcc_cmp_return_mode
10729 #undef TARGET_LIBGCC_SHIFT_COUNT_MODE
10730 #define TARGET_LIBGCC_SHIFT_COUNT_MODE s390_libgcc_shift_count_mode
10732 #undef TARGET_LEGITIMATE_ADDRESS_P
10733 #define TARGET_LEGITIMATE_ADDRESS_P s390_legitimate_address_p
10735 #undef TARGET_CAN_ELIMINATE
10736 #define TARGET_CAN_ELIMINATE s390_can_eliminate
10738 #undef TARGET_CONDITIONAL_REGISTER_USAGE
10739 #define TARGET_CONDITIONAL_REGISTER_USAGE s390_conditional_register_usage
10741 #undef TARGET_LOOP_UNROLL_ADJUST
10742 #define TARGET_LOOP_UNROLL_ADJUST s390_loop_unroll_adjust
10744 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
10745 #define TARGET_ASM_TRAMPOLINE_TEMPLATE s390_asm_trampoline_template
10746 #undef TARGET_TRAMPOLINE_INIT
10747 #define TARGET_TRAMPOLINE_INIT s390_trampoline_init
10749 #undef TARGET_UNWIND_WORD_MODE
10750 #define TARGET_UNWIND_WORD_MODE s390_unwind_word_mode
10752 struct gcc_target targetm
= TARGET_INITIALIZER
;
10754 #include "gt-s390.h"