1 /* Subroutines used for code generation on IBM S/390 and zSeries
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
3 Free Software Foundation, Inc.
4 Contributed by Hartmut Penner (hpenner@de.ibm.com) and
5 Ulrich Weigand (uweigand@de.ibm.com).
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 2, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING. If not, write to the Free
21 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
26 #include "coretypes.h"
32 #include "hard-reg-set.h"
34 #include "insn-config.h"
35 #include "conditions.h"
37 #include "insn-attr.h"
45 #include "basic-block.h"
46 #include "integrate.h"
49 #include "target-def.h"
51 #include "langhooks.h"
53 #include "tree-gimple.h"
56 /* Define the specific costs for a given cpu. */
58 struct processor_costs
61 const int m
; /* cost of an M instruction. */
62 const int mghi
; /* cost of an MGHI instruction. */
63 const int mh
; /* cost of an MH instruction. */
64 const int mhi
; /* cost of an MHI instruction. */
65 const int ml
; /* cost of an ML instruction. */
66 const int mr
; /* cost of an MR instruction. */
67 const int ms
; /* cost of an MS instruction. */
68 const int msg
; /* cost of an MSG instruction. */
69 const int msgf
; /* cost of an MSGF instruction. */
70 const int msgfr
; /* cost of an MSGFR instruction. */
71 const int msgr
; /* cost of an MSGR instruction. */
72 const int msr
; /* cost of an MSR instruction. */
73 const int mult_df
; /* cost of multiplication in DFmode. */
76 const int sqxbr
; /* cost of square root in TFmode. */
77 const int sqdbr
; /* cost of square root in DFmode. */
78 const int sqebr
; /* cost of square root in SFmode. */
79 /* multiply and add */
80 const int madbr
; /* cost of multiply and add in DFmode. */
81 const int maebr
; /* cost of multiply and add in SFmode. */
96 const struct processor_costs
*s390_cost
;
99 struct processor_costs z900_cost
=
101 COSTS_N_INSNS (5), /* M */
102 COSTS_N_INSNS (10), /* MGHI */
103 COSTS_N_INSNS (5), /* MH */
104 COSTS_N_INSNS (4), /* MHI */
105 COSTS_N_INSNS (5), /* ML */
106 COSTS_N_INSNS (5), /* MR */
107 COSTS_N_INSNS (4), /* MS */
108 COSTS_N_INSNS (15), /* MSG */
109 COSTS_N_INSNS (7), /* MSGF */
110 COSTS_N_INSNS (7), /* MSGFR */
111 COSTS_N_INSNS (10), /* MSGR */
112 COSTS_N_INSNS (4), /* MSR */
113 COSTS_N_INSNS (7), /* multiplication in DFmode */
114 COSTS_N_INSNS (13), /* MXBR */
115 COSTS_N_INSNS (136), /* SQXBR */
116 COSTS_N_INSNS (44), /* SQDBR */
117 COSTS_N_INSNS (35), /* SQEBR */
118 COSTS_N_INSNS (18), /* MADBR */
119 COSTS_N_INSNS (13), /* MAEBR */
120 COSTS_N_INSNS (134), /* DXBR */
121 COSTS_N_INSNS (135), /* DXR */
122 COSTS_N_INSNS (30), /* DDBR */
123 COSTS_N_INSNS (30), /* DDR */
124 COSTS_N_INSNS (27), /* DEBR */
125 COSTS_N_INSNS (26), /* DER */
126 COSTS_N_INSNS (220), /* DLGR */
127 COSTS_N_INSNS (34), /* DLR */
128 COSTS_N_INSNS (34), /* DR */
129 COSTS_N_INSNS (32), /* DSGFR */
130 COSTS_N_INSNS (32), /* DSGR */
134 struct processor_costs z990_cost
=
136 COSTS_N_INSNS (4), /* M */
137 COSTS_N_INSNS (2), /* MGHI */
138 COSTS_N_INSNS (2), /* MH */
139 COSTS_N_INSNS (2), /* MHI */
140 COSTS_N_INSNS (4), /* ML */
141 COSTS_N_INSNS (4), /* MR */
142 COSTS_N_INSNS (5), /* MS */
143 COSTS_N_INSNS (6), /* MSG */
144 COSTS_N_INSNS (4), /* MSGF */
145 COSTS_N_INSNS (4), /* MSGFR */
146 COSTS_N_INSNS (4), /* MSGR */
147 COSTS_N_INSNS (4), /* MSR */
148 COSTS_N_INSNS (1), /* multiplication in DFmode */
149 COSTS_N_INSNS (28), /* MXBR */
150 COSTS_N_INSNS (130), /* SQXBR */
151 COSTS_N_INSNS (66), /* SQDBR */
152 COSTS_N_INSNS (38), /* SQEBR */
153 COSTS_N_INSNS (1), /* MADBR */
154 COSTS_N_INSNS (1), /* MAEBR */
155 COSTS_N_INSNS (60), /* DXBR */
156 COSTS_N_INSNS (72), /* DXR */
157 COSTS_N_INSNS (40), /* DDBR */
158 COSTS_N_INSNS (44), /* DDR */
159 COSTS_N_INSNS (26), /* DDBR */
160 COSTS_N_INSNS (28), /* DER */
161 COSTS_N_INSNS (176), /* DLGR */
162 COSTS_N_INSNS (31), /* DLR */
163 COSTS_N_INSNS (31), /* DR */
164 COSTS_N_INSNS (31), /* DSGFR */
165 COSTS_N_INSNS (31), /* DSGR */
169 struct processor_costs z9_109_cost
=
171 COSTS_N_INSNS (4), /* M */
172 COSTS_N_INSNS (2), /* MGHI */
173 COSTS_N_INSNS (2), /* MH */
174 COSTS_N_INSNS (2), /* MHI */
175 COSTS_N_INSNS (4), /* ML */
176 COSTS_N_INSNS (4), /* MR */
177 COSTS_N_INSNS (5), /* MS */
178 COSTS_N_INSNS (6), /* MSG */
179 COSTS_N_INSNS (4), /* MSGF */
180 COSTS_N_INSNS (4), /* MSGFR */
181 COSTS_N_INSNS (4), /* MSGR */
182 COSTS_N_INSNS (4), /* MSR */
183 COSTS_N_INSNS (1), /* multiplication in DFmode */
184 COSTS_N_INSNS (28), /* MXBR */
185 COSTS_N_INSNS (130), /* SQXBR */
186 COSTS_N_INSNS (66), /* SQDBR */
187 COSTS_N_INSNS (38), /* SQEBR */
188 COSTS_N_INSNS (1), /* MADBR */
189 COSTS_N_INSNS (1), /* MAEBR */
190 COSTS_N_INSNS (60), /* DXBR */
191 COSTS_N_INSNS (72), /* DXR */
192 COSTS_N_INSNS (40), /* DDBR */
193 COSTS_N_INSNS (37), /* DDR */
194 COSTS_N_INSNS (26), /* DDBR */
195 COSTS_N_INSNS (28), /* DER */
196 COSTS_N_INSNS (30), /* DLGR */
197 COSTS_N_INSNS (23), /* DLR */
198 COSTS_N_INSNS (23), /* DR */
199 COSTS_N_INSNS (24), /* DSGFR */
200 COSTS_N_INSNS (24), /* DSGR */
203 extern int reload_completed
;
205 /* Save information from a "cmpxx" operation until the branch or scc is
207 rtx s390_compare_op0
, s390_compare_op1
;
209 /* Save the result of a compare_and_swap until the branch or scc is
211 rtx s390_compare_emitted
= NULL_RTX
;
213 /* Structure used to hold the components of a S/390 memory
214 address. A legitimate address on S/390 is of the general
216 base + index + displacement
217 where any of the components is optional.
219 base and index are registers of the class ADDR_REGS,
220 displacement is an unsigned 12-bit immediate constant. */
231 /* Which cpu are we tuning for. */
232 enum processor_type s390_tune
= PROCESSOR_max
;
233 enum processor_flags s390_tune_flags
;
234 /* Which instruction set architecture to use. */
235 enum processor_type s390_arch
;
236 enum processor_flags s390_arch_flags
;
238 HOST_WIDE_INT s390_warn_framesize
= 0;
239 HOST_WIDE_INT s390_stack_size
= 0;
240 HOST_WIDE_INT s390_stack_guard
= 0;
242 /* The following structure is embedded in the machine
243 specific part of struct function. */
245 struct s390_frame_layout
GTY (())
247 /* Offset within stack frame. */
248 HOST_WIDE_INT gprs_offset
;
249 HOST_WIDE_INT f0_offset
;
250 HOST_WIDE_INT f4_offset
;
251 HOST_WIDE_INT f8_offset
;
252 HOST_WIDE_INT backchain_offset
;
254 /* Number of first and last gpr where slots in the register
255 save area are reserved for. */
256 int first_save_gpr_slot
;
257 int last_save_gpr_slot
;
259 /* Number of first and last gpr to be saved, restored. */
261 int first_restore_gpr
;
263 int last_restore_gpr
;
265 /* Bits standing for floating point registers. Set, if the
266 respective register has to be saved. Starting with reg 16 (f0)
267 at the rightmost bit.
268 Bit 15 - 8 7 6 5 4 3 2 1 0
269 fpr 15 - 8 7 5 3 1 6 4 2 0
270 reg 31 - 24 23 22 21 20 19 18 17 16 */
271 unsigned int fpr_bitmap
;
273 /* Number of floating point registers f8-f15 which must be saved. */
276 /* Set if return address needs to be saved.
277 This flag is set by s390_return_addr_rtx if it could not use
278 the initial value of r14 and therefore depends on r14 saved
280 bool save_return_addr_p
;
282 /* Size of stack frame. */
283 HOST_WIDE_INT frame_size
;
286 /* Define the structure for the machine field in struct function. */
288 struct machine_function
GTY(())
290 struct s390_frame_layout frame_layout
;
292 /* Literal pool base register. */
295 /* True if we may need to perform branch splitting. */
296 bool split_branches_pending_p
;
298 /* True during final stage of literal pool processing. */
299 bool decomposed_literal_pool_addresses_ok_p
;
301 /* Some local-dynamic TLS symbol name. */
302 const char *some_ld_name
;
304 bool has_landing_pad_p
;
307 /* Few accessor macros for struct cfun->machine->s390_frame_layout. */
309 #define cfun_frame_layout (cfun->machine->frame_layout)
310 #define cfun_save_high_fprs_p (!!cfun_frame_layout.high_fprs)
311 #define cfun_gprs_save_area_size ((cfun_frame_layout.last_save_gpr_slot - \
312 cfun_frame_layout.first_save_gpr_slot + 1) * UNITS_PER_WORD)
313 #define cfun_set_fpr_bit(BITNUM) (cfun->machine->frame_layout.fpr_bitmap |= \
315 #define cfun_fpr_bit_p(BITNUM) (!!(cfun->machine->frame_layout.fpr_bitmap & \
318 /* Number of GPRs and FPRs used for argument passing. */
319 #define GP_ARG_NUM_REG 5
320 #define FP_ARG_NUM_REG (TARGET_64BIT? 4 : 2)
322 /* A couple of shortcuts. */
323 #define CONST_OK_FOR_J(x) \
324 CONST_OK_FOR_CONSTRAINT_P((x), 'J', "J")
325 #define CONST_OK_FOR_K(x) \
326 CONST_OK_FOR_CONSTRAINT_P((x), 'K', "K")
327 #define CONST_OK_FOR_Os(x) \
328 CONST_OK_FOR_CONSTRAINT_P((x), 'O', "Os")
329 #define CONST_OK_FOR_Op(x) \
330 CONST_OK_FOR_CONSTRAINT_P((x), 'O', "Op")
331 #define CONST_OK_FOR_On(x) \
332 CONST_OK_FOR_CONSTRAINT_P((x), 'O', "On")
334 /* Set the has_landing_pad_p flag in struct machine_function to VALUE. */
337 s390_set_has_landing_pad_p (bool value
)
339 cfun
->machine
->has_landing_pad_p
= value
;
342 /* If two condition code modes are compatible, return a condition code
343 mode which is compatible with both. Otherwise, return
346 static enum machine_mode
347 s390_cc_modes_compatible (enum machine_mode m1
, enum machine_mode m2
)
355 if (m2
== CCUmode
|| m2
== CCTmode
|| m2
== CCZ1mode
356 || m2
== CCSmode
|| m2
== CCSRmode
|| m2
== CCURmode
)
377 /* Return true if SET either doesn't set the CC register, or else
378 the source and destination have matching CC modes and that
379 CC mode is at least as constrained as REQ_MODE. */
382 s390_match_ccmode_set (rtx set
, enum machine_mode req_mode
)
384 enum machine_mode set_mode
;
386 gcc_assert (GET_CODE (set
) == SET
);
388 if (GET_CODE (SET_DEST (set
)) != REG
|| !CC_REGNO_P (REGNO (SET_DEST (set
))))
391 set_mode
= GET_MODE (SET_DEST (set
));
405 if (req_mode
!= set_mode
)
410 if (req_mode
!= CCSmode
&& req_mode
!= CCUmode
&& req_mode
!= CCTmode
411 && req_mode
!= CCSRmode
&& req_mode
!= CCURmode
)
417 if (req_mode
!= CCAmode
)
425 return (GET_MODE (SET_SRC (set
)) == set_mode
);
428 /* Return true if every SET in INSN that sets the CC register
429 has source and destination with matching CC modes and that
430 CC mode is at least as constrained as REQ_MODE.
431 If REQ_MODE is VOIDmode, always return false. */
434 s390_match_ccmode (rtx insn
, enum machine_mode req_mode
)
438 /* s390_tm_ccmode returns VOIDmode to indicate failure. */
439 if (req_mode
== VOIDmode
)
442 if (GET_CODE (PATTERN (insn
)) == SET
)
443 return s390_match_ccmode_set (PATTERN (insn
), req_mode
);
445 if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
446 for (i
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
448 rtx set
= XVECEXP (PATTERN (insn
), 0, i
);
449 if (GET_CODE (set
) == SET
)
450 if (!s390_match_ccmode_set (set
, req_mode
))
457 /* If a test-under-mask instruction can be used to implement
458 (compare (and ... OP1) OP2), return the CC mode required
459 to do that. Otherwise, return VOIDmode.
460 MIXED is true if the instruction can distinguish between
461 CC1 and CC2 for mixed selected bits (TMxx), it is false
462 if the instruction cannot (TM). */
465 s390_tm_ccmode (rtx op1
, rtx op2
, bool mixed
)
469 /* ??? Fixme: should work on CONST_DOUBLE as well. */
470 if (GET_CODE (op1
) != CONST_INT
|| GET_CODE (op2
) != CONST_INT
)
473 /* Selected bits all zero: CC0.
474 e.g.: int a; if ((a & (16 + 128)) == 0) */
475 if (INTVAL (op2
) == 0)
478 /* Selected bits all one: CC3.
479 e.g.: int a; if ((a & (16 + 128)) == 16 + 128) */
480 if (INTVAL (op2
) == INTVAL (op1
))
483 /* Exactly two bits selected, mixed zeroes and ones: CC1 or CC2. e.g.:
485 if ((a & (16 + 128)) == 16) -> CCT1
486 if ((a & (16 + 128)) == 128) -> CCT2 */
489 bit1
= exact_log2 (INTVAL (op2
));
490 bit0
= exact_log2 (INTVAL (op1
) ^ INTVAL (op2
));
491 if (bit0
!= -1 && bit1
!= -1)
492 return bit0
> bit1
? CCT1mode
: CCT2mode
;
498 /* Given a comparison code OP (EQ, NE, etc.) and the operands
499 OP0 and OP1 of a COMPARE, return the mode to be used for the
503 s390_select_ccmode (enum rtx_code code
, rtx op0
, rtx op1
)
509 if ((GET_CODE (op0
) == NEG
|| GET_CODE (op0
) == ABS
)
510 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
512 if (GET_CODE (op0
) == PLUS
&& GET_CODE (XEXP (op0
, 1)) == CONST_INT
513 && CONST_OK_FOR_K (INTVAL (XEXP (op0
, 1))))
515 if ((GET_CODE (op0
) == PLUS
|| GET_CODE (op0
) == MINUS
516 || GET_CODE (op1
) == NEG
)
517 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
520 if (GET_CODE (op0
) == AND
)
522 /* Check whether we can potentially do it via TM. */
523 enum machine_mode ccmode
;
524 ccmode
= s390_tm_ccmode (XEXP (op0
, 1), op1
, 1);
525 if (ccmode
!= VOIDmode
)
527 /* Relax CCTmode to CCZmode to allow fall-back to AND
528 if that turns out to be beneficial. */
529 return ccmode
== CCTmode
? CCZmode
: ccmode
;
533 if (register_operand (op0
, HImode
)
534 && GET_CODE (op1
) == CONST_INT
535 && (INTVAL (op1
) == -1 || INTVAL (op1
) == 65535))
537 if (register_operand (op0
, QImode
)
538 && GET_CODE (op1
) == CONST_INT
539 && (INTVAL (op1
) == -1 || INTVAL (op1
) == 255))
548 /* The only overflow condition of NEG and ABS happens when
549 -INT_MAX is used as parameter, which stays negative. So
550 we have an overflow from a positive value to a negative.
551 Using CCAP mode the resulting cc can be used for comparisons. */
552 if ((GET_CODE (op0
) == NEG
|| GET_CODE (op0
) == ABS
)
553 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
556 /* If constants are involved in an add instruction it is possible to use
557 the resulting cc for comparisons with zero. Knowing the sign of the
558 constant the overflow behavior gets predictable. e.g.:
559 int a, b; if ((b = a + c) > 0)
560 with c as a constant value: c < 0 -> CCAN and c >= 0 -> CCAP */
561 if (GET_CODE (op0
) == PLUS
&& GET_CODE (XEXP (op0
, 1)) == CONST_INT
562 && CONST_OK_FOR_K (INTVAL (XEXP (op0
, 1))))
564 if (INTVAL (XEXP((op0
), 1)) < 0)
578 if ((GET_CODE (op0
) == SIGN_EXTEND
|| GET_CODE (op0
) == ZERO_EXTEND
)
579 && GET_CODE (op1
) != CONST_INT
)
585 if (GET_CODE (op0
) == PLUS
586 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
589 if ((GET_CODE (op0
) == SIGN_EXTEND
|| GET_CODE (op0
) == ZERO_EXTEND
)
590 && GET_CODE (op1
) != CONST_INT
)
596 if (GET_CODE (op0
) == MINUS
597 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
600 if ((GET_CODE (op0
) == SIGN_EXTEND
|| GET_CODE (op0
) == ZERO_EXTEND
)
601 && GET_CODE (op1
) != CONST_INT
)
610 /* Replace the comparison OP0 CODE OP1 by a semantically equivalent one
611 that we can implement more efficiently. */
614 s390_canonicalize_comparison (enum rtx_code
*code
, rtx
*op0
, rtx
*op1
)
616 /* Convert ZERO_EXTRACT back to AND to enable TM patterns. */
617 if ((*code
== EQ
|| *code
== NE
)
618 && *op1
== const0_rtx
619 && GET_CODE (*op0
) == ZERO_EXTRACT
620 && GET_CODE (XEXP (*op0
, 1)) == CONST_INT
621 && GET_CODE (XEXP (*op0
, 2)) == CONST_INT
622 && SCALAR_INT_MODE_P (GET_MODE (XEXP (*op0
, 0))))
624 rtx inner
= XEXP (*op0
, 0);
625 HOST_WIDE_INT modesize
= GET_MODE_BITSIZE (GET_MODE (inner
));
626 HOST_WIDE_INT len
= INTVAL (XEXP (*op0
, 1));
627 HOST_WIDE_INT pos
= INTVAL (XEXP (*op0
, 2));
629 if (len
> 0 && len
< modesize
630 && pos
>= 0 && pos
+ len
<= modesize
631 && modesize
<= HOST_BITS_PER_WIDE_INT
)
633 unsigned HOST_WIDE_INT block
;
634 block
= ((unsigned HOST_WIDE_INT
) 1 << len
) - 1;
635 block
<<= modesize
- pos
- len
;
637 *op0
= gen_rtx_AND (GET_MODE (inner
), inner
,
638 gen_int_mode (block
, GET_MODE (inner
)));
642 /* Narrow AND of memory against immediate to enable TM. */
643 if ((*code
== EQ
|| *code
== NE
)
644 && *op1
== const0_rtx
645 && GET_CODE (*op0
) == AND
646 && GET_CODE (XEXP (*op0
, 1)) == CONST_INT
647 && SCALAR_INT_MODE_P (GET_MODE (XEXP (*op0
, 0))))
649 rtx inner
= XEXP (*op0
, 0);
650 rtx mask
= XEXP (*op0
, 1);
652 /* Ignore paradoxical SUBREGs if all extra bits are masked out. */
653 if (GET_CODE (inner
) == SUBREG
654 && SCALAR_INT_MODE_P (GET_MODE (SUBREG_REG (inner
)))
655 && (GET_MODE_SIZE (GET_MODE (inner
))
656 >= GET_MODE_SIZE (GET_MODE (SUBREG_REG (inner
))))
658 & GET_MODE_MASK (GET_MODE (inner
))
659 & ~GET_MODE_MASK (GET_MODE (SUBREG_REG (inner
))))
661 inner
= SUBREG_REG (inner
);
663 /* Do not change volatile MEMs. */
664 if (MEM_P (inner
) && !MEM_VOLATILE_P (inner
))
666 int part
= s390_single_part (XEXP (*op0
, 1),
667 GET_MODE (inner
), QImode
, 0);
670 mask
= gen_int_mode (s390_extract_part (mask
, QImode
, 0), QImode
);
671 inner
= adjust_address_nv (inner
, QImode
, part
);
672 *op0
= gen_rtx_AND (QImode
, inner
, mask
);
677 /* Narrow comparisons against 0xffff to HImode if possible. */
678 if ((*code
== EQ
|| *code
== NE
)
679 && GET_CODE (*op1
) == CONST_INT
680 && INTVAL (*op1
) == 0xffff
681 && SCALAR_INT_MODE_P (GET_MODE (*op0
))
682 && (nonzero_bits (*op0
, GET_MODE (*op0
))
683 & ~(unsigned HOST_WIDE_INT
) 0xffff) == 0)
685 *op0
= gen_lowpart (HImode
, *op0
);
690 /* Remove redundant UNSPEC_CMPINT conversions if possible. */
691 if (GET_CODE (*op0
) == UNSPEC
692 && XINT (*op0
, 1) == UNSPEC_CMPINT
693 && XVECLEN (*op0
, 0) == 1
694 && GET_MODE (XVECEXP (*op0
, 0, 0)) == CCUmode
695 && GET_CODE (XVECEXP (*op0
, 0, 0)) == REG
696 && REGNO (XVECEXP (*op0
, 0, 0)) == CC_REGNUM
697 && *op1
== const0_rtx
)
699 enum rtx_code new_code
= UNKNOWN
;
702 case EQ
: new_code
= EQ
; break;
703 case NE
: new_code
= NE
; break;
704 case LT
: new_code
= GTU
; break;
705 case GT
: new_code
= LTU
; break;
706 case LE
: new_code
= GEU
; break;
707 case GE
: new_code
= LEU
; break;
711 if (new_code
!= UNKNOWN
)
713 *op0
= XVECEXP (*op0
, 0, 0);
718 /* Simplify cascaded EQ, NE with const0_rtx. */
719 if ((*code
== NE
|| *code
== EQ
)
720 && (GET_CODE (*op0
) == EQ
|| GET_CODE (*op0
) == NE
)
721 && GET_MODE (*op0
) == SImode
722 && GET_MODE (XEXP (*op0
, 0)) == CCZ1mode
723 && REG_P (XEXP (*op0
, 0))
724 && XEXP (*op0
, 1) == const0_rtx
725 && *op1
== const0_rtx
)
727 if ((*code
== EQ
&& GET_CODE (*op0
) == NE
)
728 || (*code
== NE
&& GET_CODE (*op0
) == EQ
))
732 *op0
= XEXP (*op0
, 0);
735 /* Prefer register over memory as first operand. */
736 if (MEM_P (*op0
) && REG_P (*op1
))
738 rtx tem
= *op0
; *op0
= *op1
; *op1
= tem
;
739 *code
= swap_condition (*code
);
743 /* Emit a compare instruction suitable to implement the comparison
744 OP0 CODE OP1. Return the correct condition RTL to be placed in
745 the IF_THEN_ELSE of the conditional branch testing the result. */
748 s390_emit_compare (enum rtx_code code
, rtx op0
, rtx op1
)
750 enum machine_mode mode
= s390_select_ccmode (code
, op0
, op1
);
753 /* Do not output a redundant compare instruction if a compare_and_swap
754 pattern already computed the result and the machine modes are compatible. */
755 if (s390_compare_emitted
756 && (s390_cc_modes_compatible (GET_MODE (s390_compare_emitted
), mode
)
757 == GET_MODE (s390_compare_emitted
)))
758 ret
= gen_rtx_fmt_ee (code
, VOIDmode
, s390_compare_emitted
, const0_rtx
);
761 rtx cc
= gen_rtx_REG (mode
, CC_REGNUM
);
763 emit_insn (gen_rtx_SET (VOIDmode
, cc
, gen_rtx_COMPARE (mode
, op0
, op1
)));
764 ret
= gen_rtx_fmt_ee (code
, VOIDmode
, cc
, const0_rtx
);
766 s390_compare_emitted
= NULL_RTX
;
770 /* Emit a SImode compare and swap instruction setting MEM to NEW if OLD
772 Return the correct condition RTL to be placed in the IF_THEN_ELSE of the
773 conditional branch testing the result. */
776 s390_emit_compare_and_swap (enum rtx_code code
, rtx old
, rtx mem
, rtx cmp
, rtx
new)
780 emit_insn (gen_sync_compare_and_swap_ccsi (old
, mem
, cmp
, new));
781 ret
= gen_rtx_fmt_ee (code
, VOIDmode
, s390_compare_emitted
, const0_rtx
);
783 s390_compare_emitted
= NULL_RTX
;
788 /* Emit a jump instruction to TARGET. If COND is NULL_RTX, emit an
789 unconditional jump, else a conditional jump under condition COND. */
792 s390_emit_jump (rtx target
, rtx cond
)
796 target
= gen_rtx_LABEL_REF (VOIDmode
, target
);
798 target
= gen_rtx_IF_THEN_ELSE (VOIDmode
, cond
, target
, pc_rtx
);
800 insn
= gen_rtx_SET (VOIDmode
, pc_rtx
, target
);
801 emit_jump_insn (insn
);
804 /* Return branch condition mask to implement a branch
805 specified by CODE. Return -1 for invalid comparisons. */
808 s390_branch_condition_mask (rtx code
)
810 const int CC0
= 1 << 3;
811 const int CC1
= 1 << 2;
812 const int CC2
= 1 << 1;
813 const int CC3
= 1 << 0;
815 gcc_assert (GET_CODE (XEXP (code
, 0)) == REG
);
816 gcc_assert (REGNO (XEXP (code
, 0)) == CC_REGNUM
);
817 gcc_assert (XEXP (code
, 1) == const0_rtx
);
819 switch (GET_MODE (XEXP (code
, 0)))
823 switch (GET_CODE (code
))
826 case NE
: return CC1
| CC2
| CC3
;
832 switch (GET_CODE (code
))
835 case NE
: return CC0
| CC2
| CC3
;
841 switch (GET_CODE (code
))
844 case NE
: return CC0
| CC1
| CC3
;
850 switch (GET_CODE (code
))
853 case NE
: return CC0
| CC1
| CC2
;
859 switch (GET_CODE (code
))
861 case EQ
: return CC0
| CC2
;
862 case NE
: return CC1
| CC3
;
868 switch (GET_CODE (code
))
870 case LTU
: return CC2
| CC3
; /* carry */
871 case GEU
: return CC0
| CC1
; /* no carry */
877 switch (GET_CODE (code
))
879 case GTU
: return CC0
| CC1
; /* borrow */
880 case LEU
: return CC2
| CC3
; /* no borrow */
886 switch (GET_CODE (code
))
888 case EQ
: return CC0
| CC2
;
889 case NE
: return CC1
| CC3
;
890 case LTU
: return CC1
;
891 case GTU
: return CC3
;
892 case LEU
: return CC1
| CC2
;
893 case GEU
: return CC2
| CC3
;
898 switch (GET_CODE (code
))
901 case NE
: return CC1
| CC2
| CC3
;
902 case LTU
: return CC1
;
903 case GTU
: return CC2
;
904 case LEU
: return CC0
| CC1
;
905 case GEU
: return CC0
| CC2
;
911 switch (GET_CODE (code
))
914 case NE
: return CC2
| CC1
| CC3
;
915 case LTU
: return CC2
;
916 case GTU
: return CC1
;
917 case LEU
: return CC0
| CC2
;
918 case GEU
: return CC0
| CC1
;
924 switch (GET_CODE (code
))
927 case NE
: return CC1
| CC2
| CC3
;
928 case LT
: return CC1
| CC3
;
930 case LE
: return CC0
| CC1
| CC3
;
931 case GE
: return CC0
| CC2
;
937 switch (GET_CODE (code
))
940 case NE
: return CC1
| CC2
| CC3
;
942 case GT
: return CC2
| CC3
;
943 case LE
: return CC0
| CC1
;
944 case GE
: return CC0
| CC2
| CC3
;
950 switch (GET_CODE (code
))
953 case NE
: return CC1
| CC2
| CC3
;
956 case LE
: return CC0
| CC1
;
957 case GE
: return CC0
| CC2
;
958 case UNORDERED
: return CC3
;
959 case ORDERED
: return CC0
| CC1
| CC2
;
960 case UNEQ
: return CC0
| CC3
;
961 case UNLT
: return CC1
| CC3
;
962 case UNGT
: return CC2
| CC3
;
963 case UNLE
: return CC0
| CC1
| CC3
;
964 case UNGE
: return CC0
| CC2
| CC3
;
965 case LTGT
: return CC1
| CC2
;
971 switch (GET_CODE (code
))
974 case NE
: return CC2
| CC1
| CC3
;
977 case LE
: return CC0
| CC2
;
978 case GE
: return CC0
| CC1
;
979 case UNORDERED
: return CC3
;
980 case ORDERED
: return CC0
| CC2
| CC1
;
981 case UNEQ
: return CC0
| CC3
;
982 case UNLT
: return CC2
| CC3
;
983 case UNGT
: return CC1
| CC3
;
984 case UNLE
: return CC0
| CC2
| CC3
;
985 case UNGE
: return CC0
| CC1
| CC3
;
986 case LTGT
: return CC2
| CC1
;
996 /* If INV is false, return assembler mnemonic string to implement
997 a branch specified by CODE. If INV is true, return mnemonic
998 for the corresponding inverted branch. */
1001 s390_branch_condition_mnemonic (rtx code
, int inv
)
1003 static const char *const mnemonic
[16] =
1005 NULL
, "o", "h", "nle",
1006 "l", "nhe", "lh", "ne",
1007 "e", "nlh", "he", "nl",
1008 "le", "nh", "no", NULL
1011 int mask
= s390_branch_condition_mask (code
);
1012 gcc_assert (mask
>= 0);
1017 gcc_assert (mask
>= 1 && mask
<= 14);
1019 return mnemonic
[mask
];
1022 /* Return the part of op which has a value different from def.
1023 The size of the part is determined by mode.
1024 Use this function only if you already know that op really
1025 contains such a part. */
1027 unsigned HOST_WIDE_INT
1028 s390_extract_part (rtx op
, enum machine_mode mode
, int def
)
1030 unsigned HOST_WIDE_INT value
= 0;
1031 int max_parts
= HOST_BITS_PER_WIDE_INT
/ GET_MODE_BITSIZE (mode
);
1032 int part_bits
= GET_MODE_BITSIZE (mode
);
1033 unsigned HOST_WIDE_INT part_mask
1034 = ((unsigned HOST_WIDE_INT
)1 << part_bits
) - 1;
1037 for (i
= 0; i
< max_parts
; i
++)
1040 value
= (unsigned HOST_WIDE_INT
) INTVAL (op
);
1042 value
>>= part_bits
;
1044 if ((value
& part_mask
) != (def
& part_mask
))
1045 return value
& part_mask
;
1051 /* If OP is an integer constant of mode MODE with exactly one
1052 part of mode PART_MODE unequal to DEF, return the number of that
1053 part. Otherwise, return -1. */
1056 s390_single_part (rtx op
,
1057 enum machine_mode mode
,
1058 enum machine_mode part_mode
,
1061 unsigned HOST_WIDE_INT value
= 0;
1062 int n_parts
= GET_MODE_SIZE (mode
) / GET_MODE_SIZE (part_mode
);
1063 unsigned HOST_WIDE_INT part_mask
1064 = ((unsigned HOST_WIDE_INT
)1 << GET_MODE_BITSIZE (part_mode
)) - 1;
1067 if (GET_CODE (op
) != CONST_INT
)
1070 for (i
= 0; i
< n_parts
; i
++)
1073 value
= (unsigned HOST_WIDE_INT
) INTVAL (op
);
1075 value
>>= GET_MODE_BITSIZE (part_mode
);
1077 if ((value
& part_mask
) != (def
& part_mask
))
1085 return part
== -1 ? -1 : n_parts
- 1 - part
;
1088 /* Check whether we can (and want to) split a double-word
1089 move in mode MODE from SRC to DST into two single-word
1090 moves, moving the subword FIRST_SUBWORD first. */
1093 s390_split_ok_p (rtx dst
, rtx src
, enum machine_mode mode
, int first_subword
)
1095 /* Floating point registers cannot be split. */
1096 if (FP_REG_P (src
) || FP_REG_P (dst
))
1099 /* We don't need to split if operands are directly accessible. */
1100 if (s_operand (src
, mode
) || s_operand (dst
, mode
))
1103 /* Non-offsettable memory references cannot be split. */
1104 if ((GET_CODE (src
) == MEM
&& !offsettable_memref_p (src
))
1105 || (GET_CODE (dst
) == MEM
&& !offsettable_memref_p (dst
)))
1108 /* Moving the first subword must not clobber a register
1109 needed to move the second subword. */
1110 if (register_operand (dst
, mode
))
1112 rtx subreg
= operand_subword (dst
, first_subword
, 0, mode
);
1113 if (reg_overlap_mentioned_p (subreg
, src
))
1120 /* Return true if it can be proven that [MEM1, MEM1 + SIZE]
1121 and [MEM2, MEM2 + SIZE] do overlap and false
1125 s390_overlap_p (rtx mem1
, rtx mem2
, HOST_WIDE_INT size
)
1127 rtx addr1
, addr2
, addr_delta
;
1128 HOST_WIDE_INT delta
;
1130 if (GET_CODE (mem1
) != MEM
|| GET_CODE (mem2
) != MEM
)
1136 addr1
= XEXP (mem1
, 0);
1137 addr2
= XEXP (mem2
, 0);
1139 addr_delta
= simplify_binary_operation (MINUS
, Pmode
, addr2
, addr1
);
1141 /* This overlapping check is used by peepholes merging memory block operations.
1142 Overlapping operations would otherwise be recognized by the S/390 hardware
1143 and would fall back to a slower implementation. Allowing overlapping
1144 operations would lead to slow code but not to wrong code. Therefore we are
1145 somewhat optimistic if we cannot prove that the memory blocks are
1147 That's why we return false here although this may accept operations on
1148 overlapping memory areas. */
1149 if (!addr_delta
|| GET_CODE (addr_delta
) != CONST_INT
)
1152 delta
= INTVAL (addr_delta
);
1155 || (delta
> 0 && delta
< size
)
1156 || (delta
< 0 && -delta
< size
))
1162 /* Check whether the address of memory reference MEM2 equals exactly
1163 the address of memory reference MEM1 plus DELTA. Return true if
1164 we can prove this to be the case, false otherwise. */
1167 s390_offset_p (rtx mem1
, rtx mem2
, rtx delta
)
1169 rtx addr1
, addr2
, addr_delta
;
1171 if (GET_CODE (mem1
) != MEM
|| GET_CODE (mem2
) != MEM
)
1174 addr1
= XEXP (mem1
, 0);
1175 addr2
= XEXP (mem2
, 0);
1177 addr_delta
= simplify_binary_operation (MINUS
, Pmode
, addr2
, addr1
);
1178 if (!addr_delta
|| !rtx_equal_p (addr_delta
, delta
))
1184 /* Expand logical operator CODE in mode MODE with operands OPERANDS. */
1187 s390_expand_logical_operator (enum rtx_code code
, enum machine_mode mode
,
1190 enum machine_mode wmode
= mode
;
1191 rtx dst
= operands
[0];
1192 rtx src1
= operands
[1];
1193 rtx src2
= operands
[2];
1196 /* If we cannot handle the operation directly, use a temp register. */
1197 if (!s390_logical_operator_ok_p (operands
))
1198 dst
= gen_reg_rtx (mode
);
1200 /* QImode and HImode patterns make sense only if we have a destination
1201 in memory. Otherwise perform the operation in SImode. */
1202 if ((mode
== QImode
|| mode
== HImode
) && GET_CODE (dst
) != MEM
)
1205 /* Widen operands if required. */
1208 if (GET_CODE (dst
) == SUBREG
1209 && (tem
= simplify_subreg (wmode
, dst
, mode
, 0)) != 0)
1211 else if (REG_P (dst
))
1212 dst
= gen_rtx_SUBREG (wmode
, dst
, 0);
1214 dst
= gen_reg_rtx (wmode
);
1216 if (GET_CODE (src1
) == SUBREG
1217 && (tem
= simplify_subreg (wmode
, src1
, mode
, 0)) != 0)
1219 else if (GET_MODE (src1
) != VOIDmode
)
1220 src1
= gen_rtx_SUBREG (wmode
, force_reg (mode
, src1
), 0);
1222 if (GET_CODE (src2
) == SUBREG
1223 && (tem
= simplify_subreg (wmode
, src2
, mode
, 0)) != 0)
1225 else if (GET_MODE (src2
) != VOIDmode
)
1226 src2
= gen_rtx_SUBREG (wmode
, force_reg (mode
, src2
), 0);
1229 /* Emit the instruction. */
1230 op
= gen_rtx_SET (VOIDmode
, dst
, gen_rtx_fmt_ee (code
, wmode
, src1
, src2
));
1231 clob
= gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
1232 emit_insn (gen_rtx_PARALLEL (VOIDmode
, gen_rtvec (2, op
, clob
)));
1234 /* Fix up the destination if needed. */
1235 if (dst
!= operands
[0])
1236 emit_move_insn (operands
[0], gen_lowpart (mode
, dst
));
1239 /* Check whether OPERANDS are OK for a logical operation (AND, IOR, XOR). */
1242 s390_logical_operator_ok_p (rtx
*operands
)
1244 /* If the destination operand is in memory, it needs to coincide
1245 with one of the source operands. After reload, it has to be
1246 the first source operand. */
1247 if (GET_CODE (operands
[0]) == MEM
)
1248 return rtx_equal_p (operands
[0], operands
[1])
1249 || (!reload_completed
&& rtx_equal_p (operands
[0], operands
[2]));
1254 /* Narrow logical operation CODE of memory operand MEMOP with immediate
1255 operand IMMOP to switch from SS to SI type instructions. */
1258 s390_narrow_logical_operator (enum rtx_code code
, rtx
*memop
, rtx
*immop
)
1260 int def
= code
== AND
? -1 : 0;
1264 gcc_assert (GET_CODE (*memop
) == MEM
);
1265 gcc_assert (!MEM_VOLATILE_P (*memop
));
1267 mask
= s390_extract_part (*immop
, QImode
, def
);
1268 part
= s390_single_part (*immop
, GET_MODE (*memop
), QImode
, def
);
1269 gcc_assert (part
>= 0);
1271 *memop
= adjust_address (*memop
, QImode
, part
);
1272 *immop
= gen_int_mode (mask
, QImode
);
1276 /* How to allocate a 'struct machine_function'. */
1278 static struct machine_function
*
1279 s390_init_machine_status (void)
1281 return ggc_alloc_cleared (sizeof (struct machine_function
));
1284 /* Change optimizations to be performed, depending on the
1287 LEVEL is the optimization level specified; 2 if `-O2' is
1288 specified, 1 if `-O' is specified, and 0 if neither is specified.
1290 SIZE is nonzero if `-Os' is specified and zero otherwise. */
1293 optimization_options (int level ATTRIBUTE_UNUSED
, int size ATTRIBUTE_UNUSED
)
1295 /* ??? There are apparently still problems with -fcaller-saves. */
1296 flag_caller_saves
= 0;
1298 /* By default, always emit DWARF-2 unwind info. This allows debugging
1299 without maintaining a stack frame back-chain. */
1300 flag_asynchronous_unwind_tables
= 1;
1302 /* Use MVCLE instructions to decrease code size if requested. */
1304 target_flags
|= MASK_MVCLE
;
1307 /* Return true if ARG is the name of a processor. Set *TYPE and *FLAGS
1308 to the associated processor_type and processor_flags if so. */
1311 s390_handle_arch_option (const char *arg
,
1312 enum processor_type
*type
,
1313 enum processor_flags
*flags
)
1317 const char *const name
; /* processor name or nickname. */
1318 const enum processor_type processor
;
1319 const enum processor_flags flags
;
1321 const processor_alias_table
[] =
1323 {"g5", PROCESSOR_9672_G5
, PF_IEEE_FLOAT
},
1324 {"g6", PROCESSOR_9672_G6
, PF_IEEE_FLOAT
},
1325 {"z900", PROCESSOR_2064_Z900
, PF_IEEE_FLOAT
| PF_ZARCH
},
1326 {"z990", PROCESSOR_2084_Z990
, PF_IEEE_FLOAT
| PF_ZARCH
1327 | PF_LONG_DISPLACEMENT
},
1328 {"z9-109", PROCESSOR_2094_Z9_109
, PF_IEEE_FLOAT
| PF_ZARCH
1329 | PF_LONG_DISPLACEMENT
| PF_EXTIMM
},
1333 for (i
= 0; i
< ARRAY_SIZE (processor_alias_table
); i
++)
1334 if (strcmp (arg
, processor_alias_table
[i
].name
) == 0)
1336 *type
= processor_alias_table
[i
].processor
;
1337 *flags
= processor_alias_table
[i
].flags
;
1343 /* Implement TARGET_HANDLE_OPTION. */
1346 s390_handle_option (size_t code
, const char *arg
, int value ATTRIBUTE_UNUSED
)
1351 return s390_handle_arch_option (arg
, &s390_arch
, &s390_arch_flags
);
1353 case OPT_mstack_guard_
:
1354 if (sscanf (arg
, HOST_WIDE_INT_PRINT_DEC
, &s390_stack_guard
) != 1)
1356 if (exact_log2 (s390_stack_guard
) == -1)
1357 error ("stack guard value must be an exact power of 2");
1360 case OPT_mstack_size_
:
1361 if (sscanf (arg
, HOST_WIDE_INT_PRINT_DEC
, &s390_stack_size
) != 1)
1363 if (exact_log2 (s390_stack_size
) == -1)
1364 error ("stack size must be an exact power of 2");
1368 return s390_handle_arch_option (arg
, &s390_tune
, &s390_tune_flags
);
1370 case OPT_mwarn_framesize_
:
1371 return sscanf (arg
, HOST_WIDE_INT_PRINT_DEC
, &s390_warn_framesize
) == 1;
1379 override_options (void)
1381 /* Set up function hooks. */
1382 init_machine_status
= s390_init_machine_status
;
1384 /* Architecture mode defaults according to ABI. */
1385 if (!(target_flags_explicit
& MASK_ZARCH
))
1388 target_flags
|= MASK_ZARCH
;
1390 target_flags
&= ~MASK_ZARCH
;
1393 /* Determine processor architectural level. */
1394 if (!s390_arch_string
)
1396 s390_arch_string
= TARGET_ZARCH
? "z900" : "g5";
1397 s390_handle_arch_option (s390_arch_string
, &s390_arch
, &s390_arch_flags
);
1400 /* Determine processor to tune for. */
1401 if (s390_tune
== PROCESSOR_max
)
1403 s390_tune
= s390_arch
;
1404 s390_tune_flags
= s390_arch_flags
;
1407 /* Sanity checks. */
1408 if (TARGET_ZARCH
&& !(s390_arch_flags
& PF_ZARCH
))
1409 error ("z/Architecture mode not supported on %s", s390_arch_string
);
1410 if (TARGET_64BIT
&& !TARGET_ZARCH
)
1411 error ("64-bit ABI not supported in ESA/390 mode");
1413 /* Set processor cost function. */
1414 if (s390_tune
== PROCESSOR_2094_Z9_109
)
1415 s390_cost
= &z9_109_cost
;
1416 else if (s390_tune
== PROCESSOR_2084_Z990
)
1417 s390_cost
= &z990_cost
;
1419 s390_cost
= &z900_cost
;
1421 if (TARGET_BACKCHAIN
&& TARGET_PACKED_STACK
&& TARGET_HARD_FLOAT
)
1422 error ("-mbackchain -mpacked-stack -mhard-float are not supported "
1425 if (s390_stack_size
)
1427 if (!s390_stack_guard
)
1428 error ("-mstack-size implies use of -mstack-guard");
1429 else if (s390_stack_guard
>= s390_stack_size
)
1430 error ("stack size must be greater than the stack guard value");
1431 else if (s390_stack_size
> 1 << 16)
1432 error ("stack size must not be greater than 64k");
1434 else if (s390_stack_guard
)
1435 error ("-mstack-guard implies use of -mstack-size");
1438 /* Map for smallest class containing reg regno. */
1440 const enum reg_class regclass_map
[FIRST_PSEUDO_REGISTER
] =
1441 { GENERAL_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1442 ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1443 ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1444 ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
1445 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1446 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1447 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1448 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
1449 ADDR_REGS
, CC_REGS
, ADDR_REGS
, ADDR_REGS
,
1450 ACCESS_REGS
, ACCESS_REGS
1453 /* Return attribute type of insn. */
1455 static enum attr_type
1456 s390_safe_attr_type (rtx insn
)
1458 if (recog_memoized (insn
) >= 0)
1459 return get_attr_type (insn
);
1464 /* Return true if DISP is a valid short displacement. */
1467 s390_short_displacement (rtx disp
)
1469 /* No displacement is OK. */
1473 /* Integer displacement in range. */
1474 if (GET_CODE (disp
) == CONST_INT
)
1475 return INTVAL (disp
) >= 0 && INTVAL (disp
) < 4096;
1477 /* GOT offset is not OK, the GOT can be large. */
1478 if (GET_CODE (disp
) == CONST
1479 && GET_CODE (XEXP (disp
, 0)) == UNSPEC
1480 && (XINT (XEXP (disp
, 0), 1) == UNSPEC_GOT
1481 || XINT (XEXP (disp
, 0), 1) == UNSPEC_GOTNTPOFF
))
1484 /* All other symbolic constants are literal pool references,
1485 which are OK as the literal pool must be small. */
1486 if (GET_CODE (disp
) == CONST
)
1492 /* Decompose a RTL expression ADDR for a memory address into
1493 its components, returned in OUT.
1495 Returns false if ADDR is not a valid memory address, true
1496 otherwise. If OUT is NULL, don't return the components,
1497 but check for validity only.
1499 Note: Only addresses in canonical form are recognized.
1500 LEGITIMIZE_ADDRESS should convert non-canonical forms to the
1501 canonical form so that they will be recognized. */
1504 s390_decompose_address (rtx addr
, struct s390_address
*out
)
1506 HOST_WIDE_INT offset
= 0;
1507 rtx base
= NULL_RTX
;
1508 rtx indx
= NULL_RTX
;
1509 rtx disp
= NULL_RTX
;
1511 bool pointer
= false;
1512 bool base_ptr
= false;
1513 bool indx_ptr
= false;
1514 bool literal_pool
= false;
1516 /* We may need to substitute the literal pool base register into the address
1517 below. However, at this point we do not know which register is going to
1518 be used as base, so we substitute the arg pointer register. This is going
1519 to be treated as holding a pointer below -- it shouldn't be used for any
1521 rtx fake_pool_base
= gen_rtx_REG (Pmode
, ARG_POINTER_REGNUM
);
1523 /* Decompose address into base + index + displacement. */
1525 if (GET_CODE (addr
) == REG
|| GET_CODE (addr
) == UNSPEC
)
1528 else if (GET_CODE (addr
) == PLUS
)
1530 rtx op0
= XEXP (addr
, 0);
1531 rtx op1
= XEXP (addr
, 1);
1532 enum rtx_code code0
= GET_CODE (op0
);
1533 enum rtx_code code1
= GET_CODE (op1
);
1535 if (code0
== REG
|| code0
== UNSPEC
)
1537 if (code1
== REG
|| code1
== UNSPEC
)
1539 indx
= op0
; /* index + base */
1545 base
= op0
; /* base + displacement */
1550 else if (code0
== PLUS
)
1552 indx
= XEXP (op0
, 0); /* index + base + disp */
1553 base
= XEXP (op0
, 1);
1564 disp
= addr
; /* displacement */
1566 /* Extract integer part of displacement. */
1570 if (GET_CODE (disp
) == CONST_INT
)
1572 offset
= INTVAL (disp
);
1575 else if (GET_CODE (disp
) == CONST
1576 && GET_CODE (XEXP (disp
, 0)) == PLUS
1577 && GET_CODE (XEXP (XEXP (disp
, 0), 1)) == CONST_INT
)
1579 offset
= INTVAL (XEXP (XEXP (disp
, 0), 1));
1580 disp
= XEXP (XEXP (disp
, 0), 0);
1584 /* Strip off CONST here to avoid special case tests later. */
1585 if (disp
&& GET_CODE (disp
) == CONST
)
1586 disp
= XEXP (disp
, 0);
1588 /* We can convert literal pool addresses to
1589 displacements by basing them off the base register. */
1590 if (disp
&& GET_CODE (disp
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (disp
))
1592 /* Either base or index must be free to hold the base register. */
1594 base
= fake_pool_base
, literal_pool
= true;
1596 indx
= fake_pool_base
, literal_pool
= true;
1600 /* Mark up the displacement. */
1601 disp
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, disp
),
1602 UNSPEC_LTREL_OFFSET
);
1605 /* Validate base register. */
1608 if (GET_CODE (base
) == UNSPEC
)
1609 switch (XINT (base
, 1))
1613 disp
= gen_rtx_UNSPEC (Pmode
,
1614 gen_rtvec (1, XVECEXP (base
, 0, 0)),
1615 UNSPEC_LTREL_OFFSET
);
1619 base
= XVECEXP (base
, 0, 1);
1622 case UNSPEC_LTREL_BASE
:
1623 if (XVECLEN (base
, 0) == 1)
1624 base
= fake_pool_base
, literal_pool
= true;
1626 base
= XVECEXP (base
, 0, 1);
1633 if (GET_CODE (base
) != REG
|| GET_MODE (base
) != Pmode
)
1636 if (REGNO (base
) == STACK_POINTER_REGNUM
1637 || REGNO (base
) == FRAME_POINTER_REGNUM
1638 || ((reload_completed
|| reload_in_progress
)
1639 && frame_pointer_needed
1640 && REGNO (base
) == HARD_FRAME_POINTER_REGNUM
)
1641 || REGNO (base
) == ARG_POINTER_REGNUM
1643 && REGNO (base
) == PIC_OFFSET_TABLE_REGNUM
))
1644 pointer
= base_ptr
= true;
1646 if ((reload_completed
|| reload_in_progress
)
1647 && base
== cfun
->machine
->base_reg
)
1648 pointer
= base_ptr
= literal_pool
= true;
1651 /* Validate index register. */
1654 if (GET_CODE (indx
) == UNSPEC
)
1655 switch (XINT (indx
, 1))
1659 disp
= gen_rtx_UNSPEC (Pmode
,
1660 gen_rtvec (1, XVECEXP (indx
, 0, 0)),
1661 UNSPEC_LTREL_OFFSET
);
1665 indx
= XVECEXP (indx
, 0, 1);
1668 case UNSPEC_LTREL_BASE
:
1669 if (XVECLEN (indx
, 0) == 1)
1670 indx
= fake_pool_base
, literal_pool
= true;
1672 indx
= XVECEXP (indx
, 0, 1);
1679 if (GET_CODE (indx
) != REG
|| GET_MODE (indx
) != Pmode
)
1682 if (REGNO (indx
) == STACK_POINTER_REGNUM
1683 || REGNO (indx
) == FRAME_POINTER_REGNUM
1684 || ((reload_completed
|| reload_in_progress
)
1685 && frame_pointer_needed
1686 && REGNO (indx
) == HARD_FRAME_POINTER_REGNUM
)
1687 || REGNO (indx
) == ARG_POINTER_REGNUM
1689 && REGNO (indx
) == PIC_OFFSET_TABLE_REGNUM
))
1690 pointer
= indx_ptr
= true;
1692 if ((reload_completed
|| reload_in_progress
)
1693 && indx
== cfun
->machine
->base_reg
)
1694 pointer
= indx_ptr
= literal_pool
= true;
1697 /* Prefer to use pointer as base, not index. */
1698 if (base
&& indx
&& !base_ptr
1699 && (indx_ptr
|| (!REG_POINTER (base
) && REG_POINTER (indx
))))
1706 /* Validate displacement. */
1709 /* If virtual registers are involved, the displacement will change later
1710 anyway as the virtual registers get eliminated. This could make a
1711 valid displacement invalid, but it is more likely to make an invalid
1712 displacement valid, because we sometimes access the register save area
1713 via negative offsets to one of those registers.
1714 Thus we don't check the displacement for validity here. If after
1715 elimination the displacement turns out to be invalid after all,
1716 this is fixed up by reload in any case. */
1717 if (base
!= arg_pointer_rtx
1718 && indx
!= arg_pointer_rtx
1719 && base
!= return_address_pointer_rtx
1720 && indx
!= return_address_pointer_rtx
1721 && base
!= frame_pointer_rtx
1722 && indx
!= frame_pointer_rtx
1723 && base
!= virtual_stack_vars_rtx
1724 && indx
!= virtual_stack_vars_rtx
)
1725 if (!DISP_IN_RANGE (offset
))
1730 /* All the special cases are pointers. */
1733 /* In the small-PIC case, the linker converts @GOT
1734 and @GOTNTPOFF offsets to possible displacements. */
1735 if (GET_CODE (disp
) == UNSPEC
1736 && (XINT (disp
, 1) == UNSPEC_GOT
1737 || XINT (disp
, 1) == UNSPEC_GOTNTPOFF
)
1744 /* Accept chunkified literal pool symbol references. */
1745 else if (cfun
&& cfun
->machine
1746 && cfun
->machine
->decomposed_literal_pool_addresses_ok_p
1747 && GET_CODE (disp
) == MINUS
1748 && GET_CODE (XEXP (disp
, 0)) == LABEL_REF
1749 && GET_CODE (XEXP (disp
, 1)) == LABEL_REF
)
1754 /* Accept literal pool references. */
1755 else if (GET_CODE (disp
) == UNSPEC
1756 && XINT (disp
, 1) == UNSPEC_LTREL_OFFSET
)
1758 orig_disp
= gen_rtx_CONST (Pmode
, disp
);
1761 /* If we have an offset, make sure it does not
1762 exceed the size of the constant pool entry. */
1763 rtx sym
= XVECEXP (disp
, 0, 0);
1764 if (offset
>= GET_MODE_SIZE (get_pool_mode (sym
)))
1767 orig_disp
= plus_constant (orig_disp
, offset
);
1782 out
->disp
= orig_disp
;
1783 out
->pointer
= pointer
;
1784 out
->literal_pool
= literal_pool
;
1790 /* Decompose a RTL expression OP for a shift count into its components,
1791 and return the base register in BASE and the offset in OFFSET.
1793 Return true if OP is a valid shift count, false if not. */
1796 s390_decompose_shift_count (rtx op
, rtx
*base
, HOST_WIDE_INT
*offset
)
1798 HOST_WIDE_INT off
= 0;
1800 /* We can have an integer constant, an address register,
1801 or a sum of the two. */
1802 if (GET_CODE (op
) == CONST_INT
)
1807 if (op
&& GET_CODE (op
) == PLUS
&& GET_CODE (XEXP (op
, 1)) == CONST_INT
)
1809 off
= INTVAL (XEXP (op
, 1));
1812 while (op
&& GET_CODE (op
) == SUBREG
)
1813 op
= SUBREG_REG (op
);
1815 if (op
&& GET_CODE (op
) != REG
)
1827 /* Return true if CODE is a valid address without index. */
1830 s390_legitimate_address_without_index_p (rtx op
)
1832 struct s390_address addr
;
1834 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
1842 /* Return 1 if OP is a valid operand for a C constraint, 0 else. */
1845 s390_extra_constraint_str (rtx op
, int c
, const char * str
)
1847 struct s390_address addr
;
1849 gcc_assert (c
== str
[0]);
1851 /* Check for offsettable variants of memory constraints. */
1854 /* Only accept non-volatile MEMs. */
1855 if (!MEM_P (op
) || MEM_VOLATILE_P (op
))
1858 if ((reload_completed
|| reload_in_progress
)
1859 ? !offsettable_memref_p (op
)
1860 : !offsettable_nonstrict_memref_p (op
))
1866 /* Check for non-literal-pool variants of memory constraints. */
1869 if (GET_CODE (op
) != MEM
)
1871 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
1873 if (addr
.literal_pool
)
1882 if (GET_CODE (op
) != MEM
)
1884 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
1889 if (TARGET_LONG_DISPLACEMENT
)
1891 if (!s390_short_displacement (addr
.disp
))
1897 if (GET_CODE (op
) != MEM
)
1900 if (TARGET_LONG_DISPLACEMENT
)
1902 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
1904 if (!s390_short_displacement (addr
.disp
))
1910 if (!TARGET_LONG_DISPLACEMENT
)
1912 if (GET_CODE (op
) != MEM
)
1914 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
1918 if (s390_short_displacement (addr
.disp
))
1923 if (!TARGET_LONG_DISPLACEMENT
)
1925 if (GET_CODE (op
) != MEM
)
1927 /* Any invalid address here will be fixed up by reload,
1928 so accept it for the most generic constraint. */
1929 if (s390_decompose_address (XEXP (op
, 0), &addr
)
1930 && s390_short_displacement (addr
.disp
))
1935 if (TARGET_LONG_DISPLACEMENT
)
1937 if (!s390_decompose_address (op
, &addr
))
1939 if (!s390_short_displacement (addr
.disp
))
1945 if (!TARGET_LONG_DISPLACEMENT
)
1947 /* Any invalid address here will be fixed up by reload,
1948 so accept it for the most generic constraint. */
1949 if (s390_decompose_address (op
, &addr
)
1950 && s390_short_displacement (addr
.disp
))
1955 /* Simply check for the basic form of a shift count. Reload will
1956 take care of making sure we have a proper base register. */
1957 if (!s390_decompose_shift_count (op
, NULL
, NULL
))
1968 /* Return true if VALUE matches the constraint STR. */
1971 s390_const_double_ok_for_constraint_p (rtx value
,
1975 gcc_assert (c
== str
[0]);
1980 /* The floating point zero constant. */
1981 return (GET_MODE_CLASS (GET_MODE (value
)) == MODE_FLOAT
1982 && value
== CONST0_RTX (GET_MODE (value
)));
1989 /* Return true if VALUE matches the constraint STR. */
1992 s390_const_ok_for_constraint_p (HOST_WIDE_INT value
,
1996 enum machine_mode mode
, part_mode
;
1998 int part
, part_goal
;
2000 gcc_assert (c
== str
[0]);
2005 return (unsigned int)value
< 256;
2008 return (unsigned int)value
< 4096;
2011 return value
>= -32768 && value
< 32768;
2014 return (TARGET_LONG_DISPLACEMENT
?
2015 (value
>= -524288 && value
<= 524287)
2016 : (value
>= 0 && value
<= 4095));
2018 return value
== 2147483647;
2024 part_goal
= str
[1] - '0';
2028 case 'Q': part_mode
= QImode
; break;
2029 case 'H': part_mode
= HImode
; break;
2030 case 'S': part_mode
= SImode
; break;
2036 case 'H': mode
= HImode
; break;
2037 case 'S': mode
= SImode
; break;
2038 case 'D': mode
= DImode
; break;
2044 case '0': def
= 0; break;
2045 case 'F': def
= -1; break;
2049 if (GET_MODE_SIZE (mode
) <= GET_MODE_SIZE (part_mode
))
2052 part
= s390_single_part (GEN_INT (value
), mode
, part_mode
, def
);
2055 if (part_goal
!= -1 && part_goal
!= part
)
2067 return trunc_int_for_mode (value
, SImode
) == value
;
2071 || s390_single_part (GEN_INT (value
), DImode
, SImode
, 0) == 1;
2076 || s390_single_part (GEN_INT (value
), DImode
, SImode
, -1) == 1)
2077 && value
!= -((HOST_WIDE_INT
)1 << 32);
2085 return legitimate_reload_constant_p (GEN_INT (value
));
2094 /* Compute a (partial) cost for rtx X. Return true if the complete
2095 cost has been computed, and false if subexpressions should be
2096 scanned. In either case, *TOTAL contains the cost result.
2097 CODE contains GET_CODE (x), OUTER_CODE contains the code
2098 of the superexpression of x. */
2101 s390_rtx_costs (rtx x
, int code
, int outer_code
, int *total
)
2124 *total
= COSTS_N_INSNS (1);
2129 /* Check for multiply and add. */
2130 if ((GET_MODE (x
) == DFmode
|| GET_MODE (x
) == SFmode
)
2131 && GET_CODE (XEXP (x
, 0)) == MULT
2132 && TARGET_HARD_FLOAT
&& TARGET_IEEE_FLOAT
&& TARGET_FUSED_MADD
)
2134 /* This is the multiply and add case. */
2135 if (GET_MODE (x
) == DFmode
)
2136 *total
= s390_cost
->madbr
;
2138 *total
= s390_cost
->maebr
;
2139 *total
+= rtx_cost (XEXP (XEXP (x
, 0), 0), MULT
)
2140 + rtx_cost (XEXP (XEXP (x
, 0), 1), MULT
)
2141 + rtx_cost (XEXP (x
, 1), code
);
2142 return true; /* Do not do an additional recursive descent. */
2144 *total
= COSTS_N_INSNS (1);
2148 switch (GET_MODE (x
))
2152 rtx left
= XEXP (x
, 0);
2153 rtx right
= XEXP (x
, 1);
2154 if (GET_CODE (right
) == CONST_INT
2155 && CONST_OK_FOR_K (INTVAL (right
)))
2156 *total
= s390_cost
->mhi
;
2157 else if (GET_CODE (left
) == SIGN_EXTEND
)
2158 *total
= s390_cost
->mh
;
2160 *total
= s390_cost
->ms
; /* msr, ms, msy */
2165 rtx left
= XEXP (x
, 0);
2166 rtx right
= XEXP (x
, 1);
2169 if (GET_CODE (right
) == CONST_INT
2170 && CONST_OK_FOR_K (INTVAL (right
)))
2171 *total
= s390_cost
->mghi
;
2172 else if (GET_CODE (left
) == SIGN_EXTEND
)
2173 *total
= s390_cost
->msgf
;
2175 *total
= s390_cost
->msg
; /* msgr, msg */
2177 else /* TARGET_31BIT */
2179 if (GET_CODE (left
) == SIGN_EXTEND
2180 && GET_CODE (right
) == SIGN_EXTEND
)
2181 /* mulsidi case: mr, m */
2182 *total
= s390_cost
->m
;
2183 else if (GET_CODE (left
) == ZERO_EXTEND
2184 && GET_CODE (right
) == ZERO_EXTEND
2185 && TARGET_CPU_ZARCH
)
2186 /* umulsidi case: ml, mlr */
2187 *total
= s390_cost
->ml
;
2189 /* Complex calculation is required. */
2190 *total
= COSTS_N_INSNS (40);
2196 *total
= s390_cost
->mult_df
;
2199 *total
= s390_cost
->mxbr
;
2208 if (GET_MODE (x
) == TImode
) /* 128 bit division */
2209 *total
= s390_cost
->dlgr
;
2210 else if (GET_MODE (x
) == DImode
)
2212 rtx right
= XEXP (x
, 1);
2213 if (GET_CODE (right
) == ZERO_EXTEND
) /* 64 by 32 bit division */
2214 *total
= s390_cost
->dlr
;
2215 else /* 64 by 64 bit division */
2216 *total
= s390_cost
->dlgr
;
2218 else if (GET_MODE (x
) == SImode
) /* 32 bit division */
2219 *total
= s390_cost
->dlr
;
2224 if (GET_MODE (x
) == DImode
)
2226 rtx right
= XEXP (x
, 1);
2227 if (GET_CODE (right
) == ZERO_EXTEND
) /* 64 by 32 bit division */
2229 *total
= s390_cost
->dsgfr
;
2231 *total
= s390_cost
->dr
;
2232 else /* 64 by 64 bit division */
2233 *total
= s390_cost
->dsgr
;
2235 else if (GET_MODE (x
) == SImode
) /* 32 bit division */
2236 *total
= s390_cost
->dlr
;
2237 else if (GET_MODE (x
) == SFmode
)
2239 if (TARGET_IEEE_FLOAT
)
2240 *total
= s390_cost
->debr
;
2241 else /* TARGET_IBM_FLOAT */
2242 *total
= s390_cost
->der
;
2244 else if (GET_MODE (x
) == DFmode
)
2246 if (TARGET_IEEE_FLOAT
)
2247 *total
= s390_cost
->ddbr
;
2248 else /* TARGET_IBM_FLOAT */
2249 *total
= s390_cost
->ddr
;
2251 else if (GET_MODE (x
) == TFmode
)
2253 if (TARGET_IEEE_FLOAT
)
2254 *total
= s390_cost
->dxbr
;
2255 else /* TARGET_IBM_FLOAT */
2256 *total
= s390_cost
->dxr
;
2261 if (GET_MODE (x
) == SFmode
)
2262 *total
= s390_cost
->sqebr
;
2263 else if (GET_MODE (x
) == DFmode
)
2264 *total
= s390_cost
->sqdbr
;
2266 *total
= s390_cost
->sqxbr
;
2271 if (outer_code
== MULT
|| outer_code
== DIV
|| outer_code
== MOD
2272 || outer_code
== PLUS
|| outer_code
== MINUS
2273 || outer_code
== COMPARE
)
2278 *total
= COSTS_N_INSNS (1);
2279 if (GET_CODE (XEXP (x
, 0)) == AND
2280 && GET_CODE (XEXP (x
, 1)) == CONST_INT
2281 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
)
2283 rtx op0
= XEXP (XEXP (x
, 0), 0);
2284 rtx op1
= XEXP (XEXP (x
, 0), 1);
2285 rtx op2
= XEXP (x
, 1);
2287 if (memory_operand (op0
, GET_MODE (op0
))
2288 && s390_tm_ccmode (op1
, op2
, 0) != VOIDmode
)
2290 if (register_operand (op0
, GET_MODE (op0
))
2291 && s390_tm_ccmode (op1
, op2
, 1) != VOIDmode
)
2301 /* Return the cost of an address rtx ADDR. */
2304 s390_address_cost (rtx addr
)
2306 struct s390_address ad
;
2307 if (!s390_decompose_address (addr
, &ad
))
2310 return ad
.indx
? COSTS_N_INSNS (1) + 1 : COSTS_N_INSNS (1);
2313 /* If OP is a SYMBOL_REF of a thread-local symbol, return its TLS mode,
2314 otherwise return 0. */
2317 tls_symbolic_operand (rtx op
)
2319 if (GET_CODE (op
) != SYMBOL_REF
)
2321 return SYMBOL_REF_TLS_MODEL (op
);
2324 /* Split DImode access register reference REG (on 64-bit) into its constituent
2325 low and high parts, and store them into LO and HI. Note that gen_lowpart/
2326 gen_highpart cannot be used as they assume all registers are word-sized,
2327 while our access registers have only half that size. */
2330 s390_split_access_reg (rtx reg
, rtx
*lo
, rtx
*hi
)
2332 gcc_assert (TARGET_64BIT
);
2333 gcc_assert (ACCESS_REG_P (reg
));
2334 gcc_assert (GET_MODE (reg
) == DImode
);
2335 gcc_assert (!(REGNO (reg
) & 1));
2337 *lo
= gen_rtx_REG (SImode
, REGNO (reg
) + 1);
2338 *hi
= gen_rtx_REG (SImode
, REGNO (reg
));
2341 /* Return true if OP contains a symbol reference */
2344 symbolic_reference_mentioned_p (rtx op
)
2349 if (GET_CODE (op
) == SYMBOL_REF
|| GET_CODE (op
) == LABEL_REF
)
2352 fmt
= GET_RTX_FORMAT (GET_CODE (op
));
2353 for (i
= GET_RTX_LENGTH (GET_CODE (op
)) - 1; i
>= 0; i
--)
2359 for (j
= XVECLEN (op
, i
) - 1; j
>= 0; j
--)
2360 if (symbolic_reference_mentioned_p (XVECEXP (op
, i
, j
)))
2364 else if (fmt
[i
] == 'e' && symbolic_reference_mentioned_p (XEXP (op
, i
)))
2371 /* Return true if OP contains a reference to a thread-local symbol. */
2374 tls_symbolic_reference_mentioned_p (rtx op
)
2379 if (GET_CODE (op
) == SYMBOL_REF
)
2380 return tls_symbolic_operand (op
);
2382 fmt
= GET_RTX_FORMAT (GET_CODE (op
));
2383 for (i
= GET_RTX_LENGTH (GET_CODE (op
)) - 1; i
>= 0; i
--)
2389 for (j
= XVECLEN (op
, i
) - 1; j
>= 0; j
--)
2390 if (tls_symbolic_reference_mentioned_p (XVECEXP (op
, i
, j
)))
2394 else if (fmt
[i
] == 'e' && tls_symbolic_reference_mentioned_p (XEXP (op
, i
)))
2402 /* Return true if OP is a legitimate general operand when
2403 generating PIC code. It is given that flag_pic is on
2404 and that OP satisfies CONSTANT_P or is a CONST_DOUBLE. */
2407 legitimate_pic_operand_p (rtx op
)
2409 /* Accept all non-symbolic constants. */
2410 if (!SYMBOLIC_CONST (op
))
2413 /* Reject everything else; must be handled
2414 via emit_symbolic_move. */
2418 /* Returns true if the constant value OP is a legitimate general operand.
2419 It is given that OP satisfies CONSTANT_P or is a CONST_DOUBLE. */
2422 legitimate_constant_p (rtx op
)
2424 /* Accept all non-symbolic constants. */
2425 if (!SYMBOLIC_CONST (op
))
2428 /* Accept immediate LARL operands. */
2429 if (TARGET_CPU_ZARCH
&& larl_operand (op
, VOIDmode
))
2432 /* Thread-local symbols are never legal constants. This is
2433 so that emit_call knows that computing such addresses
2434 might require a function call. */
2435 if (TLS_SYMBOLIC_CONST (op
))
2438 /* In the PIC case, symbolic constants must *not* be
2439 forced into the literal pool. We accept them here,
2440 so that they will be handled by emit_symbolic_move. */
2444 /* All remaining non-PIC symbolic constants are
2445 forced into the literal pool. */
2449 /* Determine if it's legal to put X into the constant pool. This
2450 is not possible if X contains the address of a symbol that is
2451 not constant (TLS) or not known at final link time (PIC). */
2454 s390_cannot_force_const_mem (rtx x
)
2456 switch (GET_CODE (x
))
2460 /* Accept all non-symbolic constants. */
2464 /* Labels are OK iff we are non-PIC. */
2465 return flag_pic
!= 0;
2468 /* 'Naked' TLS symbol references are never OK,
2469 non-TLS symbols are OK iff we are non-PIC. */
2470 if (tls_symbolic_operand (x
))
2473 return flag_pic
!= 0;
2476 return s390_cannot_force_const_mem (XEXP (x
, 0));
2479 return s390_cannot_force_const_mem (XEXP (x
, 0))
2480 || s390_cannot_force_const_mem (XEXP (x
, 1));
2483 switch (XINT (x
, 1))
2485 /* Only lt-relative or GOT-relative UNSPECs are OK. */
2486 case UNSPEC_LTREL_OFFSET
:
2494 case UNSPEC_GOTNTPOFF
:
2495 case UNSPEC_INDNTPOFF
:
2498 /* If the literal pool shares the code section, be put
2499 execute template placeholders into the pool as well. */
2501 return TARGET_CPU_ZARCH
;
2513 /* Returns true if the constant value OP is a legitimate general
2514 operand during and after reload. The difference to
2515 legitimate_constant_p is that this function will not accept
2516 a constant that would need to be forced to the literal pool
2517 before it can be used as operand. */
2520 legitimate_reload_constant_p (rtx op
)
2522 /* Accept la(y) operands. */
2523 if (GET_CODE (op
) == CONST_INT
2524 && DISP_IN_RANGE (INTVAL (op
)))
2527 /* Accept l(g)hi/l(g)fi operands. */
2528 if (GET_CODE (op
) == CONST_INT
2529 && (CONST_OK_FOR_K (INTVAL (op
)) || CONST_OK_FOR_Os (INTVAL (op
))))
2532 /* Accept lliXX operands. */
2534 && GET_CODE (op
) == CONST_INT
2535 && trunc_int_for_mode (INTVAL (op
), word_mode
) == INTVAL (op
)
2536 && s390_single_part (op
, word_mode
, HImode
, 0) >= 0)
2540 && GET_CODE (op
) == CONST_INT
2541 && trunc_int_for_mode (INTVAL (op
), word_mode
) == INTVAL (op
)
2542 && s390_single_part (op
, word_mode
, SImode
, 0) >= 0)
2545 /* Accept larl operands. */
2546 if (TARGET_CPU_ZARCH
2547 && larl_operand (op
, VOIDmode
))
2550 /* Accept lzXX operands. */
2551 if (GET_CODE (op
) == CONST_DOUBLE
2552 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op
, 'G', "G"))
2555 /* Accept double-word operands that can be split. */
2556 if (GET_CODE (op
) == CONST_INT
2557 && trunc_int_for_mode (INTVAL (op
), word_mode
) != INTVAL (op
))
2559 enum machine_mode dword_mode
= word_mode
== SImode
? DImode
: TImode
;
2560 rtx hi
= operand_subword (op
, 0, 0, dword_mode
);
2561 rtx lo
= operand_subword (op
, 1, 0, dword_mode
);
2562 return legitimate_reload_constant_p (hi
)
2563 && legitimate_reload_constant_p (lo
);
2566 /* Everything else cannot be handled without reload. */
2570 /* Given an rtx OP being reloaded into a reg required to be in class CLASS,
2571 return the class of reg to actually use. */
2574 s390_preferred_reload_class (rtx op
, enum reg_class
class)
2576 switch (GET_CODE (op
))
2578 /* Constants we cannot reload must be forced into the
2583 if (legitimate_reload_constant_p (op
))
2588 /* If a symbolic constant or a PLUS is reloaded,
2589 it is most likely being used as an address, so
2590 prefer ADDR_REGS. If 'class' is not a superset
2591 of ADDR_REGS, e.g. FP_REGS, reject this reload. */
2596 if (reg_class_subset_p (ADDR_REGS
, class))
2608 /* Return the register class of a scratch register needed to
2609 load IN into a register of class CLASS in MODE.
2611 We need a temporary when loading a PLUS expression which
2612 is not a legitimate operand of the LOAD ADDRESS instruction. */
2615 s390_secondary_input_reload_class (enum reg_class
class,
2616 enum machine_mode mode
, rtx in
)
2618 if (s390_plus_operand (in
, mode
))
2621 if (reg_classes_intersect_p (FP_REGS
, class)
2623 && GET_CODE (in
) == MEM
2624 && GET_CODE (XEXP (in
, 0)) == PLUS
2625 && GET_CODE (XEXP (XEXP (in
, 0), 1)) == CONST_INT
2626 && !DISP_IN_RANGE (INTVAL (XEXP (XEXP (in
, 0), 1))
2627 + GET_MODE_SIZE (mode
) - 1))
2630 if (reg_classes_intersect_p (CC_REGS
, class))
2631 return GENERAL_REGS
;
2636 /* Return the register class of a scratch register needed to
2637 store a register of class CLASS in MODE into OUT:
2639 We need a temporary when storing a double-word to a
2640 non-offsettable memory address. */
2643 s390_secondary_output_reload_class (enum reg_class
class,
2644 enum machine_mode mode
, rtx out
)
2646 if ((TARGET_64BIT
? (mode
== TImode
|| mode
== TFmode
)
2647 : (mode
== DImode
|| mode
== DFmode
))
2648 && reg_classes_intersect_p (GENERAL_REGS
, class)
2649 && GET_CODE (out
) == MEM
2650 && GET_CODE (XEXP (out
, 0)) == PLUS
2651 && GET_CODE (XEXP (XEXP (out
, 0), 0)) == PLUS
2652 && GET_CODE (XEXP (XEXP (out
, 0), 1)) == CONST_INT
2653 && !DISP_IN_RANGE (INTVAL (XEXP (XEXP (out
, 0), 1))
2654 + GET_MODE_SIZE (mode
) - 1))
2657 if (reg_classes_intersect_p (FP_REGS
, class)
2659 && GET_CODE (out
) == MEM
2660 && GET_CODE (XEXP (out
, 0)) == PLUS
2661 && GET_CODE (XEXP (XEXP (out
, 0), 1)) == CONST_INT
2662 && !DISP_IN_RANGE (INTVAL (XEXP (XEXP (out
, 0), 1))
2663 + GET_MODE_SIZE (mode
) - 1))
2666 if (reg_classes_intersect_p (CC_REGS
, class))
2667 return GENERAL_REGS
;
2672 /* Generate code to load SRC, which is PLUS that is not a
2673 legitimate operand for the LA instruction, into TARGET.
2674 SCRATCH may be used as scratch register. */
2677 s390_expand_plus_operand (rtx target
, rtx src
,
2681 struct s390_address ad
;
2683 /* src must be a PLUS; get its two operands. */
2684 gcc_assert (GET_CODE (src
) == PLUS
);
2685 gcc_assert (GET_MODE (src
) == Pmode
);
2687 /* Check if any of the two operands is already scheduled
2688 for replacement by reload. This can happen e.g. when
2689 float registers occur in an address. */
2690 sum1
= find_replacement (&XEXP (src
, 0));
2691 sum2
= find_replacement (&XEXP (src
, 1));
2692 src
= gen_rtx_PLUS (Pmode
, sum1
, sum2
);
2694 /* If the address is already strictly valid, there's nothing to do. */
2695 if (!s390_decompose_address (src
, &ad
)
2696 || (ad
.base
&& !REG_OK_FOR_BASE_STRICT_P (ad
.base
))
2697 || (ad
.indx
&& !REG_OK_FOR_INDEX_STRICT_P (ad
.indx
)))
2699 /* Otherwise, one of the operands cannot be an address register;
2700 we reload its value into the scratch register. */
2701 if (true_regnum (sum1
) < 1 || true_regnum (sum1
) > 15)
2703 emit_move_insn (scratch
, sum1
);
2706 if (true_regnum (sum2
) < 1 || true_regnum (sum2
) > 15)
2708 emit_move_insn (scratch
, sum2
);
2712 /* According to the way these invalid addresses are generated
2713 in reload.c, it should never happen (at least on s390) that
2714 *neither* of the PLUS components, after find_replacements
2715 was applied, is an address register. */
2716 if (sum1
== scratch
&& sum2
== scratch
)
2722 src
= gen_rtx_PLUS (Pmode
, sum1
, sum2
);
2725 /* Emit the LOAD ADDRESS pattern. Note that reload of PLUS
2726 is only ever performed on addresses, so we can mark the
2727 sum as legitimate for LA in any case. */
2728 s390_load_address (target
, src
);
2732 /* Return true if ADDR is a valid memory address.
2733 STRICT specifies whether strict register checking applies. */
2736 legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED
,
2737 rtx addr
, int strict
)
2739 struct s390_address ad
;
2740 if (!s390_decompose_address (addr
, &ad
))
2745 if (ad
.base
&& !REG_OK_FOR_BASE_STRICT_P (ad
.base
))
2747 if (ad
.indx
&& !REG_OK_FOR_INDEX_STRICT_P (ad
.indx
))
2752 if (ad
.base
&& !REG_OK_FOR_BASE_NONSTRICT_P (ad
.base
))
2754 if (ad
.indx
&& !REG_OK_FOR_INDEX_NONSTRICT_P (ad
.indx
))
2761 /* Return true if OP is a valid operand for the LA instruction.
2762 In 31-bit, we need to prove that the result is used as an
2763 address, as LA performs only a 31-bit addition. */
2766 legitimate_la_operand_p (rtx op
)
2768 struct s390_address addr
;
2769 if (!s390_decompose_address (op
, &addr
))
2772 return (TARGET_64BIT
|| addr
.pointer
);
2775 /* Return true if it is valid *and* preferable to use LA to
2776 compute the sum of OP1 and OP2. */
2779 preferred_la_operand_p (rtx op1
, rtx op2
)
2781 struct s390_address addr
;
2783 if (op2
!= const0_rtx
)
2784 op1
= gen_rtx_PLUS (Pmode
, op1
, op2
);
2786 if (!s390_decompose_address (op1
, &addr
))
2788 if (addr
.base
&& !REG_OK_FOR_BASE_STRICT_P (addr
.base
))
2790 if (addr
.indx
&& !REG_OK_FOR_INDEX_STRICT_P (addr
.indx
))
2793 if (!TARGET_64BIT
&& !addr
.pointer
)
2799 if ((addr
.base
&& REG_P (addr
.base
) && REG_POINTER (addr
.base
))
2800 || (addr
.indx
&& REG_P (addr
.indx
) && REG_POINTER (addr
.indx
)))
2806 /* Emit a forced load-address operation to load SRC into DST.
2807 This will use the LOAD ADDRESS instruction even in situations
2808 where legitimate_la_operand_p (SRC) returns false. */
2811 s390_load_address (rtx dst
, rtx src
)
2814 emit_move_insn (dst
, src
);
2816 emit_insn (gen_force_la_31 (dst
, src
));
2819 /* Return a legitimate reference for ORIG (an address) using the
2820 register REG. If REG is 0, a new pseudo is generated.
2822 There are two types of references that must be handled:
2824 1. Global data references must load the address from the GOT, via
2825 the PIC reg. An insn is emitted to do this load, and the reg is
2828 2. Static data references, constant pool addresses, and code labels
2829 compute the address as an offset from the GOT, whose base is in
2830 the PIC reg. Static data objects have SYMBOL_FLAG_LOCAL set to
2831 differentiate them from global data objects. The returned
2832 address is the PIC reg + an unspec constant.
2834 GO_IF_LEGITIMATE_ADDRESS rejects symbolic references unless the PIC
2835 reg also appears in the address. */
2838 legitimize_pic_address (rtx orig
, rtx reg
)
2844 gcc_assert (!TLS_SYMBOLIC_CONST (addr
));
2846 if (GET_CODE (addr
) == LABEL_REF
2847 || (GET_CODE (addr
) == SYMBOL_REF
&& SYMBOL_REF_LOCAL_P (addr
)))
2849 /* This is a local symbol. */
2850 if (TARGET_CPU_ZARCH
&& larl_operand (addr
, VOIDmode
))
2852 /* Access local symbols PC-relative via LARL.
2853 This is the same as in the non-PIC case, so it is
2854 handled automatically ... */
2858 /* Access local symbols relative to the GOT. */
2860 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
2862 if (reload_in_progress
|| reload_completed
)
2863 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
2865 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTOFF
);
2866 addr
= gen_rtx_CONST (Pmode
, addr
);
2867 addr
= force_const_mem (Pmode
, addr
);
2868 emit_move_insn (temp
, addr
);
2870 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
2873 s390_load_address (reg
, new);
2878 else if (GET_CODE (addr
) == SYMBOL_REF
)
2881 reg
= gen_reg_rtx (Pmode
);
2885 /* Assume GOT offset < 4k. This is handled the same way
2886 in both 31- and 64-bit code (@GOT). */
2888 if (reload_in_progress
|| reload_completed
)
2889 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
2891 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOT
);
2892 new = gen_rtx_CONST (Pmode
, new);
2893 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, new);
2894 new = gen_const_mem (Pmode
, new);
2895 emit_move_insn (reg
, new);
2898 else if (TARGET_CPU_ZARCH
)
2900 /* If the GOT offset might be >= 4k, we determine the position
2901 of the GOT entry via a PC-relative LARL (@GOTENT). */
2903 rtx temp
= gen_reg_rtx (Pmode
);
2905 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTENT
);
2906 new = gen_rtx_CONST (Pmode
, new);
2907 emit_move_insn (temp
, new);
2909 new = gen_const_mem (Pmode
, temp
);
2910 emit_move_insn (reg
, new);
2915 /* If the GOT offset might be >= 4k, we have to load it
2916 from the literal pool (@GOT). */
2918 rtx temp
= gen_reg_rtx (Pmode
);
2920 if (reload_in_progress
|| reload_completed
)
2921 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
2923 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOT
);
2924 addr
= gen_rtx_CONST (Pmode
, addr
);
2925 addr
= force_const_mem (Pmode
, addr
);
2926 emit_move_insn (temp
, addr
);
2928 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
2929 new = gen_const_mem (Pmode
, new);
2930 emit_move_insn (reg
, new);
2936 if (GET_CODE (addr
) == CONST
)
2938 addr
= XEXP (addr
, 0);
2939 if (GET_CODE (addr
) == UNSPEC
)
2941 gcc_assert (XVECLEN (addr
, 0) == 1);
2942 switch (XINT (addr
, 1))
2944 /* If someone moved a GOT-relative UNSPEC
2945 out of the literal pool, force them back in. */
2948 new = force_const_mem (Pmode
, orig
);
2951 /* @GOT is OK as is if small. */
2954 new = force_const_mem (Pmode
, orig
);
2957 /* @GOTENT is OK as is. */
2961 /* @PLT is OK as is on 64-bit, must be converted to
2962 GOT-relative @PLTOFF on 31-bit. */
2964 if (!TARGET_CPU_ZARCH
)
2966 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
2968 if (reload_in_progress
|| reload_completed
)
2969 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
2971 addr
= XVECEXP (addr
, 0, 0);
2972 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
),
2974 addr
= gen_rtx_CONST (Pmode
, addr
);
2975 addr
= force_const_mem (Pmode
, addr
);
2976 emit_move_insn (temp
, addr
);
2978 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
2981 s390_load_address (reg
, new);
2987 /* Everything else cannot happen. */
2993 gcc_assert (GET_CODE (addr
) == PLUS
);
2995 if (GET_CODE (addr
) == PLUS
)
2997 rtx op0
= XEXP (addr
, 0), op1
= XEXP (addr
, 1);
2999 gcc_assert (!TLS_SYMBOLIC_CONST (op0
));
3000 gcc_assert (!TLS_SYMBOLIC_CONST (op1
));
3002 /* Check first to see if this is a constant offset
3003 from a local symbol reference. */
3004 if ((GET_CODE (op0
) == LABEL_REF
3005 || (GET_CODE (op0
) == SYMBOL_REF
&& SYMBOL_REF_LOCAL_P (op0
)))
3006 && GET_CODE (op1
) == CONST_INT
)
3008 if (TARGET_CPU_ZARCH
3009 && larl_operand (op0
, VOIDmode
)
3010 && INTVAL (op1
) < (HOST_WIDE_INT
)1 << 31
3011 && INTVAL (op1
) >= -((HOST_WIDE_INT
)1 << 31))
3013 if (INTVAL (op1
) & 1)
3015 /* LARL can't handle odd offsets, so emit a
3016 pair of LARL and LA. */
3017 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3019 if (!DISP_IN_RANGE (INTVAL (op1
)))
3021 HOST_WIDE_INT even
= INTVAL (op1
) - 1;
3022 op0
= gen_rtx_PLUS (Pmode
, op0
, GEN_INT (even
));
3023 op0
= gen_rtx_CONST (Pmode
, op0
);
3027 emit_move_insn (temp
, op0
);
3028 new = gen_rtx_PLUS (Pmode
, temp
, op1
);
3032 s390_load_address (reg
, new);
3038 /* If the offset is even, we can just use LARL.
3039 This will happen automatically. */
3044 /* Access local symbols relative to the GOT. */
3046 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
3048 if (reload_in_progress
|| reload_completed
)
3049 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
3051 addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op0
),
3053 addr
= gen_rtx_PLUS (Pmode
, addr
, op1
);
3054 addr
= gen_rtx_CONST (Pmode
, addr
);
3055 addr
= force_const_mem (Pmode
, addr
);
3056 emit_move_insn (temp
, addr
);
3058 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3061 s390_load_address (reg
, new);
3067 /* Now, check whether it is a GOT relative symbol plus offset
3068 that was pulled out of the literal pool. Force it back in. */
3070 else if (GET_CODE (op0
) == UNSPEC
3071 && GET_CODE (op1
) == CONST_INT
3072 && XINT (op0
, 1) == UNSPEC_GOTOFF
)
3074 gcc_assert (XVECLEN (op0
, 0) == 1);
3076 new = force_const_mem (Pmode
, orig
);
3079 /* Otherwise, compute the sum. */
3082 base
= legitimize_pic_address (XEXP (addr
, 0), reg
);
3083 new = legitimize_pic_address (XEXP (addr
, 1),
3084 base
== reg
? NULL_RTX
: reg
);
3085 if (GET_CODE (new) == CONST_INT
)
3086 new = plus_constant (base
, INTVAL (new));
3089 if (GET_CODE (new) == PLUS
&& CONSTANT_P (XEXP (new, 1)))
3091 base
= gen_rtx_PLUS (Pmode
, base
, XEXP (new, 0));
3092 new = XEXP (new, 1);
3094 new = gen_rtx_PLUS (Pmode
, base
, new);
3097 if (GET_CODE (new) == CONST
)
3098 new = XEXP (new, 0);
3099 new = force_operand (new, 0);
3106 /* Load the thread pointer into a register. */
3109 s390_get_thread_pointer (void)
3111 rtx tp
= gen_reg_rtx (Pmode
);
3113 emit_move_insn (tp
, gen_rtx_REG (Pmode
, TP_REGNUM
));
3114 mark_reg_pointer (tp
, BITS_PER_WORD
);
3119 /* Emit a tls call insn. The call target is the SYMBOL_REF stored
3120 in s390_tls_symbol which always refers to __tls_get_offset.
3121 The returned offset is written to RESULT_REG and an USE rtx is
3122 generated for TLS_CALL. */
3124 static GTY(()) rtx s390_tls_symbol
;
3127 s390_emit_tls_call_insn (rtx result_reg
, rtx tls_call
)
3131 gcc_assert (flag_pic
);
3133 if (!s390_tls_symbol
)
3134 s390_tls_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "__tls_get_offset");
3136 insn
= s390_emit_call (s390_tls_symbol
, tls_call
, result_reg
,
3137 gen_rtx_REG (Pmode
, RETURN_REGNUM
));
3139 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), result_reg
);
3140 CONST_OR_PURE_CALL_P (insn
) = 1;
3143 /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
3144 this (thread-local) address. REG may be used as temporary. */
3147 legitimize_tls_address (rtx addr
, rtx reg
)
3149 rtx
new, tls_call
, temp
, base
, r2
, insn
;
3151 if (GET_CODE (addr
) == SYMBOL_REF
)
3152 switch (tls_symbolic_operand (addr
))
3154 case TLS_MODEL_GLOBAL_DYNAMIC
:
3156 r2
= gen_rtx_REG (Pmode
, 2);
3157 tls_call
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_TLSGD
);
3158 new = gen_rtx_CONST (Pmode
, tls_call
);
3159 new = force_const_mem (Pmode
, new);
3160 emit_move_insn (r2
, new);
3161 s390_emit_tls_call_insn (r2
, tls_call
);
3162 insn
= get_insns ();
3165 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_NTPOFF
);
3166 temp
= gen_reg_rtx (Pmode
);
3167 emit_libcall_block (insn
, temp
, r2
, new);
3169 new = gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3172 s390_load_address (reg
, new);
3177 case TLS_MODEL_LOCAL_DYNAMIC
:
3179 r2
= gen_rtx_REG (Pmode
, 2);
3180 tls_call
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, const0_rtx
), UNSPEC_TLSLDM
);
3181 new = gen_rtx_CONST (Pmode
, tls_call
);
3182 new = force_const_mem (Pmode
, new);
3183 emit_move_insn (r2
, new);
3184 s390_emit_tls_call_insn (r2
, tls_call
);
3185 insn
= get_insns ();
3188 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, const0_rtx
), UNSPEC_TLSLDM_NTPOFF
);
3189 temp
= gen_reg_rtx (Pmode
);
3190 emit_libcall_block (insn
, temp
, r2
, new);
3192 new = gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3193 base
= gen_reg_rtx (Pmode
);
3194 s390_load_address (base
, new);
3196 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_DTPOFF
);
3197 new = gen_rtx_CONST (Pmode
, new);
3198 new = force_const_mem (Pmode
, new);
3199 temp
= gen_reg_rtx (Pmode
);
3200 emit_move_insn (temp
, new);
3202 new = gen_rtx_PLUS (Pmode
, base
, temp
);
3205 s390_load_address (reg
, new);
3210 case TLS_MODEL_INITIAL_EXEC
:
3213 /* Assume GOT offset < 4k. This is handled the same way
3214 in both 31- and 64-bit code. */
3216 if (reload_in_progress
|| reload_completed
)
3217 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
3219 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTNTPOFF
);
3220 new = gen_rtx_CONST (Pmode
, new);
3221 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, new);
3222 new = gen_const_mem (Pmode
, new);
3223 temp
= gen_reg_rtx (Pmode
);
3224 emit_move_insn (temp
, new);
3226 else if (TARGET_CPU_ZARCH
)
3228 /* If the GOT offset might be >= 4k, we determine the position
3229 of the GOT entry via a PC-relative LARL. */
3231 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_INDNTPOFF
);
3232 new = gen_rtx_CONST (Pmode
, new);
3233 temp
= gen_reg_rtx (Pmode
);
3234 emit_move_insn (temp
, new);
3236 new = gen_const_mem (Pmode
, temp
);
3237 temp
= gen_reg_rtx (Pmode
);
3238 emit_move_insn (temp
, new);
3242 /* If the GOT offset might be >= 4k, we have to load it
3243 from the literal pool. */
3245 if (reload_in_progress
|| reload_completed
)
3246 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
3248 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTNTPOFF
);
3249 new = gen_rtx_CONST (Pmode
, new);
3250 new = force_const_mem (Pmode
, new);
3251 temp
= gen_reg_rtx (Pmode
);
3252 emit_move_insn (temp
, new);
3254 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
3255 new = gen_const_mem (Pmode
, new);
3257 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, new, addr
), UNSPEC_TLS_LOAD
);
3258 temp
= gen_reg_rtx (Pmode
);
3259 emit_insn (gen_rtx_SET (Pmode
, temp
, new));
3263 /* In position-dependent code, load the absolute address of
3264 the GOT entry from the literal pool. */
3266 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_INDNTPOFF
);
3267 new = gen_rtx_CONST (Pmode
, new);
3268 new = force_const_mem (Pmode
, new);
3269 temp
= gen_reg_rtx (Pmode
);
3270 emit_move_insn (temp
, new);
3273 new = gen_const_mem (Pmode
, new);
3274 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, new, addr
), UNSPEC_TLS_LOAD
);
3275 temp
= gen_reg_rtx (Pmode
);
3276 emit_insn (gen_rtx_SET (Pmode
, temp
, new));
3279 new = gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3282 s390_load_address (reg
, new);
3287 case TLS_MODEL_LOCAL_EXEC
:
3288 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_NTPOFF
);
3289 new = gen_rtx_CONST (Pmode
, new);
3290 new = force_const_mem (Pmode
, new);
3291 temp
= gen_reg_rtx (Pmode
);
3292 emit_move_insn (temp
, new);
3294 new = gen_rtx_PLUS (Pmode
, s390_get_thread_pointer (), temp
);
3297 s390_load_address (reg
, new);
3306 else if (GET_CODE (addr
) == CONST
&& GET_CODE (XEXP (addr
, 0)) == UNSPEC
)
3308 switch (XINT (XEXP (addr
, 0), 1))
3310 case UNSPEC_INDNTPOFF
:
3311 gcc_assert (TARGET_CPU_ZARCH
);
3320 else if (GET_CODE (addr
) == CONST
&& GET_CODE (XEXP (addr
, 0)) == PLUS
3321 && GET_CODE (XEXP (XEXP (addr
, 0), 1)) == CONST_INT
)
3323 new = XEXP (XEXP (addr
, 0), 0);
3324 if (GET_CODE (new) != SYMBOL_REF
)
3325 new = gen_rtx_CONST (Pmode
, new);
3327 new = legitimize_tls_address (new, reg
);
3328 new = plus_constant (new, INTVAL (XEXP (XEXP (addr
, 0), 1)));
3329 new = force_operand (new, 0);
3333 gcc_unreachable (); /* for now ... */
3338 /* Emit insns to move operands[1] into operands[0]. */
3341 emit_symbolic_move (rtx
*operands
)
3343 rtx temp
= no_new_pseudos
? operands
[0] : gen_reg_rtx (Pmode
);
3345 if (GET_CODE (operands
[0]) == MEM
)
3346 operands
[1] = force_reg (Pmode
, operands
[1]);
3347 else if (TLS_SYMBOLIC_CONST (operands
[1]))
3348 operands
[1] = legitimize_tls_address (operands
[1], temp
);
3350 operands
[1] = legitimize_pic_address (operands
[1], temp
);
3353 /* Try machine-dependent ways of modifying an illegitimate address X
3354 to be legitimate. If we find one, return the new, valid address.
3356 OLDX is the address as it was before break_out_memory_refs was called.
3357 In some cases it is useful to look at this to decide what needs to be done.
3359 MODE is the mode of the operand pointed to by X.
3361 When -fpic is used, special handling is needed for symbolic references.
3362 See comments by legitimize_pic_address for details. */
3365 legitimize_address (rtx x
, rtx oldx ATTRIBUTE_UNUSED
,
3366 enum machine_mode mode ATTRIBUTE_UNUSED
)
3368 rtx constant_term
= const0_rtx
;
3370 if (TLS_SYMBOLIC_CONST (x
))
3372 x
= legitimize_tls_address (x
, 0);
3374 if (legitimate_address_p (mode
, x
, FALSE
))
3377 else if (GET_CODE (x
) == PLUS
3378 && (TLS_SYMBOLIC_CONST (XEXP (x
, 0))
3379 || TLS_SYMBOLIC_CONST (XEXP (x
, 1))))
3385 if (SYMBOLIC_CONST (x
)
3386 || (GET_CODE (x
) == PLUS
3387 && (SYMBOLIC_CONST (XEXP (x
, 0))
3388 || SYMBOLIC_CONST (XEXP (x
, 1)))))
3389 x
= legitimize_pic_address (x
, 0);
3391 if (legitimate_address_p (mode
, x
, FALSE
))
3395 x
= eliminate_constant_term (x
, &constant_term
);
3397 /* Optimize loading of large displacements by splitting them
3398 into the multiple of 4K and the rest; this allows the
3399 former to be CSE'd if possible.
3401 Don't do this if the displacement is added to a register
3402 pointing into the stack frame, as the offsets will
3403 change later anyway. */
3405 if (GET_CODE (constant_term
) == CONST_INT
3406 && !TARGET_LONG_DISPLACEMENT
3407 && !DISP_IN_RANGE (INTVAL (constant_term
))
3408 && !(REG_P (x
) && REGNO_PTR_FRAME_P (REGNO (x
))))
3410 HOST_WIDE_INT lower
= INTVAL (constant_term
) & 0xfff;
3411 HOST_WIDE_INT upper
= INTVAL (constant_term
) ^ lower
;
3413 rtx temp
= gen_reg_rtx (Pmode
);
3414 rtx val
= force_operand (GEN_INT (upper
), temp
);
3416 emit_move_insn (temp
, val
);
3418 x
= gen_rtx_PLUS (Pmode
, x
, temp
);
3419 constant_term
= GEN_INT (lower
);
3422 if (GET_CODE (x
) == PLUS
)
3424 if (GET_CODE (XEXP (x
, 0)) == REG
)
3426 rtx temp
= gen_reg_rtx (Pmode
);
3427 rtx val
= force_operand (XEXP (x
, 1), temp
);
3429 emit_move_insn (temp
, val
);
3431 x
= gen_rtx_PLUS (Pmode
, XEXP (x
, 0), temp
);
3434 else if (GET_CODE (XEXP (x
, 1)) == REG
)
3436 rtx temp
= gen_reg_rtx (Pmode
);
3437 rtx val
= force_operand (XEXP (x
, 0), temp
);
3439 emit_move_insn (temp
, val
);
3441 x
= gen_rtx_PLUS (Pmode
, temp
, XEXP (x
, 1));
3445 if (constant_term
!= const0_rtx
)
3446 x
= gen_rtx_PLUS (Pmode
, x
, constant_term
);
3451 /* Try a machine-dependent way of reloading an illegitimate address AD
3452 operand. If we find one, push the reload and and return the new address.
3454 MODE is the mode of the enclosing MEM. OPNUM is the operand number
3455 and TYPE is the reload type of the current reload. */
3458 legitimize_reload_address (rtx ad
, enum machine_mode mode ATTRIBUTE_UNUSED
,
3459 int opnum
, int type
)
3461 if (!optimize
|| TARGET_LONG_DISPLACEMENT
)
3464 if (GET_CODE (ad
) == PLUS
)
3466 rtx tem
= simplify_binary_operation (PLUS
, Pmode
,
3467 XEXP (ad
, 0), XEXP (ad
, 1));
3472 if (GET_CODE (ad
) == PLUS
3473 && GET_CODE (XEXP (ad
, 0)) == REG
3474 && GET_CODE (XEXP (ad
, 1)) == CONST_INT
3475 && !DISP_IN_RANGE (INTVAL (XEXP (ad
, 1))))
3477 HOST_WIDE_INT lower
= INTVAL (XEXP (ad
, 1)) & 0xfff;
3478 HOST_WIDE_INT upper
= INTVAL (XEXP (ad
, 1)) ^ lower
;
3481 cst
= GEN_INT (upper
);
3482 if (!legitimate_reload_constant_p (cst
))
3483 cst
= force_const_mem (Pmode
, cst
);
3485 tem
= gen_rtx_PLUS (Pmode
, XEXP (ad
, 0), cst
);
3486 new = gen_rtx_PLUS (Pmode
, tem
, GEN_INT (lower
));
3488 push_reload (XEXP (tem
, 1), 0, &XEXP (tem
, 1), 0,
3489 BASE_REG_CLASS
, Pmode
, VOIDmode
, 0, 0,
3490 opnum
, (enum reload_type
) type
);
3497 /* Emit code to move LEN bytes from DST to SRC. */
3500 s390_expand_movmem (rtx dst
, rtx src
, rtx len
)
3502 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) >= 0 && INTVAL (len
) <= 256)
3504 if (INTVAL (len
) > 0)
3505 emit_insn (gen_movmem_short (dst
, src
, GEN_INT (INTVAL (len
) - 1)));
3508 else if (TARGET_MVCLE
)
3510 emit_insn (gen_movmem_long (dst
, src
, convert_to_mode (Pmode
, len
, 1)));
3515 rtx dst_addr
, src_addr
, count
, blocks
, temp
;
3516 rtx loop_start_label
= gen_label_rtx ();
3517 rtx loop_end_label
= gen_label_rtx ();
3518 rtx end_label
= gen_label_rtx ();
3519 enum machine_mode mode
;
3521 mode
= GET_MODE (len
);
3522 if (mode
== VOIDmode
)
3525 dst_addr
= gen_reg_rtx (Pmode
);
3526 src_addr
= gen_reg_rtx (Pmode
);
3527 count
= gen_reg_rtx (mode
);
3528 blocks
= gen_reg_rtx (mode
);
3530 convert_move (count
, len
, 1);
3531 emit_cmp_and_jump_insns (count
, const0_rtx
,
3532 EQ
, NULL_RTX
, mode
, 1, end_label
);
3534 emit_move_insn (dst_addr
, force_operand (XEXP (dst
, 0), NULL_RTX
));
3535 emit_move_insn (src_addr
, force_operand (XEXP (src
, 0), NULL_RTX
));
3536 dst
= change_address (dst
, VOIDmode
, dst_addr
);
3537 src
= change_address (src
, VOIDmode
, src_addr
);
3539 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1, 0);
3541 emit_move_insn (count
, temp
);
3543 temp
= expand_binop (mode
, lshr_optab
, count
, GEN_INT (8), blocks
, 1, 0);
3545 emit_move_insn (blocks
, temp
);
3547 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3548 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3550 emit_label (loop_start_label
);
3552 emit_insn (gen_movmem_short (dst
, src
, GEN_INT (255)));
3553 s390_load_address (dst_addr
,
3554 gen_rtx_PLUS (Pmode
, dst_addr
, GEN_INT (256)));
3555 s390_load_address (src_addr
,
3556 gen_rtx_PLUS (Pmode
, src_addr
, GEN_INT (256)));
3558 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1, 0);
3560 emit_move_insn (blocks
, temp
);
3562 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3563 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3565 emit_jump (loop_start_label
);
3566 emit_label (loop_end_label
);
3568 emit_insn (gen_movmem_short (dst
, src
,
3569 convert_to_mode (Pmode
, count
, 1)));
3570 emit_label (end_label
);
3574 /* Emit code to set LEN bytes at DST to VAL.
3575 Make use of clrmem if VAL is zero. */
3578 s390_expand_setmem (rtx dst
, rtx len
, rtx val
)
3580 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) == 0)
3583 gcc_assert (GET_CODE (val
) == CONST_INT
|| GET_MODE (val
) == QImode
);
3585 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) > 0 && INTVAL (len
) <= 257)
3587 if (val
== const0_rtx
&& INTVAL (len
) <= 256)
3588 emit_insn (gen_clrmem_short (dst
, GEN_INT (INTVAL (len
) - 1)));
3591 /* Initialize memory by storing the first byte. */
3592 emit_move_insn (adjust_address (dst
, QImode
, 0), val
);
3594 if (INTVAL (len
) > 1)
3596 /* Initiate 1 byte overlap move.
3597 The first byte of DST is propagated through DSTP1.
3598 Prepare a movmem for: DST+1 = DST (length = LEN - 1).
3599 DST is set to size 1 so the rest of the memory location
3600 does not count as source operand. */
3601 rtx dstp1
= adjust_address (dst
, VOIDmode
, 1);
3602 set_mem_size (dst
, const1_rtx
);
3604 emit_insn (gen_movmem_short (dstp1
, dst
,
3605 GEN_INT (INTVAL (len
) - 2)));
3610 else if (TARGET_MVCLE
)
3612 val
= force_not_mem (convert_modes (Pmode
, QImode
, val
, 1));
3613 emit_insn (gen_setmem_long (dst
, convert_to_mode (Pmode
, len
, 1), val
));
3618 rtx dst_addr
, src_addr
, count
, blocks
, temp
, dstp1
= NULL_RTX
;
3619 rtx loop_start_label
= gen_label_rtx ();
3620 rtx loop_end_label
= gen_label_rtx ();
3621 rtx end_label
= gen_label_rtx ();
3622 enum machine_mode mode
;
3624 mode
= GET_MODE (len
);
3625 if (mode
== VOIDmode
)
3628 dst_addr
= gen_reg_rtx (Pmode
);
3629 src_addr
= gen_reg_rtx (Pmode
);
3630 count
= gen_reg_rtx (mode
);
3631 blocks
= gen_reg_rtx (mode
);
3633 convert_move (count
, len
, 1);
3634 emit_cmp_and_jump_insns (count
, const0_rtx
,
3635 EQ
, NULL_RTX
, mode
, 1, end_label
);
3637 emit_move_insn (dst_addr
, force_operand (XEXP (dst
, 0), NULL_RTX
));
3638 dst
= change_address (dst
, VOIDmode
, dst_addr
);
3640 if (val
== const0_rtx
)
3641 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1, 0);
3644 dstp1
= adjust_address (dst
, VOIDmode
, 1);
3645 set_mem_size (dst
, const1_rtx
);
3647 /* Initialize memory by storing the first byte. */
3648 emit_move_insn (adjust_address (dst
, QImode
, 0), val
);
3650 /* If count is 1 we are done. */
3651 emit_cmp_and_jump_insns (count
, const1_rtx
,
3652 EQ
, NULL_RTX
, mode
, 1, end_label
);
3654 temp
= expand_binop (mode
, add_optab
, count
, GEN_INT (-2), count
, 1, 0);
3657 emit_move_insn (count
, temp
);
3659 temp
= expand_binop (mode
, lshr_optab
, count
, GEN_INT (8), blocks
, 1, 0);
3661 emit_move_insn (blocks
, temp
);
3663 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3664 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3666 emit_label (loop_start_label
);
3668 if (val
== const0_rtx
)
3669 emit_insn (gen_clrmem_short (dst
, GEN_INT (255)));
3671 emit_insn (gen_movmem_short (dstp1
, dst
, GEN_INT (255)));
3672 s390_load_address (dst_addr
,
3673 gen_rtx_PLUS (Pmode
, dst_addr
, GEN_INT (256)));
3675 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1, 0);
3677 emit_move_insn (blocks
, temp
);
3679 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3680 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3682 emit_jump (loop_start_label
);
3683 emit_label (loop_end_label
);
3685 if (val
== const0_rtx
)
3686 emit_insn (gen_clrmem_short (dst
, convert_to_mode (Pmode
, count
, 1)));
3688 emit_insn (gen_movmem_short (dstp1
, dst
, convert_to_mode (Pmode
, count
, 1)));
3689 emit_label (end_label
);
3693 /* Emit code to compare LEN bytes at OP0 with those at OP1,
3694 and return the result in TARGET. */
3697 s390_expand_cmpmem (rtx target
, rtx op0
, rtx op1
, rtx len
)
3699 rtx ccreg
= gen_rtx_REG (CCUmode
, CC_REGNUM
);
3702 /* As the result of CMPINT is inverted compared to what we need,
3703 we have to swap the operands. */
3704 tmp
= op0
; op0
= op1
; op1
= tmp
;
3706 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) >= 0 && INTVAL (len
) <= 256)
3708 if (INTVAL (len
) > 0)
3710 emit_insn (gen_cmpmem_short (op0
, op1
, GEN_INT (INTVAL (len
) - 1)));
3711 emit_insn (gen_cmpint (target
, ccreg
));
3714 emit_move_insn (target
, const0_rtx
);
3716 else if (TARGET_MVCLE
)
3718 emit_insn (gen_cmpmem_long (op0
, op1
, convert_to_mode (Pmode
, len
, 1)));
3719 emit_insn (gen_cmpint (target
, ccreg
));
3723 rtx addr0
, addr1
, count
, blocks
, temp
;
3724 rtx loop_start_label
= gen_label_rtx ();
3725 rtx loop_end_label
= gen_label_rtx ();
3726 rtx end_label
= gen_label_rtx ();
3727 enum machine_mode mode
;
3729 mode
= GET_MODE (len
);
3730 if (mode
== VOIDmode
)
3733 addr0
= gen_reg_rtx (Pmode
);
3734 addr1
= gen_reg_rtx (Pmode
);
3735 count
= gen_reg_rtx (mode
);
3736 blocks
= gen_reg_rtx (mode
);
3738 convert_move (count
, len
, 1);
3739 emit_cmp_and_jump_insns (count
, const0_rtx
,
3740 EQ
, NULL_RTX
, mode
, 1, end_label
);
3742 emit_move_insn (addr0
, force_operand (XEXP (op0
, 0), NULL_RTX
));
3743 emit_move_insn (addr1
, force_operand (XEXP (op1
, 0), NULL_RTX
));
3744 op0
= change_address (op0
, VOIDmode
, addr0
);
3745 op1
= change_address (op1
, VOIDmode
, addr1
);
3747 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1, 0);
3749 emit_move_insn (count
, temp
);
3751 temp
= expand_binop (mode
, lshr_optab
, count
, GEN_INT (8), blocks
, 1, 0);
3753 emit_move_insn (blocks
, temp
);
3755 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3756 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3758 emit_label (loop_start_label
);
3760 emit_insn (gen_cmpmem_short (op0
, op1
, GEN_INT (255)));
3761 temp
= gen_rtx_NE (VOIDmode
, ccreg
, const0_rtx
);
3762 temp
= gen_rtx_IF_THEN_ELSE (VOIDmode
, temp
,
3763 gen_rtx_LABEL_REF (VOIDmode
, end_label
), pc_rtx
);
3764 temp
= gen_rtx_SET (VOIDmode
, pc_rtx
, temp
);
3765 emit_jump_insn (temp
);
3767 s390_load_address (addr0
,
3768 gen_rtx_PLUS (Pmode
, addr0
, GEN_INT (256)));
3769 s390_load_address (addr1
,
3770 gen_rtx_PLUS (Pmode
, addr1
, GEN_INT (256)));
3772 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1, 0);
3774 emit_move_insn (blocks
, temp
);
3776 emit_cmp_and_jump_insns (blocks
, const0_rtx
,
3777 EQ
, NULL_RTX
, mode
, 1, loop_end_label
);
3779 emit_jump (loop_start_label
);
3780 emit_label (loop_end_label
);
3782 emit_insn (gen_cmpmem_short (op0
, op1
,
3783 convert_to_mode (Pmode
, count
, 1)));
3784 emit_label (end_label
);
3786 emit_insn (gen_cmpint (target
, ccreg
));
3791 /* Expand conditional increment or decrement using alc/slb instructions.
3792 Should generate code setting DST to either SRC or SRC + INCREMENT,
3793 depending on the result of the comparison CMP_OP0 CMP_CODE CMP_OP1.
3794 Returns true if successful, false otherwise.
3796 That makes it possible to implement some if-constructs without jumps e.g.:
3797 (borrow = CC0 | CC1 and carry = CC2 | CC3)
3798 unsigned int a, b, c;
3799 if (a < b) c++; -> CCU b > a -> CC2; c += carry;
3800 if (a < b) c--; -> CCL3 a - b -> borrow; c -= borrow;
3801 if (a <= b) c++; -> CCL3 b - a -> borrow; c += carry;
3802 if (a <= b) c--; -> CCU a <= b -> borrow; c -= borrow;
3804 Checks for EQ and NE with a nonzero value need an additional xor e.g.:
3805 if (a == b) c++; -> CCL3 a ^= b; 0 - a -> borrow; c += carry;
3806 if (a == b) c--; -> CCU a ^= b; a <= 0 -> CC0 | CC1; c -= borrow;
3807 if (a != b) c++; -> CCU a ^= b; a > 0 -> CC2; c += carry;
3808 if (a != b) c--; -> CCL3 a ^= b; 0 - a -> borrow; c -= borrow; */
3811 s390_expand_addcc (enum rtx_code cmp_code
, rtx cmp_op0
, rtx cmp_op1
,
3812 rtx dst
, rtx src
, rtx increment
)
3814 enum machine_mode cmp_mode
;
3815 enum machine_mode cc_mode
;
3821 if ((GET_MODE (cmp_op0
) == SImode
|| GET_MODE (cmp_op0
) == VOIDmode
)
3822 && (GET_MODE (cmp_op1
) == SImode
|| GET_MODE (cmp_op1
) == VOIDmode
))
3824 else if ((GET_MODE (cmp_op0
) == DImode
|| GET_MODE (cmp_op0
) == VOIDmode
)
3825 && (GET_MODE (cmp_op1
) == DImode
|| GET_MODE (cmp_op1
) == VOIDmode
))
3830 /* Try ADD LOGICAL WITH CARRY. */
3831 if (increment
== const1_rtx
)
3833 /* Determine CC mode to use. */
3834 if (cmp_code
== EQ
|| cmp_code
== NE
)
3836 if (cmp_op1
!= const0_rtx
)
3838 cmp_op0
= expand_simple_binop (cmp_mode
, XOR
, cmp_op0
, cmp_op1
,
3839 NULL_RTX
, 0, OPTAB_WIDEN
);
3840 cmp_op1
= const0_rtx
;
3843 cmp_code
= cmp_code
== EQ
? LEU
: GTU
;
3846 if (cmp_code
== LTU
|| cmp_code
== LEU
)
3851 cmp_code
= swap_condition (cmp_code
);
3868 /* Emit comparison instruction pattern. */
3869 if (!register_operand (cmp_op0
, cmp_mode
))
3870 cmp_op0
= force_reg (cmp_mode
, cmp_op0
);
3872 insn
= gen_rtx_SET (VOIDmode
, gen_rtx_REG (cc_mode
, CC_REGNUM
),
3873 gen_rtx_COMPARE (cc_mode
, cmp_op0
, cmp_op1
));
3874 /* We use insn_invalid_p here to add clobbers if required. */
3875 ret
= insn_invalid_p (emit_insn (insn
));
3878 /* Emit ALC instruction pattern. */
3879 op_res
= gen_rtx_fmt_ee (cmp_code
, GET_MODE (dst
),
3880 gen_rtx_REG (cc_mode
, CC_REGNUM
),
3883 if (src
!= const0_rtx
)
3885 if (!register_operand (src
, GET_MODE (dst
)))
3886 src
= force_reg (GET_MODE (dst
), src
);
3888 src
= gen_rtx_PLUS (GET_MODE (dst
), src
, const0_rtx
);
3889 op_res
= gen_rtx_PLUS (GET_MODE (dst
), src
, op_res
);
3892 p
= rtvec_alloc (2);
3894 gen_rtx_SET (VOIDmode
, dst
, op_res
);
3896 gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
3897 emit_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
3902 /* Try SUBTRACT LOGICAL WITH BORROW. */
3903 if (increment
== constm1_rtx
)
3905 /* Determine CC mode to use. */
3906 if (cmp_code
== EQ
|| cmp_code
== NE
)
3908 if (cmp_op1
!= const0_rtx
)
3910 cmp_op0
= expand_simple_binop (cmp_mode
, XOR
, cmp_op0
, cmp_op1
,
3911 NULL_RTX
, 0, OPTAB_WIDEN
);
3912 cmp_op1
= const0_rtx
;
3915 cmp_code
= cmp_code
== EQ
? LEU
: GTU
;
3918 if (cmp_code
== GTU
|| cmp_code
== GEU
)
3923 cmp_code
= swap_condition (cmp_code
);
3940 /* Emit comparison instruction pattern. */
3941 if (!register_operand (cmp_op0
, cmp_mode
))
3942 cmp_op0
= force_reg (cmp_mode
, cmp_op0
);
3944 insn
= gen_rtx_SET (VOIDmode
, gen_rtx_REG (cc_mode
, CC_REGNUM
),
3945 gen_rtx_COMPARE (cc_mode
, cmp_op0
, cmp_op1
));
3946 /* We use insn_invalid_p here to add clobbers if required. */
3947 ret
= insn_invalid_p (emit_insn (insn
));
3950 /* Emit SLB instruction pattern. */
3951 if (!register_operand (src
, GET_MODE (dst
)))
3952 src
= force_reg (GET_MODE (dst
), src
);
3954 op_res
= gen_rtx_MINUS (GET_MODE (dst
),
3955 gen_rtx_MINUS (GET_MODE (dst
), src
, const0_rtx
),
3956 gen_rtx_fmt_ee (cmp_code
, GET_MODE (dst
),
3957 gen_rtx_REG (cc_mode
, CC_REGNUM
),
3959 p
= rtvec_alloc (2);
3961 gen_rtx_SET (VOIDmode
, dst
, op_res
);
3963 gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CC_REGNUM
));
3964 emit_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
3972 /* Expand code for the insv template. Return true if successful, false else. */
3975 s390_expand_insv (rtx dest
, rtx op1
, rtx op2
, rtx src
)
3977 int bitsize
= INTVAL (op1
);
3978 int bitpos
= INTVAL (op2
);
3980 /* We need byte alignment. */
3981 if (bitsize
% BITS_PER_UNIT
)
3985 && memory_operand (dest
, VOIDmode
)
3986 && (register_operand (src
, word_mode
)
3987 || const_int_operand (src
, VOIDmode
)))
3989 /* Emit standard pattern if possible. */
3990 enum machine_mode mode
= smallest_mode_for_size (bitsize
, MODE_INT
);
3991 if (GET_MODE_BITSIZE (mode
) == bitsize
)
3992 emit_move_insn (adjust_address (dest
, mode
, 0), gen_lowpart (mode
, src
));
3994 /* (set (ze (mem)) (const_int)). */
3995 else if (const_int_operand (src
, VOIDmode
))
3997 int size
= bitsize
/ BITS_PER_UNIT
;
3998 rtx src_mem
= adjust_address (force_const_mem (word_mode
, src
), BLKmode
,
3999 GET_MODE_SIZE (word_mode
) - size
);
4001 dest
= adjust_address (dest
, BLKmode
, 0);
4002 set_mem_size (dest
, GEN_INT (size
));
4003 s390_expand_movmem (dest
, src_mem
, GEN_INT (size
));
4006 /* (set (ze (mem)) (reg)). */
4007 else if (register_operand (src
, word_mode
))
4009 if (bitsize
<= GET_MODE_BITSIZE (SImode
))
4010 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
, op1
,
4014 /* Emit st,stcmh sequence. */
4015 int stcmh_width
= bitsize
- GET_MODE_BITSIZE (SImode
);
4016 int size
= stcmh_width
/ BITS_PER_UNIT
;
4018 emit_move_insn (adjust_address (dest
, SImode
, size
),
4019 gen_lowpart (SImode
, src
));
4020 set_mem_size (dest
, GEN_INT (size
));
4021 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
, GEN_INT
4022 (stcmh_width
), const0_rtx
),
4023 gen_rtx_LSHIFTRT (word_mode
, src
, GEN_INT
4024 (GET_MODE_BITSIZE (SImode
))));
4033 /* (set (ze (reg)) (const_int)). */
4035 && register_operand (dest
, word_mode
)
4036 && (bitpos
% 16) == 0
4037 && (bitsize
% 16) == 0
4038 && const_int_operand (src
, VOIDmode
))
4040 HOST_WIDE_INT val
= INTVAL (src
);
4041 int regpos
= bitpos
+ bitsize
;
4043 while (regpos
> bitpos
)
4045 enum machine_mode putmode
;
4048 if (TARGET_EXTIMM
&& (regpos
% 32 == 0) && (regpos
>= bitpos
+ 32))
4053 putsize
= GET_MODE_BITSIZE (putmode
);
4055 emit_move_insn (gen_rtx_ZERO_EXTRACT (word_mode
, dest
,
4058 gen_int_mode (val
, putmode
));
4061 gcc_assert (regpos
== bitpos
);
4068 /* A subroutine of s390_expand_cs_hqi and s390_expand_atomic which returns a
4069 register that holds VAL of mode MODE shifted by COUNT bits. */
4072 s390_expand_mask_and_shift (rtx val
, enum machine_mode mode
, rtx count
)
4074 val
= expand_simple_binop (SImode
, AND
, val
, GEN_INT (GET_MODE_MASK (mode
)),
4075 NULL_RTX
, 1, OPTAB_DIRECT
);
4076 return expand_simple_binop (SImode
, ASHIFT
, val
, count
,
4077 NULL_RTX
, 1, OPTAB_DIRECT
);
4080 /* Structure to hold the initial parameters for a compare_and_swap operation
4081 in HImode and QImode. */
4083 struct alignment_context
4085 rtx memsi
; /* SI aligned memory location. */
4086 rtx shift
; /* Bit offset with regard to lsb. */
4087 rtx modemask
; /* Mask of the HQImode shifted by SHIFT bits. */
4088 rtx modemaski
; /* ~modemask */
4089 bool aligned
; /* True if memory is aliged, false else. */
4092 /* A subroutine of s390_expand_cs_hqi and s390_expand_atomic to initialize
4093 structure AC for transparent simplifying, if the memory alignment is known
4094 to be at least 32bit. MEM is the memory location for the actual operation
4095 and MODE its mode. */
4098 init_alignment_context (struct alignment_context
*ac
, rtx mem
,
4099 enum machine_mode mode
)
4101 ac
->shift
= GEN_INT (GET_MODE_SIZE (SImode
) - GET_MODE_SIZE (mode
));
4102 ac
->aligned
= (MEM_ALIGN (mem
) >= GET_MODE_BITSIZE (SImode
));
4105 ac
->memsi
= adjust_address (mem
, SImode
, 0); /* Memory is aligned. */
4108 /* Alignment is unknown. */
4109 rtx byteoffset
, addr
, align
;
4111 /* Force the address into a register. */
4112 addr
= force_reg (Pmode
, XEXP (mem
, 0));
4114 /* Align it to SImode. */
4115 align
= expand_simple_binop (Pmode
, AND
, addr
,
4116 GEN_INT (-GET_MODE_SIZE (SImode
)),
4117 NULL_RTX
, 1, OPTAB_DIRECT
);
4119 ac
->memsi
= gen_rtx_MEM (SImode
, align
);
4120 MEM_VOLATILE_P (ac
->memsi
) = MEM_VOLATILE_P (mem
);
4121 set_mem_alias_set (ac
->memsi
, ALIAS_SET_MEMORY_BARRIER
);
4122 set_mem_align (ac
->memsi
, GET_MODE_BITSIZE (SImode
));
4124 /* Calculate shiftcount. */
4125 byteoffset
= expand_simple_binop (Pmode
, AND
, addr
,
4126 GEN_INT (GET_MODE_SIZE (SImode
) - 1),
4127 NULL_RTX
, 1, OPTAB_DIRECT
);
4128 /* As we already have some offset, evaluate the remaining distance. */
4129 ac
->shift
= expand_simple_binop (SImode
, MINUS
, ac
->shift
, byteoffset
,
4130 NULL_RTX
, 1, OPTAB_DIRECT
);
4133 /* Shift is the byte count, but we need the bitcount. */
4134 ac
->shift
= expand_simple_binop (SImode
, MULT
, ac
->shift
, GEN_INT (BITS_PER_UNIT
),
4135 NULL_RTX
, 1, OPTAB_DIRECT
);
4136 /* Calculate masks. */
4137 ac
->modemask
= expand_simple_binop (SImode
, ASHIFT
,
4138 GEN_INT (GET_MODE_MASK (mode
)), ac
->shift
,
4139 NULL_RTX
, 1, OPTAB_DIRECT
);
4140 ac
->modemaski
= expand_simple_unop (SImode
, NOT
, ac
->modemask
, NULL_RTX
, 1);
4143 /* Expand an atomic compare and swap operation for HImode and QImode. MEM is
4144 the memory location, CMP the old value to compare MEM with and NEW the value
4145 to set if CMP == MEM.
4146 CMP is never in memory for compare_and_swap_cc because
4147 expand_bool_compare_and_swap puts it into a register for later compare. */
4150 s390_expand_cs_hqi (enum machine_mode mode
, rtx target
, rtx mem
, rtx cmp
, rtx
new)
4152 struct alignment_context ac
;
4153 rtx cmpv
, newv
, val
, resv
, cc
;
4154 rtx res
= gen_reg_rtx (SImode
);
4155 rtx csloop
= gen_label_rtx ();
4156 rtx csend
= gen_label_rtx ();
4158 gcc_assert (register_operand (target
, VOIDmode
));
4159 gcc_assert (MEM_P (mem
));
4161 init_alignment_context (&ac
, mem
, mode
);
4163 /* Shift the values to the correct bit positions. */
4164 if (!(ac
.aligned
&& MEM_P (cmp
)))
4165 cmp
= s390_expand_mask_and_shift (cmp
, mode
, ac
.shift
);
4166 if (!(ac
.aligned
&& MEM_P (new)))
4167 new = s390_expand_mask_and_shift (new, mode
, ac
.shift
);
4169 /* Load full word. Subsequent loads are performed by CS. */
4170 val
= expand_simple_binop (SImode
, AND
, ac
.memsi
, ac
.modemaski
,
4171 NULL_RTX
, 1, OPTAB_DIRECT
);
4173 /* Start CS loop. */
4174 emit_label (csloop
);
4175 /* val = "<mem>00..0<mem>"
4176 * cmp = "00..0<cmp>00..0"
4177 * new = "00..0<new>00..0"
4180 /* Patch cmp and new with val at correct position. */
4181 if (ac
.aligned
&& MEM_P (cmp
))
4183 cmpv
= force_reg (SImode
, val
);
4184 store_bit_field (cmpv
, GET_MODE_BITSIZE (mode
), 0, SImode
, cmp
);
4187 cmpv
= force_reg (SImode
, expand_simple_binop (SImode
, IOR
, cmp
, val
,
4188 NULL_RTX
, 1, OPTAB_DIRECT
));
4189 if (ac
.aligned
&& MEM_P (new))
4191 newv
= force_reg (SImode
, val
);
4192 store_bit_field (newv
, GET_MODE_BITSIZE (mode
), 0, SImode
, new);
4195 newv
= force_reg (SImode
, expand_simple_binop (SImode
, IOR
, new, val
,
4196 NULL_RTX
, 1, OPTAB_DIRECT
));
4198 /* Jump to end if we're done (likely?). */
4199 s390_emit_jump (csend
, s390_emit_compare_and_swap (EQ
, res
, ac
.memsi
,
4202 /* Check for changes outside mode. */
4203 resv
= expand_simple_binop (SImode
, AND
, res
, ac
.modemaski
,
4204 NULL_RTX
, 1, OPTAB_DIRECT
);
4205 cc
= s390_emit_compare (NE
, resv
, val
);
4206 emit_move_insn (val
, resv
);
4207 /* Loop internal if so. */
4208 s390_emit_jump (csloop
, cc
);
4212 /* Return the correct part of the bitfield. */
4213 convert_move (target
, expand_simple_binop (SImode
, LSHIFTRT
, res
, ac
.shift
,
4214 NULL_RTX
, 1, OPTAB_DIRECT
), 1);
4217 /* Expand an atomic operation CODE of mode MODE. MEM is the memory location
4218 and VAL the value to play with. If AFTER is true then store the the value
4219 MEM holds after the operation, if AFTER is false then store the value MEM
4220 holds before the operation. If TARGET is zero then discard that value, else
4221 store it to TARGET. */
4224 s390_expand_atomic (enum machine_mode mode
, enum rtx_code code
,
4225 rtx target
, rtx mem
, rtx val
, bool after
)
4227 struct alignment_context ac
;
4229 rtx
new = gen_reg_rtx (SImode
);
4230 rtx orig
= gen_reg_rtx (SImode
);
4231 rtx csloop
= gen_label_rtx ();
4233 gcc_assert (!target
|| register_operand (target
, VOIDmode
));
4234 gcc_assert (MEM_P (mem
));
4236 init_alignment_context (&ac
, mem
, mode
);
4238 /* Shift val to the correct bit positions.
4239 Preserve "icm", but prevent "ex icm". */
4240 if (!(ac
.aligned
&& code
== SET
&& MEM_P (val
)))
4241 val
= s390_expand_mask_and_shift (val
, mode
, ac
.shift
);
4243 /* Further preparation insns. */
4244 if (code
== PLUS
|| code
== MINUS
)
4245 emit_move_insn (orig
, val
);
4246 else if (code
== MULT
|| code
== AND
) /* val = "11..1<val>11..1" */
4247 val
= expand_simple_binop (SImode
, XOR
, val
, ac
.modemaski
,
4248 NULL_RTX
, 1, OPTAB_DIRECT
);
4250 /* Load full word. Subsequent loads are performed by CS. */
4251 cmp
= force_reg (SImode
, ac
.memsi
);
4253 /* Start CS loop. */
4254 emit_label (csloop
);
4255 emit_move_insn (new, cmp
);
4257 /* Patch new with val at correct position. */
4262 val
= expand_simple_binop (SImode
, code
, new, orig
,
4263 NULL_RTX
, 1, OPTAB_DIRECT
);
4264 val
= expand_simple_binop (SImode
, AND
, val
, ac
.modemask
,
4265 NULL_RTX
, 1, OPTAB_DIRECT
);
4268 if (ac
.aligned
&& MEM_P (val
))
4269 store_bit_field (new, GET_MODE_BITSIZE (mode
), 0, SImode
, val
);
4272 new = expand_simple_binop (SImode
, AND
, new, ac
.modemaski
,
4273 NULL_RTX
, 1, OPTAB_DIRECT
);
4274 new = expand_simple_binop (SImode
, IOR
, new, val
,
4275 NULL_RTX
, 1, OPTAB_DIRECT
);
4281 new = expand_simple_binop (SImode
, code
, new, val
,
4282 NULL_RTX
, 1, OPTAB_DIRECT
);
4284 case MULT
: /* NAND */
4285 new = expand_simple_binop (SImode
, XOR
, new, ac
.modemask
,
4286 NULL_RTX
, 1, OPTAB_DIRECT
);
4287 new = expand_simple_binop (SImode
, AND
, new, val
,
4288 NULL_RTX
, 1, OPTAB_DIRECT
);
4294 s390_emit_jump (csloop
, s390_emit_compare_and_swap (NE
, cmp
,
4295 ac
.memsi
, cmp
, new));
4297 /* Return the correct part of the bitfield. */
4299 convert_move (target
, expand_simple_binop (SImode
, LSHIFTRT
,
4300 after
? new : cmp
, ac
.shift
,
4301 NULL_RTX
, 1, OPTAB_DIRECT
), 1);
4304 /* This is called from dwarf2out.c via TARGET_ASM_OUTPUT_DWARF_DTPREL.
4305 We need to emit DTP-relative relocations. */
4307 static void s390_output_dwarf_dtprel (FILE *, int, rtx
) ATTRIBUTE_UNUSED
;
4310 s390_output_dwarf_dtprel (FILE *file
, int size
, rtx x
)
4315 fputs ("\t.long\t", file
);
4318 fputs ("\t.quad\t", file
);
4323 output_addr_const (file
, x
);
4324 fputs ("@DTPOFF", file
);
4327 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
4328 /* Implement TARGET_MANGLE_FUNDAMENTAL_TYPE. */
4331 s390_mangle_fundamental_type (tree type
)
4333 if (TYPE_MAIN_VARIANT (type
) == long_double_type_node
4334 && TARGET_LONG_DOUBLE_128
)
4337 /* For all other types, use normal C++ mangling. */
4342 /* In the name of slightly smaller debug output, and to cater to
4343 general assembler lossage, recognize various UNSPEC sequences
4344 and turn them back into a direct symbol reference. */
4347 s390_delegitimize_address (rtx orig_x
)
4351 if (GET_CODE (x
) != MEM
)
4355 if (GET_CODE (x
) == PLUS
4356 && GET_CODE (XEXP (x
, 1)) == CONST
4357 && GET_CODE (XEXP (x
, 0)) == REG
4358 && REGNO (XEXP (x
, 0)) == PIC_OFFSET_TABLE_REGNUM
)
4360 y
= XEXP (XEXP (x
, 1), 0);
4361 if (GET_CODE (y
) == UNSPEC
4362 && XINT (y
, 1) == UNSPEC_GOT
)
4363 return XVECEXP (y
, 0, 0);
4367 if (GET_CODE (x
) == CONST
)
4370 if (GET_CODE (y
) == UNSPEC
4371 && XINT (y
, 1) == UNSPEC_GOTENT
)
4372 return XVECEXP (y
, 0, 0);
4379 /* Output operand OP to stdio stream FILE.
4380 OP is an address (register + offset) which is not used to address data;
4381 instead the rightmost bits are interpreted as the value. */
4384 print_shift_count_operand (FILE *file
, rtx op
)
4386 HOST_WIDE_INT offset
;
4389 /* Extract base register and offset. */
4390 if (!s390_decompose_shift_count (op
, &base
, &offset
))
4396 gcc_assert (GET_CODE (base
) == REG
);
4397 gcc_assert (REGNO (base
) < FIRST_PSEUDO_REGISTER
);
4398 gcc_assert (REGNO_REG_CLASS (REGNO (base
)) == ADDR_REGS
);
4401 /* Offsets are constricted to twelve bits. */
4402 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, offset
& ((1 << 12) - 1));
4404 fprintf (file
, "(%s)", reg_names
[REGNO (base
)]);
4407 /* See 'get_some_local_dynamic_name'. */
4410 get_some_local_dynamic_name_1 (rtx
*px
, void *data ATTRIBUTE_UNUSED
)
4414 if (GET_CODE (x
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (x
))
4416 x
= get_pool_constant (x
);
4417 return for_each_rtx (&x
, get_some_local_dynamic_name_1
, 0);
4420 if (GET_CODE (x
) == SYMBOL_REF
4421 && tls_symbolic_operand (x
) == TLS_MODEL_LOCAL_DYNAMIC
)
4423 cfun
->machine
->some_ld_name
= XSTR (x
, 0);
4430 /* Locate some local-dynamic symbol still in use by this function
4431 so that we can print its name in local-dynamic base patterns. */
4434 get_some_local_dynamic_name (void)
4438 if (cfun
->machine
->some_ld_name
)
4439 return cfun
->machine
->some_ld_name
;
4441 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
4443 && for_each_rtx (&PATTERN (insn
), get_some_local_dynamic_name_1
, 0))
4444 return cfun
->machine
->some_ld_name
;
4449 /* Output machine-dependent UNSPECs occurring in address constant X
4450 in assembler syntax to stdio stream FILE. Returns true if the
4451 constant X could be recognized, false otherwise. */
4454 s390_output_addr_const_extra (FILE *file
, rtx x
)
4456 if (GET_CODE (x
) == UNSPEC
&& XVECLEN (x
, 0) == 1)
4457 switch (XINT (x
, 1))
4460 output_addr_const (file
, XVECEXP (x
, 0, 0));
4461 fprintf (file
, "@GOTENT");
4464 output_addr_const (file
, XVECEXP (x
, 0, 0));
4465 fprintf (file
, "@GOT");
4468 output_addr_const (file
, XVECEXP (x
, 0, 0));
4469 fprintf (file
, "@GOTOFF");
4472 output_addr_const (file
, XVECEXP (x
, 0, 0));
4473 fprintf (file
, "@PLT");
4476 output_addr_const (file
, XVECEXP (x
, 0, 0));
4477 fprintf (file
, "@PLTOFF");
4480 output_addr_const (file
, XVECEXP (x
, 0, 0));
4481 fprintf (file
, "@TLSGD");
4484 assemble_name (file
, get_some_local_dynamic_name ());
4485 fprintf (file
, "@TLSLDM");
4488 output_addr_const (file
, XVECEXP (x
, 0, 0));
4489 fprintf (file
, "@DTPOFF");
4492 output_addr_const (file
, XVECEXP (x
, 0, 0));
4493 fprintf (file
, "@NTPOFF");
4495 case UNSPEC_GOTNTPOFF
:
4496 output_addr_const (file
, XVECEXP (x
, 0, 0));
4497 fprintf (file
, "@GOTNTPOFF");
4499 case UNSPEC_INDNTPOFF
:
4500 output_addr_const (file
, XVECEXP (x
, 0, 0));
4501 fprintf (file
, "@INDNTPOFF");
4508 /* Output address operand ADDR in assembler syntax to
4509 stdio stream FILE. */
4512 print_operand_address (FILE *file
, rtx addr
)
4514 struct s390_address ad
;
4516 if (!s390_decompose_address (addr
, &ad
)
4517 || (ad
.base
&& !REG_OK_FOR_BASE_STRICT_P (ad
.base
))
4518 || (ad
.indx
&& !REG_OK_FOR_INDEX_STRICT_P (ad
.indx
)))
4519 output_operand_lossage ("cannot decompose address");
4522 output_addr_const (file
, ad
.disp
);
4524 fprintf (file
, "0");
4526 if (ad
.base
&& ad
.indx
)
4527 fprintf (file
, "(%s,%s)", reg_names
[REGNO (ad
.indx
)],
4528 reg_names
[REGNO (ad
.base
)]);
4530 fprintf (file
, "(%s)", reg_names
[REGNO (ad
.base
)]);
4533 /* Output operand X in assembler syntax to stdio stream FILE.
4534 CODE specified the format flag. The following format flags
4537 'C': print opcode suffix for branch condition.
4538 'D': print opcode suffix for inverse branch condition.
4539 'J': print tls_load/tls_gdcall/tls_ldcall suffix
4540 'G': print the size of the operand in bytes.
4541 'O': print only the displacement of a memory reference.
4542 'R': print only the base register of a memory reference.
4543 'S': print S-type memory reference (base+displacement).
4544 'N': print the second word of a DImode operand.
4545 'M': print the second word of a TImode operand.
4546 'Y': print shift count operand.
4548 'b': print integer X as if it's an unsigned byte.
4549 'x': print integer X as if it's an unsigned halfword.
4550 'h': print integer X as if it's a signed halfword.
4551 'i': print the first nonzero HImode part of X.
4552 'j': print the first HImode part unequal to -1 of X.
4553 'k': print the first nonzero SImode part of X.
4554 'm': print the first SImode part unequal to -1 of X.
4555 'o': print integer X as if it's an unsigned 32bit word. */
4558 print_operand (FILE *file
, rtx x
, int code
)
4563 fprintf (file
, s390_branch_condition_mnemonic (x
, FALSE
));
4567 fprintf (file
, s390_branch_condition_mnemonic (x
, TRUE
));
4571 if (GET_CODE (x
) == SYMBOL_REF
)
4573 fprintf (file
, "%s", ":tls_load:");
4574 output_addr_const (file
, x
);
4576 else if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_TLSGD
)
4578 fprintf (file
, "%s", ":tls_gdcall:");
4579 output_addr_const (file
, XVECEXP (x
, 0, 0));
4581 else if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_TLSLDM
)
4583 fprintf (file
, "%s", ":tls_ldcall:");
4584 assemble_name (file
, get_some_local_dynamic_name ());
4591 fprintf (file
, "%u", GET_MODE_SIZE (GET_MODE (x
)));
4596 struct s390_address ad
;
4599 gcc_assert (GET_CODE (x
) == MEM
);
4600 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
4602 gcc_assert (!ad
.base
|| REG_OK_FOR_BASE_STRICT_P (ad
.base
));
4603 gcc_assert (!ad
.indx
);
4606 output_addr_const (file
, ad
.disp
);
4608 fprintf (file
, "0");
4614 struct s390_address ad
;
4617 gcc_assert (GET_CODE (x
) == MEM
);
4618 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
4620 gcc_assert (!ad
.base
|| REG_OK_FOR_BASE_STRICT_P (ad
.base
));
4621 gcc_assert (!ad
.indx
);
4624 fprintf (file
, "%s", reg_names
[REGNO (ad
.base
)]);
4626 fprintf (file
, "0");
4632 struct s390_address ad
;
4635 gcc_assert (GET_CODE (x
) == MEM
);
4636 ret
= s390_decompose_address (XEXP (x
, 0), &ad
);
4638 gcc_assert (!ad
.base
|| REG_OK_FOR_BASE_STRICT_P (ad
.base
));
4639 gcc_assert (!ad
.indx
);
4642 output_addr_const (file
, ad
.disp
);
4644 fprintf (file
, "0");
4647 fprintf (file
, "(%s)", reg_names
[REGNO (ad
.base
)]);
4652 if (GET_CODE (x
) == REG
)
4653 x
= gen_rtx_REG (GET_MODE (x
), REGNO (x
) + 1);
4654 else if (GET_CODE (x
) == MEM
)
4655 x
= change_address (x
, VOIDmode
, plus_constant (XEXP (x
, 0), 4));
4661 if (GET_CODE (x
) == REG
)
4662 x
= gen_rtx_REG (GET_MODE (x
), REGNO (x
) + 1);
4663 else if (GET_CODE (x
) == MEM
)
4664 x
= change_address (x
, VOIDmode
, plus_constant (XEXP (x
, 0), 8));
4670 print_shift_count_operand (file
, x
);
4674 switch (GET_CODE (x
))
4677 fprintf (file
, "%s", reg_names
[REGNO (x
)]);
4681 output_address (XEXP (x
, 0));
4688 output_addr_const (file
, x
);
4693 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
) & 0xff);
4694 else if (code
== 'x')
4695 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
) & 0xffff);
4696 else if (code
== 'h')
4697 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, ((INTVAL (x
) & 0xffff) ^ 0x8000) - 0x8000);
4698 else if (code
== 'i')
4699 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
4700 s390_extract_part (x
, HImode
, 0));
4701 else if (code
== 'j')
4702 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
4703 s390_extract_part (x
, HImode
, -1));
4704 else if (code
== 'k')
4705 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
4706 s390_extract_part (x
, SImode
, 0));
4707 else if (code
== 'm')
4708 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
4709 s390_extract_part (x
, SImode
, -1));
4710 else if (code
== 'o')
4711 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
) & 0xffffffff);
4713 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
));
4717 gcc_assert (GET_MODE (x
) == VOIDmode
);
4719 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, CONST_DOUBLE_LOW (x
) & 0xff);
4720 else if (code
== 'x')
4721 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, CONST_DOUBLE_LOW (x
) & 0xffff);
4722 else if (code
== 'h')
4723 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, ((CONST_DOUBLE_LOW (x
) & 0xffff) ^ 0x8000) - 0x8000);
4729 fatal_insn ("UNKNOWN in print_operand !?", x
);
4734 /* Target hook for assembling integer objects. We need to define it
4735 here to work a round a bug in some versions of GAS, which couldn't
4736 handle values smaller than INT_MIN when printed in decimal. */
4739 s390_assemble_integer (rtx x
, unsigned int size
, int aligned_p
)
4741 if (size
== 8 && aligned_p
4742 && GET_CODE (x
) == CONST_INT
&& INTVAL (x
) < INT_MIN
)
4744 fprintf (asm_out_file
, "\t.quad\t" HOST_WIDE_INT_PRINT_HEX
"\n",
4748 return default_assemble_integer (x
, size
, aligned_p
);
4751 /* Returns true if register REGNO is used for forming
4752 a memory address in expression X. */
4755 reg_used_in_mem_p (int regno
, rtx x
)
4757 enum rtx_code code
= GET_CODE (x
);
4763 if (refers_to_regno_p (regno
, regno
+1,
4767 else if (code
== SET
4768 && GET_CODE (SET_DEST (x
)) == PC
)
4770 if (refers_to_regno_p (regno
, regno
+1,
4775 fmt
= GET_RTX_FORMAT (code
);
4776 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4779 && reg_used_in_mem_p (regno
, XEXP (x
, i
)))
4782 else if (fmt
[i
] == 'E')
4783 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
4784 if (reg_used_in_mem_p (regno
, XVECEXP (x
, i
, j
)))
4790 /* Returns true if expression DEP_RTX sets an address register
4791 used by instruction INSN to address memory. */
4794 addr_generation_dependency_p (rtx dep_rtx
, rtx insn
)
4798 if (GET_CODE (dep_rtx
) == INSN
)
4799 dep_rtx
= PATTERN (dep_rtx
);
4801 if (GET_CODE (dep_rtx
) == SET
)
4803 target
= SET_DEST (dep_rtx
);
4804 if (GET_CODE (target
) == STRICT_LOW_PART
)
4805 target
= XEXP (target
, 0);
4806 while (GET_CODE (target
) == SUBREG
)
4807 target
= SUBREG_REG (target
);
4809 if (GET_CODE (target
) == REG
)
4811 int regno
= REGNO (target
);
4813 if (s390_safe_attr_type (insn
) == TYPE_LA
)
4815 pat
= PATTERN (insn
);
4816 if (GET_CODE (pat
) == PARALLEL
)
4818 gcc_assert (XVECLEN (pat
, 0) == 2);
4819 pat
= XVECEXP (pat
, 0, 0);
4821 gcc_assert (GET_CODE (pat
) == SET
);
4822 return refers_to_regno_p (regno
, regno
+1, SET_SRC (pat
), 0);
4824 else if (get_attr_atype (insn
) == ATYPE_AGEN
)
4825 return reg_used_in_mem_p (regno
, PATTERN (insn
));
4831 /* Return 1, if dep_insn sets register used in insn in the agen unit. */
4834 s390_agen_dep_p (rtx dep_insn
, rtx insn
)
4836 rtx dep_rtx
= PATTERN (dep_insn
);
4839 if (GET_CODE (dep_rtx
) == SET
4840 && addr_generation_dependency_p (dep_rtx
, insn
))
4842 else if (GET_CODE (dep_rtx
) == PARALLEL
)
4844 for (i
= 0; i
< XVECLEN (dep_rtx
, 0); i
++)
4846 if (addr_generation_dependency_p (XVECEXP (dep_rtx
, 0, i
), insn
))
4853 /* A C statement (sans semicolon) to update the integer scheduling priority
4854 INSN_PRIORITY (INSN). Increase the priority to execute the INSN earlier,
4855 reduce the priority to execute INSN later. Do not define this macro if
4856 you do not need to adjust the scheduling priorities of insns.
4858 A STD instruction should be scheduled earlier,
4859 in order to use the bypass. */
4862 s390_adjust_priority (rtx insn ATTRIBUTE_UNUSED
, int priority
)
4864 if (! INSN_P (insn
))
4867 if (s390_tune
!= PROCESSOR_2084_Z990
4868 && s390_tune
!= PROCESSOR_2094_Z9_109
)
4871 switch (s390_safe_attr_type (insn
))
4875 priority
= priority
<< 3;
4879 priority
= priority
<< 1;
4887 /* The number of instructions that can be issued per cycle. */
4890 s390_issue_rate (void)
4892 if (s390_tune
== PROCESSOR_2084_Z990
4893 || s390_tune
== PROCESSOR_2094_Z9_109
)
4899 s390_first_cycle_multipass_dfa_lookahead (void)
4905 /* Annotate every literal pool reference in X by an UNSPEC_LTREF expression.
4906 Fix up MEMs as required. */
4909 annotate_constant_pool_refs (rtx
*x
)
4914 gcc_assert (GET_CODE (*x
) != SYMBOL_REF
4915 || !CONSTANT_POOL_ADDRESS_P (*x
));
4917 /* Literal pool references can only occur inside a MEM ... */
4918 if (GET_CODE (*x
) == MEM
)
4920 rtx memref
= XEXP (*x
, 0);
4922 if (GET_CODE (memref
) == SYMBOL_REF
4923 && CONSTANT_POOL_ADDRESS_P (memref
))
4925 rtx base
= cfun
->machine
->base_reg
;
4926 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, memref
, base
),
4929 *x
= replace_equiv_address (*x
, addr
);
4933 if (GET_CODE (memref
) == CONST
4934 && GET_CODE (XEXP (memref
, 0)) == PLUS
4935 && GET_CODE (XEXP (XEXP (memref
, 0), 1)) == CONST_INT
4936 && GET_CODE (XEXP (XEXP (memref
, 0), 0)) == SYMBOL_REF
4937 && CONSTANT_POOL_ADDRESS_P (XEXP (XEXP (memref
, 0), 0)))
4939 HOST_WIDE_INT off
= INTVAL (XEXP (XEXP (memref
, 0), 1));
4940 rtx sym
= XEXP (XEXP (memref
, 0), 0);
4941 rtx base
= cfun
->machine
->base_reg
;
4942 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, sym
, base
),
4945 *x
= replace_equiv_address (*x
, plus_constant (addr
, off
));
4950 /* ... or a load-address type pattern. */
4951 if (GET_CODE (*x
) == SET
)
4953 rtx addrref
= SET_SRC (*x
);
4955 if (GET_CODE (addrref
) == SYMBOL_REF
4956 && CONSTANT_POOL_ADDRESS_P (addrref
))
4958 rtx base
= cfun
->machine
->base_reg
;
4959 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, addrref
, base
),
4962 SET_SRC (*x
) = addr
;
4966 if (GET_CODE (addrref
) == CONST
4967 && GET_CODE (XEXP (addrref
, 0)) == PLUS
4968 && GET_CODE (XEXP (XEXP (addrref
, 0), 1)) == CONST_INT
4969 && GET_CODE (XEXP (XEXP (addrref
, 0), 0)) == SYMBOL_REF
4970 && CONSTANT_POOL_ADDRESS_P (XEXP (XEXP (addrref
, 0), 0)))
4972 HOST_WIDE_INT off
= INTVAL (XEXP (XEXP (addrref
, 0), 1));
4973 rtx sym
= XEXP (XEXP (addrref
, 0), 0);
4974 rtx base
= cfun
->machine
->base_reg
;
4975 rtx addr
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, sym
, base
),
4978 SET_SRC (*x
) = plus_constant (addr
, off
);
4983 /* Annotate LTREL_BASE as well. */
4984 if (GET_CODE (*x
) == UNSPEC
4985 && XINT (*x
, 1) == UNSPEC_LTREL_BASE
)
4987 rtx base
= cfun
->machine
->base_reg
;
4988 *x
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, XVECEXP (*x
, 0, 0), base
),
4993 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
4994 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
4998 annotate_constant_pool_refs (&XEXP (*x
, i
));
5000 else if (fmt
[i
] == 'E')
5002 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
5003 annotate_constant_pool_refs (&XVECEXP (*x
, i
, j
));
5008 /* Split all branches that exceed the maximum distance.
5009 Returns true if this created a new literal pool entry. */
5012 s390_split_branches (void)
5014 rtx temp_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
5015 int new_literal
= 0, ret
;
5016 rtx insn
, pat
, tmp
, target
;
5019 /* We need correct insn addresses. */
5021 shorten_branches (get_insns ());
5023 /* Find all branches that exceed 64KB, and split them. */
5025 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5027 if (GET_CODE (insn
) != JUMP_INSN
)
5030 pat
= PATTERN (insn
);
5031 if (GET_CODE (pat
) == PARALLEL
&& XVECLEN (pat
, 0) > 2)
5032 pat
= XVECEXP (pat
, 0, 0);
5033 if (GET_CODE (pat
) != SET
|| SET_DEST (pat
) != pc_rtx
)
5036 if (GET_CODE (SET_SRC (pat
)) == LABEL_REF
)
5038 label
= &SET_SRC (pat
);
5040 else if (GET_CODE (SET_SRC (pat
)) == IF_THEN_ELSE
)
5042 if (GET_CODE (XEXP (SET_SRC (pat
), 1)) == LABEL_REF
)
5043 label
= &XEXP (SET_SRC (pat
), 1);
5044 else if (GET_CODE (XEXP (SET_SRC (pat
), 2)) == LABEL_REF
)
5045 label
= &XEXP (SET_SRC (pat
), 2);
5052 if (get_attr_length (insn
) <= 4)
5055 /* We are going to use the return register as scratch register,
5056 make sure it will be saved/restored by the prologue/epilogue. */
5057 cfun_frame_layout
.save_return_addr_p
= 1;
5062 tmp
= force_const_mem (Pmode
, *label
);
5063 tmp
= emit_insn_before (gen_rtx_SET (Pmode
, temp_reg
, tmp
), insn
);
5064 INSN_ADDRESSES_NEW (tmp
, -1);
5065 annotate_constant_pool_refs (&PATTERN (tmp
));
5072 target
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, *label
),
5073 UNSPEC_LTREL_OFFSET
);
5074 target
= gen_rtx_CONST (Pmode
, target
);
5075 target
= force_const_mem (Pmode
, target
);
5076 tmp
= emit_insn_before (gen_rtx_SET (Pmode
, temp_reg
, target
), insn
);
5077 INSN_ADDRESSES_NEW (tmp
, -1);
5078 annotate_constant_pool_refs (&PATTERN (tmp
));
5080 target
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, XEXP (target
, 0),
5081 cfun
->machine
->base_reg
),
5083 target
= gen_rtx_PLUS (Pmode
, temp_reg
, target
);
5086 ret
= validate_change (insn
, label
, target
, 0);
5094 /* Find an annotated literal pool symbol referenced in RTX X,
5095 and store it at REF. Will abort if X contains references to
5096 more than one such pool symbol; multiple references to the same
5097 symbol are allowed, however.
5099 The rtx pointed to by REF must be initialized to NULL_RTX
5100 by the caller before calling this routine. */
5103 find_constant_pool_ref (rtx x
, rtx
*ref
)
5108 /* Ignore LTREL_BASE references. */
5109 if (GET_CODE (x
) == UNSPEC
5110 && XINT (x
, 1) == UNSPEC_LTREL_BASE
)
5112 /* Likewise POOL_ENTRY insns. */
5113 if (GET_CODE (x
) == UNSPEC_VOLATILE
5114 && XINT (x
, 1) == UNSPECV_POOL_ENTRY
)
5117 gcc_assert (GET_CODE (x
) != SYMBOL_REF
5118 || !CONSTANT_POOL_ADDRESS_P (x
));
5120 if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_LTREF
)
5122 rtx sym
= XVECEXP (x
, 0, 0);
5123 gcc_assert (GET_CODE (sym
) == SYMBOL_REF
5124 && CONSTANT_POOL_ADDRESS_P (sym
));
5126 if (*ref
== NULL_RTX
)
5129 gcc_assert (*ref
== sym
);
5134 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
5135 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
5139 find_constant_pool_ref (XEXP (x
, i
), ref
);
5141 else if (fmt
[i
] == 'E')
5143 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
5144 find_constant_pool_ref (XVECEXP (x
, i
, j
), ref
);
5149 /* Replace every reference to the annotated literal pool
5150 symbol REF in X by its base plus OFFSET. */
5153 replace_constant_pool_ref (rtx
*x
, rtx ref
, rtx offset
)
5158 gcc_assert (*x
!= ref
);
5160 if (GET_CODE (*x
) == UNSPEC
5161 && XINT (*x
, 1) == UNSPEC_LTREF
5162 && XVECEXP (*x
, 0, 0) == ref
)
5164 *x
= gen_rtx_PLUS (Pmode
, XVECEXP (*x
, 0, 1), offset
);
5168 if (GET_CODE (*x
) == PLUS
5169 && GET_CODE (XEXP (*x
, 1)) == CONST_INT
5170 && GET_CODE (XEXP (*x
, 0)) == UNSPEC
5171 && XINT (XEXP (*x
, 0), 1) == UNSPEC_LTREF
5172 && XVECEXP (XEXP (*x
, 0), 0, 0) == ref
)
5174 rtx addr
= gen_rtx_PLUS (Pmode
, XVECEXP (XEXP (*x
, 0), 0, 1), offset
);
5175 *x
= plus_constant (addr
, INTVAL (XEXP (*x
, 1)));
5179 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
5180 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
5184 replace_constant_pool_ref (&XEXP (*x
, i
), ref
, offset
);
5186 else if (fmt
[i
] == 'E')
5188 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
5189 replace_constant_pool_ref (&XVECEXP (*x
, i
, j
), ref
, offset
);
5194 /* Check whether X contains an UNSPEC_LTREL_BASE.
5195 Return its constant pool symbol if found, NULL_RTX otherwise. */
5198 find_ltrel_base (rtx x
)
5203 if (GET_CODE (x
) == UNSPEC
5204 && XINT (x
, 1) == UNSPEC_LTREL_BASE
)
5205 return XVECEXP (x
, 0, 0);
5207 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
5208 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
5212 rtx fnd
= find_ltrel_base (XEXP (x
, i
));
5216 else if (fmt
[i
] == 'E')
5218 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
5220 rtx fnd
= find_ltrel_base (XVECEXP (x
, i
, j
));
5230 /* Replace any occurrence of UNSPEC_LTREL_BASE in X with its base. */
5233 replace_ltrel_base (rtx
*x
)
5238 if (GET_CODE (*x
) == UNSPEC
5239 && XINT (*x
, 1) == UNSPEC_LTREL_BASE
)
5241 *x
= XVECEXP (*x
, 0, 1);
5245 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
5246 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
5250 replace_ltrel_base (&XEXP (*x
, i
));
5252 else if (fmt
[i
] == 'E')
5254 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
5255 replace_ltrel_base (&XVECEXP (*x
, i
, j
));
5261 /* We keep a list of constants which we have to add to internal
5262 constant tables in the middle of large functions. */
5264 #define NR_C_MODES 8
5265 enum machine_mode constant_modes
[NR_C_MODES
] =
5276 struct constant
*next
;
5281 struct constant_pool
5283 struct constant_pool
*next
;
5288 struct constant
*constants
[NR_C_MODES
];
5289 struct constant
*execute
;
5294 /* Allocate new constant_pool structure. */
5296 static struct constant_pool
*
5297 s390_alloc_pool (void)
5299 struct constant_pool
*pool
;
5302 pool
= (struct constant_pool
*) xmalloc (sizeof *pool
);
5304 for (i
= 0; i
< NR_C_MODES
; i
++)
5305 pool
->constants
[i
] = NULL
;
5307 pool
->execute
= NULL
;
5308 pool
->label
= gen_label_rtx ();
5309 pool
->first_insn
= NULL_RTX
;
5310 pool
->pool_insn
= NULL_RTX
;
5311 pool
->insns
= BITMAP_ALLOC (NULL
);
5317 /* Create new constant pool covering instructions starting at INSN
5318 and chain it to the end of POOL_LIST. */
5320 static struct constant_pool
*
5321 s390_start_pool (struct constant_pool
**pool_list
, rtx insn
)
5323 struct constant_pool
*pool
, **prev
;
5325 pool
= s390_alloc_pool ();
5326 pool
->first_insn
= insn
;
5328 for (prev
= pool_list
; *prev
; prev
= &(*prev
)->next
)
5335 /* End range of instructions covered by POOL at INSN and emit
5336 placeholder insn representing the pool. */
5339 s390_end_pool (struct constant_pool
*pool
, rtx insn
)
5341 rtx pool_size
= GEN_INT (pool
->size
+ 8 /* alignment slop */);
5344 insn
= get_last_insn ();
5346 pool
->pool_insn
= emit_insn_after (gen_pool (pool_size
), insn
);
5347 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
5350 /* Add INSN to the list of insns covered by POOL. */
5353 s390_add_pool_insn (struct constant_pool
*pool
, rtx insn
)
5355 bitmap_set_bit (pool
->insns
, INSN_UID (insn
));
5358 /* Return pool out of POOL_LIST that covers INSN. */
5360 static struct constant_pool
*
5361 s390_find_pool (struct constant_pool
*pool_list
, rtx insn
)
5363 struct constant_pool
*pool
;
5365 for (pool
= pool_list
; pool
; pool
= pool
->next
)
5366 if (bitmap_bit_p (pool
->insns
, INSN_UID (insn
)))
5372 /* Add constant VAL of mode MODE to the constant pool POOL. */
5375 s390_add_constant (struct constant_pool
*pool
, rtx val
, enum machine_mode mode
)
5380 for (i
= 0; i
< NR_C_MODES
; i
++)
5381 if (constant_modes
[i
] == mode
)
5383 gcc_assert (i
!= NR_C_MODES
);
5385 for (c
= pool
->constants
[i
]; c
!= NULL
; c
= c
->next
)
5386 if (rtx_equal_p (val
, c
->value
))
5391 c
= (struct constant
*) xmalloc (sizeof *c
);
5393 c
->label
= gen_label_rtx ();
5394 c
->next
= pool
->constants
[i
];
5395 pool
->constants
[i
] = c
;
5396 pool
->size
+= GET_MODE_SIZE (mode
);
5400 /* Find constant VAL of mode MODE in the constant pool POOL.
5401 Return an RTX describing the distance from the start of
5402 the pool to the location of the new constant. */
5405 s390_find_constant (struct constant_pool
*pool
, rtx val
,
5406 enum machine_mode mode
)
5412 for (i
= 0; i
< NR_C_MODES
; i
++)
5413 if (constant_modes
[i
] == mode
)
5415 gcc_assert (i
!= NR_C_MODES
);
5417 for (c
= pool
->constants
[i
]; c
!= NULL
; c
= c
->next
)
5418 if (rtx_equal_p (val
, c
->value
))
5423 offset
= gen_rtx_MINUS (Pmode
, gen_rtx_LABEL_REF (Pmode
, c
->label
),
5424 gen_rtx_LABEL_REF (Pmode
, pool
->label
));
5425 offset
= gen_rtx_CONST (Pmode
, offset
);
5429 /* Check whether INSN is an execute. Return the label_ref to its
5430 execute target template if so, NULL_RTX otherwise. */
5433 s390_execute_label (rtx insn
)
5435 if (GET_CODE (insn
) == INSN
5436 && GET_CODE (PATTERN (insn
)) == PARALLEL
5437 && GET_CODE (XVECEXP (PATTERN (insn
), 0, 0)) == UNSPEC
5438 && XINT (XVECEXP (PATTERN (insn
), 0, 0), 1) == UNSPEC_EXECUTE
)
5439 return XVECEXP (XVECEXP (PATTERN (insn
), 0, 0), 0, 2);
5444 /* Add execute target for INSN to the constant pool POOL. */
5447 s390_add_execute (struct constant_pool
*pool
, rtx insn
)
5451 for (c
= pool
->execute
; c
!= NULL
; c
= c
->next
)
5452 if (INSN_UID (insn
) == INSN_UID (c
->value
))
5457 c
= (struct constant
*) xmalloc (sizeof *c
);
5459 c
->label
= gen_label_rtx ();
5460 c
->next
= pool
->execute
;
5466 /* Find execute target for INSN in the constant pool POOL.
5467 Return an RTX describing the distance from the start of
5468 the pool to the location of the execute target. */
5471 s390_find_execute (struct constant_pool
*pool
, rtx insn
)
5476 for (c
= pool
->execute
; c
!= NULL
; c
= c
->next
)
5477 if (INSN_UID (insn
) == INSN_UID (c
->value
))
5482 offset
= gen_rtx_MINUS (Pmode
, gen_rtx_LABEL_REF (Pmode
, c
->label
),
5483 gen_rtx_LABEL_REF (Pmode
, pool
->label
));
5484 offset
= gen_rtx_CONST (Pmode
, offset
);
5488 /* For an execute INSN, extract the execute target template. */
5491 s390_execute_target (rtx insn
)
5493 rtx pattern
= PATTERN (insn
);
5494 gcc_assert (s390_execute_label (insn
));
5496 if (XVECLEN (pattern
, 0) == 2)
5498 pattern
= copy_rtx (XVECEXP (pattern
, 0, 1));
5502 rtvec vec
= rtvec_alloc (XVECLEN (pattern
, 0) - 1);
5505 for (i
= 0; i
< XVECLEN (pattern
, 0) - 1; i
++)
5506 RTVEC_ELT (vec
, i
) = copy_rtx (XVECEXP (pattern
, 0, i
+ 1));
5508 pattern
= gen_rtx_PARALLEL (VOIDmode
, vec
);
5514 /* Indicate that INSN cannot be duplicated. This is the case for
5515 execute insns that carry a unique label. */
5518 s390_cannot_copy_insn_p (rtx insn
)
5520 rtx label
= s390_execute_label (insn
);
5521 return label
&& label
!= const0_rtx
;
5524 /* Dump out the constants in POOL. If REMOTE_LABEL is true,
5525 do not emit the pool base label. */
5528 s390_dump_pool (struct constant_pool
*pool
, bool remote_label
)
5531 rtx insn
= pool
->pool_insn
;
5534 /* Switch to rodata section. */
5535 if (TARGET_CPU_ZARCH
)
5537 insn
= emit_insn_after (gen_pool_section_start (), insn
);
5538 INSN_ADDRESSES_NEW (insn
, -1);
5541 /* Ensure minimum pool alignment. */
5542 if (TARGET_CPU_ZARCH
)
5543 insn
= emit_insn_after (gen_pool_align (GEN_INT (8)), insn
);
5545 insn
= emit_insn_after (gen_pool_align (GEN_INT (4)), insn
);
5546 INSN_ADDRESSES_NEW (insn
, -1);
5548 /* Emit pool base label. */
5551 insn
= emit_label_after (pool
->label
, insn
);
5552 INSN_ADDRESSES_NEW (insn
, -1);
5555 /* Dump constants in descending alignment requirement order,
5556 ensuring proper alignment for every constant. */
5557 for (i
= 0; i
< NR_C_MODES
; i
++)
5558 for (c
= pool
->constants
[i
]; c
; c
= c
->next
)
5560 /* Convert UNSPEC_LTREL_OFFSET unspecs to pool-relative references. */
5561 rtx value
= c
->value
;
5562 if (GET_CODE (value
) == CONST
5563 && GET_CODE (XEXP (value
, 0)) == UNSPEC
5564 && XINT (XEXP (value
, 0), 1) == UNSPEC_LTREL_OFFSET
5565 && XVECLEN (XEXP (value
, 0), 0) == 1)
5567 value
= gen_rtx_MINUS (Pmode
, XVECEXP (XEXP (value
, 0), 0, 0),
5568 gen_rtx_LABEL_REF (VOIDmode
, pool
->label
));
5569 value
= gen_rtx_CONST (VOIDmode
, value
);
5572 insn
= emit_label_after (c
->label
, insn
);
5573 INSN_ADDRESSES_NEW (insn
, -1);
5575 value
= gen_rtx_UNSPEC_VOLATILE (constant_modes
[i
],
5576 gen_rtvec (1, value
),
5577 UNSPECV_POOL_ENTRY
);
5578 insn
= emit_insn_after (value
, insn
);
5579 INSN_ADDRESSES_NEW (insn
, -1);
5582 /* Ensure minimum alignment for instructions. */
5583 insn
= emit_insn_after (gen_pool_align (GEN_INT (2)), insn
);
5584 INSN_ADDRESSES_NEW (insn
, -1);
5586 /* Output in-pool execute template insns. */
5587 for (c
= pool
->execute
; c
; c
= c
->next
)
5589 insn
= emit_label_after (c
->label
, insn
);
5590 INSN_ADDRESSES_NEW (insn
, -1);
5592 insn
= emit_insn_after (s390_execute_target (c
->value
), insn
);
5593 INSN_ADDRESSES_NEW (insn
, -1);
5596 /* Switch back to previous section. */
5597 if (TARGET_CPU_ZARCH
)
5599 insn
= emit_insn_after (gen_pool_section_end (), insn
);
5600 INSN_ADDRESSES_NEW (insn
, -1);
5603 insn
= emit_barrier_after (insn
);
5604 INSN_ADDRESSES_NEW (insn
, -1);
5606 /* Remove placeholder insn. */
5607 remove_insn (pool
->pool_insn
);
5610 /* Free all memory used by POOL. */
5613 s390_free_pool (struct constant_pool
*pool
)
5615 struct constant
*c
, *next
;
5618 for (i
= 0; i
< NR_C_MODES
; i
++)
5619 for (c
= pool
->constants
[i
]; c
; c
= next
)
5625 for (c
= pool
->execute
; c
; c
= next
)
5631 BITMAP_FREE (pool
->insns
);
5636 /* Collect main literal pool. Return NULL on overflow. */
5638 static struct constant_pool
*
5639 s390_mainpool_start (void)
5641 struct constant_pool
*pool
;
5644 pool
= s390_alloc_pool ();
5646 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5648 if (GET_CODE (insn
) == INSN
5649 && GET_CODE (PATTERN (insn
)) == SET
5650 && GET_CODE (SET_SRC (PATTERN (insn
))) == UNSPEC_VOLATILE
5651 && XINT (SET_SRC (PATTERN (insn
)), 1) == UNSPECV_MAIN_POOL
)
5653 gcc_assert (!pool
->pool_insn
);
5654 pool
->pool_insn
= insn
;
5657 if (!TARGET_CPU_ZARCH
&& s390_execute_label (insn
))
5659 s390_add_execute (pool
, insn
);
5661 else if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
5663 rtx pool_ref
= NULL_RTX
;
5664 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
5667 rtx constant
= get_pool_constant (pool_ref
);
5668 enum machine_mode mode
= get_pool_mode (pool_ref
);
5669 s390_add_constant (pool
, constant
, mode
);
5674 gcc_assert (pool
->pool_insn
|| pool
->size
== 0);
5676 if (pool
->size
>= 4096)
5678 /* We're going to chunkify the pool, so remove the main
5679 pool placeholder insn. */
5680 remove_insn (pool
->pool_insn
);
5682 s390_free_pool (pool
);
5689 /* POOL holds the main literal pool as collected by s390_mainpool_start.
5690 Modify the current function to output the pool constants as well as
5691 the pool register setup instruction. */
5694 s390_mainpool_finish (struct constant_pool
*pool
)
5696 rtx base_reg
= cfun
->machine
->base_reg
;
5699 /* If the pool is empty, we're done. */
5700 if (pool
->size
== 0)
5702 /* We don't actually need a base register after all. */
5703 cfun
->machine
->base_reg
= NULL_RTX
;
5705 if (pool
->pool_insn
)
5706 remove_insn (pool
->pool_insn
);
5707 s390_free_pool (pool
);
5711 /* We need correct insn addresses. */
5712 shorten_branches (get_insns ());
5714 /* On zSeries, we use a LARL to load the pool register. The pool is
5715 located in the .rodata section, so we emit it after the function. */
5716 if (TARGET_CPU_ZARCH
)
5718 insn
= gen_main_base_64 (base_reg
, pool
->label
);
5719 insn
= emit_insn_after (insn
, pool
->pool_insn
);
5720 INSN_ADDRESSES_NEW (insn
, -1);
5721 remove_insn (pool
->pool_insn
);
5723 insn
= get_last_insn ();
5724 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
5725 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
5727 s390_dump_pool (pool
, 0);
5730 /* On S/390, if the total size of the function's code plus literal pool
5731 does not exceed 4096 bytes, we use BASR to set up a function base
5732 pointer, and emit the literal pool at the end of the function. */
5733 else if (INSN_ADDRESSES (INSN_UID (get_last_insn ()))
5734 + pool
->size
+ 8 /* alignment slop */ < 4096)
5736 insn
= gen_main_base_31_small (base_reg
, pool
->label
);
5737 insn
= emit_insn_after (insn
, pool
->pool_insn
);
5738 INSN_ADDRESSES_NEW (insn
, -1);
5739 remove_insn (pool
->pool_insn
);
5741 insn
= emit_label_after (pool
->label
, insn
);
5742 INSN_ADDRESSES_NEW (insn
, -1);
5744 insn
= get_last_insn ();
5745 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
5746 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
5748 s390_dump_pool (pool
, 1);
5751 /* Otherwise, we emit an inline literal pool and use BASR to branch
5752 over it, setting up the pool register at the same time. */
5755 rtx pool_end
= gen_label_rtx ();
5757 insn
= gen_main_base_31_large (base_reg
, pool
->label
, pool_end
);
5758 insn
= emit_insn_after (insn
, pool
->pool_insn
);
5759 INSN_ADDRESSES_NEW (insn
, -1);
5760 remove_insn (pool
->pool_insn
);
5762 insn
= emit_label_after (pool
->label
, insn
);
5763 INSN_ADDRESSES_NEW (insn
, -1);
5765 pool
->pool_insn
= emit_insn_after (gen_pool (const0_rtx
), insn
);
5766 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
5768 insn
= emit_label_after (pool_end
, pool
->pool_insn
);
5769 INSN_ADDRESSES_NEW (insn
, -1);
5771 s390_dump_pool (pool
, 1);
5775 /* Replace all literal pool references. */
5777 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5780 replace_ltrel_base (&PATTERN (insn
));
5782 if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
5784 rtx addr
, pool_ref
= NULL_RTX
;
5785 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
5788 if (s390_execute_label (insn
))
5789 addr
= s390_find_execute (pool
, insn
);
5791 addr
= s390_find_constant (pool
, get_pool_constant (pool_ref
),
5792 get_pool_mode (pool_ref
));
5794 replace_constant_pool_ref (&PATTERN (insn
), pool_ref
, addr
);
5795 INSN_CODE (insn
) = -1;
5801 /* Free the pool. */
5802 s390_free_pool (pool
);
5805 /* POOL holds the main literal pool as collected by s390_mainpool_start.
5806 We have decided we cannot use this pool, so revert all changes
5807 to the current function that were done by s390_mainpool_start. */
5809 s390_mainpool_cancel (struct constant_pool
*pool
)
5811 /* We didn't actually change the instruction stream, so simply
5812 free the pool memory. */
5813 s390_free_pool (pool
);
5817 /* Chunkify the literal pool. */
5819 #define S390_POOL_CHUNK_MIN 0xc00
5820 #define S390_POOL_CHUNK_MAX 0xe00
5822 static struct constant_pool
*
5823 s390_chunkify_start (void)
5825 struct constant_pool
*curr_pool
= NULL
, *pool_list
= NULL
;
5828 rtx pending_ltrel
= NULL_RTX
;
5831 rtx (*gen_reload_base
) (rtx
, rtx
) =
5832 TARGET_CPU_ZARCH
? gen_reload_base_64
: gen_reload_base_31
;
5835 /* We need correct insn addresses. */
5837 shorten_branches (get_insns ());
5839 /* Scan all insns and move literals to pool chunks. */
5841 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5843 /* Check for pending LTREL_BASE. */
5846 rtx ltrel_base
= find_ltrel_base (PATTERN (insn
));
5849 gcc_assert (ltrel_base
== pending_ltrel
);
5850 pending_ltrel
= NULL_RTX
;
5854 if (!TARGET_CPU_ZARCH
&& s390_execute_label (insn
))
5857 curr_pool
= s390_start_pool (&pool_list
, insn
);
5859 s390_add_execute (curr_pool
, insn
);
5860 s390_add_pool_insn (curr_pool
, insn
);
5862 else if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
5864 rtx pool_ref
= NULL_RTX
;
5865 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
5868 rtx constant
= get_pool_constant (pool_ref
);
5869 enum machine_mode mode
= get_pool_mode (pool_ref
);
5872 curr_pool
= s390_start_pool (&pool_list
, insn
);
5874 s390_add_constant (curr_pool
, constant
, mode
);
5875 s390_add_pool_insn (curr_pool
, insn
);
5877 /* Don't split the pool chunk between a LTREL_OFFSET load
5878 and the corresponding LTREL_BASE. */
5879 if (GET_CODE (constant
) == CONST
5880 && GET_CODE (XEXP (constant
, 0)) == UNSPEC
5881 && XINT (XEXP (constant
, 0), 1) == UNSPEC_LTREL_OFFSET
)
5883 gcc_assert (!pending_ltrel
);
5884 pending_ltrel
= pool_ref
;
5889 if (GET_CODE (insn
) == JUMP_INSN
|| GET_CODE (insn
) == CODE_LABEL
)
5892 s390_add_pool_insn (curr_pool
, insn
);
5893 /* An LTREL_BASE must follow within the same basic block. */
5894 gcc_assert (!pending_ltrel
);
5898 || INSN_ADDRESSES_SIZE () <= (size_t) INSN_UID (insn
)
5899 || INSN_ADDRESSES (INSN_UID (insn
)) == -1)
5902 if (TARGET_CPU_ZARCH
)
5904 if (curr_pool
->size
< S390_POOL_CHUNK_MAX
)
5907 s390_end_pool (curr_pool
, NULL_RTX
);
5912 int chunk_size
= INSN_ADDRESSES (INSN_UID (insn
))
5913 - INSN_ADDRESSES (INSN_UID (curr_pool
->first_insn
))
5916 /* We will later have to insert base register reload insns.
5917 Those will have an effect on code size, which we need to
5918 consider here. This calculation makes rather pessimistic
5919 worst-case assumptions. */
5920 if (GET_CODE (insn
) == CODE_LABEL
)
5923 if (chunk_size
< S390_POOL_CHUNK_MIN
5924 && curr_pool
->size
< S390_POOL_CHUNK_MIN
)
5927 /* Pool chunks can only be inserted after BARRIERs ... */
5928 if (GET_CODE (insn
) == BARRIER
)
5930 s390_end_pool (curr_pool
, insn
);
5935 /* ... so if we don't find one in time, create one. */
5936 else if ((chunk_size
> S390_POOL_CHUNK_MAX
5937 || curr_pool
->size
> S390_POOL_CHUNK_MAX
))
5939 rtx label
, jump
, barrier
;
5941 /* We can insert the barrier only after a 'real' insn. */
5942 if (GET_CODE (insn
) != INSN
&& GET_CODE (insn
) != CALL_INSN
)
5944 if (get_attr_length (insn
) == 0)
5947 /* Don't separate LTREL_BASE from the corresponding
5948 LTREL_OFFSET load. */
5952 label
= gen_label_rtx ();
5953 jump
= emit_jump_insn_after (gen_jump (label
), insn
);
5954 barrier
= emit_barrier_after (jump
);
5955 insn
= emit_label_after (label
, barrier
);
5956 JUMP_LABEL (jump
) = label
;
5957 LABEL_NUSES (label
) = 1;
5959 INSN_ADDRESSES_NEW (jump
, -1);
5960 INSN_ADDRESSES_NEW (barrier
, -1);
5961 INSN_ADDRESSES_NEW (insn
, -1);
5963 s390_end_pool (curr_pool
, barrier
);
5971 s390_end_pool (curr_pool
, NULL_RTX
);
5972 gcc_assert (!pending_ltrel
);
5974 /* Find all labels that are branched into
5975 from an insn belonging to a different chunk. */
5977 far_labels
= BITMAP_ALLOC (NULL
);
5979 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5981 /* Labels marked with LABEL_PRESERVE_P can be target
5982 of non-local jumps, so we have to mark them.
5983 The same holds for named labels.
5985 Don't do that, however, if it is the label before
5988 if (GET_CODE (insn
) == CODE_LABEL
5989 && (LABEL_PRESERVE_P (insn
) || LABEL_NAME (insn
)))
5991 rtx vec_insn
= next_real_insn (insn
);
5992 rtx vec_pat
= vec_insn
&& GET_CODE (vec_insn
) == JUMP_INSN
?
5993 PATTERN (vec_insn
) : NULL_RTX
;
5995 || !(GET_CODE (vec_pat
) == ADDR_VEC
5996 || GET_CODE (vec_pat
) == ADDR_DIFF_VEC
))
5997 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (insn
));
6000 /* If we have a direct jump (conditional or unconditional)
6001 or a casesi jump, check all potential targets. */
6002 else if (GET_CODE (insn
) == JUMP_INSN
)
6004 rtx pat
= PATTERN (insn
);
6005 if (GET_CODE (pat
) == PARALLEL
&& XVECLEN (pat
, 0) > 2)
6006 pat
= XVECEXP (pat
, 0, 0);
6008 if (GET_CODE (pat
) == SET
)
6010 rtx label
= JUMP_LABEL (insn
);
6013 if (s390_find_pool (pool_list
, label
)
6014 != s390_find_pool (pool_list
, insn
))
6015 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (label
));
6018 else if (GET_CODE (pat
) == PARALLEL
6019 && XVECLEN (pat
, 0) == 2
6020 && GET_CODE (XVECEXP (pat
, 0, 0)) == SET
6021 && GET_CODE (XVECEXP (pat
, 0, 1)) == USE
6022 && GET_CODE (XEXP (XVECEXP (pat
, 0, 1), 0)) == LABEL_REF
)
6024 /* Find the jump table used by this casesi jump. */
6025 rtx vec_label
= XEXP (XEXP (XVECEXP (pat
, 0, 1), 0), 0);
6026 rtx vec_insn
= next_real_insn (vec_label
);
6027 rtx vec_pat
= vec_insn
&& GET_CODE (vec_insn
) == JUMP_INSN
?
6028 PATTERN (vec_insn
) : NULL_RTX
;
6030 && (GET_CODE (vec_pat
) == ADDR_VEC
6031 || GET_CODE (vec_pat
) == ADDR_DIFF_VEC
))
6033 int i
, diff_p
= GET_CODE (vec_pat
) == ADDR_DIFF_VEC
;
6035 for (i
= 0; i
< XVECLEN (vec_pat
, diff_p
); i
++)
6037 rtx label
= XEXP (XVECEXP (vec_pat
, diff_p
, i
), 0);
6039 if (s390_find_pool (pool_list
, label
)
6040 != s390_find_pool (pool_list
, insn
))
6041 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (label
));
6048 /* Insert base register reload insns before every pool. */
6050 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
6052 rtx new_insn
= gen_reload_base (cfun
->machine
->base_reg
,
6054 rtx insn
= curr_pool
->first_insn
;
6055 INSN_ADDRESSES_NEW (emit_insn_before (new_insn
, insn
), -1);
6058 /* Insert base register reload insns at every far label. */
6060 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6061 if (GET_CODE (insn
) == CODE_LABEL
6062 && bitmap_bit_p (far_labels
, CODE_LABEL_NUMBER (insn
)))
6064 struct constant_pool
*pool
= s390_find_pool (pool_list
, insn
);
6067 rtx new_insn
= gen_reload_base (cfun
->machine
->base_reg
,
6069 INSN_ADDRESSES_NEW (emit_insn_after (new_insn
, insn
), -1);
6074 BITMAP_FREE (far_labels
);
6077 /* Recompute insn addresses. */
6079 init_insn_lengths ();
6080 shorten_branches (get_insns ());
6085 /* POOL_LIST is a chunk list as prepared by s390_chunkify_start.
6086 After we have decided to use this list, finish implementing
6087 all changes to the current function as required. */
6090 s390_chunkify_finish (struct constant_pool
*pool_list
)
6092 struct constant_pool
*curr_pool
= NULL
;
6096 /* Replace all literal pool references. */
6098 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6101 replace_ltrel_base (&PATTERN (insn
));
6103 curr_pool
= s390_find_pool (pool_list
, insn
);
6107 if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
6109 rtx addr
, pool_ref
= NULL_RTX
;
6110 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
6113 if (s390_execute_label (insn
))
6114 addr
= s390_find_execute (curr_pool
, insn
);
6116 addr
= s390_find_constant (curr_pool
,
6117 get_pool_constant (pool_ref
),
6118 get_pool_mode (pool_ref
));
6120 replace_constant_pool_ref (&PATTERN (insn
), pool_ref
, addr
);
6121 INSN_CODE (insn
) = -1;
6126 /* Dump out all literal pools. */
6128 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
6129 s390_dump_pool (curr_pool
, 0);
6131 /* Free pool list. */
6135 struct constant_pool
*next
= pool_list
->next
;
6136 s390_free_pool (pool_list
);
6141 /* POOL_LIST is a chunk list as prepared by s390_chunkify_start.
6142 We have decided we cannot use this list, so revert all changes
6143 to the current function that were done by s390_chunkify_start. */
6146 s390_chunkify_cancel (struct constant_pool
*pool_list
)
6148 struct constant_pool
*curr_pool
= NULL
;
6151 /* Remove all pool placeholder insns. */
6153 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
6155 /* Did we insert an extra barrier? Remove it. */
6156 rtx barrier
= PREV_INSN (curr_pool
->pool_insn
);
6157 rtx jump
= barrier
? PREV_INSN (barrier
) : NULL_RTX
;
6158 rtx label
= NEXT_INSN (curr_pool
->pool_insn
);
6160 if (jump
&& GET_CODE (jump
) == JUMP_INSN
6161 && barrier
&& GET_CODE (barrier
) == BARRIER
6162 && label
&& GET_CODE (label
) == CODE_LABEL
6163 && GET_CODE (PATTERN (jump
)) == SET
6164 && SET_DEST (PATTERN (jump
)) == pc_rtx
6165 && GET_CODE (SET_SRC (PATTERN (jump
))) == LABEL_REF
6166 && XEXP (SET_SRC (PATTERN (jump
)), 0) == label
)
6169 remove_insn (barrier
);
6170 remove_insn (label
);
6173 remove_insn (curr_pool
->pool_insn
);
6176 /* Remove all base register reload insns. */
6178 for (insn
= get_insns (); insn
; )
6180 rtx next_insn
= NEXT_INSN (insn
);
6182 if (GET_CODE (insn
) == INSN
6183 && GET_CODE (PATTERN (insn
)) == SET
6184 && GET_CODE (SET_SRC (PATTERN (insn
))) == UNSPEC
6185 && XINT (SET_SRC (PATTERN (insn
)), 1) == UNSPEC_RELOAD_BASE
)
6191 /* Free pool list. */
6195 struct constant_pool
*next
= pool_list
->next
;
6196 s390_free_pool (pool_list
);
6202 /* Output the constant pool entry EXP in mode MODE with alignment ALIGN. */
6205 s390_output_pool_entry (rtx exp
, enum machine_mode mode
, unsigned int align
)
6209 switch (GET_MODE_CLASS (mode
))
6212 gcc_assert (GET_CODE (exp
) == CONST_DOUBLE
);
6214 REAL_VALUE_FROM_CONST_DOUBLE (r
, exp
);
6215 assemble_real (r
, mode
, align
);
6219 assemble_integer (exp
, GET_MODE_SIZE (mode
), align
, 1);
6228 /* Return an RTL expression representing the value of the return address
6229 for the frame COUNT steps up from the current frame. FRAME is the
6230 frame pointer of that frame. */
6233 s390_return_addr_rtx (int count
, rtx frame ATTRIBUTE_UNUSED
)
6238 /* Without backchain, we fail for all but the current frame. */
6240 if (!TARGET_BACKCHAIN
&& count
> 0)
6243 /* For the current frame, we need to make sure the initial
6244 value of RETURN_REGNUM is actually saved. */
6248 /* On non-z architectures branch splitting could overwrite r14. */
6249 if (TARGET_CPU_ZARCH
)
6250 return get_hard_reg_initial_val (Pmode
, RETURN_REGNUM
);
6253 cfun_frame_layout
.save_return_addr_p
= true;
6254 return gen_rtx_MEM (Pmode
, return_address_pointer_rtx
);
6258 if (TARGET_PACKED_STACK
)
6259 offset
= -2 * UNITS_PER_WORD
;
6261 offset
= RETURN_REGNUM
* UNITS_PER_WORD
;
6263 addr
= plus_constant (frame
, offset
);
6264 addr
= memory_address (Pmode
, addr
);
6265 return gen_rtx_MEM (Pmode
, addr
);
6268 /* Return an RTL expression representing the back chain stored in
6269 the current stack frame. */
6272 s390_back_chain_rtx (void)
6276 gcc_assert (TARGET_BACKCHAIN
);
6278 if (TARGET_PACKED_STACK
)
6279 chain
= plus_constant (stack_pointer_rtx
,
6280 STACK_POINTER_OFFSET
- UNITS_PER_WORD
);
6282 chain
= stack_pointer_rtx
;
6284 chain
= gen_rtx_MEM (Pmode
, chain
);
6288 /* Find first call clobbered register unused in a function.
6289 This could be used as base register in a leaf function
6290 or for holding the return address before epilogue. */
6293 find_unused_clobbered_reg (void)
6296 for (i
= 0; i
< 6; i
++)
6297 if (!regs_ever_live
[i
])
6303 /* Helper function for s390_regs_ever_clobbered. Sets the fields in DATA for all
6304 clobbered hard regs in SETREG. */
6307 s390_reg_clobbered_rtx (rtx setreg
, rtx set_insn ATTRIBUTE_UNUSED
, void *data
)
6309 int *regs_ever_clobbered
= (int *)data
;
6310 unsigned int i
, regno
;
6311 enum machine_mode mode
= GET_MODE (setreg
);
6313 if (GET_CODE (setreg
) == SUBREG
)
6315 rtx inner
= SUBREG_REG (setreg
);
6316 if (!GENERAL_REG_P (inner
))
6318 regno
= subreg_regno (setreg
);
6320 else if (GENERAL_REG_P (setreg
))
6321 regno
= REGNO (setreg
);
6326 i
< regno
+ HARD_REGNO_NREGS (regno
, mode
);
6328 regs_ever_clobbered
[i
] = 1;
6331 /* Walks through all basic blocks of the current function looking
6332 for clobbered hard regs using s390_reg_clobbered_rtx. The fields
6333 of the passed integer array REGS_EVER_CLOBBERED are set to one for
6334 each of those regs. */
6337 s390_regs_ever_clobbered (int *regs_ever_clobbered
)
6343 memset (regs_ever_clobbered
, 0, 16 * sizeof (int));
6345 /* For non-leaf functions we have to consider all call clobbered regs to be
6347 if (!current_function_is_leaf
)
6349 for (i
= 0; i
< 16; i
++)
6350 regs_ever_clobbered
[i
] = call_really_used_regs
[i
];
6353 /* Make the "magic" eh_return registers live if necessary. For regs_ever_live
6354 this work is done by liveness analysis (mark_regs_live_at_end).
6355 Special care is needed for functions containing landing pads. Landing pads
6356 may use the eh registers, but the code which sets these registers is not
6357 contained in that function. Hence s390_regs_ever_clobbered is not able to
6358 deal with this automatically. */
6359 if (current_function_calls_eh_return
|| cfun
->machine
->has_landing_pad_p
)
6360 for (i
= 0; EH_RETURN_DATA_REGNO (i
) != INVALID_REGNUM
; i
++)
6361 if (current_function_calls_eh_return
6362 || (cfun
->machine
->has_landing_pad_p
6363 && regs_ever_live
[EH_RETURN_DATA_REGNO (i
)]))
6364 regs_ever_clobbered
[EH_RETURN_DATA_REGNO (i
)] = 1;
6366 /* For nonlocal gotos all call-saved registers have to be saved.
6367 This flag is also set for the unwinding code in libgcc.
6368 See expand_builtin_unwind_init. For regs_ever_live this is done by
6370 if (current_function_has_nonlocal_label
)
6371 for (i
= 0; i
< 16; i
++)
6372 if (!call_really_used_regs
[i
])
6373 regs_ever_clobbered
[i
] = 1;
6375 FOR_EACH_BB (cur_bb
)
6377 FOR_BB_INSNS (cur_bb
, cur_insn
)
6379 if (INSN_P (cur_insn
))
6380 note_stores (PATTERN (cur_insn
),
6381 s390_reg_clobbered_rtx
,
6382 regs_ever_clobbered
);
6387 /* Determine the frame area which actually has to be accessed
6388 in the function epilogue. The values are stored at the
6389 given pointers AREA_BOTTOM (address of the lowest used stack
6390 address) and AREA_TOP (address of the first item which does
6391 not belong to the stack frame). */
6394 s390_frame_area (int *area_bottom
, int *area_top
)
6402 if (cfun_frame_layout
.first_restore_gpr
!= -1)
6404 b
= (cfun_frame_layout
.gprs_offset
6405 + cfun_frame_layout
.first_restore_gpr
* UNITS_PER_WORD
);
6406 t
= b
+ (cfun_frame_layout
.last_restore_gpr
6407 - cfun_frame_layout
.first_restore_gpr
+ 1) * UNITS_PER_WORD
;
6410 if (TARGET_64BIT
&& cfun_save_high_fprs_p
)
6412 b
= MIN (b
, cfun_frame_layout
.f8_offset
);
6413 t
= MAX (t
, (cfun_frame_layout
.f8_offset
6414 + cfun_frame_layout
.high_fprs
* 8));
6418 for (i
= 2; i
< 4; i
++)
6419 if (cfun_fpr_bit_p (i
))
6421 b
= MIN (b
, cfun_frame_layout
.f4_offset
+ (i
- 2) * 8);
6422 t
= MAX (t
, cfun_frame_layout
.f4_offset
+ (i
- 1) * 8);
6429 /* Fill cfun->machine with info about register usage of current function.
6430 Return in CLOBBERED_REGS which GPRs are currently considered set. */
6433 s390_register_info (int clobbered_regs
[])
6437 /* fprs 8 - 15 are call saved for 64 Bit ABI. */
6438 cfun_frame_layout
.fpr_bitmap
= 0;
6439 cfun_frame_layout
.high_fprs
= 0;
6441 for (i
= 24; i
< 32; i
++)
6442 if (regs_ever_live
[i
] && !global_regs
[i
])
6444 cfun_set_fpr_bit (i
- 16);
6445 cfun_frame_layout
.high_fprs
++;
6448 /* Find first and last gpr to be saved. We trust regs_ever_live
6449 data, except that we don't save and restore global registers.
6451 Also, all registers with special meaning to the compiler need
6452 to be handled extra. */
6454 s390_regs_ever_clobbered (clobbered_regs
);
6456 for (i
= 0; i
< 16; i
++)
6457 clobbered_regs
[i
] = clobbered_regs
[i
] && !global_regs
[i
] && !fixed_regs
[i
];
6459 if (frame_pointer_needed
)
6460 clobbered_regs
[HARD_FRAME_POINTER_REGNUM
] = 1;
6463 clobbered_regs
[PIC_OFFSET_TABLE_REGNUM
]
6464 |= regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
];
6466 clobbered_regs
[BASE_REGNUM
]
6467 |= (cfun
->machine
->base_reg
6468 && REGNO (cfun
->machine
->base_reg
) == BASE_REGNUM
);
6470 clobbered_regs
[RETURN_REGNUM
]
6471 |= (!current_function_is_leaf
6472 || TARGET_TPF_PROFILING
6473 || cfun
->machine
->split_branches_pending_p
6474 || cfun_frame_layout
.save_return_addr_p
6475 || current_function_calls_eh_return
6476 || current_function_stdarg
);
6478 clobbered_regs
[STACK_POINTER_REGNUM
]
6479 |= (!current_function_is_leaf
6480 || TARGET_TPF_PROFILING
6481 || cfun_save_high_fprs_p
6482 || get_frame_size () > 0
6483 || current_function_calls_alloca
6484 || current_function_stdarg
);
6486 for (i
= 6; i
< 16; i
++)
6487 if (regs_ever_live
[i
] || clobbered_regs
[i
])
6489 for (j
= 15; j
> i
; j
--)
6490 if (regs_ever_live
[j
] || clobbered_regs
[j
])
6495 /* Nothing to save/restore. */
6496 cfun_frame_layout
.first_save_gpr_slot
= -1;
6497 cfun_frame_layout
.last_save_gpr_slot
= -1;
6498 cfun_frame_layout
.first_save_gpr
= -1;
6499 cfun_frame_layout
.first_restore_gpr
= -1;
6500 cfun_frame_layout
.last_save_gpr
= -1;
6501 cfun_frame_layout
.last_restore_gpr
= -1;
6505 /* Save slots for gprs from i to j. */
6506 cfun_frame_layout
.first_save_gpr_slot
= i
;
6507 cfun_frame_layout
.last_save_gpr_slot
= j
;
6509 for (i
= cfun_frame_layout
.first_save_gpr_slot
;
6510 i
< cfun_frame_layout
.last_save_gpr_slot
+ 1;
6512 if (clobbered_regs
[i
])
6515 for (j
= cfun_frame_layout
.last_save_gpr_slot
; j
> i
; j
--)
6516 if (clobbered_regs
[j
])
6519 if (i
== cfun_frame_layout
.last_save_gpr_slot
+ 1)
6521 /* Nothing to save/restore. */
6522 cfun_frame_layout
.first_save_gpr
= -1;
6523 cfun_frame_layout
.first_restore_gpr
= -1;
6524 cfun_frame_layout
.last_save_gpr
= -1;
6525 cfun_frame_layout
.last_restore_gpr
= -1;
6529 /* Save / Restore from gpr i to j. */
6530 cfun_frame_layout
.first_save_gpr
= i
;
6531 cfun_frame_layout
.first_restore_gpr
= i
;
6532 cfun_frame_layout
.last_save_gpr
= j
;
6533 cfun_frame_layout
.last_restore_gpr
= j
;
6537 if (current_function_stdarg
)
6539 /* Varargs functions need to save gprs 2 to 6. */
6540 if (cfun
->va_list_gpr_size
6541 && current_function_args_info
.gprs
< GP_ARG_NUM_REG
)
6543 int min_gpr
= current_function_args_info
.gprs
;
6544 int max_gpr
= min_gpr
+ cfun
->va_list_gpr_size
;
6545 if (max_gpr
> GP_ARG_NUM_REG
)
6546 max_gpr
= GP_ARG_NUM_REG
;
6548 if (cfun_frame_layout
.first_save_gpr
== -1
6549 || cfun_frame_layout
.first_save_gpr
> 2 + min_gpr
)
6551 cfun_frame_layout
.first_save_gpr
= 2 + min_gpr
;
6552 cfun_frame_layout
.first_save_gpr_slot
= 2 + min_gpr
;
6555 if (cfun_frame_layout
.last_save_gpr
== -1
6556 || cfun_frame_layout
.last_save_gpr
< 2 + max_gpr
- 1)
6558 cfun_frame_layout
.last_save_gpr
= 2 + max_gpr
- 1;
6559 cfun_frame_layout
.last_save_gpr_slot
= 2 + max_gpr
- 1;
6563 /* Mark f0, f2 for 31 bit and f0-f4 for 64 bit to be saved. */
6564 if (TARGET_HARD_FLOAT
&& cfun
->va_list_fpr_size
6565 && current_function_args_info
.fprs
< FP_ARG_NUM_REG
)
6567 int min_fpr
= current_function_args_info
.fprs
;
6568 int max_fpr
= min_fpr
+ cfun
->va_list_fpr_size
;
6569 if (max_fpr
> FP_ARG_NUM_REG
)
6570 max_fpr
= FP_ARG_NUM_REG
;
6572 /* ??? This is currently required to ensure proper location
6573 of the fpr save slots within the va_list save area. */
6574 if (TARGET_PACKED_STACK
)
6577 for (i
= min_fpr
; i
< max_fpr
; i
++)
6578 cfun_set_fpr_bit (i
);
6583 for (i
= 2; i
< 4; i
++)
6584 if (regs_ever_live
[i
+ 16] && !global_regs
[i
+ 16])
6585 cfun_set_fpr_bit (i
);
6588 /* Fill cfun->machine with info about frame of current function. */
6591 s390_frame_info (void)
6595 cfun_frame_layout
.frame_size
= get_frame_size ();
6596 if (!TARGET_64BIT
&& cfun_frame_layout
.frame_size
> 0x7fff0000)
6597 fatal_error ("total size of local variables exceeds architecture limit");
6599 if (!TARGET_PACKED_STACK
)
6601 cfun_frame_layout
.backchain_offset
= 0;
6602 cfun_frame_layout
.f0_offset
= 16 * UNITS_PER_WORD
;
6603 cfun_frame_layout
.f4_offset
= cfun_frame_layout
.f0_offset
+ 2 * 8;
6604 cfun_frame_layout
.f8_offset
= -cfun_frame_layout
.high_fprs
* 8;
6605 cfun_frame_layout
.gprs_offset
= (cfun_frame_layout
.first_save_gpr_slot
6608 else if (TARGET_BACKCHAIN
) /* kernel stack layout */
6610 cfun_frame_layout
.backchain_offset
= (STACK_POINTER_OFFSET
6612 cfun_frame_layout
.gprs_offset
6613 = (cfun_frame_layout
.backchain_offset
6614 - (STACK_POINTER_REGNUM
- cfun_frame_layout
.first_save_gpr_slot
+ 1)
6619 cfun_frame_layout
.f4_offset
6620 = (cfun_frame_layout
.gprs_offset
6621 - 8 * (cfun_fpr_bit_p (2) + cfun_fpr_bit_p (3)));
6623 cfun_frame_layout
.f0_offset
6624 = (cfun_frame_layout
.f4_offset
6625 - 8 * (cfun_fpr_bit_p (0) + cfun_fpr_bit_p (1)));
6629 /* On 31 bit we have to care about alignment of the
6630 floating point regs to provide fastest access. */
6631 cfun_frame_layout
.f0_offset
6632 = ((cfun_frame_layout
.gprs_offset
6633 & ~(STACK_BOUNDARY
/ BITS_PER_UNIT
- 1))
6634 - 8 * (cfun_fpr_bit_p (0) + cfun_fpr_bit_p (1)));
6636 cfun_frame_layout
.f4_offset
6637 = (cfun_frame_layout
.f0_offset
6638 - 8 * (cfun_fpr_bit_p (2) + cfun_fpr_bit_p (3)));
6641 else /* no backchain */
6643 cfun_frame_layout
.f4_offset
6644 = (STACK_POINTER_OFFSET
6645 - 8 * (cfun_fpr_bit_p (2) + cfun_fpr_bit_p (3)));
6647 cfun_frame_layout
.f0_offset
6648 = (cfun_frame_layout
.f4_offset
6649 - 8 * (cfun_fpr_bit_p (0) + cfun_fpr_bit_p (1)));
6651 cfun_frame_layout
.gprs_offset
6652 = cfun_frame_layout
.f0_offset
- cfun_gprs_save_area_size
;
6655 if (current_function_is_leaf
6656 && !TARGET_TPF_PROFILING
6657 && cfun_frame_layout
.frame_size
== 0
6658 && !cfun_save_high_fprs_p
6659 && !current_function_calls_alloca
6660 && !current_function_stdarg
)
6663 if (!TARGET_PACKED_STACK
)
6664 cfun_frame_layout
.frame_size
+= (STACK_POINTER_OFFSET
6665 + current_function_outgoing_args_size
6666 + cfun_frame_layout
.high_fprs
* 8);
6669 if (TARGET_BACKCHAIN
)
6670 cfun_frame_layout
.frame_size
+= UNITS_PER_WORD
;
6672 /* No alignment trouble here because f8-f15 are only saved under
6674 cfun_frame_layout
.f8_offset
= (MIN (MIN (cfun_frame_layout
.f0_offset
,
6675 cfun_frame_layout
.f4_offset
),
6676 cfun_frame_layout
.gprs_offset
)
6677 - cfun_frame_layout
.high_fprs
* 8);
6679 cfun_frame_layout
.frame_size
+= cfun_frame_layout
.high_fprs
* 8;
6681 for (i
= 0; i
< 8; i
++)
6682 if (cfun_fpr_bit_p (i
))
6683 cfun_frame_layout
.frame_size
+= 8;
6685 cfun_frame_layout
.frame_size
+= cfun_gprs_save_area_size
;
6687 /* If under 31 bit an odd number of gprs has to be saved we have to adjust
6688 the frame size to sustain 8 byte alignment of stack frames. */
6689 cfun_frame_layout
.frame_size
= ((cfun_frame_layout
.frame_size
+
6690 STACK_BOUNDARY
/ BITS_PER_UNIT
- 1)
6691 & ~(STACK_BOUNDARY
/ BITS_PER_UNIT
- 1));
6693 cfun_frame_layout
.frame_size
+= current_function_outgoing_args_size
;
6697 /* Generate frame layout. Fills in register and frame data for the current
6698 function in cfun->machine. This routine can be called multiple times;
6699 it will re-do the complete frame layout every time. */
6702 s390_init_frame_layout (void)
6704 HOST_WIDE_INT frame_size
;
6706 int clobbered_regs
[16];
6708 /* On S/390 machines, we may need to perform branch splitting, which
6709 will require both base and return address register. We have no
6710 choice but to assume we're going to need them until right at the
6711 end of the machine dependent reorg phase. */
6712 if (!TARGET_CPU_ZARCH
)
6713 cfun
->machine
->split_branches_pending_p
= true;
6717 frame_size
= cfun_frame_layout
.frame_size
;
6719 /* Try to predict whether we'll need the base register. */
6720 base_used
= cfun
->machine
->split_branches_pending_p
6721 || current_function_uses_const_pool
6722 || (!DISP_IN_RANGE (frame_size
)
6723 && !CONST_OK_FOR_K (frame_size
));
6725 /* Decide which register to use as literal pool base. In small
6726 leaf functions, try to use an unused call-clobbered register
6727 as base register to avoid save/restore overhead. */
6729 cfun
->machine
->base_reg
= NULL_RTX
;
6730 else if (current_function_is_leaf
&& !regs_ever_live
[5])
6731 cfun
->machine
->base_reg
= gen_rtx_REG (Pmode
, 5);
6733 cfun
->machine
->base_reg
= gen_rtx_REG (Pmode
, BASE_REGNUM
);
6735 s390_register_info (clobbered_regs
);
6738 while (frame_size
!= cfun_frame_layout
.frame_size
);
6741 /* Update frame layout. Recompute actual register save data based on
6742 current info and update regs_ever_live for the special registers.
6743 May be called multiple times, but may never cause *more* registers
6744 to be saved than s390_init_frame_layout allocated room for. */
6747 s390_update_frame_layout (void)
6749 int clobbered_regs
[16];
6751 s390_register_info (clobbered_regs
);
6753 regs_ever_live
[BASE_REGNUM
] = clobbered_regs
[BASE_REGNUM
];
6754 regs_ever_live
[RETURN_REGNUM
] = clobbered_regs
[RETURN_REGNUM
];
6755 regs_ever_live
[STACK_POINTER_REGNUM
] = clobbered_regs
[STACK_POINTER_REGNUM
];
6757 if (cfun
->machine
->base_reg
)
6758 regs_ever_live
[REGNO (cfun
->machine
->base_reg
)] = 1;
6761 /* Return nonzero if register OLD_REG can be renamed to register NEW_REG. */
6764 s390_hard_regno_rename_ok (unsigned int old_reg
, unsigned int new_reg
)
6766 /* Once we've decided upon a register to use as base register, it must
6767 no longer be used for any other purpose. */
6768 if (cfun
->machine
->base_reg
)
6769 if (REGNO (cfun
->machine
->base_reg
) == old_reg
6770 || REGNO (cfun
->machine
->base_reg
) == new_reg
)
6776 /* Return true if register FROM can be eliminated via register TO. */
6779 s390_can_eliminate (int from
, int to
)
6781 /* On zSeries machines, we have not marked the base register as fixed.
6782 Instead, we have an elimination rule BASE_REGNUM -> BASE_REGNUM.
6783 If a function requires the base register, we say here that this
6784 elimination cannot be performed. This will cause reload to free
6785 up the base register (as if it were fixed). On the other hand,
6786 if the current function does *not* require the base register, we
6787 say here the elimination succeeds, which in turn allows reload
6788 to allocate the base register for any other purpose. */
6789 if (from
== BASE_REGNUM
&& to
== BASE_REGNUM
)
6791 if (TARGET_CPU_ZARCH
)
6793 s390_init_frame_layout ();
6794 return cfun
->machine
->base_reg
== NULL_RTX
;
6800 /* Everything else must point into the stack frame. */
6801 gcc_assert (to
== STACK_POINTER_REGNUM
6802 || to
== HARD_FRAME_POINTER_REGNUM
);
6804 gcc_assert (from
== FRAME_POINTER_REGNUM
6805 || from
== ARG_POINTER_REGNUM
6806 || from
== RETURN_ADDRESS_POINTER_REGNUM
);
6808 /* Make sure we actually saved the return address. */
6809 if (from
== RETURN_ADDRESS_POINTER_REGNUM
)
6810 if (!current_function_calls_eh_return
6811 && !current_function_stdarg
6812 && !cfun_frame_layout
.save_return_addr_p
)
6818 /* Return offset between register FROM and TO initially after prolog. */
6821 s390_initial_elimination_offset (int from
, int to
)
6823 HOST_WIDE_INT offset
;
6826 /* ??? Why are we called for non-eliminable pairs? */
6827 if (!s390_can_eliminate (from
, to
))
6832 case FRAME_POINTER_REGNUM
:
6833 offset
= (get_frame_size()
6834 + STACK_POINTER_OFFSET
6835 + current_function_outgoing_args_size
);
6838 case ARG_POINTER_REGNUM
:
6839 s390_init_frame_layout ();
6840 offset
= cfun_frame_layout
.frame_size
+ STACK_POINTER_OFFSET
;
6843 case RETURN_ADDRESS_POINTER_REGNUM
:
6844 s390_init_frame_layout ();
6845 index
= RETURN_REGNUM
- cfun_frame_layout
.first_save_gpr_slot
;
6846 gcc_assert (index
>= 0);
6847 offset
= cfun_frame_layout
.frame_size
+ cfun_frame_layout
.gprs_offset
;
6848 offset
+= index
* UNITS_PER_WORD
;
6862 /* Emit insn to save fpr REGNUM at offset OFFSET relative
6863 to register BASE. Return generated insn. */
6866 save_fpr (rtx base
, int offset
, int regnum
)
6869 addr
= gen_rtx_MEM (DFmode
, plus_constant (base
, offset
));
6871 if (regnum
>= 16 && regnum
<= (16 + FP_ARG_NUM_REG
))
6872 set_mem_alias_set (addr
, get_varargs_alias_set ());
6874 set_mem_alias_set (addr
, get_frame_alias_set ());
6876 return emit_move_insn (addr
, gen_rtx_REG (DFmode
, regnum
));
6879 /* Emit insn to restore fpr REGNUM from offset OFFSET relative
6880 to register BASE. Return generated insn. */
6883 restore_fpr (rtx base
, int offset
, int regnum
)
6886 addr
= gen_rtx_MEM (DFmode
, plus_constant (base
, offset
));
6887 set_mem_alias_set (addr
, get_frame_alias_set ());
6889 return emit_move_insn (gen_rtx_REG (DFmode
, regnum
), addr
);
6892 /* Generate insn to save registers FIRST to LAST into
6893 the register save area located at offset OFFSET
6894 relative to register BASE. */
6897 save_gprs (rtx base
, int offset
, int first
, int last
)
6899 rtx addr
, insn
, note
;
6902 addr
= plus_constant (base
, offset
);
6903 addr
= gen_rtx_MEM (Pmode
, addr
);
6905 set_mem_alias_set (addr
, get_frame_alias_set ());
6907 /* Special-case single register. */
6911 insn
= gen_movdi (addr
, gen_rtx_REG (Pmode
, first
));
6913 insn
= gen_movsi (addr
, gen_rtx_REG (Pmode
, first
));
6915 RTX_FRAME_RELATED_P (insn
) = 1;
6920 insn
= gen_store_multiple (addr
,
6921 gen_rtx_REG (Pmode
, first
),
6922 GEN_INT (last
- first
+ 1));
6924 if (first
<= 6 && current_function_stdarg
)
6925 for (i
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
6927 rtx mem
= XEXP (XVECEXP (PATTERN (insn
), 0, i
), 0);
6930 set_mem_alias_set (mem
, get_varargs_alias_set ());
6933 /* We need to set the FRAME_RELATED flag on all SETs
6934 inside the store-multiple pattern.
6936 However, we must not emit DWARF records for registers 2..5
6937 if they are stored for use by variable arguments ...
6939 ??? Unfortunately, it is not enough to simply not the
6940 FRAME_RELATED flags for those SETs, because the first SET
6941 of the PARALLEL is always treated as if it had the flag
6942 set, even if it does not. Therefore we emit a new pattern
6943 without those registers as REG_FRAME_RELATED_EXPR note. */
6947 rtx pat
= PATTERN (insn
);
6949 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
6950 if (GET_CODE (XVECEXP (pat
, 0, i
)) == SET
)
6951 RTX_FRAME_RELATED_P (XVECEXP (pat
, 0, i
)) = 1;
6953 RTX_FRAME_RELATED_P (insn
) = 1;
6957 addr
= plus_constant (base
, offset
+ (6 - first
) * UNITS_PER_WORD
);
6958 note
= gen_store_multiple (gen_rtx_MEM (Pmode
, addr
),
6959 gen_rtx_REG (Pmode
, 6),
6960 GEN_INT (last
- 6 + 1));
6961 note
= PATTERN (note
);
6964 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR
,
6965 note
, REG_NOTES (insn
));
6967 for (i
= 0; i
< XVECLEN (note
, 0); i
++)
6968 if (GET_CODE (XVECEXP (note
, 0, i
)) == SET
)
6969 RTX_FRAME_RELATED_P (XVECEXP (note
, 0, i
)) = 1;
6971 RTX_FRAME_RELATED_P (insn
) = 1;
6977 /* Generate insn to restore registers FIRST to LAST from
6978 the register save area located at offset OFFSET
6979 relative to register BASE. */
6982 restore_gprs (rtx base
, int offset
, int first
, int last
)
6986 addr
= plus_constant (base
, offset
);
6987 addr
= gen_rtx_MEM (Pmode
, addr
);
6988 set_mem_alias_set (addr
, get_frame_alias_set ());
6990 /* Special-case single register. */
6994 insn
= gen_movdi (gen_rtx_REG (Pmode
, first
), addr
);
6996 insn
= gen_movsi (gen_rtx_REG (Pmode
, first
), addr
);
7001 insn
= gen_load_multiple (gen_rtx_REG (Pmode
, first
),
7003 GEN_INT (last
- first
+ 1));
7007 /* Return insn sequence to load the GOT register. */
7009 static GTY(()) rtx got_symbol
;
7011 s390_load_got (void)
7017 got_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "_GLOBAL_OFFSET_TABLE_");
7018 SYMBOL_REF_FLAGS (got_symbol
) = SYMBOL_FLAG_LOCAL
;
7023 if (TARGET_CPU_ZARCH
)
7025 emit_move_insn (pic_offset_table_rtx
, got_symbol
);
7031 offset
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, got_symbol
),
7032 UNSPEC_LTREL_OFFSET
);
7033 offset
= gen_rtx_CONST (Pmode
, offset
);
7034 offset
= force_const_mem (Pmode
, offset
);
7036 emit_move_insn (pic_offset_table_rtx
, offset
);
7038 offset
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, XEXP (offset
, 0)),
7040 offset
= gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, offset
);
7042 emit_move_insn (pic_offset_table_rtx
, offset
);
7045 insns
= get_insns ();
7050 /* Expand the prologue into a bunch of separate insns. */
7053 s390_emit_prologue (void)
7061 /* Complete frame layout. */
7063 s390_update_frame_layout ();
7065 /* Annotate all constant pool references to let the scheduler know
7066 they implicitly use the base register. */
7068 push_topmost_sequence ();
7070 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
7072 annotate_constant_pool_refs (&PATTERN (insn
));
7074 pop_topmost_sequence ();
7076 /* Choose best register to use for temp use within prologue.
7077 See below for why TPF must use the register 1. */
7079 if (!has_hard_reg_initial_val (Pmode
, RETURN_REGNUM
)
7080 && !current_function_is_leaf
7081 && !TARGET_TPF_PROFILING
)
7082 temp_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
7084 temp_reg
= gen_rtx_REG (Pmode
, 1);
7086 /* Save call saved gprs. */
7087 if (cfun_frame_layout
.first_save_gpr
!= -1)
7089 insn
= save_gprs (stack_pointer_rtx
,
7090 cfun_frame_layout
.gprs_offset
+
7091 UNITS_PER_WORD
* (cfun_frame_layout
.first_save_gpr
7092 - cfun_frame_layout
.first_save_gpr_slot
),
7093 cfun_frame_layout
.first_save_gpr
,
7094 cfun_frame_layout
.last_save_gpr
);
7098 /* Dummy insn to mark literal pool slot. */
7100 if (cfun
->machine
->base_reg
)
7101 emit_insn (gen_main_pool (cfun
->machine
->base_reg
));
7103 offset
= cfun_frame_layout
.f0_offset
;
7105 /* Save f0 and f2. */
7106 for (i
= 0; i
< 2; i
++)
7108 if (cfun_fpr_bit_p (i
))
7110 save_fpr (stack_pointer_rtx
, offset
, i
+ 16);
7113 else if (!TARGET_PACKED_STACK
)
7117 /* Save f4 and f6. */
7118 offset
= cfun_frame_layout
.f4_offset
;
7119 for (i
= 2; i
< 4; i
++)
7121 if (cfun_fpr_bit_p (i
))
7123 insn
= save_fpr (stack_pointer_rtx
, offset
, i
+ 16);
7126 /* If f4 and f6 are call clobbered they are saved due to stdargs and
7127 therefore are not frame related. */
7128 if (!call_really_used_regs
[i
+ 16])
7129 RTX_FRAME_RELATED_P (insn
) = 1;
7131 else if (!TARGET_PACKED_STACK
)
7135 if (TARGET_PACKED_STACK
7136 && cfun_save_high_fprs_p
7137 && cfun_frame_layout
.f8_offset
+ cfun_frame_layout
.high_fprs
* 8 > 0)
7139 offset
= (cfun_frame_layout
.f8_offset
7140 + (cfun_frame_layout
.high_fprs
- 1) * 8);
7142 for (i
= 15; i
> 7 && offset
>= 0; i
--)
7143 if (cfun_fpr_bit_p (i
))
7145 insn
= save_fpr (stack_pointer_rtx
, offset
, i
+ 16);
7147 RTX_FRAME_RELATED_P (insn
) = 1;
7150 if (offset
>= cfun_frame_layout
.f8_offset
)
7154 if (!TARGET_PACKED_STACK
)
7155 next_fpr
= cfun_save_high_fprs_p
? 31 : 0;
7157 /* Decrement stack pointer. */
7159 if (cfun_frame_layout
.frame_size
> 0)
7161 rtx frame_off
= GEN_INT (-cfun_frame_layout
.frame_size
);
7163 if (s390_stack_size
)
7165 HOST_WIDE_INT stack_check_mask
= ((s390_stack_size
- 1)
7166 & ~(s390_stack_guard
- 1));
7167 rtx t
= gen_rtx_AND (Pmode
, stack_pointer_rtx
,
7168 GEN_INT (stack_check_mask
));
7171 gen_cmpdi (t
, const0_rtx
);
7173 gen_cmpsi (t
, const0_rtx
);
7175 emit_insn (gen_conditional_trap (gen_rtx_EQ (CCmode
,
7176 gen_rtx_REG (CCmode
,
7182 if (s390_warn_framesize
> 0
7183 && cfun_frame_layout
.frame_size
>= s390_warn_framesize
)
7184 warning (0, "frame size of %qs is " HOST_WIDE_INT_PRINT_DEC
" bytes",
7185 current_function_name (), cfun_frame_layout
.frame_size
);
7187 if (s390_warn_dynamicstack_p
&& cfun
->calls_alloca
)
7188 warning (0, "%qs uses dynamic stack allocation", current_function_name ());
7190 /* Save incoming stack pointer into temp reg. */
7191 if (TARGET_BACKCHAIN
|| next_fpr
)
7192 insn
= emit_insn (gen_move_insn (temp_reg
, stack_pointer_rtx
));
7194 /* Subtract frame size from stack pointer. */
7196 if (DISP_IN_RANGE (INTVAL (frame_off
)))
7198 insn
= gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
7199 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
7201 insn
= emit_insn (insn
);
7205 if (!CONST_OK_FOR_K (INTVAL (frame_off
)))
7206 frame_off
= force_const_mem (Pmode
, frame_off
);
7208 insn
= emit_insn (gen_add2_insn (stack_pointer_rtx
, frame_off
));
7209 annotate_constant_pool_refs (&PATTERN (insn
));
7212 RTX_FRAME_RELATED_P (insn
) = 1;
7214 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR
,
7215 gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
7216 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
7217 GEN_INT (-cfun_frame_layout
.frame_size
))),
7220 /* Set backchain. */
7222 if (TARGET_BACKCHAIN
)
7224 if (cfun_frame_layout
.backchain_offset
)
7225 addr
= gen_rtx_MEM (Pmode
,
7226 plus_constant (stack_pointer_rtx
,
7227 cfun_frame_layout
.backchain_offset
));
7229 addr
= gen_rtx_MEM (Pmode
, stack_pointer_rtx
);
7230 set_mem_alias_set (addr
, get_frame_alias_set ());
7231 insn
= emit_insn (gen_move_insn (addr
, temp_reg
));
7234 /* If we support asynchronous exceptions (e.g. for Java),
7235 we need to make sure the backchain pointer is set up
7236 before any possibly trapping memory access. */
7238 if (TARGET_BACKCHAIN
&& flag_non_call_exceptions
)
7240 addr
= gen_rtx_MEM (BLKmode
, gen_rtx_SCRATCH (VOIDmode
));
7241 emit_insn (gen_rtx_CLOBBER (VOIDmode
, addr
));
7245 /* Save fprs 8 - 15 (64 bit ABI). */
7247 if (cfun_save_high_fprs_p
&& next_fpr
)
7249 insn
= emit_insn (gen_add2_insn (temp_reg
,
7250 GEN_INT (cfun_frame_layout
.f8_offset
)));
7254 for (i
= 24; i
<= next_fpr
; i
++)
7255 if (cfun_fpr_bit_p (i
- 16))
7257 rtx addr
= plus_constant (stack_pointer_rtx
,
7258 cfun_frame_layout
.frame_size
7259 + cfun_frame_layout
.f8_offset
7262 insn
= save_fpr (temp_reg
, offset
, i
);
7264 RTX_FRAME_RELATED_P (insn
) = 1;
7266 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR
,
7267 gen_rtx_SET (VOIDmode
,
7268 gen_rtx_MEM (DFmode
, addr
),
7269 gen_rtx_REG (DFmode
, i
)),
7274 /* Set frame pointer, if needed. */
7276 if (frame_pointer_needed
)
7278 insn
= emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
);
7279 RTX_FRAME_RELATED_P (insn
) = 1;
7282 /* Set up got pointer, if needed. */
7284 if (flag_pic
&& regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
])
7286 rtx insns
= s390_load_got ();
7288 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
7290 annotate_constant_pool_refs (&PATTERN (insn
));
7292 REG_NOTES (insn
) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD
, NULL_RTX
,
7299 if (TARGET_TPF_PROFILING
)
7301 /* Generate a BAS instruction to serve as a function
7302 entry intercept to facilitate the use of tracing
7303 algorithms located at the branch target. */
7304 emit_insn (gen_prologue_tpf ());
7306 /* Emit a blockage here so that all code
7307 lies between the profiling mechanisms. */
7308 emit_insn (gen_blockage ());
7312 /* Expand the epilogue into a bunch of separate insns. */
7315 s390_emit_epilogue (bool sibcall
)
7317 rtx frame_pointer
, return_reg
;
7318 int area_bottom
, area_top
, offset
= 0;
7323 if (TARGET_TPF_PROFILING
)
7326 /* Generate a BAS instruction to serve as a function
7327 entry intercept to facilitate the use of tracing
7328 algorithms located at the branch target. */
7330 /* Emit a blockage here so that all code
7331 lies between the profiling mechanisms. */
7332 emit_insn (gen_blockage ());
7334 emit_insn (gen_epilogue_tpf ());
7337 /* Check whether to use frame or stack pointer for restore. */
7339 frame_pointer
= (frame_pointer_needed
7340 ? hard_frame_pointer_rtx
: stack_pointer_rtx
);
7342 s390_frame_area (&area_bottom
, &area_top
);
7344 /* Check whether we can access the register save area.
7345 If not, increment the frame pointer as required. */
7347 if (area_top
<= area_bottom
)
7349 /* Nothing to restore. */
7351 else if (DISP_IN_RANGE (cfun_frame_layout
.frame_size
+ area_bottom
)
7352 && DISP_IN_RANGE (cfun_frame_layout
.frame_size
+ area_top
- 1))
7354 /* Area is in range. */
7355 offset
= cfun_frame_layout
.frame_size
;
7359 rtx insn
, frame_off
;
7361 offset
= area_bottom
< 0 ? -area_bottom
: 0;
7362 frame_off
= GEN_INT (cfun_frame_layout
.frame_size
- offset
);
7364 if (DISP_IN_RANGE (INTVAL (frame_off
)))
7366 insn
= gen_rtx_SET (VOIDmode
, frame_pointer
,
7367 gen_rtx_PLUS (Pmode
, frame_pointer
, frame_off
));
7368 insn
= emit_insn (insn
);
7372 if (!CONST_OK_FOR_K (INTVAL (frame_off
)))
7373 frame_off
= force_const_mem (Pmode
, frame_off
);
7375 insn
= emit_insn (gen_add2_insn (frame_pointer
, frame_off
));
7376 annotate_constant_pool_refs (&PATTERN (insn
));
7380 /* Restore call saved fprs. */
7384 if (cfun_save_high_fprs_p
)
7386 next_offset
= cfun_frame_layout
.f8_offset
;
7387 for (i
= 24; i
< 32; i
++)
7389 if (cfun_fpr_bit_p (i
- 16))
7391 restore_fpr (frame_pointer
,
7392 offset
+ next_offset
, i
);
7401 next_offset
= cfun_frame_layout
.f4_offset
;
7402 for (i
= 18; i
< 20; i
++)
7404 if (cfun_fpr_bit_p (i
- 16))
7406 restore_fpr (frame_pointer
,
7407 offset
+ next_offset
, i
);
7410 else if (!TARGET_PACKED_STACK
)
7416 /* Return register. */
7418 return_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
7420 /* Restore call saved gprs. */
7422 if (cfun_frame_layout
.first_restore_gpr
!= -1)
7427 /* Check for global register and save them
7428 to stack location from where they get restored. */
7430 for (i
= cfun_frame_layout
.first_restore_gpr
;
7431 i
<= cfun_frame_layout
.last_restore_gpr
;
7434 /* These registers are special and need to be
7435 restored in any case. */
7436 if (i
== STACK_POINTER_REGNUM
7437 || i
== RETURN_REGNUM
7439 || (flag_pic
&& i
== (int)PIC_OFFSET_TABLE_REGNUM
))
7444 addr
= plus_constant (frame_pointer
,
7445 offset
+ cfun_frame_layout
.gprs_offset
7446 + (i
- cfun_frame_layout
.first_save_gpr_slot
)
7448 addr
= gen_rtx_MEM (Pmode
, addr
);
7449 set_mem_alias_set (addr
, get_frame_alias_set ());
7450 emit_move_insn (addr
, gen_rtx_REG (Pmode
, i
));
7456 /* Fetch return address from stack before load multiple,
7457 this will do good for scheduling. */
7459 if (cfun_frame_layout
.save_return_addr_p
7460 || (cfun_frame_layout
.first_restore_gpr
< BASE_REGNUM
7461 && cfun_frame_layout
.last_restore_gpr
> RETURN_REGNUM
))
7463 int return_regnum
= find_unused_clobbered_reg();
7466 return_reg
= gen_rtx_REG (Pmode
, return_regnum
);
7468 addr
= plus_constant (frame_pointer
,
7469 offset
+ cfun_frame_layout
.gprs_offset
7471 - cfun_frame_layout
.first_save_gpr_slot
)
7473 addr
= gen_rtx_MEM (Pmode
, addr
);
7474 set_mem_alias_set (addr
, get_frame_alias_set ());
7475 emit_move_insn (return_reg
, addr
);
7479 insn
= restore_gprs (frame_pointer
,
7480 offset
+ cfun_frame_layout
.gprs_offset
7481 + (cfun_frame_layout
.first_restore_gpr
7482 - cfun_frame_layout
.first_save_gpr_slot
)
7484 cfun_frame_layout
.first_restore_gpr
,
7485 cfun_frame_layout
.last_restore_gpr
);
7492 /* Return to caller. */
7494 p
= rtvec_alloc (2);
7496 RTVEC_ELT (p
, 0) = gen_rtx_RETURN (VOIDmode
);
7497 RTVEC_ELT (p
, 1) = gen_rtx_USE (VOIDmode
, return_reg
);
7498 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
7503 /* Return the size in bytes of a function argument of
7504 type TYPE and/or mode MODE. At least one of TYPE or
7505 MODE must be specified. */
7508 s390_function_arg_size (enum machine_mode mode
, tree type
)
7511 return int_size_in_bytes (type
);
7513 /* No type info available for some library calls ... */
7514 if (mode
!= BLKmode
)
7515 return GET_MODE_SIZE (mode
);
7517 /* If we have neither type nor mode, abort */
7521 /* Return true if a function argument of type TYPE and mode MODE
7522 is to be passed in a floating-point register, if available. */
7525 s390_function_arg_float (enum machine_mode mode
, tree type
)
7527 int size
= s390_function_arg_size (mode
, type
);
7531 /* Soft-float changes the ABI: no floating-point registers are used. */
7532 if (TARGET_SOFT_FLOAT
)
7535 /* No type info available for some library calls ... */
7537 return mode
== SFmode
|| mode
== DFmode
;
7539 /* The ABI says that record types with a single member are treated
7540 just like that member would be. */
7541 while (TREE_CODE (type
) == RECORD_TYPE
)
7543 tree field
, single
= NULL_TREE
;
7545 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
7547 if (TREE_CODE (field
) != FIELD_DECL
)
7550 if (single
== NULL_TREE
)
7551 single
= TREE_TYPE (field
);
7556 if (single
== NULL_TREE
)
7562 return TREE_CODE (type
) == REAL_TYPE
;
7565 /* Return true if a function argument of type TYPE and mode MODE
7566 is to be passed in an integer register, or a pair of integer
7567 registers, if available. */
7570 s390_function_arg_integer (enum machine_mode mode
, tree type
)
7572 int size
= s390_function_arg_size (mode
, type
);
7576 /* No type info available for some library calls ... */
7578 return GET_MODE_CLASS (mode
) == MODE_INT
7579 || (TARGET_SOFT_FLOAT
&& GET_MODE_CLASS (mode
) == MODE_FLOAT
);
7581 /* We accept small integral (and similar) types. */
7582 if (INTEGRAL_TYPE_P (type
)
7583 || POINTER_TYPE_P (type
)
7584 || TREE_CODE (type
) == OFFSET_TYPE
7585 || (TARGET_SOFT_FLOAT
&& TREE_CODE (type
) == REAL_TYPE
))
7588 /* We also accept structs of size 1, 2, 4, 8 that are not
7589 passed in floating-point registers. */
7590 if (AGGREGATE_TYPE_P (type
)
7591 && exact_log2 (size
) >= 0
7592 && !s390_function_arg_float (mode
, type
))
7598 /* Return 1 if a function argument of type TYPE and mode MODE
7599 is to be passed by reference. The ABI specifies that only
7600 structures of size 1, 2, 4, or 8 bytes are passed by value,
7601 all other structures (and complex numbers) are passed by
7605 s390_pass_by_reference (CUMULATIVE_ARGS
*ca ATTRIBUTE_UNUSED
,
7606 enum machine_mode mode
, tree type
,
7607 bool named ATTRIBUTE_UNUSED
)
7609 int size
= s390_function_arg_size (mode
, type
);
7615 if (AGGREGATE_TYPE_P (type
) && exact_log2 (size
) < 0)
7618 if (TREE_CODE (type
) == COMPLEX_TYPE
7619 || TREE_CODE (type
) == VECTOR_TYPE
)
7626 /* Update the data in CUM to advance over an argument of mode MODE and
7627 data type TYPE. (TYPE is null for libcalls where that information
7628 may not be available.). The boolean NAMED specifies whether the
7629 argument is a named argument (as opposed to an unnamed argument
7630 matching an ellipsis). */
7633 s390_function_arg_advance (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
,
7634 tree type
, int named ATTRIBUTE_UNUSED
)
7636 if (s390_function_arg_float (mode
, type
))
7640 else if (s390_function_arg_integer (mode
, type
))
7642 int size
= s390_function_arg_size (mode
, type
);
7643 cum
->gprs
+= ((size
+ UNITS_PER_WORD
-1) / UNITS_PER_WORD
);
7649 /* Define where to put the arguments to a function.
7650 Value is zero to push the argument on the stack,
7651 or a hard register in which to store the argument.
7653 MODE is the argument's machine mode.
7654 TYPE is the data type of the argument (as a tree).
7655 This is null for libcalls where that information may
7657 CUM is a variable of type CUMULATIVE_ARGS which gives info about
7658 the preceding args and about the function being called.
7659 NAMED is nonzero if this argument is a named parameter
7660 (otherwise it is an extra parameter matching an ellipsis).
7662 On S/390, we use general purpose registers 2 through 6 to
7663 pass integer, pointer, and certain structure arguments, and
7664 floating point registers 0 and 2 (0, 2, 4, and 6 on 64-bit)
7665 to pass floating point arguments. All remaining arguments
7666 are pushed to the stack. */
7669 s390_function_arg (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
, tree type
,
7670 int named ATTRIBUTE_UNUSED
)
7672 if (s390_function_arg_float (mode
, type
))
7674 if (cum
->fprs
+ 1 > FP_ARG_NUM_REG
)
7677 return gen_rtx_REG (mode
, cum
->fprs
+ 16);
7679 else if (s390_function_arg_integer (mode
, type
))
7681 int size
= s390_function_arg_size (mode
, type
);
7682 int n_gprs
= (size
+ UNITS_PER_WORD
-1) / UNITS_PER_WORD
;
7684 if (cum
->gprs
+ n_gprs
> GP_ARG_NUM_REG
)
7687 return gen_rtx_REG (mode
, cum
->gprs
+ 2);
7690 /* After the real arguments, expand_call calls us once again
7691 with a void_type_node type. Whatever we return here is
7692 passed as operand 2 to the call expanders.
7694 We don't need this feature ... */
7695 else if (type
== void_type_node
)
7701 /* Return true if return values of type TYPE should be returned
7702 in a memory buffer whose address is passed by the caller as
7703 hidden first argument. */
7706 s390_return_in_memory (tree type
, tree fundecl ATTRIBUTE_UNUSED
)
7708 /* We accept small integral (and similar) types. */
7709 if (INTEGRAL_TYPE_P (type
)
7710 || POINTER_TYPE_P (type
)
7711 || TREE_CODE (type
) == OFFSET_TYPE
7712 || TREE_CODE (type
) == REAL_TYPE
)
7713 return int_size_in_bytes (type
) > 8;
7715 /* Aggregates and similar constructs are always returned
7717 if (AGGREGATE_TYPE_P (type
)
7718 || TREE_CODE (type
) == COMPLEX_TYPE
7719 || TREE_CODE (type
) == VECTOR_TYPE
)
7722 /* ??? We get called on all sorts of random stuff from
7723 aggregate_value_p. We can't abort, but it's not clear
7724 what's safe to return. Pretend it's a struct I guess. */
7728 /* Define where to return a (scalar) value of type TYPE.
7729 If TYPE is null, define where to return a (scalar)
7730 value of mode MODE from a libcall. */
7733 s390_function_value (tree type
, enum machine_mode mode
)
7737 int unsignedp
= TYPE_UNSIGNED (type
);
7738 mode
= promote_mode (type
, TYPE_MODE (type
), &unsignedp
, 1);
7741 gcc_assert (GET_MODE_CLASS (mode
) == MODE_INT
7742 || GET_MODE_CLASS (mode
) == MODE_FLOAT
);
7743 gcc_assert (GET_MODE_SIZE (mode
) <= 8);
7745 if (TARGET_HARD_FLOAT
&& GET_MODE_CLASS (mode
) == MODE_FLOAT
)
7746 return gen_rtx_REG (mode
, 16);
7748 return gen_rtx_REG (mode
, 2);
7752 /* Create and return the va_list datatype.
7754 On S/390, va_list is an array type equivalent to
7756 typedef struct __va_list_tag
7760 void *__overflow_arg_area;
7761 void *__reg_save_area;
7764 where __gpr and __fpr hold the number of general purpose
7765 or floating point arguments used up to now, respectively,
7766 __overflow_arg_area points to the stack location of the
7767 next argument passed on the stack, and __reg_save_area
7768 always points to the start of the register area in the
7769 call frame of the current function. The function prologue
7770 saves all registers used for argument passing into this
7771 area if the function uses variable arguments. */
7774 s390_build_builtin_va_list (void)
7776 tree f_gpr
, f_fpr
, f_ovf
, f_sav
, record
, type_decl
;
7778 record
= lang_hooks
.types
.make_type (RECORD_TYPE
);
7781 build_decl (TYPE_DECL
, get_identifier ("__va_list_tag"), record
);
7783 f_gpr
= build_decl (FIELD_DECL
, get_identifier ("__gpr"),
7784 long_integer_type_node
);
7785 f_fpr
= build_decl (FIELD_DECL
, get_identifier ("__fpr"),
7786 long_integer_type_node
);
7787 f_ovf
= build_decl (FIELD_DECL
, get_identifier ("__overflow_arg_area"),
7789 f_sav
= build_decl (FIELD_DECL
, get_identifier ("__reg_save_area"),
7792 va_list_gpr_counter_field
= f_gpr
;
7793 va_list_fpr_counter_field
= f_fpr
;
7795 DECL_FIELD_CONTEXT (f_gpr
) = record
;
7796 DECL_FIELD_CONTEXT (f_fpr
) = record
;
7797 DECL_FIELD_CONTEXT (f_ovf
) = record
;
7798 DECL_FIELD_CONTEXT (f_sav
) = record
;
7800 TREE_CHAIN (record
) = type_decl
;
7801 TYPE_NAME (record
) = type_decl
;
7802 TYPE_FIELDS (record
) = f_gpr
;
7803 TREE_CHAIN (f_gpr
) = f_fpr
;
7804 TREE_CHAIN (f_fpr
) = f_ovf
;
7805 TREE_CHAIN (f_ovf
) = f_sav
;
7807 layout_type (record
);
7809 /* The correct type is an array type of one element. */
7810 return build_array_type (record
, build_index_type (size_zero_node
));
7813 /* Implement va_start by filling the va_list structure VALIST.
7814 STDARG_P is always true, and ignored.
7815 NEXTARG points to the first anonymous stack argument.
7817 The following global variables are used to initialize
7818 the va_list structure:
7820 current_function_args_info:
7821 holds number of gprs and fprs used for named arguments.
7822 current_function_arg_offset_rtx:
7823 holds the offset of the first anonymous stack argument
7824 (relative to the virtual arg pointer). */
7827 s390_va_start (tree valist
, rtx nextarg ATTRIBUTE_UNUSED
)
7829 HOST_WIDE_INT n_gpr
, n_fpr
;
7831 tree f_gpr
, f_fpr
, f_ovf
, f_sav
;
7832 tree gpr
, fpr
, ovf
, sav
, t
;
7834 f_gpr
= TYPE_FIELDS (TREE_TYPE (va_list_type_node
));
7835 f_fpr
= TREE_CHAIN (f_gpr
);
7836 f_ovf
= TREE_CHAIN (f_fpr
);
7837 f_sav
= TREE_CHAIN (f_ovf
);
7839 valist
= build_va_arg_indirect_ref (valist
);
7840 gpr
= build (COMPONENT_REF
, TREE_TYPE (f_gpr
), valist
, f_gpr
, NULL_TREE
);
7841 fpr
= build (COMPONENT_REF
, TREE_TYPE (f_fpr
), valist
, f_fpr
, NULL_TREE
);
7842 ovf
= build (COMPONENT_REF
, TREE_TYPE (f_ovf
), valist
, f_ovf
, NULL_TREE
);
7843 sav
= build (COMPONENT_REF
, TREE_TYPE (f_sav
), valist
, f_sav
, NULL_TREE
);
7845 /* Count number of gp and fp argument registers used. */
7847 n_gpr
= current_function_args_info
.gprs
;
7848 n_fpr
= current_function_args_info
.fprs
;
7850 if (cfun
->va_list_gpr_size
)
7852 t
= build (MODIFY_EXPR
, TREE_TYPE (gpr
), gpr
,
7853 build_int_cst (NULL_TREE
, n_gpr
));
7854 TREE_SIDE_EFFECTS (t
) = 1;
7855 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
7858 if (cfun
->va_list_fpr_size
)
7860 t
= build (MODIFY_EXPR
, TREE_TYPE (fpr
), fpr
,
7861 build_int_cst (NULL_TREE
, n_fpr
));
7862 TREE_SIDE_EFFECTS (t
) = 1;
7863 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
7866 /* Find the overflow area. */
7867 if (n_gpr
+ cfun
->va_list_gpr_size
> GP_ARG_NUM_REG
7868 || n_fpr
+ cfun
->va_list_fpr_size
> FP_ARG_NUM_REG
)
7870 t
= make_tree (TREE_TYPE (ovf
), virtual_incoming_args_rtx
);
7872 off
= INTVAL (current_function_arg_offset_rtx
);
7873 off
= off
< 0 ? 0 : off
;
7874 if (TARGET_DEBUG_ARG
)
7875 fprintf (stderr
, "va_start: n_gpr = %d, n_fpr = %d off %d\n",
7876 (int)n_gpr
, (int)n_fpr
, off
);
7878 t
= build (PLUS_EXPR
, TREE_TYPE (ovf
), t
, build_int_cst (NULL_TREE
, off
));
7880 t
= build (MODIFY_EXPR
, TREE_TYPE (ovf
), ovf
, t
);
7881 TREE_SIDE_EFFECTS (t
) = 1;
7882 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
7885 /* Find the register save area. */
7886 if ((cfun
->va_list_gpr_size
&& n_gpr
< GP_ARG_NUM_REG
)
7887 || (cfun
->va_list_fpr_size
&& n_fpr
< FP_ARG_NUM_REG
))
7889 t
= make_tree (TREE_TYPE (sav
), return_address_pointer_rtx
);
7890 t
= build (PLUS_EXPR
, TREE_TYPE (sav
), t
,
7891 build_int_cst (NULL_TREE
, -RETURN_REGNUM
* UNITS_PER_WORD
));
7893 t
= build (MODIFY_EXPR
, TREE_TYPE (sav
), sav
, t
);
7894 TREE_SIDE_EFFECTS (t
) = 1;
7895 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
7899 /* Implement va_arg by updating the va_list structure
7900 VALIST as required to retrieve an argument of type
7901 TYPE, and returning that argument.
7903 Generates code equivalent to:
7905 if (integral value) {
7906 if (size <= 4 && args.gpr < 5 ||
7907 size > 4 && args.gpr < 4 )
7908 ret = args.reg_save_area[args.gpr+8]
7910 ret = *args.overflow_arg_area++;
7911 } else if (float value) {
7913 ret = args.reg_save_area[args.fpr+64]
7915 ret = *args.overflow_arg_area++;
7916 } else if (aggregate value) {
7918 ret = *args.reg_save_area[args.gpr]
7920 ret = **args.overflow_arg_area++;
7924 s390_gimplify_va_arg (tree valist
, tree type
, tree
*pre_p
,
7925 tree
*post_p ATTRIBUTE_UNUSED
)
7927 tree f_gpr
, f_fpr
, f_ovf
, f_sav
;
7928 tree gpr
, fpr
, ovf
, sav
, reg
, t
, u
;
7929 int indirect_p
, size
, n_reg
, sav_ofs
, sav_scale
, max_reg
;
7930 tree lab_false
, lab_over
, addr
;
7932 f_gpr
= TYPE_FIELDS (TREE_TYPE (va_list_type_node
));
7933 f_fpr
= TREE_CHAIN (f_gpr
);
7934 f_ovf
= TREE_CHAIN (f_fpr
);
7935 f_sav
= TREE_CHAIN (f_ovf
);
7937 valist
= build_va_arg_indirect_ref (valist
);
7938 gpr
= build (COMPONENT_REF
, TREE_TYPE (f_gpr
), valist
, f_gpr
, NULL_TREE
);
7939 fpr
= build (COMPONENT_REF
, TREE_TYPE (f_fpr
), valist
, f_fpr
, NULL_TREE
);
7940 ovf
= build (COMPONENT_REF
, TREE_TYPE (f_ovf
), valist
, f_ovf
, NULL_TREE
);
7941 sav
= build (COMPONENT_REF
, TREE_TYPE (f_sav
), valist
, f_sav
, NULL_TREE
);
7943 size
= int_size_in_bytes (type
);
7945 if (pass_by_reference (NULL
, TYPE_MODE (type
), type
, false))
7947 if (TARGET_DEBUG_ARG
)
7949 fprintf (stderr
, "va_arg: aggregate type");
7953 /* Aggregates are passed by reference. */
7958 /* kernel stack layout on 31 bit: It is assumed here that no padding
7959 will be added by s390_frame_info because for va_args always an even
7960 number of gprs has to be saved r15-r2 = 14 regs. */
7961 sav_ofs
= 2 * UNITS_PER_WORD
;
7962 sav_scale
= UNITS_PER_WORD
;
7963 size
= UNITS_PER_WORD
;
7964 max_reg
= GP_ARG_NUM_REG
- n_reg
;
7966 else if (s390_function_arg_float (TYPE_MODE (type
), type
))
7968 if (TARGET_DEBUG_ARG
)
7970 fprintf (stderr
, "va_arg: float type");
7974 /* FP args go in FP registers, if present. */
7978 sav_ofs
= 16 * UNITS_PER_WORD
;
7980 max_reg
= FP_ARG_NUM_REG
- n_reg
;
7984 if (TARGET_DEBUG_ARG
)
7986 fprintf (stderr
, "va_arg: other type");
7990 /* Otherwise into GP registers. */
7993 n_reg
= (size
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
7995 /* kernel stack layout on 31 bit: It is assumed here that no padding
7996 will be added by s390_frame_info because for va_args always an even
7997 number of gprs has to be saved r15-r2 = 14 regs. */
7998 sav_ofs
= 2 * UNITS_PER_WORD
;
8000 if (size
< UNITS_PER_WORD
)
8001 sav_ofs
+= UNITS_PER_WORD
- size
;
8003 sav_scale
= UNITS_PER_WORD
;
8004 max_reg
= GP_ARG_NUM_REG
- n_reg
;
8007 /* Pull the value out of the saved registers ... */
8009 lab_false
= create_artificial_label ();
8010 lab_over
= create_artificial_label ();
8011 addr
= create_tmp_var (ptr_type_node
, "addr");
8012 DECL_POINTER_ALIAS_SET (addr
) = get_varargs_alias_set ();
8014 t
= fold_convert (TREE_TYPE (reg
), size_int (max_reg
));
8015 t
= build2 (GT_EXPR
, boolean_type_node
, reg
, t
);
8016 u
= build1 (GOTO_EXPR
, void_type_node
, lab_false
);
8017 t
= build3 (COND_EXPR
, void_type_node
, t
, u
, NULL_TREE
);
8018 gimplify_and_add (t
, pre_p
);
8020 t
= build2 (PLUS_EXPR
, ptr_type_node
, sav
,
8021 fold_convert (ptr_type_node
, size_int (sav_ofs
)));
8022 u
= build2 (MULT_EXPR
, TREE_TYPE (reg
), reg
,
8023 fold_convert (TREE_TYPE (reg
), size_int (sav_scale
)));
8024 t
= build2 (PLUS_EXPR
, ptr_type_node
, t
, fold_convert (ptr_type_node
, u
));
8026 t
= build2 (MODIFY_EXPR
, void_type_node
, addr
, t
);
8027 gimplify_and_add (t
, pre_p
);
8029 t
= build1 (GOTO_EXPR
, void_type_node
, lab_over
);
8030 gimplify_and_add (t
, pre_p
);
8032 t
= build1 (LABEL_EXPR
, void_type_node
, lab_false
);
8033 append_to_statement_list (t
, pre_p
);
8036 /* ... Otherwise out of the overflow area. */
8039 if (size
< UNITS_PER_WORD
)
8040 t
= build2 (PLUS_EXPR
, ptr_type_node
, t
,
8041 fold_convert (ptr_type_node
, size_int (UNITS_PER_WORD
- size
)));
8043 gimplify_expr (&t
, pre_p
, NULL
, is_gimple_val
, fb_rvalue
);
8045 u
= build2 (MODIFY_EXPR
, void_type_node
, addr
, t
);
8046 gimplify_and_add (u
, pre_p
);
8048 t
= build2 (PLUS_EXPR
, ptr_type_node
, t
,
8049 fold_convert (ptr_type_node
, size_int (size
)));
8050 t
= build2 (MODIFY_EXPR
, ptr_type_node
, ovf
, t
);
8051 gimplify_and_add (t
, pre_p
);
8053 t
= build1 (LABEL_EXPR
, void_type_node
, lab_over
);
8054 append_to_statement_list (t
, pre_p
);
8057 /* Increment register save count. */
8059 u
= build2 (PREINCREMENT_EXPR
, TREE_TYPE (reg
), reg
,
8060 fold_convert (TREE_TYPE (reg
), size_int (n_reg
)));
8061 gimplify_and_add (u
, pre_p
);
8065 t
= build_pointer_type (build_pointer_type (type
));
8066 addr
= fold_convert (t
, addr
);
8067 addr
= build_va_arg_indirect_ref (addr
);
8071 t
= build_pointer_type (type
);
8072 addr
= fold_convert (t
, addr
);
8075 return build_va_arg_indirect_ref (addr
);
8083 S390_BUILTIN_THREAD_POINTER
,
8084 S390_BUILTIN_SET_THREAD_POINTER
,
8089 static unsigned int const code_for_builtin_64
[S390_BUILTIN_max
] = {
8094 static unsigned int const code_for_builtin_31
[S390_BUILTIN_max
] = {
8100 s390_init_builtins (void)
8104 ftype
= build_function_type (ptr_type_node
, void_list_node
);
8105 lang_hooks
.builtin_function ("__builtin_thread_pointer", ftype
,
8106 S390_BUILTIN_THREAD_POINTER
, BUILT_IN_MD
,
8109 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
8110 lang_hooks
.builtin_function ("__builtin_set_thread_pointer", ftype
,
8111 S390_BUILTIN_SET_THREAD_POINTER
, BUILT_IN_MD
,
8115 /* Expand an expression EXP that calls a built-in function,
8116 with result going to TARGET if that's convenient
8117 (and in mode MODE if that's convenient).
8118 SUBTARGET may be used as the target for computing one of EXP's operands.
8119 IGNORE is nonzero if the value is to be ignored. */
8122 s390_expand_builtin (tree exp
, rtx target
, rtx subtarget ATTRIBUTE_UNUSED
,
8123 enum machine_mode mode ATTRIBUTE_UNUSED
,
8124 int ignore ATTRIBUTE_UNUSED
)
8128 unsigned int const *code_for_builtin
=
8129 TARGET_64BIT
? code_for_builtin_64
: code_for_builtin_31
;
8131 tree fndecl
= TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
8132 unsigned int fcode
= DECL_FUNCTION_CODE (fndecl
);
8133 tree arglist
= TREE_OPERAND (exp
, 1);
8134 enum insn_code icode
;
8135 rtx op
[MAX_ARGS
], pat
;
8139 if (fcode
>= S390_BUILTIN_max
)
8140 internal_error ("bad builtin fcode");
8141 icode
= code_for_builtin
[fcode
];
8143 internal_error ("bad builtin fcode");
8145 nonvoid
= TREE_TYPE (TREE_TYPE (fndecl
)) != void_type_node
;
8147 for (arglist
= TREE_OPERAND (exp
, 1), arity
= 0;
8149 arglist
= TREE_CHAIN (arglist
), arity
++)
8151 const struct insn_operand_data
*insn_op
;
8153 tree arg
= TREE_VALUE (arglist
);
8154 if (arg
== error_mark_node
)
8156 if (arity
> MAX_ARGS
)
8159 insn_op
= &insn_data
[icode
].operand
[arity
+ nonvoid
];
8161 op
[arity
] = expand_expr (arg
, NULL_RTX
, insn_op
->mode
, 0);
8163 if (!(*insn_op
->predicate
) (op
[arity
], insn_op
->mode
))
8164 op
[arity
] = copy_to_mode_reg (insn_op
->mode
, op
[arity
]);
8169 enum machine_mode tmode
= insn_data
[icode
].operand
[0].mode
;
8171 || GET_MODE (target
) != tmode
8172 || !(*insn_data
[icode
].operand
[0].predicate
) (target
, tmode
))
8173 target
= gen_reg_rtx (tmode
);
8179 pat
= GEN_FCN (icode
) (target
);
8183 pat
= GEN_FCN (icode
) (target
, op
[0]);
8185 pat
= GEN_FCN (icode
) (op
[0]);
8188 pat
= GEN_FCN (icode
) (target
, op
[0], op
[1]);
8204 /* Output assembly code for the trampoline template to
8207 On S/390, we use gpr 1 internally in the trampoline code;
8208 gpr 0 is used to hold the static chain. */
8211 s390_trampoline_template (FILE *file
)
8214 op
[0] = gen_rtx_REG (Pmode
, 0);
8215 op
[1] = gen_rtx_REG (Pmode
, 1);
8219 output_asm_insn ("basr\t%1,0", op
);
8220 output_asm_insn ("lmg\t%0,%1,14(%1)", op
);
8221 output_asm_insn ("br\t%1", op
);
8222 ASM_OUTPUT_SKIP (file
, (HOST_WIDE_INT
)(TRAMPOLINE_SIZE
- 10));
8226 output_asm_insn ("basr\t%1,0", op
);
8227 output_asm_insn ("lm\t%0,%1,6(%1)", op
);
8228 output_asm_insn ("br\t%1", op
);
8229 ASM_OUTPUT_SKIP (file
, (HOST_WIDE_INT
)(TRAMPOLINE_SIZE
- 8));
8233 /* Emit RTL insns to initialize the variable parts of a trampoline.
8234 FNADDR is an RTX for the address of the function's pure code.
8235 CXT is an RTX for the static chain value for the function. */
8238 s390_initialize_trampoline (rtx addr
, rtx fnaddr
, rtx cxt
)
8240 emit_move_insn (gen_rtx_MEM (Pmode
,
8241 memory_address (Pmode
,
8242 plus_constant (addr
, (TARGET_64BIT
? 16 : 8)))), cxt
);
8243 emit_move_insn (gen_rtx_MEM (Pmode
,
8244 memory_address (Pmode
,
8245 plus_constant (addr
, (TARGET_64BIT
? 24 : 12)))), fnaddr
);
8248 /* Return rtx for 64-bit constant formed from the 32-bit subwords
8249 LOW and HIGH, independent of the host word size. */
8252 s390_gen_rtx_const_DI (int high
, int low
)
8254 #if HOST_BITS_PER_WIDE_INT >= 64
8256 val
= (HOST_WIDE_INT
)high
;
8258 val
|= (HOST_WIDE_INT
)low
;
8260 return GEN_INT (val
);
8262 #if HOST_BITS_PER_WIDE_INT >= 32
8263 return immed_double_const ((HOST_WIDE_INT
)low
, (HOST_WIDE_INT
)high
, DImode
);
8270 /* Output assembler code to FILE to increment profiler label # LABELNO
8271 for profiling a function entry. */
8274 s390_function_profiler (FILE *file
, int labelno
)
8279 ASM_GENERATE_INTERNAL_LABEL (label
, "LP", labelno
);
8281 fprintf (file
, "# function profiler \n");
8283 op
[0] = gen_rtx_REG (Pmode
, RETURN_REGNUM
);
8284 op
[1] = gen_rtx_REG (Pmode
, STACK_POINTER_REGNUM
);
8285 op
[1] = gen_rtx_MEM (Pmode
, plus_constant (op
[1], UNITS_PER_WORD
));
8287 op
[2] = gen_rtx_REG (Pmode
, 1);
8288 op
[3] = gen_rtx_SYMBOL_REF (Pmode
, label
);
8289 SYMBOL_REF_FLAGS (op
[3]) = SYMBOL_FLAG_LOCAL
;
8291 op
[4] = gen_rtx_SYMBOL_REF (Pmode
, "_mcount");
8294 op
[4] = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op
[4]), UNSPEC_PLT
);
8295 op
[4] = gen_rtx_CONST (Pmode
, op
[4]);
8300 output_asm_insn ("stg\t%0,%1", op
);
8301 output_asm_insn ("larl\t%2,%3", op
);
8302 output_asm_insn ("brasl\t%0,%4", op
);
8303 output_asm_insn ("lg\t%0,%1", op
);
8307 op
[6] = gen_label_rtx ();
8309 output_asm_insn ("st\t%0,%1", op
);
8310 output_asm_insn ("bras\t%2,%l6", op
);
8311 output_asm_insn (".long\t%4", op
);
8312 output_asm_insn (".long\t%3", op
);
8313 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[6]));
8314 output_asm_insn ("l\t%0,0(%2)", op
);
8315 output_asm_insn ("l\t%2,4(%2)", op
);
8316 output_asm_insn ("basr\t%0,%0", op
);
8317 output_asm_insn ("l\t%0,%1", op
);
8321 op
[5] = gen_label_rtx ();
8322 op
[6] = gen_label_rtx ();
8324 output_asm_insn ("st\t%0,%1", op
);
8325 output_asm_insn ("bras\t%2,%l6", op
);
8326 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[5]));
8327 output_asm_insn (".long\t%4-%l5", op
);
8328 output_asm_insn (".long\t%3-%l5", op
);
8329 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[6]));
8330 output_asm_insn ("lr\t%0,%2", op
);
8331 output_asm_insn ("a\t%0,0(%2)", op
);
8332 output_asm_insn ("a\t%2,4(%2)", op
);
8333 output_asm_insn ("basr\t%0,%0", op
);
8334 output_asm_insn ("l\t%0,%1", op
);
8338 /* Encode symbol attributes (local vs. global, tls model) of a SYMBOL_REF
8339 into its SYMBOL_REF_FLAGS. */
8342 s390_encode_section_info (tree decl
, rtx rtl
, int first
)
8344 default_encode_section_info (decl
, rtl
, first
);
8346 /* If a variable has a forced alignment to < 2 bytes, mark it with
8347 SYMBOL_FLAG_ALIGN1 to prevent it from being used as LARL operand. */
8348 if (TREE_CODE (decl
) == VAR_DECL
8349 && DECL_USER_ALIGN (decl
) && DECL_ALIGN (decl
) < 16)
8350 SYMBOL_REF_FLAGS (XEXP (rtl
, 0)) |= SYMBOL_FLAG_ALIGN1
;
8353 /* Output thunk to FILE that implements a C++ virtual function call (with
8354 multiple inheritance) to FUNCTION. The thunk adjusts the this pointer
8355 by DELTA, and unless VCALL_OFFSET is zero, applies an additional adjustment
8356 stored at VCALL_OFFSET in the vtable whose address is located at offset 0
8357 relative to the resulting this pointer. */
8360 s390_output_mi_thunk (FILE *file
, tree thunk ATTRIBUTE_UNUSED
,
8361 HOST_WIDE_INT delta
, HOST_WIDE_INT vcall_offset
,
8367 /* Operand 0 is the target function. */
8368 op
[0] = XEXP (DECL_RTL (function
), 0);
8369 if (flag_pic
&& !SYMBOL_REF_LOCAL_P (op
[0]))
8372 op
[0] = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op
[0]),
8373 TARGET_64BIT
? UNSPEC_PLT
: UNSPEC_GOT
);
8374 op
[0] = gen_rtx_CONST (Pmode
, op
[0]);
8377 /* Operand 1 is the 'this' pointer. */
8378 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function
)), function
))
8379 op
[1] = gen_rtx_REG (Pmode
, 3);
8381 op
[1] = gen_rtx_REG (Pmode
, 2);
8383 /* Operand 2 is the delta. */
8384 op
[2] = GEN_INT (delta
);
8386 /* Operand 3 is the vcall_offset. */
8387 op
[3] = GEN_INT (vcall_offset
);
8389 /* Operand 4 is the temporary register. */
8390 op
[4] = gen_rtx_REG (Pmode
, 1);
8392 /* Operands 5 to 8 can be used as labels. */
8398 /* Operand 9 can be used for temporary register. */
8401 /* Generate code. */
8404 /* Setup literal pool pointer if required. */
8405 if ((!DISP_IN_RANGE (delta
)
8406 && !CONST_OK_FOR_K (delta
)
8407 && !CONST_OK_FOR_Os (delta
))
8408 || (!DISP_IN_RANGE (vcall_offset
)
8409 && !CONST_OK_FOR_K (vcall_offset
)
8410 && !CONST_OK_FOR_Os (vcall_offset
)))
8412 op
[5] = gen_label_rtx ();
8413 output_asm_insn ("larl\t%4,%5", op
);
8416 /* Add DELTA to this pointer. */
8419 if (CONST_OK_FOR_J (delta
))
8420 output_asm_insn ("la\t%1,%2(%1)", op
);
8421 else if (DISP_IN_RANGE (delta
))
8422 output_asm_insn ("lay\t%1,%2(%1)", op
);
8423 else if (CONST_OK_FOR_K (delta
))
8424 output_asm_insn ("aghi\t%1,%2", op
);
8425 else if (CONST_OK_FOR_Os (delta
))
8426 output_asm_insn ("agfi\t%1,%2", op
);
8429 op
[6] = gen_label_rtx ();
8430 output_asm_insn ("agf\t%1,%6-%5(%4)", op
);
8434 /* Perform vcall adjustment. */
8437 if (DISP_IN_RANGE (vcall_offset
))
8439 output_asm_insn ("lg\t%4,0(%1)", op
);
8440 output_asm_insn ("ag\t%1,%3(%4)", op
);
8442 else if (CONST_OK_FOR_K (vcall_offset
))
8444 output_asm_insn ("lghi\t%4,%3", op
);
8445 output_asm_insn ("ag\t%4,0(%1)", op
);
8446 output_asm_insn ("ag\t%1,0(%4)", op
);
8448 else if (CONST_OK_FOR_Os (vcall_offset
))
8450 output_asm_insn ("lgfi\t%4,%3", op
);
8451 output_asm_insn ("ag\t%4,0(%1)", op
);
8452 output_asm_insn ("ag\t%1,0(%4)", op
);
8456 op
[7] = gen_label_rtx ();
8457 output_asm_insn ("llgf\t%4,%7-%5(%4)", op
);
8458 output_asm_insn ("ag\t%4,0(%1)", op
);
8459 output_asm_insn ("ag\t%1,0(%4)", op
);
8463 /* Jump to target. */
8464 output_asm_insn ("jg\t%0", op
);
8466 /* Output literal pool if required. */
8469 output_asm_insn (".align\t4", op
);
8470 targetm
.asm_out
.internal_label (file
, "L",
8471 CODE_LABEL_NUMBER (op
[5]));
8475 targetm
.asm_out
.internal_label (file
, "L",
8476 CODE_LABEL_NUMBER (op
[6]));
8477 output_asm_insn (".long\t%2", op
);
8481 targetm
.asm_out
.internal_label (file
, "L",
8482 CODE_LABEL_NUMBER (op
[7]));
8483 output_asm_insn (".long\t%3", op
);
8488 /* Setup base pointer if required. */
8490 || (!DISP_IN_RANGE (delta
)
8491 && !CONST_OK_FOR_K (delta
)
8492 && !CONST_OK_FOR_Os (delta
))
8493 || (!DISP_IN_RANGE (delta
)
8494 && !CONST_OK_FOR_K (vcall_offset
)
8495 && !CONST_OK_FOR_Os (vcall_offset
)))
8497 op
[5] = gen_label_rtx ();
8498 output_asm_insn ("basr\t%4,0", op
);
8499 targetm
.asm_out
.internal_label (file
, "L",
8500 CODE_LABEL_NUMBER (op
[5]));
8503 /* Add DELTA to this pointer. */
8506 if (CONST_OK_FOR_J (delta
))
8507 output_asm_insn ("la\t%1,%2(%1)", op
);
8508 else if (DISP_IN_RANGE (delta
))
8509 output_asm_insn ("lay\t%1,%2(%1)", op
);
8510 else if (CONST_OK_FOR_K (delta
))
8511 output_asm_insn ("ahi\t%1,%2", op
);
8512 else if (CONST_OK_FOR_Os (delta
))
8513 output_asm_insn ("afi\t%1,%2", op
);
8516 op
[6] = gen_label_rtx ();
8517 output_asm_insn ("a\t%1,%6-%5(%4)", op
);
8521 /* Perform vcall adjustment. */
8524 if (CONST_OK_FOR_J (vcall_offset
))
8526 output_asm_insn ("l\t%4,0(%1)", op
);
8527 output_asm_insn ("a\t%1,%3(%4)", op
);
8529 else if (DISP_IN_RANGE (vcall_offset
))
8531 output_asm_insn ("l\t%4,0(%1)", op
);
8532 output_asm_insn ("ay\t%1,%3(%4)", op
);
8534 else if (CONST_OK_FOR_K (vcall_offset
))
8536 output_asm_insn ("lhi\t%4,%3", op
);
8537 output_asm_insn ("a\t%4,0(%1)", op
);
8538 output_asm_insn ("a\t%1,0(%4)", op
);
8540 else if (CONST_OK_FOR_Os (vcall_offset
))
8542 output_asm_insn ("iilf\t%4,%3", op
);
8543 output_asm_insn ("a\t%4,0(%1)", op
);
8544 output_asm_insn ("a\t%1,0(%4)", op
);
8548 op
[7] = gen_label_rtx ();
8549 output_asm_insn ("l\t%4,%7-%5(%4)", op
);
8550 output_asm_insn ("a\t%4,0(%1)", op
);
8551 output_asm_insn ("a\t%1,0(%4)", op
);
8554 /* We had to clobber the base pointer register.
8555 Re-setup the base pointer (with a different base). */
8556 op
[5] = gen_label_rtx ();
8557 output_asm_insn ("basr\t%4,0", op
);
8558 targetm
.asm_out
.internal_label (file
, "L",
8559 CODE_LABEL_NUMBER (op
[5]));
8562 /* Jump to target. */
8563 op
[8] = gen_label_rtx ();
8566 output_asm_insn ("l\t%4,%8-%5(%4)", op
);
8568 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
8569 /* We cannot call through .plt, since .plt requires %r12 loaded. */
8570 else if (flag_pic
== 1)
8572 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
8573 output_asm_insn ("l\t%4,%0(%4)", op
);
8575 else if (flag_pic
== 2)
8577 op
[9] = gen_rtx_REG (Pmode
, 0);
8578 output_asm_insn ("l\t%9,%8-4-%5(%4)", op
);
8579 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
8580 output_asm_insn ("ar\t%4,%9", op
);
8581 output_asm_insn ("l\t%4,0(%4)", op
);
8584 output_asm_insn ("br\t%4", op
);
8586 /* Output literal pool. */
8587 output_asm_insn (".align\t4", op
);
8589 if (nonlocal
&& flag_pic
== 2)
8590 output_asm_insn (".long\t%0", op
);
8593 op
[0] = gen_rtx_SYMBOL_REF (Pmode
, "_GLOBAL_OFFSET_TABLE_");
8594 SYMBOL_REF_FLAGS (op
[0]) = SYMBOL_FLAG_LOCAL
;
8597 targetm
.asm_out
.internal_label (file
, "L", CODE_LABEL_NUMBER (op
[8]));
8599 output_asm_insn (".long\t%0", op
);
8601 output_asm_insn (".long\t%0-%5", op
);
8605 targetm
.asm_out
.internal_label (file
, "L",
8606 CODE_LABEL_NUMBER (op
[6]));
8607 output_asm_insn (".long\t%2", op
);
8611 targetm
.asm_out
.internal_label (file
, "L",
8612 CODE_LABEL_NUMBER (op
[7]));
8613 output_asm_insn (".long\t%3", op
);
8619 s390_valid_pointer_mode (enum machine_mode mode
)
8621 return (mode
== SImode
|| (TARGET_64BIT
&& mode
== DImode
));
8624 /* Checks whether the given ARGUMENT_LIST would use a caller
8625 saved register. This is used to decide whether sibling call
8626 optimization could be performed on the respective function
8630 s390_call_saved_register_used (tree argument_list
)
8632 CUMULATIVE_ARGS cum
;
8634 enum machine_mode mode
;
8639 INIT_CUMULATIVE_ARGS (cum
, NULL
, NULL
, 0, 0);
8641 while (argument_list
)
8643 parameter
= TREE_VALUE (argument_list
);
8644 argument_list
= TREE_CHAIN (argument_list
);
8646 gcc_assert (parameter
);
8648 /* For an undeclared variable passed as parameter we will get
8649 an ERROR_MARK node here. */
8650 if (TREE_CODE (parameter
) == ERROR_MARK
)
8653 type
= TREE_TYPE (parameter
);
8656 mode
= TYPE_MODE (type
);
8659 if (pass_by_reference (&cum
, mode
, type
, true))
8662 type
= build_pointer_type (type
);
8665 parm_rtx
= s390_function_arg (&cum
, mode
, type
, 0);
8667 s390_function_arg_advance (&cum
, mode
, type
, 0);
8669 if (parm_rtx
&& REG_P (parm_rtx
))
8672 reg
< HARD_REGNO_NREGS (REGNO (parm_rtx
), GET_MODE (parm_rtx
));
8674 if (! call_used_regs
[reg
+ REGNO (parm_rtx
)])
8681 /* Return true if the given call expression can be
8682 turned into a sibling call.
8683 DECL holds the declaration of the function to be called whereas
8684 EXP is the call expression itself. */
8687 s390_function_ok_for_sibcall (tree decl
, tree exp
)
8689 /* The TPF epilogue uses register 1. */
8690 if (TARGET_TPF_PROFILING
)
8693 /* The 31 bit PLT code uses register 12 (GOT pointer - caller saved)
8694 which would have to be restored before the sibcall. */
8695 if (!TARGET_64BIT
&& flag_pic
&& decl
&& TREE_PUBLIC (decl
))
8698 /* Register 6 on s390 is available as an argument register but unfortunately
8699 "caller saved". This makes functions needing this register for arguments
8700 not suitable for sibcalls. */
8701 if (TREE_OPERAND (exp
, 1)
8702 && s390_call_saved_register_used (TREE_OPERAND (exp
, 1)))
8708 /* Return the fixed registers used for condition codes. */
8711 s390_fixed_condition_code_regs (unsigned int *p1
, unsigned int *p2
)
8714 *p2
= INVALID_REGNUM
;
8719 /* This function is used by the call expanders of the machine description.
8720 It emits the call insn itself together with the necessary operations
8721 to adjust the target address and returns the emitted insn.
8722 ADDR_LOCATION is the target address rtx
8723 TLS_CALL the location of the thread-local symbol
8724 RESULT_REG the register where the result of the call should be stored
8725 RETADDR_REG the register where the return address should be stored
8726 If this parameter is NULL_RTX the call is considered
8727 to be a sibling call. */
8730 s390_emit_call (rtx addr_location
, rtx tls_call
, rtx result_reg
,
8733 bool plt_call
= false;
8739 /* Direct function calls need special treatment. */
8740 if (GET_CODE (addr_location
) == SYMBOL_REF
)
8742 /* When calling a global routine in PIC mode, we must
8743 replace the symbol itself with the PLT stub. */
8744 if (flag_pic
&& !SYMBOL_REF_LOCAL_P (addr_location
))
8746 addr_location
= gen_rtx_UNSPEC (Pmode
,
8747 gen_rtvec (1, addr_location
),
8749 addr_location
= gen_rtx_CONST (Pmode
, addr_location
);
8753 /* Unless we can use the bras(l) insn, force the
8754 routine address into a register. */
8755 if (!TARGET_SMALL_EXEC
&& !TARGET_CPU_ZARCH
)
8758 addr_location
= legitimize_pic_address (addr_location
, 0);
8760 addr_location
= force_reg (Pmode
, addr_location
);
8764 /* If it is already an indirect call or the code above moved the
8765 SYMBOL_REF to somewhere else make sure the address can be found in
8767 if (retaddr_reg
== NULL_RTX
8768 && GET_CODE (addr_location
) != SYMBOL_REF
8771 emit_move_insn (gen_rtx_REG (Pmode
, SIBCALL_REGNUM
), addr_location
);
8772 addr_location
= gen_rtx_REG (Pmode
, SIBCALL_REGNUM
);
8775 addr_location
= gen_rtx_MEM (QImode
, addr_location
);
8776 call
= gen_rtx_CALL (VOIDmode
, addr_location
, const0_rtx
);
8778 if (result_reg
!= NULL_RTX
)
8779 call
= gen_rtx_SET (VOIDmode
, result_reg
, call
);
8781 if (retaddr_reg
!= NULL_RTX
)
8783 clobber
= gen_rtx_CLOBBER (VOIDmode
, retaddr_reg
);
8785 if (tls_call
!= NULL_RTX
)
8786 vec
= gen_rtvec (3, call
, clobber
,
8787 gen_rtx_USE (VOIDmode
, tls_call
));
8789 vec
= gen_rtvec (2, call
, clobber
);
8791 call
= gen_rtx_PARALLEL (VOIDmode
, vec
);
8794 insn
= emit_call_insn (call
);
8796 /* 31-bit PLT stubs and tls calls use the GOT register implicitly. */
8797 if ((!TARGET_64BIT
&& plt_call
) || tls_call
!= NULL_RTX
)
8799 /* s390_function_ok_for_sibcall should
8800 have denied sibcalls in this case. */
8801 gcc_assert (retaddr_reg
!= NULL_RTX
);
8803 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), pic_offset_table_rtx
);
8808 /* Implement CONDITIONAL_REGISTER_USAGE. */
8811 s390_conditional_register_usage (void)
8817 fixed_regs
[PIC_OFFSET_TABLE_REGNUM
] = 1;
8818 call_used_regs
[PIC_OFFSET_TABLE_REGNUM
] = 1;
8820 if (TARGET_CPU_ZARCH
)
8822 fixed_regs
[BASE_REGNUM
] = 0;
8823 call_used_regs
[BASE_REGNUM
] = 0;
8824 fixed_regs
[RETURN_REGNUM
] = 0;
8825 call_used_regs
[RETURN_REGNUM
] = 0;
8829 for (i
= 24; i
< 32; i
++)
8830 call_used_regs
[i
] = call_really_used_regs
[i
] = 0;
8834 for (i
= 18; i
< 20; i
++)
8835 call_used_regs
[i
] = call_really_used_regs
[i
] = 0;
8838 if (TARGET_SOFT_FLOAT
)
8840 for (i
= 16; i
< 32; i
++)
8841 call_used_regs
[i
] = fixed_regs
[i
] = 1;
8845 /* Corresponding function to eh_return expander. */
8847 static GTY(()) rtx s390_tpf_eh_return_symbol
;
8849 s390_emit_tpf_eh_return (rtx target
)
8853 if (!s390_tpf_eh_return_symbol
)
8854 s390_tpf_eh_return_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "__tpf_eh_return");
8856 reg
= gen_rtx_REG (Pmode
, 2);
8858 emit_move_insn (reg
, target
);
8859 insn
= s390_emit_call (s390_tpf_eh_return_symbol
, NULL_RTX
, reg
,
8860 gen_rtx_REG (Pmode
, RETURN_REGNUM
));
8861 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), reg
);
8863 emit_move_insn (EH_RETURN_HANDLER_RTX
, reg
);
8866 /* Rework the prologue/epilogue to avoid saving/restoring
8867 registers unnecessarily. */
8870 s390_optimize_prologue (void)
8872 rtx insn
, new_insn
, next_insn
;
8874 /* Do a final recompute of the frame-related data. */
8876 s390_update_frame_layout ();
8878 /* If all special registers are in fact used, there's nothing we
8879 can do, so no point in walking the insn list. */
8881 if (cfun_frame_layout
.first_save_gpr
<= BASE_REGNUM
8882 && cfun_frame_layout
.last_save_gpr
>= BASE_REGNUM
8883 && (TARGET_CPU_ZARCH
8884 || (cfun_frame_layout
.first_save_gpr
<= RETURN_REGNUM
8885 && cfun_frame_layout
.last_save_gpr
>= RETURN_REGNUM
)))
8888 /* Search for prologue/epilogue insns and replace them. */
8890 for (insn
= get_insns (); insn
; insn
= next_insn
)
8892 int first
, last
, off
;
8893 rtx set
, base
, offset
;
8895 next_insn
= NEXT_INSN (insn
);
8897 if (GET_CODE (insn
) != INSN
)
8900 if (GET_CODE (PATTERN (insn
)) == PARALLEL
8901 && store_multiple_operation (PATTERN (insn
), VOIDmode
))
8903 set
= XVECEXP (PATTERN (insn
), 0, 0);
8904 first
= REGNO (SET_SRC (set
));
8905 last
= first
+ XVECLEN (PATTERN (insn
), 0) - 1;
8906 offset
= const0_rtx
;
8907 base
= eliminate_constant_term (XEXP (SET_DEST (set
), 0), &offset
);
8908 off
= INTVAL (offset
);
8910 if (GET_CODE (base
) != REG
|| off
< 0)
8912 if (cfun_frame_layout
.first_save_gpr
!= -1
8913 && (cfun_frame_layout
.first_save_gpr
< first
8914 || cfun_frame_layout
.last_save_gpr
> last
))
8916 if (REGNO (base
) != STACK_POINTER_REGNUM
8917 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
8919 if (first
> BASE_REGNUM
|| last
< BASE_REGNUM
)
8922 if (cfun_frame_layout
.first_save_gpr
!= -1)
8924 new_insn
= save_gprs (base
,
8925 off
+ (cfun_frame_layout
.first_save_gpr
8926 - first
) * UNITS_PER_WORD
,
8927 cfun_frame_layout
.first_save_gpr
,
8928 cfun_frame_layout
.last_save_gpr
);
8929 new_insn
= emit_insn_before (new_insn
, insn
);
8930 INSN_ADDRESSES_NEW (new_insn
, -1);
8937 if (cfun_frame_layout
.first_save_gpr
== -1
8938 && GET_CODE (PATTERN (insn
)) == SET
8939 && GET_CODE (SET_SRC (PATTERN (insn
))) == REG
8940 && (REGNO (SET_SRC (PATTERN (insn
))) == BASE_REGNUM
8941 || (!TARGET_CPU_ZARCH
8942 && REGNO (SET_SRC (PATTERN (insn
))) == RETURN_REGNUM
))
8943 && GET_CODE (SET_DEST (PATTERN (insn
))) == MEM
)
8945 set
= PATTERN (insn
);
8946 first
= REGNO (SET_SRC (set
));
8947 offset
= const0_rtx
;
8948 base
= eliminate_constant_term (XEXP (SET_DEST (set
), 0), &offset
);
8949 off
= INTVAL (offset
);
8951 if (GET_CODE (base
) != REG
|| off
< 0)
8953 if (REGNO (base
) != STACK_POINTER_REGNUM
8954 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
8961 if (GET_CODE (PATTERN (insn
)) == PARALLEL
8962 && load_multiple_operation (PATTERN (insn
), VOIDmode
))
8964 set
= XVECEXP (PATTERN (insn
), 0, 0);
8965 first
= REGNO (SET_DEST (set
));
8966 last
= first
+ XVECLEN (PATTERN (insn
), 0) - 1;
8967 offset
= const0_rtx
;
8968 base
= eliminate_constant_term (XEXP (SET_SRC (set
), 0), &offset
);
8969 off
= INTVAL (offset
);
8971 if (GET_CODE (base
) != REG
|| off
< 0)
8973 if (cfun_frame_layout
.first_restore_gpr
!= -1
8974 && (cfun_frame_layout
.first_restore_gpr
< first
8975 || cfun_frame_layout
.last_restore_gpr
> last
))
8977 if (REGNO (base
) != STACK_POINTER_REGNUM
8978 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
8980 if (first
> BASE_REGNUM
|| last
< BASE_REGNUM
)
8983 if (cfun_frame_layout
.first_restore_gpr
!= -1)
8985 new_insn
= restore_gprs (base
,
8986 off
+ (cfun_frame_layout
.first_restore_gpr
8987 - first
) * UNITS_PER_WORD
,
8988 cfun_frame_layout
.first_restore_gpr
,
8989 cfun_frame_layout
.last_restore_gpr
);
8990 new_insn
= emit_insn_before (new_insn
, insn
);
8991 INSN_ADDRESSES_NEW (new_insn
, -1);
8998 if (cfun_frame_layout
.first_restore_gpr
== -1
8999 && GET_CODE (PATTERN (insn
)) == SET
9000 && GET_CODE (SET_DEST (PATTERN (insn
))) == REG
9001 && (REGNO (SET_DEST (PATTERN (insn
))) == BASE_REGNUM
9002 || (!TARGET_CPU_ZARCH
9003 && REGNO (SET_DEST (PATTERN (insn
))) == RETURN_REGNUM
))
9004 && GET_CODE (SET_SRC (PATTERN (insn
))) == MEM
)
9006 set
= PATTERN (insn
);
9007 first
= REGNO (SET_DEST (set
));
9008 offset
= const0_rtx
;
9009 base
= eliminate_constant_term (XEXP (SET_SRC (set
), 0), &offset
);
9010 off
= INTVAL (offset
);
9012 if (GET_CODE (base
) != REG
|| off
< 0)
9014 if (REGNO (base
) != STACK_POINTER_REGNUM
9015 && REGNO (base
) != HARD_FRAME_POINTER_REGNUM
)
9024 /* Perform machine-dependent processing. */
9029 bool pool_overflow
= false;
9031 /* Make sure all splits have been performed; splits after
9032 machine_dependent_reorg might confuse insn length counts. */
9033 split_all_insns_noflow ();
9035 /* From here on decomposed literal pool addresses must be accepted. */
9036 cfun
->machine
->decomposed_literal_pool_addresses_ok_p
= true;
9038 /* Install the main literal pool and the associated base
9039 register load insns.
9041 In addition, there are two problematic situations we need
9044 - the literal pool might be > 4096 bytes in size, so that
9045 some of its elements cannot be directly accessed
9047 - a branch target might be > 64K away from the branch, so that
9048 it is not possible to use a PC-relative instruction.
9050 To fix those, we split the single literal pool into multiple
9051 pool chunks, reloading the pool base register at various
9052 points throughout the function to ensure it always points to
9053 the pool chunk the following code expects, and / or replace
9054 PC-relative branches by absolute branches.
9056 However, the two problems are interdependent: splitting the
9057 literal pool can move a branch further away from its target,
9058 causing the 64K limit to overflow, and on the other hand,
9059 replacing a PC-relative branch by an absolute branch means
9060 we need to put the branch target address into the literal
9061 pool, possibly causing it to overflow.
9063 So, we loop trying to fix up both problems until we manage
9064 to satisfy both conditions at the same time. Note that the
9065 loop is guaranteed to terminate as every pass of the loop
9066 strictly decreases the total number of PC-relative branches
9067 in the function. (This is not completely true as there
9068 might be branch-over-pool insns introduced by chunkify_start.
9069 Those never need to be split however.) */
9073 struct constant_pool
*pool
= NULL
;
9075 /* Collect the literal pool. */
9078 pool
= s390_mainpool_start ();
9080 pool_overflow
= true;
9083 /* If literal pool overflowed, start to chunkify it. */
9085 pool
= s390_chunkify_start ();
9087 /* Split out-of-range branches. If this has created new
9088 literal pool entries, cancel current chunk list and
9089 recompute it. zSeries machines have large branch
9090 instructions, so we never need to split a branch. */
9091 if (!TARGET_CPU_ZARCH
&& s390_split_branches ())
9094 s390_chunkify_cancel (pool
);
9096 s390_mainpool_cancel (pool
);
9101 /* If we made it up to here, both conditions are satisfied.
9102 Finish up literal pool related changes. */
9104 s390_chunkify_finish (pool
);
9106 s390_mainpool_finish (pool
);
9108 /* We're done splitting branches. */
9109 cfun
->machine
->split_branches_pending_p
= false;
9113 /* Generate out-of-pool execute target insns. */
9114 if (TARGET_CPU_ZARCH
)
9116 rtx insn
, label
, target
;
9118 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
9120 label
= s390_execute_label (insn
);
9124 gcc_assert (label
!= const0_rtx
);
9126 target
= emit_label (XEXP (label
, 0));
9127 INSN_ADDRESSES_NEW (target
, -1);
9129 target
= emit_insn (s390_execute_target (insn
));
9130 INSN_ADDRESSES_NEW (target
, -1);
9134 /* Try to optimize prologue and epilogue further. */
9135 s390_optimize_prologue ();
9139 /* Initialize GCC target structure. */
9141 #undef TARGET_ASM_ALIGNED_HI_OP
9142 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
9143 #undef TARGET_ASM_ALIGNED_DI_OP
9144 #define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
9145 #undef TARGET_ASM_INTEGER
9146 #define TARGET_ASM_INTEGER s390_assemble_integer
9148 #undef TARGET_ASM_OPEN_PAREN
9149 #define TARGET_ASM_OPEN_PAREN ""
9151 #undef TARGET_ASM_CLOSE_PAREN
9152 #define TARGET_ASM_CLOSE_PAREN ""
9154 #undef TARGET_DEFAULT_TARGET_FLAGS
9155 #define TARGET_DEFAULT_TARGET_FLAGS (TARGET_DEFAULT | MASK_FUSED_MADD)
9156 #undef TARGET_HANDLE_OPTION
9157 #define TARGET_HANDLE_OPTION s390_handle_option
9159 #undef TARGET_ENCODE_SECTION_INFO
9160 #define TARGET_ENCODE_SECTION_INFO s390_encode_section_info
9163 #undef TARGET_HAVE_TLS
9164 #define TARGET_HAVE_TLS true
9166 #undef TARGET_CANNOT_FORCE_CONST_MEM
9167 #define TARGET_CANNOT_FORCE_CONST_MEM s390_cannot_force_const_mem
9169 #undef TARGET_DELEGITIMIZE_ADDRESS
9170 #define TARGET_DELEGITIMIZE_ADDRESS s390_delegitimize_address
9172 #undef TARGET_RETURN_IN_MEMORY
9173 #define TARGET_RETURN_IN_MEMORY s390_return_in_memory
9175 #undef TARGET_INIT_BUILTINS
9176 #define TARGET_INIT_BUILTINS s390_init_builtins
9177 #undef TARGET_EXPAND_BUILTIN
9178 #define TARGET_EXPAND_BUILTIN s390_expand_builtin
9180 #undef TARGET_ASM_OUTPUT_MI_THUNK
9181 #define TARGET_ASM_OUTPUT_MI_THUNK s390_output_mi_thunk
9182 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
9183 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
9185 #undef TARGET_SCHED_ADJUST_PRIORITY
9186 #define TARGET_SCHED_ADJUST_PRIORITY s390_adjust_priority
9187 #undef TARGET_SCHED_ISSUE_RATE
9188 #define TARGET_SCHED_ISSUE_RATE s390_issue_rate
9189 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
9190 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD s390_first_cycle_multipass_dfa_lookahead
9192 #undef TARGET_CANNOT_COPY_INSN_P
9193 #define TARGET_CANNOT_COPY_INSN_P s390_cannot_copy_insn_p
9194 #undef TARGET_RTX_COSTS
9195 #define TARGET_RTX_COSTS s390_rtx_costs
9196 #undef TARGET_ADDRESS_COST
9197 #define TARGET_ADDRESS_COST s390_address_cost
9199 #undef TARGET_MACHINE_DEPENDENT_REORG
9200 #define TARGET_MACHINE_DEPENDENT_REORG s390_reorg
9202 #undef TARGET_VALID_POINTER_MODE
9203 #define TARGET_VALID_POINTER_MODE s390_valid_pointer_mode
9205 #undef TARGET_BUILD_BUILTIN_VA_LIST
9206 #define TARGET_BUILD_BUILTIN_VA_LIST s390_build_builtin_va_list
9207 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
9208 #define TARGET_GIMPLIFY_VA_ARG_EXPR s390_gimplify_va_arg
9210 #undef TARGET_PROMOTE_FUNCTION_ARGS
9211 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
9212 #undef TARGET_PROMOTE_FUNCTION_RETURN
9213 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
9214 #undef TARGET_PASS_BY_REFERENCE
9215 #define TARGET_PASS_BY_REFERENCE s390_pass_by_reference
9217 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
9218 #define TARGET_FUNCTION_OK_FOR_SIBCALL s390_function_ok_for_sibcall
9220 #undef TARGET_FIXED_CONDITION_CODE_REGS
9221 #define TARGET_FIXED_CONDITION_CODE_REGS s390_fixed_condition_code_regs
9223 #undef TARGET_CC_MODES_COMPATIBLE
9224 #define TARGET_CC_MODES_COMPATIBLE s390_cc_modes_compatible
9226 #undef TARGET_INVALID_WITHIN_DOLOOP
9227 #define TARGET_INVALID_WITHIN_DOLOOP hook_constcharptr_rtx_null
9230 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
9231 #define TARGET_ASM_OUTPUT_DWARF_DTPREL s390_output_dwarf_dtprel
9234 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
9235 #undef TARGET_MANGLE_FUNDAMENTAL_TYPE
9236 #define TARGET_MANGLE_FUNDAMENTAL_TYPE s390_mangle_fundamental_type
9239 struct gcc_target targetm
= TARGET_INITIALIZER
;
9241 #include "gt-s390.h"