2016-11-10 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / config / ft32 / ft32.c
blob6ac87017f64a6e109e705bfbb4038d3669b9bda5
1 /* Target Code for ft32
2 Copyright (C) 2015-2016 Free Software Foundation, Inc.
3 Contributed by FTDI <support@ftdi.com>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published
9 by the Free Software Foundation; either version 3, or (at your
10 option) any later version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "backend.h"
25 #include "target.h"
26 #include "rtl.h"
27 #include "tree.h"
28 #include "df.h"
29 #include "memmodel.h"
30 #include "tm_p.h"
31 #include "regs.h"
32 #include "emit-rtl.h"
33 #include "diagnostic-core.h"
34 #include "output.h"
35 #include "stor-layout.h"
36 #include "calls.h"
37 #include "expr.h"
38 #include "builtins.h"
39 #include "print-tree.h"
41 /* This file should be included last. */
42 #include "target-def.h"
44 #include <stdint.h>
46 #define LOSE_AND_RETURN(msgid, x) \
47 do \
48 { \
49 ft32_operand_lossage (msgid, x); \
50 return; \
51 } while (0)
53 /* Worker function for TARGET_RETURN_IN_MEMORY. */
55 static bool
56 ft32_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
58 const HOST_WIDE_INT size = int_size_in_bytes (type);
59 return (size == -1 || size > 2 * UNITS_PER_WORD);
62 /* Define how to find the value returned by a function.
63 VALTYPE is the data type of the value (as a tree).
64 If the precise function being called is known, FUNC is its
65 FUNCTION_DECL; otherwise, FUNC is 0.
67 We always return values in register $r0 for ft32. */
69 static rtx
70 ft32_function_value (const_tree valtype,
71 const_tree fntype_or_decl ATTRIBUTE_UNUSED,
72 bool outgoing ATTRIBUTE_UNUSED)
74 return gen_rtx_REG (TYPE_MODE (valtype), FT32_R0);
77 /* Define how to find the value returned by a library function.
79 We always return values in register $r0 for ft32. */
81 static rtx
82 ft32_libcall_value (enum machine_mode mode, const_rtx fun ATTRIBUTE_UNUSED)
84 return gen_rtx_REG (mode, FT32_R0);
87 /* Handle TARGET_FUNCTION_VALUE_REGNO_P.
89 We always return values in register $r0 for ft32. */
91 static bool
92 ft32_function_value_regno_p (const unsigned int regno)
94 return (regno == FT32_R0);
97 /* Emit an error message when we're in an asm, and a fatal error for
98 "normal" insns. Formatted output isn't easily implemented, since we
99 use output_operand_lossage to output the actual message and handle the
100 categorization of the error. */
102 static void
103 ft32_operand_lossage (const char *msgid, rtx op)
105 debug_rtx (op);
106 output_operand_lossage ("%s", msgid);
109 /* The PRINT_OPERAND_ADDRESS worker. */
111 void
112 ft32_print_operand_address (FILE * file, rtx x)
114 switch (GET_CODE (x))
116 case REG:
117 fprintf (file, "%s,0", reg_names[REGNO (x)]);
118 break;
120 case PLUS:
121 switch (GET_CODE (XEXP (x, 1)))
123 case CONST_INT:
124 fprintf (file, "%s,%ld",
125 reg_names[REGNO (XEXP (x, 0))], INTVAL (XEXP (x, 1)));
126 break;
127 case SYMBOL_REF:
128 output_addr_const (file, XEXP (x, 1));
129 fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]);
130 break;
131 case CONST:
133 rtx plus = XEXP (XEXP (x, 1), 0);
134 if (GET_CODE (XEXP (plus, 0)) == SYMBOL_REF
135 && CONST_INT_P (XEXP (plus, 1)))
137 output_addr_const (file, XEXP (plus, 0));
138 fprintf (file, "+%ld(%s)", INTVAL (XEXP (plus, 1)),
139 reg_names[REGNO (XEXP (x, 0))]);
141 else
142 abort ();
144 break;
145 default:
146 abort ();
148 break;
150 default:
151 output_addr_const (file, x);
152 break;
156 /* The PRINT_OPERAND worker. */
158 void
159 ft32_print_operand (FILE * file, rtx x, int code)
161 rtx operand = x;
163 /* New code entries should just be added to the switch below. If
164 handling is finished, just return. If handling was just a
165 modification of the operand, the modified operand should be put in
166 "operand", and then do a break to let default handling
167 (zero-modifier) output the operand. */
169 switch (code)
171 case 0:
172 /* No code, print as usual. */
173 break;
175 case 'h':
176 if (GET_CODE (operand) != REG)
177 internal_error ("'h' applied to non-register operand");
178 fprintf (file, "%s", reg_names[REGNO (operand) + 1]);
179 return;
181 case 'm':
182 fprintf (file, "%ld", (long) (- INTVAL(x)));
183 return;
185 case 'd': // a DW spec, from an integer alignment (for BLKmode insns)
187 int i = INTVAL (x);
188 char dwspec;
189 switch (i)
191 case 1:
192 dwspec = 'b';
193 break;
194 case 2:
195 dwspec = 's';
196 break;
197 case 4:
198 dwspec = 'l';
199 break;
200 default:
201 if ((i % 4) != 0)
202 internal_error ("bad alignment: %d", i);
203 else
204 dwspec = 'l';
205 break;
207 fprintf (file, "%c", dwspec);
208 return;
211 case 'f':
213 int bf = ft32_as_bitfield (INTVAL (x));
214 fprintf (file, "512|(%d<<5)|%d", bf >> 5, bf & 31);
215 return;
218 case 'g':
220 int bf = ft32_as_bitfield (0xffffffff ^ INTVAL (x));
221 fprintf (file, "(%d<<5)|%d", bf >> 5, bf & 31);
222 return;
225 case 'b':
227 ft32_print_operand (file, XEXP (x, 0), 0);
228 return;
231 default:
232 LOSE_AND_RETURN ("invalid operand modifier letter", x);
235 /* Print an operand as without a modifier letter. */
236 switch (GET_CODE (operand))
238 case REG:
239 fprintf (file, "%s", reg_names[REGNO (operand)]);
240 return;
242 case MEM:
243 output_address (GET_MODE (XEXP (operand, 0)), XEXP (operand, 0));
244 return;
246 default:
247 /* No need to handle all strange variants, let output_addr_const
248 do it for us. */
249 if (CONSTANT_P (operand))
251 output_addr_const (file, operand);
252 return;
255 LOSE_AND_RETURN ("unexpected operand", x);
259 const char *
260 ft32_load_immediate (rtx dst, int32_t i)
262 char pattern[100];
264 if ((-524288 <= i) && (i <= 524287))
266 sprintf (pattern, "ldk.l %%0,%d", i);
267 output_asm_insn (pattern, &dst);
269 else if ((-536870912 <= i) && (i <= 536870911))
271 ft32_load_immediate (dst, i >> 10);
272 sprintf (pattern, "ldl.l %%0,%%0,%d", i & 1023);
273 output_asm_insn (pattern, &dst);
275 else
277 int rd; // rotate distance
278 uint32_t u = i;
279 for (rd = 1; rd < 32; rd++)
281 u = ((u >> 31) & 1) | (u << 1);
282 if ((-524288 <= (int32_t) u) && ((int32_t) u <= 524287))
284 ft32_load_immediate (dst, (int32_t) u);
285 sprintf (pattern, "ror.l %%0,%%0,%d", rd);
286 output_asm_insn (pattern, &dst);
287 return "";
290 ft32_load_immediate (dst, i >> 10);
291 sprintf (pattern, "ldl.l %%0,%%0,%d", i & 1023);
292 output_asm_insn (pattern, &dst);
295 return "";
298 // x is a bit mask, for example:
299 // 00000000000000000000001111111110
300 // If x contains a single bit mask, return the bitfield spec.
301 // in the above case it returns ((9 << 5) | 1)
302 // Otherwise return -1.
305 #define NBITS(n) ((1U << (n)) - 1U)
308 ft32_as_bitfield (unsigned int x)
310 int lobit, hibit;
312 if (x == 0)
313 return -1;
315 for (lobit = 0; lobit < 32; lobit++)
316 if (x & (1 << lobit))
317 break;
318 for (hibit = 31; hibit >= 0; hibit--)
319 if (x & (1 << hibit))
320 break;
322 int width = 1 + hibit - lobit;
323 if (width > 16)
324 return -1;
326 if (x != (NBITS (width) << lobit))
327 return -1; // not a clean bitfield
329 return ((width & 15) << 5) | lobit;
332 /* Per-function machine data. */
333 struct GTY (()) machine_function
335 /* Number of bytes saved on the stack for callee saved registers. */
336 int callee_saved_reg_size;
338 /* Number of bytes saved on the stack for local variables. */
339 int local_vars_size;
341 /* The sum of 2 sizes: locals vars and padding byte for saving the
342 * registers. Used in expand_prologue () and expand_epilogue (). */
343 int size_for_adjusting_sp;
346 /* Zero initialization is OK for all current fields. */
348 static struct machine_function *
349 ft32_init_machine_status (void)
351 return ggc_cleared_alloc < machine_function > ();
355 /* The TARGET_OPTION_OVERRIDE worker.
356 All this curently does is set init_machine_status. */
357 static void
358 ft32_option_override (void)
360 /* Set the per-function-data initializer. */
361 init_machine_status = ft32_init_machine_status;
364 /* Implement targetm.select_section. */
365 static section *
366 ft32_select_section (tree decl, int reloc, unsigned HOST_WIDE_INT align)
368 /* Variables and constants defined in the __ea address space
369 go into a special section named "._ea". */
370 if (TREE_TYPE (decl) != error_mark_node
371 && TYPE_ADDR_SPACE (TREE_TYPE (decl)) == ADDR_SPACE_PM)
373 /* We might get called with string constants, but get_named_section
374 doesn't like them as they are not DECLs. Also, we need to set
375 flags in that case. */
376 if (!DECL_P (decl))
377 return get_section ("._pm", SECTION_WRITE | SECTION_DEBUG, NULL);
379 return get_named_section (decl, "._pm", reloc);
382 return default_elf_select_section (decl, reloc, align);
385 /* Compute the size of the local area and the size to be adjusted by the
386 * prologue and epilogue. */
388 static void
389 ft32_compute_frame (void)
391 /* For aligning the local variables. */
392 int stack_alignment = STACK_BOUNDARY / BITS_PER_UNIT;
393 int padding_locals;
394 int regno;
396 /* Padding needed for each element of the frame. */
397 cfun->machine->local_vars_size = get_frame_size ();
399 /* Align to the stack alignment. */
400 padding_locals = cfun->machine->local_vars_size % stack_alignment;
401 if (padding_locals)
402 padding_locals = stack_alignment - padding_locals;
404 cfun->machine->local_vars_size += padding_locals;
406 cfun->machine->callee_saved_reg_size = 0;
408 /* Save callee-saved registers. */
409 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
410 if (df_regs_ever_live_p (regno) && (!call_used_regs[regno]))
411 cfun->machine->callee_saved_reg_size += 4;
413 cfun->machine->size_for_adjusting_sp =
414 0 // crtl->args.pretend_args_size
415 + cfun->machine->local_vars_size
416 + (ACCUMULATE_OUTGOING_ARGS ? crtl->outgoing_args_size : 0);
419 // Must use LINK/UNLINK when...
420 // the frame is bigger than 512 bytes so cannot just "SUB" from SP
421 // the function actually uses $fp
423 static int
424 must_link (void)
426 int bigframe = (cfun->machine->size_for_adjusting_sp >= 512);
427 return (bigframe || frame_pointer_needed || df_regs_ever_live_p (FT32_FP)
428 || df_regs_ever_live_p (FT32_FP));
431 void
432 ft32_expand_prologue (void)
434 int regno;
435 rtx insn;
437 ft32_compute_frame ();
439 int args_to_push = crtl->args.pretend_args_size;
440 if (args_to_push)
442 int i;
444 insn = emit_insn (gen_movsi_pop ((gen_rtx_REG (Pmode, FT32_R29))));
446 for (i = 0; i < (args_to_push / 4); i++)
448 insn =
449 emit_insn (gen_movsi_push ((gen_rtx_REG (Pmode, FT32_R5 - i))));
450 RTX_FRAME_RELATED_P (insn) = 1;
453 insn = emit_insn (gen_movsi_push ((gen_rtx_REG (Pmode, FT32_R29))));
456 if (flag_stack_usage_info)
457 current_function_static_stack_size = cfun->machine->size_for_adjusting_sp;
459 if (!must_link () && (cfun->machine->callee_saved_reg_size == 4))
461 insn =
462 emit_insn (gen_link
463 (gen_rtx_REG (Pmode, FT32_R13),
464 GEN_INT (-cfun->machine->size_for_adjusting_sp)));
465 RTX_FRAME_RELATED_P (insn) = 1;
466 return;
468 /* Save callee-saved registers. */
469 if (optimize_size)
471 for (regno = FIRST_PSEUDO_REGISTER; regno-- > 0;)
473 if (!fixed_regs[regno] && !call_used_regs[regno]
474 && df_regs_ever_live_p (regno))
476 rtx preg = gen_rtx_REG (Pmode, regno);
477 emit_insn (gen_call_prolog (preg));
478 break;
482 else
484 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
486 if (!fixed_regs[regno] && df_regs_ever_live_p (regno)
487 && !call_used_regs[regno])
489 insn = emit_insn (gen_movsi_push (gen_rtx_REG (Pmode, regno)));
490 RTX_FRAME_RELATED_P (insn) = 1;
495 if (65536 <= cfun->machine->size_for_adjusting_sp)
497 error ("stack frame must be smaller than 64K");
498 return;
500 if (must_link ())
502 insn =
503 emit_insn (gen_link
504 (gen_rtx_REG (Pmode, FT32_FP),
505 GEN_INT (-cfun->machine->size_for_adjusting_sp)));
506 RTX_FRAME_RELATED_P (insn) = 1;
508 else if (cfun->machine->size_for_adjusting_sp > 0)
510 int adj = cfun->machine->size_for_adjusting_sp;
511 insn = emit_insn (gen_addsi3 (gen_rtx_REG (SImode, FT32_SP),
512 gen_rtx_REG (SImode, FT32_SP),
513 GEN_INT (-adj)));
514 RTX_FRAME_RELATED_P (insn) = 1;
518 void
519 ft32_expand_epilogue (void)
521 int regno;
522 int pretend = crtl->args.pretend_args_size;
524 if (!must_link ()
525 && (cfun->machine->size_for_adjusting_sp == 24)
526 && (cfun->machine->callee_saved_reg_size == 0))
528 emit_jump_insn (gen_returner24 ());
529 return;
532 // Set when the epilog code will also add 24 to $sp
533 int epilog24 = (!must_link ()
534 && (cfun->machine->size_for_adjusting_sp == 24)
535 && optimize_size);
537 if (must_link ())
539 emit_insn (gen_unlink ());
541 else if (!epilog24 && (cfun->machine->size_for_adjusting_sp > 0))
543 emit_insn (gen_addsi3 (gen_rtx_REG (SImode, FT32_SP),
544 gen_rtx_REG (SImode, FT32_SP),
545 GEN_INT (cfun->machine->size_for_adjusting_sp)));
548 if (cfun->machine->callee_saved_reg_size != 0)
550 for (regno = FIRST_PSEUDO_REGISTER; regno-- > 0;)
552 if (!fixed_regs[regno] && !call_used_regs[regno]
553 && df_regs_ever_live_p (regno))
555 rtx preg = gen_rtx_REG (Pmode, regno);
556 if (optimize_size && (pretend == 0))
558 if (epilog24)
559 emit_insn (gen_jump_epilog24 (preg));
560 else
561 emit_insn (gen_jump_epilog (preg));
562 return;
564 emit_insn (gen_movsi_pop (preg));
569 if (pretend != 0)
570 emit_jump_insn (gen_pretend_returner (GEN_INT (pretend)));
571 else
572 emit_jump_insn (gen_returner ());
575 #undef TARGET_FRAME_POINTER_REQUIRED
576 #define TARGET_FRAME_POINTER_REQUIRED ft32_frame_pointer_required
577 static bool
578 ft32_frame_pointer_required (void)
580 return cfun->calls_alloca;
583 #undef TARGET_CAN_ELIMINATE
584 #define TARGET_CAN_ELIMINATE ft32_can_eliminate
586 /* Return true if register FROM can be eliminated via register TO. */
588 static bool
589 ft32_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to)
591 return 1;
592 return (to == FRAME_POINTER_REGNUM) || !ft32_frame_pointer_required ();
595 /* Implements the macro INITIAL_ELIMINATION_OFFSET, return the OFFSET. */
598 ft32_initial_elimination_offset (int from, int to)
600 ft32_compute_frame ();
602 if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM)
604 return cfun->machine->callee_saved_reg_size + 2 * UNITS_PER_WORD;
607 if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
609 int arg_offset;
610 arg_offset = must_link ()? 2 : 1;
611 return ((cfun->machine->callee_saved_reg_size
612 + arg_offset * UNITS_PER_WORD)
613 + cfun->machine->size_for_adjusting_sp);
616 if ((from == FRAME_POINTER_REGNUM) && (to == STACK_POINTER_REGNUM))
618 return cfun->machine->size_for_adjusting_sp;
621 gcc_unreachable ();
624 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. */
626 static void
627 ft32_setup_incoming_varargs (cumulative_args_t cum_v,
628 enum machine_mode mode,
629 tree type ATTRIBUTE_UNUSED,
630 int *pretend_size, int no_rtl ATTRIBUTE_UNUSED)
632 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
633 int named_size =
634 GET_MODE_SIZE (SImode) * (*cum - FT32_R0) + GET_MODE_SIZE (mode);
636 if (named_size < 24)
637 *pretend_size = 24 - named_size;
638 else
639 *pretend_size = 0;
642 /* Return the fixed registers used for condition codes. */
644 static bool
645 ft32_fixed_condition_code_regs (unsigned int *p1, unsigned int *p2)
647 *p1 = CC_REG;
648 *p2 = INVALID_REGNUM;
649 return true;
652 /* Return the next register to be used to hold a function argument or
653 NULL_RTX if there's no more space. */
655 static rtx
656 ft32_function_arg (cumulative_args_t cum_v, enum machine_mode mode,
657 const_tree type ATTRIBUTE_UNUSED,
658 bool named ATTRIBUTE_UNUSED)
660 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
662 if (*cum < 8)
663 return gen_rtx_REG (mode, *cum);
664 else
665 return NULL_RTX;
668 #define FT32_FUNCTION_ARG_SIZE(MODE, TYPE) \
669 ((MODE) != BLKmode ? GET_MODE_SIZE (MODE) \
670 : (unsigned) int_size_in_bytes (TYPE))
672 static void
673 ft32_function_arg_advance (cumulative_args_t cum_v, enum machine_mode mode,
674 const_tree type, bool named ATTRIBUTE_UNUSED)
676 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
678 *cum = (*cum < FT32_R6
679 ? *cum + ((3 + FT32_FUNCTION_ARG_SIZE (mode, type)) / 4) : *cum);
682 /* Return non-zero if the function argument described by TYPE is to be
683 passed by reference. */
685 static bool
686 ft32_pass_by_reference (cumulative_args_t cum ATTRIBUTE_UNUSED,
687 enum machine_mode mode, const_tree type,
688 bool named ATTRIBUTE_UNUSED)
690 unsigned HOST_WIDE_INT size;
692 if (type)
694 if (AGGREGATE_TYPE_P (type))
695 return true;
696 size = int_size_in_bytes (type);
698 else
699 size = GET_MODE_SIZE (mode);
701 return size > 4 * 6;
704 /* Some function arguments will only partially fit in the registers
705 that hold arguments. Given a new arg, return the number of bytes
706 that fit in argument passing registers. */
708 static int
709 ft32_arg_partial_bytes (cumulative_args_t cum_v,
710 enum machine_mode mode, tree type, bool named)
712 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
713 int bytes_left, size;
715 if (*cum >= 8)
716 return 0;
718 if (ft32_pass_by_reference (cum_v, mode, type, named))
719 size = 4;
720 else if (type)
722 if (AGGREGATE_TYPE_P (type))
723 return 0;
724 size = int_size_in_bytes (type);
726 else
727 size = GET_MODE_SIZE (mode);
729 bytes_left = (4 * 6) - ((*cum - 2) * 4);
731 if (size > bytes_left)
732 return bytes_left;
733 else
734 return 0;
737 /* Used by constraints.md to distinguish between GENERIC and PM
738 memory addresses. */
741 ft32_is_mem_pm (rtx o)
743 return (MEM_P (o)
744 && !ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (o)));
747 /* The Global `targetm' Variable. */
749 /* Initialize the GCC target structure. */
751 #undef TARGET_PROMOTE_PROTOTYPES
752 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
754 #undef TARGET_RETURN_IN_MEMORY
755 #define TARGET_RETURN_IN_MEMORY ft32_return_in_memory
756 #undef TARGET_MUST_PASS_IN_STACK
757 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
758 #undef TARGET_PASS_BY_REFERENCE
759 #define TARGET_PASS_BY_REFERENCE ft32_pass_by_reference
760 #undef TARGET_ARG_PARTIAL_BYTES
761 #define TARGET_ARG_PARTIAL_BYTES ft32_arg_partial_bytes
762 #undef TARGET_FUNCTION_ARG
763 #define TARGET_FUNCTION_ARG ft32_function_arg
764 #undef TARGET_FUNCTION_ARG_ADVANCE
765 #define TARGET_FUNCTION_ARG_ADVANCE ft32_function_arg_advance
768 #undef TARGET_SETUP_INCOMING_VARARGS
769 #define TARGET_SETUP_INCOMING_VARARGS ft32_setup_incoming_varargs
771 #undef TARGET_FIXED_CONDITION_CODE_REGS
772 #define TARGET_FIXED_CONDITION_CODE_REGS ft32_fixed_condition_code_regs
774 /* Define this to return an RTX representing the place where a
775 function returns or receives a value of data type RET_TYPE, a tree
776 node representing a data type. */
777 #undef TARGET_FUNCTION_VALUE
778 #define TARGET_FUNCTION_VALUE ft32_function_value
779 #undef TARGET_LIBCALL_VALUE
780 #define TARGET_LIBCALL_VALUE ft32_libcall_value
781 #undef TARGET_FUNCTION_VALUE_REGNO_P
782 #define TARGET_FUNCTION_VALUE_REGNO_P ft32_function_value_regno_p
784 #undef TARGET_OPTION_OVERRIDE
785 #define TARGET_OPTION_OVERRIDE ft32_option_override
787 #undef TARGET_ASM_SELECT_SECTION
788 #define TARGET_ASM_SELECT_SECTION ft32_select_section
790 #undef TARGET_VALID_POINTER_MODE
791 #define TARGET_VALID_POINTER_MODE ft32_valid_pointer_mode
792 static bool
793 ft32_valid_pointer_mode (enum machine_mode mode)
795 if (mode == SImode)
796 return 1;
797 return 0;
800 #undef TARGET_ADDR_SPACE_POINTER_MODE
801 #define TARGET_ADDR_SPACE_POINTER_MODE ft32_addr_space_pointer_mode
802 static enum machine_mode
803 ft32_addr_space_pointer_mode (addr_space_t addrspace ATTRIBUTE_UNUSED)
805 return Pmode;
808 #undef TARGET_ADDR_SPACE_ADDRESS_MODE
809 #define TARGET_ADDR_SPACE_ADDRESS_MODE ft32_addr_space_address_mode
810 static enum machine_mode
811 ft32_addr_space_address_mode (addr_space_t addrspace ATTRIBUTE_UNUSED)
813 return Pmode;
816 #undef TARGET_ADDR_SPACE_SUBSET_P
817 #define TARGET_ADDR_SPACE_SUBSET_P ft32_addr_space_subset_p
818 static bool
819 ft32_addr_space_subset_p (addr_space_t subset ATTRIBUTE_UNUSED,
820 addr_space_t superset ATTRIBUTE_UNUSED)
822 return false;
825 #undef TARGET_CASE_VALUES_THRESHOLD
826 #define TARGET_CASE_VALUES_THRESHOLD ft32_target_case_values_threshold
828 static unsigned int
829 ft32_target_case_values_threshold (void)
831 return 4;
834 #undef TARGET_ADDR_SPACE_LEGITIMATE_ADDRESS_P
835 #define TARGET_ADDR_SPACE_LEGITIMATE_ADDRESS_P \
836 ft32_addr_space_legitimate_address_p
839 // Enabling LRA gives the infamous
840 // internal compiler error: Max. number of generated reload insns per insn is achieved (90)
841 // errors e.g. when compiling sieve.c
843 static bool
844 ft32_lra_p (void)
846 return ft32_lra_flag;
849 #undef TARGET_LRA_P
850 #define TARGET_LRA_P ft32_lra_p
852 static bool
853 reg_ok_for_base_p (rtx r, bool strict)
855 int NUM = REGNO (r);
856 if (strict)
857 return (HARD_REGNO_OK_FOR_BASE_P (NUM)
858 || HARD_REGNO_OK_FOR_BASE_P (reg_renumber[(NUM)]));
859 else
860 return ((NUM) >= FIRST_PSEUDO_REGISTER || HARD_REGNO_OK_FOR_BASE_P (NUM));
863 static bool
864 ft32_addr_space_legitimate_address_p (enum machine_mode mode, rtx x,
865 bool strict,
866 addr_space_t as ATTRIBUTE_UNUSED)
868 if (mode != BLKmode)
870 if (GET_CODE (x) == PLUS)
872 rtx op1, op2;
873 op1 = XEXP (x, 0);
874 op2 = XEXP (x, 1);
875 if (GET_CODE (op1) == REG
876 && CONST_INT_P (op2)
877 && INTVAL (op2) >= -128
878 && INTVAL (op2) < 128 && reg_ok_for_base_p (op1, strict))
879 goto yes;
880 if (GET_CODE (op1) == SYMBOL_REF && CONST_INT_P (op2))
881 goto yes;
883 if (REG_P (x) && reg_ok_for_base_p (x, strict))
884 goto yes;
885 if (GET_CODE (x) == SYMBOL_REF
886 || GET_CODE (x) == LABEL_REF || CONST_INT_P (x))
887 goto yes;
889 else
891 if (REG_P (x) && reg_ok_for_base_p (x, strict))
892 goto yes;
895 return 0;
896 yes:
897 return 1;
900 #undef TARGET_ENCODE_SECTION_INFO
901 #define TARGET_ENCODE_SECTION_INFO ft32_elf_encode_section_info
903 void
904 ft32_elf_encode_section_info (tree decl, rtx rtl, int first)
906 enum tree_code code;
907 rtx symbol;
909 /* Careful not to prod global register variables. */
910 if (!MEM_P (rtl))
911 return;
912 symbol = XEXP (rtl, 0);
913 if (GET_CODE (symbol) != SYMBOL_REF)
914 return;
916 default_encode_section_info (decl, rtl, first);
918 code = TREE_CODE (decl);
919 switch (TREE_CODE_CLASS (code))
921 case tcc_declaration:
923 tree type = TREE_TYPE (decl);
924 int is_flash = (type && TYPE_P (type)
925 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type)));
926 if ((code == VAR_DECL) && !is_flash)
927 SYMBOL_REF_FLAGS (symbol) |= 0x1000;
929 break;
931 case tcc_constant:
932 case tcc_exceptional:
933 if (code == STRING_CST)
934 SYMBOL_REF_FLAGS (symbol) |= 0x1000;
935 break;
937 default:
938 break;
942 struct gcc_target targetm = TARGET_INITIALIZER;
944 #include "gt-ft32.h"