1 /* Subroutines used for code generation on IBM S/390 and zSeries
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
3 Free Software Foundation, Inc.
4 Contributed by Hartmut Penner (hpenner@de.ibm.com) and
5 Ulrich Weigand (uweigand@de.ibm.com).
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 2, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING. If not, write to the Free
21 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
26 #include "coretypes.h"
32 #include "hard-reg-set.h"
34 #include "insn-config.h"
35 #include "conditions.h"
37 #include "insn-attr.h"
45 #include "basic-block.h"
46 #include "integrate.h"
49 #include "target-def.h"
51 #include "langhooks.h"
53 #include "tree-gimple.h"
56 /* Define the specific costs for a given cpu. */
58 struct processor_costs
61 const int m
; /* cost of an M instruction. */
62 const int mghi
; /* cost of an MGHI instruction. */
63 const int mh
; /* cost of an MH instruction. */
64 const int mhi
; /* cost of an MHI instruction. */
65 const int ml
; /* cost of an ML instruction. */
66 const int mr
; /* cost of an MR instruction. */
67 const int ms
; /* cost of an MS instruction. */
68 const int msg
; /* cost of an MSG instruction. */
69 const int msgf
; /* cost of an MSGF instruction. */
70 const int msgfr
; /* cost of an MSGFR instruction. */
71 const int msgr
; /* cost of an MSGR instruction. */
72 const int msr
; /* cost of an MSR instruction. */
73 const int mult_df
; /* cost of multiplication in DFmode. */
76 const int sqxbr
; /* cost of square root in TFmode. */
77 const int sqdbr
; /* cost of square root in DFmode. */
78 const int sqebr
; /* cost of square root in SFmode. */
79 /* multiply and add */
80 const int madbr
; /* cost of multiply and add in DFmode. */
81 const int maebr
; /* cost of multiply and add in SFmode. */
96 const struct processor_costs
*s390_cost
;
99 struct processor_costs z900_cost
=
101 COSTS_N_INSNS (5), /* M */
102 COSTS_N_INSNS (10), /* MGHI */
103 COSTS_N_INSNS (5), /* MH */
104 COSTS_N_INSNS (4), /* MHI */
105 COSTS_N_INSNS (5), /* ML */
106 COSTS_N_INSNS (5), /* MR */
107 COSTS_N_INSNS (4), /* MS */
108 COSTS_N_INSNS (15), /* MSG */
109 COSTS_N_INSNS (7), /* MSGF */
110 COSTS_N_INSNS (7), /* MSGFR */
111 COSTS_N_INSNS (10), /* MSGR */
112 COSTS_N_INSNS (4), /* MSR */
113 COSTS_N_INSNS (7), /* multiplication in DFmode */
114 COSTS_N_INSNS (13), /* MXBR */
115 COSTS_N_INSNS (136), /* SQXBR */
116 COSTS_N_INSNS (44), /* SQDBR */
117 COSTS_N_INSNS (35), /* SQEBR */
118 COSTS_N_INSNS (18), /* MADBR */
119 COSTS_N_INSNS (13), /* MAEBR */
120 COSTS_N_INSNS (134), /* DXBR */
121 COSTS_N_INSNS (135), /* DXR */
122 COSTS_N_INSNS (30), /* DDBR */
123 COSTS_N_INSNS (30), /* DDR */
124 COSTS_N_INSNS (27), /* DEBR */
125 COSTS_N_INSNS (26), /* DER */
126 COSTS_N_INSNS (220), /* DLGR */
127 COSTS_N_INSNS (34), /* DLR */
128 COSTS_N_INSNS (34), /* DR */
129 COSTS_N_INSNS (32), /* DSGFR */
130 COSTS_N_INSNS (32), /* DSGR */
134 struct processor_costs z990_cost
=
136 COSTS_N_INSNS (4), /* M */
137 COSTS_N_INSNS (2), /* MGHI */
138 COSTS_N_INSNS (2), /* MH */
139 COSTS_N_INSNS (2), /* MHI */
140 COSTS_N_INSNS (4), /* ML */
141 COSTS_N_INSNS (4), /* MR */
142 COSTS_N_INSNS (5), /* MS */
143 COSTS_N_INSNS (6), /* MSG */
144 COSTS_N_INSNS (4), /* MSGF */
145 COSTS_N_INSNS (4), /* MSGFR */
146 COSTS_N_INSNS (4), /* MSGR */
147 COSTS_N_INSNS (4), /* MSR */
148 COSTS_N_INSNS (1), /* multiplication in DFmode */
149 COSTS_N_INSNS (28), /* MXBR */
150 COSTS_N_INSNS (130), /* SQXBR */
151 COSTS_N_INSNS (66), /* SQDBR */
152 COSTS_N_INSNS (38), /* SQEBR */
153 COSTS_N_INSNS (1), /* MADBR */
154 COSTS_N_INSNS (1), /* MAEBR */
155 COSTS_N_INSNS (60), /* DXBR */
156 COSTS_N_INSNS (72), /* DXR */
157 COSTS_N_INSNS (40), /* DDBR */
158 COSTS_N_INSNS (44), /* DDR */
159 COSTS_N_INSNS (26), /* DDBR */
160 COSTS_N_INSNS (28), /* DER */
161 COSTS_N_INSNS (176), /* DLGR */
162 COSTS_N_INSNS (31), /* DLR */
163 COSTS_N_INSNS (31), /* DR */
164 COSTS_N_INSNS (31), /* DSGFR */
165 COSTS_N_INSNS (31), /* DSGR */
169 struct processor_costs z9_109_cost
=
171 COSTS_N_INSNS (4), /* M */
172 COSTS_N_INSNS (2), /* MGHI */
173 COSTS_N_INSNS (2), /* MH */
174 COSTS_N_INSNS (2), /* MHI */
175 COSTS_N_INSNS (4), /* ML */
176 COSTS_N_INSNS (4), /* MR */
177 COSTS_N_INSNS (5), /* MS */
178 COSTS_N_INSNS (6), /* MSG */
179 COSTS_N_INSNS (4), /* MSGF */
180 COSTS_N_INSNS (4), /* MSGFR */
181 COSTS_N_INSNS (4), /* MSGR */
182 COSTS_N_INSNS (4), /* MSR */
183 COSTS_N_INSNS (1), /* multiplication in DFmode */
184 COSTS_N_INSNS (28), /* MXBR */
185 COSTS_N_INSNS (130), /* SQXBR */
186 COSTS_N_INSNS (66), /* SQDBR */
187 COSTS_N_INSNS (38), /* SQEBR */
188 COSTS_N_INSNS (1), /* MADBR */
189 COSTS_N_INSNS (1), /* MAEBR */
190 COSTS_N_INSNS (60), /* DXBR */
191 COSTS_N_INSNS (72), /* DXR */
192 COSTS_N_INSNS (40), /* DDBR */
193 COSTS_N_INSNS (37), /* DDR */
194 COSTS_N_INSNS (26), /* DDBR */
195 COSTS_N_INSNS (28), /* DER */
196 COSTS_N_INSNS (30), /* DLGR */
197 COSTS_N_INSNS (23), /* DLR */
198 COSTS_N_INSNS (23), /* DR */
199 COSTS_N_INSNS (24), /* DSGFR */
200 COSTS_N_INSNS (24), /* DSGR */
203 extern int reload_completed
;
205 /* Save information from a "cmpxx" operation until the branch or scc is
207 rtx s390_compare_op0
, s390_compare_op1
;
209 /* Save the result of a compare_and_swap until the branch or scc is
211 rtx s390_compare_emitted
= NULL_RTX
;
213 /* Structure used to hold the components of a S/390 memory
214 address. A legitimate address on S/390 is of the general
216 base + index + displacement
217 where any of the components is optional.
219 base and index are registers of the class ADDR_REGS,
220 displacement is an unsigned 12-bit immediate constant. */
231 /* Which cpu are we tuning for. */
232 enum processor_type s390_tune
= PROCESSOR_max
;
233 enum processor_flags s390_tune_flags
;
234 /* Which instruction set architecture to use. */
235 enum processor_type s390_arch
;
236 enum processor_flags s390_arch_flags
;
238 HOST_WIDE_INT s390_warn_framesize
= 0;
239 HOST_WIDE_INT s390_stack_size
= 0;
240 HOST_WIDE_INT s390_stack_guard
= 0;
242 /* The following structure is embedded in the machine
243 specific part of struct function. */
245 struct s390_frame_layout
GTY (())
247 /* Offset within stack frame. */
248 HOST_WIDE_INT gprs_offset
;
249 HOST_WIDE_INT f0_offset
;
250 HOST_WIDE_INT f4_offset
;
251 HOST_WIDE_INT f8_offset
;
252 HOST_WIDE_INT backchain_offset
;
254 /* Number of first and last gpr where slots in the register
255 save area are reserved for. */
256 int first_save_gpr_slot
;
257 int last_save_gpr_slot
;
259 /* Number of first and last gpr to be saved, restored. */
261 int first_restore_gpr
;
263 int last_restore_gpr
;
265 /* Bits standing for floating point registers. Set, if the
266 respective register has to be saved. Starting with reg 16 (f0)
267 at the rightmost bit.
268 Bit 15 - 8 7 6 5 4 3 2 1 0
269 fpr 15 - 8 7 5 3 1 6 4 2 0
270 reg 31 - 24 23 22 21 20 19 18 17 16 */
271 unsigned int fpr_bitmap
;
273 /* Number of floating point registers f8-f15 which must be saved. */
276 /* Set if return address needs to be saved.
277 This flag is set by s390_return_addr_rtx if it could not use
278 the initial value of r14 and therefore depends on r14 saved
280 bool save_return_addr_p
;
282 /* Size of stack frame. */
283 HOST_WIDE_INT frame_size
;
286 /* Define the structure for the machine field in struct function. */
288 struct machine_function
GTY(())
290 struct s390_frame_layout frame_layout
;
292 /* Literal pool base register. */
295 /* True if we may need to perform branch splitting. */
296 bool split_branches_pending_p
;
298 /* True during final stage of literal pool processing. */
299 bool decomposed_literal_pool_addresses_ok_p
;
301 /* Some local-dynamic TLS symbol name. */
302 const char *some_ld_name
;
304 bool has_landing_pad_p
;
307 /* Few accessor macros for struct cfun->machine->s390_frame_layout. */
309 #define cfun_frame_layout (cfun->machine->frame_layout)
310 #define cfun_save_high_fprs_p (!!cfun_frame_layout.high_fprs)
311 #define cfun_gprs_save_area_size ((cfun_frame_layout.last_save_gpr_slot - \
312 cfun_frame_layout.first_save_gpr_slot + 1) * UNITS_PER_WORD)
313 #define cfun_set_fpr_bit(BITNUM) (cfun->machine->frame_layout.fpr_bitmap |= \
315 #define cfun_fpr_bit_p(BITNUM) (!!(cfun->machine->frame_layout.fpr_bitmap & \
318 /* Number of GPRs and FPRs used for argument passing. */
319 #define GP_ARG_NUM_REG 5
320 #define FP_ARG_NUM_REG (TARGET_64BIT? 4 : 2)
322 /* A couple of shortcuts. */
323 #define CONST_OK_FOR_J(x) \
324 CONST_OK_FOR_CONSTRAINT_P((x), 'J', "J")
325 #define CONST_OK_FOR_K(x) \
326 CONST_OK_FOR_CONSTRAINT_P((x), 'K', "K")
327 #define CONST_OK_FOR_Os(x) \
328 CONST_OK_FOR_CONSTRAINT_P((x), 'O', "Os")
329 #define CONST_OK_FOR_Op(x) \
330 CONST_OK_FOR_CONSTRAINT_P((x), 'O', "Op")
331 #define CONST_OK_FOR_On(x) \
332 CONST_OK_FOR_CONSTRAINT_P((x), 'O', "On")
334 #define REGNO_PAIR_OK(REGNO, MODE) \
335 (HARD_REGNO_NREGS ((REGNO), (MODE)) == 1 || !((REGNO) & 1))
337 /* Return true if the back end supports mode MODE. */
339 s390_scalar_mode_supported_p (enum machine_mode mode
)
341 if (DECIMAL_FLOAT_MODE_P (mode
))
344 return default_scalar_mode_supported_p (mode
);
347 /* Set the has_landing_pad_p flag in struct machine_function to VALUE. */
350 s390_set_has_landing_pad_p (bool value
)
352 cfun
->machine
->has_landing_pad_p
= value
;
355 /* If two condition code modes are compatible, return a condition code
356 mode which is compatible with both. Otherwise, return
359 static enum machine_mode
360 s390_cc_modes_compatible (enum machine_mode m1
, enum machine_mode m2
)
368 if (m2
== CCUmode
|| m2
== CCTmode
|| m2
== CCZ1mode
369 || m2
== CCSmode
|| m2
== CCSRmode
|| m2
== CCURmode
)
390 /* Return true if SET either doesn't set the CC register, or else
391 the source and destination have matching CC modes and that
392 CC mode is at least as constrained as REQ_MODE. */
395 s390_match_ccmode_set (rtx set
, enum machine_mode req_mode
)
397 enum machine_mode set_mode
;
399 gcc_assert (GET_CODE (set
) == SET
);
401 if (GET_CODE (SET_DEST (set
)) != REG
|| !CC_REGNO_P (REGNO (SET_DEST (set
))))
404 set_mode
= GET_MODE (SET_DEST (set
));
418 if (req_mode
!= set_mode
)
423 if (req_mode
!= CCSmode
&& req_mode
!= CCUmode
&& req_mode
!= CCTmode
424 && req_mode
!= CCSRmode
&& req_mode
!= CCURmode
)
430 if (req_mode
!= CCAmode
)
438 return (GET_MODE (SET_SRC (set
)) == set_mode
);
441 /* Return true if every SET in INSN that sets the CC register
442 has source and destination with matching CC modes and that
443 CC mode is at least as constrained as REQ_MODE.
444 If REQ_MODE is VOIDmode, always return false. */
447 s390_match_ccmode (rtx insn
, enum machine_mode req_mode
)
451 /* s390_tm_ccmode returns VOIDmode to indicate failure. */
452 if (req_mode
== VOIDmode
)
455 if (GET_CODE (PATTERN (insn
)) == SET
)
456 return s390_match_ccmode_set (PATTERN (insn
), req_mode
);
458 if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
459 for (i
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
461 rtx set
= XVECEXP (PATTERN (insn
), 0, i
);
462 if (GET_CODE (set
) == SET
)
463 if (!s390_match_ccmode_set (set
, req_mode
))
470 /* If a test-under-mask instruction can be used to implement
471 (compare (and ... OP1) OP2), return the CC mode required
472 to do that. Otherwise, return VOIDmode.
473 MIXED is true if the instruction can distinguish between
474 CC1 and CC2 for mixed selected bits (TMxx), it is false
475 if the instruction cannot (TM). */
478 s390_tm_ccmode (rtx op1
, rtx op2
, bool mixed
)
482 /* ??? Fixme: should work on CONST_DOUBLE as well. */
483 if (GET_CODE (op1
) != CONST_INT
|| GET_CODE (op2
) != CONST_INT
)
486 /* Selected bits all zero: CC0.
487 e.g.: int a; if ((a & (16 + 128)) == 0) */
488 if (INTVAL (op2
) == 0)
491 /* Selected bits all one: CC3.
492 e.g.: int a; if ((a & (16 + 128)) == 16 + 128) */
493 if (INTVAL (op2
) == INTVAL (op1
))
496 /* Exactly two bits selected, mixed zeroes and ones: CC1 or CC2. e.g.:
498 if ((a & (16 + 128)) == 16) -> CCT1
499 if ((a & (16 + 128)) == 128) -> CCT2 */
502 bit1
= exact_log2 (INTVAL (op2
));
503 bit0
= exact_log2 (INTVAL (op1
) ^ INTVAL (op2
));
504 if (bit0
!= -1 && bit1
!= -1)
505 return bit0
> bit1
? CCT1mode
: CCT2mode
;
511 /* Given a comparison code OP (EQ, NE, etc.) and the operands
512 OP0 and OP1 of a COMPARE, return the mode to be used for the
516 s390_select_ccmode (enum rtx_code code
, rtx op0
, rtx op1
)
522 if ((GET_CODE (op0
) == NEG
|| GET_CODE (op0
) == ABS
)
523 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
525 if (GET_CODE (op0
) == PLUS
&& GET_CODE (XEXP (op0
, 1)) == CONST_INT
526 && CONST_OK_FOR_K (INTVAL (XEXP (op0
, 1))))
528 if ((GET_CODE (op0
) == PLUS
|| GET_CODE (op0
) == MINUS
529 || GET_CODE (op1
) == NEG
)
530 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
533 if (GET_CODE (op0
) == AND
)
535 /* Check whether we can potentially do it via TM. */
536 enum machine_mode ccmode
;
537 ccmode
= s390_tm_ccmode (XEXP (op0
, 1), op1
, 1);
538 if (ccmode
!= VOIDmode
)
540 /* Relax CCTmode to CCZmode to allow fall-back to AND
541 if that turns out to be beneficial. */
542 return ccmode
== CCTmode
? CCZmode
: ccmode
;
546 if (register_operand (op0
, HImode
)
547 && GET_CODE (op1
) == CONST_INT
548 && (INTVAL (op1
) == -1 || INTVAL (op1
) == 65535))
550 if (register_operand (op0
, QImode
)
551 && GET_CODE (op1
) == CONST_INT
552 && (INTVAL (op1
) == -1 || INTVAL (op1
) == 255))
561 /* The only overflow condition of NEG and ABS happens when
562 -INT_MAX is used as parameter, which stays negative. So
563 we have an overflow from a positive value to a negative.
564 Using CCAP mode the resulting cc can be used for comparisons. */
565 if ((GET_CODE (op0
) == NEG
|| GET_CODE (op0
) == ABS
)
566 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
569 /* If constants are involved in an add instruction it is possible to use
570 the resulting cc for comparisons with zero. Knowing the sign of the
571 constant the overflow behavior gets predictable. e.g.:
572 int a, b; if ((b = a + c) > 0)
573 with c as a constant value: c < 0 -> CCAN and c >= 0 -> CCAP */
574 if (GET_CODE (op0
) == PLUS
&& GET_CODE (XEXP (op0
, 1)) == CONST_INT
575 && CONST_OK_FOR_K (INTVAL (XEXP (op0
, 1))))
577 if (INTVAL (XEXP((op0
), 1)) < 0)
591 if ((GET_CODE (op0
) == SIGN_EXTEND
|| GET_CODE (op0
) == ZERO_EXTEND
)
592 && GET_CODE (op1
) != CONST_INT
)
598 if (GET_CODE (op0
) == PLUS
599 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
602 if ((GET_CODE (op0
) == SIGN_EXTEND
|| GET_CODE (op0
) == ZERO_EXTEND
)
603 && GET_CODE (op1
) != CONST_INT
)
609 if (GET_CODE (op0
) == MINUS
610 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
613 if ((GET_CODE (op0
) == SIGN_EXTEND
|| GET_CODE (op0
) == ZERO_EXTEND
)
614 && GET_CODE (op1
) != CONST_INT
)
623 /* Replace the comparison OP0 CODE OP1 by a semantically equivalent one
624 that we can implement more efficiently. */
627 s390_canonicalize_comparison (enum rtx_code
*code
, rtx
*op0
, rtx
*op1
)
629 /* Convert ZERO_EXTRACT back to AND to enable TM patterns. */
630 if ((*code
== EQ
|| *code
== NE
)
631 && *op1
== const0_rtx
632 && GET_CODE (*op0
) == ZERO_EXTRACT
633 && GET_CODE (XEXP (*op0
, 1)) == CONST_INT
634 && GET_CODE (XEXP (*op0
, 2)) == CONST_INT
635 && SCALAR_INT_MODE_P (GET_MODE (XEXP (*op0
, 0))))
637 rtx inner
= XEXP (*op0
, 0);
638 HOST_WIDE_INT modesize
= GET_MODE_BITSIZE (GET_MODE (inner
));
639 HOST_WIDE_INT len
= INTVAL (XEXP (*op0
, 1));
640 HOST_WIDE_INT pos
= INTVAL (XEXP (*op0
, 2));
642 if (len
> 0 && len
< modesize
643 && pos
>= 0 && pos
+ len
<= modesize
644 && modesize
<= HOST_BITS_PER_WIDE_INT
)
646 unsigned HOST_WIDE_INT block
;
647 block
= ((unsigned HOST_WIDE_INT
) 1 << len
) - 1;
648 block
<<= modesize
- pos
- len
;
650 *op0
= gen_rtx_AND (GET_MODE (inner
), inner
,
651 gen_int_mode (block
, GET_MODE (inner
)));
655 /* Narrow AND of memory against immediate to enable TM. */
656 if ((*code
== EQ
|| *code
== NE
)
657 && *op1
== const0_rtx
658 && GET_CODE (*op0
) == AND
659 && GET_CODE (XEXP (*op0
, 1)) == CONST_INT
660 && SCALAR_INT_MODE_P (GET_MODE (XEXP (*op0
, 0))))
662 rtx inner
= XEXP (*op0
, 0);
663 rtx mask
= XEXP (*op0
, 1);
665 /* Ignore paradoxical SUBREGs if all extra bits are masked out. */
666 if (GET_CODE (inner
) == SUBREG
667 && SCALAR_INT_MODE_P (GET_MODE (SUBREG_REG (inner
)))
668 && (GET_MODE_SIZE (GET_MODE (inner
))
669 >= GET_MODE_SIZE (GET_MODE (SUBREG_REG (inner
))))
671 & GET_MODE_MASK (GET_MODE (inner
))
672 & ~GET_MODE_MASK (GET_MODE (SUBREG_REG (inner
))))
674 inner
= SUBREG_REG (inner
);
676 /* Do not change volatile MEMs. */
677 if (MEM_P (inner
) && !MEM_VOLATILE_P (inner
))
679 int part
= s390_single_part (XEXP (*op0
, 1),
680 GET_MODE (inner
), QImode
, 0);
683 mask
= gen_int_mode (s390_extract_part (mask
, QImode
, 0), QImode
);
684 inner
= adjust_address_nv (inner
, QImode
, part
);
685 *op0
= gen_rtx_AND (QImode
, inner
, mask
);
690 /* Narrow comparisons against 0xffff to HImode if possible. */
691 if ((*code
== EQ
|| *code
== NE
)
692 && GET_CODE (*op1
) == CONST_INT
693 && INTVAL (*op1
) == 0xffff
694 && SCALAR_INT_MODE_P (GET_MODE (*op0
))
695 && (nonzero_bits (*op0
, GET_MODE (*op0
))
696 & ~(unsigned HOST_WIDE_INT
) 0xffff) == 0)
698 *op0
= gen_lowpart (HImode
, *op0
);
703 /* Remove redundant UNSPEC_CMPINT conversions if possible. */
704 if (GET_CODE (*op0
) == UNSPEC
705 && XINT (*op0
, 1) == UNSPEC_CMPINT
706 && XVECLEN (*op0
, 0) == 1
707 && GET_MODE (XVECEXP (*op0
, 0, 0)) == CCUmode
708 && GET_CODE (XVECEXP (*op0
, 0, 0)) == REG
709 && REGNO (XVECEXP (*op0
, 0, 0)) == CC_REGNUM
710 && *op1
== const0_rtx
)
712 enum rtx_code new_code
= UNKNOWN
;
715 case EQ
: new_code
= EQ
; break;
716 case NE
: new_code
= NE
; break;
717 case LT
: new_code
= GTU
; break;
718 case GT
: new_code
= LTU
; break;
719 case LE
: new_code
= GEU
; break;
720 case GE
: new_code
= LEU
; break;
724 if (new_code
!= UNKNOWN
)
726 *op0
= XVECEXP (*op0
, 0, 0);
731 /* Simplify cascaded EQ, NE with const0_rtx. */
732 if ((*code
== NE
|| *code
== EQ
)
733 && (GET_CODE (*op0
) == EQ
|| GET_CODE (*op0
) == NE
)
734 && GET_MODE (*op0
) == SImode
735 && GET_MODE (XEXP (*op0
, 0)) == CCZ1mode
736 && REG_P (XEXP (*op0
, 0))
737 && XEXP (*op0
, 1) == const0_rtx
738 && *op1
== const0_rtx
)
740 if ((*code
== EQ
&& GET_CODE (*op0
) == NE
)
741 || (*code
== NE
&& GET_CODE (*op0
) == EQ
))
745 *op0
= XEXP (*op0
, 0);
748 /* Prefer register over memory as first operand. */
749 if (MEM_P (*op0
) && REG_P (*op1
))
751 rtx tem
= *op0
; *op0
= *op1
; *op1
= tem
;
752 *code
= swap_condition (*code
);
756 /* Emit a compare instruction suitable to implement the comparison
757 OP0 CODE OP1. Return the correct condition RTL to be placed in
758 the IF_THEN_ELSE of the conditional branch testing the result. */
761 s390_emit_compare (enum rtx_code code
, rtx op0
, rtx op1
)
763 enum machine_mode mode
= s390_select_ccmode (code
, op0
, op1
);
766 /* Do not output a redundant compare instruction if a compare_and_swap
767 pattern already computed the result and the machine modes are compatible. */
768 if (s390_compare_emitted
769 && (s390_cc_modes_compatible (GET_MODE (s390_compare_emitted
), mode
)
770 == GET_MODE (s390_compare_emitted
)))
771 ret
= gen_rtx_fmt_ee (code
, VOIDmode
, s390_compare_emitted
, const0_rtx
);
774 rtx cc
= gen_rtx_REG (mode
, CC_REGNUM
);
776 emit_insn (gen_rtx_SET (VOIDmode
, cc
, gen_rtx_COMPARE (mode
, op0
, op1
)));
777 ret
= gen_rtx_fmt_ee (code
, VOIDmode
, cc
, const0_rtx
);
779 s390_compare_emitted
= NULL_RTX
;
783 /* Emit a SImode compare and swap instruction setting MEM to NEW if OLD
785 Return the correct condition RTL to be placed in the IF_THEN_ELSE of the
786 conditional branch testing the result. */
789 s390_emit_compare_and_swap (enum rtx_code code
, rtx old
, rtx mem
, rtx cmp
, rtx
new)
793 emit_insn (gen_sync_compare_and_swap_ccsi (old
, mem
, cmp
, new));
794 ret
= gen_rtx_fmt_ee (code
, VOIDmode
, s390_compare_emitted
, const0_rtx
);
796 s390_compare_emitted
= NULL_RTX
;
801 /* Emit a jump instruction to TARGET. If COND is NULL_RTX, emit an
802 unconditional jump, else a conditional jump under condition COND. */
805 s390_emit_jump (rtx target
, rtx cond
)
809 target
= gen_rtx_LABEL_REF (VOIDmode
, target
);
811 target
= gen_rtx_IF_THEN_ELSE (VOIDmode
, cond
, target
, pc_rtx
);
813 insn
= gen_rtx_SET (VOIDmode
, pc_rtx
, target
);
814 emit_jump_insn (insn
);
817 /* Return branch condition mask to implement a branch
818 specified by CODE. Return -1 for invalid comparisons. */
821 s390_branch_condition_mask (rtx code
)
823 const int CC0
= 1 << 3;
824 const int CC1
= 1 << 2;
825 const int CC2
= 1 << 1;
826 const int CC3
= 1 << 0;
828 gcc_assert (GET_CODE (XEXP (code
, 0)) == REG
);
829 gcc_assert (REGNO (XEXP (code
, 0)) == CC_REGNUM
);
830 gcc_assert (XEXP (code
, 1) == const0_rtx
);
832 switch (GET_MODE (XEXP (code
, 0)))
836 switch (GET_CODE (code
))
839 case NE
: return CC1
| CC2
| CC3
;
845 switch (GET_CODE (code
))
848 case NE
: return CC0
| CC2
| CC3
;
854 switch (GET_CODE (code
))
857 case NE
: return CC0
| CC1
| CC3
;
863 switch (GET_CODE (code
))
866 case NE
: return CC0
| CC1
| CC2
;
872 switch (GET_CODE (code
))
874 case EQ
: return CC0
| CC2
;
875 case NE
: return CC1
| CC3
;
881 switch (GET_CODE (code
))
883 case LTU
: return CC2
| CC3
; /* carry */
884 case GEU
: return CC0
| CC1
; /* no carry */
890 switch (GET_CODE (code
))
892 case GTU
: return CC0
| CC1
; /* borrow */
893 case LEU
: return CC2
| CC3
; /* no borrow */
899 switch (GET_CODE (code
))
901 case EQ
: return CC0
| CC2
;
902 case NE
: return CC1
| CC3
;
903 case LTU
: return CC1
;
904 case GTU
: return CC3
;
905 case LEU
: return CC1
| CC2
;
906 case GEU
: return CC2
| CC3
;
911 switch (GET_CODE (code
))
914 case NE
: return CC1
| CC2
| CC3
;
915 case LTU
: return CC1
;
916 case GTU
: return CC2
;
917 case LEU
: return CC0
| CC1
;
918 case GEU
: return CC0
| CC2
;
924 switch (GET_CODE (code
))
927 case NE
: return CC2
| CC1
| CC3
;
928 case LTU
: return CC2
;
929 case GTU
: return CC1
;
930 case LEU
: return CC0
| CC2
;
931 case GEU
: return CC0
| CC1
;
937 switch (GET_CODE (code
))
940 case NE
: return CC1
| CC2
| CC3
;
941 case LT
: return CC1
| CC3
;
943 case LE
: return CC0
| CC1
| CC3
;
944 case GE
: return CC0
| CC2
;
950 switch (GET_CODE (code
))
953 case NE
: return CC1
| CC2
| CC3
;
955 case GT
: return CC2
| CC3
;
956 case LE
: return CC0
| CC1
;
957 case GE
: return CC0
| CC2
| CC3
;
963 switch (GET_CODE (code
))
966 case NE
: return CC1
| CC2
| CC3
;
969 case LE
: return CC0
| CC1
;
970 case GE
: return CC0
| CC2
;
971 case UNORDERED
: return CC3
;
972 case ORDERED
: return CC0
| CC1
| CC2
;
973 case UNEQ
: return CC0
| CC3
;
974 case UNLT
: return CC1
| CC3
;
975 case UNGT
: return CC2
| CC3
;
976 case UNLE
: return CC0
| CC1
| CC3
;
977 case UNGE
: return CC0
| CC2
| CC3
;
978 case LTGT
: return CC1
| CC2
;
984 switch (GET_CODE (code
))
987 case NE
: return CC2
| CC1
| CC3
;
990 case LE
: return CC0
| CC2
;
991 case GE
: return CC0
| CC1
;
992 case UNORDERED
: return CC3
;
993 case ORDERED
: return CC0
| CC2
| CC1
;
994 case UNEQ
: return CC0
| CC3
;
995 case UNLT
: return CC2
| CC3
;
996 case UNGT
: return CC1
| CC3
;
997 case UNLE
: return CC0
| CC2
| CC3
;
998 case UNGE
: return CC0
| CC1
| CC3
;
999 case LTGT
: return CC2
| CC1
;
1009 /* If INV is false, return assembler mnemonic string to implement
1010 a branch specified by CODE. If INV is true, return mnemonic
1011 for the corresponding inverted branch. */
1014 s390_branch_condition_mnemonic (rtx code
, int inv
)
1016 static const char *const mnemonic
[16] =
1018 NULL
, "o", "h", "nle",
1019 "l", "nhe", "lh", "ne",
1020 "e", "nlh", "he", "nl",
1021 "le", "nh", "no", NULL
1024 int mask
= s390_branch_condition_mask (code
);
1025 gcc_assert (mask
>= 0);
1030 gcc_assert (mask
>= 1 && mask
<= 14);
1032 return mnemonic
[mask
];
1035 /* Return the part of op which has a value different from def.
1036 The size of the part is determined by mode.
1037 Use this function only if you already know that op really
1038 contains such a part. */
1040 unsigned HOST_WIDE_INT
1041 s390_extract_part (rtx op
, enum machine_mode mode
, int def
)
1043 unsigned HOST_WIDE_INT value
= 0;
1044 int max_parts
= HOST_BITS_PER_WIDE_INT
/ GET_MODE_BITSIZE (mode
);
1045 int part_bits
= GET_MODE_BITSIZE (mode
);
1046 unsigned HOST_WIDE_INT part_mask
1047 = ((unsigned HOST_WIDE_INT
)1 << part_bits
) - 1;
1050 for (i
= 0; i
< max_parts
; i
++)
1053 value
= (unsigned HOST_WIDE_INT
) INTVAL (op
);
1055 value
>>= part_bits
;
1057 if ((value
& part_mask
) != (def
& part_mask
))
1058 return value
& part_mask
;
1064 /* If OP is an integer constant of mode MODE with exactly one
1065 part of mode PART_MODE unequal to DEF, return the number of that
1066 part. Otherwise, return -1. */
1069 s390_single_part (rtx op
,
1070 enum machine_mode mode
,
1071 enum machine_mode part_mode
,
1074 unsigned HOST_WIDE_INT value
= 0;
1075 int n_parts
= GET_MODE_SIZE (mode
) / GET_MODE_SIZE (part_mode
);
1076 unsigned HOST_WIDE_INT part_mask
1077 = ((unsigned HOST_WIDE_INT
)1 << GET_MODE_BITSIZE (part_mode
)) - 1;
1080 if (GET_CODE (op
) != CONST_INT
)
1083 for (i
= 0; i
< n_parts
; i
++)
1086 value
= (unsigned HOST_WIDE_INT
) INTVAL (op
);
1088 value
>>= GET_MODE_BITSIZE (part_mode
);
1090 if ((value
& part_mask
) != (def
& part_mask
))
1098 return part
== -1 ? -1 : n_parts
- 1 - part
;
1101 /* Check whether we can (and want to) split a double-word
1102 move in mode MODE from SRC to DST into two single-word
1103 moves, moving the subword FIRST_SUBWORD first. */
1106 s390_split_ok_p (rtx dst
, rtx src
, enum machine_mode mode
, int first_subword
)
1108 /* Floating point registers cannot be split. */
1109 if (FP_REG_P (src
) || FP_REG_P (dst
))
1112 /* We don't need to split if operands are directly accessible. */
1113 if (s_operand (src
, mode
) || s_operand (dst
, mode
))
1116 /* Non-offsettable memory references cannot be split. */
1117 if ((GET_CODE (src
) == MEM
&& !offsettable_memref_p (src
))
1118 || (GET_CODE (dst
) == MEM
&& !offsettable_memref_p (dst
)))
1121 /* Moving the first subword must not clobber a register
1122 needed to move the second subword. */
1123 if (register_operand (dst
, mode
))
1125 rtx subreg
= operand_subword (dst
, first_subword
, 0, mode
);
1126 if (reg_overlap_mentioned_p (subreg
, src
))
1133 /* Return true if it can be proven that [MEM1, MEM1 + SIZE]
1134 and [MEM2, MEM2 + SIZE] do overlap and false
1138 s390_overlap_p (rtx mem1
, rtx mem2
, HOST_WIDE_INT size
)
1140 rtx addr1
, addr2
, addr_delta
;
1141 HOST_WIDE_INT delta
;
1143 if (GET_CODE (mem1
) != MEM
|| GET_CODE (mem2
) != MEM
)
1149 addr1
= XEXP (mem1
, 0);
1150 addr2
= XEXP (mem2
, 0);
1152 addr_delta
= simplify_binary_operation (MINUS
, Pmode
, addr2
, addr1
);
1154 /* This overlapping check is used by peepholes merging memory block operations.
1155 Overlapping operations would otherwise be recognized by the S/390 hardware
1156 and would fall back to a slower implementation. Allowing overlapping
1157 operations would lead to slow code but not to wrong code. Therefore we are
1158 somewhat optimistic if we cannot prove that the memory blocks are
1160 That's why we return false here although this may accept operations on
1161 overlapping memory areas. */
1162 if (!addr_delta
|| GET_CODE (addr_delta
) != CONST_INT
)
1165 delta
= INTVAL (addr_delta
);
1168 || (delta
> 0 && delta
< size
)
1169 || (delta
< 0 && -delta
< size
))
1175 /* Check whether the address of memory reference MEM2 equals exactly
1176 the address of memory reference MEM1 plus DELTA. Return true if
1177 we can prove this to be the case, false otherwise. */
1180 s390_offset_p (rtx mem1
, rtx mem2
, rtx delta
)
1182 rtx addr1
, addr2
, addr_delta
;
1184 if (GET_CODE (mem1
) != MEM
|| GET_CODE (mem2
) != MEM
)
1187 addr1
= XEXP (mem1
, 0);
1188 addr2
= XEXP (mem2
, 0);
1190 addr_delta
= simplify_binary_operation (MINUS
, Pmode
, addr2
, addr1
);
1191 if (!addr_delta
|| !rtx_equal_p (addr_delta
, delta
))
1197 /* Expand logical operator CODE in mode MODE with operands OPERANDS. */
1200 s390_expand_logical_operator (enum rtx_code code
, enum machine_mode mode
,
1203 enum machine_mode wmode
= mode
;
1204 rtx dst
= operands
[0];
1205 rtx src1
= operands
[1];
1206 rtx src2
= operands
[2];
1209 /* If we cannot handle the operation directly, use a temp register. */
1210 if (!s390_logical_operator_ok_p (operands
))
1211 dst
= gen_reg_rtx (mode
);
1213 /* QImode and HImode patterns make sense only if we have a destination
1214 in memory. Otherwise perform the operation in SImode. */
1215 if ((mode
== QImode
|| mode
== HImode
) && GET_CODE (dst
) != MEM
)
1218 /* Widen operands if required. */
1221 if (GET_CODE (dst
) == SUBREG
1222 && (tem
= simplify_subreg (wmode
, dst
, mode
, 0)) != 0)
1224 else if (REG_P (dst
))
1225 dst
= gen_rtx_SUBREG (wmode
, dst
, 0);
1227 dst
= gen_reg_rtx (wmode
);
1229 if (GET_CODE (src1
) == SUBREG
1230 && (tem
= simplify_subreg (wmode
, src1
, mode
, 0)) != 0)
1232 else if (GET_MODE (src1
) != VOIDmode
)
1233 src1
= gen_rtx_SUBREG (wmode
, force_reg (mode
, src1
), 0);
1235 if (GET_CODE (src2
) == SUBREG
1236 && (tem
= simplify_subreg (wmode
, src2
, mode
, 0)) != 0)
1238 else if (GET_MODE (src2
) != VOIDmode
)
1239 src2
= gen_rtx_SUBREG (wmode
, force_reg (mode
, src2
), 0);
1242 /* Emit the instruction. */
1243 op
= gen_rtx_SET (VOIDmode
, dst
, gen_rtx_fmt_ee (code
, wmode
, src1
, src2
));
1244 clob
= gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
1245 emit_insn (gen_rtx_PARALLEL (VOIDmode
, gen_rtvec (2, op
, clob
)));
1247 /* Fix up the destination if needed. */
1248 if (dst
!= operands
[0])
1249 emit_move_insn (operands
[0], gen_lowpart (mode
, dst
));
1252 /* Check whether OPERANDS are OK for a logical operation (AND, IOR, XOR). */
1255 s390_logical_operator_ok_p (rtx
*operands
)
1257 /* If the destination operand is in memory, it needs to coincide
1258 with one of the source operands. After reload, it has to be
1259 the first source operand. */
1260 if (GET_CODE (operands
[0]) == MEM
)
1261 return rtx_equal_p (operands
[0], operands
[1])
1262 || (!reload_completed
&& rtx_equal_p (operands
[0], operands
[2]));
1267 /* Narrow logical operation CODE of memory operand MEMOP with immediate
1268 operand IMMOP to switch from SS to SI type instructions. */
1271 s390_narrow_logical_operator (enum rtx_code code
, rtx
*memop
, rtx
*immop
)
1273 int def
= code
== AND
? -1 : 0;
1277 gcc_assert (GET_CODE (*memop
) == MEM
);
1278 gcc_assert (!MEM_VOLATILE_P (*memop
));
1280 mask
= s390_extract_part (*immop
, QImode
, def
);
1281 part
= s390_single_part (*immop
, GET_MODE (*memop
), QImode
, def
);
1282 gcc_assert (part
>= 0);
1284 *memop
= adjust_address (*memop
, QImode
, part
);
1285 *immop
= gen_int_mode (mask
, QImode
);
1289 /* How to allocate a 'struct machine_function'. */
1291 static struct machine_function
*
1292 s390_init_machine_status (void)
1294 return ggc_alloc_cleared (sizeof (struct machine_function
));
1297 /* Change optimizations to be performed, depending on the
1300 LEVEL is the optimization level specified; 2 if `-O2' is
1301 specified, 1 if `-O' is specified, and 0 if neither is specified.
1303 SIZE is nonzero if `-Os' is specified and zero otherwise. */
1306 optimization_options (int level ATTRIBUTE_UNUSED
, int size ATTRIBUTE_UNUSED
)
1308 /* ??? There are apparently still problems with -fcaller-saves. */
1309 flag_caller_saves
= 0;
1311 /* By default, always emit DWARF-2 unwind info. This allows debugging
1312 without maintaining a stack frame back-chain. */
1313 flag_asynchronous_unwind_tables
= 1;
1315 /* Use MVCLE instructions to decrease code size if requested. */
1317 target_flags
|= MASK_MVCLE
;
1320 /* Return true if ARG is the name of a processor. Set *TYPE and *FLAGS
1321 to the associated processor_type and processor_flags if so. */
1324 s390_handle_arch_option (const char *arg
,
1325 enum processor_type
*type
,
1326 enum processor_flags
*flags
)
1330 const char *const name
; /* processor name or nickname. */
1331 const enum processor_type processor
;
1332 const enum processor_flags flags
;
1334 const processor_alias_table
[] =
1336 {"g5", PROCESSOR_9672_G5
, PF_IEEE_FLOAT
},
1337 {"g6", PROCESSOR_9672_G6
, PF_IEEE_FLOAT
},
1338 {"z900", PROCESSOR_2064_Z900
, PF_IEEE_FLOAT
| PF_ZARCH
},
1339 {"z990", PROCESSOR_2084_Z990
, PF_IEEE_FLOAT
| PF_ZARCH
1340 | PF_LONG_DISPLACEMENT
},
1341 {"z9-109", PROCESSOR_2094_Z9_109
, PF_IEEE_FLOAT
| PF_ZARCH
1342 | PF_LONG_DISPLACEMENT
| PF_EXTIMM
},
1343 {"z9-ec", PROCESSOR_2094_Z9_109
, PF_IEEE_FLOAT
| PF_ZARCH
1344 | PF_LONG_DISPLACEMENT
| PF_EXTIMM
| PF_DFP
},
1348 for (i
= 0; i
< ARRAY_SIZE (processor_alias_table
); i
++)
1349 if (strcmp (arg
, processor_alias_table
[i
].name
) == 0)
1351 *type
= processor_alias_table
[i
].processor
;
1352 *flags
= processor_alias_table
[i
].flags
;
1358 /* Implement TARGET_HANDLE_OPTION. */
1361 s390_handle_option (size_t code
, const char *arg
, int value ATTRIBUTE_UNUSED
)
1366 return s390_handle_arch_option (arg
, &s390_arch
, &s390_arch_flags
);
1368 case OPT_mstack_guard_
:
1369 if (sscanf (arg
, HOST_WIDE_INT_PRINT_DEC
, &s390_stack_guard
) != 1)
1371 if (exact_log2 (s390_stack_guard
) == -1)
1372 error ("stack guard value must be an exact power of 2");
1375 case OPT_mstack_size_
:
1376 if (sscanf (arg
, HOST_WIDE_INT_PRINT_DEC
, &s390_stack_size
) != 1)
1378 if (exact_log2 (s390_stack_size
) == -1)
1379 error ("stack size must be an exact power of 2");
1383 return s390_handle_arch_option (arg
, &s390_tune
, &s390_tune_flags
);
1385 case OPT_mwarn_framesize_
:
1386 return sscanf (arg
, HOST_WIDE_INT_PRINT_DEC
, &s390_warn_framesize
) == 1;
1394 override_options (void)
1396 /* Set up function hooks. */
1397 init_machine_status
= s390_init_machine_status
;
1399 /* Architecture mode defaults according to ABI. */
1400 if (!(target_flags_explicit
& MASK_ZARCH
))
1403 target_flags
|= MASK_ZARCH
;
1405 target_flags
&= ~MASK_ZARCH
;
1408 /* Determine processor architectural level. */
1409 if (!s390_arch_string
)
1411 s390_arch_string
= TARGET_ZARCH
? "z900" : "g5";
1412 s390_handle_arch_option (s390_arch_string
, &s390_arch
, &s390_arch_flags
);
1415 /* Determine processor to tune for. */
1416 if (s390_tune
== PROCESSOR_max
)
1418 s390_tune
= s390_arch
;
1419 s390_tune_flags
= s390_arch_flags
;
1422 /* Sanity checks. */
1423 if (TARGET_ZARCH
&& !TARGET_CPU_ZARCH
)
1424 error ("z/Architecture mode not supported on %s", s390_arch_string
);
1425 if (TARGET_64BIT
&& !TARGET_ZARCH
)
1426 error ("64-bit ABI not supported in ESA/390 mode");
1428 if (TARGET_HARD_DFP
&& (!TARGET_CPU_DFP
|| !TARGET_ZARCH
))
1430 if (target_flags_explicit
& MASK_SOFT_DFP
)
1432 if (!TARGET_CPU_DFP
)
1433 error ("Hardware decimal floating point instructions"
1434 " not available on %s", s390_arch_string
);
1436 error ("Hardware decimal floating point instructions"
1437 " not available in ESA/390 mode");
1440 target_flags
|= MASK_SOFT_DFP
;
1443 if ((target_flags_explicit
& MASK_SOFT_FLOAT
) && TARGET_SOFT_FLOAT
)
1445 if ((target_flags_explicit
& MASK_SOFT_DFP
) && TARGET_HARD_DFP
)
1446 error ("-mhard-dfp can't be used in conjunction with -msoft-float");
1448 target_flags
|= MASK_SOFT_DFP
;
1451 /* Set processor cost function. */
1452 if (s390_tune
== PROCESSOR_2094_Z9_109
)
1453 s390_cost
= &z9_109_cost
;
1454 else if (s390_tune
== PROCESSOR_2084_Z990
)
1455 s390_cost
= &z990_cost
;
1457 s390_cost
= &z900_cost
;
1459 if (TARGET_BACKCHAIN
&& TARGET_PACKED_STACK
&& TARGET_HARD_FLOAT
)
1460 error ("-mbackchain -mpacked-stack -mhard-float are not supported "
1463 if (s390_stack_size
)
1465 if (s390_stack_guard
>= s390_stack_size
)
1466 error ("stack size must be greater than the stack guard value");
1467 else if (s390_stack_size
> 1 << 16)
1468 error ("stack size must not be greater than 64k");
1470 else if (s390_stack_guard
)
1471 error ("-mstack-guard implies use of -mstack-size");
1473 #ifdef TARGET_DEFAULT_LONG_DOUBLE_128
1474 if (!(target_flags_explicit
& MASK_LONG_DOUBLE_128
))
1475 target_flags
|= MASK_LONG_DOUBLE_128
;
1479 /* Map for smallest class containing reg regno. */
1481 const enum reg_class regclass_map
[FIRST_PSEUDO_REGISTER
] =
1482 { GENERAL_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1483 ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1484 ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1485 ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1486 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1487 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1488 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1489 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1490 ADDR_REGS
, CC_REGS
, ADDR_REGS
, ADDR_REGS
,
1491 ACCESS_REGS
, ACCESS_REGS
1494 /* Return attribute type of insn. */
1496 static enum attr_type
1497 s390_safe_attr_type (rtx insn
)
1499 if (recog_memoized (insn
) >= 0)
1500 return get_attr_type (insn
);
1505 /* Return true if DISP is a valid short displacement. */
1508 s390_short_displacement (rtx disp
)
1510 /* No displacement is OK. */
1514 /* Integer displacement in range. */
1515 if (GET_CODE (disp
) == CONST_INT
)
1516 return INTVAL (disp
) >= 0 && INTVAL (disp
) < 4096;
1518 /* GOT offset is not OK, the GOT can be large. */
1519 if (GET_CODE (disp
) == CONST
1520 && GET_CODE (XEXP (disp
, 0)) == UNSPEC
1521 && (XINT (XEXP (disp
, 0), 1) == UNSPEC_GOT
1522 || XINT (XEXP (disp
, 0), 1) == UNSPEC_GOTNTPOFF
))
1525 /* All other symbolic constants are literal pool references,
1526 which are OK as the literal pool must be small. */
1527 if (GET_CODE (disp
) == CONST
)
1533 /* Decompose a RTL expression ADDR for a memory address into
1534 its components, returned in OUT.
1536 Returns false if ADDR is not a valid memory address, true
1537 otherwise. If OUT is NULL, don't return the components,
1538 but check for validity only.
1540 Note: Only addresses in canonical form are recognized.
1541 LEGITIMIZE_ADDRESS should convert non-canonical forms to the
1542 canonical form so that they will be recognized. */
1545 s390_decompose_address (rtx addr
, struct s390_address
*out
)
1547 HOST_WIDE_INT offset
= 0;
1548 rtx base
= NULL_RTX
;
1549 rtx indx
= NULL_RTX
;
1550 rtx disp
= NULL_RTX
;
1552 bool pointer
= false;
1553 bool base_ptr
= false;
1554 bool indx_ptr
= false;
1555 bool literal_pool
= false;
1557 /* We may need to substitute the literal pool base register into the address
1558 below. However, at this point we do not know which register is going to
1559 be used as base, so we substitute the arg pointer register. This is going
1560 to be treated as holding a pointer below -- it shouldn't be used for any
1562 rtx fake_pool_base
= gen_rtx_REG (Pmode
, ARG_POINTER_REGNUM
);
1564 /* Decompose address into base + index + displacement. */
1566 if (GET_CODE (addr
) == REG
|| GET_CODE (addr
) == UNSPEC
)
1569 else if (GET_CODE (addr
) == PLUS
)
1571 rtx op0
= XEXP (addr
, 0);
1572 rtx op1
= XEXP (addr
, 1);
1573 enum rtx_code code0
= GET_CODE (op0
);
1574 enum rtx_code code1
= GET_CODE (op1
);
1576 if (code0
== REG
|| code0
== UNSPEC
)
1578 if (code1
== REG
|| code1
== UNSPEC
)
1580 indx
= op0
; /* index + base */
1586 base
= op0
; /* base + displacement */
1591 else if (code0
== PLUS
)
1593 indx
= XEXP (op0
, 0); /* index + base + disp */
1594 base
= XEXP (op0
, 1);
1605 disp
= addr
; /* displacement */
1607 /* Extract integer part of displacement. */
1611 if (GET_CODE (disp
) == CONST_INT
)
1613 offset
= INTVAL (disp
);
1616 else if (GET_CODE (disp
) == CONST
1617 && GET_CODE (XEXP (disp
, 0)) == PLUS
1618 && GET_CODE (XEXP (XEXP (disp
, 0), 1)) == CONST_INT
)
1620 offset
= INTVAL (XEXP (XEXP (disp
, 0), 1));
1621 disp
= XEXP (XEXP (disp
, 0), 0);
1625 /* Strip off CONST here to avoid special case tests later. */
1626 if (disp
&& GET_CODE (disp
) == CONST
)
1627 disp
= XEXP (disp
, 0);
1629 /* We can convert literal pool addresses to
1630 displacements by basing them off the base register. */
1631 if (disp
&& GET_CODE (disp
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (disp
))
1633 /* Either base or index must be free to hold the base register. */
1635 base
= fake_pool_base
, literal_pool
= true;
1637 indx
= fake_pool_base
, literal_pool
= true;
1641 /* Mark up the displacement. */
1642 disp
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, disp
),
1643 UNSPEC_LTREL_OFFSET
);
1646 /* Validate base register. */
1649 if (GET_CODE (base
) == UNSPEC
)
1650 switch (XINT (base
, 1))
1654 disp
= gen_rtx_UNSPEC (Pmode
,
1655 gen_rtvec (1, XVECEXP (base
, 0, 0)),
1656 UNSPEC_LTREL_OFFSET
);
1660 base
= XVECEXP (base
, 0, 1);
1663 case UNSPEC_LTREL_BASE
:
1664 if (XVECLEN (base
, 0) == 1)
1665 base
= fake_pool_base
, literal_pool
= true;
1667 base
= XVECEXP (base
, 0, 1);
1675 || (GET_MODE (base
) != SImode
1676 && GET_MODE (base
) != Pmode
))
1679 if (REGNO (base
) == STACK_POINTER_REGNUM
1680 || REGNO (base
) == FRAME_POINTER_REGNUM
1681 || ((reload_completed
|| reload_in_progress
)
1682 && frame_pointer_needed
1683 && REGNO (base
) == HARD_FRAME_POINTER_REGNUM
)
1684 || REGNO (base
) == ARG_POINTER_REGNUM
1686 && REGNO (base
) == PIC_OFFSET_TABLE_REGNUM
))
1687 pointer
= base_ptr
= true;
1689 if ((reload_completed
|| reload_in_progress
)
1690 && base
== cfun
->machine
->base_reg
)
1691 pointer
= base_ptr
= literal_pool
= true;
1694 /* Validate index register. */
1697 if (GET_CODE (indx
) == UNSPEC
)
1698 switch (XINT (indx
, 1))
1702 disp
= gen_rtx_UNSPEC (Pmode
,
1703 gen_rtvec (1, XVECEXP (indx
, 0, 0)),
1704 UNSPEC_LTREL_OFFSET
);
1708 indx
= XVECEXP (indx
, 0, 1);
1711 case UNSPEC_LTREL_BASE
:
1712 if (XVECLEN (indx
, 0) == 1)
1713 indx
= fake_pool_base
, literal_pool
= true;
1715 indx
= XVECEXP (indx
, 0, 1);
1723 || (GET_MODE (indx
) != SImode
1724 && GET_MODE (indx
) != Pmode
))
1727 if (REGNO (indx
) == STACK_POINTER_REGNUM
1728 || REGNO (indx
) == FRAME_POINTER_REGNUM
1729 || ((reload_completed
|| reload_in_progress
)
1730 && frame_pointer_needed
1731 && REGNO (indx
) == HARD_FRAME_POINTER_REGNUM
)
1732 || REGNO (indx
) == ARG_POINTER_REGNUM
1734 && REGNO (indx
) == PIC_OFFSET_TABLE_REGNUM
))
1735 pointer
= indx_ptr
= true;
1737 if ((reload_completed
|| reload_in_progress
)
1738 && indx
== cfun
->machine
->base_reg
)
1739 pointer
= indx_ptr
= literal_pool
= true;
1742 /* Prefer to use pointer as base, not index. */
1743 if (base
&& indx
&& !base_ptr
1744 && (indx_ptr
|| (!REG_POINTER (base
) && REG_POINTER (indx
))))
1751 /* Validate displacement. */
1754 /* If virtual registers are involved, the displacement will change later
1755 anyway as the virtual registers get eliminated. This could make a
1756 valid displacement invalid, but it is more likely to make an invalid
1757 displacement valid, because we sometimes access the register save area
1758 via negative offsets to one of those registers.
1759 Thus we don't check the displacement for validity here. If after
1760 elimination the displacement turns out to be invalid after all,
1761 this is fixed up by reload in any case. */
1762 if (base
!= arg_pointer_rtx
1763 && indx
!= arg_pointer_rtx
1764 && base
!= return_address_pointer_rtx
1765 && indx
!= return_address_pointer_rtx
1766 && base
!= frame_pointer_rtx
1767 && indx
!= frame_pointer_rtx
1768 && base
!= virtual_stack_vars_rtx
1769 && indx
!= virtual_stack_vars_rtx
)
1770 if (!DISP_IN_RANGE (offset
))
1775 /* All the special cases are pointers. */
1778 /* In the small-PIC case, the linker converts @GOT
1779 and @GOTNTPOFF offsets to possible displacements. */
1780 if (GET_CODE (disp
) == UNSPEC
1781 && (XINT (disp
, 1) == UNSPEC_GOT
1782 || XINT (disp
, 1) == UNSPEC_GOTNTPOFF
)
1788 /* Accept chunkified literal pool symbol references. */
1789 else if (cfun
&& cfun
->machine
1790 && cfun
->machine
->decomposed_literal_pool_addresses_ok_p
1791 && GET_CODE (disp
) == MINUS
1792 && GET_CODE (XEXP (disp
, 0)) == LABEL_REF
1793 && GET_CODE (XEXP (disp
, 1)) == LABEL_REF
)
1798 /* Accept literal pool references. */
1799 else if (GET_CODE (disp
) == UNSPEC
1800 && XINT (disp
, 1) == UNSPEC_LTREL_OFFSET
)
1802 orig_disp
= gen_rtx_CONST (Pmode
, disp
);
1805 /* If we have an offset, make sure it does not
1806 exceed the size of the constant pool entry. */
1807 rtx sym
= XVECEXP (disp
, 0, 0);
1808 if (offset
>= GET_MODE_SIZE (get_pool_mode (sym
)))
1811 orig_disp
= plus_constant (orig_disp
, offset
);
1826 out
->disp
= orig_disp
;
1827 out
->pointer
= pointer
;
1828 out
->literal_pool
= literal_pool
;
1834 /* Decompose a RTL expression OP for a shift count into its components,
1835 and return the base register in BASE and the offset in OFFSET.
1837 Return true if OP is a valid shift count, false if not. */
1840 s390_decompose_shift_count (rtx op
, rtx
*base
, HOST_WIDE_INT
*offset
)
1842 HOST_WIDE_INT off
= 0;
1844 /* We can have an integer constant, an address register,
1845 or a sum of the two. */
1846 if (GET_CODE (op
) == CONST_INT
)
1851 if (op
&& GET_CODE (op
) == PLUS
&& GET_CODE (XEXP (op
, 1)) == CONST_INT
)
1853 off
= INTVAL (XEXP (op
, 1));
1856 while (op
&& GET_CODE (op
) == SUBREG
)
1857 op
= SUBREG_REG (op
);
1859 if (op
&& GET_CODE (op
) != REG
)
1871 /* Return true if CODE is a valid address without index. */
1874 s390_legitimate_address_without_index_p (rtx op
)
1876 struct s390_address addr
;
1878 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
1887 /* Evaluates constraint strings described by the regular expression
1888 ([A|B](Q|R|S|T))|U|W and returns 1 if OP is a valid operand for the
1889 constraint given in STR, or 0 else. */
1892 s390_mem_constraint (const char *str
, rtx op
)
1894 struct s390_address addr
;
1897 /* Check for offsettable variants of memory constraints. */
1900 /* Only accept non-volatile MEMs. */
1901 if (!MEM_P (op
) || MEM_VOLATILE_P (op
))
1904 if ((reload_completed
|| reload_in_progress
)
1905 ? !offsettable_memref_p (op
) : !offsettable_nonstrict_memref_p (op
))
1911 /* Check for non-literal-pool variants of memory constraints. */
1914 if (GET_CODE (op
) != MEM
)
1916 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
1918 if (addr
.literal_pool
)
1927 if (GET_CODE (op
) != MEM
)
1929 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
1934 if (TARGET_LONG_DISPLACEMENT
)
1936 if (!s390_short_displacement (addr
.disp
))
1942 if (GET_CODE (op
) != MEM
)
1945 if (TARGET_LONG_DISPLACEMENT
)
1947 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
1949 if (!s390_short_displacement (addr
.disp
))
1955 if (!TARGET_LONG_DISPLACEMENT
)
1957 if (GET_CODE (op
) != MEM
)
1959 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
1963 if (s390_short_displacement (addr
.disp
))
1968 if (!TARGET_LONG_DISPLACEMENT
)
1970 if (GET_CODE (op
) != MEM
)
1972 /* Any invalid address here will be fixed up by reload,
1973 so accept it for the most generic constraint. */
1974 if (s390_decompose_address (XEXP (op
, 0), &addr
)
1975 && s390_short_displacement (addr
.disp
))
1980 if (TARGET_LONG_DISPLACEMENT
)
1982 if (!s390_decompose_address (op
, &addr
))
1984 if (!s390_short_displacement (addr
.disp
))
1990 if (!TARGET_LONG_DISPLACEMENT
)
1992 /* Any invalid address here will be fixed up by reload,
1993 so accept it for the most generic constraint. */
1994 if (s390_decompose_address (op
, &addr
)
1995 && s390_short_displacement (addr
.disp
))
2000 /* Simply check for the basic form of a shift count. Reload will
2001 take care of making sure we have a proper base register. */
2002 if (!s390_decompose_shift_count (op
, NULL
, NULL
))
2015 /* Evaluates constraint strings starting with letter O. Input
2016 parameter C is the second letter following the "O" in the constraint
2017 string. Returns 1 if VALUE meets the respective constraint and 0
2021 s390_O_constraint_str (const char c
, HOST_WIDE_INT value
)
2029 return trunc_int_for_mode (value
, SImode
) == value
;
2033 || s390_single_part (GEN_INT (value
), DImode
, SImode
, 0) == 1;
2037 || s390_single_part (GEN_INT (value
), DImode
, SImode
, -1) == 1;
2045 /* Evaluates constraint strings starting with letter N. Parameter STR
2046 contains the letters following letter "N" in the constraint string.
2047 Returns true if VALUE matches the constraint. */
2050 s390_N_constraint_str (const char *str
, HOST_WIDE_INT value
)
2052 enum machine_mode mode
, part_mode
;
2054 int part
, part_goal
;
2060 part_goal
= str
[0] - '0';
2104 if (GET_MODE_SIZE (mode
) <= GET_MODE_SIZE (part_mode
))
2107 part
= s390_single_part (GEN_INT (value
), mode
, part_mode
, def
);
2110 if (part_goal
!= -1 && part_goal
!= part
)
2117 /* Returns true if the input parameter VALUE is a float zero. */
2120 s390_float_const_zero_p (rtx value
)
2122 return (GET_MODE_CLASS (GET_MODE (value
)) == MODE_FLOAT
2123 && value
== CONST0_RTX (GET_MODE (value
)));
2127 /* Compute a (partial) cost for rtx X. Return true if the complete
2128 cost has been computed, and false if subexpressions should be
2129 scanned. In either case, *TOTAL contains the cost result.
2130 CODE contains GET_CODE (x), OUTER_CODE contains the code
2131 of the superexpression of x. */
2134 s390_rtx_costs (rtx x
, int code
, int outer_code
, int *total
)
2157 *total
= COSTS_N_INSNS (1);
2162 /* Check for multiply and add. */
2163 if ((GET_MODE (x
) == DFmode
|| GET_MODE (x
) == SFmode
)
2164 && GET_CODE (XEXP (x
, 0)) == MULT
2165 && TARGET_HARD_FLOAT
&& TARGET_IEEE_FLOAT
&& TARGET_FUSED_MADD
)
2167 /* This is the multiply and add case. */
2168 if (GET_MODE (x
) == DFmode
)
2169 *total
= s390_cost
->madbr
;
2171 *total
= s390_cost
->maebr
;
2172 *total
+= rtx_cost (XEXP (XEXP (x
, 0), 0), MULT
)
2173 + rtx_cost (XEXP (XEXP (x
, 0), 1), MULT
)
2174 + rtx_cost (XEXP (x
, 1), code
);
2175 return true; /* Do not do an additional recursive descent. */
2177 *total
= COSTS_N_INSNS (1);
2181 switch (GET_MODE (x
))
2185 rtx left
= XEXP (x
, 0);
2186 rtx right
= XEXP (x
, 1);
2187 if (GET_CODE (right
) == CONST_INT
2188 && CONST_OK_FOR_K (INTVAL (right
)))
2189 *total
= s390_cost
->mhi
;
2190 else if (GET_CODE (left
) == SIGN_EXTEND
)
2191 *total
= s390_cost
->mh
;
2193 *total
= s390_cost
->ms
; /* msr, ms, msy */
2198 rtx left
= XEXP (x
, 0);
2199 rtx right
= XEXP (x
, 1);
2202 if (GET_CODE (right
) == CONST_INT
2203 && CONST_OK_FOR_K (INTVAL (right
)))
2204 *total
= s390_cost
->mghi
;
2205 else if (GET_CODE (left
) == SIGN_EXTEND
)
2206 *total
= s390_cost
->msgf
;
2208 *total
= s390_cost
->msg
; /* msgr, msg */
2210 else /* TARGET_31BIT */
2212 if (GET_CODE (left
) == SIGN_EXTEND
2213 && GET_CODE (right
) == SIGN_EXTEND
)
2214 /* mulsidi case: mr, m */
2215 *total
= s390_cost
->m
;
2216 else if (GET_CODE (left
) == ZERO_EXTEND
2217 && GET_CODE (right
) == ZERO_EXTEND
2218 && TARGET_CPU_ZARCH
)
2219 /* umulsidi case: ml, mlr */
2220 *total
= s390_cost
->ml
;
2222 /* Complex calculation is required. */
2223 *total
= COSTS_N_INSNS (40);
2229 *total
= s390_cost
->mult_df
;
2232 *total
= s390_cost
->mxbr
;
2241 if (GET_MODE (x
) == TImode
) /* 128 bit division */
2242 *total
= s390_cost
->dlgr
;
2243 else if (GET_MODE (x
) == DImode
)
2245 rtx right
= XEXP (x
, 1);
2246 if (GET_CODE (right
) == ZERO_EXTEND
) /* 64 by 32 bit division */
2247 *total
= s390_cost
->dlr
;
2248 else /* 64 by 64 bit division */
2249 *total
= s390_cost
->dlgr
;
2251 else if (GET_MODE (x
) == SImode
) /* 32 bit division */
2252 *total
= s390_cost
->dlr
;
2257 if (GET_MODE (x
) == DImode
)
2259 rtx right
= XEXP (x
, 1);
2260 if (GET_CODE (right
) == ZERO_EXTEND
) /* 64 by 32 bit division */
2262 *total
= s390_cost
->dsgfr
;
2264 *total
= s390_cost
->dr
;
2265 else /* 64 by 64 bit division */
2266 *total
= s390_cost
->dsgr
;
2268 else if (GET_MODE (x
) == SImode
) /* 32 bit division */
2269 *total
= s390_cost
->dlr
;
2270 else if (GET_MODE (x
) == SFmode
)
2272 if (TARGET_IEEE_FLOAT
)
2273 *total
= s390_cost
->debr
;
2274 else /* TARGET_IBM_FLOAT */
2275 *total
= s390_cost
->der
;
2277 else if (GET_MODE (x
) == DFmode
)
2279 if (TARGET_IEEE_FLOAT
)
2280 *total
= s390_cost
->ddbr
;
2281 else /* TARGET_IBM_FLOAT */
2282 *total
= s390_cost
->ddr
;
2284 else if (GET_MODE (x
) == TFmode
)
2286 if (TARGET_IEEE_FLOAT
)
2287 *total
= s390_cost
->dxbr
;
2288 else /* TARGET_IBM_FLOAT */
2289 *total
= s390_cost
->dxr
;
2294 if (GET_MODE (x
) == SFmode
)
2295 *total
= s390_cost
->sqebr
;
2296 else if (GET_MODE (x
) == DFmode
)
2297 *total
= s390_cost
->sqdbr
;
2299 *total
= s390_cost
->sqxbr
;
2304 if (outer_code
== MULT
|| outer_code
== DIV
|| outer_code
== MOD
2305 || outer_code
== PLUS
|| outer_code
== MINUS
2306 || outer_code
== COMPARE
)
2311 *total
= COSTS_N_INSNS (1);
2312 if (GET_CODE (XEXP (x
, 0)) == AND
2313 && GET_CODE (XEXP (x
, 1)) == CONST_INT
2314 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
)
2316 rtx op0
= XEXP (XEXP (x
, 0), 0);
2317 rtx op1
= XEXP (XEXP (x
, 0), 1);
2318 rtx op2
= XEXP (x
, 1);
2320 if (memory_operand (op0
, GET_MODE (op0
))
2321 && s390_tm_ccmode (op1
, op2
, 0) != VOIDmode
)
2323 if (register_operand (op0
, GET_MODE (op0
))
2324 && s390_tm_ccmode (op1
, op2
, 1) != VOIDmode
)
2334 /* Return the cost of an address rtx ADDR. */
2337 s390_address_cost (rtx addr
)
2339 struct s390_address ad
;
2340 if (!s390_decompose_address (addr
, &ad
))
2343 return ad
.indx
? COSTS_N_INSNS (1) + 1 : COSTS_N_INSNS (1);
2346 /* If OP is a SYMBOL_REF of a thread-local symbol, return its TLS mode,
2347 otherwise return 0. */
2350 tls_symbolic_operand (rtx op
)
2352 if (GET_CODE (op
) != SYMBOL_REF
)
2354 return SYMBOL_REF_TLS_MODEL (op
);
2357 /* Split DImode access register reference REG (on 64-bit) into its constituent
2358 low and high parts, and store them into LO and HI. Note that gen_lowpart/
2359 gen_highpart cannot be used as they assume all registers are word-sized,
2360 while our access registers have only half that size. */
2363 s390_split_access_reg (rtx reg
, rtx
*lo
, rtx
*hi
)
2365 gcc_assert (TARGET_64BIT
);
2366 gcc_assert (ACCESS_REG_P (reg
));
2367 gcc_assert (GET_MODE (reg
) == DImode
);
2368 gcc_assert (!(REGNO (reg
) & 1));
2370 *lo
= gen_rtx_REG (SImode
, REGNO (reg
) + 1);
2371 *hi
= gen_rtx_REG (SImode
, REGNO (reg
));
2374 /* Return true if OP contains a symbol reference */
2377 symbolic_reference_mentioned_p (rtx op
)
2382 if (GET_CODE (op
) == SYMBOL_REF
|| GET_CODE (op
) == LABEL_REF
)
2385 fmt
= GET_RTX_FORMAT (GET_CODE (op
));
2386 for (i
= GET_RTX_LENGTH (GET_CODE (op
)) - 1; i
>= 0; i
--)
2392 for (j
= XVECLEN (op
, i
) - 1; j
>= 0; j
--)
2393 if (symbolic_reference_mentioned_p (XVECEXP (op
, i
, j
)))
2397 else if (fmt
[i
] == 'e' && symbolic_reference_mentioned_p (XEXP (op
, i
)))
2404 /* Return true if OP contains a reference to a thread-local symbol. */
2407 tls_symbolic_reference_mentioned_p (rtx op
)
2412 if (GET_CODE (op
) == SYMBOL_REF
)
2413 return tls_symbolic_operand (op
);
2415 fmt
= GET_RTX_FORMAT (GET_CODE (op
));
2416 for (i
= GET_RTX_LENGTH (GET_CODE (op
)) - 1; i
>= 0; i
--)
2422 for (j
= XVECLEN (op
, i
) - 1; j
>= 0; j
--)
2423 if (tls_symbolic_reference_mentioned_p (XVECEXP (op
, i
, j
)))
2427 else if (fmt
[i
] == 'e' && tls_symbolic_reference_mentioned_p (XEXP (op
, i
)))
2435 /* Return true if OP is a legitimate general operand when
2436 generating PIC code. It is given that flag_pic is on
2437 and that OP satisfies CONSTANT_P or is a CONST_DOUBLE. */
2440 legitimate_pic_operand_p (rtx op
)
2442 /* Accept all non-symbolic constants. */
2443 if (!SYMBOLIC_CONST (op
))
2446 /* Reject everything else; must be handled
2447 via emit_symbolic_move. */
2451 /* Returns true if the constant value OP is a legitimate general operand.
2452 It is given that OP satisfies CONSTANT_P or is a CONST_DOUBLE. */
2455 legitimate_constant_p (rtx op
)
2457 /* Accept all non-symbolic constants. */
2458 if (!SYMBOLIC_CONST (op
))
2461 /* Accept immediate LARL operands. */
2462 if (TARGET_CPU_ZARCH
&& larl_operand (op
, VOIDmode
))
2465 /* Thread-local symbols are never legal constants. This is
2466 so that emit_call knows that computing such addresses
2467 might require a function call. */
2468 if (TLS_SYMBOLIC_CONST (op
))
2471 /* In the PIC case, symbolic constants must *not* be
2472 forced into the literal pool. We accept them here,
2473 so that they will be handled by emit_symbolic_move. */
2477 /* All remaining non-PIC symbolic constants are
2478 forced into the literal pool. */
2482 /* Determine if it's legal to put X into the constant pool. This
2483 is not possible if X contains the address of a symbol that is
2484 not constant (TLS) or not known at final link time (PIC). */
2487 s390_cannot_force_const_mem (rtx x
)
2489 switch (GET_CODE (x
))
2493 /* Accept all non-symbolic constants. */
2497 /* Labels are OK iff we are non-PIC. */
2498 return flag_pic
!= 0;
2501 /* 'Naked' TLS symbol references are never OK,
2502 non-TLS symbols are OK iff we are non-PIC. */
2503 if (tls_symbolic_operand (x
))
2506 return flag_pic
!= 0;
2509 return s390_cannot_force_const_mem (XEXP (x
, 0));
2512 return s390_cannot_force_const_mem (XEXP (x
, 0))
2513 || s390_cannot_force_const_mem (XEXP (x
, 1));
2516 switch (XINT (x
, 1))
2518 /* Only lt-relative or GOT-relative UNSPECs are OK. */
2519 case UNSPEC_LTREL_OFFSET
:
2527 case UNSPEC_GOTNTPOFF
:
2528 case UNSPEC_INDNTPOFF
:
2531 /* If the literal pool shares the code section, be put
2532 execute template placeholders into the pool as well. */
2534 return TARGET_CPU_ZARCH
;
2546 /* Returns true if the constant value OP is a legitimate general
2547 operand during and after reload. The difference to
2548 legitimate_constant_p is that this function will not accept
2549 a constant that would need to be forced to the literal pool
2550 before it can be used as operand. */
2553 legitimate_reload_constant_p (rtx op
)
2555 /* Accept la(y) operands. */
2556 if (GET_CODE (op
) == CONST_INT
2557 && DISP_IN_RANGE (INTVAL (op
)))
2560 /* Accept l(g)hi/l(g)fi operands. */
2561 if (GET_CODE (op
) == CONST_INT
2562 && (CONST_OK_FOR_K (INTVAL (op
)) || CONST_OK_FOR_Os (INTVAL (op
))))
2565 /* Accept lliXX operands. */
2567 && GET_CODE (op
) == CONST_INT
2568 && trunc_int_for_mode (INTVAL (op
), word_mode
) == INTVAL (op
)
2569 && s390_single_part (op
, word_mode
, HImode
, 0) >= 0)
2573 && GET_CODE (op
) == CONST_INT
2574 && trunc_int_for_mode (INTVAL (op
), word_mode
) == INTVAL (op
)
2575 && s390_single_part (op
, word_mode
, SImode
, 0) >= 0)
2578 /* Accept larl operands. */
2579 if (TARGET_CPU_ZARCH
2580 && larl_operand (op
, VOIDmode
))
2583 /* Accept lzXX operands. */
2584 if (GET_CODE (op
) == CONST_DOUBLE
2585 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op
, 'G', "G"))
2588 /* Accept double-word operands that can be split. */
2589 if (GET_CODE (op
) == CONST_INT
2590 && trunc_int_for_mode (INTVAL (op
), word_mode
) != INTVAL (op
))
2592 enum machine_mode dword_mode
= word_mode
== SImode
? DImode
: TImode
;
2593 rtx hi
= operand_subword (op
, 0, 0, dword_mode
);
2594 rtx lo
= operand_subword (op
, 1, 0, dword_mode
);
2595 return legitimate_reload_constant_p (hi
)
2596 && legitimate_reload_constant_p (lo
);
2599 /* Everything else cannot be handled without reload. */
2603 /* Given an rtx OP being reloaded into a reg required to be in class CLASS,
2604 return the class of reg to actually use. */
2607 s390_preferred_reload_class (rtx op
, enum reg_class
class)
2609 switch (GET_CODE (op
))
2611 /* Constants we cannot reload must be forced into the
2616 if (legitimate_reload_constant_p (op
))
2621 /* If a symbolic constant or a PLUS is reloaded,
2622 it is most likely being used as an address, so
2623 prefer ADDR_REGS. If 'class' is not a superset
2624 of ADDR_REGS, e.g. FP_REGS, reject this reload. */
2629 if (reg_class_subset_p (ADDR_REGS
, class))
2641 /* Return the register class of a scratch register needed to
2642 load IN into a register of class CLASS in MODE.
2644 We need a temporary when loading a PLUS expression which
2645 is not a legitimate operand of the LOAD ADDRESS instruction. */
2648 s390_secondary_input_reload_class (enum reg_class
class,
2649 enum machine_mode mode
, rtx in
)
2651 if (s390_plus_operand (in
, mode
))
2654 if (reg_classes_intersect_p (FP_REGS
, class)
2656 && GET_CODE (in
) == MEM
2657 && GET_CODE (XEXP (in
, 0)) == PLUS
2658 && GET_CODE (XEXP (XEXP (in
, 0), 1)) == CONST_INT
2659 && !DISP_IN_RANGE (INTVAL (XEXP (XEXP (in
, 0), 1))
2660 + GET_MODE_SIZE (mode
) - 1))
2663 if (reg_classes_intersect_p (CC_REGS
, class))
2664 return GENERAL_REGS
;
2669 /* Return the register class of a scratch register needed to
2670 store a register of class CLASS in MODE into OUT:
2672 We need a temporary when storing a double-word to a
2673 non-offsettable memory address. */
2676 s390_secondary_output_reload_class (enum reg_class
class,
2677 enum machine_mode mode
, rtx out
)
2679 if ((TARGET_64BIT
? (mode
== TImode
|| mode
== TFmode
)
2680 : (mode
== DImode
|| mode
== DFmode
))
2681 && reg_classes_intersect_p (GENERAL_REGS
, class)
2682 && GET_CODE (out
) == MEM
2683 && GET_CODE (XEXP (out
, 0)) == PLUS
2684 && GET_CODE (XEXP (XEXP (out
, 0), 0)) == PLUS
2685 && GET_CODE (XEXP (XEXP (out
, 0), 1)) == CONST_INT
2686 && !DISP_IN_RANGE (INTVAL (XEXP (XEXP (out
, 0), 1))
2687 + GET_MODE_SIZE (mode
) - 1))
2690 if (reg_classes_intersect_p (FP_REGS
, class)
2692 && GET_CODE (out
) == MEM
2693 && GET_CODE (XEXP (out
, 0)) == PLUS
2694 && GET_CODE (XEXP (XEXP (out
, 0), 1)) == CONST_INT
2695 && !DISP_IN_RANGE (INTVAL (XEXP (XEXP (out
, 0), 1))
2696 + GET_MODE_SIZE (mode
) - 1))
2699 if (reg_classes_intersect_p (CC_REGS
, class))
2700 return GENERAL_REGS
;
2705 /* Generate code to load SRC, which is PLUS that is not a
2706 legitimate operand for the LA instruction, into TARGET.
2707 SCRATCH may be used as scratch register. */
2710 s390_expand_plus_operand (rtx target
, rtx src
,
2714 struct s390_address ad
;
2716 /* src must be a PLUS; get its two operands. */
2717 gcc_assert (GET_CODE (src
) == PLUS
);
2718 gcc_assert (GET_MODE (src
) == Pmode
);
2720 /* Check if any of the two operands is already scheduled
2721 for replacement by reload. This can happen e.g. when
2722 float registers occur in an address. */
2723 sum1
= find_replacement (&XEXP (src
, 0));
2724 sum2
= find_replacement (&XEXP (src
, 1));
2725 src
= gen_rtx_PLUS (Pmode
, sum1
, sum2
);
2727 /* If the address is already strictly valid, there's nothing to do. */
2728 if (!s390_decompose_address (src
, &ad
)
2729 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
2730 || (ad
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (ad
.indx
))))
2732 /* Otherwise, one of the operands cannot be an address register;
2733 we reload its value into the scratch register. */
2734 if (true_regnum (sum1
) < 1 || true_regnum (sum1
) > 15)
2736 emit_move_insn (scratch
, sum1
);
2739 if (true_regnum (sum2
) < 1 || true_regnum (sum2
) > 15)
2741 emit_move_insn (scratch
, sum2
);
2745 /* According to the way these invalid addresses are generated
2746 in reload.c, it should never happen (at least on s390) that
2747 *neither* of the PLUS components, after find_replacements
2748 was applied, is an address register. */
2749 if (sum1
== scratch
&& sum2
== scratch
)
2755 src
= gen_rtx_PLUS (Pmode
, sum1
, sum2
);
2758 /* Emit the LOAD ADDRESS pattern. Note that reload of PLUS
2759 is only ever performed on addresses, so we can mark the
2760 sum as legitimate for LA in any case. */
2761 s390_load_address (target
, src
);
2765 /* Return true if ADDR is a valid memory address.
2766 STRICT specifies whether strict register checking applies. */
2769 legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED
,
2770 rtx addr
, int strict
)
2772 struct s390_address ad
;
2773 if (!s390_decompose_address (addr
, &ad
))
2778 if (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
2781 if (ad
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (ad
.indx
)))
2787 && !(REGNO (ad
.base
) >= FIRST_PSEUDO_REGISTER
2788 || REGNO_REG_CLASS (REGNO (ad
.base
)) == ADDR_REGS
))
2792 && !(REGNO (ad
.indx
) >= FIRST_PSEUDO_REGISTER
2793 || REGNO_REG_CLASS (REGNO (ad
.indx
)) == ADDR_REGS
))
2799 /* Return true if OP is a valid operand for the LA instruction.
2800 In 31-bit, we need to prove that the result is used as an
2801 address, as LA performs only a 31-bit addition. */
2804 legitimate_la_operand_p (rtx op
)
2806 struct s390_address addr
;
2807 if (!s390_decompose_address (op
, &addr
))
2810 return (TARGET_64BIT
|| addr
.pointer
);
2813 /* Return true if it is valid *and* preferable to use LA to
2814 compute the sum of OP1 and OP2. */
2817 preferred_la_operand_p (rtx op1
, rtx op2
)
2819 struct s390_address addr
;
2821 if (op2
!= const0_rtx
)
2822 op1
= gen_rtx_PLUS (Pmode
, op1
, op2
);
2824 if (!s390_decompose_address (op1
, &addr
))
2826 if (addr
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (addr
.base
)))
2828 if (addr
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (addr
.indx
)))
2831 if (!TARGET_64BIT
&& !addr
.pointer
)
2837 if ((addr
.base
&& REG_P (addr
.base
) && REG_POINTER (addr
.base
))
2838 || (addr
.indx
&& REG_P (addr
.indx
) && REG_POINTER (addr
.indx
)))
2844 /* Emit a forced load-address operation to load SRC into DST.
2845 This will use the LOAD ADDRESS instruction even in situations
2846 where legitimate_la_operand_p (SRC) returns false. */
2849 s390_load_address (rtx dst
, rtx src
)
2852 emit_move_insn (dst
, src
);
2854 emit_insn (gen_force_la_31 (dst
, src
));
2857 /* Return a legitimate reference for ORIG (an address) using the
2858 register REG. If REG is 0, a new pseudo is generated.
2860 There are two types of references that must be handled:
2862 1. Global data references must load the address from the GOT, via
2863 the PIC reg. An insn is emitted to do this load, and the reg is
2866 2. Static data references, constant pool addresses, and code labels
2867 compute the address as an offset from the GOT, whose base is in
2868 the PIC reg. Static data objects have SYMBOL_FLAG_LOCAL set to
2869 differentiate them from global data objects. The returned
2870 address is the PIC reg + an unspec constant.
2872 GO_IF_LEGITIMATE_ADDRESS rejects symbolic references unless the PIC
2873 reg also appears in the address. */
2876 legitimize_pic_address (rtx orig
, rtx reg
)
2882 gcc_assert (!TLS_SYMBOLIC_CONST (addr
));
2884 if (GET_CODE (addr
) == LABEL_REF
2885 || (GET_CODE (addr
) == SYMBOL_REF
&& SYMBOL_REF_LOCAL_P (addr
)))
2887 /* This is a local symbol. */
2888 if (TARGET_CPU_ZARCH
&& larl_operand (addr
, VOIDmode
))
2890 /* Access local symbols PC-relative via LARL.
2891 This is the same as in the non-PIC case, so it is
2892 handled automatically ... */
2896 /* Access local symbols relative to the GOT. */
2898 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
2900 if (reload_in_progress
|| reload_completed
)
2901 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
2903 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTOFF
);
2904 addr
= gen_rtx_CONST (Pmode
, addr
);
2905 addr
= force_const_mem (Pmode
, addr
);
2906 emit_move_insn (temp
, addr
);
2908 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
2911 s390_load_address (reg
, new);
2916 else if (GET_CODE (addr
) == SYMBOL_REF
)
2919 reg
= gen_reg_rtx (Pmode
);
2923 /* Assume GOT offset < 4k. This is handled the same way
2924 in both 31- and 64-bit code (@GOT). */
2926 if (reload_in_progress
|| reload_completed
)
2927 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
2929 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOT
);
2930 new = gen_rtx_CONST (Pmode
, new);
2931 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, new);
2932 new = gen_const_mem (Pmode
, new);
2933 emit_move_insn (reg
, new);
2936 else if (TARGET_CPU_ZARCH
)
2938 /* If the GOT offset might be >= 4k, we determine the position
2939 of the GOT entry via a PC-relative LARL (@GOTENT). */
2941 rtx temp
= gen_reg_rtx (Pmode
);
2943 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTENT
);
2944 new = gen_rtx_CONST (Pmode
, new);
2945 emit_move_insn (temp
, new);
2947 new = gen_const_mem (Pmode
, temp
);
2948 emit_move_insn (reg
, new);
2953 /* If the GOT offset might be >= 4k, we have to load it
2954 from the literal pool (@GOT). */
2956 rtx temp
= gen_reg_rtx (Pmode
);
2958 if (reload_in_progress
|| reload_completed
)
2959 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
2961 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOT
);
2962 addr
= gen_rtx_CONST (Pmode
, addr
);
2963 addr
= force_const_mem (Pmode
, addr
);
2964 emit_move_insn (temp
, addr
);
2966 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
2967 new = gen_const_mem (Pmode
, new);
2968 emit_move_insn (reg
, new);
2974 if (GET_CODE (addr
) == CONST
)
2976 addr
= XEXP (addr
, 0);
2977 if (GET_CODE (addr
) == UNSPEC
)
2979 gcc_assert (XVECLEN (addr
, 0) == 1);
2980 switch (XINT (addr
, 1))
2982 /* If someone moved a GOT-relative UNSPEC
2983 out of the literal pool, force them back in. */
2986 new = force_const_mem (Pmode
, orig
);
2989 /* @GOT is OK as is if small. */
2992 new = force_const_mem (Pmode
, orig
);
2995 /* @GOTENT is OK as is. */
2999 /* @PLT is OK as is on 64-bit, must be converted to
3000 GOT-relative @PLTOFF on 31-bit. */
3002 if (!TARGET_CPU_ZARCH
)
3004 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3006 if (reload_in_progress
|| reload_completed
)
3007 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
3009 addr
= XVECEXP (addr
, 0, 0);
3010 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
),
3012 addr
= gen_rtx_CONST (Pmode
, addr
);
3013 addr
= force_const_mem (Pmode
, addr
);
3014 emit_move_insn (temp
, addr
);
3016 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3019 s390_load_address (reg
, new);
3025 /* Everything else cannot happen. */
3031 gcc_assert (GET_CODE (addr
) == PLUS
);
3033 if (GET_CODE (addr
) == PLUS
)
3035 rtx op0
= XEXP (addr
, 0), op1
= XEXP (addr
, 1);
3037 gcc_assert (!TLS_SYMBOLIC_CONST (op0
));
3038 gcc_assert (!TLS_SYMBOLIC_CONST (op1
));
3040 /* Check first to see if this is a constant offset
3041 from a local symbol reference. */
3042 if ((GET_CODE (op0
) == LABEL_REF
3043 || (GET_CODE (op0
) == SYMBOL_REF
&& SYMBOL_REF_LOCAL_P (op0
)))
3044 && GET_CODE (op1
) == CONST_INT
)
3046 if (TARGET_CPU_ZARCH
3047 && larl_operand (op0
, VOIDmode
)
3048 && INTVAL (op1
) < (HOST_WIDE_INT
)1 << 31
3049 && INTVAL (op1
) >= -((HOST_WIDE_INT
)1 << 31))
3051 if (INTVAL (op1
) & 1)
3053 /* LARL can't handle odd offsets, so emit a
3054 pair of LARL and LA. */
3055 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3057 if (!DISP_IN_RANGE (INTVAL (op1
)))
3059 HOST_WIDE_INT even
= INTVAL (op1
) - 1;
3060 op0
= gen_rtx_PLUS (Pmode
, op0
, GEN_INT (even
));
3061 op0
= gen_rtx_CONST (Pmode
, op0
);
3065 emit_move_insn (temp
, op0
);
3066 new = gen_rtx_PLUS (Pmode
, temp
, op1
);
3070 s390_load_address (reg
, new);
3076 /* If the offset is even, we can just use LARL.
3077 This will happen automatically. */
3082 /* Access local symbols relative to the GOT. */
3084 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3086 if (reload_in_progress
|| reload_completed
)
3087 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
3089 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op0
),
3091 addr
= gen_rtx_PLUS (Pmode
, addr
, op1
);
3092 addr
= gen_rtx_CONST (Pmode
, addr
);
3093 addr
= force_const_mem (Pmode
, addr
);
3094 emit_move_insn (temp
, addr
);
3096 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3099 s390_load_address (reg
, new);
3105 /* Now, check whether it is a GOT relative symbol plus offset
3106 that was pulled out of the literal pool. Force it back in. */
3108 else if (GET_CODE (op0
) == UNSPEC
3109 && GET_CODE (op1
) == CONST_INT
3110 && XINT (op0
, 1) == UNSPEC_GOTOFF
)
3112 gcc_assert (XVECLEN (op0
, 0) == 1);
3114 new = force_const_mem (Pmode
, orig
);
3117 /* Otherwise, compute the sum. */
3120 base
= legitimize_pic_address (XEXP (addr
, 0), reg
);
3121 new = legitimize_pic_address (XEXP (addr
, 1),
3122 base
== reg
? NULL_RTX
: reg
);
3123 if (GET_CODE (new) == CONST_INT
)
3124 new = plus_constant (base
, INTVAL (new));
3127 if (GET_CODE (new) == PLUS
&& CONSTANT_P (XEXP (new, 1)))
3129 base
= gen_rtx_PLUS (Pmode
, base
, XEXP (new, 0));
3130 new = XEXP (new, 1);
3132 new = gen_rtx_PLUS (Pmode
, base
, new);
3135 if (GET_CODE (new) == CONST
)
3136 new = XEXP (new, 0);
3137 new = force_operand (new, 0);
3144 /* Load the thread pointer into a register. */
3147 s390_get_thread_pointer (void)
3149 rtx tp
= gen_reg_rtx (Pmode
);
3151 emit_move_insn (tp
, gen_rtx_REG (Pmode
, TP_REGNUM
));
3152 mark_reg_pointer (tp
, BITS_PER_WORD
);
3157 /* Emit a tls call insn. The call target is the SYMBOL_REF stored
3158 in s390_tls_symbol which always refers to __tls_get_offset.
3159 The returned offset is written to RESULT_REG and an USE rtx is
3160 generated for TLS_CALL. */
3162 static GTY(()) rtx s390_tls_symbol
;
3165 s390_emit_tls_call_insn (rtx result_reg
, rtx tls_call
)
3169 gcc_assert (flag_pic
);
3171 if (!s390_tls_symbol
)
3172 s390_tls_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "__tls_get_offset");
3174 insn
= s390_emit_call (s390_tls_symbol
, tls_call
, result_reg
,
3175 gen_rtx_REG (Pmode
, RETURN_REGNUM
));
3177 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), result_reg
);
3178 CONST_OR_PURE_CALL_P (insn
) = 1;
3181 /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
3182 this (thread-local) address. REG may be used as temporary. */
3185 legitimize_tls_address (rtx addr
, rtx reg
)
3187 rtx
new, tls_call
, temp
, base
, r2
, insn
;
3189 if (GET_CODE (addr
) == SYMBOL_REF
)
3190 switch (tls_symbolic_operand (addr
))
3192 case TLS_MODEL_GLOBAL_DYNAMIC
:
3194 r2
= gen_rtx_REG (Pmode
, 2);
3195 tls_call
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_TLSGD
);
3196 new = gen_rtx_CONST (Pmode
, tls_call
);
3197 new = force_const_mem (Pmode
, new);
3198 emit_move_insn (r2
, new);
3199 s390_emit_tls_call_insn (r2
, tls_call
);
3200 insn
= get_insns ();
3203 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_NTPOFF
);
3204 temp
= gen_reg_rtx (Pmode
);
3205 emit_libcall_block (insn
, temp
, r2
, new);
3207 new = gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3210 s390_load_address (reg
, new);
3215 case TLS_MODEL_LOCAL_DYNAMIC
:
3217 r2
= gen_rtx_REG (Pmode
, 2);
3218 tls_call
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, const0_rtx
), UNSPEC_TLSLDM
);
3219 new = gen_rtx_CONST (Pmode
, tls_call
);
3220 new = force_const_mem (Pmode
, new);
3221 emit_move_insn (r2
, new);
3222 s390_emit_tls_call_insn (r2
, tls_call
);
3223 insn
= get_insns ();
3226 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, const0_rtx
), UNSPEC_TLSLDM_NTPOFF
);
3227 temp
= gen_reg_rtx (Pmode
);
3228 emit_libcall_block (insn
, temp
, r2
, new);
3230 new = gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3231 base
= gen_reg_rtx (Pmode
);
3232 s390_load_address (base
, new);
3234 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_DTPOFF
);
3235 new = gen_rtx_CONST (Pmode
, new);
3236 new = force_const_mem (Pmode
, new);
3237 temp
= gen_reg_rtx (Pmode
);
3238 emit_move_insn (temp
, new);
3240 new = gen_rtx_PLUS (Pmode
, base
, temp
);
3243 s390_load_address (reg
, new);
3248 case TLS_MODEL_INITIAL_EXEC
:
3251 /* Assume GOT offset < 4k. This is handled the same way
3252 in both 31- and 64-bit code. */
3254 if (reload_in_progress
|| reload_completed
)
3255 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
3257 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTNTPOFF
);
3258 new = gen_rtx_CONST (Pmode
, new);
3259 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, new);
3260 new = gen_const_mem (Pmode
, new);
3261 temp
= gen_reg_rtx (Pmode
);
3262 emit_move_insn (temp
, new);
3264 else if (TARGET_CPU_ZARCH
)
3266 /* If the GOT offset might be >= 4k, we determine the position
3267 of the GOT entry via a PC-relative LARL. */
3269 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_INDNTPOFF
);
3270 new = gen_rtx_CONST (Pmode
, new);
3271 temp
= gen_reg_rtx (Pmode
);
3272 emit_move_insn (temp
, new);
3274 new = gen_const_mem (Pmode
, temp
);
3275 temp
= gen_reg_rtx (Pmode
);
3276 emit_move_insn (temp
, new);
3280 /* If the GOT offset might be >= 4k, we have to load it
3281 from the literal pool. */
3283 if (reload_in_progress
|| reload_completed
)
3284 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
3286 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTNTPOFF
);
3287 new = gen_rtx_CONST (Pmode
, new);
3288 new = force_const_mem (Pmode
, new);
3289 temp
= gen_reg_rtx (Pmode
);
3290 emit_move_insn (temp
, new);
3292 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3293 new = gen_const_mem (Pmode
, new);
3295 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, new, addr
), UNSPEC_TLS_LOAD
);
3296 temp
= gen_reg_rtx (Pmode
);
3297 emit_insn (gen_rtx_SET (Pmode
, temp
, new));
3301 /* In position-dependent code, load the absolute address of
3302 the GOT entry from the literal pool. */
3304 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_INDNTPOFF
);
3305 new = gen_rtx_CONST (Pmode
, new);
3306 new = force_const_mem (Pmode
, new);
3307 temp
= gen_reg_rtx (Pmode
);
3308 emit_move_insn (temp
, new);
3311 new = gen_const_mem (Pmode
, new);
3312 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, new, addr
), UNSPEC_TLS_LOAD
);
3313 temp
= gen_reg_rtx (Pmode
);
3314 emit_insn (gen_rtx_SET (Pmode
, temp
, new));
3317 new = gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3320 s390_load_address (reg
, new);
3325 case TLS_MODEL_LOCAL_EXEC
:
3326 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_NTPOFF
);
3327 new = gen_rtx_CONST (Pmode
, new);
3328 new = force_const_mem (Pmode
, new);
3329 temp
= gen_reg_rtx (Pmode
);
3330 emit_move_insn (temp
, new);
3332 new = gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3335 s390_load_address (reg
, new);
3344 else if (GET_CODE (addr
) == CONST
&& GET_CODE (XEXP (addr
, 0)) == UNSPEC
)
3346 switch (XINT (XEXP (addr
, 0), 1))
3348 case UNSPEC_INDNTPOFF
:
3349 gcc_assert (TARGET_CPU_ZARCH
);
3358 else if (GET_CODE (addr
) == CONST
&& GET_CODE (XEXP (addr
, 0)) == PLUS
3359 && GET_CODE (XEXP (XEXP (addr
, 0), 1)) == CONST_INT
)
3361 new = XEXP (XEXP (addr
, 0), 0);
3362 if (GET_CODE (new) != SYMBOL_REF
)
3363 new = gen_rtx_CONST (Pmode
, new);
3365 new = legitimize_tls_address (new, reg
);
3366 new = plus_constant (new, INTVAL (XEXP (XEXP (addr
, 0), 1)));
3367 new = force_operand (new, 0);
3371 gcc_unreachable (); /* for now ... */
3376 /* Emit insns to move operands[1] into operands[0]. */
3379 emit_symbolic_move (rtx
*operands
)
3381 rtx temp
= no_new_pseudos
? operands
[0] : gen_reg_rtx (Pmode
);
3383 if (GET_CODE (operands
[0]) == MEM
)
3384 operands
[1] = force_reg (Pmode
, operands
[1]);
3385 else if (TLS_SYMBOLIC_CONST (operands
[1]))
3386 operands
[1] = legitimize_tls_address (operands
[1], temp
);
3388 operands
[1] = legitimize_pic_address (operands
[1], temp
);
3391 /* Try machine-dependent ways of modifying an illegitimate address X
3392 to be legitimate. If we find one, return the new, valid address.
3394 OLDX is the address as it was before break_out_memory_refs was called.
3395 In some cases it is useful to look at this to decide what needs to be done.
3397 MODE is the mode of the operand pointed to by X.
3399 When -fpic is used, special handling is needed for symbolic references.
3400 See comments by legitimize_pic_address for details. */
3403 legitimize_address (rtx x
, rtx oldx ATTRIBUTE_UNUSED
,
3404 enum machine_mode mode ATTRIBUTE_UNUSED
)
3406 rtx constant_term
= const0_rtx
;
3408 if (TLS_SYMBOLIC_CONST (x
))
3410 x
= legitimize_tls_address (x
, 0);
3412 if (legitimate_address_p (mode
, x
, FALSE
))
3415 else if (GET_CODE (x
) == PLUS
3416 && (TLS_SYMBOLIC_CONST (XEXP (x
, 0))
3417 || TLS_SYMBOLIC_CONST (XEXP (x
, 1))))
3423 if (SYMBOLIC_CONST (x
)
3424 || (GET_CODE (x
) == PLUS
3425 && (SYMBOLIC_CONST (XEXP (x
, 0))
3426 || SYMBOLIC_CONST (XEXP (x
, 1)))))
3427 x
= legitimize_pic_address (x
, 0);
3429 if (legitimate_address_p (mode
, x
, FALSE
))
3433 x
= eliminate_constant_term (x
, &constant_term
);
3435 /* Optimize loading of large displacements by splitting them
3436 into the multiple of 4K and the rest; this allows the
3437 former to be CSE'd if possible.
3439 Don't do this if the displacement is added to a register
3440 pointing into the stack frame, as the offsets will
3441 change later anyway. */
3443 if (GET_CODE (constant_term
) == CONST_INT
3444 && !TARGET_LONG_DISPLACEMENT
3445 && !DISP_IN_RANGE (INTVAL (constant_term
))
3446 && !(REG_P (x
) && REGNO_PTR_FRAME_P (REGNO (x
))))
3448 HOST_WIDE_INT lower
= INTVAL (constant_term
) & 0xfff;
3449 HOST_WIDE_INT upper
= INTVAL (constant_term
) ^ lower
;
3451 rtx temp
= gen_reg_rtx (Pmode
);
3452 rtx val
= force_operand (GEN_INT (upper
), temp
);
3454 emit_move_insn (temp
, val
);
3456 x
= gen_rtx_PLUS (Pmode
, x
, temp
);
3457 constant_term
= GEN_INT (lower
);
3460 if (GET_CODE (x
) == PLUS
)
3462 if (GET_CODE (XEXP (x
, 0)) == REG
)
3464 rtx temp
= gen_reg_rtx (Pmode
);
3465 rtx val
= force_operand (XEXP (x
, 1), temp
);
3467 emit_move_insn (temp
, val
);
3469 x
= gen_rtx_PLUS (Pmode
, XEXP (x
, 0), temp
);
3472 else if (GET_CODE (XEXP (x
, 1)) == REG
)
3474 rtx temp
= gen_reg_rtx (Pmode
);
3475 rtx val
= force_operand (XEXP (x
, 0), temp
);
3477 emit_move_insn (temp
, val
);
3479 x
= gen_rtx_PLUS (Pmode
, temp
, XEXP (x
, 1));
3483 if (constant_term
!= const0_rtx
)
3484 x
= gen_rtx_PLUS (Pmode
, x
, constant_term
);
3489 /* Try a machine-dependent way of reloading an illegitimate address AD
3490 operand. If we find one, push the reload and and return the new address.
3492 MODE is the mode of the enclosing MEM. OPNUM is the operand number
3493 and TYPE is the reload type of the current reload. */
3496 legitimize_reload_address (rtx ad
, enum machine_mode mode ATTRIBUTE_UNUSED
,
3497 int opnum
, int type
)
3499 if (!optimize
|| TARGET_LONG_DISPLACEMENT
)
3502 if (GET_CODE (ad
) == PLUS
)
3504 rtx tem
= simplify_binary_operation (PLUS
, Pmode
,
3505 XEXP (ad
, 0), XEXP (ad
, 1));
3510 if (GET_CODE (ad
) == PLUS
3511 && GET_CODE (XEXP (ad
, 0)) == REG
3512 && GET_CODE (XEXP (ad
, 1)) == CONST_INT
3513 && !DISP_IN_RANGE (INTVAL (XEXP (ad
, 1))))
3515 HOST_WIDE_INT lower
= INTVAL (XEXP (ad
, 1)) & 0xfff;
3516 HOST_WIDE_INT upper
= INTVAL (XEXP (ad
, 1)) ^ lower
;
3519 cst
= GEN_INT (upper
);
3520 if (!legitimate_reload_constant_p (cst
))
3521 cst
= force_const_mem (Pmode
, cst
);
3523 tem
= gen_rtx_PLUS (Pmode
, XEXP (ad
, 0), cst
);
3524 new = gen_rtx_PLUS (Pmode
, tem
, GEN_INT (lower
));
3526 push_reload (XEXP (tem
, 1), 0, &XEXP (tem
, 1), 0,
3527 BASE_REG_CLASS
, Pmode
, VOIDmode
, 0, 0,
3528 opnum
, (enum reload_type
) type
);
3535 /* Emit code to move LEN bytes from DST to SRC. */
3538 s390_expand_movmem (rtx dst
, rtx src
, rtx len
)
3540 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) >= 0 && INTVAL (len
) <= 256)
3542 if (INTVAL (len
) > 0)
3543 emit_insn (gen_movmem_short (dst
, src
, GEN_INT (INTVAL (len
) - 1)));
3546 else if (TARGET_MVCLE
)
3548 emit_insn (gen_movmem_long (dst
, src
, convert_to_mode (Pmode
, len
, 1)));
3553 rtx dst_addr
, src_addr
, count
, blocks
, temp
;
3554 rtx loop_start_label
= gen_label_rtx ();
3555 rtx loop_end_label
= gen_label_rtx ();
3556 rtx end_label
= gen_label_rtx ();
3557 enum machine_mode mode
;
3559 mode
= GET_MODE (len
);
3560 if (mode
== VOIDmode
)
3563 dst_addr
= gen_reg_rtx (Pmode
);
3564 src_addr
= gen_reg_rtx (Pmode
);
3565 count
= gen_reg_rtx (mode
);
3566 blocks
= gen_reg_rtx (mode
);
3568 convert_move (count
, len
, 1);
3569 emit_cmp_and_jump_insns (count
, const0_rtx
,
3570 EQ
, NULL_RTX
, mode
, 1, end_label
);
3572 emit_move_insn (dst_addr
, force_operand (XEXP (dst
, 0), NULL_RTX
));
3573 emit_move_insn (src_addr
, force_operand (XEXP (src
, 0), NULL_RTX
));
3574 dst
= change_address (dst
, VOIDmode
, dst_addr
);
3575 src
= change_address (src
, VOIDmode
, src_addr
);
3577 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1, 0);
3579 emit_move_insn (count
, temp
);
3581 temp
= expand_binop (mode
, ashr_optab
, count
, GEN_INT (8), blocks
, 1, 0);
3583 emit_move_insn (blocks
, temp
);
3585 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3586 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3588 emit_label (loop_start_label
);
3590 emit_insn (gen_movmem_short (dst
, src
, GEN_INT (255)));
3591 s390_load_address (dst_addr
,
3592 gen_rtx_PLUS (Pmode
, dst_addr
, GEN_INT (256)));
3593 s390_load_address (src_addr
,
3594 gen_rtx_PLUS (Pmode
, src_addr
, GEN_INT (256)));
3596 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1, 0);
3598 emit_move_insn (blocks
, temp
);
3600 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3601 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3603 emit_jump (loop_start_label
);
3604 emit_label (loop_end_label
);
3606 emit_insn (gen_movmem_short (dst
, src
,
3607 convert_to_mode (Pmode
, count
, 1)));
3608 emit_label (end_label
);
3612 /* Emit code to set LEN bytes at DST to VAL.
3613 Make use of clrmem if VAL is zero. */
3616 s390_expand_setmem (rtx dst
, rtx len
, rtx val
)
3618 gcc_assert (GET_CODE (len
) != CONST_INT
|| INTVAL (len
) > 0);
3619 gcc_assert (GET_CODE (val
) == CONST_INT
|| GET_MODE (val
) == QImode
);
3621 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) <= 257)
3623 if (val
== const0_rtx
&& INTVAL (len
) <= 256)
3624 emit_insn (gen_clrmem_short (dst
, GEN_INT (INTVAL (len
) - 1)));
3627 /* Initialize memory by storing the first byte. */
3628 emit_move_insn (adjust_address (dst
, QImode
, 0), val
);
3630 if (INTVAL (len
) > 1)
3632 /* Initiate 1 byte overlap move.
3633 The first byte of DST is propagated through DSTP1.
3634 Prepare a movmem for: DST+1 = DST (length = LEN - 1).
3635 DST is set to size 1 so the rest of the memory location
3636 does not count as source operand. */
3637 rtx dstp1
= adjust_address (dst
, VOIDmode
, 1);
3638 set_mem_size (dst
, const1_rtx
);
3640 emit_insn (gen_movmem_short (dstp1
, dst
,
3641 GEN_INT (INTVAL (len
) - 2)));
3646 else if (TARGET_MVCLE
)
3648 val
= force_not_mem (convert_modes (Pmode
, QImode
, val
, 1));
3649 emit_insn (gen_setmem_long (dst
, convert_to_mode (Pmode
, len
, 1), val
));
3654 rtx dst_addr
, src_addr
, count
, blocks
, temp
, dstp1
= NULL_RTX
;
3655 rtx loop_start_label
= gen_label_rtx ();
3656 rtx loop_end_label
= gen_label_rtx ();
3657 rtx end_label
= gen_label_rtx ();
3658 enum machine_mode mode
;
3660 mode
= GET_MODE (len
);
3661 if (mode
== VOIDmode
)
3664 dst_addr
= gen_reg_rtx (Pmode
);
3665 src_addr
= gen_reg_rtx (Pmode
);
3666 count
= gen_reg_rtx (mode
);
3667 blocks
= gen_reg_rtx (mode
);
3669 convert_move (count
, len
, 1);
3670 emit_cmp_and_jump_insns (count
, const0_rtx
,
3671 EQ
, NULL_RTX
, mode
, 1, end_label
);
3673 emit_move_insn (dst_addr
, force_operand (XEXP (dst
, 0), NULL_RTX
));
3674 dst
= change_address (dst
, VOIDmode
, dst_addr
);
3676 if (val
== const0_rtx
)
3677 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1, 0);
3680 dstp1
= adjust_address (dst
, VOIDmode
, 1);
3681 set_mem_size (dst
, const1_rtx
);
3683 /* Initialize memory by storing the first byte. */
3684 emit_move_insn (adjust_address (dst
, QImode
, 0), val
);
3686 /* If count is 1 we are done. */
3687 emit_cmp_and_jump_insns (count
, const1_rtx
,
3688 EQ
, NULL_RTX
, mode
, 1, end_label
);
3690 temp
= expand_binop (mode
, add_optab
, count
, GEN_INT (-2), count
, 1, 0);
3693 emit_move_insn (count
, temp
);
3695 temp
= expand_binop (mode
, ashr_optab
, count
, GEN_INT (8), blocks
, 1, 0);
3697 emit_move_insn (blocks
, temp
);
3699 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3700 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3702 emit_label (loop_start_label
);
3704 if (val
== const0_rtx
)
3705 emit_insn (gen_clrmem_short (dst
, GEN_INT (255)));
3707 emit_insn (gen_movmem_short (dstp1
, dst
, GEN_INT (255)));
3708 s390_load_address (dst_addr
,
3709 gen_rtx_PLUS (Pmode
, dst_addr
, GEN_INT (256)));
3711 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1, 0);
3713 emit_move_insn (blocks
, temp
);
3715 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3716 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3718 emit_jump (loop_start_label
);
3719 emit_label (loop_end_label
);
3721 if (val
== const0_rtx
)
3722 emit_insn (gen_clrmem_short (dst
, convert_to_mode (Pmode
, count
, 1)));
3724 emit_insn (gen_movmem_short (dstp1
, dst
, convert_to_mode (Pmode
, count
, 1)));
3725 emit_label (end_label
);
3729 /* Emit code to compare LEN bytes at OP0 with those at OP1,
3730 and return the result in TARGET. */
3733 s390_expand_cmpmem (rtx target
, rtx op0
, rtx op1
, rtx len
)
3735 rtx ccreg
= gen_rtx_REG (CCUmode
, CC_REGNUM
);
3738 /* As the result of CMPINT is inverted compared to what we need,
3739 we have to swap the operands. */
3740 tmp
= op0
; op0
= op1
; op1
= tmp
;
3742 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) >= 0 && INTVAL (len
) <= 256)
3744 if (INTVAL (len
) > 0)
3746 emit_insn (gen_cmpmem_short (op0
, op1
, GEN_INT (INTVAL (len
) - 1)));
3747 emit_insn (gen_cmpint (target
, ccreg
));
3750 emit_move_insn (target
, const0_rtx
);
3752 else if (TARGET_MVCLE
)
3754 emit_insn (gen_cmpmem_long (op0
, op1
, convert_to_mode (Pmode
, len
, 1)));
3755 emit_insn (gen_cmpint (target
, ccreg
));
3759 rtx addr0
, addr1
, count
, blocks
, temp
;
3760 rtx loop_start_label
= gen_label_rtx ();
3761 rtx loop_end_label
= gen_label_rtx ();
3762 rtx end_label
= gen_label_rtx ();
3763 enum machine_mode mode
;
3765 mode
= GET_MODE (len
);
3766 if (mode
== VOIDmode
)
3769 addr0
= gen_reg_rtx (Pmode
);
3770 addr1
= gen_reg_rtx (Pmode
);
3771 count
= gen_reg_rtx (mode
);
3772 blocks
= gen_reg_rtx (mode
);
3774 convert_move (count
, len
, 1);
3775 emit_cmp_and_jump_insns (count
, const0_rtx
,
3776 EQ
, NULL_RTX
, mode
, 1, end_label
);
3778 emit_move_insn (addr0
, force_operand (XEXP (op0
, 0), NULL_RTX
));
3779 emit_move_insn (addr1
, force_operand (XEXP (op1
, 0), NULL_RTX
));
3780 op0
= change_address (op0
, VOIDmode
, addr0
);
3781 op1
= change_address (op1
, VOIDmode
, addr1
);
3783 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1, 0);
3785 emit_move_insn (count
, temp
);
3787 temp
= expand_binop (mode
, ashr_optab
, count
, GEN_INT (8), blocks
, 1, 0);
3789 emit_move_insn (blocks
, temp
);
3791 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3792 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3794 emit_label (loop_start_label
);
3796 emit_insn (gen_cmpmem_short (op0
, op1
, GEN_INT (255)));
3797 temp
= gen_rtx_NE (VOIDmode
, ccreg
, const0_rtx
);
3798 temp
= gen_rtx_IF_THEN_ELSE (VOIDmode
, temp
,
3799 gen_rtx_LABEL_REF (VOIDmode
, end_label
), pc_rtx
);
3800 temp
= gen_rtx_SET (VOIDmode
, pc_rtx
, temp
);
3801 emit_jump_insn (temp
);
3803 s390_load_address (addr0
,
3804 gen_rtx_PLUS (Pmode
, addr0
, GEN_INT (256)));
3805 s390_load_address (addr1
,
3806 gen_rtx_PLUS (Pmode
, addr1
, GEN_INT (256)));
3808 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1, 0);
3810 emit_move_insn (blocks
, temp
);
3812 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3813 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3815 emit_jump (loop_start_label
);
3816 emit_label (loop_end_label
);
3818 emit_insn (gen_cmpmem_short (op0
, op1
,
3819 convert_to_mode (Pmode
, count
, 1)));
3820 emit_label (end_label
);
3822 emit_insn (gen_cmpint (target
, ccreg
));
3827 /* Expand conditional increment or decrement using alc/slb instructions.
3828 Should generate code setting DST to either SRC or SRC + INCREMENT,
3829 depending on the result of the comparison CMP_OP0 CMP_CODE CMP_OP1.
3830 Returns true if successful, false otherwise.
3832 That makes it possible to implement some if-constructs without jumps e.g.:
3833 (borrow = CC0 | CC1 and carry = CC2 | CC3)
3834 unsigned int a, b, c;
3835 if (a < b) c++; -> CCU b > a -> CC2; c += carry;
3836 if (a < b) c--; -> CCL3 a - b -> borrow; c -= borrow;
3837 if (a <= b) c++; -> CCL3 b - a -> borrow; c += carry;
3838 if (a <= b) c--; -> CCU a <= b -> borrow; c -= borrow;
3840 Checks for EQ and NE with a nonzero value need an additional xor e.g.:
3841 if (a == b) c++; -> CCL3 a ^= b; 0 - a -> borrow; c += carry;
3842 if (a == b) c--; -> CCU a ^= b; a <= 0 -> CC0 | CC1; c -= borrow;
3843 if (a != b) c++; -> CCU a ^= b; a > 0 -> CC2; c += carry;
3844 if (a != b) c--; -> CCL3 a ^= b; 0 - a -> borrow; c -= borrow; */
3847 s390_expand_addcc (enum rtx_code cmp_code
, rtx cmp_op0
, rtx cmp_op1
,
3848 rtx dst
, rtx src
, rtx increment
)
3850 enum machine_mode cmp_mode
;
3851 enum machine_mode cc_mode
;
3857 if ((GET_MODE (cmp_op0
) == SImode
|| GET_MODE (cmp_op0
) == VOIDmode
)
3858 && (GET_MODE (cmp_op1
) == SImode
|| GET_MODE (cmp_op1
) == VOIDmode
))
3860 else if ((GET_MODE (cmp_op0
) == DImode
|| GET_MODE (cmp_op0
) == VOIDmode
)
3861 && (GET_MODE (cmp_op1
) == DImode
|| GET_MODE (cmp_op1
) == VOIDmode
))
3866 /* Try ADD LOGICAL WITH CARRY. */
3867 if (increment
== const1_rtx
)
3869 /* Determine CC mode to use. */
3870 if (cmp_code
== EQ
|| cmp_code
== NE
)
3872 if (cmp_op1
!= const0_rtx
)
3874 cmp_op0
= expand_simple_binop (cmp_mode
, XOR
, cmp_op0
, cmp_op1
,
3875 NULL_RTX
, 0, OPTAB_WIDEN
);
3876 cmp_op1
= const0_rtx
;
3879 cmp_code
= cmp_code
== EQ
? LEU
: GTU
;
3882 if (cmp_code
== LTU
|| cmp_code
== LEU
)
3887 cmp_code
= swap_condition (cmp_code
);
3904 /* Emit comparison instruction pattern. */
3905 if (!register_operand (cmp_op0
, cmp_mode
))
3906 cmp_op0
= force_reg (cmp_mode
, cmp_op0
);
3908 insn
= gen_rtx_SET (VOIDmode
, gen_rtx_REG (cc_mode
, CC_REGNUM
),
3909 gen_rtx_COMPARE (cc_mode
, cmp_op0
, cmp_op1
));
3910 /* We use insn_invalid_p here to add clobbers if required. */
3911 ret
= insn_invalid_p (emit_insn (insn
));
3914 /* Emit ALC instruction pattern. */
3915 op_res
= gen_rtx_fmt_ee (cmp_code
, GET_MODE (dst
),
3916 gen_rtx_REG (cc_mode
, CC_REGNUM
),
3919 if (src
!= const0_rtx
)
3921 if (!register_operand (src
, GET_MODE (dst
)))
3922 src
= force_reg (GET_MODE (dst
), src
);
3924 src
= gen_rtx_PLUS (GET_MODE (dst
), src
, const0_rtx
);
3925 op_res
= gen_rtx_PLUS (GET_MODE (dst
), src
, op_res
);
3928 p
= rtvec_alloc (2);
3930 gen_rtx_SET (VOIDmode
, dst
, op_res
);
3932 gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
3933 emit_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
3938 /* Try SUBTRACT LOGICAL WITH BORROW. */
3939 if (increment
== constm1_rtx
)
3941 /* Determine CC mode to use. */
3942 if (cmp_code
== EQ
|| cmp_code
== NE
)
3944 if (cmp_op1
!= const0_rtx
)
3946 cmp_op0
= expand_simple_binop (cmp_mode
, XOR
, cmp_op0
, cmp_op1
,
3947 NULL_RTX
, 0, OPTAB_WIDEN
);
3948 cmp_op1
= const0_rtx
;
3951 cmp_code
= cmp_code
== EQ
? LEU
: GTU
;
3954 if (cmp_code
== GTU
|| cmp_code
== GEU
)
3959 cmp_code
= swap_condition (cmp_code
);
3976 /* Emit comparison instruction pattern. */
3977 if (!register_operand (cmp_op0
, cmp_mode
))
3978 cmp_op0
= force_reg (cmp_mode
, cmp_op0
);
3980 insn
= gen_rtx_SET (VOIDmode
, gen_rtx_REG (cc_mode
, CC_REGNUM
),
3981 gen_rtx_COMPARE (cc_mode
, cmp_op0
, cmp_op1
));
3982 /* We use insn_invalid_p here to add clobbers if required. */
3983 ret
= insn_invalid_p (emit_insn (insn
));
3986 /* Emit SLB instruction pattern. */
3987 if (!register_operand (src
, GET_MODE (dst
)))
3988 src
= force_reg (GET_MODE (dst
), src
);
3990 op_res
= gen_rtx_MINUS (GET_MODE (dst
),
3991 gen_rtx_MINUS (GET_MODE (dst
), src
, const0_rtx
),
3992 gen_rtx_fmt_ee (cmp_code
, GET_MODE (dst
),
3993 gen_rtx_REG (cc_mode
, CC_REGNUM
),
3995 p
= rtvec_alloc (2);
3997 gen_rtx_SET (VOIDmode
, dst
, op_res
);
3999 gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
4000 emit_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
4008 /* Expand code for the insv template. Return true if successful, false else. */
4011 s390_expand_insv (rtx dest
, rtx op1
, rtx op2
, rtx src
)
4013 int bitsize
= INTVAL (op1
);
4014 int bitpos
= INTVAL (op2
);
4016 /* We need byte alignment. */
4017 if (bitsize
% BITS_PER_UNIT
)
4021 && memory_operand (dest
, VOIDmode
)
4022 && (register_operand (src
, word_mode
)
4023 || const_int_operand (src
, VOIDmode
)))
4025 /* Emit standard pattern if possible. */
4026 enum machine_mode mode
= smallest_mode_for_size (bitsize
, MODE_INT
);
4027 if (GET_MODE_BITSIZE (mode
) == bitsize
)
4028 emit_move_insn (adjust_address (dest
, mode
, 0), gen_lowpart (mode
, src
));
4030 /* (set (ze (mem)) (const_int)). */
4031 else if (const_int_operand (src
, VOIDmode
))
4033 int size
= bitsize
/ BITS_PER_UNIT
;
4034 rtx src_mem
= adjust_address (force_const_mem (word_mode
, src
), BLKmode
,
4035 GET_MODE_SIZE (word_mode
) - size
);
4037 dest
= adjust_address (dest
, BLKmode
, 0);
4038 set_mem_size (dest
, GEN_INT (size
));
4039 s390_expand_movmem (dest
, src_mem
, GEN_INT (size
));
4042 /* (set (ze (mem)) (reg)). */
4043 else if (register_operand (src
, word_mode
))
4045 if (bitsize
<= GET_MODE_BITSIZE (SImode
))
4046 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
, op1
,
4050 /* Emit st,stcmh sequence. */
4051 int stcmh_width
= bitsize
- GET_MODE_BITSIZE (SImode
);
4052 int size
= stcmh_width
/ BITS_PER_UNIT
;
4054 emit_move_insn (adjust_address (dest
, SImode
, size
),
4055 gen_lowpart (SImode
, src
));
4056 set_mem_size (dest
, GEN_INT (size
));
4057 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
, GEN_INT
4058 (stcmh_width
), const0_rtx
),
4059 gen_rtx_LSHIFTRT (word_mode
, src
, GEN_INT
4060 (GET_MODE_BITSIZE (SImode
))));
4069 /* (set (ze (reg)) (const_int)). */
4071 && register_operand (dest
, word_mode
)
4072 && (bitpos
% 16) == 0
4073 && (bitsize
% 16) == 0
4074 && const_int_operand (src
, VOIDmode
))
4076 HOST_WIDE_INT val
= INTVAL (src
);
4077 int regpos
= bitpos
+ bitsize
;
4079 while (regpos
> bitpos
)
4081 enum machine_mode putmode
;
4084 if (TARGET_EXTIMM
&& (regpos
% 32 == 0) && (regpos
>= bitpos
+ 32))
4089 putsize
= GET_MODE_BITSIZE (putmode
);
4091 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
,
4094 gen_int_mode (val
, putmode
));
4097 gcc_assert (regpos
== bitpos
);
4104 /* A subroutine of s390_expand_cs_hqi and s390_expand_atomic which returns a
4105 register that holds VAL of mode MODE shifted by COUNT bits. */
4108 s390_expand_mask_and_shift (rtx val
, enum machine_mode mode
, rtx count
)
4110 val
= expand_simple_binop (SImode
, AND
, val
, GEN_INT (GET_MODE_MASK (mode
)),
4111 NULL_RTX
, 1, OPTAB_DIRECT
);
4112 return expand_simple_binop (SImode
, ASHIFT
, val
, count
,
4113 NULL_RTX
, 1, OPTAB_DIRECT
);
4116 /* Structure to hold the initial parameters for a compare_and_swap operation
4117 in HImode and QImode. */
4119 struct alignment_context
4121 rtx memsi
; /* SI aligned memory location. */
4122 rtx shift
; /* Bit offset with regard to lsb. */
4123 rtx modemask
; /* Mask of the HQImode shifted by SHIFT bits. */
4124 rtx modemaski
; /* ~modemask */
4125 bool aligned
; /* True if memory is aligned, false else. */
4128 /* A subroutine of s390_expand_cs_hqi and s390_expand_atomic to initialize
4129 structure AC for transparent simplifying, if the memory alignment is known
4130 to be at least 32bit. MEM is the memory location for the actual operation
4131 and MODE its mode. */
4134 init_alignment_context (struct alignment_context
*ac
, rtx mem
,
4135 enum machine_mode mode
)
4137 ac
->shift
= GEN_INT (GET_MODE_SIZE (SImode
) - GET_MODE_SIZE (mode
));
4138 ac
->aligned
= (MEM_ALIGN (mem
) >= GET_MODE_BITSIZE (SImode
));
4141 ac
->memsi
= adjust_address (mem
, SImode
, 0); /* Memory is aligned. */
4144 /* Alignment is unknown. */
4145 rtx byteoffset
, addr
, align
;
4147 /* Force the address into a register. */
4148 addr
= force_reg (Pmode
, XEXP (mem
, 0));
4150 /* Align it to SImode. */
4151 align
= expand_simple_binop (Pmode
, AND
, addr
,
4152 GEN_INT (-GET_MODE_SIZE (SImode
)),
4153 NULL_RTX
, 1, OPTAB_DIRECT
);
4155 ac
->memsi
= gen_rtx_MEM (SImode
, align
);
4156 MEM_VOLATILE_P (ac
->memsi
) = MEM_VOLATILE_P (mem
);
4157 set_mem_alias_set (ac
->memsi
, ALIAS_SET_MEMORY_BARRIER
);
4158 set_mem_align (ac
->memsi
, GET_MODE_BITSIZE (SImode
));
4160 /* Calculate shiftcount. */
4161 byteoffset
= expand_simple_binop (Pmode
, AND
, addr
,
4162 GEN_INT (GET_MODE_SIZE (SImode
) - 1),
4163 NULL_RTX
, 1, OPTAB_DIRECT
);
4164 /* As we already have some offset, evaluate the remaining distance. */
4165 ac
->shift
= expand_simple_binop (SImode
, MINUS
, ac
->shift
, byteoffset
,
4166 NULL_RTX
, 1, OPTAB_DIRECT
);
4169 /* Shift is the byte count, but we need the bitcount. */
4170 ac
->shift
= expand_simple_binop (SImode
, MULT
, ac
->shift
, GEN_INT (BITS_PER_UNIT
),
4171 NULL_RTX
, 1, OPTAB_DIRECT
);
4172 /* Calculate masks. */
4173 ac
->modemask
= expand_simple_binop (SImode
, ASHIFT
,
4174 GEN_INT (GET_MODE_MASK (mode
)), ac
->shift
,
4175 NULL_RTX
, 1, OPTAB_DIRECT
);
4176 ac
->modemaski
= expand_simple_unop (SImode
, NOT
, ac
->modemask
, NULL_RTX
, 1);
4179 /* Expand an atomic compare and swap operation for HImode and QImode. MEM is
4180 the memory location, CMP the old value to compare MEM with and NEW the value
4181 to set if CMP == MEM.
4182 CMP is never in memory for compare_and_swap_cc because
4183 expand_bool_compare_and_swap puts it into a register for later compare. */
4186 s390_expand_cs_hqi (enum machine_mode mode
, rtx target
, rtx mem
, rtx cmp
, rtx
new)
4188 struct alignment_context ac
;
4189 rtx cmpv
, newv
, val
, resv
, cc
;
4190 rtx res
= gen_reg_rtx (SImode
);
4191 rtx csloop
= gen_label_rtx ();
4192 rtx csend
= gen_label_rtx ();
4194 gcc_assert (register_operand (target
, VOIDmode
));
4195 gcc_assert (MEM_P (mem
));
4197 init_alignment_context (&ac
, mem
, mode
);
4199 /* Shift the values to the correct bit positions. */
4200 if (!(ac
.aligned
&& MEM_P (cmp
)))
4201 cmp
= s390_expand_mask_and_shift (cmp
, mode
, ac
.shift
);
4202 if (!(ac
.aligned
&& MEM_P (new)))
4203 new = s390_expand_mask_and_shift (new, mode
, ac
.shift
);
4205 /* Load full word. Subsequent loads are performed by CS. */
4206 val
= expand_simple_binop (SImode
, AND
, ac
.memsi
, ac
.modemaski
,
4207 NULL_RTX
, 1, OPTAB_DIRECT
);
4209 /* Start CS loop. */
4210 emit_label (csloop
);
4211 /* val = "<mem>00..0<mem>"
4212 * cmp = "00..0<cmp>00..0"
4213 * new = "00..0<new>00..0"
4216 /* Patch cmp and new with val at correct position. */
4217 if (ac
.aligned
&& MEM_P (cmp
))
4219 cmpv
= force_reg (SImode
, val
);
4220 store_bit_field (cmpv
, GET_MODE_BITSIZE (mode
), 0, SImode
, cmp
);
4223 cmpv
= force_reg (SImode
, expand_simple_binop (SImode
, IOR
, cmp
, val
,
4224 NULL_RTX
, 1, OPTAB_DIRECT
));
4225 if (ac
.aligned
&& MEM_P (new))
4227 newv
= force_reg (SImode
, val
);
4228 store_bit_field (newv
, GET_MODE_BITSIZE (mode
), 0, SImode
, new);
4231 newv
= force_reg (SImode
, expand_simple_binop (SImode
, IOR
, new, val
,
4232 NULL_RTX
, 1, OPTAB_DIRECT
));
4234 /* Jump to end if we're done (likely?). */
4235 s390_emit_jump (csend
, s390_emit_compare_and_swap (EQ
, res
, ac
.memsi
,
4238 /* Check for changes outside mode. */
4239 resv
= expand_simple_binop (SImode
, AND
, res
, ac
.modemaski
,
4240 NULL_RTX
, 1, OPTAB_DIRECT
);
4241 cc
= s390_emit_compare (NE
, resv
, val
);
4242 emit_move_insn (val
, resv
);
4243 /* Loop internal if so. */
4244 s390_emit_jump (csloop
, cc
);
4248 /* Return the correct part of the bitfield. */
4249 convert_move (target
, expand_simple_binop (SImode
, LSHIFTRT
, res
, ac
.shift
,
4250 NULL_RTX
, 1, OPTAB_DIRECT
), 1);
4253 /* Expand an atomic operation CODE of mode MODE. MEM is the memory location
4254 and VAL the value to play with. If AFTER is true then store the value
4255 MEM holds after the operation, if AFTER is false then store the value MEM
4256 holds before the operation. If TARGET is zero then discard that value, else
4257 store it to TARGET. */
4260 s390_expand_atomic (enum machine_mode mode
, enum rtx_code code
,
4261 rtx target
, rtx mem
, rtx val
, bool after
)
4263 struct alignment_context ac
;
4265 rtx
new = gen_reg_rtx (SImode
);
4266 rtx orig
= gen_reg_rtx (SImode
);
4267 rtx csloop
= gen_label_rtx ();
4269 gcc_assert (!target
|| register_operand (target
, VOIDmode
));
4270 gcc_assert (MEM_P (mem
));
4272 init_alignment_context (&ac
, mem
, mode
);
4274 /* Shift val to the correct bit positions.
4275 Preserve "icm", but prevent "ex icm". */
4276 if (!(ac
.aligned
&& code
== SET
&& MEM_P (val
)))
4277 val
= s390_expand_mask_and_shift (val
, mode
, ac
.shift
);
4279 /* Further preparation insns. */
4280 if (code
== PLUS
|| code
== MINUS
)
4281 emit_move_insn (orig
, val
);
4282 else if (code
== MULT
|| code
== AND
) /* val = "11..1<val>11..1" */
4283 val
= expand_simple_binop (SImode
, XOR
, val
, ac
.modemaski
,
4284 NULL_RTX
, 1, OPTAB_DIRECT
);
4286 /* Load full word. Subsequent loads are performed by CS. */
4287 cmp
= force_reg (SImode
, ac
.memsi
);
4289 /* Start CS loop. */
4290 emit_label (csloop
);
4291 emit_move_insn (new, cmp
);
4293 /* Patch new with val at correct position. */
4298 val
= expand_simple_binop (SImode
, code
, new, orig
,
4299 NULL_RTX
, 1, OPTAB_DIRECT
);
4300 val
= expand_simple_binop (SImode
, AND
, val
, ac
.modemask
,
4301 NULL_RTX
, 1, OPTAB_DIRECT
);
4304 if (ac
.aligned
&& MEM_P (val
))
4305 store_bit_field (new, GET_MODE_BITSIZE (mode
), 0, SImode
, val
);
4308 new = expand_simple_binop (SImode
, AND
, new, ac
.modemaski
,
4309 NULL_RTX
, 1, OPTAB_DIRECT
);
4310 new = expand_simple_binop (SImode
, IOR
, new, val
,
4311 NULL_RTX
, 1, OPTAB_DIRECT
);
4317 new = expand_simple_binop (SImode
, code
, new, val
,
4318 NULL_RTX
, 1, OPTAB_DIRECT
);
4320 case MULT
: /* NAND */
4321 new = expand_simple_binop (SImode
, XOR
, new, ac
.modemask
,
4322 NULL_RTX
, 1, OPTAB_DIRECT
);
4323 new = expand_simple_binop (SImode
, AND
, new, val
,
4324 NULL_RTX
, 1, OPTAB_DIRECT
);
4330 s390_emit_jump (csloop
, s390_emit_compare_and_swap (NE
, cmp
,
4331 ac
.memsi
, cmp
, new));
4333 /* Return the correct part of the bitfield. */
4335 convert_move (target
, expand_simple_binop (SImode
, LSHIFTRT
,
4336 after
? new : cmp
, ac
.shift
,
4337 NULL_RTX
, 1, OPTAB_DIRECT
), 1);
4340 /* This is called from dwarf2out.c via TARGET_ASM_OUTPUT_DWARF_DTPREL.
4341 We need to emit DTP-relative relocations. */
4343 static void s390_output_dwarf_dtprel (FILE *, int, rtx
) ATTRIBUTE_UNUSED
;
4346 s390_output_dwarf_dtprel (FILE *file
, int size
, rtx x
)
4351 fputs ("\t.long\t", file
);
4354 fputs ("\t.quad\t", file
);
4359 output_addr_const (file
, x
);
4360 fputs ("@DTPOFF", file
);
4363 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
4364 /* Implement TARGET_MANGLE_FUNDAMENTAL_TYPE. */
4367 s390_mangle_fundamental_type (tree type
)
4369 if (TYPE_MAIN_VARIANT (type
) == long_double_type_node
4370 && TARGET_LONG_DOUBLE_128
)
4373 /* For all other types, use normal C++ mangling. */
4378 /* In the name of slightly smaller debug output, and to cater to
4379 general assembler lossage, recognize various UNSPEC sequences
4380 and turn them back into a direct symbol reference. */
4383 s390_delegitimize_address (rtx orig_x
)
4387 if (GET_CODE (x
) != MEM
)
4391 if (GET_CODE (x
) == PLUS
4392 && GET_CODE (XEXP (x
, 1)) == CONST
4393 && GET_CODE (XEXP (x
, 0)) == REG
4394 && REGNO (XEXP (x
, 0)) == PIC_OFFSET_TABLE_REGNUM
)
4396 y
= XEXP (XEXP (x
, 1), 0);
4397 if (GET_CODE (y
) == UNSPEC
4398 && XINT (y
, 1) == UNSPEC_GOT
)
4399 return XVECEXP (y
, 0, 0);
4403 if (GET_CODE (x
) == CONST
)
4406 if (GET_CODE (y
) == UNSPEC
4407 && XINT (y
, 1) == UNSPEC_GOTENT
)
4408 return XVECEXP (y
, 0, 0);
4415 /* Output operand OP to stdio stream FILE.
4416 OP is an address (register + offset) which is not used to address data;
4417 instead the rightmost bits are interpreted as the value. */
4420 print_shift_count_operand (FILE *file
, rtx op
)
4422 HOST_WIDE_INT offset
;
4425 /* Extract base register and offset. */
4426 if (!s390_decompose_shift_count (op
, &base
, &offset
))
4432 gcc_assert (GET_CODE (base
) == REG
);
4433 gcc_assert (REGNO (base
) < FIRST_PSEUDO_REGISTER
);
4434 gcc_assert (REGNO_REG_CLASS (REGNO (base
)) == ADDR_REGS
);
4437 /* Offsets are constricted to twelve bits. */
4438 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, offset
& ((1 << 12) - 1));
4440 fprintf (file
, "(%s)", reg_names
[REGNO (base
)]);
4443 /* See 'get_some_local_dynamic_name'. */
4446 get_some_local_dynamic_name_1 (rtx
*px
, void *data ATTRIBUTE_UNUSED
)
4450 if (GET_CODE (x
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (x
))
4452 x
= get_pool_constant (x
);
4453 return for_each_rtx (&x
, get_some_local_dynamic_name_1
, 0);
4456 if (GET_CODE (x
) == SYMBOL_REF
4457 && tls_symbolic_operand (x
) == TLS_MODEL_LOCAL_DYNAMIC
)
4459 cfun
->machine
->some_ld_name
= XSTR (x
, 0);
4466 /* Locate some local-dynamic symbol still in use by this function
4467 so that we can print its name in local-dynamic base patterns. */
4470 get_some_local_dynamic_name (void)
4474 if (cfun
->machine
->some_ld_name
)
4475 return cfun
->machine
->some_ld_name
;
4477 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
4479 && for_each_rtx (&PATTERN (insn
), get_some_local_dynamic_name_1
, 0))
4480 return cfun
->machine
->some_ld_name
;
4485 /* Output machine-dependent UNSPECs occurring in address constant X
4486 in assembler syntax to stdio stream FILE. Returns true if the
4487 constant X could be recognized, false otherwise. */
4490 s390_output_addr_const_extra (FILE *file
, rtx x
)
4492 if (GET_CODE (x
) == UNSPEC
&& XVECLEN (x
, 0) == 1)
4493 switch (XINT (x
, 1))
4496 output_addr_const (file
, XVECEXP (x
, 0, 0));
4497 fprintf (file
, "@GOTENT");
4500 output_addr_const (file
, XVECEXP (x
, 0, 0));
4501 fprintf (file
, "@GOT");
4504 output_addr_const (file
, XVECEXP (x
, 0, 0));
4505 fprintf (file
, "@GOTOFF");
4508 output_addr_const (file
, XVECEXP (x
, 0, 0));
4509 fprintf (file
, "@PLT");
4512 output_addr_const (file
, XVECEXP (x
, 0, 0));
4513 fprintf (file
, "@PLTOFF");
4516 output_addr_const (file
, XVECEXP (x
, 0, 0));
4517 fprintf (file
, "@TLSGD");
4520 assemble_name (file
, get_some_local_dynamic_name ());
4521 fprintf (file
, "@TLSLDM");
4524 output_addr_const (file
, XVECEXP (x
, 0, 0));
4525 fprintf (file
, "@DTPOFF");
4528 output_addr_const (file
, XVECEXP (x
, 0, 0));
4529 fprintf (file
, "@NTPOFF");
4531 case UNSPEC_GOTNTPOFF
:
4532 output_addr_const (file
, XVECEXP (x
, 0, 0));
4533 fprintf (file
, "@GOTNTPOFF");
4535 case UNSPEC_INDNTPOFF
:
4536 output_addr_const (file
, XVECEXP (x
, 0, 0));
4537 fprintf (file
, "@INDNTPOFF");
4544 /* Output address operand ADDR in assembler syntax to
4545 stdio stream FILE. */
4548 print_operand_address (FILE *file
, rtx addr
)
4550 struct s390_address ad
;
4552 if (!s390_decompose_address (addr
, &ad
)
4553 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
4554 || (ad
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (ad
.indx
))))
4555 output_operand_lossage ("cannot decompose address");
4558 output_addr_const (file
, ad
.disp
);
4560 fprintf (file
, "0");
4562 if (ad
.base
&& ad
.indx
)
4563 fprintf (file
, "(%s,%s)", reg_names
[REGNO (ad
.indx
)],
4564 reg_names
[REGNO (ad
.base
)]);
4566 fprintf (file
, "(%s)", reg_names
[REGNO (ad
.base
)]);
4569 /* Output operand X in assembler syntax to stdio stream FILE.
4570 CODE specified the format flag. The following format flags
4573 'C': print opcode suffix for branch condition.
4574 'D': print opcode suffix for inverse branch condition.
4575 'J': print tls_load/tls_gdcall/tls_ldcall suffix
4576 'G': print the size of the operand in bytes.
4577 'O': print only the displacement of a memory reference.
4578 'R': print only the base register of a memory reference.
4579 'S': print S-type memory reference (base+displacement).
4580 'N': print the second word of a DImode operand.
4581 'M': print the second word of a TImode operand.
4582 'Y': print shift count operand.
4584 'b': print integer X as if it's an unsigned byte.
4585 'x': print integer X as if it's an unsigned halfword.
4586 'h': print integer X as if it's a signed halfword.
4587 'i': print the first nonzero HImode part of X.
4588 'j': print the first HImode part unequal to -1 of X.
4589 'k': print the first nonzero SImode part of X.
4590 'm': print the first SImode part unequal to -1 of X.
4591 'o': print integer X as if it's an unsigned 32bit word. */
4594 print_operand (FILE *file
, rtx x
, int code
)
4599 fprintf (file
, s390_branch_condition_mnemonic (x
, FALSE
));
4603 fprintf (file
, s390_branch_condition_mnemonic (x
, TRUE
));
4607 if (GET_CODE (x
) == SYMBOL_REF
)
4609 fprintf (file
, "%s", ":tls_load:");
4610 output_addr_const (file
, x
);
4612 else if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_TLSGD
)
4614 fprintf (file
, "%s", ":tls_gdcall:");
4615 output_addr_const (file
, XVECEXP (x
, 0, 0));
4617 else if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_TLSLDM
)
4619 fprintf (file
, "%s", ":tls_ldcall:");
4620 assemble_name (file
, get_some_local_dynamic_name ());
4627 fprintf (file
, "%u", GET_MODE_SIZE (GET_MODE (x
)));
4632 struct s390_address ad
;
4635 gcc_assert (GET_CODE (x
) == MEM
);
4636 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
4638 gcc_assert (!ad
.base
|| REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)));
4639 gcc_assert (!ad
.indx
);
4642 output_addr_const (file
, ad
.disp
);
4644 fprintf (file
, "0");
4650 struct s390_address ad
;
4653 gcc_assert (GET_CODE (x
) == MEM
);
4654 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
4656 gcc_assert (!ad
.base
|| REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)));
4657 gcc_assert (!ad
.indx
);
4660 fprintf (file
, "%s", reg_names
[REGNO (ad
.base
)]);
4662 fprintf (file
, "0");
4668 struct s390_address ad
;
4671 gcc_assert (GET_CODE (x
) == MEM
);
4672 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
4674 gcc_assert (!ad
.base
|| REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)));
4675 gcc_assert (!ad
.indx
);
4678 output_addr_const (file
, ad
.disp
);
4680 fprintf (file
, "0");
4683 fprintf (file
, "(%s)", reg_names
[REGNO (ad
.base
)]);
4688 if (GET_CODE (x
) == REG
)
4689 x
= gen_rtx_REG (GET_MODE (x
), REGNO (x
) + 1);
4690 else if (GET_CODE (x
) == MEM
)
4691 x
= change_address (x
, VOIDmode
, plus_constant (XEXP (x
, 0), 4));
4697 if (GET_CODE (x
) == REG
)
4698 x
= gen_rtx_REG (GET_MODE (x
), REGNO (x
) + 1);
4699 else if (GET_CODE (x
) == MEM
)
4700 x
= change_address (x
, VOIDmode
, plus_constant (XEXP (x
, 0), 8));
4706 print_shift_count_operand (file
, x
);
4710 switch (GET_CODE (x
))
4713 fprintf (file
, "%s", reg_names
[REGNO (x
)]);
4717 output_address (XEXP (x
, 0));
4724 output_addr_const (file
, x
);
4729 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
) & 0xff);
4730 else if (code
== 'x')
4731 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
) & 0xffff);
4732 else if (code
== 'h')
4733 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, ((INTVAL (x
) & 0xffff) ^ 0x8000) - 0x8000);
4734 else if (code
== 'i')
4735 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
4736 s390_extract_part (x
, HImode
, 0));
4737 else if (code
== 'j')
4738 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
4739 s390_extract_part (x
, HImode
, -1));
4740 else if (code
== 'k')
4741 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
4742 s390_extract_part (x
, SImode
, 0));
4743 else if (code
== 'm')
4744 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
4745 s390_extract_part (x
, SImode
, -1));
4746 else if (code
== 'o')
4747 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
) & 0xffffffff);
4749 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
));
4753 gcc_assert (GET_MODE (x
) == VOIDmode
);
4755 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, CONST_DOUBLE_LOW (x
) & 0xff);
4756 else if (code
== 'x')
4757 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, CONST_DOUBLE_LOW (x
) & 0xffff);
4758 else if (code
== 'h')
4759 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, ((CONST_DOUBLE_LOW (x
) & 0xffff) ^ 0x8000) - 0x8000);
4765 fatal_insn ("UNKNOWN in print_operand !?", x
);
4770 /* Target hook for assembling integer objects. We need to define it
4771 here to work a round a bug in some versions of GAS, which couldn't
4772 handle values smaller than INT_MIN when printed in decimal. */
4775 s390_assemble_integer (rtx x
, unsigned int size
, int aligned_p
)
4777 if (size
== 8 && aligned_p
4778 && GET_CODE (x
) == CONST_INT
&& INTVAL (x
) < INT_MIN
)
4780 fprintf (asm_out_file
, "\t.quad\t" HOST_WIDE_INT_PRINT_HEX
"\n",
4784 return default_assemble_integer (x
, size
, aligned_p
);
4787 /* Returns true if register REGNO is used for forming
4788 a memory address in expression X. */
4791 reg_used_in_mem_p (int regno
, rtx x
)
4793 enum rtx_code code
= GET_CODE (x
);
4799 if (refers_to_regno_p (regno
, regno
+1,
4803 else if (code
== SET
4804 && GET_CODE (SET_DEST (x
)) == PC
)
4806 if (refers_to_regno_p (regno
, regno
+1,
4811 fmt
= GET_RTX_FORMAT (code
);
4812 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4815 && reg_used_in_mem_p (regno
, XEXP (x
, i
)))
4818 else if (fmt
[i
] == 'E')
4819 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
4820 if (reg_used_in_mem_p (regno
, XVECEXP (x
, i
, j
)))
4826 /* Returns true if expression DEP_RTX sets an address register
4827 used by instruction INSN to address memory. */
4830 addr_generation_dependency_p (rtx dep_rtx
, rtx insn
)
4834 if (GET_CODE (dep_rtx
) == INSN
)
4835 dep_rtx
= PATTERN (dep_rtx
);
4837 if (GET_CODE (dep_rtx
) == SET
)
4839 target
= SET_DEST (dep_rtx
);
4840 if (GET_CODE (target
) == STRICT_LOW_PART
)
4841 target
= XEXP (target
, 0);
4842 while (GET_CODE (target
) == SUBREG
)
4843 target
= SUBREG_REG (target
);
4845 if (GET_CODE (target
) == REG
)
4847 int regno
= REGNO (target
);
4849 if (s390_safe_attr_type (insn
) == TYPE_LA
)
4851 pat
= PATTERN (insn
);
4852 if (GET_CODE (pat
) == PARALLEL
)
4854 gcc_assert (XVECLEN (pat
, 0) == 2);
4855 pat
= XVECEXP (pat
, 0, 0);
4857 gcc_assert (GET_CODE (pat
) == SET
);
4858 return refers_to_regno_p (regno
, regno
+1, SET_SRC (pat
), 0);
4860 else if (get_attr_atype (insn
) == ATYPE_AGEN
)
4861 return reg_used_in_mem_p (regno
, PATTERN (insn
));
4867 /* Return 1, if dep_insn sets register used in insn in the agen unit. */
4870 s390_agen_dep_p (rtx dep_insn
, rtx insn
)
4872 rtx dep_rtx
= PATTERN (dep_insn
);
4875 if (GET_CODE (dep_rtx
) == SET
4876 && addr_generation_dependency_p (dep_rtx
, insn
))
4878 else if (GET_CODE (dep_rtx
) == PARALLEL
)
4880 for (i
= 0; i
< XVECLEN (dep_rtx
, 0); i
++)
4882 if (addr_generation_dependency_p (XVECEXP (dep_rtx
, 0, i
), insn
))
4889 /* A C statement (sans semicolon) to update the integer scheduling priority
4890 INSN_PRIORITY (INSN). Increase the priority to execute the INSN earlier,
4891 reduce the priority to execute INSN later. Do not define this macro if
4892 you do not need to adjust the scheduling priorities of insns.
4894 A STD instruction should be scheduled earlier,
4895 in order to use the bypass. */
4898 s390_adjust_priority (rtx insn ATTRIBUTE_UNUSED
, int priority
)
4900 if (! INSN_P (insn
))
4903 if (s390_tune
!= PROCESSOR_2084_Z990
4904 && s390_tune
!= PROCESSOR_2094_Z9_109
)
4907 switch (s390_safe_attr_type (insn
))
4911 priority
= priority
<< 3;
4915 priority
= priority
<< 1;
4923 /* The number of instructions that can be issued per cycle. */
4926 s390_issue_rate (void)
4928 if (s390_tune
== PROCESSOR_2084_Z990
4929 || s390_tune
== PROCESSOR_2094_Z9_109
)
4935 s390_first_cycle_multipass_dfa_lookahead (void)
4941 /* Annotate every literal pool reference in X by an UNSPEC_LTREF expression.
4942 Fix up MEMs as required. */
4945 annotate_constant_pool_refs (rtx
*x
)
4950 gcc_assert (GET_CODE (*x
) != SYMBOL_REF
4951 || !CONSTANT_POOL_ADDRESS_P (*x
));
4953 /* Literal pool references can only occur inside a MEM ... */
4954 if (GET_CODE (*x
) == MEM
)
4956 rtx memref
= XEXP (*x
, 0);
4958 if (GET_CODE (memref
) == SYMBOL_REF
4959 && CONSTANT_POOL_ADDRESS_P (memref
))
4961 rtx base
= cfun
->machine
->base_reg
;
4962 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, memref
, base
),
4965 *x
= replace_equiv_address (*x
, addr
);
4969 if (GET_CODE (memref
) == CONST
4970 && GET_CODE (XEXP (memref
, 0)) == PLUS
4971 && GET_CODE (XEXP (XEXP (memref
, 0), 1)) == CONST_INT
4972 && GET_CODE (XEXP (XEXP (memref
, 0), 0)) == SYMBOL_REF
4973 && CONSTANT_POOL_ADDRESS_P (XEXP (XEXP (memref
, 0), 0)))
4975 HOST_WIDE_INT off
= INTVAL (XEXP (XEXP (memref
, 0), 1));
4976 rtx sym
= XEXP (XEXP (memref
, 0), 0);
4977 rtx base
= cfun
->machine
->base_reg
;
4978 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, sym
, base
),
4981 *x
= replace_equiv_address (*x
, plus_constant (addr
, off
));
4986 /* ... or a load-address type pattern. */
4987 if (GET_CODE (*x
) == SET
)
4989 rtx addrref
= SET_SRC (*x
);
4991 if (GET_CODE (addrref
) == SYMBOL_REF
4992 && CONSTANT_POOL_ADDRESS_P (addrref
))
4994 rtx base
= cfun
->machine
->base_reg
;
4995 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, addrref
, base
),
4998 SET_SRC (*x
) = addr
;
5002 if (GET_CODE (addrref
) == CONST
5003 && GET_CODE (XEXP (addrref
, 0)) == PLUS
5004 && GET_CODE (XEXP (XEXP (addrref
, 0), 1)) == CONST_INT
5005 && GET_CODE (XEXP (XEXP (addrref
, 0), 0)) == SYMBOL_REF
5006 && CONSTANT_POOL_ADDRESS_P (XEXP (XEXP (addrref
, 0), 0)))
5008 HOST_WIDE_INT off
= INTVAL (XEXP (XEXP (addrref
, 0), 1));
5009 rtx sym
= XEXP (XEXP (addrref
, 0), 0);
5010 rtx base
= cfun
->machine
->base_reg
;
5011 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, sym
, base
),
5014 SET_SRC (*x
) = plus_constant (addr
, off
);
5019 /* Annotate LTREL_BASE as well. */
5020 if (GET_CODE (*x
) == UNSPEC
5021 && XINT (*x
, 1) == UNSPEC_LTREL_BASE
)
5023 rtx base
= cfun
->machine
->base_reg
;
5024 *x
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, XVECEXP (*x
, 0, 0), base
),
5029 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
5030 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
5034 annotate_constant_pool_refs (&XEXP (*x
, i
));
5036 else if (fmt
[i
] == 'E')
5038 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
5039 annotate_constant_pool_refs (&XVECEXP (*x
, i
, j
));
5044 /* Split all branches that exceed the maximum distance.
5045 Returns true if this created a new literal pool entry. */
5048 s390_split_branches (void)
5050 rtx temp_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
5051 int new_literal
= 0, ret
;
5052 rtx insn
, pat
, tmp
, target
;
5055 /* We need correct insn addresses. */
5057 shorten_branches (get_insns ());
5059 /* Find all branches that exceed 64KB, and split them. */
5061 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5063 if (GET_CODE (insn
) != JUMP_INSN
)
5066 pat
= PATTERN (insn
);
5067 if (GET_CODE (pat
) == PARALLEL
&& XVECLEN (pat
, 0) > 2)
5068 pat
= XVECEXP (pat
, 0, 0);
5069 if (GET_CODE (pat
) != SET
|| SET_DEST (pat
) != pc_rtx
)
5072 if (GET_CODE (SET_SRC (pat
)) == LABEL_REF
)
5074 label
= &SET_SRC (pat
);
5076 else if (GET_CODE (SET_SRC (pat
)) == IF_THEN_ELSE
)
5078 if (GET_CODE (XEXP (SET_SRC (pat
), 1)) == LABEL_REF
)
5079 label
= &XEXP (SET_SRC (pat
), 1);
5080 else if (GET_CODE (XEXP (SET_SRC (pat
), 2)) == LABEL_REF
)
5081 label
= &XEXP (SET_SRC (pat
), 2);
5088 if (get_attr_length (insn
) <= 4)
5091 /* We are going to use the return register as scratch register,
5092 make sure it will be saved/restored by the prologue/epilogue. */
5093 cfun_frame_layout
.save_return_addr_p
= 1;
5098 tmp
= force_const_mem (Pmode
, *label
);
5099 tmp
= emit_insn_before (gen_rtx_SET (Pmode
, temp_reg
, tmp
), insn
);
5100 INSN_ADDRESSES_NEW (tmp
, -1);
5101 annotate_constant_pool_refs (&PATTERN (tmp
));
5108 target
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, *label
),
5109 UNSPEC_LTREL_OFFSET
);
5110 target
= gen_rtx_CONST (Pmode
, target
);
5111 target
= force_const_mem (Pmode
, target
);
5112 tmp
= emit_insn_before (gen_rtx_SET (Pmode
, temp_reg
, target
), insn
);
5113 INSN_ADDRESSES_NEW (tmp
, -1);
5114 annotate_constant_pool_refs (&PATTERN (tmp
));
5116 target
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, XEXP (target
, 0),
5117 cfun
->machine
->base_reg
),
5119 target
= gen_rtx_PLUS (Pmode
, temp_reg
, target
);
5122 ret
= validate_change (insn
, label
, target
, 0);
5130 /* Find an annotated literal pool symbol referenced in RTX X,
5131 and store it at REF. Will abort if X contains references to
5132 more than one such pool symbol; multiple references to the same
5133 symbol are allowed, however.
5135 The rtx pointed to by REF must be initialized to NULL_RTX
5136 by the caller before calling this routine. */
5139 find_constant_pool_ref (rtx x
, rtx
*ref
)
5144 /* Ignore LTREL_BASE references. */
5145 if (GET_CODE (x
) == UNSPEC
5146 && XINT (x
, 1) == UNSPEC_LTREL_BASE
)
5148 /* Likewise POOL_ENTRY insns. */
5149 if (GET_CODE (x
) == UNSPEC_VOLATILE
5150 && XINT (x
, 1) == UNSPECV_POOL_ENTRY
)
5153 gcc_assert (GET_CODE (x
) != SYMBOL_REF
5154 || !CONSTANT_POOL_ADDRESS_P (x
));
5156 if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_LTREF
)
5158 rtx sym
= XVECEXP (x
, 0, 0);
5159 gcc_assert (GET_CODE (sym
) == SYMBOL_REF
5160 && CONSTANT_POOL_ADDRESS_P (sym
));
5162 if (*ref
== NULL_RTX
)
5165 gcc_assert (*ref
== sym
);
5170 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
5171 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
5175 find_constant_pool_ref (XEXP (x
, i
), ref
);
5177 else if (fmt
[i
] == 'E')
5179 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
5180 find_constant_pool_ref (XVECEXP (x
, i
, j
), ref
);
5185 /* Replace every reference to the annotated literal pool
5186 symbol REF in X by its base plus OFFSET. */
5189 replace_constant_pool_ref (rtx
*x
, rtx ref
, rtx offset
)
5194 gcc_assert (*x
!= ref
);
5196 if (GET_CODE (*x
) == UNSPEC
5197 && XINT (*x
, 1) == UNSPEC_LTREF
5198 && XVECEXP (*x
, 0, 0) == ref
)
5200 *x
= gen_rtx_PLUS (Pmode
, XVECEXP (*x
, 0, 1), offset
);
5204 if (GET_CODE (*x
) == PLUS
5205 && GET_CODE (XEXP (*x
, 1)) == CONST_INT
5206 && GET_CODE (XEXP (*x
, 0)) == UNSPEC
5207 && XINT (XEXP (*x
, 0), 1) == UNSPEC_LTREF
5208 && XVECEXP (XEXP (*x
, 0), 0, 0) == ref
)
5210 rtx addr
= gen_rtx_PLUS (Pmode
, XVECEXP (XEXP (*x
, 0), 0, 1), offset
);
5211 *x
= plus_constant (addr
, INTVAL (XEXP (*x
, 1)));
5215 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
5216 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
5220 replace_constant_pool_ref (&XEXP (*x
, i
), ref
, offset
);
5222 else if (fmt
[i
] == 'E')
5224 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
5225 replace_constant_pool_ref (&XVECEXP (*x
, i
, j
), ref
, offset
);
5230 /* Check whether X contains an UNSPEC_LTREL_BASE.
5231 Return its constant pool symbol if found, NULL_RTX otherwise. */
5234 find_ltrel_base (rtx x
)
5239 if (GET_CODE (x
) == UNSPEC
5240 && XINT (x
, 1) == UNSPEC_LTREL_BASE
)
5241 return XVECEXP (x
, 0, 0);
5243 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
5244 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
5248 rtx fnd
= find_ltrel_base (XEXP (x
, i
));
5252 else if (fmt
[i
] == 'E')
5254 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
5256 rtx fnd
= find_ltrel_base (XVECEXP (x
, i
, j
));
5266 /* Replace any occurrence of UNSPEC_LTREL_BASE in X with its base. */
5269 replace_ltrel_base (rtx
*x
)
5274 if (GET_CODE (*x
) == UNSPEC
5275 && XINT (*x
, 1) == UNSPEC_LTREL_BASE
)
5277 *x
= XVECEXP (*x
, 0, 1);
5281 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
5282 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
5286 replace_ltrel_base (&XEXP (*x
, i
));
5288 else if (fmt
[i
] == 'E')
5290 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
5291 replace_ltrel_base (&XVECEXP (*x
, i
, j
));
5297 /* We keep a list of constants which we have to add to internal
5298 constant tables in the middle of large functions. */
5300 #define NR_C_MODES 11
5301 enum machine_mode constant_modes
[NR_C_MODES
] =
5303 TFmode
, TImode
, TDmode
,
5304 DFmode
, DImode
, DDmode
,
5305 SFmode
, SImode
, SDmode
,
5312 struct constant
*next
;
5317 struct constant_pool
5319 struct constant_pool
*next
;
5324 struct constant
*constants
[NR_C_MODES
];
5325 struct constant
*execute
;
5330 /* Allocate new constant_pool structure. */
5332 static struct constant_pool
*
5333 s390_alloc_pool (void)
5335 struct constant_pool
*pool
;
5338 pool
= (struct constant_pool
*) xmalloc (sizeof *pool
);
5340 for (i
= 0; i
< NR_C_MODES
; i
++)
5341 pool
->constants
[i
] = NULL
;
5343 pool
->execute
= NULL
;
5344 pool
->label
= gen_label_rtx ();
5345 pool
->first_insn
= NULL_RTX
;
5346 pool
->pool_insn
= NULL_RTX
;
5347 pool
->insns
= BITMAP_ALLOC (NULL
);
5353 /* Create new constant pool covering instructions starting at INSN
5354 and chain it to the end of POOL_LIST. */
5356 static struct constant_pool
*
5357 s390_start_pool (struct constant_pool
**pool_list
, rtx insn
)
5359 struct constant_pool
*pool
, **prev
;
5361 pool
= s390_alloc_pool ();
5362 pool
->first_insn
= insn
;
5364 for (prev
= pool_list
; *prev
; prev
= &(*prev
)->next
)
5371 /* End range of instructions covered by POOL at INSN and emit
5372 placeholder insn representing the pool. */
5375 s390_end_pool (struct constant_pool
*pool
, rtx insn
)
5377 rtx pool_size
= GEN_INT (pool
->size
+ 8 /* alignment slop */);
5380 insn
= get_last_insn ();
5382 pool
->pool_insn
= emit_insn_after (gen_pool (pool_size
), insn
);
5383 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
5386 /* Add INSN to the list of insns covered by POOL. */
5389 s390_add_pool_insn (struct constant_pool
*pool
, rtx insn
)
5391 bitmap_set_bit (pool
->insns
, INSN_UID (insn
));
5394 /* Return pool out of POOL_LIST that covers INSN. */
5396 static struct constant_pool
*
5397 s390_find_pool (struct constant_pool
*pool_list
, rtx insn
)
5399 struct constant_pool
*pool
;
5401 for (pool
= pool_list
; pool
; pool
= pool
->next
)
5402 if (bitmap_bit_p (pool
->insns
, INSN_UID (insn
)))
5408 /* Add constant VAL of mode MODE to the constant pool POOL. */
5411 s390_add_constant (struct constant_pool
*pool
, rtx val
, enum machine_mode mode
)
5416 for (i
= 0; i
< NR_C_MODES
; i
++)
5417 if (constant_modes
[i
] == mode
)
5419 gcc_assert (i
!= NR_C_MODES
);
5421 for (c
= pool
->constants
[i
]; c
!= NULL
; c
= c
->next
)
5422 if (rtx_equal_p (val
, c
->value
))
5427 c
= (struct constant
*) xmalloc (sizeof *c
);
5429 c
->label
= gen_label_rtx ();
5430 c
->next
= pool
->constants
[i
];
5431 pool
->constants
[i
] = c
;
5432 pool
->size
+= GET_MODE_SIZE (mode
);
5436 /* Find constant VAL of mode MODE in the constant pool POOL.
5437 Return an RTX describing the distance from the start of
5438 the pool to the location of the new constant. */
5441 s390_find_constant (struct constant_pool
*pool
, rtx val
,
5442 enum machine_mode mode
)
5448 for (i
= 0; i
< NR_C_MODES
; i
++)
5449 if (constant_modes
[i
] == mode
)
5451 gcc_assert (i
!= NR_C_MODES
);
5453 for (c
= pool
->constants
[i
]; c
!= NULL
; c
= c
->next
)
5454 if (rtx_equal_p (val
, c
->value
))
5459 offset
= gen_rtx_MINUS (Pmode
, gen_rtx_LABEL_REF (Pmode
, c
->label
),
5460 gen_rtx_LABEL_REF (Pmode
, pool
->label
));
5461 offset
= gen_rtx_CONST (Pmode
, offset
);
5465 /* Check whether INSN is an execute. Return the label_ref to its
5466 execute target template if so, NULL_RTX otherwise. */
5469 s390_execute_label (rtx insn
)
5471 if (GET_CODE (insn
) == INSN
5472 && GET_CODE (PATTERN (insn
)) == PARALLEL
5473 && GET_CODE (XVECEXP (PATTERN (insn
), 0, 0)) == UNSPEC
5474 && XINT (XVECEXP (PATTERN (insn
), 0, 0), 1) == UNSPEC_EXECUTE
)
5475 return XVECEXP (XVECEXP (PATTERN (insn
), 0, 0), 0, 2);
5480 /* Add execute target for INSN to the constant pool POOL. */
5483 s390_add_execute (struct constant_pool
*pool
, rtx insn
)
5487 for (c
= pool
->execute
; c
!= NULL
; c
= c
->next
)
5488 if (INSN_UID (insn
) == INSN_UID (c
->value
))
5493 c
= (struct constant
*) xmalloc (sizeof *c
);
5495 c
->label
= gen_label_rtx ();
5496 c
->next
= pool
->execute
;
5502 /* Find execute target for INSN in the constant pool POOL.
5503 Return an RTX describing the distance from the start of
5504 the pool to the location of the execute target. */
5507 s390_find_execute (struct constant_pool
*pool
, rtx insn
)
5512 for (c
= pool
->execute
; c
!= NULL
; c
= c
->next
)
5513 if (INSN_UID (insn
) == INSN_UID (c
->value
))
5518 offset
= gen_rtx_MINUS (Pmode
, gen_rtx_LABEL_REF (Pmode
, c
->label
),
5519 gen_rtx_LABEL_REF (Pmode
, pool
->label
));
5520 offset
= gen_rtx_CONST (Pmode
, offset
);
5524 /* For an execute INSN, extract the execute target template. */
5527 s390_execute_target (rtx insn
)
5529 rtx pattern
= PATTERN (insn
);
5530 gcc_assert (s390_execute_label (insn
));
5532 if (XVECLEN (pattern
, 0) == 2)
5534 pattern
= copy_rtx (XVECEXP (pattern
, 0, 1));
5538 rtvec vec
= rtvec_alloc (XVECLEN (pattern
, 0) - 1);
5541 for (i
= 0; i
< XVECLEN (pattern
, 0) - 1; i
++)
5542 RTVEC_ELT (vec
, i
) = copy_rtx (XVECEXP (pattern
, 0, i
+ 1));
5544 pattern
= gen_rtx_PARALLEL (VOIDmode
, vec
);
5550 /* Indicate that INSN cannot be duplicated. This is the case for
5551 execute insns that carry a unique label. */
5554 s390_cannot_copy_insn_p (rtx insn
)
5556 rtx label
= s390_execute_label (insn
);
5557 return label
&& label
!= const0_rtx
;
5560 /* Dump out the constants in POOL. If REMOTE_LABEL is true,
5561 do not emit the pool base label. */
5564 s390_dump_pool (struct constant_pool
*pool
, bool remote_label
)
5567 rtx insn
= pool
->pool_insn
;
5570 /* Switch to rodata section. */
5571 if (TARGET_CPU_ZARCH
)
5573 insn
= emit_insn_after (gen_pool_section_start (), insn
);
5574 INSN_ADDRESSES_NEW (insn
, -1);
5577 /* Ensure minimum pool alignment. */
5578 if (TARGET_CPU_ZARCH
)
5579 insn
= emit_insn_after (gen_pool_align (GEN_INT (8)), insn
);
5581 insn
= emit_insn_after (gen_pool_align (GEN_INT (4)), insn
);
5582 INSN_ADDRESSES_NEW (insn
, -1);
5584 /* Emit pool base label. */
5587 insn
= emit_label_after (pool
->label
, insn
);
5588 INSN_ADDRESSES_NEW (insn
, -1);
5591 /* Dump constants in descending alignment requirement order,
5592 ensuring proper alignment for every constant. */
5593 for (i
= 0; i
< NR_C_MODES
; i
++)
5594 for (c
= pool
->constants
[i
]; c
; c
= c
->next
)
5596 /* Convert UNSPEC_LTREL_OFFSET unspecs to pool-relative references. */
5597 rtx value
= c
->value
;
5598 if (GET_CODE (value
) == CONST
5599 && GET_CODE (XEXP (value
, 0)) == UNSPEC
5600 && XINT (XEXP (value
, 0), 1) == UNSPEC_LTREL_OFFSET
5601 && XVECLEN (XEXP (value
, 0), 0) == 1)
5603 value
= gen_rtx_MINUS (Pmode
, XVECEXP (XEXP (value
, 0), 0, 0),
5604 gen_rtx_LABEL_REF (VOIDmode
, pool
->label
));
5605 value
= gen_rtx_CONST (VOIDmode
, value
);
5608 insn
= emit_label_after (c
->label
, insn
);
5609 INSN_ADDRESSES_NEW (insn
, -1);
5611 value
= gen_rtx_UNSPEC_VOLATILE (constant_modes
[i
],
5612 gen_rtvec (1, value
),
5613 UNSPECV_POOL_ENTRY
);
5614 insn
= emit_insn_after (value
, insn
);
5615 INSN_ADDRESSES_NEW (insn
, -1);
5618 /* Ensure minimum alignment for instructions. */
5619 insn
= emit_insn_after (gen_pool_align (GEN_INT (2)), insn
);
5620 INSN_ADDRESSES_NEW (insn
, -1);
5622 /* Output in-pool execute template insns. */
5623 for (c
= pool
->execute
; c
; c
= c
->next
)
5625 insn
= emit_label_after (c
->label
, insn
);
5626 INSN_ADDRESSES_NEW (insn
, -1);
5628 insn
= emit_insn_after (s390_execute_target (c
->value
), insn
);
5629 INSN_ADDRESSES_NEW (insn
, -1);
5632 /* Switch back to previous section. */
5633 if (TARGET_CPU_ZARCH
)
5635 insn
= emit_insn_after (gen_pool_section_end (), insn
);
5636 INSN_ADDRESSES_NEW (insn
, -1);
5639 insn
= emit_barrier_after (insn
);
5640 INSN_ADDRESSES_NEW (insn
, -1);
5642 /* Remove placeholder insn. */
5643 remove_insn (pool
->pool_insn
);
5646 /* Free all memory used by POOL. */
5649 s390_free_pool (struct constant_pool
*pool
)
5651 struct constant
*c
, *next
;
5654 for (i
= 0; i
< NR_C_MODES
; i
++)
5655 for (c
= pool
->constants
[i
]; c
; c
= next
)
5661 for (c
= pool
->execute
; c
; c
= next
)
5667 BITMAP_FREE (pool
->insns
);
5672 /* Collect main literal pool. Return NULL on overflow. */
5674 static struct constant_pool
*
5675 s390_mainpool_start (void)
5677 struct constant_pool
*pool
;
5680 pool
= s390_alloc_pool ();
5682 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5684 if (GET_CODE (insn
) == INSN
5685 && GET_CODE (PATTERN (insn
)) == SET
5686 && GET_CODE (SET_SRC (PATTERN (insn
))) == UNSPEC_VOLATILE
5687 && XINT (SET_SRC (PATTERN (insn
)), 1) == UNSPECV_MAIN_POOL
)
5689 gcc_assert (!pool
->pool_insn
);
5690 pool
->pool_insn
= insn
;
5693 if (!TARGET_CPU_ZARCH
&& s390_execute_label (insn
))
5695 s390_add_execute (pool
, insn
);
5697 else if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
5699 rtx pool_ref
= NULL_RTX
;
5700 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
5703 rtx constant
= get_pool_constant (pool_ref
);
5704 enum machine_mode mode
= get_pool_mode (pool_ref
);
5705 s390_add_constant (pool
, constant
, mode
);
5710 gcc_assert (pool
->pool_insn
|| pool
->size
== 0);
5712 if (pool
->size
>= 4096)
5714 /* We're going to chunkify the pool, so remove the main
5715 pool placeholder insn. */
5716 remove_insn (pool
->pool_insn
);
5718 s390_free_pool (pool
);
5725 /* POOL holds the main literal pool as collected by s390_mainpool_start.
5726 Modify the current function to output the pool constants as well as
5727 the pool register setup instruction. */
5730 s390_mainpool_finish (struct constant_pool
*pool
)
5732 rtx base_reg
= cfun
->machine
->base_reg
;
5735 /* If the pool is empty, we're done. */
5736 if (pool
->size
== 0)
5738 /* We don't actually need a base register after all. */
5739 cfun
->machine
->base_reg
= NULL_RTX
;
5741 if (pool
->pool_insn
)
5742 remove_insn (pool
->pool_insn
);
5743 s390_free_pool (pool
);
5747 /* We need correct insn addresses. */
5748 shorten_branches (get_insns ());
5750 /* On zSeries, we use a LARL to load the pool register. The pool is
5751 located in the .rodata section, so we emit it after the function. */
5752 if (TARGET_CPU_ZARCH
)
5754 insn
= gen_main_base_64 (base_reg
, pool
->label
);
5755 insn
= emit_insn_after (insn
, pool
->pool_insn
);
5756 INSN_ADDRESSES_NEW (insn
, -1);
5757 remove_insn (pool
->pool_insn
);
5759 insn
= get_last_insn ();
5760 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
5761 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
5763 s390_dump_pool (pool
, 0);
5766 /* On S/390, if the total size of the function's code plus literal pool
5767 does not exceed 4096 bytes, we use BASR to set up a function base
5768 pointer, and emit the literal pool at the end of the function. */
5769 else if (INSN_ADDRESSES (INSN_UID (get_last_insn ()))
5770 + pool
->size
+ 8 /* alignment slop */ < 4096)
5772 insn
= gen_main_base_31_small (base_reg
, pool
->label
);
5773 insn
= emit_insn_after (insn
, pool
->pool_insn
);
5774 INSN_ADDRESSES_NEW (insn
, -1);
5775 remove_insn (pool
->pool_insn
);
5777 insn
= emit_label_after (pool
->label
, insn
);
5778 INSN_ADDRESSES_NEW (insn
, -1);
5780 insn
= get_last_insn ();
5781 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
5782 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
5784 s390_dump_pool (pool
, 1);
5787 /* Otherwise, we emit an inline literal pool and use BASR to branch
5788 over it, setting up the pool register at the same time. */
5791 rtx pool_end
= gen_label_rtx ();
5793 insn
= gen_main_base_31_large (base_reg
, pool
->label
, pool_end
);
5794 insn
= emit_insn_after (insn
, pool
->pool_insn
);
5795 INSN_ADDRESSES_NEW (insn
, -1);
5796 remove_insn (pool
->pool_insn
);
5798 insn
= emit_label_after (pool
->label
, insn
);
5799 INSN_ADDRESSES_NEW (insn
, -1);
5801 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
5802 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
5804 insn
= emit_label_after (pool_end
, pool
->pool_insn
);
5805 INSN_ADDRESSES_NEW (insn
, -1);
5807 s390_dump_pool (pool
, 1);
5811 /* Replace all literal pool references. */
5813 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5816 replace_ltrel_base (&PATTERN (insn
));
5818 if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
5820 rtx addr
, pool_ref
= NULL_RTX
;
5821 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
5824 if (s390_execute_label (insn
))
5825 addr
= s390_find_execute (pool
, insn
);
5827 addr
= s390_find_constant (pool
, get_pool_constant (pool_ref
),
5828 get_pool_mode (pool_ref
));
5830 replace_constant_pool_ref (&PATTERN (insn
), pool_ref
, addr
);
5831 INSN_CODE (insn
) = -1;
5837 /* Free the pool. */
5838 s390_free_pool (pool
);
5841 /* POOL holds the main literal pool as collected by s390_mainpool_start.
5842 We have decided we cannot use this pool, so revert all changes
5843 to the current function that were done by s390_mainpool_start. */
5845 s390_mainpool_cancel (struct constant_pool
*pool
)
5847 /* We didn't actually change the instruction stream, so simply
5848 free the pool memory. */
5849 s390_free_pool (pool
);
5853 /* Chunkify the literal pool. */
5855 #define S390_POOL_CHUNK_MIN 0xc00
5856 #define S390_POOL_CHUNK_MAX 0xe00
5858 static struct constant_pool
*
5859 s390_chunkify_start (void)
5861 struct constant_pool
*curr_pool
= NULL
, *pool_list
= NULL
;
5864 rtx pending_ltrel
= NULL_RTX
;
5867 rtx (*gen_reload_base
) (rtx
, rtx
) =
5868 TARGET_CPU_ZARCH
? gen_reload_base_64
: gen_reload_base_31
;
5871 /* We need correct insn addresses. */
5873 shorten_branches (get_insns ());
5875 /* Scan all insns and move literals to pool chunks. */
5877 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5879 /* Check for pending LTREL_BASE. */
5882 rtx ltrel_base
= find_ltrel_base (PATTERN (insn
));
5885 gcc_assert (ltrel_base
== pending_ltrel
);
5886 pending_ltrel
= NULL_RTX
;
5890 if (!TARGET_CPU_ZARCH
&& s390_execute_label (insn
))
5893 curr_pool
= s390_start_pool (&pool_list
, insn
);
5895 s390_add_execute (curr_pool
, insn
);
5896 s390_add_pool_insn (curr_pool
, insn
);
5898 else if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
5900 rtx pool_ref
= NULL_RTX
;
5901 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
5904 rtx constant
= get_pool_constant (pool_ref
);
5905 enum machine_mode mode
= get_pool_mode (pool_ref
);
5908 curr_pool
= s390_start_pool (&pool_list
, insn
);
5910 s390_add_constant (curr_pool
, constant
, mode
);
5911 s390_add_pool_insn (curr_pool
, insn
);
5913 /* Don't split the pool chunk between a LTREL_OFFSET load
5914 and the corresponding LTREL_BASE. */
5915 if (GET_CODE (constant
) == CONST
5916 && GET_CODE (XEXP (constant
, 0)) == UNSPEC
5917 && XINT (XEXP (constant
, 0), 1) == UNSPEC_LTREL_OFFSET
)
5919 gcc_assert (!pending_ltrel
);
5920 pending_ltrel
= pool_ref
;
5925 if (GET_CODE (insn
) == JUMP_INSN
|| GET_CODE (insn
) == CODE_LABEL
)
5928 s390_add_pool_insn (curr_pool
, insn
);
5929 /* An LTREL_BASE must follow within the same basic block. */
5930 gcc_assert (!pending_ltrel
);
5934 || INSN_ADDRESSES_SIZE () <= (size_t) INSN_UID (insn
)
5935 || INSN_ADDRESSES (INSN_UID (insn
)) == -1)
5938 if (TARGET_CPU_ZARCH
)
5940 if (curr_pool
->size
< S390_POOL_CHUNK_MAX
)
5943 s390_end_pool (curr_pool
, NULL_RTX
);
5948 int chunk_size
= INSN_ADDRESSES (INSN_UID (insn
))
5949 - INSN_ADDRESSES (INSN_UID (curr_pool
->first_insn
))
5952 /* We will later have to insert base register reload insns.
5953 Those will have an effect on code size, which we need to
5954 consider here. This calculation makes rather pessimistic
5955 worst-case assumptions. */
5956 if (GET_CODE (insn
) == CODE_LABEL
)
5959 if (chunk_size
< S390_POOL_CHUNK_MIN
5960 && curr_pool
->size
< S390_POOL_CHUNK_MIN
)
5963 /* Pool chunks can only be inserted after BARRIERs ... */
5964 if (GET_CODE (insn
) == BARRIER
)
5966 s390_end_pool (curr_pool
, insn
);
5971 /* ... so if we don't find one in time, create one. */
5972 else if ((chunk_size
> S390_POOL_CHUNK_MAX
5973 || curr_pool
->size
> S390_POOL_CHUNK_MAX
))
5975 rtx label
, jump
, barrier
;
5977 /* We can insert the barrier only after a 'real' insn. */
5978 if (GET_CODE (insn
) != INSN
&& GET_CODE (insn
) != CALL_INSN
)
5980 if (get_attr_length (insn
) == 0)
5983 /* Don't separate LTREL_BASE from the corresponding
5984 LTREL_OFFSET load. */
5988 label
= gen_label_rtx ();
5989 jump
= emit_jump_insn_after (gen_jump (label
), insn
);
5990 barrier
= emit_barrier_after (jump
);
5991 insn
= emit_label_after (label
, barrier
);
5992 JUMP_LABEL (jump
) = label
;
5993 LABEL_NUSES (label
) = 1;
5995 INSN_ADDRESSES_NEW (jump
, -1);
5996 INSN_ADDRESSES_NEW (barrier
, -1);
5997 INSN_ADDRESSES_NEW (insn
, -1);
5999 s390_end_pool (curr_pool
, barrier
);
6007 s390_end_pool (curr_pool
, NULL_RTX
);
6008 gcc_assert (!pending_ltrel
);
6010 /* Find all labels that are branched into
6011 from an insn belonging to a different chunk. */
6013 far_labels
= BITMAP_ALLOC (NULL
);
6015 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6017 /* Labels marked with LABEL_PRESERVE_P can be target
6018 of non-local jumps, so we have to mark them.
6019 The same holds for named labels.
6021 Don't do that, however, if it is the label before
6024 if (GET_CODE (insn
) == CODE_LABEL
6025 && (LABEL_PRESERVE_P (insn
) || LABEL_NAME (insn
)))
6027 rtx vec_insn
= next_real_insn (insn
);
6028 rtx vec_pat
= vec_insn
&& GET_CODE (vec_insn
) == JUMP_INSN
?
6029 PATTERN (vec_insn
) : NULL_RTX
;
6031 || !(GET_CODE (vec_pat
) == ADDR_VEC
6032 || GET_CODE (vec_pat
) == ADDR_DIFF_VEC
))
6033 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (insn
));
6036 /* If we have a direct jump (conditional or unconditional)
6037 or a casesi jump, check all potential targets. */
6038 else if (GET_CODE (insn
) == JUMP_INSN
)
6040 rtx pat
= PATTERN (insn
);
6041 if (GET_CODE (pat
) == PARALLEL
&& XVECLEN (pat
, 0) > 2)
6042 pat
= XVECEXP (pat
, 0, 0);
6044 if (GET_CODE (pat
) == SET
)
6046 rtx label
= JUMP_LABEL (insn
);
6049 if (s390_find_pool (pool_list
, label
)
6050 != s390_find_pool (pool_list
, insn
))
6051 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (label
));
6054 else if (GET_CODE (pat
) == PARALLEL
6055 && XVECLEN (pat
, 0) == 2
6056 && GET_CODE (XVECEXP (pat
, 0, 0)) == SET
6057 && GET_CODE (XVECEXP (pat
, 0, 1)) == USE
6058 && GET_CODE (XEXP (XVECEXP (pat
, 0, 1), 0)) == LABEL_REF
)
6060 /* Find the jump table used by this casesi jump. */
6061 rtx vec_label
= XEXP (XEXP (XVECEXP (pat
, 0, 1), 0), 0);
6062 rtx vec_insn
= next_real_insn (vec_label
);
6063 rtx vec_pat
= vec_insn
&& GET_CODE (vec_insn
) == JUMP_INSN
?
6064 PATTERN (vec_insn
) : NULL_RTX
;
6066 && (GET_CODE (vec_pat
) == ADDR_VEC
6067 || GET_CODE (vec_pat
) == ADDR_DIFF_VEC
))
6069 int i
, diff_p
= GET_CODE (vec_pat
) == ADDR_DIFF_VEC
;
6071 for (i
= 0; i
< XVECLEN (vec_pat
, diff_p
); i
++)
6073 rtx label
= XEXP (XVECEXP (vec_pat
, diff_p
, i
), 0);
6075 if (s390_find_pool (pool_list
, label
)
6076 != s390_find_pool (pool_list
, insn
))
6077 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (label
));
6084 /* Insert base register reload insns before every pool. */
6086 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
6088 rtx new_insn
= gen_reload_base (cfun
->machine
->base_reg
,
6090 rtx insn
= curr_pool
->first_insn
;
6091 INSN_ADDRESSES_NEW (emit_insn_before (new_insn
, insn
), -1);
6094 /* Insert base register reload insns at every far label. */
6096 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6097 if (GET_CODE (insn
) == CODE_LABEL
6098 && bitmap_bit_p (far_labels
, CODE_LABEL_NUMBER (insn
)))
6100 struct constant_pool
*pool
= s390_find_pool (pool_list
, insn
);
6103 rtx new_insn
= gen_reload_base (cfun
->machine
->base_reg
,
6105 INSN_ADDRESSES_NEW (emit_insn_after (new_insn
, insn
), -1);
6110 BITMAP_FREE (far_labels
);
6113 /* Recompute insn addresses. */
6115 init_insn_lengths ();
6116 shorten_branches (get_insns ());
6121 /* POOL_LIST is a chunk list as prepared by s390_chunkify_start.
6122 After we have decided to use this list, finish implementing
6123 all changes to the current function as required. */
6126 s390_chunkify_finish (struct constant_pool
*pool_list
)
6128 struct constant_pool
*curr_pool
= NULL
;
6132 /* Replace all literal pool references. */
6134 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6137 replace_ltrel_base (&PATTERN (insn
));
6139 curr_pool
= s390_find_pool (pool_list
, insn
);
6143 if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
6145 rtx addr
, pool_ref
= NULL_RTX
;
6146 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
6149 if (s390_execute_label (insn
))
6150 addr
= s390_find_execute (curr_pool
, insn
);
6152 addr
= s390_find_constant (curr_pool
,
6153 get_pool_constant (pool_ref
),
6154 get_pool_mode (pool_ref
));
6156 replace_constant_pool_ref (&PATTERN (insn
), pool_ref
, addr
);
6157 INSN_CODE (insn
) = -1;
6162 /* Dump out all literal pools. */
6164 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
6165 s390_dump_pool (curr_pool
, 0);
6167 /* Free pool list. */
6171 struct constant_pool
*next
= pool_list
->next
;
6172 s390_free_pool (pool_list
);
6177 /* POOL_LIST is a chunk list as prepared by s390_chunkify_start.
6178 We have decided we cannot use this list, so revert all changes
6179 to the current function that were done by s390_chunkify_start. */
6182 s390_chunkify_cancel (struct constant_pool
*pool_list
)
6184 struct constant_pool
*curr_pool
= NULL
;
6187 /* Remove all pool placeholder insns. */
6189 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
6191 /* Did we insert an extra barrier? Remove it. */
6192 rtx barrier
= PREV_INSN (curr_pool
->pool_insn
);
6193 rtx jump
= barrier
? PREV_INSN (barrier
) : NULL_RTX
;
6194 rtx label
= NEXT_INSN (curr_pool
->pool_insn
);
6196 if (jump
&& GET_CODE (jump
) == JUMP_INSN
6197 && barrier
&& GET_CODE (barrier
) == BARRIER
6198 && label
&& GET_CODE (label
) == CODE_LABEL
6199 && GET_CODE (PATTERN (jump
)) == SET
6200 && SET_DEST (PATTERN (jump
)) == pc_rtx
6201 && GET_CODE (SET_SRC (PATTERN (jump
))) == LABEL_REF
6202 && XEXP (SET_SRC (PATTERN (jump
)), 0) == label
)
6205 remove_insn (barrier
);
6206 remove_insn (label
);
6209 remove_insn (curr_pool
->pool_insn
);
6212 /* Remove all base register reload insns. */
6214 for (insn
= get_insns (); insn
; )
6216 rtx next_insn
= NEXT_INSN (insn
);
6218 if (GET_CODE (insn
) == INSN
6219 && GET_CODE (PATTERN (insn
)) == SET
6220 && GET_CODE (SET_SRC (PATTERN (insn
))) == UNSPEC
6221 && XINT (SET_SRC (PATTERN (insn
)), 1) == UNSPEC_RELOAD_BASE
)
6227 /* Free pool list. */
6231 struct constant_pool
*next
= pool_list
->next
;
6232 s390_free_pool (pool_list
);
6238 /* Output the constant pool entry EXP in mode MODE with alignment ALIGN. */
6241 s390_output_pool_entry (rtx exp
, enum machine_mode mode
, unsigned int align
)
6245 switch (GET_MODE_CLASS (mode
))
6248 case MODE_DECIMAL_FLOAT
:
6249 gcc_assert (GET_CODE (exp
) == CONST_DOUBLE
);
6251 REAL_VALUE_FROM_CONST_DOUBLE (r
, exp
);
6252 assemble_real (r
, mode
, align
);
6256 assemble_integer (exp
, GET_MODE_SIZE (mode
), align
, 1);
6265 /* Return an RTL expression representing the value of the return address
6266 for the frame COUNT steps up from the current frame. FRAME is the
6267 frame pointer of that frame. */
6270 s390_return_addr_rtx (int count
, rtx frame ATTRIBUTE_UNUSED
)
6275 /* Without backchain, we fail for all but the current frame. */
6277 if (!TARGET_BACKCHAIN
&& count
> 0)
6280 /* For the current frame, we need to make sure the initial
6281 value of RETURN_REGNUM is actually saved. */
6285 /* On non-z architectures branch splitting could overwrite r14. */
6286 if (TARGET_CPU_ZARCH
)
6287 return get_hard_reg_initial_val (Pmode
, RETURN_REGNUM
);
6290 cfun_frame_layout
.save_return_addr_p
= true;
6291 return gen_rtx_MEM (Pmode
, return_address_pointer_rtx
);
6295 if (TARGET_PACKED_STACK
)
6296 offset
= -2 * UNITS_PER_WORD
;
6298 offset
= RETURN_REGNUM
* UNITS_PER_WORD
;
6300 addr
= plus_constant (frame
, offset
);
6301 addr
= memory_address (Pmode
, addr
);
6302 return gen_rtx_MEM (Pmode
, addr
);
6305 /* Return an RTL expression representing the back chain stored in
6306 the current stack frame. */
6309 s390_back_chain_rtx (void)
6313 gcc_assert (TARGET_BACKCHAIN
);
6315 if (TARGET_PACKED_STACK
)
6316 chain
= plus_constant (stack_pointer_rtx
,
6317 STACK_POINTER_OFFSET
- UNITS_PER_WORD
);
6319 chain
= stack_pointer_rtx
;
6321 chain
= gen_rtx_MEM (Pmode
, chain
);
6325 /* Find first call clobbered register unused in a function.
6326 This could be used as base register in a leaf function
6327 or for holding the return address before epilogue. */
6330 find_unused_clobbered_reg (void)
6333 for (i
= 0; i
< 6; i
++)
6334 if (!regs_ever_live
[i
])
6340 /* Helper function for s390_regs_ever_clobbered. Sets the fields in DATA for all
6341 clobbered hard regs in SETREG. */
6344 s390_reg_clobbered_rtx (rtx setreg
, rtx set_insn ATTRIBUTE_UNUSED
, void *data
)
6346 int *regs_ever_clobbered
= (int *)data
;
6347 unsigned int i
, regno
;
6348 enum machine_mode mode
= GET_MODE (setreg
);
6350 if (GET_CODE (setreg
) == SUBREG
)
6352 rtx inner
= SUBREG_REG (setreg
);
6353 if (!GENERAL_REG_P (inner
))
6355 regno
= subreg_regno (setreg
);
6357 else if (GENERAL_REG_P (setreg
))
6358 regno
= REGNO (setreg
);
6363 i
< regno
+ HARD_REGNO_NREGS (regno
, mode
);
6365 regs_ever_clobbered
[i
] = 1;
6368 /* Walks through all basic blocks of the current function looking
6369 for clobbered hard regs using s390_reg_clobbered_rtx. The fields
6370 of the passed integer array REGS_EVER_CLOBBERED are set to one for
6371 each of those regs. */
6374 s390_regs_ever_clobbered (int *regs_ever_clobbered
)
6380 memset (regs_ever_clobbered
, 0, 16 * sizeof (int));
6382 /* For non-leaf functions we have to consider all call clobbered regs to be
6384 if (!current_function_is_leaf
)
6386 for (i
= 0; i
< 16; i
++)
6387 regs_ever_clobbered
[i
] = call_really_used_regs
[i
];
6390 /* Make the "magic" eh_return registers live if necessary. For regs_ever_live
6391 this work is done by liveness analysis (mark_regs_live_at_end).
6392 Special care is needed for functions containing landing pads. Landing pads
6393 may use the eh registers, but the code which sets these registers is not
6394 contained in that function. Hence s390_regs_ever_clobbered is not able to
6395 deal with this automatically. */
6396 if (current_function_calls_eh_return
|| cfun
->machine
->has_landing_pad_p
)
6397 for (i
= 0; EH_RETURN_DATA_REGNO (i
) != INVALID_REGNUM
; i
++)
6398 if (current_function_calls_eh_return
6399 || (cfun
->machine
->has_landing_pad_p
6400 && regs_ever_live
[EH_RETURN_DATA_REGNO (i
)]))
6401 regs_ever_clobbered
[EH_RETURN_DATA_REGNO (i
)] = 1;
6403 /* For nonlocal gotos all call-saved registers have to be saved.
6404 This flag is also set for the unwinding code in libgcc.
6405 See expand_builtin_unwind_init. For regs_ever_live this is done by
6407 if (current_function_has_nonlocal_label
)
6408 for (i
= 0; i
< 16; i
++)
6409 if (!call_really_used_regs
[i
])
6410 regs_ever_clobbered
[i
] = 1;
6412 FOR_EACH_BB (cur_bb
)
6414 FOR_BB_INSNS (cur_bb
, cur_insn
)
6416 if (INSN_P (cur_insn
))
6417 note_stores (PATTERN (cur_insn
),
6418 s390_reg_clobbered_rtx
,
6419 regs_ever_clobbered
);
6424 /* Determine the frame area which actually has to be accessed
6425 in the function epilogue. The values are stored at the
6426 given pointers AREA_BOTTOM (address of the lowest used stack
6427 address) and AREA_TOP (address of the first item which does
6428 not belong to the stack frame). */
6431 s390_frame_area (int *area_bottom
, int *area_top
)
6439 if (cfun_frame_layout
.first_restore_gpr
!= -1)
6441 b
= (cfun_frame_layout
.gprs_offset
6442 + cfun_frame_layout
.first_restore_gpr
* UNITS_PER_WORD
);
6443 t
= b
+ (cfun_frame_layout
.last_restore_gpr
6444 - cfun_frame_layout
.first_restore_gpr
+ 1) * UNITS_PER_WORD
;
6447 if (TARGET_64BIT
&& cfun_save_high_fprs_p
)
6449 b
= MIN (b
, cfun_frame_layout
.f8_offset
);
6450 t
= MAX (t
, (cfun_frame_layout
.f8_offset
6451 + cfun_frame_layout
.high_fprs
* 8));
6455 for (i
= 2; i
< 4; i
++)
6456 if (cfun_fpr_bit_p (i
))
6458 b
= MIN (b
, cfun_frame_layout
.f4_offset
+ (i
- 2) * 8);
6459 t
= MAX (t
, cfun_frame_layout
.f4_offset
+ (i
- 1) * 8);
6466 /* Fill cfun->machine with info about register usage of current function.
6467 Return in CLOBBERED_REGS which GPRs are currently considered set. */
6470 s390_register_info (int clobbered_regs
[])
6474 /* fprs 8 - 15 are call saved for 64 Bit ABI. */
6475 cfun_frame_layout
.fpr_bitmap
= 0;
6476 cfun_frame_layout
.high_fprs
= 0;
6478 for (i
= 24; i
< 32; i
++)
6479 if (regs_ever_live
[i
] && !global_regs
[i
])
6481 cfun_set_fpr_bit (i
- 16);
6482 cfun_frame_layout
.high_fprs
++;
6485 /* Find first and last gpr to be saved. We trust regs_ever_live
6486 data, except that we don't save and restore global registers.
6488 Also, all registers with special meaning to the compiler need
6489 to be handled extra. */
6491 s390_regs_ever_clobbered (clobbered_regs
);
6493 for (i
= 0; i
< 16; i
++)
6494 clobbered_regs
[i
] = clobbered_regs
[i
] && !global_regs
[i
] && !fixed_regs
[i
];
6496 if (frame_pointer_needed
)
6497 clobbered_regs
[HARD_FRAME_POINTER_REGNUM
] = 1;
6500 clobbered_regs
[PIC_OFFSET_TABLE_REGNUM
]
6501 |= regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
];
6503 clobbered_regs
[BASE_REGNUM
]
6504 |= (cfun
->machine
->base_reg
6505 && REGNO (cfun
->machine
->base_reg
) == BASE_REGNUM
);
6507 clobbered_regs
[RETURN_REGNUM
]
6508 |= (!current_function_is_leaf
6509 || TARGET_TPF_PROFILING
6510 || cfun
->machine
->split_branches_pending_p
6511 || cfun_frame_layout
.save_return_addr_p
6512 || current_function_calls_eh_return
6513 || current_function_stdarg
);
6515 clobbered_regs
[STACK_POINTER_REGNUM
]
6516 |= (!current_function_is_leaf
6517 || TARGET_TPF_PROFILING
6518 || cfun_save_high_fprs_p
6519 || get_frame_size () > 0
6520 || current_function_calls_alloca
6521 || current_function_stdarg
);
6523 for (i
= 6; i
< 16; i
++)
6524 if (regs_ever_live
[i
] || clobbered_regs
[i
])
6526 for (j
= 15; j
> i
; j
--)
6527 if (regs_ever_live
[j
] || clobbered_regs
[j
])
6532 /* Nothing to save/restore. */
6533 cfun_frame_layout
.first_save_gpr_slot
= -1;
6534 cfun_frame_layout
.last_save_gpr_slot
= -1;
6535 cfun_frame_layout
.first_save_gpr
= -1;
6536 cfun_frame_layout
.first_restore_gpr
= -1;
6537 cfun_frame_layout
.last_save_gpr
= -1;
6538 cfun_frame_layout
.last_restore_gpr
= -1;
6542 /* Save slots for gprs from i to j. */
6543 cfun_frame_layout
.first_save_gpr_slot
= i
;
6544 cfun_frame_layout
.last_save_gpr_slot
= j
;
6546 for (i
= cfun_frame_layout
.first_save_gpr_slot
;
6547 i
< cfun_frame_layout
.last_save_gpr_slot
+ 1;
6549 if (clobbered_regs
[i
])
6552 for (j
= cfun_frame_layout
.last_save_gpr_slot
; j
> i
; j
--)
6553 if (clobbered_regs
[j
])
6556 if (i
== cfun_frame_layout
.last_save_gpr_slot
+ 1)
6558 /* Nothing to save/restore. */
6559 cfun_frame_layout
.first_save_gpr
= -1;
6560 cfun_frame_layout
.first_restore_gpr
= -1;
6561 cfun_frame_layout
.last_save_gpr
= -1;
6562 cfun_frame_layout
.last_restore_gpr
= -1;
6566 /* Save / Restore from gpr i to j. */
6567 cfun_frame_layout
.first_save_gpr
= i
;
6568 cfun_frame_layout
.first_restore_gpr
= i
;
6569 cfun_frame_layout
.last_save_gpr
= j
;
6570 cfun_frame_layout
.last_restore_gpr
= j
;
6574 if (current_function_stdarg
)
6576 /* Varargs functions need to save gprs 2 to 6. */
6577 if (cfun
->va_list_gpr_size
6578 && current_function_args_info
.gprs
< GP_ARG_NUM_REG
)
6580 int min_gpr
= current_function_args_info
.gprs
;
6581 int max_gpr
= min_gpr
+ cfun
->va_list_gpr_size
;
6582 if (max_gpr
> GP_ARG_NUM_REG
)
6583 max_gpr
= GP_ARG_NUM_REG
;
6585 if (cfun_frame_layout
.first_save_gpr
== -1
6586 || cfun_frame_layout
.first_save_gpr
> 2 + min_gpr
)
6588 cfun_frame_layout
.first_save_gpr
= 2 + min_gpr
;
6589 cfun_frame_layout
.first_save_gpr_slot
= 2 + min_gpr
;
6592 if (cfun_frame_layout
.last_save_gpr
== -1
6593 || cfun_frame_layout
.last_save_gpr
< 2 + max_gpr
- 1)
6595 cfun_frame_layout
.last_save_gpr
= 2 + max_gpr
- 1;
6596 cfun_frame_layout
.last_save_gpr_slot
= 2 + max_gpr
- 1;
6600 /* Mark f0, f2 for 31 bit and f0-f4 for 64 bit to be saved. */
6601 if (TARGET_HARD_FLOAT
&& cfun
->va_list_fpr_size
6602 && current_function_args_info
.fprs
< FP_ARG_NUM_REG
)
6604 int min_fpr
= current_function_args_info
.fprs
;
6605 int max_fpr
= min_fpr
+ cfun
->va_list_fpr_size
;
6606 if (max_fpr
> FP_ARG_NUM_REG
)
6607 max_fpr
= FP_ARG_NUM_REG
;
6609 /* ??? This is currently required to ensure proper location
6610 of the fpr save slots within the va_list save area. */
6611 if (TARGET_PACKED_STACK
)
6614 for (i
= min_fpr
; i
< max_fpr
; i
++)
6615 cfun_set_fpr_bit (i
);
6620 for (i
= 2; i
< 4; i
++)
6621 if (regs_ever_live
[i
+ 16] && !global_regs
[i
+ 16])
6622 cfun_set_fpr_bit (i
);
6625 /* Fill cfun->machine with info about frame of current function. */
6628 s390_frame_info (void)
6632 cfun_frame_layout
.frame_size
= get_frame_size ();
6633 if (!TARGET_64BIT
&& cfun_frame_layout
.frame_size
> 0x7fff0000)
6634 fatal_error ("total size of local variables exceeds architecture limit");
6636 if (!TARGET_PACKED_STACK
)
6638 cfun_frame_layout
.backchain_offset
= 0;
6639 cfun_frame_layout
.f0_offset
= 16 * UNITS_PER_WORD
;
6640 cfun_frame_layout
.f4_offset
= cfun_frame_layout
.f0_offset
+ 2 * 8;
6641 cfun_frame_layout
.f8_offset
= -cfun_frame_layout
.high_fprs
* 8;
6642 cfun_frame_layout
.gprs_offset
= (cfun_frame_layout
.first_save_gpr_slot
6645 else if (TARGET_BACKCHAIN
) /* kernel stack layout */
6647 cfun_frame_layout
.backchain_offset
= (STACK_POINTER_OFFSET
6649 cfun_frame_layout
.gprs_offset
6650 = (cfun_frame_layout
.backchain_offset
6651 - (STACK_POINTER_REGNUM
- cfun_frame_layout
.first_save_gpr_slot
+ 1)
6656 cfun_frame_layout
.f4_offset
6657 = (cfun_frame_layout
.gprs_offset
6658 - 8 * (cfun_fpr_bit_p (2) + cfun_fpr_bit_p (3)));
6660 cfun_frame_layout
.f0_offset
6661 = (cfun_frame_layout
.f4_offset
6662 - 8 * (cfun_fpr_bit_p (0) + cfun_fpr_bit_p (1)));
6666 /* On 31 bit we have to care about alignment of the
6667 floating point regs to provide fastest access. */
6668 cfun_frame_layout
.f0_offset
6669 = ((cfun_frame_layout
.gprs_offset
6670 & ~(STACK_BOUNDARY
/ BITS_PER_UNIT
- 1))
6671 - 8 * (cfun_fpr_bit_p (0) + cfun_fpr_bit_p (1)));
6673 cfun_frame_layout
.f4_offset
6674 = (cfun_frame_layout
.f0_offset
6675 - 8 * (cfun_fpr_bit_p (2) + cfun_fpr_bit_p (3)));
6678 else /* no backchain */
6680 cfun_frame_layout
.f4_offset
6681 = (STACK_POINTER_OFFSET
6682 - 8 * (cfun_fpr_bit_p (2) + cfun_fpr_bit_p (3)));
6684 cfun_frame_layout
.f0_offset
6685 = (cfun_frame_layout
.f4_offset
6686 - 8 * (cfun_fpr_bit_p (0) + cfun_fpr_bit_p (1)));
6688 cfun_frame_layout
.gprs_offset
6689 = cfun_frame_layout
.f0_offset
- cfun_gprs_save_area_size
;
6692 if (current_function_is_leaf
6693 && !TARGET_TPF_PROFILING
6694 && cfun_frame_layout
.frame_size
== 0
6695 && !cfun_save_high_fprs_p
6696 && !current_function_calls_alloca
6697 && !current_function_stdarg
)
6700 if (!TARGET_PACKED_STACK
)
6701 cfun_frame_layout
.frame_size
+= (STACK_POINTER_OFFSET
6702 + current_function_outgoing_args_size
6703 + cfun_frame_layout
.high_fprs
* 8);
6706 if (TARGET_BACKCHAIN
)
6707 cfun_frame_layout
.frame_size
+= UNITS_PER_WORD
;
6709 /* No alignment trouble here because f8-f15 are only saved under
6711 cfun_frame_layout
.f8_offset
= (MIN (MIN (cfun_frame_layout
.f0_offset
,
6712 cfun_frame_layout
.f4_offset
),
6713 cfun_frame_layout
.gprs_offset
)
6714 - cfun_frame_layout
.high_fprs
* 8);
6716 cfun_frame_layout
.frame_size
+= cfun_frame_layout
.high_fprs
* 8;
6718 for (i
= 0; i
< 8; i
++)
6719 if (cfun_fpr_bit_p (i
))
6720 cfun_frame_layout
.frame_size
+= 8;
6722 cfun_frame_layout
.frame_size
+= cfun_gprs_save_area_size
;
6724 /* If under 31 bit an odd number of gprs has to be saved we have to adjust
6725 the frame size to sustain 8 byte alignment of stack frames. */
6726 cfun_frame_layout
.frame_size
= ((cfun_frame_layout
.frame_size
+
6727 STACK_BOUNDARY
/ BITS_PER_UNIT
- 1)
6728 & ~(STACK_BOUNDARY
/ BITS_PER_UNIT
- 1));
6730 cfun_frame_layout
.frame_size
+= current_function_outgoing_args_size
;
6734 /* Generate frame layout. Fills in register and frame data for the current
6735 function in cfun->machine. This routine can be called multiple times;
6736 it will re-do the complete frame layout every time. */
6739 s390_init_frame_layout (void)
6741 HOST_WIDE_INT frame_size
;
6743 int clobbered_regs
[16];
6745 /* On S/390 machines, we may need to perform branch splitting, which
6746 will require both base and return address register. We have no
6747 choice but to assume we're going to need them until right at the
6748 end of the machine dependent reorg phase. */
6749 if (!TARGET_CPU_ZARCH
)
6750 cfun
->machine
->split_branches_pending_p
= true;
6754 frame_size
= cfun_frame_layout
.frame_size
;
6756 /* Try to predict whether we'll need the base register. */
6757 base_used
= cfun
->machine
->split_branches_pending_p
6758 || current_function_uses_const_pool
6759 || (!DISP_IN_RANGE (frame_size
)
6760 && !CONST_OK_FOR_K (frame_size
));
6762 /* Decide which register to use as literal pool base. In small
6763 leaf functions, try to use an unused call-clobbered register
6764 as base register to avoid save/restore overhead. */
6766 cfun
->machine
->base_reg
= NULL_RTX
;
6767 else if (current_function_is_leaf
&& !regs_ever_live
[5])
6768 cfun
->machine
->base_reg
= gen_rtx_REG (Pmode
, 5);
6770 cfun
->machine
->base_reg
= gen_rtx_REG (Pmode
, BASE_REGNUM
);
6772 s390_register_info (clobbered_regs
);
6775 while (frame_size
!= cfun_frame_layout
.frame_size
);
6778 /* Update frame layout. Recompute actual register save data based on
6779 current info and update regs_ever_live for the special registers.
6780 May be called multiple times, but may never cause *more* registers
6781 to be saved than s390_init_frame_layout allocated room for. */
6784 s390_update_frame_layout (void)
6786 int clobbered_regs
[16];
6788 s390_register_info (clobbered_regs
);
6790 regs_ever_live
[BASE_REGNUM
] = clobbered_regs
[BASE_REGNUM
];
6791 regs_ever_live
[RETURN_REGNUM
] = clobbered_regs
[RETURN_REGNUM
];
6792 regs_ever_live
[STACK_POINTER_REGNUM
] = clobbered_regs
[STACK_POINTER_REGNUM
];
6794 if (cfun
->machine
->base_reg
)
6795 regs_ever_live
[REGNO (cfun
->machine
->base_reg
)] = 1;
6798 /* Return true if it is legal to put a value with MODE into REGNO. */
6801 s390_hard_regno_mode_ok (unsigned int regno
, enum machine_mode mode
)
6803 switch (REGNO_REG_CLASS (regno
))
6806 if (REGNO_PAIR_OK (regno
, mode
))
6808 if (mode
== SImode
|| mode
== DImode
)
6811 if (FLOAT_MODE_P (mode
) && GET_MODE_CLASS (mode
) != MODE_VECTOR_FLOAT
)
6816 if (FRAME_REGNO_P (regno
) && mode
== Pmode
)
6821 if (REGNO_PAIR_OK (regno
, mode
))
6824 || (mode
!= TFmode
&& mode
!= TCmode
&& mode
!= TDmode
))
6829 if (GET_MODE_CLASS (mode
) == MODE_CC
)
6833 if (REGNO_PAIR_OK (regno
, mode
))
6835 if (mode
== SImode
|| mode
== Pmode
)
6846 /* Return nonzero if register OLD_REG can be renamed to register NEW_REG. */
6849 s390_hard_regno_rename_ok (unsigned int old_reg
, unsigned int new_reg
)
6851 /* Once we've decided upon a register to use as base register, it must
6852 no longer be used for any other purpose. */
6853 if (cfun
->machine
->base_reg
)
6854 if (REGNO (cfun
->machine
->base_reg
) == old_reg
6855 || REGNO (cfun
->machine
->base_reg
) == new_reg
)
6861 /* Maximum number of registers to represent a value of mode MODE
6862 in a register of class CLASS. */
6865 s390_class_max_nregs (enum reg_class
class, enum machine_mode mode
)
6870 if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
)
6871 return 2 * ((GET_MODE_SIZE (mode
) / 2 + 8 - 1) / 8);
6873 return (GET_MODE_SIZE (mode
) + 8 - 1) / 8;
6875 return (GET_MODE_SIZE (mode
) + 4 - 1) / 4;
6879 return (GET_MODE_SIZE (mode
) + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
6882 /* Return true if register FROM can be eliminated via register TO. */
6885 s390_can_eliminate (int from
, int to
)
6887 /* On zSeries machines, we have not marked the base register as fixed.
6888 Instead, we have an elimination rule BASE_REGNUM -> BASE_REGNUM.
6889 If a function requires the base register, we say here that this
6890 elimination cannot be performed. This will cause reload to free
6891 up the base register (as if it were fixed). On the other hand,
6892 if the current function does *not* require the base register, we
6893 say here the elimination succeeds, which in turn allows reload
6894 to allocate the base register for any other purpose. */
6895 if (from
== BASE_REGNUM
&& to
== BASE_REGNUM
)
6897 if (TARGET_CPU_ZARCH
)
6899 s390_init_frame_layout ();
6900 return cfun
->machine
->base_reg
== NULL_RTX
;
6906 /* Everything else must point into the stack frame. */
6907 gcc_assert (to
== STACK_POINTER_REGNUM
6908 || to
== HARD_FRAME_POINTER_REGNUM
);
6910 gcc_assert (from
== FRAME_POINTER_REGNUM
6911 || from
== ARG_POINTER_REGNUM
6912 || from
== RETURN_ADDRESS_POINTER_REGNUM
);
6914 /* Make sure we actually saved the return address. */
6915 if (from
== RETURN_ADDRESS_POINTER_REGNUM
)
6916 if (!current_function_calls_eh_return
6917 && !current_function_stdarg
6918 && !cfun_frame_layout
.save_return_addr_p
)
6924 /* Return offset between register FROM and TO initially after prolog. */
6927 s390_initial_elimination_offset (int from
, int to
)
6929 HOST_WIDE_INT offset
;
6932 /* ??? Why are we called for non-eliminable pairs? */
6933 if (!s390_can_eliminate (from
, to
))
6938 case FRAME_POINTER_REGNUM
:
6939 offset
= (get_frame_size()
6940 + STACK_POINTER_OFFSET
6941 + current_function_outgoing_args_size
);
6944 case ARG_POINTER_REGNUM
:
6945 s390_init_frame_layout ();
6946 offset
= cfun_frame_layout
.frame_size
+ STACK_POINTER_OFFSET
;
6949 case RETURN_ADDRESS_POINTER_REGNUM
:
6950 s390_init_frame_layout ();
6951 index
= RETURN_REGNUM
- cfun_frame_layout
.first_save_gpr_slot
;
6952 gcc_assert (index
>= 0);
6953 offset
= cfun_frame_layout
.frame_size
+ cfun_frame_layout
.gprs_offset
;
6954 offset
+= index
* UNITS_PER_WORD
;
6968 /* Emit insn to save fpr REGNUM at offset OFFSET relative
6969 to register BASE. Return generated insn. */
6972 save_fpr (rtx base
, int offset
, int regnum
)
6975 addr
= gen_rtx_MEM (DFmode
, plus_constant (base
, offset
));
6977 if (regnum
>= 16 && regnum
<= (16 + FP_ARG_NUM_REG
))
6978 set_mem_alias_set (addr
, get_varargs_alias_set ());
6980 set_mem_alias_set (addr
, get_frame_alias_set ());
6982 return emit_move_insn (addr
, gen_rtx_REG (DFmode
, regnum
));
6985 /* Emit insn to restore fpr REGNUM from offset OFFSET relative
6986 to register BASE. Return generated insn. */
6989 restore_fpr (rtx base
, int offset
, int regnum
)
6992 addr
= gen_rtx_MEM (DFmode
, plus_constant (base
, offset
));
6993 set_mem_alias_set (addr
, get_frame_alias_set ());
6995 return emit_move_insn (gen_rtx_REG (DFmode
, regnum
), addr
);
6998 /* Generate insn to save registers FIRST to LAST into
6999 the register save area located at offset OFFSET
7000 relative to register BASE. */
7003 save_gprs (rtx base
, int offset
, int first
, int last
)
7005 rtx addr
, insn
, note
;
7008 addr
= plus_constant (base
, offset
);
7009 addr
= gen_rtx_MEM (Pmode
, addr
);
7011 set_mem_alias_set (addr
, get_frame_alias_set ());
7013 /* Special-case single register. */
7017 insn
= gen_movdi (addr
, gen_rtx_REG (Pmode
, first
));
7019 insn
= gen_movsi (addr
, gen_rtx_REG (Pmode
, first
));
7021 RTX_FRAME_RELATED_P (insn
) = 1;
7026 insn
= gen_store_multiple (addr
,
7027 gen_rtx_REG (Pmode
, first
),
7028 GEN_INT (last
- first
+ 1));
7030 if (first
<= 6 && current_function_stdarg
)
7031 for (i
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
7033 rtx mem
= XEXP (XVECEXP (PATTERN (insn
), 0, i
), 0);
7036 set_mem_alias_set (mem
, get_varargs_alias_set ());
7039 /* We need to set the FRAME_RELATED flag on all SETs
7040 inside the store-multiple pattern.
7042 However, we must not emit DWARF records for registers 2..5
7043 if they are stored for use by variable arguments ...
7045 ??? Unfortunately, it is not enough to simply not the
7046 FRAME_RELATED flags for those SETs, because the first SET
7047 of the PARALLEL is always treated as if it had the flag
7048 set, even if it does not. Therefore we emit a new pattern
7049 without those registers as REG_FRAME_RELATED_EXPR note. */
7053 rtx pat
= PATTERN (insn
);
7055 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
7056 if (GET_CODE (XVECEXP (pat
, 0, i
)) == SET
)
7057 RTX_FRAME_RELATED_P (XVECEXP (pat
, 0, i
)) = 1;
7059 RTX_FRAME_RELATED_P (insn
) = 1;
7063 addr
= plus_constant (base
, offset
+ (6 - first
) * UNITS_PER_WORD
);
7064 note
= gen_store_multiple (gen_rtx_MEM (Pmode
, addr
),
7065 gen_rtx_REG (Pmode
, 6),
7066 GEN_INT (last
- 6 + 1));
7067 note
= PATTERN (note
);
7070 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR
,
7071 note
, REG_NOTES (insn
));
7073 for (i
= 0; i
< XVECLEN (note
, 0); i
++)
7074 if (GET_CODE (XVECEXP (note
, 0, i
)) == SET
)
7075 RTX_FRAME_RELATED_P (XVECEXP (note
, 0, i
)) = 1;
7077 RTX_FRAME_RELATED_P (insn
) = 1;
7083 /* Generate insn to restore registers FIRST to LAST from
7084 the register save area located at offset OFFSET
7085 relative to register BASE. */
7088 restore_gprs (rtx base
, int offset
, int first
, int last
)
7092 addr
= plus_constant (base
, offset
);
7093 addr
= gen_rtx_MEM (Pmode
, addr
);
7094 set_mem_alias_set (addr
, get_frame_alias_set ());
7096 /* Special-case single register. */
7100 insn
= gen_movdi (gen_rtx_REG (Pmode
, first
), addr
);
7102 insn
= gen_movsi (gen_rtx_REG (Pmode
, first
), addr
);
7107 insn
= gen_load_multiple (gen_rtx_REG (Pmode
, first
),
7109 GEN_INT (last
- first
+ 1));
7113 /* Return insn sequence to load the GOT register. */
7115 static GTY(()) rtx got_symbol
;
7117 s390_load_got (void)
7123 got_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "_GLOBAL_OFFSET_TABLE_");
7124 SYMBOL_REF_FLAGS (got_symbol
) = SYMBOL_FLAG_LOCAL
;
7129 if (TARGET_CPU_ZARCH
)
7131 emit_move_insn (pic_offset_table_rtx
, got_symbol
);
7137 offset
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, got_symbol
),
7138 UNSPEC_LTREL_OFFSET
);
7139 offset
= gen_rtx_CONST (Pmode
, offset
);
7140 offset
= force_const_mem (Pmode
, offset
);
7142 emit_move_insn (pic_offset_table_rtx
, offset
);
7144 offset
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, XEXP (offset
, 0)),
7146 offset
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, offset
);
7148 emit_move_insn (pic_offset_table_rtx
, offset
);
7151 insns
= get_insns ();
7156 /* Expand the prologue into a bunch of separate insns. */
7159 s390_emit_prologue (void)
7167 /* Complete frame layout. */
7169 s390_update_frame_layout ();
7171 /* Annotate all constant pool references to let the scheduler know
7172 they implicitly use the base register. */
7174 push_topmost_sequence ();
7176 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
7178 annotate_constant_pool_refs (&PATTERN (insn
));
7180 pop_topmost_sequence ();
7182 /* Choose best register to use for temp use within prologue.
7183 See below for why TPF must use the register 1. */
7185 if (!has_hard_reg_initial_val (Pmode
, RETURN_REGNUM
)
7186 && !current_function_is_leaf
7187 && !TARGET_TPF_PROFILING
)
7188 temp_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
7190 temp_reg
= gen_rtx_REG (Pmode
, 1);
7192 /* Save call saved gprs. */
7193 if (cfun_frame_layout
.first_save_gpr
!= -1)
7195 insn
= save_gprs (stack_pointer_rtx
,
7196 cfun_frame_layout
.gprs_offset
+
7197 UNITS_PER_WORD
* (cfun_frame_layout
.first_save_gpr
7198 - cfun_frame_layout
.first_save_gpr_slot
),
7199 cfun_frame_layout
.first_save_gpr
,
7200 cfun_frame_layout
.last_save_gpr
);
7204 /* Dummy insn to mark literal pool slot. */
7206 if (cfun
->machine
->base_reg
)
7207 emit_insn (gen_main_pool (cfun
->machine
->base_reg
));
7209 offset
= cfun_frame_layout
.f0_offset
;
7211 /* Save f0 and f2. */
7212 for (i
= 0; i
< 2; i
++)
7214 if (cfun_fpr_bit_p (i
))
7216 save_fpr (stack_pointer_rtx
, offset
, i
+ 16);
7219 else if (!TARGET_PACKED_STACK
)
7223 /* Save f4 and f6. */
7224 offset
= cfun_frame_layout
.f4_offset
;
7225 for (i
= 2; i
< 4; i
++)
7227 if (cfun_fpr_bit_p (i
))
7229 insn
= save_fpr (stack_pointer_rtx
, offset
, i
+ 16);
7232 /* If f4 and f6 are call clobbered they are saved due to stdargs and
7233 therefore are not frame related. */
7234 if (!call_really_used_regs
[i
+ 16])
7235 RTX_FRAME_RELATED_P (insn
) = 1;
7237 else if (!TARGET_PACKED_STACK
)
7241 if (TARGET_PACKED_STACK
7242 && cfun_save_high_fprs_p
7243 && cfun_frame_layout
.f8_offset
+ cfun_frame_layout
.high_fprs
* 8 > 0)
7245 offset
= (cfun_frame_layout
.f8_offset
7246 + (cfun_frame_layout
.high_fprs
- 1) * 8);
7248 for (i
= 15; i
> 7 && offset
>= 0; i
--)
7249 if (cfun_fpr_bit_p (i
))
7251 insn
= save_fpr (stack_pointer_rtx
, offset
, i
+ 16);
7253 RTX_FRAME_RELATED_P (insn
) = 1;
7256 if (offset
>= cfun_frame_layout
.f8_offset
)
7260 if (!TARGET_PACKED_STACK
)
7261 next_fpr
= cfun_save_high_fprs_p
? 31 : 0;
7263 /* Decrement stack pointer. */
7265 if (cfun_frame_layout
.frame_size
> 0)
7267 rtx frame_off
= GEN_INT (-cfun_frame_layout
.frame_size
);
7269 if (s390_stack_size
)
7271 HOST_WIDE_INT stack_guard
;
7273 if (s390_stack_guard
)
7274 stack_guard
= s390_stack_guard
;
7277 /* If no value for stack guard is provided the smallest power of 2
7278 larger than the current frame size is chosen. */
7280 while (stack_guard
< cfun_frame_layout
.frame_size
)
7284 if (cfun_frame_layout
.frame_size
>= s390_stack_size
)
7286 warning (0, "frame size of function %qs is "
7287 HOST_WIDE_INT_PRINT_DEC
7288 " bytes exceeding user provided stack limit of "
7289 HOST_WIDE_INT_PRINT_DEC
" bytes. "
7290 "An unconditional trap is added.",
7291 current_function_name(), cfun_frame_layout
.frame_size
,
7293 emit_insn (gen_trap ());
7297 HOST_WIDE_INT stack_check_mask
= ((s390_stack_size
- 1)
7298 & ~(stack_guard
- 1));
7299 rtx t
= gen_rtx_AND (Pmode
, stack_pointer_rtx
,
7300 GEN_INT (stack_check_mask
));
7302 gen_cmpdi (t
, const0_rtx
);
7304 gen_cmpsi (t
, const0_rtx
);
7306 emit_insn (gen_conditional_trap (gen_rtx_EQ (CCmode
,
7307 gen_rtx_REG (CCmode
,
7314 if (s390_warn_framesize
> 0
7315 && cfun_frame_layout
.frame_size
>= s390_warn_framesize
)
7316 warning (0, "frame size of %qs is " HOST_WIDE_INT_PRINT_DEC
" bytes",
7317 current_function_name (), cfun_frame_layout
.frame_size
);
7319 if (s390_warn_dynamicstack_p
&& cfun
->calls_alloca
)
7320 warning (0, "%qs uses dynamic stack allocation", current_function_name ());
7322 /* Save incoming stack pointer into temp reg. */
7323 if (TARGET_BACKCHAIN
|| next_fpr
)
7324 insn
= emit_insn (gen_move_insn (temp_reg
, stack_pointer_rtx
));
7326 /* Subtract frame size from stack pointer. */
7328 if (DISP_IN_RANGE (INTVAL (frame_off
)))
7330 insn
= gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
7331 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
7333 insn
= emit_insn (insn
);
7337 if (!CONST_OK_FOR_K (INTVAL (frame_off
)))
7338 frame_off
= force_const_mem (Pmode
, frame_off
);
7340 insn
= emit_insn (gen_add2_insn (stack_pointer_rtx
, frame_off
));
7341 annotate_constant_pool_refs (&PATTERN (insn
));
7344 RTX_FRAME_RELATED_P (insn
) = 1;
7346 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR
,
7347 gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
7348 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
7349 GEN_INT (-cfun_frame_layout
.frame_size
))),
7352 /* Set backchain. */
7354 if (TARGET_BACKCHAIN
)
7356 if (cfun_frame_layout
.backchain_offset
)
7357 addr
= gen_rtx_MEM (Pmode
,
7358 plus_constant (stack_pointer_rtx
,
7359 cfun_frame_layout
.backchain_offset
));
7361 addr
= gen_rtx_MEM (Pmode
, stack_pointer_rtx
);
7362 set_mem_alias_set (addr
, get_frame_alias_set ());
7363 insn
= emit_insn (gen_move_insn (addr
, temp_reg
));
7366 /* If we support asynchronous exceptions (e.g. for Java),
7367 we need to make sure the backchain pointer is set up
7368 before any possibly trapping memory access. */
7370 if (TARGET_BACKCHAIN
&& flag_non_call_exceptions
)
7372 addr
= gen_rtx_MEM (BLKmode
, gen_rtx_SCRATCH (VOIDmode
));
7373 emit_insn (gen_rtx_CLOBBER (VOIDmode
, addr
));
7377 /* Save fprs 8 - 15 (64 bit ABI). */
7379 if (cfun_save_high_fprs_p
&& next_fpr
)
7381 insn
= emit_insn (gen_add2_insn (temp_reg
,
7382 GEN_INT (cfun_frame_layout
.f8_offset
)));
7386 for (i
= 24; i
<= next_fpr
; i
++)
7387 if (cfun_fpr_bit_p (i
- 16))
7389 rtx addr
= plus_constant (stack_pointer_rtx
,
7390 cfun_frame_layout
.frame_size
7391 + cfun_frame_layout
.f8_offset
7394 insn
= save_fpr (temp_reg
, offset
, i
);
7396 RTX_FRAME_RELATED_P (insn
) = 1;
7398 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR
,
7399 gen_rtx_SET (VOIDmode
,
7400 gen_rtx_MEM (DFmode
, addr
),
7401 gen_rtx_REG (DFmode
, i
)),
7406 /* Set frame pointer, if needed. */
7408 if (frame_pointer_needed
)
7410 insn
= emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
);
7411 RTX_FRAME_RELATED_P (insn
) = 1;
7414 /* Set up got pointer, if needed. */
7416 if (flag_pic
&& regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
])
7418 rtx insns
= s390_load_got ();
7420 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
7422 annotate_constant_pool_refs (&PATTERN (insn
));
7424 REG_NOTES (insn
) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD
, NULL_RTX
,
7431 if (TARGET_TPF_PROFILING
)
7433 /* Generate a BAS instruction to serve as a function
7434 entry intercept to facilitate the use of tracing
7435 algorithms located at the branch target. */
7436 emit_insn (gen_prologue_tpf ());
7438 /* Emit a blockage here so that all code
7439 lies between the profiling mechanisms. */
7440 emit_insn (gen_blockage ());
7444 /* Expand the epilogue into a bunch of separate insns. */
7447 s390_emit_epilogue (bool sibcall
)
7449 rtx frame_pointer
, return_reg
;
7450 int area_bottom
, area_top
, offset
= 0;
7455 if (TARGET_TPF_PROFILING
)
7458 /* Generate a BAS instruction to serve as a function
7459 entry intercept to facilitate the use of tracing
7460 algorithms located at the branch target. */
7462 /* Emit a blockage here so that all code
7463 lies between the profiling mechanisms. */
7464 emit_insn (gen_blockage ());
7466 emit_insn (gen_epilogue_tpf ());
7469 /* Check whether to use frame or stack pointer for restore. */
7471 frame_pointer
= (frame_pointer_needed
7472 ? hard_frame_pointer_rtx
: stack_pointer_rtx
);
7474 s390_frame_area (&area_bottom
, &area_top
);
7476 /* Check whether we can access the register save area.
7477 If not, increment the frame pointer as required. */
7479 if (area_top
<= area_bottom
)
7481 /* Nothing to restore. */
7483 else if (DISP_IN_RANGE (cfun_frame_layout
.frame_size
+ area_bottom
)
7484 && DISP_IN_RANGE (cfun_frame_layout
.frame_size
+ area_top
- 1))
7486 /* Area is in range. */
7487 offset
= cfun_frame_layout
.frame_size
;
7491 rtx insn
, frame_off
;
7493 offset
= area_bottom
< 0 ? -area_bottom
: 0;
7494 frame_off
= GEN_INT (cfun_frame_layout
.frame_size
- offset
);
7496 if (DISP_IN_RANGE (INTVAL (frame_off
)))
7498 insn
= gen_rtx_SET (VOIDmode
, frame_pointer
,
7499 gen_rtx_PLUS (Pmode
, frame_pointer
, frame_off
));
7500 insn
= emit_insn (insn
);
7504 if (!CONST_OK_FOR_K (INTVAL (frame_off
)))
7505 frame_off
= force_const_mem (Pmode
, frame_off
);
7507 insn
= emit_insn (gen_add2_insn (frame_pointer
, frame_off
));
7508 annotate_constant_pool_refs (&PATTERN (insn
));
7512 /* Restore call saved fprs. */
7516 if (cfun_save_high_fprs_p
)
7518 next_offset
= cfun_frame_layout
.f8_offset
;
7519 for (i
= 24; i
< 32; i
++)
7521 if (cfun_fpr_bit_p (i
- 16))
7523 restore_fpr (frame_pointer
,
7524 offset
+ next_offset
, i
);
7533 next_offset
= cfun_frame_layout
.f4_offset
;
7534 for (i
= 18; i
< 20; i
++)
7536 if (cfun_fpr_bit_p (i
- 16))
7538 restore_fpr (frame_pointer
,
7539 offset
+ next_offset
, i
);
7542 else if (!TARGET_PACKED_STACK
)
7548 /* Return register. */
7550 return_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
7552 /* Restore call saved gprs. */
7554 if (cfun_frame_layout
.first_restore_gpr
!= -1)
7559 /* Check for global register and save them
7560 to stack location from where they get restored. */
7562 for (i
= cfun_frame_layout
.first_restore_gpr
;
7563 i
<= cfun_frame_layout
.last_restore_gpr
;
7566 /* These registers are special and need to be
7567 restored in any case. */
7568 if (i
== STACK_POINTER_REGNUM
7569 || i
== RETURN_REGNUM
7571 || (flag_pic
&& i
== (int)PIC_OFFSET_TABLE_REGNUM
))
7576 addr
= plus_constant (frame_pointer
,
7577 offset
+ cfun_frame_layout
.gprs_offset
7578 + (i
- cfun_frame_layout
.first_save_gpr_slot
)
7580 addr
= gen_rtx_MEM (Pmode
, addr
);
7581 set_mem_alias_set (addr
, get_frame_alias_set ());
7582 emit_move_insn (addr
, gen_rtx_REG (Pmode
, i
));
7588 /* Fetch return address from stack before load multiple,
7589 this will do good for scheduling. */
7591 if (cfun_frame_layout
.save_return_addr_p
7592 || (cfun_frame_layout
.first_restore_gpr
< BASE_REGNUM
7593 && cfun_frame_layout
.last_restore_gpr
> RETURN_REGNUM
))
7595 int return_regnum
= find_unused_clobbered_reg();
7598 return_reg
= gen_rtx_REG (Pmode
, return_regnum
);
7600 addr
= plus_constant (frame_pointer
,
7601 offset
+ cfun_frame_layout
.gprs_offset
7603 - cfun_frame_layout
.first_save_gpr_slot
)
7605 addr
= gen_rtx_MEM (Pmode
, addr
);
7606 set_mem_alias_set (addr
, get_frame_alias_set ());
7607 emit_move_insn (return_reg
, addr
);
7611 insn
= restore_gprs (frame_pointer
,
7612 offset
+ cfun_frame_layout
.gprs_offset
7613 + (cfun_frame_layout
.first_restore_gpr
7614 - cfun_frame_layout
.first_save_gpr_slot
)
7616 cfun_frame_layout
.first_restore_gpr
,
7617 cfun_frame_layout
.last_restore_gpr
);
7624 /* Return to caller. */
7626 p
= rtvec_alloc (2);
7628 RTVEC_ELT (p
, 0) = gen_rtx_RETURN (VOIDmode
);
7629 RTVEC_ELT (p
, 1) = gen_rtx_USE (VOIDmode
, return_reg
);
7630 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
7635 /* Return the size in bytes of a function argument of
7636 type TYPE and/or mode MODE. At least one of TYPE or
7637 MODE must be specified. */
7640 s390_function_arg_size (enum machine_mode mode
, tree type
)
7643 return int_size_in_bytes (type
);
7645 /* No type info available for some library calls ... */
7646 if (mode
!= BLKmode
)
7647 return GET_MODE_SIZE (mode
);
7649 /* If we have neither type nor mode, abort */
7653 /* Return true if a function argument of type TYPE and mode MODE
7654 is to be passed in a floating-point register, if available. */
7657 s390_function_arg_float (enum machine_mode mode
, tree type
)
7659 int size
= s390_function_arg_size (mode
, type
);
7663 /* Soft-float changes the ABI: no floating-point registers are used. */
7664 if (TARGET_SOFT_FLOAT
)
7667 /* No type info available for some library calls ... */
7669 return mode
== SFmode
|| mode
== DFmode
|| mode
== SDmode
|| mode
== DDmode
;
7671 /* The ABI says that record types with a single member are treated
7672 just like that member would be. */
7673 while (TREE_CODE (type
) == RECORD_TYPE
)
7675 tree field
, single
= NULL_TREE
;
7677 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
7679 if (TREE_CODE (field
) != FIELD_DECL
)
7682 if (single
== NULL_TREE
)
7683 single
= TREE_TYPE (field
);
7688 if (single
== NULL_TREE
)
7694 return TREE_CODE (type
) == REAL_TYPE
;
7697 /* Return true if a function argument of type TYPE and mode MODE
7698 is to be passed in an integer register, or a pair of integer
7699 registers, if available. */
7702 s390_function_arg_integer (enum machine_mode mode
, tree type
)
7704 int size
= s390_function_arg_size (mode
, type
);
7708 /* No type info available for some library calls ... */
7710 return GET_MODE_CLASS (mode
) == MODE_INT
7711 || (TARGET_SOFT_FLOAT
&& SCALAR_FLOAT_MODE_P (mode
));
7713 /* We accept small integral (and similar) types. */
7714 if (INTEGRAL_TYPE_P (type
)
7715 || POINTER_TYPE_P (type
)
7716 || TREE_CODE (type
) == OFFSET_TYPE
7717 || (TARGET_SOFT_FLOAT
&& TREE_CODE (type
) == REAL_TYPE
))
7720 /* We also accept structs of size 1, 2, 4, 8 that are not
7721 passed in floating-point registers. */
7722 if (AGGREGATE_TYPE_P (type
)
7723 && exact_log2 (size
) >= 0
7724 && !s390_function_arg_float (mode
, type
))
7730 /* Return 1 if a function argument of type TYPE and mode MODE
7731 is to be passed by reference. The ABI specifies that only
7732 structures of size 1, 2, 4, or 8 bytes are passed by value,
7733 all other structures (and complex numbers) are passed by
7737 s390_pass_by_reference (CUMULATIVE_ARGS
*ca ATTRIBUTE_UNUSED
,
7738 enum machine_mode mode
, tree type
,
7739 bool named ATTRIBUTE_UNUSED
)
7741 int size
= s390_function_arg_size (mode
, type
);
7747 if (AGGREGATE_TYPE_P (type
) && exact_log2 (size
) < 0)
7750 if (TREE_CODE (type
) == COMPLEX_TYPE
7751 || TREE_CODE (type
) == VECTOR_TYPE
)
7758 /* Update the data in CUM to advance over an argument of mode MODE and
7759 data type TYPE. (TYPE is null for libcalls where that information
7760 may not be available.). The boolean NAMED specifies whether the
7761 argument is a named argument (as opposed to an unnamed argument
7762 matching an ellipsis). */
7765 s390_function_arg_advance (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
,
7766 tree type
, int named ATTRIBUTE_UNUSED
)
7768 if (s390_function_arg_float (mode
, type
))
7772 else if (s390_function_arg_integer (mode
, type
))
7774 int size
= s390_function_arg_size (mode
, type
);
7775 cum
->gprs
+= ((size
+ UNITS_PER_WORD
-1) / UNITS_PER_WORD
);
7781 /* Define where to put the arguments to a function.
7782 Value is zero to push the argument on the stack,
7783 or a hard register in which to store the argument.
7785 MODE is the argument's machine mode.
7786 TYPE is the data type of the argument (as a tree).
7787 This is null for libcalls where that information may
7789 CUM is a variable of type CUMULATIVE_ARGS which gives info about
7790 the preceding args and about the function being called.
7791 NAMED is nonzero if this argument is a named parameter
7792 (otherwise it is an extra parameter matching an ellipsis).
7794 On S/390, we use general purpose registers 2 through 6 to
7795 pass integer, pointer, and certain structure arguments, and
7796 floating point registers 0 and 2 (0, 2, 4, and 6 on 64-bit)
7797 to pass floating point arguments. All remaining arguments
7798 are pushed to the stack. */
7801 s390_function_arg (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
, tree type
,
7802 int named ATTRIBUTE_UNUSED
)
7804 if (s390_function_arg_float (mode
, type
))
7806 if (cum
->fprs
+ 1 > FP_ARG_NUM_REG
)
7809 return gen_rtx_REG (mode
, cum
->fprs
+ 16);
7811 else if (s390_function_arg_integer (mode
, type
))
7813 int size
= s390_function_arg_size (mode
, type
);
7814 int n_gprs
= (size
+ UNITS_PER_WORD
-1) / UNITS_PER_WORD
;
7816 if (cum
->gprs
+ n_gprs
> GP_ARG_NUM_REG
)
7819 return gen_rtx_REG (mode
, cum
->gprs
+ 2);
7822 /* After the real arguments, expand_call calls us once again
7823 with a void_type_node type. Whatever we return here is
7824 passed as operand 2 to the call expanders.
7826 We don't need this feature ... */
7827 else if (type
== void_type_node
)
7833 /* Return true if return values of type TYPE should be returned
7834 in a memory buffer whose address is passed by the caller as
7835 hidden first argument. */
7838 s390_return_in_memory (tree type
, tree fundecl ATTRIBUTE_UNUSED
)
7840 /* We accept small integral (and similar) types. */
7841 if (INTEGRAL_TYPE_P (type
)
7842 || POINTER_TYPE_P (type
)
7843 || TREE_CODE (type
) == OFFSET_TYPE
7844 || TREE_CODE (type
) == REAL_TYPE
)
7845 return int_size_in_bytes (type
) > 8;
7847 /* Aggregates and similar constructs are always returned
7849 if (AGGREGATE_TYPE_P (type
)
7850 || TREE_CODE (type
) == COMPLEX_TYPE
7851 || TREE_CODE (type
) == VECTOR_TYPE
)
7854 /* ??? We get called on all sorts of random stuff from
7855 aggregate_value_p. We can't abort, but it's not clear
7856 what's safe to return. Pretend it's a struct I guess. */
7860 /* Define where to return a (scalar) value of type TYPE.
7861 If TYPE is null, define where to return a (scalar)
7862 value of mode MODE from a libcall. */
7865 s390_function_value (tree type
, enum machine_mode mode
)
7869 int unsignedp
= TYPE_UNSIGNED (type
);
7870 mode
= promote_mode (type
, TYPE_MODE (type
), &unsignedp
, 1);
7873 gcc_assert (GET_MODE_CLASS (mode
) == MODE_INT
|| SCALAR_FLOAT_MODE_P (mode
));
7874 gcc_assert (GET_MODE_SIZE (mode
) <= 8);
7876 if (TARGET_HARD_FLOAT
&& SCALAR_FLOAT_MODE_P (mode
))
7877 return gen_rtx_REG (mode
, 16);
7879 return gen_rtx_REG (mode
, 2);
7883 /* Create and return the va_list datatype.
7885 On S/390, va_list is an array type equivalent to
7887 typedef struct __va_list_tag
7891 void *__overflow_arg_area;
7892 void *__reg_save_area;
7895 where __gpr and __fpr hold the number of general purpose
7896 or floating point arguments used up to now, respectively,
7897 __overflow_arg_area points to the stack location of the
7898 next argument passed on the stack, and __reg_save_area
7899 always points to the start of the register area in the
7900 call frame of the current function. The function prologue
7901 saves all registers used for argument passing into this
7902 area if the function uses variable arguments. */
7905 s390_build_builtin_va_list (void)
7907 tree f_gpr
, f_fpr
, f_ovf
, f_sav
, record
, type_decl
;
7909 record
= lang_hooks
.types
.make_type (RECORD_TYPE
);
7912 build_decl (TYPE_DECL
, get_identifier ("__va_list_tag"), record
);
7914 f_gpr
= build_decl (FIELD_DECL
, get_identifier ("__gpr"),
7915 long_integer_type_node
);
7916 f_fpr
= build_decl (FIELD_DECL
, get_identifier ("__fpr"),
7917 long_integer_type_node
);
7918 f_ovf
= build_decl (FIELD_DECL
, get_identifier ("__overflow_arg_area"),
7920 f_sav
= build_decl (FIELD_DECL
, get_identifier ("__reg_save_area"),
7923 va_list_gpr_counter_field
= f_gpr
;
7924 va_list_fpr_counter_field
= f_fpr
;
7926 DECL_FIELD_CONTEXT (f_gpr
) = record
;
7927 DECL_FIELD_CONTEXT (f_fpr
) = record
;
7928 DECL_FIELD_CONTEXT (f_ovf
) = record
;
7929 DECL_FIELD_CONTEXT (f_sav
) = record
;
7931 TREE_CHAIN (record
) = type_decl
;
7932 TYPE_NAME (record
) = type_decl
;
7933 TYPE_FIELDS (record
) = f_gpr
;
7934 TREE_CHAIN (f_gpr
) = f_fpr
;
7935 TREE_CHAIN (f_fpr
) = f_ovf
;
7936 TREE_CHAIN (f_ovf
) = f_sav
;
7938 layout_type (record
);
7940 /* The correct type is an array type of one element. */
7941 return build_array_type (record
, build_index_type (size_zero_node
));
7944 /* Implement va_start by filling the va_list structure VALIST.
7945 STDARG_P is always true, and ignored.
7946 NEXTARG points to the first anonymous stack argument.
7948 The following global variables are used to initialize
7949 the va_list structure:
7951 current_function_args_info:
7952 holds number of gprs and fprs used for named arguments.
7953 current_function_arg_offset_rtx:
7954 holds the offset of the first anonymous stack argument
7955 (relative to the virtual arg pointer). */
7958 s390_va_start (tree valist
, rtx nextarg ATTRIBUTE_UNUSED
)
7960 HOST_WIDE_INT n_gpr
, n_fpr
;
7962 tree f_gpr
, f_fpr
, f_ovf
, f_sav
;
7963 tree gpr
, fpr
, ovf
, sav
, t
;
7965 f_gpr
= TYPE_FIELDS (TREE_TYPE (va_list_type_node
));
7966 f_fpr
= TREE_CHAIN (f_gpr
);
7967 f_ovf
= TREE_CHAIN (f_fpr
);
7968 f_sav
= TREE_CHAIN (f_ovf
);
7970 valist
= build_va_arg_indirect_ref (valist
);
7971 gpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_gpr
), valist
, f_gpr
, NULL_TREE
);
7972 fpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_fpr
), valist
, f_fpr
, NULL_TREE
);
7973 ovf
= build3 (COMPONENT_REF
, TREE_TYPE (f_ovf
), valist
, f_ovf
, NULL_TREE
);
7974 sav
= build3 (COMPONENT_REF
, TREE_TYPE (f_sav
), valist
, f_sav
, NULL_TREE
);
7976 /* Count number of gp and fp argument registers used. */
7978 n_gpr
= current_function_args_info
.gprs
;
7979 n_fpr
= current_function_args_info
.fprs
;
7981 if (cfun
->va_list_gpr_size
)
7983 t
= build2 (GIMPLE_MODIFY_STMT
, TREE_TYPE (gpr
), gpr
,
7984 build_int_cst (NULL_TREE
, n_gpr
));
7985 TREE_SIDE_EFFECTS (t
) = 1;
7986 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
7989 if (cfun
->va_list_fpr_size
)
7991 t
= build2 (GIMPLE_MODIFY_STMT
, TREE_TYPE (fpr
), fpr
,
7992 build_int_cst (NULL_TREE
, n_fpr
));
7993 TREE_SIDE_EFFECTS (t
) = 1;
7994 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
7997 /* Find the overflow area. */
7998 if (n_gpr
+ cfun
->va_list_gpr_size
> GP_ARG_NUM_REG
7999 || n_fpr
+ cfun
->va_list_fpr_size
> FP_ARG_NUM_REG
)
8001 t
= make_tree (TREE_TYPE (ovf
), virtual_incoming_args_rtx
);
8003 off
= INTVAL (current_function_arg_offset_rtx
);
8004 off
= off
< 0 ? 0 : off
;
8005 if (TARGET_DEBUG_ARG
)
8006 fprintf (stderr
, "va_start: n_gpr = %d, n_fpr = %d off %d\n",
8007 (int)n_gpr
, (int)n_fpr
, off
);
8009 t
= build2 (PLUS_EXPR
, TREE_TYPE (ovf
), t
, build_int_cst (NULL_TREE
, off
));
8011 t
= build2 (GIMPLE_MODIFY_STMT
, TREE_TYPE (ovf
), ovf
, t
);
8012 TREE_SIDE_EFFECTS (t
) = 1;
8013 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
8016 /* Find the register save area. */
8017 if ((cfun
->va_list_gpr_size
&& n_gpr
< GP_ARG_NUM_REG
)
8018 || (cfun
->va_list_fpr_size
&& n_fpr
< FP_ARG_NUM_REG
))
8020 t
= make_tree (TREE_TYPE (sav
), return_address_pointer_rtx
);
8021 t
= build2 (PLUS_EXPR
, TREE_TYPE (sav
), t
,
8022 build_int_cst (NULL_TREE
, -RETURN_REGNUM
* UNITS_PER_WORD
));
8024 t
= build2 (GIMPLE_MODIFY_STMT
, TREE_TYPE (sav
), sav
, t
);
8025 TREE_SIDE_EFFECTS (t
) = 1;
8026 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
8030 /* Implement va_arg by updating the va_list structure
8031 VALIST as required to retrieve an argument of type
8032 TYPE, and returning that argument.
8034 Generates code equivalent to:
8036 if (integral value) {
8037 if (size <= 4 && args.gpr < 5 ||
8038 size > 4 && args.gpr < 4 )
8039 ret = args.reg_save_area[args.gpr+8]
8041 ret = *args.overflow_arg_area++;
8042 } else if (float value) {
8044 ret = args.reg_save_area[args.fpr+64]
8046 ret = *args.overflow_arg_area++;
8047 } else if (aggregate value) {
8049 ret = *args.reg_save_area[args.gpr]
8051 ret = **args.overflow_arg_area++;
8055 s390_gimplify_va_arg (tree valist
, tree type
, tree
*pre_p
,
8056 tree
*post_p ATTRIBUTE_UNUSED
)
8058 tree f_gpr
, f_fpr
, f_ovf
, f_sav
;
8059 tree gpr
, fpr
, ovf
, sav
, reg
, t
, u
;
8060 int indirect_p
, size
, n_reg
, sav_ofs
, sav_scale
, max_reg
;
8061 tree lab_false
, lab_over
, addr
;
8063 f_gpr
= TYPE_FIELDS (TREE_TYPE (va_list_type_node
));
8064 f_fpr
= TREE_CHAIN (f_gpr
);
8065 f_ovf
= TREE_CHAIN (f_fpr
);
8066 f_sav
= TREE_CHAIN (f_ovf
);
8068 valist
= build_va_arg_indirect_ref (valist
);
8069 gpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_gpr
), valist
, f_gpr
, NULL_TREE
);
8070 fpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_fpr
), valist
, f_fpr
, NULL_TREE
);
8071 ovf
= build3 (COMPONENT_REF
, TREE_TYPE (f_ovf
), valist
, f_ovf
, NULL_TREE
);
8072 sav
= build3 (COMPONENT_REF
, TREE_TYPE (f_sav
), valist
, f_sav
, NULL_TREE
);
8074 size
= int_size_in_bytes (type
);
8076 if (pass_by_reference (NULL
, TYPE_MODE (type
), type
, false))
8078 if (TARGET_DEBUG_ARG
)
8080 fprintf (stderr
, "va_arg: aggregate type");
8084 /* Aggregates are passed by reference. */
8089 /* kernel stack layout on 31 bit: It is assumed here that no padding
8090 will be added by s390_frame_info because for va_args always an even
8091 number of gprs has to be saved r15-r2 = 14 regs. */
8092 sav_ofs
= 2 * UNITS_PER_WORD
;
8093 sav_scale
= UNITS_PER_WORD
;
8094 size
= UNITS_PER_WORD
;
8095 max_reg
= GP_ARG_NUM_REG
- n_reg
;
8097 else if (s390_function_arg_float (TYPE_MODE (type
), type
))
8099 if (TARGET_DEBUG_ARG
)
8101 fprintf (stderr
, "va_arg: float type");
8105 /* FP args go in FP registers, if present. */
8109 sav_ofs
= 16 * UNITS_PER_WORD
;
8111 max_reg
= FP_ARG_NUM_REG
- n_reg
;
8115 if (TARGET_DEBUG_ARG
)
8117 fprintf (stderr
, "va_arg: other type");
8121 /* Otherwise into GP registers. */
8124 n_reg
= (size
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
8126 /* kernel stack layout on 31 bit: It is assumed here that no padding
8127 will be added by s390_frame_info because for va_args always an even
8128 number of gprs has to be saved r15-r2 = 14 regs. */
8129 sav_ofs
= 2 * UNITS_PER_WORD
;
8131 if (size
< UNITS_PER_WORD
)
8132 sav_ofs
+= UNITS_PER_WORD
- size
;
8134 sav_scale
= UNITS_PER_WORD
;
8135 max_reg
= GP_ARG_NUM_REG
- n_reg
;
8138 /* Pull the value out of the saved registers ... */
8140 lab_false
= create_artificial_label ();
8141 lab_over
= create_artificial_label ();
8142 addr
= create_tmp_var (ptr_type_node
, "addr");
8143 DECL_POINTER_ALIAS_SET (addr
) = get_varargs_alias_set ();
8145 t
= fold_convert (TREE_TYPE (reg
), size_int (max_reg
));
8146 t
= build2 (GT_EXPR
, boolean_type_node
, reg
, t
);
8147 u
= build1 (GOTO_EXPR
, void_type_node
, lab_false
);
8148 t
= build3 (COND_EXPR
, void_type_node
, t
, u
, NULL_TREE
);
8149 gimplify_and_add (t
, pre_p
);
8151 t
= build2 (PLUS_EXPR
, ptr_type_node
, sav
,
8152 fold_convert (ptr_type_node
, size_int (sav_ofs
)));
8153 u
= build2 (MULT_EXPR
, TREE_TYPE (reg
), reg
,
8154 fold_convert (TREE_TYPE (reg
), size_int (sav_scale
)));
8155 t
= build2 (PLUS_EXPR
, ptr_type_node
, t
, fold_convert (ptr_type_node
, u
));
8157 t
= build2 (GIMPLE_MODIFY_STMT
, void_type_node
, addr
, t
);
8158 gimplify_and_add (t
, pre_p
);
8160 t
= build1 (GOTO_EXPR
, void_type_node
, lab_over
);
8161 gimplify_and_add (t
, pre_p
);
8163 t
= build1 (LABEL_EXPR
, void_type_node
, lab_false
);
8164 append_to_statement_list (t
, pre_p
);
8167 /* ... Otherwise out of the overflow area. */
8170 if (size
< UNITS_PER_WORD
)
8171 t
= build2 (PLUS_EXPR
, ptr_type_node
, t
,
8172 fold_convert (ptr_type_node
, size_int (UNITS_PER_WORD
- size
)));
8174 gimplify_expr (&t
, pre_p
, NULL
, is_gimple_val
, fb_rvalue
);
8176 u
= build2 (GIMPLE_MODIFY_STMT
, void_type_node
, addr
, t
);
8177 gimplify_and_add (u
, pre_p
);
8179 t
= build2 (PLUS_EXPR
, ptr_type_node
, t
,
8180 fold_convert (ptr_type_node
, size_int (size
)));
8181 t
= build2 (GIMPLE_MODIFY_STMT
, ptr_type_node
, ovf
, t
);
8182 gimplify_and_add (t
, pre_p
);
8184 t
= build1 (LABEL_EXPR
, void_type_node
, lab_over
);
8185 append_to_statement_list (t
, pre_p
);
8188 /* Increment register save count. */
8190 u
= build2 (PREINCREMENT_EXPR
, TREE_TYPE (reg
), reg
,
8191 fold_convert (TREE_TYPE (reg
), size_int (n_reg
)));
8192 gimplify_and_add (u
, pre_p
);
8196 t
= build_pointer_type (build_pointer_type (type
));
8197 addr
= fold_convert (t
, addr
);
8198 addr
= build_va_arg_indirect_ref (addr
);
8202 t
= build_pointer_type (type
);
8203 addr
= fold_convert (t
, addr
);
8206 return build_va_arg_indirect_ref (addr
);
8214 S390_BUILTIN_THREAD_POINTER
,
8215 S390_BUILTIN_SET_THREAD_POINTER
,
8220 static unsigned int const code_for_builtin_64
[S390_BUILTIN_max
] = {
8225 static unsigned int const code_for_builtin_31
[S390_BUILTIN_max
] = {
8231 s390_init_builtins (void)
8235 ftype
= build_function_type (ptr_type_node
, void_list_node
);
8236 add_builtin_function ("__builtin_thread_pointer", ftype
,
8237 S390_BUILTIN_THREAD_POINTER
, BUILT_IN_MD
,
8240 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
8241 add_builtin_function ("__builtin_set_thread_pointer", ftype
,
8242 S390_BUILTIN_SET_THREAD_POINTER
, BUILT_IN_MD
,
8246 /* Expand an expression EXP that calls a built-in function,
8247 with result going to TARGET if that's convenient
8248 (and in mode MODE if that's convenient).
8249 SUBTARGET may be used as the target for computing one of EXP's operands.
8250 IGNORE is nonzero if the value is to be ignored. */
8253 s390_expand_builtin (tree exp
, rtx target
, rtx subtarget ATTRIBUTE_UNUSED
,
8254 enum machine_mode mode ATTRIBUTE_UNUSED
,
8255 int ignore ATTRIBUTE_UNUSED
)
8259 unsigned int const *code_for_builtin
=
8260 TARGET_64BIT
? code_for_builtin_64
: code_for_builtin_31
;
8262 tree fndecl
= TREE_OPERAND (CALL_EXPR_FN (exp
), 0);
8263 unsigned int fcode
= DECL_FUNCTION_CODE (fndecl
);
8264 enum insn_code icode
;
8265 rtx op
[MAX_ARGS
], pat
;
8269 call_expr_arg_iterator iter
;
8271 if (fcode
>= S390_BUILTIN_max
)
8272 internal_error ("bad builtin fcode");
8273 icode
= code_for_builtin
[fcode
];
8275 internal_error ("bad builtin fcode");
8277 nonvoid
= TREE_TYPE (TREE_TYPE (fndecl
)) != void_type_node
;
8280 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, exp
)
8282 const struct insn_operand_data
*insn_op
;
8284 if (arg
== error_mark_node
)
8286 if (arity
> MAX_ARGS
)
8289 insn_op
= &insn_data
[icode
].operand
[arity
+ nonvoid
];
8291 op
[arity
] = expand_expr (arg
, NULL_RTX
, insn_op
->mode
, 0);
8293 if (!(*insn_op
->predicate
) (op
[arity
], insn_op
->mode
))
8294 op
[arity
] = copy_to_mode_reg (insn_op
->mode
, op
[arity
]);
8300 enum machine_mode tmode
= insn_data
[icode
].operand
[0].mode
;
8302 || GET_MODE (target
) != tmode
8303 || !(*insn_data
[icode
].operand
[0].predicate
) (target
, tmode
))
8304 target
= gen_reg_rtx (tmode
);
8310 pat
= GEN_FCN (icode
) (target
);
8314 pat
= GEN_FCN (icode
) (target
, op
[0]);
8316 pat
= GEN_FCN (icode
) (op
[0]);
8319 pat
= GEN_FCN (icode
) (target
, op
[0], op
[1]);
8335 /* Output assembly code for the trampoline template to
8338 On S/390, we use gpr 1 internally in the trampoline code;
8339 gpr 0 is used to hold the static chain. */
8342 s390_trampoline_template (FILE *file
)
8345 op
[0] = gen_rtx_REG (Pmode
, 0);
8346 op
[1] = gen_rtx_REG (Pmode
, 1);
8350 output_asm_insn ("basr\t%1,0", op
);
8351 output_asm_insn ("lmg\t%0,%1,14(%1)", op
);
8352 output_asm_insn ("br\t%1", op
);
8353 ASM_OUTPUT_SKIP (file
, (HOST_WIDE_INT
)(TRAMPOLINE_SIZE
- 10));
8357 output_asm_insn ("basr\t%1,0", op
);
8358 output_asm_insn ("lm\t%0,%1,6(%1)", op
);
8359 output_asm_insn ("br\t%1", op
);
8360 ASM_OUTPUT_SKIP (file
, (HOST_WIDE_INT
)(TRAMPOLINE_SIZE
- 8));
8364 /* Emit RTL insns to initialize the variable parts of a trampoline.
8365 FNADDR is an RTX for the address of the function's pure code.
8366 CXT is an RTX for the static chain value for the function. */
8369 s390_initialize_trampoline (rtx addr
, rtx fnaddr
, rtx cxt
)
8371 emit_move_insn (gen_rtx_MEM (Pmode
,
8372 memory_address (Pmode
,
8373 plus_constant (addr
, (TARGET_64BIT
? 16 : 8)))), cxt
);
8374 emit_move_insn (gen_rtx_MEM (Pmode
,
8375 memory_address (Pmode
,
8376 plus_constant (addr
, (TARGET_64BIT
? 24 : 12)))), fnaddr
);
8379 /* Return rtx for 64-bit constant formed from the 32-bit subwords
8380 LOW and HIGH, independent of the host word size. */
8383 s390_gen_rtx_const_DI (int high
, int low
)
8385 #if HOST_BITS_PER_WIDE_INT >= 64
8387 val
= (HOST_WIDE_INT
)high
;
8389 val
|= (HOST_WIDE_INT
)low
;
8391 return GEN_INT (val
);
8393 #if HOST_BITS_PER_WIDE_INT >= 32
8394 return immed_double_const ((HOST_WIDE_INT
)low
, (HOST_WIDE_INT
)high
, DImode
);
8401 /* Output assembler code to FILE to increment profiler label # LABELNO
8402 for profiling a function entry. */
8405 s390_function_profiler (FILE *file
, int labelno
)
8410 ASM_GENERATE_INTERNAL_LABEL (label
, "LP", labelno
);
8412 fprintf (file
, "# function profiler \n");
8414 op
[0] = gen_rtx_REG (Pmode
, RETURN_REGNUM
);
8415 op
[1] = gen_rtx_REG (Pmode
, STACK_POINTER_REGNUM
);
8416 op
[1] = gen_rtx_MEM (Pmode
, plus_constant (op
[1], UNITS_PER_WORD
));
8418 op
[2] = gen_rtx_REG (Pmode
, 1);
8419 op
[3] = gen_rtx_SYMBOL_REF (Pmode
, label
);
8420 SYMBOL_REF_FLAGS (op
[3]) = SYMBOL_FLAG_LOCAL
;
8422 op
[4] = gen_rtx_SYMBOL_REF (Pmode
, "_mcount");
8425 op
[4] = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op
[4]), UNSPEC_PLT
);
8426 op
[4] = gen_rtx_CONST (Pmode
, op
[4]);
8431 output_asm_insn ("stg\t%0,%1", op
);
8432 output_asm_insn ("larl\t%2,%3", op
);
8433 output_asm_insn ("brasl\t%0,%4", op
);
8434 output_asm_insn ("lg\t%0,%1", op
);
8438 op
[6] = gen_label_rtx ();
8440 output_asm_insn ("st\t%0,%1", op
);
8441 output_asm_insn ("bras\t%2,%l6", op
);
8442 output_asm_insn (".long\t%4", op
);
8443 output_asm_insn (".long\t%3", op
);
8444 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[6]));
8445 output_asm_insn ("l\t%0,0(%2)", op
);
8446 output_asm_insn ("l\t%2,4(%2)", op
);
8447 output_asm_insn ("basr\t%0,%0", op
);
8448 output_asm_insn ("l\t%0,%1", op
);
8452 op
[5] = gen_label_rtx ();
8453 op
[6] = gen_label_rtx ();
8455 output_asm_insn ("st\t%0,%1", op
);
8456 output_asm_insn ("bras\t%2,%l6", op
);
8457 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[5]));
8458 output_asm_insn (".long\t%4-%l5", op
);
8459 output_asm_insn (".long\t%3-%l5", op
);
8460 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[6]));
8461 output_asm_insn ("lr\t%0,%2", op
);
8462 output_asm_insn ("a\t%0,0(%2)", op
);
8463 output_asm_insn ("a\t%2,4(%2)", op
);
8464 output_asm_insn ("basr\t%0,%0", op
);
8465 output_asm_insn ("l\t%0,%1", op
);
8469 /* Encode symbol attributes (local vs. global, tls model) of a SYMBOL_REF
8470 into its SYMBOL_REF_FLAGS. */
8473 s390_encode_section_info (tree decl
, rtx rtl
, int first
)
8475 default_encode_section_info (decl
, rtl
, first
);
8477 /* If a variable has a forced alignment to < 2 bytes, mark it with
8478 SYMBOL_FLAG_ALIGN1 to prevent it from being used as LARL operand. */
8479 if (TREE_CODE (decl
) == VAR_DECL
8480 && DECL_USER_ALIGN (decl
) && DECL_ALIGN (decl
) < 16)
8481 SYMBOL_REF_FLAGS (XEXP (rtl
, 0)) |= SYMBOL_FLAG_ALIGN1
;
8484 /* Output thunk to FILE that implements a C++ virtual function call (with
8485 multiple inheritance) to FUNCTION. The thunk adjusts the this pointer
8486 by DELTA, and unless VCALL_OFFSET is zero, applies an additional adjustment
8487 stored at VCALL_OFFSET in the vtable whose address is located at offset 0
8488 relative to the resulting this pointer. */
8491 s390_output_mi_thunk (FILE *file
, tree thunk ATTRIBUTE_UNUSED
,
8492 HOST_WIDE_INT delta
, HOST_WIDE_INT vcall_offset
,
8498 /* Operand 0 is the target function. */
8499 op
[0] = XEXP (DECL_RTL (function
), 0);
8500 if (flag_pic
&& !SYMBOL_REF_LOCAL_P (op
[0]))
8503 op
[0] = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op
[0]),
8504 TARGET_64BIT
? UNSPEC_PLT
: UNSPEC_GOT
);
8505 op
[0] = gen_rtx_CONST (Pmode
, op
[0]);
8508 /* Operand 1 is the 'this' pointer. */
8509 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function
)), function
))
8510 op
[1] = gen_rtx_REG (Pmode
, 3);
8512 op
[1] = gen_rtx_REG (Pmode
, 2);
8514 /* Operand 2 is the delta. */
8515 op
[2] = GEN_INT (delta
);
8517 /* Operand 3 is the vcall_offset. */
8518 op
[3] = GEN_INT (vcall_offset
);
8520 /* Operand 4 is the temporary register. */
8521 op
[4] = gen_rtx_REG (Pmode
, 1);
8523 /* Operands 5 to 8 can be used as labels. */
8529 /* Operand 9 can be used for temporary register. */
8532 /* Generate code. */
8535 /* Setup literal pool pointer if required. */
8536 if ((!DISP_IN_RANGE (delta
)
8537 && !CONST_OK_FOR_K (delta
)
8538 && !CONST_OK_FOR_Os (delta
))
8539 || (!DISP_IN_RANGE (vcall_offset
)
8540 && !CONST_OK_FOR_K (vcall_offset
)
8541 && !CONST_OK_FOR_Os (vcall_offset
)))
8543 op
[5] = gen_label_rtx ();
8544 output_asm_insn ("larl\t%4,%5", op
);
8547 /* Add DELTA to this pointer. */
8550 if (CONST_OK_FOR_J (delta
))
8551 output_asm_insn ("la\t%1,%2(%1)", op
);
8552 else if (DISP_IN_RANGE (delta
))
8553 output_asm_insn ("lay\t%1,%2(%1)", op
);
8554 else if (CONST_OK_FOR_K (delta
))
8555 output_asm_insn ("aghi\t%1,%2", op
);
8556 else if (CONST_OK_FOR_Os (delta
))
8557 output_asm_insn ("agfi\t%1,%2", op
);
8560 op
[6] = gen_label_rtx ();
8561 output_asm_insn ("agf\t%1,%6-%5(%4)", op
);
8565 /* Perform vcall adjustment. */
8568 if (DISP_IN_RANGE (vcall_offset
))
8570 output_asm_insn ("lg\t%4,0(%1)", op
);
8571 output_asm_insn ("ag\t%1,%3(%4)", op
);
8573 else if (CONST_OK_FOR_K (vcall_offset
))
8575 output_asm_insn ("lghi\t%4,%3", op
);
8576 output_asm_insn ("ag\t%4,0(%1)", op
);
8577 output_asm_insn ("ag\t%1,0(%4)", op
);
8579 else if (CONST_OK_FOR_Os (vcall_offset
))
8581 output_asm_insn ("lgfi\t%4,%3", op
);
8582 output_asm_insn ("ag\t%4,0(%1)", op
);
8583 output_asm_insn ("ag\t%1,0(%4)", op
);
8587 op
[7] = gen_label_rtx ();
8588 output_asm_insn ("llgf\t%4,%7-%5(%4)", op
);
8589 output_asm_insn ("ag\t%4,0(%1)", op
);
8590 output_asm_insn ("ag\t%1,0(%4)", op
);
8594 /* Jump to target. */
8595 output_asm_insn ("jg\t%0", op
);
8597 /* Output literal pool if required. */
8600 output_asm_insn (".align\t4", op
);
8601 targetm
.asm_out
.internal_label (file
, "L",
8602 CODE_LABEL_NUMBER (op
[5]));
8606 targetm
.asm_out
.internal_label (file
, "L",
8607 CODE_LABEL_NUMBER (op
[6]));
8608 output_asm_insn (".long\t%2", op
);
8612 targetm
.asm_out
.internal_label (file
, "L",
8613 CODE_LABEL_NUMBER (op
[7]));
8614 output_asm_insn (".long\t%3", op
);
8619 /* Setup base pointer if required. */
8621 || (!DISP_IN_RANGE (delta
)
8622 && !CONST_OK_FOR_K (delta
)
8623 && !CONST_OK_FOR_Os (delta
))
8624 || (!DISP_IN_RANGE (delta
)
8625 && !CONST_OK_FOR_K (vcall_offset
)
8626 && !CONST_OK_FOR_Os (vcall_offset
)))
8628 op
[5] = gen_label_rtx ();
8629 output_asm_insn ("basr\t%4,0", op
);
8630 targetm
.asm_out
.internal_label (file
, "L",
8631 CODE_LABEL_NUMBER (op
[5]));
8634 /* Add DELTA to this pointer. */
8637 if (CONST_OK_FOR_J (delta
))
8638 output_asm_insn ("la\t%1,%2(%1)", op
);
8639 else if (DISP_IN_RANGE (delta
))
8640 output_asm_insn ("lay\t%1,%2(%1)", op
);
8641 else if (CONST_OK_FOR_K (delta
))
8642 output_asm_insn ("ahi\t%1,%2", op
);
8643 else if (CONST_OK_FOR_Os (delta
))
8644 output_asm_insn ("afi\t%1,%2", op
);
8647 op
[6] = gen_label_rtx ();
8648 output_asm_insn ("a\t%1,%6-%5(%4)", op
);
8652 /* Perform vcall adjustment. */
8655 if (CONST_OK_FOR_J (vcall_offset
))
8657 output_asm_insn ("l\t%4,0(%1)", op
);
8658 output_asm_insn ("a\t%1,%3(%4)", op
);
8660 else if (DISP_IN_RANGE (vcall_offset
))
8662 output_asm_insn ("l\t%4,0(%1)", op
);
8663 output_asm_insn ("ay\t%1,%3(%4)", op
);
8665 else if (CONST_OK_FOR_K (vcall_offset
))
8667 output_asm_insn ("lhi\t%4,%3", op
);
8668 output_asm_insn ("a\t%4,0(%1)", op
);
8669 output_asm_insn ("a\t%1,0(%4)", op
);
8671 else if (CONST_OK_FOR_Os (vcall_offset
))
8673 output_asm_insn ("iilf\t%4,%3", op
);
8674 output_asm_insn ("a\t%4,0(%1)", op
);
8675 output_asm_insn ("a\t%1,0(%4)", op
);
8679 op
[7] = gen_label_rtx ();
8680 output_asm_insn ("l\t%4,%7-%5(%4)", op
);
8681 output_asm_insn ("a\t%4,0(%1)", op
);
8682 output_asm_insn ("a\t%1,0(%4)", op
);
8685 /* We had to clobber the base pointer register.
8686 Re-setup the base pointer (with a different base). */
8687 op
[5] = gen_label_rtx ();
8688 output_asm_insn ("basr\t%4,0", op
);
8689 targetm
.asm_out
.internal_label (file
, "L",
8690 CODE_LABEL_NUMBER (op
[5]));
8693 /* Jump to target. */
8694 op
[8] = gen_label_rtx ();
8697 output_asm_insn ("l\t%4,%8-%5(%4)", op
);
8699 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
8700 /* We cannot call through .plt, since .plt requires %r12 loaded. */
8701 else if (flag_pic
== 1)
8703 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
8704 output_asm_insn ("l\t%4,%0(%4)", op
);
8706 else if (flag_pic
== 2)
8708 op
[9] = gen_rtx_REG (Pmode
, 0);
8709 output_asm_insn ("l\t%9,%8-4-%5(%4)", op
);
8710 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
8711 output_asm_insn ("ar\t%4,%9", op
);
8712 output_asm_insn ("l\t%4,0(%4)", op
);
8715 output_asm_insn ("br\t%4", op
);
8717 /* Output literal pool. */
8718 output_asm_insn (".align\t4", op
);
8720 if (nonlocal
&& flag_pic
== 2)
8721 output_asm_insn (".long\t%0", op
);
8724 op
[0] = gen_rtx_SYMBOL_REF (Pmode
, "_GLOBAL_OFFSET_TABLE_");
8725 SYMBOL_REF_FLAGS (op
[0]) = SYMBOL_FLAG_LOCAL
;
8728 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[8]));
8730 output_asm_insn (".long\t%0", op
);
8732 output_asm_insn (".long\t%0-%5", op
);
8736 targetm
.asm_out
.internal_label (file
, "L",
8737 CODE_LABEL_NUMBER (op
[6]));
8738 output_asm_insn (".long\t%2", op
);
8742 targetm
.asm_out
.internal_label (file
, "L",
8743 CODE_LABEL_NUMBER (op
[7]));
8744 output_asm_insn (".long\t%3", op
);
8750 s390_valid_pointer_mode (enum machine_mode mode
)
8752 return (mode
== SImode
|| (TARGET_64BIT
&& mode
== DImode
));
8755 /* Checks whether the given CALL_EXPR would use a caller
8756 saved register. This is used to decide whether sibling call
8757 optimization could be performed on the respective function
8761 s390_call_saved_register_used (tree call_expr
)
8763 CUMULATIVE_ARGS cum
;
8765 enum machine_mode mode
;
8770 INIT_CUMULATIVE_ARGS (cum
, NULL
, NULL
, 0, 0);
8772 for (i
= 0; i
< call_expr_nargs (call_expr
); i
++)
8774 parameter
= CALL_EXPR_ARG (call_expr
, i
);
8775 gcc_assert (parameter
);
8777 /* For an undeclared variable passed as parameter we will get
8778 an ERROR_MARK node here. */
8779 if (TREE_CODE (parameter
) == ERROR_MARK
)
8782 type
= TREE_TYPE (parameter
);
8785 mode
= TYPE_MODE (type
);
8788 if (pass_by_reference (&cum
, mode
, type
, true))
8791 type
= build_pointer_type (type
);
8794 parm_rtx
= s390_function_arg (&cum
, mode
, type
, 0);
8796 s390_function_arg_advance (&cum
, mode
, type
, 0);
8798 if (parm_rtx
&& REG_P (parm_rtx
))
8801 reg
< HARD_REGNO_NREGS (REGNO (parm_rtx
), GET_MODE (parm_rtx
));
8803 if (! call_used_regs
[reg
+ REGNO (parm_rtx
)])
8810 /* Return true if the given call expression can be
8811 turned into a sibling call.
8812 DECL holds the declaration of the function to be called whereas
8813 EXP is the call expression itself. */
8816 s390_function_ok_for_sibcall (tree decl
, tree exp
)
8818 /* The TPF epilogue uses register 1. */
8819 if (TARGET_TPF_PROFILING
)
8822 /* The 31 bit PLT code uses register 12 (GOT pointer - caller saved)
8823 which would have to be restored before the sibcall. */
8824 if (!TARGET_64BIT
&& flag_pic
&& decl
&& !targetm
.binds_local_p (decl
))
8827 /* Register 6 on s390 is available as an argument register but unfortunately
8828 "caller saved". This makes functions needing this register for arguments
8829 not suitable for sibcalls. */
8830 return !s390_call_saved_register_used (exp
);
8833 /* Return the fixed registers used for condition codes. */
8836 s390_fixed_condition_code_regs (unsigned int *p1
, unsigned int *p2
)
8839 *p2
= INVALID_REGNUM
;
8844 /* This function is used by the call expanders of the machine description.
8845 It emits the call insn itself together with the necessary operations
8846 to adjust the target address and returns the emitted insn.
8847 ADDR_LOCATION is the target address rtx
8848 TLS_CALL the location of the thread-local symbol
8849 RESULT_REG the register where the result of the call should be stored
8850 RETADDR_REG the register where the return address should be stored
8851 If this parameter is NULL_RTX the call is considered
8852 to be a sibling call. */
8855 s390_emit_call (rtx addr_location
, rtx tls_call
, rtx result_reg
,
8858 bool plt_call
= false;
8864 /* Direct function calls need special treatment. */
8865 if (GET_CODE (addr_location
) == SYMBOL_REF
)
8867 /* When calling a global routine in PIC mode, we must
8868 replace the symbol itself with the PLT stub. */
8869 if (flag_pic
&& !SYMBOL_REF_LOCAL_P (addr_location
))
8871 addr_location
= gen_rtx_UNSPEC (Pmode
,
8872 gen_rtvec (1, addr_location
),
8874 addr_location
= gen_rtx_CONST (Pmode
, addr_location
);
8878 /* Unless we can use the bras(l) insn, force the
8879 routine address into a register. */
8880 if (!TARGET_SMALL_EXEC
&& !TARGET_CPU_ZARCH
)
8883 addr_location
= legitimize_pic_address (addr_location
, 0);
8885 addr_location
= force_reg (Pmode
, addr_location
);
8889 /* If it is already an indirect call or the code above moved the
8890 SYMBOL_REF to somewhere else make sure the address can be found in
8892 if (retaddr_reg
== NULL_RTX
8893 && GET_CODE (addr_location
) != SYMBOL_REF
8896 emit_move_insn (gen_rtx_REG (Pmode
, SIBCALL_REGNUM
), addr_location
);
8897 addr_location
= gen_rtx_REG (Pmode
, SIBCALL_REGNUM
);
8900 addr_location
= gen_rtx_MEM (QImode
, addr_location
);
8901 call
= gen_rtx_CALL (VOIDmode
, addr_location
, const0_rtx
);
8903 if (result_reg
!= NULL_RTX
)
8904 call
= gen_rtx_SET (VOIDmode
, result_reg
, call
);
8906 if (retaddr_reg
!= NULL_RTX
)
8908 clobber
= gen_rtx_CLOBBER (VOIDmode
, retaddr_reg
);
8910 if (tls_call
!= NULL_RTX
)
8911 vec
= gen_rtvec (3, call
, clobber
,
8912 gen_rtx_USE (VOIDmode
, tls_call
));
8914 vec
= gen_rtvec (2, call
, clobber
);
8916 call
= gen_rtx_PARALLEL (VOIDmode
, vec
);
8919 insn
= emit_call_insn (call
);
8921 /* 31-bit PLT stubs and tls calls use the GOT register implicitly. */
8922 if ((!TARGET_64BIT
&& plt_call
) || tls_call
!= NULL_RTX
)
8924 /* s390_function_ok_for_sibcall should
8925 have denied sibcalls in this case. */
8926 gcc_assert (retaddr_reg
!= NULL_RTX
);
8928 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), pic_offset_table_rtx
);
8933 /* Implement CONDITIONAL_REGISTER_USAGE. */
8936 s390_conditional_register_usage (void)
8942 fixed_regs
[PIC_OFFSET_TABLE_REGNUM
] = 1;
8943 call_used_regs
[PIC_OFFSET_TABLE_REGNUM
] = 1;
8945 if (TARGET_CPU_ZARCH
)
8947 fixed_regs
[BASE_REGNUM
] = 0;
8948 call_used_regs
[BASE_REGNUM
] = 0;
8949 fixed_regs
[RETURN_REGNUM
] = 0;
8950 call_used_regs
[RETURN_REGNUM
] = 0;
8954 for (i
= 24; i
< 32; i
++)
8955 call_used_regs
[i
] = call_really_used_regs
[i
] = 0;
8959 for (i
= 18; i
< 20; i
++)
8960 call_used_regs
[i
] = call_really_used_regs
[i
] = 0;
8963 if (TARGET_SOFT_FLOAT
)
8965 for (i
= 16; i
< 32; i
++)
8966 call_used_regs
[i
] = fixed_regs
[i
] = 1;
8970 /* Corresponding function to eh_return expander. */
8972 static GTY(()) rtx s390_tpf_eh_return_symbol
;
8974 s390_emit_tpf_eh_return (rtx target
)
8978 if (!s390_tpf_eh_return_symbol
)
8979 s390_tpf_eh_return_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "__tpf_eh_return");
8981 reg
= gen_rtx_REG (Pmode
, 2);
8983 emit_move_insn (reg
, target
);
8984 insn
= s390_emit_call (s390_tpf_eh_return_symbol
, NULL_RTX
, reg
,
8985 gen_rtx_REG (Pmode
, RETURN_REGNUM
));
8986 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), reg
);
8988 emit_move_insn (EH_RETURN_HANDLER_RTX
, reg
);
8991 /* Rework the prologue/epilogue to avoid saving/restoring
8992 registers unnecessarily. */
8995 s390_optimize_prologue (void)
8997 rtx insn
, new_insn
, next_insn
;
8999 /* Do a final recompute of the frame-related data. */
9001 s390_update_frame_layout ();
9003 /* If all special registers are in fact used, there's nothing we
9004 can do, so no point in walking the insn list. */
9006 if (cfun_frame_layout
.first_save_gpr
<= BASE_REGNUM
9007 && cfun_frame_layout
.last_save_gpr
>= BASE_REGNUM
9008 && (TARGET_CPU_ZARCH
9009 || (cfun_frame_layout
.first_save_gpr
<= RETURN_REGNUM
9010 && cfun_frame_layout
.last_save_gpr
>= RETURN_REGNUM
)))
9013 /* Search for prologue/epilogue insns and replace them. */
9015 for (insn
= get_insns (); insn
; insn
= next_insn
)
9017 int first
, last
, off
;
9018 rtx set
, base
, offset
;
9020 next_insn
= NEXT_INSN (insn
);
9022 if (GET_CODE (insn
) != INSN
)
9025 if (GET_CODE (PATTERN (insn
)) == PARALLEL
9026 && store_multiple_operation (PATTERN (insn
), VOIDmode
))
9028 set
= XVECEXP (PATTERN (insn
), 0, 0);
9029 first
= REGNO (SET_SRC (set
));
9030 last
= first
+ XVECLEN (PATTERN (insn
), 0) - 1;
9031 offset
= const0_rtx
;
9032 base
= eliminate_constant_term (XEXP (SET_DEST (set
), 0), &offset
);
9033 off
= INTVAL (offset
);
9035 if (GET_CODE (base
) != REG
|| off
< 0)
9037 if (cfun_frame_layout
.first_save_gpr
!= -1
9038 && (cfun_frame_layout
.first_save_gpr
< first
9039 || cfun_frame_layout
.last_save_gpr
> last
))
9041 if (REGNO (base
) != STACK_POINTER_REGNUM
9042 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
9044 if (first
> BASE_REGNUM
|| last
< BASE_REGNUM
)
9047 if (cfun_frame_layout
.first_save_gpr
!= -1)
9049 new_insn
= save_gprs (base
,
9050 off
+ (cfun_frame_layout
.first_save_gpr
9051 - first
) * UNITS_PER_WORD
,
9052 cfun_frame_layout
.first_save_gpr
,
9053 cfun_frame_layout
.last_save_gpr
);
9054 new_insn
= emit_insn_before (new_insn
, insn
);
9055 INSN_ADDRESSES_NEW (new_insn
, -1);
9062 if (cfun_frame_layout
.first_save_gpr
== -1
9063 && GET_CODE (PATTERN (insn
)) == SET
9064 && GET_CODE (SET_SRC (PATTERN (insn
))) == REG
9065 && (REGNO (SET_SRC (PATTERN (insn
))) == BASE_REGNUM
9066 || (!TARGET_CPU_ZARCH
9067 && REGNO (SET_SRC (PATTERN (insn
))) == RETURN_REGNUM
))
9068 && GET_CODE (SET_DEST (PATTERN (insn
))) == MEM
)
9070 set
= PATTERN (insn
);
9071 first
= REGNO (SET_SRC (set
));
9072 offset
= const0_rtx
;
9073 base
= eliminate_constant_term (XEXP (SET_DEST (set
), 0), &offset
);
9074 off
= INTVAL (offset
);
9076 if (GET_CODE (base
) != REG
|| off
< 0)
9078 if (REGNO (base
) != STACK_POINTER_REGNUM
9079 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
9086 if (GET_CODE (PATTERN (insn
)) == PARALLEL
9087 && load_multiple_operation (PATTERN (insn
), VOIDmode
))
9089 set
= XVECEXP (PATTERN (insn
), 0, 0);
9090 first
= REGNO (SET_DEST (set
));
9091 last
= first
+ XVECLEN (PATTERN (insn
), 0) - 1;
9092 offset
= const0_rtx
;
9093 base
= eliminate_constant_term (XEXP (SET_SRC (set
), 0), &offset
);
9094 off
= INTVAL (offset
);
9096 if (GET_CODE (base
) != REG
|| off
< 0)
9098 if (cfun_frame_layout
.first_restore_gpr
!= -1
9099 && (cfun_frame_layout
.first_restore_gpr
< first
9100 || cfun_frame_layout
.last_restore_gpr
> last
))
9102 if (REGNO (base
) != STACK_POINTER_REGNUM
9103 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
9105 if (first
> BASE_REGNUM
|| last
< BASE_REGNUM
)
9108 if (cfun_frame_layout
.first_restore_gpr
!= -1)
9110 new_insn
= restore_gprs (base
,
9111 off
+ (cfun_frame_layout
.first_restore_gpr
9112 - first
) * UNITS_PER_WORD
,
9113 cfun_frame_layout
.first_restore_gpr
,
9114 cfun_frame_layout
.last_restore_gpr
);
9115 new_insn
= emit_insn_before (new_insn
, insn
);
9116 INSN_ADDRESSES_NEW (new_insn
, -1);
9123 if (cfun_frame_layout
.first_restore_gpr
== -1
9124 && GET_CODE (PATTERN (insn
)) == SET
9125 && GET_CODE (SET_DEST (PATTERN (insn
))) == REG
9126 && (REGNO (SET_DEST (PATTERN (insn
))) == BASE_REGNUM
9127 || (!TARGET_CPU_ZARCH
9128 && REGNO (SET_DEST (PATTERN (insn
))) == RETURN_REGNUM
))
9129 && GET_CODE (SET_SRC (PATTERN (insn
))) == MEM
)
9131 set
= PATTERN (insn
);
9132 first
= REGNO (SET_DEST (set
));
9133 offset
= const0_rtx
;
9134 base
= eliminate_constant_term (XEXP (SET_SRC (set
), 0), &offset
);
9135 off
= INTVAL (offset
);
9137 if (GET_CODE (base
) != REG
|| off
< 0)
9139 if (REGNO (base
) != STACK_POINTER_REGNUM
9140 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
9149 /* Perform machine-dependent processing. */
9154 bool pool_overflow
= false;
9156 /* Make sure all splits have been performed; splits after
9157 machine_dependent_reorg might confuse insn length counts. */
9158 split_all_insns_noflow ();
9160 /* From here on decomposed literal pool addresses must be accepted. */
9161 cfun
->machine
->decomposed_literal_pool_addresses_ok_p
= true;
9163 /* Install the main literal pool and the associated base
9164 register load insns.
9166 In addition, there are two problematic situations we need
9169 - the literal pool might be > 4096 bytes in size, so that
9170 some of its elements cannot be directly accessed
9172 - a branch target might be > 64K away from the branch, so that
9173 it is not possible to use a PC-relative instruction.
9175 To fix those, we split the single literal pool into multiple
9176 pool chunks, reloading the pool base register at various
9177 points throughout the function to ensure it always points to
9178 the pool chunk the following code expects, and / or replace
9179 PC-relative branches by absolute branches.
9181 However, the two problems are interdependent: splitting the
9182 literal pool can move a branch further away from its target,
9183 causing the 64K limit to overflow, and on the other hand,
9184 replacing a PC-relative branch by an absolute branch means
9185 we need to put the branch target address into the literal
9186 pool, possibly causing it to overflow.
9188 So, we loop trying to fix up both problems until we manage
9189 to satisfy both conditions at the same time. Note that the
9190 loop is guaranteed to terminate as every pass of the loop
9191 strictly decreases the total number of PC-relative branches
9192 in the function. (This is not completely true as there
9193 might be branch-over-pool insns introduced by chunkify_start.
9194 Those never need to be split however.) */
9198 struct constant_pool
*pool
= NULL
;
9200 /* Collect the literal pool. */
9203 pool
= s390_mainpool_start ();
9205 pool_overflow
= true;
9208 /* If literal pool overflowed, start to chunkify it. */
9210 pool
= s390_chunkify_start ();
9212 /* Split out-of-range branches. If this has created new
9213 literal pool entries, cancel current chunk list and
9214 recompute it. zSeries machines have large branch
9215 instructions, so we never need to split a branch. */
9216 if (!TARGET_CPU_ZARCH
&& s390_split_branches ())
9219 s390_chunkify_cancel (pool
);
9221 s390_mainpool_cancel (pool
);
9226 /* If we made it up to here, both conditions are satisfied.
9227 Finish up literal pool related changes. */
9229 s390_chunkify_finish (pool
);
9231 s390_mainpool_finish (pool
);
9233 /* We're done splitting branches. */
9234 cfun
->machine
->split_branches_pending_p
= false;
9238 /* Generate out-of-pool execute target insns. */
9239 if (TARGET_CPU_ZARCH
)
9241 rtx insn
, label
, target
;
9243 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
9245 label
= s390_execute_label (insn
);
9249 gcc_assert (label
!= const0_rtx
);
9251 target
= emit_label (XEXP (label
, 0));
9252 INSN_ADDRESSES_NEW (target
, -1);
9254 target
= emit_insn (s390_execute_target (insn
));
9255 INSN_ADDRESSES_NEW (target
, -1);
9259 /* Try to optimize prologue and epilogue further. */
9260 s390_optimize_prologue ();
9264 /* Initialize GCC target structure. */
9266 #undef TARGET_ASM_ALIGNED_HI_OP
9267 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
9268 #undef TARGET_ASM_ALIGNED_DI_OP
9269 #define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
9270 #undef TARGET_ASM_INTEGER
9271 #define TARGET_ASM_INTEGER s390_assemble_integer
9273 #undef TARGET_ASM_OPEN_PAREN
9274 #define TARGET_ASM_OPEN_PAREN ""
9276 #undef TARGET_ASM_CLOSE_PAREN
9277 #define TARGET_ASM_CLOSE_PAREN ""
9279 #undef TARGET_DEFAULT_TARGET_FLAGS
9280 #define TARGET_DEFAULT_TARGET_FLAGS (TARGET_DEFAULT | MASK_FUSED_MADD)
9281 #undef TARGET_HANDLE_OPTION
9282 #define TARGET_HANDLE_OPTION s390_handle_option
9284 #undef TARGET_ENCODE_SECTION_INFO
9285 #define TARGET_ENCODE_SECTION_INFO s390_encode_section_info
9288 #undef TARGET_HAVE_TLS
9289 #define TARGET_HAVE_TLS true
9291 #undef TARGET_CANNOT_FORCE_CONST_MEM
9292 #define TARGET_CANNOT_FORCE_CONST_MEM s390_cannot_force_const_mem
9294 #undef TARGET_DELEGITIMIZE_ADDRESS
9295 #define TARGET_DELEGITIMIZE_ADDRESS s390_delegitimize_address
9297 #undef TARGET_RETURN_IN_MEMORY
9298 #define TARGET_RETURN_IN_MEMORY s390_return_in_memory
9300 #undef TARGET_INIT_BUILTINS
9301 #define TARGET_INIT_BUILTINS s390_init_builtins
9302 #undef TARGET_EXPAND_BUILTIN
9303 #define TARGET_EXPAND_BUILTIN s390_expand_builtin
9305 #undef TARGET_ASM_OUTPUT_MI_THUNK
9306 #define TARGET_ASM_OUTPUT_MI_THUNK s390_output_mi_thunk
9307 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
9308 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
9310 #undef TARGET_SCHED_ADJUST_PRIORITY
9311 #define TARGET_SCHED_ADJUST_PRIORITY s390_adjust_priority
9312 #undef TARGET_SCHED_ISSUE_RATE
9313 #define TARGET_SCHED_ISSUE_RATE s390_issue_rate
9314 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
9315 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD s390_first_cycle_multipass_dfa_lookahead
9317 #undef TARGET_CANNOT_COPY_INSN_P
9318 #define TARGET_CANNOT_COPY_INSN_P s390_cannot_copy_insn_p
9319 #undef TARGET_RTX_COSTS
9320 #define TARGET_RTX_COSTS s390_rtx_costs
9321 #undef TARGET_ADDRESS_COST
9322 #define TARGET_ADDRESS_COST s390_address_cost
9324 #undef TARGET_MACHINE_DEPENDENT_REORG
9325 #define TARGET_MACHINE_DEPENDENT_REORG s390_reorg
9327 #undef TARGET_VALID_POINTER_MODE
9328 #define TARGET_VALID_POINTER_MODE s390_valid_pointer_mode
9330 #undef TARGET_BUILD_BUILTIN_VA_LIST
9331 #define TARGET_BUILD_BUILTIN_VA_LIST s390_build_builtin_va_list
9332 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
9333 #define TARGET_GIMPLIFY_VA_ARG_EXPR s390_gimplify_va_arg
9335 #undef TARGET_PROMOTE_FUNCTION_ARGS
9336 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
9337 #undef TARGET_PROMOTE_FUNCTION_RETURN
9338 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
9339 #undef TARGET_PASS_BY_REFERENCE
9340 #define TARGET_PASS_BY_REFERENCE s390_pass_by_reference
9342 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
9343 #define TARGET_FUNCTION_OK_FOR_SIBCALL s390_function_ok_for_sibcall
9345 #undef TARGET_FIXED_CONDITION_CODE_REGS
9346 #define TARGET_FIXED_CONDITION_CODE_REGS s390_fixed_condition_code_regs
9348 #undef TARGET_CC_MODES_COMPATIBLE
9349 #define TARGET_CC_MODES_COMPATIBLE s390_cc_modes_compatible
9351 #undef TARGET_INVALID_WITHIN_DOLOOP
9352 #define TARGET_INVALID_WITHIN_DOLOOP hook_constcharptr_rtx_null
9355 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
9356 #define TARGET_ASM_OUTPUT_DWARF_DTPREL s390_output_dwarf_dtprel
9359 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
9360 #undef TARGET_MANGLE_FUNDAMENTAL_TYPE
9361 #define TARGET_MANGLE_FUNDAMENTAL_TYPE s390_mangle_fundamental_type
9364 #undef TARGET_SCALAR_MODE_SUPPORTED_P
9365 #define TARGET_SCALAR_MODE_SUPPORTED_P s390_scalar_mode_supported_p
9367 struct gcc_target targetm
= TARGET_INITIALIZER
;
9369 #include "gt-s390.h"