OSDN Git Service

* mn10300/mn10300.c (expand_prologue): Rework to avoid unnecessary
[pf3gnuchains/gcc-fork.git] / gcc / config / mn10300 / mn10300.c
1 /* Subroutines for insn-output.c for Matsushita MN10300 series
2    Copyright (C) 1996 Free Software Foundation, Inc.
3    Contributed by Jeff Law (law@cygnus.com).
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22 #include <stdio.h>
23 #include "config.h"
24 #include "rtl.h"
25 #include "regs.h"
26 #include "hard-reg-set.h"
27 #include "real.h"
28 #include "insn-config.h"
29 #include "conditions.h"
30 #include "insn-flags.h"
31 #include "output.h"
32 #include "insn-attr.h"
33 #include "flags.h"
34 #include "recog.h"
35 #include "expr.h"
36 #include "tree.h"
37 #include "obstack.h"
38
39 void
40 asm_file_start (file)
41      FILE *file;
42 {
43   fprintf (file, "#\tGCC For the Matsushita MN10300\n");
44   if (optimize)
45     fprintf (file, "# -O%d\n", optimize);
46   else
47     fprintf (file, "\n\n");
48   output_file_directive (file, main_input_filename);
49 }
50 \f
51
52 int
53 const_costs (r, c)
54      rtx r;
55      enum rtx_code c;
56 {
57   switch (c)
58     {
59     case CONST_INT:
60       if (INT_8_BITS (INTVAL (r)))
61         return 0;
62       else if (INT_16_BITS (INTVAL (r)))
63         return 1;
64       else
65         return 2;
66     case CONST_DOUBLE:
67       return 8;
68     default:
69       return 4;
70     }
71 }
72 \f
73 /* Print operand X using operand code CODE to assembly language output file
74    FILE.  */
75
76 void
77 print_operand (file, x, code)
78      FILE *file;
79      rtx x;
80      int code;
81 {
82   switch (code)
83     {
84       case 'b':
85       case 'B':
86         /* These are normal and reversed branches.  */
87         switch (code == 'b' ? GET_CODE (x) : reverse_condition (GET_CODE (x)))
88           {
89           case NE:
90             fprintf (file, "ne");
91             break;
92           case EQ:
93             fprintf (file, "eq");
94             break;
95           case GE:
96             fprintf (file, "ge");
97             break;
98           case GT:
99             fprintf (file, "gt");
100             break;
101           case LE:
102             fprintf (file, "le");
103             break;
104           case LT:
105             fprintf (file, "lt");
106             break;
107           case GEU:
108             fprintf (file, "cc");
109             break;
110           case GTU:
111             fprintf (file, "hi");
112             break;
113           case LEU:
114             fprintf (file, "ls");
115             break;
116           case LTU:
117             fprintf (file, "cs");
118             break;
119           default:
120             abort ();
121           }
122         break;
123       case 'C':
124         /* This is used for the operand to a call instruction;
125            if it's a REG, enclose it in parens, else output
126            the operand normally.  */
127         if (GET_CODE (x) == REG)
128           {
129             fputc ('(', file);
130             print_operand (file, x, 0);
131             fputc (')', file);
132           }
133         else
134           print_operand (file, x, 0);
135         break;
136      
137       default:
138         switch (GET_CODE (x))
139           {
140           case MEM:
141             fputc ('(', file);
142             output_address (XEXP (x, 0));
143             fputc (')', file);
144             break;
145
146           case REG:
147             fprintf (file, "%s", reg_names[REGNO (x)]);
148             break;
149
150           case SUBREG:
151             fprintf (file, "%s",
152                      reg_names[REGNO (SUBREG_REG (x)) + SUBREG_WORD (x)]);
153             break;
154
155           case CONST_INT:
156           case SYMBOL_REF:
157           case CONST:
158           case LABEL_REF:
159           case CODE_LABEL:
160             print_operand_address (file, x);
161             break;
162           default:
163             abort ();
164           }
165         break;
166    }
167 }
168
169 /* Output assembly language output for the address ADDR to FILE.  */
170
171 void
172 print_operand_address (file, addr)
173      FILE *file;
174      rtx addr;
175 {
176   switch (GET_CODE (addr))
177     {
178     case REG:
179       if (addr == stack_pointer_rtx)
180         print_operand_address (file, gen_rtx (PLUS, SImode,
181                                               stack_pointer_rtx,
182                                               GEN_INT (0)));
183       else
184         print_operand (file, addr, 0);
185       break;
186     case PLUS:
187       {
188         rtx base, index;
189         if (REG_P (XEXP (addr, 0))
190             && REG_OK_FOR_BASE_P (XEXP (addr, 0)))
191           base = XEXP (addr, 0), index = XEXP (addr, 1);
192         else if (REG_P (XEXP (addr, 1))
193             && REG_OK_FOR_BASE_P (XEXP (addr, 1)))
194           base = XEXP (addr, 1), index = XEXP (addr, 0);
195         else
196           abort ();
197         print_operand (file, index, 0);
198         fputc (',', file);
199         print_operand (file, base, 0);;
200         break;
201       }
202     case SYMBOL_REF:
203       output_addr_const (file, addr);
204       break;
205     default:
206       output_addr_const (file, addr);
207       break;
208     }
209 }
210
211 void
212 expand_prologue ()
213 {
214   unsigned int size = get_frame_size ();
215
216   /* For simplicity, we just movm all the callee saved registers to
217      the stack with one instruction, then set up the frame pointer
218      (if needed), and finally allocate the new stack.  */
219   emit_insn (gen_store_movm ());
220
221   if (frame_pointer_needed)
222     emit_move_insn (frame_pointer_rtx, stack_pointer_rtx);
223
224   if (size)
225     emit_insn (gen_addsi3 (stack_pointer_rtx,
226                            stack_pointer_rtx,
227                            GEN_INT (-size)));
228 }
229
230 void
231 expand_epilogue ()
232 {
233   unsigned int size = get_frame_size ();
234
235   /* Cut back the stack.  */
236   if (frame_pointer_needed)
237     {
238       emit_move_insn (stack_pointer_rtx, frame_pointer_rtx);
239       size = 0;
240     }
241   else if (size > 255)
242     {
243       emit_insn (gen_addsi3 (stack_pointer_rtx,
244                              stack_pointer_rtx,
245                              GEN_INT (size)));
246       size = 0;
247     }
248
249   /* Deallocate remaining stack, restore registers and return.  And return.  */
250   emit_jump_insn (gen_return_internal (GEN_INT (size)));
251 }
252
253 /* Update the condition code from the insn.  */
254
255 void
256 notice_update_cc (body, insn)
257      rtx body;
258      rtx insn;
259 {
260   switch (get_attr_cc (insn))
261     {
262     case CC_NONE:
263       /* Insn does not affect CC at all.  */
264       break;
265
266     case CC_NONE_0HIT:
267       /* Insn does not change CC, but the 0'th operand has been changed.  */
268       if (cc_status.value1 != 0
269           && reg_overlap_mentioned_p (recog_operand[0], cc_status.value1))
270         cc_status.value1 = 0;
271       break;
272
273     case CC_SET_ZN_C0:
274       /* Insn sets the Z,N flags of CC to recog_operand[0].
275          V is always set to 0.  C may or may not be set to 0 but that's ok
276          because alter_cond will change tests to use EQ/NE.  */
277       CC_STATUS_INIT;
278       cc_status.flags |= CC_NO_OVERFLOW;
279       cc_status.value1 = recog_operand[0];
280       break;
281
282     case CC_SET:
283       /* The insn sets all the condition codes, except v is bogus.  */
284       CC_STATUS_INIT;
285       cc_status.flags |= CC_OVERFLOW_UNUSABLE;
286       cc_status.value1 = recog_operand[0];
287       break;
288
289     case CC_COMPARE:
290       /* The insn is a compare instruction.  */
291       CC_STATUS_INIT;
292       cc_status.value1 = SET_SRC (body);
293       break;
294
295     case CC_CLOBBER:
296       /* Insn doesn't leave CC in a usable state.  */
297       CC_STATUS_INIT;
298       break;
299
300     default:
301       abort ();
302     }
303 }
304
305 /* Return true if OP is a valid call operand.  */
306
307 int
308 call_address_operand (op, mode)
309      rtx op;
310      enum machine_mode mode;
311 {
312   return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == REG);
313 }
314
315 /* What (if any) secondary registers are needed to move IN with mode
316    MODE into a register from in register class CLASS. 
317
318    We might be able to simplify this.  */
319 enum reg_class
320 secondary_reload_class (class, mode, in)
321      enum reg_class class;
322      enum machine_mode mode;
323      rtx in;
324 {
325   int regno;
326
327   /* Memory loads less than a full word wide can't have an
328      address or stack pointer destination.  They must use
329      a data register as an intermediate register.  */
330   if (GET_CODE (in) == MEM
331       && (mode == QImode || mode == HImode)
332       && (class == ADDRESS_REGS || class == SP_REGS))
333     return DATA_REGS;
334
335   /* We can't directly load sp + const_int into a data register;
336      we must use an address register as an intermediate.  */
337   if (class == DATA_REGS
338       && (in == stack_pointer_rtx
339           || (GET_CODE (in) == PLUS
340               && XEXP (in, 0) == stack_pointer_rtx)))
341     return ADDRESS_REGS;
342
343   /* Get the true register.  */
344   if (GET_CODE (in) == REG)
345     {
346       regno = REGNO (in);
347       if (regno >= FIRST_PSEUDO_REGISTER)
348         regno = true_regnum (in);
349     }
350
351   /* We can't copy directly from a data register into the stack
352      pointer.  */
353   if (class == SP_REGS
354       && GET_CODE (in) == REG
355       && regno < 4)
356     return ADDRESS_REGS;
357
358   /* Otherwise assume no secondary reloads are needed.  */
359   return NO_REGS;
360 }