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 /* In case CSE pulled a non literal pool reference out of
2069 the pool we have to reject the address. This is
2070 especially important when loading the GOT pointer on non
2071 zarch CPUs. In this case the literal pool contains an lt
2072 relative offset to the _GLOBAL_OFFSET_TABLE_ label which
2073 will most likely exceed the displacement. */
2074 if (GET_CODE (XVECEXP (disp
, 0, 0)) != SYMBOL_REF
2075 || !CONSTANT_POOL_ADDRESS_P (XVECEXP (disp
, 0, 0)))
2078 orig_disp
= gen_rtx_CONST (Pmode
, disp
);
2081 /* If we have an offset, make sure it does not
2082 exceed the size of the constant pool entry. */
2083 rtx sym
= XVECEXP (disp
, 0, 0);
2084 if (offset
>= GET_MODE_SIZE (get_pool_mode (sym
)))
2087 orig_disp
= plus_constant (orig_disp
, offset
);
2102 out
->disp
= orig_disp
;
2103 out
->pointer
= pointer
;
2104 out
->literal_pool
= literal_pool
;
2110 /* Decompose a RTL expression OP for a shift count into its components,
2111 and return the base register in BASE and the offset in OFFSET.
2113 Return true if OP is a valid shift count, false if not. */
2116 s390_decompose_shift_count (rtx op
, rtx
*base
, HOST_WIDE_INT
*offset
)
2118 HOST_WIDE_INT off
= 0;
2120 /* We can have an integer constant, an address register,
2121 or a sum of the two. */
2122 if (GET_CODE (op
) == CONST_INT
)
2127 if (op
&& GET_CODE (op
) == PLUS
&& GET_CODE (XEXP (op
, 1)) == CONST_INT
)
2129 off
= INTVAL (XEXP (op
, 1));
2132 while (op
&& GET_CODE (op
) == SUBREG
)
2133 op
= SUBREG_REG (op
);
2135 if (op
&& GET_CODE (op
) != REG
)
2147 /* Return true if CODE is a valid address without index. */
2150 s390_legitimate_address_without_index_p (rtx op
)
2152 struct s390_address addr
;
2154 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
2163 /* Return true if ADDR is of kind symbol_ref or symbol_ref + const_int
2164 and return these parts in SYMREF and ADDEND. You can pass NULL in
2165 SYMREF and/or ADDEND if you are not interested in these values.
2166 Literal pool references are *not* considered symbol references. */
2169 s390_symref_operand_p (rtx addr
, rtx
*symref
, HOST_WIDE_INT
*addend
)
2171 HOST_WIDE_INT tmpaddend
= 0;
2173 if (GET_CODE (addr
) == CONST
)
2174 addr
= XEXP (addr
, 0);
2176 if (GET_CODE (addr
) == PLUS
)
2178 if (GET_CODE (XEXP (addr
, 0)) == SYMBOL_REF
2179 && !CONSTANT_POOL_ADDRESS_P (XEXP (addr
, 0))
2180 && CONST_INT_P (XEXP (addr
, 1)))
2182 tmpaddend
= INTVAL (XEXP (addr
, 1));
2183 addr
= XEXP (addr
, 0);
2189 if (GET_CODE (addr
) != SYMBOL_REF
|| CONSTANT_POOL_ADDRESS_P (addr
))
2195 *addend
= tmpaddend
;
2201 /* Return true if the address in OP is valid for constraint letter C
2202 if wrapped in a MEM rtx. Set LIT_POOL_OK to true if it literal
2203 pool MEMs should be accepted. Only the Q, R, S, T constraint
2204 letters are allowed for C. */
2207 s390_check_qrst_address (char c
, rtx op
, bool lit_pool_ok
)
2209 struct s390_address addr
;
2210 bool decomposed
= false;
2212 /* This check makes sure that no symbolic address (except literal
2213 pool references) are accepted by the R or T constraints. */
2214 if (s390_symref_operand_p (op
, NULL
, NULL
))
2217 /* Ensure literal pool references are only accepted if LIT_POOL_OK. */
2220 if (!s390_decompose_address (op
, &addr
))
2222 if (addr
.literal_pool
)
2229 case 'Q': /* no index short displacement */
2230 if (!decomposed
&& !s390_decompose_address (op
, &addr
))
2234 if (!s390_short_displacement (addr
.disp
))
2238 case 'R': /* with index short displacement */
2239 if (TARGET_LONG_DISPLACEMENT
)
2241 if (!decomposed
&& !s390_decompose_address (op
, &addr
))
2243 if (!s390_short_displacement (addr
.disp
))
2246 /* Any invalid address here will be fixed up by reload,
2247 so accept it for the most generic constraint. */
2250 case 'S': /* no index long displacement */
2251 if (!TARGET_LONG_DISPLACEMENT
)
2253 if (!decomposed
&& !s390_decompose_address (op
, &addr
))
2257 if (s390_short_displacement (addr
.disp
))
2261 case 'T': /* with index long displacement */
2262 if (!TARGET_LONG_DISPLACEMENT
)
2264 /* Any invalid address here will be fixed up by reload,
2265 so accept it for the most generic constraint. */
2266 if ((decomposed
|| s390_decompose_address (op
, &addr
))
2267 && s390_short_displacement (addr
.disp
))
2277 /* Evaluates constraint strings described by the regular expression
2278 ([A|B|Z](Q|R|S|T))|U|W|Y and returns 1 if OP is a valid operand for
2279 the constraint given in STR, or 0 else. */
2282 s390_mem_constraint (const char *str
, rtx op
)
2289 /* Check for offsettable variants of memory constraints. */
2290 if (!MEM_P (op
) || MEM_VOLATILE_P (op
))
2292 if ((reload_completed
|| reload_in_progress
)
2293 ? !offsettable_memref_p (op
) : !offsettable_nonstrict_memref_p (op
))
2295 return s390_check_qrst_address (str
[1], XEXP (op
, 0), true);
2297 /* Check for non-literal-pool variants of memory constraints. */
2300 return s390_check_qrst_address (str
[1], XEXP (op
, 0), false);
2305 if (GET_CODE (op
) != MEM
)
2307 return s390_check_qrst_address (c
, XEXP (op
, 0), true);
2309 return (s390_check_qrst_address ('Q', op
, true)
2310 || s390_check_qrst_address ('R', op
, true));
2312 return (s390_check_qrst_address ('S', op
, true)
2313 || s390_check_qrst_address ('T', op
, true));
2315 /* Simply check for the basic form of a shift count. Reload will
2316 take care of making sure we have a proper base register. */
2317 if (!s390_decompose_shift_count (op
, NULL
, NULL
))
2321 return s390_check_qrst_address (str
[1], op
, true);
2329 /* Evaluates constraint strings starting with letter O. Input
2330 parameter C is the second letter following the "O" in the constraint
2331 string. Returns 1 if VALUE meets the respective constraint and 0
2335 s390_O_constraint_str (const char c
, HOST_WIDE_INT value
)
2343 return trunc_int_for_mode (value
, SImode
) == value
;
2347 || s390_single_part (GEN_INT (value
), DImode
, SImode
, 0) == 1;
2350 return s390_single_part (GEN_INT (value
- 1), DImode
, SImode
, -1) == 1;
2358 /* Evaluates constraint strings starting with letter N. Parameter STR
2359 contains the letters following letter "N" in the constraint string.
2360 Returns true if VALUE matches the constraint. */
2363 s390_N_constraint_str (const char *str
, HOST_WIDE_INT value
)
2365 enum machine_mode mode
, part_mode
;
2367 int part
, part_goal
;
2373 part_goal
= str
[0] - '0';
2417 if (GET_MODE_SIZE (mode
) <= GET_MODE_SIZE (part_mode
))
2420 part
= s390_single_part (GEN_INT (value
), mode
, part_mode
, def
);
2423 if (part_goal
!= -1 && part_goal
!= part
)
2430 /* Returns true if the input parameter VALUE is a float zero. */
2433 s390_float_const_zero_p (rtx value
)
2435 return (GET_MODE_CLASS (GET_MODE (value
)) == MODE_FLOAT
2436 && value
== CONST0_RTX (GET_MODE (value
)));
2439 /* Implement TARGET_REGISTER_MOVE_COST. */
2442 s390_register_move_cost (enum machine_mode mode ATTRIBUTE_UNUSED
,
2443 reg_class_t from
, reg_class_t to
)
2445 /* On s390, copy between fprs and gprs is expensive. */
2446 if ((reg_classes_intersect_p (from
, GENERAL_REGS
)
2447 && reg_classes_intersect_p (to
, FP_REGS
))
2448 || (reg_classes_intersect_p (from
, FP_REGS
)
2449 && reg_classes_intersect_p (to
, GENERAL_REGS
)))
2455 /* Implement TARGET_MEMORY_MOVE_COST. */
2458 s390_memory_move_cost (enum machine_mode mode ATTRIBUTE_UNUSED
,
2459 reg_class_t rclass ATTRIBUTE_UNUSED
,
2460 bool in ATTRIBUTE_UNUSED
)
2465 /* Compute a (partial) cost for rtx X. Return true if the complete
2466 cost has been computed, and false if subexpressions should be
2467 scanned. In either case, *TOTAL contains the cost result.
2468 CODE contains GET_CODE (x), OUTER_CODE contains the code
2469 of the superexpression of x. */
2472 s390_rtx_costs (rtx x
, int code
, int outer_code
, int *total
,
2473 bool speed ATTRIBUTE_UNUSED
)
2496 *total
= COSTS_N_INSNS (1);
2501 *total
= COSTS_N_INSNS (1);
2505 switch (GET_MODE (x
))
2509 rtx left
= XEXP (x
, 0);
2510 rtx right
= XEXP (x
, 1);
2511 if (GET_CODE (right
) == CONST_INT
2512 && CONST_OK_FOR_K (INTVAL (right
)))
2513 *total
= s390_cost
->mhi
;
2514 else if (GET_CODE (left
) == SIGN_EXTEND
)
2515 *total
= s390_cost
->mh
;
2517 *total
= s390_cost
->ms
; /* msr, ms, msy */
2522 rtx left
= XEXP (x
, 0);
2523 rtx right
= XEXP (x
, 1);
2526 if (GET_CODE (right
) == CONST_INT
2527 && CONST_OK_FOR_K (INTVAL (right
)))
2528 *total
= s390_cost
->mghi
;
2529 else if (GET_CODE (left
) == SIGN_EXTEND
)
2530 *total
= s390_cost
->msgf
;
2532 *total
= s390_cost
->msg
; /* msgr, msg */
2534 else /* TARGET_31BIT */
2536 if (GET_CODE (left
) == SIGN_EXTEND
2537 && GET_CODE (right
) == SIGN_EXTEND
)
2538 /* mulsidi case: mr, m */
2539 *total
= s390_cost
->m
;
2540 else if (GET_CODE (left
) == ZERO_EXTEND
2541 && GET_CODE (right
) == ZERO_EXTEND
2542 && TARGET_CPU_ZARCH
)
2543 /* umulsidi case: ml, mlr */
2544 *total
= s390_cost
->ml
;
2546 /* Complex calculation is required. */
2547 *total
= COSTS_N_INSNS (40);
2553 *total
= s390_cost
->mult_df
;
2556 *total
= s390_cost
->mxbr
;
2564 switch (GET_MODE (x
))
2567 *total
= s390_cost
->madbr
;
2570 *total
= s390_cost
->maebr
;
2575 /* Negate in the third argument is free: FMSUB. */
2576 if (GET_CODE (XEXP (x
, 2)) == NEG
)
2578 *total
+= (rtx_cost (XEXP (x
, 0), FMA
, speed
)
2579 + rtx_cost (XEXP (x
, 1), FMA
, speed
)
2580 + rtx_cost (XEXP (XEXP (x
, 2), 0), FMA
, speed
));
2587 if (GET_MODE (x
) == TImode
) /* 128 bit division */
2588 *total
= s390_cost
->dlgr
;
2589 else if (GET_MODE (x
) == DImode
)
2591 rtx right
= XEXP (x
, 1);
2592 if (GET_CODE (right
) == ZERO_EXTEND
) /* 64 by 32 bit division */
2593 *total
= s390_cost
->dlr
;
2594 else /* 64 by 64 bit division */
2595 *total
= s390_cost
->dlgr
;
2597 else if (GET_MODE (x
) == SImode
) /* 32 bit division */
2598 *total
= s390_cost
->dlr
;
2603 if (GET_MODE (x
) == DImode
)
2605 rtx right
= XEXP (x
, 1);
2606 if (GET_CODE (right
) == ZERO_EXTEND
) /* 64 by 32 bit division */
2608 *total
= s390_cost
->dsgfr
;
2610 *total
= s390_cost
->dr
;
2611 else /* 64 by 64 bit division */
2612 *total
= s390_cost
->dsgr
;
2614 else if (GET_MODE (x
) == SImode
) /* 32 bit division */
2615 *total
= s390_cost
->dlr
;
2616 else if (GET_MODE (x
) == SFmode
)
2618 *total
= s390_cost
->debr
;
2620 else if (GET_MODE (x
) == DFmode
)
2622 *total
= s390_cost
->ddbr
;
2624 else if (GET_MODE (x
) == TFmode
)
2626 *total
= s390_cost
->dxbr
;
2631 if (GET_MODE (x
) == SFmode
)
2632 *total
= s390_cost
->sqebr
;
2633 else if (GET_MODE (x
) == DFmode
)
2634 *total
= s390_cost
->sqdbr
;
2636 *total
= s390_cost
->sqxbr
;
2641 if (outer_code
== MULT
|| outer_code
== DIV
|| outer_code
== MOD
2642 || outer_code
== PLUS
|| outer_code
== MINUS
2643 || outer_code
== COMPARE
)
2648 *total
= COSTS_N_INSNS (1);
2649 if (GET_CODE (XEXP (x
, 0)) == AND
2650 && GET_CODE (XEXP (x
, 1)) == CONST_INT
2651 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
)
2653 rtx op0
= XEXP (XEXP (x
, 0), 0);
2654 rtx op1
= XEXP (XEXP (x
, 0), 1);
2655 rtx op2
= XEXP (x
, 1);
2657 if (memory_operand (op0
, GET_MODE (op0
))
2658 && s390_tm_ccmode (op1
, op2
, 0) != VOIDmode
)
2660 if (register_operand (op0
, GET_MODE (op0
))
2661 && s390_tm_ccmode (op1
, op2
, 1) != VOIDmode
)
2671 /* Return the cost of an address rtx ADDR. */
2674 s390_address_cost (rtx addr
, bool speed ATTRIBUTE_UNUSED
)
2676 struct s390_address ad
;
2677 if (!s390_decompose_address (addr
, &ad
))
2680 return ad
.indx
? COSTS_N_INSNS (1) + 1 : COSTS_N_INSNS (1);
2683 /* If OP is a SYMBOL_REF of a thread-local symbol, return its TLS mode,
2684 otherwise return 0. */
2687 tls_symbolic_operand (rtx op
)
2689 if (GET_CODE (op
) != SYMBOL_REF
)
2691 return SYMBOL_REF_TLS_MODEL (op
);
2694 /* Split DImode access register reference REG (on 64-bit) into its constituent
2695 low and high parts, and store them into LO and HI. Note that gen_lowpart/
2696 gen_highpart cannot be used as they assume all registers are word-sized,
2697 while our access registers have only half that size. */
2700 s390_split_access_reg (rtx reg
, rtx
*lo
, rtx
*hi
)
2702 gcc_assert (TARGET_64BIT
);
2703 gcc_assert (ACCESS_REG_P (reg
));
2704 gcc_assert (GET_MODE (reg
) == DImode
);
2705 gcc_assert (!(REGNO (reg
) & 1));
2707 *lo
= gen_rtx_REG (SImode
, REGNO (reg
) + 1);
2708 *hi
= gen_rtx_REG (SImode
, REGNO (reg
));
2711 /* Return true if OP contains a symbol reference */
2714 symbolic_reference_mentioned_p (rtx op
)
2719 if (GET_CODE (op
) == SYMBOL_REF
|| GET_CODE (op
) == LABEL_REF
)
2722 fmt
= GET_RTX_FORMAT (GET_CODE (op
));
2723 for (i
= GET_RTX_LENGTH (GET_CODE (op
)) - 1; i
>= 0; i
--)
2729 for (j
= XVECLEN (op
, i
) - 1; j
>= 0; j
--)
2730 if (symbolic_reference_mentioned_p (XVECEXP (op
, i
, j
)))
2734 else if (fmt
[i
] == 'e' && symbolic_reference_mentioned_p (XEXP (op
, i
)))
2741 /* Return true if OP contains a reference to a thread-local symbol. */
2744 tls_symbolic_reference_mentioned_p (rtx op
)
2749 if (GET_CODE (op
) == SYMBOL_REF
)
2750 return tls_symbolic_operand (op
);
2752 fmt
= GET_RTX_FORMAT (GET_CODE (op
));
2753 for (i
= GET_RTX_LENGTH (GET_CODE (op
)) - 1; i
>= 0; i
--)
2759 for (j
= XVECLEN (op
, i
) - 1; j
>= 0; j
--)
2760 if (tls_symbolic_reference_mentioned_p (XVECEXP (op
, i
, j
)))
2764 else if (fmt
[i
] == 'e' && tls_symbolic_reference_mentioned_p (XEXP (op
, i
)))
2772 /* Return true if OP is a legitimate general operand when
2773 generating PIC code. It is given that flag_pic is on
2774 and that OP satisfies CONSTANT_P or is a CONST_DOUBLE. */
2777 legitimate_pic_operand_p (rtx op
)
2779 /* Accept all non-symbolic constants. */
2780 if (!SYMBOLIC_CONST (op
))
2783 /* Reject everything else; must be handled
2784 via emit_symbolic_move. */
2788 /* Returns true if the constant value OP is a legitimate general operand.
2789 It is given that OP satisfies CONSTANT_P or is a CONST_DOUBLE. */
2792 legitimate_constant_p (rtx op
)
2794 /* Accept all non-symbolic constants. */
2795 if (!SYMBOLIC_CONST (op
))
2798 /* Accept immediate LARL operands. */
2799 if (TARGET_CPU_ZARCH
&& larl_operand (op
, VOIDmode
))
2802 /* Thread-local symbols are never legal constants. This is
2803 so that emit_call knows that computing such addresses
2804 might require a function call. */
2805 if (TLS_SYMBOLIC_CONST (op
))
2808 /* In the PIC case, symbolic constants must *not* be
2809 forced into the literal pool. We accept them here,
2810 so that they will be handled by emit_symbolic_move. */
2814 /* All remaining non-PIC symbolic constants are
2815 forced into the literal pool. */
2819 /* Determine if it's legal to put X into the constant pool. This
2820 is not possible if X contains the address of a symbol that is
2821 not constant (TLS) or not known at final link time (PIC). */
2824 s390_cannot_force_const_mem (rtx x
)
2826 switch (GET_CODE (x
))
2830 /* Accept all non-symbolic constants. */
2834 /* Labels are OK iff we are non-PIC. */
2835 return flag_pic
!= 0;
2838 /* 'Naked' TLS symbol references are never OK,
2839 non-TLS symbols are OK iff we are non-PIC. */
2840 if (tls_symbolic_operand (x
))
2843 return flag_pic
!= 0;
2846 return s390_cannot_force_const_mem (XEXP (x
, 0));
2849 return s390_cannot_force_const_mem (XEXP (x
, 0))
2850 || s390_cannot_force_const_mem (XEXP (x
, 1));
2853 switch (XINT (x
, 1))
2855 /* Only lt-relative or GOT-relative UNSPECs are OK. */
2856 case UNSPEC_LTREL_OFFSET
:
2864 case UNSPEC_GOTNTPOFF
:
2865 case UNSPEC_INDNTPOFF
:
2868 /* If the literal pool shares the code section, be put
2869 execute template placeholders into the pool as well. */
2871 return TARGET_CPU_ZARCH
;
2883 /* Returns true if the constant value OP is a legitimate general
2884 operand during and after reload. The difference to
2885 legitimate_constant_p is that this function will not accept
2886 a constant that would need to be forced to the literal pool
2887 before it can be used as operand.
2888 This function accepts all constants which can be loaded directly
2892 legitimate_reload_constant_p (rtx op
)
2894 /* Accept la(y) operands. */
2895 if (GET_CODE (op
) == CONST_INT
2896 && DISP_IN_RANGE (INTVAL (op
)))
2899 /* Accept l(g)hi/l(g)fi operands. */
2900 if (GET_CODE (op
) == CONST_INT
2901 && (CONST_OK_FOR_K (INTVAL (op
)) || CONST_OK_FOR_Os (INTVAL (op
))))
2904 /* Accept lliXX operands. */
2906 && GET_CODE (op
) == CONST_INT
2907 && trunc_int_for_mode (INTVAL (op
), word_mode
) == INTVAL (op
)
2908 && s390_single_part (op
, word_mode
, HImode
, 0) >= 0)
2912 && GET_CODE (op
) == CONST_INT
2913 && trunc_int_for_mode (INTVAL (op
), word_mode
) == INTVAL (op
)
2914 && s390_single_part (op
, word_mode
, SImode
, 0) >= 0)
2917 /* Accept larl operands. */
2918 if (TARGET_CPU_ZARCH
2919 && larl_operand (op
, VOIDmode
))
2922 /* Accept floating-point zero operands that fit into a single GPR. */
2923 if (GET_CODE (op
) == CONST_DOUBLE
2924 && s390_float_const_zero_p (op
)
2925 && GET_MODE_SIZE (GET_MODE (op
)) <= UNITS_PER_WORD
)
2928 /* Accept double-word operands that can be split. */
2929 if (GET_CODE (op
) == CONST_INT
2930 && trunc_int_for_mode (INTVAL (op
), word_mode
) != INTVAL (op
))
2932 enum machine_mode dword_mode
= word_mode
== SImode
? DImode
: TImode
;
2933 rtx hi
= operand_subword (op
, 0, 0, dword_mode
);
2934 rtx lo
= operand_subword (op
, 1, 0, dword_mode
);
2935 return legitimate_reload_constant_p (hi
)
2936 && legitimate_reload_constant_p (lo
);
2939 /* Everything else cannot be handled without reload. */
2943 /* Returns true if the constant value OP is a legitimate fp operand
2944 during and after reload.
2945 This function accepts all constants which can be loaded directly
2949 legitimate_reload_fp_constant_p (rtx op
)
2951 /* Accept floating-point zero operands if the load zero instruction
2954 && GET_CODE (op
) == CONST_DOUBLE
2955 && s390_float_const_zero_p (op
))
2961 /* Given an rtx OP being reloaded into a reg required to be in class RCLASS,
2962 return the class of reg to actually use. */
2965 s390_preferred_reload_class (rtx op
, reg_class_t rclass
)
2967 switch (GET_CODE (op
))
2969 /* Constants we cannot reload into general registers
2970 must be forced into the literal pool. */
2973 if (reg_class_subset_p (GENERAL_REGS
, rclass
)
2974 && legitimate_reload_constant_p (op
))
2975 return GENERAL_REGS
;
2976 else if (reg_class_subset_p (ADDR_REGS
, rclass
)
2977 && legitimate_reload_constant_p (op
))
2979 else if (reg_class_subset_p (FP_REGS
, rclass
)
2980 && legitimate_reload_fp_constant_p (op
))
2984 /* If a symbolic constant or a PLUS is reloaded,
2985 it is most likely being used as an address, so
2986 prefer ADDR_REGS. If 'class' is not a superset
2987 of ADDR_REGS, e.g. FP_REGS, reject this reload. */
2992 if (reg_class_subset_p (ADDR_REGS
, rclass
))
3004 /* Return true if ADDR is SYMBOL_REF + addend with addend being a
3005 multiple of ALIGNMENT and the SYMBOL_REF being naturally
3009 s390_check_symref_alignment (rtx addr
, HOST_WIDE_INT alignment
)
3011 HOST_WIDE_INT addend
;
3014 if (!s390_symref_operand_p (addr
, &symref
, &addend
))
3017 return (!SYMBOL_REF_NOT_NATURALLY_ALIGNED_P (symref
)
3018 && !(addend
& (alignment
- 1)));
3021 /* ADDR is moved into REG using larl. If ADDR isn't a valid larl
3022 operand SCRATCH is used to reload the even part of the address and
3026 s390_reload_larl_operand (rtx reg
, rtx addr
, rtx scratch
)
3028 HOST_WIDE_INT addend
;
3031 if (!s390_symref_operand_p (addr
, &symref
, &addend
))
3035 /* Easy case. The addend is even so larl will do fine. */
3036 emit_move_insn (reg
, addr
);
3039 /* We can leave the scratch register untouched if the target
3040 register is a valid base register. */
3041 if (REGNO (reg
) < FIRST_PSEUDO_REGISTER
3042 && REGNO_REG_CLASS (REGNO (reg
)) == ADDR_REGS
)
3045 gcc_assert (REGNO (scratch
) < FIRST_PSEUDO_REGISTER
);
3046 gcc_assert (REGNO_REG_CLASS (REGNO (scratch
)) == ADDR_REGS
);
3049 emit_move_insn (scratch
,
3050 gen_rtx_CONST (Pmode
,
3051 gen_rtx_PLUS (Pmode
, symref
,
3052 GEN_INT (addend
- 1))));
3054 emit_move_insn (scratch
, symref
);
3056 /* Increment the address using la in order to avoid clobbering cc. */
3057 emit_move_insn (reg
, gen_rtx_PLUS (Pmode
, scratch
, const1_rtx
));
3061 /* Generate what is necessary to move between REG and MEM using
3062 SCRATCH. The direction is given by TOMEM. */
3065 s390_reload_symref_address (rtx reg
, rtx mem
, rtx scratch
, bool tomem
)
3067 /* Reload might have pulled a constant out of the literal pool.
3068 Force it back in. */
3069 if (CONST_INT_P (mem
) || GET_CODE (mem
) == CONST_DOUBLE
3070 || GET_CODE (mem
) == CONST
)
3071 mem
= force_const_mem (GET_MODE (reg
), mem
);
3073 gcc_assert (MEM_P (mem
));
3075 /* For a load from memory we can leave the scratch register
3076 untouched if the target register is a valid base register. */
3078 && REGNO (reg
) < FIRST_PSEUDO_REGISTER
3079 && REGNO_REG_CLASS (REGNO (reg
)) == ADDR_REGS
3080 && GET_MODE (reg
) == GET_MODE (scratch
))
3083 /* Load address into scratch register. Since we can't have a
3084 secondary reload for a secondary reload we have to cover the case
3085 where larl would need a secondary reload here as well. */
3086 s390_reload_larl_operand (scratch
, XEXP (mem
, 0), scratch
);
3088 /* Now we can use a standard load/store to do the move. */
3090 emit_move_insn (replace_equiv_address (mem
, scratch
), reg
);
3092 emit_move_insn (reg
, replace_equiv_address (mem
, scratch
));
3095 /* Inform reload about cases where moving X with a mode MODE to a register in
3096 RCLASS requires an extra scratch or immediate register. Return the class
3097 needed for the immediate register. */
3100 s390_secondary_reload (bool in_p
, rtx x
, reg_class_t rclass_i
,
3101 enum machine_mode mode
, secondary_reload_info
*sri
)
3103 enum reg_class rclass
= (enum reg_class
) rclass_i
;
3105 /* Intermediate register needed. */
3106 if (reg_classes_intersect_p (CC_REGS
, rclass
))
3107 return GENERAL_REGS
;
3111 /* On z10 several optimizer steps may generate larl operands with
3114 && s390_symref_operand_p (x
, NULL
, NULL
)
3116 && !s390_check_symref_alignment (x
, 2))
3117 sri
->icode
= ((mode
== DImode
) ? CODE_FOR_reloaddi_larl_odd_addend_z10
3118 : CODE_FOR_reloadsi_larl_odd_addend_z10
);
3120 /* On z10 we need a scratch register when moving QI, TI or floating
3121 point mode values from or to a memory location with a SYMBOL_REF
3122 or if the symref addend of a SI or DI move is not aligned to the
3123 width of the access. */
3125 && s390_symref_operand_p (XEXP (x
, 0), NULL
, NULL
)
3126 && (mode
== QImode
|| mode
== TImode
|| FLOAT_MODE_P (mode
)
3127 || (!TARGET_ZARCH
&& mode
== DImode
)
3128 || ((mode
== HImode
|| mode
== SImode
|| mode
== DImode
)
3129 && (!s390_check_symref_alignment (XEXP (x
, 0),
3130 GET_MODE_SIZE (mode
))))))
3132 #define __SECONDARY_RELOAD_CASE(M,m) \
3135 sri->icode = in_p ? CODE_FOR_reload##m##di_toreg_z10 : \
3136 CODE_FOR_reload##m##di_tomem_z10; \
3138 sri->icode = in_p ? CODE_FOR_reload##m##si_toreg_z10 : \
3139 CODE_FOR_reload##m##si_tomem_z10; \
3142 switch (GET_MODE (x
))
3144 __SECONDARY_RELOAD_CASE (QI
, qi
);
3145 __SECONDARY_RELOAD_CASE (HI
, hi
);
3146 __SECONDARY_RELOAD_CASE (SI
, si
);
3147 __SECONDARY_RELOAD_CASE (DI
, di
);
3148 __SECONDARY_RELOAD_CASE (TI
, ti
);
3149 __SECONDARY_RELOAD_CASE (SF
, sf
);
3150 __SECONDARY_RELOAD_CASE (DF
, df
);
3151 __SECONDARY_RELOAD_CASE (TF
, tf
);
3152 __SECONDARY_RELOAD_CASE (SD
, sd
);
3153 __SECONDARY_RELOAD_CASE (DD
, dd
);
3154 __SECONDARY_RELOAD_CASE (TD
, td
);
3159 #undef __SECONDARY_RELOAD_CASE
3163 /* We need a scratch register when loading a PLUS expression which
3164 is not a legitimate operand of the LOAD ADDRESS instruction. */
3165 if (in_p
&& s390_plus_operand (x
, mode
))
3166 sri
->icode
= (TARGET_64BIT
?
3167 CODE_FOR_reloaddi_plus
: CODE_FOR_reloadsi_plus
);
3169 /* Performing a multiword move from or to memory we have to make sure the
3170 second chunk in memory is addressable without causing a displacement
3171 overflow. If that would be the case we calculate the address in
3172 a scratch register. */
3174 && GET_CODE (XEXP (x
, 0)) == PLUS
3175 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
3176 && !DISP_IN_RANGE (INTVAL (XEXP (XEXP (x
, 0), 1))
3177 + GET_MODE_SIZE (mode
) - 1))
3179 /* For GENERAL_REGS a displacement overflow is no problem if occurring
3180 in a s_operand address since we may fallback to lm/stm. So we only
3181 have to care about overflows in the b+i+d case. */
3182 if ((reg_classes_intersect_p (GENERAL_REGS
, rclass
)
3183 && s390_class_max_nregs (GENERAL_REGS
, mode
) > 1
3184 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == PLUS
)
3185 /* For FP_REGS no lm/stm is available so this check is triggered
3186 for displacement overflows in b+i+d and b+d like addresses. */
3187 || (reg_classes_intersect_p (FP_REGS
, rclass
)
3188 && s390_class_max_nregs (FP_REGS
, mode
) > 1))
3191 sri
->icode
= (TARGET_64BIT
?
3192 CODE_FOR_reloaddi_nonoffmem_in
:
3193 CODE_FOR_reloadsi_nonoffmem_in
);
3195 sri
->icode
= (TARGET_64BIT
?
3196 CODE_FOR_reloaddi_nonoffmem_out
:
3197 CODE_FOR_reloadsi_nonoffmem_out
);
3201 /* A scratch address register is needed when a symbolic constant is
3202 copied to r0 compiling with -fPIC. In other cases the target
3203 register might be used as temporary (see legitimize_pic_address). */
3204 if (in_p
&& SYMBOLIC_CONST (x
) && flag_pic
== 2 && rclass
!= ADDR_REGS
)
3205 sri
->icode
= (TARGET_64BIT
?
3206 CODE_FOR_reloaddi_PIC_addr
:
3207 CODE_FOR_reloadsi_PIC_addr
);
3209 /* Either scratch or no register needed. */
3213 /* Generate code to load SRC, which is PLUS that is not a
3214 legitimate operand for the LA instruction, into TARGET.
3215 SCRATCH may be used as scratch register. */
3218 s390_expand_plus_operand (rtx target
, rtx src
,
3222 struct s390_address ad
;
3224 /* src must be a PLUS; get its two operands. */
3225 gcc_assert (GET_CODE (src
) == PLUS
);
3226 gcc_assert (GET_MODE (src
) == Pmode
);
3228 /* Check if any of the two operands is already scheduled
3229 for replacement by reload. This can happen e.g. when
3230 float registers occur in an address. */
3231 sum1
= find_replacement (&XEXP (src
, 0));
3232 sum2
= find_replacement (&XEXP (src
, 1));
3233 src
= gen_rtx_PLUS (Pmode
, sum1
, sum2
);
3235 /* If the address is already strictly valid, there's nothing to do. */
3236 if (!s390_decompose_address (src
, &ad
)
3237 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
3238 || (ad
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (ad
.indx
))))
3240 /* Otherwise, one of the operands cannot be an address register;
3241 we reload its value into the scratch register. */
3242 if (true_regnum (sum1
) < 1 || true_regnum (sum1
) > 15)
3244 emit_move_insn (scratch
, sum1
);
3247 if (true_regnum (sum2
) < 1 || true_regnum (sum2
) > 15)
3249 emit_move_insn (scratch
, sum2
);
3253 /* According to the way these invalid addresses are generated
3254 in reload.c, it should never happen (at least on s390) that
3255 *neither* of the PLUS components, after find_replacements
3256 was applied, is an address register. */
3257 if (sum1
== scratch
&& sum2
== scratch
)
3263 src
= gen_rtx_PLUS (Pmode
, sum1
, sum2
);
3266 /* Emit the LOAD ADDRESS pattern. Note that reload of PLUS
3267 is only ever performed on addresses, so we can mark the
3268 sum as legitimate for LA in any case. */
3269 s390_load_address (target
, src
);
3273 /* Return true if ADDR is a valid memory address.
3274 STRICT specifies whether strict register checking applies. */
3277 s390_legitimate_address_p (enum machine_mode mode
, rtx addr
, bool strict
)
3279 struct s390_address ad
;
3282 && larl_operand (addr
, VOIDmode
)
3283 && (mode
== VOIDmode
3284 || s390_check_symref_alignment (addr
, GET_MODE_SIZE (mode
))))
3287 if (!s390_decompose_address (addr
, &ad
))
3292 if (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
3295 if (ad
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (ad
.indx
)))
3301 && !(REGNO (ad
.base
) >= FIRST_PSEUDO_REGISTER
3302 || REGNO_REG_CLASS (REGNO (ad
.base
)) == ADDR_REGS
))
3306 && !(REGNO (ad
.indx
) >= FIRST_PSEUDO_REGISTER
3307 || REGNO_REG_CLASS (REGNO (ad
.indx
)) == ADDR_REGS
))
3313 /* Return true if OP is a valid operand for the LA instruction.
3314 In 31-bit, we need to prove that the result is used as an
3315 address, as LA performs only a 31-bit addition. */
3318 legitimate_la_operand_p (rtx op
)
3320 struct s390_address addr
;
3321 if (!s390_decompose_address (op
, &addr
))
3324 return (TARGET_64BIT
|| addr
.pointer
);
3327 /* Return true if it is valid *and* preferable to use LA to
3328 compute the sum of OP1 and OP2. */
3331 preferred_la_operand_p (rtx op1
, rtx op2
)
3333 struct s390_address addr
;
3335 if (op2
!= const0_rtx
)
3336 op1
= gen_rtx_PLUS (Pmode
, op1
, op2
);
3338 if (!s390_decompose_address (op1
, &addr
))
3340 if (addr
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (addr
.base
)))
3342 if (addr
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (addr
.indx
)))
3345 /* Avoid LA instructions with index register on z196; it is
3346 preferable to use regular add instructions when possible. */
3347 if (addr
.indx
&& s390_tune
== PROCESSOR_2817_Z196
)
3350 if (!TARGET_64BIT
&& !addr
.pointer
)
3356 if ((addr
.base
&& REG_P (addr
.base
) && REG_POINTER (addr
.base
))
3357 || (addr
.indx
&& REG_P (addr
.indx
) && REG_POINTER (addr
.indx
)))
3363 /* Emit a forced load-address operation to load SRC into DST.
3364 This will use the LOAD ADDRESS instruction even in situations
3365 where legitimate_la_operand_p (SRC) returns false. */
3368 s390_load_address (rtx dst
, rtx src
)
3371 emit_move_insn (dst
, src
);
3373 emit_insn (gen_force_la_31 (dst
, src
));
3376 /* Return a legitimate reference for ORIG (an address) using the
3377 register REG. If REG is 0, a new pseudo is generated.
3379 There are two types of references that must be handled:
3381 1. Global data references must load the address from the GOT, via
3382 the PIC reg. An insn is emitted to do this load, and the reg is
3385 2. Static data references, constant pool addresses, and code labels
3386 compute the address as an offset from the GOT, whose base is in
3387 the PIC reg. Static data objects have SYMBOL_FLAG_LOCAL set to
3388 differentiate them from global data objects. The returned
3389 address is the PIC reg + an unspec constant.
3391 TARGET_LEGITIMIZE_ADDRESS_P rejects symbolic references unless the PIC
3392 reg also appears in the address. */
3395 legitimize_pic_address (rtx orig
, rtx reg
)
3401 gcc_assert (!TLS_SYMBOLIC_CONST (addr
));
3403 if (GET_CODE (addr
) == LABEL_REF
3404 || (GET_CODE (addr
) == SYMBOL_REF
&& SYMBOL_REF_LOCAL_P (addr
)))
3406 /* This is a local symbol. */
3407 if (TARGET_CPU_ZARCH
&& larl_operand (addr
, VOIDmode
))
3409 /* Access local symbols PC-relative via LARL.
3410 This is the same as in the non-PIC case, so it is
3411 handled automatically ... */
3415 /* Access local symbols relative to the GOT. */
3417 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3419 if (reload_in_progress
|| reload_completed
)
3420 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3422 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTOFF
);
3423 addr
= gen_rtx_CONST (Pmode
, addr
);
3424 addr
= force_const_mem (Pmode
, addr
);
3425 emit_move_insn (temp
, addr
);
3427 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3430 s390_load_address (reg
, new_rtx
);
3435 else if (GET_CODE (addr
) == SYMBOL_REF
)
3438 reg
= gen_reg_rtx (Pmode
);
3442 /* Assume GOT offset < 4k. This is handled the same way
3443 in both 31- and 64-bit code (@GOT). */
3445 if (reload_in_progress
|| reload_completed
)
3446 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3448 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOT
);
3449 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3450 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, new_rtx
);
3451 new_rtx
= gen_const_mem (Pmode
, new_rtx
);
3452 emit_move_insn (reg
, new_rtx
);
3455 else if (TARGET_CPU_ZARCH
)
3457 /* If the GOT offset might be >= 4k, we determine the position
3458 of the GOT entry via a PC-relative LARL (@GOTENT). */
3460 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3462 gcc_assert (REGNO (temp
) >= FIRST_PSEUDO_REGISTER
3463 || REGNO_REG_CLASS (REGNO (temp
)) == ADDR_REGS
);
3465 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTENT
);
3466 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3467 emit_move_insn (temp
, new_rtx
);
3469 new_rtx
= gen_const_mem (Pmode
, temp
);
3470 emit_move_insn (reg
, new_rtx
);
3475 /* If the GOT offset might be >= 4k, we have to load it
3476 from the literal pool (@GOT). */
3478 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3480 gcc_assert (REGNO (temp
) >= FIRST_PSEUDO_REGISTER
3481 || REGNO_REG_CLASS (REGNO (temp
)) == ADDR_REGS
);
3483 if (reload_in_progress
|| reload_completed
)
3484 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3486 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOT
);
3487 addr
= gen_rtx_CONST (Pmode
, addr
);
3488 addr
= force_const_mem (Pmode
, addr
);
3489 emit_move_insn (temp
, addr
);
3491 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3492 new_rtx
= gen_const_mem (Pmode
, new_rtx
);
3493 emit_move_insn (reg
, new_rtx
);
3499 if (GET_CODE (addr
) == CONST
)
3501 addr
= XEXP (addr
, 0);
3502 if (GET_CODE (addr
) == UNSPEC
)
3504 gcc_assert (XVECLEN (addr
, 0) == 1);
3505 switch (XINT (addr
, 1))
3507 /* If someone moved a GOT-relative UNSPEC
3508 out of the literal pool, force them back in. */
3511 new_rtx
= force_const_mem (Pmode
, orig
);
3514 /* @GOT is OK as is if small. */
3517 new_rtx
= force_const_mem (Pmode
, orig
);
3520 /* @GOTENT is OK as is. */
3524 /* @PLT is OK as is on 64-bit, must be converted to
3525 GOT-relative @PLTOFF on 31-bit. */
3527 if (!TARGET_CPU_ZARCH
)
3529 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3531 if (reload_in_progress
|| reload_completed
)
3532 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3534 addr
= XVECEXP (addr
, 0, 0);
3535 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
),
3537 addr
= gen_rtx_CONST (Pmode
, addr
);
3538 addr
= force_const_mem (Pmode
, addr
);
3539 emit_move_insn (temp
, addr
);
3541 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3544 s390_load_address (reg
, new_rtx
);
3550 /* Everything else cannot happen. */
3556 gcc_assert (GET_CODE (addr
) == PLUS
);
3558 if (GET_CODE (addr
) == PLUS
)
3560 rtx op0
= XEXP (addr
, 0), op1
= XEXP (addr
, 1);
3562 gcc_assert (!TLS_SYMBOLIC_CONST (op0
));
3563 gcc_assert (!TLS_SYMBOLIC_CONST (op1
));
3565 /* Check first to see if this is a constant offset
3566 from a local symbol reference. */
3567 if ((GET_CODE (op0
) == LABEL_REF
3568 || (GET_CODE (op0
) == SYMBOL_REF
&& SYMBOL_REF_LOCAL_P (op0
)))
3569 && GET_CODE (op1
) == CONST_INT
)
3571 if (TARGET_CPU_ZARCH
3572 && larl_operand (op0
, VOIDmode
)
3573 && INTVAL (op1
) < (HOST_WIDE_INT
)1 << 31
3574 && INTVAL (op1
) >= -((HOST_WIDE_INT
)1 << 31))
3576 if (INTVAL (op1
) & 1)
3578 /* LARL can't handle odd offsets, so emit a
3579 pair of LARL and LA. */
3580 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3582 if (!DISP_IN_RANGE (INTVAL (op1
)))
3584 HOST_WIDE_INT even
= INTVAL (op1
) - 1;
3585 op0
= gen_rtx_PLUS (Pmode
, op0
, GEN_INT (even
));
3586 op0
= gen_rtx_CONST (Pmode
, op0
);
3590 emit_move_insn (temp
, op0
);
3591 new_rtx
= gen_rtx_PLUS (Pmode
, temp
, op1
);
3595 s390_load_address (reg
, new_rtx
);
3601 /* If the offset is even, we can just use LARL.
3602 This will happen automatically. */
3607 /* Access local symbols relative to the GOT. */
3609 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3611 if (reload_in_progress
|| reload_completed
)
3612 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3614 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op0
),
3616 addr
= gen_rtx_PLUS (Pmode
, addr
, op1
);
3617 addr
= gen_rtx_CONST (Pmode
, addr
);
3618 addr
= force_const_mem (Pmode
, addr
);
3619 emit_move_insn (temp
, addr
);
3621 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3624 s390_load_address (reg
, new_rtx
);
3630 /* Now, check whether it is a GOT relative symbol plus offset
3631 that was pulled out of the literal pool. Force it back in. */
3633 else if (GET_CODE (op0
) == UNSPEC
3634 && GET_CODE (op1
) == CONST_INT
3635 && XINT (op0
, 1) == UNSPEC_GOTOFF
)
3637 gcc_assert (XVECLEN (op0
, 0) == 1);
3639 new_rtx
= force_const_mem (Pmode
, orig
);
3642 /* Otherwise, compute the sum. */
3645 base
= legitimize_pic_address (XEXP (addr
, 0), reg
);
3646 new_rtx
= legitimize_pic_address (XEXP (addr
, 1),
3647 base
== reg
? NULL_RTX
: reg
);
3648 if (GET_CODE (new_rtx
) == CONST_INT
)
3649 new_rtx
= plus_constant (base
, INTVAL (new_rtx
));
3652 if (GET_CODE (new_rtx
) == PLUS
&& CONSTANT_P (XEXP (new_rtx
, 1)))
3654 base
= gen_rtx_PLUS (Pmode
, base
, XEXP (new_rtx
, 0));
3655 new_rtx
= XEXP (new_rtx
, 1);
3657 new_rtx
= gen_rtx_PLUS (Pmode
, base
, new_rtx
);
3660 if (GET_CODE (new_rtx
) == CONST
)
3661 new_rtx
= XEXP (new_rtx
, 0);
3662 new_rtx
= force_operand (new_rtx
, 0);
3669 /* Load the thread pointer into a register. */
3672 s390_get_thread_pointer (void)
3674 rtx tp
= gen_reg_rtx (Pmode
);
3676 emit_move_insn (tp
, gen_rtx_REG (Pmode
, TP_REGNUM
));
3677 mark_reg_pointer (tp
, BITS_PER_WORD
);
3682 /* Emit a tls call insn. The call target is the SYMBOL_REF stored
3683 in s390_tls_symbol which always refers to __tls_get_offset.
3684 The returned offset is written to RESULT_REG and an USE rtx is
3685 generated for TLS_CALL. */
3687 static GTY(()) rtx s390_tls_symbol
;
3690 s390_emit_tls_call_insn (rtx result_reg
, rtx tls_call
)
3694 gcc_assert (flag_pic
);
3696 if (!s390_tls_symbol
)
3697 s390_tls_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "__tls_get_offset");
3699 insn
= s390_emit_call (s390_tls_symbol
, tls_call
, result_reg
,
3700 gen_rtx_REG (Pmode
, RETURN_REGNUM
));
3702 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), result_reg
);
3703 RTL_CONST_CALL_P (insn
) = 1;
3706 /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
3707 this (thread-local) address. REG may be used as temporary. */
3710 legitimize_tls_address (rtx addr
, rtx reg
)
3712 rtx new_rtx
, tls_call
, temp
, base
, r2
, insn
;
3714 if (GET_CODE (addr
) == SYMBOL_REF
)
3715 switch (tls_symbolic_operand (addr
))
3717 case TLS_MODEL_GLOBAL_DYNAMIC
:
3719 r2
= gen_rtx_REG (Pmode
, 2);
3720 tls_call
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_TLSGD
);
3721 new_rtx
= gen_rtx_CONST (Pmode
, tls_call
);
3722 new_rtx
= force_const_mem (Pmode
, new_rtx
);
3723 emit_move_insn (r2
, new_rtx
);
3724 s390_emit_tls_call_insn (r2
, tls_call
);
3725 insn
= get_insns ();
3728 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_NTPOFF
);
3729 temp
= gen_reg_rtx (Pmode
);
3730 emit_libcall_block (insn
, temp
, r2
, new_rtx
);
3732 new_rtx
= gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3735 s390_load_address (reg
, new_rtx
);
3740 case TLS_MODEL_LOCAL_DYNAMIC
:
3742 r2
= gen_rtx_REG (Pmode
, 2);
3743 tls_call
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, const0_rtx
), UNSPEC_TLSLDM
);
3744 new_rtx
= gen_rtx_CONST (Pmode
, tls_call
);
3745 new_rtx
= force_const_mem (Pmode
, new_rtx
);
3746 emit_move_insn (r2
, new_rtx
);
3747 s390_emit_tls_call_insn (r2
, tls_call
);
3748 insn
= get_insns ();
3751 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, const0_rtx
), UNSPEC_TLSLDM_NTPOFF
);
3752 temp
= gen_reg_rtx (Pmode
);
3753 emit_libcall_block (insn
, temp
, r2
, new_rtx
);
3755 new_rtx
= gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3756 base
= gen_reg_rtx (Pmode
);
3757 s390_load_address (base
, new_rtx
);
3759 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_DTPOFF
);
3760 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3761 new_rtx
= force_const_mem (Pmode
, new_rtx
);
3762 temp
= gen_reg_rtx (Pmode
);
3763 emit_move_insn (temp
, new_rtx
);
3765 new_rtx
= gen_rtx_PLUS (Pmode
, base
, temp
);
3768 s390_load_address (reg
, new_rtx
);
3773 case TLS_MODEL_INITIAL_EXEC
:
3776 /* Assume GOT offset < 4k. This is handled the same way
3777 in both 31- and 64-bit code. */
3779 if (reload_in_progress
|| reload_completed
)
3780 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3782 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTNTPOFF
);
3783 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3784 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, new_rtx
);
3785 new_rtx
= gen_const_mem (Pmode
, new_rtx
);
3786 temp
= gen_reg_rtx (Pmode
);
3787 emit_move_insn (temp
, new_rtx
);
3789 else if (TARGET_CPU_ZARCH
)
3791 /* If the GOT offset might be >= 4k, we determine the position
3792 of the GOT entry via a PC-relative LARL. */
3794 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_INDNTPOFF
);
3795 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3796 temp
= gen_reg_rtx (Pmode
);
3797 emit_move_insn (temp
, new_rtx
);
3799 new_rtx
= gen_const_mem (Pmode
, temp
);
3800 temp
= gen_reg_rtx (Pmode
);
3801 emit_move_insn (temp
, new_rtx
);
3805 /* If the GOT offset might be >= 4k, we have to load it
3806 from the literal pool. */
3808 if (reload_in_progress
|| reload_completed
)
3809 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3811 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTNTPOFF
);
3812 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3813 new_rtx
= force_const_mem (Pmode
, new_rtx
);
3814 temp
= gen_reg_rtx (Pmode
);
3815 emit_move_insn (temp
, new_rtx
);
3817 new_rtx
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3818 new_rtx
= gen_const_mem (Pmode
, new_rtx
);
3820 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, new_rtx
, addr
), UNSPEC_TLS_LOAD
);
3821 temp
= gen_reg_rtx (Pmode
);
3822 emit_insn (gen_rtx_SET (Pmode
, temp
, new_rtx
));
3826 /* In position-dependent code, load the absolute address of
3827 the GOT entry from the literal pool. */
3829 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_INDNTPOFF
);
3830 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3831 new_rtx
= force_const_mem (Pmode
, new_rtx
);
3832 temp
= gen_reg_rtx (Pmode
);
3833 emit_move_insn (temp
, new_rtx
);
3836 new_rtx
= gen_const_mem (Pmode
, new_rtx
);
3837 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, new_rtx
, addr
), UNSPEC_TLS_LOAD
);
3838 temp
= gen_reg_rtx (Pmode
);
3839 emit_insn (gen_rtx_SET (Pmode
, temp
, new_rtx
));
3842 new_rtx
= gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3845 s390_load_address (reg
, new_rtx
);
3850 case TLS_MODEL_LOCAL_EXEC
:
3851 new_rtx
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_NTPOFF
);
3852 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3853 new_rtx
= force_const_mem (Pmode
, new_rtx
);
3854 temp
= gen_reg_rtx (Pmode
);
3855 emit_move_insn (temp
, new_rtx
);
3857 new_rtx
= gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3860 s390_load_address (reg
, new_rtx
);
3869 else if (GET_CODE (addr
) == CONST
&& GET_CODE (XEXP (addr
, 0)) == UNSPEC
)
3871 switch (XINT (XEXP (addr
, 0), 1))
3873 case UNSPEC_INDNTPOFF
:
3874 gcc_assert (TARGET_CPU_ZARCH
);
3883 else if (GET_CODE (addr
) == CONST
&& GET_CODE (XEXP (addr
, 0)) == PLUS
3884 && GET_CODE (XEXP (XEXP (addr
, 0), 1)) == CONST_INT
)
3886 new_rtx
= XEXP (XEXP (addr
, 0), 0);
3887 if (GET_CODE (new_rtx
) != SYMBOL_REF
)
3888 new_rtx
= gen_rtx_CONST (Pmode
, new_rtx
);
3890 new_rtx
= legitimize_tls_address (new_rtx
, reg
);
3891 new_rtx
= plus_constant (new_rtx
, INTVAL (XEXP (XEXP (addr
, 0), 1)));
3892 new_rtx
= force_operand (new_rtx
, 0);
3896 gcc_unreachable (); /* for now ... */
3901 /* Emit insns making the address in operands[1] valid for a standard
3902 move to operands[0]. operands[1] is replaced by an address which
3903 should be used instead of the former RTX to emit the move
3907 emit_symbolic_move (rtx
*operands
)
3909 rtx temp
= !can_create_pseudo_p () ? operands
[0] : gen_reg_rtx (Pmode
);
3911 if (GET_CODE (operands
[0]) == MEM
)
3912 operands
[1] = force_reg (Pmode
, operands
[1]);
3913 else if (TLS_SYMBOLIC_CONST (operands
[1]))
3914 operands
[1] = legitimize_tls_address (operands
[1], temp
);
3916 operands
[1] = legitimize_pic_address (operands
[1], temp
);
3919 /* Try machine-dependent ways of modifying an illegitimate address X
3920 to be legitimate. If we find one, return the new, valid address.
3922 OLDX is the address as it was before break_out_memory_refs was called.
3923 In some cases it is useful to look at this to decide what needs to be done.
3925 MODE is the mode of the operand pointed to by X.
3927 When -fpic is used, special handling is needed for symbolic references.
3928 See comments by legitimize_pic_address for details. */
3931 s390_legitimize_address (rtx x
, rtx oldx ATTRIBUTE_UNUSED
,
3932 enum machine_mode mode ATTRIBUTE_UNUSED
)
3934 rtx constant_term
= const0_rtx
;
3936 if (TLS_SYMBOLIC_CONST (x
))
3938 x
= legitimize_tls_address (x
, 0);
3940 if (s390_legitimate_address_p (mode
, x
, FALSE
))
3943 else if (GET_CODE (x
) == PLUS
3944 && (TLS_SYMBOLIC_CONST (XEXP (x
, 0))
3945 || TLS_SYMBOLIC_CONST (XEXP (x
, 1))))
3951 if (SYMBOLIC_CONST (x
)
3952 || (GET_CODE (x
) == PLUS
3953 && (SYMBOLIC_CONST (XEXP (x
, 0))
3954 || SYMBOLIC_CONST (XEXP (x
, 1)))))
3955 x
= legitimize_pic_address (x
, 0);
3957 if (s390_legitimate_address_p (mode
, x
, FALSE
))
3961 x
= eliminate_constant_term (x
, &constant_term
);
3963 /* Optimize loading of large displacements by splitting them
3964 into the multiple of 4K and the rest; this allows the
3965 former to be CSE'd if possible.
3967 Don't do this if the displacement is added to a register
3968 pointing into the stack frame, as the offsets will
3969 change later anyway. */
3971 if (GET_CODE (constant_term
) == CONST_INT
3972 && !TARGET_LONG_DISPLACEMENT
3973 && !DISP_IN_RANGE (INTVAL (constant_term
))
3974 && !(REG_P (x
) && REGNO_PTR_FRAME_P (REGNO (x
))))
3976 HOST_WIDE_INT lower
= INTVAL (constant_term
) & 0xfff;
3977 HOST_WIDE_INT upper
= INTVAL (constant_term
) ^ lower
;
3979 rtx temp
= gen_reg_rtx (Pmode
);
3980 rtx val
= force_operand (GEN_INT (upper
), temp
);
3982 emit_move_insn (temp
, val
);
3984 x
= gen_rtx_PLUS (Pmode
, x
, temp
);
3985 constant_term
= GEN_INT (lower
);
3988 if (GET_CODE (x
) == PLUS
)
3990 if (GET_CODE (XEXP (x
, 0)) == REG
)
3992 rtx temp
= gen_reg_rtx (Pmode
);
3993 rtx val
= force_operand (XEXP (x
, 1), temp
);
3995 emit_move_insn (temp
, val
);
3997 x
= gen_rtx_PLUS (Pmode
, XEXP (x
, 0), temp
);
4000 else if (GET_CODE (XEXP (x
, 1)) == REG
)
4002 rtx temp
= gen_reg_rtx (Pmode
);
4003 rtx val
= force_operand (XEXP (x
, 0), temp
);
4005 emit_move_insn (temp
, val
);
4007 x
= gen_rtx_PLUS (Pmode
, temp
, XEXP (x
, 1));
4011 if (constant_term
!= const0_rtx
)
4012 x
= gen_rtx_PLUS (Pmode
, x
, constant_term
);
4017 /* Try a machine-dependent way of reloading an illegitimate address AD
4018 operand. If we find one, push the reload and and return the new address.
4020 MODE is the mode of the enclosing MEM. OPNUM is the operand number
4021 and TYPE is the reload type of the current reload. */
4024 legitimize_reload_address (rtx ad
, enum machine_mode mode ATTRIBUTE_UNUSED
,
4025 int opnum
, int type
)
4027 if (!optimize
|| TARGET_LONG_DISPLACEMENT
)
4030 if (GET_CODE (ad
) == PLUS
)
4032 rtx tem
= simplify_binary_operation (PLUS
, Pmode
,
4033 XEXP (ad
, 0), XEXP (ad
, 1));
4038 if (GET_CODE (ad
) == PLUS
4039 && GET_CODE (XEXP (ad
, 0)) == REG
4040 && GET_CODE (XEXP (ad
, 1)) == CONST_INT
4041 && !DISP_IN_RANGE (INTVAL (XEXP (ad
, 1))))
4043 HOST_WIDE_INT lower
= INTVAL (XEXP (ad
, 1)) & 0xfff;
4044 HOST_WIDE_INT upper
= INTVAL (XEXP (ad
, 1)) ^ lower
;
4045 rtx cst
, tem
, new_rtx
;
4047 cst
= GEN_INT (upper
);
4048 if (!legitimate_reload_constant_p (cst
))
4049 cst
= force_const_mem (Pmode
, cst
);
4051 tem
= gen_rtx_PLUS (Pmode
, XEXP (ad
, 0), cst
);
4052 new_rtx
= gen_rtx_PLUS (Pmode
, tem
, GEN_INT (lower
));
4054 push_reload (XEXP (tem
, 1), 0, &XEXP (tem
, 1), 0,
4055 BASE_REG_CLASS
, Pmode
, VOIDmode
, 0, 0,
4056 opnum
, (enum reload_type
) type
);
4063 /* Emit code to move LEN bytes from DST to SRC. */
4066 s390_expand_movmem (rtx dst
, rtx src
, rtx len
)
4068 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) >= 0 && INTVAL (len
) <= 256)
4070 if (INTVAL (len
) > 0)
4071 emit_insn (gen_movmem_short (dst
, src
, GEN_INT (INTVAL (len
) - 1)));
4074 else if (TARGET_MVCLE
)
4076 emit_insn (gen_movmem_long (dst
, src
, convert_to_mode (Pmode
, len
, 1)));
4081 rtx dst_addr
, src_addr
, count
, blocks
, temp
;
4082 rtx loop_start_label
= gen_label_rtx ();
4083 rtx loop_end_label
= gen_label_rtx ();
4084 rtx end_label
= gen_label_rtx ();
4085 enum machine_mode mode
;
4087 mode
= GET_MODE (len
);
4088 if (mode
== VOIDmode
)
4091 dst_addr
= gen_reg_rtx (Pmode
);
4092 src_addr
= gen_reg_rtx (Pmode
);
4093 count
= gen_reg_rtx (mode
);
4094 blocks
= gen_reg_rtx (mode
);
4096 convert_move (count
, len
, 1);
4097 emit_cmp_and_jump_insns (count
, const0_rtx
,
4098 EQ
, NULL_RTX
, mode
, 1, end_label
);
4100 emit_move_insn (dst_addr
, force_operand (XEXP (dst
, 0), NULL_RTX
));
4101 emit_move_insn (src_addr
, force_operand (XEXP (src
, 0), NULL_RTX
));
4102 dst
= change_address (dst
, VOIDmode
, dst_addr
);
4103 src
= change_address (src
, VOIDmode
, src_addr
);
4105 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1,
4108 emit_move_insn (count
, temp
);
4110 temp
= expand_binop (mode
, lshr_optab
, count
, GEN_INT (8), blocks
, 1,
4113 emit_move_insn (blocks
, temp
);
4115 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
4116 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
4118 emit_label (loop_start_label
);
4121 && (GET_CODE (len
) != CONST_INT
|| INTVAL (len
) > 768))
4125 /* Issue a read prefetch for the +3 cache line. */
4126 prefetch
= gen_prefetch (gen_rtx_PLUS (Pmode
, src_addr
, GEN_INT (768)),
4127 const0_rtx
, const0_rtx
);
4128 PREFETCH_SCHEDULE_BARRIER_P (prefetch
) = true;
4129 emit_insn (prefetch
);
4131 /* Issue a write prefetch for the +3 cache line. */
4132 prefetch
= gen_prefetch (gen_rtx_PLUS (Pmode
, dst_addr
, GEN_INT (768)),
4133 const1_rtx
, const0_rtx
);
4134 PREFETCH_SCHEDULE_BARRIER_P (prefetch
) = true;
4135 emit_insn (prefetch
);
4138 emit_insn (gen_movmem_short (dst
, src
, GEN_INT (255)));
4139 s390_load_address (dst_addr
,
4140 gen_rtx_PLUS (Pmode
, dst_addr
, GEN_INT (256)));
4141 s390_load_address (src_addr
,
4142 gen_rtx_PLUS (Pmode
, src_addr
, GEN_INT (256)));
4144 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1,
4147 emit_move_insn (blocks
, temp
);
4149 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
4150 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
4152 emit_jump (loop_start_label
);
4153 emit_label (loop_end_label
);
4155 emit_insn (gen_movmem_short (dst
, src
,
4156 convert_to_mode (Pmode
, count
, 1)));
4157 emit_label (end_label
);
4161 /* Emit code to set LEN bytes at DST to VAL.
4162 Make use of clrmem if VAL is zero. */
4165 s390_expand_setmem (rtx dst
, rtx len
, rtx val
)
4167 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) == 0)
4170 gcc_assert (GET_CODE (val
) == CONST_INT
|| GET_MODE (val
) == QImode
);
4172 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) > 0 && INTVAL (len
) <= 257)
4174 if (val
== const0_rtx
&& INTVAL (len
) <= 256)
4175 emit_insn (gen_clrmem_short (dst
, GEN_INT (INTVAL (len
) - 1)));
4178 /* Initialize memory by storing the first byte. */
4179 emit_move_insn (adjust_address (dst
, QImode
, 0), val
);
4181 if (INTVAL (len
) > 1)
4183 /* Initiate 1 byte overlap move.
4184 The first byte of DST is propagated through DSTP1.
4185 Prepare a movmem for: DST+1 = DST (length = LEN - 1).
4186 DST is set to size 1 so the rest of the memory location
4187 does not count as source operand. */
4188 rtx dstp1
= adjust_address (dst
, VOIDmode
, 1);
4189 set_mem_size (dst
, const1_rtx
);
4191 emit_insn (gen_movmem_short (dstp1
, dst
,
4192 GEN_INT (INTVAL (len
) - 2)));
4197 else if (TARGET_MVCLE
)
4199 val
= force_not_mem (convert_modes (Pmode
, QImode
, val
, 1));
4200 emit_insn (gen_setmem_long (dst
, convert_to_mode (Pmode
, len
, 1), val
));
4205 rtx dst_addr
, count
, blocks
, temp
, dstp1
= NULL_RTX
;
4206 rtx loop_start_label
= gen_label_rtx ();
4207 rtx loop_end_label
= gen_label_rtx ();
4208 rtx end_label
= gen_label_rtx ();
4209 enum machine_mode mode
;
4211 mode
= GET_MODE (len
);
4212 if (mode
== VOIDmode
)
4215 dst_addr
= gen_reg_rtx (Pmode
);
4216 count
= gen_reg_rtx (mode
);
4217 blocks
= gen_reg_rtx (mode
);
4219 convert_move (count
, len
, 1);
4220 emit_cmp_and_jump_insns (count
, const0_rtx
,
4221 EQ
, NULL_RTX
, mode
, 1, end_label
);
4223 emit_move_insn (dst_addr
, force_operand (XEXP (dst
, 0), NULL_RTX
));
4224 dst
= change_address (dst
, VOIDmode
, dst_addr
);
4226 if (val
== const0_rtx
)
4227 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1,
4231 dstp1
= adjust_address (dst
, VOIDmode
, 1);
4232 set_mem_size (dst
, const1_rtx
);
4234 /* Initialize memory by storing the first byte. */
4235 emit_move_insn (adjust_address (dst
, QImode
, 0), val
);
4237 /* If count is 1 we are done. */
4238 emit_cmp_and_jump_insns (count
, const1_rtx
,
4239 EQ
, NULL_RTX
, mode
, 1, end_label
);
4241 temp
= expand_binop (mode
, add_optab
, count
, GEN_INT (-2), count
, 1,
4245 emit_move_insn (count
, temp
);
4247 temp
= expand_binop (mode
, lshr_optab
, count
, GEN_INT (8), blocks
, 1,
4250 emit_move_insn (blocks
, temp
);
4252 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
4253 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
4255 emit_label (loop_start_label
);
4258 && (GET_CODE (len
) != CONST_INT
|| INTVAL (len
) > 1024))
4260 /* Issue a write prefetch for the +4 cache line. */
4261 rtx prefetch
= gen_prefetch (gen_rtx_PLUS (Pmode
, dst_addr
,
4263 const1_rtx
, const0_rtx
);
4264 emit_insn (prefetch
);
4265 PREFETCH_SCHEDULE_BARRIER_P (prefetch
) = true;
4268 if (val
== const0_rtx
)
4269 emit_insn (gen_clrmem_short (dst
, GEN_INT (255)));
4271 emit_insn (gen_movmem_short (dstp1
, dst
, GEN_INT (255)));
4272 s390_load_address (dst_addr
,
4273 gen_rtx_PLUS (Pmode
, dst_addr
, GEN_INT (256)));
4275 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1,
4278 emit_move_insn (blocks
, temp
);
4280 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
4281 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
4283 emit_jump (loop_start_label
);
4284 emit_label (loop_end_label
);
4286 if (val
== const0_rtx
)
4287 emit_insn (gen_clrmem_short (dst
, convert_to_mode (Pmode
, count
, 1)));
4289 emit_insn (gen_movmem_short (dstp1
, dst
, convert_to_mode (Pmode
, count
, 1)));
4290 emit_label (end_label
);
4294 /* Emit code to compare LEN bytes at OP0 with those at OP1,
4295 and return the result in TARGET. */
4298 s390_expand_cmpmem (rtx target
, rtx op0
, rtx op1
, rtx len
)
4300 rtx ccreg
= gen_rtx_REG (CCUmode
, CC_REGNUM
);
4303 /* As the result of CMPINT is inverted compared to what we need,
4304 we have to swap the operands. */
4305 tmp
= op0
; op0
= op1
; op1
= tmp
;
4307 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) >= 0 && INTVAL (len
) <= 256)
4309 if (INTVAL (len
) > 0)
4311 emit_insn (gen_cmpmem_short (op0
, op1
, GEN_INT (INTVAL (len
) - 1)));
4312 emit_insn (gen_cmpint (target
, ccreg
));
4315 emit_move_insn (target
, const0_rtx
);
4317 else if (TARGET_MVCLE
)
4319 emit_insn (gen_cmpmem_long (op0
, op1
, convert_to_mode (Pmode
, len
, 1)));
4320 emit_insn (gen_cmpint (target
, ccreg
));
4324 rtx addr0
, addr1
, count
, blocks
, temp
;
4325 rtx loop_start_label
= gen_label_rtx ();
4326 rtx loop_end_label
= gen_label_rtx ();
4327 rtx end_label
= gen_label_rtx ();
4328 enum machine_mode mode
;
4330 mode
= GET_MODE (len
);
4331 if (mode
== VOIDmode
)
4334 addr0
= gen_reg_rtx (Pmode
);
4335 addr1
= gen_reg_rtx (Pmode
);
4336 count
= gen_reg_rtx (mode
);
4337 blocks
= gen_reg_rtx (mode
);
4339 convert_move (count
, len
, 1);
4340 emit_cmp_and_jump_insns (count
, const0_rtx
,
4341 EQ
, NULL_RTX
, mode
, 1, end_label
);
4343 emit_move_insn (addr0
, force_operand (XEXP (op0
, 0), NULL_RTX
));
4344 emit_move_insn (addr1
, force_operand (XEXP (op1
, 0), NULL_RTX
));
4345 op0
= change_address (op0
, VOIDmode
, addr0
);
4346 op1
= change_address (op1
, VOIDmode
, addr1
);
4348 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1,
4351 emit_move_insn (count
, temp
);
4353 temp
= expand_binop (mode
, lshr_optab
, count
, GEN_INT (8), blocks
, 1,
4356 emit_move_insn (blocks
, temp
);
4358 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
4359 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
4361 emit_label (loop_start_label
);
4364 && (GET_CODE (len
) != CONST_INT
|| INTVAL (len
) > 512))
4368 /* Issue a read prefetch for the +2 cache line of operand 1. */
4369 prefetch
= gen_prefetch (gen_rtx_PLUS (Pmode
, addr0
, GEN_INT (512)),
4370 const0_rtx
, const0_rtx
);
4371 emit_insn (prefetch
);
4372 PREFETCH_SCHEDULE_BARRIER_P (prefetch
) = true;
4374 /* Issue a read prefetch for the +2 cache line of operand 2. */
4375 prefetch
= gen_prefetch (gen_rtx_PLUS (Pmode
, addr1
, GEN_INT (512)),
4376 const0_rtx
, const0_rtx
);
4377 emit_insn (prefetch
);
4378 PREFETCH_SCHEDULE_BARRIER_P (prefetch
) = true;
4381 emit_insn (gen_cmpmem_short (op0
, op1
, GEN_INT (255)));
4382 temp
= gen_rtx_NE (VOIDmode
, ccreg
, const0_rtx
);
4383 temp
= gen_rtx_IF_THEN_ELSE (VOIDmode
, temp
,
4384 gen_rtx_LABEL_REF (VOIDmode
, end_label
), pc_rtx
);
4385 temp
= gen_rtx_SET (VOIDmode
, pc_rtx
, temp
);
4386 emit_jump_insn (temp
);
4388 s390_load_address (addr0
,
4389 gen_rtx_PLUS (Pmode
, addr0
, GEN_INT (256)));
4390 s390_load_address (addr1
,
4391 gen_rtx_PLUS (Pmode
, addr1
, GEN_INT (256)));
4393 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1,
4396 emit_move_insn (blocks
, temp
);
4398 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
4399 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
4401 emit_jump (loop_start_label
);
4402 emit_label (loop_end_label
);
4404 emit_insn (gen_cmpmem_short (op0
, op1
,
4405 convert_to_mode (Pmode
, count
, 1)));
4406 emit_label (end_label
);
4408 emit_insn (gen_cmpint (target
, ccreg
));
4413 /* Expand conditional increment or decrement using alc/slb instructions.
4414 Should generate code setting DST to either SRC or SRC + INCREMENT,
4415 depending on the result of the comparison CMP_OP0 CMP_CODE CMP_OP1.
4416 Returns true if successful, false otherwise.
4418 That makes it possible to implement some if-constructs without jumps e.g.:
4419 (borrow = CC0 | CC1 and carry = CC2 | CC3)
4420 unsigned int a, b, c;
4421 if (a < b) c++; -> CCU b > a -> CC2; c += carry;
4422 if (a < b) c--; -> CCL3 a - b -> borrow; c -= borrow;
4423 if (a <= b) c++; -> CCL3 b - a -> borrow; c += carry;
4424 if (a <= b) c--; -> CCU a <= b -> borrow; c -= borrow;
4426 Checks for EQ and NE with a nonzero value need an additional xor e.g.:
4427 if (a == b) c++; -> CCL3 a ^= b; 0 - a -> borrow; c += carry;
4428 if (a == b) c--; -> CCU a ^= b; a <= 0 -> CC0 | CC1; c -= borrow;
4429 if (a != b) c++; -> CCU a ^= b; a > 0 -> CC2; c += carry;
4430 if (a != b) c--; -> CCL3 a ^= b; 0 - a -> borrow; c -= borrow; */
4433 s390_expand_addcc (enum rtx_code cmp_code
, rtx cmp_op0
, rtx cmp_op1
,
4434 rtx dst
, rtx src
, rtx increment
)
4436 enum machine_mode cmp_mode
;
4437 enum machine_mode cc_mode
;
4443 if ((GET_MODE (cmp_op0
) == SImode
|| GET_MODE (cmp_op0
) == VOIDmode
)
4444 && (GET_MODE (cmp_op1
) == SImode
|| GET_MODE (cmp_op1
) == VOIDmode
))
4446 else if ((GET_MODE (cmp_op0
) == DImode
|| GET_MODE (cmp_op0
) == VOIDmode
)
4447 && (GET_MODE (cmp_op1
) == DImode
|| GET_MODE (cmp_op1
) == VOIDmode
))
4452 /* Try ADD LOGICAL WITH CARRY. */
4453 if (increment
== const1_rtx
)
4455 /* Determine CC mode to use. */
4456 if (cmp_code
== EQ
|| cmp_code
== NE
)
4458 if (cmp_op1
!= const0_rtx
)
4460 cmp_op0
= expand_simple_binop (cmp_mode
, XOR
, cmp_op0
, cmp_op1
,
4461 NULL_RTX
, 0, OPTAB_WIDEN
);
4462 cmp_op1
= const0_rtx
;
4465 cmp_code
= cmp_code
== EQ
? LEU
: GTU
;
4468 if (cmp_code
== LTU
|| cmp_code
== LEU
)
4473 cmp_code
= swap_condition (cmp_code
);
4490 /* Emit comparison instruction pattern. */
4491 if (!register_operand (cmp_op0
, cmp_mode
))
4492 cmp_op0
= force_reg (cmp_mode
, cmp_op0
);
4494 insn
= gen_rtx_SET (VOIDmode
, gen_rtx_REG (cc_mode
, CC_REGNUM
),
4495 gen_rtx_COMPARE (cc_mode
, cmp_op0
, cmp_op1
));
4496 /* We use insn_invalid_p here to add clobbers if required. */
4497 ret
= insn_invalid_p (emit_insn (insn
));
4500 /* Emit ALC instruction pattern. */
4501 op_res
= gen_rtx_fmt_ee (cmp_code
, GET_MODE (dst
),
4502 gen_rtx_REG (cc_mode
, CC_REGNUM
),
4505 if (src
!= const0_rtx
)
4507 if (!register_operand (src
, GET_MODE (dst
)))
4508 src
= force_reg (GET_MODE (dst
), src
);
4510 op_res
= gen_rtx_PLUS (GET_MODE (dst
), op_res
, src
);
4511 op_res
= gen_rtx_PLUS (GET_MODE (dst
), op_res
, const0_rtx
);
4514 p
= rtvec_alloc (2);
4516 gen_rtx_SET (VOIDmode
, dst
, op_res
);
4518 gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
4519 emit_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
4524 /* Try SUBTRACT LOGICAL WITH BORROW. */
4525 if (increment
== constm1_rtx
)
4527 /* Determine CC mode to use. */
4528 if (cmp_code
== EQ
|| cmp_code
== NE
)
4530 if (cmp_op1
!= const0_rtx
)
4532 cmp_op0
= expand_simple_binop (cmp_mode
, XOR
, cmp_op0
, cmp_op1
,
4533 NULL_RTX
, 0, OPTAB_WIDEN
);
4534 cmp_op1
= const0_rtx
;
4537 cmp_code
= cmp_code
== EQ
? LEU
: GTU
;
4540 if (cmp_code
== GTU
|| cmp_code
== GEU
)
4545 cmp_code
= swap_condition (cmp_code
);
4562 /* Emit comparison instruction pattern. */
4563 if (!register_operand (cmp_op0
, cmp_mode
))
4564 cmp_op0
= force_reg (cmp_mode
, cmp_op0
);
4566 insn
= gen_rtx_SET (VOIDmode
, gen_rtx_REG (cc_mode
, CC_REGNUM
),
4567 gen_rtx_COMPARE (cc_mode
, cmp_op0
, cmp_op1
));
4568 /* We use insn_invalid_p here to add clobbers if required. */
4569 ret
= insn_invalid_p (emit_insn (insn
));
4572 /* Emit SLB instruction pattern. */
4573 if (!register_operand (src
, GET_MODE (dst
)))
4574 src
= force_reg (GET_MODE (dst
), src
);
4576 op_res
= gen_rtx_MINUS (GET_MODE (dst
),
4577 gen_rtx_MINUS (GET_MODE (dst
), src
, const0_rtx
),
4578 gen_rtx_fmt_ee (cmp_code
, GET_MODE (dst
),
4579 gen_rtx_REG (cc_mode
, CC_REGNUM
),
4581 p
= rtvec_alloc (2);
4583 gen_rtx_SET (VOIDmode
, dst
, op_res
);
4585 gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
4586 emit_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
4594 /* Expand code for the insv template. Return true if successful. */
4597 s390_expand_insv (rtx dest
, rtx op1
, rtx op2
, rtx src
)
4599 int bitsize
= INTVAL (op1
);
4600 int bitpos
= INTVAL (op2
);
4602 /* On z10 we can use the risbg instruction to implement insv. */
4604 && ((GET_MODE (dest
) == DImode
&& GET_MODE (src
) == DImode
)
4605 || (GET_MODE (dest
) == SImode
&& GET_MODE (src
) == SImode
)))
4610 op
= gen_rtx_SET (GET_MODE(src
),
4611 gen_rtx_ZERO_EXTRACT (GET_MODE (dest
), dest
, op1
, op2
),
4613 clobber
= gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
4614 emit_insn (gen_rtx_PARALLEL (VOIDmode
, gen_rtvec (2, op
, clobber
)));
4619 /* We need byte alignment. */
4620 if (bitsize
% BITS_PER_UNIT
)
4624 && memory_operand (dest
, VOIDmode
)
4625 && (register_operand (src
, word_mode
)
4626 || const_int_operand (src
, VOIDmode
)))
4628 /* Emit standard pattern if possible. */
4629 enum machine_mode mode
= smallest_mode_for_size (bitsize
, MODE_INT
);
4630 if (GET_MODE_BITSIZE (mode
) == bitsize
)
4631 emit_move_insn (adjust_address (dest
, mode
, 0), gen_lowpart (mode
, src
));
4633 /* (set (ze (mem)) (const_int)). */
4634 else if (const_int_operand (src
, VOIDmode
))
4636 int size
= bitsize
/ BITS_PER_UNIT
;
4637 rtx src_mem
= adjust_address (force_const_mem (word_mode
, src
), BLKmode
,
4638 GET_MODE_SIZE (word_mode
) - size
);
4640 dest
= adjust_address (dest
, BLKmode
, 0);
4641 set_mem_size (dest
, GEN_INT (size
));
4642 s390_expand_movmem (dest
, src_mem
, GEN_INT (size
));
4645 /* (set (ze (mem)) (reg)). */
4646 else if (register_operand (src
, word_mode
))
4648 if (bitsize
<= GET_MODE_BITSIZE (SImode
))
4649 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
, op1
,
4653 /* Emit st,stcmh sequence. */
4654 int stcmh_width
= bitsize
- GET_MODE_BITSIZE (SImode
);
4655 int size
= stcmh_width
/ BITS_PER_UNIT
;
4657 emit_move_insn (adjust_address (dest
, SImode
, size
),
4658 gen_lowpart (SImode
, src
));
4659 set_mem_size (dest
, GEN_INT (size
));
4660 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
, GEN_INT
4661 (stcmh_width
), const0_rtx
),
4662 gen_rtx_LSHIFTRT (word_mode
, src
, GEN_INT
4663 (GET_MODE_BITSIZE (SImode
))));
4672 /* (set (ze (reg)) (const_int)). */
4674 && register_operand (dest
, word_mode
)
4675 && (bitpos
% 16) == 0
4676 && (bitsize
% 16) == 0
4677 && const_int_operand (src
, VOIDmode
))
4679 HOST_WIDE_INT val
= INTVAL (src
);
4680 int regpos
= bitpos
+ bitsize
;
4682 while (regpos
> bitpos
)
4684 enum machine_mode putmode
;
4687 if (TARGET_EXTIMM
&& (regpos
% 32 == 0) && (regpos
>= bitpos
+ 32))
4692 putsize
= GET_MODE_BITSIZE (putmode
);
4694 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
,
4697 gen_int_mode (val
, putmode
));
4700 gcc_assert (regpos
== bitpos
);
4707 /* A subroutine of s390_expand_cs_hqi and s390_expand_atomic which returns a
4708 register that holds VAL of mode MODE shifted by COUNT bits. */
4711 s390_expand_mask_and_shift (rtx val
, enum machine_mode mode
, rtx count
)
4713 val
= expand_simple_binop (SImode
, AND
, val
, GEN_INT (GET_MODE_MASK (mode
)),
4714 NULL_RTX
, 1, OPTAB_DIRECT
);
4715 return expand_simple_binop (SImode
, ASHIFT
, val
, count
,
4716 NULL_RTX
, 1, OPTAB_DIRECT
);
4719 /* Structure to hold the initial parameters for a compare_and_swap operation
4720 in HImode and QImode. */
4722 struct alignment_context
4724 rtx memsi
; /* SI aligned memory location. */
4725 rtx shift
; /* Bit offset with regard to lsb. */
4726 rtx modemask
; /* Mask of the HQImode shifted by SHIFT bits. */
4727 rtx modemaski
; /* ~modemask */
4728 bool aligned
; /* True if memory is aligned, false else. */
4731 /* A subroutine of s390_expand_cs_hqi and s390_expand_atomic to initialize
4732 structure AC for transparent simplifying, if the memory alignment is known
4733 to be at least 32bit. MEM is the memory location for the actual operation
4734 and MODE its mode. */
4737 init_alignment_context (struct alignment_context
*ac
, rtx mem
,
4738 enum machine_mode mode
)
4740 ac
->shift
= GEN_INT (GET_MODE_SIZE (SImode
) - GET_MODE_SIZE (mode
));
4741 ac
->aligned
= (MEM_ALIGN (mem
) >= GET_MODE_BITSIZE (SImode
));
4744 ac
->memsi
= adjust_address (mem
, SImode
, 0); /* Memory is aligned. */
4747 /* Alignment is unknown. */
4748 rtx byteoffset
, addr
, align
;
4750 /* Force the address into a register. */
4751 addr
= force_reg (Pmode
, XEXP (mem
, 0));
4753 /* Align it to SImode. */
4754 align
= expand_simple_binop (Pmode
, AND
, addr
,
4755 GEN_INT (-GET_MODE_SIZE (SImode
)),
4756 NULL_RTX
, 1, OPTAB_DIRECT
);
4758 ac
->memsi
= gen_rtx_MEM (SImode
, align
);
4759 MEM_VOLATILE_P (ac
->memsi
) = MEM_VOLATILE_P (mem
);
4760 set_mem_alias_set (ac
->memsi
, ALIAS_SET_MEMORY_BARRIER
);
4761 set_mem_align (ac
->memsi
, GET_MODE_BITSIZE (SImode
));
4763 /* Calculate shiftcount. */
4764 byteoffset
= expand_simple_binop (Pmode
, AND
, addr
,
4765 GEN_INT (GET_MODE_SIZE (SImode
) - 1),
4766 NULL_RTX
, 1, OPTAB_DIRECT
);
4767 /* As we already have some offset, evaluate the remaining distance. */
4768 ac
->shift
= expand_simple_binop (SImode
, MINUS
, ac
->shift
, byteoffset
,
4769 NULL_RTX
, 1, OPTAB_DIRECT
);
4772 /* Shift is the byte count, but we need the bitcount. */
4773 ac
->shift
= expand_simple_binop (SImode
, MULT
, ac
->shift
, GEN_INT (BITS_PER_UNIT
),
4774 NULL_RTX
, 1, OPTAB_DIRECT
);
4775 /* Calculate masks. */
4776 ac
->modemask
= expand_simple_binop (SImode
, ASHIFT
,
4777 GEN_INT (GET_MODE_MASK (mode
)), ac
->shift
,
4778 NULL_RTX
, 1, OPTAB_DIRECT
);
4779 ac
->modemaski
= expand_simple_unop (SImode
, NOT
, ac
->modemask
, NULL_RTX
, 1);
4782 /* Expand an atomic compare and swap operation for HImode and QImode. MEM is
4783 the memory location, CMP the old value to compare MEM with and NEW_RTX the value
4784 to set if CMP == MEM.
4785 CMP is never in memory for compare_and_swap_cc because
4786 expand_bool_compare_and_swap puts it into a register for later compare. */
4789 s390_expand_cs_hqi (enum machine_mode mode
, rtx target
, rtx mem
, rtx cmp
, rtx new_rtx
)
4791 struct alignment_context ac
;
4792 rtx cmpv
, newv
, val
, resv
, cc
;
4793 rtx res
= gen_reg_rtx (SImode
);
4794 rtx csloop
= gen_label_rtx ();
4795 rtx csend
= gen_label_rtx ();
4797 gcc_assert (register_operand (target
, VOIDmode
));
4798 gcc_assert (MEM_P (mem
));
4800 init_alignment_context (&ac
, mem
, mode
);
4802 /* Shift the values to the correct bit positions. */
4803 if (!(ac
.aligned
&& MEM_P (cmp
)))
4804 cmp
= s390_expand_mask_and_shift (cmp
, mode
, ac
.shift
);
4805 if (!(ac
.aligned
&& MEM_P (new_rtx
)))
4806 new_rtx
= s390_expand_mask_and_shift (new_rtx
, mode
, ac
.shift
);
4808 /* Load full word. Subsequent loads are performed by CS. */
4809 val
= expand_simple_binop (SImode
, AND
, ac
.memsi
, ac
.modemaski
,
4810 NULL_RTX
, 1, OPTAB_DIRECT
);
4812 /* Start CS loop. */
4813 emit_label (csloop
);
4814 /* val = "<mem>00..0<mem>"
4815 * cmp = "00..0<cmp>00..0"
4816 * new = "00..0<new>00..0"
4819 /* Patch cmp and new with val at correct position. */
4820 if (ac
.aligned
&& MEM_P (cmp
))
4822 cmpv
= force_reg (SImode
, val
);
4823 store_bit_field (cmpv
, GET_MODE_BITSIZE (mode
), 0, SImode
, cmp
);
4826 cmpv
= force_reg (SImode
, expand_simple_binop (SImode
, IOR
, cmp
, val
,
4827 NULL_RTX
, 1, OPTAB_DIRECT
));
4828 if (ac
.aligned
&& MEM_P (new_rtx
))
4830 newv
= force_reg (SImode
, val
);
4831 store_bit_field (newv
, GET_MODE_BITSIZE (mode
), 0, SImode
, new_rtx
);
4834 newv
= force_reg (SImode
, expand_simple_binop (SImode
, IOR
, new_rtx
, val
,
4835 NULL_RTX
, 1, OPTAB_DIRECT
));
4837 /* Jump to end if we're done (likely?). */
4838 s390_emit_jump (csend
, s390_emit_compare_and_swap (EQ
, res
, ac
.memsi
,
4841 /* Check for changes outside mode. */
4842 resv
= expand_simple_binop (SImode
, AND
, res
, ac
.modemaski
,
4843 NULL_RTX
, 1, OPTAB_DIRECT
);
4844 cc
= s390_emit_compare (NE
, resv
, val
);
4845 emit_move_insn (val
, resv
);
4846 /* Loop internal if so. */
4847 s390_emit_jump (csloop
, cc
);
4851 /* Return the correct part of the bitfield. */
4852 convert_move (target
, expand_simple_binop (SImode
, LSHIFTRT
, res
, ac
.shift
,
4853 NULL_RTX
, 1, OPTAB_DIRECT
), 1);
4856 /* Expand an atomic operation CODE of mode MODE. MEM is the memory location
4857 and VAL the value to play with. If AFTER is true then store the value
4858 MEM holds after the operation, if AFTER is false then store the value MEM
4859 holds before the operation. If TARGET is zero then discard that value, else
4860 store it to TARGET. */
4863 s390_expand_atomic (enum machine_mode mode
, enum rtx_code code
,
4864 rtx target
, rtx mem
, rtx val
, bool after
)
4866 struct alignment_context ac
;
4868 rtx new_rtx
= gen_reg_rtx (SImode
);
4869 rtx orig
= gen_reg_rtx (SImode
);
4870 rtx csloop
= gen_label_rtx ();
4872 gcc_assert (!target
|| register_operand (target
, VOIDmode
));
4873 gcc_assert (MEM_P (mem
));
4875 init_alignment_context (&ac
, mem
, mode
);
4877 /* Shift val to the correct bit positions.
4878 Preserve "icm", but prevent "ex icm". */
4879 if (!(ac
.aligned
&& code
== SET
&& MEM_P (val
)))
4880 val
= s390_expand_mask_and_shift (val
, mode
, ac
.shift
);
4882 /* Further preparation insns. */
4883 if (code
== PLUS
|| code
== MINUS
)
4884 emit_move_insn (orig
, val
);
4885 else if (code
== MULT
|| code
== AND
) /* val = "11..1<val>11..1" */
4886 val
= expand_simple_binop (SImode
, XOR
, val
, ac
.modemaski
,
4887 NULL_RTX
, 1, OPTAB_DIRECT
);
4889 /* Load full word. Subsequent loads are performed by CS. */
4890 cmp
= force_reg (SImode
, ac
.memsi
);
4892 /* Start CS loop. */
4893 emit_label (csloop
);
4894 emit_move_insn (new_rtx
, cmp
);
4896 /* Patch new with val at correct position. */
4901 val
= expand_simple_binop (SImode
, code
, new_rtx
, orig
,
4902 NULL_RTX
, 1, OPTAB_DIRECT
);
4903 val
= expand_simple_binop (SImode
, AND
, val
, ac
.modemask
,
4904 NULL_RTX
, 1, OPTAB_DIRECT
);
4907 if (ac
.aligned
&& MEM_P (val
))
4908 store_bit_field (new_rtx
, GET_MODE_BITSIZE (mode
), 0, SImode
, val
);
4911 new_rtx
= expand_simple_binop (SImode
, AND
, new_rtx
, ac
.modemaski
,
4912 NULL_RTX
, 1, OPTAB_DIRECT
);
4913 new_rtx
= expand_simple_binop (SImode
, IOR
, new_rtx
, val
,
4914 NULL_RTX
, 1, OPTAB_DIRECT
);
4920 new_rtx
= expand_simple_binop (SImode
, code
, new_rtx
, val
,
4921 NULL_RTX
, 1, OPTAB_DIRECT
);
4923 case MULT
: /* NAND */
4924 new_rtx
= expand_simple_binop (SImode
, AND
, new_rtx
, val
,
4925 NULL_RTX
, 1, OPTAB_DIRECT
);
4926 new_rtx
= expand_simple_binop (SImode
, XOR
, new_rtx
, ac
.modemask
,
4927 NULL_RTX
, 1, OPTAB_DIRECT
);
4933 s390_emit_jump (csloop
, s390_emit_compare_and_swap (NE
, cmp
,
4934 ac
.memsi
, cmp
, new_rtx
));
4936 /* Return the correct part of the bitfield. */
4938 convert_move (target
, expand_simple_binop (SImode
, LSHIFTRT
,
4939 after
? new_rtx
: cmp
, ac
.shift
,
4940 NULL_RTX
, 1, OPTAB_DIRECT
), 1);
4943 /* This is called from dwarf2out.c via TARGET_ASM_OUTPUT_DWARF_DTPREL.
4944 We need to emit DTP-relative relocations. */
4946 static void s390_output_dwarf_dtprel (FILE *, int, rtx
) ATTRIBUTE_UNUSED
;
4949 s390_output_dwarf_dtprel (FILE *file
, int size
, rtx x
)
4954 fputs ("\t.long\t", file
);
4957 fputs ("\t.quad\t", file
);
4962 output_addr_const (file
, x
);
4963 fputs ("@DTPOFF", file
);
4966 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
4967 /* Implement TARGET_MANGLE_TYPE. */
4970 s390_mangle_type (const_tree type
)
4972 if (TYPE_MAIN_VARIANT (type
) == long_double_type_node
4973 && TARGET_LONG_DOUBLE_128
)
4976 /* For all other types, use normal C++ mangling. */
4981 /* In the name of slightly smaller debug output, and to cater to
4982 general assembler lossage, recognize various UNSPEC sequences
4983 and turn them back into a direct symbol reference. */
4986 s390_delegitimize_address (rtx orig_x
)
4990 orig_x
= delegitimize_mem_from_attrs (orig_x
);
4992 if (GET_CODE (x
) != MEM
)
4996 if (GET_CODE (x
) == PLUS
4997 && GET_CODE (XEXP (x
, 1)) == CONST
4998 && GET_CODE (XEXP (x
, 0)) == REG
4999 && REGNO (XEXP (x
, 0)) == PIC_OFFSET_TABLE_REGNUM
)
5001 y
= XEXP (XEXP (x
, 1), 0);
5002 if (GET_CODE (y
) == UNSPEC
5003 && XINT (y
, 1) == UNSPEC_GOT
)
5004 return XVECEXP (y
, 0, 0);
5008 if (GET_CODE (x
) == CONST
)
5011 if (GET_CODE (y
) == UNSPEC
5012 && XINT (y
, 1) == UNSPEC_GOTENT
)
5013 return XVECEXP (y
, 0, 0);
5020 /* Output operand OP to stdio stream FILE.
5021 OP is an address (register + offset) which is not used to address data;
5022 instead the rightmost bits are interpreted as the value. */
5025 print_shift_count_operand (FILE *file
, rtx op
)
5027 HOST_WIDE_INT offset
;
5030 /* Extract base register and offset. */
5031 if (!s390_decompose_shift_count (op
, &base
, &offset
))
5037 gcc_assert (GET_CODE (base
) == REG
);
5038 gcc_assert (REGNO (base
) < FIRST_PSEUDO_REGISTER
);
5039 gcc_assert (REGNO_REG_CLASS (REGNO (base
)) == ADDR_REGS
);
5042 /* Offsets are constricted to twelve bits. */
5043 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, offset
& ((1 << 12) - 1));
5045 fprintf (file
, "(%s)", reg_names
[REGNO (base
)]);
5048 /* See 'get_some_local_dynamic_name'. */
5051 get_some_local_dynamic_name_1 (rtx
*px
, void *data ATTRIBUTE_UNUSED
)
5055 if (GET_CODE (x
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (x
))
5057 x
= get_pool_constant (x
);
5058 return for_each_rtx (&x
, get_some_local_dynamic_name_1
, 0);
5061 if (GET_CODE (x
) == SYMBOL_REF
5062 && tls_symbolic_operand (x
) == TLS_MODEL_LOCAL_DYNAMIC
)
5064 cfun
->machine
->some_ld_name
= XSTR (x
, 0);
5071 /* Locate some local-dynamic symbol still in use by this function
5072 so that we can print its name in local-dynamic base patterns. */
5075 get_some_local_dynamic_name (void)
5079 if (cfun
->machine
->some_ld_name
)
5080 return cfun
->machine
->some_ld_name
;
5082 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5084 && for_each_rtx (&PATTERN (insn
), get_some_local_dynamic_name_1
, 0))
5085 return cfun
->machine
->some_ld_name
;
5090 /* Output machine-dependent UNSPECs occurring in address constant X
5091 in assembler syntax to stdio stream FILE. Returns true if the
5092 constant X could be recognized, false otherwise. */
5095 s390_output_addr_const_extra (FILE *file
, rtx x
)
5097 if (GET_CODE (x
) == UNSPEC
&& XVECLEN (x
, 0) == 1)
5098 switch (XINT (x
, 1))
5101 output_addr_const (file
, XVECEXP (x
, 0, 0));
5102 fprintf (file
, "@GOTENT");
5105 output_addr_const (file
, XVECEXP (x
, 0, 0));
5106 fprintf (file
, "@GOT");
5109 output_addr_const (file
, XVECEXP (x
, 0, 0));
5110 fprintf (file
, "@GOTOFF");
5113 output_addr_const (file
, XVECEXP (x
, 0, 0));
5114 fprintf (file
, "@PLT");
5117 output_addr_const (file
, XVECEXP (x
, 0, 0));
5118 fprintf (file
, "@PLTOFF");
5121 output_addr_const (file
, XVECEXP (x
, 0, 0));
5122 fprintf (file
, "@TLSGD");
5125 assemble_name (file
, get_some_local_dynamic_name ());
5126 fprintf (file
, "@TLSLDM");
5129 output_addr_const (file
, XVECEXP (x
, 0, 0));
5130 fprintf (file
, "@DTPOFF");
5133 output_addr_const (file
, XVECEXP (x
, 0, 0));
5134 fprintf (file
, "@NTPOFF");
5136 case UNSPEC_GOTNTPOFF
:
5137 output_addr_const (file
, XVECEXP (x
, 0, 0));
5138 fprintf (file
, "@GOTNTPOFF");
5140 case UNSPEC_INDNTPOFF
:
5141 output_addr_const (file
, XVECEXP (x
, 0, 0));
5142 fprintf (file
, "@INDNTPOFF");
5146 if (GET_CODE (x
) == UNSPEC
&& XVECLEN (x
, 0) == 2)
5147 switch (XINT (x
, 1))
5149 case UNSPEC_POOL_OFFSET
:
5150 x
= gen_rtx_MINUS (GET_MODE (x
), XVECEXP (x
, 0, 0), XVECEXP (x
, 0, 1));
5151 output_addr_const (file
, x
);
5157 /* Output address operand ADDR in assembler syntax to
5158 stdio stream FILE. */
5161 print_operand_address (FILE *file
, rtx addr
)
5163 struct s390_address ad
;
5165 if (s390_symref_operand_p (addr
, NULL
, NULL
))
5169 output_operand_lossage ("symbolic memory references are "
5170 "only supported on z10 or later");
5173 output_addr_const (file
, addr
);
5177 if (!s390_decompose_address (addr
, &ad
)
5178 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
5179 || (ad
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (ad
.indx
))))
5180 output_operand_lossage ("cannot decompose address");
5183 output_addr_const (file
, ad
.disp
);
5185 fprintf (file
, "0");
5187 if (ad
.base
&& ad
.indx
)
5188 fprintf (file
, "(%s,%s)", reg_names
[REGNO (ad
.indx
)],
5189 reg_names
[REGNO (ad
.base
)]);
5191 fprintf (file
, "(%s)", reg_names
[REGNO (ad
.base
)]);
5194 /* Output operand X in assembler syntax to stdio stream FILE.
5195 CODE specified the format flag. The following format flags
5198 'C': print opcode suffix for branch condition.
5199 'D': print opcode suffix for inverse branch condition.
5200 'E': print opcode suffix for branch on index instruction.
5201 'J': print tls_load/tls_gdcall/tls_ldcall suffix
5202 'G': print the size of the operand in bytes.
5203 'O': print only the displacement of a memory reference.
5204 'R': print only the base register of a memory reference.
5205 'S': print S-type memory reference (base+displacement).
5206 'N': print the second word of a DImode operand.
5207 'M': print the second word of a TImode operand.
5208 'Y': print shift count operand.
5210 'b': print integer X as if it's an unsigned byte.
5211 'c': print integer X as if it's an signed byte.
5212 'x': print integer X as if it's an unsigned halfword.
5213 'h': print integer X as if it's a signed halfword.
5214 'i': print the first nonzero HImode part of X.
5215 'j': print the first HImode part unequal to -1 of X.
5216 'k': print the first nonzero SImode part of X.
5217 'm': print the first SImode part unequal to -1 of X.
5218 'o': print integer X as if it's an unsigned 32bit word. */
5221 print_operand (FILE *file
, rtx x
, int code
)
5226 fprintf (file
, s390_branch_condition_mnemonic (x
, FALSE
));
5230 fprintf (file
, s390_branch_condition_mnemonic (x
, TRUE
));
5234 if (GET_CODE (x
) == LE
)
5235 fprintf (file
, "l");
5236 else if (GET_CODE (x
) == GT
)
5237 fprintf (file
, "h");
5239 output_operand_lossage ("invalid comparison operator "
5240 "for 'E' output modifier");
5244 if (GET_CODE (x
) == SYMBOL_REF
)
5246 fprintf (file
, "%s", ":tls_load:");
5247 output_addr_const (file
, x
);
5249 else if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_TLSGD
)
5251 fprintf (file
, "%s", ":tls_gdcall:");
5252 output_addr_const (file
, XVECEXP (x
, 0, 0));
5254 else if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_TLSLDM
)
5256 fprintf (file
, "%s", ":tls_ldcall:");
5257 assemble_name (file
, get_some_local_dynamic_name ());
5260 output_operand_lossage ("invalid reference for 'J' output modifier");
5264 fprintf (file
, "%u", GET_MODE_SIZE (GET_MODE (x
)));
5269 struct s390_address ad
;
5274 output_operand_lossage ("memory reference expected for "
5275 "'O' output modifier");
5279 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
5282 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
5285 output_operand_lossage ("invalid address for 'O' output modifier");
5290 output_addr_const (file
, ad
.disp
);
5292 fprintf (file
, "0");
5298 struct s390_address ad
;
5303 output_operand_lossage ("memory reference expected for "
5304 "'R' output modifier");
5308 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
5311 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
5314 output_operand_lossage ("invalid address for 'R' output modifier");
5319 fprintf (file
, "%s", reg_names
[REGNO (ad
.base
)]);
5321 fprintf (file
, "0");
5327 struct s390_address ad
;
5332 output_operand_lossage ("memory reference expected for "
5333 "'S' output modifier");
5336 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
5339 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
5342 output_operand_lossage ("invalid address for 'S' output modifier");
5347 output_addr_const (file
, ad
.disp
);
5349 fprintf (file
, "0");
5352 fprintf (file
, "(%s)", reg_names
[REGNO (ad
.base
)]);
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), 4));
5362 output_operand_lossage ("register or memory expression expected "
5363 "for 'N' output modifier");
5367 if (GET_CODE (x
) == REG
)
5368 x
= gen_rtx_REG (GET_MODE (x
), REGNO (x
) + 1);
5369 else if (GET_CODE (x
) == MEM
)
5370 x
= change_address (x
, VOIDmode
, plus_constant (XEXP (x
, 0), 8));
5372 output_operand_lossage ("register or memory expression expected "
5373 "for 'M' output modifier");
5377 print_shift_count_operand (file
, x
);
5381 switch (GET_CODE (x
))
5384 fprintf (file
, "%s", reg_names
[REGNO (x
)]);
5388 output_address (XEXP (x
, 0));
5395 output_addr_const (file
, x
);
5400 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
) & 0xff);
5401 else if (code
== 'c')
5402 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, ((INTVAL (x
) & 0xff) ^ 0x80) - 0x80);
5403 else if (code
== 'x')
5404 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
) & 0xffff);
5405 else if (code
== 'h')
5406 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, ((INTVAL (x
) & 0xffff) ^ 0x8000) - 0x8000);
5407 else if (code
== 'i')
5408 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
5409 s390_extract_part (x
, HImode
, 0));
5410 else if (code
== 'j')
5411 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
5412 s390_extract_part (x
, HImode
, -1));
5413 else if (code
== 'k')
5414 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
5415 s390_extract_part (x
, SImode
, 0));
5416 else if (code
== 'm')
5417 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
5418 s390_extract_part (x
, SImode
, -1));
5419 else if (code
== 'o')
5420 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
) & 0xffffffff);
5422 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
));
5426 gcc_assert (GET_MODE (x
) == VOIDmode
);
5428 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, CONST_DOUBLE_LOW (x
) & 0xff);
5429 else if (code
== 'x')
5430 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, CONST_DOUBLE_LOW (x
) & 0xffff);
5431 else if (code
== 'h')
5432 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
5433 ((CONST_DOUBLE_LOW (x
) & 0xffff) ^ 0x8000) - 0x8000);
5437 output_operand_lossage ("invalid constant - try using "
5438 "an output modifier");
5440 output_operand_lossage ("invalid constant for output modifier '%c'",
5447 output_operand_lossage ("invalid expression - try using "
5448 "an output modifier");
5450 output_operand_lossage ("invalid expression for output "
5451 "modifier '%c'", code
);
5456 /* Target hook for assembling integer objects. We need to define it
5457 here to work a round a bug in some versions of GAS, which couldn't
5458 handle values smaller than INT_MIN when printed in decimal. */
5461 s390_assemble_integer (rtx x
, unsigned int size
, int aligned_p
)
5463 if (size
== 8 && aligned_p
5464 && GET_CODE (x
) == CONST_INT
&& INTVAL (x
) < INT_MIN
)
5466 fprintf (asm_out_file
, "\t.quad\t" HOST_WIDE_INT_PRINT_HEX
"\n",
5470 return default_assemble_integer (x
, size
, aligned_p
);
5473 /* Returns true if register REGNO is used for forming
5474 a memory address in expression X. */
5477 reg_used_in_mem_p (int regno
, rtx x
)
5479 enum rtx_code code
= GET_CODE (x
);
5485 if (refers_to_regno_p (regno
, regno
+1,
5489 else if (code
== SET
5490 && GET_CODE (SET_DEST (x
)) == PC
)
5492 if (refers_to_regno_p (regno
, regno
+1,
5497 fmt
= GET_RTX_FORMAT (code
);
5498 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
5501 && reg_used_in_mem_p (regno
, XEXP (x
, i
)))
5504 else if (fmt
[i
] == 'E')
5505 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
5506 if (reg_used_in_mem_p (regno
, XVECEXP (x
, i
, j
)))
5512 /* Returns true if expression DEP_RTX sets an address register
5513 used by instruction INSN to address memory. */
5516 addr_generation_dependency_p (rtx dep_rtx
, rtx insn
)
5520 if (GET_CODE (dep_rtx
) == INSN
)
5521 dep_rtx
= PATTERN (dep_rtx
);
5523 if (GET_CODE (dep_rtx
) == SET
)
5525 target
= SET_DEST (dep_rtx
);
5526 if (GET_CODE (target
) == STRICT_LOW_PART
)
5527 target
= XEXP (target
, 0);
5528 while (GET_CODE (target
) == SUBREG
)
5529 target
= SUBREG_REG (target
);
5531 if (GET_CODE (target
) == REG
)
5533 int regno
= REGNO (target
);
5535 if (s390_safe_attr_type (insn
) == TYPE_LA
)
5537 pat
= PATTERN (insn
);
5538 if (GET_CODE (pat
) == PARALLEL
)
5540 gcc_assert (XVECLEN (pat
, 0) == 2);
5541 pat
= XVECEXP (pat
, 0, 0);
5543 gcc_assert (GET_CODE (pat
) == SET
);
5544 return refers_to_regno_p (regno
, regno
+1, SET_SRC (pat
), 0);
5546 else if (get_attr_atype (insn
) == ATYPE_AGEN
)
5547 return reg_used_in_mem_p (regno
, PATTERN (insn
));
5553 /* Return 1, if dep_insn sets register used in insn in the agen unit. */
5556 s390_agen_dep_p (rtx dep_insn
, rtx insn
)
5558 rtx dep_rtx
= PATTERN (dep_insn
);
5561 if (GET_CODE (dep_rtx
) == SET
5562 && addr_generation_dependency_p (dep_rtx
, insn
))
5564 else if (GET_CODE (dep_rtx
) == PARALLEL
)
5566 for (i
= 0; i
< XVECLEN (dep_rtx
, 0); i
++)
5568 if (addr_generation_dependency_p (XVECEXP (dep_rtx
, 0, i
), insn
))
5576 /* A C statement (sans semicolon) to update the integer scheduling priority
5577 INSN_PRIORITY (INSN). Increase the priority to execute the INSN earlier,
5578 reduce the priority to execute INSN later. Do not define this macro if
5579 you do not need to adjust the scheduling priorities of insns.
5581 A STD instruction should be scheduled earlier,
5582 in order to use the bypass. */
5584 s390_adjust_priority (rtx insn ATTRIBUTE_UNUSED
, int priority
)
5586 if (! INSN_P (insn
))
5589 if (s390_tune
!= PROCESSOR_2084_Z990
5590 && s390_tune
!= PROCESSOR_2094_Z9_109
5591 && s390_tune
!= PROCESSOR_2097_Z10
5592 && s390_tune
!= PROCESSOR_2817_Z196
)
5595 switch (s390_safe_attr_type (insn
))
5599 priority
= priority
<< 3;
5603 priority
= priority
<< 1;
5612 /* The number of instructions that can be issued per cycle. */
5615 s390_issue_rate (void)
5619 case PROCESSOR_2084_Z990
:
5620 case PROCESSOR_2094_Z9_109
:
5621 case PROCESSOR_2817_Z196
:
5623 case PROCESSOR_2097_Z10
:
5631 s390_first_cycle_multipass_dfa_lookahead (void)
5636 /* Annotate every literal pool reference in X by an UNSPEC_LTREF expression.
5637 Fix up MEMs as required. */
5640 annotate_constant_pool_refs (rtx
*x
)
5645 gcc_assert (GET_CODE (*x
) != SYMBOL_REF
5646 || !CONSTANT_POOL_ADDRESS_P (*x
));
5648 /* Literal pool references can only occur inside a MEM ... */
5649 if (GET_CODE (*x
) == MEM
)
5651 rtx memref
= XEXP (*x
, 0);
5653 if (GET_CODE (memref
) == SYMBOL_REF
5654 && CONSTANT_POOL_ADDRESS_P (memref
))
5656 rtx base
= cfun
->machine
->base_reg
;
5657 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, memref
, base
),
5660 *x
= replace_equiv_address (*x
, addr
);
5664 if (GET_CODE (memref
) == CONST
5665 && GET_CODE (XEXP (memref
, 0)) == PLUS
5666 && GET_CODE (XEXP (XEXP (memref
, 0), 1)) == CONST_INT
5667 && GET_CODE (XEXP (XEXP (memref
, 0), 0)) == SYMBOL_REF
5668 && CONSTANT_POOL_ADDRESS_P (XEXP (XEXP (memref
, 0), 0)))
5670 HOST_WIDE_INT off
= INTVAL (XEXP (XEXP (memref
, 0), 1));
5671 rtx sym
= XEXP (XEXP (memref
, 0), 0);
5672 rtx base
= cfun
->machine
->base_reg
;
5673 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, sym
, base
),
5676 *x
= replace_equiv_address (*x
, plus_constant (addr
, off
));
5681 /* ... or a load-address type pattern. */
5682 if (GET_CODE (*x
) == SET
)
5684 rtx addrref
= SET_SRC (*x
);
5686 if (GET_CODE (addrref
) == SYMBOL_REF
5687 && CONSTANT_POOL_ADDRESS_P (addrref
))
5689 rtx base
= cfun
->machine
->base_reg
;
5690 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, addrref
, base
),
5693 SET_SRC (*x
) = addr
;
5697 if (GET_CODE (addrref
) == CONST
5698 && GET_CODE (XEXP (addrref
, 0)) == PLUS
5699 && GET_CODE (XEXP (XEXP (addrref
, 0), 1)) == CONST_INT
5700 && GET_CODE (XEXP (XEXP (addrref
, 0), 0)) == SYMBOL_REF
5701 && CONSTANT_POOL_ADDRESS_P (XEXP (XEXP (addrref
, 0), 0)))
5703 HOST_WIDE_INT off
= INTVAL (XEXP (XEXP (addrref
, 0), 1));
5704 rtx sym
= XEXP (XEXP (addrref
, 0), 0);
5705 rtx base
= cfun
->machine
->base_reg
;
5706 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, sym
, base
),
5709 SET_SRC (*x
) = plus_constant (addr
, off
);
5714 /* Annotate LTREL_BASE as well. */
5715 if (GET_CODE (*x
) == UNSPEC
5716 && XINT (*x
, 1) == UNSPEC_LTREL_BASE
)
5718 rtx base
= cfun
->machine
->base_reg
;
5719 *x
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, XVECEXP (*x
, 0, 0), base
),
5724 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
5725 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
5729 annotate_constant_pool_refs (&XEXP (*x
, i
));
5731 else if (fmt
[i
] == 'E')
5733 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
5734 annotate_constant_pool_refs (&XVECEXP (*x
, i
, j
));
5739 /* Split all branches that exceed the maximum distance.
5740 Returns true if this created a new literal pool entry. */
5743 s390_split_branches (void)
5745 rtx temp_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
5746 int new_literal
= 0, ret
;
5747 rtx insn
, pat
, tmp
, target
;
5750 /* We need correct insn addresses. */
5752 shorten_branches (get_insns ());
5754 /* Find all branches that exceed 64KB, and split them. */
5756 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5758 if (GET_CODE (insn
) != JUMP_INSN
)
5761 pat
= PATTERN (insn
);
5762 if (GET_CODE (pat
) == PARALLEL
&& XVECLEN (pat
, 0) > 2)
5763 pat
= XVECEXP (pat
, 0, 0);
5764 if (GET_CODE (pat
) != SET
|| SET_DEST (pat
) != pc_rtx
)
5767 if (GET_CODE (SET_SRC (pat
)) == LABEL_REF
)
5769 label
= &SET_SRC (pat
);
5771 else if (GET_CODE (SET_SRC (pat
)) == IF_THEN_ELSE
)
5773 if (GET_CODE (XEXP (SET_SRC (pat
), 1)) == LABEL_REF
)
5774 label
= &XEXP (SET_SRC (pat
), 1);
5775 else if (GET_CODE (XEXP (SET_SRC (pat
), 2)) == LABEL_REF
)
5776 label
= &XEXP (SET_SRC (pat
), 2);
5783 if (get_attr_length (insn
) <= 4)
5786 /* We are going to use the return register as scratch register,
5787 make sure it will be saved/restored by the prologue/epilogue. */
5788 cfun_frame_layout
.save_return_addr_p
= 1;
5793 tmp
= force_const_mem (Pmode
, *label
);
5794 tmp
= emit_insn_before (gen_rtx_SET (Pmode
, temp_reg
, tmp
), insn
);
5795 INSN_ADDRESSES_NEW (tmp
, -1);
5796 annotate_constant_pool_refs (&PATTERN (tmp
));
5803 target
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, *label
),
5804 UNSPEC_LTREL_OFFSET
);
5805 target
= gen_rtx_CONST (Pmode
, target
);
5806 target
= force_const_mem (Pmode
, target
);
5807 tmp
= emit_insn_before (gen_rtx_SET (Pmode
, temp_reg
, target
), insn
);
5808 INSN_ADDRESSES_NEW (tmp
, -1);
5809 annotate_constant_pool_refs (&PATTERN (tmp
));
5811 target
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, XEXP (target
, 0),
5812 cfun
->machine
->base_reg
),
5814 target
= gen_rtx_PLUS (Pmode
, temp_reg
, target
);
5817 ret
= validate_change (insn
, label
, target
, 0);
5825 /* Find an annotated literal pool symbol referenced in RTX X,
5826 and store it at REF. Will abort if X contains references to
5827 more than one such pool symbol; multiple references to the same
5828 symbol are allowed, however.
5830 The rtx pointed to by REF must be initialized to NULL_RTX
5831 by the caller before calling this routine. */
5834 find_constant_pool_ref (rtx x
, rtx
*ref
)
5839 /* Ignore LTREL_BASE references. */
5840 if (GET_CODE (x
) == UNSPEC
5841 && XINT (x
, 1) == UNSPEC_LTREL_BASE
)
5843 /* Likewise POOL_ENTRY insns. */
5844 if (GET_CODE (x
) == UNSPEC_VOLATILE
5845 && XINT (x
, 1) == UNSPECV_POOL_ENTRY
)
5848 gcc_assert (GET_CODE (x
) != SYMBOL_REF
5849 || !CONSTANT_POOL_ADDRESS_P (x
));
5851 if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_LTREF
)
5853 rtx sym
= XVECEXP (x
, 0, 0);
5854 gcc_assert (GET_CODE (sym
) == SYMBOL_REF
5855 && CONSTANT_POOL_ADDRESS_P (sym
));
5857 if (*ref
== NULL_RTX
)
5860 gcc_assert (*ref
== sym
);
5865 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
5866 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
5870 find_constant_pool_ref (XEXP (x
, i
), ref
);
5872 else if (fmt
[i
] == 'E')
5874 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
5875 find_constant_pool_ref (XVECEXP (x
, i
, j
), ref
);
5880 /* Replace every reference to the annotated literal pool
5881 symbol REF in X by its base plus OFFSET. */
5884 replace_constant_pool_ref (rtx
*x
, rtx ref
, rtx offset
)
5889 gcc_assert (*x
!= ref
);
5891 if (GET_CODE (*x
) == UNSPEC
5892 && XINT (*x
, 1) == UNSPEC_LTREF
5893 && XVECEXP (*x
, 0, 0) == ref
)
5895 *x
= gen_rtx_PLUS (Pmode
, XVECEXP (*x
, 0, 1), offset
);
5899 if (GET_CODE (*x
) == PLUS
5900 && GET_CODE (XEXP (*x
, 1)) == CONST_INT
5901 && GET_CODE (XEXP (*x
, 0)) == UNSPEC
5902 && XINT (XEXP (*x
, 0), 1) == UNSPEC_LTREF
5903 && XVECEXP (XEXP (*x
, 0), 0, 0) == ref
)
5905 rtx addr
= gen_rtx_PLUS (Pmode
, XVECEXP (XEXP (*x
, 0), 0, 1), offset
);
5906 *x
= plus_constant (addr
, INTVAL (XEXP (*x
, 1)));
5910 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
5911 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
5915 replace_constant_pool_ref (&XEXP (*x
, i
), ref
, offset
);
5917 else if (fmt
[i
] == 'E')
5919 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
5920 replace_constant_pool_ref (&XVECEXP (*x
, i
, j
), ref
, offset
);
5925 /* Check whether X contains an UNSPEC_LTREL_BASE.
5926 Return its constant pool symbol if found, NULL_RTX otherwise. */
5929 find_ltrel_base (rtx x
)
5934 if (GET_CODE (x
) == UNSPEC
5935 && XINT (x
, 1) == UNSPEC_LTREL_BASE
)
5936 return XVECEXP (x
, 0, 0);
5938 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
5939 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
5943 rtx fnd
= find_ltrel_base (XEXP (x
, i
));
5947 else if (fmt
[i
] == 'E')
5949 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
5951 rtx fnd
= find_ltrel_base (XVECEXP (x
, i
, j
));
5961 /* Replace any occurrence of UNSPEC_LTREL_BASE in X with its base. */
5964 replace_ltrel_base (rtx
*x
)
5969 if (GET_CODE (*x
) == UNSPEC
5970 && XINT (*x
, 1) == UNSPEC_LTREL_BASE
)
5972 *x
= XVECEXP (*x
, 0, 1);
5976 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
5977 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
5981 replace_ltrel_base (&XEXP (*x
, i
));
5983 else if (fmt
[i
] == 'E')
5985 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
5986 replace_ltrel_base (&XVECEXP (*x
, i
, j
));
5992 /* We keep a list of constants which we have to add to internal
5993 constant tables in the middle of large functions. */
5995 #define NR_C_MODES 11
5996 enum machine_mode constant_modes
[NR_C_MODES
] =
5998 TFmode
, TImode
, TDmode
,
5999 DFmode
, DImode
, DDmode
,
6000 SFmode
, SImode
, SDmode
,
6007 struct constant
*next
;
6012 struct constant_pool
6014 struct constant_pool
*next
;
6018 rtx emit_pool_after
;
6020 struct constant
*constants
[NR_C_MODES
];
6021 struct constant
*execute
;
6026 /* Allocate new constant_pool structure. */
6028 static struct constant_pool
*
6029 s390_alloc_pool (void)
6031 struct constant_pool
*pool
;
6034 pool
= (struct constant_pool
*) xmalloc (sizeof *pool
);
6036 for (i
= 0; i
< NR_C_MODES
; i
++)
6037 pool
->constants
[i
] = NULL
;
6039 pool
->execute
= NULL
;
6040 pool
->label
= gen_label_rtx ();
6041 pool
->first_insn
= NULL_RTX
;
6042 pool
->pool_insn
= NULL_RTX
;
6043 pool
->insns
= BITMAP_ALLOC (NULL
);
6045 pool
->emit_pool_after
= NULL_RTX
;
6050 /* Create new constant pool covering instructions starting at INSN
6051 and chain it to the end of POOL_LIST. */
6053 static struct constant_pool
*
6054 s390_start_pool (struct constant_pool
**pool_list
, rtx insn
)
6056 struct constant_pool
*pool
, **prev
;
6058 pool
= s390_alloc_pool ();
6059 pool
->first_insn
= insn
;
6061 for (prev
= pool_list
; *prev
; prev
= &(*prev
)->next
)
6068 /* End range of instructions covered by POOL at INSN and emit
6069 placeholder insn representing the pool. */
6072 s390_end_pool (struct constant_pool
*pool
, rtx insn
)
6074 rtx pool_size
= GEN_INT (pool
->size
+ 8 /* alignment slop */);
6077 insn
= get_last_insn ();
6079 pool
->pool_insn
= emit_insn_after (gen_pool (pool_size
), insn
);
6080 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
6083 /* Add INSN to the list of insns covered by POOL. */
6086 s390_add_pool_insn (struct constant_pool
*pool
, rtx insn
)
6088 bitmap_set_bit (pool
->insns
, INSN_UID (insn
));
6091 /* Return pool out of POOL_LIST that covers INSN. */
6093 static struct constant_pool
*
6094 s390_find_pool (struct constant_pool
*pool_list
, rtx insn
)
6096 struct constant_pool
*pool
;
6098 for (pool
= pool_list
; pool
; pool
= pool
->next
)
6099 if (bitmap_bit_p (pool
->insns
, INSN_UID (insn
)))
6105 /* Add constant VAL of mode MODE to the constant pool POOL. */
6108 s390_add_constant (struct constant_pool
*pool
, rtx val
, enum machine_mode mode
)
6113 for (i
= 0; i
< NR_C_MODES
; i
++)
6114 if (constant_modes
[i
] == mode
)
6116 gcc_assert (i
!= NR_C_MODES
);
6118 for (c
= pool
->constants
[i
]; c
!= NULL
; c
= c
->next
)
6119 if (rtx_equal_p (val
, c
->value
))
6124 c
= (struct constant
*) xmalloc (sizeof *c
);
6126 c
->label
= gen_label_rtx ();
6127 c
->next
= pool
->constants
[i
];
6128 pool
->constants
[i
] = c
;
6129 pool
->size
+= GET_MODE_SIZE (mode
);
6133 /* Return an rtx that represents the offset of X from the start of
6137 s390_pool_offset (struct constant_pool
*pool
, rtx x
)
6141 label
= gen_rtx_LABEL_REF (GET_MODE (x
), pool
->label
);
6142 x
= gen_rtx_UNSPEC (GET_MODE (x
), gen_rtvec (2, x
, label
),
6143 UNSPEC_POOL_OFFSET
);
6144 return gen_rtx_CONST (GET_MODE (x
), x
);
6147 /* Find constant VAL of mode MODE in the constant pool POOL.
6148 Return an RTX describing the distance from the start of
6149 the pool to the location of the new constant. */
6152 s390_find_constant (struct constant_pool
*pool
, rtx val
,
6153 enum machine_mode mode
)
6158 for (i
= 0; i
< NR_C_MODES
; i
++)
6159 if (constant_modes
[i
] == mode
)
6161 gcc_assert (i
!= NR_C_MODES
);
6163 for (c
= pool
->constants
[i
]; c
!= NULL
; c
= c
->next
)
6164 if (rtx_equal_p (val
, c
->value
))
6169 return s390_pool_offset (pool
, gen_rtx_LABEL_REF (Pmode
, c
->label
));
6172 /* Check whether INSN is an execute. Return the label_ref to its
6173 execute target template if so, NULL_RTX otherwise. */
6176 s390_execute_label (rtx insn
)
6178 if (GET_CODE (insn
) == INSN
6179 && GET_CODE (PATTERN (insn
)) == PARALLEL
6180 && GET_CODE (XVECEXP (PATTERN (insn
), 0, 0)) == UNSPEC
6181 && XINT (XVECEXP (PATTERN (insn
), 0, 0), 1) == UNSPEC_EXECUTE
)
6182 return XVECEXP (XVECEXP (PATTERN (insn
), 0, 0), 0, 2);
6187 /* Add execute target for INSN to the constant pool POOL. */
6190 s390_add_execute (struct constant_pool
*pool
, rtx insn
)
6194 for (c
= pool
->execute
; c
!= NULL
; c
= c
->next
)
6195 if (INSN_UID (insn
) == INSN_UID (c
->value
))
6200 c
= (struct constant
*) xmalloc (sizeof *c
);
6202 c
->label
= gen_label_rtx ();
6203 c
->next
= pool
->execute
;
6209 /* Find execute target for INSN in the constant pool POOL.
6210 Return an RTX describing the distance from the start of
6211 the pool to the location of the execute target. */
6214 s390_find_execute (struct constant_pool
*pool
, rtx insn
)
6218 for (c
= pool
->execute
; c
!= NULL
; c
= c
->next
)
6219 if (INSN_UID (insn
) == INSN_UID (c
->value
))
6224 return s390_pool_offset (pool
, gen_rtx_LABEL_REF (Pmode
, c
->label
));
6227 /* For an execute INSN, extract the execute target template. */
6230 s390_execute_target (rtx insn
)
6232 rtx pattern
= PATTERN (insn
);
6233 gcc_assert (s390_execute_label (insn
));
6235 if (XVECLEN (pattern
, 0) == 2)
6237 pattern
= copy_rtx (XVECEXP (pattern
, 0, 1));
6241 rtvec vec
= rtvec_alloc (XVECLEN (pattern
, 0) - 1);
6244 for (i
= 0; i
< XVECLEN (pattern
, 0) - 1; i
++)
6245 RTVEC_ELT (vec
, i
) = copy_rtx (XVECEXP (pattern
, 0, i
+ 1));
6247 pattern
= gen_rtx_PARALLEL (VOIDmode
, vec
);
6253 /* Indicate that INSN cannot be duplicated. This is the case for
6254 execute insns that carry a unique label. */
6257 s390_cannot_copy_insn_p (rtx insn
)
6259 rtx label
= s390_execute_label (insn
);
6260 return label
&& label
!= const0_rtx
;
6263 /* Dump out the constants in POOL. If REMOTE_LABEL is true,
6264 do not emit the pool base label. */
6267 s390_dump_pool (struct constant_pool
*pool
, bool remote_label
)
6270 rtx insn
= pool
->pool_insn
;
6273 /* Switch to rodata section. */
6274 if (TARGET_CPU_ZARCH
)
6276 insn
= emit_insn_after (gen_pool_section_start (), insn
);
6277 INSN_ADDRESSES_NEW (insn
, -1);
6280 /* Ensure minimum pool alignment. */
6281 if (TARGET_CPU_ZARCH
)
6282 insn
= emit_insn_after (gen_pool_align (GEN_INT (8)), insn
);
6284 insn
= emit_insn_after (gen_pool_align (GEN_INT (4)), insn
);
6285 INSN_ADDRESSES_NEW (insn
, -1);
6287 /* Emit pool base label. */
6290 insn
= emit_label_after (pool
->label
, insn
);
6291 INSN_ADDRESSES_NEW (insn
, -1);
6294 /* Dump constants in descending alignment requirement order,
6295 ensuring proper alignment for every constant. */
6296 for (i
= 0; i
< NR_C_MODES
; i
++)
6297 for (c
= pool
->constants
[i
]; c
; c
= c
->next
)
6299 /* Convert UNSPEC_LTREL_OFFSET unspecs to pool-relative references. */
6300 rtx value
= copy_rtx (c
->value
);
6301 if (GET_CODE (value
) == CONST
6302 && GET_CODE (XEXP (value
, 0)) == UNSPEC
6303 && XINT (XEXP (value
, 0), 1) == UNSPEC_LTREL_OFFSET
6304 && XVECLEN (XEXP (value
, 0), 0) == 1)
6305 value
= s390_pool_offset (pool
, XVECEXP (XEXP (value
, 0), 0, 0));
6307 insn
= emit_label_after (c
->label
, insn
);
6308 INSN_ADDRESSES_NEW (insn
, -1);
6310 value
= gen_rtx_UNSPEC_VOLATILE (constant_modes
[i
],
6311 gen_rtvec (1, value
),
6312 UNSPECV_POOL_ENTRY
);
6313 insn
= emit_insn_after (value
, insn
);
6314 INSN_ADDRESSES_NEW (insn
, -1);
6317 /* Ensure minimum alignment for instructions. */
6318 insn
= emit_insn_after (gen_pool_align (GEN_INT (2)), insn
);
6319 INSN_ADDRESSES_NEW (insn
, -1);
6321 /* Output in-pool execute template insns. */
6322 for (c
= pool
->execute
; c
; c
= c
->next
)
6324 insn
= emit_label_after (c
->label
, insn
);
6325 INSN_ADDRESSES_NEW (insn
, -1);
6327 insn
= emit_insn_after (s390_execute_target (c
->value
), insn
);
6328 INSN_ADDRESSES_NEW (insn
, -1);
6331 /* Switch back to previous section. */
6332 if (TARGET_CPU_ZARCH
)
6334 insn
= emit_insn_after (gen_pool_section_end (), insn
);
6335 INSN_ADDRESSES_NEW (insn
, -1);
6338 insn
= emit_barrier_after (insn
);
6339 INSN_ADDRESSES_NEW (insn
, -1);
6341 /* Remove placeholder insn. */
6342 remove_insn (pool
->pool_insn
);
6345 /* Free all memory used by POOL. */
6348 s390_free_pool (struct constant_pool
*pool
)
6350 struct constant
*c
, *next
;
6353 for (i
= 0; i
< NR_C_MODES
; i
++)
6354 for (c
= pool
->constants
[i
]; c
; c
= next
)
6360 for (c
= pool
->execute
; c
; c
= next
)
6366 BITMAP_FREE (pool
->insns
);
6371 /* Collect main literal pool. Return NULL on overflow. */
6373 static struct constant_pool
*
6374 s390_mainpool_start (void)
6376 struct constant_pool
*pool
;
6379 pool
= s390_alloc_pool ();
6381 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6383 if (GET_CODE (insn
) == INSN
6384 && GET_CODE (PATTERN (insn
)) == SET
6385 && GET_CODE (SET_SRC (PATTERN (insn
))) == UNSPEC_VOLATILE
6386 && XINT (SET_SRC (PATTERN (insn
)), 1) == UNSPECV_MAIN_POOL
)
6388 gcc_assert (!pool
->pool_insn
);
6389 pool
->pool_insn
= insn
;
6392 if (!TARGET_CPU_ZARCH
&& s390_execute_label (insn
))
6394 s390_add_execute (pool
, insn
);
6396 else if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
6398 rtx pool_ref
= NULL_RTX
;
6399 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
6402 rtx constant
= get_pool_constant (pool_ref
);
6403 enum machine_mode mode
= get_pool_mode (pool_ref
);
6404 s390_add_constant (pool
, constant
, mode
);
6408 /* If hot/cold partitioning is enabled we have to make sure that
6409 the literal pool is emitted in the same section where the
6410 initialization of the literal pool base pointer takes place.
6411 emit_pool_after is only used in the non-overflow case on non
6412 Z cpus where we can emit the literal pool at the end of the
6413 function body within the text section. */
6415 && NOTE_KIND (insn
) == NOTE_INSN_SWITCH_TEXT_SECTIONS
6416 && !pool
->emit_pool_after
)
6417 pool
->emit_pool_after
= PREV_INSN (insn
);
6420 gcc_assert (pool
->pool_insn
|| pool
->size
== 0);
6422 if (pool
->size
>= 4096)
6424 /* We're going to chunkify the pool, so remove the main
6425 pool placeholder insn. */
6426 remove_insn (pool
->pool_insn
);
6428 s390_free_pool (pool
);
6432 /* If the functions ends with the section where the literal pool
6433 should be emitted set the marker to its end. */
6434 if (pool
&& !pool
->emit_pool_after
)
6435 pool
->emit_pool_after
= get_last_insn ();
6440 /* POOL holds the main literal pool as collected by s390_mainpool_start.
6441 Modify the current function to output the pool constants as well as
6442 the pool register setup instruction. */
6445 s390_mainpool_finish (struct constant_pool
*pool
)
6447 rtx base_reg
= cfun
->machine
->base_reg
;
6450 /* If the pool is empty, we're done. */
6451 if (pool
->size
== 0)
6453 /* We don't actually need a base register after all. */
6454 cfun
->machine
->base_reg
= NULL_RTX
;
6456 if (pool
->pool_insn
)
6457 remove_insn (pool
->pool_insn
);
6458 s390_free_pool (pool
);
6462 /* We need correct insn addresses. */
6463 shorten_branches (get_insns ());
6465 /* On zSeries, we use a LARL to load the pool register. The pool is
6466 located in the .rodata section, so we emit it after the function. */
6467 if (TARGET_CPU_ZARCH
)
6469 insn
= gen_main_base_64 (base_reg
, pool
->label
);
6470 insn
= emit_insn_after (insn
, pool
->pool_insn
);
6471 INSN_ADDRESSES_NEW (insn
, -1);
6472 remove_insn (pool
->pool_insn
);
6474 insn
= get_last_insn ();
6475 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
6476 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
6478 s390_dump_pool (pool
, 0);
6481 /* On S/390, if the total size of the function's code plus literal pool
6482 does not exceed 4096 bytes, we use BASR to set up a function base
6483 pointer, and emit the literal pool at the end of the function. */
6484 else if (INSN_ADDRESSES (INSN_UID (pool
->emit_pool_after
))
6485 + pool
->size
+ 8 /* alignment slop */ < 4096)
6487 insn
= gen_main_base_31_small (base_reg
, pool
->label
);
6488 insn
= emit_insn_after (insn
, pool
->pool_insn
);
6489 INSN_ADDRESSES_NEW (insn
, -1);
6490 remove_insn (pool
->pool_insn
);
6492 insn
= emit_label_after (pool
->label
, insn
);
6493 INSN_ADDRESSES_NEW (insn
, -1);
6495 /* emit_pool_after will be set by s390_mainpool_start to the
6496 last insn of the section where the literal pool should be
6498 insn
= pool
->emit_pool_after
;
6500 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
6501 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
6503 s390_dump_pool (pool
, 1);
6506 /* Otherwise, we emit an inline literal pool and use BASR to branch
6507 over it, setting up the pool register at the same time. */
6510 rtx pool_end
= gen_label_rtx ();
6512 insn
= gen_main_base_31_large (base_reg
, pool
->label
, pool_end
);
6513 insn
= emit_insn_after (insn
, pool
->pool_insn
);
6514 INSN_ADDRESSES_NEW (insn
, -1);
6515 remove_insn (pool
->pool_insn
);
6517 insn
= emit_label_after (pool
->label
, insn
);
6518 INSN_ADDRESSES_NEW (insn
, -1);
6520 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
6521 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
6523 insn
= emit_label_after (pool_end
, pool
->pool_insn
);
6524 INSN_ADDRESSES_NEW (insn
, -1);
6526 s390_dump_pool (pool
, 1);
6530 /* Replace all literal pool references. */
6532 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6535 replace_ltrel_base (&PATTERN (insn
));
6537 if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
6539 rtx addr
, pool_ref
= NULL_RTX
;
6540 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
6543 if (s390_execute_label (insn
))
6544 addr
= s390_find_execute (pool
, insn
);
6546 addr
= s390_find_constant (pool
, get_pool_constant (pool_ref
),
6547 get_pool_mode (pool_ref
));
6549 replace_constant_pool_ref (&PATTERN (insn
), pool_ref
, addr
);
6550 INSN_CODE (insn
) = -1;
6556 /* Free the pool. */
6557 s390_free_pool (pool
);
6560 /* POOL holds the main literal pool as collected by s390_mainpool_start.
6561 We have decided we cannot use this pool, so revert all changes
6562 to the current function that were done by s390_mainpool_start. */
6564 s390_mainpool_cancel (struct constant_pool
*pool
)
6566 /* We didn't actually change the instruction stream, so simply
6567 free the pool memory. */
6568 s390_free_pool (pool
);
6572 /* Chunkify the literal pool. */
6574 #define S390_POOL_CHUNK_MIN 0xc00
6575 #define S390_POOL_CHUNK_MAX 0xe00
6577 static struct constant_pool
*
6578 s390_chunkify_start (void)
6580 struct constant_pool
*curr_pool
= NULL
, *pool_list
= NULL
;
6583 rtx pending_ltrel
= NULL_RTX
;
6586 rtx (*gen_reload_base
) (rtx
, rtx
) =
6587 TARGET_CPU_ZARCH
? gen_reload_base_64
: gen_reload_base_31
;
6590 /* We need correct insn addresses. */
6592 shorten_branches (get_insns ());
6594 /* Scan all insns and move literals to pool chunks. */
6596 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6598 bool section_switch_p
= false;
6600 /* Check for pending LTREL_BASE. */
6603 rtx ltrel_base
= find_ltrel_base (PATTERN (insn
));
6606 gcc_assert (ltrel_base
== pending_ltrel
);
6607 pending_ltrel
= NULL_RTX
;
6611 if (!TARGET_CPU_ZARCH
&& s390_execute_label (insn
))
6614 curr_pool
= s390_start_pool (&pool_list
, insn
);
6616 s390_add_execute (curr_pool
, insn
);
6617 s390_add_pool_insn (curr_pool
, insn
);
6619 else if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
6621 rtx pool_ref
= NULL_RTX
;
6622 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
6625 rtx constant
= get_pool_constant (pool_ref
);
6626 enum machine_mode mode
= get_pool_mode (pool_ref
);
6629 curr_pool
= s390_start_pool (&pool_list
, insn
);
6631 s390_add_constant (curr_pool
, constant
, mode
);
6632 s390_add_pool_insn (curr_pool
, insn
);
6634 /* Don't split the pool chunk between a LTREL_OFFSET load
6635 and the corresponding LTREL_BASE. */
6636 if (GET_CODE (constant
) == CONST
6637 && GET_CODE (XEXP (constant
, 0)) == UNSPEC
6638 && XINT (XEXP (constant
, 0), 1) == UNSPEC_LTREL_OFFSET
)
6640 gcc_assert (!pending_ltrel
);
6641 pending_ltrel
= pool_ref
;
6646 if (GET_CODE (insn
) == JUMP_INSN
|| GET_CODE (insn
) == CODE_LABEL
)
6649 s390_add_pool_insn (curr_pool
, insn
);
6650 /* An LTREL_BASE must follow within the same basic block. */
6651 gcc_assert (!pending_ltrel
);
6654 if (NOTE_P (insn
) && NOTE_KIND (insn
) == NOTE_INSN_SWITCH_TEXT_SECTIONS
)
6655 section_switch_p
= true;
6658 || INSN_ADDRESSES_SIZE () <= (size_t) INSN_UID (insn
)
6659 || INSN_ADDRESSES (INSN_UID (insn
)) == -1)
6662 if (TARGET_CPU_ZARCH
)
6664 if (curr_pool
->size
< S390_POOL_CHUNK_MAX
)
6667 s390_end_pool (curr_pool
, NULL_RTX
);
6672 int chunk_size
= INSN_ADDRESSES (INSN_UID (insn
))
6673 - INSN_ADDRESSES (INSN_UID (curr_pool
->first_insn
))
6676 /* We will later have to insert base register reload insns.
6677 Those will have an effect on code size, which we need to
6678 consider here. This calculation makes rather pessimistic
6679 worst-case assumptions. */
6680 if (GET_CODE (insn
) == CODE_LABEL
)
6683 if (chunk_size
< S390_POOL_CHUNK_MIN
6684 && curr_pool
->size
< S390_POOL_CHUNK_MIN
6685 && !section_switch_p
)
6688 /* Pool chunks can only be inserted after BARRIERs ... */
6689 if (GET_CODE (insn
) == BARRIER
)
6691 s390_end_pool (curr_pool
, insn
);
6696 /* ... so if we don't find one in time, create one. */
6697 else if (chunk_size
> S390_POOL_CHUNK_MAX
6698 || curr_pool
->size
> S390_POOL_CHUNK_MAX
6699 || section_switch_p
)
6701 rtx label
, jump
, barrier
;
6703 if (!section_switch_p
)
6705 /* We can insert the barrier only after a 'real' insn. */
6706 if (GET_CODE (insn
) != INSN
&& GET_CODE (insn
) != CALL_INSN
)
6708 if (get_attr_length (insn
) == 0)
6710 /* Don't separate LTREL_BASE from the corresponding
6711 LTREL_OFFSET load. */
6717 gcc_assert (!pending_ltrel
);
6719 /* The old pool has to end before the section switch
6720 note in order to make it part of the current
6722 insn
= PREV_INSN (insn
);
6725 label
= gen_label_rtx ();
6726 jump
= emit_jump_insn_after (gen_jump (label
), insn
);
6727 barrier
= emit_barrier_after (jump
);
6728 insn
= emit_label_after (label
, barrier
);
6729 JUMP_LABEL (jump
) = label
;
6730 LABEL_NUSES (label
) = 1;
6732 INSN_ADDRESSES_NEW (jump
, -1);
6733 INSN_ADDRESSES_NEW (barrier
, -1);
6734 INSN_ADDRESSES_NEW (insn
, -1);
6736 s390_end_pool (curr_pool
, barrier
);
6744 s390_end_pool (curr_pool
, NULL_RTX
);
6745 gcc_assert (!pending_ltrel
);
6747 /* Find all labels that are branched into
6748 from an insn belonging to a different chunk. */
6750 far_labels
= BITMAP_ALLOC (NULL
);
6752 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6754 /* Labels marked with LABEL_PRESERVE_P can be target
6755 of non-local jumps, so we have to mark them.
6756 The same holds for named labels.
6758 Don't do that, however, if it is the label before
6761 if (GET_CODE (insn
) == CODE_LABEL
6762 && (LABEL_PRESERVE_P (insn
) || LABEL_NAME (insn
)))
6764 rtx vec_insn
= next_real_insn (insn
);
6765 rtx vec_pat
= vec_insn
&& GET_CODE (vec_insn
) == JUMP_INSN
?
6766 PATTERN (vec_insn
) : NULL_RTX
;
6768 || !(GET_CODE (vec_pat
) == ADDR_VEC
6769 || GET_CODE (vec_pat
) == ADDR_DIFF_VEC
))
6770 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (insn
));
6773 /* If we have a direct jump (conditional or unconditional)
6774 or a casesi jump, check all potential targets. */
6775 else if (GET_CODE (insn
) == JUMP_INSN
)
6777 rtx pat
= PATTERN (insn
);
6778 if (GET_CODE (pat
) == PARALLEL
&& XVECLEN (pat
, 0) > 2)
6779 pat
= XVECEXP (pat
, 0, 0);
6781 if (GET_CODE (pat
) == SET
)
6783 rtx label
= JUMP_LABEL (insn
);
6786 if (s390_find_pool (pool_list
, label
)
6787 != s390_find_pool (pool_list
, insn
))
6788 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (label
));
6791 else if (GET_CODE (pat
) == PARALLEL
6792 && XVECLEN (pat
, 0) == 2
6793 && GET_CODE (XVECEXP (pat
, 0, 0)) == SET
6794 && GET_CODE (XVECEXP (pat
, 0, 1)) == USE
6795 && GET_CODE (XEXP (XVECEXP (pat
, 0, 1), 0)) == LABEL_REF
)
6797 /* Find the jump table used by this casesi jump. */
6798 rtx vec_label
= XEXP (XEXP (XVECEXP (pat
, 0, 1), 0), 0);
6799 rtx vec_insn
= next_real_insn (vec_label
);
6800 rtx vec_pat
= vec_insn
&& GET_CODE (vec_insn
) == JUMP_INSN
?
6801 PATTERN (vec_insn
) : NULL_RTX
;
6803 && (GET_CODE (vec_pat
) == ADDR_VEC
6804 || GET_CODE (vec_pat
) == ADDR_DIFF_VEC
))
6806 int i
, diff_p
= GET_CODE (vec_pat
) == ADDR_DIFF_VEC
;
6808 for (i
= 0; i
< XVECLEN (vec_pat
, diff_p
); i
++)
6810 rtx label
= XEXP (XVECEXP (vec_pat
, diff_p
, i
), 0);
6812 if (s390_find_pool (pool_list
, label
)
6813 != s390_find_pool (pool_list
, insn
))
6814 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (label
));
6821 /* Insert base register reload insns before every pool. */
6823 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
6825 rtx new_insn
= gen_reload_base (cfun
->machine
->base_reg
,
6827 rtx insn
= curr_pool
->first_insn
;
6828 INSN_ADDRESSES_NEW (emit_insn_before (new_insn
, insn
), -1);
6831 /* Insert base register reload insns at every far label. */
6833 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6834 if (GET_CODE (insn
) == CODE_LABEL
6835 && bitmap_bit_p (far_labels
, CODE_LABEL_NUMBER (insn
)))
6837 struct constant_pool
*pool
= s390_find_pool (pool_list
, insn
);
6840 rtx new_insn
= gen_reload_base (cfun
->machine
->base_reg
,
6842 INSN_ADDRESSES_NEW (emit_insn_after (new_insn
, insn
), -1);
6847 BITMAP_FREE (far_labels
);
6850 /* Recompute insn addresses. */
6852 init_insn_lengths ();
6853 shorten_branches (get_insns ());
6858 /* POOL_LIST is a chunk list as prepared by s390_chunkify_start.
6859 After we have decided to use this list, finish implementing
6860 all changes to the current function as required. */
6863 s390_chunkify_finish (struct constant_pool
*pool_list
)
6865 struct constant_pool
*curr_pool
= NULL
;
6869 /* Replace all literal pool references. */
6871 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6874 replace_ltrel_base (&PATTERN (insn
));
6876 curr_pool
= s390_find_pool (pool_list
, insn
);
6880 if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
6882 rtx addr
, pool_ref
= NULL_RTX
;
6883 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
6886 if (s390_execute_label (insn
))
6887 addr
= s390_find_execute (curr_pool
, insn
);
6889 addr
= s390_find_constant (curr_pool
,
6890 get_pool_constant (pool_ref
),
6891 get_pool_mode (pool_ref
));
6893 replace_constant_pool_ref (&PATTERN (insn
), pool_ref
, addr
);
6894 INSN_CODE (insn
) = -1;
6899 /* Dump out all literal pools. */
6901 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
6902 s390_dump_pool (curr_pool
, 0);
6904 /* Free pool list. */
6908 struct constant_pool
*next
= pool_list
->next
;
6909 s390_free_pool (pool_list
);
6914 /* POOL_LIST is a chunk list as prepared by s390_chunkify_start.
6915 We have decided we cannot use this list, so revert all changes
6916 to the current function that were done by s390_chunkify_start. */
6919 s390_chunkify_cancel (struct constant_pool
*pool_list
)
6921 struct constant_pool
*curr_pool
= NULL
;
6924 /* Remove all pool placeholder insns. */
6926 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
6928 /* Did we insert an extra barrier? Remove it. */
6929 rtx barrier
= PREV_INSN (curr_pool
->pool_insn
);
6930 rtx jump
= barrier
? PREV_INSN (barrier
) : NULL_RTX
;
6931 rtx label
= NEXT_INSN (curr_pool
->pool_insn
);
6933 if (jump
&& GET_CODE (jump
) == JUMP_INSN
6934 && barrier
&& GET_CODE (barrier
) == BARRIER
6935 && label
&& GET_CODE (label
) == CODE_LABEL
6936 && GET_CODE (PATTERN (jump
)) == SET
6937 && SET_DEST (PATTERN (jump
)) == pc_rtx
6938 && GET_CODE (SET_SRC (PATTERN (jump
))) == LABEL_REF
6939 && XEXP (SET_SRC (PATTERN (jump
)), 0) == label
)
6942 remove_insn (barrier
);
6943 remove_insn (label
);
6946 remove_insn (curr_pool
->pool_insn
);
6949 /* Remove all base register reload insns. */
6951 for (insn
= get_insns (); insn
; )
6953 rtx next_insn
= NEXT_INSN (insn
);
6955 if (GET_CODE (insn
) == INSN
6956 && GET_CODE (PATTERN (insn
)) == SET
6957 && GET_CODE (SET_SRC (PATTERN (insn
))) == UNSPEC
6958 && XINT (SET_SRC (PATTERN (insn
)), 1) == UNSPEC_RELOAD_BASE
)
6964 /* Free pool list. */
6968 struct constant_pool
*next
= pool_list
->next
;
6969 s390_free_pool (pool_list
);
6974 /* Output the constant pool entry EXP in mode MODE with alignment ALIGN. */
6977 s390_output_pool_entry (rtx exp
, enum machine_mode mode
, unsigned int align
)
6981 switch (GET_MODE_CLASS (mode
))
6984 case MODE_DECIMAL_FLOAT
:
6985 gcc_assert (GET_CODE (exp
) == CONST_DOUBLE
);
6987 REAL_VALUE_FROM_CONST_DOUBLE (r
, exp
);
6988 assemble_real (r
, mode
, align
);
6992 assemble_integer (exp
, GET_MODE_SIZE (mode
), align
, 1);
6993 mark_symbol_refs_as_used (exp
);
7002 /* Return an RTL expression representing the value of the return address
7003 for the frame COUNT steps up from the current frame. FRAME is the
7004 frame pointer of that frame. */
7007 s390_return_addr_rtx (int count
, rtx frame ATTRIBUTE_UNUSED
)
7012 /* Without backchain, we fail for all but the current frame. */
7014 if (!TARGET_BACKCHAIN
&& count
> 0)
7017 /* For the current frame, we need to make sure the initial
7018 value of RETURN_REGNUM is actually saved. */
7022 /* On non-z architectures branch splitting could overwrite r14. */
7023 if (TARGET_CPU_ZARCH
)
7024 return get_hard_reg_initial_val (Pmode
, RETURN_REGNUM
);
7027 cfun_frame_layout
.save_return_addr_p
= true;
7028 return gen_rtx_MEM (Pmode
, return_address_pointer_rtx
);
7032 if (TARGET_PACKED_STACK
)
7033 offset
= -2 * UNITS_PER_LONG
;
7035 offset
= RETURN_REGNUM
* UNITS_PER_LONG
;
7037 addr
= plus_constant (frame
, offset
);
7038 addr
= memory_address (Pmode
, addr
);
7039 return gen_rtx_MEM (Pmode
, addr
);
7042 /* Return an RTL expression representing the back chain stored in
7043 the current stack frame. */
7046 s390_back_chain_rtx (void)
7050 gcc_assert (TARGET_BACKCHAIN
);
7052 if (TARGET_PACKED_STACK
)
7053 chain
= plus_constant (stack_pointer_rtx
,
7054 STACK_POINTER_OFFSET
- UNITS_PER_LONG
);
7056 chain
= stack_pointer_rtx
;
7058 chain
= gen_rtx_MEM (Pmode
, chain
);
7062 /* Find first call clobbered register unused in a function.
7063 This could be used as base register in a leaf function
7064 or for holding the return address before epilogue. */
7067 find_unused_clobbered_reg (void)
7070 for (i
= 0; i
< 6; i
++)
7071 if (!df_regs_ever_live_p (i
))
7077 /* Helper function for s390_regs_ever_clobbered. Sets the fields in DATA for all
7078 clobbered hard regs in SETREG. */
7081 s390_reg_clobbered_rtx (rtx setreg
, const_rtx set_insn ATTRIBUTE_UNUSED
, void *data
)
7083 int *regs_ever_clobbered
= (int *)data
;
7084 unsigned int i
, regno
;
7085 enum machine_mode mode
= GET_MODE (setreg
);
7087 if (GET_CODE (setreg
) == SUBREG
)
7089 rtx inner
= SUBREG_REG (setreg
);
7090 if (!GENERAL_REG_P (inner
))
7092 regno
= subreg_regno (setreg
);
7094 else if (GENERAL_REG_P (setreg
))
7095 regno
= REGNO (setreg
);
7100 i
< regno
+ HARD_REGNO_NREGS (regno
, mode
);
7102 regs_ever_clobbered
[i
] = 1;
7105 /* Walks through all basic blocks of the current function looking
7106 for clobbered hard regs using s390_reg_clobbered_rtx. The fields
7107 of the passed integer array REGS_EVER_CLOBBERED are set to one for
7108 each of those regs. */
7111 s390_regs_ever_clobbered (int *regs_ever_clobbered
)
7117 memset (regs_ever_clobbered
, 0, 16 * sizeof (int));
7119 /* For non-leaf functions we have to consider all call clobbered regs to be
7121 if (!current_function_is_leaf
)
7123 for (i
= 0; i
< 16; i
++)
7124 regs_ever_clobbered
[i
] = call_really_used_regs
[i
];
7127 /* Make the "magic" eh_return registers live if necessary. For regs_ever_live
7128 this work is done by liveness analysis (mark_regs_live_at_end).
7129 Special care is needed for functions containing landing pads. Landing pads
7130 may use the eh registers, but the code which sets these registers is not
7131 contained in that function. Hence s390_regs_ever_clobbered is not able to
7132 deal with this automatically. */
7133 if (crtl
->calls_eh_return
|| cfun
->machine
->has_landing_pad_p
)
7134 for (i
= 0; EH_RETURN_DATA_REGNO (i
) != INVALID_REGNUM
; i
++)
7135 if (crtl
->calls_eh_return
7136 || (cfun
->machine
->has_landing_pad_p
7137 && df_regs_ever_live_p (EH_RETURN_DATA_REGNO (i
))))
7138 regs_ever_clobbered
[EH_RETURN_DATA_REGNO (i
)] = 1;
7140 /* For nonlocal gotos all call-saved registers have to be saved.
7141 This flag is also set for the unwinding code in libgcc.
7142 See expand_builtin_unwind_init. For regs_ever_live this is done by
7144 if (cfun
->has_nonlocal_label
)
7145 for (i
= 0; i
< 16; i
++)
7146 if (!call_really_used_regs
[i
])
7147 regs_ever_clobbered
[i
] = 1;
7149 FOR_EACH_BB (cur_bb
)
7151 FOR_BB_INSNS (cur_bb
, cur_insn
)
7153 if (INSN_P (cur_insn
))
7154 note_stores (PATTERN (cur_insn
),
7155 s390_reg_clobbered_rtx
,
7156 regs_ever_clobbered
);
7161 /* Determine the frame area which actually has to be accessed
7162 in the function epilogue. The values are stored at the
7163 given pointers AREA_BOTTOM (address of the lowest used stack
7164 address) and AREA_TOP (address of the first item which does
7165 not belong to the stack frame). */
7168 s390_frame_area (int *area_bottom
, int *area_top
)
7176 if (cfun_frame_layout
.first_restore_gpr
!= -1)
7178 b
= (cfun_frame_layout
.gprs_offset
7179 + cfun_frame_layout
.first_restore_gpr
* UNITS_PER_LONG
);
7180 t
= b
+ (cfun_frame_layout
.last_restore_gpr
7181 - cfun_frame_layout
.first_restore_gpr
+ 1) * UNITS_PER_LONG
;
7184 if (TARGET_64BIT
&& cfun_save_high_fprs_p
)
7186 b
= MIN (b
, cfun_frame_layout
.f8_offset
);
7187 t
= MAX (t
, (cfun_frame_layout
.f8_offset
7188 + cfun_frame_layout
.high_fprs
* 8));
7192 for (i
= 2; i
< 4; i
++)
7193 if (cfun_fpr_bit_p (i
))
7195 b
= MIN (b
, cfun_frame_layout
.f4_offset
+ (i
- 2) * 8);
7196 t
= MAX (t
, cfun_frame_layout
.f4_offset
+ (i
- 1) * 8);
7203 /* Fill cfun->machine with info about register usage of current function.
7204 Return in CLOBBERED_REGS which GPRs are currently considered set. */
7207 s390_register_info (int clobbered_regs
[])
7211 /* fprs 8 - 15 are call saved for 64 Bit ABI. */
7212 cfun_frame_layout
.fpr_bitmap
= 0;
7213 cfun_frame_layout
.high_fprs
= 0;
7215 for (i
= 24; i
< 32; i
++)
7216 if (df_regs_ever_live_p (i
) && !global_regs
[i
])
7218 cfun_set_fpr_bit (i
- 16);
7219 cfun_frame_layout
.high_fprs
++;
7222 /* Find first and last gpr to be saved. We trust regs_ever_live
7223 data, except that we don't save and restore global registers.
7225 Also, all registers with special meaning to the compiler need
7226 to be handled extra. */
7228 s390_regs_ever_clobbered (clobbered_regs
);
7230 for (i
= 0; i
< 16; i
++)
7231 clobbered_regs
[i
] = clobbered_regs
[i
] && !global_regs
[i
] && !fixed_regs
[i
];
7233 if (frame_pointer_needed
)
7234 clobbered_regs
[HARD_FRAME_POINTER_REGNUM
] = 1;
7237 clobbered_regs
[PIC_OFFSET_TABLE_REGNUM
]
7238 |= df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM
);
7240 clobbered_regs
[BASE_REGNUM
]
7241 |= (cfun
->machine
->base_reg
7242 && REGNO (cfun
->machine
->base_reg
) == BASE_REGNUM
);
7244 clobbered_regs
[RETURN_REGNUM
]
7245 |= (!current_function_is_leaf
7246 || TARGET_TPF_PROFILING
7247 || cfun
->machine
->split_branches_pending_p
7248 || cfun_frame_layout
.save_return_addr_p
7249 || crtl
->calls_eh_return
7252 clobbered_regs
[STACK_POINTER_REGNUM
]
7253 |= (!current_function_is_leaf
7254 || TARGET_TPF_PROFILING
7255 || cfun_save_high_fprs_p
7256 || get_frame_size () > 0
7257 || cfun
->calls_alloca
7260 for (i
= 6; i
< 16; i
++)
7261 if (df_regs_ever_live_p (i
) || clobbered_regs
[i
])
7263 for (j
= 15; j
> i
; j
--)
7264 if (df_regs_ever_live_p (j
) || clobbered_regs
[j
])
7269 /* Nothing to save/restore. */
7270 cfun_frame_layout
.first_save_gpr_slot
= -1;
7271 cfun_frame_layout
.last_save_gpr_slot
= -1;
7272 cfun_frame_layout
.first_save_gpr
= -1;
7273 cfun_frame_layout
.first_restore_gpr
= -1;
7274 cfun_frame_layout
.last_save_gpr
= -1;
7275 cfun_frame_layout
.last_restore_gpr
= -1;
7279 /* Save slots for gprs from i to j. */
7280 cfun_frame_layout
.first_save_gpr_slot
= i
;
7281 cfun_frame_layout
.last_save_gpr_slot
= j
;
7283 for (i
= cfun_frame_layout
.first_save_gpr_slot
;
7284 i
< cfun_frame_layout
.last_save_gpr_slot
+ 1;
7286 if (clobbered_regs
[i
])
7289 for (j
= cfun_frame_layout
.last_save_gpr_slot
; j
> i
; j
--)
7290 if (clobbered_regs
[j
])
7293 if (i
== cfun_frame_layout
.last_save_gpr_slot
+ 1)
7295 /* Nothing to save/restore. */
7296 cfun_frame_layout
.first_save_gpr
= -1;
7297 cfun_frame_layout
.first_restore_gpr
= -1;
7298 cfun_frame_layout
.last_save_gpr
= -1;
7299 cfun_frame_layout
.last_restore_gpr
= -1;
7303 /* Save / Restore from gpr i to j. */
7304 cfun_frame_layout
.first_save_gpr
= i
;
7305 cfun_frame_layout
.first_restore_gpr
= i
;
7306 cfun_frame_layout
.last_save_gpr
= j
;
7307 cfun_frame_layout
.last_restore_gpr
= j
;
7313 /* Varargs functions need to save gprs 2 to 6. */
7314 if (cfun
->va_list_gpr_size
7315 && crtl
->args
.info
.gprs
< GP_ARG_NUM_REG
)
7317 int min_gpr
= crtl
->args
.info
.gprs
;
7318 int max_gpr
= min_gpr
+ cfun
->va_list_gpr_size
;
7319 if (max_gpr
> GP_ARG_NUM_REG
)
7320 max_gpr
= GP_ARG_NUM_REG
;
7322 if (cfun_frame_layout
.first_save_gpr
== -1
7323 || cfun_frame_layout
.first_save_gpr
> 2 + min_gpr
)
7325 cfun_frame_layout
.first_save_gpr
= 2 + min_gpr
;
7326 cfun_frame_layout
.first_save_gpr_slot
= 2 + min_gpr
;
7329 if (cfun_frame_layout
.last_save_gpr
== -1
7330 || cfun_frame_layout
.last_save_gpr
< 2 + max_gpr
- 1)
7332 cfun_frame_layout
.last_save_gpr
= 2 + max_gpr
- 1;
7333 cfun_frame_layout
.last_save_gpr_slot
= 2 + max_gpr
- 1;
7337 /* Mark f0, f2 for 31 bit and f0-f4 for 64 bit to be saved. */
7338 if (TARGET_HARD_FLOAT
&& cfun
->va_list_fpr_size
7339 && crtl
->args
.info
.fprs
< FP_ARG_NUM_REG
)
7341 int min_fpr
= crtl
->args
.info
.fprs
;
7342 int max_fpr
= min_fpr
+ cfun
->va_list_fpr_size
;
7343 if (max_fpr
> FP_ARG_NUM_REG
)
7344 max_fpr
= FP_ARG_NUM_REG
;
7346 /* ??? This is currently required to ensure proper location
7347 of the fpr save slots within the va_list save area. */
7348 if (TARGET_PACKED_STACK
)
7351 for (i
= min_fpr
; i
< max_fpr
; i
++)
7352 cfun_set_fpr_bit (i
);
7357 for (i
= 2; i
< 4; i
++)
7358 if (df_regs_ever_live_p (i
+ 16) && !global_regs
[i
+ 16])
7359 cfun_set_fpr_bit (i
);
7362 /* Fill cfun->machine with info about frame of current function. */
7365 s390_frame_info (void)
7369 cfun_frame_layout
.frame_size
= get_frame_size ();
7370 if (!TARGET_64BIT
&& cfun_frame_layout
.frame_size
> 0x7fff0000)
7371 fatal_error ("total size of local variables exceeds architecture limit");
7373 if (!TARGET_PACKED_STACK
)
7375 cfun_frame_layout
.backchain_offset
= 0;
7376 cfun_frame_layout
.f0_offset
= 16 * UNITS_PER_LONG
;
7377 cfun_frame_layout
.f4_offset
= cfun_frame_layout
.f0_offset
+ 2 * 8;
7378 cfun_frame_layout
.f8_offset
= -cfun_frame_layout
.high_fprs
* 8;
7379 cfun_frame_layout
.gprs_offset
= (cfun_frame_layout
.first_save_gpr_slot
7382 else if (TARGET_BACKCHAIN
) /* kernel stack layout */
7384 cfun_frame_layout
.backchain_offset
= (STACK_POINTER_OFFSET
7386 cfun_frame_layout
.gprs_offset
7387 = (cfun_frame_layout
.backchain_offset
7388 - (STACK_POINTER_REGNUM
- cfun_frame_layout
.first_save_gpr_slot
+ 1)
7393 cfun_frame_layout
.f4_offset
7394 = (cfun_frame_layout
.gprs_offset
7395 - 8 * (cfun_fpr_bit_p (2) + cfun_fpr_bit_p (3)));
7397 cfun_frame_layout
.f0_offset
7398 = (cfun_frame_layout
.f4_offset
7399 - 8 * (cfun_fpr_bit_p (0) + cfun_fpr_bit_p (1)));
7403 /* On 31 bit we have to care about alignment of the
7404 floating point regs to provide fastest access. */
7405 cfun_frame_layout
.f0_offset
7406 = ((cfun_frame_layout
.gprs_offset
7407 & ~(STACK_BOUNDARY
/ BITS_PER_UNIT
- 1))
7408 - 8 * (cfun_fpr_bit_p (0) + cfun_fpr_bit_p (1)));
7410 cfun_frame_layout
.f4_offset
7411 = (cfun_frame_layout
.f0_offset
7412 - 8 * (cfun_fpr_bit_p (2) + cfun_fpr_bit_p (3)));
7415 else /* no backchain */
7417 cfun_frame_layout
.f4_offset
7418 = (STACK_POINTER_OFFSET
7419 - 8 * (cfun_fpr_bit_p (2) + cfun_fpr_bit_p (3)));
7421 cfun_frame_layout
.f0_offset
7422 = (cfun_frame_layout
.f4_offset
7423 - 8 * (cfun_fpr_bit_p (0) + cfun_fpr_bit_p (1)));
7425 cfun_frame_layout
.gprs_offset
7426 = cfun_frame_layout
.f0_offset
- cfun_gprs_save_area_size
;
7429 if (current_function_is_leaf
7430 && !TARGET_TPF_PROFILING
7431 && cfun_frame_layout
.frame_size
== 0
7432 && !cfun_save_high_fprs_p
7433 && !cfun
->calls_alloca
7437 if (!TARGET_PACKED_STACK
)
7438 cfun_frame_layout
.frame_size
+= (STACK_POINTER_OFFSET
7439 + crtl
->outgoing_args_size
7440 + cfun_frame_layout
.high_fprs
* 8);
7443 if (TARGET_BACKCHAIN
)
7444 cfun_frame_layout
.frame_size
+= UNITS_PER_LONG
;
7446 /* No alignment trouble here because f8-f15 are only saved under
7448 cfun_frame_layout
.f8_offset
= (MIN (MIN (cfun_frame_layout
.f0_offset
,
7449 cfun_frame_layout
.f4_offset
),
7450 cfun_frame_layout
.gprs_offset
)
7451 - cfun_frame_layout
.high_fprs
* 8);
7453 cfun_frame_layout
.frame_size
+= cfun_frame_layout
.high_fprs
* 8;
7455 for (i
= 0; i
< 8; i
++)
7456 if (cfun_fpr_bit_p (i
))
7457 cfun_frame_layout
.frame_size
+= 8;
7459 cfun_frame_layout
.frame_size
+= cfun_gprs_save_area_size
;
7461 /* If under 31 bit an odd number of gprs has to be saved we have to adjust
7462 the frame size to sustain 8 byte alignment of stack frames. */
7463 cfun_frame_layout
.frame_size
= ((cfun_frame_layout
.frame_size
+
7464 STACK_BOUNDARY
/ BITS_PER_UNIT
- 1)
7465 & ~(STACK_BOUNDARY
/ BITS_PER_UNIT
- 1));
7467 cfun_frame_layout
.frame_size
+= crtl
->outgoing_args_size
;
7471 /* Generate frame layout. Fills in register and frame data for the current
7472 function in cfun->machine. This routine can be called multiple times;
7473 it will re-do the complete frame layout every time. */
7476 s390_init_frame_layout (void)
7478 HOST_WIDE_INT frame_size
;
7480 int clobbered_regs
[16];
7482 /* On S/390 machines, we may need to perform branch splitting, which
7483 will require both base and return address register. We have no
7484 choice but to assume we're going to need them until right at the
7485 end of the machine dependent reorg phase. */
7486 if (!TARGET_CPU_ZARCH
)
7487 cfun
->machine
->split_branches_pending_p
= true;
7491 frame_size
= cfun_frame_layout
.frame_size
;
7493 /* Try to predict whether we'll need the base register. */
7494 base_used
= cfun
->machine
->split_branches_pending_p
7495 || crtl
->uses_const_pool
7496 || (!DISP_IN_RANGE (frame_size
)
7497 && !CONST_OK_FOR_K (frame_size
));
7499 /* Decide which register to use as literal pool base. In small
7500 leaf functions, try to use an unused call-clobbered register
7501 as base register to avoid save/restore overhead. */
7503 cfun
->machine
->base_reg
= NULL_RTX
;
7504 else if (current_function_is_leaf
&& !df_regs_ever_live_p (5))
7505 cfun
->machine
->base_reg
= gen_rtx_REG (Pmode
, 5);
7507 cfun
->machine
->base_reg
= gen_rtx_REG (Pmode
, BASE_REGNUM
);
7509 s390_register_info (clobbered_regs
);
7512 while (frame_size
!= cfun_frame_layout
.frame_size
);
7515 /* Update frame layout. Recompute actual register save data based on
7516 current info and update regs_ever_live for the special registers.
7517 May be called multiple times, but may never cause *more* registers
7518 to be saved than s390_init_frame_layout allocated room for. */
7521 s390_update_frame_layout (void)
7523 int clobbered_regs
[16];
7525 s390_register_info (clobbered_regs
);
7527 df_set_regs_ever_live (BASE_REGNUM
,
7528 clobbered_regs
[BASE_REGNUM
] ? true : false);
7529 df_set_regs_ever_live (RETURN_REGNUM
,
7530 clobbered_regs
[RETURN_REGNUM
] ? true : false);
7531 df_set_regs_ever_live (STACK_POINTER_REGNUM
,
7532 clobbered_regs
[STACK_POINTER_REGNUM
] ? true : false);
7534 if (cfun
->machine
->base_reg
)
7535 df_set_regs_ever_live (REGNO (cfun
->machine
->base_reg
), true);
7538 /* Return true if it is legal to put a value with MODE into REGNO. */
7541 s390_hard_regno_mode_ok (unsigned int regno
, enum machine_mode mode
)
7543 switch (REGNO_REG_CLASS (regno
))
7546 if (REGNO_PAIR_OK (regno
, mode
))
7548 if (mode
== SImode
|| mode
== DImode
)
7551 if (FLOAT_MODE_P (mode
) && GET_MODE_CLASS (mode
) != MODE_VECTOR_FLOAT
)
7556 if (FRAME_REGNO_P (regno
) && mode
== Pmode
)
7561 if (REGNO_PAIR_OK (regno
, mode
))
7564 || (mode
!= TFmode
&& mode
!= TCmode
&& mode
!= TDmode
))
7569 if (GET_MODE_CLASS (mode
) == MODE_CC
)
7573 if (REGNO_PAIR_OK (regno
, mode
))
7575 if (mode
== SImode
|| mode
== Pmode
)
7586 /* Return nonzero if register OLD_REG can be renamed to register NEW_REG. */
7589 s390_hard_regno_rename_ok (unsigned int old_reg
, unsigned int new_reg
)
7591 /* Once we've decided upon a register to use as base register, it must
7592 no longer be used for any other purpose. */
7593 if (cfun
->machine
->base_reg
)
7594 if (REGNO (cfun
->machine
->base_reg
) == old_reg
7595 || REGNO (cfun
->machine
->base_reg
) == new_reg
)
7601 /* Maximum number of registers to represent a value of mode MODE
7602 in a register of class RCLASS. */
7605 s390_class_max_nregs (enum reg_class rclass
, enum machine_mode mode
)
7610 if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
)
7611 return 2 * ((GET_MODE_SIZE (mode
) / 2 + 8 - 1) / 8);
7613 return (GET_MODE_SIZE (mode
) + 8 - 1) / 8;
7615 return (GET_MODE_SIZE (mode
) + 4 - 1) / 4;
7619 return (GET_MODE_SIZE (mode
) + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
7622 /* Return true if register FROM can be eliminated via register TO. */
7625 s390_can_eliminate (const int from
, const int to
)
7627 /* On zSeries machines, we have not marked the base register as fixed.
7628 Instead, we have an elimination rule BASE_REGNUM -> BASE_REGNUM.
7629 If a function requires the base register, we say here that this
7630 elimination cannot be performed. This will cause reload to free
7631 up the base register (as if it were fixed). On the other hand,
7632 if the current function does *not* require the base register, we
7633 say here the elimination succeeds, which in turn allows reload
7634 to allocate the base register for any other purpose. */
7635 if (from
== BASE_REGNUM
&& to
== BASE_REGNUM
)
7637 if (TARGET_CPU_ZARCH
)
7639 s390_init_frame_layout ();
7640 return cfun
->machine
->base_reg
== NULL_RTX
;
7646 /* Everything else must point into the stack frame. */
7647 gcc_assert (to
== STACK_POINTER_REGNUM
7648 || to
== HARD_FRAME_POINTER_REGNUM
);
7650 gcc_assert (from
== FRAME_POINTER_REGNUM
7651 || from
== ARG_POINTER_REGNUM
7652 || from
== RETURN_ADDRESS_POINTER_REGNUM
);
7654 /* Make sure we actually saved the return address. */
7655 if (from
== RETURN_ADDRESS_POINTER_REGNUM
)
7656 if (!crtl
->calls_eh_return
7658 && !cfun_frame_layout
.save_return_addr_p
)
7664 /* Return offset between register FROM and TO initially after prolog. */
7667 s390_initial_elimination_offset (int from
, int to
)
7669 HOST_WIDE_INT offset
;
7672 /* ??? Why are we called for non-eliminable pairs? */
7673 if (!s390_can_eliminate (from
, to
))
7678 case FRAME_POINTER_REGNUM
:
7679 offset
= (get_frame_size()
7680 + STACK_POINTER_OFFSET
7681 + crtl
->outgoing_args_size
);
7684 case ARG_POINTER_REGNUM
:
7685 s390_init_frame_layout ();
7686 offset
= cfun_frame_layout
.frame_size
+ STACK_POINTER_OFFSET
;
7689 case RETURN_ADDRESS_POINTER_REGNUM
:
7690 s390_init_frame_layout ();
7691 index
= RETURN_REGNUM
- cfun_frame_layout
.first_save_gpr_slot
;
7692 gcc_assert (index
>= 0);
7693 offset
= cfun_frame_layout
.frame_size
+ cfun_frame_layout
.gprs_offset
;
7694 offset
+= index
* UNITS_PER_LONG
;
7708 /* Emit insn to save fpr REGNUM at offset OFFSET relative
7709 to register BASE. Return generated insn. */
7712 save_fpr (rtx base
, int offset
, int regnum
)
7715 addr
= gen_rtx_MEM (DFmode
, plus_constant (base
, offset
));
7717 if (regnum
>= 16 && regnum
<= (16 + FP_ARG_NUM_REG
))
7718 set_mem_alias_set (addr
, get_varargs_alias_set ());
7720 set_mem_alias_set (addr
, get_frame_alias_set ());
7722 return emit_move_insn (addr
, gen_rtx_REG (DFmode
, regnum
));
7725 /* Emit insn to restore fpr REGNUM from offset OFFSET relative
7726 to register BASE. Return generated insn. */
7729 restore_fpr (rtx base
, int offset
, int regnum
)
7732 addr
= gen_rtx_MEM (DFmode
, plus_constant (base
, offset
));
7733 set_mem_alias_set (addr
, get_frame_alias_set ());
7735 return emit_move_insn (gen_rtx_REG (DFmode
, regnum
), addr
);
7738 /* Return true if REGNO is a global register, but not one
7739 of the special ones that need to be saved/restored in anyway. */
7742 global_not_special_regno_p (int regno
)
7744 return (global_regs
[regno
]
7745 /* These registers are special and need to be
7746 restored in any case. */
7747 && !(regno
== STACK_POINTER_REGNUM
7748 || regno
== RETURN_REGNUM
7749 || regno
== BASE_REGNUM
7750 || (flag_pic
&& regno
== (int)PIC_OFFSET_TABLE_REGNUM
)));
7753 /* Generate insn to save registers FIRST to LAST into
7754 the register save area located at offset OFFSET
7755 relative to register BASE. */
7758 save_gprs (rtx base
, int offset
, int first
, int last
)
7760 rtx addr
, insn
, note
;
7763 addr
= plus_constant (base
, offset
);
7764 addr
= gen_rtx_MEM (Pmode
, addr
);
7766 set_mem_alias_set (addr
, get_frame_alias_set ());
7768 /* Special-case single register. */
7772 insn
= gen_movdi (addr
, gen_rtx_REG (Pmode
, first
));
7774 insn
= gen_movsi (addr
, gen_rtx_REG (Pmode
, first
));
7776 if (!global_not_special_regno_p (first
))
7777 RTX_FRAME_RELATED_P (insn
) = 1;
7782 insn
= gen_store_multiple (addr
,
7783 gen_rtx_REG (Pmode
, first
),
7784 GEN_INT (last
- first
+ 1));
7786 if (first
<= 6 && cfun
->stdarg
)
7787 for (i
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
7789 rtx mem
= XEXP (XVECEXP (PATTERN (insn
), 0, i
), 0);
7792 set_mem_alias_set (mem
, get_varargs_alias_set ());
7795 /* We need to set the FRAME_RELATED flag on all SETs
7796 inside the store-multiple pattern.
7798 However, we must not emit DWARF records for registers 2..5
7799 if they are stored for use by variable arguments ...
7801 ??? Unfortunately, it is not enough to simply not the
7802 FRAME_RELATED flags for those SETs, because the first SET
7803 of the PARALLEL is always treated as if it had the flag
7804 set, even if it does not. Therefore we emit a new pattern
7805 without those registers as REG_FRAME_RELATED_EXPR note. */
7807 if (first
>= 6 && !global_not_special_regno_p (first
))
7809 rtx pat
= PATTERN (insn
);
7811 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
7812 if (GET_CODE (XVECEXP (pat
, 0, i
)) == SET
7813 && !global_not_special_regno_p (REGNO (SET_SRC (XVECEXP (pat
,
7815 RTX_FRAME_RELATED_P (XVECEXP (pat
, 0, i
)) = 1;
7817 RTX_FRAME_RELATED_P (insn
) = 1;
7823 for (start
= first
>= 6 ? first
: 6; start
<= last
; start
++)
7824 if (!global_not_special_regno_p (start
))
7830 addr
= plus_constant (base
, offset
+ (start
- first
) * UNITS_PER_LONG
);
7831 note
= gen_store_multiple (gen_rtx_MEM (Pmode
, addr
),
7832 gen_rtx_REG (Pmode
, start
),
7833 GEN_INT (last
- start
+ 1));
7834 note
= PATTERN (note
);
7836 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
, note
);
7838 for (i
= 0; i
< XVECLEN (note
, 0); i
++)
7839 if (GET_CODE (XVECEXP (note
, 0, i
)) == SET
7840 && !global_not_special_regno_p (REGNO (SET_SRC (XVECEXP (note
,
7842 RTX_FRAME_RELATED_P (XVECEXP (note
, 0, i
)) = 1;
7844 RTX_FRAME_RELATED_P (insn
) = 1;
7850 /* Generate insn to restore registers FIRST to LAST from
7851 the register save area located at offset OFFSET
7852 relative to register BASE. */
7855 restore_gprs (rtx base
, int offset
, int first
, int last
)
7859 addr
= plus_constant (base
, offset
);
7860 addr
= gen_rtx_MEM (Pmode
, addr
);
7861 set_mem_alias_set (addr
, get_frame_alias_set ());
7863 /* Special-case single register. */
7867 insn
= gen_movdi (gen_rtx_REG (Pmode
, first
), addr
);
7869 insn
= gen_movsi (gen_rtx_REG (Pmode
, first
), addr
);
7874 insn
= gen_load_multiple (gen_rtx_REG (Pmode
, first
),
7876 GEN_INT (last
- first
+ 1));
7880 /* Return insn sequence to load the GOT register. */
7882 static GTY(()) rtx got_symbol
;
7884 s390_load_got (void)
7890 got_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "_GLOBAL_OFFSET_TABLE_");
7891 SYMBOL_REF_FLAGS (got_symbol
) = SYMBOL_FLAG_LOCAL
;
7896 if (TARGET_CPU_ZARCH
)
7898 emit_move_insn (pic_offset_table_rtx
, got_symbol
);
7904 offset
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, got_symbol
),
7905 UNSPEC_LTREL_OFFSET
);
7906 offset
= gen_rtx_CONST (Pmode
, offset
);
7907 offset
= force_const_mem (Pmode
, offset
);
7909 emit_move_insn (pic_offset_table_rtx
, offset
);
7911 offset
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, XEXP (offset
, 0)),
7913 offset
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, offset
);
7915 emit_move_insn (pic_offset_table_rtx
, offset
);
7918 insns
= get_insns ();
7923 /* This ties together stack memory (MEM with an alias set of frame_alias_set)
7924 and the change to the stack pointer. */
7927 s390_emit_stack_tie (void)
7929 rtx mem
= gen_frame_mem (BLKmode
,
7930 gen_rtx_REG (Pmode
, STACK_POINTER_REGNUM
));
7932 emit_insn (gen_stack_tie (mem
));
7935 /* Expand the prologue into a bunch of separate insns. */
7938 s390_emit_prologue (void)
7946 /* Complete frame layout. */
7948 s390_update_frame_layout ();
7950 /* Annotate all constant pool references to let the scheduler know
7951 they implicitly use the base register. */
7953 push_topmost_sequence ();
7955 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
7958 annotate_constant_pool_refs (&PATTERN (insn
));
7959 df_insn_rescan (insn
);
7962 pop_topmost_sequence ();
7964 /* Choose best register to use for temp use within prologue.
7965 See below for why TPF must use the register 1. */
7967 if (!has_hard_reg_initial_val (Pmode
, RETURN_REGNUM
)
7968 && !current_function_is_leaf
7969 && !TARGET_TPF_PROFILING
)
7970 temp_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
7972 temp_reg
= gen_rtx_REG (Pmode
, 1);
7974 /* Save call saved gprs. */
7975 if (cfun_frame_layout
.first_save_gpr
!= -1)
7977 insn
= save_gprs (stack_pointer_rtx
,
7978 cfun_frame_layout
.gprs_offset
+
7979 UNITS_PER_LONG
* (cfun_frame_layout
.first_save_gpr
7980 - cfun_frame_layout
.first_save_gpr_slot
),
7981 cfun_frame_layout
.first_save_gpr
,
7982 cfun_frame_layout
.last_save_gpr
);
7986 /* Dummy insn to mark literal pool slot. */
7988 if (cfun
->machine
->base_reg
)
7989 emit_insn (gen_main_pool (cfun
->machine
->base_reg
));
7991 offset
= cfun_frame_layout
.f0_offset
;
7993 /* Save f0 and f2. */
7994 for (i
= 0; i
< 2; i
++)
7996 if (cfun_fpr_bit_p (i
))
7998 save_fpr (stack_pointer_rtx
, offset
, i
+ 16);
8001 else if (!TARGET_PACKED_STACK
)
8005 /* Save f4 and f6. */
8006 offset
= cfun_frame_layout
.f4_offset
;
8007 for (i
= 2; i
< 4; i
++)
8009 if (cfun_fpr_bit_p (i
))
8011 insn
= save_fpr (stack_pointer_rtx
, offset
, i
+ 16);
8014 /* If f4 and f6 are call clobbered they are saved due to stdargs and
8015 therefore are not frame related. */
8016 if (!call_really_used_regs
[i
+ 16])
8017 RTX_FRAME_RELATED_P (insn
) = 1;
8019 else if (!TARGET_PACKED_STACK
)
8023 if (TARGET_PACKED_STACK
8024 && cfun_save_high_fprs_p
8025 && cfun_frame_layout
.f8_offset
+ cfun_frame_layout
.high_fprs
* 8 > 0)
8027 offset
= (cfun_frame_layout
.f8_offset
8028 + (cfun_frame_layout
.high_fprs
- 1) * 8);
8030 for (i
= 15; i
> 7 && offset
>= 0; i
--)
8031 if (cfun_fpr_bit_p (i
))
8033 insn
= save_fpr (stack_pointer_rtx
, offset
, i
+ 16);
8035 RTX_FRAME_RELATED_P (insn
) = 1;
8038 if (offset
>= cfun_frame_layout
.f8_offset
)
8042 if (!TARGET_PACKED_STACK
)
8043 next_fpr
= cfun_save_high_fprs_p
? 31 : 0;
8045 if (flag_stack_usage
)
8046 current_function_static_stack_size
= cfun_frame_layout
.frame_size
;
8048 /* Decrement stack pointer. */
8050 if (cfun_frame_layout
.frame_size
> 0)
8052 rtx frame_off
= GEN_INT (-cfun_frame_layout
.frame_size
);
8055 if (s390_stack_size
)
8057 HOST_WIDE_INT stack_guard
;
8059 if (s390_stack_guard
)
8060 stack_guard
= s390_stack_guard
;
8063 /* If no value for stack guard is provided the smallest power of 2
8064 larger than the current frame size is chosen. */
8066 while (stack_guard
< cfun_frame_layout
.frame_size
)
8070 if (cfun_frame_layout
.frame_size
>= s390_stack_size
)
8072 warning (0, "frame size of function %qs is "
8073 HOST_WIDE_INT_PRINT_DEC
8074 " bytes exceeding user provided stack limit of "
8075 HOST_WIDE_INT_PRINT_DEC
" bytes. "
8076 "An unconditional trap is added.",
8077 current_function_name(), cfun_frame_layout
.frame_size
,
8079 emit_insn (gen_trap ());
8083 /* stack_guard has to be smaller than s390_stack_size.
8084 Otherwise we would emit an AND with zero which would
8085 not match the test under mask pattern. */
8086 if (stack_guard
>= s390_stack_size
)
8088 warning (0, "frame size of function %qs is "
8089 HOST_WIDE_INT_PRINT_DEC
8090 " bytes which is more than half the stack size. "
8091 "The dynamic check would not be reliable. "
8092 "No check emitted for this function.",
8093 current_function_name(),
8094 cfun_frame_layout
.frame_size
);
8098 HOST_WIDE_INT stack_check_mask
= ((s390_stack_size
- 1)
8099 & ~(stack_guard
- 1));
8101 rtx t
= gen_rtx_AND (Pmode
, stack_pointer_rtx
,
8102 GEN_INT (stack_check_mask
));
8104 emit_insn (gen_ctrapdi4 (gen_rtx_EQ (VOIDmode
,
8106 t
, const0_rtx
, const0_rtx
));
8108 emit_insn (gen_ctrapsi4 (gen_rtx_EQ (VOIDmode
,
8110 t
, const0_rtx
, const0_rtx
));
8115 if (s390_warn_framesize
> 0
8116 && cfun_frame_layout
.frame_size
>= s390_warn_framesize
)
8117 warning (0, "frame size of %qs is " HOST_WIDE_INT_PRINT_DEC
" bytes",
8118 current_function_name (), cfun_frame_layout
.frame_size
);
8120 if (s390_warn_dynamicstack_p
&& cfun
->calls_alloca
)
8121 warning (0, "%qs uses dynamic stack allocation", current_function_name ());
8123 /* Save incoming stack pointer into temp reg. */
8124 if (TARGET_BACKCHAIN
|| next_fpr
)
8125 insn
= emit_insn (gen_move_insn (temp_reg
, stack_pointer_rtx
));
8127 /* Subtract frame size from stack pointer. */
8129 if (DISP_IN_RANGE (INTVAL (frame_off
)))
8131 insn
= gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
8132 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
8134 insn
= emit_insn (insn
);
8138 if (!CONST_OK_FOR_K (INTVAL (frame_off
)))
8139 frame_off
= force_const_mem (Pmode
, frame_off
);
8141 insn
= emit_insn (gen_add2_insn (stack_pointer_rtx
, frame_off
));
8142 annotate_constant_pool_refs (&PATTERN (insn
));
8145 RTX_FRAME_RELATED_P (insn
) = 1;
8146 real_frame_off
= GEN_INT (-cfun_frame_layout
.frame_size
);
8147 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
,
8148 gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
8149 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
8152 /* Set backchain. */
8154 if (TARGET_BACKCHAIN
)
8156 if (cfun_frame_layout
.backchain_offset
)
8157 addr
= gen_rtx_MEM (Pmode
,
8158 plus_constant (stack_pointer_rtx
,
8159 cfun_frame_layout
.backchain_offset
));
8161 addr
= gen_rtx_MEM (Pmode
, stack_pointer_rtx
);
8162 set_mem_alias_set (addr
, get_frame_alias_set ());
8163 insn
= emit_insn (gen_move_insn (addr
, temp_reg
));
8166 /* If we support non-call exceptions (e.g. for Java),
8167 we need to make sure the backchain pointer is set up
8168 before any possibly trapping memory access. */
8169 if (TARGET_BACKCHAIN
&& cfun
->can_throw_non_call_exceptions
)
8171 addr
= gen_rtx_MEM (BLKmode
, gen_rtx_SCRATCH (VOIDmode
));
8172 emit_clobber (addr
);
8176 /* Save fprs 8 - 15 (64 bit ABI). */
8178 if (cfun_save_high_fprs_p
&& next_fpr
)
8180 /* If the stack might be accessed through a different register
8181 we have to make sure that the stack pointer decrement is not
8182 moved below the use of the stack slots. */
8183 s390_emit_stack_tie ();
8185 insn
= emit_insn (gen_add2_insn (temp_reg
,
8186 GEN_INT (cfun_frame_layout
.f8_offset
)));
8190 for (i
= 24; i
<= next_fpr
; i
++)
8191 if (cfun_fpr_bit_p (i
- 16))
8193 rtx addr
= plus_constant (stack_pointer_rtx
,
8194 cfun_frame_layout
.frame_size
8195 + cfun_frame_layout
.f8_offset
8198 insn
= save_fpr (temp_reg
, offset
, i
);
8200 RTX_FRAME_RELATED_P (insn
) = 1;
8201 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
,
8202 gen_rtx_SET (VOIDmode
,
8203 gen_rtx_MEM (DFmode
, addr
),
8204 gen_rtx_REG (DFmode
, i
)));
8208 /* Set frame pointer, if needed. */
8210 if (frame_pointer_needed
)
8212 insn
= emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
);
8213 RTX_FRAME_RELATED_P (insn
) = 1;
8216 /* Set up got pointer, if needed. */
8218 if (flag_pic
&& df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM
))
8220 rtx insns
= s390_load_got ();
8222 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
8223 annotate_constant_pool_refs (&PATTERN (insn
));
8228 if (TARGET_TPF_PROFILING
)
8230 /* Generate a BAS instruction to serve as a function
8231 entry intercept to facilitate the use of tracing
8232 algorithms located at the branch target. */
8233 emit_insn (gen_prologue_tpf ());
8235 /* Emit a blockage here so that all code
8236 lies between the profiling mechanisms. */
8237 emit_insn (gen_blockage ());
8241 /* Expand the epilogue into a bunch of separate insns. */
8244 s390_emit_epilogue (bool sibcall
)
8246 rtx frame_pointer
, return_reg
, cfa_restores
= NULL_RTX
;
8247 int area_bottom
, area_top
, offset
= 0;
8252 if (TARGET_TPF_PROFILING
)
8255 /* Generate a BAS instruction to serve as a function
8256 entry intercept to facilitate the use of tracing
8257 algorithms located at the branch target. */
8259 /* Emit a blockage here so that all code
8260 lies between the profiling mechanisms. */
8261 emit_insn (gen_blockage ());
8263 emit_insn (gen_epilogue_tpf ());
8266 /* Check whether to use frame or stack pointer for restore. */
8268 frame_pointer
= (frame_pointer_needed
8269 ? hard_frame_pointer_rtx
: stack_pointer_rtx
);
8271 s390_frame_area (&area_bottom
, &area_top
);
8273 /* Check whether we can access the register save area.
8274 If not, increment the frame pointer as required. */
8276 if (area_top
<= area_bottom
)
8278 /* Nothing to restore. */
8280 else if (DISP_IN_RANGE (cfun_frame_layout
.frame_size
+ area_bottom
)
8281 && DISP_IN_RANGE (cfun_frame_layout
.frame_size
+ area_top
- 1))
8283 /* Area is in range. */
8284 offset
= cfun_frame_layout
.frame_size
;
8288 rtx insn
, frame_off
, cfa
;
8290 offset
= area_bottom
< 0 ? -area_bottom
: 0;
8291 frame_off
= GEN_INT (cfun_frame_layout
.frame_size
- offset
);
8293 cfa
= gen_rtx_SET (VOIDmode
, frame_pointer
,
8294 gen_rtx_PLUS (Pmode
, frame_pointer
, frame_off
));
8295 if (DISP_IN_RANGE (INTVAL (frame_off
)))
8297 insn
= gen_rtx_SET (VOIDmode
, frame_pointer
,
8298 gen_rtx_PLUS (Pmode
, frame_pointer
, frame_off
));
8299 insn
= emit_insn (insn
);
8303 if (!CONST_OK_FOR_K (INTVAL (frame_off
)))
8304 frame_off
= force_const_mem (Pmode
, frame_off
);
8306 insn
= emit_insn (gen_add2_insn (frame_pointer
, frame_off
));
8307 annotate_constant_pool_refs (&PATTERN (insn
));
8309 add_reg_note (insn
, REG_CFA_ADJUST_CFA
, cfa
);
8310 RTX_FRAME_RELATED_P (insn
) = 1;
8313 /* Restore call saved fprs. */
8317 if (cfun_save_high_fprs_p
)
8319 next_offset
= cfun_frame_layout
.f8_offset
;
8320 for (i
= 24; i
< 32; i
++)
8322 if (cfun_fpr_bit_p (i
- 16))
8324 restore_fpr (frame_pointer
,
8325 offset
+ next_offset
, i
);
8327 = alloc_reg_note (REG_CFA_RESTORE
,
8328 gen_rtx_REG (DFmode
, i
), cfa_restores
);
8337 next_offset
= cfun_frame_layout
.f4_offset
;
8338 for (i
= 18; i
< 20; i
++)
8340 if (cfun_fpr_bit_p (i
- 16))
8342 restore_fpr (frame_pointer
,
8343 offset
+ next_offset
, i
);
8345 = alloc_reg_note (REG_CFA_RESTORE
,
8346 gen_rtx_REG (DFmode
, i
), cfa_restores
);
8349 else if (!TARGET_PACKED_STACK
)
8355 /* Return register. */
8357 return_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
8359 /* Restore call saved gprs. */
8361 if (cfun_frame_layout
.first_restore_gpr
!= -1)
8366 /* Check for global register and save them
8367 to stack location from where they get restored. */
8369 for (i
= cfun_frame_layout
.first_restore_gpr
;
8370 i
<= cfun_frame_layout
.last_restore_gpr
;
8373 if (global_not_special_regno_p (i
))
8375 addr
= plus_constant (frame_pointer
,
8376 offset
+ cfun_frame_layout
.gprs_offset
8377 + (i
- cfun_frame_layout
.first_save_gpr_slot
)
8379 addr
= gen_rtx_MEM (Pmode
, addr
);
8380 set_mem_alias_set (addr
, get_frame_alias_set ());
8381 emit_move_insn (addr
, gen_rtx_REG (Pmode
, i
));
8385 = alloc_reg_note (REG_CFA_RESTORE
,
8386 gen_rtx_REG (Pmode
, i
), cfa_restores
);
8391 /* Fetch return address from stack before load multiple,
8392 this will do good for scheduling. */
8394 if (cfun_frame_layout
.save_return_addr_p
8395 || (cfun_frame_layout
.first_restore_gpr
< BASE_REGNUM
8396 && cfun_frame_layout
.last_restore_gpr
> RETURN_REGNUM
))
8398 int return_regnum
= find_unused_clobbered_reg();
8401 return_reg
= gen_rtx_REG (Pmode
, return_regnum
);
8403 addr
= plus_constant (frame_pointer
,
8404 offset
+ cfun_frame_layout
.gprs_offset
8406 - cfun_frame_layout
.first_save_gpr_slot
)
8408 addr
= gen_rtx_MEM (Pmode
, addr
);
8409 set_mem_alias_set (addr
, get_frame_alias_set ());
8410 emit_move_insn (return_reg
, addr
);
8414 insn
= restore_gprs (frame_pointer
,
8415 offset
+ cfun_frame_layout
.gprs_offset
8416 + (cfun_frame_layout
.first_restore_gpr
8417 - cfun_frame_layout
.first_save_gpr_slot
)
8419 cfun_frame_layout
.first_restore_gpr
,
8420 cfun_frame_layout
.last_restore_gpr
);
8421 insn
= emit_insn (insn
);
8422 REG_NOTES (insn
) = cfa_restores
;
8423 add_reg_note (insn
, REG_CFA_DEF_CFA
,
8424 plus_constant (stack_pointer_rtx
, STACK_POINTER_OFFSET
));
8425 RTX_FRAME_RELATED_P (insn
) = 1;
8431 /* Return to caller. */
8433 p
= rtvec_alloc (2);
8435 RTVEC_ELT (p
, 0) = gen_rtx_RETURN (VOIDmode
);
8436 RTVEC_ELT (p
, 1) = gen_rtx_USE (VOIDmode
, return_reg
);
8437 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
8442 /* Return the size in bytes of a function argument of
8443 type TYPE and/or mode MODE. At least one of TYPE or
8444 MODE must be specified. */
8447 s390_function_arg_size (enum machine_mode mode
, const_tree type
)
8450 return int_size_in_bytes (type
);
8452 /* No type info available for some library calls ... */
8453 if (mode
!= BLKmode
)
8454 return GET_MODE_SIZE (mode
);
8456 /* If we have neither type nor mode, abort */
8460 /* Return true if a function argument of type TYPE and mode MODE
8461 is to be passed in a floating-point register, if available. */
8464 s390_function_arg_float (enum machine_mode mode
, const_tree type
)
8466 int size
= s390_function_arg_size (mode
, type
);
8470 /* Soft-float changes the ABI: no floating-point registers are used. */
8471 if (TARGET_SOFT_FLOAT
)
8474 /* No type info available for some library calls ... */
8476 return mode
== SFmode
|| mode
== DFmode
|| mode
== SDmode
|| mode
== DDmode
;
8478 /* The ABI says that record types with a single member are treated
8479 just like that member would be. */
8480 while (TREE_CODE (type
) == RECORD_TYPE
)
8482 tree field
, single
= NULL_TREE
;
8484 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
8486 if (TREE_CODE (field
) != FIELD_DECL
)
8489 if (single
== NULL_TREE
)
8490 single
= TREE_TYPE (field
);
8495 if (single
== NULL_TREE
)
8501 return TREE_CODE (type
) == REAL_TYPE
;
8504 /* Return true if a function argument of type TYPE and mode MODE
8505 is to be passed in an integer register, or a pair of integer
8506 registers, if available. */
8509 s390_function_arg_integer (enum machine_mode mode
, const_tree type
)
8511 int size
= s390_function_arg_size (mode
, type
);
8515 /* No type info available for some library calls ... */
8517 return GET_MODE_CLASS (mode
) == MODE_INT
8518 || (TARGET_SOFT_FLOAT
&& SCALAR_FLOAT_MODE_P (mode
));
8520 /* We accept small integral (and similar) types. */
8521 if (INTEGRAL_TYPE_P (type
)
8522 || POINTER_TYPE_P (type
)
8523 || TREE_CODE (type
) == NULLPTR_TYPE
8524 || TREE_CODE (type
) == OFFSET_TYPE
8525 || (TARGET_SOFT_FLOAT
&& TREE_CODE (type
) == REAL_TYPE
))
8528 /* We also accept structs of size 1, 2, 4, 8 that are not
8529 passed in floating-point registers. */
8530 if (AGGREGATE_TYPE_P (type
)
8531 && exact_log2 (size
) >= 0
8532 && !s390_function_arg_float (mode
, type
))
8538 /* Return 1 if a function argument of type TYPE and mode MODE
8539 is to be passed by reference. The ABI specifies that only
8540 structures of size 1, 2, 4, or 8 bytes are passed by value,
8541 all other structures (and complex numbers) are passed by
8545 s390_pass_by_reference (CUMULATIVE_ARGS
*ca ATTRIBUTE_UNUSED
,
8546 enum machine_mode mode
, const_tree type
,
8547 bool named ATTRIBUTE_UNUSED
)
8549 int size
= s390_function_arg_size (mode
, type
);
8555 if (AGGREGATE_TYPE_P (type
) && exact_log2 (size
) < 0)
8558 if (TREE_CODE (type
) == COMPLEX_TYPE
8559 || TREE_CODE (type
) == VECTOR_TYPE
)
8566 /* Update the data in CUM to advance over an argument of mode MODE and
8567 data type TYPE. (TYPE is null for libcalls where that information
8568 may not be available.). The boolean NAMED specifies whether the
8569 argument is a named argument (as opposed to an unnamed argument
8570 matching an ellipsis). */
8573 s390_function_arg_advance (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
,
8574 const_tree type
, bool named ATTRIBUTE_UNUSED
)
8576 if (s390_function_arg_float (mode
, type
))
8580 else if (s390_function_arg_integer (mode
, type
))
8582 int size
= s390_function_arg_size (mode
, type
);
8583 cum
->gprs
+= ((size
+ UNITS_PER_LONG
- 1) / UNITS_PER_LONG
);
8589 /* Define where to put the arguments to a function.
8590 Value is zero to push the argument on the stack,
8591 or a hard register in which to store the argument.
8593 MODE is the argument's machine mode.
8594 TYPE is the data type of the argument (as a tree).
8595 This is null for libcalls where that information may
8597 CUM is a variable of type CUMULATIVE_ARGS which gives info about
8598 the preceding args and about the function being called.
8599 NAMED is nonzero if this argument is a named parameter
8600 (otherwise it is an extra parameter matching an ellipsis).
8602 On S/390, we use general purpose registers 2 through 6 to
8603 pass integer, pointer, and certain structure arguments, and
8604 floating point registers 0 and 2 (0, 2, 4, and 6 on 64-bit)
8605 to pass floating point arguments. All remaining arguments
8606 are pushed to the stack. */
8609 s390_function_arg (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
,
8610 const_tree type
, bool named ATTRIBUTE_UNUSED
)
8612 if (s390_function_arg_float (mode
, type
))
8614 if (cum
->fprs
+ 1 > FP_ARG_NUM_REG
)
8617 return gen_rtx_REG (mode
, cum
->fprs
+ 16);
8619 else if (s390_function_arg_integer (mode
, type
))
8621 int size
= s390_function_arg_size (mode
, type
);
8622 int n_gprs
= (size
+ UNITS_PER_LONG
- 1) / UNITS_PER_LONG
;
8624 if (cum
->gprs
+ n_gprs
> GP_ARG_NUM_REG
)
8626 else if (n_gprs
== 1 || UNITS_PER_WORD
== UNITS_PER_LONG
)
8627 return gen_rtx_REG (mode
, cum
->gprs
+ 2);
8628 else if (n_gprs
== 2)
8630 rtvec p
= rtvec_alloc (2);
8633 = gen_rtx_EXPR_LIST (SImode
, gen_rtx_REG (SImode
, cum
->gprs
+ 2),
8636 = gen_rtx_EXPR_LIST (SImode
, gen_rtx_REG (SImode
, cum
->gprs
+ 3),
8639 return gen_rtx_PARALLEL (mode
, p
);
8643 /* After the real arguments, expand_call calls us once again
8644 with a void_type_node type. Whatever we return here is
8645 passed as operand 2 to the call expanders.
8647 We don't need this feature ... */
8648 else if (type
== void_type_node
)
8654 /* Return true if return values of type TYPE should be returned
8655 in a memory buffer whose address is passed by the caller as
8656 hidden first argument. */
8659 s390_return_in_memory (const_tree type
, const_tree fundecl ATTRIBUTE_UNUSED
)
8661 /* We accept small integral (and similar) types. */
8662 if (INTEGRAL_TYPE_P (type
)
8663 || POINTER_TYPE_P (type
)
8664 || TREE_CODE (type
) == OFFSET_TYPE
8665 || TREE_CODE (type
) == REAL_TYPE
)
8666 return int_size_in_bytes (type
) > 8;
8668 /* Aggregates and similar constructs are always returned
8670 if (AGGREGATE_TYPE_P (type
)
8671 || TREE_CODE (type
) == COMPLEX_TYPE
8672 || TREE_CODE (type
) == VECTOR_TYPE
)
8675 /* ??? We get called on all sorts of random stuff from
8676 aggregate_value_p. We can't abort, but it's not clear
8677 what's safe to return. Pretend it's a struct I guess. */
8681 /* Function arguments and return values are promoted to word size. */
8683 static enum machine_mode
8684 s390_promote_function_mode (const_tree type
, enum machine_mode mode
,
8686 const_tree fntype ATTRIBUTE_UNUSED
,
8687 int for_return ATTRIBUTE_UNUSED
)
8689 if (INTEGRAL_MODE_P (mode
)
8690 && GET_MODE_SIZE (mode
) < UNITS_PER_LONG
)
8692 if (POINTER_TYPE_P (type
))
8693 *punsignedp
= POINTERS_EXTEND_UNSIGNED
;
8700 /* Define where to return a (scalar) value of type RET_TYPE.
8701 If RET_TYPE is null, define where to return a (scalar)
8702 value of mode MODE from a libcall. */
8705 s390_function_and_libcall_value (enum machine_mode mode
,
8706 const_tree ret_type
,
8707 const_tree fntype_or_decl
,
8708 bool outgoing ATTRIBUTE_UNUSED
)
8710 /* For normal functions perform the promotion as
8711 promote_function_mode would do. */
8714 int unsignedp
= TYPE_UNSIGNED (ret_type
);
8715 mode
= promote_function_mode (ret_type
, mode
, &unsignedp
,
8719 gcc_assert (GET_MODE_CLASS (mode
) == MODE_INT
|| SCALAR_FLOAT_MODE_P (mode
));
8720 gcc_assert (GET_MODE_SIZE (mode
) <= 8);
8722 if (TARGET_HARD_FLOAT
&& SCALAR_FLOAT_MODE_P (mode
))
8723 return gen_rtx_REG (mode
, 16);
8724 else if (GET_MODE_SIZE (mode
) <= UNITS_PER_LONG
8725 || UNITS_PER_LONG
== UNITS_PER_WORD
)
8726 return gen_rtx_REG (mode
, 2);
8727 else if (GET_MODE_SIZE (mode
) == 2 * UNITS_PER_LONG
)
8729 /* This case is triggered when returning a 64 bit value with
8730 -m31 -mzarch. Although the value would fit into a single
8731 register it has to be forced into a 32 bit register pair in
8732 order to match the ABI. */
8733 rtvec p
= rtvec_alloc (2);
8736 = gen_rtx_EXPR_LIST (SImode
, gen_rtx_REG (SImode
, 2), const0_rtx
);
8738 = gen_rtx_EXPR_LIST (SImode
, gen_rtx_REG (SImode
, 3), GEN_INT (4));
8740 return gen_rtx_PARALLEL (mode
, p
);
8746 /* Define where to return a scalar return value of type RET_TYPE. */
8749 s390_function_value (const_tree ret_type
, const_tree fn_decl_or_type
,
8752 return s390_function_and_libcall_value (TYPE_MODE (ret_type
), ret_type
,
8753 fn_decl_or_type
, outgoing
);
8756 /* Define where to return a scalar libcall return value of mode
8760 s390_libcall_value (enum machine_mode mode
, const_rtx fun ATTRIBUTE_UNUSED
)
8762 return s390_function_and_libcall_value (mode
, NULL_TREE
,
8767 /* Create and return the va_list datatype.
8769 On S/390, va_list is an array type equivalent to
8771 typedef struct __va_list_tag
8775 void *__overflow_arg_area;
8776 void *__reg_save_area;
8779 where __gpr and __fpr hold the number of general purpose
8780 or floating point arguments used up to now, respectively,
8781 __overflow_arg_area points to the stack location of the
8782 next argument passed on the stack, and __reg_save_area
8783 always points to the start of the register area in the
8784 call frame of the current function. The function prologue
8785 saves all registers used for argument passing into this
8786 area if the function uses variable arguments. */
8789 s390_build_builtin_va_list (void)
8791 tree f_gpr
, f_fpr
, f_ovf
, f_sav
, record
, type_decl
;
8793 record
= lang_hooks
.types
.make_type (RECORD_TYPE
);
8796 build_decl (BUILTINS_LOCATION
,
8797 TYPE_DECL
, get_identifier ("__va_list_tag"), record
);
8799 f_gpr
= build_decl (BUILTINS_LOCATION
,
8800 FIELD_DECL
, get_identifier ("__gpr"),
8801 long_integer_type_node
);
8802 f_fpr
= build_decl (BUILTINS_LOCATION
,
8803 FIELD_DECL
, get_identifier ("__fpr"),
8804 long_integer_type_node
);
8805 f_ovf
= build_decl (BUILTINS_LOCATION
,
8806 FIELD_DECL
, get_identifier ("__overflow_arg_area"),
8808 f_sav
= build_decl (BUILTINS_LOCATION
,
8809 FIELD_DECL
, get_identifier ("__reg_save_area"),
8812 va_list_gpr_counter_field
= f_gpr
;
8813 va_list_fpr_counter_field
= f_fpr
;
8815 DECL_FIELD_CONTEXT (f_gpr
) = record
;
8816 DECL_FIELD_CONTEXT (f_fpr
) = record
;
8817 DECL_FIELD_CONTEXT (f_ovf
) = record
;
8818 DECL_FIELD_CONTEXT (f_sav
) = record
;
8820 TYPE_STUB_DECL (record
) = type_decl
;
8821 TYPE_NAME (record
) = type_decl
;
8822 TYPE_FIELDS (record
) = f_gpr
;
8823 DECL_CHAIN (f_gpr
) = f_fpr
;
8824 DECL_CHAIN (f_fpr
) = f_ovf
;
8825 DECL_CHAIN (f_ovf
) = f_sav
;
8827 layout_type (record
);
8829 /* The correct type is an array type of one element. */
8830 return build_array_type (record
, build_index_type (size_zero_node
));
8833 /* Implement va_start by filling the va_list structure VALIST.
8834 STDARG_P is always true, and ignored.
8835 NEXTARG points to the first anonymous stack argument.
8837 The following global variables are used to initialize
8838 the va_list structure:
8841 holds number of gprs and fprs used for named arguments.
8842 crtl->args.arg_offset_rtx:
8843 holds the offset of the first anonymous stack argument
8844 (relative to the virtual arg pointer). */
8847 s390_va_start (tree valist
, rtx nextarg ATTRIBUTE_UNUSED
)
8849 HOST_WIDE_INT n_gpr
, n_fpr
;
8851 tree f_gpr
, f_fpr
, f_ovf
, f_sav
;
8852 tree gpr
, fpr
, ovf
, sav
, t
;
8854 f_gpr
= TYPE_FIELDS (TREE_TYPE (va_list_type_node
));
8855 f_fpr
= DECL_CHAIN (f_gpr
);
8856 f_ovf
= DECL_CHAIN (f_fpr
);
8857 f_sav
= DECL_CHAIN (f_ovf
);
8859 valist
= build_simple_mem_ref (valist
);
8860 gpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_gpr
), valist
, f_gpr
, NULL_TREE
);
8861 fpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_fpr
), valist
, f_fpr
, NULL_TREE
);
8862 ovf
= build3 (COMPONENT_REF
, TREE_TYPE (f_ovf
), valist
, f_ovf
, NULL_TREE
);
8863 sav
= build3 (COMPONENT_REF
, TREE_TYPE (f_sav
), valist
, f_sav
, NULL_TREE
);
8865 /* Count number of gp and fp argument registers used. */
8867 n_gpr
= crtl
->args
.info
.gprs
;
8868 n_fpr
= crtl
->args
.info
.fprs
;
8870 if (cfun
->va_list_gpr_size
)
8872 t
= build2 (MODIFY_EXPR
, TREE_TYPE (gpr
), gpr
,
8873 build_int_cst (NULL_TREE
, n_gpr
));
8874 TREE_SIDE_EFFECTS (t
) = 1;
8875 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
8878 if (cfun
->va_list_fpr_size
)
8880 t
= build2 (MODIFY_EXPR
, TREE_TYPE (fpr
), fpr
,
8881 build_int_cst (NULL_TREE
, n_fpr
));
8882 TREE_SIDE_EFFECTS (t
) = 1;
8883 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
8886 /* Find the overflow area. */
8887 if (n_gpr
+ cfun
->va_list_gpr_size
> GP_ARG_NUM_REG
8888 || n_fpr
+ cfun
->va_list_fpr_size
> FP_ARG_NUM_REG
)
8890 t
= make_tree (TREE_TYPE (ovf
), virtual_incoming_args_rtx
);
8892 off
= INTVAL (crtl
->args
.arg_offset_rtx
);
8893 off
= off
< 0 ? 0 : off
;
8894 if (TARGET_DEBUG_ARG
)
8895 fprintf (stderr
, "va_start: n_gpr = %d, n_fpr = %d off %d\n",
8896 (int)n_gpr
, (int)n_fpr
, off
);
8898 t
= build2 (POINTER_PLUS_EXPR
, TREE_TYPE (ovf
), t
, size_int (off
));
8900 t
= build2 (MODIFY_EXPR
, TREE_TYPE (ovf
), ovf
, t
);
8901 TREE_SIDE_EFFECTS (t
) = 1;
8902 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
8905 /* Find the register save area. */
8906 if ((cfun
->va_list_gpr_size
&& n_gpr
< GP_ARG_NUM_REG
)
8907 || (cfun
->va_list_fpr_size
&& n_fpr
< FP_ARG_NUM_REG
))
8909 t
= make_tree (TREE_TYPE (sav
), return_address_pointer_rtx
);
8910 t
= build2 (POINTER_PLUS_EXPR
, TREE_TYPE (sav
), t
,
8911 size_int (-RETURN_REGNUM
* UNITS_PER_LONG
));
8913 t
= build2 (MODIFY_EXPR
, TREE_TYPE (sav
), sav
, t
);
8914 TREE_SIDE_EFFECTS (t
) = 1;
8915 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
8919 /* Implement va_arg by updating the va_list structure
8920 VALIST as required to retrieve an argument of type
8921 TYPE, and returning that argument.
8923 Generates code equivalent to:
8925 if (integral value) {
8926 if (size <= 4 && args.gpr < 5 ||
8927 size > 4 && args.gpr < 4 )
8928 ret = args.reg_save_area[args.gpr+8]
8930 ret = *args.overflow_arg_area++;
8931 } else if (float value) {
8933 ret = args.reg_save_area[args.fpr+64]
8935 ret = *args.overflow_arg_area++;
8936 } else if (aggregate value) {
8938 ret = *args.reg_save_area[args.gpr]
8940 ret = **args.overflow_arg_area++;
8944 s390_gimplify_va_arg (tree valist
, tree type
, gimple_seq
*pre_p
,
8945 gimple_seq
*post_p ATTRIBUTE_UNUSED
)
8947 tree f_gpr
, f_fpr
, f_ovf
, f_sav
;
8948 tree gpr
, fpr
, ovf
, sav
, reg
, t
, u
;
8949 int indirect_p
, size
, n_reg
, sav_ofs
, sav_scale
, max_reg
;
8950 tree lab_false
, lab_over
, addr
;
8952 f_gpr
= TYPE_FIELDS (TREE_TYPE (va_list_type_node
));
8953 f_fpr
= DECL_CHAIN (f_gpr
);
8954 f_ovf
= DECL_CHAIN (f_fpr
);
8955 f_sav
= DECL_CHAIN (f_ovf
);
8957 valist
= build_va_arg_indirect_ref (valist
);
8958 gpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_gpr
), valist
, f_gpr
, NULL_TREE
);
8959 fpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_fpr
), valist
, f_fpr
, NULL_TREE
);
8960 sav
= build3 (COMPONENT_REF
, TREE_TYPE (f_sav
), valist
, f_sav
, NULL_TREE
);
8962 /* The tree for args* cannot be shared between gpr/fpr and ovf since
8963 both appear on a lhs. */
8964 valist
= unshare_expr (valist
);
8965 ovf
= build3 (COMPONENT_REF
, TREE_TYPE (f_ovf
), valist
, f_ovf
, NULL_TREE
);
8967 size
= int_size_in_bytes (type
);
8969 if (pass_by_reference (NULL
, TYPE_MODE (type
), type
, false))
8971 if (TARGET_DEBUG_ARG
)
8973 fprintf (stderr
, "va_arg: aggregate type");
8977 /* Aggregates are passed by reference. */
8982 /* kernel stack layout on 31 bit: It is assumed here that no padding
8983 will be added by s390_frame_info because for va_args always an even
8984 number of gprs has to be saved r15-r2 = 14 regs. */
8985 sav_ofs
= 2 * UNITS_PER_LONG
;
8986 sav_scale
= UNITS_PER_LONG
;
8987 size
= UNITS_PER_LONG
;
8988 max_reg
= GP_ARG_NUM_REG
- n_reg
;
8990 else if (s390_function_arg_float (TYPE_MODE (type
), type
))
8992 if (TARGET_DEBUG_ARG
)
8994 fprintf (stderr
, "va_arg: float type");
8998 /* FP args go in FP registers, if present. */
9002 sav_ofs
= 16 * UNITS_PER_LONG
;
9004 max_reg
= FP_ARG_NUM_REG
- n_reg
;
9008 if (TARGET_DEBUG_ARG
)
9010 fprintf (stderr
, "va_arg: other type");
9014 /* Otherwise into GP registers. */
9017 n_reg
= (size
+ UNITS_PER_LONG
- 1) / UNITS_PER_LONG
;
9019 /* kernel stack layout on 31 bit: It is assumed here that no padding
9020 will be added by s390_frame_info because for va_args always an even
9021 number of gprs has to be saved r15-r2 = 14 regs. */
9022 sav_ofs
= 2 * UNITS_PER_LONG
;
9024 if (size
< UNITS_PER_LONG
)
9025 sav_ofs
+= UNITS_PER_LONG
- size
;
9027 sav_scale
= UNITS_PER_LONG
;
9028 max_reg
= GP_ARG_NUM_REG
- n_reg
;
9031 /* Pull the value out of the saved registers ... */
9033 lab_false
= create_artificial_label (UNKNOWN_LOCATION
);
9034 lab_over
= create_artificial_label (UNKNOWN_LOCATION
);
9035 addr
= create_tmp_var (ptr_type_node
, "addr");
9037 t
= fold_convert (TREE_TYPE (reg
), size_int (max_reg
));
9038 t
= build2 (GT_EXPR
, boolean_type_node
, reg
, t
);
9039 u
= build1 (GOTO_EXPR
, void_type_node
, lab_false
);
9040 t
= build3 (COND_EXPR
, void_type_node
, t
, u
, NULL_TREE
);
9041 gimplify_and_add (t
, pre_p
);
9043 t
= build2 (POINTER_PLUS_EXPR
, ptr_type_node
, sav
,
9044 size_int (sav_ofs
));
9045 u
= build2 (MULT_EXPR
, TREE_TYPE (reg
), reg
,
9046 fold_convert (TREE_TYPE (reg
), size_int (sav_scale
)));
9047 t
= build2 (POINTER_PLUS_EXPR
, ptr_type_node
, t
, fold_convert (sizetype
, u
));
9049 gimplify_assign (addr
, t
, pre_p
);
9051 gimple_seq_add_stmt (pre_p
, gimple_build_goto (lab_over
));
9053 gimple_seq_add_stmt (pre_p
, gimple_build_label (lab_false
));
9056 /* ... Otherwise out of the overflow area. */
9059 if (size
< UNITS_PER_LONG
)
9060 t
= build2 (POINTER_PLUS_EXPR
, ptr_type_node
, t
,
9061 size_int (UNITS_PER_LONG
- size
));
9063 gimplify_expr (&t
, pre_p
, NULL
, is_gimple_val
, fb_rvalue
);
9065 gimplify_assign (addr
, t
, pre_p
);
9067 t
= build2 (POINTER_PLUS_EXPR
, ptr_type_node
, t
,
9069 gimplify_assign (ovf
, t
, pre_p
);
9071 gimple_seq_add_stmt (pre_p
, gimple_build_label (lab_over
));
9074 /* Increment register save count. */
9076 u
= build2 (PREINCREMENT_EXPR
, TREE_TYPE (reg
), reg
,
9077 fold_convert (TREE_TYPE (reg
), size_int (n_reg
)));
9078 gimplify_and_add (u
, pre_p
);
9082 t
= build_pointer_type_for_mode (build_pointer_type (type
),
9084 addr
= fold_convert (t
, addr
);
9085 addr
= build_va_arg_indirect_ref (addr
);
9089 t
= build_pointer_type_for_mode (type
, ptr_mode
, true);
9090 addr
= fold_convert (t
, addr
);
9093 return build_va_arg_indirect_ref (addr
);
9101 S390_BUILTIN_THREAD_POINTER
,
9102 S390_BUILTIN_SET_THREAD_POINTER
,
9107 static enum insn_code
const code_for_builtin_64
[S390_BUILTIN_max
] = {
9112 static enum insn_code
const code_for_builtin_31
[S390_BUILTIN_max
] = {
9118 s390_init_builtins (void)
9122 ftype
= build_function_type (ptr_type_node
, void_list_node
);
9123 add_builtin_function ("__builtin_thread_pointer", ftype
,
9124 S390_BUILTIN_THREAD_POINTER
, BUILT_IN_MD
,
9127 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
9128 add_builtin_function ("__builtin_set_thread_pointer", ftype
,
9129 S390_BUILTIN_SET_THREAD_POINTER
, BUILT_IN_MD
,
9133 /* Expand an expression EXP that calls a built-in function,
9134 with result going to TARGET if that's convenient
9135 (and in mode MODE if that's convenient).
9136 SUBTARGET may be used as the target for computing one of EXP's operands.
9137 IGNORE is nonzero if the value is to be ignored. */
9140 s390_expand_builtin (tree exp
, rtx target
, rtx subtarget ATTRIBUTE_UNUSED
,
9141 enum machine_mode mode ATTRIBUTE_UNUSED
,
9142 int ignore ATTRIBUTE_UNUSED
)
9146 enum insn_code
const *code_for_builtin
=
9147 TARGET_64BIT
? code_for_builtin_64
: code_for_builtin_31
;
9149 tree fndecl
= TREE_OPERAND (CALL_EXPR_FN (exp
), 0);
9150 unsigned int fcode
= DECL_FUNCTION_CODE (fndecl
);
9151 enum insn_code icode
;
9152 rtx op
[MAX_ARGS
], pat
;
9156 call_expr_arg_iterator iter
;
9158 if (fcode
>= S390_BUILTIN_max
)
9159 internal_error ("bad builtin fcode");
9160 icode
= code_for_builtin
[fcode
];
9162 internal_error ("bad builtin fcode");
9164 nonvoid
= TREE_TYPE (TREE_TYPE (fndecl
)) != void_type_node
;
9167 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, exp
)
9169 const struct insn_operand_data
*insn_op
;
9171 if (arg
== error_mark_node
)
9173 if (arity
> MAX_ARGS
)
9176 insn_op
= &insn_data
[icode
].operand
[arity
+ nonvoid
];
9178 op
[arity
] = expand_expr (arg
, NULL_RTX
, insn_op
->mode
, EXPAND_NORMAL
);
9180 if (!(*insn_op
->predicate
) (op
[arity
], insn_op
->mode
))
9181 op
[arity
] = copy_to_mode_reg (insn_op
->mode
, op
[arity
]);
9187 enum machine_mode tmode
= insn_data
[icode
].operand
[0].mode
;
9189 || GET_MODE (target
) != tmode
9190 || !(*insn_data
[icode
].operand
[0].predicate
) (target
, tmode
))
9191 target
= gen_reg_rtx (tmode
);
9197 pat
= GEN_FCN (icode
) (target
);
9201 pat
= GEN_FCN (icode
) (target
, op
[0]);
9203 pat
= GEN_FCN (icode
) (op
[0]);
9206 pat
= GEN_FCN (icode
) (target
, op
[0], op
[1]);
9222 /* Output assembly code for the trampoline template to
9225 On S/390, we use gpr 1 internally in the trampoline code;
9226 gpr 0 is used to hold the static chain. */
9229 s390_asm_trampoline_template (FILE *file
)
9232 op
[0] = gen_rtx_REG (Pmode
, 0);
9233 op
[1] = gen_rtx_REG (Pmode
, 1);
9237 output_asm_insn ("basr\t%1,0", op
);
9238 output_asm_insn ("lmg\t%0,%1,14(%1)", op
);
9239 output_asm_insn ("br\t%1", op
);
9240 ASM_OUTPUT_SKIP (file
, (HOST_WIDE_INT
)(TRAMPOLINE_SIZE
- 10));
9244 output_asm_insn ("basr\t%1,0", op
);
9245 output_asm_insn ("lm\t%0,%1,6(%1)", op
);
9246 output_asm_insn ("br\t%1", op
);
9247 ASM_OUTPUT_SKIP (file
, (HOST_WIDE_INT
)(TRAMPOLINE_SIZE
- 8));
9251 /* Emit RTL insns to initialize the variable parts of a trampoline.
9252 FNADDR is an RTX for the address of the function's pure code.
9253 CXT is an RTX for the static chain value for the function. */
9256 s390_trampoline_init (rtx m_tramp
, tree fndecl
, rtx cxt
)
9258 rtx fnaddr
= XEXP (DECL_RTL (fndecl
), 0);
9261 emit_block_move (m_tramp
, assemble_trampoline_template (),
9262 GEN_INT (2*UNITS_PER_WORD
), BLOCK_OP_NORMAL
);
9264 mem
= adjust_address (m_tramp
, Pmode
, 2*UNITS_PER_WORD
);
9265 emit_move_insn (mem
, cxt
);
9266 mem
= adjust_address (m_tramp
, Pmode
, 3*UNITS_PER_WORD
);
9267 emit_move_insn (mem
, fnaddr
);
9270 /* Output assembler code to FILE to increment profiler label # LABELNO
9271 for profiling a function entry. */
9274 s390_function_profiler (FILE *file
, int labelno
)
9279 ASM_GENERATE_INTERNAL_LABEL (label
, "LP", labelno
);
9281 fprintf (file
, "# function profiler \n");
9283 op
[0] = gen_rtx_REG (Pmode
, RETURN_REGNUM
);
9284 op
[1] = gen_rtx_REG (Pmode
, STACK_POINTER_REGNUM
);
9285 op
[1] = gen_rtx_MEM (Pmode
, plus_constant (op
[1], UNITS_PER_LONG
));
9287 op
[2] = gen_rtx_REG (Pmode
, 1);
9288 op
[3] = gen_rtx_SYMBOL_REF (Pmode
, label
);
9289 SYMBOL_REF_FLAGS (op
[3]) = SYMBOL_FLAG_LOCAL
;
9291 op
[4] = gen_rtx_SYMBOL_REF (Pmode
, "_mcount");
9294 op
[4] = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op
[4]), UNSPEC_PLT
);
9295 op
[4] = gen_rtx_CONST (Pmode
, op
[4]);
9300 output_asm_insn ("stg\t%0,%1", op
);
9301 output_asm_insn ("larl\t%2,%3", op
);
9302 output_asm_insn ("brasl\t%0,%4", op
);
9303 output_asm_insn ("lg\t%0,%1", op
);
9307 op
[6] = gen_label_rtx ();
9309 output_asm_insn ("st\t%0,%1", op
);
9310 output_asm_insn ("bras\t%2,%l6", op
);
9311 output_asm_insn (".long\t%4", op
);
9312 output_asm_insn (".long\t%3", op
);
9313 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[6]));
9314 output_asm_insn ("l\t%0,0(%2)", op
);
9315 output_asm_insn ("l\t%2,4(%2)", op
);
9316 output_asm_insn ("basr\t%0,%0", op
);
9317 output_asm_insn ("l\t%0,%1", op
);
9321 op
[5] = gen_label_rtx ();
9322 op
[6] = gen_label_rtx ();
9324 output_asm_insn ("st\t%0,%1", op
);
9325 output_asm_insn ("bras\t%2,%l6", op
);
9326 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[5]));
9327 output_asm_insn (".long\t%4-%l5", op
);
9328 output_asm_insn (".long\t%3-%l5", op
);
9329 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[6]));
9330 output_asm_insn ("lr\t%0,%2", op
);
9331 output_asm_insn ("a\t%0,0(%2)", op
);
9332 output_asm_insn ("a\t%2,4(%2)", op
);
9333 output_asm_insn ("basr\t%0,%0", op
);
9334 output_asm_insn ("l\t%0,%1", op
);
9338 /* Encode symbol attributes (local vs. global, tls model) of a SYMBOL_REF
9339 into its SYMBOL_REF_FLAGS. */
9342 s390_encode_section_info (tree decl
, rtx rtl
, int first
)
9344 default_encode_section_info (decl
, rtl
, first
);
9346 if (TREE_CODE (decl
) == VAR_DECL
)
9348 /* If a variable has a forced alignment to < 2 bytes, mark it
9349 with SYMBOL_FLAG_ALIGN1 to prevent it from being used as LARL
9351 if (DECL_USER_ALIGN (decl
) && DECL_ALIGN (decl
) < 16)
9352 SYMBOL_REF_FLAGS (XEXP (rtl
, 0)) |= SYMBOL_FLAG_ALIGN1
;
9353 if (!DECL_SIZE (decl
)
9354 || !DECL_ALIGN (decl
)
9355 || !host_integerp (DECL_SIZE (decl
), 0)
9356 || (DECL_ALIGN (decl
) <= 64
9357 && DECL_ALIGN (decl
) != tree_low_cst (DECL_SIZE (decl
), 0)))
9358 SYMBOL_REF_FLAGS (XEXP (rtl
, 0)) |= SYMBOL_FLAG_NOT_NATURALLY_ALIGNED
;
9361 /* Literal pool references don't have a decl so they are handled
9362 differently here. We rely on the information in the MEM_ALIGN
9363 entry to decide upon natural alignment. */
9365 && GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
9366 && TREE_CONSTANT_POOL_ADDRESS_P (XEXP (rtl
, 0))
9367 && (MEM_ALIGN (rtl
) == 0
9368 || GET_MODE_BITSIZE (GET_MODE (rtl
)) == 0
9369 || MEM_ALIGN (rtl
) < GET_MODE_BITSIZE (GET_MODE (rtl
))))
9370 SYMBOL_REF_FLAGS (XEXP (rtl
, 0)) |= SYMBOL_FLAG_NOT_NATURALLY_ALIGNED
;
9373 /* Output thunk to FILE that implements a C++ virtual function call (with
9374 multiple inheritance) to FUNCTION. The thunk adjusts the this pointer
9375 by DELTA, and unless VCALL_OFFSET is zero, applies an additional adjustment
9376 stored at VCALL_OFFSET in the vtable whose address is located at offset 0
9377 relative to the resulting this pointer. */
9380 s390_output_mi_thunk (FILE *file
, tree thunk ATTRIBUTE_UNUSED
,
9381 HOST_WIDE_INT delta
, HOST_WIDE_INT vcall_offset
,
9387 /* Make sure unwind info is emitted for the thunk if needed. */
9388 final_start_function (emit_barrier (), file
, 1);
9390 /* Operand 0 is the target function. */
9391 op
[0] = XEXP (DECL_RTL (function
), 0);
9392 if (flag_pic
&& !SYMBOL_REF_LOCAL_P (op
[0]))
9395 op
[0] = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op
[0]),
9396 TARGET_64BIT
? UNSPEC_PLT
: UNSPEC_GOT
);
9397 op
[0] = gen_rtx_CONST (Pmode
, op
[0]);
9400 /* Operand 1 is the 'this' pointer. */
9401 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function
)), function
))
9402 op
[1] = gen_rtx_REG (Pmode
, 3);
9404 op
[1] = gen_rtx_REG (Pmode
, 2);
9406 /* Operand 2 is the delta. */
9407 op
[2] = GEN_INT (delta
);
9409 /* Operand 3 is the vcall_offset. */
9410 op
[3] = GEN_INT (vcall_offset
);
9412 /* Operand 4 is the temporary register. */
9413 op
[4] = gen_rtx_REG (Pmode
, 1);
9415 /* Operands 5 to 8 can be used as labels. */
9421 /* Operand 9 can be used for temporary register. */
9424 /* Generate code. */
9427 /* Setup literal pool pointer if required. */
9428 if ((!DISP_IN_RANGE (delta
)
9429 && !CONST_OK_FOR_K (delta
)
9430 && !CONST_OK_FOR_Os (delta
))
9431 || (!DISP_IN_RANGE (vcall_offset
)
9432 && !CONST_OK_FOR_K (vcall_offset
)
9433 && !CONST_OK_FOR_Os (vcall_offset
)))
9435 op
[5] = gen_label_rtx ();
9436 output_asm_insn ("larl\t%4,%5", op
);
9439 /* Add DELTA to this pointer. */
9442 if (CONST_OK_FOR_J (delta
))
9443 output_asm_insn ("la\t%1,%2(%1)", op
);
9444 else if (DISP_IN_RANGE (delta
))
9445 output_asm_insn ("lay\t%1,%2(%1)", op
);
9446 else if (CONST_OK_FOR_K (delta
))
9447 output_asm_insn ("aghi\t%1,%2", op
);
9448 else if (CONST_OK_FOR_Os (delta
))
9449 output_asm_insn ("agfi\t%1,%2", op
);
9452 op
[6] = gen_label_rtx ();
9453 output_asm_insn ("agf\t%1,%6-%5(%4)", op
);
9457 /* Perform vcall adjustment. */
9460 if (DISP_IN_RANGE (vcall_offset
))
9462 output_asm_insn ("lg\t%4,0(%1)", op
);
9463 output_asm_insn ("ag\t%1,%3(%4)", op
);
9465 else if (CONST_OK_FOR_K (vcall_offset
))
9467 output_asm_insn ("lghi\t%4,%3", op
);
9468 output_asm_insn ("ag\t%4,0(%1)", op
);
9469 output_asm_insn ("ag\t%1,0(%4)", op
);
9471 else if (CONST_OK_FOR_Os (vcall_offset
))
9473 output_asm_insn ("lgfi\t%4,%3", op
);
9474 output_asm_insn ("ag\t%4,0(%1)", op
);
9475 output_asm_insn ("ag\t%1,0(%4)", op
);
9479 op
[7] = gen_label_rtx ();
9480 output_asm_insn ("llgf\t%4,%7-%5(%4)", op
);
9481 output_asm_insn ("ag\t%4,0(%1)", op
);
9482 output_asm_insn ("ag\t%1,0(%4)", op
);
9486 /* Jump to target. */
9487 output_asm_insn ("jg\t%0", op
);
9489 /* Output literal pool if required. */
9492 output_asm_insn (".align\t4", op
);
9493 targetm
.asm_out
.internal_label (file
, "L",
9494 CODE_LABEL_NUMBER (op
[5]));
9498 targetm
.asm_out
.internal_label (file
, "L",
9499 CODE_LABEL_NUMBER (op
[6]));
9500 output_asm_insn (".long\t%2", op
);
9504 targetm
.asm_out
.internal_label (file
, "L",
9505 CODE_LABEL_NUMBER (op
[7]));
9506 output_asm_insn (".long\t%3", op
);
9511 /* Setup base pointer if required. */
9513 || (!DISP_IN_RANGE (delta
)
9514 && !CONST_OK_FOR_K (delta
)
9515 && !CONST_OK_FOR_Os (delta
))
9516 || (!DISP_IN_RANGE (delta
)
9517 && !CONST_OK_FOR_K (vcall_offset
)
9518 && !CONST_OK_FOR_Os (vcall_offset
)))
9520 op
[5] = gen_label_rtx ();
9521 output_asm_insn ("basr\t%4,0", op
);
9522 targetm
.asm_out
.internal_label (file
, "L",
9523 CODE_LABEL_NUMBER (op
[5]));
9526 /* Add DELTA to this pointer. */
9529 if (CONST_OK_FOR_J (delta
))
9530 output_asm_insn ("la\t%1,%2(%1)", op
);
9531 else if (DISP_IN_RANGE (delta
))
9532 output_asm_insn ("lay\t%1,%2(%1)", op
);
9533 else if (CONST_OK_FOR_K (delta
))
9534 output_asm_insn ("ahi\t%1,%2", op
);
9535 else if (CONST_OK_FOR_Os (delta
))
9536 output_asm_insn ("afi\t%1,%2", op
);
9539 op
[6] = gen_label_rtx ();
9540 output_asm_insn ("a\t%1,%6-%5(%4)", op
);
9544 /* Perform vcall adjustment. */
9547 if (CONST_OK_FOR_J (vcall_offset
))
9549 output_asm_insn ("l\t%4,0(%1)", op
);
9550 output_asm_insn ("a\t%1,%3(%4)", op
);
9552 else if (DISP_IN_RANGE (vcall_offset
))
9554 output_asm_insn ("l\t%4,0(%1)", op
);
9555 output_asm_insn ("ay\t%1,%3(%4)", op
);
9557 else if (CONST_OK_FOR_K (vcall_offset
))
9559 output_asm_insn ("lhi\t%4,%3", op
);
9560 output_asm_insn ("a\t%4,0(%1)", op
);
9561 output_asm_insn ("a\t%1,0(%4)", op
);
9563 else if (CONST_OK_FOR_Os (vcall_offset
))
9565 output_asm_insn ("iilf\t%4,%3", op
);
9566 output_asm_insn ("a\t%4,0(%1)", op
);
9567 output_asm_insn ("a\t%1,0(%4)", op
);
9571 op
[7] = gen_label_rtx ();
9572 output_asm_insn ("l\t%4,%7-%5(%4)", op
);
9573 output_asm_insn ("a\t%4,0(%1)", op
);
9574 output_asm_insn ("a\t%1,0(%4)", op
);
9577 /* We had to clobber the base pointer register.
9578 Re-setup the base pointer (with a different base). */
9579 op
[5] = gen_label_rtx ();
9580 output_asm_insn ("basr\t%4,0", op
);
9581 targetm
.asm_out
.internal_label (file
, "L",
9582 CODE_LABEL_NUMBER (op
[5]));
9585 /* Jump to target. */
9586 op
[8] = gen_label_rtx ();
9589 output_asm_insn ("l\t%4,%8-%5(%4)", op
);
9591 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
9592 /* We cannot call through .plt, since .plt requires %r12 loaded. */
9593 else if (flag_pic
== 1)
9595 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
9596 output_asm_insn ("l\t%4,%0(%4)", op
);
9598 else if (flag_pic
== 2)
9600 op
[9] = gen_rtx_REG (Pmode
, 0);
9601 output_asm_insn ("l\t%9,%8-4-%5(%4)", op
);
9602 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
9603 output_asm_insn ("ar\t%4,%9", op
);
9604 output_asm_insn ("l\t%4,0(%4)", op
);
9607 output_asm_insn ("br\t%4", op
);
9609 /* Output literal pool. */
9610 output_asm_insn (".align\t4", op
);
9612 if (nonlocal
&& flag_pic
== 2)
9613 output_asm_insn (".long\t%0", op
);
9616 op
[0] = gen_rtx_SYMBOL_REF (Pmode
, "_GLOBAL_OFFSET_TABLE_");
9617 SYMBOL_REF_FLAGS (op
[0]) = SYMBOL_FLAG_LOCAL
;
9620 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[8]));
9622 output_asm_insn (".long\t%0", op
);
9624 output_asm_insn (".long\t%0-%5", op
);
9628 targetm
.asm_out
.internal_label (file
, "L",
9629 CODE_LABEL_NUMBER (op
[6]));
9630 output_asm_insn (".long\t%2", op
);
9634 targetm
.asm_out
.internal_label (file
, "L",
9635 CODE_LABEL_NUMBER (op
[7]));
9636 output_asm_insn (".long\t%3", op
);
9639 final_end_function ();
9643 s390_valid_pointer_mode (enum machine_mode mode
)
9645 return (mode
== SImode
|| (TARGET_64BIT
&& mode
== DImode
));
9648 /* Checks whether the given CALL_EXPR would use a caller
9649 saved register. This is used to decide whether sibling call
9650 optimization could be performed on the respective function
9654 s390_call_saved_register_used (tree call_expr
)
9656 CUMULATIVE_ARGS cum
;
9658 enum machine_mode mode
;
9663 INIT_CUMULATIVE_ARGS (cum
, NULL
, NULL
, 0, 0);
9665 for (i
= 0; i
< call_expr_nargs (call_expr
); i
++)
9667 parameter
= CALL_EXPR_ARG (call_expr
, i
);
9668 gcc_assert (parameter
);
9670 /* For an undeclared variable passed as parameter we will get
9671 an ERROR_MARK node here. */
9672 if (TREE_CODE (parameter
) == ERROR_MARK
)
9675 type
= TREE_TYPE (parameter
);
9678 mode
= TYPE_MODE (type
);
9681 if (pass_by_reference (&cum
, mode
, type
, true))
9684 type
= build_pointer_type (type
);
9687 parm_rtx
= s390_function_arg (&cum
, mode
, type
, 0);
9689 s390_function_arg_advance (&cum
, mode
, type
, 0);
9694 if (REG_P (parm_rtx
))
9697 reg
< HARD_REGNO_NREGS (REGNO (parm_rtx
), GET_MODE (parm_rtx
));
9699 if (!call_used_regs
[reg
+ REGNO (parm_rtx
)])
9703 if (GET_CODE (parm_rtx
) == PARALLEL
)
9707 for (i
= 0; i
< XVECLEN (parm_rtx
, 0); i
++)
9709 rtx r
= XEXP (XVECEXP (parm_rtx
, 0, i
), 0);
9711 gcc_assert (REG_P (r
));
9714 reg
< HARD_REGNO_NREGS (REGNO (r
), GET_MODE (r
));
9716 if (!call_used_regs
[reg
+ REGNO (r
)])
9725 /* Return true if the given call expression can be
9726 turned into a sibling call.
9727 DECL holds the declaration of the function to be called whereas
9728 EXP is the call expression itself. */
9731 s390_function_ok_for_sibcall (tree decl
, tree exp
)
9733 /* The TPF epilogue uses register 1. */
9734 if (TARGET_TPF_PROFILING
)
9737 /* The 31 bit PLT code uses register 12 (GOT pointer - caller saved)
9738 which would have to be restored before the sibcall. */
9739 if (!TARGET_64BIT
&& flag_pic
&& decl
&& !targetm
.binds_local_p (decl
))
9742 /* Register 6 on s390 is available as an argument register but unfortunately
9743 "caller saved". This makes functions needing this register for arguments
9744 not suitable for sibcalls. */
9745 return !s390_call_saved_register_used (exp
);
9748 /* Return the fixed registers used for condition codes. */
9751 s390_fixed_condition_code_regs (unsigned int *p1
, unsigned int *p2
)
9754 *p2
= INVALID_REGNUM
;
9759 /* This function is used by the call expanders of the machine description.
9760 It emits the call insn itself together with the necessary operations
9761 to adjust the target address and returns the emitted insn.
9762 ADDR_LOCATION is the target address rtx
9763 TLS_CALL the location of the thread-local symbol
9764 RESULT_REG the register where the result of the call should be stored
9765 RETADDR_REG the register where the return address should be stored
9766 If this parameter is NULL_RTX the call is considered
9767 to be a sibling call. */
9770 s390_emit_call (rtx addr_location
, rtx tls_call
, rtx result_reg
,
9773 bool plt_call
= false;
9779 /* Direct function calls need special treatment. */
9780 if (GET_CODE (addr_location
) == SYMBOL_REF
)
9782 /* When calling a global routine in PIC mode, we must
9783 replace the symbol itself with the PLT stub. */
9784 if (flag_pic
&& !SYMBOL_REF_LOCAL_P (addr_location
))
9786 if (retaddr_reg
!= NULL_RTX
)
9788 addr_location
= gen_rtx_UNSPEC (Pmode
,
9789 gen_rtvec (1, addr_location
),
9791 addr_location
= gen_rtx_CONST (Pmode
, addr_location
);
9795 /* For -fpic code the PLT entries might use r12 which is
9796 call-saved. Therefore we cannot do a sibcall when
9797 calling directly using a symbol ref. When reaching
9798 this point we decided (in s390_function_ok_for_sibcall)
9799 to do a sibcall for a function pointer but one of the
9800 optimizers was able to get rid of the function pointer
9801 by propagating the symbol ref into the call. This
9802 optimization is illegal for S/390 so we turn the direct
9803 call into a indirect call again. */
9804 addr_location
= force_reg (Pmode
, addr_location
);
9807 /* Unless we can use the bras(l) insn, force the
9808 routine address into a register. */
9809 if (!TARGET_SMALL_EXEC
&& !TARGET_CPU_ZARCH
)
9812 addr_location
= legitimize_pic_address (addr_location
, 0);
9814 addr_location
= force_reg (Pmode
, addr_location
);
9818 /* If it is already an indirect call or the code above moved the
9819 SYMBOL_REF to somewhere else make sure the address can be found in
9821 if (retaddr_reg
== NULL_RTX
9822 && GET_CODE (addr_location
) != SYMBOL_REF
9825 emit_move_insn (gen_rtx_REG (Pmode
, SIBCALL_REGNUM
), addr_location
);
9826 addr_location
= gen_rtx_REG (Pmode
, SIBCALL_REGNUM
);
9829 addr_location
= gen_rtx_MEM (QImode
, addr_location
);
9830 call
= gen_rtx_CALL (VOIDmode
, addr_location
, const0_rtx
);
9832 if (result_reg
!= NULL_RTX
)
9833 call
= gen_rtx_SET (VOIDmode
, result_reg
, call
);
9835 if (retaddr_reg
!= NULL_RTX
)
9837 clobber
= gen_rtx_CLOBBER (VOIDmode
, retaddr_reg
);
9839 if (tls_call
!= NULL_RTX
)
9840 vec
= gen_rtvec (3, call
, clobber
,
9841 gen_rtx_USE (VOIDmode
, tls_call
));
9843 vec
= gen_rtvec (2, call
, clobber
);
9845 call
= gen_rtx_PARALLEL (VOIDmode
, vec
);
9848 insn
= emit_call_insn (call
);
9850 /* 31-bit PLT stubs and tls calls use the GOT register implicitly. */
9851 if ((!TARGET_64BIT
&& plt_call
) || tls_call
!= NULL_RTX
)
9853 /* s390_function_ok_for_sibcall should
9854 have denied sibcalls in this case. */
9855 gcc_assert (retaddr_reg
!= NULL_RTX
);
9857 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), pic_offset_table_rtx
);
9862 /* Implement TARGET_CONDITIONAL_REGISTER_USAGE. */
9865 s390_conditional_register_usage (void)
9871 fixed_regs
[PIC_OFFSET_TABLE_REGNUM
] = 1;
9872 call_used_regs
[PIC_OFFSET_TABLE_REGNUM
] = 1;
9874 if (TARGET_CPU_ZARCH
)
9876 fixed_regs
[BASE_REGNUM
] = 0;
9877 call_used_regs
[BASE_REGNUM
] = 0;
9878 fixed_regs
[RETURN_REGNUM
] = 0;
9879 call_used_regs
[RETURN_REGNUM
] = 0;
9883 for (i
= 24; i
< 32; i
++)
9884 call_used_regs
[i
] = call_really_used_regs
[i
] = 0;
9888 for (i
= 18; i
< 20; i
++)
9889 call_used_regs
[i
] = call_really_used_regs
[i
] = 0;
9892 if (TARGET_SOFT_FLOAT
)
9894 for (i
= 16; i
< 32; i
++)
9895 call_used_regs
[i
] = fixed_regs
[i
] = 1;
9899 /* Corresponding function to eh_return expander. */
9901 static GTY(()) rtx s390_tpf_eh_return_symbol
;
9903 s390_emit_tpf_eh_return (rtx target
)
9907 if (!s390_tpf_eh_return_symbol
)
9908 s390_tpf_eh_return_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "__tpf_eh_return");
9910 reg
= gen_rtx_REG (Pmode
, 2);
9912 emit_move_insn (reg
, target
);
9913 insn
= s390_emit_call (s390_tpf_eh_return_symbol
, NULL_RTX
, reg
,
9914 gen_rtx_REG (Pmode
, RETURN_REGNUM
));
9915 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), reg
);
9917 emit_move_insn (EH_RETURN_HANDLER_RTX
, reg
);
9920 /* Rework the prologue/epilogue to avoid saving/restoring
9921 registers unnecessarily. */
9924 s390_optimize_prologue (void)
9926 rtx insn
, new_insn
, next_insn
;
9928 /* Do a final recompute of the frame-related data. */
9930 s390_update_frame_layout ();
9932 /* If all special registers are in fact used, there's nothing we
9933 can do, so no point in walking the insn list. */
9935 if (cfun_frame_layout
.first_save_gpr
<= BASE_REGNUM
9936 && cfun_frame_layout
.last_save_gpr
>= BASE_REGNUM
9937 && (TARGET_CPU_ZARCH
9938 || (cfun_frame_layout
.first_save_gpr
<= RETURN_REGNUM
9939 && cfun_frame_layout
.last_save_gpr
>= RETURN_REGNUM
)))
9942 /* Search for prologue/epilogue insns and replace them. */
9944 for (insn
= get_insns (); insn
; insn
= next_insn
)
9946 int first
, last
, off
;
9947 rtx set
, base
, offset
;
9949 next_insn
= NEXT_INSN (insn
);
9951 if (GET_CODE (insn
) != INSN
)
9954 if (GET_CODE (PATTERN (insn
)) == PARALLEL
9955 && store_multiple_operation (PATTERN (insn
), VOIDmode
))
9957 set
= XVECEXP (PATTERN (insn
), 0, 0);
9958 first
= REGNO (SET_SRC (set
));
9959 last
= first
+ XVECLEN (PATTERN (insn
), 0) - 1;
9960 offset
= const0_rtx
;
9961 base
= eliminate_constant_term (XEXP (SET_DEST (set
), 0), &offset
);
9962 off
= INTVAL (offset
);
9964 if (GET_CODE (base
) != REG
|| off
< 0)
9966 if (cfun_frame_layout
.first_save_gpr
!= -1
9967 && (cfun_frame_layout
.first_save_gpr
< first
9968 || cfun_frame_layout
.last_save_gpr
> last
))
9970 if (REGNO (base
) != STACK_POINTER_REGNUM
9971 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
9973 if (first
> BASE_REGNUM
|| last
< BASE_REGNUM
)
9976 if (cfun_frame_layout
.first_save_gpr
!= -1)
9978 new_insn
= save_gprs (base
,
9979 off
+ (cfun_frame_layout
.first_save_gpr
9980 - first
) * UNITS_PER_LONG
,
9981 cfun_frame_layout
.first_save_gpr
,
9982 cfun_frame_layout
.last_save_gpr
);
9983 new_insn
= emit_insn_before (new_insn
, insn
);
9984 INSN_ADDRESSES_NEW (new_insn
, -1);
9991 if (cfun_frame_layout
.first_save_gpr
== -1
9992 && GET_CODE (PATTERN (insn
)) == SET
9993 && GET_CODE (SET_SRC (PATTERN (insn
))) == REG
9994 && (REGNO (SET_SRC (PATTERN (insn
))) == BASE_REGNUM
9995 || (!TARGET_CPU_ZARCH
9996 && REGNO (SET_SRC (PATTERN (insn
))) == RETURN_REGNUM
))
9997 && GET_CODE (SET_DEST (PATTERN (insn
))) == MEM
)
9999 set
= PATTERN (insn
);
10000 first
= REGNO (SET_SRC (set
));
10001 offset
= const0_rtx
;
10002 base
= eliminate_constant_term (XEXP (SET_DEST (set
), 0), &offset
);
10003 off
= INTVAL (offset
);
10005 if (GET_CODE (base
) != REG
|| off
< 0)
10007 if (REGNO (base
) != STACK_POINTER_REGNUM
10008 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
10011 remove_insn (insn
);
10015 if (GET_CODE (PATTERN (insn
)) == PARALLEL
10016 && load_multiple_operation (PATTERN (insn
), VOIDmode
))
10018 set
= XVECEXP (PATTERN (insn
), 0, 0);
10019 first
= REGNO (SET_DEST (set
));
10020 last
= first
+ XVECLEN (PATTERN (insn
), 0) - 1;
10021 offset
= const0_rtx
;
10022 base
= eliminate_constant_term (XEXP (SET_SRC (set
), 0), &offset
);
10023 off
= INTVAL (offset
);
10025 if (GET_CODE (base
) != REG
|| off
< 0)
10027 if (cfun_frame_layout
.first_restore_gpr
!= -1
10028 && (cfun_frame_layout
.first_restore_gpr
< first
10029 || cfun_frame_layout
.last_restore_gpr
> last
))
10031 if (REGNO (base
) != STACK_POINTER_REGNUM
10032 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
10034 if (first
> BASE_REGNUM
|| last
< BASE_REGNUM
)
10037 if (cfun_frame_layout
.first_restore_gpr
!= -1)
10039 new_insn
= restore_gprs (base
,
10040 off
+ (cfun_frame_layout
.first_restore_gpr
10041 - first
) * UNITS_PER_LONG
,
10042 cfun_frame_layout
.first_restore_gpr
,
10043 cfun_frame_layout
.last_restore_gpr
);
10044 new_insn
= emit_insn_before (new_insn
, insn
);
10045 INSN_ADDRESSES_NEW (new_insn
, -1);
10048 remove_insn (insn
);
10052 if (cfun_frame_layout
.first_restore_gpr
== -1
10053 && GET_CODE (PATTERN (insn
)) == SET
10054 && GET_CODE (SET_DEST (PATTERN (insn
))) == REG
10055 && (REGNO (SET_DEST (PATTERN (insn
))) == BASE_REGNUM
10056 || (!TARGET_CPU_ZARCH
10057 && REGNO (SET_DEST (PATTERN (insn
))) == RETURN_REGNUM
))
10058 && GET_CODE (SET_SRC (PATTERN (insn
))) == MEM
)
10060 set
= PATTERN (insn
);
10061 first
= REGNO (SET_DEST (set
));
10062 offset
= const0_rtx
;
10063 base
= eliminate_constant_term (XEXP (SET_SRC (set
), 0), &offset
);
10064 off
= INTVAL (offset
);
10066 if (GET_CODE (base
) != REG
|| off
< 0)
10068 if (REGNO (base
) != STACK_POINTER_REGNUM
10069 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
10072 remove_insn (insn
);
10078 /* On z10 and later the dynamic branch prediction must see the
10079 backward jump within a certain windows. If not it falls back to
10080 the static prediction. This function rearranges the loop backward
10081 branch in a way which makes the static prediction always correct.
10082 The function returns true if it added an instruction. */
10084 s390_fix_long_loop_prediction (rtx insn
)
10086 rtx set
= single_set (insn
);
10087 rtx code_label
, label_ref
, new_label
;
10093 /* This will exclude branch on count and branch on index patterns
10094 since these are correctly statically predicted. */
10096 || SET_DEST (set
) != pc_rtx
10097 || GET_CODE (SET_SRC(set
)) != IF_THEN_ELSE
)
10100 label_ref
= (GET_CODE (XEXP (SET_SRC (set
), 1)) == LABEL_REF
?
10101 XEXP (SET_SRC (set
), 1) : XEXP (SET_SRC (set
), 2));
10103 gcc_assert (GET_CODE (label_ref
) == LABEL_REF
);
10105 code_label
= XEXP (label_ref
, 0);
10107 if (INSN_ADDRESSES (INSN_UID (code_label
)) == -1
10108 || INSN_ADDRESSES (INSN_UID (insn
)) == -1
10109 || (INSN_ADDRESSES (INSN_UID (insn
))
10110 - INSN_ADDRESSES (INSN_UID (code_label
)) < PREDICT_DISTANCE
))
10113 for (distance
= 0, cur_insn
= PREV_INSN (insn
);
10114 distance
< PREDICT_DISTANCE
- 6;
10115 distance
+= get_attr_length (cur_insn
), cur_insn
= PREV_INSN (cur_insn
))
10116 if (!cur_insn
|| JUMP_P (cur_insn
) || LABEL_P (cur_insn
))
10119 new_label
= gen_label_rtx ();
10120 uncond_jump
= emit_jump_insn_after (
10121 gen_rtx_SET (VOIDmode
, pc_rtx
,
10122 gen_rtx_LABEL_REF (VOIDmode
, code_label
)),
10124 emit_label_after (new_label
, uncond_jump
);
10126 tmp
= XEXP (SET_SRC (set
), 1);
10127 XEXP (SET_SRC (set
), 1) = XEXP (SET_SRC (set
), 2);
10128 XEXP (SET_SRC (set
), 2) = tmp
;
10129 INSN_CODE (insn
) = -1;
10131 XEXP (label_ref
, 0) = new_label
;
10132 JUMP_LABEL (insn
) = new_label
;
10133 JUMP_LABEL (uncond_jump
) = code_label
;
10138 /* Returns 1 if INSN reads the value of REG for purposes not related
10139 to addressing of memory, and 0 otherwise. */
10141 s390_non_addr_reg_read_p (rtx reg
, rtx insn
)
10143 return reg_referenced_p (reg
, PATTERN (insn
))
10144 && !reg_used_in_mem_p (REGNO (reg
), PATTERN (insn
));
10147 /* Starting from INSN find_cond_jump looks downwards in the insn
10148 stream for a single jump insn which is the last user of the
10149 condition code set in INSN. */
10151 find_cond_jump (rtx insn
)
10153 for (; insn
; insn
= NEXT_INSN (insn
))
10157 if (LABEL_P (insn
))
10160 if (!JUMP_P (insn
))
10162 if (reg_mentioned_p (gen_rtx_REG (CCmode
, CC_REGNUM
), insn
))
10167 /* This will be triggered by a return. */
10168 if (GET_CODE (PATTERN (insn
)) != SET
)
10171 gcc_assert (SET_DEST (PATTERN (insn
)) == pc_rtx
);
10172 ite
= SET_SRC (PATTERN (insn
));
10174 if (GET_CODE (ite
) != IF_THEN_ELSE
)
10177 cc
= XEXP (XEXP (ite
, 0), 0);
10178 if (!REG_P (cc
) || !CC_REGNO_P (REGNO (cc
)))
10181 if (find_reg_note (insn
, REG_DEAD
, cc
))
10189 /* Swap the condition in COND and the operands in OP0 and OP1 so that
10190 the semantics does not change. If NULL_RTX is passed as COND the
10191 function tries to find the conditional jump starting with INSN. */
10193 s390_swap_cmp (rtx cond
, rtx
*op0
, rtx
*op1
, rtx insn
)
10197 if (cond
== NULL_RTX
)
10199 rtx jump
= find_cond_jump (NEXT_INSN (insn
));
10200 jump
= jump
? single_set (jump
) : NULL_RTX
;
10202 if (jump
== NULL_RTX
)
10205 cond
= XEXP (XEXP (jump
, 1), 0);
10210 PUT_CODE (cond
, swap_condition (GET_CODE (cond
)));
10213 /* On z10, instructions of the compare-and-branch family have the
10214 property to access the register occurring as second operand with
10215 its bits complemented. If such a compare is grouped with a second
10216 instruction that accesses the same register non-complemented, and
10217 if that register's value is delivered via a bypass, then the
10218 pipeline recycles, thereby causing significant performance decline.
10219 This function locates such situations and exchanges the two
10220 operands of the compare. The function return true whenever it
10223 s390_z10_optimize_cmp (rtx insn
)
10225 rtx prev_insn
, next_insn
;
10226 bool insn_added_p
= false;
10227 rtx cond
, *op0
, *op1
;
10229 if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
10231 /* Handle compare and branch and branch on count
10233 rtx pattern
= single_set (insn
);
10236 || SET_DEST (pattern
) != pc_rtx
10237 || GET_CODE (SET_SRC (pattern
)) != IF_THEN_ELSE
)
10240 cond
= XEXP (SET_SRC (pattern
), 0);
10241 op0
= &XEXP (cond
, 0);
10242 op1
= &XEXP (cond
, 1);
10244 else if (GET_CODE (PATTERN (insn
)) == SET
)
10248 /* Handle normal compare instructions. */
10249 src
= SET_SRC (PATTERN (insn
));
10250 dest
= SET_DEST (PATTERN (insn
));
10253 || !CC_REGNO_P (REGNO (dest
))
10254 || GET_CODE (src
) != COMPARE
)
10257 /* s390_swap_cmp will try to find the conditional
10258 jump when passing NULL_RTX as condition. */
10260 op0
= &XEXP (src
, 0);
10261 op1
= &XEXP (src
, 1);
10266 if (!REG_P (*op0
) || !REG_P (*op1
))
10269 if (GET_MODE_CLASS (GET_MODE (*op0
)) != MODE_INT
)
10272 /* Swap the COMPARE arguments and its mask if there is a
10273 conflicting access in the previous insn. */
10274 prev_insn
= prev_active_insn (insn
);
10275 if (prev_insn
!= NULL_RTX
&& INSN_P (prev_insn
)
10276 && reg_referenced_p (*op1
, PATTERN (prev_insn
)))
10277 s390_swap_cmp (cond
, op0
, op1
, insn
);
10279 /* Check if there is a conflict with the next insn. If there
10280 was no conflict with the previous insn, then swap the
10281 COMPARE arguments and its mask. If we already swapped
10282 the operands, or if swapping them would cause a conflict
10283 with the previous insn, issue a NOP after the COMPARE in
10284 order to separate the two instuctions. */
10285 next_insn
= next_active_insn (insn
);
10286 if (next_insn
!= NULL_RTX
&& INSN_P (next_insn
)
10287 && s390_non_addr_reg_read_p (*op1
, next_insn
))
10289 if (prev_insn
!= NULL_RTX
&& INSN_P (prev_insn
)
10290 && s390_non_addr_reg_read_p (*op0
, prev_insn
))
10292 if (REGNO (*op1
) == 0)
10293 emit_insn_after (gen_nop1 (), insn
);
10295 emit_insn_after (gen_nop (), insn
);
10296 insn_added_p
= true;
10299 s390_swap_cmp (cond
, op0
, op1
, insn
);
10301 return insn_added_p
;
10304 /* Perform machine-dependent processing. */
10309 bool pool_overflow
= false;
10311 /* Make sure all splits have been performed; splits after
10312 machine_dependent_reorg might confuse insn length counts. */
10313 split_all_insns_noflow ();
10315 /* Install the main literal pool and the associated base
10316 register load insns.
10318 In addition, there are two problematic situations we need
10321 - the literal pool might be > 4096 bytes in size, so that
10322 some of its elements cannot be directly accessed
10324 - a branch target might be > 64K away from the branch, so that
10325 it is not possible to use a PC-relative instruction.
10327 To fix those, we split the single literal pool into multiple
10328 pool chunks, reloading the pool base register at various
10329 points throughout the function to ensure it always points to
10330 the pool chunk the following code expects, and / or replace
10331 PC-relative branches by absolute branches.
10333 However, the two problems are interdependent: splitting the
10334 literal pool can move a branch further away from its target,
10335 causing the 64K limit to overflow, and on the other hand,
10336 replacing a PC-relative branch by an absolute branch means
10337 we need to put the branch target address into the literal
10338 pool, possibly causing it to overflow.
10340 So, we loop trying to fix up both problems until we manage
10341 to satisfy both conditions at the same time. Note that the
10342 loop is guaranteed to terminate as every pass of the loop
10343 strictly decreases the total number of PC-relative branches
10344 in the function. (This is not completely true as there
10345 might be branch-over-pool insns introduced by chunkify_start.
10346 Those never need to be split however.) */
10350 struct constant_pool
*pool
= NULL
;
10352 /* Collect the literal pool. */
10353 if (!pool_overflow
)
10355 pool
= s390_mainpool_start ();
10357 pool_overflow
= true;
10360 /* If literal pool overflowed, start to chunkify it. */
10362 pool
= s390_chunkify_start ();
10364 /* Split out-of-range branches. If this has created new
10365 literal pool entries, cancel current chunk list and
10366 recompute it. zSeries machines have large branch
10367 instructions, so we never need to split a branch. */
10368 if (!TARGET_CPU_ZARCH
&& s390_split_branches ())
10371 s390_chunkify_cancel (pool
);
10373 s390_mainpool_cancel (pool
);
10378 /* If we made it up to here, both conditions are satisfied.
10379 Finish up literal pool related changes. */
10381 s390_chunkify_finish (pool
);
10383 s390_mainpool_finish (pool
);
10385 /* We're done splitting branches. */
10386 cfun
->machine
->split_branches_pending_p
= false;
10390 /* Generate out-of-pool execute target insns. */
10391 if (TARGET_CPU_ZARCH
)
10393 rtx insn
, label
, target
;
10395 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
10397 label
= s390_execute_label (insn
);
10401 gcc_assert (label
!= const0_rtx
);
10403 target
= emit_label (XEXP (label
, 0));
10404 INSN_ADDRESSES_NEW (target
, -1);
10406 target
= emit_insn (s390_execute_target (insn
));
10407 INSN_ADDRESSES_NEW (target
, -1);
10411 /* Try to optimize prologue and epilogue further. */
10412 s390_optimize_prologue ();
10414 /* Walk over the insns and do some >=z10 specific changes. */
10415 if (s390_tune
== PROCESSOR_2097_Z10
10416 || s390_tune
== PROCESSOR_2817_Z196
)
10419 bool insn_added_p
= false;
10421 /* The insn lengths and addresses have to be up to date for the
10422 following manipulations. */
10423 shorten_branches (get_insns ());
10425 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
10427 if (!INSN_P (insn
) || INSN_CODE (insn
) <= 0)
10431 insn_added_p
|= s390_fix_long_loop_prediction (insn
);
10433 if ((GET_CODE (PATTERN (insn
)) == PARALLEL
10434 || GET_CODE (PATTERN (insn
)) == SET
)
10435 && s390_tune
== PROCESSOR_2097_Z10
)
10436 insn_added_p
|= s390_z10_optimize_cmp (insn
);
10439 /* Adjust branches if we added new instructions. */
10441 shorten_branches (get_insns ());
10445 /* Return true if INSN is a fp load insn writing register REGNO. */
10447 s390_fpload_toreg (rtx insn
, unsigned int regno
)
10450 enum attr_type flag
= s390_safe_attr_type (insn
);
10452 if (flag
!= TYPE_FLOADSF
&& flag
!= TYPE_FLOADDF
)
10455 set
= single_set (insn
);
10457 if (set
== NULL_RTX
)
10460 if (!REG_P (SET_DEST (set
)) || !MEM_P (SET_SRC (set
)))
10463 if (REGNO (SET_DEST (set
)) != regno
)
10469 /* This value describes the distance to be avoided between an
10470 aritmetic fp instruction and an fp load writing the same register.
10471 Z10_EARLYLOAD_DISTANCE - 1 as well as Z10_EARLYLOAD_DISTANCE + 1 is
10472 fine but the exact value has to be avoided. Otherwise the FP
10473 pipeline will throw an exception causing a major penalty. */
10474 #define Z10_EARLYLOAD_DISTANCE 7
10476 /* Rearrange the ready list in order to avoid the situation described
10477 for Z10_EARLYLOAD_DISTANCE. A problematic load instruction is
10478 moved to the very end of the ready list. */
10480 s390_z10_prevent_earlyload_conflicts (rtx
*ready
, int *nready_p
)
10482 unsigned int regno
;
10483 int nready
= *nready_p
;
10488 enum attr_type flag
;
10491 /* Skip DISTANCE - 1 active insns. */
10492 for (insn
= last_scheduled_insn
, distance
= Z10_EARLYLOAD_DISTANCE
- 1;
10493 distance
> 0 && insn
!= NULL_RTX
;
10494 distance
--, insn
= prev_active_insn (insn
))
10495 if (CALL_P (insn
) || JUMP_P (insn
))
10498 if (insn
== NULL_RTX
)
10501 set
= single_set (insn
);
10503 if (set
== NULL_RTX
|| !REG_P (SET_DEST (set
))
10504 || GET_MODE_CLASS (GET_MODE (SET_DEST (set
))) != MODE_FLOAT
)
10507 flag
= s390_safe_attr_type (insn
);
10509 if (flag
== TYPE_FLOADSF
|| flag
== TYPE_FLOADDF
)
10512 regno
= REGNO (SET_DEST (set
));
10515 while (!s390_fpload_toreg (ready
[i
], regno
) && i
> 0)
10522 memmove (&ready
[1], &ready
[0], sizeof (rtx
) * i
);
10526 /* This function is called via hook TARGET_SCHED_REORDER before
10527 issueing one insn from list READY which contains *NREADYP entries.
10528 For target z10 it reorders load instructions to avoid early load
10529 conflicts in the floating point pipeline */
10531 s390_sched_reorder (FILE *file ATTRIBUTE_UNUSED
, int verbose ATTRIBUTE_UNUSED
,
10532 rtx
*ready
, int *nreadyp
, int clock ATTRIBUTE_UNUSED
)
10534 if (s390_tune
== PROCESSOR_2097_Z10
)
10535 if (reload_completed
&& *nreadyp
> 1)
10536 s390_z10_prevent_earlyload_conflicts (ready
, nreadyp
);
10538 return s390_issue_rate ();
10541 /* This function is called via hook TARGET_SCHED_VARIABLE_ISSUE after
10542 the scheduler has issued INSN. It stores the last issued insn into
10543 last_scheduled_insn in order to make it available for
10544 s390_sched_reorder. */
10546 s390_sched_variable_issue (FILE *file ATTRIBUTE_UNUSED
,
10547 int verbose ATTRIBUTE_UNUSED
,
10548 rtx insn
, int more
)
10550 last_scheduled_insn
= insn
;
10552 if (GET_CODE (PATTERN (insn
)) != USE
10553 && GET_CODE (PATTERN (insn
)) != CLOBBER
)
10560 s390_sched_init (FILE *file ATTRIBUTE_UNUSED
,
10561 int verbose ATTRIBUTE_UNUSED
,
10562 int max_ready ATTRIBUTE_UNUSED
)
10564 last_scheduled_insn
= NULL_RTX
;
10567 /* This function checks the whole of insn X for memory references. The
10568 function always returns zero because the framework it is called
10569 from would stop recursively analyzing the insn upon a return value
10570 other than zero. The real result of this function is updating
10571 counter variable MEM_COUNT. */
10573 check_dpu (rtx
*x
, unsigned *mem_count
)
10575 if (*x
!= NULL_RTX
&& MEM_P (*x
))
10580 /* This target hook implementation for TARGET_LOOP_UNROLL_ADJUST calculates
10581 a new number struct loop *loop should be unrolled if tuned for cpus with
10582 a built-in stride prefetcher.
10583 The loop is analyzed for memory accesses by calling check_dpu for
10584 each rtx of the loop. Depending on the loop_depth and the amount of
10585 memory accesses a new number <=nunroll is returned to improve the
10586 behaviour of the hardware prefetch unit. */
10588 s390_loop_unroll_adjust (unsigned nunroll
, struct loop
*loop
)
10593 unsigned mem_count
= 0;
10595 if (s390_tune
!= PROCESSOR_2097_Z10
&& s390_tune
!= PROCESSOR_2817_Z196
)
10598 /* Count the number of memory references within the loop body. */
10599 bbs
= get_loop_body (loop
);
10600 for (i
= 0; i
< loop
->num_nodes
; i
++)
10602 for (insn
= BB_HEAD (bbs
[i
]); insn
!= BB_END (bbs
[i
]); insn
= NEXT_INSN (insn
))
10603 if (INSN_P (insn
) && INSN_CODE (insn
) != -1)
10604 for_each_rtx (&insn
, (rtx_function
) check_dpu
, &mem_count
);
10608 /* Prevent division by zero, and we do not need to adjust nunroll in this case. */
10609 if (mem_count
== 0)
10612 switch (loop_depth(loop
))
10615 return MIN (nunroll
, 28 / mem_count
);
10617 return MIN (nunroll
, 22 / mem_count
);
10619 return MIN (nunroll
, 16 / mem_count
);
10623 /* Initialize GCC target structure. */
10625 #undef TARGET_ASM_ALIGNED_HI_OP
10626 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
10627 #undef TARGET_ASM_ALIGNED_DI_OP
10628 #define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
10629 #undef TARGET_ASM_INTEGER
10630 #define TARGET_ASM_INTEGER s390_assemble_integer
10632 #undef TARGET_ASM_OPEN_PAREN
10633 #define TARGET_ASM_OPEN_PAREN ""
10635 #undef TARGET_ASM_CLOSE_PAREN
10636 #define TARGET_ASM_CLOSE_PAREN ""
10638 #undef TARGET_DEFAULT_TARGET_FLAGS
10639 #define TARGET_DEFAULT_TARGET_FLAGS (TARGET_DEFAULT)
10641 #undef TARGET_HANDLE_OPTION
10642 #define TARGET_HANDLE_OPTION s390_handle_option
10644 #undef TARGET_OPTION_OVERRIDE
10645 #define TARGET_OPTION_OVERRIDE s390_option_override
10647 #undef TARGET_OPTION_OPTIMIZATION_TABLE
10648 #define TARGET_OPTION_OPTIMIZATION_TABLE s390_option_optimization_table
10650 #undef TARGET_OPTION_INIT_STRUCT
10651 #define TARGET_OPTION_INIT_STRUCT s390_option_init_struct
10653 #undef TARGET_ENCODE_SECTION_INFO
10654 #define TARGET_ENCODE_SECTION_INFO s390_encode_section_info
10656 #undef TARGET_SCALAR_MODE_SUPPORTED_P
10657 #define TARGET_SCALAR_MODE_SUPPORTED_P s390_scalar_mode_supported_p
10660 #undef TARGET_HAVE_TLS
10661 #define TARGET_HAVE_TLS true
10663 #undef TARGET_CANNOT_FORCE_CONST_MEM
10664 #define TARGET_CANNOT_FORCE_CONST_MEM s390_cannot_force_const_mem
10666 #undef TARGET_DELEGITIMIZE_ADDRESS
10667 #define TARGET_DELEGITIMIZE_ADDRESS s390_delegitimize_address
10669 #undef TARGET_LEGITIMIZE_ADDRESS
10670 #define TARGET_LEGITIMIZE_ADDRESS s390_legitimize_address
10672 #undef TARGET_RETURN_IN_MEMORY
10673 #define TARGET_RETURN_IN_MEMORY s390_return_in_memory
10675 #undef TARGET_INIT_BUILTINS
10676 #define TARGET_INIT_BUILTINS s390_init_builtins
10677 #undef TARGET_EXPAND_BUILTIN
10678 #define TARGET_EXPAND_BUILTIN s390_expand_builtin
10680 #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA
10681 #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA s390_output_addr_const_extra
10683 #undef TARGET_ASM_OUTPUT_MI_THUNK
10684 #define TARGET_ASM_OUTPUT_MI_THUNK s390_output_mi_thunk
10685 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
10686 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_const_tree_hwi_hwi_const_tree_true
10688 #undef TARGET_SCHED_ADJUST_PRIORITY
10689 #define TARGET_SCHED_ADJUST_PRIORITY s390_adjust_priority
10690 #undef TARGET_SCHED_ISSUE_RATE
10691 #define TARGET_SCHED_ISSUE_RATE s390_issue_rate
10692 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
10693 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD s390_first_cycle_multipass_dfa_lookahead
10695 #undef TARGET_SCHED_VARIABLE_ISSUE
10696 #define TARGET_SCHED_VARIABLE_ISSUE s390_sched_variable_issue
10697 #undef TARGET_SCHED_REORDER
10698 #define TARGET_SCHED_REORDER s390_sched_reorder
10699 #undef TARGET_SCHED_INIT
10700 #define TARGET_SCHED_INIT s390_sched_init
10702 #undef TARGET_CANNOT_COPY_INSN_P
10703 #define TARGET_CANNOT_COPY_INSN_P s390_cannot_copy_insn_p
10704 #undef TARGET_RTX_COSTS
10705 #define TARGET_RTX_COSTS s390_rtx_costs
10706 #undef TARGET_ADDRESS_COST
10707 #define TARGET_ADDRESS_COST s390_address_cost
10708 #undef TARGET_REGISTER_MOVE_COST
10709 #define TARGET_REGISTER_MOVE_COST s390_register_move_cost
10710 #undef TARGET_MEMORY_MOVE_COST
10711 #define TARGET_MEMORY_MOVE_COST s390_memory_move_cost
10713 #undef TARGET_MACHINE_DEPENDENT_REORG
10714 #define TARGET_MACHINE_DEPENDENT_REORG s390_reorg
10716 #undef TARGET_VALID_POINTER_MODE
10717 #define TARGET_VALID_POINTER_MODE s390_valid_pointer_mode
10719 #undef TARGET_BUILD_BUILTIN_VA_LIST
10720 #define TARGET_BUILD_BUILTIN_VA_LIST s390_build_builtin_va_list
10721 #undef TARGET_EXPAND_BUILTIN_VA_START
10722 #define TARGET_EXPAND_BUILTIN_VA_START s390_va_start
10723 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
10724 #define TARGET_GIMPLIFY_VA_ARG_EXPR s390_gimplify_va_arg
10726 #undef TARGET_PROMOTE_FUNCTION_MODE
10727 #define TARGET_PROMOTE_FUNCTION_MODE s390_promote_function_mode
10728 #undef TARGET_PASS_BY_REFERENCE
10729 #define TARGET_PASS_BY_REFERENCE s390_pass_by_reference
10731 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
10732 #define TARGET_FUNCTION_OK_FOR_SIBCALL s390_function_ok_for_sibcall
10733 #undef TARGET_FUNCTION_ARG
10734 #define TARGET_FUNCTION_ARG s390_function_arg
10735 #undef TARGET_FUNCTION_ARG_ADVANCE
10736 #define TARGET_FUNCTION_ARG_ADVANCE s390_function_arg_advance
10737 #undef TARGET_FUNCTION_VALUE
10738 #define TARGET_FUNCTION_VALUE s390_function_value
10739 #undef TARGET_LIBCALL_VALUE
10740 #define TARGET_LIBCALL_VALUE s390_libcall_value
10742 #undef TARGET_FIXED_CONDITION_CODE_REGS
10743 #define TARGET_FIXED_CONDITION_CODE_REGS s390_fixed_condition_code_regs
10745 #undef TARGET_CC_MODES_COMPATIBLE
10746 #define TARGET_CC_MODES_COMPATIBLE s390_cc_modes_compatible
10748 #undef TARGET_INVALID_WITHIN_DOLOOP
10749 #define TARGET_INVALID_WITHIN_DOLOOP hook_constcharptr_const_rtx_null
10752 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
10753 #define TARGET_ASM_OUTPUT_DWARF_DTPREL s390_output_dwarf_dtprel
10756 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
10757 #undef TARGET_MANGLE_TYPE
10758 #define TARGET_MANGLE_TYPE s390_mangle_type
10761 #undef TARGET_SCALAR_MODE_SUPPORTED_P
10762 #define TARGET_SCALAR_MODE_SUPPORTED_P s390_scalar_mode_supported_p
10764 #undef TARGET_PREFERRED_RELOAD_CLASS
10765 #define TARGET_PREFERRED_RELOAD_CLASS s390_preferred_reload_class
10767 #undef TARGET_SECONDARY_RELOAD
10768 #define TARGET_SECONDARY_RELOAD s390_secondary_reload
10770 #undef TARGET_LIBGCC_CMP_RETURN_MODE
10771 #define TARGET_LIBGCC_CMP_RETURN_MODE s390_libgcc_cmp_return_mode
10773 #undef TARGET_LIBGCC_SHIFT_COUNT_MODE
10774 #define TARGET_LIBGCC_SHIFT_COUNT_MODE s390_libgcc_shift_count_mode
10776 #undef TARGET_LEGITIMATE_ADDRESS_P
10777 #define TARGET_LEGITIMATE_ADDRESS_P s390_legitimate_address_p
10779 #undef TARGET_CAN_ELIMINATE
10780 #define TARGET_CAN_ELIMINATE s390_can_eliminate
10782 #undef TARGET_CONDITIONAL_REGISTER_USAGE
10783 #define TARGET_CONDITIONAL_REGISTER_USAGE s390_conditional_register_usage
10785 #undef TARGET_LOOP_UNROLL_ADJUST
10786 #define TARGET_LOOP_UNROLL_ADJUST s390_loop_unroll_adjust
10788 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
10789 #define TARGET_ASM_TRAMPOLINE_TEMPLATE s390_asm_trampoline_template
10790 #undef TARGET_TRAMPOLINE_INIT
10791 #define TARGET_TRAMPOLINE_INIT s390_trampoline_init
10793 #undef TARGET_UNWIND_WORD_MODE
10794 #define TARGET_UNWIND_WORD_MODE s390_unwind_word_mode
10796 struct gcc_target targetm
= TARGET_INITIALIZER
;
10798 #include "gt-s390.h"