gcc/ChangeLog:
[official-gcc.git] / gcc / config / ft32 / ft32.c
blob78c5edc8f098656a4776429056bd2fd057f3cd9a
1 /* Target Code for ft32
2 Copyright (C) 2015-2017 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 "stringpool.h"
29 #include "attribs.h"
30 #include "df.h"
31 #include "memmodel.h"
32 #include "tm_p.h"
33 #include "regs.h"
34 #include "emit-rtl.h"
35 #include "diagnostic-core.h"
36 #include "output.h"
37 #include "stor-layout.h"
38 #include "calls.h"
39 #include "expr.h"
40 #include "builtins.h"
41 #include "print-tree.h"
43 /* This file should be included last. */
44 #include "target-def.h"
46 #include <stdint.h>
48 #define LOSE_AND_RETURN(msgid, x) \
49 do \
50 { \
51 ft32_operand_lossage (msgid, x); \
52 return; \
53 } while (0)
55 /* Worker function for TARGET_RETURN_IN_MEMORY. */
57 static bool
58 ft32_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
60 const HOST_WIDE_INT size = int_size_in_bytes (type);
61 return (size == -1 || size > 2 * UNITS_PER_WORD);
64 /* Define how to find the value returned by a function.
65 VALTYPE is the data type of the value (as a tree).
66 If the precise function being called is known, FUNC is its
67 FUNCTION_DECL; otherwise, FUNC is 0.
69 We always return values in register $r0 for ft32. */
71 static rtx
72 ft32_function_value (const_tree valtype,
73 const_tree fntype_or_decl ATTRIBUTE_UNUSED,
74 bool outgoing ATTRIBUTE_UNUSED)
76 return gen_rtx_REG (TYPE_MODE (valtype), FT32_R0);
79 /* Define how to find the value returned by a library function.
81 We always return values in register $r0 for ft32. */
83 static rtx
84 ft32_libcall_value (machine_mode mode, const_rtx fun ATTRIBUTE_UNUSED)
86 return gen_rtx_REG (mode, FT32_R0);
89 /* Handle TARGET_FUNCTION_VALUE_REGNO_P.
91 We always return values in register $r0 for ft32. */
93 static bool
94 ft32_function_value_regno_p (const unsigned int regno)
96 return (regno == FT32_R0);
99 /* Emit an error message when we're in an asm, and a fatal error for
100 "normal" insns. Formatted output isn't easily implemented, since we
101 use output_operand_lossage to output the actual message and handle the
102 categorization of the error. */
104 static void
105 ft32_operand_lossage (const char *msgid, rtx op)
107 debug_rtx (op);
108 output_operand_lossage ("%s", msgid);
111 /* The PRINT_OPERAND_ADDRESS worker. */
113 void
114 ft32_print_operand_address (FILE * file, rtx x)
116 switch (GET_CODE (x))
118 case REG:
119 fprintf (file, "%s,0", reg_names[REGNO (x)]);
120 break;
122 case PLUS:
123 switch (GET_CODE (XEXP (x, 1)))
125 case CONST_INT:
126 fprintf (file, "%s,%ld",
127 reg_names[REGNO (XEXP (x, 0))], INTVAL (XEXP (x, 1)));
128 break;
129 case SYMBOL_REF:
130 output_addr_const (file, XEXP (x, 1));
131 fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]);
132 break;
133 case CONST:
135 rtx plus = XEXP (XEXP (x, 1), 0);
136 if (GET_CODE (XEXP (plus, 0)) == SYMBOL_REF
137 && CONST_INT_P (XEXP (plus, 1)))
139 output_addr_const (file, XEXP (plus, 0));
140 fprintf (file, "+%ld(%s)", INTVAL (XEXP (plus, 1)),
141 reg_names[REGNO (XEXP (x, 0))]);
143 else
144 abort ();
146 break;
147 default:
148 abort ();
150 break;
152 default:
153 output_addr_const (file, x);
154 break;
158 /* The PRINT_OPERAND worker. */
160 void
161 ft32_print_operand (FILE * file, rtx x, int code)
163 rtx operand = x;
165 /* New code entries should just be added to the switch below. If
166 handling is finished, just return. If handling was just a
167 modification of the operand, the modified operand should be put in
168 "operand", and then do a break to let default handling
169 (zero-modifier) output the operand. */
171 switch (code)
173 case 0:
174 /* No code, print as usual. */
175 break;
177 case 'h':
178 if (GET_CODE (operand) != REG)
179 internal_error ("'h' applied to non-register operand");
180 fprintf (file, "%s", reg_names[REGNO (operand) + 1]);
181 return;
183 case 'm':
184 fprintf (file, "%ld", (long) (- INTVAL(x)));
185 return;
187 case 'd': // a DW spec, from an integer alignment (for BLKmode insns)
189 int i = INTVAL (x);
190 char dwspec;
191 switch (i)
193 case 1:
194 dwspec = 'b';
195 break;
196 case 2:
197 dwspec = 's';
198 break;
199 case 4:
200 dwspec = 'l';
201 break;
202 default:
203 if ((i % 4) != 0)
204 internal_error ("bad alignment: %d", i);
205 else
206 dwspec = 'l';
207 break;
209 fprintf (file, "%c", dwspec);
210 return;
213 case 'f':
215 int bf = ft32_as_bitfield (INTVAL (x));
216 fprintf (file, "512|(%d<<5)|%d", bf >> 5, bf & 31);
217 return;
220 case 'g':
222 int bf = ft32_as_bitfield (0xffffffff ^ INTVAL (x));
223 fprintf (file, "(%d<<5)|%d", bf >> 5, bf & 31);
224 return;
227 case 'b':
229 ft32_print_operand (file, XEXP (x, 0), 0);
230 return;
233 default:
234 LOSE_AND_RETURN ("invalid operand modifier letter", x);
237 /* Print an operand as without a modifier letter. */
238 switch (GET_CODE (operand))
240 case REG:
241 fprintf (file, "%s", reg_names[REGNO (operand)]);
242 return;
244 case MEM:
245 output_address (GET_MODE (XEXP (operand, 0)), XEXP (operand, 0));
246 return;
248 default:
249 /* No need to handle all strange variants, let output_addr_const
250 do it for us. */
251 if (CONSTANT_P (operand))
253 output_addr_const (file, operand);
254 return;
257 LOSE_AND_RETURN ("unexpected operand", x);
261 const char *
262 ft32_load_immediate (rtx dst, int32_t i)
264 char pattern[100];
266 if ((-524288 <= i) && (i <= 524287))
268 sprintf (pattern, "ldk.l %%0,%d", i);
269 output_asm_insn (pattern, &dst);
271 else if ((-536870912 <= i) && (i <= 536870911))
273 ft32_load_immediate (dst, i >> 10);
274 sprintf (pattern, "ldl.l %%0,%%0,%d", i & 1023);
275 output_asm_insn (pattern, &dst);
277 else
279 int rd; // rotate distance
280 uint32_t u = i;
281 for (rd = 1; rd < 32; rd++)
283 u = ((u >> 31) & 1) | (u << 1);
284 if ((-524288 <= (int32_t) u) && ((int32_t) u <= 524287))
286 ft32_load_immediate (dst, (int32_t) u);
287 sprintf (pattern, "ror.l %%0,%%0,%d", rd);
288 output_asm_insn (pattern, &dst);
289 return "";
292 ft32_load_immediate (dst, i >> 10);
293 sprintf (pattern, "ldl.l %%0,%%0,%d", i & 1023);
294 output_asm_insn (pattern, &dst);
297 return "";
300 // x is a bit mask, for example:
301 // 00000000000000000000001111111110
302 // If x contains a single bit mask, return the bitfield spec.
303 // in the above case it returns ((9 << 5) | 1)
304 // Otherwise return -1.
307 #define NBITS(n) ((1U << (n)) - 1U)
310 ft32_as_bitfield (unsigned int x)
312 int lobit, hibit;
314 if (x == 0)
315 return -1;
317 for (lobit = 0; lobit < 32; lobit++)
318 if (x & (1 << lobit))
319 break;
320 for (hibit = 31; hibit >= 0; hibit--)
321 if (x & (1 << hibit))
322 break;
324 int width = 1 + hibit - lobit;
325 if (width > 16)
326 return -1;
328 if (x != (NBITS (width) << lobit))
329 return -1; // not a clean bitfield
331 return ((width & 15) << 5) | lobit;
334 /* Per-function machine data. */
335 struct GTY (()) machine_function
337 /* Number of bytes saved on the stack for callee saved registers. */
338 int callee_saved_reg_size;
340 /* Number of bytes saved on the stack for local variables. */
341 int local_vars_size;
343 /* The sum of 2 sizes: locals vars and padding byte for saving the
344 * registers. Used in expand_prologue () and expand_epilogue (). */
345 int size_for_adjusting_sp;
348 /* Zero initialization is OK for all current fields. */
350 static struct machine_function *
351 ft32_init_machine_status (void)
353 return ggc_cleared_alloc < machine_function > ();
357 /* The TARGET_OPTION_OVERRIDE worker.
358 All this curently does is set init_machine_status. */
359 static void
360 ft32_option_override (void)
362 /* Set the per-function-data initializer. */
363 init_machine_status = ft32_init_machine_status;
366 /* Implement targetm.select_section. */
367 static section *
368 ft32_select_section (tree decl, int reloc, unsigned HOST_WIDE_INT align)
370 /* Variables and constants defined in the __ea address space
371 go into a special section named "._ea". */
372 if (TREE_TYPE (decl) != error_mark_node
373 && TYPE_ADDR_SPACE (TREE_TYPE (decl)) == ADDR_SPACE_PM)
375 /* We might get called with string constants, but get_named_section
376 doesn't like them as they are not DECLs. Also, we need to set
377 flags in that case. */
378 if (!DECL_P (decl))
379 return get_section ("._pm", SECTION_WRITE | SECTION_DEBUG, NULL);
381 return get_named_section (decl, "._pm", reloc);
384 return default_elf_select_section (decl, reloc, align);
387 /* Compute the size of the local area and the size to be adjusted by the
388 * prologue and epilogue. */
390 static void
391 ft32_compute_frame (void)
393 /* For aligning the local variables. */
394 int stack_alignment = STACK_BOUNDARY / BITS_PER_UNIT;
395 int padding_locals;
396 int regno;
398 /* Padding needed for each element of the frame. */
399 cfun->machine->local_vars_size = get_frame_size ();
401 /* Align to the stack alignment. */
402 padding_locals = cfun->machine->local_vars_size % stack_alignment;
403 if (padding_locals)
404 padding_locals = stack_alignment - padding_locals;
406 cfun->machine->local_vars_size += padding_locals;
408 cfun->machine->callee_saved_reg_size = 0;
410 /* Save callee-saved registers. */
411 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
412 if (df_regs_ever_live_p (regno) && (!call_used_regs[regno]))
413 cfun->machine->callee_saved_reg_size += 4;
415 cfun->machine->size_for_adjusting_sp =
416 0 // crtl->args.pretend_args_size
417 + cfun->machine->local_vars_size
418 + (ACCUMULATE_OUTGOING_ARGS ? crtl->outgoing_args_size : 0);
421 // Must use LINK/UNLINK when...
422 // the frame is bigger than 512 bytes so cannot just "SUB" from SP
423 // the function actually uses $fp
425 static int
426 must_link (void)
428 int bigframe = (cfun->machine->size_for_adjusting_sp >= 512);
429 return (bigframe || frame_pointer_needed || df_regs_ever_live_p (FT32_FP)
430 || df_regs_ever_live_p (FT32_FP));
433 void
434 ft32_expand_prologue (void)
436 int regno;
437 rtx insn;
439 ft32_compute_frame ();
441 int args_to_push = crtl->args.pretend_args_size;
442 if (args_to_push)
444 int i;
446 insn = emit_insn (gen_movsi_pop ((gen_rtx_REG (Pmode, FT32_R29))));
448 for (i = 0; i < (args_to_push / 4); i++)
450 insn =
451 emit_insn (gen_movsi_push ((gen_rtx_REG (Pmode, FT32_R5 - i))));
452 RTX_FRAME_RELATED_P (insn) = 1;
455 insn = emit_insn (gen_movsi_push ((gen_rtx_REG (Pmode, FT32_R29))));
458 if (flag_stack_usage_info)
459 current_function_static_stack_size = cfun->machine->size_for_adjusting_sp;
461 if (!must_link () && (cfun->machine->callee_saved_reg_size == 4))
463 insn =
464 emit_insn (gen_link
465 (gen_rtx_REG (Pmode, FT32_R13),
466 GEN_INT (-cfun->machine->size_for_adjusting_sp)));
467 RTX_FRAME_RELATED_P (insn) = 1;
468 return;
470 /* Save callee-saved registers. */
471 if (optimize_size)
473 for (regno = FIRST_PSEUDO_REGISTER; regno-- > 0;)
475 if (!fixed_regs[regno] && !call_used_regs[regno]
476 && df_regs_ever_live_p (regno))
478 rtx preg = gen_rtx_REG (Pmode, regno);
479 emit_insn (gen_call_prolog (preg));
480 break;
484 else
486 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
488 if (!fixed_regs[regno] && df_regs_ever_live_p (regno)
489 && !call_used_regs[regno])
491 insn = emit_insn (gen_movsi_push (gen_rtx_REG (Pmode, regno)));
492 RTX_FRAME_RELATED_P (insn) = 1;
497 if (65536 <= cfun->machine->size_for_adjusting_sp)
499 error ("stack frame must be smaller than 64K");
500 return;
502 if (must_link ())
504 insn =
505 emit_insn (gen_link
506 (gen_rtx_REG (Pmode, FT32_FP),
507 GEN_INT (-cfun->machine->size_for_adjusting_sp)));
508 RTX_FRAME_RELATED_P (insn) = 1;
510 else if (cfun->machine->size_for_adjusting_sp > 0)
512 int adj = cfun->machine->size_for_adjusting_sp;
513 insn = emit_insn (gen_addsi3 (gen_rtx_REG (SImode, FT32_SP),
514 gen_rtx_REG (SImode, FT32_SP),
515 GEN_INT (-adj)));
516 RTX_FRAME_RELATED_P (insn) = 1;
520 void
521 ft32_expand_epilogue (void)
523 int regno;
524 int pretend = crtl->args.pretend_args_size;
526 if (!must_link ()
527 && (cfun->machine->size_for_adjusting_sp == 24)
528 && (cfun->machine->callee_saved_reg_size == 0))
530 emit_jump_insn (gen_returner24 ());
531 return;
534 // Set when the epilog code will also add 24 to $sp
535 int epilog24 = (!must_link ()
536 && (cfun->machine->size_for_adjusting_sp == 24)
537 && optimize_size);
539 if (must_link ())
541 emit_insn (gen_unlink ());
543 else if (!epilog24 && (cfun->machine->size_for_adjusting_sp > 0))
545 emit_insn (gen_addsi3 (gen_rtx_REG (SImode, FT32_SP),
546 gen_rtx_REG (SImode, FT32_SP),
547 GEN_INT (cfun->machine->size_for_adjusting_sp)));
550 if (cfun->machine->callee_saved_reg_size != 0)
552 for (regno = FIRST_PSEUDO_REGISTER; regno-- > 0;)
554 if (!fixed_regs[regno] && !call_used_regs[regno]
555 && df_regs_ever_live_p (regno))
557 rtx preg = gen_rtx_REG (Pmode, regno);
558 if (optimize_size && (pretend == 0))
560 if (epilog24)
561 emit_insn (gen_jump_epilog24 (preg));
562 else
563 emit_insn (gen_jump_epilog (preg));
564 return;
566 emit_insn (gen_movsi_pop (preg));
571 if (pretend != 0)
572 emit_jump_insn (gen_pretend_returner (GEN_INT (pretend)));
573 else
574 emit_jump_insn (gen_returner ());
577 #undef TARGET_FRAME_POINTER_REQUIRED
578 #define TARGET_FRAME_POINTER_REQUIRED ft32_frame_pointer_required
579 static bool
580 ft32_frame_pointer_required (void)
582 return cfun->calls_alloca;
585 #undef TARGET_CAN_ELIMINATE
586 #define TARGET_CAN_ELIMINATE ft32_can_eliminate
588 /* Return true if register FROM can be eliminated via register TO. */
590 static bool
591 ft32_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to)
593 return 1;
594 return (to == FRAME_POINTER_REGNUM) || !ft32_frame_pointer_required ();
597 /* Implements the macro INITIAL_ELIMINATION_OFFSET, return the OFFSET. */
600 ft32_initial_elimination_offset (int from, int to)
602 ft32_compute_frame ();
604 if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM)
606 return cfun->machine->callee_saved_reg_size + 2 * UNITS_PER_WORD;
609 if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
611 int arg_offset;
612 arg_offset = must_link ()? 2 : 1;
613 return ((cfun->machine->callee_saved_reg_size
614 + arg_offset * UNITS_PER_WORD)
615 + cfun->machine->size_for_adjusting_sp);
618 if ((from == FRAME_POINTER_REGNUM) && (to == STACK_POINTER_REGNUM))
620 return cfun->machine->size_for_adjusting_sp;
623 gcc_unreachable ();
626 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. */
628 static void
629 ft32_setup_incoming_varargs (cumulative_args_t cum_v,
630 machine_mode mode,
631 tree type ATTRIBUTE_UNUSED,
632 int *pretend_size, int no_rtl ATTRIBUTE_UNUSED)
634 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
635 int named_size =
636 GET_MODE_SIZE (SImode) * (*cum - FT32_R0) + GET_MODE_SIZE (mode);
638 if (named_size < 24)
639 *pretend_size = 24 - named_size;
640 else
641 *pretend_size = 0;
644 /* Return the fixed registers used for condition codes. */
646 static bool
647 ft32_fixed_condition_code_regs (unsigned int *p1, unsigned int *p2)
649 *p1 = CC_REG;
650 *p2 = INVALID_REGNUM;
651 return true;
654 /* Return the next register to be used to hold a function argument or
655 NULL_RTX if there's no more space. */
657 static rtx
658 ft32_function_arg (cumulative_args_t cum_v, machine_mode mode,
659 const_tree type ATTRIBUTE_UNUSED,
660 bool named ATTRIBUTE_UNUSED)
662 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
664 if (*cum < 8)
665 return gen_rtx_REG (mode, *cum);
666 else
667 return NULL_RTX;
670 #define FT32_FUNCTION_ARG_SIZE(MODE, TYPE) \
671 ((MODE) != BLKmode ? GET_MODE_SIZE (MODE) \
672 : (unsigned) int_size_in_bytes (TYPE))
674 static void
675 ft32_function_arg_advance (cumulative_args_t cum_v, machine_mode mode,
676 const_tree type, bool named ATTRIBUTE_UNUSED)
678 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
680 *cum = (*cum < FT32_R6
681 ? *cum + ((3 + FT32_FUNCTION_ARG_SIZE (mode, type)) / 4) : *cum);
684 /* Return non-zero if the function argument described by TYPE is to be
685 passed by reference. */
687 static bool
688 ft32_pass_by_reference (cumulative_args_t cum ATTRIBUTE_UNUSED,
689 machine_mode mode, const_tree type,
690 bool named ATTRIBUTE_UNUSED)
692 unsigned HOST_WIDE_INT size;
694 if (type)
696 if (AGGREGATE_TYPE_P (type))
697 return true;
698 size = int_size_in_bytes (type);
700 else
701 size = GET_MODE_SIZE (mode);
703 return size > 4 * 6;
706 /* Some function arguments will only partially fit in the registers
707 that hold arguments. Given a new arg, return the number of bytes
708 that fit in argument passing registers. */
710 static int
711 ft32_arg_partial_bytes (cumulative_args_t cum_v,
712 machine_mode mode, tree type, bool named)
714 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
715 int bytes_left, size;
717 if (*cum >= 8)
718 return 0;
720 if (ft32_pass_by_reference (cum_v, mode, type, named))
721 size = 4;
722 else if (type)
724 if (AGGREGATE_TYPE_P (type))
725 return 0;
726 size = int_size_in_bytes (type);
728 else
729 size = GET_MODE_SIZE (mode);
731 bytes_left = (4 * 6) - ((*cum - 2) * 4);
733 if (size > bytes_left)
734 return bytes_left;
735 else
736 return 0;
739 /* Used by constraints.md to distinguish between GENERIC and PM
740 memory addresses. */
743 ft32_is_mem_pm (rtx o)
745 return (MEM_P (o)
746 && !ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (o)));
749 /* The Global `targetm' Variable. */
751 /* Initialize the GCC target structure. */
753 #undef TARGET_PROMOTE_PROTOTYPES
754 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
756 #undef TARGET_RETURN_IN_MEMORY
757 #define TARGET_RETURN_IN_MEMORY ft32_return_in_memory
758 #undef TARGET_MUST_PASS_IN_STACK
759 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
760 #undef TARGET_PASS_BY_REFERENCE
761 #define TARGET_PASS_BY_REFERENCE ft32_pass_by_reference
762 #undef TARGET_ARG_PARTIAL_BYTES
763 #define TARGET_ARG_PARTIAL_BYTES ft32_arg_partial_bytes
764 #undef TARGET_FUNCTION_ARG
765 #define TARGET_FUNCTION_ARG ft32_function_arg
766 #undef TARGET_FUNCTION_ARG_ADVANCE
767 #define TARGET_FUNCTION_ARG_ADVANCE ft32_function_arg_advance
770 #undef TARGET_SETUP_INCOMING_VARARGS
771 #define TARGET_SETUP_INCOMING_VARARGS ft32_setup_incoming_varargs
773 #undef TARGET_FIXED_CONDITION_CODE_REGS
774 #define TARGET_FIXED_CONDITION_CODE_REGS ft32_fixed_condition_code_regs
776 /* Define this to return an RTX representing the place where a
777 function returns or receives a value of data type RET_TYPE, a tree
778 node representing a data type. */
779 #undef TARGET_FUNCTION_VALUE
780 #define TARGET_FUNCTION_VALUE ft32_function_value
781 #undef TARGET_LIBCALL_VALUE
782 #define TARGET_LIBCALL_VALUE ft32_libcall_value
783 #undef TARGET_FUNCTION_VALUE_REGNO_P
784 #define TARGET_FUNCTION_VALUE_REGNO_P ft32_function_value_regno_p
786 #undef TARGET_OPTION_OVERRIDE
787 #define TARGET_OPTION_OVERRIDE ft32_option_override
789 #undef TARGET_ASM_SELECT_SECTION
790 #define TARGET_ASM_SELECT_SECTION ft32_select_section
792 #undef TARGET_VALID_POINTER_MODE
793 #define TARGET_VALID_POINTER_MODE ft32_valid_pointer_mode
794 static bool
795 ft32_valid_pointer_mode (machine_mode mode)
797 if (mode == SImode)
798 return 1;
799 return 0;
802 #undef TARGET_ADDR_SPACE_POINTER_MODE
803 #define TARGET_ADDR_SPACE_POINTER_MODE ft32_addr_space_pointer_mode
804 static machine_mode
805 ft32_addr_space_pointer_mode (addr_space_t addrspace ATTRIBUTE_UNUSED)
807 return Pmode;
810 #undef TARGET_ADDR_SPACE_ADDRESS_MODE
811 #define TARGET_ADDR_SPACE_ADDRESS_MODE ft32_addr_space_address_mode
812 static machine_mode
813 ft32_addr_space_address_mode (addr_space_t addrspace ATTRIBUTE_UNUSED)
815 return Pmode;
818 #undef TARGET_ADDR_SPACE_SUBSET_P
819 #define TARGET_ADDR_SPACE_SUBSET_P ft32_addr_space_subset_p
820 static bool
821 ft32_addr_space_subset_p (addr_space_t subset ATTRIBUTE_UNUSED,
822 addr_space_t superset ATTRIBUTE_UNUSED)
824 return false;
827 #undef TARGET_CASE_VALUES_THRESHOLD
828 #define TARGET_CASE_VALUES_THRESHOLD ft32_target_case_values_threshold
830 static unsigned int
831 ft32_target_case_values_threshold (void)
833 return 4;
836 #undef TARGET_ADDR_SPACE_LEGITIMATE_ADDRESS_P
837 #define TARGET_ADDR_SPACE_LEGITIMATE_ADDRESS_P \
838 ft32_addr_space_legitimate_address_p
841 // Enabling LRA gives the infamous
842 // internal compiler error: Max. number of generated reload insns per insn is achieved (90)
843 // errors e.g. when compiling sieve.c
845 static bool
846 ft32_lra_p (void)
848 return ft32_lra_flag;
851 #undef TARGET_LRA_P
852 #define TARGET_LRA_P ft32_lra_p
854 static bool
855 reg_ok_for_base_p (rtx r, bool strict)
857 int NUM = REGNO (r);
858 if (strict)
859 return (HARD_REGNO_OK_FOR_BASE_P (NUM)
860 || HARD_REGNO_OK_FOR_BASE_P (reg_renumber[(NUM)]));
861 else
862 return ((NUM) >= FIRST_PSEUDO_REGISTER || HARD_REGNO_OK_FOR_BASE_P (NUM));
865 static bool
866 ft32_addr_space_legitimate_address_p (machine_mode mode, rtx x, bool strict,
867 addr_space_t as ATTRIBUTE_UNUSED)
869 if (mode != BLKmode)
871 if (GET_CODE (x) == PLUS)
873 rtx op1, op2;
874 op1 = XEXP (x, 0);
875 op2 = XEXP (x, 1);
876 if (GET_CODE (op1) == REG
877 && CONST_INT_P (op2)
878 && INTVAL (op2) >= -128
879 && INTVAL (op2) < 128 && reg_ok_for_base_p (op1, strict))
880 goto yes;
881 if (GET_CODE (op1) == SYMBOL_REF && CONST_INT_P (op2))
882 goto yes;
884 if (REG_P (x) && reg_ok_for_base_p (x, strict))
885 goto yes;
886 if (GET_CODE (x) == SYMBOL_REF
887 || GET_CODE (x) == LABEL_REF || CONST_INT_P (x))
888 goto yes;
890 else
892 if (REG_P (x) && reg_ok_for_base_p (x, strict))
893 goto yes;
896 return 0;
897 yes:
898 return 1;
901 #undef TARGET_ENCODE_SECTION_INFO
902 #define TARGET_ENCODE_SECTION_INFO ft32_elf_encode_section_info
904 void
905 ft32_elf_encode_section_info (tree decl, rtx rtl, int first)
907 enum tree_code code;
908 rtx symbol;
910 /* Careful not to prod global register variables. */
911 if (!MEM_P (rtl))
912 return;
913 symbol = XEXP (rtl, 0);
914 if (GET_CODE (symbol) != SYMBOL_REF)
915 return;
917 default_encode_section_info (decl, rtl, first);
919 code = TREE_CODE (decl);
920 switch (TREE_CODE_CLASS (code))
922 case tcc_declaration:
924 tree type = TREE_TYPE (decl);
925 int is_flash = (type && TYPE_P (type)
926 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type)));
927 if ((code == VAR_DECL) && !is_flash)
928 SYMBOL_REF_FLAGS (symbol) |= 0x1000;
930 break;
932 case tcc_constant:
933 case tcc_exceptional:
934 if (code == STRING_CST)
935 SYMBOL_REF_FLAGS (symbol) |= 0x1000;
936 break;
938 default:
939 break;
943 struct gcc_target targetm = TARGET_INITIALIZER;
945 #include "gt-ft32.h"