Debian Codegraph @

gcc/config/epiphany/epiphany.cc

raw
1 /* Subroutines used for code generation on the EPIPHANY cpu.
2 Copyright (C) 1994-2025 Free Software Foundation, Inc.
3 Contributed by Embecosm on behalf of Adapteva, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
11
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public 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 #define IN_TARGET_CODE 1
22
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "backend.h"
27 #include "target.h"
28 #include "rtl.h"
29 #include "tree.h"
30 #include "df.h"
31 #include "memmodel.h"
32 #include "tm_p.h"
33 #include "stringpool.h"
34 #include "attribs.h"
35 #include "optabs.h"
36 #include "emit-rtl.h"
37 #include "recog.h"
38 #include "diagnostic-core.h"
39 #include "alias.h"
40 #include "stor-layout.h"
41 #include "varasm.h"
42 #include "calls.h"
43 #include "output.h"
44 #include "insn-attr.h"
45 #include "explow.h"
46 #include "expr.h"
47 #include "tm-constrs.h"
48 #include "tree-pass.h" /* for current_pass */
49 #include "context.h"
50 #include "pass_manager.h"
51 #include "builtins.h"
52
53 /* Which cpu we're compiling for. */
54 int epiphany_cpu_type;
55
56 /* Name of mangle string to add to symbols to separate code compiled for each
57 cpu (or NULL). */
58 const char *epiphany_mangle_cpu;
59
60 /* Array of valid operand punctuation characters. */
61 char epiphany_punct_chars[256];
62
63 /* The rounding mode that we generally use for floating point. */
64 int epiphany_normal_fp_rounding;
65
66 /* The pass instance, for use in epiphany_optimize_mode_switching. */
67 static opt_pass *pass_mode_switch_use;
68
69 static void epiphany_init_reg_tables (void);
70 static int get_epiphany_condition_code (rtx);
71 static tree epiphany_handle_interrupt_attribute (tree *, tree, tree, int, bool *);
72 static tree epiphany_handle_forwarder_attribute (tree *, tree, tree, int,
73 bool *);
74 static bool epiphany_pass_by_reference (cumulative_args_t,
75 const function_arg_info &);
76 static rtx_insn *frame_insn (rtx);
77
78 /* defines for the initialization of the GCC target structure. */
79 #define TARGET_ATTRIBUTE_TABLE epiphany_attribute_table
80
81 #define TARGET_PRINT_OPERAND epiphany_print_operand
82 #define TARGET_PRINT_OPERAND_ADDRESS epiphany_print_operand_address
83
84 #define TARGET_RTX_COSTS epiphany_rtx_costs
85 #define TARGET_ADDRESS_COST epiphany_address_cost
86 #define TARGET_MEMORY_MOVE_COST epiphany_memory_move_cost
87
88 #define TARGET_PROMOTE_FUNCTION_MODE epiphany_promote_function_mode
89 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
90
91 #define TARGET_RETURN_IN_MEMORY epiphany_return_in_memory
92 #define TARGET_PASS_BY_REFERENCE epiphany_pass_by_reference
93 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_arg_info_true
94 #define TARGET_FUNCTION_VALUE epiphany_function_value
95 #define TARGET_LIBCALL_VALUE epiphany_libcall_value
96 #define TARGET_FUNCTION_VALUE_REGNO_P epiphany_function_value_regno_p
97
98 #define TARGET_SETUP_INCOMING_VARARGS epiphany_setup_incoming_varargs
99
100 /* Using the simplistic varags handling forces us to do partial reg/stack
101 argument passing for types with larger size (> 4 bytes) than alignment. */
102 #define TARGET_ARG_PARTIAL_BYTES epiphany_arg_partial_bytes
103
104 #define TARGET_FUNCTION_OK_FOR_SIBCALL epiphany_function_ok_for_sibcall
105
106 #define TARGET_SCHED_ISSUE_RATE epiphany_issue_rate
107 #define TARGET_SCHED_ADJUST_COST epiphany_adjust_cost
108
109 #define TARGET_LEGITIMATE_ADDRESS_P epiphany_legitimate_address_p
110
111 #define TARGET_SECONDARY_RELOAD epiphany_secondary_reload
112
113 #define TARGET_OPTION_OVERRIDE epiphany_override_options
114
115 #define TARGET_CONDITIONAL_REGISTER_USAGE epiphany_conditional_register_usage
116
117 #define TARGET_FUNCTION_ARG epiphany_function_arg
118
119 #define TARGET_FUNCTION_ARG_ADVANCE epiphany_function_arg_advance
120
121 #define TARGET_FUNCTION_ARG_BOUNDARY epiphany_function_arg_boundary
122
123 #define TARGET_TRAMPOLINE_INIT epiphany_trampoline_init
124
125 /* Nonzero if the constant rtx value is a legitimate general operand.
126 We can handle any 32- or 64-bit constant. */
127 #define TARGET_LEGITIMATE_CONSTANT_P hook_bool_mode_rtx_true
128
129 #define TARGET_MIN_DIVISIONS_FOR_RECIP_MUL \
130 epiphany_min_divisions_for_recip_mul
131
132 #define TARGET_VECTORIZE_PREFERRED_SIMD_MODE epiphany_preferred_simd_mode
133
134 #define TARGET_VECTOR_MODE_SUPPORTED_P epiphany_vector_mode_supported_p
135
136 #define TARGET_VECTORIZE_VECTOR_ALIGNMENT_REACHABLE \
137 epiphany_vector_alignment_reachable
138
139 #define TARGET_VECTORIZE_SUPPORT_VECTOR_MISALIGNMENT \
140 epiphany_support_vector_misalignment
141
142 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK \
143 hook_bool_const_tree_hwi_hwi_const_tree_true
144 #define TARGET_ASM_OUTPUT_MI_THUNK epiphany_output_mi_thunk
145
146 /* ??? we can use larger offsets for wider-mode sized accesses, but there
147 is no concept of anchors being dependent on the modes that they are used
148 for, so we can only use an offset range that would suit all modes. */
149 #define TARGET_MAX_ANCHOR_OFFSET (optimize_size ? 31 : 2047)
150 /* We further restrict the minimum to be a multiple of eight. */
151 #define TARGET_MIN_ANCHOR_OFFSET (optimize_size ? 0 : -2040)
152
153 /* Mode switching hooks. */
154
155 #define TARGET_MODE_EMIT emit_set_fp_mode
156
157 #define TARGET_MODE_NEEDED epiphany_mode_needed
158
159 #define TARGET_MODE_PRIORITY epiphany_mode_priority
160
161 #define TARGET_MODE_ENTRY epiphany_mode_entry
162
163 #define TARGET_MODE_EXIT epiphany_mode_exit
164
165 #define TARGET_MODE_AFTER epiphany_mode_after
166
167 #include "target-def.h"
168
169 #undef TARGET_ASM_ALIGNED_HI_OP
170 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
171 #undef TARGET_ASM_ALIGNED_SI_OP
172 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
173
174 #undef TARGET_HARD_REGNO_MODE_OK
175 #define TARGET_HARD_REGNO_MODE_OK epiphany_hard_regno_mode_ok
176
177 #undef TARGET_CONSTANT_ALIGNMENT
178 #define TARGET_CONSTANT_ALIGNMENT epiphany_constant_alignment
179
180 #undef TARGET_STARTING_FRAME_OFFSET
181 #define TARGET_STARTING_FRAME_OFFSET epiphany_starting_frame_offset
182
183 bool
184 epiphany_is_interrupt_p (tree decl)
185 {
186 tree attrs;
187
188 attrs = DECL_ATTRIBUTES (decl);
189 if (lookup_attribute ("interrupt", attrs))
190 return true;
191 else
192 return false;
193 }
194
195 /* Called from epiphany_override_options.
196 We use this to initialize various things. */
197
198 static void
199 epiphany_init (void)
200 {
201 /* N.B. this pass must not run before the first optimize_mode_switching
202 pass because of the side offect of epiphany_mode_needed on
203 MACHINE_FUNCTION(cfun)->unknown_mode_uses. But it must run before
204 pass_resolve_sw_modes. */
205 pass_mode_switch_use = make_pass_mode_switch_use (g);
206 struct register_pass_info insert_use_info
207 = { pass_mode_switch_use, "mode_sw",
208 1, PASS_POS_INSERT_AFTER
209 };
210 opt_pass *mode_sw2
211 = g->get_passes()->get_pass_mode_switching ()->clone ();
212 struct register_pass_info mode_sw2_info
213 = { mode_sw2, "mode_sw",
214 1, PASS_POS_INSERT_AFTER
215 };
216 opt_pass *mode_sw3 = make_pass_resolve_sw_modes (g);
217 struct register_pass_info mode_sw3_info
218 = { mode_sw3, "mode_sw",
219 1, PASS_POS_INSERT_AFTER
220 };
221 opt_pass *mode_sw4
222 = g->get_passes()->get_pass_split_all_insns ()->clone ();
223 struct register_pass_info mode_sw4_info
224 = { mode_sw4, "mode_sw",
225 1, PASS_POS_INSERT_AFTER
226 };
227 static const int num_modes[] = NUM_MODES_FOR_MODE_SWITCHING;
228 #define N_ENTITIES ARRAY_SIZE (num_modes)
229
230 epiphany_init_reg_tables ();
231
232 /* Initialize array for PRINT_OPERAND_PUNCT_VALID_P. */
233 memset (epiphany_punct_chars, 0, sizeof (epiphany_punct_chars));
234 epiphany_punct_chars['-'] = 1;
235
236 epiphany_normal_fp_rounding
237 = (epiphany_normal_fp_mode == FP_MODE_ROUND_TRUNC
238 ? FP_MODE_ROUND_TRUNC : FP_MODE_ROUND_NEAREST);
239 register_pass (&mode_sw4_info);
240 register_pass (&mode_sw2_info);
241 register_pass (&mode_sw3_info);
242 register_pass (&insert_use_info);
243 register_pass (&mode_sw2_info);
244 /* Verify that NUM_MODES_FOR_MODE_SWITCHING has one value per entity. */
245 gcc_assert (N_ENTITIES == EPIPHANY_MSW_ENTITY_NUM);
246
247 #if 1 /* As long as peep2_rescan is not implemented,
248 (see http://gcc.gnu.org/ml/gcc-patches/2011-10/msg02819.html,)
249 we need a second peephole2 pass to get reasonable code. */
250 {
251 opt_pass *extra_peephole2
252 = g->get_passes ()->get_pass_peephole2 ()->clone ();
253 struct register_pass_info peep2_2_info
254 = { extra_peephole2, "peephole2",
255 1, PASS_POS_INSERT_AFTER
256 };
257
258 register_pass (&peep2_2_info);
259 }
260 #endif
261 }
262
263 /* The condition codes of the EPIPHANY, and the inverse function. */
264 static const char *const epiphany_condition_codes[] =
265 { /* 0 1 2 3 4 5 6 7 8 9 */
266 "eq", "ne", "ltu", "gteu", "gt", "lte", "gte", "lt", "gtu", "lteu",
267 /* 10 11 12 13 */
268 "beq","bne","blt", "blte",
269 };
270
271 #define EPIPHANY_INVERSE_CONDITION_CODE(X) ((X) ^ 1)
272
273 /* Returns the index of the EPIPHANY condition code string in
274 `epiphany_condition_codes'. COMPARISON should be an rtx like
275 `(eq (...) (...))'. */
276
277 static int
278 get_epiphany_condition_code (rtx comparison)
279 {
280 switch (GET_MODE (XEXP (comparison, 0)))
281 {
282 case E_CCmode:
283 switch (GET_CODE (comparison))
284 {
285 case EQ : return 0;
286 case NE : return 1;
287 case LTU : return 2;
288 case GEU : return 3;
289 case GT : return 4;
290 case LE : return 5;
291 case GE : return 6;
292 case LT : return 7;
293 case GTU : return 8;
294 case LEU : return 9;
295
296 default : gcc_unreachable ();
297 }
298 case E_CC_N_NEmode:
299 switch (GET_CODE (comparison))
300 {
301 case EQ: return 6;
302 case NE: return 7;
303 default: gcc_unreachable ();
304 }
305 case E_CC_C_LTUmode:
306 switch (GET_CODE (comparison))
307 {
308 case GEU: return 2;
309 case LTU: return 3;
310 default: gcc_unreachable ();
311 }
312 case E_CC_C_GTUmode:
313 switch (GET_CODE (comparison))
314 {
315 case LEU: return 3;
316 case GTU: return 2;
317 default: gcc_unreachable ();
318 }
319 case E_CC_FPmode:
320 switch (GET_CODE (comparison))
321 {
322 case EQ: return 10;
323 case NE: return 11;
324 case LT: return 12;
325 case LE: return 13;
326 default: gcc_unreachable ();
327 }
328 case E_CC_FP_EQmode:
329 switch (GET_CODE (comparison))
330 {
331 case EQ: return 0;
332 case NE: return 1;
333 default: gcc_unreachable ();
334 }
335 case E_CC_FP_GTEmode:
336 switch (GET_CODE (comparison))
337 {
338 case EQ: return 0;
339 case NE: return 1;
340 case GT : return 4;
341 case GE : return 6;
342 case UNLE : return 5;
343 case UNLT : return 7;
344 default: gcc_unreachable ();
345 }
346 case E_CC_FP_ORDmode:
347 switch (GET_CODE (comparison))
348 {
349 case ORDERED: return 9;
350 case UNORDERED: return 8;
351 default: gcc_unreachable ();
352 }
353 case E_CC_FP_UNEQmode:
354 switch (GET_CODE (comparison))
355 {
356 case UNEQ: return 9;
357 case LTGT: return 8;
358 default: gcc_unreachable ();
359 }
360 default: gcc_unreachable ();
361 }
362 /*NOTREACHED*/
363 return (42);
364 }
365
366
367 /* Implement TARGET_HARD_REGNO_MODE_OK. */
368
369 static bool
370 epiphany_hard_regno_mode_ok (unsigned int regno, machine_mode mode)
371 {
372 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
373 return (regno & 1) == 0 && GPR_P (regno);
374 else
375 return true;
376 }
377
378 /* Given a comparison code (EQ, NE, etc.) and the first operand of a COMPARE,
379 return the mode to be used for the comparison. */
380
381 machine_mode
382 epiphany_select_cc_mode (enum rtx_code op,
383 rtx x ATTRIBUTE_UNUSED,
384 rtx y ATTRIBUTE_UNUSED)
385 {
386 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
387 {
388 if (TARGET_SOFT_CMPSF
389 || op == ORDERED || op == UNORDERED)
390 {
391 if (op == EQ || op == NE)
392 return CC_FP_EQmode;
393 if (op == ORDERED || op == UNORDERED)
394 return CC_FP_ORDmode;
395 if (op == UNEQ || op == LTGT)
396 return CC_FP_UNEQmode;
397 return CC_FP_GTEmode;
398 }
399 return CC_FPmode;
400 }
401 /* recognize combiner pattern ashlsi_btst:
402 (parallel [
403 (set (reg:N_NE 65 cc1)
404 (compare:N_NE (zero_extract:SI (reg/v:SI 75 [ a ])
405 (const_int 1 [0x1])
406 (const_int 0 [0x0]))
407 (const_int 0 [0x0])))
408 (clobber (scratch:SI)) */
409 else if ((op == EQ || op == NE)
410 && GET_CODE (x) == ZERO_EXTRACT
411 && XEXP (x, 1) == const1_rtx
412 && CONST_INT_P (XEXP (x, 2)))
413 return CC_N_NEmode;
414 else if ((op == GEU || op == LTU) && GET_CODE (x) == PLUS)
415 return CC_C_LTUmode;
416 else if ((op == LEU || op == GTU) && GET_CODE (x) == MINUS)
417 return CC_C_GTUmode;
418 else
419 return CCmode;
420 }
421
422 enum reg_class epiphany_regno_reg_class[FIRST_PSEUDO_REGISTER];
423
424 static void
425 epiphany_init_reg_tables (void)
426 {
427 int i;
428
429 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
430 {
431 if (i == GPR_LR)
432 epiphany_regno_reg_class[i] = LR_REGS;
433 else if (i <= 7 && TARGET_PREFER_SHORT_INSN_REGS)
434 epiphany_regno_reg_class[i] = SHORT_INSN_REGS;
435 else if (call_used_or_fixed_reg_p (i)
436 && TEST_HARD_REG_BIT (reg_class_contents[GENERAL_REGS], i))
437 epiphany_regno_reg_class[i] = SIBCALL_REGS;
438 else if (i >= CORE_CONTROL_FIRST && i <= CORE_CONTROL_LAST)
439 epiphany_regno_reg_class[i] = CORE_CONTROL_REGS;
440 else if (i < (GPR_LAST+1)
441 || i == ARG_POINTER_REGNUM || i == FRAME_POINTER_REGNUM)
442 epiphany_regno_reg_class[i] = GENERAL_REGS;
443 else if (i == CC_REGNUM)
444 epiphany_regno_reg_class[i] = NO_REGS /* CC_REG: must be NO_REGS */;
445 else
446 epiphany_regno_reg_class[i] = NO_REGS;
447 }
448 }
449
450 /* EPIPHANY specific attribute support.
451
452 The EPIPHANY has these attributes:
453 interrupt - for interrupt functions.
454 short_call - the function is assumed to be reachable with the b / bl
455 instructions.
456 long_call - the function address is loaded into a register before use.
457 disinterrupt - functions which mask interrupts throughout.
458 They unmask them while calling an interruptible
459 function, though. */
460
461 TARGET_GNU_ATTRIBUTES (epiphany_attribute_table,
462 {
463 /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
464 affects_type_identity, handler, exclude } */
465 { "interrupt", 0, 9, true, false, false, true,
466 epiphany_handle_interrupt_attribute, NULL },
467 { "forwarder_section", 1, 1, true, false, false, false,
468 epiphany_handle_forwarder_attribute, NULL },
469 { "long_call", 0, 0, false, true, true, false, NULL, NULL },
470 { "short_call", 0, 0, false, true, true, false, NULL, NULL },
471 { "disinterrupt", 0, 0, false, true, true, true, NULL, NULL }
472 });
473
474 /* Handle an "interrupt" attribute; arguments as in
475 struct attribute_spec.handler. */
476 static tree
477 epiphany_handle_interrupt_attribute (tree *node, tree name, tree args,
478 int flags ATTRIBUTE_UNUSED,
479 bool *no_add_attrs)
480 {
481 tree value;
482
483 if (!args)
484 {
485 gcc_assert (DECL_P (*node));
486 tree t = TREE_TYPE (*node);
487 if (TREE_CODE (t) != FUNCTION_TYPE)
488 warning (OPT_Wattributes, "%qE attribute only applies to functions",
489 name);
490 /* Argument handling and the stack layout for interrupt handlers
491 don't mix. It makes no sense in the first place, so emit an
492 error for this. */
493 else if (TYPE_ARG_TYPES (t)
494 && TREE_VALUE (TYPE_ARG_TYPES (t)) != void_type_node)
495 error_at (DECL_SOURCE_LOCATION (*node),
496 "interrupt handlers cannot have arguments");
497 return NULL_TREE;
498 }
499
500 value = TREE_VALUE (args);
501
502 if (TREE_CODE (value) != STRING_CST)
503 {
504 warning (OPT_Wattributes,
505 "argument of %qE attribute is not a string constant", name);
506 *no_add_attrs = true;
507 }
508 else if (strcmp (TREE_STRING_POINTER (value), "reset")
509 && strcmp (TREE_STRING_POINTER (value), "software_exception")
510 && strcmp (TREE_STRING_POINTER (value), "page_miss")
511 && strcmp (TREE_STRING_POINTER (value), "timer0")
512 && strcmp (TREE_STRING_POINTER (value), "timer1")
513 && strcmp (TREE_STRING_POINTER (value), "message")
514 && strcmp (TREE_STRING_POINTER (value), "dma0")
515 && strcmp (TREE_STRING_POINTER (value), "dma1")
516 && strcmp (TREE_STRING_POINTER (value), "wand")
517 && strcmp (TREE_STRING_POINTER (value), "swi"))
518 {
519 warning (OPT_Wattributes,
520 "argument of %qE attribute is not %qs, %qs %qs, %qs, %qs, "
521 "%qs, %qs, %qs, %qs or %qs", name,
522 "reset", "software_exception", "page_miss", "timer0", "timer1",
523 "message", "dma0", "dma1", "wand", "swi");
524 *no_add_attrs = true;
525 return NULL_TREE;
526 }
527
528 return epiphany_handle_interrupt_attribute (node, name, TREE_CHAIN (args),
529 flags, no_add_attrs);
530 }
531
532 /* Handle a "forwarder_section" attribute; arguments as in
533 struct attribute_spec.handler. */
534 static tree
535 epiphany_handle_forwarder_attribute (tree *node ATTRIBUTE_UNUSED,
536 tree name, tree args,
537 int flags ATTRIBUTE_UNUSED,
538 bool *no_add_attrs)
539 {
540 tree value;
541
542 value = TREE_VALUE (args);
543
544 if (TREE_CODE (value) != STRING_CST)
545 {
546 warning (OPT_Wattributes,
547 "argument of %qE attribute is not a string constant", name);
548 *no_add_attrs = true;
549 }
550 return NULL_TREE;
551 }
552
553
554 /* Misc. utilities. */
555
556 /* Generate a SYMBOL_REF for the special function NAME. When the address
557 can't be placed directly into a call instruction, and if possible, copy
558 it to a register so that cse / code hoisting is possible. */
559 rtx
560 sfunc_symbol (const char *name)
561 {
562 rtx sym = gen_rtx_SYMBOL_REF (Pmode, name);
563
564 /* These sfuncs should be hidden, and every dso should get a copy. */
565 SYMBOL_REF_FLAGS (sym) = SYMBOL_FLAG_FUNCTION | SYMBOL_FLAG_LOCAL;
566 if (TARGET_SHORT_CALLS)
567 ; /* Nothing to be done. */
568 else if (can_create_pseudo_p ())
569 sym = copy_to_mode_reg (Pmode, sym);
570 else /* We rely on reload to fix this up. */
571 gcc_assert (!reload_in_progress || reload_completed);
572 return sym;
573 }
574
575 /* X and Y are two things to compare using CODE in IN_MODE.
576 Emit the compare insn, construct the proper cc reg in the proper
577 mode, and return the rtx for the cc reg comparison in CMODE. */
578
579 rtx
580 gen_compare_reg (machine_mode cmode, enum rtx_code code,
581 machine_mode in_mode, rtx x, rtx y)
582 {
583 machine_mode mode = SELECT_CC_MODE (code, x, y);
584 rtx cc_reg, pat, clob0, clob1, clob2;
585
586 if (in_mode == VOIDmode)
587 in_mode = GET_MODE (x);
588 if (in_mode == VOIDmode)
589 in_mode = GET_MODE (y);
590
591 if (mode == CC_FPmode)
592 {
593 /* The epiphany has only EQ / NE / LT / LE conditions for
594 hardware floating point. */
595 if (code == GT || code == GE || code == UNLE || code == UNLT)
596 {
597 rtx tmp = x; x = y; y = tmp;
598 code = swap_condition (code);
599 }
600 cc_reg = gen_rtx_REG (mode, CCFP_REGNUM);
601 y = force_reg (in_mode, y);
602 }
603 else
604 {
605 if (mode == CC_FP_GTEmode
606 && (code == LE || code == LT || code == UNGT || code == UNGE))
607 {
608 if (flag_finite_math_only
609 && ((REG_P (x) && REGNO (x) == GPR_0)
610 || (REG_P (y) && REGNO (y) == GPR_1)))
611 switch (code)
612 {
613 case LE: code = UNLE; break;
614 case LT: code = UNLT; break;
615 case UNGT: code = GT; break;
616 case UNGE: code = GE; break;
617 default: gcc_unreachable ();
618 }
619 else
620 {
621 rtx tmp = x; x = y; y = tmp;
622 code = swap_condition (code);
623 }
624 }
625 cc_reg = gen_rtx_REG (mode, CC_REGNUM);
626 }
627 if ((mode == CC_FP_EQmode || mode == CC_FP_GTEmode
628 || mode == CC_FP_ORDmode || mode == CC_FP_UNEQmode)
629 /* mov<mode>cc might want to re-emit a comparison during ifcvt. */
630 && (!REG_P (x) || REGNO (x) != GPR_0
631 || !REG_P (y) || REGNO (y) != GPR_1))
632 {
633 rtx reg;
634
635 #if 0
636 /* ??? We should really do the r0/r1 clobber only during rtl expansion,
637 but just like the flag clobber of movsicc, we have to allow
638 this for ifcvt to work, on the assumption that we'll only want
639 to do this if these registers have been used before by the
640 pre-ifcvt code. */
641 gcc_assert (currently_expanding_to_rtl);
642 #endif
643 reg = gen_rtx_REG (in_mode, GPR_0);
644 if (reg_overlap_mentioned_p (reg, y))
645 return 0;
646 emit_move_insn (reg, x);
647 x = reg;
648 reg = gen_rtx_REG (in_mode, GPR_1);
649 emit_move_insn (reg, y);
650 y = reg;
651 }
652 else
653 x = force_reg (in_mode, x);
654
655 pat = gen_rtx_SET (cc_reg, gen_rtx_COMPARE (mode, x, y));
656 if (mode == CC_FP_EQmode || mode == CC_FP_GTEmode)
657 {
658 const char *name = mode == CC_FP_EQmode ? "__eqsf2" : "__gtesf2";
659 rtx use = gen_rtx_USE (VOIDmode, sfunc_symbol (name));
660
661 clob0 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, GPR_IP));
662 clob1 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, GPR_LR));
663 pat = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (4, pat, use, clob0, clob1));
664 }
665 else if (mode == CC_FP_ORDmode || mode == CC_FP_UNEQmode)
666 {
667 const char *name = mode == CC_FP_ORDmode ? "__ordsf2" : "__uneqsf2";
668 rtx use = gen_rtx_USE (VOIDmode, sfunc_symbol (name));
669
670 clob0 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, GPR_IP));
671 clob1 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, GPR_16));
672 clob2 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, GPR_LR));
673 pat = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (5, pat, use,
674 clob0, clob1, clob2));
675 }
676 else
677 {
678 clob0 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (in_mode));
679 pat = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, pat, clob0));
680 }
681 emit_insn (pat);
682 return gen_rtx_fmt_ee (code, cmode, cc_reg, const0_rtx);
683 }
684
685 /* The ROUND_ADVANCE* macros are local to this file. */
686 /* Round SIZE up to a word boundary. */
687 #define ROUND_ADVANCE(SIZE) \
688 (((SIZE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
689
690 /* Round arg MODE/TYPE up to the next word boundary. */
691 #define ROUND_ADVANCE_ARG(MODE, TYPE) \
692 ((MODE) == BLKmode \
693 ? ROUND_ADVANCE (int_size_in_bytes (TYPE)) \
694 : ROUND_ADVANCE (GET_MODE_SIZE (MODE)))
695
696 /* Round CUM up to the necessary point for argument MODE/TYPE. */
697 #define ROUND_ADVANCE_CUM(CUM, MODE, TYPE) \
698 (epiphany_function_arg_boundary ((MODE), (TYPE)) > BITS_PER_WORD \
699 ? (((CUM) + 1) & ~1) \
700 : (CUM))
701
702 static unsigned int
703 epiphany_function_arg_boundary (machine_mode mode, const_tree type)
704 {
705 if ((type ? TYPE_ALIGN (type) : GET_MODE_BITSIZE (mode)) <= PARM_BOUNDARY)
706 return PARM_BOUNDARY;
707 return 2 * PARM_BOUNDARY;
708 }
709
710 /* Do any needed setup for a variadic function. For the EPIPHANY, we
711 actually emit the code in epiphany_expand_prologue.
712
713 CUM has not been updated for the last named argument (which is given
714 by ARG), and we rely on this fact. */
715
716
717 static void
718 epiphany_setup_incoming_varargs (cumulative_args_t cum,
719 const function_arg_info &arg,
720 int *pretend_size, int no_rtl)
721 {
722 int first_anon_arg;
723 CUMULATIVE_ARGS next_cum;
724 machine_function_t *mf = MACHINE_FUNCTION (cfun);
725
726 /* All BLKmode values are passed by reference. */
727 if (!TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (current_function_decl)))
728 gcc_assert (arg.mode != BLKmode);
729
730 next_cum = *get_cumulative_args (cum);
731 if (!TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (current_function_decl))
732 || arg.type != NULL_TREE)
733 next_cum = (ROUND_ADVANCE_CUM (next_cum, arg.mode, arg.type)
734 + ROUND_ADVANCE_ARG (arg.mode, arg.type));
735 first_anon_arg = next_cum;
736
737 if (first_anon_arg < MAX_EPIPHANY_PARM_REGS && !no_rtl)
738 {
739 /* Note that first_reg_offset < MAX_EPIPHANY_PARM_REGS. */
740 int first_reg_offset = first_anon_arg;
741
742 *pretend_size = ((MAX_EPIPHANY_PARM_REGS - first_reg_offset)
743 * UNITS_PER_WORD);
744 }
745 mf->args_parsed = 1;
746 mf->pretend_args_odd = ((*pretend_size & UNITS_PER_WORD) ? 1 : 0);
747 }
748
749 static int
750 epiphany_arg_partial_bytes (cumulative_args_t cum,
751 const function_arg_info &arg)
752 {
753 int words = 0, rounded_cum;
754
755 gcc_assert (!epiphany_pass_by_reference (cum, arg));
756
757 rounded_cum = ROUND_ADVANCE_CUM (*get_cumulative_args (cum),
758 arg.mode, arg.type);
759 if (rounded_cum < MAX_EPIPHANY_PARM_REGS)
760 {
761 words = MAX_EPIPHANY_PARM_REGS - rounded_cum;
762 if (words >= ROUND_ADVANCE_ARG (arg.mode, arg.type))
763 words = 0;
764 }
765 return words * UNITS_PER_WORD;
766 }
767
768 /* Cost functions. */
769
770 /* Compute a (partial) cost for rtx X. Return true if the complete
771 cost has been computed, and false if subexpressions should be
772 scanned. In either case, *TOTAL contains the cost result. */
773
774 static bool
775 epiphany_rtx_costs (rtx x, machine_mode mode, int outer_code,
776 int opno ATTRIBUTE_UNUSED,
777 int *total, bool speed ATTRIBUTE_UNUSED)
778 {
779 int code = GET_CODE (x);
780
781 switch (code)
782 {
783 /* Small integers in the right context are as cheap as registers. */
784 case CONST_INT:
785 if ((outer_code == PLUS || outer_code == MINUS)
786 && SIMM11 (INTVAL (x)))
787 {
788 *total = 0;
789 return true;
790 }
791 if (IMM16 (INTVAL (x)))
792 {
793 *total = outer_code == SET ? 0 : COSTS_N_INSNS (1);
794 return true;
795 }
796 /* FALLTHRU */
797
798 case CONST:
799 case LABEL_REF:
800 case SYMBOL_REF:
801 *total = COSTS_N_INSNS ((epiphany_small16 (x) ? 0 : 1)
802 + (outer_code == SET ? 0 : 1));
803 return true;
804
805 case CONST_DOUBLE:
806 {
807 rtx high, low;
808 split_double (x, &high, &low);
809 *total = COSTS_N_INSNS (!IMM16 (INTVAL (high))
810 + !IMM16 (INTVAL (low)));
811 return true;
812 }
813
814 case ASHIFT:
815 case ASHIFTRT:
816 case LSHIFTRT:
817 *total = COSTS_N_INSNS (1);
818 return true;
819
820 case COMPARE:
821 switch (mode)
822 {
823 /* There are a number of single-insn combiner patterns that use
824 the flag side effects of arithmetic. */
825 case E_CC_N_NEmode:
826 case E_CC_C_LTUmode:
827 case E_CC_C_GTUmode:
828 return true;
829 default:
830 return false;
831 }
832
833
834 case SET:
835 {
836 rtx src = SET_SRC (x);
837 if (BINARY_P (src))
838 *total = 0;
839 return false;
840 }
841
842 default:
843 return false;
844 }
845 }
846
847
848 /* Provide the costs of an addressing mode that contains ADDR.
849 If ADDR is not a valid address, its cost is irrelevant. */
850
851 static int
852 epiphany_address_cost (rtx addr, machine_mode mode,
853 addr_space_t as ATTRIBUTE_UNUSED, bool speed)
854 {
855 rtx reg;
856 rtx off = const0_rtx;
857 int i;
858
859 if (speed)
860 return 0;
861 /* Return 0 for addresses valid in short insns, 1 for addresses only valid
862 in long insns. */
863 switch (GET_CODE (addr))
864 {
865 case PLUS :
866 reg = XEXP (addr, 0);
867 off = XEXP (addr, 1);
868 break;
869 case POST_MODIFY:
870 reg = XEXP (addr, 0);
871 off = XEXP (addr, 1);
872 gcc_assert (GET_CODE (off) == PLUS && rtx_equal_p (reg, XEXP (off, 0)));
873 off = XEXP (off, 1);
874 if (satisfies_constraint_Rgs (reg) && satisfies_constraint_Rgs (off))
875 return 0;
876 return 1;
877 case REG:
878 default:
879 reg = addr;
880 break;
881 }
882 if (!satisfies_constraint_Rgs (reg))
883 return 1;
884 /* The offset range available for short instructions depends on the mode
885 of the memory access. */
886 /* First, make sure we have a valid integer. */
887 if (!satisfies_constraint_L (off))
888 return 1;
889 i = INTVAL (off);
890 switch (GET_MODE_SIZE (mode))
891 {
892 default:
893 case 4:
894 if (i & 1)
895 return 1;
896 i >>= 1;
897 /* Fall through. */
898 case 2:
899 if (i & 1)
900 return 1;
901 i >>= 1;
902 /* Fall through. */
903 case 1:
904 return i < -7 || i > 7;
905 }
906 }
907
908 /* Compute the cost of moving data between registers and memory.
909 For integer, load latency is twice as long as register-register moves,
910 but issue pich is the same. For floating point, load latency is three
911 times as much as a reg-reg move. */
912 static int
913 epiphany_memory_move_cost (machine_mode mode,
914 reg_class_t rclass ATTRIBUTE_UNUSED,
915 bool in ATTRIBUTE_UNUSED)
916 {
917 return GET_MODE_CLASS (mode) == MODE_INT ? 3 : 4;
918 }
919
920 /* Function prologue/epilogue handlers. */
921
922 /* EPIPHANY stack frames look like:
923
924 Before call After call
925 +-----------------------+ +-----------------------+
926 | | | |
927 high | local variables, | | local variables, |
928 mem | reg save area, etc. | | reg save area, etc. |
929 | | | |
930 +-----------------------+ +-----------------------+
931 | | | |
932 | arguments on stack. | | arguments on stack. |
933 | | | |
934 SP+8->+-----------------------+FP+8m->+-----------------------+
935 | 2 word save area for | | reg parm save area, |
936 | leaf funcs / flags | | only created for |
937 SP+0->+-----------------------+ | variable argument |
938 | functions |
939 FP+8n->+-----------------------+
940 | |
941 | register save area |
942 | |
943 +-----------------------+
944 | |
945 | local variables |
946 | |
947 FP+0->+-----------------------+
948 | |
949 | alloca allocations |
950 | |
951 +-----------------------+
952 | |
953 | arguments on stack |
954 | |
955 SP+8->+-----------------------+
956 low | 2 word save area for |
957 memory | leaf funcs / flags |
958 SP+0->+-----------------------+
959
960 Notes:
961 1) The "reg parm save area" does not exist for non variable argument fns.
962 The "reg parm save area" could be eliminated if we created our
963 own TARGET_GIMPLIFY_VA_ARG_EXPR, but that has tradeoffs as well
964 (so it's not done). */
965
966 /* Structure to be filled in by epiphany_compute_frame_size with register
967 save masks, and offsets for the current function. */
968 struct epiphany_frame_info
969 {
970 unsigned int total_size; /* # bytes that the entire frame takes up. */
971 unsigned int pretend_size; /* # bytes we push and pretend caller did. */
972 unsigned int args_size; /* # bytes that outgoing arguments take up. */
973 unsigned int reg_size; /* # bytes needed to store regs. */
974 unsigned int var_size; /* # bytes that variables take up. */
975 HARD_REG_SET gmask; /* Set of saved gp registers. */
976 int initialized; /* Nonzero if frame size already calculated. */
977 int stld_sz; /* Current load/store data size for offset
978 adjustment. */
979 int need_fp; /* value to override "frame_pointer_needed */
980 /* FIRST_SLOT is the slot that is saved first, at the very start of
981 the frame, with a POST_MODIFY to allocate the frame, if the size fits,
982 or at least the parm and register save areas, otherwise.
983 In the case of a large frame, LAST_SLOT is the slot that is saved last,
984 with a POST_MODIFY to allocate the rest of the frame. */
985 int first_slot, last_slot, first_slot_offset, last_slot_offset;
986 int first_slot_size;
987 int small_threshold;
988 };
989
990 /* Current frame information calculated by epiphany_compute_frame_size. */
991 static struct epiphany_frame_info current_frame_info;
992
993 /* Zero structure to initialize current_frame_info. */
994 static struct epiphany_frame_info zero_frame_info;
995
996 /* The usual; we set up our machine_function data. */
997 static struct machine_function *
998 epiphany_init_machine_status (void)
999 {
1000 struct machine_function *machine;
1001
1002 /* Reset state info for each function. */
1003 current_frame_info = zero_frame_info;
1004
1005 machine = ggc_cleared_alloc<machine_function_t> ();
1006
1007 return machine;
1008 }
1009
1010 /* Implements INIT_EXPANDERS. We just set up to call the above
1011 * function. */
1012 void
1013 epiphany_init_expanders (void)
1014 {
1015 init_machine_status = epiphany_init_machine_status;
1016 }
1017
1018 /* Type of function DECL.
1019
1020 The result is cached. To reset the cache at the end of a function,
1021 call with DECL = NULL_TREE. */
1022
1023 static enum epiphany_function_type
1024 epiphany_compute_function_type (tree decl)
1025 {
1026 tree a;
1027 /* Cached value. */
1028 static enum epiphany_function_type fn_type = EPIPHANY_FUNCTION_UNKNOWN;
1029 /* Last function we were called for. */
1030 static tree last_fn = NULL_TREE;
1031
1032 /* Resetting the cached value? */
1033 if (decl == NULL_TREE)
1034 {
1035 fn_type = EPIPHANY_FUNCTION_UNKNOWN;
1036 last_fn = NULL_TREE;
1037 return fn_type;
1038 }
1039
1040 if (decl == last_fn && fn_type != EPIPHANY_FUNCTION_UNKNOWN)
1041 return fn_type;
1042
1043 /* Assume we have a normal function (not an interrupt handler). */
1044 fn_type = EPIPHANY_FUNCTION_NORMAL;
1045
1046 /* Now see if this is an interrupt handler. */
1047 for (a = DECL_ATTRIBUTES (decl);
1048 a;
1049 a = TREE_CHAIN (a))
1050 {
1051 tree name = TREE_PURPOSE (a);
1052
1053 if (name == get_identifier ("interrupt"))
1054 fn_type = EPIPHANY_FUNCTION_INTERRUPT;
1055 }
1056
1057 last_fn = decl;
1058 return fn_type;
1059 }
1060
1061 #define RETURN_ADDR_REGNUM GPR_LR
1062 #define FRAME_POINTER_MASK (1 << (FRAME_POINTER_REGNUM))
1063 #define RETURN_ADDR_MASK (1 << (RETURN_ADDR_REGNUM))
1064
1065 /* Tell prologue and epilogue if register REGNO should be saved / restored.
1066 The return address and frame pointer are treated separately.
1067 Don't consider them here. */
1068 #define MUST_SAVE_REGISTER(regno, interrupt_p) \
1069 ((df_regs_ever_live_p (regno) \
1070 || (interrupt_p && !crtl->is_leaf \
1071 && call_used_or_fixed_reg_p (regno) && !fixed_regs[regno])) \
1072 && (!call_used_or_fixed_reg_p (regno) || regno == GPR_LR \
1073 || (interrupt_p && regno != GPR_SP)))
1074
1075 #define MUST_SAVE_RETURN_ADDR 0
1076
1077 /* Return the bytes needed to compute the frame pointer from the current
1078 stack pointer.
1079
1080 SIZE is the size needed for local variables. */
1081
1082 static unsigned int
1083 epiphany_compute_frame_size (int size /* # of var. bytes allocated. */)
1084 {
1085 int regno;
1086 unsigned int total_size, var_size, args_size, pretend_size, reg_size;
1087 HARD_REG_SET gmask;
1088 enum epiphany_function_type fn_type;
1089 int interrupt_p;
1090 int first_slot, last_slot, first_slot_offset, last_slot_offset;
1091 int first_slot_size;
1092 int small_slots = 0;
1093
1094 var_size = size;
1095 args_size = crtl->outgoing_args_size;
1096 pretend_size = crtl->args.pretend_args_size;
1097 total_size = args_size + var_size;
1098 reg_size = 0;
1099 CLEAR_HARD_REG_SET (gmask);
1100 first_slot = -1;
1101 first_slot_offset = 0;
1102 last_slot = -1;
1103 last_slot_offset = 0;
1104 first_slot_size = UNITS_PER_WORD;
1105
1106 /* See if this is an interrupt handler. Call used registers must be saved
1107 for them too. */
1108 fn_type = epiphany_compute_function_type (current_function_decl);
1109 interrupt_p = EPIPHANY_INTERRUPT_P (fn_type);
1110
1111 /* Calculate space needed for registers. */
1112
1113 for (regno = MAX_EPIPHANY_PARM_REGS - 1; pretend_size > reg_size; regno--)
1114 {
1115 reg_size += UNITS_PER_WORD;
1116 SET_HARD_REG_BIT (gmask, regno);
1117 if (epiphany_stack_offset - reg_size == 0)
1118 first_slot = regno;
1119 }
1120
1121 if (interrupt_p)
1122 reg_size += 2 * UNITS_PER_WORD;
1123 else
1124 small_slots = epiphany_stack_offset / UNITS_PER_WORD;
1125
1126 if (frame_pointer_needed)
1127 {
1128 current_frame_info.need_fp = 1;
1129 if (!interrupt_p && first_slot < 0)
1130 first_slot = GPR_FP;
1131 }
1132 else
1133 current_frame_info.need_fp = 0;
1134 for (regno = 0; regno <= GPR_LAST; regno++)
1135 {
1136 if (MUST_SAVE_REGISTER (regno, interrupt_p))
1137 {
1138 gcc_assert (!TEST_HARD_REG_BIT (gmask, regno));
1139 reg_size += UNITS_PER_WORD;
1140 SET_HARD_REG_BIT (gmask, regno);
1141 /* FIXME: when optimizing for speed, take schedling into account
1142 when selecting these registers. */
1143 if (regno == first_slot)
1144 gcc_assert (regno == GPR_FP && frame_pointer_needed);
1145 else if (!interrupt_p && first_slot < 0)
1146 first_slot = regno;
1147 else if (last_slot < 0
1148 && (first_slot ^ regno) != 1
1149 && (!interrupt_p || regno > GPR_1))
1150 last_slot = regno;
1151 }
1152 }
1153 if (TEST_HARD_REG_BIT (gmask, GPR_LR))
1154 MACHINE_FUNCTION (cfun)->lr_clobbered = 1;
1155 /* ??? Could sometimes do better than that. */
1156 current_frame_info.small_threshold
1157 = (optimize >= 3 || interrupt_p ? 0
1158 : pretend_size ? small_slots
1159 : 4 + small_slots - (first_slot == GPR_FP));
1160
1161 /* If there might be variables with 64-bit alignment requirement, align the
1162 start of the variables. */
1163 if (var_size >= 2 * UNITS_PER_WORD
1164 /* We don't want to split a double reg save/restore across two unpaired
1165 stack slots when optimizing. This rounding could be avoided with
1166 more complex reordering of the register saves, but that would seem
1167 to be a lot of code complexity for little gain. */
1168 || (reg_size > 8 && optimize))
1169 reg_size = EPIPHANY_STACK_ALIGN (reg_size);
1170 if (((total_size + reg_size
1171 /* Reserve space for UNKNOWN_REGNUM. */
1172 + EPIPHANY_STACK_ALIGN (4))
1173 <= (unsigned) epiphany_stack_offset)
1174 && !interrupt_p
1175 && crtl->is_leaf && !frame_pointer_needed)
1176 {
1177 first_slot = -1;
1178 last_slot = -1;
1179 goto alloc_done;
1180 }
1181 else if (reg_size
1182 && !interrupt_p
1183 && reg_size < (unsigned HOST_WIDE_INT) epiphany_stack_offset)
1184 reg_size = epiphany_stack_offset;
1185 if (interrupt_p)
1186 {
1187 if (total_size + reg_size < 0x3fc)
1188 {
1189 first_slot_offset = EPIPHANY_STACK_ALIGN (total_size + reg_size);
1190 first_slot_offset += EPIPHANY_STACK_ALIGN (epiphany_stack_offset);
1191 last_slot = -1;
1192 }
1193 else
1194 {
1195 first_slot_offset = EPIPHANY_STACK_ALIGN (reg_size);
1196 last_slot_offset = EPIPHANY_STACK_ALIGN (total_size);
1197 last_slot_offset += EPIPHANY_STACK_ALIGN (epiphany_stack_offset);
1198 if (last_slot >= 0)
1199 CLEAR_HARD_REG_BIT (gmask, last_slot);
1200 }
1201 }
1202 else if (total_size + reg_size < 0x1ffc && first_slot >= 0)
1203 {
1204 first_slot_offset = EPIPHANY_STACK_ALIGN (total_size + reg_size);
1205 last_slot = -1;
1206 }
1207 else
1208 {
1209 if (total_size + reg_size <= (unsigned) epiphany_stack_offset)
1210 {
1211 gcc_assert (first_slot < 0);
1212 gcc_assert (reg_size == 0 || (int) reg_size == epiphany_stack_offset);
1213 last_slot_offset = EPIPHANY_STACK_ALIGN (total_size + reg_size);
1214 }
1215 else
1216 {
1217 first_slot_offset
1218 = (reg_size
1219 ? EPIPHANY_STACK_ALIGN (reg_size - epiphany_stack_offset) : 0);
1220 if (!first_slot_offset)
1221 {
1222 if (first_slot != GPR_FP || !current_frame_info.need_fp)
1223 last_slot = first_slot;
1224 first_slot = -1;
1225 }
1226 last_slot_offset = EPIPHANY_STACK_ALIGN (total_size);
1227 if (reg_size)
1228 last_slot_offset += EPIPHANY_STACK_ALIGN (epiphany_stack_offset);
1229 }
1230 if (last_slot >= 0)
1231 CLEAR_HARD_REG_BIT (gmask, last_slot);
1232 }
1233 alloc_done:
1234 if (first_slot >= 0)
1235 {
1236 CLEAR_HARD_REG_BIT (gmask, first_slot);
1237 if (TEST_HARD_REG_BIT (gmask, first_slot ^ 1)
1238 && epiphany_stack_offset - pretend_size >= 2 * UNITS_PER_WORD)
1239 {
1240 CLEAR_HARD_REG_BIT (gmask, first_slot ^ 1);
1241 first_slot_size = 2 * UNITS_PER_WORD;
1242 first_slot &= ~1;
1243 }
1244 }
1245 total_size = first_slot_offset + last_slot_offset;
1246
1247 /* Save computed information. */
1248 current_frame_info.total_size = total_size;
1249 current_frame_info.pretend_size = pretend_size;
1250 current_frame_info.var_size = var_size;
1251 current_frame_info.args_size = args_size;
1252 current_frame_info.reg_size = reg_size;
1253 current_frame_info.gmask = gmask;
1254 current_frame_info.first_slot = first_slot;
1255 current_frame_info.last_slot = last_slot;
1256 current_frame_info.first_slot_offset = first_slot_offset;
1257 current_frame_info.first_slot_size = first_slot_size;
1258 current_frame_info.last_slot_offset = last_slot_offset;
1259
1260 current_frame_info.initialized = reload_completed;
1261
1262 /* Ok, we're done. */
1263 return total_size;
1264 }
1265
1266 /* Print operand X (an rtx) in assembler syntax to file FILE.
1267 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
1268 For `%' followed by punctuation, CODE is the punctuation and X is null. */
1269
1270 static void
1271 epiphany_print_operand (FILE *file, rtx x, int code)
1272 {
1273 switch (code)
1274 {
1275 case 'd':
1276 fputs (epiphany_condition_codes[get_epiphany_condition_code (x)], file);
1277 return;
1278 case 'D':
1279 fputs (epiphany_condition_codes[EPIPHANY_INVERSE_CONDITION_CODE
1280 (get_epiphany_condition_code (x))],
1281 file);
1282 return;
1283
1284 case 'X':
1285 current_frame_info.stld_sz = 8;
1286 break;
1287
1288 case 'C' :
1289 current_frame_info.stld_sz = 4;
1290 break;
1291
1292 case 'c' :
1293 current_frame_info.stld_sz = 2;
1294 break;
1295
1296 case 'f':
1297 fputs (REG_P (x) ? "jalr " : "bl ", file);
1298 break;
1299
1300 case '-':
1301 fprintf (file, "r%d", epiphany_m1reg);
1302 return;
1303
1304 case 0 :
1305 /* Do nothing special. */
1306 break;
1307 default :
1308 /* Unknown flag. */
1309 output_operand_lossage ("invalid operand output code");
1310 }
1311
1312 switch (GET_CODE (x))
1313 {
1314 rtx addr;
1315 rtx offset;
1316
1317 case REG :
1318 fputs (reg_names[REGNO (x)], file);
1319 break;
1320 case MEM :
1321 if (code == 0)
1322 current_frame_info.stld_sz = 1;
1323 fputc ('[', file);
1324 addr = XEXP (x, 0);
1325 switch (GET_CODE (addr))
1326 {
1327 case POST_INC:
1328 offset = GEN_INT (GET_MODE_SIZE (GET_MODE (x)));
1329 addr = XEXP (addr, 0);
1330 break;
1331 case POST_DEC:
1332 offset = GEN_INT (-GET_MODE_SIZE (GET_MODE (x)));
1333 addr = XEXP (addr, 0);
1334 break;
1335 case POST_MODIFY:
1336 offset = XEXP (XEXP (addr, 1), 1);
1337 addr = XEXP (addr, 0);
1338 break;
1339 default:
1340 offset = 0;
1341 break;
1342 }
1343 output_address (GET_MODE (x), addr);
1344 fputc (']', file);
1345 if (offset)
1346 {
1347 fputc (',', file);
1348 if (CONST_INT_P (offset)) switch (GET_MODE_SIZE (GET_MODE (x)))
1349 {
1350 default:
1351 gcc_unreachable ();
1352 case 8:
1353 offset = GEN_INT (INTVAL (offset) >> 3);
1354 break;
1355 case 4:
1356 offset = GEN_INT (INTVAL (offset) >> 2);
1357 break;
1358 case 2:
1359 offset = GEN_INT (INTVAL (offset) >> 1);
1360 break;
1361 case 1:
1362 break;
1363 }
1364 output_address (GET_MODE (x), offset);
1365 }
1366 break;
1367 case CONST_DOUBLE :
1368 /* We handle SFmode constants here as output_addr_const doesn't. */
1369 if (GET_MODE (x) == SFmode)
1370 {
1371 long l;
1372
1373 REAL_VALUE_TO_TARGET_SINGLE (*CONST_DOUBLE_REAL_VALUE (x), l);
1374 fprintf (file, "%s0x%08lx", IMMEDIATE_PREFIX, l);
1375 break;
1376 }
1377 /* FALLTHRU */
1378 /* Let output_addr_const deal with it. */
1379 case CONST_INT:
1380 fprintf(file,"%s",IMMEDIATE_PREFIX);
1381 if (code == 'C' || code == 'X')
1382 {
1383 fprintf (file, "%ld",
1384 (long) (INTVAL (x) / current_frame_info.stld_sz));
1385 break;
1386 }
1387 /* Fall through */
1388 default :
1389 output_addr_const (file, x);
1390 break;
1391 }
1392 }
1393
1394 /* Print a memory address as an operand to reference that memory location. */
1395
1396 static void
1397 epiphany_print_operand_address (FILE *file, machine_mode /*mode*/, rtx addr)
1398 {
1399 rtx base, index = 0;
1400 int offset = 0;
1401
1402 switch (GET_CODE (addr))
1403 {
1404 case REG :
1405 fputs (reg_names[REGNO (addr)], file);
1406 break;
1407 case SYMBOL_REF :
1408 if (/*???*/ 0 && SYMBOL_REF_FUNCTION_P (addr))
1409 {
1410 output_addr_const (file, addr);
1411 }
1412 else
1413 {
1414 output_addr_const (file, addr);
1415 }
1416 break;
1417 case PLUS :
1418 if (GET_CODE (XEXP (addr, 0)) == CONST_INT)
1419 offset = INTVAL (XEXP (addr, 0)), base = XEXP (addr, 1);
1420 else if (GET_CODE (XEXP (addr, 1)) == CONST_INT)
1421 offset = INTVAL (XEXP (addr, 1)), base = XEXP (addr, 0);
1422 else
1423 base = XEXP (addr, 0), index = XEXP (addr, 1);
1424 gcc_assert (GET_CODE (base) == REG);
1425 fputs (reg_names[REGNO (base)], file);
1426 if (index == 0)
1427 {
1428 /*
1429 ** ++rk quirky method to scale offset for ld/str.......
1430 */
1431 fprintf (file, ",%s%d", IMMEDIATE_PREFIX,
1432 offset/current_frame_info.stld_sz);
1433 }
1434 else
1435 {
1436 switch (GET_CODE (index))
1437 {
1438 case REG:
1439 fprintf (file, ",%s", reg_names[REGNO (index)]);
1440 break;
1441 case SYMBOL_REF:
1442 fputc (',', file), output_addr_const (file, index);
1443 break;
1444 default:
1445 gcc_unreachable ();
1446 }
1447 }
1448 break;
1449 case PRE_INC: case PRE_DEC: case POST_INC: case POST_DEC: case POST_MODIFY:
1450 /* We shouldn't get here as we've lost the mode of the memory object
1451 (which says how much to inc/dec by.
1452 FIXME: We have the mode now, address printing can be moved into this
1453 function. */
1454 gcc_unreachable ();
1455 break;
1456 default:
1457 output_addr_const (file, addr);
1458 break;
1459 }
1460 }
1461
1462 void
1463 epiphany_final_prescan_insn (rtx_insn *insn ATTRIBUTE_UNUSED,
1464 rtx *opvec ATTRIBUTE_UNUSED,
1465 int noperands ATTRIBUTE_UNUSED)
1466 {
1467 int i = epiphany_n_nops;
1468 rtx pat ATTRIBUTE_UNUSED;
1469
1470 while (i--)
1471 fputs ("\tnop\n", asm_out_file);
1472 }
1473
1474
1475 /* Worker function for TARGET_RETURN_IN_MEMORY. */
1476
1477 static bool
1478 epiphany_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
1479 {
1480 HOST_WIDE_INT size = int_size_in_bytes (type);
1481
1482 if (AGGREGATE_TYPE_P (type)
1483 && (TYPE_MODE (type) == BLKmode || TYPE_NEEDS_CONSTRUCTING (type)))
1484 return true;
1485 return (size == -1 || size > 8);
1486 }
1487
1488 /* For EPIPHANY, All aggregates and arguments greater than 8 bytes are
1489 passed by reference. */
1490
1491 static bool
1492 epiphany_pass_by_reference (cumulative_args_t, const function_arg_info &arg)
1493 {
1494 if (tree type = arg.type)
1495 {
1496 if (AGGREGATE_TYPE_P (type)
1497 && (arg.mode == BLKmode || TYPE_NEEDS_CONSTRUCTING (type)))
1498 return true;
1499 }
1500 return false;
1501 }
1502
1503
1504 static rtx
1505 epiphany_function_value (const_tree ret_type,
1506 const_tree fn_decl_or_type ATTRIBUTE_UNUSED,
1507 bool outgoing ATTRIBUTE_UNUSED)
1508 {
1509 machine_mode mode;
1510
1511 mode = TYPE_MODE (ret_type);
1512 /* We must change the mode like PROMOTE_MODE does.
1513 ??? PROMOTE_MODE is ignored for non-scalar types.
1514 The set of types tested here has to be kept in sync
1515 with the one in explow.cc:promote_mode. */
1516 if (GET_MODE_CLASS (mode) == MODE_INT
1517 && GET_MODE_SIZE (mode) < 4
1518 && (TREE_CODE (ret_type) == INTEGER_TYPE
1519 || TREE_CODE (ret_type) == ENUMERAL_TYPE
1520 || TREE_CODE (ret_type) == BOOLEAN_TYPE
1521 || TREE_CODE (ret_type) == OFFSET_TYPE))
1522 mode = SImode;
1523 return gen_rtx_REG (mode, 0);
1524 }
1525
1526 static rtx
1527 epiphany_libcall_value (machine_mode mode, const_rtx fun ATTRIBUTE_UNUSED)
1528 {
1529 return gen_rtx_REG (mode, 0);
1530 }
1531
1532 static bool
1533 epiphany_function_value_regno_p (const unsigned int regno ATTRIBUTE_UNUSED)
1534 {
1535 return regno == 0;
1536 }
1537
1538 /* Fix up invalid option settings. */
1539 static void
1540 epiphany_override_options (void)
1541 {
1542 if (epiphany_stack_offset < 4)
1543 error ("%<stack_offset%> must be at least 4");
1544 if (epiphany_stack_offset & 3)
1545 error ("%<stack_offset%> must be a multiple of 4");
1546 epiphany_stack_offset = (epiphany_stack_offset + 3) & -4;
1547 if (!TARGET_SOFT_CMPSF)
1548 flag_finite_math_only = 1;
1549
1550 /* This needs to be done at start up. It's convenient to do it here. */
1551 epiphany_init ();
1552 }
1553
1554 /* For a DImode load / store SET, make a SImode set for a
1555 REG_FRAME_RELATED_EXPR note, using OFFSET to create a high or lowpart
1556 subreg. */
1557 static rtx
1558 frame_subreg_note (rtx set, int offset)
1559 {
1560 rtx src = simplify_gen_subreg (SImode, SET_SRC (set), DImode, offset);
1561 rtx dst = simplify_gen_subreg (SImode, SET_DEST (set), DImode, offset);
1562
1563 set = gen_rtx_SET (dst ,src);
1564 RTX_FRAME_RELATED_P (set) = 1;
1565 return set;
1566 }
1567
1568 static rtx_insn *
1569 frame_insn (rtx x)
1570 {
1571 int i;
1572 rtx note = NULL_RTX;
1573 rtx_insn *insn;
1574
1575 if (GET_CODE (x) == PARALLEL)
1576 {
1577 rtx part = XVECEXP (x, 0, 0);
1578
1579 if (GET_MODE (SET_DEST (part)) == DImode)
1580 {
1581 note = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (XVECLEN (x, 0) + 1));
1582 XVECEXP (note, 0, 0) = frame_subreg_note (part, 0);
1583 XVECEXP (note, 0, 1) = frame_subreg_note (part, UNITS_PER_WORD);
1584 for (i = XVECLEN (x, 0) - 1; i >= 1; i--)
1585 {
1586 part = copy_rtx (XVECEXP (x, 0, i));
1587
1588 if (GET_CODE (part) == SET)
1589 RTX_FRAME_RELATED_P (part) = 1;
1590 XVECEXP (note, 0, i + 1) = part;
1591 }
1592 }
1593 else
1594 {
1595 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
1596 {
1597 part = XVECEXP (x, 0, i);
1598
1599 if (GET_CODE (part) == SET)
1600 RTX_FRAME_RELATED_P (part) = 1;
1601 }
1602 }
1603 }
1604 else if (GET_CODE (x) == SET && GET_MODE (SET_DEST (x)) == DImode)
1605 note = gen_rtx_PARALLEL (VOIDmode,
1606 gen_rtvec (2, frame_subreg_note (x, 0),
1607 frame_subreg_note (x, UNITS_PER_WORD)));
1608 insn = emit_insn (x);
1609 RTX_FRAME_RELATED_P (insn) = 1;
1610 if (note)
1611 add_reg_note (insn, REG_FRAME_RELATED_EXPR, note);
1612 return insn;
1613 }
1614
1615 static rtx_insn *
1616 frame_move_insn (rtx to, rtx from)
1617 {
1618 return frame_insn (gen_rtx_SET (to, from));
1619 }
1620
1621 /* Generate a MEM referring to a varargs argument slot. */
1622
1623 static rtx
1624 gen_varargs_mem (machine_mode mode, rtx addr)
1625 {
1626 rtx mem = gen_rtx_MEM (mode, addr);
1627 MEM_NOTRAP_P (mem) = 1;
1628 set_mem_alias_set (mem, get_varargs_alias_set ());
1629 return mem;
1630 }
1631
1632 /* Emit instructions to save or restore registers in the range [MIN..LIMIT) .
1633 If EPILOGUE_P is 0, save; if it is one, restore.
1634 ADDR is the stack slot to save the first register to; subsequent
1635 registers are written to lower addresses.
1636 However, the order of register pairs can be reversed in order to
1637 use double-word load-store instructions. Likewise, an unpaired single
1638 word save slot can be skipped while double saves are carried out, and
1639 reused when a single register is to be saved. */
1640
1641 static void
1642 epiphany_emit_save_restore (int min, int limit, rtx addr, int epilogue_p)
1643 {
1644 int i;
1645 int stack_offset
1646 = current_frame_info.first_slot >= 0 ? epiphany_stack_offset : 0;
1647 rtx skipped_mem = NULL_RTX;
1648 int last_saved = limit - 1;
1649
1650 if (!optimize)
1651 while (last_saved >= 0
1652 && !TEST_HARD_REG_BIT (current_frame_info.gmask, last_saved))
1653 last_saved--;
1654 for (i = 0; i < limit; i++)
1655 {
1656 machine_mode mode = word_mode;
1657 rtx mem, reg;
1658 int n = i;
1659 rtx (*gen_mem) (machine_mode, rtx) = gen_frame_mem;
1660
1661 /* Make sure we push the arguments in the right order. */
1662 if (n < MAX_EPIPHANY_PARM_REGS && crtl->args.pretend_args_size)
1663 {
1664 n = MAX_EPIPHANY_PARM_REGS - 1 - n;
1665 gen_mem = gen_varargs_mem;
1666 }
1667 if (stack_offset == current_frame_info.first_slot_size
1668 && current_frame_info.first_slot >= 0)
1669 {
1670 if (current_frame_info.first_slot_size > UNITS_PER_WORD)
1671 {
1672 mode = DImode;
1673 addr = plus_constant (Pmode, addr,
1674 - (HOST_WIDE_INT) UNITS_PER_WORD);
1675 }
1676 if (i-- < min || !epilogue_p)
1677 goto next_slot;
1678 n = current_frame_info.first_slot;
1679 gen_mem = gen_frame_mem;
1680 }
1681 else if (n == UNKNOWN_REGNUM
1682 && stack_offset > current_frame_info.first_slot_size)
1683 {
1684 i--;
1685 goto next_slot;
1686 }
1687 else if (!TEST_HARD_REG_BIT (current_frame_info.gmask, n))
1688 continue;
1689 else if (i < min)
1690 goto next_slot;
1691
1692 /* Check for a register pair to save. */
1693 if (n == i
1694 && (n >= MAX_EPIPHANY_PARM_REGS || crtl->args.pretend_args_size == 0)
1695 && (n & 1) == 0 && n+1 < limit
1696 && TEST_HARD_REG_BIT (current_frame_info.gmask, n+1))
1697 {
1698 /* If it fits in the current stack slot pair, place it there. */
1699 if (GET_CODE (addr) == PLUS && (stack_offset & 7) == 0
1700 && stack_offset != 2 * UNITS_PER_WORD
1701 && (current_frame_info.last_slot < 0
1702 || INTVAL (XEXP (addr, 1)) != UNITS_PER_WORD)
1703 && (n+1 != last_saved || !skipped_mem))
1704 {
1705 mode = DImode;
1706 i++;
1707 addr = plus_constant (Pmode, addr,
1708 - (HOST_WIDE_INT) UNITS_PER_WORD);
1709 }
1710 /* If it fits in the following stack slot pair, that's fine, too. */
1711 else if (GET_CODE (addr) == PLUS && (stack_offset & 7) == 4
1712 && stack_offset != 2 * UNITS_PER_WORD
1713 && stack_offset != 3 * UNITS_PER_WORD
1714 && (current_frame_info.last_slot < 0
1715 || INTVAL (XEXP (addr, 1)) != 2 * UNITS_PER_WORD)
1716 && n + 1 != last_saved)
1717 {
1718 gcc_assert (!skipped_mem);
1719 stack_offset -= GET_MODE_SIZE (mode);
1720 skipped_mem = gen_mem (mode, addr);
1721 mode = DImode;
1722 i++;
1723 addr = plus_constant (Pmode, addr,
1724 - (HOST_WIDE_INT) 2 * UNITS_PER_WORD);
1725 }
1726 }
1727 reg = gen_rtx_REG (mode, n);
1728 if (mode != DImode && skipped_mem)
1729 mem = skipped_mem;
1730 else
1731 mem = gen_mem (mode, addr);
1732
1733 /* If we are loading / storing LR, note the offset that
1734 gen_reload_insi_ra requires. Since GPR_LR is even,
1735 we only need to test n, even if mode is DImode. */
1736 gcc_assert ((GPR_LR & 1) == 0);
1737 if (n == GPR_LR)
1738 {
1739 long lr_slot_offset = 0;
1740 rtx m_addr = XEXP (mem, 0);
1741
1742 if (GET_CODE (m_addr) == PLUS)
1743 lr_slot_offset = INTVAL (XEXP (m_addr, 1));
1744 if (frame_pointer_needed)
1745 lr_slot_offset += (current_frame_info.first_slot_offset
1746 - current_frame_info.total_size);
1747 if (MACHINE_FUNCTION (cfun)->lr_slot_known)
1748 gcc_assert (MACHINE_FUNCTION (cfun)->lr_slot_offset
1749 == lr_slot_offset);
1750 MACHINE_FUNCTION (cfun)->lr_slot_offset = lr_slot_offset;
1751 MACHINE_FUNCTION (cfun)->lr_slot_known = 1;
1752 }
1753
1754 if (!epilogue_p)
1755 frame_move_insn (mem, reg);
1756 else if (n >= MAX_EPIPHANY_PARM_REGS || !crtl->args.pretend_args_size)
1757 emit_move_insn (reg, mem);
1758 if (mem == skipped_mem)
1759 {
1760 skipped_mem = NULL_RTX;
1761 continue;
1762 }
1763 next_slot:
1764 addr = plus_constant (Pmode, addr, -(HOST_WIDE_INT) UNITS_PER_WORD);
1765 stack_offset -= GET_MODE_SIZE (mode);
1766 }
1767 }
1768
1769 void
1770 epiphany_expand_prologue (void)
1771 {
1772 int interrupt_p;
1773 enum epiphany_function_type fn_type;
1774 rtx addr, mem, off, reg;
1775
1776 if (!current_frame_info.initialized)
1777 epiphany_compute_frame_size (get_frame_size ());
1778
1779 /* It is debatable if we should adjust this by epiphany_stack_offset. */
1780 if (flag_stack_usage_info)
1781 current_function_static_stack_size = current_frame_info.total_size;
1782
1783 fn_type = epiphany_compute_function_type (current_function_decl);
1784 interrupt_p = EPIPHANY_INTERRUPT_P (fn_type);
1785
1786 if (interrupt_p)
1787 {
1788 addr = plus_constant (Pmode, stack_pointer_rtx,
1789 - (HOST_WIDE_INT) 2 * UNITS_PER_WORD);
1790 if (!lookup_attribute ("forwarder_section",
1791 DECL_ATTRIBUTES (current_function_decl))
1792 || !epiphany_is_long_call_p (XEXP (DECL_RTL (current_function_decl),
1793 0)))
1794 frame_move_insn (gen_frame_mem (DImode, addr),
1795 gen_rtx_REG (DImode, GPR_0));
1796 frame_move_insn (gen_rtx_REG (SImode, GPR_0),
1797 gen_rtx_REG (word_mode, STATUS_REGNUM));
1798 frame_move_insn (gen_rtx_REG (SImode, GPR_1),
1799 gen_rtx_REG (word_mode, IRET_REGNUM));
1800 mem = gen_frame_mem (BLKmode, stack_pointer_rtx);
1801 off = GEN_INT (-current_frame_info.first_slot_offset);
1802 frame_insn (gen_stack_adjust_add (off, mem));
1803 if (!epiphany_uninterruptible_p (current_function_decl))
1804 emit_insn (gen_gie ());
1805 addr = plus_constant (Pmode, stack_pointer_rtx,
1806 current_frame_info.first_slot_offset
1807 - (HOST_WIDE_INT) 3 * UNITS_PER_WORD);
1808 }
1809 else
1810 {
1811 addr = plus_constant (Pmode, stack_pointer_rtx,
1812 epiphany_stack_offset
1813 - (HOST_WIDE_INT) UNITS_PER_WORD);
1814 epiphany_emit_save_restore (0, current_frame_info.small_threshold,
1815 addr, 0);
1816 /* Allocate register save area; for small to medium size frames,
1817 allocate the entire frame; this is joint with one register save. */
1818 if (current_frame_info.first_slot >= 0)
1819 {
1820 machine_mode mode
1821 = (current_frame_info.first_slot_size == UNITS_PER_WORD
1822 ? word_mode : DImode);
1823
1824 off = GEN_INT (-current_frame_info.first_slot_offset);
1825 mem = gen_frame_mem (BLKmode,
1826 gen_rtx_PLUS (Pmode, stack_pointer_rtx, off));
1827 frame_insn (gen_stack_adjust_str
1828 (gen_frame_mem (mode, stack_pointer_rtx),
1829 gen_rtx_REG (mode, current_frame_info.first_slot),
1830 off, mem));
1831 addr = plus_constant (Pmode, addr,
1832 current_frame_info.first_slot_offset);
1833 }
1834 }
1835 epiphany_emit_save_restore (current_frame_info.small_threshold,
1836 FIRST_PSEUDO_REGISTER, addr, 0);
1837 if (current_frame_info.need_fp)
1838 frame_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
1839 /* For large frames, allocate bulk of frame. This is usually joint with one
1840 register save. */
1841 if (current_frame_info.last_slot >= 0)
1842 {
1843 rtx ip, mem2, note;
1844 rtx_insn *insn;
1845
1846 gcc_assert (current_frame_info.last_slot != GPR_FP
1847 || (!current_frame_info.need_fp
1848 && current_frame_info.first_slot < 0));
1849 off = GEN_INT (-current_frame_info.last_slot_offset);
1850 mem = gen_frame_mem (BLKmode,
1851 gen_rtx_PLUS (Pmode, stack_pointer_rtx, off));
1852 ip = gen_rtx_REG (Pmode, GPR_IP);
1853 frame_move_insn (ip, off);
1854 reg = gen_rtx_REG (word_mode, current_frame_info.last_slot),
1855 mem2 = gen_frame_mem (word_mode, stack_pointer_rtx),
1856 insn = frame_insn (gen_stack_adjust_str (mem2, reg, ip, mem));
1857 /* Instruction scheduling can separate the instruction setting IP from
1858 INSN so that dwarf2out_frame_debug_expr becomes confused what the
1859 temporary register is. Example: _gcov.o */
1860 note = gen_rtx_SET (stack_pointer_rtx,
1861 gen_rtx_PLUS (Pmode, stack_pointer_rtx, off));
1862 note = gen_rtx_PARALLEL (VOIDmode,
1863 gen_rtvec (2, gen_rtx_SET (mem2, reg), note));
1864 add_reg_note (insn, REG_FRAME_RELATED_EXPR, note);
1865 }
1866 /* If there is only one or no register to save, yet we have a large frame,
1867 use an add. */
1868 else if (current_frame_info.last_slot_offset)
1869 {
1870 mem = gen_frame_mem (BLKmode,
1871 plus_constant (Pmode, stack_pointer_rtx,
1872 current_frame_info.last_slot_offset));
1873 off = GEN_INT (-current_frame_info.last_slot_offset);
1874 if (!SIMM11 (INTVAL (off)))
1875 {
1876 reg = gen_rtx_REG (Pmode, GPR_IP);
1877 frame_move_insn (reg, off);
1878 off = reg;
1879 }
1880 frame_insn (gen_stack_adjust_add (off, mem));
1881 }
1882 }
1883
1884 void
1885 epiphany_expand_epilogue (int sibcall_p)
1886 {
1887 int interrupt_p;
1888 enum epiphany_function_type fn_type;
1889 rtx mem, addr, reg, off;
1890 HOST_WIDE_INT restore_offset;
1891
1892 fn_type = epiphany_compute_function_type( current_function_decl);
1893 interrupt_p = EPIPHANY_INTERRUPT_P (fn_type);
1894
1895 /* For variable frames, deallocate bulk of frame. */
1896 if (current_frame_info.need_fp)
1897 {
1898 mem = gen_frame_mem (BLKmode, stack_pointer_rtx);
1899 emit_insn (gen_stack_adjust_mov (mem));
1900 }
1901 /* Else for large static frames, deallocate bulk of frame. */
1902 else if (current_frame_info.last_slot_offset)
1903 {
1904 mem = gen_frame_mem (BLKmode, stack_pointer_rtx);
1905 reg = gen_rtx_REG (Pmode, GPR_IP);
1906 emit_move_insn (reg, GEN_INT (current_frame_info.last_slot_offset));
1907 emit_insn (gen_stack_adjust_add (reg, mem));
1908 }
1909 restore_offset = (interrupt_p
1910 ? - 3 * UNITS_PER_WORD
1911 : epiphany_stack_offset - (HOST_WIDE_INT) UNITS_PER_WORD);
1912 addr = plus_constant (Pmode, stack_pointer_rtx,
1913 (current_frame_info.first_slot_offset
1914 + restore_offset));
1915 epiphany_emit_save_restore (current_frame_info.small_threshold,
1916 FIRST_PSEUDO_REGISTER, addr, 1);
1917
1918 if (interrupt_p && !epiphany_uninterruptible_p (current_function_decl))
1919 emit_insn (gen_gid ());
1920
1921 off = GEN_INT (current_frame_info.first_slot_offset);
1922 mem = gen_frame_mem (BLKmode, stack_pointer_rtx);
1923 /* For large / variable size frames, deallocating the register save area is
1924 joint with one register restore; for medium size frames, we use a
1925 dummy post-increment load to dealloacte the whole frame. */
1926 if (!SIMM11 (INTVAL (off)) || current_frame_info.last_slot >= 0)
1927 {
1928 emit_insn (gen_stack_adjust_ldr
1929 (gen_rtx_REG (word_mode,
1930 (current_frame_info.last_slot >= 0
1931 ? current_frame_info.last_slot : GPR_IP)),
1932 gen_frame_mem (word_mode, stack_pointer_rtx),
1933 off,
1934 mem));
1935 }
1936 /* While for small frames, we deallocate the entire frame with one add. */
1937 else if (INTVAL (off))
1938 {
1939 emit_insn (gen_stack_adjust_add (off, mem));
1940 }
1941 if (interrupt_p)
1942 {
1943 emit_move_insn (gen_rtx_REG (word_mode, STATUS_REGNUM),
1944 gen_rtx_REG (SImode, GPR_0));
1945 emit_move_insn (gen_rtx_REG (word_mode, IRET_REGNUM),
1946 gen_rtx_REG (SImode, GPR_1));
1947 addr = plus_constant (Pmode, stack_pointer_rtx,
1948 - (HOST_WIDE_INT) 2 * UNITS_PER_WORD);
1949 emit_move_insn (gen_rtx_REG (DImode, GPR_0),
1950 gen_frame_mem (DImode, addr));
1951 }
1952 addr = plus_constant (Pmode, stack_pointer_rtx,
1953 epiphany_stack_offset - (HOST_WIDE_INT) UNITS_PER_WORD);
1954 epiphany_emit_save_restore (0, current_frame_info.small_threshold, addr, 1);
1955 if (!sibcall_p)
1956 {
1957 if (interrupt_p)
1958 emit_jump_insn (gen_return_internal_interrupt());
1959 else
1960 emit_jump_insn (gen_return_i ());
1961 }
1962 }
1963
1964 int
1965 epiphany_initial_elimination_offset (int from, int to)
1966 {
1967 epiphany_compute_frame_size (get_frame_size ());
1968 if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
1969 return current_frame_info.total_size - current_frame_info.reg_size;
1970 if (from == FRAME_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
1971 return current_frame_info.first_slot_offset - current_frame_info.reg_size;
1972 if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
1973 return (current_frame_info.total_size
1974 - ((current_frame_info.pretend_size + 4) & -8));
1975 if (from == ARG_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
1976 return (current_frame_info.first_slot_offset
1977 - ((current_frame_info.pretend_size + 4) & -8));
1978 gcc_unreachable ();
1979 }
1980
1981 bool
1982 epiphany_regno_rename_ok (unsigned, unsigned dst)
1983 {
1984 enum epiphany_function_type fn_type;
1985
1986 fn_type = epiphany_compute_function_type (current_function_decl);
1987 if (!EPIPHANY_INTERRUPT_P (fn_type))
1988 return true;
1989 if (df_regs_ever_live_p (dst))
1990 return true;
1991 return false;
1992 }
1993
1994 static int
1995 epiphany_issue_rate (void)
1996 {
1997 return 2;
1998 }
1999
2000 /* Function to update the integer COST
2001 based on the relationship between INSN that is dependent on
2002 DEP_INSN through the dependence LINK. The default is to make no
2003 adjustment to COST. This can be used for example to specify to
2004 the scheduler that an output- or anti-dependence does not incur
2005 the same cost as a data-dependence. The return value should be
2006 the new value for COST. */
2007 static int
2008 epiphany_adjust_cost (rtx_insn *insn, int dep_type, rtx_insn *dep_insn,
2009 int cost, unsigned int)
2010 {
2011 if (dep_type == 0)
2012 {
2013 rtx dep_set;
2014
2015 if (recog_memoized (insn) < 0
2016 || recog_memoized (dep_insn) < 0)
2017 return cost;
2018
2019 dep_set = single_set (dep_insn);
2020
2021 /* The latency that we specify in the scheduling description refers
2022 to the actual output, not to an auto-increment register; for that,
2023 the latency is one. */
2024 if (dep_set && MEM_P (SET_SRC (dep_set)) && cost > 1)
2025 {
2026 rtx set = single_set (insn);
2027
2028 if (set
2029 && !reg_overlap_mentioned_p (SET_DEST (dep_set), SET_SRC (set))
2030 && (!MEM_P (SET_DEST (set))
2031 || !reg_overlap_mentioned_p (SET_DEST (dep_set),
2032 XEXP (SET_DEST (set), 0))))
2033 cost = 1;
2034 }
2035 }
2036 return cost;
2037 }
2038
2039 #define REG_OK_FOR_INDEX_P(X) REG_OK_FOR_BASE_P (X)
2040
2041 #define RTX_OK_FOR_BASE_P(X) \
2042 (REG_P (X) && REG_OK_FOR_BASE_P (X))
2043
2044 #define RTX_OK_FOR_INDEX_P(MODE, X) \
2045 ((GET_MODE_CLASS (MODE) != MODE_VECTOR_INT \
2046 || epiphany_vect_align >= GET_MODE_SIZE (MODE)) \
2047 && (REG_P (X) && REG_OK_FOR_INDEX_P (X)))
2048
2049 #define LEGITIMATE_OFFSET_ADDRESS_P(MODE, X) \
2050 (GET_CODE (X) == PLUS \
2051 && RTX_OK_FOR_BASE_P (XEXP (X, 0)) \
2052 && (RTX_OK_FOR_INDEX_P (MODE, XEXP (X, 1)) \
2053 || RTX_OK_FOR_OFFSET_P (MODE, XEXP (X, 1))))
2054
2055 static bool
2056 epiphany_legitimate_address_p (machine_mode mode, rtx x, bool strict,
2057 code_helper = ERROR_MARK)
2058 {
2059 #define REG_OK_FOR_BASE_P(X) \
2060 (strict ? GPR_P (REGNO (X)) : GPR_AP_OR_PSEUDO_P (REGNO (X)))
2061 if (RTX_OK_FOR_BASE_P (x))
2062 return true;
2063 if (RTX_FRAME_OFFSET_P (x))
2064 return true;
2065 if (LEGITIMATE_OFFSET_ADDRESS_P (mode, x))
2066 return true;
2067 /* If this is a misaligned stack access, don't force it to reg+index. */
2068 if (GET_MODE_SIZE (mode) == 8
2069 && GET_CODE (x) == PLUS && XEXP (x, 0) == stack_pointer_rtx
2070 /* Decomposed to SImode; GET_MODE_SIZE (SImode) == 4 */
2071 && !(INTVAL (XEXP (x, 1)) & 3)
2072 && INTVAL (XEXP (x, 1)) >= -2047 * 4
2073 && INTVAL (XEXP (x, 1)) <= 2046 * 4)
2074 return true;
2075 if (TARGET_POST_INC
2076 && (GET_CODE (x) == POST_DEC || GET_CODE (x) == POST_INC)
2077 && RTX_OK_FOR_BASE_P (XEXP ((x), 0)))
2078 return true;
2079 if ((TARGET_POST_MODIFY || reload_completed)
2080 && GET_CODE (x) == POST_MODIFY
2081 && GET_CODE (XEXP ((x), 1)) == PLUS
2082 && rtx_equal_p (XEXP ((x), 0), XEXP (XEXP ((x), 1), 0))
2083 && LEGITIMATE_OFFSET_ADDRESS_P (mode, XEXP ((x), 1)))
2084 return true;
2085 if (mode == BLKmode)
2086 return epiphany_legitimate_address_p (SImode, x, strict);
2087 return false;
2088 }
2089
2090 static reg_class_t
2091 epiphany_secondary_reload (bool in_p, rtx x, reg_class_t rclass,
2092 machine_mode mode ATTRIBUTE_UNUSED,
2093 secondary_reload_info *sri)
2094 {
2095 /* This could give more reload inheritance, but we are missing some
2096 reload infrastructure. */
2097 if (0)
2098 if (in_p && GET_CODE (x) == UNSPEC
2099 && satisfies_constraint_Sra (x) && !satisfies_constraint_Rra (x))
2100 {
2101 gcc_assert (rclass == GENERAL_REGS);
2102 sri->icode = CODE_FOR_reload_insi_ra;
2103 return NO_REGS;
2104 }
2105 return NO_REGS;
2106 }
2107
2108 bool
2109 epiphany_is_long_call_p (rtx x)
2110 {
2111 tree decl = SYMBOL_REF_DECL (x);
2112 bool ret_val = !TARGET_SHORT_CALLS;
2113 tree attrs;
2114
2115 /* ??? Is it safe to default to ret_val if decl is NULL? We should
2116 probably encode information via encode_section_info, and also
2117 have (an) option(s) to take SYMBOL_FLAG_LOCAL and/or SYMBOL_FLAG_EXTERNAL
2118 into account. */
2119 if (decl)
2120 {
2121 attrs = TYPE_ATTRIBUTES (TREE_TYPE (decl));
2122 if (lookup_attribute ("long_call", attrs))
2123 ret_val = true;
2124 else if (lookup_attribute ("short_call", attrs))
2125 ret_val = false;
2126 }
2127 return ret_val;
2128 }
2129
2130 bool
2131 epiphany_small16 (rtx x)
2132 {
2133 rtx base = x;
2134 rtx offs ATTRIBUTE_UNUSED = const0_rtx;
2135
2136 if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS)
2137 {
2138 base = XEXP (XEXP (x, 0), 0);
2139 offs = XEXP (XEXP (x, 0), 1);
2140 }
2141 if (GET_CODE (base) == SYMBOL_REF && SYMBOL_REF_FUNCTION_P (base)
2142 && epiphany_is_long_call_p (base))
2143 return false;
2144 return TARGET_SMALL16 != 0;
2145 }
2146
2147 /* Return nonzero if it is ok to make a tail-call to DECL. */
2148 static bool
2149 epiphany_function_ok_for_sibcall (tree decl, tree exp)
2150 {
2151 bool cfun_interrupt_p, call_interrupt_p;
2152
2153 cfun_interrupt_p = EPIPHANY_INTERRUPT_P (epiphany_compute_function_type
2154 (current_function_decl));
2155 if (decl)
2156 call_interrupt_p = EPIPHANY_INTERRUPT_P (epiphany_compute_function_type (decl));
2157 else
2158 {
2159 tree fn_type = TREE_TYPE (CALL_EXPR_FN (exp));
2160
2161 gcc_assert (POINTER_TYPE_P (fn_type));
2162 fn_type = TREE_TYPE (fn_type);
2163 gcc_assert (FUNC_OR_METHOD_TYPE_P (fn_type));
2164 call_interrupt_p
2165 = lookup_attribute ("interrupt", TYPE_ATTRIBUTES (fn_type)) != NULL;
2166 }
2167
2168 /* Don't tailcall from or to an ISR routine - although we could in
2169 principle tailcall from one ISR routine to another, we'd need to
2170 handle this in sibcall_epilogue to make it work. */
2171 if (cfun_interrupt_p || call_interrupt_p)
2172 return false;
2173
2174 /* Everything else is ok. */
2175 return true;
2176 }
2177
2178 /* T is a function declaration or the MEM_EXPR of a MEM passed to a call
2179 expander.
2180 Return true iff the type of T has the uninterruptible attribute.
2181 If T is NULL, return false. */
2182 bool
2183 epiphany_uninterruptible_p (tree t)
2184 {
2185 tree attrs;
2186
2187 if (t)
2188 {
2189 attrs = TYPE_ATTRIBUTES (TREE_TYPE (t));
2190 if (lookup_attribute ("disinterrupt", attrs))
2191 return true;
2192 }
2193 return false;
2194 }
2195
2196 bool
2197 epiphany_call_uninterruptible_p (rtx mem)
2198 {
2199 rtx addr = XEXP (mem, 0);
2200 tree t = NULL_TREE;
2201
2202 if (GET_CODE (addr) == SYMBOL_REF)
2203 t = SYMBOL_REF_DECL (addr);
2204 if (!t)
2205 t = MEM_EXPR (mem);
2206 return epiphany_uninterruptible_p (t);
2207 }
2208
2209 static machine_mode
2210 epiphany_promote_function_mode (const_tree type, machine_mode mode,
2211 int *punsignedp ATTRIBUTE_UNUSED,
2212 const_tree funtype ATTRIBUTE_UNUSED,
2213 int for_return ATTRIBUTE_UNUSED)
2214 {
2215 int dummy;
2216
2217 return promote_mode (type, mode, &dummy);
2218 }
2219
2220 static void
2221 epiphany_conditional_register_usage (void)
2222 {
2223 int i;
2224
2225 if (PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM)
2226 {
2227 fixed_regs[PIC_OFFSET_TABLE_REGNUM] = 1;
2228 call_used_regs[PIC_OFFSET_TABLE_REGNUM] = 1;
2229 }
2230 if (TARGET_HALF_REG_FILE)
2231 {
2232 for (i = 32; i <= 63; i++)
2233 {
2234 fixed_regs[i] = 1;
2235 call_used_regs[i] = 1;
2236 }
2237 }
2238 if (epiphany_m1reg >= 0)
2239 {
2240 fixed_regs[epiphany_m1reg] = 1;
2241 call_used_regs[epiphany_m1reg] = 1;
2242 }
2243 if (!TARGET_PREFER_SHORT_INSN_REGS)
2244 CLEAR_HARD_REG_SET (reg_class_contents[SHORT_INSN_REGS]);
2245 reg_class_contents[SIBCALL_REGS] = reg_class_contents[GENERAL_REGS];
2246 /* It would be simpler and quicker if we could just use
2247 &~, alas, call_used_or_fixed_regs is yet uninitialized;
2248 it is set up later by our caller. */
2249 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
2250 if (!call_used_regs[i])
2251 CLEAR_HARD_REG_BIT (reg_class_contents[SIBCALL_REGS], i);
2252 }
2253
2254 /* Determine where to put an argument to a function.
2255 Value is zero to push the argument on the stack,
2256 or a hard register in which to store the argument.
2257
2258 CUM is a variable of type CUMULATIVE_ARGS which gives info about
2259 the preceding args and about the function being called.
2260 ARG is a description of the argument. */
2261 /* On the EPIPHANY the first MAX_EPIPHANY_PARM_REGS args are normally in
2262 registers and the rest are pushed. */
2263 static rtx
2264 epiphany_function_arg (cumulative_args_t cum_v, const function_arg_info &arg)
2265 {
2266 CUMULATIVE_ARGS cum = *get_cumulative_args (cum_v);
2267
2268 if (PASS_IN_REG_P (cum, arg.mode, arg.type))
2269 return gen_rtx_REG (arg.mode, ROUND_ADVANCE_CUM (cum, arg.mode, arg.type));
2270 return 0;
2271 }
2272
2273 /* Update the data in CUM to advance over argument ARG. */
2274 static void
2275 epiphany_function_arg_advance (cumulative_args_t cum_v,
2276 const function_arg_info &arg)
2277 {
2278 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
2279
2280 *cum = (ROUND_ADVANCE_CUM (*cum, arg.mode, arg.type)
2281 + ROUND_ADVANCE_ARG (arg.mode, arg.type));
2282 }
2283
2284 /* Nested function support.
2285 An epiphany trampoline looks like this:
2286 mov r16,%low(fnaddr)
2287 movt r16,%high(fnaddr)
2288 mov ip,%low(cxt)
2289 movt ip,%high(cxt)
2290 jr r16 */
2291
2292 #define EPIPHANY_LOW_RTX(X) \
2293 (gen_rtx_IOR (SImode, \
2294 gen_rtx_ASHIFT (SImode, \
2295 gen_rtx_AND (SImode, (X), GEN_INT (0xff)), GEN_INT (5)), \
2296 gen_rtx_ASHIFT (SImode, \
2297 gen_rtx_AND (SImode, (X), GEN_INT (0xff00)), GEN_INT (12))))
2298 #define EPIPHANY_HIGH_RTX(X) \
2299 EPIPHANY_LOW_RTX (gen_rtx_LSHIFTRT (SImode, (X), GEN_INT (16)))
2300
2301 /* Emit RTL insns to initialize the variable parts of a trampoline.
2302 FNADDR is an RTX for the address of the function's pure code.
2303 CXT is an RTX for the static chain value for the function. */
2304 static void
2305 epiphany_trampoline_init (rtx tramp_mem, tree fndecl, rtx cxt)
2306 {
2307 rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
2308 rtx tramp = force_reg (Pmode, XEXP (tramp_mem, 0));
2309
2310 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (Pmode, tramp, 0)),
2311 gen_rtx_IOR (SImode, GEN_INT (0x4002000b),
2312 EPIPHANY_LOW_RTX (fnaddr)));
2313 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (Pmode, tramp, 4)),
2314 gen_rtx_IOR (SImode, GEN_INT (0x5002000b),
2315 EPIPHANY_HIGH_RTX (fnaddr)));
2316 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (Pmode, tramp, 8)),
2317 gen_rtx_IOR (SImode, GEN_INT (0x2002800b),
2318 EPIPHANY_LOW_RTX (cxt)));
2319 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (Pmode, tramp, 12)),
2320 gen_rtx_IOR (SImode, GEN_INT (0x3002800b),
2321 EPIPHANY_HIGH_RTX (cxt)));
2322 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (Pmode, tramp, 16)),
2323 GEN_INT (0x0802014f));
2324 }
2325
2326 bool
2327 epiphany_optimize_mode_switching (int entity)
2328 {
2329 if (MACHINE_FUNCTION (cfun)->sw_entities_processed & (1 << entity))
2330 return false;
2331 switch (entity)
2332 {
2333 case EPIPHANY_MSW_ENTITY_AND:
2334 case EPIPHANY_MSW_ENTITY_OR:
2335 case EPIPHANY_MSW_ENTITY_CONFIG:
2336 return true;
2337 case EPIPHANY_MSW_ENTITY_NEAREST:
2338 case EPIPHANY_MSW_ENTITY_TRUNC:
2339 return optimize > 0;
2340 case EPIPHANY_MSW_ENTITY_ROUND_UNKNOWN:
2341 return MACHINE_FUNCTION (cfun)->unknown_mode_uses != 0;
2342 case EPIPHANY_MSW_ENTITY_ROUND_KNOWN:
2343 return (MACHINE_FUNCTION (cfun)->sw_entities_processed
2344 & (1 << EPIPHANY_MSW_ENTITY_ROUND_UNKNOWN)) != 0;
2345 case EPIPHANY_MSW_ENTITY_FPU_OMNIBUS:
2346 return optimize == 0 || current_pass == pass_mode_switch_use;
2347 }
2348 gcc_unreachable ();
2349 }
2350
2351 static int
2352 epiphany_mode_priority (int entity, int priority)
2353 {
2354 if (entity == EPIPHANY_MSW_ENTITY_AND || entity == EPIPHANY_MSW_ENTITY_OR
2355 || entity== EPIPHANY_MSW_ENTITY_CONFIG)
2356 return priority;
2357 if (priority > 3)
2358 switch (priority)
2359 {
2360 case 4: return FP_MODE_ROUND_UNKNOWN;
2361 case 5: return FP_MODE_NONE;
2362 default: gcc_unreachable ();
2363 }
2364 switch ((enum attr_fp_mode) epiphany_normal_fp_mode)
2365 {
2366 case FP_MODE_INT:
2367 switch (priority)
2368 {
2369 case 0: return FP_MODE_INT;
2370 case 1: return epiphany_normal_fp_rounding;
2371 case 2: return (epiphany_normal_fp_rounding == FP_MODE_ROUND_NEAREST
2372 ? FP_MODE_ROUND_TRUNC : FP_MODE_ROUND_NEAREST);
2373 case 3: return FP_MODE_CALLER;
2374 default: gcc_unreachable ();
2375 }
2376 case FP_MODE_ROUND_NEAREST:
2377 case FP_MODE_CALLER:
2378 switch (priority)
2379 {
2380 case 0: return FP_MODE_ROUND_NEAREST;
2381 case 1: return FP_MODE_ROUND_TRUNC;
2382 case 2: return FP_MODE_INT;
2383 case 3: return FP_MODE_CALLER;
2384 default: gcc_unreachable ();
2385 }
2386 case FP_MODE_ROUND_TRUNC:
2387 switch (priority)
2388 {
2389 case 0: return FP_MODE_ROUND_TRUNC;
2390 case 1: return FP_MODE_ROUND_NEAREST;
2391 case 2: return FP_MODE_INT;
2392 case 3: return FP_MODE_CALLER;
2393 default: gcc_unreachable ();
2394 }
2395 case FP_MODE_ROUND_UNKNOWN:
2396 case FP_MODE_NONE:
2397 gcc_unreachable ();
2398 }
2399 gcc_unreachable ();
2400 }
2401
2402 int
2403 epiphany_mode_needed (int entity, rtx_insn *insn, HARD_REG_SET)
2404 {
2405 enum attr_fp_mode mode;
2406
2407 if (recog_memoized (insn) < 0)
2408 {
2409 if (entity == EPIPHANY_MSW_ENTITY_AND
2410 || entity == EPIPHANY_MSW_ENTITY_OR
2411 || entity == EPIPHANY_MSW_ENTITY_CONFIG)
2412 return 2;
2413 return FP_MODE_NONE;
2414 }
2415 mode = get_attr_fp_mode (insn);
2416
2417 switch (entity)
2418 {
2419 case EPIPHANY_MSW_ENTITY_AND:
2420 return mode != FP_MODE_NONE && mode != FP_MODE_INT ? 1 : 2;
2421 case EPIPHANY_MSW_ENTITY_OR:
2422 return mode == FP_MODE_INT ? 1 : 2;
2423 case EPIPHANY_MSW_ENTITY_CONFIG:
2424 /* We must know/save config before we set it to something else.
2425 Where we need the original value, we are fine with having it
2426 just unchanged from the function start.
2427 Because of the nature of the mode switching optimization,
2428 a restore will be dominated by a clobber. */
2429 if (mode != FP_MODE_NONE && mode != FP_MODE_CALLER)
2430 return 1;
2431 /* A cpecial case are abnormal edges, which are deemed to clobber
2432 the mode as well. We need to pin this effect on a actually
2433 dominating insn, and one where the frame can be accessed, too, in
2434 case the pseudo used to save CONFIG doesn't get a hard register. */
2435 if (CALL_P (insn) && find_reg_note (insn, REG_EH_REGION, NULL_RTX))
2436 return 1;
2437 return 2;
2438 case EPIPHANY_MSW_ENTITY_ROUND_KNOWN:
2439 if (recog_memoized (insn) == CODE_FOR_set_fp_mode)
2440 mode = (enum attr_fp_mode) epiphany_mode_after (entity, mode, insn, {});
2441 /* Fall through. */
2442 case EPIPHANY_MSW_ENTITY_NEAREST:
2443 case EPIPHANY_MSW_ENTITY_TRUNC:
2444 if (mode == FP_MODE_ROUND_UNKNOWN)
2445 {
2446 MACHINE_FUNCTION (cfun)->unknown_mode_uses++;
2447 return FP_MODE_NONE;
2448 }
2449 return mode;
2450 case EPIPHANY_MSW_ENTITY_ROUND_UNKNOWN:
2451 if (mode == FP_MODE_ROUND_NEAREST || mode == FP_MODE_ROUND_TRUNC)
2452 return FP_MODE_ROUND_UNKNOWN;
2453 return mode;
2454 case EPIPHANY_MSW_ENTITY_FPU_OMNIBUS:
2455 if (mode == FP_MODE_ROUND_UNKNOWN)
2456 return epiphany_normal_fp_rounding;
2457 return mode;
2458 default:
2459 gcc_unreachable ();
2460 }
2461 }
2462
2463 static int
2464 epiphany_mode_entry_exit (int entity, bool exit)
2465 {
2466 int normal_mode = epiphany_normal_fp_mode ;
2467
2468 MACHINE_FUNCTION (cfun)->sw_entities_processed |= (1 << entity);
2469 if (epiphany_is_interrupt_p (current_function_decl))
2470 normal_mode = FP_MODE_CALLER;
2471 switch (entity)
2472 {
2473 case EPIPHANY_MSW_ENTITY_AND:
2474 if (exit)
2475 return normal_mode != FP_MODE_INT ? 1 : 2;
2476 return 0;
2477 case EPIPHANY_MSW_ENTITY_OR:
2478 if (exit)
2479 return normal_mode == FP_MODE_INT ? 1 : 2;
2480 return 0;
2481 case EPIPHANY_MSW_ENTITY_CONFIG:
2482 if (exit)
2483 return 2;
2484 return normal_mode == FP_MODE_CALLER ? 0 : 1;
2485 case EPIPHANY_MSW_ENTITY_ROUND_UNKNOWN:
2486 if (normal_mode == FP_MODE_ROUND_NEAREST
2487 || normal_mode == FP_MODE_ROUND_TRUNC)
2488 return FP_MODE_ROUND_UNKNOWN;
2489 /* Fall through. */
2490 case EPIPHANY_MSW_ENTITY_NEAREST:
2491 case EPIPHANY_MSW_ENTITY_TRUNC:
2492 case EPIPHANY_MSW_ENTITY_ROUND_KNOWN:
2493 case EPIPHANY_MSW_ENTITY_FPU_OMNIBUS:
2494 return normal_mode;
2495 default:
2496 gcc_unreachable ();
2497 }
2498 }
2499
2500 int
2501 epiphany_mode_after (int entity, int last_mode, rtx_insn *insn,
2502 HARD_REG_SET)
2503 {
2504 /* We have too few call-saved registers to hope to keep the masks across
2505 calls. */
2506 if (entity == EPIPHANY_MSW_ENTITY_AND || entity == EPIPHANY_MSW_ENTITY_OR)
2507 {
2508 if (CALL_P (insn))
2509 return 0;
2510 return last_mode;
2511 }
2512 /* If there is an abnormal edge, we don't want the config register to
2513 be 'saved' again at the destination.
2514 The frame pointer adjustment is inside a PARALLEL because of the
2515 flags clobber. */
2516 if (entity == EPIPHANY_MSW_ENTITY_CONFIG && NONJUMP_INSN_P (insn)
2517 && GET_CODE (PATTERN (insn)) == PARALLEL
2518 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET
2519 && SET_DEST (XVECEXP (PATTERN (insn), 0, 0)) == frame_pointer_rtx)
2520 {
2521 gcc_assert (cfun->has_nonlocal_label);
2522 return 1;
2523 }
2524 if (recog_memoized (insn) < 0)
2525 return last_mode;
2526 if (get_attr_fp_mode (insn) == FP_MODE_ROUND_UNKNOWN
2527 && last_mode != FP_MODE_ROUND_NEAREST && last_mode != FP_MODE_ROUND_TRUNC)
2528 {
2529 if (entity == EPIPHANY_MSW_ENTITY_NEAREST)
2530 return FP_MODE_ROUND_NEAREST;
2531 if (entity == EPIPHANY_MSW_ENTITY_TRUNC)
2532 return FP_MODE_ROUND_TRUNC;
2533 }
2534 if (recog_memoized (insn) == CODE_FOR_set_fp_mode)
2535 {
2536 rtx src = SET_SRC (XVECEXP (PATTERN (insn), 0, 0));
2537 int fp_mode;
2538
2539 if (REG_P (src))
2540 return FP_MODE_CALLER;
2541 fp_mode = INTVAL (XVECEXP (XEXP (src, 0), 0, 0));
2542 if (entity == EPIPHANY_MSW_ENTITY_ROUND_UNKNOWN
2543 && (fp_mode == FP_MODE_ROUND_NEAREST
2544 || fp_mode == EPIPHANY_MSW_ENTITY_TRUNC))
2545 return FP_MODE_ROUND_UNKNOWN;
2546 return fp_mode;
2547 }
2548 return last_mode;
2549 }
2550
2551 static int
2552 epiphany_mode_entry (int entity)
2553 {
2554 return epiphany_mode_entry_exit (entity, false);
2555 }
2556
2557 static int
2558 epiphany_mode_exit (int entity)
2559 {
2560 return epiphany_mode_entry_exit (entity, true);
2561 }
2562
2563 void
2564 emit_set_fp_mode (int entity, int mode, int prev_mode ATTRIBUTE_UNUSED,
2565 HARD_REG_SET regs_live ATTRIBUTE_UNUSED)
2566 {
2567 rtx save_cc, cc_reg, mask, src, src2;
2568 enum attr_fp_mode fp_mode;
2569
2570 if (!MACHINE_FUNCTION (cfun)->and_mask)
2571 {
2572 MACHINE_FUNCTION (cfun)->and_mask = gen_reg_rtx (SImode);
2573 MACHINE_FUNCTION (cfun)->or_mask = gen_reg_rtx (SImode);
2574 }
2575 if (entity == EPIPHANY_MSW_ENTITY_AND)
2576 {
2577 gcc_assert (mode >= 0 && mode <= 2);
2578 if (mode == 1)
2579 emit_move_insn (MACHINE_FUNCTION (cfun)->and_mask,
2580 gen_int_mode (0xfff1fffe, SImode));
2581 return;
2582 }
2583 else if (entity == EPIPHANY_MSW_ENTITY_OR)
2584 {
2585 gcc_assert (mode >= 0 && mode <= 2);
2586 if (mode == 1)
2587 emit_move_insn (MACHINE_FUNCTION (cfun)->or_mask, GEN_INT(0x00080000));
2588 return;
2589 }
2590 else if (entity == EPIPHANY_MSW_ENTITY_CONFIG)
2591 {
2592 /* Mode switching optimization is done after emit_initial_value_sets,
2593 so we have to take care of CONFIG_REGNUM here. */
2594 gcc_assert (mode >= 0 && mode <= 2);
2595 rtx save = get_hard_reg_initial_val (SImode, CONFIG_REGNUM);
2596 if (mode == 1)
2597 emit_insn (gen_save_config (save));
2598 return;
2599 }
2600 fp_mode = (enum attr_fp_mode) mode;
2601 src = NULL_RTX;
2602
2603 switch (fp_mode)
2604 {
2605 case FP_MODE_CALLER:
2606 /* The EPIPHANY_MSW_ENTITY_CONFIG processing must come later
2607 so that the config save gets inserted before the first use. */
2608 gcc_assert (entity > EPIPHANY_MSW_ENTITY_CONFIG);
2609 src = get_hard_reg_initial_val (SImode, CONFIG_REGNUM);
2610 mask = MACHINE_FUNCTION (cfun)->and_mask;
2611 break;
2612 case FP_MODE_ROUND_UNKNOWN:
2613 MACHINE_FUNCTION (cfun)->unknown_mode_sets++;
2614 mask = MACHINE_FUNCTION (cfun)->and_mask;
2615 break;
2616 case FP_MODE_ROUND_NEAREST:
2617 if (entity == EPIPHANY_MSW_ENTITY_TRUNC)
2618 return;
2619 mask = MACHINE_FUNCTION (cfun)->and_mask;
2620 break;
2621 case FP_MODE_ROUND_TRUNC:
2622 if (entity == EPIPHANY_MSW_ENTITY_NEAREST)
2623 return;
2624 mask = MACHINE_FUNCTION (cfun)->and_mask;
2625 break;
2626 case FP_MODE_INT:
2627 mask = MACHINE_FUNCTION (cfun)->or_mask;
2628 break;
2629 case FP_MODE_NONE:
2630 default:
2631 gcc_unreachable ();
2632 }
2633 save_cc = gen_reg_rtx (CCmode);
2634 cc_reg = gen_rtx_REG (CCmode, CC_REGNUM);
2635 emit_move_insn (save_cc, cc_reg);
2636 mask = force_reg (SImode, mask);
2637 if (!src)
2638 {
2639 rtvec v = gen_rtvec (1, GEN_INT (fp_mode));
2640
2641 src = gen_rtx_CONST (SImode, gen_rtx_UNSPEC (SImode, v, UNSPEC_FP_MODE));
2642 }
2643 if (entity == EPIPHANY_MSW_ENTITY_ROUND_KNOWN
2644 || entity == EPIPHANY_MSW_ENTITY_FPU_OMNIBUS)
2645 src2 = copy_rtx (src);
2646 else
2647 {
2648 rtvec v = gen_rtvec (1, GEN_INT (FP_MODE_ROUND_UNKNOWN));
2649
2650 src2 = gen_rtx_CONST (SImode, gen_rtx_UNSPEC (SImode, v, UNSPEC_FP_MODE));
2651 }
2652 emit_insn (gen_set_fp_mode (src, src2, mask));
2653 emit_move_insn (cc_reg, save_cc);
2654 }
2655
2656 void
2657 epiphany_expand_set_fp_mode (rtx *operands)
2658 {
2659 rtx ctrl = gen_rtx_REG (SImode, CONFIG_REGNUM);
2660 rtx src = operands[0];
2661 rtx mask_reg = operands[2];
2662 rtx scratch = operands[3];
2663 enum attr_fp_mode fp_mode;
2664
2665
2666 gcc_assert (rtx_equal_p (src, operands[1])
2667 /* Sometimes reload gets silly and reloads the same pseudo
2668 into different registers. */
2669 || (REG_P (src) && REG_P (operands[1])));
2670
2671 if (!epiphany_uninterruptible_p (current_function_decl))
2672 emit_insn (gen_gid ());
2673 emit_move_insn (scratch, ctrl);
2674
2675 if (GET_CODE (src) == REG)
2676 {
2677 /* FP_MODE_CALLER */
2678 emit_insn (gen_xorsi3 (scratch, scratch, src));
2679 emit_insn (gen_andsi3 (scratch, scratch, mask_reg));
2680 emit_insn (gen_xorsi3 (scratch, scratch, src));
2681 }
2682 else
2683 {
2684 gcc_assert (GET_CODE (src) == CONST);
2685 src = XEXP (src, 0);
2686 fp_mode = (enum attr_fp_mode) INTVAL (XVECEXP (src, 0, 0));
2687 switch (fp_mode)
2688 {
2689 case FP_MODE_ROUND_NEAREST:
2690 emit_insn (gen_andsi3 (scratch, scratch, mask_reg));
2691 break;
2692 case FP_MODE_ROUND_TRUNC:
2693 emit_insn (gen_andsi3 (scratch, scratch, mask_reg));
2694 emit_insn (gen_add2_insn (scratch, const1_rtx));
2695 break;
2696 case FP_MODE_INT:
2697 emit_insn (gen_iorsi3 (scratch, scratch, mask_reg));
2698 break;
2699 case FP_MODE_CALLER:
2700 case FP_MODE_ROUND_UNKNOWN:
2701 case FP_MODE_NONE:
2702 gcc_unreachable ();
2703 }
2704 }
2705 emit_move_insn (ctrl, scratch);
2706 if (!epiphany_uninterruptible_p (current_function_decl))
2707 emit_insn (gen_gie ());
2708 }
2709
2710 void
2711 epiphany_insert_mode_switch_use (rtx_insn *insn,
2712 int entity ATTRIBUTE_UNUSED,
2713 int mode ATTRIBUTE_UNUSED)
2714 {
2715 rtx pat = PATTERN (insn);
2716 rtvec v;
2717 int len, i;
2718 rtx near = gen_rtx_REG (SImode, FP_NEAREST_REGNUM);
2719 rtx trunc = gen_rtx_REG (SImode, FP_TRUNCATE_REGNUM);
2720
2721 if (entity != EPIPHANY_MSW_ENTITY_FPU_OMNIBUS)
2722 return;
2723 switch ((enum attr_fp_mode) get_attr_fp_mode (insn))
2724 {
2725 case FP_MODE_ROUND_NEAREST:
2726 near = gen_rtx_USE (VOIDmode, near);
2727 trunc = gen_rtx_CLOBBER (VOIDmode, trunc);
2728 break;
2729 case FP_MODE_ROUND_TRUNC:
2730 near = gen_rtx_CLOBBER (VOIDmode, near);
2731 trunc = gen_rtx_USE (VOIDmode, trunc);
2732 break;
2733 case FP_MODE_ROUND_UNKNOWN:
2734 near = gen_rtx_USE (VOIDmode, gen_rtx_REG (SImode, FP_ANYFP_REGNUM));
2735 trunc = copy_rtx (near);
2736 /* Fall through. */
2737 case FP_MODE_INT:
2738 case FP_MODE_CALLER:
2739 near = gen_rtx_USE (VOIDmode, near);
2740 trunc = gen_rtx_USE (VOIDmode, trunc);
2741 break;
2742 case FP_MODE_NONE:
2743 gcc_unreachable ();
2744 }
2745 gcc_assert (GET_CODE (pat) == PARALLEL);
2746 len = XVECLEN (pat, 0);
2747 v = rtvec_alloc (len + 2);
2748 for (i = 0; i < len; i++)
2749 RTVEC_ELT (v, i) = XVECEXP (pat, 0, i);
2750 RTVEC_ELT (v, len) = near;
2751 RTVEC_ELT (v, len + 1) = trunc;
2752 pat = gen_rtx_PARALLEL (VOIDmode, v);
2753 PATTERN (insn) = pat;
2754 MACHINE_FUNCTION (cfun)->control_use_inserted = true;
2755 }
2756
2757 bool
2758 epiphany_epilogue_uses (int regno)
2759 {
2760 if (regno == GPR_LR)
2761 return true;
2762 if (reload_completed && epiphany_is_interrupt_p (current_function_decl))
2763 {
2764 if (fixed_regs[regno]
2765 && regno != STATUS_REGNUM && regno != IRET_REGNUM
2766 && regno != FP_NEAREST_REGNUM && regno != FP_TRUNCATE_REGNUM)
2767 return false;
2768 return true;
2769 }
2770 if (regno == FP_NEAREST_REGNUM
2771 && epiphany_normal_fp_mode != FP_MODE_ROUND_TRUNC)
2772 return true;
2773 if (regno == FP_TRUNCATE_REGNUM
2774 && epiphany_normal_fp_mode != FP_MODE_ROUND_NEAREST)
2775 return true;
2776 return false;
2777 }
2778
2779 static unsigned int
2780 epiphany_min_divisions_for_recip_mul (machine_mode mode)
2781 {
2782 if (flag_reciprocal_math && mode == SFmode)
2783 /* We'll expand into a multiply-by-reciprocal anyway, so we might a well do
2784 it already at the tree level and expose it to further optimizations. */
2785 return 1;
2786 return default_min_divisions_for_recip_mul (mode);
2787 }
2788
2789 static machine_mode
2790 epiphany_preferred_simd_mode (scalar_mode mode ATTRIBUTE_UNUSED)
2791 {
2792 return TARGET_VECT_DOUBLE ? DImode : SImode;
2793 }
2794
2795 static bool
2796 epiphany_vector_mode_supported_p (machine_mode mode)
2797 {
2798 if (mode == V2SFmode)
2799 return true;
2800 if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT
2801 && (GET_MODE_SIZE (mode) == 4 || GET_MODE_SIZE (mode) == 8))
2802 return true;
2803 return false;
2804 }
2805
2806 static bool
2807 epiphany_vector_alignment_reachable (const_tree type, bool is_packed)
2808 {
2809 /* Vectors which aren't in packed structures will not be less aligned than
2810 the natural alignment of their element type, so this is safe. */
2811 if (TYPE_ALIGN_UNIT (type) == 4)
2812 return !is_packed;
2813
2814 return default_builtin_vector_alignment_reachable (type, is_packed);
2815 }
2816
2817 static bool
2818 epiphany_support_vector_misalignment (machine_mode mode, const_tree type,
2819 int misalignment, bool is_packed)
2820 {
2821 if (GET_MODE_SIZE (mode) == 8 && misalignment % 4 == 0)
2822 return true;
2823 return default_builtin_support_vector_misalignment (mode, type, misalignment,
2824 is_packed);
2825 }
2826
2827 /* STRUCTURE_SIZE_BOUNDARY seems a bit crude in how it enlarges small
2828 structs. Make structs double-word-aligned it they are a double word or
2829 (potentially) larger; failing that, do the same for a size of 32 bits. */
2830 unsigned
2831 epiphany_special_round_type_align (tree type, unsigned computed,
2832 unsigned specified)
2833 {
2834 unsigned align = MAX (computed, specified);
2835 tree field;
2836 HOST_WIDE_INT total, max;
2837 unsigned try_align = FASTEST_ALIGNMENT;
2838
2839 if (maximum_field_alignment && try_align > maximum_field_alignment)
2840 try_align = maximum_field_alignment;
2841 if (align >= try_align)
2842 return align;
2843 for (max = 0, field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
2844 {
2845 tree offset, size;
2846
2847 if (TREE_CODE (field) != FIELD_DECL
2848 || TREE_TYPE (field) == error_mark_node)
2849 continue;
2850 offset = bit_position (field);
2851 size = DECL_SIZE (field);
2852 if (!tree_fits_uhwi_p (offset) || !tree_fits_uhwi_p (size)
2853 || tree_to_uhwi (offset) >= try_align
2854 || tree_to_uhwi (size) >= try_align)
2855 return try_align;
2856 total = tree_to_uhwi (offset) + tree_to_uhwi (size);
2857 if (total > max)
2858 max = total;
2859 }
2860 if (max >= (HOST_WIDE_INT) try_align)
2861 align = try_align;
2862 else if (try_align > 32 && max >= 32)
2863 align = max > 32 ? 64 : 32;
2864 return align;
2865 }
2866
2867 /* Upping the alignment of arrays in structs is not only a performance
2868 enhancement, it also helps preserve assumptions about how
2869 arrays-at-the-end-of-structs work, like for struct gcov_fn_info in
2870 libgcov.c . */
2871 unsigned
2872 epiphany_adjust_field_align (tree type, unsigned computed)
2873 {
2874 if (computed == 32
2875 && TREE_CODE (type) == ARRAY_TYPE)
2876 {
2877 tree elmsz = TYPE_SIZE (TREE_TYPE (type));
2878
2879 if (!tree_fits_uhwi_p (elmsz) || tree_to_uhwi (elmsz) >= 32)
2880 return 64;
2881 }
2882 return computed;
2883 }
2884
2885 /* Output code to add DELTA to the first argument, and then jump
2886 to FUNCTION. Used for C++ multiple inheritance. */
2887 static void
2888 epiphany_output_mi_thunk (FILE *file, tree thunk ATTRIBUTE_UNUSED,
2889 HOST_WIDE_INT delta,
2890 HOST_WIDE_INT vcall_offset,
2891 tree function)
2892 {
2893 const char *fnname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (thunk));
2894 int this_regno
2895 = aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function) ? 1 : 0;
2896 const char *this_name = reg_names[this_regno];
2897 const char *fname;
2898
2899 assemble_start_function (thunk, fnname);
2900 /* We use IP and R16 as a scratch registers. */
2901 gcc_assert (call_used_or_fixed_reg_p (GPR_IP));
2902 gcc_assert (call_used_or_fixed_reg_p (GPR_16));
2903
2904 /* Add DELTA. When possible use a plain add, otherwise load it into
2905 a register first. */
2906 if (delta == 0)
2907 ; /* Done. */
2908 else if (SIMM11 (delta))
2909 asm_fprintf (file, "\tadd\t%s,%s,%d\n", this_name, this_name, (int) delta);
2910 else if (delta < 0 && delta >= -0xffff)
2911 {
2912 asm_fprintf (file, "\tmov\tip,%d\n", (int) -delta);
2913 asm_fprintf (file, "\tsub\t%s,%s,ip\n", this_name, this_name);
2914 }
2915 else
2916 {
2917 asm_fprintf (file, "\tmov\tip,%%low(%ld)\n", (long) delta);
2918 if (delta & ~0xffff)
2919 asm_fprintf (file, "\tmovt\tip,%%high(%ld)\n", (long) delta);
2920 asm_fprintf (file, "\tadd\t%s,%s,ip\n", this_name, this_name);
2921 }
2922
2923 /* If needed, add *(*THIS + VCALL_OFFSET) to THIS. */
2924 if (vcall_offset != 0)
2925 {
2926 /* ldr ip,[this] --> temp = *this
2927 ldr ip,[ip,vcall_offset] > temp = *(*this + vcall_offset)
2928 add this,this,ip --> this+ = *(*this + vcall_offset) */
2929 asm_fprintf (file, "\tldr\tip, [%s]\n", this_name);
2930 if (vcall_offset < -0x7ff * 4 || vcall_offset > 0x7ff * 4
2931 || (vcall_offset & 3) != 0)
2932 {
2933 asm_fprintf (file, "\tmov\tr16, %%low(%ld)\n", (long) vcall_offset);
2934 asm_fprintf (file, "\tmovt\tr16, %%high(%ld)\n", (long) vcall_offset);
2935 asm_fprintf (file, "\tldr\tip, [ip,r16]\n");
2936 }
2937 else
2938 asm_fprintf (file, "\tldr\tip, [ip,%d]\n", (int) vcall_offset / 4);
2939 asm_fprintf (file, "\tadd\t%s, %s, ip\n", this_name, this_name);
2940 }
2941
2942 fname = XSTR (XEXP (DECL_RTL (function), 0), 0);
2943 if (epiphany_is_long_call_p (XEXP (DECL_RTL (function), 0)))
2944 {
2945 fputs ("\tmov\tip,%low(", file);
2946 assemble_name (file, fname);
2947 fputs (")\n\tmovt\tip,%high(", file);
2948 assemble_name (file, fname);
2949 fputs (")\n\tjr ip\n", file);
2950 }
2951 else
2952 {
2953 fputs ("\tb\t", file);
2954 assemble_name (file, fname);
2955 fputc ('\n', file);
2956 }
2957 assemble_end_function (thunk, fnname);
2958 }
2959
2960 void
2961 epiphany_start_function (FILE *file, const char *name, tree decl)
2962 {
2963 /* If the function doesn't fit into the on-chip memory, it will have a
2964 section attribute - or lack of it - that denotes it goes somewhere else.
2965 But the architecture spec says that an interrupt vector still has to
2966 point to on-chip memory. So we must place a jump there to get to the
2967 actual function implementation. The forwarder_section attribute
2968 specifies the section where this jump goes.
2969 This mechanism can also be useful to have a shortcall destination for
2970 a function that is actually placed much farther away. */
2971 tree attrs, int_attr, int_names, int_name, forwarder_attr;
2972
2973 attrs = DECL_ATTRIBUTES (decl);
2974 int_attr = lookup_attribute ("interrupt", attrs);
2975 if (int_attr)
2976 for (int_names = TREE_VALUE (int_attr); int_names;
2977 int_names = TREE_CHAIN (int_names))
2978 {
2979 char buf[99];
2980
2981 int_name = TREE_VALUE (int_names);
2982 sprintf (buf, "ivt_entry_%.80s", TREE_STRING_POINTER (int_name));
2983 switch_to_section (get_section (buf, SECTION_CODE, decl));
2984 fputs ("\tb\t", file);
2985 assemble_name (file, name);
2986 fputc ('\n', file);
2987 }
2988 forwarder_attr = lookup_attribute ("forwarder_section", attrs);
2989 if (forwarder_attr)
2990 {
2991 const char *prefix = "__forwarder_dst_";
2992 char *dst_name = (char *) alloca (strlen (prefix) + strlen (name) + 1);
2993
2994 strcpy (dst_name, prefix);
2995 strcat (dst_name, name);
2996 forwarder_attr = TREE_VALUE (TREE_VALUE (forwarder_attr));
2997 switch_to_section (get_section (TREE_STRING_POINTER (forwarder_attr),
2998 SECTION_CODE, decl));
2999 ASM_OUTPUT_FUNCTION_LABEL (file, name, decl);
3000 if (epiphany_is_long_call_p (XEXP (DECL_RTL (decl), 0)))
3001 {
3002 int tmp = GPR_0;
3003
3004 if (int_attr)
3005 fputs ("\tstrd r0,[sp,-1]\n", file);
3006 else
3007 tmp = GPR_16;
3008 gcc_assert (call_used_or_fixed_reg_p (tmp));
3009 fprintf (file, "\tmov r%d,%%low(", tmp);
3010 assemble_name (file, dst_name);
3011 fprintf (file, ")\n"
3012 "\tmovt r%d,%%high(", tmp);
3013 assemble_name (file, dst_name);
3014 fprintf (file, ")\n"
3015 "\tjr r%d\n", tmp);
3016 }
3017 else
3018 {
3019 fputs ("\tb\t", file);
3020 assemble_name (file, dst_name);
3021 fputc ('\n', file);
3022 }
3023 name = dst_name;
3024 }
3025 switch_to_section (function_section (decl));
3026 ASM_OUTPUT_FUNCTION_LABEL (file, name, decl);
3027 }
3028
3029
3030 /* Implement TARGET_CONSTANT_ALIGNMENT. */
3031
3032 static HOST_WIDE_INT
3033 epiphany_constant_alignment (const_tree exp, HOST_WIDE_INT align)
3034 {
3035 if (TREE_CODE (exp) == STRING_CST)
3036 return MAX (align, FASTEST_ALIGNMENT);
3037 return align;
3038 }
3039
3040 /* Implement TARGET_STARTING_FRAME_OFFSET. */
3041
3042 static HOST_WIDE_INT
3043 epiphany_starting_frame_offset (void)
3044 {
3045 return epiphany_stack_offset;
3046 }
3047
3048 #undef TARGET_DOCUMENTATION_NAME
3049 #define TARGET_DOCUMENTATION_NAME "Epiphany"
3050
3051 struct gcc_target targetm = TARGET_INITIALIZER;