1 /* Subroutines used for code generation on IBM S/390 and zSeries
2 Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
3 Contributed by Hartmut Penner (hpenner@de.ibm.com) and
4 Ulrich Weigand (uweigand@de.ibm.com).
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
25 #include "coretypes.h"
31 #include "hard-reg-set.h"
33 #include "insn-config.h"
34 #include "conditions.h"
36 #include "insn-attr.h"
44 #include "basic-block.h"
45 #include "integrate.h"
48 #include "target-def.h"
50 #include "langhooks.h"
53 static bool s390_assemble_integer
PARAMS ((rtx
, unsigned int, int));
54 static void s390_select_rtx_section
PARAMS ((enum machine_mode
, rtx
,
55 unsigned HOST_WIDE_INT
));
56 static void s390_encode_section_info
PARAMS ((tree
, int));
57 static const char *s390_strip_name_encoding
PARAMS ((const char *));
58 static bool s390_cannot_force_const_mem
PARAMS ((rtx
));
59 static rtx s390_delegitimize_address
PARAMS ((rtx
));
60 static void s390_init_builtins
PARAMS ((void));
61 static rtx s390_expand_builtin
PARAMS ((tree
, rtx
, rtx
,
62 enum machine_mode
, int));
63 static void s390_output_mi_thunk
PARAMS ((FILE *, tree
, HOST_WIDE_INT
,
64 HOST_WIDE_INT
, tree
));
65 static enum attr_type s390_safe_attr_type
PARAMS ((rtx
));
67 static int s390_adjust_cost
PARAMS ((rtx
, rtx
, rtx
, int));
68 static int s390_issue_rate
PARAMS ((void));
69 static int s390_use_dfa_pipeline_interface
PARAMS ((void));
70 static bool s390_rtx_costs
PARAMS ((rtx
, int, int, int *));
71 static int s390_address_cost
PARAMS ((rtx
));
74 #undef TARGET_ASM_ALIGNED_HI_OP
75 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
76 #undef TARGET_ASM_ALIGNED_DI_OP
77 #define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
78 #undef TARGET_ASM_INTEGER
79 #define TARGET_ASM_INTEGER s390_assemble_integer
81 #undef TARGET_ASM_OPEN_PAREN
82 #define TARGET_ASM_OPEN_PAREN ""
84 #undef TARGET_ASM_CLOSE_PAREN
85 #define TARGET_ASM_CLOSE_PAREN ""
87 #undef TARGET_ASM_SELECT_RTX_SECTION
88 #define TARGET_ASM_SELECT_RTX_SECTION s390_select_rtx_section
90 #undef TARGET_ENCODE_SECTION_INFO
91 #define TARGET_ENCODE_SECTION_INFO s390_encode_section_info
92 #undef TARGET_STRIP_NAME_ENCODING
93 #define TARGET_STRIP_NAME_ENCODING s390_strip_name_encoding
96 #undef TARGET_HAVE_TLS
97 #define TARGET_HAVE_TLS true
99 #undef TARGET_CANNOT_FORCE_CONST_MEM
100 #define TARGET_CANNOT_FORCE_CONST_MEM s390_cannot_force_const_mem
102 #undef TARGET_DELEGITIMIZE_ADDRESS
103 #define TARGET_DELEGITIMIZE_ADDRESS s390_delegitimize_address
105 #undef TARGET_INIT_BUILTINS
106 #define TARGET_INIT_BUILTINS s390_init_builtins
107 #undef TARGET_EXPAND_BUILTIN
108 #define TARGET_EXPAND_BUILTIN s390_expand_builtin
110 #undef TARGET_ASM_OUTPUT_MI_THUNK
111 #define TARGET_ASM_OUTPUT_MI_THUNK s390_output_mi_thunk
112 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
113 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
115 #undef TARGET_SCHED_ADJUST_COST
116 #define TARGET_SCHED_ADJUST_COST s390_adjust_cost
117 #undef TARGET_SCHED_ISSUE_RATE
118 #define TARGET_SCHED_ISSUE_RATE s390_issue_rate
119 #undef TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE
120 #define TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE s390_use_dfa_pipeline_interface
122 #undef TARGET_RTX_COSTS
123 #define TARGET_RTX_COSTS s390_rtx_costs
124 #undef TARGET_ADDRESS_COST
125 #define TARGET_ADDRESS_COST s390_address_cost
127 struct gcc_target targetm
= TARGET_INITIALIZER
;
129 extern int reload_completed
;
131 /* The alias set for prologue/epilogue register save/restore. */
132 static int s390_sr_alias_set
= 0;
134 /* Save information from a "cmpxx" operation until the branch or scc is
136 rtx s390_compare_op0
, s390_compare_op1
;
138 /* The encoding characters for the four TLS models present in ELF. */
139 static char const tls_model_chars
[] = " GLil";
141 /* Structure used to hold the components of a S/390 memory
142 address. A legitimate address on S/390 is of the general
144 base + index + displacement
145 where any of the components is optional.
147 base and index are registers of the class ADDR_REGS,
148 displacement is an unsigned 12-bit immediate constant. */
158 /* Which cpu are we tuning for. */
159 enum processor_type s390_cpu
;
160 /* Which instruction set architecture to use. */
161 enum processor_type s390_arch
;
163 /* Strings to hold which cpu and instruction set architecture to use. */
164 const char *s390_tune_string
; /* for -mtune=<xxx> */
165 const char *s390_arch_string
; /* for -march=<xxx> */
167 /* Define the structure for the machine field in struct function. */
169 struct machine_function
GTY(())
171 /* Label of start of initial literal pool. */
172 rtx literal_pool_label
;
174 /* Set, if some of the fprs 8-15 need to be saved (64 bit abi). */
177 /* Number of first and last gpr to be saved, restored. */
179 int first_restore_gpr
;
182 /* Size of stack frame. */
183 HOST_WIDE_INT frame_size
;
185 /* Some local-dynamic TLS symbol name. */
186 const char *some_ld_name
;
189 static int s390_match_ccmode_set
PARAMS ((rtx
, enum machine_mode
));
190 static int s390_branch_condition_mask
PARAMS ((rtx
));
191 static const char *s390_branch_condition_mnemonic
PARAMS ((rtx
, int));
192 static int check_mode
PARAMS ((rtx
, enum machine_mode
*));
193 static int general_s_operand
PARAMS ((rtx
, enum machine_mode
, int));
194 static int s390_decompose_address
PARAMS ((rtx
, struct s390_address
*));
195 static rtx get_thread_pointer
PARAMS ((void));
196 static rtx legitimize_tls_address
PARAMS ((rtx
, rtx
));
197 static const char *get_some_local_dynamic_name
PARAMS ((void));
198 static int get_some_local_dynamic_name_1
PARAMS ((rtx
*, void *));
199 static int reg_used_in_mem_p
PARAMS ((int, rtx
));
200 static int addr_generation_dependency_p
PARAMS ((rtx
, rtx
));
201 static int s390_split_branches
PARAMS ((rtx
, bool *));
202 static void find_constant_pool_ref
PARAMS ((rtx
, rtx
*));
203 static void replace_constant_pool_ref
PARAMS ((rtx
*, rtx
, rtx
));
204 static int find_base_register_in_addr
PARAMS ((struct s390_address
*));
205 static bool find_base_register_ref
PARAMS ((rtx
));
206 static void replace_base_register_ref
PARAMS ((rtx
*, rtx
));
207 static void s390_optimize_prolog
PARAMS ((int));
208 static bool s390_fixup_clobbered_return_reg
PARAMS ((rtx
));
209 static int find_unused_clobbered_reg
PARAMS ((void));
210 static void s390_frame_info
PARAMS ((void));
211 static rtx save_fpr
PARAMS ((rtx
, int, int));
212 static rtx restore_fpr
PARAMS ((rtx
, int, int));
213 static rtx save_gprs
PARAMS ((rtx
, int, int, int));
214 static rtx restore_gprs
PARAMS ((rtx
, int, int, int));
215 static int s390_function_arg_size
PARAMS ((enum machine_mode
, tree
));
216 static struct machine_function
* s390_init_machine_status
PARAMS ((void));
218 /* Return true if SET either doesn't set the CC register, or else
219 the source and destination have matching CC modes and that
220 CC mode is at least as constrained as REQ_MODE. */
223 s390_match_ccmode_set (set
, req_mode
)
225 enum machine_mode req_mode
;
227 enum machine_mode set_mode
;
229 if (GET_CODE (set
) != SET
)
232 if (GET_CODE (SET_DEST (set
)) != REG
|| !CC_REGNO_P (REGNO (SET_DEST (set
))))
235 set_mode
= GET_MODE (SET_DEST (set
));
248 if (req_mode
!= set_mode
)
253 if (req_mode
!= CCSmode
&& req_mode
!= CCUmode
&& req_mode
!= CCTmode
254 && req_mode
!= CCSRmode
&& req_mode
!= CCURmode
)
260 if (req_mode
!= CCAmode
)
268 return (GET_MODE (SET_SRC (set
)) == set_mode
);
271 /* Return true if every SET in INSN that sets the CC register
272 has source and destination with matching CC modes and that
273 CC mode is at least as constrained as REQ_MODE.
274 If REQ_MODE is VOIDmode, always return false. */
277 s390_match_ccmode (insn
, req_mode
)
279 enum machine_mode req_mode
;
283 /* s390_tm_ccmode returns VOIDmode to indicate failure. */
284 if (req_mode
== VOIDmode
)
287 if (GET_CODE (PATTERN (insn
)) == SET
)
288 return s390_match_ccmode_set (PATTERN (insn
), req_mode
);
290 if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
291 for (i
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
293 rtx set
= XVECEXP (PATTERN (insn
), 0, i
);
294 if (GET_CODE (set
) == SET
)
295 if (!s390_match_ccmode_set (set
, req_mode
))
302 /* If a test-under-mask instruction can be used to implement
303 (compare (and ... OP1) OP2), return the CC mode required
304 to do that. Otherwise, return VOIDmode.
305 MIXED is true if the instruction can distinguish between
306 CC1 and CC2 for mixed selected bits (TMxx), it is false
307 if the instruction cannot (TM). */
310 s390_tm_ccmode (op1
, op2
, mixed
)
317 /* ??? Fixme: should work on CONST_DOUBLE as well. */
318 if (GET_CODE (op1
) != CONST_INT
|| GET_CODE (op2
) != CONST_INT
)
321 /* Selected bits all zero: CC0. */
322 if (INTVAL (op2
) == 0)
325 /* Selected bits all one: CC3. */
326 if (INTVAL (op2
) == INTVAL (op1
))
329 /* Exactly two bits selected, mixed zeroes and ones: CC1 or CC2. */
332 bit1
= exact_log2 (INTVAL (op2
));
333 bit0
= exact_log2 (INTVAL (op1
) ^ INTVAL (op2
));
334 if (bit0
!= -1 && bit1
!= -1)
335 return bit0
> bit1
? CCT1mode
: CCT2mode
;
341 /* Given a comparison code OP (EQ, NE, etc.) and the operands
342 OP0 and OP1 of a COMPARE, return the mode to be used for the
346 s390_select_ccmode (code
, op0
, op1
)
355 if (GET_CODE (op0
) == PLUS
&& GET_CODE (XEXP (op0
, 1)) == CONST_INT
356 && CONST_OK_FOR_LETTER_P (INTVAL (XEXP (op0
, 1)), 'K'))
358 if (GET_CODE (op0
) == PLUS
|| GET_CODE (op0
) == MINUS
359 || GET_CODE (op1
) == NEG
)
362 if (GET_CODE (op0
) == AND
)
364 /* Check whether we can potentially do it via TM. */
365 enum machine_mode ccmode
;
366 ccmode
= s390_tm_ccmode (XEXP (op0
, 1), op1
, 1);
367 if (ccmode
!= VOIDmode
)
369 /* Relax CCTmode to CCZmode to allow fall-back to AND
370 if that turns out to be beneficial. */
371 return ccmode
== CCTmode
? CCZmode
: ccmode
;
375 if (register_operand (op0
, HImode
)
376 && GET_CODE (op1
) == CONST_INT
377 && (INTVAL (op1
) == -1 || INTVAL (op1
) == 65535))
379 if (register_operand (op0
, QImode
)
380 && GET_CODE (op1
) == CONST_INT
381 && (INTVAL (op1
) == -1 || INTVAL (op1
) == 255))
390 if (GET_CODE (op0
) == PLUS
&& GET_CODE (XEXP (op0
, 1)) == CONST_INT
391 && CONST_OK_FOR_LETTER_P (INTVAL (XEXP (op0
, 1)), 'K'))
393 if (INTVAL (XEXP((op0
), 1)) < 0)
406 if ((GET_CODE (op0
) == SIGN_EXTEND
|| GET_CODE (op0
) == ZERO_EXTEND
)
407 && GET_CODE (op1
) != CONST_INT
)
413 if (GET_CODE (op0
) == PLUS
)
416 if ((GET_CODE (op0
) == SIGN_EXTEND
|| GET_CODE (op0
) == ZERO_EXTEND
)
417 && GET_CODE (op1
) != CONST_INT
)
423 if (GET_CODE (op0
) == MINUS
)
426 if ((GET_CODE (op0
) == SIGN_EXTEND
|| GET_CODE (op0
) == ZERO_EXTEND
)
427 && GET_CODE (op1
) != CONST_INT
)
436 /* Return branch condition mask to implement a branch
437 specified by CODE. */
440 s390_branch_condition_mask (code
)
443 const int CC0
= 1 << 3;
444 const int CC1
= 1 << 2;
445 const int CC2
= 1 << 1;
446 const int CC3
= 1 << 0;
448 if (GET_CODE (XEXP (code
, 0)) != REG
449 || REGNO (XEXP (code
, 0)) != CC_REGNUM
450 || XEXP (code
, 1) != const0_rtx
)
453 switch (GET_MODE (XEXP (code
, 0)))
456 switch (GET_CODE (code
))
459 case NE
: return CC1
| CC2
| CC3
;
466 switch (GET_CODE (code
))
469 case NE
: return CC0
| CC2
| CC3
;
476 switch (GET_CODE (code
))
479 case NE
: return CC0
| CC1
| CC3
;
486 switch (GET_CODE (code
))
489 case NE
: return CC0
| CC1
| CC2
;
496 switch (GET_CODE (code
))
498 case EQ
: return CC0
| CC2
;
499 case NE
: return CC1
| CC3
;
506 switch (GET_CODE (code
))
508 case LTU
: return CC2
| CC3
; /* carry */
509 case GEU
: return CC0
| CC1
; /* no carry */
516 switch (GET_CODE (code
))
518 case GTU
: return CC0
| CC1
; /* borrow */
519 case LEU
: return CC2
| CC3
; /* no borrow */
526 switch (GET_CODE (code
))
529 case NE
: return CC1
| CC2
| CC3
;
530 case LTU
: return CC1
;
531 case GTU
: return CC2
;
532 case LEU
: return CC0
| CC1
;
533 case GEU
: return CC0
| CC2
;
540 switch (GET_CODE (code
))
543 case NE
: return CC2
| CC1
| CC3
;
544 case LTU
: return CC2
;
545 case GTU
: return CC1
;
546 case LEU
: return CC0
| CC2
;
547 case GEU
: return CC0
| CC1
;
554 switch (GET_CODE (code
))
557 case NE
: return CC1
| CC2
| CC3
;
558 case LT
: return CC1
| CC3
;
560 case LE
: return CC0
| CC1
| CC3
;
561 case GE
: return CC0
| CC2
;
568 switch (GET_CODE (code
))
571 case NE
: return CC1
| CC2
| CC3
;
573 case GT
: return CC2
| CC3
;
574 case LE
: return CC0
| CC1
;
575 case GE
: return CC0
| CC2
| CC3
;
582 switch (GET_CODE (code
))
585 case NE
: return CC1
| CC2
| CC3
;
588 case LE
: return CC0
| CC1
;
589 case GE
: return CC0
| CC2
;
590 case UNORDERED
: return CC3
;
591 case ORDERED
: return CC0
| CC1
| CC2
;
592 case UNEQ
: return CC0
| CC3
;
593 case UNLT
: return CC1
| CC3
;
594 case UNGT
: return CC2
| CC3
;
595 case UNLE
: return CC0
| CC1
| CC3
;
596 case UNGE
: return CC0
| CC2
| CC3
;
597 case LTGT
: return CC1
| CC2
;
604 switch (GET_CODE (code
))
607 case NE
: return CC2
| CC1
| CC3
;
610 case LE
: return CC0
| CC2
;
611 case GE
: return CC0
| CC1
;
612 case UNORDERED
: return CC3
;
613 case ORDERED
: return CC0
| CC2
| CC1
;
614 case UNEQ
: return CC0
| CC3
;
615 case UNLT
: return CC2
| CC3
;
616 case UNGT
: return CC1
| CC3
;
617 case UNLE
: return CC0
| CC2
| CC3
;
618 case UNGE
: return CC0
| CC1
| CC3
;
619 case LTGT
: return CC2
| CC1
;
630 /* If INV is false, return assembler mnemonic string to implement
631 a branch specified by CODE. If INV is true, return mnemonic
632 for the corresponding inverted branch. */
635 s390_branch_condition_mnemonic (code
, inv
)
639 static const char *const mnemonic
[16] =
641 NULL
, "o", "h", "nle",
642 "l", "nhe", "lh", "ne",
643 "e", "nlh", "he", "nl",
644 "le", "nh", "no", NULL
647 int mask
= s390_branch_condition_mask (code
);
652 if (mask
< 1 || mask
> 14)
655 return mnemonic
[mask
];
658 /* If OP is an integer constant of mode MODE with exactly one
659 HImode subpart unequal to DEF, return the number of that
660 subpart. As a special case, all HImode subparts of OP are
661 equal to DEF, return zero. Otherwise, return -1. */
664 s390_single_hi (op
, mode
, def
)
666 enum machine_mode mode
;
669 if (GET_CODE (op
) == CONST_INT
)
671 unsigned HOST_WIDE_INT value
= 0;
672 int n_parts
= GET_MODE_SIZE (mode
) / 2;
675 for (i
= 0; i
< n_parts
; i
++)
678 value
= (unsigned HOST_WIDE_INT
) INTVAL (op
);
682 if ((value
& 0xffff) != (unsigned)(def
& 0xffff))
691 return part
== -1 ? 0 : (n_parts
- 1 - part
);
694 else if (GET_CODE (op
) == CONST_DOUBLE
695 && GET_MODE (op
) == VOIDmode
)
697 unsigned HOST_WIDE_INT value
= 0;
698 int n_parts
= GET_MODE_SIZE (mode
) / 2;
701 for (i
= 0; i
< n_parts
; i
++)
704 value
= (unsigned HOST_WIDE_INT
) CONST_DOUBLE_LOW (op
);
705 else if (i
== HOST_BITS_PER_WIDE_INT
/ 16)
706 value
= (unsigned HOST_WIDE_INT
) CONST_DOUBLE_HIGH (op
);
710 if ((value
& 0xffff) != (unsigned)(def
& 0xffff))
719 return part
== -1 ? 0 : (n_parts
- 1 - part
);
725 /* Extract the HImode part number PART from integer
726 constant OP of mode MODE. */
729 s390_extract_hi (op
, mode
, part
)
731 enum machine_mode mode
;
734 int n_parts
= GET_MODE_SIZE (mode
) / 2;
735 if (part
< 0 || part
>= n_parts
)
738 part
= n_parts
- 1 - part
;
740 if (GET_CODE (op
) == CONST_INT
)
742 unsigned HOST_WIDE_INT value
= (unsigned HOST_WIDE_INT
) INTVAL (op
);
743 return ((value
>> (16 * part
)) & 0xffff);
745 else if (GET_CODE (op
) == CONST_DOUBLE
746 && GET_MODE (op
) == VOIDmode
)
748 unsigned HOST_WIDE_INT value
;
749 if (part
< HOST_BITS_PER_WIDE_INT
/ 16)
750 value
= (unsigned HOST_WIDE_INT
) CONST_DOUBLE_LOW (op
);
752 value
= (unsigned HOST_WIDE_INT
) CONST_DOUBLE_HIGH (op
),
753 part
-= HOST_BITS_PER_WIDE_INT
/ 16;
755 return ((value
>> (16 * part
)) & 0xffff);
761 /* If OP is an integer constant of mode MODE with exactly one
762 QImode subpart unequal to DEF, return the number of that
763 subpart. As a special case, all QImode subparts of OP are
764 equal to DEF, return zero. Otherwise, return -1. */
767 s390_single_qi (op
, mode
, def
)
769 enum machine_mode mode
;
772 if (GET_CODE (op
) == CONST_INT
)
774 unsigned HOST_WIDE_INT value
= 0;
775 int n_parts
= GET_MODE_SIZE (mode
);
778 for (i
= 0; i
< n_parts
; i
++)
781 value
= (unsigned HOST_WIDE_INT
) INTVAL (op
);
785 if ((value
& 0xff) != (unsigned)(def
& 0xff))
794 return part
== -1 ? 0 : (n_parts
- 1 - part
);
797 else if (GET_CODE (op
) == CONST_DOUBLE
798 && GET_MODE (op
) == VOIDmode
)
800 unsigned HOST_WIDE_INT value
= 0;
801 int n_parts
= GET_MODE_SIZE (mode
);
804 for (i
= 0; i
< n_parts
; i
++)
807 value
= (unsigned HOST_WIDE_INT
) CONST_DOUBLE_LOW (op
);
808 else if (i
== HOST_BITS_PER_WIDE_INT
/ 8)
809 value
= (unsigned HOST_WIDE_INT
) CONST_DOUBLE_HIGH (op
);
813 if ((value
& 0xff) != (unsigned)(def
& 0xff))
822 return part
== -1 ? 0 : (n_parts
- 1 - part
);
828 /* Extract the QImode part number PART from integer
829 constant OP of mode MODE. */
832 s390_extract_qi (op
, mode
, part
)
834 enum machine_mode mode
;
837 int n_parts
= GET_MODE_SIZE (mode
);
838 if (part
< 0 || part
>= n_parts
)
841 part
= n_parts
- 1 - part
;
843 if (GET_CODE (op
) == CONST_INT
)
845 unsigned HOST_WIDE_INT value
= (unsigned HOST_WIDE_INT
) INTVAL (op
);
846 return ((value
>> (8 * part
)) & 0xff);
848 else if (GET_CODE (op
) == CONST_DOUBLE
849 && GET_MODE (op
) == VOIDmode
)
851 unsigned HOST_WIDE_INT value
;
852 if (part
< HOST_BITS_PER_WIDE_INT
/ 8)
853 value
= (unsigned HOST_WIDE_INT
) CONST_DOUBLE_LOW (op
);
855 value
= (unsigned HOST_WIDE_INT
) CONST_DOUBLE_HIGH (op
),
856 part
-= HOST_BITS_PER_WIDE_INT
/ 8;
858 return ((value
>> (8 * part
)) & 0xff);
865 /* Change optimizations to be performed, depending on the
868 LEVEL is the optimization level specified; 2 if `-O2' is
869 specified, 1 if `-O' is specified, and 0 if neither is specified.
871 SIZE is nonzero if `-Os' is specified and zero otherwise. */
874 optimization_options (level
, size
)
875 int level ATTRIBUTE_UNUSED
;
876 int size ATTRIBUTE_UNUSED
;
878 /* ??? There are apparently still problems with -fcaller-saves. */
879 flag_caller_saves
= 0;
881 /* By default, always emit DWARF-2 unwind info. This allows debugging
882 without maintaining a stack frame back-chain. */
883 flag_asynchronous_unwind_tables
= 1;
890 static const char * const cpu_names
[] = TARGET_CPU_DEFAULT_NAMES
;
893 const char *const name
; /* processor name or nickname. */
894 const enum processor_type processor
;
901 const processor_alias_table
[] =
903 {"g5", PROCESSOR_9672_G5
, PTA_IEEE_FLOAT
},
904 {"g6", PROCESSOR_9672_G6
, PTA_IEEE_FLOAT
},
905 {"z900", PROCESSOR_2064_Z900
, PTA_IEEE_FLOAT
| PTA_ZARCH
},
908 int const pta_size
= ARRAY_SIZE (processor_alias_table
);
910 /* Acquire a unique set number for our register saves and restores. */
911 s390_sr_alias_set
= new_alias_set ();
913 /* Set up function hooks. */
914 init_machine_status
= s390_init_machine_status
;
916 /* Set cpu and arch, if only partially given. */
917 if (!s390_tune_string
&& s390_arch_string
)
918 s390_tune_string
= s390_arch_string
;
919 if (!s390_tune_string
)
920 s390_tune_string
= cpu_names
[TARGET_64BIT
? TARGET_CPU_DEFAULT_2064
921 : TARGET_CPU_DEFAULT_9672
];
922 if (!s390_arch_string
)
923 #ifdef DEFAULT_TARGET_64BIT
924 s390_arch_string
= "z900";
926 s390_arch_string
= "g5";
929 for (i
= 0; i
< pta_size
; i
++)
930 if (! strcmp (s390_arch_string
, processor_alias_table
[i
].name
))
932 s390_arch
= processor_alias_table
[i
].processor
;
933 /* Default cpu tuning to the architecture. */
934 s390_cpu
= s390_arch
;
936 if (!(processor_alias_table
[i
].flags
& PTA_ZARCH
)
938 error ("64-bit ABI not supported on %s", s390_arch_string
);
940 if (!(processor_alias_table
[i
].flags
& PTA_ZARCH
)
942 error ("z/Architecture not supported on %s", s390_arch_string
);
948 error ("bad value (%s) for -march= switch", s390_arch_string
);
950 /* ESA implies 31 bit mode. */
951 if ((target_flags_explicit
& MASK_ZARCH
) && !TARGET_ZARCH
)
953 if ((target_flags_explicit
& MASK_64BIT
) && TARGET_64BIT
)
954 error ("64-bit ABI not possible in ESA/390 mode");
956 target_flags
&= ~MASK_64BIT
;
959 for (i
= 0; i
< pta_size
; i
++)
960 if (! strcmp (s390_tune_string
, processor_alias_table
[i
].name
))
962 s390_cpu
= processor_alias_table
[i
].processor
;
967 error ("bad value (%s) for -mtune= switch", s390_tune_string
);
970 /* Map for smallest class containing reg regno. */
972 const enum reg_class regclass_map
[FIRST_PSEUDO_REGISTER
] =
973 { GENERAL_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
974 ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
975 ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
976 ADDR_REGS
, ADDR_REGS
, ADDR_REGS
, ADDR_REGS
,
977 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
978 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
979 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
980 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
981 ADDR_REGS
, NO_REGS
, ADDR_REGS
984 /* Return attribute type of insn. */
986 static enum attr_type
987 s390_safe_attr_type (insn
)
990 if (recog_memoized (insn
) >= 0)
991 return get_attr_type (insn
);
996 /* Return true if OP a (const_int 0) operand.
997 OP is the current operation.
998 MODE is the current operation mode. */
1001 const0_operand (op
, mode
)
1003 enum machine_mode mode
;
1005 return op
== CONST0_RTX (mode
);
1008 /* Return true if OP is constant.
1009 OP is the current operation.
1010 MODE is the current operation mode. */
1013 consttable_operand (op
, mode
)
1015 enum machine_mode mode ATTRIBUTE_UNUSED
;
1017 return CONSTANT_P (op
);
1020 /* Return true if the mode of operand OP matches MODE.
1021 If MODE is set to VOIDmode, set it to the mode of OP. */
1024 check_mode (op
, mode
)
1026 enum machine_mode
*mode
;
1028 if (*mode
== VOIDmode
)
1029 *mode
= GET_MODE (op
);
1032 if (GET_MODE (op
) != VOIDmode
&& GET_MODE (op
) != *mode
)
1038 /* Return true if OP a valid operand for the LARL instruction.
1039 OP is the current operation.
1040 MODE is the current operation mode. */
1043 larl_operand (op
, mode
)
1045 enum machine_mode mode
;
1047 if (! check_mode (op
, &mode
))
1050 /* Allow labels and local symbols. */
1051 if (GET_CODE (op
) == LABEL_REF
)
1053 if (GET_CODE (op
) == SYMBOL_REF
1054 && !tls_symbolic_operand (op
)
1055 && (!flag_pic
|| SYMBOL_REF_FLAG (op
)
1056 || CONSTANT_POOL_ADDRESS_P (op
)))
1059 /* Everything else must have a CONST, so strip it. */
1060 if (GET_CODE (op
) != CONST
)
1064 /* Allow adding *even* constants. */
1065 if (GET_CODE (op
) == PLUS
)
1067 if (GET_CODE (XEXP (op
, 1)) != CONST_INT
1068 || (INTVAL (XEXP (op
, 1)) & 1) != 0)
1073 /* Labels and local symbols allowed here as well. */
1074 if (GET_CODE (op
) == LABEL_REF
)
1076 if (GET_CODE (op
) == SYMBOL_REF
1077 && !tls_symbolic_operand (op
)
1078 && (!flag_pic
|| SYMBOL_REF_FLAG (op
)
1079 || CONSTANT_POOL_ADDRESS_P (op
)))
1082 /* Now we must have a @GOTENT offset or @PLT stub
1083 or an @INDNTPOFF TLS offset. */
1084 if (GET_CODE (op
) == UNSPEC
1085 && XINT (op
, 1) == 111)
1087 if (GET_CODE (op
) == UNSPEC
1088 && XINT (op
, 1) == 113)
1090 if (GET_CODE (op
) == UNSPEC
1091 && XINT (op
, 1) == UNSPEC_INDNTPOFF
)
1097 /* Helper routine to implement s_operand and s_imm_operand.
1098 OP is the current operation.
1099 MODE is the current operation mode.
1100 ALLOW_IMMEDIATE specifies whether immediate operands should
1101 be accepted or not. */
1104 general_s_operand (op
, mode
, allow_immediate
)
1106 enum machine_mode mode
;
1107 int allow_immediate
;
1109 struct s390_address addr
;
1111 /* Call general_operand first, so that we don't have to
1112 check for many special cases. */
1113 if (!general_operand (op
, mode
))
1116 /* Just like memory_operand, allow (subreg (mem ...))
1118 if (reload_completed
1119 && GET_CODE (op
) == SUBREG
1120 && GET_CODE (SUBREG_REG (op
)) == MEM
)
1121 op
= SUBREG_REG (op
);
1123 switch (GET_CODE (op
))
1125 /* Constants that we are sure will be forced to the
1126 literal pool in reload are OK as s-operand. Note
1127 that we cannot call s390_preferred_reload_class here
1128 because it might not be known yet at this point
1129 whether the current function is a leaf or not. */
1132 if (!allow_immediate
|| reload_completed
)
1134 if (!legitimate_reload_constant_p (op
))
1140 /* Memory operands are OK unless they already use an
1143 if (GET_CODE (XEXP (op
, 0)) == ADDRESSOF
)
1145 if (s390_decompose_address (XEXP (op
, 0), &addr
)
1157 /* Return true if OP is a valid S-type operand.
1158 OP is the current operation.
1159 MODE is the current operation mode. */
1162 s_operand (op
, mode
)
1164 enum machine_mode mode
;
1166 return general_s_operand (op
, mode
, 0);
1169 /* Return true if OP is a valid S-type operand or an immediate
1170 operand that can be addressed as S-type operand by forcing
1171 it into the literal pool.
1172 OP is the current operation.
1173 MODE is the current operation mode. */
1176 s_imm_operand (op
, mode
)
1178 enum machine_mode mode
;
1180 return general_s_operand (op
, mode
, 1);
1183 /* Return true if OP is a valid operand for a 'Q' constraint.
1184 This differs from s_operand in that only memory operands
1185 without index register are accepted, nothing else. */
1191 struct s390_address addr
;
1193 if (GET_CODE (op
) != MEM
)
1196 if (!s390_decompose_address (XEXP (op
, 0), &addr
))
1205 /* Compute a (partial) cost for rtx X. Return true if the complete
1206 cost has been computed, and false if subexpressions should be
1207 scanned. In either case, *TOTAL contains the cost result. */
1210 s390_rtx_costs (x
, code
, outer_code
, total
)
1212 int code
, outer_code
;
1218 if (GET_CODE (XEXP (x
, 0)) == MINUS
1219 && GET_CODE (XEXP (XEXP (x
, 0), 1)) != CONST_INT
)
1226 /* Force_const_mem does not work out of reload, because the
1227 saveable_obstack is set to reload_obstack, which does not
1228 live long enough. Because of this we cannot use force_const_mem
1229 in addsi3. This leads to problems with gen_add2_insn with a
1230 constant greater than a short. Because of that we give an
1231 addition of greater constants a cost of 3 (reload1.c 10096). */
1232 /* ??? saveable_obstack no longer exists. */
1233 if (outer_code
== PLUS
1234 && (INTVAL (x
) > 32767 || INTVAL (x
) < -32768))
1235 *total
= COSTS_N_INSNS (3);
1256 *total
= COSTS_N_INSNS (1);
1260 if (GET_MODE (XEXP (x
, 0)) == DImode
)
1261 *total
= COSTS_N_INSNS (40);
1263 *total
= COSTS_N_INSNS (7);
1270 *total
= COSTS_N_INSNS (33);
1278 /* Return the cost of an address rtx ADDR. */
1281 s390_address_cost (addr
)
1284 struct s390_address ad
;
1285 if (!s390_decompose_address (addr
, &ad
))
1288 return ad
.indx
? COSTS_N_INSNS (1) + 1 : COSTS_N_INSNS (1);
1291 /* Return true if OP is a valid operand for the BRAS instruction.
1292 OP is the current operation.
1293 MODE is the current operation mode. */
1296 bras_sym_operand (op
, mode
)
1298 enum machine_mode mode ATTRIBUTE_UNUSED
;
1300 register enum rtx_code code
= GET_CODE (op
);
1302 /* Allow SYMBOL_REFs. */
1303 if (code
== SYMBOL_REF
)
1306 /* Allow @PLT stubs. */
1308 && GET_CODE (XEXP (op
, 0)) == UNSPEC
1309 && XINT (XEXP (op
, 0), 1) == 113)
1314 /* If OP is a SYMBOL_REF of a thread-local symbol, return its TLS mode,
1315 otherwise return 0. */
1318 tls_symbolic_operand (op
)
1321 const char *symbol_str
;
1323 if (GET_CODE (op
) != SYMBOL_REF
)
1325 symbol_str
= XSTR (op
, 0);
1327 if (symbol_str
[0] != '%')
1329 return strchr (tls_model_chars
, symbol_str
[1]) - tls_model_chars
;
1332 /* Return true if OP is a load multiple operation. It is known to be a
1333 PARALLEL and the first section will be tested.
1334 OP is the current operation.
1335 MODE is the current operation mode. */
1338 load_multiple_operation (op
, mode
)
1340 enum machine_mode mode ATTRIBUTE_UNUSED
;
1342 int count
= XVECLEN (op
, 0);
1343 unsigned int dest_regno
;
1348 /* Perform a quick check so we don't blow up below. */
1350 || GET_CODE (XVECEXP (op
, 0, 0)) != SET
1351 || GET_CODE (SET_DEST (XVECEXP (op
, 0, 0))) != REG
1352 || GET_CODE (SET_SRC (XVECEXP (op
, 0, 0))) != MEM
)
1355 dest_regno
= REGNO (SET_DEST (XVECEXP (op
, 0, 0)));
1356 src_addr
= XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 0);
1358 /* Check, is base, or base + displacement. */
1360 if (GET_CODE (src_addr
) == REG
)
1362 else if (GET_CODE (src_addr
) == PLUS
1363 && GET_CODE (XEXP (src_addr
, 0)) == REG
1364 && GET_CODE (XEXP (src_addr
, 1)) == CONST_INT
)
1366 off
= INTVAL (XEXP (src_addr
, 1));
1367 src_addr
= XEXP (src_addr
, 0);
1372 if (src_addr
== frame_pointer_rtx
|| src_addr
== arg_pointer_rtx
)
1375 for (i
= 1; i
< count
; i
++)
1377 rtx elt
= XVECEXP (op
, 0, i
);
1379 if (GET_CODE (elt
) != SET
1380 || GET_CODE (SET_DEST (elt
)) != REG
1381 || GET_MODE (SET_DEST (elt
)) != Pmode
1382 || REGNO (SET_DEST (elt
)) != dest_regno
+ i
1383 || GET_CODE (SET_SRC (elt
)) != MEM
1384 || GET_MODE (SET_SRC (elt
)) != Pmode
1385 || GET_CODE (XEXP (SET_SRC (elt
), 0)) != PLUS
1386 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt
), 0), 0), src_addr
)
1387 || GET_CODE (XEXP (XEXP (SET_SRC (elt
), 0), 1)) != CONST_INT
1388 || INTVAL (XEXP (XEXP (SET_SRC (elt
), 0), 1))
1389 != off
+ i
* UNITS_PER_WORD
)
1396 /* Return true if OP is a store multiple operation. It is known to be a
1397 PARALLEL and the first section will be tested.
1398 OP is the current operation.
1399 MODE is the current operation mode. */
1402 store_multiple_operation (op
, mode
)
1404 enum machine_mode mode ATTRIBUTE_UNUSED
;
1406 int count
= XVECLEN (op
, 0);
1407 unsigned int src_regno
;
1411 /* Perform a quick check so we don't blow up below. */
1413 || GET_CODE (XVECEXP (op
, 0, 0)) != SET
1414 || GET_CODE (SET_DEST (XVECEXP (op
, 0, 0))) != MEM
1415 || GET_CODE (SET_SRC (XVECEXP (op
, 0, 0))) != REG
)
1418 src_regno
= REGNO (SET_SRC (XVECEXP (op
, 0, 0)));
1419 dest_addr
= XEXP (SET_DEST (XVECEXP (op
, 0, 0)), 0);
1421 /* Check, is base, or base + displacement. */
1423 if (GET_CODE (dest_addr
) == REG
)
1425 else if (GET_CODE (dest_addr
) == PLUS
1426 && GET_CODE (XEXP (dest_addr
, 0)) == REG
1427 && GET_CODE (XEXP (dest_addr
, 1)) == CONST_INT
)
1429 off
= INTVAL (XEXP (dest_addr
, 1));
1430 dest_addr
= XEXP (dest_addr
, 0);
1435 if (dest_addr
== frame_pointer_rtx
|| dest_addr
== arg_pointer_rtx
)
1438 for (i
= 1; i
< count
; i
++)
1440 rtx elt
= XVECEXP (op
, 0, i
);
1442 if (GET_CODE (elt
) != SET
1443 || GET_CODE (SET_SRC (elt
)) != REG
1444 || GET_MODE (SET_SRC (elt
)) != Pmode
1445 || REGNO (SET_SRC (elt
)) != src_regno
+ i
1446 || GET_CODE (SET_DEST (elt
)) != MEM
1447 || GET_MODE (SET_DEST (elt
)) != Pmode
1448 || GET_CODE (XEXP (SET_DEST (elt
), 0)) != PLUS
1449 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt
), 0), 0), dest_addr
)
1450 || GET_CODE (XEXP (XEXP (SET_DEST (elt
), 0), 1)) != CONST_INT
1451 || INTVAL (XEXP (XEXP (SET_DEST (elt
), 0), 1))
1452 != off
+ i
* UNITS_PER_WORD
)
1459 /* Return true if OP contains a symbol reference */
1462 symbolic_reference_mentioned_p (op
)
1465 register const char *fmt
;
1468 if (GET_CODE (op
) == SYMBOL_REF
|| GET_CODE (op
) == LABEL_REF
)
1471 fmt
= GET_RTX_FORMAT (GET_CODE (op
));
1472 for (i
= GET_RTX_LENGTH (GET_CODE (op
)) - 1; i
>= 0; i
--)
1478 for (j
= XVECLEN (op
, i
) - 1; j
>= 0; j
--)
1479 if (symbolic_reference_mentioned_p (XVECEXP (op
, i
, j
)))
1483 else if (fmt
[i
] == 'e' && symbolic_reference_mentioned_p (XEXP (op
, i
)))
1490 /* Return true if OP contains a reference to a thread-local symbol. */
1493 tls_symbolic_reference_mentioned_p (op
)
1496 register const char *fmt
;
1499 if (GET_CODE (op
) == SYMBOL_REF
)
1500 return tls_symbolic_operand (op
);
1502 fmt
= GET_RTX_FORMAT (GET_CODE (op
));
1503 for (i
= GET_RTX_LENGTH (GET_CODE (op
)) - 1; i
>= 0; i
--)
1509 for (j
= XVECLEN (op
, i
) - 1; j
>= 0; j
--)
1510 if (tls_symbolic_reference_mentioned_p (XVECEXP (op
, i
, j
)))
1514 else if (fmt
[i
] == 'e' && tls_symbolic_reference_mentioned_p (XEXP (op
, i
)))
1522 /* Return true if OP is a legitimate general operand when
1523 generating PIC code. It is given that flag_pic is on
1524 and that OP satisfies CONSTANT_P or is a CONST_DOUBLE. */
1527 legitimate_pic_operand_p (op
)
1530 /* Accept all non-symbolic constants. */
1531 if (!SYMBOLIC_CONST (op
))
1534 /* Reject everything else; must be handled
1535 via emit_symbolic_move. */
1539 /* Returns true if the constant value OP is a legitimate general operand.
1540 It is given that OP satisfies CONSTANT_P or is a CONST_DOUBLE. */
1543 legitimate_constant_p (op
)
1546 /* Accept all non-symbolic constants. */
1547 if (!SYMBOLIC_CONST (op
))
1550 /* Accept immediate LARL operands. */
1551 if (TARGET_64BIT
&& larl_operand (op
, VOIDmode
))
1554 /* Thread-local symbols are never legal constants. This is
1555 so that emit_call knows that computing such addresses
1556 might require a function call. */
1557 if (TLS_SYMBOLIC_CONST (op
))
1560 /* In the PIC case, symbolic constants must *not* be
1561 forced into the literal pool. We accept them here,
1562 so that they will be handled by emit_symbolic_move. */
1566 /* All remaining non-PIC symbolic constants are
1567 forced into the literal pool. */
1571 /* Determine if it's legal to put X into the constant pool. This
1572 is not possible if X contains the address of a symbol that is
1573 not constant (TLS) or not known at final link time (PIC). */
1576 s390_cannot_force_const_mem (x
)
1579 switch (GET_CODE (x
))
1583 /* Accept all non-symbolic constants. */
1587 /* Labels are OK iff we are non-PIC. */
1588 return flag_pic
!= 0;
1591 /* 'Naked' TLS symbol references are never OK,
1592 non-TLS symbols are OK iff we are non-PIC. */
1593 if (tls_symbolic_operand (x
))
1596 return flag_pic
!= 0;
1599 return s390_cannot_force_const_mem (XEXP (x
, 0));
1602 return s390_cannot_force_const_mem (XEXP (x
, 0))
1603 || s390_cannot_force_const_mem (XEXP (x
, 1));
1606 switch (XINT (x
, 1))
1608 /* Only lt-relative or GOT-relative UNSPECs are OK. */
1617 case UNSPEC_GOTNTPOFF
:
1618 case UNSPEC_INDNTPOFF
:
1631 /* Returns true if the constant value OP is a legitimate general
1632 operand during and after reload. The difference to
1633 legitimate_constant_p is that this function will not accept
1634 a constant that would need to be forced to the literal pool
1635 before it can be used as operand. */
1638 legitimate_reload_constant_p (op
)
1641 /* Accept l(g)hi operands. */
1642 if (GET_CODE (op
) == CONST_INT
1643 && CONST_OK_FOR_LETTER_P (INTVAL (op
), 'K'))
1646 /* Accept lliXX operands. */
1648 && s390_single_hi (op
, DImode
, 0) >= 0)
1651 /* Accept larl operands. */
1653 && larl_operand (op
, VOIDmode
))
1656 /* Everything else cannot be handled without reload. */
1660 /* Given an rtx OP being reloaded into a reg required to be in class CLASS,
1661 return the class of reg to actually use. */
1664 s390_preferred_reload_class (op
, class)
1666 enum reg_class
class;
1668 /* This can happen if a floating point constant is being
1669 reloaded into an integer register. Leave well alone. */
1670 if (GET_MODE_CLASS (GET_MODE (op
)) == MODE_FLOAT
1671 && class != FP_REGS
)
1674 switch (GET_CODE (op
))
1676 /* Constants we cannot reload must be forced into the
1677 literal pool. For constants we *could* handle directly,
1678 it might still be preferable to put them in the pool and
1679 use a memory-to-memory instruction.
1681 However, try to avoid needlessly allocating a literal
1682 pool in a routine that wouldn't otherwise need any.
1683 Heuristically, we assume that 64-bit leaf functions
1684 typically don't need a literal pool, all others do. */
1687 if (!legitimate_reload_constant_p (op
))
1690 if (TARGET_64BIT
&& current_function_is_leaf
)
1695 /* If a symbolic constant or a PLUS is reloaded,
1696 it is most likely being used as an address, so
1697 prefer ADDR_REGS. If 'class' is not a superset
1698 of ADDR_REGS, e.g. FP_REGS, reject this reload. */
1703 if (reg_class_subset_p (ADDR_REGS
, class))
1715 /* Return the register class of a scratch register needed to
1716 load IN into a register of class CLASS in MODE.
1718 We need a temporary when loading a PLUS expression which
1719 is not a legitimate operand of the LOAD ADDRESS instruction. */
1722 s390_secondary_input_reload_class (class, mode
, in
)
1723 enum reg_class
class ATTRIBUTE_UNUSED
;
1724 enum machine_mode mode
;
1727 if (s390_plus_operand (in
, mode
))
1733 /* Return true if OP is a PLUS that is not a legitimate
1734 operand for the LA instruction.
1735 OP is the current operation.
1736 MODE is the current operation mode. */
1739 s390_plus_operand (op
, mode
)
1741 enum machine_mode mode
;
1743 if (!check_mode (op
, &mode
) || mode
!= Pmode
)
1746 if (GET_CODE (op
) != PLUS
)
1749 if (legitimate_la_operand_p (op
))
1755 /* Generate code to load SRC, which is PLUS that is not a
1756 legitimate operand for the LA instruction, into TARGET.
1757 SCRATCH may be used as scratch register. */
1760 s390_expand_plus_operand (target
, src
, scratch
)
1761 register rtx target
;
1763 register rtx scratch
;
1766 struct s390_address ad
;
1768 /* src must be a PLUS; get its two operands. */
1769 if (GET_CODE (src
) != PLUS
|| GET_MODE (src
) != Pmode
)
1772 /* Check if any of the two operands is already scheduled
1773 for replacement by reload. This can happen e.g. when
1774 float registers occur in an address. */
1775 sum1
= find_replacement (&XEXP (src
, 0));
1776 sum2
= find_replacement (&XEXP (src
, 1));
1777 src
= gen_rtx_PLUS (Pmode
, sum1
, sum2
);
1779 /* If the address is already strictly valid, there's nothing to do. */
1780 if (!s390_decompose_address (src
, &ad
)
1781 || (ad
.base
&& !REG_OK_FOR_BASE_STRICT_P (ad
.base
))
1782 || (ad
.indx
&& !REG_OK_FOR_INDEX_STRICT_P (ad
.indx
)))
1784 /* Otherwise, one of the operands cannot be an address register;
1785 we reload its value into the scratch register. */
1786 if (true_regnum (sum1
) < 1 || true_regnum (sum1
) > 15)
1788 emit_move_insn (scratch
, sum1
);
1791 if (true_regnum (sum2
) < 1 || true_regnum (sum2
) > 15)
1793 emit_move_insn (scratch
, sum2
);
1797 /* According to the way these invalid addresses are generated
1798 in reload.c, it should never happen (at least on s390) that
1799 *neither* of the PLUS components, after find_replacements
1800 was applied, is an address register. */
1801 if (sum1
== scratch
&& sum2
== scratch
)
1807 src
= gen_rtx_PLUS (Pmode
, sum1
, sum2
);
1810 /* Emit the LOAD ADDRESS pattern. Note that reload of PLUS
1811 is only ever performed on addresses, so we can mark the
1812 sum as legitimate for LA in any case. */
1813 s390_load_address (target
, src
);
1817 /* Decompose a RTL expression ADDR for a memory address into
1818 its components, returned in OUT.
1820 Returns 0 if ADDR is not a valid memory address, nonzero
1821 otherwise. If OUT is NULL, don't return the components,
1822 but check for validity only.
1824 Note: Only addresses in canonical form are recognized.
1825 LEGITIMIZE_ADDRESS should convert non-canonical forms to the
1826 canonical form so that they will be recognized. */
1829 s390_decompose_address (addr
, out
)
1831 struct s390_address
*out
;
1833 rtx base
= NULL_RTX
;
1834 rtx indx
= NULL_RTX
;
1835 rtx disp
= NULL_RTX
;
1836 int pointer
= FALSE
;
1838 /* Decompose address into base + index + displacement. */
1840 if (GET_CODE (addr
) == REG
|| GET_CODE (addr
) == UNSPEC
)
1843 else if (GET_CODE (addr
) == PLUS
)
1845 rtx op0
= XEXP (addr
, 0);
1846 rtx op1
= XEXP (addr
, 1);
1847 enum rtx_code code0
= GET_CODE (op0
);
1848 enum rtx_code code1
= GET_CODE (op1
);
1850 if (code0
== REG
|| code0
== UNSPEC
)
1852 if (code1
== REG
|| code1
== UNSPEC
)
1854 indx
= op0
; /* index + base */
1860 base
= op0
; /* base + displacement */
1865 else if (code0
== PLUS
)
1867 indx
= XEXP (op0
, 0); /* index + base + disp */
1868 base
= XEXP (op0
, 1);
1879 disp
= addr
; /* displacement */
1882 /* Validate base register. */
1885 if (GET_CODE (base
) == UNSPEC
)
1887 if (XVECLEN (base
, 0) != 1 || XINT (base
, 1) != 101)
1889 base
= XVECEXP (base
, 0, 0);
1893 if (GET_CODE (base
) != REG
|| GET_MODE (base
) != Pmode
)
1896 if (REGNO (base
) == BASE_REGISTER
1897 || REGNO (base
) == STACK_POINTER_REGNUM
1898 || REGNO (base
) == FRAME_POINTER_REGNUM
1899 || ((reload_completed
|| reload_in_progress
)
1900 && frame_pointer_needed
1901 && REGNO (base
) == HARD_FRAME_POINTER_REGNUM
)
1902 || REGNO (base
) == ARG_POINTER_REGNUM
1903 || (REGNO (base
) >= FIRST_VIRTUAL_REGISTER
1904 && REGNO (base
) <= LAST_VIRTUAL_REGISTER
)
1906 && REGNO (base
) == PIC_OFFSET_TABLE_REGNUM
))
1910 /* Validate index register. */
1913 if (GET_CODE (indx
) == UNSPEC
)
1915 if (XVECLEN (indx
, 0) != 1 || XINT (indx
, 1) != 101)
1917 indx
= XVECEXP (indx
, 0, 0);
1921 if (GET_CODE (indx
) != REG
|| GET_MODE (indx
) != Pmode
)
1924 if (REGNO (indx
) == BASE_REGISTER
1925 || REGNO (indx
) == STACK_POINTER_REGNUM
1926 || REGNO (indx
) == FRAME_POINTER_REGNUM
1927 || ((reload_completed
|| reload_in_progress
)
1928 && frame_pointer_needed
1929 && REGNO (indx
) == HARD_FRAME_POINTER_REGNUM
)
1930 || REGNO (indx
) == ARG_POINTER_REGNUM
1931 || (REGNO (indx
) >= FIRST_VIRTUAL_REGISTER
1932 && REGNO (indx
) <= LAST_VIRTUAL_REGISTER
)
1934 && REGNO (indx
) == PIC_OFFSET_TABLE_REGNUM
))
1938 /* Validate displacement. */
1941 /* Allow integer constant in range. */
1942 if (GET_CODE (disp
) == CONST_INT
)
1944 /* If the argument pointer is involved, the displacement will change
1945 later anyway as the argument pointer gets eliminated. This could
1946 make a valid displacement invalid, but it is more likely to make
1947 an invalid displacement valid, because we sometimes access the
1948 register save area via negative offsets to the arg pointer.
1949 Thus we don't check the displacement for validity here. If after
1950 elimination the displacement turns out to be invalid after all,
1951 this is fixed up by reload in any case. */
1952 if (base
!= arg_pointer_rtx
&& indx
!= arg_pointer_rtx
)
1954 if (INTVAL (disp
) < 0 || INTVAL (disp
) >= 4096)
1959 /* In the small-PIC case, the linker converts @GOT12
1960 and @GOTNTPOFF offsets to possible displacements. */
1961 else if (GET_CODE (disp
) == CONST
1962 && GET_CODE (XEXP (disp
, 0)) == UNSPEC
1963 && (XINT (XEXP (disp
, 0), 1) == 110
1964 || XINT (XEXP (disp
, 0), 1) == UNSPEC_GOTNTPOFF
))
1972 /* Accept chunkfied literal pool symbol references. */
1973 else if (GET_CODE (disp
) == CONST
1974 && GET_CODE (XEXP (disp
, 0)) == MINUS
1975 && GET_CODE (XEXP (XEXP (disp
, 0), 0)) == LABEL_REF
1976 && GET_CODE (XEXP (XEXP (disp
, 0), 1)) == LABEL_REF
)
1981 /* Likewise if a constant offset is present. */
1982 else if (GET_CODE (disp
) == CONST
1983 && GET_CODE (XEXP (disp
, 0)) == PLUS
1984 && GET_CODE (XEXP (XEXP (disp
, 0), 1)) == CONST_INT
1985 && GET_CODE (XEXP (XEXP (disp
, 0), 0)) == MINUS
1986 && GET_CODE (XEXP (XEXP (XEXP (disp
, 0), 0), 0)) == LABEL_REF
1987 && GET_CODE (XEXP (XEXP (XEXP (disp
, 0), 0), 1)) == LABEL_REF
)
1992 /* We can convert literal pool addresses to
1993 displacements by basing them off the base register. */
1996 /* In some cases, we can accept an additional
1997 small constant offset. Split these off here. */
1999 unsigned int offset
= 0;
2001 if (GET_CODE (disp
) == CONST
2002 && GET_CODE (XEXP (disp
, 0)) == PLUS
2003 && GET_CODE (XEXP (XEXP (disp
, 0), 1)) == CONST_INT
)
2005 offset
= INTVAL (XEXP (XEXP (disp
, 0), 1));
2006 disp
= XEXP (XEXP (disp
, 0), 0);
2009 /* Now we must have a literal pool address. */
2010 if (GET_CODE (disp
) != SYMBOL_REF
2011 || !CONSTANT_POOL_ADDRESS_P (disp
))
2014 /* If we have an offset, make sure it does not
2015 exceed the size of the constant pool entry. */
2016 if (offset
&& offset
>= GET_MODE_SIZE (get_pool_mode (disp
)))
2019 /* Either base or index must be free to
2020 hold the base register. */
2024 /* Convert the address. */
2026 indx
= gen_rtx_REG (Pmode
, BASE_REGISTER
);
2028 base
= gen_rtx_REG (Pmode
, BASE_REGISTER
);
2030 disp
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, disp
), 100);
2031 disp
= gen_rtx_CONST (Pmode
, disp
);
2034 disp
= plus_constant (disp
, offset
);
2048 out
->pointer
= pointer
;
2054 /* Return nonzero if ADDR is a valid memory address.
2055 STRICT specifies whether strict register checking applies. */
2058 legitimate_address_p (mode
, addr
, strict
)
2059 enum machine_mode mode ATTRIBUTE_UNUSED
;
2063 struct s390_address ad
;
2064 if (!s390_decompose_address (addr
, &ad
))
2069 if (ad
.base
&& !REG_OK_FOR_BASE_STRICT_P (ad
.base
))
2071 if (ad
.indx
&& !REG_OK_FOR_INDEX_STRICT_P (ad
.indx
))
2076 if (ad
.base
&& !REG_OK_FOR_BASE_NONSTRICT_P (ad
.base
))
2078 if (ad
.indx
&& !REG_OK_FOR_INDEX_NONSTRICT_P (ad
.indx
))
2085 /* Return 1 if OP is a valid operand for the LA instruction.
2086 In 31-bit, we need to prove that the result is used as an
2087 address, as LA performs only a 31-bit addition. */
2090 legitimate_la_operand_p (op
)
2093 struct s390_address addr
;
2094 if (!s390_decompose_address (op
, &addr
))
2097 if (TARGET_64BIT
|| addr
.pointer
)
2103 /* Return 1 if OP is a valid operand for the LA instruction,
2104 and we prefer to use LA over addition to compute it. */
2107 preferred_la_operand_p (op
)
2110 struct s390_address addr
;
2111 if (!s390_decompose_address (op
, &addr
))
2114 if (!TARGET_64BIT
&& !addr
.pointer
)
2120 if ((addr
.base
&& REG_P (addr
.base
) && REG_POINTER (addr
.base
))
2121 || (addr
.indx
&& REG_P (addr
.indx
) && REG_POINTER (addr
.indx
)))
2127 /* Emit a forced load-address operation to load SRC into DST.
2128 This will use the LOAD ADDRESS instruction even in situations
2129 where legitimate_la_operand_p (SRC) returns false. */
2132 s390_load_address (dst
, src
)
2137 emit_move_insn (dst
, src
);
2139 emit_insn (gen_force_la_31 (dst
, src
));
2142 /* Return a legitimate reference for ORIG (an address) using the
2143 register REG. If REG is 0, a new pseudo is generated.
2145 There are two types of references that must be handled:
2147 1. Global data references must load the address from the GOT, via
2148 the PIC reg. An insn is emitted to do this load, and the reg is
2151 2. Static data references, constant pool addresses, and code labels
2152 compute the address as an offset from the GOT, whose base is in
2153 the PIC reg. Static data objects have SYMBOL_REF_FLAG set to
2154 differentiate them from global data objects. The returned
2155 address is the PIC reg + an unspec constant.
2157 GO_IF_LEGITIMATE_ADDRESS rejects symbolic references unless the PIC
2158 reg also appears in the address. */
2161 legitimize_pic_address (orig
, reg
)
2169 if (GET_CODE (addr
) == LABEL_REF
2170 || (GET_CODE (addr
) == SYMBOL_REF
2171 && (SYMBOL_REF_FLAG (addr
)
2172 || CONSTANT_POOL_ADDRESS_P (addr
))))
2174 /* This is a local symbol. */
2177 /* Access local symbols PC-relative via LARL.
2178 This is the same as in the non-PIC case, so it is
2179 handled automatically ... */
2183 /* Access local symbols relative to the literal pool. */
2185 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
2187 addr
= gen_rtx_UNSPEC (SImode
, gen_rtvec (1, addr
), 100);
2188 addr
= gen_rtx_CONST (SImode
, addr
);
2189 addr
= force_const_mem (SImode
, addr
);
2190 emit_move_insn (temp
, addr
);
2192 base
= gen_rtx_REG (Pmode
, BASE_REGISTER
);
2193 base
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, base
), 101);
2194 new = gen_rtx_PLUS (Pmode
, base
, temp
);
2198 emit_move_insn (reg
, new);
2203 else if (GET_CODE (addr
) == SYMBOL_REF
)
2206 reg
= gen_reg_rtx (Pmode
);
2210 /* Assume GOT offset < 4k. This is handled the same way
2211 in both 31- and 64-bit code (@GOT12). */
2213 if (reload_in_progress
|| reload_completed
)
2214 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
2216 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), 110);
2217 new = gen_rtx_CONST (Pmode
, new);
2218 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, new);
2219 new = gen_rtx_MEM (Pmode
, new);
2220 RTX_UNCHANGING_P (new) = 1;
2221 emit_move_insn (reg
, new);
2224 else if (TARGET_64BIT
)
2226 /* If the GOT offset might be >= 4k, we determine the position
2227 of the GOT entry via a PC-relative LARL (@GOTENT). */
2229 rtx temp
= gen_reg_rtx (Pmode
);
2231 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), 111);
2232 new = gen_rtx_CONST (Pmode
, new);
2233 emit_move_insn (temp
, new);
2235 new = gen_rtx_MEM (Pmode
, temp
);
2236 RTX_UNCHANGING_P (new) = 1;
2237 emit_move_insn (reg
, new);
2242 /* If the GOT offset might be >= 4k, we have to load it
2243 from the literal pool (@GOT). */
2245 rtx temp
= gen_reg_rtx (Pmode
);
2247 if (reload_in_progress
|| reload_completed
)
2248 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
2250 addr
= gen_rtx_UNSPEC (SImode
, gen_rtvec (1, addr
), 112);
2251 addr
= gen_rtx_CONST (SImode
, addr
);
2252 addr
= force_const_mem (SImode
, addr
);
2253 emit_move_insn (temp
, addr
);
2255 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
2256 new = gen_rtx_MEM (Pmode
, new);
2257 RTX_UNCHANGING_P (new) = 1;
2258 emit_move_insn (reg
, new);
2264 if (GET_CODE (addr
) == CONST
)
2266 addr
= XEXP (addr
, 0);
2267 if (GET_CODE (addr
) == UNSPEC
)
2269 if (XVECLEN (addr
, 0) != 1)
2271 switch (XINT (addr
, 1))
2273 /* If someone moved an @GOT or lt-relative UNSPEC
2274 out of the literal pool, force them back in. */
2278 new = force_const_mem (SImode
, orig
);
2281 /* @GOTENT is OK as is. */
2285 /* @PLT is OK as is on 64-bit, must be converted to
2286 lt-relative PLT on 31-bit. */
2290 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
2292 addr
= XVECEXP (addr
, 0, 0);
2293 addr
= gen_rtx_UNSPEC (SImode
, gen_rtvec (1, addr
), 114);
2294 addr
= gen_rtx_CONST (SImode
, addr
);
2295 addr
= force_const_mem (SImode
, addr
);
2296 emit_move_insn (temp
, addr
);
2298 base
= gen_rtx_REG (Pmode
, BASE_REGISTER
);
2299 base
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, base
), 101);
2300 new = gen_rtx_PLUS (Pmode
, base
, temp
);
2304 emit_move_insn (reg
, new);
2310 /* Everything else cannot happen. */
2315 else if (GET_CODE (addr
) != PLUS
)
2318 if (GET_CODE (addr
) == PLUS
)
2320 rtx op0
= XEXP (addr
, 0), op1
= XEXP (addr
, 1);
2321 /* Check first to see if this is a constant offset
2322 from a local symbol reference. */
2323 if ((GET_CODE (op0
) == LABEL_REF
2324 || (GET_CODE (op0
) == SYMBOL_REF
2325 && (SYMBOL_REF_FLAG (op0
)
2326 || CONSTANT_POOL_ADDRESS_P (op0
))))
2327 && GET_CODE (op1
) == CONST_INT
)
2331 if (INTVAL (op1
) & 1)
2333 /* LARL can't handle odd offsets, so emit a
2334 pair of LARL and LA. */
2335 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
2337 if (INTVAL (op1
) < 0 || INTVAL (op1
) >= 4096)
2339 int even
= INTVAL (op1
) - 1;
2340 op0
= gen_rtx_PLUS (Pmode
, op0
, GEN_INT (even
));
2341 op0
= gen_rtx_CONST (Pmode
, op0
);
2345 emit_move_insn (temp
, op0
);
2346 new = gen_rtx_PLUS (Pmode
, temp
, op1
);
2350 emit_move_insn (reg
, new);
2356 /* If the offset is even, we can just use LARL.
2357 This will happen automatically. */
2362 /* Access local symbols relative to the literal pool. */
2364 rtx temp
= reg
? reg
: gen_reg_rtx (Pmode
);
2366 addr
= gen_rtx_UNSPEC (SImode
, gen_rtvec (1, op0
), 100);
2367 addr
= gen_rtx_PLUS (SImode
, addr
, op1
);
2368 addr
= gen_rtx_CONST (SImode
, addr
);
2369 addr
= force_const_mem (SImode
, addr
);
2370 emit_move_insn (temp
, addr
);
2372 base
= gen_rtx_REG (Pmode
, BASE_REGISTER
);
2373 base
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, base
), 101);
2374 new = gen_rtx_PLUS (Pmode
, base
, temp
);
2378 emit_move_insn (reg
, new);
2384 /* Now, check whether it is an LT-relative symbol plus offset
2385 that was pulled out of the literal pool. Force it back in. */
2387 else if (GET_CODE (op0
) == UNSPEC
2388 && GET_CODE (op1
) == CONST_INT
)
2390 if (XVECLEN (op0
, 0) != 1)
2392 if (XINT (op0
, 1) != 100)
2395 new = force_const_mem (SImode
, orig
);
2398 /* Otherwise, compute the sum. */
2401 base
= legitimize_pic_address (XEXP (addr
, 0), reg
);
2402 new = legitimize_pic_address (XEXP (addr
, 1),
2403 base
== reg
? NULL_RTX
: reg
);
2404 if (GET_CODE (new) == CONST_INT
)
2405 new = plus_constant (base
, INTVAL (new));
2408 if (GET_CODE (new) == PLUS
&& CONSTANT_P (XEXP (new, 1)))
2410 base
= gen_rtx_PLUS (Pmode
, base
, XEXP (new, 0));
2411 new = XEXP (new, 1);
2413 new = gen_rtx_PLUS (Pmode
, base
, new);
2416 if (GET_CODE (new) == CONST
)
2417 new = XEXP (new, 0);
2418 new = force_operand (new, 0);
2425 /* Load the thread pointer into a register. */
2428 get_thread_pointer ()
2432 tp
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, const0_rtx
), UNSPEC_TP
);
2433 tp
= force_reg (Pmode
, tp
);
2434 mark_reg_pointer (tp
, BITS_PER_WORD
);
2439 /* Construct the SYMBOL_REF for the tls_get_offset function. */
2441 static GTY(()) rtx s390_tls_symbol
;
2443 s390_tls_get_offset ()
2445 if (!s390_tls_symbol
)
2446 s390_tls_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "__tls_get_offset");
2448 return s390_tls_symbol
;
2451 /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
2452 this (thread-local) address. REG may be used as temporary. */
2455 legitimize_tls_address (addr
, reg
)
2459 rtx
new, tls_call
, temp
, base
, r2
, insn
;
2461 if (GET_CODE (addr
) == SYMBOL_REF
)
2462 switch (tls_symbolic_operand (addr
))
2464 case TLS_MODEL_GLOBAL_DYNAMIC
:
2466 r2
= gen_rtx_REG (Pmode
, 2);
2467 tls_call
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_TLSGD
);
2468 new = gen_rtx_CONST (Pmode
, tls_call
);
2469 new = force_const_mem (Pmode
, new);
2470 emit_move_insn (r2
, new);
2471 emit_call_insn (gen_call_value_tls (r2
, tls_call
));
2472 insn
= get_insns ();
2475 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_NTPOFF
);
2476 temp
= gen_reg_rtx (Pmode
);
2477 emit_libcall_block (insn
, temp
, r2
, new);
2479 new = gen_rtx_PLUS (Pmode
, get_thread_pointer (), temp
);
2482 s390_load_address (reg
, new);
2487 case TLS_MODEL_LOCAL_DYNAMIC
:
2489 r2
= gen_rtx_REG (Pmode
, 2);
2490 tls_call
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, const0_rtx
), UNSPEC_TLSLDM
);
2491 new = gen_rtx_CONST (Pmode
, tls_call
);
2492 new = force_const_mem (Pmode
, new);
2493 emit_move_insn (r2
, new);
2494 emit_call_insn (gen_call_value_tls (r2
, tls_call
));
2495 insn
= get_insns ();
2498 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, const0_rtx
), UNSPEC_TLSLDM_NTPOFF
);
2499 temp
= gen_reg_rtx (Pmode
);
2500 emit_libcall_block (insn
, temp
, r2
, new);
2502 new = gen_rtx_PLUS (Pmode
, get_thread_pointer (), temp
);
2503 base
= gen_reg_rtx (Pmode
);
2504 s390_load_address (base
, new);
2506 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_DTPOFF
);
2507 new = gen_rtx_CONST (Pmode
, new);
2508 new = force_const_mem (Pmode
, new);
2509 temp
= gen_reg_rtx (Pmode
);
2510 emit_move_insn (temp
, new);
2512 new = gen_rtx_PLUS (Pmode
, base
, temp
);
2515 s390_load_address (reg
, new);
2520 case TLS_MODEL_INITIAL_EXEC
:
2523 /* Assume GOT offset < 4k. This is handled the same way
2524 in both 31- and 64-bit code. */
2526 if (reload_in_progress
|| reload_completed
)
2527 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
2529 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTNTPOFF
);
2530 new = gen_rtx_CONST (Pmode
, new);
2531 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, new);
2532 new = gen_rtx_MEM (Pmode
, new);
2533 RTX_UNCHANGING_P (new) = 1;
2534 temp
= gen_reg_rtx (Pmode
);
2535 emit_move_insn (temp
, new);
2537 else if (TARGET_64BIT
)
2539 /* If the GOT offset might be >= 4k, we determine the position
2540 of the GOT entry via a PC-relative LARL. */
2542 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_INDNTPOFF
);
2543 new = gen_rtx_CONST (Pmode
, new);
2544 temp
= gen_reg_rtx (Pmode
);
2545 emit_move_insn (temp
, new);
2547 new = gen_rtx_MEM (Pmode
, temp
);
2548 RTX_UNCHANGING_P (new) = 1;
2549 temp
= gen_reg_rtx (Pmode
);
2550 emit_move_insn (temp
, new);
2554 /* If the GOT offset might be >= 4k, we have to load it
2555 from the literal pool. */
2557 if (reload_in_progress
|| reload_completed
)
2558 regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
] = 1;
2560 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_GOTNTPOFF
);
2561 new = gen_rtx_CONST (Pmode
, new);
2562 new = force_const_mem (Pmode
, new);
2563 temp
= gen_reg_rtx (Pmode
);
2564 emit_move_insn (temp
, new);
2566 new = gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
, temp
);
2567 new = gen_rtx_MEM (Pmode
, new);
2568 RTX_UNCHANGING_P (new) = 1;
2570 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, new, addr
), UNSPEC_TLS_LOAD
);
2571 temp
= gen_reg_rtx (Pmode
);
2572 emit_insn (gen_rtx_SET (Pmode
, temp
, new));
2576 /* In position-dependent code, load the absolute address of
2577 the GOT entry from the literal pool. */
2579 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_INDNTPOFF
);
2580 new = gen_rtx_CONST (Pmode
, new);
2581 new = force_const_mem (Pmode
, new);
2582 temp
= gen_reg_rtx (Pmode
);
2583 emit_move_insn (temp
, new);
2586 new = gen_rtx_MEM (Pmode
, new);
2587 RTX_UNCHANGING_P (new) = 1;
2589 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, new, addr
), UNSPEC_TLS_LOAD
);
2590 temp
= gen_reg_rtx (Pmode
);
2591 emit_insn (gen_rtx_SET (Pmode
, temp
, new));
2594 new = gen_rtx_PLUS (Pmode
, get_thread_pointer (), temp
);
2597 s390_load_address (reg
, new);
2602 case TLS_MODEL_LOCAL_EXEC
:
2603 new = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, addr
), UNSPEC_NTPOFF
);
2604 new = gen_rtx_CONST (Pmode
, new);
2605 new = force_const_mem (Pmode
, new);
2606 temp
= gen_reg_rtx (Pmode
);
2607 emit_move_insn (temp
, new);
2609 new = gen_rtx_PLUS (Pmode
, get_thread_pointer (), temp
);
2612 s390_load_address (reg
, new);
2621 else if (GET_CODE (addr
) == CONST
&& GET_CODE (XEXP (addr
, 0)) == UNSPEC
)
2623 switch (XINT (XEXP (addr
, 0), 1))
2625 case UNSPEC_INDNTPOFF
:
2638 abort (); /* for now ... */
2643 /* Emit insns to move operands[1] into operands[0]. */
2646 emit_symbolic_move (operands
)
2649 rtx temp
= no_new_pseudos
? operands
[0] : gen_reg_rtx (Pmode
);
2651 if (GET_CODE (operands
[0]) == MEM
)
2652 operands
[1] = force_reg (Pmode
, operands
[1]);
2653 else if (TLS_SYMBOLIC_CONST (operands
[1]))
2654 operands
[1] = legitimize_tls_address (operands
[1], temp
);
2656 operands
[1] = legitimize_pic_address (operands
[1], temp
);
2659 /* Try machine-dependent ways of modifying an illegitimate address X
2660 to be legitimate. If we find one, return the new, valid address.
2662 OLDX is the address as it was before break_out_memory_refs was called.
2663 In some cases it is useful to look at this to decide what needs to be done.
2665 MODE is the mode of the operand pointed to by X.
2667 When -fpic is used, special handling is needed for symbolic references.
2668 See comments by legitimize_pic_address for details. */
2671 legitimize_address (x
, oldx
, mode
)
2673 register rtx oldx ATTRIBUTE_UNUSED
;
2674 enum machine_mode mode ATTRIBUTE_UNUSED
;
2676 rtx constant_term
= const0_rtx
;
2678 if (TLS_SYMBOLIC_CONST (x
))
2680 x
= legitimize_tls_address (x
, 0);
2682 if (legitimate_address_p (mode
, x
, FALSE
))
2687 if (SYMBOLIC_CONST (x
)
2688 || (GET_CODE (x
) == PLUS
2689 && (SYMBOLIC_CONST (XEXP (x
, 0))
2690 || SYMBOLIC_CONST (XEXP (x
, 1)))))
2691 x
= legitimize_pic_address (x
, 0);
2693 if (legitimate_address_p (mode
, x
, FALSE
))
2697 x
= eliminate_constant_term (x
, &constant_term
);
2699 /* Optimize loading of large displacements by splitting them
2700 into the multiple of 4K and the rest; this allows the
2701 former to be CSE'd if possible.
2703 Don't do this if the displacement is added to a register
2704 pointing into the stack frame, as the offsets will
2705 change later anyway. */
2707 if (GET_CODE (constant_term
) == CONST_INT
2708 && (INTVAL (constant_term
) < 0
2709 || INTVAL (constant_term
) >= 4096)
2710 && !(REG_P (x
) && REGNO_PTR_FRAME_P (REGNO (x
))))
2712 HOST_WIDE_INT lower
= INTVAL (constant_term
) & 0xfff;
2713 HOST_WIDE_INT upper
= INTVAL (constant_term
) ^ lower
;
2715 rtx temp
= gen_reg_rtx (Pmode
);
2716 rtx val
= force_operand (GEN_INT (upper
), temp
);
2718 emit_move_insn (temp
, val
);
2720 x
= gen_rtx_PLUS (Pmode
, x
, temp
);
2721 constant_term
= GEN_INT (lower
);
2724 if (GET_CODE (x
) == PLUS
)
2726 if (GET_CODE (XEXP (x
, 0)) == REG
)
2728 register rtx temp
= gen_reg_rtx (Pmode
);
2729 register rtx val
= force_operand (XEXP (x
, 1), temp
);
2731 emit_move_insn (temp
, val
);
2733 x
= gen_rtx_PLUS (Pmode
, XEXP (x
, 0), temp
);
2736 else if (GET_CODE (XEXP (x
, 1)) == REG
)
2738 register rtx temp
= gen_reg_rtx (Pmode
);
2739 register rtx val
= force_operand (XEXP (x
, 0), temp
);
2741 emit_move_insn (temp
, val
);
2743 x
= gen_rtx_PLUS (Pmode
, temp
, XEXP (x
, 1));
2747 if (constant_term
!= const0_rtx
)
2748 x
= gen_rtx_PLUS (Pmode
, x
, constant_term
);
2753 /* Emit code to move LEN bytes from DST to SRC. */
2756 s390_expand_movstr (dst
, src
, len
)
2761 rtx (*gen_short
) PARAMS ((rtx
, rtx
, rtx
)) =
2762 TARGET_64BIT
? gen_movstr_short_64
: gen_movstr_short_31
;
2763 rtx (*gen_long
) PARAMS ((rtx
, rtx
, rtx
, rtx
)) =
2764 TARGET_64BIT
? gen_movstr_long_64
: gen_movstr_long_31
;
2767 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) >= 0 && INTVAL (len
) <= 256)
2769 if (INTVAL (len
) > 0)
2770 emit_insn ((*gen_short
) (dst
, src
, GEN_INT (INTVAL (len
) - 1)));
2773 else if (TARGET_MVCLE
)
2775 enum machine_mode double_mode
= TARGET_64BIT
? TImode
: DImode
;
2776 enum machine_mode single_mode
= TARGET_64BIT
? DImode
: SImode
;
2777 rtx reg0
= gen_reg_rtx (double_mode
);
2778 rtx reg1
= gen_reg_rtx (double_mode
);
2780 emit_move_insn (gen_highpart (single_mode
, reg0
),
2781 force_operand (XEXP (dst
, 0), NULL_RTX
));
2782 emit_move_insn (gen_highpart (single_mode
, reg1
),
2783 force_operand (XEXP (src
, 0), NULL_RTX
));
2785 convert_move (gen_lowpart (single_mode
, reg0
), len
, 1);
2786 convert_move (gen_lowpart (single_mode
, reg1
), len
, 1);
2788 emit_insn ((*gen_long
) (reg0
, reg1
, reg0
, reg1
));
2793 rtx dst_addr
, src_addr
, count
, blocks
, temp
;
2794 rtx end_label
= gen_label_rtx ();
2795 enum machine_mode mode
;
2798 mode
= GET_MODE (len
);
2799 if (mode
== VOIDmode
)
2802 type
= (*lang_hooks
.types
.type_for_mode
) (mode
, 1);
2806 dst_addr
= gen_reg_rtx (Pmode
);
2807 src_addr
= gen_reg_rtx (Pmode
);
2808 count
= gen_reg_rtx (mode
);
2809 blocks
= gen_reg_rtx (mode
);
2811 convert_move (count
, len
, 1);
2812 emit_cmp_and_jump_insns (count
, const0_rtx
,
2813 EQ
, NULL_RTX
, mode
, 1, end_label
);
2815 emit_move_insn (dst_addr
, force_operand (XEXP (dst
, 0), NULL_RTX
));
2816 emit_move_insn (src_addr
, force_operand (XEXP (src
, 0), NULL_RTX
));
2817 dst
= change_address (dst
, VOIDmode
, dst_addr
);
2818 src
= change_address (src
, VOIDmode
, src_addr
);
2820 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1, 0);
2822 emit_move_insn (count
, temp
);
2824 temp
= expand_binop (mode
, ashr_optab
, count
, GEN_INT (8), blocks
, 1, 0);
2826 emit_move_insn (blocks
, temp
);
2828 expand_start_loop (1);
2829 expand_exit_loop_top_cond (0, build (NE_EXPR
, type
,
2830 make_tree (type
, blocks
),
2831 make_tree (type
, const0_rtx
)));
2833 emit_insn ((*gen_short
) (dst
, src
, GEN_INT (255)));
2834 s390_load_address (dst_addr
,
2835 gen_rtx_PLUS (Pmode
, dst_addr
, GEN_INT (256)));
2836 s390_load_address (src_addr
,
2837 gen_rtx_PLUS (Pmode
, src_addr
, GEN_INT (256)));
2839 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1, 0);
2841 emit_move_insn (blocks
, temp
);
2845 emit_insn ((*gen_short
) (dst
, src
, convert_to_mode (word_mode
, count
, 1)));
2846 emit_label (end_label
);
2850 /* Emit code to clear LEN bytes at DST. */
2853 s390_expand_clrstr (dst
, len
)
2857 rtx (*gen_short
) PARAMS ((rtx
, rtx
)) =
2858 TARGET_64BIT
? gen_clrstr_short_64
: gen_clrstr_short_31
;
2859 rtx (*gen_long
) PARAMS ((rtx
, rtx
, rtx
)) =
2860 TARGET_64BIT
? gen_clrstr_long_64
: gen_clrstr_long_31
;
2863 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) >= 0 && INTVAL (len
) <= 256)
2865 if (INTVAL (len
) > 0)
2866 emit_insn ((*gen_short
) (dst
, GEN_INT (INTVAL (len
) - 1)));
2869 else if (TARGET_MVCLE
)
2871 enum machine_mode double_mode
= TARGET_64BIT
? TImode
: DImode
;
2872 enum machine_mode single_mode
= TARGET_64BIT
? DImode
: SImode
;
2873 rtx reg0
= gen_reg_rtx (double_mode
);
2874 rtx reg1
= gen_reg_rtx (double_mode
);
2876 emit_move_insn (gen_highpart (single_mode
, reg0
),
2877 force_operand (XEXP (dst
, 0), NULL_RTX
));
2878 convert_move (gen_lowpart (single_mode
, reg0
), len
, 1);
2880 emit_move_insn (gen_highpart (single_mode
, reg1
), const0_rtx
);
2881 emit_move_insn (gen_lowpart (single_mode
, reg1
), const0_rtx
);
2883 emit_insn ((*gen_long
) (reg0
, reg1
, reg0
));
2888 rtx dst_addr
, src_addr
, count
, blocks
, temp
;
2889 rtx end_label
= gen_label_rtx ();
2890 enum machine_mode mode
;
2893 mode
= GET_MODE (len
);
2894 if (mode
== VOIDmode
)
2897 type
= (*lang_hooks
.types
.type_for_mode
) (mode
, 1);
2901 dst_addr
= gen_reg_rtx (Pmode
);
2902 src_addr
= gen_reg_rtx (Pmode
);
2903 count
= gen_reg_rtx (mode
);
2904 blocks
= gen_reg_rtx (mode
);
2906 convert_move (count
, len
, 1);
2907 emit_cmp_and_jump_insns (count
, const0_rtx
,
2908 EQ
, NULL_RTX
, mode
, 1, end_label
);
2910 emit_move_insn (dst_addr
, force_operand (XEXP (dst
, 0), NULL_RTX
));
2911 dst
= change_address (dst
, VOIDmode
, dst_addr
);
2913 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1, 0);
2915 emit_move_insn (count
, temp
);
2917 temp
= expand_binop (mode
, ashr_optab
, count
, GEN_INT (8), blocks
, 1, 0);
2919 emit_move_insn (blocks
, temp
);
2921 expand_start_loop (1);
2922 expand_exit_loop_top_cond (0, build (NE_EXPR
, type
,
2923 make_tree (type
, blocks
),
2924 make_tree (type
, const0_rtx
)));
2926 emit_insn ((*gen_short
) (dst
, GEN_INT (255)));
2927 s390_load_address (dst_addr
,
2928 gen_rtx_PLUS (Pmode
, dst_addr
, GEN_INT (256)));
2930 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1, 0);
2932 emit_move_insn (blocks
, temp
);
2936 emit_insn ((*gen_short
) (dst
, convert_to_mode (word_mode
, count
, 1)));
2937 emit_label (end_label
);
2941 /* Emit code to compare LEN bytes at OP0 with those at OP1,
2942 and return the result in TARGET. */
2945 s390_expand_cmpstr (target
, op0
, op1
, len
)
2951 rtx (*gen_short
) PARAMS ((rtx
, rtx
, rtx
)) =
2952 TARGET_64BIT
? gen_cmpstr_short_64
: gen_cmpstr_short_31
;
2953 rtx (*gen_long
) PARAMS ((rtx
, rtx
, rtx
, rtx
)) =
2954 TARGET_64BIT
? gen_cmpstr_long_64
: gen_cmpstr_long_31
;
2955 rtx (*gen_result
) PARAMS ((rtx
)) =
2956 GET_MODE (target
) == DImode
? gen_cmpint_di
: gen_cmpint_si
;
2958 op0
= protect_from_queue (op0
, 0);
2959 op1
= protect_from_queue (op1
, 0);
2960 len
= protect_from_queue (len
, 0);
2962 if (GET_CODE (len
) == CONST_INT
&& INTVAL (len
) >= 0 && INTVAL (len
) <= 256)
2964 if (INTVAL (len
) > 0)
2966 emit_insn ((*gen_short
) (op0
, op1
, GEN_INT (INTVAL (len
) - 1)));
2967 emit_insn ((*gen_result
) (target
));
2970 emit_move_insn (target
, const0_rtx
);
2973 else if (TARGET_MVCLE
)
2975 enum machine_mode double_mode
= TARGET_64BIT
? TImode
: DImode
;
2976 enum machine_mode single_mode
= TARGET_64BIT
? DImode
: SImode
;
2977 rtx reg0
= gen_reg_rtx (double_mode
);
2978 rtx reg1
= gen_reg_rtx (double_mode
);
2980 emit_move_insn (gen_highpart (single_mode
, reg0
),
2981 force_operand (XEXP (op0
, 0), NULL_RTX
));
2982 emit_move_insn (gen_highpart (single_mode
, reg1
),
2983 force_operand (XEXP (op1
, 0), NULL_RTX
));
2985 convert_move (gen_lowpart (single_mode
, reg0
), len
, 1);
2986 convert_move (gen_lowpart (single_mode
, reg1
), len
, 1);
2988 emit_insn ((*gen_long
) (reg0
, reg1
, reg0
, reg1
));
2989 emit_insn ((*gen_result
) (target
));
2994 rtx addr0
, addr1
, count
, blocks
, temp
;
2995 rtx end_label
= gen_label_rtx ();
2996 enum machine_mode mode
;
2999 mode
= GET_MODE (len
);
3000 if (mode
== VOIDmode
)
3003 type
= (*lang_hooks
.types
.type_for_mode
) (mode
, 1);
3007 addr0
= gen_reg_rtx (Pmode
);
3008 addr1
= gen_reg_rtx (Pmode
);
3009 count
= gen_reg_rtx (mode
);
3010 blocks
= gen_reg_rtx (mode
);
3012 convert_move (count
, len
, 1);
3013 emit_cmp_and_jump_insns (count
, const0_rtx
,
3014 EQ
, NULL_RTX
, mode
, 1, end_label
);
3016 emit_move_insn (addr0
, force_operand (XEXP (op0
, 0), NULL_RTX
));
3017 emit_move_insn (addr1
, force_operand (XEXP (op1
, 0), NULL_RTX
));
3018 op0
= change_address (op0
, VOIDmode
, addr0
);
3019 op1
= change_address (op1
, VOIDmode
, addr1
);
3021 temp
= expand_binop (mode
, add_optab
, count
, constm1_rtx
, count
, 1, 0);
3023 emit_move_insn (count
, temp
);
3025 temp
= expand_binop (mode
, ashr_optab
, count
, GEN_INT (8), blocks
, 1, 0);
3027 emit_move_insn (blocks
, temp
);
3029 expand_start_loop (1);
3030 expand_exit_loop_top_cond (0, build (NE_EXPR
, type
,
3031 make_tree (type
, blocks
),
3032 make_tree (type
, const0_rtx
)));
3034 emit_insn ((*gen_short
) (op0
, op1
, GEN_INT (255)));
3035 temp
= gen_rtx_NE (VOIDmode
, gen_rtx_REG (CCSmode
, 33), const0_rtx
);
3036 temp
= gen_rtx_IF_THEN_ELSE (VOIDmode
, temp
,
3037 gen_rtx_LABEL_REF (VOIDmode
, end_label
), pc_rtx
);
3038 temp
= gen_rtx_SET (VOIDmode
, pc_rtx
, temp
);
3039 emit_jump_insn (temp
);
3041 s390_load_address (addr0
,
3042 gen_rtx_PLUS (Pmode
, addr0
, GEN_INT (256)));
3043 s390_load_address (addr1
,
3044 gen_rtx_PLUS (Pmode
, addr1
, GEN_INT (256)));
3046 temp
= expand_binop (mode
, add_optab
, blocks
, constm1_rtx
, blocks
, 1, 0);
3048 emit_move_insn (blocks
, temp
);
3052 emit_insn ((*gen_short
) (op0
, op1
, convert_to_mode (word_mode
, count
, 1)));
3053 emit_label (end_label
);
3055 emit_insn ((*gen_result
) (target
));
3059 /* In the name of slightly smaller debug output, and to cater to
3060 general assembler losage, recognize various UNSPEC sequences
3061 and turn them back into a direct symbol reference. */
3064 s390_delegitimize_address (orig_x
)
3069 if (GET_CODE (x
) != MEM
)
3073 if (GET_CODE (x
) == PLUS
3074 && GET_CODE (XEXP (x
, 1)) == CONST
3075 && GET_CODE (XEXP (x
, 0)) == REG
3076 && REGNO (XEXP (x
, 0)) == PIC_OFFSET_TABLE_REGNUM
)
3078 y
= XEXP (XEXP (x
, 1), 0);
3079 if (GET_CODE (y
) == UNSPEC
3080 && XINT (y
, 1) == 110)
3081 return XVECEXP (y
, 0, 0);
3085 if (GET_CODE (x
) == CONST
)
3088 if (GET_CODE (y
) == UNSPEC
3089 && XINT (y
, 1) == 111)
3090 return XVECEXP (y
, 0, 0);
3097 /* Locate some local-dynamic symbol still in use by this function
3098 so that we can print its name in local-dynamic base patterns. */
3101 get_some_local_dynamic_name ()
3105 if (cfun
->machine
->some_ld_name
)
3106 return cfun
->machine
->some_ld_name
;
3108 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3110 && for_each_rtx (&PATTERN (insn
), get_some_local_dynamic_name_1
, 0))
3111 return cfun
->machine
->some_ld_name
;
3117 get_some_local_dynamic_name_1 (px
, data
)
3119 void *data ATTRIBUTE_UNUSED
;
3123 if (GET_CODE (x
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (x
))
3125 x
= get_pool_constant (x
);
3126 return for_each_rtx (&x
, get_some_local_dynamic_name_1
, 0);
3129 if (GET_CODE (x
) == SYMBOL_REF
3130 && tls_symbolic_operand (x
) == TLS_MODEL_LOCAL_DYNAMIC
)
3132 cfun
->machine
->some_ld_name
= XSTR (x
, 0);
3139 /* Output symbolic constant X in assembler syntax to
3140 stdio stream FILE. */
3143 s390_output_symbolic_const (file
, x
)
3147 switch (GET_CODE (x
))
3152 s390_output_symbolic_const (file
, XEXP (x
, 0));
3156 s390_output_symbolic_const (file
, XEXP (x
, 0));
3157 fprintf (file
, "+");
3158 s390_output_symbolic_const (file
, XEXP (x
, 1));
3162 s390_output_symbolic_const (file
, XEXP (x
, 0));
3163 fprintf (file
, "-");
3164 s390_output_symbolic_const (file
, XEXP (x
, 1));
3171 output_addr_const (file
, x
);
3175 if (XVECLEN (x
, 0) != 1)
3176 output_operand_lossage ("invalid UNSPEC as operand (1)");
3177 switch (XINT (x
, 1))
3181 s390_output_symbolic_const (file
, XVECEXP (x
, 0, 0));
3182 fprintf (file
, "-");
3183 s390_output_symbolic_const (file
, cfun
->machine
->literal_pool_label
);
3186 s390_output_symbolic_const (file
, cfun
->machine
->literal_pool_label
);
3187 fprintf (file
, "-");
3188 s390_output_symbolic_const (file
, XVECEXP (x
, 0, 0));
3191 s390_output_symbolic_const (file
, XVECEXP (x
, 0, 0));
3192 fprintf (file
, "@GOT12");
3195 s390_output_symbolic_const (file
, XVECEXP (x
, 0, 0));
3196 fprintf (file
, "@GOTENT");
3199 s390_output_symbolic_const (file
, XVECEXP (x
, 0, 0));
3200 fprintf (file
, "@GOT");
3203 s390_output_symbolic_const (file
, XVECEXP (x
, 0, 0));
3204 fprintf (file
, "@PLT");
3207 s390_output_symbolic_const (file
, XVECEXP (x
, 0, 0));
3208 fprintf (file
, "@PLT-");
3209 s390_output_symbolic_const (file
, cfun
->machine
->literal_pool_label
);
3212 s390_output_symbolic_const (file
, XVECEXP (x
, 0, 0));
3213 fprintf (file
, "@TLSGD");
3216 assemble_name (file
, get_some_local_dynamic_name ());
3217 fprintf (file
, "@TLSLDM");
3220 s390_output_symbolic_const (file
, XVECEXP (x
, 0, 0));
3221 fprintf (file
, "@DTPOFF");
3224 s390_output_symbolic_const (file
, XVECEXP (x
, 0, 0));
3225 fprintf (file
, "@NTPOFF");
3227 case UNSPEC_GOTNTPOFF
:
3228 s390_output_symbolic_const (file
, XVECEXP (x
, 0, 0));
3229 fprintf (file
, "@GOTNTPOFF");
3231 case UNSPEC_INDNTPOFF
:
3232 s390_output_symbolic_const (file
, XVECEXP (x
, 0, 0));
3233 fprintf (file
, "@INDNTPOFF");
3236 output_operand_lossage ("invalid UNSPEC as operand (2)");
3242 fatal_insn ("UNKNOWN in s390_output_symbolic_const !?", x
);
3247 /* Output address operand ADDR in assembler syntax to
3248 stdio stream FILE. */
3251 print_operand_address (file
, addr
)
3255 struct s390_address ad
;
3257 if (!s390_decompose_address (addr
, &ad
)
3258 || (ad
.base
&& !REG_OK_FOR_BASE_STRICT_P (ad
.base
))
3259 || (ad
.indx
&& !REG_OK_FOR_INDEX_STRICT_P (ad
.indx
)))
3260 output_operand_lossage ("Cannot decompose address.");
3263 s390_output_symbolic_const (file
, ad
.disp
);
3265 fprintf (file
, "0");
3267 if (ad
.base
&& ad
.indx
)
3268 fprintf (file
, "(%s,%s)", reg_names
[REGNO (ad
.indx
)],
3269 reg_names
[REGNO (ad
.base
)]);
3271 fprintf (file
, "(%s)", reg_names
[REGNO (ad
.base
)]);
3274 /* Output operand X in assembler syntax to stdio stream FILE.
3275 CODE specified the format flag. The following format flags
3278 'C': print opcode suffix for branch condition.
3279 'D': print opcode suffix for inverse branch condition.
3280 'J': print tls_load/tls_gdcall/tls_ldcall suffix
3281 'O': print only the displacement of a memory reference.
3282 'R': print only the base register of a memory reference.
3283 'N': print the second word of a DImode operand.
3284 'M': print the second word of a TImode operand.
3286 'b': print integer X as if it's an unsigned byte.
3287 'x': print integer X as if it's an unsigned word.
3288 'h': print integer X as if it's a signed word. */
3291 print_operand (file
, x
, code
)
3299 fprintf (file
, s390_branch_condition_mnemonic (x
, FALSE
));
3303 fprintf (file
, s390_branch_condition_mnemonic (x
, TRUE
));
3307 if (GET_CODE (x
) == SYMBOL_REF
)
3309 fprintf (file
, "%s", ":tls_load:");
3310 output_addr_const (file
, x
);
3312 else if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_TLSGD
)
3314 fprintf (file
, "%s", ":tls_gdcall:");
3315 output_addr_const (file
, XVECEXP (x
, 0, 0));
3317 else if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == UNSPEC_TLSLDM
)
3319 fprintf (file
, "%s", ":tls_ldcall:");
3320 assemble_name (file
, get_some_local_dynamic_name ());
3328 struct s390_address ad
;
3330 if (GET_CODE (x
) != MEM
3331 || !s390_decompose_address (XEXP (x
, 0), &ad
)
3332 || (ad
.base
&& !REG_OK_FOR_BASE_STRICT_P (ad
.base
))
3337 s390_output_symbolic_const (file
, ad
.disp
);
3339 fprintf (file
, "0");
3345 struct s390_address ad
;
3347 if (GET_CODE (x
) != MEM
3348 || !s390_decompose_address (XEXP (x
, 0), &ad
)
3349 || (ad
.base
&& !REG_OK_FOR_BASE_STRICT_P (ad
.base
))
3354 fprintf (file
, "%s", reg_names
[REGNO (ad
.base
)]);
3356 fprintf (file
, "0");
3361 if (GET_CODE (x
) == REG
)
3362 x
= gen_rtx_REG (GET_MODE (x
), REGNO (x
) + 1);
3363 else if (GET_CODE (x
) == MEM
)
3364 x
= change_address (x
, VOIDmode
, plus_constant (XEXP (x
, 0), 4));
3370 if (GET_CODE (x
) == REG
)
3371 x
= gen_rtx_REG (GET_MODE (x
), REGNO (x
) + 1);
3372 else if (GET_CODE (x
) == MEM
)
3373 x
= change_address (x
, VOIDmode
, plus_constant (XEXP (x
, 0), 8));
3379 switch (GET_CODE (x
))
3382 fprintf (file
, "%s", reg_names
[REGNO (x
)]);
3386 output_address (XEXP (x
, 0));
3393 s390_output_symbolic_const (file
, x
);
3398 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
) & 0xff);
3399 else if (code
== 'x')
3400 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
) & 0xffff);
3401 else if (code
== 'h')
3402 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, ((INTVAL (x
) & 0xffff) ^ 0x8000) - 0x8000);
3404 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
));
3408 if (GET_MODE (x
) != VOIDmode
)
3411 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, CONST_DOUBLE_LOW (x
) & 0xff);
3412 else if (code
== 'x')
3413 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, CONST_DOUBLE_LOW (x
) & 0xffff);
3414 else if (code
== 'h')
3415 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, ((CONST_DOUBLE_LOW (x
) & 0xffff) ^ 0x8000) - 0x8000);
3421 fatal_insn ("UNKNOWN in print_operand !?", x
);
3426 /* Target hook for assembling integer objects. We need to define it
3427 here to work a round a bug in some versions of GAS, which couldn't
3428 handle values smaller than INT_MIN when printed in decimal. */
3431 s390_assemble_integer (x
, size
, aligned_p
)
3436 if (size
== 8 && aligned_p
3437 && GET_CODE (x
) == CONST_INT
&& INTVAL (x
) < INT_MIN
)
3439 fputs ("\t.quad\t", asm_out_file
);
3440 fprintf (asm_out_file
, HOST_WIDE_INT_PRINT_HEX
, INTVAL (x
));
3441 putc ('\n', asm_out_file
);
3444 return default_assemble_integer (x
, size
, aligned_p
);
3447 /* Returns true if register REGNO is used for forming
3448 a memory address in expression X. */
3451 reg_used_in_mem_p (regno
, x
)
3455 enum rtx_code code
= GET_CODE (x
);
3461 if (refers_to_regno_p (regno
, regno
+1,
3465 else if (code
== SET
3466 && GET_CODE (SET_DEST (x
)) == PC
)
3468 if (refers_to_regno_p (regno
, regno
+1,
3473 fmt
= GET_RTX_FORMAT (code
);
3474 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3477 && reg_used_in_mem_p (regno
, XEXP (x
, i
)))
3480 else if (fmt
[i
] == 'E')
3481 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3482 if (reg_used_in_mem_p (regno
, XVECEXP (x
, i
, j
)))
3488 /* Returns true if expression DEP_RTX sets an address register
3489 used by instruction INSN to address memory. */
3492 addr_generation_dependency_p (dep_rtx
, insn
)
3498 if (GET_CODE (dep_rtx
) == INSN
)
3499 dep_rtx
= PATTERN (dep_rtx
);
3501 if (GET_CODE (dep_rtx
) == SET
)
3503 target
= SET_DEST (dep_rtx
);
3504 if (GET_CODE (target
) == STRICT_LOW_PART
)
3505 target
= XEXP (target
, 0);
3506 while (GET_CODE (target
) == SUBREG
)
3507 target
= SUBREG_REG (target
);
3509 if (GET_CODE (target
) == REG
)
3511 int regno
= REGNO (target
);
3513 if (s390_safe_attr_type (insn
) == TYPE_LA
)
3515 pat
= PATTERN (insn
);
3516 if (GET_CODE (pat
) == PARALLEL
)
3518 if (XVECLEN (pat
, 0) != 2)
3520 pat
= XVECEXP (pat
, 0, 0);
3522 if (GET_CODE (pat
) == SET
)
3523 return refers_to_regno_p (regno
, regno
+1, SET_SRC (pat
), 0);
3527 else if (get_attr_atype (insn
) == ATYPE_AGEN
)
3528 return reg_used_in_mem_p (regno
, PATTERN (insn
));
3534 /* Return 1, if dep_insn sets register used in insn in the agen unit. */
3538 s390_agen_dep_p(dep_insn
, insn
)
3542 rtx dep_rtx
= PATTERN (dep_insn
);
3545 if (GET_CODE (dep_rtx
) == SET
3546 && addr_generation_dependency_p (dep_rtx
, insn
))
3548 else if (GET_CODE (dep_rtx
) == PARALLEL
)
3550 for (i
= 0; i
< XVECLEN (dep_rtx
, 0); i
++)
3552 if (addr_generation_dependency_p (XVECEXP (dep_rtx
, 0, i
), insn
))
3560 /* Return the modified cost of the dependency of instruction INSN
3561 on instruction DEP_INSN through the link LINK. COST is the
3562 default cost of that dependency.
3564 Data dependencies are all handled without delay. However, if a
3565 register is modified and subsequently used as base or index
3566 register of a memory reference, at least 4 cycles need to pass
3567 between setting and using the register to avoid pipeline stalls.
3568 An exception is the LA instruction. An address generated by LA can
3569 be used by introducing only a one cycle stall on the pipeline. */
3572 s390_adjust_cost (insn
, link
, dep_insn
, cost
)
3581 /* If the dependence is an anti-dependence, there is no cost. For an
3582 output dependence, there is sometimes a cost, but it doesn't seem
3583 worth handling those few cases. */
3585 if (REG_NOTE_KIND (link
) != 0)
3588 /* If we can't recognize the insns, we can't really do anything. */
3589 if (recog_memoized (insn
) < 0 || recog_memoized (dep_insn
) < 0)
3592 /* DFA based scheduling checks address dependency in md file. */
3593 if (s390_use_dfa_pipeline_interface ())
3596 dep_rtx
= PATTERN (dep_insn
);
3598 if (GET_CODE (dep_rtx
) == SET
3599 && addr_generation_dependency_p (dep_rtx
, insn
))
3600 cost
+= (s390_safe_attr_type (dep_insn
) == TYPE_LA
) ? 1 : 4;
3601 else if (GET_CODE (dep_rtx
) == PARALLEL
)
3603 for (i
= 0; i
< XVECLEN (dep_rtx
, 0); i
++)
3605 if (addr_generation_dependency_p (XVECEXP (dep_rtx
, 0, i
), insn
))
3606 cost
+= (s390_safe_attr_type (dep_insn
) == TYPE_LA
) ? 1 : 4;
3613 /* The number of instructions that can be issued per cycle. */
3621 /* If the following function returns TRUE, we will use the the DFA
3625 s390_use_dfa_pipeline_interface ()
3627 if (s390_cpu
== PROCESSOR_2064_Z900
)
3633 /* Split all branches that exceed the maximum distance.
3634 Returns true if this created a new literal pool entry.
3636 Code generated by this routine is allowed to use
3637 TEMP_REG as temporary scratch register. If this is
3638 done, TEMP_USED is set to true. */
3641 s390_split_branches (temp_reg
, temp_used
)
3645 int new_literal
= 0;
3646 rtx insn
, pat
, tmp
, target
;
3649 /* We need correct insn addresses. */
3651 shorten_branches (get_insns ());
3653 /* Find all branches that exceed 64KB, and split them. */
3655 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3657 if (GET_CODE (insn
) != JUMP_INSN
)
3660 pat
= PATTERN (insn
);
3661 if (GET_CODE (pat
) == PARALLEL
&& XVECLEN (pat
, 0) > 2)
3662 pat
= XVECEXP (pat
, 0, 0);
3663 if (GET_CODE (pat
) != SET
|| SET_DEST (pat
) != pc_rtx
)
3666 if (GET_CODE (SET_SRC (pat
)) == LABEL_REF
)
3668 label
= &SET_SRC (pat
);
3670 else if (GET_CODE (SET_SRC (pat
)) == IF_THEN_ELSE
)
3672 if (GET_CODE (XEXP (SET_SRC (pat
), 1)) == LABEL_REF
)
3673 label
= &XEXP (SET_SRC (pat
), 1);
3674 else if (GET_CODE (XEXP (SET_SRC (pat
), 2)) == LABEL_REF
)
3675 label
= &XEXP (SET_SRC (pat
), 2);
3682 if (get_attr_length (insn
) <= (TARGET_64BIT
? 6 : 4))
3689 tmp
= emit_insn_before (gen_rtx_SET (Pmode
, temp_reg
, *label
), insn
);
3690 INSN_ADDRESSES_NEW (tmp
, -1);
3697 tmp
= force_const_mem (Pmode
, *label
);
3698 tmp
= emit_insn_before (gen_rtx_SET (Pmode
, temp_reg
, tmp
), insn
);
3699 INSN_ADDRESSES_NEW (tmp
, -1);
3706 tmp
= gen_rtx_UNSPEC (SImode
, gen_rtvec (1, *label
), 104);
3707 tmp
= gen_rtx_CONST (SImode
, tmp
);
3708 tmp
= force_const_mem (SImode
, tmp
);
3709 tmp
= emit_insn_before (gen_rtx_SET (Pmode
, temp_reg
, tmp
), insn
);
3710 INSN_ADDRESSES_NEW (tmp
, -1);
3712 target
= gen_rtx_REG (Pmode
, BASE_REGISTER
);
3713 target
= gen_rtx_PLUS (Pmode
, target
, temp_reg
);
3716 if (!validate_change (insn
, label
, target
, 0))
3724 /* Find a literal pool symbol referenced in RTX X, and store
3725 it at REF. Will abort if X contains references to more than
3726 one such pool symbol; multiple references to the same symbol
3727 are allowed, however.
3729 The rtx pointed to by REF must be initialized to NULL_RTX
3730 by the caller before calling this routine. */
3733 find_constant_pool_ref (x
, ref
)
3740 if (GET_CODE (x
) == SYMBOL_REF
3741 && CONSTANT_POOL_ADDRESS_P (x
))
3743 if (*ref
== NULL_RTX
)
3749 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
3750 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
3754 find_constant_pool_ref (XEXP (x
, i
), ref
);
3756 else if (fmt
[i
] == 'E')
3758 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3759 find_constant_pool_ref (XVECEXP (x
, i
, j
), ref
);
3764 /* Replace every reference to the literal pool symbol REF
3765 in X by the address ADDR. Fix up MEMs as required. */
3768 replace_constant_pool_ref (x
, ref
, addr
)
3779 /* Literal pool references can only occur inside a MEM ... */
3780 if (GET_CODE (*x
) == MEM
)
3782 rtx memref
= XEXP (*x
, 0);
3786 *x
= replace_equiv_address (*x
, addr
);
3790 if (GET_CODE (memref
) == CONST
3791 && GET_CODE (XEXP (memref
, 0)) == PLUS
3792 && GET_CODE (XEXP (XEXP (memref
, 0), 1)) == CONST_INT
3793 && XEXP (XEXP (memref
, 0), 0) == ref
)
3795 HOST_WIDE_INT off
= INTVAL (XEXP (XEXP (memref
, 0), 1));
3796 *x
= replace_equiv_address (*x
, plus_constant (addr
, off
));
3801 /* ... or a load-address type pattern. */
3802 if (GET_CODE (*x
) == SET
)
3804 rtx addrref
= SET_SRC (*x
);
3808 SET_SRC (*x
) = addr
;
3812 if (GET_CODE (addrref
) == CONST
3813 && GET_CODE (XEXP (addrref
, 0)) == PLUS
3814 && GET_CODE (XEXP (XEXP (addrref
, 0), 1)) == CONST_INT
3815 && XEXP (XEXP (addrref
, 0), 0) == ref
)
3817 HOST_WIDE_INT off
= INTVAL (XEXP (XEXP (addrref
, 0), 1));
3818 SET_SRC (*x
) = plus_constant (addr
, off
);
3823 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
3824 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
3828 replace_constant_pool_ref (&XEXP (*x
, i
), ref
, addr
);
3830 else if (fmt
[i
] == 'E')
3832 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
3833 replace_constant_pool_ref (&XVECEXP (*x
, i
, j
), ref
, addr
);
3838 /* Check whether ADDR is an address that uses the base register,
3839 without actually constituting a literal pool access. (This happens
3840 in 31-bit PIC mode, where the base register is used as anchor for
3841 relative addressing of local symbols.)
3843 Returns 1 if the base register occupies the base slot,
3844 returns 2 if the base register occupies the index slot,
3845 returns 0 if the address is not of this form. */
3848 find_base_register_in_addr (addr
)
3849 struct s390_address
*addr
;
3851 /* If DISP is complex, we might have a literal pool reference. */
3852 if (addr
->disp
&& GET_CODE (addr
->disp
) != CONST_INT
)
3855 if (addr
->base
&& REG_P (addr
->base
) && REGNO (addr
->base
) == BASE_REGISTER
)
3858 if (addr
->indx
&& REG_P (addr
->indx
) && REGNO (addr
->indx
) == BASE_REGISTER
)
3864 /* Return true if X contains an address that uses the base register,
3865 without actually constituting a literal pool access. */
3868 find_base_register_ref (x
)
3872 struct s390_address addr
;
3876 /* Addresses can only occur inside a MEM ... */
3877 if (GET_CODE (x
) == MEM
)
3879 if (s390_decompose_address (XEXP (x
, 0), &addr
)
3880 && find_base_register_in_addr (&addr
))
3884 /* ... or a load-address type pattern. */
3885 if (GET_CODE (x
) == SET
&& GET_CODE (SET_DEST (x
)) == REG
)
3887 if (s390_decompose_address (SET_SRC (x
), &addr
)
3888 && find_base_register_in_addr (&addr
))
3892 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
3893 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
3897 retv
|= find_base_register_ref (XEXP (x
, i
));
3899 else if (fmt
[i
] == 'E')
3901 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3902 retv
|= find_base_register_ref (XVECEXP (x
, i
, j
));
3909 /* If X contains an address that uses the base register,
3910 without actually constituting a literal pool access,
3911 replace the base register with REPL in all such cases.
3913 Handles both MEMs and load address patterns. */
3916 replace_base_register_ref (x
, repl
)
3920 struct s390_address addr
;
3925 /* Addresses can only occur inside a MEM ... */
3926 if (GET_CODE (*x
) == MEM
)
3928 if (s390_decompose_address (XEXP (*x
, 0), &addr
)
3929 && (pos
= find_base_register_in_addr (&addr
)))
3936 new_addr
= addr
.base
;
3938 new_addr
= gen_rtx_PLUS (Pmode
, new_addr
, addr
.indx
);
3940 new_addr
= gen_rtx_PLUS (Pmode
, new_addr
, addr
.disp
);
3942 *x
= replace_equiv_address (*x
, new_addr
);
3947 /* ... or a load-address type pattern. */
3948 if (GET_CODE (*x
) == SET
&& GET_CODE (SET_DEST (*x
)) == REG
)
3950 if (s390_decompose_address (SET_SRC (*x
), &addr
)
3951 && (pos
= find_base_register_in_addr (&addr
)))
3958 new_addr
= addr
.base
;
3960 new_addr
= gen_rtx_PLUS (Pmode
, new_addr
, addr
.indx
);
3962 new_addr
= gen_rtx_PLUS (Pmode
, new_addr
, addr
.disp
);
3964 SET_SRC (*x
) = new_addr
;
3969 fmt
= GET_RTX_FORMAT (GET_CODE (*x
));
3970 for (i
= GET_RTX_LENGTH (GET_CODE (*x
)) - 1; i
>= 0; i
--)
3974 replace_base_register_ref (&XEXP (*x
, i
), repl
);
3976 else if (fmt
[i
] == 'E')
3978 for (j
= 0; j
< XVECLEN (*x
, i
); j
++)
3979 replace_base_register_ref (&XVECEXP (*x
, i
, j
), repl
);
3985 /* We keep a list of constants we which we have to add to internal
3986 constant tables in the middle of large functions. */
3988 #define NR_C_MODES 6
3989 enum machine_mode constant_modes
[NR_C_MODES
] =
3997 rtx (*gen_consttable
[NR_C_MODES
])(rtx
) =
3999 gen_consttable_df
, gen_consttable_di
,
4000 gen_consttable_sf
, gen_consttable_si
,
4007 struct constant
*next
;
4012 struct constant_pool
4014 struct constant_pool
*next
;
4019 struct constant
*constants
[NR_C_MODES
];
4025 static struct constant_pool
* s390_chunkify_start
PARAMS ((rtx
, bool *));
4026 static void s390_chunkify_finish
PARAMS ((struct constant_pool
*, rtx
));
4027 static void s390_chunkify_cancel
PARAMS ((struct constant_pool
*));
4029 static struct constant_pool
*s390_start_pool
PARAMS ((struct constant_pool
**, rtx
));
4030 static void s390_end_pool
PARAMS ((struct constant_pool
*, rtx
));
4031 static void s390_add_pool_insn
PARAMS ((struct constant_pool
*, rtx
));
4032 static struct constant_pool
*s390_find_pool
PARAMS ((struct constant_pool
*, rtx
));
4033 static void s390_add_constant
PARAMS ((struct constant_pool
*, rtx
, enum machine_mode
));
4034 static rtx s390_find_constant
PARAMS ((struct constant_pool
*, rtx
, enum machine_mode
));
4035 static void s390_add_anchor
PARAMS ((struct constant_pool
*));
4036 static rtx s390_dump_pool
PARAMS ((struct constant_pool
*));
4037 static void s390_free_pool
PARAMS ((struct constant_pool
*));
4039 /* Create new constant pool covering instructions starting at INSN
4040 and chain it to the end of POOL_LIST. */
4042 static struct constant_pool
*
4043 s390_start_pool (pool_list
, insn
)
4044 struct constant_pool
**pool_list
;
4047 struct constant_pool
*pool
, **prev
;
4050 pool
= (struct constant_pool
*) xmalloc (sizeof *pool
);
4052 for (i
= 0; i
< NR_C_MODES
; i
++)
4053 pool
->constants
[i
] = NULL
;
4055 pool
->label
= gen_label_rtx ();
4056 pool
->first_insn
= insn
;
4057 pool
->pool_insn
= NULL_RTX
;
4058 pool
->insns
= BITMAP_XMALLOC ();
4060 pool
->anchor
= FALSE
;
4062 for (prev
= pool_list
; *prev
; prev
= &(*prev
)->next
)
4069 /* End range of instructions covered by POOL at INSN and emit
4070 placeholder insn representing the pool. */
4073 s390_end_pool (pool
, insn
)
4074 struct constant_pool
*pool
;
4077 rtx pool_size
= GEN_INT (pool
->size
+ 8 /* alignment slop */);
4080 insn
= get_last_insn ();
4082 pool
->pool_insn
= emit_insn_after (gen_pool (pool_size
), insn
);
4083 INSN_ADDRESSES_NEW (pool
->pool_insn
, -1);
4086 /* Add INSN to the list of insns covered by POOL. */
4089 s390_add_pool_insn (pool
, insn
)
4090 struct constant_pool
*pool
;
4093 bitmap_set_bit (pool
->insns
, INSN_UID (insn
));
4096 /* Return pool out of POOL_LIST that covers INSN. */
4098 static struct constant_pool
*
4099 s390_find_pool (pool_list
, insn
)
4100 struct constant_pool
*pool_list
;
4103 struct constant_pool
*pool
;
4105 for (pool
= pool_list
; pool
; pool
= pool
->next
)
4106 if (bitmap_bit_p (pool
->insns
, INSN_UID (insn
)))
4112 /* Add constant VAL of mode MODE to the constant pool POOL. */
4115 s390_add_constant (pool
, val
, mode
)
4116 struct constant_pool
*pool
;
4118 enum machine_mode mode
;
4123 for (i
= 0; i
< NR_C_MODES
; i
++)
4124 if (constant_modes
[i
] == mode
)
4126 if (i
== NR_C_MODES
)
4129 for (c
= pool
->constants
[i
]; c
!= NULL
; c
= c
->next
)
4130 if (rtx_equal_p (val
, c
->value
))
4135 c
= (struct constant
*) xmalloc (sizeof *c
);
4137 c
->label
= gen_label_rtx ();
4138 c
->next
= pool
->constants
[i
];
4139 pool
->constants
[i
] = c
;
4140 pool
->size
+= GET_MODE_SIZE (mode
);
4144 /* Find constant VAL of mode MODE in the constant pool POOL.
4145 Return an RTX describing the distance from the start of
4146 the pool to the location of the new constant. */
4149 s390_find_constant (pool
, val
, mode
)
4150 struct constant_pool
*pool
;
4152 enum machine_mode mode
;
4158 for (i
= 0; i
< NR_C_MODES
; i
++)
4159 if (constant_modes
[i
] == mode
)
4161 if (i
== NR_C_MODES
)
4164 for (c
= pool
->constants
[i
]; c
!= NULL
; c
= c
->next
)
4165 if (rtx_equal_p (val
, c
->value
))
4171 offset
= gen_rtx_MINUS (Pmode
, gen_rtx_LABEL_REF (Pmode
, c
->label
),
4172 gen_rtx_LABEL_REF (Pmode
, pool
->label
));
4173 offset
= gen_rtx_CONST (Pmode
, offset
);
4177 /* Set 'anchor' flag in POOL. */
4180 s390_add_anchor (pool
)
4181 struct constant_pool
*pool
;
4185 pool
->anchor
= TRUE
;
4190 /* Dump out the constants in POOL. */
4193 s390_dump_pool (pool
)
4194 struct constant_pool
*pool
;
4200 /* Pool start insn switches to proper section
4201 and guarantees necessary alignment. */
4203 insn
= emit_insn_after (gen_pool_start_64 (), pool
->pool_insn
);
4205 insn
= emit_insn_after (gen_pool_start_31 (), pool
->pool_insn
);
4206 INSN_ADDRESSES_NEW (insn
, -1);
4208 insn
= emit_label_after (pool
->label
, insn
);
4209 INSN_ADDRESSES_NEW (insn
, -1);
4211 /* Emit anchor if we need one. */
4214 rtx anchor
= gen_rtx_LABEL_REF (VOIDmode
, pool
->label
);
4215 anchor
= gen_rtx_UNSPEC (VOIDmode
, gen_rtvec (1, anchor
), 105);
4216 anchor
= gen_rtx_CONST (VOIDmode
, anchor
);
4217 insn
= emit_insn_after (gen_consttable_si (anchor
), insn
);
4218 INSN_ADDRESSES_NEW (insn
, -1);
4221 /* Dump constants in descending alignment requirement order,
4222 ensuring proper alignment for every constant. */
4223 for (i
= 0; i
< NR_C_MODES
; i
++)
4224 for (c
= pool
->constants
[i
]; c
; c
= c
->next
)
4226 /* Convert 104 unspecs to pool-relative references. */
4227 rtx value
= c
->value
;
4228 if (GET_CODE (value
) == CONST
4229 && GET_CODE (XEXP (value
, 0)) == UNSPEC
4230 && XINT (XEXP (value
, 0), 1) == 104
4231 && XVECLEN (XEXP (value
, 0), 0) == 1)
4233 value
= gen_rtx_MINUS (Pmode
, XVECEXP (XEXP (value
, 0), 0, 0),
4234 gen_rtx_LABEL_REF (VOIDmode
, pool
->label
));
4235 value
= gen_rtx_CONST (VOIDmode
, value
);
4238 insn
= emit_label_after (c
->label
, insn
);
4239 INSN_ADDRESSES_NEW (insn
, -1);
4240 insn
= emit_insn_after (gen_consttable
[i
] (value
), insn
);
4241 INSN_ADDRESSES_NEW (insn
, -1);
4244 /* Pool end insn switches back to previous section
4245 and guarantees necessary alignment. */
4247 insn
= emit_insn_after (gen_pool_end_64 (), insn
);
4249 insn
= emit_insn_after (gen_pool_end_31 (), insn
);
4250 INSN_ADDRESSES_NEW (insn
, -1);
4252 insn
= emit_barrier_after (insn
);
4253 INSN_ADDRESSES_NEW (insn
, -1);
4255 /* Remove placeholder insn. */
4256 remove_insn (pool
->pool_insn
);
4261 /* Free all memory used by POOL. */
4264 s390_free_pool (pool
)
4265 struct constant_pool
*pool
;
4269 for (i
= 0; i
< NR_C_MODES
; i
++)
4271 struct constant
*c
= pool
->constants
[i
];
4274 struct constant
*next
= c
->next
;
4280 BITMAP_XFREE (pool
->insns
);
4285 /* Chunkify the literal pool if required.
4287 Code generated by this routine is allowed to use
4288 TEMP_REG as temporary scratch register. If this is
4289 done, TEMP_USED is set to true. */
4291 #define S390_POOL_CHUNK_MIN 0xc00
4292 #define S390_POOL_CHUNK_MAX 0xe00
4294 static struct constant_pool
*
4295 s390_chunkify_start (temp_reg
, temp_used
)
4299 rtx base_reg
= gen_rtx_REG (Pmode
, BASE_REGISTER
);
4301 struct constant_pool
*curr_pool
= NULL
, *pool_list
= NULL
;
4306 rtx (*gen_reload_base
) PARAMS ((rtx
, rtx
)) =
4307 TARGET_64BIT
? gen_reload_base_64
: gen_reload_base_31
;
4310 /* Do we need to chunkify the literal pool? */
4312 if (get_pool_size () < S390_POOL_CHUNK_MAX
)
4315 /* We need correct insn addresses. */
4317 shorten_branches (get_insns ());
4319 /* Scan all insns and move literals to pool chunks.
4320 Also, emit anchor reload insns before every insn that uses
4321 the literal pool base register as anchor pointer. */
4323 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
4325 if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
4327 rtx pool_ref
= NULL_RTX
;
4328 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
4332 curr_pool
= s390_start_pool (&pool_list
, insn
);
4334 s390_add_constant (curr_pool
, get_pool_constant (pool_ref
),
4335 get_pool_mode (pool_ref
));
4336 s390_add_pool_insn (curr_pool
, insn
);
4339 else if (!TARGET_64BIT
&& flag_pic
4340 && find_base_register_ref (PATTERN (insn
)))
4342 rtx
new = gen_reload_anchor (temp_reg
, base_reg
);
4343 new = emit_insn_before (new, insn
);
4344 INSN_ADDRESSES_NEW (new, INSN_ADDRESSES (INSN_UID (insn
)));
4349 curr_pool
= s390_start_pool (&pool_list
, new);
4351 s390_add_anchor (curr_pool
);
4352 s390_add_pool_insn (curr_pool
, insn
);
4356 if (GET_CODE (insn
) == JUMP_INSN
|| GET_CODE (insn
) == CODE_LABEL
)
4358 s390_add_pool_insn (curr_pool
, insn
);
4361 || INSN_ADDRESSES_SIZE () <= (size_t) INSN_UID (insn
)
4362 || INSN_ADDRESSES (INSN_UID (insn
)) == -1)
4367 if (curr_pool
->size
< S390_POOL_CHUNK_MAX
)
4370 s390_end_pool (curr_pool
, NULL_RTX
);
4375 int chunk_size
= INSN_ADDRESSES (INSN_UID (insn
))
4376 - INSN_ADDRESSES (INSN_UID (curr_pool
->first_insn
))
4379 /* We will later have to insert base register reload insns.
4380 Those will have an effect on code size, which we need to
4381 consider here. This calculation makes rather pessimistic
4382 worst-case assumptions. */
4383 if (GET_CODE (insn
) == CODE_LABEL
)
4386 if (chunk_size
< S390_POOL_CHUNK_MIN
4387 && curr_pool
->size
< S390_POOL_CHUNK_MIN
)
4390 /* Pool chunks can only be inserted after BARRIERs ... */
4391 if (GET_CODE (insn
) == BARRIER
)
4393 s390_end_pool (curr_pool
, insn
);
4398 /* ... so if we don't find one in time, create one. */
4399 else if ((chunk_size
> S390_POOL_CHUNK_MAX
4400 || curr_pool
->size
> S390_POOL_CHUNK_MAX
))
4402 rtx label
, jump
, barrier
;
4404 /* We can insert the barrier only after a 'real' insn. */
4405 if (GET_CODE (insn
) != INSN
&& GET_CODE (insn
) != CALL_INSN
)
4407 if (get_attr_length (insn
) == 0)
4410 /* Don't separate insns created by s390_split_branches. */
4411 if (GET_CODE (insn
) == INSN
4412 && GET_CODE (PATTERN (insn
)) == SET
4413 && rtx_equal_p (SET_DEST (PATTERN (insn
)), temp_reg
))
4416 label
= gen_label_rtx ();
4417 jump
= emit_jump_insn_after (gen_jump (label
), insn
);
4418 barrier
= emit_barrier_after (jump
);
4419 insn
= emit_label_after (label
, barrier
);
4420 JUMP_LABEL (jump
) = label
;
4421 LABEL_NUSES (label
) = 1;
4423 INSN_ADDRESSES_NEW (jump
, -1);
4424 INSN_ADDRESSES_NEW (barrier
, -1);
4425 INSN_ADDRESSES_NEW (insn
, -1);
4427 s390_end_pool (curr_pool
, barrier
);
4435 s390_end_pool (curr_pool
, NULL_RTX
);
4438 /* Find all labels that are branched into
4439 from an insn belonging to a different chunk. */
4441 far_labels
= BITMAP_XMALLOC ();
4443 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
4445 /* Labels marked with LABEL_PRESERVE_P can be target
4446 of non-local jumps, so we have to mark them.
4447 The same holds for named labels.
4449 Don't do that, however, if it is the label before
4452 if (GET_CODE (insn
) == CODE_LABEL
4453 && (LABEL_PRESERVE_P (insn
) || LABEL_NAME (insn
)))
4455 rtx vec_insn
= next_real_insn (insn
);
4456 rtx vec_pat
= vec_insn
&& GET_CODE (vec_insn
) == JUMP_INSN
?
4457 PATTERN (vec_insn
) : NULL_RTX
;
4459 || !(GET_CODE (vec_pat
) == ADDR_VEC
4460 || GET_CODE (vec_pat
) == ADDR_DIFF_VEC
))
4461 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (insn
));
4464 /* If we have a direct jump (conditional or unconditional)
4465 or a casesi jump, check all potential targets. */
4466 else if (GET_CODE (insn
) == JUMP_INSN
)
4468 rtx pat
= PATTERN (insn
);
4469 if (GET_CODE (pat
) == PARALLEL
&& XVECLEN (pat
, 0) > 2)
4470 pat
= XVECEXP (pat
, 0, 0);
4472 if (GET_CODE (pat
) == SET
)
4474 rtx label
= JUMP_LABEL (insn
);
4477 if (s390_find_pool (pool_list
, label
)
4478 != s390_find_pool (pool_list
, insn
))
4479 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (label
));
4482 else if (GET_CODE (pat
) == PARALLEL
4483 && XVECLEN (pat
, 0) == 2
4484 && GET_CODE (XVECEXP (pat
, 0, 0)) == SET
4485 && GET_CODE (XVECEXP (pat
, 0, 1)) == USE
4486 && GET_CODE (XEXP (XVECEXP (pat
, 0, 1), 0)) == LABEL_REF
)
4488 /* Find the jump table used by this casesi jump. */
4489 rtx vec_label
= XEXP (XEXP (XVECEXP (pat
, 0, 1), 0), 0);
4490 rtx vec_insn
= next_real_insn (vec_label
);
4491 rtx vec_pat
= vec_insn
&& GET_CODE (vec_insn
) == JUMP_INSN
?
4492 PATTERN (vec_insn
) : NULL_RTX
;
4494 && (GET_CODE (vec_pat
) == ADDR_VEC
4495 || GET_CODE (vec_pat
) == ADDR_DIFF_VEC
))
4497 int i
, diff_p
= GET_CODE (vec_pat
) == ADDR_DIFF_VEC
;
4499 for (i
= 0; i
< XVECLEN (vec_pat
, diff_p
); i
++)
4501 rtx label
= XEXP (XVECEXP (vec_pat
, diff_p
, i
), 0);
4503 if (s390_find_pool (pool_list
, label
)
4504 != s390_find_pool (pool_list
, insn
))
4505 bitmap_set_bit (far_labels
, CODE_LABEL_NUMBER (label
));
4512 /* Insert base register reload insns before every pool. */
4514 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
4516 rtx new_insn
= gen_reload_base (base_reg
, curr_pool
->label
);
4517 rtx insn
= curr_pool
->first_insn
;
4518 INSN_ADDRESSES_NEW (emit_insn_before (new_insn
, insn
), -1);
4521 /* Insert base register reload insns at every far label. */
4523 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
4524 if (GET_CODE (insn
) == CODE_LABEL
4525 && bitmap_bit_p (far_labels
, CODE_LABEL_NUMBER (insn
)))
4527 struct constant_pool
*pool
= s390_find_pool (pool_list
, insn
);
4530 rtx new_insn
= gen_reload_base (base_reg
, pool
->label
);
4531 INSN_ADDRESSES_NEW (emit_insn_after (new_insn
, insn
), -1);
4536 BITMAP_XFREE (far_labels
);
4539 /* Recompute insn addresses. */
4541 init_insn_lengths ();
4542 shorten_branches (get_insns ());
4547 /* POOL_LIST is a chunk list as prepared by s390_chunkify_start.
4548 After we have decided to use this list, finish implementing
4549 all changes to the current function as required.
4551 Code generated by this routine is allowed to use
4552 TEMP_REG as temporary scratch register. */
4555 s390_chunkify_finish (pool_list
, temp_reg
)
4556 struct constant_pool
*pool_list
;
4559 rtx base_reg
= gen_rtx_REG (Pmode
, BASE_REGISTER
);
4560 struct constant_pool
*curr_pool
= NULL
;
4564 /* Replace all literal pool references. */
4566 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
4568 curr_pool
= s390_find_pool (pool_list
, insn
);
4572 if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == CALL_INSN
)
4574 rtx addr
, pool_ref
= NULL_RTX
;
4575 find_constant_pool_ref (PATTERN (insn
), &pool_ref
);
4578 addr
= s390_find_constant (curr_pool
, get_pool_constant (pool_ref
),
4579 get_pool_mode (pool_ref
));
4580 addr
= gen_rtx_PLUS (Pmode
, base_reg
, addr
);
4581 replace_constant_pool_ref (&PATTERN (insn
), pool_ref
, addr
);
4582 INSN_CODE (insn
) = -1;
4585 else if (!TARGET_64BIT
&& flag_pic
4586 && find_base_register_ref (PATTERN (insn
)))
4588 replace_base_register_ref (&PATTERN (insn
), temp_reg
);
4593 /* Dump out all literal pools. */
4595 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
4596 s390_dump_pool (curr_pool
);
4598 /* Free pool list. */
4602 struct constant_pool
*next
= pool_list
->next
;
4603 s390_free_pool (pool_list
);
4608 /* POOL_LIST is a chunk list as prepared by s390_chunkify_start.
4609 We have decided we cannot use this list, so revert all changes
4610 to the current function that were done by s390_chunkify_start. */
4613 s390_chunkify_cancel (pool_list
)
4614 struct constant_pool
*pool_list
;
4616 struct constant_pool
*curr_pool
= NULL
;
4619 /* Remove all pool placeholder insns. */
4621 for (curr_pool
= pool_list
; curr_pool
; curr_pool
= curr_pool
->next
)
4623 /* Did we insert an extra barrier? Remove it. */
4624 rtx barrier
= PREV_INSN (curr_pool
->pool_insn
);
4625 rtx jump
= barrier
? PREV_INSN (barrier
) : NULL_RTX
;
4626 rtx label
= NEXT_INSN (curr_pool
->pool_insn
);
4628 if (jump
&& GET_CODE (jump
) == JUMP_INSN
4629 && barrier
&& GET_CODE (barrier
) == BARRIER
4630 && label
&& GET_CODE (label
) == CODE_LABEL
4631 && GET_CODE (PATTERN (jump
)) == SET
4632 && SET_DEST (PATTERN (jump
)) == pc_rtx
4633 && GET_CODE (SET_SRC (PATTERN (jump
))) == LABEL_REF
4634 && XEXP (SET_SRC (PATTERN (jump
)), 0) == label
)
4637 remove_insn (barrier
);
4638 remove_insn (label
);
4641 remove_insn (curr_pool
->pool_insn
);
4644 /* Remove all base/anchor register reload insns. */
4646 for (insn
= get_insns (); insn
; )
4648 rtx next_insn
= NEXT_INSN (insn
);
4650 if (GET_CODE (insn
) == INSN
4651 && GET_CODE (PATTERN (insn
)) == SET
4652 && GET_CODE (SET_SRC (PATTERN (insn
))) == UNSPEC
4653 && (XINT (SET_SRC (PATTERN (insn
)), 1) == 210
4654 || XINT (SET_SRC (PATTERN (insn
)), 1) == 211))
4660 /* Free pool list. */
4664 struct constant_pool
*next
= pool_list
->next
;
4665 s390_free_pool (pool_list
);
4671 /* Index of constant pool chunk that is currently being processed.
4672 Set to -1 before function output has started. */
4673 int s390_pool_count
= -1;
4675 /* Number of elements of current constant pool. */
4676 int s390_nr_constants
;
4678 /* Output main constant pool to stdio stream FILE. */
4681 s390_output_constant_pool (start_label
, end_label
)
4687 readonly_data_section ();
4688 ASM_OUTPUT_ALIGN (asm_out_file
, 3);
4689 (*targetm
.asm_out
.internal_label
) (asm_out_file
, "L",
4690 CODE_LABEL_NUMBER (start_label
));
4694 (*targetm
.asm_out
.internal_label
) (asm_out_file
, "L",
4695 CODE_LABEL_NUMBER (start_label
));
4696 ASM_OUTPUT_ALIGN (asm_out_file
, 2);
4699 s390_pool_count
= 0;
4700 output_constant_pool (current_function_name
, current_function_decl
);
4701 s390_pool_count
= -1;
4703 function_section (current_function_decl
);
4706 ASM_OUTPUT_ALIGN (asm_out_file
, 1);
4707 (*targetm
.asm_out
.internal_label
) (asm_out_file
, "L",
4708 CODE_LABEL_NUMBER (end_label
));
4712 /* Rework the prolog/epilog to avoid saving/restoring
4713 registers unnecessarily. If TEMP_REGNO is nonnegative,
4714 it specifies the number of a caller-saved register used
4715 as temporary scratch register by code emitted during
4716 machine dependent reorg. */
4719 s390_optimize_prolog (temp_regno
)
4722 int save_first
, save_last
, restore_first
, restore_last
;
4724 rtx insn
, new_insn
, next_insn
;
4726 /* Recompute regs_ever_live data for special registers. */
4727 regs_ever_live
[BASE_REGISTER
] = 0;
4728 regs_ever_live
[RETURN_REGNUM
] = 0;
4729 regs_ever_live
[STACK_POINTER_REGNUM
] = cfun
->machine
->frame_size
> 0;
4731 /* If there is (possibly) any pool entry, we need to
4732 load the base register.
4733 ??? FIXME: this should be more precise. */
4734 if (get_pool_size ())
4735 regs_ever_live
[BASE_REGISTER
] = 1;
4737 /* In non-leaf functions, the prolog/epilog code relies
4738 on RETURN_REGNUM being saved in any case. */
4739 if (!current_function_is_leaf
)
4740 regs_ever_live
[RETURN_REGNUM
] = 1;
4742 /* We need to save/restore the temporary register. */
4743 if (temp_regno
>= 0)
4744 regs_ever_live
[temp_regno
] = 1;
4747 /* Find first and last gpr to be saved. */
4749 for (i
= 6; i
< 16; i
++)
4750 if (regs_ever_live
[i
])
4753 for (j
= 15; j
> i
; j
--)
4754 if (regs_ever_live
[j
])
4759 /* Nothing to save/restore. */
4760 save_first
= restore_first
= -1;
4761 save_last
= restore_last
= -1;
4765 /* Save/restore from i to j. */
4766 save_first
= restore_first
= i
;
4767 save_last
= restore_last
= j
;
4770 /* Varargs functions need to save gprs 2 to 6. */
4771 if (current_function_stdarg
)
4779 /* If all special registers are in fact used, there's nothing we
4780 can do, so no point in walking the insn list. */
4781 if (i
<= BASE_REGISTER
&& j
>= BASE_REGISTER
4782 && i
<= RETURN_REGNUM
&& j
>= RETURN_REGNUM
)
4786 /* Search for prolog/epilog insns and replace them. */
4788 for (insn
= get_insns (); insn
; insn
= next_insn
)
4790 int first
, last
, off
;
4791 rtx set
, base
, offset
;
4793 next_insn
= NEXT_INSN (insn
);
4795 if (GET_CODE (insn
) != INSN
)
4797 if (GET_CODE (PATTERN (insn
)) != PARALLEL
)
4800 if (store_multiple_operation (PATTERN (insn
), VOIDmode
))
4802 set
= XVECEXP (PATTERN (insn
), 0, 0);
4803 first
= REGNO (SET_SRC (set
));
4804 last
= first
+ XVECLEN (PATTERN (insn
), 0) - 1;
4805 offset
= const0_rtx
;
4806 base
= eliminate_constant_term (XEXP (SET_DEST (set
), 0), &offset
);
4807 off
= INTVAL (offset
) - first
* UNITS_PER_WORD
;
4809 if (GET_CODE (base
) != REG
|| off
< 0)
4811 if (first
> BASE_REGISTER
&& first
> RETURN_REGNUM
)
4813 if (last
< BASE_REGISTER
&& last
< RETURN_REGNUM
)
4816 if (save_first
!= -1)
4818 new_insn
= save_gprs (base
, off
, save_first
, save_last
);
4819 new_insn
= emit_insn_before (new_insn
, insn
);
4820 INSN_ADDRESSES_NEW (new_insn
, -1);
4826 if (load_multiple_operation (PATTERN (insn
), VOIDmode
))
4828 set
= XVECEXP (PATTERN (insn
), 0, 0);
4829 first
= REGNO (SET_DEST (set
));
4830 last
= first
+ XVECLEN (PATTERN (insn
), 0) - 1;
4831 offset
= const0_rtx
;
4832 base
= eliminate_constant_term (XEXP (SET_SRC (set
), 0), &offset
);
4833 off
= INTVAL (offset
) - first
* UNITS_PER_WORD
;
4835 if (GET_CODE (base
) != REG
|| off
< 0)
4837 if (first
> BASE_REGISTER
&& first
> RETURN_REGNUM
)
4839 if (last
< BASE_REGISTER
&& last
< RETURN_REGNUM
)
4842 if (restore_first
!= -1)
4844 new_insn
= restore_gprs (base
, off
, restore_first
, restore_last
);
4845 new_insn
= emit_insn_before (new_insn
, insn
);
4846 INSN_ADDRESSES_NEW (new_insn
, -1);
4854 /* Check whether any insn in the function makes use of the original
4855 value of RETURN_REG (e.g. for __builtin_return_address).
4856 If so, insert an insn reloading that value.
4858 Return true if any such insn was found. */
4861 s390_fixup_clobbered_return_reg (return_reg
)
4864 bool replacement_done
= 0;
4867 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
4869 rtx reg
, off
, new_insn
;
4871 if (GET_CODE (insn
) != INSN
)
4873 if (!reg_referenced_p (return_reg
, PATTERN (insn
)))
4875 if (GET_CODE (PATTERN (insn
)) == PARALLEL
4876 && store_multiple_operation (PATTERN (insn
), VOIDmode
))
4879 if (frame_pointer_needed
)
4880 reg
= hard_frame_pointer_rtx
;
4882 reg
= stack_pointer_rtx
;
4884 off
= GEN_INT (cfun
->machine
->frame_size
+ REGNO (return_reg
) * UNITS_PER_WORD
);
4885 if (INTVAL (off
) >= 4096)
4887 off
= force_const_mem (Pmode
, off
);
4888 new_insn
= gen_rtx_SET (Pmode
, return_reg
, off
);
4889 new_insn
= emit_insn_before (new_insn
, insn
);
4890 INSN_ADDRESSES_NEW (new_insn
, -1);
4894 new_insn
= gen_rtx_MEM (Pmode
, gen_rtx_PLUS (Pmode
, reg
, off
));
4895 new_insn
= gen_rtx_SET (Pmode
, return_reg
, new_insn
);
4896 new_insn
= emit_insn_before (new_insn
, insn
);
4897 INSN_ADDRESSES_NEW (new_insn
, -1);
4899 replacement_done
= 1;
4902 return replacement_done
;
4905 /* Perform machine-dependent processing. */
4908 s390_machine_dependent_reorg (first
)
4909 rtx first ATTRIBUTE_UNUSED
;
4911 bool fixed_up_clobbered_return_reg
= 0;
4912 rtx temp_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
4915 /* Make sure all splits have been performed; splits after
4916 machine_dependent_reorg might confuse insn length counts. */
4917 split_all_insns_noflow ();
4920 /* There are two problematic situations we need to correct:
4922 - the literal pool might be > 4096 bytes in size, so that
4923 some of its elements cannot be directly accessed
4925 - a branch target might be > 64K away from the branch, so that
4926 it is not possible to use a PC-relative instruction.
4928 To fix those, we split the single literal pool into multiple
4929 pool chunks, reloading the pool base register at various
4930 points throughout the function to ensure it always points to
4931 the pool chunk the following code expects, and / or replace
4932 PC-relative branches by absolute branches.
4934 However, the two problems are interdependent: splitting the
4935 literal pool can move a branch further away from its target,
4936 causing the 64K limit to overflow, and on the other hand,
4937 replacing a PC-relative branch by an absolute branch means
4938 we need to put the branch target address into the literal
4939 pool, possibly causing it to overflow.
4941 So, we loop trying to fix up both problems until we manage
4942 to satisfy both conditions at the same time. Note that the
4943 loop is guaranteed to terminate as every pass of the loop
4944 strictly decreases the total number of PC-relative branches
4945 in the function. (This is not completely true as there
4946 might be branch-over-pool insns introduced by chunkify_start.
4947 Those never need to be split however.) */
4951 struct constant_pool
*pool_list
;
4953 /* Try to chunkify the literal pool. */
4954 pool_list
= s390_chunkify_start (temp_reg
, &temp_used
);
4956 /* Split out-of-range branches. If this has created new
4957 literal pool entries, cancel current chunk list and
4959 if (s390_split_branches (temp_reg
, &temp_used
))
4962 s390_chunkify_cancel (pool_list
);
4967 /* Check whether we have clobbered a use of the return
4968 register (e.g. for __builtin_return_address). If so,
4969 add insns reloading the register where necessary. */
4970 if (temp_used
&& !fixed_up_clobbered_return_reg
4971 && s390_fixup_clobbered_return_reg (temp_reg
))
4973 fixed_up_clobbered_return_reg
= 1;
4975 /* The fixup insns might have caused a jump to overflow. */
4977 s390_chunkify_cancel (pool_list
);
4982 /* If we made it up to here, both conditions are satisfied.
4983 Finish up pool chunkification if required. */
4985 s390_chunkify_finish (pool_list
, temp_reg
);
4990 s390_optimize_prolog (temp_used
? RETURN_REGNUM
: -1);
4994 /* Return an RTL expression representing the value of the return address
4995 for the frame COUNT steps up from the current frame. FRAME is the
4996 frame pointer of that frame. */
4999 s390_return_addr_rtx (count
, frame
)
5005 /* For the current frame, we use the initial value of RETURN_REGNUM.
5006 This works both in leaf and non-leaf functions. */
5009 return get_hard_reg_initial_val (Pmode
, RETURN_REGNUM
);
5011 /* For frames farther back, we read the stack slot where the
5012 corresponding RETURN_REGNUM value was saved. */
5014 addr
= plus_constant (frame
, RETURN_REGNUM
* UNITS_PER_WORD
);
5015 addr
= memory_address (Pmode
, addr
);
5016 return gen_rtx_MEM (Pmode
, addr
);
5019 /* Find first call clobbered register unsused in a function.
5020 This could be used as base register in a leaf function
5021 or for holding the return address before epilogue. */
5024 find_unused_clobbered_reg ()
5027 for (i
= 0; i
< 6; i
++)
5028 if (!regs_ever_live
[i
])
5033 /* Fill FRAME with info about frame of current function. */
5038 char gprs_ever_live
[16];
5040 HOST_WIDE_INT fsize
= get_frame_size ();
5042 if (fsize
> 0x7fff0000)
5043 fatal_error ("Total size of local variables exceeds architecture limit.");
5045 /* fprs 8 - 15 are caller saved for 64 Bit ABI. */
5046 cfun
->machine
->save_fprs_p
= 0;
5048 for (i
= 24; i
< 32; i
++)
5049 if (regs_ever_live
[i
])
5051 cfun
->machine
->save_fprs_p
= 1;
5055 cfun
->machine
->frame_size
= fsize
+ cfun
->machine
->save_fprs_p
* 64;
5057 /* Does function need to setup frame and save area. */
5059 if (! current_function_is_leaf
5060 || cfun
->machine
->frame_size
> 0
5061 || current_function_calls_alloca
5062 || current_function_stdarg
)
5063 cfun
->machine
->frame_size
+= STARTING_FRAME_OFFSET
;
5065 /* Find first and last gpr to be saved. Note that at this point,
5066 we assume the return register and the base register always
5067 need to be saved. This is done because the usage of these
5068 register might change even after the prolog was emitted.
5069 If it turns out later that we really don't need them, the
5070 prolog/epilog code is modified again. */
5072 for (i
= 0; i
< 16; i
++)
5073 gprs_ever_live
[i
] = regs_ever_live
[i
];
5075 gprs_ever_live
[BASE_REGISTER
] = 1;
5076 gprs_ever_live
[RETURN_REGNUM
] = 1;
5077 gprs_ever_live
[STACK_POINTER_REGNUM
] = cfun
->machine
->frame_size
> 0;
5079 for (i
= 6; i
< 16; i
++)
5080 if (gprs_ever_live
[i
])
5083 for (j
= 15; j
> i
; j
--)
5084 if (gprs_ever_live
[j
])
5088 /* Save / Restore from gpr i to j. */
5089 cfun
->machine
->first_save_gpr
= i
;
5090 cfun
->machine
->first_restore_gpr
= i
;
5091 cfun
->machine
->last_save_gpr
= j
;
5093 /* Varargs functions need to save gprs 2 to 6. */
5094 if (current_function_stdarg
)
5095 cfun
->machine
->first_save_gpr
= 2;
5098 /* Return offset between argument pointer and frame pointer
5099 initially after prologue. */
5102 s390_arg_frame_offset ()
5104 HOST_WIDE_INT fsize
= get_frame_size ();
5107 /* fprs 8 - 15 are caller saved for 64 Bit ABI. */
5110 for (i
= 24; i
< 32; i
++)
5111 if (regs_ever_live
[i
])
5117 fsize
= fsize
+ save_fprs_p
* 64;
5119 /* Does function need to setup frame and save area. */
5121 if (! current_function_is_leaf
5123 || current_function_calls_alloca
5124 || current_function_stdarg
)
5125 fsize
+= STARTING_FRAME_OFFSET
;
5126 return fsize
+ STACK_POINTER_OFFSET
;
5129 /* Emit insn to save fpr REGNUM at offset OFFSET relative
5130 to register BASE. Return generated insn. */
5133 save_fpr (base
, offset
, regnum
)
5139 addr
= gen_rtx_MEM (DFmode
, plus_constant (base
, offset
));
5140 set_mem_alias_set (addr
, s390_sr_alias_set
);
5142 return emit_move_insn (addr
, gen_rtx_REG (DFmode
, regnum
));
5145 /* Emit insn to restore fpr REGNUM from offset OFFSET relative
5146 to register BASE. Return generated insn. */
5149 restore_fpr (base
, offset
, regnum
)
5155 addr
= gen_rtx_MEM (DFmode
, plus_constant (base
, offset
));
5156 set_mem_alias_set (addr
, s390_sr_alias_set
);
5158 return emit_move_insn (gen_rtx_REG (DFmode
, regnum
), addr
);
5161 /* Generate insn to save registers FIRST to LAST into
5162 the register save area located at offset OFFSET
5163 relative to register BASE. */
5166 save_gprs (base
, offset
, first
, last
)
5172 rtx addr
, insn
, note
;
5175 addr
= plus_constant (base
, offset
+ first
* UNITS_PER_WORD
);
5176 addr
= gen_rtx_MEM (Pmode
, addr
);
5177 set_mem_alias_set (addr
, s390_sr_alias_set
);
5179 /* Special-case single register. */
5183 insn
= gen_movdi (addr
, gen_rtx_REG (Pmode
, first
));
5185 insn
= gen_movsi (addr
, gen_rtx_REG (Pmode
, first
));
5187 RTX_FRAME_RELATED_P (insn
) = 1;
5192 insn
= gen_store_multiple (addr
,
5193 gen_rtx_REG (Pmode
, first
),
5194 GEN_INT (last
- first
+ 1));
5197 /* We need to set the FRAME_RELATED flag on all SETs
5198 inside the store-multiple pattern.
5200 However, we must not emit DWARF records for registers 2..5
5201 if they are stored for use by variable arguments ...
5203 ??? Unfortunately, it is not enough to simply not the the
5204 FRAME_RELATED flags for those SETs, because the first SET
5205 of the PARALLEL is always treated as if it had the flag
5206 set, even if it does not. Therefore we emit a new pattern
5207 without those registers as REG_FRAME_RELATED_EXPR note. */
5211 rtx pat
= PATTERN (insn
);
5213 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
5214 if (GET_CODE (XVECEXP (pat
, 0, i
)) == SET
)
5215 RTX_FRAME_RELATED_P (XVECEXP (pat
, 0, i
)) = 1;
5217 RTX_FRAME_RELATED_P (insn
) = 1;
5221 addr
= plus_constant (base
, offset
+ 6 * UNITS_PER_WORD
);
5222 note
= gen_store_multiple (gen_rtx_MEM (Pmode
, addr
),
5223 gen_rtx_REG (Pmode
, 6),
5224 GEN_INT (last
- 6 + 1));
5225 note
= PATTERN (note
);
5228 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR
,
5229 note
, REG_NOTES (insn
));
5231 for (i
= 0; i
< XVECLEN (note
, 0); i
++)
5232 if (GET_CODE (XVECEXP (note
, 0, i
)) == SET
)
5233 RTX_FRAME_RELATED_P (XVECEXP (note
, 0, i
)) = 1;
5235 RTX_FRAME_RELATED_P (insn
) = 1;
5241 /* Generate insn to restore registers FIRST to LAST from
5242 the register save area located at offset OFFSET
5243 relative to register BASE. */
5246 restore_gprs (base
, offset
, first
, last
)
5254 addr
= plus_constant (base
, offset
+ first
* UNITS_PER_WORD
);
5255 addr
= gen_rtx_MEM (Pmode
, addr
);
5256 set_mem_alias_set (addr
, s390_sr_alias_set
);
5258 /* Special-case single register. */
5262 insn
= gen_movdi (gen_rtx_REG (Pmode
, first
), addr
);
5264 insn
= gen_movsi (gen_rtx_REG (Pmode
, first
), addr
);
5269 insn
= gen_load_multiple (gen_rtx_REG (Pmode
, first
),
5271 GEN_INT (last
- first
+ 1));
5275 /* Expand the prologue into a bunch of separate insns. */
5278 s390_emit_prologue ()
5282 rtx pool_start_label
, pool_end_label
;
5285 /* Compute frame_info. */
5289 /* Choose best register to use for temp use within prologue. */
5291 if (!current_function_is_leaf
5292 && !has_hard_reg_initial_val (Pmode
, RETURN_REGNUM
)
5293 && get_pool_size () < S390_POOL_CHUNK_MAX
/ 2)
5294 temp_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
5296 temp_reg
= gen_rtx_REG (Pmode
, 1);
5298 /* Save call saved gprs. */
5300 insn
= save_gprs (stack_pointer_rtx
, 0,
5301 cfun
->machine
->first_save_gpr
, cfun
->machine
->last_save_gpr
);
5304 /* Dump constant pool and set constant pool register. */
5306 pool_start_label
= gen_label_rtx();
5307 pool_end_label
= gen_label_rtx();
5308 cfun
->machine
->literal_pool_label
= pool_start_label
;
5311 insn
= emit_insn (gen_literal_pool_64 (gen_rtx_REG (Pmode
, BASE_REGISTER
),
5312 pool_start_label
, pool_end_label
));
5314 insn
= emit_insn (gen_literal_pool_31 (gen_rtx_REG (Pmode
, BASE_REGISTER
),
5315 pool_start_label
, pool_end_label
));
5317 /* Save fprs for variable args. */
5319 if (current_function_stdarg
)
5321 /* Save fpr 0 and 2. */
5323 save_fpr (stack_pointer_rtx
, STACK_POINTER_OFFSET
- 32, 16);
5324 save_fpr (stack_pointer_rtx
, STACK_POINTER_OFFSET
- 24, 17);
5328 /* Save fpr 4 and 6. */
5330 save_fpr (stack_pointer_rtx
, STACK_POINTER_OFFSET
- 16, 18);
5331 save_fpr (stack_pointer_rtx
, STACK_POINTER_OFFSET
- 8, 19);
5335 /* Save fprs 4 and 6 if used (31 bit ABI). */
5339 /* Save fpr 4 and 6. */
5340 if (regs_ever_live
[18])
5342 insn
= save_fpr (stack_pointer_rtx
, STACK_POINTER_OFFSET
- 16, 18);
5343 RTX_FRAME_RELATED_P (insn
) = 1;
5345 if (regs_ever_live
[19])
5347 insn
= save_fpr (stack_pointer_rtx
, STACK_POINTER_OFFSET
- 8, 19);
5348 RTX_FRAME_RELATED_P (insn
) = 1;
5352 /* Decrement stack pointer. */
5354 if (cfun
->machine
->frame_size
> 0)
5356 rtx frame_off
= GEN_INT (-cfun
->machine
->frame_size
);
5358 /* Save incoming stack pointer into temp reg. */
5360 if (TARGET_BACKCHAIN
|| cfun
->machine
->save_fprs_p
)
5362 insn
= emit_insn (gen_move_insn (temp_reg
, stack_pointer_rtx
));
5365 /* Substract frame size from stack pointer. */
5367 frame_off
= GEN_INT (-cfun
->machine
->frame_size
);
5368 if (!CONST_OK_FOR_LETTER_P (-cfun
->machine
->frame_size
, 'K'))
5369 frame_off
= force_const_mem (Pmode
, frame_off
);
5371 insn
= emit_insn (gen_add2_insn (stack_pointer_rtx
, frame_off
));
5372 RTX_FRAME_RELATED_P (insn
) = 1;
5374 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR
,
5375 gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
5376 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
5377 GEN_INT (-cfun
->machine
->frame_size
))),
5380 /* Set backchain. */
5382 if (TARGET_BACKCHAIN
)
5384 addr
= gen_rtx_MEM (Pmode
, stack_pointer_rtx
);
5385 set_mem_alias_set (addr
, s390_sr_alias_set
);
5386 insn
= emit_insn (gen_move_insn (addr
, temp_reg
));
5390 /* Save fprs 8 - 15 (64 bit ABI). */
5392 if (cfun
->machine
->save_fprs_p
)
5394 insn
= emit_insn (gen_add2_insn (temp_reg
, GEN_INT(-64)));
5396 for (i
= 24; i
< 32; i
++)
5397 if (regs_ever_live
[i
])
5399 rtx addr
= plus_constant (stack_pointer_rtx
,
5400 cfun
->machine
->frame_size
- 64 + (i
-24)*8);
5402 insn
= save_fpr (temp_reg
, (i
-24)*8, i
);
5403 RTX_FRAME_RELATED_P (insn
) = 1;
5405 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR
,
5406 gen_rtx_SET (VOIDmode
,
5407 gen_rtx_MEM (DFmode
, addr
),
5408 gen_rtx_REG (DFmode
, i
)),
5413 /* Set frame pointer, if needed. */
5415 if (frame_pointer_needed
)
5417 insn
= emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
);
5418 RTX_FRAME_RELATED_P (insn
) = 1;
5421 /* Set up got pointer, if needed. */
5423 if (flag_pic
&& regs_ever_live
[PIC_OFFSET_TABLE_REGNUM
])
5425 rtx got_symbol
= gen_rtx_SYMBOL_REF (Pmode
, "_GLOBAL_OFFSET_TABLE_");
5426 SYMBOL_REF_FLAG (got_symbol
) = 1;
5430 insn
= emit_insn (gen_movdi (pic_offset_table_rtx
,
5433 /* It can happen that the GOT pointer isn't really needed ... */
5434 REG_NOTES(insn
) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD
, NULL_RTX
,
5439 got_symbol
= gen_rtx_UNSPEC (VOIDmode
,
5440 gen_rtvec (1, got_symbol
), 100);
5441 got_symbol
= gen_rtx_CONST (VOIDmode
, got_symbol
);
5442 got_symbol
= force_const_mem (Pmode
, got_symbol
);
5443 insn
= emit_move_insn (pic_offset_table_rtx
,
5445 REG_NOTES(insn
) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD
, NULL_RTX
,
5448 insn
= emit_insn (gen_add2_insn (pic_offset_table_rtx
,
5449 gen_rtx_REG (Pmode
, BASE_REGISTER
)));
5450 REG_NOTES(insn
) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD
, NULL_RTX
,
5456 /* Expand the epilogue into a bunch of separate insns. */
5459 s390_emit_epilogue ()
5461 rtx frame_pointer
, return_reg
;
5462 int area_bottom
, area_top
, offset
= 0;
5465 /* Check whether to use frame or stack pointer for restore. */
5467 frame_pointer
= frame_pointer_needed
?
5468 hard_frame_pointer_rtx
: stack_pointer_rtx
;
5470 /* Compute which parts of the save area we need to access. */
5472 if (cfun
->machine
->first_restore_gpr
!= -1)
5474 area_bottom
= cfun
->machine
->first_restore_gpr
* UNITS_PER_WORD
;
5475 area_top
= (cfun
->machine
->last_save_gpr
+ 1) * UNITS_PER_WORD
;
5479 area_bottom
= INT_MAX
;
5485 if (cfun
->machine
->save_fprs_p
)
5487 if (area_bottom
> -64)
5495 if (regs_ever_live
[18])
5497 if (area_bottom
> STACK_POINTER_OFFSET
- 16)
5498 area_bottom
= STACK_POINTER_OFFSET
- 16;
5499 if (area_top
< STACK_POINTER_OFFSET
- 8)
5500 area_top
= STACK_POINTER_OFFSET
- 8;
5502 if (regs_ever_live
[19])
5504 if (area_bottom
> STACK_POINTER_OFFSET
- 8)
5505 area_bottom
= STACK_POINTER_OFFSET
- 8;
5506 if (area_top
< STACK_POINTER_OFFSET
)
5507 area_top
= STACK_POINTER_OFFSET
;
5511 /* Check whether we can access the register save area.
5512 If not, increment the frame pointer as required. */
5514 if (area_top
<= area_bottom
)
5516 /* Nothing to restore. */
5518 else if (cfun
->machine
->frame_size
+ area_bottom
>= 0
5519 && cfun
->machine
->frame_size
+ area_top
<= 4096)
5521 /* Area is in range. */
5522 offset
= cfun
->machine
->frame_size
;
5526 rtx insn
, frame_off
;
5528 offset
= area_bottom
< 0 ? -area_bottom
: 0;
5529 frame_off
= GEN_INT (cfun
->machine
->frame_size
- offset
);
5531 if (!CONST_OK_FOR_LETTER_P (INTVAL (frame_off
), 'K'))
5532 frame_off
= force_const_mem (Pmode
, frame_off
);
5534 insn
= emit_insn (gen_add2_insn (frame_pointer
, frame_off
));
5537 /* Restore call saved fprs. */
5543 if (cfun
->machine
->save_fprs_p
)
5544 for (i
= 24; i
< 32; i
++)
5545 if (regs_ever_live
[i
] && !global_regs
[i
])
5546 restore_fpr (frame_pointer
,
5547 offset
- 64 + (i
-24) * 8, i
);
5551 if (regs_ever_live
[18] && !global_regs
[18])
5552 restore_fpr (frame_pointer
, offset
+ STACK_POINTER_OFFSET
- 16, 18);
5553 if (regs_ever_live
[19] && !global_regs
[19])
5554 restore_fpr (frame_pointer
, offset
+ STACK_POINTER_OFFSET
- 8, 19);
5557 /* Return register. */
5559 return_reg
= gen_rtx_REG (Pmode
, RETURN_REGNUM
);
5561 /* Restore call saved gprs. */
5563 if (cfun
->machine
->first_restore_gpr
!= -1)
5568 /* Check for global register and save them
5569 to stack location from where they get restored. */
5571 for (i
= cfun
->machine
->first_restore_gpr
;
5572 i
<= cfun
->machine
->last_save_gpr
;
5575 /* These registers are special and need to be
5576 restored in any case. */
5577 if (i
== STACK_POINTER_REGNUM
5578 || i
== RETURN_REGNUM
5579 || i
== BASE_REGISTER
5580 || (flag_pic
&& i
== (int)PIC_OFFSET_TABLE_REGNUM
))
5585 addr
= plus_constant (frame_pointer
,
5586 offset
+ i
* UNITS_PER_WORD
);
5587 addr
= gen_rtx_MEM (Pmode
, addr
);
5588 set_mem_alias_set (addr
, s390_sr_alias_set
);
5589 emit_move_insn (addr
, gen_rtx_REG (Pmode
, i
));
5593 /* Fetch return address from stack before load multiple,
5594 this will do good for scheduling. */
5596 if (!current_function_is_leaf
)
5598 int return_regnum
= find_unused_clobbered_reg();
5601 return_reg
= gen_rtx_REG (Pmode
, return_regnum
);
5603 addr
= plus_constant (frame_pointer
,
5604 offset
+ RETURN_REGNUM
* UNITS_PER_WORD
);
5605 addr
= gen_rtx_MEM (Pmode
, addr
);
5606 set_mem_alias_set (addr
, s390_sr_alias_set
);
5607 emit_move_insn (return_reg
, addr
);
5610 /* ??? As references to the base register are not made
5611 explicit in insn RTX code, we have to add a barrier here
5612 to prevent incorrect scheduling. */
5614 emit_insn (gen_blockage());
5616 insn
= restore_gprs (frame_pointer
, offset
,
5617 cfun
->machine
->first_restore_gpr
,
5618 cfun
->machine
->last_save_gpr
);
5622 /* Return to caller. */
5624 p
= rtvec_alloc (2);
5626 RTVEC_ELT (p
, 0) = gen_rtx_RETURN (VOIDmode
);
5627 RTVEC_ELT (p
, 1) = gen_rtx_USE (VOIDmode
, return_reg
);
5628 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode
, p
));
5632 /* Return the size in bytes of a function argument of
5633 type TYPE and/or mode MODE. At least one of TYPE or
5634 MODE must be specified. */
5637 s390_function_arg_size (mode
, type
)
5638 enum machine_mode mode
;
5642 return int_size_in_bytes (type
);
5644 /* No type info available for some library calls ... */
5645 if (mode
!= BLKmode
)
5646 return GET_MODE_SIZE (mode
);
5648 /* If we have neither type nor mode, abort */
5652 /* Return 1 if a function argument of type TYPE and mode MODE
5653 is to be passed by reference. The ABI specifies that only
5654 structures of size 1, 2, 4, or 8 bytes are passed by value,
5655 all other structures (and complex numbers) are passed by
5659 s390_function_arg_pass_by_reference (mode
, type
)
5660 enum machine_mode mode
;
5663 int size
= s390_function_arg_size (mode
, type
);
5667 if (AGGREGATE_TYPE_P (type
) &&
5668 size
!= 1 && size
!= 2 && size
!= 4 && size
!= 8)
5671 if (TREE_CODE (type
) == COMPLEX_TYPE
)
5678 /* Update the data in CUM to advance over an argument of mode MODE and
5679 data type TYPE. (TYPE is null for libcalls where that information
5680 may not be available.). The boolean NAMED specifies whether the
5681 argument is a named argument (as opposed to an unnamed argument
5682 matching an ellipsis). */
5685 s390_function_arg_advance (cum
, mode
, type
, named
)
5686 CUMULATIVE_ARGS
*cum
;
5687 enum machine_mode mode
;
5689 int named ATTRIBUTE_UNUSED
;
5691 if (! TARGET_SOFT_FLOAT
&& (mode
== DFmode
|| mode
== SFmode
))
5695 else if (s390_function_arg_pass_by_reference (mode
, type
))
5701 int size
= s390_function_arg_size (mode
, type
);
5702 cum
->gprs
+= ((size
+ UNITS_PER_WORD
-1) / UNITS_PER_WORD
);
5706 /* Define where to put the arguments to a function.
5707 Value is zero to push the argument on the stack,
5708 or a hard register in which to store the argument.
5710 MODE is the argument's machine mode.
5711 TYPE is the data type of the argument (as a tree).
5712 This is null for libcalls where that information may
5714 CUM is a variable of type CUMULATIVE_ARGS which gives info about
5715 the preceding args and about the function being called.
5716 NAMED is nonzero if this argument is a named parameter
5717 (otherwise it is an extra parameter matching an ellipsis).
5719 On S/390, we use general purpose registers 2 through 6 to
5720 pass integer, pointer, and certain structure arguments, and
5721 floating point registers 0 and 2 (0, 2, 4, and 6 on 64-bit)
5722 to pass floating point arguments. All remaining arguments
5723 are pushed to the stack. */
5726 s390_function_arg (cum
, mode
, type
, named
)
5727 CUMULATIVE_ARGS
*cum
;
5728 enum machine_mode mode
;
5730 int named ATTRIBUTE_UNUSED
;
5732 if (s390_function_arg_pass_by_reference (mode
, type
))
5735 if (! TARGET_SOFT_FLOAT
&& (mode
== DFmode
|| mode
== SFmode
))
5737 if (cum
->fprs
+ 1 > (TARGET_64BIT
? 4 : 2))
5740 return gen_rtx (REG
, mode
, cum
->fprs
+ 16);
5744 int size
= s390_function_arg_size (mode
, type
);
5745 int n_gprs
= (size
+ UNITS_PER_WORD
-1) / UNITS_PER_WORD
;
5747 if (cum
->gprs
+ n_gprs
> 5)
5750 return gen_rtx (REG
, mode
, cum
->gprs
+ 2);
5755 /* Create and return the va_list datatype.
5757 On S/390, va_list is an array type equivalent to
5759 typedef struct __va_list_tag
5763 void *__overflow_arg_area;
5764 void *__reg_save_area;
5768 where __gpr and __fpr hold the number of general purpose
5769 or floating point arguments used up to now, respectively,
5770 __overflow_arg_area points to the stack location of the
5771 next argument passed on the stack, and __reg_save_area
5772 always points to the start of the register area in the
5773 call frame of the current function. The function prologue
5774 saves all registers used for argument passing into this
5775 area if the function uses variable arguments. */
5778 s390_build_va_list ()
5780 tree f_gpr
, f_fpr
, f_ovf
, f_sav
, record
, type_decl
;
5782 record
= (*lang_hooks
.types
.make_type
) (RECORD_TYPE
);
5785 build_decl (TYPE_DECL
, get_identifier ("__va_list_tag"), record
);
5787 f_gpr
= build_decl (FIELD_DECL
, get_identifier ("__gpr"),
5788 long_integer_type_node
);
5789 f_fpr
= build_decl (FIELD_DECL
, get_identifier ("__fpr"),
5790 long_integer_type_node
);
5791 f_ovf
= build_decl (FIELD_DECL
, get_identifier ("__overflow_arg_area"),
5793 f_sav
= build_decl (FIELD_DECL
, get_identifier ("__reg_save_area"),
5796 DECL_FIELD_CONTEXT (f_gpr
) = record
;
5797 DECL_FIELD_CONTEXT (f_fpr
) = record
;
5798 DECL_FIELD_CONTEXT (f_ovf
) = record
;
5799 DECL_FIELD_CONTEXT (f_sav
) = record
;
5801 TREE_CHAIN (record
) = type_decl
;
5802 TYPE_NAME (record
) = type_decl
;
5803 TYPE_FIELDS (record
) = f_gpr
;
5804 TREE_CHAIN (f_gpr
) = f_fpr
;
5805 TREE_CHAIN (f_fpr
) = f_ovf
;
5806 TREE_CHAIN (f_ovf
) = f_sav
;
5808 layout_type (record
);
5810 /* The correct type is an array type of one element. */
5811 return build_array_type (record
, build_index_type (size_zero_node
));
5814 /* Implement va_start by filling the va_list structure VALIST.
5815 STDARG_P is always true, and ignored.
5816 NEXTARG points to the first anonymous stack argument.
5818 The following global variables are used to initialize
5819 the va_list structure:
5821 current_function_args_info:
5822 holds number of gprs and fprs used for named arguments.
5823 current_function_arg_offset_rtx:
5824 holds the offset of the first anonymous stack argument
5825 (relative to the virtual arg pointer). */
5828 s390_va_start (valist
, nextarg
)
5830 rtx nextarg ATTRIBUTE_UNUSED
;
5832 HOST_WIDE_INT n_gpr
, n_fpr
;
5834 tree f_gpr
, f_fpr
, f_ovf
, f_sav
;
5835 tree gpr
, fpr
, ovf
, sav
, t
;
5837 f_gpr
= TYPE_FIELDS (TREE_TYPE (va_list_type_node
));
5838 f_fpr
= TREE_CHAIN (f_gpr
);
5839 f_ovf
= TREE_CHAIN (f_fpr
);
5840 f_sav
= TREE_CHAIN (f_ovf
);
5842 valist
= build1 (INDIRECT_REF
, TREE_TYPE (TREE_TYPE (valist
)), valist
);
5843 gpr
= build (COMPONENT_REF
, TREE_TYPE (f_gpr
), valist
, f_gpr
);
5844 fpr
= build (COMPONENT_REF
, TREE_TYPE (f_fpr
), valist
, f_fpr
);
5845 ovf
= build (COMPONENT_REF
, TREE_TYPE (f_ovf
), valist
, f_ovf
);
5846 sav
= build (COMPONENT_REF
, TREE_TYPE (f_sav
), valist
, f_sav
);
5848 /* Count number of gp and fp argument registers used. */
5850 n_gpr
= current_function_args_info
.gprs
;
5851 n_fpr
= current_function_args_info
.fprs
;
5853 t
= build (MODIFY_EXPR
, TREE_TYPE (gpr
), gpr
, build_int_2 (n_gpr
, 0));
5854 TREE_SIDE_EFFECTS (t
) = 1;
5855 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
5857 t
= build (MODIFY_EXPR
, TREE_TYPE (fpr
), fpr
, build_int_2 (n_fpr
, 0));
5858 TREE_SIDE_EFFECTS (t
) = 1;
5859 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
5861 /* Find the overflow area. */
5862 t
= make_tree (TREE_TYPE (ovf
), virtual_incoming_args_rtx
);
5864 off
= INTVAL (current_function_arg_offset_rtx
);
5865 off
= off
< 0 ? 0 : off
;
5866 if (TARGET_DEBUG_ARG
)
5867 fprintf (stderr
, "va_start: n_gpr = %d, n_fpr = %d off %d\n",
5868 (int)n_gpr
, (int)n_fpr
, off
);
5870 t
= build (PLUS_EXPR
, TREE_TYPE (ovf
), t
, build_int_2 (off
, 0));
5872 t
= build (MODIFY_EXPR
, TREE_TYPE (ovf
), ovf
, t
);
5873 TREE_SIDE_EFFECTS (t
) = 1;
5874 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
5876 /* Find the register save area. */
5877 t
= make_tree (TREE_TYPE (sav
), virtual_incoming_args_rtx
);
5878 t
= build (PLUS_EXPR
, TREE_TYPE (sav
), t
,
5879 build_int_2 (-STACK_POINTER_OFFSET
, -1));
5880 t
= build (MODIFY_EXPR
, TREE_TYPE (sav
), sav
, t
);
5881 TREE_SIDE_EFFECTS (t
) = 1;
5882 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
5885 /* Implement va_arg by updating the va_list structure
5886 VALIST as required to retrieve an argument of type
5887 TYPE, and returning that argument.
5889 Generates code equivalent to:
5891 if (integral value) {
5892 if (size <= 4 && args.gpr < 5 ||
5893 size > 4 && args.gpr < 4 )
5894 ret = args.reg_save_area[args.gpr+8]
5896 ret = *args.overflow_arg_area++;
5897 } else if (float value) {
5899 ret = args.reg_save_area[args.fpr+64]
5901 ret = *args.overflow_arg_area++;
5902 } else if (aggregate value) {
5904 ret = *args.reg_save_area[args.gpr]
5906 ret = **args.overflow_arg_area++;
5910 s390_va_arg (valist
, type
)
5914 tree f_gpr
, f_fpr
, f_ovf
, f_sav
;
5915 tree gpr
, fpr
, ovf
, sav
, reg
, t
, u
;
5916 int indirect_p
, size
, n_reg
, sav_ofs
, sav_scale
, max_reg
;
5917 rtx lab_false
, lab_over
, addr_rtx
, r
;
5919 f_gpr
= TYPE_FIELDS (TREE_TYPE (va_list_type_node
));
5920 f_fpr
= TREE_CHAIN (f_gpr
);
5921 f_ovf
= TREE_CHAIN (f_fpr
);
5922 f_sav
= TREE_CHAIN (f_ovf
);
5924 valist
= build1 (INDIRECT_REF
, TREE_TYPE (TREE_TYPE (valist
)), valist
);
5925 gpr
= build (COMPONENT_REF
, TREE_TYPE (f_gpr
), valist
, f_gpr
);
5926 fpr
= build (COMPONENT_REF
, TREE_TYPE (f_fpr
), valist
, f_fpr
);
5927 ovf
= build (COMPONENT_REF
, TREE_TYPE (f_ovf
), valist
, f_ovf
);
5928 sav
= build (COMPONENT_REF
, TREE_TYPE (f_sav
), valist
, f_sav
);
5930 size
= int_size_in_bytes (type
);
5932 if (s390_function_arg_pass_by_reference (TYPE_MODE (type
), type
))
5934 if (TARGET_DEBUG_ARG
)
5936 fprintf (stderr
, "va_arg: aggregate type");
5940 /* Aggregates are passed by reference. */
5944 sav_ofs
= 2 * UNITS_PER_WORD
;
5945 sav_scale
= UNITS_PER_WORD
;
5946 size
= UNITS_PER_WORD
;
5949 else if (FLOAT_TYPE_P (type
) && ! TARGET_SOFT_FLOAT
)
5951 if (TARGET_DEBUG_ARG
)
5953 fprintf (stderr
, "va_arg: float type");
5957 /* FP args go in FP registers, if present. */
5961 sav_ofs
= 16 * UNITS_PER_WORD
;
5963 /* TARGET_64BIT has up to 4 parameter in fprs */
5964 max_reg
= TARGET_64BIT
? 3 : 1;
5968 if (TARGET_DEBUG_ARG
)
5970 fprintf (stderr
, "va_arg: other type");
5974 /* Otherwise into GP registers. */
5977 n_reg
= (size
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
5978 sav_ofs
= 2 * UNITS_PER_WORD
;
5980 sav_ofs
+= TYPE_MODE (type
) == SImode
? 4 :
5981 TYPE_MODE (type
) == HImode
? 6 :
5982 TYPE_MODE (type
) == QImode
? 7 : 0;
5984 sav_ofs
+= TYPE_MODE (type
) == HImode
? 2 :
5985 TYPE_MODE (type
) == QImode
? 3 : 0;
5987 sav_scale
= UNITS_PER_WORD
;
5994 /* Pull the value out of the saved registers ... */
5996 lab_false
= gen_label_rtx ();
5997 lab_over
= gen_label_rtx ();
5998 addr_rtx
= gen_reg_rtx (Pmode
);
6000 emit_cmp_and_jump_insns (expand_expr (reg
, NULL_RTX
, Pmode
, EXPAND_NORMAL
),
6002 GT
, const1_rtx
, Pmode
, 0, lab_false
);
6005 t
= build (PLUS_EXPR
, ptr_type_node
, sav
, build_int_2 (sav_ofs
, 0));
6009 u
= build (MULT_EXPR
, long_integer_type_node
,
6010 reg
, build_int_2 (sav_scale
, 0));
6011 TREE_SIDE_EFFECTS (u
) = 1;
6013 t
= build (PLUS_EXPR
, ptr_type_node
, t
, u
);
6014 TREE_SIDE_EFFECTS (t
) = 1;
6016 r
= expand_expr (t
, addr_rtx
, Pmode
, EXPAND_NORMAL
);
6018 emit_move_insn (addr_rtx
, r
);
6021 emit_jump_insn (gen_jump (lab_over
));
6023 emit_label (lab_false
);
6025 /* ... Otherwise out of the overflow area. */
6027 t
= save_expr (ovf
);
6030 /* In 64 BIT for each argument on stack, a full 64 bit slot is allocated. */
6031 if (size
< UNITS_PER_WORD
)
6033 t
= build (PLUS_EXPR
, TREE_TYPE (t
), t
, build_int_2 (UNITS_PER_WORD
-size
, 0));
6034 t
= build (MODIFY_EXPR
, TREE_TYPE (ovf
), ovf
, t
);
6035 TREE_SIDE_EFFECTS (t
) = 1;
6036 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
6038 t
= save_expr (ovf
);
6041 r
= expand_expr (t
, addr_rtx
, Pmode
, EXPAND_NORMAL
);
6043 emit_move_insn (addr_rtx
, r
);
6045 t
= build (PLUS_EXPR
, TREE_TYPE (t
), t
, build_int_2 (size
, 0));
6046 t
= build (MODIFY_EXPR
, TREE_TYPE (ovf
), ovf
, t
);
6047 TREE_SIDE_EFFECTS (t
) = 1;
6048 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
6050 emit_label (lab_over
);
6052 /* If less than max_regs a registers are retrieved out
6053 of register save area, increment. */
6055 u
= build (PREINCREMENT_EXPR
, TREE_TYPE (reg
), reg
,
6056 build_int_2 (n_reg
, 0));
6057 TREE_SIDE_EFFECTS (u
) = 1;
6058 expand_expr (u
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
6062 r
= gen_rtx_MEM (Pmode
, addr_rtx
);
6063 set_mem_alias_set (r
, get_varargs_alias_set ());
6064 emit_move_insn (addr_rtx
, r
);
6076 S390_BUILTIN_THREAD_POINTER
,
6077 S390_BUILTIN_SET_THREAD_POINTER
,
6082 static unsigned int const code_for_builtin_64
[S390_BUILTIN_max
] = {
6087 static unsigned int const code_for_builtin_31
[S390_BUILTIN_max
] = {
6093 s390_init_builtins ()
6097 ftype
= build_function_type (ptr_type_node
, void_list_node
);
6098 builtin_function ("__builtin_thread_pointer", ftype
,
6099 S390_BUILTIN_THREAD_POINTER
, BUILT_IN_MD
,
6102 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
6103 builtin_function ("__builtin_set_thread_pointer", ftype
,
6104 S390_BUILTIN_SET_THREAD_POINTER
, BUILT_IN_MD
,
6108 /* Expand an expression EXP that calls a built-in function,
6109 with result going to TARGET if that's convenient
6110 (and in mode MODE if that's convenient).
6111 SUBTARGET may be used as the target for computing one of EXP's operands.
6112 IGNORE is nonzero if the value is to be ignored. */
6115 s390_expand_builtin (exp
, target
, subtarget
, mode
, ignore
)
6118 rtx subtarget ATTRIBUTE_UNUSED
;
6119 enum machine_mode mode ATTRIBUTE_UNUSED
;
6120 int ignore ATTRIBUTE_UNUSED
;
6124 unsigned int const *code_for_builtin
=
6125 TARGET_64BIT
? code_for_builtin_64
: code_for_builtin_31
;
6127 tree fndecl
= TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
6128 unsigned int fcode
= DECL_FUNCTION_CODE (fndecl
);
6129 tree arglist
= TREE_OPERAND (exp
, 1);
6130 enum insn_code icode
;
6131 rtx op
[MAX_ARGS
], pat
;
6135 if (fcode
>= S390_BUILTIN_max
)
6136 internal_error ("bad builtin fcode");
6137 icode
= code_for_builtin
[fcode
];
6139 internal_error ("bad builtin fcode");
6141 nonvoid
= TREE_TYPE (TREE_TYPE (fndecl
)) != void_type_node
;
6143 for (arglist
= TREE_OPERAND (exp
, 1), arity
= 0;
6145 arglist
= TREE_CHAIN (arglist
), arity
++)
6147 const struct insn_operand_data
*insn_op
;
6149 tree arg
= TREE_VALUE (arglist
);
6150 if (arg
== error_mark_node
)
6152 if (arity
> MAX_ARGS
)
6155 insn_op
= &insn_data
[icode
].operand
[arity
+ nonvoid
];
6157 op
[arity
] = expand_expr (arg
, NULL_RTX
, insn_op
->mode
, 0);
6159 if (!(*insn_op
->predicate
) (op
[arity
], insn_op
->mode
))
6160 op
[arity
] = copy_to_mode_reg (insn_op
->mode
, op
[arity
]);
6165 enum machine_mode tmode
= insn_data
[icode
].operand
[0].mode
;
6167 || GET_MODE (target
) != tmode
6168 || !(*insn_data
[icode
].operand
[0].predicate
) (target
, tmode
))
6169 target
= gen_reg_rtx (tmode
);
6175 pat
= GEN_FCN (icode
) (target
);
6179 pat
= GEN_FCN (icode
) (target
, op
[0]);
6181 pat
= GEN_FCN (icode
) (op
[0]);
6184 pat
= GEN_FCN (icode
) (target
, op
[0], op
[1]);
6200 /* Output assembly code for the trampoline template to
6203 On S/390, we use gpr 1 internally in the trampoline code;
6204 gpr 0 is used to hold the static chain. */
6207 s390_trampoline_template (file
)
6212 fprintf (file
, "larl\t%s,0f\n", reg_names
[1]);
6213 fprintf (file
, "lg\t%s,0(%s)\n", reg_names
[0], reg_names
[1]);
6214 fprintf (file
, "lg\t%s,8(%s)\n", reg_names
[1], reg_names
[1]);
6215 fprintf (file
, "br\t%s\n", reg_names
[1]);
6216 fprintf (file
, "0:\t.quad\t0\n");
6217 fprintf (file
, ".quad\t0\n");
6221 fprintf (file
, "basr\t%s,0\n", reg_names
[1]);
6222 fprintf (file
, "l\t%s,10(%s)\n", reg_names
[0], reg_names
[1]);
6223 fprintf (file
, "l\t%s,14(%s)\n", reg_names
[1], reg_names
[1]);
6224 fprintf (file
, "br\t%s\n", reg_names
[1]);
6225 fprintf (file
, ".long\t0\n");
6226 fprintf (file
, ".long\t0\n");
6230 /* Emit RTL insns to initialize the variable parts of a trampoline.
6231 FNADDR is an RTX for the address of the function's pure code.
6232 CXT is an RTX for the static chain value for the function. */
6235 s390_initialize_trampoline (addr
, fnaddr
, cxt
)
6240 emit_move_insn (gen_rtx
6242 memory_address (Pmode
,
6243 plus_constant (addr
, (TARGET_64BIT
? 20 : 12) ))), cxt
);
6244 emit_move_insn (gen_rtx
6246 memory_address (Pmode
,
6247 plus_constant (addr
, (TARGET_64BIT
? 28 : 16) ))), fnaddr
);
6250 /* Return rtx for 64-bit constant formed from the 32-bit subwords
6251 LOW and HIGH, independent of the host word size. */
6254 s390_gen_rtx_const_DI (high
, low
)
6258 #if HOST_BITS_PER_WIDE_INT >= 64
6260 val
= (HOST_WIDE_INT
)high
;
6262 val
|= (HOST_WIDE_INT
)low
;
6264 return GEN_INT (val
);
6266 #if HOST_BITS_PER_WIDE_INT >= 32
6267 return immed_double_const ((HOST_WIDE_INT
)low
, (HOST_WIDE_INT
)high
, DImode
);
6274 /* Output assembler code to FILE to increment profiler label # LABELNO
6275 for profiling a function entry. */
6278 s390_function_profiler (file
, labelno
)
6285 ASM_GENERATE_INTERNAL_LABEL (label
, "LP", labelno
);
6287 fprintf (file
, "# function profiler \n");
6289 op
[0] = gen_rtx_REG (Pmode
, RETURN_REGNUM
);
6290 op
[1] = gen_rtx_REG (Pmode
, STACK_POINTER_REGNUM
);
6291 op
[1] = gen_rtx_MEM (Pmode
, plus_constant (op
[1], UNITS_PER_WORD
));
6293 op
[2] = gen_rtx_REG (Pmode
, 1);
6294 op
[3] = gen_rtx_SYMBOL_REF (Pmode
, label
);
6295 SYMBOL_REF_FLAG (op
[3]) = 1;
6297 op
[4] = gen_rtx_SYMBOL_REF (Pmode
, "_mcount");
6300 op
[4] = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op
[4]), 113);
6301 op
[4] = gen_rtx_CONST (Pmode
, op
[4]);
6306 output_asm_insn ("stg\t%0,%1", op
);
6307 output_asm_insn ("larl\t%2,%3", op
);
6308 output_asm_insn ("brasl\t%0,%4", op
);
6309 output_asm_insn ("lg\t%0,%1", op
);
6313 op
[6] = gen_label_rtx ();
6315 output_asm_insn ("st\t%0,%1", op
);
6316 output_asm_insn ("bras\t%2,%l6", op
);
6317 output_asm_insn (".long\t%4", op
);
6318 output_asm_insn (".long\t%3", op
);
6319 (*targetm
.asm_out
.internal_label
) (file
, "L", CODE_LABEL_NUMBER (op
[6]));
6320 output_asm_insn ("l\t%0,0(%2)", op
);
6321 output_asm_insn ("l\t%2,4(%2)", op
);
6322 output_asm_insn ("basr\t%0,%0", op
);
6323 output_asm_insn ("l\t%0,%1", op
);
6327 op
[5] = gen_label_rtx ();
6328 op
[6] = gen_label_rtx ();
6330 output_asm_insn ("st\t%0,%1", op
);
6331 output_asm_insn ("bras\t%2,%l6", op
);
6332 (*targetm
.asm_out
.internal_label
) (file
, "L", CODE_LABEL_NUMBER (op
[5]));
6333 output_asm_insn (".long\t%4-%l5", op
);
6334 output_asm_insn (".long\t%3-%l5", op
);
6335 (*targetm
.asm_out
.internal_label
) (file
, "L", CODE_LABEL_NUMBER (op
[6]));
6336 output_asm_insn ("lr\t%0,%2", op
);
6337 output_asm_insn ("a\t%0,0(%2)", op
);
6338 output_asm_insn ("a\t%2,4(%2)", op
);
6339 output_asm_insn ("basr\t%0,%0", op
);
6340 output_asm_insn ("l\t%0,%1", op
);
6344 /* Select section for constant in constant pool. In 32-bit mode,
6345 constants go in the function section; in 64-bit mode in .rodata. */
6348 s390_select_rtx_section (mode
, x
, align
)
6349 enum machine_mode mode ATTRIBUTE_UNUSED
;
6350 rtx x ATTRIBUTE_UNUSED
;
6351 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
;
6354 readonly_data_section ();
6356 function_section (current_function_decl
);
6359 /* Encode symbol attributes (local vs. global, tls model) of a SYMBOL_REF
6360 into its name and SYMBOL_REF_FLAG. */
6363 s390_encode_section_info (decl
, first
)
6365 int first ATTRIBUTE_UNUSED
;
6367 bool local_p
= (*targetm
.binds_local_p
) (decl
);
6370 rtl
= DECL_P (decl
) ? DECL_RTL (decl
) : TREE_CST_RTL (decl
);
6371 if (GET_CODE (rtl
) != MEM
)
6373 symbol
= XEXP (rtl
, 0);
6374 if (GET_CODE (symbol
) != SYMBOL_REF
)
6377 /* When using PIC, SYMBOL_REF_FLAG marks non-global symbols
6378 that can be accessed directly. */
6380 SYMBOL_REF_FLAG (symbol
) = local_p
;
6382 /* Encode thread-local data with %[GLil] for "global dynamic",
6383 "local dynamic", "initial exec" or "local exec" TLS models,
6386 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL (decl
))
6388 const char *symbol_str
= XSTR (symbol
, 0);
6391 enum tls_model kind
= decl_tls_model (decl
);
6395 /* We don't allow non-pic code for shared libraries,
6396 so don't generate GD/LD TLS models for non-pic code. */
6399 case TLS_MODEL_GLOBAL_DYNAMIC
:
6400 kind
= TLS_MODEL_INITIAL_EXEC
; break;
6401 case TLS_MODEL_LOCAL_DYNAMIC
:
6402 kind
= TLS_MODEL_LOCAL_EXEC
; break;
6408 if (symbol_str
[0] == '%')
6410 if (symbol_str
[1] == tls_model_chars
[kind
])
6414 len
= strlen (symbol_str
) + 1;
6415 newstr
= alloca (len
+ 2);
6418 newstr
[1] = tls_model_chars
[kind
];
6419 memcpy (newstr
+ 2, symbol_str
, len
);
6421 XSTR (symbol
, 0) = ggc_alloc_string (newstr
, len
+ 2 - 1);
6425 /* Undo the above when printing symbol names. */
6428 s390_strip_name_encoding (str
)
6438 /* Output thunk to FILE that implements a C++ virtual function call (with
6439 multiple inheritance) to FUNCTION. The thunk adjusts the this pointer
6440 by DELTA, and unless VCALL_OFFSET is zero, applies an additional adjustment
6441 stored at VCALL_OFFSET in the vtable whose address is located at offset 0
6442 relative to the resulting this pointer. */
6445 s390_output_mi_thunk (file
, thunk
, delta
, vcall_offset
, function
)
6447 tree thunk ATTRIBUTE_UNUSED
;
6448 HOST_WIDE_INT delta
;
6449 HOST_WIDE_INT vcall_offset
;
6454 /* Operand 0 is the target function. */
6455 op
[0] = XEXP (DECL_RTL (function
), 0);
6456 if (flag_pic
&& !SYMBOL_REF_FLAG (op
[0]))
6458 op
[0] = gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, op
[0]), 113);
6459 op
[0] = gen_rtx_CONST (Pmode
, op
[0]);
6462 /* Operand 1 is the 'this' pointer. */
6463 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function
))))
6464 op
[1] = gen_rtx_REG (Pmode
, 3);
6466 op
[1] = gen_rtx_REG (Pmode
, 2);
6468 /* Operand 2 is the delta. */
6469 op
[2] = GEN_INT (delta
);
6471 /* Operand 3 is the vcall_offset. */
6472 op
[3] = GEN_INT (vcall_offset
);
6474 /* Operand 4 is the temporary register. */
6475 op
[4] = gen_rtx_REG (Pmode
, 1);
6477 /* Operands 5 to 8 can be used as labels. */
6483 /* Generate code. */
6486 /* Setup literal pool pointer if required. */
6487 if (!CONST_OK_FOR_LETTER_P (delta
, 'K')
6488 || !CONST_OK_FOR_LETTER_P (vcall_offset
, 'K'))
6490 op
[5] = gen_label_rtx ();
6491 output_asm_insn ("larl\t%4,%5", op
);
6494 /* Add DELTA to this pointer. */
6497 if (CONST_OK_FOR_LETTER_P (delta
, 'J'))
6498 output_asm_insn ("la\t%1,%2(%1)", op
);
6499 else if (CONST_OK_FOR_LETTER_P (delta
, 'K'))
6500 output_asm_insn ("aghi\t%1,%2", op
);
6503 op
[6] = gen_label_rtx ();
6504 output_asm_insn ("agf\t%1,%6-%5(%4)", op
);
6508 /* Perform vcall adjustment. */
6511 if (CONST_OK_FOR_LETTER_P (vcall_offset
, 'J'))
6513 output_asm_insn ("lg\t%4,0(%1)", op
);
6514 output_asm_insn ("ag\t%1,%3(%4)", op
);
6516 else if (CONST_OK_FOR_LETTER_P (vcall_offset
, 'K'))
6518 output_asm_insn ("lghi\t%4,%3", op
);
6519 output_asm_insn ("ag\t%4,0(%1)", op
);
6520 output_asm_insn ("ag\t%1,0(%4)", op
);
6524 op
[7] = gen_label_rtx ();
6525 output_asm_insn ("llgf\t%4,%7-%5(%4)", op
);
6526 output_asm_insn ("ag\t%4,0(%1)", op
);
6527 output_asm_insn ("ag\t%1,0(%4)", op
);
6531 /* Jump to target. */
6532 output_asm_insn ("jg\t%0", op
);
6534 /* Output literal pool if required. */
6537 output_asm_insn (".align\t4", op
);
6538 (*targetm
.asm_out
.internal_label
) (file
, "L",
6539 CODE_LABEL_NUMBER (op
[5]));
6543 (*targetm
.asm_out
.internal_label
) (file
, "L",
6544 CODE_LABEL_NUMBER (op
[6]));
6545 output_asm_insn (".long\t%2", op
);
6549 (*targetm
.asm_out
.internal_label
) (file
, "L",
6550 CODE_LABEL_NUMBER (op
[7]));
6551 output_asm_insn (".long\t%3", op
);
6556 /* Setup base pointer if required. */
6558 || !CONST_OK_FOR_LETTER_P (delta
, 'K')
6559 || !CONST_OK_FOR_LETTER_P (vcall_offset
, 'K'))
6561 op
[5] = gen_label_rtx ();
6562 output_asm_insn ("basr\t%4,0", op
);
6563 (*targetm
.asm_out
.internal_label
) (file
, "L",
6564 CODE_LABEL_NUMBER (op
[5]));
6567 /* Add DELTA to this pointer. */
6570 if (CONST_OK_FOR_LETTER_P (delta
, 'J'))
6571 output_asm_insn ("la\t%1,%2(%1)", op
);
6572 else if (CONST_OK_FOR_LETTER_P (delta
, 'K'))
6573 output_asm_insn ("ahi\t%1,%2", op
);
6576 op
[6] = gen_label_rtx ();
6577 output_asm_insn ("a\t%1,%6-%5(%4)", op
);
6581 /* Perform vcall adjustment. */
6584 if (CONST_OK_FOR_LETTER_P (vcall_offset
, 'J'))
6586 output_asm_insn ("lg\t%4,0(%1)", op
);
6587 output_asm_insn ("a\t%1,%3(%4)", op
);
6589 else if (CONST_OK_FOR_LETTER_P (vcall_offset
, 'K'))
6591 output_asm_insn ("lhi\t%4,%3", op
);
6592 output_asm_insn ("a\t%4,0(%1)", op
);
6593 output_asm_insn ("a\t%1,0(%4)", op
);
6597 op
[7] = gen_label_rtx ();
6598 output_asm_insn ("l\t%4,%7-%5(%4)", op
);
6599 output_asm_insn ("a\t%4,0(%1)", op
);
6600 output_asm_insn ("a\t%1,0(%4)", op
);
6603 /* We had to clobber the base pointer register.
6604 Re-setup the base pointer (with a different base). */
6605 op
[5] = gen_label_rtx ();
6606 output_asm_insn ("basr\t%4,0", op
);
6607 (*targetm
.asm_out
.internal_label
) (file
, "L",
6608 CODE_LABEL_NUMBER (op
[5]));
6611 /* Jump to target. */
6612 op
[8] = gen_label_rtx ();
6614 output_asm_insn ("l\t%4,%8-%5(%4)", op
);
6616 output_asm_insn ("a\t%4,%8-%5(%4)", op
);
6617 output_asm_insn ("br\t%4", op
);
6619 /* Output literal pool. */
6620 output_asm_insn (".align\t4", op
);
6621 (*targetm
.asm_out
.internal_label
) (file
, "L", CODE_LABEL_NUMBER (op
[8]));
6623 output_asm_insn (".long\t%0", op
);
6625 output_asm_insn (".long\t%0-%5", op
);
6629 (*targetm
.asm_out
.internal_label
) (file
, "L",
6630 CODE_LABEL_NUMBER (op
[6]));
6631 output_asm_insn (".long\t%2", op
);
6635 (*targetm
.asm_out
.internal_label
) (file
, "L",
6636 CODE_LABEL_NUMBER (op
[7]));
6637 output_asm_insn (".long\t%3", op
);
6642 /* How to allocate a 'struct machine_function'. */
6644 static struct machine_function
*
6645 s390_init_machine_status ()
6647 return ggc_alloc_cleared (sizeof (struct machine_function
));
6650 #include "gt-s390.h"