OSDN Git Service

Latest updates from FSF 4.7 branch
[pf3gnuchains/gcc-fork.git] / gcc / config / v850 / v850.h
1 /* Definitions of target machine for GNU compiler. NEC V850 series
2    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3    2007, 2008, 2009, 2010, 2011  Free Software Foundation, Inc.
4    Contributed by Jeff Law (law@cygnus.com).
5
6    This file is part of GCC.
7
8    GCC is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3, or (at your option)
11    any later version.
12
13    GCC is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public 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 #ifndef GCC_V850_H
23 #define GCC_V850_H
24
25 extern GTY(()) rtx v850_compare_op0;
26 extern GTY(()) rtx v850_compare_op1;
27
28 #undef LIB_SPEC
29 #define LIB_SPEC "%{!shared:%{!symbolic:--start-group -lc -lgcc --end-group}}"
30
31 #undef ENDFILE_SPEC
32 #undef LINK_SPEC
33 #undef STARTFILE_SPEC
34 #undef ASM_SPEC
35
36 #define TARGET_CPU_generic      1
37 #define TARGET_CPU_v850e        2
38 #define TARGET_CPU_v850e1       3
39 #define TARGET_CPU_v850e2       4
40 #define TARGET_CPU_v850e2v3     5
41
42
43 #ifndef TARGET_CPU_DEFAULT
44 #define TARGET_CPU_DEFAULT      TARGET_CPU_generic
45 #endif
46
47 #define MASK_DEFAULT            MASK_V850
48 #define SUBTARGET_ASM_SPEC      "%{!mv*:-mv850}"
49 #define SUBTARGET_CPP_SPEC      "%{!mv*:-D__v850__}"
50
51 /* Choose which processor will be the default.
52    We must pass a -mv850xx option to the assembler if no explicit -mv* option
53    is given, because the assembler's processor default may not be correct.  */
54 #if TARGET_CPU_DEFAULT == TARGET_CPU_v850e
55 #undef  MASK_DEFAULT
56 #define MASK_DEFAULT            MASK_V850E
57 #undef  SUBTARGET_ASM_SPEC
58 #define SUBTARGET_ASM_SPEC      "%{!mv*:-mv850e}"
59 #undef  SUBTARGET_CPP_SPEC
60 #define SUBTARGET_CPP_SPEC      "%{!mv*:-D__v850e__}"
61 #endif
62
63 #if TARGET_CPU_DEFAULT == TARGET_CPU_v850e1
64 #undef  MASK_DEFAULT
65 #define MASK_DEFAULT            MASK_V850E     /* No practical difference.  */     
66 #undef  SUBTARGET_ASM_SPEC
67 #define SUBTARGET_ASM_SPEC      "%{!mv*:-mv850e1}"
68 #undef  SUBTARGET_CPP_SPEC
69 #define SUBTARGET_CPP_SPEC      "%{!mv*:-D__v850e1__} %{mv850e1:-D__v850e1__}"
70 #endif
71
72 #if TARGET_CPU_DEFAULT == TARGET_CPU_v850e2
73 #undef  MASK_DEFAULT
74 #define MASK_DEFAULT            MASK_V850E2     
75 #undef  SUBTARGET_ASM_SPEC
76 #define SUBTARGET_ASM_SPEC      "%{!mv*:-mv850e2}"
77 #undef  SUBTARGET_CPP_SPEC
78 #define SUBTARGET_CPP_SPEC      "%{!mv*:-D__v850e2__} %{mv850e2:-D__v850e2__}"
79 #endif
80
81 #if TARGET_CPU_DEFAULT == TARGET_CPU_v850e2v3
82 #undef  MASK_DEFAULT
83 #define MASK_DEFAULT            MASK_V850E2V3
84 #undef  SUBTARGET_ASM_SPEC
85 #define SUBTARGET_ASM_SPEC      "%{!mv*:-mv850e2v3}"
86 #undef  SUBTARGET_CPP_SPEC
87 #define SUBTARGET_CPP_SPEC      "%{!mv*:-D__v850e2v3__} %{mv850e2v3:-D__v850e2v3__}"
88 #endif
89
90 #define TARGET_V850E2_ALL      (TARGET_V850E2 || TARGET_V850E2V3) 
91
92 #define ASM_SPEC "%{mv850es:-mv850e1}%{!mv850es:%{mv*:-mv%*}} %{mrelax:-mrelax}"
93 #define CPP_SPEC "\
94   %{mv850e2v3:-D__v850e2v3__} \
95   %{mv850e2:-D__v850e2__} \
96   %{mv850es:-D__v850e1__} \
97   %{mv850e1:-D__v850e1__} \
98   %{mv850e:-D__v850e__} \
99   %{mv850:-D__v850__} \
100   %(subtarget_cpp_spec)" \
101   " %{mep:-D__EP__}"
102
103 #define EXTRA_SPECS \
104  { "subtarget_asm_spec", SUBTARGET_ASM_SPEC }, \
105  { "subtarget_cpp_spec", SUBTARGET_CPP_SPEC } 
106
107 /* Names to predefine in the preprocessor for this target machine.  */
108 #define TARGET_CPU_CPP_BUILTINS() do {          \
109   builtin_define( "__v851__" );                        \
110   builtin_define( "__v850" );                   \
111   builtin_assert( "machine=v850" );             \
112   builtin_assert( "cpu=v850" );                 \
113   if (TARGET_EP)                                \
114     builtin_define ("__EP__");                  \
115 } while(0)
116
117 #define MASK_CPU (MASK_V850 | MASK_V850E | MASK_V850E1 | MASK_V850E2 | MASK_V850E2V3)
118 \f
119 /* Target machine storage layout */
120
121 /* Define this if most significant bit is lowest numbered
122    in instructions that operate on numbered bit-fields.
123    This is not true on the NEC V850.  */
124 #define BITS_BIG_ENDIAN 0
125
126 /* Define this if most significant byte of a word is the lowest numbered.  */
127 /* This is not true on the NEC V850.  */
128 #define BYTES_BIG_ENDIAN 0
129
130 /* Define this if most significant word of a multiword number is lowest
131    numbered.
132    This is not true on the NEC V850.  */
133 #define WORDS_BIG_ENDIAN 0
134
135 /* Width of a word, in units (bytes).  */
136 #define UNITS_PER_WORD          4
137
138 /* Define this macro if it is advisable to hold scalars in registers
139    in a wider mode than that declared by the program.  In such cases,
140    the value is constrained to be within the bounds of the declared
141    type, but kept valid in the wider mode.  The signedness of the
142    extension may differ from that of the type.
143
144    Some simple experiments have shown that leaving UNSIGNEDP alone
145    generates the best overall code.  */
146
147 #define PROMOTE_MODE(MODE,UNSIGNEDP,TYPE)  \
148   if (GET_MODE_CLASS (MODE) == MODE_INT \
149       && GET_MODE_SIZE (MODE) < 4)      \
150     { (MODE) = SImode; }
151
152 /* Allocation boundary (in *bits*) for storing arguments in argument list.  */
153 #define PARM_BOUNDARY           32
154
155 /* The stack goes in 32-bit lumps.  */
156 #define STACK_BOUNDARY          32
157
158 /* Allocation boundary (in *bits*) for the code of a function.
159    16 is the minimum boundary; 32 would give better performance.  */
160 #define FUNCTION_BOUNDARY (optimize_size ? 16 : 32)
161
162 /* No data type wants to be aligned rounder than this.  */
163 #define BIGGEST_ALIGNMENT       32
164
165 /* Alignment of field after `int : 0' in a structure.  */
166 #define EMPTY_FIELD_BOUNDARY 32
167
168 /* No structure field wants to be aligned rounder than this.  */
169 #define BIGGEST_FIELD_ALIGNMENT 32
170
171 /* Define this if move instructions will actually fail to work
172    when given unaligned data.  */
173 #define STRICT_ALIGNMENT  (!TARGET_NO_STRICT_ALIGN)
174
175 /* Define this as 1 if `char' should by default be signed; else as 0.
176
177    On the NEC V850, loads do sign extension, so make this default.  */
178 #define DEFAULT_SIGNED_CHAR 1
179
180 #undef  SIZE_TYPE
181 #define SIZE_TYPE "unsigned int"
182
183 #undef  PTRDIFF_TYPE
184 #define PTRDIFF_TYPE "int"
185
186 #undef  WCHAR_TYPE
187 #define WCHAR_TYPE "long int"
188
189 #undef  WCHAR_TYPE_SIZE
190 #define WCHAR_TYPE_SIZE BITS_PER_WORD
191 \f
192 /* Standard register usage.  */
193
194 /* Number of actual hardware registers.
195    The hardware registers are assigned numbers for the compiler
196    from 0 to just below FIRST_PSEUDO_REGISTER.
197
198    All registers that the compiler knows about must be given numbers,
199    even those that are not normally considered general registers.  */
200
201 #define FIRST_PSEUDO_REGISTER 36
202
203 /* 1 for registers that have pervasive standard uses
204    and are not available for the register allocator.  */
205
206 #define FIXED_REGISTERS \
207   { 1, 1, 1, 1, 1, 1, 0, 0, \
208     0, 0, 0, 0, 0, 0, 0, 0, \
209     0, 0, 0, 0, 0, 0, 0, 0, \
210     0, 0, 0, 0, 0, 0, 1, 0, \
211     1, 1,       \
212     1, 1}
213
214 /* 1 for registers not available across function calls.
215    These must include the FIXED_REGISTERS and also any
216    registers that can be used without being saved.
217    The latter must include the registers where values are returned
218    and the register where structure-value addresses are passed.
219    Aside from that, you can include as many other registers as you
220    like.  */
221
222 #define CALL_USED_REGISTERS \
223   { 1, 1, 1, 1, 1, 1, 1, 1, \
224     1, 1, 1, 1, 1, 1, 1, 1, \
225     1, 1, 1, 1, 0, 0, 0, 0, \
226     0, 0, 0, 0, 0, 0, 1, 1, \
227     1, 1,       \
228     1, 1}
229
230 /* List the order in which to allocate registers.  Each register must be
231    listed once, even those in FIXED_REGISTERS.
232
233    On the 850, we make the return registers first, then all of the volatile
234    registers, then the saved registers in reverse order to better save the
235    registers with an out of line function, and finally the fixed
236    registers.  */
237
238 #define REG_ALLOC_ORDER                                                 \
239 {                                                                       \
240   10, 11,                               /* return registers */          \
241   12, 13, 14, 15, 16, 17, 18, 19,       /* scratch registers */         \
242    6,  7,  8,  9, 31,                   /* argument registers */        \
243   29, 28, 27, 26, 25, 24, 23, 22,       /* saved registers */           \
244   21, 20,  2,                                                           \
245    0,  1,  3,  4,  5, 30, 32, 33,      /* fixed registers */           \
246   34, 35                                                                \
247 }
248
249 /* Return number of consecutive hard regs needed starting at reg REGNO
250    to hold something of mode MODE.
251
252    This is ordinarily the length in words of a value of mode MODE
253    but can be less for certain modes in special long registers.  */
254
255 #define HARD_REGNO_NREGS(REGNO, MODE)   \
256   ((GET_MODE_SIZE (MODE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
257
258 /* Value is 1 if hard register REGNO can hold a value of machine-mode
259    MODE.  */
260
261 #define HARD_REGNO_MODE_OK(REGNO, MODE) \
262  ((GET_MODE_SIZE (MODE) <= 4) || (((REGNO) & 1) == 0 && (REGNO) != 0))
263
264 /* Value is 1 if it is a good idea to tie two pseudo registers
265    when one has mode MODE1 and one has mode MODE2.
266    If HARD_REGNO_MODE_OK could produce different values for MODE1 and MODE2,
267    for any hard reg, then this must be 0 for correct output.  */
268 #define MODES_TIEABLE_P(MODE1, MODE2) \
269   (MODE1 == MODE2 || (GET_MODE_SIZE (MODE1) <= 4 && GET_MODE_SIZE (MODE2) <= 4))
270
271 \f
272 /* Define the classes of registers for register constraints in the
273    machine description.  Also define ranges of constants.
274
275    One of the classes must always be named ALL_REGS and include all hard regs.
276    If there is more than one class, another class must be named NO_REGS
277    and contain no registers.
278
279    The name GENERAL_REGS must be the name of a class (or an alias for
280    another name such as ALL_REGS).  This is the class of registers
281    that is allowed by "g" or "r" in a register constraint.
282    Also, registers outside this class are allocated only when
283    instructions express preferences for them.
284
285    The classes must be numbered in nondecreasing order; that is,
286    a larger-numbered class must never be contained completely
287    in a smaller-numbered class.
288
289    For any two classes, it is very desirable that there be another
290    class that represents their union.  */
291    
292 enum reg_class
293 {
294   NO_REGS, GENERAL_REGS, EVEN_REGS, ALL_REGS, LIM_REG_CLASSES
295 };
296
297 #define N_REG_CLASSES (int) LIM_REG_CLASSES
298
299 /* Give names of register classes as strings for dump file.  */
300
301 #define REG_CLASS_NAMES \
302 { "NO_REGS", "GENERAL_REGS", "EVEN_REGS", "ALL_REGS", "LIM_REGS" }
303
304 /* Define which registers fit in which classes.
305    This is an initializer for a vector of HARD_REG_SET
306    of length N_REG_CLASSES.  */
307
308 #define REG_CLASS_CONTENTS                     \
309 {                                              \
310   { 0x00000000,0x0 }, /* NO_REGS      */       \
311   { 0xffffffff,0x0 }, /* GENERAL_REGS */       \
312   { 0x55555554,0x0 }, /* EVEN_REGS */          \
313   { 0xffffffff,0x0 }, /* ALL_REGS      */      \
314 }
315
316 /* The same information, inverted:
317    Return the class number of the smallest class containing
318    reg number REGNO.  This could be a conditional expression
319    or could index an array.  */
320
321 #define REGNO_REG_CLASS(REGNO)  ((REGNO == CC_REGNUM || REGNO == FCC_REGNUM) ? NO_REGS : GENERAL_REGS)
322
323 /* The class value for index registers, and the one for base regs.  */
324
325 #define INDEX_REG_CLASS NO_REGS
326 #define BASE_REG_CLASS  GENERAL_REGS
327
328 /* Macros to check register numbers against specific register classes.  */
329
330 /* These assume that REGNO is a hard or pseudo reg number.
331    They give nonzero only if REGNO is a hard reg of the suitable class
332    or a pseudo reg currently allocated to a suitable hard reg.
333    Since they use reg_renumber, they are safe only once reg_renumber
334    has been allocated, which happens in local-alloc.c.  */
335  
336 #define REGNO_OK_FOR_BASE_P(regno)             \
337   (((regno) < FIRST_PSEUDO_REGISTER            \
338     && (regno) != CC_REGNUM                    \
339     && (regno) != FCC_REGNUM)                  \
340    || reg_renumber[regno] >= 0)
341
342 #define REGNO_OK_FOR_INDEX_P(regno) 0
343
344 /* Convenience wrappers around insn_const_int_ok_for_constraint.  */
345
346 #define CONST_OK_FOR_I(VALUE) \
347   insn_const_int_ok_for_constraint (VALUE, CONSTRAINT_I)
348 #define CONST_OK_FOR_J(VALUE) \
349   insn_const_int_ok_for_constraint (VALUE, CONSTRAINT_J)
350 #define CONST_OK_FOR_K(VALUE) \
351   insn_const_int_ok_for_constraint (VALUE, CONSTRAINT_K)
352 #define CONST_OK_FOR_L(VALUE) \
353   insn_const_int_ok_for_constraint (VALUE, CONSTRAINT_L)
354 #define CONST_OK_FOR_M(VALUE) \
355   insn_const_int_ok_for_constraint (VALUE, CONSTRAINT_M)
356 #define CONST_OK_FOR_N(VALUE) \
357   insn_const_int_ok_for_constraint (VALUE, CONSTRAINT_N)
358 #define CONST_OK_FOR_O(VALUE) \
359   insn_const_int_ok_for_constraint (VALUE, CONSTRAINT_O)
360
361 \f
362 /* Stack layout; function entry, exit and calling.  */
363
364 /* Define this if pushing a word on the stack
365    makes the stack pointer a smaller address.  */
366
367 #define STACK_GROWS_DOWNWARD
368
369 /* Define this to nonzero if the nominal address of the stack frame
370    is at the high-address end of the local variables;
371    that is, each additional local variable allocated
372    goes at a more negative offset in the frame.  */
373
374 #define FRAME_GROWS_DOWNWARD 1
375
376 /* Offset within stack frame to start allocating local variables at.
377    If FRAME_GROWS_DOWNWARD, this is the offset to the END of the
378    first local allocated.  Otherwise, it is the offset to the BEGINNING
379    of the first local allocated.  */
380
381 #define STARTING_FRAME_OFFSET 0
382
383 /* Offset of first parameter from the argument pointer register value.  */
384 /* Is equal to the size of the saved fp + pc, even if an fp isn't
385    saved since the value is used before we know.  */
386
387 #define FIRST_PARM_OFFSET(FNDECL) 0
388
389 /* Specify the registers used for certain standard purposes.
390    The values of these macros are register numbers.  */
391
392 /* Register to use for pushing function arguments.  */
393 #define STACK_POINTER_REGNUM SP_REGNUM
394
395 /* Base register for access to local variables of the function.  */
396 #define FRAME_POINTER_REGNUM 34
397
398 /* Register containing return address from latest function call.  */
399 #define LINK_POINTER_REGNUM LP_REGNUM
400      
401 /* On some machines the offset between the frame pointer and starting
402    offset of the automatic variables is not known until after register
403    allocation has been done (for example, because the saved registers
404    are between these two locations).  On those machines, define
405    `FRAME_POINTER_REGNUM' the number of a special, fixed register to
406    be used internally until the offset is known, and define
407    `HARD_FRAME_POINTER_REGNUM' to be actual the hard register number
408    used for the frame pointer.
409
410    You should define this macro only in the very rare circumstances
411    when it is not possible to calculate the offset between the frame
412    pointer and the automatic variables until after register
413    allocation has been completed.  When this macro is defined, you
414    must also indicate in your definition of `ELIMINABLE_REGS' how to
415    eliminate `FRAME_POINTER_REGNUM' into either
416    `HARD_FRAME_POINTER_REGNUM' or `STACK_POINTER_REGNUM'.
417
418    Do not define this macro if it would be the same as
419    `FRAME_POINTER_REGNUM'.  */
420 #undef  HARD_FRAME_POINTER_REGNUM 
421 #define HARD_FRAME_POINTER_REGNUM 29
422
423 /* Base register for access to arguments of the function.  */
424 #define ARG_POINTER_REGNUM 35
425
426 /* Register in which static-chain is passed to a function.  */
427 #define STATIC_CHAIN_REGNUM 20
428
429 /* If defined, this macro specifies a table of register pairs used to
430    eliminate unneeded registers that point into the stack frame.  If
431    it is not defined, the only elimination attempted by the compiler
432    is to replace references to the frame pointer with references to
433    the stack pointer.
434
435    The definition of this macro is a list of structure
436    initializations, each of which specifies an original and
437    replacement register.
438
439    On some machines, the position of the argument pointer is not
440    known until the compilation is completed.  In such a case, a
441    separate hard register must be used for the argument pointer.
442    This register can be eliminated by replacing it with either the
443    frame pointer or the argument pointer, depending on whether or not
444    the frame pointer has been eliminated.
445
446    In this case, you might specify:
447         #define ELIMINABLE_REGS  \
448         {{ARG_POINTER_REGNUM, STACK_POINTER_REGNUM}, \
449          {ARG_POINTER_REGNUM, FRAME_POINTER_REGNUM}, \
450          {FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM}}
451
452    Note that the elimination of the argument pointer with the stack
453    pointer is specified first since that is the preferred elimination.  */
454
455 #define ELIMINABLE_REGS                                                 \
456 {{ FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM },                        \
457  { FRAME_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM },                   \
458  { ARG_POINTER_REGNUM,   STACK_POINTER_REGNUM },                        \
459  { ARG_POINTER_REGNUM,   HARD_FRAME_POINTER_REGNUM }}                   \
460
461 /* This macro is similar to `INITIAL_FRAME_POINTER_OFFSET'.  It
462    specifies the initial difference between the specified pair of
463    registers.  This macro must be defined if `ELIMINABLE_REGS' is
464    defined.  */
465
466 #define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET)                    \
467 {                                                                       \
468   if ((FROM) == FRAME_POINTER_REGNUM)                                   \
469     (OFFSET) = get_frame_size () + crtl->outgoing_args_size;    \
470   else if ((FROM) == ARG_POINTER_REGNUM)                                \
471    (OFFSET) = compute_frame_size (get_frame_size (), (long *)0);        \
472   else                                                                  \
473     gcc_unreachable ();                                                 \
474 }
475
476 /* Keep the stack pointer constant throughout the function.  */
477 #define ACCUMULATE_OUTGOING_ARGS 1
478
479 #define RETURN_ADDR_RTX(COUNT, FP) v850_return_addr (COUNT)
480 \f
481 /* Define a data type for recording info about an argument list
482    during the scan of that argument list.  This data type should
483    hold all necessary information about the function itself
484    and about the args processed so far, enough to enable macros
485    such as FUNCTION_ARG to determine where the next arg should go.  */
486
487 #define CUMULATIVE_ARGS struct cum_arg
488 struct cum_arg { int nbytes; int anonymous_args; };
489
490 /* Initialize a variable CUM of type CUMULATIVE_ARGS
491    for a call to a function whose data type is FNTYPE.
492    For a library call, FNTYPE is 0.  */
493
494 #define INIT_CUMULATIVE_ARGS(CUM, FNTYPE, LIBNAME, INDIRECT, N_NAMED_ARGS) \
495  ((CUM).nbytes = 0, (CUM).anonymous_args = 0)
496
497 /* When a parameter is passed in a register, stack space is still
498    allocated for it.  */
499 #define REG_PARM_STACK_SPACE(DECL) 0
500
501 /* 1 if N is a possible register number for function argument passing.  */
502
503 #define FUNCTION_ARG_REGNO_P(N) (N >= 6 && N <= 9)
504
505 /* Define how to find the value returned by a library function
506    assuming the value has mode MODE.  */
507
508 #define LIBCALL_VALUE(MODE) \
509   gen_rtx_REG (MODE, 10)
510
511 #define DEFAULT_PCC_STRUCT_RETURN 0
512
513 /* EXIT_IGNORE_STACK should be nonzero if, when returning from a function,
514    the stack pointer does not matter.  The value is tested only in
515    functions that have frame pointers.
516    No definition is equivalent to always zero.  */
517
518 #define EXIT_IGNORE_STACK 1
519
520 /* Define this macro as a C expression that is nonzero for registers
521    used by the epilogue or the `return' pattern.  */
522
523 #define EPILOGUE_USES(REGNO) \
524   (reload_completed && (REGNO) == LINK_POINTER_REGNUM)
525
526 /* Output assembler code to FILE to increment profiler label # LABELNO
527    for profiling a function entry.  */
528
529 #define FUNCTION_PROFILER(FILE, LABELNO) ;
530
531 /* Length in units of the trampoline for entering a nested function.  */
532
533 #define TRAMPOLINE_SIZE 24
534
535 /* Addressing modes, and classification of registers for them.  */
536
537 \f
538 /* 1 if X is an rtx for a constant that is a valid address.  */
539
540 /* ??? This seems too exclusive.  May get better code by accepting more
541    possibilities here, in particular, should accept ZDA_NAME SYMBOL_REFs.  */
542
543 #define CONSTANT_ADDRESS_P(X) constraint_satisfied_p (X, CONSTRAINT_K)
544
545 /* Maximum number of registers that can appear in a valid memory address.  */
546
547 #define MAX_REGS_PER_ADDRESS 1
548
549 /* The macros REG_OK_FOR..._P assume that the arg is a REG rtx
550    and check its validity for a certain class.
551    We have two alternate definitions for each of them.
552    The usual definition accepts all pseudo regs; the other rejects
553    them unless they have been allocated suitable hard regs.
554    The symbol REG_OK_STRICT causes the latter definition to be used.
555
556    Most source files want to accept pseudo regs in the hope that
557    they will get allocated to the class that the insn wants them to be in.
558    Source files for reload pass need to be strict.
559    After reload, it makes no difference, since pseudo regs have
560    been eliminated by then.  */
561
562 #ifndef REG_OK_STRICT
563
564 /* Nonzero if X is a hard reg that can be used as an index
565    or if it is a pseudo reg.  */
566 #define REG_OK_FOR_INDEX_P(X) 0
567 /* Nonzero if X is a hard reg that can be used as a base reg
568    or if it is a pseudo reg.  */
569 #define REG_OK_FOR_BASE_P(X) 1
570 #define REG_OK_FOR_INDEX_P_STRICT(X) 0
571 #define REG_OK_FOR_BASE_P_STRICT(X) REGNO_OK_FOR_BASE_P (REGNO (X))
572 #define STRICT 0
573
574 #else
575
576 /* Nonzero if X is a hard reg that can be used as an index.  */
577 #define REG_OK_FOR_INDEX_P(X) 0
578 /* Nonzero if X is a hard reg that can be used as a base reg.  */
579 #define REG_OK_FOR_BASE_P(X) REGNO_OK_FOR_BASE_P (REGNO (X))
580 #define STRICT 1
581
582 #endif
583
584 \f
585 /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
586    that is a valid memory address for an instruction.
587    The MODE argument is the machine mode for the MEM expression
588    that wants to use this address.
589
590    The other macros defined here are used only in GO_IF_LEGITIMATE_ADDRESS,
591    except for CONSTANT_ADDRESS_P which is actually
592    machine-independent.  */
593
594 /* Accept either REG or SUBREG where a register is valid.  */
595   
596 #define RTX_OK_FOR_BASE_P(X)                                            \
597   ((REG_P (X) && REG_OK_FOR_BASE_P (X))                                 \
598    || (GET_CODE (X) == SUBREG && REG_P (SUBREG_REG (X))                 \
599        && REG_OK_FOR_BASE_P (SUBREG_REG (X))))
600
601 #define GO_IF_LEGITIMATE_ADDRESS(MODE, X, ADDR)                         \
602 do {                                                                    \
603   if (RTX_OK_FOR_BASE_P (X))                                            \
604     goto ADDR;                                                          \
605   if (CONSTANT_ADDRESS_P (X)                                            \
606       && (MODE == QImode || INTVAL (X) % 2 == 0)                        \
607       && (GET_MODE_SIZE (MODE) <= 4 || INTVAL (X) % 4 == 0))            \
608     goto ADDR;                                                          \
609   if (GET_CODE (X) == LO_SUM                                            \
610       && REG_P (XEXP (X, 0))                                            \
611       && REG_OK_FOR_BASE_P (XEXP (X, 0))                                \
612       && CONSTANT_P (XEXP (X, 1))                                       \
613       && (GET_CODE (XEXP (X, 1)) != CONST_INT                           \
614           || ((MODE == QImode || INTVAL (XEXP (X, 1)) % 2 == 0)         \
615               && CONST_OK_FOR_K (INTVAL (XEXP (X, 1)))))                \
616       && GET_MODE_SIZE (MODE) <= GET_MODE_SIZE (word_mode))             \
617     goto ADDR;                                                          \
618   if (special_symbolref_operand (X, MODE)                               \
619       && (GET_MODE_SIZE (MODE) <= GET_MODE_SIZE (word_mode)))           \
620      goto ADDR;                                                         \
621   if (GET_CODE (X) == PLUS                                              \
622       && RTX_OK_FOR_BASE_P (XEXP (X, 0))                                \
623       && constraint_satisfied_p (XEXP (X,1), CONSTRAINT_K)              \
624       && ((MODE == QImode || INTVAL (XEXP (X, 1)) % 2 == 0)             \
625            && CONST_OK_FOR_K (INTVAL (XEXP (X, 1))                      \
626                               + (GET_MODE_NUNITS (MODE) * UNITS_PER_WORD)))) \
627     goto ADDR;                  \
628 } while (0)
629
630 \f
631 /* Given a comparison code (EQ, NE, etc.) and the first operand of a COMPARE,
632    return the mode to be used for the comparison.
633
634    For floating-point equality comparisons, CCFPEQmode should be used.
635    VOIDmode should be used in all other cases.
636
637    For integer comparisons against zero, reduce to CCNOmode or CCZmode if
638    possible, to allow for more combinations.  */
639
640 #define SELECT_CC_MODE(OP, X, Y)       v850_select_cc_mode (OP, X, Y)
641
642 /* Tell final.c how to eliminate redundant test instructions.  */
643
644 /* Here we define machine-dependent flags and fields in cc_status
645    (see `conditions.h').  No extra ones are needed for the VAX.  */
646
647 /* Store in cc_status the expressions
648    that the condition codes will describe
649    after execution of an instruction whose pattern is EXP.
650    Do not alter them if the instruction would not alter the cc's.  */
651
652 #define CC_OVERFLOW_UNUSABLE 0x200
653 #define CC_NO_CARRY CC_NO_OVERFLOW
654 #define NOTICE_UPDATE_CC(EXP, INSN) notice_update_cc(EXP, INSN)
655
656 /* Nonzero if access to memory by bytes or half words is no faster
657    than accessing full words.  */
658 #define SLOW_BYTE_ACCESS 1
659
660 /* According expr.c, a value of around 6 should minimize code size, and
661    for the V850 series, that's our primary concern.  */
662 #define MOVE_RATIO(speed) 6
663
664 /* Indirect calls are expensive, never turn a direct call
665    into an indirect call.  */
666 #define NO_FUNCTION_CSE
667
668 /* The four different data regions on the v850.  */
669 typedef enum 
670 {
671   DATA_AREA_NORMAL,
672   DATA_AREA_SDA,
673   DATA_AREA_TDA,
674   DATA_AREA_ZDA
675 } v850_data_area;
676
677 #define TEXT_SECTION_ASM_OP  "\t.section .text"
678 #define DATA_SECTION_ASM_OP  "\t.section .data"
679 #define BSS_SECTION_ASM_OP   "\t.section .bss"
680 #define SDATA_SECTION_ASM_OP "\t.section .sdata,\"aw\""
681 #define SBSS_SECTION_ASM_OP  "\t.section .sbss,\"aw\""
682
683 #define SCOMMON_ASM_OP         "\t.scomm\t"
684 #define ZCOMMON_ASM_OP         "\t.zcomm\t"
685 #define TCOMMON_ASM_OP         "\t.tcomm\t"
686
687 #define ASM_COMMENT_START "#"
688
689 /* Output to assembler file text saying following lines
690    may contain character constants, extra white space, comments, etc.  */
691
692 #define ASM_APP_ON "#APP\n"
693
694 /* Output to assembler file text saying following lines
695    no longer contain unusual constructs.  */
696
697 #define ASM_APP_OFF "#NO_APP\n"
698
699 #undef  USER_LABEL_PREFIX
700 #define USER_LABEL_PREFIX "_"
701
702 /* This says how to output the assembler to define a global
703    uninitialized but not common symbol.  */
704
705 #define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
706   asm_output_aligned_bss ((FILE), (DECL), (NAME), (SIZE), (ALIGN))
707
708 #undef  ASM_OUTPUT_ALIGNED_BSS 
709 #define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
710   v850_output_aligned_bss (FILE, DECL, NAME, SIZE, ALIGN)
711
712 /* This says how to output the assembler to define a global
713    uninitialized, common symbol.  */
714 #undef  ASM_OUTPUT_ALIGNED_COMMON
715 #undef  ASM_OUTPUT_COMMON
716 #define ASM_OUTPUT_ALIGNED_DECL_COMMON(FILE, DECL, NAME, SIZE, ALIGN) \
717      v850_output_common (FILE, DECL, NAME, SIZE, ALIGN)
718
719 /* This says how to output the assembler to define a local
720    uninitialized symbol.  */
721 #undef  ASM_OUTPUT_ALIGNED_LOCAL
722 #undef  ASM_OUTPUT_LOCAL
723 #define ASM_OUTPUT_ALIGNED_DECL_LOCAL(FILE, DECL, NAME, SIZE, ALIGN) \
724      v850_output_local (FILE, DECL, NAME, SIZE, ALIGN)
725      
726 /* Globalizing directive for a label.  */
727 #define GLOBAL_ASM_OP "\t.global "
728
729 #define ASM_PN_FORMAT "%s___%lu"
730
731 /* This is how we tell the assembler that two symbols have the same value.  */
732
733 #define ASM_OUTPUT_DEF(FILE,NAME1,NAME2) \
734   do { assemble_name(FILE, NAME1);       \
735        fputs(" = ", FILE);               \
736        assemble_name(FILE, NAME2);       \
737        fputc('\n', FILE); } while (0)
738
739
740 /* How to refer to registers in assembler output.
741    This sequence is indexed by compiler's hard-register-number (see above).  */
742
743 #define REGISTER_NAMES                                         \
744 {  "r0",  "r1",  "r2",  "sp",  "gp",  "r5",  "r6" , "r7",      \
745    "r8",  "r9", "r10", "r11", "r12", "r13", "r14", "r15",      \
746   "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",      \
747   "r24", "r25", "r26", "r27", "r28", "r29",  "ep", "r31",      \
748   "psw", "fcc",      \
749   ".fp", ".ap"}
750
751 /* Register numbers */
752
753 #define ADDITIONAL_REGISTER_NAMES              \
754 { { "zero",    ZERO_REGNUM },                  \
755   { "hp",      2 },                            \
756   { "r3",      3 },                            \
757   { "r4",      4 },                            \
758   { "tp",      5 },                            \
759   { "fp",      29 },                           \
760   { "r30",     30 },                           \
761   { "lp",      LP_REGNUM} }
762
763 /* This is how to output an element of a case-vector that is absolute.  */
764
765 #define ASM_OUTPUT_ADDR_VEC_ELT(FILE, VALUE) \
766   fprintf (FILE, "\t%s .L%d\n",                                 \
767            (TARGET_BIG_SWITCH ? ".long" : ".short"), VALUE)
768
769 /* This is how to output an element of a case-vector that is relative.  */
770
771 /* Disable the shift, which is for the currently disabled "switch"
772    opcode.  Se casesi in v850.md.  */
773
774 #define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, BODY, VALUE, REL)                \
775   fprintf (FILE, "\t%s %s.L%d-.L%d%s\n",                                \
776            (TARGET_BIG_SWITCH ? ".long" : ".short"),                    \
777            (0 && ! TARGET_BIG_SWITCH && (TARGET_V850E || TARGET_V850E2_ALL) ? "(" : ""),             \
778            VALUE, REL,                                                  \
779            (0 && ! TARGET_BIG_SWITCH && (TARGET_V850E || TARGET_V850E2_ALL) ? ")>>1" : ""))
780
781 #define ASM_OUTPUT_ALIGN(FILE, LOG)     \
782   if ((LOG) != 0)                       \
783     fprintf (FILE, "\t.align %d\n", (LOG))
784
785 /* We don't have to worry about dbx compatibility for the v850.  */
786 #define DEFAULT_GDB_EXTENSIONS 1
787
788 /* Use stabs debugging info by default.  */
789 #undef  PREFERRED_DEBUGGING_TYPE
790 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
791
792 #define DWARF2_FRAME_INFO  1
793 #define DWARF2_UNWIND_INFO 0
794 #define INCOMING_RETURN_ADDR_RTX   gen_rtx_REG (Pmode, LINK_POINTER_REGNUM)
795 #define DWARF_FRAME_RETURN_COLUMN  DWARF_FRAME_REGNUM (LINK_POINTER_REGNUM)
796
797 /* Specify the machine mode that this machine uses
798    for the index in the tablejump instruction.  */
799 #define CASE_VECTOR_MODE (TARGET_BIG_SWITCH ? SImode : HImode)
800
801 /* Define as C expression which evaluates to nonzero if the tablejump
802    instruction expects the table to contain offsets from the address of the
803    table.
804    Do not define this if the table should contain absolute addresses.  */
805 #define CASE_VECTOR_PC_RELATIVE 1
806
807 /* The switch instruction requires that the jump table immediately follow
808    it.  */
809 #define JUMP_TABLES_IN_TEXT_SECTION (!TARGET_JUMP_TABLES_IN_DATA_SECTION)
810
811 #undef ASM_OUTPUT_BEFORE_CASE_LABEL
812 #define ASM_OUTPUT_BEFORE_CASE_LABEL(FILE,PREFIX,NUM,TABLE) \
813   ASM_OUTPUT_ALIGN ((FILE), (TARGET_BIG_SWITCH ? 2 : 1));
814
815 #define WORD_REGISTER_OPERATIONS
816
817 /* Byte and short loads sign extend the value to a word.  */
818 #define LOAD_EXTEND_OP(MODE) SIGN_EXTEND
819
820 /* This flag, if defined, says the same insns that convert to a signed fixnum
821    also convert validly to an unsigned one.  */
822 #define FIXUNS_TRUNC_LIKE_FIX_TRUNC
823
824 /* Max number of bytes we can move from memory to memory
825    in one reasonably fast instruction.  */
826 #define MOVE_MAX        4
827
828 /* Define if shifts truncate the shift count
829    which implies one can omit a sign-extension or zero-extension
830    of a shift count.  */
831 #define SHIFT_COUNT_TRUNCATED 1
832
833 /* Value is 1 if truncating an integer of INPREC bits to OUTPREC bits
834    is done just by pretending it is already truncated.  */
835 #define TRULY_NOOP_TRUNCATION(OUTPREC, INPREC) 1
836
837 /* Specify the machine mode that pointers have.
838    After generation of rtl, the compiler makes no further distinction
839    between pointers and any other objects of this machine mode.  */
840 #define Pmode SImode
841
842 /* A function address in a call instruction
843    is a byte address (for indexing purposes)
844    so give the MEM rtx a byte's mode.  */
845 #define FUNCTION_MODE QImode
846
847 /* Tell compiler we want to support GHS pragmas */
848 #define REGISTER_TARGET_PRAGMAS() do {                          \
849   c_register_pragma ("ghs", "interrupt", ghs_pragma_interrupt); \
850   c_register_pragma ("ghs", "section",   ghs_pragma_section);   \
851   c_register_pragma ("ghs", "starttda",  ghs_pragma_starttda);  \
852   c_register_pragma ("ghs", "startsda",  ghs_pragma_startsda);  \
853   c_register_pragma ("ghs", "startzda",  ghs_pragma_startzda);  \
854   c_register_pragma ("ghs", "endtda",    ghs_pragma_endtda);    \
855   c_register_pragma ("ghs", "endsda",    ghs_pragma_endsda);    \
856   c_register_pragma ("ghs", "endzda",    ghs_pragma_endzda);    \
857 } while (0)
858
859 /* enum GHS_SECTION_KIND is an enumeration of the kinds of sections that
860    can appear in the "ghs section" pragma.  These names are used to index
861    into the GHS_default_section_names[] and GHS_current_section_names[]
862    that are defined in v850.c, and so the ordering of each must remain
863    consistent. 
864
865    These arrays give the default and current names for each kind of 
866    section defined by the GHS pragmas.  The current names can be changed
867    by the "ghs section" pragma.  If the current names are null, use 
868    the default names.  Note that the two arrays have different types.
869
870    For the *normal* section kinds (like .data, .text, etc.) we do not
871    want to explicitly force the name of these sections, but would rather
872    let the linker (or at least the back end) choose the name of the 
873    section, UNLESS the user has force a specific name for these section
874    kinds.  To accomplish this set the name in ghs_default_section_names
875    to null.  */
876
877 enum GHS_section_kind
878
879   GHS_SECTION_KIND_DEFAULT,
880
881   GHS_SECTION_KIND_TEXT,
882   GHS_SECTION_KIND_DATA, 
883   GHS_SECTION_KIND_RODATA,
884   GHS_SECTION_KIND_BSS,
885   GHS_SECTION_KIND_SDATA,
886   GHS_SECTION_KIND_ROSDATA,
887   GHS_SECTION_KIND_TDATA,
888   GHS_SECTION_KIND_ZDATA,
889   GHS_SECTION_KIND_ROZDATA,
890
891   COUNT_OF_GHS_SECTION_KINDS  /* must be last */
892 };
893
894 /* The following code is for handling pragmas supported by the
895    v850 compiler produced by Green Hills Software.  This is at
896    the specific request of a customer.  */
897
898 typedef struct data_area_stack_element
899 {
900   struct data_area_stack_element * prev;
901   v850_data_area                   data_area; /* Current default data area.  */
902 } data_area_stack_element;
903
904 /* Track the current data area set by the
905    data area pragma (which can be nested).  */
906 extern data_area_stack_element * data_area_stack;
907
908 /* Names of the various data areas used on the v850.  */
909 extern tree GHS_default_section_names [(int) COUNT_OF_GHS_SECTION_KINDS];
910 extern tree GHS_current_section_names [(int) COUNT_OF_GHS_SECTION_KINDS];
911
912 /* The assembler op to start the file.  */
913
914 #define FILE_ASM_OP "\t.file\n"
915
916 /* Enable the register move pass to improve code.  */
917 #define ENABLE_REGMOVE_PASS
918
919
920 /* Implement ZDA, TDA, and SDA */
921
922 #define EP_REGNUM 30    /* ep register number */
923
924 #define SYMBOL_FLAG_ZDA         (SYMBOL_FLAG_MACH_DEP << 0)
925 #define SYMBOL_FLAG_TDA         (SYMBOL_FLAG_MACH_DEP << 1)
926 #define SYMBOL_FLAG_SDA         (SYMBOL_FLAG_MACH_DEP << 2)
927 #define SYMBOL_REF_ZDA_P(X)     ((SYMBOL_REF_FLAGS (X) & SYMBOL_FLAG_ZDA) != 0)
928 #define SYMBOL_REF_TDA_P(X)     ((SYMBOL_REF_FLAGS (X) & SYMBOL_FLAG_TDA) != 0)
929 #define SYMBOL_REF_SDA_P(X)     ((SYMBOL_REF_FLAGS (X) & SYMBOL_FLAG_SDA) != 0)
930
931 #define TARGET_ASM_INIT_SECTIONS v850_asm_init_sections
932
933 /* Define this so that the cc1plus will not think that system header files
934    need an implicit 'extern "C" { ... }' assumed.  This breaks testing C++
935    in a build directory where the libstdc++ header files are found via a
936    -isystem <path-to-build-dir>.  */
937 #define NO_IMPLICIT_EXTERN_C
938
939 #endif /* ! GCC_V850_H */