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 jump instruction to TARGET. If COND is NULL_RTX, emit an
784 unconditional jump, else a conditional jump under condition COND. */
787 s390_emit_jump (rtx target
, rtx cond
)
791 target
= gen_rtx_LABEL_REF (VOIDmode
, target
);
793 target
= gen_rtx_IF_THEN_ELSE (VOIDmode
, cond
, target
, pc_rtx
);
795 insn
= gen_rtx_SET (VOIDmode
, pc_rtx
, target
);
796 emit_jump_insn (insn
);
799 /* Return branch condition mask to implement a branch
800 specified by CODE. Return -1 for invalid comparisons. */
803 s390_branch_condition_mask (rtx code
)
805 const int CC0
= 1 << 3;
806 const int CC1
= 1 << 2;
807 const int CC2
= 1 << 1;
808 const int CC3
= 1 << 0;
810 gcc_assert (GET_CODE (XEXP (code
, 0)) == REG
);
811 gcc_assert (REGNO (XEXP (code
, 0)) == CC_REGNUM
);
812 gcc_assert (XEXP (code
, 1) == const0_rtx
);
814 switch (GET_MODE (XEXP (code
, 0)))
818 switch (GET_CODE (code
))
821 case NE
: return CC1
| CC2
| CC3
;
827 switch (GET_CODE (code
))
830 case NE
: return CC0
| CC2
| CC3
;
836 switch (GET_CODE (code
))
839 case NE
: return CC0
| CC1
| CC3
;
845 switch (GET_CODE (code
))
848 case NE
: return CC0
| CC1
| CC2
;
854 switch (GET_CODE (code
))
856 case EQ
: return CC0
| CC2
;
857 case NE
: return CC1
| CC3
;
863 switch (GET_CODE (code
))
865 case LTU
: return CC2
| CC3
; /* carry */
866 case GEU
: return CC0
| CC1
; /* no carry */
872 switch (GET_CODE (code
))
874 case GTU
: return CC0
| CC1
; /* borrow */
875 case LEU
: return CC2
| CC3
; /* no borrow */
881 switch (GET_CODE (code
))
883 case EQ
: return CC0
| CC2
;
884 case NE
: return CC1
| CC3
;
885 case LTU
: return CC1
;
886 case GTU
: return CC3
;
887 case LEU
: return CC1
| CC2
;
888 case GEU
: return CC2
| CC3
;
893 switch (GET_CODE (code
))
896 case NE
: return CC1
| CC2
| CC3
;
897 case LTU
: return CC1
;
898 case GTU
: return CC2
;
899 case LEU
: return CC0
| CC1
;
900 case GEU
: return CC0
| CC2
;
906 switch (GET_CODE (code
))
909 case NE
: return CC2
| CC1
| CC3
;
910 case LTU
: return CC2
;
911 case GTU
: return CC1
;
912 case LEU
: return CC0
| CC2
;
913 case GEU
: return CC0
| CC1
;
919 switch (GET_CODE (code
))
922 case NE
: return CC1
| CC2
| CC3
;
923 case LT
: return CC1
| CC3
;
925 case LE
: return CC0
| CC1
| CC3
;
926 case GE
: return CC0
| CC2
;
932 switch (GET_CODE (code
))
935 case NE
: return CC1
| CC2
| CC3
;
937 case GT
: return CC2
| CC3
;
938 case LE
: return CC0
| CC1
;
939 case GE
: return CC0
| CC2
| CC3
;
945 switch (GET_CODE (code
))
948 case NE
: return CC1
| CC2
| CC3
;
951 case LE
: return CC0
| CC1
;
952 case GE
: return CC0
| CC2
;
953 case UNORDERED
: return CC3
;
954 case ORDERED
: return CC0
| CC1
| CC2
;
955 case UNEQ
: return CC0
| CC3
;
956 case UNLT
: return CC1
| CC3
;
957 case UNGT
: return CC2
| CC3
;
958 case UNLE
: return CC0
| CC1
| CC3
;
959 case UNGE
: return CC0
| CC2
| CC3
;
960 case LTGT
: return CC1
| CC2
;
966 switch (GET_CODE (code
))
969 case NE
: return CC2
| CC1
| CC3
;
972 case LE
: return CC0
| CC2
;
973 case GE
: return CC0
| CC1
;
974 case UNORDERED
: return CC3
;
975 case ORDERED
: return CC0
| CC2
| CC1
;
976 case UNEQ
: return CC0
| CC3
;
977 case UNLT
: return CC2
| CC3
;
978 case UNGT
: return CC1
| CC3
;
979 case UNLE
: return CC0
| CC2
| CC3
;
980 case UNGE
: return CC0
| CC1
| CC3
;
981 case LTGT
: return CC2
| CC1
;
991 /* If INV is false, return assembler mnemonic string to implement
992 a branch specified by CODE. If INV is true, return mnemonic
993 for the corresponding inverted branch. */
996 s390_branch_condition_mnemonic (rtx code
, int inv
)
998 static const char *const mnemonic
[16] =
1000 NULL
, "o", "h", "nle",
1001 "l", "nhe", "lh", "ne",
1002 "e", "nlh", "he", "nl",
1003 "le", "nh", "no", NULL
1006 int mask
= s390_branch_condition_mask (code
);
1007 gcc_assert (mask
>= 0);
1012 gcc_assert (mask
>= 1 && mask
<= 14);
1014 return mnemonic
[mask
];
1017 /* Return the part of op which has a value different from def.
1018 The size of the part is determined by mode.
1019 Use this function only if you already know that op really
1020 contains such a part. */
1022 unsigned HOST_WIDE_INT
1023 s390_extract_part (rtx op
, enum machine_mode mode
, int def
)
1025 unsigned HOST_WIDE_INT value
= 0;
1026 int max_parts
= HOST_BITS_PER_WIDE_INT
/ GET_MODE_BITSIZE (mode
);
1027 int part_bits
= GET_MODE_BITSIZE (mode
);
1028 unsigned HOST_WIDE_INT part_mask
1029 = ((unsigned HOST_WIDE_INT
)1 << part_bits
) - 1;
1032 for (i
= 0; i
< max_parts
; i
++)
1035 value
= (unsigned HOST_WIDE_INT
) INTVAL (op
);
1037 value
>>= part_bits
;
1039 if ((value
& part_mask
) != (def
& part_mask
))
1040 return value
& part_mask
;
1046 /* If OP is an integer constant of mode MODE with exactly one
1047 part of mode PART_MODE unequal to DEF, return the number of that
1048 part. Otherwise, return -1. */
1051 s390_single_part (rtx op
,
1052 enum machine_mode mode
,
1053 enum machine_mode part_mode
,
1056 unsigned HOST_WIDE_INT value
= 0;
1057 int n_parts
= GET_MODE_SIZE (mode
) / GET_MODE_SIZE (part_mode
);
1058 unsigned HOST_WIDE_INT part_mask
1059 = ((unsigned HOST_WIDE_INT
)1 << GET_MODE_BITSIZE (part_mode
)) - 1;
1062 if (GET_CODE (op
) != CONST_INT
)
1065 for (i
= 0; i
< n_parts
; i
++)
1068 value
= (unsigned HOST_WIDE_INT
) INTVAL (op
);
1070 value
>>= GET_MODE_BITSIZE (part_mode
);
1072 if ((value
& part_mask
) != (def
& part_mask
))
1080 return part
== -1 ? -1 : n_parts
- 1 - part
;
1083 /* Check whether we can (and want to) split a double-word
1084 move in mode MODE from SRC to DST into two single-word
1085 moves, moving the subword FIRST_SUBWORD first. */
1088 s390_split_ok_p (rtx dst
, rtx src
, enum machine_mode mode
, int first_subword
)
1090 /* Floating point registers cannot be split. */
1091 if (FP_REG_P (src
) || FP_REG_P (dst
))
1094 /* We don't need to split if operands are directly accessible. */
1095 if (s_operand (src
, mode
) || s_operand (dst
, mode
))
1098 /* Non-offsettable memory references cannot be split. */
1099 if ((GET_CODE (src
) == MEM
&& !offsettable_memref_p (src
))
1100 || (GET_CODE (dst
) == MEM
&& !offsettable_memref_p (dst
)))
1103 /* Moving the first subword must not clobber a register
1104 needed to move the second subword. */
1105 if (register_operand (dst
, mode
))
1107 rtx subreg
= operand_subword (dst
, first_subword
, 0, mode
);
1108 if (reg_overlap_mentioned_p (subreg
, src
))
1115 /* Return true if it can be proven that [MEM1, MEM1 + SIZE]
1116 and [MEM2, MEM2 + SIZE] do overlap and false
1120 s390_overlap_p (rtx mem1
, rtx mem2
, HOST_WIDE_INT size
)
1122 rtx addr1
, addr2
, addr_delta
;
1123 HOST_WIDE_INT delta
;
1125 if (GET_CODE (mem1
) != MEM
|| GET_CODE (mem2
) != MEM
)
1131 addr1
= XEXP (mem1
, 0);
1132 addr2
= XEXP (mem2
, 0);
1134 addr_delta
= simplify_binary_operation (MINUS
, Pmode
, addr2
, addr1
);
1136 /* This overlapping check is used by peepholes merging memory block operations.
1137 Overlapping operations would otherwise be recognized by the S/390 hardware
1138 and would fall back to a slower implementation. Allowing overlapping
1139 operations would lead to slow code but not to wrong code. Therefore we are
1140 somewhat optimistic if we cannot prove that the memory blocks are
1142 That's why we return false here although this may accept operations on
1143 overlapping memory areas. */
1144 if (!addr_delta
|| GET_CODE (addr_delta
) != CONST_INT
)
1147 delta
= INTVAL (addr_delta
);
1150 || (delta
> 0 && delta
< size
)
1151 || (delta
< 0 && -delta
< size
))
1157 /* Check whether the address of memory reference MEM2 equals exactly
1158 the address of memory reference MEM1 plus DELTA. Return true if
1159 we can prove this to be the case, false otherwise. */
1162 s390_offset_p (rtx mem1
, rtx mem2
, rtx delta
)
1164 rtx addr1
, addr2
, addr_delta
;
1166 if (GET_CODE (mem1
) != MEM
|| GET_CODE (mem2
) != MEM
)
1169 addr1
= XEXP (mem1
, 0);
1170 addr2
= XEXP (mem2
, 0);
1172 addr_delta
= simplify_binary_operation (MINUS
, Pmode
, addr2
, addr1
);
1173 if (!addr_delta
|| !rtx_equal_p (addr_delta
, delta
))
1179 /* Expand logical operator CODE in mode MODE with operands OPERANDS. */
1182 s390_expand_logical_operator (enum rtx_code code
, enum machine_mode mode
,
1185 enum machine_mode wmode
= mode
;
1186 rtx dst
= operands
[0];
1187 rtx src1
= operands
[1];
1188 rtx src2
= operands
[2];
1191 /* If we cannot handle the operation directly, use a temp register. */
1192 if (!s390_logical_operator_ok_p (operands
))
1193 dst
= gen_reg_rtx (mode
);
1195 /* QImode and HImode patterns make sense only if we have a destination
1196 in memory. Otherwise perform the operation in SImode. */
1197 if ((mode
== QImode
|| mode
== HImode
) && GET_CODE (dst
) != MEM
)
1200 /* Widen operands if required. */
1203 if (GET_CODE (dst
) == SUBREG
1204 && (tem
= simplify_subreg (wmode
, dst
, mode
, 0)) != 0)
1206 else if (REG_P (dst
))
1207 dst
= gen_rtx_SUBREG (wmode
, dst
, 0);
1209 dst
= gen_reg_rtx (wmode
);
1211 if (GET_CODE (src1
) == SUBREG
1212 && (tem
= simplify_subreg (wmode
, src1
, mode
, 0)) != 0)
1214 else if (GET_MODE (src1
) != VOIDmode
)
1215 src1
= gen_rtx_SUBREG (wmode
, force_reg (mode
, src1
), 0);
1217 if (GET_CODE (src2
) == SUBREG
1218 && (tem
= simplify_subreg (wmode
, src2
, mode
, 0)) != 0)
1220 else if (GET_MODE (src2
) != VOIDmode
)
1221 src2
= gen_rtx_SUBREG (wmode
, force_reg (mode
, src2
), 0);
1224 /* Emit the instruction. */
1225 op
= gen_rtx_SET (VOIDmode
, dst
, gen_rtx_fmt_ee (code
, wmode
, src1
, src2
));
1226 clob
= gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
1227 emit_insn (gen_rtx_PARALLEL (VOIDmode
, gen_rtvec (2, op
, clob
)));
1229 /* Fix up the destination if needed. */
1230 if (dst
!= operands
[0])
1231 emit_move_insn (operands
[0], gen_lowpart (mode
, dst
));
1234 /* Check whether OPERANDS are OK for a logical operation (AND, IOR, XOR). */
1237 s390_logical_operator_ok_p (rtx
*operands
)
1239 /* If the destination operand is in memory, it needs to coincide
1240 with one of the source operands. After reload, it has to be
1241 the first source operand. */
1242 if (GET_CODE (operands
[0]) == MEM
)
1243 return rtx_equal_p (operands
[0], operands
[1])
1244 || (!reload_completed
&& rtx_equal_p (operands
[0], operands
[2]));
1249 /* Narrow logical operation CODE of memory operand MEMOP with immediate
1250 operand IMMOP to switch from SS to SI type instructions. */
1253 s390_narrow_logical_operator (enum rtx_code code
, rtx
*memop
, rtx
*immop
)
1255 int def
= code
== AND
? -1 : 0;
1259 gcc_assert (GET_CODE (*memop
) == MEM
);
1260 gcc_assert (!MEM_VOLATILE_P (*memop
));
1262 mask
= s390_extract_part (*immop
, QImode
, def
);
1263 part
= s390_single_part (*immop
, GET_MODE (*memop
), QImode
, def
);
1264 gcc_assert (part
>= 0);
1266 *memop
= adjust_address (*memop
, QImode
, part
);
1267 *immop
= gen_int_mode (mask
, QImode
);
1271 /* How to allocate a 'struct machine_function'. */
1273 static struct machine_function
*
1274 s390_init_machine_status (void)
1276 return ggc_alloc_cleared (sizeof (struct machine_function
));
1279 /* Change optimizations to be performed, depending on the
1282 LEVEL is the optimization level specified; 2 if `-O2' is
1283 specified, 1 if `-O' is specified, and 0 if neither is specified.
1285 SIZE is nonzero if `-Os' is specified and zero otherwise. */
1288 optimization_options (int level ATTRIBUTE_UNUSED
, int size ATTRIBUTE_UNUSED
)
1290 /* ??? There are apparently still problems with -fcaller-saves. */
1291 flag_caller_saves
= 0;
1293 /* By default, always emit DWARF-2 unwind info. This allows debugging
1294 without maintaining a stack frame back-chain. */
1295 flag_asynchronous_unwind_tables
= 1;
1297 /* Use MVCLE instructions to decrease code size if requested. */
1299 target_flags
|= MASK_MVCLE
;
1302 /* Return true if ARG is the name of a processor. Set *TYPE and *FLAGS
1303 to the associated processor_type and processor_flags if so. */
1306 s390_handle_arch_option (const char *arg
,
1307 enum processor_type
*type
,
1308 enum processor_flags
*flags
)
1312 const char *const name
; /* processor name or nickname. */
1313 const enum processor_type processor
;
1314 const enum processor_flags flags
;
1316 const processor_alias_table
[] =
1318 {"g5", PROCESSOR_9672_G5
, PF_IEEE_FLOAT
},
1319 {"g6", PROCESSOR_9672_G6
, PF_IEEE_FLOAT
},
1320 {"z900", PROCESSOR_2064_Z900
, PF_IEEE_FLOAT
| PF_ZARCH
},
1321 {"z990", PROCESSOR_2084_Z990
, PF_IEEE_FLOAT
| PF_ZARCH
1322 | PF_LONG_DISPLACEMENT
},
1323 {"z9-109", PROCESSOR_2094_Z9_109
, PF_IEEE_FLOAT
| PF_ZARCH
1324 | PF_LONG_DISPLACEMENT
| PF_EXTIMM
},
1328 for (i
= 0; i
< ARRAY_SIZE (processor_alias_table
); i
++)
1329 if (strcmp (arg
, processor_alias_table
[i
].name
) == 0)
1331 *type
= processor_alias_table
[i
].processor
;
1332 *flags
= processor_alias_table
[i
].flags
;
1338 /* Implement TARGET_HANDLE_OPTION. */
1341 s390_handle_option (size_t code
, const char *arg
, int value ATTRIBUTE_UNUSED
)
1346 return s390_handle_arch_option (arg
, &s390_arch
, &s390_arch_flags
);
1348 case OPT_mstack_guard_
:
1349 if (sscanf (arg
, HOST_WIDE_INT_PRINT_DEC
, &s390_stack_guard
) != 1)
1351 if (exact_log2 (s390_stack_guard
) == -1)
1352 error ("stack guard value must be an exact power of 2");
1355 case OPT_mstack_size_
:
1356 if (sscanf (arg
, HOST_WIDE_INT_PRINT_DEC
, &s390_stack_size
) != 1)
1358 if (exact_log2 (s390_stack_size
) == -1)
1359 error ("stack size must be an exact power of 2");
1363 return s390_handle_arch_option (arg
, &s390_tune
, &s390_tune_flags
);
1365 case OPT_mwarn_framesize_
:
1366 return sscanf (arg
, HOST_WIDE_INT_PRINT_DEC
, &s390_warn_framesize
) == 1;
1374 override_options (void)
1376 /* Set up function hooks. */
1377 init_machine_status
= s390_init_machine_status
;
1379 /* Architecture mode defaults according to ABI. */
1380 if (!(target_flags_explicit
& MASK_ZARCH
))
1383 target_flags
|= MASK_ZARCH
;
1385 target_flags
&= ~MASK_ZARCH
;
1388 /* Determine processor architectural level. */
1389 if (!s390_arch_string
)
1391 s390_arch_string
= TARGET_ZARCH
? "z900" : "g5";
1392 s390_handle_arch_option (s390_arch_string
, &s390_arch
, &s390_arch_flags
);
1395 /* Determine processor to tune for. */
1396 if (s390_tune
== PROCESSOR_max
)
1398 s390_tune
= s390_arch
;
1399 s390_tune_flags
= s390_arch_flags
;
1402 /* Sanity checks. */
1403 if (TARGET_ZARCH
&& !(s390_arch_flags
& PF_ZARCH
))
1404 error ("z/Architecture mode not supported on %s", s390_arch_string
);
1405 if (TARGET_64BIT
&& !TARGET_ZARCH
)
1406 error ("64-bit ABI not supported in ESA/390 mode");
1408 /* Set processor cost function. */
1409 if (s390_tune
== PROCESSOR_2094_Z9_109
)
1410 s390_cost
= &z9_109_cost
;
1411 else if (s390_tune
== PROCESSOR_2084_Z990
)
1412 s390_cost
= &z990_cost
;
1414 s390_cost
= &z900_cost
;
1416 if (TARGET_BACKCHAIN
&& TARGET_PACKED_STACK
&& TARGET_HARD_FLOAT
)
1417 error ("-mbackchain -mpacked-stack -mhard-float are not supported "
1420 if (s390_stack_size
)
1422 if (!s390_stack_guard
)
1423 error ("-mstack-size implies use of -mstack-guard");
1424 else if (s390_stack_guard
>= s390_stack_size
)
1425 error ("stack size must be greater than the stack guard value");
1426 else if (s390_stack_size
> 1 << 16)
1427 error ("stack size must not be greater than 64k");
1429 else if (s390_stack_guard
)
1430 error ("-mstack-guard implies use of -mstack-size");
1432 #ifdef TARGET_DEFAULT_LONG_DOUBLE_128
1433 if (!(target_flags_explicit
& MASK_LONG_DOUBLE_128
))
1434 target_flags
|= MASK_LONG_DOUBLE_128
;
1438 /* Map for smallest class containing reg regno. */
1440 const enum reg_class regclass_map
[FIRST_PSEUDO_REGISTER
] =
1441 { GENERAL_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1442 ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1443 ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1444 ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1445 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1446 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1447 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1448 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1449 ADDR_REGS
, CC_REGS
, ADDR_REGS
, ADDR_REGS
,
1450 ACCESS_REGS
, ACCESS_REGS
1453 /* Return attribute type of insn. */
1455 static enum attr_type
1456 s390_safe_attr_type (rtx insn
)
1458 if (recog_memoized (insn
) >= 0)
1459 return get_attr_type (insn
);
1464 /* Return true if DISP is a valid short displacement. */
1467 s390_short_displacement (rtx disp
)
1469 /* No displacement is OK. */
1473 /* Integer displacement in range. */
1474 if (GET_CODE (disp
) == CONST_INT
)
1475 return INTVAL (disp
) >= 0 && INTVAL (disp
) < 4096;
1477 /* GOT offset is not OK, the GOT can be large. */
1478 if (GET_CODE (disp
) == CONST
1479 && GET_CODE (XEXP (disp
, 0)) == UNSPEC
1480 && (XINT (XEXP (disp
, 0), 1) == UNSPEC_GOT
1481 || XINT (XEXP (disp
, 0), 1) == UNSPEC_GOTNTPOFF
))
1484 /* All other symbolic constants are literal pool references,
1485 which are OK as the literal pool must be small. */
1486 if (GET_CODE (disp
) == CONST
)
1492 /* Decompose a RTL expression ADDR for a memory address into
1493 its components, returned in OUT.
1495 Returns false if ADDR is not a valid memory address, true
1496 otherwise. If OUT is NULL, don't return the components,
1497 but check for validity only.
1499 Note: Only addresses in canonical form are recognized.
1500 LEGITIMIZE_ADDRESS should convert non-canonical forms to the
1501 canonical form so that they will be recognized. */
1504 s390_decompose_address (rtx addr
, struct s390_address
*out
)
1506 HOST_WIDE_INT offset
= 0;
1507 rtx base
= NULL_RTX
;
1508 rtx indx
= NULL_RTX
;
1509 rtx disp
= NULL_RTX
;
1511 bool pointer
= false;
1512 bool base_ptr
= false;
1513 bool indx_ptr
= false;
1514 bool literal_pool
= false;
1516 /* We may need to substitute the literal pool base register into the address
1517 below. However, at this point we do not know which register is going to
1518 be used as base, so we substitute the arg pointer register. This is going
1519 to be treated as holding a pointer below -- it shouldn't be used for any
1521 rtx fake_pool_base
= gen_rtx_REG (Pmode
, ARG_POINTER_REGNUM
);
1523 /* Decompose address into base + index + displacement. */
1525 if (GET_CODE (addr
) == REG
|| GET_CODE (addr
) == UNSPEC
)
1528 else if (GET_CODE (addr
) == PLUS
)
1530 rtx op0
= XEXP (addr
, 0);
1531 rtx op1
= XEXP (addr
, 1);
1532 enum rtx_code code0
= GET_CODE (op0
);
1533 enum rtx_code code1
= GET_CODE (op1
);
1535 if (code0
== REG
|| code0
== UNSPEC
)
1537 if (code1
== REG
|| code1
== UNSPEC
)
1539 indx
= op0
; /* index + base */
1545 base
= op0
; /* base + displacement */
1550 else if (code0
== PLUS
)
1552 indx
= XEXP (op0
, 0); /* index + base + disp */
1553 base
= XEXP (op0
, 1);
1564 disp
= addr
; /* displacement */
1566 /* Extract integer part of displacement. */
1570 if (GET_CODE (disp
) == CONST_INT
)
1572 offset
= INTVAL (disp
);
1575 else if (GET_CODE (disp
) == CONST
1576 && GET_CODE (XEXP (disp
, 0)) == PLUS
1577 && GET_CODE (XEXP (XEXP (disp
, 0), 1)) == CONST_INT
)
1579 offset
= INTVAL (XEXP (XEXP (disp
, 0), 1));
1580 disp
= XEXP (XEXP (disp
, 0), 0);
1584 /* Strip off CONST here to avoid special case tests later. */
1585 if (disp
&& GET_CODE (disp
) == CONST
)
1586 disp
= XEXP (disp
, 0);
1588 /* We can convert literal pool addresses to
1589 displacements by basing them off the base register. */
1590 if (disp
&& GET_CODE (disp
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (disp
))
1592 /* Either base or index must be free to hold the base register. */
1594 base
= fake_pool_base
, literal_pool
= true;
1596 indx
= fake_pool_base
, literal_pool
= true;
1600 /* Mark up the displacement. */
1601 disp
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, disp
),
1602 UNSPEC_LTREL_OFFSET
);
1605 /* Validate base register. */
1608 if (GET_CODE (base
) == UNSPEC
)
1609 switch (XINT (base
, 1))
1613 disp
= gen_rtx_UNSPEC (Pmode
,
1614 gen_rtvec (1, XVECEXP (base
, 0, 0)),
1615 UNSPEC_LTREL_OFFSET
);
1619 base
= XVECEXP (base
, 0, 1);
1622 case UNSPEC_LTREL_BASE
:
1623 if (XVECLEN (base
, 0) == 1)
1624 base
= fake_pool_base
, literal_pool
= true;
1626 base
= XVECEXP (base
, 0, 1);
1634 || (GET_MODE (base
) != SImode
1635 && GET_MODE (base
) != Pmode
))
1638 if (REGNO (base
) == STACK_POINTER_REGNUM
1639 || REGNO (base
) == FRAME_POINTER_REGNUM
1640 || ((reload_completed
|| reload_in_progress
)
1641 && frame_pointer_needed
1642 && REGNO (base
) == HARD_FRAME_POINTER_REGNUM
)
1643 || REGNO (base
) == ARG_POINTER_REGNUM
1645 && REGNO (base
) == PIC_OFFSET_TABLE_REGNUM
))
1646 pointer
= base_ptr
= true;
1648 if ((reload_completed
|| reload_in_progress
)
1649 && base
== cfun
->machine
->base_reg
)
1650 pointer
= base_ptr
= literal_pool
= true;
1653 /* Validate index register. */
1656 if (GET_CODE (indx
) == UNSPEC
)
1657 switch (XINT (indx
, 1))
1661 disp
= gen_rtx_UNSPEC (Pmode
,
1662 gen_rtvec (1, XVECEXP (indx
, 0, 0)),
1663 UNSPEC_LTREL_OFFSET
);
1667 indx
= XVECEXP (indx
, 0, 1);
1670 case UNSPEC_LTREL_BASE
:
1671 if (XVECLEN (indx
, 0) == 1)
1672 indx
= fake_pool_base
, literal_pool
= true;
1674 indx
= XVECEXP (indx
, 0, 1);
1682 || (GET_MODE (indx
) != SImode
1683 && GET_MODE (indx
) != Pmode
))
1686 if (REGNO (indx
) == STACK_POINTER_REGNUM
1687 || REGNO (indx
) == FRAME_POINTER_REGNUM
1688 || ((reload_completed
|| reload_in_progress
)
1689 && frame_pointer_needed
1690 && REGNO (indx
) == HARD_FRAME_POINTER_REGNUM
)
1691 || REGNO (indx
) == ARG_POINTER_REGNUM
1693 && REGNO (indx
) == PIC_OFFSET_TABLE_REGNUM
))
1694 pointer
= indx_ptr
= true;
1696 if ((reload_completed
|| reload_in_progress
)
1697 && indx
== cfun
->machine
->base_reg
)
1698 pointer
= indx_ptr
= literal_pool
= true;
1701 /* Prefer to use pointer as base, not index. */
1702 if (base
&& indx
&& !base_ptr
1703 && (indx_ptr
|| (!REG_POINTER (base
) && REG_POINTER (indx
))))
1710 /* Validate displacement. */
1713 /* If virtual registers are involved, the displacement will change later
1714 anyway as the virtual registers get eliminated. This could make a
1715 valid displacement invalid, but it is more likely to make an invalid
1716 displacement valid, because we sometimes access the register save area
1717 via negative offsets to one of those registers.
1718 Thus we don't check the displacement for validity here. If after
1719 elimination the displacement turns out to be invalid after all,
1720 this is fixed up by reload in any case. */
1721 if (base
!= arg_pointer_rtx
1722 && indx
!= arg_pointer_rtx
1723 && base
!= return_address_pointer_rtx
1724 && indx
!= return_address_pointer_rtx
1725 && base
!= frame_pointer_rtx
1726 && indx
!= frame_pointer_rtx
1727 && base
!= virtual_stack_vars_rtx
1728 && indx
!= virtual_stack_vars_rtx
)
1729 if (!DISP_IN_RANGE (offset
))
1734 /* All the special cases are pointers. */
1737 /* In the small-PIC case, the linker converts @GOT
1738 and @GOTNTPOFF offsets to possible displacements. */
1739 if (GET_CODE (disp
) == UNSPEC
1740 && (XINT (disp
, 1) == UNSPEC_GOT
1741 || XINT (disp
, 1) == UNSPEC_GOTNTPOFF
)
1748 /* Accept chunkified literal pool symbol references. */
1749 else if (cfun
&& cfun
->machine
1750 && cfun
->machine
->decomposed_literal_pool_addresses_ok_p
1751 && GET_CODE (disp
) == MINUS
1752 && GET_CODE (XEXP (disp
, 0)) == LABEL_REF
1753 && GET_CODE (XEXP (disp
, 1)) == LABEL_REF
)
1758 /* Accept literal pool references. */
1759 else if (GET_CODE (disp
) == UNSPEC
1760 && XINT (disp
, 1) == UNSPEC_LTREL_OFFSET
)
1762 orig_disp
= gen_rtx_CONST (Pmode
, disp
);
1765 /* If we have an offset, make sure it does not
1766 exceed the size of the constant pool entry. */
1767 rtx sym
= XVECEXP (disp
, 0, 0);
1768 if (offset
>= GET_MODE_SIZE (get_pool_mode (sym
)))
1771 orig_disp
= plus_constant (orig_disp
, offset
);
1786 out
->disp
= orig_disp
;
1787 out
->pointer
= pointer
;
1788 out
->literal_pool
= literal_pool
;
1794 /* Decompose a RTL expression OP for a shift count into its components,
1795 and return the base register in BASE and the offset in OFFSET.
1797 Return true if OP is a valid shift count, false if not. */
1800 s390_decompose_shift_count (rtx op
, rtx
*base
, HOST_WIDE_INT
*offset
)
1802 HOST_WIDE_INT off
= 0;
1804 /* We can have an integer constant, an address register,
1805 or a sum of the two. */
1806 if (GET_CODE (op
) == CONST_INT
)
1811 if (op
&& GET_CODE (op
) == PLUS
&& GET_CODE (XEXP (op
, 1)) == CONST_INT
)
1813 off
= INTVAL (XEXP (op
, 1));
1816 while (op
&& GET_CODE (op
) == SUBREG
)
1817 op
= SUBREG_REG (op
);
1819 if (op
&& GET_CODE (op
) != REG
)
1831 /* Return true if CODE is a valid address without index. */
1834 s390_legitimate_address_without_index_p (rtx op
)
1836 struct s390_address addr
;
1838 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
1846 /* Return 1 if OP is a valid operand for a C constraint, 0 else. */
1849 s390_extra_constraint_str (rtx op
, int c
, const char * str
)
1851 struct s390_address addr
;
1853 gcc_assert (c
== str
[0]);
1855 /* Check for offsettable variants of memory constraints. */
1858 /* Only accept non-volatile MEMs. */
1859 if (!MEM_P (op
) || MEM_VOLATILE_P (op
))
1862 if ((reload_completed
|| reload_in_progress
)
1863 ? !offsettable_memref_p (op
)
1864 : !offsettable_nonstrict_memref_p (op
))
1870 /* Check for non-literal-pool variants of memory constraints. */
1873 if (GET_CODE (op
) != MEM
)
1875 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
1877 if (addr
.literal_pool
)
1886 if (GET_CODE (op
) != MEM
)
1888 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
1893 if (TARGET_LONG_DISPLACEMENT
)
1895 if (!s390_short_displacement (addr
.disp
))
1901 if (GET_CODE (op
) != MEM
)
1904 if (TARGET_LONG_DISPLACEMENT
)
1906 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
1908 if (!s390_short_displacement (addr
.disp
))
1914 if (!TARGET_LONG_DISPLACEMENT
)
1916 if (GET_CODE (op
) != MEM
)
1918 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
1922 if (s390_short_displacement (addr
.disp
))
1927 if (!TARGET_LONG_DISPLACEMENT
)
1929 if (GET_CODE (op
) != MEM
)
1931 /* Any invalid address here will be fixed up by reload,
1932 so accept it for the most generic constraint. */
1933 if (s390_decompose_address (XEXP (op
, 0), &addr
)
1934 && s390_short_displacement (addr
.disp
))
1939 if (TARGET_LONG_DISPLACEMENT
)
1941 if (!s390_decompose_address (op
, &addr
))
1943 if (!s390_short_displacement (addr
.disp
))
1949 if (!TARGET_LONG_DISPLACEMENT
)
1951 /* Any invalid address here will be fixed up by reload,
1952 so accept it for the most generic constraint. */
1953 if (s390_decompose_address (op
, &addr
)
1954 && s390_short_displacement (addr
.disp
))
1959 /* Simply check for the basic form of a shift count. Reload will
1960 take care of making sure we have a proper base register. */
1961 if (!s390_decompose_shift_count (op
, NULL
, NULL
))
1972 /* Return true if VALUE matches the constraint STR. */
1975 s390_const_double_ok_for_constraint_p (rtx value
,
1979 gcc_assert (c
== str
[0]);
1984 /* The floating point zero constant. */
1985 return (GET_MODE_CLASS (GET_MODE (value
)) == MODE_FLOAT
1986 && value
== CONST0_RTX (GET_MODE (value
)));
1993 /* Return true if VALUE matches the constraint STR. */
1996 s390_const_ok_for_constraint_p (HOST_WIDE_INT value
,
2000 enum machine_mode mode
, part_mode
;
2002 int part
, part_goal
;
2004 gcc_assert (c
== str
[0]);
2009 return (unsigned int)value
< 256;
2012 return (unsigned int)value
< 4096;
2015 return value
>= -32768 && value
< 32768;
2018 return (TARGET_LONG_DISPLACEMENT
?
2019 (value
>= -524288 && value
<= 524287)
2020 : (value
>= 0 && value
<= 4095));
2022 return value
== 2147483647;
2028 part_goal
= str
[1] - '0';
2032 case 'Q': part_mode
= QImode
; break;
2033 case 'H': part_mode
= HImode
; break;
2034 case 'S': part_mode
= SImode
; break;
2040 case 'H': mode
= HImode
; break;
2041 case 'S': mode
= SImode
; break;
2042 case 'D': mode
= DImode
; break;
2048 case '0': def
= 0; break;
2049 case 'F': def
= -1; break;
2053 if (GET_MODE_SIZE (mode
) <= GET_MODE_SIZE (part_mode
))
2056 part
= s390_single_part (GEN_INT (value
), mode
, part_mode
, def
);
2059 if (part_goal
!= -1 && part_goal
!= part
)
2071 return trunc_int_for_mode (value
, SImode
) == value
;
2075 || s390_single_part (GEN_INT (value
), DImode
, SImode
, 0) == 1;
2079 || s390_single_part (GEN_INT (value
), DImode
, SImode
, -1) == 1;
2087 return legitimate_reload_constant_p (GEN_INT (value
));
2096 /* Compute a (partial) cost for rtx X. Return true if the complete
2097 cost has been computed, and false if subexpressions should be
2098 scanned. In either case, *TOTAL contains the cost result.
2099 CODE contains GET_CODE (x), OUTER_CODE contains the code
2100 of the superexpression of x. */
2103 s390_rtx_costs (rtx x
, int code
, int outer_code
, int *total
)
2126 *total
= COSTS_N_INSNS (1);
2131 /* Check for multiply and add. */
2132 if ((GET_MODE (x
) == DFmode
|| GET_MODE (x
) == SFmode
)
2133 && GET_CODE (XEXP (x
, 0)) == MULT
2134 && TARGET_HARD_FLOAT
&& TARGET_IEEE_FLOAT
&& TARGET_FUSED_MADD
)
2136 /* This is the multiply and add case. */
2137 if (GET_MODE (x
) == DFmode
)
2138 *total
= s390_cost
->madbr
;
2140 *total
= s390_cost
->maebr
;
2141 *total
+= rtx_cost (XEXP (XEXP (x
, 0), 0), MULT
)
2142 + rtx_cost (XEXP (XEXP (x
, 0), 1), MULT
)
2143 + rtx_cost (XEXP (x
, 1), code
);
2144 return true; /* Do not do an additional recursive descent. */
2146 *total
= COSTS_N_INSNS (1);
2150 switch (GET_MODE (x
))
2154 rtx left
= XEXP (x
, 0);
2155 rtx right
= XEXP (x
, 1);
2156 if (GET_CODE (right
) == CONST_INT
2157 && CONST_OK_FOR_K (INTVAL (right
)))
2158 *total
= s390_cost
->mhi
;
2159 else if (GET_CODE (left
) == SIGN_EXTEND
)
2160 *total
= s390_cost
->mh
;
2162 *total
= s390_cost
->ms
; /* msr, ms, msy */
2167 rtx left
= XEXP (x
, 0);
2168 rtx right
= XEXP (x
, 1);
2171 if (GET_CODE (right
) == CONST_INT
2172 && CONST_OK_FOR_K (INTVAL (right
)))
2173 *total
= s390_cost
->mghi
;
2174 else if (GET_CODE (left
) == SIGN_EXTEND
)
2175 *total
= s390_cost
->msgf
;
2177 *total
= s390_cost
->msg
; /* msgr, msg */
2179 else /* TARGET_31BIT */
2181 if (GET_CODE (left
) == SIGN_EXTEND
2182 && GET_CODE (right
) == SIGN_EXTEND
)
2183 /* mulsidi case: mr, m */
2184 *total
= s390_cost
->m
;
2185 else if (GET_CODE (left
) == ZERO_EXTEND
2186 && GET_CODE (right
) == ZERO_EXTEND
2187 && TARGET_CPU_ZARCH
)
2188 /* umulsidi case: ml, mlr */
2189 *total
= s390_cost
->ml
;
2191 /* Complex calculation is required. */
2192 *total
= COSTS_N_INSNS (40);
2198 *total
= s390_cost
->mult_df
;
2201 *total
= s390_cost
->mxbr
;
2210 if (GET_MODE (x
) == TImode
) /* 128 bit division */
2211 *total
= s390_cost
->dlgr
;
2212 else if (GET_MODE (x
) == DImode
)
2214 rtx right
= XEXP (x
, 1);
2215 if (GET_CODE (right
) == ZERO_EXTEND
) /* 64 by 32 bit division */
2216 *total
= s390_cost
->dlr
;
2217 else /* 64 by 64 bit division */
2218 *total
= s390_cost
->dlgr
;
2220 else if (GET_MODE (x
) == SImode
) /* 32 bit division */
2221 *total
= s390_cost
->dlr
;
2226 if (GET_MODE (x
) == DImode
)
2228 rtx right
= XEXP (x
, 1);
2229 if (GET_CODE (right
) == ZERO_EXTEND
) /* 64 by 32 bit division */
2231 *total
= s390_cost
->dsgfr
;
2233 *total
= s390_cost
->dr
;
2234 else /* 64 by 64 bit division */
2235 *total
= s390_cost
->dsgr
;
2237 else if (GET_MODE (x
) == SImode
) /* 32 bit division */
2238 *total
= s390_cost
->dlr
;
2239 else if (GET_MODE (x
) == SFmode
)
2241 if (TARGET_IEEE_FLOAT
)
2242 *total
= s390_cost
->debr
;
2243 else /* TARGET_IBM_FLOAT */
2244 *total
= s390_cost
->der
;
2246 else if (GET_MODE (x
) == DFmode
)
2248 if (TARGET_IEEE_FLOAT
)
2249 *total
= s390_cost
->ddbr
;
2250 else /* TARGET_IBM_FLOAT */
2251 *total
= s390_cost
->ddr
;
2253 else if (GET_MODE (x
) == TFmode
)
2255 if (TARGET_IEEE_FLOAT
)
2256 *total
= s390_cost
->dxbr
;
2257 else /* TARGET_IBM_FLOAT */
2258 *total
= s390_cost
->dxr
;
2263 if (GET_MODE (x
) == SFmode
)
2264 *total
= s390_cost
->sqebr
;
2265 else if (GET_MODE (x
) == DFmode
)
2266 *total
= s390_cost
->sqdbr
;
2268 *total
= s390_cost
->sqxbr
;
2273 if (outer_code
== MULT
|| outer_code
== DIV
|| outer_code
== MOD
2274 || outer_code
== PLUS
|| outer_code
== MINUS
2275 || outer_code
== COMPARE
)
2280 *total
= COSTS_N_INSNS (1);
2281 if (GET_CODE (XEXP (x
, 0)) == AND
2282 && GET_CODE (XEXP (x
, 1)) == CONST_INT
2283 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
)
2285 rtx op0
= XEXP (XEXP (x
, 0), 0);
2286 rtx op1
= XEXP (XEXP (x
, 0), 1);
2287 rtx op2
= XEXP (x
, 1);
2289 if (memory_operand (op0
, GET_MODE (op0
))
2290 && s390_tm_ccmode (op1
, op2
, 0) != VOIDmode
)
2292 if (register_operand (op0
, GET_MODE (op0
))
2293 && s390_tm_ccmode (op1
, op2
, 1) != VOIDmode
)
2303 /* Return the cost of an address rtx ADDR. */
2306 s390_address_cost (rtx addr
)
2308 struct s390_address ad
;
2309 if (!s390_decompose_address (addr
, &ad
))
2312 return ad
.indx
? COSTS_N_INSNS (1) + 1 : COSTS_N_INSNS (1);
2315 /* If OP is a SYMBOL_REF of a thread-local symbol, return its TLS mode,
2316 otherwise return 0. */
2319 tls_symbolic_operand (rtx op
)
2321 if (GET_CODE (op
) != SYMBOL_REF
)
2323 return SYMBOL_REF_TLS_MODEL (op
);
2326 /* Split DImode access register reference REG (on 64-bit) into its constituent
2327 low and high parts, and store them into LO and HI. Note that gen_lowpart/
2328 gen_highpart cannot be used as they assume all registers are word-sized,
2329 while our access registers have only half that size. */
2332 s390_split_access_reg (rtx reg
, rtx
*lo
, rtx
*hi
)
2334 gcc_assert (TARGET_64BIT
);
2335 gcc_assert (ACCESS_REG_P (reg
));
2336 gcc_assert (GET_MODE (reg
) == DImode
);
2337 gcc_assert (!(REGNO (reg
) & 1));
2339 *lo
= gen_rtx_REG (SImode
, REGNO (reg
) + 1);
2340 *hi
= gen_rtx_REG (SImode
, REGNO (reg
));
2343 /* Return true if OP contains a symbol reference */
2346 symbolic_reference_mentioned_p (rtx op
)
2351 if (GET_CODE (op
) == SYMBOL_REF
|| GET_CODE (op
) == LABEL_REF
)
2354 fmt
= GET_RTX_FORMAT (GET_CODE (op
));
2355 for (i
= GET_RTX_LENGTH (GET_CODE (op
)) - 1; i
>= 0; i
--)
2361 for (j
= XVECLEN (op
, i
) - 1; j
>= 0; j
--)
2362 if (symbolic_reference_mentioned_p (XVECEXP (op
, i
, j
)))
2366 else if (fmt
[i
] == 'e' && symbolic_reference_mentioned_p (XEXP (op
, i
)))
2373 /* Return true if OP contains a reference to a thread-local symbol. */
2376 tls_symbolic_reference_mentioned_p (rtx op
)
2381 if (GET_CODE (op
) == SYMBOL_REF
)
2382 return tls_symbolic_operand (op
);
2384 fmt
= GET_RTX_FORMAT (GET_CODE (op
));
2385 for (i
= GET_RTX_LENGTH (GET_CODE (op
)) - 1; i
>= 0; i
--)
2391 for (j
= XVECLEN (op
, i
) - 1; j
>= 0; j
--)
2392 if (tls_symbolic_reference_mentioned_p (XVECEXP (op
, i
, j
)))
2396 else if (fmt
[i
] == 'e' && tls_symbolic_reference_mentioned_p (XEXP (op
, i
)))
2404 /* Return true if OP is a legitimate general operand when
2405 generating PIC code. It is given that flag_pic is on
2406 and that OP satisfies CONSTANT_P or is a CONST_DOUBLE. */
2409 legitimate_pic_operand_p (rtx op
)
2411 /* Accept all non-symbolic constants. */
2412 if (!SYMBOLIC_CONST (op
))
2415 /* Reject everything else; must be handled
2416 via emit_symbolic_move. */
2420 /* Returns true if the constant value OP is a legitimate general operand.
2421 It is given that OP satisfies CONSTANT_P or is a CONST_DOUBLE. */
2424 legitimate_constant_p (rtx op
)
2426 /* Accept all non-symbolic constants. */
2427 if (!SYMBOLIC_CONST (op
))
2430 /* Accept immediate LARL operands. */
2431 if (TARGET_CPU_ZARCH
&& larl_operand (op
, VOIDmode
))
2434 /* Thread-local symbols are never legal constants. This is
2435 so that emit_call knows that computing such addresses
2436 might require a function call. */
2437 if (TLS_SYMBOLIC_CONST (op
))
2440 /* In the PIC case, symbolic constants must *not* be
2441 forced into the literal pool. We accept them here,
2442 so that they will be handled by emit_symbolic_move. */
2446 /* All remaining non-PIC symbolic constants are
2447 forced into the literal pool. */
2451 /* Determine if it's legal to put X into the constant pool. This
2452 is not possible if X contains the address of a symbol that is
2453 not constant (TLS) or not known at final link time (PIC). */
2456 s390_cannot_force_const_mem (rtx x
)
2458 switch (GET_CODE (x
))
2462 /* Accept all non-symbolic constants. */
2466 /* Labels are OK iff we are non-PIC. */
2467 return flag_pic
!= 0;
2470 /* 'Naked' TLS symbol references are never OK,
2471 non-TLS symbols are OK iff we are non-PIC. */
2472 if (tls_symbolic_operand (x
))
2475 return flag_pic
!= 0;
2478 return s390_cannot_force_const_mem (XEXP (x
, 0));
2481 return s390_cannot_force_const_mem (XEXP (x
, 0))
2482 || s390_cannot_force_const_mem (XEXP (x
, 1));
2485 switch (XINT (x
, 1))
2487 /* Only lt-relative or GOT-relative UNSPECs are OK. */
2488 case UNSPEC_LTREL_OFFSET
:
2496 case UNSPEC_GOTNTPOFF
:
2497 case UNSPEC_INDNTPOFF
:
2500 /* If the literal pool shares the code section, be put
2501 execute template placeholders into the pool as well. */
2503 return TARGET_CPU_ZARCH
;
2515 /* Returns true if the constant value OP is a legitimate general
2516 operand during and after reload. The difference to
2517 legitimate_constant_p is that this function will not accept
2518 a constant that would need to be forced to the literal pool
2519 before it can be used as operand. */
2522 legitimate_reload_constant_p (rtx op
)
2524 /* Accept la(y) operands. */
2525 if (GET_CODE (op
) == CONST_INT
2526 && DISP_IN_RANGE (INTVAL (op
)))
2529 /* Accept l(g)hi/l(g)fi operands. */
2530 if (GET_CODE (op
) == CONST_INT
2531 && (CONST_OK_FOR_K (INTVAL (op
)) || CONST_OK_FOR_Os (INTVAL (op
))))
2534 /* Accept lliXX operands. */
2536 && GET_CODE (op
) == CONST_INT
2537 && trunc_int_for_mode (INTVAL (op
), word_mode
) == INTVAL (op
)
2538 && s390_single_part (op
, word_mode
, HImode
, 0) >= 0)
2542 && GET_CODE (op
) == CONST_INT
2543 && trunc_int_for_mode (INTVAL (op
), word_mode
) == INTVAL (op
)
2544 && s390_single_part (op
, word_mode
, SImode
, 0) >= 0)
2547 /* Accept larl operands. */
2548 if (TARGET_CPU_ZARCH
2549 && larl_operand (op
, VOIDmode
))
2552 /* Accept lzXX operands. */
2553 if (GET_CODE (op
) == CONST_DOUBLE
2554 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op
, 'G', "G"))
2557 /* Accept double-word operands that can be split. */
2558 if (GET_CODE (op
) == CONST_INT
2559 && trunc_int_for_mode (INTVAL (op
), word_mode
) != INTVAL (op
))
2561 enum machine_mode dword_mode
= word_mode
== SImode
? DImode
: TImode
;
2562 rtx hi
= operand_subword (op
, 0, 0, dword_mode
);
2563 rtx lo
= operand_subword (op
, 1, 0, dword_mode
);
2564 return legitimate_reload_constant_p (hi
)
2565 && legitimate_reload_constant_p (lo
);
2568 /* Everything else cannot be handled without reload. */
2572 /* Given an rtx OP being reloaded into a reg required to be in class CLASS,
2573 return the class of reg to actually use. */
2576 s390_preferred_reload_class (rtx op
, enum reg_class
class)
2578 switch (GET_CODE (op
))
2580 /* Constants we cannot reload must be forced into the
2585 if (legitimate_reload_constant_p (op
))
2590 /* If a symbolic constant or a PLUS is reloaded,
2591 it is most likely being used as an address, so
2592 prefer ADDR_REGS. If 'class' is not a superset
2593 of ADDR_REGS, e.g. FP_REGS, reject this reload. */
2598 if (reg_class_subset_p (ADDR_REGS
, class))
2610 /* Return the register class of a scratch register needed to
2611 load IN into a register of class CLASS in MODE.
2613 We need a temporary when loading a PLUS expression which
2614 is not a legitimate operand of the LOAD ADDRESS instruction. */
2617 s390_secondary_input_reload_class (enum reg_class
class,
2618 enum machine_mode mode
, rtx in
)
2620 if (s390_plus_operand (in
, mode
))
2623 if (reg_classes_intersect_p (FP_REGS
, class)
2625 && GET_CODE (in
) == MEM
2626 && GET_CODE (XEXP (in
, 0)) == PLUS
2627 && GET_CODE (XEXP (XEXP (in
, 0), 1)) == CONST_INT
2628 && !DISP_IN_RANGE (INTVAL (XEXP (XEXP (in
, 0), 1))
2629 + GET_MODE_SIZE (mode
) - 1))
2632 if (reg_classes_intersect_p (CC_REGS
, class))
2633 return GENERAL_REGS
;
2638 /* Return the register class of a scratch register needed to
2639 store a register of class CLASS in MODE into OUT:
2641 We need a temporary when storing a double-word to a
2642 non-offsettable memory address. */
2645 s390_secondary_output_reload_class (enum reg_class
class,
2646 enum machine_mode mode
, rtx out
)
2648 if ((TARGET_64BIT
? (mode
== TImode
|| mode
== TFmode
)
2649 : (mode
== DImode
|| mode
== DFmode
))
2650 && reg_classes_intersect_p (GENERAL_REGS
, class)
2651 && GET_CODE (out
) == MEM
2652 && GET_CODE (XEXP (out
, 0)) == PLUS
2653 && GET_CODE (XEXP (XEXP (out
, 0), 0)) == PLUS
2654 && GET_CODE (XEXP (XEXP (out
, 0), 1)) == CONST_INT
2655 && !DISP_IN_RANGE (INTVAL (XEXP (XEXP (out
, 0), 1))
2656 + GET_MODE_SIZE (mode
) - 1))
2659 if (reg_classes_intersect_p (FP_REGS
, class)
2661 && GET_CODE (out
) == MEM
2662 && GET_CODE (XEXP (out
, 0)) == PLUS
2663 && GET_CODE (XEXP (XEXP (out
, 0), 1)) == CONST_INT
2664 && !DISP_IN_RANGE (INTVAL (XEXP (XEXP (out
, 0), 1))
2665 + GET_MODE_SIZE (mode
) - 1))
2668 if (reg_classes_intersect_p (CC_REGS
, class))
2669 return GENERAL_REGS
;
2674 /* Generate code to load SRC, which is PLUS that is not a
2675 legitimate operand for the LA instruction, into TARGET.
2676 SCRATCH may be used as scratch register. */
2679 s390_expand_plus_operand (rtx target
, rtx src
,
2683 struct s390_address ad
;
2685 /* src must be a PLUS; get its two operands. */
2686 gcc_assert (GET_CODE (src
) == PLUS
);
2687 gcc_assert (GET_MODE (src
) == Pmode
);
2689 /* Check if any of the two operands is already scheduled
2690 for replacement by reload. This can happen e.g. when
2691 float registers occur in an address. */
2692 sum1
= find_replacement (&XEXP (src
, 0));
2693 sum2
= find_replacement (&XEXP (src
, 1));
2694 src
= gen_rtx_PLUS (Pmode
, sum1
, sum2
);
2696 /* If the address is already strictly valid, there's nothing to do. */
2697 if (!s390_decompose_address (src
, &ad
)
2698 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
2699 || (ad
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (ad
.indx
))))
2701 /* Otherwise, one of the operands cannot be an address register;
2702 we reload its value into the scratch register. */
2703 if (true_regnum (sum1
) < 1 || true_regnum (sum1
) > 15)
2705 emit_move_insn (scratch
, sum1
);
2708 if (true_regnum (sum2
) < 1 || true_regnum (sum2
) > 15)
2710 emit_move_insn (scratch
, sum2
);
2714 /* According to the way these invalid addresses are generated
2715 in reload.c, it should never happen (at least on s390) that
2716 *neither* of the PLUS components, after find_replacements
2717 was applied, is an address register. */
2718 if (sum1
== scratch
&& sum2
== scratch
)
2724 src
= gen_rtx_PLUS (Pmode
, sum1
, sum2
);
2727 /* Emit the LOAD ADDRESS pattern. Note that reload of PLUS
2728 is only ever performed on addresses, so we can mark the
2729 sum as legitimate for LA in any case. */
2730 s390_load_address (target
, src
);
2734 /* Return true if ADDR is a valid memory address.
2735 STRICT specifies whether strict register checking applies. */
2738 legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED
,
2739 rtx addr
, int strict
)
2741 struct s390_address ad
;
2742 if (!s390_decompose_address (addr
, &ad
))
2747 if (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
2750 if (ad
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (ad
.indx
)))
2756 && !(REGNO (ad
.base
) >= FIRST_PSEUDO_REGISTER
2757 || REGNO_REG_CLASS (REGNO (ad
.base
)) == ADDR_REGS
))
2761 && !(REGNO (ad
.indx
) >= FIRST_PSEUDO_REGISTER
2762 || REGNO_REG_CLASS (REGNO (ad
.indx
)) == ADDR_REGS
))
2768 /* Return true if OP is a valid operand for the LA instruction.
2769 In 31-bit, we need to prove that the result is used as an
2770 address, as LA performs only a 31-bit addition. */
2773 legitimate_la_operand_p (rtx op
)
2775 struct s390_address addr
;
2776 if (!s390_decompose_address (op
, &addr
))
2779 return (TARGET_64BIT
|| addr
.pointer
);
2782 /* Return true if it is valid *and* preferable to use LA to
2783 compute the sum of OP1 and OP2. */
2786 preferred_la_operand_p (rtx op1
, rtx op2
)
2788 struct s390_address addr
;
2790 if (op2
!= const0_rtx
)
2791 op1
= gen_rtx_PLUS (Pmode
, op1
, op2
);
2793 if (!s390_decompose_address (op1
, &addr
))
2795 if (addr
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (addr
.base
)))
2797 if (addr
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (addr
.indx
)))
2800 if (!TARGET_64BIT
&& !addr
.pointer
)
2806 if ((addr
.base
&& REG_P (addr
.base
) && REG_POINTER (addr
.base
))
2807 || (addr
.indx
&& REG_P (addr
.indx
) && REG_POINTER (addr
.indx
)))
2813 /* Emit a forced load-address operation to load SRC into DST.
2814 This will use the LOAD ADDRESS instruction even in situations
2815 where legitimate_la_operand_p (SRC) returns false. */
2818 s390_load_address (rtx dst
, rtx src
)
2821 emit_move_insn (dst
, src
);
2823 emit_insn (gen_force_la_31 (dst
, src
));
2826 /* Return a legitimate reference for ORIG (an address) using the
2827 register REG. If REG is 0, a new pseudo is generated.
2829 There are two types of references that must be handled:
2831 1. Global data references must load the address from the GOT, via
2832 the PIC reg. An insn is emitted to do this load, and the reg is
2835 2. Static data references, constant pool addresses, and code labels
2836 compute the address as an offset from the GOT, whose base is in
2837 the PIC reg. Static data objects have SYMBOL_FLAG_LOCAL set to
2838 differentiate them from global data objects. The returned
2839 address is the PIC reg + an unspec constant.
2841 GO_IF_LEGITIMATE_ADDRESS rejects symbolic references unless the PIC
2842 reg also appears in the address. */
2845 legitimize_pic_address (rtx orig
, rtx reg
)
2851 gcc_assert (!TLS_SYMBOLIC_CONST (addr
));
2853 if (GET_CODE (addr
) == LABEL_REF
2854 || (GET_CODE (addr
) == SYMBOL_REF
&& SYMBOL_REF_LOCAL_P (addr
)))
2856 /* This is a local symbol. */
2857 if (TARGET_CPU_ZARCH
&& larl_operand (addr
, VOIDmode
))
2859 /* Access local symbols PC-relative via LARL.
2860 This is the same as in the non-PIC case, so it is
2861 handled automatically ... */
2865 /* Access local symbols relative to the GOT. */
2867 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
2869 if (reload_in_progress
|| reload_completed
)
2870 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
2872 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTOFF
);
2873 addr
= gen_rtx_CONST (Pmode
, addr
);
2874 addr
= force_const_mem (Pmode
, addr
);
2875 emit_move_insn (temp
, addr
);
2877 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
2880 s390_load_address (reg
, new);
2885 else if (GET_CODE (addr
) == SYMBOL_REF
)
2888 reg
= gen_reg_rtx (Pmode
);
2892 /* Assume GOT offset < 4k. This is handled the same way
2893 in both 31- and 64-bit code (@GOT). */
2895 if (reload_in_progress
|| reload_completed
)
2896 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
2898 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOT
);
2899 new = gen_rtx_CONST (Pmode
, new);
2900 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, new);
2901 new = gen_const_mem (Pmode
, new);
2902 emit_move_insn (reg
, new);
2905 else if (TARGET_CPU_ZARCH
)
2907 /* If the GOT offset might be >= 4k, we determine the position
2908 of the GOT entry via a PC-relative LARL (@GOTENT). */
2910 rtx temp
= gen_reg_rtx (Pmode
);
2912 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTENT
);
2913 new = gen_rtx_CONST (Pmode
, new);
2914 emit_move_insn (temp
, new);
2916 new = gen_const_mem (Pmode
, temp
);
2917 emit_move_insn (reg
, new);
2922 /* If the GOT offset might be >= 4k, we have to load it
2923 from the literal pool (@GOT). */
2925 rtx temp
= gen_reg_rtx (Pmode
);
2927 if (reload_in_progress
|| reload_completed
)
2928 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
2930 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOT
);
2931 addr
= gen_rtx_CONST (Pmode
, addr
);
2932 addr
= force_const_mem (Pmode
, addr
);
2933 emit_move_insn (temp
, addr
);
2935 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
2936 new = gen_const_mem (Pmode
, new);
2937 emit_move_insn (reg
, new);
2943 if (GET_CODE (addr
) == CONST
)
2945 addr
= XEXP (addr
, 0);
2946 if (GET_CODE (addr
) == UNSPEC
)
2948 gcc_assert (XVECLEN (addr
, 0) == 1);
2949 switch (XINT (addr
, 1))
2951 /* If someone moved a GOT-relative UNSPEC
2952 out of the literal pool, force them back in. */
2955 new = force_const_mem (Pmode
, orig
);
2958 /* @GOT is OK as is if small. */
2961 new = force_const_mem (Pmode
, orig
);
2964 /* @GOTENT is OK as is. */
2968 /* @PLT is OK as is on 64-bit, must be converted to
2969 GOT-relative @PLTOFF on 31-bit. */
2971 if (!TARGET_CPU_ZARCH
)
2973 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
2975 if (reload_in_progress
|| reload_completed
)
2976 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
2978 addr
= XVECEXP (addr
, 0, 0);
2979 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
),
2981 addr
= gen_rtx_CONST (Pmode
, addr
);
2982 addr
= force_const_mem (Pmode
, addr
);
2983 emit_move_insn (temp
, addr
);
2985 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
2988 s390_load_address (reg
, new);
2994 /* Everything else cannot happen. */
3000 gcc_assert (GET_CODE (addr
) == PLUS
);
3002 if (GET_CODE (addr
) == PLUS
)
3004 rtx op0
= XEXP (addr
, 0), op1
= XEXP (addr
, 1);
3006 gcc_assert (!TLS_SYMBOLIC_CONST (op0
));
3007 gcc_assert (!TLS_SYMBOLIC_CONST (op1
));
3009 /* Check first to see if this is a constant offset
3010 from a local symbol reference. */
3011 if ((GET_CODE (op0
) == LABEL_REF
3012 || (GET_CODE (op0
) == SYMBOL_REF
&& SYMBOL_REF_LOCAL_P (op0
)))
3013 && GET_CODE (op1
) == CONST_INT
)
3015 if (TARGET_CPU_ZARCH
&& larl_operand (op0
, VOIDmode
))
3017 if (INTVAL (op1
) & 1)
3019 /* LARL can't handle odd offsets, so emit a
3020 pair of LARL and LA. */
3021 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3023 if (!DISP_IN_RANGE (INTVAL (op1
)))
3025 int even
= INTVAL (op1
) - 1;
3026 op0
= gen_rtx_PLUS (Pmode
, op0
, GEN_INT (even
));
3027 op0
= gen_rtx_CONST (Pmode
, op0
);
3031 emit_move_insn (temp
, op0
);
3032 new = gen_rtx_PLUS (Pmode
, temp
, op1
);
3036 s390_load_address (reg
, new);
3042 /* If the offset is even, we can just use LARL.
3043 This will happen automatically. */
3048 /* Access local symbols relative to the GOT. */
3050 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3052 if (reload_in_progress
|| reload_completed
)
3053 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
3055 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op0
),
3057 addr
= gen_rtx_PLUS (Pmode
, addr
, op1
);
3058 addr
= gen_rtx_CONST (Pmode
, addr
);
3059 addr
= force_const_mem (Pmode
, addr
);
3060 emit_move_insn (temp
, addr
);
3062 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3065 s390_load_address (reg
, new);
3071 /* Now, check whether it is a GOT relative symbol plus offset
3072 that was pulled out of the literal pool. Force it back in. */
3074 else if (GET_CODE (op0
) == UNSPEC
3075 && GET_CODE (op1
) == CONST_INT
3076 && XINT (op0
, 1) == UNSPEC_GOTOFF
)
3078 gcc_assert (XVECLEN (op0
, 0) == 1);
3080 new = force_const_mem (Pmode
, orig
);
3083 /* Otherwise, compute the sum. */
3086 base
= legitimize_pic_address (XEXP (addr
, 0), reg
);
3087 new = legitimize_pic_address (XEXP (addr
, 1),
3088 base
== reg
? NULL_RTX
: reg
);
3089 if (GET_CODE (new) == CONST_INT
)
3090 new = plus_constant (base
, INTVAL (new));
3093 if (GET_CODE (new) == PLUS
&& CONSTANT_P (XEXP (new, 1)))
3095 base
= gen_rtx_PLUS (Pmode
, base
, XEXP (new, 0));
3096 new = XEXP (new, 1);
3098 new = gen_rtx_PLUS (Pmode
, base
, new);
3101 if (GET_CODE (new) == CONST
)
3102 new = XEXP (new, 0);
3103 new = force_operand (new, 0);
3110 /* Load the thread pointer into a register. */
3113 s390_get_thread_pointer (void)
3115 rtx tp
= gen_reg_rtx (Pmode
);
3117 emit_move_insn (tp
, gen_rtx_REG (Pmode
, TP_REGNUM
));
3118 mark_reg_pointer (tp
, BITS_PER_WORD
);
3123 /* Emit a tls call insn. The call target is the SYMBOL_REF stored
3124 in s390_tls_symbol which always refers to __tls_get_offset.
3125 The returned offset is written to RESULT_REG and an USE rtx is
3126 generated for TLS_CALL. */
3128 static GTY(()) rtx s390_tls_symbol
;
3131 s390_emit_tls_call_insn (rtx result_reg
, rtx tls_call
)
3135 gcc_assert (flag_pic
);
3137 if (!s390_tls_symbol
)
3138 s390_tls_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "__tls_get_offset");
3140 insn
= s390_emit_call (s390_tls_symbol
, tls_call
, result_reg
,
3141 gen_rtx_REG (Pmode
, RETURN_REGNUM
));
3143 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), result_reg
);
3144 CONST_OR_PURE_CALL_P (insn
) = 1;
3147 /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
3148 this (thread-local) address. REG may be used as temporary. */
3151 legitimize_tls_address (rtx addr
, rtx reg
)
3153 rtx
new, tls_call
, temp
, base
, r2
, insn
;
3155 if (GET_CODE (addr
) == SYMBOL_REF
)
3156 switch (tls_symbolic_operand (addr
))
3158 case TLS_MODEL_GLOBAL_DYNAMIC
:
3160 r2
= gen_rtx_REG (Pmode
, 2);
3161 tls_call
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_TLSGD
);
3162 new = gen_rtx_CONST (Pmode
, tls_call
);
3163 new = force_const_mem (Pmode
, new);
3164 emit_move_insn (r2
, new);
3165 s390_emit_tls_call_insn (r2
, tls_call
);
3166 insn
= get_insns ();
3169 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_NTPOFF
);
3170 temp
= gen_reg_rtx (Pmode
);
3171 emit_libcall_block (insn
, temp
, r2
, new);
3173 new = gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3176 s390_load_address (reg
, new);
3181 case TLS_MODEL_LOCAL_DYNAMIC
:
3183 r2
= gen_rtx_REG (Pmode
, 2);
3184 tls_call
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, const0_rtx
), UNSPEC_TLSLDM
);
3185 new = gen_rtx_CONST (Pmode
, tls_call
);
3186 new = force_const_mem (Pmode
, new);
3187 emit_move_insn (r2
, new);
3188 s390_emit_tls_call_insn (r2
, tls_call
);
3189 insn
= get_insns ();
3192 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, const0_rtx
), UNSPEC_TLSLDM_NTPOFF
);
3193 temp
= gen_reg_rtx (Pmode
);
3194 emit_libcall_block (insn
, temp
, r2
, new);
3196 new = gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3197 base
= gen_reg_rtx (Pmode
);
3198 s390_load_address (base
, new);
3200 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_DTPOFF
);
3201 new = gen_rtx_CONST (Pmode
, new);
3202 new = force_const_mem (Pmode
, new);
3203 temp
= gen_reg_rtx (Pmode
);
3204 emit_move_insn (temp
, new);
3206 new = gen_rtx_PLUS (Pmode
, base
, temp
);
3209 s390_load_address (reg
, new);
3214 case TLS_MODEL_INITIAL_EXEC
:
3217 /* Assume GOT offset < 4k. This is handled the same way
3218 in both 31- and 64-bit code. */
3220 if (reload_in_progress
|| reload_completed
)
3221 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
3223 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTNTPOFF
);
3224 new = gen_rtx_CONST (Pmode
, new);
3225 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, new);
3226 new = gen_const_mem (Pmode
, new);
3227 temp
= gen_reg_rtx (Pmode
);
3228 emit_move_insn (temp
, new);
3230 else if (TARGET_CPU_ZARCH
)
3232 /* If the GOT offset might be >= 4k, we determine the position
3233 of the GOT entry via a PC-relative LARL. */
3235 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_INDNTPOFF
);
3236 new = gen_rtx_CONST (Pmode
, new);
3237 temp
= gen_reg_rtx (Pmode
);
3238 emit_move_insn (temp
, new);
3240 new = gen_const_mem (Pmode
, temp
);
3241 temp
= gen_reg_rtx (Pmode
);
3242 emit_move_insn (temp
, new);
3246 /* If the GOT offset might be >= 4k, we have to load it
3247 from the literal pool. */
3249 if (reload_in_progress
|| reload_completed
)
3250 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
3252 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTNTPOFF
);
3253 new = gen_rtx_CONST (Pmode
, new);
3254 new = force_const_mem (Pmode
, new);
3255 temp
= gen_reg_rtx (Pmode
);
3256 emit_move_insn (temp
, new);
3258 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3259 new = gen_const_mem (Pmode
, new);
3261 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, new, addr
), UNSPEC_TLS_LOAD
);
3262 temp
= gen_reg_rtx (Pmode
);
3263 emit_insn (gen_rtx_SET (Pmode
, temp
, new));
3267 /* In position-dependent code, load the absolute address of
3268 the GOT entry from the literal pool. */
3270 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_INDNTPOFF
);
3271 new = gen_rtx_CONST (Pmode
, new);
3272 new = force_const_mem (Pmode
, new);
3273 temp
= gen_reg_rtx (Pmode
);
3274 emit_move_insn (temp
, new);
3277 new = gen_const_mem (Pmode
, new);
3278 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, new, addr
), UNSPEC_TLS_LOAD
);
3279 temp
= gen_reg_rtx (Pmode
);
3280 emit_insn (gen_rtx_SET (Pmode
, temp
, new));
3283 new = gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3286 s390_load_address (reg
, new);
3291 case TLS_MODEL_LOCAL_EXEC
:
3292 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_NTPOFF
);
3293 new = gen_rtx_CONST (Pmode
, new);
3294 new = force_const_mem (Pmode
, new);
3295 temp
= gen_reg_rtx (Pmode
);
3296 emit_move_insn (temp
, new);
3298 new = gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3301 s390_load_address (reg
, new);
3310 else if (GET_CODE (addr
) == CONST
&& GET_CODE (XEXP (addr
, 0)) == UNSPEC
)
3312 switch (XINT (XEXP (addr
, 0), 1))
3314 case UNSPEC_INDNTPOFF
:
3315 gcc_assert (TARGET_CPU_ZARCH
);
3324 else if (GET_CODE (addr
) == CONST
&& GET_CODE (XEXP (addr
, 0)) == PLUS
3325 && GET_CODE (XEXP (XEXP (addr
, 0), 1)) == CONST_INT
)
3327 new = XEXP (XEXP (addr
, 0), 0);
3328 if (GET_CODE (new) != SYMBOL_REF
)
3329 new = gen_rtx_CONST (Pmode
, new);
3331 new = legitimize_tls_address (new, reg
);
3332 new = plus_constant (new, INTVAL (XEXP (XEXP (addr
, 0), 1)));
3333 new = force_operand (new, 0);
3337 gcc_unreachable (); /* for now ... */
3342 /* Emit insns to move operands[1] into operands[0]. */
3345 emit_symbolic_move (rtx
*operands
)
3347 rtx temp
= no_new_pseudos
? operands
[0] : gen_reg_rtx (Pmode
);
3349 if (GET_CODE (operands
[0]) == MEM
)
3350 operands
[1] = force_reg (Pmode
, operands
[1]);
3351 else if (TLS_SYMBOLIC_CONST (operands
[1]))
3352 operands
[1] = legitimize_tls_address (operands
[1], temp
);
3354 operands
[1] = legitimize_pic_address (operands
[1], temp
);
3357 /* Try machine-dependent ways of modifying an illegitimate address X
3358 to be legitimate. If we find one, return the new, valid address.
3360 OLDX is the address as it was before break_out_memory_refs was called.
3361 In some cases it is useful to look at this to decide what needs to be done.
3363 MODE is the mode of the operand pointed to by X.
3365 When -fpic is used, special handling is needed for symbolic references.
3366 See comments by legitimize_pic_address for details. */
3369 legitimize_address (rtx x
, rtx oldx ATTRIBUTE_UNUSED
,
3370 enum machine_mode mode ATTRIBUTE_UNUSED
)
3372 rtx constant_term
= const0_rtx
;
3374 if (TLS_SYMBOLIC_CONST (x
))
3376 x
= legitimize_tls_address (x
, 0);
3378 if (legitimate_address_p (mode
, x
, FALSE
))
3381 else if (GET_CODE (x
) == PLUS
3382 && (TLS_SYMBOLIC_CONST (XEXP (x
, 0))
3383 || TLS_SYMBOLIC_CONST (XEXP (x
, 1))))
3389 if (SYMBOLIC_CONST (x
)
3390 || (GET_CODE (x
) == PLUS
3391 && (SYMBOLIC_CONST (XEXP (x
, 0))
3392 || SYMBOLIC_CONST (XEXP (x
, 1)))))
3393 x
= legitimize_pic_address (x
, 0);
3395 if (legitimate_address_p (mode
, x
, FALSE
))
3399 x
= eliminate_constant_term (x
, &constant_term
);
3401 /* Optimize loading of large displacements by splitting them
3402 into the multiple of 4K and the rest; this allows the
3403 former to be CSE'd if possible.
3405 Don't do this if the displacement is added to a register
3406 pointing into the stack frame, as the offsets will
3407 change later anyway. */
3409 if (GET_CODE (constant_term
) == CONST_INT
3410 && !TARGET_LONG_DISPLACEMENT
3411 && !DISP_IN_RANGE (INTVAL (constant_term
))
3412 && !(REG_P (x
) && REGNO_PTR_FRAME_P (REGNO (x
))))
3414 HOST_WIDE_INT lower
= INTVAL (constant_term
) & 0xfff;
3415 HOST_WIDE_INT upper
= INTVAL (constant_term
) ^ lower
;
3417 rtx temp
= gen_reg_rtx (Pmode
);
3418 rtx val
= force_operand (GEN_INT (upper
), temp
);
3420 emit_move_insn (temp
, val
);
3422 x
= gen_rtx_PLUS (Pmode
, x
, temp
);
3423 constant_term
= GEN_INT (lower
);
3426 if (GET_CODE (x
) == PLUS
)
3428 if (GET_CODE (XEXP (x
, 0)) == REG
)
3430 rtx temp
= gen_reg_rtx (Pmode
);
3431 rtx val
= force_operand (XEXP (x
, 1), temp
);
3433 emit_move_insn (temp
, val
);
3435 x
= gen_rtx_PLUS (Pmode
, XEXP (x
, 0), temp
);
3438 else if (GET_CODE (XEXP (x
, 1)) == REG
)
3440 rtx temp
= gen_reg_rtx (Pmode
);
3441 rtx val
= force_operand (XEXP (x
, 0), temp
);
3443 emit_move_insn (temp
, val
);
3445 x
= gen_rtx_PLUS (Pmode
, temp
, XEXP (x
, 1));
3449 if (constant_term
!= const0_rtx
)
3450 x
= gen_rtx_PLUS (Pmode
, x
, constant_term
);
3455 /* Try a machine-dependent way of reloading an illegitimate address AD
3456 operand. If we find one, push the reload and and return the new address.
3458 MODE is the mode of the enclosing MEM. OPNUM is the operand number
3459 and TYPE is the reload type of the current reload. */
3462 legitimize_reload_address (rtx ad
, enum machine_mode mode ATTRIBUTE_UNUSED
,
3463 int opnum
, int type
)
3465 if (!optimize
|| TARGET_LONG_DISPLACEMENT
)
3468 if (GET_CODE (ad
) == PLUS
)
3470 rtx tem
= simplify_binary_operation (PLUS
, Pmode
,
3471 XEXP (ad
, 0), XEXP (ad
, 1));
3476 if (GET_CODE (ad
) == PLUS
3477 && GET_CODE (XEXP (ad
, 0)) == REG
3478 && GET_CODE (XEXP (ad
, 1)) == CONST_INT
3479 && !DISP_IN_RANGE (INTVAL (XEXP (ad
, 1))))
3481 HOST_WIDE_INT lower
= INTVAL (XEXP (ad
, 1)) & 0xfff;
3482 HOST_WIDE_INT upper
= INTVAL (XEXP (ad
, 1)) ^ lower
;
3485 cst
= GEN_INT (upper
);
3486 if (!legitimate_reload_constant_p (cst
))
3487 cst
= force_const_mem (Pmode
, cst
);
3489 tem
= gen_rtx_PLUS (Pmode
, XEXP (ad
, 0), cst
);
3490 new = gen_rtx_PLUS (Pmode
, tem
, GEN_INT (lower
));
3492 push_reload (XEXP (tem
, 1), 0, &XEXP (tem
, 1), 0,
3493 BASE_REG_CLASS
, Pmode
, VOIDmode
, 0, 0,
3494 opnum
, (enum reload_type
) type
);
3501 /* Emit code to move LEN bytes from DST to SRC. */
3504 s390_expand_movmem (rtx dst
, rtx src
, rtx len
)
3506 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) >= 0 && INTVAL (len
) <= 256)
3508 if (INTVAL (len
) > 0)
3509 emit_insn (gen_movmem_short (dst
, src
, GEN_INT (INTVAL (len
) - 1)));
3512 else if (TARGET_MVCLE
)
3514 emit_insn (gen_movmem_long (dst
, src
, convert_to_mode (Pmode
, len
, 1)));
3519 rtx dst_addr
, src_addr
, count
, blocks
, temp
;
3520 rtx loop_start_label
= gen_label_rtx ();
3521 rtx loop_end_label
= gen_label_rtx ();
3522 rtx end_label
= gen_label_rtx ();
3523 enum machine_mode mode
;
3525 mode
= GET_MODE (len
);
3526 if (mode
== VOIDmode
)
3529 dst_addr
= gen_reg_rtx (Pmode
);
3530 src_addr
= gen_reg_rtx (Pmode
);
3531 count
= gen_reg_rtx (mode
);
3532 blocks
= gen_reg_rtx (mode
);
3534 convert_move (count
, len
, 1);
3535 emit_cmp_and_jump_insns (count
, const0_rtx
,
3536 EQ
, NULL_RTX
, mode
, 1, end_label
);
3538 emit_move_insn (dst_addr
, force_operand (XEXP (dst
, 0), NULL_RTX
));
3539 emit_move_insn (src_addr
, force_operand (XEXP (src
, 0), NULL_RTX
));
3540 dst
= change_address (dst
, VOIDmode
, dst_addr
);
3541 src
= change_address (src
, VOIDmode
, src_addr
);
3543 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1, 0);
3545 emit_move_insn (count
, temp
);
3547 temp
= expand_binop (mode
, ashr_optab
, count
, GEN_INT (8), blocks
, 1, 0);
3549 emit_move_insn (blocks
, temp
);
3551 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3552 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3554 emit_label (loop_start_label
);
3556 emit_insn (gen_movmem_short (dst
, src
, GEN_INT (255)));
3557 s390_load_address (dst_addr
,
3558 gen_rtx_PLUS (Pmode
, dst_addr
, GEN_INT (256)));
3559 s390_load_address (src_addr
,
3560 gen_rtx_PLUS (Pmode
, src_addr
, GEN_INT (256)));
3562 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1, 0);
3564 emit_move_insn (blocks
, temp
);
3566 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3567 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3569 emit_jump (loop_start_label
);
3570 emit_label (loop_end_label
);
3572 emit_insn (gen_movmem_short (dst
, src
,
3573 convert_to_mode (Pmode
, count
, 1)));
3574 emit_label (end_label
);
3578 /* Emit code to set LEN bytes at DST to VAL.
3579 Make use of clrmem if VAL is zero. */
3582 s390_expand_setmem (rtx dst
, rtx len
, rtx val
)
3584 gcc_assert (GET_CODE (len
) != CONST_INT
|| INTVAL (len
) > 0);
3585 gcc_assert (GET_CODE (val
) == CONST_INT
|| GET_MODE (val
) == QImode
);
3587 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) <= 257)
3589 if (val
== const0_rtx
&& INTVAL (len
) <= 256)
3590 emit_insn (gen_clrmem_short (dst
, GEN_INT (INTVAL (len
) - 1)));
3593 /* Initialize memory by storing the first byte. */
3594 emit_move_insn (adjust_address (dst
, QImode
, 0), val
);
3596 if (INTVAL (len
) > 1)
3598 /* Initiate 1 byte overlap move.
3599 The first byte of DST is propagated through DSTP1.
3600 Prepare a movmem for: DST+1 = DST (length = LEN - 1).
3601 DST is set to size 1 so the rest of the memory location
3602 does not count as source operand. */
3603 rtx dstp1
= adjust_address (dst
, VOIDmode
, 1);
3604 set_mem_size (dst
, const1_rtx
);
3606 emit_insn (gen_movmem_short (dstp1
, dst
,
3607 GEN_INT (INTVAL (len
) - 2)));
3612 else if (TARGET_MVCLE
)
3614 val
= force_not_mem (convert_modes (Pmode
, QImode
, val
, 1));
3615 emit_insn (gen_setmem_long (dst
, convert_to_mode (Pmode
, len
, 1), val
));
3620 rtx dst_addr
, src_addr
, count
, blocks
, temp
, dstp1
= NULL_RTX
;
3621 rtx loop_start_label
= gen_label_rtx ();
3622 rtx loop_end_label
= gen_label_rtx ();
3623 rtx end_label
= gen_label_rtx ();
3624 enum machine_mode mode
;
3626 mode
= GET_MODE (len
);
3627 if (mode
== VOIDmode
)
3630 dst_addr
= gen_reg_rtx (Pmode
);
3631 src_addr
= gen_reg_rtx (Pmode
);
3632 count
= gen_reg_rtx (mode
);
3633 blocks
= gen_reg_rtx (mode
);
3635 convert_move (count
, len
, 1);
3636 emit_cmp_and_jump_insns (count
, const0_rtx
,
3637 EQ
, NULL_RTX
, mode
, 1, end_label
);
3639 emit_move_insn (dst_addr
, force_operand (XEXP (dst
, 0), NULL_RTX
));
3640 dst
= change_address (dst
, VOIDmode
, dst_addr
);
3642 if (val
== const0_rtx
)
3643 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1, 0);
3646 dstp1
= adjust_address (dst
, VOIDmode
, 1);
3647 set_mem_size (dst
, const1_rtx
);
3649 /* Initialize memory by storing the first byte. */
3650 emit_move_insn (adjust_address (dst
, QImode
, 0), val
);
3652 /* If count is 1 we are done. */
3653 emit_cmp_and_jump_insns (count
, const1_rtx
,
3654 EQ
, NULL_RTX
, mode
, 1, end_label
);
3656 temp
= expand_binop (mode
, add_optab
, count
, GEN_INT (-2), count
, 1, 0);
3659 emit_move_insn (count
, temp
);
3661 temp
= expand_binop (mode
, ashr_optab
, count
, GEN_INT (8), blocks
, 1, 0);
3663 emit_move_insn (blocks
, temp
);
3665 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3666 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3668 emit_label (loop_start_label
);
3670 if (val
== const0_rtx
)
3671 emit_insn (gen_clrmem_short (dst
, GEN_INT (255)));
3673 emit_insn (gen_movmem_short (dstp1
, dst
, GEN_INT (255)));
3674 s390_load_address (dst_addr
,
3675 gen_rtx_PLUS (Pmode
, dst_addr
, GEN_INT (256)));
3677 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1, 0);
3679 emit_move_insn (blocks
, temp
);
3681 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3682 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3684 emit_jump (loop_start_label
);
3685 emit_label (loop_end_label
);
3687 if (val
== const0_rtx
)
3688 emit_insn (gen_clrmem_short (dst
, convert_to_mode (Pmode
, count
, 1)));
3690 emit_insn (gen_movmem_short (dstp1
, dst
, convert_to_mode (Pmode
, count
, 1)));
3691 emit_label (end_label
);
3695 /* Emit code to compare LEN bytes at OP0 with those at OP1,
3696 and return the result in TARGET. */
3699 s390_expand_cmpmem (rtx target
, rtx op0
, rtx op1
, rtx len
)
3701 rtx ccreg
= gen_rtx_REG (CCUmode
, CC_REGNUM
);
3704 /* As the result of CMPINT is inverted compared to what we need,
3705 we have to swap the operands. */
3706 tmp
= op0
; op0
= op1
; op1
= tmp
;
3708 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) >= 0 && INTVAL (len
) <= 256)
3710 if (INTVAL (len
) > 0)
3712 emit_insn (gen_cmpmem_short (op0
, op1
, GEN_INT (INTVAL (len
) - 1)));
3713 emit_insn (gen_cmpint (target
, ccreg
));
3716 emit_move_insn (target
, const0_rtx
);
3718 else if (TARGET_MVCLE
)
3720 emit_insn (gen_cmpmem_long (op0
, op1
, convert_to_mode (Pmode
, len
, 1)));
3721 emit_insn (gen_cmpint (target
, ccreg
));
3725 rtx addr0
, addr1
, count
, blocks
, temp
;
3726 rtx loop_start_label
= gen_label_rtx ();
3727 rtx loop_end_label
= gen_label_rtx ();
3728 rtx end_label
= gen_label_rtx ();
3729 enum machine_mode mode
;
3731 mode
= GET_MODE (len
);
3732 if (mode
== VOIDmode
)
3735 addr0
= gen_reg_rtx (Pmode
);
3736 addr1
= gen_reg_rtx (Pmode
);
3737 count
= gen_reg_rtx (mode
);
3738 blocks
= gen_reg_rtx (mode
);
3740 convert_move (count
, len
, 1);
3741 emit_cmp_and_jump_insns (count
, const0_rtx
,
3742 EQ
, NULL_RTX
, mode
, 1, end_label
);
3744 emit_move_insn (addr0
, force_operand (XEXP (op0
, 0), NULL_RTX
));
3745 emit_move_insn (addr1
, force_operand (XEXP (op1
, 0), NULL_RTX
));
3746 op0
= change_address (op0
, VOIDmode
, addr0
);
3747 op1
= change_address (op1
, VOIDmode
, addr1
);
3749 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1, 0);
3751 emit_move_insn (count
, temp
);
3753 temp
= expand_binop (mode
, ashr_optab
, count
, GEN_INT (8), blocks
, 1, 0);
3755 emit_move_insn (blocks
, temp
);
3757 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3758 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3760 emit_label (loop_start_label
);
3762 emit_insn (gen_cmpmem_short (op0
, op1
, GEN_INT (255)));
3763 temp
= gen_rtx_NE (VOIDmode
, ccreg
, const0_rtx
);
3764 temp
= gen_rtx_IF_THEN_ELSE (VOIDmode
, temp
,
3765 gen_rtx_LABEL_REF (VOIDmode
, end_label
), pc_rtx
);
3766 temp
= gen_rtx_SET (VOIDmode
, pc_rtx
, temp
);
3767 emit_jump_insn (temp
);
3769 s390_load_address (addr0
,
3770 gen_rtx_PLUS (Pmode
, addr0
, GEN_INT (256)));
3771 s390_load_address (addr1
,
3772 gen_rtx_PLUS (Pmode
, addr1
, GEN_INT (256)));
3774 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1, 0);
3776 emit_move_insn (blocks
, temp
);
3778 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3779 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3781 emit_jump (loop_start_label
);
3782 emit_label (loop_end_label
);
3784 emit_insn (gen_cmpmem_short (op0
, op1
,
3785 convert_to_mode (Pmode
, count
, 1)));
3786 emit_label (end_label
);
3788 emit_insn (gen_cmpint (target
, ccreg
));
3793 /* Expand conditional increment or decrement using alc/slb instructions.
3794 Should generate code setting DST to either SRC or SRC + INCREMENT,
3795 depending on the result of the comparison CMP_OP0 CMP_CODE CMP_OP1.
3796 Returns true if successful, false otherwise.
3798 That makes it possible to implement some if-constructs without jumps e.g.:
3799 (borrow = CC0 | CC1 and carry = CC2 | CC3)
3800 unsigned int a, b, c;
3801 if (a < b) c++; -> CCU b > a -> CC2; c += carry;
3802 if (a < b) c--; -> CCL3 a - b -> borrow; c -= borrow;
3803 if (a <= b) c++; -> CCL3 b - a -> borrow; c += carry;
3804 if (a <= b) c--; -> CCU a <= b -> borrow; c -= borrow;
3806 Checks for EQ and NE with a nonzero value need an additional xor e.g.:
3807 if (a == b) c++; -> CCL3 a ^= b; 0 - a -> borrow; c += carry;
3808 if (a == b) c--; -> CCU a ^= b; a <= 0 -> CC0 | CC1; c -= borrow;
3809 if (a != b) c++; -> CCU a ^= b; a > 0 -> CC2; c += carry;
3810 if (a != b) c--; -> CCL3 a ^= b; 0 - a -> borrow; c -= borrow; */
3813 s390_expand_addcc (enum rtx_code cmp_code
, rtx cmp_op0
, rtx cmp_op1
,
3814 rtx dst
, rtx src
, rtx increment
)
3816 enum machine_mode cmp_mode
;
3817 enum machine_mode cc_mode
;
3823 if ((GET_MODE (cmp_op0
) == SImode
|| GET_MODE (cmp_op0
) == VOIDmode
)
3824 && (GET_MODE (cmp_op1
) == SImode
|| GET_MODE (cmp_op1
) == VOIDmode
))
3826 else if ((GET_MODE (cmp_op0
) == DImode
|| GET_MODE (cmp_op0
) == VOIDmode
)
3827 && (GET_MODE (cmp_op1
) == DImode
|| GET_MODE (cmp_op1
) == VOIDmode
))
3832 /* Try ADD LOGICAL WITH CARRY. */
3833 if (increment
== const1_rtx
)
3835 /* Determine CC mode to use. */
3836 if (cmp_code
== EQ
|| cmp_code
== NE
)
3838 if (cmp_op1
!= const0_rtx
)
3840 cmp_op0
= expand_simple_binop (cmp_mode
, XOR
, cmp_op0
, cmp_op1
,
3841 NULL_RTX
, 0, OPTAB_WIDEN
);
3842 cmp_op1
= const0_rtx
;
3845 cmp_code
= cmp_code
== EQ
? LEU
: GTU
;
3848 if (cmp_code
== LTU
|| cmp_code
== LEU
)
3853 cmp_code
= swap_condition (cmp_code
);
3870 /* Emit comparison instruction pattern. */
3871 if (!register_operand (cmp_op0
, cmp_mode
))
3872 cmp_op0
= force_reg (cmp_mode
, cmp_op0
);
3874 insn
= gen_rtx_SET (VOIDmode
, gen_rtx_REG (cc_mode
, CC_REGNUM
),
3875 gen_rtx_COMPARE (cc_mode
, cmp_op0
, cmp_op1
));
3876 /* We use insn_invalid_p here to add clobbers if required. */
3877 ret
= insn_invalid_p (emit_insn (insn
));
3880 /* Emit ALC instruction pattern. */
3881 op_res
= gen_rtx_fmt_ee (cmp_code
, GET_MODE (dst
),
3882 gen_rtx_REG (cc_mode
, CC_REGNUM
),
3885 if (src
!= const0_rtx
)
3887 if (!register_operand (src
, GET_MODE (dst
)))
3888 src
= force_reg (GET_MODE (dst
), src
);
3890 src
= gen_rtx_PLUS (GET_MODE (dst
), src
, const0_rtx
);
3891 op_res
= gen_rtx_PLUS (GET_MODE (dst
), src
, op_res
);
3894 p
= rtvec_alloc (2);
3896 gen_rtx_SET (VOIDmode
, dst
, op_res
);
3898 gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
3899 emit_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
3904 /* Try SUBTRACT LOGICAL WITH BORROW. */
3905 if (increment
== constm1_rtx
)
3907 /* Determine CC mode to use. */
3908 if (cmp_code
== EQ
|| cmp_code
== NE
)
3910 if (cmp_op1
!= const0_rtx
)
3912 cmp_op0
= expand_simple_binop (cmp_mode
, XOR
, cmp_op0
, cmp_op1
,
3913 NULL_RTX
, 0, OPTAB_WIDEN
);
3914 cmp_op1
= const0_rtx
;
3917 cmp_code
= cmp_code
== EQ
? LEU
: GTU
;
3920 if (cmp_code
== GTU
|| cmp_code
== GEU
)
3925 cmp_code
= swap_condition (cmp_code
);
3942 /* Emit comparison instruction pattern. */
3943 if (!register_operand (cmp_op0
, cmp_mode
))
3944 cmp_op0
= force_reg (cmp_mode
, cmp_op0
);
3946 insn
= gen_rtx_SET (VOIDmode
, gen_rtx_REG (cc_mode
, CC_REGNUM
),
3947 gen_rtx_COMPARE (cc_mode
, cmp_op0
, cmp_op1
));
3948 /* We use insn_invalid_p here to add clobbers if required. */
3949 ret
= insn_invalid_p (emit_insn (insn
));
3952 /* Emit SLB instruction pattern. */
3953 if (!register_operand (src
, GET_MODE (dst
)))
3954 src
= force_reg (GET_MODE (dst
), src
);
3956 op_res
= gen_rtx_MINUS (GET_MODE (dst
),
3957 gen_rtx_MINUS (GET_MODE (dst
), src
, const0_rtx
),
3958 gen_rtx_fmt_ee (cmp_code
, GET_MODE (dst
),
3959 gen_rtx_REG (cc_mode
, CC_REGNUM
),
3961 p
= rtvec_alloc (2);
3963 gen_rtx_SET (VOIDmode
, dst
, op_res
);
3965 gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
3966 emit_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
3974 /* Expand code for the insv template. Return true if successful, false else. */
3977 s390_expand_insv (rtx dest
, rtx op1
, rtx op2
, rtx src
)
3979 int bitsize
= INTVAL (op1
);
3980 int bitpos
= INTVAL (op2
);
3982 /* We need byte alignment. */
3983 if (bitsize
% BITS_PER_UNIT
)
3987 && memory_operand (dest
, VOIDmode
)
3988 && (register_operand (src
, word_mode
)
3989 || const_int_operand (src
, VOIDmode
)))
3991 /* Emit standard pattern if possible. */
3992 enum machine_mode mode
= smallest_mode_for_size (bitsize
, MODE_INT
);
3993 if (GET_MODE_BITSIZE (mode
) == bitsize
)
3994 emit_move_insn (adjust_address (dest
, mode
, 0), gen_lowpart (mode
, src
));
3996 /* (set (ze (mem)) (const_int)). */
3997 else if (const_int_operand (src
, VOIDmode
))
3999 int size
= bitsize
/ BITS_PER_UNIT
;
4000 rtx src_mem
= adjust_address (force_const_mem (word_mode
, src
), BLKmode
,
4001 GET_MODE_SIZE (word_mode
) - size
);
4003 dest
= adjust_address (dest
, BLKmode
, 0);
4004 set_mem_size (dest
, GEN_INT (size
));
4005 s390_expand_movmem (dest
, src_mem
, GEN_INT (size
));
4008 /* (set (ze (mem)) (reg)). */
4009 else if (register_operand (src
, word_mode
))
4011 if (bitsize
<= GET_MODE_BITSIZE (SImode
))
4012 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
, op1
,
4016 /* Emit st,stcmh sequence. */
4017 int stcmh_width
= bitsize
- GET_MODE_BITSIZE (SImode
);
4018 int size
= stcmh_width
/ BITS_PER_UNIT
;
4020 emit_move_insn (adjust_address (dest
, SImode
, size
),
4021 gen_lowpart (SImode
, src
));
4022 set_mem_size (dest
, GEN_INT (size
));
4023 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
, GEN_INT
4024 (stcmh_width
), const0_rtx
),
4025 gen_rtx_LSHIFTRT (word_mode
, src
, GEN_INT
4026 (GET_MODE_BITSIZE (SImode
))));
4035 /* (set (ze (reg)) (const_int)). */
4037 && register_operand (dest
, word_mode
)
4038 && (bitpos
% 16) == 0
4039 && (bitsize
% 16) == 0
4040 && const_int_operand (src
, VOIDmode
))
4042 HOST_WIDE_INT val
= INTVAL (src
);
4043 int regpos
= bitpos
+ bitsize
;
4045 while (regpos
> bitpos
)
4047 enum machine_mode putmode
;
4050 if (TARGET_EXTIMM
&& (regpos
% 32 == 0) && (regpos
>= bitpos
+ 32))
4055 putsize
= GET_MODE_BITSIZE (putmode
);
4057 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
,
4060 gen_int_mode (val
, putmode
));
4063 gcc_assert (regpos
== bitpos
);
4070 /* A subroutine of s390_expand_cs_hqi and s390_expand_atomic which returns a
4071 register that holds VAL of mode MODE shifted by COUNT bits. */
4074 s390_expand_mask_and_shift (rtx val
, enum machine_mode mode
, rtx count
)
4076 val
= expand_simple_binop (SImode
, AND
, val
, GEN_INT (GET_MODE_MASK (mode
)),
4077 NULL_RTX
, 1, OPTAB_DIRECT
);
4078 return expand_simple_binop (SImode
, ASHIFT
, val
, count
,
4079 NULL_RTX
, 1, OPTAB_DIRECT
);
4082 /* Structure to hold the initial parameters for a compare_and_swap operation
4083 in HImode and QImode. */
4085 struct alignment_context
4087 rtx memsi
; /* SI aligned memory location. */
4088 rtx shift
; /* Bit offset with regard to lsb. */
4089 rtx modemask
; /* Mask of the HQImode shifted by SHIFT bits. */
4090 rtx modemaski
; /* ~modemask */
4091 bool aligned
; /* True if memory is aligned, false else. */
4094 /* A subroutine of s390_expand_cs_hqi and s390_expand_atomic to initialize
4095 structure AC for transparent simplifying, if the memory alignment is known
4096 to be at least 32bit. MEM is the memory location for the actual operation
4097 and MODE its mode. */
4100 init_alignment_context (struct alignment_context
*ac
, rtx mem
,
4101 enum machine_mode mode
)
4103 ac
->shift
= GEN_INT (GET_MODE_SIZE (SImode
) - GET_MODE_SIZE (mode
));
4104 ac
->aligned
= (MEM_ALIGN (mem
) >= GET_MODE_BITSIZE (SImode
));
4107 ac
->memsi
= adjust_address (mem
, SImode
, 0); /* Memory is aligned. */
4110 /* Alignment is unknown. */
4111 rtx byteoffset
, addr
, align
;
4113 /* Force the address into a register. */
4114 addr
= force_reg (Pmode
, XEXP (mem
, 0));
4116 /* Align it to SImode. */
4117 align
= expand_simple_binop (Pmode
, AND
, addr
,
4118 GEN_INT (-GET_MODE_SIZE (SImode
)),
4119 NULL_RTX
, 1, OPTAB_DIRECT
);
4121 ac
->memsi
= gen_rtx_MEM (SImode
, align
);
4122 MEM_VOLATILE_P (ac
->memsi
) = MEM_VOLATILE_P (mem
);
4123 set_mem_alias_set (ac
->memsi
, ALIAS_SET_MEMORY_BARRIER
);
4124 set_mem_align (ac
->memsi
, GET_MODE_BITSIZE (SImode
));
4126 /* Calculate shiftcount. */
4127 byteoffset
= expand_simple_binop (Pmode
, AND
, addr
,
4128 GEN_INT (GET_MODE_SIZE (SImode
) - 1),
4129 NULL_RTX
, 1, OPTAB_DIRECT
);
4130 /* As we already have some offset, evaluate the remaining distance. */
4131 ac
->shift
= expand_simple_binop (SImode
, MINUS
, ac
->shift
, byteoffset
,
4132 NULL_RTX
, 1, OPTAB_DIRECT
);
4135 /* Shift is the byte count, but we need the bitcount. */
4136 ac
->shift
= expand_simple_binop (SImode
, MULT
, ac
->shift
, GEN_INT (BITS_PER_UNIT
),
4137 NULL_RTX
, 1, OPTAB_DIRECT
);
4138 /* Calculate masks. */
4139 ac
->modemask
= expand_simple_binop (SImode
, ASHIFT
,
4140 GEN_INT (GET_MODE_MASK (mode
)), ac
->shift
,
4141 NULL_RTX
, 1, OPTAB_DIRECT
);
4142 ac
->modemaski
= expand_simple_unop (SImode
, NOT
, ac
->modemask
, NULL_RTX
, 1);
4145 /* Expand an atomic compare and swap operation for HImode and QImode. MEM is
4146 the memory location, CMP the old value to compare MEM with and NEW the value
4147 to set if CMP == MEM.
4148 CMP is never in memory for compare_and_swap_cc because
4149 expand_bool_compare_and_swap puts it into a register for later compare. */
4152 s390_expand_cs_hqi (enum machine_mode mode
, rtx target
, rtx mem
, rtx cmp
, rtx
new)
4154 struct alignment_context ac
;
4155 rtx cmpv
, newv
, val
, resv
, cc
;
4156 rtx res
= gen_reg_rtx (SImode
);
4157 rtx csloop
= gen_label_rtx ();
4158 rtx csend
= gen_label_rtx ();
4160 gcc_assert (register_operand (target
, VOIDmode
));
4161 gcc_assert (MEM_P (mem
));
4163 init_alignment_context (&ac
, mem
, mode
);
4165 /* Shift the values to the correct bit positions. */
4166 if (!(ac
.aligned
&& MEM_P (cmp
)))
4167 cmp
= s390_expand_mask_and_shift (cmp
, mode
, ac
.shift
);
4168 if (!(ac
.aligned
&& MEM_P (new)))
4169 new = s390_expand_mask_and_shift (new, mode
, ac
.shift
);
4171 /* Load full word. Subsequent loads are performed by CS. */
4172 val
= expand_simple_binop (SImode
, AND
, ac
.memsi
, ac
.modemaski
,
4173 NULL_RTX
, 1, OPTAB_DIRECT
);
4175 /* Start CS loop. */
4176 emit_label (csloop
);
4177 /* val = "<mem>00..0<mem>"
4178 * cmp = "00..0<cmp>00..0"
4179 * new = "00..0<new>00..0"
4182 /* Patch cmp and new with val at correct position. */
4183 if (ac
.aligned
&& MEM_P (cmp
))
4185 cmpv
= force_reg (SImode
, val
);
4186 store_bit_field (cmpv
, GET_MODE_BITSIZE (mode
), 0, SImode
, cmp
);
4189 cmpv
= force_reg (SImode
, expand_simple_binop (SImode
, IOR
, cmp
, val
,
4190 NULL_RTX
, 1, OPTAB_DIRECT
));
4191 if (ac
.aligned
&& MEM_P (new))
4193 newv
= force_reg (SImode
, val
);
4194 store_bit_field (newv
, GET_MODE_BITSIZE (mode
), 0, SImode
, new);
4197 newv
= force_reg (SImode
, expand_simple_binop (SImode
, IOR
, new, val
,
4198 NULL_RTX
, 1, OPTAB_DIRECT
));
4200 /* Emit compare_and_swap pattern. */
4201 emit_insn (gen_sync_compare_and_swap_ccsi (res
, ac
.memsi
, cmpv
, newv
));
4203 /* Jump to end if we're done (likely?). */
4204 s390_emit_jump (csend
, s390_emit_compare (EQ
, cmpv
, ac
.memsi
));
4206 /* Check for changes outside mode. */
4207 resv
= expand_simple_binop (SImode
, AND
, res
, ac
.modemaski
,
4208 NULL_RTX
, 1, OPTAB_DIRECT
);
4209 cc
= s390_emit_compare (NE
, resv
, val
);
4210 emit_move_insn (val
, resv
);
4211 /* Loop internal if so. */
4212 s390_emit_jump (csloop
, cc
);
4216 /* Return the correct part of the bitfield. */
4217 convert_move (target
, expand_simple_binop (SImode
, LSHIFTRT
, res
, ac
.shift
,
4218 NULL_RTX
, 1, OPTAB_DIRECT
), 1);
4221 /* Expand an atomic operation CODE of mode MODE. MEM is the memory location
4222 and VAL the value to play with. If AFTER is true then store the the value
4223 MEM holds after the operation, if AFTER is false then store the value MEM
4224 holds before the operation. If TARGET is zero then discard that value, else
4225 store it to TARGET. */
4228 s390_expand_atomic (enum machine_mode mode
, enum rtx_code code
,
4229 rtx target
, rtx mem
, rtx val
, bool after
)
4231 struct alignment_context ac
;
4233 rtx
new = gen_reg_rtx (SImode
);
4234 rtx orig
= gen_reg_rtx (SImode
);
4235 rtx csloop
= gen_label_rtx ();
4237 gcc_assert (!target
|| register_operand (target
, VOIDmode
));
4238 gcc_assert (MEM_P (mem
));
4240 init_alignment_context (&ac
, mem
, mode
);
4242 /* Shift val to the correct bit positions.
4243 Preserve "icm", but prevent "ex icm". */
4244 if (!(ac
.aligned
&& code
== SET
&& MEM_P (val
)))
4245 val
= s390_expand_mask_and_shift (val
, mode
, ac
.shift
);
4247 /* Further preparation insns. */
4248 if (code
== PLUS
|| code
== MINUS
)
4249 emit_move_insn (orig
, val
);
4250 else if (code
== MULT
|| code
== AND
) /* val = "11..1<val>11..1" */
4251 val
= expand_simple_binop (SImode
, XOR
, val
, ac
.modemaski
,
4252 NULL_RTX
, 1, OPTAB_DIRECT
);
4254 /* Load full word. Subsequent loads are performed by CS. */
4255 cmp
= force_reg (SImode
, ac
.memsi
);
4257 /* Start CS loop. */
4258 emit_label (csloop
);
4259 emit_move_insn (new, cmp
);
4261 /* Patch new with val at correct position. */
4266 val
= expand_simple_binop (SImode
, code
, new, orig
,
4267 NULL_RTX
, 1, OPTAB_DIRECT
);
4268 val
= expand_simple_binop (SImode
, AND
, val
, ac
.modemask
,
4269 NULL_RTX
, 1, OPTAB_DIRECT
);
4272 if (ac
.aligned
&& MEM_P (val
))
4273 store_bit_field (new, GET_MODE_BITSIZE (mode
), 0, SImode
, val
);
4276 new = expand_simple_binop (SImode
, AND
, new, ac
.modemaski
,
4277 NULL_RTX
, 1, OPTAB_DIRECT
);
4278 new = expand_simple_binop (SImode
, IOR
, new, val
,
4279 NULL_RTX
, 1, OPTAB_DIRECT
);
4285 new = expand_simple_binop (SImode
, code
, new, val
,
4286 NULL_RTX
, 1, OPTAB_DIRECT
);
4288 case MULT
: /* NAND */
4289 new = expand_simple_binop (SImode
, XOR
, new, ac
.modemask
,
4290 NULL_RTX
, 1, OPTAB_DIRECT
);
4291 new = expand_simple_binop (SImode
, AND
, new, val
,
4292 NULL_RTX
, 1, OPTAB_DIRECT
);
4297 /* Emit compare_and_swap pattern. */
4298 emit_insn (gen_sync_compare_and_swap_ccsi (cmp
, ac
.memsi
, cmp
, new));
4300 /* Loop until swapped (unlikely?). */
4301 s390_emit_jump (csloop
, gen_rtx_fmt_ee (NE
, CCZ1mode
,
4302 gen_rtx_REG (CCZ1mode
, CC_REGNUM
),
4305 /* Return the correct part of the bitfield. */
4307 convert_move (target
, expand_simple_binop (SImode
, LSHIFTRT
,
4308 after
? new : cmp
, ac
.shift
,
4309 NULL_RTX
, 1, OPTAB_DIRECT
), 1);
4312 /* This is called from dwarf2out.c via TARGET_ASM_OUTPUT_DWARF_DTPREL.
4313 We need to emit DTP-relative relocations. */
4315 static void s390_output_dwarf_dtprel (FILE *, int, rtx
) ATTRIBUTE_UNUSED
;
4318 s390_output_dwarf_dtprel (FILE *file
, int size
, rtx x
)
4323 fputs ("\t.long\t", file
);
4326 fputs ("\t.quad\t", file
);
4331 output_addr_const (file
, x
);
4332 fputs ("@DTPOFF", file
);
4335 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
4336 /* Implement TARGET_MANGLE_FUNDAMENTAL_TYPE. */
4339 s390_mangle_fundamental_type (tree type
)
4341 if (TYPE_MAIN_VARIANT (type
) == long_double_type_node
4342 && TARGET_LONG_DOUBLE_128
)
4345 /* For all other types, use normal C++ mangling. */
4350 /* In the name of slightly smaller debug output, and to cater to
4351 general assembler lossage, recognize various UNSPEC sequences
4352 and turn them back into a direct symbol reference. */
4355 s390_delegitimize_address (rtx orig_x
)
4359 if (GET_CODE (x
) != MEM
)
4363 if (GET_CODE (x
) == PLUS
4364 && GET_CODE (XEXP (x
, 1)) == CONST
4365 && GET_CODE (XEXP (x
, 0)) == REG
4366 && REGNO (XEXP (x
, 0)) == PIC_OFFSET_TABLE_REGNUM
)
4368 y
= XEXP (XEXP (x
, 1), 0);
4369 if (GET_CODE (y
) == UNSPEC
4370 && XINT (y
, 1) == UNSPEC_GOT
)
4371 return XVECEXP (y
, 0, 0);
4375 if (GET_CODE (x
) == CONST
)
4378 if (GET_CODE (y
) == UNSPEC
4379 && XINT (y
, 1) == UNSPEC_GOTENT
)
4380 return XVECEXP (y
, 0, 0);
4387 /* Output operand OP to stdio stream FILE.
4388 OP is an address (register + offset) which is not used to address data;
4389 instead the rightmost bits are interpreted as the value. */
4392 print_shift_count_operand (FILE *file
, rtx op
)
4394 HOST_WIDE_INT offset
;
4397 /* Extract base register and offset. */
4398 if (!s390_decompose_shift_count (op
, &base
, &offset
))
4404 gcc_assert (GET_CODE (base
) == REG
);
4405 gcc_assert (REGNO (base
) < FIRST_PSEUDO_REGISTER
);
4406 gcc_assert (REGNO_REG_CLASS (REGNO (base
)) == ADDR_REGS
);
4409 /* Offsets are constricted to twelve bits. */
4410 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, offset
& ((1 << 12) - 1));
4412 fprintf (file
, "(%s)", reg_names
[REGNO (base
)]);
4415 /* See 'get_some_local_dynamic_name'. */
4418 get_some_local_dynamic_name_1 (rtx
*px
, void *data ATTRIBUTE_UNUSED
)
4422 if (GET_CODE (x
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (x
))
4424 x
= get_pool_constant (x
);
4425 return for_each_rtx (&x
, get_some_local_dynamic_name_1
, 0);
4428 if (GET_CODE (x
) == SYMBOL_REF
4429 && tls_symbolic_operand (x
) == TLS_MODEL_LOCAL_DYNAMIC
)
4431 cfun
->machine
->some_ld_name
= XSTR (x
, 0);
4438 /* Locate some local-dynamic symbol still in use by this function
4439 so that we can print its name in local-dynamic base patterns. */
4442 get_some_local_dynamic_name (void)
4446 if (cfun
->machine
->some_ld_name
)
4447 return cfun
->machine
->some_ld_name
;
4449 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
4451 && for_each_rtx (&PATTERN (insn
), get_some_local_dynamic_name_1
, 0))
4452 return cfun
->machine
->some_ld_name
;
4457 /* Output machine-dependent UNSPECs occurring in address constant X
4458 in assembler syntax to stdio stream FILE. Returns true if the
4459 constant X could be recognized, false otherwise. */
4462 s390_output_addr_const_extra (FILE *file
, rtx x
)
4464 if (GET_CODE (x
) == UNSPEC
&& XVECLEN (x
, 0) == 1)
4465 switch (XINT (x
, 1))
4468 output_addr_const (file
, XVECEXP (x
, 0, 0));
4469 fprintf (file
, "@GOTENT");
4472 output_addr_const (file
, XVECEXP (x
, 0, 0));
4473 fprintf (file
, "@GOT");
4476 output_addr_const (file
, XVECEXP (x
, 0, 0));
4477 fprintf (file
, "@GOTOFF");
4480 output_addr_const (file
, XVECEXP (x
, 0, 0));
4481 fprintf (file
, "@PLT");
4484 output_addr_const (file
, XVECEXP (x
, 0, 0));
4485 fprintf (file
, "@PLTOFF");
4488 output_addr_const (file
, XVECEXP (x
, 0, 0));
4489 fprintf (file
, "@TLSGD");
4492 assemble_name (file
, get_some_local_dynamic_name ());
4493 fprintf (file
, "@TLSLDM");
4496 output_addr_const (file
, XVECEXP (x
, 0, 0));
4497 fprintf (file
, "@DTPOFF");
4500 output_addr_const (file
, XVECEXP (x
, 0, 0));
4501 fprintf (file
, "@NTPOFF");
4503 case UNSPEC_GOTNTPOFF
:
4504 output_addr_const (file
, XVECEXP (x
, 0, 0));
4505 fprintf (file
, "@GOTNTPOFF");
4507 case UNSPEC_INDNTPOFF
:
4508 output_addr_const (file
, XVECEXP (x
, 0, 0));
4509 fprintf (file
, "@INDNTPOFF");
4516 /* Output address operand ADDR in assembler syntax to
4517 stdio stream FILE. */
4520 print_operand_address (FILE *file
, rtx addr
)
4522 struct s390_address ad
;
4524 if (!s390_decompose_address (addr
, &ad
)
4525 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
4526 || (ad
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (ad
.indx
))))
4527 output_operand_lossage ("cannot decompose address");
4530 output_addr_const (file
, ad
.disp
);
4532 fprintf (file
, "0");
4534 if (ad
.base
&& ad
.indx
)
4535 fprintf (file
, "(%s,%s)", reg_names
[REGNO (ad
.indx
)],
4536 reg_names
[REGNO (ad
.base
)]);
4538 fprintf (file
, "(%s)", reg_names
[REGNO (ad
.base
)]);
4541 /* Output operand X in assembler syntax to stdio stream FILE.
4542 CODE specified the format flag. The following format flags
4545 'C': print opcode suffix for branch condition.
4546 'D': print opcode suffix for inverse branch condition.
4547 'J': print tls_load/tls_gdcall/tls_ldcall suffix
4548 'G': print the size of the operand in bytes.
4549 'O': print only the displacement of a memory reference.
4550 'R': print only the base register of a memory reference.
4551 'S': print S-type memory reference (base+displacement).
4552 'N': print the second word of a DImode operand.
4553 'M': print the second word of a TImode operand.
4554 'Y': print shift count operand.
4556 'b': print integer X as if it's an unsigned byte.
4557 'x': print integer X as if it's an unsigned halfword.
4558 'h': print integer X as if it's a signed halfword.
4559 'i': print the first nonzero HImode part of X.
4560 'j': print the first HImode part unequal to -1 of X.
4561 'k': print the first nonzero SImode part of X.
4562 'm': print the first SImode part unequal to -1 of X.
4563 'o': print integer X as if it's an unsigned 32bit word. */
4566 print_operand (FILE *file
, rtx x
, int code
)
4571 fprintf (file
, s390_branch_condition_mnemonic (x
, FALSE
));
4575 fprintf (file
, s390_branch_condition_mnemonic (x
, TRUE
));
4579 if (GET_CODE (x
) == SYMBOL_REF
)
4581 fprintf (file
, "%s", ":tls_load:");
4582 output_addr_const (file
, x
);
4584 else if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_TLSGD
)
4586 fprintf (file
, "%s", ":tls_gdcall:");
4587 output_addr_const (file
, XVECEXP (x
, 0, 0));
4589 else if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_TLSLDM
)
4591 fprintf (file
, "%s", ":tls_ldcall:");
4592 assemble_name (file
, get_some_local_dynamic_name ());
4599 fprintf (file
, "%u", GET_MODE_SIZE (GET_MODE (x
)));
4604 struct s390_address ad
;
4607 gcc_assert (GET_CODE (x
) == MEM
);
4608 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
4610 gcc_assert (!ad
.base
|| REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)));
4611 gcc_assert (!ad
.indx
);
4614 output_addr_const (file
, ad
.disp
);
4616 fprintf (file
, "0");
4622 struct s390_address ad
;
4625 gcc_assert (GET_CODE (x
) == MEM
);
4626 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
4628 gcc_assert (!ad
.base
|| REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)));
4629 gcc_assert (!ad
.indx
);
4632 fprintf (file
, "%s", reg_names
[REGNO (ad
.base
)]);
4634 fprintf (file
, "0");
4640 struct s390_address ad
;
4643 gcc_assert (GET_CODE (x
) == MEM
);
4644 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
4646 gcc_assert (!ad
.base
|| REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)));
4647 gcc_assert (!ad
.indx
);
4650 output_addr_const (file
, ad
.disp
);
4652 fprintf (file
, "0");
4655 fprintf (file
, "(%s)", reg_names
[REGNO (ad
.base
)]);
4660 if (GET_CODE (x
) == REG
)
4661 x
= gen_rtx_REG (GET_MODE (x
), REGNO (x
) + 1);
4662 else if (GET_CODE (x
) == MEM
)
4663 x
= change_address (x
, VOIDmode
, plus_constant (XEXP (x
, 0), 4));
4669 if (GET_CODE (x
) == REG
)
4670 x
= gen_rtx_REG (GET_MODE (x
), REGNO (x
) + 1);
4671 else if (GET_CODE (x
) == MEM
)
4672 x
= change_address (x
, VOIDmode
, plus_constant (XEXP (x
, 0), 8));
4678 print_shift_count_operand (file
, x
);
4682 switch (GET_CODE (x
))
4685 fprintf (file
, "%s", reg_names
[REGNO (x
)]);
4689 output_address (XEXP (x
, 0));
4696 output_addr_const (file
, x
);
4701 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
) & 0xff);
4702 else if (code
== 'x')
4703 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
) & 0xffff);
4704 else if (code
== 'h')
4705 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, ((INTVAL (x
) & 0xffff) ^ 0x8000) - 0x8000);
4706 else if (code
== 'i')
4707 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
4708 s390_extract_part (x
, HImode
, 0));
4709 else if (code
== 'j')
4710 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
4711 s390_extract_part (x
, HImode
, -1));
4712 else if (code
== 'k')
4713 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
4714 s390_extract_part (x
, SImode
, 0));
4715 else if (code
== 'm')
4716 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
4717 s390_extract_part (x
, SImode
, -1));
4718 else if (code
== 'o')
4719 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
) & 0xffffffff);
4721 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
));
4725 gcc_assert (GET_MODE (x
) == VOIDmode
);
4727 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, CONST_DOUBLE_LOW (x
) & 0xff);
4728 else if (code
== 'x')
4729 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, CONST_DOUBLE_LOW (x
) & 0xffff);
4730 else if (code
== 'h')
4731 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, ((CONST_DOUBLE_LOW (x
) & 0xffff) ^ 0x8000) - 0x8000);
4737 fatal_insn ("UNKNOWN in print_operand !?", x
);
4742 /* Target hook for assembling integer objects. We need to define it
4743 here to work a round a bug in some versions of GAS, which couldn't
4744 handle values smaller than INT_MIN when printed in decimal. */
4747 s390_assemble_integer (rtx x
, unsigned int size
, int aligned_p
)
4749 if (size
== 8 && aligned_p
4750 && GET_CODE (x
) == CONST_INT
&& INTVAL (x
) < INT_MIN
)
4752 fprintf (asm_out_file
, "\t.quad\t" HOST_WIDE_INT_PRINT_HEX
"\n",
4756 return default_assemble_integer (x
, size
, aligned_p
);
4759 /* Returns true if register REGNO is used for forming
4760 a memory address in expression X. */
4763 reg_used_in_mem_p (int regno
, rtx x
)
4765 enum rtx_code code
= GET_CODE (x
);
4771 if (refers_to_regno_p (regno
, regno
+1,
4775 else if (code
== SET
4776 && GET_CODE (SET_DEST (x
)) == PC
)
4778 if (refers_to_regno_p (regno
, regno
+1,
4783 fmt
= GET_RTX_FORMAT (code
);
4784 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4787 && reg_used_in_mem_p (regno
, XEXP (x
, i
)))
4790 else if (fmt
[i
] == 'E')
4791 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
4792 if (reg_used_in_mem_p (regno
, XVECEXP (x
, i
, j
)))
4798 /* Returns true if expression DEP_RTX sets an address register
4799 used by instruction INSN to address memory. */
4802 addr_generation_dependency_p (rtx dep_rtx
, rtx insn
)
4806 if (GET_CODE (dep_rtx
) == INSN
)
4807 dep_rtx
= PATTERN (dep_rtx
);
4809 if (GET_CODE (dep_rtx
) == SET
)
4811 target
= SET_DEST (dep_rtx
);
4812 if (GET_CODE (target
) == STRICT_LOW_PART
)
4813 target
= XEXP (target
, 0);
4814 while (GET_CODE (target
) == SUBREG
)
4815 target
= SUBREG_REG (target
);
4817 if (GET_CODE (target
) == REG
)
4819 int regno
= REGNO (target
);
4821 if (s390_safe_attr_type (insn
) == TYPE_LA
)
4823 pat
= PATTERN (insn
);
4824 if (GET_CODE (pat
) == PARALLEL
)
4826 gcc_assert (XVECLEN (pat
, 0) == 2);
4827 pat
= XVECEXP (pat
, 0, 0);
4829 gcc_assert (GET_CODE (pat
) == SET
);
4830 return refers_to_regno_p (regno
, regno
+1, SET_SRC (pat
), 0);
4832 else if (get_attr_atype (insn
) == ATYPE_AGEN
)
4833 return reg_used_in_mem_p (regno
, PATTERN (insn
));
4839 /* Return 1, if dep_insn sets register used in insn in the agen unit. */
4842 s390_agen_dep_p (rtx dep_insn
, rtx insn
)
4844 rtx dep_rtx
= PATTERN (dep_insn
);
4847 if (GET_CODE (dep_rtx
) == SET
4848 && addr_generation_dependency_p (dep_rtx
, insn
))
4850 else if (GET_CODE (dep_rtx
) == PARALLEL
)
4852 for (i
= 0; i
< XVECLEN (dep_rtx
, 0); i
++)
4854 if (addr_generation_dependency_p (XVECEXP (dep_rtx
, 0, i
), insn
))
4861 /* A C statement (sans semicolon) to update the integer scheduling priority
4862 INSN_PRIORITY (INSN). Increase the priority to execute the INSN earlier,
4863 reduce the priority to execute INSN later. Do not define this macro if
4864 you do not need to adjust the scheduling priorities of insns.
4866 A STD instruction should be scheduled earlier,
4867 in order to use the bypass. */
4870 s390_adjust_priority (rtx insn ATTRIBUTE_UNUSED
, int priority
)
4872 if (! INSN_P (insn
))
4875 if (s390_tune
!= PROCESSOR_2084_Z990
4876 && s390_tune
!= PROCESSOR_2094_Z9_109
)
4879 switch (s390_safe_attr_type (insn
))
4883 priority
= priority
<< 3;
4887 priority
= priority
<< 1;
4895 /* The number of instructions that can be issued per cycle. */
4898 s390_issue_rate (void)
4900 if (s390_tune
== PROCESSOR_2084_Z990
4901 || s390_tune
== PROCESSOR_2094_Z9_109
)
4907 s390_first_cycle_multipass_dfa_lookahead (void)
4913 /* Annotate every literal pool reference in X by an UNSPEC_LTREF expression.
4914 Fix up MEMs as required. */
4917 annotate_constant_pool_refs (rtx
*x
)
4922 gcc_assert (GET_CODE (*x
) != SYMBOL_REF
4923 || !CONSTANT_POOL_ADDRESS_P (*x
));
4925 /* Literal pool references can only occur inside a MEM ... */
4926 if (GET_CODE (*x
) == MEM
)
4928 rtx memref
= XEXP (*x
, 0);
4930 if (GET_CODE (memref
) == SYMBOL_REF
4931 && CONSTANT_POOL_ADDRESS_P (memref
))
4933 rtx base
= cfun
->machine
->base_reg
;
4934 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, memref
, base
),
4937 *x
= replace_equiv_address (*x
, addr
);
4941 if (GET_CODE (memref
) == CONST
4942 && GET_CODE (XEXP (memref
, 0)) == PLUS
4943 && GET_CODE (XEXP (XEXP (memref
, 0), 1)) == CONST_INT
4944 && GET_CODE (XEXP (XEXP (memref
, 0), 0)) == SYMBOL_REF
4945 && CONSTANT_POOL_ADDRESS_P (XEXP (XEXP (memref
, 0), 0)))
4947 HOST_WIDE_INT off
= INTVAL (XEXP (XEXP (memref
, 0), 1));
4948 rtx sym
= XEXP (XEXP (memref
, 0), 0);
4949 rtx base
= cfun
->machine
->base_reg
;
4950 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, sym
, base
),
4953 *x
= replace_equiv_address (*x
, plus_constant (addr
, off
));
4958 /* ... or a load-address type pattern. */
4959 if (GET_CODE (*x
) == SET
)
4961 rtx addrref
= SET_SRC (*x
);
4963 if (GET_CODE (addrref
) == SYMBOL_REF
4964 && CONSTANT_POOL_ADDRESS_P (addrref
))
4966 rtx base
= cfun
->machine
->base_reg
;
4967 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, addrref
, base
),
4970 SET_SRC (*x
) = addr
;
4974 if (GET_CODE (addrref
) == CONST
4975 && GET_CODE (XEXP (addrref
, 0)) == PLUS
4976 && GET_CODE (XEXP (XEXP (addrref
, 0), 1)) == CONST_INT
4977 && GET_CODE (XEXP (XEXP (addrref
, 0), 0)) == SYMBOL_REF
4978 && CONSTANT_POOL_ADDRESS_P (XEXP (XEXP (addrref
, 0), 0)))
4980 HOST_WIDE_INT off
= INTVAL (XEXP (XEXP (addrref
, 0), 1));
4981 rtx sym
= XEXP (XEXP (addrref
, 0), 0);
4982 rtx base
= cfun
->machine
->base_reg
;
4983 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, sym
, base
),
4986 SET_SRC (*x
) = plus_constant (addr
, off
);
4991 /* Annotate LTREL_BASE as well. */
4992 if (GET_CODE (*x
) == UNSPEC
4993 && XINT (*x
, 1) == UNSPEC_LTREL_BASE
)
4995 rtx base
= cfun
->machine
->base_reg
;
4996 *x
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, XVECEXP (*x
, 0, 0), base
),
5001 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
5002 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
5006 annotate_constant_pool_refs (&XEXP (*x
, i
));
5008 else if (fmt
[i
] == 'E')
5010 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
5011 annotate_constant_pool_refs (&XVECEXP (*x
, i
, j
));
5016 /* Split all branches that exceed the maximum distance.
5017 Returns true if this created a new literal pool entry. */
5020 s390_split_branches (void)
5022 rtx temp_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
5023 int new_literal
= 0, ret
;
5024 rtx insn
, pat
, tmp
, target
;
5027 /* We need correct insn addresses. */
5029 shorten_branches (get_insns ());
5031 /* Find all branches that exceed 64KB, and split them. */
5033 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5035 if (GET_CODE (insn
) != JUMP_INSN
)
5038 pat
= PATTERN (insn
);
5039 if (GET_CODE (pat
) == PARALLEL
&& XVECLEN (pat
, 0) > 2)
5040 pat
= XVECEXP (pat
, 0, 0);
5041 if (GET_CODE (pat
) != SET
|| SET_DEST (pat
) != pc_rtx
)
5044 if (GET_CODE (SET_SRC (pat
)) == LABEL_REF
)
5046 label
= &SET_SRC (pat
);
5048 else if (GET_CODE (SET_SRC (pat
)) == IF_THEN_ELSE
)
5050 if (GET_CODE (XEXP (SET_SRC (pat
), 1)) == LABEL_REF
)
5051 label
= &XEXP (SET_SRC (pat
), 1);
5052 else if (GET_CODE (XEXP (SET_SRC (pat
), 2)) == LABEL_REF
)
5053 label
= &XEXP (SET_SRC (pat
), 2);
5060 if (get_attr_length (insn
) <= 4)
5063 /* We are going to use the return register as scratch register,
5064 make sure it will be saved/restored by the prologue/epilogue. */
5065 cfun_frame_layout
.save_return_addr_p
= 1;
5070 tmp
= force_const_mem (Pmode
, *label
);
5071 tmp
= emit_insn_before (gen_rtx_SET (Pmode
, temp_reg
, tmp
), insn
);
5072 INSN_ADDRESSES_NEW (tmp
, -1);
5073 annotate_constant_pool_refs (&PATTERN (tmp
));
5080 target
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, *label
),
5081 UNSPEC_LTREL_OFFSET
);
5082 target
= gen_rtx_CONST (Pmode
, target
);
5083 target
= force_const_mem (Pmode
, target
);
5084 tmp
= emit_insn_before (gen_rtx_SET (Pmode
, temp_reg
, target
), insn
);
5085 INSN_ADDRESSES_NEW (tmp
, -1);
5086 annotate_constant_pool_refs (&PATTERN (tmp
));
5088 target
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, XEXP (target
, 0),
5089 cfun
->machine
->base_reg
),
5091 target
= gen_rtx_PLUS (Pmode
, temp_reg
, target
);
5094 ret
= validate_change (insn
, label
, target
, 0);
5102 /* Find an annotated literal pool symbol referenced in RTX X,
5103 and store it at REF. Will abort if X contains references to
5104 more than one such pool symbol; multiple references to the same
5105 symbol are allowed, however.
5107 The rtx pointed to by REF must be initialized to NULL_RTX
5108 by the caller before calling this routine. */
5111 find_constant_pool_ref (rtx x
, rtx
*ref
)
5116 /* Ignore LTREL_BASE references. */
5117 if (GET_CODE (x
) == UNSPEC
5118 && XINT (x
, 1) == UNSPEC_LTREL_BASE
)
5120 /* Likewise POOL_ENTRY insns. */
5121 if (GET_CODE (x
) == UNSPEC_VOLATILE
5122 && XINT (x
, 1) == UNSPECV_POOL_ENTRY
)
5125 gcc_assert (GET_CODE (x
) != SYMBOL_REF
5126 || !CONSTANT_POOL_ADDRESS_P (x
));
5128 if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_LTREF
)
5130 rtx sym
= XVECEXP (x
, 0, 0);
5131 gcc_assert (GET_CODE (sym
) == SYMBOL_REF
5132 && CONSTANT_POOL_ADDRESS_P (sym
));
5134 if (*ref
== NULL_RTX
)
5137 gcc_assert (*ref
== sym
);
5142 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
5143 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
5147 find_constant_pool_ref (XEXP (x
, i
), ref
);
5149 else if (fmt
[i
] == 'E')
5151 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
5152 find_constant_pool_ref (XVECEXP (x
, i
, j
), ref
);
5157 /* Replace every reference to the annotated literal pool
5158 symbol REF in X by its base plus OFFSET. */
5161 replace_constant_pool_ref (rtx
*x
, rtx ref
, rtx offset
)
5166 gcc_assert (*x
!= ref
);
5168 if (GET_CODE (*x
) == UNSPEC
5169 && XINT (*x
, 1) == UNSPEC_LTREF
5170 && XVECEXP (*x
, 0, 0) == ref
)
5172 *x
= gen_rtx_PLUS (Pmode
, XVECEXP (*x
, 0, 1), offset
);
5176 if (GET_CODE (*x
) == PLUS
5177 && GET_CODE (XEXP (*x
, 1)) == CONST_INT
5178 && GET_CODE (XEXP (*x
, 0)) == UNSPEC
5179 && XINT (XEXP (*x
, 0), 1) == UNSPEC_LTREF
5180 && XVECEXP (XEXP (*x
, 0), 0, 0) == ref
)
5182 rtx addr
= gen_rtx_PLUS (Pmode
, XVECEXP (XEXP (*x
, 0), 0, 1), offset
);
5183 *x
= plus_constant (addr
, INTVAL (XEXP (*x
, 1)));
5187 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
5188 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
5192 replace_constant_pool_ref (&XEXP (*x
, i
), ref
, offset
);
5194 else if (fmt
[i
] == 'E')
5196 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
5197 replace_constant_pool_ref (&XVECEXP (*x
, i
, j
), ref
, offset
);
5202 /* Check whether X contains an UNSPEC_LTREL_BASE.
5203 Return its constant pool symbol if found, NULL_RTX otherwise. */
5206 find_ltrel_base (rtx x
)
5211 if (GET_CODE (x
) == UNSPEC
5212 && XINT (x
, 1) == UNSPEC_LTREL_BASE
)
5213 return XVECEXP (x
, 0, 0);
5215 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
5216 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
5220 rtx fnd
= find_ltrel_base (XEXP (x
, i
));
5224 else if (fmt
[i
] == 'E')
5226 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
5228 rtx fnd
= find_ltrel_base (XVECEXP (x
, i
, j
));
5238 /* Replace any occurrence of UNSPEC_LTREL_BASE in X with its base. */
5241 replace_ltrel_base (rtx
*x
)
5246 if (GET_CODE (*x
) == UNSPEC
5247 && XINT (*x
, 1) == UNSPEC_LTREL_BASE
)
5249 *x
= XVECEXP (*x
, 0, 1);
5253 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
5254 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
5258 replace_ltrel_base (&XEXP (*x
, i
));
5260 else if (fmt
[i
] == 'E')
5262 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
5263 replace_ltrel_base (&XVECEXP (*x
, i
, j
));
5269 /* We keep a list of constants which we have to add to internal
5270 constant tables in the middle of large functions. */
5272 #define NR_C_MODES 11
5273 enum machine_mode constant_modes
[NR_C_MODES
] =
5275 TFmode
, TImode
, TDmode
,
5276 DFmode
, DImode
, DDmode
,
5277 SFmode
, SImode
, SDmode
,
5284 struct constant
*next
;
5289 struct constant_pool
5291 struct constant_pool
*next
;
5296 struct constant
*constants
[NR_C_MODES
];
5297 struct constant
*execute
;
5302 /* Allocate new constant_pool structure. */
5304 static struct constant_pool
*
5305 s390_alloc_pool (void)
5307 struct constant_pool
*pool
;
5310 pool
= (struct constant_pool
*) xmalloc (sizeof *pool
);
5312 for (i
= 0; i
< NR_C_MODES
; i
++)
5313 pool
->constants
[i
] = NULL
;
5315 pool
->execute
= NULL
;
5316 pool
->label
= gen_label_rtx ();
5317 pool
->first_insn
= NULL_RTX
;
5318 pool
->pool_insn
= NULL_RTX
;
5319 pool
->insns
= BITMAP_ALLOC (NULL
);
5325 /* Create new constant pool covering instructions starting at INSN
5326 and chain it to the end of POOL_LIST. */
5328 static struct constant_pool
*
5329 s390_start_pool (struct constant_pool
**pool_list
, rtx insn
)
5331 struct constant_pool
*pool
, **prev
;
5333 pool
= s390_alloc_pool ();
5334 pool
->first_insn
= insn
;
5336 for (prev
= pool_list
; *prev
; prev
= &(*prev
)->next
)
5343 /* End range of instructions covered by POOL at INSN and emit
5344 placeholder insn representing the pool. */
5347 s390_end_pool (struct constant_pool
*pool
, rtx insn
)
5349 rtx pool_size
= GEN_INT (pool
->size
+ 8 /* alignment slop */);
5352 insn
= get_last_insn ();
5354 pool
->pool_insn
= emit_insn_after (gen_pool (pool_size
), insn
);
5355 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
5358 /* Add INSN to the list of insns covered by POOL. */
5361 s390_add_pool_insn (struct constant_pool
*pool
, rtx insn
)
5363 bitmap_set_bit (pool
->insns
, INSN_UID (insn
));
5366 /* Return pool out of POOL_LIST that covers INSN. */
5368 static struct constant_pool
*
5369 s390_find_pool (struct constant_pool
*pool_list
, rtx insn
)
5371 struct constant_pool
*pool
;
5373 for (pool
= pool_list
; pool
; pool
= pool
->next
)
5374 if (bitmap_bit_p (pool
->insns
, INSN_UID (insn
)))
5380 /* Add constant VAL of mode MODE to the constant pool POOL. */
5383 s390_add_constant (struct constant_pool
*pool
, rtx val
, enum machine_mode mode
)
5388 for (i
= 0; i
< NR_C_MODES
; i
++)
5389 if (constant_modes
[i
] == mode
)
5391 gcc_assert (i
!= NR_C_MODES
);
5393 for (c
= pool
->constants
[i
]; c
!= NULL
; c
= c
->next
)
5394 if (rtx_equal_p (val
, c
->value
))
5399 c
= (struct constant
*) xmalloc (sizeof *c
);
5401 c
->label
= gen_label_rtx ();
5402 c
->next
= pool
->constants
[i
];
5403 pool
->constants
[i
] = c
;
5404 pool
->size
+= GET_MODE_SIZE (mode
);
5408 /* Find constant VAL of mode MODE in the constant pool POOL.
5409 Return an RTX describing the distance from the start of
5410 the pool to the location of the new constant. */
5413 s390_find_constant (struct constant_pool
*pool
, rtx val
,
5414 enum machine_mode mode
)
5420 for (i
= 0; i
< NR_C_MODES
; i
++)
5421 if (constant_modes
[i
] == mode
)
5423 gcc_assert (i
!= NR_C_MODES
);
5425 for (c
= pool
->constants
[i
]; c
!= NULL
; c
= c
->next
)
5426 if (rtx_equal_p (val
, c
->value
))
5431 offset
= gen_rtx_MINUS (Pmode
, gen_rtx_LABEL_REF (Pmode
, c
->label
),
5432 gen_rtx_LABEL_REF (Pmode
, pool
->label
));
5433 offset
= gen_rtx_CONST (Pmode
, offset
);
5437 /* Check whether INSN is an execute. Return the label_ref to its
5438 execute target template if so, NULL_RTX otherwise. */
5441 s390_execute_label (rtx insn
)
5443 if (GET_CODE (insn
) == INSN
5444 && GET_CODE (PATTERN (insn
)) == PARALLEL
5445 && GET_CODE (XVECEXP (PATTERN (insn
), 0, 0)) == UNSPEC
5446 && XINT (XVECEXP (PATTERN (insn
), 0, 0), 1) == UNSPEC_EXECUTE
)
5447 return XVECEXP (XVECEXP (PATTERN (insn
), 0, 0), 0, 2);
5452 /* Add execute target for INSN to the constant pool POOL. */
5455 s390_add_execute (struct constant_pool
*pool
, rtx insn
)
5459 for (c
= pool
->execute
; c
!= NULL
; c
= c
->next
)
5460 if (INSN_UID (insn
) == INSN_UID (c
->value
))
5465 c
= (struct constant
*) xmalloc (sizeof *c
);
5467 c
->label
= gen_label_rtx ();
5468 c
->next
= pool
->execute
;
5474 /* Find execute target for INSN in the constant pool POOL.
5475 Return an RTX describing the distance from the start of
5476 the pool to the location of the execute target. */
5479 s390_find_execute (struct constant_pool
*pool
, rtx insn
)
5484 for (c
= pool
->execute
; c
!= NULL
; c
= c
->next
)
5485 if (INSN_UID (insn
) == INSN_UID (c
->value
))
5490 offset
= gen_rtx_MINUS (Pmode
, gen_rtx_LABEL_REF (Pmode
, c
->label
),
5491 gen_rtx_LABEL_REF (Pmode
, pool
->label
));
5492 offset
= gen_rtx_CONST (Pmode
, offset
);
5496 /* For an execute INSN, extract the execute target template. */
5499 s390_execute_target (rtx insn
)
5501 rtx pattern
= PATTERN (insn
);
5502 gcc_assert (s390_execute_label (insn
));
5504 if (XVECLEN (pattern
, 0) == 2)
5506 pattern
= copy_rtx (XVECEXP (pattern
, 0, 1));
5510 rtvec vec
= rtvec_alloc (XVECLEN (pattern
, 0) - 1);
5513 for (i
= 0; i
< XVECLEN (pattern
, 0) - 1; i
++)
5514 RTVEC_ELT (vec
, i
) = copy_rtx (XVECEXP (pattern
, 0, i
+ 1));
5516 pattern
= gen_rtx_PARALLEL (VOIDmode
, vec
);
5522 /* Indicate that INSN cannot be duplicated. This is the case for
5523 execute insns that carry a unique label. */
5526 s390_cannot_copy_insn_p (rtx insn
)
5528 rtx label
= s390_execute_label (insn
);
5529 return label
&& label
!= const0_rtx
;
5532 /* Dump out the constants in POOL. If REMOTE_LABEL is true,
5533 do not emit the pool base label. */
5536 s390_dump_pool (struct constant_pool
*pool
, bool remote_label
)
5539 rtx insn
= pool
->pool_insn
;
5542 /* Switch to rodata section. */
5543 if (TARGET_CPU_ZARCH
)
5545 insn
= emit_insn_after (gen_pool_section_start (), insn
);
5546 INSN_ADDRESSES_NEW (insn
, -1);
5549 /* Ensure minimum pool alignment. */
5550 if (TARGET_CPU_ZARCH
)
5551 insn
= emit_insn_after (gen_pool_align (GEN_INT (8)), insn
);
5553 insn
= emit_insn_after (gen_pool_align (GEN_INT (4)), insn
);
5554 INSN_ADDRESSES_NEW (insn
, -1);
5556 /* Emit pool base label. */
5559 insn
= emit_label_after (pool
->label
, insn
);
5560 INSN_ADDRESSES_NEW (insn
, -1);
5563 /* Dump constants in descending alignment requirement order,
5564 ensuring proper alignment for every constant. */
5565 for (i
= 0; i
< NR_C_MODES
; i
++)
5566 for (c
= pool
->constants
[i
]; c
; c
= c
->next
)
5568 /* Convert UNSPEC_LTREL_OFFSET unspecs to pool-relative references. */
5569 rtx value
= c
->value
;
5570 if (GET_CODE (value
) == CONST
5571 && GET_CODE (XEXP (value
, 0)) == UNSPEC
5572 && XINT (XEXP (value
, 0), 1) == UNSPEC_LTREL_OFFSET
5573 && XVECLEN (XEXP (value
, 0), 0) == 1)
5575 value
= gen_rtx_MINUS (Pmode
, XVECEXP (XEXP (value
, 0), 0, 0),
5576 gen_rtx_LABEL_REF (VOIDmode
, pool
->label
));
5577 value
= gen_rtx_CONST (VOIDmode
, value
);
5580 insn
= emit_label_after (c
->label
, insn
);
5581 INSN_ADDRESSES_NEW (insn
, -1);
5583 value
= gen_rtx_UNSPEC_VOLATILE (constant_modes
[i
],
5584 gen_rtvec (1, value
),
5585 UNSPECV_POOL_ENTRY
);
5586 insn
= emit_insn_after (value
, insn
);
5587 INSN_ADDRESSES_NEW (insn
, -1);
5590 /* Ensure minimum alignment for instructions. */
5591 insn
= emit_insn_after (gen_pool_align (GEN_INT (2)), insn
);
5592 INSN_ADDRESSES_NEW (insn
, -1);
5594 /* Output in-pool execute template insns. */
5595 for (c
= pool
->execute
; c
; c
= c
->next
)
5597 insn
= emit_label_after (c
->label
, insn
);
5598 INSN_ADDRESSES_NEW (insn
, -1);
5600 insn
= emit_insn_after (s390_execute_target (c
->value
), insn
);
5601 INSN_ADDRESSES_NEW (insn
, -1);
5604 /* Switch back to previous section. */
5605 if (TARGET_CPU_ZARCH
)
5607 insn
= emit_insn_after (gen_pool_section_end (), insn
);
5608 INSN_ADDRESSES_NEW (insn
, -1);
5611 insn
= emit_barrier_after (insn
);
5612 INSN_ADDRESSES_NEW (insn
, -1);
5614 /* Remove placeholder insn. */
5615 remove_insn (pool
->pool_insn
);
5618 /* Free all memory used by POOL. */
5621 s390_free_pool (struct constant_pool
*pool
)
5623 struct constant
*c
, *next
;
5626 for (i
= 0; i
< NR_C_MODES
; i
++)
5627 for (c
= pool
->constants
[i
]; c
; c
= next
)
5633 for (c
= pool
->execute
; c
; c
= next
)
5639 BITMAP_FREE (pool
->insns
);
5644 /* Collect main literal pool. Return NULL on overflow. */
5646 static struct constant_pool
*
5647 s390_mainpool_start (void)
5649 struct constant_pool
*pool
;
5652 pool
= s390_alloc_pool ();
5654 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5656 if (GET_CODE (insn
) == INSN
5657 && GET_CODE (PATTERN (insn
)) == SET
5658 && GET_CODE (SET_SRC (PATTERN (insn
))) == UNSPEC_VOLATILE
5659 && XINT (SET_SRC (PATTERN (insn
)), 1) == UNSPECV_MAIN_POOL
)
5661 gcc_assert (!pool
->pool_insn
);
5662 pool
->pool_insn
= insn
;
5665 if (!TARGET_CPU_ZARCH
&& s390_execute_label (insn
))
5667 s390_add_execute (pool
, insn
);
5669 else if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
5671 rtx pool_ref
= NULL_RTX
;
5672 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
5675 rtx constant
= get_pool_constant (pool_ref
);
5676 enum machine_mode mode
= get_pool_mode (pool_ref
);
5677 s390_add_constant (pool
, constant
, mode
);
5682 gcc_assert (pool
->pool_insn
|| pool
->size
== 0);
5684 if (pool
->size
>= 4096)
5686 /* We're going to chunkify the pool, so remove the main
5687 pool placeholder insn. */
5688 remove_insn (pool
->pool_insn
);
5690 s390_free_pool (pool
);
5697 /* POOL holds the main literal pool as collected by s390_mainpool_start.
5698 Modify the current function to output the pool constants as well as
5699 the pool register setup instruction. */
5702 s390_mainpool_finish (struct constant_pool
*pool
)
5704 rtx base_reg
= cfun
->machine
->base_reg
;
5707 /* If the pool is empty, we're done. */
5708 if (pool
->size
== 0)
5710 /* We don't actually need a base register after all. */
5711 cfun
->machine
->base_reg
= NULL_RTX
;
5713 if (pool
->pool_insn
)
5714 remove_insn (pool
->pool_insn
);
5715 s390_free_pool (pool
);
5719 /* We need correct insn addresses. */
5720 shorten_branches (get_insns ());
5722 /* On zSeries, we use a LARL to load the pool register. The pool is
5723 located in the .rodata section, so we emit it after the function. */
5724 if (TARGET_CPU_ZARCH
)
5726 insn
= gen_main_base_64 (base_reg
, pool
->label
);
5727 insn
= emit_insn_after (insn
, pool
->pool_insn
);
5728 INSN_ADDRESSES_NEW (insn
, -1);
5729 remove_insn (pool
->pool_insn
);
5731 insn
= get_last_insn ();
5732 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
5733 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
5735 s390_dump_pool (pool
, 0);
5738 /* On S/390, if the total size of the function's code plus literal pool
5739 does not exceed 4096 bytes, we use BASR to set up a function base
5740 pointer, and emit the literal pool at the end of the function. */
5741 else if (INSN_ADDRESSES (INSN_UID (get_last_insn ()))
5742 + pool
->size
+ 8 /* alignment slop */ < 4096)
5744 insn
= gen_main_base_31_small (base_reg
, pool
->label
);
5745 insn
= emit_insn_after (insn
, pool
->pool_insn
);
5746 INSN_ADDRESSES_NEW (insn
, -1);
5747 remove_insn (pool
->pool_insn
);
5749 insn
= emit_label_after (pool
->label
, insn
);
5750 INSN_ADDRESSES_NEW (insn
, -1);
5752 insn
= get_last_insn ();
5753 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
5754 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
5756 s390_dump_pool (pool
, 1);
5759 /* Otherwise, we emit an inline literal pool and use BASR to branch
5760 over it, setting up the pool register at the same time. */
5763 rtx pool_end
= gen_label_rtx ();
5765 insn
= gen_main_base_31_large (base_reg
, pool
->label
, pool_end
);
5766 insn
= emit_insn_after (insn
, pool
->pool_insn
);
5767 INSN_ADDRESSES_NEW (insn
, -1);
5768 remove_insn (pool
->pool_insn
);
5770 insn
= emit_label_after (pool
->label
, insn
);
5771 INSN_ADDRESSES_NEW (insn
, -1);
5773 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
5774 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
5776 insn
= emit_label_after (pool_end
, pool
->pool_insn
);
5777 INSN_ADDRESSES_NEW (insn
, -1);
5779 s390_dump_pool (pool
, 1);
5783 /* Replace all literal pool references. */
5785 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5788 replace_ltrel_base (&PATTERN (insn
));
5790 if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
5792 rtx addr
, pool_ref
= NULL_RTX
;
5793 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
5796 if (s390_execute_label (insn
))
5797 addr
= s390_find_execute (pool
, insn
);
5799 addr
= s390_find_constant (pool
, get_pool_constant (pool_ref
),
5800 get_pool_mode (pool_ref
));
5802 replace_constant_pool_ref (&PATTERN (insn
), pool_ref
, addr
);
5803 INSN_CODE (insn
) = -1;
5809 /* Free the pool. */
5810 s390_free_pool (pool
);
5813 /* POOL holds the main literal pool as collected by s390_mainpool_start.
5814 We have decided we cannot use this pool, so revert all changes
5815 to the current function that were done by s390_mainpool_start. */
5817 s390_mainpool_cancel (struct constant_pool
*pool
)
5819 /* We didn't actually change the instruction stream, so simply
5820 free the pool memory. */
5821 s390_free_pool (pool
);
5825 /* Chunkify the literal pool. */
5827 #define S390_POOL_CHUNK_MIN 0xc00
5828 #define S390_POOL_CHUNK_MAX 0xe00
5830 static struct constant_pool
*
5831 s390_chunkify_start (void)
5833 struct constant_pool
*curr_pool
= NULL
, *pool_list
= NULL
;
5836 rtx pending_ltrel
= NULL_RTX
;
5839 rtx (*gen_reload_base
) (rtx
, rtx
) =
5840 TARGET_CPU_ZARCH
? gen_reload_base_64
: gen_reload_base_31
;
5843 /* We need correct insn addresses. */
5845 shorten_branches (get_insns ());
5847 /* Scan all insns and move literals to pool chunks. */
5849 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5851 /* Check for pending LTREL_BASE. */
5854 rtx ltrel_base
= find_ltrel_base (PATTERN (insn
));
5857 gcc_assert (ltrel_base
== pending_ltrel
);
5858 pending_ltrel
= NULL_RTX
;
5862 if (!TARGET_CPU_ZARCH
&& s390_execute_label (insn
))
5865 curr_pool
= s390_start_pool (&pool_list
, insn
);
5867 s390_add_execute (curr_pool
, insn
);
5868 s390_add_pool_insn (curr_pool
, insn
);
5870 else if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
5872 rtx pool_ref
= NULL_RTX
;
5873 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
5876 rtx constant
= get_pool_constant (pool_ref
);
5877 enum machine_mode mode
= get_pool_mode (pool_ref
);
5880 curr_pool
= s390_start_pool (&pool_list
, insn
);
5882 s390_add_constant (curr_pool
, constant
, mode
);
5883 s390_add_pool_insn (curr_pool
, insn
);
5885 /* Don't split the pool chunk between a LTREL_OFFSET load
5886 and the corresponding LTREL_BASE. */
5887 if (GET_CODE (constant
) == CONST
5888 && GET_CODE (XEXP (constant
, 0)) == UNSPEC
5889 && XINT (XEXP (constant
, 0), 1) == UNSPEC_LTREL_OFFSET
)
5891 gcc_assert (!pending_ltrel
);
5892 pending_ltrel
= pool_ref
;
5897 if (GET_CODE (insn
) == JUMP_INSN
|| GET_CODE (insn
) == CODE_LABEL
)
5900 s390_add_pool_insn (curr_pool
, insn
);
5901 /* An LTREL_BASE must follow within the same basic block. */
5902 gcc_assert (!pending_ltrel
);
5906 || INSN_ADDRESSES_SIZE () <= (size_t) INSN_UID (insn
)
5907 || INSN_ADDRESSES (INSN_UID (insn
)) == -1)
5910 if (TARGET_CPU_ZARCH
)
5912 if (curr_pool
->size
< S390_POOL_CHUNK_MAX
)
5915 s390_end_pool (curr_pool
, NULL_RTX
);
5920 int chunk_size
= INSN_ADDRESSES (INSN_UID (insn
))
5921 - INSN_ADDRESSES (INSN_UID (curr_pool
->first_insn
))
5924 /* We will later have to insert base register reload insns.
5925 Those will have an effect on code size, which we need to
5926 consider here. This calculation makes rather pessimistic
5927 worst-case assumptions. */
5928 if (GET_CODE (insn
) == CODE_LABEL
)
5931 if (chunk_size
< S390_POOL_CHUNK_MIN
5932 && curr_pool
->size
< S390_POOL_CHUNK_MIN
)
5935 /* Pool chunks can only be inserted after BARRIERs ... */
5936 if (GET_CODE (insn
) == BARRIER
)
5938 s390_end_pool (curr_pool
, insn
);
5943 /* ... so if we don't find one in time, create one. */
5944 else if ((chunk_size
> S390_POOL_CHUNK_MAX
5945 || curr_pool
->size
> S390_POOL_CHUNK_MAX
))
5947 rtx label
, jump
, barrier
;
5949 /* We can insert the barrier only after a 'real' insn. */
5950 if (GET_CODE (insn
) != INSN
&& GET_CODE (insn
) != CALL_INSN
)
5952 if (get_attr_length (insn
) == 0)
5955 /* Don't separate LTREL_BASE from the corresponding
5956 LTREL_OFFSET load. */
5960 label
= gen_label_rtx ();
5961 jump
= emit_jump_insn_after (gen_jump (label
), insn
);
5962 barrier
= emit_barrier_after (jump
);
5963 insn
= emit_label_after (label
, barrier
);
5964 JUMP_LABEL (jump
) = label
;
5965 LABEL_NUSES (label
) = 1;
5967 INSN_ADDRESSES_NEW (jump
, -1);
5968 INSN_ADDRESSES_NEW (barrier
, -1);
5969 INSN_ADDRESSES_NEW (insn
, -1);
5971 s390_end_pool (curr_pool
, barrier
);
5979 s390_end_pool (curr_pool
, NULL_RTX
);
5980 gcc_assert (!pending_ltrel
);
5982 /* Find all labels that are branched into
5983 from an insn belonging to a different chunk. */
5985 far_labels
= BITMAP_ALLOC (NULL
);
5987 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5989 /* Labels marked with LABEL_PRESERVE_P can be target
5990 of non-local jumps, so we have to mark them.
5991 The same holds for named labels.
5993 Don't do that, however, if it is the label before
5996 if (GET_CODE (insn
) == CODE_LABEL
5997 && (LABEL_PRESERVE_P (insn
) || LABEL_NAME (insn
)))
5999 rtx vec_insn
= next_real_insn (insn
);
6000 rtx vec_pat
= vec_insn
&& GET_CODE (vec_insn
) == JUMP_INSN
?
6001 PATTERN (vec_insn
) : NULL_RTX
;
6003 || !(GET_CODE (vec_pat
) == ADDR_VEC
6004 || GET_CODE (vec_pat
) == ADDR_DIFF_VEC
))
6005 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (insn
));
6008 /* If we have a direct jump (conditional or unconditional)
6009 or a casesi jump, check all potential targets. */
6010 else if (GET_CODE (insn
) == JUMP_INSN
)
6012 rtx pat
= PATTERN (insn
);
6013 if (GET_CODE (pat
) == PARALLEL
&& XVECLEN (pat
, 0) > 2)
6014 pat
= XVECEXP (pat
, 0, 0);
6016 if (GET_CODE (pat
) == SET
)
6018 rtx label
= JUMP_LABEL (insn
);
6021 if (s390_find_pool (pool_list
, label
)
6022 != s390_find_pool (pool_list
, insn
))
6023 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (label
));
6026 else if (GET_CODE (pat
) == PARALLEL
6027 && XVECLEN (pat
, 0) == 2
6028 && GET_CODE (XVECEXP (pat
, 0, 0)) == SET
6029 && GET_CODE (XVECEXP (pat
, 0, 1)) == USE
6030 && GET_CODE (XEXP (XVECEXP (pat
, 0, 1), 0)) == LABEL_REF
)
6032 /* Find the jump table used by this casesi jump. */
6033 rtx vec_label
= XEXP (XEXP (XVECEXP (pat
, 0, 1), 0), 0);
6034 rtx vec_insn
= next_real_insn (vec_label
);
6035 rtx vec_pat
= vec_insn
&& GET_CODE (vec_insn
) == JUMP_INSN
?
6036 PATTERN (vec_insn
) : NULL_RTX
;
6038 && (GET_CODE (vec_pat
) == ADDR_VEC
6039 || GET_CODE (vec_pat
) == ADDR_DIFF_VEC
))
6041 int i
, diff_p
= GET_CODE (vec_pat
) == ADDR_DIFF_VEC
;
6043 for (i
= 0; i
< XVECLEN (vec_pat
, diff_p
); i
++)
6045 rtx label
= XEXP (XVECEXP (vec_pat
, diff_p
, i
), 0);
6047 if (s390_find_pool (pool_list
, label
)
6048 != s390_find_pool (pool_list
, insn
))
6049 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (label
));
6056 /* Insert base register reload insns before every pool. */
6058 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
6060 rtx new_insn
= gen_reload_base (cfun
->machine
->base_reg
,
6062 rtx insn
= curr_pool
->first_insn
;
6063 INSN_ADDRESSES_NEW (emit_insn_before (new_insn
, insn
), -1);
6066 /* Insert base register reload insns at every far label. */
6068 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6069 if (GET_CODE (insn
) == CODE_LABEL
6070 && bitmap_bit_p (far_labels
, CODE_LABEL_NUMBER (insn
)))
6072 struct constant_pool
*pool
= s390_find_pool (pool_list
, insn
);
6075 rtx new_insn
= gen_reload_base (cfun
->machine
->base_reg
,
6077 INSN_ADDRESSES_NEW (emit_insn_after (new_insn
, insn
), -1);
6082 BITMAP_FREE (far_labels
);
6085 /* Recompute insn addresses. */
6087 init_insn_lengths ();
6088 shorten_branches (get_insns ());
6093 /* POOL_LIST is a chunk list as prepared by s390_chunkify_start.
6094 After we have decided to use this list, finish implementing
6095 all changes to the current function as required. */
6098 s390_chunkify_finish (struct constant_pool
*pool_list
)
6100 struct constant_pool
*curr_pool
= NULL
;
6104 /* Replace all literal pool references. */
6106 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6109 replace_ltrel_base (&PATTERN (insn
));
6111 curr_pool
= s390_find_pool (pool_list
, insn
);
6115 if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
6117 rtx addr
, pool_ref
= NULL_RTX
;
6118 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
6121 if (s390_execute_label (insn
))
6122 addr
= s390_find_execute (curr_pool
, insn
);
6124 addr
= s390_find_constant (curr_pool
,
6125 get_pool_constant (pool_ref
),
6126 get_pool_mode (pool_ref
));
6128 replace_constant_pool_ref (&PATTERN (insn
), pool_ref
, addr
);
6129 INSN_CODE (insn
) = -1;
6134 /* Dump out all literal pools. */
6136 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
6137 s390_dump_pool (curr_pool
, 0);
6139 /* Free pool list. */
6143 struct constant_pool
*next
= pool_list
->next
;
6144 s390_free_pool (pool_list
);
6149 /* POOL_LIST is a chunk list as prepared by s390_chunkify_start.
6150 We have decided we cannot use this list, so revert all changes
6151 to the current function that were done by s390_chunkify_start. */
6154 s390_chunkify_cancel (struct constant_pool
*pool_list
)
6156 struct constant_pool
*curr_pool
= NULL
;
6159 /* Remove all pool placeholder insns. */
6161 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
6163 /* Did we insert an extra barrier? Remove it. */
6164 rtx barrier
= PREV_INSN (curr_pool
->pool_insn
);
6165 rtx jump
= barrier
? PREV_INSN (barrier
) : NULL_RTX
;
6166 rtx label
= NEXT_INSN (curr_pool
->pool_insn
);
6168 if (jump
&& GET_CODE (jump
) == JUMP_INSN
6169 && barrier
&& GET_CODE (barrier
) == BARRIER
6170 && label
&& GET_CODE (label
) == CODE_LABEL
6171 && GET_CODE (PATTERN (jump
)) == SET
6172 && SET_DEST (PATTERN (jump
)) == pc_rtx
6173 && GET_CODE (SET_SRC (PATTERN (jump
))) == LABEL_REF
6174 && XEXP (SET_SRC (PATTERN (jump
)), 0) == label
)
6177 remove_insn (barrier
);
6178 remove_insn (label
);
6181 remove_insn (curr_pool
->pool_insn
);
6184 /* Remove all base register reload insns. */
6186 for (insn
= get_insns (); insn
; )
6188 rtx next_insn
= NEXT_INSN (insn
);
6190 if (GET_CODE (insn
) == INSN
6191 && GET_CODE (PATTERN (insn
)) == SET
6192 && GET_CODE (SET_SRC (PATTERN (insn
))) == UNSPEC
6193 && XINT (SET_SRC (PATTERN (insn
)), 1) == UNSPEC_RELOAD_BASE
)
6199 /* Free pool list. */
6203 struct constant_pool
*next
= pool_list
->next
;
6204 s390_free_pool (pool_list
);
6210 /* Output the constant pool entry EXP in mode MODE with alignment ALIGN. */
6213 s390_output_pool_entry (rtx exp
, enum machine_mode mode
, unsigned int align
)
6217 switch (GET_MODE_CLASS (mode
))
6220 case MODE_DECIMAL_FLOAT
:
6221 gcc_assert (GET_CODE (exp
) == CONST_DOUBLE
);
6223 REAL_VALUE_FROM_CONST_DOUBLE (r
, exp
);
6224 assemble_real (r
, mode
, align
);
6228 assemble_integer (exp
, GET_MODE_SIZE (mode
), align
, 1);
6237 /* Return an RTL expression representing the value of the return address
6238 for the frame COUNT steps up from the current frame. FRAME is the
6239 frame pointer of that frame. */
6242 s390_return_addr_rtx (int count
, rtx frame ATTRIBUTE_UNUSED
)
6247 /* Without backchain, we fail for all but the current frame. */
6249 if (!TARGET_BACKCHAIN
&& count
> 0)
6252 /* For the current frame, we need to make sure the initial
6253 value of RETURN_REGNUM is actually saved. */
6257 /* On non-z architectures branch splitting could overwrite r14. */
6258 if (TARGET_CPU_ZARCH
)
6259 return get_hard_reg_initial_val (Pmode
, RETURN_REGNUM
);
6262 cfun_frame_layout
.save_return_addr_p
= true;
6263 return gen_rtx_MEM (Pmode
, return_address_pointer_rtx
);
6267 if (TARGET_PACKED_STACK
)
6268 offset
= -2 * UNITS_PER_WORD
;
6270 offset
= RETURN_REGNUM
* UNITS_PER_WORD
;
6272 addr
= plus_constant (frame
, offset
);
6273 addr
= memory_address (Pmode
, addr
);
6274 return gen_rtx_MEM (Pmode
, addr
);
6277 /* Return an RTL expression representing the back chain stored in
6278 the current stack frame. */
6281 s390_back_chain_rtx (void)
6285 gcc_assert (TARGET_BACKCHAIN
);
6287 if (TARGET_PACKED_STACK
)
6288 chain
= plus_constant (stack_pointer_rtx
,
6289 STACK_POINTER_OFFSET
- UNITS_PER_WORD
);
6291 chain
= stack_pointer_rtx
;
6293 chain
= gen_rtx_MEM (Pmode
, chain
);
6297 /* Find first call clobbered register unused in a function.
6298 This could be used as base register in a leaf function
6299 or for holding the return address before epilogue. */
6302 find_unused_clobbered_reg (void)
6305 for (i
= 0; i
< 6; i
++)
6306 if (!regs_ever_live
[i
])
6312 /* Helper function for s390_regs_ever_clobbered. Sets the fields in DATA for all
6313 clobbered hard regs in SETREG. */
6316 s390_reg_clobbered_rtx (rtx setreg
, rtx set_insn ATTRIBUTE_UNUSED
, void *data
)
6318 int *regs_ever_clobbered
= (int *)data
;
6319 unsigned int i
, regno
;
6320 enum machine_mode mode
= GET_MODE (setreg
);
6322 if (GET_CODE (setreg
) == SUBREG
)
6324 rtx inner
= SUBREG_REG (setreg
);
6325 if (!GENERAL_REG_P (inner
))
6327 regno
= subreg_regno (setreg
);
6329 else if (GENERAL_REG_P (setreg
))
6330 regno
= REGNO (setreg
);
6335 i
< regno
+ HARD_REGNO_NREGS (regno
, mode
);
6337 regs_ever_clobbered
[i
] = 1;
6340 /* Walks through all basic blocks of the current function looking
6341 for clobbered hard regs using s390_reg_clobbered_rtx. The fields
6342 of the passed integer array REGS_EVER_CLOBBERED are set to one for
6343 each of those regs. */
6346 s390_regs_ever_clobbered (int *regs_ever_clobbered
)
6352 memset (regs_ever_clobbered
, 0, 16 * sizeof (int));
6354 /* For non-leaf functions we have to consider all call clobbered regs to be
6356 if (!current_function_is_leaf
)
6358 for (i
= 0; i
< 16; i
++)
6359 regs_ever_clobbered
[i
] = call_really_used_regs
[i
];
6362 /* Make the "magic" eh_return registers live if necessary. For regs_ever_live
6363 this work is done by liveness analysis (mark_regs_live_at_end).
6364 Special care is needed for functions containing landing pads. Landing pads
6365 may use the eh registers, but the code which sets these registers is not
6366 contained in that function. Hence s390_regs_ever_clobbered is not able to
6367 deal with this automatically. */
6368 if (current_function_calls_eh_return
|| cfun
->machine
->has_landing_pad_p
)
6369 for (i
= 0; EH_RETURN_DATA_REGNO (i
) != INVALID_REGNUM
; i
++)
6370 if (current_function_calls_eh_return
6371 || (cfun
->machine
->has_landing_pad_p
6372 && regs_ever_live
[EH_RETURN_DATA_REGNO (i
)]))
6373 regs_ever_clobbered
[EH_RETURN_DATA_REGNO (i
)] = 1;
6375 /* For nonlocal gotos all call-saved registers have to be saved.
6376 This flag is also set for the unwinding code in libgcc.
6377 See expand_builtin_unwind_init. For regs_ever_live this is done by
6379 if (current_function_has_nonlocal_label
)
6380 for (i
= 0; i
< 16; i
++)
6381 if (!call_really_used_regs
[i
])
6382 regs_ever_clobbered
[i
] = 1;
6384 FOR_EACH_BB (cur_bb
)
6386 FOR_BB_INSNS (cur_bb
, cur_insn
)
6388 if (INSN_P (cur_insn
))
6389 note_stores (PATTERN (cur_insn
),
6390 s390_reg_clobbered_rtx
,
6391 regs_ever_clobbered
);
6396 /* Determine the frame area which actually has to be accessed
6397 in the function epilogue. The values are stored at the
6398 given pointers AREA_BOTTOM (address of the lowest used stack
6399 address) and AREA_TOP (address of the first item which does
6400 not belong to the stack frame). */
6403 s390_frame_area (int *area_bottom
, int *area_top
)
6411 if (cfun_frame_layout
.first_restore_gpr
!= -1)
6413 b
= (cfun_frame_layout
.gprs_offset
6414 + cfun_frame_layout
.first_restore_gpr
* UNITS_PER_WORD
);
6415 t
= b
+ (cfun_frame_layout
.last_restore_gpr
6416 - cfun_frame_layout
.first_restore_gpr
+ 1) * UNITS_PER_WORD
;
6419 if (TARGET_64BIT
&& cfun_save_high_fprs_p
)
6421 b
= MIN (b
, cfun_frame_layout
.f8_offset
);
6422 t
= MAX (t
, (cfun_frame_layout
.f8_offset
6423 + cfun_frame_layout
.high_fprs
* 8));
6427 for (i
= 2; i
< 4; i
++)
6428 if (cfun_fpr_bit_p (i
))
6430 b
= MIN (b
, cfun_frame_layout
.f4_offset
+ (i
- 2) * 8);
6431 t
= MAX (t
, cfun_frame_layout
.f4_offset
+ (i
- 1) * 8);
6438 /* Fill cfun->machine with info about register usage of current function.
6439 Return in CLOBBERED_REGS which GPRs are currently considered set. */
6442 s390_register_info (int clobbered_regs
[])
6446 /* fprs 8 - 15 are call saved for 64 Bit ABI. */
6447 cfun_frame_layout
.fpr_bitmap
= 0;
6448 cfun_frame_layout
.high_fprs
= 0;
6450 for (i
= 24; i
< 32; i
++)
6451 if (regs_ever_live
[i
] && !global_regs
[i
])
6453 cfun_set_fpr_bit (i
- 16);
6454 cfun_frame_layout
.high_fprs
++;
6457 /* Find first and last gpr to be saved. We trust regs_ever_live
6458 data, except that we don't save and restore global registers.
6460 Also, all registers with special meaning to the compiler need
6461 to be handled extra. */
6463 s390_regs_ever_clobbered (clobbered_regs
);
6465 for (i
= 0; i
< 16; i
++)
6466 clobbered_regs
[i
] = clobbered_regs
[i
] && !global_regs
[i
] && !fixed_regs
[i
];
6468 if (frame_pointer_needed
)
6469 clobbered_regs
[HARD_FRAME_POINTER_REGNUM
] = 1;
6472 clobbered_regs
[PIC_OFFSET_TABLE_REGNUM
]
6473 |= regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
];
6475 clobbered_regs
[BASE_REGNUM
]
6476 |= (cfun
->machine
->base_reg
6477 && REGNO (cfun
->machine
->base_reg
) == BASE_REGNUM
);
6479 clobbered_regs
[RETURN_REGNUM
]
6480 |= (!current_function_is_leaf
6481 || TARGET_TPF_PROFILING
6482 || cfun
->machine
->split_branches_pending_p
6483 || cfun_frame_layout
.save_return_addr_p
6484 || current_function_calls_eh_return
6485 || current_function_stdarg
);
6487 clobbered_regs
[STACK_POINTER_REGNUM
]
6488 |= (!current_function_is_leaf
6489 || TARGET_TPF_PROFILING
6490 || cfun_save_high_fprs_p
6491 || get_frame_size () > 0
6492 || current_function_calls_alloca
6493 || current_function_stdarg
);
6495 for (i
= 6; i
< 16; i
++)
6496 if (regs_ever_live
[i
] || clobbered_regs
[i
])
6498 for (j
= 15; j
> i
; j
--)
6499 if (regs_ever_live
[j
] || clobbered_regs
[j
])
6504 /* Nothing to save/restore. */
6505 cfun_frame_layout
.first_save_gpr_slot
= -1;
6506 cfun_frame_layout
.last_save_gpr_slot
= -1;
6507 cfun_frame_layout
.first_save_gpr
= -1;
6508 cfun_frame_layout
.first_restore_gpr
= -1;
6509 cfun_frame_layout
.last_save_gpr
= -1;
6510 cfun_frame_layout
.last_restore_gpr
= -1;
6514 /* Save slots for gprs from i to j. */
6515 cfun_frame_layout
.first_save_gpr_slot
= i
;
6516 cfun_frame_layout
.last_save_gpr_slot
= j
;
6518 for (i
= cfun_frame_layout
.first_save_gpr_slot
;
6519 i
< cfun_frame_layout
.last_save_gpr_slot
+ 1;
6521 if (clobbered_regs
[i
])
6524 for (j
= cfun_frame_layout
.last_save_gpr_slot
; j
> i
; j
--)
6525 if (clobbered_regs
[j
])
6528 if (i
== cfun_frame_layout
.last_save_gpr_slot
+ 1)
6530 /* Nothing to save/restore. */
6531 cfun_frame_layout
.first_save_gpr
= -1;
6532 cfun_frame_layout
.first_restore_gpr
= -1;
6533 cfun_frame_layout
.last_save_gpr
= -1;
6534 cfun_frame_layout
.last_restore_gpr
= -1;
6538 /* Save / Restore from gpr i to j. */
6539 cfun_frame_layout
.first_save_gpr
= i
;
6540 cfun_frame_layout
.first_restore_gpr
= i
;
6541 cfun_frame_layout
.last_save_gpr
= j
;
6542 cfun_frame_layout
.last_restore_gpr
= j
;
6546 if (current_function_stdarg
)
6548 /* Varargs functions need to save gprs 2 to 6. */
6549 if (cfun
->va_list_gpr_size
6550 && current_function_args_info
.gprs
< GP_ARG_NUM_REG
)
6552 int min_gpr
= current_function_args_info
.gprs
;
6553 int max_gpr
= min_gpr
+ cfun
->va_list_gpr_size
;
6554 if (max_gpr
> GP_ARG_NUM_REG
)
6555 max_gpr
= GP_ARG_NUM_REG
;
6557 if (cfun_frame_layout
.first_save_gpr
== -1
6558 || cfun_frame_layout
.first_save_gpr
> 2 + min_gpr
)
6560 cfun_frame_layout
.first_save_gpr
= 2 + min_gpr
;
6561 cfun_frame_layout
.first_save_gpr_slot
= 2 + min_gpr
;
6564 if (cfun_frame_layout
.last_save_gpr
== -1
6565 || cfun_frame_layout
.last_save_gpr
< 2 + max_gpr
- 1)
6567 cfun_frame_layout
.last_save_gpr
= 2 + max_gpr
- 1;
6568 cfun_frame_layout
.last_save_gpr_slot
= 2 + max_gpr
- 1;
6572 /* Mark f0, f2 for 31 bit and f0-f4 for 64 bit to be saved. */
6573 if (TARGET_HARD_FLOAT
&& cfun
->va_list_fpr_size
6574 && current_function_args_info
.fprs
< FP_ARG_NUM_REG
)
6576 int min_fpr
= current_function_args_info
.fprs
;
6577 int max_fpr
= min_fpr
+ cfun
->va_list_fpr_size
;
6578 if (max_fpr
> FP_ARG_NUM_REG
)
6579 max_fpr
= FP_ARG_NUM_REG
;
6581 /* ??? This is currently required to ensure proper location
6582 of the fpr save slots within the va_list save area. */
6583 if (TARGET_PACKED_STACK
)
6586 for (i
= min_fpr
; i
< max_fpr
; i
++)
6587 cfun_set_fpr_bit (i
);
6592 for (i
= 2; i
< 4; i
++)
6593 if (regs_ever_live
[i
+ 16] && !global_regs
[i
+ 16])
6594 cfun_set_fpr_bit (i
);
6597 /* Fill cfun->machine with info about frame of current function. */
6600 s390_frame_info (void)
6604 cfun_frame_layout
.frame_size
= get_frame_size ();
6605 if (!TARGET_64BIT
&& cfun_frame_layout
.frame_size
> 0x7fff0000)
6606 fatal_error ("total size of local variables exceeds architecture limit");
6608 if (!TARGET_PACKED_STACK
)
6610 cfun_frame_layout
.backchain_offset
= 0;
6611 cfun_frame_layout
.f0_offset
= 16 * UNITS_PER_WORD
;
6612 cfun_frame_layout
.f4_offset
= cfun_frame_layout
.f0_offset
+ 2 * 8;
6613 cfun_frame_layout
.f8_offset
= -cfun_frame_layout
.high_fprs
* 8;
6614 cfun_frame_layout
.gprs_offset
= (cfun_frame_layout
.first_save_gpr_slot
6617 else if (TARGET_BACKCHAIN
) /* kernel stack layout */
6619 cfun_frame_layout
.backchain_offset
= (STACK_POINTER_OFFSET
6621 cfun_frame_layout
.gprs_offset
6622 = (cfun_frame_layout
.backchain_offset
6623 - (STACK_POINTER_REGNUM
- cfun_frame_layout
.first_save_gpr_slot
+ 1)
6628 cfun_frame_layout
.f4_offset
6629 = (cfun_frame_layout
.gprs_offset
6630 - 8 * (cfun_fpr_bit_p (2) + cfun_fpr_bit_p (3)));
6632 cfun_frame_layout
.f0_offset
6633 = (cfun_frame_layout
.f4_offset
6634 - 8 * (cfun_fpr_bit_p (0) + cfun_fpr_bit_p (1)));
6638 /* On 31 bit we have to care about alignment of the
6639 floating point regs to provide fastest access. */
6640 cfun_frame_layout
.f0_offset
6641 = ((cfun_frame_layout
.gprs_offset
6642 & ~(STACK_BOUNDARY
/ BITS_PER_UNIT
- 1))
6643 - 8 * (cfun_fpr_bit_p (0) + cfun_fpr_bit_p (1)));
6645 cfun_frame_layout
.f4_offset
6646 = (cfun_frame_layout
.f0_offset
6647 - 8 * (cfun_fpr_bit_p (2) + cfun_fpr_bit_p (3)));
6650 else /* no backchain */
6652 cfun_frame_layout
.f4_offset
6653 = (STACK_POINTER_OFFSET
6654 - 8 * (cfun_fpr_bit_p (2) + cfun_fpr_bit_p (3)));
6656 cfun_frame_layout
.f0_offset
6657 = (cfun_frame_layout
.f4_offset
6658 - 8 * (cfun_fpr_bit_p (0) + cfun_fpr_bit_p (1)));
6660 cfun_frame_layout
.gprs_offset
6661 = cfun_frame_layout
.f0_offset
- cfun_gprs_save_area_size
;
6664 if (current_function_is_leaf
6665 && !TARGET_TPF_PROFILING
6666 && cfun_frame_layout
.frame_size
== 0
6667 && !cfun_save_high_fprs_p
6668 && !current_function_calls_alloca
6669 && !current_function_stdarg
)
6672 if (!TARGET_PACKED_STACK
)
6673 cfun_frame_layout
.frame_size
+= (STACK_POINTER_OFFSET
6674 + current_function_outgoing_args_size
6675 + cfun_frame_layout
.high_fprs
* 8);
6678 if (TARGET_BACKCHAIN
)
6679 cfun_frame_layout
.frame_size
+= UNITS_PER_WORD
;
6681 /* No alignment trouble here because f8-f15 are only saved under
6683 cfun_frame_layout
.f8_offset
= (MIN (MIN (cfun_frame_layout
.f0_offset
,
6684 cfun_frame_layout
.f4_offset
),
6685 cfun_frame_layout
.gprs_offset
)
6686 - cfun_frame_layout
.high_fprs
* 8);
6688 cfun_frame_layout
.frame_size
+= cfun_frame_layout
.high_fprs
* 8;
6690 for (i
= 0; i
< 8; i
++)
6691 if (cfun_fpr_bit_p (i
))
6692 cfun_frame_layout
.frame_size
+= 8;
6694 cfun_frame_layout
.frame_size
+= cfun_gprs_save_area_size
;
6696 /* If under 31 bit an odd number of gprs has to be saved we have to adjust
6697 the frame size to sustain 8 byte alignment of stack frames. */
6698 cfun_frame_layout
.frame_size
= ((cfun_frame_layout
.frame_size
+
6699 STACK_BOUNDARY
/ BITS_PER_UNIT
- 1)
6700 & ~(STACK_BOUNDARY
/ BITS_PER_UNIT
- 1));
6702 cfun_frame_layout
.frame_size
+= current_function_outgoing_args_size
;
6706 /* Generate frame layout. Fills in register and frame data for the current
6707 function in cfun->machine. This routine can be called multiple times;
6708 it will re-do the complete frame layout every time. */
6711 s390_init_frame_layout (void)
6713 HOST_WIDE_INT frame_size
;
6715 int clobbered_regs
[16];
6717 /* On S/390 machines, we may need to perform branch splitting, which
6718 will require both base and return address register. We have no
6719 choice but to assume we're going to need them until right at the
6720 end of the machine dependent reorg phase. */
6721 if (!TARGET_CPU_ZARCH
)
6722 cfun
->machine
->split_branches_pending_p
= true;
6726 frame_size
= cfun_frame_layout
.frame_size
;
6728 /* Try to predict whether we'll need the base register. */
6729 base_used
= cfun
->machine
->split_branches_pending_p
6730 || current_function_uses_const_pool
6731 || (!DISP_IN_RANGE (-frame_size
)
6732 && !CONST_OK_FOR_K (-frame_size
));
6734 /* Decide which register to use as literal pool base. In small
6735 leaf functions, try to use an unused call-clobbered register
6736 as base register to avoid save/restore overhead. */
6738 cfun
->machine
->base_reg
= NULL_RTX
;
6739 else if (current_function_is_leaf
&& !regs_ever_live
[5])
6740 cfun
->machine
->base_reg
= gen_rtx_REG (Pmode
, 5);
6742 cfun
->machine
->base_reg
= gen_rtx_REG (Pmode
, BASE_REGNUM
);
6744 s390_register_info (clobbered_regs
);
6747 while (frame_size
!= cfun_frame_layout
.frame_size
);
6750 /* Update frame layout. Recompute actual register save data based on
6751 current info and update regs_ever_live for the special registers.
6752 May be called multiple times, but may never cause *more* registers
6753 to be saved than s390_init_frame_layout allocated room for. */
6756 s390_update_frame_layout (void)
6758 int clobbered_regs
[16];
6760 s390_register_info (clobbered_regs
);
6762 regs_ever_live
[BASE_REGNUM
] = clobbered_regs
[BASE_REGNUM
];
6763 regs_ever_live
[RETURN_REGNUM
] = clobbered_regs
[RETURN_REGNUM
];
6764 regs_ever_live
[STACK_POINTER_REGNUM
] = clobbered_regs
[STACK_POINTER_REGNUM
];
6766 if (cfun
->machine
->base_reg
)
6767 regs_ever_live
[REGNO (cfun
->machine
->base_reg
)] = 1;
6770 /* Return true if it is legal to put a value with MODE into REGNO. */
6773 s390_hard_regno_mode_ok (unsigned int regno
, enum machine_mode mode
)
6775 switch (REGNO_REG_CLASS (regno
))
6778 if (REGNO_PAIR_OK (regno
, mode
))
6780 if (mode
== SImode
|| mode
== DImode
)
6783 if (FLOAT_MODE_P (mode
) && GET_MODE_CLASS (mode
) != MODE_VECTOR_FLOAT
)
6788 if (FRAME_REGNO_P (regno
) && mode
== Pmode
)
6793 if (REGNO_PAIR_OK (regno
, mode
))
6796 || (mode
!= TFmode
&& mode
!= TCmode
&& mode
!= TDmode
))
6801 if (GET_MODE_CLASS (mode
) == MODE_CC
)
6805 if (REGNO_PAIR_OK (regno
, mode
))
6807 if (mode
== SImode
|| mode
== Pmode
)
6818 /* Return nonzero if register OLD_REG can be renamed to register NEW_REG. */
6821 s390_hard_regno_rename_ok (unsigned int old_reg
, unsigned int new_reg
)
6823 /* Once we've decided upon a register to use as base register, it must
6824 no longer be used for any other purpose. */
6825 if (cfun
->machine
->base_reg
)
6826 if (REGNO (cfun
->machine
->base_reg
) == old_reg
6827 || REGNO (cfun
->machine
->base_reg
) == new_reg
)
6833 /* Maximum number of registers to represent a value of mode MODE
6834 in a register of class CLASS. */
6837 s390_class_max_nregs (enum reg_class
class, enum machine_mode mode
)
6842 if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
)
6843 return 2 * ((GET_MODE_SIZE (mode
) / 2 + 8 - 1) / 8);
6845 return (GET_MODE_SIZE (mode
) + 8 - 1) / 8;
6847 return (GET_MODE_SIZE (mode
) + 4 - 1) / 4;
6851 return (GET_MODE_SIZE (mode
) + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
6854 /* Return true if register FROM can be eliminated via register TO. */
6857 s390_can_eliminate (int from
, int to
)
6859 /* On zSeries machines, we have not marked the base register as fixed.
6860 Instead, we have an elimination rule BASE_REGNUM -> BASE_REGNUM.
6861 If a function requires the base register, we say here that this
6862 elimination cannot be performed. This will cause reload to free
6863 up the base register (as if it were fixed). On the other hand,
6864 if the current function does *not* require the base register, we
6865 say here the elimination succeeds, which in turn allows reload
6866 to allocate the base register for any other purpose. */
6867 if (from
== BASE_REGNUM
&& to
== BASE_REGNUM
)
6869 if (TARGET_CPU_ZARCH
)
6871 s390_init_frame_layout ();
6872 return cfun
->machine
->base_reg
== NULL_RTX
;
6878 /* Everything else must point into the stack frame. */
6879 gcc_assert (to
== STACK_POINTER_REGNUM
6880 || to
== HARD_FRAME_POINTER_REGNUM
);
6882 gcc_assert (from
== FRAME_POINTER_REGNUM
6883 || from
== ARG_POINTER_REGNUM
6884 || from
== RETURN_ADDRESS_POINTER_REGNUM
);
6886 /* Make sure we actually saved the return address. */
6887 if (from
== RETURN_ADDRESS_POINTER_REGNUM
)
6888 if (!current_function_calls_eh_return
6889 && !current_function_stdarg
6890 && !cfun_frame_layout
.save_return_addr_p
)
6896 /* Return offset between register FROM and TO initially after prolog. */
6899 s390_initial_elimination_offset (int from
, int to
)
6901 HOST_WIDE_INT offset
;
6904 /* ??? Why are we called for non-eliminable pairs? */
6905 if (!s390_can_eliminate (from
, to
))
6910 case FRAME_POINTER_REGNUM
:
6911 offset
= (get_frame_size()
6912 + STACK_POINTER_OFFSET
6913 + current_function_outgoing_args_size
);
6916 case ARG_POINTER_REGNUM
:
6917 s390_init_frame_layout ();
6918 offset
= cfun_frame_layout
.frame_size
+ STACK_POINTER_OFFSET
;
6921 case RETURN_ADDRESS_POINTER_REGNUM
:
6922 s390_init_frame_layout ();
6923 index
= RETURN_REGNUM
- cfun_frame_layout
.first_save_gpr_slot
;
6924 gcc_assert (index
>= 0);
6925 offset
= cfun_frame_layout
.frame_size
+ cfun_frame_layout
.gprs_offset
;
6926 offset
+= index
* UNITS_PER_WORD
;
6940 /* Emit insn to save fpr REGNUM at offset OFFSET relative
6941 to register BASE. Return generated insn. */
6944 save_fpr (rtx base
, int offset
, int regnum
)
6947 addr
= gen_rtx_MEM (DFmode
, plus_constant (base
, offset
));
6949 if (regnum
>= 16 && regnum
<= (16 + FP_ARG_NUM_REG
))
6950 set_mem_alias_set (addr
, get_varargs_alias_set ());
6952 set_mem_alias_set (addr
, get_frame_alias_set ());
6954 return emit_move_insn (addr
, gen_rtx_REG (DFmode
, regnum
));
6957 /* Emit insn to restore fpr REGNUM from offset OFFSET relative
6958 to register BASE. Return generated insn. */
6961 restore_fpr (rtx base
, int offset
, int regnum
)
6964 addr
= gen_rtx_MEM (DFmode
, plus_constant (base
, offset
));
6965 set_mem_alias_set (addr
, get_frame_alias_set ());
6967 return emit_move_insn (gen_rtx_REG (DFmode
, regnum
), addr
);
6970 /* Generate insn to save registers FIRST to LAST into
6971 the register save area located at offset OFFSET
6972 relative to register BASE. */
6975 save_gprs (rtx base
, int offset
, int first
, int last
)
6977 rtx addr
, insn
, note
;
6980 addr
= plus_constant (base
, offset
);
6981 addr
= gen_rtx_MEM (Pmode
, addr
);
6983 set_mem_alias_set (addr
, get_frame_alias_set ());
6985 /* Special-case single register. */
6989 insn
= gen_movdi (addr
, gen_rtx_REG (Pmode
, first
));
6991 insn
= gen_movsi (addr
, gen_rtx_REG (Pmode
, first
));
6993 RTX_FRAME_RELATED_P (insn
) = 1;
6998 insn
= gen_store_multiple (addr
,
6999 gen_rtx_REG (Pmode
, first
),
7000 GEN_INT (last
- first
+ 1));
7002 if (first
<= 6 && current_function_stdarg
)
7003 for (i
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
7005 rtx mem
= XEXP (XVECEXP (PATTERN (insn
), 0, i
), 0);
7008 set_mem_alias_set (mem
, get_varargs_alias_set ());
7011 /* We need to set the FRAME_RELATED flag on all SETs
7012 inside the store-multiple pattern.
7014 However, we must not emit DWARF records for registers 2..5
7015 if they are stored for use by variable arguments ...
7017 ??? Unfortunately, it is not enough to simply not the
7018 FRAME_RELATED flags for those SETs, because the first SET
7019 of the PARALLEL is always treated as if it had the flag
7020 set, even if it does not. Therefore we emit a new pattern
7021 without those registers as REG_FRAME_RELATED_EXPR note. */
7025 rtx pat
= PATTERN (insn
);
7027 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
7028 if (GET_CODE (XVECEXP (pat
, 0, i
)) == SET
)
7029 RTX_FRAME_RELATED_P (XVECEXP (pat
, 0, i
)) = 1;
7031 RTX_FRAME_RELATED_P (insn
) = 1;
7035 addr
= plus_constant (base
, offset
+ (6 - first
) * UNITS_PER_WORD
);
7036 note
= gen_store_multiple (gen_rtx_MEM (Pmode
, addr
),
7037 gen_rtx_REG (Pmode
, 6),
7038 GEN_INT (last
- 6 + 1));
7039 note
= PATTERN (note
);
7042 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR
,
7043 note
, REG_NOTES (insn
));
7045 for (i
= 0; i
< XVECLEN (note
, 0); i
++)
7046 if (GET_CODE (XVECEXP (note
, 0, i
)) == SET
)
7047 RTX_FRAME_RELATED_P (XVECEXP (note
, 0, i
)) = 1;
7049 RTX_FRAME_RELATED_P (insn
) = 1;
7055 /* Generate insn to restore registers FIRST to LAST from
7056 the register save area located at offset OFFSET
7057 relative to register BASE. */
7060 restore_gprs (rtx base
, int offset
, int first
, int last
)
7064 addr
= plus_constant (base
, offset
);
7065 addr
= gen_rtx_MEM (Pmode
, addr
);
7066 set_mem_alias_set (addr
, get_frame_alias_set ());
7068 /* Special-case single register. */
7072 insn
= gen_movdi (gen_rtx_REG (Pmode
, first
), addr
);
7074 insn
= gen_movsi (gen_rtx_REG (Pmode
, first
), addr
);
7079 insn
= gen_load_multiple (gen_rtx_REG (Pmode
, first
),
7081 GEN_INT (last
- first
+ 1));
7085 /* Return insn sequence to load the GOT register. */
7087 static GTY(()) rtx got_symbol
;
7089 s390_load_got (void)
7095 got_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "_GLOBAL_OFFSET_TABLE_");
7096 SYMBOL_REF_FLAGS (got_symbol
) = SYMBOL_FLAG_LOCAL
;
7101 if (TARGET_CPU_ZARCH
)
7103 emit_move_insn (pic_offset_table_rtx
, got_symbol
);
7109 offset
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, got_symbol
),
7110 UNSPEC_LTREL_OFFSET
);
7111 offset
= gen_rtx_CONST (Pmode
, offset
);
7112 offset
= force_const_mem (Pmode
, offset
);
7114 emit_move_insn (pic_offset_table_rtx
, offset
);
7116 offset
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, XEXP (offset
, 0)),
7118 offset
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, offset
);
7120 emit_move_insn (pic_offset_table_rtx
, offset
);
7123 insns
= get_insns ();
7128 /* Expand the prologue into a bunch of separate insns. */
7131 s390_emit_prologue (void)
7139 /* Complete frame layout. */
7141 s390_update_frame_layout ();
7143 /* Annotate all constant pool references to let the scheduler know
7144 they implicitly use the base register. */
7146 push_topmost_sequence ();
7148 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
7150 annotate_constant_pool_refs (&PATTERN (insn
));
7152 pop_topmost_sequence ();
7154 /* Choose best register to use for temp use within prologue.
7155 See below for why TPF must use the register 1. */
7157 if (!has_hard_reg_initial_val (Pmode
, RETURN_REGNUM
)
7158 && !current_function_is_leaf
7159 && !TARGET_TPF_PROFILING
)
7160 temp_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
7162 temp_reg
= gen_rtx_REG (Pmode
, 1);
7164 /* Save call saved gprs. */
7165 if (cfun_frame_layout
.first_save_gpr
!= -1)
7167 insn
= save_gprs (stack_pointer_rtx
,
7168 cfun_frame_layout
.gprs_offset
+
7169 UNITS_PER_WORD
* (cfun_frame_layout
.first_save_gpr
7170 - cfun_frame_layout
.first_save_gpr_slot
),
7171 cfun_frame_layout
.first_save_gpr
,
7172 cfun_frame_layout
.last_save_gpr
);
7176 /* Dummy insn to mark literal pool slot. */
7178 if (cfun
->machine
->base_reg
)
7179 emit_insn (gen_main_pool (cfun
->machine
->base_reg
));
7181 offset
= cfun_frame_layout
.f0_offset
;
7183 /* Save f0 and f2. */
7184 for (i
= 0; i
< 2; i
++)
7186 if (cfun_fpr_bit_p (i
))
7188 save_fpr (stack_pointer_rtx
, offset
, i
+ 16);
7191 else if (!TARGET_PACKED_STACK
)
7195 /* Save f4 and f6. */
7196 offset
= cfun_frame_layout
.f4_offset
;
7197 for (i
= 2; i
< 4; i
++)
7199 if (cfun_fpr_bit_p (i
))
7201 insn
= save_fpr (stack_pointer_rtx
, offset
, i
+ 16);
7204 /* If f4 and f6 are call clobbered they are saved due to stdargs and
7205 therefore are not frame related. */
7206 if (!call_really_used_regs
[i
+ 16])
7207 RTX_FRAME_RELATED_P (insn
) = 1;
7209 else if (!TARGET_PACKED_STACK
)
7213 if (TARGET_PACKED_STACK
7214 && cfun_save_high_fprs_p
7215 && cfun_frame_layout
.f8_offset
+ cfun_frame_layout
.high_fprs
* 8 > 0)
7217 offset
= (cfun_frame_layout
.f8_offset
7218 + (cfun_frame_layout
.high_fprs
- 1) * 8);
7220 for (i
= 15; i
> 7 && offset
>= 0; i
--)
7221 if (cfun_fpr_bit_p (i
))
7223 insn
= save_fpr (stack_pointer_rtx
, offset
, i
+ 16);
7225 RTX_FRAME_RELATED_P (insn
) = 1;
7228 if (offset
>= cfun_frame_layout
.f8_offset
)
7232 if (!TARGET_PACKED_STACK
)
7233 next_fpr
= cfun_save_high_fprs_p
? 31 : 0;
7235 /* Decrement stack pointer. */
7237 if (cfun_frame_layout
.frame_size
> 0)
7239 rtx frame_off
= GEN_INT (-cfun_frame_layout
.frame_size
);
7241 if (s390_stack_size
)
7243 HOST_WIDE_INT stack_check_mask
= ((s390_stack_size
- 1)
7244 & ~(s390_stack_guard
- 1));
7245 rtx t
= gen_rtx_AND (Pmode
, stack_pointer_rtx
,
7246 GEN_INT (stack_check_mask
));
7249 gen_cmpdi (t
, const0_rtx
);
7251 gen_cmpsi (t
, const0_rtx
);
7253 emit_insn (gen_conditional_trap (gen_rtx_EQ (CCmode
,
7254 gen_rtx_REG (CCmode
,
7260 if (s390_warn_framesize
> 0
7261 && cfun_frame_layout
.frame_size
>= s390_warn_framesize
)
7262 warning (0, "frame size of %qs is " HOST_WIDE_INT_PRINT_DEC
" bytes",
7263 current_function_name (), cfun_frame_layout
.frame_size
);
7265 if (s390_warn_dynamicstack_p
&& cfun
->calls_alloca
)
7266 warning (0, "%qs uses dynamic stack allocation", current_function_name ());
7268 /* Save incoming stack pointer into temp reg. */
7269 if (TARGET_BACKCHAIN
|| next_fpr
)
7270 insn
= emit_insn (gen_move_insn (temp_reg
, stack_pointer_rtx
));
7272 /* Subtract frame size from stack pointer. */
7274 if (DISP_IN_RANGE (INTVAL (frame_off
)))
7276 insn
= gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
7277 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
7279 insn
= emit_insn (insn
);
7283 if (!CONST_OK_FOR_K (INTVAL (frame_off
)))
7284 frame_off
= force_const_mem (Pmode
, frame_off
);
7286 insn
= emit_insn (gen_add2_insn (stack_pointer_rtx
, frame_off
));
7287 annotate_constant_pool_refs (&PATTERN (insn
));
7290 RTX_FRAME_RELATED_P (insn
) = 1;
7292 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR
,
7293 gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
7294 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
7295 GEN_INT (-cfun_frame_layout
.frame_size
))),
7298 /* Set backchain. */
7300 if (TARGET_BACKCHAIN
)
7302 if (cfun_frame_layout
.backchain_offset
)
7303 addr
= gen_rtx_MEM (Pmode
,
7304 plus_constant (stack_pointer_rtx
,
7305 cfun_frame_layout
.backchain_offset
));
7307 addr
= gen_rtx_MEM (Pmode
, stack_pointer_rtx
);
7308 set_mem_alias_set (addr
, get_frame_alias_set ());
7309 insn
= emit_insn (gen_move_insn (addr
, temp_reg
));
7312 /* If we support asynchronous exceptions (e.g. for Java),
7313 we need to make sure the backchain pointer is set up
7314 before any possibly trapping memory access. */
7316 if (TARGET_BACKCHAIN
&& flag_non_call_exceptions
)
7318 addr
= gen_rtx_MEM (BLKmode
, gen_rtx_SCRATCH (VOIDmode
));
7319 emit_insn (gen_rtx_CLOBBER (VOIDmode
, addr
));
7323 /* Save fprs 8 - 15 (64 bit ABI). */
7325 if (cfun_save_high_fprs_p
&& next_fpr
)
7327 insn
= emit_insn (gen_add2_insn (temp_reg
,
7328 GEN_INT (cfun_frame_layout
.f8_offset
)));
7332 for (i
= 24; i
<= next_fpr
; i
++)
7333 if (cfun_fpr_bit_p (i
- 16))
7335 rtx addr
= plus_constant (stack_pointer_rtx
,
7336 cfun_frame_layout
.frame_size
7337 + cfun_frame_layout
.f8_offset
7340 insn
= save_fpr (temp_reg
, offset
, i
);
7342 RTX_FRAME_RELATED_P (insn
) = 1;
7344 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR
,
7345 gen_rtx_SET (VOIDmode
,
7346 gen_rtx_MEM (DFmode
, addr
),
7347 gen_rtx_REG (DFmode
, i
)),
7352 /* Set frame pointer, if needed. */
7354 if (frame_pointer_needed
)
7356 insn
= emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
);
7357 RTX_FRAME_RELATED_P (insn
) = 1;
7360 /* Set up got pointer, if needed. */
7362 if (flag_pic
&& regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
])
7364 rtx insns
= s390_load_got ();
7366 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
7368 annotate_constant_pool_refs (&PATTERN (insn
));
7370 REG_NOTES (insn
) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD
, NULL_RTX
,
7377 if (TARGET_TPF_PROFILING
)
7379 /* Generate a BAS instruction to serve as a function
7380 entry intercept to facilitate the use of tracing
7381 algorithms located at the branch target. */
7382 emit_insn (gen_prologue_tpf ());
7384 /* Emit a blockage here so that all code
7385 lies between the profiling mechanisms. */
7386 emit_insn (gen_blockage ());
7390 /* Expand the epilogue into a bunch of separate insns. */
7393 s390_emit_epilogue (bool sibcall
)
7395 rtx frame_pointer
, return_reg
;
7396 int area_bottom
, area_top
, offset
= 0;
7401 if (TARGET_TPF_PROFILING
)
7404 /* Generate a BAS instruction to serve as a function
7405 entry intercept to facilitate the use of tracing
7406 algorithms located at the branch target. */
7408 /* Emit a blockage here so that all code
7409 lies between the profiling mechanisms. */
7410 emit_insn (gen_blockage ());
7412 emit_insn (gen_epilogue_tpf ());
7415 /* Check whether to use frame or stack pointer for restore. */
7417 frame_pointer
= (frame_pointer_needed
7418 ? hard_frame_pointer_rtx
: stack_pointer_rtx
);
7420 s390_frame_area (&area_bottom
, &area_top
);
7422 /* Check whether we can access the register save area.
7423 If not, increment the frame pointer as required. */
7425 if (area_top
<= area_bottom
)
7427 /* Nothing to restore. */
7429 else if (DISP_IN_RANGE (cfun_frame_layout
.frame_size
+ area_bottom
)
7430 && DISP_IN_RANGE (cfun_frame_layout
.frame_size
+ area_top
- 1))
7432 /* Area is in range. */
7433 offset
= cfun_frame_layout
.frame_size
;
7437 rtx insn
, frame_off
;
7439 offset
= area_bottom
< 0 ? -area_bottom
: 0;
7440 frame_off
= GEN_INT (cfun_frame_layout
.frame_size
- offset
);
7442 if (DISP_IN_RANGE (INTVAL (frame_off
)))
7444 insn
= gen_rtx_SET (VOIDmode
, frame_pointer
,
7445 gen_rtx_PLUS (Pmode
, frame_pointer
, frame_off
));
7446 insn
= emit_insn (insn
);
7450 if (!CONST_OK_FOR_K (INTVAL (frame_off
)))
7451 frame_off
= force_const_mem (Pmode
, frame_off
);
7453 insn
= emit_insn (gen_add2_insn (frame_pointer
, frame_off
));
7454 annotate_constant_pool_refs (&PATTERN (insn
));
7458 /* Restore call saved fprs. */
7462 if (cfun_save_high_fprs_p
)
7464 next_offset
= cfun_frame_layout
.f8_offset
;
7465 for (i
= 24; i
< 32; i
++)
7467 if (cfun_fpr_bit_p (i
- 16))
7469 restore_fpr (frame_pointer
,
7470 offset
+ next_offset
, i
);
7479 next_offset
= cfun_frame_layout
.f4_offset
;
7480 for (i
= 18; i
< 20; i
++)
7482 if (cfun_fpr_bit_p (i
- 16))
7484 restore_fpr (frame_pointer
,
7485 offset
+ next_offset
, i
);
7488 else if (!TARGET_PACKED_STACK
)
7494 /* Return register. */
7496 return_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
7498 /* Restore call saved gprs. */
7500 if (cfun_frame_layout
.first_restore_gpr
!= -1)
7505 /* Check for global register and save them
7506 to stack location from where they get restored. */
7508 for (i
= cfun_frame_layout
.first_restore_gpr
;
7509 i
<= cfun_frame_layout
.last_restore_gpr
;
7512 /* These registers are special and need to be
7513 restored in any case. */
7514 if (i
== STACK_POINTER_REGNUM
7515 || i
== RETURN_REGNUM
7517 || (flag_pic
&& i
== (int)PIC_OFFSET_TABLE_REGNUM
))
7522 addr
= plus_constant (frame_pointer
,
7523 offset
+ cfun_frame_layout
.gprs_offset
7524 + (i
- cfun_frame_layout
.first_save_gpr_slot
)
7526 addr
= gen_rtx_MEM (Pmode
, addr
);
7527 set_mem_alias_set (addr
, get_frame_alias_set ());
7528 emit_move_insn (addr
, gen_rtx_REG (Pmode
, i
));
7534 /* Fetch return address from stack before load multiple,
7535 this will do good for scheduling. */
7537 if (cfun_frame_layout
.save_return_addr_p
7538 || (cfun_frame_layout
.first_restore_gpr
< BASE_REGNUM
7539 && cfun_frame_layout
.last_restore_gpr
> RETURN_REGNUM
))
7541 int return_regnum
= find_unused_clobbered_reg();
7544 return_reg
= gen_rtx_REG (Pmode
, return_regnum
);
7546 addr
= plus_constant (frame_pointer
,
7547 offset
+ cfun_frame_layout
.gprs_offset
7549 - cfun_frame_layout
.first_save_gpr_slot
)
7551 addr
= gen_rtx_MEM (Pmode
, addr
);
7552 set_mem_alias_set (addr
, get_frame_alias_set ());
7553 emit_move_insn (return_reg
, addr
);
7557 insn
= restore_gprs (frame_pointer
,
7558 offset
+ cfun_frame_layout
.gprs_offset
7559 + (cfun_frame_layout
.first_restore_gpr
7560 - cfun_frame_layout
.first_save_gpr_slot
)
7562 cfun_frame_layout
.first_restore_gpr
,
7563 cfun_frame_layout
.last_restore_gpr
);
7570 /* Return to caller. */
7572 p
= rtvec_alloc (2);
7574 RTVEC_ELT (p
, 0) = gen_rtx_RETURN (VOIDmode
);
7575 RTVEC_ELT (p
, 1) = gen_rtx_USE (VOIDmode
, return_reg
);
7576 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
7581 /* Return the size in bytes of a function argument of
7582 type TYPE and/or mode MODE. At least one of TYPE or
7583 MODE must be specified. */
7586 s390_function_arg_size (enum machine_mode mode
, tree type
)
7589 return int_size_in_bytes (type
);
7591 /* No type info available for some library calls ... */
7592 if (mode
!= BLKmode
)
7593 return GET_MODE_SIZE (mode
);
7595 /* If we have neither type nor mode, abort */
7599 /* Return true if a function argument of type TYPE and mode MODE
7600 is to be passed in a floating-point register, if available. */
7603 s390_function_arg_float (enum machine_mode mode
, tree type
)
7605 int size
= s390_function_arg_size (mode
, type
);
7609 /* Soft-float changes the ABI: no floating-point registers are used. */
7610 if (TARGET_SOFT_FLOAT
)
7613 /* No type info available for some library calls ... */
7615 return mode
== SFmode
|| mode
== DFmode
|| mode
== SDmode
|| mode
== DDmode
;
7617 /* The ABI says that record types with a single member are treated
7618 just like that member would be. */
7619 while (TREE_CODE (type
) == RECORD_TYPE
)
7621 tree field
, single
= NULL_TREE
;
7623 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
7625 if (TREE_CODE (field
) != FIELD_DECL
)
7628 if (single
== NULL_TREE
)
7629 single
= TREE_TYPE (field
);
7634 if (single
== NULL_TREE
)
7640 return TREE_CODE (type
) == REAL_TYPE
;
7643 /* Return true if a function argument of type TYPE and mode MODE
7644 is to be passed in an integer register, or a pair of integer
7645 registers, if available. */
7648 s390_function_arg_integer (enum machine_mode mode
, tree type
)
7650 int size
= s390_function_arg_size (mode
, type
);
7654 /* No type info available for some library calls ... */
7656 return GET_MODE_CLASS (mode
) == MODE_INT
7657 || (TARGET_SOFT_FLOAT
&& SCALAR_FLOAT_MODE_P (mode
));
7659 /* We accept small integral (and similar) types. */
7660 if (INTEGRAL_TYPE_P (type
)
7661 || POINTER_TYPE_P (type
)
7662 || TREE_CODE (type
) == OFFSET_TYPE
7663 || (TARGET_SOFT_FLOAT
&& TREE_CODE (type
) == REAL_TYPE
))
7666 /* We also accept structs of size 1, 2, 4, 8 that are not
7667 passed in floating-point registers. */
7668 if (AGGREGATE_TYPE_P (type
)
7669 && exact_log2 (size
) >= 0
7670 && !s390_function_arg_float (mode
, type
))
7676 /* Return 1 if a function argument of type TYPE and mode MODE
7677 is to be passed by reference. The ABI specifies that only
7678 structures of size 1, 2, 4, or 8 bytes are passed by value,
7679 all other structures (and complex numbers) are passed by
7683 s390_pass_by_reference (CUMULATIVE_ARGS
*ca ATTRIBUTE_UNUSED
,
7684 enum machine_mode mode
, tree type
,
7685 bool named ATTRIBUTE_UNUSED
)
7687 int size
= s390_function_arg_size (mode
, type
);
7693 if (AGGREGATE_TYPE_P (type
) && exact_log2 (size
) < 0)
7696 if (TREE_CODE (type
) == COMPLEX_TYPE
7697 || TREE_CODE (type
) == VECTOR_TYPE
)
7704 /* Update the data in CUM to advance over an argument of mode MODE and
7705 data type TYPE. (TYPE is null for libcalls where that information
7706 may not be available.). The boolean NAMED specifies whether the
7707 argument is a named argument (as opposed to an unnamed argument
7708 matching an ellipsis). */
7711 s390_function_arg_advance (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
,
7712 tree type
, int named ATTRIBUTE_UNUSED
)
7714 if (s390_function_arg_float (mode
, type
))
7718 else if (s390_function_arg_integer (mode
, type
))
7720 int size
= s390_function_arg_size (mode
, type
);
7721 cum
->gprs
+= ((size
+ UNITS_PER_WORD
-1) / UNITS_PER_WORD
);
7727 /* Define where to put the arguments to a function.
7728 Value is zero to push the argument on the stack,
7729 or a hard register in which to store the argument.
7731 MODE is the argument's machine mode.
7732 TYPE is the data type of the argument (as a tree).
7733 This is null for libcalls where that information may
7735 CUM is a variable of type CUMULATIVE_ARGS which gives info about
7736 the preceding args and about the function being called.
7737 NAMED is nonzero if this argument is a named parameter
7738 (otherwise it is an extra parameter matching an ellipsis).
7740 On S/390, we use general purpose registers 2 through 6 to
7741 pass integer, pointer, and certain structure arguments, and
7742 floating point registers 0 and 2 (0, 2, 4, and 6 on 64-bit)
7743 to pass floating point arguments. All remaining arguments
7744 are pushed to the stack. */
7747 s390_function_arg (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
, tree type
,
7748 int named ATTRIBUTE_UNUSED
)
7750 if (s390_function_arg_float (mode
, type
))
7752 if (cum
->fprs
+ 1 > FP_ARG_NUM_REG
)
7755 return gen_rtx_REG (mode
, cum
->fprs
+ 16);
7757 else if (s390_function_arg_integer (mode
, type
))
7759 int size
= s390_function_arg_size (mode
, type
);
7760 int n_gprs
= (size
+ UNITS_PER_WORD
-1) / UNITS_PER_WORD
;
7762 if (cum
->gprs
+ n_gprs
> GP_ARG_NUM_REG
)
7765 return gen_rtx_REG (mode
, cum
->gprs
+ 2);
7768 /* After the real arguments, expand_call calls us once again
7769 with a void_type_node type. Whatever we return here is
7770 passed as operand 2 to the call expanders.
7772 We don't need this feature ... */
7773 else if (type
== void_type_node
)
7779 /* Return true if return values of type TYPE should be returned
7780 in a memory buffer whose address is passed by the caller as
7781 hidden first argument. */
7784 s390_return_in_memory (tree type
, tree fundecl ATTRIBUTE_UNUSED
)
7786 /* We accept small integral (and similar) types. */
7787 if (INTEGRAL_TYPE_P (type
)
7788 || POINTER_TYPE_P (type
)
7789 || TREE_CODE (type
) == OFFSET_TYPE
7790 || TREE_CODE (type
) == REAL_TYPE
)
7791 return int_size_in_bytes (type
) > 8;
7793 /* Aggregates and similar constructs are always returned
7795 if (AGGREGATE_TYPE_P (type
)
7796 || TREE_CODE (type
) == COMPLEX_TYPE
7797 || TREE_CODE (type
) == VECTOR_TYPE
)
7800 /* ??? We get called on all sorts of random stuff from
7801 aggregate_value_p. We can't abort, but it's not clear
7802 what's safe to return. Pretend it's a struct I guess. */
7806 /* Define where to return a (scalar) value of type TYPE.
7807 If TYPE is null, define where to return a (scalar)
7808 value of mode MODE from a libcall. */
7811 s390_function_value (tree type
, enum machine_mode mode
)
7815 int unsignedp
= TYPE_UNSIGNED (type
);
7816 mode
= promote_mode (type
, TYPE_MODE (type
), &unsignedp
, 1);
7819 gcc_assert (GET_MODE_CLASS (mode
) == MODE_INT
|| SCALAR_FLOAT_MODE_P (mode
));
7820 gcc_assert (GET_MODE_SIZE (mode
) <= 8);
7822 if (TARGET_HARD_FLOAT
&& SCALAR_FLOAT_MODE_P (mode
))
7823 return gen_rtx_REG (mode
, 16);
7825 return gen_rtx_REG (mode
, 2);
7829 /* Create and return the va_list datatype.
7831 On S/390, va_list is an array type equivalent to
7833 typedef struct __va_list_tag
7837 void *__overflow_arg_area;
7838 void *__reg_save_area;
7841 where __gpr and __fpr hold the number of general purpose
7842 or floating point arguments used up to now, respectively,
7843 __overflow_arg_area points to the stack location of the
7844 next argument passed on the stack, and __reg_save_area
7845 always points to the start of the register area in the
7846 call frame of the current function. The function prologue
7847 saves all registers used for argument passing into this
7848 area if the function uses variable arguments. */
7851 s390_build_builtin_va_list (void)
7853 tree f_gpr
, f_fpr
, f_ovf
, f_sav
, record
, type_decl
;
7855 record
= lang_hooks
.types
.make_type (RECORD_TYPE
);
7858 build_decl (TYPE_DECL
, get_identifier ("__va_list_tag"), record
);
7860 f_gpr
= build_decl (FIELD_DECL
, get_identifier ("__gpr"),
7861 long_integer_type_node
);
7862 f_fpr
= build_decl (FIELD_DECL
, get_identifier ("__fpr"),
7863 long_integer_type_node
);
7864 f_ovf
= build_decl (FIELD_DECL
, get_identifier ("__overflow_arg_area"),
7866 f_sav
= build_decl (FIELD_DECL
, get_identifier ("__reg_save_area"),
7869 va_list_gpr_counter_field
= f_gpr
;
7870 va_list_fpr_counter_field
= f_fpr
;
7872 DECL_FIELD_CONTEXT (f_gpr
) = record
;
7873 DECL_FIELD_CONTEXT (f_fpr
) = record
;
7874 DECL_FIELD_CONTEXT (f_ovf
) = record
;
7875 DECL_FIELD_CONTEXT (f_sav
) = record
;
7877 TREE_CHAIN (record
) = type_decl
;
7878 TYPE_NAME (record
) = type_decl
;
7879 TYPE_FIELDS (record
) = f_gpr
;
7880 TREE_CHAIN (f_gpr
) = f_fpr
;
7881 TREE_CHAIN (f_fpr
) = f_ovf
;
7882 TREE_CHAIN (f_ovf
) = f_sav
;
7884 layout_type (record
);
7886 /* The correct type is an array type of one element. */
7887 return build_array_type (record
, build_index_type (size_zero_node
));
7890 /* Implement va_start by filling the va_list structure VALIST.
7891 STDARG_P is always true, and ignored.
7892 NEXTARG points to the first anonymous stack argument.
7894 The following global variables are used to initialize
7895 the va_list structure:
7897 current_function_args_info:
7898 holds number of gprs and fprs used for named arguments.
7899 current_function_arg_offset_rtx:
7900 holds the offset of the first anonymous stack argument
7901 (relative to the virtual arg pointer). */
7904 s390_va_start (tree valist
, rtx nextarg ATTRIBUTE_UNUSED
)
7906 HOST_WIDE_INT n_gpr
, n_fpr
;
7908 tree f_gpr
, f_fpr
, f_ovf
, f_sav
;
7909 tree gpr
, fpr
, ovf
, sav
, t
;
7911 f_gpr
= TYPE_FIELDS (TREE_TYPE (va_list_type_node
));
7912 f_fpr
= TREE_CHAIN (f_gpr
);
7913 f_ovf
= TREE_CHAIN (f_fpr
);
7914 f_sav
= TREE_CHAIN (f_ovf
);
7916 valist
= build_va_arg_indirect_ref (valist
);
7917 gpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_gpr
), valist
, f_gpr
, NULL_TREE
);
7918 fpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_fpr
), valist
, f_fpr
, NULL_TREE
);
7919 ovf
= build3 (COMPONENT_REF
, TREE_TYPE (f_ovf
), valist
, f_ovf
, NULL_TREE
);
7920 sav
= build3 (COMPONENT_REF
, TREE_TYPE (f_sav
), valist
, f_sav
, NULL_TREE
);
7922 /* Count number of gp and fp argument registers used. */
7924 n_gpr
= current_function_args_info
.gprs
;
7925 n_fpr
= current_function_args_info
.fprs
;
7927 if (cfun
->va_list_gpr_size
)
7929 t
= build2 (MODIFY_EXPR
, TREE_TYPE (gpr
), gpr
,
7930 build_int_cst (NULL_TREE
, n_gpr
));
7931 TREE_SIDE_EFFECTS (t
) = 1;
7932 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
7935 if (cfun
->va_list_fpr_size
)
7937 t
= build2 (MODIFY_EXPR
, TREE_TYPE (fpr
), fpr
,
7938 build_int_cst (NULL_TREE
, n_fpr
));
7939 TREE_SIDE_EFFECTS (t
) = 1;
7940 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
7943 /* Find the overflow area. */
7944 if (n_gpr
+ cfun
->va_list_gpr_size
> GP_ARG_NUM_REG
7945 || n_fpr
+ cfun
->va_list_fpr_size
> FP_ARG_NUM_REG
)
7947 t
= make_tree (TREE_TYPE (ovf
), virtual_incoming_args_rtx
);
7949 off
= INTVAL (current_function_arg_offset_rtx
);
7950 off
= off
< 0 ? 0 : off
;
7951 if (TARGET_DEBUG_ARG
)
7952 fprintf (stderr
, "va_start: n_gpr = %d, n_fpr = %d off %d\n",
7953 (int)n_gpr
, (int)n_fpr
, off
);
7955 t
= build2 (PLUS_EXPR
, TREE_TYPE (ovf
), t
, build_int_cst (NULL_TREE
, off
));
7957 t
= build2 (MODIFY_EXPR
, TREE_TYPE (ovf
), ovf
, t
);
7958 TREE_SIDE_EFFECTS (t
) = 1;
7959 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
7962 /* Find the register save area. */
7963 if ((cfun
->va_list_gpr_size
&& n_gpr
< GP_ARG_NUM_REG
)
7964 || (cfun
->va_list_fpr_size
&& n_fpr
< FP_ARG_NUM_REG
))
7966 t
= make_tree (TREE_TYPE (sav
), return_address_pointer_rtx
);
7967 t
= build2 (PLUS_EXPR
, TREE_TYPE (sav
), t
,
7968 build_int_cst (NULL_TREE
, -RETURN_REGNUM
* UNITS_PER_WORD
));
7970 t
= build2 (MODIFY_EXPR
, TREE_TYPE (sav
), sav
, t
);
7971 TREE_SIDE_EFFECTS (t
) = 1;
7972 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
7976 /* Implement va_arg by updating the va_list structure
7977 VALIST as required to retrieve an argument of type
7978 TYPE, and returning that argument.
7980 Generates code equivalent to:
7982 if (integral value) {
7983 if (size <= 4 && args.gpr < 5 ||
7984 size > 4 && args.gpr < 4 )
7985 ret = args.reg_save_area[args.gpr+8]
7987 ret = *args.overflow_arg_area++;
7988 } else if (float value) {
7990 ret = args.reg_save_area[args.fpr+64]
7992 ret = *args.overflow_arg_area++;
7993 } else if (aggregate value) {
7995 ret = *args.reg_save_area[args.gpr]
7997 ret = **args.overflow_arg_area++;
8001 s390_gimplify_va_arg (tree valist
, tree type
, tree
*pre_p
,
8002 tree
*post_p ATTRIBUTE_UNUSED
)
8004 tree f_gpr
, f_fpr
, f_ovf
, f_sav
;
8005 tree gpr
, fpr
, ovf
, sav
, reg
, t
, u
;
8006 int indirect_p
, size
, n_reg
, sav_ofs
, sav_scale
, max_reg
;
8007 tree lab_false
, lab_over
, addr
;
8009 f_gpr
= TYPE_FIELDS (TREE_TYPE (va_list_type_node
));
8010 f_fpr
= TREE_CHAIN (f_gpr
);
8011 f_ovf
= TREE_CHAIN (f_fpr
);
8012 f_sav
= TREE_CHAIN (f_ovf
);
8014 valist
= build_va_arg_indirect_ref (valist
);
8015 gpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_gpr
), valist
, f_gpr
, NULL_TREE
);
8016 fpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_fpr
), valist
, f_fpr
, NULL_TREE
);
8017 ovf
= build3 (COMPONENT_REF
, TREE_TYPE (f_ovf
), valist
, f_ovf
, NULL_TREE
);
8018 sav
= build3 (COMPONENT_REF
, TREE_TYPE (f_sav
), valist
, f_sav
, NULL_TREE
);
8020 size
= int_size_in_bytes (type
);
8022 if (pass_by_reference (NULL
, TYPE_MODE (type
), type
, false))
8024 if (TARGET_DEBUG_ARG
)
8026 fprintf (stderr
, "va_arg: aggregate type");
8030 /* Aggregates are passed by reference. */
8035 /* kernel stack layout on 31 bit: It is assumed here that no padding
8036 will be added by s390_frame_info because for va_args always an even
8037 number of gprs has to be saved r15-r2 = 14 regs. */
8038 sav_ofs
= 2 * UNITS_PER_WORD
;
8039 sav_scale
= UNITS_PER_WORD
;
8040 size
= UNITS_PER_WORD
;
8041 max_reg
= GP_ARG_NUM_REG
- n_reg
;
8043 else if (s390_function_arg_float (TYPE_MODE (type
), type
))
8045 if (TARGET_DEBUG_ARG
)
8047 fprintf (stderr
, "va_arg: float type");
8051 /* FP args go in FP registers, if present. */
8055 sav_ofs
= 16 * UNITS_PER_WORD
;
8057 max_reg
= FP_ARG_NUM_REG
- n_reg
;
8061 if (TARGET_DEBUG_ARG
)
8063 fprintf (stderr
, "va_arg: other type");
8067 /* Otherwise into GP registers. */
8070 n_reg
= (size
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
8072 /* kernel stack layout on 31 bit: It is assumed here that no padding
8073 will be added by s390_frame_info because for va_args always an even
8074 number of gprs has to be saved r15-r2 = 14 regs. */
8075 sav_ofs
= 2 * UNITS_PER_WORD
;
8077 if (size
< UNITS_PER_WORD
)
8078 sav_ofs
+= UNITS_PER_WORD
- size
;
8080 sav_scale
= UNITS_PER_WORD
;
8081 max_reg
= GP_ARG_NUM_REG
- n_reg
;
8084 /* Pull the value out of the saved registers ... */
8086 lab_false
= create_artificial_label ();
8087 lab_over
= create_artificial_label ();
8088 addr
= create_tmp_var (ptr_type_node
, "addr");
8089 DECL_POINTER_ALIAS_SET (addr
) = get_varargs_alias_set ();
8091 t
= fold_convert (TREE_TYPE (reg
), size_int (max_reg
));
8092 t
= build2 (GT_EXPR
, boolean_type_node
, reg
, t
);
8093 u
= build1 (GOTO_EXPR
, void_type_node
, lab_false
);
8094 t
= build3 (COND_EXPR
, void_type_node
, t
, u
, NULL_TREE
);
8095 gimplify_and_add (t
, pre_p
);
8097 t
= build2 (PLUS_EXPR
, ptr_type_node
, sav
,
8098 fold_convert (ptr_type_node
, size_int (sav_ofs
)));
8099 u
= build2 (MULT_EXPR
, TREE_TYPE (reg
), reg
,
8100 fold_convert (TREE_TYPE (reg
), size_int (sav_scale
)));
8101 t
= build2 (PLUS_EXPR
, ptr_type_node
, t
, fold_convert (ptr_type_node
, u
));
8103 t
= build2 (MODIFY_EXPR
, void_type_node
, addr
, t
);
8104 gimplify_and_add (t
, pre_p
);
8106 t
= build1 (GOTO_EXPR
, void_type_node
, lab_over
);
8107 gimplify_and_add (t
, pre_p
);
8109 t
= build1 (LABEL_EXPR
, void_type_node
, lab_false
);
8110 append_to_statement_list (t
, pre_p
);
8113 /* ... Otherwise out of the overflow area. */
8116 if (size
< UNITS_PER_WORD
)
8117 t
= build2 (PLUS_EXPR
, ptr_type_node
, t
,
8118 fold_convert (ptr_type_node
, size_int (UNITS_PER_WORD
- size
)));
8120 gimplify_expr (&t
, pre_p
, NULL
, is_gimple_val
, fb_rvalue
);
8122 u
= build2 (MODIFY_EXPR
, void_type_node
, addr
, t
);
8123 gimplify_and_add (u
, pre_p
);
8125 t
= build2 (PLUS_EXPR
, ptr_type_node
, t
,
8126 fold_convert (ptr_type_node
, size_int (size
)));
8127 t
= build2 (MODIFY_EXPR
, ptr_type_node
, ovf
, t
);
8128 gimplify_and_add (t
, pre_p
);
8130 t
= build1 (LABEL_EXPR
, void_type_node
, lab_over
);
8131 append_to_statement_list (t
, pre_p
);
8134 /* Increment register save count. */
8136 u
= build2 (PREINCREMENT_EXPR
, TREE_TYPE (reg
), reg
,
8137 fold_convert (TREE_TYPE (reg
), size_int (n_reg
)));
8138 gimplify_and_add (u
, pre_p
);
8142 t
= build_pointer_type (build_pointer_type (type
));
8143 addr
= fold_convert (t
, addr
);
8144 addr
= build_va_arg_indirect_ref (addr
);
8148 t
= build_pointer_type (type
);
8149 addr
= fold_convert (t
, addr
);
8152 return build_va_arg_indirect_ref (addr
);
8160 S390_BUILTIN_THREAD_POINTER
,
8161 S390_BUILTIN_SET_THREAD_POINTER
,
8166 static unsigned int const code_for_builtin_64
[S390_BUILTIN_max
] = {
8171 static unsigned int const code_for_builtin_31
[S390_BUILTIN_max
] = {
8177 s390_init_builtins (void)
8181 ftype
= build_function_type (ptr_type_node
, void_list_node
);
8182 lang_hooks
.builtin_function ("__builtin_thread_pointer", ftype
,
8183 S390_BUILTIN_THREAD_POINTER
, BUILT_IN_MD
,
8186 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
8187 lang_hooks
.builtin_function ("__builtin_set_thread_pointer", ftype
,
8188 S390_BUILTIN_SET_THREAD_POINTER
, BUILT_IN_MD
,
8192 /* Expand an expression EXP that calls a built-in function,
8193 with result going to TARGET if that's convenient
8194 (and in mode MODE if that's convenient).
8195 SUBTARGET may be used as the target for computing one of EXP's operands.
8196 IGNORE is nonzero if the value is to be ignored. */
8199 s390_expand_builtin (tree exp
, rtx target
, rtx subtarget ATTRIBUTE_UNUSED
,
8200 enum machine_mode mode ATTRIBUTE_UNUSED
,
8201 int ignore ATTRIBUTE_UNUSED
)
8205 unsigned int const *code_for_builtin
=
8206 TARGET_64BIT
? code_for_builtin_64
: code_for_builtin_31
;
8208 tree fndecl
= TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
8209 unsigned int fcode
= DECL_FUNCTION_CODE (fndecl
);
8210 tree arglist
= TREE_OPERAND (exp
, 1);
8211 enum insn_code icode
;
8212 rtx op
[MAX_ARGS
], pat
;
8216 if (fcode
>= S390_BUILTIN_max
)
8217 internal_error ("bad builtin fcode");
8218 icode
= code_for_builtin
[fcode
];
8220 internal_error ("bad builtin fcode");
8222 nonvoid
= TREE_TYPE (TREE_TYPE (fndecl
)) != void_type_node
;
8224 for (arglist
= TREE_OPERAND (exp
, 1), arity
= 0;
8226 arglist
= TREE_CHAIN (arglist
), arity
++)
8228 const struct insn_operand_data
*insn_op
;
8230 tree arg
= TREE_VALUE (arglist
);
8231 if (arg
== error_mark_node
)
8233 if (arity
> MAX_ARGS
)
8236 insn_op
= &insn_data
[icode
].operand
[arity
+ nonvoid
];
8238 op
[arity
] = expand_expr (arg
, NULL_RTX
, insn_op
->mode
, 0);
8240 if (!(*insn_op
->predicate
) (op
[arity
], insn_op
->mode
))
8241 op
[arity
] = copy_to_mode_reg (insn_op
->mode
, op
[arity
]);
8246 enum machine_mode tmode
= insn_data
[icode
].operand
[0].mode
;
8248 || GET_MODE (target
) != tmode
8249 || !(*insn_data
[icode
].operand
[0].predicate
) (target
, tmode
))
8250 target
= gen_reg_rtx (tmode
);
8256 pat
= GEN_FCN (icode
) (target
);
8260 pat
= GEN_FCN (icode
) (target
, op
[0]);
8262 pat
= GEN_FCN (icode
) (op
[0]);
8265 pat
= GEN_FCN (icode
) (target
, op
[0], op
[1]);
8281 /* Output assembly code for the trampoline template to
8284 On S/390, we use gpr 1 internally in the trampoline code;
8285 gpr 0 is used to hold the static chain. */
8288 s390_trampoline_template (FILE *file
)
8291 op
[0] = gen_rtx_REG (Pmode
, 0);
8292 op
[1] = gen_rtx_REG (Pmode
, 1);
8296 output_asm_insn ("basr\t%1,0", op
);
8297 output_asm_insn ("lmg\t%0,%1,14(%1)", op
);
8298 output_asm_insn ("br\t%1", op
);
8299 ASM_OUTPUT_SKIP (file
, (HOST_WIDE_INT
)(TRAMPOLINE_SIZE
- 10));
8303 output_asm_insn ("basr\t%1,0", op
);
8304 output_asm_insn ("lm\t%0,%1,6(%1)", op
);
8305 output_asm_insn ("br\t%1", op
);
8306 ASM_OUTPUT_SKIP (file
, (HOST_WIDE_INT
)(TRAMPOLINE_SIZE
- 8));
8310 /* Emit RTL insns to initialize the variable parts of a trampoline.
8311 FNADDR is an RTX for the address of the function's pure code.
8312 CXT is an RTX for the static chain value for the function. */
8315 s390_initialize_trampoline (rtx addr
, rtx fnaddr
, rtx cxt
)
8317 emit_move_insn (gen_rtx_MEM (Pmode
,
8318 memory_address (Pmode
,
8319 plus_constant (addr
, (TARGET_64BIT
? 16 : 8)))), cxt
);
8320 emit_move_insn (gen_rtx_MEM (Pmode
,
8321 memory_address (Pmode
,
8322 plus_constant (addr
, (TARGET_64BIT
? 24 : 12)))), fnaddr
);
8325 /* Return rtx for 64-bit constant formed from the 32-bit subwords
8326 LOW and HIGH, independent of the host word size. */
8329 s390_gen_rtx_const_DI (int high
, int low
)
8331 #if HOST_BITS_PER_WIDE_INT >= 64
8333 val
= (HOST_WIDE_INT
)high
;
8335 val
|= (HOST_WIDE_INT
)low
;
8337 return GEN_INT (val
);
8339 #if HOST_BITS_PER_WIDE_INT >= 32
8340 return immed_double_const ((HOST_WIDE_INT
)low
, (HOST_WIDE_INT
)high
, DImode
);
8347 /* Output assembler code to FILE to increment profiler label # LABELNO
8348 for profiling a function entry. */
8351 s390_function_profiler (FILE *file
, int labelno
)
8356 ASM_GENERATE_INTERNAL_LABEL (label
, "LP", labelno
);
8358 fprintf (file
, "# function profiler \n");
8360 op
[0] = gen_rtx_REG (Pmode
, RETURN_REGNUM
);
8361 op
[1] = gen_rtx_REG (Pmode
, STACK_POINTER_REGNUM
);
8362 op
[1] = gen_rtx_MEM (Pmode
, plus_constant (op
[1], UNITS_PER_WORD
));
8364 op
[2] = gen_rtx_REG (Pmode
, 1);
8365 op
[3] = gen_rtx_SYMBOL_REF (Pmode
, label
);
8366 SYMBOL_REF_FLAGS (op
[3]) = SYMBOL_FLAG_LOCAL
;
8368 op
[4] = gen_rtx_SYMBOL_REF (Pmode
, "_mcount");
8371 op
[4] = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op
[4]), UNSPEC_PLT
);
8372 op
[4] = gen_rtx_CONST (Pmode
, op
[4]);
8377 output_asm_insn ("stg\t%0,%1", op
);
8378 output_asm_insn ("larl\t%2,%3", op
);
8379 output_asm_insn ("brasl\t%0,%4", op
);
8380 output_asm_insn ("lg\t%0,%1", op
);
8384 op
[6] = gen_label_rtx ();
8386 output_asm_insn ("st\t%0,%1", op
);
8387 output_asm_insn ("bras\t%2,%l6", op
);
8388 output_asm_insn (".long\t%4", op
);
8389 output_asm_insn (".long\t%3", op
);
8390 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[6]));
8391 output_asm_insn ("l\t%0,0(%2)", op
);
8392 output_asm_insn ("l\t%2,4(%2)", op
);
8393 output_asm_insn ("basr\t%0,%0", op
);
8394 output_asm_insn ("l\t%0,%1", op
);
8398 op
[5] = gen_label_rtx ();
8399 op
[6] = gen_label_rtx ();
8401 output_asm_insn ("st\t%0,%1", op
);
8402 output_asm_insn ("bras\t%2,%l6", op
);
8403 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[5]));
8404 output_asm_insn (".long\t%4-%l5", op
);
8405 output_asm_insn (".long\t%3-%l5", op
);
8406 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[6]));
8407 output_asm_insn ("lr\t%0,%2", op
);
8408 output_asm_insn ("a\t%0,0(%2)", op
);
8409 output_asm_insn ("a\t%2,4(%2)", op
);
8410 output_asm_insn ("basr\t%0,%0", op
);
8411 output_asm_insn ("l\t%0,%1", op
);
8415 /* Encode symbol attributes (local vs. global, tls model) of a SYMBOL_REF
8416 into its SYMBOL_REF_FLAGS. */
8419 s390_encode_section_info (tree decl
, rtx rtl
, int first
)
8421 default_encode_section_info (decl
, rtl
, first
);
8423 /* If a variable has a forced alignment to < 2 bytes, mark it with
8424 SYMBOL_FLAG_ALIGN1 to prevent it from being used as LARL operand. */
8425 if (TREE_CODE (decl
) == VAR_DECL
8426 && DECL_USER_ALIGN (decl
) && DECL_ALIGN (decl
) < 16)
8427 SYMBOL_REF_FLAGS (XEXP (rtl
, 0)) |= SYMBOL_FLAG_ALIGN1
;
8430 /* Output thunk to FILE that implements a C++ virtual function call (with
8431 multiple inheritance) to FUNCTION. The thunk adjusts the this pointer
8432 by DELTA, and unless VCALL_OFFSET is zero, applies an additional adjustment
8433 stored at VCALL_OFFSET in the vtable whose address is located at offset 0
8434 relative to the resulting this pointer. */
8437 s390_output_mi_thunk (FILE *file
, tree thunk ATTRIBUTE_UNUSED
,
8438 HOST_WIDE_INT delta
, HOST_WIDE_INT vcall_offset
,
8444 /* Operand 0 is the target function. */
8445 op
[0] = XEXP (DECL_RTL (function
), 0);
8446 if (flag_pic
&& !SYMBOL_REF_LOCAL_P (op
[0]))
8449 op
[0] = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op
[0]),
8450 TARGET_64BIT
? UNSPEC_PLT
: UNSPEC_GOT
);
8451 op
[0] = gen_rtx_CONST (Pmode
, op
[0]);
8454 /* Operand 1 is the 'this' pointer. */
8455 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function
)), function
))
8456 op
[1] = gen_rtx_REG (Pmode
, 3);
8458 op
[1] = gen_rtx_REG (Pmode
, 2);
8460 /* Operand 2 is the delta. */
8461 op
[2] = GEN_INT (delta
);
8463 /* Operand 3 is the vcall_offset. */
8464 op
[3] = GEN_INT (vcall_offset
);
8466 /* Operand 4 is the temporary register. */
8467 op
[4] = gen_rtx_REG (Pmode
, 1);
8469 /* Operands 5 to 8 can be used as labels. */
8475 /* Operand 9 can be used for temporary register. */
8478 /* Generate code. */
8481 /* Setup literal pool pointer if required. */
8482 if ((!DISP_IN_RANGE (delta
)
8483 && !CONST_OK_FOR_K (delta
)
8484 && !CONST_OK_FOR_Os (delta
))
8485 || (!DISP_IN_RANGE (vcall_offset
)
8486 && !CONST_OK_FOR_K (vcall_offset
)
8487 && !CONST_OK_FOR_Os (vcall_offset
)))
8489 op
[5] = gen_label_rtx ();
8490 output_asm_insn ("larl\t%4,%5", op
);
8493 /* Add DELTA to this pointer. */
8496 if (CONST_OK_FOR_J (delta
))
8497 output_asm_insn ("la\t%1,%2(%1)", op
);
8498 else if (DISP_IN_RANGE (delta
))
8499 output_asm_insn ("lay\t%1,%2(%1)", op
);
8500 else if (CONST_OK_FOR_K (delta
))
8501 output_asm_insn ("aghi\t%1,%2", op
);
8502 else if (CONST_OK_FOR_Os (delta
))
8503 output_asm_insn ("agfi\t%1,%2", op
);
8506 op
[6] = gen_label_rtx ();
8507 output_asm_insn ("agf\t%1,%6-%5(%4)", op
);
8511 /* Perform vcall adjustment. */
8514 if (DISP_IN_RANGE (vcall_offset
))
8516 output_asm_insn ("lg\t%4,0(%1)", op
);
8517 output_asm_insn ("ag\t%1,%3(%4)", op
);
8519 else if (CONST_OK_FOR_K (vcall_offset
))
8521 output_asm_insn ("lghi\t%4,%3", op
);
8522 output_asm_insn ("ag\t%4,0(%1)", op
);
8523 output_asm_insn ("ag\t%1,0(%4)", op
);
8525 else if (CONST_OK_FOR_Os (vcall_offset
))
8527 output_asm_insn ("lgfi\t%4,%3", op
);
8528 output_asm_insn ("ag\t%4,0(%1)", op
);
8529 output_asm_insn ("ag\t%1,0(%4)", op
);
8533 op
[7] = gen_label_rtx ();
8534 output_asm_insn ("llgf\t%4,%7-%5(%4)", op
);
8535 output_asm_insn ("ag\t%4,0(%1)", op
);
8536 output_asm_insn ("ag\t%1,0(%4)", op
);
8540 /* Jump to target. */
8541 output_asm_insn ("jg\t%0", op
);
8543 /* Output literal pool if required. */
8546 output_asm_insn (".align\t4", op
);
8547 targetm
.asm_out
.internal_label (file
, "L",
8548 CODE_LABEL_NUMBER (op
[5]));
8552 targetm
.asm_out
.internal_label (file
, "L",
8553 CODE_LABEL_NUMBER (op
[6]));
8554 output_asm_insn (".long\t%2", op
);
8558 targetm
.asm_out
.internal_label (file
, "L",
8559 CODE_LABEL_NUMBER (op
[7]));
8560 output_asm_insn (".long\t%3", op
);
8565 /* Setup base pointer if required. */
8567 || (!DISP_IN_RANGE (delta
)
8568 && !CONST_OK_FOR_K (delta
)
8569 && !CONST_OK_FOR_Os (delta
))
8570 || (!DISP_IN_RANGE (delta
)
8571 && !CONST_OK_FOR_K (vcall_offset
)
8572 && !CONST_OK_FOR_Os (vcall_offset
)))
8574 op
[5] = gen_label_rtx ();
8575 output_asm_insn ("basr\t%4,0", op
);
8576 targetm
.asm_out
.internal_label (file
, "L",
8577 CODE_LABEL_NUMBER (op
[5]));
8580 /* Add DELTA to this pointer. */
8583 if (CONST_OK_FOR_J (delta
))
8584 output_asm_insn ("la\t%1,%2(%1)", op
);
8585 else if (DISP_IN_RANGE (delta
))
8586 output_asm_insn ("lay\t%1,%2(%1)", op
);
8587 else if (CONST_OK_FOR_K (delta
))
8588 output_asm_insn ("ahi\t%1,%2", op
);
8589 else if (CONST_OK_FOR_Os (delta
))
8590 output_asm_insn ("afi\t%1,%2", op
);
8593 op
[6] = gen_label_rtx ();
8594 output_asm_insn ("a\t%1,%6-%5(%4)", op
);
8598 /* Perform vcall adjustment. */
8601 if (CONST_OK_FOR_J (vcall_offset
))
8603 output_asm_insn ("l\t%4,0(%1)", op
);
8604 output_asm_insn ("a\t%1,%3(%4)", op
);
8606 else if (DISP_IN_RANGE (vcall_offset
))
8608 output_asm_insn ("l\t%4,0(%1)", op
);
8609 output_asm_insn ("ay\t%1,%3(%4)", op
);
8611 else if (CONST_OK_FOR_K (vcall_offset
))
8613 output_asm_insn ("lhi\t%4,%3", op
);
8614 output_asm_insn ("a\t%4,0(%1)", op
);
8615 output_asm_insn ("a\t%1,0(%4)", op
);
8617 else if (CONST_OK_FOR_Os (vcall_offset
))
8619 output_asm_insn ("iilf\t%4,%3", op
);
8620 output_asm_insn ("a\t%4,0(%1)", op
);
8621 output_asm_insn ("a\t%1,0(%4)", op
);
8625 op
[7] = gen_label_rtx ();
8626 output_asm_insn ("l\t%4,%7-%5(%4)", op
);
8627 output_asm_insn ("a\t%4,0(%1)", op
);
8628 output_asm_insn ("a\t%1,0(%4)", op
);
8631 /* We had to clobber the base pointer register.
8632 Re-setup the base pointer (with a different base). */
8633 op
[5] = gen_label_rtx ();
8634 output_asm_insn ("basr\t%4,0", op
);
8635 targetm
.asm_out
.internal_label (file
, "L",
8636 CODE_LABEL_NUMBER (op
[5]));
8639 /* Jump to target. */
8640 op
[8] = gen_label_rtx ();
8643 output_asm_insn ("l\t%4,%8-%5(%4)", op
);
8645 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
8646 /* We cannot call through .plt, since .plt requires %r12 loaded. */
8647 else if (flag_pic
== 1)
8649 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
8650 output_asm_insn ("l\t%4,%0(%4)", op
);
8652 else if (flag_pic
== 2)
8654 op
[9] = gen_rtx_REG (Pmode
, 0);
8655 output_asm_insn ("l\t%9,%8-4-%5(%4)", op
);
8656 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
8657 output_asm_insn ("ar\t%4,%9", op
);
8658 output_asm_insn ("l\t%4,0(%4)", op
);
8661 output_asm_insn ("br\t%4", op
);
8663 /* Output literal pool. */
8664 output_asm_insn (".align\t4", op
);
8666 if (nonlocal
&& flag_pic
== 2)
8667 output_asm_insn (".long\t%0", op
);
8670 op
[0] = gen_rtx_SYMBOL_REF (Pmode
, "_GLOBAL_OFFSET_TABLE_");
8671 SYMBOL_REF_FLAGS (op
[0]) = SYMBOL_FLAG_LOCAL
;
8674 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[8]));
8676 output_asm_insn (".long\t%0", op
);
8678 output_asm_insn (".long\t%0-%5", op
);
8682 targetm
.asm_out
.internal_label (file
, "L",
8683 CODE_LABEL_NUMBER (op
[6]));
8684 output_asm_insn (".long\t%2", op
);
8688 targetm
.asm_out
.internal_label (file
, "L",
8689 CODE_LABEL_NUMBER (op
[7]));
8690 output_asm_insn (".long\t%3", op
);
8696 s390_valid_pointer_mode (enum machine_mode mode
)
8698 return (mode
== SImode
|| (TARGET_64BIT
&& mode
== DImode
));
8701 /* Checks whether the given ARGUMENT_LIST would use a caller
8702 saved register. This is used to decide whether sibling call
8703 optimization could be performed on the respective function
8707 s390_call_saved_register_used (tree argument_list
)
8709 CUMULATIVE_ARGS cum
;
8711 enum machine_mode mode
;
8716 INIT_CUMULATIVE_ARGS (cum
, NULL
, NULL
, 0, 0);
8718 while (argument_list
)
8720 parameter
= TREE_VALUE (argument_list
);
8721 argument_list
= TREE_CHAIN (argument_list
);
8723 gcc_assert (parameter
);
8725 /* For an undeclared variable passed as parameter we will get
8726 an ERROR_MARK node here. */
8727 if (TREE_CODE (parameter
) == ERROR_MARK
)
8730 type
= TREE_TYPE (parameter
);
8733 mode
= TYPE_MODE (type
);
8736 if (pass_by_reference (&cum
, mode
, type
, true))
8739 type
= build_pointer_type (type
);
8742 parm_rtx
= s390_function_arg (&cum
, mode
, type
, 0);
8744 s390_function_arg_advance (&cum
, mode
, type
, 0);
8746 if (parm_rtx
&& REG_P (parm_rtx
))
8749 reg
< HARD_REGNO_NREGS (REGNO (parm_rtx
), GET_MODE (parm_rtx
));
8751 if (! call_used_regs
[reg
+ REGNO (parm_rtx
)])
8758 /* Return true if the given call expression can be
8759 turned into a sibling call.
8760 DECL holds the declaration of the function to be called whereas
8761 EXP is the call expression itself. */
8764 s390_function_ok_for_sibcall (tree decl
, tree exp
)
8766 /* The TPF epilogue uses register 1. */
8767 if (TARGET_TPF_PROFILING
)
8770 /* The 31 bit PLT code uses register 12 (GOT pointer - caller saved)
8771 which would have to be restored before the sibcall. */
8772 if (!TARGET_64BIT
&& flag_pic
&& decl
&& !targetm
.binds_local_p (decl
))
8775 /* Register 6 on s390 is available as an argument register but unfortunately
8776 "caller saved". This makes functions needing this register for arguments
8777 not suitable for sibcalls. */
8778 if (TREE_OPERAND (exp
, 1)
8779 && s390_call_saved_register_used (TREE_OPERAND (exp
, 1)))
8785 /* Return the fixed registers used for condition codes. */
8788 s390_fixed_condition_code_regs (unsigned int *p1
, unsigned int *p2
)
8791 *p2
= INVALID_REGNUM
;
8796 /* This function is used by the call expanders of the machine description.
8797 It emits the call insn itself together with the necessary operations
8798 to adjust the target address and returns the emitted insn.
8799 ADDR_LOCATION is the target address rtx
8800 TLS_CALL the location of the thread-local symbol
8801 RESULT_REG the register where the result of the call should be stored
8802 RETADDR_REG the register where the return address should be stored
8803 If this parameter is NULL_RTX the call is considered
8804 to be a sibling call. */
8807 s390_emit_call (rtx addr_location
, rtx tls_call
, rtx result_reg
,
8810 bool plt_call
= false;
8816 /* Direct function calls need special treatment. */
8817 if (GET_CODE (addr_location
) == SYMBOL_REF
)
8819 /* When calling a global routine in PIC mode, we must
8820 replace the symbol itself with the PLT stub. */
8821 if (flag_pic
&& !SYMBOL_REF_LOCAL_P (addr_location
))
8823 addr_location
= gen_rtx_UNSPEC (Pmode
,
8824 gen_rtvec (1, addr_location
),
8826 addr_location
= gen_rtx_CONST (Pmode
, addr_location
);
8830 /* Unless we can use the bras(l) insn, force the
8831 routine address into a register. */
8832 if (!TARGET_SMALL_EXEC
&& !TARGET_CPU_ZARCH
)
8835 addr_location
= legitimize_pic_address (addr_location
, 0);
8837 addr_location
= force_reg (Pmode
, addr_location
);
8841 /* If it is already an indirect call or the code above moved the
8842 SYMBOL_REF to somewhere else make sure the address can be found in
8844 if (retaddr_reg
== NULL_RTX
8845 && GET_CODE (addr_location
) != SYMBOL_REF
8848 emit_move_insn (gen_rtx_REG (Pmode
, SIBCALL_REGNUM
), addr_location
);
8849 addr_location
= gen_rtx_REG (Pmode
, SIBCALL_REGNUM
);
8852 addr_location
= gen_rtx_MEM (QImode
, addr_location
);
8853 call
= gen_rtx_CALL (VOIDmode
, addr_location
, const0_rtx
);
8855 if (result_reg
!= NULL_RTX
)
8856 call
= gen_rtx_SET (VOIDmode
, result_reg
, call
);
8858 if (retaddr_reg
!= NULL_RTX
)
8860 clobber
= gen_rtx_CLOBBER (VOIDmode
, retaddr_reg
);
8862 if (tls_call
!= NULL_RTX
)
8863 vec
= gen_rtvec (3, call
, clobber
,
8864 gen_rtx_USE (VOIDmode
, tls_call
));
8866 vec
= gen_rtvec (2, call
, clobber
);
8868 call
= gen_rtx_PARALLEL (VOIDmode
, vec
);
8871 insn
= emit_call_insn (call
);
8873 /* 31-bit PLT stubs and tls calls use the GOT register implicitly. */
8874 if ((!TARGET_64BIT
&& plt_call
) || tls_call
!= NULL_RTX
)
8876 /* s390_function_ok_for_sibcall should
8877 have denied sibcalls in this case. */
8878 gcc_assert (retaddr_reg
!= NULL_RTX
);
8880 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), pic_offset_table_rtx
);
8885 /* Implement CONDITIONAL_REGISTER_USAGE. */
8888 s390_conditional_register_usage (void)
8894 fixed_regs
[PIC_OFFSET_TABLE_REGNUM
] = 1;
8895 call_used_regs
[PIC_OFFSET_TABLE_REGNUM
] = 1;
8897 if (TARGET_CPU_ZARCH
)
8899 fixed_regs
[BASE_REGNUM
] = 0;
8900 call_used_regs
[BASE_REGNUM
] = 0;
8901 fixed_regs
[RETURN_REGNUM
] = 0;
8902 call_used_regs
[RETURN_REGNUM
] = 0;
8906 for (i
= 24; i
< 32; i
++)
8907 call_used_regs
[i
] = call_really_used_regs
[i
] = 0;
8911 for (i
= 18; i
< 20; i
++)
8912 call_used_regs
[i
] = call_really_used_regs
[i
] = 0;
8915 if (TARGET_SOFT_FLOAT
)
8917 for (i
= 16; i
< 32; i
++)
8918 call_used_regs
[i
] = fixed_regs
[i
] = 1;
8922 /* Corresponding function to eh_return expander. */
8924 static GTY(()) rtx s390_tpf_eh_return_symbol
;
8926 s390_emit_tpf_eh_return (rtx target
)
8930 if (!s390_tpf_eh_return_symbol
)
8931 s390_tpf_eh_return_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "__tpf_eh_return");
8933 reg
= gen_rtx_REG (Pmode
, 2);
8935 emit_move_insn (reg
, target
);
8936 insn
= s390_emit_call (s390_tpf_eh_return_symbol
, NULL_RTX
, reg
,
8937 gen_rtx_REG (Pmode
, RETURN_REGNUM
));
8938 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), reg
);
8940 emit_move_insn (EH_RETURN_HANDLER_RTX
, reg
);
8943 /* Rework the prologue/epilogue to avoid saving/restoring
8944 registers unnecessarily. */
8947 s390_optimize_prologue (void)
8949 rtx insn
, new_insn
, next_insn
;
8951 /* Do a final recompute of the frame-related data. */
8953 s390_update_frame_layout ();
8955 /* If all special registers are in fact used, there's nothing we
8956 can do, so no point in walking the insn list. */
8958 if (cfun_frame_layout
.first_save_gpr
<= BASE_REGNUM
8959 && cfun_frame_layout
.last_save_gpr
>= BASE_REGNUM
8960 && (TARGET_CPU_ZARCH
8961 || (cfun_frame_layout
.first_save_gpr
<= RETURN_REGNUM
8962 && cfun_frame_layout
.last_save_gpr
>= RETURN_REGNUM
)))
8965 /* Search for prologue/epilogue insns and replace them. */
8967 for (insn
= get_insns (); insn
; insn
= next_insn
)
8969 int first
, last
, off
;
8970 rtx set
, base
, offset
;
8972 next_insn
= NEXT_INSN (insn
);
8974 if (GET_CODE (insn
) != INSN
)
8977 if (GET_CODE (PATTERN (insn
)) == PARALLEL
8978 && store_multiple_operation (PATTERN (insn
), VOIDmode
))
8980 set
= XVECEXP (PATTERN (insn
), 0, 0);
8981 first
= REGNO (SET_SRC (set
));
8982 last
= first
+ XVECLEN (PATTERN (insn
), 0) - 1;
8983 offset
= const0_rtx
;
8984 base
= eliminate_constant_term (XEXP (SET_DEST (set
), 0), &offset
);
8985 off
= INTVAL (offset
);
8987 if (GET_CODE (base
) != REG
|| off
< 0)
8989 if (cfun_frame_layout
.first_save_gpr
!= -1
8990 && (cfun_frame_layout
.first_save_gpr
< first
8991 || cfun_frame_layout
.last_save_gpr
> last
))
8993 if (REGNO (base
) != STACK_POINTER_REGNUM
8994 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
8996 if (first
> BASE_REGNUM
|| last
< BASE_REGNUM
)
8999 if (cfun_frame_layout
.first_save_gpr
!= -1)
9001 new_insn
= save_gprs (base
,
9002 off
+ (cfun_frame_layout
.first_save_gpr
9003 - first
) * UNITS_PER_WORD
,
9004 cfun_frame_layout
.first_save_gpr
,
9005 cfun_frame_layout
.last_save_gpr
);
9006 new_insn
= emit_insn_before (new_insn
, insn
);
9007 INSN_ADDRESSES_NEW (new_insn
, -1);
9014 if (cfun_frame_layout
.first_save_gpr
== -1
9015 && GET_CODE (PATTERN (insn
)) == SET
9016 && GET_CODE (SET_SRC (PATTERN (insn
))) == REG
9017 && (REGNO (SET_SRC (PATTERN (insn
))) == BASE_REGNUM
9018 || (!TARGET_CPU_ZARCH
9019 && REGNO (SET_SRC (PATTERN (insn
))) == RETURN_REGNUM
))
9020 && GET_CODE (SET_DEST (PATTERN (insn
))) == MEM
)
9022 set
= PATTERN (insn
);
9023 first
= REGNO (SET_SRC (set
));
9024 offset
= const0_rtx
;
9025 base
= eliminate_constant_term (XEXP (SET_DEST (set
), 0), &offset
);
9026 off
= INTVAL (offset
);
9028 if (GET_CODE (base
) != REG
|| off
< 0)
9030 if (REGNO (base
) != STACK_POINTER_REGNUM
9031 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
9038 if (GET_CODE (PATTERN (insn
)) == PARALLEL
9039 && load_multiple_operation (PATTERN (insn
), VOIDmode
))
9041 set
= XVECEXP (PATTERN (insn
), 0, 0);
9042 first
= REGNO (SET_DEST (set
));
9043 last
= first
+ XVECLEN (PATTERN (insn
), 0) - 1;
9044 offset
= const0_rtx
;
9045 base
= eliminate_constant_term (XEXP (SET_SRC (set
), 0), &offset
);
9046 off
= INTVAL (offset
);
9048 if (GET_CODE (base
) != REG
|| off
< 0)
9050 if (cfun_frame_layout
.first_restore_gpr
!= -1
9051 && (cfun_frame_layout
.first_restore_gpr
< first
9052 || cfun_frame_layout
.last_restore_gpr
> last
))
9054 if (REGNO (base
) != STACK_POINTER_REGNUM
9055 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
9057 if (first
> BASE_REGNUM
|| last
< BASE_REGNUM
)
9060 if (cfun_frame_layout
.first_restore_gpr
!= -1)
9062 new_insn
= restore_gprs (base
,
9063 off
+ (cfun_frame_layout
.first_restore_gpr
9064 - first
) * UNITS_PER_WORD
,
9065 cfun_frame_layout
.first_restore_gpr
,
9066 cfun_frame_layout
.last_restore_gpr
);
9067 new_insn
= emit_insn_before (new_insn
, insn
);
9068 INSN_ADDRESSES_NEW (new_insn
, -1);
9075 if (cfun_frame_layout
.first_restore_gpr
== -1
9076 && GET_CODE (PATTERN (insn
)) == SET
9077 && GET_CODE (SET_DEST (PATTERN (insn
))) == REG
9078 && (REGNO (SET_DEST (PATTERN (insn
))) == BASE_REGNUM
9079 || (!TARGET_CPU_ZARCH
9080 && REGNO (SET_DEST (PATTERN (insn
))) == RETURN_REGNUM
))
9081 && GET_CODE (SET_SRC (PATTERN (insn
))) == MEM
)
9083 set
= PATTERN (insn
);
9084 first
= REGNO (SET_DEST (set
));
9085 offset
= const0_rtx
;
9086 base
= eliminate_constant_term (XEXP (SET_SRC (set
), 0), &offset
);
9087 off
= INTVAL (offset
);
9089 if (GET_CODE (base
) != REG
|| off
< 0)
9091 if (REGNO (base
) != STACK_POINTER_REGNUM
9092 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
9101 /* Perform machine-dependent processing. */
9106 bool pool_overflow
= false;
9108 /* Make sure all splits have been performed; splits after
9109 machine_dependent_reorg might confuse insn length counts. */
9110 split_all_insns_noflow ();
9112 /* From here on decomposed literal pool addresses must be accepted. */
9113 cfun
->machine
->decomposed_literal_pool_addresses_ok_p
= true;
9115 /* Install the main literal pool and the associated base
9116 register load insns.
9118 In addition, there are two problematic situations we need
9121 - the literal pool might be > 4096 bytes in size, so that
9122 some of its elements cannot be directly accessed
9124 - a branch target might be > 64K away from the branch, so that
9125 it is not possible to use a PC-relative instruction.
9127 To fix those, we split the single literal pool into multiple
9128 pool chunks, reloading the pool base register at various
9129 points throughout the function to ensure it always points to
9130 the pool chunk the following code expects, and / or replace
9131 PC-relative branches by absolute branches.
9133 However, the two problems are interdependent: splitting the
9134 literal pool can move a branch further away from its target,
9135 causing the 64K limit to overflow, and on the other hand,
9136 replacing a PC-relative branch by an absolute branch means
9137 we need to put the branch target address into the literal
9138 pool, possibly causing it to overflow.
9140 So, we loop trying to fix up both problems until we manage
9141 to satisfy both conditions at the same time. Note that the
9142 loop is guaranteed to terminate as every pass of the loop
9143 strictly decreases the total number of PC-relative branches
9144 in the function. (This is not completely true as there
9145 might be branch-over-pool insns introduced by chunkify_start.
9146 Those never need to be split however.) */
9150 struct constant_pool
*pool
= NULL
;
9152 /* Collect the literal pool. */
9155 pool
= s390_mainpool_start ();
9157 pool_overflow
= true;
9160 /* If literal pool overflowed, start to chunkify it. */
9162 pool
= s390_chunkify_start ();
9164 /* Split out-of-range branches. If this has created new
9165 literal pool entries, cancel current chunk list and
9166 recompute it. zSeries machines have large branch
9167 instructions, so we never need to split a branch. */
9168 if (!TARGET_CPU_ZARCH
&& s390_split_branches ())
9171 s390_chunkify_cancel (pool
);
9173 s390_mainpool_cancel (pool
);
9178 /* If we made it up to here, both conditions are satisfied.
9179 Finish up literal pool related changes. */
9181 s390_chunkify_finish (pool
);
9183 s390_mainpool_finish (pool
);
9185 /* We're done splitting branches. */
9186 cfun
->machine
->split_branches_pending_p
= false;
9190 /* Generate out-of-pool execute target insns. */
9191 if (TARGET_CPU_ZARCH
)
9193 rtx insn
, label
, target
;
9195 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
9197 label
= s390_execute_label (insn
);
9201 gcc_assert (label
!= const0_rtx
);
9203 target
= emit_label (XEXP (label
, 0));
9204 INSN_ADDRESSES_NEW (target
, -1);
9206 target
= emit_insn (s390_execute_target (insn
));
9207 INSN_ADDRESSES_NEW (target
, -1);
9211 /* Try to optimize prologue and epilogue further. */
9212 s390_optimize_prologue ();
9216 /* Initialize GCC target structure. */
9218 #undef TARGET_ASM_ALIGNED_HI_OP
9219 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
9220 #undef TARGET_ASM_ALIGNED_DI_OP
9221 #define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
9222 #undef TARGET_ASM_INTEGER
9223 #define TARGET_ASM_INTEGER s390_assemble_integer
9225 #undef TARGET_ASM_OPEN_PAREN
9226 #define TARGET_ASM_OPEN_PAREN ""
9228 #undef TARGET_ASM_CLOSE_PAREN
9229 #define TARGET_ASM_CLOSE_PAREN ""
9231 #undef TARGET_DEFAULT_TARGET_FLAGS
9232 #define TARGET_DEFAULT_TARGET_FLAGS (TARGET_DEFAULT | MASK_FUSED_MADD)
9233 #undef TARGET_HANDLE_OPTION
9234 #define TARGET_HANDLE_OPTION s390_handle_option
9236 #undef TARGET_ENCODE_SECTION_INFO
9237 #define TARGET_ENCODE_SECTION_INFO s390_encode_section_info
9240 #undef TARGET_HAVE_TLS
9241 #define TARGET_HAVE_TLS true
9243 #undef TARGET_CANNOT_FORCE_CONST_MEM
9244 #define TARGET_CANNOT_FORCE_CONST_MEM s390_cannot_force_const_mem
9246 #undef TARGET_DELEGITIMIZE_ADDRESS
9247 #define TARGET_DELEGITIMIZE_ADDRESS s390_delegitimize_address
9249 #undef TARGET_RETURN_IN_MEMORY
9250 #define TARGET_RETURN_IN_MEMORY s390_return_in_memory
9252 #undef TARGET_INIT_BUILTINS
9253 #define TARGET_INIT_BUILTINS s390_init_builtins
9254 #undef TARGET_EXPAND_BUILTIN
9255 #define TARGET_EXPAND_BUILTIN s390_expand_builtin
9257 #undef TARGET_ASM_OUTPUT_MI_THUNK
9258 #define TARGET_ASM_OUTPUT_MI_THUNK s390_output_mi_thunk
9259 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
9260 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
9262 #undef TARGET_SCHED_ADJUST_PRIORITY
9263 #define TARGET_SCHED_ADJUST_PRIORITY s390_adjust_priority
9264 #undef TARGET_SCHED_ISSUE_RATE
9265 #define TARGET_SCHED_ISSUE_RATE s390_issue_rate
9266 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
9267 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD s390_first_cycle_multipass_dfa_lookahead
9269 #undef TARGET_CANNOT_COPY_INSN_P
9270 #define TARGET_CANNOT_COPY_INSN_P s390_cannot_copy_insn_p
9271 #undef TARGET_RTX_COSTS
9272 #define TARGET_RTX_COSTS s390_rtx_costs
9273 #undef TARGET_ADDRESS_COST
9274 #define TARGET_ADDRESS_COST s390_address_cost
9276 #undef TARGET_MACHINE_DEPENDENT_REORG
9277 #define TARGET_MACHINE_DEPENDENT_REORG s390_reorg
9279 #undef TARGET_VALID_POINTER_MODE
9280 #define TARGET_VALID_POINTER_MODE s390_valid_pointer_mode
9282 #undef TARGET_BUILD_BUILTIN_VA_LIST
9283 #define TARGET_BUILD_BUILTIN_VA_LIST s390_build_builtin_va_list
9284 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
9285 #define TARGET_GIMPLIFY_VA_ARG_EXPR s390_gimplify_va_arg
9287 #undef TARGET_PROMOTE_FUNCTION_ARGS
9288 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
9289 #undef TARGET_PROMOTE_FUNCTION_RETURN
9290 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
9291 #undef TARGET_PASS_BY_REFERENCE
9292 #define TARGET_PASS_BY_REFERENCE s390_pass_by_reference
9294 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
9295 #define TARGET_FUNCTION_OK_FOR_SIBCALL s390_function_ok_for_sibcall
9297 #undef TARGET_FIXED_CONDITION_CODE_REGS
9298 #define TARGET_FIXED_CONDITION_CODE_REGS s390_fixed_condition_code_regs
9300 #undef TARGET_CC_MODES_COMPATIBLE
9301 #define TARGET_CC_MODES_COMPATIBLE s390_cc_modes_compatible
9303 #undef TARGET_INVALID_WITHIN_DOLOOP
9304 #define TARGET_INVALID_WITHIN_DOLOOP hook_constcharptr_rtx_null
9307 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
9308 #define TARGET_ASM_OUTPUT_DWARF_DTPREL s390_output_dwarf_dtprel
9311 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
9312 #undef TARGET_MANGLE_FUNDAMENTAL_TYPE
9313 #define TARGET_MANGLE_FUNDAMENTAL_TYPE s390_mangle_fundamental_type
9316 #undef TARGET_SCALAR_MODE_SUPPORTED_P
9317 #define TARGET_SCALAR_MODE_SUPPORTED_P s390_scalar_mode_supported_p
9319 struct gcc_target targetm
= TARGET_INITIALIZER
;
9321 #include "gt-s390.h"