Debian Codegraph @

gcc/config/microblaze/microblaze.cc

raw
1 /* Subroutines used for code generation on Xilinx MicroBlaze.
2 Copyright (C) 2009-2025 Free Software Foundation, Inc.
3
4 Contributed by Michael Eager <[email protected]>.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published
10 by the Free Software Foundation; either version 3, or (at your
11 option) any later version.
12
13 GCC is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16 License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
21
22 #define IN_TARGET_CODE 1
23
24 #include "config.h"
25 #include "system.h"
26 #include "coretypes.h"
27 #include "backend.h"
28 #include "target.h"
29 #include "rtl.h"
30 #include "tree.h"
31 #include "stringpool.h"
32 #include "attribs.h"
33 #include "df.h"
34 #include "memmodel.h"
35 #include "tm_p.h"
36 #include "optabs.h"
37 #include "regs.h"
38 #include "emit-rtl.h"
39 #include "recog.h"
40 #include "cgraph.h"
41 #include "diagnostic-core.h"
42 #include "varasm.h"
43 #include "stor-layout.h"
44 #include "calls.h"
45 #include "explow.h"
46 #include "expr.h"
47 #include "reload.h"
48 #include "output.h"
49 #include "builtins.h"
50 #include "rtl-iter.h"
51 #include "cfgloop.h"
52 #include "insn-addr.h"
53 #include "cfgrtl.h"
54 #include "opts.h"
55
56 /* This file should be included last. */
57 #include "target-def.h"
58
59 #define MICROBLAZE_VERSION_COMPARE(VA,VB) strverscmp (VA, VB)
60
61 /* Classifies an address.
62
63 ADDRESS_INVALID
64 An invalid address.
65
66 ADDRESS_REG
67
68 A natural register or a register + const_int offset address.
69 The register satisfies microblaze_valid_base_register_p and the
70 offset is a const_arith_operand.
71
72 ADDRESS_REG_INDEX
73
74 A natural register offset by the index contained in an index register. The base
75 register satisfies microblaze_valid_base_register_p and the index register
76 satisfies microblaze_valid_index_register_p
77
78 ADDRESS_CONST_INT
79
80 A signed 16/32-bit constant address.
81
82 ADDRESS_SYMBOLIC:
83
84 A constant symbolic address or a (register + symbol). */
85
86 enum microblaze_address_type
87 {
88 ADDRESS_INVALID,
89 ADDRESS_REG,
90 ADDRESS_REG_INDEX,
91 ADDRESS_CONST_INT,
92 ADDRESS_SYMBOLIC,
93 ADDRESS_GOTOFF,
94 ADDRESS_PLT,
95 ADDRESS_TLS,
96 ADDRESS_SYMBOLIC_TXT_REL
97 };
98
99 /* Classifies symbols
100
101 SYMBOL_TYPE_GENERAL
102
103 A general symbol. */
104 enum microblaze_symbol_type
105 {
106 SYMBOL_TYPE_INVALID,
107 SYMBOL_TYPE_GENERAL
108 };
109
110 /* TLS Address Type. */
111 enum tls_reloc {
112 TLS_GD,
113 TLS_LDM,
114 TLS_DTPREL,
115 TLS_IE,
116 TLS_LE
117 };
118
119 /* Classification of a MicroBlaze address. */
120 struct microblaze_address_info
121 {
122 enum microblaze_address_type type;
123 rtx regA; /* Contains valid values on ADDRESS_REG, ADDRESS_REG_INDEX,
124 ADDRESS_SYMBOLIC. */
125 rtx regB; /* Contains valid values on ADDRESS_REG_INDEX. */
126 rtx offset; /* Contains valid values on ADDRESS_CONST_INT and ADDRESS_REG. */
127 rtx symbol; /* Contains valid values on ADDRESS_SYMBOLIC. */
128 enum microblaze_symbol_type symbol_type;
129 enum tls_reloc tls_type;
130 };
131
132 /* Structure to be filled in by compute_frame_size with register
133 save masks, and offsets for the current function. */
134
135 struct GTY(()) microblaze_frame_info {
136 long total_size; /* # bytes that the entire frame takes up. */
137 long var_size; /* # bytes that variables take up. */
138 long args_size; /* # bytes that outgoing arguments take up. */
139 int link_debug_size; /* # bytes for the link reg and back pointer. */
140 int gp_reg_size; /* # bytes needed to store gp regs. */
141 long gp_offset; /* offset from new sp to store gp registers. */
142 long mask; /* mask of saved gp registers. */
143 int initialized; /* != 0 if frame size already calculated. */
144 int num_gp; /* number of gp registers saved. */
145 long insns_len; /* length of insns. */
146 int alloc_stack; /* Flag to indicate if the current function
147 must not create stack space. (As an optimization). */
148 };
149
150 /* Global variables for machine-dependent things. */
151
152 /* Toggle which pipleline interface to use. */
153 static GTY(()) int microblaze_sched_use_dfa = 0;
154
155 /* Threshold for data being put into the small data/bss area, instead
156 of the normal data area (references to the small data/bss area take
157 1 instruction, and use the global pointer, references to the normal
158 data area takes 2 instructions). */
159 int microblaze_section_threshold = -1;
160
161 /* Prevent scheduling potentially exception causing instructions in
162 delay slots. -mcpu=v3.00.a or v4.00.a turns this on. */
163 int microblaze_no_unsafe_delay;
164
165 /* Set to one if the targeted core has the CLZ insn. */
166 int microblaze_has_clz = 0;
167
168 /* Which CPU pipeline do we use. We haven't really standardized on a CPU
169 version having only a particular type of pipeline. There can still be
170 options on the CPU to scale pipeline features up or down. :(
171 Bad Presentation (??), so we let the MD file rely on the value of
172 this variable instead Making PIPE_5 the default. It should be backward
173 optimal with PIPE_3 MicroBlazes. */
174 enum pipeline_type microblaze_pipe = MICROBLAZE_PIPE_5;
175
176 /* High and low marks for floating point values which we will accept
177 as legitimate constants for TARGET_LEGITIMATE_CONSTANT_P. These are
178 initialized in override_options. */
179 REAL_VALUE_TYPE dfhigh, dflow, sfhigh, sflow;
180
181 /* Array giving truth value on whether or not a given hard register
182 can support a given mode. */
183 static char microblaze_hard_regno_mode_ok_p[(int)MAX_MACHINE_MODE]
184 [FIRST_PSEUDO_REGISTER];
185
186 /* Current frame information calculated by compute_frame_size. */
187 struct microblaze_frame_info current_frame_info;
188
189 /* Zero structure to initialize current_frame_info. */
190 struct microblaze_frame_info zero_frame_info;
191
192 /* List of all MICROBLAZE punctuation characters used by print_operand. */
193 char microblaze_print_operand_punct[256];
194
195 /* Map GCC register number to debugger register number. */
196 int microblaze_debugger_regno[FIRST_PSEUDO_REGISTER];
197
198 /* Map hard register number to register class. */
199 enum reg_class microblaze_regno_to_class[] =
200 {
201 GR_REGS, GR_REGS, GR_REGS, GR_REGS,
202 GR_REGS, GR_REGS, GR_REGS, GR_REGS,
203 GR_REGS, GR_REGS, GR_REGS, GR_REGS,
204 GR_REGS, GR_REGS, GR_REGS, GR_REGS,
205 GR_REGS, GR_REGS, GR_REGS, GR_REGS,
206 GR_REGS, GR_REGS, GR_REGS, GR_REGS,
207 GR_REGS, GR_REGS, GR_REGS, GR_REGS,
208 GR_REGS, GR_REGS, GR_REGS, GR_REGS,
209 ST_REGS, GR_REGS, GR_REGS, GR_REGS
210 };
211
212 /* MicroBlaze specific machine attributes.
213 interrupt_handler - Interrupt handler attribute to add interrupt prologue
214 and epilogue and use appropriate interrupt return.
215 save_volatiles - Similar to interrupt handler, but use normal return. */
216 int interrupt_handler;
217 int break_handler;
218 int fast_interrupt;
219 int save_volatiles;
220
221 TARGET_GNU_ATTRIBUTES (microblaze_attribute_table, {
222 /* name min_len, max_len, decl_req, type_req, fn_type_req,
223 affects_type_identity, handler, exclude */
224 {"interrupt_handler", 0, 0, true, false, false, false, NULL, NULL },
225 {"break_handler", 0, 0, true, false, false, false, NULL, NULL },
226 {"fast_interrupt", 0, 0, true, false, false, false, NULL, NULL },
227 {"save_volatiles", 0, 0, true, false, false, false, NULL, NULL }
228 });
229
230 static int microblaze_interrupt_function_p (tree);
231
232 static void microblaze_elf_asm_constructor (rtx, int) ATTRIBUTE_UNUSED;
233 static void microblaze_elf_asm_destructor (rtx, int) ATTRIBUTE_UNUSED;
234
235 section *sdata2_section;
236
237 #ifdef HAVE_AS_TLS
238 #undef TARGET_HAVE_TLS
239 #define TARGET_HAVE_TLS true
240 #endif
241
242 /* MicroBlaze does not do speculative execution. */
243 #undef TARGET_HAVE_SPECULATION_SAFE_VALUE
244 #define TARGET_HAVE_SPECULATION_SAFE_VALUE speculation_safe_value_not_needed
245
246 /* Return truth value if a CONST_DOUBLE is ok to be a legitimate constant. */
247 static bool
248 microblaze_const_double_ok (rtx op, machine_mode mode)
249 {
250 REAL_VALUE_TYPE d;
251
252 if (GET_CODE (op) != CONST_DOUBLE)
253 return 0;
254
255 if (GET_MODE (op) == VOIDmode)
256 return 1;
257
258 if (mode != SFmode && mode != DFmode)
259 return 0;
260
261 if (op == CONST0_RTX (mode))
262 return 1;
263
264 d = *CONST_DOUBLE_REAL_VALUE (op);
265
266 if (REAL_VALUE_ISNAN (d))
267 return FALSE;
268
269 if (REAL_VALUE_NEGATIVE (d))
270 d = real_value_negate (&d);
271
272 if (mode == DFmode)
273 {
274 if (real_less (&d, &dfhigh) && real_less (&dflow, &d))
275 return 1;
276 }
277 else
278 {
279 if (real_less (&d, &sfhigh) && real_less (&sflow, &d))
280 return 1;
281 }
282
283 return 0;
284 }
285
286 /* Return truth value if a memory operand fits in a single instruction
287 (ie, register + small offset) or (register + register). */
288
289 int
290 simple_memory_operand (rtx op, machine_mode mode ATTRIBUTE_UNUSED)
291 {
292 rtx addr, plus0, plus1;
293
294 /* Eliminate non-memory operations. */
295 if (GET_CODE (op) != MEM)
296 return 0;
297
298 /* dword operations really put out 2 instructions, so eliminate them. */
299 /* ??? This isn't strictly correct. It is OK to accept multiword modes
300 here, since the length attributes are being set correctly, but only
301 if the address is offsettable. */
302 if (GET_MODE_SIZE (GET_MODE (op)) > UNITS_PER_WORD)
303 return 0;
304
305
306 /* Decode the address now. */
307 addr = XEXP (op, 0);
308 switch (GET_CODE (addr))
309
310 {
311 case REG:
312 return 1;
313
314 case PLUS:
315 plus0 = XEXP (addr, 0);
316 plus1 = XEXP (addr, 1);
317
318 if (GET_CODE (plus0) != REG)
319 return 0;
320
321 if (GET_CODE (plus0) == REG && GET_CODE (plus1) == CONST_INT
322 && SMALL_INT (plus1))
323 {
324 return 1;
325 }
326 else if (GET_CODE (plus1) == REG && GET_CODE (plus0) == CONST_INT)
327 {
328 return 1;
329 }
330 else if (GET_CODE (plus0) == REG && GET_CODE (plus1) == REG)
331 {
332 return 1;
333 }
334 else
335 return 0;
336
337 case SYMBOL_REF:
338 return 0;
339
340 default:
341 break;
342 }
343
344 return 0;
345 }
346
347 /* Return nonzero for a memory address that can be used to load or store
348 a doubleword. */
349
350 int
351 double_memory_operand (rtx op, machine_mode mode)
352 {
353 rtx addr;
354
355 if (GET_CODE (op) != MEM || !memory_operand (op, mode))
356 {
357 /* During reload, we accept a pseudo register if it has an
358 appropriate memory address. If we don't do this, we will
359 wind up reloading into a register, and then reloading that
360 register from memory, when we could just reload directly from
361 memory. */
362 if (reload_in_progress
363 && GET_CODE (op) == REG
364 && REGNO (op) >= FIRST_PSEUDO_REGISTER
365 && reg_renumber[REGNO (op)] < 0
366 && reg_equiv_mem (REGNO (op)) != 0
367 && double_memory_operand (reg_equiv_mem (REGNO (op)), mode))
368 return 1;
369 return 0;
370 }
371
372 /* Make sure that 4 added to the address is a valid memory address.
373 This essentially just checks for overflow in an added constant. */
374
375 addr = XEXP (op, 0);
376
377 if (CONSTANT_ADDRESS_P (addr))
378 return 1;
379
380 return memory_address_p ((GET_MODE_CLASS (mode) == MODE_INT
381 ? E_SImode : E_SFmode),
382 plus_constant (Pmode, addr, 4));
383 }
384
385 /* Implement REG_OK_FOR_BASE_P -and- REG_OK_FOR_INDEX_P. */
386 int
387 microblaze_regno_ok_for_base_p (int regno, int strict)
388 {
389 if (regno >= FIRST_PSEUDO_REGISTER)
390 {
391 if (!strict)
392 return true;
393 regno = reg_renumber[regno];
394 }
395
396 /* These fake registers will be eliminated to either the stack or
397 hard frame pointer, both of which are usually valid base registers.
398 Reload deals with the cases where the eliminated form isn't valid. */
399 if (regno == ARG_POINTER_REGNUM || regno == FRAME_POINTER_REGNUM)
400 return true;
401
402 return GP_REG_P (regno);
403 }
404
405 /* Return true if X is a valid base register for the given mode.
406 Allow only hard registers if STRICT. */
407
408 static bool
409 microblaze_valid_base_register_p (rtx x,
410 machine_mode mode ATTRIBUTE_UNUSED,
411 int strict)
412 {
413 if (!strict && GET_CODE (x) == SUBREG)
414 x = SUBREG_REG (x);
415
416 return (GET_CODE (x) == REG
417 && microblaze_regno_ok_for_base_p (REGNO (x), strict));
418 }
419
420 /* Build the SYMBOL_REF for __tls_get_addr. */
421
422 static GTY(()) rtx tls_get_addr_libfunc;
423
424 static rtx
425 get_tls_get_addr (void)
426 {
427 if (!tls_get_addr_libfunc)
428 tls_get_addr_libfunc = init_one_libfunc ("__tls_get_addr");
429 return tls_get_addr_libfunc;
430 }
431
432 /* Return TRUE if X is a thread-local symbol. */
433 bool
434 microblaze_tls_symbol_p (rtx x)
435 {
436 if (!TARGET_HAVE_TLS)
437 return false;
438
439 if (GET_CODE (x) != SYMBOL_REF)
440 return false;
441
442 return SYMBOL_REF_TLS_MODEL (x) != 0;
443 }
444
445 /* Return TRUE if X contains any TLS symbol references. */
446
447 bool
448 microblaze_tls_referenced_p (rtx x)
449 {
450 if (!TARGET_HAVE_TLS)
451 return false;
452 subrtx_iterator::array_type array;
453 FOR_EACH_SUBRTX (iter, array, x, ALL)
454 {
455 const_rtx x = *iter;
456 if (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (x) != 0)
457 return true;
458 /* Don't recurse into UNSPEC_TLS looking for TLS symbols; these are
459 TLS offsets, not real symbol references. */
460 if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_TLS)
461 iter.skip_subrtxes ();
462 }
463 return false;
464 }
465
466 bool
467 microblaze_cannot_force_const_mem (machine_mode mode ATTRIBUTE_UNUSED, rtx x)
468 {
469 return microblaze_tls_referenced_p(x);
470 }
471
472 /* Return TRUE if X references a SYMBOL_REF. */
473 int
474 symbol_mentioned_p (rtx x)
475 {
476 const char * fmt;
477 int i;
478
479 if (GET_CODE (x) == SYMBOL_REF)
480 return 1;
481
482 /* UNSPEC entries for a symbol include the SYMBOL_REF, but they
483 are constant offsets, not symbols. */
484 if (GET_CODE (x) == UNSPEC)
485 return 0;
486
487 fmt = GET_RTX_FORMAT (GET_CODE (x));
488
489 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
490 {
491 if (fmt[i] == 'E')
492 {
493 int j;
494
495 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
496 if (symbol_mentioned_p (XVECEXP (x, i, j)))
497 return 1;
498 }
499 else if (fmt[i] == 'e' && symbol_mentioned_p (XEXP (x, i)))
500 return 1;
501 }
502
503 return 0;
504 }
505
506 /* Return TRUE if X references a LABEL_REF. */
507 int
508 label_mentioned_p (rtx x)
509 {
510 const char * fmt;
511 int i;
512
513 if (GET_CODE (x) == LABEL_REF)
514 return 1;
515
516 /* UNSPEC entries for a symbol include a LABEL_REF for the referencing
517 instruction, but they are constant offsets, not symbols. */
518 if (GET_CODE (x) == UNSPEC)
519 return 0;
520
521 fmt = GET_RTX_FORMAT (GET_CODE (x));
522 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
523 {
524 if (fmt[i] == 'E')
525 {
526 int j;
527
528 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
529 if (label_mentioned_p (XVECEXP (x, i, j)))
530 return 1;
531 }
532 else if (fmt[i] == 'e' && label_mentioned_p (XEXP (x, i)))
533 return 1;
534 }
535
536 return 0;
537 }
538
539 int
540 tls_mentioned_p (rtx x)
541 {
542 switch (GET_CODE (x))
543 {
544 case CONST:
545 return tls_mentioned_p (XEXP (x, 0));
546
547 case UNSPEC:
548 if (XINT (x, 1) == UNSPEC_TLS)
549 return 1;
550 return 0;
551
552 default:
553 return 0;
554 }
555 }
556
557 static rtx
558 load_tls_operand (rtx x, rtx reg)
559 {
560 rtx tmp;
561
562 if (reg == NULL_RTX)
563 reg = gen_reg_rtx (Pmode);
564
565 tmp = gen_rtx_CONST (Pmode, x);
566
567 emit_insn (gen_rtx_SET (reg,
568 gen_rtx_PLUS (Pmode, pic_offset_table_rtx, tmp)));
569
570 return reg;
571 }
572
573 static rtx_insn *
574 microblaze_call_tls_get_addr (rtx x, rtx reg, rtx *valuep, int reloc)
575 {
576 rtx_insn *insns;
577 rtx tls_entry;
578
579 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
580
581 start_sequence ();
582
583 tls_entry = gen_rtx_UNSPEC (Pmode, gen_rtvec (2, x, GEN_INT (reloc)),
584 UNSPEC_TLS);
585
586 reg = load_tls_operand (tls_entry, reg);
587
588 *valuep = emit_library_call_value (get_tls_get_addr (), NULL_RTX,
589 LCT_PURE, /* LCT_CONST? */
590 Pmode, reg, Pmode);
591
592 insns = get_insns ();
593 end_sequence ();
594
595 return insns;
596 }
597
598 rtx
599 microblaze_legitimize_tls_address(rtx x, rtx reg)
600 {
601 rtx dest, ret, eqv, addend;
602 rtx_insn *insns;
603 enum tls_model model;
604 model = SYMBOL_REF_TLS_MODEL (x);
605
606 switch (model)
607 {
608 case TLS_MODEL_LOCAL_DYNAMIC:
609 case TLS_MODEL_GLOBAL_DYNAMIC:
610 case TLS_MODEL_INITIAL_EXEC:
611 insns = microblaze_call_tls_get_addr (x, reg, &ret, TLS_GD);
612 dest = gen_reg_rtx (Pmode);
613 emit_libcall_block (insns, dest, ret, x);
614 break;
615
616 case TLS_MODEL_LOCAL_EXEC:
617 insns = microblaze_call_tls_get_addr (x, reg, &ret, TLS_LDM);
618
619 /* Attach a unique REG_EQUIV, to allow the RTL optimizers to
620 share the LDM result with other LD model accesses. */
621 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const1_rtx), UNSPEC_TLS);
622 dest = gen_reg_rtx (Pmode);
623 emit_libcall_block (insns, dest, ret, eqv);
624
625 /* Load the addend. */
626 addend = gen_rtx_UNSPEC (Pmode, gen_rtvec (2, x, GEN_INT (TLS_DTPREL)),
627 UNSPEC_TLS);
628 addend = force_reg (SImode, gen_rtx_CONST (SImode, addend));
629 dest = gen_rtx_PLUS (Pmode, dest, addend);
630 break;
631
632 default:
633 gcc_unreachable ();
634 }
635 return dest;
636 }
637
638 static bool
639 microblaze_classify_unspec (struct microblaze_address_info *info, rtx x)
640 {
641 info->symbol_type = SYMBOL_TYPE_GENERAL;
642 info->symbol = XVECEXP (x, 0, 0);
643
644 if (XINT (x, 1) == UNSPEC_GOTOFF)
645 {
646 info->regA = gen_rtx_REG (SImode, PIC_OFFSET_TABLE_REGNUM);
647 info->type = ADDRESS_GOTOFF;
648 }
649 else if (XINT (x, 1) == UNSPEC_PLT)
650 {
651 info->type = ADDRESS_PLT;
652 }
653 else if (XINT (x, 1) == UNSPEC_TLS)
654 {
655 info->type = ADDRESS_TLS;
656 info->tls_type = tls_reloc (INTVAL (XVECEXP (x, 0, 1)));
657 }
658 else if (XINT (x, 1) == UNSPEC_TEXT)
659 {
660 info->type = ADDRESS_SYMBOLIC_TXT_REL;
661 }
662 else
663 {
664 return false;
665 }
666 return true;
667 }
668
669
670 /* Return true if X is a valid index register for the given mode.
671 Allow only hard registers if STRICT. */
672
673 static bool
674 microblaze_valid_index_register_p (rtx x,
675 machine_mode mode ATTRIBUTE_UNUSED,
676 int strict)
677 {
678 if (!strict && GET_CODE (x) == SUBREG)
679 x = SUBREG_REG (x);
680
681 return (GET_CODE (x) == REG
682 /* A base register is good enough to be an index register on MicroBlaze. */
683 && microblaze_regno_ok_for_base_p (REGNO (x), strict));
684 }
685
686 /* Get the base register for accessing a value from the memory or
687 Symbol ref. Used for MicroBlaze Small Data Area Pointer Optimization. */
688 static int
689 get_base_reg (rtx x)
690 {
691 tree decl;
692 int base_reg;
693
694 if (!flag_pic || microblaze_tls_symbol_p(x))
695 base_reg = MB_ABI_BASE_REGNUM;
696 else if (flag_pic)
697 base_reg = MB_ABI_PIC_ADDR_REGNUM;
698
699 if (TARGET_XLGPOPT
700 && GET_CODE (x) == SYMBOL_REF
701 && SYMBOL_REF_SMALL_P (x) && (decl = SYMBOL_REF_DECL (x)) != NULL)
702 {
703 if (TREE_READONLY (decl))
704 base_reg = MB_ABI_GPRO_REGNUM;
705 else
706 base_reg = MB_ABI_GPRW_REGNUM;
707 }
708
709 return base_reg;
710 }
711
712 /* Return true if X is a valid address for machine mode MODE. If it is,
713 fill in INFO appropriately.
714 STRICT > 0 if we should only accept hard base registers.
715 STRICT = 2 if the operand address is being printed thus
716 function has been called by print_operand_address.
717
718 type regA regB offset symbol
719
720 ADDRESS_INVALID NULL NULL NULL NULL
721
722 ADDRESS_REG %0 NULL const_0 / NULL
723 const_int
724 ADDRESS_REG_INDEX %0 %1 NULL NULL
725
726 ADDRESS_SYMBOLIC r0 / NULL NULL symbol
727 sda_base_reg
728
729 ADDRESS_CONST_INT r0 NULL const NULL
730
731 For modes spanning multiple registers (DFmode in 32-bit GPRs,
732 DImode, TImode), indexed addressing cannot be used because
733 adjacent memory cells are accessed by adding word-sized offsets
734 during assembly output. */
735
736 static bool
737 microblaze_classify_address (struct microblaze_address_info *info, rtx x,
738 machine_mode mode, int strict)
739 {
740 rtx xplus0;
741 rtx xplus1;
742 rtx offset;
743
744 info->type = ADDRESS_INVALID;
745 info->regA = NULL;
746 info->regB = NULL;
747 info->offset = NULL;
748 info->symbol = NULL;
749 info->symbol_type = SYMBOL_TYPE_INVALID;
750 offset = NULL;
751
752 switch (GET_CODE (x))
753 {
754 case REG:
755 case SUBREG:
756 {
757 info->type = ADDRESS_REG;
758 info->regA = x;
759 info->offset = const0_rtx;
760 return microblaze_valid_base_register_p (info->regA, mode, strict);
761 }
762 case PLUS:
763 {
764 xplus0 = XEXP (x, 0);
765 xplus1 = XEXP (x, 1);
766
767 if (microblaze_valid_base_register_p (xplus0, mode, strict))
768 {
769 info->type = ADDRESS_REG;
770 info->regA = xplus0;
771
772 if (GET_CODE (xplus1) == CONST_INT)
773 {
774 info->offset = xplus1;
775 return true;
776 }
777 else if (GET_CODE (xplus1) == UNSPEC)
778 {
779 /* Need offsettable address. */
780 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
781 return false;
782
783 return microblaze_classify_unspec (info, xplus1);
784 }
785 else if ((GET_CODE (xplus1) == SYMBOL_REF ||
786 GET_CODE (xplus1) == LABEL_REF))
787 {
788 if (flag_pic == 2 || microblaze_tls_symbol_p(xplus1))
789 return false;
790 info->type = ADDRESS_SYMBOLIC;
791 info->symbol = xplus1;
792 info->symbol_type = SYMBOL_TYPE_GENERAL;
793 return true;
794 }
795 else if (GET_CODE (xplus1) == CONST)
796 {
797 rtx xconst0 = XEXP(xplus1, 0);
798
799 /* base + unspec. */
800 if (GET_CODE (xconst0) == UNSPEC)
801 {
802 /* Need offsettable address. */
803 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
804 return false;
805 return microblaze_classify_unspec(info, xconst0);
806 }
807
808 /* for (plus x const_int) just look at x. */
809 if (GET_CODE (xconst0) == PLUS
810 && GET_CODE (XEXP (xconst0, 1)) == CONST_INT
811 && (SMALL_INT (XEXP (xconst0, 1))
812 || GET_CODE (XEXP (xconst0, 0)) == UNSPEC))
813 {
814 /* Hold CONST_INT Value in offset in case of
815 UNSPEC + CONST_INT. */
816 offset = XEXP (xconst0, 1);
817
818 /* This is ok as info->symbol is set to xplus1 the full
819 const-expression below. */
820 xconst0 = XEXP (xconst0, 0);
821 }
822
823 if (GET_CODE (xconst0) == SYMBOL_REF
824 || GET_CODE (xconst0) == LABEL_REF)
825 {
826 if (flag_pic == 2 || microblaze_tls_symbol_p(xconst0))
827 return false;
828
829 info->type = ADDRESS_SYMBOLIC;
830 info->symbol = xplus1;
831 info->symbol_type = SYMBOL_TYPE_GENERAL;
832 return true;
833 }
834
835 if (GET_CODE (xconst0) == UNSPEC && TARGET_PIC_DATA_TEXT_REL)
836 {
837 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
838 return false;
839
840 info->offset = offset;
841 return microblaze_classify_unspec (info, xconst0);
842 }
843
844 /* Not base + symbol || base + UNSPEC. */
845 return false;
846
847 }
848 else if (GET_CODE (xplus1) == REG
849 && microblaze_valid_index_register_p (xplus1, mode,
850 strict)
851 && (GET_MODE_SIZE (mode) <= UNITS_PER_WORD))
852 {
853 /* Restrict larger than word-width modes from using an index register. */
854 info->type = ADDRESS_REG_INDEX;
855 info->regB = xplus1;
856 return true;
857 }
858 }
859 break;
860 }
861 case CONST_INT:
862 {
863 info->regA = gen_raw_REG (mode, 0);
864 info->type = ADDRESS_CONST_INT;
865 info->offset = x;
866 return true;
867 }
868 case CONST:
869 case LABEL_REF:
870 case SYMBOL_REF:
871 {
872 info->type = ADDRESS_SYMBOLIC;
873 info->symbol_type = SYMBOL_TYPE_GENERAL;
874 info->symbol = x;
875 info->regA = gen_raw_REG (mode, get_base_reg (x));
876
877 if (GET_CODE (x) == CONST)
878 {
879 if (GET_CODE (XEXP (x, 0)) == UNSPEC)
880 {
881 info->regA = gen_raw_REG (mode,
882 get_base_reg (XVECEXP (XEXP (x,0), 0, 0)));
883 return microblaze_classify_unspec (info, XEXP (x, 0));
884 }
885 return !(flag_pic && pic_address_needs_scratch (x));
886 }
887
888 /* Avoid error in print_operand_address in case UNSPEC
889 is removed from SYMBOL or LABEL REFS during optimization. */
890 if ((GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF)
891 && flag_pic && TARGET_PIC_DATA_TEXT_REL && strict == 2)
892 {
893 info->type = ADDRESS_SYMBOLIC_TXT_REL;
894 return true;
895 }
896
897 if (flag_pic == 2)
898 return false;
899 else if (microblaze_tls_symbol_p(x))
900 return false;
901
902 return true;
903 }
904
905 case UNSPEC:
906 {
907 if (reload_in_progress)
908 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
909 return microblaze_classify_unspec (info, x);
910 }
911
912 default:
913 return false;
914 }
915
916 return false;
917 }
918
919 /* This function is used to implement GO_IF_LEGITIMATE_ADDRESS. It
920 returns a nonzero value if X is a legitimate address for a memory
921 operand of the indicated MODE. STRICT is nonzero if this function
922 is called during reload. */
923
924 bool
925 microblaze_legitimate_address_p (machine_mode mode, rtx x, bool strict,
926 code_helper)
927 {
928 struct microblaze_address_info addr;
929
930 return microblaze_classify_address (&addr, x, mode, strict);
931 }
932
933 bool
934 microblaze_constant_address_p (rtx x)
935 {
936 return ((GET_CODE (x) == LABEL_REF) || (GET_CODE (x) == SYMBOL_REF)
937 || GET_CODE (x) == CONST_INT
938 || (GET_CODE (x) == CONST
939 && ! (flag_pic && pic_address_needs_scratch (x))));
940 }
941
942 int
943 microblaze_valid_pic_const (rtx x)
944 {
945 switch (GET_CODE (x))
946 {
947 case CONST:
948 case CONST_INT:
949 case CONST_DOUBLE:
950 return true;
951 default:
952 return false;
953 }
954 }
955
956 int
957 microblaze_legitimate_pic_operand (rtx x)
958 {
959 if (flag_pic == 2 && (symbol_mentioned_p (x) || label_mentioned_p (x))
960 && !(TARGET_PIC_DATA_TEXT_REL && call_insn_operand (x,VOIDmode)))
961 return 0;
962
963 if (microblaze_tls_referenced_p(x))
964 return 0;
965
966 return 1;
967 }
968
969 /* Try machine-dependent ways of modifying an illegitimate address
970 to be legitimate. If we find one, return the new, valid address.
971 This is used from only one place: `memory_address' in explow.cc.
972
973 OLDX is the address as it was before break_out_memory_refs was
974 called. In some cases it is useful to look at this to decide what
975 needs to be done.
976
977 It is always safe for this function to do nothing. It exists to
978 recognize opportunities to optimize the output.
979
980 For the MicroBlaze, transform:
981
982 memory(X + <large int>)
983
984 into:
985
986 Y = <large int> & ~0x7fff;
987 Z = X + Y
988 memory (Z + (<large int> & 0x7fff));
989
990 This is for CSE to find several similar references, and only use one Z.
991
992 When PIC, convert addresses of the form memory (symbol+large int) to
993 memory (reg+large int). */
994
995 static rtx
996 microblaze_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
997 machine_mode mode ATTRIBUTE_UNUSED)
998 {
999 rtx xinsn = x, result;
1000
1001 if (GET_CODE (xinsn) == CONST
1002 && flag_pic && pic_address_needs_scratch (xinsn))
1003 {
1004 rtx ptr_reg = gen_reg_rtx (Pmode);
1005 rtx constant = XEXP (XEXP (xinsn, 0), 1);
1006
1007 emit_move_insn (ptr_reg, XEXP (XEXP (xinsn, 0), 0));
1008
1009 result = gen_rtx_PLUS (Pmode, ptr_reg, constant);
1010 if (SMALL_INT (constant))
1011 return result;
1012 /* Otherwise we fall through so the code below will fix the
1013 constant. */
1014 xinsn = result;
1015 }
1016
1017 if (GET_CODE (xinsn) == PLUS)
1018 {
1019 rtx xplus0 = XEXP (xinsn, 0);
1020 rtx xplus1 = XEXP (xinsn, 1);
1021 enum rtx_code code0 = GET_CODE (xplus0);
1022 enum rtx_code code1 = GET_CODE (xplus1);
1023
1024 if (code0 != REG && code1 == REG)
1025 {
1026 xplus0 = XEXP (xinsn, 1);
1027 xplus1 = XEXP (xinsn, 0);
1028 code0 = GET_CODE (xplus0);
1029 code1 = GET_CODE (xplus1);
1030 }
1031
1032 if (code0 == REG && REG_OK_FOR_BASE_P (xplus0)
1033 && code1 == CONST_INT && !SMALL_INT (xplus1))
1034 {
1035 rtx int_reg = gen_reg_rtx (Pmode);
1036 rtx ptr_reg = gen_reg_rtx (Pmode);
1037
1038 emit_move_insn (int_reg, GEN_INT (INTVAL (xplus1) & ~0x7fff));
1039
1040 emit_insn (gen_rtx_SET (ptr_reg,
1041 gen_rtx_PLUS (Pmode, xplus0, int_reg)));
1042
1043 result = gen_rtx_PLUS (Pmode, ptr_reg,
1044 GEN_INT (INTVAL (xplus1) & 0x7fff));
1045 return result;
1046 }
1047
1048 if (code0 == REG && REG_OK_FOR_BASE_P (xplus0))
1049 {
1050 if (reload_in_progress)
1051 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
1052 if (code1 == CONST)
1053 {
1054 xplus1 = XEXP (xplus1, 0);
1055 code1 = GET_CODE (xplus1);
1056 }
1057 if (code1 == SYMBOL_REF)
1058 {
1059 if (microblaze_tls_symbol_p(xplus1))
1060 {
1061 rtx tls_ref, reg;
1062 reg = gen_reg_rtx (Pmode);
1063
1064 tls_ref = microblaze_legitimize_tls_address (xplus1,
1065 NULL_RTX);
1066 emit_move_insn (reg, tls_ref);
1067
1068 result = gen_rtx_PLUS (Pmode, xplus0, reg);
1069
1070 return result;
1071 }
1072 else if (flag_pic == 2)
1073 {
1074 if (!TARGET_PIC_DATA_TEXT_REL)
1075 {
1076 rtx pic_ref, reg;
1077 reg = gen_reg_rtx (Pmode);
1078
1079 pic_ref = gen_rtx_UNSPEC (Pmode,
1080 gen_rtvec (1, xplus1),
1081 UNSPEC_GOTOFF);
1082 pic_ref = gen_rtx_CONST (Pmode, pic_ref);
1083 pic_ref = gen_rtx_PLUS (Pmode,
1084 pic_offset_table_rtx, pic_ref);
1085 pic_ref = gen_const_mem (Pmode, pic_ref);
1086 emit_move_insn (reg, pic_ref);
1087 result = gen_rtx_PLUS (Pmode, xplus0, reg);
1088 return result;
1089 }
1090 else
1091 {
1092 rtx pic_ref, reg;
1093 reg = gen_reg_rtx (Pmode);
1094 pic_ref = gen_rtx_UNSPEC (Pmode,
1095 gen_rtvec (1, xplus1),
1096 UNSPEC_TEXT);
1097 pic_ref = gen_rtx_CONST (Pmode, pic_ref);
1098 emit_insn (gen_addsi3 (reg,
1099 pic_offset_table_rtx, xplus0));
1100 result = gen_rtx_PLUS (Pmode, reg, pic_ref);
1101 return result;
1102 }
1103 }
1104 }
1105 }
1106 }
1107
1108 if (GET_CODE (xinsn) == SYMBOL_REF)
1109 {
1110 rtx reg = NULL;
1111 if (microblaze_tls_symbol_p(xinsn))
1112 {
1113 reg = microblaze_legitimize_tls_address (xinsn, NULL_RTX);
1114 }
1115 else if (flag_pic == 2)
1116 {
1117 if (reload_in_progress)
1118 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
1119
1120 if (!TARGET_PIC_DATA_TEXT_REL)
1121 {
1122 rtx pic_ref;
1123
1124 pic_ref = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, xinsn), UNSPEC_GOTOFF);
1125 pic_ref = gen_rtx_CONST (Pmode, pic_ref);
1126 pic_ref = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, pic_ref);
1127 pic_ref = gen_const_mem (Pmode, pic_ref);
1128 reg = pic_ref;
1129 }
1130 else
1131 {
1132 rtx pic_ref;
1133
1134 pic_ref = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, xinsn), UNSPEC_TEXT);
1135 pic_ref = gen_rtx_CONST (Pmode, pic_ref);
1136 pic_ref = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, pic_ref);
1137 reg = pic_ref;
1138 }
1139 }
1140 else
1141 {
1142 /* This should never happen. */
1143 gcc_unreachable ();
1144 }
1145 return reg;
1146 }
1147
1148 return x;
1149 }
1150
1151 /* Block Moves. */
1152
1153 #define MAX_MOVE_REGS 8
1154 #define MAX_MOVE_BYTES (MAX_MOVE_REGS * UNITS_PER_WORD)
1155
1156 /* Emit straight-line code to move LENGTH bytes from SRC to DEST.
1157 Assume that the areas do not overlap. */
1158
1159 static void
1160 microblaze_block_move_straight (rtx dest, rtx src, HOST_WIDE_INT length)
1161 {
1162 HOST_WIDE_INT offset, delta;
1163 unsigned HOST_WIDE_INT bits;
1164 int i;
1165 machine_mode mode;
1166 rtx *regs;
1167
1168 bits = BITS_PER_WORD;
1169 mode = int_mode_for_size (bits, 0).require ();
1170 delta = bits / BITS_PER_UNIT;
1171
1172 /* Allocate a buffer for the temporary registers. */
1173 regs = XALLOCAVEC (rtx, length / delta);
1174
1175 /* Load as many BITS-sized chunks as possible. Use a normal load if
1176 the source has enough alignment, otherwise use left/right pairs. */
1177 for (offset = 0, i = 0; offset + delta <= length; offset += delta, i++)
1178 {
1179 regs[i] = gen_reg_rtx (mode);
1180 emit_move_insn (regs[i], adjust_address (src, mode, offset));
1181 }
1182
1183 /* Copy the chunks to the destination. */
1184 for (offset = 0, i = 0; offset + delta <= length; offset += delta, i++)
1185 emit_move_insn (adjust_address (dest, mode, offset), regs[i]);
1186
1187 /* Mop up any left-over bytes. */
1188 if (offset < length)
1189 {
1190 src = adjust_address (src, BLKmode, offset);
1191 dest = adjust_address (dest, BLKmode, offset);
1192 move_by_pieces (dest, src, length - offset,
1193 MIN (MEM_ALIGN (src), MEM_ALIGN (dest)), RETURN_BEGIN);
1194 }
1195 }
1196
1197 /* Helper function for doing a loop-based block operation on memory
1198 reference MEM. Each iteration of the loop will operate on LENGTH
1199 bytes of MEM.
1200
1201 Create a new base register for use within the loop and point it to
1202 the start of MEM. Create a new memory reference that uses this
1203 register. Store them in *LOOP_REG and *LOOP_MEM respectively. */
1204
1205 static void
1206 microblaze_adjust_block_mem (rtx mem, HOST_WIDE_INT length,
1207 rtx * loop_reg, rtx * loop_mem)
1208 {
1209 *loop_reg = copy_addr_to_reg (XEXP (mem, 0));
1210
1211 /* Although the new mem does not refer to a known location,
1212 it does keep up to LENGTH bytes of alignment. */
1213 *loop_mem = change_address (mem, BLKmode, *loop_reg);
1214 set_mem_align (*loop_mem,
1215 MIN ((HOST_WIDE_INT) MEM_ALIGN (mem),
1216 length * BITS_PER_UNIT));
1217 }
1218
1219
1220 /* Move LENGTH bytes from SRC to DEST using a loop that moves MAX_MOVE_BYTES
1221 per iteration. LENGTH must be at least MAX_MOVE_BYTES. Assume that the
1222 memory regions do not overlap. */
1223
1224 static void
1225 microblaze_block_move_loop (rtx dest, rtx src, HOST_WIDE_INT length)
1226 {
1227 rtx_code_label *label;
1228 rtx src_reg, dest_reg, final_src;
1229 HOST_WIDE_INT leftover;
1230
1231 leftover = length % MAX_MOVE_BYTES;
1232 length -= leftover;
1233
1234 /* Create registers and memory references for use within the loop. */
1235 microblaze_adjust_block_mem (src, MAX_MOVE_BYTES, &src_reg, &src);
1236 microblaze_adjust_block_mem (dest, MAX_MOVE_BYTES, &dest_reg, &dest);
1237
1238 /* Calculate the value that SRC_REG should have after the last iteration
1239 of the loop. */
1240 final_src = expand_simple_binop (Pmode, PLUS, src_reg, GEN_INT (length),
1241 0, 0, OPTAB_WIDEN);
1242
1243 /* Emit the start of the loop. */
1244 label = gen_label_rtx ();
1245 emit_label (label);
1246
1247 /* Emit the loop body. */
1248 microblaze_block_move_straight (dest, src, MAX_MOVE_BYTES);
1249
1250 /* Move on to the next block. */
1251 emit_move_insn (src_reg, plus_constant (Pmode, src_reg, MAX_MOVE_BYTES));
1252 emit_move_insn (dest_reg, plus_constant (Pmode, dest_reg, MAX_MOVE_BYTES));
1253
1254 /* Emit the test & branch. */
1255 emit_insn (gen_cbranchsi4 (gen_rtx_NE (SImode, src_reg, final_src),
1256 src_reg, final_src, label));
1257
1258 /* Mop up any left-over bytes. */
1259 if (leftover)
1260 microblaze_block_move_straight (dest, src, leftover);
1261 }
1262
1263 /* Expand a cpymemsi instruction. */
1264
1265 bool
1266 microblaze_expand_block_move (rtx dest, rtx src, rtx length, rtx align_rtx)
1267 {
1268
1269 if (GET_CODE (length) == CONST_INT)
1270 {
1271 unsigned HOST_WIDE_INT bytes = UINTVAL (length);
1272 unsigned int align = UINTVAL (align_rtx);
1273
1274 if (align > UNITS_PER_WORD)
1275 {
1276 align = UNITS_PER_WORD; /* We can't do any better. */
1277 }
1278 else if (align < UNITS_PER_WORD)
1279 {
1280 if (UINTVAL (length) <= MAX_MOVE_BYTES)
1281 {
1282 move_by_pieces (dest, src, bytes, align, RETURN_BEGIN);
1283 return true;
1284 }
1285 else
1286 return false;
1287 }
1288
1289 if (UINTVAL (length) <= 2 * MAX_MOVE_BYTES)
1290 {
1291 microblaze_block_move_straight (dest, src, UINTVAL (length));
1292 return true;
1293 }
1294 else if (optimize)
1295 {
1296 microblaze_block_move_loop (dest, src, UINTVAL (length));
1297 return true;
1298 }
1299 }
1300 return false;
1301 }
1302
1303 /* Compute memory address *aligned_mem and corresponding shift value (*shift)
1304 from a QImode memory reference MEM */
1305 void
1306 microblaze_subword_address (rtx mem, rtx *aligned_mem, rtx *shift)
1307 {
1308 /* Align the memory address to a word. */
1309 rtx addr = force_reg (Pmode, XEXP (mem, 0));
1310
1311 rtx addr_mask = gen_int_mode (-4, Pmode);
1312
1313 rtx aligned_addr = gen_reg_rtx (Pmode);
1314
1315 emit_move_insn (aligned_addr, gen_rtx_AND (Pmode, addr, addr_mask));
1316
1317 *aligned_mem = change_address (mem, SImode, aligned_addr);
1318
1319 /* Calculate the shift amount. */
1320 emit_move_insn (*shift, gen_rtx_AND (SImode, addr, gen_int_mode (3, SImode)));
1321
1322 if (TARGET_LITTLE_ENDIAN == 0) {
1323 emit_move_insn (*shift,
1324 gen_rtx_MINUS (SImode, gen_int_mode (3, SImode), *shift));
1325 }
1326
1327 emit_move_insn (*shift, gen_rtx_ASHIFT (SImode, *shift,
1328 gen_int_mode (3, SImode)));
1329 }
1330
1331 static bool
1332 microblaze_rtx_costs (rtx x, machine_mode mode, int outer_code ATTRIBUTE_UNUSED,
1333 int opno ATTRIBUTE_UNUSED, int *total,
1334 bool speed ATTRIBUTE_UNUSED)
1335 {
1336 int code = GET_CODE (x);
1337
1338 switch (code)
1339 {
1340 case MEM:
1341 {
1342 int num_words = (GET_MODE_SIZE (mode) > UNITS_PER_WORD) ? 2 : 1;
1343 if (simple_memory_operand (x, mode))
1344 *total = COSTS_N_INSNS (2 * num_words);
1345 else
1346 *total = COSTS_N_INSNS (2 * (2 * num_words));
1347
1348 return true;
1349 }
1350 case NOT:
1351 {
1352 if (mode == DImode)
1353 {
1354 *total = COSTS_N_INSNS (2);
1355 }
1356 else
1357 *total = COSTS_N_INSNS (1);
1358 return false;
1359 }
1360 case AND:
1361 case IOR:
1362 case XOR:
1363 {
1364 if (mode == DImode)
1365 {
1366 *total = COSTS_N_INSNS (2);
1367 }
1368 else
1369 *total = COSTS_N_INSNS (1);
1370
1371 return false;
1372 }
1373 case ASHIFT:
1374 case ASHIFTRT:
1375 case LSHIFTRT:
1376 {
1377 if (TARGET_BARREL_SHIFT)
1378 {
1379 if (MICROBLAZE_VERSION_COMPARE (microblaze_select_cpu, "v5.00.a")
1380 >= 0)
1381 *total = COSTS_N_INSNS (1);
1382 else
1383 *total = COSTS_N_INSNS (2);
1384 }
1385 else if (!TARGET_SOFT_MUL)
1386 *total = COSTS_N_INSNS (1);
1387 else if (GET_CODE (XEXP (x, 1)) == CONST_INT)
1388 {
1389 /* Add 1 to make shift slightly more expensive than add. */
1390 *total = COSTS_N_INSNS (INTVAL (XEXP (x, 1))) + 1;
1391 /* Reduce shift costs for special circumstances. */
1392 if (optimize_size && INTVAL (XEXP (x, 1)) > 5)
1393 *total -= 2;
1394 if (!optimize_size && INTVAL (XEXP (x, 1)) > 17)
1395 *total -= 2;
1396 }
1397 else
1398 /* Double the worst cost of shifts when there is no barrel shifter and
1399 the shift amount is in a reg. */
1400 *total = COSTS_N_INSNS (32 * 4);
1401 return true;
1402 }
1403 case PLUS:
1404 case MINUS:
1405 {
1406 if (mode == SFmode || mode == DFmode)
1407 {
1408 if (TARGET_HARD_FLOAT)
1409 *total = COSTS_N_INSNS (6);
1410 return true;
1411 }
1412 else if (mode == DImode)
1413 {
1414 *total = COSTS_N_INSNS (4);
1415 return true;
1416 }
1417 else
1418 {
1419 *total = COSTS_N_INSNS (1);
1420 return true;
1421 }
1422
1423 return false;
1424 }
1425 case NEG:
1426 {
1427 if (mode == DImode)
1428 *total = COSTS_N_INSNS (4);
1429
1430 return false;
1431 }
1432 case MULT:
1433 {
1434 if (mode == SFmode)
1435 {
1436 if (TARGET_HARD_FLOAT)
1437 *total = COSTS_N_INSNS (6);
1438 }
1439 else if (!TARGET_SOFT_MUL)
1440 {
1441 if (MICROBLAZE_VERSION_COMPARE (microblaze_select_cpu, "v5.00.a")
1442 >= 0)
1443 *total = COSTS_N_INSNS (1);
1444 else
1445 *total = COSTS_N_INSNS (3);
1446 }
1447 else
1448 *total = COSTS_N_INSNS (10);
1449 return true;
1450 }
1451 case DIV:
1452 case UDIV:
1453 {
1454 if (mode == SFmode)
1455 {
1456 if (TARGET_HARD_FLOAT)
1457 *total = COSTS_N_INSNS (23);
1458 }
1459 return false;
1460 }
1461 case SIGN_EXTEND:
1462 {
1463 *total = COSTS_N_INSNS (1);
1464 return false;
1465 }
1466 case ZERO_EXTEND:
1467 {
1468 *total = COSTS_N_INSNS (1);
1469 return false;
1470 }
1471 }
1472
1473 return false;
1474 }
1475
1476 /* Return the number of instructions needed to load or store a value
1477 of mode MODE at X. Return 0 if X isn't valid for MODE. */
1478
1479 static int
1480 microblaze_address_insns (rtx x, machine_mode mode)
1481 {
1482 struct microblaze_address_info addr;
1483
1484 if (microblaze_classify_address (&addr, x, mode, false))
1485 {
1486 switch (addr.type)
1487 {
1488 case ADDRESS_REG:
1489 if (SMALL_INT (addr.offset))
1490 return 1;
1491 else
1492 return 2;
1493 case ADDRESS_CONST_INT:
1494 if (SMALL_INT (x))
1495 return 1;
1496 else
1497 return 2;
1498 case ADDRESS_REG_INDEX:
1499 return 1;
1500 case ADDRESS_SYMBOLIC:
1501 case ADDRESS_SYMBOLIC_TXT_REL:
1502 case ADDRESS_GOTOFF:
1503 return 2;
1504 case ADDRESS_TLS:
1505 switch (addr.tls_type)
1506 {
1507 case TLS_GD:
1508 return 2;
1509 case TLS_LDM:
1510 return 2;
1511 case TLS_DTPREL:
1512 return 1;
1513 default :
1514 gcc_unreachable ();
1515 }
1516 default:
1517 break;
1518 }
1519 }
1520 return 0;
1521 }
1522
1523 /* Provide the costs of an addressing mode that contains ADDR.
1524 If ADDR is not a valid address, its cost is irrelevant. */
1525 static int
1526 microblaze_address_cost (rtx addr, machine_mode mode ATTRIBUTE_UNUSED,
1527 addr_space_t as ATTRIBUTE_UNUSED,
1528 bool speed ATTRIBUTE_UNUSED)
1529 {
1530 return COSTS_N_INSNS (microblaze_address_insns (addr, GET_MODE (addr)));
1531 }
1532
1533 /* Return nonzero if X is an address which needs a temporary register when
1534 reloaded while generating PIC code. */
1535
1536 int
1537 pic_address_needs_scratch (rtx x)
1538 {
1539 if (GET_CODE (x) == CONST && GET_CODE (XEXP (x,0)) == PLUS)
1540 {
1541 rtx p0, p1;
1542
1543 p0 = XEXP (XEXP (x, 0), 0);
1544 p1 = XEXP (XEXP (x, 0), 1);
1545
1546 if ((GET_CODE (p0) == SYMBOL_REF || GET_CODE (p0) == LABEL_REF)
1547 && (GET_CODE (p1) == CONST_INT)
1548 && (flag_pic == 2 || microblaze_tls_symbol_p (p0) || !SMALL_INT (p1)))
1549 return 1;
1550 }
1551 return 0;
1552 }
1553
1554 /* Argument support functions. */
1555 /* Initialize CUMULATIVE_ARGS for a function. */
1556
1557 void
1558 init_cumulative_args (CUMULATIVE_ARGS * cum, tree fntype,
1559 rtx libname ATTRIBUTE_UNUSED)
1560 {
1561 static CUMULATIVE_ARGS zero_cum;
1562 tree param, next_param;
1563
1564 *cum = zero_cum;
1565
1566 /* Determine if this function has variable arguments. This is
1567 indicated by the last argument being 'void_type_mode' if there
1568 are no variable arguments. The standard MicroBlaze calling sequence
1569 passes all arguments in the general purpose registers in this case. */
1570
1571 for (param = fntype ? TYPE_ARG_TYPES (fntype) : 0;
1572 param != 0; param = next_param)
1573 {
1574 next_param = TREE_CHAIN (param);
1575 if (next_param == 0 && TREE_VALUE (param) != void_type_node)
1576 cum->gp_reg_found = 1;
1577 }
1578 }
1579
1580 /* Advance the argument to the next argument position. */
1581
1582 static void
1583 microblaze_function_arg_advance (cumulative_args_t cum_v,
1584 const function_arg_info &arg)
1585 {
1586 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
1587
1588 cum->arg_number++;
1589 switch (arg.mode)
1590 {
1591 case E_VOIDmode:
1592 break;
1593
1594 default:
1595 gcc_assert (GET_MODE_CLASS (arg.mode) == MODE_COMPLEX_INT
1596 || GET_MODE_CLASS (arg.mode) == MODE_COMPLEX_FLOAT);
1597
1598 cum->gp_reg_found = 1;
1599 cum->arg_words += ((GET_MODE_SIZE (arg.mode) + UNITS_PER_WORD - 1)
1600 / UNITS_PER_WORD);
1601 break;
1602
1603 case E_BLKmode:
1604 cum->gp_reg_found = 1;
1605 cum->arg_words += ((int_size_in_bytes (arg.type) + UNITS_PER_WORD - 1)
1606 / UNITS_PER_WORD);
1607 break;
1608
1609 case E_SFmode:
1610 cum->arg_words++;
1611 if (!cum->gp_reg_found && cum->arg_number <= 2)
1612 cum->fp_code += 1 << ((cum->arg_number - 1) * 2);
1613 break;
1614
1615 case E_DFmode:
1616 cum->arg_words += 2;
1617 if (!cum->gp_reg_found && cum->arg_number <= 2)
1618 cum->fp_code += 2 << ((cum->arg_number - 1) * 2);
1619 break;
1620
1621 case E_DImode:
1622 cum->gp_reg_found = 1;
1623 cum->arg_words += 2;
1624 break;
1625
1626 case E_QImode:
1627 case E_HImode:
1628 case E_SImode:
1629 case E_TImode:
1630 cum->gp_reg_found = 1;
1631 cum->arg_words++;
1632 break;
1633 }
1634 }
1635
1636 /* Return an RTL expression containing the register for the given argument
1637 or 0 if the argument is to be passed on the stack. */
1638
1639 static rtx
1640 microblaze_function_arg (cumulative_args_t cum_v, const function_arg_info &arg)
1641 {
1642 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
1643
1644 rtx ret;
1645 int regbase = -1;
1646 int *arg_words = &cum->arg_words;
1647
1648 cum->last_arg_fp = 0;
1649 switch (arg.mode)
1650 {
1651 case E_SFmode:
1652 case E_DFmode:
1653 case E_VOIDmode:
1654 case E_QImode:
1655 case E_HImode:
1656 case E_SImode:
1657 case E_DImode:
1658 case E_TImode:
1659 regbase = GP_ARG_FIRST;
1660 break;
1661 default:
1662 gcc_assert (GET_MODE_CLASS (arg.mode) == MODE_COMPLEX_INT
1663 || GET_MODE_CLASS (arg.mode) == MODE_COMPLEX_FLOAT);
1664 /* FALLTHRU */
1665 case E_BLKmode:
1666 regbase = GP_ARG_FIRST;
1667 break;
1668 }
1669
1670 if (*arg_words >= MAX_ARGS_IN_REGISTERS)
1671 ret = 0;
1672 else
1673 {
1674 gcc_assert (regbase != -1);
1675
1676 ret = gen_rtx_REG (arg.mode, regbase + *arg_words);
1677 }
1678
1679 if (arg.end_marker_p ())
1680 {
1681 if (cum->num_adjusts > 0)
1682 ret = gen_rtx_PARALLEL ((machine_mode) cum->fp_code,
1683 gen_rtvec_v (cum->num_adjusts, cum->adjust));
1684 }
1685
1686 return ret;
1687 }
1688
1689 /* Return number of bytes of argument to put in registers. */
1690 static int
1691 function_arg_partial_bytes (cumulative_args_t cum_v,
1692 const function_arg_info &arg)
1693 {
1694 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
1695
1696 if ((arg.mode == BLKmode
1697 || GET_MODE_CLASS (arg.mode) != MODE_COMPLEX_INT
1698 || GET_MODE_CLASS (arg.mode) != MODE_COMPLEX_FLOAT)
1699 && cum->arg_words < MAX_ARGS_IN_REGISTERS)
1700 {
1701 int words = ((arg.promoted_size_in_bytes () + UNITS_PER_WORD - 1)
1702 / UNITS_PER_WORD);
1703 if (words + cum->arg_words <= MAX_ARGS_IN_REGISTERS)
1704 return 0; /* structure fits in registers */
1705
1706 return (MAX_ARGS_IN_REGISTERS - cum->arg_words) * UNITS_PER_WORD;
1707 }
1708
1709 else if (arg.mode == DImode && cum->arg_words == MAX_ARGS_IN_REGISTERS - 1)
1710 return UNITS_PER_WORD;
1711
1712 return 0;
1713 }
1714
1715 /* Convert a version number of the form "vX.YY.Z" to an integer encoding
1716 for easier range comparison. */
1717 static int
1718 microblaze_version_to_int (const char *version)
1719 {
1720 const char *p, *v;
1721 const char *tmpl = "vXX.YY.Z";
1722 int iver = 0;
1723
1724 p = version;
1725 v = tmpl;
1726
1727 while (*p)
1728 {
1729 if (*v == 'X')
1730 { /* Looking for major */
1731 if (*p == '.')
1732 {
1733 v++;
1734 }
1735 else
1736 {
1737 if (!(*p >= '0' && *p <= '9'))
1738 return -1;
1739 iver += (int) (*p - '0');
1740 iver *= 10;
1741 }
1742 }
1743 else if (*v == 'Y')
1744 { /* Looking for minor */
1745 if (!(*p >= '0' && *p <= '9'))
1746 return -1;
1747 iver += (int) (*p - '0');
1748 iver *= 10;
1749 }
1750 else if (*v == 'Z')
1751 { /* Looking for compat */
1752 if (!(*p >= 'a' && *p <= 'z'))
1753 return -1;
1754 iver *= 10;
1755 iver += (int) (*p - 'a');
1756 }
1757 else
1758 {
1759 if (*p != *v)
1760 return -1;
1761 }
1762
1763 v++;
1764 p++;
1765 }
1766
1767 if (*p)
1768 return -1;
1769
1770 return iver;
1771 }
1772
1773
1774 static void
1775 microblaze_option_override (void)
1776 {
1777 int i, start;
1778 int regno;
1779 machine_mode mode;
1780 int ver;
1781
1782 microblaze_section_threshold = (OPTION_SET_P (g_switch_value)
1783 ? g_switch_value
1784 : MICROBLAZE_DEFAULT_GVALUE);
1785
1786 if (flag_pic)
1787 {
1788 /* Make sure it's 2, we only support one kind of PIC. */
1789 flag_pic = 2;
1790 if (!TARGET_SUPPORTS_PIC)
1791 {
1792 error ("%<-fPIC%>/%<-fpic%> not supported for this target");
1793 /* Clear it to avoid further errors. */
1794 flag_pic = 0;
1795 }
1796 }
1797
1798 /* Check the MicroBlaze CPU version for any special action to be done. */
1799 if (microblaze_select_cpu == NULL)
1800 microblaze_select_cpu = MICROBLAZE_DEFAULT_CPU;
1801 ver = microblaze_version_to_int (microblaze_select_cpu);
1802 if (ver == -1)
1803 {
1804 error ("%qs is an invalid argument to %<-mcpu=%>", microblaze_select_cpu);
1805 }
1806
1807 ver = MICROBLAZE_VERSION_COMPARE (microblaze_select_cpu, "v3.00.a");
1808 if (ver < 0)
1809 {
1810 /* No hardware exceptions in earlier versions. So no worries. */
1811 #if 0
1812 microblaze_select_flags &= ~(MICROBLAZE_MASK_NO_UNSAFE_DELAY);
1813 #endif
1814 microblaze_no_unsafe_delay = 0;
1815 microblaze_pipe = MICROBLAZE_PIPE_3;
1816 }
1817 else if (ver == 0
1818 || (MICROBLAZE_VERSION_COMPARE (microblaze_select_cpu, "v4.00.b")
1819 == 0))
1820 {
1821 #if 0
1822 microblaze_select_flags |= (MICROBLAZE_MASK_NO_UNSAFE_DELAY);
1823 #endif
1824 microblaze_no_unsafe_delay = 1;
1825 microblaze_pipe = MICROBLAZE_PIPE_3;
1826 }
1827 else
1828 {
1829 /* We agree to use 5 pipe-stage model even on area optimized 3
1830 pipe-stage variants. */
1831 #if 0
1832 microblaze_select_flags &= ~(MICROBLAZE_MASK_NO_UNSAFE_DELAY);
1833 #endif
1834 microblaze_no_unsafe_delay = 0;
1835 microblaze_pipe = MICROBLAZE_PIPE_5;
1836 if (MICROBLAZE_VERSION_COMPARE (microblaze_select_cpu, "v5.00.a") == 0
1837 || MICROBLAZE_VERSION_COMPARE (microblaze_select_cpu,
1838 "v5.00.b") == 0
1839 || MICROBLAZE_VERSION_COMPARE (microblaze_select_cpu,
1840 "v5.00.c") == 0)
1841 {
1842 /* Pattern compares are to be turned on by default only when
1843 compiling for MB v5.00.'z'. */
1844 target_flags |= MASK_PATTERN_COMPARE;
1845 }
1846 }
1847
1848 ver = MICROBLAZE_VERSION_COMPARE (microblaze_select_cpu, "v6.00.a");
1849 if (ver < 0)
1850 {
1851 if (TARGET_MULTIPLY_HIGH)
1852 warning (0,
1853 "%<-mxl-multiply-high%> can be used only with "
1854 "%<-mcpu=v6.00.a%> or greater");
1855 }
1856
1857 ver = MICROBLAZE_VERSION_COMPARE (microblaze_select_cpu, "v8.10.a");
1858 microblaze_has_clz = 1;
1859 if (ver < 0)
1860 {
1861 /* MicroBlaze prior to 8.10.a didn't have clz. */
1862 microblaze_has_clz = 0;
1863 }
1864
1865 /* TARGET_REORDER defaults to 2 if -mxl-reorder not specified. */
1866 ver = MICROBLAZE_VERSION_COMPARE (microblaze_select_cpu, "v8.30.a");
1867 if (ver < 0)
1868 {
1869 if (TARGET_REORDER == 1)
1870 warning (0, "%<-mxl-reorder%> can be used only with "
1871 "%<-mcpu=v8.30.a%> or greater");
1872 TARGET_REORDER = 0;
1873 }
1874 else if ((ver == 0) && !TARGET_PATTERN_COMPARE)
1875 {
1876 if (TARGET_REORDER == 1)
1877 warning (0, "%<-mxl-reorder%> requires %<-mxl-pattern-compare%> for "
1878 "%<-mcpu=v8.30.a%>");
1879 TARGET_REORDER = 0;
1880 }
1881
1882 if (TARGET_MULTIPLY_HIGH && TARGET_SOFT_MUL)
1883 error ("%<-mxl-multiply-high%> requires %<-mno-xl-soft-mul%>");
1884
1885 /* Always use DFA scheduler. */
1886 microblaze_sched_use_dfa = 1;
1887
1888 #if 0
1889 microblaze_abicalls = MICROBLAZE_ABICALLS_NO;
1890 #endif
1891
1892 /* Initialize the high, low values for legit floating point constants. */
1893 real_maxval (&dfhigh, 0, DFmode);
1894 real_maxval (&dflow, 1, DFmode);
1895 real_maxval (&sfhigh, 0, SFmode);
1896 real_maxval (&sflow, 1, SFmode);
1897
1898 microblaze_print_operand_punct['?'] = 1;
1899 microblaze_print_operand_punct['#'] = 1;
1900 microblaze_print_operand_punct['&'] = 1;
1901 microblaze_print_operand_punct['!'] = 1;
1902 microblaze_print_operand_punct['*'] = 1;
1903 microblaze_print_operand_punct['@'] = 1;
1904 microblaze_print_operand_punct['.'] = 1;
1905 microblaze_print_operand_punct['('] = 1;
1906 microblaze_print_operand_punct[')'] = 1;
1907 microblaze_print_operand_punct['['] = 1;
1908 microblaze_print_operand_punct[']'] = 1;
1909 microblaze_print_operand_punct['<'] = 1;
1910 microblaze_print_operand_punct['>'] = 1;
1911 microblaze_print_operand_punct['{'] = 1;
1912 microblaze_print_operand_punct['}'] = 1;
1913 microblaze_print_operand_punct['^'] = 1;
1914 microblaze_print_operand_punct['$'] = 1;
1915 microblaze_print_operand_punct['+'] = 1;
1916
1917 /* Set up array to map GCC register number to debug register number.
1918 Ignore the special purpose register numbers. */
1919
1920 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1921 microblaze_debugger_regno[i] = -1;
1922
1923 start = GP_DEBUGGER_FIRST - GP_REG_FIRST;
1924 for (i = GP_REG_FIRST; i <= GP_REG_LAST; i++)
1925 microblaze_debugger_regno[i] = i + start;
1926
1927 /* Set up array giving whether a given register can hold a given mode. */
1928
1929 for (mode = VOIDmode;
1930 mode != MAX_MACHINE_MODE; mode = (machine_mode) ((int) mode + 1))
1931 {
1932 int size = GET_MODE_SIZE (mode);
1933
1934 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
1935 {
1936 int ok;
1937
1938 if (mode == CCmode)
1939 {
1940 ok = (ST_REG_P (regno) || GP_REG_P (regno));
1941 }
1942 else if (GP_REG_P (regno))
1943 ok = ((regno & 1) == 0 || size <= UNITS_PER_WORD);
1944 else
1945 ok = 0;
1946
1947 microblaze_hard_regno_mode_ok_p[(int) mode][regno] = ok;
1948 }
1949 }
1950 }
1951
1952 /* Implement TARGET_HARD_REGNO_MODE_OK. In 32 bit mode, require that
1953 DImode and DFmode be in even registers. For DImode, this makes some
1954 of the insns easier to write, since you don't have to worry about a
1955 DImode value in registers 3 & 4, producing a result in 4 & 5.
1956
1957 To make the code simpler, the hook now just references an
1958 array built in override_options. */
1959
1960 static bool
1961 microblaze_hard_regno_mode_ok (unsigned int regno, machine_mode mode)
1962 {
1963 return microblaze_hard_regno_mode_ok_p[mode][regno];
1964 }
1965
1966 /* Implement TARGET_MODES_TIEABLE_P. */
1967
1968 static bool
1969 microblaze_modes_tieable_p (machine_mode mode1, machine_mode mode2)
1970 {
1971 return ((GET_MODE_CLASS (mode1) == MODE_FLOAT
1972 || GET_MODE_CLASS (mode1) == MODE_COMPLEX_FLOAT)
1973 == (GET_MODE_CLASS (mode2) == MODE_FLOAT
1974 || GET_MODE_CLASS (mode2) == MODE_COMPLEX_FLOAT));
1975 }
1976
1977 /* Return true if FUNC is an interrupt function as specified
1978 by the "interrupt_handler" attribute. */
1979
1980 static int
1981 microblaze_interrupt_function_p (tree func)
1982 {
1983 tree a;
1984
1985 if (TREE_CODE (func) != FUNCTION_DECL)
1986 return 0;
1987
1988 a = lookup_attribute ("interrupt_handler", DECL_ATTRIBUTES (func));
1989 return a != NULL_TREE;
1990 }
1991
1992 static int
1993 microblaze_fast_interrupt_function_p (tree func)
1994 {
1995 tree a;
1996
1997 if (TREE_CODE (func) != FUNCTION_DECL)
1998 return 0;
1999
2000 a = lookup_attribute ("fast_interrupt", DECL_ATTRIBUTES (func));
2001 return a != NULL_TREE;
2002 }
2003 int
2004 microblaze_break_function_p (tree func)
2005 {
2006 tree a;
2007 if (!func)
2008 return 0;
2009 if (TREE_CODE (func) != FUNCTION_DECL)
2010 return 0;
2011
2012 a = lookup_attribute ("break_handler", DECL_ATTRIBUTES (func));
2013 return a != NULL_TREE;
2014 }
2015 /* Return true if FUNC is an interrupt function which uses
2016 normal return, indicated by the "save_volatiles" attribute. */
2017
2018 static int
2019 microblaze_save_volatiles (tree func)
2020 {
2021 tree a;
2022
2023 if (TREE_CODE (func) != FUNCTION_DECL)
2024 return 0;
2025
2026 a = lookup_attribute ("save_volatiles", DECL_ATTRIBUTES (func));
2027 return a != NULL_TREE;
2028 }
2029
2030 /* Return whether function is tagged with 'interrupt_handler'
2031 or 'fast_interrupt' attribute. Return true if function
2032 should use return from interrupt rather than normal
2033 function return. */
2034 int
2035 microblaze_is_interrupt_variant (void)
2036 {
2037 return (interrupt_handler || fast_interrupt);
2038 }
2039 int
2040 microblaze_is_break_handler (void)
2041 {
2042 return break_handler;
2043 }
2044
2045 /* Determine of register must be saved/restored in call. */
2046 static int
2047 microblaze_must_save_register (int regno)
2048 {
2049 if (pic_offset_table_rtx &&
2050 (regno == MB_ABI_PIC_ADDR_REGNUM) && df_regs_ever_live_p (regno))
2051 return 1;
2052
2053 if (df_regs_ever_live_p (regno) && !call_used_or_fixed_reg_p (regno))
2054 return 1;
2055
2056 if (frame_pointer_needed && (regno == HARD_FRAME_POINTER_REGNUM))
2057 return 1;
2058
2059 if (crtl->calls_eh_return
2060 && regno == MB_ABI_SUB_RETURN_ADDR_REGNUM)
2061 return 1;
2062
2063 if (!crtl->is_leaf)
2064 {
2065 if (regno == MB_ABI_SUB_RETURN_ADDR_REGNUM)
2066 return 1;
2067 if ((microblaze_is_interrupt_variant () || save_volatiles) &&
2068 (regno >= 3 && regno <= 12))
2069 return 1;
2070 }
2071
2072 if (microblaze_is_interrupt_variant ())
2073 {
2074 if (df_regs_ever_live_p (regno)
2075 || regno == MB_ABI_MSR_SAVE_REG
2076 || ((interrupt_handler || fast_interrupt)
2077 && (regno == MB_ABI_ASM_TEMP_REGNUM
2078 || regno == MB_ABI_EXCEPTION_RETURN_ADDR_REGNUM)))
2079 return 1;
2080 }
2081
2082 if (save_volatiles)
2083 {
2084 if (df_regs_ever_live_p (regno)
2085 || regno == MB_ABI_ASM_TEMP_REGNUM
2086 || regno == MB_ABI_EXCEPTION_RETURN_ADDR_REGNUM)
2087 return 1;
2088 }
2089
2090 if (crtl->calls_eh_return
2091 && (regno == EH_RETURN_DATA_REGNO (0)
2092 || regno == EH_RETURN_DATA_REGNO (1)))
2093 return 1;
2094
2095 return 0;
2096 }
2097
2098 /* Return the bytes needed to compute the frame pointer from the current
2099 stack pointer.
2100
2101 MicroBlaze stack frames look like:
2102
2103
2104
2105 Before call After call
2106 +-----------------------+ +-----------------------+
2107 high | | | |
2108 mem. | local variables, | | local variables, |
2109 | callee saved and | | callee saved and |
2110 | temps | | temps |
2111 +-----------------------+ +-----------------------+
2112 | arguments for called | | arguments for called |
2113 | subroutines | | subroutines |
2114 | (optional) | | (optional) |
2115 +-----------------------+ +-----------------------+
2116 | Link register | | Link register |
2117 SP->| | | |
2118 +-----------------------+ +-----------------------+
2119 | |
2120 | local variables, |
2121 | callee saved and |
2122 | temps |
2123 +-----------------------+
2124 | MSR (optional if, |
2125 | interrupt handler) |
2126 +-----------------------+
2127 | |
2128 | alloca allocations |
2129 | |
2130 +-----------------------+
2131 | |
2132 | arguments for called |
2133 | subroutines |
2134 | (optional) |
2135 | |
2136 +-----------------------+
2137 | Link register |
2138 low FP,SP->| |
2139 memory +-----------------------+
2140
2141 */
2142
2143 static HOST_WIDE_INT
2144 compute_frame_size (HOST_WIDE_INT size)
2145 {
2146 int regno;
2147 HOST_WIDE_INT total_size; /* # bytes that the entire frame takes up. */
2148 HOST_WIDE_INT var_size; /* # bytes that local variables take up. */
2149 HOST_WIDE_INT args_size; /* # bytes that outgoing arguments take up. */
2150 int link_debug_size; /* # bytes for link register. */
2151 HOST_WIDE_INT gp_reg_size; /* # bytes needed to store calle-saved gp regs. */
2152 long mask; /* mask of saved gp registers. */
2153
2154 interrupt_handler =
2155 microblaze_interrupt_function_p (current_function_decl);
2156 break_handler =
2157 microblaze_break_function_p (current_function_decl);
2158
2159 fast_interrupt =
2160 microblaze_fast_interrupt_function_p (current_function_decl);
2161 save_volatiles = microblaze_save_volatiles (current_function_decl);
2162 if (break_handler)
2163 interrupt_handler = break_handler;
2164
2165 gp_reg_size = 0;
2166 mask = 0;
2167 var_size = size;
2168 args_size = crtl->outgoing_args_size;
2169
2170 if ((args_size == 0) && cfun->calls_alloca)
2171 args_size = NUM_OF_ARGS * UNITS_PER_WORD;
2172
2173 total_size = var_size + args_size;
2174
2175 if (flag_pic == 2 && !TARGET_PIC_DATA_TEXT_REL)
2176 /* force setting GOT. */
2177 df_set_regs_ever_live (MB_ABI_PIC_ADDR_REGNUM, true);
2178
2179 /* Calculate space needed for gp registers. */
2180 for (regno = GP_REG_FIRST; regno <= GP_REG_LAST; regno++)
2181 {
2182 if (microblaze_must_save_register (regno))
2183 {
2184
2185 if (regno != MB_ABI_SUB_RETURN_ADDR_REGNUM)
2186 /* Don't account for link register. It is accounted specially below. */
2187 gp_reg_size += GET_MODE_SIZE (SImode);
2188
2189 mask |= (1L << (regno - GP_REG_FIRST));
2190 }
2191 }
2192
2193 total_size += gp_reg_size;
2194
2195 /* Add 4 bytes for MSR. */
2196 if (microblaze_is_interrupt_variant ())
2197 total_size += 4;
2198
2199 /* No space to be allocated for link register in leaf functions with no other
2200 stack requirements. */
2201 if (total_size == 0 && crtl->is_leaf)
2202 link_debug_size = 0;
2203 else
2204 link_debug_size = UNITS_PER_WORD;
2205
2206 total_size += link_debug_size;
2207
2208 /* Save other computed information. */
2209 current_frame_info.total_size = total_size;
2210 current_frame_info.var_size = var_size;
2211 current_frame_info.args_size = args_size;
2212 current_frame_info.gp_reg_size = gp_reg_size;
2213 current_frame_info.mask = mask;
2214 current_frame_info.initialized = reload_completed;
2215 current_frame_info.num_gp = gp_reg_size / UNITS_PER_WORD;
2216 current_frame_info.link_debug_size = link_debug_size;
2217
2218 if (mask)
2219 /* Offset from which to callee-save GP regs. */
2220 current_frame_info.gp_offset = (total_size - gp_reg_size);
2221 else
2222 current_frame_info.gp_offset = 0;
2223
2224 /* Ok, we're done. */
2225 return total_size;
2226 }
2227
2228 /* Make sure that we're not trying to eliminate to the wrong hard frame
2229 pointer. */
2230
2231 static bool
2232 microblaze_can_eliminate (const int from, const int to)
2233 {
2234 return ((from == RETURN_ADDRESS_POINTER_REGNUM && !leaf_function_p())
2235 || (to == MB_ABI_SUB_RETURN_ADDR_REGNUM && leaf_function_p())
2236 || (from != RETURN_ADDRESS_POINTER_REGNUM
2237 && (to == HARD_FRAME_POINTER_REGNUM
2238 || (to == STACK_POINTER_REGNUM && !frame_pointer_needed))));
2239 }
2240
2241 /* Implement INITIAL_ELIMINATION_OFFSET. FROM is either the frame
2242 pointer or argument pointer or the return address pointer. TO is either
2243 the stack pointer or hard frame pointer. */
2244
2245 HOST_WIDE_INT
2246 microblaze_initial_elimination_offset (int from, int to)
2247 {
2248 HOST_WIDE_INT offset;
2249
2250 switch (from)
2251 {
2252 case FRAME_POINTER_REGNUM:
2253 offset = 0;
2254 break;
2255 case ARG_POINTER_REGNUM:
2256 if (to == STACK_POINTER_REGNUM || to == HARD_FRAME_POINTER_REGNUM)
2257 offset = compute_frame_size (get_frame_size ());
2258 else
2259 gcc_unreachable ();
2260 break;
2261 case RETURN_ADDRESS_POINTER_REGNUM:
2262 if (crtl->is_leaf)
2263 offset = 0;
2264 else
2265 offset = current_frame_info.gp_offset +
2266 ((UNITS_PER_WORD - (POINTER_SIZE / BITS_PER_UNIT)));
2267 break;
2268 default:
2269 gcc_unreachable ();
2270 }
2271 return offset;
2272 }
2273
2274 /* Print operands using format code.
2275
2276 The MicroBlaze specific codes are:
2277
2278 'X' X is CONST_INT, prints 32 bits in hexadecimal format = "0x%08x",
2279 'x' X is CONST_INT, prints 16 bits in hexadecimal format = "0x%04x",
2280 'F' op is CONST_DOUBLE, print 32 bits in hex,
2281 'd' output integer constant in decimal,
2282 'z' if the operand is 0, use $0 instead of normal operand.
2283 'D' print second register of double-word register operand.
2284 'L' print low-order register of double-word register operand.
2285 'M' print high-order register of double-word register operand.
2286 'C' print part of opcode for a branch condition.
2287 'N' print part of opcode for a branch condition, inverted.
2288 'S' X is CODE_LABEL, print with prefix of "LS" (for embedded switch).
2289 'B' print 'z' for EQ, 'n' for NE
2290 'b' print 'n' for EQ, 'z' for NE
2291 'T' print 'f' for EQ, 't' for NE
2292 't' print 't' for EQ, 'f' for NE
2293 'm' Print 1<<operand.
2294 'i' Print 'i' if MEM operand has immediate value
2295 'y' Print 'y' if MEM operand is single register
2296 'o' Print operand address+4
2297 '?' Print 'd' if we use a branch with delay slot instead of normal branch.
2298 'h' Print high word of const_double (int or float) value as hex
2299 'j' Print low word of const_double (int or float) value as hex
2300 's' Print -1 if operand is negative, 0 if positive (sign extend)
2301 '@' Print the name of the temporary register (rMB_ABI_ASM_TEMP_REGNUM).
2302 '#' Print nop if the delay slot of a branch is not filled.
2303 */
2304
2305 void
2306 print_operand (FILE * file, rtx op, int letter)
2307 {
2308 enum rtx_code code;
2309
2310 if (PRINT_OPERAND_PUNCT_VALID_P (letter))
2311 {
2312 switch (letter)
2313 {
2314 case '?':
2315 /* Conditionally add a 'd' to indicate filled delay slot. */
2316 if (final_sequence != NULL)
2317 fputs ("d", file);
2318 break;
2319
2320 case '#':
2321 /* Conditionally add a nop in unfilled delay slot. */
2322 if (final_sequence == NULL)
2323 fputs ("nop\t\t# Unfilled delay slot\n", file);
2324 break;
2325
2326 case '@':
2327 fputs (reg_names[GP_REG_FIRST + MB_ABI_ASM_TEMP_REGNUM], file);
2328 break;
2329
2330 default:
2331 output_operand_lossage ("unknown punctuation '%c'", letter);
2332 break;
2333 }
2334
2335 return;
2336 }
2337
2338 if (!op)
2339 {
2340 output_operand_lossage ("null pointer");
2341 return;
2342 }
2343
2344 code = GET_CODE (op);
2345
2346 if (code == SIGN_EXTEND)
2347 op = XEXP (op, 0), code = GET_CODE (op);
2348
2349 if (letter == 'C')
2350 switch (code)
2351 {
2352 case EQ:
2353 fputs ("eq", file);
2354 break;
2355 case NE:
2356 fputs ("ne", file);
2357 break;
2358 case GT:
2359 case GTU:
2360 fputs ("gt", file);
2361 break;
2362 case GE:
2363 case GEU:
2364 fputs ("ge", file);
2365 break;
2366 case LT:
2367 case LTU:
2368 fputs ("lt", file);
2369 break;
2370 case LE:
2371 case LEU:
2372 fputs ("le", file);
2373 break;
2374 default:
2375 fatal_insn ("PRINT_OPERAND, invalid insn for %%C", op);
2376 }
2377
2378 else if (letter == 'N')
2379 switch (code)
2380 {
2381 case EQ:
2382 fputs ("ne", file);
2383 break;
2384 case NE:
2385 fputs ("eq", file);
2386 break;
2387 case GT:
2388 case GTU:
2389 fputs ("le", file);
2390 break;
2391 case GE:
2392 case GEU:
2393 fputs ("lt", file);
2394 break;
2395 case LT:
2396 case LTU:
2397 fputs ("ge", file);
2398 break;
2399 case LE:
2400 case LEU:
2401 fputs ("gt", file);
2402 break;
2403 default:
2404 fatal_insn ("PRINT_OPERAND, invalid insn for %%N", op);
2405 }
2406
2407 else if (letter == 'S')
2408 {
2409 char buffer[100];
2410
2411 ASM_GENERATE_INTERNAL_LABEL (buffer, "LS", CODE_LABEL_NUMBER (op));
2412 assemble_name (file, buffer);
2413 }
2414
2415 /* Print 'i' for memory operands which have immediate values. */
2416 else if (letter == 'i')
2417 {
2418 if (code == MEM)
2419 {
2420 struct microblaze_address_info info;
2421
2422 if (!microblaze_classify_address
2423 (&info, XEXP (op, 0), GET_MODE (op), 1))
2424 fatal_insn ("insn contains an invalid address !", op);
2425
2426 switch (info.type)
2427 {
2428 case ADDRESS_REG:
2429 case ADDRESS_CONST_INT:
2430 case ADDRESS_SYMBOLIC:
2431 case ADDRESS_SYMBOLIC_TXT_REL:
2432 case ADDRESS_GOTOFF:
2433 case ADDRESS_TLS:
2434 fputs ("i", file);
2435 break;
2436 case ADDRESS_REG_INDEX:
2437 break;
2438 case ADDRESS_INVALID:
2439 case ADDRESS_PLT:
2440 fatal_insn ("invalid address", op);
2441 }
2442 }
2443 }
2444
2445 else if (code == REG || code == SUBREG)
2446 {
2447 int regnum;
2448
2449 if (code == REG)
2450 regnum = REGNO (op);
2451 else
2452 regnum = true_regnum (op);
2453
2454 if ((letter == 'M' && !WORDS_BIG_ENDIAN)
2455 || (letter == 'L' && WORDS_BIG_ENDIAN) || letter == 'D')
2456 regnum++;
2457
2458 fprintf (file, "%s", reg_names[regnum]);
2459 }
2460
2461 else if (code == MEM)
2462 if (letter == 'o')
2463 {
2464 rtx op4 = adjust_address (op, GET_MODE (op), 4);
2465 output_address (GET_MODE (op), XEXP (op4, 0));
2466 }
2467 else if (letter == 'y')
2468 {
2469 rtx mem_reg = XEXP (op, 0);
2470 if (GET_CODE (mem_reg) == REG)
2471 {
2472 int regnum = REGNO (mem_reg);
2473 fprintf (file, "%s", reg_names[regnum]);
2474 }
2475 }
2476 else
2477 output_address (GET_MODE (op), XEXP (op, 0));
2478
2479 else if (letter == 'h' || letter == 'j')
2480 {
2481 long val[2];
2482 if (code == CONST_DOUBLE)
2483 {
2484 if (GET_MODE (op) == DFmode)
2485 REAL_VALUE_TO_TARGET_DOUBLE (*CONST_DOUBLE_REAL_VALUE (op), val);
2486 else
2487 {
2488 val[0] = CONST_DOUBLE_HIGH (op);
2489 val[1] = CONST_DOUBLE_LOW (op);
2490 }
2491 }
2492 else if (code == CONST_INT)
2493 {
2494 val[0] = (INTVAL (op) & 0xffffffff00000000LL) >> 32;
2495 val[1] = INTVAL (op) & 0x00000000ffffffffLL;
2496 if (val[0] == 0 && val[1] < 0)
2497 val[0] = -1;
2498
2499 }
2500 fprintf (file, "0x%8.8lx", (letter == 'h') ? val[0] : val[1]);
2501 }
2502 else if (code == CONST_DOUBLE)
2503 {
2504 if (letter == 'F')
2505 {
2506 unsigned long value_long;
2507 REAL_VALUE_TO_TARGET_SINGLE (*CONST_DOUBLE_REAL_VALUE (op),
2508 value_long);
2509 fprintf (file, "0x%lx", value_long);
2510 }
2511 else
2512 {
2513 char s[60];
2514 real_to_decimal (s, CONST_DOUBLE_REAL_VALUE (op), sizeof (s), 0, 1);
2515 fputs (s, file);
2516 }
2517 }
2518
2519 else if (code == UNSPEC)
2520 {
2521 print_operand_address (file, op);
2522 }
2523
2524 else if (letter == 'x' && GET_CODE (op) == CONST_INT)
2525 fprintf (file, HOST_WIDE_INT_PRINT_HEX, 0xffff & INTVAL (op));
2526
2527 else if (letter == 'X' && GET_CODE (op) == CONST_INT)
2528 fprintf (file, HOST_WIDE_INT_PRINT_HEX, INTVAL (op));
2529
2530 else if (letter == 'd' && GET_CODE (op) == CONST_INT)
2531 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (INTVAL (op)));
2532
2533 else if (letter == 'z' && GET_CODE (op) == CONST_INT && INTVAL (op) == 0)
2534 fputs (reg_names[GP_REG_FIRST], file);
2535
2536 else if (letter == 's' && GET_CODE (op) == CONST_INT)
2537 if (INTVAL (op) < 0)
2538 fputs ("-1", file);
2539 else
2540 fputs ("0", file);
2541
2542 else if (letter == 'd' || letter == 'x' || letter == 'X' || letter == 's')
2543 output_operand_lossage ("letter %c was found & insn was not CONST_INT", letter);
2544
2545 else if (letter == 'B')
2546 fputs (code == EQ ? "z" : "n", file);
2547 else if (letter == 'b')
2548 fputs (code == EQ ? "n" : "z", file);
2549 else if (letter == 'T')
2550 fputs (code == EQ ? "f" : "t", file);
2551 else if (letter == 't')
2552 fputs (code == EQ ? "t" : "f", file);
2553
2554 else if (code == CONST
2555 && ((GET_CODE (XEXP (op, 0)) == REG)
2556 || (GET_CODE (XEXP (op, 0)) == UNSPEC)))
2557 {
2558 print_operand (file, XEXP (op, 0), letter);
2559 }
2560 else if (code == CONST
2561 && (GET_CODE (XEXP (op, 0)) == PLUS)
2562 && (GET_CODE (XEXP (XEXP (op, 0), 0)) == REG)
2563 && (GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST))
2564 {
2565 print_operand_address (file, XEXP (op, 0));
2566 }
2567 else if (letter == 'm')
2568 fprintf (file, "%ld", (1L << INTVAL (op)));
2569 else
2570 output_addr_const (file, op);
2571 }
2572
2573 /* A C compound statement to output to stdio stream STREAM the
2574 assembler syntax for an instruction operand that is a memory
2575 reference whose address is ADDR. ADDR is an RTL expression.
2576
2577 Possible address classifications and output formats are,
2578
2579 ADDRESS_REG "%0, r0"
2580
2581 ADDRESS_REG with non-zero "%0, <addr_const>"
2582 offset
2583
2584 ADDRESS_REG_INDEX "rA, RB"
2585 (if rA is r0, rA and rB are swapped)
2586
2587 ADDRESS_CONST_INT "r0, <addr_const>"
2588
2589 ADDRESS_SYMBOLIC "rBase, <addr_const>"
2590 (rBase is a base register suitable for the
2591 symbol's type)
2592 */
2593
2594 void
2595 print_operand_address (FILE * file, rtx addr)
2596 {
2597 struct microblaze_address_info info;
2598 enum microblaze_address_type type;
2599 if (!microblaze_classify_address (&info, addr, GET_MODE (addr), 2))
2600 fatal_insn ("insn contains an invalid address !", addr);
2601
2602 type = info.type;
2603 switch (info.type)
2604 {
2605 case ADDRESS_REG:
2606 fprintf (file, "%s,", reg_names[REGNO (info.regA)]);
2607 output_addr_const (file, info.offset);
2608 break;
2609 case ADDRESS_REG_INDEX:
2610 if (REGNO (info.regA) == 0)
2611 /* Make rB == r0 instead of rA == r0. This helps reduce read port
2612 congestion. */
2613 fprintf (file, "%s,%s", reg_names[REGNO (info.regB)],
2614 reg_names[REGNO (info.regA)]);
2615 else if (REGNO (info.regB) != 0)
2616 /* This is a silly swap to help Dhrystone. */
2617 fprintf (file, "%s,%s", reg_names[REGNO (info.regB)],
2618 reg_names[REGNO (info.regA)]);
2619 break;
2620 case ADDRESS_CONST_INT:
2621 fprintf (file, "%s,", reg_names[REGNO (info.regA)]);
2622 output_addr_const (file, info.offset);
2623 break;
2624 case ADDRESS_SYMBOLIC:
2625 case ADDRESS_SYMBOLIC_TXT_REL:
2626 case ADDRESS_GOTOFF:
2627 case ADDRESS_PLT:
2628 case ADDRESS_TLS:
2629 if (info.regA)
2630 fprintf (file, "%s,", reg_names[REGNO (info.regA)]);
2631 output_addr_const (file, info.symbol);
2632 if (type == ADDRESS_GOTOFF)
2633 {
2634 fputs ("@GOT", file);
2635 }
2636 else if (type == ADDRESS_PLT)
2637 {
2638 fputs ("@PLT", file);
2639 }
2640 else if (type == ADDRESS_SYMBOLIC_TXT_REL)
2641 {
2642 if (info.offset != NULL && CONST_INT_P (info.offset)
2643 && INTVAL (info.offset) > 0)
2644 {
2645 fprintf (file, "+");
2646 output_addr_const (file, info.offset);
2647 }
2648 fputs ("@TXTREL", file);
2649 }
2650 else if (type == ADDRESS_TLS)
2651 {
2652 switch (info.tls_type)
2653 {
2654 case TLS_GD:
2655 fputs ("@TLSGD", file);
2656 break;
2657 case TLS_LDM:
2658 fputs ("@TLSLDM", file);
2659 break;
2660 case TLS_DTPREL:
2661 fputs ("@TLSDTPREL", file);
2662 break;
2663 default :
2664 gcc_unreachable ();
2665 break;
2666 }
2667 }
2668 break;
2669 case ADDRESS_INVALID:
2670 fatal_insn ("invalid address", addr);
2671 break;
2672 }
2673 }
2674
2675 /* Emit either a label, .comm, or .lcomm directive, and mark that the symbol
2676 is used, so that we don't emit an .extern for it in
2677 microblaze_asm_file_end. */
2678
2679 void
2680 microblaze_declare_object (FILE * stream, const char *name,
2681 const char *section, const char *fmt, int size)
2682 {
2683
2684 fputs (section, stream);
2685 assemble_name (stream, name);
2686 fprintf (stream, fmt, size);
2687 }
2688
2689 /* Common code to emit the insns (or to write the instructions to a file)
2690 to save/restore registers.
2691
2692 Other parts of the code assume that MICROBLAZE_TEMP1_REGNUM (aka large_reg)
2693 is not modified within save_restore_insns. */
2694
2695 #define BITSET_P(VALUE,BIT) (((VALUE) & (1L << (BIT))) != 0)
2696
2697 /* Save or restore instructions based on whether this is the prologue or
2698 epilogue. prologue is 1 for the prologue. */
2699 static void
2700 save_restore_insns (int prologue)
2701 {
2702 rtx base_reg_rtx, reg_rtx, mem_rtx, /* msr_rtx, */ isr_reg_rtx =
2703 0, isr_mem_rtx = 0;
2704 rtx isr_msr_rtx = 0, insn;
2705 long mask = current_frame_info.mask;
2706 HOST_WIDE_INT gp_offset;
2707 int regno;
2708
2709 if (frame_pointer_needed
2710 && !BITSET_P (mask, HARD_FRAME_POINTER_REGNUM - GP_REG_FIRST))
2711 gcc_unreachable ();
2712
2713 if (mask == 0)
2714 return;
2715
2716 /* Save registers starting from high to low. The debuggers prefer at least
2717 the return register be stored at func+4, and also it allows us not to
2718 need a nop in the epilog if at least one register is reloaded in
2719 addition to return address. */
2720
2721 /* Pick which pointer to use as a base register. For small frames, just
2722 use the stack pointer. Otherwise, use a temporary register. Save 2
2723 cycles if the save area is near the end of a large frame, by reusing
2724 the constant created in the prologue/epilogue to adjust the stack
2725 frame. */
2726
2727 gp_offset = current_frame_info.gp_offset;
2728
2729 gcc_assert (gp_offset > 0);
2730
2731 base_reg_rtx = stack_pointer_rtx;
2732
2733 /* For interrupt_handlers, need to save/restore the MSR. */
2734 if (microblaze_is_interrupt_variant ())
2735 {
2736 isr_mem_rtx = gen_rtx_MEM (SImode,
2737 gen_rtx_PLUS (Pmode, base_reg_rtx,
2738 GEN_INT (current_frame_info.
2739 gp_offset -
2740 UNITS_PER_WORD)));
2741
2742 /* Do not optimize in flow analysis. */
2743 MEM_VOLATILE_P (isr_mem_rtx) = 1;
2744 isr_reg_rtx = gen_rtx_REG (SImode, MB_ABI_MSR_SAVE_REG);
2745 isr_msr_rtx = gen_rtx_REG (SImode, ST_REG);
2746 }
2747
2748 if (microblaze_is_interrupt_variant () && !prologue)
2749 {
2750 emit_move_insn (isr_reg_rtx, isr_mem_rtx);
2751 emit_move_insn (isr_msr_rtx, isr_reg_rtx);
2752 /* Do not optimize in flow analysis. */
2753 emit_insn (gen_rtx_USE (SImode, isr_reg_rtx));
2754 emit_insn (gen_rtx_USE (SImode, isr_msr_rtx));
2755 }
2756
2757 for (regno = GP_REG_FIRST; regno <= GP_REG_LAST; regno++)
2758 {
2759 if (BITSET_P (mask, regno - GP_REG_FIRST))
2760 {
2761 if (regno == MB_ABI_SUB_RETURN_ADDR_REGNUM)
2762 /* Don't handle here. Already handled as the first register. */
2763 continue;
2764
2765 reg_rtx = gen_rtx_REG (SImode, regno);
2766 insn = gen_rtx_PLUS (Pmode, base_reg_rtx, GEN_INT (gp_offset));
2767 mem_rtx = gen_rtx_MEM (SImode, insn);
2768 if (microblaze_is_interrupt_variant () || save_volatiles)
2769 /* Do not optimize in flow analysis. */
2770 MEM_VOLATILE_P (mem_rtx) = 1;
2771
2772 if (prologue)
2773 {
2774 insn = emit_move_insn (mem_rtx, reg_rtx);
2775 RTX_FRAME_RELATED_P (insn) = 1;
2776 }
2777 else
2778 {
2779 insn = emit_move_insn (reg_rtx, mem_rtx);
2780 }
2781
2782 gp_offset += GET_MODE_SIZE (SImode);
2783 }
2784 }
2785
2786 if (microblaze_is_interrupt_variant () && prologue)
2787 {
2788 emit_move_insn (isr_reg_rtx, isr_msr_rtx);
2789 emit_move_insn (isr_mem_rtx, isr_reg_rtx);
2790
2791 /* Do not optimize in flow analysis. */
2792 emit_insn (gen_rtx_USE (SImode, isr_reg_rtx));
2793 emit_insn (gen_rtx_USE (SImode, isr_msr_rtx));
2794 }
2795
2796 /* Done saving and restoring */
2797 }
2798
2799
2800 /* Set up the stack and frame (if desired) for the function. */
2801 static void
2802 microblaze_function_prologue (FILE * file)
2803 {
2804 const char *fnname;
2805 long fsiz = current_frame_info.total_size;
2806
2807 /* Get the function name the same way that toplev.cc does before calling
2808 assemble_start_function. This is needed so that the name used here
2809 exactly matches the name used in ASM_DECLARE_FUNCTION_NAME. */
2810 fnname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
2811 if (!flag_inhibit_size_directive)
2812 {
2813 fputs ("\t.ent\t", file);
2814 if (interrupt_handler && strcmp (INTERRUPT_HANDLER_NAME, fnname))
2815 fputs ("_interrupt_handler", file);
2816 else if (break_handler && strcmp (BREAK_HANDLER_NAME, fnname))
2817 fputs ("_break_handler", file);
2818 else if (fast_interrupt && strcmp (FAST_INTERRUPT_NAME, fnname))
2819 fputs ("_fast_interrupt", file);
2820 else
2821 assemble_name (file, fnname);
2822 fputs ("\n", file);
2823 if (!microblaze_is_interrupt_variant ())
2824 ASM_OUTPUT_TYPE_DIRECTIVE (file, fnname, "function");
2825 }
2826
2827 ASM_OUTPUT_FUNCTION_LABEL (file, fnname, current_function_decl);
2828
2829 if (interrupt_handler && strcmp (INTERRUPT_HANDLER_NAME, fnname))
2830 fputs ("_interrupt_handler:\n", file);
2831 if (break_handler && strcmp (BREAK_HANDLER_NAME, fnname))
2832 fputs ("_break_handler:\n", file);
2833 if (!flag_inhibit_size_directive)
2834 {
2835 /* .frame FRAMEREG, FRAMESIZE, RETREG. */
2836 fprintf (file,
2837 "\t.frame\t%s,%ld,%s\t\t# vars= %ld, regs= %d, args= %d\n",
2838 (reg_names[(frame_pointer_needed)
2839 ? HARD_FRAME_POINTER_REGNUM :
2840 STACK_POINTER_REGNUM]), fsiz,
2841 reg_names[MB_ABI_SUB_RETURN_ADDR_REGNUM + GP_REG_FIRST],
2842 current_frame_info.var_size, current_frame_info.num_gp,
2843 (int) crtl->outgoing_args_size);
2844 fprintf (file, "\t.mask\t0x%08lx\n", current_frame_info.mask);
2845 }
2846 }
2847
2848 /* Output extra assembler code at the end of a prologue. */
2849 static void
2850 microblaze_function_end_prologue (FILE * file)
2851 {
2852 if (TARGET_STACK_CHECK)
2853 {
2854 fprintf (file, "\t# Stack Check Stub -- Start.\n\t");
2855 fprintf (file, "ori\tr18,r0,_stack_end\n\t");
2856 fprintf (file, "cmpu\tr18,r1,r18\n\t");
2857 fprintf (file, "bgei\tr18,_stack_overflow_exit\n\t");
2858 fprintf (file, "# Stack Check Stub -- End.\n");
2859 }
2860 }
2861
2862 static void
2863 microblaze_elf_asm_cdtor (rtx symbol, int priority, bool is_ctor)
2864 {
2865 section *s;
2866
2867 if (priority != DEFAULT_INIT_PRIORITY)
2868 {
2869 char buf[18];
2870 sprintf (buf, "%s.%.5u",
2871 is_ctor ? ".ctors" : ".dtors",
2872 MAX_INIT_PRIORITY - priority);
2873 s = get_section (buf, SECTION_WRITE, NULL_TREE);
2874 }
2875 else if (is_ctor)
2876 s = ctors_section;
2877 else
2878 s = dtors_section;
2879
2880 switch_to_section (s);
2881 assemble_align (POINTER_SIZE);
2882 fputs ("\t.word\t", asm_out_file);
2883 output_addr_const (asm_out_file, symbol);
2884 fputs ("\n", asm_out_file);
2885 }
2886
2887 /* Add a function to the list of static constructors. */
2888
2889 static void
2890 microblaze_elf_asm_constructor (rtx symbol, int priority)
2891 {
2892 microblaze_elf_asm_cdtor (symbol, priority, /*is_ctor=*/true);
2893 }
2894
2895 /* Add a function to the list of static destructors. */
2896
2897 static void
2898 microblaze_elf_asm_destructor (rtx symbol, int priority)
2899 {
2900 microblaze_elf_asm_cdtor (symbol, priority, /*is_ctor=*/false);
2901 }
2902
2903 /* Expand the prologue into a bunch of separate insns. */
2904
2905 void
2906 microblaze_expand_prologue (void)
2907 {
2908 int regno;
2909 HOST_WIDE_INT fsiz;
2910 const char *arg_name = 0;
2911 tree fndecl = current_function_decl;
2912 tree fntype = TREE_TYPE (fndecl);
2913 tree fnargs = DECL_ARGUMENTS (fndecl);
2914 rtx next_arg_reg;
2915 int i;
2916 tree next_arg;
2917 tree cur_arg;
2918 CUMULATIVE_ARGS args_so_far_v;
2919 cumulative_args_t args_so_far;
2920 rtx mem_rtx, reg_rtx;
2921
2922 /* If struct value address is treated as the first argument, make it so. */
2923 if (aggregate_value_p (DECL_RESULT (fndecl), fntype)
2924 && !cfun->returns_pcc_struct)
2925 {
2926 tree type = build_pointer_type (fntype);
2927 tree function_result_decl = build_decl (BUILTINS_LOCATION, PARM_DECL,
2928 NULL_TREE, type);
2929
2930 DECL_ARG_TYPE (function_result_decl) = type;
2931 TREE_CHAIN (function_result_decl) = fnargs;
2932 fnargs = function_result_decl;
2933 }
2934
2935 /* Determine the last argument, and get its name. */
2936
2937 INIT_CUMULATIVE_ARGS (args_so_far_v, fntype, NULL_RTX, 0, 0);
2938 args_so_far = pack_cumulative_args (&args_so_far_v);
2939 regno = GP_ARG_FIRST;
2940
2941 for (cur_arg = fnargs; cur_arg != 0; cur_arg = next_arg)
2942 {
2943 tree passed_type = DECL_ARG_TYPE (cur_arg);
2944 machine_mode passed_mode = TYPE_MODE (passed_type);
2945 rtx entry_parm;
2946
2947 if (TREE_ADDRESSABLE (passed_type))
2948 {
2949 passed_type = build_pointer_type (passed_type);
2950 passed_mode = Pmode;
2951 }
2952
2953 function_arg_info arg (passed_type, passed_mode, /*named=*/true);
2954 entry_parm = targetm.calls.function_arg (args_so_far, arg);
2955
2956 if (entry_parm)
2957 {
2958 int words;
2959
2960 /* passed in a register, so will get homed automatically. */
2961 if (GET_MODE (entry_parm) == BLKmode)
2962 words = (int_size_in_bytes (passed_type) + 3) / 4;
2963 else
2964 words = (GET_MODE_SIZE (GET_MODE (entry_parm)) + 3) / 4;
2965
2966 regno = REGNO (entry_parm) + words - 1;
2967 }
2968 else
2969 {
2970 regno = GP_ARG_LAST + 1;
2971 break;
2972 }
2973
2974 targetm.calls.function_arg_advance (args_so_far, arg);
2975
2976 next_arg = TREE_CHAIN (cur_arg);
2977 if (next_arg == 0)
2978 {
2979 if (DECL_NAME (cur_arg))
2980 arg_name = IDENTIFIER_POINTER (DECL_NAME (cur_arg));
2981
2982 break;
2983 }
2984 }
2985
2986 /* Split parallel insn into a sequence of insns. */
2987
2988 next_arg_reg = targetm.calls.function_arg (args_so_far,
2989 function_arg_info::end_marker ());
2990 if (next_arg_reg != 0 && GET_CODE (next_arg_reg) == PARALLEL)
2991 {
2992 rtvec adjust = XVEC (next_arg_reg, 0);
2993 int num = GET_NUM_ELEM (adjust);
2994
2995 for (i = 0; i < num; i++)
2996 {
2997 rtx pattern = RTVEC_ELT (adjust, i);
2998 emit_insn (pattern);
2999 }
3000 }
3001
3002 fsiz = compute_frame_size (get_frame_size ());
3003
3004 if (flag_stack_usage_info)
3005 current_function_static_stack_size = fsiz;
3006
3007 /* If this function is a varargs function, store any registers that
3008 would normally hold arguments ($5 - $10) on the stack. */
3009 if (((TYPE_ARG_TYPES (fntype) != 0
3010 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
3011 != void_type_node))
3012 || (arg_name != 0
3013 && ((arg_name[0] == '_'
3014 && strcmp (arg_name, "__builtin_va_alist") == 0)
3015 || (arg_name[0] == 'v'
3016 && strcmp (arg_name, "va_alist") == 0)))))
3017 {
3018 int offset = (regno - GP_ARG_FIRST + 1) * UNITS_PER_WORD;
3019 rtx ptr = stack_pointer_rtx;
3020
3021 /* If we are doing svr4-abi, sp has already been decremented by fsiz. */
3022 for (; regno <= GP_ARG_LAST; regno++)
3023 {
3024 if (offset != 0)
3025 ptr = gen_rtx_PLUS (Pmode, stack_pointer_rtx, GEN_INT (offset));
3026 emit_move_insn (gen_rtx_MEM (SImode, ptr),
3027 gen_rtx_REG (SImode, regno));
3028
3029 offset += GET_MODE_SIZE (SImode);
3030 }
3031 }
3032
3033 if (fsiz > 0)
3034 {
3035 rtx fsiz_rtx = GEN_INT (fsiz);
3036
3037 rtx_insn *insn = NULL;
3038 insn = emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx,
3039 fsiz_rtx));
3040 if (insn)
3041 RTX_FRAME_RELATED_P (insn) = 1;
3042
3043 /* Handle SUB_RETURN_ADDR_REGNUM specially at first. */
3044 if (!crtl->is_leaf || interrupt_handler)
3045 {
3046 mem_rtx = gen_rtx_MEM (SImode,
3047 gen_rtx_PLUS (Pmode, stack_pointer_rtx,
3048 const0_rtx));
3049
3050 if (interrupt_handler)
3051 /* Do not optimize in flow analysis. */
3052 MEM_VOLATILE_P (mem_rtx) = 1;
3053
3054 reg_rtx = gen_rtx_REG (SImode, MB_ABI_SUB_RETURN_ADDR_REGNUM);
3055 insn = emit_move_insn (mem_rtx, reg_rtx);
3056 RTX_FRAME_RELATED_P (insn) = 1;
3057 }
3058
3059 /* _save_ registers for prologue. */
3060 save_restore_insns (1);
3061
3062 if (frame_pointer_needed)
3063 {
3064 rtx_insn *insn = 0;
3065
3066 insn = emit_insn (gen_movsi (hard_frame_pointer_rtx,
3067 stack_pointer_rtx));
3068
3069 if (insn)
3070 RTX_FRAME_RELATED_P (insn) = 1;
3071 }
3072 }
3073
3074 if ((flag_pic == 2 || TLS_NEEDS_GOT )
3075 && df_regs_ever_live_p (MB_ABI_PIC_ADDR_REGNUM))
3076 {
3077 if ((flag_pic == 2 && !TARGET_PIC_DATA_TEXT_REL) || TLS_NEEDS_GOT)
3078 {
3079 SET_REGNO (pic_offset_table_rtx, MB_ABI_PIC_ADDR_REGNUM);
3080 /* setting GOT. */
3081 emit_insn (gen_set_got (pic_offset_table_rtx));
3082 }
3083 else
3084 {
3085 SET_REGNO (pic_offset_table_rtx, MB_ABI_PIC_ADDR_REGNUM);
3086 /* setting start of text. */
3087 emit_insn (gen_set_text (pic_offset_table_rtx));
3088 }
3089 }
3090
3091 /* If we are profiling, make sure no instructions are scheduled before
3092 the call to mcount. */
3093
3094 if (profile_flag)
3095 emit_insn (gen_blockage ());
3096 }
3097
3098 /* Do necessary cleanup after a function to restore stack, frame, and regs. */
3099
3100 #define RA_MASK ((long) 0x80000000) /* 1 << 31 */
3101 #define PIC_OFFSET_TABLE_MASK (1 << (PIC_OFFSET_TABLE_REGNUM - GP_REG_FIRST))
3102
3103 static void
3104 microblaze_function_epilogue (FILE *file)
3105 {
3106 const char *fnname;
3107
3108 /* Get the function name the same way that toplev.cc does before calling
3109 assemble_start_function. This is needed so that the name used here
3110 exactly matches the name used in ASM_DECLARE_FUNCTION_NAME. */
3111 fnname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
3112
3113 if (!flag_inhibit_size_directive)
3114 {
3115 fputs ("\t.end\t", file);
3116 if (interrupt_handler && !break_handler)
3117 fputs ("_interrupt_handler", file);
3118 else if (break_handler)
3119 fputs ("_break_handler", file);
3120 else
3121 assemble_name (file, fnname);
3122 fputs ("\n", file);
3123 }
3124
3125 /* Reset state info for each function. */
3126 current_frame_info = zero_frame_info;
3127
3128 /* Restore the output file if optimizing the GP (optimizing the GP causes
3129 the text to be diverted to a tempfile, so that data decls come before
3130 references to the data). */
3131 }
3132
3133 /* Expand the epilogue into a bunch of separate insns. */
3134
3135 void
3136 microblaze_expand_epilogue (void)
3137 {
3138 HOST_WIDE_INT fsiz = current_frame_info.total_size;
3139 rtx fsiz_rtx = GEN_INT (fsiz);
3140 rtx reg_rtx;
3141 rtx mem_rtx;
3142
3143 /* In case of interrupt handlers use addki instead of addi for changing the
3144 stack pointer value. */
3145
3146 if (microblaze_can_use_return_insn ())
3147 {
3148 emit_jump_insn (gen_return_internal (gen_rtx_REG (Pmode,
3149 GP_REG_FIRST +
3150 MB_ABI_SUB_RETURN_ADDR_REGNUM)));
3151 return;
3152 }
3153
3154 if (fsiz > 0)
3155 {
3156 /* Restore SUB_RETURN_ADDR_REGNUM at first. This is to prevent the
3157 sequence of load-followed by a use (in rtsd) in every prologue. Saves
3158 a load-use stall cycle :) This is also important to handle alloca.
3159 (See comments for if (frame_pointer_needed) below. */
3160
3161 if (!crtl->is_leaf || interrupt_handler)
3162 {
3163 mem_rtx =
3164 gen_rtx_MEM (SImode,
3165 gen_rtx_PLUS (Pmode, stack_pointer_rtx, const0_rtx));
3166 if (interrupt_handler)
3167 /* Do not optimize in flow analysis. */
3168 MEM_VOLATILE_P (mem_rtx) = 1;
3169 reg_rtx = gen_rtx_REG (SImode, MB_ABI_SUB_RETURN_ADDR_REGNUM);
3170 emit_move_insn (reg_rtx, mem_rtx);
3171 }
3172
3173 /* It is important that this is done after we restore the return address
3174 register (above). When alloca is used, we want to restore the
3175 sub-routine return address only from the current stack top and not
3176 from the frame pointer (which we restore below). (frame_pointer + 0)
3177 might have been over-written since alloca allocates memory on the
3178 current stack. */
3179 if (frame_pointer_needed)
3180 emit_insn (gen_movsi (stack_pointer_rtx, hard_frame_pointer_rtx));
3181
3182 /* _restore_ registers for epilogue. */
3183 save_restore_insns (0);
3184 emit_insn (gen_blockage ());
3185 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, fsiz_rtx));
3186 }
3187
3188 if (crtl->calls_eh_return)
3189 emit_insn (gen_addsi3 (stack_pointer_rtx,
3190 stack_pointer_rtx,
3191 gen_raw_REG (SImode,
3192 MB_EH_STACKADJ_REGNUM)));
3193
3194 emit_jump_insn (gen_return_internal (gen_rtx_REG (Pmode, GP_REG_FIRST +
3195 MB_ABI_SUB_RETURN_ADDR_REGNUM)));
3196 }
3197
3198
3199 /* Return nonzero if this function is known to have a null epilogue.
3200 This allows the optimizer to omit jumps to jumps if no stack
3201 was created. */
3202
3203 int
3204 microblaze_can_use_return_insn (void)
3205 {
3206 if (!reload_completed)
3207 return 0;
3208
3209 if (df_regs_ever_live_p (MB_ABI_SUB_RETURN_ADDR_REGNUM) || profile_flag)
3210 return 0;
3211
3212 if (current_frame_info.initialized)
3213 return current_frame_info.total_size == 0;
3214
3215 return compute_frame_size (get_frame_size ()) == 0;
3216 }
3217
3218 /* Implement TARGET_SECONDARY_RELOAD. */
3219
3220 static reg_class_t
3221 microblaze_secondary_reload (bool in_p ATTRIBUTE_UNUSED, rtx x ATTRIBUTE_UNUSED,
3222 reg_class_t rclass, machine_mode mode ATTRIBUTE_UNUSED,
3223 secondary_reload_info *sri ATTRIBUTE_UNUSED)
3224 {
3225 if (rclass == ST_REGS)
3226 return GR_REGS;
3227
3228 return NO_REGS;
3229 }
3230
3231 static void
3232 microblaze_globalize_label (FILE * stream, const char *name)
3233 {
3234 fputs ("\t.globl\t", stream);
3235 if (microblaze_is_interrupt_variant ())
3236 {
3237 if (interrupt_handler && strcmp (name, INTERRUPT_HANDLER_NAME))
3238 fputs (INTERRUPT_HANDLER_NAME, stream);
3239 else if (break_handler && strcmp (name, BREAK_HANDLER_NAME))
3240 fputs (BREAK_HANDLER_NAME, stream);
3241 else if (fast_interrupt && strcmp (name, FAST_INTERRUPT_NAME))
3242 fputs (FAST_INTERRUPT_NAME, stream);
3243 fputs ("\n\t.globl\t", stream);
3244 }
3245 assemble_name (stream, name);
3246 fputs ("\n", stream);
3247 }
3248
3249 /* Returns true if decl should be placed into a "small data" section. */
3250 static bool
3251 microblaze_elf_in_small_data_p (const_tree decl)
3252 {
3253 HOST_WIDE_INT size;
3254
3255 if (!TARGET_XLGPOPT)
3256 return false;
3257
3258 /* We want to merge strings, so we never consider them small data. */
3259 if (TREE_CODE (decl) == STRING_CST)
3260 return false;
3261
3262 /* Functions are never in the small data area. */
3263 if (TREE_CODE (decl) == FUNCTION_DECL)
3264 return false;
3265
3266 if (VAR_P (decl) && DECL_SECTION_NAME (decl))
3267 {
3268 const char *section = DECL_SECTION_NAME (decl);
3269 if (strcmp (section, ".sdata") == 0
3270 || strcmp (section, ".sdata2") == 0
3271 || strcmp (section, ".sbss") == 0
3272 || strcmp (section, ".sbss2") == 0)
3273 return true;
3274 }
3275
3276 size = int_size_in_bytes (TREE_TYPE (decl));
3277
3278 return (size > 0 && size <= microblaze_section_threshold);
3279 }
3280
3281 /* We need to disable address diff vectors in
3282 case of pic data text relative mode. */
3283
3284 static bool
3285 microblaze_gen_pic_addr_dif_vec (void)
3286 {
3287 return (flag_pic && !TARGET_PIC_DATA_TEXT_REL);
3288 }
3289
3290 static section *
3291 microblaze_select_section (tree decl, int reloc, unsigned HOST_WIDE_INT align)
3292 {
3293 switch (categorize_decl_for_section (decl, reloc))
3294 {
3295 case SECCAT_RODATA_MERGE_STR:
3296 case SECCAT_RODATA_MERGE_STR_INIT:
3297 /* MB binutils have various issues with mergeable string sections and
3298 relaxation/relocation. Currently, turning mergeable sections
3299 into regular readonly sections. */
3300
3301 return readonly_data_section;
3302 default:
3303 return default_elf_select_section (decl, reloc, align);
3304 }
3305 }
3306
3307 /*
3308 Encode info about sections into the RTL based on a symbol's declaration.
3309 The default definition of this hook, default_encode_section_info in
3310 `varasm.cc', sets a number of commonly-useful bits in SYMBOL_REF_FLAGS. */
3311
3312 static void
3313 microblaze_encode_section_info (tree decl, rtx rtl, int first)
3314 {
3315 default_encode_section_info (decl, rtl, first);
3316 }
3317
3318 static rtx
3319 expand_pic_symbol_ref (machine_mode mode ATTRIBUTE_UNUSED, rtx op)
3320 {
3321 rtx result;
3322 bool isFunc = (GET_CODE (op) == SYMBOL_REF
3323 && (SYMBOL_REF_FLAGS (op) & SYMBOL_FLAG_FUNCTION));
3324 result = (!TARGET_PIC_DATA_TEXT_REL)
3325 ? gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op), UNSPEC_GOTOFF)
3326 : gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op), UNSPEC_TEXT);
3327 result = gen_rtx_CONST (Pmode, result);
3328 result = (TARGET_PIC_DATA_TEXT_REL && isFunc)
3329 ? gen_rtx_PLUS (Pmode, gen_raw_REG (Pmode,
3330 get_base_reg (op)), result)
3331 : gen_rtx_PLUS (Pmode, pic_offset_table_rtx, result);
3332 result = (!TARGET_PIC_DATA_TEXT_REL)
3333 ? gen_const_mem (Pmode, result) : result;
3334
3335 return result;
3336 }
3337
3338 static void
3339 microblaze_asm_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
3340 HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
3341 tree function)
3342 {
3343 const char *fnname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (thunk_fndecl));
3344 rtx this_rtx, funexp;
3345 rtx_insn *insn;
3346
3347 reload_completed = 1;
3348 epilogue_completed = 1;
3349
3350 /* Mark the end of the (empty) prologue. */
3351 emit_note (NOTE_INSN_PROLOGUE_END);
3352
3353 /* Find the "this" pointer. If the function returns a structure,
3354 the structure return pointer is in MB_ABI_FIRST_ARG_REGNUM. */
3355 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function))
3356 this_rtx = gen_rtx_REG (Pmode, (MB_ABI_FIRST_ARG_REGNUM + 1));
3357 else
3358 this_rtx = gen_rtx_REG (Pmode, MB_ABI_FIRST_ARG_REGNUM);
3359
3360 /* Apply the constant offset, if required. */
3361 if (delta)
3362 emit_insn (gen_addsi3 (this_rtx, this_rtx, GEN_INT (delta)));
3363
3364 /* Apply the offset from the vtable, if required. */
3365 if (vcall_offset)
3366 {
3367 rtx vcall_offset_rtx = GEN_INT (vcall_offset);
3368 rtx temp1 = gen_rtx_REG (Pmode, MB_ABI_TEMP1_REGNUM);
3369
3370 emit_move_insn (temp1, gen_rtx_MEM (Pmode, this_rtx));
3371
3372 rtx loc = gen_rtx_PLUS (Pmode, temp1, vcall_offset_rtx);
3373 emit_move_insn (temp1, gen_rtx_MEM (Pmode, loc));
3374
3375 emit_insn (gen_addsi3 (this_rtx, this_rtx, temp1));
3376 }
3377
3378 /* Generate a tail call to the target function. */
3379 if (!TREE_USED (function))
3380 {
3381 assemble_external (function);
3382 TREE_USED (function) = 1;
3383 }
3384
3385 funexp = XEXP (DECL_RTL (function), 0);
3386 rtx temp2 = gen_rtx_REG (Pmode, MB_ABI_TEMP2_REGNUM);
3387
3388 if (flag_pic)
3389 emit_move_insn (temp2, expand_pic_symbol_ref (Pmode, funexp));
3390 else
3391 emit_move_insn (temp2, funexp);
3392
3393 emit_insn (gen_indirect_jump (temp2));
3394
3395 /* Run just enough of rest_of_compilation. This sequence was
3396 "borrowed" from rs6000.cc. */
3397 insn = get_insns ();
3398 shorten_branches (insn);
3399 assemble_start_function (thunk_fndecl, fnname);
3400 final_start_function (insn, file, 1);
3401 final (insn, file, 1);
3402 final_end_function ();
3403 assemble_end_function (thunk_fndecl, fnname);
3404
3405 reload_completed = 0;
3406 epilogue_completed = 0;
3407 }
3408
3409 bool
3410 microblaze_expand_move (machine_mode mode, rtx operands[])
3411 {
3412 rtx op0, op1;
3413
3414 op0 = operands[0];
3415 op1 = operands[1];
3416
3417 if (!register_operand (op0, SImode)
3418 && !register_operand (op1, SImode)
3419 && (GET_CODE (op1) != CONST_INT || INTVAL (op1) != 0))
3420 {
3421 rtx temp = force_reg (SImode, op1);
3422 emit_move_insn (op0, temp);
3423 return true;
3424 }
3425 /* If operands[1] is a constant address invalid for pic, then we need to
3426 handle it just like LEGITIMIZE_ADDRESS does. */
3427 if (GET_CODE (op1) == SYMBOL_REF || GET_CODE (op1) == LABEL_REF)
3428 {
3429 rtx result;
3430 if (microblaze_tls_symbol_p(op1))
3431 {
3432 result = microblaze_legitimize_tls_address (op1, NULL_RTX);
3433 emit_move_insn (op0, result);
3434 return true;
3435 }
3436 else if (flag_pic)
3437 {
3438 if (reload_in_progress)
3439 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
3440 result = expand_pic_symbol_ref (mode, op1);
3441
3442 if (TARGET_PIC_DATA_TEXT_REL && GET_CODE (op0) == REG
3443 && REGNO (op0) >= FIRST_PSEUDO_REGISTER)
3444 result = force_reg (SImode, result);
3445
3446 emit_move_insn (op0, result);
3447 return true;
3448 }
3449 }
3450 if (GET_CODE (op1) == PLUS && GET_CODE (XEXP (op1,1)) == CONST)
3451 {
3452 rtx p0, p1 = NULL, result, temp;
3453
3454 p0 = XEXP (XEXP (op1,1), 0);
3455
3456 if (GET_CODE (p0) == PLUS)
3457 {
3458 p1 = XEXP (p0, 1);
3459 p0 = XEXP (p0, 0);
3460 }
3461
3462 /* This should never happen. */
3463 if (p1 == NULL)
3464 gcc_unreachable ();
3465
3466 if (GET_CODE (p0) == UNSPEC && GET_CODE (p1) == CONST_INT
3467 && flag_pic && TARGET_PIC_DATA_TEXT_REL)
3468 {
3469 result = gen_rtx_CONST (Pmode, p0);
3470 result = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, result);
3471 temp = force_reg (SImode, result);
3472 emit_move_insn (op0, gen_rtx_PLUS (SImode, temp, p1));
3473 return true;
3474 }
3475 }
3476 /* Handle Case of (const (plus symbol const_int)). */
3477 if (GET_CODE (op1) == CONST && GET_CODE (XEXP (op1,0)) == PLUS)
3478 {
3479 rtx p0, p1;
3480
3481 p0 = XEXP (XEXP (op1, 0), 0);
3482 p1 = XEXP (XEXP (op1, 0), 1);
3483
3484 if ((GET_CODE (p1) == CONST_INT)
3485 && ((GET_CODE (p0) == UNSPEC)
3486 || ((GET_CODE (p0) == SYMBOL_REF || GET_CODE (p0) == LABEL_REF)
3487 && (flag_pic == 2 || microblaze_tls_symbol_p (p0)
3488 || !SMALL_INT (p1)))))
3489 {
3490 rtx temp = force_reg (SImode, p0);
3491 rtx temp2 = p1;
3492
3493 if (flag_pic && reload_in_progress)
3494 df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
3495 emit_move_insn (op0, gen_rtx_PLUS (SImode, temp, temp2));
3496 return true;
3497 }
3498 }
3499 return false;
3500 }
3501
3502 /* Expand shift operations. */
3503 int
3504 microblaze_expand_shift (rtx operands[])
3505 {
3506 gcc_assert ((GET_CODE (operands[2]) == CONST_INT)
3507 || (GET_CODE (operands[2]) == REG)
3508 || (GET_CODE (operands[2]) == SUBREG));
3509
3510 /* Shift by one -- generate pattern. */
3511 if ((GET_CODE (operands[2]) == CONST_INT) && (INTVAL (operands[2]) == 1))
3512 return 0;
3513
3514 /* Have barrel shifter and shift > 1: use it. */
3515 if (TARGET_BARREL_SHIFT)
3516 return 0;
3517
3518 gcc_assert ((GET_CODE (operands[0]) == REG)
3519 || (GET_CODE (operands[0]) == SUBREG)
3520 || (GET_CODE (operands[1]) == REG)
3521 || (GET_CODE (operands[1]) == SUBREG));
3522
3523 /* Shift by zero -- copy regs if necessary. */
3524 if (operands[2] == const0_rtx
3525 && !rtx_equal_p (operands[0], operands[1]))
3526 {
3527 emit_insn (gen_movsi (operands[0], operands[1]));
3528 return 1;
3529 }
3530
3531 return 0;
3532 }
3533
3534 /* Return an RTX indicating where the return address to the
3535 calling function can be found. */
3536 rtx
3537 microblaze_return_addr (int count, rtx frame ATTRIBUTE_UNUSED)
3538 {
3539 if (count != 0)
3540 return NULL_RTX;
3541
3542 return get_hard_reg_initial_val (Pmode,
3543 MB_ABI_SUB_RETURN_ADDR_REGNUM);
3544 }
3545
3546 void
3547 microblaze_eh_return (rtx op0)
3548 {
3549 emit_insn (gen_movsi (gen_rtx_MEM (Pmode, stack_pointer_rtx), op0));
3550 }
3551
3552 /* Queue an .ident string in the queue of top-level asm statements.
3553 If the string size is below the threshold, put it into .sdata2.
3554 If the front-end is done, we must be being called from toplev.cc.
3555 In that case, do nothing. */
3556 void
3557 microblaze_asm_output_ident (const char *string)
3558 {
3559 const char *section_asm_op;
3560 int size;
3561 char *buf;
3562
3563 if (symtab->state != PARSING)
3564 return;
3565
3566 size = strlen (string) + 1;
3567 if (size <= microblaze_section_threshold)
3568 section_asm_op = SDATA2_SECTION_ASM_OP;
3569 else
3570 section_asm_op = READONLY_DATA_SECTION_ASM_OP;
3571
3572 buf = ACONCAT (("\t.pushsection", section_asm_op,
3573 "\n\t.ascii \"", string, "\\0\"\n",
3574 "\t.popsection\n", NULL));
3575 symtab->finalize_toplevel_asm (build_string (strlen (buf), buf));
3576 }
3577
3578 static void
3579 microblaze_elf_asm_init_sections (void)
3580 {
3581 sdata2_section
3582 = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
3583 SDATA2_SECTION_ASM_OP);
3584 }
3585
3586 /* Generate assembler code for constant parts of a trampoline. */
3587
3588 static void
3589 microblaze_asm_trampoline_template (FILE *f)
3590 {
3591 fprintf (f, "\tmfs r18, rpc\n");
3592 fprintf (f, "\tlwi r3, r18, 16\n");
3593 fprintf (f, "\tlwi r18, r18, 20\n");
3594 fprintf (f, "\tbra r18\n");
3595 /* fprintf (f, "\t.word\t0x00000000\t\t# <function address>\n"); */
3596 /* fprintf (f, "\t.word\t0x00000000\t\t# <static chain value>\n"); */
3597 }
3598
3599 /* Implement TARGET_TRAMPOLINE_INIT. */
3600
3601 static void
3602 microblaze_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
3603 {
3604 rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
3605 rtx mem;
3606
3607 emit_block_move (m_tramp, assemble_trampoline_template (),
3608 GEN_INT (6*UNITS_PER_WORD), BLOCK_OP_NORMAL);
3609
3610 mem = adjust_address (m_tramp, SImode, 16);
3611 emit_move_insn (mem, chain_value);
3612 mem = adjust_address (m_tramp, SImode, 20);
3613 emit_move_insn (mem, fnaddr);
3614 }
3615
3616 /* Generate conditional branch -- first, generate test condition,
3617 second, generate correct branch instruction. */
3618
3619 void
3620 microblaze_expand_conditional_branch (machine_mode mode, rtx operands[])
3621 {
3622 enum rtx_code code = GET_CODE (operands[0]);
3623 rtx cmp_op0 = operands[1];
3624 rtx cmp_op1 = operands[2];
3625 rtx label1 = operands[3];
3626 rtx comp_reg = gen_reg_rtx (SImode);
3627 rtx condition;
3628
3629 gcc_assert ((GET_CODE (cmp_op0) == REG) || (GET_CODE (cmp_op0) == SUBREG));
3630
3631 /* If comparing against zero, just test source reg. */
3632 if (cmp_op1 == const0_rtx)
3633 {
3634 comp_reg = cmp_op0;
3635 condition = gen_rtx_fmt_ee (signed_condition (code), SImode, comp_reg, const0_rtx);
3636 emit_jump_insn (gen_condjump (condition, label1));
3637 }
3638
3639 else if (code == EQ || code == NE)
3640 {
3641 /* Use xor for equal/not-equal comparison. */
3642 emit_insn (gen_xorsi3 (comp_reg, cmp_op0, cmp_op1));
3643 condition = gen_rtx_fmt_ee (signed_condition (code), SImode, comp_reg, const0_rtx);
3644 emit_jump_insn (gen_condjump (condition, label1));
3645 }
3646 else
3647 {
3648 /* Generate compare and branch in single instruction. */
3649 cmp_op1 = force_reg (mode, cmp_op1);
3650 condition = gen_rtx_fmt_ee (code, mode, cmp_op0, cmp_op1);
3651 emit_jump_insn (gen_branch_compare(condition, cmp_op0, cmp_op1, label1));
3652 }
3653 }
3654
3655 void
3656 microblaze_expand_conditional_branch_reg (machine_mode mode, rtx operands[])
3657 {
3658 enum rtx_code code = GET_CODE (operands[0]);
3659 rtx cmp_op0 = operands[1];
3660 rtx cmp_op1 = operands[2];
3661 rtx label1 = operands[3];
3662 rtx comp_reg = gen_reg_rtx (SImode);
3663 rtx condition;
3664
3665 gcc_assert ((GET_CODE (cmp_op0) == REG)
3666 || (GET_CODE (cmp_op0) == SUBREG));
3667
3668 /* If comparing against zero, just test source reg. */
3669 if (cmp_op1 == const0_rtx)
3670 {
3671 comp_reg = cmp_op0;
3672 condition = gen_rtx_fmt_ee (signed_condition (code),
3673 SImode, comp_reg, const0_rtx);
3674 emit_jump_insn (gen_condjump (condition, label1));
3675 }
3676 else if (code == EQ)
3677 {
3678 emit_insn (gen_seq_internal_pat (comp_reg,
3679 cmp_op0, cmp_op1));
3680 condition = gen_rtx_EQ (SImode, comp_reg, const0_rtx);
3681 emit_jump_insn (gen_condjump (condition, label1));
3682 }
3683 else if (code == NE)
3684 {
3685 emit_insn (gen_sne_internal_pat (comp_reg, cmp_op0,
3686 cmp_op1));
3687 condition = gen_rtx_NE (SImode, comp_reg, const0_rtx);
3688 emit_jump_insn (gen_condjump (condition, label1));
3689 }
3690 else
3691 {
3692 /* Generate compare and branch in single instruction. */
3693 cmp_op1 = force_reg (mode, cmp_op1);
3694 condition = gen_rtx_fmt_ee (code, mode, cmp_op0, cmp_op1);
3695 emit_jump_insn (gen_branch_compare (condition, cmp_op0,
3696 cmp_op1, label1));
3697 }
3698 }
3699
3700 void
3701 microblaze_expand_conditional_branch_sf (rtx operands[])
3702 {
3703 rtx condition;
3704 rtx cmp_op0 = XEXP (operands[0], 0);
3705 rtx cmp_op1 = XEXP (operands[0], 1);
3706 rtx comp_reg = gen_reg_rtx (SImode);
3707
3708 emit_insn (gen_cstoresf4 (comp_reg, operands[0], cmp_op0, cmp_op1));
3709 condition = gen_rtx_NE (SImode, comp_reg, const0_rtx);
3710 emit_jump_insn (gen_condjump (condition, operands[3]));
3711 }
3712
3713 /* Implement TARGET_FRAME_POINTER_REQUIRED. */
3714
3715 static bool
3716 microblaze_frame_pointer_required (void)
3717 {
3718 /* If the function contains dynamic stack allocations, we need to
3719 use the frame pointer to access the static parts of the frame. */
3720 if (cfun->calls_alloca)
3721 return true;
3722 return false;
3723 }
3724
3725 void
3726 microblaze_expand_divide (rtx operands[])
3727 {
3728 /* Table lookup software divides. Works for all (nr/dr) where (0 <= nr,dr <= 15). */
3729
3730 rtx regt1 = gen_reg_rtx (SImode);
3731 rtx reg18 = gen_rtx_REG (SImode, R_TMP);
3732 rtx regqi = gen_reg_rtx (QImode);
3733 rtx_code_label *div_label = gen_label_rtx ();
3734 rtx_code_label *div_end_label = gen_label_rtx ();
3735 rtx div_table_rtx = gen_rtx_SYMBOL_REF (QImode,"_divsi3_table");
3736 rtx mem_rtx;
3737 rtx ret;
3738 rtx_insn *jump, *cjump, *insn;
3739
3740 insn = emit_insn (gen_iorsi3 (regt1, operands[1], operands[2]));
3741 cjump = emit_jump_insn_after (gen_cbranchsi4 (
3742 gen_rtx_GTU (SImode, regt1, GEN_INT (15)),
3743 regt1, GEN_INT (15), div_label), insn);
3744 LABEL_NUSES (div_label) = 1;
3745 JUMP_LABEL (cjump) = div_label;
3746 emit_insn (gen_rtx_CLOBBER (SImode, reg18));
3747
3748 emit_insn (gen_ashlsi3_bshift (regt1, operands[1], GEN_INT(4)));
3749 emit_insn (gen_addsi3 (regt1, regt1, operands[2]));
3750 mem_rtx = gen_rtx_MEM (QImode,
3751 gen_rtx_PLUS (Pmode, regt1, div_table_rtx));
3752
3753 insn = emit_insn (gen_movqi (regqi, mem_rtx));
3754 insn = emit_insn (gen_movsi (operands[0], gen_rtx_SUBREG (SImode, regqi, 0)));
3755 jump = emit_jump_insn_after (gen_jump (div_end_label), insn);
3756 JUMP_LABEL (jump) = div_end_label;
3757 LABEL_NUSES (div_end_label) = 1;
3758 emit_barrier ();
3759
3760 emit_label (div_label);
3761 ret = emit_library_call_value (gen_rtx_SYMBOL_REF (Pmode, "__divsi3"),
3762 operands[0], LCT_NORMAL,
3763 GET_MODE (operands[0]),
3764 operands[1], GET_MODE (operands[1]),
3765 operands[2], GET_MODE (operands[2]));
3766 if (ret != operands[0])
3767 emit_move_insn (operands[0], ret);
3768
3769 emit_label (div_end_label);
3770 emit_insn (gen_blockage ());
3771 }
3772
3773 /* Implement TARGET_FUNCTION_VALUE. */
3774 static rtx
3775 microblaze_function_value (const_tree valtype,
3776 const_tree func ATTRIBUTE_UNUSED,
3777 bool outgoing ATTRIBUTE_UNUSED)
3778 {
3779 return LIBCALL_VALUE (TYPE_MODE (valtype));
3780 }
3781
3782 /* Implement TARGET_SCHED_ADJUST_COST. */
3783 static int
3784 microblaze_adjust_cost (rtx_insn *, int dep_type, rtx_insn *, int cost,
3785 unsigned int)
3786 {
3787 if (dep_type == REG_DEP_OUTPUT || dep_type == 0)
3788 return cost;
3789 return 0;
3790 }
3791
3792 /* Implement TARGET_LEGITIMATE_CONSTANT_P.
3793
3794 At present, GAS doesn't understand li.[sd], so don't allow it
3795 to be generated at present. */
3796 static bool
3797 microblaze_legitimate_constant_p (machine_mode mode ATTRIBUTE_UNUSED, rtx x)
3798 {
3799
3800 if (microblaze_cannot_force_const_mem(mode, x))
3801 return false;
3802
3803 if (GET_CODE (x) == CONST_DOUBLE)
3804 {
3805 return microblaze_const_double_ok (x, GET_MODE (x));
3806 }
3807
3808 /* Handle Case of (const (plus unspec const_int)). */
3809 if (GET_CODE (x) == CONST && GET_CODE (XEXP (x,0)) == PLUS)
3810 {
3811 rtx p0, p1;
3812
3813 p0 = XEXP (XEXP (x, 0), 0);
3814 p1 = XEXP (XEXP (x, 0), 1);
3815
3816 if (GET_CODE(p1) == CONST_INT)
3817 {
3818 /* Const offset from UNSPEC is not supported. */
3819 if ((GET_CODE (p0) == UNSPEC))
3820 return false;
3821
3822 if ((GET_CODE (p0) == SYMBOL_REF || GET_CODE (p0) == LABEL_REF)
3823 && (microblaze_tls_symbol_p (p0) || !SMALL_INT (p1)))
3824 return false;
3825 }
3826 }
3827
3828 return true;
3829 }
3830
3831 static rtx
3832 get_branch_target (rtx branch)
3833 {
3834 if (CALL_P (branch))
3835 {
3836 rtx call;
3837
3838 call = XVECEXP (PATTERN (branch), 0, 0);
3839 if (GET_CODE (call) == SET)
3840 call = SET_SRC (call);
3841 if (GET_CODE (call) != CALL)
3842 gcc_unreachable ();
3843 return XEXP (XEXP (call, 0), 0);
3844 }
3845
3846 return NULL_RTX;
3847 }
3848
3849 /* Heuristics to identify where to insert at the
3850 fall through path of the caller function. If there
3851 is a call after the caller branch delay slot then
3852 we dont generate the instruction prefetch instruction.
3853
3854 Scan up to 32 instructions after the call and checks
3855 for the JUMP and call instruction . If there is a call
3856 or JUMP instruction in the range of 32 instruction "wic"
3857 instruction wont be generated. Otherwise insert the "wic"
3858 instruction in the fall through of the call instruction
3859 four instruction after the call. before_4 is used for
3860 the position to insert "wic" instructions. before_16 is
3861 used to check for call and JUMP instruction for first
3862 15 insns. */
3863
3864 static void
3865 insert_wic_for_ilb_runout (rtx_insn *first)
3866 {
3867 rtx_insn *insn;
3868 rtx_insn *before_4 = 0;
3869 rtx_insn *before_16 = 0;
3870 int addr_offset = 0;
3871 int length;
3872 int wic_addr0 = 128 * 4;
3873
3874 int first_addr = INSN_ADDRESSES (INSN_UID (first));
3875
3876 for (insn = first; insn; insn = NEXT_INSN (insn))
3877 if (INSN_P (insn))
3878 {
3879 addr_offset = INSN_ADDRESSES (INSN_UID (insn)) - first_addr;
3880 length = get_attr_length (insn);
3881 if (before_4 == 0 && addr_offset + length >= 4 * 4)
3882 before_4 = insn;
3883
3884 if (JUMP_P(insn))
3885 return;
3886 if (before_16 == 0 && addr_offset + length >= 14 * 4)
3887 before_16 = insn;
3888 if (CALL_P (insn) || tablejump_p (insn, 0, 0))
3889 return;
3890 if (addr_offset + length >= 32 * 4)
3891 {
3892 gcc_assert (before_4 && before_16);
3893 if (wic_addr0 > 4 * 4)
3894 {
3895 insn =
3896 emit_insn_before (gen_iprefetch
3897 (gen_int_mode (addr_offset, SImode)),
3898 before_4);
3899 recog_memoized (insn);
3900 INSN_LOCATION (insn) = INSN_LOCATION (before_4);
3901 INSN_ADDRESSES_NEW (insn, INSN_ADDRESSES (INSN_UID (before_4)));
3902 return;
3903 }
3904 }
3905 }
3906 }
3907
3908 /* Insert instruction prefetch instruction at the fall
3909 through path of the function call. */
3910
3911 static void
3912 insert_wic (void)
3913 {
3914 rtx_insn *insn;
3915 int i;
3916 basic_block bb, prev = 0;
3917 rtx branch_target = 0;
3918
3919 shorten_branches (get_insns ());
3920
3921 for (i = 0; i < n_basic_blocks_for_fn (cfun) - 1; i++)
3922 {
3923 edge e;
3924 edge_iterator ei;
3925 bool simple_loop = false;
3926
3927 bb = BASIC_BLOCK_FOR_FN (cfun, i);
3928
3929 if (bb == NULL)
3930 continue;
3931
3932 if ((prev != 0) && (prev != bb))
3933 continue;
3934 else
3935 prev = 0;
3936
3937 FOR_EACH_EDGE (e, ei, bb->preds)
3938 if (e->src == bb)
3939 {
3940 simple_loop = true;
3941 prev= e->dest;
3942 break;
3943 }
3944
3945 for (insn = BB_END (bb); insn; insn = PREV_INSN (insn))
3946 {
3947 if (INSN_P (insn) && !simple_loop
3948 && CALL_P(insn))
3949 {
3950 if ((branch_target = get_branch_target (insn)))
3951 insert_wic_for_ilb_runout (
3952 next_active_insn (next_active_insn (insn)));
3953 }
3954 if (insn == BB_HEAD (bb))
3955 break;
3956 }
3957 }
3958 }
3959
3960 /* The reorg function defined through the macro
3961 TARGET_MACHINE_DEPENDENT_REORG. */
3962
3963 static void
3964 microblaze_machine_dependent_reorg (void)
3965 {
3966 if (TARGET_PREFETCH)
3967 {
3968 compute_bb_for_insn ();
3969 loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
3970 shorten_branches (get_insns ());
3971 insert_wic ();
3972 loop_optimizer_finalize ();
3973 free_bb_for_insn ();
3974 return;
3975 }
3976 }
3977
3978 /* Implement TARGET_CONSTANT_ALIGNMENT. */
3979
3980 static HOST_WIDE_INT
3981 microblaze_constant_alignment (const_tree exp, HOST_WIDE_INT align)
3982 {
3983 if (TREE_CODE (exp) == STRING_CST || TREE_CODE (exp) == CONSTRUCTOR)
3984 return MAX (align, BITS_PER_WORD);
3985 return align;
3986 }
3987
3988 /* Implement TARGET_STARTING_FRAME_OFFSET. */
3989
3990 static HOST_WIDE_INT
3991 microblaze_starting_frame_offset (void)
3992 {
3993 return (crtl->outgoing_args_size + FIRST_PARM_OFFSET(FNDECL));
3994 }
3995
3996 #undef TARGET_ENCODE_SECTION_INFO
3997 #define TARGET_ENCODE_SECTION_INFO microblaze_encode_section_info
3998
3999 #undef TARGET_ASM_GLOBALIZE_LABEL
4000 #define TARGET_ASM_GLOBALIZE_LABEL microblaze_globalize_label
4001
4002 #undef TARGET_ASM_FUNCTION_PROLOGUE
4003 #define TARGET_ASM_FUNCTION_PROLOGUE microblaze_function_prologue
4004
4005 #undef TARGET_ASM_FUNCTION_EPILOGUE
4006 #define TARGET_ASM_FUNCTION_EPILOGUE microblaze_function_epilogue
4007
4008 #undef TARGET_RTX_COSTS
4009 #define TARGET_RTX_COSTS microblaze_rtx_costs
4010
4011 #undef TARGET_CANNOT_FORCE_CONST_MEM
4012 #define TARGET_CANNOT_FORCE_CONST_MEM microblaze_cannot_force_const_mem
4013
4014 #undef TARGET_ADDRESS_COST
4015 #define TARGET_ADDRESS_COST microblaze_address_cost
4016
4017 #undef TARGET_ATTRIBUTE_TABLE
4018 #define TARGET_ATTRIBUTE_TABLE microblaze_attribute_table
4019
4020 #undef TARGET_IN_SMALL_DATA_P
4021 #define TARGET_IN_SMALL_DATA_P microblaze_elf_in_small_data_p
4022
4023 #undef TARGET_ASM_SELECT_SECTION
4024 #define TARGET_ASM_SELECT_SECTION microblaze_select_section
4025
4026 #undef TARGET_HAVE_SRODATA_SECTION
4027 #define TARGET_HAVE_SRODATA_SECTION true
4028
4029 #undef TARGET_ASM_FUNCTION_END_PROLOGUE
4030 #define TARGET_ASM_FUNCTION_END_PROLOGUE \
4031 microblaze_function_end_prologue
4032
4033 #undef TARGET_ARG_PARTIAL_BYTES
4034 #define TARGET_ARG_PARTIAL_BYTES function_arg_partial_bytes
4035
4036 #undef TARGET_FUNCTION_ARG
4037 #define TARGET_FUNCTION_ARG microblaze_function_arg
4038
4039 #undef TARGET_FUNCTION_ARG_ADVANCE
4040 #define TARGET_FUNCTION_ARG_ADVANCE microblaze_function_arg_advance
4041
4042 #undef TARGET_CAN_ELIMINATE
4043 #define TARGET_CAN_ELIMINATE microblaze_can_eliminate
4044
4045 #undef TARGET_LEGITIMIZE_ADDRESS
4046 #define TARGET_LEGITIMIZE_ADDRESS microblaze_legitimize_address
4047
4048 #undef TARGET_LEGITIMATE_ADDRESS_P
4049 #define TARGET_LEGITIMATE_ADDRESS_P microblaze_legitimate_address_p
4050
4051 #undef TARGET_FRAME_POINTER_REQUIRED
4052 #define TARGET_FRAME_POINTER_REQUIRED microblaze_frame_pointer_required
4053
4054 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
4055 #define TARGET_ASM_TRAMPOLINE_TEMPLATE microblaze_asm_trampoline_template
4056
4057 #undef TARGET_TRAMPOLINE_INIT
4058 #define TARGET_TRAMPOLINE_INIT microblaze_trampoline_init
4059
4060 #undef TARGET_PROMOTE_FUNCTION_MODE
4061 #define TARGET_PROMOTE_FUNCTION_MODE default_promote_function_mode_always_promote
4062
4063 #undef TARGET_FUNCTION_VALUE
4064 #define TARGET_FUNCTION_VALUE microblaze_function_value
4065
4066 #undef TARGET_SECONDARY_RELOAD
4067 #define TARGET_SECONDARY_RELOAD microblaze_secondary_reload
4068
4069 #undef TARGET_ASM_OUTPUT_MI_THUNK
4070 #define TARGET_ASM_OUTPUT_MI_THUNK microblaze_asm_output_mi_thunk
4071
4072 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
4073 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_const_tree_hwi_hwi_const_tree_true
4074
4075 #undef TARGET_SCHED_ADJUST_COST
4076 #define TARGET_SCHED_ADJUST_COST microblaze_adjust_cost
4077
4078 #undef TARGET_ASM_INIT_SECTIONS
4079 #define TARGET_ASM_INIT_SECTIONS microblaze_elf_asm_init_sections
4080
4081 #undef TARGET_OPTION_OVERRIDE
4082 #define TARGET_OPTION_OVERRIDE microblaze_option_override
4083
4084 #undef TARGET_LEGITIMATE_CONSTANT_P
4085 #define TARGET_LEGITIMATE_CONSTANT_P microblaze_legitimate_constant_p
4086
4087 #undef TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC
4088 #define TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC microblaze_gen_pic_addr_dif_vec
4089
4090 #undef TARGET_MACHINE_DEPENDENT_REORG
4091 #define TARGET_MACHINE_DEPENDENT_REORG microblaze_machine_dependent_reorg
4092
4093 #undef TARGET_HARD_REGNO_MODE_OK
4094 #define TARGET_HARD_REGNO_MODE_OK microblaze_hard_regno_mode_ok
4095
4096 #undef TARGET_MODES_TIEABLE_P
4097 #define TARGET_MODES_TIEABLE_P microblaze_modes_tieable_p
4098
4099 #undef TARGET_CONSTANT_ALIGNMENT
4100 #define TARGET_CONSTANT_ALIGNMENT microblaze_constant_alignment
4101
4102 #undef TARGET_STARTING_FRAME_OFFSET
4103 #define TARGET_STARTING_FRAME_OFFSET microblaze_starting_frame_offset
4104
4105 #undef TARGET_DOCUMENTATION_NAME
4106 #define TARGET_DOCUMENTATION_NAME "MicroBlaze"
4107
4108 struct gcc_target targetm = TARGET_INITIALIZER;
4109
4110 #include "gt-microblaze.h"