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
)
1747 /* Accept chunkified literal pool symbol references. */
1748 else if (cfun
&& cfun
->machine
1749 && cfun
->machine
->decomposed_literal_pool_addresses_ok_p
1750 && GET_CODE (disp
) == MINUS
1751 && GET_CODE (XEXP (disp
, 0)) == LABEL_REF
1752 && GET_CODE (XEXP (disp
, 1)) == LABEL_REF
)
1757 /* Accept literal pool references. */
1758 else if (GET_CODE (disp
) == UNSPEC
1759 && XINT (disp
, 1) == UNSPEC_LTREL_OFFSET
)
1761 orig_disp
= gen_rtx_CONST (Pmode
, disp
);
1764 /* If we have an offset, make sure it does not
1765 exceed the size of the constant pool entry. */
1766 rtx sym
= XVECEXP (disp
, 0, 0);
1767 if (offset
>= GET_MODE_SIZE (get_pool_mode (sym
)))
1770 orig_disp
= plus_constant (orig_disp
, offset
);
1785 out
->disp
= orig_disp
;
1786 out
->pointer
= pointer
;
1787 out
->literal_pool
= literal_pool
;
1793 /* Decompose a RTL expression OP for a shift count into its components,
1794 and return the base register in BASE and the offset in OFFSET.
1796 Return true if OP is a valid shift count, false if not. */
1799 s390_decompose_shift_count (rtx op
, rtx
*base
, HOST_WIDE_INT
*offset
)
1801 HOST_WIDE_INT off
= 0;
1803 /* We can have an integer constant, an address register,
1804 or a sum of the two. */
1805 if (GET_CODE (op
) == CONST_INT
)
1810 if (op
&& GET_CODE (op
) == PLUS
&& GET_CODE (XEXP (op
, 1)) == CONST_INT
)
1812 off
= INTVAL (XEXP (op
, 1));
1815 while (op
&& GET_CODE (op
) == SUBREG
)
1816 op
= SUBREG_REG (op
);
1818 if (op
&& GET_CODE (op
) != REG
)
1830 /* Return true if CODE is a valid address without index. */
1833 s390_legitimate_address_without_index_p (rtx op
)
1835 struct s390_address addr
;
1837 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
1845 /* Return 1 if OP is a valid operand for a C constraint, 0 else. */
1848 s390_extra_constraint_str (rtx op
, int c
, const char * str
)
1850 struct s390_address addr
;
1852 gcc_assert (c
== str
[0]);
1854 /* Check for offsettable variants of memory constraints. */
1857 /* Only accept non-volatile MEMs. */
1858 if (!MEM_P (op
) || MEM_VOLATILE_P (op
))
1861 if ((reload_completed
|| reload_in_progress
)
1862 ? !offsettable_memref_p (op
)
1863 : !offsettable_nonstrict_memref_p (op
))
1869 /* Check for non-literal-pool variants of memory constraints. */
1872 if (GET_CODE (op
) != MEM
)
1874 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
1876 if (addr
.literal_pool
)
1885 if (GET_CODE (op
) != MEM
)
1887 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
1892 if (TARGET_LONG_DISPLACEMENT
)
1894 if (!s390_short_displacement (addr
.disp
))
1900 if (GET_CODE (op
) != MEM
)
1903 if (TARGET_LONG_DISPLACEMENT
)
1905 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
1907 if (!s390_short_displacement (addr
.disp
))
1913 if (!TARGET_LONG_DISPLACEMENT
)
1915 if (GET_CODE (op
) != MEM
)
1917 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
1921 if (s390_short_displacement (addr
.disp
))
1926 if (!TARGET_LONG_DISPLACEMENT
)
1928 if (GET_CODE (op
) != MEM
)
1930 /* Any invalid address here will be fixed up by reload,
1931 so accept it for the most generic constraint. */
1932 if (s390_decompose_address (XEXP (op
, 0), &addr
)
1933 && s390_short_displacement (addr
.disp
))
1938 if (TARGET_LONG_DISPLACEMENT
)
1940 if (!s390_decompose_address (op
, &addr
))
1942 if (!s390_short_displacement (addr
.disp
))
1948 if (!TARGET_LONG_DISPLACEMENT
)
1950 /* Any invalid address here will be fixed up by reload,
1951 so accept it for the most generic constraint. */
1952 if (s390_decompose_address (op
, &addr
)
1953 && s390_short_displacement (addr
.disp
))
1958 /* Simply check for the basic form of a shift count. Reload will
1959 take care of making sure we have a proper base register. */
1960 if (!s390_decompose_shift_count (op
, NULL
, NULL
))
1971 /* Return true if VALUE matches the constraint STR. */
1974 s390_const_double_ok_for_constraint_p (rtx value
,
1978 gcc_assert (c
== str
[0]);
1983 /* The floating point zero constant. */
1984 return (GET_MODE_CLASS (GET_MODE (value
)) == MODE_FLOAT
1985 && value
== CONST0_RTX (GET_MODE (value
)));
1992 /* Return true if VALUE matches the constraint STR. */
1995 s390_const_ok_for_constraint_p (HOST_WIDE_INT value
,
1999 enum machine_mode mode
, part_mode
;
2001 int part
, part_goal
;
2003 gcc_assert (c
== str
[0]);
2008 return (unsigned int)value
< 256;
2011 return (unsigned int)value
< 4096;
2014 return value
>= -32768 && value
< 32768;
2017 return (TARGET_LONG_DISPLACEMENT
?
2018 (value
>= -524288 && value
<= 524287)
2019 : (value
>= 0 && value
<= 4095));
2021 return value
== 2147483647;
2027 part_goal
= str
[1] - '0';
2031 case 'Q': part_mode
= QImode
; break;
2032 case 'H': part_mode
= HImode
; break;
2033 case 'S': part_mode
= SImode
; break;
2039 case 'H': mode
= HImode
; break;
2040 case 'S': mode
= SImode
; break;
2041 case 'D': mode
= DImode
; break;
2047 case '0': def
= 0; break;
2048 case 'F': def
= -1; break;
2052 if (GET_MODE_SIZE (mode
) <= GET_MODE_SIZE (part_mode
))
2055 part
= s390_single_part (GEN_INT (value
), mode
, part_mode
, def
);
2058 if (part_goal
!= -1 && part_goal
!= part
)
2070 return trunc_int_for_mode (value
, SImode
) == value
;
2074 || s390_single_part (GEN_INT (value
), DImode
, SImode
, 0) == 1;
2079 || s390_single_part (GEN_INT (value
), DImode
, SImode
, -1) == 1)
2080 && value
!= -((HOST_WIDE_INT
)1 << 32);
2088 return legitimate_reload_constant_p (GEN_INT (value
));
2097 /* Compute a (partial) cost for rtx X. Return true if the complete
2098 cost has been computed, and false if subexpressions should be
2099 scanned. In either case, *TOTAL contains the cost result.
2100 CODE contains GET_CODE (x), OUTER_CODE contains the code
2101 of the superexpression of x. */
2104 s390_rtx_costs (rtx x
, int code
, int outer_code
, int *total
)
2127 *total
= COSTS_N_INSNS (1);
2132 /* Check for multiply and add. */
2133 if ((GET_MODE (x
) == DFmode
|| GET_MODE (x
) == SFmode
)
2134 && GET_CODE (XEXP (x
, 0)) == MULT
2135 && TARGET_HARD_FLOAT
&& TARGET_IEEE_FLOAT
&& TARGET_FUSED_MADD
)
2137 /* This is the multiply and add case. */
2138 if (GET_MODE (x
) == DFmode
)
2139 *total
= s390_cost
->madbr
;
2141 *total
= s390_cost
->maebr
;
2142 *total
+= rtx_cost (XEXP (XEXP (x
, 0), 0), MULT
)
2143 + rtx_cost (XEXP (XEXP (x
, 0), 1), MULT
)
2144 + rtx_cost (XEXP (x
, 1), code
);
2145 return true; /* Do not do an additional recursive descent. */
2147 *total
= COSTS_N_INSNS (1);
2151 switch (GET_MODE (x
))
2155 rtx left
= XEXP (x
, 0);
2156 rtx right
= XEXP (x
, 1);
2157 if (GET_CODE (right
) == CONST_INT
2158 && CONST_OK_FOR_K (INTVAL (right
)))
2159 *total
= s390_cost
->mhi
;
2160 else if (GET_CODE (left
) == SIGN_EXTEND
)
2161 *total
= s390_cost
->mh
;
2163 *total
= s390_cost
->ms
; /* msr, ms, msy */
2168 rtx left
= XEXP (x
, 0);
2169 rtx right
= XEXP (x
, 1);
2172 if (GET_CODE (right
) == CONST_INT
2173 && CONST_OK_FOR_K (INTVAL (right
)))
2174 *total
= s390_cost
->mghi
;
2175 else if (GET_CODE (left
) == SIGN_EXTEND
)
2176 *total
= s390_cost
->msgf
;
2178 *total
= s390_cost
->msg
; /* msgr, msg */
2180 else /* TARGET_31BIT */
2182 if (GET_CODE (left
) == SIGN_EXTEND
2183 && GET_CODE (right
) == SIGN_EXTEND
)
2184 /* mulsidi case: mr, m */
2185 *total
= s390_cost
->m
;
2186 else if (GET_CODE (left
) == ZERO_EXTEND
2187 && GET_CODE (right
) == ZERO_EXTEND
2188 && TARGET_CPU_ZARCH
)
2189 /* umulsidi case: ml, mlr */
2190 *total
= s390_cost
->ml
;
2192 /* Complex calculation is required. */
2193 *total
= COSTS_N_INSNS (40);
2199 *total
= s390_cost
->mult_df
;
2202 *total
= s390_cost
->mxbr
;
2211 if (GET_MODE (x
) == TImode
) /* 128 bit division */
2212 *total
= s390_cost
->dlgr
;
2213 else if (GET_MODE (x
) == DImode
)
2215 rtx right
= XEXP (x
, 1);
2216 if (GET_CODE (right
) == ZERO_EXTEND
) /* 64 by 32 bit division */
2217 *total
= s390_cost
->dlr
;
2218 else /* 64 by 64 bit division */
2219 *total
= s390_cost
->dlgr
;
2221 else if (GET_MODE (x
) == SImode
) /* 32 bit division */
2222 *total
= s390_cost
->dlr
;
2227 if (GET_MODE (x
) == DImode
)
2229 rtx right
= XEXP (x
, 1);
2230 if (GET_CODE (right
) == ZERO_EXTEND
) /* 64 by 32 bit division */
2232 *total
= s390_cost
->dsgfr
;
2234 *total
= s390_cost
->dr
;
2235 else /* 64 by 64 bit division */
2236 *total
= s390_cost
->dsgr
;
2238 else if (GET_MODE (x
) == SImode
) /* 32 bit division */
2239 *total
= s390_cost
->dlr
;
2240 else if (GET_MODE (x
) == SFmode
)
2242 if (TARGET_IEEE_FLOAT
)
2243 *total
= s390_cost
->debr
;
2244 else /* TARGET_IBM_FLOAT */
2245 *total
= s390_cost
->der
;
2247 else if (GET_MODE (x
) == DFmode
)
2249 if (TARGET_IEEE_FLOAT
)
2250 *total
= s390_cost
->ddbr
;
2251 else /* TARGET_IBM_FLOAT */
2252 *total
= s390_cost
->ddr
;
2254 else if (GET_MODE (x
) == TFmode
)
2256 if (TARGET_IEEE_FLOAT
)
2257 *total
= s390_cost
->dxbr
;
2258 else /* TARGET_IBM_FLOAT */
2259 *total
= s390_cost
->dxr
;
2264 if (GET_MODE (x
) == SFmode
)
2265 *total
= s390_cost
->sqebr
;
2266 else if (GET_MODE (x
) == DFmode
)
2267 *total
= s390_cost
->sqdbr
;
2269 *total
= s390_cost
->sqxbr
;
2274 if (outer_code
== MULT
|| outer_code
== DIV
|| outer_code
== MOD
2275 || outer_code
== PLUS
|| outer_code
== MINUS
2276 || outer_code
== COMPARE
)
2281 *total
= COSTS_N_INSNS (1);
2282 if (GET_CODE (XEXP (x
, 0)) == AND
2283 && GET_CODE (XEXP (x
, 1)) == CONST_INT
2284 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
)
2286 rtx op0
= XEXP (XEXP (x
, 0), 0);
2287 rtx op1
= XEXP (XEXP (x
, 0), 1);
2288 rtx op2
= XEXP (x
, 1);
2290 if (memory_operand (op0
, GET_MODE (op0
))
2291 && s390_tm_ccmode (op1
, op2
, 0) != VOIDmode
)
2293 if (register_operand (op0
, GET_MODE (op0
))
2294 && s390_tm_ccmode (op1
, op2
, 1) != VOIDmode
)
2304 /* Return the cost of an address rtx ADDR. */
2307 s390_address_cost (rtx addr
)
2309 struct s390_address ad
;
2310 if (!s390_decompose_address (addr
, &ad
))
2313 return ad
.indx
? COSTS_N_INSNS (1) + 1 : COSTS_N_INSNS (1);
2316 /* If OP is a SYMBOL_REF of a thread-local symbol, return its TLS mode,
2317 otherwise return 0. */
2320 tls_symbolic_operand (rtx op
)
2322 if (GET_CODE (op
) != SYMBOL_REF
)
2324 return SYMBOL_REF_TLS_MODEL (op
);
2327 /* Split DImode access register reference REG (on 64-bit) into its constituent
2328 low and high parts, and store them into LO and HI. Note that gen_lowpart/
2329 gen_highpart cannot be used as they assume all registers are word-sized,
2330 while our access registers have only half that size. */
2333 s390_split_access_reg (rtx reg
, rtx
*lo
, rtx
*hi
)
2335 gcc_assert (TARGET_64BIT
);
2336 gcc_assert (ACCESS_REG_P (reg
));
2337 gcc_assert (GET_MODE (reg
) == DImode
);
2338 gcc_assert (!(REGNO (reg
) & 1));
2340 *lo
= gen_rtx_REG (SImode
, REGNO (reg
) + 1);
2341 *hi
= gen_rtx_REG (SImode
, REGNO (reg
));
2344 /* Return true if OP contains a symbol reference */
2347 symbolic_reference_mentioned_p (rtx op
)
2352 if (GET_CODE (op
) == SYMBOL_REF
|| GET_CODE (op
) == LABEL_REF
)
2355 fmt
= GET_RTX_FORMAT (GET_CODE (op
));
2356 for (i
= GET_RTX_LENGTH (GET_CODE (op
)) - 1; i
>= 0; i
--)
2362 for (j
= XVECLEN (op
, i
) - 1; j
>= 0; j
--)
2363 if (symbolic_reference_mentioned_p (XVECEXP (op
, i
, j
)))
2367 else if (fmt
[i
] == 'e' && symbolic_reference_mentioned_p (XEXP (op
, i
)))
2374 /* Return true if OP contains a reference to a thread-local symbol. */
2377 tls_symbolic_reference_mentioned_p (rtx op
)
2382 if (GET_CODE (op
) == SYMBOL_REF
)
2383 return tls_symbolic_operand (op
);
2385 fmt
= GET_RTX_FORMAT (GET_CODE (op
));
2386 for (i
= GET_RTX_LENGTH (GET_CODE (op
)) - 1; i
>= 0; i
--)
2392 for (j
= XVECLEN (op
, i
) - 1; j
>= 0; j
--)
2393 if (tls_symbolic_reference_mentioned_p (XVECEXP (op
, i
, j
)))
2397 else if (fmt
[i
] == 'e' && tls_symbolic_reference_mentioned_p (XEXP (op
, i
)))
2405 /* Return true if OP is a legitimate general operand when
2406 generating PIC code. It is given that flag_pic is on
2407 and that OP satisfies CONSTANT_P or is a CONST_DOUBLE. */
2410 legitimate_pic_operand_p (rtx op
)
2412 /* Accept all non-symbolic constants. */
2413 if (!SYMBOLIC_CONST (op
))
2416 /* Reject everything else; must be handled
2417 via emit_symbolic_move. */
2421 /* Returns true if the constant value OP is a legitimate general operand.
2422 It is given that OP satisfies CONSTANT_P or is a CONST_DOUBLE. */
2425 legitimate_constant_p (rtx op
)
2427 /* Accept all non-symbolic constants. */
2428 if (!SYMBOLIC_CONST (op
))
2431 /* Accept immediate LARL operands. */
2432 if (TARGET_CPU_ZARCH
&& larl_operand (op
, VOIDmode
))
2435 /* Thread-local symbols are never legal constants. This is
2436 so that emit_call knows that computing such addresses
2437 might require a function call. */
2438 if (TLS_SYMBOLIC_CONST (op
))
2441 /* In the PIC case, symbolic constants must *not* be
2442 forced into the literal pool. We accept them here,
2443 so that they will be handled by emit_symbolic_move. */
2447 /* All remaining non-PIC symbolic constants are
2448 forced into the literal pool. */
2452 /* Determine if it's legal to put X into the constant pool. This
2453 is not possible if X contains the address of a symbol that is
2454 not constant (TLS) or not known at final link time (PIC). */
2457 s390_cannot_force_const_mem (rtx x
)
2459 switch (GET_CODE (x
))
2463 /* Accept all non-symbolic constants. */
2467 /* Labels are OK iff we are non-PIC. */
2468 return flag_pic
!= 0;
2471 /* 'Naked' TLS symbol references are never OK,
2472 non-TLS symbols are OK iff we are non-PIC. */
2473 if (tls_symbolic_operand (x
))
2476 return flag_pic
!= 0;
2479 return s390_cannot_force_const_mem (XEXP (x
, 0));
2482 return s390_cannot_force_const_mem (XEXP (x
, 0))
2483 || s390_cannot_force_const_mem (XEXP (x
, 1));
2486 switch (XINT (x
, 1))
2488 /* Only lt-relative or GOT-relative UNSPECs are OK. */
2489 case UNSPEC_LTREL_OFFSET
:
2497 case UNSPEC_GOTNTPOFF
:
2498 case UNSPEC_INDNTPOFF
:
2501 /* If the literal pool shares the code section, be put
2502 execute template placeholders into the pool as well. */
2504 return TARGET_CPU_ZARCH
;
2516 /* Returns true if the constant value OP is a legitimate general
2517 operand during and after reload. The difference to
2518 legitimate_constant_p is that this function will not accept
2519 a constant that would need to be forced to the literal pool
2520 before it can be used as operand. */
2523 legitimate_reload_constant_p (rtx op
)
2525 /* Accept la(y) operands. */
2526 if (GET_CODE (op
) == CONST_INT
2527 && DISP_IN_RANGE (INTVAL (op
)))
2530 /* Accept l(g)hi/l(g)fi operands. */
2531 if (GET_CODE (op
) == CONST_INT
2532 && (CONST_OK_FOR_K (INTVAL (op
)) || CONST_OK_FOR_Os (INTVAL (op
))))
2535 /* Accept lliXX operands. */
2537 && GET_CODE (op
) == CONST_INT
2538 && trunc_int_for_mode (INTVAL (op
), word_mode
) == INTVAL (op
)
2539 && s390_single_part (op
, word_mode
, HImode
, 0) >= 0)
2543 && GET_CODE (op
) == CONST_INT
2544 && trunc_int_for_mode (INTVAL (op
), word_mode
) == INTVAL (op
)
2545 && s390_single_part (op
, word_mode
, SImode
, 0) >= 0)
2548 /* Accept larl operands. */
2549 if (TARGET_CPU_ZARCH
2550 && larl_operand (op
, VOIDmode
))
2553 /* Accept lzXX operands. */
2554 if (GET_CODE (op
) == CONST_DOUBLE
2555 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op
, 'G', "G"))
2558 /* Accept double-word operands that can be split. */
2559 if (GET_CODE (op
) == CONST_INT
2560 && trunc_int_for_mode (INTVAL (op
), word_mode
) != INTVAL (op
))
2562 enum machine_mode dword_mode
= word_mode
== SImode
? DImode
: TImode
;
2563 rtx hi
= operand_subword (op
, 0, 0, dword_mode
);
2564 rtx lo
= operand_subword (op
, 1, 0, dword_mode
);
2565 return legitimate_reload_constant_p (hi
)
2566 && legitimate_reload_constant_p (lo
);
2569 /* Everything else cannot be handled without reload. */
2573 /* Given an rtx OP being reloaded into a reg required to be in class CLASS,
2574 return the class of reg to actually use. */
2577 s390_preferred_reload_class (rtx op
, enum reg_class
class)
2579 switch (GET_CODE (op
))
2581 /* Constants we cannot reload must be forced into the
2586 if (legitimate_reload_constant_p (op
))
2591 /* If a symbolic constant or a PLUS is reloaded,
2592 it is most likely being used as an address, so
2593 prefer ADDR_REGS. If 'class' is not a superset
2594 of ADDR_REGS, e.g. FP_REGS, reject this reload. */
2599 if (reg_class_subset_p (ADDR_REGS
, class))
2611 /* Return the register class of a scratch register needed to
2612 load IN into a register of class CLASS in MODE.
2614 We need a temporary when loading a PLUS expression which
2615 is not a legitimate operand of the LOAD ADDRESS instruction. */
2618 s390_secondary_input_reload_class (enum reg_class
class,
2619 enum machine_mode mode
, rtx in
)
2621 if (s390_plus_operand (in
, mode
))
2624 if (reg_classes_intersect_p (FP_REGS
, class)
2626 && GET_CODE (in
) == MEM
2627 && GET_CODE (XEXP (in
, 0)) == PLUS
2628 && GET_CODE (XEXP (XEXP (in
, 0), 1)) == CONST_INT
2629 && !DISP_IN_RANGE (INTVAL (XEXP (XEXP (in
, 0), 1))
2630 + GET_MODE_SIZE (mode
) - 1))
2633 if (reg_classes_intersect_p (CC_REGS
, class))
2634 return GENERAL_REGS
;
2639 /* Return the register class of a scratch register needed to
2640 store a register of class CLASS in MODE into OUT:
2642 We need a temporary when storing a double-word to a
2643 non-offsettable memory address. */
2646 s390_secondary_output_reload_class (enum reg_class
class,
2647 enum machine_mode mode
, rtx out
)
2649 if ((TARGET_64BIT
? (mode
== TImode
|| mode
== TFmode
)
2650 : (mode
== DImode
|| mode
== DFmode
))
2651 && reg_classes_intersect_p (GENERAL_REGS
, class)
2652 && GET_CODE (out
) == MEM
2653 && GET_CODE (XEXP (out
, 0)) == PLUS
2654 && GET_CODE (XEXP (XEXP (out
, 0), 0)) == PLUS
2655 && GET_CODE (XEXP (XEXP (out
, 0), 1)) == CONST_INT
2656 && !DISP_IN_RANGE (INTVAL (XEXP (XEXP (out
, 0), 1))
2657 + GET_MODE_SIZE (mode
) - 1))
2660 if (reg_classes_intersect_p (FP_REGS
, class)
2662 && GET_CODE (out
) == MEM
2663 && GET_CODE (XEXP (out
, 0)) == PLUS
2664 && GET_CODE (XEXP (XEXP (out
, 0), 1)) == CONST_INT
2665 && !DISP_IN_RANGE (INTVAL (XEXP (XEXP (out
, 0), 1))
2666 + GET_MODE_SIZE (mode
) - 1))
2669 if (reg_classes_intersect_p (CC_REGS
, class))
2670 return GENERAL_REGS
;
2675 /* Generate code to load SRC, which is PLUS that is not a
2676 legitimate operand for the LA instruction, into TARGET.
2677 SCRATCH may be used as scratch register. */
2680 s390_expand_plus_operand (rtx target
, rtx src
,
2684 struct s390_address ad
;
2686 /* src must be a PLUS; get its two operands. */
2687 gcc_assert (GET_CODE (src
) == PLUS
);
2688 gcc_assert (GET_MODE (src
) == Pmode
);
2690 /* Check if any of the two operands is already scheduled
2691 for replacement by reload. This can happen e.g. when
2692 float registers occur in an address. */
2693 sum1
= find_replacement (&XEXP (src
, 0));
2694 sum2
= find_replacement (&XEXP (src
, 1));
2695 src
= gen_rtx_PLUS (Pmode
, sum1
, sum2
);
2697 /* If the address is already strictly valid, there's nothing to do. */
2698 if (!s390_decompose_address (src
, &ad
)
2699 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
2700 || (ad
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (ad
.indx
))))
2702 /* Otherwise, one of the operands cannot be an address register;
2703 we reload its value into the scratch register. */
2704 if (true_regnum (sum1
) < 1 || true_regnum (sum1
) > 15)
2706 emit_move_insn (scratch
, sum1
);
2709 if (true_regnum (sum2
) < 1 || true_regnum (sum2
) > 15)
2711 emit_move_insn (scratch
, sum2
);
2715 /* According to the way these invalid addresses are generated
2716 in reload.c, it should never happen (at least on s390) that
2717 *neither* of the PLUS components, after find_replacements
2718 was applied, is an address register. */
2719 if (sum1
== scratch
&& sum2
== scratch
)
2725 src
= gen_rtx_PLUS (Pmode
, sum1
, sum2
);
2728 /* Emit the LOAD ADDRESS pattern. Note that reload of PLUS
2729 is only ever performed on addresses, so we can mark the
2730 sum as legitimate for LA in any case. */
2731 s390_load_address (target
, src
);
2735 /* Return true if ADDR is a valid memory address.
2736 STRICT specifies whether strict register checking applies. */
2739 legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED
,
2740 rtx addr
, int strict
)
2742 struct s390_address ad
;
2743 if (!s390_decompose_address (addr
, &ad
))
2748 if (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
2751 if (ad
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (ad
.indx
)))
2757 && !(REGNO (ad
.base
) >= FIRST_PSEUDO_REGISTER
2758 || REGNO_REG_CLASS (REGNO (ad
.base
)) == ADDR_REGS
))
2762 && !(REGNO (ad
.indx
) >= FIRST_PSEUDO_REGISTER
2763 || REGNO_REG_CLASS (REGNO (ad
.indx
)) == ADDR_REGS
))
2769 /* Return true if OP is a valid operand for the LA instruction.
2770 In 31-bit, we need to prove that the result is used as an
2771 address, as LA performs only a 31-bit addition. */
2774 legitimate_la_operand_p (rtx op
)
2776 struct s390_address addr
;
2777 if (!s390_decompose_address (op
, &addr
))
2780 return (TARGET_64BIT
|| addr
.pointer
);
2783 /* Return true if it is valid *and* preferable to use LA to
2784 compute the sum of OP1 and OP2. */
2787 preferred_la_operand_p (rtx op1
, rtx op2
)
2789 struct s390_address addr
;
2791 if (op2
!= const0_rtx
)
2792 op1
= gen_rtx_PLUS (Pmode
, op1
, op2
);
2794 if (!s390_decompose_address (op1
, &addr
))
2796 if (addr
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (addr
.base
)))
2798 if (addr
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (addr
.indx
)))
2801 if (!TARGET_64BIT
&& !addr
.pointer
)
2807 if ((addr
.base
&& REG_P (addr
.base
) && REG_POINTER (addr
.base
))
2808 || (addr
.indx
&& REG_P (addr
.indx
) && REG_POINTER (addr
.indx
)))
2814 /* Emit a forced load-address operation to load SRC into DST.
2815 This will use the LOAD ADDRESS instruction even in situations
2816 where legitimate_la_operand_p (SRC) returns false. */
2819 s390_load_address (rtx dst
, rtx src
)
2822 emit_move_insn (dst
, src
);
2824 emit_insn (gen_force_la_31 (dst
, src
));
2827 /* Return a legitimate reference for ORIG (an address) using the
2828 register REG. If REG is 0, a new pseudo is generated.
2830 There are two types of references that must be handled:
2832 1. Global data references must load the address from the GOT, via
2833 the PIC reg. An insn is emitted to do this load, and the reg is
2836 2. Static data references, constant pool addresses, and code labels
2837 compute the address as an offset from the GOT, whose base is in
2838 the PIC reg. Static data objects have SYMBOL_FLAG_LOCAL set to
2839 differentiate them from global data objects. The returned
2840 address is the PIC reg + an unspec constant.
2842 GO_IF_LEGITIMATE_ADDRESS rejects symbolic references unless the PIC
2843 reg also appears in the address. */
2846 legitimize_pic_address (rtx orig
, rtx reg
)
2852 gcc_assert (!TLS_SYMBOLIC_CONST (addr
));
2854 if (GET_CODE (addr
) == LABEL_REF
2855 || (GET_CODE (addr
) == SYMBOL_REF
&& SYMBOL_REF_LOCAL_P (addr
)))
2857 /* This is a local symbol. */
2858 if (TARGET_CPU_ZARCH
&& larl_operand (addr
, VOIDmode
))
2860 /* Access local symbols PC-relative via LARL.
2861 This is the same as in the non-PIC case, so it is
2862 handled automatically ... */
2866 /* Access local symbols relative to the GOT. */
2868 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
2870 if (reload_in_progress
|| reload_completed
)
2871 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
2873 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTOFF
);
2874 addr
= gen_rtx_CONST (Pmode
, addr
);
2875 addr
= force_const_mem (Pmode
, addr
);
2876 emit_move_insn (temp
, addr
);
2878 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
2881 s390_load_address (reg
, new);
2886 else if (GET_CODE (addr
) == SYMBOL_REF
)
2889 reg
= gen_reg_rtx (Pmode
);
2893 /* Assume GOT offset < 4k. This is handled the same way
2894 in both 31- and 64-bit code (@GOT). */
2896 if (reload_in_progress
|| reload_completed
)
2897 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
2899 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOT
);
2900 new = gen_rtx_CONST (Pmode
, new);
2901 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, new);
2902 new = gen_const_mem (Pmode
, new);
2903 emit_move_insn (reg
, new);
2906 else if (TARGET_CPU_ZARCH
)
2908 /* If the GOT offset might be >= 4k, we determine the position
2909 of the GOT entry via a PC-relative LARL (@GOTENT). */
2911 rtx temp
= gen_reg_rtx (Pmode
);
2913 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTENT
);
2914 new = gen_rtx_CONST (Pmode
, new);
2915 emit_move_insn (temp
, new);
2917 new = gen_const_mem (Pmode
, temp
);
2918 emit_move_insn (reg
, new);
2923 /* If the GOT offset might be >= 4k, we have to load it
2924 from the literal pool (@GOT). */
2926 rtx temp
= gen_reg_rtx (Pmode
);
2928 if (reload_in_progress
|| reload_completed
)
2929 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
2931 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOT
);
2932 addr
= gen_rtx_CONST (Pmode
, addr
);
2933 addr
= force_const_mem (Pmode
, addr
);
2934 emit_move_insn (temp
, addr
);
2936 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
2937 new = gen_const_mem (Pmode
, new);
2938 emit_move_insn (reg
, new);
2944 if (GET_CODE (addr
) == CONST
)
2946 addr
= XEXP (addr
, 0);
2947 if (GET_CODE (addr
) == UNSPEC
)
2949 gcc_assert (XVECLEN (addr
, 0) == 1);
2950 switch (XINT (addr
, 1))
2952 /* If someone moved a GOT-relative UNSPEC
2953 out of the literal pool, force them back in. */
2956 new = force_const_mem (Pmode
, orig
);
2959 /* @GOT is OK as is if small. */
2962 new = force_const_mem (Pmode
, orig
);
2965 /* @GOTENT is OK as is. */
2969 /* @PLT is OK as is on 64-bit, must be converted to
2970 GOT-relative @PLTOFF on 31-bit. */
2972 if (!TARGET_CPU_ZARCH
)
2974 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
2976 if (reload_in_progress
|| reload_completed
)
2977 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
2979 addr
= XVECEXP (addr
, 0, 0);
2980 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
),
2982 addr
= gen_rtx_CONST (Pmode
, addr
);
2983 addr
= force_const_mem (Pmode
, addr
);
2984 emit_move_insn (temp
, addr
);
2986 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
2989 s390_load_address (reg
, new);
2995 /* Everything else cannot happen. */
3001 gcc_assert (GET_CODE (addr
) == PLUS
);
3003 if (GET_CODE (addr
) == PLUS
)
3005 rtx op0
= XEXP (addr
, 0), op1
= XEXP (addr
, 1);
3007 gcc_assert (!TLS_SYMBOLIC_CONST (op0
));
3008 gcc_assert (!TLS_SYMBOLIC_CONST (op1
));
3010 /* Check first to see if this is a constant offset
3011 from a local symbol reference. */
3012 if ((GET_CODE (op0
) == LABEL_REF
3013 || (GET_CODE (op0
) == SYMBOL_REF
&& SYMBOL_REF_LOCAL_P (op0
)))
3014 && GET_CODE (op1
) == CONST_INT
)
3016 if (TARGET_CPU_ZARCH
&& larl_operand (op0
, VOIDmode
))
3018 if (INTVAL (op1
) & 1)
3020 /* LARL can't handle odd offsets, so emit a
3021 pair of LARL and LA. */
3022 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3024 if (!DISP_IN_RANGE (INTVAL (op1
)))
3026 int even
= INTVAL (op1
) - 1;
3027 op0
= gen_rtx_PLUS (Pmode
, op0
, GEN_INT (even
));
3028 op0
= gen_rtx_CONST (Pmode
, op0
);
3032 emit_move_insn (temp
, op0
);
3033 new = gen_rtx_PLUS (Pmode
, temp
, op1
);
3037 s390_load_address (reg
, new);
3043 /* If the offset is even, we can just use LARL.
3044 This will happen automatically. */
3049 /* Access local symbols relative to the GOT. */
3051 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3053 if (reload_in_progress
|| reload_completed
)
3054 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
3056 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op0
),
3058 addr
= gen_rtx_PLUS (Pmode
, addr
, op1
);
3059 addr
= gen_rtx_CONST (Pmode
, addr
);
3060 addr
= force_const_mem (Pmode
, addr
);
3061 emit_move_insn (temp
, addr
);
3063 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3066 s390_load_address (reg
, new);
3072 /* Now, check whether it is a GOT relative symbol plus offset
3073 that was pulled out of the literal pool. Force it back in. */
3075 else if (GET_CODE (op0
) == UNSPEC
3076 && GET_CODE (op1
) == CONST_INT
3077 && XINT (op0
, 1) == UNSPEC_GOTOFF
)
3079 gcc_assert (XVECLEN (op0
, 0) == 1);
3081 new = force_const_mem (Pmode
, orig
);
3084 /* Otherwise, compute the sum. */
3087 base
= legitimize_pic_address (XEXP (addr
, 0), reg
);
3088 new = legitimize_pic_address (XEXP (addr
, 1),
3089 base
== reg
? NULL_RTX
: reg
);
3090 if (GET_CODE (new) == CONST_INT
)
3091 new = plus_constant (base
, INTVAL (new));
3094 if (GET_CODE (new) == PLUS
&& CONSTANT_P (XEXP (new, 1)))
3096 base
= gen_rtx_PLUS (Pmode
, base
, XEXP (new, 0));
3097 new = XEXP (new, 1);
3099 new = gen_rtx_PLUS (Pmode
, base
, new);
3102 if (GET_CODE (new) == CONST
)
3103 new = XEXP (new, 0);
3104 new = force_operand (new, 0);
3111 /* Load the thread pointer into a register. */
3114 s390_get_thread_pointer (void)
3116 rtx tp
= gen_reg_rtx (Pmode
);
3118 emit_move_insn (tp
, gen_rtx_REG (Pmode
, TP_REGNUM
));
3119 mark_reg_pointer (tp
, BITS_PER_WORD
);
3124 /* Emit a tls call insn. The call target is the SYMBOL_REF stored
3125 in s390_tls_symbol which always refers to __tls_get_offset.
3126 The returned offset is written to RESULT_REG and an USE rtx is
3127 generated for TLS_CALL. */
3129 static GTY(()) rtx s390_tls_symbol
;
3132 s390_emit_tls_call_insn (rtx result_reg
, rtx tls_call
)
3136 gcc_assert (flag_pic
);
3138 if (!s390_tls_symbol
)
3139 s390_tls_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "__tls_get_offset");
3141 insn
= s390_emit_call (s390_tls_symbol
, tls_call
, result_reg
,
3142 gen_rtx_REG (Pmode
, RETURN_REGNUM
));
3144 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), result_reg
);
3145 CONST_OR_PURE_CALL_P (insn
) = 1;
3148 /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
3149 this (thread-local) address. REG may be used as temporary. */
3152 legitimize_tls_address (rtx addr
, rtx reg
)
3154 rtx
new, tls_call
, temp
, base
, r2
, insn
;
3156 if (GET_CODE (addr
) == SYMBOL_REF
)
3157 switch (tls_symbolic_operand (addr
))
3159 case TLS_MODEL_GLOBAL_DYNAMIC
:
3161 r2
= gen_rtx_REG (Pmode
, 2);
3162 tls_call
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_TLSGD
);
3163 new = gen_rtx_CONST (Pmode
, tls_call
);
3164 new = force_const_mem (Pmode
, new);
3165 emit_move_insn (r2
, new);
3166 s390_emit_tls_call_insn (r2
, tls_call
);
3167 insn
= get_insns ();
3170 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_NTPOFF
);
3171 temp
= gen_reg_rtx (Pmode
);
3172 emit_libcall_block (insn
, temp
, r2
, new);
3174 new = gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3177 s390_load_address (reg
, new);
3182 case TLS_MODEL_LOCAL_DYNAMIC
:
3184 r2
= gen_rtx_REG (Pmode
, 2);
3185 tls_call
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, const0_rtx
), UNSPEC_TLSLDM
);
3186 new = gen_rtx_CONST (Pmode
, tls_call
);
3187 new = force_const_mem (Pmode
, new);
3188 emit_move_insn (r2
, new);
3189 s390_emit_tls_call_insn (r2
, tls_call
);
3190 insn
= get_insns ();
3193 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, const0_rtx
), UNSPEC_TLSLDM_NTPOFF
);
3194 temp
= gen_reg_rtx (Pmode
);
3195 emit_libcall_block (insn
, temp
, r2
, new);
3197 new = gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3198 base
= gen_reg_rtx (Pmode
);
3199 s390_load_address (base
, new);
3201 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_DTPOFF
);
3202 new = gen_rtx_CONST (Pmode
, new);
3203 new = force_const_mem (Pmode
, new);
3204 temp
= gen_reg_rtx (Pmode
);
3205 emit_move_insn (temp
, new);
3207 new = gen_rtx_PLUS (Pmode
, base
, temp
);
3210 s390_load_address (reg
, new);
3215 case TLS_MODEL_INITIAL_EXEC
:
3218 /* Assume GOT offset < 4k. This is handled the same way
3219 in both 31- and 64-bit code. */
3221 if (reload_in_progress
|| reload_completed
)
3222 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
3224 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTNTPOFF
);
3225 new = gen_rtx_CONST (Pmode
, new);
3226 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, new);
3227 new = gen_const_mem (Pmode
, new);
3228 temp
= gen_reg_rtx (Pmode
);
3229 emit_move_insn (temp
, new);
3231 else if (TARGET_CPU_ZARCH
)
3233 /* If the GOT offset might be >= 4k, we determine the position
3234 of the GOT entry via a PC-relative LARL. */
3236 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_INDNTPOFF
);
3237 new = gen_rtx_CONST (Pmode
, new);
3238 temp
= gen_reg_rtx (Pmode
);
3239 emit_move_insn (temp
, new);
3241 new = gen_const_mem (Pmode
, temp
);
3242 temp
= gen_reg_rtx (Pmode
);
3243 emit_move_insn (temp
, new);
3247 /* If the GOT offset might be >= 4k, we have to load it
3248 from the literal pool. */
3250 if (reload_in_progress
|| reload_completed
)
3251 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
3253 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTNTPOFF
);
3254 new = gen_rtx_CONST (Pmode
, new);
3255 new = force_const_mem (Pmode
, new);
3256 temp
= gen_reg_rtx (Pmode
);
3257 emit_move_insn (temp
, new);
3259 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3260 new = gen_const_mem (Pmode
, new);
3262 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, new, addr
), UNSPEC_TLS_LOAD
);
3263 temp
= gen_reg_rtx (Pmode
);
3264 emit_insn (gen_rtx_SET (Pmode
, temp
, new));
3268 /* In position-dependent code, load the absolute address of
3269 the GOT entry from the literal pool. */
3271 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_INDNTPOFF
);
3272 new = gen_rtx_CONST (Pmode
, new);
3273 new = force_const_mem (Pmode
, new);
3274 temp
= gen_reg_rtx (Pmode
);
3275 emit_move_insn (temp
, new);
3278 new = gen_const_mem (Pmode
, new);
3279 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, new, addr
), UNSPEC_TLS_LOAD
);
3280 temp
= gen_reg_rtx (Pmode
);
3281 emit_insn (gen_rtx_SET (Pmode
, temp
, new));
3284 new = gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3287 s390_load_address (reg
, new);
3292 case TLS_MODEL_LOCAL_EXEC
:
3293 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_NTPOFF
);
3294 new = gen_rtx_CONST (Pmode
, new);
3295 new = force_const_mem (Pmode
, new);
3296 temp
= gen_reg_rtx (Pmode
);
3297 emit_move_insn (temp
, new);
3299 new = gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3302 s390_load_address (reg
, new);
3311 else if (GET_CODE (addr
) == CONST
&& GET_CODE (XEXP (addr
, 0)) == UNSPEC
)
3313 switch (XINT (XEXP (addr
, 0), 1))
3315 case UNSPEC_INDNTPOFF
:
3316 gcc_assert (TARGET_CPU_ZARCH
);
3325 else if (GET_CODE (addr
) == CONST
&& GET_CODE (XEXP (addr
, 0)) == PLUS
3326 && GET_CODE (XEXP (XEXP (addr
, 0), 1)) == CONST_INT
)
3328 new = XEXP (XEXP (addr
, 0), 0);
3329 if (GET_CODE (new) != SYMBOL_REF
)
3330 new = gen_rtx_CONST (Pmode
, new);
3332 new = legitimize_tls_address (new, reg
);
3333 new = plus_constant (new, INTVAL (XEXP (XEXP (addr
, 0), 1)));
3334 new = force_operand (new, 0);
3338 gcc_unreachable (); /* for now ... */
3343 /* Emit insns to move operands[1] into operands[0]. */
3346 emit_symbolic_move (rtx
*operands
)
3348 rtx temp
= no_new_pseudos
? operands
[0] : gen_reg_rtx (Pmode
);
3350 if (GET_CODE (operands
[0]) == MEM
)
3351 operands
[1] = force_reg (Pmode
, operands
[1]);
3352 else if (TLS_SYMBOLIC_CONST (operands
[1]))
3353 operands
[1] = legitimize_tls_address (operands
[1], temp
);
3355 operands
[1] = legitimize_pic_address (operands
[1], temp
);
3358 /* Try machine-dependent ways of modifying an illegitimate address X
3359 to be legitimate. If we find one, return the new, valid address.
3361 OLDX is the address as it was before break_out_memory_refs was called.
3362 In some cases it is useful to look at this to decide what needs to be done.
3364 MODE is the mode of the operand pointed to by X.
3366 When -fpic is used, special handling is needed for symbolic references.
3367 See comments by legitimize_pic_address for details. */
3370 legitimize_address (rtx x
, rtx oldx ATTRIBUTE_UNUSED
,
3371 enum machine_mode mode ATTRIBUTE_UNUSED
)
3373 rtx constant_term
= const0_rtx
;
3375 if (TLS_SYMBOLIC_CONST (x
))
3377 x
= legitimize_tls_address (x
, 0);
3379 if (legitimate_address_p (mode
, x
, FALSE
))
3382 else if (GET_CODE (x
) == PLUS
3383 && (TLS_SYMBOLIC_CONST (XEXP (x
, 0))
3384 || TLS_SYMBOLIC_CONST (XEXP (x
, 1))))
3390 if (SYMBOLIC_CONST (x
)
3391 || (GET_CODE (x
) == PLUS
3392 && (SYMBOLIC_CONST (XEXP (x
, 0))
3393 || SYMBOLIC_CONST (XEXP (x
, 1)))))
3394 x
= legitimize_pic_address (x
, 0);
3396 if (legitimate_address_p (mode
, x
, FALSE
))
3400 x
= eliminate_constant_term (x
, &constant_term
);
3402 /* Optimize loading of large displacements by splitting them
3403 into the multiple of 4K and the rest; this allows the
3404 former to be CSE'd if possible.
3406 Don't do this if the displacement is added to a register
3407 pointing into the stack frame, as the offsets will
3408 change later anyway. */
3410 if (GET_CODE (constant_term
) == CONST_INT
3411 && !TARGET_LONG_DISPLACEMENT
3412 && !DISP_IN_RANGE (INTVAL (constant_term
))
3413 && !(REG_P (x
) && REGNO_PTR_FRAME_P (REGNO (x
))))
3415 HOST_WIDE_INT lower
= INTVAL (constant_term
) & 0xfff;
3416 HOST_WIDE_INT upper
= INTVAL (constant_term
) ^ lower
;
3418 rtx temp
= gen_reg_rtx (Pmode
);
3419 rtx val
= force_operand (GEN_INT (upper
), temp
);
3421 emit_move_insn (temp
, val
);
3423 x
= gen_rtx_PLUS (Pmode
, x
, temp
);
3424 constant_term
= GEN_INT (lower
);
3427 if (GET_CODE (x
) == PLUS
)
3429 if (GET_CODE (XEXP (x
, 0)) == REG
)
3431 rtx temp
= gen_reg_rtx (Pmode
);
3432 rtx val
= force_operand (XEXP (x
, 1), temp
);
3434 emit_move_insn (temp
, val
);
3436 x
= gen_rtx_PLUS (Pmode
, XEXP (x
, 0), temp
);
3439 else if (GET_CODE (XEXP (x
, 1)) == REG
)
3441 rtx temp
= gen_reg_rtx (Pmode
);
3442 rtx val
= force_operand (XEXP (x
, 0), temp
);
3444 emit_move_insn (temp
, val
);
3446 x
= gen_rtx_PLUS (Pmode
, temp
, XEXP (x
, 1));
3450 if (constant_term
!= const0_rtx
)
3451 x
= gen_rtx_PLUS (Pmode
, x
, constant_term
);
3456 /* Try a machine-dependent way of reloading an illegitimate address AD
3457 operand. If we find one, push the reload and and return the new address.
3459 MODE is the mode of the enclosing MEM. OPNUM is the operand number
3460 and TYPE is the reload type of the current reload. */
3463 legitimize_reload_address (rtx ad
, enum machine_mode mode ATTRIBUTE_UNUSED
,
3464 int opnum
, int type
)
3466 if (!optimize
|| TARGET_LONG_DISPLACEMENT
)
3469 if (GET_CODE (ad
) == PLUS
)
3471 rtx tem
= simplify_binary_operation (PLUS
, Pmode
,
3472 XEXP (ad
, 0), XEXP (ad
, 1));
3477 if (GET_CODE (ad
) == PLUS
3478 && GET_CODE (XEXP (ad
, 0)) == REG
3479 && GET_CODE (XEXP (ad
, 1)) == CONST_INT
3480 && !DISP_IN_RANGE (INTVAL (XEXP (ad
, 1))))
3482 HOST_WIDE_INT lower
= INTVAL (XEXP (ad
, 1)) & 0xfff;
3483 HOST_WIDE_INT upper
= INTVAL (XEXP (ad
, 1)) ^ lower
;
3486 cst
= GEN_INT (upper
);
3487 if (!legitimate_reload_constant_p (cst
))
3488 cst
= force_const_mem (Pmode
, cst
);
3490 tem
= gen_rtx_PLUS (Pmode
, XEXP (ad
, 0), cst
);
3491 new = gen_rtx_PLUS (Pmode
, tem
, GEN_INT (lower
));
3493 push_reload (XEXP (tem
, 1), 0, &XEXP (tem
, 1), 0,
3494 BASE_REG_CLASS
, Pmode
, VOIDmode
, 0, 0,
3495 opnum
, (enum reload_type
) type
);
3502 /* Emit code to move LEN bytes from DST to SRC. */
3505 s390_expand_movmem (rtx dst
, rtx src
, rtx len
)
3507 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) >= 0 && INTVAL (len
) <= 256)
3509 if (INTVAL (len
) > 0)
3510 emit_insn (gen_movmem_short (dst
, src
, GEN_INT (INTVAL (len
) - 1)));
3513 else if (TARGET_MVCLE
)
3515 emit_insn (gen_movmem_long (dst
, src
, convert_to_mode (Pmode
, len
, 1)));
3520 rtx dst_addr
, src_addr
, count
, blocks
, temp
;
3521 rtx loop_start_label
= gen_label_rtx ();
3522 rtx loop_end_label
= gen_label_rtx ();
3523 rtx end_label
= gen_label_rtx ();
3524 enum machine_mode mode
;
3526 mode
= GET_MODE (len
);
3527 if (mode
== VOIDmode
)
3530 dst_addr
= gen_reg_rtx (Pmode
);
3531 src_addr
= gen_reg_rtx (Pmode
);
3532 count
= gen_reg_rtx (mode
);
3533 blocks
= gen_reg_rtx (mode
);
3535 convert_move (count
, len
, 1);
3536 emit_cmp_and_jump_insns (count
, const0_rtx
,
3537 EQ
, NULL_RTX
, mode
, 1, end_label
);
3539 emit_move_insn (dst_addr
, force_operand (XEXP (dst
, 0), NULL_RTX
));
3540 emit_move_insn (src_addr
, force_operand (XEXP (src
, 0), NULL_RTX
));
3541 dst
= change_address (dst
, VOIDmode
, dst_addr
);
3542 src
= change_address (src
, VOIDmode
, src_addr
);
3544 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1, 0);
3546 emit_move_insn (count
, temp
);
3548 temp
= expand_binop (mode
, ashr_optab
, count
, GEN_INT (8), blocks
, 1, 0);
3550 emit_move_insn (blocks
, temp
);
3552 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3553 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3555 emit_label (loop_start_label
);
3557 emit_insn (gen_movmem_short (dst
, src
, GEN_INT (255)));
3558 s390_load_address (dst_addr
,
3559 gen_rtx_PLUS (Pmode
, dst_addr
, GEN_INT (256)));
3560 s390_load_address (src_addr
,
3561 gen_rtx_PLUS (Pmode
, src_addr
, GEN_INT (256)));
3563 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1, 0);
3565 emit_move_insn (blocks
, temp
);
3567 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3568 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3570 emit_jump (loop_start_label
);
3571 emit_label (loop_end_label
);
3573 emit_insn (gen_movmem_short (dst
, src
,
3574 convert_to_mode (Pmode
, count
, 1)));
3575 emit_label (end_label
);
3579 /* Emit code to set LEN bytes at DST to VAL.
3580 Make use of clrmem if VAL is zero. */
3583 s390_expand_setmem (rtx dst
, rtx len
, rtx val
)
3585 gcc_assert (GET_CODE (len
) != CONST_INT
|| INTVAL (len
) > 0);
3586 gcc_assert (GET_CODE (val
) == CONST_INT
|| GET_MODE (val
) == QImode
);
3588 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) <= 257)
3590 if (val
== const0_rtx
&& INTVAL (len
) <= 256)
3591 emit_insn (gen_clrmem_short (dst
, GEN_INT (INTVAL (len
) - 1)));
3594 /* Initialize memory by storing the first byte. */
3595 emit_move_insn (adjust_address (dst
, QImode
, 0), val
);
3597 if (INTVAL (len
) > 1)
3599 /* Initiate 1 byte overlap move.
3600 The first byte of DST is propagated through DSTP1.
3601 Prepare a movmem for: DST+1 = DST (length = LEN - 1).
3602 DST is set to size 1 so the rest of the memory location
3603 does not count as source operand. */
3604 rtx dstp1
= adjust_address (dst
, VOIDmode
, 1);
3605 set_mem_size (dst
, const1_rtx
);
3607 emit_insn (gen_movmem_short (dstp1
, dst
,
3608 GEN_INT (INTVAL (len
) - 2)));
3613 else if (TARGET_MVCLE
)
3615 val
= force_not_mem (convert_modes (Pmode
, QImode
, val
, 1));
3616 emit_insn (gen_setmem_long (dst
, convert_to_mode (Pmode
, len
, 1), val
));
3621 rtx dst_addr
, src_addr
, count
, blocks
, temp
, dstp1
= NULL_RTX
;
3622 rtx loop_start_label
= gen_label_rtx ();
3623 rtx loop_end_label
= gen_label_rtx ();
3624 rtx end_label
= gen_label_rtx ();
3625 enum machine_mode mode
;
3627 mode
= GET_MODE (len
);
3628 if (mode
== VOIDmode
)
3631 dst_addr
= gen_reg_rtx (Pmode
);
3632 src_addr
= gen_reg_rtx (Pmode
);
3633 count
= gen_reg_rtx (mode
);
3634 blocks
= gen_reg_rtx (mode
);
3636 convert_move (count
, len
, 1);
3637 emit_cmp_and_jump_insns (count
, const0_rtx
,
3638 EQ
, NULL_RTX
, mode
, 1, end_label
);
3640 emit_move_insn (dst_addr
, force_operand (XEXP (dst
, 0), NULL_RTX
));
3641 dst
= change_address (dst
, VOIDmode
, dst_addr
);
3643 if (val
== const0_rtx
)
3644 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1, 0);
3647 dstp1
= adjust_address (dst
, VOIDmode
, 1);
3648 set_mem_size (dst
, const1_rtx
);
3650 /* Initialize memory by storing the first byte. */
3651 emit_move_insn (adjust_address (dst
, QImode
, 0), val
);
3653 /* If count is 1 we are done. */
3654 emit_cmp_and_jump_insns (count
, const1_rtx
,
3655 EQ
, NULL_RTX
, mode
, 1, end_label
);
3657 temp
= expand_binop (mode
, add_optab
, count
, GEN_INT (-2), count
, 1, 0);
3660 emit_move_insn (count
, temp
);
3662 temp
= expand_binop (mode
, ashr_optab
, count
, GEN_INT (8), blocks
, 1, 0);
3664 emit_move_insn (blocks
, temp
);
3666 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3667 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3669 emit_label (loop_start_label
);
3671 if (val
== const0_rtx
)
3672 emit_insn (gen_clrmem_short (dst
, GEN_INT (255)));
3674 emit_insn (gen_movmem_short (dstp1
, dst
, GEN_INT (255)));
3675 s390_load_address (dst_addr
,
3676 gen_rtx_PLUS (Pmode
, dst_addr
, GEN_INT (256)));
3678 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1, 0);
3680 emit_move_insn (blocks
, temp
);
3682 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3683 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3685 emit_jump (loop_start_label
);
3686 emit_label (loop_end_label
);
3688 if (val
== const0_rtx
)
3689 emit_insn (gen_clrmem_short (dst
, convert_to_mode (Pmode
, count
, 1)));
3691 emit_insn (gen_movmem_short (dstp1
, dst
, convert_to_mode (Pmode
, count
, 1)));
3692 emit_label (end_label
);
3696 /* Emit code to compare LEN bytes at OP0 with those at OP1,
3697 and return the result in TARGET. */
3700 s390_expand_cmpmem (rtx target
, rtx op0
, rtx op1
, rtx len
)
3702 rtx ccreg
= gen_rtx_REG (CCUmode
, CC_REGNUM
);
3705 /* As the result of CMPINT is inverted compared to what we need,
3706 we have to swap the operands. */
3707 tmp
= op0
; op0
= op1
; op1
= tmp
;
3709 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) >= 0 && INTVAL (len
) <= 256)
3711 if (INTVAL (len
) > 0)
3713 emit_insn (gen_cmpmem_short (op0
, op1
, GEN_INT (INTVAL (len
) - 1)));
3714 emit_insn (gen_cmpint (target
, ccreg
));
3717 emit_move_insn (target
, const0_rtx
);
3719 else if (TARGET_MVCLE
)
3721 emit_insn (gen_cmpmem_long (op0
, op1
, convert_to_mode (Pmode
, len
, 1)));
3722 emit_insn (gen_cmpint (target
, ccreg
));
3726 rtx addr0
, addr1
, count
, blocks
, temp
;
3727 rtx loop_start_label
= gen_label_rtx ();
3728 rtx loop_end_label
= gen_label_rtx ();
3729 rtx end_label
= gen_label_rtx ();
3730 enum machine_mode mode
;
3732 mode
= GET_MODE (len
);
3733 if (mode
== VOIDmode
)
3736 addr0
= gen_reg_rtx (Pmode
);
3737 addr1
= gen_reg_rtx (Pmode
);
3738 count
= gen_reg_rtx (mode
);
3739 blocks
= gen_reg_rtx (mode
);
3741 convert_move (count
, len
, 1);
3742 emit_cmp_and_jump_insns (count
, const0_rtx
,
3743 EQ
, NULL_RTX
, mode
, 1, end_label
);
3745 emit_move_insn (addr0
, force_operand (XEXP (op0
, 0), NULL_RTX
));
3746 emit_move_insn (addr1
, force_operand (XEXP (op1
, 0), NULL_RTX
));
3747 op0
= change_address (op0
, VOIDmode
, addr0
);
3748 op1
= change_address (op1
, VOIDmode
, addr1
);
3750 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1, 0);
3752 emit_move_insn (count
, temp
);
3754 temp
= expand_binop (mode
, ashr_optab
, count
, GEN_INT (8), blocks
, 1, 0);
3756 emit_move_insn (blocks
, temp
);
3758 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3759 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3761 emit_label (loop_start_label
);
3763 emit_insn (gen_cmpmem_short (op0
, op1
, GEN_INT (255)));
3764 temp
= gen_rtx_NE (VOIDmode
, ccreg
, const0_rtx
);
3765 temp
= gen_rtx_IF_THEN_ELSE (VOIDmode
, temp
,
3766 gen_rtx_LABEL_REF (VOIDmode
, end_label
), pc_rtx
);
3767 temp
= gen_rtx_SET (VOIDmode
, pc_rtx
, temp
);
3768 emit_jump_insn (temp
);
3770 s390_load_address (addr0
,
3771 gen_rtx_PLUS (Pmode
, addr0
, GEN_INT (256)));
3772 s390_load_address (addr1
,
3773 gen_rtx_PLUS (Pmode
, addr1
, GEN_INT (256)));
3775 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1, 0);
3777 emit_move_insn (blocks
, temp
);
3779 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3780 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3782 emit_jump (loop_start_label
);
3783 emit_label (loop_end_label
);
3785 emit_insn (gen_cmpmem_short (op0
, op1
,
3786 convert_to_mode (Pmode
, count
, 1)));
3787 emit_label (end_label
);
3789 emit_insn (gen_cmpint (target
, ccreg
));
3794 /* Expand conditional increment or decrement using alc/slb instructions.
3795 Should generate code setting DST to either SRC or SRC + INCREMENT,
3796 depending on the result of the comparison CMP_OP0 CMP_CODE CMP_OP1.
3797 Returns true if successful, false otherwise.
3799 That makes it possible to implement some if-constructs without jumps e.g.:
3800 (borrow = CC0 | CC1 and carry = CC2 | CC3)
3801 unsigned int a, b, c;
3802 if (a < b) c++; -> CCU b > a -> CC2; c += carry;
3803 if (a < b) c--; -> CCL3 a - b -> borrow; c -= borrow;
3804 if (a <= b) c++; -> CCL3 b - a -> borrow; c += carry;
3805 if (a <= b) c--; -> CCU a <= b -> borrow; c -= borrow;
3807 Checks for EQ and NE with a nonzero value need an additional xor e.g.:
3808 if (a == b) c++; -> CCL3 a ^= b; 0 - a -> borrow; c += carry;
3809 if (a == b) c--; -> CCU a ^= b; a <= 0 -> CC0 | CC1; c -= borrow;
3810 if (a != b) c++; -> CCU a ^= b; a > 0 -> CC2; c += carry;
3811 if (a != b) c--; -> CCL3 a ^= b; 0 - a -> borrow; c -= borrow; */
3814 s390_expand_addcc (enum rtx_code cmp_code
, rtx cmp_op0
, rtx cmp_op1
,
3815 rtx dst
, rtx src
, rtx increment
)
3817 enum machine_mode cmp_mode
;
3818 enum machine_mode cc_mode
;
3824 if ((GET_MODE (cmp_op0
) == SImode
|| GET_MODE (cmp_op0
) == VOIDmode
)
3825 && (GET_MODE (cmp_op1
) == SImode
|| GET_MODE (cmp_op1
) == VOIDmode
))
3827 else if ((GET_MODE (cmp_op0
) == DImode
|| GET_MODE (cmp_op0
) == VOIDmode
)
3828 && (GET_MODE (cmp_op1
) == DImode
|| GET_MODE (cmp_op1
) == VOIDmode
))
3833 /* Try ADD LOGICAL WITH CARRY. */
3834 if (increment
== const1_rtx
)
3836 /* Determine CC mode to use. */
3837 if (cmp_code
== EQ
|| cmp_code
== NE
)
3839 if (cmp_op1
!= const0_rtx
)
3841 cmp_op0
= expand_simple_binop (cmp_mode
, XOR
, cmp_op0
, cmp_op1
,
3842 NULL_RTX
, 0, OPTAB_WIDEN
);
3843 cmp_op1
= const0_rtx
;
3846 cmp_code
= cmp_code
== EQ
? LEU
: GTU
;
3849 if (cmp_code
== LTU
|| cmp_code
== LEU
)
3854 cmp_code
= swap_condition (cmp_code
);
3871 /* Emit comparison instruction pattern. */
3872 if (!register_operand (cmp_op0
, cmp_mode
))
3873 cmp_op0
= force_reg (cmp_mode
, cmp_op0
);
3875 insn
= gen_rtx_SET (VOIDmode
, gen_rtx_REG (cc_mode
, CC_REGNUM
),
3876 gen_rtx_COMPARE (cc_mode
, cmp_op0
, cmp_op1
));
3877 /* We use insn_invalid_p here to add clobbers if required. */
3878 ret
= insn_invalid_p (emit_insn (insn
));
3881 /* Emit ALC instruction pattern. */
3882 op_res
= gen_rtx_fmt_ee (cmp_code
, GET_MODE (dst
),
3883 gen_rtx_REG (cc_mode
, CC_REGNUM
),
3886 if (src
!= const0_rtx
)
3888 if (!register_operand (src
, GET_MODE (dst
)))
3889 src
= force_reg (GET_MODE (dst
), src
);
3891 src
= gen_rtx_PLUS (GET_MODE (dst
), src
, const0_rtx
);
3892 op_res
= gen_rtx_PLUS (GET_MODE (dst
), src
, op_res
);
3895 p
= rtvec_alloc (2);
3897 gen_rtx_SET (VOIDmode
, dst
, op_res
);
3899 gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
3900 emit_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
3905 /* Try SUBTRACT LOGICAL WITH BORROW. */
3906 if (increment
== constm1_rtx
)
3908 /* Determine CC mode to use. */
3909 if (cmp_code
== EQ
|| cmp_code
== NE
)
3911 if (cmp_op1
!= const0_rtx
)
3913 cmp_op0
= expand_simple_binop (cmp_mode
, XOR
, cmp_op0
, cmp_op1
,
3914 NULL_RTX
, 0, OPTAB_WIDEN
);
3915 cmp_op1
= const0_rtx
;
3918 cmp_code
= cmp_code
== EQ
? LEU
: GTU
;
3921 if (cmp_code
== GTU
|| cmp_code
== GEU
)
3926 cmp_code
= swap_condition (cmp_code
);
3943 /* Emit comparison instruction pattern. */
3944 if (!register_operand (cmp_op0
, cmp_mode
))
3945 cmp_op0
= force_reg (cmp_mode
, cmp_op0
);
3947 insn
= gen_rtx_SET (VOIDmode
, gen_rtx_REG (cc_mode
, CC_REGNUM
),
3948 gen_rtx_COMPARE (cc_mode
, cmp_op0
, cmp_op1
));
3949 /* We use insn_invalid_p here to add clobbers if required. */
3950 ret
= insn_invalid_p (emit_insn (insn
));
3953 /* Emit SLB instruction pattern. */
3954 if (!register_operand (src
, GET_MODE (dst
)))
3955 src
= force_reg (GET_MODE (dst
), src
);
3957 op_res
= gen_rtx_MINUS (GET_MODE (dst
),
3958 gen_rtx_MINUS (GET_MODE (dst
), src
, const0_rtx
),
3959 gen_rtx_fmt_ee (cmp_code
, GET_MODE (dst
),
3960 gen_rtx_REG (cc_mode
, CC_REGNUM
),
3962 p
= rtvec_alloc (2);
3964 gen_rtx_SET (VOIDmode
, dst
, op_res
);
3966 gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
3967 emit_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
3975 /* Expand code for the insv template. Return true if successful, false else. */
3978 s390_expand_insv (rtx dest
, rtx op1
, rtx op2
, rtx src
)
3980 int bitsize
= INTVAL (op1
);
3981 int bitpos
= INTVAL (op2
);
3983 /* We need byte alignment. */
3984 if (bitsize
% BITS_PER_UNIT
)
3988 && memory_operand (dest
, VOIDmode
)
3989 && (register_operand (src
, word_mode
)
3990 || const_int_operand (src
, VOIDmode
)))
3992 /* Emit standard pattern if possible. */
3993 enum machine_mode mode
= smallest_mode_for_size (bitsize
, MODE_INT
);
3994 if (GET_MODE_BITSIZE (mode
) == bitsize
)
3995 emit_move_insn (adjust_address (dest
, mode
, 0), gen_lowpart (mode
, src
));
3997 /* (set (ze (mem)) (const_int)). */
3998 else if (const_int_operand (src
, VOIDmode
))
4000 int size
= bitsize
/ BITS_PER_UNIT
;
4001 rtx src_mem
= adjust_address (force_const_mem (word_mode
, src
), BLKmode
,
4002 GET_MODE_SIZE (word_mode
) - size
);
4004 dest
= adjust_address (dest
, BLKmode
, 0);
4005 set_mem_size (dest
, GEN_INT (size
));
4006 s390_expand_movmem (dest
, src_mem
, GEN_INT (size
));
4009 /* (set (ze (mem)) (reg)). */
4010 else if (register_operand (src
, word_mode
))
4012 if (bitsize
<= GET_MODE_BITSIZE (SImode
))
4013 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
, op1
,
4017 /* Emit st,stcmh sequence. */
4018 int stcmh_width
= bitsize
- GET_MODE_BITSIZE (SImode
);
4019 int size
= stcmh_width
/ BITS_PER_UNIT
;
4021 emit_move_insn (adjust_address (dest
, SImode
, size
),
4022 gen_lowpart (SImode
, src
));
4023 set_mem_size (dest
, GEN_INT (size
));
4024 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
, GEN_INT
4025 (stcmh_width
), const0_rtx
),
4026 gen_rtx_LSHIFTRT (word_mode
, src
, GEN_INT
4027 (GET_MODE_BITSIZE (SImode
))));
4036 /* (set (ze (reg)) (const_int)). */
4038 && register_operand (dest
, word_mode
)
4039 && (bitpos
% 16) == 0
4040 && (bitsize
% 16) == 0
4041 && const_int_operand (src
, VOIDmode
))
4043 HOST_WIDE_INT val
= INTVAL (src
);
4044 int regpos
= bitpos
+ bitsize
;
4046 while (regpos
> bitpos
)
4048 enum machine_mode putmode
;
4051 if (TARGET_EXTIMM
&& (regpos
% 32 == 0) && (regpos
>= bitpos
+ 32))
4056 putsize
= GET_MODE_BITSIZE (putmode
);
4058 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
,
4061 gen_int_mode (val
, putmode
));
4064 gcc_assert (regpos
== bitpos
);
4071 /* A subroutine of s390_expand_cs_hqi and s390_expand_atomic which returns a
4072 register that holds VAL of mode MODE shifted by COUNT bits. */
4075 s390_expand_mask_and_shift (rtx val
, enum machine_mode mode
, rtx count
)
4077 val
= expand_simple_binop (SImode
, AND
, val
, GEN_INT (GET_MODE_MASK (mode
)),
4078 NULL_RTX
, 1, OPTAB_DIRECT
);
4079 return expand_simple_binop (SImode
, ASHIFT
, val
, count
,
4080 NULL_RTX
, 1, OPTAB_DIRECT
);
4083 /* Structure to hold the initial parameters for a compare_and_swap operation
4084 in HImode and QImode. */
4086 struct alignment_context
4088 rtx memsi
; /* SI aligned memory location. */
4089 rtx shift
; /* Bit offset with regard to lsb. */
4090 rtx modemask
; /* Mask of the HQImode shifted by SHIFT bits. */
4091 rtx modemaski
; /* ~modemask */
4092 bool aligned
; /* True if memory is aligned, false else. */
4095 /* A subroutine of s390_expand_cs_hqi and s390_expand_atomic to initialize
4096 structure AC for transparent simplifying, if the memory alignment is known
4097 to be at least 32bit. MEM is the memory location for the actual operation
4098 and MODE its mode. */
4101 init_alignment_context (struct alignment_context
*ac
, rtx mem
,
4102 enum machine_mode mode
)
4104 ac
->shift
= GEN_INT (GET_MODE_SIZE (SImode
) - GET_MODE_SIZE (mode
));
4105 ac
->aligned
= (MEM_ALIGN (mem
) >= GET_MODE_BITSIZE (SImode
));
4108 ac
->memsi
= adjust_address (mem
, SImode
, 0); /* Memory is aligned. */
4111 /* Alignment is unknown. */
4112 rtx byteoffset
, addr
, align
;
4114 /* Force the address into a register. */
4115 addr
= force_reg (Pmode
, XEXP (mem
, 0));
4117 /* Align it to SImode. */
4118 align
= expand_simple_binop (Pmode
, AND
, addr
,
4119 GEN_INT (-GET_MODE_SIZE (SImode
)),
4120 NULL_RTX
, 1, OPTAB_DIRECT
);
4122 ac
->memsi
= gen_rtx_MEM (SImode
, align
);
4123 MEM_VOLATILE_P (ac
->memsi
) = MEM_VOLATILE_P (mem
);
4124 set_mem_alias_set (ac
->memsi
, ALIAS_SET_MEMORY_BARRIER
);
4125 set_mem_align (ac
->memsi
, GET_MODE_BITSIZE (SImode
));
4127 /* Calculate shiftcount. */
4128 byteoffset
= expand_simple_binop (Pmode
, AND
, addr
,
4129 GEN_INT (GET_MODE_SIZE (SImode
) - 1),
4130 NULL_RTX
, 1, OPTAB_DIRECT
);
4131 /* As we already have some offset, evaluate the remaining distance. */
4132 ac
->shift
= expand_simple_binop (SImode
, MINUS
, ac
->shift
, byteoffset
,
4133 NULL_RTX
, 1, OPTAB_DIRECT
);
4136 /* Shift is the byte count, but we need the bitcount. */
4137 ac
->shift
= expand_simple_binop (SImode
, MULT
, ac
->shift
, GEN_INT (BITS_PER_UNIT
),
4138 NULL_RTX
, 1, OPTAB_DIRECT
);
4139 /* Calculate masks. */
4140 ac
->modemask
= expand_simple_binop (SImode
, ASHIFT
,
4141 GEN_INT (GET_MODE_MASK (mode
)), ac
->shift
,
4142 NULL_RTX
, 1, OPTAB_DIRECT
);
4143 ac
->modemaski
= expand_simple_unop (SImode
, NOT
, ac
->modemask
, NULL_RTX
, 1);
4146 /* Expand an atomic compare and swap operation for HImode and QImode. MEM is
4147 the memory location, CMP the old value to compare MEM with and NEW the value
4148 to set if CMP == MEM.
4149 CMP is never in memory for compare_and_swap_cc because
4150 expand_bool_compare_and_swap puts it into a register for later compare. */
4153 s390_expand_cs_hqi (enum machine_mode mode
, rtx target
, rtx mem
, rtx cmp
, rtx
new)
4155 struct alignment_context ac
;
4156 rtx cmpv
, newv
, val
, resv
, cc
;
4157 rtx res
= gen_reg_rtx (SImode
);
4158 rtx csloop
= gen_label_rtx ();
4159 rtx csend
= gen_label_rtx ();
4161 gcc_assert (register_operand (target
, VOIDmode
));
4162 gcc_assert (MEM_P (mem
));
4164 init_alignment_context (&ac
, mem
, mode
);
4166 /* Shift the values to the correct bit positions. */
4167 if (!(ac
.aligned
&& MEM_P (cmp
)))
4168 cmp
= s390_expand_mask_and_shift (cmp
, mode
, ac
.shift
);
4169 if (!(ac
.aligned
&& MEM_P (new)))
4170 new = s390_expand_mask_and_shift (new, mode
, ac
.shift
);
4172 /* Load full word. Subsequent loads are performed by CS. */
4173 val
= expand_simple_binop (SImode
, AND
, ac
.memsi
, ac
.modemaski
,
4174 NULL_RTX
, 1, OPTAB_DIRECT
);
4176 /* Start CS loop. */
4177 emit_label (csloop
);
4178 /* val = "<mem>00..0<mem>"
4179 * cmp = "00..0<cmp>00..0"
4180 * new = "00..0<new>00..0"
4183 /* Patch cmp and new with val at correct position. */
4184 if (ac
.aligned
&& MEM_P (cmp
))
4186 cmpv
= force_reg (SImode
, val
);
4187 store_bit_field (cmpv
, GET_MODE_BITSIZE (mode
), 0, SImode
, cmp
);
4190 cmpv
= force_reg (SImode
, expand_simple_binop (SImode
, IOR
, cmp
, val
,
4191 NULL_RTX
, 1, OPTAB_DIRECT
));
4192 if (ac
.aligned
&& MEM_P (new))
4194 newv
= force_reg (SImode
, val
);
4195 store_bit_field (newv
, GET_MODE_BITSIZE (mode
), 0, SImode
, new);
4198 newv
= force_reg (SImode
, expand_simple_binop (SImode
, IOR
, new, val
,
4199 NULL_RTX
, 1, OPTAB_DIRECT
));
4201 /* Emit compare_and_swap pattern. */
4202 emit_insn (gen_sync_compare_and_swap_ccsi (res
, ac
.memsi
, cmpv
, newv
));
4204 /* Jump to end if we're done (likely?). */
4205 s390_emit_jump (csend
, s390_emit_compare (EQ
, cmpv
, ac
.memsi
));
4207 /* Check for changes outside mode. */
4208 resv
= expand_simple_binop (SImode
, AND
, res
, ac
.modemaski
,
4209 NULL_RTX
, 1, OPTAB_DIRECT
);
4210 cc
= s390_emit_compare (NE
, resv
, val
);
4211 emit_move_insn (val
, resv
);
4212 /* Loop internal if so. */
4213 s390_emit_jump (csloop
, cc
);
4217 /* Return the correct part of the bitfield. */
4218 convert_move (target
, expand_simple_binop (SImode
, LSHIFTRT
, res
, ac
.shift
,
4219 NULL_RTX
, 1, OPTAB_DIRECT
), 1);
4222 /* Expand an atomic operation CODE of mode MODE. MEM is the memory location
4223 and VAL the value to play with. If AFTER is true then store the the value
4224 MEM holds after the operation, if AFTER is false then store the value MEM
4225 holds before the operation. If TARGET is zero then discard that value, else
4226 store it to TARGET. */
4229 s390_expand_atomic (enum machine_mode mode
, enum rtx_code code
,
4230 rtx target
, rtx mem
, rtx val
, bool after
)
4232 struct alignment_context ac
;
4234 rtx
new = gen_reg_rtx (SImode
);
4235 rtx orig
= gen_reg_rtx (SImode
);
4236 rtx csloop
= gen_label_rtx ();
4238 gcc_assert (!target
|| register_operand (target
, VOIDmode
));
4239 gcc_assert (MEM_P (mem
));
4241 init_alignment_context (&ac
, mem
, mode
);
4243 /* Shift val to the correct bit positions.
4244 Preserve "icm", but prevent "ex icm". */
4245 if (!(ac
.aligned
&& code
== SET
&& MEM_P (val
)))
4246 val
= s390_expand_mask_and_shift (val
, mode
, ac
.shift
);
4248 /* Further preparation insns. */
4249 if (code
== PLUS
|| code
== MINUS
)
4250 emit_move_insn (orig
, val
);
4251 else if (code
== MULT
|| code
== AND
) /* val = "11..1<val>11..1" */
4252 val
= expand_simple_binop (SImode
, XOR
, val
, ac
.modemaski
,
4253 NULL_RTX
, 1, OPTAB_DIRECT
);
4255 /* Load full word. Subsequent loads are performed by CS. */
4256 cmp
= force_reg (SImode
, ac
.memsi
);
4258 /* Start CS loop. */
4259 emit_label (csloop
);
4260 emit_move_insn (new, cmp
);
4262 /* Patch new with val at correct position. */
4267 val
= expand_simple_binop (SImode
, code
, new, orig
,
4268 NULL_RTX
, 1, OPTAB_DIRECT
);
4269 val
= expand_simple_binop (SImode
, AND
, val
, ac
.modemask
,
4270 NULL_RTX
, 1, OPTAB_DIRECT
);
4273 if (ac
.aligned
&& MEM_P (val
))
4274 store_bit_field (new, GET_MODE_BITSIZE (mode
), 0, SImode
, val
);
4277 new = expand_simple_binop (SImode
, AND
, new, ac
.modemaski
,
4278 NULL_RTX
, 1, OPTAB_DIRECT
);
4279 new = expand_simple_binop (SImode
, IOR
, new, val
,
4280 NULL_RTX
, 1, OPTAB_DIRECT
);
4286 new = expand_simple_binop (SImode
, code
, new, val
,
4287 NULL_RTX
, 1, OPTAB_DIRECT
);
4289 case MULT
: /* NAND */
4290 new = expand_simple_binop (SImode
, XOR
, new, ac
.modemask
,
4291 NULL_RTX
, 1, OPTAB_DIRECT
);
4292 new = expand_simple_binop (SImode
, AND
, new, val
,
4293 NULL_RTX
, 1, OPTAB_DIRECT
);
4298 /* Emit compare_and_swap pattern. */
4299 emit_insn (gen_sync_compare_and_swap_ccsi (cmp
, ac
.memsi
, cmp
, new));
4301 /* Loop until swapped (unlikely?). */
4302 s390_emit_jump (csloop
, gen_rtx_fmt_ee (NE
, CCZ1mode
,
4303 gen_rtx_REG (CCZ1mode
, CC_REGNUM
),
4306 /* Return the correct part of the bitfield. */
4308 convert_move (target
, expand_simple_binop (SImode
, LSHIFTRT
,
4309 after
? new : cmp
, ac
.shift
,
4310 NULL_RTX
, 1, OPTAB_DIRECT
), 1);
4313 /* This is called from dwarf2out.c via TARGET_ASM_OUTPUT_DWARF_DTPREL.
4314 We need to emit DTP-relative relocations. */
4316 static void s390_output_dwarf_dtprel (FILE *, int, rtx
) ATTRIBUTE_UNUSED
;
4319 s390_output_dwarf_dtprel (FILE *file
, int size
, rtx x
)
4324 fputs ("\t.long\t", file
);
4327 fputs ("\t.quad\t", file
);
4332 output_addr_const (file
, x
);
4333 fputs ("@DTPOFF", file
);
4336 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
4337 /* Implement TARGET_MANGLE_FUNDAMENTAL_TYPE. */
4340 s390_mangle_fundamental_type (tree type
)
4342 if (TYPE_MAIN_VARIANT (type
) == long_double_type_node
4343 && TARGET_LONG_DOUBLE_128
)
4346 /* For all other types, use normal C++ mangling. */
4351 /* In the name of slightly smaller debug output, and to cater to
4352 general assembler lossage, recognize various UNSPEC sequences
4353 and turn them back into a direct symbol reference. */
4356 s390_delegitimize_address (rtx orig_x
)
4360 if (GET_CODE (x
) != MEM
)
4364 if (GET_CODE (x
) == PLUS
4365 && GET_CODE (XEXP (x
, 1)) == CONST
4366 && GET_CODE (XEXP (x
, 0)) == REG
4367 && REGNO (XEXP (x
, 0)) == PIC_OFFSET_TABLE_REGNUM
)
4369 y
= XEXP (XEXP (x
, 1), 0);
4370 if (GET_CODE (y
) == UNSPEC
4371 && XINT (y
, 1) == UNSPEC_GOT
)
4372 return XVECEXP (y
, 0, 0);
4376 if (GET_CODE (x
) == CONST
)
4379 if (GET_CODE (y
) == UNSPEC
4380 && XINT (y
, 1) == UNSPEC_GOTENT
)
4381 return XVECEXP (y
, 0, 0);
4388 /* Output operand OP to stdio stream FILE.
4389 OP is an address (register + offset) which is not used to address data;
4390 instead the rightmost bits are interpreted as the value. */
4393 print_shift_count_operand (FILE *file
, rtx op
)
4395 HOST_WIDE_INT offset
;
4398 /* Extract base register and offset. */
4399 if (!s390_decompose_shift_count (op
, &base
, &offset
))
4405 gcc_assert (GET_CODE (base
) == REG
);
4406 gcc_assert (REGNO (base
) < FIRST_PSEUDO_REGISTER
);
4407 gcc_assert (REGNO_REG_CLASS (REGNO (base
)) == ADDR_REGS
);
4410 /* Offsets are constricted to twelve bits. */
4411 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, offset
& ((1 << 12) - 1));
4413 fprintf (file
, "(%s)", reg_names
[REGNO (base
)]);
4416 /* See 'get_some_local_dynamic_name'. */
4419 get_some_local_dynamic_name_1 (rtx
*px
, void *data ATTRIBUTE_UNUSED
)
4423 if (GET_CODE (x
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (x
))
4425 x
= get_pool_constant (x
);
4426 return for_each_rtx (&x
, get_some_local_dynamic_name_1
, 0);
4429 if (GET_CODE (x
) == SYMBOL_REF
4430 && tls_symbolic_operand (x
) == TLS_MODEL_LOCAL_DYNAMIC
)
4432 cfun
->machine
->some_ld_name
= XSTR (x
, 0);
4439 /* Locate some local-dynamic symbol still in use by this function
4440 so that we can print its name in local-dynamic base patterns. */
4443 get_some_local_dynamic_name (void)
4447 if (cfun
->machine
->some_ld_name
)
4448 return cfun
->machine
->some_ld_name
;
4450 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
4452 && for_each_rtx (&PATTERN (insn
), get_some_local_dynamic_name_1
, 0))
4453 return cfun
->machine
->some_ld_name
;
4458 /* Output machine-dependent UNSPECs occurring in address constant X
4459 in assembler syntax to stdio stream FILE. Returns true if the
4460 constant X could be recognized, false otherwise. */
4463 s390_output_addr_const_extra (FILE *file
, rtx x
)
4465 if (GET_CODE (x
) == UNSPEC
&& XVECLEN (x
, 0) == 1)
4466 switch (XINT (x
, 1))
4469 output_addr_const (file
, XVECEXP (x
, 0, 0));
4470 fprintf (file
, "@GOTENT");
4473 output_addr_const (file
, XVECEXP (x
, 0, 0));
4474 fprintf (file
, "@GOT");
4477 output_addr_const (file
, XVECEXP (x
, 0, 0));
4478 fprintf (file
, "@GOTOFF");
4481 output_addr_const (file
, XVECEXP (x
, 0, 0));
4482 fprintf (file
, "@PLT");
4485 output_addr_const (file
, XVECEXP (x
, 0, 0));
4486 fprintf (file
, "@PLTOFF");
4489 output_addr_const (file
, XVECEXP (x
, 0, 0));
4490 fprintf (file
, "@TLSGD");
4493 assemble_name (file
, get_some_local_dynamic_name ());
4494 fprintf (file
, "@TLSLDM");
4497 output_addr_const (file
, XVECEXP (x
, 0, 0));
4498 fprintf (file
, "@DTPOFF");
4501 output_addr_const (file
, XVECEXP (x
, 0, 0));
4502 fprintf (file
, "@NTPOFF");
4504 case UNSPEC_GOTNTPOFF
:
4505 output_addr_const (file
, XVECEXP (x
, 0, 0));
4506 fprintf (file
, "@GOTNTPOFF");
4508 case UNSPEC_INDNTPOFF
:
4509 output_addr_const (file
, XVECEXP (x
, 0, 0));
4510 fprintf (file
, "@INDNTPOFF");
4517 /* Output address operand ADDR in assembler syntax to
4518 stdio stream FILE. */
4521 print_operand_address (FILE *file
, rtx addr
)
4523 struct s390_address ad
;
4525 if (!s390_decompose_address (addr
, &ad
)
4526 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
4527 || (ad
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (ad
.indx
))))
4528 output_operand_lossage ("cannot decompose address");
4531 output_addr_const (file
, ad
.disp
);
4533 fprintf (file
, "0");
4535 if (ad
.base
&& ad
.indx
)
4536 fprintf (file
, "(%s,%s)", reg_names
[REGNO (ad
.indx
)],
4537 reg_names
[REGNO (ad
.base
)]);
4539 fprintf (file
, "(%s)", reg_names
[REGNO (ad
.base
)]);
4542 /* Output operand X in assembler syntax to stdio stream FILE.
4543 CODE specified the format flag. The following format flags
4546 'C': print opcode suffix for branch condition.
4547 'D': print opcode suffix for inverse branch condition.
4548 'J': print tls_load/tls_gdcall/tls_ldcall suffix
4549 'G': print the size of the operand in bytes.
4550 'O': print only the displacement of a memory reference.
4551 'R': print only the base register of a memory reference.
4552 'S': print S-type memory reference (base+displacement).
4553 'N': print the second word of a DImode operand.
4554 'M': print the second word of a TImode operand.
4555 'Y': print shift count operand.
4557 'b': print integer X as if it's an unsigned byte.
4558 'x': print integer X as if it's an unsigned halfword.
4559 'h': print integer X as if it's a signed halfword.
4560 'i': print the first nonzero HImode part of X.
4561 'j': print the first HImode part unequal to -1 of X.
4562 'k': print the first nonzero SImode part of X.
4563 'm': print the first SImode part unequal to -1 of X.
4564 'o': print integer X as if it's an unsigned 32bit word. */
4567 print_operand (FILE *file
, rtx x
, int code
)
4572 fprintf (file
, s390_branch_condition_mnemonic (x
, FALSE
));
4576 fprintf (file
, s390_branch_condition_mnemonic (x
, TRUE
));
4580 if (GET_CODE (x
) == SYMBOL_REF
)
4582 fprintf (file
, "%s", ":tls_load:");
4583 output_addr_const (file
, x
);
4585 else if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_TLSGD
)
4587 fprintf (file
, "%s", ":tls_gdcall:");
4588 output_addr_const (file
, XVECEXP (x
, 0, 0));
4590 else if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_TLSLDM
)
4592 fprintf (file
, "%s", ":tls_ldcall:");
4593 assemble_name (file
, get_some_local_dynamic_name ());
4600 fprintf (file
, "%u", GET_MODE_SIZE (GET_MODE (x
)));
4605 struct s390_address ad
;
4608 gcc_assert (GET_CODE (x
) == MEM
);
4609 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
4611 gcc_assert (!ad
.base
|| REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)));
4612 gcc_assert (!ad
.indx
);
4615 output_addr_const (file
, ad
.disp
);
4617 fprintf (file
, "0");
4623 struct s390_address ad
;
4626 gcc_assert (GET_CODE (x
) == MEM
);
4627 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
4629 gcc_assert (!ad
.base
|| REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)));
4630 gcc_assert (!ad
.indx
);
4633 fprintf (file
, "%s", reg_names
[REGNO (ad
.base
)]);
4635 fprintf (file
, "0");
4641 struct s390_address ad
;
4644 gcc_assert (GET_CODE (x
) == MEM
);
4645 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
4647 gcc_assert (!ad
.base
|| REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)));
4648 gcc_assert (!ad
.indx
);
4651 output_addr_const (file
, ad
.disp
);
4653 fprintf (file
, "0");
4656 fprintf (file
, "(%s)", reg_names
[REGNO (ad
.base
)]);
4661 if (GET_CODE (x
) == REG
)
4662 x
= gen_rtx_REG (GET_MODE (x
), REGNO (x
) + 1);
4663 else if (GET_CODE (x
) == MEM
)
4664 x
= change_address (x
, VOIDmode
, plus_constant (XEXP (x
, 0), 4));
4670 if (GET_CODE (x
) == REG
)
4671 x
= gen_rtx_REG (GET_MODE (x
), REGNO (x
) + 1);
4672 else if (GET_CODE (x
) == MEM
)
4673 x
= change_address (x
, VOIDmode
, plus_constant (XEXP (x
, 0), 8));
4679 print_shift_count_operand (file
, x
);
4683 switch (GET_CODE (x
))
4686 fprintf (file
, "%s", reg_names
[REGNO (x
)]);
4690 output_address (XEXP (x
, 0));
4697 output_addr_const (file
, x
);
4702 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
) & 0xff);
4703 else if (code
== 'x')
4704 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
) & 0xffff);
4705 else if (code
== 'h')
4706 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, ((INTVAL (x
) & 0xffff) ^ 0x8000) - 0x8000);
4707 else if (code
== 'i')
4708 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
4709 s390_extract_part (x
, HImode
, 0));
4710 else if (code
== 'j')
4711 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
4712 s390_extract_part (x
, HImode
, -1));
4713 else if (code
== 'k')
4714 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
4715 s390_extract_part (x
, SImode
, 0));
4716 else if (code
== 'm')
4717 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
4718 s390_extract_part (x
, SImode
, -1));
4719 else if (code
== 'o')
4720 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
) & 0xffffffff);
4722 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
));
4726 gcc_assert (GET_MODE (x
) == VOIDmode
);
4728 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, CONST_DOUBLE_LOW (x
) & 0xff);
4729 else if (code
== 'x')
4730 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, CONST_DOUBLE_LOW (x
) & 0xffff);
4731 else if (code
== 'h')
4732 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, ((CONST_DOUBLE_LOW (x
) & 0xffff) ^ 0x8000) - 0x8000);
4738 fatal_insn ("UNKNOWN in print_operand !?", x
);
4743 /* Target hook for assembling integer objects. We need to define it
4744 here to work a round a bug in some versions of GAS, which couldn't
4745 handle values smaller than INT_MIN when printed in decimal. */
4748 s390_assemble_integer (rtx x
, unsigned int size
, int aligned_p
)
4750 if (size
== 8 && aligned_p
4751 && GET_CODE (x
) == CONST_INT
&& INTVAL (x
) < INT_MIN
)
4753 fprintf (asm_out_file
, "\t.quad\t" HOST_WIDE_INT_PRINT_HEX
"\n",
4757 return default_assemble_integer (x
, size
, aligned_p
);
4760 /* Returns true if register REGNO is used for forming
4761 a memory address in expression X. */
4764 reg_used_in_mem_p (int regno
, rtx x
)
4766 enum rtx_code code
= GET_CODE (x
);
4772 if (refers_to_regno_p (regno
, regno
+1,
4776 else if (code
== SET
4777 && GET_CODE (SET_DEST (x
)) == PC
)
4779 if (refers_to_regno_p (regno
, regno
+1,
4784 fmt
= GET_RTX_FORMAT (code
);
4785 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4788 && reg_used_in_mem_p (regno
, XEXP (x
, i
)))
4791 else if (fmt
[i
] == 'E')
4792 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
4793 if (reg_used_in_mem_p (regno
, XVECEXP (x
, i
, j
)))
4799 /* Returns true if expression DEP_RTX sets an address register
4800 used by instruction INSN to address memory. */
4803 addr_generation_dependency_p (rtx dep_rtx
, rtx insn
)
4807 if (GET_CODE (dep_rtx
) == INSN
)
4808 dep_rtx
= PATTERN (dep_rtx
);
4810 if (GET_CODE (dep_rtx
) == SET
)
4812 target
= SET_DEST (dep_rtx
);
4813 if (GET_CODE (target
) == STRICT_LOW_PART
)
4814 target
= XEXP (target
, 0);
4815 while (GET_CODE (target
) == SUBREG
)
4816 target
= SUBREG_REG (target
);
4818 if (GET_CODE (target
) == REG
)
4820 int regno
= REGNO (target
);
4822 if (s390_safe_attr_type (insn
) == TYPE_LA
)
4824 pat
= PATTERN (insn
);
4825 if (GET_CODE (pat
) == PARALLEL
)
4827 gcc_assert (XVECLEN (pat
, 0) == 2);
4828 pat
= XVECEXP (pat
, 0, 0);
4830 gcc_assert (GET_CODE (pat
) == SET
);
4831 return refers_to_regno_p (regno
, regno
+1, SET_SRC (pat
), 0);
4833 else if (get_attr_atype (insn
) == ATYPE_AGEN
)
4834 return reg_used_in_mem_p (regno
, PATTERN (insn
));
4840 /* Return 1, if dep_insn sets register used in insn in the agen unit. */
4843 s390_agen_dep_p (rtx dep_insn
, rtx insn
)
4845 rtx dep_rtx
= PATTERN (dep_insn
);
4848 if (GET_CODE (dep_rtx
) == SET
4849 && addr_generation_dependency_p (dep_rtx
, insn
))
4851 else if (GET_CODE (dep_rtx
) == PARALLEL
)
4853 for (i
= 0; i
< XVECLEN (dep_rtx
, 0); i
++)
4855 if (addr_generation_dependency_p (XVECEXP (dep_rtx
, 0, i
), insn
))
4862 /* A C statement (sans semicolon) to update the integer scheduling priority
4863 INSN_PRIORITY (INSN). Increase the priority to execute the INSN earlier,
4864 reduce the priority to execute INSN later. Do not define this macro if
4865 you do not need to adjust the scheduling priorities of insns.
4867 A STD instruction should be scheduled earlier,
4868 in order to use the bypass. */
4871 s390_adjust_priority (rtx insn ATTRIBUTE_UNUSED
, int priority
)
4873 if (! INSN_P (insn
))
4876 if (s390_tune
!= PROCESSOR_2084_Z990
4877 && s390_tune
!= PROCESSOR_2094_Z9_109
)
4880 switch (s390_safe_attr_type (insn
))
4884 priority
= priority
<< 3;
4888 priority
= priority
<< 1;
4896 /* The number of instructions that can be issued per cycle. */
4899 s390_issue_rate (void)
4901 if (s390_tune
== PROCESSOR_2084_Z990
4902 || s390_tune
== PROCESSOR_2094_Z9_109
)
4908 s390_first_cycle_multipass_dfa_lookahead (void)
4914 /* Annotate every literal pool reference in X by an UNSPEC_LTREF expression.
4915 Fix up MEMs as required. */
4918 annotate_constant_pool_refs (rtx
*x
)
4923 gcc_assert (GET_CODE (*x
) != SYMBOL_REF
4924 || !CONSTANT_POOL_ADDRESS_P (*x
));
4926 /* Literal pool references can only occur inside a MEM ... */
4927 if (GET_CODE (*x
) == MEM
)
4929 rtx memref
= XEXP (*x
, 0);
4931 if (GET_CODE (memref
) == SYMBOL_REF
4932 && CONSTANT_POOL_ADDRESS_P (memref
))
4934 rtx base
= cfun
->machine
->base_reg
;
4935 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, memref
, base
),
4938 *x
= replace_equiv_address (*x
, addr
);
4942 if (GET_CODE (memref
) == CONST
4943 && GET_CODE (XEXP (memref
, 0)) == PLUS
4944 && GET_CODE (XEXP (XEXP (memref
, 0), 1)) == CONST_INT
4945 && GET_CODE (XEXP (XEXP (memref
, 0), 0)) == SYMBOL_REF
4946 && CONSTANT_POOL_ADDRESS_P (XEXP (XEXP (memref
, 0), 0)))
4948 HOST_WIDE_INT off
= INTVAL (XEXP (XEXP (memref
, 0), 1));
4949 rtx sym
= XEXP (XEXP (memref
, 0), 0);
4950 rtx base
= cfun
->machine
->base_reg
;
4951 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, sym
, base
),
4954 *x
= replace_equiv_address (*x
, plus_constant (addr
, off
));
4959 /* ... or a load-address type pattern. */
4960 if (GET_CODE (*x
) == SET
)
4962 rtx addrref
= SET_SRC (*x
);
4964 if (GET_CODE (addrref
) == SYMBOL_REF
4965 && CONSTANT_POOL_ADDRESS_P (addrref
))
4967 rtx base
= cfun
->machine
->base_reg
;
4968 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, addrref
, base
),
4971 SET_SRC (*x
) = addr
;
4975 if (GET_CODE (addrref
) == CONST
4976 && GET_CODE (XEXP (addrref
, 0)) == PLUS
4977 && GET_CODE (XEXP (XEXP (addrref
, 0), 1)) == CONST_INT
4978 && GET_CODE (XEXP (XEXP (addrref
, 0), 0)) == SYMBOL_REF
4979 && CONSTANT_POOL_ADDRESS_P (XEXP (XEXP (addrref
, 0), 0)))
4981 HOST_WIDE_INT off
= INTVAL (XEXP (XEXP (addrref
, 0), 1));
4982 rtx sym
= XEXP (XEXP (addrref
, 0), 0);
4983 rtx base
= cfun
->machine
->base_reg
;
4984 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, sym
, base
),
4987 SET_SRC (*x
) = plus_constant (addr
, off
);
4992 /* Annotate LTREL_BASE as well. */
4993 if (GET_CODE (*x
) == UNSPEC
4994 && XINT (*x
, 1) == UNSPEC_LTREL_BASE
)
4996 rtx base
= cfun
->machine
->base_reg
;
4997 *x
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, XVECEXP (*x
, 0, 0), base
),
5002 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
5003 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
5007 annotate_constant_pool_refs (&XEXP (*x
, i
));
5009 else if (fmt
[i
] == 'E')
5011 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
5012 annotate_constant_pool_refs (&XVECEXP (*x
, i
, j
));
5017 /* Split all branches that exceed the maximum distance.
5018 Returns true if this created a new literal pool entry. */
5021 s390_split_branches (void)
5023 rtx temp_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
5024 int new_literal
= 0, ret
;
5025 rtx insn
, pat
, tmp
, target
;
5028 /* We need correct insn addresses. */
5030 shorten_branches (get_insns ());
5032 /* Find all branches that exceed 64KB, and split them. */
5034 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5036 if (GET_CODE (insn
) != JUMP_INSN
)
5039 pat
= PATTERN (insn
);
5040 if (GET_CODE (pat
) == PARALLEL
&& XVECLEN (pat
, 0) > 2)
5041 pat
= XVECEXP (pat
, 0, 0);
5042 if (GET_CODE (pat
) != SET
|| SET_DEST (pat
) != pc_rtx
)
5045 if (GET_CODE (SET_SRC (pat
)) == LABEL_REF
)
5047 label
= &SET_SRC (pat
);
5049 else if (GET_CODE (SET_SRC (pat
)) == IF_THEN_ELSE
)
5051 if (GET_CODE (XEXP (SET_SRC (pat
), 1)) == LABEL_REF
)
5052 label
= &XEXP (SET_SRC (pat
), 1);
5053 else if (GET_CODE (XEXP (SET_SRC (pat
), 2)) == LABEL_REF
)
5054 label
= &XEXP (SET_SRC (pat
), 2);
5061 if (get_attr_length (insn
) <= 4)
5064 /* We are going to use the return register as scratch register,
5065 make sure it will be saved/restored by the prologue/epilogue. */
5066 cfun_frame_layout
.save_return_addr_p
= 1;
5071 tmp
= force_const_mem (Pmode
, *label
);
5072 tmp
= emit_insn_before (gen_rtx_SET (Pmode
, temp_reg
, tmp
), insn
);
5073 INSN_ADDRESSES_NEW (tmp
, -1);
5074 annotate_constant_pool_refs (&PATTERN (tmp
));
5081 target
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, *label
),
5082 UNSPEC_LTREL_OFFSET
);
5083 target
= gen_rtx_CONST (Pmode
, target
);
5084 target
= force_const_mem (Pmode
, target
);
5085 tmp
= emit_insn_before (gen_rtx_SET (Pmode
, temp_reg
, target
), insn
);
5086 INSN_ADDRESSES_NEW (tmp
, -1);
5087 annotate_constant_pool_refs (&PATTERN (tmp
));
5089 target
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, XEXP (target
, 0),
5090 cfun
->machine
->base_reg
),
5092 target
= gen_rtx_PLUS (Pmode
, temp_reg
, target
);
5095 ret
= validate_change (insn
, label
, target
, 0);
5103 /* Find an annotated literal pool symbol referenced in RTX X,
5104 and store it at REF. Will abort if X contains references to
5105 more than one such pool symbol; multiple references to the same
5106 symbol are allowed, however.
5108 The rtx pointed to by REF must be initialized to NULL_RTX
5109 by the caller before calling this routine. */
5112 find_constant_pool_ref (rtx x
, rtx
*ref
)
5117 /* Ignore LTREL_BASE references. */
5118 if (GET_CODE (x
) == UNSPEC
5119 && XINT (x
, 1) == UNSPEC_LTREL_BASE
)
5121 /* Likewise POOL_ENTRY insns. */
5122 if (GET_CODE (x
) == UNSPEC_VOLATILE
5123 && XINT (x
, 1) == UNSPECV_POOL_ENTRY
)
5126 gcc_assert (GET_CODE (x
) != SYMBOL_REF
5127 || !CONSTANT_POOL_ADDRESS_P (x
));
5129 if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_LTREF
)
5131 rtx sym
= XVECEXP (x
, 0, 0);
5132 gcc_assert (GET_CODE (sym
) == SYMBOL_REF
5133 && CONSTANT_POOL_ADDRESS_P (sym
));
5135 if (*ref
== NULL_RTX
)
5138 gcc_assert (*ref
== sym
);
5143 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
5144 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
5148 find_constant_pool_ref (XEXP (x
, i
), ref
);
5150 else if (fmt
[i
] == 'E')
5152 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
5153 find_constant_pool_ref (XVECEXP (x
, i
, j
), ref
);
5158 /* Replace every reference to the annotated literal pool
5159 symbol REF in X by its base plus OFFSET. */
5162 replace_constant_pool_ref (rtx
*x
, rtx ref
, rtx offset
)
5167 gcc_assert (*x
!= ref
);
5169 if (GET_CODE (*x
) == UNSPEC
5170 && XINT (*x
, 1) == UNSPEC_LTREF
5171 && XVECEXP (*x
, 0, 0) == ref
)
5173 *x
= gen_rtx_PLUS (Pmode
, XVECEXP (*x
, 0, 1), offset
);
5177 if (GET_CODE (*x
) == PLUS
5178 && GET_CODE (XEXP (*x
, 1)) == CONST_INT
5179 && GET_CODE (XEXP (*x
, 0)) == UNSPEC
5180 && XINT (XEXP (*x
, 0), 1) == UNSPEC_LTREF
5181 && XVECEXP (XEXP (*x
, 0), 0, 0) == ref
)
5183 rtx addr
= gen_rtx_PLUS (Pmode
, XVECEXP (XEXP (*x
, 0), 0, 1), offset
);
5184 *x
= plus_constant (addr
, INTVAL (XEXP (*x
, 1)));
5188 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
5189 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
5193 replace_constant_pool_ref (&XEXP (*x
, i
), ref
, offset
);
5195 else if (fmt
[i
] == 'E')
5197 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
5198 replace_constant_pool_ref (&XVECEXP (*x
, i
, j
), ref
, offset
);
5203 /* Check whether X contains an UNSPEC_LTREL_BASE.
5204 Return its constant pool symbol if found, NULL_RTX otherwise. */
5207 find_ltrel_base (rtx x
)
5212 if (GET_CODE (x
) == UNSPEC
5213 && XINT (x
, 1) == UNSPEC_LTREL_BASE
)
5214 return XVECEXP (x
, 0, 0);
5216 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
5217 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
5221 rtx fnd
= find_ltrel_base (XEXP (x
, i
));
5225 else if (fmt
[i
] == 'E')
5227 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
5229 rtx fnd
= find_ltrel_base (XVECEXP (x
, i
, j
));
5239 /* Replace any occurrence of UNSPEC_LTREL_BASE in X with its base. */
5242 replace_ltrel_base (rtx
*x
)
5247 if (GET_CODE (*x
) == UNSPEC
5248 && XINT (*x
, 1) == UNSPEC_LTREL_BASE
)
5250 *x
= XVECEXP (*x
, 0, 1);
5254 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
5255 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
5259 replace_ltrel_base (&XEXP (*x
, i
));
5261 else if (fmt
[i
] == 'E')
5263 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
5264 replace_ltrel_base (&XVECEXP (*x
, i
, j
));
5270 /* We keep a list of constants which we have to add to internal
5271 constant tables in the middle of large functions. */
5273 #define NR_C_MODES 11
5274 enum machine_mode constant_modes
[NR_C_MODES
] =
5276 TFmode
, TImode
, TDmode
,
5277 DFmode
, DImode
, DDmode
,
5278 SFmode
, SImode
, SDmode
,
5285 struct constant
*next
;
5290 struct constant_pool
5292 struct constant_pool
*next
;
5297 struct constant
*constants
[NR_C_MODES
];
5298 struct constant
*execute
;
5303 /* Allocate new constant_pool structure. */
5305 static struct constant_pool
*
5306 s390_alloc_pool (void)
5308 struct constant_pool
*pool
;
5311 pool
= (struct constant_pool
*) xmalloc (sizeof *pool
);
5313 for (i
= 0; i
< NR_C_MODES
; i
++)
5314 pool
->constants
[i
] = NULL
;
5316 pool
->execute
= NULL
;
5317 pool
->label
= gen_label_rtx ();
5318 pool
->first_insn
= NULL_RTX
;
5319 pool
->pool_insn
= NULL_RTX
;
5320 pool
->insns
= BITMAP_ALLOC (NULL
);
5326 /* Create new constant pool covering instructions starting at INSN
5327 and chain it to the end of POOL_LIST. */
5329 static struct constant_pool
*
5330 s390_start_pool (struct constant_pool
**pool_list
, rtx insn
)
5332 struct constant_pool
*pool
, **prev
;
5334 pool
= s390_alloc_pool ();
5335 pool
->first_insn
= insn
;
5337 for (prev
= pool_list
; *prev
; prev
= &(*prev
)->next
)
5344 /* End range of instructions covered by POOL at INSN and emit
5345 placeholder insn representing the pool. */
5348 s390_end_pool (struct constant_pool
*pool
, rtx insn
)
5350 rtx pool_size
= GEN_INT (pool
->size
+ 8 /* alignment slop */);
5353 insn
= get_last_insn ();
5355 pool
->pool_insn
= emit_insn_after (gen_pool (pool_size
), insn
);
5356 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
5359 /* Add INSN to the list of insns covered by POOL. */
5362 s390_add_pool_insn (struct constant_pool
*pool
, rtx insn
)
5364 bitmap_set_bit (pool
->insns
, INSN_UID (insn
));
5367 /* Return pool out of POOL_LIST that covers INSN. */
5369 static struct constant_pool
*
5370 s390_find_pool (struct constant_pool
*pool_list
, rtx insn
)
5372 struct constant_pool
*pool
;
5374 for (pool
= pool_list
; pool
; pool
= pool
->next
)
5375 if (bitmap_bit_p (pool
->insns
, INSN_UID (insn
)))
5381 /* Add constant VAL of mode MODE to the constant pool POOL. */
5384 s390_add_constant (struct constant_pool
*pool
, rtx val
, enum machine_mode mode
)
5389 for (i
= 0; i
< NR_C_MODES
; i
++)
5390 if (constant_modes
[i
] == mode
)
5392 gcc_assert (i
!= NR_C_MODES
);
5394 for (c
= pool
->constants
[i
]; c
!= NULL
; c
= c
->next
)
5395 if (rtx_equal_p (val
, c
->value
))
5400 c
= (struct constant
*) xmalloc (sizeof *c
);
5402 c
->label
= gen_label_rtx ();
5403 c
->next
= pool
->constants
[i
];
5404 pool
->constants
[i
] = c
;
5405 pool
->size
+= GET_MODE_SIZE (mode
);
5409 /* Find constant VAL of mode MODE in the constant pool POOL.
5410 Return an RTX describing the distance from the start of
5411 the pool to the location of the new constant. */
5414 s390_find_constant (struct constant_pool
*pool
, rtx val
,
5415 enum machine_mode mode
)
5421 for (i
= 0; i
< NR_C_MODES
; i
++)
5422 if (constant_modes
[i
] == mode
)
5424 gcc_assert (i
!= NR_C_MODES
);
5426 for (c
= pool
->constants
[i
]; c
!= NULL
; c
= c
->next
)
5427 if (rtx_equal_p (val
, c
->value
))
5432 offset
= gen_rtx_MINUS (Pmode
, gen_rtx_LABEL_REF (Pmode
, c
->label
),
5433 gen_rtx_LABEL_REF (Pmode
, pool
->label
));
5434 offset
= gen_rtx_CONST (Pmode
, offset
);
5438 /* Check whether INSN is an execute. Return the label_ref to its
5439 execute target template if so, NULL_RTX otherwise. */
5442 s390_execute_label (rtx insn
)
5444 if (GET_CODE (insn
) == INSN
5445 && GET_CODE (PATTERN (insn
)) == PARALLEL
5446 && GET_CODE (XVECEXP (PATTERN (insn
), 0, 0)) == UNSPEC
5447 && XINT (XVECEXP (PATTERN (insn
), 0, 0), 1) == UNSPEC_EXECUTE
)
5448 return XVECEXP (XVECEXP (PATTERN (insn
), 0, 0), 0, 2);
5453 /* Add execute target for INSN to the constant pool POOL. */
5456 s390_add_execute (struct constant_pool
*pool
, rtx insn
)
5460 for (c
= pool
->execute
; c
!= NULL
; c
= c
->next
)
5461 if (INSN_UID (insn
) == INSN_UID (c
->value
))
5466 c
= (struct constant
*) xmalloc (sizeof *c
);
5468 c
->label
= gen_label_rtx ();
5469 c
->next
= pool
->execute
;
5475 /* Find execute target for INSN in the constant pool POOL.
5476 Return an RTX describing the distance from the start of
5477 the pool to the location of the execute target. */
5480 s390_find_execute (struct constant_pool
*pool
, rtx insn
)
5485 for (c
= pool
->execute
; c
!= NULL
; c
= c
->next
)
5486 if (INSN_UID (insn
) == INSN_UID (c
->value
))
5491 offset
= gen_rtx_MINUS (Pmode
, gen_rtx_LABEL_REF (Pmode
, c
->label
),
5492 gen_rtx_LABEL_REF (Pmode
, pool
->label
));
5493 offset
= gen_rtx_CONST (Pmode
, offset
);
5497 /* For an execute INSN, extract the execute target template. */
5500 s390_execute_target (rtx insn
)
5502 rtx pattern
= PATTERN (insn
);
5503 gcc_assert (s390_execute_label (insn
));
5505 if (XVECLEN (pattern
, 0) == 2)
5507 pattern
= copy_rtx (XVECEXP (pattern
, 0, 1));
5511 rtvec vec
= rtvec_alloc (XVECLEN (pattern
, 0) - 1);
5514 for (i
= 0; i
< XVECLEN (pattern
, 0) - 1; i
++)
5515 RTVEC_ELT (vec
, i
) = copy_rtx (XVECEXP (pattern
, 0, i
+ 1));
5517 pattern
= gen_rtx_PARALLEL (VOIDmode
, vec
);
5523 /* Indicate that INSN cannot be duplicated. This is the case for
5524 execute insns that carry a unique label. */
5527 s390_cannot_copy_insn_p (rtx insn
)
5529 rtx label
= s390_execute_label (insn
);
5530 return label
&& label
!= const0_rtx
;
5533 /* Dump out the constants in POOL. If REMOTE_LABEL is true,
5534 do not emit the pool base label. */
5537 s390_dump_pool (struct constant_pool
*pool
, bool remote_label
)
5540 rtx insn
= pool
->pool_insn
;
5543 /* Switch to rodata section. */
5544 if (TARGET_CPU_ZARCH
)
5546 insn
= emit_insn_after (gen_pool_section_start (), insn
);
5547 INSN_ADDRESSES_NEW (insn
, -1);
5550 /* Ensure minimum pool alignment. */
5551 if (TARGET_CPU_ZARCH
)
5552 insn
= emit_insn_after (gen_pool_align (GEN_INT (8)), insn
);
5554 insn
= emit_insn_after (gen_pool_align (GEN_INT (4)), insn
);
5555 INSN_ADDRESSES_NEW (insn
, -1);
5557 /* Emit pool base label. */
5560 insn
= emit_label_after (pool
->label
, insn
);
5561 INSN_ADDRESSES_NEW (insn
, -1);
5564 /* Dump constants in descending alignment requirement order,
5565 ensuring proper alignment for every constant. */
5566 for (i
= 0; i
< NR_C_MODES
; i
++)
5567 for (c
= pool
->constants
[i
]; c
; c
= c
->next
)
5569 /* Convert UNSPEC_LTREL_OFFSET unspecs to pool-relative references. */
5570 rtx value
= c
->value
;
5571 if (GET_CODE (value
) == CONST
5572 && GET_CODE (XEXP (value
, 0)) == UNSPEC
5573 && XINT (XEXP (value
, 0), 1) == UNSPEC_LTREL_OFFSET
5574 && XVECLEN (XEXP (value
, 0), 0) == 1)
5576 value
= gen_rtx_MINUS (Pmode
, XVECEXP (XEXP (value
, 0), 0, 0),
5577 gen_rtx_LABEL_REF (VOIDmode
, pool
->label
));
5578 value
= gen_rtx_CONST (VOIDmode
, value
);
5581 insn
= emit_label_after (c
->label
, insn
);
5582 INSN_ADDRESSES_NEW (insn
, -1);
5584 value
= gen_rtx_UNSPEC_VOLATILE (constant_modes
[i
],
5585 gen_rtvec (1, value
),
5586 UNSPECV_POOL_ENTRY
);
5587 insn
= emit_insn_after (value
, insn
);
5588 INSN_ADDRESSES_NEW (insn
, -1);
5591 /* Ensure minimum alignment for instructions. */
5592 insn
= emit_insn_after (gen_pool_align (GEN_INT (2)), insn
);
5593 INSN_ADDRESSES_NEW (insn
, -1);
5595 /* Output in-pool execute template insns. */
5596 for (c
= pool
->execute
; c
; c
= c
->next
)
5598 insn
= emit_label_after (c
->label
, insn
);
5599 INSN_ADDRESSES_NEW (insn
, -1);
5601 insn
= emit_insn_after (s390_execute_target (c
->value
), insn
);
5602 INSN_ADDRESSES_NEW (insn
, -1);
5605 /* Switch back to previous section. */
5606 if (TARGET_CPU_ZARCH
)
5608 insn
= emit_insn_after (gen_pool_section_end (), insn
);
5609 INSN_ADDRESSES_NEW (insn
, -1);
5612 insn
= emit_barrier_after (insn
);
5613 INSN_ADDRESSES_NEW (insn
, -1);
5615 /* Remove placeholder insn. */
5616 remove_insn (pool
->pool_insn
);
5619 /* Free all memory used by POOL. */
5622 s390_free_pool (struct constant_pool
*pool
)
5624 struct constant
*c
, *next
;
5627 for (i
= 0; i
< NR_C_MODES
; i
++)
5628 for (c
= pool
->constants
[i
]; c
; c
= next
)
5634 for (c
= pool
->execute
; c
; c
= next
)
5640 BITMAP_FREE (pool
->insns
);
5645 /* Collect main literal pool. Return NULL on overflow. */
5647 static struct constant_pool
*
5648 s390_mainpool_start (void)
5650 struct constant_pool
*pool
;
5653 pool
= s390_alloc_pool ();
5655 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5657 if (GET_CODE (insn
) == INSN
5658 && GET_CODE (PATTERN (insn
)) == SET
5659 && GET_CODE (SET_SRC (PATTERN (insn
))) == UNSPEC_VOLATILE
5660 && XINT (SET_SRC (PATTERN (insn
)), 1) == UNSPECV_MAIN_POOL
)
5662 gcc_assert (!pool
->pool_insn
);
5663 pool
->pool_insn
= insn
;
5666 if (!TARGET_CPU_ZARCH
&& s390_execute_label (insn
))
5668 s390_add_execute (pool
, insn
);
5670 else if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
5672 rtx pool_ref
= NULL_RTX
;
5673 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
5676 rtx constant
= get_pool_constant (pool_ref
);
5677 enum machine_mode mode
= get_pool_mode (pool_ref
);
5678 s390_add_constant (pool
, constant
, mode
);
5683 gcc_assert (pool
->pool_insn
|| pool
->size
== 0);
5685 if (pool
->size
>= 4096)
5687 /* We're going to chunkify the pool, so remove the main
5688 pool placeholder insn. */
5689 remove_insn (pool
->pool_insn
);
5691 s390_free_pool (pool
);
5698 /* POOL holds the main literal pool as collected by s390_mainpool_start.
5699 Modify the current function to output the pool constants as well as
5700 the pool register setup instruction. */
5703 s390_mainpool_finish (struct constant_pool
*pool
)
5705 rtx base_reg
= cfun
->machine
->base_reg
;
5708 /* If the pool is empty, we're done. */
5709 if (pool
->size
== 0)
5711 /* We don't actually need a base register after all. */
5712 cfun
->machine
->base_reg
= NULL_RTX
;
5714 if (pool
->pool_insn
)
5715 remove_insn (pool
->pool_insn
);
5716 s390_free_pool (pool
);
5720 /* We need correct insn addresses. */
5721 shorten_branches (get_insns ());
5723 /* On zSeries, we use a LARL to load the pool register. The pool is
5724 located in the .rodata section, so we emit it after the function. */
5725 if (TARGET_CPU_ZARCH
)
5727 insn
= gen_main_base_64 (base_reg
, pool
->label
);
5728 insn
= emit_insn_after (insn
, pool
->pool_insn
);
5729 INSN_ADDRESSES_NEW (insn
, -1);
5730 remove_insn (pool
->pool_insn
);
5732 insn
= get_last_insn ();
5733 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
5734 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
5736 s390_dump_pool (pool
, 0);
5739 /* On S/390, if the total size of the function's code plus literal pool
5740 does not exceed 4096 bytes, we use BASR to set up a function base
5741 pointer, and emit the literal pool at the end of the function. */
5742 else if (INSN_ADDRESSES (INSN_UID (get_last_insn ()))
5743 + pool
->size
+ 8 /* alignment slop */ < 4096)
5745 insn
= gen_main_base_31_small (base_reg
, pool
->label
);
5746 insn
= emit_insn_after (insn
, pool
->pool_insn
);
5747 INSN_ADDRESSES_NEW (insn
, -1);
5748 remove_insn (pool
->pool_insn
);
5750 insn
= emit_label_after (pool
->label
, insn
);
5751 INSN_ADDRESSES_NEW (insn
, -1);
5753 insn
= get_last_insn ();
5754 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
5755 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
5757 s390_dump_pool (pool
, 1);
5760 /* Otherwise, we emit an inline literal pool and use BASR to branch
5761 over it, setting up the pool register at the same time. */
5764 rtx pool_end
= gen_label_rtx ();
5766 insn
= gen_main_base_31_large (base_reg
, pool
->label
, pool_end
);
5767 insn
= emit_insn_after (insn
, pool
->pool_insn
);
5768 INSN_ADDRESSES_NEW (insn
, -1);
5769 remove_insn (pool
->pool_insn
);
5771 insn
= emit_label_after (pool
->label
, insn
);
5772 INSN_ADDRESSES_NEW (insn
, -1);
5774 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
5775 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
5777 insn
= emit_label_after (pool_end
, pool
->pool_insn
);
5778 INSN_ADDRESSES_NEW (insn
, -1);
5780 s390_dump_pool (pool
, 1);
5784 /* Replace all literal pool references. */
5786 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5789 replace_ltrel_base (&PATTERN (insn
));
5791 if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
5793 rtx addr
, pool_ref
= NULL_RTX
;
5794 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
5797 if (s390_execute_label (insn
))
5798 addr
= s390_find_execute (pool
, insn
);
5800 addr
= s390_find_constant (pool
, get_pool_constant (pool_ref
),
5801 get_pool_mode (pool_ref
));
5803 replace_constant_pool_ref (&PATTERN (insn
), pool_ref
, addr
);
5804 INSN_CODE (insn
) = -1;
5810 /* Free the pool. */
5811 s390_free_pool (pool
);
5814 /* POOL holds the main literal pool as collected by s390_mainpool_start.
5815 We have decided we cannot use this pool, so revert all changes
5816 to the current function that were done by s390_mainpool_start. */
5818 s390_mainpool_cancel (struct constant_pool
*pool
)
5820 /* We didn't actually change the instruction stream, so simply
5821 free the pool memory. */
5822 s390_free_pool (pool
);
5826 /* Chunkify the literal pool. */
5828 #define S390_POOL_CHUNK_MIN 0xc00
5829 #define S390_POOL_CHUNK_MAX 0xe00
5831 static struct constant_pool
*
5832 s390_chunkify_start (void)
5834 struct constant_pool
*curr_pool
= NULL
, *pool_list
= NULL
;
5837 rtx pending_ltrel
= NULL_RTX
;
5840 rtx (*gen_reload_base
) (rtx
, rtx
) =
5841 TARGET_CPU_ZARCH
? gen_reload_base_64
: gen_reload_base_31
;
5844 /* We need correct insn addresses. */
5846 shorten_branches (get_insns ());
5848 /* Scan all insns and move literals to pool chunks. */
5850 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5852 /* Check for pending LTREL_BASE. */
5855 rtx ltrel_base
= find_ltrel_base (PATTERN (insn
));
5858 gcc_assert (ltrel_base
== pending_ltrel
);
5859 pending_ltrel
= NULL_RTX
;
5863 if (!TARGET_CPU_ZARCH
&& s390_execute_label (insn
))
5866 curr_pool
= s390_start_pool (&pool_list
, insn
);
5868 s390_add_execute (curr_pool
, insn
);
5869 s390_add_pool_insn (curr_pool
, insn
);
5871 else if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
5873 rtx pool_ref
= NULL_RTX
;
5874 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
5877 rtx constant
= get_pool_constant (pool_ref
);
5878 enum machine_mode mode
= get_pool_mode (pool_ref
);
5881 curr_pool
= s390_start_pool (&pool_list
, insn
);
5883 s390_add_constant (curr_pool
, constant
, mode
);
5884 s390_add_pool_insn (curr_pool
, insn
);
5886 /* Don't split the pool chunk between a LTREL_OFFSET load
5887 and the corresponding LTREL_BASE. */
5888 if (GET_CODE (constant
) == CONST
5889 && GET_CODE (XEXP (constant
, 0)) == UNSPEC
5890 && XINT (XEXP (constant
, 0), 1) == UNSPEC_LTREL_OFFSET
)
5892 gcc_assert (!pending_ltrel
);
5893 pending_ltrel
= pool_ref
;
5898 if (GET_CODE (insn
) == JUMP_INSN
|| GET_CODE (insn
) == CODE_LABEL
)
5901 s390_add_pool_insn (curr_pool
, insn
);
5902 /* An LTREL_BASE must follow within the same basic block. */
5903 gcc_assert (!pending_ltrel
);
5907 || INSN_ADDRESSES_SIZE () <= (size_t) INSN_UID (insn
)
5908 || INSN_ADDRESSES (INSN_UID (insn
)) == -1)
5911 if (TARGET_CPU_ZARCH
)
5913 if (curr_pool
->size
< S390_POOL_CHUNK_MAX
)
5916 s390_end_pool (curr_pool
, NULL_RTX
);
5921 int chunk_size
= INSN_ADDRESSES (INSN_UID (insn
))
5922 - INSN_ADDRESSES (INSN_UID (curr_pool
->first_insn
))
5925 /* We will later have to insert base register reload insns.
5926 Those will have an effect on code size, which we need to
5927 consider here. This calculation makes rather pessimistic
5928 worst-case assumptions. */
5929 if (GET_CODE (insn
) == CODE_LABEL
)
5932 if (chunk_size
< S390_POOL_CHUNK_MIN
5933 && curr_pool
->size
< S390_POOL_CHUNK_MIN
)
5936 /* Pool chunks can only be inserted after BARRIERs ... */
5937 if (GET_CODE (insn
) == BARRIER
)
5939 s390_end_pool (curr_pool
, insn
);
5944 /* ... so if we don't find one in time, create one. */
5945 else if ((chunk_size
> S390_POOL_CHUNK_MAX
5946 || curr_pool
->size
> S390_POOL_CHUNK_MAX
))
5948 rtx label
, jump
, barrier
;
5950 /* We can insert the barrier only after a 'real' insn. */
5951 if (GET_CODE (insn
) != INSN
&& GET_CODE (insn
) != CALL_INSN
)
5953 if (get_attr_length (insn
) == 0)
5956 /* Don't separate LTREL_BASE from the corresponding
5957 LTREL_OFFSET load. */
5961 label
= gen_label_rtx ();
5962 jump
= emit_jump_insn_after (gen_jump (label
), insn
);
5963 barrier
= emit_barrier_after (jump
);
5964 insn
= emit_label_after (label
, barrier
);
5965 JUMP_LABEL (jump
) = label
;
5966 LABEL_NUSES (label
) = 1;
5968 INSN_ADDRESSES_NEW (jump
, -1);
5969 INSN_ADDRESSES_NEW (barrier
, -1);
5970 INSN_ADDRESSES_NEW (insn
, -1);
5972 s390_end_pool (curr_pool
, barrier
);
5980 s390_end_pool (curr_pool
, NULL_RTX
);
5981 gcc_assert (!pending_ltrel
);
5983 /* Find all labels that are branched into
5984 from an insn belonging to a different chunk. */
5986 far_labels
= BITMAP_ALLOC (NULL
);
5988 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5990 /* Labels marked with LABEL_PRESERVE_P can be target
5991 of non-local jumps, so we have to mark them.
5992 The same holds for named labels.
5994 Don't do that, however, if it is the label before
5997 if (GET_CODE (insn
) == CODE_LABEL
5998 && (LABEL_PRESERVE_P (insn
) || LABEL_NAME (insn
)))
6000 rtx vec_insn
= next_real_insn (insn
);
6001 rtx vec_pat
= vec_insn
&& GET_CODE (vec_insn
) == JUMP_INSN
?
6002 PATTERN (vec_insn
) : NULL_RTX
;
6004 || !(GET_CODE (vec_pat
) == ADDR_VEC
6005 || GET_CODE (vec_pat
) == ADDR_DIFF_VEC
))
6006 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (insn
));
6009 /* If we have a direct jump (conditional or unconditional)
6010 or a casesi jump, check all potential targets. */
6011 else if (GET_CODE (insn
) == JUMP_INSN
)
6013 rtx pat
= PATTERN (insn
);
6014 if (GET_CODE (pat
) == PARALLEL
&& XVECLEN (pat
, 0) > 2)
6015 pat
= XVECEXP (pat
, 0, 0);
6017 if (GET_CODE (pat
) == SET
)
6019 rtx label
= JUMP_LABEL (insn
);
6022 if (s390_find_pool (pool_list
, label
)
6023 != s390_find_pool (pool_list
, insn
))
6024 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (label
));
6027 else if (GET_CODE (pat
) == PARALLEL
6028 && XVECLEN (pat
, 0) == 2
6029 && GET_CODE (XVECEXP (pat
, 0, 0)) == SET
6030 && GET_CODE (XVECEXP (pat
, 0, 1)) == USE
6031 && GET_CODE (XEXP (XVECEXP (pat
, 0, 1), 0)) == LABEL_REF
)
6033 /* Find the jump table used by this casesi jump. */
6034 rtx vec_label
= XEXP (XEXP (XVECEXP (pat
, 0, 1), 0), 0);
6035 rtx vec_insn
= next_real_insn (vec_label
);
6036 rtx vec_pat
= vec_insn
&& GET_CODE (vec_insn
) == JUMP_INSN
?
6037 PATTERN (vec_insn
) : NULL_RTX
;
6039 && (GET_CODE (vec_pat
) == ADDR_VEC
6040 || GET_CODE (vec_pat
) == ADDR_DIFF_VEC
))
6042 int i
, diff_p
= GET_CODE (vec_pat
) == ADDR_DIFF_VEC
;
6044 for (i
= 0; i
< XVECLEN (vec_pat
, diff_p
); i
++)
6046 rtx label
= XEXP (XVECEXP (vec_pat
, diff_p
, i
), 0);
6048 if (s390_find_pool (pool_list
, label
)
6049 != s390_find_pool (pool_list
, insn
))
6050 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (label
));
6057 /* Insert base register reload insns before every pool. */
6059 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
6061 rtx new_insn
= gen_reload_base (cfun
->machine
->base_reg
,
6063 rtx insn
= curr_pool
->first_insn
;
6064 INSN_ADDRESSES_NEW (emit_insn_before (new_insn
, insn
), -1);
6067 /* Insert base register reload insns at every far label. */
6069 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6070 if (GET_CODE (insn
) == CODE_LABEL
6071 && bitmap_bit_p (far_labels
, CODE_LABEL_NUMBER (insn
)))
6073 struct constant_pool
*pool
= s390_find_pool (pool_list
, insn
);
6076 rtx new_insn
= gen_reload_base (cfun
->machine
->base_reg
,
6078 INSN_ADDRESSES_NEW (emit_insn_after (new_insn
, insn
), -1);
6083 BITMAP_FREE (far_labels
);
6086 /* Recompute insn addresses. */
6088 init_insn_lengths ();
6089 shorten_branches (get_insns ());
6094 /* POOL_LIST is a chunk list as prepared by s390_chunkify_start.
6095 After we have decided to use this list, finish implementing
6096 all changes to the current function as required. */
6099 s390_chunkify_finish (struct constant_pool
*pool_list
)
6101 struct constant_pool
*curr_pool
= NULL
;
6105 /* Replace all literal pool references. */
6107 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6110 replace_ltrel_base (&PATTERN (insn
));
6112 curr_pool
= s390_find_pool (pool_list
, insn
);
6116 if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
6118 rtx addr
, pool_ref
= NULL_RTX
;
6119 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
6122 if (s390_execute_label (insn
))
6123 addr
= s390_find_execute (curr_pool
, insn
);
6125 addr
= s390_find_constant (curr_pool
,
6126 get_pool_constant (pool_ref
),
6127 get_pool_mode (pool_ref
));
6129 replace_constant_pool_ref (&PATTERN (insn
), pool_ref
, addr
);
6130 INSN_CODE (insn
) = -1;
6135 /* Dump out all literal pools. */
6137 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
6138 s390_dump_pool (curr_pool
, 0);
6140 /* Free pool list. */
6144 struct constant_pool
*next
= pool_list
->next
;
6145 s390_free_pool (pool_list
);
6150 /* POOL_LIST is a chunk list as prepared by s390_chunkify_start.
6151 We have decided we cannot use this list, so revert all changes
6152 to the current function that were done by s390_chunkify_start. */
6155 s390_chunkify_cancel (struct constant_pool
*pool_list
)
6157 struct constant_pool
*curr_pool
= NULL
;
6160 /* Remove all pool placeholder insns. */
6162 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
6164 /* Did we insert an extra barrier? Remove it. */
6165 rtx barrier
= PREV_INSN (curr_pool
->pool_insn
);
6166 rtx jump
= barrier
? PREV_INSN (barrier
) : NULL_RTX
;
6167 rtx label
= NEXT_INSN (curr_pool
->pool_insn
);
6169 if (jump
&& GET_CODE (jump
) == JUMP_INSN
6170 && barrier
&& GET_CODE (barrier
) == BARRIER
6171 && label
&& GET_CODE (label
) == CODE_LABEL
6172 && GET_CODE (PATTERN (jump
)) == SET
6173 && SET_DEST (PATTERN (jump
)) == pc_rtx
6174 && GET_CODE (SET_SRC (PATTERN (jump
))) == LABEL_REF
6175 && XEXP (SET_SRC (PATTERN (jump
)), 0) == label
)
6178 remove_insn (barrier
);
6179 remove_insn (label
);
6182 remove_insn (curr_pool
->pool_insn
);
6185 /* Remove all base register reload insns. */
6187 for (insn
= get_insns (); insn
; )
6189 rtx next_insn
= NEXT_INSN (insn
);
6191 if (GET_CODE (insn
) == INSN
6192 && GET_CODE (PATTERN (insn
)) == SET
6193 && GET_CODE (SET_SRC (PATTERN (insn
))) == UNSPEC
6194 && XINT (SET_SRC (PATTERN (insn
)), 1) == UNSPEC_RELOAD_BASE
)
6200 /* Free pool list. */
6204 struct constant_pool
*next
= pool_list
->next
;
6205 s390_free_pool (pool_list
);
6211 /* Output the constant pool entry EXP in mode MODE with alignment ALIGN. */
6214 s390_output_pool_entry (rtx exp
, enum machine_mode mode
, unsigned int align
)
6218 switch (GET_MODE_CLASS (mode
))
6221 case MODE_DECIMAL_FLOAT
:
6222 gcc_assert (GET_CODE (exp
) == CONST_DOUBLE
);
6224 REAL_VALUE_FROM_CONST_DOUBLE (r
, exp
);
6225 assemble_real (r
, mode
, align
);
6229 assemble_integer (exp
, GET_MODE_SIZE (mode
), align
, 1);
6238 /* Return an RTL expression representing the value of the return address
6239 for the frame COUNT steps up from the current frame. FRAME is the
6240 frame pointer of that frame. */
6243 s390_return_addr_rtx (int count
, rtx frame ATTRIBUTE_UNUSED
)
6248 /* Without backchain, we fail for all but the current frame. */
6250 if (!TARGET_BACKCHAIN
&& count
> 0)
6253 /* For the current frame, we need to make sure the initial
6254 value of RETURN_REGNUM is actually saved. */
6258 /* On non-z architectures branch splitting could overwrite r14. */
6259 if (TARGET_CPU_ZARCH
)
6260 return get_hard_reg_initial_val (Pmode
, RETURN_REGNUM
);
6263 cfun_frame_layout
.save_return_addr_p
= true;
6264 return gen_rtx_MEM (Pmode
, return_address_pointer_rtx
);
6268 if (TARGET_PACKED_STACK
)
6269 offset
= -2 * UNITS_PER_WORD
;
6271 offset
= RETURN_REGNUM
* UNITS_PER_WORD
;
6273 addr
= plus_constant (frame
, offset
);
6274 addr
= memory_address (Pmode
, addr
);
6275 return gen_rtx_MEM (Pmode
, addr
);
6278 /* Return an RTL expression representing the back chain stored in
6279 the current stack frame. */
6282 s390_back_chain_rtx (void)
6286 gcc_assert (TARGET_BACKCHAIN
);
6288 if (TARGET_PACKED_STACK
)
6289 chain
= plus_constant (stack_pointer_rtx
,
6290 STACK_POINTER_OFFSET
- UNITS_PER_WORD
);
6292 chain
= stack_pointer_rtx
;
6294 chain
= gen_rtx_MEM (Pmode
, chain
);
6298 /* Find first call clobbered register unused in a function.
6299 This could be used as base register in a leaf function
6300 or for holding the return address before epilogue. */
6303 find_unused_clobbered_reg (void)
6306 for (i
= 0; i
< 6; i
++)
6307 if (!regs_ever_live
[i
])
6313 /* Helper function for s390_regs_ever_clobbered. Sets the fields in DATA for all
6314 clobbered hard regs in SETREG. */
6317 s390_reg_clobbered_rtx (rtx setreg
, rtx set_insn ATTRIBUTE_UNUSED
, void *data
)
6319 int *regs_ever_clobbered
= (int *)data
;
6320 unsigned int i
, regno
;
6321 enum machine_mode mode
= GET_MODE (setreg
);
6323 if (GET_CODE (setreg
) == SUBREG
)
6325 rtx inner
= SUBREG_REG (setreg
);
6326 if (!GENERAL_REG_P (inner
))
6328 regno
= subreg_regno (setreg
);
6330 else if (GENERAL_REG_P (setreg
))
6331 regno
= REGNO (setreg
);
6336 i
< regno
+ HARD_REGNO_NREGS (regno
, mode
);
6338 regs_ever_clobbered
[i
] = 1;
6341 /* Walks through all basic blocks of the current function looking
6342 for clobbered hard regs using s390_reg_clobbered_rtx. The fields
6343 of the passed integer array REGS_EVER_CLOBBERED are set to one for
6344 each of those regs. */
6347 s390_regs_ever_clobbered (int *regs_ever_clobbered
)
6353 memset (regs_ever_clobbered
, 0, 16 * sizeof (int));
6355 /* For non-leaf functions we have to consider all call clobbered regs to be
6357 if (!current_function_is_leaf
)
6359 for (i
= 0; i
< 16; i
++)
6360 regs_ever_clobbered
[i
] = call_really_used_regs
[i
];
6363 /* Make the "magic" eh_return registers live if necessary. For regs_ever_live
6364 this work is done by liveness analysis (mark_regs_live_at_end).
6365 Special care is needed for functions containing landing pads. Landing pads
6366 may use the eh registers, but the code which sets these registers is not
6367 contained in that function. Hence s390_regs_ever_clobbered is not able to
6368 deal with this automatically. */
6369 if (current_function_calls_eh_return
|| cfun
->machine
->has_landing_pad_p
)
6370 for (i
= 0; EH_RETURN_DATA_REGNO (i
) != INVALID_REGNUM
; i
++)
6371 if (current_function_calls_eh_return
6372 || (cfun
->machine
->has_landing_pad_p
6373 && regs_ever_live
[EH_RETURN_DATA_REGNO (i
)]))
6374 regs_ever_clobbered
[EH_RETURN_DATA_REGNO (i
)] = 1;
6376 /* For nonlocal gotos all call-saved registers have to be saved.
6377 This flag is also set for the unwinding code in libgcc.
6378 See expand_builtin_unwind_init. For regs_ever_live this is done by
6380 if (current_function_has_nonlocal_label
)
6381 for (i
= 0; i
< 16; i
++)
6382 if (!call_really_used_regs
[i
])
6383 regs_ever_clobbered
[i
] = 1;
6385 FOR_EACH_BB (cur_bb
)
6387 FOR_BB_INSNS (cur_bb
, cur_insn
)
6389 if (INSN_P (cur_insn
))
6390 note_stores (PATTERN (cur_insn
),
6391 s390_reg_clobbered_rtx
,
6392 regs_ever_clobbered
);
6397 /* Determine the frame area which actually has to be accessed
6398 in the function epilogue. The values are stored at the
6399 given pointers AREA_BOTTOM (address of the lowest used stack
6400 address) and AREA_TOP (address of the first item which does
6401 not belong to the stack frame). */
6404 s390_frame_area (int *area_bottom
, int *area_top
)
6412 if (cfun_frame_layout
.first_restore_gpr
!= -1)
6414 b
= (cfun_frame_layout
.gprs_offset
6415 + cfun_frame_layout
.first_restore_gpr
* UNITS_PER_WORD
);
6416 t
= b
+ (cfun_frame_layout
.last_restore_gpr
6417 - cfun_frame_layout
.first_restore_gpr
+ 1) * UNITS_PER_WORD
;
6420 if (TARGET_64BIT
&& cfun_save_high_fprs_p
)
6422 b
= MIN (b
, cfun_frame_layout
.f8_offset
);
6423 t
= MAX (t
, (cfun_frame_layout
.f8_offset
6424 + cfun_frame_layout
.high_fprs
* 8));
6428 for (i
= 2; i
< 4; i
++)
6429 if (cfun_fpr_bit_p (i
))
6431 b
= MIN (b
, cfun_frame_layout
.f4_offset
+ (i
- 2) * 8);
6432 t
= MAX (t
, cfun_frame_layout
.f4_offset
+ (i
- 1) * 8);
6439 /* Fill cfun->machine with info about register usage of current function.
6440 Return in CLOBBERED_REGS which GPRs are currently considered set. */
6443 s390_register_info (int clobbered_regs
[])
6447 /* fprs 8 - 15 are call saved for 64 Bit ABI. */
6448 cfun_frame_layout
.fpr_bitmap
= 0;
6449 cfun_frame_layout
.high_fprs
= 0;
6451 for (i
= 24; i
< 32; i
++)
6452 if (regs_ever_live
[i
] && !global_regs
[i
])
6454 cfun_set_fpr_bit (i
- 16);
6455 cfun_frame_layout
.high_fprs
++;
6458 /* Find first and last gpr to be saved. We trust regs_ever_live
6459 data, except that we don't save and restore global registers.
6461 Also, all registers with special meaning to the compiler need
6462 to be handled extra. */
6464 s390_regs_ever_clobbered (clobbered_regs
);
6466 for (i
= 0; i
< 16; i
++)
6467 clobbered_regs
[i
] = clobbered_regs
[i
] && !global_regs
[i
] && !fixed_regs
[i
];
6469 if (frame_pointer_needed
)
6470 clobbered_regs
[HARD_FRAME_POINTER_REGNUM
] = 1;
6473 clobbered_regs
[PIC_OFFSET_TABLE_REGNUM
]
6474 |= regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
];
6476 clobbered_regs
[BASE_REGNUM
]
6477 |= (cfun
->machine
->base_reg
6478 && REGNO (cfun
->machine
->base_reg
) == BASE_REGNUM
);
6480 clobbered_regs
[RETURN_REGNUM
]
6481 |= (!current_function_is_leaf
6482 || TARGET_TPF_PROFILING
6483 || cfun
->machine
->split_branches_pending_p
6484 || cfun_frame_layout
.save_return_addr_p
6485 || current_function_calls_eh_return
6486 || current_function_stdarg
);
6488 clobbered_regs
[STACK_POINTER_REGNUM
]
6489 |= (!current_function_is_leaf
6490 || TARGET_TPF_PROFILING
6491 || cfun_save_high_fprs_p
6492 || get_frame_size () > 0
6493 || current_function_calls_alloca
6494 || current_function_stdarg
);
6496 for (i
= 6; i
< 16; i
++)
6497 if (regs_ever_live
[i
] || clobbered_regs
[i
])
6499 for (j
= 15; j
> i
; j
--)
6500 if (regs_ever_live
[j
] || clobbered_regs
[j
])
6505 /* Nothing to save/restore. */
6506 cfun_frame_layout
.first_save_gpr_slot
= -1;
6507 cfun_frame_layout
.last_save_gpr_slot
= -1;
6508 cfun_frame_layout
.first_save_gpr
= -1;
6509 cfun_frame_layout
.first_restore_gpr
= -1;
6510 cfun_frame_layout
.last_save_gpr
= -1;
6511 cfun_frame_layout
.last_restore_gpr
= -1;
6515 /* Save slots for gprs from i to j. */
6516 cfun_frame_layout
.first_save_gpr_slot
= i
;
6517 cfun_frame_layout
.last_save_gpr_slot
= j
;
6519 for (i
= cfun_frame_layout
.first_save_gpr_slot
;
6520 i
< cfun_frame_layout
.last_save_gpr_slot
+ 1;
6522 if (clobbered_regs
[i
])
6525 for (j
= cfun_frame_layout
.last_save_gpr_slot
; j
> i
; j
--)
6526 if (clobbered_regs
[j
])
6529 if (i
== cfun_frame_layout
.last_save_gpr_slot
+ 1)
6531 /* Nothing to save/restore. */
6532 cfun_frame_layout
.first_save_gpr
= -1;
6533 cfun_frame_layout
.first_restore_gpr
= -1;
6534 cfun_frame_layout
.last_save_gpr
= -1;
6535 cfun_frame_layout
.last_restore_gpr
= -1;
6539 /* Save / Restore from gpr i to j. */
6540 cfun_frame_layout
.first_save_gpr
= i
;
6541 cfun_frame_layout
.first_restore_gpr
= i
;
6542 cfun_frame_layout
.last_save_gpr
= j
;
6543 cfun_frame_layout
.last_restore_gpr
= j
;
6547 if (current_function_stdarg
)
6549 /* Varargs functions need to save gprs 2 to 6. */
6550 if (cfun
->va_list_gpr_size
6551 && current_function_args_info
.gprs
< GP_ARG_NUM_REG
)
6553 int min_gpr
= current_function_args_info
.gprs
;
6554 int max_gpr
= min_gpr
+ cfun
->va_list_gpr_size
;
6555 if (max_gpr
> GP_ARG_NUM_REG
)
6556 max_gpr
= GP_ARG_NUM_REG
;
6558 if (cfun_frame_layout
.first_save_gpr
== -1
6559 || cfun_frame_layout
.first_save_gpr
> 2 + min_gpr
)
6561 cfun_frame_layout
.first_save_gpr
= 2 + min_gpr
;
6562 cfun_frame_layout
.first_save_gpr_slot
= 2 + min_gpr
;
6565 if (cfun_frame_layout
.last_save_gpr
== -1
6566 || cfun_frame_layout
.last_save_gpr
< 2 + max_gpr
- 1)
6568 cfun_frame_layout
.last_save_gpr
= 2 + max_gpr
- 1;
6569 cfun_frame_layout
.last_save_gpr_slot
= 2 + max_gpr
- 1;
6573 /* Mark f0, f2 for 31 bit and f0-f4 for 64 bit to be saved. */
6574 if (TARGET_HARD_FLOAT
&& cfun
->va_list_fpr_size
6575 && current_function_args_info
.fprs
< FP_ARG_NUM_REG
)
6577 int min_fpr
= current_function_args_info
.fprs
;
6578 int max_fpr
= min_fpr
+ cfun
->va_list_fpr_size
;
6579 if (max_fpr
> FP_ARG_NUM_REG
)
6580 max_fpr
= FP_ARG_NUM_REG
;
6582 /* ??? This is currently required to ensure proper location
6583 of the fpr save slots within the va_list save area. */
6584 if (TARGET_PACKED_STACK
)
6587 for (i
= min_fpr
; i
< max_fpr
; i
++)
6588 cfun_set_fpr_bit (i
);
6593 for (i
= 2; i
< 4; i
++)
6594 if (regs_ever_live
[i
+ 16] && !global_regs
[i
+ 16])
6595 cfun_set_fpr_bit (i
);
6598 /* Fill cfun->machine with info about frame of current function. */
6601 s390_frame_info (void)
6605 cfun_frame_layout
.frame_size
= get_frame_size ();
6606 if (!TARGET_64BIT
&& cfun_frame_layout
.frame_size
> 0x7fff0000)
6607 fatal_error ("total size of local variables exceeds architecture limit");
6609 if (!TARGET_PACKED_STACK
)
6611 cfun_frame_layout
.backchain_offset
= 0;
6612 cfun_frame_layout
.f0_offset
= 16 * UNITS_PER_WORD
;
6613 cfun_frame_layout
.f4_offset
= cfun_frame_layout
.f0_offset
+ 2 * 8;
6614 cfun_frame_layout
.f8_offset
= -cfun_frame_layout
.high_fprs
* 8;
6615 cfun_frame_layout
.gprs_offset
= (cfun_frame_layout
.first_save_gpr_slot
6618 else if (TARGET_BACKCHAIN
) /* kernel stack layout */
6620 cfun_frame_layout
.backchain_offset
= (STACK_POINTER_OFFSET
6622 cfun_frame_layout
.gprs_offset
6623 = (cfun_frame_layout
.backchain_offset
6624 - (STACK_POINTER_REGNUM
- cfun_frame_layout
.first_save_gpr_slot
+ 1)
6629 cfun_frame_layout
.f4_offset
6630 = (cfun_frame_layout
.gprs_offset
6631 - 8 * (cfun_fpr_bit_p (2) + cfun_fpr_bit_p (3)));
6633 cfun_frame_layout
.f0_offset
6634 = (cfun_frame_layout
.f4_offset
6635 - 8 * (cfun_fpr_bit_p (0) + cfun_fpr_bit_p (1)));
6639 /* On 31 bit we have to care about alignment of the
6640 floating point regs to provide fastest access. */
6641 cfun_frame_layout
.f0_offset
6642 = ((cfun_frame_layout
.gprs_offset
6643 & ~(STACK_BOUNDARY
/ BITS_PER_UNIT
- 1))
6644 - 8 * (cfun_fpr_bit_p (0) + cfun_fpr_bit_p (1)));
6646 cfun_frame_layout
.f4_offset
6647 = (cfun_frame_layout
.f0_offset
6648 - 8 * (cfun_fpr_bit_p (2) + cfun_fpr_bit_p (3)));
6651 else /* no backchain */
6653 cfun_frame_layout
.f4_offset
6654 = (STACK_POINTER_OFFSET
6655 - 8 * (cfun_fpr_bit_p (2) + cfun_fpr_bit_p (3)));
6657 cfun_frame_layout
.f0_offset
6658 = (cfun_frame_layout
.f4_offset
6659 - 8 * (cfun_fpr_bit_p (0) + cfun_fpr_bit_p (1)));
6661 cfun_frame_layout
.gprs_offset
6662 = cfun_frame_layout
.f0_offset
- cfun_gprs_save_area_size
;
6665 if (current_function_is_leaf
6666 && !TARGET_TPF_PROFILING
6667 && cfun_frame_layout
.frame_size
== 0
6668 && !cfun_save_high_fprs_p
6669 && !current_function_calls_alloca
6670 && !current_function_stdarg
)
6673 if (!TARGET_PACKED_STACK
)
6674 cfun_frame_layout
.frame_size
+= (STACK_POINTER_OFFSET
6675 + current_function_outgoing_args_size
6676 + cfun_frame_layout
.high_fprs
* 8);
6679 if (TARGET_BACKCHAIN
)
6680 cfun_frame_layout
.frame_size
+= UNITS_PER_WORD
;
6682 /* No alignment trouble here because f8-f15 are only saved under
6684 cfun_frame_layout
.f8_offset
= (MIN (MIN (cfun_frame_layout
.f0_offset
,
6685 cfun_frame_layout
.f4_offset
),
6686 cfun_frame_layout
.gprs_offset
)
6687 - cfun_frame_layout
.high_fprs
* 8);
6689 cfun_frame_layout
.frame_size
+= cfun_frame_layout
.high_fprs
* 8;
6691 for (i
= 0; i
< 8; i
++)
6692 if (cfun_fpr_bit_p (i
))
6693 cfun_frame_layout
.frame_size
+= 8;
6695 cfun_frame_layout
.frame_size
+= cfun_gprs_save_area_size
;
6697 /* If under 31 bit an odd number of gprs has to be saved we have to adjust
6698 the frame size to sustain 8 byte alignment of stack frames. */
6699 cfun_frame_layout
.frame_size
= ((cfun_frame_layout
.frame_size
+
6700 STACK_BOUNDARY
/ BITS_PER_UNIT
- 1)
6701 & ~(STACK_BOUNDARY
/ BITS_PER_UNIT
- 1));
6703 cfun_frame_layout
.frame_size
+= current_function_outgoing_args_size
;
6707 /* Generate frame layout. Fills in register and frame data for the current
6708 function in cfun->machine. This routine can be called multiple times;
6709 it will re-do the complete frame layout every time. */
6712 s390_init_frame_layout (void)
6714 HOST_WIDE_INT frame_size
;
6716 int clobbered_regs
[16];
6718 /* On S/390 machines, we may need to perform branch splitting, which
6719 will require both base and return address register. We have no
6720 choice but to assume we're going to need them until right at the
6721 end of the machine dependent reorg phase. */
6722 if (!TARGET_CPU_ZARCH
)
6723 cfun
->machine
->split_branches_pending_p
= true;
6727 frame_size
= cfun_frame_layout
.frame_size
;
6729 /* Try to predict whether we'll need the base register. */
6730 base_used
= cfun
->machine
->split_branches_pending_p
6731 || current_function_uses_const_pool
6732 || (!DISP_IN_RANGE (-frame_size
)
6733 && !CONST_OK_FOR_K (-frame_size
));
6735 /* Decide which register to use as literal pool base. In small
6736 leaf functions, try to use an unused call-clobbered register
6737 as base register to avoid save/restore overhead. */
6739 cfun
->machine
->base_reg
= NULL_RTX
;
6740 else if (current_function_is_leaf
&& !regs_ever_live
[5])
6741 cfun
->machine
->base_reg
= gen_rtx_REG (Pmode
, 5);
6743 cfun
->machine
->base_reg
= gen_rtx_REG (Pmode
, BASE_REGNUM
);
6745 s390_register_info (clobbered_regs
);
6748 while (frame_size
!= cfun_frame_layout
.frame_size
);
6751 /* Update frame layout. Recompute actual register save data based on
6752 current info and update regs_ever_live for the special registers.
6753 May be called multiple times, but may never cause *more* registers
6754 to be saved than s390_init_frame_layout allocated room for. */
6757 s390_update_frame_layout (void)
6759 int clobbered_regs
[16];
6761 s390_register_info (clobbered_regs
);
6763 regs_ever_live
[BASE_REGNUM
] = clobbered_regs
[BASE_REGNUM
];
6764 regs_ever_live
[RETURN_REGNUM
] = clobbered_regs
[RETURN_REGNUM
];
6765 regs_ever_live
[STACK_POINTER_REGNUM
] = clobbered_regs
[STACK_POINTER_REGNUM
];
6767 if (cfun
->machine
->base_reg
)
6768 regs_ever_live
[REGNO (cfun
->machine
->base_reg
)] = 1;
6771 /* Return true if it is legal to put a value with MODE into REGNO. */
6774 s390_hard_regno_mode_ok (unsigned int regno
, enum machine_mode mode
)
6776 switch (REGNO_REG_CLASS (regno
))
6779 if (REGNO_PAIR_OK (regno
, mode
))
6781 if (mode
== SImode
|| mode
== DImode
)
6784 if (FLOAT_MODE_P (mode
) && GET_MODE_CLASS (mode
) != MODE_VECTOR_FLOAT
)
6789 if (FRAME_REGNO_P (regno
) && mode
== Pmode
)
6794 if (REGNO_PAIR_OK (regno
, mode
))
6797 || (mode
!= TFmode
&& mode
!= TCmode
&& mode
!= TDmode
))
6802 if (GET_MODE_CLASS (mode
) == MODE_CC
)
6806 if (REGNO_PAIR_OK (regno
, mode
))
6808 if (mode
== SImode
|| mode
== Pmode
)
6819 /* Return nonzero if register OLD_REG can be renamed to register NEW_REG. */
6822 s390_hard_regno_rename_ok (unsigned int old_reg
, unsigned int new_reg
)
6824 /* Once we've decided upon a register to use as base register, it must
6825 no longer be used for any other purpose. */
6826 if (cfun
->machine
->base_reg
)
6827 if (REGNO (cfun
->machine
->base_reg
) == old_reg
6828 || REGNO (cfun
->machine
->base_reg
) == new_reg
)
6834 /* Maximum number of registers to represent a value of mode MODE
6835 in a register of class CLASS. */
6838 s390_class_max_nregs (enum reg_class
class, enum machine_mode mode
)
6843 if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
)
6844 return 2 * ((GET_MODE_SIZE (mode
) / 2 + 8 - 1) / 8);
6846 return (GET_MODE_SIZE (mode
) + 8 - 1) / 8;
6848 return (GET_MODE_SIZE (mode
) + 4 - 1) / 4;
6852 return (GET_MODE_SIZE (mode
) + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
6855 /* Return true if register FROM can be eliminated via register TO. */
6858 s390_can_eliminate (int from
, int to
)
6860 /* On zSeries machines, we have not marked the base register as fixed.
6861 Instead, we have an elimination rule BASE_REGNUM -> BASE_REGNUM.
6862 If a function requires the base register, we say here that this
6863 elimination cannot be performed. This will cause reload to free
6864 up the base register (as if it were fixed). On the other hand,
6865 if the current function does *not* require the base register, we
6866 say here the elimination succeeds, which in turn allows reload
6867 to allocate the base register for any other purpose. */
6868 if (from
== BASE_REGNUM
&& to
== BASE_REGNUM
)
6870 if (TARGET_CPU_ZARCH
)
6872 s390_init_frame_layout ();
6873 return cfun
->machine
->base_reg
== NULL_RTX
;
6879 /* Everything else must point into the stack frame. */
6880 gcc_assert (to
== STACK_POINTER_REGNUM
6881 || to
== HARD_FRAME_POINTER_REGNUM
);
6883 gcc_assert (from
== FRAME_POINTER_REGNUM
6884 || from
== ARG_POINTER_REGNUM
6885 || from
== RETURN_ADDRESS_POINTER_REGNUM
);
6887 /* Make sure we actually saved the return address. */
6888 if (from
== RETURN_ADDRESS_POINTER_REGNUM
)
6889 if (!current_function_calls_eh_return
6890 && !current_function_stdarg
6891 && !cfun_frame_layout
.save_return_addr_p
)
6897 /* Return offset between register FROM and TO initially after prolog. */
6900 s390_initial_elimination_offset (int from
, int to
)
6902 HOST_WIDE_INT offset
;
6905 /* ??? Why are we called for non-eliminable pairs? */
6906 if (!s390_can_eliminate (from
, to
))
6911 case FRAME_POINTER_REGNUM
:
6912 offset
= (get_frame_size()
6913 + STACK_POINTER_OFFSET
6914 + current_function_outgoing_args_size
);
6917 case ARG_POINTER_REGNUM
:
6918 s390_init_frame_layout ();
6919 offset
= cfun_frame_layout
.frame_size
+ STACK_POINTER_OFFSET
;
6922 case RETURN_ADDRESS_POINTER_REGNUM
:
6923 s390_init_frame_layout ();
6924 index
= RETURN_REGNUM
- cfun_frame_layout
.first_save_gpr_slot
;
6925 gcc_assert (index
>= 0);
6926 offset
= cfun_frame_layout
.frame_size
+ cfun_frame_layout
.gprs_offset
;
6927 offset
+= index
* UNITS_PER_WORD
;
6941 /* Emit insn to save fpr REGNUM at offset OFFSET relative
6942 to register BASE. Return generated insn. */
6945 save_fpr (rtx base
, int offset
, int regnum
)
6948 addr
= gen_rtx_MEM (DFmode
, plus_constant (base
, offset
));
6950 if (regnum
>= 16 && regnum
<= (16 + FP_ARG_NUM_REG
))
6951 set_mem_alias_set (addr
, get_varargs_alias_set ());
6953 set_mem_alias_set (addr
, get_frame_alias_set ());
6955 return emit_move_insn (addr
, gen_rtx_REG (DFmode
, regnum
));
6958 /* Emit insn to restore fpr REGNUM from offset OFFSET relative
6959 to register BASE. Return generated insn. */
6962 restore_fpr (rtx base
, int offset
, int regnum
)
6965 addr
= gen_rtx_MEM (DFmode
, plus_constant (base
, offset
));
6966 set_mem_alias_set (addr
, get_frame_alias_set ());
6968 return emit_move_insn (gen_rtx_REG (DFmode
, regnum
), addr
);
6971 /* Generate insn to save registers FIRST to LAST into
6972 the register save area located at offset OFFSET
6973 relative to register BASE. */
6976 save_gprs (rtx base
, int offset
, int first
, int last
)
6978 rtx addr
, insn
, note
;
6981 addr
= plus_constant (base
, offset
);
6982 addr
= gen_rtx_MEM (Pmode
, addr
);
6984 set_mem_alias_set (addr
, get_frame_alias_set ());
6986 /* Special-case single register. */
6990 insn
= gen_movdi (addr
, gen_rtx_REG (Pmode
, first
));
6992 insn
= gen_movsi (addr
, gen_rtx_REG (Pmode
, first
));
6994 RTX_FRAME_RELATED_P (insn
) = 1;
6999 insn
= gen_store_multiple (addr
,
7000 gen_rtx_REG (Pmode
, first
),
7001 GEN_INT (last
- first
+ 1));
7003 if (first
<= 6 && current_function_stdarg
)
7004 for (i
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
7006 rtx mem
= XEXP (XVECEXP (PATTERN (insn
), 0, i
), 0);
7009 set_mem_alias_set (mem
, get_varargs_alias_set ());
7012 /* We need to set the FRAME_RELATED flag on all SETs
7013 inside the store-multiple pattern.
7015 However, we must not emit DWARF records for registers 2..5
7016 if they are stored for use by variable arguments ...
7018 ??? Unfortunately, it is not enough to simply not the
7019 FRAME_RELATED flags for those SETs, because the first SET
7020 of the PARALLEL is always treated as if it had the flag
7021 set, even if it does not. Therefore we emit a new pattern
7022 without those registers as REG_FRAME_RELATED_EXPR note. */
7026 rtx pat
= PATTERN (insn
);
7028 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
7029 if (GET_CODE (XVECEXP (pat
, 0, i
)) == SET
)
7030 RTX_FRAME_RELATED_P (XVECEXP (pat
, 0, i
)) = 1;
7032 RTX_FRAME_RELATED_P (insn
) = 1;
7036 addr
= plus_constant (base
, offset
+ (6 - first
) * UNITS_PER_WORD
);
7037 note
= gen_store_multiple (gen_rtx_MEM (Pmode
, addr
),
7038 gen_rtx_REG (Pmode
, 6),
7039 GEN_INT (last
- 6 + 1));
7040 note
= PATTERN (note
);
7043 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR
,
7044 note
, REG_NOTES (insn
));
7046 for (i
= 0; i
< XVECLEN (note
, 0); i
++)
7047 if (GET_CODE (XVECEXP (note
, 0, i
)) == SET
)
7048 RTX_FRAME_RELATED_P (XVECEXP (note
, 0, i
)) = 1;
7050 RTX_FRAME_RELATED_P (insn
) = 1;
7056 /* Generate insn to restore registers FIRST to LAST from
7057 the register save area located at offset OFFSET
7058 relative to register BASE. */
7061 restore_gprs (rtx base
, int offset
, int first
, int last
)
7065 addr
= plus_constant (base
, offset
);
7066 addr
= gen_rtx_MEM (Pmode
, addr
);
7067 set_mem_alias_set (addr
, get_frame_alias_set ());
7069 /* Special-case single register. */
7073 insn
= gen_movdi (gen_rtx_REG (Pmode
, first
), addr
);
7075 insn
= gen_movsi (gen_rtx_REG (Pmode
, first
), addr
);
7080 insn
= gen_load_multiple (gen_rtx_REG (Pmode
, first
),
7082 GEN_INT (last
- first
+ 1));
7086 /* Return insn sequence to load the GOT register. */
7088 static GTY(()) rtx got_symbol
;
7090 s390_load_got (void)
7096 got_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "_GLOBAL_OFFSET_TABLE_");
7097 SYMBOL_REF_FLAGS (got_symbol
) = SYMBOL_FLAG_LOCAL
;
7102 if (TARGET_CPU_ZARCH
)
7104 emit_move_insn (pic_offset_table_rtx
, got_symbol
);
7110 offset
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, got_symbol
),
7111 UNSPEC_LTREL_OFFSET
);
7112 offset
= gen_rtx_CONST (Pmode
, offset
);
7113 offset
= force_const_mem (Pmode
, offset
);
7115 emit_move_insn (pic_offset_table_rtx
, offset
);
7117 offset
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, XEXP (offset
, 0)),
7119 offset
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, offset
);
7121 emit_move_insn (pic_offset_table_rtx
, offset
);
7124 insns
= get_insns ();
7129 /* Expand the prologue into a bunch of separate insns. */
7132 s390_emit_prologue (void)
7140 /* Complete frame layout. */
7142 s390_update_frame_layout ();
7144 /* Annotate all constant pool references to let the scheduler know
7145 they implicitly use the base register. */
7147 push_topmost_sequence ();
7149 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
7151 annotate_constant_pool_refs (&PATTERN (insn
));
7153 pop_topmost_sequence ();
7155 /* Choose best register to use for temp use within prologue.
7156 See below for why TPF must use the register 1. */
7158 if (!has_hard_reg_initial_val (Pmode
, RETURN_REGNUM
)
7159 && !current_function_is_leaf
7160 && !TARGET_TPF_PROFILING
)
7161 temp_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
7163 temp_reg
= gen_rtx_REG (Pmode
, 1);
7165 /* Save call saved gprs. */
7166 if (cfun_frame_layout
.first_save_gpr
!= -1)
7168 insn
= save_gprs (stack_pointer_rtx
,
7169 cfun_frame_layout
.gprs_offset
+
7170 UNITS_PER_WORD
* (cfun_frame_layout
.first_save_gpr
7171 - cfun_frame_layout
.first_save_gpr_slot
),
7172 cfun_frame_layout
.first_save_gpr
,
7173 cfun_frame_layout
.last_save_gpr
);
7177 /* Dummy insn to mark literal pool slot. */
7179 if (cfun
->machine
->base_reg
)
7180 emit_insn (gen_main_pool (cfun
->machine
->base_reg
));
7182 offset
= cfun_frame_layout
.f0_offset
;
7184 /* Save f0 and f2. */
7185 for (i
= 0; i
< 2; i
++)
7187 if (cfun_fpr_bit_p (i
))
7189 save_fpr (stack_pointer_rtx
, offset
, i
+ 16);
7192 else if (!TARGET_PACKED_STACK
)
7196 /* Save f4 and f6. */
7197 offset
= cfun_frame_layout
.f4_offset
;
7198 for (i
= 2; i
< 4; i
++)
7200 if (cfun_fpr_bit_p (i
))
7202 insn
= save_fpr (stack_pointer_rtx
, offset
, i
+ 16);
7205 /* If f4 and f6 are call clobbered they are saved due to stdargs and
7206 therefore are not frame related. */
7207 if (!call_really_used_regs
[i
+ 16])
7208 RTX_FRAME_RELATED_P (insn
) = 1;
7210 else if (!TARGET_PACKED_STACK
)
7214 if (TARGET_PACKED_STACK
7215 && cfun_save_high_fprs_p
7216 && cfun_frame_layout
.f8_offset
+ cfun_frame_layout
.high_fprs
* 8 > 0)
7218 offset
= (cfun_frame_layout
.f8_offset
7219 + (cfun_frame_layout
.high_fprs
- 1) * 8);
7221 for (i
= 15; i
> 7 && offset
>= 0; i
--)
7222 if (cfun_fpr_bit_p (i
))
7224 insn
= save_fpr (stack_pointer_rtx
, offset
, i
+ 16);
7226 RTX_FRAME_RELATED_P (insn
) = 1;
7229 if (offset
>= cfun_frame_layout
.f8_offset
)
7233 if (!TARGET_PACKED_STACK
)
7234 next_fpr
= cfun_save_high_fprs_p
? 31 : 0;
7236 /* Decrement stack pointer. */
7238 if (cfun_frame_layout
.frame_size
> 0)
7240 rtx frame_off
= GEN_INT (-cfun_frame_layout
.frame_size
);
7242 if (s390_stack_size
)
7244 HOST_WIDE_INT stack_check_mask
= ((s390_stack_size
- 1)
7245 & ~(s390_stack_guard
- 1));
7246 rtx t
= gen_rtx_AND (Pmode
, stack_pointer_rtx
,
7247 GEN_INT (stack_check_mask
));
7250 gen_cmpdi (t
, const0_rtx
);
7252 gen_cmpsi (t
, const0_rtx
);
7254 emit_insn (gen_conditional_trap (gen_rtx_EQ (CCmode
,
7255 gen_rtx_REG (CCmode
,
7261 if (s390_warn_framesize
> 0
7262 && cfun_frame_layout
.frame_size
>= s390_warn_framesize
)
7263 warning (0, "frame size of %qs is " HOST_WIDE_INT_PRINT_DEC
" bytes",
7264 current_function_name (), cfun_frame_layout
.frame_size
);
7266 if (s390_warn_dynamicstack_p
&& cfun
->calls_alloca
)
7267 warning (0, "%qs uses dynamic stack allocation", current_function_name ());
7269 /* Save incoming stack pointer into temp reg. */
7270 if (TARGET_BACKCHAIN
|| next_fpr
)
7271 insn
= emit_insn (gen_move_insn (temp_reg
, stack_pointer_rtx
));
7273 /* Subtract frame size from stack pointer. */
7275 if (DISP_IN_RANGE (INTVAL (frame_off
)))
7277 insn
= gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
7278 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
7280 insn
= emit_insn (insn
);
7284 if (!CONST_OK_FOR_K (INTVAL (frame_off
)))
7285 frame_off
= force_const_mem (Pmode
, frame_off
);
7287 insn
= emit_insn (gen_add2_insn (stack_pointer_rtx
, frame_off
));
7288 annotate_constant_pool_refs (&PATTERN (insn
));
7291 RTX_FRAME_RELATED_P (insn
) = 1;
7293 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR
,
7294 gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
7295 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
7296 GEN_INT (-cfun_frame_layout
.frame_size
))),
7299 /* Set backchain. */
7301 if (TARGET_BACKCHAIN
)
7303 if (cfun_frame_layout
.backchain_offset
)
7304 addr
= gen_rtx_MEM (Pmode
,
7305 plus_constant (stack_pointer_rtx
,
7306 cfun_frame_layout
.backchain_offset
));
7308 addr
= gen_rtx_MEM (Pmode
, stack_pointer_rtx
);
7309 set_mem_alias_set (addr
, get_frame_alias_set ());
7310 insn
= emit_insn (gen_move_insn (addr
, temp_reg
));
7313 /* If we support asynchronous exceptions (e.g. for Java),
7314 we need to make sure the backchain pointer is set up
7315 before any possibly trapping memory access. */
7317 if (TARGET_BACKCHAIN
&& flag_non_call_exceptions
)
7319 addr
= gen_rtx_MEM (BLKmode
, gen_rtx_SCRATCH (VOIDmode
));
7320 emit_insn (gen_rtx_CLOBBER (VOIDmode
, addr
));
7324 /* Save fprs 8 - 15 (64 bit ABI). */
7326 if (cfun_save_high_fprs_p
&& next_fpr
)
7328 insn
= emit_insn (gen_add2_insn (temp_reg
,
7329 GEN_INT (cfun_frame_layout
.f8_offset
)));
7333 for (i
= 24; i
<= next_fpr
; i
++)
7334 if (cfun_fpr_bit_p (i
- 16))
7336 rtx addr
= plus_constant (stack_pointer_rtx
,
7337 cfun_frame_layout
.frame_size
7338 + cfun_frame_layout
.f8_offset
7341 insn
= save_fpr (temp_reg
, offset
, i
);
7343 RTX_FRAME_RELATED_P (insn
) = 1;
7345 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR
,
7346 gen_rtx_SET (VOIDmode
,
7347 gen_rtx_MEM (DFmode
, addr
),
7348 gen_rtx_REG (DFmode
, i
)),
7353 /* Set frame pointer, if needed. */
7355 if (frame_pointer_needed
)
7357 insn
= emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
);
7358 RTX_FRAME_RELATED_P (insn
) = 1;
7361 /* Set up got pointer, if needed. */
7363 if (flag_pic
&& regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
])
7365 rtx insns
= s390_load_got ();
7367 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
7369 annotate_constant_pool_refs (&PATTERN (insn
));
7371 REG_NOTES (insn
) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD
, NULL_RTX
,
7378 if (TARGET_TPF_PROFILING
)
7380 /* Generate a BAS instruction to serve as a function
7381 entry intercept to facilitate the use of tracing
7382 algorithms located at the branch target. */
7383 emit_insn (gen_prologue_tpf ());
7385 /* Emit a blockage here so that all code
7386 lies between the profiling mechanisms. */
7387 emit_insn (gen_blockage ());
7391 /* Expand the epilogue into a bunch of separate insns. */
7394 s390_emit_epilogue (bool sibcall
)
7396 rtx frame_pointer
, return_reg
;
7397 int area_bottom
, area_top
, offset
= 0;
7402 if (TARGET_TPF_PROFILING
)
7405 /* Generate a BAS instruction to serve as a function
7406 entry intercept to facilitate the use of tracing
7407 algorithms located at the branch target. */
7409 /* Emit a blockage here so that all code
7410 lies between the profiling mechanisms. */
7411 emit_insn (gen_blockage ());
7413 emit_insn (gen_epilogue_tpf ());
7416 /* Check whether to use frame or stack pointer for restore. */
7418 frame_pointer
= (frame_pointer_needed
7419 ? hard_frame_pointer_rtx
: stack_pointer_rtx
);
7421 s390_frame_area (&area_bottom
, &area_top
);
7423 /* Check whether we can access the register save area.
7424 If not, increment the frame pointer as required. */
7426 if (area_top
<= area_bottom
)
7428 /* Nothing to restore. */
7430 else if (DISP_IN_RANGE (cfun_frame_layout
.frame_size
+ area_bottom
)
7431 && DISP_IN_RANGE (cfun_frame_layout
.frame_size
+ area_top
- 1))
7433 /* Area is in range. */
7434 offset
= cfun_frame_layout
.frame_size
;
7438 rtx insn
, frame_off
;
7440 offset
= area_bottom
< 0 ? -area_bottom
: 0;
7441 frame_off
= GEN_INT (cfun_frame_layout
.frame_size
- offset
);
7443 if (DISP_IN_RANGE (INTVAL (frame_off
)))
7445 insn
= gen_rtx_SET (VOIDmode
, frame_pointer
,
7446 gen_rtx_PLUS (Pmode
, frame_pointer
, frame_off
));
7447 insn
= emit_insn (insn
);
7451 if (!CONST_OK_FOR_K (INTVAL (frame_off
)))
7452 frame_off
= force_const_mem (Pmode
, frame_off
);
7454 insn
= emit_insn (gen_add2_insn (frame_pointer
, frame_off
));
7455 annotate_constant_pool_refs (&PATTERN (insn
));
7459 /* Restore call saved fprs. */
7463 if (cfun_save_high_fprs_p
)
7465 next_offset
= cfun_frame_layout
.f8_offset
;
7466 for (i
= 24; i
< 32; i
++)
7468 if (cfun_fpr_bit_p (i
- 16))
7470 restore_fpr (frame_pointer
,
7471 offset
+ next_offset
, i
);
7480 next_offset
= cfun_frame_layout
.f4_offset
;
7481 for (i
= 18; i
< 20; i
++)
7483 if (cfun_fpr_bit_p (i
- 16))
7485 restore_fpr (frame_pointer
,
7486 offset
+ next_offset
, i
);
7489 else if (!TARGET_PACKED_STACK
)
7495 /* Return register. */
7497 return_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
7499 /* Restore call saved gprs. */
7501 if (cfun_frame_layout
.first_restore_gpr
!= -1)
7506 /* Check for global register and save them
7507 to stack location from where they get restored. */
7509 for (i
= cfun_frame_layout
.first_restore_gpr
;
7510 i
<= cfun_frame_layout
.last_restore_gpr
;
7513 /* These registers are special and need to be
7514 restored in any case. */
7515 if (i
== STACK_POINTER_REGNUM
7516 || i
== RETURN_REGNUM
7518 || (flag_pic
&& i
== (int)PIC_OFFSET_TABLE_REGNUM
))
7523 addr
= plus_constant (frame_pointer
,
7524 offset
+ cfun_frame_layout
.gprs_offset
7525 + (i
- cfun_frame_layout
.first_save_gpr_slot
)
7527 addr
= gen_rtx_MEM (Pmode
, addr
);
7528 set_mem_alias_set (addr
, get_frame_alias_set ());
7529 emit_move_insn (addr
, gen_rtx_REG (Pmode
, i
));
7535 /* Fetch return address from stack before load multiple,
7536 this will do good for scheduling. */
7538 if (cfun_frame_layout
.save_return_addr_p
7539 || (cfun_frame_layout
.first_restore_gpr
< BASE_REGNUM
7540 && cfun_frame_layout
.last_restore_gpr
> RETURN_REGNUM
))
7542 int return_regnum
= find_unused_clobbered_reg();
7545 return_reg
= gen_rtx_REG (Pmode
, return_regnum
);
7547 addr
= plus_constant (frame_pointer
,
7548 offset
+ cfun_frame_layout
.gprs_offset
7550 - cfun_frame_layout
.first_save_gpr_slot
)
7552 addr
= gen_rtx_MEM (Pmode
, addr
);
7553 set_mem_alias_set (addr
, get_frame_alias_set ());
7554 emit_move_insn (return_reg
, addr
);
7558 insn
= restore_gprs (frame_pointer
,
7559 offset
+ cfun_frame_layout
.gprs_offset
7560 + (cfun_frame_layout
.first_restore_gpr
7561 - cfun_frame_layout
.first_save_gpr_slot
)
7563 cfun_frame_layout
.first_restore_gpr
,
7564 cfun_frame_layout
.last_restore_gpr
);
7571 /* Return to caller. */
7573 p
= rtvec_alloc (2);
7575 RTVEC_ELT (p
, 0) = gen_rtx_RETURN (VOIDmode
);
7576 RTVEC_ELT (p
, 1) = gen_rtx_USE (VOIDmode
, return_reg
);
7577 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
7582 /* Return the size in bytes of a function argument of
7583 type TYPE and/or mode MODE. At least one of TYPE or
7584 MODE must be specified. */
7587 s390_function_arg_size (enum machine_mode mode
, tree type
)
7590 return int_size_in_bytes (type
);
7592 /* No type info available for some library calls ... */
7593 if (mode
!= BLKmode
)
7594 return GET_MODE_SIZE (mode
);
7596 /* If we have neither type nor mode, abort */
7600 /* Return true if a function argument of type TYPE and mode MODE
7601 is to be passed in a floating-point register, if available. */
7604 s390_function_arg_float (enum machine_mode mode
, tree type
)
7606 int size
= s390_function_arg_size (mode
, type
);
7610 /* Soft-float changes the ABI: no floating-point registers are used. */
7611 if (TARGET_SOFT_FLOAT
)
7614 /* No type info available for some library calls ... */
7616 return mode
== SFmode
|| mode
== DFmode
|| mode
== SDmode
|| mode
== DDmode
;
7618 /* The ABI says that record types with a single member are treated
7619 just like that member would be. */
7620 while (TREE_CODE (type
) == RECORD_TYPE
)
7622 tree field
, single
= NULL_TREE
;
7624 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
7626 if (TREE_CODE (field
) != FIELD_DECL
)
7629 if (single
== NULL_TREE
)
7630 single
= TREE_TYPE (field
);
7635 if (single
== NULL_TREE
)
7641 return TREE_CODE (type
) == REAL_TYPE
;
7644 /* Return true if a function argument of type TYPE and mode MODE
7645 is to be passed in an integer register, or a pair of integer
7646 registers, if available. */
7649 s390_function_arg_integer (enum machine_mode mode
, tree type
)
7651 int size
= s390_function_arg_size (mode
, type
);
7655 /* No type info available for some library calls ... */
7657 return GET_MODE_CLASS (mode
) == MODE_INT
7658 || (TARGET_SOFT_FLOAT
&& SCALAR_FLOAT_MODE_P (mode
));
7660 /* We accept small integral (and similar) types. */
7661 if (INTEGRAL_TYPE_P (type
)
7662 || POINTER_TYPE_P (type
)
7663 || TREE_CODE (type
) == OFFSET_TYPE
7664 || (TARGET_SOFT_FLOAT
&& TREE_CODE (type
) == REAL_TYPE
))
7667 /* We also accept structs of size 1, 2, 4, 8 that are not
7668 passed in floating-point registers. */
7669 if (AGGREGATE_TYPE_P (type
)
7670 && exact_log2 (size
) >= 0
7671 && !s390_function_arg_float (mode
, type
))
7677 /* Return 1 if a function argument of type TYPE and mode MODE
7678 is to be passed by reference. The ABI specifies that only
7679 structures of size 1, 2, 4, or 8 bytes are passed by value,
7680 all other structures (and complex numbers) are passed by
7684 s390_pass_by_reference (CUMULATIVE_ARGS
*ca ATTRIBUTE_UNUSED
,
7685 enum machine_mode mode
, tree type
,
7686 bool named ATTRIBUTE_UNUSED
)
7688 int size
= s390_function_arg_size (mode
, type
);
7694 if (AGGREGATE_TYPE_P (type
) && exact_log2 (size
) < 0)
7697 if (TREE_CODE (type
) == COMPLEX_TYPE
7698 || TREE_CODE (type
) == VECTOR_TYPE
)
7705 /* Update the data in CUM to advance over an argument of mode MODE and
7706 data type TYPE. (TYPE is null for libcalls where that information
7707 may not be available.). The boolean NAMED specifies whether the
7708 argument is a named argument (as opposed to an unnamed argument
7709 matching an ellipsis). */
7712 s390_function_arg_advance (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
,
7713 tree type
, int named ATTRIBUTE_UNUSED
)
7715 if (s390_function_arg_float (mode
, type
))
7719 else if (s390_function_arg_integer (mode
, type
))
7721 int size
= s390_function_arg_size (mode
, type
);
7722 cum
->gprs
+= ((size
+ UNITS_PER_WORD
-1) / UNITS_PER_WORD
);
7728 /* Define where to put the arguments to a function.
7729 Value is zero to push the argument on the stack,
7730 or a hard register in which to store the argument.
7732 MODE is the argument's machine mode.
7733 TYPE is the data type of the argument (as a tree).
7734 This is null for libcalls where that information may
7736 CUM is a variable of type CUMULATIVE_ARGS which gives info about
7737 the preceding args and about the function being called.
7738 NAMED is nonzero if this argument is a named parameter
7739 (otherwise it is an extra parameter matching an ellipsis).
7741 On S/390, we use general purpose registers 2 through 6 to
7742 pass integer, pointer, and certain structure arguments, and
7743 floating point registers 0 and 2 (0, 2, 4, and 6 on 64-bit)
7744 to pass floating point arguments. All remaining arguments
7745 are pushed to the stack. */
7748 s390_function_arg (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
, tree type
,
7749 int named ATTRIBUTE_UNUSED
)
7751 if (s390_function_arg_float (mode
, type
))
7753 if (cum
->fprs
+ 1 > FP_ARG_NUM_REG
)
7756 return gen_rtx_REG (mode
, cum
->fprs
+ 16);
7758 else if (s390_function_arg_integer (mode
, type
))
7760 int size
= s390_function_arg_size (mode
, type
);
7761 int n_gprs
= (size
+ UNITS_PER_WORD
-1) / UNITS_PER_WORD
;
7763 if (cum
->gprs
+ n_gprs
> GP_ARG_NUM_REG
)
7766 return gen_rtx_REG (mode
, cum
->gprs
+ 2);
7769 /* After the real arguments, expand_call calls us once again
7770 with a void_type_node type. Whatever we return here is
7771 passed as operand 2 to the call expanders.
7773 We don't need this feature ... */
7774 else if (type
== void_type_node
)
7780 /* Return true if return values of type TYPE should be returned
7781 in a memory buffer whose address is passed by the caller as
7782 hidden first argument. */
7785 s390_return_in_memory (tree type
, tree fundecl ATTRIBUTE_UNUSED
)
7787 /* We accept small integral (and similar) types. */
7788 if (INTEGRAL_TYPE_P (type
)
7789 || POINTER_TYPE_P (type
)
7790 || TREE_CODE (type
) == OFFSET_TYPE
7791 || TREE_CODE (type
) == REAL_TYPE
)
7792 return int_size_in_bytes (type
) > 8;
7794 /* Aggregates and similar constructs are always returned
7796 if (AGGREGATE_TYPE_P (type
)
7797 || TREE_CODE (type
) == COMPLEX_TYPE
7798 || TREE_CODE (type
) == VECTOR_TYPE
)
7801 /* ??? We get called on all sorts of random stuff from
7802 aggregate_value_p. We can't abort, but it's not clear
7803 what's safe to return. Pretend it's a struct I guess. */
7807 /* Define where to return a (scalar) value of type TYPE.
7808 If TYPE is null, define where to return a (scalar)
7809 value of mode MODE from a libcall. */
7812 s390_function_value (tree type
, enum machine_mode mode
)
7816 int unsignedp
= TYPE_UNSIGNED (type
);
7817 mode
= promote_mode (type
, TYPE_MODE (type
), &unsignedp
, 1);
7820 gcc_assert (GET_MODE_CLASS (mode
) == MODE_INT
|| SCALAR_FLOAT_MODE_P (mode
));
7821 gcc_assert (GET_MODE_SIZE (mode
) <= 8);
7823 if (TARGET_HARD_FLOAT
&& SCALAR_FLOAT_MODE_P (mode
))
7824 return gen_rtx_REG (mode
, 16);
7826 return gen_rtx_REG (mode
, 2);
7830 /* Create and return the va_list datatype.
7832 On S/390, va_list is an array type equivalent to
7834 typedef struct __va_list_tag
7838 void *__overflow_arg_area;
7839 void *__reg_save_area;
7842 where __gpr and __fpr hold the number of general purpose
7843 or floating point arguments used up to now, respectively,
7844 __overflow_arg_area points to the stack location of the
7845 next argument passed on the stack, and __reg_save_area
7846 always points to the start of the register area in the
7847 call frame of the current function. The function prologue
7848 saves all registers used for argument passing into this
7849 area if the function uses variable arguments. */
7852 s390_build_builtin_va_list (void)
7854 tree f_gpr
, f_fpr
, f_ovf
, f_sav
, record
, type_decl
;
7856 record
= lang_hooks
.types
.make_type (RECORD_TYPE
);
7859 build_decl (TYPE_DECL
, get_identifier ("__va_list_tag"), record
);
7861 f_gpr
= build_decl (FIELD_DECL
, get_identifier ("__gpr"),
7862 long_integer_type_node
);
7863 f_fpr
= build_decl (FIELD_DECL
, get_identifier ("__fpr"),
7864 long_integer_type_node
);
7865 f_ovf
= build_decl (FIELD_DECL
, get_identifier ("__overflow_arg_area"),
7867 f_sav
= build_decl (FIELD_DECL
, get_identifier ("__reg_save_area"),
7870 va_list_gpr_counter_field
= f_gpr
;
7871 va_list_fpr_counter_field
= f_fpr
;
7873 DECL_FIELD_CONTEXT (f_gpr
) = record
;
7874 DECL_FIELD_CONTEXT (f_fpr
) = record
;
7875 DECL_FIELD_CONTEXT (f_ovf
) = record
;
7876 DECL_FIELD_CONTEXT (f_sav
) = record
;
7878 TREE_CHAIN (record
) = type_decl
;
7879 TYPE_NAME (record
) = type_decl
;
7880 TYPE_FIELDS (record
) = f_gpr
;
7881 TREE_CHAIN (f_gpr
) = f_fpr
;
7882 TREE_CHAIN (f_fpr
) = f_ovf
;
7883 TREE_CHAIN (f_ovf
) = f_sav
;
7885 layout_type (record
);
7887 /* The correct type is an array type of one element. */
7888 return build_array_type (record
, build_index_type (size_zero_node
));
7891 /* Implement va_start by filling the va_list structure VALIST.
7892 STDARG_P is always true, and ignored.
7893 NEXTARG points to the first anonymous stack argument.
7895 The following global variables are used to initialize
7896 the va_list structure:
7898 current_function_args_info:
7899 holds number of gprs and fprs used for named arguments.
7900 current_function_arg_offset_rtx:
7901 holds the offset of the first anonymous stack argument
7902 (relative to the virtual arg pointer). */
7905 s390_va_start (tree valist
, rtx nextarg ATTRIBUTE_UNUSED
)
7907 HOST_WIDE_INT n_gpr
, n_fpr
;
7909 tree f_gpr
, f_fpr
, f_ovf
, f_sav
;
7910 tree gpr
, fpr
, ovf
, sav
, t
;
7912 f_gpr
= TYPE_FIELDS (TREE_TYPE (va_list_type_node
));
7913 f_fpr
= TREE_CHAIN (f_gpr
);
7914 f_ovf
= TREE_CHAIN (f_fpr
);
7915 f_sav
= TREE_CHAIN (f_ovf
);
7917 valist
= build_va_arg_indirect_ref (valist
);
7918 gpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_gpr
), valist
, f_gpr
, NULL_TREE
);
7919 fpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_fpr
), valist
, f_fpr
, NULL_TREE
);
7920 ovf
= build3 (COMPONENT_REF
, TREE_TYPE (f_ovf
), valist
, f_ovf
, NULL_TREE
);
7921 sav
= build3 (COMPONENT_REF
, TREE_TYPE (f_sav
), valist
, f_sav
, NULL_TREE
);
7923 /* Count number of gp and fp argument registers used. */
7925 n_gpr
= current_function_args_info
.gprs
;
7926 n_fpr
= current_function_args_info
.fprs
;
7928 if (cfun
->va_list_gpr_size
)
7930 t
= build2 (MODIFY_EXPR
, TREE_TYPE (gpr
), gpr
,
7931 build_int_cst (NULL_TREE
, n_gpr
));
7932 TREE_SIDE_EFFECTS (t
) = 1;
7933 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
7936 if (cfun
->va_list_fpr_size
)
7938 t
= build2 (MODIFY_EXPR
, TREE_TYPE (fpr
), fpr
,
7939 build_int_cst (NULL_TREE
, n_fpr
));
7940 TREE_SIDE_EFFECTS (t
) = 1;
7941 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
7944 /* Find the overflow area. */
7945 if (n_gpr
+ cfun
->va_list_gpr_size
> GP_ARG_NUM_REG
7946 || n_fpr
+ cfun
->va_list_fpr_size
> FP_ARG_NUM_REG
)
7948 t
= make_tree (TREE_TYPE (ovf
), virtual_incoming_args_rtx
);
7950 off
= INTVAL (current_function_arg_offset_rtx
);
7951 off
= off
< 0 ? 0 : off
;
7952 if (TARGET_DEBUG_ARG
)
7953 fprintf (stderr
, "va_start: n_gpr = %d, n_fpr = %d off %d\n",
7954 (int)n_gpr
, (int)n_fpr
, off
);
7956 t
= build2 (PLUS_EXPR
, TREE_TYPE (ovf
), t
, build_int_cst (NULL_TREE
, off
));
7958 t
= build2 (MODIFY_EXPR
, TREE_TYPE (ovf
), ovf
, t
);
7959 TREE_SIDE_EFFECTS (t
) = 1;
7960 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
7963 /* Find the register save area. */
7964 if ((cfun
->va_list_gpr_size
&& n_gpr
< GP_ARG_NUM_REG
)
7965 || (cfun
->va_list_fpr_size
&& n_fpr
< FP_ARG_NUM_REG
))
7967 t
= make_tree (TREE_TYPE (sav
), return_address_pointer_rtx
);
7968 t
= build2 (PLUS_EXPR
, TREE_TYPE (sav
), t
,
7969 build_int_cst (NULL_TREE
, -RETURN_REGNUM
* UNITS_PER_WORD
));
7971 t
= build2 (MODIFY_EXPR
, TREE_TYPE (sav
), sav
, t
);
7972 TREE_SIDE_EFFECTS (t
) = 1;
7973 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
7977 /* Implement va_arg by updating the va_list structure
7978 VALIST as required to retrieve an argument of type
7979 TYPE, and returning that argument.
7981 Generates code equivalent to:
7983 if (integral value) {
7984 if (size <= 4 && args.gpr < 5 ||
7985 size > 4 && args.gpr < 4 )
7986 ret = args.reg_save_area[args.gpr+8]
7988 ret = *args.overflow_arg_area++;
7989 } else if (float value) {
7991 ret = args.reg_save_area[args.fpr+64]
7993 ret = *args.overflow_arg_area++;
7994 } else if (aggregate value) {
7996 ret = *args.reg_save_area[args.gpr]
7998 ret = **args.overflow_arg_area++;
8002 s390_gimplify_va_arg (tree valist
, tree type
, tree
*pre_p
,
8003 tree
*post_p ATTRIBUTE_UNUSED
)
8005 tree f_gpr
, f_fpr
, f_ovf
, f_sav
;
8006 tree gpr
, fpr
, ovf
, sav
, reg
, t
, u
;
8007 int indirect_p
, size
, n_reg
, sav_ofs
, sav_scale
, max_reg
;
8008 tree lab_false
, lab_over
, addr
;
8010 f_gpr
= TYPE_FIELDS (TREE_TYPE (va_list_type_node
));
8011 f_fpr
= TREE_CHAIN (f_gpr
);
8012 f_ovf
= TREE_CHAIN (f_fpr
);
8013 f_sav
= TREE_CHAIN (f_ovf
);
8015 valist
= build_va_arg_indirect_ref (valist
);
8016 gpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_gpr
), valist
, f_gpr
, NULL_TREE
);
8017 fpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_fpr
), valist
, f_fpr
, NULL_TREE
);
8018 ovf
= build3 (COMPONENT_REF
, TREE_TYPE (f_ovf
), valist
, f_ovf
, NULL_TREE
);
8019 sav
= build3 (COMPONENT_REF
, TREE_TYPE (f_sav
), valist
, f_sav
, NULL_TREE
);
8021 size
= int_size_in_bytes (type
);
8023 if (pass_by_reference (NULL
, TYPE_MODE (type
), type
, false))
8025 if (TARGET_DEBUG_ARG
)
8027 fprintf (stderr
, "va_arg: aggregate type");
8031 /* Aggregates are passed by reference. */
8036 /* kernel stack layout on 31 bit: It is assumed here that no padding
8037 will be added by s390_frame_info because for va_args always an even
8038 number of gprs has to be saved r15-r2 = 14 regs. */
8039 sav_ofs
= 2 * UNITS_PER_WORD
;
8040 sav_scale
= UNITS_PER_WORD
;
8041 size
= UNITS_PER_WORD
;
8042 max_reg
= GP_ARG_NUM_REG
- n_reg
;
8044 else if (s390_function_arg_float (TYPE_MODE (type
), type
))
8046 if (TARGET_DEBUG_ARG
)
8048 fprintf (stderr
, "va_arg: float type");
8052 /* FP args go in FP registers, if present. */
8056 sav_ofs
= 16 * UNITS_PER_WORD
;
8058 max_reg
= FP_ARG_NUM_REG
- n_reg
;
8062 if (TARGET_DEBUG_ARG
)
8064 fprintf (stderr
, "va_arg: other type");
8068 /* Otherwise into GP registers. */
8071 n_reg
= (size
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
8073 /* kernel stack layout on 31 bit: It is assumed here that no padding
8074 will be added by s390_frame_info because for va_args always an even
8075 number of gprs has to be saved r15-r2 = 14 regs. */
8076 sav_ofs
= 2 * UNITS_PER_WORD
;
8078 if (size
< UNITS_PER_WORD
)
8079 sav_ofs
+= UNITS_PER_WORD
- size
;
8081 sav_scale
= UNITS_PER_WORD
;
8082 max_reg
= GP_ARG_NUM_REG
- n_reg
;
8085 /* Pull the value out of the saved registers ... */
8087 lab_false
= create_artificial_label ();
8088 lab_over
= create_artificial_label ();
8089 addr
= create_tmp_var (ptr_type_node
, "addr");
8090 DECL_POINTER_ALIAS_SET (addr
) = get_varargs_alias_set ();
8092 t
= fold_convert (TREE_TYPE (reg
), size_int (max_reg
));
8093 t
= build2 (GT_EXPR
, boolean_type_node
, reg
, t
);
8094 u
= build1 (GOTO_EXPR
, void_type_node
, lab_false
);
8095 t
= build3 (COND_EXPR
, void_type_node
, t
, u
, NULL_TREE
);
8096 gimplify_and_add (t
, pre_p
);
8098 t
= build2 (PLUS_EXPR
, ptr_type_node
, sav
,
8099 fold_convert (ptr_type_node
, size_int (sav_ofs
)));
8100 u
= build2 (MULT_EXPR
, TREE_TYPE (reg
), reg
,
8101 fold_convert (TREE_TYPE (reg
), size_int (sav_scale
)));
8102 t
= build2 (PLUS_EXPR
, ptr_type_node
, t
, fold_convert (ptr_type_node
, u
));
8104 t
= build2 (MODIFY_EXPR
, void_type_node
, addr
, t
);
8105 gimplify_and_add (t
, pre_p
);
8107 t
= build1 (GOTO_EXPR
, void_type_node
, lab_over
);
8108 gimplify_and_add (t
, pre_p
);
8110 t
= build1 (LABEL_EXPR
, void_type_node
, lab_false
);
8111 append_to_statement_list (t
, pre_p
);
8114 /* ... Otherwise out of the overflow area. */
8117 if (size
< UNITS_PER_WORD
)
8118 t
= build2 (PLUS_EXPR
, ptr_type_node
, t
,
8119 fold_convert (ptr_type_node
, size_int (UNITS_PER_WORD
- size
)));
8121 gimplify_expr (&t
, pre_p
, NULL
, is_gimple_val
, fb_rvalue
);
8123 u
= build2 (MODIFY_EXPR
, void_type_node
, addr
, t
);
8124 gimplify_and_add (u
, pre_p
);
8126 t
= build2 (PLUS_EXPR
, ptr_type_node
, t
,
8127 fold_convert (ptr_type_node
, size_int (size
)));
8128 t
= build2 (MODIFY_EXPR
, ptr_type_node
, ovf
, t
);
8129 gimplify_and_add (t
, pre_p
);
8131 t
= build1 (LABEL_EXPR
, void_type_node
, lab_over
);
8132 append_to_statement_list (t
, pre_p
);
8135 /* Increment register save count. */
8137 u
= build2 (PREINCREMENT_EXPR
, TREE_TYPE (reg
), reg
,
8138 fold_convert (TREE_TYPE (reg
), size_int (n_reg
)));
8139 gimplify_and_add (u
, pre_p
);
8143 t
= build_pointer_type (build_pointer_type (type
));
8144 addr
= fold_convert (t
, addr
);
8145 addr
= build_va_arg_indirect_ref (addr
);
8149 t
= build_pointer_type (type
);
8150 addr
= fold_convert (t
, addr
);
8153 return build_va_arg_indirect_ref (addr
);
8161 S390_BUILTIN_THREAD_POINTER
,
8162 S390_BUILTIN_SET_THREAD_POINTER
,
8167 static unsigned int const code_for_builtin_64
[S390_BUILTIN_max
] = {
8172 static unsigned int const code_for_builtin_31
[S390_BUILTIN_max
] = {
8178 s390_init_builtins (void)
8182 ftype
= build_function_type (ptr_type_node
, void_list_node
);
8183 lang_hooks
.builtin_function ("__builtin_thread_pointer", ftype
,
8184 S390_BUILTIN_THREAD_POINTER
, BUILT_IN_MD
,
8187 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
8188 lang_hooks
.builtin_function ("__builtin_set_thread_pointer", ftype
,
8189 S390_BUILTIN_SET_THREAD_POINTER
, BUILT_IN_MD
,
8193 /* Expand an expression EXP that calls a built-in function,
8194 with result going to TARGET if that's convenient
8195 (and in mode MODE if that's convenient).
8196 SUBTARGET may be used as the target for computing one of EXP's operands.
8197 IGNORE is nonzero if the value is to be ignored. */
8200 s390_expand_builtin (tree exp
, rtx target
, rtx subtarget ATTRIBUTE_UNUSED
,
8201 enum machine_mode mode ATTRIBUTE_UNUSED
,
8202 int ignore ATTRIBUTE_UNUSED
)
8206 unsigned int const *code_for_builtin
=
8207 TARGET_64BIT
? code_for_builtin_64
: code_for_builtin_31
;
8209 tree fndecl
= TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
8210 unsigned int fcode
= DECL_FUNCTION_CODE (fndecl
);
8211 tree arglist
= TREE_OPERAND (exp
, 1);
8212 enum insn_code icode
;
8213 rtx op
[MAX_ARGS
], pat
;
8217 if (fcode
>= S390_BUILTIN_max
)
8218 internal_error ("bad builtin fcode");
8219 icode
= code_for_builtin
[fcode
];
8221 internal_error ("bad builtin fcode");
8223 nonvoid
= TREE_TYPE (TREE_TYPE (fndecl
)) != void_type_node
;
8225 for (arglist
= TREE_OPERAND (exp
, 1), arity
= 0;
8227 arglist
= TREE_CHAIN (arglist
), arity
++)
8229 const struct insn_operand_data
*insn_op
;
8231 tree arg
= TREE_VALUE (arglist
);
8232 if (arg
== error_mark_node
)
8234 if (arity
> MAX_ARGS
)
8237 insn_op
= &insn_data
[icode
].operand
[arity
+ nonvoid
];
8239 op
[arity
] = expand_expr (arg
, NULL_RTX
, insn_op
->mode
, 0);
8241 if (!(*insn_op
->predicate
) (op
[arity
], insn_op
->mode
))
8242 op
[arity
] = copy_to_mode_reg (insn_op
->mode
, op
[arity
]);
8247 enum machine_mode tmode
= insn_data
[icode
].operand
[0].mode
;
8249 || GET_MODE (target
) != tmode
8250 || !(*insn_data
[icode
].operand
[0].predicate
) (target
, tmode
))
8251 target
= gen_reg_rtx (tmode
);
8257 pat
= GEN_FCN (icode
) (target
);
8261 pat
= GEN_FCN (icode
) (target
, op
[0]);
8263 pat
= GEN_FCN (icode
) (op
[0]);
8266 pat
= GEN_FCN (icode
) (target
, op
[0], op
[1]);
8282 /* Output assembly code for the trampoline template to
8285 On S/390, we use gpr 1 internally in the trampoline code;
8286 gpr 0 is used to hold the static chain. */
8289 s390_trampoline_template (FILE *file
)
8292 op
[0] = gen_rtx_REG (Pmode
, 0);
8293 op
[1] = gen_rtx_REG (Pmode
, 1);
8297 output_asm_insn ("basr\t%1,0", op
);
8298 output_asm_insn ("lmg\t%0,%1,14(%1)", op
);
8299 output_asm_insn ("br\t%1", op
);
8300 ASM_OUTPUT_SKIP (file
, (HOST_WIDE_INT
)(TRAMPOLINE_SIZE
- 10));
8304 output_asm_insn ("basr\t%1,0", op
);
8305 output_asm_insn ("lm\t%0,%1,6(%1)", op
);
8306 output_asm_insn ("br\t%1", op
);
8307 ASM_OUTPUT_SKIP (file
, (HOST_WIDE_INT
)(TRAMPOLINE_SIZE
- 8));
8311 /* Emit RTL insns to initialize the variable parts of a trampoline.
8312 FNADDR is an RTX for the address of the function's pure code.
8313 CXT is an RTX for the static chain value for the function. */
8316 s390_initialize_trampoline (rtx addr
, rtx fnaddr
, rtx cxt
)
8318 emit_move_insn (gen_rtx_MEM (Pmode
,
8319 memory_address (Pmode
,
8320 plus_constant (addr
, (TARGET_64BIT
? 16 : 8)))), cxt
);
8321 emit_move_insn (gen_rtx_MEM (Pmode
,
8322 memory_address (Pmode
,
8323 plus_constant (addr
, (TARGET_64BIT
? 24 : 12)))), fnaddr
);
8326 /* Return rtx for 64-bit constant formed from the 32-bit subwords
8327 LOW and HIGH, independent of the host word size. */
8330 s390_gen_rtx_const_DI (int high
, int low
)
8332 #if HOST_BITS_PER_WIDE_INT >= 64
8334 val
= (HOST_WIDE_INT
)high
;
8336 val
|= (HOST_WIDE_INT
)low
;
8338 return GEN_INT (val
);
8340 #if HOST_BITS_PER_WIDE_INT >= 32
8341 return immed_double_const ((HOST_WIDE_INT
)low
, (HOST_WIDE_INT
)high
, DImode
);
8348 /* Output assembler code to FILE to increment profiler label # LABELNO
8349 for profiling a function entry. */
8352 s390_function_profiler (FILE *file
, int labelno
)
8357 ASM_GENERATE_INTERNAL_LABEL (label
, "LP", labelno
);
8359 fprintf (file
, "# function profiler \n");
8361 op
[0] = gen_rtx_REG (Pmode
, RETURN_REGNUM
);
8362 op
[1] = gen_rtx_REG (Pmode
, STACK_POINTER_REGNUM
);
8363 op
[1] = gen_rtx_MEM (Pmode
, plus_constant (op
[1], UNITS_PER_WORD
));
8365 op
[2] = gen_rtx_REG (Pmode
, 1);
8366 op
[3] = gen_rtx_SYMBOL_REF (Pmode
, label
);
8367 SYMBOL_REF_FLAGS (op
[3]) = SYMBOL_FLAG_LOCAL
;
8369 op
[4] = gen_rtx_SYMBOL_REF (Pmode
, "_mcount");
8372 op
[4] = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op
[4]), UNSPEC_PLT
);
8373 op
[4] = gen_rtx_CONST (Pmode
, op
[4]);
8378 output_asm_insn ("stg\t%0,%1", op
);
8379 output_asm_insn ("larl\t%2,%3", op
);
8380 output_asm_insn ("brasl\t%0,%4", op
);
8381 output_asm_insn ("lg\t%0,%1", op
);
8385 op
[6] = gen_label_rtx ();
8387 output_asm_insn ("st\t%0,%1", op
);
8388 output_asm_insn ("bras\t%2,%l6", op
);
8389 output_asm_insn (".long\t%4", op
);
8390 output_asm_insn (".long\t%3", op
);
8391 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[6]));
8392 output_asm_insn ("l\t%0,0(%2)", op
);
8393 output_asm_insn ("l\t%2,4(%2)", op
);
8394 output_asm_insn ("basr\t%0,%0", op
);
8395 output_asm_insn ("l\t%0,%1", op
);
8399 op
[5] = gen_label_rtx ();
8400 op
[6] = gen_label_rtx ();
8402 output_asm_insn ("st\t%0,%1", op
);
8403 output_asm_insn ("bras\t%2,%l6", op
);
8404 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[5]));
8405 output_asm_insn (".long\t%4-%l5", op
);
8406 output_asm_insn (".long\t%3-%l5", op
);
8407 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[6]));
8408 output_asm_insn ("lr\t%0,%2", op
);
8409 output_asm_insn ("a\t%0,0(%2)", op
);
8410 output_asm_insn ("a\t%2,4(%2)", op
);
8411 output_asm_insn ("basr\t%0,%0", op
);
8412 output_asm_insn ("l\t%0,%1", op
);
8416 /* Encode symbol attributes (local vs. global, tls model) of a SYMBOL_REF
8417 into its SYMBOL_REF_FLAGS. */
8420 s390_encode_section_info (tree decl
, rtx rtl
, int first
)
8422 default_encode_section_info (decl
, rtl
, first
);
8424 /* If a variable has a forced alignment to < 2 bytes, mark it with
8425 SYMBOL_FLAG_ALIGN1 to prevent it from being used as LARL operand. */
8426 if (TREE_CODE (decl
) == VAR_DECL
8427 && DECL_USER_ALIGN (decl
) && DECL_ALIGN (decl
) < 16)
8428 SYMBOL_REF_FLAGS (XEXP (rtl
, 0)) |= SYMBOL_FLAG_ALIGN1
;
8431 /* Output thunk to FILE that implements a C++ virtual function call (with
8432 multiple inheritance) to FUNCTION. The thunk adjusts the this pointer
8433 by DELTA, and unless VCALL_OFFSET is zero, applies an additional adjustment
8434 stored at VCALL_OFFSET in the vtable whose address is located at offset 0
8435 relative to the resulting this pointer. */
8438 s390_output_mi_thunk (FILE *file
, tree thunk ATTRIBUTE_UNUSED
,
8439 HOST_WIDE_INT delta
, HOST_WIDE_INT vcall_offset
,
8445 /* Operand 0 is the target function. */
8446 op
[0] = XEXP (DECL_RTL (function
), 0);
8447 if (flag_pic
&& !SYMBOL_REF_LOCAL_P (op
[0]))
8450 op
[0] = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op
[0]),
8451 TARGET_64BIT
? UNSPEC_PLT
: UNSPEC_GOT
);
8452 op
[0] = gen_rtx_CONST (Pmode
, op
[0]);
8455 /* Operand 1 is the 'this' pointer. */
8456 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function
)), function
))
8457 op
[1] = gen_rtx_REG (Pmode
, 3);
8459 op
[1] = gen_rtx_REG (Pmode
, 2);
8461 /* Operand 2 is the delta. */
8462 op
[2] = GEN_INT (delta
);
8464 /* Operand 3 is the vcall_offset. */
8465 op
[3] = GEN_INT (vcall_offset
);
8467 /* Operand 4 is the temporary register. */
8468 op
[4] = gen_rtx_REG (Pmode
, 1);
8470 /* Operands 5 to 8 can be used as labels. */
8476 /* Operand 9 can be used for temporary register. */
8479 /* Generate code. */
8482 /* Setup literal pool pointer if required. */
8483 if ((!DISP_IN_RANGE (delta
)
8484 && !CONST_OK_FOR_K (delta
)
8485 && !CONST_OK_FOR_Os (delta
))
8486 || (!DISP_IN_RANGE (vcall_offset
)
8487 && !CONST_OK_FOR_K (vcall_offset
)
8488 && !CONST_OK_FOR_Os (vcall_offset
)))
8490 op
[5] = gen_label_rtx ();
8491 output_asm_insn ("larl\t%4,%5", op
);
8494 /* Add DELTA to this pointer. */
8497 if (CONST_OK_FOR_J (delta
))
8498 output_asm_insn ("la\t%1,%2(%1)", op
);
8499 else if (DISP_IN_RANGE (delta
))
8500 output_asm_insn ("lay\t%1,%2(%1)", op
);
8501 else if (CONST_OK_FOR_K (delta
))
8502 output_asm_insn ("aghi\t%1,%2", op
);
8503 else if (CONST_OK_FOR_Os (delta
))
8504 output_asm_insn ("agfi\t%1,%2", op
);
8507 op
[6] = gen_label_rtx ();
8508 output_asm_insn ("agf\t%1,%6-%5(%4)", op
);
8512 /* Perform vcall adjustment. */
8515 if (DISP_IN_RANGE (vcall_offset
))
8517 output_asm_insn ("lg\t%4,0(%1)", op
);
8518 output_asm_insn ("ag\t%1,%3(%4)", op
);
8520 else if (CONST_OK_FOR_K (vcall_offset
))
8522 output_asm_insn ("lghi\t%4,%3", op
);
8523 output_asm_insn ("ag\t%4,0(%1)", op
);
8524 output_asm_insn ("ag\t%1,0(%4)", op
);
8526 else if (CONST_OK_FOR_Os (vcall_offset
))
8528 output_asm_insn ("lgfi\t%4,%3", op
);
8529 output_asm_insn ("ag\t%4,0(%1)", op
);
8530 output_asm_insn ("ag\t%1,0(%4)", op
);
8534 op
[7] = gen_label_rtx ();
8535 output_asm_insn ("llgf\t%4,%7-%5(%4)", op
);
8536 output_asm_insn ("ag\t%4,0(%1)", op
);
8537 output_asm_insn ("ag\t%1,0(%4)", op
);
8541 /* Jump to target. */
8542 output_asm_insn ("jg\t%0", op
);
8544 /* Output literal pool if required. */
8547 output_asm_insn (".align\t4", op
);
8548 targetm
.asm_out
.internal_label (file
, "L",
8549 CODE_LABEL_NUMBER (op
[5]));
8553 targetm
.asm_out
.internal_label (file
, "L",
8554 CODE_LABEL_NUMBER (op
[6]));
8555 output_asm_insn (".long\t%2", op
);
8559 targetm
.asm_out
.internal_label (file
, "L",
8560 CODE_LABEL_NUMBER (op
[7]));
8561 output_asm_insn (".long\t%3", op
);
8566 /* Setup base pointer if required. */
8568 || (!DISP_IN_RANGE (delta
)
8569 && !CONST_OK_FOR_K (delta
)
8570 && !CONST_OK_FOR_Os (delta
))
8571 || (!DISP_IN_RANGE (delta
)
8572 && !CONST_OK_FOR_K (vcall_offset
)
8573 && !CONST_OK_FOR_Os (vcall_offset
)))
8575 op
[5] = gen_label_rtx ();
8576 output_asm_insn ("basr\t%4,0", op
);
8577 targetm
.asm_out
.internal_label (file
, "L",
8578 CODE_LABEL_NUMBER (op
[5]));
8581 /* Add DELTA to this pointer. */
8584 if (CONST_OK_FOR_J (delta
))
8585 output_asm_insn ("la\t%1,%2(%1)", op
);
8586 else if (DISP_IN_RANGE (delta
))
8587 output_asm_insn ("lay\t%1,%2(%1)", op
);
8588 else if (CONST_OK_FOR_K (delta
))
8589 output_asm_insn ("ahi\t%1,%2", op
);
8590 else if (CONST_OK_FOR_Os (delta
))
8591 output_asm_insn ("afi\t%1,%2", op
);
8594 op
[6] = gen_label_rtx ();
8595 output_asm_insn ("a\t%1,%6-%5(%4)", op
);
8599 /* Perform vcall adjustment. */
8602 if (CONST_OK_FOR_J (vcall_offset
))
8604 output_asm_insn ("l\t%4,0(%1)", op
);
8605 output_asm_insn ("a\t%1,%3(%4)", op
);
8607 else if (DISP_IN_RANGE (vcall_offset
))
8609 output_asm_insn ("l\t%4,0(%1)", op
);
8610 output_asm_insn ("ay\t%1,%3(%4)", op
);
8612 else if (CONST_OK_FOR_K (vcall_offset
))
8614 output_asm_insn ("lhi\t%4,%3", op
);
8615 output_asm_insn ("a\t%4,0(%1)", op
);
8616 output_asm_insn ("a\t%1,0(%4)", op
);
8618 else if (CONST_OK_FOR_Os (vcall_offset
))
8620 output_asm_insn ("iilf\t%4,%3", op
);
8621 output_asm_insn ("a\t%4,0(%1)", op
);
8622 output_asm_insn ("a\t%1,0(%4)", op
);
8626 op
[7] = gen_label_rtx ();
8627 output_asm_insn ("l\t%4,%7-%5(%4)", op
);
8628 output_asm_insn ("a\t%4,0(%1)", op
);
8629 output_asm_insn ("a\t%1,0(%4)", op
);
8632 /* We had to clobber the base pointer register.
8633 Re-setup the base pointer (with a different base). */
8634 op
[5] = gen_label_rtx ();
8635 output_asm_insn ("basr\t%4,0", op
);
8636 targetm
.asm_out
.internal_label (file
, "L",
8637 CODE_LABEL_NUMBER (op
[5]));
8640 /* Jump to target. */
8641 op
[8] = gen_label_rtx ();
8644 output_asm_insn ("l\t%4,%8-%5(%4)", op
);
8646 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
8647 /* We cannot call through .plt, since .plt requires %r12 loaded. */
8648 else if (flag_pic
== 1)
8650 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
8651 output_asm_insn ("l\t%4,%0(%4)", op
);
8653 else if (flag_pic
== 2)
8655 op
[9] = gen_rtx_REG (Pmode
, 0);
8656 output_asm_insn ("l\t%9,%8-4-%5(%4)", op
);
8657 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
8658 output_asm_insn ("ar\t%4,%9", op
);
8659 output_asm_insn ("l\t%4,0(%4)", op
);
8662 output_asm_insn ("br\t%4", op
);
8664 /* Output literal pool. */
8665 output_asm_insn (".align\t4", op
);
8667 if (nonlocal
&& flag_pic
== 2)
8668 output_asm_insn (".long\t%0", op
);
8671 op
[0] = gen_rtx_SYMBOL_REF (Pmode
, "_GLOBAL_OFFSET_TABLE_");
8672 SYMBOL_REF_FLAGS (op
[0]) = SYMBOL_FLAG_LOCAL
;
8675 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[8]));
8677 output_asm_insn (".long\t%0", op
);
8679 output_asm_insn (".long\t%0-%5", op
);
8683 targetm
.asm_out
.internal_label (file
, "L",
8684 CODE_LABEL_NUMBER (op
[6]));
8685 output_asm_insn (".long\t%2", op
);
8689 targetm
.asm_out
.internal_label (file
, "L",
8690 CODE_LABEL_NUMBER (op
[7]));
8691 output_asm_insn (".long\t%3", op
);
8697 s390_valid_pointer_mode (enum machine_mode mode
)
8699 return (mode
== SImode
|| (TARGET_64BIT
&& mode
== DImode
));
8702 /* Checks whether the given ARGUMENT_LIST would use a caller
8703 saved register. This is used to decide whether sibling call
8704 optimization could be performed on the respective function
8708 s390_call_saved_register_used (tree argument_list
)
8710 CUMULATIVE_ARGS cum
;
8712 enum machine_mode mode
;
8717 INIT_CUMULATIVE_ARGS (cum
, NULL
, NULL
, 0, 0);
8719 while (argument_list
)
8721 parameter
= TREE_VALUE (argument_list
);
8722 argument_list
= TREE_CHAIN (argument_list
);
8724 gcc_assert (parameter
);
8726 /* For an undeclared variable passed as parameter we will get
8727 an ERROR_MARK node here. */
8728 if (TREE_CODE (parameter
) == ERROR_MARK
)
8731 type
= TREE_TYPE (parameter
);
8734 mode
= TYPE_MODE (type
);
8737 if (pass_by_reference (&cum
, mode
, type
, true))
8740 type
= build_pointer_type (type
);
8743 parm_rtx
= s390_function_arg (&cum
, mode
, type
, 0);
8745 s390_function_arg_advance (&cum
, mode
, type
, 0);
8747 if (parm_rtx
&& REG_P (parm_rtx
))
8750 reg
< HARD_REGNO_NREGS (REGNO (parm_rtx
), GET_MODE (parm_rtx
));
8752 if (! call_used_regs
[reg
+ REGNO (parm_rtx
)])
8759 /* Return true if the given call expression can be
8760 turned into a sibling call.
8761 DECL holds the declaration of the function to be called whereas
8762 EXP is the call expression itself. */
8765 s390_function_ok_for_sibcall (tree decl
, tree exp
)
8767 /* The TPF epilogue uses register 1. */
8768 if (TARGET_TPF_PROFILING
)
8771 /* The 31 bit PLT code uses register 12 (GOT pointer - caller saved)
8772 which would have to be restored before the sibcall. */
8773 if (!TARGET_64BIT
&& flag_pic
&& decl
&& !targetm
.binds_local_p (decl
))
8776 /* Register 6 on s390 is available as an argument register but unfortunately
8777 "caller saved". This makes functions needing this register for arguments
8778 not suitable for sibcalls. */
8779 if (TREE_OPERAND (exp
, 1)
8780 && s390_call_saved_register_used (TREE_OPERAND (exp
, 1)))
8786 /* Return the fixed registers used for condition codes. */
8789 s390_fixed_condition_code_regs (unsigned int *p1
, unsigned int *p2
)
8792 *p2
= INVALID_REGNUM
;
8797 /* This function is used by the call expanders of the machine description.
8798 It emits the call insn itself together with the necessary operations
8799 to adjust the target address and returns the emitted insn.
8800 ADDR_LOCATION is the target address rtx
8801 TLS_CALL the location of the thread-local symbol
8802 RESULT_REG the register where the result of the call should be stored
8803 RETADDR_REG the register where the return address should be stored
8804 If this parameter is NULL_RTX the call is considered
8805 to be a sibling call. */
8808 s390_emit_call (rtx addr_location
, rtx tls_call
, rtx result_reg
,
8811 bool plt_call
= false;
8817 /* Direct function calls need special treatment. */
8818 if (GET_CODE (addr_location
) == SYMBOL_REF
)
8820 /* When calling a global routine in PIC mode, we must
8821 replace the symbol itself with the PLT stub. */
8822 if (flag_pic
&& !SYMBOL_REF_LOCAL_P (addr_location
))
8824 addr_location
= gen_rtx_UNSPEC (Pmode
,
8825 gen_rtvec (1, addr_location
),
8827 addr_location
= gen_rtx_CONST (Pmode
, addr_location
);
8831 /* Unless we can use the bras(l) insn, force the
8832 routine address into a register. */
8833 if (!TARGET_SMALL_EXEC
&& !TARGET_CPU_ZARCH
)
8836 addr_location
= legitimize_pic_address (addr_location
, 0);
8838 addr_location
= force_reg (Pmode
, addr_location
);
8842 /* If it is already an indirect call or the code above moved the
8843 SYMBOL_REF to somewhere else make sure the address can be found in
8845 if (retaddr_reg
== NULL_RTX
8846 && GET_CODE (addr_location
) != SYMBOL_REF
8849 emit_move_insn (gen_rtx_REG (Pmode
, SIBCALL_REGNUM
), addr_location
);
8850 addr_location
= gen_rtx_REG (Pmode
, SIBCALL_REGNUM
);
8853 addr_location
= gen_rtx_MEM (QImode
, addr_location
);
8854 call
= gen_rtx_CALL (VOIDmode
, addr_location
, const0_rtx
);
8856 if (result_reg
!= NULL_RTX
)
8857 call
= gen_rtx_SET (VOIDmode
, result_reg
, call
);
8859 if (retaddr_reg
!= NULL_RTX
)
8861 clobber
= gen_rtx_CLOBBER (VOIDmode
, retaddr_reg
);
8863 if (tls_call
!= NULL_RTX
)
8864 vec
= gen_rtvec (3, call
, clobber
,
8865 gen_rtx_USE (VOIDmode
, tls_call
));
8867 vec
= gen_rtvec (2, call
, clobber
);
8869 call
= gen_rtx_PARALLEL (VOIDmode
, vec
);
8872 insn
= emit_call_insn (call
);
8874 /* 31-bit PLT stubs and tls calls use the GOT register implicitly. */
8875 if ((!TARGET_64BIT
&& plt_call
) || tls_call
!= NULL_RTX
)
8877 /* s390_function_ok_for_sibcall should
8878 have denied sibcalls in this case. */
8879 gcc_assert (retaddr_reg
!= NULL_RTX
);
8881 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), pic_offset_table_rtx
);
8886 /* Implement CONDITIONAL_REGISTER_USAGE. */
8889 s390_conditional_register_usage (void)
8895 fixed_regs
[PIC_OFFSET_TABLE_REGNUM
] = 1;
8896 call_used_regs
[PIC_OFFSET_TABLE_REGNUM
] = 1;
8898 if (TARGET_CPU_ZARCH
)
8900 fixed_regs
[BASE_REGNUM
] = 0;
8901 call_used_regs
[BASE_REGNUM
] = 0;
8902 fixed_regs
[RETURN_REGNUM
] = 0;
8903 call_used_regs
[RETURN_REGNUM
] = 0;
8907 for (i
= 24; i
< 32; i
++)
8908 call_used_regs
[i
] = call_really_used_regs
[i
] = 0;
8912 for (i
= 18; i
< 20; i
++)
8913 call_used_regs
[i
] = call_really_used_regs
[i
] = 0;
8916 if (TARGET_SOFT_FLOAT
)
8918 for (i
= 16; i
< 32; i
++)
8919 call_used_regs
[i
] = fixed_regs
[i
] = 1;
8923 /* Corresponding function to eh_return expander. */
8925 static GTY(()) rtx s390_tpf_eh_return_symbol
;
8927 s390_emit_tpf_eh_return (rtx target
)
8931 if (!s390_tpf_eh_return_symbol
)
8932 s390_tpf_eh_return_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "__tpf_eh_return");
8934 reg
= gen_rtx_REG (Pmode
, 2);
8936 emit_move_insn (reg
, target
);
8937 insn
= s390_emit_call (s390_tpf_eh_return_symbol
, NULL_RTX
, reg
,
8938 gen_rtx_REG (Pmode
, RETURN_REGNUM
));
8939 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), reg
);
8941 emit_move_insn (EH_RETURN_HANDLER_RTX
, reg
);
8944 /* Rework the prologue/epilogue to avoid saving/restoring
8945 registers unnecessarily. */
8948 s390_optimize_prologue (void)
8950 rtx insn
, new_insn
, next_insn
;
8952 /* Do a final recompute of the frame-related data. */
8954 s390_update_frame_layout ();
8956 /* If all special registers are in fact used, there's nothing we
8957 can do, so no point in walking the insn list. */
8959 if (cfun_frame_layout
.first_save_gpr
<= BASE_REGNUM
8960 && cfun_frame_layout
.last_save_gpr
>= BASE_REGNUM
8961 && (TARGET_CPU_ZARCH
8962 || (cfun_frame_layout
.first_save_gpr
<= RETURN_REGNUM
8963 && cfun_frame_layout
.last_save_gpr
>= RETURN_REGNUM
)))
8966 /* Search for prologue/epilogue insns and replace them. */
8968 for (insn
= get_insns (); insn
; insn
= next_insn
)
8970 int first
, last
, off
;
8971 rtx set
, base
, offset
;
8973 next_insn
= NEXT_INSN (insn
);
8975 if (GET_CODE (insn
) != INSN
)
8978 if (GET_CODE (PATTERN (insn
)) == PARALLEL
8979 && store_multiple_operation (PATTERN (insn
), VOIDmode
))
8981 set
= XVECEXP (PATTERN (insn
), 0, 0);
8982 first
= REGNO (SET_SRC (set
));
8983 last
= first
+ XVECLEN (PATTERN (insn
), 0) - 1;
8984 offset
= const0_rtx
;
8985 base
= eliminate_constant_term (XEXP (SET_DEST (set
), 0), &offset
);
8986 off
= INTVAL (offset
);
8988 if (GET_CODE (base
) != REG
|| off
< 0)
8990 if (cfun_frame_layout
.first_save_gpr
!= -1
8991 && (cfun_frame_layout
.first_save_gpr
< first
8992 || cfun_frame_layout
.last_save_gpr
> last
))
8994 if (REGNO (base
) != STACK_POINTER_REGNUM
8995 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
8997 if (first
> BASE_REGNUM
|| last
< BASE_REGNUM
)
9000 if (cfun_frame_layout
.first_save_gpr
!= -1)
9002 new_insn
= save_gprs (base
,
9003 off
+ (cfun_frame_layout
.first_save_gpr
9004 - first
) * UNITS_PER_WORD
,
9005 cfun_frame_layout
.first_save_gpr
,
9006 cfun_frame_layout
.last_save_gpr
);
9007 new_insn
= emit_insn_before (new_insn
, insn
);
9008 INSN_ADDRESSES_NEW (new_insn
, -1);
9015 if (cfun_frame_layout
.first_save_gpr
== -1
9016 && GET_CODE (PATTERN (insn
)) == SET
9017 && GET_CODE (SET_SRC (PATTERN (insn
))) == REG
9018 && (REGNO (SET_SRC (PATTERN (insn
))) == BASE_REGNUM
9019 || (!TARGET_CPU_ZARCH
9020 && REGNO (SET_SRC (PATTERN (insn
))) == RETURN_REGNUM
))
9021 && GET_CODE (SET_DEST (PATTERN (insn
))) == MEM
)
9023 set
= PATTERN (insn
);
9024 first
= REGNO (SET_SRC (set
));
9025 offset
= const0_rtx
;
9026 base
= eliminate_constant_term (XEXP (SET_DEST (set
), 0), &offset
);
9027 off
= INTVAL (offset
);
9029 if (GET_CODE (base
) != REG
|| off
< 0)
9031 if (REGNO (base
) != STACK_POINTER_REGNUM
9032 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
9039 if (GET_CODE (PATTERN (insn
)) == PARALLEL
9040 && load_multiple_operation (PATTERN (insn
), VOIDmode
))
9042 set
= XVECEXP (PATTERN (insn
), 0, 0);
9043 first
= REGNO (SET_DEST (set
));
9044 last
= first
+ XVECLEN (PATTERN (insn
), 0) - 1;
9045 offset
= const0_rtx
;
9046 base
= eliminate_constant_term (XEXP (SET_SRC (set
), 0), &offset
);
9047 off
= INTVAL (offset
);
9049 if (GET_CODE (base
) != REG
|| off
< 0)
9051 if (cfun_frame_layout
.first_restore_gpr
!= -1
9052 && (cfun_frame_layout
.first_restore_gpr
< first
9053 || cfun_frame_layout
.last_restore_gpr
> last
))
9055 if (REGNO (base
) != STACK_POINTER_REGNUM
9056 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
9058 if (first
> BASE_REGNUM
|| last
< BASE_REGNUM
)
9061 if (cfun_frame_layout
.first_restore_gpr
!= -1)
9063 new_insn
= restore_gprs (base
,
9064 off
+ (cfun_frame_layout
.first_restore_gpr
9065 - first
) * UNITS_PER_WORD
,
9066 cfun_frame_layout
.first_restore_gpr
,
9067 cfun_frame_layout
.last_restore_gpr
);
9068 new_insn
= emit_insn_before (new_insn
, insn
);
9069 INSN_ADDRESSES_NEW (new_insn
, -1);
9076 if (cfun_frame_layout
.first_restore_gpr
== -1
9077 && GET_CODE (PATTERN (insn
)) == SET
9078 && GET_CODE (SET_DEST (PATTERN (insn
))) == REG
9079 && (REGNO (SET_DEST (PATTERN (insn
))) == BASE_REGNUM
9080 || (!TARGET_CPU_ZARCH
9081 && REGNO (SET_DEST (PATTERN (insn
))) == RETURN_REGNUM
))
9082 && GET_CODE (SET_SRC (PATTERN (insn
))) == MEM
)
9084 set
= PATTERN (insn
);
9085 first
= REGNO (SET_DEST (set
));
9086 offset
= const0_rtx
;
9087 base
= eliminate_constant_term (XEXP (SET_SRC (set
), 0), &offset
);
9088 off
= INTVAL (offset
);
9090 if (GET_CODE (base
) != REG
|| off
< 0)
9092 if (REGNO (base
) != STACK_POINTER_REGNUM
9093 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
9102 /* Perform machine-dependent processing. */
9107 bool pool_overflow
= false;
9109 /* Make sure all splits have been performed; splits after
9110 machine_dependent_reorg might confuse insn length counts. */
9111 split_all_insns_noflow ();
9113 /* From here on decomposed literal pool addresses must be accepted. */
9114 cfun
->machine
->decomposed_literal_pool_addresses_ok_p
= true;
9116 /* Install the main literal pool and the associated base
9117 register load insns.
9119 In addition, there are two problematic situations we need
9122 - the literal pool might be > 4096 bytes in size, so that
9123 some of its elements cannot be directly accessed
9125 - a branch target might be > 64K away from the branch, so that
9126 it is not possible to use a PC-relative instruction.
9128 To fix those, we split the single literal pool into multiple
9129 pool chunks, reloading the pool base register at various
9130 points throughout the function to ensure it always points to
9131 the pool chunk the following code expects, and / or replace
9132 PC-relative branches by absolute branches.
9134 However, the two problems are interdependent: splitting the
9135 literal pool can move a branch further away from its target,
9136 causing the 64K limit to overflow, and on the other hand,
9137 replacing a PC-relative branch by an absolute branch means
9138 we need to put the branch target address into the literal
9139 pool, possibly causing it to overflow.
9141 So, we loop trying to fix up both problems until we manage
9142 to satisfy both conditions at the same time. Note that the
9143 loop is guaranteed to terminate as every pass of the loop
9144 strictly decreases the total number of PC-relative branches
9145 in the function. (This is not completely true as there
9146 might be branch-over-pool insns introduced by chunkify_start.
9147 Those never need to be split however.) */
9151 struct constant_pool
*pool
= NULL
;
9153 /* Collect the literal pool. */
9156 pool
= s390_mainpool_start ();
9158 pool_overflow
= true;
9161 /* If literal pool overflowed, start to chunkify it. */
9163 pool
= s390_chunkify_start ();
9165 /* Split out-of-range branches. If this has created new
9166 literal pool entries, cancel current chunk list and
9167 recompute it. zSeries machines have large branch
9168 instructions, so we never need to split a branch. */
9169 if (!TARGET_CPU_ZARCH
&& s390_split_branches ())
9172 s390_chunkify_cancel (pool
);
9174 s390_mainpool_cancel (pool
);
9179 /* If we made it up to here, both conditions are satisfied.
9180 Finish up literal pool related changes. */
9182 s390_chunkify_finish (pool
);
9184 s390_mainpool_finish (pool
);
9186 /* We're done splitting branches. */
9187 cfun
->machine
->split_branches_pending_p
= false;
9191 /* Generate out-of-pool execute target insns. */
9192 if (TARGET_CPU_ZARCH
)
9194 rtx insn
, label
, target
;
9196 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
9198 label
= s390_execute_label (insn
);
9202 gcc_assert (label
!= const0_rtx
);
9204 target
= emit_label (XEXP (label
, 0));
9205 INSN_ADDRESSES_NEW (target
, -1);
9207 target
= emit_insn (s390_execute_target (insn
));
9208 INSN_ADDRESSES_NEW (target
, -1);
9212 /* Try to optimize prologue and epilogue further. */
9213 s390_optimize_prologue ();
9217 /* Initialize GCC target structure. */
9219 #undef TARGET_ASM_ALIGNED_HI_OP
9220 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
9221 #undef TARGET_ASM_ALIGNED_DI_OP
9222 #define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
9223 #undef TARGET_ASM_INTEGER
9224 #define TARGET_ASM_INTEGER s390_assemble_integer
9226 #undef TARGET_ASM_OPEN_PAREN
9227 #define TARGET_ASM_OPEN_PAREN ""
9229 #undef TARGET_ASM_CLOSE_PAREN
9230 #define TARGET_ASM_CLOSE_PAREN ""
9232 #undef TARGET_DEFAULT_TARGET_FLAGS
9233 #define TARGET_DEFAULT_TARGET_FLAGS (TARGET_DEFAULT | MASK_FUSED_MADD)
9234 #undef TARGET_HANDLE_OPTION
9235 #define TARGET_HANDLE_OPTION s390_handle_option
9237 #undef TARGET_ENCODE_SECTION_INFO
9238 #define TARGET_ENCODE_SECTION_INFO s390_encode_section_info
9241 #undef TARGET_HAVE_TLS
9242 #define TARGET_HAVE_TLS true
9244 #undef TARGET_CANNOT_FORCE_CONST_MEM
9245 #define TARGET_CANNOT_FORCE_CONST_MEM s390_cannot_force_const_mem
9247 #undef TARGET_DELEGITIMIZE_ADDRESS
9248 #define TARGET_DELEGITIMIZE_ADDRESS s390_delegitimize_address
9250 #undef TARGET_RETURN_IN_MEMORY
9251 #define TARGET_RETURN_IN_MEMORY s390_return_in_memory
9253 #undef TARGET_INIT_BUILTINS
9254 #define TARGET_INIT_BUILTINS s390_init_builtins
9255 #undef TARGET_EXPAND_BUILTIN
9256 #define TARGET_EXPAND_BUILTIN s390_expand_builtin
9258 #undef TARGET_ASM_OUTPUT_MI_THUNK
9259 #define TARGET_ASM_OUTPUT_MI_THUNK s390_output_mi_thunk
9260 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
9261 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
9263 #undef TARGET_SCHED_ADJUST_PRIORITY
9264 #define TARGET_SCHED_ADJUST_PRIORITY s390_adjust_priority
9265 #undef TARGET_SCHED_ISSUE_RATE
9266 #define TARGET_SCHED_ISSUE_RATE s390_issue_rate
9267 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
9268 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD s390_first_cycle_multipass_dfa_lookahead
9270 #undef TARGET_CANNOT_COPY_INSN_P
9271 #define TARGET_CANNOT_COPY_INSN_P s390_cannot_copy_insn_p
9272 #undef TARGET_RTX_COSTS
9273 #define TARGET_RTX_COSTS s390_rtx_costs
9274 #undef TARGET_ADDRESS_COST
9275 #define TARGET_ADDRESS_COST s390_address_cost
9277 #undef TARGET_MACHINE_DEPENDENT_REORG
9278 #define TARGET_MACHINE_DEPENDENT_REORG s390_reorg
9280 #undef TARGET_VALID_POINTER_MODE
9281 #define TARGET_VALID_POINTER_MODE s390_valid_pointer_mode
9283 #undef TARGET_BUILD_BUILTIN_VA_LIST
9284 #define TARGET_BUILD_BUILTIN_VA_LIST s390_build_builtin_va_list
9285 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
9286 #define TARGET_GIMPLIFY_VA_ARG_EXPR s390_gimplify_va_arg
9288 #undef TARGET_PROMOTE_FUNCTION_ARGS
9289 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
9290 #undef TARGET_PROMOTE_FUNCTION_RETURN
9291 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
9292 #undef TARGET_PASS_BY_REFERENCE
9293 #define TARGET_PASS_BY_REFERENCE s390_pass_by_reference
9295 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
9296 #define TARGET_FUNCTION_OK_FOR_SIBCALL s390_function_ok_for_sibcall
9298 #undef TARGET_FIXED_CONDITION_CODE_REGS
9299 #define TARGET_FIXED_CONDITION_CODE_REGS s390_fixed_condition_code_regs
9301 #undef TARGET_CC_MODES_COMPATIBLE
9302 #define TARGET_CC_MODES_COMPATIBLE s390_cc_modes_compatible
9304 #undef TARGET_INVALID_WITHIN_DOLOOP
9305 #define TARGET_INVALID_WITHIN_DOLOOP hook_constcharptr_rtx_null
9308 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
9309 #define TARGET_ASM_OUTPUT_DWARF_DTPREL s390_output_dwarf_dtprel
9312 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
9313 #undef TARGET_MANGLE_FUNDAMENTAL_TYPE
9314 #define TARGET_MANGLE_FUNDAMENTAL_TYPE s390_mangle_fundamental_type
9317 #undef TARGET_SCALAR_MODE_SUPPORTED_P
9318 #define TARGET_SCALAR_MODE_SUPPORTED_P s390_scalar_mode_supported_p
9320 struct gcc_target targetm
= TARGET_INITIALIZER
;
9322 #include "gt-s390.h"