gcc/
[official-gcc.git] / gcc / config / ft32 / ft32.c
blob4adf39b8b5785da3b4c08e760658271606af2b12
1 /* Target Code for ft32
2 Copyright (C) 2015 Free Software Foundation
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 "tm.h"
25 #include "rtl.h"
26 #include "regs.h"
27 #include "hard-reg-set.h"
28 #include "insn-config.h"
29 #include "conditions.h"
30 #include "insn-flags.h"
31 #include "output.h"
32 #include "insn-attr.h"
33 #include "flags.h"
34 #include "recog.h"
35 #include "reload.h"
36 #include "diagnostic-core.h"
37 #include "obstack.h"
38 #include "alias.h"
39 #include "symtab.h"
40 #include "tree.h"
41 #include "stor-layout.h"
42 #include "calls.h"
43 #include "expr.h"
44 #include "optabs.h"
45 #include "except.h"
46 #include "function.h"
47 #include "target.h"
48 #include "tm_p.h"
49 #include "langhooks.h"
50 #include "dominance.h"
51 #include "cfg.h"
52 #include "cfgrtl.h"
53 #include "cfganal.h"
54 #include "lcm.h"
55 #include "cfgbuild.h"
56 #include "cfgcleanup.h"
57 #include "predict.h"
58 #include "basic-block.h"
59 #include "df.h"
60 #include "builtins.h"
61 #include "emit-rtl.h"
63 /* This file should be included last. */
64 #include "target-def.h"
66 #include <stdint.h>
68 #define LOSE_AND_RETURN(msgid, x) \
69 do \
70 { \
71 ft32_operand_lossage (msgid, x); \
72 return; \
73 } while (0)
75 /* Worker function for TARGET_RETURN_IN_MEMORY. */
77 static bool
78 ft32_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
80 const HOST_WIDE_INT size = int_size_in_bytes (type);
81 return (size == -1 || size > 2 * UNITS_PER_WORD);
84 /* Define how to find the value returned by a function.
85 VALTYPE is the data type of the value (as a tree).
86 If the precise function being called is known, FUNC is its
87 FUNCTION_DECL; otherwise, FUNC is 0.
89 We always return values in register $r0 for ft32. */
91 static rtx
92 ft32_function_value (const_tree valtype,
93 const_tree fntype_or_decl ATTRIBUTE_UNUSED,
94 bool outgoing ATTRIBUTE_UNUSED)
96 return gen_rtx_REG (TYPE_MODE (valtype), FT32_R0);
99 /* Define how to find the value returned by a library function.
101 We always return values in register $r0 for ft32. */
103 static rtx
104 ft32_libcall_value (enum machine_mode mode, const_rtx fun ATTRIBUTE_UNUSED)
106 return gen_rtx_REG (mode, FT32_R0);
109 /* Handle TARGET_FUNCTION_VALUE_REGNO_P.
111 We always return values in register $r0 for ft32. */
113 static bool
114 ft32_function_value_regno_p (const unsigned int regno)
116 return (regno == FT32_R0);
119 /* Emit an error message when we're in an asm, and a fatal error for
120 "normal" insns. Formatted output isn't easily implemented, since we
121 use output_operand_lossage to output the actual message and handle the
122 categorization of the error. */
124 static void
125 ft32_operand_lossage (const char *msgid, rtx op)
127 debug_rtx (op);
128 output_operand_lossage ("%s", msgid);
131 /* The PRINT_OPERAND_ADDRESS worker. */
133 void
134 ft32_print_operand_address (FILE * file, rtx x)
136 switch (GET_CODE (x))
138 case REG:
139 fprintf (file, "%s,0", reg_names[REGNO (x)]);
140 break;
142 case PLUS:
143 switch (GET_CODE (XEXP (x, 1)))
145 case CONST_INT:
146 fprintf (file, "%s,%ld",
147 reg_names[REGNO (XEXP (x, 0))], INTVAL (XEXP (x, 1)));
148 break;
149 case SYMBOL_REF:
150 output_addr_const (file, XEXP (x, 1));
151 fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]);
152 break;
153 case CONST:
155 rtx plus = XEXP (XEXP (x, 1), 0);
156 if (GET_CODE (XEXP (plus, 0)) == SYMBOL_REF
157 && CONST_INT_P (XEXP (plus, 1)))
159 output_addr_const (file, XEXP (plus, 0));
160 fprintf (file, "+%ld(%s)", INTVAL (XEXP (plus, 1)),
161 reg_names[REGNO (XEXP (x, 0))]);
163 else
164 abort ();
166 break;
167 default:
168 abort ();
170 break;
172 default:
173 output_addr_const (file, x);
174 break;
178 /* The PRINT_OPERAND worker. */
180 void
181 ft32_print_operand (FILE * file, rtx x, int code)
183 rtx operand = x;
185 /* New code entries should just be added to the switch below. If
186 handling is finished, just return. If handling was just a
187 modification of the operand, the modified operand should be put in
188 "operand", and then do a break to let default handling
189 (zero-modifier) output the operand. */
191 switch (code)
193 case 0:
194 /* No code, print as usual. */
195 break;
197 case 'h':
198 if (GET_CODE (operand) != REG)
199 internal_error ("'h' applied to non-register operand");
200 fprintf (file, "%s", reg_names[REGNO (operand) + 1]);
201 return;
203 case 'm':
204 fprintf (file, "%ld", (long) (- INTVAL(x)));
205 return;
207 case 'd': // a DW spec, from an integer alignment (for BLKmode insns)
209 int i = INTVAL (x);
210 char dwspec;
211 switch (i)
213 case 1:
214 dwspec = 'b';
215 break;
216 case 2:
217 dwspec = 's';
218 break;
219 case 4:
220 dwspec = 'l';
221 break;
222 default:
223 if ((i % 4) != 0)
224 internal_error ("bad alignment: %d", i);
225 else
226 dwspec = 'l';
227 break;
229 fprintf (file, "%c", dwspec);
230 return;
233 case 'f':
235 int bf = ft32_as_bitfield (INTVAL (x));
236 fprintf (file, "512|(%d<<5)|%d", bf >> 5, bf & 31);
237 return;
240 case 'g':
242 int bf = ft32_as_bitfield (0xffffffff ^ INTVAL (x));
243 fprintf (file, "(%d<<5)|%d", bf >> 5, bf & 31);
244 return;
247 case 'b':
249 ft32_print_operand (file, XEXP (x, 0), 0);
250 return;
253 default:
254 LOSE_AND_RETURN ("invalid operand modifier letter", x);
257 /* Print an operand as without a modifier letter. */
258 switch (GET_CODE (operand))
260 case REG:
261 fprintf (file, "%s", reg_names[REGNO (operand)]);
262 return;
264 case MEM:
265 output_address (XEXP (operand, 0));
266 return;
268 default:
269 /* No need to handle all strange variants, let output_addr_const
270 do it for us. */
271 if (CONSTANT_P (operand))
273 output_addr_const (file, operand);
274 return;
277 LOSE_AND_RETURN ("unexpected operand", x);
281 const char *
282 ft32_load_immediate (rtx dst, int32_t i)
284 char pattern[100];
286 if ((-524288 <= i) && (i <= 524287))
288 sprintf (pattern, "ldk.l %%0,%d", i);
289 output_asm_insn (pattern, &dst);
291 else if ((-536870912 <= i) && (i <= 536870911))
293 ft32_load_immediate (dst, i >> 10);
294 sprintf (pattern, "ldl.l %%0,%%0,%d", i & 1023);
295 output_asm_insn (pattern, &dst);
297 else
299 int rd; // rotate distance
300 uint32_t u = i;
301 for (rd = 1; rd < 32; rd++)
303 u = ((u >> 31) & 1) | (u << 1);
304 if ((-524288 <= (int32_t) u) && ((int32_t) u <= 524287))
306 ft32_load_immediate (dst, (int32_t) u);
307 sprintf (pattern, "ror.l %%0,%%0,%d", rd);
308 output_asm_insn (pattern, &dst);
309 return "";
312 ft32_load_immediate (dst, i >> 10);
313 sprintf (pattern, "ldl.l %%0,%%0,%d", i & 1023);
314 output_asm_insn (pattern, &dst);
317 return "";
320 // x is a bit mask, for example:
321 // 00000000000000000000001111111110
322 // If x contains a single bit mask, return the bitfield spec.
323 // in the above case it returns ((9 << 5) | 1)
324 // Otherwise return -1.
327 #define NBITS(n) ((1U << (n)) - 1U)
330 ft32_as_bitfield (unsigned int x)
332 int lobit, hibit;
334 if (x == 0)
335 return -1;
337 for (lobit = 0; lobit < 32; lobit++)
338 if (x & (1 << lobit))
339 break;
340 for (hibit = 31; hibit >= 0; hibit--)
341 if (x & (1 << hibit))
342 break;
344 int width = 1 + hibit - lobit;
345 if (width > 16)
346 return -1;
348 if (x != (NBITS (width) << lobit))
349 return -1; // not a clean bitfield
351 return ((width & 15) << 5) | lobit;
354 /* Per-function machine data. */
355 struct GTY (()) machine_function
357 /* Number of bytes saved on the stack for callee saved registers. */
358 int callee_saved_reg_size;
360 /* Number of bytes saved on the stack for local variables. */
361 int local_vars_size;
363 /* The sum of 2 sizes: locals vars and padding byte for saving the
364 * registers. Used in expand_prologue () and expand_epilogue (). */
365 int size_for_adjusting_sp;
368 /* Zero initialization is OK for all current fields. */
370 static struct machine_function *
371 ft32_init_machine_status (void)
373 return ggc_cleared_alloc < machine_function > ();
377 /* The TARGET_OPTION_OVERRIDE worker.
378 All this curently does is set init_machine_status. */
379 static void
380 ft32_option_override (void)
382 /* Set the per-function-data initializer. */
383 init_machine_status = ft32_init_machine_status;
386 /* Implement targetm.select_section. */
387 static section *
388 ft32_select_section (tree decl, int reloc, unsigned HOST_WIDE_INT align)
390 /* Variables and constants defined in the __ea address space
391 go into a special section named "._ea". */
392 if (TREE_TYPE (decl) != error_mark_node
393 && TYPE_ADDR_SPACE (TREE_TYPE (decl)) == ADDR_SPACE_PM)
395 /* We might get called with string constants, but get_named_section
396 doesn't like them as they are not DECLs. Also, we need to set
397 flags in that case. */
398 if (!DECL_P (decl))
399 return get_section ("._pm", SECTION_WRITE | SECTION_DEBUG, NULL);
401 return get_named_section (decl, "._pm", reloc);
404 return default_elf_select_section (decl, reloc, align);
407 /* Compute the size of the local area and the size to be adjusted by the
408 * prologue and epilogue. */
410 static void
411 ft32_compute_frame (void)
413 /* For aligning the local variables. */
414 int stack_alignment = STACK_BOUNDARY / BITS_PER_UNIT;
415 int padding_locals;
416 int regno;
418 /* Padding needed for each element of the frame. */
419 cfun->machine->local_vars_size = get_frame_size ();
421 /* Align to the stack alignment. */
422 padding_locals = cfun->machine->local_vars_size % stack_alignment;
423 if (padding_locals)
424 padding_locals = stack_alignment - padding_locals;
426 cfun->machine->local_vars_size += padding_locals;
428 cfun->machine->callee_saved_reg_size = 0;
430 /* Save callee-saved registers. */
431 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
432 if (df_regs_ever_live_p (regno) && (!call_used_regs[regno]))
433 cfun->machine->callee_saved_reg_size += 4;
435 cfun->machine->size_for_adjusting_sp =
436 crtl->args.pretend_args_size
437 + cfun->machine->local_vars_size
438 + (ACCUMULATE_OUTGOING_ARGS ? crtl->outgoing_args_size : 0);
441 // Must use LINK/UNLINK when...
442 // the frame is bigger than 512 bytes so cannot just "SUB" from SP
443 // the function actually uses $fp
445 static int
446 must_link (void)
448 int bigframe = (cfun->machine->size_for_adjusting_sp >= 512);
449 return (bigframe || frame_pointer_needed || df_regs_ever_live_p (FT32_FP)
450 || df_regs_ever_live_p (FT32_FP));
453 void
454 ft32_expand_prologue (void)
456 int regno;
457 rtx insn;
459 ft32_compute_frame ();
461 if (flag_stack_usage_info)
462 current_function_static_stack_size = cfun->machine->size_for_adjusting_sp;
464 if (!must_link () && (cfun->machine->callee_saved_reg_size == 4))
466 insn =
467 emit_insn (gen_link
468 (gen_rtx_REG (Pmode, FT32_R13),
469 GEN_INT (-cfun->machine->size_for_adjusting_sp)));
470 RTX_FRAME_RELATED_P (insn) = 1;
471 return;
473 /* Save callee-saved registers. */
474 if (optimize_size)
476 for (regno = FIRST_PSEUDO_REGISTER; regno-- > 0;)
478 if (!fixed_regs[regno] && !call_used_regs[regno]
479 && df_regs_ever_live_p (regno))
481 rtx preg = gen_rtx_REG (Pmode, regno);
482 emit_insn (gen_call_prolog (preg));
483 break;
487 else
489 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
491 if (!fixed_regs[regno] && df_regs_ever_live_p (regno)
492 && !call_used_regs[regno])
494 insn = emit_insn (gen_movsi_push (gen_rtx_REG (Pmode, regno)));
495 RTX_FRAME_RELATED_P (insn) = 1;
500 if (65536 <= cfun->machine->size_for_adjusting_sp)
502 error ("stack frame must be smaller than 64K");
503 return;
505 if (must_link ())
507 insn =
508 emit_insn (gen_link
509 (gen_rtx_REG (Pmode, FT32_FP),
510 GEN_INT (-cfun->machine->size_for_adjusting_sp)));
511 RTX_FRAME_RELATED_P (insn) = 1;
513 else if (cfun->machine->size_for_adjusting_sp > 0)
515 insn = emit_insn (gen_addsi3 (gen_rtx_REG (SImode, FT32_SP),
516 gen_rtx_REG (SImode, FT32_SP),
517 GEN_INT (-(cfun->machine->
518 size_for_adjusting_sp))));
519 RTX_FRAME_RELATED_P (insn) = 1;
523 void
524 ft32_expand_epilogue (void)
526 int regno;
528 if (!must_link ()
529 && (cfun->machine->size_for_adjusting_sp == 24)
530 && (cfun->machine->callee_saved_reg_size == 0))
532 emit_jump_insn (gen_returner24 ());
533 return;
536 // Set when the epilog code will also add 24 to $sp
537 int epilog24 = (!must_link ()
538 && (cfun->machine->size_for_adjusting_sp == 24)
539 && optimize_size);
541 if (must_link ())
543 emit_insn (gen_unlink ());
545 else if (!epilog24 && (cfun->machine->size_for_adjusting_sp > 0))
547 emit_insn (gen_addsi3 (gen_rtx_REG (SImode, FT32_SP),
548 gen_rtx_REG (SImode, FT32_SP),
549 GEN_INT (cfun->machine->size_for_adjusting_sp)));
552 if (cfun->machine->callee_saved_reg_size != 0)
554 for (regno = FIRST_PSEUDO_REGISTER; regno-- > 0;)
556 if (!fixed_regs[regno] && !call_used_regs[regno]
557 && df_regs_ever_live_p (regno))
559 rtx preg = gen_rtx_REG (Pmode, regno);
560 if (optimize_size)
562 if (epilog24)
563 emit_insn (gen_jump_epilog24 (preg));
564 else
565 emit_insn (gen_jump_epilog (preg));
566 return;
568 emit_insn (gen_movsi_pop (preg));
573 emit_jump_insn (gen_returner ());
576 #undef TARGET_FRAME_POINTER_REQUIRED
577 #define TARGET_FRAME_POINTER_REQUIRED ft32_frame_pointer_required
578 static bool
579 ft32_frame_pointer_required (void)
581 return cfun->calls_alloca;
584 #undef TARGET_CAN_ELIMINATE
585 #define TARGET_CAN_ELIMINATE ft32_can_eliminate
587 /* Return true if register FROM can be eliminated via register TO. */
589 static bool
590 ft32_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to)
592 return 1;
593 return (to == FRAME_POINTER_REGNUM) || !ft32_frame_pointer_required ();
596 /* Implements the macro INITIAL_ELIMINATION_OFFSET, return the OFFSET. */
599 ft32_initial_elimination_offset (int from, int to)
601 ft32_compute_frame ();
603 if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM)
605 return cfun->machine->callee_saved_reg_size + 2 * UNITS_PER_WORD;
608 if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
610 int arg_offset;
611 arg_offset = must_link ()? 2 : 1;
612 return ((cfun->machine->callee_saved_reg_size
613 + arg_offset * UNITS_PER_WORD)
614 + cfun->machine->size_for_adjusting_sp);
617 if ((from == FRAME_POINTER_REGNUM) && (to == STACK_POINTER_REGNUM))
619 return cfun->machine->size_for_adjusting_sp;
622 gcc_unreachable ();
625 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. */
627 static void
628 ft32_setup_incoming_varargs (cumulative_args_t cum_v,
629 enum machine_mode mode ATTRIBUTE_UNUSED,
630 tree type ATTRIBUTE_UNUSED,
631 int *pretend_size, int no_rtl)
633 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
634 int regno;
635 int regs = 8 - *cum;
637 *pretend_size = regs < 0 ? 0 : GET_MODE_SIZE (SImode) * regs;
639 if (no_rtl)
640 return;
642 for (regno = *cum; regno < 8; regno++)
644 rtx reg = gen_rtx_REG (SImode, regno);
645 rtx slot = gen_rtx_PLUS (Pmode,
646 gen_rtx_REG (SImode, ARG_POINTER_REGNUM),
647 GEN_INT (UNITS_PER_WORD * (regno - FT32_R0)));
649 emit_move_insn (gen_rtx_MEM (SImode, slot), reg);
654 /* Return the fixed registers used for condition codes. */
656 static bool
657 ft32_fixed_condition_code_regs (unsigned int *p1, unsigned int *p2)
659 *p1 = CC_REG;
660 *p2 = INVALID_REGNUM;
661 return true;
664 /* Return the next register to be used to hold a function argument or
665 NULL_RTX if there's no more space. */
667 static rtx
668 ft32_function_arg (cumulative_args_t cum_v, enum machine_mode mode,
669 const_tree type ATTRIBUTE_UNUSED,
670 bool named ATTRIBUTE_UNUSED)
672 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
674 if (*cum < 8)
675 return gen_rtx_REG (mode, *cum);
676 else
677 return NULL_RTX;
680 #define FT32_FUNCTION_ARG_SIZE(MODE, TYPE) \
681 ((MODE) != BLKmode ? GET_MODE_SIZE (MODE) \
682 : (unsigned) int_size_in_bytes (TYPE))
684 static void
685 ft32_function_arg_advance (cumulative_args_t cum_v, enum machine_mode mode,
686 const_tree type, bool named ATTRIBUTE_UNUSED)
688 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
690 *cum = (*cum < FT32_R6
691 ? *cum + ((3 + FT32_FUNCTION_ARG_SIZE (mode, type)) / 4) : *cum);
694 /* Return non-zero if the function argument described by TYPE is to be
695 passed by reference. */
697 static bool
698 ft32_pass_by_reference (cumulative_args_t cum ATTRIBUTE_UNUSED,
699 enum machine_mode mode, const_tree type,
700 bool named ATTRIBUTE_UNUSED)
702 unsigned HOST_WIDE_INT size;
704 if (type)
706 if (AGGREGATE_TYPE_P (type))
707 return true;
708 size = int_size_in_bytes (type);
710 else
711 size = GET_MODE_SIZE (mode);
713 return size > 4 * 6;
716 /* Some function arguments will only partially fit in the registers
717 that hold arguments. Given a new arg, return the number of bytes
718 that fit in argument passing registers. */
720 static int
721 ft32_arg_partial_bytes (cumulative_args_t cum_v,
722 enum machine_mode mode, tree type, bool named)
724 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
725 int bytes_left, size;
727 if (*cum >= 8)
728 return 0;
730 if (ft32_pass_by_reference (cum_v, mode, type, named))
731 size = 4;
732 else if (type)
734 if (AGGREGATE_TYPE_P (type))
735 return 0;
736 size = int_size_in_bytes (type);
738 else
739 size = GET_MODE_SIZE (mode);
741 bytes_left = (4 * 6) - ((*cum - 2) * 4);
743 if (size > bytes_left)
744 return bytes_left;
745 else
746 return 0;
749 /* Used by constraints.md to distinguish between GENERIC and PM
750 memory addresses. */
753 ft32_is_mem_pm (rtx o)
755 if (GET_CODE (o) != MEM)
756 return false;
757 if (MEM_EXPR (o))
758 return TYPE_ADDR_SPACE (TREE_TYPE (MEM_EXPR (o))) == ADDR_SPACE_PM;
759 else
760 return MEM_ADDR_SPACE (o) == ADDR_SPACE_PM;
763 /* The Global `targetm' Variable. */
765 /* Initialize the GCC target structure. */
767 #undef TARGET_PROMOTE_PROTOTYPES
768 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
770 #undef TARGET_RETURN_IN_MEMORY
771 #define TARGET_RETURN_IN_MEMORY ft32_return_in_memory
772 #undef TARGET_MUST_PASS_IN_STACK
773 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
774 #undef TARGET_PASS_BY_REFERENCE
775 #define TARGET_PASS_BY_REFERENCE ft32_pass_by_reference
776 #undef TARGET_ARG_PARTIAL_BYTES
777 #define TARGET_ARG_PARTIAL_BYTES ft32_arg_partial_bytes
778 #undef TARGET_FUNCTION_ARG
779 #define TARGET_FUNCTION_ARG ft32_function_arg
780 #undef TARGET_FUNCTION_ARG_ADVANCE
781 #define TARGET_FUNCTION_ARG_ADVANCE ft32_function_arg_advance
784 #undef TARGET_SETUP_INCOMING_VARARGS
785 #define TARGET_SETUP_INCOMING_VARARGS ft32_setup_incoming_varargs
787 #undef TARGET_FIXED_CONDITION_CODE_REGS
788 #define TARGET_FIXED_CONDITION_CODE_REGS ft32_fixed_condition_code_regs
790 /* Define this to return an RTX representing the place where a
791 function returns or receives a value of data type RET_TYPE, a tree
792 node node representing a data type. */
793 #undef TARGET_FUNCTION_VALUE
794 #define TARGET_FUNCTION_VALUE ft32_function_value
795 #undef TARGET_LIBCALL_VALUE
796 #define TARGET_LIBCALL_VALUE ft32_libcall_value
797 #undef TARGET_FUNCTION_VALUE_REGNO_P
798 #define TARGET_FUNCTION_VALUE_REGNO_P ft32_function_value_regno_p
800 #undef TARGET_OPTION_OVERRIDE
801 #define TARGET_OPTION_OVERRIDE ft32_option_override
803 #undef TARGET_ASM_SELECT_SECTION
804 #define TARGET_ASM_SELECT_SECTION ft32_select_section
806 #undef TARGET_VALID_POINTER_MODE
807 #define TARGET_VALID_POINTER_MODE ft32_valid_pointer_mode
808 static bool
809 ft32_valid_pointer_mode (enum machine_mode mode)
811 if (mode == SImode)
812 return 1;
813 return 0;
816 #undef TARGET_ADDR_SPACE_POINTER_MODE
817 #define TARGET_ADDR_SPACE_POINTER_MODE ft32_addr_space_pointer_mode
818 static enum machine_mode
819 ft32_addr_space_pointer_mode (addr_space_t addrspace ATTRIBUTE_UNUSED)
821 return Pmode;
824 #undef TARGET_ADDR_SPACE_ADDRESS_MODE
825 #define TARGET_ADDR_SPACE_ADDRESS_MODE ft32_addr_space_address_mode
826 static enum machine_mode
827 ft32_addr_space_address_mode (addr_space_t addrspace ATTRIBUTE_UNUSED)
829 return Pmode;
832 #undef TARGET_ADDR_SPACE_SUBSET_P
833 #define TARGET_ADDR_SPACE_SUBSET_P ft32_addr_space_subset_p
834 static bool
835 ft32_addr_space_subset_p (addr_space_t subset ATTRIBUTE_UNUSED,
836 addr_space_t superset ATTRIBUTE_UNUSED)
838 return false;
841 #undef TARGET_CASE_VALUES_THRESHOLD
842 #define TARGET_CASE_VALUES_THRESHOLD ft32_target_case_values_threshold
844 static unsigned int
845 ft32_target_case_values_threshold (void)
847 return 4;
850 #undef TARGET_ADDR_SPACE_LEGITIMATE_ADDRESS_P
851 #define TARGET_ADDR_SPACE_LEGITIMATE_ADDRESS_P \
852 ft32_addr_space_legitimate_address_p
855 // Enabling LRA gives the infamous
856 // internal compiler error: Max. number of generated reload insns per insn is achieved (90)
857 // errors e.g. when compiling sieve.c
859 static bool
860 ft32_lra_p (void)
862 return ft32_lra_flag;
865 #undef TARGET_LRA_P
866 #define TARGET_LRA_P ft32_lra_p
868 static bool
869 reg_ok_for_base_p (rtx r, bool strict)
871 int NUM = REGNO (r);
872 if (strict)
873 return (HARD_REGNO_OK_FOR_BASE_P (NUM)
874 || HARD_REGNO_OK_FOR_BASE_P (reg_renumber[(NUM)]));
875 else
876 return ((NUM) >= FIRST_PSEUDO_REGISTER || HARD_REGNO_OK_FOR_BASE_P (NUM));
879 static bool
880 ft32_addr_space_legitimate_address_p (enum machine_mode mode, rtx x,
881 bool strict,
882 addr_space_t as ATTRIBUTE_UNUSED)
884 if (mode != BLKmode)
886 if (GET_CODE (x) == PLUS)
888 rtx op1, op2;
889 op1 = XEXP (x, 0);
890 op2 = XEXP (x, 1);
891 if (GET_CODE (op1) == REG
892 && CONST_INT_P (op2)
893 && INTVAL (op2) >= -128
894 && INTVAL (op2) < 128 && reg_ok_for_base_p (op1, strict))
895 goto yes;
896 if (GET_CODE (op1) == SYMBOL_REF && CONST_INT_P (op2))
897 goto yes;
899 if (REG_P (x) && reg_ok_for_base_p (x, strict))
900 goto yes;
901 if (GET_CODE (x) == SYMBOL_REF
902 || GET_CODE (x) == LABEL_REF || CONST_INT_P (x))
903 goto yes;
905 else
907 if (REG_P (x) && reg_ok_for_base_p (x, strict))
908 goto yes;
911 return 0;
912 yes:
913 return 1;
916 struct gcc_target targetm = TARGET_INITIALIZER;
918 #include "gt-ft32.h"