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 3, 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 COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
25 #include "coretypes.h"
31 #include "hard-reg-set.h"
33 #include "insn-config.h"
34 #include "conditions.h"
36 #include "insn-attr.h"
44 #include "basic-block.h"
45 #include "integrate.h"
48 #include "target-def.h"
50 #include "langhooks.h"
52 #include "tree-gimple.h"
56 /* Define the specific costs for a given cpu. */
58 struct processor_costs
61 const int m
; /* cost of an M instruction. */
62 const int mghi
; /* cost of an MGHI instruction. */
63 const int mh
; /* cost of an MH instruction. */
64 const int mhi
; /* cost of an MHI instruction. */
65 const int ml
; /* cost of an ML instruction. */
66 const int mr
; /* cost of an MR instruction. */
67 const int ms
; /* cost of an MS instruction. */
68 const int msg
; /* cost of an MSG instruction. */
69 const int msgf
; /* cost of an MSGF instruction. */
70 const int msgfr
; /* cost of an MSGFR instruction. */
71 const int msgr
; /* cost of an MSGR instruction. */
72 const int msr
; /* cost of an MSR instruction. */
73 const int mult_df
; /* cost of multiplication in DFmode. */
76 const int sqxbr
; /* cost of square root in TFmode. */
77 const int sqdbr
; /* cost of square root in DFmode. */
78 const int sqebr
; /* cost of square root in SFmode. */
79 /* multiply and add */
80 const int madbr
; /* cost of multiply and add in DFmode. */
81 const int maebr
; /* cost of multiply and add in SFmode. */
93 const struct processor_costs
*s390_cost
;
96 struct processor_costs z900_cost
=
98 COSTS_N_INSNS (5), /* M */
99 COSTS_N_INSNS (10), /* MGHI */
100 COSTS_N_INSNS (5), /* MH */
101 COSTS_N_INSNS (4), /* MHI */
102 COSTS_N_INSNS (5), /* ML */
103 COSTS_N_INSNS (5), /* MR */
104 COSTS_N_INSNS (4), /* MS */
105 COSTS_N_INSNS (15), /* MSG */
106 COSTS_N_INSNS (7), /* MSGF */
107 COSTS_N_INSNS (7), /* MSGFR */
108 COSTS_N_INSNS (10), /* MSGR */
109 COSTS_N_INSNS (4), /* MSR */
110 COSTS_N_INSNS (7), /* multiplication in DFmode */
111 COSTS_N_INSNS (13), /* MXBR */
112 COSTS_N_INSNS (136), /* SQXBR */
113 COSTS_N_INSNS (44), /* SQDBR */
114 COSTS_N_INSNS (35), /* SQEBR */
115 COSTS_N_INSNS (18), /* MADBR */
116 COSTS_N_INSNS (13), /* MAEBR */
117 COSTS_N_INSNS (134), /* DXBR */
118 COSTS_N_INSNS (30), /* DDBR */
119 COSTS_N_INSNS (27), /* DEBR */
120 COSTS_N_INSNS (220), /* DLGR */
121 COSTS_N_INSNS (34), /* DLR */
122 COSTS_N_INSNS (34), /* DR */
123 COSTS_N_INSNS (32), /* DSGFR */
124 COSTS_N_INSNS (32), /* DSGR */
128 struct processor_costs z990_cost
=
130 COSTS_N_INSNS (4), /* M */
131 COSTS_N_INSNS (2), /* MGHI */
132 COSTS_N_INSNS (2), /* MH */
133 COSTS_N_INSNS (2), /* MHI */
134 COSTS_N_INSNS (4), /* ML */
135 COSTS_N_INSNS (4), /* MR */
136 COSTS_N_INSNS (5), /* MS */
137 COSTS_N_INSNS (6), /* MSG */
138 COSTS_N_INSNS (4), /* MSGF */
139 COSTS_N_INSNS (4), /* MSGFR */
140 COSTS_N_INSNS (4), /* MSGR */
141 COSTS_N_INSNS (4), /* MSR */
142 COSTS_N_INSNS (1), /* multiplication in DFmode */
143 COSTS_N_INSNS (28), /* MXBR */
144 COSTS_N_INSNS (130), /* SQXBR */
145 COSTS_N_INSNS (66), /* SQDBR */
146 COSTS_N_INSNS (38), /* SQEBR */
147 COSTS_N_INSNS (1), /* MADBR */
148 COSTS_N_INSNS (1), /* MAEBR */
149 COSTS_N_INSNS (60), /* DXBR */
150 COSTS_N_INSNS (40), /* DDBR */
151 COSTS_N_INSNS (26), /* DEBR */
152 COSTS_N_INSNS (176), /* DLGR */
153 COSTS_N_INSNS (31), /* DLR */
154 COSTS_N_INSNS (31), /* DR */
155 COSTS_N_INSNS (31), /* DSGFR */
156 COSTS_N_INSNS (31), /* DSGR */
160 struct processor_costs z9_109_cost
=
162 COSTS_N_INSNS (4), /* M */
163 COSTS_N_INSNS (2), /* MGHI */
164 COSTS_N_INSNS (2), /* MH */
165 COSTS_N_INSNS (2), /* MHI */
166 COSTS_N_INSNS (4), /* ML */
167 COSTS_N_INSNS (4), /* MR */
168 COSTS_N_INSNS (5), /* MS */
169 COSTS_N_INSNS (6), /* MSG */
170 COSTS_N_INSNS (4), /* MSGF */
171 COSTS_N_INSNS (4), /* MSGFR */
172 COSTS_N_INSNS (4), /* MSGR */
173 COSTS_N_INSNS (4), /* MSR */
174 COSTS_N_INSNS (1), /* multiplication in DFmode */
175 COSTS_N_INSNS (28), /* MXBR */
176 COSTS_N_INSNS (130), /* SQXBR */
177 COSTS_N_INSNS (66), /* SQDBR */
178 COSTS_N_INSNS (38), /* SQEBR */
179 COSTS_N_INSNS (1), /* MADBR */
180 COSTS_N_INSNS (1), /* MAEBR */
181 COSTS_N_INSNS (60), /* DXBR */
182 COSTS_N_INSNS (40), /* DDBR */
183 COSTS_N_INSNS (26), /* DEBR */
184 COSTS_N_INSNS (30), /* DLGR */
185 COSTS_N_INSNS (23), /* DLR */
186 COSTS_N_INSNS (23), /* DR */
187 COSTS_N_INSNS (24), /* DSGFR */
188 COSTS_N_INSNS (24), /* DSGR */
192 struct processor_costs z10_cost
=
194 COSTS_N_INSNS (4), /* M */
195 COSTS_N_INSNS (2), /* MGHI */
196 COSTS_N_INSNS (2), /* MH */
197 COSTS_N_INSNS (2), /* MHI */
198 COSTS_N_INSNS (4), /* ML */
199 COSTS_N_INSNS (4), /* MR */
200 COSTS_N_INSNS (5), /* MS */
201 COSTS_N_INSNS (6), /* MSG */
202 COSTS_N_INSNS (4), /* MSGF */
203 COSTS_N_INSNS (4), /* MSGFR */
204 COSTS_N_INSNS (4), /* MSGR */
205 COSTS_N_INSNS (4), /* MSR */
206 COSTS_N_INSNS (1), /* multiplication in DFmode */
207 COSTS_N_INSNS (28), /* MXBR */
208 COSTS_N_INSNS (130), /* SQXBR */
209 COSTS_N_INSNS (66), /* SQDBR */
210 COSTS_N_INSNS (38), /* SQEBR */
211 COSTS_N_INSNS (1), /* MADBR */
212 COSTS_N_INSNS (1), /* MAEBR */
213 COSTS_N_INSNS (60), /* DXBR */
214 COSTS_N_INSNS (40), /* DDBR */
215 COSTS_N_INSNS (26), /* DEBR */
216 COSTS_N_INSNS (30), /* DLGR */
217 COSTS_N_INSNS (23), /* DLR */
218 COSTS_N_INSNS (23), /* DR */
219 COSTS_N_INSNS (24), /* DSGFR */
220 COSTS_N_INSNS (24), /* DSGR */
223 extern int reload_completed
;
225 /* Save information from a "cmpxx" operation until the branch or scc is
227 rtx s390_compare_op0
, s390_compare_op1
;
229 /* Save the result of a compare_and_swap until the branch or scc is
231 rtx s390_compare_emitted
= NULL_RTX
;
233 /* Structure used to hold the components of a S/390 memory
234 address. A legitimate address on S/390 is of the general
236 base + index + displacement
237 where any of the components is optional.
239 base and index are registers of the class ADDR_REGS,
240 displacement is an unsigned 12-bit immediate constant. */
251 /* Which cpu are we tuning for. */
252 enum processor_type s390_tune
= PROCESSOR_max
;
253 enum processor_flags s390_tune_flags
;
254 /* Which instruction set architecture to use. */
255 enum processor_type s390_arch
;
256 enum processor_flags s390_arch_flags
;
258 HOST_WIDE_INT s390_warn_framesize
= 0;
259 HOST_WIDE_INT s390_stack_size
= 0;
260 HOST_WIDE_INT s390_stack_guard
= 0;
262 /* The following structure is embedded in the machine
263 specific part of struct function. */
265 struct s390_frame_layout
GTY (())
267 /* Offset within stack frame. */
268 HOST_WIDE_INT gprs_offset
;
269 HOST_WIDE_INT f0_offset
;
270 HOST_WIDE_INT f4_offset
;
271 HOST_WIDE_INT f8_offset
;
272 HOST_WIDE_INT backchain_offset
;
274 /* Number of first and last gpr where slots in the register
275 save area are reserved for. */
276 int first_save_gpr_slot
;
277 int last_save_gpr_slot
;
279 /* Number of first and last gpr to be saved, restored. */
281 int first_restore_gpr
;
283 int last_restore_gpr
;
285 /* Bits standing for floating point registers. Set, if the
286 respective register has to be saved. Starting with reg 16 (f0)
287 at the rightmost bit.
288 Bit 15 - 8 7 6 5 4 3 2 1 0
289 fpr 15 - 8 7 5 3 1 6 4 2 0
290 reg 31 - 24 23 22 21 20 19 18 17 16 */
291 unsigned int fpr_bitmap
;
293 /* Number of floating point registers f8-f15 which must be saved. */
296 /* Set if return address needs to be saved.
297 This flag is set by s390_return_addr_rtx if it could not use
298 the initial value of r14 and therefore depends on r14 saved
300 bool save_return_addr_p
;
302 /* Size of stack frame. */
303 HOST_WIDE_INT frame_size
;
306 /* Define the structure for the machine field in struct function. */
308 struct machine_function
GTY(())
310 struct s390_frame_layout frame_layout
;
312 /* Literal pool base register. */
315 /* True if we may need to perform branch splitting. */
316 bool split_branches_pending_p
;
318 /* True during final stage of literal pool processing. */
319 bool decomposed_literal_pool_addresses_ok_p
;
321 /* Some local-dynamic TLS symbol name. */
322 const char *some_ld_name
;
324 bool has_landing_pad_p
;
327 /* Few accessor macros for struct cfun->machine->s390_frame_layout. */
329 #define cfun_frame_layout (cfun->machine->frame_layout)
330 #define cfun_save_high_fprs_p (!!cfun_frame_layout.high_fprs)
331 #define cfun_gprs_save_area_size ((cfun_frame_layout.last_save_gpr_slot - \
332 cfun_frame_layout.first_save_gpr_slot + 1) * UNITS_PER_WORD)
333 #define cfun_set_fpr_bit(BITNUM) (cfun->machine->frame_layout.fpr_bitmap |= \
335 #define cfun_fpr_bit_p(BITNUM) (!!(cfun->machine->frame_layout.fpr_bitmap & \
338 /* Number of GPRs and FPRs used for argument passing. */
339 #define GP_ARG_NUM_REG 5
340 #define FP_ARG_NUM_REG (TARGET_64BIT? 4 : 2)
342 /* A couple of shortcuts. */
343 #define CONST_OK_FOR_J(x) \
344 CONST_OK_FOR_CONSTRAINT_P((x), 'J', "J")
345 #define CONST_OK_FOR_K(x) \
346 CONST_OK_FOR_CONSTRAINT_P((x), 'K', "K")
347 #define CONST_OK_FOR_Os(x) \
348 CONST_OK_FOR_CONSTRAINT_P((x), 'O', "Os")
349 #define CONST_OK_FOR_Op(x) \
350 CONST_OK_FOR_CONSTRAINT_P((x), 'O', "Op")
351 #define CONST_OK_FOR_On(x) \
352 CONST_OK_FOR_CONSTRAINT_P((x), 'O', "On")
354 #define REGNO_PAIR_OK(REGNO, MODE) \
355 (HARD_REGNO_NREGS ((REGNO), (MODE)) == 1 || !((REGNO) & 1))
357 static enum machine_mode
358 s390_libgcc_cmp_return_mode (void)
360 return TARGET_64BIT
? DImode
: SImode
;
363 static enum machine_mode
364 s390_libgcc_shift_count_mode (void)
366 return TARGET_64BIT
? DImode
: SImode
;
369 /* Return true if the back end supports mode MODE. */
371 s390_scalar_mode_supported_p (enum machine_mode mode
)
373 if (DECIMAL_FLOAT_MODE_P (mode
))
376 return default_scalar_mode_supported_p (mode
);
379 /* Set the has_landing_pad_p flag in struct machine_function to VALUE. */
382 s390_set_has_landing_pad_p (bool value
)
384 cfun
->machine
->has_landing_pad_p
= value
;
387 /* If two condition code modes are compatible, return a condition code
388 mode which is compatible with both. Otherwise, return
391 static enum machine_mode
392 s390_cc_modes_compatible (enum machine_mode m1
, enum machine_mode m2
)
400 if (m2
== CCUmode
|| m2
== CCTmode
|| m2
== CCZ1mode
401 || m2
== CCSmode
|| m2
== CCSRmode
|| m2
== CCURmode
)
422 /* Return true if SET either doesn't set the CC register, or else
423 the source and destination have matching CC modes and that
424 CC mode is at least as constrained as REQ_MODE. */
427 s390_match_ccmode_set (rtx set
, enum machine_mode req_mode
)
429 enum machine_mode set_mode
;
431 gcc_assert (GET_CODE (set
) == SET
);
433 if (GET_CODE (SET_DEST (set
)) != REG
|| !CC_REGNO_P (REGNO (SET_DEST (set
))))
436 set_mode
= GET_MODE (SET_DEST (set
));
450 if (req_mode
!= set_mode
)
455 if (req_mode
!= CCSmode
&& req_mode
!= CCUmode
&& req_mode
!= CCTmode
456 && req_mode
!= CCSRmode
&& req_mode
!= CCURmode
)
462 if (req_mode
!= CCAmode
)
470 return (GET_MODE (SET_SRC (set
)) == set_mode
);
473 /* Return true if every SET in INSN that sets the CC register
474 has source and destination with matching CC modes and that
475 CC mode is at least as constrained as REQ_MODE.
476 If REQ_MODE is VOIDmode, always return false. */
479 s390_match_ccmode (rtx insn
, enum machine_mode req_mode
)
483 /* s390_tm_ccmode returns VOIDmode to indicate failure. */
484 if (req_mode
== VOIDmode
)
487 if (GET_CODE (PATTERN (insn
)) == SET
)
488 return s390_match_ccmode_set (PATTERN (insn
), req_mode
);
490 if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
491 for (i
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
493 rtx set
= XVECEXP (PATTERN (insn
), 0, i
);
494 if (GET_CODE (set
) == SET
)
495 if (!s390_match_ccmode_set (set
, req_mode
))
502 /* If a test-under-mask instruction can be used to implement
503 (compare (and ... OP1) OP2), return the CC mode required
504 to do that. Otherwise, return VOIDmode.
505 MIXED is true if the instruction can distinguish between
506 CC1 and CC2 for mixed selected bits (TMxx), it is false
507 if the instruction cannot (TM). */
510 s390_tm_ccmode (rtx op1
, rtx op2
, bool mixed
)
514 /* ??? Fixme: should work on CONST_DOUBLE as well. */
515 if (GET_CODE (op1
) != CONST_INT
|| GET_CODE (op2
) != CONST_INT
)
518 /* Selected bits all zero: CC0.
519 e.g.: int a; if ((a & (16 + 128)) == 0) */
520 if (INTVAL (op2
) == 0)
523 /* Selected bits all one: CC3.
524 e.g.: int a; if ((a & (16 + 128)) == 16 + 128) */
525 if (INTVAL (op2
) == INTVAL (op1
))
528 /* Exactly two bits selected, mixed zeroes and ones: CC1 or CC2. e.g.:
530 if ((a & (16 + 128)) == 16) -> CCT1
531 if ((a & (16 + 128)) == 128) -> CCT2 */
534 bit1
= exact_log2 (INTVAL (op2
));
535 bit0
= exact_log2 (INTVAL (op1
) ^ INTVAL (op2
));
536 if (bit0
!= -1 && bit1
!= -1)
537 return bit0
> bit1
? CCT1mode
: CCT2mode
;
543 /* Given a comparison code OP (EQ, NE, etc.) and the operands
544 OP0 and OP1 of a COMPARE, return the mode to be used for the
548 s390_select_ccmode (enum rtx_code code
, rtx op0
, rtx op1
)
554 if ((GET_CODE (op0
) == NEG
|| GET_CODE (op0
) == ABS
)
555 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
557 if (GET_CODE (op0
) == PLUS
&& GET_CODE (XEXP (op0
, 1)) == CONST_INT
558 && CONST_OK_FOR_K (INTVAL (XEXP (op0
, 1))))
560 if ((GET_CODE (op0
) == PLUS
|| GET_CODE (op0
) == MINUS
561 || GET_CODE (op1
) == NEG
)
562 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
565 if (GET_CODE (op0
) == AND
)
567 /* Check whether we can potentially do it via TM. */
568 enum machine_mode ccmode
;
569 ccmode
= s390_tm_ccmode (XEXP (op0
, 1), op1
, 1);
570 if (ccmode
!= VOIDmode
)
572 /* Relax CCTmode to CCZmode to allow fall-back to AND
573 if that turns out to be beneficial. */
574 return ccmode
== CCTmode
? CCZmode
: ccmode
;
578 if (register_operand (op0
, HImode
)
579 && GET_CODE (op1
) == CONST_INT
580 && (INTVAL (op1
) == -1 || INTVAL (op1
) == 65535))
582 if (register_operand (op0
, QImode
)
583 && GET_CODE (op1
) == CONST_INT
584 && (INTVAL (op1
) == -1 || INTVAL (op1
) == 255))
593 /* The only overflow condition of NEG and ABS happens when
594 -INT_MAX is used as parameter, which stays negative. So
595 we have an overflow from a positive value to a negative.
596 Using CCAP mode the resulting cc can be used for comparisons. */
597 if ((GET_CODE (op0
) == NEG
|| GET_CODE (op0
) == ABS
)
598 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
601 /* If constants are involved in an add instruction it is possible to use
602 the resulting cc for comparisons with zero. Knowing the sign of the
603 constant the overflow behavior gets predictable. e.g.:
604 int a, b; if ((b = a + c) > 0)
605 with c as a constant value: c < 0 -> CCAN and c >= 0 -> CCAP */
606 if (GET_CODE (op0
) == PLUS
&& GET_CODE (XEXP (op0
, 1)) == CONST_INT
607 && CONST_OK_FOR_K (INTVAL (XEXP (op0
, 1))))
609 if (INTVAL (XEXP((op0
), 1)) < 0)
623 if ((GET_CODE (op0
) == SIGN_EXTEND
|| GET_CODE (op0
) == ZERO_EXTEND
)
624 && GET_CODE (op1
) != CONST_INT
)
630 if (GET_CODE (op0
) == PLUS
631 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
634 if ((GET_CODE (op0
) == SIGN_EXTEND
|| GET_CODE (op0
) == ZERO_EXTEND
)
635 && GET_CODE (op1
) != CONST_INT
)
641 if (GET_CODE (op0
) == MINUS
642 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
645 if ((GET_CODE (op0
) == SIGN_EXTEND
|| GET_CODE (op0
) == ZERO_EXTEND
)
646 && GET_CODE (op1
) != CONST_INT
)
655 /* Replace the comparison OP0 CODE OP1 by a semantically equivalent one
656 that we can implement more efficiently. */
659 s390_canonicalize_comparison (enum rtx_code
*code
, rtx
*op0
, rtx
*op1
)
661 /* Convert ZERO_EXTRACT back to AND to enable TM patterns. */
662 if ((*code
== EQ
|| *code
== NE
)
663 && *op1
== const0_rtx
664 && GET_CODE (*op0
) == ZERO_EXTRACT
665 && GET_CODE (XEXP (*op0
, 1)) == CONST_INT
666 && GET_CODE (XEXP (*op0
, 2)) == CONST_INT
667 && SCALAR_INT_MODE_P (GET_MODE (XEXP (*op0
, 0))))
669 rtx inner
= XEXP (*op0
, 0);
670 HOST_WIDE_INT modesize
= GET_MODE_BITSIZE (GET_MODE (inner
));
671 HOST_WIDE_INT len
= INTVAL (XEXP (*op0
, 1));
672 HOST_WIDE_INT pos
= INTVAL (XEXP (*op0
, 2));
674 if (len
> 0 && len
< modesize
675 && pos
>= 0 && pos
+ len
<= modesize
676 && modesize
<= HOST_BITS_PER_WIDE_INT
)
678 unsigned HOST_WIDE_INT block
;
679 block
= ((unsigned HOST_WIDE_INT
) 1 << len
) - 1;
680 block
<<= modesize
- pos
- len
;
682 *op0
= gen_rtx_AND (GET_MODE (inner
), inner
,
683 gen_int_mode (block
, GET_MODE (inner
)));
687 /* Narrow AND of memory against immediate to enable TM. */
688 if ((*code
== EQ
|| *code
== NE
)
689 && *op1
== const0_rtx
690 && GET_CODE (*op0
) == AND
691 && GET_CODE (XEXP (*op0
, 1)) == CONST_INT
692 && SCALAR_INT_MODE_P (GET_MODE (XEXP (*op0
, 0))))
694 rtx inner
= XEXP (*op0
, 0);
695 rtx mask
= XEXP (*op0
, 1);
697 /* Ignore paradoxical SUBREGs if all extra bits are masked out. */
698 if (GET_CODE (inner
) == SUBREG
699 && SCALAR_INT_MODE_P (GET_MODE (SUBREG_REG (inner
)))
700 && (GET_MODE_SIZE (GET_MODE (inner
))
701 >= GET_MODE_SIZE (GET_MODE (SUBREG_REG (inner
))))
703 & GET_MODE_MASK (GET_MODE (inner
))
704 & ~GET_MODE_MASK (GET_MODE (SUBREG_REG (inner
))))
706 inner
= SUBREG_REG (inner
);
708 /* Do not change volatile MEMs. */
709 if (MEM_P (inner
) && !MEM_VOLATILE_P (inner
))
711 int part
= s390_single_part (XEXP (*op0
, 1),
712 GET_MODE (inner
), QImode
, 0);
715 mask
= gen_int_mode (s390_extract_part (mask
, QImode
, 0), QImode
);
716 inner
= adjust_address_nv (inner
, QImode
, part
);
717 *op0
= gen_rtx_AND (QImode
, inner
, mask
);
722 /* Narrow comparisons against 0xffff to HImode if possible. */
723 if ((*code
== EQ
|| *code
== NE
)
724 && GET_CODE (*op1
) == CONST_INT
725 && INTVAL (*op1
) == 0xffff
726 && SCALAR_INT_MODE_P (GET_MODE (*op0
))
727 && (nonzero_bits (*op0
, GET_MODE (*op0
))
728 & ~(unsigned HOST_WIDE_INT
) 0xffff) == 0)
730 *op0
= gen_lowpart (HImode
, *op0
);
734 /* Remove redundant UNSPEC_CCU_TO_INT conversions if possible. */
735 if (GET_CODE (*op0
) == UNSPEC
736 && XINT (*op0
, 1) == UNSPEC_CCU_TO_INT
737 && XVECLEN (*op0
, 0) == 1
738 && GET_MODE (XVECEXP (*op0
, 0, 0)) == CCUmode
739 && GET_CODE (XVECEXP (*op0
, 0, 0)) == REG
740 && REGNO (XVECEXP (*op0
, 0, 0)) == CC_REGNUM
741 && *op1
== const0_rtx
)
743 enum rtx_code new_code
= UNKNOWN
;
746 case EQ
: new_code
= EQ
; break;
747 case NE
: new_code
= NE
; break;
748 case LT
: new_code
= GTU
; break;
749 case GT
: new_code
= LTU
; break;
750 case LE
: new_code
= GEU
; break;
751 case GE
: new_code
= LEU
; break;
755 if (new_code
!= UNKNOWN
)
757 *op0
= XVECEXP (*op0
, 0, 0);
762 /* Remove redundant UNSPEC_CCZ_TO_INT conversions if possible. */
763 if (GET_CODE (*op0
) == UNSPEC
764 && XINT (*op0
, 1) == UNSPEC_CCZ_TO_INT
765 && XVECLEN (*op0
, 0) == 1
766 && GET_MODE (XVECEXP (*op0
, 0, 0)) == CCZmode
767 && GET_CODE (XVECEXP (*op0
, 0, 0)) == REG
768 && REGNO (XVECEXP (*op0
, 0, 0)) == CC_REGNUM
769 && *op1
== const0_rtx
)
771 enum rtx_code new_code
= UNKNOWN
;
774 case EQ
: new_code
= EQ
; break;
775 case NE
: new_code
= NE
; break;
779 if (new_code
!= UNKNOWN
)
781 *op0
= XVECEXP (*op0
, 0, 0);
786 /* Simplify cascaded EQ, NE with const0_rtx. */
787 if ((*code
== NE
|| *code
== EQ
)
788 && (GET_CODE (*op0
) == EQ
|| GET_CODE (*op0
) == NE
)
789 && GET_MODE (*op0
) == SImode
790 && GET_MODE (XEXP (*op0
, 0)) == CCZ1mode
791 && REG_P (XEXP (*op0
, 0))
792 && XEXP (*op0
, 1) == const0_rtx
793 && *op1
== const0_rtx
)
795 if ((*code
== EQ
&& GET_CODE (*op0
) == NE
)
796 || (*code
== NE
&& GET_CODE (*op0
) == EQ
))
800 *op0
= XEXP (*op0
, 0);
803 /* Prefer register over memory as first operand. */
804 if (MEM_P (*op0
) && REG_P (*op1
))
806 rtx tem
= *op0
; *op0
= *op1
; *op1
= tem
;
807 *code
= swap_condition (*code
);
811 /* Emit a compare instruction suitable to implement the comparison
812 OP0 CODE OP1. Return the correct condition RTL to be placed in
813 the IF_THEN_ELSE of the conditional branch testing the result. */
816 s390_emit_compare (enum rtx_code code
, rtx op0
, rtx op1
)
818 enum machine_mode mode
= s390_select_ccmode (code
, op0
, op1
);
821 /* Do not output a redundant compare instruction if a compare_and_swap
822 pattern already computed the result and the machine modes are compatible. */
823 if (s390_compare_emitted
824 && (s390_cc_modes_compatible (GET_MODE (s390_compare_emitted
), mode
)
825 == GET_MODE (s390_compare_emitted
)))
826 ret
= gen_rtx_fmt_ee (code
, VOIDmode
, s390_compare_emitted
, const0_rtx
);
829 rtx cc
= gen_rtx_REG (mode
, CC_REGNUM
);
831 emit_insn (gen_rtx_SET (VOIDmode
, cc
, gen_rtx_COMPARE (mode
, op0
, op1
)));
832 ret
= gen_rtx_fmt_ee (code
, VOIDmode
, cc
, const0_rtx
);
834 s390_compare_emitted
= NULL_RTX
;
838 /* Emit a SImode compare and swap instruction setting MEM to NEW if OLD
840 Return the correct condition RTL to be placed in the IF_THEN_ELSE of the
841 conditional branch testing the result. */
844 s390_emit_compare_and_swap (enum rtx_code code
, rtx old
, rtx mem
, rtx cmp
, rtx
new)
848 emit_insn (gen_sync_compare_and_swap_ccsi (old
, mem
, cmp
, new));
849 ret
= gen_rtx_fmt_ee (code
, VOIDmode
, s390_compare_emitted
, const0_rtx
);
851 s390_compare_emitted
= NULL_RTX
;
856 /* Emit a jump instruction to TARGET. If COND is NULL_RTX, emit an
857 unconditional jump, else a conditional jump under condition COND. */
860 s390_emit_jump (rtx target
, rtx cond
)
864 target
= gen_rtx_LABEL_REF (VOIDmode
, target
);
866 target
= gen_rtx_IF_THEN_ELSE (VOIDmode
, cond
, target
, pc_rtx
);
868 insn
= gen_rtx_SET (VOIDmode
, pc_rtx
, target
);
869 emit_jump_insn (insn
);
872 /* Return branch condition mask to implement a branch
873 specified by CODE. Return -1 for invalid comparisons. */
876 s390_branch_condition_mask (rtx code
)
878 const int CC0
= 1 << 3;
879 const int CC1
= 1 << 2;
880 const int CC2
= 1 << 1;
881 const int CC3
= 1 << 0;
883 gcc_assert (GET_CODE (XEXP (code
, 0)) == REG
);
884 gcc_assert (REGNO (XEXP (code
, 0)) == CC_REGNUM
);
885 gcc_assert (XEXP (code
, 1) == const0_rtx
);
887 switch (GET_MODE (XEXP (code
, 0)))
891 switch (GET_CODE (code
))
894 case NE
: return CC1
| CC2
| CC3
;
900 switch (GET_CODE (code
))
903 case NE
: return CC0
| CC2
| CC3
;
909 switch (GET_CODE (code
))
912 case NE
: return CC0
| CC1
| CC3
;
918 switch (GET_CODE (code
))
921 case NE
: return CC0
| CC1
| CC2
;
927 switch (GET_CODE (code
))
929 case EQ
: return CC0
| CC2
;
930 case NE
: return CC1
| CC3
;
936 switch (GET_CODE (code
))
938 case LTU
: return CC2
| CC3
; /* carry */
939 case GEU
: return CC0
| CC1
; /* no carry */
945 switch (GET_CODE (code
))
947 case GTU
: return CC0
| CC1
; /* borrow */
948 case LEU
: return CC2
| CC3
; /* no borrow */
954 switch (GET_CODE (code
))
956 case EQ
: return CC0
| CC2
;
957 case NE
: return CC1
| CC3
;
958 case LTU
: return CC1
;
959 case GTU
: return CC3
;
960 case LEU
: return CC1
| CC2
;
961 case GEU
: return CC2
| CC3
;
966 switch (GET_CODE (code
))
969 case NE
: return CC1
| CC2
| CC3
;
970 case LTU
: return CC1
;
971 case GTU
: return CC2
;
972 case LEU
: return CC0
| CC1
;
973 case GEU
: return CC0
| CC2
;
979 switch (GET_CODE (code
))
982 case NE
: return CC2
| CC1
| CC3
;
983 case LTU
: return CC2
;
984 case GTU
: return CC1
;
985 case LEU
: return CC0
| CC2
;
986 case GEU
: return CC0
| CC1
;
992 switch (GET_CODE (code
))
995 case NE
: return CC1
| CC2
| CC3
;
996 case LT
: return CC1
| CC3
;
998 case LE
: return CC0
| CC1
| CC3
;
999 case GE
: return CC0
| CC2
;
1005 switch (GET_CODE (code
))
1007 case EQ
: return CC0
;
1008 case NE
: return CC1
| CC2
| CC3
;
1009 case LT
: return CC1
;
1010 case GT
: return CC2
| CC3
;
1011 case LE
: return CC0
| CC1
;
1012 case GE
: return CC0
| CC2
| CC3
;
1018 switch (GET_CODE (code
))
1020 case EQ
: return CC0
;
1021 case NE
: return CC1
| CC2
| CC3
;
1022 case LT
: return CC1
;
1023 case GT
: return CC2
;
1024 case LE
: return CC0
| CC1
;
1025 case GE
: return CC0
| CC2
;
1026 case UNORDERED
: return CC3
;
1027 case ORDERED
: return CC0
| CC1
| CC2
;
1028 case UNEQ
: return CC0
| CC3
;
1029 case UNLT
: return CC1
| CC3
;
1030 case UNGT
: return CC2
| CC3
;
1031 case UNLE
: return CC0
| CC1
| CC3
;
1032 case UNGE
: return CC0
| CC2
| CC3
;
1033 case LTGT
: return CC1
| CC2
;
1039 switch (GET_CODE (code
))
1041 case EQ
: return CC0
;
1042 case NE
: return CC2
| CC1
| CC3
;
1043 case LT
: return CC2
;
1044 case GT
: return CC1
;
1045 case LE
: return CC0
| CC2
;
1046 case GE
: return CC0
| CC1
;
1047 case UNORDERED
: return CC3
;
1048 case ORDERED
: return CC0
| CC2
| CC1
;
1049 case UNEQ
: return CC0
| CC3
;
1050 case UNLT
: return CC2
| CC3
;
1051 case UNGT
: return CC1
| CC3
;
1052 case UNLE
: return CC0
| CC2
| CC3
;
1053 case UNGE
: return CC0
| CC1
| CC3
;
1054 case LTGT
: return CC2
| CC1
;
1064 /* If INV is false, return assembler mnemonic string to implement
1065 a branch specified by CODE. If INV is true, return mnemonic
1066 for the corresponding inverted branch. */
1069 s390_branch_condition_mnemonic (rtx code
, int inv
)
1071 static const char *const mnemonic
[16] =
1073 NULL
, "o", "h", "nle",
1074 "l", "nhe", "lh", "ne",
1075 "e", "nlh", "he", "nl",
1076 "le", "nh", "no", NULL
1079 int mask
= s390_branch_condition_mask (code
);
1080 gcc_assert (mask
>= 0);
1085 gcc_assert (mask
>= 1 && mask
<= 14);
1087 return mnemonic
[mask
];
1090 /* Return the part of op which has a value different from def.
1091 The size of the part is determined by mode.
1092 Use this function only if you already know that op really
1093 contains such a part. */
1095 unsigned HOST_WIDE_INT
1096 s390_extract_part (rtx op
, enum machine_mode mode
, int def
)
1098 unsigned HOST_WIDE_INT value
= 0;
1099 int max_parts
= HOST_BITS_PER_WIDE_INT
/ GET_MODE_BITSIZE (mode
);
1100 int part_bits
= GET_MODE_BITSIZE (mode
);
1101 unsigned HOST_WIDE_INT part_mask
1102 = ((unsigned HOST_WIDE_INT
)1 << part_bits
) - 1;
1105 for (i
= 0; i
< max_parts
; i
++)
1108 value
= (unsigned HOST_WIDE_INT
) INTVAL (op
);
1110 value
>>= part_bits
;
1112 if ((value
& part_mask
) != (def
& part_mask
))
1113 return value
& part_mask
;
1119 /* If OP is an integer constant of mode MODE with exactly one
1120 part of mode PART_MODE unequal to DEF, return the number of that
1121 part. Otherwise, return -1. */
1124 s390_single_part (rtx op
,
1125 enum machine_mode mode
,
1126 enum machine_mode part_mode
,
1129 unsigned HOST_WIDE_INT value
= 0;
1130 int n_parts
= GET_MODE_SIZE (mode
) / GET_MODE_SIZE (part_mode
);
1131 unsigned HOST_WIDE_INT part_mask
1132 = ((unsigned HOST_WIDE_INT
)1 << GET_MODE_BITSIZE (part_mode
)) - 1;
1135 if (GET_CODE (op
) != CONST_INT
)
1138 for (i
= 0; i
< n_parts
; i
++)
1141 value
= (unsigned HOST_WIDE_INT
) INTVAL (op
);
1143 value
>>= GET_MODE_BITSIZE (part_mode
);
1145 if ((value
& part_mask
) != (def
& part_mask
))
1153 return part
== -1 ? -1 : n_parts
- 1 - part
;
1156 /* Check whether we can (and want to) split a double-word
1157 move in mode MODE from SRC to DST into two single-word
1158 moves, moving the subword FIRST_SUBWORD first. */
1161 s390_split_ok_p (rtx dst
, rtx src
, enum machine_mode mode
, int first_subword
)
1163 /* Floating point registers cannot be split. */
1164 if (FP_REG_P (src
) || FP_REG_P (dst
))
1167 /* We don't need to split if operands are directly accessible. */
1168 if (s_operand (src
, mode
) || s_operand (dst
, mode
))
1171 /* Non-offsettable memory references cannot be split. */
1172 if ((GET_CODE (src
) == MEM
&& !offsettable_memref_p (src
))
1173 || (GET_CODE (dst
) == MEM
&& !offsettable_memref_p (dst
)))
1176 /* Moving the first subword must not clobber a register
1177 needed to move the second subword. */
1178 if (register_operand (dst
, mode
))
1180 rtx subreg
= operand_subword (dst
, first_subword
, 0, mode
);
1181 if (reg_overlap_mentioned_p (subreg
, src
))
1188 /* Return true if it can be proven that [MEM1, MEM1 + SIZE]
1189 and [MEM2, MEM2 + SIZE] do overlap and false
1193 s390_overlap_p (rtx mem1
, rtx mem2
, HOST_WIDE_INT size
)
1195 rtx addr1
, addr2
, addr_delta
;
1196 HOST_WIDE_INT delta
;
1198 if (GET_CODE (mem1
) != MEM
|| GET_CODE (mem2
) != MEM
)
1204 addr1
= XEXP (mem1
, 0);
1205 addr2
= XEXP (mem2
, 0);
1207 addr_delta
= simplify_binary_operation (MINUS
, Pmode
, addr2
, addr1
);
1209 /* This overlapping check is used by peepholes merging memory block operations.
1210 Overlapping operations would otherwise be recognized by the S/390 hardware
1211 and would fall back to a slower implementation. Allowing overlapping
1212 operations would lead to slow code but not to wrong code. Therefore we are
1213 somewhat optimistic if we cannot prove that the memory blocks are
1215 That's why we return false here although this may accept operations on
1216 overlapping memory areas. */
1217 if (!addr_delta
|| GET_CODE (addr_delta
) != CONST_INT
)
1220 delta
= INTVAL (addr_delta
);
1223 || (delta
> 0 && delta
< size
)
1224 || (delta
< 0 && -delta
< size
))
1230 /* Check whether the address of memory reference MEM2 equals exactly
1231 the address of memory reference MEM1 plus DELTA. Return true if
1232 we can prove this to be the case, false otherwise. */
1235 s390_offset_p (rtx mem1
, rtx mem2
, rtx delta
)
1237 rtx addr1
, addr2
, addr_delta
;
1239 if (GET_CODE (mem1
) != MEM
|| GET_CODE (mem2
) != MEM
)
1242 addr1
= XEXP (mem1
, 0);
1243 addr2
= XEXP (mem2
, 0);
1245 addr_delta
= simplify_binary_operation (MINUS
, Pmode
, addr2
, addr1
);
1246 if (!addr_delta
|| !rtx_equal_p (addr_delta
, delta
))
1252 /* Expand logical operator CODE in mode MODE with operands OPERANDS. */
1255 s390_expand_logical_operator (enum rtx_code code
, enum machine_mode mode
,
1258 enum machine_mode wmode
= mode
;
1259 rtx dst
= operands
[0];
1260 rtx src1
= operands
[1];
1261 rtx src2
= operands
[2];
1264 /* If we cannot handle the operation directly, use a temp register. */
1265 if (!s390_logical_operator_ok_p (operands
))
1266 dst
= gen_reg_rtx (mode
);
1268 /* QImode and HImode patterns make sense only if we have a destination
1269 in memory. Otherwise perform the operation in SImode. */
1270 if ((mode
== QImode
|| mode
== HImode
) && GET_CODE (dst
) != MEM
)
1273 /* Widen operands if required. */
1276 if (GET_CODE (dst
) == SUBREG
1277 && (tem
= simplify_subreg (wmode
, dst
, mode
, 0)) != 0)
1279 else if (REG_P (dst
))
1280 dst
= gen_rtx_SUBREG (wmode
, dst
, 0);
1282 dst
= gen_reg_rtx (wmode
);
1284 if (GET_CODE (src1
) == SUBREG
1285 && (tem
= simplify_subreg (wmode
, src1
, mode
, 0)) != 0)
1287 else if (GET_MODE (src1
) != VOIDmode
)
1288 src1
= gen_rtx_SUBREG (wmode
, force_reg (mode
, src1
), 0);
1290 if (GET_CODE (src2
) == SUBREG
1291 && (tem
= simplify_subreg (wmode
, src2
, mode
, 0)) != 0)
1293 else if (GET_MODE (src2
) != VOIDmode
)
1294 src2
= gen_rtx_SUBREG (wmode
, force_reg (mode
, src2
), 0);
1297 /* Emit the instruction. */
1298 op
= gen_rtx_SET (VOIDmode
, dst
, gen_rtx_fmt_ee (code
, wmode
, src1
, src2
));
1299 clob
= gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
1300 emit_insn (gen_rtx_PARALLEL (VOIDmode
, gen_rtvec (2, op
, clob
)));
1302 /* Fix up the destination if needed. */
1303 if (dst
!= operands
[0])
1304 emit_move_insn (operands
[0], gen_lowpart (mode
, dst
));
1307 /* Check whether OPERANDS are OK for a logical operation (AND, IOR, XOR). */
1310 s390_logical_operator_ok_p (rtx
*operands
)
1312 /* If the destination operand is in memory, it needs to coincide
1313 with one of the source operands. After reload, it has to be
1314 the first source operand. */
1315 if (GET_CODE (operands
[0]) == MEM
)
1316 return rtx_equal_p (operands
[0], operands
[1])
1317 || (!reload_completed
&& rtx_equal_p (operands
[0], operands
[2]));
1322 /* Narrow logical operation CODE of memory operand MEMOP with immediate
1323 operand IMMOP to switch from SS to SI type instructions. */
1326 s390_narrow_logical_operator (enum rtx_code code
, rtx
*memop
, rtx
*immop
)
1328 int def
= code
== AND
? -1 : 0;
1332 gcc_assert (GET_CODE (*memop
) == MEM
);
1333 gcc_assert (!MEM_VOLATILE_P (*memop
));
1335 mask
= s390_extract_part (*immop
, QImode
, def
);
1336 part
= s390_single_part (*immop
, GET_MODE (*memop
), QImode
, def
);
1337 gcc_assert (part
>= 0);
1339 *memop
= adjust_address (*memop
, QImode
, part
);
1340 *immop
= gen_int_mode (mask
, QImode
);
1344 /* How to allocate a 'struct machine_function'. */
1346 static struct machine_function
*
1347 s390_init_machine_status (void)
1349 return ggc_alloc_cleared (sizeof (struct machine_function
));
1352 /* Change optimizations to be performed, depending on the
1355 LEVEL is the optimization level specified; 2 if `-O2' is
1356 specified, 1 if `-O' is specified, and 0 if neither is specified.
1358 SIZE is nonzero if `-Os' is specified and zero otherwise. */
1361 optimization_options (int level ATTRIBUTE_UNUSED
, int size ATTRIBUTE_UNUSED
)
1363 /* ??? There are apparently still problems with -fcaller-saves. */
1364 flag_caller_saves
= 0;
1366 /* By default, always emit DWARF-2 unwind info. This allows debugging
1367 without maintaining a stack frame back-chain. */
1368 flag_asynchronous_unwind_tables
= 1;
1370 /* Use MVCLE instructions to decrease code size if requested. */
1372 target_flags
|= MASK_MVCLE
;
1375 /* Return true if ARG is the name of a processor. Set *TYPE and *FLAGS
1376 to the associated processor_type and processor_flags if so. */
1379 s390_handle_arch_option (const char *arg
,
1380 enum processor_type
*type
,
1381 enum processor_flags
*flags
)
1385 const char *const name
; /* processor name or nickname. */
1386 const enum processor_type processor
;
1387 const enum processor_flags flags
;
1389 const processor_alias_table
[] =
1391 {"g5", PROCESSOR_9672_G5
, PF_IEEE_FLOAT
},
1392 {"g6", PROCESSOR_9672_G6
, PF_IEEE_FLOAT
},
1393 {"z900", PROCESSOR_2064_Z900
, PF_IEEE_FLOAT
| PF_ZARCH
},
1394 {"z990", PROCESSOR_2084_Z990
, PF_IEEE_FLOAT
| PF_ZARCH
1395 | PF_LONG_DISPLACEMENT
},
1396 {"z9-109", PROCESSOR_2094_Z9_109
, PF_IEEE_FLOAT
| PF_ZARCH
1397 | PF_LONG_DISPLACEMENT
| PF_EXTIMM
},
1398 {"z9-ec", PROCESSOR_2094_Z9_109
, PF_IEEE_FLOAT
| PF_ZARCH
1399 | PF_LONG_DISPLACEMENT
| PF_EXTIMM
| PF_DFP
},
1400 {"z10", PROCESSOR_2097_Z10
, PF_IEEE_FLOAT
| PF_ZARCH
1401 | PF_LONG_DISPLACEMENT
| PF_EXTIMM
| PF_DFP
| PF_Z10
},
1405 for (i
= 0; i
< ARRAY_SIZE (processor_alias_table
); i
++)
1406 if (strcmp (arg
, processor_alias_table
[i
].name
) == 0)
1408 *type
= processor_alias_table
[i
].processor
;
1409 *flags
= processor_alias_table
[i
].flags
;
1415 /* Implement TARGET_HANDLE_OPTION. */
1418 s390_handle_option (size_t code
, const char *arg
, int value ATTRIBUTE_UNUSED
)
1423 return s390_handle_arch_option (arg
, &s390_arch
, &s390_arch_flags
);
1425 case OPT_mstack_guard_
:
1426 if (sscanf (arg
, HOST_WIDE_INT_PRINT_DEC
, &s390_stack_guard
) != 1)
1428 if (exact_log2 (s390_stack_guard
) == -1)
1429 error ("stack guard value must be an exact power of 2");
1432 case OPT_mstack_size_
:
1433 if (sscanf (arg
, HOST_WIDE_INT_PRINT_DEC
, &s390_stack_size
) != 1)
1435 if (exact_log2 (s390_stack_size
) == -1)
1436 error ("stack size must be an exact power of 2");
1440 return s390_handle_arch_option (arg
, &s390_tune
, &s390_tune_flags
);
1442 case OPT_mwarn_framesize_
:
1443 return sscanf (arg
, HOST_WIDE_INT_PRINT_DEC
, &s390_warn_framesize
) == 1;
1451 override_options (void)
1453 /* Set up function hooks. */
1454 init_machine_status
= s390_init_machine_status
;
1456 /* Architecture mode defaults according to ABI. */
1457 if (!(target_flags_explicit
& MASK_ZARCH
))
1460 target_flags
|= MASK_ZARCH
;
1462 target_flags
&= ~MASK_ZARCH
;
1465 /* Determine processor architectural level. */
1466 if (!s390_arch_string
)
1468 s390_arch_string
= TARGET_ZARCH
? "z900" : "g5";
1469 s390_handle_arch_option (s390_arch_string
, &s390_arch
, &s390_arch_flags
);
1472 /* Determine processor to tune for. */
1473 if (s390_tune
== PROCESSOR_max
)
1475 s390_tune
= s390_arch
;
1476 s390_tune_flags
= s390_arch_flags
;
1479 /* Sanity checks. */
1480 if (TARGET_ZARCH
&& !TARGET_CPU_ZARCH
)
1481 error ("z/Architecture mode not supported on %s", s390_arch_string
);
1482 if (TARGET_64BIT
&& !TARGET_ZARCH
)
1483 error ("64-bit ABI not supported in ESA/390 mode");
1485 if (TARGET_HARD_DFP
&& !TARGET_DFP
)
1487 if (target_flags_explicit
& MASK_HARD_DFP
)
1489 if (!TARGET_CPU_DFP
)
1490 error ("Hardware decimal floating point instructions"
1491 " not available on %s", s390_arch_string
);
1493 error ("Hardware decimal floating point instructions"
1494 " not available in ESA/390 mode");
1497 target_flags
&= ~MASK_HARD_DFP
;
1500 if ((target_flags_explicit
& MASK_SOFT_FLOAT
) && TARGET_SOFT_FLOAT
)
1502 if ((target_flags_explicit
& MASK_HARD_DFP
) && TARGET_HARD_DFP
)
1503 error ("-mhard-dfp can't be used in conjunction with -msoft-float");
1505 target_flags
&= ~MASK_HARD_DFP
;
1508 /* Set processor cost function. */
1511 case PROCESSOR_2084_Z990
:
1512 s390_cost
= &z990_cost
;
1514 case PROCESSOR_2094_Z9_109
:
1515 s390_cost
= &z9_109_cost
;
1517 case PROCESSOR_2097_Z10
:
1518 s390_cost
= &z10_cost
;
1521 s390_cost
= &z900_cost
;
1524 if (TARGET_BACKCHAIN
&& TARGET_PACKED_STACK
&& TARGET_HARD_FLOAT
)
1525 error ("-mbackchain -mpacked-stack -mhard-float are not supported "
1528 if (s390_stack_size
)
1530 if (s390_stack_guard
>= s390_stack_size
)
1531 error ("stack size must be greater than the stack guard value");
1532 else if (s390_stack_size
> 1 << 16)
1533 error ("stack size must not be greater than 64k");
1535 else if (s390_stack_guard
)
1536 error ("-mstack-guard implies use of -mstack-size");
1538 #ifdef TARGET_DEFAULT_LONG_DOUBLE_128
1539 if (!(target_flags_explicit
& MASK_LONG_DOUBLE_128
))
1540 target_flags
|= MASK_LONG_DOUBLE_128
;
1544 /* Map for smallest class containing reg regno. */
1546 const enum reg_class regclass_map
[FIRST_PSEUDO_REGISTER
] =
1547 { GENERAL_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1548 ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1549 ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1550 ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1551 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1552 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1553 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1554 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1555 ADDR_REGS
, CC_REGS
, ADDR_REGS
, ADDR_REGS
,
1556 ACCESS_REGS
, ACCESS_REGS
1559 /* Return attribute type of insn. */
1561 static enum attr_type
1562 s390_safe_attr_type (rtx insn
)
1564 if (recog_memoized (insn
) >= 0)
1565 return get_attr_type (insn
);
1570 /* Return true if DISP is a valid short displacement. */
1573 s390_short_displacement (rtx disp
)
1575 /* No displacement is OK. */
1579 /* Integer displacement in range. */
1580 if (GET_CODE (disp
) == CONST_INT
)
1581 return INTVAL (disp
) >= 0 && INTVAL (disp
) < 4096;
1583 /* GOT offset is not OK, the GOT can be large. */
1584 if (GET_CODE (disp
) == CONST
1585 && GET_CODE (XEXP (disp
, 0)) == UNSPEC
1586 && (XINT (XEXP (disp
, 0), 1) == UNSPEC_GOT
1587 || XINT (XEXP (disp
, 0), 1) == UNSPEC_GOTNTPOFF
))
1590 /* All other symbolic constants are literal pool references,
1591 which are OK as the literal pool must be small. */
1592 if (GET_CODE (disp
) == CONST
)
1598 /* Decompose a RTL expression ADDR for a memory address into
1599 its components, returned in OUT.
1601 Returns false if ADDR is not a valid memory address, true
1602 otherwise. If OUT is NULL, don't return the components,
1603 but check for validity only.
1605 Note: Only addresses in canonical form are recognized.
1606 LEGITIMIZE_ADDRESS should convert non-canonical forms to the
1607 canonical form so that they will be recognized. */
1610 s390_decompose_address (rtx addr
, struct s390_address
*out
)
1612 HOST_WIDE_INT offset
= 0;
1613 rtx base
= NULL_RTX
;
1614 rtx indx
= NULL_RTX
;
1615 rtx disp
= NULL_RTX
;
1617 bool pointer
= false;
1618 bool base_ptr
= false;
1619 bool indx_ptr
= false;
1620 bool literal_pool
= false;
1622 /* We may need to substitute the literal pool base register into the address
1623 below. However, at this point we do not know which register is going to
1624 be used as base, so we substitute the arg pointer register. This is going
1625 to be treated as holding a pointer below -- it shouldn't be used for any
1627 rtx fake_pool_base
= gen_rtx_REG (Pmode
, ARG_POINTER_REGNUM
);
1629 /* Decompose address into base + index + displacement. */
1631 if (GET_CODE (addr
) == REG
|| GET_CODE (addr
) == UNSPEC
)
1634 else if (GET_CODE (addr
) == PLUS
)
1636 rtx op0
= XEXP (addr
, 0);
1637 rtx op1
= XEXP (addr
, 1);
1638 enum rtx_code code0
= GET_CODE (op0
);
1639 enum rtx_code code1
= GET_CODE (op1
);
1641 if (code0
== REG
|| code0
== UNSPEC
)
1643 if (code1
== REG
|| code1
== UNSPEC
)
1645 indx
= op0
; /* index + base */
1651 base
= op0
; /* base + displacement */
1656 else if (code0
== PLUS
)
1658 indx
= XEXP (op0
, 0); /* index + base + disp */
1659 base
= XEXP (op0
, 1);
1670 disp
= addr
; /* displacement */
1672 /* Extract integer part of displacement. */
1676 if (GET_CODE (disp
) == CONST_INT
)
1678 offset
= INTVAL (disp
);
1681 else if (GET_CODE (disp
) == CONST
1682 && GET_CODE (XEXP (disp
, 0)) == PLUS
1683 && GET_CODE (XEXP (XEXP (disp
, 0), 1)) == CONST_INT
)
1685 offset
= INTVAL (XEXP (XEXP (disp
, 0), 1));
1686 disp
= XEXP (XEXP (disp
, 0), 0);
1690 /* Strip off CONST here to avoid special case tests later. */
1691 if (disp
&& GET_CODE (disp
) == CONST
)
1692 disp
= XEXP (disp
, 0);
1694 /* We can convert literal pool addresses to
1695 displacements by basing them off the base register. */
1696 if (disp
&& GET_CODE (disp
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (disp
))
1698 /* Either base or index must be free to hold the base register. */
1700 base
= fake_pool_base
, literal_pool
= true;
1702 indx
= fake_pool_base
, literal_pool
= true;
1706 /* Mark up the displacement. */
1707 disp
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, disp
),
1708 UNSPEC_LTREL_OFFSET
);
1711 /* Validate base register. */
1714 if (GET_CODE (base
) == UNSPEC
)
1715 switch (XINT (base
, 1))
1719 disp
= gen_rtx_UNSPEC (Pmode
,
1720 gen_rtvec (1, XVECEXP (base
, 0, 0)),
1721 UNSPEC_LTREL_OFFSET
);
1725 base
= XVECEXP (base
, 0, 1);
1728 case UNSPEC_LTREL_BASE
:
1729 if (XVECLEN (base
, 0) == 1)
1730 base
= fake_pool_base
, literal_pool
= true;
1732 base
= XVECEXP (base
, 0, 1);
1740 || (GET_MODE (base
) != SImode
1741 && GET_MODE (base
) != Pmode
))
1744 if (REGNO (base
) == STACK_POINTER_REGNUM
1745 || REGNO (base
) == FRAME_POINTER_REGNUM
1746 || ((reload_completed
|| reload_in_progress
)
1747 && frame_pointer_needed
1748 && REGNO (base
) == HARD_FRAME_POINTER_REGNUM
)
1749 || REGNO (base
) == ARG_POINTER_REGNUM
1751 && REGNO (base
) == PIC_OFFSET_TABLE_REGNUM
))
1752 pointer
= base_ptr
= true;
1754 if ((reload_completed
|| reload_in_progress
)
1755 && base
== cfun
->machine
->base_reg
)
1756 pointer
= base_ptr
= literal_pool
= true;
1759 /* Validate index register. */
1762 if (GET_CODE (indx
) == UNSPEC
)
1763 switch (XINT (indx
, 1))
1767 disp
= gen_rtx_UNSPEC (Pmode
,
1768 gen_rtvec (1, XVECEXP (indx
, 0, 0)),
1769 UNSPEC_LTREL_OFFSET
);
1773 indx
= XVECEXP (indx
, 0, 1);
1776 case UNSPEC_LTREL_BASE
:
1777 if (XVECLEN (indx
, 0) == 1)
1778 indx
= fake_pool_base
, literal_pool
= true;
1780 indx
= XVECEXP (indx
, 0, 1);
1788 || (GET_MODE (indx
) != SImode
1789 && GET_MODE (indx
) != Pmode
))
1792 if (REGNO (indx
) == STACK_POINTER_REGNUM
1793 || REGNO (indx
) == FRAME_POINTER_REGNUM
1794 || ((reload_completed
|| reload_in_progress
)
1795 && frame_pointer_needed
1796 && REGNO (indx
) == HARD_FRAME_POINTER_REGNUM
)
1797 || REGNO (indx
) == ARG_POINTER_REGNUM
1799 && REGNO (indx
) == PIC_OFFSET_TABLE_REGNUM
))
1800 pointer
= indx_ptr
= true;
1802 if ((reload_completed
|| reload_in_progress
)
1803 && indx
== cfun
->machine
->base_reg
)
1804 pointer
= indx_ptr
= literal_pool
= true;
1807 /* Prefer to use pointer as base, not index. */
1808 if (base
&& indx
&& !base_ptr
1809 && (indx_ptr
|| (!REG_POINTER (base
) && REG_POINTER (indx
))))
1816 /* Validate displacement. */
1819 /* If virtual registers are involved, the displacement will change later
1820 anyway as the virtual registers get eliminated. This could make a
1821 valid displacement invalid, but it is more likely to make an invalid
1822 displacement valid, because we sometimes access the register save area
1823 via negative offsets to one of those registers.
1824 Thus we don't check the displacement for validity here. If after
1825 elimination the displacement turns out to be invalid after all,
1826 this is fixed up by reload in any case. */
1827 if (base
!= arg_pointer_rtx
1828 && indx
!= arg_pointer_rtx
1829 && base
!= return_address_pointer_rtx
1830 && indx
!= return_address_pointer_rtx
1831 && base
!= frame_pointer_rtx
1832 && indx
!= frame_pointer_rtx
1833 && base
!= virtual_stack_vars_rtx
1834 && indx
!= virtual_stack_vars_rtx
)
1835 if (!DISP_IN_RANGE (offset
))
1840 /* All the special cases are pointers. */
1843 /* In the small-PIC case, the linker converts @GOT
1844 and @GOTNTPOFF offsets to possible displacements. */
1845 if (GET_CODE (disp
) == UNSPEC
1846 && (XINT (disp
, 1) == UNSPEC_GOT
1847 || XINT (disp
, 1) == UNSPEC_GOTNTPOFF
)
1853 /* Accept chunkified literal pool symbol references. */
1854 else if (cfun
&& cfun
->machine
1855 && cfun
->machine
->decomposed_literal_pool_addresses_ok_p
1856 && GET_CODE (disp
) == MINUS
1857 && GET_CODE (XEXP (disp
, 0)) == LABEL_REF
1858 && GET_CODE (XEXP (disp
, 1)) == LABEL_REF
)
1863 /* Accept literal pool references. */
1864 else if (GET_CODE (disp
) == UNSPEC
1865 && XINT (disp
, 1) == UNSPEC_LTREL_OFFSET
)
1867 orig_disp
= gen_rtx_CONST (Pmode
, disp
);
1870 /* If we have an offset, make sure it does not
1871 exceed the size of the constant pool entry. */
1872 rtx sym
= XVECEXP (disp
, 0, 0);
1873 if (offset
>= GET_MODE_SIZE (get_pool_mode (sym
)))
1876 orig_disp
= plus_constant (orig_disp
, offset
);
1891 out
->disp
= orig_disp
;
1892 out
->pointer
= pointer
;
1893 out
->literal_pool
= literal_pool
;
1899 /* Decompose a RTL expression OP for a shift count into its components,
1900 and return the base register in BASE and the offset in OFFSET.
1902 Return true if OP is a valid shift count, false if not. */
1905 s390_decompose_shift_count (rtx op
, rtx
*base
, HOST_WIDE_INT
*offset
)
1907 HOST_WIDE_INT off
= 0;
1909 /* We can have an integer constant, an address register,
1910 or a sum of the two. */
1911 if (GET_CODE (op
) == CONST_INT
)
1916 if (op
&& GET_CODE (op
) == PLUS
&& GET_CODE (XEXP (op
, 1)) == CONST_INT
)
1918 off
= INTVAL (XEXP (op
, 1));
1921 while (op
&& GET_CODE (op
) == SUBREG
)
1922 op
= SUBREG_REG (op
);
1924 if (op
&& GET_CODE (op
) != REG
)
1936 /* Return true if CODE is a valid address without index. */
1939 s390_legitimate_address_without_index_p (rtx op
)
1941 struct s390_address addr
;
1943 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
1952 /* Evaluates constraint strings described by the regular expression
1953 ([A|B](Q|R|S|T))|U|W and returns 1 if OP is a valid operand for the
1954 constraint given in STR, or 0 else. */
1957 s390_mem_constraint (const char *str
, rtx op
)
1959 struct s390_address addr
;
1962 /* Check for offsettable variants of memory constraints. */
1965 /* Only accept non-volatile MEMs. */
1966 if (!MEM_P (op
) || MEM_VOLATILE_P (op
))
1969 if ((reload_completed
|| reload_in_progress
)
1970 ? !offsettable_memref_p (op
) : !offsettable_nonstrict_memref_p (op
))
1976 /* Check for non-literal-pool variants of memory constraints. */
1979 if (GET_CODE (op
) != MEM
)
1981 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
1983 if (addr
.literal_pool
)
1992 if (GET_CODE (op
) != MEM
)
1994 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
1999 if (TARGET_LONG_DISPLACEMENT
)
2001 if (!s390_short_displacement (addr
.disp
))
2007 if (GET_CODE (op
) != MEM
)
2010 if (TARGET_LONG_DISPLACEMENT
)
2012 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
2014 if (!s390_short_displacement (addr
.disp
))
2020 if (!TARGET_LONG_DISPLACEMENT
)
2022 if (GET_CODE (op
) != MEM
)
2024 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
2028 if (s390_short_displacement (addr
.disp
))
2033 if (!TARGET_LONG_DISPLACEMENT
)
2035 if (GET_CODE (op
) != MEM
)
2037 /* Any invalid address here will be fixed up by reload,
2038 so accept it for the most generic constraint. */
2039 if (s390_decompose_address (XEXP (op
, 0), &addr
)
2040 && s390_short_displacement (addr
.disp
))
2045 if (TARGET_LONG_DISPLACEMENT
)
2047 if (!s390_decompose_address (op
, &addr
))
2049 if (!s390_short_displacement (addr
.disp
))
2055 if (!TARGET_LONG_DISPLACEMENT
)
2057 /* Any invalid address here will be fixed up by reload,
2058 so accept it for the most generic constraint. */
2059 if (s390_decompose_address (op
, &addr
)
2060 && s390_short_displacement (addr
.disp
))
2065 /* Simply check for the basic form of a shift count. Reload will
2066 take care of making sure we have a proper base register. */
2067 if (!s390_decompose_shift_count (op
, NULL
, NULL
))
2080 /* Evaluates constraint strings starting with letter O. Input
2081 parameter C is the second letter following the "O" in the constraint
2082 string. Returns 1 if VALUE meets the respective constraint and 0
2086 s390_O_constraint_str (const char c
, HOST_WIDE_INT value
)
2094 return trunc_int_for_mode (value
, SImode
) == value
;
2098 || s390_single_part (GEN_INT (value
), DImode
, SImode
, 0) == 1;
2101 return s390_single_part (GEN_INT (value
- 1), DImode
, SImode
, -1) == 1;
2109 /* Evaluates constraint strings starting with letter N. Parameter STR
2110 contains the letters following letter "N" in the constraint string.
2111 Returns true if VALUE matches the constraint. */
2114 s390_N_constraint_str (const char *str
, HOST_WIDE_INT value
)
2116 enum machine_mode mode
, part_mode
;
2118 int part
, part_goal
;
2124 part_goal
= str
[0] - '0';
2168 if (GET_MODE_SIZE (mode
) <= GET_MODE_SIZE (part_mode
))
2171 part
= s390_single_part (GEN_INT (value
), mode
, part_mode
, def
);
2174 if (part_goal
!= -1 && part_goal
!= part
)
2181 /* Returns true if the input parameter VALUE is a float zero. */
2184 s390_float_const_zero_p (rtx value
)
2186 return (GET_MODE_CLASS (GET_MODE (value
)) == MODE_FLOAT
2187 && value
== CONST0_RTX (GET_MODE (value
)));
2191 /* Compute a (partial) cost for rtx X. Return true if the complete
2192 cost has been computed, and false if subexpressions should be
2193 scanned. In either case, *TOTAL contains the cost result.
2194 CODE contains GET_CODE (x), OUTER_CODE contains the code
2195 of the superexpression of x. */
2198 s390_rtx_costs (rtx x
, int code
, int outer_code
, int *total
)
2221 *total
= COSTS_N_INSNS (1);
2226 /* Check for multiply and add. */
2227 if ((GET_MODE (x
) == DFmode
|| GET_MODE (x
) == SFmode
)
2228 && GET_CODE (XEXP (x
, 0)) == MULT
2229 && TARGET_HARD_FLOAT
&& TARGET_FUSED_MADD
)
2231 /* This is the multiply and add case. */
2232 if (GET_MODE (x
) == DFmode
)
2233 *total
= s390_cost
->madbr
;
2235 *total
= s390_cost
->maebr
;
2236 *total
+= rtx_cost (XEXP (XEXP (x
, 0), 0), MULT
)
2237 + rtx_cost (XEXP (XEXP (x
, 0), 1), MULT
)
2238 + rtx_cost (XEXP (x
, 1), code
);
2239 return true; /* Do not do an additional recursive descent. */
2241 *total
= COSTS_N_INSNS (1);
2245 switch (GET_MODE (x
))
2249 rtx left
= XEXP (x
, 0);
2250 rtx right
= XEXP (x
, 1);
2251 if (GET_CODE (right
) == CONST_INT
2252 && CONST_OK_FOR_K (INTVAL (right
)))
2253 *total
= s390_cost
->mhi
;
2254 else if (GET_CODE (left
) == SIGN_EXTEND
)
2255 *total
= s390_cost
->mh
;
2257 *total
= s390_cost
->ms
; /* msr, ms, msy */
2262 rtx left
= XEXP (x
, 0);
2263 rtx right
= XEXP (x
, 1);
2266 if (GET_CODE (right
) == CONST_INT
2267 && CONST_OK_FOR_K (INTVAL (right
)))
2268 *total
= s390_cost
->mghi
;
2269 else if (GET_CODE (left
) == SIGN_EXTEND
)
2270 *total
= s390_cost
->msgf
;
2272 *total
= s390_cost
->msg
; /* msgr, msg */
2274 else /* TARGET_31BIT */
2276 if (GET_CODE (left
) == SIGN_EXTEND
2277 && GET_CODE (right
) == SIGN_EXTEND
)
2278 /* mulsidi case: mr, m */
2279 *total
= s390_cost
->m
;
2280 else if (GET_CODE (left
) == ZERO_EXTEND
2281 && GET_CODE (right
) == ZERO_EXTEND
2282 && TARGET_CPU_ZARCH
)
2283 /* umulsidi case: ml, mlr */
2284 *total
= s390_cost
->ml
;
2286 /* Complex calculation is required. */
2287 *total
= COSTS_N_INSNS (40);
2293 *total
= s390_cost
->mult_df
;
2296 *total
= s390_cost
->mxbr
;
2305 if (GET_MODE (x
) == TImode
) /* 128 bit division */
2306 *total
= s390_cost
->dlgr
;
2307 else if (GET_MODE (x
) == DImode
)
2309 rtx right
= XEXP (x
, 1);
2310 if (GET_CODE (right
) == ZERO_EXTEND
) /* 64 by 32 bit division */
2311 *total
= s390_cost
->dlr
;
2312 else /* 64 by 64 bit division */
2313 *total
= s390_cost
->dlgr
;
2315 else if (GET_MODE (x
) == SImode
) /* 32 bit division */
2316 *total
= s390_cost
->dlr
;
2321 if (GET_MODE (x
) == DImode
)
2323 rtx right
= XEXP (x
, 1);
2324 if (GET_CODE (right
) == ZERO_EXTEND
) /* 64 by 32 bit division */
2326 *total
= s390_cost
->dsgfr
;
2328 *total
= s390_cost
->dr
;
2329 else /* 64 by 64 bit division */
2330 *total
= s390_cost
->dsgr
;
2332 else if (GET_MODE (x
) == SImode
) /* 32 bit division */
2333 *total
= s390_cost
->dlr
;
2334 else if (GET_MODE (x
) == SFmode
)
2336 *total
= s390_cost
->debr
;
2338 else if (GET_MODE (x
) == DFmode
)
2340 *total
= s390_cost
->ddbr
;
2342 else if (GET_MODE (x
) == TFmode
)
2344 *total
= s390_cost
->dxbr
;
2349 if (GET_MODE (x
) == SFmode
)
2350 *total
= s390_cost
->sqebr
;
2351 else if (GET_MODE (x
) == DFmode
)
2352 *total
= s390_cost
->sqdbr
;
2354 *total
= s390_cost
->sqxbr
;
2359 if (outer_code
== MULT
|| outer_code
== DIV
|| outer_code
== MOD
2360 || outer_code
== PLUS
|| outer_code
== MINUS
2361 || outer_code
== COMPARE
)
2366 *total
= COSTS_N_INSNS (1);
2367 if (GET_CODE (XEXP (x
, 0)) == AND
2368 && GET_CODE (XEXP (x
, 1)) == CONST_INT
2369 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
)
2371 rtx op0
= XEXP (XEXP (x
, 0), 0);
2372 rtx op1
= XEXP (XEXP (x
, 0), 1);
2373 rtx op2
= XEXP (x
, 1);
2375 if (memory_operand (op0
, GET_MODE (op0
))
2376 && s390_tm_ccmode (op1
, op2
, 0) != VOIDmode
)
2378 if (register_operand (op0
, GET_MODE (op0
))
2379 && s390_tm_ccmode (op1
, op2
, 1) != VOIDmode
)
2389 /* Return the cost of an address rtx ADDR. */
2392 s390_address_cost (rtx addr
)
2394 struct s390_address ad
;
2395 if (!s390_decompose_address (addr
, &ad
))
2398 return ad
.indx
? COSTS_N_INSNS (1) + 1 : COSTS_N_INSNS (1);
2401 /* If OP is a SYMBOL_REF of a thread-local symbol, return its TLS mode,
2402 otherwise return 0. */
2405 tls_symbolic_operand (rtx op
)
2407 if (GET_CODE (op
) != SYMBOL_REF
)
2409 return SYMBOL_REF_TLS_MODEL (op
);
2412 /* Split DImode access register reference REG (on 64-bit) into its constituent
2413 low and high parts, and store them into LO and HI. Note that gen_lowpart/
2414 gen_highpart cannot be used as they assume all registers are word-sized,
2415 while our access registers have only half that size. */
2418 s390_split_access_reg (rtx reg
, rtx
*lo
, rtx
*hi
)
2420 gcc_assert (TARGET_64BIT
);
2421 gcc_assert (ACCESS_REG_P (reg
));
2422 gcc_assert (GET_MODE (reg
) == DImode
);
2423 gcc_assert (!(REGNO (reg
) & 1));
2425 *lo
= gen_rtx_REG (SImode
, REGNO (reg
) + 1);
2426 *hi
= gen_rtx_REG (SImode
, REGNO (reg
));
2429 /* Return true if OP contains a symbol reference */
2432 symbolic_reference_mentioned_p (rtx op
)
2437 if (GET_CODE (op
) == SYMBOL_REF
|| GET_CODE (op
) == LABEL_REF
)
2440 fmt
= GET_RTX_FORMAT (GET_CODE (op
));
2441 for (i
= GET_RTX_LENGTH (GET_CODE (op
)) - 1; i
>= 0; i
--)
2447 for (j
= XVECLEN (op
, i
) - 1; j
>= 0; j
--)
2448 if (symbolic_reference_mentioned_p (XVECEXP (op
, i
, j
)))
2452 else if (fmt
[i
] == 'e' && symbolic_reference_mentioned_p (XEXP (op
, i
)))
2459 /* Return true if OP contains a reference to a thread-local symbol. */
2462 tls_symbolic_reference_mentioned_p (rtx op
)
2467 if (GET_CODE (op
) == SYMBOL_REF
)
2468 return tls_symbolic_operand (op
);
2470 fmt
= GET_RTX_FORMAT (GET_CODE (op
));
2471 for (i
= GET_RTX_LENGTH (GET_CODE (op
)) - 1; i
>= 0; i
--)
2477 for (j
= XVECLEN (op
, i
) - 1; j
>= 0; j
--)
2478 if (tls_symbolic_reference_mentioned_p (XVECEXP (op
, i
, j
)))
2482 else if (fmt
[i
] == 'e' && tls_symbolic_reference_mentioned_p (XEXP (op
, i
)))
2490 /* Return true if OP is a legitimate general operand when
2491 generating PIC code. It is given that flag_pic is on
2492 and that OP satisfies CONSTANT_P or is a CONST_DOUBLE. */
2495 legitimate_pic_operand_p (rtx op
)
2497 /* Accept all non-symbolic constants. */
2498 if (!SYMBOLIC_CONST (op
))
2501 /* Reject everything else; must be handled
2502 via emit_symbolic_move. */
2506 /* Returns true if the constant value OP is a legitimate general operand.
2507 It is given that OP satisfies CONSTANT_P or is a CONST_DOUBLE. */
2510 legitimate_constant_p (rtx op
)
2512 /* Accept all non-symbolic constants. */
2513 if (!SYMBOLIC_CONST (op
))
2516 /* Accept immediate LARL operands. */
2517 if (TARGET_CPU_ZARCH
&& larl_operand (op
, VOIDmode
))
2520 /* Thread-local symbols are never legal constants. This is
2521 so that emit_call knows that computing such addresses
2522 might require a function call. */
2523 if (TLS_SYMBOLIC_CONST (op
))
2526 /* In the PIC case, symbolic constants must *not* be
2527 forced into the literal pool. We accept them here,
2528 so that they will be handled by emit_symbolic_move. */
2532 /* All remaining non-PIC symbolic constants are
2533 forced into the literal pool. */
2537 /* Determine if it's legal to put X into the constant pool. This
2538 is not possible if X contains the address of a symbol that is
2539 not constant (TLS) or not known at final link time (PIC). */
2542 s390_cannot_force_const_mem (rtx x
)
2544 switch (GET_CODE (x
))
2548 /* Accept all non-symbolic constants. */
2552 /* Labels are OK iff we are non-PIC. */
2553 return flag_pic
!= 0;
2556 /* 'Naked' TLS symbol references are never OK,
2557 non-TLS symbols are OK iff we are non-PIC. */
2558 if (tls_symbolic_operand (x
))
2561 return flag_pic
!= 0;
2564 return s390_cannot_force_const_mem (XEXP (x
, 0));
2567 return s390_cannot_force_const_mem (XEXP (x
, 0))
2568 || s390_cannot_force_const_mem (XEXP (x
, 1));
2571 switch (XINT (x
, 1))
2573 /* Only lt-relative or GOT-relative UNSPECs are OK. */
2574 case UNSPEC_LTREL_OFFSET
:
2582 case UNSPEC_GOTNTPOFF
:
2583 case UNSPEC_INDNTPOFF
:
2586 /* If the literal pool shares the code section, be put
2587 execute template placeholders into the pool as well. */
2589 return TARGET_CPU_ZARCH
;
2601 /* Returns true if the constant value OP is a legitimate general
2602 operand during and after reload. The difference to
2603 legitimate_constant_p is that this function will not accept
2604 a constant that would need to be forced to the literal pool
2605 before it can be used as operand. */
2608 legitimate_reload_constant_p (rtx op
)
2610 /* Accept la(y) operands. */
2611 if (GET_CODE (op
) == CONST_INT
2612 && DISP_IN_RANGE (INTVAL (op
)))
2615 /* Accept l(g)hi/l(g)fi operands. */
2616 if (GET_CODE (op
) == CONST_INT
2617 && (CONST_OK_FOR_K (INTVAL (op
)) || CONST_OK_FOR_Os (INTVAL (op
))))
2620 /* Accept lliXX operands. */
2622 && GET_CODE (op
) == CONST_INT
2623 && trunc_int_for_mode (INTVAL (op
), word_mode
) == INTVAL (op
)
2624 && s390_single_part (op
, word_mode
, HImode
, 0) >= 0)
2628 && GET_CODE (op
) == CONST_INT
2629 && trunc_int_for_mode (INTVAL (op
), word_mode
) == INTVAL (op
)
2630 && s390_single_part (op
, word_mode
, SImode
, 0) >= 0)
2633 /* Accept larl operands. */
2634 if (TARGET_CPU_ZARCH
2635 && larl_operand (op
, VOIDmode
))
2638 /* Accept lzXX operands. */
2639 if (GET_CODE (op
) == CONST_DOUBLE
2640 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op
, 'G', "G"))
2643 /* Accept double-word operands that can be split. */
2644 if (GET_CODE (op
) == CONST_INT
2645 && trunc_int_for_mode (INTVAL (op
), word_mode
) != INTVAL (op
))
2647 enum machine_mode dword_mode
= word_mode
== SImode
? DImode
: TImode
;
2648 rtx hi
= operand_subword (op
, 0, 0, dword_mode
);
2649 rtx lo
= operand_subword (op
, 1, 0, dword_mode
);
2650 return legitimate_reload_constant_p (hi
)
2651 && legitimate_reload_constant_p (lo
);
2654 /* Everything else cannot be handled without reload. */
2658 /* Given an rtx OP being reloaded into a reg required to be in class CLASS,
2659 return the class of reg to actually use. */
2662 s390_preferred_reload_class (rtx op
, enum reg_class
class)
2664 switch (GET_CODE (op
))
2666 /* Constants we cannot reload must be forced into the
2671 if (legitimate_reload_constant_p (op
))
2676 /* If a symbolic constant or a PLUS is reloaded,
2677 it is most likely being used as an address, so
2678 prefer ADDR_REGS. If 'class' is not a superset
2679 of ADDR_REGS, e.g. FP_REGS, reject this reload. */
2684 if (reg_class_subset_p (ADDR_REGS
, class))
2696 /* Inform reload about cases where moving X with a mode MODE to a register in
2697 CLASS requires an extra scratch or immediate register. Return the class
2698 needed for the immediate register. */
2700 static enum reg_class
2701 s390_secondary_reload (bool in_p
, rtx x
, enum reg_class
class,
2702 enum machine_mode mode
, secondary_reload_info
*sri
)
2704 /* Intermediate register needed. */
2705 if (reg_classes_intersect_p (CC_REGS
, class))
2706 return GENERAL_REGS
;
2708 /* We need a scratch register when loading a PLUS expression which
2709 is not a legitimate operand of the LOAD ADDRESS instruction. */
2710 if (in_p
&& s390_plus_operand (x
, mode
))
2711 sri
->icode
= (TARGET_64BIT
?
2712 CODE_FOR_reloaddi_plus
: CODE_FOR_reloadsi_plus
);
2714 /* Performing a multiword move from or to memory we have to make sure the
2715 second chunk in memory is addressable without causing a displacement
2716 overflow. If that would be the case we calculate the address in
2717 a scratch register. */
2719 && GET_CODE (XEXP (x
, 0)) == PLUS
2720 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
2721 && !DISP_IN_RANGE (INTVAL (XEXP (XEXP (x
, 0), 1))
2722 + GET_MODE_SIZE (mode
) - 1))
2724 /* For GENERAL_REGS a displacement overflow is no problem if occurring
2725 in a s_operand address since we may fallback to lm/stm. So we only
2726 have to care about overflows in the b+i+d case. */
2727 if ((reg_classes_intersect_p (GENERAL_REGS
, class)
2728 && s390_class_max_nregs (GENERAL_REGS
, mode
) > 1
2729 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == PLUS
)
2730 /* For FP_REGS no lm/stm is available so this check is triggered
2731 for displacement overflows in b+i+d and b+d like addresses. */
2732 || (reg_classes_intersect_p (FP_REGS
, class)
2733 && s390_class_max_nregs (FP_REGS
, mode
) > 1))
2736 sri
->icode
= (TARGET_64BIT
?
2737 CODE_FOR_reloaddi_nonoffmem_in
:
2738 CODE_FOR_reloadsi_nonoffmem_in
);
2740 sri
->icode
= (TARGET_64BIT
?
2741 CODE_FOR_reloaddi_nonoffmem_out
:
2742 CODE_FOR_reloadsi_nonoffmem_out
);
2746 /* Either scratch or no register needed. */
2750 /* Generate code to load SRC, which is PLUS that is not a
2751 legitimate operand for the LA instruction, into TARGET.
2752 SCRATCH may be used as scratch register. */
2755 s390_expand_plus_operand (rtx target
, rtx src
,
2759 struct s390_address ad
;
2761 /* src must be a PLUS; get its two operands. */
2762 gcc_assert (GET_CODE (src
) == PLUS
);
2763 gcc_assert (GET_MODE (src
) == Pmode
);
2765 /* Check if any of the two operands is already scheduled
2766 for replacement by reload. This can happen e.g. when
2767 float registers occur in an address. */
2768 sum1
= find_replacement (&XEXP (src
, 0));
2769 sum2
= find_replacement (&XEXP (src
, 1));
2770 src
= gen_rtx_PLUS (Pmode
, sum1
, sum2
);
2772 /* If the address is already strictly valid, there's nothing to do. */
2773 if (!s390_decompose_address (src
, &ad
)
2774 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
2775 || (ad
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (ad
.indx
))))
2777 /* Otherwise, one of the operands cannot be an address register;
2778 we reload its value into the scratch register. */
2779 if (true_regnum (sum1
) < 1 || true_regnum (sum1
) > 15)
2781 emit_move_insn (scratch
, sum1
);
2784 if (true_regnum (sum2
) < 1 || true_regnum (sum2
) > 15)
2786 emit_move_insn (scratch
, sum2
);
2790 /* According to the way these invalid addresses are generated
2791 in reload.c, it should never happen (at least on s390) that
2792 *neither* of the PLUS components, after find_replacements
2793 was applied, is an address register. */
2794 if (sum1
== scratch
&& sum2
== scratch
)
2800 src
= gen_rtx_PLUS (Pmode
, sum1
, sum2
);
2803 /* Emit the LOAD ADDRESS pattern. Note that reload of PLUS
2804 is only ever performed on addresses, so we can mark the
2805 sum as legitimate for LA in any case. */
2806 s390_load_address (target
, src
);
2810 /* Return true if ADDR is a valid memory address.
2811 STRICT specifies whether strict register checking applies. */
2814 legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED
,
2815 rtx addr
, int strict
)
2817 struct s390_address ad
;
2818 if (!s390_decompose_address (addr
, &ad
))
2823 if (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
2826 if (ad
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (ad
.indx
)))
2832 && !(REGNO (ad
.base
) >= FIRST_PSEUDO_REGISTER
2833 || REGNO_REG_CLASS (REGNO (ad
.base
)) == ADDR_REGS
))
2837 && !(REGNO (ad
.indx
) >= FIRST_PSEUDO_REGISTER
2838 || REGNO_REG_CLASS (REGNO (ad
.indx
)) == ADDR_REGS
))
2844 /* Return true if OP is a valid operand for the LA instruction.
2845 In 31-bit, we need to prove that the result is used as an
2846 address, as LA performs only a 31-bit addition. */
2849 legitimate_la_operand_p (rtx op
)
2851 struct s390_address addr
;
2852 if (!s390_decompose_address (op
, &addr
))
2855 return (TARGET_64BIT
|| addr
.pointer
);
2858 /* Return true if it is valid *and* preferable to use LA to
2859 compute the sum of OP1 and OP2. */
2862 preferred_la_operand_p (rtx op1
, rtx op2
)
2864 struct s390_address addr
;
2866 if (op2
!= const0_rtx
)
2867 op1
= gen_rtx_PLUS (Pmode
, op1
, op2
);
2869 if (!s390_decompose_address (op1
, &addr
))
2871 if (addr
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (addr
.base
)))
2873 if (addr
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (addr
.indx
)))
2876 if (!TARGET_64BIT
&& !addr
.pointer
)
2882 if ((addr
.base
&& REG_P (addr
.base
) && REG_POINTER (addr
.base
))
2883 || (addr
.indx
&& REG_P (addr
.indx
) && REG_POINTER (addr
.indx
)))
2889 /* Emit a forced load-address operation to load SRC into DST.
2890 This will use the LOAD ADDRESS instruction even in situations
2891 where legitimate_la_operand_p (SRC) returns false. */
2894 s390_load_address (rtx dst
, rtx src
)
2897 emit_move_insn (dst
, src
);
2899 emit_insn (gen_force_la_31 (dst
, src
));
2902 /* Return a legitimate reference for ORIG (an address) using the
2903 register REG. If REG is 0, a new pseudo is generated.
2905 There are two types of references that must be handled:
2907 1. Global data references must load the address from the GOT, via
2908 the PIC reg. An insn is emitted to do this load, and the reg is
2911 2. Static data references, constant pool addresses, and code labels
2912 compute the address as an offset from the GOT, whose base is in
2913 the PIC reg. Static data objects have SYMBOL_FLAG_LOCAL set to
2914 differentiate them from global data objects. The returned
2915 address is the PIC reg + an unspec constant.
2917 GO_IF_LEGITIMATE_ADDRESS rejects symbolic references unless the PIC
2918 reg also appears in the address. */
2921 legitimize_pic_address (rtx orig
, rtx reg
)
2927 gcc_assert (!TLS_SYMBOLIC_CONST (addr
));
2929 if (GET_CODE (addr
) == LABEL_REF
2930 || (GET_CODE (addr
) == SYMBOL_REF
&& SYMBOL_REF_LOCAL_P (addr
)))
2932 /* This is a local symbol. */
2933 if (TARGET_CPU_ZARCH
&& larl_operand (addr
, VOIDmode
))
2935 /* Access local symbols PC-relative via LARL.
2936 This is the same as in the non-PIC case, so it is
2937 handled automatically ... */
2941 /* Access local symbols relative to the GOT. */
2943 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
2945 if (reload_in_progress
|| reload_completed
)
2946 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
2948 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTOFF
);
2949 addr
= gen_rtx_CONST (Pmode
, addr
);
2950 addr
= force_const_mem (Pmode
, addr
);
2951 emit_move_insn (temp
, addr
);
2953 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
2956 s390_load_address (reg
, new);
2961 else if (GET_CODE (addr
) == SYMBOL_REF
)
2964 reg
= gen_reg_rtx (Pmode
);
2968 /* Assume GOT offset < 4k. This is handled the same way
2969 in both 31- and 64-bit code (@GOT). */
2971 if (reload_in_progress
|| reload_completed
)
2972 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
2974 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOT
);
2975 new = gen_rtx_CONST (Pmode
, new);
2976 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, new);
2977 new = gen_const_mem (Pmode
, new);
2978 emit_move_insn (reg
, new);
2981 else if (TARGET_CPU_ZARCH
)
2983 /* If the GOT offset might be >= 4k, we determine the position
2984 of the GOT entry via a PC-relative LARL (@GOTENT). */
2986 rtx temp
= gen_reg_rtx (Pmode
);
2988 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTENT
);
2989 new = gen_rtx_CONST (Pmode
, new);
2990 emit_move_insn (temp
, new);
2992 new = gen_const_mem (Pmode
, temp
);
2993 emit_move_insn (reg
, new);
2998 /* If the GOT offset might be >= 4k, we have to load it
2999 from the literal pool (@GOT). */
3001 rtx temp
= gen_reg_rtx (Pmode
);
3003 if (reload_in_progress
|| reload_completed
)
3004 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3006 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOT
);
3007 addr
= gen_rtx_CONST (Pmode
, addr
);
3008 addr
= force_const_mem (Pmode
, addr
);
3009 emit_move_insn (temp
, addr
);
3011 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3012 new = gen_const_mem (Pmode
, new);
3013 emit_move_insn (reg
, new);
3019 if (GET_CODE (addr
) == CONST
)
3021 addr
= XEXP (addr
, 0);
3022 if (GET_CODE (addr
) == UNSPEC
)
3024 gcc_assert (XVECLEN (addr
, 0) == 1);
3025 switch (XINT (addr
, 1))
3027 /* If someone moved a GOT-relative UNSPEC
3028 out of the literal pool, force them back in. */
3031 new = force_const_mem (Pmode
, orig
);
3034 /* @GOT is OK as is if small. */
3037 new = force_const_mem (Pmode
, orig
);
3040 /* @GOTENT is OK as is. */
3044 /* @PLT is OK as is on 64-bit, must be converted to
3045 GOT-relative @PLTOFF on 31-bit. */
3047 if (!TARGET_CPU_ZARCH
)
3049 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3051 if (reload_in_progress
|| reload_completed
)
3052 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3054 addr
= XVECEXP (addr
, 0, 0);
3055 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
),
3057 addr
= gen_rtx_CONST (Pmode
, addr
);
3058 addr
= force_const_mem (Pmode
, addr
);
3059 emit_move_insn (temp
, addr
);
3061 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3064 s390_load_address (reg
, new);
3070 /* Everything else cannot happen. */
3076 gcc_assert (GET_CODE (addr
) == PLUS
);
3078 if (GET_CODE (addr
) == PLUS
)
3080 rtx op0
= XEXP (addr
, 0), op1
= XEXP (addr
, 1);
3082 gcc_assert (!TLS_SYMBOLIC_CONST (op0
));
3083 gcc_assert (!TLS_SYMBOLIC_CONST (op1
));
3085 /* Check first to see if this is a constant offset
3086 from a local symbol reference. */
3087 if ((GET_CODE (op0
) == LABEL_REF
3088 || (GET_CODE (op0
) == SYMBOL_REF
&& SYMBOL_REF_LOCAL_P (op0
)))
3089 && GET_CODE (op1
) == CONST_INT
)
3091 if (TARGET_CPU_ZARCH
3092 && larl_operand (op0
, VOIDmode
)
3093 && INTVAL (op1
) < (HOST_WIDE_INT
)1 << 31
3094 && INTVAL (op1
) >= -((HOST_WIDE_INT
)1 << 31))
3096 if (INTVAL (op1
) & 1)
3098 /* LARL can't handle odd offsets, so emit a
3099 pair of LARL and LA. */
3100 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3102 if (!DISP_IN_RANGE (INTVAL (op1
)))
3104 HOST_WIDE_INT even
= INTVAL (op1
) - 1;
3105 op0
= gen_rtx_PLUS (Pmode
, op0
, GEN_INT (even
));
3106 op0
= gen_rtx_CONST (Pmode
, op0
);
3110 emit_move_insn (temp
, op0
);
3111 new = gen_rtx_PLUS (Pmode
, temp
, op1
);
3115 s390_load_address (reg
, new);
3121 /* If the offset is even, we can just use LARL.
3122 This will happen automatically. */
3127 /* Access local symbols relative to the GOT. */
3129 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3131 if (reload_in_progress
|| reload_completed
)
3132 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3134 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op0
),
3136 addr
= gen_rtx_PLUS (Pmode
, addr
, op1
);
3137 addr
= gen_rtx_CONST (Pmode
, addr
);
3138 addr
= force_const_mem (Pmode
, addr
);
3139 emit_move_insn (temp
, addr
);
3141 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3144 s390_load_address (reg
, new);
3150 /* Now, check whether it is a GOT relative symbol plus offset
3151 that was pulled out of the literal pool. Force it back in. */
3153 else if (GET_CODE (op0
) == UNSPEC
3154 && GET_CODE (op1
) == CONST_INT
3155 && XINT (op0
, 1) == UNSPEC_GOTOFF
)
3157 gcc_assert (XVECLEN (op0
, 0) == 1);
3159 new = force_const_mem (Pmode
, orig
);
3162 /* Otherwise, compute the sum. */
3165 base
= legitimize_pic_address (XEXP (addr
, 0), reg
);
3166 new = legitimize_pic_address (XEXP (addr
, 1),
3167 base
== reg
? NULL_RTX
: reg
);
3168 if (GET_CODE (new) == CONST_INT
)
3169 new = plus_constant (base
, INTVAL (new));
3172 if (GET_CODE (new) == PLUS
&& CONSTANT_P (XEXP (new, 1)))
3174 base
= gen_rtx_PLUS (Pmode
, base
, XEXP (new, 0));
3175 new = XEXP (new, 1);
3177 new = gen_rtx_PLUS (Pmode
, base
, new);
3180 if (GET_CODE (new) == CONST
)
3181 new = XEXP (new, 0);
3182 new = force_operand (new, 0);
3189 /* Load the thread pointer into a register. */
3192 s390_get_thread_pointer (void)
3194 rtx tp
= gen_reg_rtx (Pmode
);
3196 emit_move_insn (tp
, gen_rtx_REG (Pmode
, TP_REGNUM
));
3197 mark_reg_pointer (tp
, BITS_PER_WORD
);
3202 /* Emit a tls call insn. The call target is the SYMBOL_REF stored
3203 in s390_tls_symbol which always refers to __tls_get_offset.
3204 The returned offset is written to RESULT_REG and an USE rtx is
3205 generated for TLS_CALL. */
3207 static GTY(()) rtx s390_tls_symbol
;
3210 s390_emit_tls_call_insn (rtx result_reg
, rtx tls_call
)
3214 gcc_assert (flag_pic
);
3216 if (!s390_tls_symbol
)
3217 s390_tls_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "__tls_get_offset");
3219 insn
= s390_emit_call (s390_tls_symbol
, tls_call
, result_reg
,
3220 gen_rtx_REG (Pmode
, RETURN_REGNUM
));
3222 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), result_reg
);
3223 RTL_CONST_CALL_P (insn
) = 1;
3226 /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
3227 this (thread-local) address. REG may be used as temporary. */
3230 legitimize_tls_address (rtx addr
, rtx reg
)
3232 rtx
new, tls_call
, temp
, base
, r2
, insn
;
3234 if (GET_CODE (addr
) == SYMBOL_REF
)
3235 switch (tls_symbolic_operand (addr
))
3237 case TLS_MODEL_GLOBAL_DYNAMIC
:
3239 r2
= gen_rtx_REG (Pmode
, 2);
3240 tls_call
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_TLSGD
);
3241 new = gen_rtx_CONST (Pmode
, tls_call
);
3242 new = force_const_mem (Pmode
, new);
3243 emit_move_insn (r2
, new);
3244 s390_emit_tls_call_insn (r2
, tls_call
);
3245 insn
= get_insns ();
3248 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_NTPOFF
);
3249 temp
= gen_reg_rtx (Pmode
);
3250 emit_libcall_block (insn
, temp
, r2
, new);
3252 new = gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3255 s390_load_address (reg
, new);
3260 case TLS_MODEL_LOCAL_DYNAMIC
:
3262 r2
= gen_rtx_REG (Pmode
, 2);
3263 tls_call
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, const0_rtx
), UNSPEC_TLSLDM
);
3264 new = gen_rtx_CONST (Pmode
, tls_call
);
3265 new = force_const_mem (Pmode
, new);
3266 emit_move_insn (r2
, new);
3267 s390_emit_tls_call_insn (r2
, tls_call
);
3268 insn
= get_insns ();
3271 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, const0_rtx
), UNSPEC_TLSLDM_NTPOFF
);
3272 temp
= gen_reg_rtx (Pmode
);
3273 emit_libcall_block (insn
, temp
, r2
, new);
3275 new = gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3276 base
= gen_reg_rtx (Pmode
);
3277 s390_load_address (base
, new);
3279 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_DTPOFF
);
3280 new = gen_rtx_CONST (Pmode
, new);
3281 new = force_const_mem (Pmode
, new);
3282 temp
= gen_reg_rtx (Pmode
);
3283 emit_move_insn (temp
, new);
3285 new = gen_rtx_PLUS (Pmode
, base
, temp
);
3288 s390_load_address (reg
, new);
3293 case TLS_MODEL_INITIAL_EXEC
:
3296 /* Assume GOT offset < 4k. This is handled the same way
3297 in both 31- and 64-bit code. */
3299 if (reload_in_progress
|| reload_completed
)
3300 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3302 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTNTPOFF
);
3303 new = gen_rtx_CONST (Pmode
, new);
3304 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, new);
3305 new = gen_const_mem (Pmode
, new);
3306 temp
= gen_reg_rtx (Pmode
);
3307 emit_move_insn (temp
, new);
3309 else if (TARGET_CPU_ZARCH
)
3311 /* If the GOT offset might be >= 4k, we determine the position
3312 of the GOT entry via a PC-relative LARL. */
3314 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_INDNTPOFF
);
3315 new = gen_rtx_CONST (Pmode
, new);
3316 temp
= gen_reg_rtx (Pmode
);
3317 emit_move_insn (temp
, new);
3319 new = gen_const_mem (Pmode
, temp
);
3320 temp
= gen_reg_rtx (Pmode
);
3321 emit_move_insn (temp
, new);
3325 /* If the GOT offset might be >= 4k, we have to load it
3326 from the literal pool. */
3328 if (reload_in_progress
|| reload_completed
)
3329 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM
, true);
3331 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTNTPOFF
);
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
, pic_offset_table_rtx
, temp
);
3338 new = gen_const_mem (Pmode
, new);
3340 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, new, addr
), UNSPEC_TLS_LOAD
);
3341 temp
= gen_reg_rtx (Pmode
);
3342 emit_insn (gen_rtx_SET (Pmode
, temp
, new));
3346 /* In position-dependent code, load the absolute address of
3347 the GOT entry from the literal pool. */
3349 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_INDNTPOFF
);
3350 new = gen_rtx_CONST (Pmode
, new);
3351 new = force_const_mem (Pmode
, new);
3352 temp
= gen_reg_rtx (Pmode
);
3353 emit_move_insn (temp
, new);
3356 new = gen_const_mem (Pmode
, new);
3357 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, new, addr
), UNSPEC_TLS_LOAD
);
3358 temp
= gen_reg_rtx (Pmode
);
3359 emit_insn (gen_rtx_SET (Pmode
, temp
, new));
3362 new = gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3365 s390_load_address (reg
, new);
3370 case TLS_MODEL_LOCAL_EXEC
:
3371 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_NTPOFF
);
3372 new = gen_rtx_CONST (Pmode
, new);
3373 new = force_const_mem (Pmode
, new);
3374 temp
= gen_reg_rtx (Pmode
);
3375 emit_move_insn (temp
, new);
3377 new = gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3380 s390_load_address (reg
, new);
3389 else if (GET_CODE (addr
) == CONST
&& GET_CODE (XEXP (addr
, 0)) == UNSPEC
)
3391 switch (XINT (XEXP (addr
, 0), 1))
3393 case UNSPEC_INDNTPOFF
:
3394 gcc_assert (TARGET_CPU_ZARCH
);
3403 else if (GET_CODE (addr
) == CONST
&& GET_CODE (XEXP (addr
, 0)) == PLUS
3404 && GET_CODE (XEXP (XEXP (addr
, 0), 1)) == CONST_INT
)
3406 new = XEXP (XEXP (addr
, 0), 0);
3407 if (GET_CODE (new) != SYMBOL_REF
)
3408 new = gen_rtx_CONST (Pmode
, new);
3410 new = legitimize_tls_address (new, reg
);
3411 new = plus_constant (new, INTVAL (XEXP (XEXP (addr
, 0), 1)));
3412 new = force_operand (new, 0);
3416 gcc_unreachable (); /* for now ... */
3421 /* Emit insns to move operands[1] into operands[0]. */
3424 emit_symbolic_move (rtx
*operands
)
3426 rtx temp
= !can_create_pseudo_p () ? operands
[0] : gen_reg_rtx (Pmode
);
3428 if (GET_CODE (operands
[0]) == MEM
)
3429 operands
[1] = force_reg (Pmode
, operands
[1]);
3430 else if (TLS_SYMBOLIC_CONST (operands
[1]))
3431 operands
[1] = legitimize_tls_address (operands
[1], temp
);
3433 operands
[1] = legitimize_pic_address (operands
[1], temp
);
3436 /* Try machine-dependent ways of modifying an illegitimate address X
3437 to be legitimate. If we find one, return the new, valid address.
3439 OLDX is the address as it was before break_out_memory_refs was called.
3440 In some cases it is useful to look at this to decide what needs to be done.
3442 MODE is the mode of the operand pointed to by X.
3444 When -fpic is used, special handling is needed for symbolic references.
3445 See comments by legitimize_pic_address for details. */
3448 legitimize_address (rtx x
, rtx oldx ATTRIBUTE_UNUSED
,
3449 enum machine_mode mode ATTRIBUTE_UNUSED
)
3451 rtx constant_term
= const0_rtx
;
3453 if (TLS_SYMBOLIC_CONST (x
))
3455 x
= legitimize_tls_address (x
, 0);
3457 if (legitimate_address_p (mode
, x
, FALSE
))
3460 else if (GET_CODE (x
) == PLUS
3461 && (TLS_SYMBOLIC_CONST (XEXP (x
, 0))
3462 || TLS_SYMBOLIC_CONST (XEXP (x
, 1))))
3468 if (SYMBOLIC_CONST (x
)
3469 || (GET_CODE (x
) == PLUS
3470 && (SYMBOLIC_CONST (XEXP (x
, 0))
3471 || SYMBOLIC_CONST (XEXP (x
, 1)))))
3472 x
= legitimize_pic_address (x
, 0);
3474 if (legitimate_address_p (mode
, x
, FALSE
))
3478 x
= eliminate_constant_term (x
, &constant_term
);
3480 /* Optimize loading of large displacements by splitting them
3481 into the multiple of 4K and the rest; this allows the
3482 former to be CSE'd if possible.
3484 Don't do this if the displacement is added to a register
3485 pointing into the stack frame, as the offsets will
3486 change later anyway. */
3488 if (GET_CODE (constant_term
) == CONST_INT
3489 && !TARGET_LONG_DISPLACEMENT
3490 && !DISP_IN_RANGE (INTVAL (constant_term
))
3491 && !(REG_P (x
) && REGNO_PTR_FRAME_P (REGNO (x
))))
3493 HOST_WIDE_INT lower
= INTVAL (constant_term
) & 0xfff;
3494 HOST_WIDE_INT upper
= INTVAL (constant_term
) ^ lower
;
3496 rtx temp
= gen_reg_rtx (Pmode
);
3497 rtx val
= force_operand (GEN_INT (upper
), temp
);
3499 emit_move_insn (temp
, val
);
3501 x
= gen_rtx_PLUS (Pmode
, x
, temp
);
3502 constant_term
= GEN_INT (lower
);
3505 if (GET_CODE (x
) == PLUS
)
3507 if (GET_CODE (XEXP (x
, 0)) == REG
)
3509 rtx temp
= gen_reg_rtx (Pmode
);
3510 rtx val
= force_operand (XEXP (x
, 1), temp
);
3512 emit_move_insn (temp
, val
);
3514 x
= gen_rtx_PLUS (Pmode
, XEXP (x
, 0), temp
);
3517 else if (GET_CODE (XEXP (x
, 1)) == REG
)
3519 rtx temp
= gen_reg_rtx (Pmode
);
3520 rtx val
= force_operand (XEXP (x
, 0), temp
);
3522 emit_move_insn (temp
, val
);
3524 x
= gen_rtx_PLUS (Pmode
, temp
, XEXP (x
, 1));
3528 if (constant_term
!= const0_rtx
)
3529 x
= gen_rtx_PLUS (Pmode
, x
, constant_term
);
3534 /* Try a machine-dependent way of reloading an illegitimate address AD
3535 operand. If we find one, push the reload and and return the new address.
3537 MODE is the mode of the enclosing MEM. OPNUM is the operand number
3538 and TYPE is the reload type of the current reload. */
3541 legitimize_reload_address (rtx ad
, enum machine_mode mode ATTRIBUTE_UNUSED
,
3542 int opnum
, int type
)
3544 if (!optimize
|| TARGET_LONG_DISPLACEMENT
)
3547 if (GET_CODE (ad
) == PLUS
)
3549 rtx tem
= simplify_binary_operation (PLUS
, Pmode
,
3550 XEXP (ad
, 0), XEXP (ad
, 1));
3555 if (GET_CODE (ad
) == PLUS
3556 && GET_CODE (XEXP (ad
, 0)) == REG
3557 && GET_CODE (XEXP (ad
, 1)) == CONST_INT
3558 && !DISP_IN_RANGE (INTVAL (XEXP (ad
, 1))))
3560 HOST_WIDE_INT lower
= INTVAL (XEXP (ad
, 1)) & 0xfff;
3561 HOST_WIDE_INT upper
= INTVAL (XEXP (ad
, 1)) ^ lower
;
3564 cst
= GEN_INT (upper
);
3565 if (!legitimate_reload_constant_p (cst
))
3566 cst
= force_const_mem (Pmode
, cst
);
3568 tem
= gen_rtx_PLUS (Pmode
, XEXP (ad
, 0), cst
);
3569 new = gen_rtx_PLUS (Pmode
, tem
, GEN_INT (lower
));
3571 push_reload (XEXP (tem
, 1), 0, &XEXP (tem
, 1), 0,
3572 BASE_REG_CLASS
, Pmode
, VOIDmode
, 0, 0,
3573 opnum
, (enum reload_type
) type
);
3580 /* Emit code to move LEN bytes from DST to SRC. */
3583 s390_expand_movmem (rtx dst
, rtx src
, rtx len
)
3585 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) >= 0 && INTVAL (len
) <= 256)
3587 if (INTVAL (len
) > 0)
3588 emit_insn (gen_movmem_short (dst
, src
, GEN_INT (INTVAL (len
) - 1)));
3591 else if (TARGET_MVCLE
)
3593 emit_insn (gen_movmem_long (dst
, src
, convert_to_mode (Pmode
, len
, 1)));
3598 rtx dst_addr
, src_addr
, count
, blocks
, temp
;
3599 rtx loop_start_label
= gen_label_rtx ();
3600 rtx loop_end_label
= gen_label_rtx ();
3601 rtx end_label
= gen_label_rtx ();
3602 enum machine_mode mode
;
3604 mode
= GET_MODE (len
);
3605 if (mode
== VOIDmode
)
3608 dst_addr
= gen_reg_rtx (Pmode
);
3609 src_addr
= gen_reg_rtx (Pmode
);
3610 count
= gen_reg_rtx (mode
);
3611 blocks
= gen_reg_rtx (mode
);
3613 convert_move (count
, len
, 1);
3614 emit_cmp_and_jump_insns (count
, const0_rtx
,
3615 EQ
, NULL_RTX
, mode
, 1, end_label
);
3617 emit_move_insn (dst_addr
, force_operand (XEXP (dst
, 0), NULL_RTX
));
3618 emit_move_insn (src_addr
, force_operand (XEXP (src
, 0), NULL_RTX
));
3619 dst
= change_address (dst
, VOIDmode
, dst_addr
);
3620 src
= change_address (src
, VOIDmode
, src_addr
);
3622 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1, 0);
3624 emit_move_insn (count
, temp
);
3626 temp
= expand_binop (mode
, lshr_optab
, count
, GEN_INT (8), blocks
, 1, 0);
3628 emit_move_insn (blocks
, temp
);
3630 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3631 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3633 emit_label (loop_start_label
);
3635 emit_insn (gen_movmem_short (dst
, src
, GEN_INT (255)));
3636 s390_load_address (dst_addr
,
3637 gen_rtx_PLUS (Pmode
, dst_addr
, GEN_INT (256)));
3638 s390_load_address (src_addr
,
3639 gen_rtx_PLUS (Pmode
, src_addr
, GEN_INT (256)));
3641 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1, 0);
3643 emit_move_insn (blocks
, temp
);
3645 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3646 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3648 emit_jump (loop_start_label
);
3649 emit_label (loop_end_label
);
3651 emit_insn (gen_movmem_short (dst
, src
,
3652 convert_to_mode (Pmode
, count
, 1)));
3653 emit_label (end_label
);
3657 /* Emit code to set LEN bytes at DST to VAL.
3658 Make use of clrmem if VAL is zero. */
3661 s390_expand_setmem (rtx dst
, rtx len
, rtx val
)
3663 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) == 0)
3666 gcc_assert (GET_CODE (val
) == CONST_INT
|| GET_MODE (val
) == QImode
);
3668 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) > 0 && INTVAL (len
) <= 257)
3670 if (val
== const0_rtx
&& INTVAL (len
) <= 256)
3671 emit_insn (gen_clrmem_short (dst
, GEN_INT (INTVAL (len
) - 1)));
3674 /* Initialize memory by storing the first byte. */
3675 emit_move_insn (adjust_address (dst
, QImode
, 0), val
);
3677 if (INTVAL (len
) > 1)
3679 /* Initiate 1 byte overlap move.
3680 The first byte of DST is propagated through DSTP1.
3681 Prepare a movmem for: DST+1 = DST (length = LEN - 1).
3682 DST is set to size 1 so the rest of the memory location
3683 does not count as source operand. */
3684 rtx dstp1
= adjust_address (dst
, VOIDmode
, 1);
3685 set_mem_size (dst
, const1_rtx
);
3687 emit_insn (gen_movmem_short (dstp1
, dst
,
3688 GEN_INT (INTVAL (len
) - 2)));
3693 else if (TARGET_MVCLE
)
3695 val
= force_not_mem (convert_modes (Pmode
, QImode
, val
, 1));
3696 emit_insn (gen_setmem_long (dst
, convert_to_mode (Pmode
, len
, 1), val
));
3701 rtx dst_addr
, src_addr
, count
, blocks
, temp
, dstp1
= NULL_RTX
;
3702 rtx loop_start_label
= gen_label_rtx ();
3703 rtx loop_end_label
= gen_label_rtx ();
3704 rtx end_label
= gen_label_rtx ();
3705 enum machine_mode mode
;
3707 mode
= GET_MODE (len
);
3708 if (mode
== VOIDmode
)
3711 dst_addr
= gen_reg_rtx (Pmode
);
3712 src_addr
= gen_reg_rtx (Pmode
);
3713 count
= gen_reg_rtx (mode
);
3714 blocks
= gen_reg_rtx (mode
);
3716 convert_move (count
, len
, 1);
3717 emit_cmp_and_jump_insns (count
, const0_rtx
,
3718 EQ
, NULL_RTX
, mode
, 1, end_label
);
3720 emit_move_insn (dst_addr
, force_operand (XEXP (dst
, 0), NULL_RTX
));
3721 dst
= change_address (dst
, VOIDmode
, dst_addr
);
3723 if (val
== const0_rtx
)
3724 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1, 0);
3727 dstp1
= adjust_address (dst
, VOIDmode
, 1);
3728 set_mem_size (dst
, const1_rtx
);
3730 /* Initialize memory by storing the first byte. */
3731 emit_move_insn (adjust_address (dst
, QImode
, 0), val
);
3733 /* If count is 1 we are done. */
3734 emit_cmp_and_jump_insns (count
, const1_rtx
,
3735 EQ
, NULL_RTX
, mode
, 1, end_label
);
3737 temp
= expand_binop (mode
, add_optab
, count
, GEN_INT (-2), count
, 1, 0);
3740 emit_move_insn (count
, temp
);
3742 temp
= expand_binop (mode
, lshr_optab
, count
, GEN_INT (8), blocks
, 1, 0);
3744 emit_move_insn (blocks
, temp
);
3746 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3747 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3749 emit_label (loop_start_label
);
3751 if (val
== const0_rtx
)
3752 emit_insn (gen_clrmem_short (dst
, GEN_INT (255)));
3754 emit_insn (gen_movmem_short (dstp1
, dst
, GEN_INT (255)));
3755 s390_load_address (dst_addr
,
3756 gen_rtx_PLUS (Pmode
, dst_addr
, GEN_INT (256)));
3758 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1, 0);
3760 emit_move_insn (blocks
, temp
);
3762 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3763 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3765 emit_jump (loop_start_label
);
3766 emit_label (loop_end_label
);
3768 if (val
== const0_rtx
)
3769 emit_insn (gen_clrmem_short (dst
, convert_to_mode (Pmode
, count
, 1)));
3771 emit_insn (gen_movmem_short (dstp1
, dst
, convert_to_mode (Pmode
, count
, 1)));
3772 emit_label (end_label
);
3776 /* Emit code to compare LEN bytes at OP0 with those at OP1,
3777 and return the result in TARGET. */
3780 s390_expand_cmpmem (rtx target
, rtx op0
, rtx op1
, rtx len
)
3782 rtx ccreg
= gen_rtx_REG (CCUmode
, CC_REGNUM
);
3785 /* As the result of CMPINT is inverted compared to what we need,
3786 we have to swap the operands. */
3787 tmp
= op0
; op0
= op1
; op1
= tmp
;
3789 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) >= 0 && INTVAL (len
) <= 256)
3791 if (INTVAL (len
) > 0)
3793 emit_insn (gen_cmpmem_short (op0
, op1
, GEN_INT (INTVAL (len
) - 1)));
3794 emit_insn (gen_cmpint (target
, ccreg
));
3797 emit_move_insn (target
, const0_rtx
);
3799 else if (TARGET_MVCLE
)
3801 emit_insn (gen_cmpmem_long (op0
, op1
, convert_to_mode (Pmode
, len
, 1)));
3802 emit_insn (gen_cmpint (target
, ccreg
));
3806 rtx addr0
, addr1
, count
, blocks
, temp
;
3807 rtx loop_start_label
= gen_label_rtx ();
3808 rtx loop_end_label
= gen_label_rtx ();
3809 rtx end_label
= gen_label_rtx ();
3810 enum machine_mode mode
;
3812 mode
= GET_MODE (len
);
3813 if (mode
== VOIDmode
)
3816 addr0
= gen_reg_rtx (Pmode
);
3817 addr1
= gen_reg_rtx (Pmode
);
3818 count
= gen_reg_rtx (mode
);
3819 blocks
= gen_reg_rtx (mode
);
3821 convert_move (count
, len
, 1);
3822 emit_cmp_and_jump_insns (count
, const0_rtx
,
3823 EQ
, NULL_RTX
, mode
, 1, end_label
);
3825 emit_move_insn (addr0
, force_operand (XEXP (op0
, 0), NULL_RTX
));
3826 emit_move_insn (addr1
, force_operand (XEXP (op1
, 0), NULL_RTX
));
3827 op0
= change_address (op0
, VOIDmode
, addr0
);
3828 op1
= change_address (op1
, VOIDmode
, addr1
);
3830 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1, 0);
3832 emit_move_insn (count
, temp
);
3834 temp
= expand_binop (mode
, lshr_optab
, count
, GEN_INT (8), blocks
, 1, 0);
3836 emit_move_insn (blocks
, temp
);
3838 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3839 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3841 emit_label (loop_start_label
);
3843 emit_insn (gen_cmpmem_short (op0
, op1
, GEN_INT (255)));
3844 temp
= gen_rtx_NE (VOIDmode
, ccreg
, const0_rtx
);
3845 temp
= gen_rtx_IF_THEN_ELSE (VOIDmode
, temp
,
3846 gen_rtx_LABEL_REF (VOIDmode
, end_label
), pc_rtx
);
3847 temp
= gen_rtx_SET (VOIDmode
, pc_rtx
, temp
);
3848 emit_jump_insn (temp
);
3850 s390_load_address (addr0
,
3851 gen_rtx_PLUS (Pmode
, addr0
, GEN_INT (256)));
3852 s390_load_address (addr1
,
3853 gen_rtx_PLUS (Pmode
, addr1
, GEN_INT (256)));
3855 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1, 0);
3857 emit_move_insn (blocks
, temp
);
3859 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3860 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3862 emit_jump (loop_start_label
);
3863 emit_label (loop_end_label
);
3865 emit_insn (gen_cmpmem_short (op0
, op1
,
3866 convert_to_mode (Pmode
, count
, 1)));
3867 emit_label (end_label
);
3869 emit_insn (gen_cmpint (target
, ccreg
));
3874 /* Expand conditional increment or decrement using alc/slb instructions.
3875 Should generate code setting DST to either SRC or SRC + INCREMENT,
3876 depending on the result of the comparison CMP_OP0 CMP_CODE CMP_OP1.
3877 Returns true if successful, false otherwise.
3879 That makes it possible to implement some if-constructs without jumps e.g.:
3880 (borrow = CC0 | CC1 and carry = CC2 | CC3)
3881 unsigned int a, b, c;
3882 if (a < b) c++; -> CCU b > a -> CC2; c += carry;
3883 if (a < b) c--; -> CCL3 a - b -> borrow; c -= borrow;
3884 if (a <= b) c++; -> CCL3 b - a -> borrow; c += carry;
3885 if (a <= b) c--; -> CCU a <= b -> borrow; c -= borrow;
3887 Checks for EQ and NE with a nonzero value need an additional xor e.g.:
3888 if (a == b) c++; -> CCL3 a ^= b; 0 - a -> borrow; c += carry;
3889 if (a == b) c--; -> CCU a ^= b; a <= 0 -> CC0 | CC1; c -= borrow;
3890 if (a != b) c++; -> CCU a ^= b; a > 0 -> CC2; c += carry;
3891 if (a != b) c--; -> CCL3 a ^= b; 0 - a -> borrow; c -= borrow; */
3894 s390_expand_addcc (enum rtx_code cmp_code
, rtx cmp_op0
, rtx cmp_op1
,
3895 rtx dst
, rtx src
, rtx increment
)
3897 enum machine_mode cmp_mode
;
3898 enum machine_mode cc_mode
;
3904 if ((GET_MODE (cmp_op0
) == SImode
|| GET_MODE (cmp_op0
) == VOIDmode
)
3905 && (GET_MODE (cmp_op1
) == SImode
|| GET_MODE (cmp_op1
) == VOIDmode
))
3907 else if ((GET_MODE (cmp_op0
) == DImode
|| GET_MODE (cmp_op0
) == VOIDmode
)
3908 && (GET_MODE (cmp_op1
) == DImode
|| GET_MODE (cmp_op1
) == VOIDmode
))
3913 /* Try ADD LOGICAL WITH CARRY. */
3914 if (increment
== const1_rtx
)
3916 /* Determine CC mode to use. */
3917 if (cmp_code
== EQ
|| cmp_code
== NE
)
3919 if (cmp_op1
!= const0_rtx
)
3921 cmp_op0
= expand_simple_binop (cmp_mode
, XOR
, cmp_op0
, cmp_op1
,
3922 NULL_RTX
, 0, OPTAB_WIDEN
);
3923 cmp_op1
= const0_rtx
;
3926 cmp_code
= cmp_code
== EQ
? LEU
: GTU
;
3929 if (cmp_code
== LTU
|| cmp_code
== LEU
)
3934 cmp_code
= swap_condition (cmp_code
);
3951 /* Emit comparison instruction pattern. */
3952 if (!register_operand (cmp_op0
, cmp_mode
))
3953 cmp_op0
= force_reg (cmp_mode
, cmp_op0
);
3955 insn
= gen_rtx_SET (VOIDmode
, gen_rtx_REG (cc_mode
, CC_REGNUM
),
3956 gen_rtx_COMPARE (cc_mode
, cmp_op0
, cmp_op1
));
3957 /* We use insn_invalid_p here to add clobbers if required. */
3958 ret
= insn_invalid_p (emit_insn (insn
));
3961 /* Emit ALC instruction pattern. */
3962 op_res
= gen_rtx_fmt_ee (cmp_code
, GET_MODE (dst
),
3963 gen_rtx_REG (cc_mode
, CC_REGNUM
),
3966 if (src
!= const0_rtx
)
3968 if (!register_operand (src
, GET_MODE (dst
)))
3969 src
= force_reg (GET_MODE (dst
), src
);
3971 op_res
= gen_rtx_PLUS (GET_MODE (dst
), op_res
, src
);
3972 op_res
= gen_rtx_PLUS (GET_MODE (dst
), op_res
, const0_rtx
);
3975 p
= rtvec_alloc (2);
3977 gen_rtx_SET (VOIDmode
, dst
, op_res
);
3979 gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
3980 emit_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
3985 /* Try SUBTRACT LOGICAL WITH BORROW. */
3986 if (increment
== constm1_rtx
)
3988 /* Determine CC mode to use. */
3989 if (cmp_code
== EQ
|| cmp_code
== NE
)
3991 if (cmp_op1
!= const0_rtx
)
3993 cmp_op0
= expand_simple_binop (cmp_mode
, XOR
, cmp_op0
, cmp_op1
,
3994 NULL_RTX
, 0, OPTAB_WIDEN
);
3995 cmp_op1
= const0_rtx
;
3998 cmp_code
= cmp_code
== EQ
? LEU
: GTU
;
4001 if (cmp_code
== GTU
|| cmp_code
== GEU
)
4006 cmp_code
= swap_condition (cmp_code
);
4023 /* Emit comparison instruction pattern. */
4024 if (!register_operand (cmp_op0
, cmp_mode
))
4025 cmp_op0
= force_reg (cmp_mode
, cmp_op0
);
4027 insn
= gen_rtx_SET (VOIDmode
, gen_rtx_REG (cc_mode
, CC_REGNUM
),
4028 gen_rtx_COMPARE (cc_mode
, cmp_op0
, cmp_op1
));
4029 /* We use insn_invalid_p here to add clobbers if required. */
4030 ret
= insn_invalid_p (emit_insn (insn
));
4033 /* Emit SLB instruction pattern. */
4034 if (!register_operand (src
, GET_MODE (dst
)))
4035 src
= force_reg (GET_MODE (dst
), src
);
4037 op_res
= gen_rtx_MINUS (GET_MODE (dst
),
4038 gen_rtx_MINUS (GET_MODE (dst
), src
, const0_rtx
),
4039 gen_rtx_fmt_ee (cmp_code
, GET_MODE (dst
),
4040 gen_rtx_REG (cc_mode
, CC_REGNUM
),
4042 p
= rtvec_alloc (2);
4044 gen_rtx_SET (VOIDmode
, dst
, op_res
);
4046 gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
4047 emit_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
4055 /* Expand code for the insv template. Return true if successful, false else. */
4058 s390_expand_insv (rtx dest
, rtx op1
, rtx op2
, rtx src
)
4060 int bitsize
= INTVAL (op1
);
4061 int bitpos
= INTVAL (op2
);
4063 /* We need byte alignment. */
4064 if (bitsize
% BITS_PER_UNIT
)
4068 && memory_operand (dest
, VOIDmode
)
4069 && (register_operand (src
, word_mode
)
4070 || const_int_operand (src
, VOIDmode
)))
4072 /* Emit standard pattern if possible. */
4073 enum machine_mode mode
= smallest_mode_for_size (bitsize
, MODE_INT
);
4074 if (GET_MODE_BITSIZE (mode
) == bitsize
)
4075 emit_move_insn (adjust_address (dest
, mode
, 0), gen_lowpart (mode
, src
));
4077 /* (set (ze (mem)) (const_int)). */
4078 else if (const_int_operand (src
, VOIDmode
))
4080 int size
= bitsize
/ BITS_PER_UNIT
;
4081 rtx src_mem
= adjust_address (force_const_mem (word_mode
, src
), BLKmode
,
4082 GET_MODE_SIZE (word_mode
) - size
);
4084 dest
= adjust_address (dest
, BLKmode
, 0);
4085 set_mem_size (dest
, GEN_INT (size
));
4086 s390_expand_movmem (dest
, src_mem
, GEN_INT (size
));
4089 /* (set (ze (mem)) (reg)). */
4090 else if (register_operand (src
, word_mode
))
4092 if (bitsize
<= GET_MODE_BITSIZE (SImode
))
4093 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
, op1
,
4097 /* Emit st,stcmh sequence. */
4098 int stcmh_width
= bitsize
- GET_MODE_BITSIZE (SImode
);
4099 int size
= stcmh_width
/ BITS_PER_UNIT
;
4101 emit_move_insn (adjust_address (dest
, SImode
, size
),
4102 gen_lowpart (SImode
, src
));
4103 set_mem_size (dest
, GEN_INT (size
));
4104 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
, GEN_INT
4105 (stcmh_width
), const0_rtx
),
4106 gen_rtx_LSHIFTRT (word_mode
, src
, GEN_INT
4107 (GET_MODE_BITSIZE (SImode
))));
4116 /* (set (ze (reg)) (const_int)). */
4118 && register_operand (dest
, word_mode
)
4119 && (bitpos
% 16) == 0
4120 && (bitsize
% 16) == 0
4121 && const_int_operand (src
, VOIDmode
))
4123 HOST_WIDE_INT val
= INTVAL (src
);
4124 int regpos
= bitpos
+ bitsize
;
4126 while (regpos
> bitpos
)
4128 enum machine_mode putmode
;
4131 if (TARGET_EXTIMM
&& (regpos
% 32 == 0) && (regpos
>= bitpos
+ 32))
4136 putsize
= GET_MODE_BITSIZE (putmode
);
4138 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
,
4141 gen_int_mode (val
, putmode
));
4144 gcc_assert (regpos
== bitpos
);
4151 /* A subroutine of s390_expand_cs_hqi and s390_expand_atomic which returns a
4152 register that holds VAL of mode MODE shifted by COUNT bits. */
4155 s390_expand_mask_and_shift (rtx val
, enum machine_mode mode
, rtx count
)
4157 val
= expand_simple_binop (SImode
, AND
, val
, GEN_INT (GET_MODE_MASK (mode
)),
4158 NULL_RTX
, 1, OPTAB_DIRECT
);
4159 return expand_simple_binop (SImode
, ASHIFT
, val
, count
,
4160 NULL_RTX
, 1, OPTAB_DIRECT
);
4163 /* Structure to hold the initial parameters for a compare_and_swap operation
4164 in HImode and QImode. */
4166 struct alignment_context
4168 rtx memsi
; /* SI aligned memory location. */
4169 rtx shift
; /* Bit offset with regard to lsb. */
4170 rtx modemask
; /* Mask of the HQImode shifted by SHIFT bits. */
4171 rtx modemaski
; /* ~modemask */
4172 bool aligned
; /* True if memory is aligned, false else. */
4175 /* A subroutine of s390_expand_cs_hqi and s390_expand_atomic to initialize
4176 structure AC for transparent simplifying, if the memory alignment is known
4177 to be at least 32bit. MEM is the memory location for the actual operation
4178 and MODE its mode. */
4181 init_alignment_context (struct alignment_context
*ac
, rtx mem
,
4182 enum machine_mode mode
)
4184 ac
->shift
= GEN_INT (GET_MODE_SIZE (SImode
) - GET_MODE_SIZE (mode
));
4185 ac
->aligned
= (MEM_ALIGN (mem
) >= GET_MODE_BITSIZE (SImode
));
4188 ac
->memsi
= adjust_address (mem
, SImode
, 0); /* Memory is aligned. */
4191 /* Alignment is unknown. */
4192 rtx byteoffset
, addr
, align
;
4194 /* Force the address into a register. */
4195 addr
= force_reg (Pmode
, XEXP (mem
, 0));
4197 /* Align it to SImode. */
4198 align
= expand_simple_binop (Pmode
, AND
, addr
,
4199 GEN_INT (-GET_MODE_SIZE (SImode
)),
4200 NULL_RTX
, 1, OPTAB_DIRECT
);
4202 ac
->memsi
= gen_rtx_MEM (SImode
, align
);
4203 MEM_VOLATILE_P (ac
->memsi
) = MEM_VOLATILE_P (mem
);
4204 set_mem_alias_set (ac
->memsi
, ALIAS_SET_MEMORY_BARRIER
);
4205 set_mem_align (ac
->memsi
, GET_MODE_BITSIZE (SImode
));
4207 /* Calculate shiftcount. */
4208 byteoffset
= expand_simple_binop (Pmode
, AND
, addr
,
4209 GEN_INT (GET_MODE_SIZE (SImode
) - 1),
4210 NULL_RTX
, 1, OPTAB_DIRECT
);
4211 /* As we already have some offset, evaluate the remaining distance. */
4212 ac
->shift
= expand_simple_binop (SImode
, MINUS
, ac
->shift
, byteoffset
,
4213 NULL_RTX
, 1, OPTAB_DIRECT
);
4216 /* Shift is the byte count, but we need the bitcount. */
4217 ac
->shift
= expand_simple_binop (SImode
, MULT
, ac
->shift
, GEN_INT (BITS_PER_UNIT
),
4218 NULL_RTX
, 1, OPTAB_DIRECT
);
4219 /* Calculate masks. */
4220 ac
->modemask
= expand_simple_binop (SImode
, ASHIFT
,
4221 GEN_INT (GET_MODE_MASK (mode
)), ac
->shift
,
4222 NULL_RTX
, 1, OPTAB_DIRECT
);
4223 ac
->modemaski
= expand_simple_unop (SImode
, NOT
, ac
->modemask
, NULL_RTX
, 1);
4226 /* Expand an atomic compare and swap operation for HImode and QImode. MEM is
4227 the memory location, CMP the old value to compare MEM with and NEW the value
4228 to set if CMP == MEM.
4229 CMP is never in memory for compare_and_swap_cc because
4230 expand_bool_compare_and_swap puts it into a register for later compare. */
4233 s390_expand_cs_hqi (enum machine_mode mode
, rtx target
, rtx mem
, rtx cmp
, rtx
new)
4235 struct alignment_context ac
;
4236 rtx cmpv
, newv
, val
, resv
, cc
;
4237 rtx res
= gen_reg_rtx (SImode
);
4238 rtx csloop
= gen_label_rtx ();
4239 rtx csend
= gen_label_rtx ();
4241 gcc_assert (register_operand (target
, VOIDmode
));
4242 gcc_assert (MEM_P (mem
));
4244 init_alignment_context (&ac
, mem
, mode
);
4246 /* Shift the values to the correct bit positions. */
4247 if (!(ac
.aligned
&& MEM_P (cmp
)))
4248 cmp
= s390_expand_mask_and_shift (cmp
, mode
, ac
.shift
);
4249 if (!(ac
.aligned
&& MEM_P (new)))
4250 new = s390_expand_mask_and_shift (new, mode
, ac
.shift
);
4252 /* Load full word. Subsequent loads are performed by CS. */
4253 val
= expand_simple_binop (SImode
, AND
, ac
.memsi
, ac
.modemaski
,
4254 NULL_RTX
, 1, OPTAB_DIRECT
);
4256 /* Start CS loop. */
4257 emit_label (csloop
);
4258 /* val = "<mem>00..0<mem>"
4259 * cmp = "00..0<cmp>00..0"
4260 * new = "00..0<new>00..0"
4263 /* Patch cmp and new with val at correct position. */
4264 if (ac
.aligned
&& MEM_P (cmp
))
4266 cmpv
= force_reg (SImode
, val
);
4267 store_bit_field (cmpv
, GET_MODE_BITSIZE (mode
), 0, SImode
, cmp
);
4270 cmpv
= force_reg (SImode
, expand_simple_binop (SImode
, IOR
, cmp
, val
,
4271 NULL_RTX
, 1, OPTAB_DIRECT
));
4272 if (ac
.aligned
&& MEM_P (new))
4274 newv
= force_reg (SImode
, val
);
4275 store_bit_field (newv
, GET_MODE_BITSIZE (mode
), 0, SImode
, new);
4278 newv
= force_reg (SImode
, expand_simple_binop (SImode
, IOR
, new, val
,
4279 NULL_RTX
, 1, OPTAB_DIRECT
));
4281 /* Jump to end if we're done (likely?). */
4282 s390_emit_jump (csend
, s390_emit_compare_and_swap (EQ
, res
, ac
.memsi
,
4285 /* Check for changes outside mode. */
4286 resv
= expand_simple_binop (SImode
, AND
, res
, ac
.modemaski
,
4287 NULL_RTX
, 1, OPTAB_DIRECT
);
4288 cc
= s390_emit_compare (NE
, resv
, val
);
4289 emit_move_insn (val
, resv
);
4290 /* Loop internal if so. */
4291 s390_emit_jump (csloop
, cc
);
4295 /* Return the correct part of the bitfield. */
4296 convert_move (target
, expand_simple_binop (SImode
, LSHIFTRT
, res
, ac
.shift
,
4297 NULL_RTX
, 1, OPTAB_DIRECT
), 1);
4300 /* Expand an atomic operation CODE of mode MODE. MEM is the memory location
4301 and VAL the value to play with. If AFTER is true then store the value
4302 MEM holds after the operation, if AFTER is false then store the value MEM
4303 holds before the operation. If TARGET is zero then discard that value, else
4304 store it to TARGET. */
4307 s390_expand_atomic (enum machine_mode mode
, enum rtx_code code
,
4308 rtx target
, rtx mem
, rtx val
, bool after
)
4310 struct alignment_context ac
;
4312 rtx
new = gen_reg_rtx (SImode
);
4313 rtx orig
= gen_reg_rtx (SImode
);
4314 rtx csloop
= gen_label_rtx ();
4316 gcc_assert (!target
|| register_operand (target
, VOIDmode
));
4317 gcc_assert (MEM_P (mem
));
4319 init_alignment_context (&ac
, mem
, mode
);
4321 /* Shift val to the correct bit positions.
4322 Preserve "icm", but prevent "ex icm". */
4323 if (!(ac
.aligned
&& code
== SET
&& MEM_P (val
)))
4324 val
= s390_expand_mask_and_shift (val
, mode
, ac
.shift
);
4326 /* Further preparation insns. */
4327 if (code
== PLUS
|| code
== MINUS
)
4328 emit_move_insn (orig
, val
);
4329 else if (code
== MULT
|| code
== AND
) /* val = "11..1<val>11..1" */
4330 val
= expand_simple_binop (SImode
, XOR
, val
, ac
.modemaski
,
4331 NULL_RTX
, 1, OPTAB_DIRECT
);
4333 /* Load full word. Subsequent loads are performed by CS. */
4334 cmp
= force_reg (SImode
, ac
.memsi
);
4336 /* Start CS loop. */
4337 emit_label (csloop
);
4338 emit_move_insn (new, cmp
);
4340 /* Patch new with val at correct position. */
4345 val
= expand_simple_binop (SImode
, code
, new, orig
,
4346 NULL_RTX
, 1, OPTAB_DIRECT
);
4347 val
= expand_simple_binop (SImode
, AND
, val
, ac
.modemask
,
4348 NULL_RTX
, 1, OPTAB_DIRECT
);
4351 if (ac
.aligned
&& MEM_P (val
))
4352 store_bit_field (new, GET_MODE_BITSIZE (mode
), 0, SImode
, val
);
4355 new = expand_simple_binop (SImode
, AND
, new, ac
.modemaski
,
4356 NULL_RTX
, 1, OPTAB_DIRECT
);
4357 new = expand_simple_binop (SImode
, IOR
, new, val
,
4358 NULL_RTX
, 1, OPTAB_DIRECT
);
4364 new = expand_simple_binop (SImode
, code
, new, val
,
4365 NULL_RTX
, 1, OPTAB_DIRECT
);
4367 case MULT
: /* NAND */
4368 new = expand_simple_binop (SImode
, XOR
, new, ac
.modemask
,
4369 NULL_RTX
, 1, OPTAB_DIRECT
);
4370 new = expand_simple_binop (SImode
, AND
, new, val
,
4371 NULL_RTX
, 1, OPTAB_DIRECT
);
4377 s390_emit_jump (csloop
, s390_emit_compare_and_swap (NE
, cmp
,
4378 ac
.memsi
, cmp
, new));
4380 /* Return the correct part of the bitfield. */
4382 convert_move (target
, expand_simple_binop (SImode
, LSHIFTRT
,
4383 after
? new : cmp
, ac
.shift
,
4384 NULL_RTX
, 1, OPTAB_DIRECT
), 1);
4387 /* This is called from dwarf2out.c via TARGET_ASM_OUTPUT_DWARF_DTPREL.
4388 We need to emit DTP-relative relocations. */
4390 static void s390_output_dwarf_dtprel (FILE *, int, rtx
) ATTRIBUTE_UNUSED
;
4393 s390_output_dwarf_dtprel (FILE *file
, int size
, rtx x
)
4398 fputs ("\t.long\t", file
);
4401 fputs ("\t.quad\t", file
);
4406 output_addr_const (file
, x
);
4407 fputs ("@DTPOFF", file
);
4410 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
4411 /* Implement TARGET_MANGLE_TYPE. */
4414 s390_mangle_type (const_tree type
)
4416 if (TYPE_MAIN_VARIANT (type
) == long_double_type_node
4417 && TARGET_LONG_DOUBLE_128
)
4420 /* For all other types, use normal C++ mangling. */
4425 /* In the name of slightly smaller debug output, and to cater to
4426 general assembler lossage, recognize various UNSPEC sequences
4427 and turn them back into a direct symbol reference. */
4430 s390_delegitimize_address (rtx orig_x
)
4434 if (GET_CODE (x
) != MEM
)
4438 if (GET_CODE (x
) == PLUS
4439 && GET_CODE (XEXP (x
, 1)) == CONST
4440 && GET_CODE (XEXP (x
, 0)) == REG
4441 && REGNO (XEXP (x
, 0)) == PIC_OFFSET_TABLE_REGNUM
)
4443 y
= XEXP (XEXP (x
, 1), 0);
4444 if (GET_CODE (y
) == UNSPEC
4445 && XINT (y
, 1) == UNSPEC_GOT
)
4446 return XVECEXP (y
, 0, 0);
4450 if (GET_CODE (x
) == CONST
)
4453 if (GET_CODE (y
) == UNSPEC
4454 && XINT (y
, 1) == UNSPEC_GOTENT
)
4455 return XVECEXP (y
, 0, 0);
4462 /* Output operand OP to stdio stream FILE.
4463 OP is an address (register + offset) which is not used to address data;
4464 instead the rightmost bits are interpreted as the value. */
4467 print_shift_count_operand (FILE *file
, rtx op
)
4469 HOST_WIDE_INT offset
;
4472 /* Extract base register and offset. */
4473 if (!s390_decompose_shift_count (op
, &base
, &offset
))
4479 gcc_assert (GET_CODE (base
) == REG
);
4480 gcc_assert (REGNO (base
) < FIRST_PSEUDO_REGISTER
);
4481 gcc_assert (REGNO_REG_CLASS (REGNO (base
)) == ADDR_REGS
);
4484 /* Offsets are constricted to twelve bits. */
4485 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, offset
& ((1 << 12) - 1));
4487 fprintf (file
, "(%s)", reg_names
[REGNO (base
)]);
4490 /* See 'get_some_local_dynamic_name'. */
4493 get_some_local_dynamic_name_1 (rtx
*px
, void *data ATTRIBUTE_UNUSED
)
4497 if (GET_CODE (x
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (x
))
4499 x
= get_pool_constant (x
);
4500 return for_each_rtx (&x
, get_some_local_dynamic_name_1
, 0);
4503 if (GET_CODE (x
) == SYMBOL_REF
4504 && tls_symbolic_operand (x
) == TLS_MODEL_LOCAL_DYNAMIC
)
4506 cfun
->machine
->some_ld_name
= XSTR (x
, 0);
4513 /* Locate some local-dynamic symbol still in use by this function
4514 so that we can print its name in local-dynamic base patterns. */
4517 get_some_local_dynamic_name (void)
4521 if (cfun
->machine
->some_ld_name
)
4522 return cfun
->machine
->some_ld_name
;
4524 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
4526 && for_each_rtx (&PATTERN (insn
), get_some_local_dynamic_name_1
, 0))
4527 return cfun
->machine
->some_ld_name
;
4532 /* Output machine-dependent UNSPECs occurring in address constant X
4533 in assembler syntax to stdio stream FILE. Returns true if the
4534 constant X could be recognized, false otherwise. */
4537 s390_output_addr_const_extra (FILE *file
, rtx x
)
4539 if (GET_CODE (x
) == UNSPEC
&& XVECLEN (x
, 0) == 1)
4540 switch (XINT (x
, 1))
4543 output_addr_const (file
, XVECEXP (x
, 0, 0));
4544 fprintf (file
, "@GOTENT");
4547 output_addr_const (file
, XVECEXP (x
, 0, 0));
4548 fprintf (file
, "@GOT");
4551 output_addr_const (file
, XVECEXP (x
, 0, 0));
4552 fprintf (file
, "@GOTOFF");
4555 output_addr_const (file
, XVECEXP (x
, 0, 0));
4556 fprintf (file
, "@PLT");
4559 output_addr_const (file
, XVECEXP (x
, 0, 0));
4560 fprintf (file
, "@PLTOFF");
4563 output_addr_const (file
, XVECEXP (x
, 0, 0));
4564 fprintf (file
, "@TLSGD");
4567 assemble_name (file
, get_some_local_dynamic_name ());
4568 fprintf (file
, "@TLSLDM");
4571 output_addr_const (file
, XVECEXP (x
, 0, 0));
4572 fprintf (file
, "@DTPOFF");
4575 output_addr_const (file
, XVECEXP (x
, 0, 0));
4576 fprintf (file
, "@NTPOFF");
4578 case UNSPEC_GOTNTPOFF
:
4579 output_addr_const (file
, XVECEXP (x
, 0, 0));
4580 fprintf (file
, "@GOTNTPOFF");
4582 case UNSPEC_INDNTPOFF
:
4583 output_addr_const (file
, XVECEXP (x
, 0, 0));
4584 fprintf (file
, "@INDNTPOFF");
4591 /* Output address operand ADDR in assembler syntax to
4592 stdio stream FILE. */
4595 print_operand_address (FILE *file
, rtx addr
)
4597 struct s390_address ad
;
4599 if (!s390_decompose_address (addr
, &ad
)
4600 || (ad
.base
&& !REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)))
4601 || (ad
.indx
&& !REGNO_OK_FOR_INDEX_P (REGNO (ad
.indx
))))
4602 output_operand_lossage ("cannot decompose address");
4605 output_addr_const (file
, ad
.disp
);
4607 fprintf (file
, "0");
4609 if (ad
.base
&& ad
.indx
)
4610 fprintf (file
, "(%s,%s)", reg_names
[REGNO (ad
.indx
)],
4611 reg_names
[REGNO (ad
.base
)]);
4613 fprintf (file
, "(%s)", reg_names
[REGNO (ad
.base
)]);
4616 /* Output operand X in assembler syntax to stdio stream FILE.
4617 CODE specified the format flag. The following format flags
4620 'C': print opcode suffix for branch condition.
4621 'D': print opcode suffix for inverse branch condition.
4622 'J': print tls_load/tls_gdcall/tls_ldcall suffix
4623 'G': print the size of the operand in bytes.
4624 'O': print only the displacement of a memory reference.
4625 'R': print only the base register of a memory reference.
4626 'S': print S-type memory reference (base+displacement).
4627 'N': print the second word of a DImode operand.
4628 'M': print the second word of a TImode operand.
4629 'Y': print shift count operand.
4631 'b': print integer X as if it's an unsigned byte.
4632 'x': print integer X as if it's an unsigned halfword.
4633 'h': print integer X as if it's a signed halfword.
4634 'i': print the first nonzero HImode part of X.
4635 'j': print the first HImode part unequal to -1 of X.
4636 'k': print the first nonzero SImode part of X.
4637 'm': print the first SImode part unequal to -1 of X.
4638 'o': print integer X as if it's an unsigned 32bit word. */
4641 print_operand (FILE *file
, rtx x
, int code
)
4646 fprintf (file
, s390_branch_condition_mnemonic (x
, FALSE
));
4650 fprintf (file
, s390_branch_condition_mnemonic (x
, TRUE
));
4654 if (GET_CODE (x
) == SYMBOL_REF
)
4656 fprintf (file
, "%s", ":tls_load:");
4657 output_addr_const (file
, x
);
4659 else if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_TLSGD
)
4661 fprintf (file
, "%s", ":tls_gdcall:");
4662 output_addr_const (file
, XVECEXP (x
, 0, 0));
4664 else if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_TLSLDM
)
4666 fprintf (file
, "%s", ":tls_ldcall:");
4667 assemble_name (file
, get_some_local_dynamic_name ());
4674 fprintf (file
, "%u", GET_MODE_SIZE (GET_MODE (x
)));
4679 struct s390_address ad
;
4682 gcc_assert (GET_CODE (x
) == MEM
);
4683 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
4685 gcc_assert (!ad
.base
|| REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)));
4686 gcc_assert (!ad
.indx
);
4689 output_addr_const (file
, ad
.disp
);
4691 fprintf (file
, "0");
4697 struct s390_address ad
;
4700 gcc_assert (GET_CODE (x
) == MEM
);
4701 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
4703 gcc_assert (!ad
.base
|| REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)));
4704 gcc_assert (!ad
.indx
);
4707 fprintf (file
, "%s", reg_names
[REGNO (ad
.base
)]);
4709 fprintf (file
, "0");
4715 struct s390_address ad
;
4718 gcc_assert (GET_CODE (x
) == MEM
);
4719 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
4721 gcc_assert (!ad
.base
|| REGNO_OK_FOR_BASE_P (REGNO (ad
.base
)));
4722 gcc_assert (!ad
.indx
);
4725 output_addr_const (file
, ad
.disp
);
4727 fprintf (file
, "0");
4730 fprintf (file
, "(%s)", reg_names
[REGNO (ad
.base
)]);
4735 if (GET_CODE (x
) == REG
)
4736 x
= gen_rtx_REG (GET_MODE (x
), REGNO (x
) + 1);
4737 else if (GET_CODE (x
) == MEM
)
4738 x
= change_address (x
, VOIDmode
, plus_constant (XEXP (x
, 0), 4));
4744 if (GET_CODE (x
) == REG
)
4745 x
= gen_rtx_REG (GET_MODE (x
), REGNO (x
) + 1);
4746 else if (GET_CODE (x
) == MEM
)
4747 x
= change_address (x
, VOIDmode
, plus_constant (XEXP (x
, 0), 8));
4753 print_shift_count_operand (file
, x
);
4757 switch (GET_CODE (x
))
4760 fprintf (file
, "%s", reg_names
[REGNO (x
)]);
4764 output_address (XEXP (x
, 0));
4771 output_addr_const (file
, x
);
4776 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
) & 0xff);
4777 else if (code
== 'x')
4778 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
) & 0xffff);
4779 else if (code
== 'h')
4780 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, ((INTVAL (x
) & 0xffff) ^ 0x8000) - 0x8000);
4781 else if (code
== 'i')
4782 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
4783 s390_extract_part (x
, HImode
, 0));
4784 else if (code
== 'j')
4785 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
4786 s390_extract_part (x
, HImode
, -1));
4787 else if (code
== 'k')
4788 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
4789 s390_extract_part (x
, SImode
, 0));
4790 else if (code
== 'm')
4791 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
4792 s390_extract_part (x
, SImode
, -1));
4793 else if (code
== 'o')
4794 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
) & 0xffffffff);
4796 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
));
4800 gcc_assert (GET_MODE (x
) == VOIDmode
);
4802 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, CONST_DOUBLE_LOW (x
) & 0xff);
4803 else if (code
== 'x')
4804 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, CONST_DOUBLE_LOW (x
) & 0xffff);
4805 else if (code
== 'h')
4806 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, ((CONST_DOUBLE_LOW (x
) & 0xffff) ^ 0x8000) - 0x8000);
4812 fatal_insn ("UNKNOWN in print_operand !?", x
);
4817 /* Target hook for assembling integer objects. We need to define it
4818 here to work a round a bug in some versions of GAS, which couldn't
4819 handle values smaller than INT_MIN when printed in decimal. */
4822 s390_assemble_integer (rtx x
, unsigned int size
, int aligned_p
)
4824 if (size
== 8 && aligned_p
4825 && GET_CODE (x
) == CONST_INT
&& INTVAL (x
) < INT_MIN
)
4827 fprintf (asm_out_file
, "\t.quad\t" HOST_WIDE_INT_PRINT_HEX
"\n",
4831 return default_assemble_integer (x
, size
, aligned_p
);
4834 /* Returns true if register REGNO is used for forming
4835 a memory address in expression X. */
4838 reg_used_in_mem_p (int regno
, rtx x
)
4840 enum rtx_code code
= GET_CODE (x
);
4846 if (refers_to_regno_p (regno
, regno
+1,
4850 else if (code
== SET
4851 && GET_CODE (SET_DEST (x
)) == PC
)
4853 if (refers_to_regno_p (regno
, regno
+1,
4858 fmt
= GET_RTX_FORMAT (code
);
4859 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4862 && reg_used_in_mem_p (regno
, XEXP (x
, i
)))
4865 else if (fmt
[i
] == 'E')
4866 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
4867 if (reg_used_in_mem_p (regno
, XVECEXP (x
, i
, j
)))
4873 /* Returns true if expression DEP_RTX sets an address register
4874 used by instruction INSN to address memory. */
4877 addr_generation_dependency_p (rtx dep_rtx
, rtx insn
)
4881 if (GET_CODE (dep_rtx
) == INSN
)
4882 dep_rtx
= PATTERN (dep_rtx
);
4884 if (GET_CODE (dep_rtx
) == SET
)
4886 target
= SET_DEST (dep_rtx
);
4887 if (GET_CODE (target
) == STRICT_LOW_PART
)
4888 target
= XEXP (target
, 0);
4889 while (GET_CODE (target
) == SUBREG
)
4890 target
= SUBREG_REG (target
);
4892 if (GET_CODE (target
) == REG
)
4894 int regno
= REGNO (target
);
4896 if (s390_safe_attr_type (insn
) == TYPE_LA
)
4898 pat
= PATTERN (insn
);
4899 if (GET_CODE (pat
) == PARALLEL
)
4901 gcc_assert (XVECLEN (pat
, 0) == 2);
4902 pat
= XVECEXP (pat
, 0, 0);
4904 gcc_assert (GET_CODE (pat
) == SET
);
4905 return refers_to_regno_p (regno
, regno
+1, SET_SRC (pat
), 0);
4907 else if (get_attr_atype (insn
) == ATYPE_AGEN
)
4908 return reg_used_in_mem_p (regno
, PATTERN (insn
));
4914 /* Return 1, if dep_insn sets register used in insn in the agen unit. */
4917 s390_agen_dep_p (rtx dep_insn
, rtx insn
)
4919 rtx dep_rtx
= PATTERN (dep_insn
);
4922 if (GET_CODE (dep_rtx
) == SET
4923 && addr_generation_dependency_p (dep_rtx
, insn
))
4925 else if (GET_CODE (dep_rtx
) == PARALLEL
)
4927 for (i
= 0; i
< XVECLEN (dep_rtx
, 0); i
++)
4929 if (addr_generation_dependency_p (XVECEXP (dep_rtx
, 0, i
), insn
))
4936 /* A C statement (sans semicolon) to update the integer scheduling priority
4937 INSN_PRIORITY (INSN). Increase the priority to execute the INSN earlier,
4938 reduce the priority to execute INSN later. Do not define this macro if
4939 you do not need to adjust the scheduling priorities of insns.
4941 A STD instruction should be scheduled earlier,
4942 in order to use the bypass. */
4945 s390_adjust_priority (rtx insn ATTRIBUTE_UNUSED
, int priority
)
4947 if (! INSN_P (insn
))
4950 if (s390_tune
!= PROCESSOR_2084_Z990
4951 && s390_tune
!= PROCESSOR_2094_Z9_109
)
4954 switch (s390_safe_attr_type (insn
))
4958 priority
= priority
<< 3;
4962 priority
= priority
<< 1;
4970 /* The number of instructions that can be issued per cycle. */
4973 s390_issue_rate (void)
4977 case PROCESSOR_2084_Z990
:
4978 case PROCESSOR_2094_Z9_109
:
4980 case PROCESSOR_2097_Z10
:
4988 s390_first_cycle_multipass_dfa_lookahead (void)
4994 /* Annotate every literal pool reference in X by an UNSPEC_LTREF expression.
4995 Fix up MEMs as required. */
4998 annotate_constant_pool_refs (rtx
*x
)
5003 gcc_assert (GET_CODE (*x
) != SYMBOL_REF
5004 || !CONSTANT_POOL_ADDRESS_P (*x
));
5006 /* Literal pool references can only occur inside a MEM ... */
5007 if (GET_CODE (*x
) == MEM
)
5009 rtx memref
= XEXP (*x
, 0);
5011 if (GET_CODE (memref
) == SYMBOL_REF
5012 && CONSTANT_POOL_ADDRESS_P (memref
))
5014 rtx base
= cfun
->machine
->base_reg
;
5015 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, memref
, base
),
5018 *x
= replace_equiv_address (*x
, addr
);
5022 if (GET_CODE (memref
) == CONST
5023 && GET_CODE (XEXP (memref
, 0)) == PLUS
5024 && GET_CODE (XEXP (XEXP (memref
, 0), 1)) == CONST_INT
5025 && GET_CODE (XEXP (XEXP (memref
, 0), 0)) == SYMBOL_REF
5026 && CONSTANT_POOL_ADDRESS_P (XEXP (XEXP (memref
, 0), 0)))
5028 HOST_WIDE_INT off
= INTVAL (XEXP (XEXP (memref
, 0), 1));
5029 rtx sym
= XEXP (XEXP (memref
, 0), 0);
5030 rtx base
= cfun
->machine
->base_reg
;
5031 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, sym
, base
),
5034 *x
= replace_equiv_address (*x
, plus_constant (addr
, off
));
5039 /* ... or a load-address type pattern. */
5040 if (GET_CODE (*x
) == SET
)
5042 rtx addrref
= SET_SRC (*x
);
5044 if (GET_CODE (addrref
) == SYMBOL_REF
5045 && CONSTANT_POOL_ADDRESS_P (addrref
))
5047 rtx base
= cfun
->machine
->base_reg
;
5048 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, addrref
, base
),
5051 SET_SRC (*x
) = addr
;
5055 if (GET_CODE (addrref
) == CONST
5056 && GET_CODE (XEXP (addrref
, 0)) == PLUS
5057 && GET_CODE (XEXP (XEXP (addrref
, 0), 1)) == CONST_INT
5058 && GET_CODE (XEXP (XEXP (addrref
, 0), 0)) == SYMBOL_REF
5059 && CONSTANT_POOL_ADDRESS_P (XEXP (XEXP (addrref
, 0), 0)))
5061 HOST_WIDE_INT off
= INTVAL (XEXP (XEXP (addrref
, 0), 1));
5062 rtx sym
= XEXP (XEXP (addrref
, 0), 0);
5063 rtx base
= cfun
->machine
->base_reg
;
5064 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, sym
, base
),
5067 SET_SRC (*x
) = plus_constant (addr
, off
);
5072 /* Annotate LTREL_BASE as well. */
5073 if (GET_CODE (*x
) == UNSPEC
5074 && XINT (*x
, 1) == UNSPEC_LTREL_BASE
)
5076 rtx base
= cfun
->machine
->base_reg
;
5077 *x
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, XVECEXP (*x
, 0, 0), base
),
5082 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
5083 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
5087 annotate_constant_pool_refs (&XEXP (*x
, i
));
5089 else if (fmt
[i
] == 'E')
5091 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
5092 annotate_constant_pool_refs (&XVECEXP (*x
, i
, j
));
5097 /* Split all branches that exceed the maximum distance.
5098 Returns true if this created a new literal pool entry. */
5101 s390_split_branches (void)
5103 rtx temp_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
5104 int new_literal
= 0, ret
;
5105 rtx insn
, pat
, tmp
, target
;
5108 /* We need correct insn addresses. */
5110 shorten_branches (get_insns ());
5112 /* Find all branches that exceed 64KB, and split them. */
5114 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5116 if (GET_CODE (insn
) != JUMP_INSN
)
5119 pat
= PATTERN (insn
);
5120 if (GET_CODE (pat
) == PARALLEL
&& XVECLEN (pat
, 0) > 2)
5121 pat
= XVECEXP (pat
, 0, 0);
5122 if (GET_CODE (pat
) != SET
|| SET_DEST (pat
) != pc_rtx
)
5125 if (GET_CODE (SET_SRC (pat
)) == LABEL_REF
)
5127 label
= &SET_SRC (pat
);
5129 else if (GET_CODE (SET_SRC (pat
)) == IF_THEN_ELSE
)
5131 if (GET_CODE (XEXP (SET_SRC (pat
), 1)) == LABEL_REF
)
5132 label
= &XEXP (SET_SRC (pat
), 1);
5133 else if (GET_CODE (XEXP (SET_SRC (pat
), 2)) == LABEL_REF
)
5134 label
= &XEXP (SET_SRC (pat
), 2);
5141 if (get_attr_length (insn
) <= 4)
5144 /* We are going to use the return register as scratch register,
5145 make sure it will be saved/restored by the prologue/epilogue. */
5146 cfun_frame_layout
.save_return_addr_p
= 1;
5151 tmp
= force_const_mem (Pmode
, *label
);
5152 tmp
= emit_insn_before (gen_rtx_SET (Pmode
, temp_reg
, tmp
), insn
);
5153 INSN_ADDRESSES_NEW (tmp
, -1);
5154 annotate_constant_pool_refs (&PATTERN (tmp
));
5161 target
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, *label
),
5162 UNSPEC_LTREL_OFFSET
);
5163 target
= gen_rtx_CONST (Pmode
, target
);
5164 target
= force_const_mem (Pmode
, target
);
5165 tmp
= emit_insn_before (gen_rtx_SET (Pmode
, temp_reg
, target
), insn
);
5166 INSN_ADDRESSES_NEW (tmp
, -1);
5167 annotate_constant_pool_refs (&PATTERN (tmp
));
5169 target
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, XEXP (target
, 0),
5170 cfun
->machine
->base_reg
),
5172 target
= gen_rtx_PLUS (Pmode
, temp_reg
, target
);
5175 ret
= validate_change (insn
, label
, target
, 0);
5183 /* Find an annotated literal pool symbol referenced in RTX X,
5184 and store it at REF. Will abort if X contains references to
5185 more than one such pool symbol; multiple references to the same
5186 symbol are allowed, however.
5188 The rtx pointed to by REF must be initialized to NULL_RTX
5189 by the caller before calling this routine. */
5192 find_constant_pool_ref (rtx x
, rtx
*ref
)
5197 /* Ignore LTREL_BASE references. */
5198 if (GET_CODE (x
) == UNSPEC
5199 && XINT (x
, 1) == UNSPEC_LTREL_BASE
)
5201 /* Likewise POOL_ENTRY insns. */
5202 if (GET_CODE (x
) == UNSPEC_VOLATILE
5203 && XINT (x
, 1) == UNSPECV_POOL_ENTRY
)
5206 gcc_assert (GET_CODE (x
) != SYMBOL_REF
5207 || !CONSTANT_POOL_ADDRESS_P (x
));
5209 if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_LTREF
)
5211 rtx sym
= XVECEXP (x
, 0, 0);
5212 gcc_assert (GET_CODE (sym
) == SYMBOL_REF
5213 && CONSTANT_POOL_ADDRESS_P (sym
));
5215 if (*ref
== NULL_RTX
)
5218 gcc_assert (*ref
== sym
);
5223 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
5224 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
5228 find_constant_pool_ref (XEXP (x
, i
), ref
);
5230 else if (fmt
[i
] == 'E')
5232 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
5233 find_constant_pool_ref (XVECEXP (x
, i
, j
), ref
);
5238 /* Replace every reference to the annotated literal pool
5239 symbol REF in X by its base plus OFFSET. */
5242 replace_constant_pool_ref (rtx
*x
, rtx ref
, rtx offset
)
5247 gcc_assert (*x
!= ref
);
5249 if (GET_CODE (*x
) == UNSPEC
5250 && XINT (*x
, 1) == UNSPEC_LTREF
5251 && XVECEXP (*x
, 0, 0) == ref
)
5253 *x
= gen_rtx_PLUS (Pmode
, XVECEXP (*x
, 0, 1), offset
);
5257 if (GET_CODE (*x
) == PLUS
5258 && GET_CODE (XEXP (*x
, 1)) == CONST_INT
5259 && GET_CODE (XEXP (*x
, 0)) == UNSPEC
5260 && XINT (XEXP (*x
, 0), 1) == UNSPEC_LTREF
5261 && XVECEXP (XEXP (*x
, 0), 0, 0) == ref
)
5263 rtx addr
= gen_rtx_PLUS (Pmode
, XVECEXP (XEXP (*x
, 0), 0, 1), offset
);
5264 *x
= plus_constant (addr
, INTVAL (XEXP (*x
, 1)));
5268 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
5269 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
5273 replace_constant_pool_ref (&XEXP (*x
, i
), ref
, offset
);
5275 else if (fmt
[i
] == 'E')
5277 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
5278 replace_constant_pool_ref (&XVECEXP (*x
, i
, j
), ref
, offset
);
5283 /* Check whether X contains an UNSPEC_LTREL_BASE.
5284 Return its constant pool symbol if found, NULL_RTX otherwise. */
5287 find_ltrel_base (rtx x
)
5292 if (GET_CODE (x
) == UNSPEC
5293 && XINT (x
, 1) == UNSPEC_LTREL_BASE
)
5294 return XVECEXP (x
, 0, 0);
5296 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
5297 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
5301 rtx fnd
= find_ltrel_base (XEXP (x
, i
));
5305 else if (fmt
[i
] == 'E')
5307 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
5309 rtx fnd
= find_ltrel_base (XVECEXP (x
, i
, j
));
5319 /* Replace any occurrence of UNSPEC_LTREL_BASE in X with its base. */
5322 replace_ltrel_base (rtx
*x
)
5327 if (GET_CODE (*x
) == UNSPEC
5328 && XINT (*x
, 1) == UNSPEC_LTREL_BASE
)
5330 *x
= XVECEXP (*x
, 0, 1);
5334 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
5335 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
5339 replace_ltrel_base (&XEXP (*x
, i
));
5341 else if (fmt
[i
] == 'E')
5343 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
5344 replace_ltrel_base (&XVECEXP (*x
, i
, j
));
5350 /* We keep a list of constants which we have to add to internal
5351 constant tables in the middle of large functions. */
5353 #define NR_C_MODES 11
5354 enum machine_mode constant_modes
[NR_C_MODES
] =
5356 TFmode
, TImode
, TDmode
,
5357 DFmode
, DImode
, DDmode
,
5358 SFmode
, SImode
, SDmode
,
5365 struct constant
*next
;
5370 struct constant_pool
5372 struct constant_pool
*next
;
5376 rtx emit_pool_after
;
5378 struct constant
*constants
[NR_C_MODES
];
5379 struct constant
*execute
;
5384 /* Allocate new constant_pool structure. */
5386 static struct constant_pool
*
5387 s390_alloc_pool (void)
5389 struct constant_pool
*pool
;
5392 pool
= (struct constant_pool
*) xmalloc (sizeof *pool
);
5394 for (i
= 0; i
< NR_C_MODES
; i
++)
5395 pool
->constants
[i
] = NULL
;
5397 pool
->execute
= NULL
;
5398 pool
->label
= gen_label_rtx ();
5399 pool
->first_insn
= NULL_RTX
;
5400 pool
->pool_insn
= NULL_RTX
;
5401 pool
->insns
= BITMAP_ALLOC (NULL
);
5403 pool
->emit_pool_after
= NULL_RTX
;
5408 /* Create new constant pool covering instructions starting at INSN
5409 and chain it to the end of POOL_LIST. */
5411 static struct constant_pool
*
5412 s390_start_pool (struct constant_pool
**pool_list
, rtx insn
)
5414 struct constant_pool
*pool
, **prev
;
5416 pool
= s390_alloc_pool ();
5417 pool
->first_insn
= insn
;
5419 for (prev
= pool_list
; *prev
; prev
= &(*prev
)->next
)
5426 /* End range of instructions covered by POOL at INSN and emit
5427 placeholder insn representing the pool. */
5430 s390_end_pool (struct constant_pool
*pool
, rtx insn
)
5432 rtx pool_size
= GEN_INT (pool
->size
+ 8 /* alignment slop */);
5435 insn
= get_last_insn ();
5437 pool
->pool_insn
= emit_insn_after (gen_pool (pool_size
), insn
);
5438 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
5441 /* Add INSN to the list of insns covered by POOL. */
5444 s390_add_pool_insn (struct constant_pool
*pool
, rtx insn
)
5446 bitmap_set_bit (pool
->insns
, INSN_UID (insn
));
5449 /* Return pool out of POOL_LIST that covers INSN. */
5451 static struct constant_pool
*
5452 s390_find_pool (struct constant_pool
*pool_list
, rtx insn
)
5454 struct constant_pool
*pool
;
5456 for (pool
= pool_list
; pool
; pool
= pool
->next
)
5457 if (bitmap_bit_p (pool
->insns
, INSN_UID (insn
)))
5463 /* Add constant VAL of mode MODE to the constant pool POOL. */
5466 s390_add_constant (struct constant_pool
*pool
, rtx val
, enum machine_mode mode
)
5471 for (i
= 0; i
< NR_C_MODES
; i
++)
5472 if (constant_modes
[i
] == mode
)
5474 gcc_assert (i
!= NR_C_MODES
);
5476 for (c
= pool
->constants
[i
]; c
!= NULL
; c
= c
->next
)
5477 if (rtx_equal_p (val
, c
->value
))
5482 c
= (struct constant
*) xmalloc (sizeof *c
);
5484 c
->label
= gen_label_rtx ();
5485 c
->next
= pool
->constants
[i
];
5486 pool
->constants
[i
] = c
;
5487 pool
->size
+= GET_MODE_SIZE (mode
);
5491 /* Find constant VAL of mode MODE in the constant pool POOL.
5492 Return an RTX describing the distance from the start of
5493 the pool to the location of the new constant. */
5496 s390_find_constant (struct constant_pool
*pool
, rtx val
,
5497 enum machine_mode mode
)
5503 for (i
= 0; i
< NR_C_MODES
; i
++)
5504 if (constant_modes
[i
] == mode
)
5506 gcc_assert (i
!= NR_C_MODES
);
5508 for (c
= pool
->constants
[i
]; c
!= NULL
; c
= c
->next
)
5509 if (rtx_equal_p (val
, c
->value
))
5514 offset
= gen_rtx_MINUS (Pmode
, gen_rtx_LABEL_REF (Pmode
, c
->label
),
5515 gen_rtx_LABEL_REF (Pmode
, pool
->label
));
5516 offset
= gen_rtx_CONST (Pmode
, offset
);
5520 /* Check whether INSN is an execute. Return the label_ref to its
5521 execute target template if so, NULL_RTX otherwise. */
5524 s390_execute_label (rtx insn
)
5526 if (GET_CODE (insn
) == INSN
5527 && GET_CODE (PATTERN (insn
)) == PARALLEL
5528 && GET_CODE (XVECEXP (PATTERN (insn
), 0, 0)) == UNSPEC
5529 && XINT (XVECEXP (PATTERN (insn
), 0, 0), 1) == UNSPEC_EXECUTE
)
5530 return XVECEXP (XVECEXP (PATTERN (insn
), 0, 0), 0, 2);
5535 /* Add execute target for INSN to the constant pool POOL. */
5538 s390_add_execute (struct constant_pool
*pool
, rtx insn
)
5542 for (c
= pool
->execute
; c
!= NULL
; c
= c
->next
)
5543 if (INSN_UID (insn
) == INSN_UID (c
->value
))
5548 c
= (struct constant
*) xmalloc (sizeof *c
);
5550 c
->label
= gen_label_rtx ();
5551 c
->next
= pool
->execute
;
5557 /* Find execute target for INSN in the constant pool POOL.
5558 Return an RTX describing the distance from the start of
5559 the pool to the location of the execute target. */
5562 s390_find_execute (struct constant_pool
*pool
, rtx insn
)
5567 for (c
= pool
->execute
; c
!= NULL
; c
= c
->next
)
5568 if (INSN_UID (insn
) == INSN_UID (c
->value
))
5573 offset
= gen_rtx_MINUS (Pmode
, gen_rtx_LABEL_REF (Pmode
, c
->label
),
5574 gen_rtx_LABEL_REF (Pmode
, pool
->label
));
5575 offset
= gen_rtx_CONST (Pmode
, offset
);
5579 /* For an execute INSN, extract the execute target template. */
5582 s390_execute_target (rtx insn
)
5584 rtx pattern
= PATTERN (insn
);
5585 gcc_assert (s390_execute_label (insn
));
5587 if (XVECLEN (pattern
, 0) == 2)
5589 pattern
= copy_rtx (XVECEXP (pattern
, 0, 1));
5593 rtvec vec
= rtvec_alloc (XVECLEN (pattern
, 0) - 1);
5596 for (i
= 0; i
< XVECLEN (pattern
, 0) - 1; i
++)
5597 RTVEC_ELT (vec
, i
) = copy_rtx (XVECEXP (pattern
, 0, i
+ 1));
5599 pattern
= gen_rtx_PARALLEL (VOIDmode
, vec
);
5605 /* Indicate that INSN cannot be duplicated. This is the case for
5606 execute insns that carry a unique label. */
5609 s390_cannot_copy_insn_p (rtx insn
)
5611 rtx label
= s390_execute_label (insn
);
5612 return label
&& label
!= const0_rtx
;
5615 /* Dump out the constants in POOL. If REMOTE_LABEL is true,
5616 do not emit the pool base label. */
5619 s390_dump_pool (struct constant_pool
*pool
, bool remote_label
)
5622 rtx insn
= pool
->pool_insn
;
5625 /* Switch to rodata section. */
5626 if (TARGET_CPU_ZARCH
)
5628 insn
= emit_insn_after (gen_pool_section_start (), insn
);
5629 INSN_ADDRESSES_NEW (insn
, -1);
5632 /* Ensure minimum pool alignment. */
5633 if (TARGET_CPU_ZARCH
)
5634 insn
= emit_insn_after (gen_pool_align (GEN_INT (8)), insn
);
5636 insn
= emit_insn_after (gen_pool_align (GEN_INT (4)), insn
);
5637 INSN_ADDRESSES_NEW (insn
, -1);
5639 /* Emit pool base label. */
5642 insn
= emit_label_after (pool
->label
, insn
);
5643 INSN_ADDRESSES_NEW (insn
, -1);
5646 /* Dump constants in descending alignment requirement order,
5647 ensuring proper alignment for every constant. */
5648 for (i
= 0; i
< NR_C_MODES
; i
++)
5649 for (c
= pool
->constants
[i
]; c
; c
= c
->next
)
5651 /* Convert UNSPEC_LTREL_OFFSET unspecs to pool-relative references. */
5652 rtx value
= copy_rtx (c
->value
);
5653 if (GET_CODE (value
) == CONST
5654 && GET_CODE (XEXP (value
, 0)) == UNSPEC
5655 && XINT (XEXP (value
, 0), 1) == UNSPEC_LTREL_OFFSET
5656 && XVECLEN (XEXP (value
, 0), 0) == 1)
5658 value
= gen_rtx_MINUS (Pmode
, XVECEXP (XEXP (value
, 0), 0, 0),
5659 gen_rtx_LABEL_REF (VOIDmode
, pool
->label
));
5660 value
= gen_rtx_CONST (VOIDmode
, value
);
5663 insn
= emit_label_after (c
->label
, insn
);
5664 INSN_ADDRESSES_NEW (insn
, -1);
5666 value
= gen_rtx_UNSPEC_VOLATILE (constant_modes
[i
],
5667 gen_rtvec (1, value
),
5668 UNSPECV_POOL_ENTRY
);
5669 insn
= emit_insn_after (value
, insn
);
5670 INSN_ADDRESSES_NEW (insn
, -1);
5673 /* Ensure minimum alignment for instructions. */
5674 insn
= emit_insn_after (gen_pool_align (GEN_INT (2)), insn
);
5675 INSN_ADDRESSES_NEW (insn
, -1);
5677 /* Output in-pool execute template insns. */
5678 for (c
= pool
->execute
; c
; c
= c
->next
)
5680 insn
= emit_label_after (c
->label
, insn
);
5681 INSN_ADDRESSES_NEW (insn
, -1);
5683 insn
= emit_insn_after (s390_execute_target (c
->value
), insn
);
5684 INSN_ADDRESSES_NEW (insn
, -1);
5687 /* Switch back to previous section. */
5688 if (TARGET_CPU_ZARCH
)
5690 insn
= emit_insn_after (gen_pool_section_end (), insn
);
5691 INSN_ADDRESSES_NEW (insn
, -1);
5694 insn
= emit_barrier_after (insn
);
5695 INSN_ADDRESSES_NEW (insn
, -1);
5697 /* Remove placeholder insn. */
5698 remove_insn (pool
->pool_insn
);
5701 /* Free all memory used by POOL. */
5704 s390_free_pool (struct constant_pool
*pool
)
5706 struct constant
*c
, *next
;
5709 for (i
= 0; i
< NR_C_MODES
; i
++)
5710 for (c
= pool
->constants
[i
]; c
; c
= next
)
5716 for (c
= pool
->execute
; c
; c
= next
)
5722 BITMAP_FREE (pool
->insns
);
5727 /* Collect main literal pool. Return NULL on overflow. */
5729 static struct constant_pool
*
5730 s390_mainpool_start (void)
5732 struct constant_pool
*pool
;
5735 pool
= s390_alloc_pool ();
5737 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5739 if (GET_CODE (insn
) == INSN
5740 && GET_CODE (PATTERN (insn
)) == SET
5741 && GET_CODE (SET_SRC (PATTERN (insn
))) == UNSPEC_VOLATILE
5742 && XINT (SET_SRC (PATTERN (insn
)), 1) == UNSPECV_MAIN_POOL
)
5744 gcc_assert (!pool
->pool_insn
);
5745 pool
->pool_insn
= insn
;
5748 if (!TARGET_CPU_ZARCH
&& s390_execute_label (insn
))
5750 s390_add_execute (pool
, insn
);
5752 else if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
5754 rtx pool_ref
= NULL_RTX
;
5755 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
5758 rtx constant
= get_pool_constant (pool_ref
);
5759 enum machine_mode mode
= get_pool_mode (pool_ref
);
5760 s390_add_constant (pool
, constant
, mode
);
5764 /* If hot/cold partitioning is enabled we have to make sure that
5765 the literal pool is emitted in the same section where the
5766 initialization of the literal pool base pointer takes place.
5767 emit_pool_after is only used in the non-overflow case on non
5768 Z cpus where we can emit the literal pool at the end of the
5769 function body within the text section. */
5771 && NOTE_KIND (insn
) == NOTE_INSN_SWITCH_TEXT_SECTIONS
5772 && !pool
->emit_pool_after
)
5773 pool
->emit_pool_after
= PREV_INSN (insn
);
5776 gcc_assert (pool
->pool_insn
|| pool
->size
== 0);
5778 if (pool
->size
>= 4096)
5780 /* We're going to chunkify the pool, so remove the main
5781 pool placeholder insn. */
5782 remove_insn (pool
->pool_insn
);
5784 s390_free_pool (pool
);
5788 /* If the functions ends with the section where the literal pool
5789 should be emitted set the marker to its end. */
5790 if (pool
&& !pool
->emit_pool_after
)
5791 pool
->emit_pool_after
= get_last_insn ();
5796 /* POOL holds the main literal pool as collected by s390_mainpool_start.
5797 Modify the current function to output the pool constants as well as
5798 the pool register setup instruction. */
5801 s390_mainpool_finish (struct constant_pool
*pool
)
5803 rtx base_reg
= cfun
->machine
->base_reg
;
5806 /* If the pool is empty, we're done. */
5807 if (pool
->size
== 0)
5809 /* We don't actually need a base register after all. */
5810 cfun
->machine
->base_reg
= NULL_RTX
;
5812 if (pool
->pool_insn
)
5813 remove_insn (pool
->pool_insn
);
5814 s390_free_pool (pool
);
5818 /* We need correct insn addresses. */
5819 shorten_branches (get_insns ());
5821 /* On zSeries, we use a LARL to load the pool register. The pool is
5822 located in the .rodata section, so we emit it after the function. */
5823 if (TARGET_CPU_ZARCH
)
5825 insn
= gen_main_base_64 (base_reg
, pool
->label
);
5826 insn
= emit_insn_after (insn
, pool
->pool_insn
);
5827 INSN_ADDRESSES_NEW (insn
, -1);
5828 remove_insn (pool
->pool_insn
);
5830 insn
= get_last_insn ();
5831 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
5832 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
5834 s390_dump_pool (pool
, 0);
5837 /* On S/390, if the total size of the function's code plus literal pool
5838 does not exceed 4096 bytes, we use BASR to set up a function base
5839 pointer, and emit the literal pool at the end of the function. */
5840 else if (INSN_ADDRESSES (INSN_UID (pool
->emit_pool_after
))
5841 + pool
->size
+ 8 /* alignment slop */ < 4096)
5843 insn
= gen_main_base_31_small (base_reg
, pool
->label
);
5844 insn
= emit_insn_after (insn
, pool
->pool_insn
);
5845 INSN_ADDRESSES_NEW (insn
, -1);
5846 remove_insn (pool
->pool_insn
);
5848 insn
= emit_label_after (pool
->label
, insn
);
5849 INSN_ADDRESSES_NEW (insn
, -1);
5851 /* emit_pool_after will be set by s390_mainpool_start to the
5852 last insn of the section where the literal pool should be
5854 insn
= pool
->emit_pool_after
;
5856 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
5857 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
5859 s390_dump_pool (pool
, 1);
5862 /* Otherwise, we emit an inline literal pool and use BASR to branch
5863 over it, setting up the pool register at the same time. */
5866 rtx pool_end
= gen_label_rtx ();
5868 insn
= gen_main_base_31_large (base_reg
, pool
->label
, pool_end
);
5869 insn
= emit_insn_after (insn
, pool
->pool_insn
);
5870 INSN_ADDRESSES_NEW (insn
, -1);
5871 remove_insn (pool
->pool_insn
);
5873 insn
= emit_label_after (pool
->label
, insn
);
5874 INSN_ADDRESSES_NEW (insn
, -1);
5876 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
5877 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
5879 insn
= emit_label_after (pool_end
, pool
->pool_insn
);
5880 INSN_ADDRESSES_NEW (insn
, -1);
5882 s390_dump_pool (pool
, 1);
5886 /* Replace all literal pool references. */
5888 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5891 replace_ltrel_base (&PATTERN (insn
));
5893 if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
5895 rtx addr
, pool_ref
= NULL_RTX
;
5896 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
5899 if (s390_execute_label (insn
))
5900 addr
= s390_find_execute (pool
, insn
);
5902 addr
= s390_find_constant (pool
, get_pool_constant (pool_ref
),
5903 get_pool_mode (pool_ref
));
5905 replace_constant_pool_ref (&PATTERN (insn
), pool_ref
, addr
);
5906 INSN_CODE (insn
) = -1;
5912 /* Free the pool. */
5913 s390_free_pool (pool
);
5916 /* POOL holds the main literal pool as collected by s390_mainpool_start.
5917 We have decided we cannot use this pool, so revert all changes
5918 to the current function that were done by s390_mainpool_start. */
5920 s390_mainpool_cancel (struct constant_pool
*pool
)
5922 /* We didn't actually change the instruction stream, so simply
5923 free the pool memory. */
5924 s390_free_pool (pool
);
5928 /* Chunkify the literal pool. */
5930 #define S390_POOL_CHUNK_MIN 0xc00
5931 #define S390_POOL_CHUNK_MAX 0xe00
5933 static struct constant_pool
*
5934 s390_chunkify_start (void)
5936 struct constant_pool
*curr_pool
= NULL
, *pool_list
= NULL
;
5939 rtx pending_ltrel
= NULL_RTX
;
5942 rtx (*gen_reload_base
) (rtx
, rtx
) =
5943 TARGET_CPU_ZARCH
? gen_reload_base_64
: gen_reload_base_31
;
5946 /* We need correct insn addresses. */
5948 shorten_branches (get_insns ());
5950 /* Scan all insns and move literals to pool chunks. */
5952 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5954 bool section_switch_p
= false;
5956 /* Check for pending LTREL_BASE. */
5959 rtx ltrel_base
= find_ltrel_base (PATTERN (insn
));
5962 gcc_assert (ltrel_base
== pending_ltrel
);
5963 pending_ltrel
= NULL_RTX
;
5967 if (!TARGET_CPU_ZARCH
&& s390_execute_label (insn
))
5970 curr_pool
= s390_start_pool (&pool_list
, insn
);
5972 s390_add_execute (curr_pool
, insn
);
5973 s390_add_pool_insn (curr_pool
, insn
);
5975 else if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
5977 rtx pool_ref
= NULL_RTX
;
5978 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
5981 rtx constant
= get_pool_constant (pool_ref
);
5982 enum machine_mode mode
= get_pool_mode (pool_ref
);
5985 curr_pool
= s390_start_pool (&pool_list
, insn
);
5987 s390_add_constant (curr_pool
, constant
, mode
);
5988 s390_add_pool_insn (curr_pool
, insn
);
5990 /* Don't split the pool chunk between a LTREL_OFFSET load
5991 and the corresponding LTREL_BASE. */
5992 if (GET_CODE (constant
) == CONST
5993 && GET_CODE (XEXP (constant
, 0)) == UNSPEC
5994 && XINT (XEXP (constant
, 0), 1) == UNSPEC_LTREL_OFFSET
)
5996 gcc_assert (!pending_ltrel
);
5997 pending_ltrel
= pool_ref
;
6002 if (GET_CODE (insn
) == JUMP_INSN
|| GET_CODE (insn
) == CODE_LABEL
)
6005 s390_add_pool_insn (curr_pool
, insn
);
6006 /* An LTREL_BASE must follow within the same basic block. */
6007 gcc_assert (!pending_ltrel
);
6010 if (NOTE_P (insn
) && NOTE_KIND (insn
) == NOTE_INSN_SWITCH_TEXT_SECTIONS
)
6011 section_switch_p
= true;
6014 || INSN_ADDRESSES_SIZE () <= (size_t) INSN_UID (insn
)
6015 || INSN_ADDRESSES (INSN_UID (insn
)) == -1)
6018 if (TARGET_CPU_ZARCH
)
6020 if (curr_pool
->size
< S390_POOL_CHUNK_MAX
)
6023 s390_end_pool (curr_pool
, NULL_RTX
);
6028 int chunk_size
= INSN_ADDRESSES (INSN_UID (insn
))
6029 - INSN_ADDRESSES (INSN_UID (curr_pool
->first_insn
))
6032 /* We will later have to insert base register reload insns.
6033 Those will have an effect on code size, which we need to
6034 consider here. This calculation makes rather pessimistic
6035 worst-case assumptions. */
6036 if (GET_CODE (insn
) == CODE_LABEL
)
6039 if (chunk_size
< S390_POOL_CHUNK_MIN
6040 && curr_pool
->size
< S390_POOL_CHUNK_MIN
6041 && !section_switch_p
)
6044 /* Pool chunks can only be inserted after BARRIERs ... */
6045 if (GET_CODE (insn
) == BARRIER
)
6047 s390_end_pool (curr_pool
, insn
);
6052 /* ... so if we don't find one in time, create one. */
6053 else if (chunk_size
> S390_POOL_CHUNK_MAX
6054 || curr_pool
->size
> S390_POOL_CHUNK_MAX
6055 || section_switch_p
)
6057 rtx label
, jump
, barrier
;
6059 if (!section_switch_p
)
6061 /* We can insert the barrier only after a 'real' insn. */
6062 if (GET_CODE (insn
) != INSN
&& GET_CODE (insn
) != CALL_INSN
)
6064 if (get_attr_length (insn
) == 0)
6066 /* Don't separate LTREL_BASE from the corresponding
6067 LTREL_OFFSET load. */
6073 gcc_assert (!pending_ltrel
);
6075 /* The old pool has to end before the section switch
6076 note in order to make it part of the current
6078 insn
= PREV_INSN (insn
);
6081 label
= gen_label_rtx ();
6082 jump
= emit_jump_insn_after (gen_jump (label
), insn
);
6083 barrier
= emit_barrier_after (jump
);
6084 insn
= emit_label_after (label
, barrier
);
6085 JUMP_LABEL (jump
) = label
;
6086 LABEL_NUSES (label
) = 1;
6088 INSN_ADDRESSES_NEW (jump
, -1);
6089 INSN_ADDRESSES_NEW (barrier
, -1);
6090 INSN_ADDRESSES_NEW (insn
, -1);
6092 s390_end_pool (curr_pool
, barrier
);
6100 s390_end_pool (curr_pool
, NULL_RTX
);
6101 gcc_assert (!pending_ltrel
);
6103 /* Find all labels that are branched into
6104 from an insn belonging to a different chunk. */
6106 far_labels
= BITMAP_ALLOC (NULL
);
6108 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6110 /* Labels marked with LABEL_PRESERVE_P can be target
6111 of non-local jumps, so we have to mark them.
6112 The same holds for named labels.
6114 Don't do that, however, if it is the label before
6117 if (GET_CODE (insn
) == CODE_LABEL
6118 && (LABEL_PRESERVE_P (insn
) || LABEL_NAME (insn
)))
6120 rtx vec_insn
= next_real_insn (insn
);
6121 rtx vec_pat
= vec_insn
&& GET_CODE (vec_insn
) == JUMP_INSN
?
6122 PATTERN (vec_insn
) : NULL_RTX
;
6124 || !(GET_CODE (vec_pat
) == ADDR_VEC
6125 || GET_CODE (vec_pat
) == ADDR_DIFF_VEC
))
6126 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (insn
));
6129 /* If we have a direct jump (conditional or unconditional)
6130 or a casesi jump, check all potential targets. */
6131 else if (GET_CODE (insn
) == JUMP_INSN
)
6133 rtx pat
= PATTERN (insn
);
6134 if (GET_CODE (pat
) == PARALLEL
&& XVECLEN (pat
, 0) > 2)
6135 pat
= XVECEXP (pat
, 0, 0);
6137 if (GET_CODE (pat
) == SET
)
6139 rtx label
= JUMP_LABEL (insn
);
6142 if (s390_find_pool (pool_list
, label
)
6143 != s390_find_pool (pool_list
, insn
))
6144 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (label
));
6147 else if (GET_CODE (pat
) == PARALLEL
6148 && XVECLEN (pat
, 0) == 2
6149 && GET_CODE (XVECEXP (pat
, 0, 0)) == SET
6150 && GET_CODE (XVECEXP (pat
, 0, 1)) == USE
6151 && GET_CODE (XEXP (XVECEXP (pat
, 0, 1), 0)) == LABEL_REF
)
6153 /* Find the jump table used by this casesi jump. */
6154 rtx vec_label
= XEXP (XEXP (XVECEXP (pat
, 0, 1), 0), 0);
6155 rtx vec_insn
= next_real_insn (vec_label
);
6156 rtx vec_pat
= vec_insn
&& GET_CODE (vec_insn
) == JUMP_INSN
?
6157 PATTERN (vec_insn
) : NULL_RTX
;
6159 && (GET_CODE (vec_pat
) == ADDR_VEC
6160 || GET_CODE (vec_pat
) == ADDR_DIFF_VEC
))
6162 int i
, diff_p
= GET_CODE (vec_pat
) == ADDR_DIFF_VEC
;
6164 for (i
= 0; i
< XVECLEN (vec_pat
, diff_p
); i
++)
6166 rtx label
= XEXP (XVECEXP (vec_pat
, diff_p
, i
), 0);
6168 if (s390_find_pool (pool_list
, label
)
6169 != s390_find_pool (pool_list
, insn
))
6170 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (label
));
6177 /* Insert base register reload insns before every pool. */
6179 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
6181 rtx new_insn
= gen_reload_base (cfun
->machine
->base_reg
,
6183 rtx insn
= curr_pool
->first_insn
;
6184 INSN_ADDRESSES_NEW (emit_insn_before (new_insn
, insn
), -1);
6187 /* Insert base register reload insns at every far label. */
6189 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6190 if (GET_CODE (insn
) == CODE_LABEL
6191 && bitmap_bit_p (far_labels
, CODE_LABEL_NUMBER (insn
)))
6193 struct constant_pool
*pool
= s390_find_pool (pool_list
, insn
);
6196 rtx new_insn
= gen_reload_base (cfun
->machine
->base_reg
,
6198 INSN_ADDRESSES_NEW (emit_insn_after (new_insn
, insn
), -1);
6203 BITMAP_FREE (far_labels
);
6206 /* Recompute insn addresses. */
6208 init_insn_lengths ();
6209 shorten_branches (get_insns ());
6214 /* POOL_LIST is a chunk list as prepared by s390_chunkify_start.
6215 After we have decided to use this list, finish implementing
6216 all changes to the current function as required. */
6219 s390_chunkify_finish (struct constant_pool
*pool_list
)
6221 struct constant_pool
*curr_pool
= NULL
;
6225 /* Replace all literal pool references. */
6227 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6230 replace_ltrel_base (&PATTERN (insn
));
6232 curr_pool
= s390_find_pool (pool_list
, insn
);
6236 if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
6238 rtx addr
, pool_ref
= NULL_RTX
;
6239 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
6242 if (s390_execute_label (insn
))
6243 addr
= s390_find_execute (curr_pool
, insn
);
6245 addr
= s390_find_constant (curr_pool
,
6246 get_pool_constant (pool_ref
),
6247 get_pool_mode (pool_ref
));
6249 replace_constant_pool_ref (&PATTERN (insn
), pool_ref
, addr
);
6250 INSN_CODE (insn
) = -1;
6255 /* Dump out all literal pools. */
6257 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
6258 s390_dump_pool (curr_pool
, 0);
6260 /* Free pool list. */
6264 struct constant_pool
*next
= pool_list
->next
;
6265 s390_free_pool (pool_list
);
6270 /* POOL_LIST is a chunk list as prepared by s390_chunkify_start.
6271 We have decided we cannot use this list, so revert all changes
6272 to the current function that were done by s390_chunkify_start. */
6275 s390_chunkify_cancel (struct constant_pool
*pool_list
)
6277 struct constant_pool
*curr_pool
= NULL
;
6280 /* Remove all pool placeholder insns. */
6282 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
6284 /* Did we insert an extra barrier? Remove it. */
6285 rtx barrier
= PREV_INSN (curr_pool
->pool_insn
);
6286 rtx jump
= barrier
? PREV_INSN (barrier
) : NULL_RTX
;
6287 rtx label
= NEXT_INSN (curr_pool
->pool_insn
);
6289 if (jump
&& GET_CODE (jump
) == JUMP_INSN
6290 && barrier
&& GET_CODE (barrier
) == BARRIER
6291 && label
&& GET_CODE (label
) == CODE_LABEL
6292 && GET_CODE (PATTERN (jump
)) == SET
6293 && SET_DEST (PATTERN (jump
)) == pc_rtx
6294 && GET_CODE (SET_SRC (PATTERN (jump
))) == LABEL_REF
6295 && XEXP (SET_SRC (PATTERN (jump
)), 0) == label
)
6298 remove_insn (barrier
);
6299 remove_insn (label
);
6302 remove_insn (curr_pool
->pool_insn
);
6305 /* Remove all base register reload insns. */
6307 for (insn
= get_insns (); insn
; )
6309 rtx next_insn
= NEXT_INSN (insn
);
6311 if (GET_CODE (insn
) == INSN
6312 && GET_CODE (PATTERN (insn
)) == SET
6313 && GET_CODE (SET_SRC (PATTERN (insn
))) == UNSPEC
6314 && XINT (SET_SRC (PATTERN (insn
)), 1) == UNSPEC_RELOAD_BASE
)
6320 /* Free pool list. */
6324 struct constant_pool
*next
= pool_list
->next
;
6325 s390_free_pool (pool_list
);
6331 /* Output the constant pool entry EXP in mode MODE with alignment ALIGN. */
6334 s390_output_pool_entry (rtx exp
, enum machine_mode mode
, unsigned int align
)
6338 switch (GET_MODE_CLASS (mode
))
6341 case MODE_DECIMAL_FLOAT
:
6342 gcc_assert (GET_CODE (exp
) == CONST_DOUBLE
);
6344 REAL_VALUE_FROM_CONST_DOUBLE (r
, exp
);
6345 assemble_real (r
, mode
, align
);
6349 assemble_integer (exp
, GET_MODE_SIZE (mode
), align
, 1);
6358 /* Return an RTL expression representing the value of the return address
6359 for the frame COUNT steps up from the current frame. FRAME is the
6360 frame pointer of that frame. */
6363 s390_return_addr_rtx (int count
, rtx frame ATTRIBUTE_UNUSED
)
6368 /* Without backchain, we fail for all but the current frame. */
6370 if (!TARGET_BACKCHAIN
&& count
> 0)
6373 /* For the current frame, we need to make sure the initial
6374 value of RETURN_REGNUM is actually saved. */
6378 /* On non-z architectures branch splitting could overwrite r14. */
6379 if (TARGET_CPU_ZARCH
)
6380 return get_hard_reg_initial_val (Pmode
, RETURN_REGNUM
);
6383 cfun_frame_layout
.save_return_addr_p
= true;
6384 return gen_rtx_MEM (Pmode
, return_address_pointer_rtx
);
6388 if (TARGET_PACKED_STACK
)
6389 offset
= -2 * UNITS_PER_WORD
;
6391 offset
= RETURN_REGNUM
* UNITS_PER_WORD
;
6393 addr
= plus_constant (frame
, offset
);
6394 addr
= memory_address (Pmode
, addr
);
6395 return gen_rtx_MEM (Pmode
, addr
);
6398 /* Return an RTL expression representing the back chain stored in
6399 the current stack frame. */
6402 s390_back_chain_rtx (void)
6406 gcc_assert (TARGET_BACKCHAIN
);
6408 if (TARGET_PACKED_STACK
)
6409 chain
= plus_constant (stack_pointer_rtx
,
6410 STACK_POINTER_OFFSET
- UNITS_PER_WORD
);
6412 chain
= stack_pointer_rtx
;
6414 chain
= gen_rtx_MEM (Pmode
, chain
);
6418 /* Find first call clobbered register unused in a function.
6419 This could be used as base register in a leaf function
6420 or for holding the return address before epilogue. */
6423 find_unused_clobbered_reg (void)
6426 for (i
= 0; i
< 6; i
++)
6427 if (!df_regs_ever_live_p (i
))
6433 /* Helper function for s390_regs_ever_clobbered. Sets the fields in DATA for all
6434 clobbered hard regs in SETREG. */
6437 s390_reg_clobbered_rtx (rtx setreg
, const_rtx set_insn ATTRIBUTE_UNUSED
, void *data
)
6439 int *regs_ever_clobbered
= (int *)data
;
6440 unsigned int i
, regno
;
6441 enum machine_mode mode
= GET_MODE (setreg
);
6443 if (GET_CODE (setreg
) == SUBREG
)
6445 rtx inner
= SUBREG_REG (setreg
);
6446 if (!GENERAL_REG_P (inner
))
6448 regno
= subreg_regno (setreg
);
6450 else if (GENERAL_REG_P (setreg
))
6451 regno
= REGNO (setreg
);
6456 i
< regno
+ HARD_REGNO_NREGS (regno
, mode
);
6458 regs_ever_clobbered
[i
] = 1;
6461 /* Walks through all basic blocks of the current function looking
6462 for clobbered hard regs using s390_reg_clobbered_rtx. The fields
6463 of the passed integer array REGS_EVER_CLOBBERED are set to one for
6464 each of those regs. */
6467 s390_regs_ever_clobbered (int *regs_ever_clobbered
)
6473 memset (regs_ever_clobbered
, 0, 16 * sizeof (int));
6475 /* For non-leaf functions we have to consider all call clobbered regs to be
6477 if (!current_function_is_leaf
)
6479 for (i
= 0; i
< 16; i
++)
6480 regs_ever_clobbered
[i
] = call_really_used_regs
[i
];
6483 /* Make the "magic" eh_return registers live if necessary. For regs_ever_live
6484 this work is done by liveness analysis (mark_regs_live_at_end).
6485 Special care is needed for functions containing landing pads. Landing pads
6486 may use the eh registers, but the code which sets these registers is not
6487 contained in that function. Hence s390_regs_ever_clobbered is not able to
6488 deal with this automatically. */
6489 if (crtl
->calls_eh_return
|| cfun
->machine
->has_landing_pad_p
)
6490 for (i
= 0; EH_RETURN_DATA_REGNO (i
) != INVALID_REGNUM
; i
++)
6491 if (crtl
->calls_eh_return
6492 || (cfun
->machine
->has_landing_pad_p
6493 && df_regs_ever_live_p (EH_RETURN_DATA_REGNO (i
))))
6494 regs_ever_clobbered
[EH_RETURN_DATA_REGNO (i
)] = 1;
6496 /* For nonlocal gotos all call-saved registers have to be saved.
6497 This flag is also set for the unwinding code in libgcc.
6498 See expand_builtin_unwind_init. For regs_ever_live this is done by
6500 if (cfun
->has_nonlocal_label
)
6501 for (i
= 0; i
< 16; i
++)
6502 if (!call_really_used_regs
[i
])
6503 regs_ever_clobbered
[i
] = 1;
6505 FOR_EACH_BB (cur_bb
)
6507 FOR_BB_INSNS (cur_bb
, cur_insn
)
6509 if (INSN_P (cur_insn
))
6510 note_stores (PATTERN (cur_insn
),
6511 s390_reg_clobbered_rtx
,
6512 regs_ever_clobbered
);
6517 /* Determine the frame area which actually has to be accessed
6518 in the function epilogue. The values are stored at the
6519 given pointers AREA_BOTTOM (address of the lowest used stack
6520 address) and AREA_TOP (address of the first item which does
6521 not belong to the stack frame). */
6524 s390_frame_area (int *area_bottom
, int *area_top
)
6532 if (cfun_frame_layout
.first_restore_gpr
!= -1)
6534 b
= (cfun_frame_layout
.gprs_offset
6535 + cfun_frame_layout
.first_restore_gpr
* UNITS_PER_WORD
);
6536 t
= b
+ (cfun_frame_layout
.last_restore_gpr
6537 - cfun_frame_layout
.first_restore_gpr
+ 1) * UNITS_PER_WORD
;
6540 if (TARGET_64BIT
&& cfun_save_high_fprs_p
)
6542 b
= MIN (b
, cfun_frame_layout
.f8_offset
);
6543 t
= MAX (t
, (cfun_frame_layout
.f8_offset
6544 + cfun_frame_layout
.high_fprs
* 8));
6548 for (i
= 2; i
< 4; i
++)
6549 if (cfun_fpr_bit_p (i
))
6551 b
= MIN (b
, cfun_frame_layout
.f4_offset
+ (i
- 2) * 8);
6552 t
= MAX (t
, cfun_frame_layout
.f4_offset
+ (i
- 1) * 8);
6559 /* Fill cfun->machine with info about register usage of current function.
6560 Return in CLOBBERED_REGS which GPRs are currently considered set. */
6563 s390_register_info (int clobbered_regs
[])
6567 /* fprs 8 - 15 are call saved for 64 Bit ABI. */
6568 cfun_frame_layout
.fpr_bitmap
= 0;
6569 cfun_frame_layout
.high_fprs
= 0;
6571 for (i
= 24; i
< 32; i
++)
6572 if (df_regs_ever_live_p (i
) && !global_regs
[i
])
6574 cfun_set_fpr_bit (i
- 16);
6575 cfun_frame_layout
.high_fprs
++;
6578 /* Find first and last gpr to be saved. We trust regs_ever_live
6579 data, except that we don't save and restore global registers.
6581 Also, all registers with special meaning to the compiler need
6582 to be handled extra. */
6584 s390_regs_ever_clobbered (clobbered_regs
);
6586 for (i
= 0; i
< 16; i
++)
6587 clobbered_regs
[i
] = clobbered_regs
[i
] && !global_regs
[i
] && !fixed_regs
[i
];
6589 if (frame_pointer_needed
)
6590 clobbered_regs
[HARD_FRAME_POINTER_REGNUM
] = 1;
6593 clobbered_regs
[PIC_OFFSET_TABLE_REGNUM
]
6594 |= df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM
);
6596 clobbered_regs
[BASE_REGNUM
]
6597 |= (cfun
->machine
->base_reg
6598 && REGNO (cfun
->machine
->base_reg
) == BASE_REGNUM
);
6600 clobbered_regs
[RETURN_REGNUM
]
6601 |= (!current_function_is_leaf
6602 || TARGET_TPF_PROFILING
6603 || cfun
->machine
->split_branches_pending_p
6604 || cfun_frame_layout
.save_return_addr_p
6605 || crtl
->calls_eh_return
6608 clobbered_regs
[STACK_POINTER_REGNUM
]
6609 |= (!current_function_is_leaf
6610 || TARGET_TPF_PROFILING
6611 || cfun_save_high_fprs_p
6612 || get_frame_size () > 0
6613 || cfun
->calls_alloca
6616 for (i
= 6; i
< 16; i
++)
6617 if (df_regs_ever_live_p (i
) || clobbered_regs
[i
])
6619 for (j
= 15; j
> i
; j
--)
6620 if (df_regs_ever_live_p (j
) || clobbered_regs
[j
])
6625 /* Nothing to save/restore. */
6626 cfun_frame_layout
.first_save_gpr_slot
= -1;
6627 cfun_frame_layout
.last_save_gpr_slot
= -1;
6628 cfun_frame_layout
.first_save_gpr
= -1;
6629 cfun_frame_layout
.first_restore_gpr
= -1;
6630 cfun_frame_layout
.last_save_gpr
= -1;
6631 cfun_frame_layout
.last_restore_gpr
= -1;
6635 /* Save slots for gprs from i to j. */
6636 cfun_frame_layout
.first_save_gpr_slot
= i
;
6637 cfun_frame_layout
.last_save_gpr_slot
= j
;
6639 for (i
= cfun_frame_layout
.first_save_gpr_slot
;
6640 i
< cfun_frame_layout
.last_save_gpr_slot
+ 1;
6642 if (clobbered_regs
[i
])
6645 for (j
= cfun_frame_layout
.last_save_gpr_slot
; j
> i
; j
--)
6646 if (clobbered_regs
[j
])
6649 if (i
== cfun_frame_layout
.last_save_gpr_slot
+ 1)
6651 /* Nothing to save/restore. */
6652 cfun_frame_layout
.first_save_gpr
= -1;
6653 cfun_frame_layout
.first_restore_gpr
= -1;
6654 cfun_frame_layout
.last_save_gpr
= -1;
6655 cfun_frame_layout
.last_restore_gpr
= -1;
6659 /* Save / Restore from gpr i to j. */
6660 cfun_frame_layout
.first_save_gpr
= i
;
6661 cfun_frame_layout
.first_restore_gpr
= i
;
6662 cfun_frame_layout
.last_save_gpr
= j
;
6663 cfun_frame_layout
.last_restore_gpr
= j
;
6669 /* Varargs functions need to save gprs 2 to 6. */
6670 if (cfun
->va_list_gpr_size
6671 && crtl
->args
.info
.gprs
< GP_ARG_NUM_REG
)
6673 int min_gpr
= crtl
->args
.info
.gprs
;
6674 int max_gpr
= min_gpr
+ cfun
->va_list_gpr_size
;
6675 if (max_gpr
> GP_ARG_NUM_REG
)
6676 max_gpr
= GP_ARG_NUM_REG
;
6678 if (cfun_frame_layout
.first_save_gpr
== -1
6679 || cfun_frame_layout
.first_save_gpr
> 2 + min_gpr
)
6681 cfun_frame_layout
.first_save_gpr
= 2 + min_gpr
;
6682 cfun_frame_layout
.first_save_gpr_slot
= 2 + min_gpr
;
6685 if (cfun_frame_layout
.last_save_gpr
== -1
6686 || cfun_frame_layout
.last_save_gpr
< 2 + max_gpr
- 1)
6688 cfun_frame_layout
.last_save_gpr
= 2 + max_gpr
- 1;
6689 cfun_frame_layout
.last_save_gpr_slot
= 2 + max_gpr
- 1;
6693 /* Mark f0, f2 for 31 bit and f0-f4 for 64 bit to be saved. */
6694 if (TARGET_HARD_FLOAT
&& cfun
->va_list_fpr_size
6695 && crtl
->args
.info
.fprs
< FP_ARG_NUM_REG
)
6697 int min_fpr
= crtl
->args
.info
.fprs
;
6698 int max_fpr
= min_fpr
+ cfun
->va_list_fpr_size
;
6699 if (max_fpr
> FP_ARG_NUM_REG
)
6700 max_fpr
= FP_ARG_NUM_REG
;
6702 /* ??? This is currently required to ensure proper location
6703 of the fpr save slots within the va_list save area. */
6704 if (TARGET_PACKED_STACK
)
6707 for (i
= min_fpr
; i
< max_fpr
; i
++)
6708 cfun_set_fpr_bit (i
);
6713 for (i
= 2; i
< 4; i
++)
6714 if (df_regs_ever_live_p (i
+ 16) && !global_regs
[i
+ 16])
6715 cfun_set_fpr_bit (i
);
6718 /* Fill cfun->machine with info about frame of current function. */
6721 s390_frame_info (void)
6725 cfun_frame_layout
.frame_size
= get_frame_size ();
6726 if (!TARGET_64BIT
&& cfun_frame_layout
.frame_size
> 0x7fff0000)
6727 fatal_error ("total size of local variables exceeds architecture limit");
6729 if (!TARGET_PACKED_STACK
)
6731 cfun_frame_layout
.backchain_offset
= 0;
6732 cfun_frame_layout
.f0_offset
= 16 * UNITS_PER_WORD
;
6733 cfun_frame_layout
.f4_offset
= cfun_frame_layout
.f0_offset
+ 2 * 8;
6734 cfun_frame_layout
.f8_offset
= -cfun_frame_layout
.high_fprs
* 8;
6735 cfun_frame_layout
.gprs_offset
= (cfun_frame_layout
.first_save_gpr_slot
6738 else if (TARGET_BACKCHAIN
) /* kernel stack layout */
6740 cfun_frame_layout
.backchain_offset
= (STACK_POINTER_OFFSET
6742 cfun_frame_layout
.gprs_offset
6743 = (cfun_frame_layout
.backchain_offset
6744 - (STACK_POINTER_REGNUM
- cfun_frame_layout
.first_save_gpr_slot
+ 1)
6749 cfun_frame_layout
.f4_offset
6750 = (cfun_frame_layout
.gprs_offset
6751 - 8 * (cfun_fpr_bit_p (2) + cfun_fpr_bit_p (3)));
6753 cfun_frame_layout
.f0_offset
6754 = (cfun_frame_layout
.f4_offset
6755 - 8 * (cfun_fpr_bit_p (0) + cfun_fpr_bit_p (1)));
6759 /* On 31 bit we have to care about alignment of the
6760 floating point regs to provide fastest access. */
6761 cfun_frame_layout
.f0_offset
6762 = ((cfun_frame_layout
.gprs_offset
6763 & ~(STACK_BOUNDARY
/ BITS_PER_UNIT
- 1))
6764 - 8 * (cfun_fpr_bit_p (0) + cfun_fpr_bit_p (1)));
6766 cfun_frame_layout
.f4_offset
6767 = (cfun_frame_layout
.f0_offset
6768 - 8 * (cfun_fpr_bit_p (2) + cfun_fpr_bit_p (3)));
6771 else /* no backchain */
6773 cfun_frame_layout
.f4_offset
6774 = (STACK_POINTER_OFFSET
6775 - 8 * (cfun_fpr_bit_p (2) + cfun_fpr_bit_p (3)));
6777 cfun_frame_layout
.f0_offset
6778 = (cfun_frame_layout
.f4_offset
6779 - 8 * (cfun_fpr_bit_p (0) + cfun_fpr_bit_p (1)));
6781 cfun_frame_layout
.gprs_offset
6782 = cfun_frame_layout
.f0_offset
- cfun_gprs_save_area_size
;
6785 if (current_function_is_leaf
6786 && !TARGET_TPF_PROFILING
6787 && cfun_frame_layout
.frame_size
== 0
6788 && !cfun_save_high_fprs_p
6789 && !cfun
->calls_alloca
6793 if (!TARGET_PACKED_STACK
)
6794 cfun_frame_layout
.frame_size
+= (STACK_POINTER_OFFSET
6795 + crtl
->outgoing_args_size
6796 + cfun_frame_layout
.high_fprs
* 8);
6799 if (TARGET_BACKCHAIN
)
6800 cfun_frame_layout
.frame_size
+= UNITS_PER_WORD
;
6802 /* No alignment trouble here because f8-f15 are only saved under
6804 cfun_frame_layout
.f8_offset
= (MIN (MIN (cfun_frame_layout
.f0_offset
,
6805 cfun_frame_layout
.f4_offset
),
6806 cfun_frame_layout
.gprs_offset
)
6807 - cfun_frame_layout
.high_fprs
* 8);
6809 cfun_frame_layout
.frame_size
+= cfun_frame_layout
.high_fprs
* 8;
6811 for (i
= 0; i
< 8; i
++)
6812 if (cfun_fpr_bit_p (i
))
6813 cfun_frame_layout
.frame_size
+= 8;
6815 cfun_frame_layout
.frame_size
+= cfun_gprs_save_area_size
;
6817 /* If under 31 bit an odd number of gprs has to be saved we have to adjust
6818 the frame size to sustain 8 byte alignment of stack frames. */
6819 cfun_frame_layout
.frame_size
= ((cfun_frame_layout
.frame_size
+
6820 STACK_BOUNDARY
/ BITS_PER_UNIT
- 1)
6821 & ~(STACK_BOUNDARY
/ BITS_PER_UNIT
- 1));
6823 cfun_frame_layout
.frame_size
+= crtl
->outgoing_args_size
;
6827 /* Generate frame layout. Fills in register and frame data for the current
6828 function in cfun->machine. This routine can be called multiple times;
6829 it will re-do the complete frame layout every time. */
6832 s390_init_frame_layout (void)
6834 HOST_WIDE_INT frame_size
;
6836 int clobbered_regs
[16];
6838 /* On S/390 machines, we may need to perform branch splitting, which
6839 will require both base and return address register. We have no
6840 choice but to assume we're going to need them until right at the
6841 end of the machine dependent reorg phase. */
6842 if (!TARGET_CPU_ZARCH
)
6843 cfun
->machine
->split_branches_pending_p
= true;
6847 frame_size
= cfun_frame_layout
.frame_size
;
6849 /* Try to predict whether we'll need the base register. */
6850 base_used
= cfun
->machine
->split_branches_pending_p
6851 || crtl
->uses_const_pool
6852 || (!DISP_IN_RANGE (frame_size
)
6853 && !CONST_OK_FOR_K (frame_size
));
6855 /* Decide which register to use as literal pool base. In small
6856 leaf functions, try to use an unused call-clobbered register
6857 as base register to avoid save/restore overhead. */
6859 cfun
->machine
->base_reg
= NULL_RTX
;
6860 else if (current_function_is_leaf
&& !df_regs_ever_live_p (5))
6861 cfun
->machine
->base_reg
= gen_rtx_REG (Pmode
, 5);
6863 cfun
->machine
->base_reg
= gen_rtx_REG (Pmode
, BASE_REGNUM
);
6865 s390_register_info (clobbered_regs
);
6868 while (frame_size
!= cfun_frame_layout
.frame_size
);
6871 /* Update frame layout. Recompute actual register save data based on
6872 current info and update regs_ever_live for the special registers.
6873 May be called multiple times, but may never cause *more* registers
6874 to be saved than s390_init_frame_layout allocated room for. */
6877 s390_update_frame_layout (void)
6879 int clobbered_regs
[16];
6881 s390_register_info (clobbered_regs
);
6883 df_set_regs_ever_live (BASE_REGNUM
,
6884 clobbered_regs
[BASE_REGNUM
] ? true : false);
6885 df_set_regs_ever_live (RETURN_REGNUM
,
6886 clobbered_regs
[RETURN_REGNUM
] ? true : false);
6887 df_set_regs_ever_live (STACK_POINTER_REGNUM
,
6888 clobbered_regs
[STACK_POINTER_REGNUM
] ? true : false);
6890 if (cfun
->machine
->base_reg
)
6891 df_set_regs_ever_live (REGNO (cfun
->machine
->base_reg
), true);
6894 /* Return true if it is legal to put a value with MODE into REGNO. */
6897 s390_hard_regno_mode_ok (unsigned int regno
, enum machine_mode mode
)
6899 switch (REGNO_REG_CLASS (regno
))
6902 if (REGNO_PAIR_OK (regno
, mode
))
6904 if (mode
== SImode
|| mode
== DImode
)
6907 if (FLOAT_MODE_P (mode
) && GET_MODE_CLASS (mode
) != MODE_VECTOR_FLOAT
)
6912 if (FRAME_REGNO_P (regno
) && mode
== Pmode
)
6917 if (REGNO_PAIR_OK (regno
, mode
))
6920 || (mode
!= TFmode
&& mode
!= TCmode
&& mode
!= TDmode
))
6925 if (GET_MODE_CLASS (mode
) == MODE_CC
)
6929 if (REGNO_PAIR_OK (regno
, mode
))
6931 if (mode
== SImode
|| mode
== Pmode
)
6942 /* Return nonzero if register OLD_REG can be renamed to register NEW_REG. */
6945 s390_hard_regno_rename_ok (unsigned int old_reg
, unsigned int new_reg
)
6947 /* Once we've decided upon a register to use as base register, it must
6948 no longer be used for any other purpose. */
6949 if (cfun
->machine
->base_reg
)
6950 if (REGNO (cfun
->machine
->base_reg
) == old_reg
6951 || REGNO (cfun
->machine
->base_reg
) == new_reg
)
6957 /* Maximum number of registers to represent a value of mode MODE
6958 in a register of class CLASS. */
6961 s390_class_max_nregs (enum reg_class
class, enum machine_mode mode
)
6966 if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
)
6967 return 2 * ((GET_MODE_SIZE (mode
) / 2 + 8 - 1) / 8);
6969 return (GET_MODE_SIZE (mode
) + 8 - 1) / 8;
6971 return (GET_MODE_SIZE (mode
) + 4 - 1) / 4;
6975 return (GET_MODE_SIZE (mode
) + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
6978 /* Return true if register FROM can be eliminated via register TO. */
6981 s390_can_eliminate (int from
, int to
)
6983 /* On zSeries machines, we have not marked the base register as fixed.
6984 Instead, we have an elimination rule BASE_REGNUM -> BASE_REGNUM.
6985 If a function requires the base register, we say here that this
6986 elimination cannot be performed. This will cause reload to free
6987 up the base register (as if it were fixed). On the other hand,
6988 if the current function does *not* require the base register, we
6989 say here the elimination succeeds, which in turn allows reload
6990 to allocate the base register for any other purpose. */
6991 if (from
== BASE_REGNUM
&& to
== BASE_REGNUM
)
6993 if (TARGET_CPU_ZARCH
)
6995 s390_init_frame_layout ();
6996 return cfun
->machine
->base_reg
== NULL_RTX
;
7002 /* Everything else must point into the stack frame. */
7003 gcc_assert (to
== STACK_POINTER_REGNUM
7004 || to
== HARD_FRAME_POINTER_REGNUM
);
7006 gcc_assert (from
== FRAME_POINTER_REGNUM
7007 || from
== ARG_POINTER_REGNUM
7008 || from
== RETURN_ADDRESS_POINTER_REGNUM
);
7010 /* Make sure we actually saved the return address. */
7011 if (from
== RETURN_ADDRESS_POINTER_REGNUM
)
7012 if (!crtl
->calls_eh_return
7014 && !cfun_frame_layout
.save_return_addr_p
)
7020 /* Return offset between register FROM and TO initially after prolog. */
7023 s390_initial_elimination_offset (int from
, int to
)
7025 HOST_WIDE_INT offset
;
7028 /* ??? Why are we called for non-eliminable pairs? */
7029 if (!s390_can_eliminate (from
, to
))
7034 case FRAME_POINTER_REGNUM
:
7035 offset
= (get_frame_size()
7036 + STACK_POINTER_OFFSET
7037 + crtl
->outgoing_args_size
);
7040 case ARG_POINTER_REGNUM
:
7041 s390_init_frame_layout ();
7042 offset
= cfun_frame_layout
.frame_size
+ STACK_POINTER_OFFSET
;
7045 case RETURN_ADDRESS_POINTER_REGNUM
:
7046 s390_init_frame_layout ();
7047 index
= RETURN_REGNUM
- cfun_frame_layout
.first_save_gpr_slot
;
7048 gcc_assert (index
>= 0);
7049 offset
= cfun_frame_layout
.frame_size
+ cfun_frame_layout
.gprs_offset
;
7050 offset
+= index
* UNITS_PER_WORD
;
7064 /* Emit insn to save fpr REGNUM at offset OFFSET relative
7065 to register BASE. Return generated insn. */
7068 save_fpr (rtx base
, int offset
, int regnum
)
7071 addr
= gen_rtx_MEM (DFmode
, plus_constant (base
, offset
));
7073 if (regnum
>= 16 && regnum
<= (16 + FP_ARG_NUM_REG
))
7074 set_mem_alias_set (addr
, get_varargs_alias_set ());
7076 set_mem_alias_set (addr
, get_frame_alias_set ());
7078 return emit_move_insn (addr
, gen_rtx_REG (DFmode
, regnum
));
7081 /* Emit insn to restore fpr REGNUM from offset OFFSET relative
7082 to register BASE. Return generated insn. */
7085 restore_fpr (rtx base
, int offset
, int regnum
)
7088 addr
= gen_rtx_MEM (DFmode
, plus_constant (base
, offset
));
7089 set_mem_alias_set (addr
, get_frame_alias_set ());
7091 return emit_move_insn (gen_rtx_REG (DFmode
, regnum
), addr
);
7094 /* Generate insn to save registers FIRST to LAST into
7095 the register save area located at offset OFFSET
7096 relative to register BASE. */
7099 save_gprs (rtx base
, int offset
, int first
, int last
)
7101 rtx addr
, insn
, note
;
7104 addr
= plus_constant (base
, offset
);
7105 addr
= gen_rtx_MEM (Pmode
, addr
);
7107 set_mem_alias_set (addr
, get_frame_alias_set ());
7109 /* Special-case single register. */
7113 insn
= gen_movdi (addr
, gen_rtx_REG (Pmode
, first
));
7115 insn
= gen_movsi (addr
, gen_rtx_REG (Pmode
, first
));
7117 RTX_FRAME_RELATED_P (insn
) = 1;
7122 insn
= gen_store_multiple (addr
,
7123 gen_rtx_REG (Pmode
, first
),
7124 GEN_INT (last
- first
+ 1));
7126 if (first
<= 6 && cfun
->stdarg
)
7127 for (i
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
7129 rtx mem
= XEXP (XVECEXP (PATTERN (insn
), 0, i
), 0);
7132 set_mem_alias_set (mem
, get_varargs_alias_set ());
7135 /* We need to set the FRAME_RELATED flag on all SETs
7136 inside the store-multiple pattern.
7138 However, we must not emit DWARF records for registers 2..5
7139 if they are stored for use by variable arguments ...
7141 ??? Unfortunately, it is not enough to simply not the
7142 FRAME_RELATED flags for those SETs, because the first SET
7143 of the PARALLEL is always treated as if it had the flag
7144 set, even if it does not. Therefore we emit a new pattern
7145 without those registers as REG_FRAME_RELATED_EXPR note. */
7149 rtx pat
= PATTERN (insn
);
7151 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
7152 if (GET_CODE (XVECEXP (pat
, 0, i
)) == SET
)
7153 RTX_FRAME_RELATED_P (XVECEXP (pat
, 0, i
)) = 1;
7155 RTX_FRAME_RELATED_P (insn
) = 1;
7159 addr
= plus_constant (base
, offset
+ (6 - first
) * UNITS_PER_WORD
);
7160 note
= gen_store_multiple (gen_rtx_MEM (Pmode
, addr
),
7161 gen_rtx_REG (Pmode
, 6),
7162 GEN_INT (last
- 6 + 1));
7163 note
= PATTERN (note
);
7166 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR
,
7167 note
, REG_NOTES (insn
));
7169 for (i
= 0; i
< XVECLEN (note
, 0); i
++)
7170 if (GET_CODE (XVECEXP (note
, 0, i
)) == SET
)
7171 RTX_FRAME_RELATED_P (XVECEXP (note
, 0, i
)) = 1;
7173 RTX_FRAME_RELATED_P (insn
) = 1;
7179 /* Generate insn to restore registers FIRST to LAST from
7180 the register save area located at offset OFFSET
7181 relative to register BASE. */
7184 restore_gprs (rtx base
, int offset
, int first
, int last
)
7188 addr
= plus_constant (base
, offset
);
7189 addr
= gen_rtx_MEM (Pmode
, addr
);
7190 set_mem_alias_set (addr
, get_frame_alias_set ());
7192 /* Special-case single register. */
7196 insn
= gen_movdi (gen_rtx_REG (Pmode
, first
), addr
);
7198 insn
= gen_movsi (gen_rtx_REG (Pmode
, first
), addr
);
7203 insn
= gen_load_multiple (gen_rtx_REG (Pmode
, first
),
7205 GEN_INT (last
- first
+ 1));
7209 /* Return insn sequence to load the GOT register. */
7211 static GTY(()) rtx got_symbol
;
7213 s390_load_got (void)
7219 got_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "_GLOBAL_OFFSET_TABLE_");
7220 SYMBOL_REF_FLAGS (got_symbol
) = SYMBOL_FLAG_LOCAL
;
7225 if (TARGET_CPU_ZARCH
)
7227 emit_move_insn (pic_offset_table_rtx
, got_symbol
);
7233 offset
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, got_symbol
),
7234 UNSPEC_LTREL_OFFSET
);
7235 offset
= gen_rtx_CONST (Pmode
, offset
);
7236 offset
= force_const_mem (Pmode
, offset
);
7238 emit_move_insn (pic_offset_table_rtx
, offset
);
7240 offset
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, XEXP (offset
, 0)),
7242 offset
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, offset
);
7244 emit_move_insn (pic_offset_table_rtx
, offset
);
7247 insns
= get_insns ();
7252 /* This ties together stack memory (MEM with an alias set of frame_alias_set)
7253 and the change to the stack pointer. */
7256 s390_emit_stack_tie (void)
7258 rtx mem
= gen_frame_mem (BLKmode
,
7259 gen_rtx_REG (Pmode
, STACK_POINTER_REGNUM
));
7261 emit_insn (gen_stack_tie (mem
));
7264 /* Expand the prologue into a bunch of separate insns. */
7267 s390_emit_prologue (void)
7275 /* Complete frame layout. */
7277 s390_update_frame_layout ();
7279 /* Annotate all constant pool references to let the scheduler know
7280 they implicitly use the base register. */
7282 push_topmost_sequence ();
7284 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
7287 annotate_constant_pool_refs (&PATTERN (insn
));
7288 df_insn_rescan (insn
);
7291 pop_topmost_sequence ();
7293 /* Choose best register to use for temp use within prologue.
7294 See below for why TPF must use the register 1. */
7296 if (!has_hard_reg_initial_val (Pmode
, RETURN_REGNUM
)
7297 && !current_function_is_leaf
7298 && !TARGET_TPF_PROFILING
)
7299 temp_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
7301 temp_reg
= gen_rtx_REG (Pmode
, 1);
7303 /* Save call saved gprs. */
7304 if (cfun_frame_layout
.first_save_gpr
!= -1)
7306 insn
= save_gprs (stack_pointer_rtx
,
7307 cfun_frame_layout
.gprs_offset
+
7308 UNITS_PER_WORD
* (cfun_frame_layout
.first_save_gpr
7309 - cfun_frame_layout
.first_save_gpr_slot
),
7310 cfun_frame_layout
.first_save_gpr
,
7311 cfun_frame_layout
.last_save_gpr
);
7315 /* Dummy insn to mark literal pool slot. */
7317 if (cfun
->machine
->base_reg
)
7318 emit_insn (gen_main_pool (cfun
->machine
->base_reg
));
7320 offset
= cfun_frame_layout
.f0_offset
;
7322 /* Save f0 and f2. */
7323 for (i
= 0; i
< 2; i
++)
7325 if (cfun_fpr_bit_p (i
))
7327 save_fpr (stack_pointer_rtx
, offset
, i
+ 16);
7330 else if (!TARGET_PACKED_STACK
)
7334 /* Save f4 and f6. */
7335 offset
= cfun_frame_layout
.f4_offset
;
7336 for (i
= 2; i
< 4; i
++)
7338 if (cfun_fpr_bit_p (i
))
7340 insn
= save_fpr (stack_pointer_rtx
, offset
, i
+ 16);
7343 /* If f4 and f6 are call clobbered they are saved due to stdargs and
7344 therefore are not frame related. */
7345 if (!call_really_used_regs
[i
+ 16])
7346 RTX_FRAME_RELATED_P (insn
) = 1;
7348 else if (!TARGET_PACKED_STACK
)
7352 if (TARGET_PACKED_STACK
7353 && cfun_save_high_fprs_p
7354 && cfun_frame_layout
.f8_offset
+ cfun_frame_layout
.high_fprs
* 8 > 0)
7356 offset
= (cfun_frame_layout
.f8_offset
7357 + (cfun_frame_layout
.high_fprs
- 1) * 8);
7359 for (i
= 15; i
> 7 && offset
>= 0; i
--)
7360 if (cfun_fpr_bit_p (i
))
7362 insn
= save_fpr (stack_pointer_rtx
, offset
, i
+ 16);
7364 RTX_FRAME_RELATED_P (insn
) = 1;
7367 if (offset
>= cfun_frame_layout
.f8_offset
)
7371 if (!TARGET_PACKED_STACK
)
7372 next_fpr
= cfun_save_high_fprs_p
? 31 : 0;
7374 /* Decrement stack pointer. */
7376 if (cfun_frame_layout
.frame_size
> 0)
7378 rtx frame_off
= GEN_INT (-cfun_frame_layout
.frame_size
);
7380 if (s390_stack_size
)
7382 HOST_WIDE_INT stack_guard
;
7384 if (s390_stack_guard
)
7385 stack_guard
= s390_stack_guard
;
7388 /* If no value for stack guard is provided the smallest power of 2
7389 larger than the current frame size is chosen. */
7391 while (stack_guard
< cfun_frame_layout
.frame_size
)
7395 if (cfun_frame_layout
.frame_size
>= s390_stack_size
)
7397 warning (0, "frame size of function %qs is "
7398 HOST_WIDE_INT_PRINT_DEC
7399 " bytes exceeding user provided stack limit of "
7400 HOST_WIDE_INT_PRINT_DEC
" bytes. "
7401 "An unconditional trap is added.",
7402 current_function_name(), cfun_frame_layout
.frame_size
,
7404 emit_insn (gen_trap ());
7408 HOST_WIDE_INT stack_check_mask
= ((s390_stack_size
- 1)
7409 & ~(stack_guard
- 1));
7410 rtx t
= gen_rtx_AND (Pmode
, stack_pointer_rtx
,
7411 GEN_INT (stack_check_mask
));
7413 gen_cmpdi (t
, const0_rtx
);
7415 gen_cmpsi (t
, const0_rtx
);
7417 emit_insn (gen_conditional_trap (gen_rtx_EQ (CCmode
,
7418 gen_rtx_REG (CCmode
,
7425 if (s390_warn_framesize
> 0
7426 && cfun_frame_layout
.frame_size
>= s390_warn_framesize
)
7427 warning (0, "frame size of %qs is " HOST_WIDE_INT_PRINT_DEC
" bytes",
7428 current_function_name (), cfun_frame_layout
.frame_size
);
7430 if (s390_warn_dynamicstack_p
&& cfun
->calls_alloca
)
7431 warning (0, "%qs uses dynamic stack allocation", current_function_name ());
7433 /* Save incoming stack pointer into temp reg. */
7434 if (TARGET_BACKCHAIN
|| next_fpr
)
7435 insn
= emit_insn (gen_move_insn (temp_reg
, stack_pointer_rtx
));
7437 /* Subtract frame size from stack pointer. */
7439 if (DISP_IN_RANGE (INTVAL (frame_off
)))
7441 insn
= gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
7442 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
7444 insn
= emit_insn (insn
);
7448 if (!CONST_OK_FOR_K (INTVAL (frame_off
)))
7449 frame_off
= force_const_mem (Pmode
, frame_off
);
7451 insn
= emit_insn (gen_add2_insn (stack_pointer_rtx
, frame_off
));
7452 annotate_constant_pool_refs (&PATTERN (insn
));
7455 RTX_FRAME_RELATED_P (insn
) = 1;
7457 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR
,
7458 gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
7459 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
7460 GEN_INT (-cfun_frame_layout
.frame_size
))),
7463 /* Set backchain. */
7465 if (TARGET_BACKCHAIN
)
7467 if (cfun_frame_layout
.backchain_offset
)
7468 addr
= gen_rtx_MEM (Pmode
,
7469 plus_constant (stack_pointer_rtx
,
7470 cfun_frame_layout
.backchain_offset
));
7472 addr
= gen_rtx_MEM (Pmode
, stack_pointer_rtx
);
7473 set_mem_alias_set (addr
, get_frame_alias_set ());
7474 insn
= emit_insn (gen_move_insn (addr
, temp_reg
));
7477 /* If we support asynchronous exceptions (e.g. for Java),
7478 we need to make sure the backchain pointer is set up
7479 before any possibly trapping memory access. */
7481 if (TARGET_BACKCHAIN
&& flag_non_call_exceptions
)
7483 addr
= gen_rtx_MEM (BLKmode
, gen_rtx_SCRATCH (VOIDmode
));
7484 emit_insn (gen_rtx_CLOBBER (VOIDmode
, addr
));
7488 /* Save fprs 8 - 15 (64 bit ABI). */
7490 if (cfun_save_high_fprs_p
&& next_fpr
)
7492 /* If the stack might be accessed through a different register
7493 we have to make sure that the stack pointer decrement is not
7494 moved below the use of the stack slots. */
7495 s390_emit_stack_tie ();
7497 insn
= emit_insn (gen_add2_insn (temp_reg
,
7498 GEN_INT (cfun_frame_layout
.f8_offset
)));
7502 for (i
= 24; i
<= next_fpr
; i
++)
7503 if (cfun_fpr_bit_p (i
- 16))
7505 rtx addr
= plus_constant (stack_pointer_rtx
,
7506 cfun_frame_layout
.frame_size
7507 + cfun_frame_layout
.f8_offset
7510 insn
= save_fpr (temp_reg
, offset
, i
);
7512 RTX_FRAME_RELATED_P (insn
) = 1;
7514 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR
,
7515 gen_rtx_SET (VOIDmode
,
7516 gen_rtx_MEM (DFmode
, addr
),
7517 gen_rtx_REG (DFmode
, i
)),
7522 /* Set frame pointer, if needed. */
7524 if (frame_pointer_needed
)
7526 insn
= emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
);
7527 RTX_FRAME_RELATED_P (insn
) = 1;
7530 /* Set up got pointer, if needed. */
7532 if (flag_pic
&& df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM
))
7534 rtx insns
= s390_load_got ();
7536 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
7537 annotate_constant_pool_refs (&PATTERN (insn
));
7542 if (TARGET_TPF_PROFILING
)
7544 /* Generate a BAS instruction to serve as a function
7545 entry intercept to facilitate the use of tracing
7546 algorithms located at the branch target. */
7547 emit_insn (gen_prologue_tpf ());
7549 /* Emit a blockage here so that all code
7550 lies between the profiling mechanisms. */
7551 emit_insn (gen_blockage ());
7555 /* Expand the epilogue into a bunch of separate insns. */
7558 s390_emit_epilogue (bool sibcall
)
7560 rtx frame_pointer
, return_reg
;
7561 int area_bottom
, area_top
, offset
= 0;
7566 if (TARGET_TPF_PROFILING
)
7569 /* Generate a BAS instruction to serve as a function
7570 entry intercept to facilitate the use of tracing
7571 algorithms located at the branch target. */
7573 /* Emit a blockage here so that all code
7574 lies between the profiling mechanisms. */
7575 emit_insn (gen_blockage ());
7577 emit_insn (gen_epilogue_tpf ());
7580 /* Check whether to use frame or stack pointer for restore. */
7582 frame_pointer
= (frame_pointer_needed
7583 ? hard_frame_pointer_rtx
: stack_pointer_rtx
);
7585 s390_frame_area (&area_bottom
, &area_top
);
7587 /* Check whether we can access the register save area.
7588 If not, increment the frame pointer as required. */
7590 if (area_top
<= area_bottom
)
7592 /* Nothing to restore. */
7594 else if (DISP_IN_RANGE (cfun_frame_layout
.frame_size
+ area_bottom
)
7595 && DISP_IN_RANGE (cfun_frame_layout
.frame_size
+ area_top
- 1))
7597 /* Area is in range. */
7598 offset
= cfun_frame_layout
.frame_size
;
7602 rtx insn
, frame_off
;
7604 offset
= area_bottom
< 0 ? -area_bottom
: 0;
7605 frame_off
= GEN_INT (cfun_frame_layout
.frame_size
- offset
);
7607 if (DISP_IN_RANGE (INTVAL (frame_off
)))
7609 insn
= gen_rtx_SET (VOIDmode
, frame_pointer
,
7610 gen_rtx_PLUS (Pmode
, frame_pointer
, frame_off
));
7611 insn
= emit_insn (insn
);
7615 if (!CONST_OK_FOR_K (INTVAL (frame_off
)))
7616 frame_off
= force_const_mem (Pmode
, frame_off
);
7618 insn
= emit_insn (gen_add2_insn (frame_pointer
, frame_off
));
7619 annotate_constant_pool_refs (&PATTERN (insn
));
7623 /* Restore call saved fprs. */
7627 if (cfun_save_high_fprs_p
)
7629 next_offset
= cfun_frame_layout
.f8_offset
;
7630 for (i
= 24; i
< 32; i
++)
7632 if (cfun_fpr_bit_p (i
- 16))
7634 restore_fpr (frame_pointer
,
7635 offset
+ next_offset
, i
);
7644 next_offset
= cfun_frame_layout
.f4_offset
;
7645 for (i
= 18; i
< 20; i
++)
7647 if (cfun_fpr_bit_p (i
- 16))
7649 restore_fpr (frame_pointer
,
7650 offset
+ next_offset
, i
);
7653 else if (!TARGET_PACKED_STACK
)
7659 /* Return register. */
7661 return_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
7663 /* Restore call saved gprs. */
7665 if (cfun_frame_layout
.first_restore_gpr
!= -1)
7670 /* Check for global register and save them
7671 to stack location from where they get restored. */
7673 for (i
= cfun_frame_layout
.first_restore_gpr
;
7674 i
<= cfun_frame_layout
.last_restore_gpr
;
7677 /* These registers are special and need to be
7678 restored in any case. */
7679 if (i
== STACK_POINTER_REGNUM
7680 || i
== RETURN_REGNUM
7682 || (flag_pic
&& i
== (int)PIC_OFFSET_TABLE_REGNUM
))
7687 addr
= plus_constant (frame_pointer
,
7688 offset
+ cfun_frame_layout
.gprs_offset
7689 + (i
- cfun_frame_layout
.first_save_gpr_slot
)
7691 addr
= gen_rtx_MEM (Pmode
, addr
);
7692 set_mem_alias_set (addr
, get_frame_alias_set ());
7693 emit_move_insn (addr
, gen_rtx_REG (Pmode
, i
));
7699 /* Fetch return address from stack before load multiple,
7700 this will do good for scheduling. */
7702 if (cfun_frame_layout
.save_return_addr_p
7703 || (cfun_frame_layout
.first_restore_gpr
< BASE_REGNUM
7704 && cfun_frame_layout
.last_restore_gpr
> RETURN_REGNUM
))
7706 int return_regnum
= find_unused_clobbered_reg();
7709 return_reg
= gen_rtx_REG (Pmode
, return_regnum
);
7711 addr
= plus_constant (frame_pointer
,
7712 offset
+ cfun_frame_layout
.gprs_offset
7714 - cfun_frame_layout
.first_save_gpr_slot
)
7716 addr
= gen_rtx_MEM (Pmode
, addr
);
7717 set_mem_alias_set (addr
, get_frame_alias_set ());
7718 emit_move_insn (return_reg
, addr
);
7722 insn
= restore_gprs (frame_pointer
,
7723 offset
+ cfun_frame_layout
.gprs_offset
7724 + (cfun_frame_layout
.first_restore_gpr
7725 - cfun_frame_layout
.first_save_gpr_slot
)
7727 cfun_frame_layout
.first_restore_gpr
,
7728 cfun_frame_layout
.last_restore_gpr
);
7735 /* Return to caller. */
7737 p
= rtvec_alloc (2);
7739 RTVEC_ELT (p
, 0) = gen_rtx_RETURN (VOIDmode
);
7740 RTVEC_ELT (p
, 1) = gen_rtx_USE (VOIDmode
, return_reg
);
7741 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
7746 /* Return the size in bytes of a function argument of
7747 type TYPE and/or mode MODE. At least one of TYPE or
7748 MODE must be specified. */
7751 s390_function_arg_size (enum machine_mode mode
, const_tree type
)
7754 return int_size_in_bytes (type
);
7756 /* No type info available for some library calls ... */
7757 if (mode
!= BLKmode
)
7758 return GET_MODE_SIZE (mode
);
7760 /* If we have neither type nor mode, abort */
7764 /* Return true if a function argument of type TYPE and mode MODE
7765 is to be passed in a floating-point register, if available. */
7768 s390_function_arg_float (enum machine_mode mode
, tree type
)
7770 int size
= s390_function_arg_size (mode
, type
);
7774 /* Soft-float changes the ABI: no floating-point registers are used. */
7775 if (TARGET_SOFT_FLOAT
)
7778 /* No type info available for some library calls ... */
7780 return mode
== SFmode
|| mode
== DFmode
|| mode
== SDmode
|| mode
== DDmode
;
7782 /* The ABI says that record types with a single member are treated
7783 just like that member would be. */
7784 while (TREE_CODE (type
) == RECORD_TYPE
)
7786 tree field
, single
= NULL_TREE
;
7788 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
7790 if (TREE_CODE (field
) != FIELD_DECL
)
7793 if (single
== NULL_TREE
)
7794 single
= TREE_TYPE (field
);
7799 if (single
== NULL_TREE
)
7805 return TREE_CODE (type
) == REAL_TYPE
;
7808 /* Return true if a function argument of type TYPE and mode MODE
7809 is to be passed in an integer register, or a pair of integer
7810 registers, if available. */
7813 s390_function_arg_integer (enum machine_mode mode
, tree type
)
7815 int size
= s390_function_arg_size (mode
, type
);
7819 /* No type info available for some library calls ... */
7821 return GET_MODE_CLASS (mode
) == MODE_INT
7822 || (TARGET_SOFT_FLOAT
&& SCALAR_FLOAT_MODE_P (mode
));
7824 /* We accept small integral (and similar) types. */
7825 if (INTEGRAL_TYPE_P (type
)
7826 || POINTER_TYPE_P (type
)
7827 || TREE_CODE (type
) == OFFSET_TYPE
7828 || (TARGET_SOFT_FLOAT
&& TREE_CODE (type
) == REAL_TYPE
))
7831 /* We also accept structs of size 1, 2, 4, 8 that are not
7832 passed in floating-point registers. */
7833 if (AGGREGATE_TYPE_P (type
)
7834 && exact_log2 (size
) >= 0
7835 && !s390_function_arg_float (mode
, type
))
7841 /* Return 1 if a function argument of type TYPE and mode MODE
7842 is to be passed by reference. The ABI specifies that only
7843 structures of size 1, 2, 4, or 8 bytes are passed by value,
7844 all other structures (and complex numbers) are passed by
7848 s390_pass_by_reference (CUMULATIVE_ARGS
*ca ATTRIBUTE_UNUSED
,
7849 enum machine_mode mode
, const_tree type
,
7850 bool named ATTRIBUTE_UNUSED
)
7852 int size
= s390_function_arg_size (mode
, type
);
7858 if (AGGREGATE_TYPE_P (type
) && exact_log2 (size
) < 0)
7861 if (TREE_CODE (type
) == COMPLEX_TYPE
7862 || TREE_CODE (type
) == VECTOR_TYPE
)
7869 /* Update the data in CUM to advance over an argument of mode MODE and
7870 data type TYPE. (TYPE is null for libcalls where that information
7871 may not be available.). The boolean NAMED specifies whether the
7872 argument is a named argument (as opposed to an unnamed argument
7873 matching an ellipsis). */
7876 s390_function_arg_advance (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
,
7877 tree type
, int named ATTRIBUTE_UNUSED
)
7879 if (s390_function_arg_float (mode
, type
))
7883 else if (s390_function_arg_integer (mode
, type
))
7885 int size
= s390_function_arg_size (mode
, type
);
7886 cum
->gprs
+= ((size
+ UNITS_PER_WORD
-1) / UNITS_PER_WORD
);
7892 /* Define where to put the arguments to a function.
7893 Value is zero to push the argument on the stack,
7894 or a hard register in which to store the argument.
7896 MODE is the argument's machine mode.
7897 TYPE is the data type of the argument (as a tree).
7898 This is null for libcalls where that information may
7900 CUM is a variable of type CUMULATIVE_ARGS which gives info about
7901 the preceding args and about the function being called.
7902 NAMED is nonzero if this argument is a named parameter
7903 (otherwise it is an extra parameter matching an ellipsis).
7905 On S/390, we use general purpose registers 2 through 6 to
7906 pass integer, pointer, and certain structure arguments, and
7907 floating point registers 0 and 2 (0, 2, 4, and 6 on 64-bit)
7908 to pass floating point arguments. All remaining arguments
7909 are pushed to the stack. */
7912 s390_function_arg (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
, tree type
,
7913 int named ATTRIBUTE_UNUSED
)
7915 if (s390_function_arg_float (mode
, type
))
7917 if (cum
->fprs
+ 1 > FP_ARG_NUM_REG
)
7920 return gen_rtx_REG (mode
, cum
->fprs
+ 16);
7922 else if (s390_function_arg_integer (mode
, type
))
7924 int size
= s390_function_arg_size (mode
, type
);
7925 int n_gprs
= (size
+ UNITS_PER_WORD
-1) / UNITS_PER_WORD
;
7927 if (cum
->gprs
+ n_gprs
> GP_ARG_NUM_REG
)
7930 return gen_rtx_REG (mode
, cum
->gprs
+ 2);
7933 /* After the real arguments, expand_call calls us once again
7934 with a void_type_node type. Whatever we return here is
7935 passed as operand 2 to the call expanders.
7937 We don't need this feature ... */
7938 else if (type
== void_type_node
)
7944 /* Return true if return values of type TYPE should be returned
7945 in a memory buffer whose address is passed by the caller as
7946 hidden first argument. */
7949 s390_return_in_memory (const_tree type
, const_tree fundecl ATTRIBUTE_UNUSED
)
7951 /* We accept small integral (and similar) types. */
7952 if (INTEGRAL_TYPE_P (type
)
7953 || POINTER_TYPE_P (type
)
7954 || TREE_CODE (type
) == OFFSET_TYPE
7955 || TREE_CODE (type
) == REAL_TYPE
)
7956 return int_size_in_bytes (type
) > 8;
7958 /* Aggregates and similar constructs are always returned
7960 if (AGGREGATE_TYPE_P (type
)
7961 || TREE_CODE (type
) == COMPLEX_TYPE
7962 || TREE_CODE (type
) == VECTOR_TYPE
)
7965 /* ??? We get called on all sorts of random stuff from
7966 aggregate_value_p. We can't abort, but it's not clear
7967 what's safe to return. Pretend it's a struct I guess. */
7971 /* Define where to return a (scalar) value of type TYPE.
7972 If TYPE is null, define where to return a (scalar)
7973 value of mode MODE from a libcall. */
7976 s390_function_value (const_tree type
, enum machine_mode mode
)
7980 int unsignedp
= TYPE_UNSIGNED (type
);
7981 mode
= promote_mode (type
, TYPE_MODE (type
), &unsignedp
, 1);
7984 gcc_assert (GET_MODE_CLASS (mode
) == MODE_INT
|| SCALAR_FLOAT_MODE_P (mode
));
7985 gcc_assert (GET_MODE_SIZE (mode
) <= 8);
7987 if (TARGET_HARD_FLOAT
&& SCALAR_FLOAT_MODE_P (mode
))
7988 return gen_rtx_REG (mode
, 16);
7990 return gen_rtx_REG (mode
, 2);
7994 /* Create and return the va_list datatype.
7996 On S/390, va_list is an array type equivalent to
7998 typedef struct __va_list_tag
8002 void *__overflow_arg_area;
8003 void *__reg_save_area;
8006 where __gpr and __fpr hold the number of general purpose
8007 or floating point arguments used up to now, respectively,
8008 __overflow_arg_area points to the stack location of the
8009 next argument passed on the stack, and __reg_save_area
8010 always points to the start of the register area in the
8011 call frame of the current function. The function prologue
8012 saves all registers used for argument passing into this
8013 area if the function uses variable arguments. */
8016 s390_build_builtin_va_list (void)
8018 tree f_gpr
, f_fpr
, f_ovf
, f_sav
, record
, type_decl
;
8020 record
= lang_hooks
.types
.make_type (RECORD_TYPE
);
8023 build_decl (TYPE_DECL
, get_identifier ("__va_list_tag"), record
);
8025 f_gpr
= build_decl (FIELD_DECL
, get_identifier ("__gpr"),
8026 long_integer_type_node
);
8027 f_fpr
= build_decl (FIELD_DECL
, get_identifier ("__fpr"),
8028 long_integer_type_node
);
8029 f_ovf
= build_decl (FIELD_DECL
, get_identifier ("__overflow_arg_area"),
8031 f_sav
= build_decl (FIELD_DECL
, get_identifier ("__reg_save_area"),
8034 va_list_gpr_counter_field
= f_gpr
;
8035 va_list_fpr_counter_field
= f_fpr
;
8037 DECL_FIELD_CONTEXT (f_gpr
) = record
;
8038 DECL_FIELD_CONTEXT (f_fpr
) = record
;
8039 DECL_FIELD_CONTEXT (f_ovf
) = record
;
8040 DECL_FIELD_CONTEXT (f_sav
) = record
;
8042 TREE_CHAIN (record
) = type_decl
;
8043 TYPE_NAME (record
) = type_decl
;
8044 TYPE_FIELDS (record
) = f_gpr
;
8045 TREE_CHAIN (f_gpr
) = f_fpr
;
8046 TREE_CHAIN (f_fpr
) = f_ovf
;
8047 TREE_CHAIN (f_ovf
) = f_sav
;
8049 layout_type (record
);
8051 /* The correct type is an array type of one element. */
8052 return build_array_type (record
, build_index_type (size_zero_node
));
8055 /* Implement va_start by filling the va_list structure VALIST.
8056 STDARG_P is always true, and ignored.
8057 NEXTARG points to the first anonymous stack argument.
8059 The following global variables are used to initialize
8060 the va_list structure:
8063 holds number of gprs and fprs used for named arguments.
8064 crtl->args.arg_offset_rtx:
8065 holds the offset of the first anonymous stack argument
8066 (relative to the virtual arg pointer). */
8069 s390_va_start (tree valist
, rtx nextarg ATTRIBUTE_UNUSED
)
8071 HOST_WIDE_INT n_gpr
, n_fpr
;
8073 tree f_gpr
, f_fpr
, f_ovf
, f_sav
;
8074 tree gpr
, fpr
, ovf
, sav
, t
;
8076 f_gpr
= TYPE_FIELDS (TREE_TYPE (va_list_type_node
));
8077 f_fpr
= TREE_CHAIN (f_gpr
);
8078 f_ovf
= TREE_CHAIN (f_fpr
);
8079 f_sav
= TREE_CHAIN (f_ovf
);
8081 valist
= build_va_arg_indirect_ref (valist
);
8082 gpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_gpr
), valist
, f_gpr
, NULL_TREE
);
8083 fpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_fpr
), valist
, f_fpr
, NULL_TREE
);
8084 ovf
= build3 (COMPONENT_REF
, TREE_TYPE (f_ovf
), valist
, f_ovf
, NULL_TREE
);
8085 sav
= build3 (COMPONENT_REF
, TREE_TYPE (f_sav
), valist
, f_sav
, NULL_TREE
);
8087 /* Count number of gp and fp argument registers used. */
8089 n_gpr
= crtl
->args
.info
.gprs
;
8090 n_fpr
= crtl
->args
.info
.fprs
;
8092 if (cfun
->va_list_gpr_size
)
8094 t
= build2 (GIMPLE_MODIFY_STMT
, TREE_TYPE (gpr
), gpr
,
8095 build_int_cst (NULL_TREE
, n_gpr
));
8096 TREE_SIDE_EFFECTS (t
) = 1;
8097 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
8100 if (cfun
->va_list_fpr_size
)
8102 t
= build2 (GIMPLE_MODIFY_STMT
, TREE_TYPE (fpr
), fpr
,
8103 build_int_cst (NULL_TREE
, n_fpr
));
8104 TREE_SIDE_EFFECTS (t
) = 1;
8105 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
8108 /* Find the overflow area. */
8109 if (n_gpr
+ cfun
->va_list_gpr_size
> GP_ARG_NUM_REG
8110 || n_fpr
+ cfun
->va_list_fpr_size
> FP_ARG_NUM_REG
)
8112 t
= make_tree (TREE_TYPE (ovf
), virtual_incoming_args_rtx
);
8114 off
= INTVAL (crtl
->args
.arg_offset_rtx
);
8115 off
= off
< 0 ? 0 : off
;
8116 if (TARGET_DEBUG_ARG
)
8117 fprintf (stderr
, "va_start: n_gpr = %d, n_fpr = %d off %d\n",
8118 (int)n_gpr
, (int)n_fpr
, off
);
8120 t
= build2 (POINTER_PLUS_EXPR
, TREE_TYPE (ovf
), t
, size_int (off
));
8122 t
= build2 (GIMPLE_MODIFY_STMT
, TREE_TYPE (ovf
), ovf
, t
);
8123 TREE_SIDE_EFFECTS (t
) = 1;
8124 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
8127 /* Find the register save area. */
8128 if ((cfun
->va_list_gpr_size
&& n_gpr
< GP_ARG_NUM_REG
)
8129 || (cfun
->va_list_fpr_size
&& n_fpr
< FP_ARG_NUM_REG
))
8131 t
= make_tree (TREE_TYPE (sav
), return_address_pointer_rtx
);
8132 t
= build2 (POINTER_PLUS_EXPR
, TREE_TYPE (sav
), t
,
8133 size_int (-RETURN_REGNUM
* UNITS_PER_WORD
));
8135 t
= build2 (GIMPLE_MODIFY_STMT
, TREE_TYPE (sav
), sav
, t
);
8136 TREE_SIDE_EFFECTS (t
) = 1;
8137 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
8141 /* Implement va_arg by updating the va_list structure
8142 VALIST as required to retrieve an argument of type
8143 TYPE, and returning that argument.
8145 Generates code equivalent to:
8147 if (integral value) {
8148 if (size <= 4 && args.gpr < 5 ||
8149 size > 4 && args.gpr < 4 )
8150 ret = args.reg_save_area[args.gpr+8]
8152 ret = *args.overflow_arg_area++;
8153 } else if (float value) {
8155 ret = args.reg_save_area[args.fpr+64]
8157 ret = *args.overflow_arg_area++;
8158 } else if (aggregate value) {
8160 ret = *args.reg_save_area[args.gpr]
8162 ret = **args.overflow_arg_area++;
8166 s390_gimplify_va_arg (tree valist
, tree type
, tree
*pre_p
,
8167 tree
*post_p ATTRIBUTE_UNUSED
)
8169 tree f_gpr
, f_fpr
, f_ovf
, f_sav
;
8170 tree gpr
, fpr
, ovf
, sav
, reg
, t
, u
;
8171 int indirect_p
, size
, n_reg
, sav_ofs
, sav_scale
, max_reg
;
8172 tree lab_false
, lab_over
, addr
;
8174 f_gpr
= TYPE_FIELDS (TREE_TYPE (va_list_type_node
));
8175 f_fpr
= TREE_CHAIN (f_gpr
);
8176 f_ovf
= TREE_CHAIN (f_fpr
);
8177 f_sav
= TREE_CHAIN (f_ovf
);
8179 valist
= build_va_arg_indirect_ref (valist
);
8180 gpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_gpr
), valist
, f_gpr
, NULL_TREE
);
8181 fpr
= build3 (COMPONENT_REF
, TREE_TYPE (f_fpr
), valist
, f_fpr
, NULL_TREE
);
8182 ovf
= build3 (COMPONENT_REF
, TREE_TYPE (f_ovf
), valist
, f_ovf
, NULL_TREE
);
8183 sav
= build3 (COMPONENT_REF
, TREE_TYPE (f_sav
), valist
, f_sav
, NULL_TREE
);
8185 size
= int_size_in_bytes (type
);
8187 if (pass_by_reference (NULL
, TYPE_MODE (type
), type
, false))
8189 if (TARGET_DEBUG_ARG
)
8191 fprintf (stderr
, "va_arg: aggregate type");
8195 /* Aggregates are passed by reference. */
8200 /* kernel stack layout on 31 bit: It is assumed here that no padding
8201 will be added by s390_frame_info because for va_args always an even
8202 number of gprs has to be saved r15-r2 = 14 regs. */
8203 sav_ofs
= 2 * UNITS_PER_WORD
;
8204 sav_scale
= UNITS_PER_WORD
;
8205 size
= UNITS_PER_WORD
;
8206 max_reg
= GP_ARG_NUM_REG
- n_reg
;
8208 else if (s390_function_arg_float (TYPE_MODE (type
), type
))
8210 if (TARGET_DEBUG_ARG
)
8212 fprintf (stderr
, "va_arg: float type");
8216 /* FP args go in FP registers, if present. */
8220 sav_ofs
= 16 * UNITS_PER_WORD
;
8222 max_reg
= FP_ARG_NUM_REG
- n_reg
;
8226 if (TARGET_DEBUG_ARG
)
8228 fprintf (stderr
, "va_arg: other type");
8232 /* Otherwise into GP registers. */
8235 n_reg
= (size
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
8237 /* kernel stack layout on 31 bit: It is assumed here that no padding
8238 will be added by s390_frame_info because for va_args always an even
8239 number of gprs has to be saved r15-r2 = 14 regs. */
8240 sav_ofs
= 2 * UNITS_PER_WORD
;
8242 if (size
< UNITS_PER_WORD
)
8243 sav_ofs
+= UNITS_PER_WORD
- size
;
8245 sav_scale
= UNITS_PER_WORD
;
8246 max_reg
= GP_ARG_NUM_REG
- n_reg
;
8249 /* Pull the value out of the saved registers ... */
8251 lab_false
= create_artificial_label ();
8252 lab_over
= create_artificial_label ();
8253 addr
= create_tmp_var (ptr_type_node
, "addr");
8254 DECL_POINTER_ALIAS_SET (addr
) = get_varargs_alias_set ();
8256 t
= fold_convert (TREE_TYPE (reg
), size_int (max_reg
));
8257 t
= build2 (GT_EXPR
, boolean_type_node
, reg
, t
);
8258 u
= build1 (GOTO_EXPR
, void_type_node
, lab_false
);
8259 t
= build3 (COND_EXPR
, void_type_node
, t
, u
, NULL_TREE
);
8260 gimplify_and_add (t
, pre_p
);
8262 t
= build2 (POINTER_PLUS_EXPR
, ptr_type_node
, sav
,
8263 size_int (sav_ofs
));
8264 u
= build2 (MULT_EXPR
, TREE_TYPE (reg
), reg
,
8265 fold_convert (TREE_TYPE (reg
), size_int (sav_scale
)));
8266 t
= build2 (POINTER_PLUS_EXPR
, ptr_type_node
, t
, fold_convert (sizetype
, u
));
8268 t
= build2 (GIMPLE_MODIFY_STMT
, void_type_node
, addr
, t
);
8269 gimplify_and_add (t
, pre_p
);
8271 t
= build1 (GOTO_EXPR
, void_type_node
, lab_over
);
8272 gimplify_and_add (t
, pre_p
);
8274 t
= build1 (LABEL_EXPR
, void_type_node
, lab_false
);
8275 append_to_statement_list (t
, pre_p
);
8278 /* ... Otherwise out of the overflow area. */
8281 if (size
< UNITS_PER_WORD
)
8282 t
= build2 (POINTER_PLUS_EXPR
, ptr_type_node
, t
,
8283 size_int (UNITS_PER_WORD
- size
));
8285 gimplify_expr (&t
, pre_p
, NULL
, is_gimple_val
, fb_rvalue
);
8287 u
= build2 (GIMPLE_MODIFY_STMT
, void_type_node
, addr
, t
);
8288 gimplify_and_add (u
, pre_p
);
8290 t
= build2 (POINTER_PLUS_EXPR
, ptr_type_node
, t
,
8292 t
= build2 (GIMPLE_MODIFY_STMT
, ptr_type_node
, ovf
, t
);
8293 gimplify_and_add (t
, pre_p
);
8295 t
= build1 (LABEL_EXPR
, void_type_node
, lab_over
);
8296 append_to_statement_list (t
, pre_p
);
8299 /* Increment register save count. */
8301 u
= build2 (PREINCREMENT_EXPR
, TREE_TYPE (reg
), reg
,
8302 fold_convert (TREE_TYPE (reg
), size_int (n_reg
)));
8303 gimplify_and_add (u
, pre_p
);
8307 t
= build_pointer_type (build_pointer_type (type
));
8308 addr
= fold_convert (t
, addr
);
8309 addr
= build_va_arg_indirect_ref (addr
);
8313 t
= build_pointer_type (type
);
8314 addr
= fold_convert (t
, addr
);
8317 return build_va_arg_indirect_ref (addr
);
8325 S390_BUILTIN_THREAD_POINTER
,
8326 S390_BUILTIN_SET_THREAD_POINTER
,
8331 static unsigned int const code_for_builtin_64
[S390_BUILTIN_max
] = {
8336 static unsigned int const code_for_builtin_31
[S390_BUILTIN_max
] = {
8342 s390_init_builtins (void)
8346 ftype
= build_function_type (ptr_type_node
, void_list_node
);
8347 add_builtin_function ("__builtin_thread_pointer", ftype
,
8348 S390_BUILTIN_THREAD_POINTER
, BUILT_IN_MD
,
8351 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
8352 add_builtin_function ("__builtin_set_thread_pointer", ftype
,
8353 S390_BUILTIN_SET_THREAD_POINTER
, BUILT_IN_MD
,
8357 /* Expand an expression EXP that calls a built-in function,
8358 with result going to TARGET if that's convenient
8359 (and in mode MODE if that's convenient).
8360 SUBTARGET may be used as the target for computing one of EXP's operands.
8361 IGNORE is nonzero if the value is to be ignored. */
8364 s390_expand_builtin (tree exp
, rtx target
, rtx subtarget ATTRIBUTE_UNUSED
,
8365 enum machine_mode mode ATTRIBUTE_UNUSED
,
8366 int ignore ATTRIBUTE_UNUSED
)
8370 unsigned int const *code_for_builtin
=
8371 TARGET_64BIT
? code_for_builtin_64
: code_for_builtin_31
;
8373 tree fndecl
= TREE_OPERAND (CALL_EXPR_FN (exp
), 0);
8374 unsigned int fcode
= DECL_FUNCTION_CODE (fndecl
);
8375 enum insn_code icode
;
8376 rtx op
[MAX_ARGS
], pat
;
8380 call_expr_arg_iterator iter
;
8382 if (fcode
>= S390_BUILTIN_max
)
8383 internal_error ("bad builtin fcode");
8384 icode
= code_for_builtin
[fcode
];
8386 internal_error ("bad builtin fcode");
8388 nonvoid
= TREE_TYPE (TREE_TYPE (fndecl
)) != void_type_node
;
8391 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, exp
)
8393 const struct insn_operand_data
*insn_op
;
8395 if (arg
== error_mark_node
)
8397 if (arity
> MAX_ARGS
)
8400 insn_op
= &insn_data
[icode
].operand
[arity
+ nonvoid
];
8402 op
[arity
] = expand_expr (arg
, NULL_RTX
, insn_op
->mode
, 0);
8404 if (!(*insn_op
->predicate
) (op
[arity
], insn_op
->mode
))
8405 op
[arity
] = copy_to_mode_reg (insn_op
->mode
, op
[arity
]);
8411 enum machine_mode tmode
= insn_data
[icode
].operand
[0].mode
;
8413 || GET_MODE (target
) != tmode
8414 || !(*insn_data
[icode
].operand
[0].predicate
) (target
, tmode
))
8415 target
= gen_reg_rtx (tmode
);
8421 pat
= GEN_FCN (icode
) (target
);
8425 pat
= GEN_FCN (icode
) (target
, op
[0]);
8427 pat
= GEN_FCN (icode
) (op
[0]);
8430 pat
= GEN_FCN (icode
) (target
, op
[0], op
[1]);
8446 /* Output assembly code for the trampoline template to
8449 On S/390, we use gpr 1 internally in the trampoline code;
8450 gpr 0 is used to hold the static chain. */
8453 s390_trampoline_template (FILE *file
)
8456 op
[0] = gen_rtx_REG (Pmode
, 0);
8457 op
[1] = gen_rtx_REG (Pmode
, 1);
8461 output_asm_insn ("basr\t%1,0", op
);
8462 output_asm_insn ("lmg\t%0,%1,14(%1)", op
);
8463 output_asm_insn ("br\t%1", op
);
8464 ASM_OUTPUT_SKIP (file
, (HOST_WIDE_INT
)(TRAMPOLINE_SIZE
- 10));
8468 output_asm_insn ("basr\t%1,0", op
);
8469 output_asm_insn ("lm\t%0,%1,6(%1)", op
);
8470 output_asm_insn ("br\t%1", op
);
8471 ASM_OUTPUT_SKIP (file
, (HOST_WIDE_INT
)(TRAMPOLINE_SIZE
- 8));
8475 /* Emit RTL insns to initialize the variable parts of a trampoline.
8476 FNADDR is an RTX for the address of the function's pure code.
8477 CXT is an RTX for the static chain value for the function. */
8480 s390_initialize_trampoline (rtx addr
, rtx fnaddr
, rtx cxt
)
8482 emit_move_insn (gen_rtx_MEM (Pmode
,
8483 memory_address (Pmode
,
8484 plus_constant (addr
, (TARGET_64BIT
? 16 : 8)))), cxt
);
8485 emit_move_insn (gen_rtx_MEM (Pmode
,
8486 memory_address (Pmode
,
8487 plus_constant (addr
, (TARGET_64BIT
? 24 : 12)))), fnaddr
);
8490 /* Output assembler code to FILE to increment profiler label # LABELNO
8491 for profiling a function entry. */
8494 s390_function_profiler (FILE *file
, int labelno
)
8499 ASM_GENERATE_INTERNAL_LABEL (label
, "LP", labelno
);
8501 fprintf (file
, "# function profiler \n");
8503 op
[0] = gen_rtx_REG (Pmode
, RETURN_REGNUM
);
8504 op
[1] = gen_rtx_REG (Pmode
, STACK_POINTER_REGNUM
);
8505 op
[1] = gen_rtx_MEM (Pmode
, plus_constant (op
[1], UNITS_PER_WORD
));
8507 op
[2] = gen_rtx_REG (Pmode
, 1);
8508 op
[3] = gen_rtx_SYMBOL_REF (Pmode
, label
);
8509 SYMBOL_REF_FLAGS (op
[3]) = SYMBOL_FLAG_LOCAL
;
8511 op
[4] = gen_rtx_SYMBOL_REF (Pmode
, "_mcount");
8514 op
[4] = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op
[4]), UNSPEC_PLT
);
8515 op
[4] = gen_rtx_CONST (Pmode
, op
[4]);
8520 output_asm_insn ("stg\t%0,%1", op
);
8521 output_asm_insn ("larl\t%2,%3", op
);
8522 output_asm_insn ("brasl\t%0,%4", op
);
8523 output_asm_insn ("lg\t%0,%1", op
);
8527 op
[6] = gen_label_rtx ();
8529 output_asm_insn ("st\t%0,%1", op
);
8530 output_asm_insn ("bras\t%2,%l6", op
);
8531 output_asm_insn (".long\t%4", op
);
8532 output_asm_insn (".long\t%3", op
);
8533 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[6]));
8534 output_asm_insn ("l\t%0,0(%2)", op
);
8535 output_asm_insn ("l\t%2,4(%2)", op
);
8536 output_asm_insn ("basr\t%0,%0", op
);
8537 output_asm_insn ("l\t%0,%1", op
);
8541 op
[5] = gen_label_rtx ();
8542 op
[6] = gen_label_rtx ();
8544 output_asm_insn ("st\t%0,%1", op
);
8545 output_asm_insn ("bras\t%2,%l6", op
);
8546 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[5]));
8547 output_asm_insn (".long\t%4-%l5", op
);
8548 output_asm_insn (".long\t%3-%l5", op
);
8549 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[6]));
8550 output_asm_insn ("lr\t%0,%2", op
);
8551 output_asm_insn ("a\t%0,0(%2)", op
);
8552 output_asm_insn ("a\t%2,4(%2)", op
);
8553 output_asm_insn ("basr\t%0,%0", op
);
8554 output_asm_insn ("l\t%0,%1", op
);
8558 /* Encode symbol attributes (local vs. global, tls model) of a SYMBOL_REF
8559 into its SYMBOL_REF_FLAGS. */
8562 s390_encode_section_info (tree decl
, rtx rtl
, int first
)
8564 default_encode_section_info (decl
, rtl
, first
);
8566 /* If a variable has a forced alignment to < 2 bytes, mark it with
8567 SYMBOL_FLAG_ALIGN1 to prevent it from being used as LARL operand. */
8568 if (TREE_CODE (decl
) == VAR_DECL
8569 && DECL_USER_ALIGN (decl
) && DECL_ALIGN (decl
) < 16)
8570 SYMBOL_REF_FLAGS (XEXP (rtl
, 0)) |= SYMBOL_FLAG_ALIGN1
;
8573 /* Output thunk to FILE that implements a C++ virtual function call (with
8574 multiple inheritance) to FUNCTION. The thunk adjusts the this pointer
8575 by DELTA, and unless VCALL_OFFSET is zero, applies an additional adjustment
8576 stored at VCALL_OFFSET in the vtable whose address is located at offset 0
8577 relative to the resulting this pointer. */
8580 s390_output_mi_thunk (FILE *file
, tree thunk ATTRIBUTE_UNUSED
,
8581 HOST_WIDE_INT delta
, HOST_WIDE_INT vcall_offset
,
8587 /* Operand 0 is the target function. */
8588 op
[0] = XEXP (DECL_RTL (function
), 0);
8589 if (flag_pic
&& !SYMBOL_REF_LOCAL_P (op
[0]))
8592 op
[0] = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op
[0]),
8593 TARGET_64BIT
? UNSPEC_PLT
: UNSPEC_GOT
);
8594 op
[0] = gen_rtx_CONST (Pmode
, op
[0]);
8597 /* Operand 1 is the 'this' pointer. */
8598 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function
)), function
))
8599 op
[1] = gen_rtx_REG (Pmode
, 3);
8601 op
[1] = gen_rtx_REG (Pmode
, 2);
8603 /* Operand 2 is the delta. */
8604 op
[2] = GEN_INT (delta
);
8606 /* Operand 3 is the vcall_offset. */
8607 op
[3] = GEN_INT (vcall_offset
);
8609 /* Operand 4 is the temporary register. */
8610 op
[4] = gen_rtx_REG (Pmode
, 1);
8612 /* Operands 5 to 8 can be used as labels. */
8618 /* Operand 9 can be used for temporary register. */
8621 /* Generate code. */
8624 /* Setup literal pool pointer if required. */
8625 if ((!DISP_IN_RANGE (delta
)
8626 && !CONST_OK_FOR_K (delta
)
8627 && !CONST_OK_FOR_Os (delta
))
8628 || (!DISP_IN_RANGE (vcall_offset
)
8629 && !CONST_OK_FOR_K (vcall_offset
)
8630 && !CONST_OK_FOR_Os (vcall_offset
)))
8632 op
[5] = gen_label_rtx ();
8633 output_asm_insn ("larl\t%4,%5", op
);
8636 /* Add DELTA to this pointer. */
8639 if (CONST_OK_FOR_J (delta
))
8640 output_asm_insn ("la\t%1,%2(%1)", op
);
8641 else if (DISP_IN_RANGE (delta
))
8642 output_asm_insn ("lay\t%1,%2(%1)", op
);
8643 else if (CONST_OK_FOR_K (delta
))
8644 output_asm_insn ("aghi\t%1,%2", op
);
8645 else if (CONST_OK_FOR_Os (delta
))
8646 output_asm_insn ("agfi\t%1,%2", op
);
8649 op
[6] = gen_label_rtx ();
8650 output_asm_insn ("agf\t%1,%6-%5(%4)", op
);
8654 /* Perform vcall adjustment. */
8657 if (DISP_IN_RANGE (vcall_offset
))
8659 output_asm_insn ("lg\t%4,0(%1)", op
);
8660 output_asm_insn ("ag\t%1,%3(%4)", op
);
8662 else if (CONST_OK_FOR_K (vcall_offset
))
8664 output_asm_insn ("lghi\t%4,%3", op
);
8665 output_asm_insn ("ag\t%4,0(%1)", op
);
8666 output_asm_insn ("ag\t%1,0(%4)", op
);
8668 else if (CONST_OK_FOR_Os (vcall_offset
))
8670 output_asm_insn ("lgfi\t%4,%3", op
);
8671 output_asm_insn ("ag\t%4,0(%1)", op
);
8672 output_asm_insn ("ag\t%1,0(%4)", op
);
8676 op
[7] = gen_label_rtx ();
8677 output_asm_insn ("llgf\t%4,%7-%5(%4)", op
);
8678 output_asm_insn ("ag\t%4,0(%1)", op
);
8679 output_asm_insn ("ag\t%1,0(%4)", op
);
8683 /* Jump to target. */
8684 output_asm_insn ("jg\t%0", op
);
8686 /* Output literal pool if required. */
8689 output_asm_insn (".align\t4", op
);
8690 targetm
.asm_out
.internal_label (file
, "L",
8691 CODE_LABEL_NUMBER (op
[5]));
8695 targetm
.asm_out
.internal_label (file
, "L",
8696 CODE_LABEL_NUMBER (op
[6]));
8697 output_asm_insn (".long\t%2", op
);
8701 targetm
.asm_out
.internal_label (file
, "L",
8702 CODE_LABEL_NUMBER (op
[7]));
8703 output_asm_insn (".long\t%3", op
);
8708 /* Setup base pointer if required. */
8710 || (!DISP_IN_RANGE (delta
)
8711 && !CONST_OK_FOR_K (delta
)
8712 && !CONST_OK_FOR_Os (delta
))
8713 || (!DISP_IN_RANGE (delta
)
8714 && !CONST_OK_FOR_K (vcall_offset
)
8715 && !CONST_OK_FOR_Os (vcall_offset
)))
8717 op
[5] = gen_label_rtx ();
8718 output_asm_insn ("basr\t%4,0", op
);
8719 targetm
.asm_out
.internal_label (file
, "L",
8720 CODE_LABEL_NUMBER (op
[5]));
8723 /* Add DELTA to this pointer. */
8726 if (CONST_OK_FOR_J (delta
))
8727 output_asm_insn ("la\t%1,%2(%1)", op
);
8728 else if (DISP_IN_RANGE (delta
))
8729 output_asm_insn ("lay\t%1,%2(%1)", op
);
8730 else if (CONST_OK_FOR_K (delta
))
8731 output_asm_insn ("ahi\t%1,%2", op
);
8732 else if (CONST_OK_FOR_Os (delta
))
8733 output_asm_insn ("afi\t%1,%2", op
);
8736 op
[6] = gen_label_rtx ();
8737 output_asm_insn ("a\t%1,%6-%5(%4)", op
);
8741 /* Perform vcall adjustment. */
8744 if (CONST_OK_FOR_J (vcall_offset
))
8746 output_asm_insn ("l\t%4,0(%1)", op
);
8747 output_asm_insn ("a\t%1,%3(%4)", op
);
8749 else if (DISP_IN_RANGE (vcall_offset
))
8751 output_asm_insn ("l\t%4,0(%1)", op
);
8752 output_asm_insn ("ay\t%1,%3(%4)", op
);
8754 else if (CONST_OK_FOR_K (vcall_offset
))
8756 output_asm_insn ("lhi\t%4,%3", op
);
8757 output_asm_insn ("a\t%4,0(%1)", op
);
8758 output_asm_insn ("a\t%1,0(%4)", op
);
8760 else if (CONST_OK_FOR_Os (vcall_offset
))
8762 output_asm_insn ("iilf\t%4,%3", op
);
8763 output_asm_insn ("a\t%4,0(%1)", op
);
8764 output_asm_insn ("a\t%1,0(%4)", op
);
8768 op
[7] = gen_label_rtx ();
8769 output_asm_insn ("l\t%4,%7-%5(%4)", op
);
8770 output_asm_insn ("a\t%4,0(%1)", op
);
8771 output_asm_insn ("a\t%1,0(%4)", op
);
8774 /* We had to clobber the base pointer register.
8775 Re-setup the base pointer (with a different base). */
8776 op
[5] = gen_label_rtx ();
8777 output_asm_insn ("basr\t%4,0", op
);
8778 targetm
.asm_out
.internal_label (file
, "L",
8779 CODE_LABEL_NUMBER (op
[5]));
8782 /* Jump to target. */
8783 op
[8] = gen_label_rtx ();
8786 output_asm_insn ("l\t%4,%8-%5(%4)", op
);
8788 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
8789 /* We cannot call through .plt, since .plt requires %r12 loaded. */
8790 else if (flag_pic
== 1)
8792 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
8793 output_asm_insn ("l\t%4,%0(%4)", op
);
8795 else if (flag_pic
== 2)
8797 op
[9] = gen_rtx_REG (Pmode
, 0);
8798 output_asm_insn ("l\t%9,%8-4-%5(%4)", op
);
8799 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
8800 output_asm_insn ("ar\t%4,%9", op
);
8801 output_asm_insn ("l\t%4,0(%4)", op
);
8804 output_asm_insn ("br\t%4", op
);
8806 /* Output literal pool. */
8807 output_asm_insn (".align\t4", op
);
8809 if (nonlocal
&& flag_pic
== 2)
8810 output_asm_insn (".long\t%0", op
);
8813 op
[0] = gen_rtx_SYMBOL_REF (Pmode
, "_GLOBAL_OFFSET_TABLE_");
8814 SYMBOL_REF_FLAGS (op
[0]) = SYMBOL_FLAG_LOCAL
;
8817 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[8]));
8819 output_asm_insn (".long\t%0", op
);
8821 output_asm_insn (".long\t%0-%5", op
);
8825 targetm
.asm_out
.internal_label (file
, "L",
8826 CODE_LABEL_NUMBER (op
[6]));
8827 output_asm_insn (".long\t%2", op
);
8831 targetm
.asm_out
.internal_label (file
, "L",
8832 CODE_LABEL_NUMBER (op
[7]));
8833 output_asm_insn (".long\t%3", op
);
8839 s390_valid_pointer_mode (enum machine_mode mode
)
8841 return (mode
== SImode
|| (TARGET_64BIT
&& mode
== DImode
));
8844 /* Checks whether the given CALL_EXPR would use a caller
8845 saved register. This is used to decide whether sibling call
8846 optimization could be performed on the respective function
8850 s390_call_saved_register_used (tree call_expr
)
8852 CUMULATIVE_ARGS cum
;
8854 enum machine_mode mode
;
8859 INIT_CUMULATIVE_ARGS (cum
, NULL
, NULL
, 0, 0);
8861 for (i
= 0; i
< call_expr_nargs (call_expr
); i
++)
8863 parameter
= CALL_EXPR_ARG (call_expr
, i
);
8864 gcc_assert (parameter
);
8866 /* For an undeclared variable passed as parameter we will get
8867 an ERROR_MARK node here. */
8868 if (TREE_CODE (parameter
) == ERROR_MARK
)
8871 type
= TREE_TYPE (parameter
);
8874 mode
= TYPE_MODE (type
);
8877 if (pass_by_reference (&cum
, mode
, type
, true))
8880 type
= build_pointer_type (type
);
8883 parm_rtx
= s390_function_arg (&cum
, mode
, type
, 0);
8885 s390_function_arg_advance (&cum
, mode
, type
, 0);
8887 if (parm_rtx
&& REG_P (parm_rtx
))
8890 reg
< HARD_REGNO_NREGS (REGNO (parm_rtx
), GET_MODE (parm_rtx
));
8892 if (! call_used_regs
[reg
+ REGNO (parm_rtx
)])
8899 /* Return true if the given call expression can be
8900 turned into a sibling call.
8901 DECL holds the declaration of the function to be called whereas
8902 EXP is the call expression itself. */
8905 s390_function_ok_for_sibcall (tree decl
, tree exp
)
8907 /* The TPF epilogue uses register 1. */
8908 if (TARGET_TPF_PROFILING
)
8911 /* The 31 bit PLT code uses register 12 (GOT pointer - caller saved)
8912 which would have to be restored before the sibcall. */
8913 if (!TARGET_64BIT
&& flag_pic
&& decl
&& !targetm
.binds_local_p (decl
))
8916 /* Register 6 on s390 is available as an argument register but unfortunately
8917 "caller saved". This makes functions needing this register for arguments
8918 not suitable for sibcalls. */
8919 return !s390_call_saved_register_used (exp
);
8922 /* Return the fixed registers used for condition codes. */
8925 s390_fixed_condition_code_regs (unsigned int *p1
, unsigned int *p2
)
8928 *p2
= INVALID_REGNUM
;
8933 /* This function is used by the call expanders of the machine description.
8934 It emits the call insn itself together with the necessary operations
8935 to adjust the target address and returns the emitted insn.
8936 ADDR_LOCATION is the target address rtx
8937 TLS_CALL the location of the thread-local symbol
8938 RESULT_REG the register where the result of the call should be stored
8939 RETADDR_REG the register where the return address should be stored
8940 If this parameter is NULL_RTX the call is considered
8941 to be a sibling call. */
8944 s390_emit_call (rtx addr_location
, rtx tls_call
, rtx result_reg
,
8947 bool plt_call
= false;
8953 /* Direct function calls need special treatment. */
8954 if (GET_CODE (addr_location
) == SYMBOL_REF
)
8956 /* When calling a global routine in PIC mode, we must
8957 replace the symbol itself with the PLT stub. */
8958 if (flag_pic
&& !SYMBOL_REF_LOCAL_P (addr_location
))
8960 addr_location
= gen_rtx_UNSPEC (Pmode
,
8961 gen_rtvec (1, addr_location
),
8963 addr_location
= gen_rtx_CONST (Pmode
, addr_location
);
8967 /* Unless we can use the bras(l) insn, force the
8968 routine address into a register. */
8969 if (!TARGET_SMALL_EXEC
&& !TARGET_CPU_ZARCH
)
8972 addr_location
= legitimize_pic_address (addr_location
, 0);
8974 addr_location
= force_reg (Pmode
, addr_location
);
8978 /* If it is already an indirect call or the code above moved the
8979 SYMBOL_REF to somewhere else make sure the address can be found in
8981 if (retaddr_reg
== NULL_RTX
8982 && GET_CODE (addr_location
) != SYMBOL_REF
8985 emit_move_insn (gen_rtx_REG (Pmode
, SIBCALL_REGNUM
), addr_location
);
8986 addr_location
= gen_rtx_REG (Pmode
, SIBCALL_REGNUM
);
8989 addr_location
= gen_rtx_MEM (QImode
, addr_location
);
8990 call
= gen_rtx_CALL (VOIDmode
, addr_location
, const0_rtx
);
8992 if (result_reg
!= NULL_RTX
)
8993 call
= gen_rtx_SET (VOIDmode
, result_reg
, call
);
8995 if (retaddr_reg
!= NULL_RTX
)
8997 clobber
= gen_rtx_CLOBBER (VOIDmode
, retaddr_reg
);
8999 if (tls_call
!= NULL_RTX
)
9000 vec
= gen_rtvec (3, call
, clobber
,
9001 gen_rtx_USE (VOIDmode
, tls_call
));
9003 vec
= gen_rtvec (2, call
, clobber
);
9005 call
= gen_rtx_PARALLEL (VOIDmode
, vec
);
9008 insn
= emit_call_insn (call
);
9010 /* 31-bit PLT stubs and tls calls use the GOT register implicitly. */
9011 if ((!TARGET_64BIT
&& plt_call
) || tls_call
!= NULL_RTX
)
9013 /* s390_function_ok_for_sibcall should
9014 have denied sibcalls in this case. */
9015 gcc_assert (retaddr_reg
!= NULL_RTX
);
9017 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), pic_offset_table_rtx
);
9022 /* Implement CONDITIONAL_REGISTER_USAGE. */
9025 s390_conditional_register_usage (void)
9031 fixed_regs
[PIC_OFFSET_TABLE_REGNUM
] = 1;
9032 call_used_regs
[PIC_OFFSET_TABLE_REGNUM
] = 1;
9034 if (TARGET_CPU_ZARCH
)
9036 fixed_regs
[BASE_REGNUM
] = 0;
9037 call_used_regs
[BASE_REGNUM
] = 0;
9038 fixed_regs
[RETURN_REGNUM
] = 0;
9039 call_used_regs
[RETURN_REGNUM
] = 0;
9043 for (i
= 24; i
< 32; i
++)
9044 call_used_regs
[i
] = call_really_used_regs
[i
] = 0;
9048 for (i
= 18; i
< 20; i
++)
9049 call_used_regs
[i
] = call_really_used_regs
[i
] = 0;
9052 if (TARGET_SOFT_FLOAT
)
9054 for (i
= 16; i
< 32; i
++)
9055 call_used_regs
[i
] = fixed_regs
[i
] = 1;
9059 /* Corresponding function to eh_return expander. */
9061 static GTY(()) rtx s390_tpf_eh_return_symbol
;
9063 s390_emit_tpf_eh_return (rtx target
)
9067 if (!s390_tpf_eh_return_symbol
)
9068 s390_tpf_eh_return_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "__tpf_eh_return");
9070 reg
= gen_rtx_REG (Pmode
, 2);
9072 emit_move_insn (reg
, target
);
9073 insn
= s390_emit_call (s390_tpf_eh_return_symbol
, NULL_RTX
, reg
,
9074 gen_rtx_REG (Pmode
, RETURN_REGNUM
));
9075 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), reg
);
9077 emit_move_insn (EH_RETURN_HANDLER_RTX
, reg
);
9080 /* Rework the prologue/epilogue to avoid saving/restoring
9081 registers unnecessarily. */
9084 s390_optimize_prologue (void)
9086 rtx insn
, new_insn
, next_insn
;
9088 /* Do a final recompute of the frame-related data. */
9090 s390_update_frame_layout ();
9092 /* If all special registers are in fact used, there's nothing we
9093 can do, so no point in walking the insn list. */
9095 if (cfun_frame_layout
.first_save_gpr
<= BASE_REGNUM
9096 && cfun_frame_layout
.last_save_gpr
>= BASE_REGNUM
9097 && (TARGET_CPU_ZARCH
9098 || (cfun_frame_layout
.first_save_gpr
<= RETURN_REGNUM
9099 && cfun_frame_layout
.last_save_gpr
>= RETURN_REGNUM
)))
9102 /* Search for prologue/epilogue insns and replace them. */
9104 for (insn
= get_insns (); insn
; insn
= next_insn
)
9106 int first
, last
, off
;
9107 rtx set
, base
, offset
;
9109 next_insn
= NEXT_INSN (insn
);
9111 if (GET_CODE (insn
) != INSN
)
9114 if (GET_CODE (PATTERN (insn
)) == PARALLEL
9115 && store_multiple_operation (PATTERN (insn
), VOIDmode
))
9117 set
= XVECEXP (PATTERN (insn
), 0, 0);
9118 first
= REGNO (SET_SRC (set
));
9119 last
= first
+ XVECLEN (PATTERN (insn
), 0) - 1;
9120 offset
= const0_rtx
;
9121 base
= eliminate_constant_term (XEXP (SET_DEST (set
), 0), &offset
);
9122 off
= INTVAL (offset
);
9124 if (GET_CODE (base
) != REG
|| off
< 0)
9126 if (cfun_frame_layout
.first_save_gpr
!= -1
9127 && (cfun_frame_layout
.first_save_gpr
< first
9128 || cfun_frame_layout
.last_save_gpr
> last
))
9130 if (REGNO (base
) != STACK_POINTER_REGNUM
9131 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
9133 if (first
> BASE_REGNUM
|| last
< BASE_REGNUM
)
9136 if (cfun_frame_layout
.first_save_gpr
!= -1)
9138 new_insn
= save_gprs (base
,
9139 off
+ (cfun_frame_layout
.first_save_gpr
9140 - first
) * UNITS_PER_WORD
,
9141 cfun_frame_layout
.first_save_gpr
,
9142 cfun_frame_layout
.last_save_gpr
);
9143 new_insn
= emit_insn_before (new_insn
, insn
);
9144 INSN_ADDRESSES_NEW (new_insn
, -1);
9151 if (cfun_frame_layout
.first_save_gpr
== -1
9152 && GET_CODE (PATTERN (insn
)) == SET
9153 && GET_CODE (SET_SRC (PATTERN (insn
))) == REG
9154 && (REGNO (SET_SRC (PATTERN (insn
))) == BASE_REGNUM
9155 || (!TARGET_CPU_ZARCH
9156 && REGNO (SET_SRC (PATTERN (insn
))) == RETURN_REGNUM
))
9157 && GET_CODE (SET_DEST (PATTERN (insn
))) == MEM
)
9159 set
= PATTERN (insn
);
9160 first
= REGNO (SET_SRC (set
));
9161 offset
= const0_rtx
;
9162 base
= eliminate_constant_term (XEXP (SET_DEST (set
), 0), &offset
);
9163 off
= INTVAL (offset
);
9165 if (GET_CODE (base
) != REG
|| off
< 0)
9167 if (REGNO (base
) != STACK_POINTER_REGNUM
9168 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
9175 if (GET_CODE (PATTERN (insn
)) == PARALLEL
9176 && load_multiple_operation (PATTERN (insn
), VOIDmode
))
9178 set
= XVECEXP (PATTERN (insn
), 0, 0);
9179 first
= REGNO (SET_DEST (set
));
9180 last
= first
+ XVECLEN (PATTERN (insn
), 0) - 1;
9181 offset
= const0_rtx
;
9182 base
= eliminate_constant_term (XEXP (SET_SRC (set
), 0), &offset
);
9183 off
= INTVAL (offset
);
9185 if (GET_CODE (base
) != REG
|| off
< 0)
9187 if (cfun_frame_layout
.first_restore_gpr
!= -1
9188 && (cfun_frame_layout
.first_restore_gpr
< first
9189 || cfun_frame_layout
.last_restore_gpr
> last
))
9191 if (REGNO (base
) != STACK_POINTER_REGNUM
9192 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
9194 if (first
> BASE_REGNUM
|| last
< BASE_REGNUM
)
9197 if (cfun_frame_layout
.first_restore_gpr
!= -1)
9199 new_insn
= restore_gprs (base
,
9200 off
+ (cfun_frame_layout
.first_restore_gpr
9201 - first
) * UNITS_PER_WORD
,
9202 cfun_frame_layout
.first_restore_gpr
,
9203 cfun_frame_layout
.last_restore_gpr
);
9204 new_insn
= emit_insn_before (new_insn
, insn
);
9205 INSN_ADDRESSES_NEW (new_insn
, -1);
9212 if (cfun_frame_layout
.first_restore_gpr
== -1
9213 && GET_CODE (PATTERN (insn
)) == SET
9214 && GET_CODE (SET_DEST (PATTERN (insn
))) == REG
9215 && (REGNO (SET_DEST (PATTERN (insn
))) == BASE_REGNUM
9216 || (!TARGET_CPU_ZARCH
9217 && REGNO (SET_DEST (PATTERN (insn
))) == RETURN_REGNUM
))
9218 && GET_CODE (SET_SRC (PATTERN (insn
))) == MEM
)
9220 set
= PATTERN (insn
);
9221 first
= REGNO (SET_DEST (set
));
9222 offset
= const0_rtx
;
9223 base
= eliminate_constant_term (XEXP (SET_SRC (set
), 0), &offset
);
9224 off
= INTVAL (offset
);
9226 if (GET_CODE (base
) != REG
|| off
< 0)
9228 if (REGNO (base
) != STACK_POINTER_REGNUM
9229 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
9238 /* Perform machine-dependent processing. */
9243 bool pool_overflow
= false;
9245 /* Make sure all splits have been performed; splits after
9246 machine_dependent_reorg might confuse insn length counts. */
9247 split_all_insns_noflow ();
9249 /* From here on decomposed literal pool addresses must be accepted. */
9250 cfun
->machine
->decomposed_literal_pool_addresses_ok_p
= true;
9252 /* Install the main literal pool and the associated base
9253 register load insns.
9255 In addition, there are two problematic situations we need
9258 - the literal pool might be > 4096 bytes in size, so that
9259 some of its elements cannot be directly accessed
9261 - a branch target might be > 64K away from the branch, so that
9262 it is not possible to use a PC-relative instruction.
9264 To fix those, we split the single literal pool into multiple
9265 pool chunks, reloading the pool base register at various
9266 points throughout the function to ensure it always points to
9267 the pool chunk the following code expects, and / or replace
9268 PC-relative branches by absolute branches.
9270 However, the two problems are interdependent: splitting the
9271 literal pool can move a branch further away from its target,
9272 causing the 64K limit to overflow, and on the other hand,
9273 replacing a PC-relative branch by an absolute branch means
9274 we need to put the branch target address into the literal
9275 pool, possibly causing it to overflow.
9277 So, we loop trying to fix up both problems until we manage
9278 to satisfy both conditions at the same time. Note that the
9279 loop is guaranteed to terminate as every pass of the loop
9280 strictly decreases the total number of PC-relative branches
9281 in the function. (This is not completely true as there
9282 might be branch-over-pool insns introduced by chunkify_start.
9283 Those never need to be split however.) */
9287 struct constant_pool
*pool
= NULL
;
9289 /* Collect the literal pool. */
9292 pool
= s390_mainpool_start ();
9294 pool_overflow
= true;
9297 /* If literal pool overflowed, start to chunkify it. */
9299 pool
= s390_chunkify_start ();
9301 /* Split out-of-range branches. If this has created new
9302 literal pool entries, cancel current chunk list and
9303 recompute it. zSeries machines have large branch
9304 instructions, so we never need to split a branch. */
9305 if (!TARGET_CPU_ZARCH
&& s390_split_branches ())
9308 s390_chunkify_cancel (pool
);
9310 s390_mainpool_cancel (pool
);
9315 /* If we made it up to here, both conditions are satisfied.
9316 Finish up literal pool related changes. */
9318 s390_chunkify_finish (pool
);
9320 s390_mainpool_finish (pool
);
9322 /* We're done splitting branches. */
9323 cfun
->machine
->split_branches_pending_p
= false;
9327 /* Generate out-of-pool execute target insns. */
9328 if (TARGET_CPU_ZARCH
)
9330 rtx insn
, label
, target
;
9332 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
9334 label
= s390_execute_label (insn
);
9338 gcc_assert (label
!= const0_rtx
);
9340 target
= emit_label (XEXP (label
, 0));
9341 INSN_ADDRESSES_NEW (target
, -1);
9343 target
= emit_insn (s390_execute_target (insn
));
9344 INSN_ADDRESSES_NEW (target
, -1);
9348 /* Try to optimize prologue and epilogue further. */
9349 s390_optimize_prologue ();
9353 /* Initialize GCC target structure. */
9355 #undef TARGET_ASM_ALIGNED_HI_OP
9356 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
9357 #undef TARGET_ASM_ALIGNED_DI_OP
9358 #define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
9359 #undef TARGET_ASM_INTEGER
9360 #define TARGET_ASM_INTEGER s390_assemble_integer
9362 #undef TARGET_ASM_OPEN_PAREN
9363 #define TARGET_ASM_OPEN_PAREN ""
9365 #undef TARGET_ASM_CLOSE_PAREN
9366 #define TARGET_ASM_CLOSE_PAREN ""
9368 #undef TARGET_DEFAULT_TARGET_FLAGS
9369 #define TARGET_DEFAULT_TARGET_FLAGS (TARGET_DEFAULT | MASK_FUSED_MADD)
9370 #undef TARGET_HANDLE_OPTION
9371 #define TARGET_HANDLE_OPTION s390_handle_option
9373 #undef TARGET_ENCODE_SECTION_INFO
9374 #define TARGET_ENCODE_SECTION_INFO s390_encode_section_info
9377 #undef TARGET_HAVE_TLS
9378 #define TARGET_HAVE_TLS true
9380 #undef TARGET_CANNOT_FORCE_CONST_MEM
9381 #define TARGET_CANNOT_FORCE_CONST_MEM s390_cannot_force_const_mem
9383 #undef TARGET_DELEGITIMIZE_ADDRESS
9384 #define TARGET_DELEGITIMIZE_ADDRESS s390_delegitimize_address
9386 #undef TARGET_RETURN_IN_MEMORY
9387 #define TARGET_RETURN_IN_MEMORY s390_return_in_memory
9389 #undef TARGET_INIT_BUILTINS
9390 #define TARGET_INIT_BUILTINS s390_init_builtins
9391 #undef TARGET_EXPAND_BUILTIN
9392 #define TARGET_EXPAND_BUILTIN s390_expand_builtin
9394 #undef TARGET_ASM_OUTPUT_MI_THUNK
9395 #define TARGET_ASM_OUTPUT_MI_THUNK s390_output_mi_thunk
9396 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
9397 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_const_tree_hwi_hwi_const_tree_true
9399 #undef TARGET_SCHED_ADJUST_PRIORITY
9400 #define TARGET_SCHED_ADJUST_PRIORITY s390_adjust_priority
9401 #undef TARGET_SCHED_ISSUE_RATE
9402 #define TARGET_SCHED_ISSUE_RATE s390_issue_rate
9403 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
9404 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD s390_first_cycle_multipass_dfa_lookahead
9406 #undef TARGET_CANNOT_COPY_INSN_P
9407 #define TARGET_CANNOT_COPY_INSN_P s390_cannot_copy_insn_p
9408 #undef TARGET_RTX_COSTS
9409 #define TARGET_RTX_COSTS s390_rtx_costs
9410 #undef TARGET_ADDRESS_COST
9411 #define TARGET_ADDRESS_COST s390_address_cost
9413 #undef TARGET_MACHINE_DEPENDENT_REORG
9414 #define TARGET_MACHINE_DEPENDENT_REORG s390_reorg
9416 #undef TARGET_VALID_POINTER_MODE
9417 #define TARGET_VALID_POINTER_MODE s390_valid_pointer_mode
9419 #undef TARGET_BUILD_BUILTIN_VA_LIST
9420 #define TARGET_BUILD_BUILTIN_VA_LIST s390_build_builtin_va_list
9421 #undef TARGET_EXPAND_BUILTIN_VA_START
9422 #define TARGET_EXPAND_BUILTIN_VA_START s390_va_start
9423 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
9424 #define TARGET_GIMPLIFY_VA_ARG_EXPR s390_gimplify_va_arg
9426 #undef TARGET_PROMOTE_FUNCTION_ARGS
9427 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_const_tree_true
9428 #undef TARGET_PROMOTE_FUNCTION_RETURN
9429 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_const_tree_true
9430 #undef TARGET_PASS_BY_REFERENCE
9431 #define TARGET_PASS_BY_REFERENCE s390_pass_by_reference
9433 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
9434 #define TARGET_FUNCTION_OK_FOR_SIBCALL s390_function_ok_for_sibcall
9436 #undef TARGET_FIXED_CONDITION_CODE_REGS
9437 #define TARGET_FIXED_CONDITION_CODE_REGS s390_fixed_condition_code_regs
9439 #undef TARGET_CC_MODES_COMPATIBLE
9440 #define TARGET_CC_MODES_COMPATIBLE s390_cc_modes_compatible
9442 #undef TARGET_INVALID_WITHIN_DOLOOP
9443 #define TARGET_INVALID_WITHIN_DOLOOP hook_constcharptr_const_rtx_null
9446 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
9447 #define TARGET_ASM_OUTPUT_DWARF_DTPREL s390_output_dwarf_dtprel
9450 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
9451 #undef TARGET_MANGLE_TYPE
9452 #define TARGET_MANGLE_TYPE s390_mangle_type
9455 #undef TARGET_SCALAR_MODE_SUPPORTED_P
9456 #define TARGET_SCALAR_MODE_SUPPORTED_P s390_scalar_mode_supported_p
9458 #undef TARGET_SECONDARY_RELOAD
9459 #define TARGET_SECONDARY_RELOAD s390_secondary_reload
9461 #undef TARGET_LIBGCC_CMP_RETURN_MODE
9462 #define TARGET_LIBGCC_CMP_RETURN_MODE s390_libgcc_cmp_return_mode
9464 #undef TARGET_LIBGCC_SHIFT_COUNT_MODE
9465 #define TARGET_LIBGCC_SHIFT_COUNT_MODE s390_libgcc_shift_count_mode
9467 struct gcc_target targetm
= TARGET_INITIALIZER
;
9469 #include "gt-s390.h"