comparison gcc/config/ft32/ft32.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
comparison
equal deleted inserted replaced
68:561a7518be6b 111:04ced10e8804
1 /* Target Code for ft32
2 Copyright (C) 2015-2017 Free Software Foundation, Inc.
3 Contributed by FTDI <support@ftdi.com>
4
5 This file is part of GCC.
6
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.
11
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.
16
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/>. */
20
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"
42
43 /* This file should be included last. */
44 #include "target-def.h"
45
46 #include <stdint.h>
47
48 #define LOSE_AND_RETURN(msgid, x) \
49 do \
50 { \
51 ft32_operand_lossage (msgid, x); \
52 return; \
53 } while (0)
54
55 /* Worker function for TARGET_RETURN_IN_MEMORY. */
56
57 static bool
58 ft32_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
59 {
60 const HOST_WIDE_INT size = int_size_in_bytes (type);
61 return (size == -1 || size > 2 * UNITS_PER_WORD);
62 }
63
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.
68
69 We always return values in register $r0 for ft32. */
70
71 static rtx
72 ft32_function_value (const_tree valtype,
73 const_tree fntype_or_decl ATTRIBUTE_UNUSED,
74 bool outgoing ATTRIBUTE_UNUSED)
75 {
76 return gen_rtx_REG (TYPE_MODE (valtype), FT32_R0);
77 }
78
79 /* Define how to find the value returned by a library function.
80
81 We always return values in register $r0 for ft32. */
82
83 static rtx
84 ft32_libcall_value (machine_mode mode, const_rtx fun ATTRIBUTE_UNUSED)
85 {
86 return gen_rtx_REG (mode, FT32_R0);
87 }
88
89 /* Handle TARGET_FUNCTION_VALUE_REGNO_P.
90
91 We always return values in register $r0 for ft32. */
92
93 static bool
94 ft32_function_value_regno_p (const unsigned int regno)
95 {
96 return (regno == FT32_R0);
97 }
98
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. */
103
104 static void
105 ft32_operand_lossage (const char *msgid, rtx op)
106 {
107 debug_rtx (op);
108 output_operand_lossage ("%s", msgid);
109 }
110
111 /* The PRINT_OPERAND_ADDRESS worker. */
112
113 void
114 ft32_print_operand_address (FILE * file, rtx x)
115 {
116 switch (GET_CODE (x))
117 {
118 case REG:
119 fprintf (file, "%s,0", reg_names[REGNO (x)]);
120 break;
121
122 case PLUS:
123 switch (GET_CODE (XEXP (x, 1)))
124 {
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:
134 {
135 rtx plus = XEXP (XEXP (x, 1), 0);
136 if (GET_CODE (XEXP (plus, 0)) == SYMBOL_REF
137 && CONST_INT_P (XEXP (plus, 1)))
138 {
139 output_addr_const (file, XEXP (plus, 0));
140 fprintf (file, "+%ld(%s)", INTVAL (XEXP (plus, 1)),
141 reg_names[REGNO (XEXP (x, 0))]);
142 }
143 else
144 abort ();
145 }
146 break;
147 default:
148 abort ();
149 }
150 break;
151
152 default:
153 output_addr_const (file, x);
154 break;
155 }
156 }
157
158 /* The PRINT_OPERAND worker. */
159
160 void
161 ft32_print_operand (FILE * file, rtx x, int code)
162 {
163 rtx operand = x;
164
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. */
170
171 switch (code)
172 {
173 case 0:
174 /* No code, print as usual. */
175 break;
176
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;
182
183 case 'm':
184 fprintf (file, "%ld", (long) (- INTVAL(x)));
185 return;
186
187 case 'd': // a DW spec, from an integer alignment (for BLKmode insns)
188 {
189 int i = INTVAL (x);
190 char dwspec;
191 switch (i)
192 {
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;
208 }
209 fprintf (file, "%c", dwspec);
210 return;
211 }
212
213 case 'f':
214 {
215 int bf = ft32_as_bitfield (INTVAL (x));
216 fprintf (file, "512|(%d<<5)|%d", bf >> 5, bf & 31);
217 return;
218 }
219
220 case 'g':
221 {
222 int bf = ft32_as_bitfield (0xffffffff ^ INTVAL (x));
223 fprintf (file, "(%d<<5)|%d", bf >> 5, bf & 31);
224 return;
225 }
226
227 case 'b':
228 {
229 ft32_print_operand (file, XEXP (x, 0), 0);
230 return;
231 }
232
233 default:
234 LOSE_AND_RETURN ("invalid operand modifier letter", x);
235 }
236
237 /* Print an operand as without a modifier letter. */
238 switch (GET_CODE (operand))
239 {
240 case REG:
241 fprintf (file, "%s", reg_names[REGNO (operand)]);
242 return;
243
244 case MEM:
245 output_address (GET_MODE (XEXP (operand, 0)), XEXP (operand, 0));
246 return;
247
248 default:
249 /* No need to handle all strange variants, let output_addr_const
250 do it for us. */
251 if (CONSTANT_P (operand))
252 {
253 output_addr_const (file, operand);
254 return;
255 }
256
257 LOSE_AND_RETURN ("unexpected operand", x);
258 }
259 }
260
261 const char *
262 ft32_load_immediate (rtx dst, int32_t i)
263 {
264 char pattern[100];
265
266 if ((-524288 <= i) && (i <= 524287))
267 {
268 sprintf (pattern, "ldk.l %%0,%d", i);
269 output_asm_insn (pattern, &dst);
270 }
271 else if ((-536870912 <= i) && (i <= 536870911))
272 {
273 ft32_load_immediate (dst, i >> 10);
274 sprintf (pattern, "ldl.l %%0,%%0,%d", i & 1023);
275 output_asm_insn (pattern, &dst);
276 }
277 else
278 {
279 int rd; // rotate distance
280 uint32_t u = i;
281 for (rd = 1; rd < 32; rd++)
282 {
283 u = ((u >> 31) & 1) | (u << 1);
284 if ((-524288 <= (int32_t) u) && ((int32_t) u <= 524287))
285 {
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 "";
290 }
291 }
292 ft32_load_immediate (dst, i >> 10);
293 sprintf (pattern, "ldl.l %%0,%%0,%d", i & 1023);
294 output_asm_insn (pattern, &dst);
295 }
296
297 return "";
298 }
299
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.
305 //
306
307 #define NBITS(n) ((1U << (n)) - 1U)
308
309 int
310 ft32_as_bitfield (unsigned int x)
311 {
312 int lobit, hibit;
313
314 if (x == 0)
315 return -1;
316
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;
323
324 int width = 1 + hibit - lobit;
325 if (width > 16)
326 return -1;
327
328 if (x != (NBITS (width) << lobit))
329 return -1; // not a clean bitfield
330
331 return ((width & 15) << 5) | lobit;
332 }
333
334 /* Per-function machine data. */
335 struct GTY (()) machine_function
336 {
337 /* Number of bytes saved on the stack for callee saved registers. */
338 int callee_saved_reg_size;
339
340 /* Number of bytes saved on the stack for local variables. */
341 int local_vars_size;
342
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;
346 };
347
348 /* Zero initialization is OK for all current fields. */
349
350 static struct machine_function *
351 ft32_init_machine_status (void)
352 {
353 return ggc_cleared_alloc < machine_function > ();
354 }
355
356
357 /* The TARGET_OPTION_OVERRIDE worker.
358 All this curently does is set init_machine_status. */
359 static void
360 ft32_option_override (void)
361 {
362 /* Set the per-function-data initializer. */
363 init_machine_status = ft32_init_machine_status;
364 }
365
366 /* Implement targetm.select_section. */
367 static section *
368 ft32_select_section (tree decl, int reloc, unsigned HOST_WIDE_INT align)
369 {
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)
374 {
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);
380
381 return get_named_section (decl, "._pm", reloc);
382 }
383
384 return default_elf_select_section (decl, reloc, align);
385 }
386
387 /* Compute the size of the local area and the size to be adjusted by the
388 * prologue and epilogue. */
389
390 static void
391 ft32_compute_frame (void)
392 {
393 /* For aligning the local variables. */
394 int stack_alignment = STACK_BOUNDARY / BITS_PER_UNIT;
395 int padding_locals;
396 int regno;
397
398 /* Padding needed for each element of the frame. */
399 cfun->machine->local_vars_size = get_frame_size ();
400
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;
405
406 cfun->machine->local_vars_size += padding_locals;
407
408 cfun->machine->callee_saved_reg_size = 0;
409
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;
414
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);
419 }
420
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
424
425 static int
426 must_link (void)
427 {
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));
431 }
432
433 void
434 ft32_expand_prologue (void)
435 {
436 int regno;
437 rtx insn;
438
439 ft32_compute_frame ();
440
441 int args_to_push = crtl->args.pretend_args_size;
442 if (args_to_push)
443 {
444 int i;
445
446 insn = emit_insn (gen_movsi_pop ((gen_rtx_REG (Pmode, FT32_R29))));
447
448 for (i = 0; i < (args_to_push / 4); i++)
449 {
450 insn =
451 emit_insn (gen_movsi_push ((gen_rtx_REG (Pmode, FT32_R5 - i))));
452 RTX_FRAME_RELATED_P (insn) = 1;
453 }
454
455 insn = emit_insn (gen_movsi_push ((gen_rtx_REG (Pmode, FT32_R29))));
456 }
457
458 if (flag_stack_usage_info)
459 current_function_static_stack_size = cfun->machine->size_for_adjusting_sp;
460
461 if (!must_link () && (cfun->machine->callee_saved_reg_size == 4))
462 {
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;
469 }
470 /* Save callee-saved registers. */
471 if (optimize_size)
472 {
473 for (regno = FIRST_PSEUDO_REGISTER; regno-- > 0;)
474 {
475 if (!fixed_regs[regno] && !call_used_regs[regno]
476 && df_regs_ever_live_p (regno))
477 {
478 rtx preg = gen_rtx_REG (Pmode, regno);
479 emit_insn (gen_call_prolog (preg));
480 break;
481 }
482 }
483 }
484 else
485 {
486 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
487 {
488 if (!fixed_regs[regno] && df_regs_ever_live_p (regno)
489 && !call_used_regs[regno])
490 {
491 insn = emit_insn (gen_movsi_push (gen_rtx_REG (Pmode, regno)));
492 RTX_FRAME_RELATED_P (insn) = 1;
493 }
494 }
495 }
496
497 if (65536 <= cfun->machine->size_for_adjusting_sp)
498 {
499 error ("stack frame must be smaller than 64K");
500 return;
501 }
502 if (must_link ())
503 {
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;
509 }
510 else if (cfun->machine->size_for_adjusting_sp > 0)
511 {
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;
517 }
518 }
519
520 void
521 ft32_expand_epilogue (void)
522 {
523 int regno;
524 int pretend = crtl->args.pretend_args_size;
525
526 if (!must_link ()
527 && (cfun->machine->size_for_adjusting_sp == 24)
528 && (cfun->machine->callee_saved_reg_size == 0))
529 {
530 emit_jump_insn (gen_returner24 ());
531 return;
532 }
533
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);
538
539 if (must_link ())
540 {
541 emit_insn (gen_unlink ());
542 }
543 else if (!epilog24 && (cfun->machine->size_for_adjusting_sp > 0))
544 {
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)));
548 }
549
550 if (cfun->machine->callee_saved_reg_size != 0)
551 {
552 for (regno = FIRST_PSEUDO_REGISTER; regno-- > 0;)
553 {
554 if (!fixed_regs[regno] && !call_used_regs[regno]
555 && df_regs_ever_live_p (regno))
556 {
557 rtx preg = gen_rtx_REG (Pmode, regno);
558 if (optimize_size && (pretend == 0))
559 {
560 if (epilog24)
561 emit_insn (gen_jump_epilog24 (preg));
562 else
563 emit_insn (gen_jump_epilog (preg));
564 return;
565 }
566 emit_insn (gen_movsi_pop (preg));
567 }
568 }
569 }
570
571 if (pretend != 0)
572 emit_jump_insn (gen_pretend_returner (GEN_INT (pretend)));
573 else
574 emit_jump_insn (gen_returner ());
575 }
576
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)
581 {
582 return cfun->calls_alloca;
583 }
584
585 #undef TARGET_CAN_ELIMINATE
586 #define TARGET_CAN_ELIMINATE ft32_can_eliminate
587
588 /* Return true if register FROM can be eliminated via register TO. */
589
590 static bool
591 ft32_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to)
592 {
593 return 1;
594 return (to == FRAME_POINTER_REGNUM) || !ft32_frame_pointer_required ();
595 }
596
597 /* Implements the macro INITIAL_ELIMINATION_OFFSET, return the OFFSET. */
598
599 int
600 ft32_initial_elimination_offset (int from, int to)
601 {
602 ft32_compute_frame ();
603
604 if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM)
605 {
606 return cfun->machine->callee_saved_reg_size + 2 * UNITS_PER_WORD;
607 }
608
609 if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
610 {
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);
616 }
617
618 if ((from == FRAME_POINTER_REGNUM) && (to == STACK_POINTER_REGNUM))
619 {
620 return cfun->machine->size_for_adjusting_sp;
621 }
622
623 gcc_unreachable ();
624 }
625
626 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. */
627
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)
633 {
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);
637
638 if (named_size < 24)
639 *pretend_size = 24 - named_size;
640 else
641 *pretend_size = 0;
642 }
643
644 /* Return the fixed registers used for condition codes. */
645
646 static bool
647 ft32_fixed_condition_code_regs (unsigned int *p1, unsigned int *p2)
648 {
649 *p1 = CC_REG;
650 *p2 = INVALID_REGNUM;
651 return true;
652 }
653
654 /* Return the next register to be used to hold a function argument or
655 NULL_RTX if there's no more space. */
656
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)
661 {
662 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
663
664 if (*cum < 8)
665 return gen_rtx_REG (mode, *cum);
666 else
667 return NULL_RTX;
668 }
669
670 #define FT32_FUNCTION_ARG_SIZE(MODE, TYPE) \
671 ((MODE) != BLKmode ? GET_MODE_SIZE (MODE) \
672 : (unsigned) int_size_in_bytes (TYPE))
673
674 static void
675 ft32_function_arg_advance (cumulative_args_t cum_v, machine_mode mode,
676 const_tree type, bool named ATTRIBUTE_UNUSED)
677 {
678 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
679
680 *cum = (*cum < FT32_R6
681 ? *cum + ((3 + FT32_FUNCTION_ARG_SIZE (mode, type)) / 4) : *cum);
682 }
683
684 /* Return non-zero if the function argument described by TYPE is to be
685 passed by reference. */
686
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)
691 {
692 unsigned HOST_WIDE_INT size;
693
694 if (type)
695 {
696 if (AGGREGATE_TYPE_P (type))
697 return true;
698 size = int_size_in_bytes (type);
699 }
700 else
701 size = GET_MODE_SIZE (mode);
702
703 return size > 4 * 6;
704 }
705
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. */
709
710 static int
711 ft32_arg_partial_bytes (cumulative_args_t cum_v,
712 machine_mode mode, tree type, bool named)
713 {
714 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
715 int bytes_left, size;
716
717 if (*cum >= 8)
718 return 0;
719
720 if (ft32_pass_by_reference (cum_v, mode, type, named))
721 size = 4;
722 else if (type)
723 {
724 if (AGGREGATE_TYPE_P (type))
725 return 0;
726 size = int_size_in_bytes (type);
727 }
728 else
729 size = GET_MODE_SIZE (mode);
730
731 bytes_left = (4 * 6) - ((*cum - 2) * 4);
732
733 if (size > bytes_left)
734 return bytes_left;
735 else
736 return 0;
737 }
738
739 /* Used by constraints.md to distinguish between GENERIC and PM
740 memory addresses. */
741
742 int
743 ft32_is_mem_pm (rtx o)
744 {
745 return (MEM_P (o)
746 && !ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (o)));
747 }
748
749 /* The Global `targetm' Variable. */
750
751 /* Initialize the GCC target structure. */
752
753 #undef TARGET_PROMOTE_PROTOTYPES
754 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
755
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
768
769
770 #undef TARGET_SETUP_INCOMING_VARARGS
771 #define TARGET_SETUP_INCOMING_VARARGS ft32_setup_incoming_varargs
772
773 #undef TARGET_FIXED_CONDITION_CODE_REGS
774 #define TARGET_FIXED_CONDITION_CODE_REGS ft32_fixed_condition_code_regs
775
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
785
786 #undef TARGET_OPTION_OVERRIDE
787 #define TARGET_OPTION_OVERRIDE ft32_option_override
788
789 #undef TARGET_ASM_SELECT_SECTION
790 #define TARGET_ASM_SELECT_SECTION ft32_select_section
791
792 #undef TARGET_VALID_POINTER_MODE
793 #define TARGET_VALID_POINTER_MODE ft32_valid_pointer_mode
794 static bool
795 ft32_valid_pointer_mode (scalar_int_mode mode)
796 {
797 if (mode == SImode)
798 return 1;
799 return 0;
800 }
801
802 #undef TARGET_ADDR_SPACE_POINTER_MODE
803 #define TARGET_ADDR_SPACE_POINTER_MODE ft32_addr_space_pointer_mode
804 static scalar_int_mode
805 ft32_addr_space_pointer_mode (addr_space_t addrspace ATTRIBUTE_UNUSED)
806 {
807 return Pmode;
808 }
809
810 #undef TARGET_ADDR_SPACE_ADDRESS_MODE
811 #define TARGET_ADDR_SPACE_ADDRESS_MODE ft32_addr_space_address_mode
812 static scalar_int_mode
813 ft32_addr_space_address_mode (addr_space_t addrspace ATTRIBUTE_UNUSED)
814 {
815 return Pmode;
816 }
817
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)
823 {
824 return false;
825 }
826
827 #undef TARGET_CASE_VALUES_THRESHOLD
828 #define TARGET_CASE_VALUES_THRESHOLD ft32_target_case_values_threshold
829
830 static unsigned int
831 ft32_target_case_values_threshold (void)
832 {
833 return 4;
834 }
835
836 #undef TARGET_ADDR_SPACE_LEGITIMATE_ADDRESS_P
837 #define TARGET_ADDR_SPACE_LEGITIMATE_ADDRESS_P \
838 ft32_addr_space_legitimate_address_p
839
840
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
844
845 static bool
846 ft32_lra_p (void)
847 {
848 return ft32_lra_flag;
849 }
850
851 #undef TARGET_LRA_P
852 #define TARGET_LRA_P ft32_lra_p
853
854 static bool
855 reg_ok_for_base_p (rtx r, bool strict)
856 {
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));
863 }
864
865 static bool
866 ft32_addr_space_legitimate_address_p (machine_mode mode, rtx x, bool strict,
867 addr_space_t as ATTRIBUTE_UNUSED)
868 {
869 if (mode != BLKmode)
870 {
871 if (GET_CODE (x) == PLUS)
872 {
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;
883 }
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;
889 }
890 else
891 {
892 if (REG_P (x) && reg_ok_for_base_p (x, strict))
893 goto yes;
894 }
895
896 return 0;
897 yes:
898 return 1;
899 }
900
901 #undef TARGET_ENCODE_SECTION_INFO
902 #define TARGET_ENCODE_SECTION_INFO ft32_elf_encode_section_info
903
904 void
905 ft32_elf_encode_section_info (tree decl, rtx rtl, int first)
906 {
907 enum tree_code code;
908 rtx symbol;
909
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;
916
917 default_encode_section_info (decl, rtl, first);
918
919 code = TREE_CODE (decl);
920 switch (TREE_CODE_CLASS (code))
921 {
922 case tcc_declaration:
923 {
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;
929 }
930 break;
931
932 case tcc_constant:
933 case tcc_exceptional:
934 if (code == STRING_CST)
935 SYMBOL_REF_FLAGS (symbol) |= 0x1000;
936 break;
937
938 default:
939 break;
940 }
941 }
942
943 #undef TARGET_CONSTANT_ALIGNMENT
944 #define TARGET_CONSTANT_ALIGNMENT constant_alignment_word_strings
945
946 struct gcc_target targetm = TARGET_INITIALIZER;
947
948 #include "gt-ft32.h"