1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
|
/* FR30 specific functions.
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004
Free Software Foundation, Inc.
Contributed by Cygnus Solutions.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/*{{{ Includes */
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "rtl.h"
#include "regs.h"
#include "hard-reg-set.h"
#include "real.h"
#include "insn-config.h"
#include "conditions.h"
#include "insn-attr.h"
#include "flags.h"
#include "recog.h"
#include "tree.h"
#include "output.h"
#include "expr.h"
#include "obstack.h"
#include "except.h"
#include "function.h"
#include "toplev.h"
#include "tm_p.h"
#include "target.h"
#include "target-def.h"
/*}}}*/
/*{{{ Function Prologues & Epilogues */
/* Define the information needed to generate branch and scc insns. This is
stored from the compare operation. */
struct rtx_def * fr30_compare_op0;
struct rtx_def * fr30_compare_op1;
/* The FR30 stack looks like this:
Before call After call
FP ->| | | |
+-----------------------+ +-----------------------+ high
| | | | memory
| local variables, | | local variables, |
| reg save area, etc. | | reg save area, etc. |
| | | |
+-----------------------+ +-----------------------+
| | | |
| args to the func that | | args to this func. |
| is being called that | | |
SP ->| do not fit in regs | | |
+-----------------------+ +-----------------------+
| args that used to be | \
| in regs; only created | | pretend_size
AP-> | for vararg funcs | /
+-----------------------+
| | \
| register save area | |
| | |
+-----------------------+ | reg_size
| return address | |
+-----------------------+ |
FP ->| previous frame ptr | /
+-----------------------+
| | \
| local variables | | var_size
| | /
+-----------------------+
| | \
low | room for args to | |
memory | other funcs called | | args_size
| from this one | |
SP ->| | /
+-----------------------+
Note, AP is a fake hard register. It will be eliminated in favor of
SP or FP as appropriate.
Note, Some or all of the stack sections above may be omitted if they
are not needed. */
/* Structure to be filled in by fr30_compute_frame_size() with register
save masks, and offsets for the current function. */
struct fr30_frame_info
{
unsigned int total_size; /* # Bytes that the entire frame takes up. */
unsigned int pretend_size; /* # Bytes we push and pretend caller did. */
unsigned int args_size; /* # Bytes that outgoing arguments take up. */
unsigned int reg_size; /* # Bytes needed to store regs. */
unsigned int var_size; /* # Bytes that variables take up. */
unsigned int frame_size; /* # Bytes in current frame. */
unsigned int gmask; /* Mask of saved registers. */
unsigned int save_fp; /* Nonzero if frame pointer must be saved. */
unsigned int save_rp; /* Nonzero if return pointer must be saved. */
int initialised; /* Nonzero if frame size already calculated. */
};
/* Current frame information calculated by fr30_compute_frame_size(). */
static struct fr30_frame_info current_frame_info;
/* Zero structure to initialize current_frame_info. */
static struct fr30_frame_info zero_frame_info;
static void fr30_setup_incoming_varargs (CUMULATIVE_ARGS *, enum machine_mode,
tree, int *, int);
static tree fr30_gimplify_va_arg_expr (tree, tree, tree *, tree *);
static bool fr30_must_pass_in_stack (enum machine_mode, tree);
#define FRAME_POINTER_MASK (1 << (FRAME_POINTER_REGNUM))
#define RETURN_POINTER_MASK (1 << (RETURN_POINTER_REGNUM))
/* Tell prologue and epilogue if register REGNO should be saved / restored.
The return address and frame pointer are treated separately.
Don't consider them here. */
#define MUST_SAVE_REGISTER(regno) \
( (regno) != RETURN_POINTER_REGNUM \
&& (regno) != FRAME_POINTER_REGNUM \
&& regs_ever_live [regno] \
&& ! call_used_regs [regno] )
#define MUST_SAVE_FRAME_POINTER (regs_ever_live [FRAME_POINTER_REGNUM] || frame_pointer_needed)
#define MUST_SAVE_RETURN_POINTER (regs_ever_live [RETURN_POINTER_REGNUM] || current_function_profile)
#if UNITS_PER_WORD == 4
#define WORD_ALIGN(SIZE) (((SIZE) + 3) & ~3)
#endif
/* Initialize the GCC target structure. */
#undef TARGET_ASM_ALIGNED_HI_OP
#define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
#undef TARGET_ASM_ALIGNED_SI_OP
#define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
#undef TARGET_PROMOTE_PROTOTYPES
#define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
#undef TARGET_SETUP_INCOMING_VARARGS
#define TARGET_SETUP_INCOMING_VARARGS fr30_setup_incoming_varargs
#undef TARGET_MUST_PASS_IN_STACK
#define TARGET_MUST_PASS_IN_STACK fr30_must_pass_in_stack
#undef TARGET_GIMPLIFY_VA_ARG_EXPR
#define TARGET_GIMPLIFY_VA_ARG_EXPR fr30_gimplify_va_arg_expr
struct gcc_target targetm = TARGET_INITIALIZER;
/* Returns the number of bytes offset between FROM_REG and TO_REG
for the current function. As a side effect it fills in the
current_frame_info structure, if the data is available. */
unsigned int
fr30_compute_frame_size (int from_reg, int to_reg)
{
int regno;
unsigned int return_value;
unsigned int var_size;
unsigned int args_size;
unsigned int pretend_size;
unsigned int reg_size;
unsigned int gmask;
var_size = WORD_ALIGN (get_frame_size ());
args_size = WORD_ALIGN (current_function_outgoing_args_size);
pretend_size = current_function_pretend_args_size;
reg_size = 0;
gmask = 0;
/* Calculate space needed for registers. */
for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno ++)
{
if (MUST_SAVE_REGISTER (regno))
{
reg_size += UNITS_PER_WORD;
gmask |= 1 << regno;
}
}
current_frame_info.save_fp = MUST_SAVE_FRAME_POINTER;
current_frame_info.save_rp = MUST_SAVE_RETURN_POINTER;
reg_size += (current_frame_info.save_fp + current_frame_info.save_rp)
* UNITS_PER_WORD;
/* Save computed information. */
current_frame_info.pretend_size = pretend_size;
current_frame_info.var_size = var_size;
current_frame_info.args_size = args_size;
current_frame_info.reg_size = reg_size;
current_frame_info.frame_size = args_size + var_size;
current_frame_info.total_size = args_size + var_size + reg_size + pretend_size;
current_frame_info.gmask = gmask;
current_frame_info.initialised = reload_completed;
/* Calculate the required distance. */
return_value = 0;
if (to_reg == STACK_POINTER_REGNUM)
return_value += args_size + var_size;
if (from_reg == ARG_POINTER_REGNUM)
return_value += reg_size;
return return_value;
}
/* Called after register allocation to add any instructions needed for the
prologue. Using a prologue insn is favored compared to putting all of the
instructions in output_function_prologue(), since it allows the scheduler
to intermix instructions with the saves of the caller saved registers. In
some cases, it might be necessary to emit a barrier instruction as the last
insn to prevent such scheduling. */
void
fr30_expand_prologue (void)
{
int regno;
rtx insn;
if (! current_frame_info.initialised)
fr30_compute_frame_size (0, 0);
/* This cases shouldn't happen. Catch it now. */
if (current_frame_info.total_size == 0
&& current_frame_info.gmask)
abort ();
/* Allocate space for register arguments if this is a variadic function. */
if (current_frame_info.pretend_size)
{
int regs_to_save = current_frame_info.pretend_size / UNITS_PER_WORD;
/* Push argument registers into the pretend arg area. */
for (regno = FIRST_ARG_REGNUM + FR30_NUM_ARG_REGS; regno --, regs_to_save --;)
{
insn = emit_insn (gen_movsi_push (gen_rtx_REG (Pmode, regno)));
RTX_FRAME_RELATED_P (insn) = 1;
}
}
if (current_frame_info.gmask)
{
/* Save any needed call-saved regs. */
for (regno = STACK_POINTER_REGNUM; regno--;)
{
if ((current_frame_info.gmask & (1 << regno)) != 0)
{
insn = emit_insn (gen_movsi_push (gen_rtx_REG (Pmode, regno)));
RTX_FRAME_RELATED_P (insn) = 1;
}
}
}
/* Save return address if necessary. */
if (current_frame_info.save_rp)
{
insn = emit_insn (gen_movsi_push (gen_rtx_REG (Pmode,
RETURN_POINTER_REGNUM)));
RTX_FRAME_RELATED_P (insn) = 1;
}
/* Save old frame pointer and create new one, if necessary. */
if (current_frame_info.save_fp)
{
if (current_frame_info.frame_size < ((1 << 10) - UNITS_PER_WORD))
{
int enter_size = current_frame_info.frame_size + UNITS_PER_WORD;
rtx pattern;
insn = emit_insn (gen_enter_func (GEN_INT (enter_size)));
RTX_FRAME_RELATED_P (insn) = 1;
pattern = PATTERN (insn);
/* Also mark all 3 subexpressions as RTX_FRAME_RELATED_P. */
if (GET_CODE (pattern) == PARALLEL)
{
int x;
for (x = XVECLEN (pattern, 0); x--;)
{
rtx part = XVECEXP (pattern, 0, x);
/* One of the insns in the ENTER pattern updates the
frame pointer. If we do not actually need the frame
pointer in this function then this is a side effect
rather than a desired effect, so we do not mark that
insn as being related to the frame set up. Doing this
allows us to compile the crash66.C test file in the
G++ testsuite. */
if (! frame_pointer_needed
&& GET_CODE (part) == SET
&& REGNO (SET_DEST (part)) == HARD_FRAME_POINTER_REGNUM)
RTX_FRAME_RELATED_P (part) = 0;
else
RTX_FRAME_RELATED_P (part) = 1;
}
}
}
else
{
insn = emit_insn (gen_movsi_push (frame_pointer_rtx));
RTX_FRAME_RELATED_P (insn) = 1;
if (frame_pointer_needed)
{
insn = emit_insn (gen_movsi (frame_pointer_rtx, stack_pointer_rtx));
RTX_FRAME_RELATED_P (insn) = 1;
}
}
}
/* Allocate the stack frame. */
if (current_frame_info.frame_size == 0)
; /* Nothing to do. */
else if (current_frame_info.save_fp
&& current_frame_info.frame_size < ((1 << 10) - UNITS_PER_WORD))
; /* Nothing to do. */
else if (current_frame_info.frame_size <= 512)
{
insn = emit_insn (gen_add_to_stack (GEN_INT (- current_frame_info.frame_size)));
RTX_FRAME_RELATED_P (insn) = 1;
}
else
{
rtx tmp = gen_rtx_REG (Pmode, PROLOGUE_TMP_REGNUM);
insn = emit_insn (gen_movsi (tmp, GEN_INT (current_frame_info.frame_size)));
RTX_FRAME_RELATED_P (insn) = 1;
insn = emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, tmp));
RTX_FRAME_RELATED_P (insn) = 1;
}
if (current_function_profile)
emit_insn (gen_blockage ());
}
/* Called after register allocation to add any instructions needed for the
epilogue. Using an epilogue insn is favored compared to putting all of the
instructions in output_function_epilogue(), since it allows the scheduler
to intermix instructions with the restores of the caller saved registers.
In some cases, it might be necessary to emit a barrier instruction as the
first insn to prevent such scheduling. */
void
fr30_expand_epilogue (void)
{
int regno;
/* Perform the inversion operations of the prologue. */
if (! current_frame_info.initialised)
abort ();
/* Pop local variables and arguments off the stack.
If frame_pointer_needed is TRUE then the frame pointer register
has actually been used as a frame pointer, and we can recover
the stack pointer from it, otherwise we must unwind the stack
manually. */
if (current_frame_info.frame_size > 0)
{
if (current_frame_info.save_fp && frame_pointer_needed)
{
emit_insn (gen_leave_func ());
current_frame_info.save_fp = 0;
}
else if (current_frame_info.frame_size <= 508)
emit_insn (gen_add_to_stack
(GEN_INT (current_frame_info.frame_size)));
else
{
rtx tmp = gen_rtx_REG (Pmode, PROLOGUE_TMP_REGNUM);
emit_insn (gen_movsi (tmp, GEN_INT (current_frame_info.frame_size)));
emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, tmp));
}
}
if (current_frame_info.save_fp)
emit_insn (gen_movsi_pop (frame_pointer_rtx));
/* Pop all the registers that were pushed. */
if (current_frame_info.save_rp)
emit_insn (gen_movsi_pop (gen_rtx_REG (Pmode, RETURN_POINTER_REGNUM)));
for (regno = 0; regno < STACK_POINTER_REGNUM; regno ++)
if (current_frame_info.gmask & (1 << regno))
emit_insn (gen_movsi_pop (gen_rtx_REG (Pmode, regno)));
if (current_frame_info.pretend_size)
emit_insn (gen_add_to_stack (GEN_INT (current_frame_info.pretend_size)));
/* Reset state info for each function. */
current_frame_info = zero_frame_info;
emit_jump_insn (gen_return_from_func ());
}
/* Do any needed setup for a variadic function. We must create a register
parameter block, and then copy any anonymous arguments, plus the last
named argument, from registers into memory. * copying actually done in
fr30_expand_prologue().
ARG_REGS_USED_SO_FAR has *not* been updated for the last named argument
which has type TYPE and mode MODE, and we rely on this fact. */
void
fr30_setup_incoming_varargs (CUMULATIVE_ARGS *arg_regs_used_so_far,
enum machine_mode mode,
tree type ATTRIBUTE_UNUSED,
int *pretend_size,
int second_time ATTRIBUTE_UNUSED)
{
int size;
/* All BLKmode values are passed by reference. */
if (mode == BLKmode)
abort ();
/* ??? This run-time test as well as the code inside the if
statement is probably unnecessary. */
if (targetm.calls.strict_argument_naming (arg_regs_used_so_far))
/* If TARGET_STRICT_ARGUMENT_NAMING returns true, then the last named
arg must not be treated as an anonymous arg. */
arg_regs_used_so_far += fr30_num_arg_regs (mode, type);
size = FR30_NUM_ARG_REGS - (* arg_regs_used_so_far);
if (size <= 0)
return;
* pretend_size = (size * UNITS_PER_WORD);
}
/*}}}*/
/*{{{ Printing operands */
/* Print a memory address as an operand to reference that memory location. */
void
fr30_print_operand_address (FILE *stream, rtx address)
{
switch (GET_CODE (address))
{
case SYMBOL_REF:
output_addr_const (stream, address);
break;
default:
fprintf (stderr, "code = %x\n", GET_CODE (address));
debug_rtx (address);
output_operand_lossage ("fr30_print_operand_address: unhandled address");
break;
}
}
/* Print an operand. */
void
fr30_print_operand (FILE *file, rtx x, int code)
{
rtx x0;
switch (code)
{
case '#':
/* Output a :D if this instruction is delayed. */
if (dbr_sequence_length () != 0)
fputs (":D", file);
return;
case 'p':
/* Compute the register name of the second register in a hi/lo
register pair. */
if (GET_CODE (x) != REG)
output_operand_lossage ("fr30_print_operand: unrecognized %%p code");
else
fprintf (file, "r%d", REGNO (x) + 1);
return;
case 'b':
/* Convert GCC's comparison operators into FR30 comparison codes. */
switch (GET_CODE (x))
{
case EQ: fprintf (file, "eq"); break;
case NE: fprintf (file, "ne"); break;
case LT: fprintf (file, "lt"); break;
case LE: fprintf (file, "le"); break;
case GT: fprintf (file, "gt"); break;
case GE: fprintf (file, "ge"); break;
case LTU: fprintf (file, "c"); break;
case LEU: fprintf (file, "ls"); break;
case GTU: fprintf (file, "hi"); break;
case GEU: fprintf (file, "nc"); break;
default:
output_operand_lossage ("fr30_print_operand: unrecognized %%b code");
break;
}
return;
case 'B':
/* Convert GCC's comparison operators into the complimentary FR30
comparison codes. */
switch (GET_CODE (x))
{
case EQ: fprintf (file, "ne"); break;
case NE: fprintf (file, "eq"); break;
case LT: fprintf (file, "ge"); break;
case LE: fprintf (file, "gt"); break;
case GT: fprintf (file, "le"); break;
case GE: fprintf (file, "lt"); break;
case LTU: fprintf (file, "nc"); break;
case LEU: fprintf (file, "hi"); break;
case GTU: fprintf (file, "ls"); break;
case GEU: fprintf (file, "c"); break;
default:
output_operand_lossage ("fr30_print_operand: unrecognized %%B code");
break;
}
return;
case 'A':
/* Print a signed byte value as an unsigned value. */
if (GET_CODE (x) != CONST_INT)
output_operand_lossage ("fr30_print_operand: invalid operand to %%A code");
else
{
HOST_WIDE_INT val;
val = INTVAL (x);
val &= 0xff;
fprintf (file, HOST_WIDE_INT_PRINT_DEC, val);
}
return;
case 'x':
if (GET_CODE (x) != CONST_INT
|| INTVAL (x) < 16
|| INTVAL (x) > 32)
output_operand_lossage ("fr30_print_operand: invalid %%x code");
else
fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) - 16);
return;
case 'F':
if (GET_CODE (x) != CONST_DOUBLE)
output_operand_lossage ("fr30_print_operand: invalid %%F code");
else
{
char str[30];
real_to_decimal (str, CONST_DOUBLE_REAL_VALUE (x),
sizeof (str), 0, 1);
fputs (str, file);
}
return;
case 0:
/* Handled below. */
break;
default:
fprintf (stderr, "unknown code = %x\n", code);
output_operand_lossage ("fr30_print_operand: unknown code");
return;
}
switch (GET_CODE (x))
{
case REG:
fputs (reg_names [REGNO (x)], file);
break;
case MEM:
x0 = XEXP (x,0);
switch (GET_CODE (x0))
{
case REG:
if ((unsigned) REGNO (x0) >= ARRAY_SIZE (reg_names))
abort ();
fprintf (file, "@%s", reg_names [REGNO (x0)]);
break;
case PLUS:
if (GET_CODE (XEXP (x0, 0)) != REG
|| REGNO (XEXP (x0, 0)) < FRAME_POINTER_REGNUM
|| REGNO (XEXP (x0, 0)) > STACK_POINTER_REGNUM
|| GET_CODE (XEXP (x0, 1)) != CONST_INT)
{
fprintf (stderr, "bad INDEXed address:");
debug_rtx (x);
output_operand_lossage ("fr30_print_operand: unhandled MEM");
}
else if (REGNO (XEXP (x0, 0)) == FRAME_POINTER_REGNUM)
{
HOST_WIDE_INT val = INTVAL (XEXP (x0, 1));
if (val < -(1 << 9) || val > ((1 << 9) - 4))
{
fprintf (stderr, "frame INDEX out of range:");
debug_rtx (x);
output_operand_lossage ("fr30_print_operand: unhandled MEM");
}
fprintf (file, "@(r14, #" HOST_WIDE_INT_PRINT_DEC ")", val);
}
else
{
HOST_WIDE_INT val = INTVAL (XEXP (x0, 1));
if (val < 0 || val > ((1 << 6) - 4))
{
fprintf (stderr, "stack INDEX out of range:");
debug_rtx (x);
output_operand_lossage ("fr30_print_operand: unhandled MEM");
}
fprintf (file, "@(r15, #" HOST_WIDE_INT_PRINT_DEC ")", val);
}
break;
case SYMBOL_REF:
output_address (x0);
break;
default:
fprintf (stderr, "bad MEM code = %x\n", GET_CODE (x0));
debug_rtx (x);
output_operand_lossage ("fr30_print_operand: unhandled MEM");
break;
}
break;
case CONST_DOUBLE :
/* We handle SFmode constants here as output_addr_const doesn't. */
if (GET_MODE (x) == SFmode)
{
REAL_VALUE_TYPE d;
long l;
REAL_VALUE_FROM_CONST_DOUBLE (d, x);
REAL_VALUE_TO_TARGET_SINGLE (d, l);
fprintf (file, "0x%08lx", l);
break;
}
/* Fall through. Let output_addr_const deal with it. */
default:
output_addr_const (file, x);
break;
}
return;
}
/*}}}*/
/*{{{ Function arguments */
/* Return true if we should pass an argument on the stack rather than
in registers. */
static bool
fr30_must_pass_in_stack (enum machine_mode mode, tree type)
{
if (mode == BLKmode)
return true;
if (type == NULL)
return false;
return AGGREGATE_TYPE_P (type);
}
/* Compute the number of word sized registers needed to hold a
function argument of mode INT_MODE and tree type TYPE. */
int
fr30_num_arg_regs (enum machine_mode mode, tree type)
{
int size;
if (targetm.calls.must_pass_in_stack (mode, type))
return 0;
if (type && mode == BLKmode)
size = int_size_in_bytes (type);
else
size = GET_MODE_SIZE (mode);
return (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
}
/* Implements the FUNCTION_ARG_PARTIAL_NREGS macro.
Returns the number of argument registers required to hold *part* of
a parameter of machine mode MODE and tree type TYPE (which may be
NULL if the type is not known). If the argument fits entirely in
the argument registers, or entirely on the stack, then 0 is returned.
CUM is the number of argument registers already used by earlier
parameters to the function. */
int
fr30_function_arg_partial_nregs (CUMULATIVE_ARGS cum, enum machine_mode mode,
tree type, int named)
{
/* Unnamed arguments, ie those that are prototyped as ...
are always passed on the stack.
Also check here to see if all the argument registers are full. */
if (named == 0 || cum >= FR30_NUM_ARG_REGS)
return 0;
/* Work out how many argument registers would be needed if this
parameter were to be passed entirely in registers. If there
are sufficient argument registers available (or if no registers
are needed because the parameter must be passed on the stack)
then return zero, as this parameter does not require partial
register, partial stack stack space. */
if (cum + fr30_num_arg_regs (mode, type) <= FR30_NUM_ARG_REGS)
return 0;
/* Otherwise return the number of registers that would be used. */
return FR30_NUM_ARG_REGS - cum;
}
/* Implement `va_arg'. */
static tree
fr30_gimplify_va_arg_expr (tree valist, tree type, tree *pre_p, tree *post_p)
{
if (FUNCTION_ARG_PASS_BY_REFERENCE (dummy, TYPE_MODE (type), type, dummy))
return ind_gimplify_va_arg_expr (valist, type, pre_p, post_p);
else
return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
}
/*}}}*/
/*{{{ Operand predicates */
#ifndef Mmode
#define Mmode enum machine_mode
#endif
/* Returns true if OPERAND is an integer value suitable for use in
an ADDSP instruction. */
int
stack_add_operand (rtx operand, Mmode mode ATTRIBUTE_UNUSED)
{
return
(GET_CODE (operand) == CONST_INT
&& INTVAL (operand) >= -512
&& INTVAL (operand) <= 508
&& ((INTVAL (operand) & 3) == 0));
}
/* Returns true if OPERAND is an integer value suitable for use in
an ADD por ADD2 instruction, or if it is a register. */
int
add_immediate_operand (rtx operand, Mmode mode ATTRIBUTE_UNUSED)
{
return
(GET_CODE (operand) == REG
|| (GET_CODE (operand) == CONST_INT
&& INTVAL (operand) >= -16
&& INTVAL (operand) <= 15));
}
/* Returns true if OPERAND is hard register in the range 8 - 15. */
int
high_register_operand (rtx operand, Mmode mode ATTRIBUTE_UNUSED)
{
return
(GET_CODE (operand) == REG
&& REGNO (operand) <= 15
&& REGNO (operand) >= 8);
}
/* Returns true if OPERAND is hard register in the range 0 - 7. */
int
low_register_operand (rtx operand, Mmode mode ATTRIBUTE_UNUSED)
{
return
(GET_CODE (operand) == REG
&& REGNO (operand) <= 7);
}
/* Returns true if OPERAND is suitable for use in a CALL insn. */
int
call_operand (rtx operand, Mmode mode ATTRIBUTE_UNUSED)
{
return (GET_CODE (operand) == MEM
&& (GET_CODE (XEXP (operand, 0)) == SYMBOL_REF
|| GET_CODE (XEXP (operand, 0)) == REG));
}
/* Returns TRUE if OP is a valid operand of a DImode operation. */
int
di_operand (rtx op, Mmode mode)
{
if (register_operand (op, mode))
return TRUE;
if (mode != VOIDmode && GET_MODE (op) != VOIDmode && GET_MODE (op) != DImode)
return FALSE;
if (GET_CODE (op) == SUBREG)
op = SUBREG_REG (op);
switch (GET_CODE (op))
{
case CONST_DOUBLE:
case CONST_INT:
return TRUE;
case MEM:
return memory_address_p (DImode, XEXP (op, 0));
default:
return FALSE;
}
}
/* Returns TRUE if OP is a DImode register or MEM. */
int
nonimmediate_di_operand (rtx op, Mmode mode)
{
if (register_operand (op, mode))
return TRUE;
if (mode != VOIDmode && GET_MODE (op) != VOIDmode && GET_MODE (op) != DImode)
return FALSE;
if (GET_CODE (op) == SUBREG)
op = SUBREG_REG (op);
if (GET_CODE (op) == MEM)
return memory_address_p (DImode, XEXP (op, 0));
return FALSE;
}
/* Returns true iff all the registers in the operands array
are in descending or ascending order. */
int
fr30_check_multiple_regs (rtx *operands, int num_operands, int descending)
{
if (descending)
{
unsigned int prev_regno = 0;
while (num_operands --)
{
if (GET_CODE (operands [num_operands]) != REG)
return 0;
if (REGNO (operands [num_operands]) < prev_regno)
return 0;
prev_regno = REGNO (operands [num_operands]);
}
}
else
{
unsigned int prev_regno = CONDITION_CODE_REGNUM;
while (num_operands --)
{
if (GET_CODE (operands [num_operands]) != REG)
return 0;
if (REGNO (operands [num_operands]) > prev_regno)
return 0;
prev_regno = REGNO (operands [num_operands]);
}
}
return 1;
}
int
fr30_const_double_is_zero (rtx operand)
{
REAL_VALUE_TYPE d;
if (operand == NULL || GET_CODE (operand) != CONST_DOUBLE)
return 0;
REAL_VALUE_FROM_CONST_DOUBLE (d, operand);
return REAL_VALUES_EQUAL (d, dconst0);
}
/*}}}*/
/*{{{ Instruction Output Routines */
/* Output a double word move.
It must be REG<-REG, REG<-MEM, MEM<-REG or REG<-CONST.
On the FR30 we are constrained by the fact that it does not
support offsetable addresses, and so we have to load the
address of the secnd word into the second destination register
before we can use it. */
rtx
fr30_move_double (rtx * operands)
{
rtx src = operands[1];
rtx dest = operands[0];
enum rtx_code src_code = GET_CODE (src);
enum rtx_code dest_code = GET_CODE (dest);
enum machine_mode mode = GET_MODE (dest);
rtx val;
start_sequence ();
if (dest_code == REG)
{
if (src_code == REG)
{
int reverse = (REGNO (dest) == REGNO (src) + 1);
/* We normally copy the low-numbered register first. However, if
the first register of operand 0 is the same as the second register
of operand 1, we must copy in the opposite order. */
emit_insn (gen_rtx_SET (VOIDmode,
operand_subword (dest, reverse, TRUE, mode),
operand_subword (src, reverse, TRUE, mode)));
emit_insn (gen_rtx_SET (VOIDmode,
operand_subword (dest, !reverse, TRUE, mode),
operand_subword (src, !reverse, TRUE, mode)));
}
else if (src_code == MEM)
{
rtx addr = XEXP (src, 0);
int dregno = REGNO (dest);
rtx dest0;
rtx dest1;
rtx new_mem;
/* If the high-address word is used in the address, we
must load it last. Otherwise, load it first. */
int reverse = (refers_to_regno_p (dregno, dregno + 1, addr, 0) != 0);
if (GET_CODE (addr) != REG)
abort ();
dest0 = operand_subword (dest, reverse, TRUE, mode);
dest1 = operand_subword (dest, !reverse, TRUE, mode);
if (reverse)
{
emit_insn (gen_rtx_SET (VOIDmode, dest1,
adjust_address (src, SImode, 0)));
emit_insn (gen_rtx_SET (SImode, dest0,
gen_rtx_REG (SImode, REGNO (addr))));
emit_insn (gen_rtx_SET (SImode, dest0,
plus_constant (dest0, UNITS_PER_WORD)));
new_mem = gen_rtx_MEM (SImode, dest0);
MEM_COPY_ATTRIBUTES (new_mem, src);
emit_insn (gen_rtx_SET (VOIDmode, dest0, new_mem));
}
else
{
emit_insn (gen_rtx_SET (VOIDmode, dest0,
adjust_address (src, SImode, 0)));
emit_insn (gen_rtx_SET (SImode, dest1,
gen_rtx_REG (SImode, REGNO (addr))));
emit_insn (gen_rtx_SET (SImode, dest1,
plus_constant (dest1, UNITS_PER_WORD)));
new_mem = gen_rtx_MEM (SImode, dest1);
MEM_COPY_ATTRIBUTES (new_mem, src);
emit_insn (gen_rtx_SET (VOIDmode, dest1, new_mem));
}
}
else if (src_code == CONST_INT || src_code == CONST_DOUBLE)
{
rtx words[2];
split_double (src, &words[0], &words[1]);
emit_insn (gen_rtx_SET (VOIDmode,
operand_subword (dest, 0, TRUE, mode),
words[0]));
emit_insn (gen_rtx_SET (VOIDmode,
operand_subword (dest, 1, TRUE, mode),
words[1]));
}
}
else if (src_code == REG && dest_code == MEM)
{
rtx addr = XEXP (dest, 0);
rtx src0;
rtx src1;
if (GET_CODE (addr) != REG)
abort ();
src0 = operand_subword (src, 0, TRUE, mode);
src1 = operand_subword (src, 1, TRUE, mode);
emit_insn (gen_rtx_SET (VOIDmode, adjust_address (dest, SImode, 0),
src0));
if (REGNO (addr) == STACK_POINTER_REGNUM
|| REGNO (addr) == FRAME_POINTER_REGNUM)
emit_insn (gen_rtx_SET (VOIDmode,
adjust_address (dest, SImode, UNITS_PER_WORD),
src1));
else
{
rtx new_mem;
/* We need a scratch register to hold the value of 'address + 4'.
We ought to allow gcc to find one for us, but for now, just
push one of the source registers. */
emit_insn (gen_movsi_push (src0));
emit_insn (gen_movsi_internal (src0, addr));
emit_insn (gen_addsi_small_int (src0, src0, GEN_INT (UNITS_PER_WORD)));
new_mem = gen_rtx_MEM (SImode, src0);
MEM_COPY_ATTRIBUTES (new_mem, dest);
emit_insn (gen_rtx_SET (VOIDmode, new_mem, src1));
emit_insn (gen_movsi_pop (src0));
}
}
else
/* This should have been prevented by the constraints on movdi_insn. */
abort ();
val = get_insns ();
end_sequence ();
return val;
}
/*}}}*/
/* Local Variables: */
/* folded-file: t */
/* End: */
|