1 /* Subroutines used for code generation on IBM S/390 and zSeries
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
3 2007 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"
57 /* Define the specific costs for a given cpu. */
59 struct processor_costs
62 const int m
; /* cost of an M instruction. */
63 const int mghi
; /* cost of an MGHI instruction. */
64 const int mh
; /* cost of an MH instruction. */
65 const int mhi
; /* cost of an MHI instruction. */
66 const int ml
; /* cost of an ML instruction. */
67 const int mr
; /* cost of an MR instruction. */
68 const int ms
; /* cost of an MS instruction. */
69 const int msg
; /* cost of an MSG instruction. */
70 const int msgf
; /* cost of an MSGF instruction. */
71 const int msgfr
; /* cost of an MSGFR instruction. */
72 const int msgr
; /* cost of an MSGR instruction. */
73 const int msr
; /* cost of an MSR instruction. */
74 const int mult_df
; /* cost of multiplication in DFmode. */
77 const int sqxbr
; /* cost of square root in TFmode. */
78 const int sqdbr
; /* cost of square root in DFmode. */
79 const int sqebr
; /* cost of square root in SFmode. */
80 /* multiply and add */
81 const int madbr
; /* cost of multiply and add in DFmode. */
82 const int maebr
; /* cost of multiply and add in SFmode. */
94 const struct processor_costs
*s390_cost
;
97 struct processor_costs z900_cost
=
99 COSTS_N_INSNS (5), /* M */
100 COSTS_N_INSNS (10), /* MGHI */
101 COSTS_N_INSNS (5), /* MH */
102 COSTS_N_INSNS (4), /* MHI */
103 COSTS_N_INSNS (5), /* ML */
104 COSTS_N_INSNS (5), /* MR */
105 COSTS_N_INSNS (4), /* MS */
106 COSTS_N_INSNS (15), /* MSG */
107 COSTS_N_INSNS (7), /* MSGF */
108 COSTS_N_INSNS (7), /* MSGFR */
109 COSTS_N_INSNS (10), /* MSGR */
110 COSTS_N_INSNS (4), /* MSR */
111 COSTS_N_INSNS (7), /* multiplication in DFmode */
112 COSTS_N_INSNS (13), /* MXBR */
113 COSTS_N_INSNS (136), /* SQXBR */
114 COSTS_N_INSNS (44), /* SQDBR */
115 COSTS_N_INSNS (35), /* SQEBR */
116 COSTS_N_INSNS (18), /* MADBR */
117 COSTS_N_INSNS (13), /* MAEBR */
118 COSTS_N_INSNS (134), /* DXBR */
119 COSTS_N_INSNS (30), /* DDBR */
120 COSTS_N_INSNS (27), /* DEBR */
121 COSTS_N_INSNS (220), /* DLGR */
122 COSTS_N_INSNS (34), /* DLR */
123 COSTS_N_INSNS (34), /* DR */
124 COSTS_N_INSNS (32), /* DSGFR */
125 COSTS_N_INSNS (32), /* DSGR */
129 struct processor_costs z990_cost
=
131 COSTS_N_INSNS (4), /* M */
132 COSTS_N_INSNS (2), /* MGHI */
133 COSTS_N_INSNS (2), /* MH */
134 COSTS_N_INSNS (2), /* MHI */
135 COSTS_N_INSNS (4), /* ML */
136 COSTS_N_INSNS (4), /* MR */
137 COSTS_N_INSNS (5), /* MS */
138 COSTS_N_INSNS (6), /* MSG */
139 COSTS_N_INSNS (4), /* MSGF */
140 COSTS_N_INSNS (4), /* MSGFR */
141 COSTS_N_INSNS (4), /* MSGR */
142 COSTS_N_INSNS (4), /* MSR */
143 COSTS_N_INSNS (1), /* multiplication in DFmode */
144 COSTS_N_INSNS (28), /* MXBR */
145 COSTS_N_INSNS (130), /* SQXBR */
146 COSTS_N_INSNS (66), /* SQDBR */
147 COSTS_N_INSNS (38), /* SQEBR */
148 COSTS_N_INSNS (1), /* MADBR */
149 COSTS_N_INSNS (1), /* MAEBR */
150 COSTS_N_INSNS (60), /* DXBR */
151 COSTS_N_INSNS (40), /* DDBR */
152 COSTS_N_INSNS (26), /* DEBR */
153 COSTS_N_INSNS (176), /* DLGR */
154 COSTS_N_INSNS (31), /* DLR */
155 COSTS_N_INSNS (31), /* DR */
156 COSTS_N_INSNS (31), /* DSGFR */
157 COSTS_N_INSNS (31), /* DSGR */
161 struct processor_costs z9_109_cost
=
163 COSTS_N_INSNS (4), /* M */
164 COSTS_N_INSNS (2), /* MGHI */
165 COSTS_N_INSNS (2), /* MH */
166 COSTS_N_INSNS (2), /* MHI */
167 COSTS_N_INSNS (4), /* ML */
168 COSTS_N_INSNS (4), /* MR */
169 COSTS_N_INSNS (5), /* MS */
170 COSTS_N_INSNS (6), /* MSG */
171 COSTS_N_INSNS (4), /* MSGF */
172 COSTS_N_INSNS (4), /* MSGFR */
173 COSTS_N_INSNS (4), /* MSGR */
174 COSTS_N_INSNS (4), /* MSR */
175 COSTS_N_INSNS (1), /* multiplication in DFmode */
176 COSTS_N_INSNS (28), /* MXBR */
177 COSTS_N_INSNS (130), /* SQXBR */
178 COSTS_N_INSNS (66), /* SQDBR */
179 COSTS_N_INSNS (38), /* SQEBR */
180 COSTS_N_INSNS (1), /* MADBR */
181 COSTS_N_INSNS (1), /* MAEBR */
182 COSTS_N_INSNS (60), /* DXBR */
183 COSTS_N_INSNS (40), /* DDBR */
184 COSTS_N_INSNS (26), /* DEBR */
185 COSTS_N_INSNS (30), /* DLGR */
186 COSTS_N_INSNS (23), /* DLR */
187 COSTS_N_INSNS (23), /* DR */
188 COSTS_N_INSNS (24), /* DSGFR */
189 COSTS_N_INSNS (24), /* DSGR */
192 extern int reload_completed
;
194 /* Save information from a "cmpxx" operation until the branch or scc is
196 rtx s390_compare_op0
, s390_compare_op1
;
198 /* Save the result of a compare_and_swap until the branch or scc is
200 rtx s390_compare_emitted
= NULL_RTX
;
202 /* Structure used to hold the components of a S/390 memory
203 address. A legitimate address on S/390 is of the general
205 base + index + displacement
206 where any of the components is optional.
208 base and index are registers of the class ADDR_REGS,
209 displacement is an unsigned 12-bit immediate constant. */
220 /* Which cpu are we tuning for. */
221 enum processor_type s390_tune
= PROCESSOR_max
;
222 enum processor_flags s390_tune_flags
;
223 /* Which instruction set architecture to use. */
224 enum processor_type s390_arch
;
225 enum processor_flags s390_arch_flags
;
227 HOST_WIDE_INT s390_warn_framesize
= 0;
228 HOST_WIDE_INT s390_stack_size
= 0;
229 HOST_WIDE_INT s390_stack_guard
= 0;
231 /* The following structure is embedded in the machine
232 specific part of struct function. */
234 struct s390_frame_layout
GTY (())
236 /* Offset within stack frame. */
237 HOST_WIDE_INT gprs_offset
;
238 HOST_WIDE_INT f0_offset
;
239 HOST_WIDE_INT f4_offset
;
240 HOST_WIDE_INT f8_offset
;
241 HOST_WIDE_INT backchain_offset
;
243 /* Number of first and last gpr where slots in the register
244 save area are reserved for. */
245 int first_save_gpr_slot
;
246 int last_save_gpr_slot
;
248 /* Number of first and last gpr to be saved, restored. */
250 int first_restore_gpr
;
252 int last_restore_gpr
;
254 /* Bits standing for floating point registers. Set, if the
255 respective register has to be saved. Starting with reg 16 (f0)
256 at the rightmost bit.
257 Bit 15 - 8 7 6 5 4 3 2 1 0
258 fpr 15 - 8 7 5 3 1 6 4 2 0
259 reg 31 - 24 23 22 21 20 19 18 17 16 */
260 unsigned int fpr_bitmap
;
262 /* Number of floating point registers f8-f15 which must be saved. */
265 /* Set if return address needs to be saved.
266 This flag is set by s390_return_addr_rtx if it could not use
267 the initial value of r14 and therefore depends on r14 saved
269 bool save_return_addr_p
;
271 /* Size of stack frame. */
272 HOST_WIDE_INT frame_size
;
275 /* Define the structure for the machine field in struct function. */
277 struct machine_function
GTY(())
279 struct s390_frame_layout frame_layout
;
281 /* Literal pool base register. */
284 /* True if we may need to perform branch splitting. */
285 bool split_branches_pending_p
;
287 /* True during final stage of literal pool processing. */
288 bool decomposed_literal_pool_addresses_ok_p
;
290 /* Some local-dynamic TLS symbol name. */
291 const char *some_ld_name
;
293 bool has_landing_pad_p
;
296 /* Few accessor macros for struct cfun->machine->s390_frame_layout. */
298 #define cfun_frame_layout (cfun->machine->frame_layout)
299 #define cfun_save_high_fprs_p (!!cfun_frame_layout.high_fprs)
300 #define cfun_gprs_save_area_size ((cfun_frame_layout.last_save_gpr_slot - \
301 cfun_frame_layout.first_save_gpr_slot + 1) * UNITS_PER_WORD)
302 #define cfun_set_fpr_bit(BITNUM) (cfun->machine->frame_layout.fpr_bitmap |= \
304 #define cfun_fpr_bit_p(BITNUM) (!!(cfun->machine->frame_layout.fpr_bitmap & \
307 /* Number of GPRs and FPRs used for argument passing. */
308 #define GP_ARG_NUM_REG 5
309 #define FP_ARG_NUM_REG (TARGET_64BIT? 4 : 2)
311 /* A couple of shortcuts. */
312 #define CONST_OK_FOR_J(x) \
313 CONST_OK_FOR_CONSTRAINT_P((x), 'J', "J")
314 #define CONST_OK_FOR_K(x) \
315 CONST_OK_FOR_CONSTRAINT_P((x), 'K', "K")
316 #define CONST_OK_FOR_Os(x) \
317 CONST_OK_FOR_CONSTRAINT_P((x), 'O', "Os")
318 #define CONST_OK_FOR_Op(x) \
319 CONST_OK_FOR_CONSTRAINT_P((x), 'O', "Op")
320 #define CONST_OK_FOR_On(x) \
321 CONST_OK_FOR_CONSTRAINT_P((x), 'O', "On")
323 #define REGNO_PAIR_OK(REGNO, MODE) \
324 (HARD_REGNO_NREGS ((REGNO), (MODE)) == 1 || !((REGNO) & 1))
326 static enum machine_mode
327 s390_libgcc_cmp_return_mode (void)
329 return TARGET_64BIT
? DImode
: SImode
;
332 static enum machine_mode
333 s390_libgcc_shift_count_mode (void)
335 return TARGET_64BIT
? DImode
: SImode
;
338 /* Return true if the back end supports mode MODE. */
340 s390_scalar_mode_supported_p (enum machine_mode mode
)
342 if (DECIMAL_FLOAT_MODE_P (mode
))
345 return default_scalar_mode_supported_p (mode
);
348 /* Set the has_landing_pad_p flag in struct machine_function to VALUE. */
351 s390_set_has_landing_pad_p (bool value
)
353 cfun
->machine
->has_landing_pad_p
= value
;
356 /* If two condition code modes are compatible, return a condition code
357 mode which is compatible with both. Otherwise, return
360 static enum machine_mode
361 s390_cc_modes_compatible (enum machine_mode m1
, enum machine_mode m2
)
369 if (m2
== CCUmode
|| m2
== CCTmode
|| m2
== CCZ1mode
370 || m2
== CCSmode
|| m2
== CCSRmode
|| m2
== CCURmode
)
391 /* Return true if SET either doesn't set the CC register, or else
392 the source and destination have matching CC modes and that
393 CC mode is at least as constrained as REQ_MODE. */
396 s390_match_ccmode_set (rtx set
, enum machine_mode req_mode
)
398 enum machine_mode set_mode
;
400 gcc_assert (GET_CODE (set
) == SET
);
402 if (GET_CODE (SET_DEST (set
)) != REG
|| !CC_REGNO_P (REGNO (SET_DEST (set
))))
405 set_mode
= GET_MODE (SET_DEST (set
));
419 if (req_mode
!= set_mode
)
424 if (req_mode
!= CCSmode
&& req_mode
!= CCUmode
&& req_mode
!= CCTmode
425 && req_mode
!= CCSRmode
&& req_mode
!= CCURmode
)
431 if (req_mode
!= CCAmode
)
439 return (GET_MODE (SET_SRC (set
)) == set_mode
);
442 /* Return true if every SET in INSN that sets the CC register
443 has source and destination with matching CC modes and that
444 CC mode is at least as constrained as REQ_MODE.
445 If REQ_MODE is VOIDmode, always return false. */
448 s390_match_ccmode (rtx insn
, enum machine_mode req_mode
)
452 /* s390_tm_ccmode returns VOIDmode to indicate failure. */
453 if (req_mode
== VOIDmode
)
456 if (GET_CODE (PATTERN (insn
)) == SET
)
457 return s390_match_ccmode_set (PATTERN (insn
), req_mode
);
459 if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
460 for (i
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
462 rtx set
= XVECEXP (PATTERN (insn
), 0, i
);
463 if (GET_CODE (set
) == SET
)
464 if (!s390_match_ccmode_set (set
, req_mode
))
471 /* If a test-under-mask instruction can be used to implement
472 (compare (and ... OP1) OP2), return the CC mode required
473 to do that. Otherwise, return VOIDmode.
474 MIXED is true if the instruction can distinguish between
475 CC1 and CC2 for mixed selected bits (TMxx), it is false
476 if the instruction cannot (TM). */
479 s390_tm_ccmode (rtx op1
, rtx op2
, bool mixed
)
483 /* ??? Fixme: should work on CONST_DOUBLE as well. */
484 if (GET_CODE (op1
) != CONST_INT
|| GET_CODE (op2
) != CONST_INT
)
487 /* Selected bits all zero: CC0.
488 e.g.: int a; if ((a & (16 + 128)) == 0) */
489 if (INTVAL (op2
) == 0)
492 /* Selected bits all one: CC3.
493 e.g.: int a; if ((a & (16 + 128)) == 16 + 128) */
494 if (INTVAL (op2
) == INTVAL (op1
))
497 /* Exactly two bits selected, mixed zeroes and ones: CC1 or CC2. e.g.:
499 if ((a & (16 + 128)) == 16) -> CCT1
500 if ((a & (16 + 128)) == 128) -> CCT2 */
503 bit1
= exact_log2 (INTVAL (op2
));
504 bit0
= exact_log2 (INTVAL (op1
) ^ INTVAL (op2
));
505 if (bit0
!= -1 && bit1
!= -1)
506 return bit0
> bit1
? CCT1mode
: CCT2mode
;
512 /* Given a comparison code OP (EQ, NE, etc.) and the operands
513 OP0 and OP1 of a COMPARE, return the mode to be used for the
517 s390_select_ccmode (enum rtx_code code
, rtx op0
, rtx op1
)
523 if ((GET_CODE (op0
) == NEG
|| GET_CODE (op0
) == ABS
)
524 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
526 if (GET_CODE (op0
) == PLUS
&& GET_CODE (XEXP (op0
, 1)) == CONST_INT
527 && CONST_OK_FOR_K (INTVAL (XEXP (op0
, 1))))
529 if ((GET_CODE (op0
) == PLUS
|| GET_CODE (op0
) == MINUS
530 || GET_CODE (op1
) == NEG
)
531 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
534 if (GET_CODE (op0
) == AND
)
536 /* Check whether we can potentially do it via TM. */
537 enum machine_mode ccmode
;
538 ccmode
= s390_tm_ccmode (XEXP (op0
, 1), op1
, 1);
539 if (ccmode
!= VOIDmode
)
541 /* Relax CCTmode to CCZmode to allow fall-back to AND
542 if that turns out to be beneficial. */
543 return ccmode
== CCTmode
? CCZmode
: ccmode
;
547 if (register_operand (op0
, HImode
)
548 && GET_CODE (op1
) == CONST_INT
549 && (INTVAL (op1
) == -1 || INTVAL (op1
) == 65535))
551 if (register_operand (op0
, QImode
)
552 && GET_CODE (op1
) == CONST_INT
553 && (INTVAL (op1
) == -1 || INTVAL (op1
) == 255))
562 /* The only overflow condition of NEG and ABS happens when
563 -INT_MAX is used as parameter, which stays negative. So
564 we have an overflow from a positive value to a negative.
565 Using CCAP mode the resulting cc can be used for comparisons. */
566 if ((GET_CODE (op0
) == NEG
|| GET_CODE (op0
) == ABS
)
567 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
570 /* If constants are involved in an add instruction it is possible to use
571 the resulting cc for comparisons with zero. Knowing the sign of the
572 constant the overflow behavior gets predictable. e.g.:
573 int a, b; if ((b = a + c) > 0)
574 with c as a constant value: c < 0 -> CCAN and c >= 0 -> CCAP */
575 if (GET_CODE (op0
) == PLUS
&& GET_CODE (XEXP (op0
, 1)) == CONST_INT
576 && CONST_OK_FOR_K (INTVAL (XEXP (op0
, 1))))
578 if (INTVAL (XEXP((op0
), 1)) < 0)
592 if ((GET_CODE (op0
) == SIGN_EXTEND
|| GET_CODE (op0
) == ZERO_EXTEND
)
593 && GET_CODE (op1
) != CONST_INT
)
599 if (GET_CODE (op0
) == PLUS
600 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
603 if ((GET_CODE (op0
) == SIGN_EXTEND
|| GET_CODE (op0
) == ZERO_EXTEND
)
604 && GET_CODE (op1
) != CONST_INT
)
610 if (GET_CODE (op0
) == MINUS
611 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
614 if ((GET_CODE (op0
) == SIGN_EXTEND
|| GET_CODE (op0
) == ZERO_EXTEND
)
615 && GET_CODE (op1
) != CONST_INT
)
624 /* Replace the comparison OP0 CODE OP1 by a semantically equivalent one
625 that we can implement more efficiently. */
628 s390_canonicalize_comparison (enum rtx_code
*code
, rtx
*op0
, rtx
*op1
)
630 /* Convert ZERO_EXTRACT back to AND to enable TM patterns. */
631 if ((*code
== EQ
|| *code
== NE
)
632 && *op1
== const0_rtx
633 && GET_CODE (*op0
) == ZERO_EXTRACT
634 && GET_CODE (XEXP (*op0
, 1)) == CONST_INT
635 && GET_CODE (XEXP (*op0
, 2)) == CONST_INT
636 && SCALAR_INT_MODE_P (GET_MODE (XEXP (*op0
, 0))))
638 rtx inner
= XEXP (*op0
, 0);
639 HOST_WIDE_INT modesize
= GET_MODE_BITSIZE (GET_MODE (inner
));
640 HOST_WIDE_INT len
= INTVAL (XEXP (*op0
, 1));
641 HOST_WIDE_INT pos
= INTVAL (XEXP (*op0
, 2));
643 if (len
> 0 && len
< modesize
644 && pos
>= 0 && pos
+ len
<= modesize
645 && modesize
<= HOST_BITS_PER_WIDE_INT
)
647 unsigned HOST_WIDE_INT block
;
648 block
= ((unsigned HOST_WIDE_INT
) 1 << len
) - 1;
649 block
<<= modesize
- pos
- len
;
651 *op0
= gen_rtx_AND (GET_MODE (inner
), inner
,
652 gen_int_mode (block
, GET_MODE (inner
)));
656 /* Narrow AND of memory against immediate to enable TM. */
657 if ((*code
== EQ
|| *code
== NE
)
658 && *op1
== const0_rtx
659 && GET_CODE (*op0
) == AND
660 && GET_CODE (XEXP (*op0
, 1)) == CONST_INT
661 && SCALAR_INT_MODE_P (GET_MODE (XEXP (*op0
, 0))))
663 rtx inner
= XEXP (*op0
, 0);
664 rtx mask
= XEXP (*op0
, 1);
666 /* Ignore paradoxical SUBREGs if all extra bits are masked out. */
667 if (GET_CODE (inner
) == SUBREG
668 && SCALAR_INT_MODE_P (GET_MODE (SUBREG_REG (inner
)))
669 && (GET_MODE_SIZE (GET_MODE (inner
))
670 >= GET_MODE_SIZE (GET_MODE (SUBREG_REG (inner
))))
672 & GET_MODE_MASK (GET_MODE (inner
))
673 & ~GET_MODE_MASK (GET_MODE (SUBREG_REG (inner
))))
675 inner
= SUBREG_REG (inner
);
677 /* Do not change volatile MEMs. */
678 if (MEM_P (inner
) && !MEM_VOLATILE_P (inner
))
680 int part
= s390_single_part (XEXP (*op0
, 1),
681 GET_MODE (inner
), QImode
, 0);
684 mask
= gen_int_mode (s390_extract_part (mask
, QImode
, 0), QImode
);
685 inner
= adjust_address_nv (inner
, QImode
, part
);
686 *op0
= gen_rtx_AND (QImode
, inner
, mask
);
691 /* Narrow comparisons against 0xffff to HImode if possible. */
692 if ((*code
== EQ
|| *code
== NE
)
693 && GET_CODE (*op1
) == CONST_INT
694 && INTVAL (*op1
) == 0xffff
695 && SCALAR_INT_MODE_P (GET_MODE (*op0
))
696 && (nonzero_bits (*op0
, GET_MODE (*op0
))
697 & ~(unsigned HOST_WIDE_INT
) 0xffff) == 0)
699 *op0
= gen_lowpart (HImode
, *op0
);
703 /* Remove redundant UNSPEC_CCU_TO_INT conversions if possible. */
704 if (GET_CODE (*op0
) == UNSPEC
705 && XINT (*op0
, 1) == UNSPEC_CCU_TO_INT
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 /* Remove redundant UNSPEC_CCZ_TO_INT conversions if possible. */
732 if (GET_CODE (*op0
) == UNSPEC
733 && XINT (*op0
, 1) == UNSPEC_CCZ_TO_INT
734 && XVECLEN (*op0
, 0) == 1
735 && GET_MODE (XVECEXP (*op0
, 0, 0)) == CCZmode
736 && GET_CODE (XVECEXP (*op0
, 0, 0)) == REG
737 && REGNO (XVECEXP (*op0
, 0, 0)) == CC_REGNUM
738 && *op1
== const0_rtx
)
740 enum rtx_code new_code
= UNKNOWN
;
743 case EQ
: new_code
= EQ
; break;
744 case NE
: new_code
= NE
; break;
748 if (new_code
!= UNKNOWN
)
750 *op0
= XVECEXP (*op0
, 0, 0);
755 /* Simplify cascaded EQ, NE with const0_rtx. */
756 if ((*code
== NE
|| *code
== EQ
)
757 && (GET_CODE (*op0
) == EQ
|| GET_CODE (*op0
) == NE
)
758 && GET_MODE (*op0
) == SImode
759 && GET_MODE (XEXP (*op0
, 0)) == CCZ1mode
760 && REG_P (XEXP (*op0
, 0))
761 && XEXP (*op0
, 1) == const0_rtx
762 && *op1
== const0_rtx
)
764 if ((*code
== EQ
&& GET_CODE (*op0
) == NE
)
765 || (*code
== NE
&& GET_CODE (*op0
) == EQ
))
769 *op0
= XEXP (*op0
, 0);
772 /* Prefer register over memory as first operand. */
773 if (MEM_P (*op0
) && REG_P (*op1
))
775 rtx tem
= *op0
; *op0
= *op1
; *op1
= tem
;
776 *code
= swap_condition (*code
);
780 /* Emit a compare instruction suitable to implement the comparison
781 OP0 CODE OP1. Return the correct condition RTL to be placed in
782 the IF_THEN_ELSE of the conditional branch testing the result. */
785 s390_emit_compare (enum rtx_code code
, rtx op0
, rtx op1
)
787 enum machine_mode mode
= s390_select_ccmode (code
, op0
, op1
);
790 /* Do not output a redundant compare instruction if a compare_and_swap
791 pattern already computed the result and the machine modes are compatible. */
792 if (s390_compare_emitted
793 && (s390_cc_modes_compatible (GET_MODE (s390_compare_emitted
), mode
)
794 == GET_MODE (s390_compare_emitted
)))
795 ret
= gen_rtx_fmt_ee (code
, VOIDmode
, s390_compare_emitted
, const0_rtx
);
798 rtx cc
= gen_rtx_REG (mode
, CC_REGNUM
);
800 emit_insn (gen_rtx_SET (VOIDmode
, cc
, gen_rtx_COMPARE (mode
, op0
, op1
)));
801 ret
= gen_rtx_fmt_ee (code
, VOIDmode
, cc
, const0_rtx
);
803 s390_compare_emitted
= NULL_RTX
;
807 /* Emit a SImode compare and swap instruction setting MEM to NEW if OLD
809 Return the correct condition RTL to be placed in the IF_THEN_ELSE of the
810 conditional branch testing the result. */
813 s390_emit_compare_and_swap (enum rtx_code code
, rtx old
, rtx mem
, rtx cmp
, rtx
new)
817 emit_insn (gen_sync_compare_and_swap_ccsi (old
, mem
, cmp
, new));
818 ret
= gen_rtx_fmt_ee (code
, VOIDmode
, s390_compare_emitted
, const0_rtx
);
820 s390_compare_emitted
= NULL_RTX
;
825 /* Emit a jump instruction to TARGET. If COND is NULL_RTX, emit an
826 unconditional jump, else a conditional jump under condition COND. */
829 s390_emit_jump (rtx target
, rtx cond
)
833 target
= gen_rtx_LABEL_REF (VOIDmode
, target
);
835 target
= gen_rtx_IF_THEN_ELSE (VOIDmode
, cond
, target
, pc_rtx
);
837 insn
= gen_rtx_SET (VOIDmode
, pc_rtx
, target
);
838 emit_jump_insn (insn
);
841 /* Return branch condition mask to implement a branch
842 specified by CODE. Return -1 for invalid comparisons. */
845 s390_branch_condition_mask (rtx code
)
847 const int CC0
= 1 << 3;
848 const int CC1
= 1 << 2;
849 const int CC2
= 1 << 1;
850 const int CC3
= 1 << 0;
852 gcc_assert (GET_CODE (XEXP (code
, 0)) == REG
);
853 gcc_assert (REGNO (XEXP (code
, 0)) == CC_REGNUM
);
854 gcc_assert (XEXP (code
, 1) == const0_rtx
);
856 switch (GET_MODE (XEXP (code
, 0)))
860 switch (GET_CODE (code
))
863 case NE
: return CC1
| CC2
| CC3
;
869 switch (GET_CODE (code
))
872 case NE
: return CC0
| CC2
| CC3
;
878 switch (GET_CODE (code
))
881 case NE
: return CC0
| CC1
| CC3
;
887 switch (GET_CODE (code
))
890 case NE
: return CC0
| CC1
| CC2
;
896 switch (GET_CODE (code
))
898 case EQ
: return CC0
| CC2
;
899 case NE
: return CC1
| CC3
;
905 switch (GET_CODE (code
))
907 case LTU
: return CC2
| CC3
; /* carry */
908 case GEU
: return CC0
| CC1
; /* no carry */
914 switch (GET_CODE (code
))
916 case GTU
: return CC0
| CC1
; /* borrow */
917 case LEU
: return CC2
| CC3
; /* no borrow */
923 switch (GET_CODE (code
))
925 case EQ
: return CC0
| CC2
;
926 case NE
: return CC1
| CC3
;
927 case LTU
: return CC1
;
928 case GTU
: return CC3
;
929 case LEU
: return CC1
| CC2
;
930 case GEU
: return CC2
| CC3
;
935 switch (GET_CODE (code
))
938 case NE
: return CC1
| CC2
| CC3
;
939 case LTU
: return CC1
;
940 case GTU
: return CC2
;
941 case LEU
: return CC0
| CC1
;
942 case GEU
: return CC0
| CC2
;
948 switch (GET_CODE (code
))
951 case NE
: return CC2
| CC1
| CC3
;
952 case LTU
: return CC2
;
953 case GTU
: return CC1
;
954 case LEU
: return CC0
| CC2
;
955 case GEU
: return CC0
| CC1
;
961 switch (GET_CODE (code
))
964 case NE
: return CC1
| CC2
| CC3
;
965 case LT
: return CC1
| CC3
;
967 case LE
: return CC0
| CC1
| CC3
;
968 case GE
: return CC0
| CC2
;
974 switch (GET_CODE (code
))
977 case NE
: return CC1
| CC2
| CC3
;
979 case GT
: return CC2
| CC3
;
980 case LE
: return CC0
| CC1
;
981 case GE
: return CC0
| CC2
| CC3
;
987 switch (GET_CODE (code
))
990 case NE
: return CC1
| CC2
| CC3
;
993 case LE
: return CC0
| CC1
;
994 case GE
: return CC0
| CC2
;
995 case UNORDERED
: return CC3
;
996 case ORDERED
: return CC0
| CC1
| CC2
;
997 case UNEQ
: return CC0
| CC3
;
998 case UNLT
: return CC1
| CC3
;
999 case UNGT
: return CC2
| CC3
;
1000 case UNLE
: return CC0
| CC1
| CC3
;
1001 case UNGE
: return CC0
| CC2
| CC3
;
1002 case LTGT
: return CC1
| CC2
;
1008 switch (GET_CODE (code
))
1010 case EQ
: return CC0
;
1011 case NE
: return CC2
| CC1
| CC3
;
1012 case LT
: return CC2
;
1013 case GT
: return CC1
;
1014 case LE
: return CC0
| CC2
;
1015 case GE
: return CC0
| CC1
;
1016 case UNORDERED
: return CC3
;
1017 case ORDERED
: return CC0
| CC2
| CC1
;
1018 case UNEQ
: return CC0
| CC3
;
1019 case UNLT
: return CC2
| CC3
;
1020 case UNGT
: return CC1
| CC3
;
1021 case UNLE
: return CC0
| CC2
| CC3
;
1022 case UNGE
: return CC0
| CC1
| CC3
;
1023 case LTGT
: return CC2
| CC1
;
1033 /* If INV is false, return assembler mnemonic string to implement
1034 a branch specified by CODE. If INV is true, return mnemonic
1035 for the corresponding inverted branch. */
1038 s390_branch_condition_mnemonic (rtx code
, int inv
)
1040 static const char *const mnemonic
[16] =
1042 NULL
, "o", "h", "nle",
1043 "l", "nhe", "lh", "ne",
1044 "e", "nlh", "he", "nl",
1045 "le", "nh", "no", NULL
1048 int mask
= s390_branch_condition_mask (code
);
1049 gcc_assert (mask
>= 0);
1054 gcc_assert (mask
>= 1 && mask
<= 14);
1056 return mnemonic
[mask
];
1059 /* Return the part of op which has a value different from def.
1060 The size of the part is determined by mode.
1061 Use this function only if you already know that op really
1062 contains such a part. */
1064 unsigned HOST_WIDE_INT
1065 s390_extract_part (rtx op
, enum machine_mode mode
, int def
)
1067 unsigned HOST_WIDE_INT value
= 0;
1068 int max_parts
= HOST_BITS_PER_WIDE_INT
/ GET_MODE_BITSIZE (mode
);
1069 int part_bits
= GET_MODE_BITSIZE (mode
);
1070 unsigned HOST_WIDE_INT part_mask
1071 = ((unsigned HOST_WIDE_INT
)1 << part_bits
) - 1;
1074 for (i
= 0; i
< max_parts
; i
++)
1077 value
= (unsigned HOST_WIDE_INT
) INTVAL (op
);
1079 value
>>= part_bits
;
1081 if ((value
& part_mask
) != (def
& part_mask
))
1082 return value
& part_mask
;
1088 /* If OP is an integer constant of mode MODE with exactly one
1089 part of mode PART_MODE unequal to DEF, return the number of that
1090 part. Otherwise, return -1. */
1093 s390_single_part (rtx op
,
1094 enum machine_mode mode
,
1095 enum machine_mode part_mode
,
1098 unsigned HOST_WIDE_INT value
= 0;
1099 int n_parts
= GET_MODE_SIZE (mode
) / GET_MODE_SIZE (part_mode
);
1100 unsigned HOST_WIDE_INT part_mask
1101 = ((unsigned HOST_WIDE_INT
)1 << GET_MODE_BITSIZE (part_mode
)) - 1;
1104 if (GET_CODE (op
) != CONST_INT
)
1107 for (i
= 0; i
< n_parts
; i
++)
1110 value
= (unsigned HOST_WIDE_INT
) INTVAL (op
);
1112 value
>>= GET_MODE_BITSIZE (part_mode
);
1114 if ((value
& part_mask
) != (def
& part_mask
))
1122 return part
== -1 ? -1 : n_parts
- 1 - part
;
1125 /* Check whether we can (and want to) split a double-word
1126 move in mode MODE from SRC to DST into two single-word
1127 moves, moving the subword FIRST_SUBWORD first. */
1130 s390_split_ok_p (rtx dst
, rtx src
, enum machine_mode mode
, int first_subword
)
1132 /* Floating point registers cannot be split. */
1133 if (FP_REG_P (src
) || FP_REG_P (dst
))
1136 /* We don't need to split if operands are directly accessible. */
1137 if (s_operand (src
, mode
) || s_operand (dst
, mode
))
1140 /* Non-offsettable memory references cannot be split. */
1141 if ((GET_CODE (src
) == MEM
&& !offsettable_memref_p (src
))
1142 || (GET_CODE (dst
) == MEM
&& !offsettable_memref_p (dst
)))
1145 /* Moving the first subword must not clobber a register
1146 needed to move the second subword. */
1147 if (register_operand (dst
, mode
))
1149 rtx subreg
= operand_subword (dst
, first_subword
, 0, mode
);
1150 if (reg_overlap_mentioned_p (subreg
, src
))
1157 /* Return true if it can be proven that [MEM1, MEM1 + SIZE]
1158 and [MEM2, MEM2 + SIZE] do overlap and false
1162 s390_overlap_p (rtx mem1
, rtx mem2
, HOST_WIDE_INT size
)
1164 rtx addr1
, addr2
, addr_delta
;
1165 HOST_WIDE_INT delta
;
1167 if (GET_CODE (mem1
) != MEM
|| GET_CODE (mem2
) != MEM
)
1173 addr1
= XEXP (mem1
, 0);
1174 addr2
= XEXP (mem2
, 0);
1176 addr_delta
= simplify_binary_operation (MINUS
, Pmode
, addr2
, addr1
);
1178 /* This overlapping check is used by peepholes merging memory block operations.
1179 Overlapping operations would otherwise be recognized by the S/390 hardware
1180 and would fall back to a slower implementation. Allowing overlapping
1181 operations would lead to slow code but not to wrong code. Therefore we are
1182 somewhat optimistic if we cannot prove that the memory blocks are
1184 That's why we return false here although this may accept operations on
1185 overlapping memory areas. */
1186 if (!addr_delta
|| GET_CODE (addr_delta
) != CONST_INT
)
1189 delta
= INTVAL (addr_delta
);
1192 || (delta
> 0 && delta
< size
)
1193 || (delta
< 0 && -delta
< size
))
1199 /* Check whether the address of memory reference MEM2 equals exactly
1200 the address of memory reference MEM1 plus DELTA. Return true if
1201 we can prove this to be the case, false otherwise. */
1204 s390_offset_p (rtx mem1
, rtx mem2
, rtx delta
)
1206 rtx addr1
, addr2
, addr_delta
;
1208 if (GET_CODE (mem1
) != MEM
|| GET_CODE (mem2
) != MEM
)
1211 addr1
= XEXP (mem1
, 0);
1212 addr2
= XEXP (mem2
, 0);
1214 addr_delta
= simplify_binary_operation (MINUS
, Pmode
, addr2
, addr1
);
1215 if (!addr_delta
|| !rtx_equal_p (addr_delta
, delta
))
1221 /* Expand logical operator CODE in mode MODE with operands OPERANDS. */
1224 s390_expand_logical_operator (enum rtx_code code
, enum machine_mode mode
,
1227 enum machine_mode wmode
= mode
;
1228 rtx dst
= operands
[0];
1229 rtx src1
= operands
[1];
1230 rtx src2
= operands
[2];
1233 /* If we cannot handle the operation directly, use a temp register. */
1234 if (!s390_logical_operator_ok_p (operands
))
1235 dst
= gen_reg_rtx (mode
);
1237 /* QImode and HImode patterns make sense only if we have a destination
1238 in memory. Otherwise perform the operation in SImode. */
1239 if ((mode
== QImode
|| mode
== HImode
) && GET_CODE (dst
) != MEM
)
1242 /* Widen operands if required. */
1245 if (GET_CODE (dst
) == SUBREG
1246 && (tem
= simplify_subreg (wmode
, dst
, mode
, 0)) != 0)
1248 else if (REG_P (dst
))
1249 dst
= gen_rtx_SUBREG (wmode
, dst
, 0);
1251 dst
= gen_reg_rtx (wmode
);
1253 if (GET_CODE (src1
) == SUBREG
1254 && (tem
= simplify_subreg (wmode
, src1
, mode
, 0)) != 0)
1256 else if (GET_MODE (src1
) != VOIDmode
)
1257 src1
= gen_rtx_SUBREG (wmode
, force_reg (mode
, src1
), 0);
1259 if (GET_CODE (src2
) == SUBREG
1260 && (tem
= simplify_subreg (wmode
, src2
, mode
, 0)) != 0)
1262 else if (GET_MODE (src2
) != VOIDmode
)
1263 src2
= gen_rtx_SUBREG (wmode
, force_reg (mode
, src2
), 0);
1266 /* Emit the instruction. */
1267 op
= gen_rtx_SET (VOIDmode
, dst
, gen_rtx_fmt_ee (code
, wmode
, src1
, src2
));
1268 clob
= gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
1269 emit_insn (gen_rtx_PARALLEL (VOIDmode
, gen_rtvec (2, op
, clob
)));
1271 /* Fix up the destination if needed. */
1272 if (dst
!= operands
[0])
1273 emit_move_insn (operands
[0], gen_lowpart (mode
, dst
));
1276 /* Check whether OPERANDS are OK for a logical operation (AND, IOR, XOR). */
1279 s390_logical_operator_ok_p (rtx
*operands
)
1281 /* If the destination operand is in memory, it needs to coincide
1282 with one of the source operands. After reload, it has to be
1283 the first source operand. */
1284 if (GET_CODE (operands
[0]) == MEM
)
1285 return rtx_equal_p (operands
[0], operands
[1])
1286 || (!reload_completed
&& rtx_equal_p (operands
[0], operands
[2]));
1291 /* Narrow logical operation CODE of memory operand MEMOP with immediate
1292 operand IMMOP to switch from SS to SI type instructions. */
1295 s390_narrow_logical_operator (enum rtx_code code
, rtx
*memop
, rtx
*immop
)
1297 int def
= code
== AND
? -1 : 0;
1301 gcc_assert (GET_CODE (*memop
) == MEM
);
1302 gcc_assert (!MEM_VOLATILE_P (*memop
));
1304 mask
= s390_extract_part (*immop
, QImode
, def
);
1305 part
= s390_single_part (*immop
, GET_MODE (*memop
), QImode
, def
);
1306 gcc_assert (part
>= 0);
1308 *memop
= adjust_address (*memop
, QImode
, part
);
1309 *immop
= gen_int_mode (mask
, QImode
);
1313 /* How to allocate a 'struct machine_function'. */
1315 static struct machine_function
*
1316 s390_init_machine_status (void)
1318 return ggc_alloc_cleared (sizeof (struct machine_function
));
1321 /* Change optimizations to be performed, depending on the
1324 LEVEL is the optimization level specified; 2 if `-O2' is
1325 specified, 1 if `-O' is specified, and 0 if neither is specified.
1327 SIZE is nonzero if `-Os' is specified and zero otherwise. */
1330 optimization_options (int level ATTRIBUTE_UNUSED
, int size ATTRIBUTE_UNUSED
)
1332 /* ??? There are apparently still problems with -fcaller-saves. */
1333 flag_caller_saves
= 0;
1335 /* By default, always emit DWARF-2 unwind info. This allows debugging
1336 without maintaining a stack frame back-chain. */
1337 flag_asynchronous_unwind_tables
= 1;
1339 /* Use MVCLE instructions to decrease code size if requested. */
1341 target_flags
|= MASK_MVCLE
;
1344 /* Return true if ARG is the name of a processor. Set *TYPE and *FLAGS
1345 to the associated processor_type and processor_flags if so. */
1348 s390_handle_arch_option (const char *arg
,
1349 enum processor_type
*type
,
1350 enum processor_flags
*flags
)
1354 const char *const name
; /* processor name or nickname. */
1355 const enum processor_type processor
;
1356 const enum processor_flags flags
;
1358 const processor_alias_table
[] =
1360 {"g5", PROCESSOR_9672_G5
, PF_IEEE_FLOAT
},
1361 {"g6", PROCESSOR_9672_G6
, PF_IEEE_FLOAT
},
1362 {"z900", PROCESSOR_2064_Z900
, PF_IEEE_FLOAT
| PF_ZARCH
},
1363 {"z990", PROCESSOR_2084_Z990
, PF_IEEE_FLOAT
| PF_ZARCH
1364 | PF_LONG_DISPLACEMENT
},
1365 {"z9-109", PROCESSOR_2094_Z9_109
, PF_IEEE_FLOAT
| PF_ZARCH
1366 | PF_LONG_DISPLACEMENT
| PF_EXTIMM
},
1367 {"z9-ec", PROCESSOR_2094_Z9_109
, PF_IEEE_FLOAT
| PF_ZARCH
1368 | PF_LONG_DISPLACEMENT
| PF_EXTIMM
| PF_DFP
},
1372 for (i
= 0; i
< ARRAY_SIZE (processor_alias_table
); i
++)
1373 if (strcmp (arg
, processor_alias_table
[i
].name
) == 0)
1375 *type
= processor_alias_table
[i
].processor
;
1376 *flags
= processor_alias_table
[i
].flags
;
1382 /* Implement TARGET_HANDLE_OPTION. */
1385 s390_handle_option (size_t code
, const char *arg
, int value ATTRIBUTE_UNUSED
)
1390 return s390_handle_arch_option (arg
, &s390_arch
, &s390_arch_flags
);
1392 case OPT_mstack_guard_
:
1393 if (sscanf (arg
, HOST_WIDE_INT_PRINT_DEC
, &s390_stack_guard
) != 1)
1395 if (exact_log2 (s390_stack_guard
) == -1)
1396 error ("stack guard value must be an exact power of 2");
1399 case OPT_mstack_size_
:
1400 if (sscanf (arg
, HOST_WIDE_INT_PRINT_DEC
, &s390_stack_size
) != 1)
1402 if (exact_log2 (s390_stack_size
) == -1)
1403 error ("stack size must be an exact power of 2");
1407 return s390_handle_arch_option (arg
, &s390_tune
, &s390_tune_flags
);
1409 case OPT_mwarn_framesize_
:
1410 return sscanf (arg
, HOST_WIDE_INT_PRINT_DEC
, &s390_warn_framesize
) == 1;
1418 override_options (void)
1420 /* Set up function hooks. */
1421 init_machine_status
= s390_init_machine_status
;
1423 /* Architecture mode defaults according to ABI. */
1424 if (!(target_flags_explicit
& MASK_ZARCH
))
1427 target_flags
|= MASK_ZARCH
;
1429 target_flags
&= ~MASK_ZARCH
;
1432 /* Determine processor architectural level. */
1433 if (!s390_arch_string
)
1435 s390_arch_string
= TARGET_ZARCH
? "z900" : "g5";
1436 s390_handle_arch_option (s390_arch_string
, &s390_arch
, &s390_arch_flags
);
1439 /* Determine processor to tune for. */
1440 if (s390_tune
== PROCESSOR_max
)
1442 s390_tune
= s390_arch
;
1443 s390_tune_flags
= s390_arch_flags
;
1446 /* Sanity checks. */
1447 if (TARGET_ZARCH
&& !TARGET_CPU_ZARCH
)
1448 error ("z/Architecture mode not supported on %s", s390_arch_string
);
1449 if (TARGET_64BIT
&& !TARGET_ZARCH
)
1450 error ("64-bit ABI not supported in ESA/390 mode");
1452 if (TARGET_HARD_DFP
&& (!TARGET_CPU_DFP
|| !TARGET_ZARCH
))
1454 if (target_flags_explicit
& MASK_SOFT_DFP
)
1456 if (!TARGET_CPU_DFP
)
1457 error ("Hardware decimal floating point instructions"
1458 " not available on %s", s390_arch_string
);
1460 error ("Hardware decimal floating point instructions"
1461 " not available in ESA/390 mode");
1464 target_flags
|= MASK_SOFT_DFP
;
1467 if ((target_flags_explicit
& MASK_SOFT_FLOAT
) && TARGET_SOFT_FLOAT
)
1469 if ((target_flags_explicit
& MASK_SOFT_DFP
) && TARGET_HARD_DFP
)
1470 error ("-mhard-dfp can't be used in conjunction with -msoft-float");
1472 target_flags
|= MASK_SOFT_DFP
;
1475 /* Set processor cost function. */
1476 if (s390_tune
== PROCESSOR_2094_Z9_109
)
1477 s390_cost
= &z9_109_cost
;
1478 else if (s390_tune
== PROCESSOR_2084_Z990
)
1479 s390_cost
= &z990_cost
;
1481 s390_cost
= &z900_cost
;
1483 if (TARGET_BACKCHAIN
&& TARGET_PACKED_STACK
&& TARGET_HARD_FLOAT
)
1484 error ("-mbackchain -mpacked-stack -mhard-float are not supported "
1487 if (s390_stack_size
)
1489 if (s390_stack_guard
>= s390_stack_size
)
1490 error ("stack size must be greater than the stack guard value");
1491 else if (s390_stack_size
> 1 << 16)
1492 error ("stack size must not be greater than 64k");
1494 else if (s390_stack_guard
)
1495 error ("-mstack-guard implies use of -mstack-size");
1497 #ifdef TARGET_DEFAULT_LONG_DOUBLE_128
1498 if (!(target_flags_explicit
& MASK_LONG_DOUBLE_128
))
1499 target_flags
|= MASK_LONG_DOUBLE_128
;
1503 /* Map for smallest class containing reg regno. */
1505 const enum reg_class regclass_map
[FIRST_PSEUDO_REGISTER
] =
1506 { GENERAL_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1507 ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1508 ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1509 ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1510 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1511 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1512 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1513 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1514 ADDR_REGS
, CC_REGS
, ADDR_REGS
, ADDR_REGS
,
1515 ACCESS_REGS
, ACCESS_REGS
1518 /* Return attribute type of insn. */
1520 static enum attr_type
1521 s390_safe_attr_type (rtx insn
)
1523 if (recog_memoized (insn
) >= 0)
1524 return get_attr_type (insn
);
1529 /* Return true if DISP is a valid short displacement. */
1532 s390_short_displacement (rtx disp
)
1534 /* No displacement is OK. */
1538 /* Integer displacement in range. */
1539 if (GET_CODE (disp
) == CONST_INT
)
1540 return INTVAL (disp
) >= 0 && INTVAL (disp
) < 4096;
1542 /* GOT offset is not OK, the GOT can be large. */
1543 if (GET_CODE (disp
) == CONST
1544 && GET_CODE (XEXP (disp
, 0)) == UNSPEC
1545 && (XINT (XEXP (disp
, 0), 1) == UNSPEC_GOT
1546 || XINT (XEXP (disp
, 0), 1) == UNSPEC_GOTNTPOFF
))
1549 /* All other symbolic constants are literal pool references,
1550 which are OK as the literal pool must be small. */
1551 if (GET_CODE (disp
) == CONST
)
1557 /* Decompose a RTL expression ADDR for a memory address into
1558 its components, returned in OUT.
1560 Returns false if ADDR is not a valid memory address, true
1561 otherwise. If OUT is NULL, don't return the components,
1562 but check for validity only.
1564 Note: Only addresses in canonical form are recognized.
1565 LEGITIMIZE_ADDRESS should convert non-canonical forms to the
1566 canonical form so that they will be recognized. */
1569 s390_decompose_address (rtx addr
, struct s390_address
*out
)
1571 HOST_WIDE_INT offset
= 0;
1572 rtx base
= NULL_RTX
;
1573 rtx indx
= NULL_RTX
;
1574 rtx disp
= NULL_RTX
;
1576 bool pointer
= false;
1577 bool base_ptr
= false;
1578 bool indx_ptr
= false;
1579 bool literal_pool
= false;
1581 /* We may need to substitute the literal pool base register into the address
1582 below. However, at this point we do not know which register is going to
1583 be used as base, so we substitute the arg pointer register. This is going
1584 to be treated as holding a pointer below -- it shouldn't be used for any
1586 rtx fake_pool_base
= gen_rtx_REG (Pmode
, ARG_POINTER_REGNUM
);
1588 /* Decompose address into base + index + displacement. */
1590 if (GET_CODE (addr
) == REG
|| GET_CODE (addr
) == UNSPEC
)
1593 else if (GET_CODE (addr
) == PLUS
)
1595 rtx op0
= XEXP (addr
, 0);
1596 rtx op1
= XEXP (addr
, 1);
1597 enum rtx_code code0
= GET_CODE (op0
);
1598 enum rtx_code code1
= GET_CODE (op1
);
1600 if (code0
== REG
|| code0
== UNSPEC
)
1602 if (code1
== REG
|| code1
== UNSPEC
)
1604 indx
= op0
; /* index + base */
1610 base
= op0
; /* base + displacement */
1615 else if (code0
== PLUS
)
1617 indx
= XEXP (op0
, 0); /* index + base + disp */
1618 base
= XEXP (op0
, 1);
1629 disp
= addr
; /* displacement */
1631 /* Extract integer part of displacement. */
1635 if (GET_CODE (disp
) == CONST_INT
)
1637 offset
= INTVAL (disp
);
1640 else if (GET_CODE (disp
) == CONST
1641 && GET_CODE (XEXP (disp
, 0)) == PLUS
1642 && GET_CODE (XEXP (XEXP (disp
, 0), 1)) == CONST_INT
)
1644 offset
= INTVAL (XEXP (XEXP (disp
, 0), 1));
1645 disp
= XEXP (XEXP (disp
, 0), 0);
1649 /* Strip off CONST here to avoid special case tests later. */
1650 if (disp
&& GET_CODE (disp
) == CONST
)
1651 disp
= XEXP (disp
, 0);
1653 /* We can convert literal pool addresses to
1654 displacements by basing them off the base register. */
1655 if (disp
&& GET_CODE (disp
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (disp
))
1657 /* Either base or index must be free to hold the base register. */
1659 base
= fake_pool_base
, literal_pool
= true;
1661 indx
= fake_pool_base
, literal_pool
= true;
1665 /* Mark up the displacement. */
1666 disp
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, disp
),
1667 UNSPEC_LTREL_OFFSET
);
1670 /* Validate base register. */
1673 if (GET_CODE (base
) == UNSPEC
)
1674 switch (XINT (base
, 1))
1678 disp
= gen_rtx_UNSPEC (Pmode
,
1679 gen_rtvec (1, XVECEXP (base
, 0, 0)),
1680 UNSPEC_LTREL_OFFSET
);
1684 base
= XVECEXP (base
, 0, 1);
1687 case UNSPEC_LTREL_BASE
:
1688 if (XVECLEN (base
, 0) == 1)
1689 base
= fake_pool_base
, literal_pool
= true;
1691 base
= XVECEXP (base
, 0, 1);
1699 || (GET_MODE (base
) != SImode
1700 && GET_MODE (base
) != Pmode
))
1703 if (REGNO (base
) == STACK_POINTER_REGNUM
1704 || REGNO (base
) == FRAME_POINTER_REGNUM
1705 || ((reload_completed
|| reload_in_progress
)
1706 && frame_pointer_needed
1707 && REGNO (base
) == HARD_FRAME_POINTER_REGNUM
)
1708 || REGNO (base
) == ARG_POINTER_REGNUM
1710 && REGNO (base
) == PIC_OFFSET_TABLE_REGNUM
))
1711 pointer
= base_ptr
= true;
1713 if ((reload_completed
|| reload_in_progress
)
1714 && base
== cfun
->machine
->base_reg
)
1715 pointer
= base_ptr
= literal_pool
= true;
1718 /* Validate index register. */
1721 if (GET_CODE (indx
) == UNSPEC
)
1722 switch (XINT (indx
, 1))
1726 disp
= gen_rtx_UNSPEC (Pmode
,
1727 gen_rtvec (1, XVECEXP (indx
, 0, 0)),
1728 UNSPEC_LTREL_OFFSET
);
1732 indx
= XVECEXP (indx
, 0, 1);
1735 case UNSPEC_LTREL_BASE
:
1736 if (XVECLEN (indx
, 0) == 1)
1737 indx
= fake_pool_base
, literal_pool
= true;
1739 indx
= XVECEXP (indx
, 0, 1);
1747 || (GET_MODE (indx
) != SImode
1748 && GET_MODE (indx
) != Pmode
))
1751 if (REGNO (indx
) == STACK_POINTER_REGNUM
1752 || REGNO (indx
) == FRAME_POINTER_REGNUM
1753 || ((reload_completed
|| reload_in_progress
)
1754 && frame_pointer_needed
1755 && REGNO (indx
) == HARD_FRAME_POINTER_REGNUM
)
1756 || REGNO (indx
) == ARG_POINTER_REGNUM
1758 && REGNO (indx
) == PIC_OFFSET_TABLE_REGNUM
))
1759 pointer
= indx_ptr
= true;
1761 if ((reload_completed
|| reload_in_progress
)
1762 && indx
== cfun
->machine
->base_reg
)
1763 pointer
= indx_ptr
= literal_pool
= true;
1766 /* Prefer to use pointer as base, not index. */
1767 if (base
&& indx
&& !base_ptr
1768 && (indx_ptr
|| (!REG_POINTER (base
) && REG_POINTER (indx
))))
1775 /* Validate displacement. */
1778 /* If virtual registers are involved, the displacement will change later
1779 anyway as the virtual registers get eliminated. This could make a
1780 valid displacement invalid, but it is more likely to make an invalid
1781 displacement valid, because we sometimes access the register save area
1782 via negative offsets to one of those registers.
1783 Thus we don't check the displacement for validity here. If after
1784 elimination the displacement turns out to be invalid after all,
1785 this is fixed up by reload in any case. */
1786 if (base
!= arg_pointer_rtx
1787 && indx
!= arg_pointer_rtx
1788 && base
!= return_address_pointer_rtx
1789 && indx
!= return_address_pointer_rtx
1790 && base
!= frame_pointer_rtx
1791 && indx
!= frame_pointer_rtx
1792 && base
!= virtual_stack_vars_rtx
1793 && indx
!= virtual_stack_vars_rtx
)
1794 if (!DISP_IN_RANGE (offset
))
1799 /* All the special cases are pointers. */
1802 /* In the small-PIC case, the linker converts @GOT
1803 and @GOTNTPOFF offsets to possible displacements. */
1804 if (GET_CODE (disp
) == UNSPEC
1805 && (XINT (disp
, 1) == UNSPEC_GOT
1806 || XINT (disp
, 1) == UNSPEC_GOTNTPOFF
)
1812 /* Accept chunkified literal pool symbol references. */
1813 else if (cfun
&& cfun
->machine
1814 && cfun
->machine
->decomposed_literal_pool_addresses_ok_p
1815 && GET_CODE (disp
) == MINUS
1816 && GET_CODE (XEXP (disp
, 0)) == LABEL_REF
1817 && GET_CODE (XEXP (disp
, 1)) == LABEL_REF
)
1822 /* Accept literal pool references. */
1823 else if (GET_CODE (disp
) == UNSPEC
1824 && XINT (disp
, 1) == UNSPEC_LTREL_OFFSET
)
1826 orig_disp
= gen_rtx_CONST (Pmode
, disp
);
1829 /* If we have an offset, make sure it does not
1830 exceed the size of the constant pool entry. */
1831 rtx sym
= XVECEXP (disp
, 0, 0);
1832 if (offset
>= GET_MODE_SIZE (get_pool_mode (sym
)))
1835 orig_disp
= plus_constant (orig_disp
, offset
);
1850 out
->disp
= orig_disp
;
1851 out
->pointer
= pointer
;
1852 out
->literal_pool
= literal_pool
;
1858 /* Decompose a RTL expression OP for a shift count into its components,
1859 and return the base register in BASE and the offset in OFFSET.
1861 Return true if OP is a valid shift count, false if not. */
1864 s390_decompose_shift_count (rtx op
, rtx
*base
, HOST_WIDE_INT
*offset
)
1866 HOST_WIDE_INT off
= 0;
1868 /* We can have an integer constant, an address register,
1869 or a sum of the two. */
1870 if (GET_CODE (op
) == CONST_INT
)
1875 if (op
&& GET_CODE (op
) == PLUS
&& GET_CODE (XEXP (op
, 1)) == CONST_INT
)
1877 off
= INTVAL (XEXP (op
, 1));
1880 while (op
&& GET_CODE (op
) == SUBREG
)
1881 op
= SUBREG_REG (op
);
1883 if (op
&& GET_CODE (op
) != REG
)
1895 /* Return true if CODE is a valid address without index. */
1898 s390_legitimate_address_without_index_p (rtx op
)
1900 struct s390_address addr
;
1902 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
1911 /* Evaluates constraint strings described by the regular expression
1912 ([A|B](Q|R|S|T))|U|W and returns 1 if OP is a valid operand for the
1913 constraint given in STR, or 0 else. */
1916 s390_mem_constraint (const char *str
, rtx op
)
1918 struct s390_address addr
;
1921 /* Check for offsettable variants of memory constraints. */
1924 /* Only accept non-volatile MEMs. */
1925 if (!MEM_P (op
) || MEM_VOLATILE_P (op
))
1928 if ((reload_completed
|| reload_in_progress
)
1929 ? !offsettable_memref_p (op
) : !offsettable_nonstrict_memref_p (op
))
1935 /* Check for non-literal-pool variants of memory constraints. */
1938 if (GET_CODE (op
) != MEM
)
1940 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
1942 if (addr
.literal_pool
)
1951 if (GET_CODE (op
) != MEM
)
1953 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
1958 if (TARGET_LONG_DISPLACEMENT
)
1960 if (!s390_short_displacement (addr
.disp
))
1966 if (GET_CODE (op
) != MEM
)
1969 if (TARGET_LONG_DISPLACEMENT
)
1971 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
1973 if (!s390_short_displacement (addr
.disp
))
1979 if (!TARGET_LONG_DISPLACEMENT
)
1981 if (GET_CODE (op
) != MEM
)
1983 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
1987 if (s390_short_displacement (addr
.disp
))
1992 if (!TARGET_LONG_DISPLACEMENT
)
1994 if (GET_CODE (op
) != MEM
)
1996 /* Any invalid address here will be fixed up by reload,
1997 so accept it for the most generic constraint. */
1998 if (s390_decompose_address (XEXP (op
, 0), &addr
)
1999 && s390_short_displacement (addr
.disp
))
2004 if (TARGET_LONG_DISPLACEMENT
)
2006 if (!s390_decompose_address (op
, &addr
))
2008 if (!s390_short_displacement (addr
.disp
))
2014 if (!TARGET_LONG_DISPLACEMENT
)
2016 /* Any invalid address here will be fixed up by reload,
2017 so accept it for the most generic constraint. */
2018 if (s390_decompose_address (op
, &addr
)
2019 && s390_short_displacement (addr
.disp
))
2024 /* Simply check for the basic form of a shift count. Reload will
2025 take care of making sure we have a proper base register. */
2026 if (!s390_decompose_shift_count (op
, NULL
, NULL
))
2039 /* Evaluates constraint strings starting with letter O. Input
2040 parameter C is the second letter following the "O" in the constraint
2041 string. Returns 1 if VALUE meets the respective constraint and 0
2045 s390_O_constraint_str (const char c
, HOST_WIDE_INT value
)
2053 return trunc_int_for_mode (value
, SImode
) == value
;
2057 || s390_single_part (GEN_INT (value
), DImode
, SImode
, 0) == 1;
2061 || s390_single_part (GEN_INT (value
), DImode
, SImode
, -1) == 1;
2069 /* Evaluates constraint strings starting with letter N. Parameter STR
2070 contains the letters following letter "N" in the constraint string.
2071 Returns true if VALUE matches the constraint. */
2074 s390_N_constraint_str (const char *str
, HOST_WIDE_INT value
)
2076 enum machine_mode mode
, part_mode
;
2078 int part
, part_goal
;
2084 part_goal
= str
[0] - '0';
2128 if (GET_MODE_SIZE (mode
) <= GET_MODE_SIZE (part_mode
))
2131 part
= s390_single_part (GEN_INT (value
), mode
, part_mode
, def
);
2134 if (part_goal
!= -1 && part_goal
!= part
)
2141 /* Returns true if the input parameter VALUE is a float zero. */
2144 s390_float_const_zero_p (rtx value
)
2146 return (GET_MODE_CLASS (GET_MODE (value
)) == MODE_FLOAT
2147 && value
== CONST0_RTX (GET_MODE (value
)));
2151 /* Compute a (partial) cost for rtx X. Return true if the complete
2152 cost has been computed, and false if subexpressions should be
2153 scanned. In either case, *TOTAL contains the cost result.
2154 CODE contains GET_CODE (x), OUTER_CODE contains the code
2155 of the superexpression of x. */
2158 s390_rtx_costs (rtx x
, int code
, int outer_code
, int *total
)
2181 *total
= COSTS_N_INSNS (1);
2186 /* Check for multiply and add. */
2187 if ((GET_MODE (x
) == DFmode
|| GET_MODE (x
) == SFmode
)
2188 && GET_CODE (XEXP (x
, 0)) == MULT
2189 && TARGET_HARD_FLOAT
&& TARGET_FUSED_MADD
)
2191 /* This is the multiply and add case. */
2192 if (GET_MODE (x
) == DFmode
)
2193 *total
= s390_cost
->madbr
;
2195 *total
= s390_cost
->maebr
;
2196 *total
+= rtx_cost (XEXP (XEXP (x
, 0), 0), MULT
)
2197 + rtx_cost (XEXP (XEXP (x
, 0), 1), MULT
)
2198 + rtx_cost (XEXP (x
, 1), code
);
2199 return true; /* Do not do an additional recursive descent. */
2201 *total
= COSTS_N_INSNS (1);
2205 switch (GET_MODE (x
))
2209 rtx left
= XEXP (x
, 0);
2210 rtx right
= XEXP (x
, 1);
2211 if (GET_CODE (right
) == CONST_INT
2212 && CONST_OK_FOR_K (INTVAL (right
)))
2213 *total
= s390_cost
->mhi
;
2214 else if (GET_CODE (left
) == SIGN_EXTEND
)
2215 *total
= s390_cost
->mh
;
2217 *total
= s390_cost
->ms
; /* msr, ms, msy */
2222 rtx left
= XEXP (x
, 0);
2223 rtx right
= XEXP (x
, 1);
2226 if (GET_CODE (right
) == CONST_INT
2227 && CONST_OK_FOR_K (INTVAL (right
)))
2228 *total
= s390_cost
->mghi
;
2229 else if (GET_CODE (left
) == SIGN_EXTEND
)
2230 *total
= s390_cost
->msgf
;
2232 *total
= s390_cost
->msg
; /* msgr, msg */
2234 else /* TARGET_31BIT */
2236 if (GET_CODE (left
) == SIGN_EXTEND
2237 && GET_CODE (right
) == SIGN_EXTEND
)
2238 /* mulsidi case: mr, m */
2239 *total
= s390_cost
->m
;
2240 else if (GET_CODE (left
) == ZERO_EXTEND
2241 && GET_CODE (right
) == ZERO_EXTEND
2242 && TARGET_CPU_ZARCH
)
2243 /* umulsidi case: ml, mlr */
2244 *total
= s390_cost
->ml
;
2246 /* Complex calculation is required. */
2247 *total
= COSTS_N_INSNS (40);
2253 *total
= s390_cost
->mult_df
;
2256 *total
= s390_cost
->mxbr
;
2265 if (GET_MODE (x
) == TImode
) /* 128 bit division */
2266 *total
= s390_cost
->dlgr
;
2267 else if (GET_MODE (x
) == DImode
)
2269 rtx right
= XEXP (x
, 1);
2270 if (GET_CODE (right
) == ZERO_EXTEND
) /* 64 by 32 bit division */
2271 *total
= s390_cost
->dlr
;
2272 else /* 64 by 64 bit division */
2273 *total
= s390_cost
->dlgr
;
2275 else if (GET_MODE (x
) == SImode
) /* 32 bit division */
2276 *total
= s390_cost
->dlr
;
2281 if (GET_MODE (x
) == DImode
)
2283 rtx right
= XEXP (x
, 1);
2284 if (GET_CODE (right
) == ZERO_EXTEND
) /* 64 by 32 bit division */
2286 *total
= s390_cost
->dsgfr
;
2288 *total
= s390_cost
->dr
;
2289 else /* 64 by 64 bit division */
2290 *total
= s390_cost
->dsgr
;
2292 else if (GET_MODE (x
) == SImode
) /* 32 bit division */
2293 *total
= s390_cost
->dlr
;
2294 else if (GET_MODE (x
) == SFmode
)
2296 *total
= s390_cost
->debr
;
2298 else if (GET_MODE (x
) == DFmode
)
2300 *total
= s390_cost
->ddbr
;
2302 else if (GET_MODE (x
) == TFmode
)
2304 *total
= s390_cost
->dxbr
;
2309 if (GET_MODE (x
) == SFmode
)
2310 *total
= s390_cost
->sqebr
;
2311 else if (GET_MODE (x
) == DFmode
)
2312 *total
= s390_cost
->sqdbr
;
2314 *total
= s390_cost
->sqxbr
;
2319 if (outer_code
== MULT
|| outer_code
== DIV
|| outer_code
== MOD
2320 || outer_code
== PLUS
|| outer_code
== MINUS
2321 || outer_code
== COMPARE
)
2326 *total
= COSTS_N_INSNS (1);
2327 if (GET_CODE (XEXP (x
, 0)) == AND
2328 && GET_CODE (XEXP (x
, 1)) == CONST_INT
2329 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
)
2331 rtx op0
= XEXP (XEXP (x
, 0), 0);
2332 rtx op1
= XEXP (XEXP (x
, 0), 1);
2333 rtx op2
= XEXP (x
, 1);
2335 if (memory_operand (op0
, GET_MODE (op0
))
2336 && s390_tm_ccmode (op1
, op2
, 0) != VOIDmode
)
2338 if (register_operand (op0
, GET_MODE (op0
))
2339 && s390_tm_ccmode (op1
, op2
, 1) != VOIDmode
)
2349 /* Return the cost of an address rtx ADDR. */
2352 s390_address_cost (rtx addr
)
2354 struct s390_address ad
;
2355 if (!s390_decompose_address (addr
, &ad
))
2358 return ad
.indx
? COSTS_N_INSNS (1) + 1 : COSTS_N_INSNS (1);
2361 /* If OP is a SYMBOL_REF of a thread-local symbol, return its TLS mode,
2362 otherwise return 0. */
2365 tls_symbolic_operand (rtx op
)
2367 if (GET_CODE (op
) != SYMBOL_REF
)
2369 return SYMBOL_REF_TLS_MODEL (op
);
2372 /* Split DImode access register reference REG (on 64-bit) into its constituent
2373 low and high parts, and store them into LO and HI. Note that gen_lowpart/
2374 gen_highpart cannot be used as they assume all registers are word-sized,
2375 while our access registers have only half that size. */
2378 s390_split_access_reg (rtx reg
, rtx
*lo
, rtx
*hi
)
2380 gcc_assert (TARGET_64BIT
);
2381 gcc_assert (ACCESS_REG_P (reg
));
2382 gcc_assert (GET_MODE (reg
) == DImode
);
2383 gcc_assert (!(REGNO (reg
) & 1));
2385 *lo
= gen_rtx_REG (SImode
, REGNO (reg
) + 1);
2386 *hi
= gen_rtx_REG (SImode
, REGNO (reg
));
2389 /* Return true if OP contains a symbol reference */
2392 symbolic_reference_mentioned_p (rtx op
)
2397 if (GET_CODE (op
) == SYMBOL_REF
|| GET_CODE (op
) == LABEL_REF
)
2400 fmt
= GET_RTX_FORMAT (GET_CODE (op
));
2401 for (i
= GET_RTX_LENGTH (GET_CODE (op
)) - 1; i
>= 0; i
--)
2407 for (j
= XVECLEN (op
, i
) - 1; j
>= 0; j
--)
2408 if (symbolic_reference_mentioned_p (XVECEXP (op
, i
, j
)))
2412 else if (fmt
[i
] == 'e' && symbolic_reference_mentioned_p (XEXP (op
, i
)))
2419 /* Return true if OP contains a reference to a thread-local symbol. */
2422 tls_symbolic_reference_mentioned_p (rtx op
)
2427 if (GET_CODE (op
) == SYMBOL_REF
)
2428 return tls_symbolic_operand (op
);
2430 fmt
= GET_RTX_FORMAT (GET_CODE (op
));
2431 for (i
= GET_RTX_LENGTH (GET_CODE (op
)) - 1; i
>= 0; i
--)
2437 for (j
= XVECLEN (op
, i
) - 1; j
>= 0; j
--)
2438 if (tls_symbolic_reference_mentioned_p (XVECEXP (op
, i
, j
)))
2442 else if (fmt
[i
] == 'e' && tls_symbolic_reference_mentioned_p (XEXP (op
, i
)))
2450 /* Return true if OP is a legitimate general operand when
2451 generating PIC code. It is given that flag_pic is on
2452 and that OP satisfies CONSTANT_P or is a CONST_DOUBLE. */
2455 legitimate_pic_operand_p (rtx op
)
2457 /* Accept all non-symbolic constants. */
2458 if (!SYMBOLIC_CONST (op
))
2461 /* Reject everything else; must be handled
2462 via emit_symbolic_move. */
2466 /* Returns true if the constant value OP is a legitimate general operand.
2467 It is given that OP satisfies CONSTANT_P or is a CONST_DOUBLE. */
2470 legitimate_constant_p (rtx op
)
2472 /* Accept all non-symbolic constants. */
2473 if (!SYMBOLIC_CONST (op
))
2476 /* Accept immediate LARL operands. */
2477 if (TARGET_CPU_ZARCH
&& larl_operand (op
, VOIDmode
))
2480 /* Thread-local symbols are never legal constants. This is
2481 so that emit_call knows that computing such addresses
2482 might require a function call. */
2483 if (TLS_SYMBOLIC_CONST (op
))
2486 /* In the PIC case, symbolic constants must *not* be
2487 forced into the literal pool. We accept them here,
2488 so that they will be handled by emit_symbolic_move. */
2492 /* All remaining non-PIC symbolic constants are
2493 forced into the literal pool. */
2497 /* Determine if it's legal to put X into the constant pool. This
2498 is not possible if X contains the address of a symbol that is
2499 not constant (TLS) or not known at final link time (PIC). */
2502 s390_cannot_force_const_mem (rtx x
)
2504 switch (GET_CODE (x
))
2508 /* Accept all non-symbolic constants. */
2512 /* Labels are OK iff we are non-PIC. */
2513 return flag_pic
!= 0;
2516 /* 'Naked' TLS symbol references are never OK,
2517 non-TLS symbols are OK iff we are non-PIC. */
2518 if (tls_symbolic_operand (x
))
2521 return flag_pic
!= 0;
2524 return s390_cannot_force_const_mem (XEXP (x
, 0));
2527 return s390_cannot_force_const_mem (XEXP (x
, 0))
2528 || s390_cannot_force_const_mem (XEXP (x
, 1));
2531 switch (XINT (x
, 1))
2533 /* Only lt-relative or GOT-relative UNSPECs are OK. */
2534 case UNSPEC_LTREL_OFFSET
:
2542 case UNSPEC_GOTNTPOFF
:
2543 case UNSPEC_INDNTPOFF
:
2546 /* If the literal pool shares the code section, be put
2547 execute template placeholders into the pool as well. */
2549 return TARGET_CPU_ZARCH
;
2561 /* Returns true if the constant value OP is a legitimate general
2562 operand during and after reload. The difference to
2563 legitimate_constant_p is that this function will not accept
2564 a constant that would need to be forced to the literal pool
2565 before it can be used as operand. */
2568 legitimate_reload_constant_p (rtx op
)
2570 /* Accept la(y) operands. */
2571 if (GET_CODE (op
) == CONST_INT
2572 && DISP_IN_RANGE (INTVAL (op
)))
2575 /* Accept l(g)hi/l(g)fi operands. */
2576 if (GET_CODE (op
) == CONST_INT
2577 && (CONST_OK_FOR_K (INTVAL (op
)) || CONST_OK_FOR_Os (INTVAL (op
))))
2580 /* Accept lliXX operands. */
2582 && GET_CODE (op
) == CONST_INT
2583 && trunc_int_for_mode (INTVAL (op
), word_mode
) == INTVAL (op
)
2584 && s390_single_part (op
, word_mode
, HImode
, 0) >= 0)
2588 && GET_CODE (op
) == CONST_INT
2589 && trunc_int_for_mode (INTVAL (op
), word_mode
) == INTVAL (op
)
2590 && s390_single_part (op
, word_mode
, SImode
, 0) >= 0)
2593 /* Accept larl operands. */
2594 if (TARGET_CPU_ZARCH
2595 && larl_operand (op
, VOIDmode
))
2598 /* Accept lzXX operands. */
2599 if (GET_CODE (op
) == CONST_DOUBLE
2600 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op
, 'G', "G"))
2603 /* Accept double-word operands that can be split. */
2604 if (GET_CODE (op
) == CONST_INT
2605 && trunc_int_for_mode (INTVAL (op
), word_mode
) != INTVAL (op
))
2607 enum machine_mode dword_mode
= word_mode
== SImode
? DImode
: TImode
;
2608 rtx hi
= operand_subword (op
, 0, 0, dword_mode
);
2609 rtx lo
= operand_subword (op
, 1, 0, dword_mode
);
2610 return legitimate_reload_constant_p (hi
)
2611 && legitimate_reload_constant_p (lo
);
2614 /* Everything else cannot be handled without reload. */
2618 /* Given an rtx OP being reloaded into a reg required to be in class CLASS,
2619 return the class of reg to actually use. */
2622 s390_preferred_reload_class (rtx op
, enum reg_class
class)
2624 switch (GET_CODE (op
))
2626 /* Constants we cannot reload must be forced into the
2631 if (legitimate_reload_constant_p (op
))
2636 /* If a symbolic constant or a PLUS is reloaded,
2637 it is most likely being used as an address, so
2638 prefer ADDR_REGS. If 'class' is not a superset
2639 of ADDR_REGS, e.g. FP_REGS, reject this reload. */
2644 if (reg_class_subset_p (ADDR_REGS
, class))
2656 /* Inform reload about cases where moving X with a mode MODE to a register in
2657 CLASS requires an extra scratch or immediate register. Return the class
2658 needed for the immediate register. */
2660 static enum reg_class
2661 s390_secondary_reload (bool in_p
, rtx x
, enum reg_class
class,
2662 enum machine_mode mode
, secondary_reload_info
*sri
)
2664 /* Intermediate register needed. */
2665 if (reg_classes_intersect_p (CC_REGS
, class))
2666 return GENERAL_REGS
;
2668 /* We need a scratch register when loading a PLUS expression which
2669 is not a legitimate operand of the LOAD ADDRESS instruction. */
2670 if (in_p
&& s390_plus_operand (x
, mode
))
2671 sri
->icode
= (TARGET_64BIT
?
2672 CODE_FOR_reloaddi_plus
: CODE_FOR_reloadsi_plus
);
2674 /* Performing a multiword move from or to memory we have to make sure the
2675 second chunk in memory is addressable without causing a displacement
2676 overflow. If that would be the case we calculate the address in
2677 a scratch register. */
2679 && GET_CODE (XEXP (x
, 0)) == PLUS
2680 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
2681 && !DISP_IN_RANGE (INTVAL (XEXP (XEXP (x
, 0), 1))
2682 + GET_MODE_SIZE (mode
) - 1))
2684 /* For GENERAL_REGS a displacement overflow is no problem if occurring
2685 in a s_operand address since we may fallback to lm/stm. So we only
2686 have to care about overflows in the b+i+d case. */
2687 if ((reg_classes_intersect_p (GENERAL_REGS
, class)
2688 && s390_class_max_nregs (GENERAL_REGS
, mode
) > 1
2689 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == PLUS
)
2690 /* For FP_REGS no lm/stm is available so this check is triggered
2691 for displacement overflows in b+i+d and b+d like addresses. */
2692 || (reg_classes_intersect_p (FP_REGS
, class)
2693 && s390_class_max_nregs (FP_REGS
, mode
) > 1))
2696 sri
->icode
= (TARGET_64BIT
?
2697 CODE_FOR_reloaddi_nonoffmem_in
:
2698 CODE_FOR_reloadsi_nonoffmem_in
);
2700 sri
->icode
= (TARGET_64BIT
?
2701 CODE_FOR_reloaddi_nonoffmem_out
:
2702 CODE_FOR_reloadsi_nonoffmem_out
);
2706 /* Either scratch or no register needed. */
2710 /* Generate code to load SRC, which is PLUS that is not a
2711 legitimate operand for the LA instruction, into TARGET.
2712 SCRATCH may be used as scratch register. */
2715 s390_expand_plus_operand (rtx target
, rtx src
,
2719 struct s390_address ad
;
2721 /* src must be a PLUS; get its two operands. */
2722 gcc_assert (GET_CODE (src
) == PLUS
);
2723 gcc_assert (GET_MODE (src
) == Pmode
);
2725 /* Check if any of the two operands is already scheduled
2726 for replacement by reload. This can happen e.g. when
2727 float registers occur in an address. */
2728 sum1
= find_replacement (&XEXP (src
, 0));
2729 sum2
= find_replacement (&XEXP (src
, 1));
2730 src
= gen_rtx_PLUS (Pmode
, sum1
, sum2
);
2732 /* If the address is already strictly valid, there's nothing to do. */
2733 if (!s390_decompose_address (src
, &ad
)
2734 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
2735 || (ad
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (ad
.indx
))))
2737 /* Otherwise, one of the operands cannot be an address register;
2738 we reload its value into the scratch register. */
2739 if (true_regnum (sum1
) < 1 || true_regnum (sum1
) > 15)
2741 emit_move_insn (scratch
, sum1
);
2744 if (true_regnum (sum2
) < 1 || true_regnum (sum2
) > 15)
2746 emit_move_insn (scratch
, sum2
);
2750 /* According to the way these invalid addresses are generated
2751 in reload.c, it should never happen (at least on s390) that
2752 *neither* of the PLUS components, after find_replacements
2753 was applied, is an address register. */
2754 if (sum1
== scratch
&& sum2
== scratch
)
2760 src
= gen_rtx_PLUS (Pmode
, sum1
, sum2
);
2763 /* Emit the LOAD ADDRESS pattern. Note that reload of PLUS
2764 is only ever performed on addresses, so we can mark the
2765 sum as legitimate for LA in any case. */
2766 s390_load_address (target
, src
);
2770 /* Return true if ADDR is a valid memory address.
2771 STRICT specifies whether strict register checking applies. */
2774 legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED
,
2775 rtx addr
, int strict
)
2777 struct s390_address ad
;
2778 if (!s390_decompose_address (addr
, &ad
))
2783 if (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
2786 if (ad
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (ad
.indx
)))
2792 && !(REGNO (ad
.base
) >= FIRST_PSEUDO_REGISTER
2793 || REGNO_REG_CLASS (REGNO (ad
.base
)) == ADDR_REGS
))
2797 && !(REGNO (ad
.indx
) >= FIRST_PSEUDO_REGISTER
2798 || REGNO_REG_CLASS (REGNO (ad
.indx
)) == ADDR_REGS
))
2804 /* Return true if OP is a valid operand for the LA instruction.
2805 In 31-bit, we need to prove that the result is used as an
2806 address, as LA performs only a 31-bit addition. */
2809 legitimate_la_operand_p (rtx op
)
2811 struct s390_address addr
;
2812 if (!s390_decompose_address (op
, &addr
))
2815 return (TARGET_64BIT
|| addr
.pointer
);
2818 /* Return true if it is valid *and* preferable to use LA to
2819 compute the sum of OP1 and OP2. */
2822 preferred_la_operand_p (rtx op1
, rtx op2
)
2824 struct s390_address addr
;
2826 if (op2
!= const0_rtx
)
2827 op1
= gen_rtx_PLUS (Pmode
, op1
, op2
);
2829 if (!s390_decompose_address (op1
, &addr
))
2831 if (addr
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (addr
.base
)))
2833 if (addr
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (addr
.indx
)))
2836 if (!TARGET_64BIT
&& !addr
.pointer
)
2842 if ((addr
.base
&& REG_P (addr
.base
) && REG_POINTER (addr
.base
))
2843 || (addr
.indx
&& REG_P (addr
.indx
) && REG_POINTER (addr
.indx
)))
2849 /* Emit a forced load-address operation to load SRC into DST.
2850 This will use the LOAD ADDRESS instruction even in situations
2851 where legitimate_la_operand_p (SRC) returns false. */
2854 s390_load_address (rtx dst
, rtx src
)
2857 emit_move_insn (dst
, src
);
2859 emit_insn (gen_force_la_31 (dst
, src
));
2862 /* Return a legitimate reference for ORIG (an address) using the
2863 register REG. If REG is 0, a new pseudo is generated.
2865 There are two types of references that must be handled:
2867 1. Global data references must load the address from the GOT, via
2868 the PIC reg. An insn is emitted to do this load, and the reg is
2871 2. Static data references, constant pool addresses, and code labels
2872 compute the address as an offset from the GOT, whose base is in
2873 the PIC reg. Static data objects have SYMBOL_FLAG_LOCAL set to
2874 differentiate them from global data objects. The returned
2875 address is the PIC reg + an unspec constant.
2877 GO_IF_LEGITIMATE_ADDRESS rejects symbolic references unless the PIC
2878 reg also appears in the address. */
2881 legitimize_pic_address (rtx orig
, rtx reg
)
2887 gcc_assert (!TLS_SYMBOLIC_CONST (addr
));
2889 if (GET_CODE (addr
) == LABEL_REF
2890 || (GET_CODE (addr
) == SYMBOL_REF
&& SYMBOL_REF_LOCAL_P (addr
)))
2892 /* This is a local symbol. */
2893 if (TARGET_CPU_ZARCH
&& larl_operand (addr
, VOIDmode
))
2895 /* Access local symbols PC-relative via LARL.
2896 This is the same as in the non-PIC case, so it is
2897 handled automatically ... */
2901 /* Access local symbols relative to the GOT. */
2903 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
2905 if (reload_in_progress
|| reload_completed
)
2906 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
2908 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTOFF
);
2909 addr
= gen_rtx_CONST (Pmode
, addr
);
2910 addr
= force_const_mem (Pmode
, addr
);
2911 emit_move_insn (temp
, addr
);
2913 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
2916 s390_load_address (reg
, new);
2921 else if (GET_CODE (addr
) == SYMBOL_REF
)
2924 reg
= gen_reg_rtx (Pmode
);
2928 /* Assume GOT offset < 4k. This is handled the same way
2929 in both 31- and 64-bit code (@GOT). */
2931 if (reload_in_progress
|| reload_completed
)
2932 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
2934 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOT
);
2935 new = gen_rtx_CONST (Pmode
, new);
2936 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, new);
2937 new = gen_const_mem (Pmode
, new);
2938 emit_move_insn (reg
, new);
2941 else if (TARGET_CPU_ZARCH
)
2943 /* If the GOT offset might be >= 4k, we determine the position
2944 of the GOT entry via a PC-relative LARL (@GOTENT). */
2946 rtx temp
= gen_reg_rtx (Pmode
);
2948 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTENT
);
2949 new = gen_rtx_CONST (Pmode
, new);
2950 emit_move_insn (temp
, new);
2952 new = gen_const_mem (Pmode
, temp
);
2953 emit_move_insn (reg
, new);
2958 /* If the GOT offset might be >= 4k, we have to load it
2959 from the literal pool (@GOT). */
2961 rtx temp
= gen_reg_rtx (Pmode
);
2963 if (reload_in_progress
|| reload_completed
)
2964 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
2966 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOT
);
2967 addr
= gen_rtx_CONST (Pmode
, addr
);
2968 addr
= force_const_mem (Pmode
, addr
);
2969 emit_move_insn (temp
, addr
);
2971 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
2972 new = gen_const_mem (Pmode
, new);
2973 emit_move_insn (reg
, new);
2979 if (GET_CODE (addr
) == CONST
)
2981 addr
= XEXP (addr
, 0);
2982 if (GET_CODE (addr
) == UNSPEC
)
2984 gcc_assert (XVECLEN (addr
, 0) == 1);
2985 switch (XINT (addr
, 1))
2987 /* If someone moved a GOT-relative UNSPEC
2988 out of the literal pool, force them back in. */
2991 new = force_const_mem (Pmode
, orig
);
2994 /* @GOT is OK as is if small. */
2997 new = force_const_mem (Pmode
, orig
);
3000 /* @GOTENT is OK as is. */
3004 /* @PLT is OK as is on 64-bit, must be converted to
3005 GOT-relative @PLTOFF on 31-bit. */
3007 if (!TARGET_CPU_ZARCH
)
3009 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3011 if (reload_in_progress
|| reload_completed
)
3012 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3014 addr
= XVECEXP (addr
, 0, 0);
3015 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
),
3017 addr
= gen_rtx_CONST (Pmode
, addr
);
3018 addr
= force_const_mem (Pmode
, addr
);
3019 emit_move_insn (temp
, addr
);
3021 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3024 s390_load_address (reg
, new);
3030 /* Everything else cannot happen. */
3036 gcc_assert (GET_CODE (addr
) == PLUS
);
3038 if (GET_CODE (addr
) == PLUS
)
3040 rtx op0
= XEXP (addr
, 0), op1
= XEXP (addr
, 1);
3042 gcc_assert (!TLS_SYMBOLIC_CONST (op0
));
3043 gcc_assert (!TLS_SYMBOLIC_CONST (op1
));
3045 /* Check first to see if this is a constant offset
3046 from a local symbol reference. */
3047 if ((GET_CODE (op0
) == LABEL_REF
3048 || (GET_CODE (op0
) == SYMBOL_REF
&& SYMBOL_REF_LOCAL_P (op0
)))
3049 && GET_CODE (op1
) == CONST_INT
)
3051 if (TARGET_CPU_ZARCH
3052 && larl_operand (op0
, VOIDmode
)
3053 && INTVAL (op1
) < (HOST_WIDE_INT
)1 << 31
3054 && INTVAL (op1
) >= -((HOST_WIDE_INT
)1 << 31))
3056 if (INTVAL (op1
) & 1)
3058 /* LARL can't handle odd offsets, so emit a
3059 pair of LARL and LA. */
3060 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3062 if (!DISP_IN_RANGE (INTVAL (op1
)))
3064 HOST_WIDE_INT even
= INTVAL (op1
) - 1;
3065 op0
= gen_rtx_PLUS (Pmode
, op0
, GEN_INT (even
));
3066 op0
= gen_rtx_CONST (Pmode
, op0
);
3070 emit_move_insn (temp
, op0
);
3071 new = gen_rtx_PLUS (Pmode
, temp
, op1
);
3075 s390_load_address (reg
, new);
3081 /* If the offset is even, we can just use LARL.
3082 This will happen automatically. */
3087 /* Access local symbols relative to the GOT. */
3089 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3091 if (reload_in_progress
|| reload_completed
)
3092 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3094 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op0
),
3096 addr
= gen_rtx_PLUS (Pmode
, addr
, op1
);
3097 addr
= gen_rtx_CONST (Pmode
, addr
);
3098 addr
= force_const_mem (Pmode
, addr
);
3099 emit_move_insn (temp
, addr
);
3101 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3104 s390_load_address (reg
, new);
3110 /* Now, check whether it is a GOT relative symbol plus offset
3111 that was pulled out of the literal pool. Force it back in. */
3113 else if (GET_CODE (op0
) == UNSPEC
3114 && GET_CODE (op1
) == CONST_INT
3115 && XINT (op0
, 1) == UNSPEC_GOTOFF
)
3117 gcc_assert (XVECLEN (op0
, 0) == 1);
3119 new = force_const_mem (Pmode
, orig
);
3122 /* Otherwise, compute the sum. */
3125 base
= legitimize_pic_address (XEXP (addr
, 0), reg
);
3126 new = legitimize_pic_address (XEXP (addr
, 1),
3127 base
== reg
? NULL_RTX
: reg
);
3128 if (GET_CODE (new) == CONST_INT
)
3129 new = plus_constant (base
, INTVAL (new));
3132 if (GET_CODE (new) == PLUS
&& CONSTANT_P (XEXP (new, 1)))
3134 base
= gen_rtx_PLUS (Pmode
, base
, XEXP (new, 0));
3135 new = XEXP (new, 1);
3137 new = gen_rtx_PLUS (Pmode
, base
, new);
3140 if (GET_CODE (new) == CONST
)
3141 new = XEXP (new, 0);
3142 new = force_operand (new, 0);
3149 /* Load the thread pointer into a register. */
3152 s390_get_thread_pointer (void)
3154 rtx tp
= gen_reg_rtx (Pmode
);
3156 emit_move_insn (tp
, gen_rtx_REG (Pmode
, TP_REGNUM
));
3157 mark_reg_pointer (tp
, BITS_PER_WORD
);
3162 /* Emit a tls call insn. The call target is the SYMBOL_REF stored
3163 in s390_tls_symbol which always refers to __tls_get_offset.
3164 The returned offset is written to RESULT_REG and an USE rtx is
3165 generated for TLS_CALL. */
3167 static GTY(()) rtx s390_tls_symbol
;
3170 s390_emit_tls_call_insn (rtx result_reg
, rtx tls_call
)
3174 gcc_assert (flag_pic
);
3176 if (!s390_tls_symbol
)
3177 s390_tls_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "__tls_get_offset");
3179 insn
= s390_emit_call (s390_tls_symbol
, tls_call
, result_reg
,
3180 gen_rtx_REG (Pmode
, RETURN_REGNUM
));
3182 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), result_reg
);
3183 CONST_OR_PURE_CALL_P (insn
) = 1;
3186 /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
3187 this (thread-local) address. REG may be used as temporary. */
3190 legitimize_tls_address (rtx addr
, rtx reg
)
3192 rtx
new, tls_call
, temp
, base
, r2
, insn
;
3194 if (GET_CODE (addr
) == SYMBOL_REF
)
3195 switch (tls_symbolic_operand (addr
))
3197 case TLS_MODEL_GLOBAL_DYNAMIC
:
3199 r2
= gen_rtx_REG (Pmode
, 2);
3200 tls_call
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_TLSGD
);
3201 new = gen_rtx_CONST (Pmode
, tls_call
);
3202 new = force_const_mem (Pmode
, new);
3203 emit_move_insn (r2
, new);
3204 s390_emit_tls_call_insn (r2
, tls_call
);
3205 insn
= get_insns ();
3208 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_NTPOFF
);
3209 temp
= gen_reg_rtx (Pmode
);
3210 emit_libcall_block (insn
, temp
, r2
, new);
3212 new = gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3215 s390_load_address (reg
, new);
3220 case TLS_MODEL_LOCAL_DYNAMIC
:
3222 r2
= gen_rtx_REG (Pmode
, 2);
3223 tls_call
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, const0_rtx
), UNSPEC_TLSLDM
);
3224 new = gen_rtx_CONST (Pmode
, tls_call
);
3225 new = force_const_mem (Pmode
, new);
3226 emit_move_insn (r2
, new);
3227 s390_emit_tls_call_insn (r2
, tls_call
);
3228 insn
= get_insns ();
3231 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, const0_rtx
), UNSPEC_TLSLDM_NTPOFF
);
3232 temp
= gen_reg_rtx (Pmode
);
3233 emit_libcall_block (insn
, temp
, r2
, new);
3235 new = gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3236 base
= gen_reg_rtx (Pmode
);
3237 s390_load_address (base
, new);
3239 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_DTPOFF
);
3240 new = gen_rtx_CONST (Pmode
, new);
3241 new = force_const_mem (Pmode
, new);
3242 temp
= gen_reg_rtx (Pmode
);
3243 emit_move_insn (temp
, new);
3245 new = gen_rtx_PLUS (Pmode
, base
, temp
);
3248 s390_load_address (reg
, new);
3253 case TLS_MODEL_INITIAL_EXEC
:
3256 /* Assume GOT offset < 4k. This is handled the same way
3257 in both 31- and 64-bit code. */
3259 if (reload_in_progress
|| reload_completed
)
3260 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3262 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTNTPOFF
);
3263 new = gen_rtx_CONST (Pmode
, new);
3264 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, new);
3265 new = gen_const_mem (Pmode
, new);
3266 temp
= gen_reg_rtx (Pmode
);
3267 emit_move_insn (temp
, new);
3269 else if (TARGET_CPU_ZARCH
)
3271 /* If the GOT offset might be >= 4k, we determine the position
3272 of the GOT entry via a PC-relative LARL. */
3274 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_INDNTPOFF
);
3275 new = gen_rtx_CONST (Pmode
, new);
3276 temp
= gen_reg_rtx (Pmode
);
3277 emit_move_insn (temp
, new);
3279 new = gen_const_mem (Pmode
, temp
);
3280 temp
= gen_reg_rtx (Pmode
);
3281 emit_move_insn (temp
, new);
3285 /* If the GOT offset might be >= 4k, we have to load it
3286 from the literal pool. */
3288 if (reload_in_progress
|| reload_completed
)
3289 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3291 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTNTPOFF
);
3292 new = gen_rtx_CONST (Pmode
, new);
3293 new = force_const_mem (Pmode
, new);
3294 temp
= gen_reg_rtx (Pmode
);
3295 emit_move_insn (temp
, new);
3297 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3298 new = gen_const_mem (Pmode
, new);
3300 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, new, addr
), UNSPEC_TLS_LOAD
);
3301 temp
= gen_reg_rtx (Pmode
);
3302 emit_insn (gen_rtx_SET (Pmode
, temp
, new));
3306 /* In position-dependent code, load the absolute address of
3307 the GOT entry from the literal pool. */
3309 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_INDNTPOFF
);
3310 new = gen_rtx_CONST (Pmode
, new);
3311 new = force_const_mem (Pmode
, new);
3312 temp
= gen_reg_rtx (Pmode
);
3313 emit_move_insn (temp
, new);
3316 new = gen_const_mem (Pmode
, new);
3317 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, new, addr
), UNSPEC_TLS_LOAD
);
3318 temp
= gen_reg_rtx (Pmode
);
3319 emit_insn (gen_rtx_SET (Pmode
, temp
, new));
3322 new = gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3325 s390_load_address (reg
, new);
3330 case TLS_MODEL_LOCAL_EXEC
:
3331 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_NTPOFF
);
3332 new = gen_rtx_CONST (Pmode
, new);
3333 new = force_const_mem (Pmode
, new);
3334 temp
= gen_reg_rtx (Pmode
);
3335 emit_move_insn (temp
, new);
3337 new = gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3340 s390_load_address (reg
, new);
3349 else if (GET_CODE (addr
) == CONST
&& GET_CODE (XEXP (addr
, 0)) == UNSPEC
)
3351 switch (XINT (XEXP (addr
, 0), 1))
3353 case UNSPEC_INDNTPOFF
:
3354 gcc_assert (TARGET_CPU_ZARCH
);
3363 else if (GET_CODE (addr
) == CONST
&& GET_CODE (XEXP (addr
, 0)) == PLUS
3364 && GET_CODE (XEXP (XEXP (addr
, 0), 1)) == CONST_INT
)
3366 new = XEXP (XEXP (addr
, 0), 0);
3367 if (GET_CODE (new) != SYMBOL_REF
)
3368 new = gen_rtx_CONST (Pmode
, new);
3370 new = legitimize_tls_address (new, reg
);
3371 new = plus_constant (new, INTVAL (XEXP (XEXP (addr
, 0), 1)));
3372 new = force_operand (new, 0);
3376 gcc_unreachable (); /* for now ... */
3381 /* Emit insns to move operands[1] into operands[0]. */
3384 emit_symbolic_move (rtx
*operands
)
3386 rtx temp
= !can_create_pseudo_p () ? operands
[0] : gen_reg_rtx (Pmode
);
3388 if (GET_CODE (operands
[0]) == MEM
)
3389 operands
[1] = force_reg (Pmode
, operands
[1]);
3390 else if (TLS_SYMBOLIC_CONST (operands
[1]))
3391 operands
[1] = legitimize_tls_address (operands
[1], temp
);
3393 operands
[1] = legitimize_pic_address (operands
[1], temp
);
3396 /* Try machine-dependent ways of modifying an illegitimate address X
3397 to be legitimate. If we find one, return the new, valid address.
3399 OLDX is the address as it was before break_out_memory_refs was called.
3400 In some cases it is useful to look at this to decide what needs to be done.
3402 MODE is the mode of the operand pointed to by X.
3404 When -fpic is used, special handling is needed for symbolic references.
3405 See comments by legitimize_pic_address for details. */
3408 legitimize_address (rtx x
, rtx oldx ATTRIBUTE_UNUSED
,
3409 enum machine_mode mode ATTRIBUTE_UNUSED
)
3411 rtx constant_term
= const0_rtx
;
3413 if (TLS_SYMBOLIC_CONST (x
))
3415 x
= legitimize_tls_address (x
, 0);
3417 if (legitimate_address_p (mode
, x
, FALSE
))
3420 else if (GET_CODE (x
) == PLUS
3421 && (TLS_SYMBOLIC_CONST (XEXP (x
, 0))
3422 || TLS_SYMBOLIC_CONST (XEXP (x
, 1))))
3428 if (SYMBOLIC_CONST (x
)
3429 || (GET_CODE (x
) == PLUS
3430 && (SYMBOLIC_CONST (XEXP (x
, 0))
3431 || SYMBOLIC_CONST (XEXP (x
, 1)))))
3432 x
= legitimize_pic_address (x
, 0);
3434 if (legitimate_address_p (mode
, x
, FALSE
))
3438 x
= eliminate_constant_term (x
, &constant_term
);
3440 /* Optimize loading of large displacements by splitting them
3441 into the multiple of 4K and the rest; this allows the
3442 former to be CSE'd if possible.
3444 Don't do this if the displacement is added to a register
3445 pointing into the stack frame, as the offsets will
3446 change later anyway. */
3448 if (GET_CODE (constant_term
) == CONST_INT
3449 && !TARGET_LONG_DISPLACEMENT
3450 && !DISP_IN_RANGE (INTVAL (constant_term
))
3451 && !(REG_P (x
) && REGNO_PTR_FRAME_P (REGNO (x
))))
3453 HOST_WIDE_INT lower
= INTVAL (constant_term
) & 0xfff;
3454 HOST_WIDE_INT upper
= INTVAL (constant_term
) ^ lower
;
3456 rtx temp
= gen_reg_rtx (Pmode
);
3457 rtx val
= force_operand (GEN_INT (upper
), temp
);
3459 emit_move_insn (temp
, val
);
3461 x
= gen_rtx_PLUS (Pmode
, x
, temp
);
3462 constant_term
= GEN_INT (lower
);
3465 if (GET_CODE (x
) == PLUS
)
3467 if (GET_CODE (XEXP (x
, 0)) == REG
)
3469 rtx temp
= gen_reg_rtx (Pmode
);
3470 rtx val
= force_operand (XEXP (x
, 1), temp
);
3472 emit_move_insn (temp
, val
);
3474 x
= gen_rtx_PLUS (Pmode
, XEXP (x
, 0), temp
);
3477 else if (GET_CODE (XEXP (x
, 1)) == REG
)
3479 rtx temp
= gen_reg_rtx (Pmode
);
3480 rtx val
= force_operand (XEXP (x
, 0), temp
);
3482 emit_move_insn (temp
, val
);
3484 x
= gen_rtx_PLUS (Pmode
, temp
, XEXP (x
, 1));
3488 if (constant_term
!= const0_rtx
)
3489 x
= gen_rtx_PLUS (Pmode
, x
, constant_term
);
3494 /* Try a machine-dependent way of reloading an illegitimate address AD
3495 operand. If we find one, push the reload and and return the new address.
3497 MODE is the mode of the enclosing MEM. OPNUM is the operand number
3498 and TYPE is the reload type of the current reload. */
3501 legitimize_reload_address (rtx ad
, enum machine_mode mode ATTRIBUTE_UNUSED
,
3502 int opnum
, int type
)
3504 if (!optimize
|| TARGET_LONG_DISPLACEMENT
)
3507 if (GET_CODE (ad
) == PLUS
)
3509 rtx tem
= simplify_binary_operation (PLUS
, Pmode
,
3510 XEXP (ad
, 0), XEXP (ad
, 1));
3515 if (GET_CODE (ad
) == PLUS
3516 && GET_CODE (XEXP (ad
, 0)) == REG
3517 && GET_CODE (XEXP (ad
, 1)) == CONST_INT
3518 && !DISP_IN_RANGE (INTVAL (XEXP (ad
, 1))))
3520 HOST_WIDE_INT lower
= INTVAL (XEXP (ad
, 1)) & 0xfff;
3521 HOST_WIDE_INT upper
= INTVAL (XEXP (ad
, 1)) ^ lower
;
3524 cst
= GEN_INT (upper
);
3525 if (!legitimate_reload_constant_p (cst
))
3526 cst
= force_const_mem (Pmode
, cst
);
3528 tem
= gen_rtx_PLUS (Pmode
, XEXP (ad
, 0), cst
);
3529 new = gen_rtx_PLUS (Pmode
, tem
, GEN_INT (lower
));
3531 push_reload (XEXP (tem
, 1), 0, &XEXP (tem
, 1), 0,
3532 BASE_REG_CLASS
, Pmode
, VOIDmode
, 0, 0,
3533 opnum
, (enum reload_type
) type
);
3540 /* Emit code to move LEN bytes from DST to SRC. */
3543 s390_expand_movmem (rtx dst
, rtx src
, rtx len
)
3545 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) >= 0 && INTVAL (len
) <= 256)
3547 if (INTVAL (len
) > 0)
3548 emit_insn (gen_movmem_short (dst
, src
, GEN_INT (INTVAL (len
) - 1)));
3551 else if (TARGET_MVCLE
)
3553 emit_insn (gen_movmem_long (dst
, src
, convert_to_mode (Pmode
, len
, 1)));
3558 rtx dst_addr
, src_addr
, count
, blocks
, temp
;
3559 rtx loop_start_label
= gen_label_rtx ();
3560 rtx loop_end_label
= gen_label_rtx ();
3561 rtx end_label
= gen_label_rtx ();
3562 enum machine_mode mode
;
3564 mode
= GET_MODE (len
);
3565 if (mode
== VOIDmode
)
3568 dst_addr
= gen_reg_rtx (Pmode
);
3569 src_addr
= gen_reg_rtx (Pmode
);
3570 count
= gen_reg_rtx (mode
);
3571 blocks
= gen_reg_rtx (mode
);
3573 convert_move (count
, len
, 1);
3574 emit_cmp_and_jump_insns (count
, const0_rtx
,
3575 EQ
, NULL_RTX
, mode
, 1, end_label
);
3577 emit_move_insn (dst_addr
, force_operand (XEXP (dst
, 0), NULL_RTX
));
3578 emit_move_insn (src_addr
, force_operand (XEXP (src
, 0), NULL_RTX
));
3579 dst
= change_address (dst
, VOIDmode
, dst_addr
);
3580 src
= change_address (src
, VOIDmode
, src_addr
);
3582 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1, 0);
3584 emit_move_insn (count
, temp
);
3586 temp
= expand_binop (mode
, lshr_optab
, count
, GEN_INT (8), blocks
, 1, 0);
3588 emit_move_insn (blocks
, temp
);
3590 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3591 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3593 emit_label (loop_start_label
);
3595 emit_insn (gen_movmem_short (dst
, src
, GEN_INT (255)));
3596 s390_load_address (dst_addr
,
3597 gen_rtx_PLUS (Pmode
, dst_addr
, GEN_INT (256)));
3598 s390_load_address (src_addr
,
3599 gen_rtx_PLUS (Pmode
, src_addr
, GEN_INT (256)));
3601 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1, 0);
3603 emit_move_insn (blocks
, temp
);
3605 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3606 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3608 emit_jump (loop_start_label
);
3609 emit_label (loop_end_label
);
3611 emit_insn (gen_movmem_short (dst
, src
,
3612 convert_to_mode (Pmode
, count
, 1)));
3613 emit_label (end_label
);
3617 /* Emit code to set LEN bytes at DST to VAL.
3618 Make use of clrmem if VAL is zero. */
3621 s390_expand_setmem (rtx dst
, rtx len
, rtx val
)
3623 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) == 0)
3626 gcc_assert (GET_CODE (val
) == CONST_INT
|| GET_MODE (val
) == QImode
);
3628 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) > 0 && INTVAL (len
) <= 257)
3630 if (val
== const0_rtx
&& INTVAL (len
) <= 256)
3631 emit_insn (gen_clrmem_short (dst
, GEN_INT (INTVAL (len
) - 1)));
3634 /* Initialize memory by storing the first byte. */
3635 emit_move_insn (adjust_address (dst
, QImode
, 0), val
);
3637 if (INTVAL (len
) > 1)
3639 /* Initiate 1 byte overlap move.
3640 The first byte of DST is propagated through DSTP1.
3641 Prepare a movmem for: DST+1 = DST (length = LEN - 1).
3642 DST is set to size 1 so the rest of the memory location
3643 does not count as source operand. */
3644 rtx dstp1
= adjust_address (dst
, VOIDmode
, 1);
3645 set_mem_size (dst
, const1_rtx
);
3647 emit_insn (gen_movmem_short (dstp1
, dst
,
3648 GEN_INT (INTVAL (len
) - 2)));
3653 else if (TARGET_MVCLE
)
3655 val
= force_not_mem (convert_modes (Pmode
, QImode
, val
, 1));
3656 emit_insn (gen_setmem_long (dst
, convert_to_mode (Pmode
, len
, 1), val
));
3661 rtx dst_addr
, src_addr
, count
, blocks
, temp
, dstp1
= NULL_RTX
;
3662 rtx loop_start_label
= gen_label_rtx ();
3663 rtx loop_end_label
= gen_label_rtx ();
3664 rtx end_label
= gen_label_rtx ();
3665 enum machine_mode mode
;
3667 mode
= GET_MODE (len
);
3668 if (mode
== VOIDmode
)
3671 dst_addr
= gen_reg_rtx (Pmode
);
3672 src_addr
= gen_reg_rtx (Pmode
);
3673 count
= gen_reg_rtx (mode
);
3674 blocks
= gen_reg_rtx (mode
);
3676 convert_move (count
, len
, 1);
3677 emit_cmp_and_jump_insns (count
, const0_rtx
,
3678 EQ
, NULL_RTX
, mode
, 1, end_label
);
3680 emit_move_insn (dst_addr
, force_operand (XEXP (dst
, 0), NULL_RTX
));
3681 dst
= change_address (dst
, VOIDmode
, dst_addr
);
3683 if (val
== const0_rtx
)
3684 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1, 0);
3687 dstp1
= adjust_address (dst
, VOIDmode
, 1);
3688 set_mem_size (dst
, const1_rtx
);
3690 /* Initialize memory by storing the first byte. */
3691 emit_move_insn (adjust_address (dst
, QImode
, 0), val
);
3693 /* If count is 1 we are done. */
3694 emit_cmp_and_jump_insns (count
, const1_rtx
,
3695 EQ
, NULL_RTX
, mode
, 1, end_label
);
3697 temp
= expand_binop (mode
, add_optab
, count
, GEN_INT (-2), count
, 1, 0);
3700 emit_move_insn (count
, temp
);
3702 temp
= expand_binop (mode
, lshr_optab
, count
, GEN_INT (8), blocks
, 1, 0);
3704 emit_move_insn (blocks
, temp
);
3706 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3707 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3709 emit_label (loop_start_label
);
3711 if (val
== const0_rtx
)
3712 emit_insn (gen_clrmem_short (dst
, GEN_INT (255)));
3714 emit_insn (gen_movmem_short (dstp1
, dst
, GEN_INT (255)));
3715 s390_load_address (dst_addr
,
3716 gen_rtx_PLUS (Pmode
, dst_addr
, GEN_INT (256)));
3718 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1, 0);
3720 emit_move_insn (blocks
, temp
);
3722 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3723 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3725 emit_jump (loop_start_label
);
3726 emit_label (loop_end_label
);
3728 if (val
== const0_rtx
)
3729 emit_insn (gen_clrmem_short (dst
, convert_to_mode (Pmode
, count
, 1)));
3731 emit_insn (gen_movmem_short (dstp1
, dst
, convert_to_mode (Pmode
, count
, 1)));
3732 emit_label (end_label
);
3736 /* Emit code to compare LEN bytes at OP0 with those at OP1,
3737 and return the result in TARGET. */
3740 s390_expand_cmpmem (rtx target
, rtx op0
, rtx op1
, rtx len
)
3742 rtx ccreg
= gen_rtx_REG (CCUmode
, CC_REGNUM
);
3745 /* As the result of CMPINT is inverted compared to what we need,
3746 we have to swap the operands. */
3747 tmp
= op0
; op0
= op1
; op1
= tmp
;
3749 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) >= 0 && INTVAL (len
) <= 256)
3751 if (INTVAL (len
) > 0)
3753 emit_insn (gen_cmpmem_short (op0
, op1
, GEN_INT (INTVAL (len
) - 1)));
3754 emit_insn (gen_cmpint (target
, ccreg
));
3757 emit_move_insn (target
, const0_rtx
);
3759 else if (TARGET_MVCLE
)
3761 emit_insn (gen_cmpmem_long (op0
, op1
, convert_to_mode (Pmode
, len
, 1)));
3762 emit_insn (gen_cmpint (target
, ccreg
));
3766 rtx addr0
, addr1
, count
, blocks
, temp
;
3767 rtx loop_start_label
= gen_label_rtx ();
3768 rtx loop_end_label
= gen_label_rtx ();
3769 rtx end_label
= gen_label_rtx ();
3770 enum machine_mode mode
;
3772 mode
= GET_MODE (len
);
3773 if (mode
== VOIDmode
)
3776 addr0
= gen_reg_rtx (Pmode
);
3777 addr1
= gen_reg_rtx (Pmode
);
3778 count
= gen_reg_rtx (mode
);
3779 blocks
= gen_reg_rtx (mode
);
3781 convert_move (count
, len
, 1);
3782 emit_cmp_and_jump_insns (count
, const0_rtx
,
3783 EQ
, NULL_RTX
, mode
, 1, end_label
);
3785 emit_move_insn (addr0
, force_operand (XEXP (op0
, 0), NULL_RTX
));
3786 emit_move_insn (addr1
, force_operand (XEXP (op1
, 0), NULL_RTX
));
3787 op0
= change_address (op0
, VOIDmode
, addr0
);
3788 op1
= change_address (op1
, VOIDmode
, addr1
);
3790 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1, 0);
3792 emit_move_insn (count
, temp
);
3794 temp
= expand_binop (mode
, lshr_optab
, count
, GEN_INT (8), blocks
, 1, 0);
3796 emit_move_insn (blocks
, temp
);
3798 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3799 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3801 emit_label (loop_start_label
);
3803 emit_insn (gen_cmpmem_short (op0
, op1
, GEN_INT (255)));
3804 temp
= gen_rtx_NE (VOIDmode
, ccreg
, const0_rtx
);
3805 temp
= gen_rtx_IF_THEN_ELSE (VOIDmode
, temp
,
3806 gen_rtx_LABEL_REF (VOIDmode
, end_label
), pc_rtx
);
3807 temp
= gen_rtx_SET (VOIDmode
, pc_rtx
, temp
);
3808 emit_jump_insn (temp
);
3810 s390_load_address (addr0
,
3811 gen_rtx_PLUS (Pmode
, addr0
, GEN_INT (256)));
3812 s390_load_address (addr1
,
3813 gen_rtx_PLUS (Pmode
, addr1
, GEN_INT (256)));
3815 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1, 0);
3817 emit_move_insn (blocks
, temp
);
3819 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3820 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3822 emit_jump (loop_start_label
);
3823 emit_label (loop_end_label
);
3825 emit_insn (gen_cmpmem_short (op0
, op1
,
3826 convert_to_mode (Pmode
, count
, 1)));
3827 emit_label (end_label
);
3829 emit_insn (gen_cmpint (target
, ccreg
));
3834 /* Expand conditional increment or decrement using alc/slb instructions.
3835 Should generate code setting DST to either SRC or SRC + INCREMENT,
3836 depending on the result of the comparison CMP_OP0 CMP_CODE CMP_OP1.
3837 Returns true if successful, false otherwise.
3839 That makes it possible to implement some if-constructs without jumps e.g.:
3840 (borrow = CC0 | CC1 and carry = CC2 | CC3)
3841 unsigned int a, b, c;
3842 if (a < b) c++; -> CCU b > a -> CC2; c += carry;
3843 if (a < b) c--; -> CCL3 a - b -> borrow; c -= borrow;
3844 if (a <= b) c++; -> CCL3 b - a -> borrow; c += carry;
3845 if (a <= b) c--; -> CCU a <= b -> borrow; c -= borrow;
3847 Checks for EQ and NE with a nonzero value need an additional xor e.g.:
3848 if (a == b) c++; -> CCL3 a ^= b; 0 - a -> borrow; c += carry;
3849 if (a == b) c--; -> CCU a ^= b; a <= 0 -> CC0 | CC1; c -= borrow;
3850 if (a != b) c++; -> CCU a ^= b; a > 0 -> CC2; c += carry;
3851 if (a != b) c--; -> CCL3 a ^= b; 0 - a -> borrow; c -= borrow; */
3854 s390_expand_addcc (enum rtx_code cmp_code
, rtx cmp_op0
, rtx cmp_op1
,
3855 rtx dst
, rtx src
, rtx increment
)
3857 enum machine_mode cmp_mode
;
3858 enum machine_mode cc_mode
;
3864 if ((GET_MODE (cmp_op0
) == SImode
|| GET_MODE (cmp_op0
) == VOIDmode
)
3865 && (GET_MODE (cmp_op1
) == SImode
|| GET_MODE (cmp_op1
) == VOIDmode
))
3867 else if ((GET_MODE (cmp_op0
) == DImode
|| GET_MODE (cmp_op0
) == VOIDmode
)
3868 && (GET_MODE (cmp_op1
) == DImode
|| GET_MODE (cmp_op1
) == VOIDmode
))
3873 /* Try ADD LOGICAL WITH CARRY. */
3874 if (increment
== const1_rtx
)
3876 /* Determine CC mode to use. */
3877 if (cmp_code
== EQ
|| cmp_code
== NE
)
3879 if (cmp_op1
!= const0_rtx
)
3881 cmp_op0
= expand_simple_binop (cmp_mode
, XOR
, cmp_op0
, cmp_op1
,
3882 NULL_RTX
, 0, OPTAB_WIDEN
);
3883 cmp_op1
= const0_rtx
;
3886 cmp_code
= cmp_code
== EQ
? LEU
: GTU
;
3889 if (cmp_code
== LTU
|| cmp_code
== LEU
)
3894 cmp_code
= swap_condition (cmp_code
);
3911 /* Emit comparison instruction pattern. */
3912 if (!register_operand (cmp_op0
, cmp_mode
))
3913 cmp_op0
= force_reg (cmp_mode
, cmp_op0
);
3915 insn
= gen_rtx_SET (VOIDmode
, gen_rtx_REG (cc_mode
, CC_REGNUM
),
3916 gen_rtx_COMPARE (cc_mode
, cmp_op0
, cmp_op1
));
3917 /* We use insn_invalid_p here to add clobbers if required. */
3918 ret
= insn_invalid_p (emit_insn (insn
));
3921 /* Emit ALC instruction pattern. */
3922 op_res
= gen_rtx_fmt_ee (cmp_code
, GET_MODE (dst
),
3923 gen_rtx_REG (cc_mode
, CC_REGNUM
),
3926 if (src
!= const0_rtx
)
3928 if (!register_operand (src
, GET_MODE (dst
)))
3929 src
= force_reg (GET_MODE (dst
), src
);
3931 src
= gen_rtx_PLUS (GET_MODE (dst
), src
, const0_rtx
);
3932 op_res
= gen_rtx_PLUS (GET_MODE (dst
), src
, op_res
);
3935 p
= rtvec_alloc (2);
3937 gen_rtx_SET (VOIDmode
, dst
, op_res
);
3939 gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
3940 emit_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
3945 /* Try SUBTRACT LOGICAL WITH BORROW. */
3946 if (increment
== constm1_rtx
)
3948 /* Determine CC mode to use. */
3949 if (cmp_code
== EQ
|| cmp_code
== NE
)
3951 if (cmp_op1
!= const0_rtx
)
3953 cmp_op0
= expand_simple_binop (cmp_mode
, XOR
, cmp_op0
, cmp_op1
,
3954 NULL_RTX
, 0, OPTAB_WIDEN
);
3955 cmp_op1
= const0_rtx
;
3958 cmp_code
= cmp_code
== EQ
? LEU
: GTU
;
3961 if (cmp_code
== GTU
|| cmp_code
== GEU
)
3966 cmp_code
= swap_condition (cmp_code
);
3983 /* Emit comparison instruction pattern. */
3984 if (!register_operand (cmp_op0
, cmp_mode
))
3985 cmp_op0
= force_reg (cmp_mode
, cmp_op0
);
3987 insn
= gen_rtx_SET (VOIDmode
, gen_rtx_REG (cc_mode
, CC_REGNUM
),
3988 gen_rtx_COMPARE (cc_mode
, cmp_op0
, cmp_op1
));
3989 /* We use insn_invalid_p here to add clobbers if required. */
3990 ret
= insn_invalid_p (emit_insn (insn
));
3993 /* Emit SLB instruction pattern. */
3994 if (!register_operand (src
, GET_MODE (dst
)))
3995 src
= force_reg (GET_MODE (dst
), src
);
3997 op_res
= gen_rtx_MINUS (GET_MODE (dst
),
3998 gen_rtx_MINUS (GET_MODE (dst
), src
, const0_rtx
),
3999 gen_rtx_fmt_ee (cmp_code
, GET_MODE (dst
),
4000 gen_rtx_REG (cc_mode
, CC_REGNUM
),
4002 p
= rtvec_alloc (2);
4004 gen_rtx_SET (VOIDmode
, dst
, op_res
);
4006 gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
4007 emit_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
4015 /* Expand code for the insv template. Return true if successful, false else. */
4018 s390_expand_insv (rtx dest
, rtx op1
, rtx op2
, rtx src
)
4020 int bitsize
= INTVAL (op1
);
4021 int bitpos
= INTVAL (op2
);
4023 /* We need byte alignment. */
4024 if (bitsize
% BITS_PER_UNIT
)
4028 && memory_operand (dest
, VOIDmode
)
4029 && (register_operand (src
, word_mode
)
4030 || const_int_operand (src
, VOIDmode
)))
4032 /* Emit standard pattern if possible. */
4033 enum machine_mode mode
= smallest_mode_for_size (bitsize
, MODE_INT
);
4034 if (GET_MODE_BITSIZE (mode
) == bitsize
)
4035 emit_move_insn (adjust_address (dest
, mode
, 0), gen_lowpart (mode
, src
));
4037 /* (set (ze (mem)) (const_int)). */
4038 else if (const_int_operand (src
, VOIDmode
))
4040 int size
= bitsize
/ BITS_PER_UNIT
;
4041 rtx src_mem
= adjust_address (force_const_mem (word_mode
, src
), BLKmode
,
4042 GET_MODE_SIZE (word_mode
) - size
);
4044 dest
= adjust_address (dest
, BLKmode
, 0);
4045 set_mem_size (dest
, GEN_INT (size
));
4046 s390_expand_movmem (dest
, src_mem
, GEN_INT (size
));
4049 /* (set (ze (mem)) (reg)). */
4050 else if (register_operand (src
, word_mode
))
4052 if (bitsize
<= GET_MODE_BITSIZE (SImode
))
4053 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
, op1
,
4057 /* Emit st,stcmh sequence. */
4058 int stcmh_width
= bitsize
- GET_MODE_BITSIZE (SImode
);
4059 int size
= stcmh_width
/ BITS_PER_UNIT
;
4061 emit_move_insn (adjust_address (dest
, SImode
, size
),
4062 gen_lowpart (SImode
, src
));
4063 set_mem_size (dest
, GEN_INT (size
));
4064 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
, GEN_INT
4065 (stcmh_width
), const0_rtx
),
4066 gen_rtx_LSHIFTRT (word_mode
, src
, GEN_INT
4067 (GET_MODE_BITSIZE (SImode
))));
4076 /* (set (ze (reg)) (const_int)). */
4078 && register_operand (dest
, word_mode
)
4079 && (bitpos
% 16) == 0
4080 && (bitsize
% 16) == 0
4081 && const_int_operand (src
, VOIDmode
))
4083 HOST_WIDE_INT val
= INTVAL (src
);
4084 int regpos
= bitpos
+ bitsize
;
4086 while (regpos
> bitpos
)
4088 enum machine_mode putmode
;
4091 if (TARGET_EXTIMM
&& (regpos
% 32 == 0) && (regpos
>= bitpos
+ 32))
4096 putsize
= GET_MODE_BITSIZE (putmode
);
4098 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
,
4101 gen_int_mode (val
, putmode
));
4104 gcc_assert (regpos
== bitpos
);
4111 /* A subroutine of s390_expand_cs_hqi and s390_expand_atomic which returns a
4112 register that holds VAL of mode MODE shifted by COUNT bits. */
4115 s390_expand_mask_and_shift (rtx val
, enum machine_mode mode
, rtx count
)
4117 val
= expand_simple_binop (SImode
, AND
, val
, GEN_INT (GET_MODE_MASK (mode
)),
4118 NULL_RTX
, 1, OPTAB_DIRECT
);
4119 return expand_simple_binop (SImode
, ASHIFT
, val
, count
,
4120 NULL_RTX
, 1, OPTAB_DIRECT
);
4123 /* Structure to hold the initial parameters for a compare_and_swap operation
4124 in HImode and QImode. */
4126 struct alignment_context
4128 rtx memsi
; /* SI aligned memory location. */
4129 rtx shift
; /* Bit offset with regard to lsb. */
4130 rtx modemask
; /* Mask of the HQImode shifted by SHIFT bits. */
4131 rtx modemaski
; /* ~modemask */
4132 bool aligned
; /* True if memory is aligned, false else. */
4135 /* A subroutine of s390_expand_cs_hqi and s390_expand_atomic to initialize
4136 structure AC for transparent simplifying, if the memory alignment is known
4137 to be at least 32bit. MEM is the memory location for the actual operation
4138 and MODE its mode. */
4141 init_alignment_context (struct alignment_context
*ac
, rtx mem
,
4142 enum machine_mode mode
)
4144 ac
->shift
= GEN_INT (GET_MODE_SIZE (SImode
) - GET_MODE_SIZE (mode
));
4145 ac
->aligned
= (MEM_ALIGN (mem
) >= GET_MODE_BITSIZE (SImode
));
4148 ac
->memsi
= adjust_address (mem
, SImode
, 0); /* Memory is aligned. */
4151 /* Alignment is unknown. */
4152 rtx byteoffset
, addr
, align
;
4154 /* Force the address into a register. */
4155 addr
= force_reg (Pmode
, XEXP (mem
, 0));
4157 /* Align it to SImode. */
4158 align
= expand_simple_binop (Pmode
, AND
, addr
,
4159 GEN_INT (-GET_MODE_SIZE (SImode
)),
4160 NULL_RTX
, 1, OPTAB_DIRECT
);
4162 ac
->memsi
= gen_rtx_MEM (SImode
, align
);
4163 MEM_VOLATILE_P (ac
->memsi
) = MEM_VOLATILE_P (mem
);
4164 set_mem_alias_set (ac
->memsi
, ALIAS_SET_MEMORY_BARRIER
);
4165 set_mem_align (ac
->memsi
, GET_MODE_BITSIZE (SImode
));
4167 /* Calculate shiftcount. */
4168 byteoffset
= expand_simple_binop (Pmode
, AND
, addr
,
4169 GEN_INT (GET_MODE_SIZE (SImode
) - 1),
4170 NULL_RTX
, 1, OPTAB_DIRECT
);
4171 /* As we already have some offset, evaluate the remaining distance. */
4172 ac
->shift
= expand_simple_binop (SImode
, MINUS
, ac
->shift
, byteoffset
,
4173 NULL_RTX
, 1, OPTAB_DIRECT
);
4176 /* Shift is the byte count, but we need the bitcount. */
4177 ac
->shift
= expand_simple_binop (SImode
, MULT
, ac
->shift
, GEN_INT (BITS_PER_UNIT
),
4178 NULL_RTX
, 1, OPTAB_DIRECT
);
4179 /* Calculate masks. */
4180 ac
->modemask
= expand_simple_binop (SImode
, ASHIFT
,
4181 GEN_INT (GET_MODE_MASK (mode
)), ac
->shift
,
4182 NULL_RTX
, 1, OPTAB_DIRECT
);
4183 ac
->modemaski
= expand_simple_unop (SImode
, NOT
, ac
->modemask
, NULL_RTX
, 1);
4186 /* Expand an atomic compare and swap operation for HImode and QImode. MEM is
4187 the memory location, CMP the old value to compare MEM with and NEW the value
4188 to set if CMP == MEM.
4189 CMP is never in memory for compare_and_swap_cc because
4190 expand_bool_compare_and_swap puts it into a register for later compare. */
4193 s390_expand_cs_hqi (enum machine_mode mode
, rtx target
, rtx mem
, rtx cmp
, rtx
new)
4195 struct alignment_context ac
;
4196 rtx cmpv
, newv
, val
, resv
, cc
;
4197 rtx res
= gen_reg_rtx (SImode
);
4198 rtx csloop
= gen_label_rtx ();
4199 rtx csend
= gen_label_rtx ();
4201 gcc_assert (register_operand (target
, VOIDmode
));
4202 gcc_assert (MEM_P (mem
));
4204 init_alignment_context (&ac
, mem
, mode
);
4206 /* Shift the values to the correct bit positions. */
4207 if (!(ac
.aligned
&& MEM_P (cmp
)))
4208 cmp
= s390_expand_mask_and_shift (cmp
, mode
, ac
.shift
);
4209 if (!(ac
.aligned
&& MEM_P (new)))
4210 new = s390_expand_mask_and_shift (new, mode
, ac
.shift
);
4212 /* Load full word. Subsequent loads are performed by CS. */
4213 val
= expand_simple_binop (SImode
, AND
, ac
.memsi
, ac
.modemaski
,
4214 NULL_RTX
, 1, OPTAB_DIRECT
);
4216 /* Start CS loop. */
4217 emit_label (csloop
);
4218 /* val = "<mem>00..0<mem>"
4219 * cmp = "00..0<cmp>00..0"
4220 * new = "00..0<new>00..0"
4223 /* Patch cmp and new with val at correct position. */
4224 if (ac
.aligned
&& MEM_P (cmp
))
4226 cmpv
= force_reg (SImode
, val
);
4227 store_bit_field (cmpv
, GET_MODE_BITSIZE (mode
), 0, SImode
, cmp
);
4230 cmpv
= force_reg (SImode
, expand_simple_binop (SImode
, IOR
, cmp
, val
,
4231 NULL_RTX
, 1, OPTAB_DIRECT
));
4232 if (ac
.aligned
&& MEM_P (new))
4234 newv
= force_reg (SImode
, val
);
4235 store_bit_field (newv
, GET_MODE_BITSIZE (mode
), 0, SImode
, new);
4238 newv
= force_reg (SImode
, expand_simple_binop (SImode
, IOR
, new, val
,
4239 NULL_RTX
, 1, OPTAB_DIRECT
));
4241 /* Jump to end if we're done (likely?). */
4242 s390_emit_jump (csend
, s390_emit_compare_and_swap (EQ
, res
, ac
.memsi
,
4245 /* Check for changes outside mode. */
4246 resv
= expand_simple_binop (SImode
, AND
, res
, ac
.modemaski
,
4247 NULL_RTX
, 1, OPTAB_DIRECT
);
4248 cc
= s390_emit_compare (NE
, resv
, val
);
4249 emit_move_insn (val
, resv
);
4250 /* Loop internal if so. */
4251 s390_emit_jump (csloop
, cc
);
4255 /* Return the correct part of the bitfield. */
4256 convert_move (target
, expand_simple_binop (SImode
, LSHIFTRT
, res
, ac
.shift
,
4257 NULL_RTX
, 1, OPTAB_DIRECT
), 1);
4260 /* Expand an atomic operation CODE of mode MODE. MEM is the memory location
4261 and VAL the value to play with. If AFTER is true then store the value
4262 MEM holds after the operation, if AFTER is false then store the value MEM
4263 holds before the operation. If TARGET is zero then discard that value, else
4264 store it to TARGET. */
4267 s390_expand_atomic (enum machine_mode mode
, enum rtx_code code
,
4268 rtx target
, rtx mem
, rtx val
, bool after
)
4270 struct alignment_context ac
;
4272 rtx
new = gen_reg_rtx (SImode
);
4273 rtx orig
= gen_reg_rtx (SImode
);
4274 rtx csloop
= gen_label_rtx ();
4276 gcc_assert (!target
|| register_operand (target
, VOIDmode
));
4277 gcc_assert (MEM_P (mem
));
4279 init_alignment_context (&ac
, mem
, mode
);
4281 /* Shift val to the correct bit positions.
4282 Preserve "icm", but prevent "ex icm". */
4283 if (!(ac
.aligned
&& code
== SET
&& MEM_P (val
)))
4284 val
= s390_expand_mask_and_shift (val
, mode
, ac
.shift
);
4286 /* Further preparation insns. */
4287 if (code
== PLUS
|| code
== MINUS
)
4288 emit_move_insn (orig
, val
);
4289 else if (code
== MULT
|| code
== AND
) /* val = "11..1<val>11..1" */
4290 val
= expand_simple_binop (SImode
, XOR
, val
, ac
.modemaski
,
4291 NULL_RTX
, 1, OPTAB_DIRECT
);
4293 /* Load full word. Subsequent loads are performed by CS. */
4294 cmp
= force_reg (SImode
, ac
.memsi
);
4296 /* Start CS loop. */
4297 emit_label (csloop
);
4298 emit_move_insn (new, cmp
);
4300 /* Patch new with val at correct position. */
4305 val
= expand_simple_binop (SImode
, code
, new, orig
,
4306 NULL_RTX
, 1, OPTAB_DIRECT
);
4307 val
= expand_simple_binop (SImode
, AND
, val
, ac
.modemask
,
4308 NULL_RTX
, 1, OPTAB_DIRECT
);
4311 if (ac
.aligned
&& MEM_P (val
))
4312 store_bit_field (new, GET_MODE_BITSIZE (mode
), 0, SImode
, val
);
4315 new = expand_simple_binop (SImode
, AND
, new, ac
.modemaski
,
4316 NULL_RTX
, 1, OPTAB_DIRECT
);
4317 new = expand_simple_binop (SImode
, IOR
, new, val
,
4318 NULL_RTX
, 1, OPTAB_DIRECT
);
4324 new = expand_simple_binop (SImode
, code
, new, val
,
4325 NULL_RTX
, 1, OPTAB_DIRECT
);
4327 case MULT
: /* NAND */
4328 new = expand_simple_binop (SImode
, XOR
, new, ac
.modemask
,
4329 NULL_RTX
, 1, OPTAB_DIRECT
);
4330 new = expand_simple_binop (SImode
, AND
, new, val
,
4331 NULL_RTX
, 1, OPTAB_DIRECT
);
4337 s390_emit_jump (csloop
, s390_emit_compare_and_swap (NE
, cmp
,
4338 ac
.memsi
, cmp
, new));
4340 /* Return the correct part of the bitfield. */
4342 convert_move (target
, expand_simple_binop (SImode
, LSHIFTRT
,
4343 after
? new : cmp
, ac
.shift
,
4344 NULL_RTX
, 1, OPTAB_DIRECT
), 1);
4347 /* This is called from dwarf2out.c via TARGET_ASM_OUTPUT_DWARF_DTPREL.
4348 We need to emit DTP-relative relocations. */
4350 static void s390_output_dwarf_dtprel (FILE *, int, rtx
) ATTRIBUTE_UNUSED
;
4353 s390_output_dwarf_dtprel (FILE *file
, int size
, rtx x
)
4358 fputs ("\t.long\t", file
);
4361 fputs ("\t.quad\t", file
);
4366 output_addr_const (file
, x
);
4367 fputs ("@DTPOFF", file
);
4370 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
4371 /* Implement TARGET_MANGLE_TYPE. */
4374 s390_mangle_type (tree type
)
4376 if (TYPE_MAIN_VARIANT (type
) == long_double_type_node
4377 && TARGET_LONG_DOUBLE_128
)
4380 /* For all other types, use normal C++ mangling. */
4385 /* In the name of slightly smaller debug output, and to cater to
4386 general assembler lossage, recognize various UNSPEC sequences
4387 and turn them back into a direct symbol reference. */
4390 s390_delegitimize_address (rtx orig_x
)
4394 if (GET_CODE (x
) != MEM
)
4398 if (GET_CODE (x
) == PLUS
4399 && GET_CODE (XEXP (x
, 1)) == CONST
4400 && GET_CODE (XEXP (x
, 0)) == REG
4401 && REGNO (XEXP (x
, 0)) == PIC_OFFSET_TABLE_REGNUM
)
4403 y
= XEXP (XEXP (x
, 1), 0);
4404 if (GET_CODE (y
) == UNSPEC
4405 && XINT (y
, 1) == UNSPEC_GOT
)
4406 return XVECEXP (y
, 0, 0);
4410 if (GET_CODE (x
) == CONST
)
4413 if (GET_CODE (y
) == UNSPEC
4414 && XINT (y
, 1) == UNSPEC_GOTENT
)
4415 return XVECEXP (y
, 0, 0);
4422 /* Output operand OP to stdio stream FILE.
4423 OP is an address (register + offset) which is not used to address data;
4424 instead the rightmost bits are interpreted as the value. */
4427 print_shift_count_operand (FILE *file
, rtx op
)
4429 HOST_WIDE_INT offset
;
4432 /* Extract base register and offset. */
4433 if (!s390_decompose_shift_count (op
, &base
, &offset
))
4439 gcc_assert (GET_CODE (base
) == REG
);
4440 gcc_assert (REGNO (base
) < FIRST_PSEUDO_REGISTER
);
4441 gcc_assert (REGNO_REG_CLASS (REGNO (base
)) == ADDR_REGS
);
4444 /* Offsets are constricted to twelve bits. */
4445 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, offset
& ((1 << 12) - 1));
4447 fprintf (file
, "(%s)", reg_names
[REGNO (base
)]);
4450 /* See 'get_some_local_dynamic_name'. */
4453 get_some_local_dynamic_name_1 (rtx
*px
, void *data ATTRIBUTE_UNUSED
)
4457 if (GET_CODE (x
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (x
))
4459 x
= get_pool_constant (x
);
4460 return for_each_rtx (&x
, get_some_local_dynamic_name_1
, 0);
4463 if (GET_CODE (x
) == SYMBOL_REF
4464 && tls_symbolic_operand (x
) == TLS_MODEL_LOCAL_DYNAMIC
)
4466 cfun
->machine
->some_ld_name
= XSTR (x
, 0);
4473 /* Locate some local-dynamic symbol still in use by this function
4474 so that we can print its name in local-dynamic base patterns. */
4477 get_some_local_dynamic_name (void)
4481 if (cfun
->machine
->some_ld_name
)
4482 return cfun
->machine
->some_ld_name
;
4484 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
4486 && for_each_rtx (&PATTERN (insn
), get_some_local_dynamic_name_1
, 0))
4487 return cfun
->machine
->some_ld_name
;
4492 /* Output machine-dependent UNSPECs occurring in address constant X
4493 in assembler syntax to stdio stream FILE. Returns true if the
4494 constant X could be recognized, false otherwise. */
4497 s390_output_addr_const_extra (FILE *file
, rtx x
)
4499 if (GET_CODE (x
) == UNSPEC
&& XVECLEN (x
, 0) == 1)
4500 switch (XINT (x
, 1))
4503 output_addr_const (file
, XVECEXP (x
, 0, 0));
4504 fprintf (file
, "@GOTENT");
4507 output_addr_const (file
, XVECEXP (x
, 0, 0));
4508 fprintf (file
, "@GOT");
4511 output_addr_const (file
, XVECEXP (x
, 0, 0));
4512 fprintf (file
, "@GOTOFF");
4515 output_addr_const (file
, XVECEXP (x
, 0, 0));
4516 fprintf (file
, "@PLT");
4519 output_addr_const (file
, XVECEXP (x
, 0, 0));
4520 fprintf (file
, "@PLTOFF");
4523 output_addr_const (file
, XVECEXP (x
, 0, 0));
4524 fprintf (file
, "@TLSGD");
4527 assemble_name (file
, get_some_local_dynamic_name ());
4528 fprintf (file
, "@TLSLDM");
4531 output_addr_const (file
, XVECEXP (x
, 0, 0));
4532 fprintf (file
, "@DTPOFF");
4535 output_addr_const (file
, XVECEXP (x
, 0, 0));
4536 fprintf (file
, "@NTPOFF");
4538 case UNSPEC_GOTNTPOFF
:
4539 output_addr_const (file
, XVECEXP (x
, 0, 0));
4540 fprintf (file
, "@GOTNTPOFF");
4542 case UNSPEC_INDNTPOFF
:
4543 output_addr_const (file
, XVECEXP (x
, 0, 0));
4544 fprintf (file
, "@INDNTPOFF");
4551 /* Output address operand ADDR in assembler syntax to
4552 stdio stream FILE. */
4555 print_operand_address (FILE *file
, rtx addr
)
4557 struct s390_address ad
;
4559 if (!s390_decompose_address (addr
, &ad
)
4560 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
4561 || (ad
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (ad
.indx
))))
4562 output_operand_lossage ("cannot decompose address");
4565 output_addr_const (file
, ad
.disp
);
4567 fprintf (file
, "0");
4569 if (ad
.base
&& ad
.indx
)
4570 fprintf (file
, "(%s,%s)", reg_names
[REGNO (ad
.indx
)],
4571 reg_names
[REGNO (ad
.base
)]);
4573 fprintf (file
, "(%s)", reg_names
[REGNO (ad
.base
)]);
4576 /* Output operand X in assembler syntax to stdio stream FILE.
4577 CODE specified the format flag. The following format flags
4580 'C': print opcode suffix for branch condition.
4581 'D': print opcode suffix for inverse branch condition.
4582 'J': print tls_load/tls_gdcall/tls_ldcall suffix
4583 'G': print the size of the operand in bytes.
4584 'O': print only the displacement of a memory reference.
4585 'R': print only the base register of a memory reference.
4586 'S': print S-type memory reference (base+displacement).
4587 'N': print the second word of a DImode operand.
4588 'M': print the second word of a TImode operand.
4589 'Y': print shift count operand.
4591 'b': print integer X as if it's an unsigned byte.
4592 'x': print integer X as if it's an unsigned halfword.
4593 'h': print integer X as if it's a signed halfword.
4594 'i': print the first nonzero HImode part of X.
4595 'j': print the first HImode part unequal to -1 of X.
4596 'k': print the first nonzero SImode part of X.
4597 'm': print the first SImode part unequal to -1 of X.
4598 'o': print integer X as if it's an unsigned 32bit word. */
4601 print_operand (FILE *file
, rtx x
, int code
)
4606 fprintf (file
, s390_branch_condition_mnemonic (x
, FALSE
));
4610 fprintf (file
, s390_branch_condition_mnemonic (x
, TRUE
));
4614 if (GET_CODE (x
) == SYMBOL_REF
)
4616 fprintf (file
, "%s", ":tls_load:");
4617 output_addr_const (file
, x
);
4619 else if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_TLSGD
)
4621 fprintf (file
, "%s", ":tls_gdcall:");
4622 output_addr_const (file
, XVECEXP (x
, 0, 0));
4624 else if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_TLSLDM
)
4626 fprintf (file
, "%s", ":tls_ldcall:");
4627 assemble_name (file
, get_some_local_dynamic_name ());
4634 fprintf (file
, "%u", GET_MODE_SIZE (GET_MODE (x
)));
4639 struct s390_address ad
;
4642 gcc_assert (GET_CODE (x
) == MEM
);
4643 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
4645 gcc_assert (!ad
.base
|| REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)));
4646 gcc_assert (!ad
.indx
);
4649 output_addr_const (file
, ad
.disp
);
4651 fprintf (file
, "0");
4657 struct s390_address ad
;
4660 gcc_assert (GET_CODE (x
) == MEM
);
4661 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
4663 gcc_assert (!ad
.base
|| REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)));
4664 gcc_assert (!ad
.indx
);
4667 fprintf (file
, "%s", reg_names
[REGNO (ad
.base
)]);
4669 fprintf (file
, "0");
4675 struct s390_address ad
;
4678 gcc_assert (GET_CODE (x
) == MEM
);
4679 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
4681 gcc_assert (!ad
.base
|| REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)));
4682 gcc_assert (!ad
.indx
);
4685 output_addr_const (file
, ad
.disp
);
4687 fprintf (file
, "0");
4690 fprintf (file
, "(%s)", reg_names
[REGNO (ad
.base
)]);
4695 if (GET_CODE (x
) == REG
)
4696 x
= gen_rtx_REG (GET_MODE (x
), REGNO (x
) + 1);
4697 else if (GET_CODE (x
) == MEM
)
4698 x
= change_address (x
, VOIDmode
, plus_constant (XEXP (x
, 0), 4));
4704 if (GET_CODE (x
) == REG
)
4705 x
= gen_rtx_REG (GET_MODE (x
), REGNO (x
) + 1);
4706 else if (GET_CODE (x
) == MEM
)
4707 x
= change_address (x
, VOIDmode
, plus_constant (XEXP (x
, 0), 8));
4713 print_shift_count_operand (file
, x
);
4717 switch (GET_CODE (x
))
4720 fprintf (file
, "%s", reg_names
[REGNO (x
)]);
4724 output_address (XEXP (x
, 0));
4731 output_addr_const (file
, x
);
4736 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
) & 0xff);
4737 else if (code
== 'x')
4738 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
) & 0xffff);
4739 else if (code
== 'h')
4740 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, ((INTVAL (x
) & 0xffff) ^ 0x8000) - 0x8000);
4741 else if (code
== 'i')
4742 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
4743 s390_extract_part (x
, HImode
, 0));
4744 else if (code
== 'j')
4745 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
4746 s390_extract_part (x
, HImode
, -1));
4747 else if (code
== 'k')
4748 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
4749 s390_extract_part (x
, SImode
, 0));
4750 else if (code
== 'm')
4751 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
4752 s390_extract_part (x
, SImode
, -1));
4753 else if (code
== 'o')
4754 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
) & 0xffffffff);
4756 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
));
4760 gcc_assert (GET_MODE (x
) == VOIDmode
);
4762 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, CONST_DOUBLE_LOW (x
) & 0xff);
4763 else if (code
== 'x')
4764 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, CONST_DOUBLE_LOW (x
) & 0xffff);
4765 else if (code
== 'h')
4766 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, ((CONST_DOUBLE_LOW (x
) & 0xffff) ^ 0x8000) - 0x8000);
4772 fatal_insn ("UNKNOWN in print_operand !?", x
);
4777 /* Target hook for assembling integer objects. We need to define it
4778 here to work a round a bug in some versions of GAS, which couldn't
4779 handle values smaller than INT_MIN when printed in decimal. */
4782 s390_assemble_integer (rtx x
, unsigned int size
, int aligned_p
)
4784 if (size
== 8 && aligned_p
4785 && GET_CODE (x
) == CONST_INT
&& INTVAL (x
) < INT_MIN
)
4787 fprintf (asm_out_file
, "\t.quad\t" HOST_WIDE_INT_PRINT_HEX
"\n",
4791 return default_assemble_integer (x
, size
, aligned_p
);
4794 /* Returns true if register REGNO is used for forming
4795 a memory address in expression X. */
4798 reg_used_in_mem_p (int regno
, rtx x
)
4800 enum rtx_code code
= GET_CODE (x
);
4806 if (refers_to_regno_p (regno
, regno
+1,
4810 else if (code
== SET
4811 && GET_CODE (SET_DEST (x
)) == PC
)
4813 if (refers_to_regno_p (regno
, regno
+1,
4818 fmt
= GET_RTX_FORMAT (code
);
4819 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4822 && reg_used_in_mem_p (regno
, XEXP (x
, i
)))
4825 else if (fmt
[i
] == 'E')
4826 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
4827 if (reg_used_in_mem_p (regno
, XVECEXP (x
, i
, j
)))
4833 /* Returns true if expression DEP_RTX sets an address register
4834 used by instruction INSN to address memory. */
4837 addr_generation_dependency_p (rtx dep_rtx
, rtx insn
)
4841 if (GET_CODE (dep_rtx
) == INSN
)
4842 dep_rtx
= PATTERN (dep_rtx
);
4844 if (GET_CODE (dep_rtx
) == SET
)
4846 target
= SET_DEST (dep_rtx
);
4847 if (GET_CODE (target
) == STRICT_LOW_PART
)
4848 target
= XEXP (target
, 0);
4849 while (GET_CODE (target
) == SUBREG
)
4850 target
= SUBREG_REG (target
);
4852 if (GET_CODE (target
) == REG
)
4854 int regno
= REGNO (target
);
4856 if (s390_safe_attr_type (insn
) == TYPE_LA
)
4858 pat
= PATTERN (insn
);
4859 if (GET_CODE (pat
) == PARALLEL
)
4861 gcc_assert (XVECLEN (pat
, 0) == 2);
4862 pat
= XVECEXP (pat
, 0, 0);
4864 gcc_assert (GET_CODE (pat
) == SET
);
4865 return refers_to_regno_p (regno
, regno
+1, SET_SRC (pat
), 0);
4867 else if (get_attr_atype (insn
) == ATYPE_AGEN
)
4868 return reg_used_in_mem_p (regno
, PATTERN (insn
));
4874 /* Return 1, if dep_insn sets register used in insn in the agen unit. */
4877 s390_agen_dep_p (rtx dep_insn
, rtx insn
)
4879 rtx dep_rtx
= PATTERN (dep_insn
);
4882 if (GET_CODE (dep_rtx
) == SET
4883 && addr_generation_dependency_p (dep_rtx
, insn
))
4885 else if (GET_CODE (dep_rtx
) == PARALLEL
)
4887 for (i
= 0; i
< XVECLEN (dep_rtx
, 0); i
++)
4889 if (addr_generation_dependency_p (XVECEXP (dep_rtx
, 0, i
), insn
))
4896 /* A C statement (sans semicolon) to update the integer scheduling priority
4897 INSN_PRIORITY (INSN). Increase the priority to execute the INSN earlier,
4898 reduce the priority to execute INSN later. Do not define this macro if
4899 you do not need to adjust the scheduling priorities of insns.
4901 A STD instruction should be scheduled earlier,
4902 in order to use the bypass. */
4905 s390_adjust_priority (rtx insn ATTRIBUTE_UNUSED
, int priority
)
4907 if (! INSN_P (insn
))
4910 if (s390_tune
!= PROCESSOR_2084_Z990
4911 && s390_tune
!= PROCESSOR_2094_Z9_109
)
4914 switch (s390_safe_attr_type (insn
))
4918 priority
= priority
<< 3;
4922 priority
= priority
<< 1;
4930 /* The number of instructions that can be issued per cycle. */
4933 s390_issue_rate (void)
4935 if (s390_tune
== PROCESSOR_2084_Z990
4936 || s390_tune
== PROCESSOR_2094_Z9_109
)
4942 s390_first_cycle_multipass_dfa_lookahead (void)
4948 /* Annotate every literal pool reference in X by an UNSPEC_LTREF expression.
4949 Fix up MEMs as required. */
4952 annotate_constant_pool_refs (rtx
*x
)
4957 gcc_assert (GET_CODE (*x
) != SYMBOL_REF
4958 || !CONSTANT_POOL_ADDRESS_P (*x
));
4960 /* Literal pool references can only occur inside a MEM ... */
4961 if (GET_CODE (*x
) == MEM
)
4963 rtx memref
= XEXP (*x
, 0);
4965 if (GET_CODE (memref
) == SYMBOL_REF
4966 && CONSTANT_POOL_ADDRESS_P (memref
))
4968 rtx base
= cfun
->machine
->base_reg
;
4969 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, memref
, base
),
4972 *x
= replace_equiv_address (*x
, addr
);
4976 if (GET_CODE (memref
) == CONST
4977 && GET_CODE (XEXP (memref
, 0)) == PLUS
4978 && GET_CODE (XEXP (XEXP (memref
, 0), 1)) == CONST_INT
4979 && GET_CODE (XEXP (XEXP (memref
, 0), 0)) == SYMBOL_REF
4980 && CONSTANT_POOL_ADDRESS_P (XEXP (XEXP (memref
, 0), 0)))
4982 HOST_WIDE_INT off
= INTVAL (XEXP (XEXP (memref
, 0), 1));
4983 rtx sym
= XEXP (XEXP (memref
, 0), 0);
4984 rtx base
= cfun
->machine
->base_reg
;
4985 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, sym
, base
),
4988 *x
= replace_equiv_address (*x
, plus_constant (addr
, off
));
4993 /* ... or a load-address type pattern. */
4994 if (GET_CODE (*x
) == SET
)
4996 rtx addrref
= SET_SRC (*x
);
4998 if (GET_CODE (addrref
) == SYMBOL_REF
4999 && CONSTANT_POOL_ADDRESS_P (addrref
))
5001 rtx base
= cfun
->machine
->base_reg
;
5002 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, addrref
, base
),
5005 SET_SRC (*x
) = addr
;
5009 if (GET_CODE (addrref
) == CONST
5010 && GET_CODE (XEXP (addrref
, 0)) == PLUS
5011 && GET_CODE (XEXP (XEXP (addrref
, 0), 1)) == CONST_INT
5012 && GET_CODE (XEXP (XEXP (addrref
, 0), 0)) == SYMBOL_REF
5013 && CONSTANT_POOL_ADDRESS_P (XEXP (XEXP (addrref
, 0), 0)))
5015 HOST_WIDE_INT off
= INTVAL (XEXP (XEXP (addrref
, 0), 1));
5016 rtx sym
= XEXP (XEXP (addrref
, 0), 0);
5017 rtx base
= cfun
->machine
->base_reg
;
5018 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, sym
, base
),
5021 SET_SRC (*x
) = plus_constant (addr
, off
);
5026 /* Annotate LTREL_BASE as well. */
5027 if (GET_CODE (*x
) == UNSPEC
5028 && XINT (*x
, 1) == UNSPEC_LTREL_BASE
)
5030 rtx base
= cfun
->machine
->base_reg
;
5031 *x
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, XVECEXP (*x
, 0, 0), base
),
5036 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
5037 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
5041 annotate_constant_pool_refs (&XEXP (*x
, i
));
5043 else if (fmt
[i
] == 'E')
5045 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
5046 annotate_constant_pool_refs (&XVECEXP (*x
, i
, j
));
5051 /* Split all branches that exceed the maximum distance.
5052 Returns true if this created a new literal pool entry. */
5055 s390_split_branches (void)
5057 rtx temp_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
5058 int new_literal
= 0, ret
;
5059 rtx insn
, pat
, tmp
, target
;
5062 /* We need correct insn addresses. */
5064 shorten_branches (get_insns ());
5066 /* Find all branches that exceed 64KB, and split them. */
5068 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5070 if (GET_CODE (insn
) != JUMP_INSN
)
5073 pat
= PATTERN (insn
);
5074 if (GET_CODE (pat
) == PARALLEL
&& XVECLEN (pat
, 0) > 2)
5075 pat
= XVECEXP (pat
, 0, 0);
5076 if (GET_CODE (pat
) != SET
|| SET_DEST (pat
) != pc_rtx
)
5079 if (GET_CODE (SET_SRC (pat
)) == LABEL_REF
)
5081 label
= &SET_SRC (pat
);
5083 else if (GET_CODE (SET_SRC (pat
)) == IF_THEN_ELSE
)
5085 if (GET_CODE (XEXP (SET_SRC (pat
), 1)) == LABEL_REF
)
5086 label
= &XEXP (SET_SRC (pat
), 1);
5087 else if (GET_CODE (XEXP (SET_SRC (pat
), 2)) == LABEL_REF
)
5088 label
= &XEXP (SET_SRC (pat
), 2);
5095 if (get_attr_length (insn
) <= 4)
5098 /* We are going to use the return register as scratch register,
5099 make sure it will be saved/restored by the prologue/epilogue. */
5100 cfun_frame_layout
.save_return_addr_p
= 1;
5105 tmp
= force_const_mem (Pmode
, *label
);
5106 tmp
= emit_insn_before (gen_rtx_SET (Pmode
, temp_reg
, tmp
), insn
);
5107 INSN_ADDRESSES_NEW (tmp
, -1);
5108 annotate_constant_pool_refs (&PATTERN (tmp
));
5115 target
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, *label
),
5116 UNSPEC_LTREL_OFFSET
);
5117 target
= gen_rtx_CONST (Pmode
, target
);
5118 target
= force_const_mem (Pmode
, target
);
5119 tmp
= emit_insn_before (gen_rtx_SET (Pmode
, temp_reg
, target
), insn
);
5120 INSN_ADDRESSES_NEW (tmp
, -1);
5121 annotate_constant_pool_refs (&PATTERN (tmp
));
5123 target
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, XEXP (target
, 0),
5124 cfun
->machine
->base_reg
),
5126 target
= gen_rtx_PLUS (Pmode
, temp_reg
, target
);
5129 ret
= validate_change (insn
, label
, target
, 0);
5137 /* Find an annotated literal pool symbol referenced in RTX X,
5138 and store it at REF. Will abort if X contains references to
5139 more than one such pool symbol; multiple references to the same
5140 symbol are allowed, however.
5142 The rtx pointed to by REF must be initialized to NULL_RTX
5143 by the caller before calling this routine. */
5146 find_constant_pool_ref (rtx x
, rtx
*ref
)
5151 /* Ignore LTREL_BASE references. */
5152 if (GET_CODE (x
) == UNSPEC
5153 && XINT (x
, 1) == UNSPEC_LTREL_BASE
)
5155 /* Likewise POOL_ENTRY insns. */
5156 if (GET_CODE (x
) == UNSPEC_VOLATILE
5157 && XINT (x
, 1) == UNSPECV_POOL_ENTRY
)
5160 gcc_assert (GET_CODE (x
) != SYMBOL_REF
5161 || !CONSTANT_POOL_ADDRESS_P (x
));
5163 if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_LTREF
)
5165 rtx sym
= XVECEXP (x
, 0, 0);
5166 gcc_assert (GET_CODE (sym
) == SYMBOL_REF
5167 && CONSTANT_POOL_ADDRESS_P (sym
));
5169 if (*ref
== NULL_RTX
)
5172 gcc_assert (*ref
== sym
);
5177 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
5178 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
5182 find_constant_pool_ref (XEXP (x
, i
), ref
);
5184 else if (fmt
[i
] == 'E')
5186 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
5187 find_constant_pool_ref (XVECEXP (x
, i
, j
), ref
);
5192 /* Replace every reference to the annotated literal pool
5193 symbol REF in X by its base plus OFFSET. */
5196 replace_constant_pool_ref (rtx
*x
, rtx ref
, rtx offset
)
5201 gcc_assert (*x
!= ref
);
5203 if (GET_CODE (*x
) == UNSPEC
5204 && XINT (*x
, 1) == UNSPEC_LTREF
5205 && XVECEXP (*x
, 0, 0) == ref
)
5207 *x
= gen_rtx_PLUS (Pmode
, XVECEXP (*x
, 0, 1), offset
);
5211 if (GET_CODE (*x
) == PLUS
5212 && GET_CODE (XEXP (*x
, 1)) == CONST_INT
5213 && GET_CODE (XEXP (*x
, 0)) == UNSPEC
5214 && XINT (XEXP (*x
, 0), 1) == UNSPEC_LTREF
5215 && XVECEXP (XEXP (*x
, 0), 0, 0) == ref
)
5217 rtx addr
= gen_rtx_PLUS (Pmode
, XVECEXP (XEXP (*x
, 0), 0, 1), offset
);
5218 *x
= plus_constant (addr
, INTVAL (XEXP (*x
, 1)));
5222 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
5223 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
5227 replace_constant_pool_ref (&XEXP (*x
, i
), ref
, offset
);
5229 else if (fmt
[i
] == 'E')
5231 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
5232 replace_constant_pool_ref (&XVECEXP (*x
, i
, j
), ref
, offset
);
5237 /* Check whether X contains an UNSPEC_LTREL_BASE.
5238 Return its constant pool symbol if found, NULL_RTX otherwise. */
5241 find_ltrel_base (rtx x
)
5246 if (GET_CODE (x
) == UNSPEC
5247 && XINT (x
, 1) == UNSPEC_LTREL_BASE
)
5248 return XVECEXP (x
, 0, 0);
5250 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
5251 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
5255 rtx fnd
= find_ltrel_base (XEXP (x
, i
));
5259 else if (fmt
[i
] == 'E')
5261 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
5263 rtx fnd
= find_ltrel_base (XVECEXP (x
, i
, j
));
5273 /* Replace any occurrence of UNSPEC_LTREL_BASE in X with its base. */
5276 replace_ltrel_base (rtx
*x
)
5281 if (GET_CODE (*x
) == UNSPEC
5282 && XINT (*x
, 1) == UNSPEC_LTREL_BASE
)
5284 *x
= XVECEXP (*x
, 0, 1);
5288 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
5289 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
5293 replace_ltrel_base (&XEXP (*x
, i
));
5295 else if (fmt
[i
] == 'E')
5297 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
5298 replace_ltrel_base (&XVECEXP (*x
, i
, j
));
5304 /* We keep a list of constants which we have to add to internal
5305 constant tables in the middle of large functions. */
5307 #define NR_C_MODES 11
5308 enum machine_mode constant_modes
[NR_C_MODES
] =
5310 TFmode
, TImode
, TDmode
,
5311 DFmode
, DImode
, DDmode
,
5312 SFmode
, SImode
, SDmode
,
5319 struct constant
*next
;
5324 struct constant_pool
5326 struct constant_pool
*next
;
5331 struct constant
*constants
[NR_C_MODES
];
5332 struct constant
*execute
;
5337 /* Allocate new constant_pool structure. */
5339 static struct constant_pool
*
5340 s390_alloc_pool (void)
5342 struct constant_pool
*pool
;
5345 pool
= (struct constant_pool
*) xmalloc (sizeof *pool
);
5347 for (i
= 0; i
< NR_C_MODES
; i
++)
5348 pool
->constants
[i
] = NULL
;
5350 pool
->execute
= NULL
;
5351 pool
->label
= gen_label_rtx ();
5352 pool
->first_insn
= NULL_RTX
;
5353 pool
->pool_insn
= NULL_RTX
;
5354 pool
->insns
= BITMAP_ALLOC (NULL
);
5360 /* Create new constant pool covering instructions starting at INSN
5361 and chain it to the end of POOL_LIST. */
5363 static struct constant_pool
*
5364 s390_start_pool (struct constant_pool
**pool_list
, rtx insn
)
5366 struct constant_pool
*pool
, **prev
;
5368 pool
= s390_alloc_pool ();
5369 pool
->first_insn
= insn
;
5371 for (prev
= pool_list
; *prev
; prev
= &(*prev
)->next
)
5378 /* End range of instructions covered by POOL at INSN and emit
5379 placeholder insn representing the pool. */
5382 s390_end_pool (struct constant_pool
*pool
, rtx insn
)
5384 rtx pool_size
= GEN_INT (pool
->size
+ 8 /* alignment slop */);
5387 insn
= get_last_insn ();
5389 pool
->pool_insn
= emit_insn_after (gen_pool (pool_size
), insn
);
5390 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
5393 /* Add INSN to the list of insns covered by POOL. */
5396 s390_add_pool_insn (struct constant_pool
*pool
, rtx insn
)
5398 bitmap_set_bit (pool
->insns
, INSN_UID (insn
));
5401 /* Return pool out of POOL_LIST that covers INSN. */
5403 static struct constant_pool
*
5404 s390_find_pool (struct constant_pool
*pool_list
, rtx insn
)
5406 struct constant_pool
*pool
;
5408 for (pool
= pool_list
; pool
; pool
= pool
->next
)
5409 if (bitmap_bit_p (pool
->insns
, INSN_UID (insn
)))
5415 /* Add constant VAL of mode MODE to the constant pool POOL. */
5418 s390_add_constant (struct constant_pool
*pool
, rtx val
, enum machine_mode mode
)
5423 for (i
= 0; i
< NR_C_MODES
; i
++)
5424 if (constant_modes
[i
] == mode
)
5426 gcc_assert (i
!= NR_C_MODES
);
5428 for (c
= pool
->constants
[i
]; c
!= NULL
; c
= c
->next
)
5429 if (rtx_equal_p (val
, c
->value
))
5434 c
= (struct constant
*) xmalloc (sizeof *c
);
5436 c
->label
= gen_label_rtx ();
5437 c
->next
= pool
->constants
[i
];
5438 pool
->constants
[i
] = c
;
5439 pool
->size
+= GET_MODE_SIZE (mode
);
5443 /* Find constant VAL of mode MODE in the constant pool POOL.
5444 Return an RTX describing the distance from the start of
5445 the pool to the location of the new constant. */
5448 s390_find_constant (struct constant_pool
*pool
, rtx val
,
5449 enum machine_mode mode
)
5455 for (i
= 0; i
< NR_C_MODES
; i
++)
5456 if (constant_modes
[i
] == mode
)
5458 gcc_assert (i
!= NR_C_MODES
);
5460 for (c
= pool
->constants
[i
]; c
!= NULL
; c
= c
->next
)
5461 if (rtx_equal_p (val
, c
->value
))
5466 offset
= gen_rtx_MINUS (Pmode
, gen_rtx_LABEL_REF (Pmode
, c
->label
),
5467 gen_rtx_LABEL_REF (Pmode
, pool
->label
));
5468 offset
= gen_rtx_CONST (Pmode
, offset
);
5472 /* Check whether INSN is an execute. Return the label_ref to its
5473 execute target template if so, NULL_RTX otherwise. */
5476 s390_execute_label (rtx insn
)
5478 if (GET_CODE (insn
) == INSN
5479 && GET_CODE (PATTERN (insn
)) == PARALLEL
5480 && GET_CODE (XVECEXP (PATTERN (insn
), 0, 0)) == UNSPEC
5481 && XINT (XVECEXP (PATTERN (insn
), 0, 0), 1) == UNSPEC_EXECUTE
)
5482 return XVECEXP (XVECEXP (PATTERN (insn
), 0, 0), 0, 2);
5487 /* Add execute target for INSN to the constant pool POOL. */
5490 s390_add_execute (struct constant_pool
*pool
, rtx insn
)
5494 for (c
= pool
->execute
; c
!= NULL
; c
= c
->next
)
5495 if (INSN_UID (insn
) == INSN_UID (c
->value
))
5500 c
= (struct constant
*) xmalloc (sizeof *c
);
5502 c
->label
= gen_label_rtx ();
5503 c
->next
= pool
->execute
;
5509 /* Find execute target for INSN in the constant pool POOL.
5510 Return an RTX describing the distance from the start of
5511 the pool to the location of the execute target. */
5514 s390_find_execute (struct constant_pool
*pool
, rtx insn
)
5519 for (c
= pool
->execute
; c
!= NULL
; c
= c
->next
)
5520 if (INSN_UID (insn
) == INSN_UID (c
->value
))
5525 offset
= gen_rtx_MINUS (Pmode
, gen_rtx_LABEL_REF (Pmode
, c
->label
),
5526 gen_rtx_LABEL_REF (Pmode
, pool
->label
));
5527 offset
= gen_rtx_CONST (Pmode
, offset
);
5531 /* For an execute INSN, extract the execute target template. */
5534 s390_execute_target (rtx insn
)
5536 rtx pattern
= PATTERN (insn
);
5537 gcc_assert (s390_execute_label (insn
));
5539 if (XVECLEN (pattern
, 0) == 2)
5541 pattern
= copy_rtx (XVECEXP (pattern
, 0, 1));
5545 rtvec vec
= rtvec_alloc (XVECLEN (pattern
, 0) - 1);
5548 for (i
= 0; i
< XVECLEN (pattern
, 0) - 1; i
++)
5549 RTVEC_ELT (vec
, i
) = copy_rtx (XVECEXP (pattern
, 0, i
+ 1));
5551 pattern
= gen_rtx_PARALLEL (VOIDmode
, vec
);
5557 /* Indicate that INSN cannot be duplicated. This is the case for
5558 execute insns that carry a unique label. */
5561 s390_cannot_copy_insn_p (rtx insn
)
5563 rtx label
= s390_execute_label (insn
);
5564 return label
&& label
!= const0_rtx
;
5567 /* Dump out the constants in POOL. If REMOTE_LABEL is true,
5568 do not emit the pool base label. */
5571 s390_dump_pool (struct constant_pool
*pool
, bool remote_label
)
5574 rtx insn
= pool
->pool_insn
;
5577 /* Switch to rodata section. */
5578 if (TARGET_CPU_ZARCH
)
5580 insn
= emit_insn_after (gen_pool_section_start (), insn
);
5581 INSN_ADDRESSES_NEW (insn
, -1);
5584 /* Ensure minimum pool alignment. */
5585 if (TARGET_CPU_ZARCH
)
5586 insn
= emit_insn_after (gen_pool_align (GEN_INT (8)), insn
);
5588 insn
= emit_insn_after (gen_pool_align (GEN_INT (4)), insn
);
5589 INSN_ADDRESSES_NEW (insn
, -1);
5591 /* Emit pool base label. */
5594 insn
= emit_label_after (pool
->label
, insn
);
5595 INSN_ADDRESSES_NEW (insn
, -1);
5598 /* Dump constants in descending alignment requirement order,
5599 ensuring proper alignment for every constant. */
5600 for (i
= 0; i
< NR_C_MODES
; i
++)
5601 for (c
= pool
->constants
[i
]; c
; c
= c
->next
)
5603 /* Convert UNSPEC_LTREL_OFFSET unspecs to pool-relative references. */
5604 rtx value
= c
->value
;
5605 if (GET_CODE (value
) == CONST
5606 && GET_CODE (XEXP (value
, 0)) == UNSPEC
5607 && XINT (XEXP (value
, 0), 1) == UNSPEC_LTREL_OFFSET
5608 && XVECLEN (XEXP (value
, 0), 0) == 1)
5610 value
= gen_rtx_MINUS (Pmode
, XVECEXP (XEXP (value
, 0), 0, 0),
5611 gen_rtx_LABEL_REF (VOIDmode
, pool
->label
));
5612 value
= gen_rtx_CONST (VOIDmode
, value
);
5615 insn
= emit_label_after (c
->label
, insn
);
5616 INSN_ADDRESSES_NEW (insn
, -1);
5618 value
= gen_rtx_UNSPEC_VOLATILE (constant_modes
[i
],
5619 gen_rtvec (1, value
),
5620 UNSPECV_POOL_ENTRY
);
5621 insn
= emit_insn_after (value
, insn
);
5622 INSN_ADDRESSES_NEW (insn
, -1);
5625 /* Ensure minimum alignment for instructions. */
5626 insn
= emit_insn_after (gen_pool_align (GEN_INT (2)), insn
);
5627 INSN_ADDRESSES_NEW (insn
, -1);
5629 /* Output in-pool execute template insns. */
5630 for (c
= pool
->execute
; c
; c
= c
->next
)
5632 insn
= emit_label_after (c
->label
, insn
);
5633 INSN_ADDRESSES_NEW (insn
, -1);
5635 insn
= emit_insn_after (s390_execute_target (c
->value
), insn
);
5636 INSN_ADDRESSES_NEW (insn
, -1);
5639 /* Switch back to previous section. */
5640 if (TARGET_CPU_ZARCH
)
5642 insn
= emit_insn_after (gen_pool_section_end (), insn
);
5643 INSN_ADDRESSES_NEW (insn
, -1);
5646 insn
= emit_barrier_after (insn
);
5647 INSN_ADDRESSES_NEW (insn
, -1);
5649 /* Remove placeholder insn. */
5650 remove_insn (pool
->pool_insn
);
5653 /* Free all memory used by POOL. */
5656 s390_free_pool (struct constant_pool
*pool
)
5658 struct constant
*c
, *next
;
5661 for (i
= 0; i
< NR_C_MODES
; i
++)
5662 for (c
= pool
->constants
[i
]; c
; c
= next
)
5668 for (c
= pool
->execute
; c
; c
= next
)
5674 BITMAP_FREE (pool
->insns
);
5679 /* Collect main literal pool. Return NULL on overflow. */
5681 static struct constant_pool
*
5682 s390_mainpool_start (void)
5684 struct constant_pool
*pool
;
5687 pool
= s390_alloc_pool ();
5689 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5691 if (GET_CODE (insn
) == INSN
5692 && GET_CODE (PATTERN (insn
)) == SET
5693 && GET_CODE (SET_SRC (PATTERN (insn
))) == UNSPEC_VOLATILE
5694 && XINT (SET_SRC (PATTERN (insn
)), 1) == UNSPECV_MAIN_POOL
)
5696 gcc_assert (!pool
->pool_insn
);
5697 pool
->pool_insn
= insn
;
5700 if (!TARGET_CPU_ZARCH
&& s390_execute_label (insn
))
5702 s390_add_execute (pool
, insn
);
5704 else if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
5706 rtx pool_ref
= NULL_RTX
;
5707 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
5710 rtx constant
= get_pool_constant (pool_ref
);
5711 enum machine_mode mode
= get_pool_mode (pool_ref
);
5712 s390_add_constant (pool
, constant
, mode
);
5717 gcc_assert (pool
->pool_insn
|| pool
->size
== 0);
5719 if (pool
->size
>= 4096)
5721 /* We're going to chunkify the pool, so remove the main
5722 pool placeholder insn. */
5723 remove_insn (pool
->pool_insn
);
5725 s390_free_pool (pool
);
5732 /* POOL holds the main literal pool as collected by s390_mainpool_start.
5733 Modify the current function to output the pool constants as well as
5734 the pool register setup instruction. */
5737 s390_mainpool_finish (struct constant_pool
*pool
)
5739 rtx base_reg
= cfun
->machine
->base_reg
;
5742 /* If the pool is empty, we're done. */
5743 if (pool
->size
== 0)
5745 /* We don't actually need a base register after all. */
5746 cfun
->machine
->base_reg
= NULL_RTX
;
5748 if (pool
->pool_insn
)
5749 remove_insn (pool
->pool_insn
);
5750 s390_free_pool (pool
);
5754 /* We need correct insn addresses. */
5755 shorten_branches (get_insns ());
5757 /* On zSeries, we use a LARL to load the pool register. The pool is
5758 located in the .rodata section, so we emit it after the function. */
5759 if (TARGET_CPU_ZARCH
)
5761 insn
= gen_main_base_64 (base_reg
, pool
->label
);
5762 insn
= emit_insn_after (insn
, pool
->pool_insn
);
5763 INSN_ADDRESSES_NEW (insn
, -1);
5764 remove_insn (pool
->pool_insn
);
5766 insn
= get_last_insn ();
5767 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
5768 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
5770 s390_dump_pool (pool
, 0);
5773 /* On S/390, if the total size of the function's code plus literal pool
5774 does not exceed 4096 bytes, we use BASR to set up a function base
5775 pointer, and emit the literal pool at the end of the function. */
5776 else if (INSN_ADDRESSES (INSN_UID (get_last_insn ()))
5777 + pool
->size
+ 8 /* alignment slop */ < 4096)
5779 insn
= gen_main_base_31_small (base_reg
, pool
->label
);
5780 insn
= emit_insn_after (insn
, pool
->pool_insn
);
5781 INSN_ADDRESSES_NEW (insn
, -1);
5782 remove_insn (pool
->pool_insn
);
5784 insn
= emit_label_after (pool
->label
, insn
);
5785 INSN_ADDRESSES_NEW (insn
, -1);
5787 insn
= get_last_insn ();
5788 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
5789 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
5791 s390_dump_pool (pool
, 1);
5794 /* Otherwise, we emit an inline literal pool and use BASR to branch
5795 over it, setting up the pool register at the same time. */
5798 rtx pool_end
= gen_label_rtx ();
5800 insn
= gen_main_base_31_large (base_reg
, pool
->label
, pool_end
);
5801 insn
= emit_insn_after (insn
, pool
->pool_insn
);
5802 INSN_ADDRESSES_NEW (insn
, -1);
5803 remove_insn (pool
->pool_insn
);
5805 insn
= emit_label_after (pool
->label
, insn
);
5806 INSN_ADDRESSES_NEW (insn
, -1);
5808 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
5809 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
5811 insn
= emit_label_after (pool_end
, pool
->pool_insn
);
5812 INSN_ADDRESSES_NEW (insn
, -1);
5814 s390_dump_pool (pool
, 1);
5818 /* Replace all literal pool references. */
5820 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5823 replace_ltrel_base (&PATTERN (insn
));
5825 if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
5827 rtx addr
, pool_ref
= NULL_RTX
;
5828 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
5831 if (s390_execute_label (insn
))
5832 addr
= s390_find_execute (pool
, insn
);
5834 addr
= s390_find_constant (pool
, get_pool_constant (pool_ref
),
5835 get_pool_mode (pool_ref
));
5837 replace_constant_pool_ref (&PATTERN (insn
), pool_ref
, addr
);
5838 INSN_CODE (insn
) = -1;
5844 /* Free the pool. */
5845 s390_free_pool (pool
);
5848 /* POOL holds the main literal pool as collected by s390_mainpool_start.
5849 We have decided we cannot use this pool, so revert all changes
5850 to the current function that were done by s390_mainpool_start. */
5852 s390_mainpool_cancel (struct constant_pool
*pool
)
5854 /* We didn't actually change the instruction stream, so simply
5855 free the pool memory. */
5856 s390_free_pool (pool
);
5860 /* Chunkify the literal pool. */
5862 #define S390_POOL_CHUNK_MIN 0xc00
5863 #define S390_POOL_CHUNK_MAX 0xe00
5865 static struct constant_pool
*
5866 s390_chunkify_start (void)
5868 struct constant_pool
*curr_pool
= NULL
, *pool_list
= NULL
;
5871 rtx pending_ltrel
= NULL_RTX
;
5874 rtx (*gen_reload_base
) (rtx
, rtx
) =
5875 TARGET_CPU_ZARCH
? gen_reload_base_64
: gen_reload_base_31
;
5878 /* We need correct insn addresses. */
5880 shorten_branches (get_insns ());
5882 /* Scan all insns and move literals to pool chunks. */
5884 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5886 /* Check for pending LTREL_BASE. */
5889 rtx ltrel_base
= find_ltrel_base (PATTERN (insn
));
5892 gcc_assert (ltrel_base
== pending_ltrel
);
5893 pending_ltrel
= NULL_RTX
;
5897 if (!TARGET_CPU_ZARCH
&& s390_execute_label (insn
))
5900 curr_pool
= s390_start_pool (&pool_list
, insn
);
5902 s390_add_execute (curr_pool
, insn
);
5903 s390_add_pool_insn (curr_pool
, insn
);
5905 else if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
5907 rtx pool_ref
= NULL_RTX
;
5908 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
5911 rtx constant
= get_pool_constant (pool_ref
);
5912 enum machine_mode mode
= get_pool_mode (pool_ref
);
5915 curr_pool
= s390_start_pool (&pool_list
, insn
);
5917 s390_add_constant (curr_pool
, constant
, mode
);
5918 s390_add_pool_insn (curr_pool
, insn
);
5920 /* Don't split the pool chunk between a LTREL_OFFSET load
5921 and the corresponding LTREL_BASE. */
5922 if (GET_CODE (constant
) == CONST
5923 && GET_CODE (XEXP (constant
, 0)) == UNSPEC
5924 && XINT (XEXP (constant
, 0), 1) == UNSPEC_LTREL_OFFSET
)
5926 gcc_assert (!pending_ltrel
);
5927 pending_ltrel
= pool_ref
;
5932 if (GET_CODE (insn
) == JUMP_INSN
|| GET_CODE (insn
) == CODE_LABEL
)
5935 s390_add_pool_insn (curr_pool
, insn
);
5936 /* An LTREL_BASE must follow within the same basic block. */
5937 gcc_assert (!pending_ltrel
);
5941 || INSN_ADDRESSES_SIZE () <= (size_t) INSN_UID (insn
)
5942 || INSN_ADDRESSES (INSN_UID (insn
)) == -1)
5945 if (TARGET_CPU_ZARCH
)
5947 if (curr_pool
->size
< S390_POOL_CHUNK_MAX
)
5950 s390_end_pool (curr_pool
, NULL_RTX
);
5955 int chunk_size
= INSN_ADDRESSES (INSN_UID (insn
))
5956 - INSN_ADDRESSES (INSN_UID (curr_pool
->first_insn
))
5959 /* We will later have to insert base register reload insns.
5960 Those will have an effect on code size, which we need to
5961 consider here. This calculation makes rather pessimistic
5962 worst-case assumptions. */
5963 if (GET_CODE (insn
) == CODE_LABEL
)
5966 if (chunk_size
< S390_POOL_CHUNK_MIN
5967 && curr_pool
->size
< S390_POOL_CHUNK_MIN
)
5970 /* Pool chunks can only be inserted after BARRIERs ... */
5971 if (GET_CODE (insn
) == BARRIER
)
5973 s390_end_pool (curr_pool
, insn
);
5978 /* ... so if we don't find one in time, create one. */
5979 else if ((chunk_size
> S390_POOL_CHUNK_MAX
5980 || curr_pool
->size
> S390_POOL_CHUNK_MAX
))
5982 rtx label
, jump
, barrier
;
5984 /* We can insert the barrier only after a 'real' insn. */
5985 if (GET_CODE (insn
) != INSN
&& GET_CODE (insn
) != CALL_INSN
)
5987 if (get_attr_length (insn
) == 0)
5990 /* Don't separate LTREL_BASE from the corresponding
5991 LTREL_OFFSET load. */
5995 label
= gen_label_rtx ();
5996 jump
= emit_jump_insn_after (gen_jump (label
), insn
);
5997 barrier
= emit_barrier_after (jump
);
5998 insn
= emit_label_after (label
, barrier
);
5999 JUMP_LABEL (jump
) = label
;
6000 LABEL_NUSES (label
) = 1;
6002 INSN_ADDRESSES_NEW (jump
, -1);
6003 INSN_ADDRESSES_NEW (barrier
, -1);
6004 INSN_ADDRESSES_NEW (insn
, -1);
6006 s390_end_pool (curr_pool
, barrier
);
6014 s390_end_pool (curr_pool
, NULL_RTX
);
6015 gcc_assert (!pending_ltrel
);
6017 /* Find all labels that are branched into
6018 from an insn belonging to a different chunk. */
6020 far_labels
= BITMAP_ALLOC (NULL
);
6022 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6024 /* Labels marked with LABEL_PRESERVE_P can be target
6025 of non-local jumps, so we have to mark them.
6026 The same holds for named labels.
6028 Don't do that, however, if it is the label before
6031 if (GET_CODE (insn
) == CODE_LABEL
6032 && (LABEL_PRESERVE_P (insn
) || LABEL_NAME (insn
)))
6034 rtx vec_insn
= next_real_insn (insn
);
6035 rtx vec_pat
= vec_insn
&& GET_CODE (vec_insn
) == JUMP_INSN
?
6036 PATTERN (vec_insn
) : NULL_RTX
;
6038 || !(GET_CODE (vec_pat
) == ADDR_VEC
6039 || GET_CODE (vec_pat
) == ADDR_DIFF_VEC
))
6040 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (insn
));
6043 /* If we have a direct jump (conditional or unconditional)
6044 or a casesi jump, check all potential targets. */
6045 else if (GET_CODE (insn
) == JUMP_INSN
)
6047 rtx pat
= PATTERN (insn
);
6048 if (GET_CODE (pat
) == PARALLEL
&& XVECLEN (pat
, 0) > 2)
6049 pat
= XVECEXP (pat
, 0, 0);
6051 if (GET_CODE (pat
) == SET
)
6053 rtx label
= JUMP_LABEL (insn
);
6056 if (s390_find_pool (pool_list
, label
)
6057 != s390_find_pool (pool_list
, insn
))
6058 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (label
));
6061 else if (GET_CODE (pat
) == PARALLEL
6062 && XVECLEN (pat
, 0) == 2
6063 && GET_CODE (XVECEXP (pat
, 0, 0)) == SET
6064 && GET_CODE (XVECEXP (pat
, 0, 1)) == USE
6065 && GET_CODE (XEXP (XVECEXP (pat
, 0, 1), 0)) == LABEL_REF
)
6067 /* Find the jump table used by this casesi jump. */
6068 rtx vec_label
= XEXP (XEXP (XVECEXP (pat
, 0, 1), 0), 0);
6069 rtx vec_insn
= next_real_insn (vec_label
);
6070 rtx vec_pat
= vec_insn
&& GET_CODE (vec_insn
) == JUMP_INSN
?
6071 PATTERN (vec_insn
) : NULL_RTX
;
6073 && (GET_CODE (vec_pat
) == ADDR_VEC
6074 || GET_CODE (vec_pat
) == ADDR_DIFF_VEC
))
6076 int i
, diff_p
= GET_CODE (vec_pat
) == ADDR_DIFF_VEC
;
6078 for (i
= 0; i
< XVECLEN (vec_pat
, diff_p
); i
++)
6080 rtx label
= XEXP (XVECEXP (vec_pat
, diff_p
, i
), 0);
6082 if (s390_find_pool (pool_list
, label
)
6083 != s390_find_pool (pool_list
, insn
))
6084 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (label
));
6091 /* Insert base register reload insns before every pool. */
6093 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
6095 rtx new_insn
= gen_reload_base (cfun
->machine
->base_reg
,
6097 rtx insn
= curr_pool
->first_insn
;
6098 INSN_ADDRESSES_NEW (emit_insn_before (new_insn
, insn
), -1);
6101 /* Insert base register reload insns at every far label. */
6103 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6104 if (GET_CODE (insn
) == CODE_LABEL
6105 && bitmap_bit_p (far_labels
, CODE_LABEL_NUMBER (insn
)))
6107 struct constant_pool
*pool
= s390_find_pool (pool_list
, insn
);
6110 rtx new_insn
= gen_reload_base (cfun
->machine
->base_reg
,
6112 INSN_ADDRESSES_NEW (emit_insn_after (new_insn
, insn
), -1);
6117 BITMAP_FREE (far_labels
);
6120 /* Recompute insn addresses. */
6122 init_insn_lengths ();
6123 shorten_branches (get_insns ());
6128 /* POOL_LIST is a chunk list as prepared by s390_chunkify_start.
6129 After we have decided to use this list, finish implementing
6130 all changes to the current function as required. */
6133 s390_chunkify_finish (struct constant_pool
*pool_list
)
6135 struct constant_pool
*curr_pool
= NULL
;
6139 /* Replace all literal pool references. */
6141 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6144 replace_ltrel_base (&PATTERN (insn
));
6146 curr_pool
= s390_find_pool (pool_list
, insn
);
6150 if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
6152 rtx addr
, pool_ref
= NULL_RTX
;
6153 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
6156 if (s390_execute_label (insn
))
6157 addr
= s390_find_execute (curr_pool
, insn
);
6159 addr
= s390_find_constant (curr_pool
,
6160 get_pool_constant (pool_ref
),
6161 get_pool_mode (pool_ref
));
6163 replace_constant_pool_ref (&PATTERN (insn
), pool_ref
, addr
);
6164 INSN_CODE (insn
) = -1;
6169 /* Dump out all literal pools. */
6171 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
6172 s390_dump_pool (curr_pool
, 0);
6174 /* Free pool list. */
6178 struct constant_pool
*next
= pool_list
->next
;
6179 s390_free_pool (pool_list
);
6184 /* POOL_LIST is a chunk list as prepared by s390_chunkify_start.
6185 We have decided we cannot use this list, so revert all changes
6186 to the current function that were done by s390_chunkify_start. */
6189 s390_chunkify_cancel (struct constant_pool
*pool_list
)
6191 struct constant_pool
*curr_pool
= NULL
;
6194 /* Remove all pool placeholder insns. */
6196 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
6198 /* Did we insert an extra barrier? Remove it. */
6199 rtx barrier
= PREV_INSN (curr_pool
->pool_insn
);
6200 rtx jump
= barrier
? PREV_INSN (barrier
) : NULL_RTX
;
6201 rtx label
= NEXT_INSN (curr_pool
->pool_insn
);
6203 if (jump
&& GET_CODE (jump
) == JUMP_INSN
6204 && barrier
&& GET_CODE (barrier
) == BARRIER
6205 && label
&& GET_CODE (label
) == CODE_LABEL
6206 && GET_CODE (PATTERN (jump
)) == SET
6207 && SET_DEST (PATTERN (jump
)) == pc_rtx
6208 && GET_CODE (SET_SRC (PATTERN (jump
))) == LABEL_REF
6209 && XEXP (SET_SRC (PATTERN (jump
)), 0) == label
)
6212 remove_insn (barrier
);
6213 remove_insn (label
);
6216 remove_insn (curr_pool
->pool_insn
);
6219 /* Remove all base register reload insns. */
6221 for (insn
= get_insns (); insn
; )
6223 rtx next_insn
= NEXT_INSN (insn
);
6225 if (GET_CODE (insn
) == INSN
6226 && GET_CODE (PATTERN (insn
)) == SET
6227 && GET_CODE (SET_SRC (PATTERN (insn
))) == UNSPEC
6228 && XINT (SET_SRC (PATTERN (insn
)), 1) == UNSPEC_RELOAD_BASE
)
6234 /* Free pool list. */
6238 struct constant_pool
*next
= pool_list
->next
;
6239 s390_free_pool (pool_list
);
6245 /* Output the constant pool entry EXP in mode MODE with alignment ALIGN. */
6248 s390_output_pool_entry (rtx exp
, enum machine_mode mode
, unsigned int align
)
6252 switch (GET_MODE_CLASS (mode
))
6255 case MODE_DECIMAL_FLOAT
:
6256 gcc_assert (GET_CODE (exp
) == CONST_DOUBLE
);
6258 REAL_VALUE_FROM_CONST_DOUBLE (r
, exp
);
6259 assemble_real (r
, mode
, align
);
6263 assemble_integer (exp
, GET_MODE_SIZE (mode
), align
, 1);
6272 /* Return an RTL expression representing the value of the return address
6273 for the frame COUNT steps up from the current frame. FRAME is the
6274 frame pointer of that frame. */
6277 s390_return_addr_rtx (int count
, rtx frame ATTRIBUTE_UNUSED
)
6282 /* Without backchain, we fail for all but the current frame. */
6284 if (!TARGET_BACKCHAIN
&& count
> 0)
6287 /* For the current frame, we need to make sure the initial
6288 value of RETURN_REGNUM is actually saved. */
6292 /* On non-z architectures branch splitting could overwrite r14. */
6293 if (TARGET_CPU_ZARCH
)
6294 return get_hard_reg_initial_val (Pmode
, RETURN_REGNUM
);
6297 cfun_frame_layout
.save_return_addr_p
= true;
6298 return gen_rtx_MEM (Pmode
, return_address_pointer_rtx
);
6302 if (TARGET_PACKED_STACK
)
6303 offset
= -2 * UNITS_PER_WORD
;
6305 offset
= RETURN_REGNUM
* UNITS_PER_WORD
;
6307 addr
= plus_constant (frame
, offset
);
6308 addr
= memory_address (Pmode
, addr
);
6309 return gen_rtx_MEM (Pmode
, addr
);
6312 /* Return an RTL expression representing the back chain stored in
6313 the current stack frame. */
6316 s390_back_chain_rtx (void)
6320 gcc_assert (TARGET_BACKCHAIN
);
6322 if (TARGET_PACKED_STACK
)
6323 chain
= plus_constant (stack_pointer_rtx
,
6324 STACK_POINTER_OFFSET
- UNITS_PER_WORD
);
6326 chain
= stack_pointer_rtx
;
6328 chain
= gen_rtx_MEM (Pmode
, chain
);
6332 /* Find first call clobbered register unused in a function.
6333 This could be used as base register in a leaf function
6334 or for holding the return address before epilogue. */
6337 find_unused_clobbered_reg (void)
6340 for (i
= 0; i
< 6; i
++)
6341 if (!df_regs_ever_live_p (i
))
6347 /* Helper function for s390_regs_ever_clobbered. Sets the fields in DATA for all
6348 clobbered hard regs in SETREG. */
6351 s390_reg_clobbered_rtx (rtx setreg
, rtx set_insn ATTRIBUTE_UNUSED
, void *data
)
6353 int *regs_ever_clobbered
= (int *)data
;
6354 unsigned int i
, regno
;
6355 enum machine_mode mode
= GET_MODE (setreg
);
6357 if (GET_CODE (setreg
) == SUBREG
)
6359 rtx inner
= SUBREG_REG (setreg
);
6360 if (!GENERAL_REG_P (inner
))
6362 regno
= subreg_regno (setreg
);
6364 else if (GENERAL_REG_P (setreg
))
6365 regno
= REGNO (setreg
);
6370 i
< regno
+ HARD_REGNO_NREGS (regno
, mode
);
6372 regs_ever_clobbered
[i
] = 1;
6375 /* Walks through all basic blocks of the current function looking
6376 for clobbered hard regs using s390_reg_clobbered_rtx. The fields
6377 of the passed integer array REGS_EVER_CLOBBERED are set to one for
6378 each of those regs. */
6381 s390_regs_ever_clobbered (int *regs_ever_clobbered
)
6387 memset (regs_ever_clobbered
, 0, 16 * sizeof (int));
6389 /* For non-leaf functions we have to consider all call clobbered regs to be
6391 if (!current_function_is_leaf
)
6393 for (i
= 0; i
< 16; i
++)
6394 regs_ever_clobbered
[i
] = call_really_used_regs
[i
];
6397 /* Make the "magic" eh_return registers live if necessary. For regs_ever_live
6398 this work is done by liveness analysis (mark_regs_live_at_end).
6399 Special care is needed for functions containing landing pads. Landing pads
6400 may use the eh registers, but the code which sets these registers is not
6401 contained in that function. Hence s390_regs_ever_clobbered is not able to
6402 deal with this automatically. */
6403 if (current_function_calls_eh_return
|| cfun
->machine
->has_landing_pad_p
)
6404 for (i
= 0; EH_RETURN_DATA_REGNO (i
) != INVALID_REGNUM
; i
++)
6405 if (current_function_calls_eh_return
6406 || (cfun
->machine
->has_landing_pad_p
6407 && df_regs_ever_live_p (EH_RETURN_DATA_REGNO (i
))))
6408 regs_ever_clobbered
[EH_RETURN_DATA_REGNO (i
)] = 1;
6410 /* For nonlocal gotos all call-saved registers have to be saved.
6411 This flag is also set for the unwinding code in libgcc.
6412 See expand_builtin_unwind_init. For regs_ever_live this is done by
6414 if (current_function_has_nonlocal_label
)
6415 for (i
= 0; i
< 16; i
++)
6416 if (!call_really_used_regs
[i
])
6417 regs_ever_clobbered
[i
] = 1;
6419 FOR_EACH_BB (cur_bb
)
6421 FOR_BB_INSNS (cur_bb
, cur_insn
)
6423 if (INSN_P (cur_insn
))
6424 note_stores (PATTERN (cur_insn
),
6425 s390_reg_clobbered_rtx
,
6426 regs_ever_clobbered
);
6431 /* Determine the frame area which actually has to be accessed
6432 in the function epilogue. The values are stored at the
6433 given pointers AREA_BOTTOM (address of the lowest used stack
6434 address) and AREA_TOP (address of the first item which does
6435 not belong to the stack frame). */
6438 s390_frame_area (int *area_bottom
, int *area_top
)
6446 if (cfun_frame_layout
.first_restore_gpr
!= -1)
6448 b
= (cfun_frame_layout
.gprs_offset
6449 + cfun_frame_layout
.first_restore_gpr
* UNITS_PER_WORD
);
6450 t
= b
+ (cfun_frame_layout
.last_restore_gpr
6451 - cfun_frame_layout
.first_restore_gpr
+ 1) * UNITS_PER_WORD
;
6454 if (TARGET_64BIT
&& cfun_save_high_fprs_p
)
6456 b
= MIN (b
, cfun_frame_layout
.f8_offset
);
6457 t
= MAX (t
, (cfun_frame_layout
.f8_offset
6458 + cfun_frame_layout
.high_fprs
* 8));
6462 for (i
= 2; i
< 4; i
++)
6463 if (cfun_fpr_bit_p (i
))
6465 b
= MIN (b
, cfun_frame_layout
.f4_offset
+ (i
- 2) * 8);
6466 t
= MAX (t
, cfun_frame_layout
.f4_offset
+ (i
- 1) * 8);
6473 /* Fill cfun->machine with info about register usage of current function.
6474 Return in CLOBBERED_REGS which GPRs are currently considered set. */
6477 s390_register_info (int clobbered_regs
[])
6481 /* fprs 8 - 15 are call saved for 64 Bit ABI. */
6482 cfun_frame_layout
.fpr_bitmap
= 0;
6483 cfun_frame_layout
.high_fprs
= 0;
6485 for (i
= 24; i
< 32; i
++)
6486 if (df_regs_ever_live_p (i
) && !global_regs
[i
])
6488 cfun_set_fpr_bit (i
- 16);
6489 cfun_frame_layout
.high_fprs
++;
6492 /* Find first and last gpr to be saved. We trust regs_ever_live
6493 data, except that we don't save and restore global registers.
6495 Also, all registers with special meaning to the compiler need
6496 to be handled extra. */
6498 s390_regs_ever_clobbered (clobbered_regs
);
6500 for (i
= 0; i
< 16; i
++)
6501 clobbered_regs
[i
] = clobbered_regs
[i
] && !global_regs
[i
] && !fixed_regs
[i
];
6503 if (frame_pointer_needed
)
6504 clobbered_regs
[HARD_FRAME_POINTER_REGNUM
] = 1;
6507 clobbered_regs
[PIC_OFFSET_TABLE_REGNUM
]
6508 |= df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM
);
6510 clobbered_regs
[BASE_REGNUM
]
6511 |= (cfun
->machine
->base_reg
6512 && REGNO (cfun
->machine
->base_reg
) == BASE_REGNUM
);
6514 clobbered_regs
[RETURN_REGNUM
]
6515 |= (!current_function_is_leaf
6516 || TARGET_TPF_PROFILING
6517 || cfun
->machine
->split_branches_pending_p
6518 || cfun_frame_layout
.save_return_addr_p
6519 || current_function_calls_eh_return
6520 || current_function_stdarg
);
6522 clobbered_regs
[STACK_POINTER_REGNUM
]
6523 |= (!current_function_is_leaf
6524 || TARGET_TPF_PROFILING
6525 || cfun_save_high_fprs_p
6526 || get_frame_size () > 0
6527 || current_function_calls_alloca
6528 || current_function_stdarg
);
6530 for (i
= 6; i
< 16; i
++)
6531 if (df_regs_ever_live_p (i
) || clobbered_regs
[i
])
6533 for (j
= 15; j
> i
; j
--)
6534 if (df_regs_ever_live_p (j
) || clobbered_regs
[j
])
6539 /* Nothing to save/restore. */
6540 cfun_frame_layout
.first_save_gpr_slot
= -1;
6541 cfun_frame_layout
.last_save_gpr_slot
= -1;
6542 cfun_frame_layout
.first_save_gpr
= -1;
6543 cfun_frame_layout
.first_restore_gpr
= -1;
6544 cfun_frame_layout
.last_save_gpr
= -1;
6545 cfun_frame_layout
.last_restore_gpr
= -1;
6549 /* Save slots for gprs from i to j. */
6550 cfun_frame_layout
.first_save_gpr_slot
= i
;
6551 cfun_frame_layout
.last_save_gpr_slot
= j
;
6553 for (i
= cfun_frame_layout
.first_save_gpr_slot
;
6554 i
< cfun_frame_layout
.last_save_gpr_slot
+ 1;
6556 if (clobbered_regs
[i
])
6559 for (j
= cfun_frame_layout
.last_save_gpr_slot
; j
> i
; j
--)
6560 if (clobbered_regs
[j
])
6563 if (i
== cfun_frame_layout
.last_save_gpr_slot
+ 1)
6565 /* Nothing to save/restore. */
6566 cfun_frame_layout
.first_save_gpr
= -1;
6567 cfun_frame_layout
.first_restore_gpr
= -1;
6568 cfun_frame_layout
.last_save_gpr
= -1;
6569 cfun_frame_layout
.last_restore_gpr
= -1;
6573 /* Save / Restore from gpr i to j. */
6574 cfun_frame_layout
.first_save_gpr
= i
;
6575 cfun_frame_layout
.first_restore_gpr
= i
;
6576 cfun_frame_layout
.last_save_gpr
= j
;
6577 cfun_frame_layout
.last_restore_gpr
= j
;
6581 if (current_function_stdarg
)
6583 /* Varargs functions need to save gprs 2 to 6. */
6584 if (cfun
->va_list_gpr_size
6585 && current_function_args_info
.gprs
< GP_ARG_NUM_REG
)
6587 int min_gpr
= current_function_args_info
.gprs
;
6588 int max_gpr
= min_gpr
+ cfun
->va_list_gpr_size
;
6589 if (max_gpr
> GP_ARG_NUM_REG
)
6590 max_gpr
= GP_ARG_NUM_REG
;
6592 if (cfun_frame_layout
.first_save_gpr
== -1
6593 || cfun_frame_layout
.first_save_gpr
> 2 + min_gpr
)
6595 cfun_frame_layout
.first_save_gpr
= 2 + min_gpr
;
6596 cfun_frame_layout
.first_save_gpr_slot
= 2 + min_gpr
;
6599 if (cfun_frame_layout
.last_save_gpr
== -1
6600 || cfun_frame_layout
.last_save_gpr
< 2 + max_gpr
- 1)
6602 cfun_frame_layout
.last_save_gpr
= 2 + max_gpr
- 1;
6603 cfun_frame_layout
.last_save_gpr_slot
= 2 + max_gpr
- 1;
6607 /* Mark f0, f2 for 31 bit and f0-f4 for 64 bit to be saved. */
6608 if (TARGET_HARD_FLOAT
&& cfun
->va_list_fpr_size
6609 && current_function_args_info
.fprs
< FP_ARG_NUM_REG
)
6611 int min_fpr
= current_function_args_info
.fprs
;
6612 int max_fpr
= min_fpr
+ cfun
->va_list_fpr_size
;
6613 if (max_fpr
> FP_ARG_NUM_REG
)
6614 max_fpr
= FP_ARG_NUM_REG
;
6616 /* ??? This is currently required to ensure proper location
6617 of the fpr save slots within the va_list save area. */
6618 if (TARGET_PACKED_STACK
)
6621 for (i
= min_fpr
; i
< max_fpr
; i
++)
6622 cfun_set_fpr_bit (i
);
6627 for (i
= 2; i
< 4; i
++)
6628 if (df_regs_ever_live_p (i
+ 16) && !global_regs
[i
+ 16])
6629 cfun_set_fpr_bit (i
);
6632 /* Fill cfun->machine with info about frame of current function. */
6635 s390_frame_info (void)
6639 cfun_frame_layout
.frame_size
= get_frame_size ();
6640 if (!TARGET_64BIT
&& cfun_frame_layout
.frame_size
> 0x7fff0000)
6641 fatal_error ("total size of local variables exceeds architecture limit");
6643 if (!TARGET_PACKED_STACK
)
6645 cfun_frame_layout
.backchain_offset
= 0;
6646 cfun_frame_layout
.f0_offset
= 16 * UNITS_PER_WORD
;
6647 cfun_frame_layout
.f4_offset
= cfun_frame_layout
.f0_offset
+ 2 * 8;
6648 cfun_frame_layout
.f8_offset
= -cfun_frame_layout
.high_fprs
* 8;
6649 cfun_frame_layout
.gprs_offset
= (cfun_frame_layout
.first_save_gpr_slot
6652 else if (TARGET_BACKCHAIN
) /* kernel stack layout */
6654 cfun_frame_layout
.backchain_offset
= (STACK_POINTER_OFFSET
6656 cfun_frame_layout
.gprs_offset
6657 = (cfun_frame_layout
.backchain_offset
6658 - (STACK_POINTER_REGNUM
- cfun_frame_layout
.first_save_gpr_slot
+ 1)
6663 cfun_frame_layout
.f4_offset
6664 = (cfun_frame_layout
.gprs_offset
6665 - 8 * (cfun_fpr_bit_p (2) + cfun_fpr_bit_p (3)));
6667 cfun_frame_layout
.f0_offset
6668 = (cfun_frame_layout
.f4_offset
6669 - 8 * (cfun_fpr_bit_p (0) + cfun_fpr_bit_p (1)));
6673 /* On 31 bit we have to care about alignment of the
6674 floating point regs to provide fastest access. */
6675 cfun_frame_layout
.f0_offset
6676 = ((cfun_frame_layout
.gprs_offset
6677 & ~(STACK_BOUNDARY
/ BITS_PER_UNIT
- 1))
6678 - 8 * (cfun_fpr_bit_p (0) + cfun_fpr_bit_p (1)));
6680 cfun_frame_layout
.f4_offset
6681 = (cfun_frame_layout
.f0_offset
6682 - 8 * (cfun_fpr_bit_p (2) + cfun_fpr_bit_p (3)));
6685 else /* no backchain */
6687 cfun_frame_layout
.f4_offset
6688 = (STACK_POINTER_OFFSET
6689 - 8 * (cfun_fpr_bit_p (2) + cfun_fpr_bit_p (3)));
6691 cfun_frame_layout
.f0_offset
6692 = (cfun_frame_layout
.f4_offset
6693 - 8 * (cfun_fpr_bit_p (0) + cfun_fpr_bit_p (1)));
6695 cfun_frame_layout
.gprs_offset
6696 = cfun_frame_layout
.f0_offset
- cfun_gprs_save_area_size
;
6699 if (current_function_is_leaf
6700 && !TARGET_TPF_PROFILING
6701 && cfun_frame_layout
.frame_size
== 0
6702 && !cfun_save_high_fprs_p
6703 && !current_function_calls_alloca
6704 && !current_function_stdarg
)
6707 if (!TARGET_PACKED_STACK
)
6708 cfun_frame_layout
.frame_size
+= (STACK_POINTER_OFFSET
6709 + current_function_outgoing_args_size
6710 + cfun_frame_layout
.high_fprs
* 8);
6713 if (TARGET_BACKCHAIN
)
6714 cfun_frame_layout
.frame_size
+= UNITS_PER_WORD
;
6716 /* No alignment trouble here because f8-f15 are only saved under
6718 cfun_frame_layout
.f8_offset
= (MIN (MIN (cfun_frame_layout
.f0_offset
,
6719 cfun_frame_layout
.f4_offset
),
6720 cfun_frame_layout
.gprs_offset
)
6721 - cfun_frame_layout
.high_fprs
* 8);
6723 cfun_frame_layout
.frame_size
+= cfun_frame_layout
.high_fprs
* 8;
6725 for (i
= 0; i
< 8; i
++)
6726 if (cfun_fpr_bit_p (i
))
6727 cfun_frame_layout
.frame_size
+= 8;
6729 cfun_frame_layout
.frame_size
+= cfun_gprs_save_area_size
;
6731 /* If under 31 bit an odd number of gprs has to be saved we have to adjust
6732 the frame size to sustain 8 byte alignment of stack frames. */
6733 cfun_frame_layout
.frame_size
= ((cfun_frame_layout
.frame_size
+
6734 STACK_BOUNDARY
/ BITS_PER_UNIT
- 1)
6735 & ~(STACK_BOUNDARY
/ BITS_PER_UNIT
- 1));
6737 cfun_frame_layout
.frame_size
+= current_function_outgoing_args_size
;
6741 /* Generate frame layout. Fills in register and frame data for the current
6742 function in cfun->machine. This routine can be called multiple times;
6743 it will re-do the complete frame layout every time. */
6746 s390_init_frame_layout (void)
6748 HOST_WIDE_INT frame_size
;
6750 int clobbered_regs
[16];
6752 /* On S/390 machines, we may need to perform branch splitting, which
6753 will require both base and return address register. We have no
6754 choice but to assume we're going to need them until right at the
6755 end of the machine dependent reorg phase. */
6756 if (!TARGET_CPU_ZARCH
)
6757 cfun
->machine
->split_branches_pending_p
= true;
6761 frame_size
= cfun_frame_layout
.frame_size
;
6763 /* Try to predict whether we'll need the base register. */
6764 base_used
= cfun
->machine
->split_branches_pending_p
6765 || current_function_uses_const_pool
6766 || (!DISP_IN_RANGE (frame_size
)
6767 && !CONST_OK_FOR_K (frame_size
));
6769 /* Decide which register to use as literal pool base. In small
6770 leaf functions, try to use an unused call-clobbered register
6771 as base register to avoid save/restore overhead. */
6773 cfun
->machine
->base_reg
= NULL_RTX
;
6774 else if (current_function_is_leaf
&& !df_regs_ever_live_p (5))
6775 cfun
->machine
->base_reg
= gen_rtx_REG (Pmode
, 5);
6777 cfun
->machine
->base_reg
= gen_rtx_REG (Pmode
, BASE_REGNUM
);
6779 s390_register_info (clobbered_regs
);
6782 while (frame_size
!= cfun_frame_layout
.frame_size
);
6785 /* Update frame layout. Recompute actual register save data based on
6786 current info and update regs_ever_live for the special registers.
6787 May be called multiple times, but may never cause *more* registers
6788 to be saved than s390_init_frame_layout allocated room for. */
6791 s390_update_frame_layout (void)
6793 int clobbered_regs
[16];
6795 s390_register_info (clobbered_regs
);
6797 df_set_regs_ever_live (BASE_REGNUM
,
6798 clobbered_regs
[BASE_REGNUM
] ? true : false);
6799 df_set_regs_ever_live (RETURN_REGNUM
,
6800 clobbered_regs
[RETURN_REGNUM
] ? true : false);
6801 df_set_regs_ever_live (STACK_POINTER_REGNUM
,
6802 clobbered_regs
[STACK_POINTER_REGNUM
] ? true : false);
6804 if (cfun
->machine
->base_reg
)
6805 df_set_regs_ever_live (REGNO (cfun
->machine
->base_reg
), true);
6808 /* Return true if it is legal to put a value with MODE into REGNO. */
6811 s390_hard_regno_mode_ok (unsigned int regno
, enum machine_mode mode
)
6813 switch (REGNO_REG_CLASS (regno
))
6816 if (REGNO_PAIR_OK (regno
, mode
))
6818 if (mode
== SImode
|| mode
== DImode
)
6821 if (FLOAT_MODE_P (mode
) && GET_MODE_CLASS (mode
) != MODE_VECTOR_FLOAT
)
6826 if (FRAME_REGNO_P (regno
) && mode
== Pmode
)
6831 if (REGNO_PAIR_OK (regno
, mode
))
6834 || (mode
!= TFmode
&& mode
!= TCmode
&& mode
!= TDmode
))
6839 if (GET_MODE_CLASS (mode
) == MODE_CC
)
6843 if (REGNO_PAIR_OK (regno
, mode
))
6845 if (mode
== SImode
|| mode
== Pmode
)
6856 /* Return nonzero if register OLD_REG can be renamed to register NEW_REG. */
6859 s390_hard_regno_rename_ok (unsigned int old_reg
, unsigned int new_reg
)
6861 /* Once we've decided upon a register to use as base register, it must
6862 no longer be used for any other purpose. */
6863 if (cfun
->machine
->base_reg
)
6864 if (REGNO (cfun
->machine
->base_reg
) == old_reg
6865 || REGNO (cfun
->machine
->base_reg
) == new_reg
)
6871 /* Maximum number of registers to represent a value of mode MODE
6872 in a register of class CLASS. */
6875 s390_class_max_nregs (enum reg_class
class, enum machine_mode mode
)
6880 if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
)
6881 return 2 * ((GET_MODE_SIZE (mode
) / 2 + 8 - 1) / 8);
6883 return (GET_MODE_SIZE (mode
) + 8 - 1) / 8;
6885 return (GET_MODE_SIZE (mode
) + 4 - 1) / 4;
6889 return (GET_MODE_SIZE (mode
) + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
6892 /* Return true if register FROM can be eliminated via register TO. */
6895 s390_can_eliminate (int from
, int to
)
6897 /* On zSeries machines, we have not marked the base register as fixed.
6898 Instead, we have an elimination rule BASE_REGNUM -> BASE_REGNUM.
6899 If a function requires the base register, we say here that this
6900 elimination cannot be performed. This will cause reload to free
6901 up the base register (as if it were fixed). On the other hand,
6902 if the current function does *not* require the base register, we
6903 say here the elimination succeeds, which in turn allows reload
6904 to allocate the base register for any other purpose. */
6905 if (from
== BASE_REGNUM
&& to
== BASE_REGNUM
)
6907 if (TARGET_CPU_ZARCH
)
6909 s390_init_frame_layout ();
6910 return cfun
->machine
->base_reg
== NULL_RTX
;
6916 /* Everything else must point into the stack frame. */
6917 gcc_assert (to
== STACK_POINTER_REGNUM
6918 || to
== HARD_FRAME_POINTER_REGNUM
);
6920 gcc_assert (from
== FRAME_POINTER_REGNUM
6921 || from
== ARG_POINTER_REGNUM
6922 || from
== RETURN_ADDRESS_POINTER_REGNUM
);
6924 /* Make sure we actually saved the return address. */
6925 if (from
== RETURN_ADDRESS_POINTER_REGNUM
)
6926 if (!current_function_calls_eh_return
6927 && !current_function_stdarg
6928 && !cfun_frame_layout
.save_return_addr_p
)
6934 /* Return offset between register FROM and TO initially after prolog. */
6937 s390_initial_elimination_offset (int from
, int to
)
6939 HOST_WIDE_INT offset
;
6942 /* ??? Why are we called for non-eliminable pairs? */
6943 if (!s390_can_eliminate (from
, to
))
6948 case FRAME_POINTER_REGNUM
:
6949 offset
= (get_frame_size()
6950 + STACK_POINTER_OFFSET
6951 + current_function_outgoing_args_size
);
6954 case ARG_POINTER_REGNUM
:
6955 s390_init_frame_layout ();
6956 offset
= cfun_frame_layout
.frame_size
+ STACK_POINTER_OFFSET
;
6959 case RETURN_ADDRESS_POINTER_REGNUM
:
6960 s390_init_frame_layout ();
6961 index
= RETURN_REGNUM
- cfun_frame_layout
.first_save_gpr_slot
;
6962 gcc_assert (index
>= 0);
6963 offset
= cfun_frame_layout
.frame_size
+ cfun_frame_layout
.gprs_offset
;
6964 offset
+= index
* UNITS_PER_WORD
;
6978 /* Emit insn to save fpr REGNUM at offset OFFSET relative
6979 to register BASE. Return generated insn. */
6982 save_fpr (rtx base
, int offset
, int regnum
)
6985 addr
= gen_rtx_MEM (DFmode
, plus_constant (base
, offset
));
6987 if (regnum
>= 16 && regnum
<= (16 + FP_ARG_NUM_REG
))
6988 set_mem_alias_set (addr
, get_varargs_alias_set ());
6990 set_mem_alias_set (addr
, get_frame_alias_set ());
6992 return emit_move_insn (addr
, gen_rtx_REG (DFmode
, regnum
));
6995 /* Emit insn to restore fpr REGNUM from offset OFFSET relative
6996 to register BASE. Return generated insn. */
6999 restore_fpr (rtx base
, int offset
, int regnum
)
7002 addr
= gen_rtx_MEM (DFmode
, plus_constant (base
, offset
));
7003 set_mem_alias_set (addr
, get_frame_alias_set ());
7005 return emit_move_insn (gen_rtx_REG (DFmode
, regnum
), addr
);
7008 /* Generate insn to save registers FIRST to LAST into
7009 the register save area located at offset OFFSET
7010 relative to register BASE. */
7013 save_gprs (rtx base
, int offset
, int first
, int last
)
7015 rtx addr
, insn
, note
;
7018 addr
= plus_constant (base
, offset
);
7019 addr
= gen_rtx_MEM (Pmode
, addr
);
7021 set_mem_alias_set (addr
, get_frame_alias_set ());
7023 /* Special-case single register. */
7027 insn
= gen_movdi (addr
, gen_rtx_REG (Pmode
, first
));
7029 insn
= gen_movsi (addr
, gen_rtx_REG (Pmode
, first
));
7031 RTX_FRAME_RELATED_P (insn
) = 1;
7036 insn
= gen_store_multiple (addr
,
7037 gen_rtx_REG (Pmode
, first
),
7038 GEN_INT (last
- first
+ 1));
7040 if (first
<= 6 && current_function_stdarg
)
7041 for (i
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
7043 rtx mem
= XEXP (XVECEXP (PATTERN (insn
), 0, i
), 0);
7046 set_mem_alias_set (mem
, get_varargs_alias_set ());
7049 /* We need to set the FRAME_RELATED flag on all SETs
7050 inside the store-multiple pattern.
7052 However, we must not emit DWARF records for registers 2..5
7053 if they are stored for use by variable arguments ...
7055 ??? Unfortunately, it is not enough to simply not the
7056 FRAME_RELATED flags for those SETs, because the first SET
7057 of the PARALLEL is always treated as if it had the flag
7058 set, even if it does not. Therefore we emit a new pattern
7059 without those registers as REG_FRAME_RELATED_EXPR note. */
7063 rtx pat
= PATTERN (insn
);
7065 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
7066 if (GET_CODE (XVECEXP (pat
, 0, i
)) == SET
)
7067 RTX_FRAME_RELATED_P (XVECEXP (pat
, 0, i
)) = 1;
7069 RTX_FRAME_RELATED_P (insn
) = 1;
7073 addr
= plus_constant (base
, offset
+ (6 - first
) * UNITS_PER_WORD
);
7074 note
= gen_store_multiple (gen_rtx_MEM (Pmode
, addr
),
7075 gen_rtx_REG (Pmode
, 6),
7076 GEN_INT (last
- 6 + 1));
7077 note
= PATTERN (note
);
7080 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR
,
7081 note
, REG_NOTES (insn
));
7083 for (i
= 0; i
< XVECLEN (note
, 0); i
++)
7084 if (GET_CODE (XVECEXP (note
, 0, i
)) == SET
)
7085 RTX_FRAME_RELATED_P (XVECEXP (note
, 0, i
)) = 1;
7087 RTX_FRAME_RELATED_P (insn
) = 1;
7093 /* Generate insn to restore registers FIRST to LAST from
7094 the register save area located at offset OFFSET
7095 relative to register BASE. */
7098 restore_gprs (rtx base
, int offset
, int first
, int last
)
7102 addr
= plus_constant (base
, offset
);
7103 addr
= gen_rtx_MEM (Pmode
, addr
);
7104 set_mem_alias_set (addr
, get_frame_alias_set ());
7106 /* Special-case single register. */
7110 insn
= gen_movdi (gen_rtx_REG (Pmode
, first
), addr
);
7112 insn
= gen_movsi (gen_rtx_REG (Pmode
, first
), addr
);
7117 insn
= gen_load_multiple (gen_rtx_REG (Pmode
, first
),
7119 GEN_INT (last
- first
+ 1));
7123 /* Return insn sequence to load the GOT register. */
7125 static GTY(()) rtx got_symbol
;
7127 s390_load_got (void)
7133 got_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "_GLOBAL_OFFSET_TABLE_");
7134 SYMBOL_REF_FLAGS (got_symbol
) = SYMBOL_FLAG_LOCAL
;
7139 if (TARGET_CPU_ZARCH
)
7141 emit_move_insn (pic_offset_table_rtx
, got_symbol
);
7147 offset
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, got_symbol
),
7148 UNSPEC_LTREL_OFFSET
);
7149 offset
= gen_rtx_CONST (Pmode
, offset
);
7150 offset
= force_const_mem (Pmode
, offset
);
7152 emit_move_insn (pic_offset_table_rtx
, offset
);
7154 offset
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, XEXP (offset
, 0)),
7156 offset
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, offset
);
7158 emit_move_insn (pic_offset_table_rtx
, offset
);
7161 insns
= get_insns ();
7166 /* Expand the prologue into a bunch of separate insns. */
7169 s390_emit_prologue (void)
7177 /* Complete frame layout. */
7179 s390_update_frame_layout ();
7181 /* Annotate all constant pool references to let the scheduler know
7182 they implicitly use the base register. */
7184 push_topmost_sequence ();
7186 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
7189 annotate_constant_pool_refs (&PATTERN (insn
));
7190 df_insn_rescan (insn
);
7193 pop_topmost_sequence ();
7195 /* Choose best register to use for temp use within prologue.
7196 See below for why TPF must use the register 1. */
7198 if (!has_hard_reg_initial_val (Pmode
, RETURN_REGNUM
)
7199 && !current_function_is_leaf
7200 && !TARGET_TPF_PROFILING
)
7201 temp_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
7203 temp_reg
= gen_rtx_REG (Pmode
, 1);
7205 /* Save call saved gprs. */
7206 if (cfun_frame_layout
.first_save_gpr
!= -1)
7208 insn
= save_gprs (stack_pointer_rtx
,
7209 cfun_frame_layout
.gprs_offset
+
7210 UNITS_PER_WORD
* (cfun_frame_layout
.first_save_gpr
7211 - cfun_frame_layout
.first_save_gpr_slot
),
7212 cfun_frame_layout
.first_save_gpr
,
7213 cfun_frame_layout
.last_save_gpr
);
7217 /* Dummy insn to mark literal pool slot. */
7219 if (cfun
->machine
->base_reg
)
7220 emit_insn (gen_main_pool (cfun
->machine
->base_reg
));
7222 offset
= cfun_frame_layout
.f0_offset
;
7224 /* Save f0 and f2. */
7225 for (i
= 0; i
< 2; i
++)
7227 if (cfun_fpr_bit_p (i
))
7229 save_fpr (stack_pointer_rtx
, offset
, i
+ 16);
7232 else if (!TARGET_PACKED_STACK
)
7236 /* Save f4 and f6. */
7237 offset
= cfun_frame_layout
.f4_offset
;
7238 for (i
= 2; i
< 4; i
++)
7240 if (cfun_fpr_bit_p (i
))
7242 insn
= save_fpr (stack_pointer_rtx
, offset
, i
+ 16);
7245 /* If f4 and f6 are call clobbered they are saved due to stdargs and
7246 therefore are not frame related. */
7247 if (!call_really_used_regs
[i
+ 16])
7248 RTX_FRAME_RELATED_P (insn
) = 1;
7250 else if (!TARGET_PACKED_STACK
)
7254 if (TARGET_PACKED_STACK
7255 && cfun_save_high_fprs_p
7256 && cfun_frame_layout
.f8_offset
+ cfun_frame_layout
.high_fprs
* 8 > 0)
7258 offset
= (cfun_frame_layout
.f8_offset
7259 + (cfun_frame_layout
.high_fprs
- 1) * 8);
7261 for (i
= 15; i
> 7 && offset
>= 0; i
--)
7262 if (cfun_fpr_bit_p (i
))
7264 insn
= save_fpr (stack_pointer_rtx
, offset
, i
+ 16);
7266 RTX_FRAME_RELATED_P (insn
) = 1;
7269 if (offset
>= cfun_frame_layout
.f8_offset
)
7273 if (!TARGET_PACKED_STACK
)
7274 next_fpr
= cfun_save_high_fprs_p
? 31 : 0;
7276 /* Decrement stack pointer. */
7278 if (cfun_frame_layout
.frame_size
> 0)
7280 rtx frame_off
= GEN_INT (-cfun_frame_layout
.frame_size
);
7282 if (s390_stack_size
)
7284 HOST_WIDE_INT stack_guard
;
7286 if (s390_stack_guard
)
7287 stack_guard
= s390_stack_guard
;
7290 /* If no value for stack guard is provided the smallest power of 2
7291 larger than the current frame size is chosen. */
7293 while (stack_guard
< cfun_frame_layout
.frame_size
)
7297 if (cfun_frame_layout
.frame_size
>= s390_stack_size
)
7299 warning (0, "frame size of function %qs is "
7300 HOST_WIDE_INT_PRINT_DEC
7301 " bytes exceeding user provided stack limit of "
7302 HOST_WIDE_INT_PRINT_DEC
" bytes. "
7303 "An unconditional trap is added.",
7304 current_function_name(), cfun_frame_layout
.frame_size
,
7306 emit_insn (gen_trap ());
7310 HOST_WIDE_INT stack_check_mask
= ((s390_stack_size
- 1)
7311 & ~(stack_guard
- 1));
7312 rtx t
= gen_rtx_AND (Pmode
, stack_pointer_rtx
,
7313 GEN_INT (stack_check_mask
));
7315 gen_cmpdi (t
, const0_rtx
);
7317 gen_cmpsi (t
, const0_rtx
);
7319 emit_insn (gen_conditional_trap (gen_rtx_EQ (CCmode
,
7320 gen_rtx_REG (CCmode
,
7327 if (s390_warn_framesize
> 0
7328 && cfun_frame_layout
.frame_size
>= s390_warn_framesize
)
7329 warning (0, "frame size of %qs is " HOST_WIDE_INT_PRINT_DEC
" bytes",
7330 current_function_name (), cfun_frame_layout
.frame_size
);
7332 if (s390_warn_dynamicstack_p
&& cfun
->calls_alloca
)
7333 warning (0, "%qs uses dynamic stack allocation", current_function_name ());
7335 /* Save incoming stack pointer into temp reg. */
7336 if (TARGET_BACKCHAIN
|| next_fpr
)
7337 insn
= emit_insn (gen_move_insn (temp_reg
, stack_pointer_rtx
));
7339 /* Subtract frame size from stack pointer. */
7341 if (DISP_IN_RANGE (INTVAL (frame_off
)))
7343 insn
= gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
7344 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
7346 insn
= emit_insn (insn
);
7350 if (!CONST_OK_FOR_K (INTVAL (frame_off
)))
7351 frame_off
= force_const_mem (Pmode
, frame_off
);
7353 insn
= emit_insn (gen_add2_insn (stack_pointer_rtx
, frame_off
));
7354 annotate_constant_pool_refs (&PATTERN (insn
));
7357 RTX_FRAME_RELATED_P (insn
) = 1;
7359 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR
,
7360 gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
7361 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
7362 GEN_INT (-cfun_frame_layout
.frame_size
))),
7365 /* Set backchain. */
7367 if (TARGET_BACKCHAIN
)
7369 if (cfun_frame_layout
.backchain_offset
)
7370 addr
= gen_rtx_MEM (Pmode
,
7371 plus_constant (stack_pointer_rtx
,
7372 cfun_frame_layout
.backchain_offset
));
7374 addr
= gen_rtx_MEM (Pmode
, stack_pointer_rtx
);
7375 set_mem_alias_set (addr
, get_frame_alias_set ());
7376 insn
= emit_insn (gen_move_insn (addr
, temp_reg
));
7379 /* If we support asynchronous exceptions (e.g. for Java),
7380 we need to make sure the backchain pointer is set up
7381 before any possibly trapping memory access. */
7383 if (TARGET_BACKCHAIN
&& flag_non_call_exceptions
)
7385 addr
= gen_rtx_MEM (BLKmode
, gen_rtx_SCRATCH (VOIDmode
));
7386 emit_insn (gen_rtx_CLOBBER (VOIDmode
, addr
));
7390 /* Save fprs 8 - 15 (64 bit ABI). */
7392 if (cfun_save_high_fprs_p
&& next_fpr
)
7394 insn
= emit_insn (gen_add2_insn (temp_reg
,
7395 GEN_INT (cfun_frame_layout
.f8_offset
)));
7399 for (i
= 24; i
<= next_fpr
; i
++)
7400 if (cfun_fpr_bit_p (i
- 16))
7402 rtx addr
= plus_constant (stack_pointer_rtx
,
7403 cfun_frame_layout
.frame_size
7404 + cfun_frame_layout
.f8_offset
7407 insn
= save_fpr (temp_reg
, offset
, i
);
7409 RTX_FRAME_RELATED_P (insn
) = 1;
7411 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR
,
7412 gen_rtx_SET (VOIDmode
,
7413 gen_rtx_MEM (DFmode
, addr
),
7414 gen_rtx_REG (DFmode
, i
)),
7419 /* Set frame pointer, if needed. */
7421 if (frame_pointer_needed
)
7423 insn
= emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
);
7424 RTX_FRAME_RELATED_P (insn
) = 1;
7427 /* Set up got pointer, if needed. */
7429 if (flag_pic
&& df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM
))
7431 rtx insns
= s390_load_got ();
7433 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
7434 annotate_constant_pool_refs (&PATTERN (insn
));
7439 if (TARGET_TPF_PROFILING
)
7441 /* Generate a BAS instruction to serve as a function
7442 entry intercept to facilitate the use of tracing
7443 algorithms located at the branch target. */
7444 emit_insn (gen_prologue_tpf ());
7446 /* Emit a blockage here so that all code
7447 lies between the profiling mechanisms. */
7448 emit_insn (gen_blockage ());
7452 /* Expand the epilogue into a bunch of separate insns. */
7455 s390_emit_epilogue (bool sibcall
)
7457 rtx frame_pointer
, return_reg
;
7458 int area_bottom
, area_top
, offset
= 0;
7463 if (TARGET_TPF_PROFILING
)
7466 /* Generate a BAS instruction to serve as a function
7467 entry intercept to facilitate the use of tracing
7468 algorithms located at the branch target. */
7470 /* Emit a blockage here so that all code
7471 lies between the profiling mechanisms. */
7472 emit_insn (gen_blockage ());
7474 emit_insn (gen_epilogue_tpf ());
7477 /* Check whether to use frame or stack pointer for restore. */
7479 frame_pointer
= (frame_pointer_needed
7480 ? hard_frame_pointer_rtx
: stack_pointer_rtx
);
7482 s390_frame_area (&area_bottom
, &area_top
);
7484 /* Check whether we can access the register save area.
7485 If not, increment the frame pointer as required. */
7487 if (area_top
<= area_bottom
)
7489 /* Nothing to restore. */
7491 else if (DISP_IN_RANGE (cfun_frame_layout
.frame_size
+ area_bottom
)
7492 && DISP_IN_RANGE (cfun_frame_layout
.frame_size
+ area_top
- 1))
7494 /* Area is in range. */
7495 offset
= cfun_frame_layout
.frame_size
;
7499 rtx insn
, frame_off
;
7501 offset
= area_bottom
< 0 ? -area_bottom
: 0;
7502 frame_off
= GEN_INT (cfun_frame_layout
.frame_size
- offset
);
7504 if (DISP_IN_RANGE (INTVAL (frame_off
)))
7506 insn
= gen_rtx_SET (VOIDmode
, frame_pointer
,
7507 gen_rtx_PLUS (Pmode
, frame_pointer
, frame_off
));
7508 insn
= emit_insn (insn
);
7512 if (!CONST_OK_FOR_K (INTVAL (frame_off
)))
7513 frame_off
= force_const_mem (Pmode
, frame_off
);
7515 insn
= emit_insn (gen_add2_insn (frame_pointer
, frame_off
));
7516 annotate_constant_pool_refs (&PATTERN (insn
));
7520 /* Restore call saved fprs. */
7524 if (cfun_save_high_fprs_p
)
7526 next_offset
= cfun_frame_layout
.f8_offset
;
7527 for (i
= 24; i
< 32; i
++)
7529 if (cfun_fpr_bit_p (i
- 16))
7531 restore_fpr (frame_pointer
,
7532 offset
+ next_offset
, i
);
7541 next_offset
= cfun_frame_layout
.f4_offset
;
7542 for (i
= 18; i
< 20; i
++)
7544 if (cfun_fpr_bit_p (i
- 16))
7546 restore_fpr (frame_pointer
,
7547 offset
+ next_offset
, i
);
7550 else if (!TARGET_PACKED_STACK
)
7556 /* Return register. */
7558 return_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
7560 /* Restore call saved gprs. */
7562 if (cfun_frame_layout
.first_restore_gpr
!= -1)
7567 /* Check for global register and save them
7568 to stack location from where they get restored. */
7570 for (i
= cfun_frame_layout
.first_restore_gpr
;
7571 i
<= cfun_frame_layout
.last_restore_gpr
;
7574 /* These registers are special and need to be
7575 restored in any case. */
7576 if (i
== STACK_POINTER_REGNUM
7577 || i
== RETURN_REGNUM
7579 || (flag_pic
&& i
== (int)PIC_OFFSET_TABLE_REGNUM
))
7584 addr
= plus_constant (frame_pointer
,
7585 offset
+ cfun_frame_layout
.gprs_offset
7586 + (i
- cfun_frame_layout
.first_save_gpr_slot
)
7588 addr
= gen_rtx_MEM (Pmode
, addr
);
7589 set_mem_alias_set (addr
, get_frame_alias_set ());
7590 emit_move_insn (addr
, gen_rtx_REG (Pmode
, i
));
7596 /* Fetch return address from stack before load multiple,
7597 this will do good for scheduling. */
7599 if (cfun_frame_layout
.save_return_addr_p
7600 || (cfun_frame_layout
.first_restore_gpr
< BASE_REGNUM
7601 && cfun_frame_layout
.last_restore_gpr
> RETURN_REGNUM
))
7603 int return_regnum
= find_unused_clobbered_reg();
7606 return_reg
= gen_rtx_REG (Pmode
, return_regnum
);
7608 addr
= plus_constant (frame_pointer
,
7609 offset
+ cfun_frame_layout
.gprs_offset
7611 - cfun_frame_layout
.first_save_gpr_slot
)
7613 addr
= gen_rtx_MEM (Pmode
, addr
);
7614 set_mem_alias_set (addr
, get_frame_alias_set ());
7615 emit_move_insn (return_reg
, addr
);
7619 insn
= restore_gprs (frame_pointer
,
7620 offset
+ cfun_frame_layout
.gprs_offset
7621 + (cfun_frame_layout
.first_restore_gpr
7622 - cfun_frame_layout
.first_save_gpr_slot
)
7624 cfun_frame_layout
.first_restore_gpr
,
7625 cfun_frame_layout
.last_restore_gpr
);
7632 /* Return to caller. */
7634 p
= rtvec_alloc (2);
7636 RTVEC_ELT (p
, 0) = gen_rtx_RETURN (VOIDmode
);
7637 RTVEC_ELT (p
, 1) = gen_rtx_USE (VOIDmode
, return_reg
);
7638 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
7643 /* Return the size in bytes of a function argument of
7644 type TYPE and/or mode MODE. At least one of TYPE or
7645 MODE must be specified. */
7648 s390_function_arg_size (enum machine_mode mode
, tree type
)
7651 return int_size_in_bytes (type
);
7653 /* No type info available for some library calls ... */
7654 if (mode
!= BLKmode
)
7655 return GET_MODE_SIZE (mode
);
7657 /* If we have neither type nor mode, abort */
7661 /* Return true if a function argument of type TYPE and mode MODE
7662 is to be passed in a floating-point register, if available. */
7665 s390_function_arg_float (enum machine_mode mode
, tree type
)
7667 int size
= s390_function_arg_size (mode
, type
);
7671 /* Soft-float changes the ABI: no floating-point registers are used. */
7672 if (TARGET_SOFT_FLOAT
)
7675 /* No type info available for some library calls ... */
7677 return mode
== SFmode
|| mode
== DFmode
|| mode
== SDmode
|| mode
== DDmode
;
7679 /* The ABI says that record types with a single member are treated
7680 just like that member would be. */
7681 while (TREE_CODE (type
) == RECORD_TYPE
)
7683 tree field
, single
= NULL_TREE
;
7685 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
7687 if (TREE_CODE (field
) != FIELD_DECL
)
7690 if (single
== NULL_TREE
)
7691 single
= TREE_TYPE (field
);
7696 if (single
== NULL_TREE
)
7702 return TREE_CODE (type
) == REAL_TYPE
;
7705 /* Return true if a function argument of type TYPE and mode MODE
7706 is to be passed in an integer register, or a pair of integer
7707 registers, if available. */
7710 s390_function_arg_integer (enum machine_mode mode
, tree type
)
7712 int size
= s390_function_arg_size (mode
, type
);
7716 /* No type info available for some library calls ... */
7718 return GET_MODE_CLASS (mode
) == MODE_INT
7719 || (TARGET_SOFT_FLOAT
&& SCALAR_FLOAT_MODE_P (mode
));
7721 /* We accept small integral (and similar) types. */
7722 if (INTEGRAL_TYPE_P (type
)
7723 || POINTER_TYPE_P (type
)
7724 || TREE_CODE (type
) == OFFSET_TYPE
7725 || (TARGET_SOFT_FLOAT
&& TREE_CODE (type
) == REAL_TYPE
))
7728 /* We also accept structs of size 1, 2, 4, 8 that are not
7729 passed in floating-point registers. */
7730 if (AGGREGATE_TYPE_P (type
)
7731 && exact_log2 (size
) >= 0
7732 && !s390_function_arg_float (mode
, type
))
7738 /* Return 1 if a function argument of type TYPE and mode MODE
7739 is to be passed by reference. The ABI specifies that only
7740 structures of size 1, 2, 4, or 8 bytes are passed by value,
7741 all other structures (and complex numbers) are passed by
7745 s390_pass_by_reference (CUMULATIVE_ARGS
*ca ATTRIBUTE_UNUSED
,
7746 enum machine_mode mode
, tree type
,
7747 bool named ATTRIBUTE_UNUSED
)
7749 int size
= s390_function_arg_size (mode
, type
);
7755 if (AGGREGATE_TYPE_P (type
) && exact_log2 (size
) < 0)
7758 if (TREE_CODE (type
) == COMPLEX_TYPE
7759 || TREE_CODE (type
) == VECTOR_TYPE
)
7766 /* Update the data in CUM to advance over an argument of mode MODE and
7767 data type TYPE. (TYPE is null for libcalls where that information
7768 may not be available.). The boolean NAMED specifies whether the
7769 argument is a named argument (as opposed to an unnamed argument
7770 matching an ellipsis). */
7773 s390_function_arg_advance (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
,
7774 tree type
, int named ATTRIBUTE_UNUSED
)
7776 if (s390_function_arg_float (mode
, type
))
7780 else if (s390_function_arg_integer (mode
, type
))
7782 int size
= s390_function_arg_size (mode
, type
);
7783 cum
->gprs
+= ((size
+ UNITS_PER_WORD
-1) / UNITS_PER_WORD
);
7789 /* Define where to put the arguments to a function.
7790 Value is zero to push the argument on the stack,
7791 or a hard register in which to store the argument.
7793 MODE is the argument's machine mode.
7794 TYPE is the data type of the argument (as a tree).
7795 This is null for libcalls where that information may
7797 CUM is a variable of type CUMULATIVE_ARGS which gives info about
7798 the preceding args and about the function being called.
7799 NAMED is nonzero if this argument is a named parameter
7800 (otherwise it is an extra parameter matching an ellipsis).
7802 On S/390, we use general purpose registers 2 through 6 to
7803 pass integer, pointer, and certain structure arguments, and
7804 floating point registers 0 and 2 (0, 2, 4, and 6 on 64-bit)
7805 to pass floating point arguments. All remaining arguments
7806 are pushed to the stack. */
7809 s390_function_arg (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
, tree type
,
7810 int named ATTRIBUTE_UNUSED
)
7812 if (s390_function_arg_float (mode
, type
))
7814 if (cum
->fprs
+ 1 > FP_ARG_NUM_REG
)
7817 return gen_rtx_REG (mode
, cum
->fprs
+ 16);
7819 else if (s390_function_arg_integer (mode
, type
))
7821 int size
= s390_function_arg_size (mode
, type
);
7822 int n_gprs
= (size
+ UNITS_PER_WORD
-1) / UNITS_PER_WORD
;
7824 if (cum
->gprs
+ n_gprs
> GP_ARG_NUM_REG
)
7827 return gen_rtx_REG (mode
, cum
->gprs
+ 2);
7830 /* After the real arguments, expand_call calls us once again
7831 with a void_type_node type. Whatever we return here is
7832 passed as operand 2 to the call expanders.
7834 We don't need this feature ... */
7835 else if (type
== void_type_node
)
7841 /* Return true if return values of type TYPE should be returned
7842 in a memory buffer whose address is passed by the caller as
7843 hidden first argument. */
7846 s390_return_in_memory (tree type
, tree fundecl ATTRIBUTE_UNUSED
)
7848 /* We accept small integral (and similar) types. */
7849 if (INTEGRAL_TYPE_P (type
)
7850 || POINTER_TYPE_P (type
)
7851 || TREE_CODE (type
) == OFFSET_TYPE
7852 || TREE_CODE (type
) == REAL_TYPE
)
7853 return int_size_in_bytes (type
) > 8;
7855 /* Aggregates and similar constructs are always returned
7857 if (AGGREGATE_TYPE_P (type
)
7858 || TREE_CODE (type
) == COMPLEX_TYPE
7859 || TREE_CODE (type
) == VECTOR_TYPE
)
7862 /* ??? We get called on all sorts of random stuff from
7863 aggregate_value_p. We can't abort, but it's not clear
7864 what's safe to return. Pretend it's a struct I guess. */
7868 /* Define where to return a (scalar) value of type TYPE.
7869 If TYPE is null, define where to return a (scalar)
7870 value of mode MODE from a libcall. */
7873 s390_function_value (tree type
, enum machine_mode mode
)
7877 int unsignedp
= TYPE_UNSIGNED (type
);
7878 mode
= promote_mode (type
, TYPE_MODE (type
), &unsignedp
, 1);
7881 gcc_assert (GET_MODE_CLASS (mode
) == MODE_INT
|| SCALAR_FLOAT_MODE_P (mode
));
7882 gcc_assert (GET_MODE_SIZE (mode
) <= 8);
7884 if (TARGET_HARD_FLOAT
&& SCALAR_FLOAT_MODE_P (mode
))
7885 return gen_rtx_REG (mode
, 16);
7887 return gen_rtx_REG (mode
, 2);
7891 /* Create and return the va_list datatype.
7893 On S/390, va_list is an array type equivalent to
7895 typedef struct __va_list_tag
7899 void *__overflow_arg_area;
7900 void *__reg_save_area;
7903 where __gpr and __fpr hold the number of general purpose
7904 or floating point arguments used up to now, respectively,
7905 __overflow_arg_area points to the stack location of the
7906 next argument passed on the stack, and __reg_save_area
7907 always points to the start of the register area in the
7908 call frame of the current function. The function prologue
7909 saves all registers used for argument passing into this
7910 area if the function uses variable arguments. */
7913 s390_build_builtin_va_list (void)
7915 tree f_gpr
, f_fpr
, f_ovf
, f_sav
, record
, type_decl
;
7917 record
= lang_hooks
.types
.make_type (RECORD_TYPE
);
7920 build_decl (TYPE_DECL
, get_identifier ("__va_list_tag"), record
);
7922 f_gpr
= build_decl (FIELD_DECL
, get_identifier ("__gpr"),
7923 long_integer_type_node
);
7924 f_fpr
= build_decl (FIELD_DECL
, get_identifier ("__fpr"),
7925 long_integer_type_node
);
7926 f_ovf
= build_decl (FIELD_DECL
, get_identifier ("__overflow_arg_area"),
7928 f_sav
= build_decl (FIELD_DECL
, get_identifier ("__reg_save_area"),
7931 va_list_gpr_counter_field
= f_gpr
;
7932 va_list_fpr_counter_field
= f_fpr
;
7934 DECL_FIELD_CONTEXT (f_gpr
) = record
;
7935 DECL_FIELD_CONTEXT (f_fpr
) = record
;
7936 DECL_FIELD_CONTEXT (f_ovf
) = record
;
7937 DECL_FIELD_CONTEXT (f_sav
) = record
;
7939 TREE_CHAIN (record
) = type_decl
;
7940 TYPE_NAME (record
) = type_decl
;
7941 TYPE_FIELDS (record
) = f_gpr
;
7942 TREE_CHAIN (f_gpr
) = f_fpr
;
7943 TREE_CHAIN (f_fpr
) = f_ovf
;
7944 TREE_CHAIN (f_ovf
) = f_sav
;
7946 layout_type (record
);
7948 /* The correct type is an array type of one element. */
7949 return build_array_type (record
, build_index_type (size_zero_node
));
7952 /* Implement va_start by filling the va_list structure VALIST.
7953 STDARG_P is always true, and ignored.
7954 NEXTARG points to the first anonymous stack argument.
7956 The following global variables are used to initialize
7957 the va_list structure:
7959 current_function_args_info:
7960 holds number of gprs and fprs used for named arguments.
7961 current_function_arg_offset_rtx:
7962 holds the offset of the first anonymous stack argument
7963 (relative to the virtual arg pointer). */
7966 s390_va_start (tree valist
, rtx nextarg ATTRIBUTE_UNUSED
)
7968 HOST_WIDE_INT n_gpr
, n_fpr
;
7970 tree f_gpr
, f_fpr
, f_ovf
, f_sav
;
7971 tree gpr
, fpr
, ovf
, sav
, t
;
7973 f_gpr
= TYPE_FIELDS (TREE_TYPE (va_list_type_node
));
7974 f_fpr
= TREE_CHAIN (f_gpr
);
7975 f_ovf
= TREE_CHAIN (f_fpr
);
7976 f_sav
= TREE_CHAIN (f_ovf
);
7978 valist
= build_va_arg_indirect_ref (valist
);
7979 gpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_gpr
), valist
, f_gpr
, NULL_TREE
);
7980 fpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_fpr
), valist
, f_fpr
, NULL_TREE
);
7981 ovf
= build3 (COMPONENT_REF
, TREE_TYPE (f_ovf
), valist
, f_ovf
, NULL_TREE
);
7982 sav
= build3 (COMPONENT_REF
, TREE_TYPE (f_sav
), valist
, f_sav
, NULL_TREE
);
7984 /* Count number of gp and fp argument registers used. */
7986 n_gpr
= current_function_args_info
.gprs
;
7987 n_fpr
= current_function_args_info
.fprs
;
7989 if (cfun
->va_list_gpr_size
)
7991 t
= build2 (GIMPLE_MODIFY_STMT
, TREE_TYPE (gpr
), gpr
,
7992 build_int_cst (NULL_TREE
, n_gpr
));
7993 TREE_SIDE_EFFECTS (t
) = 1;
7994 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
7997 if (cfun
->va_list_fpr_size
)
7999 t
= build2 (GIMPLE_MODIFY_STMT
, TREE_TYPE (fpr
), fpr
,
8000 build_int_cst (NULL_TREE
, n_fpr
));
8001 TREE_SIDE_EFFECTS (t
) = 1;
8002 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
8005 /* Find the overflow area. */
8006 if (n_gpr
+ cfun
->va_list_gpr_size
> GP_ARG_NUM_REG
8007 || n_fpr
+ cfun
->va_list_fpr_size
> FP_ARG_NUM_REG
)
8009 t
= make_tree (TREE_TYPE (ovf
), virtual_incoming_args_rtx
);
8011 off
= INTVAL (current_function_arg_offset_rtx
);
8012 off
= off
< 0 ? 0 : off
;
8013 if (TARGET_DEBUG_ARG
)
8014 fprintf (stderr
, "va_start: n_gpr = %d, n_fpr = %d off %d\n",
8015 (int)n_gpr
, (int)n_fpr
, off
);
8017 t
= build2 (POINTER_PLUS_EXPR
, TREE_TYPE (ovf
), t
, size_int (off
));
8019 t
= build2 (GIMPLE_MODIFY_STMT
, TREE_TYPE (ovf
), ovf
, t
);
8020 TREE_SIDE_EFFECTS (t
) = 1;
8021 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
8024 /* Find the register save area. */
8025 if ((cfun
->va_list_gpr_size
&& n_gpr
< GP_ARG_NUM_REG
)
8026 || (cfun
->va_list_fpr_size
&& n_fpr
< FP_ARG_NUM_REG
))
8028 t
= make_tree (TREE_TYPE (sav
), return_address_pointer_rtx
);
8029 t
= build2 (POINTER_PLUS_EXPR
, TREE_TYPE (sav
), t
,
8030 size_int (-RETURN_REGNUM
* UNITS_PER_WORD
));
8032 t
= build2 (GIMPLE_MODIFY_STMT
, TREE_TYPE (sav
), sav
, t
);
8033 TREE_SIDE_EFFECTS (t
) = 1;
8034 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
8038 /* Implement va_arg by updating the va_list structure
8039 VALIST as required to retrieve an argument of type
8040 TYPE, and returning that argument.
8042 Generates code equivalent to:
8044 if (integral value) {
8045 if (size <= 4 && args.gpr < 5 ||
8046 size > 4 && args.gpr < 4 )
8047 ret = args.reg_save_area[args.gpr+8]
8049 ret = *args.overflow_arg_area++;
8050 } else if (float value) {
8052 ret = args.reg_save_area[args.fpr+64]
8054 ret = *args.overflow_arg_area++;
8055 } else if (aggregate value) {
8057 ret = *args.reg_save_area[args.gpr]
8059 ret = **args.overflow_arg_area++;
8063 s390_gimplify_va_arg (tree valist
, tree type
, tree
*pre_p
,
8064 tree
*post_p ATTRIBUTE_UNUSED
)
8066 tree f_gpr
, f_fpr
, f_ovf
, f_sav
;
8067 tree gpr
, fpr
, ovf
, sav
, reg
, t
, u
;
8068 int indirect_p
, size
, n_reg
, sav_ofs
, sav_scale
, max_reg
;
8069 tree lab_false
, lab_over
, addr
;
8071 f_gpr
= TYPE_FIELDS (TREE_TYPE (va_list_type_node
));
8072 f_fpr
= TREE_CHAIN (f_gpr
);
8073 f_ovf
= TREE_CHAIN (f_fpr
);
8074 f_sav
= TREE_CHAIN (f_ovf
);
8076 valist
= build_va_arg_indirect_ref (valist
);
8077 gpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_gpr
), valist
, f_gpr
, NULL_TREE
);
8078 fpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_fpr
), valist
, f_fpr
, NULL_TREE
);
8079 ovf
= build3 (COMPONENT_REF
, TREE_TYPE (f_ovf
), valist
, f_ovf
, NULL_TREE
);
8080 sav
= build3 (COMPONENT_REF
, TREE_TYPE (f_sav
), valist
, f_sav
, NULL_TREE
);
8082 size
= int_size_in_bytes (type
);
8084 if (pass_by_reference (NULL
, TYPE_MODE (type
), type
, false))
8086 if (TARGET_DEBUG_ARG
)
8088 fprintf (stderr
, "va_arg: aggregate type");
8092 /* Aggregates are passed by reference. */
8097 /* kernel stack layout on 31 bit: It is assumed here that no padding
8098 will be added by s390_frame_info because for va_args always an even
8099 number of gprs has to be saved r15-r2 = 14 regs. */
8100 sav_ofs
= 2 * UNITS_PER_WORD
;
8101 sav_scale
= UNITS_PER_WORD
;
8102 size
= UNITS_PER_WORD
;
8103 max_reg
= GP_ARG_NUM_REG
- n_reg
;
8105 else if (s390_function_arg_float (TYPE_MODE (type
), type
))
8107 if (TARGET_DEBUG_ARG
)
8109 fprintf (stderr
, "va_arg: float type");
8113 /* FP args go in FP registers, if present. */
8117 sav_ofs
= 16 * UNITS_PER_WORD
;
8119 max_reg
= FP_ARG_NUM_REG
- n_reg
;
8123 if (TARGET_DEBUG_ARG
)
8125 fprintf (stderr
, "va_arg: other type");
8129 /* Otherwise into GP registers. */
8132 n_reg
= (size
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
8134 /* kernel stack layout on 31 bit: It is assumed here that no padding
8135 will be added by s390_frame_info because for va_args always an even
8136 number of gprs has to be saved r15-r2 = 14 regs. */
8137 sav_ofs
= 2 * UNITS_PER_WORD
;
8139 if (size
< UNITS_PER_WORD
)
8140 sav_ofs
+= UNITS_PER_WORD
- size
;
8142 sav_scale
= UNITS_PER_WORD
;
8143 max_reg
= GP_ARG_NUM_REG
- n_reg
;
8146 /* Pull the value out of the saved registers ... */
8148 lab_false
= create_artificial_label ();
8149 lab_over
= create_artificial_label ();
8150 addr
= create_tmp_var (ptr_type_node
, "addr");
8151 DECL_POINTER_ALIAS_SET (addr
) = get_varargs_alias_set ();
8153 t
= fold_convert (TREE_TYPE (reg
), size_int (max_reg
));
8154 t
= build2 (GT_EXPR
, boolean_type_node
, reg
, t
);
8155 u
= build1 (GOTO_EXPR
, void_type_node
, lab_false
);
8156 t
= build3 (COND_EXPR
, void_type_node
, t
, u
, NULL_TREE
);
8157 gimplify_and_add (t
, pre_p
);
8159 t
= build2 (POINTER_PLUS_EXPR
, ptr_type_node
, sav
,
8160 size_int (sav_ofs
));
8161 u
= build2 (MULT_EXPR
, TREE_TYPE (reg
), reg
,
8162 fold_convert (TREE_TYPE (reg
), size_int (sav_scale
)));
8163 t
= build2 (POINTER_PLUS_EXPR
, ptr_type_node
, t
, fold_convert (sizetype
, u
));
8165 t
= build2 (GIMPLE_MODIFY_STMT
, void_type_node
, addr
, t
);
8166 gimplify_and_add (t
, pre_p
);
8168 t
= build1 (GOTO_EXPR
, void_type_node
, lab_over
);
8169 gimplify_and_add (t
, pre_p
);
8171 t
= build1 (LABEL_EXPR
, void_type_node
, lab_false
);
8172 append_to_statement_list (t
, pre_p
);
8175 /* ... Otherwise out of the overflow area. */
8178 if (size
< UNITS_PER_WORD
)
8179 t
= build2 (POINTER_PLUS_EXPR
, ptr_type_node
, t
,
8180 size_int (UNITS_PER_WORD
- size
));
8182 gimplify_expr (&t
, pre_p
, NULL
, is_gimple_val
, fb_rvalue
);
8184 u
= build2 (GIMPLE_MODIFY_STMT
, void_type_node
, addr
, t
);
8185 gimplify_and_add (u
, pre_p
);
8187 t
= build2 (POINTER_PLUS_EXPR
, ptr_type_node
, t
,
8189 t
= build2 (GIMPLE_MODIFY_STMT
, ptr_type_node
, ovf
, t
);
8190 gimplify_and_add (t
, pre_p
);
8192 t
= build1 (LABEL_EXPR
, void_type_node
, lab_over
);
8193 append_to_statement_list (t
, pre_p
);
8196 /* Increment register save count. */
8198 u
= build2 (PREINCREMENT_EXPR
, TREE_TYPE (reg
), reg
,
8199 fold_convert (TREE_TYPE (reg
), size_int (n_reg
)));
8200 gimplify_and_add (u
, pre_p
);
8204 t
= build_pointer_type (build_pointer_type (type
));
8205 addr
= fold_convert (t
, addr
);
8206 addr
= build_va_arg_indirect_ref (addr
);
8210 t
= build_pointer_type (type
);
8211 addr
= fold_convert (t
, addr
);
8214 return build_va_arg_indirect_ref (addr
);
8222 S390_BUILTIN_THREAD_POINTER
,
8223 S390_BUILTIN_SET_THREAD_POINTER
,
8228 static unsigned int const code_for_builtin_64
[S390_BUILTIN_max
] = {
8233 static unsigned int const code_for_builtin_31
[S390_BUILTIN_max
] = {
8239 s390_init_builtins (void)
8243 ftype
= build_function_type (ptr_type_node
, void_list_node
);
8244 add_builtin_function ("__builtin_thread_pointer", ftype
,
8245 S390_BUILTIN_THREAD_POINTER
, BUILT_IN_MD
,
8248 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
8249 add_builtin_function ("__builtin_set_thread_pointer", ftype
,
8250 S390_BUILTIN_SET_THREAD_POINTER
, BUILT_IN_MD
,
8254 /* Expand an expression EXP that calls a built-in function,
8255 with result going to TARGET if that's convenient
8256 (and in mode MODE if that's convenient).
8257 SUBTARGET may be used as the target for computing one of EXP's operands.
8258 IGNORE is nonzero if the value is to be ignored. */
8261 s390_expand_builtin (tree exp
, rtx target
, rtx subtarget ATTRIBUTE_UNUSED
,
8262 enum machine_mode mode ATTRIBUTE_UNUSED
,
8263 int ignore ATTRIBUTE_UNUSED
)
8267 unsigned int const *code_for_builtin
=
8268 TARGET_64BIT
? code_for_builtin_64
: code_for_builtin_31
;
8270 tree fndecl
= TREE_OPERAND (CALL_EXPR_FN (exp
), 0);
8271 unsigned int fcode
= DECL_FUNCTION_CODE (fndecl
);
8272 enum insn_code icode
;
8273 rtx op
[MAX_ARGS
], pat
;
8277 call_expr_arg_iterator iter
;
8279 if (fcode
>= S390_BUILTIN_max
)
8280 internal_error ("bad builtin fcode");
8281 icode
= code_for_builtin
[fcode
];
8283 internal_error ("bad builtin fcode");
8285 nonvoid
= TREE_TYPE (TREE_TYPE (fndecl
)) != void_type_node
;
8288 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, exp
)
8290 const struct insn_operand_data
*insn_op
;
8292 if (arg
== error_mark_node
)
8294 if (arity
> MAX_ARGS
)
8297 insn_op
= &insn_data
[icode
].operand
[arity
+ nonvoid
];
8299 op
[arity
] = expand_expr (arg
, NULL_RTX
, insn_op
->mode
, 0);
8301 if (!(*insn_op
->predicate
) (op
[arity
], insn_op
->mode
))
8302 op
[arity
] = copy_to_mode_reg (insn_op
->mode
, op
[arity
]);
8308 enum machine_mode tmode
= insn_data
[icode
].operand
[0].mode
;
8310 || GET_MODE (target
) != tmode
8311 || !(*insn_data
[icode
].operand
[0].predicate
) (target
, tmode
))
8312 target
= gen_reg_rtx (tmode
);
8318 pat
= GEN_FCN (icode
) (target
);
8322 pat
= GEN_FCN (icode
) (target
, op
[0]);
8324 pat
= GEN_FCN (icode
) (op
[0]);
8327 pat
= GEN_FCN (icode
) (target
, op
[0], op
[1]);
8343 /* Output assembly code for the trampoline template to
8346 On S/390, we use gpr 1 internally in the trampoline code;
8347 gpr 0 is used to hold the static chain. */
8350 s390_trampoline_template (FILE *file
)
8353 op
[0] = gen_rtx_REG (Pmode
, 0);
8354 op
[1] = gen_rtx_REG (Pmode
, 1);
8358 output_asm_insn ("basr\t%1,0", op
);
8359 output_asm_insn ("lmg\t%0,%1,14(%1)", op
);
8360 output_asm_insn ("br\t%1", op
);
8361 ASM_OUTPUT_SKIP (file
, (HOST_WIDE_INT
)(TRAMPOLINE_SIZE
- 10));
8365 output_asm_insn ("basr\t%1,0", op
);
8366 output_asm_insn ("lm\t%0,%1,6(%1)", op
);
8367 output_asm_insn ("br\t%1", op
);
8368 ASM_OUTPUT_SKIP (file
, (HOST_WIDE_INT
)(TRAMPOLINE_SIZE
- 8));
8372 /* Emit RTL insns to initialize the variable parts of a trampoline.
8373 FNADDR is an RTX for the address of the function's pure code.
8374 CXT is an RTX for the static chain value for the function. */
8377 s390_initialize_trampoline (rtx addr
, rtx fnaddr
, rtx cxt
)
8379 emit_move_insn (gen_rtx_MEM (Pmode
,
8380 memory_address (Pmode
,
8381 plus_constant (addr
, (TARGET_64BIT
? 16 : 8)))), cxt
);
8382 emit_move_insn (gen_rtx_MEM (Pmode
,
8383 memory_address (Pmode
,
8384 plus_constant (addr
, (TARGET_64BIT
? 24 : 12)))), fnaddr
);
8387 /* Output assembler code to FILE to increment profiler label # LABELNO
8388 for profiling a function entry. */
8391 s390_function_profiler (FILE *file
, int labelno
)
8396 ASM_GENERATE_INTERNAL_LABEL (label
, "LP", labelno
);
8398 fprintf (file
, "# function profiler \n");
8400 op
[0] = gen_rtx_REG (Pmode
, RETURN_REGNUM
);
8401 op
[1] = gen_rtx_REG (Pmode
, STACK_POINTER_REGNUM
);
8402 op
[1] = gen_rtx_MEM (Pmode
, plus_constant (op
[1], UNITS_PER_WORD
));
8404 op
[2] = gen_rtx_REG (Pmode
, 1);
8405 op
[3] = gen_rtx_SYMBOL_REF (Pmode
, label
);
8406 SYMBOL_REF_FLAGS (op
[3]) = SYMBOL_FLAG_LOCAL
;
8408 op
[4] = gen_rtx_SYMBOL_REF (Pmode
, "_mcount");
8411 op
[4] = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op
[4]), UNSPEC_PLT
);
8412 op
[4] = gen_rtx_CONST (Pmode
, op
[4]);
8417 output_asm_insn ("stg\t%0,%1", op
);
8418 output_asm_insn ("larl\t%2,%3", op
);
8419 output_asm_insn ("brasl\t%0,%4", op
);
8420 output_asm_insn ("lg\t%0,%1", op
);
8424 op
[6] = gen_label_rtx ();
8426 output_asm_insn ("st\t%0,%1", op
);
8427 output_asm_insn ("bras\t%2,%l6", op
);
8428 output_asm_insn (".long\t%4", op
);
8429 output_asm_insn (".long\t%3", op
);
8430 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[6]));
8431 output_asm_insn ("l\t%0,0(%2)", op
);
8432 output_asm_insn ("l\t%2,4(%2)", op
);
8433 output_asm_insn ("basr\t%0,%0", op
);
8434 output_asm_insn ("l\t%0,%1", op
);
8438 op
[5] = gen_label_rtx ();
8439 op
[6] = gen_label_rtx ();
8441 output_asm_insn ("st\t%0,%1", op
);
8442 output_asm_insn ("bras\t%2,%l6", op
);
8443 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[5]));
8444 output_asm_insn (".long\t%4-%l5", op
);
8445 output_asm_insn (".long\t%3-%l5", op
);
8446 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[6]));
8447 output_asm_insn ("lr\t%0,%2", op
);
8448 output_asm_insn ("a\t%0,0(%2)", op
);
8449 output_asm_insn ("a\t%2,4(%2)", op
);
8450 output_asm_insn ("basr\t%0,%0", op
);
8451 output_asm_insn ("l\t%0,%1", op
);
8455 /* Encode symbol attributes (local vs. global, tls model) of a SYMBOL_REF
8456 into its SYMBOL_REF_FLAGS. */
8459 s390_encode_section_info (tree decl
, rtx rtl
, int first
)
8461 default_encode_section_info (decl
, rtl
, first
);
8463 /* If a variable has a forced alignment to < 2 bytes, mark it with
8464 SYMBOL_FLAG_ALIGN1 to prevent it from being used as LARL operand. */
8465 if (TREE_CODE (decl
) == VAR_DECL
8466 && DECL_USER_ALIGN (decl
) && DECL_ALIGN (decl
) < 16)
8467 SYMBOL_REF_FLAGS (XEXP (rtl
, 0)) |= SYMBOL_FLAG_ALIGN1
;
8470 /* Output thunk to FILE that implements a C++ virtual function call (with
8471 multiple inheritance) to FUNCTION. The thunk adjusts the this pointer
8472 by DELTA, and unless VCALL_OFFSET is zero, applies an additional adjustment
8473 stored at VCALL_OFFSET in the vtable whose address is located at offset 0
8474 relative to the resulting this pointer. */
8477 s390_output_mi_thunk (FILE *file
, tree thunk ATTRIBUTE_UNUSED
,
8478 HOST_WIDE_INT delta
, HOST_WIDE_INT vcall_offset
,
8484 /* Operand 0 is the target function. */
8485 op
[0] = XEXP (DECL_RTL (function
), 0);
8486 if (flag_pic
&& !SYMBOL_REF_LOCAL_P (op
[0]))
8489 op
[0] = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op
[0]),
8490 TARGET_64BIT
? UNSPEC_PLT
: UNSPEC_GOT
);
8491 op
[0] = gen_rtx_CONST (Pmode
, op
[0]);
8494 /* Operand 1 is the 'this' pointer. */
8495 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function
)), function
))
8496 op
[1] = gen_rtx_REG (Pmode
, 3);
8498 op
[1] = gen_rtx_REG (Pmode
, 2);
8500 /* Operand 2 is the delta. */
8501 op
[2] = GEN_INT (delta
);
8503 /* Operand 3 is the vcall_offset. */
8504 op
[3] = GEN_INT (vcall_offset
);
8506 /* Operand 4 is the temporary register. */
8507 op
[4] = gen_rtx_REG (Pmode
, 1);
8509 /* Operands 5 to 8 can be used as labels. */
8515 /* Operand 9 can be used for temporary register. */
8518 /* Generate code. */
8521 /* Setup literal pool pointer if required. */
8522 if ((!DISP_IN_RANGE (delta
)
8523 && !CONST_OK_FOR_K (delta
)
8524 && !CONST_OK_FOR_Os (delta
))
8525 || (!DISP_IN_RANGE (vcall_offset
)
8526 && !CONST_OK_FOR_K (vcall_offset
)
8527 && !CONST_OK_FOR_Os (vcall_offset
)))
8529 op
[5] = gen_label_rtx ();
8530 output_asm_insn ("larl\t%4,%5", op
);
8533 /* Add DELTA to this pointer. */
8536 if (CONST_OK_FOR_J (delta
))
8537 output_asm_insn ("la\t%1,%2(%1)", op
);
8538 else if (DISP_IN_RANGE (delta
))
8539 output_asm_insn ("lay\t%1,%2(%1)", op
);
8540 else if (CONST_OK_FOR_K (delta
))
8541 output_asm_insn ("aghi\t%1,%2", op
);
8542 else if (CONST_OK_FOR_Os (delta
))
8543 output_asm_insn ("agfi\t%1,%2", op
);
8546 op
[6] = gen_label_rtx ();
8547 output_asm_insn ("agf\t%1,%6-%5(%4)", op
);
8551 /* Perform vcall adjustment. */
8554 if (DISP_IN_RANGE (vcall_offset
))
8556 output_asm_insn ("lg\t%4,0(%1)", op
);
8557 output_asm_insn ("ag\t%1,%3(%4)", op
);
8559 else if (CONST_OK_FOR_K (vcall_offset
))
8561 output_asm_insn ("lghi\t%4,%3", op
);
8562 output_asm_insn ("ag\t%4,0(%1)", op
);
8563 output_asm_insn ("ag\t%1,0(%4)", op
);
8565 else if (CONST_OK_FOR_Os (vcall_offset
))
8567 output_asm_insn ("lgfi\t%4,%3", op
);
8568 output_asm_insn ("ag\t%4,0(%1)", op
);
8569 output_asm_insn ("ag\t%1,0(%4)", op
);
8573 op
[7] = gen_label_rtx ();
8574 output_asm_insn ("llgf\t%4,%7-%5(%4)", op
);
8575 output_asm_insn ("ag\t%4,0(%1)", op
);
8576 output_asm_insn ("ag\t%1,0(%4)", op
);
8580 /* Jump to target. */
8581 output_asm_insn ("jg\t%0", op
);
8583 /* Output literal pool if required. */
8586 output_asm_insn (".align\t4", op
);
8587 targetm
.asm_out
.internal_label (file
, "L",
8588 CODE_LABEL_NUMBER (op
[5]));
8592 targetm
.asm_out
.internal_label (file
, "L",
8593 CODE_LABEL_NUMBER (op
[6]));
8594 output_asm_insn (".long\t%2", op
);
8598 targetm
.asm_out
.internal_label (file
, "L",
8599 CODE_LABEL_NUMBER (op
[7]));
8600 output_asm_insn (".long\t%3", op
);
8605 /* Setup base pointer if required. */
8607 || (!DISP_IN_RANGE (delta
)
8608 && !CONST_OK_FOR_K (delta
)
8609 && !CONST_OK_FOR_Os (delta
))
8610 || (!DISP_IN_RANGE (delta
)
8611 && !CONST_OK_FOR_K (vcall_offset
)
8612 && !CONST_OK_FOR_Os (vcall_offset
)))
8614 op
[5] = gen_label_rtx ();
8615 output_asm_insn ("basr\t%4,0", op
);
8616 targetm
.asm_out
.internal_label (file
, "L",
8617 CODE_LABEL_NUMBER (op
[5]));
8620 /* Add DELTA to this pointer. */
8623 if (CONST_OK_FOR_J (delta
))
8624 output_asm_insn ("la\t%1,%2(%1)", op
);
8625 else if (DISP_IN_RANGE (delta
))
8626 output_asm_insn ("lay\t%1,%2(%1)", op
);
8627 else if (CONST_OK_FOR_K (delta
))
8628 output_asm_insn ("ahi\t%1,%2", op
);
8629 else if (CONST_OK_FOR_Os (delta
))
8630 output_asm_insn ("afi\t%1,%2", op
);
8633 op
[6] = gen_label_rtx ();
8634 output_asm_insn ("a\t%1,%6-%5(%4)", op
);
8638 /* Perform vcall adjustment. */
8641 if (CONST_OK_FOR_J (vcall_offset
))
8643 output_asm_insn ("l\t%4,0(%1)", op
);
8644 output_asm_insn ("a\t%1,%3(%4)", op
);
8646 else if (DISP_IN_RANGE (vcall_offset
))
8648 output_asm_insn ("l\t%4,0(%1)", op
);
8649 output_asm_insn ("ay\t%1,%3(%4)", op
);
8651 else if (CONST_OK_FOR_K (vcall_offset
))
8653 output_asm_insn ("lhi\t%4,%3", op
);
8654 output_asm_insn ("a\t%4,0(%1)", op
);
8655 output_asm_insn ("a\t%1,0(%4)", op
);
8657 else if (CONST_OK_FOR_Os (vcall_offset
))
8659 output_asm_insn ("iilf\t%4,%3", op
);
8660 output_asm_insn ("a\t%4,0(%1)", op
);
8661 output_asm_insn ("a\t%1,0(%4)", op
);
8665 op
[7] = gen_label_rtx ();
8666 output_asm_insn ("l\t%4,%7-%5(%4)", op
);
8667 output_asm_insn ("a\t%4,0(%1)", op
);
8668 output_asm_insn ("a\t%1,0(%4)", op
);
8671 /* We had to clobber the base pointer register.
8672 Re-setup the base pointer (with a different base). */
8673 op
[5] = gen_label_rtx ();
8674 output_asm_insn ("basr\t%4,0", op
);
8675 targetm
.asm_out
.internal_label (file
, "L",
8676 CODE_LABEL_NUMBER (op
[5]));
8679 /* Jump to target. */
8680 op
[8] = gen_label_rtx ();
8683 output_asm_insn ("l\t%4,%8-%5(%4)", op
);
8685 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
8686 /* We cannot call through .plt, since .plt requires %r12 loaded. */
8687 else if (flag_pic
== 1)
8689 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
8690 output_asm_insn ("l\t%4,%0(%4)", op
);
8692 else if (flag_pic
== 2)
8694 op
[9] = gen_rtx_REG (Pmode
, 0);
8695 output_asm_insn ("l\t%9,%8-4-%5(%4)", op
);
8696 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
8697 output_asm_insn ("ar\t%4,%9", op
);
8698 output_asm_insn ("l\t%4,0(%4)", op
);
8701 output_asm_insn ("br\t%4", op
);
8703 /* Output literal pool. */
8704 output_asm_insn (".align\t4", op
);
8706 if (nonlocal
&& flag_pic
== 2)
8707 output_asm_insn (".long\t%0", op
);
8710 op
[0] = gen_rtx_SYMBOL_REF (Pmode
, "_GLOBAL_OFFSET_TABLE_");
8711 SYMBOL_REF_FLAGS (op
[0]) = SYMBOL_FLAG_LOCAL
;
8714 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[8]));
8716 output_asm_insn (".long\t%0", op
);
8718 output_asm_insn (".long\t%0-%5", op
);
8722 targetm
.asm_out
.internal_label (file
, "L",
8723 CODE_LABEL_NUMBER (op
[6]));
8724 output_asm_insn (".long\t%2", op
);
8728 targetm
.asm_out
.internal_label (file
, "L",
8729 CODE_LABEL_NUMBER (op
[7]));
8730 output_asm_insn (".long\t%3", op
);
8736 s390_valid_pointer_mode (enum machine_mode mode
)
8738 return (mode
== SImode
|| (TARGET_64BIT
&& mode
== DImode
));
8741 /* Checks whether the given CALL_EXPR would use a caller
8742 saved register. This is used to decide whether sibling call
8743 optimization could be performed on the respective function
8747 s390_call_saved_register_used (tree call_expr
)
8749 CUMULATIVE_ARGS cum
;
8751 enum machine_mode mode
;
8756 INIT_CUMULATIVE_ARGS (cum
, NULL
, NULL
, 0, 0);
8758 for (i
= 0; i
< call_expr_nargs (call_expr
); i
++)
8760 parameter
= CALL_EXPR_ARG (call_expr
, i
);
8761 gcc_assert (parameter
);
8763 /* For an undeclared variable passed as parameter we will get
8764 an ERROR_MARK node here. */
8765 if (TREE_CODE (parameter
) == ERROR_MARK
)
8768 type
= TREE_TYPE (parameter
);
8771 mode
= TYPE_MODE (type
);
8774 if (pass_by_reference (&cum
, mode
, type
, true))
8777 type
= build_pointer_type (type
);
8780 parm_rtx
= s390_function_arg (&cum
, mode
, type
, 0);
8782 s390_function_arg_advance (&cum
, mode
, type
, 0);
8784 if (parm_rtx
&& REG_P (parm_rtx
))
8787 reg
< HARD_REGNO_NREGS (REGNO (parm_rtx
), GET_MODE (parm_rtx
));
8789 if (! call_used_regs
[reg
+ REGNO (parm_rtx
)])
8796 /* Return true if the given call expression can be
8797 turned into a sibling call.
8798 DECL holds the declaration of the function to be called whereas
8799 EXP is the call expression itself. */
8802 s390_function_ok_for_sibcall (tree decl
, tree exp
)
8804 /* The TPF epilogue uses register 1. */
8805 if (TARGET_TPF_PROFILING
)
8808 /* The 31 bit PLT code uses register 12 (GOT pointer - caller saved)
8809 which would have to be restored before the sibcall. */
8810 if (!TARGET_64BIT
&& flag_pic
&& decl
&& !targetm
.binds_local_p (decl
))
8813 /* Register 6 on s390 is available as an argument register but unfortunately
8814 "caller saved". This makes functions needing this register for arguments
8815 not suitable for sibcalls. */
8816 return !s390_call_saved_register_used (exp
);
8819 /* Return the fixed registers used for condition codes. */
8822 s390_fixed_condition_code_regs (unsigned int *p1
, unsigned int *p2
)
8825 *p2
= INVALID_REGNUM
;
8830 /* This function is used by the call expanders of the machine description.
8831 It emits the call insn itself together with the necessary operations
8832 to adjust the target address and returns the emitted insn.
8833 ADDR_LOCATION is the target address rtx
8834 TLS_CALL the location of the thread-local symbol
8835 RESULT_REG the register where the result of the call should be stored
8836 RETADDR_REG the register where the return address should be stored
8837 If this parameter is NULL_RTX the call is considered
8838 to be a sibling call. */
8841 s390_emit_call (rtx addr_location
, rtx tls_call
, rtx result_reg
,
8844 bool plt_call
= false;
8850 /* Direct function calls need special treatment. */
8851 if (GET_CODE (addr_location
) == SYMBOL_REF
)
8853 /* When calling a global routine in PIC mode, we must
8854 replace the symbol itself with the PLT stub. */
8855 if (flag_pic
&& !SYMBOL_REF_LOCAL_P (addr_location
))
8857 addr_location
= gen_rtx_UNSPEC (Pmode
,
8858 gen_rtvec (1, addr_location
),
8860 addr_location
= gen_rtx_CONST (Pmode
, addr_location
);
8864 /* Unless we can use the bras(l) insn, force the
8865 routine address into a register. */
8866 if (!TARGET_SMALL_EXEC
&& !TARGET_CPU_ZARCH
)
8869 addr_location
= legitimize_pic_address (addr_location
, 0);
8871 addr_location
= force_reg (Pmode
, addr_location
);
8875 /* If it is already an indirect call or the code above moved the
8876 SYMBOL_REF to somewhere else make sure the address can be found in
8878 if (retaddr_reg
== NULL_RTX
8879 && GET_CODE (addr_location
) != SYMBOL_REF
8882 emit_move_insn (gen_rtx_REG (Pmode
, SIBCALL_REGNUM
), addr_location
);
8883 addr_location
= gen_rtx_REG (Pmode
, SIBCALL_REGNUM
);
8886 addr_location
= gen_rtx_MEM (QImode
, addr_location
);
8887 call
= gen_rtx_CALL (VOIDmode
, addr_location
, const0_rtx
);
8889 if (result_reg
!= NULL_RTX
)
8890 call
= gen_rtx_SET (VOIDmode
, result_reg
, call
);
8892 if (retaddr_reg
!= NULL_RTX
)
8894 clobber
= gen_rtx_CLOBBER (VOIDmode
, retaddr_reg
);
8896 if (tls_call
!= NULL_RTX
)
8897 vec
= gen_rtvec (3, call
, clobber
,
8898 gen_rtx_USE (VOIDmode
, tls_call
));
8900 vec
= gen_rtvec (2, call
, clobber
);
8902 call
= gen_rtx_PARALLEL (VOIDmode
, vec
);
8905 insn
= emit_call_insn (call
);
8907 /* 31-bit PLT stubs and tls calls use the GOT register implicitly. */
8908 if ((!TARGET_64BIT
&& plt_call
) || tls_call
!= NULL_RTX
)
8910 /* s390_function_ok_for_sibcall should
8911 have denied sibcalls in this case. */
8912 gcc_assert (retaddr_reg
!= NULL_RTX
);
8914 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), pic_offset_table_rtx
);
8919 /* Implement CONDITIONAL_REGISTER_USAGE. */
8922 s390_conditional_register_usage (void)
8928 fixed_regs
[PIC_OFFSET_TABLE_REGNUM
] = 1;
8929 call_used_regs
[PIC_OFFSET_TABLE_REGNUM
] = 1;
8931 if (TARGET_CPU_ZARCH
)
8933 fixed_regs
[BASE_REGNUM
] = 0;
8934 call_used_regs
[BASE_REGNUM
] = 0;
8935 fixed_regs
[RETURN_REGNUM
] = 0;
8936 call_used_regs
[RETURN_REGNUM
] = 0;
8940 for (i
= 24; i
< 32; i
++)
8941 call_used_regs
[i
] = call_really_used_regs
[i
] = 0;
8945 for (i
= 18; i
< 20; i
++)
8946 call_used_regs
[i
] = call_really_used_regs
[i
] = 0;
8949 if (TARGET_SOFT_FLOAT
)
8951 for (i
= 16; i
< 32; i
++)
8952 call_used_regs
[i
] = fixed_regs
[i
] = 1;
8956 /* Corresponding function to eh_return expander. */
8958 static GTY(()) rtx s390_tpf_eh_return_symbol
;
8960 s390_emit_tpf_eh_return (rtx target
)
8964 if (!s390_tpf_eh_return_symbol
)
8965 s390_tpf_eh_return_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "__tpf_eh_return");
8967 reg
= gen_rtx_REG (Pmode
, 2);
8969 emit_move_insn (reg
, target
);
8970 insn
= s390_emit_call (s390_tpf_eh_return_symbol
, NULL_RTX
, reg
,
8971 gen_rtx_REG (Pmode
, RETURN_REGNUM
));
8972 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), reg
);
8974 emit_move_insn (EH_RETURN_HANDLER_RTX
, reg
);
8977 /* Rework the prologue/epilogue to avoid saving/restoring
8978 registers unnecessarily. */
8981 s390_optimize_prologue (void)
8983 rtx insn
, new_insn
, next_insn
;
8985 /* Do a final recompute of the frame-related data. */
8987 s390_update_frame_layout ();
8989 /* If all special registers are in fact used, there's nothing we
8990 can do, so no point in walking the insn list. */
8992 if (cfun_frame_layout
.first_save_gpr
<= BASE_REGNUM
8993 && cfun_frame_layout
.last_save_gpr
>= BASE_REGNUM
8994 && (TARGET_CPU_ZARCH
8995 || (cfun_frame_layout
.first_save_gpr
<= RETURN_REGNUM
8996 && cfun_frame_layout
.last_save_gpr
>= RETURN_REGNUM
)))
8999 /* Search for prologue/epilogue insns and replace them. */
9001 for (insn
= get_insns (); insn
; insn
= next_insn
)
9003 int first
, last
, off
;
9004 rtx set
, base
, offset
;
9006 next_insn
= NEXT_INSN (insn
);
9008 if (GET_CODE (insn
) != INSN
)
9011 if (GET_CODE (PATTERN (insn
)) == PARALLEL
9012 && store_multiple_operation (PATTERN (insn
), VOIDmode
))
9014 set
= XVECEXP (PATTERN (insn
), 0, 0);
9015 first
= REGNO (SET_SRC (set
));
9016 last
= first
+ XVECLEN (PATTERN (insn
), 0) - 1;
9017 offset
= const0_rtx
;
9018 base
= eliminate_constant_term (XEXP (SET_DEST (set
), 0), &offset
);
9019 off
= INTVAL (offset
);
9021 if (GET_CODE (base
) != REG
|| off
< 0)
9023 if (cfun_frame_layout
.first_save_gpr
!= -1
9024 && (cfun_frame_layout
.first_save_gpr
< first
9025 || cfun_frame_layout
.last_save_gpr
> last
))
9027 if (REGNO (base
) != STACK_POINTER_REGNUM
9028 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
9030 if (first
> BASE_REGNUM
|| last
< BASE_REGNUM
)
9033 if (cfun_frame_layout
.first_save_gpr
!= -1)
9035 new_insn
= save_gprs (base
,
9036 off
+ (cfun_frame_layout
.first_save_gpr
9037 - first
) * UNITS_PER_WORD
,
9038 cfun_frame_layout
.first_save_gpr
,
9039 cfun_frame_layout
.last_save_gpr
);
9040 new_insn
= emit_insn_before (new_insn
, insn
);
9041 INSN_ADDRESSES_NEW (new_insn
, -1);
9048 if (cfun_frame_layout
.first_save_gpr
== -1
9049 && GET_CODE (PATTERN (insn
)) == SET
9050 && GET_CODE (SET_SRC (PATTERN (insn
))) == REG
9051 && (REGNO (SET_SRC (PATTERN (insn
))) == BASE_REGNUM
9052 || (!TARGET_CPU_ZARCH
9053 && REGNO (SET_SRC (PATTERN (insn
))) == RETURN_REGNUM
))
9054 && GET_CODE (SET_DEST (PATTERN (insn
))) == MEM
)
9056 set
= PATTERN (insn
);
9057 first
= REGNO (SET_SRC (set
));
9058 offset
= const0_rtx
;
9059 base
= eliminate_constant_term (XEXP (SET_DEST (set
), 0), &offset
);
9060 off
= INTVAL (offset
);
9062 if (GET_CODE (base
) != REG
|| off
< 0)
9064 if (REGNO (base
) != STACK_POINTER_REGNUM
9065 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
9072 if (GET_CODE (PATTERN (insn
)) == PARALLEL
9073 && load_multiple_operation (PATTERN (insn
), VOIDmode
))
9075 set
= XVECEXP (PATTERN (insn
), 0, 0);
9076 first
= REGNO (SET_DEST (set
));
9077 last
= first
+ XVECLEN (PATTERN (insn
), 0) - 1;
9078 offset
= const0_rtx
;
9079 base
= eliminate_constant_term (XEXP (SET_SRC (set
), 0), &offset
);
9080 off
= INTVAL (offset
);
9082 if (GET_CODE (base
) != REG
|| off
< 0)
9084 if (cfun_frame_layout
.first_restore_gpr
!= -1
9085 && (cfun_frame_layout
.first_restore_gpr
< first
9086 || cfun_frame_layout
.last_restore_gpr
> last
))
9088 if (REGNO (base
) != STACK_POINTER_REGNUM
9089 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
9091 if (first
> BASE_REGNUM
|| last
< BASE_REGNUM
)
9094 if (cfun_frame_layout
.first_restore_gpr
!= -1)
9096 new_insn
= restore_gprs (base
,
9097 off
+ (cfun_frame_layout
.first_restore_gpr
9098 - first
) * UNITS_PER_WORD
,
9099 cfun_frame_layout
.first_restore_gpr
,
9100 cfun_frame_layout
.last_restore_gpr
);
9101 new_insn
= emit_insn_before (new_insn
, insn
);
9102 INSN_ADDRESSES_NEW (new_insn
, -1);
9109 if (cfun_frame_layout
.first_restore_gpr
== -1
9110 && GET_CODE (PATTERN (insn
)) == SET
9111 && GET_CODE (SET_DEST (PATTERN (insn
))) == REG
9112 && (REGNO (SET_DEST (PATTERN (insn
))) == BASE_REGNUM
9113 || (!TARGET_CPU_ZARCH
9114 && REGNO (SET_DEST (PATTERN (insn
))) == RETURN_REGNUM
))
9115 && GET_CODE (SET_SRC (PATTERN (insn
))) == MEM
)
9117 set
= PATTERN (insn
);
9118 first
= REGNO (SET_DEST (set
));
9119 offset
= const0_rtx
;
9120 base
= eliminate_constant_term (XEXP (SET_SRC (set
), 0), &offset
);
9121 off
= INTVAL (offset
);
9123 if (GET_CODE (base
) != REG
|| off
< 0)
9125 if (REGNO (base
) != STACK_POINTER_REGNUM
9126 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
9135 /* Perform machine-dependent processing. */
9140 bool pool_overflow
= false;
9142 /* Make sure all splits have been performed; splits after
9143 machine_dependent_reorg might confuse insn length counts. */
9144 split_all_insns_noflow ();
9146 /* From here on decomposed literal pool addresses must be accepted. */
9147 cfun
->machine
->decomposed_literal_pool_addresses_ok_p
= true;
9149 /* Install the main literal pool and the associated base
9150 register load insns.
9152 In addition, there are two problematic situations we need
9155 - the literal pool might be > 4096 bytes in size, so that
9156 some of its elements cannot be directly accessed
9158 - a branch target might be > 64K away from the branch, so that
9159 it is not possible to use a PC-relative instruction.
9161 To fix those, we split the single literal pool into multiple
9162 pool chunks, reloading the pool base register at various
9163 points throughout the function to ensure it always points to
9164 the pool chunk the following code expects, and / or replace
9165 PC-relative branches by absolute branches.
9167 However, the two problems are interdependent: splitting the
9168 literal pool can move a branch further away from its target,
9169 causing the 64K limit to overflow, and on the other hand,
9170 replacing a PC-relative branch by an absolute branch means
9171 we need to put the branch target address into the literal
9172 pool, possibly causing it to overflow.
9174 So, we loop trying to fix up both problems until we manage
9175 to satisfy both conditions at the same time. Note that the
9176 loop is guaranteed to terminate as every pass of the loop
9177 strictly decreases the total number of PC-relative branches
9178 in the function. (This is not completely true as there
9179 might be branch-over-pool insns introduced by chunkify_start.
9180 Those never need to be split however.) */
9184 struct constant_pool
*pool
= NULL
;
9186 /* Collect the literal pool. */
9189 pool
= s390_mainpool_start ();
9191 pool_overflow
= true;
9194 /* If literal pool overflowed, start to chunkify it. */
9196 pool
= s390_chunkify_start ();
9198 /* Split out-of-range branches. If this has created new
9199 literal pool entries, cancel current chunk list and
9200 recompute it. zSeries machines have large branch
9201 instructions, so we never need to split a branch. */
9202 if (!TARGET_CPU_ZARCH
&& s390_split_branches ())
9205 s390_chunkify_cancel (pool
);
9207 s390_mainpool_cancel (pool
);
9212 /* If we made it up to here, both conditions are satisfied.
9213 Finish up literal pool related changes. */
9215 s390_chunkify_finish (pool
);
9217 s390_mainpool_finish (pool
);
9219 /* We're done splitting branches. */
9220 cfun
->machine
->split_branches_pending_p
= false;
9224 /* Generate out-of-pool execute target insns. */
9225 if (TARGET_CPU_ZARCH
)
9227 rtx insn
, label
, target
;
9229 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
9231 label
= s390_execute_label (insn
);
9235 gcc_assert (label
!= const0_rtx
);
9237 target
= emit_label (XEXP (label
, 0));
9238 INSN_ADDRESSES_NEW (target
, -1);
9240 target
= emit_insn (s390_execute_target (insn
));
9241 INSN_ADDRESSES_NEW (target
, -1);
9245 /* Try to optimize prologue and epilogue further. */
9246 s390_optimize_prologue ();
9250 /* Initialize GCC target structure. */
9252 #undef TARGET_ASM_ALIGNED_HI_OP
9253 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
9254 #undef TARGET_ASM_ALIGNED_DI_OP
9255 #define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
9256 #undef TARGET_ASM_INTEGER
9257 #define TARGET_ASM_INTEGER s390_assemble_integer
9259 #undef TARGET_ASM_OPEN_PAREN
9260 #define TARGET_ASM_OPEN_PAREN ""
9262 #undef TARGET_ASM_CLOSE_PAREN
9263 #define TARGET_ASM_CLOSE_PAREN ""
9265 #undef TARGET_DEFAULT_TARGET_FLAGS
9266 #define TARGET_DEFAULT_TARGET_FLAGS (TARGET_DEFAULT | MASK_FUSED_MADD)
9267 #undef TARGET_HANDLE_OPTION
9268 #define TARGET_HANDLE_OPTION s390_handle_option
9270 #undef TARGET_ENCODE_SECTION_INFO
9271 #define TARGET_ENCODE_SECTION_INFO s390_encode_section_info
9274 #undef TARGET_HAVE_TLS
9275 #define TARGET_HAVE_TLS true
9277 #undef TARGET_CANNOT_FORCE_CONST_MEM
9278 #define TARGET_CANNOT_FORCE_CONST_MEM s390_cannot_force_const_mem
9280 #undef TARGET_DELEGITIMIZE_ADDRESS
9281 #define TARGET_DELEGITIMIZE_ADDRESS s390_delegitimize_address
9283 #undef TARGET_RETURN_IN_MEMORY
9284 #define TARGET_RETURN_IN_MEMORY s390_return_in_memory
9286 #undef TARGET_INIT_BUILTINS
9287 #define TARGET_INIT_BUILTINS s390_init_builtins
9288 #undef TARGET_EXPAND_BUILTIN
9289 #define TARGET_EXPAND_BUILTIN s390_expand_builtin
9291 #undef TARGET_ASM_OUTPUT_MI_THUNK
9292 #define TARGET_ASM_OUTPUT_MI_THUNK s390_output_mi_thunk
9293 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
9294 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
9296 #undef TARGET_SCHED_ADJUST_PRIORITY
9297 #define TARGET_SCHED_ADJUST_PRIORITY s390_adjust_priority
9298 #undef TARGET_SCHED_ISSUE_RATE
9299 #define TARGET_SCHED_ISSUE_RATE s390_issue_rate
9300 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
9301 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD s390_first_cycle_multipass_dfa_lookahead
9303 #undef TARGET_CANNOT_COPY_INSN_P
9304 #define TARGET_CANNOT_COPY_INSN_P s390_cannot_copy_insn_p
9305 #undef TARGET_RTX_COSTS
9306 #define TARGET_RTX_COSTS s390_rtx_costs
9307 #undef TARGET_ADDRESS_COST
9308 #define TARGET_ADDRESS_COST s390_address_cost
9310 #undef TARGET_MACHINE_DEPENDENT_REORG
9311 #define TARGET_MACHINE_DEPENDENT_REORG s390_reorg
9313 #undef TARGET_VALID_POINTER_MODE
9314 #define TARGET_VALID_POINTER_MODE s390_valid_pointer_mode
9316 #undef TARGET_BUILD_BUILTIN_VA_LIST
9317 #define TARGET_BUILD_BUILTIN_VA_LIST s390_build_builtin_va_list
9318 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
9319 #define TARGET_GIMPLIFY_VA_ARG_EXPR s390_gimplify_va_arg
9321 #undef TARGET_PROMOTE_FUNCTION_ARGS
9322 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
9323 #undef TARGET_PROMOTE_FUNCTION_RETURN
9324 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
9325 #undef TARGET_PASS_BY_REFERENCE
9326 #define TARGET_PASS_BY_REFERENCE s390_pass_by_reference
9328 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
9329 #define TARGET_FUNCTION_OK_FOR_SIBCALL s390_function_ok_for_sibcall
9331 #undef TARGET_FIXED_CONDITION_CODE_REGS
9332 #define TARGET_FIXED_CONDITION_CODE_REGS s390_fixed_condition_code_regs
9334 #undef TARGET_CC_MODES_COMPATIBLE
9335 #define TARGET_CC_MODES_COMPATIBLE s390_cc_modes_compatible
9337 #undef TARGET_INVALID_WITHIN_DOLOOP
9338 #define TARGET_INVALID_WITHIN_DOLOOP hook_constcharptr_rtx_null
9341 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
9342 #define TARGET_ASM_OUTPUT_DWARF_DTPREL s390_output_dwarf_dtprel
9345 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
9346 #undef TARGET_MANGLE_TYPE
9347 #define TARGET_MANGLE_TYPE s390_mangle_type
9350 #undef TARGET_SCALAR_MODE_SUPPORTED_P
9351 #define TARGET_SCALAR_MODE_SUPPORTED_P s390_scalar_mode_supported_p
9353 #undef TARGET_SECONDARY_RELOAD
9354 #define TARGET_SECONDARY_RELOAD s390_secondary_reload
9356 #undef TARGET_LIBGCC_CMP_RETURN_MODE
9357 #define TARGET_LIBGCC_CMP_RETURN_MODE s390_libgcc_cmp_return_mode
9359 #undef TARGET_LIBGCC_SHIFT_COUNT_MODE
9360 #define TARGET_LIBGCC_SHIFT_COUNT_MODE s390_libgcc_shift_count_mode
9362 struct gcc_target targetm
= TARGET_INITIALIZER
;
9364 #include "gt-s390.h"