OSDN Git Service

2004-08-22 Andrew Pinski <apinski@apple.com>
[pf3gnuchains/gcc-fork.git] / gcc / target.h
1 /* Data structure definitions for a generic GCC target.
2    Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 2, or (at your option) any
7 later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18  In other words, you are welcome to use, share and improve this program.
19  You are forbidden to forbid anyone else to use, share and improve
20  what you give them.   Help stamp out software-hoarding!  */
21
22 /* This file contains a data structure that describes a GCC target.
23    At present it is incomplete, but in future it should grow to
24    contain most or all target machine and target O/S specific
25    information.
26
27    This structure has its initializer declared in target-def.h in the
28    form of large macro TARGET_INITIALIZER that expands to many smaller
29    macros.
30
31    The smaller macros each initialize one component of the structure,
32    and each has a default.  Each target should have a file that
33    includes target.h and target-def.h, and overrides any inappropriate
34    defaults by undefining the relevant macro and defining a suitable
35    replacement.  That file should then contain the definition of
36    "targetm" like so:
37
38    struct gcc_target targetm = TARGET_INITIALIZER;
39
40    Doing things this way allows us to bring together everything that
41    defines a GCC target.  By supplying a default that is appropriate
42    to most targets, we can easily add new items without needing to
43    edit dozens of target configuration files.  It should also allow us
44    to gradually reduce the amount of conditional compilation that is
45    scattered throughout GCC.  */
46
47 #ifndef GCC_TARGET_H
48 #define GCC_TARGET_H
49
50 #include "tm.h"
51 #include "insn-modes.h"
52
53 struct gcc_target
54 {
55   /* Functions that output assembler for the target.  */
56   struct asm_out
57   {
58     /* Opening and closing parentheses for asm expression grouping.  */
59     const char *open_paren, *close_paren;
60
61     /* Assembler instructions for creating various kinds of integer object.  */
62     const char *byte_op;
63     struct asm_int_op
64     {
65       const char *hi;
66       const char *si;
67       const char *di;
68       const char *ti;
69     } aligned_op, unaligned_op;
70
71     /* Try to output the assembler code for an integer object whose
72        value is given by X.  SIZE is the size of the object in bytes and
73        ALIGNED_P indicates whether it is aligned.  Return true if
74        successful.  Only handles cases for which BYTE_OP, ALIGNED_OP
75        and UNALIGNED_OP are NULL.  */
76     bool (* integer) (rtx x, unsigned int size, int aligned_p);
77
78     /* Output code that will globalize a label.  */
79     void (* globalize_label) (FILE *, const char *);
80
81     /* Output code that will emit a label for unwind info, if this
82        target requires such labels.  Second argument is the decl the
83        unwind info is associated with, third is a boolean: true if
84        this is for exception handling, fourth is a boolean: true if
85        this is only a placeholder for an omitted FDE.  */
86     void (* unwind_label) (FILE *, tree, int, int);
87
88     /* Emit any directives required to unwind this instruction.  */
89     void (* unwind_emit) (FILE *, rtx);
90
91     /* Output an internal label.  */
92     void (* internal_label) (FILE *, const char *, unsigned long);
93
94     /* Emit an assembler directive to set visibility for the symbol
95        associated with the tree decl.  */
96     void (* visibility) (tree, int);
97
98     /* Output the assembler code for entry to a function.  */
99     void (* function_prologue) (FILE *, HOST_WIDE_INT);
100
101     /* Output the assembler code for end of prologue.  */
102     void (* function_end_prologue) (FILE *);
103
104     /* Output the assembler code for start of epilogue.  */
105     void (* function_begin_epilogue) (FILE *);
106
107     /* Output the assembler code for function exit.  */
108     void (* function_epilogue) (FILE *, HOST_WIDE_INT);
109
110     /* Switch to an arbitrary section NAME with attributes as
111        specified by FLAGS.  */
112     void (* named_section) (const char *, unsigned int);
113
114     /* Switch to the section that holds the exception table.  */
115     void (* exception_section) (void);
116
117     /* Switch to the section that holds the exception frames.  */
118     void (* eh_frame_section) (void);
119
120     /* Select and switch to a section for EXP.  It may be a DECL or a
121        constant.  RELOC is nonzero if runtime relocations must be applied;
122        bit 1 will be set if the runtime relocations require non-local
123        name resolution.  ALIGN is the required alignment of the data.  */
124     void (* select_section) (tree, int, unsigned HOST_WIDE_INT);
125
126     /* Select and switch to a section for X with MODE.  ALIGN is
127        the desired alignment of the data.  */
128     void (* select_rtx_section) (enum machine_mode, rtx,
129                                  unsigned HOST_WIDE_INT);
130
131     /* Select a unique section name for DECL.  RELOC is the same as
132        for SELECT_SECTION.  */
133     void (* unique_section) (tree, int);
134
135     /* Tell assembler to switch to the readonly data section associated
136        with function DECL.  */
137     void (* function_rodata_section) (tree); 
138
139     /* Output a constructor for a symbol with a given priority.  */
140     void (* constructor) (rtx, int);
141
142     /* Output a destructor for a symbol with a given priority.  */
143     void (* destructor) (rtx, int);
144
145     /* Output the assembler code for a thunk function.  THUNK_DECL is the
146        declaration for the thunk function itself, FUNCTION is the decl for
147        the target function.  DELTA is an immediate constant offset to be
148        added to THIS.  If VCALL_OFFSET is nonzero, the word at
149        *(*this + vcall_offset) should be added to THIS.  */
150     void (* output_mi_thunk) (FILE *file, tree thunk_decl,
151                               HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
152                               tree function_decl);
153
154     /* Determine whether output_mi_thunk would succeed.  */
155     /* ??? Ideally, this hook would not exist, and success or failure
156        would be returned from output_mi_thunk directly.  But there's
157        too much undo-able setup involved in invoking output_mi_thunk.
158        Could be fixed by making output_mi_thunk emit rtl instead of
159        text to the output file.  */
160     bool (* can_output_mi_thunk) (tree thunk_decl, HOST_WIDE_INT delta,
161                                   HOST_WIDE_INT vcall_offset,
162                                   tree function_decl);
163
164     /* Output any boilerplate text needed at the beginning of a
165        translation unit.  */
166     void (*file_start) (void);
167
168     /* Output any boilerplate text needed at the end of a
169        translation unit.  */
170     void (*file_end) (void);
171
172     /* Output an assembler pseudo-op to declare a library function name
173        external.  */
174     void (*external_libcall) (rtx);
175
176      /* Output an assembler directive to mark decl live. This instructs
177         linker to not dead code strip this symbol.  */
178     void (*mark_decl_preserved) (const char *);
179
180   } asm_out;
181
182   /* Functions relating to instruction scheduling.  */
183   struct sched
184   {
185     /* Given the current cost, COST, of an insn, INSN, calculate and
186        return a new cost based on its relationship to DEP_INSN through
187        the dependence LINK.  The default is to make no adjustment.  */
188     int (* adjust_cost) (rtx insn, rtx link, rtx def_insn, int cost);
189
190     /* Adjust the priority of an insn as you see fit.  Returns the new
191        priority.  */
192     int (* adjust_priority) (rtx, int);
193
194     /* Function which returns the maximum number of insns that can be
195        scheduled in the same machine cycle.  This must be constant
196        over an entire compilation.  The default is 1.  */
197     int (* issue_rate) (void);
198
199     /* Calculate how much this insn affects how many more insns we
200        can emit this cycle.  Default is they all cost the same.  */
201     int (* variable_issue) (FILE *, int, rtx, int);
202
203     /* Initialize machine-dependent scheduling code.  */
204     void (* md_init) (FILE *, int, int);
205
206     /* Finalize machine-dependent scheduling code.  */
207     void (* md_finish) (FILE *, int);
208
209     /* Initialize machine-dependent function while scheduling code.  */
210     void (* md_init_global) (FILE *, int, int);
211
212     /* Finalize machine-dependent function wide scheduling code.  */
213     void (* md_finish_global) (FILE *, int);
214
215     /* Reorder insns in a machine-dependent fashion, in two different
216        places.  Default does nothing.  */
217     int (* reorder) (FILE *, int, rtx *, int *, int);
218     int (* reorder2) (FILE *, int, rtx *, int *, int);
219
220     /* The following member value is a pointer to a function called
221        after evaluation forward dependencies of insns in chain given
222        by two parameter values (head and tail correspondingly).  */
223     void (* dependencies_evaluation_hook) (rtx, rtx);
224
225     /* The values of the following four members are pointers to
226        functions used to simplify the automaton descriptions.
227        dfa_pre_cycle_insn and dfa_post_cycle_insn give functions
228        returning insns which are used to change the pipeline hazard
229        recognizer state when the new simulated processor cycle
230        correspondingly starts and finishes.  The function defined by
231        init_dfa_pre_cycle_insn and init_dfa_post_cycle_insn are used
232        to initialize the corresponding insns.  The default values of
233        the members result in not changing the automaton state when
234        the new simulated processor cycle correspondingly starts and
235        finishes.  */
236     void (* init_dfa_pre_cycle_insn) (void);
237     rtx (* dfa_pre_cycle_insn) (void);
238     void (* init_dfa_post_cycle_insn) (void);
239     rtx (* dfa_post_cycle_insn) (void);
240
241     /* The following member value is a pointer to a function returning value
242        which defines how many insns in queue `ready' will we try for
243        multi-pass scheduling.  If the member value is nonzero and the
244        function returns positive value, the DFA based scheduler will make
245        multi-pass scheduling for the first cycle.  In other words, we will
246        try to choose ready insn which permits to start maximum number of
247        insns on the same cycle.  */
248     int (* first_cycle_multipass_dfa_lookahead) (void);
249
250     /* The following member value is pointer to a function controlling
251        what insns from the ready insn queue will be considered for the
252        multipass insn scheduling.  If the hook returns zero for insn
253        passed as the parameter, the insn will be not chosen to be
254        issued.  */
255     int (* first_cycle_multipass_dfa_lookahead_guard) (rtx);
256
257     /* The following member value is pointer to a function called by
258        the insn scheduler before issuing insn passed as the third
259        parameter on given cycle.  If the hook returns nonzero, the
260        insn is not issued on given processors cycle.  Instead of that,
261        the processor cycle is advanced.  If the value passed through
262        the last parameter is zero, the insn ready queue is not sorted
263        on the new cycle start as usually.  The first parameter passes
264        file for debugging output.  The second one passes the scheduler
265        verbose level of the debugging output.  The forth and the fifth
266        parameter values are correspondingly processor cycle on which
267        the previous insn has been issued and the current processor
268        cycle.  */
269     int (* dfa_new_cycle) (FILE *, int, rtx, int, int, int *);
270
271     /* The following member value is a pointer to a function called
272        by the insn scheduler.  It should return true if there exists a
273        dependence which is considered costly by the target, between 
274        the insn passed as the first parameter, and the insn passed as 
275        the second parameter.  The third parameter is the INSN_DEPEND 
276        link that represents the dependence between the two insns.  The
277        fourth argument is the cost of the dependence as estimated by
278        the scheduler.  The last argument is the distance in cycles 
279        between the already scheduled insn (first parameter) and the
280        the second insn (second parameter).  */
281     bool (* is_costly_dependence) (rtx, rtx, rtx, int, int);
282   } sched;
283
284   /* Return machine mode for filter value. */
285   enum machine_mode (* eh_return_filter_mode) (void);
286
287   /* Given two decls, merge their attributes and return the result.  */
288   tree (* merge_decl_attributes) (tree, tree);
289
290   /* Given two types, merge their attributes and return the result.  */
291   tree (* merge_type_attributes) (tree, tree);
292
293   /* Table of machine attributes and functions to handle them.
294      Ignored if NULL.  */
295   const struct attribute_spec *attribute_table;
296
297   /* Return zero if the attributes on TYPE1 and TYPE2 are incompatible,
298      one if they are compatible and two if they are nearly compatible
299      (which causes a warning to be generated).  */
300   int (* comp_type_attributes) (tree type1, tree type2);
301
302   /* Assign default attributes to the newly defined TYPE.  */
303   void (* set_default_type_attributes) (tree type);
304
305   /* Insert attributes on the newly created DECL.  */
306   void (* insert_attributes) (tree decl, tree *attributes);
307
308   /* Return true if FNDECL (which has at least one machine attribute)
309      can be inlined despite its machine attributes, false otherwise.  */
310   bool (* function_attribute_inlinable_p) (tree fndecl);
311
312   /* Return true if bitfields in RECORD_TYPE should follow the
313      Microsoft Visual C++ bitfield layout rules.  */
314   bool (* ms_bitfield_layout_p) (tree record_type);
315
316   /* Return true if anonymous bitfields affect structure alignment.  */
317   bool (* align_anon_bitfield) (void);
318
319   /* Set up target-specific built-in functions.  */
320   void (* init_builtins) (void);
321
322   /* Expand a target-specific builtin.  */
323   rtx (* expand_builtin) (tree exp, rtx target, rtx subtarget,
324                           enum machine_mode mode, int ignore);
325
326   /* For a vendor-specific fundamental TYPE, return a pointer to
327      a statically-allocated string containing the C++ mangling for
328      TYPE.  In all other cases, return NULL.  */
329   const char * (* mangle_fundamental_type) (tree type);
330
331   /* Make any adjustments to libfunc names needed for this target.  */
332   void (* init_libfuncs) (void);
333
334   /* Given a decl, a section name, and whether the decl initializer
335      has relocs, choose attributes for the section.  */
336   /* ??? Should be merged with SELECT_SECTION and UNIQUE_SECTION.  */
337   unsigned int (* section_type_flags) (tree, const char *, int);
338
339   /* True if new jumps cannot be created, to replace existing ones or
340      not, at the current point in the compilation.  */
341   bool (* cannot_modify_jumps_p) (void);
342
343   /* Return a register class for which branch target register
344      optimizations should be applied.  */
345   int (* branch_target_register_class) (void);
346
347   /* Return true if branch target register optimizations should include
348      callee-saved registers that are not already live during the current
349      function.  AFTER_PE_GEN is true if prologues and epilogues have
350      already been generated.  */
351   bool (* branch_target_register_callee_saved) (bool after_pe_gen);
352
353   /* True if the constant X cannot be placed in the constant pool.  */
354   bool (* cannot_force_const_mem) (rtx);
355
356   /* True if the insn X cannot be duplicated.  */
357   bool (* cannot_copy_insn_p) (rtx);
358
359   /* Given an address RTX, undo the effects of LEGITIMIZE_ADDRESS.  */
360   rtx (* delegitimize_address) (rtx);
361
362   /* True if it is OK to do sibling call optimization for the specified
363      call expression EXP.  DECL will be the called function, or NULL if
364      this is an indirect call.  */
365   bool (*function_ok_for_sibcall) (tree decl, tree exp);
366
367   /* True if EXP should be placed in a "small data" section.  */
368   bool (* in_small_data_p) (tree);
369
370   /* True if EXP names an object for which name resolution must resolve
371      to the current module.  */
372   bool (* binds_local_p) (tree);
373
374   /* Do something target-specific to record properties of the DECL into
375      the associated SYMBOL_REF.  */
376   void (* encode_section_info) (tree, rtx, int);
377
378   /* Undo the effects of encode_section_info on the symbol string.  */
379   const char * (* strip_name_encoding) (const char *);
380
381   /* True if MODE is valid for a pointer in __attribute__((mode("MODE"))).  */
382   bool (* valid_pointer_mode) (enum machine_mode mode);
383
384   /* True if a vector is opaque.  */
385   bool (* vector_opaque_p) (tree);
386
387   /* Compute a (partial) cost for rtx X.  Return true if the complete
388      cost has been computed, and false if subexpressions should be
389      scanned.  In either case, *TOTAL contains the cost result.  */
390   /* Note that CODE and OUTER_CODE ought to be RTX_CODE, but that's
391      not necessarily defined at this point.  */
392   bool (* rtx_costs) (rtx x, int code, int outer_code, int *total);
393
394   /* Compute the cost of X, used as an address.  Never called with
395      invalid addresses.  */
396   int (* address_cost) (rtx x);
397
398   /* Given a register, this hook should return a parallel of registers
399      to represent where to find the register pieces.  Define this hook
400      if the register and its mode are represented in Dwarf in
401      non-contiguous locations, or if the register should be
402      represented in more than one register in Dwarf.  Otherwise, this
403      hook should return NULL_RTX.  */
404   rtx (* dwarf_register_span) (rtx);
405
406   /* Fetch the fixed register(s) which hold condition codes, for
407      targets where it makes sense to look for duplicate assignments to
408      the condition codes.  This should return true if there is such a
409      register, false otherwise.  The arguments should be set to the
410      fixed register numbers.  Up to two condition code registers are
411      supported.  If there is only one for this target, the int pointed
412      at by the second argument should be set to -1.  */
413   bool (* fixed_condition_code_regs) (unsigned int *, unsigned int *);
414
415   /* If two condition code modes are compatible, return a condition
416      code mode which is compatible with both, such that a comparison
417      done in the returned mode will work for both of the original
418      modes.  If the condition code modes are not compatible, return
419      VOIDmode.  */
420   enum machine_mode (* cc_modes_compatible) (enum machine_mode,
421                                              enum machine_mode);
422
423   /* Do machine-dependent code transformations.  Called just before
424      delayed-branch scheduling.  */
425   void (* machine_dependent_reorg) (void);
426
427   /* Create the __builtin_va_list type.  */
428   tree (* build_builtin_va_list) (void);
429
430   /* Gimplifies a VA_ARG_EXPR.  */
431   tree (* gimplify_va_arg_expr) (tree valist, tree type, tree *pre_p,
432                                  tree *post_p);
433
434   /* Validity-checking routines for PCH files, target-specific.
435      get_pch_validity returns a pointer to the data to be stored,
436      and stores the size in its argument.  pch_valid_p gets the same
437      information back and returns NULL if the PCH is valid,
438      or an error message if not.
439   */
440   void * (* get_pch_validity) (size_t *);
441   const char * (* pch_valid_p) (const void *, size_t);
442
443   /* True if the compiler should give an enum type only as many
444      bytes as it takes to represent the range of possible values of
445      that type.  */
446   bool (* default_short_enums) (void);
447
448   /* This target hook returns an rtx that is used to store the address
449      of the current frame into the built-in setjmp buffer.  */
450   rtx (* builtin_setjmp_frame_value) (void);
451
452   /* This target hook should add STRING_CST trees for any hard regs
453      the port wishes to automatically clobber for all asms.  */
454   tree (* md_asm_clobbers) (tree);
455
456   /* Functions relating to calls - argument passing, returns, etc.  */
457   struct calls {
458     bool (*promote_function_args) (tree fntype);
459     bool (*promote_function_return) (tree fntype);
460     bool (*promote_prototypes) (tree fntype);
461     rtx (*struct_value_rtx) (tree fndecl, int incoming);
462     bool (*return_in_memory) (tree type, tree fndecl);
463     bool (*return_in_msb) (tree type);
464
465     /* Return true if a parameter must be passed by reference.  TYPE may
466        be null if this is a libcall.  CA may be null if this query is
467        from __builtin_va_arg.  */
468     bool (*pass_by_reference) (CUMULATIVE_ARGS *ca, enum machine_mode mode,
469                                tree type, bool named_arg);
470
471     rtx (*expand_builtin_saveregs) (void);
472     /* Returns pretend_argument_size.  */
473     void (*setup_incoming_varargs) (CUMULATIVE_ARGS *ca, enum machine_mode mode,
474                                     tree type, int *pretend_arg_size,
475                                     int second_time);
476     bool (*strict_argument_naming) (CUMULATIVE_ARGS *ca);
477     /* Returns true if we should use
478        targetm.calls.setup_incoming_varargs() and/or
479        targetm.calls.strict_argument_naming().  */
480     bool (*pretend_outgoing_varargs_named) (CUMULATIVE_ARGS *ca);
481
482     /* Given a complex type T, return true if a parameter of type T
483        should be passed as two scalars.  */
484     bool (* split_complex_arg) (tree type);
485
486     /* Return true if type T, mode MODE, may not be passed in registers,
487        but must be passed on the stack.  */
488     /* ??? This predicate should be applied strictly after pass-by-reference.
489        Need audit to verify that this is the case.  */
490     bool (* must_pass_in_stack) (enum machine_mode mode, tree t);
491   } calls;
492
493   /* Functions specific to the C++ frontend.  */
494   struct cxx {
495     /* Return the integer type used for guard variables.  */
496     tree (*guard_type) (void);
497     /* Return true if only the low bit of the guard should be tested.  */
498     bool (*guard_mask_bit) (void);
499     /* Returns the size of the array cookie for an array of type.  */
500     tree (*get_cookie_size) (tree);
501     /* Returns true if the element size should be stored in the
502        array cookie.  */
503     bool (*cookie_has_size) (void);
504     /* Allows backends to perform additional processing when
505        deciding if a class should be exported or imported.  */
506     int (*import_export_class) (tree, int);
507     /* Returns true if constructors and destructors return "this".  */
508     bool (*cdtor_returns_this) (void);
509   } cxx;
510
511   /* Leave the boolean fields at the end.  */
512
513   /* True if arbitrary sections are supported.  */
514   bool have_named_sections;
515
516   /* True if "native" constructors and destructors are supported,
517      false if we're using collect2 for the job.  */
518   bool have_ctors_dtors;
519
520   /* True if thread-local storage is supported.  */
521   bool have_tls;
522
523   /* True if a small readonly data section is supported.  */
524   bool have_srodata_section;
525
526   /* True if EH frame info sections should be zero-terminated.  */
527   bool terminate_dw2_eh_frame_info;
528
529   /* True if #NO_APP should be emitted at the beginning of
530      assembly output.  */
531   bool file_start_app_off;
532
533   /* True if output_file_directive should be called for main_input_filename
534      at the beginning of assembly output.  */
535   bool file_start_file_directive;
536
537   /* True if #pragma redefine_extname is to be supported.  */
538   bool handle_pragma_redefine_extname;
539
540   /* True if #pragma extern_prefix is to be supported.  */
541   bool handle_pragma_extern_prefix;
542
543   /* True if the RTL prologue and epilogue should be expanded after all
544      passes that modify the instructions (and not merely reorder them)
545      have been run.  */
546   bool late_rtl_prologue_epilogue;
547
548   /* Leave the boolean fields at the end.  */
549 };
550
551 extern struct gcc_target targetm;
552
553 #endif /* GCC_TARGET_H */